zitejs 0.9.144 → 0.9.146

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.
@@ -87,8 +87,11 @@ export type ZiteTrigger = {
87
87
  };
88
88
  /**
89
89
  * What a form trigger's run gets as `input`: one submission. `answers` is
90
- * keyed by question name; `submission` is the whole export, as the Fillout
91
- * API returns it (`questions`, `calculations`, `urlParameters`, …).
90
+ * keyed by question name, `answersById` by question id; `submission` is the
91
+ * whole export, as the Fillout API returns it (`questions`, `calculations`,
92
+ * `urlParameters`, …). Two questions with the same label are named
93
+ * `Email` and `Email (1)` in an order the form doesn't show, so read those by
94
+ * id.
92
95
  */
93
96
  export type ZiteFormTriggerInput = {
94
97
  event: "submitted";
@@ -97,6 +100,7 @@ export type ZiteFormTriggerInput = {
97
100
  submissionId: string;
98
101
  submittedAt: string | null;
99
102
  answers: Record<string, unknown>;
103
+ answersById: Record<string, unknown>;
100
104
  submission: Record<string, unknown> & {
101
105
  submissionId: string;
102
106
  };
@@ -303,7 +307,9 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
303
307
  * its result is saved before anything after it executes, and when a
304
308
  * failed run is resumed, completed steps return their saved results
305
309
  * instead of re-running their side effects. Names must be unique within
306
- * a run, and results must be plain JSON data under 256KB.
310
+ * a run, and results must be plain JSON data under 256KB. In a run
311
+ * fired by a schedule, webhook or trigger, `step.sleep` pauses the run
312
+ * and a failed step is tried again.
307
313
  */
308
314
  step: ZiteStep;
309
315
  context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;
@@ -322,8 +328,32 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
322
328
  * it would matter, and give a step inside a loop the item's id in its name.
323
329
  */
324
330
  export interface ZiteStep {
325
- run<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
331
+ /**
332
+ * In a run fired by a schedule, webhook or trigger, a step that throws is
333
+ * tried again `retries` more times (default 3, at most 10), 30 seconds,
334
+ * 2 minutes, then 10 minutes apart. Elsewhere its error fails the request.
335
+ */
336
+ run<T>(name: string, fn: () => Promise<T> | T, options?: ZiteStepOptions): Promise<T>;
337
+ /**
338
+ * Pause the run for `duration`: `"30s"`, `"15m"`, `"2h"`, `"3d"`, `"1w"`,
339
+ * or milliseconds, at most 30 days. Only a run fired by a schedule, webhook
340
+ * or trigger can wait; an editor test run goes straight past, and a request
341
+ * from the app throws.
342
+ *
343
+ * The run continues in a later call, which runs `execute` again from the
344
+ * top: finished steps return their saved results, and code outside a step
345
+ * runs again, so keep side effects inside steps.
346
+ */
347
+ sleep(name: string, duration: ZiteStepDuration): Promise<void>;
348
+ /** Pause the run until `when`, at most 30 days ahead. See {@link ZiteStep.sleep}. */
349
+ sleepUntil(name: string, when: Date | string): Promise<void>;
350
+ }
351
+ export interface ZiteStepOptions {
352
+ /** How many more times to try the step after it throws: 0 to 10, default 3. */
353
+ retries?: number;
326
354
  }
355
+ /** Milliseconds, or a number with a unit: `ms`, `s`, `m`, `h`, `d` or `w`. */
356
+ export type ZiteStepDuration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
327
357
  /**
328
358
  * Create an endpoint definition, parsing `input` against `inputSchema` before
329
359
  * `execute` runs. Nothing downstream parses it — the worker calls `execute` on
@@ -8,6 +8,8 @@ const requestContext = { user: { id: "u1", email: "a@b.c", roles: [] } };
8
8
  // Direct execute() calls need the step surface the runtime always provides.
9
9
  const stepStub = {
10
10
  run: async (_name, fn) => await fn(),
11
+ sleep: async () => { },
12
+ sleepUntil: async () => { },
11
13
  };
12
14
  (0, vitest_1.afterEach)(() => {
13
15
  vitest_1.vi.unstubAllGlobals();
@@ -226,7 +228,11 @@ const stepStub = {
226
228
  execute: async ({ input, trigger }) => {
227
229
  // @ts-expect-error a form submission has no cursor API
228
230
  trigger?.advance("x");
229
- return { email: input.answers.Email, id: input.submissionId };
231
+ return {
232
+ email: input.answers.Email,
233
+ workEmail: input.answersById["wWorkEmail"],
234
+ id: input.submissionId,
235
+ };
230
236
  },
231
237
  });
232
238
  (0, index_js_1.createEndpoint)({
@@ -1331,7 +1331,7 @@ function generateBackendWrapperTs(envVarNames = []) {
1331
1331
  " execute: (",
1332
1332
  " params: {",
1333
1333
  " input: ZiteEndpointInput<TInput, TTrigger>;",
1334
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. Provided by the platform; never define a local stand-in. */",
1334
+ " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, \"2d\") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */",
1335
1335
  " step: ZiteStep;",
1336
1336
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1337
1337
  // Mirrors the base module: a trigger's run gets `trigger`.
@@ -87,8 +87,11 @@ export type ZiteTrigger = {
87
87
  };
88
88
  /**
89
89
  * What a form trigger's run gets as `input`: one submission. `answers` is
90
- * keyed by question name; `submission` is the whole export, as the Fillout
91
- * API returns it (`questions`, `calculations`, `urlParameters`, …).
90
+ * keyed by question name, `answersById` by question id; `submission` is the
91
+ * whole export, as the Fillout API returns it (`questions`, `calculations`,
92
+ * `urlParameters`, …). Two questions with the same label are named
93
+ * `Email` and `Email (1)` in an order the form doesn't show, so read those by
94
+ * id.
92
95
  */
93
96
  export type ZiteFormTriggerInput = {
94
97
  event: "submitted";
@@ -97,6 +100,7 @@ export type ZiteFormTriggerInput = {
97
100
  submissionId: string;
98
101
  submittedAt: string | null;
99
102
  answers: Record<string, unknown>;
103
+ answersById: Record<string, unknown>;
100
104
  submission: Record<string, unknown> & {
101
105
  submissionId: string;
102
106
  };
@@ -303,7 +307,9 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
303
307
  * its result is saved before anything after it executes, and when a
304
308
  * failed run is resumed, completed steps return their saved results
305
309
  * instead of re-running their side effects. Names must be unique within
306
- * a run, and results must be plain JSON data under 256KB.
310
+ * a run, and results must be plain JSON data under 256KB. In a run
311
+ * fired by a schedule, webhook or trigger, `step.sleep` pauses the run
312
+ * and a failed step is tried again.
307
313
  */
308
314
  step: ZiteStep;
309
315
  context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;
@@ -322,8 +328,32 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
322
328
  * it would matter, and give a step inside a loop the item's id in its name.
323
329
  */
324
330
  export interface ZiteStep {
325
- run<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
331
+ /**
332
+ * In a run fired by a schedule, webhook or trigger, a step that throws is
333
+ * tried again `retries` more times (default 3, at most 10), 30 seconds,
334
+ * 2 minutes, then 10 minutes apart. Elsewhere its error fails the request.
335
+ */
336
+ run<T>(name: string, fn: () => Promise<T> | T, options?: ZiteStepOptions): Promise<T>;
337
+ /**
338
+ * Pause the run for `duration`: `"30s"`, `"15m"`, `"2h"`, `"3d"`, `"1w"`,
339
+ * or milliseconds, at most 30 days. Only a run fired by a schedule, webhook
340
+ * or trigger can wait; an editor test run goes straight past, and a request
341
+ * from the app throws.
342
+ *
343
+ * The run continues in a later call, which runs `execute` again from the
344
+ * top: finished steps return their saved results, and code outside a step
345
+ * runs again, so keep side effects inside steps.
346
+ */
347
+ sleep(name: string, duration: ZiteStepDuration): Promise<void>;
348
+ /** Pause the run until `when`, at most 30 days ahead. See {@link ZiteStep.sleep}. */
349
+ sleepUntil(name: string, when: Date | string): Promise<void>;
350
+ }
351
+ export interface ZiteStepOptions {
352
+ /** How many more times to try the step after it throws: 0 to 10, default 3. */
353
+ retries?: number;
326
354
  }
355
+ /** Milliseconds, or a number with a unit: `ms`, `s`, `m`, `h`, `d` or `w`. */
356
+ export type ZiteStepDuration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
327
357
  /**
328
358
  * Create an endpoint definition, parsing `input` against `inputSchema` before
329
359
  * `execute` runs. Nothing downstream parses it — the worker calls `execute` on
@@ -6,6 +6,8 @@ const requestContext = { user: { id: "u1", email: "a@b.c", roles: [] } };
6
6
  // Direct execute() calls need the step surface the runtime always provides.
7
7
  const stepStub = {
8
8
  run: async (_name, fn) => await fn(),
9
+ sleep: async () => { },
10
+ sleepUntil: async () => { },
9
11
  };
10
12
  afterEach(() => {
11
13
  vi.unstubAllGlobals();
@@ -224,7 +226,11 @@ describe("platform-triggered runs", () => {
224
226
  execute: async ({ input, trigger }) => {
225
227
  // @ts-expect-error a form submission has no cursor API
226
228
  trigger?.advance("x");
227
- return { email: input.answers.Email, id: input.submissionId };
229
+ return {
230
+ email: input.answers.Email,
231
+ workEmail: input.answersById["wWorkEmail"],
232
+ id: input.submissionId,
233
+ };
228
234
  },
229
235
  });
230
236
  createEndpoint({
@@ -1316,7 +1316,7 @@ export function generateBackendWrapperTs(envVarNames = []) {
1316
1316
  " execute: (",
1317
1317
  " params: {",
1318
1318
  " input: ZiteEndpointInput<TInput, TTrigger>;",
1319
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. Provided by the platform; never define a local stand-in. */",
1319
+ " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, \"2d\") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */",
1320
1320
  " step: ZiteStep;",
1321
1321
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1322
1322
  // Mirrors the base module: a trigger's run gets `trigger`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.144",
3
+ "version": "0.9.146",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -97,6 +97,7 @@
97
97
  "test": "vitest run",
98
98
  "test:watch": "vitest",
99
99
  "typecheck": "tsc --noEmit",
100
+ "release": "node ./scripts/release.mjs",
100
101
  "prepublishOnly": "npm run build"
101
102
  },
102
103
  "files": [