zitejs 0.10.0-start.2 → 0.10.0-start.20
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/cjs/auth/index.d.ts +2 -2
- package/dist/cjs/auth/index.js +6 -0
- package/dist/cjs/auth/index.test.js +30 -0
- package/dist/cjs/auth/previewClaim.d.ts +7 -0
- package/dist/cjs/auth/previewClaim.js +16 -0
- package/dist/cjs/backend/index.d.ts +121 -3
- package/dist/cjs/backend/index.test.js +58 -0
- package/dist/cjs/bundle/index.d.ts +8 -0
- package/dist/cjs/bundle/index.js +9 -8
- package/dist/cjs/check/index.d.ts +45 -1
- package/dist/cjs/check/index.js +198 -109
- package/dist/cjs/check/start/problem.d.ts +11 -0
- package/dist/cjs/check/start/problem.js +5 -0
- package/dist/cjs/check/start/routeTree.d.ts +9 -0
- package/dist/cjs/check/start/routeTree.js +111 -0
- package/dist/cjs/check/start/sourceRules.d.ts +8 -0
- package/dist/cjs/check/start/sourceRules.js +1110 -0
- package/dist/cjs/check/start/tsgo.d.ts +2 -0
- package/dist/cjs/check/start/tsgo.js +35 -0
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/client/index.d.ts +24 -0
- package/dist/cjs/dev/index.js +14 -4
- package/dist/cjs/integrations/rules.d.ts +13 -0
- package/dist/cjs/integrations/rules.js +29 -0
- package/dist/cjs/integrations/rules.test.js +1 -0
- package/dist/cjs/internal/appMode.d.ts +3 -0
- package/dist/cjs/internal/appMode.js +15 -0
- package/dist/cjs/runtime/index.d.ts +13 -13
- package/dist/cjs/start/entries.d.ts +10 -4
- package/dist/cjs/start/entries.js +23 -6
- package/dist/cjs/steps/index.d.ts +78 -0
- package/dist/cjs/steps/index.js +507 -0
- package/dist/cjs/steps/index.test.d.ts +1 -0
- package/dist/cjs/steps/index.test.js +635 -0
- package/dist/cjs/sync/index.js +2 -1
- package/dist/cjs/sync/lib.d.ts +10 -3
- package/dist/cjs/sync/lib.js +35 -21
- package/dist/cjs/sync/lib.test.js +106 -36
- package/dist/cjs/types/fields.d.ts +8 -1
- package/dist/cjs/types/fields.js +7 -1
- package/dist/cjs/types/tables.d.ts +16 -0
- package/dist/cjs/upload/index.js +12 -2
- package/dist/cjs/upload/index.test.js +39 -0
- package/dist/cjs/vite/index.js +8 -3
- package/dist/cjs/vite/index.test.js +10 -2
- package/dist/esm/auth/index.d.ts +2 -2
- package/dist/esm/auth/index.js +6 -0
- package/dist/esm/auth/index.test.js +30 -0
- package/dist/esm/auth/previewClaim.d.ts +7 -0
- package/dist/esm/auth/previewClaim.js +12 -0
- package/dist/esm/backend/index.d.ts +121 -3
- package/dist/esm/backend/index.test.js +58 -0
- package/dist/esm/bundle/index.d.ts +8 -0
- package/dist/esm/bundle/index.js +8 -8
- package/dist/esm/check/index.d.ts +45 -1
- package/dist/esm/check/index.js +198 -113
- package/dist/esm/check/start/problem.d.ts +11 -0
- package/dist/esm/check/start/problem.js +1 -0
- package/dist/esm/check/start/routeTree.d.ts +9 -0
- package/dist/esm/check/start/routeTree.js +70 -0
- package/dist/esm/check/start/sourceRules.d.ts +8 -0
- package/dist/esm/check/start/sourceRules.js +1107 -0
- package/dist/esm/check/start/tsgo.d.ts +2 -0
- package/dist/esm/check/start/tsgo.js +29 -0
- package/dist/esm/cli.js +1 -1
- package/dist/esm/client/index.d.ts +24 -0
- package/dist/esm/dev/index.js +16 -6
- package/dist/esm/integrations/rules.d.ts +13 -0
- package/dist/esm/integrations/rules.js +29 -0
- package/dist/esm/integrations/rules.test.js +1 -0
- package/dist/esm/internal/appMode.d.ts +3 -0
- package/dist/esm/internal/appMode.js +10 -0
- package/dist/esm/runtime/index.d.ts +13 -13
- package/dist/esm/start/aiUsage.d.ts +23 -0
- package/dist/esm/start/aiUsage.js +146 -0
- package/dist/esm/start/airtable/arrayFields.d.ts +10 -0
- package/dist/esm/start/airtable/arrayFields.js +30 -0
- package/dist/esm/start/airtable/dispatch.d.ts +54 -0
- package/dist/esm/start/airtable/dispatch.js +483 -0
- package/dist/esm/start/airtable/formulas.d.ts +70 -0
- package/dist/esm/start/airtable/formulas.js +258 -0
- package/dist/esm/start/airtable/index.d.ts +8 -0
- package/dist/esm/start/airtable/index.js +54 -0
- package/dist/esm/start/authHooks.d.ts +7 -0
- package/dist/esm/start/authHooks.js +10 -0
- package/dist/esm/start/authHooksModule.d.ts +1 -0
- package/dist/esm/start/authHooksModule.js +3 -0
- package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
- package/dist/esm/start/clientErrorMessage.test.js +105 -0
- package/dist/esm/start/credentials.d.ts +2 -0
- package/dist/esm/start/credentials.js +2 -0
- package/dist/esm/start/data/baseRunner.d.ts +92 -0
- package/dist/esm/start/data/baseRunner.js +83 -0
- package/dist/esm/start/data/dispatch.d.ts +16 -0
- package/dist/esm/start/data/dispatch.js +198 -0
- package/dist/esm/start/data/index.d.ts +15 -0
- package/dist/esm/start/data/index.js +58 -0
- package/dist/esm/start/data/sqlNameMappings.d.ts +58 -0
- package/dist/esm/start/data/sqlNameMappings.js +92 -0
- package/dist/esm/start/data/transformations.d.ts +97 -0
- package/dist/esm/start/data/transformations.js +262 -0
- package/dist/esm/start/data/types.d.ts +91 -0
- package/dist/esm/start/data/types.js +14 -0
- package/dist/esm/start/describe.d.ts +35 -5
- package/dist/esm/start/describe.js +74 -22
- package/dist/esm/start/entries.d.ts +10 -4
- package/dist/esm/start/entries.js +21 -5
- package/dist/esm/start/errors.d.ts +63 -0
- package/dist/esm/start/errors.js +146 -0
- package/dist/esm/start/errors.test.d.ts +1 -0
- package/dist/esm/start/errors.test.js +23 -0
- package/dist/esm/start/factories.test-d.d.ts +1 -0
- package/dist/esm/start/factories.test-d.js +20 -0
- package/dist/esm/start/index.d.ts +32 -27
- package/dist/esm/start/index.js +77 -47
- package/dist/esm/start/instance.d.ts +4 -4
- package/dist/esm/start/instance.js +54 -11
- package/dist/esm/start/outbound.d.ts +11 -0
- package/dist/esm/start/outbound.js +398 -0
- package/dist/esm/start/previewClaim.d.ts +7 -0
- package/dist/esm/start/previewClaim.js +23 -0
- package/dist/esm/start/problems.js +1 -1
- package/dist/esm/start/quiet.d.ts +2 -0
- package/dist/esm/start/quiet.js +27 -0
- package/dist/esm/start/redactSecrets.d.ts +15 -0
- package/dist/esm/start/redactSecrets.js +154 -0
- package/dist/esm/start/redactSecrets.test.d.ts +1 -0
- package/dist/esm/start/redactSecrets.test.js +151 -0
- package/dist/esm/start/registration.d.ts +13 -0
- package/dist/esm/start/registration.js +21 -0
- package/dist/esm/start/registrationHash.d.ts +22 -0
- package/dist/esm/start/registrationHash.js +470 -0
- package/dist/esm/start/router.d.ts +18 -4
- package/dist/esm/start/router.js +134 -11
- package/dist/esm/start/runLog.d.ts +7 -4
- package/dist/esm/start/runLog.js +64 -6
- package/dist/esm/start/scope.d.ts +2 -2
- package/dist/esm/start/server.d.ts +40 -36
- package/dist/esm/start/server.js +320 -48
- package/dist/esm/start/steps.d.ts +28 -0
- package/dist/esm/start/steps.js +97 -0
- package/dist/esm/start/types.d.ts +178 -5
- package/dist/esm/start/version.d.ts +1 -0
- package/dist/esm/start/version.js +2 -0
- package/dist/esm/start/vite.js +88 -11
- package/dist/esm/start/worker.d.ts +6 -0
- package/dist/esm/start/worker.js +12 -0
- package/dist/esm/start/workflow.d.ts +42 -12
- package/dist/esm/start/workflow.js +3 -3
- package/dist/esm/start/workflow.test-d.js +41 -8
- package/dist/esm/start/workflowModules.js +1 -1
- package/dist/esm/start/workflowRun.d.ts +21 -8
- package/dist/esm/start/workflowRun.js +29 -8
- package/dist/esm/steps/index.d.ts +78 -0
- package/dist/esm/steps/index.js +502 -0
- package/dist/esm/steps/index.test.d.ts +1 -0
- package/dist/esm/steps/index.test.js +633 -0
- package/dist/esm/sync/index.js +2 -1
- package/dist/esm/sync/lib.d.ts +10 -3
- package/dist/esm/sync/lib.js +35 -21
- package/dist/esm/sync/lib.test.js +106 -36
- package/dist/esm/types/fields.d.ts +8 -1
- package/dist/esm/types/fields.js +6 -0
- package/dist/esm/types/tables.d.ts +16 -0
- package/dist/esm/upload/index.js +12 -2
- package/dist/esm/upload/index.test.js +39 -0
- package/dist/esm/vite/index.js +8 -3
- package/dist/esm/vite/index.test.js +10 -2
- package/package.json +37 -16
- package/dist/cjs/start/problems.d.ts +0 -19
- package/dist/cjs/start/problems.js +0 -11
|
@@ -152,3 +152,33 @@ describe('loginWithRedirect', () => {
|
|
|
152
152
|
expect(params.get('usageToken')).toBeNull();
|
|
153
153
|
});
|
|
154
154
|
});
|
|
155
|
+
// AUTH-03: what the platform's auth routes receive from the client, on the app's own origin.
|
|
156
|
+
describe("the client's calls", () => {
|
|
157
|
+
const calls = () => {
|
|
158
|
+
const sent = [];
|
|
159
|
+
vi.stubGlobal('fetch', vi.fn(async (input, init) => {
|
|
160
|
+
const request = new Request(new URL(String(input instanceof Request ? input.url : input), 'https://app.zite.so'), init);
|
|
161
|
+
sent.push({
|
|
162
|
+
path: new URL(request.url).pathname,
|
|
163
|
+
method: request.method,
|
|
164
|
+
body: request.method === 'POST' ? await request.json().catch(() => null) : null,
|
|
165
|
+
});
|
|
166
|
+
return Response.json({});
|
|
167
|
+
}));
|
|
168
|
+
return sent;
|
|
169
|
+
};
|
|
170
|
+
it('sign in by link, sign out and edit the profile on /api/auth', async () => {
|
|
171
|
+
const sent = calls();
|
|
172
|
+
// The client takes its fetch when the module loads.
|
|
173
|
+
vi.resetModules();
|
|
174
|
+
const { signIn, signOut, updateProfile } = await import('./index.js');
|
|
175
|
+
await signIn.magicLink({ email: 'ada@x.co' });
|
|
176
|
+
await signOut();
|
|
177
|
+
await updateProfile({ firstName: 'Ada' });
|
|
178
|
+
expect(sent).toEqual([
|
|
179
|
+
{ path: '/api/auth/sign-in/magic-link', method: 'POST', body: expect.objectContaining({ email: 'ada@x.co' }) },
|
|
180
|
+
{ path: '/api/auth/sign-out', method: 'POST', body: expect.anything() },
|
|
181
|
+
{ path: '/api/auth/update-user', method: 'POST', body: { firstName: 'Ada' } },
|
|
182
|
+
]);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
|
|
2
|
+
/**
|
|
3
|
+
* An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
|
|
4
|
+
* cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
|
|
5
|
+
* `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
|
|
6
|
+
*/
|
|
7
|
+
export declare const browserPreviewClaim: () => string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// The host's name for it (apps/zite-host/src/previewClaim.ts).
|
|
2
|
+
export const PREVIEW_CLAIM_PARAM = 'zite_preview';
|
|
3
|
+
let captured;
|
|
4
|
+
/**
|
|
5
|
+
* An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
|
|
6
|
+
* cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
|
|
7
|
+
* `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
|
|
8
|
+
*/
|
|
9
|
+
export const browserPreviewClaim = () => {
|
|
10
|
+
captured ??= new URL(window.location.href).searchParams.get(PREVIEW_CLAIM_PARAM);
|
|
11
|
+
return captured ?? undefined;
|
|
12
|
+
};
|
|
@@ -23,6 +23,8 @@ export type ZiteTrigger = {
|
|
|
23
23
|
paused?: boolean;
|
|
24
24
|
every?: never;
|
|
25
25
|
events?: never;
|
|
26
|
+
table?: never;
|
|
27
|
+
form?: never;
|
|
26
28
|
} | {
|
|
27
29
|
/**
|
|
28
30
|
* The connection's name in `zite.config.json`, for a provider whose
|
|
@@ -37,6 +39,8 @@ export type ZiteTrigger = {
|
|
|
37
39
|
label?: string;
|
|
38
40
|
paused?: boolean;
|
|
39
41
|
every?: never;
|
|
42
|
+
table?: never;
|
|
43
|
+
form?: never;
|
|
40
44
|
} | {
|
|
41
45
|
/** `<n>m` (1–59) or `<n>h` (1–23). What makes the trigger a poll. */
|
|
42
46
|
every: string;
|
|
@@ -46,6 +50,78 @@ export type ZiteTrigger = {
|
|
|
46
50
|
label?: string;
|
|
47
51
|
paused?: boolean;
|
|
48
52
|
events?: never;
|
|
53
|
+
table?: never;
|
|
54
|
+
form?: never;
|
|
55
|
+
} | {
|
|
56
|
+
/**
|
|
57
|
+
* A table in the project's own database, as `zite.<table>` names it.
|
|
58
|
+
* Every write to it reaches the trigger, from apps, forms, imports, the
|
|
59
|
+
* database view and other automations; nothing is registered.
|
|
60
|
+
*/
|
|
61
|
+
table: string;
|
|
62
|
+
on: ZiteDatabaseTriggerEvent[];
|
|
63
|
+
/** Narrows `"updated"` to updates that changed one of these fields. */
|
|
64
|
+
fields?: string[];
|
|
65
|
+
/** The sentence the editor shows, e.g. "When an order ships". */
|
|
66
|
+
label?: string;
|
|
67
|
+
paused?: boolean;
|
|
68
|
+
integration?: never;
|
|
69
|
+
every?: never;
|
|
70
|
+
events?: never;
|
|
71
|
+
form?: never;
|
|
72
|
+
} | {
|
|
73
|
+
/**
|
|
74
|
+
* One of the project's own Fillout forms, by its name as the project
|
|
75
|
+
* lists it, or its id. Each finished live submission fires the
|
|
76
|
+
* endpoint; nothing is registered.
|
|
77
|
+
*/
|
|
78
|
+
form: string;
|
|
79
|
+
on: "submitted"[];
|
|
80
|
+
/** The sentence the editor shows, e.g. "When someone fills in the intake form". */
|
|
81
|
+
label?: string;
|
|
82
|
+
paused?: boolean;
|
|
83
|
+
integration?: never;
|
|
84
|
+
every?: never;
|
|
85
|
+
events?: never;
|
|
86
|
+
table?: never;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* What a form trigger's run gets as `input`: one submission. `answers` is
|
|
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.
|
|
95
|
+
*/
|
|
96
|
+
export type ZiteFormTriggerInput = {
|
|
97
|
+
event: "submitted";
|
|
98
|
+
form: string;
|
|
99
|
+
formId: string;
|
|
100
|
+
submissionId: string;
|
|
101
|
+
submittedAt: string | null;
|
|
102
|
+
answers: Record<string, unknown>;
|
|
103
|
+
answersById: Record<string, unknown>;
|
|
104
|
+
submission: Record<string, unknown> & {
|
|
105
|
+
submissionId: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export type ZiteDatabaseTriggerEvent = "created" | "updated" | "deleted";
|
|
109
|
+
/**
|
|
110
|
+
* What a database trigger's run gets as `input`: one changed record. Field
|
|
111
|
+
* keys are the SDK's, as `zite.<table>.findOne` returns them; cast `record`
|
|
112
|
+
* and `previous` to the table's generated `<Table>RecordType` from
|
|
113
|
+
* `zitejs/db` to type their fields.
|
|
114
|
+
*/
|
|
115
|
+
export type ZiteDatabaseTriggerInput<TRecord extends Record<string, unknown> = Record<string, unknown>> = {
|
|
116
|
+
event: ZiteDatabaseTriggerEvent;
|
|
117
|
+
table: string;
|
|
118
|
+
recordId: string;
|
|
119
|
+
/** Null on `"deleted"`, which leaves only `recordId`, and if it was deleted before the run read it. */
|
|
120
|
+
record: TRecord | null;
|
|
121
|
+
/** The record before an `"updated"`; null otherwise, and on a very large bulk write. */
|
|
122
|
+
previous: TRecord | null;
|
|
123
|
+
/** What an `"updated"` changed; on a very large bulk write, what the write changed across its records. */
|
|
124
|
+
changedFields: string[];
|
|
49
125
|
};
|
|
50
126
|
/**
|
|
51
127
|
* What a provider trigger's `subscribe` export receives. Write it as
|
|
@@ -115,10 +191,20 @@ export type ZiteTriggerDeliveryRun = ZiteTriggerRun & ZiteTriggerDeliveryInfo;
|
|
|
115
191
|
export type ZiteTriggerContext<TTrigger> = TTrigger extends {
|
|
116
192
|
every: string;
|
|
117
193
|
} ? ZiteTriggerRun : TTrigger extends {
|
|
194
|
+
table: string;
|
|
195
|
+
} | {
|
|
196
|
+
form: string;
|
|
197
|
+
} ? ZiteTriggerDeliveryInfo : TTrigger extends {
|
|
118
198
|
events: string[];
|
|
119
199
|
} ? ZiteTriggerDeliveryInfo : TTrigger extends {
|
|
120
200
|
integration: string;
|
|
121
201
|
} ? ZiteTriggerDeliveryRun : never;
|
|
202
|
+
/** A database or form trigger's runs get the change or submission as `input`. */
|
|
203
|
+
export type ZiteEndpointInput<TInput, TTrigger> = TTrigger extends {
|
|
204
|
+
table: string;
|
|
205
|
+
} ? ZiteDatabaseTriggerInput : TTrigger extends {
|
|
206
|
+
form: string;
|
|
207
|
+
} ? ZiteFormTriggerInput : TInput;
|
|
122
208
|
export interface ZiteRequestContext {
|
|
123
209
|
user: {
|
|
124
210
|
id: string;
|
|
@@ -215,13 +301,15 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
215
301
|
*/
|
|
216
302
|
validatesInput?: boolean;
|
|
217
303
|
execute: (params: {
|
|
218
|
-
input: TInput
|
|
304
|
+
input: ZiteEndpointInput<TInput, TTrigger>;
|
|
219
305
|
/**
|
|
220
306
|
* Durable steps. `step.run(name, fn)` runs `fn` once per logical run:
|
|
221
307
|
* its result is saved before anything after it executes, and when a
|
|
222
308
|
* failed run is resumed, completed steps return their saved results
|
|
223
309
|
* instead of re-running their side effects. Names must be unique within
|
|
224
|
-
* 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.
|
|
225
313
|
*/
|
|
226
314
|
step: ZiteStep;
|
|
227
315
|
context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;
|
|
@@ -240,8 +328,38 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
240
328
|
* it would matter, and give a step inside a loop the item's id in its name.
|
|
241
329
|
*/
|
|
242
330
|
export interface ZiteStep {
|
|
243
|
-
|
|
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
|
+
* Once its tries are spent the code gets its error, and later calls of the
|
|
336
|
+
* run throw it there again, rebuilt as an `Error` with its `name`,
|
|
337
|
+
* `message` and plain fields such as `code` or `status`, so branch on
|
|
338
|
+
* those rather than on `instanceof`. A result over 256KB, or one JSON
|
|
339
|
+
* can't hold such as a cycle, fails the step without a retry.
|
|
340
|
+
*/
|
|
341
|
+
run<T>(name: string, fn: () => Promise<T> | T, options?: ZiteStepOptions): Promise<T>;
|
|
342
|
+
/**
|
|
343
|
+
* Pause the run for `duration`: `"30s"`, `"15m"`, `"2h"`, `"3d"`, `"1w"`,
|
|
344
|
+
* or milliseconds, at most 30 days. Only a run fired by a schedule, webhook
|
|
345
|
+
* or trigger can wait; an editor test run goes straight past, and a request
|
|
346
|
+
* from the app throws.
|
|
347
|
+
*
|
|
348
|
+
* The run continues in a later call, which runs `execute` again from the
|
|
349
|
+
* top: finished steps return their saved results, and code outside a step
|
|
350
|
+
* runs again, so keep side effects inside steps. Call it between steps, not
|
|
351
|
+
* inside a step's code: a step can't pause halfway, so a sleep there throws.
|
|
352
|
+
*/
|
|
353
|
+
sleep(name: string, duration: ZiteStepDuration): Promise<void>;
|
|
354
|
+
/** Pause the run until `when`, at most 30 days ahead. See {@link ZiteStep.sleep}. */
|
|
355
|
+
sleepUntil(name: string, when: Date | string): Promise<void>;
|
|
356
|
+
}
|
|
357
|
+
export interface ZiteStepOptions {
|
|
358
|
+
/** How many more times to try the step after it throws: 0 to 10, default 3. */
|
|
359
|
+
retries?: number;
|
|
244
360
|
}
|
|
361
|
+
/** Milliseconds, or a number with a unit: `ms`, `s`, `m`, `h`, `d` or `w`. */
|
|
362
|
+
export type ZiteStepDuration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
|
|
245
363
|
/**
|
|
246
364
|
* Create an endpoint definition, parsing `input` against `inputSchema` before
|
|
247
365
|
* `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();
|
|
@@ -205,6 +207,62 @@ describe("platform-triggered runs", () => {
|
|
|
205
207
|
return params.trigger;
|
|
206
208
|
},
|
|
207
209
|
});
|
|
210
|
+
createEndpoint({
|
|
211
|
+
trigger: { table: "orders", on: ["updated"], fields: ["status"] },
|
|
212
|
+
execute: async ({ input, trigger }) => {
|
|
213
|
+
// @ts-expect-error a database change has no cursor API
|
|
214
|
+
trigger?.advance("x");
|
|
215
|
+
const status = input.record?.status;
|
|
216
|
+
return { status, changed: input.changedFields, at: input.event };
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
createEndpoint({
|
|
220
|
+
// @ts-expect-error a database trigger names its table, not a connection
|
|
221
|
+
trigger: { table: "orders", on: ["created"], integration: "x" },
|
|
222
|
+
execute: async () => 1,
|
|
223
|
+
});
|
|
224
|
+
createEndpoint({
|
|
225
|
+
trigger: { form: "Intake form", on: ["submitted"] },
|
|
226
|
+
execute: async ({ input, trigger }) => {
|
|
227
|
+
// @ts-expect-error a form submission has no cursor API
|
|
228
|
+
trigger?.advance("x");
|
|
229
|
+
return {
|
|
230
|
+
email: input.answers.Email,
|
|
231
|
+
workEmail: input.answersById["wWorkEmail"],
|
|
232
|
+
id: input.submissionId,
|
|
233
|
+
};
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
createEndpoint({
|
|
237
|
+
// @ts-expect-error a form trigger watches submissions only
|
|
238
|
+
trigger: { form: "Intake form", on: ["updated"] },
|
|
239
|
+
execute: async () => 1,
|
|
240
|
+
});
|
|
241
|
+
createEndpoint({
|
|
242
|
+
// @ts-expect-error only created, updated and deleted
|
|
243
|
+
trigger: { table: "orders", on: ["archived"] },
|
|
244
|
+
execute: async () => 1,
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
it("hands a database trigger its change without parsing it against the input schema", async () => {
|
|
248
|
+
const endpoint = createEndpoint({
|
|
249
|
+
inputSchema: z.object({ orderId: z.string() }),
|
|
250
|
+
trigger: { table: "orders", on: ["created"] },
|
|
251
|
+
execute: async ({ input }) => input.recordId,
|
|
252
|
+
});
|
|
253
|
+
await expect(endpoint.execute({
|
|
254
|
+
step: stepStub,
|
|
255
|
+
input: {
|
|
256
|
+
event: "created",
|
|
257
|
+
table: "orders",
|
|
258
|
+
recordId: "rec_1",
|
|
259
|
+
record: { id: "rec_1" },
|
|
260
|
+
previous: null,
|
|
261
|
+
changedFields: [],
|
|
262
|
+
},
|
|
263
|
+
context: { user: null },
|
|
264
|
+
trigger: { headers: {}, deliveryId: "db:e1:rec_1" },
|
|
265
|
+
})).resolves.toBe("rec_1");
|
|
208
266
|
});
|
|
209
267
|
it("types a trigger's registration exports and checks what subscribe returns", async () => {
|
|
210
268
|
const subscribe = (async (input) => ({
|
|
@@ -20,10 +20,18 @@
|
|
|
20
20
|
* "@babel/parser": "^7.26.0"
|
|
21
21
|
*/
|
|
22
22
|
import * as esbuild from 'esbuild';
|
|
23
|
+
import { type SourceRoot } from '../sourceRoots.js';
|
|
23
24
|
export declare const UNSUPPORTED_IN_WORKERD: Set<string>;
|
|
24
25
|
export declare const BASE_BUILD_OPTIONS: esbuild.BuildOptions;
|
|
25
26
|
export declare function createAliasPlugin(opts: {
|
|
26
27
|
baseDir?: string;
|
|
27
28
|
sdkPath?: string;
|
|
28
29
|
}): esbuild.Plugin;
|
|
30
|
+
export interface EndpointBundleResult {
|
|
31
|
+
bundledEndpoints: Record<string, string>;
|
|
32
|
+
endpointErrors?: Record<string, string>;
|
|
33
|
+
bundledAuthHooks?: string;
|
|
34
|
+
authHooksError?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function bundleEndpoints(baseDir: string, root: SourceRoot, endpointNames: string[], logLevel: esbuild.LogLevel): Promise<EndpointBundleResult>;
|
|
29
37
|
export declare function runBundle(): Promise<void>;
|
package/dist/esm/bundle/index.js
CHANGED
|
@@ -366,7 +366,7 @@ import endpoint from '${entryImport}';
|
|
|
366
366
|
globalThis.__endpoint = endpoint;
|
|
367
367
|
`;
|
|
368
368
|
}
|
|
369
|
-
async function
|
|
369
|
+
export async function bundleEndpoints(baseDir, root, endpointNames, logLevel) {
|
|
370
370
|
const bundledEndpoints = {};
|
|
371
371
|
const endpointErrors = {};
|
|
372
372
|
const aliasPlugin = createAliasPlugin({ baseDir });
|
|
@@ -403,7 +403,7 @@ async function bundleEndpointsImpl(baseDir, root, endpointNames) {
|
|
|
403
403
|
resolveDir: `${baseDir}/src`,
|
|
404
404
|
loader: 'ts',
|
|
405
405
|
},
|
|
406
|
-
logLevel
|
|
406
|
+
logLevel,
|
|
407
407
|
plugins: [aliasPlugin],
|
|
408
408
|
});
|
|
409
409
|
if (result.warnings && result.warnings.length > 0) {
|
|
@@ -473,7 +473,7 @@ globalThis.__endpoint = endpoint;
|
|
|
473
473
|
resolveDir: `${baseDir}/src`,
|
|
474
474
|
loader: 'ts',
|
|
475
475
|
},
|
|
476
|
-
logLevel
|
|
476
|
+
logLevel,
|
|
477
477
|
plugins: [aliasPlugin],
|
|
478
478
|
});
|
|
479
479
|
if (result.outputFiles && result.outputFiles.length > 0) {
|
|
@@ -500,14 +500,12 @@ globalThis.__endpoint = endpoint;
|
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
|
-
|
|
503
|
+
return {
|
|
504
504
|
bundledEndpoints,
|
|
505
505
|
endpointErrors: Object.keys(endpointErrors).length > 0 ? endpointErrors : undefined,
|
|
506
506
|
bundledAuthHooks,
|
|
507
507
|
authHooksError,
|
|
508
|
-
}
|
|
509
|
-
fs.writeFileSync('/tmp/zitejs-bundle-result.json', output);
|
|
510
|
-
console.log(output);
|
|
508
|
+
};
|
|
511
509
|
}
|
|
512
510
|
async function bundleOneOffScriptImpl(scriptPath, sdkPath) {
|
|
513
511
|
const rawScript = fs.readFileSync(scriptPath, 'utf-8');
|
|
@@ -625,5 +623,7 @@ export async function runBundle() {
|
|
|
625
623
|
endpointNames = listEndpointNames(root, baseDir);
|
|
626
624
|
}
|
|
627
625
|
// Even with no endpoints, zite.auth.ts may still need bundling.
|
|
628
|
-
|
|
626
|
+
const output = JSON.stringify(await bundleEndpoints(baseDir, root, endpointNames, 'warning'));
|
|
627
|
+
fs.writeFileSync('/tmp/zitejs-bundle-result.json', output);
|
|
628
|
+
console.log(output);
|
|
629
629
|
}
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
import { type Problem } from './start/problem.js';
|
|
2
|
+
/**
|
|
3
|
+
* A step's result. `unchecked` is why it couldn't answer at all (killed, out of
|
|
4
|
+
* memory, a tool missing): nothing for the app to fix, so it carries no output.
|
|
5
|
+
*/
|
|
6
|
+
type StepResult = {
|
|
7
|
+
ok: boolean;
|
|
8
|
+
output?: string;
|
|
9
|
+
unchecked?: string;
|
|
10
|
+
};
|
|
11
|
+
type Step = {
|
|
12
|
+
name: string;
|
|
13
|
+
} & StepResult;
|
|
14
|
+
/** One app's check, as `--json` reports it. */
|
|
15
|
+
export type AppCheck = {
|
|
16
|
+
path: string;
|
|
17
|
+
runtime: 'classic' | 'start';
|
|
18
|
+
/** False when something in it needs fixing. */
|
|
19
|
+
ok: boolean;
|
|
20
|
+
/** Set when a step couldn't run to an answer, so the app wasn't fully checked. */
|
|
21
|
+
unchecked?: true;
|
|
22
|
+
steps: Step[];
|
|
23
|
+
problems: Problem[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* While `--json` checks, stdout carries only the report: app code that logs as
|
|
27
|
+
* it's described in-process goes to stderr instead.
|
|
28
|
+
*/
|
|
29
|
+
export declare const withStdoutOnStderr: <T>(run: () => Promise<T>) => Promise<T>;
|
|
30
|
+
/** Prints as it goes, or with `--json` stays quiet and reports everything at the end. */
|
|
31
|
+
export declare class Reporter {
|
|
32
|
+
private readonly json;
|
|
33
|
+
readonly apps: AppCheck[];
|
|
34
|
+
constructor(json: boolean);
|
|
35
|
+
app(path: string, runtime: AppCheck['runtime'], heading: boolean): AppCheck;
|
|
36
|
+
step(app: AppCheck, name: string, result: StepResult): boolean;
|
|
37
|
+
problems(app: AppCheck, problems: Problem[]): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Runs a tool to its answer, or says why it gave none: a kill (a signal, or an
|
|
41
|
+
* exit of 128 and up with nothing printed) is a sandbox limit, not the app's.
|
|
42
|
+
*/
|
|
43
|
+
export declare function runTool(file: string, args: string[], cwd: string): StepResult;
|
|
44
|
+
export declare function runCheck(args?: string[]): Promise<void>;
|
|
45
|
+
export {};
|