@notionhq/workers 0.7.0 → 0.8.1
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/dist/alpha/workflow.d.ts +30 -2
- package/dist/alpha/workflow.d.ts.map +1 -1
- package/dist/alpha/workflow.js +51 -1
- package/dist/capabilities/custom-block.d.ts +124 -0
- package/dist/capabilities/custom-block.d.ts.map +1 -0
- package/dist/capabilities/custom-block.js +22 -0
- package/dist/credential.d.ts +26 -0
- package/dist/credential.d.ts.map +1 -0
- package/dist/credential.js +176 -0
- package/dist/credential.test.d.ts +2 -0
- package/dist/credential.test.d.ts.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/worker.d.ts +48 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +78 -1
- package/package.json +1 -1
- package/src/alpha/workflow.test.ts +124 -2
- package/src/alpha/workflow.ts +92 -3
- package/src/capabilities/custom-block.ts +181 -0
- package/src/credential.test.ts +324 -0
- package/src/credential.ts +238 -0
- package/src/index.ts +15 -0
- package/src/worker.test.ts +300 -2
- package/src/worker.ts +102 -2
- package/dist/block.d.ts +0 -321
- package/dist/block.d.ts.map +0 -1
- package/dist/block.js +0 -0
- package/src/block.ts +0 -525
package/dist/alpha/workflow.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, .
|
|
|
22
22
|
* Each trigger defines a specific event or condition that causes the workflow to run.
|
|
23
23
|
*/
|
|
24
24
|
triggers: TTriggers;
|
|
25
|
-
handler: (event: WorkflowEventForTriggers<TTriggers>, context:
|
|
25
|
+
handler: (event: WorkflowEventForTriggers<TTriggers>, context: WorkflowContext) => Promise<void> | void;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* A workflow capability as returned by {@link createWorkflow}.
|
|
@@ -60,11 +60,39 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
|
|
|
60
60
|
* title: "Send Welcome Email",
|
|
61
61
|
* description: "Sends a welcome email when a new page is added",
|
|
62
62
|
* triggers: [triggers.notionPageCreated()],
|
|
63
|
-
* handler: async (event) => {
|
|
63
|
+
* handler: async (event, context) => {
|
|
64
64
|
* console.log(event.page);
|
|
65
|
+
* await context.step("Process page", async ({ id }) => {
|
|
66
|
+
* console.log(`Running step ${id}`);
|
|
67
|
+
* return processPage(event.page);
|
|
68
|
+
* });
|
|
65
69
|
* },
|
|
66
70
|
* });
|
|
67
71
|
* ```
|
|
68
72
|
*/
|
|
69
73
|
export declare function createWorkflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]]>(configuration: WorkflowConfiguration<TTriggers>): Workflow<TTriggers>;
|
|
74
|
+
/** Context passed to a workflow step. */
|
|
75
|
+
export type StepContext = {
|
|
76
|
+
/** An identifier for this invocation of the step. May be used as an idempotency key. */
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
/** Context passed to a workflow handler. */
|
|
80
|
+
export type WorkflowContext = CapabilityContext & {
|
|
81
|
+
/**
|
|
82
|
+
* Run an observable unit of work within the workflow.
|
|
83
|
+
*
|
|
84
|
+
* The callback may be synchronous or asynchronous, but `step` always returns
|
|
85
|
+
* a promise. Its return value must be JSON-serializable so it can be included
|
|
86
|
+
* in the success event written to stdout.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const page = await context.step("Fetch page", async ({ id }) => {
|
|
91
|
+
* console.log(`Running step ${id}`);
|
|
92
|
+
* return context.notion.pages.retrieve({ page_id: pageId });
|
|
93
|
+
* });
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
step: <T>(name: string, fn: (context: StepContext) => T | Promise<T>) => Promise<T>;
|
|
97
|
+
};
|
|
70
98
|
//# sourceMappingURL=workflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/alpha/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,gBAAgB,CAAC,CAAC;AAErE,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,eAAe,IAAI,gBAAgB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE7F,MAAM,MAAM,wBAAwB,CAAC,CAAC,SAAS,SAAS,eAAe,EAAE,IACxE,uBAAuB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAChC,SAAS,SAAS,SAAS,CAAC,eAAe,EAAE,GAAG,eAAe,EAAE,CAAC,IAC/D;IACH;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB,OAAO,EAAE,CACR,KAAK,EAAE,wBAAwB,CAAC,SAAS,CAAC,EAC1C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../../src/alpha/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAItD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,gBAAgB,CAAC,CAAC;AAErE,MAAM,MAAM,uBAAuB,CAAC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AAa,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,CA0CtE;AAED,yCAAyC;AACzC,MAAM,MAAM,WAAW,GAAG;IACzB,wFAAwF;IACxF,EAAE,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IACjD;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;CACpF,CAAC"}
|
package/dist/alpha/workflow.js
CHANGED
|
@@ -11,7 +11,10 @@ function createWorkflow(configuration) {
|
|
|
11
11
|
},
|
|
12
12
|
async handler(event, options) {
|
|
13
13
|
try {
|
|
14
|
-
const capabilityContext =
|
|
14
|
+
const capabilityContext = {
|
|
15
|
+
...createCapabilityContext("workflow"),
|
|
16
|
+
step
|
|
17
|
+
};
|
|
15
18
|
await configuration.handler(event, capabilityContext);
|
|
16
19
|
if (options?.concreteOutput) {
|
|
17
20
|
return { status: "success" };
|
|
@@ -34,6 +37,53 @@ function createWorkflow(configuration) {
|
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
39
|
}
|
|
40
|
+
function generateUuidV7() {
|
|
41
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
42
|
+
let timestamp = Date.now();
|
|
43
|
+
for (let index = 5; index >= 0; index--) {
|
|
44
|
+
bytes[index] = timestamp % 256;
|
|
45
|
+
timestamp = Math.floor(timestamp / 256);
|
|
46
|
+
}
|
|
47
|
+
bytes[6] = bytes[6] & 15 | 112;
|
|
48
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
49
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
50
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
51
|
+
}
|
|
52
|
+
function writeStepEvent(event, value) {
|
|
53
|
+
const tag = `__notion_step_${event}__`;
|
|
54
|
+
process.stdout.write(`
|
|
55
|
+
<${tag}>${JSON.stringify(value)}</${tag}>
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
async function step(name, fn) {
|
|
59
|
+
const context = { id: generateUuidV7() };
|
|
60
|
+
const event = { id: context.id, name };
|
|
61
|
+
writeStepEvent("started", event);
|
|
62
|
+
try {
|
|
63
|
+
const value = await fn(context);
|
|
64
|
+
writeStepEvent("success", { ...event, value });
|
|
65
|
+
writeStepEvent("completed", {
|
|
66
|
+
...event,
|
|
67
|
+
type: "success"
|
|
68
|
+
});
|
|
69
|
+
return value;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
const error = new ExecutionError(err);
|
|
72
|
+
writeStepEvent("failure", {
|
|
73
|
+
...event,
|
|
74
|
+
error: {
|
|
75
|
+
name: error.name,
|
|
76
|
+
message: error.message,
|
|
77
|
+
trace: error.stack
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
writeStepEvent("completed", {
|
|
81
|
+
...event,
|
|
82
|
+
type: "failure"
|
|
83
|
+
});
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
37
87
|
export {
|
|
38
88
|
createWorkflow
|
|
39
89
|
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon for a custom block data source. Mirrors the server/client
|
|
3
|
+
* `CustomBlockManifestIcon` (`@notionhq/shared/customViews/customBlockManifestTypes`).
|
|
4
|
+
*/
|
|
5
|
+
export type CustomBlockManifestIcon = {
|
|
6
|
+
type: "emoji";
|
|
7
|
+
emoji: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "external";
|
|
10
|
+
url: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Public-API-shaped property type names usable in a custom block manifest.
|
|
14
|
+
*/
|
|
15
|
+
export type CustomBlockManifestPropertyType = "title" | "rich_text" | "number" | "select" | "multi_select" | "status" | "date" | "people" | "files" | "checkbox" | "url" | "email" | "phone_number" | "formula" | "relation" | "rollup" | "created_time" | "created_by" | "last_edited_time" | "last_edited_by" | "last_visited_time" | "button" | "unique_id" | "location" | "verification" | "place";
|
|
16
|
+
/**
|
|
17
|
+
* Describes a single property exposed by a custom block data source.
|
|
18
|
+
*/
|
|
19
|
+
export type CustomBlockManifestProperty = {
|
|
20
|
+
name: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
type: CustomBlockManifestPropertyType;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Rich schema describing one of a custom block's data sources.
|
|
26
|
+
*/
|
|
27
|
+
export type CustomBlockManifestDataSource = {
|
|
28
|
+
/** Display name for the data source. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Optional human-readable description of the data source. */
|
|
31
|
+
description?: string;
|
|
32
|
+
/** Optional icon for the data source. */
|
|
33
|
+
icon?: CustomBlockManifestIcon;
|
|
34
|
+
/** Optional property schema keyed by property key. */
|
|
35
|
+
properties?: Record<string, CustomBlockManifestProperty>;
|
|
36
|
+
};
|
|
37
|
+
export type CustomBlockManifest = {
|
|
38
|
+
version: 1;
|
|
39
|
+
/**
|
|
40
|
+
* The block's datasources schema, mapping keys you name to {@link CustomBlockManifestDataSource}
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* {
|
|
45
|
+
* "myDataSource": {
|
|
46
|
+
* "name": "My Data Source",
|
|
47
|
+
* "description": "A description of my data source",
|
|
48
|
+
* "icon": "icon.png",
|
|
49
|
+
* "properties": {
|
|
50
|
+
* "property1": {
|
|
51
|
+
* "name": "Property 1",
|
|
52
|
+
* "type": "string"
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*/
|
|
58
|
+
dataSources: Record<string, CustomBlockManifestDataSource>;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A custom block is a front-end web app served in an iframe in the client with live data access.
|
|
62
|
+
*
|
|
63
|
+
* Available `type`s are `project` (a buildable project dir) and `static` (an already-built dir served as-is).
|
|
64
|
+
*/
|
|
65
|
+
export type CustomBlockConfiguration = ({
|
|
66
|
+
/** Buildable project dir (the default). */
|
|
67
|
+
type?: "project";
|
|
68
|
+
/** Path to the project dir, relative to the worker root (e.g. `"./blocks/foo"`). */
|
|
69
|
+
path: string;
|
|
70
|
+
/** Build command run in `path`. Defaults to `npm run build`. */
|
|
71
|
+
command?: string;
|
|
72
|
+
/** Built-output dir relative to `path`. Defaults to `dist`. */
|
|
73
|
+
output?: string;
|
|
74
|
+
} | {
|
|
75
|
+
/** An already-built browser-bundle dir; served as-is, no build step. */
|
|
76
|
+
type: "static";
|
|
77
|
+
/** Path to the prebuilt dir, relative to the worker root. */
|
|
78
|
+
path: string;
|
|
79
|
+
command?: never;
|
|
80
|
+
output?: never;
|
|
81
|
+
}) & Partial<CustomBlockManifest>;
|
|
82
|
+
/**
|
|
83
|
+
* The build source of a custom block, mirroring the server's
|
|
84
|
+
* `BlockSourceDeclaration`. `project` is a buildable dir (`command` defaults to
|
|
85
|
+
* `npm run build`, `output` to `dist`); `static` is an already-built dir served
|
|
86
|
+
* as-is.
|
|
87
|
+
*/
|
|
88
|
+
export type BlockSourceDeclaration = {
|
|
89
|
+
type: "project";
|
|
90
|
+
path: string;
|
|
91
|
+
command?: string;
|
|
92
|
+
output?: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "static";
|
|
95
|
+
path: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Config payload carried in the runtime manifest for a `_tag: "custom_block"`
|
|
99
|
+
* capability entry. The server parses this (see `RawBlockCapabilityConfig` in
|
|
100
|
+
* `capabilities-service.ts`): `source` is the build entry and `manifest` is the
|
|
101
|
+
* author-declared {@link CustomBlockManifest} describing the block's data-source
|
|
102
|
+
* schema. Data-source *bindings* are instance-level and are not carried here.
|
|
103
|
+
*/
|
|
104
|
+
export type CustomBlockCapabilityConfig = {
|
|
105
|
+
source: BlockSourceDeclaration;
|
|
106
|
+
manifest: CustomBlockManifest;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* A custom-block capability entry. Unlike other capabilities it has no runtime
|
|
110
|
+
* handler — it is a build-time/deploy-time declaration only, carried through
|
|
111
|
+
* the manifest so the server can build and bind the block on deploy.
|
|
112
|
+
*/
|
|
113
|
+
export type CustomBlockCapability = {
|
|
114
|
+
readonly _tag: "custom_block";
|
|
115
|
+
readonly key: string;
|
|
116
|
+
readonly config: CustomBlockCapabilityConfig;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Builds a custom-block capability entry from its authoring configuration. The
|
|
120
|
+
* author-declared `dataSources` schema is carried verbatim into the block
|
|
121
|
+
* {@link CustomBlockManifest}; no bindings are emitted.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createCustomBlockCapability(key: string, config: CustomBlockConfiguration): CustomBlockCapability;
|
|
124
|
+
//# sourceMappingURL=custom-block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-block.d.ts","sourceRoot":"","sources":["../../src/capabilities/custom-block.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAChC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC;;GAEG;AACH,MAAM,MAAM,+BAA+B,GACxC,OAAO,GACP,WAAW,GACX,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,OAAO,GACP,UAAU,GACV,KAAK,GACL,OAAO,GACP,cAAc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AC,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAC/B;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACpE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACzC,MAAM,EAAE,sBAAsB,CAAC;IAC/B,QAAQ,EAAE,mBAAmB,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,wBAAwB,GAC9B,qBAAqB,CAsBvB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function createCustomBlockCapability(key, config) {
|
|
2
|
+
const source = config.type === "static" ? { type: "static", path: config.path } : {
|
|
3
|
+
type: "project",
|
|
4
|
+
path: config.path,
|
|
5
|
+
...config.command !== void 0 ? { command: config.command } : {},
|
|
6
|
+
...config.output !== void 0 ? { output: config.output } : {}
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
_tag: "custom_block",
|
|
10
|
+
key,
|
|
11
|
+
config: {
|
|
12
|
+
source,
|
|
13
|
+
manifest: {
|
|
14
|
+
version: config.version ?? 1,
|
|
15
|
+
dataSources: config.dataSources ?? {}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createCustomBlockCapability
|
|
22
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A symbolic marker for the declared credential value. It is safe to include
|
|
3
|
+
* in Worker source and manifests because it never contains the stored secret.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CREDENTIAL_VALUE = "{{credential}}";
|
|
6
|
+
export type CredentialKey = string;
|
|
7
|
+
/** A Vercel-compatible collection of headers to add or replace. */
|
|
8
|
+
export type CredentialHeaderTransform = {
|
|
9
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Limits credential injection to a domain. This does not grant or deny general
|
|
13
|
+
* network egress; the sandbox's egress policy remains a separate concern.
|
|
14
|
+
*/
|
|
15
|
+
export type CredentialNetworkRule = {
|
|
16
|
+
readonly domain: string;
|
|
17
|
+
readonly transform: readonly CredentialHeaderTransform[];
|
|
18
|
+
};
|
|
19
|
+
export type CredentialConfiguration = {
|
|
20
|
+
/** Destinations and header templates where the credential may be injected. */
|
|
21
|
+
readonly network: readonly CredentialNetworkRule[];
|
|
22
|
+
};
|
|
23
|
+
export type CredentialDeclaration = CredentialConfiguration & {
|
|
24
|
+
readonly key: CredentialKey;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAkBjD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,mEAAmE;AACnE,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACnD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,yBAAyB,EAAE,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACrC,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,GAAG;IAC7D,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const CREDENTIAL_VALUE = "{{credential}}";
|
|
2
|
+
const MAX_CREDENTIALS = 100;
|
|
3
|
+
const MAX_CREDENTIAL_DECLARATIONS_BYTES = 256 * 1024;
|
|
4
|
+
const MAX_NETWORK_RULES_PER_CREDENTIAL = 20;
|
|
5
|
+
const MAX_TRANSFORMS_PER_NETWORK_RULE = 20;
|
|
6
|
+
const MAX_HEADERS_PER_NETWORK_RULE = 20;
|
|
7
|
+
const MAX_DOMAIN_LENGTH = 253;
|
|
8
|
+
const MAX_HEADER_NAME_LENGTH = 256;
|
|
9
|
+
const MAX_HEADER_TEMPLATE_BYTES = 8 * 1024;
|
|
10
|
+
const ALLOWED_NOTION_CREDENTIAL_KEYS = /* @__PURE__ */ new Set(["NOTION_API_TOKEN", "NOTION_API_BASE_URL"]);
|
|
11
|
+
const CREDENTIAL_DOMAIN_PATTERN = /^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
12
|
+
function createCredentialDeclaration(key, config) {
|
|
13
|
+
validateCredentialKey(key);
|
|
14
|
+
if (config.network.length === 0) {
|
|
15
|
+
throw new Error(`Credential "${key}" must declare at least one network rule`);
|
|
16
|
+
}
|
|
17
|
+
if (config.network.length > MAX_NETWORK_RULES_PER_CREDENTIAL) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`Credential "${key}" cannot declare more than ${MAX_NETWORK_RULES_PER_CREDENTIAL} domains`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const domains = /* @__PURE__ */ new Set();
|
|
23
|
+
const network = config.network.map((rule) => {
|
|
24
|
+
const domain = normalizeDomain(rule.domain);
|
|
25
|
+
if (domains.has(domain)) {
|
|
26
|
+
throw new Error(`Credential "${key}" declares domain "${domain}" more than once`);
|
|
27
|
+
}
|
|
28
|
+
domains.add(domain);
|
|
29
|
+
if (rule.transform.length === 0 || rule.transform.length > MAX_TRANSFORMS_PER_NETWORK_RULE) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Credential "${key}" must declare 1-${MAX_TRANSFORMS_PER_NETWORK_RULE} transforms for domain "${domain}"`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const headerNames = /* @__PURE__ */ new Set();
|
|
35
|
+
return {
|
|
36
|
+
domain,
|
|
37
|
+
transform: rule.transform.map((transform) => {
|
|
38
|
+
const headers = normalizeHeaders({
|
|
39
|
+
credentialKey: key,
|
|
40
|
+
domain,
|
|
41
|
+
headers: transform.headers
|
|
42
|
+
});
|
|
43
|
+
for (const headerName of Object.keys(headers)) {
|
|
44
|
+
const normalizedHeaderName = headerName.toLowerCase();
|
|
45
|
+
if (headerNames.has(normalizedHeaderName)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Credential "${key}" declares header "${headerName}" more than once for domain "${domain}"`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
headerNames.add(normalizedHeaderName);
|
|
51
|
+
if (headerNames.size > MAX_HEADERS_PER_NETWORK_RULE) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`Credential "${key}" cannot inject more than ${MAX_HEADERS_PER_NETWORK_RULE} headers for domain "${domain}"`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { headers };
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
key,
|
|
63
|
+
network
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function validateCredentialDeclarationConflicts(existingDeclarations, declaration) {
|
|
67
|
+
for (const existing of existingDeclarations) {
|
|
68
|
+
for (const rule of declaration.network) {
|
|
69
|
+
for (const existingRule of existing.network) {
|
|
70
|
+
if (!credentialDomainsOverlap(rule.domain, existingRule.domain)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const existingHeaders = new Set(
|
|
74
|
+
existingRule.transform.flatMap(
|
|
75
|
+
(transform) => Object.keys(transform.headers).map((name) => name.toLowerCase())
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
for (const transform of rule.transform) {
|
|
79
|
+
for (const headerName of Object.keys(transform.headers)) {
|
|
80
|
+
if (existingHeaders.has(headerName.toLowerCase())) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Credential "${declaration.key}" conflicts with credential "${existing.key}" for header "${headerName}" on overlapping domains "${rule.domain}" and "${existingRule.domain}"`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function validateCredentialKey(key) {
|
|
92
|
+
if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(key)) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Credential key "${key}" must start with a letter, contain only letters, numbers, or underscores, and be at most 64 characters`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const normalizedKey = key.toUpperCase();
|
|
98
|
+
if (normalizedKey.startsWith("NOTION_") && !ALLOWED_NOTION_CREDENTIAL_KEYS.has(normalizedKey)) {
|
|
99
|
+
throw new Error(`Credential key "${key}" uses the reserved NOTION_ prefix`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function normalizeDomain(value) {
|
|
103
|
+
const domain = value.trim().toLowerCase().replace(/\.$/, "");
|
|
104
|
+
if (domain.length > MAX_DOMAIN_LENGTH || !CREDENTIAL_DOMAIN_PATTERN.test(domain)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Credential network domain "${value}" must be an exact hostname or a leading wildcard such as "*.example.com"`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return domain;
|
|
110
|
+
}
|
|
111
|
+
function credentialDomainsOverlap(first, second) {
|
|
112
|
+
if (first === second) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
const firstBase = first.startsWith("*.") ? first.slice(2) : void 0;
|
|
116
|
+
const secondBase = second.startsWith("*.") ? second.slice(2) : void 0;
|
|
117
|
+
if (firstBase === void 0 && secondBase === void 0) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (firstBase !== void 0 && secondBase === void 0) {
|
|
121
|
+
return second.endsWith(`.${firstBase}`);
|
|
122
|
+
}
|
|
123
|
+
if (firstBase === void 0 && secondBase !== void 0) {
|
|
124
|
+
return first.endsWith(`.${secondBase}`);
|
|
125
|
+
}
|
|
126
|
+
return firstBase !== void 0 && secondBase !== void 0 && (firstBase.endsWith(`.${secondBase}`) || secondBase.endsWith(`.${firstBase}`));
|
|
127
|
+
}
|
|
128
|
+
function normalizeHeaders(args) {
|
|
129
|
+
const entries = Object.entries(args.headers);
|
|
130
|
+
if (entries.length === 0) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Credential "${args.credentialKey}" has an empty header transform for domain "${args.domain}"`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return Object.fromEntries(
|
|
136
|
+
entries.map(([name, template]) => {
|
|
137
|
+
if (name.length > MAX_HEADER_NAME_LENGTH || !/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/.test(name)) {
|
|
138
|
+
throw new Error(`Invalid credential header name "${name}"`);
|
|
139
|
+
}
|
|
140
|
+
if (typeof template !== "string") {
|
|
141
|
+
throw new Error(`Credential header "${name}" must use a string template`);
|
|
142
|
+
}
|
|
143
|
+
validateHeaderTemplate(name, template);
|
|
144
|
+
return [name, template];
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function validateHeaderTemplate(name, template) {
|
|
149
|
+
if (hasControlCharacters(template)) {
|
|
150
|
+
throw new Error(`Credential header "${name}" template cannot contain control characters`);
|
|
151
|
+
}
|
|
152
|
+
const markerCount = template.split(CREDENTIAL_VALUE).length - 1;
|
|
153
|
+
if (markerCount !== 1) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`Credential header "${name}" template must contain CREDENTIAL_VALUE exactly once`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (new TextEncoder().encode(template).byteLength > MAX_HEADER_TEMPLATE_BYTES) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
`Credential header "${name}" template must be at most ${MAX_HEADER_TEMPLATE_BYTES} bytes`
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function hasControlCharacters(value) {
|
|
165
|
+
return Array.from(value).some((character) => {
|
|
166
|
+
const codePoint = character.codePointAt(0);
|
|
167
|
+
return codePoint !== void 0 && (codePoint <= 31 || codePoint === 127);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
CREDENTIAL_VALUE,
|
|
172
|
+
MAX_CREDENTIALS,
|
|
173
|
+
MAX_CREDENTIAL_DECLARATIONS_BYTES,
|
|
174
|
+
createCredentialDeclaration,
|
|
175
|
+
validateCredentialDeclarationConflicts
|
|
176
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.test.d.ts","sourceRoot":"","sources":["../src/credential.test.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { CustomBlockCapability, CustomBlockCapabilityConfig, CustomBlockConfiguration, CustomBlockManifest, CustomBlockManifestDataSource, } from "./capabilities/custom-block.js";
|
|
1
2
|
export { emojiIcon, imageCover, imageIcon, notionIcon, place } from "./builder.js";
|
|
2
3
|
export type { AiConnectorArchetype, AiConnectorCapability, AiConnectorChange, AiConnectorChangeUpsert, AiConnectorChatAuthor, AiConnectorChatChannel, AiConnectorChatMessage, AiConnectorChatRecord, AiConnectorConfiguration, AiConnectorExecutionResult, AiConnectorMode, AiConnectorProjectBlock, AiConnectorProjectRecord, AiConnectorRecordByArchetype, } from "./capabilities/ai_connector.js";
|
|
3
4
|
export type { AutomationCapability, AutomationConfiguration, AutomationEvent, PageObjectResponse, } from "./capabilities/automation.js";
|
|
@@ -8,6 +9,8 @@ export type { ToolCapability, ToolConfiguration, ToolHints } from "./capabilitie
|
|
|
8
9
|
export type { WebhookCapability, WebhookConfiguration, WebhookEvent, } from "./capabilities/webhook.js";
|
|
9
10
|
export { WebhookVerificationError } from "./capabilities/webhook.js";
|
|
10
11
|
export type { WorkflowCapability, WorkflowConfiguration, WorkflowEvent, WorkflowEventForTrigger, WorkflowEventForTriggers, } from "./capabilities/workflow.js";
|
|
12
|
+
export type { CredentialConfiguration, CredentialDeclaration, CredentialHeaderTransform, CredentialKey, CredentialNetworkRule, } from "./credential.js";
|
|
13
|
+
export { CREDENTIAL_VALUE } from "./credential.js";
|
|
11
14
|
export { RateLimitError } from "./error.js";
|
|
12
15
|
export type { AnyJSONSchema, JSONSchema } from "./json-schema.js";
|
|
13
16
|
export type { Infer, SchemaBuilder } from "./schema-builder.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACnF,YAAY,EACX,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,0B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vB,wBAAwB,GACxB,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACX,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,EACb,qBAAqB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACnD,YAAY,EACX,KAAK,EACL,IAAI,EACJ,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,UAAU,EACV,QAAQ,GACR,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { emojiIcon, imageCover, imageIcon, notionIcon, place } from "./builder.js";
|
|
2
2
|
import { WebhookVerificationError } from "./capabilities/webhook.js";
|
|
3
|
+
import { CREDENTIAL_VALUE } from "./credential.js";
|
|
3
4
|
import { RateLimitError } from "./error.js";
|
|
4
5
|
import { getSchema, j } from "./schema-builder.js";
|
|
5
6
|
import { Worker } from "./worker.js";
|
|
6
7
|
export {
|
|
8
|
+
CREDENTIAL_VALUE,
|
|
7
9
|
RateLimitError,
|
|
8
10
|
WebhookVerificationError,
|
|
9
11
|
Worker,
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { AiConnectorArchetype, AiConnectorCapability, AiConnectorConfiguration } from "./capabilities/ai_connector.js";
|
|
2
2
|
import type { AutomationCapability, AutomationConfiguration, AutomationEvent } from "./capabilities/automation.js";
|
|
3
3
|
import type { CapabilityContext } from "./capabilities/context.js";
|
|
4
|
+
import type { CustomBlockCapability, CustomBlockConfiguration } from "./capabilities/custom-block.js";
|
|
4
5
|
import type { NotionManagedOAuthConfiguration, OAuthCapability, OAuthConfiguration, UserManagedOAuthConfiguration } from "./capabilities/oauth.js";
|
|
5
6
|
import type { SyncCapability, SyncConfiguration } from "./capabilities/sync.js";
|
|
6
7
|
import type { ToolCapability, ToolConfiguration } from "./capabilities/tool.js";
|
|
7
8
|
import type { WebhookCapability, WebhookConfiguration, WebhookEvent } from "./capabilities/webhook.js";
|
|
8
9
|
import { WebhookVerificationError } from "./capabilities/webhook.js";
|
|
9
10
|
import type { WorkflowCapability, WorkflowConfiguration, WorkflowEvent } from "./capabilities/workflow.js";
|
|
11
|
+
import type { CredentialConfiguration, CredentialDeclaration, CredentialKey } from "./credential.js";
|
|
10
12
|
import type { PacerDeclaration } from "./pacer_internal.js";
|
|
11
13
|
import type { Schema } from "./schema.js";
|
|
12
14
|
import type { WorkflowTrigger } from "./triggers.generated.js";
|
|
13
15
|
import type { HandlerOptions, JSONValue } from "./types.js";
|
|
14
16
|
export type { AiConnectorConfiguration, AutomationConfiguration, AutomationEvent, CapabilityContext, NotionManagedOAuthConfiguration, OAuthConfiguration, SyncConfiguration, ToolConfiguration, UserManagedOAuthConfiguration, WebhookConfiguration, WebhookEvent, WorkflowConfiguration, WorkflowEvent, };
|
|
15
17
|
export { WebhookVerificationError };
|
|
16
|
-
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | WorkflowCapability | OAuthCapability | WebhookCapability;
|
|
18
|
+
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | WorkflowCapability | OAuthCapability | WebhookCapability | CustomBlockCapability;
|
|
17
19
|
export type CapabilityType = Capability["_tag"];
|
|
18
20
|
/**
|
|
19
21
|
* Configuration for a database that Notion creates and manages on behalf
|
|
@@ -104,12 +106,18 @@ type CapabilityManifestEntry = Pick<Capability, "_tag" | "key" | "config">;
|
|
|
104
106
|
*/
|
|
105
107
|
export type WorkerManifest = {
|
|
106
108
|
readonly sdkVersion: string;
|
|
109
|
+
readonly credentials: readonly CredentialDeclaration[];
|
|
107
110
|
readonly databases: readonly RegisteredDatabase[];
|
|
108
111
|
readonly pacers: readonly PacerDeclaration[];
|
|
109
112
|
readonly capabilities: readonly CapabilityManifestEntry[];
|
|
110
113
|
};
|
|
111
114
|
export declare class Worker {
|
|
112
115
|
#private;
|
|
116
|
+
/**
|
|
117
|
+
* Declare a credential that is injected into matching outbound HTTPS
|
|
118
|
+
* requests without exposing its value to Worker code.
|
|
119
|
+
*/
|
|
120
|
+
credential(key: CredentialKey, config: CredentialConfiguration): void;
|
|
113
121
|
database<PK extends string, S extends Schema<PK>>(key: string, config: DatabaseConfig<PK, S>): DatabaseHandle<PK, S>;
|
|
114
122
|
/**
|
|
115
123
|
* Register a pacer for rate-limiting requests to an external API.
|
|
@@ -400,6 +408,45 @@ export declare class Worker {
|
|
|
400
408
|
* @returns The registered OAuth capability.
|
|
401
409
|
*/
|
|
402
410
|
oauth(key: string, config: OAuthConfiguration): OAuthCapability;
|
|
411
|
+
/**
|
|
412
|
+
* Register a custom block capability.
|
|
413
|
+
*
|
|
414
|
+
* A custom block is a front-end view that the deploy pipeline builds from
|
|
415
|
+
* the source entry into a deployable bundle. It can optionally declare a
|
|
416
|
+
* data-source *schema* (`name`, and optional `description`, `icon`, and
|
|
417
|
+
* `properties`) that the block reads.
|
|
418
|
+
*
|
|
419
|
+
* Example:
|
|
420
|
+
*
|
|
421
|
+
* ```ts
|
|
422
|
+
* const worker = new Worker();
|
|
423
|
+
* export default worker;
|
|
424
|
+
*
|
|
425
|
+
* worker.customBlock("issueBoard", {
|
|
426
|
+
* version: 1,
|
|
427
|
+
* path: "./views/issueBoard",
|
|
428
|
+
* dataSources: {
|
|
429
|
+
* issues: {
|
|
430
|
+
* name: "Issues",
|
|
431
|
+
* properties: {
|
|
432
|
+
* title: { name: "Title", type: "title" },
|
|
433
|
+
* status: { name: "Status", type: "status" },
|
|
434
|
+
* },
|
|
435
|
+
* },
|
|
436
|
+
* },
|
|
437
|
+
* });
|
|
438
|
+
* ```
|
|
439
|
+
*
|
|
440
|
+
* The manifest keys (`version`, `dataSources`) are top-level on the config;
|
|
441
|
+
* the SDK assembles the deploy-wire `CustomBlockManifest` from them. Binding
|
|
442
|
+
* each declared data source to a concrete managed database is instance-level
|
|
443
|
+
* and handled at deploy time — the worker does not emit bindings.
|
|
444
|
+
*
|
|
445
|
+
* @param key - The unique key for this block (the block declaration key).
|
|
446
|
+
* @param config - The custom block configuration (a `project`/`static` source folder + optional `version`/`dataSources` schema).
|
|
447
|
+
* @returns The custom block capability.
|
|
448
|
+
*/
|
|
449
|
+
customBlock(key: string, config: CustomBlockConfiguration): CustomBlockCapability;
|
|
403
450
|
/**
|
|
404
451
|
* Get all registered capabilities (for discovery) without their handlers.
|
|
405
452
|
*/
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,oBAAoB,EACpB,qBAAqB,EACrB,wBAAwB,EACxB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EACX,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,EAC7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,KAAK,EAAE,cAA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