gatsby-source-notion-churnotion 1.1.23 → 1.1.25

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,19 @@
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
12
- * @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>}
8
+ * Notion API에서 GET 요청을 수행하는 함수 (재시도 로직 포함)
17
9
  */
18
10
  export declare const fetchGetWithRetry: (url: string, options?: any, tryCount?: number, maxRetries?: number) => Promise<any>;
11
+ /**
12
+ * Notion API에서 POST 요청을 수행하는 함수 (재시도 로직 포함)
13
+ * @param {string} url - API endpoint URL
14
+ * @param {any} body - 요청 데이터
15
+ * @param {number} tryCount - 현재 재시도 횟수
16
+ * @param {number} maxRetries - 최대 재시도 횟수
17
+ * @returns {Promise<any>} API 응답 데이터
18
+ */
19
+ export declare const fetchPostWithRetry: (url: string, body: any, tryCount?: number, maxRetries?: number) => Promise<any>;
@@ -1,89 +1,101 @@
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
9
- * @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>}
8
+ * Notion API에서 모든 블록 데이터를 가져오는 함수 (next_cursor 지원)
9
+ * @param {string} pageId - Notion 페이지 ID
10
+ * @returns {Promise<any[]>} 모든 블록 데이터 리스트
14
11
  */
15
- const fetchPostWithRetry = async (url, body, tryCount = 0, maxRetries = 5) => {
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 요청을 수행하는 함수 (재시도 로직 포함)
30
+ */
31
+ const fetchGetWithRetry = async (url, options = {}, tryCount = 0, maxRetries = 5) => {
16
32
  try {
17
- const response = await connector_1.instance.post(url, body);
18
- // Return data if the request was successful
19
- return response.data;
33
+ const response = await connector_1.instance.get(url);
34
+ let results = response.data.results;
35
+ // Notion API 응답에 has_more가 있으면 추가 블록을 가져와 병합
36
+ if (response.data.has_more) {
37
+ const additionalResults = await (0, exports.fetchAllBlocks)(url.split("/")[1]); // pageId 추출
38
+ results = [...results, ...additionalResults]; // 기존 results에 추가 데이터 병합
39
+ }
40
+ return { ...response.data, results }; // 병합된 전체 데이터 반환
20
41
  }
21
42
  catch (error) {
22
43
  const status = error.response?.status;
23
44
  const message = error.response?.data?.message || `Unknown error`;
24
- // Handle rate limit errors with exponential backoff
45
+ // Rate limit 오류 처리 (Exponential Backoff)
25
46
  if (status === constants_1.NOTION_LIMIT_ERROR && tryCount < maxRetries) {
26
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff: 1s, 2s, 4s...
47
+ const delay = Math.pow(2, tryCount) * 1000;
27
48
  console.log(`[${constants_1.PLUGIN_NAME}] Rate limit hit. Retrying in ${delay / 1000}s...`);
28
49
  await (0, timeLimit_1.sleep)(delay);
29
- return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
50
+ return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
30
51
  }
31
- // Handle unexpected errors with retry
52
+ // 기타 예외 처리 (Exponential Backoff)
32
53
  if (tryCount < maxRetries) {
33
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff
54
+ const delay = Math.pow(2, tryCount) * 1000;
34
55
  console.log(`[${constants_1.PLUGIN_NAME}] Unexpected error. Retrying in ${delay / 1000}s...`);
35
56
  await (0, timeLimit_1.sleep)(delay);
36
- return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
57
+ return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
37
58
  }
38
- // Log and throw the error if all retries fail
59
+ // 최대 재시도 초과 오류 출력 throw
39
60
  console.error(`[${constants_1.PLUGIN_NAME}] Failed after ${tryCount} retries:`, message);
40
61
  throw error;
41
62
  }
42
63
  };
43
- exports.fetchPostWithRetry = fetchPostWithRetry;
64
+ exports.fetchGetWithRetry = fetchGetWithRetry;
44
65
  /**
45
- * General GET/PUT/DELETE request with retry logic using axios instance
66
+ * Notion API에서 POST 요청을 수행하는 함수 (재시도 로직 포함)
46
67
  * @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>}
68
+ * @param {any} body - 요청 데이터
69
+ * @param {number} tryCount - 현재 재시도 횟수
70
+ * @param {number} maxRetries - 최대 재시도 횟수
71
+ * @returns {Promise<any>} API 응답 데이터
51
72
  */
52
- const fetchGetWithRetry = async (url, options = {}, tryCount = 0, maxRetries = 5) => {
73
+ const fetchPostWithRetry = async (url, body, tryCount = 0, maxRetries = 5) => {
53
74
  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
- }
75
+ const response = await connector_1.instance.post(url, body);
76
+ // 요청 성공 시 데이터 반환
65
77
  return response.data;
66
78
  }
67
79
  catch (error) {
68
80
  const status = error.response?.status;
69
81
  const message = error.response?.data?.message || `Unknown error`;
70
- // Handle rate limit errors with exponential backoff
82
+ // Rate limit 오류 처리 (Exponential Backoff)
71
83
  if (status === constants_1.NOTION_LIMIT_ERROR && tryCount < maxRetries) {
72
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff: 1s, 2s, 4s...
84
+ const delay = Math.pow(2, tryCount) * 1000;
73
85
  console.log(`[${constants_1.PLUGIN_NAME}] Rate limit hit. Retrying in ${delay / 1000}s...`);
74
86
  await (0, timeLimit_1.sleep)(delay);
75
- return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
87
+ return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
76
88
  }
77
- // Handle unexpected errors with retry
89
+ // 기타 예외 처리 (Exponential Backoff)
78
90
  if (tryCount < maxRetries) {
79
- const delay = Math.pow(2, tryCount) * 1000; // Exponential backoff
91
+ const delay = Math.pow(2, tryCount) * 1000;
80
92
  console.log(`[${constants_1.PLUGIN_NAME}] Unexpected error. Retrying in ${delay / 1000}s...`);
81
93
  await (0, timeLimit_1.sleep)(delay);
82
- return (0, exports.fetchGetWithRetry)(url, options, tryCount + 1, maxRetries);
94
+ return (0, exports.fetchPostWithRetry)(url, body, tryCount + 1, maxRetries);
83
95
  }
84
- // Log and throw the error if all retries fail
96
+ // 최대 재시도 초과 오류 출력 throw
85
97
  console.error(`[${constants_1.PLUGIN_NAME}] Failed after ${tryCount} retries:`, message);
86
98
  throw error;
87
99
  }
88
100
  };
89
- exports.fetchGetWithRetry = fetchGetWithRetry;
101
+ 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.25",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",