zitejs 0.9.127 → 0.9.128
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/backend/index.d.ts +22 -0
- package/dist/cjs/backend/index.test.js +26 -0
- package/dist/cjs/bundle/index.js +0 -4
- package/dist/cjs/sync/lib.js +8 -3
- package/dist/cjs/sync/lib.test.js +8 -0
- package/dist/esm/backend/index.d.ts +22 -0
- package/dist/esm/backend/index.test.js +26 -0
- package/dist/esm/bundle/index.js +0 -4
- package/dist/esm/sync/lib.js +8 -3
- package/dist/esm/sync/lib.test.js +8 -0
- package/package.json +1 -1
|
@@ -22,6 +22,21 @@ export type ZiteTrigger = {
|
|
|
22
22
|
label?: string;
|
|
23
23
|
paused?: boolean;
|
|
24
24
|
every?: never;
|
|
25
|
+
events?: never;
|
|
26
|
+
} | {
|
|
27
|
+
/**
|
|
28
|
+
* The connection's name in `zite.config.json`, for a provider whose
|
|
29
|
+
* webhooks come through Zite's own app (Slack, HubSpot, Notion,
|
|
30
|
+
* Intercom, QuickBooks). Nothing is registered: the platform routes
|
|
31
|
+
* that account's events of these types to the endpoint.
|
|
32
|
+
*/
|
|
33
|
+
integration: string;
|
|
34
|
+
/** Event names as the platform lists them for the provider, e.g. `message.channels`, `contact.creation`. */
|
|
35
|
+
events: string[];
|
|
36
|
+
/** The sentence the editor shows for what fires this endpoint, e.g. "When a message is posted in Slack". */
|
|
37
|
+
label?: string;
|
|
38
|
+
paused?: boolean;
|
|
39
|
+
every?: never;
|
|
25
40
|
} | {
|
|
26
41
|
/** `<n>m` (1–59) or `<n>h` (1–23). What makes the trigger a poll. */
|
|
27
42
|
every: string;
|
|
@@ -30,6 +45,7 @@ export type ZiteTrigger = {
|
|
|
30
45
|
/** The sentence the editor shows for this poll, e.g. "Every 10 minutes, new Stripe charges". */
|
|
31
46
|
label?: string;
|
|
32
47
|
paused?: boolean;
|
|
48
|
+
events?: never;
|
|
33
49
|
};
|
|
34
50
|
/**
|
|
35
51
|
* What a provider trigger's `subscribe` export receives. Write it as
|
|
@@ -97,6 +113,8 @@ export type ZiteTriggerDelivery = {
|
|
|
97
113
|
/** Ids earlier deliveries returned as `handled`, newest last. Skip these. */
|
|
98
114
|
seen: string[];
|
|
99
115
|
};
|
|
116
|
+
/** What an app event trigger's run carries as `input.__webhook`: one event, no cursor. */
|
|
117
|
+
export type ZiteAppEventDelivery = Omit<ZiteTriggerDelivery, "cursor" | "seen">;
|
|
100
118
|
/**
|
|
101
119
|
* What a poll-triggered run, or a provider trigger's delivery, returns for
|
|
102
120
|
* the platform to keep: its new `cursor`, and the id of every item it acted
|
|
@@ -203,6 +221,10 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
203
221
|
every: string;
|
|
204
222
|
} ? TInput & {
|
|
205
223
|
__poll?: ZitePollInput;
|
|
224
|
+
} : TTrigger extends {
|
|
225
|
+
events: string[];
|
|
226
|
+
} ? TInput & {
|
|
227
|
+
__webhook?: ZiteAppEventDelivery;
|
|
206
228
|
} : TTrigger extends {
|
|
207
229
|
integration: string;
|
|
208
230
|
} ? TInput & {
|
|
@@ -201,6 +201,32 @@ const requestContext = { user: { id: "u1", email: "a@b.c" } };
|
|
|
201
201
|
context: { user: null },
|
|
202
202
|
})).resolves.toEqual({ cursor: "sync1+1", handled: ["e2"] });
|
|
203
203
|
});
|
|
204
|
+
(0, vitest_1.it)("types an app event trigger's run as one event, with no cursor to keep", async () => {
|
|
205
|
+
const endpoint = (0, index_js_1.createEndpoint)({
|
|
206
|
+
inputSchema: zod_1.z.object({ event: zod_1.z.object({ text: zod_1.z.string() }) }),
|
|
207
|
+
trigger: { integration: "team-slack", events: ["message.channels"] },
|
|
208
|
+
execute: async ({ input }) => {
|
|
209
|
+
// @ts-expect-error an app event delivery has no cursor
|
|
210
|
+
void input.__webhook?.cursor;
|
|
211
|
+
return { id: input.__webhook?.deliveryId ?? null };
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
await (0, vitest_1.expect)(endpoint.execute({
|
|
215
|
+
input: {
|
|
216
|
+
event: { text: "hi" },
|
|
217
|
+
__webhook: { headers: {}, deliveryId: "slack:Ev1" },
|
|
218
|
+
},
|
|
219
|
+
context: { user: null },
|
|
220
|
+
})).resolves.toEqual({ id: "slack:Ev1" });
|
|
221
|
+
});
|
|
222
|
+
(0, vitest_1.it)("refuses events on a trigger that also polls", () => {
|
|
223
|
+
(0, index_js_1.createEndpoint)({
|
|
224
|
+
inputSchema: zod_1.z.object({}),
|
|
225
|
+
// @ts-expect-error a poll can't also take events
|
|
226
|
+
trigger: { every: "5m", events: ["message.channels"] },
|
|
227
|
+
execute: async () => ({}),
|
|
228
|
+
});
|
|
229
|
+
});
|
|
204
230
|
(0, vitest_1.it)("does not validate a webhook fire", async () => {
|
|
205
231
|
const endpoint = (0, index_js_1.createEndpoint)({
|
|
206
232
|
inputSchema: zod_1.z.object({ token: zod_1.z.string().min(10) }),
|
package/dist/cjs/bundle/index.js
CHANGED
|
@@ -592,10 +592,6 @@ ${bodySection}
|
|
|
592
592
|
},
|
|
593
593
|
minify: false,
|
|
594
594
|
logLevel: 'silent',
|
|
595
|
-
// A script that imports an endpoint file's named exports (a trigger's
|
|
596
|
-
// subscribe/unsubscribe) must not carry the endpoint along with them:
|
|
597
|
-
// unused, its `createEndpoint(...)` and everything `execute` imports go.
|
|
598
|
-
pure: ['createEndpoint'],
|
|
599
595
|
plugins: [plugin],
|
|
600
596
|
});
|
|
601
597
|
if (result.errors.length > 0) {
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -1232,10 +1232,13 @@ function generateBackendWrapperTs(envVarNames = []) {
|
|
|
1232
1232
|
"// Auto-generated type-narrowing wrapper. Do not edit manually.",
|
|
1233
1233
|
"// Re-exports createEndpoint with context.user typed to the app User.",
|
|
1234
1234
|
"",
|
|
1235
|
-
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStreamInterface, ZiteTrigger, ZiteWebhook } from 'zitejs/backend/base';",
|
|
1235
|
+
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStreamInterface, ZiteTrigger, ZiteTriggerDelivery, ZiteAppEventDelivery, ZitePollInput, ZiteWebhook } from 'zitejs/backend/base';",
|
|
1236
1236
|
"import type { User } from 'zitejs/auth';",
|
|
1237
1237
|
"",
|
|
1238
1238
|
"export type { ZiteErrorCode, ZiteSchedule, ZiteScheduledContext, ZiteStreamInterface, ZiteTrigger, ZiteWebhook };",
|
|
1239
|
+
// A trigger's registration exports are typed against these, and they
|
|
1240
|
+
// only reach app code through this file.
|
|
1241
|
+
"export type { ZiteAppEventDelivery, ZitePollInput, ZitePollResult, ZiteTriggerDelivery, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, ZiteTriggerSubscribeResult, ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput } from 'zitejs/backend/base';",
|
|
1239
1242
|
// The pre-monorepo SDK put this in scope for every endpoint, so migrated
|
|
1240
1243
|
// code can name it. `createEndpoint` infers the same thing without it.
|
|
1241
1244
|
"export type InferSchemaType<T> = T extends { _output: infer U } ? U : T;",
|
|
@@ -1322,11 +1325,13 @@ function generateBackendWrapperTs(envVarNames = []) {
|
|
|
1322
1325
|
" schedule?: TSchedule;",
|
|
1323
1326
|
" /** When set, an inbound webhook can also trigger this endpoint. Like `schedule`, it widens `context` — a webhook fire has no session. */",
|
|
1324
1327
|
" webhook?: TWebhook;",
|
|
1325
|
-
" /** When set, a
|
|
1328
|
+
" /** When set, a connection's events (registered by this file's own `subscribe` export) or a poll (`every`) also fire this endpoint. Like `webhook`, it widens `context` — a trigger fire has no session. */",
|
|
1326
1329
|
" trigger?: TTrigger;",
|
|
1327
1330
|
" execute: (",
|
|
1328
1331
|
" params: {",
|
|
1329
|
-
|
|
1332
|
+
// Mirrors the base module: a poll's run carries `__poll`, a provider
|
|
1333
|
+
// trigger's delivery `__webhook`.
|
|
1334
|
+
" input: TTrigger extends { every: string } ? TInput & { __poll?: ZitePollInput } : TTrigger extends { events: string[] } ? TInput & { __webhook?: ZiteAppEventDelivery } : TTrigger extends { integration: string } ? TInput & { __webhook?: ZiteTriggerDelivery } : TInput;",
|
|
1330
1335
|
" context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
|
|
1331
1336
|
" } & (TStream extends true ? { stream: ZiteStreamInterface } : {}),",
|
|
1332
1337
|
" ) => Promise<TOutput> | TOutput;",
|
|
@@ -387,6 +387,14 @@ const duplicateIdentifierErrorsIn = (source) => {
|
|
|
387
387
|
(0, vitest_1.expect)(output).toContain('TTrigger extends ZiteTrigger | undefined = undefined');
|
|
388
388
|
(0, vitest_1.expect)(output).toContain('ZiteTrigger, ZiteWebhook }');
|
|
389
389
|
});
|
|
390
|
+
(0, vitest_1.it)('passes the trigger registration types and trigger inputs through to app code', () => {
|
|
391
|
+
(0, vitest_1.expect)(output).toContain('ZiteTriggerSubscribe, ZiteTriggerSubscribeInput');
|
|
392
|
+
(0, vitest_1.expect)(output).toContain('ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput');
|
|
393
|
+
(0, vitest_1.expect)(output).toContain("TTrigger extends { every: string } ? TInput & { __poll?: ZitePollInput }");
|
|
394
|
+
(0, vitest_1.expect)(output).toContain('TInput & { __webhook?: ZiteTriggerDelivery }');
|
|
395
|
+
(0, vitest_1.expect)(output).toContain("TTrigger extends { events: string[] } ? TInput & { __webhook?: ZiteAppEventDelivery }");
|
|
396
|
+
(0, vitest_1.expect)(output).not.toContain('src/triggers/');
|
|
397
|
+
});
|
|
390
398
|
(0, vitest_1.it)('exports ZiteError', () => {
|
|
391
399
|
(0, vitest_1.expect)(output).toContain('ZiteError');
|
|
392
400
|
});
|
|
@@ -22,6 +22,21 @@ export type ZiteTrigger = {
|
|
|
22
22
|
label?: string;
|
|
23
23
|
paused?: boolean;
|
|
24
24
|
every?: never;
|
|
25
|
+
events?: never;
|
|
26
|
+
} | {
|
|
27
|
+
/**
|
|
28
|
+
* The connection's name in `zite.config.json`, for a provider whose
|
|
29
|
+
* webhooks come through Zite's own app (Slack, HubSpot, Notion,
|
|
30
|
+
* Intercom, QuickBooks). Nothing is registered: the platform routes
|
|
31
|
+
* that account's events of these types to the endpoint.
|
|
32
|
+
*/
|
|
33
|
+
integration: string;
|
|
34
|
+
/** Event names as the platform lists them for the provider, e.g. `message.channels`, `contact.creation`. */
|
|
35
|
+
events: string[];
|
|
36
|
+
/** The sentence the editor shows for what fires this endpoint, e.g. "When a message is posted in Slack". */
|
|
37
|
+
label?: string;
|
|
38
|
+
paused?: boolean;
|
|
39
|
+
every?: never;
|
|
25
40
|
} | {
|
|
26
41
|
/** `<n>m` (1–59) or `<n>h` (1–23). What makes the trigger a poll. */
|
|
27
42
|
every: string;
|
|
@@ -30,6 +45,7 @@ export type ZiteTrigger = {
|
|
|
30
45
|
/** The sentence the editor shows for this poll, e.g. "Every 10 minutes, new Stripe charges". */
|
|
31
46
|
label?: string;
|
|
32
47
|
paused?: boolean;
|
|
48
|
+
events?: never;
|
|
33
49
|
};
|
|
34
50
|
/**
|
|
35
51
|
* What a provider trigger's `subscribe` export receives. Write it as
|
|
@@ -97,6 +113,8 @@ export type ZiteTriggerDelivery = {
|
|
|
97
113
|
/** Ids earlier deliveries returned as `handled`, newest last. Skip these. */
|
|
98
114
|
seen: string[];
|
|
99
115
|
};
|
|
116
|
+
/** What an app event trigger's run carries as `input.__webhook`: one event, no cursor. */
|
|
117
|
+
export type ZiteAppEventDelivery = Omit<ZiteTriggerDelivery, "cursor" | "seen">;
|
|
100
118
|
/**
|
|
101
119
|
* What a poll-triggered run, or a provider trigger's delivery, returns for
|
|
102
120
|
* the platform to keep: its new `cursor`, and the id of every item it acted
|
|
@@ -203,6 +221,10 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
|
|
|
203
221
|
every: string;
|
|
204
222
|
} ? TInput & {
|
|
205
223
|
__poll?: ZitePollInput;
|
|
224
|
+
} : TTrigger extends {
|
|
225
|
+
events: string[];
|
|
226
|
+
} ? TInput & {
|
|
227
|
+
__webhook?: ZiteAppEventDelivery;
|
|
206
228
|
} : TTrigger extends {
|
|
207
229
|
integration: string;
|
|
208
230
|
} ? TInput & {
|
|
@@ -199,6 +199,32 @@ describe("platform-triggered runs", () => {
|
|
|
199
199
|
context: { user: null },
|
|
200
200
|
})).resolves.toEqual({ cursor: "sync1+1", handled: ["e2"] });
|
|
201
201
|
});
|
|
202
|
+
it("types an app event trigger's run as one event, with no cursor to keep", async () => {
|
|
203
|
+
const endpoint = createEndpoint({
|
|
204
|
+
inputSchema: z.object({ event: z.object({ text: z.string() }) }),
|
|
205
|
+
trigger: { integration: "team-slack", events: ["message.channels"] },
|
|
206
|
+
execute: async ({ input }) => {
|
|
207
|
+
// @ts-expect-error an app event delivery has no cursor
|
|
208
|
+
void input.__webhook?.cursor;
|
|
209
|
+
return { id: input.__webhook?.deliveryId ?? null };
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
await expect(endpoint.execute({
|
|
213
|
+
input: {
|
|
214
|
+
event: { text: "hi" },
|
|
215
|
+
__webhook: { headers: {}, deliveryId: "slack:Ev1" },
|
|
216
|
+
},
|
|
217
|
+
context: { user: null },
|
|
218
|
+
})).resolves.toEqual({ id: "slack:Ev1" });
|
|
219
|
+
});
|
|
220
|
+
it("refuses events on a trigger that also polls", () => {
|
|
221
|
+
createEndpoint({
|
|
222
|
+
inputSchema: z.object({}),
|
|
223
|
+
// @ts-expect-error a poll can't also take events
|
|
224
|
+
trigger: { every: "5m", events: ["message.channels"] },
|
|
225
|
+
execute: async () => ({}),
|
|
226
|
+
});
|
|
227
|
+
});
|
|
202
228
|
it("does not validate a webhook fire", async () => {
|
|
203
229
|
const endpoint = createEndpoint({
|
|
204
230
|
inputSchema: z.object({ token: z.string().min(10) }),
|
package/dist/esm/bundle/index.js
CHANGED
|
@@ -554,10 +554,6 @@ ${bodySection}
|
|
|
554
554
|
},
|
|
555
555
|
minify: false,
|
|
556
556
|
logLevel: 'silent',
|
|
557
|
-
// A script that imports an endpoint file's named exports (a trigger's
|
|
558
|
-
// subscribe/unsubscribe) must not carry the endpoint along with them:
|
|
559
|
-
// unused, its `createEndpoint(...)` and everything `execute` imports go.
|
|
560
|
-
pure: ['createEndpoint'],
|
|
561
557
|
plugins: [plugin],
|
|
562
558
|
});
|
|
563
559
|
if (result.errors.length > 0) {
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1217,10 +1217,13 @@ export function generateBackendWrapperTs(envVarNames = []) {
|
|
|
1217
1217
|
"// Auto-generated type-narrowing wrapper. Do not edit manually.",
|
|
1218
1218
|
"// Re-exports createEndpoint with context.user typed to the app User.",
|
|
1219
1219
|
"",
|
|
1220
|
-
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStreamInterface, ZiteTrigger, ZiteWebhook } from 'zitejs/backend/base';",
|
|
1220
|
+
"import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStreamInterface, ZiteTrigger, ZiteTriggerDelivery, ZiteAppEventDelivery, ZitePollInput, ZiteWebhook } from 'zitejs/backend/base';",
|
|
1221
1221
|
"import type { User } from 'zitejs/auth';",
|
|
1222
1222
|
"",
|
|
1223
1223
|
"export type { ZiteErrorCode, ZiteSchedule, ZiteScheduledContext, ZiteStreamInterface, ZiteTrigger, ZiteWebhook };",
|
|
1224
|
+
// A trigger's registration exports are typed against these, and they
|
|
1225
|
+
// only reach app code through this file.
|
|
1226
|
+
"export type { ZiteAppEventDelivery, ZitePollInput, ZitePollResult, ZiteTriggerDelivery, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, ZiteTriggerSubscribeResult, ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput } from 'zitejs/backend/base';",
|
|
1224
1227
|
// The pre-monorepo SDK put this in scope for every endpoint, so migrated
|
|
1225
1228
|
// code can name it. `createEndpoint` infers the same thing without it.
|
|
1226
1229
|
"export type InferSchemaType<T> = T extends { _output: infer U } ? U : T;",
|
|
@@ -1307,11 +1310,13 @@ export function generateBackendWrapperTs(envVarNames = []) {
|
|
|
1307
1310
|
" schedule?: TSchedule;",
|
|
1308
1311
|
" /** When set, an inbound webhook can also trigger this endpoint. Like `schedule`, it widens `context` — a webhook fire has no session. */",
|
|
1309
1312
|
" webhook?: TWebhook;",
|
|
1310
|
-
" /** When set, a
|
|
1313
|
+
" /** When set, a connection's events (registered by this file's own `subscribe` export) or a poll (`every`) also fire this endpoint. Like `webhook`, it widens `context` — a trigger fire has no session. */",
|
|
1311
1314
|
" trigger?: TTrigger;",
|
|
1312
1315
|
" execute: (",
|
|
1313
1316
|
" params: {",
|
|
1314
|
-
|
|
1317
|
+
// Mirrors the base module: a poll's run carries `__poll`, a provider
|
|
1318
|
+
// trigger's delivery `__webhook`.
|
|
1319
|
+
" input: TTrigger extends { every: string } ? TInput & { __poll?: ZitePollInput } : TTrigger extends { events: string[] } ? TInput & { __webhook?: ZiteAppEventDelivery } : TTrigger extends { integration: string } ? TInput & { __webhook?: ZiteTriggerDelivery } : TInput;",
|
|
1315
1320
|
" context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
|
|
1316
1321
|
" } & (TStream extends true ? { stream: ZiteStreamInterface } : {}),",
|
|
1317
1322
|
" ) => Promise<TOutput> | TOutput;",
|
|
@@ -382,6 +382,14 @@ describe('generateBackendWrapperTs', () => {
|
|
|
382
382
|
expect(output).toContain('TTrigger extends ZiteTrigger | undefined = undefined');
|
|
383
383
|
expect(output).toContain('ZiteTrigger, ZiteWebhook }');
|
|
384
384
|
});
|
|
385
|
+
it('passes the trigger registration types and trigger inputs through to app code', () => {
|
|
386
|
+
expect(output).toContain('ZiteTriggerSubscribe, ZiteTriggerSubscribeInput');
|
|
387
|
+
expect(output).toContain('ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput');
|
|
388
|
+
expect(output).toContain("TTrigger extends { every: string } ? TInput & { __poll?: ZitePollInput }");
|
|
389
|
+
expect(output).toContain('TInput & { __webhook?: ZiteTriggerDelivery }');
|
|
390
|
+
expect(output).toContain("TTrigger extends { events: string[] } ? TInput & { __webhook?: ZiteAppEventDelivery }");
|
|
391
|
+
expect(output).not.toContain('src/triggers/');
|
|
392
|
+
});
|
|
385
393
|
it('exports ZiteError', () => {
|
|
386
394
|
expect(output).toContain('ZiteError');
|
|
387
395
|
});
|