zitejs 0.10.0-start.15 → 0.10.0-start.17

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.
@@ -9,6 +9,7 @@ const react_1 = require("react");
9
9
  const react_2 = require("better-auth/react");
10
10
  const plugins_1 = require("better-auth/client/plugins");
11
11
  const constants_js_1 = require("./constants.js");
12
+ const previewClaim_js_1 = require("./previewClaim.js");
12
13
  const config_js_1 = require("./config.js");
13
14
  const authClient = (0, react_2.createAuthClient)({
14
15
  baseURL: '',
@@ -97,6 +98,11 @@ function loginWithRedirect(opts) {
97
98
  window._ziteUsageToken;
98
99
  if (usageToken)
99
100
  params.set(constants_js_1.USAGE_TOKEN_QUERY_PARAM, usageToken);
101
+ // A Start app's preview also needs its claim where the editor's frame dropped
102
+ // the cookie, as `loginHref()` sends it. Classic previews never have one.
103
+ const claim = (0, previewClaim_js_1.browserPreviewClaim)();
104
+ if (claim)
105
+ params.set(previewClaim_js_1.PREVIEW_CLAIM_PARAM, claim);
100
106
  const query = params.toString();
101
107
  window.location.href = query ? `/auth/login?${query}` : '/auth/login';
102
108
  }
@@ -0,0 +1,7 @@
1
+ export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
2
+ /**
3
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
4
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
5
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
6
+ */
7
+ export declare const browserPreviewClaim: () => string | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.browserPreviewClaim = exports.PREVIEW_CLAIM_PARAM = void 0;
4
+ // The host's name for it (apps/zite-host/src/previewClaim.ts).
5
+ exports.PREVIEW_CLAIM_PARAM = 'zite_preview';
6
+ let captured;
7
+ /**
8
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
9
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
10
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
11
+ */
12
+ const browserPreviewClaim = () => {
13
+ captured ??= new URL(window.location.href).searchParams.get(exports.PREVIEW_CLAIM_PARAM);
14
+ return captured ?? undefined;
15
+ };
16
+ exports.browserPreviewClaim = browserPreviewClaim;
@@ -97,6 +97,7 @@ function getDeclaredEnvVarNames(appDir) {
97
97
  }
98
98
  }
99
99
  function regenerateAppTypedWrappers(appDir) {
100
+ const runtime = (0, entries_js_1.isStartAppDir)(appDir.path) ? "start" : "classic";
100
101
  const outDir = (0, path_1.join)(appDir.path, ".zite");
101
102
  (0, fs_2.mkdirSync)(outDir, { recursive: true });
102
103
  // user.ts and auth.ts no longer generated — User type is fixed in zitejs/auth
@@ -107,9 +108,16 @@ function regenerateAppTypedWrappers(appDir) {
107
108
  if (emailIntegrationId) {
108
109
  const intDir = (0, path_1.join)(outDir, "integrations");
109
110
  (0, fs_2.mkdirSync)(intDir, { recursive: true });
110
- (0, fs_2.writeFileSync)((0, path_1.join)(intDir, "email.ts"), (0, lib_js_1.generateEmailSdk)(emailIntegrationId));
111
+ (0, fs_2.writeFileSync)((0, path_1.join)(intDir, "email.ts"), (0, lib_js_1.generateEmailSdk)(emailIntegrationId, runtime));
111
112
  }
112
- (0, fs_2.writeFileSync)((0, path_1.join)(outDir, "backend.ts"), (0, lib_js_1.generateBackendWrapperTs)(getDeclaredEnvVarNames(appDir)));
113
+ // A Start app's `zitejs/backend` is the package itself. This classic wrapper
114
+ // would only sit in its program with a second, id-only `hasRole`.
115
+ const backendPath = (0, path_1.join)(outDir, "backend.ts");
116
+ if (runtime === "start") {
117
+ (0, fs_2.rmSync)(backendPath, { force: true });
118
+ return;
119
+ }
120
+ (0, fs_2.writeFileSync)(backendPath, (0, lib_js_1.generateBackendWrapperTs)(getDeclaredEnvVarNames(appDir)));
113
121
  }
114
122
  function regenerateAppApiTs(appDir) {
115
123
  const apiDir = (0, path_1.join)(appDir.path, "src", "api");
@@ -158,7 +166,7 @@ function regenerateAppAirtableSdk(appDir) {
158
166
  integrationId,
159
167
  tables: int.idMappings.tables,
160
168
  };
161
- const content = (0, lib_js_1.generateAirtableTs)(airtableLock);
169
+ const content = (0, lib_js_1.generateAirtableTs)(airtableLock, (0, entries_js_1.isStartAppDir)(appDir.path) ? "start" : "classic");
162
170
  if (content) {
163
171
  const outDir = (0, path_1.join)(appDir.path, ".zite", "integrations");
164
172
  (0, fs_2.mkdirSync)(outDir, { recursive: true });
@@ -190,7 +198,9 @@ async function runGenerate() {
190
198
  try {
191
199
  if ((0, fs_2.existsSync)("zite.schema.json")) {
192
200
  const schema = JSON.parse((0, fs_2.readFileSync)("zite.schema.json", "utf-8"));
193
- const dbTs = (0, lib_js_1.generateDbTs)(schema);
201
+ const dbTs = (0, lib_js_1.generateDbTs)(schema, {
202
+ hasStartApps: (0, entries_js_1.workspaceHasStartApps)(),
203
+ });
194
204
  (0, fs_2.mkdirSync)(".zite", { recursive: true });
195
205
  (0, fs_2.writeFileSync)((0, path_1.join)(".zite", "db.ts"), dbTs);
196
206
  console.log("Wrote .zite/db.ts");
@@ -272,6 +272,12 @@ export type EmailBlock = {
272
272
  label: string;
273
273
  href: string;
274
274
  alignment?: "left" | "center" | "right";
275
+ /** A hex or `rgb()` color; defaults to the platform's button color. */
276
+ backgroundColor?: string;
277
+ /** A hex or `rgb()` color; defaults to white. */
278
+ textColor?: string;
279
+ /** Corner radius in pixels; defaults to 6. */
280
+ borderRadius?: number;
275
281
  } | {
276
282
  type: "image";
277
283
  src: string;
@@ -1,4 +1,4 @@
1
- import type { SourceDir } from "../sourceRoots.js";
1
+ import { type SourceDir } from "../sourceRoots.js";
2
2
  export declare const START_SERVER_ENTRY = ".zite/server.ts";
3
3
  export declare const START_INSTANCE_ENTRY = ".zite/start.ts";
4
4
  export type StartTarget = "cloudflare" | "node";
@@ -13,6 +13,7 @@ export declare const hasAppStart: (appDir: string) => boolean;
13
13
  /** Writes `file` under `appDir` when its content differs. Returns whether it wrote. */
14
14
  export declare const writeIfChanged: (appDir: string, file: string, content: string) => boolean;
15
15
  export declare const isStartAppDir: (appPath: string) => boolean;
16
+ export declare const workspaceHasStartApps: () => boolean;
16
17
  export declare function regenerateStartEntries(app: SourceDir): void;
17
18
  /** App modules that mention createWorkflow: what the workflow registry imports. Describe decides what each one really exports. */
18
19
  export declare function workflowFiles(appDir: string): string[];
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderWorkflowModules = exports.isStartAppDir = exports.writeIfChanged = exports.hasAppStart = exports.renderStartInstance = exports.renderStartServerEntry = exports.START_INSTANCE_ENTRY = exports.START_SERVER_ENTRY = void 0;
3
+ exports.renderWorkflowModules = exports.workspaceHasStartApps = exports.isStartAppDir = exports.writeIfChanged = exports.hasAppStart = exports.renderStartInstance = exports.renderStartServerEntry = exports.START_INSTANCE_ENTRY = exports.START_SERVER_ENTRY = void 0;
4
4
  exports.regenerateStartEntries = regenerateStartEntries;
5
5
  exports.workflowFiles = workflowFiles;
6
6
  const node_fs_1 = require("node:fs");
7
7
  const node_path_1 = require("node:path");
8
+ const sourceRoots_js_1 = require("../sourceRoots.js");
8
9
  exports.START_SERVER_ENTRY = ".zite/server.ts";
9
10
  exports.START_INSTANCE_ENTRY = ".zite/start.ts";
10
11
  const APP_START_FILES = ["src/start.ts", "src/start.tsx"];
@@ -66,6 +67,8 @@ const isStartAppDir = (appPath) => {
66
67
  };
67
68
  exports.isStartAppDir = isStartAppDir;
68
69
  const isStartApp = (app) => (0, exports.isStartAppDir)(app.path);
70
+ const workspaceHasStartApps = () => (0, sourceRoots_js_1.listSourceDirs)().some(isStartApp);
71
+ exports.workspaceHasStartApps = workspaceHasStartApps;
69
72
  function regenerateStartEntries(app) {
70
73
  if (!isStartApp(app))
71
74
  return;
@@ -21,6 +21,7 @@ __exportStar(require("./lib.js"), exports);
21
21
  const fs_1 = require("fs");
22
22
  const path_1 = require("path");
23
23
  const lib_js_1 = require("./lib.js");
24
+ const entries_js_1 = require("../start/entries.js");
24
25
  const DB_ENVIRONMENTS = {
25
26
  production: "https://tables.fillout.com/api/v1",
26
27
  staging: "https://tables.filloutstaging.com/api/v1",
@@ -74,7 +75,7 @@ async function runSync() {
74
75
  const schema = (0, lib_js_1.generateSchema)(database, existingSchema);
75
76
  (0, fs_1.writeFileSync)("zite.schema.json", JSON.stringify(schema, null, 2));
76
77
  console.log("Wrote zite.schema.json");
77
- const dbTs = (0, lib_js_1.generateDbTs)(schema);
78
+ const dbTs = (0, lib_js_1.generateDbTs)(schema, { hasStartApps: (0, entries_js_1.workspaceHasStartApps)() });
78
79
  const dotZite = ".zite";
79
80
  (0, fs_1.mkdirSync)(dotZite, { recursive: true });
80
81
  (0, fs_1.writeFileSync)((0, path_1.join)(dotZite, "db.ts"), dbTs);
@@ -31,7 +31,14 @@ export declare function generateSchema(database: Database, existingSchema?: Zite
31
31
  * Generate .zite/db.ts purely from ZiteSchema.
32
32
  * Pure function — no external data needed beyond what's in the schema file.
33
33
  */
34
- export declare function generateDbTs(inputSchema: ZiteSchema): string;
34
+ /**
35
+ * `hasStartApps` rewords the usage notes for a workspace where the code using
36
+ * the client isn't only classic endpoints. A classic-only workspace keeps the
37
+ * old wording, so its committed db.ts doesn't change.
38
+ */
39
+ export declare function generateDbTs(inputSchema: ZiteSchema, { hasStartApps }?: {
40
+ hasStartApps?: boolean;
41
+ }): string;
35
42
  export type EndpointFileInfo = {
36
43
  fileName: string;
37
44
  content?: string;
@@ -81,7 +88,7 @@ export declare function normalizeAirtableLockNames(lock: AirtableLock): {
81
88
  lock: AirtableLock;
82
89
  renames: SdkNameRename[];
83
90
  };
84
- export declare function generateAirtableTs(inputLock: AirtableLock): string | null;
91
+ export declare function generateAirtableTs(inputLock: AirtableLock, runtime?: "classic" | "start"): string | null;
85
92
  export declare function generateBackendWrapperTs(envVarNames?: string[]): string;
86
93
  /**
87
94
  * The key of the email integration an app sends through, which is the
@@ -96,7 +103,7 @@ export declare function findEmailIntegrationId(appConfig: unknown, workspaceConf
96
103
  * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
97
104
  * connected integration's key.
98
105
  */
99
- export declare function generateEmailSdk(integrationId: string): string;
106
+ export declare function generateEmailSdk(integrationId: string, runtime?: "classic" | "start"): string;
100
107
  /**
101
108
  * `.zite/integrations/index.ts`: `zitejs/integrations` for one source dir. The
102
109
  * `integrations` client typed by what the dir can see, plus the generated
@@ -491,7 +491,12 @@ function buildLinkTableComments(schema) {
491
491
  * Generate .zite/db.ts purely from ZiteSchema.
492
492
  * Pure function — no external data needed beyond what's in the schema file.
493
493
  */
494
- function generateDbTs(inputSchema) {
494
+ /**
495
+ * `hasStartApps` rewords the usage notes for a workspace where the code using
496
+ * the client isn't only classic endpoints. A classic-only workspace keeps the
497
+ * old wording, so its committed db.ts doesn't change.
498
+ */
499
+ function generateDbTs(inputSchema, { hasStartApps = false } = {}) {
495
500
  const lines = [];
496
501
  // Defensive, and idempotent: a schema whose names are already unique and
497
502
  // unreserved normalizes to itself. It matters for a `zite.schema.json`
@@ -508,7 +513,13 @@ function generateDbTs(inputSchema) {
508
513
  const tables = schema.tables.filter((table) => table.id !== AUTH_USERS_TABLE_ID);
509
514
  lines.push("// Auto-generated by zitejs generate. Do not edit manually.");
510
515
  lines.push("//");
511
- lines.push("// Usage in endpoint files (src/api/*.ts):");
516
+ if (hasStartApps) {
517
+ lines.push("// Usage in server code: a classic app's endpoints (src/api/*.ts), or a Start");
518
+ lines.push("// app's server functions and *.server.ts files:");
519
+ }
520
+ else {
521
+ lines.push("// Usage in endpoint files (src/api/*.ts):");
522
+ }
512
523
  lines.push('// import { zite } from "zitejs/db";');
513
524
  lines.push("//");
514
525
  lines.push('// Always use "zitejs/db" — never use relative paths like "../../.zite/db".');
@@ -563,7 +574,9 @@ function generateDbTs(inputSchema) {
563
574
  lines.push('// - Auth users are available as "ziteUsers" with id, name, email, firstName, lastName, and image');
564
575
  lines.push("// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL");
565
576
  lines.push("// - SELECT only — use .create/.update/.delete for writes");
566
- lines.push('// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
577
+ lines.push(hasStartApps
578
+ ? '// - In the Zite editor, the "zite:sql" skill is the full SQL reference (formulas, lookups, etc.)'
579
+ : '// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
567
580
  lines.push(...buildLinkTableComments(schema));
568
581
  lines.push("import { createTableClient, createSqlClient, createAuthClient } from 'zitejs/runtime';");
569
582
  lines.push("");
@@ -1121,7 +1134,11 @@ function normalizeAirtableLockNames(lock) {
1121
1134
  });
1122
1135
  return { lock: { ...lock, tables }, renames };
1123
1136
  }
1124
- function generateAirtableTs(inputLock) {
1137
+ /** Where an app keeps the server code a generated client is used from. */
1138
+ const serverCodeIn = (runtime) => runtime === "start"
1139
+ ? "server functions and *.server.ts files"
1140
+ : "endpoint files (src/api/*.ts)";
1141
+ function generateAirtableTs(inputLock, runtime = "classic") {
1125
1142
  if (inputLock.tables.length === 0)
1126
1143
  return null;
1127
1144
  const { lock, renames } = normalizeAirtableLockNames(inputLock);
@@ -1134,7 +1151,7 @@ function generateAirtableTs(inputLock) {
1134
1151
  "// Auto-generated by zitejs generate from zite.lock. Do not edit manually.",
1135
1152
  "// Airtable SDK — uses createAirtableClient from zitejs/runtime.",
1136
1153
  "//",
1137
- "// Usage in endpoint files (src/api/*.ts) — one client is exported per table:",
1154
+ `// Usage in ${serverCodeIn(runtime)} — one client is exported per table:`,
1138
1155
  `// import { ${lock.tables[0]?.sdkName ?? "TableName"} } from 'zitejs/integrations';`,
1139
1156
  "//",
1140
1157
  "// Always use 'zitejs/integrations' — never a relative path like",
@@ -1382,12 +1399,12 @@ function findEmailIntegrationId(appConfig, workspaceConfig) {
1382
1399
  * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
1383
1400
  * connected integration's key.
1384
1401
  */
1385
- function generateEmailSdk(integrationId) {
1402
+ function generateEmailSdk(integrationId, runtime = "classic") {
1386
1403
  return [
1387
1404
  "// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.",
1388
1405
  "// Email SDK — sends through the Zite email gateway via the runtime bridge.",
1389
1406
  "//",
1390
- "// Usage in endpoint files (src/api/*.ts):",
1407
+ `// Usage in ${serverCodeIn(runtime)}:`,
1391
1408
  "// import { Email } from 'zitejs/email';",
1392
1409
  "//",
1393
1410
  "// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
@@ -333,6 +333,22 @@ const duplicateIdentifierErrorsIn = (source) => {
333
333
  (0, vitest_1.expect)(syntaxErrorsIn((0, lib_js_1.generateDbTs)(schemaWithTableNamed(name)))).toEqual([]);
334
334
  });
335
335
  });
336
+ (0, vitest_1.describe)('generateDbTs usage notes', () => {
337
+ const schema = { tables: [] };
338
+ // A classic-only workspace regenerates db.ts on every sandbox boot, so a
339
+ // changed comment would land in its next commit and rebuild every app.
340
+ (0, vitest_1.it)('keeps the classic wording in a classic-only workspace', () => {
341
+ const out = (0, lib_js_1.generateDbTs)(schema);
342
+ (0, vitest_1.expect)(out).toContain('// Usage in endpoint files (src/api/*.ts):');
343
+ (0, vitest_1.expect)(out).toContain('// - Load the "zite:sql" skill for full SQL reference');
344
+ });
345
+ (0, vitest_1.it)('names where both runtimes keep server code once a Start app exists', () => {
346
+ const out = (0, lib_js_1.generateDbTs)(schema, { hasStartApps: true });
347
+ (0, vitest_1.expect)(out).toContain("// Usage in server code: a classic app's endpoints (src/api/*.ts), or a Start\n// app's server functions and *.server.ts files:");
348
+ (0, vitest_1.expect)(out).toContain('// - In the Zite editor, the "zite:sql" skill is the full SQL reference');
349
+ (0, vitest_1.expect)(out).not.toContain('Usage in endpoint files');
350
+ });
351
+ });
336
352
  (0, vitest_1.describe)('generateApiTs endpoint file names', () => {
337
353
  // An endpoint filename is the LLM's raw `writeFile` path argument — nothing
338
354
  // validates its characters — and it lands in an import specifier, a comment
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
2
2
  import { createAuthClient } from 'better-auth/react';
3
3
  import { magicLinkClient, inferAdditionalFields, } from 'better-auth/client/plugins';
4
4
  import { USAGE_TOKEN_QUERY_PARAM } from './constants.js';
5
+ import { browserPreviewClaim, PREVIEW_CLAIM_PARAM } from './previewClaim.js';
5
6
  import { getAccessMode } from './config.js';
6
7
  const authClient = createAuthClient({
7
8
  baseURL: '',
@@ -90,6 +91,11 @@ export function loginWithRedirect(opts) {
90
91
  window._ziteUsageToken;
91
92
  if (usageToken)
92
93
  params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
94
+ // A Start app's preview also needs its claim where the editor's frame dropped
95
+ // the cookie, as `loginHref()` sends it. Classic previews never have one.
96
+ const claim = browserPreviewClaim();
97
+ if (claim)
98
+ params.set(PREVIEW_CLAIM_PARAM, claim);
93
99
  const query = params.toString();
94
100
  window.location.href = query ? `/auth/login?${query}` : '/auth/login';
95
101
  }
@@ -0,0 +1,7 @@
1
+ export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
2
+ /**
3
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
4
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
5
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
6
+ */
7
+ export declare const browserPreviewClaim: () => string | undefined;
@@ -0,0 +1,12 @@
1
+ // The host's name for it (apps/zite-host/src/previewClaim.ts).
2
+ export const PREVIEW_CLAIM_PARAM = 'zite_preview';
3
+ let captured;
4
+ /**
5
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
6
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
7
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
8
+ */
9
+ export const browserPreviewClaim = () => {
10
+ captured ??= new URL(window.location.href).searchParams.get(PREVIEW_CLAIM_PARAM);
11
+ return captured ?? undefined;
12
+ };
@@ -1,8 +1,8 @@
1
1
  import { watch } from "fs";
2
- import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, } from "fs";
2
+ import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, rmSync, } from "fs";
3
3
  import { dirname, join, resolve } from "path";
4
4
  import { findWorkspaceRoot, listSourceDirs, } from "../sourceRoots.js";
5
- import { regenerateStartEntries } from "../start/entries.js";
5
+ import { isStartAppDir, regenerateStartEntries, workspaceHasStartApps, } from "../start/entries.js";
6
6
  import { runSync } from "../sync/index.js";
7
7
  import { generateDbTs, generateApiTs, generateBackendWrapperTs, generateAirtableTs, findEmailIntegrationId, generateEmailSdk, generateIntegrationsIndex, } from "../sync/lib.js";
8
8
  import { gettableIntegrations, } from "../integrations/rules.js";
@@ -92,6 +92,7 @@ function getDeclaredEnvVarNames(appDir) {
92
92
  }
93
93
  }
94
94
  function regenerateAppTypedWrappers(appDir) {
95
+ const runtime = isStartAppDir(appDir.path) ? "start" : "classic";
95
96
  const outDir = join(appDir.path, ".zite");
96
97
  mkdirSync(outDir, { recursive: true });
97
98
  // user.ts and auth.ts no longer generated — User type is fixed in zitejs/auth
@@ -102,9 +103,16 @@ function regenerateAppTypedWrappers(appDir) {
102
103
  if (emailIntegrationId) {
103
104
  const intDir = join(outDir, "integrations");
104
105
  mkdirSync(intDir, { recursive: true });
105
- writeFileSync(join(intDir, "email.ts"), generateEmailSdk(emailIntegrationId));
106
+ writeFileSync(join(intDir, "email.ts"), generateEmailSdk(emailIntegrationId, runtime));
106
107
  }
107
- writeFileSync(join(outDir, "backend.ts"), generateBackendWrapperTs(getDeclaredEnvVarNames(appDir)));
108
+ // A Start app's `zitejs/backend` is the package itself. This classic wrapper
109
+ // would only sit in its program with a second, id-only `hasRole`.
110
+ const backendPath = join(outDir, "backend.ts");
111
+ if (runtime === "start") {
112
+ rmSync(backendPath, { force: true });
113
+ return;
114
+ }
115
+ writeFileSync(backendPath, generateBackendWrapperTs(getDeclaredEnvVarNames(appDir)));
108
116
  }
109
117
  function regenerateAppApiTs(appDir) {
110
118
  const apiDir = join(appDir.path, "src", "api");
@@ -153,7 +161,7 @@ function regenerateAppAirtableSdk(appDir) {
153
161
  integrationId,
154
162
  tables: int.idMappings.tables,
155
163
  };
156
- const content = generateAirtableTs(airtableLock);
164
+ const content = generateAirtableTs(airtableLock, isStartAppDir(appDir.path) ? "start" : "classic");
157
165
  if (content) {
158
166
  const outDir = join(appDir.path, ".zite", "integrations");
159
167
  mkdirSync(outDir, { recursive: true });
@@ -185,7 +193,9 @@ export async function runGenerate() {
185
193
  try {
186
194
  if (existsSync("zite.schema.json")) {
187
195
  const schema = JSON.parse(readFileSync("zite.schema.json", "utf-8"));
188
- const dbTs = generateDbTs(schema);
196
+ const dbTs = generateDbTs(schema, {
197
+ hasStartApps: workspaceHasStartApps(),
198
+ });
189
199
  mkdirSync(".zite", { recursive: true });
190
200
  writeFileSync(join(".zite", "db.ts"), dbTs);
191
201
  console.log("Wrote .zite/db.ts");
@@ -272,6 +272,12 @@ export type EmailBlock = {
272
272
  label: string;
273
273
  href: string;
274
274
  alignment?: "left" | "center" | "right";
275
+ /** A hex or `rgb()` color; defaults to the platform's button color. */
276
+ backgroundColor?: string;
277
+ /** A hex or `rgb()` color; defaults to white. */
278
+ textColor?: string;
279
+ /** Corner radius in pixels; defaults to 6. */
280
+ borderRadius?: number;
275
281
  } | {
276
282
  type: "image";
277
283
  src: string;
@@ -1,4 +1,4 @@
1
- import type { SourceDir } from "../sourceRoots.js";
1
+ import { type SourceDir } from "../sourceRoots.js";
2
2
  export declare const START_SERVER_ENTRY = ".zite/server.ts";
3
3
  export declare const START_INSTANCE_ENTRY = ".zite/start.ts";
4
4
  export type StartTarget = "cloudflare" | "node";
@@ -13,6 +13,7 @@ export declare const hasAppStart: (appDir: string) => boolean;
13
13
  /** Writes `file` under `appDir` when its content differs. Returns whether it wrote. */
14
14
  export declare const writeIfChanged: (appDir: string, file: string, content: string) => boolean;
15
15
  export declare const isStartAppDir: (appPath: string) => boolean;
16
+ export declare const workspaceHasStartApps: () => boolean;
16
17
  export declare function regenerateStartEntries(app: SourceDir): void;
17
18
  /** App modules that mention createWorkflow: what the workflow registry imports. Describe decides what each one really exports. */
18
19
  export declare function workflowFiles(appDir: string): string[];
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, relative } from "node:path";
3
+ import { listSourceDirs } from "../sourceRoots.js";
3
4
  export const START_SERVER_ENTRY = ".zite/server.ts";
4
5
  export const START_INSTANCE_ENTRY = ".zite/start.ts";
5
6
  const APP_START_FILES = ["src/start.ts", "src/start.tsx"];
@@ -56,6 +57,7 @@ export const isStartAppDir = (appPath) => {
56
57
  }
57
58
  };
58
59
  const isStartApp = (app) => isStartAppDir(app.path);
60
+ export const workspaceHasStartApps = () => listSourceDirs().some(isStartApp);
59
61
  export function regenerateStartEntries(app) {
60
62
  if (!isStartApp(app))
61
63
  return;
@@ -1,10 +1,7 @@
1
- export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
1
+ import { PREVIEW_CLAIM_PARAM } from "../auth/previewClaim.js";
2
+ export { PREVIEW_CLAIM_PARAM };
2
3
  export declare const PREVIEW_CLAIM_HEADER = "x-zite-preview";
3
- /**
4
- * An editor preview's access, which the host keeps on the URL because the editor's frame may drop its cookie (WebKit
5
- * drops even Partitioned ones). On the server the host hands it over; in the browser it's on the URL the host sent
6
- * the page to, read once, before the router hides it.
7
- */
4
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
8
5
  export declare const previewClaim: () => string | undefined;
9
6
  /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
10
7
  export declare const carryPreviewClaim: (claim: string) => void;
@@ -1,19 +1,10 @@
1
+ import { browserPreviewClaim, PREVIEW_CLAIM_PARAM } from "../auth/previewClaim.js";
1
2
  import { currentHost } from "./host.js";
2
- // The host's names (apps/zite-host/src/previewClaim.ts).
3
- export const PREVIEW_CLAIM_PARAM = "zite_preview";
3
+ export { PREVIEW_CLAIM_PARAM };
4
+ // The host's name (apps/zite-host/src/previewClaim.ts).
4
5
  export const PREVIEW_CLAIM_HEADER = "x-zite-preview";
5
- let captured;
6
- /**
7
- * An editor preview's access, which the host keeps on the URL because the editor's frame may drop its cookie (WebKit
8
- * drops even Partitioned ones). On the server the host hands it over; in the browser it's on the URL the host sent
9
- * the page to, read once, before the router hides it.
10
- */
11
- export const previewClaim = () => {
12
- if (typeof window === "undefined")
13
- return currentHost()?.previewClaim;
14
- captured ??= new URL(window.location.href).searchParams.get(PREVIEW_CLAIM_PARAM);
15
- return captured ?? undefined;
16
- };
6
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
7
+ export const previewClaim = () => typeof window === "undefined" ? currentHost()?.previewClaim : browserPreviewClaim();
17
8
  let carrying = false;
18
9
  /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
19
10
  export const carryPreviewClaim = (claim) => {
@@ -1 +1 @@
1
- export declare const ZITEJS_VERSION = "0.10.0-start.15";
1
+ export declare const ZITEJS_VERSION = "0.10.0-start.17";
@@ -1,2 +1,2 @@
1
1
  // Written by scripts/write-version.mjs from package.json.
2
- export const ZITEJS_VERSION = "0.10.0-start.15";
2
+ export const ZITEJS_VERSION = "0.10.0-start.17";
@@ -3,6 +3,7 @@ export * from "./lib.js";
3
3
  import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, } from "fs";
4
4
  import { join } from "path";
5
5
  import { generateSchema, generateDbTs, generateApiTs, } from "./lib.js";
6
+ import { workspaceHasStartApps } from "../start/entries.js";
6
7
  const DB_ENVIRONMENTS = {
7
8
  production: "https://tables.fillout.com/api/v1",
8
9
  staging: "https://tables.filloutstaging.com/api/v1",
@@ -56,7 +57,7 @@ export async function runSync() {
56
57
  const schema = generateSchema(database, existingSchema);
57
58
  writeFileSync("zite.schema.json", JSON.stringify(schema, null, 2));
58
59
  console.log("Wrote zite.schema.json");
59
- const dbTs = generateDbTs(schema);
60
+ const dbTs = generateDbTs(schema, { hasStartApps: workspaceHasStartApps() });
60
61
  const dotZite = ".zite";
61
62
  mkdirSync(dotZite, { recursive: true });
62
63
  writeFileSync(join(dotZite, "db.ts"), dbTs);
@@ -31,7 +31,14 @@ export declare function generateSchema(database: Database, existingSchema?: Zite
31
31
  * Generate .zite/db.ts purely from ZiteSchema.
32
32
  * Pure function — no external data needed beyond what's in the schema file.
33
33
  */
34
- export declare function generateDbTs(inputSchema: ZiteSchema): string;
34
+ /**
35
+ * `hasStartApps` rewords the usage notes for a workspace where the code using
36
+ * the client isn't only classic endpoints. A classic-only workspace keeps the
37
+ * old wording, so its committed db.ts doesn't change.
38
+ */
39
+ export declare function generateDbTs(inputSchema: ZiteSchema, { hasStartApps }?: {
40
+ hasStartApps?: boolean;
41
+ }): string;
35
42
  export type EndpointFileInfo = {
36
43
  fileName: string;
37
44
  content?: string;
@@ -81,7 +88,7 @@ export declare function normalizeAirtableLockNames(lock: AirtableLock): {
81
88
  lock: AirtableLock;
82
89
  renames: SdkNameRename[];
83
90
  };
84
- export declare function generateAirtableTs(inputLock: AirtableLock): string | null;
91
+ export declare function generateAirtableTs(inputLock: AirtableLock, runtime?: "classic" | "start"): string | null;
85
92
  export declare function generateBackendWrapperTs(envVarNames?: string[]): string;
86
93
  /**
87
94
  * The key of the email integration an app sends through, which is the
@@ -96,7 +103,7 @@ export declare function findEmailIntegrationId(appConfig: unknown, workspaceConf
96
103
  * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
97
104
  * connected integration's key.
98
105
  */
99
- export declare function generateEmailSdk(integrationId: string): string;
106
+ export declare function generateEmailSdk(integrationId: string, runtime?: "classic" | "start"): string;
100
107
  /**
101
108
  * `.zite/integrations/index.ts`: `zitejs/integrations` for one source dir. The
102
109
  * `integrations` client typed by what the dir can see, plus the generated
@@ -476,7 +476,12 @@ function buildLinkTableComments(schema) {
476
476
  * Generate .zite/db.ts purely from ZiteSchema.
477
477
  * Pure function — no external data needed beyond what's in the schema file.
478
478
  */
479
- export function generateDbTs(inputSchema) {
479
+ /**
480
+ * `hasStartApps` rewords the usage notes for a workspace where the code using
481
+ * the client isn't only classic endpoints. A classic-only workspace keeps the
482
+ * old wording, so its committed db.ts doesn't change.
483
+ */
484
+ export function generateDbTs(inputSchema, { hasStartApps = false } = {}) {
480
485
  const lines = [];
481
486
  // Defensive, and idempotent: a schema whose names are already unique and
482
487
  // unreserved normalizes to itself. It matters for a `zite.schema.json`
@@ -493,7 +498,13 @@ export function generateDbTs(inputSchema) {
493
498
  const tables = schema.tables.filter((table) => table.id !== AUTH_USERS_TABLE_ID);
494
499
  lines.push("// Auto-generated by zitejs generate. Do not edit manually.");
495
500
  lines.push("//");
496
- lines.push("// Usage in endpoint files (src/api/*.ts):");
501
+ if (hasStartApps) {
502
+ lines.push("// Usage in server code: a classic app's endpoints (src/api/*.ts), or a Start");
503
+ lines.push("// app's server functions and *.server.ts files:");
504
+ }
505
+ else {
506
+ lines.push("// Usage in endpoint files (src/api/*.ts):");
507
+ }
497
508
  lines.push('// import { zite } from "zitejs/db";');
498
509
  lines.push("//");
499
510
  lines.push('// Always use "zitejs/db" — never use relative paths like "../../.zite/db".');
@@ -548,7 +559,9 @@ export function generateDbTs(inputSchema) {
548
559
  lines.push('// - Auth users are available as "ziteUsers" with id, name, email, firstName, lastName, and image');
549
560
  lines.push("// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL");
550
561
  lines.push("// - SELECT only — use .create/.update/.delete for writes");
551
- lines.push('// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
562
+ lines.push(hasStartApps
563
+ ? '// - In the Zite editor, the "zite:sql" skill is the full SQL reference (formulas, lookups, etc.)'
564
+ : '// - Load the "zite:sql" skill for full SQL reference (formulas, lookups, etc.)');
552
565
  lines.push(...buildLinkTableComments(schema));
553
566
  lines.push("import { createTableClient, createSqlClient, createAuthClient } from 'zitejs/runtime';");
554
567
  lines.push("");
@@ -1106,7 +1119,11 @@ export function normalizeAirtableLockNames(lock) {
1106
1119
  });
1107
1120
  return { lock: { ...lock, tables }, renames };
1108
1121
  }
1109
- export function generateAirtableTs(inputLock) {
1122
+ /** Where an app keeps the server code a generated client is used from. */
1123
+ const serverCodeIn = (runtime) => runtime === "start"
1124
+ ? "server functions and *.server.ts files"
1125
+ : "endpoint files (src/api/*.ts)";
1126
+ export function generateAirtableTs(inputLock, runtime = "classic") {
1110
1127
  if (inputLock.tables.length === 0)
1111
1128
  return null;
1112
1129
  const { lock, renames } = normalizeAirtableLockNames(inputLock);
@@ -1119,7 +1136,7 @@ export function generateAirtableTs(inputLock) {
1119
1136
  "// Auto-generated by zitejs generate from zite.lock. Do not edit manually.",
1120
1137
  "// Airtable SDK — uses createAirtableClient from zitejs/runtime.",
1121
1138
  "//",
1122
- "// Usage in endpoint files (src/api/*.ts) — one client is exported per table:",
1139
+ `// Usage in ${serverCodeIn(runtime)} — one client is exported per table:`,
1123
1140
  `// import { ${lock.tables[0]?.sdkName ?? "TableName"} } from 'zitejs/integrations';`,
1124
1141
  "//",
1125
1142
  "// Always use 'zitejs/integrations' — never a relative path like",
@@ -1367,12 +1384,12 @@ export function findEmailIntegrationId(appConfig, workspaceConfig) {
1367
1384
  * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
1368
1385
  * connected integration's key.
1369
1386
  */
1370
- export function generateEmailSdk(integrationId) {
1387
+ export function generateEmailSdk(integrationId, runtime = "classic") {
1371
1388
  return [
1372
1389
  "// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.",
1373
1390
  "// Email SDK — sends through the Zite email gateway via the runtime bridge.",
1374
1391
  "//",
1375
- "// Usage in endpoint files (src/api/*.ts):",
1392
+ `// Usage in ${serverCodeIn(runtime)}:`,
1376
1393
  "// import { Email } from 'zitejs/email';",
1377
1394
  "//",
1378
1395
  "// Always use 'zitejs/email' — never a relative path like '../../.zite/integrations/email'.",
@@ -328,6 +328,22 @@ describe('generateDbTs table names in comments', () => {
328
328
  expect(syntaxErrorsIn(generateDbTs(schemaWithTableNamed(name)))).toEqual([]);
329
329
  });
330
330
  });
331
+ describe('generateDbTs usage notes', () => {
332
+ const schema = { tables: [] };
333
+ // A classic-only workspace regenerates db.ts on every sandbox boot, so a
334
+ // changed comment would land in its next commit and rebuild every app.
335
+ it('keeps the classic wording in a classic-only workspace', () => {
336
+ const out = generateDbTs(schema);
337
+ expect(out).toContain('// Usage in endpoint files (src/api/*.ts):');
338
+ expect(out).toContain('// - Load the "zite:sql" skill for full SQL reference');
339
+ });
340
+ it('names where both runtimes keep server code once a Start app exists', () => {
341
+ const out = generateDbTs(schema, { hasStartApps: true });
342
+ expect(out).toContain("// Usage in server code: a classic app's endpoints (src/api/*.ts), or a Start\n// app's server functions and *.server.ts files:");
343
+ expect(out).toContain('// - In the Zite editor, the "zite:sql" skill is the full SQL reference');
344
+ expect(out).not.toContain('Usage in endpoint files');
345
+ });
346
+ });
331
347
  describe('generateApiTs endpoint file names', () => {
332
348
  // An endpoint filename is the LLM's raw `writeFile` path argument — nothing
333
349
  // validates its characters — and it lands in an import specifier, a comment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.10.0-start.15",
3
+ "version": "0.10.0-start.17",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,35 +0,0 @@
1
- import type { Problem } from "./problem.js";
2
- type Access = {
3
- kind: string;
4
- roles?: string[];
5
- };
6
- export type CheckedDescription = {
7
- functions: Array<{
8
- id: string;
9
- name?: string;
10
- file?: string;
11
- access: Access;
12
- input?: unknown;
13
- problems: string[];
14
- }>;
15
- routes: Array<{
16
- path: string;
17
- file?: string;
18
- description?: string;
19
- methods: Record<string, Access>;
20
- problems: string[];
21
- }>;
22
- pages?: Array<{
23
- path: string;
24
- file?: string;
25
- }>;
26
- workflows?: Array<{
27
- id: string;
28
- file: string;
29
- problems: string[];
30
- }>;
31
- };
32
- export declare function describedProblems(description: CheckedDescription, { internal }: {
33
- internal: boolean;
34
- }): Problem[];
35
- export {};
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.describedProblems = describedProblems;
4
- // The host, TanStack and Cloudflare answer these before the app does.
5
- const RESERVED_PATHS = [
6
- /^\/_zite/,
7
- /^\/__zite/,
8
- /^\/_serverFn(\/|$)/,
9
- /^\/cdn-cgi(\/|$)/,
10
- /^\/auth(\/|$)/,
11
- /^\/api\/auth(\/|$)/,
12
- /^\/manifest\.webmanifest$/,
13
- ];
14
- const OWNER_INPUTS = ["userId", "ownerId"];
15
- /** `access-missing: no signedIn…`, or a route's `GET: access-missing: …`, as a named problem. */
16
- const describeProblem = (problem, subject, file) => {
17
- const match = /^(?:(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ANY): )?([a-z][a-z-]*): (.*)$/s.exec(problem);
18
- const [, method, rule, message] = match ?? [undefined, undefined, "describe", problem];
19
- return {
20
- rule: rule ?? "describe",
21
- severity: "error",
22
- ...(file && { file }),
23
- message: `${subject}${method ? ` ${method}` : ""}: ${message ?? problem}`,
24
- };
25
- };
26
- const inputProperties = (input) => {
27
- const properties = input?.properties;
28
- return properties && typeof properties === "object" ? Object.keys(properties) : [];
29
- };
30
- function describedProblems(description, { internal }) {
31
- const problems = [];
32
- for (const fn of description.functions) {
33
- const subject = `function ${fn.name ?? fn.id}`;
34
- problems.push(...fn.problems.map((p) => describeProblem(p, subject, fn.file)));
35
- if (internal && fn.access.kind === "anyone") {
36
- problems.push({
37
- rule: "public-in-internal",
38
- severity: "error",
39
- ...(fn.file && { file: fn.file }),
40
- message: `${subject} is a publicFn, and this internal app signs everyone in; make it a signedInFn`,
41
- });
42
- }
43
- const owner = fn.access.kind === "signedIn" && inputProperties(fn.input).find((p) => OWNER_INPUTS.includes(p));
44
- if (owner) {
45
- problems.push({
46
- rule: "owner-from-input",
47
- severity: "warning",
48
- ...(fn.file && { file: fn.file }),
49
- message: `${subject} takes ${owner} as input, which any caller can set; use context.user.id`,
50
- });
51
- }
52
- }
53
- for (const route of description.routes) {
54
- const subject = `route ${route.path}`;
55
- problems.push(...route.problems.map((p) => describeProblem(p, subject, route.file)));
56
- const publicMethods = Object.entries(route.methods).filter(([, access]) => access.kind === "anyone");
57
- if (internal && publicMethods.length > 0) {
58
- problems.push({
59
- rule: "public-in-internal",
60
- severity: "error",
61
- ...(route.file && { file: route.file }),
62
- message: `${subject} lets anyone call ${publicMethods.map(([m]) => m).join(", ")}, and this internal app signs everyone in; use signedIn`,
63
- });
64
- }
65
- if (!route.description) {
66
- problems.push({
67
- rule: "description-missing",
68
- severity: "warning",
69
- ...(route.file && { file: route.file }),
70
- message: `${subject} has no description; add staticData: { description } for the editor`,
71
- });
72
- }
73
- }
74
- for (const workflow of description.workflows ?? []) {
75
- problems.push(...workflow.problems.map((p) => describeProblem(p, `workflow ${workflow.id}`, workflow.file)));
76
- }
77
- const paths = new Map([...description.routes, ...(description.pages ?? [])].map((r) => [r.path, r.file]));
78
- for (const [path, file] of paths) {
79
- if (RESERVED_PATHS.some((reserved) => reserved.test(path))) {
80
- problems.push({
81
- rule: "reserved-path",
82
- severity: "error",
83
- ...(file && { file }),
84
- message: `${path} is the platform's; give the route another path`,
85
- });
86
- }
87
- }
88
- return problems;
89
- }
@@ -1,19 +0,0 @@
1
- type WithProblems = {
2
- problems: string[];
3
- };
4
- type Described = {
5
- functions: Array<WithProblems & {
6
- id: string;
7
- file?: string;
8
- }>;
9
- routes: Array<WithProblems & {
10
- path: string;
11
- }>;
12
- workflows?: Array<WithProblems & {
13
- id: string;
14
- file: string;
15
- }>;
16
- };
17
- /** Every problem in a description, one line each, named by its rule. Any of them fails the build. */
18
- export declare function descriptionProblems(description: Described): string[];
19
- export {};
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.descriptionProblems = descriptionProblems;
4
- /** Every problem in a description, one line each, named by its rule. Any of them fails the build. */
5
- function descriptionProblems(description) {
6
- return [
7
- ...description.functions.flatMap((f) => f.problems.map((p) => `function ${f.id}${f.file ? ` (${f.file})` : ""}: ${p}`)),
8
- ...description.routes.flatMap((r) => r.problems.map((p) => `route ${r.path}: ${p}`)),
9
- ...(description.workflows ?? []).flatMap((w) => w.problems.map((p) => `workflow ${w.id} (${w.file}): ${p}`)),
10
- ];
11
- }
@@ -1,35 +0,0 @@
1
- import type { Problem } from "./problem.js";
2
- type Access = {
3
- kind: string;
4
- roles?: string[];
5
- };
6
- export type CheckedDescription = {
7
- functions: Array<{
8
- id: string;
9
- name?: string;
10
- file?: string;
11
- access: Access;
12
- input?: unknown;
13
- problems: string[];
14
- }>;
15
- routes: Array<{
16
- path: string;
17
- file?: string;
18
- description?: string;
19
- methods: Record<string, Access>;
20
- problems: string[];
21
- }>;
22
- pages?: Array<{
23
- path: string;
24
- file?: string;
25
- }>;
26
- workflows?: Array<{
27
- id: string;
28
- file: string;
29
- problems: string[];
30
- }>;
31
- };
32
- export declare function describedProblems(description: CheckedDescription, { internal }: {
33
- internal: boolean;
34
- }): Problem[];
35
- export {};
@@ -1,86 +0,0 @@
1
- // The host, TanStack and Cloudflare answer these before the app does.
2
- const RESERVED_PATHS = [
3
- /^\/_zite/,
4
- /^\/__zite/,
5
- /^\/_serverFn(\/|$)/,
6
- /^\/cdn-cgi(\/|$)/,
7
- /^\/auth(\/|$)/,
8
- /^\/api\/auth(\/|$)/,
9
- /^\/manifest\.webmanifest$/,
10
- ];
11
- const OWNER_INPUTS = ["userId", "ownerId"];
12
- /** `access-missing: no signedIn…`, or a route's `GET: access-missing: …`, as a named problem. */
13
- const describeProblem = (problem, subject, file) => {
14
- const match = /^(?:(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ANY): )?([a-z][a-z-]*): (.*)$/s.exec(problem);
15
- const [, method, rule, message] = match ?? [undefined, undefined, "describe", problem];
16
- return {
17
- rule: rule ?? "describe",
18
- severity: "error",
19
- ...(file && { file }),
20
- message: `${subject}${method ? ` ${method}` : ""}: ${message ?? problem}`,
21
- };
22
- };
23
- const inputProperties = (input) => {
24
- const properties = input?.properties;
25
- return properties && typeof properties === "object" ? Object.keys(properties) : [];
26
- };
27
- export function describedProblems(description, { internal }) {
28
- const problems = [];
29
- for (const fn of description.functions) {
30
- const subject = `function ${fn.name ?? fn.id}`;
31
- problems.push(...fn.problems.map((p) => describeProblem(p, subject, fn.file)));
32
- if (internal && fn.access.kind === "anyone") {
33
- problems.push({
34
- rule: "public-in-internal",
35
- severity: "error",
36
- ...(fn.file && { file: fn.file }),
37
- message: `${subject} is a publicFn, and this internal app signs everyone in; make it a signedInFn`,
38
- });
39
- }
40
- const owner = fn.access.kind === "signedIn" && inputProperties(fn.input).find((p) => OWNER_INPUTS.includes(p));
41
- if (owner) {
42
- problems.push({
43
- rule: "owner-from-input",
44
- severity: "warning",
45
- ...(fn.file && { file: fn.file }),
46
- message: `${subject} takes ${owner} as input, which any caller can set; use context.user.id`,
47
- });
48
- }
49
- }
50
- for (const route of description.routes) {
51
- const subject = `route ${route.path}`;
52
- problems.push(...route.problems.map((p) => describeProblem(p, subject, route.file)));
53
- const publicMethods = Object.entries(route.methods).filter(([, access]) => access.kind === "anyone");
54
- if (internal && publicMethods.length > 0) {
55
- problems.push({
56
- rule: "public-in-internal",
57
- severity: "error",
58
- ...(route.file && { file: route.file }),
59
- message: `${subject} lets anyone call ${publicMethods.map(([m]) => m).join(", ")}, and this internal app signs everyone in; use signedIn`,
60
- });
61
- }
62
- if (!route.description) {
63
- problems.push({
64
- rule: "description-missing",
65
- severity: "warning",
66
- ...(route.file && { file: route.file }),
67
- message: `${subject} has no description; add staticData: { description } for the editor`,
68
- });
69
- }
70
- }
71
- for (const workflow of description.workflows ?? []) {
72
- problems.push(...workflow.problems.map((p) => describeProblem(p, `workflow ${workflow.id}`, workflow.file)));
73
- }
74
- const paths = new Map([...description.routes, ...(description.pages ?? [])].map((r) => [r.path, r.file]));
75
- for (const [path, file] of paths) {
76
- if (RESERVED_PATHS.some((reserved) => reserved.test(path))) {
77
- problems.push({
78
- rule: "reserved-path",
79
- severity: "error",
80
- ...(file && { file }),
81
- message: `${path} is the platform's; give the route another path`,
82
- });
83
- }
84
- }
85
- return problems;
86
- }