Skip to content

Commit 6111351

Browse files
committed
syncRecordValues API schema changed
1 parent 012b2c5 commit 6111351

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

src/api/notion.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import {
23
JSONData,
34
NotionUserType,
@@ -22,23 +23,32 @@ const loadPageChunkBody = {
2223
verticalColumns: false,
2324
};
2425

26+
let ctr=0
27+
2528
const fetchNotionData = async <T extends any>({
2629
resource,
2730
body,
2831
notionToken,
2932
}: INotionParams): Promise<T> => {
30-
const res = await fetch(`${NOTION_API}/${resource}`, {
31-
method: "POST",
32-
headers: {
33-
"content-type": "application/json",
34-
...(notionToken && { cookie: `token_v2=${notionToken}` }),
35-
},
36-
37-
body: JSON.stringify(body),
38-
});
33+
try {
34+
const res = await fetch(`${NOTION_API}/${resource}`, {
35+
method: "POST",
36+
headers: {
37+
"content-type": "application/json",
38+
"referer": "https://phagedirectory.notion.site/CUE-REDCap-eCRF-Data-Dictionary-Model-ca9b547e6ab5411e96c432024ed61b52",
39+
"origin": "https://phagedirectory.notion.site",
40+
...(notionToken && { cookie: `token_v2=${notionToken}` }),
41+
},
3942

40-
let json = await res.json()
41-
return json;
43+
body: JSON.stringify(body),
44+
});
45+
46+
let json = await res.json()
47+
return json;
48+
} catch(e) {
49+
console.error('fetchNotionData error:', e)
50+
throw new Error('Failed to pull data from Notion')
51+
}
4252
};
4353

4454
export const fetchPageById = async (pageId: string, notionToken?: string) => {
@@ -131,12 +141,11 @@ export const fetchBlocks = async (
131141
return await fetchNotionData<LoadPageChunkData>({
132142
resource: "syncRecordValues",
133143
body: {
134-
recordVersionMap: {
135-
block: blockList.reduce((obj, blockId) => {
136-
obj[blockId] = -1;
137-
return obj;
138-
}, {} as { [key: string]: -1 }),
139-
},
144+
requests: blockList.map((id) => ({
145+
id,
146+
table: "block",
147+
version: -1,
148+
})),
140149
},
141150
notionToken,
142151
});

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ const handleRequest = async (fetchEvent: FetchEvent): Promise<Response> => {
9999
return getResponseAndPersist();
100100
};
101101

102+
103+
// cloudflare workers entry
102104
self.addEventListener("fetch", async (event: Event) => {
103105
const fetchEvent = event as FetchEvent;
104106
fetchEvent.respondWith(handleRequest(fetchEvent));
105-
});
107+
});

webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
transpileOnly: true,
2424
},
2525
},
26-
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
2726
],
2827
},
2928
optimization: {

webpack.config_old.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
const path = require("path");
3+
4+
const mode = process.env.NODE_ENV || "production";
5+
6+
module.exports = {
7+
output: {
8+
filename: `worker.${mode}.js`,
9+
path: path.join(__dirname, "dist"),
10+
},
11+
target: "webworker",
12+
devtool: "source-map",
13+
mode,
14+
resolve: {
15+
extensions: [".ts", ".js"],
16+
},
17+
module: {
18+
rules: [
19+
{
20+
test: /\.tsx?$/,
21+
loader: "ts-loader",
22+
options: {
23+
transpileOnly: true,
24+
},
25+
},
26+
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
27+
],
28+
},
29+
optimization: {
30+
usedExports: true,
31+
},
32+
};

0 commit comments

Comments
 (0)