@moxn/kb-migrate 0.4.27 → 0.4.29

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.
@@ -171,11 +171,28 @@ export class NotionApiClient {
171
171
  };
172
172
  if (body)
173
173
  headers['Content-Type'] = 'application/json';
174
- const response = await fetch(`${NOTION_API_BASE}${path}`, {
175
- method,
176
- headers,
177
- body: body ? JSON.stringify(body) : undefined,
178
- });
174
+ let response;
175
+ try {
176
+ response = await fetch(`${NOTION_API_BASE}${path}`, {
177
+ method,
178
+ headers,
179
+ body: body ? JSON.stringify(body) : undefined,
180
+ });
181
+ }
182
+ catch (fetchError) {
183
+ // Network-level failure (DNS, TCP reset, timeout, etc.)
184
+ lastError =
185
+ fetchError instanceof Error
186
+ ? fetchError
187
+ : new Error(String(fetchError));
188
+ if (attempt < MAX_RETRIES) {
189
+ const delay = Math.min(1000 * Math.pow(2, attempt), 30000);
190
+ console.warn(`Network error: ${lastError.message}. Retrying in ${delay}ms (attempt ${attempt + 1}/${MAX_RETRIES})`);
191
+ await sleep(delay);
192
+ continue;
193
+ }
194
+ throw lastError;
195
+ }
179
196
  if (response.ok) {
180
197
  return (await response.json());
181
198
  }
@@ -112,7 +112,7 @@ async function convertBlock(block, client, pagePathMap, visitedSyncedBlocks, dat
112
112
  // Just note it in the content.
113
113
  break;
114
114
  case 'child_database':
115
- results.push(...convertChildDatabase(block, databaseIdMap, unresolvedChildDatabases));
115
+ results.push(...(await convertChildDatabase(block, client, databaseIdMap, unresolvedChildDatabases)));
116
116
  break;
117
117
  case 'synced_block':
118
118
  results.push(...(await convertSyncedBlock(block, client, pagePathMap, visitedSyncedBlocks, databaseIdMap, unsupportedBlocks, unresolvedChildDatabases)));
@@ -188,7 +188,7 @@ function convertHeading(block, level) {
188
188
  function convertCode(block) {
189
189
  const c = block;
190
190
  const code = richTextToPlain(c.code.rich_text);
191
- const lang = c.code.language === 'plain text' ? '' : c.code.language;
191
+ const lang = c.code.language === 'plain text' ? 'text' : c.code.language;
192
192
  const caption = richTextToPlain(c.code.caption);
193
193
  let text = '```' + lang + '\n' + code + '\n```';
194
194
  if (caption)
@@ -278,7 +278,7 @@ async function convertToggle(block, client, pagePathMap, visitedSyncedBlocks, da
278
278
  }
279
279
  return results;
280
280
  }
281
- function convertChildDatabase(block, databaseIdMap, unresolvedChildDatabases) {
281
+ async function convertChildDatabase(block, client, databaseIdMap, unresolvedChildDatabases) {
282
282
  const cd = block;
283
283
  const title = cd.child_database?.title || 'Untitled Database';
284
284
  const notionDbId = normalizeId(block.id);
@@ -287,6 +287,19 @@ function convertChildDatabase(block, databaseIdMap, unresolvedChildDatabases) {
287
287
  if (kbDatabaseId) {
288
288
  return [{ blockType: 'database_embed', databaseId: kbDatabaseId }];
289
289
  }
290
+ // Try to resolve as a linked database: query one entry to find the source DB
291
+ if (databaseIdMap) {
292
+ const sourceDbId = await client.resolveLinkedDatabaseSource(notionDbId);
293
+ if (sourceDbId) {
294
+ const sourceKbDbId = databaseIdMap.get(sourceDbId);
295
+ if (sourceKbDbId) {
296
+ // Cache for future blocks in this extraction
297
+ databaseIdMap.set(notionDbId, sourceKbDbId);
298
+ console.log(` Resolved linked database "${title}" → source KB ${sourceKbDbId}`);
299
+ return [{ blockType: 'database_embed', databaseId: sourceKbDbId }];
300
+ }
301
+ }
302
+ }
290
303
  // No mapping available — collect for later creation and emit text placeholder
291
304
  if (unresolvedChildDatabases) {
292
305
  unresolvedChildDatabases.set(notionDbId, title);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moxn/kb-migrate",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "description": "Migration tool for importing documents into Moxn Knowledge Base from local files, Notion, Google Docs, and more",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",