@notionhq/workers 0.7.0 → 0.8.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/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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/worker.d.ts +41 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +50 -0
- package/package.json +1 -1
- package/src/capabilities/custom-block.ts +181 -0
- package/src/index.ts +7 -0
- package/src/worker.test.ts +147 -0
- package/src/worker.ts +59 -1
- 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
|
@@ -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,GACd,SAAS,GACT,UAAU,GACV,QAAQ,GACR,cAAc,GACd,YAAY,GACZ,kBAAkB,GAClB,gBAAgB,GAChB,mBAAmB,GACnB,QAAQ,GACR,WAAW,GACX,UAAU,GACV,cAAc,GACd,OAAO,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,+BAA+B,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC3C,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;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C;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
|
+
};
|
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";
|
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,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,GAC5B,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACX,oBAAoB,EACpB,uBAAuB,EACvB,eAAe,EACf,kBAAkB,GAClB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,YAAY,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC3F,YAAY,EACX,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,YAAY,EACX,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,uBAAuB,EACvB,wBAAw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Y,EACX,+BAA+B,EAC/B,eAAe,EACf,kBAAkB,EAClB,6BAA6B,GAC7B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACX,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAC3F,YAAY,EACX,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GACZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,YAAY,EACX,kBAAkB,EAClB,qBAAqB,EACrB,aAAa,EACb,uBAAuB,EACvB,wBAAwB,GACxB,MAAM,4BAA4B,CAAC;AACpC,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/worker.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
@@ -13,7 +14,7 @@ import type { WorkflowTrigger } from "./triggers.generated.js";
|
|
|
13
14
|
import type { HandlerOptions, JSONValue } from "./types.js";
|
|
14
15
|
export type { AiConnectorConfiguration, AutomationConfiguration, AutomationEvent, CapabilityContext, NotionManagedOAuthConfiguration, OAuthConfiguration, SyncConfiguration, ToolConfiguration, UserManagedOAuthConfiguration, WebhookConfiguration, WebhookEvent, WorkflowConfiguration, WorkflowEvent, };
|
|
15
16
|
export { WebhookVerificationError };
|
|
16
|
-
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | WorkflowCapability | OAuthCapability | WebhookCapability;
|
|
17
|
+
type Capability = SyncCapability | AiConnectorCapability | ToolCapability<any, any> | AutomationCapability | WorkflowCapability | OAuthCapability | WebhookCapability | CustomBlockCapability;
|
|
17
18
|
export type CapabilityType = Capability["_tag"];
|
|
18
19
|
/**
|
|
19
20
|
* Configuration for a database that Notion creates and manages on behalf
|
|
@@ -400,6 +401,45 @@ export declare class Worker {
|
|
|
400
401
|
* @returns The registered OAuth capability.
|
|
401
402
|
*/
|
|
402
403
|
oauth(key: string, config: OAuthConfiguration): OAuthCapability;
|
|
404
|
+
/**
|
|
405
|
+
* Register a custom block capability.
|
|
406
|
+
*
|
|
407
|
+
* A custom block is a front-end view that the deploy pipeline builds from
|
|
408
|
+
* the source entry into a deployable bundle. It can optionally declare a
|
|
409
|
+
* data-source *schema* (`name`, and optional `description`, `icon`, and
|
|
410
|
+
* `properties`) that the block reads.
|
|
411
|
+
*
|
|
412
|
+
* Example:
|
|
413
|
+
*
|
|
414
|
+
* ```ts
|
|
415
|
+
* const worker = new Worker();
|
|
416
|
+
* export default worker;
|
|
417
|
+
*
|
|
418
|
+
* worker.customBlock("issueBoard", {
|
|
419
|
+
* version: 1,
|
|
420
|
+
* path: "./views/issueBoard",
|
|
421
|
+
* dataSources: {
|
|
422
|
+
* issues: {
|
|
423
|
+
* name: "Issues",
|
|
424
|
+
* properties: {
|
|
425
|
+
* title: { name: "Title", type: "title" },
|
|
426
|
+
* status: { name: "Status", type: "status" },
|
|
427
|
+
* },
|
|
428
|
+
* },
|
|
429
|
+
* },
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*
|
|
433
|
+
* The manifest keys (`version`, `dataSources`) are top-level on the config;
|
|
434
|
+
* the SDK assembles the deploy-wire `CustomBlockManifest` from them. Binding
|
|
435
|
+
* each declared data source to a concrete managed database is instance-level
|
|
436
|
+
* and handled at deploy time — the worker does not emit bindings.
|
|
437
|
+
*
|
|
438
|
+
* @param key - The unique key for this block (the block declaration key).
|
|
439
|
+
* @param config - The custom block configuration (a `project`/`static` source folder + optional `version`/`dataSources` schema).
|
|
440
|
+
* @returns The custom block capability.
|
|
441
|
+
*/
|
|
442
|
+
customBlock(key: string, config: CustomBlockConfiguration): CustomBlockCapability;
|
|
403
443
|
/**
|
|
404
444
|
* Get all registered capabilities (for discovery) without their handlers.
|
|
405
445
|
*/
|
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,EAA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EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC,EAAE,CAMhE;IAED,IAAI,QAAQ,IAAI,cAAc,CAO7B;IAED;;;;;;;OAOG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;CAsCxF"}
|
package/dist/worker.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAiConnectorCapability } from "./capabilities/ai_connector.js";
|
|
2
2
|
import { createAutomationCapability } from "./capabilities/automation.js";
|
|
3
|
+
import { createCustomBlockCapability } from "./capabilities/custom-block.js";
|
|
3
4
|
import { createOAuthCapability } from "./capabilities/oauth.js";
|
|
4
5
|
import { createSyncCapability } from "./capabilities/sync.js";
|
|
5
6
|
import { createToolCapability } from "./capabilities/tool.js";
|
|
@@ -365,6 +366,50 @@ class Worker {
|
|
|
365
366
|
this.#capabilities.set(key, capability);
|
|
366
367
|
return capability;
|
|
367
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Register a custom block capability.
|
|
371
|
+
*
|
|
372
|
+
* A custom block is a front-end view that the deploy pipeline builds from
|
|
373
|
+
* the source entry into a deployable bundle. It can optionally declare a
|
|
374
|
+
* data-source *schema* (`name`, and optional `description`, `icon`, and
|
|
375
|
+
* `properties`) that the block reads.
|
|
376
|
+
*
|
|
377
|
+
* Example:
|
|
378
|
+
*
|
|
379
|
+
* ```ts
|
|
380
|
+
* const worker = new Worker();
|
|
381
|
+
* export default worker;
|
|
382
|
+
*
|
|
383
|
+
* worker.customBlock("issueBoard", {
|
|
384
|
+
* version: 1,
|
|
385
|
+
* path: "./views/issueBoard",
|
|
386
|
+
* dataSources: {
|
|
387
|
+
* issues: {
|
|
388
|
+
* name: "Issues",
|
|
389
|
+
* properties: {
|
|
390
|
+
* title: { name: "Title", type: "title" },
|
|
391
|
+
* status: { name: "Status", type: "status" },
|
|
392
|
+
* },
|
|
393
|
+
* },
|
|
394
|
+
* },
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* The manifest keys (`version`, `dataSources`) are top-level on the config;
|
|
399
|
+
* the SDK assembles the deploy-wire `CustomBlockManifest` from them. Binding
|
|
400
|
+
* each declared data source to a concrete managed database is instance-level
|
|
401
|
+
* and handled at deploy time — the worker does not emit bindings.
|
|
402
|
+
*
|
|
403
|
+
* @param key - The unique key for this block (the block declaration key).
|
|
404
|
+
* @param config - The custom block configuration (a `project`/`static` source folder + optional `version`/`dataSources` schema).
|
|
405
|
+
* @returns The custom block capability.
|
|
406
|
+
*/
|
|
407
|
+
customBlock(key, config) {
|
|
408
|
+
this.#validateUniqueKey(key);
|
|
409
|
+
const capability = createCustomBlockCapability(key, config);
|
|
410
|
+
this.#capabilities.set(key, capability);
|
|
411
|
+
return capability;
|
|
412
|
+
}
|
|
368
413
|
/**
|
|
369
414
|
* Get all registered capabilities (for discovery) without their handlers.
|
|
370
415
|
*/
|
|
@@ -401,6 +446,11 @@ class Worker {
|
|
|
401
446
|
`Cannot run OAuth capability "${key}" - OAuth capabilities only provide configuration`
|
|
402
447
|
);
|
|
403
448
|
}
|
|
449
|
+
if (capability._tag === "custom_block") {
|
|
450
|
+
throw new Error(
|
|
451
|
+
`Cannot run custom block capability "${key}" - custom blocks only provide configuration`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
404
454
|
if (!capability.handler) {
|
|
405
455
|
throw new Error(`Capability "${key}" cannot be executed`);
|
|
406
456
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// Custom Block Authoring API
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Icon for a custom block data source. Mirrors the server/client
|
|
7
|
+
* `CustomBlockManifestIcon` (`@notionhq/shared/customViews/customBlockManifestTypes`).
|
|
8
|
+
*/
|
|
9
|
+
export type CustomBlockManifestIcon =
|
|
10
|
+
| { type: "emoji"; emoji: string }
|
|
11
|
+
| { type: "external"; url: string };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Public-API-shaped property type names usable in a custom block manifest.
|
|
15
|
+
*/
|
|
16
|
+
export type CustomBlockManifestPropertyType =
|
|
17
|
+
| "title"
|
|
18
|
+
| "rich_text"
|
|
19
|
+
| "number"
|
|
20
|
+
| "select"
|
|
21
|
+
| "multi_select"
|
|
22
|
+
| "status"
|
|
23
|
+
| "date"
|
|
24
|
+
| "people"
|
|
25
|
+
| "files"
|
|
26
|
+
| "checkbox"
|
|
27
|
+
| "url"
|
|
28
|
+
| "email"
|
|
29
|
+
| "phone_number"
|
|
30
|
+
| "formula"
|
|
31
|
+
| "relation"
|
|
32
|
+
| "rollup"
|
|
33
|
+
| "created_time"
|
|
34
|
+
| "created_by"
|
|
35
|
+
| "last_edited_time"
|
|
36
|
+
| "last_edited_by"
|
|
37
|
+
| "last_visited_time"
|
|
38
|
+
| "button"
|
|
39
|
+
| "unique_id"
|
|
40
|
+
| "location"
|
|
41
|
+
| "verification"
|
|
42
|
+
| "place";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Describes a single property exposed by a custom block data source.
|
|
46
|
+
*/
|
|
47
|
+
export type CustomBlockManifestProperty = {
|
|
48
|
+
name: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
type: CustomBlockManifestPropertyType;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Rich schema describing one of a custom block's data sources.
|
|
55
|
+
*/
|
|
56
|
+
export type CustomBlockManifestDataSource = {
|
|
57
|
+
/** Display name for the data source. */
|
|
58
|
+
name: string;
|
|
59
|
+
/** Optional human-readable description of the data source. */
|
|
60
|
+
description?: string;
|
|
61
|
+
/** Optional icon for the data source. */
|
|
62
|
+
icon?: CustomBlockManifestIcon;
|
|
63
|
+
/** Optional property schema keyed by property key. */
|
|
64
|
+
properties?: Record<string, CustomBlockManifestProperty>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type CustomBlockManifest = {
|
|
68
|
+
version: 1;
|
|
69
|
+
/**
|
|
70
|
+
* The block's datasources schema, mapping keys you name to {@link CustomBlockManifestDataSource}
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
*
|
|
74
|
+
* {
|
|
75
|
+
* "myDataSource": {
|
|
76
|
+
* "name": "My Data Source",
|
|
77
|
+
* "description": "A description of my data source",
|
|
78
|
+
* "icon": "icon.png",
|
|
79
|
+
* "properties": {
|
|
80
|
+
* "property1": {
|
|
81
|
+
* "name": "Property 1",
|
|
82
|
+
* "type": "string"
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
*/
|
|
88
|
+
dataSources: Record<string, CustomBlockManifestDataSource>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A custom block is a front-end web app served in an iframe in the client with live data access.
|
|
93
|
+
*
|
|
94
|
+
* Available `type`s are `project` (a buildable project dir) and `static` (an already-built dir served as-is).
|
|
95
|
+
*/
|
|
96
|
+
export type CustomBlockConfiguration = (
|
|
97
|
+
| {
|
|
98
|
+
/** Buildable project dir (the default). */
|
|
99
|
+
type?: "project";
|
|
100
|
+
/** Path to the project dir, relative to the worker root (e.g. `"./blocks/foo"`). */
|
|
101
|
+
path: string;
|
|
102
|
+
/** Build command run in `path`. Defaults to `npm run build`. */
|
|
103
|
+
command?: string;
|
|
104
|
+
/** Built-output dir relative to `path`. Defaults to `dist`. */
|
|
105
|
+
output?: string;
|
|
106
|
+
}
|
|
107
|
+
| {
|
|
108
|
+
/** An already-built browser-bundle dir; served as-is, no build step. */
|
|
109
|
+
type: "static";
|
|
110
|
+
/** Path to the prebuilt dir, relative to the worker root. */
|
|
111
|
+
path: string;
|
|
112
|
+
command?: never;
|
|
113
|
+
output?: never;
|
|
114
|
+
}
|
|
115
|
+
) &
|
|
116
|
+
Partial<CustomBlockManifest>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The build source of a custom block, mirroring the server's
|
|
120
|
+
* `BlockSourceDeclaration`. `project` is a buildable dir (`command` defaults to
|
|
121
|
+
* `npm run build`, `output` to `dist`); `static` is an already-built dir served
|
|
122
|
+
* as-is.
|
|
123
|
+
*/
|
|
124
|
+
export type BlockSourceDeclaration =
|
|
125
|
+
| { type: "project"; path: string; command?: string; output?: string }
|
|
126
|
+
| { type: "static"; path: string };
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Config payload carried in the runtime manifest for a `_tag: "custom_block"`
|
|
130
|
+
* capability entry. The server parses this (see `RawBlockCapabilityConfig` in
|
|
131
|
+
* `capabilities-service.ts`): `source` is the build entry and `manifest` is the
|
|
132
|
+
* author-declared {@link CustomBlockManifest} describing the block's data-source
|
|
133
|
+
* schema. Data-source *bindings* are instance-level and are not carried here.
|
|
134
|
+
*/
|
|
135
|
+
export type CustomBlockCapabilityConfig = {
|
|
136
|
+
source: BlockSourceDeclaration;
|
|
137
|
+
manifest: CustomBlockManifest;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A custom-block capability entry. Unlike other capabilities it has no runtime
|
|
142
|
+
* handler — it is a build-time/deploy-time declaration only, carried through
|
|
143
|
+
* the manifest so the server can build and bind the block on deploy.
|
|
144
|
+
*/
|
|
145
|
+
export type CustomBlockCapability = {
|
|
146
|
+
readonly _tag: "custom_block";
|
|
147
|
+
readonly key: string;
|
|
148
|
+
readonly config: CustomBlockCapabilityConfig;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Builds a custom-block capability entry from its authoring configuration. The
|
|
153
|
+
* author-declared `dataSources` schema is carried verbatim into the block
|
|
154
|
+
* {@link CustomBlockManifest}; no bindings are emitted.
|
|
155
|
+
*/
|
|
156
|
+
export function createCustomBlockCapability(
|
|
157
|
+
key: string,
|
|
158
|
+
config: CustomBlockConfiguration,
|
|
159
|
+
): CustomBlockCapability {
|
|
160
|
+
const source: BlockSourceDeclaration =
|
|
161
|
+
config.type === "static"
|
|
162
|
+
? { type: "static", path: config.path }
|
|
163
|
+
: {
|
|
164
|
+
type: "project",
|
|
165
|
+
path: config.path,
|
|
166
|
+
...(config.command !== undefined ? { command: config.command } : {}),
|
|
167
|
+
...(config.output !== undefined ? { output: config.output } : {}),
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
_tag: "custom_block",
|
|
172
|
+
key,
|
|
173
|
+
config: {
|
|
174
|
+
source,
|
|
175
|
+
manifest: {
|
|
176
|
+
version: config.version ?? 1,
|
|
177
|
+
dataSources: config.dataSources ?? {},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
CustomBlockCapability,
|
|
3
|
+
CustomBlockCapabilityConfig,
|
|
4
|
+
CustomBlockConfiguration,
|
|
5
|
+
CustomBlockManifest,
|
|
6
|
+
CustomBlockManifestDataSource,
|
|
7
|
+
} from "./capabilities/custom-block.js";
|
|
1
8
|
export { emojiIcon, imageCover, imageIcon, notionIcon, place } from "./builder.js";
|
|
2
9
|
export type {
|
|
3
10
|
AiConnectorArchetype,
|
package/src/worker.test.ts
CHANGED
|
@@ -141,6 +141,153 @@ describe("Worker", () => {
|
|
|
141
141
|
]);
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
+
it("registers a project custom block from a folder path (type defaults to project)", () => {
|
|
145
|
+
const worker = new Worker();
|
|
146
|
+
|
|
147
|
+
worker.customBlock("visualBlock", {
|
|
148
|
+
path: "./views/visual",
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(worker.manifest.capabilities).toEqual([
|
|
152
|
+
{
|
|
153
|
+
_tag: "custom_block",
|
|
154
|
+
key: "visualBlock",
|
|
155
|
+
config: {
|
|
156
|
+
source: { type: "project", path: "./views/visual" },
|
|
157
|
+
manifest: {
|
|
158
|
+
version: 1,
|
|
159
|
+
dataSources: {},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("carries a project's custom build command and output dir", () => {
|
|
167
|
+
const worker = new Worker();
|
|
168
|
+
|
|
169
|
+
worker.customBlock("built", {
|
|
170
|
+
path: "./app",
|
|
171
|
+
command: "npm run build-prod",
|
|
172
|
+
output: "build",
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
expect(worker.manifest.capabilities).toEqual([
|
|
176
|
+
{
|
|
177
|
+
_tag: "custom_block",
|
|
178
|
+
key: "built",
|
|
179
|
+
config: {
|
|
180
|
+
source: {
|
|
181
|
+
type: "project",
|
|
182
|
+
path: "./app",
|
|
183
|
+
command: "npm run build-prod",
|
|
184
|
+
output: "build",
|
|
185
|
+
},
|
|
186
|
+
manifest: { version: 1, dataSources: {} },
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("registers a static custom block served as-is", () => {
|
|
193
|
+
const worker = new Worker();
|
|
194
|
+
|
|
195
|
+
worker.customBlock("prebuilt", { type: "static", path: "./dist" });
|
|
196
|
+
|
|
197
|
+
expect(worker.manifest.capabilities).toEqual([
|
|
198
|
+
{
|
|
199
|
+
_tag: "custom_block",
|
|
200
|
+
key: "prebuilt",
|
|
201
|
+
config: {
|
|
202
|
+
source: { type: "static", path: "./dist" },
|
|
203
|
+
manifest: { version: 1, dataSources: {} },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("carries the author-declared data-source schema verbatim into the manifest", () => {
|
|
210
|
+
const worker = new Worker();
|
|
211
|
+
|
|
212
|
+
worker.customBlock("issueBoard", {
|
|
213
|
+
path: "./views/issueBoard",
|
|
214
|
+
dataSources: {
|
|
215
|
+
issues: {
|
|
216
|
+
name: "Issues",
|
|
217
|
+
description: "The team's issues",
|
|
218
|
+
icon: { type: "emoji", emoji: "🐛" },
|
|
219
|
+
properties: {
|
|
220
|
+
title: { name: "Title", type: "title" },
|
|
221
|
+
status: {
|
|
222
|
+
name: "Status",
|
|
223
|
+
description: "Workflow state",
|
|
224
|
+
type: "status",
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
expect(worker.manifest.capabilities).toEqual([
|
|
232
|
+
{
|
|
233
|
+
_tag: "custom_block",
|
|
234
|
+
key: "issueBoard",
|
|
235
|
+
config: {
|
|
236
|
+
source: { type: "project", path: "./views/issueBoard" },
|
|
237
|
+
manifest: {
|
|
238
|
+
version: 1,
|
|
239
|
+
dataSources: {
|
|
240
|
+
issues: {
|
|
241
|
+
name: "Issues",
|
|
242
|
+
description: "The team's issues",
|
|
243
|
+
icon: { type: "emoji", emoji: "🐛" },
|
|
244
|
+
properties: {
|
|
245
|
+
title: { name: "Title", type: "title" },
|
|
246
|
+
status: {
|
|
247
|
+
name: "Status",
|
|
248
|
+
description: "Workflow state",
|
|
249
|
+
type: "status",
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
]);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("threads a top-level manifest version into the generated manifest", () => {
|
|
261
|
+
const worker = new Worker();
|
|
262
|
+
|
|
263
|
+
worker.customBlock("versioned", {
|
|
264
|
+
path: "./views/versioned",
|
|
265
|
+
version: 1,
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
expect(worker.manifest.capabilities).toEqual([
|
|
269
|
+
{
|
|
270
|
+
_tag: "custom_block",
|
|
271
|
+
key: "versioned",
|
|
272
|
+
config: {
|
|
273
|
+
source: { type: "project", path: "./views/versioned" },
|
|
274
|
+
manifest: { version: 1, dataSources: {} },
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
]);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("cannot run a custom block capability", async () => {
|
|
281
|
+
const worker = new Worker();
|
|
282
|
+
worker.customBlock("visualBlock", {
|
|
283
|
+
path: "./views/visual",
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
await expect(worker.run("visualBlock", {})).rejects.toThrow(
|
|
287
|
+
'Cannot run custom block capability "visualBlock"',
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
144
291
|
it("rejects duplicate keys across databases, pacers, and capabilities", () => {
|
|
145
292
|
const worker = new Worker();
|
|
146
293
|
const db = worker.database("shared-key", {
|