@notionhq/apps 0.0.46 → 0.0.47

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 CHANGED
@@ -174,6 +174,16 @@ do not need to specify `additionalProperties`.
174
174
  See the [manual workflow example](./skills/workflow/SKILL.md#manual-workflow-inputs)
175
175
  for the supported schema subset and a complete typed workflow.
176
176
 
177
+ ## Workflow outputs
178
+
179
+ Use `outputSchema` to declare the object a workflow returns. It takes the same
180
+ `j.object(...)` schema builder as manual inputs. The handler's return type is
181
+ inferred from the schema, and the SDK validates the returned value before the run
182
+ succeeds. The output must be at most 256 KB as JSON. A workflow without
183
+ `outputSchema` returns nothing.
184
+
185
+ See the [workflow output example](./skills/workflow/SKILL.md#workflow-outputs).
186
+
177
187
  ## Notion API access
178
188
 
179
189
  Use `context.notion` for Notion API calls. Deployed apps receive Notion API
@@ -2,9 +2,21 @@ import { Ajv } from "ajv";
2
2
  import addFormats from "ajv-formats";
3
3
  import { getSchema } from "./schema-builder.js";
4
4
  function compileWorkflowInputSchema(schema) {
5
+ return compileWorkflowObjectSchema(schema, {
6
+ schemaName: "workflow manual inputSchema",
7
+ valueName: "manual workflow input"
8
+ });
9
+ }
10
+ function compileWorkflowOutputSchema(schema) {
11
+ return compileWorkflowObjectSchema(schema, {
12
+ schemaName: "workflow outputSchema",
13
+ valueName: "workflow output"
14
+ });
15
+ }
16
+ function compileWorkflowObjectSchema(schema, names) {
5
17
  const jsonSchema = getSchema(schema);
6
18
  if (!("type" in jsonSchema) || jsonSchema.type !== "object") {
7
- throw new Error("workflow manual inputSchema: must be a j.object() schema");
19
+ throw new Error(`${names.schemaName}: must be a j.object() schema`);
8
20
  }
9
21
  const ajv = new Ajv({ allErrors: true, strict: true });
10
22
  addFormats.default(ajv, {
@@ -24,15 +36,14 @@ function compileWorkflowInputSchema(schema) {
24
36
  const validate = ajv.compile(jsonSchema);
25
37
  return {
26
38
  jsonSchema,
27
- validate(input) {
28
- if (!validate(input)) {
29
- throw new Error(
30
- `Invalid manual workflow input: ${ajv.errorsText(validate.errors)}`
31
- );
39
+ validate(value) {
40
+ if (!validate(value)) {
41
+ throw new Error(`Invalid ${names.valueName}: ${ajv.errorsText(validate.errors)}`);
32
42
  }
33
43
  }
34
44
  };
35
45
  }
36
46
  export {
37
- compileWorkflowInputSchema
47
+ compileWorkflowInputSchema,
48
+ compileWorkflowOutputSchema
38
49
  };
@@ -2,6 +2,7 @@ import { type WorkflowConnectionDeclarations, type WorkflowConnectionRequirement
2
2
  import { type WorkflowAccess, type WorkflowAccessDeclarations, type WorkflowAccessRequirements } from "./workflow-access.js";
3
3
  import type { CapabilityContext } from "./context.js";
4
4
  import { type RunMetadata } from "./runtime-metadata.js";
5
+ import type { Infer, SchemaBuilder } from "./schema-builder.js";
5
6
  import { type WorkflowState } from "./workflow-state.js";
6
7
  import type { ManualWorkflowTrigger, WebhookTrigger, WorkflowEventMap, WorkflowTrigger, WorkflowEventCreators, WorkflowTriggerForConnections } from "./events.generated.js";
7
8
  type HandlerOptions = {
@@ -91,7 +92,15 @@ export type WorkflowWaitForInputResult = {
91
92
  type WorkflowWaitResult = WorkflowWaitUntilResult | WorkflowWaitForInputResult;
92
93
  type WorkflowHandlerResult = {
93
94
  status: "success";
95
+ output?: Record<string, unknown>;
94
96
  } | WorkflowWaitResult;
97
+ /** An object schema describing the value a workflow returns. */
98
+ export type WorkflowOutputSchema = SchemaBuilder<Record<string, unknown>, "object">;
99
+ /**
100
+ * What a workflow handler returns: the value described by `outputSchema`, or
101
+ * nothing when the workflow declares no output schema.
102
+ */
103
+ export type WorkflowHandlerReturn<TOutputSchema extends WorkflowOutputSchema | undefined> = TOutputSchema extends WorkflowOutputSchema ? Promise<Infer<TOutputSchema>> | Infer<TOutputSchema> : Promise<void> | void;
95
104
  export { FatalError, RetryableError } from "./error.js";
96
105
  export type { WorkflowAccess, WorkflowAccessAgentLevel, WorkflowAccessBindings, WorkflowAccessDeclaration, WorkflowAccessDeclarations, WorkflowAccessLevel, WorkflowAccessLevelFor, WorkflowAccessResource, ResourceAccessLevel, WorkflowAccessResourceType, WorkflowAccessRequirement, WorkflowAccessRequirements, WorkflowAccessValue, } from "./workflow-access.js";
97
106
  export { access } from "./workflow-access.js";
@@ -194,7 +203,7 @@ export type WorkflowManifestTrigger = WorkflowTrigger | (WebhookTrigger & {
194
203
  /**
195
204
  * Configuration passed to {@link workflow}.
196
205
  */
197
- export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = {
206
+ export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations, TOutputSchema extends WorkflowOutputSchema | undefined = undefined> = {
198
207
  /**
199
208
  * A human-readable name for the workflow, shown in the UI when viewing workflows
200
209
  */
@@ -259,10 +268,24 @@ export type WorkflowConfiguration<TTriggers extends readonly [WorkflowTrigger, .
259
268
  * ```
260
269
  */
261
270
  verify?: WebhookVerifyHandler;
262
- handler: (event: WorkflowEventForTriggers<TTriggers>, context: WorkflowContext<TConnections, TAccess>) => Promise<void> | void;
271
+ /**
272
+ * Optional schema for the object the handler returns, built with
273
+ * `@notionhq/apps/schema-builder`. The handler's return type is inferred
274
+ * from it, and the returned value is validated before the run succeeds.
275
+ *
276
+ * Without `outputSchema`, the workflow returns nothing.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * outputSchema: j.object({ releaseUrl: j.string() }),
281
+ * handler: async () => ({ releaseUrl: "https://example.com/releases/1" }),
282
+ * ```
283
+ */
284
+ outputSchema?: TOutputSchema;
285
+ handler: (event: WorkflowEventForTriggers<TTriggers>, context: WorkflowContext<TConnections, TAccess>) => WorkflowHandlerReturn<NoInfer<TOutputSchema>>;
263
286
  };
264
287
  /** Configuration that checks trigger keys against declared connections. */
265
- export type WorkflowTriggerConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations> = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess>, "triggers"> & {
288
+ export type WorkflowTriggerConfiguration<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], TConnections extends WorkflowConnectionDeclarations, TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations, TOutputSchema extends WorkflowOutputSchema | undefined = undefined> = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>, "triggers"> & {
266
289
  triggers: (context: {
267
290
  events: WorkflowEventCreators<NoInfer<TConnections>>;
268
291
  }) => TTriggers;
@@ -286,6 +309,8 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
286
309
  access?: WorkflowAccessRequirements;
287
310
  deadline?: WorkflowDeadline;
288
311
  retry?: WorkflowRetryPolicy;
312
+ /** JSON Schema for the handler's return value. Absent when the workflow returns nothing. */
313
+ outputJsonSchema?: Record<string, unknown>;
289
314
  };
290
315
  handler: (input: WorkflowEventForTriggers<TTriggers> | WebhookVerifyInvocation, options?: HandlerOptions) => Promise<WorkflowHandlerResult | WebhookVerifyResponse | undefined>;
291
316
  };
@@ -318,8 +343,8 @@ export type Workflow<TTriggers extends readonly [WorkflowTrigger, ...WorkflowTri
318
343
  export declare function workflow<const TTriggers extends readonly [
319
344
  WorkflowTriggerForConnections<NoInfer<TConnections>>,
320
345
  ...WorkflowTriggerForConnections<NoInfer<TConnections>>[]
321
- ], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>, const TAccess extends WorkflowAccessDeclarations = Record<never, never>>(configuration: WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess>): Workflow<TTriggers>;
322
- 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>;
346
+ ], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>, const TAccess extends WorkflowAccessDeclarations = Record<never, never>, const TOutputSchema extends WorkflowOutputSchema | undefined = undefined>(configuration: WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>): Workflow<TTriggers>;
347
+ export declare function workflow<const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]], const TConnections extends WorkflowConnectionDeclarations = Record<never, never>, const TAccess extends WorkflowAccessDeclarations = Record<never, never>, const TOutputSchema extends WorkflowOutputSchema | undefined = undefined>(configuration: WorkflowConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>): Workflow<TTriggers>;
323
348
  /** Context passed to a workflow step. */
324
349
  export type StepContext = {
325
350
  /**
@@ -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;AAC1B,OAAO,EAGN,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAKtD,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAE1E,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EACX,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,6BAA6B,EAC7B,MAAM,uBAAuB,CAAC;AAE/B,KAAK,cAAc,GAAG;IACrB,yEAAyE;IACz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E,YAAY,CAAC;CACnB,CAAC"}
package/dist/workflow.js CHANGED
@@ -16,6 +16,7 @@ import { writeOutput } from "./output.js";
16
16
  import { resolveRuntimeInput } from "./runtime-input.js";
17
17
  import { readRunMetadata } from "./runtime-metadata.js";
18
18
  import { createWorkflowEvents, validateManualWorkflowInput } from "./events.generated.js";
19
+ import { compileWorkflowOutputSchema } from "./workflow-schema.js";
19
20
  import { createWorkflowStepState } from "./workflow-state.js";
20
21
  const WEBHOOK_TRIGGER_TYPE = "webhooks.webhook";
21
22
  const input = {
@@ -74,6 +75,7 @@ function workflow(configuration) {
74
75
  }
75
76
  const deadline = configuration.deadline === void 0 ? void 0 : structuredClone(configuration.deadline);
76
77
  const retry = configuration.retry === void 0 ? void 0 : manifestRetryPolicy(configuration.retry);
78
+ const outputSchema = configuration.outputSchema === void 0 ? void 0 : compileWorkflowOutputSchema(configuration.outputSchema);
77
79
  const manualTriggers = triggers.filter(
78
80
  (trigger) => trigger.type === "workflow.manual"
79
81
  );
@@ -94,7 +96,8 @@ function workflow(configuration) {
94
96
  ...configuration.connections === void 0 ? {} : { connections: requirements },
95
97
  ...configuration.access === void 0 ? {} : { access: accessRequirements },
96
98
  ...deadline === void 0 ? {} : { deadline },
97
- ...retry === void 0 ? {} : { retry }
99
+ ...retry === void 0 ? {} : { retry },
100
+ ...outputSchema === void 0 ? {} : { outputJsonSchema: outputSchema.jsonSchema }
98
101
  },
99
102
  async handler(input2, options) {
100
103
  const invocationStartedAt = Date.now();
@@ -145,11 +148,21 @@ function workflow(configuration) {
145
148
  }
146
149
  validateManualWorkflowInput(manualTrigger, event.input);
147
150
  }
148
- await configuration.handler(event, capabilityContext);
151
+ const handlerOutput = await configuration.handler(
152
+ event,
153
+ capabilityContext
154
+ );
155
+ const result = outputSchema === void 0 ? { status: "success" } : {
156
+ status: "success",
157
+ output: serializeWorkflowOutput(
158
+ handlerOutput,
159
+ outputSchema.validate
160
+ )
161
+ };
149
162
  if (options?.concreteOutput) {
150
- return { status: "success" };
163
+ return result;
151
164
  }
152
- writeOutput({ _tag: "success", value: { status: "success" } });
165
+ writeOutput({ _tag: "success", value: result });
153
166
  } catch (err) {
154
167
  if (err instanceof WorkflowWaitInterrupt) {
155
168
  if (options?.concreteOutput) {
@@ -199,6 +212,23 @@ function manifestTriggers(triggers, hasVerify) {
199
212
  (trigger) => hasVerify && trigger.type === WEBHOOK_TRIGGER_TYPE ? { ...trigger, hasVerify: true } : trigger
200
213
  );
201
214
  }
215
+ const MAX_WORKFLOW_OUTPUT_BYTES = 256 * 1024;
216
+ function serializeWorkflowOutput(value, validate) {
217
+ try {
218
+ const json = value === void 0 ? void 0 : JSON.stringify(value);
219
+ const bytes = json === void 0 ? 0 : Buffer.byteLength(json, "utf8");
220
+ if (bytes > MAX_WORKFLOW_OUTPUT_BYTES) {
221
+ throw new Error(
222
+ `Invalid workflow output: must be at most ${MAX_WORKFLOW_OUTPUT_BYTES} bytes as JSON, got ${bytes}.`
223
+ );
224
+ }
225
+ const serialized = json === void 0 ? void 0 : JSON.parse(json);
226
+ validate(serialized);
227
+ return serialized;
228
+ } catch (error) {
229
+ throw new FatalError(error instanceof Error ? error.message : String(error));
230
+ }
231
+ }
202
232
  function isVerifyInvocation(input2) {
203
233
  return typeof input2 === "object" && input2 !== null && "request" in input2;
204
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notionhq/apps",
3
- "version": "0.0.46",
3
+ "version": "0.0.47",
4
4
  "description": "An SDK for building workflow apps for Notion",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -187,6 +187,34 @@ export default workflow({
187
187
  });
188
188
  ```
189
189
 
190
+ ## Workflow outputs
191
+
192
+ Declare `outputSchema` when a workflow returns a value. Use the same
193
+ `@notionhq/apps/schema-builder` builders as manual inputs; the schema must be a
194
+ `j.object(...)`. The handler must return a matching object of at most 256 KB as
195
+ JSON, and the run fails without retrying when it does not. Omit `outputSchema` for workflows that return
196
+ nothing.
197
+
198
+ ```ts
199
+ import { workflow } from "@notionhq/apps/workflow";
200
+ import { events } from "@notionhq/apps/events";
201
+ import { j } from "@notionhq/apps/schema-builder";
202
+
203
+ export default workflow({
204
+ name: "Prepare releases",
205
+ description: "Prepares the supplied releases.",
206
+ triggers: [
207
+ events.manual({
208
+ inputSchema: j.object({ releases: j.array(j.object({ version: j.string() })) }),
209
+ }),
210
+ ],
211
+ outputSchema: j.object({ prepared: j.integer() }),
212
+ handler: async (event) => {
213
+ return { prepared: event.input.releases.length };
214
+ },
215
+ });
216
+ ```
217
+
190
218
  ## Resources created with the App
191
219
 
192
220
  Use [Notion as Code](../notion-as-code/SKILL.md) for pages, databases, and custom agents
@@ -611,6 +611,12 @@ describe("buildApp", () => {
611
611
  },
612
612
  },
613
613
  ],
614
+ outputJsonSchema: {
615
+ type: "object",
616
+ additionalProperties: false,
617
+ required: ["prepared"],
618
+ properties: { prepared: { type: "integer" } },
619
+ },
614
620
  },
615
621
  },
616
622
  ],
@@ -2,16 +2,38 @@ import { Ajv } from "ajv";
2
2
  import addFormats from "ajv-formats";
3
3
  import { getSchema, type SchemaBuilder } from "./schema-builder.js";
4
4
 
5
+ type CompiledWorkflowSchema = {
6
+ jsonSchema: Record<string, unknown>;
7
+ validate: (value: unknown) => void;
8
+ };
9
+
5
10
  /** @internal */
6
11
  export function compileWorkflowInputSchema(
7
12
  schema: SchemaBuilder<Record<string, unknown>, "object">,
8
- ): {
9
- jsonSchema: Record<string, unknown>;
10
- validate: (input: unknown) => void;
11
- } {
13
+ ): CompiledWorkflowSchema {
14
+ return compileWorkflowObjectSchema(schema, {
15
+ schemaName: "workflow manual inputSchema",
16
+ valueName: "manual workflow input",
17
+ });
18
+ }
19
+
20
+ /** @internal */
21
+ export function compileWorkflowOutputSchema(
22
+ schema: SchemaBuilder<Record<string, unknown>, "object">,
23
+ ): CompiledWorkflowSchema {
24
+ return compileWorkflowObjectSchema(schema, {
25
+ schemaName: "workflow outputSchema",
26
+ valueName: "workflow output",
27
+ });
28
+ }
29
+
30
+ function compileWorkflowObjectSchema(
31
+ schema: SchemaBuilder<Record<string, unknown>, "object">,
32
+ names: { schemaName: string; valueName: string },
33
+ ): CompiledWorkflowSchema {
12
34
  const jsonSchema = getSchema(schema);
13
35
  if (!("type" in jsonSchema) || jsonSchema.type !== "object") {
14
- throw new Error("workflow manual inputSchema: must be a j.object() schema");
36
+ throw new Error(`${names.schemaName}: must be a j.object() schema`);
15
37
  }
16
38
  const ajv = new Ajv({ allErrors: true, strict: true });
17
39
  addFormats.default(ajv, {
@@ -31,11 +53,9 @@ export function compileWorkflowInputSchema(
31
53
  const validate = ajv.compile(jsonSchema);
32
54
  return {
33
55
  jsonSchema,
34
- validate(input) {
35
- if (!validate(input)) {
36
- throw new Error(
37
- `Invalid manual workflow input: ${ajv.errorsText(validate.errors)}`,
38
- );
56
+ validate(value) {
57
+ if (!validate(value)) {
58
+ throw new Error(`Invalid ${names.valueName}: ${ajv.errorsText(validate.errors)}`);
39
59
  }
40
60
  },
41
61
  };
@@ -228,6 +228,47 @@ it("checks provider keys on callback arguments and returned triggers", () => {
228
228
  trigger: "events.notionPageCreated()",
229
229
  handler: '(_event, ctx) => { ctx.connections.oauth("github"); }',
230
230
  },
231
+ {
232
+ name: "output_async",
233
+ valid: true,
234
+ trigger: "events.manual()",
235
+ outputSchema: "j.object({ url: j.string(), draft: j.boolean().nullable() })",
236
+ handler: 'async () => ({ url: "https://example.com", draft: null })',
237
+ },
238
+ {
239
+ name: "output_sync",
240
+ valid: true,
241
+ trigger: "events.manual()",
242
+ outputSchema: "j.object({ url: j.string() })",
243
+ handler: '() => ({ url: "https://example.com" })',
244
+ },
245
+ {
246
+ name: "output_mismatch",
247
+ valid: false,
248
+ trigger: "events.manual()",
249
+ outputSchema: "j.object({ url: j.string() })",
250
+ handler: "async () => ({ url: 1 })",
251
+ },
252
+ {
253
+ name: "output_missing_value",
254
+ valid: false,
255
+ trigger: "events.manual()",
256
+ outputSchema: "j.object({ url: j.string() })",
257
+ handler: "async () => {}",
258
+ },
259
+ {
260
+ name: "output_requires_object_schema",
261
+ valid: false,
262
+ trigger: "events.manual()",
263
+ outputSchema: "j.string()",
264
+ handler: '() => "https://example.com"',
265
+ },
266
+ {
267
+ name: "output_absent_returns_void",
268
+ valid: false,
269
+ trigger: "events.manual()",
270
+ handler: 'async () => ({ url: "https://example.com" })',
271
+ },
231
272
  ];
232
273
  const fixtures = new Map(
233
274
  cases.map((testCase) => [
@@ -240,6 +281,7 @@ it("checks provider keys on callback arguments and returned triggers", () => {
240
281
  workflow({
241
282
  name: "Type check", description: "Type check",
242
283
  ${testCase.connections === undefined ? "" : `connections: ${testCase.connections},`}
284
+ ${testCase.outputSchema === undefined ? "" : `outputSchema: ${testCase.outputSchema},`}
243
285
  triggers: ({ events }) => [${testCase.trigger}],
244
286
  handler: ${testCase.handler ?? "() => {}"},
245
287
  });`,
@@ -125,6 +125,111 @@ describe("manual workflow triggers", () => {
125
125
  });
126
126
  });
127
127
 
128
+ describe("workflow output schemas", () => {
129
+ const outputSchema = j.object({ url: j.string(), publishedAt: j.datetime().nullable() });
130
+
131
+ it("records the output JSON Schema in the workflow config", () => {
132
+ const definition = workflow({
133
+ name: "Publish release",
134
+ description: "Publishes a release",
135
+ triggers: [events.manual()],
136
+ outputSchema,
137
+ handler: () => ({ url: "https://example.com", publishedAt: null }),
138
+ });
139
+
140
+ expect(definition.config.outputJsonSchema).toEqual({
141
+ type: "object",
142
+ required: ["url", "publishedAt"],
143
+ additionalProperties: false,
144
+ properties: {
145
+ url: { type: "string" },
146
+ publishedAt: { anyOf: [{ type: "string", format: "date-time" }, { type: "null" }] },
147
+ },
148
+ });
149
+ });
150
+
151
+ it("omits the output schema and output when none is declared", async () => {
152
+ const definition = workflow({
153
+ name: "Log pages",
154
+ description: "Logs created pages",
155
+ triggers: [events.notionPageCreated()],
156
+ handler: () => {},
157
+ });
158
+
159
+ expect(definition.config).not.toHaveProperty("outputJsonSchema");
160
+ await expect(definition.handler(event, { concreteOutput: true })).resolves.toEqual({
161
+ status: "success",
162
+ });
163
+ });
164
+
165
+ it("returns the output in the success envelope", async () => {
166
+ const definition = workflow({
167
+ name: "Publish release",
168
+ description: "Publishes a release",
169
+ triggers: [events.manual()],
170
+ outputSchema,
171
+ handler: async () => ({
172
+ url: "https://example.com",
173
+ publishedAt: "2026-09-28T00:00:00.000Z",
174
+ }),
175
+ });
176
+
177
+ await definition.handler({ type: "workflow.manual", input: {} });
178
+
179
+ expect(stdoutSpy).toHaveBeenLastCalledWith(
180
+ `\n<__notion_output__>${JSON.stringify({
181
+ _tag: "success",
182
+ value: {
183
+ status: "success",
184
+ output: { url: "https://example.com", publishedAt: "2026-09-28T00:00:00.000Z" },
185
+ },
186
+ })}</__notion_output__>\n`,
187
+ );
188
+ });
189
+
190
+ it.each([
191
+ { name: "a missing value", output: undefined },
192
+ { name: "a wrong type", output: { url: 1, publishedAt: null } },
193
+ { name: "an extra key", output: { url: "https://example.com", publishedAt: null, id: 1 } },
194
+ {
195
+ name: "more than 256 KB of JSON",
196
+ output: { url: "x".repeat(256 * 1024), publishedAt: null },
197
+ },
198
+ ])("fails without retrying when the handler returns $name", async ({ output }) => {
199
+ const definition = workflow({
200
+ name: "Publish release",
201
+ description: "Publishes a release",
202
+ triggers: [events.manual()],
203
+ outputSchema,
204
+ // SAFETY: Simulates untyped handler code returning a value outside the schema.
205
+ handler: () => output as never,
206
+ });
207
+
208
+ await expect(
209
+ definition.handler({ type: "workflow.manual", input: {} }),
210
+ ).rejects.toMatchObject({
211
+ cause: expect.objectContaining({
212
+ name: "FatalError",
213
+ message: expect.stringContaining("Invalid workflow output"),
214
+ }),
215
+ });
216
+ expect(String(stdoutSpy.mock.lastCall?.[0])).toContain('"_tag":"terminal"');
217
+ });
218
+
219
+ it("rejects an output schema that is not an object schema", () => {
220
+ expect(() =>
221
+ workflow({
222
+ name: "Publish release",
223
+ description: "Publishes a release",
224
+ triggers: [events.manual()],
225
+ // SAFETY: Simulates untyped app code passing a non-object schema.
226
+ outputSchema: j.string() as never,
227
+ handler: (() => {}) as never,
228
+ }),
229
+ ).toThrow("workflow outputSchema: must be a j.object() schema");
230
+ });
231
+ });
232
+
128
233
  async function createWorkflowContext(
129
234
  retry?: WorkflowRetryPolicy,
130
235
  ): Promise<WorkflowContext<Record<never, never>>> {
package/src/workflow.ts CHANGED
@@ -24,6 +24,8 @@ import { writeOutput } from "./output.js";
24
24
  import { resolveRuntimeInput } from "./runtime-input.js";
25
25
  import { readRunMetadata, type RunMetadata } from "./runtime-metadata.js";
26
26
  import { createWorkflowEvents, validateManualWorkflowInput } from "./events.generated.js";
27
+ import type { Infer, SchemaBuilder } from "./schema-builder.js";
28
+ import { compileWorkflowOutputSchema } from "./workflow-schema.js";
27
29
  import { createWorkflowStepState, type WorkflowState } from "./workflow-state.js";
28
30
  import type {
29
31
  ManualWorkflowTrigger,
@@ -183,7 +185,21 @@ export type WorkflowWaitForInputResult = {
183
185
 
184
186
  type WorkflowWaitResult = WorkflowWaitUntilResult | WorkflowWaitForInputResult;
185
187
 
186
- type WorkflowHandlerResult = { status: "success" } | WorkflowWaitResult;
188
+ type WorkflowHandlerResult =
189
+ | { status: "success"; output?: Record<string, unknown> }
190
+ | WorkflowWaitResult;
191
+
192
+ /** An object schema describing the value a workflow returns. */
193
+ export type WorkflowOutputSchema = SchemaBuilder<Record<string, unknown>, "object">;
194
+
195
+ /**
196
+ * What a workflow handler returns: the value described by `outputSchema`, or
197
+ * nothing when the workflow declares no output schema.
198
+ */
199
+ export type WorkflowHandlerReturn<TOutputSchema extends WorkflowOutputSchema | undefined> =
200
+ TOutputSchema extends WorkflowOutputSchema
201
+ ? Promise<Infer<TOutputSchema>> | Infer<TOutputSchema>
202
+ : Promise<void> | void;
187
203
 
188
204
  const MAX_WORKFLOW_WAIT_MS = 7 * 24 * 60 * 60 * 1_000;
189
205
  export { FatalError, RetryableError } from "./error.js";
@@ -355,6 +371,7 @@ export type WorkflowConfiguration<
355
371
  TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
356
372
  TConnections extends WorkflowConnectionDeclarations = WorkflowConnectionDeclarations,
357
373
  TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations,
374
+ TOutputSchema extends WorkflowOutputSchema | undefined = undefined,
358
375
  > = {
359
376
  /**
360
377
  * A human-readable name for the workflow, shown in the UI when viewing workflows
@@ -428,10 +445,25 @@ export type WorkflowConfiguration<
428
445
  */
429
446
  verify?: WebhookVerifyHandler;
430
447
 
448
+ /**
449
+ * Optional schema for the object the handler returns, built with
450
+ * `@notionhq/apps/schema-builder`. The handler's return type is inferred
451
+ * from it, and the returned value is validated before the run succeeds.
452
+ *
453
+ * Without `outputSchema`, the workflow returns nothing.
454
+ *
455
+ * @example
456
+ * ```ts
457
+ * outputSchema: j.object({ releaseUrl: j.string() }),
458
+ * handler: async () => ({ releaseUrl: "https://example.com/releases/1" }),
459
+ * ```
460
+ */
461
+ outputSchema?: TOutputSchema;
462
+
431
463
  handler: (
432
464
  event: WorkflowEventForTriggers<TTriggers>,
433
465
  context: WorkflowContext<TConnections, TAccess>,
434
- ) => Promise<void> | void;
466
+ ) => WorkflowHandlerReturn<NoInfer<TOutputSchema>>;
435
467
  };
436
468
 
437
469
  /** Configuration that checks trigger keys against declared connections. */
@@ -439,7 +471,8 @@ export type WorkflowTriggerConfiguration<
439
471
  TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
440
472
  TConnections extends WorkflowConnectionDeclarations,
441
473
  TAccess extends WorkflowAccessDeclarations = WorkflowAccessDeclarations,
442
- > = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess>, "triggers"> & {
474
+ TOutputSchema extends WorkflowOutputSchema | undefined = undefined,
475
+ > = Omit<WorkflowConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>, "triggers"> & {
443
476
  triggers: (context: { events: WorkflowEventCreators<NoInfer<TConnections>> }) => TTriggers;
444
477
  };
445
478
 
@@ -464,6 +497,8 @@ export type Workflow<
464
497
  access?: WorkflowAccessRequirements;
465
498
  deadline?: WorkflowDeadline;
466
499
  retry?: WorkflowRetryPolicy;
500
+ /** JSON Schema for the handler's return value. Absent when the workflow returns nothing. */
501
+ outputJsonSchema?: Record<string, unknown>;
467
502
  };
468
503
  handler: (
469
504
  input: WorkflowEventForTriggers<TTriggers> | WebhookVerifyInvocation,
@@ -504,22 +539,27 @@ export function workflow<
504
539
  ],
505
540
  const TConnections extends WorkflowConnectionDeclarations = Record<never, never>,
506
541
  const TAccess extends WorkflowAccessDeclarations = Record<never, never>,
542
+ const TOutputSchema extends WorkflowOutputSchema | undefined = undefined,
507
543
  >(
508
- configuration: WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess>,
544
+ configuration: WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>,
509
545
  ): Workflow<TTriggers>;
510
546
  export function workflow<
511
547
  const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
512
548
  const TConnections extends WorkflowConnectionDeclarations = Record<never, never>,
513
549
  const TAccess extends WorkflowAccessDeclarations = Record<never, never>,
514
- >(configuration: WorkflowConfiguration<TTriggers, TConnections, TAccess>): Workflow<TTriggers>;
550
+ const TOutputSchema extends WorkflowOutputSchema | undefined = undefined,
551
+ >(
552
+ configuration: WorkflowConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>,
553
+ ): Workflow<TTriggers>;
515
554
  export function workflow<
516
555
  const TTriggers extends readonly [WorkflowTrigger, ...WorkflowTrigger[]],
517
556
  const TConnections extends WorkflowConnectionDeclarations = Record<never, never>,
518
557
  const TAccess extends WorkflowAccessDeclarations = Record<never, never>,
558
+ const TOutputSchema extends WorkflowOutputSchema | undefined = undefined,
519
559
  >(
520
560
  configuration:
521
- | WorkflowConfiguration<TTriggers, TConnections, TAccess>
522
- | WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess>,
561
+ | WorkflowConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>
562
+ | WorkflowTriggerConfiguration<TTriggers, TConnections, TAccess, TOutputSchema>,
523
563
  ): Workflow<TTriggers> {
524
564
  const requirements = normalizeConnectionRequirements(configuration.connections ?? {});
525
565
  const accessRequirements = normalizeWorkflowAccess(configuration.access);
@@ -541,6 +581,10 @@ export function workflow<
541
581
  configuration.deadline === undefined ? undefined : structuredClone(configuration.deadline);
542
582
  const retry =
543
583
  configuration.retry === undefined ? undefined : manifestRetryPolicy(configuration.retry);
584
+ const outputSchema =
585
+ configuration.outputSchema === undefined
586
+ ? undefined
587
+ : compileWorkflowOutputSchema(configuration.outputSchema);
544
588
 
545
589
  const manualTriggers = triggers.filter(
546
590
  (trigger): trigger is ManualWorkflowTrigger => trigger.type === "workflow.manual",
@@ -569,6 +613,7 @@ export function workflow<
569
613
  ...(configuration.access === undefined ? {} : { access: accessRequirements }),
570
614
  ...(deadline === undefined ? {} : { deadline }),
571
615
  ...(retry === undefined ? {} : { retry }),
616
+ ...(outputSchema === undefined ? {} : { outputJsonSchema: outputSchema.jsonSchema }),
572
617
  },
573
618
  async handler(
574
619
  input: WorkflowEventForTriggers<TTriggers> | WebhookVerifyInvocation,
@@ -630,13 +675,26 @@ export function workflow<
630
675
  }
631
676
  validateManualWorkflowInput(manualTrigger, event.input);
632
677
  }
633
- await configuration.handler(event, capabilityContext);
678
+ const handlerOutput: unknown = await configuration.handler(
679
+ event,
680
+ capabilityContext,
681
+ );
682
+ const result: WorkflowHandlerResult =
683
+ outputSchema === undefined
684
+ ? { status: "success" }
685
+ : {
686
+ status: "success",
687
+ output: serializeWorkflowOutput(
688
+ handlerOutput,
689
+ outputSchema.validate,
690
+ ),
691
+ };
634
692
 
635
693
  if (options?.concreteOutput) {
636
- return { status: "success" };
694
+ return result;
637
695
  }
638
696
 
639
- writeOutput({ _tag: "success", value: { status: "success" } });
697
+ writeOutput({ _tag: "success", value: result });
640
698
  } catch (err) {
641
699
  if (err instanceof WorkflowWaitInterrupt) {
642
700
  if (options?.concreteOutput) {
@@ -721,6 +779,37 @@ function manifestTriggers(
721
779
  );
722
780
  }
723
781
 
782
+ /** The platform stores workflow output with its run, so it must stay small. */
783
+ const MAX_WORKFLOW_OUTPUT_BYTES = 256 * 1024;
784
+
785
+ /**
786
+ * Validates the JSON the platform will receive rather than the in-memory value,
787
+ * so values that change during serialization, such as `Date` or `toJSON`
788
+ * objects, are checked in the form callers will see.
789
+ *
790
+ * A mismatch is a bug in the handler, so it fails the run without retrying.
791
+ */
792
+ function serializeWorkflowOutput(
793
+ value: unknown,
794
+ validate: (value: unknown) => void,
795
+ ): Record<string, unknown> {
796
+ try {
797
+ const json = value === undefined ? undefined : JSON.stringify(value);
798
+ const bytes = json === undefined ? 0 : Buffer.byteLength(json, "utf8");
799
+ if (bytes > MAX_WORKFLOW_OUTPUT_BYTES) {
800
+ throw new Error(
801
+ `Invalid workflow output: must be at most ${MAX_WORKFLOW_OUTPUT_BYTES} bytes as JSON, got ${bytes}.`,
802
+ );
803
+ }
804
+ const serialized: unknown = json === undefined ? undefined : JSON.parse(json);
805
+ validate(serialized);
806
+ // SAFETY: validate only accepts values matching the j.object() output schema.
807
+ return serialized as Record<string, unknown>;
808
+ } catch (error) {
809
+ throw new FatalError(error instanceof Error ? error.message : String(error));
810
+ }
811
+ }
812
+
724
813
  /**
725
814
  * Whether an invocation is the platform's synchronous verify dispatch. The
726
815
  * platform sends workflow invocations as a trigger event and verify