Skip to content

Commit ab499a2

Browse files
committed
Uprgade react-notion-x and fix getPage errors
1 parent 3a4cda3 commit ab499a2

File tree

3 files changed

+82
-283
lines changed

3 files changed

+82
-283
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"mermaid": "^10.4.0",
4848
"moment": "^2.29.4",
4949
"next": "^14.2.3",
50-
"notion-client": "^6.16.0",
51-
"notion-types": "^6.16.0",
52-
"notion-utils": "^6.16.0",
50+
"notion-client": "^7.4.3",
51+
"notion-types": "^7.4.3",
52+
"notion-utils": "^7.4.3",
5353
"open-graph-scraper": "^6.2.2",
5454
"p-memoize": "^7.1.1",
5555
"prismjs": "^1.29.0",

src/lib/notionx.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,29 @@ import { ExtendedRecordMap } from 'notion-types'
33

44
export const notionX = new NotionAPI({
55
activeUser: process.env.NOTION_ACTIVE_USER,
6-
authToken: process.env.NOTION_TOKEN_V2
6+
authToken: process.env.NOTION_TOKEN_V2,
7+
kyOptions: {
8+
hooks: {
9+
beforeRequest: [
10+
(request, options) => {
11+
const url = request.url.toString();
12+
13+
if (url.includes('/api/v3/syncRecordValues')) {
14+
return new Request(
15+
url.replace('/api/v3/syncRecordValues', '/api/v3/syncRecordValuesMain'),
16+
options,
17+
);
18+
}
19+
20+
return request;
21+
},
22+
],
23+
},
24+
},
725
})
826

927
export async function getPage(pageId: string) {
10-
const recordMap = await notionX.getPage(pageId)
28+
const recordMap = await notionX.getPage(pageId, )
1129
const newRecordMap = await fixMissingBlocks(recordMap)
1230
return newRecordMap
1331
}
@@ -39,12 +57,11 @@ async function fixMissingBlocks(recordMap: ExtendedRecordMap): Promise<ExtendedR
3957
return false
4058
})
4159
}
42-
const missingBlocks = await notionX.getBlocks(brokenBlockIds)
60+
const missingBlocks = brokenBlockIds?.length ? await notionX.getBlocks(brokenBlockIds) : null
4361
const newBlocks = {
4462
...recordMap.block,
4563
...missingBlocks?.recordMap?.block
4664
}
47-
4865
return {
4966
...recordMap,
5067
block: newBlocks

0 commit comments

Comments
 (0)