gatsby-source-notion-churnotion 1.1.26 → 1.1.27

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,9 +1,10 @@
1
1
  /**
2
2
  * Notion API에서 모든 블록 데이터를 가져오는 함수 (next_cursor 지원)
3
3
  * @param {string} pageId - Notion 페이지 ID
4
+ * @param {string | null} startCursor - 처음 호출 시 넘길 next_cursor (기본값 null)
4
5
  * @returns {Promise<any[]>} 모든 블록 데이터 리스트
5
6
  */
6
- export declare const fetchAllBlocks: (pageId: string) => Promise<any[]>;
7
+ export declare const fetchAllBlocks: (pageId: string, startCursor?: string | null) => Promise<any[]>;
7
8
  /**
8
9
  * Notion API에서 GET 요청을 수행하는 함수 (재시도 로직 포함)
9
10
  */
@@ -7,20 +7,28 @@ const timeLimit_1 = require("./timeLimit");
7
7
  /**
8
8
  * Notion API에서 모든 블록 데이터를 가져오는 함수 (next_cursor 지원)
9
9
  * @param {string} pageId - Notion 페이지 ID
10
+ * @param {string | null} startCursor - 처음 호출 시 넘길 next_cursor (기본값 null)
10
11
  * @returns {Promise<any[]>} 모든 블록 데이터 리스트
11
12
  */
12
- const fetchAllBlocks = async (pageId) => {
13
+ const fetchAllBlocks = async (pageId, startCursor = null) => {
13
14
  let hasMore = true;
14
- let nextCursor = null;
15
+ let nextCursor = startCursor; // 초기 next_cursor를 설정
15
16
  let allResults = [];
16
17
  while (hasMore) {
17
18
  const pageUrl = `blocks/${pageId}/children?page_size=100${nextCursor ? `&start_cursor=${nextCursor}` : ""}`;
19
+ console.log(`[INFO] Fetching blocks from: ${pageUrl}`); // 디버깅용 로그
18
20
  const result = await (0, exports.fetchGetWithRetry)(pageUrl);
19
21
  if (result?.results?.length) {
20
22
  allResults = [...allResults, ...result.results]; // 기존 데이터와 병합
21
23
  }
24
+ console.log(`[INFO] Retrieved ${result.results.length} blocks`);
25
+ console.log(`[INFO] has_more: ${result.has_more}, next_cursor: ${result.next_cursor}`);
22
26
  hasMore = result.has_more || false; // 다음 데이터가 있는지 확인
23
27
  nextCursor = result.next_cursor || null; // 다음 페이지 커서 업데이트
28
+ // 만약 nextCursor가 계속 null이라면 루프 탈출
29
+ if (!nextCursor) {
30
+ hasMore = false;
31
+ }
24
32
  }
25
33
  return allResults;
26
34
  };
@@ -29,14 +37,22 @@ exports.fetchAllBlocks = fetchAllBlocks;
29
37
  * Notion API에서 GET 요청을 수행하는 함수 (재시도 로직 포함)
30
38
  */
31
39
  const fetchGetWithRetry = async (url, options = {}, tryCount = 0, maxRetries = 5) => {
32
- console.dir("get :" + url);
40
+ console.log(`[GET] Request URL: ${url}`); // 디버깅용 로그
33
41
  try {
34
42
  const response = await connector_1.instance.get(url);
35
43
  let results = response.data.results;
44
+ console.log(`[INFO] Initial results count: ${results.length}`);
36
45
  // Notion API 응답에 has_more가 있으면 추가 블록을 가져와 병합
37
46
  if (response.data.has_more) {
38
- const additionalResults = await (0, exports.fetchAllBlocks)(url.split("/")[1]); // pageId 추출
39
- results = [...results, ...additionalResults]; // 기존 results에 추가 데이터 병합
47
+ const pageId = url.match(/blocks\/([^\/]*)\/children/)?.[1]; // 정확한 pageId 추출
48
+ if (pageId) {
49
+ console.log(`[INFO] Fetching additional blocks for pageId: ${pageId} with next_cursor: ${response.data.next_cursor}`);
50
+ const additionalResults = await (0, exports.fetchAllBlocks)(pageId, response.data.next_cursor); // next_cursor도 함께 전달
51
+ results = [...results, ...additionalResults]; // 기존 results에 추가 데이터 병합
52
+ }
53
+ else {
54
+ console.warn(`[WARNING] Failed to extract pageId from URL: ${url}`);
55
+ }
40
56
  }
41
57
  return { ...response.data, results }; // 병합된 전체 데이터 반환
42
58
  }
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.26",
4
+ "version": "1.1.27",
5
5
  "skipLibCheck": true,
6
6
  "license": "0BSD",
7
7
  "main": "./dist/gatsby-node.js",