Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/notion-client/src/notion-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ export class NotionAPI {
throw new Error(`Notion page not found "${uuidToId(pageId)}"`)
}

// unwrap doubly-nested value structures from Notion API response
// some blocks return { role, value: { role, value: { id, type, ... } } }
for (const key of ['block', 'collection', 'collection_view'] as const) {
const map = recordMap[key]
if (!map) continue
for (const id of Object.keys(map)) {
const entry = map[id] as any
if (
entry?.value &&
entry.value.value &&
typeof entry.value.value === 'object' &&
entry.value.value.id
) {
entry.value = entry.value.value
}
}
}

// ensure that all top-level maps exist
recordMap.collection = recordMap.collection ?? {}
recordMap.collection_view = recordMap.collection_view ?? {}
Expand Down
2 changes: 1 addition & 1 deletion packages/notion-utils/src/uuid-to-id.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const uuidToId = (uuid: string) => uuid.replaceAll('-', '')
export const uuidToId = (uuid: string) => (uuid || '').replaceAll('-', '')