@secret-momo/notion 1.0.1 → 1.0.3

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.
package/lib/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { Client } from '@notionhq/client';
2
- export declare function newNotionClient(): Client;
2
+ export declare function newNotionClient(authToken?: string): Client;
3
3
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AA+C1C,wBAAgB,eAAe,WAM9B"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAiD1C,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,UAQjD"}
package/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@notionhq/client';
2
- import { warn, sleep } from '@secret-momo/utils';
2
+ import { logger, sleep } from '@secret-momo/utils';
3
3
 
4
4
  const NOTION_TLS_MAX_RETRIES = 5;
5
5
  function isCertOrTlsError(message) {
@@ -23,15 +23,16 @@ async function customFetch(input, init) {
23
23
  if (isLastAttempt || !isCertOrTlsError(message)) {
24
24
  throw error;
25
25
  }
26
- warn(`Notion TLS \u91CD\u8BD5\u7B2C ${attempt + 1} \u6B21, \u9519\u8BEF\u4FE1\u606F\uFF1A${message}`);
26
+ logger.child({ name: "notion" }).warn(`Notion TLS \u91CD\u8BD5\u7B2C ${attempt + 1} \u6B21, \u9519\u8BEF\u4FE1\u606F\uFF1A${message}`);
27
27
  await sleep(1e3 * attempt);
28
28
  }
29
29
  }
30
30
  throw new Error("Unexpected notion fetch retry failure");
31
31
  }
32
- function newNotionClient() {
32
+ function newNotionClient(authToken) {
33
+ const auth = authToken ?? process.env.NOTION_AUTH_TOKEN;
33
34
  return new Client({
34
- auth: process.env.NOTION_AUTH_TOKEN,
35
+ auth,
35
36
  fetch: customFetch,
36
37
  timeoutMs: 1e3 * 60 * 10
37
38
  // 10 分钟超时的时间
package/lib/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideo
4
4
  export { newNotionClient };
5
5
  export type { NumberPropertyItemObjectResponse, PageObjectResponse, RichTextItemResponse };
6
6
  export declare function n(num?: number): number | null;
7
- export declare function traverseDataSource(cb: (item: PageObjectResponse) => void): Promise<void>;
7
+ export declare function traverseDataSource(cb: (item: PageObjectResponse) => void, dataSourceId?: string): Promise<void>;
8
8
  /**
9
9
  * 从 API 返回的 page(或任意带 `id` 的对象)拼出可在浏览器打开的 Notion 页面地址
10
10
  * @param pageId - 页面 ID
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,gCAAgC,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;AAE3F,wBAAgB,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,iBAE7B;AAED,wBAAsB,kBAAkB,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,iBAM9E;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,gCAAgC,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,CAAC;AAE3F,wBAAgB,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,iBAE7B;AAED,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,EACtC,YAAY,CAAC,EAAE,MAAM,iBAMtB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE5D"}
package/lib/index.js CHANGED
@@ -5,10 +5,9 @@ export { uploadLocalFileToPageBody, uploadLocalImageToPageBody, uploadLocalVideo
5
5
  function n(num) {
6
6
  return num ?? null;
7
7
  }
8
- async function traverseDataSource(cb) {
9
- const data = await newNotionClient().dataSources.query({
10
- data_source_id: process.env.NOTION_DATA_SOURCE_ID ?? ""
11
- });
8
+ async function traverseDataSource(cb, dataSourceId) {
9
+ const data_source_id = dataSourceId ?? process.env.NOTION_DATA_SOURCE_ID ?? "";
10
+ const data = await newNotionClient().dataSources.query({ data_source_id });
12
11
  data.results.forEach((item) => cb(item));
13
12
  }
14
13
  function buildNotionPageWebUrl(pageId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@secret-momo/notion",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "files": [
5
5
  "lib"
6
6
  ],
@@ -24,25 +24,25 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@notionhq/client": "5.22.0",
27
- "@secret-momo/utils": "1.0.2"
27
+ "@secret-momo/utils": "1.1.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@eslint/config-helpers": "0.6.0",
31
31
  "@eslint/js": "10.0.1",
32
32
  "@types/bun": "1.3.14",
33
- "eslint": "10.4.1",
34
- "eslint-plugin-import-x": "4.16.2",
33
+ "eslint": "10.6.0",
34
+ "eslint-plugin-import-x": "4.17.0",
35
35
  "eslint-plugin-react": "7.37.5",
36
36
  "eslint-plugin-react-hooks": "7.1.1",
37
37
  "eslint-plugin-unused-imports": "4.4.1",
38
38
  "husky": "9.1.7",
39
39
  "jiti": "2.7.0",
40
- "lint-staged": "17.0.7",
41
- "prettier": "3.8.3",
42
- "rollup": "4.61.1",
40
+ "lint-staged": "17.0.8",
41
+ "prettier": "3.9.1",
42
+ "rollup": "4.62.2",
43
43
  "rollup-plugin-esbuild": "6.2.1",
44
44
  "typescript": "6.0.3",
45
- "typescript-eslint": "8.60.1"
45
+ "typescript-eslint": "8.62.0"
46
46
  },
47
47
  "lint-staged": {
48
48
  "*.{ts,tsx,js,jsx}": [