@wirecat/notion-cli 0.0.0-stage → 0.1.0
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/CHANGELOG.md +33 -0
- package/LICENSE +204 -0
- package/README.md +36 -2
- package/contracts/wirecat.json +1315 -0
- package/dist/bin/notion.d.ts +3 -0
- package/dist/bin/notion.d.ts.map +1 -0
- package/dist/bin/notion.js +40 -0
- package/dist/bin/notion.js.map +1 -0
- package/dist/bundle/all-profiles-OETMCOLN.js +278 -0
- package/dist/bundle/anthropic-5Y3O2TYM.js +91 -0
- package/dist/bundle/app-server-IVWBIVHC.js +231 -0
- package/dist/bundle/bun-EO636SAD.js +169 -0
- package/dist/bundle/bun-sqlite-C2T7QJ2M.js +76 -0
- package/dist/bundle/chunk-24FAYAML.js +52 -0
- package/dist/bundle/chunk-2YR3RYT4.js +73 -0
- package/dist/bundle/chunk-35K5T6WV.js +24 -0
- package/dist/bundle/chunk-3D3PFXBP.js +2315 -0
- package/dist/bundle/chunk-47R43UVJ.js +1068 -0
- package/dist/bundle/chunk-4GC5DBHW.js +100 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-64D5VUZ4.js +9564 -0
- package/dist/bundle/chunk-66PL7P4C.js +23 -0
- package/dist/bundle/chunk-7FII4DCE.js +362 -0
- package/dist/bundle/chunk-7N5QB6NL.js +156 -0
- package/dist/bundle/chunk-AE2KQ37N.js +95 -0
- package/dist/bundle/chunk-AQZO3ITW.js +58 -0
- package/dist/bundle/chunk-B2WFKFYL.js +1488 -0
- package/dist/bundle/chunk-B2XKEEFX.js +230 -0
- package/dist/bundle/chunk-B4B65XIO.js +73 -0
- package/dist/bundle/chunk-BWICUW7W.js +288 -0
- package/dist/bundle/chunk-CLG2ISQH.js +206 -0
- package/dist/bundle/chunk-CWVAYQXI.js +185 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DIM5YWBU.js +53 -0
- package/dist/bundle/chunk-EGTBL3MJ.js +6848 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EPAZ7DJB.js +783 -0
- package/dist/bundle/chunk-ESZT4WW3.js +142 -0
- package/dist/bundle/chunk-EU5WCOMQ.js +4001 -0
- package/dist/bundle/chunk-F6MLJ3V5.js +72 -0
- package/dist/bundle/chunk-FF4DDBCB.js +1028 -0
- package/dist/bundle/chunk-GA3URWIF.js +46 -0
- package/dist/bundle/chunk-HRTIRRXR.js +3112 -0
- package/dist/bundle/chunk-HWRKURQH.js +54 -0
- package/dist/bundle/chunk-IQWEJEB5.js +39724 -0
- package/dist/bundle/chunk-JK44XO2S.js +392 -0
- package/dist/bundle/chunk-JKIN5TOU.js +131 -0
- package/dist/bundle/chunk-K5TWMQSY.js +188 -0
- package/dist/bundle/chunk-KHOVVPLC.js +18 -0
- package/dist/bundle/chunk-NLDYZBTC.js +5862 -0
- package/dist/bundle/chunk-OWJDC4CB.js +217 -0
- package/dist/bundle/chunk-QBC23NHD.js +38 -0
- package/dist/bundle/chunk-QC3KOJT4.js +300 -0
- package/dist/bundle/chunk-R6ZM45NF.js +1239 -0
- package/dist/bundle/chunk-RAZKIHGH.js +76 -0
- package/dist/bundle/chunk-RDZ7SVBZ.js +731 -0
- package/dist/bundle/chunk-RLSFOR2D.js +161 -0
- package/dist/bundle/chunk-RSIS7BR7.js +2778 -0
- package/dist/bundle/chunk-ST2UC7FS.js +1324 -0
- package/dist/bundle/chunk-TR7R5DL4.js +370 -0
- package/dist/bundle/chunk-TSCIIXN3.js +106 -0
- package/dist/bundle/chunk-UWIA2G6Q.js +12737 -0
- package/dist/bundle/chunk-UWW24JQF.js +66 -0
- package/dist/bundle/chunk-WK3OSDNV.js +1197 -0
- package/dist/bundle/chunk-WM7663C2.js +1221 -0
- package/dist/bundle/chunk-WVZFXI36.js +274 -0
- package/dist/bundle/chunk-WWMB4UHF.js +78 -0
- package/dist/bundle/chunk-XC5CKHX2.js +63 -0
- package/dist/bundle/chunk-XL2HXHP3.js +82 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YA4LSSDZ.js +64499 -0
- package/dist/bundle/chunk-ZI3YTXSF.js +2 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/command-contract-6G5DC2FN.js +35 -0
- package/dist/bundle/command-server-entry-A66DJ3MH.js +164 -0
- package/dist/bundle/decode-7XOFRAAT.js +163 -0
- package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
- package/dist/bundle/dispatch-FEKU5UXC.js +411 -0
- package/dist/bundle/dist-YFKABFFF.js +7577 -0
- package/dist/bundle/echarts-XD2JSWU4.js +42501 -0
- package/dist/bundle/embed-F3HYGAF7.js +38 -0
- package/dist/bundle/embedder-GSEDDUH7.js +111 -0
- package/dist/bundle/failure-HDJLR2YJ.js +25 -0
- package/dist/bundle/first-run-TXNTIUSP.js +28 -0
- package/dist/bundle/first-screen-JZPJND7J.js +33 -0
- package/dist/bundle/instructions-NZGJ4FW5.js +11 -0
- package/dist/bundle/mcp-VFIOZDVY.js +167 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-RPKPDYQS.js +176 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-KH2UUYVO.js +74 -0
- package/dist/bundle/notion.js +185 -0
- package/dist/bundle/oauth-NKAI7TQD.js +20 -0
- package/dist/bundle/open-WSAEAA2V.js +23 -0
- package/dist/bundle/openai-JPVDGHG5.js +238 -0
- package/dist/bundle/process-5ZFVKOQX.js +91 -0
- package/dist/bundle/program-M3D56D6T.js +28854 -0
- package/dist/bundle/prompt-FROYQ5LV.js +17 -0
- package/dist/bundle/recognize-NYCHQMCX.js +26 -0
- package/dist/bundle/remote-4OERF3Z4.js +32 -0
- package/dist/bundle/rerank-TEGXFUWY.js +52 -0
- package/dist/bundle/schemas-MZNNOEYN.js +12214 -0
- package/dist/bundle/serve-HLYYBAXY.js +199 -0
- package/dist/bundle/server-D5OYNEUW.js +193 -0
- package/dist/bundle/server-LWZGVMNW.js +62 -0
- package/dist/bundle/sqlite-runtime-H2S5RR2F.js +20 -0
- package/dist/bundle/state-OPOXCDZL.js +36 -0
- package/dist/bundle/store-NHMXEJPD.js +164 -0
- package/dist/bundle/store-Y3KRLCJ7.js +281 -0
- package/dist/bundle/store-maintenance-command-D4W7WSLQ.js +53 -0
- package/dist/commands/api.d.ts +4 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +140 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/comments.d.ts +3 -0
- package/dist/commands/comments.d.ts.map +1 -0
- package/dist/commands/comments.js +114 -0
- package/dist/commands/comments.js.map +1 -0
- package/dist/commands/databases.d.ts +3 -0
- package/dist/commands/databases.d.ts.map +1 -0
- package/dist/commands/databases.js +65 -0
- package/dist/commands/databases.js.map +1 -0
- package/dist/commands/documents.d.ts +3 -0
- package/dist/commands/documents.d.ts.map +1 -0
- package/dist/commands/documents.js +41 -0
- package/dist/commands/documents.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +104 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +46 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +58 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +45603 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +3 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +2089 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/metadata.d.ts +6 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/metadata.js +24 -0
- package/dist/generated/metadata.js.map +1 -0
- package/dist/generated/schemas.d.ts +1223 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +11557 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +11120 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +29 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/notion/client.d.ts +42 -0
- package/dist/notion/client.d.ts.map +1 -0
- package/dist/notion/client.js +118 -0
- package/dist/notion/client.js.map +1 -0
- package/dist/notion/errors.d.ts +24 -0
- package/dist/notion/errors.d.ts.map +1 -0
- package/dist/notion/errors.js +102 -0
- package/dist/notion/errors.js.map +1 -0
- package/dist/notion/ids.d.ts +7 -0
- package/dist/notion/ids.d.ts.map +1 -0
- package/dist/notion/ids.js +37 -0
- package/dist/notion/ids.js.map +1 -0
- package/dist/notion/links.d.ts +6 -0
- package/dist/notion/links.d.ts.map +1 -0
- package/dist/notion/links.js +22 -0
- package/dist/notion/links.js.map +1 -0
- package/dist/notion/notion.d.ts +95 -0
- package/dist/notion/notion.d.ts.map +1 -0
- package/dist/notion/notion.js +269 -0
- package/dist/notion/notion.js.map +1 -0
- package/dist/notion/port.d.ts +13 -0
- package/dist/notion/port.d.ts.map +1 -0
- package/dist/notion/port.js +60 -0
- package/dist/notion/port.js.map +1 -0
- package/dist/notion/read-posts.d.ts +36 -0
- package/dist/notion/read-posts.d.ts.map +1 -0
- package/dist/notion/read-posts.js +24 -0
- package/dist/notion/read-posts.js.map +1 -0
- package/dist/notion/reads.d.ts +327 -0
- package/dist/notion/reads.d.ts.map +1 -0
- package/dist/notion/reads.js +18 -0
- package/dist/notion/reads.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +62 -0
- package/dist/program.js.map +1 -0
- package/dist/sample/comments.d.ts +61 -0
- package/dist/sample/comments.d.ts.map +1 -0
- package/dist/sample/comments.js +39 -0
- package/dist/sample/comments.js.map +1 -0
- package/dist/sample/records.d.ts +16 -0
- package/dist/sample/records.d.ts.map +1 -0
- package/dist/sample/records.js +22 -0
- package/dist/sample/records.js.map +1 -0
- package/dist/sample/transport.d.ts +42 -0
- package/dist/sample/transport.d.ts.map +1 -0
- package/dist/sample/transport.js +153 -0
- package/dist/sample/transport.js.map +1 -0
- package/dist/sync/cursor.d.ts +54 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +52 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/front-matter.d.ts +10 -0
- package/dist/sync/front-matter.d.ts.map +1 -0
- package/dist/sync/front-matter.js +114 -0
- package/dist/sync/front-matter.js.map +1 -0
- package/dist/sync/markdown.d.ts +8 -0
- package/dist/sync/markdown.d.ts.map +1 -0
- package/dist/sync/markdown.js +40 -0
- package/dist/sync/markdown.js.map +1 -0
- package/dist/sync/source.d.ts +64 -0
- package/dist/sync/source.d.ts.map +1 -0
- package/dist/sync/source.js +634 -0
- package/dist/sync/source.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +85 -4
- package/skills/notion-cli/SKILL.md +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generated/types.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,gEAAgE;AAChE,qBAAqB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ManifestIdentity } from "@wirecat/cli-base/wcat/manifest";
|
|
2
|
+
import type { AppIdentity } from "@wirecat/cli-core/cli";
|
|
3
|
+
export declare const PACKAGE = "@wirecat/notion-cli";
|
|
4
|
+
export declare const IDENTITY: AppIdentity;
|
|
5
|
+
export declare const DESKTOP: ManifestIdentity;
|
|
6
|
+
export declare const SKILL: import("url").URL;
|
|
7
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD,eAAO,MAAM,OAAO,wBAAwB,CAAA;AAE5C,eAAO,MAAM,QAAQ,EAAE,WAUtB,CAAA;AAID,eAAO,MAAM,OAAO,EAAE,gBAUrB,CAAA;AAED,eAAO,MAAM,KAAK,mBAA4D,CAAA"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DETAILS, REASONS } from "./notion/errors.js";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
3
|
+
export const PACKAGE = "@wirecat/notion-cli";
|
|
4
|
+
export const IDENTITY = {
|
|
5
|
+
command: "notion",
|
|
6
|
+
appName: "notion-cli",
|
|
7
|
+
envPrefix: "WCNOTION",
|
|
8
|
+
description: "Notion pages and databases for you and your agent, read live with your own token",
|
|
9
|
+
version: VERSION,
|
|
10
|
+
issues: "https://github.com/WireCatLabs/notion-cli/issues/new",
|
|
11
|
+
messenger: false,
|
|
12
|
+
contentLanguages: ["en", "ru", "es"],
|
|
13
|
+
errors: { reasons: REASONS, details: DETAILS },
|
|
14
|
+
};
|
|
15
|
+
// What `wcat` and WireCat Desktop show before the tool is installed. The bin passes it to wcatStart before anything
|
|
16
|
+
// else loads; src/wcat.ts adds the permission keys.
|
|
17
|
+
export const DESKTOP = {
|
|
18
|
+
...IDENTITY,
|
|
19
|
+
docs: "https://github.com/WireCatLabs/notion-cli#readme",
|
|
20
|
+
// Every host the CLI contacts (WC-CMD-32).
|
|
21
|
+
hosts: ["api.notion.com"],
|
|
22
|
+
tagline: "Notion pages and databases, searchable on your computer",
|
|
23
|
+
signIn: {
|
|
24
|
+
gives: "Lets your agent read the Notion pages and databases your token can see.",
|
|
25
|
+
asks: "A Notion personal access token, or the token of an internal connection you made in Notion.",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
export const SKILL = new URL("../skills/notion-cli/SKILL.md", import.meta.url);
|
|
29
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAE5C,MAAM,CAAC,MAAM,QAAQ,GAAgB;IACnC,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,UAAU;IACrB,WAAW,EAAE,kFAAkF;IAC/F,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,sDAAsD;IAC9D,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IACpC,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE;CAC/C,CAAA;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAM,CAAC,MAAM,OAAO,GAAqB;IACvC,GAAG,QAAQ;IACX,IAAI,EAAE,kDAAkD;IACxD,2CAA2C;IAC3C,KAAK,EAAE,CAAC,gBAAgB,CAAC;IACzB,OAAO,EAAE,yDAAyD;IAClE,MAAM,EAAE;QACN,KAAK,EAAE,yEAAyE;QAChF,IAAI,EAAE,4FAA4F;KACnG;CACF,CAAA;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,+BAA+B,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Client } from "@notionhq/client";
|
|
2
|
+
import { type SleepLike } from "@wirecat/cli-base";
|
|
3
|
+
import { type FetchLike, type PacerLike } from "@wirecat/cli-base/http";
|
|
4
|
+
import { type EventSink } from "@wirecat/cli-core/cli";
|
|
5
|
+
export declare const API_HOST = "api.notion.com";
|
|
6
|
+
/** The API version every request names ([versioning](https://developers.notion.com/reference/versioning)). */
|
|
7
|
+
export declare const NOTION_VERSION = "2026-03-11";
|
|
8
|
+
/** 180 a minute per connection, the lower plan's limit; data source queries have a slower limit of their own. */
|
|
9
|
+
export declare const PACE: {
|
|
10
|
+
perMinute: number;
|
|
11
|
+
burst: number;
|
|
12
|
+
};
|
|
13
|
+
export declare const QUERY_PACE: {
|
|
14
|
+
perMinute: number;
|
|
15
|
+
burst: number;
|
|
16
|
+
};
|
|
17
|
+
/** The run record keeps the path's shape, never a page id (WC-LIFE-15). */
|
|
18
|
+
export declare const operationOf: (method: string, url: URL) => string;
|
|
19
|
+
/** Search, queries and the other POSTs in READ_POSTS change nothing: they may be sent again. */
|
|
20
|
+
export declare const isRead: (method: string, url: URL) => boolean;
|
|
21
|
+
export interface NotionClientOptions {
|
|
22
|
+
token: string;
|
|
23
|
+
fetch?: FetchLike | undefined;
|
|
24
|
+
signal?: AbortSignal | undefined;
|
|
25
|
+
events?: EventSink | undefined;
|
|
26
|
+
pacer?: PacerLike | undefined;
|
|
27
|
+
/** The data source queries' own pace, taken on top of `pacer`. */
|
|
28
|
+
queryPacer?: PacerLike | undefined;
|
|
29
|
+
sleep?: SleepLike;
|
|
30
|
+
now?: () => Date;
|
|
31
|
+
/** Sees every answer Notion gives, as `notionClock` does for its Date header. */
|
|
32
|
+
onAnswer?: (response: Response) => void;
|
|
33
|
+
}
|
|
34
|
+
/** Every request's one path to Notion: paced per profile, retried by cli-base, data source queries on a pace of their own. */
|
|
35
|
+
export declare const notionFetch: (options: Omit<NotionClientOptions, "token">) => FetchLike;
|
|
36
|
+
/**
|
|
37
|
+
* The SDK puts the token in the Authorization header, as the `api` commands' executor does. The SDK's own retries and console
|
|
38
|
+
* logger are off: retries are cli-base's, paced by cli-core's Pacer, and the logger would print Notion's messages and
|
|
39
|
+
* answer bodies (WC-SECR-6, WC-OUT-20).
|
|
40
|
+
*/
|
|
41
|
+
export declare const notionClient: (options: NotionClientOptions) => Client;
|
|
42
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAA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AU3D,CAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Client } from "@notionhq/client";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { hostFetch, retrying, statusToCode } from "@wirecat/cli-base/http";
|
|
4
|
+
import { providerRequest } from "@wirecat/cli-core/cli";
|
|
5
|
+
import { BLOCKED, blocked, NOTION } from "./errors.js";
|
|
6
|
+
import { READ_POST_PATHS } from "./read-posts.js";
|
|
7
|
+
export const API_HOST = "api.notion.com";
|
|
8
|
+
/** The API version every request names ([versioning](https://developers.notion.com/reference/versioning)). */
|
|
9
|
+
export const NOTION_VERSION = "2026-03-11";
|
|
10
|
+
/** Notion ends a request after 60 s ([status codes](https://developers.notion.com/reference/status-codes), 503). */
|
|
11
|
+
const EXCHANGE_MS = 70_000;
|
|
12
|
+
const LARGEST_ANSWER = 16 * 1024 * 1024;
|
|
13
|
+
/** A pace or retry wait longer than this ends the run with `rate_limited` instead of sitting in it. */
|
|
14
|
+
const LONGEST_WAIT_MS = 60_000;
|
|
15
|
+
/** Notion's guide retries 429 and 529 with `Retry-After`, then backs off ([request limits](https://developers.notion.com/reference/request-limits)). */
|
|
16
|
+
const RETRY = { retries: 3, baseDelayMs: 500, maxDelayMs: 10_000, maxRetryAfterMs: LONGEST_WAIT_MS };
|
|
17
|
+
/** 180 a minute per connection, the lower plan's limit; data source queries have a slower limit of their own. */
|
|
18
|
+
export const PACE = { perMinute: 170, burst: 10 };
|
|
19
|
+
export const QUERY_PACE = { perMinute: 60, burst: 3 };
|
|
20
|
+
const ID = /[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}/giu;
|
|
21
|
+
const QUERY = /^\/v1\/data_sources\/[^/]+\/query$/u;
|
|
22
|
+
/** The run record keeps the path's shape, never a page id (WC-LIFE-15). */
|
|
23
|
+
export const operationOf = (method, url) => `${method} ${url.pathname.replace(ID, ":id")}`;
|
|
24
|
+
/** Search, queries and the other POSTs in READ_POSTS change nothing: they may be sent again. */
|
|
25
|
+
export const isRead = (method, url) => method === "GET" || (method === "POST" && READ_POST_PATHS.some((path) => path.test(url.pathname)));
|
|
26
|
+
const both = (first, second) => ({
|
|
27
|
+
reserve: async () => Math.max(await first.reserve(), await second.reserve()),
|
|
28
|
+
holdFor: async (ms) => {
|
|
29
|
+
await Promise.all([first.holdFor(ms), second.holdFor(ms)]);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
/** The SDK reads the whole body as text; past the cap the stream fails, and the SDK passes that error on as it is. */
|
|
33
|
+
const bounded = (response) => {
|
|
34
|
+
if (!response.body)
|
|
35
|
+
return response;
|
|
36
|
+
let bytes = 0;
|
|
37
|
+
const capped = response.body.pipeThrough(new TransformStream({
|
|
38
|
+
transform(chunk, controller) {
|
|
39
|
+
bytes += chunk.byteLength;
|
|
40
|
+
if (bytes > LARGEST_ANSWER)
|
|
41
|
+
controller.error(new CliError("invalid_response", `${NOTION}'s answer is over ${LARGEST_ANSWER} bytes`));
|
|
42
|
+
else
|
|
43
|
+
controller.enqueue(chunk);
|
|
44
|
+
},
|
|
45
|
+
}));
|
|
46
|
+
return new Response(capped, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
47
|
+
};
|
|
48
|
+
/** Notion's 429 body names why; a blocked connection must reach cli-base's retry as a failure, not a 429. */
|
|
49
|
+
const blockedAnswer = async (response) => {
|
|
50
|
+
try {
|
|
51
|
+
const body = (await response.clone().json());
|
|
52
|
+
return body.additional_data?.rate_limit_reason === BLOCKED;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* One attempt: only api.notion.com, no redirect (it would carry the token elsewhere), the run's signal, and a record
|
|
60
|
+
* of the call under its path template. A failure to reach Notion is already a retryable CliError from `hostFetch`.
|
|
61
|
+
*/
|
|
62
|
+
const attempt = (send, options) => async (input, init = {}) => {
|
|
63
|
+
const url = new URL(String(input));
|
|
64
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
65
|
+
const end = providerRequest(operationOf(method, url), options.events, { method, transport: "http" });
|
|
66
|
+
try {
|
|
67
|
+
const response = await send(url, {
|
|
68
|
+
...init,
|
|
69
|
+
redirect: "error",
|
|
70
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
71
|
+
});
|
|
72
|
+
options.onAnswer?.(response);
|
|
73
|
+
if (response.status === 429 && (await blockedAnswer(response))) {
|
|
74
|
+
await response.body?.cancel().catch(() => { });
|
|
75
|
+
throw blocked({ status: 429, notion_code: "rate_limited", sent: false });
|
|
76
|
+
}
|
|
77
|
+
end({ status: response.status, ...(response.ok ? {} : { errorCode: statusToCode(response.status) }) });
|
|
78
|
+
return bounded(response);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
end({ error, errorCode: error instanceof CliError ? error.code : "network_error" });
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/** Every request's one path to Notion: paced per profile, retried by cli-base, data source queries on a pace of their own. */
|
|
86
|
+
export const notionFetch = (options) => {
|
|
87
|
+
const once = attempt(hostFetch({ hosts: [API_HOST], timeoutMs: EXCHANGE_MS, ...(options.fetch ? { fetch: options.fetch } : {}) }), options);
|
|
88
|
+
const common = {
|
|
89
|
+
retry: RETRY,
|
|
90
|
+
budget: LONGEST_WAIT_MS,
|
|
91
|
+
reads: (method, url) => isRead(method, url),
|
|
92
|
+
...(options.sleep ? { sleep: options.sleep } : {}),
|
|
93
|
+
...(options.now ? { now: options.now } : {}),
|
|
94
|
+
};
|
|
95
|
+
const general = retrying(once, { ...common, ...(options.pacer ? { pacer: options.pacer } : {}) });
|
|
96
|
+
const queryPacer = options.pacer && options.queryPacer
|
|
97
|
+
? both(options.pacer, options.queryPacer)
|
|
98
|
+
: (options.queryPacer ?? options.pacer);
|
|
99
|
+
const queries = retrying(once, { ...common, ...(queryPacer ? { pacer: queryPacer } : {}) });
|
|
100
|
+
return (input, init) => (QUERY.test(new URL(String(input)).pathname) ? queries : general)(input, init);
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The SDK puts the token in the Authorization header, as the `api` commands' executor does. The SDK's own retries and console
|
|
104
|
+
* logger are off: retries are cli-base's, paced by cli-core's Pacer, and the logger would print Notion's messages and
|
|
105
|
+
* answer bodies (WC-SECR-6, WC-OUT-20).
|
|
106
|
+
*/
|
|
107
|
+
export const notionClient = (options) => {
|
|
108
|
+
const fetch = notionFetch(options);
|
|
109
|
+
return new Client({
|
|
110
|
+
auth: options.token,
|
|
111
|
+
notionVersion: NOTION_VERSION,
|
|
112
|
+
fetch: fetch,
|
|
113
|
+
retry: false,
|
|
114
|
+
timeoutMs: EXCHANGE_MS + LONGEST_WAIT_MS + 10_000,
|
|
115
|
+
logger: () => { },
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAkB,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAkB,SAAS,EAAkB,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1G,OAAO,EAAkB,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AACxC,8GAA8G;AAC9G,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAA;AAE1C,oHAAoH;AACpH,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,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,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
/** notion's own reasons; the shared ones (`session.missing`, `offline.refused`, `provider.*`) are cli-core's and cli-base's. */
|
|
3
|
+
export declare const REASONS: {
|
|
4
|
+
reason: string;
|
|
5
|
+
code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "conflict" | "internal_error" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
|
|
6
|
+
message: string;
|
|
7
|
+
details: string[];
|
|
8
|
+
step?: string | undefined;
|
|
9
|
+
}[];
|
|
10
|
+
/** Notion's error code and rate-limit reason are fixed words from its docs, never text it was sent. */
|
|
11
|
+
export declare const DETAILS: string[];
|
|
12
|
+
export declare const NOTION = "Notion";
|
|
13
|
+
/** A 429 with this reason is not a pace to wait out: "Retrying won't help" (Notion's request limits page). */
|
|
14
|
+
export declare const BLOCKED = "public_api_request_blocked";
|
|
15
|
+
export declare const blocked: (base?: Record<string, unknown>) => CliError;
|
|
16
|
+
/**
|
|
17
|
+
* Every Notion refusal as a CliError, by Notion's documented codes
|
|
18
|
+
* ([status codes](https://developers.notion.com/reference/status-codes)). Notion's own message is never repeated: it
|
|
19
|
+
* can quote what was sent, and names a connection (WC-SECR-6).
|
|
20
|
+
*/
|
|
21
|
+
export declare const failureOf: (error: unknown) => unknown;
|
|
22
|
+
/** An SDK call with its failure mapped; a CliError from the fetch chain passes through as it is. */
|
|
23
|
+
export declare const mapped: <T>(call: () => Promise<T>) => Promise<T>;
|
|
24
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/notion/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAc,MAAM,mBAAmB,CAAA;AAIxD,gIAAgI;AAChI,eAAO,MAAM,OAAO;;;;;;GAgBnB,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,OAAO,UAAuC,CAAA;AAE3D,eAAO,MAAM,MAAM,WAAW,CAAA;AAE9B,8GAA8G;AAC9G,eAAO,MAAM,OAAO,+BAA+B,CAAA;AAEnD,eAAO,MAAM,OAAO,UAAU,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAQ,QAK1D,CAAA;AASH;;;;GAIG;AACH,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,OA8D1C,CAAA;AAED,oGAAoG;AACpG,eAAO,MAAM,MAAM,GAAU,CAAC,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAMjE,CAAA"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { APIResponseError, isHTTPResponseError, RequestTimeoutError } from "@notionhq/client";
|
|
2
|
+
import { CliError, isCliError } from "@wirecat/cli-base";
|
|
3
|
+
import { providerWaitMs, statusToCode } from "@wirecat/cli-base/http";
|
|
4
|
+
import { defineReasons } from "@wirecat/cli-base/standards";
|
|
5
|
+
/** notion's own reasons; the shared ones (`session.missing`, `offline.refused`, `provider.*`) are cli-core's and cli-base's. */
|
|
6
|
+
export const REASONS = defineReasons([
|
|
7
|
+
["notion.token-refused", "authentication_error", "Notion refused the token"],
|
|
8
|
+
["notion.restricted", "permission_error", "the token may not read or change this"],
|
|
9
|
+
["notion.blocked", "permission_error", "Notion has restricted this connection's API access"],
|
|
10
|
+
["notion.not-shared", "not_found", "no such page or database, or it is not shared with this token"],
|
|
11
|
+
["notion.refused", "validation_error", "Notion refused the request as it was sent"],
|
|
12
|
+
["notion.conflict", "conflict", "Notion could not save it because it changed at the same time"],
|
|
13
|
+
["notion.rate-limited", "rate_limited", "Notion asked to slow down"],
|
|
14
|
+
["notion.unavailable", "provider_unavailable", "Notion is down or overloaded"],
|
|
15
|
+
["notion.invalid-response", "invalid_response", "Notion's answer does not have the documented shape"],
|
|
16
|
+
["notion.id-invalid", "validation_error", "that is not a Notion id or link"],
|
|
17
|
+
["notion.truncated", "provider_error", "Notion gave only part of the page"],
|
|
18
|
+
].map(([reason, code, message]) => ({ reason, code, message, details: [] })));
|
|
19
|
+
/** Notion's error code and rate-limit reason are fixed words from its docs, never text it was sent. */
|
|
20
|
+
export const DETAILS = ["notion_code", "rate_limit_reason"];
|
|
21
|
+
export const NOTION = "Notion";
|
|
22
|
+
/** A 429 with this reason is not a pace to wait out: "Retrying won't help" (Notion's request limits page). */
|
|
23
|
+
export const BLOCKED = "public_api_request_blocked";
|
|
24
|
+
export const blocked = (base = {}) => new CliError("permission_error", `${NOTION} has restricted this connection's API access; retrying will not help, contact Notion support`, { ...base, rate_limit_reason: BLOCKED, reason: "notion.blocked" });
|
|
25
|
+
const SIGN_IN = "sign in again with `notion <profile> session start`";
|
|
26
|
+
const additional = (error, key) => {
|
|
27
|
+
const value = error.additional_data?.[key];
|
|
28
|
+
return typeof value === "string" ? value : undefined;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Every Notion refusal as a CliError, by Notion's documented codes
|
|
32
|
+
* ([status codes](https://developers.notion.com/reference/status-codes)). Notion's own message is never repeated: it
|
|
33
|
+
* can quote what was sent, and names a connection (WC-SECR-6).
|
|
34
|
+
*/
|
|
35
|
+
export const failureOf = (error) => {
|
|
36
|
+
if (isCliError(error))
|
|
37
|
+
return error;
|
|
38
|
+
if (error instanceof RequestTimeoutError)
|
|
39
|
+
return new CliError("timeout", `${NOTION} did not answer in time`, { retryable: true });
|
|
40
|
+
if (!isHTTPResponseError(error))
|
|
41
|
+
return error;
|
|
42
|
+
const status = error.status;
|
|
43
|
+
const notion = APIResponseError.isAPIResponseError(error) ? error : undefined;
|
|
44
|
+
const code = notion?.code ?? "unknown";
|
|
45
|
+
const base = {
|
|
46
|
+
status,
|
|
47
|
+
notion_code: code,
|
|
48
|
+
...(error.request_id ? { request_id: error.request_id } : {}),
|
|
49
|
+
};
|
|
50
|
+
if (code === "unauthorized" || status === 401)
|
|
51
|
+
return new CliError("authentication_error", `${NOTION} refused the token; ${SIGN_IN}`, {
|
|
52
|
+
...base,
|
|
53
|
+
reason: "notion.token-refused",
|
|
54
|
+
});
|
|
55
|
+
if (code === "rate_limited" || status === 429 || code === "service_overload" || status === 529) {
|
|
56
|
+
const reason = notion ? additional(notion, "rate_limit_reason") : undefined;
|
|
57
|
+
if (reason === BLOCKED)
|
|
58
|
+
return blocked(base);
|
|
59
|
+
const wait = error.headers instanceof Headers ? providerWaitMs(error.headers, () => new Date()) : undefined;
|
|
60
|
+
return new CliError("rate_limited", `${NOTION} asked to slow down; run the command again later`, {
|
|
61
|
+
...base,
|
|
62
|
+
...(reason ? { rate_limit_reason: reason } : {}),
|
|
63
|
+
...(wait === undefined ? {} : { retry_after_ms: wait }),
|
|
64
|
+
retryable: true,
|
|
65
|
+
reason: "notion.rate-limited",
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (code === "restricted_resource" || status === 403)
|
|
69
|
+
return new CliError("permission_error", `${NOTION} says this token may not do that`, {
|
|
70
|
+
...base,
|
|
71
|
+
reason: "notion.restricted",
|
|
72
|
+
});
|
|
73
|
+
if (code === "object_not_found" || status === 404)
|
|
74
|
+
return new CliError("not_found", `${NOTION} has no such page or database, or it is not shared with this token: in Notion, open it, ` +
|
|
75
|
+
"choose ••• → Connections, and add the connection", { ...base, reason: "notion.not-shared" });
|
|
76
|
+
if (code === "conflict_error" || status === 409)
|
|
77
|
+
return new CliError("conflict", `${NOTION} could not save it because it changed at the same time`, {
|
|
78
|
+
...base,
|
|
79
|
+
reason: "notion.conflict",
|
|
80
|
+
});
|
|
81
|
+
if (status >= 500)
|
|
82
|
+
return new CliError("provider_unavailable", `${NOTION} is unavailable (HTTP ${status}); try again later`, {
|
|
83
|
+
...base,
|
|
84
|
+
retryable: true,
|
|
85
|
+
reason: "notion.unavailable",
|
|
86
|
+
});
|
|
87
|
+
const refused = statusToCode(status) === "validation_error";
|
|
88
|
+
return new CliError(refused ? "validation_error" : "provider_error", `${NOTION} refused the request (HTTP ${status}, ${code})`, {
|
|
89
|
+
...base,
|
|
90
|
+
reason: refused ? "notion.refused" : "provider.refused",
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
/** An SDK call with its failure mapped; a CliError from the fetch chain passes through as it is. */
|
|
94
|
+
export const mapped = async (call) => {
|
|
95
|
+
try {
|
|
96
|
+
return await call();
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
throw failureOf(error);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/notion/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC7F,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAE3D,gIAAgI;AAChI,MAAM,CAAC,MAAM,OAAO,GAAG,aAAa,CAEhC;IACE,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,0BAA0B,CAAC;IAC5E,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,uCAAuC,CAAC;IAClF,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,oDAAoD,CAAC;IAC5F,CAAC,mBAAmB,EAAE,WAAW,EAAE,+DAA+D,CAAC;IACnG,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,2CAA2C,CAAC;IACnF,CAAC,iBAAiB,EAAE,UAAU,EAAE,8DAA8D,CAAC;IAC/F,CAAC,qBAAqB,EAAE,cAAc,EAAE,2BAA2B,CAAC;IACpE,CAAC,oBAAoB,EAAE,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I;YACf,MAAM,EAAE,oBAAoB;SAC7B,CAAC,CAAA;IACJ,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,KAAK,kBAAkB,CAAA;IAC3D,OAAO,IAAI,QAAQ,CACjB,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,gBAAgB,EAC/C,GAAG,MAAM,8BAA8B,MAAM,KAAK,IAAI,GAAG,EACzD;QACE,GAAG,IAAI;QACP,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,kBAAkB;KACxD,CACF,CAAA;AACH,CAAC,CAAA;AAED,oGAAoG;AACpG,MAAM,CAAC,MAAM,MAAM,GAAG,KAAK,EAAK,IAAsB,EAAc,EAAE;IACpE,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,EAAE,CAAA;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A page or database id from what a person copies: the id, with or without dashes, or its Notion link. In a link the
|
|
3
|
+
* id is the last 32 hex characters of the path; `?v=` names a view, never the database. A page opened over a
|
|
4
|
+
* database, `…/<database>?v=<view>&p=<page>`, is the page in `p=`, and the database is the one in the path.
|
|
5
|
+
*/
|
|
6
|
+
export declare const notionId: (input: string, what?: string) => string;
|
|
7
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/notion/ids.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,eAAO,MAAM,QAAQ,UAAW,MAAM,oBAAkB,MAmBvD,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
const DASHED = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
3
|
+
const COMPACT = /^[0-9a-f]{32}$/iu;
|
|
4
|
+
const IN_PATH = /([0-9a-f]{32})(?:[^0-9a-f]|$)/giu;
|
|
5
|
+
const NOTION_HOSTS = /(^|\.)(notion\.so|notion\.site|notion\.com)$/u;
|
|
6
|
+
const dashed = (hex) => `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`.toLowerCase();
|
|
7
|
+
/**
|
|
8
|
+
* A page or database id from what a person copies: the id, with or without dashes, or its Notion link. In a link the
|
|
9
|
+
* id is the last 32 hex characters of the path; `?v=` names a view, never the database. A page opened over a
|
|
10
|
+
* database, `…/<database>?v=<view>&p=<page>`, is the page in `p=`, and the database is the one in the path.
|
|
11
|
+
*/
|
|
12
|
+
export const notionId = (input, what = "page") => {
|
|
13
|
+
const text = input.trim();
|
|
14
|
+
if (DASHED.test(text))
|
|
15
|
+
return text.toLowerCase();
|
|
16
|
+
if (COMPACT.test(text))
|
|
17
|
+
return dashed(text);
|
|
18
|
+
let url;
|
|
19
|
+
try {
|
|
20
|
+
url = new URL(text);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
url = undefined;
|
|
24
|
+
}
|
|
25
|
+
if (url && url.protocol === "https:" && NOTION_HOSTS.test(url.hostname)) {
|
|
26
|
+
const peek = url.searchParams.get("p")?.replaceAll("-", "");
|
|
27
|
+
if (what === "page" && peek && COMPACT.test(peek))
|
|
28
|
+
return dashed(peek);
|
|
29
|
+
const found = [...url.pathname.matchAll(IN_PATH)].at(-1)?.[1];
|
|
30
|
+
if (found)
|
|
31
|
+
return dashed(found);
|
|
32
|
+
}
|
|
33
|
+
throw new CliError("validation_error", `give the ${what}'s id or its Notion link, such as https://www.notion.so/…`, {
|
|
34
|
+
reason: "notion.id-invalid",
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
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,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxE,MAAM,IAAI,GAAG,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC3D,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;QACtE,MAAM,KAAK,GAAG,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC7D,IAAI,KAAK;YAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IACD,MAAM,IAAI,QAAQ,CAAC,kBAAkB,EAAE,YAAY,IAAI,2DAA2D,EAAE;QAClH,MAAM,EAAE,mBAAmB;KAC5B,CAAC,CAAA;AACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/notion/links.ts"],"names":[],"mappings":"AAWA,mEAAmE;AACnE,eAAO,MAAM,kBAAkB,SAAU,MAAM,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAQhF,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notion-hosted file links are signed and valid for an hour
|
|
3
|
+
* ([file object](https://developers.notion.com/reference/file-object)): whoever reads one gets the file. The signature
|
|
4
|
+
* is in the query, so every query that carries one is cut before the text is printed or stored. Where a link ends is
|
|
5
|
+
* not known: a file name can hold `(`, `'` or `[`, and Notion's image proxy carries the signed link inside its own
|
|
6
|
+
* path, percent-encoded. So the search is for the query itself, plain or encoded, not for the link around it.
|
|
7
|
+
*/
|
|
8
|
+
const QUERY = /(?<=\S)(?:\?|%3F)[\w%.~=&;+:@/-]+/giu;
|
|
9
|
+
const KEYS = "x-amz-[\\w-]+|signature|expirationtimestamp|expires|key-pair-id|policy|token|sig|se|sp|sv";
|
|
10
|
+
const SIGNED = new RegExp(`(?:^|\\?|&|;|%3F|%26)(?:${KEYS})(?:=|%3D)`, "iu");
|
|
11
|
+
/** The text with every signed query cut, and how many were cut. */
|
|
12
|
+
export const withoutSignedLinks = (text) => {
|
|
13
|
+
let removed = 0;
|
|
14
|
+
const clean = text.replace(QUERY, (query) => {
|
|
15
|
+
if (!SIGNED.test(query))
|
|
16
|
+
return query;
|
|
17
|
+
removed += 1;
|
|
18
|
+
return "";
|
|
19
|
+
});
|
|
20
|
+
return { text: clean, removed };
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.js","sourceRoot":"","sources":["../../src/notion/links.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,KAAK,GAAG,sCAAsC,CAAA;AACpD,MAAM,IAAI,GAAG,2FAA2F,CAAA;AACxG,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,2BAA2B,IAAI,YAAY,EAAE,IAAI,CAAC,CAAA;AAE5E,mEAAmE;AACnE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAqC,EAAE;IACpF,IAAI,OAAO,GAAG,CAAC,CAAA;IACf,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QACrC,OAAO,IAAI,CAAC,CAAA;QACZ,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAA;AACjC,CAAC,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Client } from "@notionhq/client";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
export declare const accountSchema: v.StrictObjectSchema<{
|
|
4
|
+
readonly workspace: v.StrictObjectSchema<{
|
|
5
|
+
readonly id: v.StringSchema<undefined>;
|
|
6
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
7
|
+
}, undefined>;
|
|
8
|
+
readonly user: v.StrictObjectSchema<{
|
|
9
|
+
readonly id: v.StringSchema<undefined>;
|
|
10
|
+
readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
11
|
+
readonly type: v.StringSchema<undefined>;
|
|
12
|
+
readonly owner: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
13
|
+
}, undefined>;
|
|
14
|
+
}, undefined>;
|
|
15
|
+
export type Account = v.InferOutput<typeof accountSchema>;
|
|
16
|
+
export declare const documentSchema: v.StrictObjectSchema<{
|
|
17
|
+
readonly id: v.StringSchema<undefined>;
|
|
18
|
+
readonly markdown: v.StringSchema<undefined>;
|
|
19
|
+
readonly truncated: v.BooleanSchema<undefined>;
|
|
20
|
+
readonly missing_block_ids: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
21
|
+
readonly signed_links_removed: v.NumberSchema<undefined>;
|
|
22
|
+
}, undefined>;
|
|
23
|
+
export type Document = v.InferOutput<typeof documentSchema>;
|
|
24
|
+
/** A part of the answer that is not there (WC-OUT-7). */
|
|
25
|
+
export type Issue = {
|
|
26
|
+
code: "not_found" | "provider_error";
|
|
27
|
+
reason: string;
|
|
28
|
+
source: "notion";
|
|
29
|
+
};
|
|
30
|
+
export declare const databaseRowSchema: v.StrictObjectSchema<{
|
|
31
|
+
readonly id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
32
|
+
readonly data_source_id: v.StringSchema<undefined>;
|
|
33
|
+
readonly title: v.StringSchema<undefined>;
|
|
34
|
+
readonly last_edited_time: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
35
|
+
}, undefined>;
|
|
36
|
+
export type DatabaseRow = v.InferOutput<typeof databaseRowSchema>;
|
|
37
|
+
export declare const databaseSchema: v.StrictObjectSchema<{
|
|
38
|
+
readonly id: v.StringSchema<undefined>;
|
|
39
|
+
readonly title: v.StringSchema<undefined>;
|
|
40
|
+
readonly description: v.StringSchema<undefined>;
|
|
41
|
+
readonly url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
42
|
+
readonly parent: v.NullableSchema<v.StrictObjectSchema<{
|
|
43
|
+
readonly type: v.StringSchema<undefined>;
|
|
44
|
+
readonly id: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
45
|
+
}, undefined>, undefined>;
|
|
46
|
+
readonly is_inline: v.BooleanSchema<undefined>;
|
|
47
|
+
readonly in_trash: v.BooleanSchema<undefined>;
|
|
48
|
+
readonly created_time: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
49
|
+
readonly last_edited_time: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
50
|
+
readonly data_sources: v.ArraySchema<v.StrictObjectSchema<{
|
|
51
|
+
readonly id: v.StringSchema<undefined>;
|
|
52
|
+
readonly title: v.StringSchema<undefined>;
|
|
53
|
+
readonly properties: v.ArraySchema<v.StrictObjectSchema<{
|
|
54
|
+
readonly id: v.StringSchema<undefined>;
|
|
55
|
+
readonly name: v.StringSchema<undefined>;
|
|
56
|
+
readonly type: v.StringSchema<undefined>;
|
|
57
|
+
readonly options: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
|
|
58
|
+
}, undefined>, undefined>;
|
|
59
|
+
}, undefined>, undefined>;
|
|
60
|
+
}, undefined>;
|
|
61
|
+
export type Database = v.InferOutput<typeof databaseSchema>;
|
|
62
|
+
/** Every Notion read the commands make, each answer checked against its documented shape. */
|
|
63
|
+
export declare const liveReads: (client: Client) => {
|
|
64
|
+
port: import("./reads.js").NotionReads;
|
|
65
|
+
/** The token's bot user; its workspace id and bot id are the account (DESIGN.md, Sign-in). */
|
|
66
|
+
me: () => Promise<Account>;
|
|
67
|
+
/**
|
|
68
|
+
* A page as Notion-flavoured Markdown (v2). A truncated page's unknown blocks are fetched again and put in place of
|
|
69
|
+
* their `<unknown>` tag, or after the page when no tag names them. What is still not there is an issue: a block
|
|
70
|
+
* the token cannot see, or a part past Notion's limit or past the blocks fetched again.
|
|
71
|
+
*/
|
|
72
|
+
document: (id: string) => Promise<{
|
|
73
|
+
document: Document;
|
|
74
|
+
issues: Issue[];
|
|
75
|
+
}>;
|
|
76
|
+
/** The data sources the token sees, one row each with its database, by Notion's own search. */
|
|
77
|
+
databases: ({ limit, cursor, title, }: {
|
|
78
|
+
limit: number;
|
|
79
|
+
cursor?: string | undefined;
|
|
80
|
+
title?: string | undefined;
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
items: {
|
|
83
|
+
id: string | null;
|
|
84
|
+
data_source_id: string;
|
|
85
|
+
title: string;
|
|
86
|
+
last_edited_time: string | null;
|
|
87
|
+
}[];
|
|
88
|
+
hasMore: boolean;
|
|
89
|
+
cursor: string | undefined;
|
|
90
|
+
}>;
|
|
91
|
+
/** A database with each data source's id and property schema: what a query or a filter needs. */
|
|
92
|
+
database: (id: string) => Promise<Database>;
|
|
93
|
+
};
|
|
94
|
+
export type LiveReads = ReturnType<typeof liveReads>;
|
|
95
|
+
//# sourceMappingURL=notion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notion.d.ts","sourceRoot":"","sources":["../../src/notion/notion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAmH5B,eAAO,MAAM,aAAa;;;;;;;;;;;aAQxB,CAAA;AACF,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,a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