#
Narkdown ํ๋ก์ ํธnotion-py ๋ฅผ ์ฌ์ฉํด์ Python ๊ธฐ๋ฐ์ผ๋ก์งํํ์์ง๋ง Python์ ์ ์ฌ์ฉํ์ง ์๋ค๋ณด๋ ์ ์ง ๋ณด์ํ๊ธฐ ํ๋ค์๋ค.
ts
๊ธฐ๋ฐ notion-api-worker ๊ฐ ์์ด์ ์ด๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ๋ค.
#
๋ชฉํCLI๋ก page url ๋๋ database url์ ์ ๋ ฅ ๋ฐ๊ณ notion์ ์ปจํ ์ธ ๋ฅผ ํ์ฑํ์ฌ md ํ์ผ์ ์์ฑํ์. (CMS๋ฅผ ์ํด)
์ดํ ์น ํ์ด์ง๋ฅผ ๋ง๋ค ์ ์์ผ๋ฉด ์ข์ ๋ฏ.
#
fetch vs axiosํ๋ก ํธ์๋์์ fetch, axios๋ ์์ฃผ ์ฌ์ฉํ๋๋ฐ, node ํ๊ฒฝ์์ api ์์ฒญ์ ํด๋ณด๋๊ฒ์ ์ฒ์์ด๋ผ, ์ด๋ค ๊ฒ์ ์ฌ์ฉํ ์ง ๊ณ ๋ฏผํ๋ค.
axios๋ node ํ๊ฒฝ์์๋ ๋์ผํ๊ฒ ์ฌ์ฉํ๋ ๊ฒ์ด ๊ฐ๋ฅํ๋ค.
fetch๋ node-fetch ๋ผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ NodeJS ๋ฐํ์ ํ๊ฒฝ์์
window.fetch
๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํ ์ต์ํ์ ์ฝ๋๋ฅผ ๋ชฉํ๋ก ํ๋ค๊ณ ํ๋ค.ํ๋ก ํธ์๋ ํ๊ฒฝ์์ fetch ๊ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น ์์ด ์ฌ์ฉํ ์ ์๋๊ฒ ์ฅ์ ์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ, ๊ตณ์ด node-fetch๋ฅผ ์ฌ์ฉํ ํ์๋ ์์ ๊ฒ ๊ฐ์์, axios๋ฅผ ์ฌ์ฉํ๊ธฐ๋ก๊ฒฐ์ ํ๋ค. (๋ณด์์ ์ธ ์ต์ ๋ axios๊ฐ ๋ง์ด ์ ๊ณตํ๋ค.)
https://www.geeksforgeeks.org/difference-between-fetch-and-axios-js-for-making-http-requests/
#
ts-nodetsconfig
์์ฑ ๋ช ๋ น์ด
tsc --init
tsconfig
์ต์ ์ ๋ฆฌ
8 Best Practices for Future-Proofing Your TypeScript Code
tsconfig ์ปดํ์ผ ์ต์ ์ ๋ฆฌ
[TS / Node] TS + Node.js + Express + Babel(option) + eslint๋ก ๊ฐ๋ฐํ๊ฒฝ ์ธํ ํ๊ธฐ
#
notion-api-workerget page ๋ฆฌํด
๊ธฐ๋ณธ ํ์ด์ง
{ "847c0e9b-15a1-42c9-9392-ca2f817c4eac": { "role": "editor", "value": { "id": "847c0e9b-15a1-42c9-9392-ca2f817c4eac", "version": 23, "type": "page", "properties": { "title": [["hello"]] }, "content": ["cc1dee2e-269d-4cd0-a5a3-b1c3d72edf61"], "permissions": [ { "role": "editor", "type": "user_permission", "user_id": "b21a69b3-a19b-438c-b599-e850190836a3" } ], "created_time": 1605604740000, "last_edited_time": 1605604740000, "parent_id": "ee7c0178-18cf-474e-a665-83f2432f545f", "parent_table": "space", "alive": true, "created_by_table": "notion_user", "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }, "cc1dee2e-269d-4cd0-a5a3-b1c3d72edf61": { "role": "editor", "value": { "id": "cc1dee2e-269d-4cd0-a5a3-b1c3d72edf61", "version": 12, "type": "text", "properties": { "title": [["1234"]] }, "created_time": 1605604740000, "last_edited_time": 1605604740000, "parent_id": "847c0e9b-15a1-42c9-9392-ca2f817c4eac", "parent_table": "block", "alive": true, "created_by_table": "notion_user", "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }}
Database ํ์ ํ์ด์ง
{ "15afa14b-8f9c-4b6c-97cc-46375c775cc5": { "role": "reader", "value": { "id": "15afa14b-8f9c-4b6c-97cc-46375c775cc5", "version": 25, "type": "page", "properties": [Object], "created_time": 1605517260000, "last_edited_time": 1605602760000, // ๋ถ๋ชจ Id // ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๊ฒฝ์ฐ collection_id "parent_id": "e543505f-be64-46cd-9c55-07117dc85a92", // ๋ถ๋ชจ "parent_table": "collection", "alive": true, "created_by_table": "notion_user", // user_id "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }, // ๋ถ๋ชจ๊ฐ space๊ฐ ์๋ ๊ฒฝ์ฐ ๋ถ๋ชจ "acc3dfd0-339e-4cac-b5ba-ae8673fddfad": { "role": "reader", "value": { "id": "acc3dfd0-339e-4cac-b5ba-ae8673fddfad", "version": 106, "type": "collection_view_page", "view_ids": [Array], "collection_id": "e543505f-be64-46cd-9c55-07117dc85a92", "format": [Object], "permissions": [Array], "created_time": 1600223639505, "last_edited_time": 1605594780000, "parent_id": "ee7c0178-18cf-474e-a665-83f2432f545f", "parent_table": "space", "alive": true, "created_by_table": "notion_user", "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }}
๋ฉํ๋ฐ์ดํฐ๊ฐ ์๋ ํ์ด์ง
{ "1c7c8eb6-ec3b-42fb-b950-63abd3c9bd61": { "role": "reader", "value": { "id": "1c7c8eb6-ec3b-42fb-b950-63abd3c9bd61", "version": 6, "type": "page", // ๋ฐ์ดํฐ๋ฒ ์ด์ค ํ์์ ์๋ ํ์ด์ง์ ๋ฉํ๋ฐ์ดํฐ ๋ถ๋ชจ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ๊ทผํด์ ๊ฐ์ ธ์์ผ ํจ. "properties": { "RXKJ": [ // ์ฌ๋ฌ ํ๊ทธ ๋ชฉ๋ก์ด ๋ฌธ์์ด ',' ๋ก ๊ตฌ๋ถ๋์ด ์ด. ["hello,bye"] ], "fb_;": [["๐ In Progress"]], "qS^H": [["Test"]], "title": [["asdf"], ["์ ์ฌ๋ณธ"]] }, // ์ ์ฒด ํ์ด์ง, ์์ ํ์ด์ง ์ฌ์ด์ฆ์ผ ๋ ํจ๊ป ์ด, ์์ผ๋ฉด ์์ด. "format": { "page_icon": "๐ก", // link์ธ ๊ฒฝ์ฐ๋ ๋งํฌ "page_cover": "https://user-images.githubusercontent.com/1440854/79684011-6c948280-822e-11ea-9e23-1644903796fb.png", // ์ ๋ก๋์ธ ๊ฒฝ์ฐ https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d53a69fd-a3e1-4914-b014-63158a1078a2/blue.png // ๊ธฐ๋ณธ ์ ๊ณต์ธ ๊ฒฝ์ฐ /images/blue.png => https://notion.so/images/blue.png๋ก ์ ๊ทผ ๊ฐ๋ฅ "page_cover_position": 0.5, "page_full_width": true, "page_small_text": true }, "created_time": 1605594821014, "last_edited_time": 1605603000000, "parent_id": "e543505f-be64-46cd-9c55-07117dc85a92", "parent_table": "collection", "alive": true, "copied_from": "15afa14b-8f9c-4b6c-97cc-46375c775cc5", "created_by_table": "notion_user", "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }, "acc3dfd0-339e-4cac-b5ba-ae8673fddfad": { "role": "reader", "value": { "id": "acc3dfd0-339e-4cac-b5ba-ae8673fddfad", "version": 106, "type": "collection_view_page", "view_ids": [ "be43c1c8-dd64-4cfb-9df9-efd97d8af60a", "cfabb574-6051-47ed-9c14-ea3a1b6aead7", "87cdd007-d8d6-464c-82f2-c7a4153bab0d", "c09c2c36-0419-4bff-8195-bf6c2b897d6f", "e0d39abd-4d7b-4c5c-9ce9-4984a3315932", "83b3d2a6-6f63-4940-987d-1142e51da175" ], "collection_id": "e543505f-be64-46cd-9c55-07117dc85a92", "format": { "page_cover_position": 0.6 }, "permissions": [ { "role": "editor", "type": "user_permission", "user_id": "b21a69b3-a19b-438c-b599-e850190836a3" }, { "role": "reader", "type": "public_permission" } ], "created_time": 1600223639505, "last_edited_time": 1605594780000, "parent_id": "ee7c0178-18cf-474e-a665-83f2432f545f", "parent_table": "space", "alive": true, "created_by_table": "notion_user", "created_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "last_edited_by_table": "notion_user", "last_edited_by_id": "b21a69b3-a19b-438c-b599-e850190836a3", "shard_id": 1004639, "space_id": "ee7c0178-18cf-474e-a665-83f2432f545f" } }}
get table ๋ฆฌํด
table๋ก ๋ ํ์ด์ง
[ { "id": "11acfd54-2ee8-4640-b3fb-1782ce9b8caa", "Status": "๐จ Published", "Category": "Test", "Name": "Basic Blocks" }, { "id": "084bbefe-7f25-481a-bfbb-e8aff2152e4f", "Status": "๐จ Published", "Category": "Test", "Name": "Copy of Basic Blocks" }, { "id": "24786a8a-3d7d-4dfd-854d-ac40559c9f82", "Status": "๐จ Published", "Category": "Test", "Name": "Code Blocks" }, { "id": "74bbb810-9a68-499f-8f12-25dcce846f02", "Status": "๐จ Published", "Category": "Test", "Name": "Embed Blocks" }, { "id": "2df7176f-d58f-4c42-921b-55e9bbf0e92e", "Status": "๐จ Published", "Category": "Test", "Name": "Table Blocks" }, { "id": "30894478-96e6-4f95-9095-d84be27a82a9", "Status": "๐จ Published", "Category": "Test", "Name": "Page Blocks" }, { "id": "cee84696-242a-4f6e-953a-2c7ecb8b1603", "Status": "๐จ Published", "Category": "Test", "Name": "Advanced Blocks" }, { "id": "64c69eaf-268a-4076-bf48-d8ee5f2ca8c8", "Status": "๐จ Published", "Category": "Test", "Name": "Linked Page" }, { "id": "6a8383c0-0a12-4859-9edc-2fe41e9cbe75", "Status": "๐จ Published", "Category": "Test", "Name": "Recursive embed Image" }, { "id": "d10a7885-58f0-4ba9-b9a4-fb357ab796e8", "Status": "๐จ Published", "Category": "Example", "Name": "Example Pages" }, { "id": "1c7c8eb6-ec3b-42fb-b950-63abd3c9bd61", "Tags": ["hello", "bye"], "Status": "๐ In Progress", "Category": "Test", "Name": "asdf์ ์ฌ๋ณธ" }, // ์์ ํ ์์ง์ ์ ๋๋ ๋น๋ฌธ์์ด๋ก ์ด. { "id": "e8b450e4-f686-4d0b-9212-6241e6099a0b", "Tags": [""], "Status": "", "Category": "" }]
blocks
#
Accept vs Content-TypeAccept : ํด๋ผ์ด์ธํธ๊ฐ ๋ฐ์ ์ ์๋ ์๋ต ํ์์ ์ง์ ํจ.
Content-Type : ํด๋ผ์ด์ธํธ๊ฐ ๋ณด๋ด๋ ์ฝํ ์ธ ์ ํ์