gatsby-source-notion-churnotion 1.1.23 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,24 @@
1
1
  /**
2
- * POST request with retry logic using axios instance
3
- * @param {string} url - API endpoint URL
4
- * @param {any} body - Request body
5
- * @param {number} tryCount - Current retry count
6
- * @param {number} maxRetries - Maximum retry attempts
7
- * @returns {Promise<any>}
2
+ * Notion API에서 모든 블록 데이터를 가져오는 함수 (next_cursor 지원)
3
+ * @param {string} pageId - Notion 페이지 ID
4
+ * @returns {Promise<any[]>} 모든 블록 데이터 리스트
8
5
  */
9
- export declare const fetchPostWithRetry: (url: string, body: any, tryCount?: number, maxRetries?: number) => Promise<any>;
6
+ export declare const fetchAllBlocks: (pageId: string) => Promise<any[]>;
10
7
  /**
11
- * General GET/PUT/DELETE request with retry logic using axios instance
8
+ * Notion API에서 GET 요청을 수행하는 함수 (재시도 로직 포함)
12
9
  * @param {string} url - API endpoint URL
13
- * @param {any} options - Axios request options
14
- * @param {number} tryCount - Current retry count
15
- * @param {number} maxRetries - Maximum retry attempts
16
- * @returns {Promise<any>}
10
+ * @param {any} options - Axios 요청 옵션
11
+ * @param {number} tryCount - 현재 재시도 횟수
12
+ * @param {number} maxRetries - 최대 재시도 횟수
13
+ * @returns {Promise<any>} API 응답 데이터
17
14
  */
18
15
  export declare const fetchGetWithRetry: (url: string, options?: any, tryCount?: number, maxRetries?: number) => Promise<any>;
16
+ /**
17
+ * Notion API에서 POST 요청을 수행하는 함수 (재시도 로직 포함)
18
+ * @param {string} url - API endpoint URL
19
+ * @param {any} body - 요청 데이터
20
+ * @param {number} tryCount - 현재 재시도 횟수
21
+ * @param {number} maxRetries - 최대 재시도 횟수
22
+ * @returns {Promise<any>} API 응답 데이터
23
+ */
24
+ export declare const fetchPostWithRetry: (url: string, body: any, tryCount?: number, maxRetries?: number) => Promise<any>;
@@ -1,89 +1,106 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchGetWithRetry = exports.fetchPostWithRetry = void 0;
3
+ exports.fetchPostWithRetry = exports.fetchGetWithRetry = exports.fetchAllBlocks = void 0;
4
4
  const connector_1 = require("../api/connector");
5
5
  const constants_1 = require("../constants");
6
6
  const timeLimit_1 = require("./timeLimit");
7
7
  /**
8
- * POST request with retry logic using axios instance
8
+ * Notion API에서 모든 블록 데이터를 가져오는 함수 (next_cursor 지원)
9
+ * @param {string} pageId - Notion 페이지 ID
10
+ * @returns {Promise<any[]>} 모든 블록 데이터 리스트
11
+ */
12
+ const fetchAllBlocks = async (pageId) => {
13
+ let hasMore = true;
14
+ let nextCursor = null;
15
+ let allResults = [];
16
+ while (hasMore) {
17
+ const pageUrl = `blocks/${pageId}/children?page_size=100${nextCursor ? `&start_cursor=${nextCursor}` : ""}`;
18
+ const result = await (0, exports.fetchGetWithRetry)(pageUrl);
19
+ if (result?.results?.length) {
20
+ allResults = [...allResults, ...result.results]; // 기존 데이터와 병합
21
+ }
22
+ hasMore = result.has_more || false; // 다음 데이터가 있는지 확인
23
+ nextCursor = result.next_cursor || null; // 다음 페이지 커서 업데이트
24
+ }
25
+ return allResults;
26
+ };
27
+ exports.fetchAllBlocks = fetchAllBlocks;
28
+ /**
29
+ * Notion API에서 GET 요청을 수행하는 함수 (재시도 로직 포함)
9
30
  * @param {string} url - API endpoint URL
10
- * @param {any} body - Request body
11
- * @param {number} tryCount - Current retry count
12
- * @param {number} maxRetries - Maximum retry attempts
13
- * @returns {Promise<any>}
31
+ * @param {any} options - Axios 요청 옵션
32
+ * @param {number} tryCount - 현재 재시도 횟수
33
+ * @param {number} maxRetries - 최대 재시도 횟수
34
+ * @returns {Promise<any>} API 응답 데이터
14
35
  */
15
- const fetchPostWithRetry = async (url, body, tryCount = 0, maxRetries = 5) => {
36
+ const fetchGetWithRetry = async (url, options = {}, tryCount = 0, maxRetries = 5) => {
16
37
  try {
17
- const response = await connector_1.instance.post(url, body);
18
- // Return data if the request was successful
19
- return response.data;
38
+ const response = await connector_1.instance.get(url);
39
+ const results = response.data.results;
40
+ // Notion API 응답에 has_more가 있으면 fetchAllBlocks 호출
41
+ if (response.data.has_more) {
42
+ const additionalResults = await (0, exports.fetchAllBlocks)(url.split("/")[1]); // pageId 추출
43
+ results.push(...additionalResults);
44
+ }
45
+ return { ...response.data, results }; // 전체 데이터 반환
20
46
  }
21
47
  catch (error) {
22
48
  const status = error.response?.status;
23
49
  const message = error.response?.data?.message || `Unknown error`;
24
- // Handle rate limit errors with exponential backoff
50
+ // Rate limit 오류 처리 (Exponential Backoff)
25
51
  if (status === constants_1.NOTION_LIMIT_ERROR && tryCount < maxRetries) {
26
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff: 1s, 2s, 4s...
52
+ const delay = Math.pow(2, tryCount) * 1000;
27
53
  console.log(`[${constants_1.PLUGIN_NAME}] Rate limit hit. Retrying in ${delay / 1000}s...`);
28
54
  await (0, timeLimit_1.sleep)(delay);
29
- return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
55
+ return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
30
56
  }
31
- // Handle unexpected errors with retry
57
+ // 기타 예외 처리 (Exponential Backoff)
32
58
  if (tryCount < maxRetries) {
33
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff
59
+ const delay = Math.pow(2, tryCount) * 1000;
34
60
  console.log(`[${constants_1.PLUGIN_NAME}] Unexpected error. Retrying in ${delay / 1000}s...`);
35
61
  await (0, timeLimit_1.sleep)(delay);
36
- return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
62
+ return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
37
63
  }
38
- // Log and throw the error if all retries fail
64
+ // 최대 재시도 초과 오류 출력 throw
39
65
  console.error(`[${constants_1.PLUGIN_NAME}] Failed after ${tryCount} retries:`, message);
40
66
  throw error;
41
67
  }
42
68
  };
43
- exports.fetchPostWithRetry = fetchPostWithRetry;
69
+ exports.fetchGetWithRetry = fetchGetWithRetry;
44
70
  /**
45
- * General GET/PUT/DELETE request with retry logic using axios instance
71
+ * Notion API에서 POST 요청을 수행하는 함수 (재시도 로직 포함)
46
72
  * @param {string} url - API endpoint URL
47
- * @param {any} options - Axios request options
48
- * @param {number} tryCount - Current retry count
49
- * @param {number} maxRetries - Maximum retry attempts
50
- * @returns {Promise<any>}
73
+ * @param {any} body - 요청 데이터
74
+ * @param {number} tryCount - 현재 재시도 횟수
75
+ * @param {number} maxRetries - 최대 재시도 횟수
76
+ * @returns {Promise<any>} API 응답 데이터
51
77
  */
52
- const fetchGetWithRetry = async (url, options = {}, tryCount = 0, maxRetries = 5) => {
78
+ const fetchPostWithRetry = async (url, body, tryCount = 0, maxRetries = 5) => {
53
79
  try {
54
- const response = await connector_1.instance.get(url);
55
- const results = response.data.results;
56
- for (const block of results) {
57
- if (block.has_children) {
58
- block.children = [];
59
- const pageUrl = `blocks/${block.id}/children?page_size=100`;
60
- const childData = await (0, exports.fetchGetWithRetry)(pageUrl);
61
- const childResults = childData.results;
62
- block.children.push(...childResults);
63
- }
64
- }
80
+ const response = await connector_1.instance.post(url, body);
81
+ // 요청 성공 시 데이터 반환
65
82
  return response.data;
66
83
  }
67
84
  catch (error) {
68
85
  const status = error.response?.status;
69
86
  const message = error.response?.data?.message || `Unknown error`;
70
- // Handle rate limit errors with exponential backoff
87
+ // Rate limit 오류 처리 (Exponential Backoff)
71
88
  if (status === constants_1.NOTION_LIMIT_ERROR && tryCount < maxRetries) {
72
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff: 1s, 2s, 4s...
89
+ const delay = Math.pow(2, tryCount) * 1000;
73
90
  console.log(`[${constants_1.PLUGIN_NAME}] Rate limit hit. Retrying in ${delay / 1000}s...`);
74
91
  await (0, timeLimit_1.sleep)(delay);
75
- return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
92
+ return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
76
93
  }
77
- // Handle unexpected errors with retry
94
+ // 기타 예외 처리 (Exponential Backoff)
78
95
  if (tryCount < maxRetries) {
79
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff
96
+ const delay = Math.pow(2, tryCount) * 1000;
80
97
  console.log(`[${constants_1.PLUGIN_NAME}] Unexpected error. Retrying in ${delay / 1000}s...`);
81
98
  await (0, timeLimit_1.sleep)(delay);
82
- return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
99
+ return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
83
100
  }
84
- // Log and throw the error if all retries fail
101
+ // 최대 재시도 초과 오류 출력 throw
85
102
  console.error(`[${constants_1.PLUGIN_NAME}] Failed after ${tryCount} retries:`, message);
86
103
  throw error;
87
104
  }
88
105
  };
89
- exports.fetchGetWithRetry = fetchGetWithRetry;
106
+ exports.fetchPostWithRetry = fetchPostWithRetry;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatsby-source-notion-churnotion",
3
3
  "description": "Gatsby plugin that can connect with One Notion Database RECURSIVELY using official API",
4
- "version": "1.1.23",
4
+ "version": "1.1.24",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",