๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

201117

ยท ์•ฝ 6๋ถ„

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-node#

  • tsconfig ์ƒ์„ฑ ๋ช…๋ น์–ด
tsc --init
  • tsconfig ์˜ต์…˜ ์ •๋ฆฌ

8 Best Practices for Future-Proofing Your TypeScript Code

tsconfig ์ปดํŒŒ์ผ ์˜ต์…˜ ์ •๋ฆฌ

[TS / Node] TS + Node.js + Express + Babel(option) + eslint๋กœ ๊ฐœ๋ฐœํ™˜๊ฒฝ ์„ธํŒ…ํ•˜๊ธฐ

Node.js ์‹œ์ž‘ํ•˜๊ธฐ

notion-api-worker#

  • get 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-Type#

  • Accept : ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์‘๋‹ต ํ˜•์‹์„ ์ง€์ •ํ•จ.

  • Content-Type : ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ณด๋‚ด๋Š” ์ฝ˜ํ…์ธ ์˜ ํ˜•์‹