zitejs 0.9.127 → 0.9.129
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/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/integrations/rules.d.ts +5 -0
- package/dist/cjs/integrations/rules.js +9 -1
- package/dist/cjs/sync/lib.js +12 -4
- package/dist/cjs/sync/lib.test.js +22 -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/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/integrations/rules.d.ts +5 -0
- package/dist/esm/integrations/rules.js +8 -0
- package/dist/esm/sync/lib.js +13 -5
- package/dist/esm/sync/lib.test.js +22 -0
- package/package.json +1 -1
- package/dist/cjs/meta/index.d.ts +0 -14
- package/dist/cjs/meta/index.js +0 -12
- package/dist/cjs/notifications/index.d.ts +0 -25
- package/dist/cjs/notifications/index.js +0 -12
- package/dist/esm/meta/index.d.ts +0 -14
- package/dist/esm/meta/index.js +0 -8
- package/dist/esm/notifications/index.d.ts +0 -25
- package/dist/esm/notifications/index.js +0 -8
|
@@ -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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Zite } from "./client/index.js";
|
|
2
2
|
export type { Record, RecordListOutput, RecordListOptions, FieldCreateInput, FieldUpdateInput, TableCreateInput, TableUpdateInput, DatabaseCreateInput, DatabaseListOutput, } from "./client/index.js";
|
|
3
3
|
export * from "./types/index.js";
|
|
4
|
-
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
4
|
+
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, OPTIONAL_CREDENTIAL_FIELDS, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
5
5
|
export type { ConfigIntegrations, CredentialServiceType, GettableIntegration, } from "./integrations/rules.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,13 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.normalizeIntegrationServiceType = exports.isCredentialServiceType = exports.gettableIntegrations = exports.NON_CREDENTIAL_SERVICE_TYPES = exports.CREDENTIAL_FIELDS = exports.Zite = void 0;
|
|
17
|
+
exports.normalizeIntegrationServiceType = exports.isCredentialServiceType = exports.gettableIntegrations = exports.OPTIONAL_CREDENTIAL_FIELDS = exports.NON_CREDENTIAL_SERVICE_TYPES = exports.CREDENTIAL_FIELDS = exports.Zite = void 0;
|
|
18
18
|
var index_js_1 = require("./client/index.js");
|
|
19
19
|
Object.defineProperty(exports, "Zite", { enumerable: true, get: function () { return index_js_1.Zite; } });
|
|
20
20
|
__exportStar(require("./types/index.js"), exports);
|
|
21
21
|
var rules_js_1 = require("./integrations/rules.js");
|
|
22
22
|
Object.defineProperty(exports, "CREDENTIAL_FIELDS", { enumerable: true, get: function () { return rules_js_1.CREDENTIAL_FIELDS; } });
|
|
23
23
|
Object.defineProperty(exports, "NON_CREDENTIAL_SERVICE_TYPES", { enumerable: true, get: function () { return rules_js_1.NON_CREDENTIAL_SERVICE_TYPES; } });
|
|
24
|
+
Object.defineProperty(exports, "OPTIONAL_CREDENTIAL_FIELDS", { enumerable: true, get: function () { return rules_js_1.OPTIONAL_CREDENTIAL_FIELDS; } });
|
|
24
25
|
Object.defineProperty(exports, "gettableIntegrations", { enumerable: true, get: function () { return rules_js_1.gettableIntegrations; } });
|
|
25
26
|
Object.defineProperty(exports, "isCredentialServiceType", { enumerable: true, get: function () { return rules_js_1.isCredentialServiceType; } });
|
|
26
27
|
Object.defineProperty(exports, "normalizeIntegrationServiceType", { enumerable: true, get: function () { return rules_js_1.normalizeIntegrationServiceType; } });
|
|
@@ -45,6 +45,11 @@ declare const FIELDS_BY_TYPE: {
|
|
|
45
45
|
export type CredentialServiceType = keyof typeof FIELDS_BY_TYPE;
|
|
46
46
|
/** Per service type: `accessToken`, then its extra labels sorted (Salesforce `instanceUrl`). */
|
|
47
47
|
export declare const CREDENTIAL_FIELDS: Readonly<Record<CredentialServiceType, readonly string[]>>;
|
|
48
|
+
/**
|
|
49
|
+
* Extras the platform omits when the account doesn't have them: a Jira site
|
|
50
|
+
* connected before its URL was stored, a Trello key the deployment never set.
|
|
51
|
+
*/
|
|
52
|
+
export declare const OPTIONAL_CREDENTIAL_FIELDS: Readonly<Partial<Record<CredentialServiceType, readonly string[]>>>;
|
|
48
53
|
/**
|
|
49
54
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
50
55
|
* the project database, Fillout) and those whose key is a frontend value (Maps, Analytics).
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Which `zite.config.json` entries `integrations.get` can name, and the fields
|
|
3
3
|
// each answers with. No imports, so the platform applies these same rules.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.gettableIntegrations = exports.isCredentialServiceType = exports.normalizeIntegrationServiceType = exports.NON_CREDENTIAL_SERVICE_TYPES = exports.CREDENTIAL_FIELDS = void 0;
|
|
5
|
+
exports.gettableIntegrations = exports.isCredentialServiceType = exports.normalizeIntegrationServiceType = exports.NON_CREDENTIAL_SERVICE_TYPES = exports.OPTIONAL_CREDENTIAL_FIELDS = exports.CREDENTIAL_FIELDS = void 0;
|
|
6
6
|
const extras = (...labels) => [
|
|
7
7
|
"accessToken",
|
|
8
8
|
...[...labels].sort(),
|
|
@@ -52,6 +52,14 @@ const FIELDS_BY_TYPE = {
|
|
|
52
52
|
};
|
|
53
53
|
/** Per service type: `accessToken`, then its extra labels sorted (Salesforce `instanceUrl`). */
|
|
54
54
|
exports.CREDENTIAL_FIELDS = FIELDS_BY_TYPE;
|
|
55
|
+
/**
|
|
56
|
+
* Extras the platform omits when the account doesn't have them: a Jira site
|
|
57
|
+
* connected before its URL was stored, a Trello key the deployment never set.
|
|
58
|
+
*/
|
|
59
|
+
exports.OPTIONAL_CREDENTIAL_FIELDS = {
|
|
60
|
+
jira: ["siteUrl"],
|
|
61
|
+
trello: ["clientApiKey"],
|
|
62
|
+
};
|
|
55
63
|
/**
|
|
56
64
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
57
65
|
* the project database, Fillout) and those whose key is a frontend value (Maps, Analytics).
|
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;",
|
|
@@ -1401,9 +1406,12 @@ function generateEmailSdk(integrationId) {
|
|
|
1401
1406
|
}
|
|
1402
1407
|
const connectedTypeFor = (serviceType) => {
|
|
1403
1408
|
const extraLabels = rules_js_1.CREDENTIAL_FIELDS[serviceType].slice(1);
|
|
1409
|
+
const optional = rules_js_1.OPTIONAL_CREDENTIAL_FIELDS[serviceType] ?? [];
|
|
1404
1410
|
return extraLabels.length === 0
|
|
1405
1411
|
? "Connected"
|
|
1406
|
-
: `Connected<{ ${extraLabels
|
|
1412
|
+
: `Connected<{ ${extraLabels
|
|
1413
|
+
.map((label) => `${label}${optional.includes(label) ? "?" : ""}: string`)
|
|
1414
|
+
.join("; ")} }>`;
|
|
1407
1415
|
};
|
|
1408
1416
|
/**
|
|
1409
1417
|
* `.zite/integrations/index.ts`: `zitejs/integrations` for one source dir. The
|
|
@@ -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
|
});
|
|
@@ -490,6 +498,20 @@ const duplicateIdentifierErrorsIn = (source) => {
|
|
|
490
498
|
"
|
|
491
499
|
`);
|
|
492
500
|
});
|
|
501
|
+
// The platform leaves these out for some accounts, so the type can't promise them.
|
|
502
|
+
(0, vitest_1.it)('marks an extra the platform may omit as optional', () => {
|
|
503
|
+
const generated = (0, lib_js_1.generateIntegrationsIndex)([{ name: 'tickets', serviceType: 'jira' }], { reexportAirtable: false });
|
|
504
|
+
(0, vitest_1.expect)(generated).toContain("'tickets': Connected<{ cloudId: string; siteUrl?: string }> | NeedsConnect;");
|
|
505
|
+
(0, vitest_1.expect)(typeErrorsIn(generated, `import { integrations } from 'zitejs/integrations';
|
|
506
|
+
const jira = await integrations.get('tickets');
|
|
507
|
+
if (jira.status === 'connected') {
|
|
508
|
+
const cloudId: string = jira.cloudId;
|
|
509
|
+
const siteUrl: string = jira.siteUrl;
|
|
510
|
+
}
|
|
511
|
+
`)).toEqual([
|
|
512
|
+
vitest_1.expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
513
|
+
]);
|
|
514
|
+
});
|
|
493
515
|
(0, vitest_1.it)('types get per name in app code', () => {
|
|
494
516
|
const generated = (0, lib_js_1.generateIntegrationsIndex)([
|
|
495
517
|
{ name: 'crm', serviceType: 'salesforce' },
|
|
@@ -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/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Zite } from "./client/index.js";
|
|
2
2
|
export type { Record, RecordListOutput, RecordListOptions, FieldCreateInput, FieldUpdateInput, TableCreateInput, TableUpdateInput, DatabaseCreateInput, DatabaseListOutput, } from "./client/index.js";
|
|
3
3
|
export * from "./types/index.js";
|
|
4
|
-
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
4
|
+
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, OPTIONAL_CREDENTIAL_FIELDS, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
5
5
|
export type { ConfigIntegrations, CredentialServiceType, GettableIntegration, } from "./integrations/rules.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Zite } from "./client/index.js";
|
|
2
2
|
export * from "./types/index.js";
|
|
3
|
-
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
3
|
+
export { CREDENTIAL_FIELDS, NON_CREDENTIAL_SERVICE_TYPES, OPTIONAL_CREDENTIAL_FIELDS, gettableIntegrations, isCredentialServiceType, normalizeIntegrationServiceType, } from "./integrations/rules.js";
|
|
@@ -45,6 +45,11 @@ declare const FIELDS_BY_TYPE: {
|
|
|
45
45
|
export type CredentialServiceType = keyof typeof FIELDS_BY_TYPE;
|
|
46
46
|
/** Per service type: `accessToken`, then its extra labels sorted (Salesforce `instanceUrl`). */
|
|
47
47
|
export declare const CREDENTIAL_FIELDS: Readonly<Record<CredentialServiceType, readonly string[]>>;
|
|
48
|
+
/**
|
|
49
|
+
* Extras the platform omits when the account doesn't have them: a Jira site
|
|
50
|
+
* connected before its URL was stored, a Trello key the deployment never set.
|
|
51
|
+
*/
|
|
52
|
+
export declare const OPTIONAL_CREDENTIAL_FIELDS: Readonly<Partial<Record<CredentialServiceType, readonly string[]>>>;
|
|
48
53
|
/**
|
|
49
54
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
50
55
|
* the project database, Fillout) and those whose key is a frontend value (Maps, Analytics).
|
|
@@ -49,6 +49,14 @@ const FIELDS_BY_TYPE = {
|
|
|
49
49
|
};
|
|
50
50
|
/** Per service type: `accessToken`, then its extra labels sorted (Salesforce `instanceUrl`). */
|
|
51
51
|
export const CREDENTIAL_FIELDS = FIELDS_BY_TYPE;
|
|
52
|
+
/**
|
|
53
|
+
* Extras the platform omits when the account doesn't have them: a Jira site
|
|
54
|
+
* connected before its URL was stored, a Trello key the deployment never set.
|
|
55
|
+
*/
|
|
56
|
+
export const OPTIONAL_CREDENTIAL_FIELDS = {
|
|
57
|
+
jira: ["siteUrl"],
|
|
58
|
+
trello: ["clientApiKey"],
|
|
59
|
+
};
|
|
52
60
|
/**
|
|
53
61
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
54
62
|
* the project database, Fillout) and those whose key is a frontend value (Maps, Analytics).
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parse } from "@babel/parser";
|
|
2
2
|
import { allocateSchemaNames, describeRenames, keepValidSdkName, normalizeSchemaNames, SdkNameAllocator, toCamelCase, toPascalCase, toSdkName, } from "./sdkNames.js";
|
|
3
|
-
import { CREDENTIAL_FIELDS, } from "../integrations/rules.js";
|
|
3
|
+
import { CREDENTIAL_FIELDS, OPTIONAL_CREDENTIAL_FIELDS, } from "../integrations/rules.js";
|
|
4
4
|
const AUTH_USERS_TABLE_ID = "zite_user";
|
|
5
5
|
/**
|
|
6
6
|
* What a field's value looks like when a record is READ back.
|
|
@@ -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;",
|
|
@@ -1386,9 +1391,12 @@ export function generateEmailSdk(integrationId) {
|
|
|
1386
1391
|
}
|
|
1387
1392
|
const connectedTypeFor = (serviceType) => {
|
|
1388
1393
|
const extraLabels = CREDENTIAL_FIELDS[serviceType].slice(1);
|
|
1394
|
+
const optional = OPTIONAL_CREDENTIAL_FIELDS[serviceType] ?? [];
|
|
1389
1395
|
return extraLabels.length === 0
|
|
1390
1396
|
? "Connected"
|
|
1391
|
-
: `Connected<{ ${extraLabels
|
|
1397
|
+
: `Connected<{ ${extraLabels
|
|
1398
|
+
.map((label) => `${label}${optional.includes(label) ? "?" : ""}: string`)
|
|
1399
|
+
.join("; ")} }>`;
|
|
1392
1400
|
};
|
|
1393
1401
|
/**
|
|
1394
1402
|
* `.zite/integrations/index.ts`: `zitejs/integrations` for one source dir. The
|
|
@@ -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
|
});
|
|
@@ -485,6 +493,20 @@ describe('generateIntegrationsIndex', () => {
|
|
|
485
493
|
"
|
|
486
494
|
`);
|
|
487
495
|
});
|
|
496
|
+
// The platform leaves these out for some accounts, so the type can't promise them.
|
|
497
|
+
it('marks an extra the platform may omit as optional', () => {
|
|
498
|
+
const generated = generateIntegrationsIndex([{ name: 'tickets', serviceType: 'jira' }], { reexportAirtable: false });
|
|
499
|
+
expect(generated).toContain("'tickets': Connected<{ cloudId: string; siteUrl?: string }> | NeedsConnect;");
|
|
500
|
+
expect(typeErrorsIn(generated, `import { integrations } from 'zitejs/integrations';
|
|
501
|
+
const jira = await integrations.get('tickets');
|
|
502
|
+
if (jira.status === 'connected') {
|
|
503
|
+
const cloudId: string = jira.cloudId;
|
|
504
|
+
const siteUrl: string = jira.siteUrl;
|
|
505
|
+
}
|
|
506
|
+
`)).toEqual([
|
|
507
|
+
expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
508
|
+
]);
|
|
509
|
+
});
|
|
488
510
|
it('types get per name in app code', () => {
|
|
489
511
|
const generated = generateIntegrationsIndex([
|
|
490
512
|
{ name: 'crm', serviceType: 'salesforce' },
|
package/package.json
CHANGED
package/dist/cjs/meta/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type ZiteProjectUser = {
|
|
2
|
-
uuid: string;
|
|
3
|
-
firstName: string | null;
|
|
4
|
-
lastName: string | null;
|
|
5
|
-
email: string;
|
|
6
|
-
profilePictureUrl: string | null;
|
|
7
|
-
};
|
|
8
|
-
export type MetaListUsersResult = {
|
|
9
|
-
users: ZiteProjectUser[];
|
|
10
|
-
};
|
|
11
|
-
export declare class ZiteMeta {
|
|
12
|
-
static listUsers(): Promise<MetaListUsersResult>;
|
|
13
|
-
}
|
|
14
|
-
export declare const Meta: typeof ZiteMeta;
|
package/dist/cjs/meta/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Meta = exports.ZiteMeta = void 0;
|
|
4
|
-
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
5
|
-
const META_SDK_INTEGRATION_ID = '__meta__';
|
|
6
|
-
class ZiteMeta {
|
|
7
|
-
static listUsers() {
|
|
8
|
-
return (0, sdkCall_js_1.getSdkCall)()(META_SDK_INTEGRATION_ID, 'ZiteMeta', 'listUsers', {});
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.ZiteMeta = ZiteMeta;
|
|
12
|
-
exports.Meta = ZiteMeta;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface NotificationLink {
|
|
2
|
-
path?: string;
|
|
3
|
-
params?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
export type NotificationsCreateParams = {
|
|
6
|
-
recipients: string[];
|
|
7
|
-
title: string;
|
|
8
|
-
body?: string;
|
|
9
|
-
link?: NotificationLink;
|
|
10
|
-
path?: string;
|
|
11
|
-
params?: Record<string, string>;
|
|
12
|
-
payload?: Record<string, unknown>;
|
|
13
|
-
idempotencyKey?: string;
|
|
14
|
-
};
|
|
15
|
-
export type NotificationsCreateResult = {
|
|
16
|
-
created: number;
|
|
17
|
-
} | {
|
|
18
|
-
created: 0;
|
|
19
|
-
preview: true;
|
|
20
|
-
wouldCreate: number;
|
|
21
|
-
};
|
|
22
|
-
export declare class ZiteNotifications {
|
|
23
|
-
static create(params: NotificationsCreateParams): Promise<NotificationsCreateResult>;
|
|
24
|
-
}
|
|
25
|
-
export declare const Notifications: typeof ZiteNotifications;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Notifications = exports.ZiteNotifications = void 0;
|
|
4
|
-
const sdkCall_js_1 = require("../internal/sdkCall.js");
|
|
5
|
-
const NOTIFICATIONS_SDK_INTEGRATION_ID = '__notifications__';
|
|
6
|
-
class ZiteNotifications {
|
|
7
|
-
static create(params) {
|
|
8
|
-
return (0, sdkCall_js_1.getSdkCall)()(NOTIFICATIONS_SDK_INTEGRATION_ID, 'ZiteNotifications', 'create', params);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.ZiteNotifications = ZiteNotifications;
|
|
12
|
-
exports.Notifications = ZiteNotifications;
|
package/dist/esm/meta/index.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type ZiteProjectUser = {
|
|
2
|
-
uuid: string;
|
|
3
|
-
firstName: string | null;
|
|
4
|
-
lastName: string | null;
|
|
5
|
-
email: string;
|
|
6
|
-
profilePictureUrl: string | null;
|
|
7
|
-
};
|
|
8
|
-
export type MetaListUsersResult = {
|
|
9
|
-
users: ZiteProjectUser[];
|
|
10
|
-
};
|
|
11
|
-
export declare class ZiteMeta {
|
|
12
|
-
static listUsers(): Promise<MetaListUsersResult>;
|
|
13
|
-
}
|
|
14
|
-
export declare const Meta: typeof ZiteMeta;
|
package/dist/esm/meta/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface NotificationLink {
|
|
2
|
-
path?: string;
|
|
3
|
-
params?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
export type NotificationsCreateParams = {
|
|
6
|
-
recipients: string[];
|
|
7
|
-
title: string;
|
|
8
|
-
body?: string;
|
|
9
|
-
link?: NotificationLink;
|
|
10
|
-
path?: string;
|
|
11
|
-
params?: Record<string, string>;
|
|
12
|
-
payload?: Record<string, unknown>;
|
|
13
|
-
idempotencyKey?: string;
|
|
14
|
-
};
|
|
15
|
-
export type NotificationsCreateResult = {
|
|
16
|
-
created: number;
|
|
17
|
-
} | {
|
|
18
|
-
created: 0;
|
|
19
|
-
preview: true;
|
|
20
|
-
wouldCreate: number;
|
|
21
|
-
};
|
|
22
|
-
export declare class ZiteNotifications {
|
|
23
|
-
static create(params: NotificationsCreateParams): Promise<NotificationsCreateResult>;
|
|
24
|
-
}
|
|
25
|
-
export declare const Notifications: typeof ZiteNotifications;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { getSdkCall } from '../internal/sdkCall.js';
|
|
2
|
-
const NOTIFICATIONS_SDK_INTEGRATION_ID = '__notifications__';
|
|
3
|
-
export class ZiteNotifications {
|
|
4
|
-
static create(params) {
|
|
5
|
-
return getSdkCall()(NOTIFICATIONS_SDK_INTEGRATION_ID, 'ZiteNotifications', 'create', params);
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export const Notifications = ZiteNotifications;
|