zitejs 0.9.148 → 0.9.149
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/integrations/rules.js +5 -3
- package/dist/cjs/runtime/index.d.ts +44 -8
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/cjs/runtime/sendEmailParamsTypes.test-d.js +32 -0
- package/dist/cjs/sync/lib.js +5 -3
- package/dist/cjs/sync/lib.test.js +10 -0
- package/dist/esm/integrations/rules.js +5 -3
- package/dist/esm/runtime/index.d.ts +44 -8
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.d.ts +1 -0
- package/dist/esm/runtime/sendEmailParamsTypes.test-d.js +30 -0
- package/dist/esm/sync/lib.js +5 -3
- package/dist/esm/sync/lib.test.js +10 -0
- package/package.json +1 -1
|
@@ -75,8 +75,8 @@ const FIELDS_BY_TYPE = {
|
|
|
75
75
|
// one host to call.
|
|
76
76
|
pipedrive: extras("apiBaseUrl"),
|
|
77
77
|
// Shopify has no global API host: every call goes to the store's own domain
|
|
78
|
-
// under a pinned API version. The storefront pair is the shopper-facing API
|
|
79
|
-
//
|
|
78
|
+
// under a pinned API version. The storefront pair is the shopper-facing API;
|
|
79
|
+
// its URL comes from the store domain, so only the token can be missing.
|
|
80
80
|
shopify: extras("shopDomain", "apiBaseUrl", "storefrontApiUrl", "storefrontAccessToken"),
|
|
81
81
|
sharepoint: extras(),
|
|
82
82
|
excel: extras(),
|
|
@@ -96,7 +96,9 @@ exports.OPTIONAL_CREDENTIAL_FIELDS = {
|
|
|
96
96
|
// Only S3-compatible providers set an endpoint, and a prefix is opt-in.
|
|
97
97
|
amazonS3: ["endpoint", "pathPrefix"],
|
|
98
98
|
snowflake: ["warehouse"],
|
|
99
|
-
|
|
99
|
+
// A store that didn't grant the storefront scopes gets no token, and
|
|
100
|
+
// Shopify then serves the Storefront API tokenless.
|
|
101
|
+
shopify: ["storefrontAccessToken"],
|
|
100
102
|
};
|
|
101
103
|
/**
|
|
102
104
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
@@ -266,6 +266,12 @@ export type EmailBlock = {
|
|
|
266
266
|
label: string;
|
|
267
267
|
href: string;
|
|
268
268
|
alignment?: "left" | "center" | "right";
|
|
269
|
+
/** Hex colour, e.g. "#7c2d3a". Defaults to the platform blue. */
|
|
270
|
+
backgroundColor?: string;
|
|
271
|
+
/** Hex colour. Defaults to white. */
|
|
272
|
+
textColor?: string;
|
|
273
|
+
/** Corner radius in pixels. Defaults to 6. */
|
|
274
|
+
borderRadius?: number;
|
|
269
275
|
} | {
|
|
270
276
|
type: "image";
|
|
271
277
|
src: string;
|
|
@@ -280,25 +286,23 @@ export type EmailBlock = {
|
|
|
280
286
|
type: "divider";
|
|
281
287
|
borderColor?: string;
|
|
282
288
|
};
|
|
283
|
-
|
|
289
|
+
interface SendEmailBaseParams {
|
|
284
290
|
/** Recipient address(es). Must be valid emails — never placeholders like "me". */
|
|
285
291
|
to: string | string[];
|
|
286
292
|
subject: string;
|
|
287
|
-
/** Email body as an array of content blocks. */
|
|
288
|
-
body: EmailBlock[];
|
|
289
293
|
cc?: string[];
|
|
290
294
|
bcc?: string[];
|
|
291
295
|
replyTo?: string;
|
|
292
|
-
/** 'formatted' (default) for styled HTML, 'plain' for text-only. */
|
|
293
|
-
layout?: "formatted" | "plain";
|
|
294
296
|
/**
|
|
295
297
|
* Text direction of the email. Use 'rtl' for right-to-left languages
|
|
296
298
|
* (Hebrew, Arabic) — sets dir="rtl" on the email wrapper and right-aligns
|
|
297
|
-
* text
|
|
298
|
-
* by the sanitizer and will NOT work. Defaults to 'ltr'.
|
|
299
|
+
* text. Defaults to 'ltr'.
|
|
299
300
|
*/
|
|
300
301
|
direction?: "ltr" | "rtl";
|
|
301
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Logo shown above the email content (header area), for branding. On an
|
|
304
|
+
* html email it replaces the brand kit's logo.
|
|
305
|
+
*/
|
|
302
306
|
logo?: {
|
|
303
307
|
url: string;
|
|
304
308
|
width?: number;
|
|
@@ -311,9 +315,41 @@ export interface SendEmailParams {
|
|
|
311
315
|
contentType?: string;
|
|
312
316
|
}[];
|
|
313
317
|
}
|
|
318
|
+
/** An email written as HTML. */
|
|
319
|
+
export interface SendHtmlEmailParams extends SendEmailBaseParams {
|
|
320
|
+
/**
|
|
321
|
+
* Email-safe HTML: tables for layout, inline styles, `<a class="button">`
|
|
322
|
+
* for buttons. Sanitized and its `<style>` rules inlined at send time.
|
|
323
|
+
*/
|
|
324
|
+
html: string;
|
|
325
|
+
/** Plain-text part. Generated from `html` when omitted. */
|
|
326
|
+
text?: string;
|
|
327
|
+
/**
|
|
328
|
+
* 'formatted' (default) puts the html in a card under the logo, in the
|
|
329
|
+
* app's brand kit; 'plain' drops the card and logo; 'none' sends the html
|
|
330
|
+
* as the whole document, with no frame or brand.
|
|
331
|
+
*/
|
|
332
|
+
layout?: "formatted" | "plain" | "none";
|
|
333
|
+
body?: never;
|
|
334
|
+
}
|
|
335
|
+
/** An email written as an array of content blocks. */
|
|
336
|
+
export interface SendBlocksEmailParams extends SendEmailBaseParams {
|
|
337
|
+
/** Email body as an array of content blocks. */
|
|
338
|
+
body: EmailBlock[];
|
|
339
|
+
/**
|
|
340
|
+
* 'formatted' (default) for styled HTML, 'plain' for text-only. HTML like
|
|
341
|
+
* `<div dir="rtl">` inside text blocks is stripped by the sanitizer.
|
|
342
|
+
*/
|
|
343
|
+
layout?: "formatted" | "plain";
|
|
344
|
+
html?: never;
|
|
345
|
+
text?: never;
|
|
346
|
+
}
|
|
347
|
+
export type SendEmailParams = SendHtmlEmailParams | SendBlocksEmailParams;
|
|
314
348
|
export interface SendEmailResult {
|
|
315
349
|
success: boolean;
|
|
316
350
|
messageId: string;
|
|
351
|
+
/** Problems that did not stop the send, e.g. an email large enough for Gmail to clip. */
|
|
352
|
+
warnings?: string[];
|
|
317
353
|
}
|
|
318
354
|
export interface EmailClient {
|
|
319
355
|
send(params: SendEmailParams): Promise<SendEmailResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
(0, vitest_1.test)("an email is written as html or as blocks, not both", () => {
|
|
5
|
+
(0, vitest_1.expectTypeOf)({
|
|
6
|
+
to: "a@example.com",
|
|
7
|
+
subject: "Hi",
|
|
8
|
+
html: "<p>Hi</p>",
|
|
9
|
+
layout: "none",
|
|
10
|
+
}).toExtend();
|
|
11
|
+
(0, vitest_1.expectTypeOf)({
|
|
12
|
+
to: "a@example.com",
|
|
13
|
+
subject: "Hi",
|
|
14
|
+
body: [{ type: "text", content: "Hi" }],
|
|
15
|
+
}).toExtend();
|
|
16
|
+
(0, vitest_1.expectTypeOf)({
|
|
17
|
+
to: "a@example.com",
|
|
18
|
+
subject: "Hi",
|
|
19
|
+
html: "<p>Hi</p>",
|
|
20
|
+
body: [],
|
|
21
|
+
}).not.toExtend();
|
|
22
|
+
(0, vitest_1.expectTypeOf)({
|
|
23
|
+
to: "a@example.com",
|
|
24
|
+
subject: "Hi",
|
|
25
|
+
body: [],
|
|
26
|
+
layout: "none",
|
|
27
|
+
}).not.toExtend();
|
|
28
|
+
(0, vitest_1.expectTypeOf)({
|
|
29
|
+
to: "a@example.com",
|
|
30
|
+
subject: "Hi",
|
|
31
|
+
}).not.toExtend();
|
|
32
|
+
});
|
package/dist/cjs/sync/lib.js
CHANGED
|
@@ -1398,18 +1398,20 @@ function generateEmailSdk(integrationId) {
|
|
|
1398
1398
|
"// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
|
|
1399
1399
|
"// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.",
|
|
1400
1400
|
"//",
|
|
1401
|
+
"// await Email.send({ to, subject, html: '<p>...</p>' })",
|
|
1401
1402
|
"// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
|
|
1402
|
-
"// => { success: boolean; messageId: string }",
|
|
1403
|
+
"// => { success: boolean; messageId: string; warnings?: string[] }",
|
|
1403
1404
|
"//",
|
|
1404
|
-
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl'
|
|
1405
|
-
"// inside body text are stripped by the sanitizer and will not work.",
|
|
1405
|
+
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl'.",
|
|
1406
1406
|
"",
|
|
1407
1407
|
"import { createEmailClient } from 'zitejs/runtime';",
|
|
1408
1408
|
"",
|
|
1409
1409
|
"export type {",
|
|
1410
1410
|
" EmailBlock,",
|
|
1411
|
+
" SendBlocksEmailParams,",
|
|
1411
1412
|
" SendEmailParams,",
|
|
1412
1413
|
" SendEmailResult,",
|
|
1414
|
+
" SendHtmlEmailParams,",
|
|
1413
1415
|
"} from 'zitejs/runtime';",
|
|
1414
1416
|
"",
|
|
1415
1417
|
`export const Email = createEmailClient(${tsSingleQuoted(integrationId)});`,
|
|
@@ -566,6 +566,16 @@ const appTypeErrors = (files, paths) => {
|
|
|
566
566
|
const jira = await integrations.get('tickets');
|
|
567
567
|
const cloudId: string = jira.cloudId;
|
|
568
568
|
const siteUrl: string = jira.siteUrl;
|
|
569
|
+
`)).toEqual([
|
|
570
|
+
vitest_1.expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
571
|
+
]);
|
|
572
|
+
});
|
|
573
|
+
(0, vitest_1.it)('types the Shopify storefront URL as always present and only its token as optional', () => {
|
|
574
|
+
const generated = (0, lib_js_1.generateIntegrationsIndex)([{ name: 'shopify', serviceType: 'shopify', perUser: false }], { reexportAirtable: false });
|
|
575
|
+
(0, vitest_1.expect)(typeErrorsIn(generated, `import { integrations } from 'zitejs/integrations';
|
|
576
|
+
const shop = await integrations.get('shopify');
|
|
577
|
+
const storefrontApiUrl: string = shop.storefrontApiUrl;
|
|
578
|
+
const storefrontAccessToken: string = shop.storefrontAccessToken;
|
|
569
579
|
`)).toEqual([
|
|
570
580
|
vitest_1.expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
571
581
|
]);
|
|
@@ -72,8 +72,8 @@ const FIELDS_BY_TYPE = {
|
|
|
72
72
|
// one host to call.
|
|
73
73
|
pipedrive: extras("apiBaseUrl"),
|
|
74
74
|
// Shopify has no global API host: every call goes to the store's own domain
|
|
75
|
-
// under a pinned API version. The storefront pair is the shopper-facing API
|
|
76
|
-
//
|
|
75
|
+
// under a pinned API version. The storefront pair is the shopper-facing API;
|
|
76
|
+
// its URL comes from the store domain, so only the token can be missing.
|
|
77
77
|
shopify: extras("shopDomain", "apiBaseUrl", "storefrontApiUrl", "storefrontAccessToken"),
|
|
78
78
|
sharepoint: extras(),
|
|
79
79
|
excel: extras(),
|
|
@@ -93,7 +93,9 @@ export const OPTIONAL_CREDENTIAL_FIELDS = {
|
|
|
93
93
|
// Only S3-compatible providers set an endpoint, and a prefix is opt-in.
|
|
94
94
|
amazonS3: ["endpoint", "pathPrefix"],
|
|
95
95
|
snowflake: ["warehouse"],
|
|
96
|
-
|
|
96
|
+
// A store that didn't grant the storefront scopes gets no token, and
|
|
97
|
+
// Shopify then serves the Storefront API tokenless.
|
|
98
|
+
shopify: ["storefrontAccessToken"],
|
|
97
99
|
};
|
|
98
100
|
/**
|
|
99
101
|
* Types the runtime never serves: those with a generated client (Airtable, email,
|
|
@@ -266,6 +266,12 @@ export type EmailBlock = {
|
|
|
266
266
|
label: string;
|
|
267
267
|
href: string;
|
|
268
268
|
alignment?: "left" | "center" | "right";
|
|
269
|
+
/** Hex colour, e.g. "#7c2d3a". Defaults to the platform blue. */
|
|
270
|
+
backgroundColor?: string;
|
|
271
|
+
/** Hex colour. Defaults to white. */
|
|
272
|
+
textColor?: string;
|
|
273
|
+
/** Corner radius in pixels. Defaults to 6. */
|
|
274
|
+
borderRadius?: number;
|
|
269
275
|
} | {
|
|
270
276
|
type: "image";
|
|
271
277
|
src: string;
|
|
@@ -280,25 +286,23 @@ export type EmailBlock = {
|
|
|
280
286
|
type: "divider";
|
|
281
287
|
borderColor?: string;
|
|
282
288
|
};
|
|
283
|
-
|
|
289
|
+
interface SendEmailBaseParams {
|
|
284
290
|
/** Recipient address(es). Must be valid emails — never placeholders like "me". */
|
|
285
291
|
to: string | string[];
|
|
286
292
|
subject: string;
|
|
287
|
-
/** Email body as an array of content blocks. */
|
|
288
|
-
body: EmailBlock[];
|
|
289
293
|
cc?: string[];
|
|
290
294
|
bcc?: string[];
|
|
291
295
|
replyTo?: string;
|
|
292
|
-
/** 'formatted' (default) for styled HTML, 'plain' for text-only. */
|
|
293
|
-
layout?: "formatted" | "plain";
|
|
294
296
|
/**
|
|
295
297
|
* Text direction of the email. Use 'rtl' for right-to-left languages
|
|
296
298
|
* (Hebrew, Arabic) — sets dir="rtl" on the email wrapper and right-aligns
|
|
297
|
-
* text
|
|
298
|
-
* by the sanitizer and will NOT work. Defaults to 'ltr'.
|
|
299
|
+
* text. Defaults to 'ltr'.
|
|
299
300
|
*/
|
|
300
301
|
direction?: "ltr" | "rtl";
|
|
301
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Logo shown above the email content (header area), for branding. On an
|
|
304
|
+
* html email it replaces the brand kit's logo.
|
|
305
|
+
*/
|
|
302
306
|
logo?: {
|
|
303
307
|
url: string;
|
|
304
308
|
width?: number;
|
|
@@ -311,9 +315,41 @@ export interface SendEmailParams {
|
|
|
311
315
|
contentType?: string;
|
|
312
316
|
}[];
|
|
313
317
|
}
|
|
318
|
+
/** An email written as HTML. */
|
|
319
|
+
export interface SendHtmlEmailParams extends SendEmailBaseParams {
|
|
320
|
+
/**
|
|
321
|
+
* Email-safe HTML: tables for layout, inline styles, `<a class="button">`
|
|
322
|
+
* for buttons. Sanitized and its `<style>` rules inlined at send time.
|
|
323
|
+
*/
|
|
324
|
+
html: string;
|
|
325
|
+
/** Plain-text part. Generated from `html` when omitted. */
|
|
326
|
+
text?: string;
|
|
327
|
+
/**
|
|
328
|
+
* 'formatted' (default) puts the html in a card under the logo, in the
|
|
329
|
+
* app's brand kit; 'plain' drops the card and logo; 'none' sends the html
|
|
330
|
+
* as the whole document, with no frame or brand.
|
|
331
|
+
*/
|
|
332
|
+
layout?: "formatted" | "plain" | "none";
|
|
333
|
+
body?: never;
|
|
334
|
+
}
|
|
335
|
+
/** An email written as an array of content blocks. */
|
|
336
|
+
export interface SendBlocksEmailParams extends SendEmailBaseParams {
|
|
337
|
+
/** Email body as an array of content blocks. */
|
|
338
|
+
body: EmailBlock[];
|
|
339
|
+
/**
|
|
340
|
+
* 'formatted' (default) for styled HTML, 'plain' for text-only. HTML like
|
|
341
|
+
* `<div dir="rtl">` inside text blocks is stripped by the sanitizer.
|
|
342
|
+
*/
|
|
343
|
+
layout?: "formatted" | "plain";
|
|
344
|
+
html?: never;
|
|
345
|
+
text?: never;
|
|
346
|
+
}
|
|
347
|
+
export type SendEmailParams = SendHtmlEmailParams | SendBlocksEmailParams;
|
|
314
348
|
export interface SendEmailResult {
|
|
315
349
|
success: boolean;
|
|
316
350
|
messageId: string;
|
|
351
|
+
/** Problems that did not stop the send, e.g. an email large enough for Gmail to clip. */
|
|
352
|
+
warnings?: string[];
|
|
317
353
|
}
|
|
318
354
|
export interface EmailClient {
|
|
319
355
|
send(params: SendEmailParams): Promise<SendEmailResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { expectTypeOf, test } from "vitest";
|
|
2
|
+
test("an email is written as html or as blocks, not both", () => {
|
|
3
|
+
expectTypeOf({
|
|
4
|
+
to: "a@example.com",
|
|
5
|
+
subject: "Hi",
|
|
6
|
+
html: "<p>Hi</p>",
|
|
7
|
+
layout: "none",
|
|
8
|
+
}).toExtend();
|
|
9
|
+
expectTypeOf({
|
|
10
|
+
to: "a@example.com",
|
|
11
|
+
subject: "Hi",
|
|
12
|
+
body: [{ type: "text", content: "Hi" }],
|
|
13
|
+
}).toExtend();
|
|
14
|
+
expectTypeOf({
|
|
15
|
+
to: "a@example.com",
|
|
16
|
+
subject: "Hi",
|
|
17
|
+
html: "<p>Hi</p>",
|
|
18
|
+
body: [],
|
|
19
|
+
}).not.toExtend();
|
|
20
|
+
expectTypeOf({
|
|
21
|
+
to: "a@example.com",
|
|
22
|
+
subject: "Hi",
|
|
23
|
+
body: [],
|
|
24
|
+
layout: "none",
|
|
25
|
+
}).not.toExtend();
|
|
26
|
+
expectTypeOf({
|
|
27
|
+
to: "a@example.com",
|
|
28
|
+
subject: "Hi",
|
|
29
|
+
}).not.toExtend();
|
|
30
|
+
});
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1383,18 +1383,20 @@ export function generateEmailSdk(integrationId) {
|
|
|
1383
1383
|
"// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
|
|
1384
1384
|
"// The tsconfig aliases resolve zitejs/* imports to the correct .zite/ files.",
|
|
1385
1385
|
"//",
|
|
1386
|
+
"// await Email.send({ to, subject, html: '<p>...</p>' })",
|
|
1386
1387
|
"// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
|
|
1387
|
-
"// => { success: boolean; messageId: string }",
|
|
1388
|
+
"// => { success: boolean; messageId: string; warnings?: string[] }",
|
|
1388
1389
|
"//",
|
|
1389
|
-
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl'
|
|
1390
|
-
"// inside body text are stripped by the sanitizer and will not work.",
|
|
1390
|
+
"// RTL languages (Hebrew, Arabic): pass direction: 'rtl'.",
|
|
1391
1391
|
"",
|
|
1392
1392
|
"import { createEmailClient } from 'zitejs/runtime';",
|
|
1393
1393
|
"",
|
|
1394
1394
|
"export type {",
|
|
1395
1395
|
" EmailBlock,",
|
|
1396
|
+
" SendBlocksEmailParams,",
|
|
1396
1397
|
" SendEmailParams,",
|
|
1397
1398
|
" SendEmailResult,",
|
|
1399
|
+
" SendHtmlEmailParams,",
|
|
1398
1400
|
"} from 'zitejs/runtime';",
|
|
1399
1401
|
"",
|
|
1400
1402
|
`export const Email = createEmailClient(${tsSingleQuoted(integrationId)});`,
|
|
@@ -561,6 +561,16 @@ describe('generateIntegrationsIndex', () => {
|
|
|
561
561
|
const jira = await integrations.get('tickets');
|
|
562
562
|
const cloudId: string = jira.cloudId;
|
|
563
563
|
const siteUrl: string = jira.siteUrl;
|
|
564
|
+
`)).toEqual([
|
|
565
|
+
expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
566
|
+
]);
|
|
567
|
+
});
|
|
568
|
+
it('types the Shopify storefront URL as always present and only its token as optional', () => {
|
|
569
|
+
const generated = generateIntegrationsIndex([{ name: 'shopify', serviceType: 'shopify', perUser: false }], { reexportAirtable: false });
|
|
570
|
+
expect(typeErrorsIn(generated, `import { integrations } from 'zitejs/integrations';
|
|
571
|
+
const shop = await integrations.get('shopify');
|
|
572
|
+
const storefrontApiUrl: string = shop.storefrontApiUrl;
|
|
573
|
+
const storefrontAccessToken: string = shop.storefrontAccessToken;
|
|
564
574
|
`)).toEqual([
|
|
565
575
|
expect.stringContaining("Type 'string | undefined' is not assignable"),
|
|
566
576
|
]);
|