@notionhq/apps 0.0.18 → 0.0.19
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/README.md +17 -0
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +12 -7
- package/dist/cli/emit-manifest.d.ts +1 -1
- package/dist/cli/emit-manifest.d.ts.map +1 -1
- package/dist/cli/emit-manifest.js +66 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/notion-as-code/custom-agent.d.ts +1 -0
- package/dist/notion-as-code/custom-agent.d.ts.map +1 -1
- package/dist/notion-as-code/custom-agent.js +1 -1
- package/dist/notion-as-code/database.d.ts +2 -0
- package/dist/notion-as-code/database.d.ts.map +1 -1
- package/dist/notion-as-code/database.js +3 -0
- package/dist/notion-as-code/page.d.ts +1 -0
- package/dist/notion-as-code/page.d.ts.map +1 -1
- package/dist/notion-as-code/page.js +1 -0
- package/dist/workflow-access-types.test.d.ts +2 -0
- package/dist/workflow-access-types.test.d.ts.map +1 -0
- package/dist/workflow-access.d.ts +68 -0
- package/dist/workflow-access.d.ts.map +1 -0
- package/dist/workflow-access.js +135 -0
- package/dist/workflow.d.ts +17 -6
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +8 -1
- package/docs/BUILD.md +38 -4
- package/package.json +1 -1
- package/skills/notion-as-code/SKILL.md +8 -0
- package/skills/workflow/SKILL.md +50 -15
- package/src/cli/build.test.ts +24 -0
- package/src/cli/build.ts +13 -8
- package/src/cli/emit-manifest.ts +107 -0
- package/src/index.ts +20 -1
- package/src/notion-as-code/custom-agent.ts +2 -1
- package/src/notion-as-code/database.ts +5 -0
- package/src/notion-as-code/page.ts +2 -0
- package/src/workflow-access-types.test.ts +69 -0
- package/src/workflow-access.ts +299 -0
- package/src/workflow.test.ts +112 -0
- package/src/workflow.ts +50 -7
package/README.md
CHANGED
|
@@ -108,6 +108,23 @@ Use `context.notion` for Notion API calls. Deployed apps receive Notion API
|
|
|
108
108
|
credentials automatically, so do not configure or push `NOTION_API_TOKEN`.
|
|
109
109
|
Local execution needs the token in `.env` before making a Notion API request.
|
|
110
110
|
|
|
111
|
+
For a resource declared with Notion as Code, add a named runtime binding with
|
|
112
|
+
`access: { handbook: { resource: handbook, level: "view" } }`. Cloud deployment
|
|
113
|
+
resolves the declaration's NaC `resourceId` to a live ID and exposes it to the
|
|
114
|
+
handler as `context.access.handbook.id`. Deployment also reconciles the declared
|
|
115
|
+
access through the existing Notion-module permissions. Those permissions, not
|
|
116
|
+
the bindings, authorize `context.notion` calls.
|
|
117
|
+
|
|
118
|
+
Resources granted to the workflow in Notion's UI do not need an `access` entry, a
|
|
119
|
+
NaC declaration, or a NaC `resourceId`. Pass the live record ID directly to the
|
|
120
|
+
appropriate `context.notion` call, for example
|
|
121
|
+
`context.notion.pages.retrieve({ page_id: "page-id" })`; the call remains subject
|
|
122
|
+
to the existing workflow permissions. UI grants do not create `context.access`
|
|
123
|
+
aliases. Pages, databases, data sources, and custom agents are supported by
|
|
124
|
+
named bindings. Workflows with nonempty `access` cannot use `--local-build`.
|
|
125
|
+
See the [workflow skill](./skills/workflow/SKILL.md#resources-created-with-the-app)
|
|
126
|
+
for access levels and a complete example.
|
|
127
|
+
|
|
111
128
|
## Data-source syncs
|
|
112
129
|
|
|
113
130
|
Declare a database with Notion as Code, then pass one of its data-source handles to `sync`:
|
package/dist/cli/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAUlD,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,WAAW,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAUlD,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,EAAE,WAAW,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CA8CxE"}
|
package/dist/cli/build.js
CHANGED
|
@@ -30,18 +30,23 @@ async function buildApp(projectRoot) {
|
|
|
30
30
|
await bundle.close();
|
|
31
31
|
}
|
|
32
32
|
const blockConfigs = await buildBlockDeclarations(projectRoot, capabilities);
|
|
33
|
-
const
|
|
34
|
-
const manifestPath = path.join(projectRoot, "dist", "manifest.json");
|
|
35
|
-
await fs.promises.writeFile(manifestPath, `${JSON.stringify(manifest, null, " ")}
|
|
36
|
-
`);
|
|
37
|
-
await emitProvisioningArtifact(
|
|
33
|
+
const entityProvisioning = await buildMetadata(
|
|
38
34
|
projectRoot,
|
|
39
35
|
capabilities.filter((capability) => capability.runtime === "worker")
|
|
40
36
|
);
|
|
37
|
+
const manifest = await extractManifest(
|
|
38
|
+
bundlePath,
|
|
39
|
+
capabilities,
|
|
40
|
+
blockConfigs,
|
|
41
|
+
entityProvisioning
|
|
42
|
+
);
|
|
43
|
+
const manifestPath = path.join(projectRoot, "dist", "manifest.json");
|
|
44
|
+
await fs.promises.writeFile(manifestPath, `${JSON.stringify(manifest, null, " ")}
|
|
45
|
+
`);
|
|
46
|
+
await emitProvisioningArtifact(projectRoot, entityProvisioning);
|
|
41
47
|
return { manifest, bundlePath, manifestPath };
|
|
42
48
|
}
|
|
43
|
-
async function emitProvisioningArtifact(projectRoot,
|
|
44
|
-
const entityProvisioning = await buildMetadata(projectRoot, capabilities);
|
|
49
|
+
async function emitProvisioningArtifact(projectRoot, entityProvisioning) {
|
|
45
50
|
const provisioningPath = path.join(projectRoot, "dist", "provisioning.json");
|
|
46
51
|
if (entityProvisioning.intents.length === 0) {
|
|
47
52
|
await fs.promises.rm(provisioningPath, { force: true });
|
|
@@ -2,7 +2,7 @@ import { type RecordedProvisioning } from "../notion-as-code/provisioning.js";
|
|
|
2
2
|
import type { AppManifest } from "../manifest.js";
|
|
3
3
|
import type { DiscoveredCapability } from "./discover.js";
|
|
4
4
|
/** Extract the app manifest from a built bundle. */
|
|
5
|
-
export declare function extractManifest(bundlePath: string, capabilities: readonly DiscoveredCapability[], blockConfigs?: Record<string, unknown
|
|
5
|
+
export declare function extractManifest(bundlePath: string, capabilities: readonly DiscoveredCapability[], blockConfigs?: Record<string, unknown>, provisioning?: RecordedProvisioning): Promise<AppManifest>;
|
|
6
6
|
/** Import the metadata bundle and return the provisioning declarations it recorded. */
|
|
7
7
|
export declare function extractProvisioning(bundlePath: string): Promise<RecordedProvisioning>;
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit-manifest.d.ts","sourceRoot":"","sources":["../../src/cli/emit-manifest.ts"],"names":[],"mappings":"AAMA,OAAO,EAEN,KAAK,oBAAoB,EACzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAA6C,MAAM,gBAAgB,CAAC;AAE7F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AA0M1D,oDAAoD;AACpD,wBAAsB,eAAe,CACpC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,SAAS,oBAAoB,EAAE,EAC7C,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,
|
|
1
|
+
{"version":3,"file":"emit-manifest.d.ts","sourceRoot":"","sources":["../../src/cli/emit-manifest.ts"],"names":[],"mappings":"AAMA,OAAO,EAEN,KAAK,oBAAoB,EACzB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAA6C,MAAM,gBAAgB,CAAC;AAE7F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AA0M1D,oDAAoD;AACpD,wBAAsB,eAAe,CACpC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,SAAS,oBAAoB,EAAE,EAC7C,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAC1C,YAAY,CAAC,EAAE,oBAAoB,GACjC,OAAO,CAAC,WAAW,CAAC,CAqFtB;AAwGD,uFAAuF;AACvF,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAW3F;AA8BD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAoCjE;AAED,yFAAyF;AACzF,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAE9F"}
|
|
@@ -162,7 +162,7 @@ class DatabaseCollector {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
|
-
async function extractManifest(bundlePath, capabilities, blockConfigs = {}) {
|
|
165
|
+
async function extractManifest(bundlePath, capabilities, blockConfigs = {}, provisioning) {
|
|
166
166
|
clearRegisteredPacers();
|
|
167
167
|
const bundle = await importBundle(bundlePath);
|
|
168
168
|
const registry = getCapabilityRegistry(bundle);
|
|
@@ -198,6 +198,9 @@ async function extractManifest(bundlePath, capabilities, blockConfigs = {}) {
|
|
|
198
198
|
const { database: _database, ...rest } = config;
|
|
199
199
|
config = { ...rest, databaseKey };
|
|
200
200
|
}
|
|
201
|
+
if (capability.type === "workflow") {
|
|
202
|
+
validateWorkflowAccessReferences(config.access, provisioning, capability.sourcePath);
|
|
203
|
+
}
|
|
201
204
|
assertJsonSafe(config, `${capability.sourcePath} config`);
|
|
202
205
|
return { type: capability.type, key: capability.key, config };
|
|
203
206
|
});
|
|
@@ -226,6 +229,68 @@ async function extractManifest(bundlePath, capabilities, blockConfigs = {}) {
|
|
|
226
229
|
}
|
|
227
230
|
return manifest;
|
|
228
231
|
}
|
|
232
|
+
const WORKFLOW_ACCESS_TYPES = {
|
|
233
|
+
page: true,
|
|
234
|
+
database: true,
|
|
235
|
+
dataSource: true,
|
|
236
|
+
customAgent: true
|
|
237
|
+
};
|
|
238
|
+
const WORKFLOW_ACCESS_LEVELS = {
|
|
239
|
+
view: true,
|
|
240
|
+
comment: true,
|
|
241
|
+
edit: true,
|
|
242
|
+
fullAccess: true
|
|
243
|
+
};
|
|
244
|
+
function validateWorkflowAccessReferences(access, provisioning, capabilityPath) {
|
|
245
|
+
if (access === void 0) return;
|
|
246
|
+
if (typeof access !== "object" || access === null || Array.isArray(access) || provisioning === void 0 && Object.keys(access).length > 0) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`${capabilityPath}: workflow access must reference resources recorded by the current build`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (provisioning === void 0) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const accessObject = access;
|
|
255
|
+
const aliases = Object.keys(accessObject);
|
|
256
|
+
if (Reflect.ownKeys(accessObject).length !== aliases.length) {
|
|
257
|
+
throw new Error(`${capabilityPath}: workflow access aliases must be enumerable strings`);
|
|
258
|
+
}
|
|
259
|
+
for (const alias of aliases) {
|
|
260
|
+
if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/.test(alias) || alias === "__proto__" || alias === "prototype" || alias === "constructor") {
|
|
261
|
+
throw new Error(`${capabilityPath}: invalid workflow access alias "${alias}"`);
|
|
262
|
+
}
|
|
263
|
+
const requirement = accessObject[alias];
|
|
264
|
+
if (typeof requirement !== "object" || requirement === null || Array.isArray(requirement) || Reflect.ownKeys(requirement).length !== 3 || !Object.hasOwn(requirement, "type") || !Object.hasOwn(requirement, "resourceId") || !Object.hasOwn(requirement, "level")) {
|
|
265
|
+
throw new Error(`${capabilityPath}: invalid workflow access requirement "${alias}"`);
|
|
266
|
+
}
|
|
267
|
+
const requirementObject = requirement;
|
|
268
|
+
const type = requirementObject.type;
|
|
269
|
+
const resourceId = requirementObject.resourceId;
|
|
270
|
+
const level = requirementObject.level;
|
|
271
|
+
if (typeof type !== "string" || !Object.hasOwn(WORKFLOW_ACCESS_TYPES, type) || typeof resourceId !== "string" || resourceId.length === 0 || typeof level !== "string" || (type === "customAgent" ? level !== "call" : !Object.hasOwn(WORKFLOW_ACCESS_LEVELS, level))) {
|
|
272
|
+
throw new Error(`${capabilityPath}: invalid workflow access requirement "${alias}"`);
|
|
273
|
+
}
|
|
274
|
+
if (!provisioning.intents.some((intent) => {
|
|
275
|
+
switch (type) {
|
|
276
|
+
case "page":
|
|
277
|
+
return intent.type === "page" && intent.resourceId === resourceId;
|
|
278
|
+
case "database":
|
|
279
|
+
return intent.type === "database" && intent.resourceId === resourceId;
|
|
280
|
+
case "customAgent":
|
|
281
|
+
return intent.type === "custom_agent" && intent.resourceId === resourceId;
|
|
282
|
+
case "dataSource":
|
|
283
|
+
return intent.type === "database" && (intent.dataSources ?? []).some(
|
|
284
|
+
(dataSource) => dataSource.resourceId === resourceId
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
})) {
|
|
288
|
+
throw new Error(
|
|
289
|
+
`${capabilityPath}: workflow access "${alias}" references ${type} "${resourceId}" that is not declared by the current build`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
229
294
|
async function extractProvisioning(bundlePath) {
|
|
230
295
|
const bundle = await importBundle(bundlePath);
|
|
231
296
|
if (typeof bundle !== "object" || bundle === null || !("default" in bundle) || !isRecordedProvisioning(bundle.default)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export { page } from "./notion-as-code/page.js";
|
|
|
5
5
|
export { teamspace } from "./notion-as-code/teamspace.js";
|
|
6
6
|
export { view } from "./notion-as-code/view.js";
|
|
7
7
|
export { sync } from "./sync.js";
|
|
8
|
-
export { workflow } from "./workflow.js";
|
|
8
|
+
export { workflow, type Workflow, type WorkflowAccess, type WorkflowAccessAgentLevel, type WorkflowAccessBindings, type WorkflowAccessDeclaration, type WorkflowAccessDeclarations, type WorkflowAccessLevel, type WorkflowAccessLevelFor, type WorkflowAccessResource, type WorkflowAccessResourceLevel, type WorkflowAccessResourceType, type WorkflowAccessRequirement, type WorkflowAccessRequirements, type WorkflowAccessValue, type WorkflowConfiguration, type WorkflowContext, type WorkflowTriggerConfiguration, } from "./workflow.js";
|
|
9
9
|
export type { WorkflowState, WorkflowStateValue } from "./workflow-state.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
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,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,QAAQ,EACR,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,4BAA4B,GACjC,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,9 @@ import { page } from "./notion-as-code/page.js";
|
|
|
5
5
|
import { teamspace } from "./notion-as-code/teamspace.js";
|
|
6
6
|
import { view } from "./notion-as-code/view.js";
|
|
7
7
|
import { sync } from "./sync.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
workflow
|
|
10
|
+
} from "./workflow.js";
|
|
9
11
|
export {
|
|
10
12
|
customAgent,
|
|
11
13
|
customBlock,
|
|
@@ -11,6 +11,7 @@ export type CustomAgentArgs = {
|
|
|
11
11
|
triggers?: readonly unknown[];
|
|
12
12
|
};
|
|
13
13
|
export type CustomAgentHandle = {
|
|
14
|
+
readonly resourceType: "customAgent";
|
|
14
15
|
readonly resourceId: string;
|
|
15
16
|
};
|
|
16
17
|
/** Declare a custom agent and validate every shared resource reference. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-agent.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/custom-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIpF,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;IAC7E,eAAe,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAExC,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CASpE"}
|
|
1
|
+
{"version":3,"file":"custom-agent.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/custom-agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIpF,MAAM,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;IAC7E,eAAe,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAExC,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,iBAAiB,CASpE"}
|
|
@@ -70,12 +70,14 @@ export type DatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema,
|
|
|
70
70
|
export type ChildDatabaseArgs<Schema extends NotionAsCodeSchema = NotionAsCodeSchema, DataSources extends DataSourceMap = DataSourceMap> = ChildSingleSourceDatabaseArgs<Schema> | ChildMultiSourceDatabaseArgs<DataSources> | Omit<ViewOnlyDatabaseArgs, "parent">;
|
|
71
71
|
/** A source handle retains its keyed authoring schema for sync inference. */
|
|
72
72
|
export type DataSourceHandle<Schema extends NotionAsCodeSchema = NotionAsCodeSchema> = {
|
|
73
|
+
readonly resourceType: "dataSource";
|
|
73
74
|
readonly resourceId: string;
|
|
74
75
|
readonly schema: Schema;
|
|
75
76
|
readonly database: Database<AppsSchemaForSchema<Schema>>;
|
|
76
77
|
addPage: (args: ChildPageArgs) => PageHandle;
|
|
77
78
|
};
|
|
78
79
|
type DatabaseHandleBase = {
|
|
80
|
+
readonly resourceType: "database";
|
|
79
81
|
readonly resourceId: string;
|
|
80
82
|
addView: (view: ViewSchema) => void;
|
|
81
83
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAEN,KAAK,cAAc,EAEnB,KAAK,gBAAgB,EAErB,KAAK,kBAAkB,EACvB,KAAK,M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its data source`);
|
|
54
54
|
}
|
|
55
55
|
return {
|
|
56
|
+
resourceType: "database",
|
|
56
57
|
resourceId: databaseResourceId,
|
|
57
58
|
dataSource,
|
|
58
59
|
addView: handle.addView
|
|
@@ -151,6 +152,7 @@ function createDatabase(intent, sourceEntries) {
|
|
|
151
152
|
}
|
|
152
153
|
recordIntent({ ...intent, type: "database" });
|
|
153
154
|
return {
|
|
155
|
+
resourceType: "database",
|
|
154
156
|
resourceId: intent.resourceId,
|
|
155
157
|
datasources: handles,
|
|
156
158
|
addView(view) {
|
|
@@ -177,6 +179,7 @@ function createDataSourceHandle(dataSource, schema) {
|
|
|
177
179
|
propertyNames.add(property.name);
|
|
178
180
|
}
|
|
179
181
|
return {
|
|
182
|
+
resourceType: "dataSource",
|
|
180
183
|
resourceId: dataSource.resourceId,
|
|
181
184
|
schema,
|
|
182
185
|
database: createAppsDatabase(dataSource.resourceId, dataSource),
|
|
@@ -11,6 +11,7 @@ export type PageArgs = {
|
|
|
11
11
|
};
|
|
12
12
|
export type ChildPageArgs = Omit<PageArgs, "parent">;
|
|
13
13
|
export type PageHandle = {
|
|
14
|
+
readonly resourceType: "page";
|
|
14
15
|
readonly resourceId: string;
|
|
15
16
|
addDatabase: ChildDatabaseFactory;
|
|
16
17
|
addPage: (args: ChildPageArgs) => PageHandle;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../../src/notion-as-code/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,MAAM,EACX,KAAK,UAAU,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAuB,KAAK,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAI/E,MAAM,MAAM,QAAQ,GAAG;IACtB,UAAU,EAAE,UAAU,CAAC;IACvB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,UAAU,CAAC,EAAE,MAAM,CA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Q,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,oBAAoB,CAAC;IAClC,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,UAAU,CAAC;CAC7C,CAAC;AAEF,oFAAoF;AACpF,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAS/C;AAED,6DAA6D;AAC7D,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAgBrF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-access-types.test.d.ts","sourceRoot":"","sources":["../src/workflow-access-types.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CustomAgentHandle } from "./notion-as-code/custom-agent.js";
|
|
2
|
+
import type { DataSourceHandle, DatabaseHandle, SingleSourceDatabaseHandle } from "./notion-as-code/database.js";
|
|
3
|
+
import type { PageHandle } from "./notion-as-code/page.js";
|
|
4
|
+
/** A Notion-as-Code resource that can provide a named workflow binding. */
|
|
5
|
+
export type WorkflowAccessResource = PageHandle | DatabaseHandle | SingleSourceDatabaseHandle | DataSourceHandle | CustomAgentHandle;
|
|
6
|
+
/** Resource kinds accepted by workflow access declarations. */
|
|
7
|
+
export type WorkflowAccessResourceType = WorkflowAccessResource["resourceType"];
|
|
8
|
+
/** Levels accepted by pages, databases, and data sources. */
|
|
9
|
+
export type WorkflowAccessResourceLevel = "view" | "comment" | "edit" | "fullAccess";
|
|
10
|
+
/** The only level accepted by a custom agent. */
|
|
11
|
+
export type WorkflowAccessAgentLevel = "call";
|
|
12
|
+
/** Every level accepted by at least one workflow access resource. */
|
|
13
|
+
export type WorkflowAccessLevel = WorkflowAccessResourceLevel | WorkflowAccessAgentLevel;
|
|
14
|
+
/** The level set accepted by a particular resource kind. */
|
|
15
|
+
export type WorkflowAccessLevelFor<TType extends WorkflowAccessResourceType> = TType extends "customAgent" ? WorkflowAccessAgentLevel : WorkflowAccessResourceLevel;
|
|
16
|
+
type AccessResourceFor<TType extends WorkflowAccessResourceType> = Extract<WorkflowAccessResource, {
|
|
17
|
+
resourceType: TType;
|
|
18
|
+
}>;
|
|
19
|
+
/** A named binding declaration pairing one NaC handle with its allowed level. */
|
|
20
|
+
export type WorkflowAccessDeclaration = {
|
|
21
|
+
[TType in WorkflowAccessResourceType]: {
|
|
22
|
+
readonly resource: AccessResourceFor<TType>;
|
|
23
|
+
readonly level: WorkflowAccessLevelFor<TType>;
|
|
24
|
+
};
|
|
25
|
+
}[WorkflowAccessResourceType];
|
|
26
|
+
/** Named binding declarations keyed by the names exposed on workflow context. */
|
|
27
|
+
export type WorkflowAccessDeclarations = Readonly<Record<string, WorkflowAccessDeclaration>>;
|
|
28
|
+
/** A normalized named-binding requirement, including the required NaC resourceId. */
|
|
29
|
+
export type WorkflowAccessRequirement = {
|
|
30
|
+
[TType in WorkflowAccessResourceType]: {
|
|
31
|
+
readonly type: TType;
|
|
32
|
+
readonly resourceId: string;
|
|
33
|
+
readonly level: WorkflowAccessLevelFor<TType>;
|
|
34
|
+
};
|
|
35
|
+
}[WorkflowAccessResourceType];
|
|
36
|
+
/** Normalized named-binding requirements keyed by public alias. */
|
|
37
|
+
export type WorkflowAccessRequirements = Readonly<Record<string, WorkflowAccessRequirement>>;
|
|
38
|
+
/** The resolved NaC binding exposed to a workflow handler. */
|
|
39
|
+
export type WorkflowAccessValue<TType extends WorkflowAccessResourceType = WorkflowAccessResourceType> = Readonly<{
|
|
40
|
+
type: TType;
|
|
41
|
+
id: string;
|
|
42
|
+
}>;
|
|
43
|
+
/** Resolved access values keyed by their public aliases. */
|
|
44
|
+
export type WorkflowAccess<TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = Readonly<{
|
|
45
|
+
[TKey in keyof TAccess]: TAccess[TKey] extends {
|
|
46
|
+
readonly resource: {
|
|
47
|
+
readonly resourceType: infer TType;
|
|
48
|
+
};
|
|
49
|
+
} ? TType extends WorkflowAccessResourceType ? WorkflowAccessValue<TType> : never : never;
|
|
50
|
+
}>;
|
|
51
|
+
/** Resolved NaC bindings keyed by public aliases, without declaration metadata. */
|
|
52
|
+
export type WorkflowAccessBindings = Readonly<Record<string, WorkflowAccessValue>>;
|
|
53
|
+
/**
|
|
54
|
+
* Normalize public binding declarations without retaining the handle objects.
|
|
55
|
+
* Handles contain methods and schema objects, so they must never be cloned into
|
|
56
|
+
* the manifest or captured by the runtime transport. These declarations do not
|
|
57
|
+
* grant or change the workflow's existing Notion-module permissions.
|
|
58
|
+
*/
|
|
59
|
+
export declare function normalizeWorkflowAccess(declarations: WorkflowAccessDeclarations | undefined): WorkflowAccessRequirements;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve trusted per-invocation NaC bindings into the minimal context value.
|
|
62
|
+
* This exposes only declared aliases and does not determine Notion API
|
|
63
|
+
* authorization; the workflow's existing Notion-module permissions do that.
|
|
64
|
+
* The environment is deliberately not parsed when no binding is required.
|
|
65
|
+
*/
|
|
66
|
+
export declare function hydrateWorkflowAccess<TAccess extends WorkflowAccessDeclarations>(requirements: WorkflowAccessRequirements | undefined): WorkflowAccess<TAccess>;
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=workflow-access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-access.d.ts","sourceRoot":"","sources":["../src/workflow-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EACX,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE3D,2EAA2E;AAC3E,MAAM,MAAM,sBAAsB,GAC/B,UAAU,GACV,cAAc,GACd,0BAA0B,GAC1B,gBAAgB,GAChB,iBAAiB,CAAC;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6
|
+
dataSource: true,
|
|
7
|
+
customAgent: true
|
|
8
|
+
};
|
|
9
|
+
function normalizeWorkflowAccess(declarations) {
|
|
10
|
+
const source = declarations ?? {};
|
|
11
|
+
assertPlainObject(source, "Workflow access must be an object keyed by alias.");
|
|
12
|
+
const keys = Object.keys(source);
|
|
13
|
+
if (Reflect.ownKeys(source).length !== keys.length) {
|
|
14
|
+
throw new Error("Workflow access aliases must be enumerable strings.");
|
|
15
|
+
}
|
|
16
|
+
if (keys.length > 100) {
|
|
17
|
+
throw new Error("Workflows support at most 100 access requirements.");
|
|
18
|
+
}
|
|
19
|
+
const normalized = /* @__PURE__ */ Object.create(null);
|
|
20
|
+
for (const alias of keys) {
|
|
21
|
+
if (!ACCESS_ALIAS_PATTERN.test(alias) || RESERVED_ACCESS_ALIASES.has(alias)) {
|
|
22
|
+
throw new Error(`Invalid workflow access alias: ${alias}`);
|
|
23
|
+
}
|
|
24
|
+
const declaration = source[alias];
|
|
25
|
+
if (!isRecord(declaration) || !Object.hasOwn(declaration, "resource") || !Object.hasOwn(declaration, "level")) {
|
|
26
|
+
throw new Error(`Workflow access "${alias}" must declare a resource and level.`);
|
|
27
|
+
}
|
|
28
|
+
const resource = declaration.resource;
|
|
29
|
+
if (!isRecord(resource) || !Object.hasOwn(resource, "resourceType") || !Object.hasOwn(resource, "resourceId") || typeof resource.resourceId !== "string" || resource.resourceId.length === 0 || !isWorkflowAccessResourceType(resource.resourceType)) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Workflow access "${alias}" must reference a supported NaC resource handle.`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
let requirement;
|
|
35
|
+
if (resource.resourceType === "customAgent") {
|
|
36
|
+
if (declaration.level !== "call") {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Workflow access "${alias}" custom agents only support level "call".`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
requirement = {
|
|
42
|
+
type: resource.resourceType,
|
|
43
|
+
resourceId: resource.resourceId,
|
|
44
|
+
level: declaration.level
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
if (!isWorkflowAccessResourceLevel(declaration.level)) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Workflow access "${alias}" ${resource.resourceType} level must be view, comment, edit, or fullAccess.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
requirement = {
|
|
53
|
+
type: resource.resourceType,
|
|
54
|
+
resourceId: resource.resourceId,
|
|
55
|
+
level: declaration.level
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
normalized[alias] = Object.freeze(requirement);
|
|
59
|
+
}
|
|
60
|
+
return Object.freeze(normalized);
|
|
61
|
+
}
|
|
62
|
+
function hydrateWorkflowAccess(requirements) {
|
|
63
|
+
const expected = requirements ?? {};
|
|
64
|
+
const aliases = Object.keys(expected);
|
|
65
|
+
const empty = /* @__PURE__ */ Object.create(null);
|
|
66
|
+
if (aliases.length === 0) {
|
|
67
|
+
return Object.freeze(empty);
|
|
68
|
+
}
|
|
69
|
+
const rawBindings = process.env.NOTION_ACCESS_BINDINGS;
|
|
70
|
+
if (rawBindings === void 0) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Workflow access requirements are not bound. Deploy and configure this requirement before running it."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (rawBindings.length === 0) {
|
|
76
|
+
throw new Error("Invalid NOTION_ACCESS_BINDINGS metadata.");
|
|
77
|
+
}
|
|
78
|
+
let parsed;
|
|
79
|
+
try {
|
|
80
|
+
parsed = JSON.parse(rawBindings);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
throw new Error("Invalid NOTION_ACCESS_BINDINGS metadata.", { cause: error });
|
|
83
|
+
}
|
|
84
|
+
assertPlainObject(parsed, "Invalid NOTION_ACCESS_BINDINGS metadata.");
|
|
85
|
+
const bindingKeys = Object.keys(parsed);
|
|
86
|
+
if (Reflect.ownKeys(parsed).length !== bindingKeys.length || bindingKeys.length !== aliases.length || bindingKeys.some((alias) => !Object.hasOwn(expected, alias))) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
"Invalid NOTION_ACCESS_BINDINGS metadata: aliases do not match workflow access."
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const resolved = /* @__PURE__ */ Object.create(null);
|
|
92
|
+
for (const alias of aliases) {
|
|
93
|
+
const requirement = expected[alias];
|
|
94
|
+
if (!requirement) {
|
|
95
|
+
throw new Error(`Workflow access "${alias}" is not declared.`);
|
|
96
|
+
}
|
|
97
|
+
const binding = parsed[alias];
|
|
98
|
+
if (!isBinding(binding)) {
|
|
99
|
+
throw new Error(`Invalid NOTION_ACCESS_BINDINGS metadata for access "${alias}".`);
|
|
100
|
+
}
|
|
101
|
+
if (binding.type !== requirement.type || binding.resourceId !== requirement.resourceId || binding.level !== requirement.level) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Workflow access "${alias}" binding does not match its declared type, resourceId, or level.`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
resolved[alias] = Object.freeze({ type: binding.type, id: binding.id });
|
|
107
|
+
}
|
|
108
|
+
return Object.freeze(resolved);
|
|
109
|
+
}
|
|
110
|
+
function isWorkflowAccessResourceType(value) {
|
|
111
|
+
return typeof value === "string" && Object.hasOwn(RESOURCE_TYPES, value);
|
|
112
|
+
}
|
|
113
|
+
function isWorkflowAccessResourceLevel(value) {
|
|
114
|
+
return value === "view" || value === "comment" || value === "edit" || value === "fullAccess";
|
|
115
|
+
}
|
|
116
|
+
function isBinding(value) {
|
|
117
|
+
if (!isRecord(value) || Reflect.ownKeys(value).length !== 4) return false;
|
|
118
|
+
const keys = Object.keys(value);
|
|
119
|
+
if (keys.length !== 4 || !keys.includes("type") || !keys.includes("resourceId") || !keys.includes("level") || !keys.includes("id")) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
return isWorkflowAccessResourceType(value.type) && typeof value.resourceId === "string" && value.resourceId.length > 0 && typeof value.level === "string" && (isWorkflowAccessResourceLevel(value.level) || value.level === "call") && typeof value.id === "string" && value.id.length > 0;
|
|
123
|
+
}
|
|
124
|
+
function assertPlainObject(value, message) {
|
|
125
|
+
if (!isRecord(value)) throw new Error(message);
|
|
126
|
+
const prototype = Object.getPrototypeOf(value);
|
|
127
|
+
if (prototype !== Object.prototype && prototype !== null) throw new Error(message);
|
|
128
|
+
}
|
|
129
|
+
function isRecord(value) {
|
|
130
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
hydrateWorkflowAccess,
|
|
134
|
+
normalizeWorkflowAccess
|
|
135
|
+
};
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type WorkflowConnectionDeclarations, type WorkflowConnectionRequirement, type WorkflowConnections } from "./connections.js";
|
|
2
|
+
import { type WorkflowAccess, type WorkflowAccessDeclarations, type WorkflowAccessRequirements } from "./workflow-access.js";
|
|
2
3
|
import type { CapabilityContext } from "./context.js";
|
|
3
4
|
import { type RunMetadata } from "./runtime-metadata.js";
|
|
4
5
|
import { type WorkflowState } from "./workflow-state.js";
|
|
@@ -37,6 +38,7 @@ export type WorkflowWaitUntilResult = {
|
|
|
37
38
|
type WorkflowHandlerResult = {
|
|
38
39
|
status: "success";
|
|
39
40
|
} | WorkflowWaitUntilResult;
|
|
41
|
+
export type { WorkflowAccess, WorkflowAccessAgentLevel, WorkflowAccessBindings, WorkflowAccessDeclaration, WorkflowAccessDeclarations, WorkflowAccessLevel, WorkflowAccessLevelFor, WorkflowAccessResource, WorkflowAccessResourceLevel, WorkflowAccessResourceType, WorkflowAccessRequirement, WorkflowAccessRequirements, WorkflowAccessValue, } from "./workflow-access.js";
|
|
40
42
|
export type WorkflowEvent = WorkflowEventMap[keyof WorkflowEventMap];
|
|
41
43
|
export type WorkflowEventForTrigger<T extends WorkflowTrigger> = WorkflowEventMap[T["type"]];
|
|
42
44
|
export type WorkflowEventForTriggers<T extends readonly WorkflowTrigger[]> = WorkflowEventForTrigger<T[number]>;
|
|
@@ -44,7 +46,7 @@ export { connections, type WorkflowConnection, type WorkflowConnectionDeclaratio
|
|
|
44
46
|
/**
|
|
45
47
|
* Configuration passed to {@link workflow}.
|
|
46
48
|
*/
|
|
47
|
-
export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations> = {
|
|
49
|
+
export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = {
|
|
48
50
|
/**
|
|
49
51
|
* A human-readable name for the workflow, shown in the UI when viewing workflows
|
|
50
52
|
*/
|
|
@@ -59,14 +61,20 @@ export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, .
|
|
|
59
61
|
* Each trigger defines a specific event or condition that causes the workflow to run.
|
|
60
62
|
*/
|
|
61
63
|
triggers: TTriggers;
|
|
64
|
+
/**
|
|
65
|
+
* Notion-as-Code resources whose access is configured during cloud deployment.
|
|
66
|
+
* Deployment reconciles grants through the existing Notion-module permissions
|
|
67
|
+
* and supplies named runtime bindings on `context.access`.
|
|
68
|
+
*/
|
|
69
|
+
access?: TAccess;
|
|
62
70
|
/**
|
|
63
71
|
* Connections that must be set up before this workflow can run.
|
|
64
72
|
*/
|
|
65
73
|
connections?: TConnections;
|
|
66
|
-
handler: (event: WorkflowEventForTriggers<TTriggers>, context: WorkflowContext<TConnections>) => Promise<void> | void;
|
|
74
|
+
handler: (event: WorkflowEventForTriggers<TTriggers>, context: WorkflowContext<TConnections, TAccess>) => Promise<void> | void;
|
|
67
75
|
};
|
|
68
76
|
/** Configuration that checks trigger keys against declared connections. */
|
|
69
|
-
export type WorkflowTriggerConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations> = Omit<WorkflowConfiguration<TTriggers, TConnections>, "triggers"> & {
|
|
77
|
+
export type WorkflowTriggerConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess>, "triggers"> & {
|
|
70
78
|
triggers: (context: {
|
|
71
79
|
triggers: WorkflowTriggerCreators<NoInfer<TConnections>>;
|
|
72
80
|
}) => TTriggers;
|
|
@@ -87,6 +95,7 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
|
|
|
87
95
|
description: string;
|
|
88
96
|
triggers: TTriggers;
|
|
89
97
|
connections?: readonly WorkflowConnectionRequirement[];
|
|
98
|
+
access?: WorkflowAccessRequirements;
|
|
90
99
|
};
|
|
91
100
|
handler: (event: WorkflowEventForTriggers<TTriggers>, options?: HandlerOptions) => Promise<WorkflowHandlerResult | undefined>;
|
|
92
101
|
};
|
|
@@ -119,8 +128,8 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
|
|
|
119
128
|
export declare function workflow<const TTriggers extends readonly [
|
|
120
129
|
WorkflowTriggerForConnections<NoInfer<TConnections>>,
|
|
121
130
|
...WorkflowTriggerForConnections<NoInfer<TConnections>>[]
|
|
122
|
-
], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>>(configuration: WorkflowTriggerConfiguration<TTriggers, TConnections>): Workflow<TTriggers>;
|
|
123
|
-
export declare function workflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>>(configuration: WorkflowConfiguration<TTriggers, TConnections>): Workflow<TTriggers>;
|
|
131
|
+
], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>, const TAccess extends WorkflowAccessDeclarations = Record<never, never>>(configuration: WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess>): Workflow<TTriggers>;
|
|
132
|
+
export declare function workflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>, const TAccess extends WorkflowAccessDeclarations = Record<never, never>>(configuration: WorkflowConfiguration<TTriggers, TConnections, TAccess>): Workflow<TTriggers>;
|
|
124
133
|
/** Context passed to a workflow step. */
|
|
125
134
|
export type StepContext = {
|
|
126
135
|
/**
|
|
@@ -158,7 +167,9 @@ type WorkflowWait = {
|
|
|
158
167
|
until(name: string, options: WorkflowWaitUntilOptions): Promise<void>;
|
|
159
168
|
};
|
|
160
169
|
/** Context passed to a workflow handler. */
|
|
161
|
-
export type WorkflowContext<TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations> = CapabilityContext & {
|
|
170
|
+
export type WorkflowContext<TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = CapabilityContext & {
|
|
171
|
+
/** Resolved NaC bindings for this invocation; UI-granted resources are not added here. */
|
|
172
|
+
readonly access: WorkflowAccess<TAccess>;
|
|
162
173
|
connections: WorkflowConnections<TConnections>;
|
|
163
174
|
} & RunMetadata & {
|
|
164
175
|
/**
|
package/dist/workflow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,0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