zitejs 0.9.67 → 0.9.69

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.
@@ -259,6 +259,15 @@ function createAliasPlugin(opts) {
259
259
  }
260
260
  return { path: 'zitejs/integrations', external: true };
261
261
  });
262
+ // Resolve zitejs/email to .zite/integrations/email.ts
263
+ build.onResolve({ filter: /^zitejs\/email$/ }, () => {
264
+ if (opts.baseDir) {
265
+ const intPath = path.resolve(opts.baseDir, '.zite/integrations/email.ts');
266
+ if (fs.existsSync(intPath))
267
+ return { path: intPath };
268
+ }
269
+ return { path: 'zitejs/email', external: true };
270
+ });
262
271
  // zitejs/runtime is NOT in PREBUNDLED_LIBS — it's a thin fetch()
263
272
  // wrapper that gets bundled inline by esbuild (no special handling).
264
273
  for (const [pkgName, modulePath] of Object.entries(PREBUNDLED_LIBS)) {
@@ -33,11 +33,39 @@ function getFlowId(appDir) {
33
33
  catch { }
34
34
  return undefined;
35
35
  }
36
+ /**
37
+ * Find the connected email integration's key in an app's zite.config.json,
38
+ * if any. The key is the integrationId used by the runtime SDK bridge.
39
+ */
40
+ function getEmailIntegrationId(appDir) {
41
+ try {
42
+ const configPath = (0, path_1.join)("apps", appDir, "zite.config.json");
43
+ if (!(0, fs_2.existsSync)(configPath))
44
+ return undefined;
45
+ const config = JSON.parse((0, fs_2.readFileSync)(configPath, "utf-8"));
46
+ const integrations = config.integrations ?? {};
47
+ for (const [id, int] of Object.entries(integrations)) {
48
+ if (int?.type === "email")
49
+ return id;
50
+ }
51
+ }
52
+ catch { }
53
+ return undefined;
54
+ }
36
55
  function regenerateAppTypedWrappers(appDir) {
37
56
  const outDir = (0, path_1.join)("apps", appDir, ".zite");
38
57
  (0, fs_2.mkdirSync)(outDir, { recursive: true });
39
58
  (0, fs_2.writeFileSync)((0, path_1.join)(outDir, "user.ts"), (0, lib_js_1.generateUserTs)());
40
59
  (0, fs_2.writeFileSync)((0, path_1.join)(outDir, "auth.ts"), (0, lib_js_1.generateAuthWrapperTs)());
60
+ // Email integration: generate the Email client at .zite/integrations/email.ts.
61
+ // Resolved by the `zitejs/email` bundler/tsconfig alias (mirrors airtable's
62
+ // `zitejs/integrations`), so endpoint code uses `import { Email } from 'zitejs/email'`.
63
+ const emailIntegrationId = getEmailIntegrationId(appDir);
64
+ if (emailIntegrationId) {
65
+ const intDir = (0, path_1.join)(outDir, "integrations");
66
+ (0, fs_2.mkdirSync)(intDir, { recursive: true });
67
+ (0, fs_2.writeFileSync)((0, path_1.join)(intDir, "email.ts"), (0, lib_js_1.generateEmailSdk)(emailIntegrationId));
68
+ }
41
69
  (0, fs_2.writeFileSync)((0, path_1.join)(outDir, "backend.ts"), (0, lib_js_1.generateBackendWrapperTs)());
42
70
  }
43
71
  function regenerateAppApiTs(appDir) {
@@ -89,6 +89,68 @@ export interface AirtableTableClient<T> {
89
89
  }): Promise<DeleteResult>;
90
90
  }
91
91
  export declare function createAirtableClient<T>(integrationId: string, className: string, implicitParams: Record<string, unknown>): AirtableTableClient<T>;
92
+ /** A block of content in an email body. */
93
+ export type EmailBlock = {
94
+ type: "text";
95
+ content: string;
96
+ } | {
97
+ type: "button";
98
+ label: string;
99
+ href: string;
100
+ alignment?: "left" | "center" | "right";
101
+ } | {
102
+ type: "image";
103
+ src: string;
104
+ alt?: string;
105
+ alignment?: "left" | "center" | "right";
106
+ width: number;
107
+ height: number;
108
+ } | {
109
+ type: "spacer";
110
+ height: number;
111
+ } | {
112
+ type: "divider";
113
+ borderColor?: string;
114
+ };
115
+ export interface SendEmailParams {
116
+ /** Recipient address(es). Must be valid emails — never placeholders like "me". */
117
+ to: string | string[];
118
+ subject: string;
119
+ /** Email body as an array of content blocks. */
120
+ body: EmailBlock[];
121
+ cc?: string[];
122
+ bcc?: string[];
123
+ replyTo?: string;
124
+ /** 'formatted' (default) for styled HTML, 'plain' for text-only. */
125
+ layout?: "formatted" | "plain";
126
+ /** Custom logo shown above the email content (header area), for branding. */
127
+ logo?: {
128
+ url: string;
129
+ width?: number;
130
+ height?: number;
131
+ };
132
+ /** File attachments, each fetched from its URL at send time. */
133
+ attachments?: {
134
+ filename: string;
135
+ url: string;
136
+ contentType?: string;
137
+ }[];
138
+ }
139
+ export interface SendEmailResult {
140
+ success: boolean;
141
+ messageId: string;
142
+ }
143
+ export interface EmailClient {
144
+ send(params: SendEmailParams): Promise<SendEmailResult>;
145
+ }
146
+ /**
147
+ * Email client — sends through the Zite email gateway via the runtime SDK
148
+ * bridge. Email cannot run in-worker (provider auth, image processing, HTML
149
+ * inlining all live in the gateway), so every call dispatches through
150
+ * getSdkCall(), which routes to the email handler. The integrationId is the
151
+ * app's connected email integration key.
152
+ */
153
+ export declare function createEmailClient(integrationId: string): EmailClient;
92
154
  export declare function createNotificationsClient(): {
93
155
  create(params: NotificationsCreateParams): Promise<NotificationsCreateResult>;
94
156
  };
@@ -4,6 +4,7 @@ exports.createCaller = void 0;
4
4
  exports.createTableClient = createTableClient;
5
5
  exports.createSqlClient = createSqlClient;
6
6
  exports.createAirtableClient = createAirtableClient;
7
+ exports.createEmailClient = createEmailClient;
7
8
  exports.createNotificationsClient = createNotificationsClient;
8
9
  exports.createMetaClient = createMetaClient;
9
10
  const sdkCall_js_1 = require("../internal/sdkCall.js");
@@ -100,6 +101,18 @@ function createAirtableClient(integrationId, className, implicitParams) {
100
101
  }),
101
102
  };
102
103
  }
104
+ /**
105
+ * Email client — sends through the Zite email gateway via the runtime SDK
106
+ * bridge. Email cannot run in-worker (provider auth, image processing, HTML
107
+ * inlining all live in the gateway), so every call dispatches through
108
+ * getSdkCall(), which routes to the email handler. The integrationId is the
109
+ * app's connected email integration key.
110
+ */
111
+ function createEmailClient(integrationId) {
112
+ return {
113
+ send: (params) => (0, sdkCall_js_1.getSdkCall)()(integrationId, "Email", "send", params),
114
+ };
115
+ }
103
116
  const NOTIFICATIONS_SDK_INTEGRATION_ID = "__notifications__";
104
117
  const META_SDK_INTEGRATION_ID = "__meta__";
105
118
  function createNotificationsClient() {
@@ -59,3 +59,11 @@ export type AirtableLock = {
59
59
  };
60
60
  export declare function generateAirtableTs(lock: AirtableLock): string | null;
61
61
  export declare function generateBackendWrapperTs(): string;
62
+ /**
63
+ * Generate `.zite/integrations/email.ts` — the `Email` client for an app with
64
+ * an email integration connected. Mirrors the airtable SDK generation: a thin
65
+ * wrapper over a `zitejs/runtime` factory that dispatches through the runtime
66
+ * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
67
+ * connected integration's key.
68
+ */
69
+ export declare function generateEmailSdk(integrationId: string): string;
@@ -9,6 +9,7 @@ exports.generateUserTs = generateUserTs;
9
9
  exports.generateAuthWrapperTs = generateAuthWrapperTs;
10
10
  exports.generateAirtableTs = generateAirtableTs;
11
11
  exports.generateBackendWrapperTs = generateBackendWrapperTs;
12
+ exports.generateEmailSdk = generateEmailSdk;
12
13
  const parser_1 = require("@babel/parser");
13
14
  const FIELD_TYPE_MAP = {
14
15
  single_line_text: "string",
@@ -725,3 +726,30 @@ function generateBackendWrapperTs() {
725
726
  "",
726
727
  ].join("\n");
727
728
  }
729
+ /**
730
+ * Generate `.zite/integrations/email.ts` — the `Email` client for an app with
731
+ * an email integration connected. Mirrors the airtable SDK generation: a thin
732
+ * wrapper over a `zitejs/runtime` factory that dispatches through the runtime
733
+ * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
734
+ * connected integration's key.
735
+ */
736
+ function generateEmailSdk(integrationId) {
737
+ return [
738
+ "// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.",
739
+ "// Email SDK — sends through the Zite email gateway via the runtime bridge.",
740
+ "//",
741
+ "// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
742
+ "// => { success: boolean; messageId: string }",
743
+ "",
744
+ "import { createEmailClient } from 'zitejs/runtime';",
745
+ "",
746
+ "export type {",
747
+ " EmailBlock,",
748
+ " SendEmailParams,",
749
+ " SendEmailResult,",
750
+ "} from 'zitejs/runtime';",
751
+ "",
752
+ `export const Email = createEmailClient('${integrationId}');`,
753
+ "",
754
+ ].join("\n");
755
+ }
@@ -223,6 +223,15 @@ function createAliasPlugin(opts) {
223
223
  }
224
224
  return { path: 'zitejs/integrations', external: true };
225
225
  });
226
+ // Resolve zitejs/email to .zite/integrations/email.ts
227
+ build.onResolve({ filter: /^zitejs\/email$/ }, () => {
228
+ if (opts.baseDir) {
229
+ const intPath = path.resolve(opts.baseDir, '.zite/integrations/email.ts');
230
+ if (fs.existsSync(intPath))
231
+ return { path: intPath };
232
+ }
233
+ return { path: 'zitejs/email', external: true };
234
+ });
226
235
  // zitejs/runtime is NOT in PREBUNDLED_LIBS — it's a thin fetch()
227
236
  // wrapper that gets bundled inline by esbuild (no special handling).
228
237
  for (const [pkgName, modulePath] of Object.entries(PREBUNDLED_LIBS)) {
package/dist/esm/cli.js CHANGED
File without changes
@@ -2,7 +2,7 @@ import { watch } from "fs";
2
2
  import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, } from "fs";
3
3
  import { join } from "path";
4
4
  import { runSync } from "../sync/index.js";
5
- import { generateDbTs, generateApiTs, generateUserTs, generateAuthWrapperTs, generateBackendWrapperTs, generateAirtableTs, } from "../sync/lib.js";
5
+ import { generateDbTs, generateApiTs, generateUserTs, generateAuthWrapperTs, generateBackendWrapperTs, generateAirtableTs, generateEmailSdk, } from "../sync/lib.js";
6
6
  const debounceTimers = new Map();
7
7
  function debounce(key, fn, ms) {
8
8
  const existing = debounceTimers.get(key);
@@ -29,11 +29,39 @@ function getFlowId(appDir) {
29
29
  catch { }
30
30
  return undefined;
31
31
  }
32
+ /**
33
+ * Find the connected email integration's key in an app's zite.config.json,
34
+ * if any. The key is the integrationId used by the runtime SDK bridge.
35
+ */
36
+ function getEmailIntegrationId(appDir) {
37
+ try {
38
+ const configPath = join("apps", appDir, "zite.config.json");
39
+ if (!existsSync(configPath))
40
+ return undefined;
41
+ const config = JSON.parse(readFileSync(configPath, "utf-8"));
42
+ const integrations = config.integrations ?? {};
43
+ for (const [id, int] of Object.entries(integrations)) {
44
+ if (int?.type === "email")
45
+ return id;
46
+ }
47
+ }
48
+ catch { }
49
+ return undefined;
50
+ }
32
51
  function regenerateAppTypedWrappers(appDir) {
33
52
  const outDir = join("apps", appDir, ".zite");
34
53
  mkdirSync(outDir, { recursive: true });
35
54
  writeFileSync(join(outDir, "user.ts"), generateUserTs());
36
55
  writeFileSync(join(outDir, "auth.ts"), generateAuthWrapperTs());
56
+ // Email integration: generate the Email client at .zite/integrations/email.ts.
57
+ // Resolved by the `zitejs/email` bundler/tsconfig alias (mirrors airtable's
58
+ // `zitejs/integrations`), so endpoint code uses `import { Email } from 'zitejs/email'`.
59
+ const emailIntegrationId = getEmailIntegrationId(appDir);
60
+ if (emailIntegrationId) {
61
+ const intDir = join(outDir, "integrations");
62
+ mkdirSync(intDir, { recursive: true });
63
+ writeFileSync(join(intDir, "email.ts"), generateEmailSdk(emailIntegrationId));
64
+ }
37
65
  writeFileSync(join(outDir, "backend.ts"), generateBackendWrapperTs());
38
66
  }
39
67
  function regenerateAppApiTs(appDir) {
@@ -89,6 +89,68 @@ export interface AirtableTableClient<T> {
89
89
  }): Promise<DeleteResult>;
90
90
  }
91
91
  export declare function createAirtableClient<T>(integrationId: string, className: string, implicitParams: Record<string, unknown>): AirtableTableClient<T>;
92
+ /** A block of content in an email body. */
93
+ export type EmailBlock = {
94
+ type: "text";
95
+ content: string;
96
+ } | {
97
+ type: "button";
98
+ label: string;
99
+ href: string;
100
+ alignment?: "left" | "center" | "right";
101
+ } | {
102
+ type: "image";
103
+ src: string;
104
+ alt?: string;
105
+ alignment?: "left" | "center" | "right";
106
+ width: number;
107
+ height: number;
108
+ } | {
109
+ type: "spacer";
110
+ height: number;
111
+ } | {
112
+ type: "divider";
113
+ borderColor?: string;
114
+ };
115
+ export interface SendEmailParams {
116
+ /** Recipient address(es). Must be valid emails — never placeholders like "me". */
117
+ to: string | string[];
118
+ subject: string;
119
+ /** Email body as an array of content blocks. */
120
+ body: EmailBlock[];
121
+ cc?: string[];
122
+ bcc?: string[];
123
+ replyTo?: string;
124
+ /** 'formatted' (default) for styled HTML, 'plain' for text-only. */
125
+ layout?: "formatted" | "plain";
126
+ /** Custom logo shown above the email content (header area), for branding. */
127
+ logo?: {
128
+ url: string;
129
+ width?: number;
130
+ height?: number;
131
+ };
132
+ /** File attachments, each fetched from its URL at send time. */
133
+ attachments?: {
134
+ filename: string;
135
+ url: string;
136
+ contentType?: string;
137
+ }[];
138
+ }
139
+ export interface SendEmailResult {
140
+ success: boolean;
141
+ messageId: string;
142
+ }
143
+ export interface EmailClient {
144
+ send(params: SendEmailParams): Promise<SendEmailResult>;
145
+ }
146
+ /**
147
+ * Email client — sends through the Zite email gateway via the runtime SDK
148
+ * bridge. Email cannot run in-worker (provider auth, image processing, HTML
149
+ * inlining all live in the gateway), so every call dispatches through
150
+ * getSdkCall(), which routes to the email handler. The integrationId is the
151
+ * app's connected email integration key.
152
+ */
153
+ export declare function createEmailClient(integrationId: string): EmailClient;
92
154
  export declare function createNotificationsClient(): {
93
155
  create(params: NotificationsCreateParams): Promise<NotificationsCreateResult>;
94
156
  };
@@ -92,6 +92,18 @@ export function createAirtableClient(integrationId, className, implicitParams) {
92
92
  }),
93
93
  };
94
94
  }
95
+ /**
96
+ * Email client — sends through the Zite email gateway via the runtime SDK
97
+ * bridge. Email cannot run in-worker (provider auth, image processing, HTML
98
+ * inlining all live in the gateway), so every call dispatches through
99
+ * getSdkCall(), which routes to the email handler. The integrationId is the
100
+ * app's connected email integration key.
101
+ */
102
+ export function createEmailClient(integrationId) {
103
+ return {
104
+ send: (params) => getSdkCall()(integrationId, "Email", "send", params),
105
+ };
106
+ }
95
107
  const NOTIFICATIONS_SDK_INTEGRATION_ID = "__notifications__";
96
108
  const META_SDK_INTEGRATION_ID = "__meta__";
97
109
  export function createNotificationsClient() {
@@ -59,3 +59,11 @@ export type AirtableLock = {
59
59
  };
60
60
  export declare function generateAirtableTs(lock: AirtableLock): string | null;
61
61
  export declare function generateBackendWrapperTs(): string;
62
+ /**
63
+ * Generate `.zite/integrations/email.ts` — the `Email` client for an app with
64
+ * an email integration connected. Mirrors the airtable SDK generation: a thin
65
+ * wrapper over a `zitejs/runtime` factory that dispatches through the runtime
66
+ * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
67
+ * connected integration's key.
68
+ */
69
+ export declare function generateEmailSdk(integrationId: string): string;
@@ -714,3 +714,30 @@ export function generateBackendWrapperTs() {
714
714
  "",
715
715
  ].join("\n");
716
716
  }
717
+ /**
718
+ * Generate `.zite/integrations/email.ts` — the `Email` client for an app with
719
+ * an email integration connected. Mirrors the airtable SDK generation: a thin
720
+ * wrapper over a `zitejs/runtime` factory that dispatches through the runtime
721
+ * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
722
+ * connected integration's key.
723
+ */
724
+ export function generateEmailSdk(integrationId) {
725
+ return [
726
+ "// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.",
727
+ "// Email SDK — sends through the Zite email gateway via the runtime bridge.",
728
+ "//",
729
+ "// await Email.send({ to, subject, body: [{ type: 'text', content: '...' }] })",
730
+ "// => { success: boolean; messageId: string }",
731
+ "",
732
+ "import { createEmailClient } from 'zitejs/runtime';",
733
+ "",
734
+ "export type {",
735
+ " EmailBlock,",
736
+ " SendEmailParams,",
737
+ " SendEmailResult,",
738
+ "} from 'zitejs/runtime';",
739
+ "",
740
+ `export const Email = createEmailClient('${integrationId}');`,
741
+ "",
742
+ ].join("\n");
743
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.67",
3
+ "version": "0.9.69",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCaller = void 0;
4
- var index_js_1 = require("../caller/index.js");
5
- Object.defineProperty(exports, "createCaller", { enumerable: true, get: function () { return index_js_1.createCaller; } });
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTableClient = void 0;
4
- var index_js_1 = require("../runtime/index.js");
5
- Object.defineProperty(exports, "createTableClient", { enumerable: true, get: function () { return index_js_1.createTableClient; } });
@@ -1,2 +0,0 @@
1
- export { createCaller } from '../caller/index.js';
2
- export type { EndpointConfig } from '../caller/index.js';
@@ -1 +0,0 @@
1
- export { createCaller } from '../caller/index.js';
@@ -1,2 +0,0 @@
1
- export { createTableClient } from '../runtime/index.js';
2
- export type { TableClient } from '../runtime/index.js';
@@ -1 +0,0 @@
1
- export { createTableClient } from '../runtime/index.js';