zitejs 0.10.0-start.2 → 0.10.0-start.20

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.
Files changed (171) hide show
  1. package/dist/cjs/auth/index.d.ts +2 -2
  2. package/dist/cjs/auth/index.js +6 -0
  3. package/dist/cjs/auth/index.test.js +30 -0
  4. package/dist/cjs/auth/previewClaim.d.ts +7 -0
  5. package/dist/cjs/auth/previewClaim.js +16 -0
  6. package/dist/cjs/backend/index.d.ts +121 -3
  7. package/dist/cjs/backend/index.test.js +58 -0
  8. package/dist/cjs/bundle/index.d.ts +8 -0
  9. package/dist/cjs/bundle/index.js +9 -8
  10. package/dist/cjs/check/index.d.ts +45 -1
  11. package/dist/cjs/check/index.js +198 -109
  12. package/dist/cjs/check/start/problem.d.ts +11 -0
  13. package/dist/cjs/check/start/problem.js +5 -0
  14. package/dist/cjs/check/start/routeTree.d.ts +9 -0
  15. package/dist/cjs/check/start/routeTree.js +111 -0
  16. package/dist/cjs/check/start/sourceRules.d.ts +8 -0
  17. package/dist/cjs/check/start/sourceRules.js +1110 -0
  18. package/dist/cjs/check/start/tsgo.d.ts +2 -0
  19. package/dist/cjs/check/start/tsgo.js +35 -0
  20. package/dist/cjs/cli.js +1 -1
  21. package/dist/cjs/client/index.d.ts +24 -0
  22. package/dist/cjs/dev/index.js +14 -4
  23. package/dist/cjs/integrations/rules.d.ts +13 -0
  24. package/dist/cjs/integrations/rules.js +29 -0
  25. package/dist/cjs/integrations/rules.test.js +1 -0
  26. package/dist/cjs/internal/appMode.d.ts +3 -0
  27. package/dist/cjs/internal/appMode.js +15 -0
  28. package/dist/cjs/runtime/index.d.ts +13 -13
  29. package/dist/cjs/start/entries.d.ts +10 -4
  30. package/dist/cjs/start/entries.js +23 -6
  31. package/dist/cjs/steps/index.d.ts +78 -0
  32. package/dist/cjs/steps/index.js +507 -0
  33. package/dist/cjs/steps/index.test.d.ts +1 -0
  34. package/dist/cjs/steps/index.test.js +635 -0
  35. package/dist/cjs/sync/index.js +2 -1
  36. package/dist/cjs/sync/lib.d.ts +10 -3
  37. package/dist/cjs/sync/lib.js +35 -21
  38. package/dist/cjs/sync/lib.test.js +106 -36
  39. package/dist/cjs/types/fields.d.ts +8 -1
  40. package/dist/cjs/types/fields.js +7 -1
  41. package/dist/cjs/types/tables.d.ts +16 -0
  42. package/dist/cjs/upload/index.js +12 -2
  43. package/dist/cjs/upload/index.test.js +39 -0
  44. package/dist/cjs/vite/index.js +8 -3
  45. package/dist/cjs/vite/index.test.js +10 -2
  46. package/dist/esm/auth/index.d.ts +2 -2
  47. package/dist/esm/auth/index.js +6 -0
  48. package/dist/esm/auth/index.test.js +30 -0
  49. package/dist/esm/auth/previewClaim.d.ts +7 -0
  50. package/dist/esm/auth/previewClaim.js +12 -0
  51. package/dist/esm/backend/index.d.ts +121 -3
  52. package/dist/esm/backend/index.test.js +58 -0
  53. package/dist/esm/bundle/index.d.ts +8 -0
  54. package/dist/esm/bundle/index.js +8 -8
  55. package/dist/esm/check/index.d.ts +45 -1
  56. package/dist/esm/check/index.js +198 -113
  57. package/dist/esm/check/start/problem.d.ts +11 -0
  58. package/dist/esm/check/start/problem.js +1 -0
  59. package/dist/esm/check/start/routeTree.d.ts +9 -0
  60. package/dist/esm/check/start/routeTree.js +70 -0
  61. package/dist/esm/check/start/sourceRules.d.ts +8 -0
  62. package/dist/esm/check/start/sourceRules.js +1107 -0
  63. package/dist/esm/check/start/tsgo.d.ts +2 -0
  64. package/dist/esm/check/start/tsgo.js +29 -0
  65. package/dist/esm/cli.js +1 -1
  66. package/dist/esm/client/index.d.ts +24 -0
  67. package/dist/esm/dev/index.js +16 -6
  68. package/dist/esm/integrations/rules.d.ts +13 -0
  69. package/dist/esm/integrations/rules.js +29 -0
  70. package/dist/esm/integrations/rules.test.js +1 -0
  71. package/dist/esm/internal/appMode.d.ts +3 -0
  72. package/dist/esm/internal/appMode.js +10 -0
  73. package/dist/esm/runtime/index.d.ts +13 -13
  74. package/dist/esm/start/aiUsage.d.ts +23 -0
  75. package/dist/esm/start/aiUsage.js +146 -0
  76. package/dist/esm/start/airtable/arrayFields.d.ts +10 -0
  77. package/dist/esm/start/airtable/arrayFields.js +30 -0
  78. package/dist/esm/start/airtable/dispatch.d.ts +54 -0
  79. package/dist/esm/start/airtable/dispatch.js +483 -0
  80. package/dist/esm/start/airtable/formulas.d.ts +70 -0
  81. package/dist/esm/start/airtable/formulas.js +258 -0
  82. package/dist/esm/start/airtable/index.d.ts +8 -0
  83. package/dist/esm/start/airtable/index.js +54 -0
  84. package/dist/esm/start/authHooks.d.ts +7 -0
  85. package/dist/esm/start/authHooks.js +10 -0
  86. package/dist/esm/start/authHooksModule.d.ts +1 -0
  87. package/dist/esm/start/authHooksModule.js +3 -0
  88. package/dist/esm/start/clientErrorMessage.test.d.ts +1 -0
  89. package/dist/esm/start/clientErrorMessage.test.js +105 -0
  90. package/dist/esm/start/credentials.d.ts +2 -0
  91. package/dist/esm/start/credentials.js +2 -0
  92. package/dist/esm/start/data/baseRunner.d.ts +92 -0
  93. package/dist/esm/start/data/baseRunner.js +83 -0
  94. package/dist/esm/start/data/dispatch.d.ts +16 -0
  95. package/dist/esm/start/data/dispatch.js +198 -0
  96. package/dist/esm/start/data/index.d.ts +15 -0
  97. package/dist/esm/start/data/index.js +58 -0
  98. package/dist/esm/start/data/sqlNameMappings.d.ts +58 -0
  99. package/dist/esm/start/data/sqlNameMappings.js +92 -0
  100. package/dist/esm/start/data/transformations.d.ts +97 -0
  101. package/dist/esm/start/data/transformations.js +262 -0
  102. package/dist/esm/start/data/types.d.ts +91 -0
  103. package/dist/esm/start/data/types.js +14 -0
  104. package/dist/esm/start/describe.d.ts +35 -5
  105. package/dist/esm/start/describe.js +74 -22
  106. package/dist/esm/start/entries.d.ts +10 -4
  107. package/dist/esm/start/entries.js +21 -5
  108. package/dist/esm/start/errors.d.ts +63 -0
  109. package/dist/esm/start/errors.js +146 -0
  110. package/dist/esm/start/errors.test.d.ts +1 -0
  111. package/dist/esm/start/errors.test.js +23 -0
  112. package/dist/esm/start/factories.test-d.d.ts +1 -0
  113. package/dist/esm/start/factories.test-d.js +20 -0
  114. package/dist/esm/start/index.d.ts +32 -27
  115. package/dist/esm/start/index.js +77 -47
  116. package/dist/esm/start/instance.d.ts +4 -4
  117. package/dist/esm/start/instance.js +54 -11
  118. package/dist/esm/start/outbound.d.ts +11 -0
  119. package/dist/esm/start/outbound.js +398 -0
  120. package/dist/esm/start/previewClaim.d.ts +7 -0
  121. package/dist/esm/start/previewClaim.js +23 -0
  122. package/dist/esm/start/problems.js +1 -1
  123. package/dist/esm/start/quiet.d.ts +2 -0
  124. package/dist/esm/start/quiet.js +27 -0
  125. package/dist/esm/start/redactSecrets.d.ts +15 -0
  126. package/dist/esm/start/redactSecrets.js +154 -0
  127. package/dist/esm/start/redactSecrets.test.d.ts +1 -0
  128. package/dist/esm/start/redactSecrets.test.js +151 -0
  129. package/dist/esm/start/registration.d.ts +13 -0
  130. package/dist/esm/start/registration.js +21 -0
  131. package/dist/esm/start/registrationHash.d.ts +22 -0
  132. package/dist/esm/start/registrationHash.js +470 -0
  133. package/dist/esm/start/router.d.ts +18 -4
  134. package/dist/esm/start/router.js +134 -11
  135. package/dist/esm/start/runLog.d.ts +7 -4
  136. package/dist/esm/start/runLog.js +64 -6
  137. package/dist/esm/start/scope.d.ts +2 -2
  138. package/dist/esm/start/server.d.ts +40 -36
  139. package/dist/esm/start/server.js +320 -48
  140. package/dist/esm/start/steps.d.ts +28 -0
  141. package/dist/esm/start/steps.js +97 -0
  142. package/dist/esm/start/types.d.ts +178 -5
  143. package/dist/esm/start/version.d.ts +1 -0
  144. package/dist/esm/start/version.js +2 -0
  145. package/dist/esm/start/vite.js +88 -11
  146. package/dist/esm/start/worker.d.ts +6 -0
  147. package/dist/esm/start/worker.js +12 -0
  148. package/dist/esm/start/workflow.d.ts +42 -12
  149. package/dist/esm/start/workflow.js +3 -3
  150. package/dist/esm/start/workflow.test-d.js +41 -8
  151. package/dist/esm/start/workflowModules.js +1 -1
  152. package/dist/esm/start/workflowRun.d.ts +21 -8
  153. package/dist/esm/start/workflowRun.js +29 -8
  154. package/dist/esm/steps/index.d.ts +78 -0
  155. package/dist/esm/steps/index.js +502 -0
  156. package/dist/esm/steps/index.test.d.ts +1 -0
  157. package/dist/esm/steps/index.test.js +633 -0
  158. package/dist/esm/sync/index.js +2 -1
  159. package/dist/esm/sync/lib.d.ts +10 -3
  160. package/dist/esm/sync/lib.js +35 -21
  161. package/dist/esm/sync/lib.test.js +106 -36
  162. package/dist/esm/types/fields.d.ts +8 -1
  163. package/dist/esm/types/fields.js +6 -0
  164. package/dist/esm/types/tables.d.ts +16 -0
  165. package/dist/esm/upload/index.js +12 -2
  166. package/dist/esm/upload/index.test.js +39 -0
  167. package/dist/esm/vite/index.js +8 -3
  168. package/dist/esm/vite/index.test.js +10 -2
  169. package/package.json +37 -16
  170. package/dist/cjs/start/problems.d.ts +0 -19
  171. package/dist/cjs/start/problems.js +0 -11
@@ -0,0 +1,2 @@
1
+ /** tsgo's launcher: the app's own, walking up from it as Node does, else the global install beside this node. */
2
+ export declare function findTsgo(appDir: string): string | undefined;
@@ -0,0 +1,29 @@
1
+ // TypeScript's native compiler, as the platform's checks run it, found the same
2
+ // way every time: never from PATH, so a check here and one in the sandbox use
3
+ // the same compiler.
4
+ import { existsSync, readFileSync } from "node:fs";
5
+ import { createRequire } from "node:module";
6
+ import path from "node:path";
7
+ const PACKAGE = "@typescript/native-preview";
8
+ // Where `npm install -g` put it for the node running this: the sandbox image's.
9
+ const globalRoot = () => process.env.npm_config_prefix
10
+ ? path.join(process.env.npm_config_prefix, process.platform === "win32" ? "node_modules" : "lib/node_modules")
11
+ : process.platform === "win32"
12
+ ? path.join(path.dirname(process.execPath), "node_modules")
13
+ : path.join(path.dirname(path.dirname(process.execPath)), "lib", "node_modules");
14
+ /** tsgo's launcher: the app's own, walking up from it as Node does, else the global install beside this node. */
15
+ export function findTsgo(appDir) {
16
+ let manifest;
17
+ try {
18
+ manifest = createRequire(path.join(path.resolve(appDir), "package.json")).resolve(`${PACKAGE}/package.json`);
19
+ }
20
+ catch {
21
+ const global = path.join(globalRoot(), PACKAGE, "package.json");
22
+ manifest = existsSync(global) ? global : undefined;
23
+ }
24
+ if (!manifest)
25
+ return undefined;
26
+ const { bin } = JSON.parse(readFileSync(manifest, "utf-8"));
27
+ const launcher = typeof bin === "string" ? bin : bin?.tsgo;
28
+ return launcher ? path.join(path.dirname(manifest), launcher) : undefined;
29
+ }
package/dist/esm/cli.js CHANGED
@@ -45,7 +45,7 @@ async function main() {
45
45
  console.error(' sync Generate .zite/db.ts from database schema (single-app)');
46
46
  console.error(' dev Run sync then watch for changes (like npx convex dev)');
47
47
  console.error(' generate Regenerate every app and automation .zite/ (monorepo)');
48
- console.error(' check Run tsc --noEmit (and vite build where there is one) for every app and automation');
48
+ console.error(' check Typecheck and build every app and automation; a Start app is typechecked with tsgo against its regenerated route tree and its source checked by rule (--json for a report)');
49
49
  console.error(' bundle Bundle endpoints (src/api/*.ts, or an automation\'s src/index.ts) for cloudflare-lambda');
50
50
  console.error(' describe Print what a built TanStack Start app declares: functions, routes, access');
51
51
  process.exit(1);
@@ -275,6 +275,10 @@ export declare class Zite {
275
275
  sortEnabled?: boolean | undefined;
276
276
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
277
277
  };
278
+ } | {
279
+ name: string;
280
+ type: "created_by";
281
+ template: globalThis.Record<string, never>;
278
282
  } | {
279
283
  name: string;
280
284
  type: "updated_by";
@@ -488,6 +492,10 @@ export declare class Zite {
488
492
  sortEnabled?: boolean | undefined;
489
493
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
490
494
  };
495
+ } | {
496
+ name: string;
497
+ type: "created_by";
498
+ template: globalThis.Record<string, never>;
491
499
  } | {
492
500
  name: string;
493
501
  type: "updated_by";
@@ -711,6 +719,10 @@ export declare class Zite {
711
719
  sortEnabled?: boolean | undefined;
712
720
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
713
721
  };
722
+ } | {
723
+ name: string;
724
+ type: "created_by";
725
+ template: globalThis.Record<string, never>;
714
726
  } | {
715
727
  name: string;
716
728
  type: "updated_by";
@@ -937,6 +949,10 @@ export declare class Zite {
937
949
  sortEnabled?: boolean | undefined;
938
950
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
939
951
  };
952
+ } | {
953
+ name: string;
954
+ type: "created_by";
955
+ template: globalThis.Record<string, never>;
940
956
  } | {
941
957
  name: string;
942
958
  type: "updated_by";
@@ -1171,6 +1187,10 @@ export declare class Zite {
1171
1187
  sortEnabled?: boolean | undefined;
1172
1188
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
1173
1189
  };
1190
+ } | {
1191
+ name: string;
1192
+ type: "created_by";
1193
+ template: globalThis.Record<string, never>;
1174
1194
  } | {
1175
1195
  name: string;
1176
1196
  type: "updated_by";
@@ -1406,6 +1426,10 @@ export declare class Zite {
1406
1426
  sortEnabled?: boolean | undefined;
1407
1427
  resultType?: "number" | "boolean" | "date" | "array" | "text" | undefined;
1408
1428
  };
1429
+ } | {
1430
+ name: string;
1431
+ type: "created_by";
1432
+ template: globalThis.Record<string, never>;
1409
1433
  } | {
1410
1434
  name: string;
1411
1435
  type: "updated_by";
@@ -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");
@@ -38,11 +38,24 @@ declare const FIELDS_BY_TYPE: {
38
38
  jira: readonly string[];
39
39
  typeform: readonly string[];
40
40
  apollo: readonly string[];
41
+ clay: readonly string[];
41
42
  attio: readonly string[];
42
43
  granola: readonly string[];
44
+ clickup: readonly string[];
43
45
  dropbox: readonly string[];
46
+ zendesk: readonly string[];
47
+ smartsheet: readonly string[];
44
48
  amazonS3: readonly string[];
45
49
  snowflake: readonly string[];
50
+ databricks: readonly string[];
51
+ confluence: readonly string[];
52
+ pipedrive: readonly string[];
53
+ shopify: readonly string[];
54
+ sharepoint: readonly string[];
55
+ excel: readonly string[];
56
+ x: readonly string[];
57
+ zoomMeetings: readonly string[];
58
+ smartsuite: readonly string[];
46
59
  };
47
60
  /** A service type `integrations.get` serves: one used through its npm package with a token. */
48
61
  export type CredentialServiceType = keyof typeof FIELDS_BY_TYPE;
@@ -44,15 +44,43 @@ const FIELDS_BY_TYPE = {
44
44
  jira: extras("cloudId", "siteUrl"),
45
45
  typeform: extras(),
46
46
  apollo: extras(),
47
+ clay: extras(),
47
48
  attio: extras(),
48
49
  granola: extras(),
50
+ clickup: extras(),
49
51
  dropbox: extras(),
52
+ // Every path is https://{subdomain}.zendesk.com/api/v2/..., and a token is
53
+ // only valid on the account it was issued for, so the subdomain travels with
54
+ // it rather than being configured per app.
55
+ zendesk: extras("subdomain"),
56
+ // Smartsheet's US, EU, AU and Gov regions are separate, and a token is only
57
+ // valid on its own region's host, so the host travels with it.
58
+ smartsheet: extras("apiBaseUrl"),
50
59
  // The IAM key alone reaches nothing: every call needs the region and the
51
60
  // bucket, and S3-compatible providers need the endpoint too.
52
61
  amazonS3: extras("keyId", "region", "bucket", "endpoint", "pathPrefix"),
53
62
  // The SQL API lives on each account's own host, and the token is pinned to
54
63
  // one role; the warehouse is optional and falls back to the user's default.
55
64
  snowflake: extras("accountUrl", "role", "warehouse"),
65
+ // A statement is addressed by workspace host and SQL warehouse, and the token
66
+ // derives neither.
67
+ databricks: extras("host", "warehouseId"),
68
+ // Cloud Confluence is addressed through api.atlassian.com by cloud id, the
69
+ // same as Jira; the site URL is only for links a human will click.
70
+ confluence: extras("cloudId", "siteUrl"),
71
+ // OAuth returns a per-company api_domain alongside the token, so there is no
72
+ // one host to call.
73
+ pipedrive: extras("apiBaseUrl"),
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
+ // which installs predating those scopes do not have.
77
+ shopify: extras("shopDomain", "apiBaseUrl", "storefrontApiUrl", "storefrontAccessToken"),
78
+ sharepoint: extras(),
79
+ excel: extras(),
80
+ x: extras(),
81
+ zoomMeetings: extras(),
82
+ // Every request names the workspace in an Account-Id header beside the key.
83
+ smartsuite: extras("workspaceId"),
56
84
  };
57
85
  /** Per service type: `accessToken`, then its extra labels sorted (Salesforce `instanceUrl`). */
58
86
  export const CREDENTIAL_FIELDS = FIELDS_BY_TYPE;
@@ -65,6 +93,7 @@ export const OPTIONAL_CREDENTIAL_FIELDS = {
65
93
  // Only S3-compatible providers set an endpoint, and a prefix is opt-in.
66
94
  amazonS3: ["endpoint", "pathPrefix"],
67
95
  snowflake: ["warehouse"],
96
+ shopify: ["storefrontApiUrl", "storefrontAccessToken"],
68
97
  };
69
98
  /**
70
99
  * Types the runtime never serves: those with a generated client (Airtable, email,
@@ -16,6 +16,7 @@ describe("CREDENTIAL_FIELDS", () => {
16
16
  ]);
17
17
  expect(CREDENTIAL_FIELDS.jira).toEqual(["accessToken", "cloudId", "siteUrl"]);
18
18
  expect(CREDENTIAL_FIELDS.granola).toEqual(["accessToken"]);
19
+ expect(CREDENTIAL_FIELDS.smartsheet).toEqual(["accessToken", "apiBaseUrl"]);
19
20
  });
20
21
  it("has no type the runtime never serves", () => {
21
22
  for (const type of NON_CREDENTIAL_SERVICE_TYPES) {
@@ -0,0 +1,3 @@
1
+ export declare const keepRenderedMode: (mode: string | undefined) => void;
2
+ /** The mode the platform served this request or page in; undefined outside a Start app. */
3
+ export declare const platformMode: () => string | undefined;
@@ -0,0 +1,10 @@
1
+ // Classic's upload client reads this too, so it imports nothing of Start: the
2
+ // request's host comes through the key src/start/host.ts reads it under.
3
+ const HOST_STORE_KEY = Symbol.for("zitejs:host-context");
4
+ // What a Start page was rendered with, kept in the browser when it hydrates.
5
+ const RENDERED_MODE = Symbol.for("zitejs:rendered-mode");
6
+ export const keepRenderedMode = (mode) => {
7
+ globalThis[RENDERED_MODE] = mode;
8
+ };
9
+ /** The mode the platform served this request or page in; undefined outside a Start app. */
10
+ export const platformMode = () => globalThis[HOST_STORE_KEY]?.getStore()?.mode ?? globalThis[RENDERED_MODE];
@@ -45,8 +45,8 @@ export type FilterOperators<V> = FilterCondition<V> | V;
45
45
  * NOT `equals`, despite `formulas.ts` having a `case 'equals'`: that case only
46
46
  * fires for the bare-value shorthand. `equals` is absent from
47
47
  * `WhereConditionOperators`, so `isNestedCondition` doesn't recognize the
48
- * object, the whole `{ equals: … }` is stringified as the operand, and Airtable
49
- * 422s on `{Email}=[object Object]`.
48
+ * object, the whole `{ equals: … }` is taken as the value, and the filter
49
+ * fails.
50
50
  *
51
51
  * One operator per field on this path — `formulas.ts` reads
52
52
  * `Object.keys(condition)[0]` and drops the rest, unlike the Zite DB filter
@@ -85,20 +85,14 @@ export type FieldSelector<T> = Extract<keyof T, string> | (string & {});
85
85
  export interface TableFindAllOptions<T = Record<string, unknown>> {
86
86
  limit?: number;
87
87
  offset?: number;
88
- /**
89
- * IGNORED on the table path. `DatabasesFindAllParamsSchema` has no `sort`
90
- * key, so zod strips it before either dispatch, and neither destructures it.
91
- * Kept in the type because removing it would only turn a silent no-op into a
92
- * compile error for apps already passing it — the real fix is to forward it.
93
- * It DOES work on `zite.auth.findAllUsers`, which is dispatched separately.
94
- */
88
+ /** `[{ field, direction }]`, applied in order. */
95
89
  sort?: unknown[];
96
90
  filters?: RecordFilters<T>;
97
91
  /**
98
- * The nested filter format (`filters` is the legacy flat one). IGNORED here
99
- * for the same reason as `sort` — not in `DatabasesFindAllParamsSchema`, so
100
- * zod strips it — but kept so code already passing it still compiles. It IS
101
- * honored by `zite.auth.findAllUsers`.
92
+ * The nested filter format (`filters` is the legacy flat one). Ignored here:
93
+ * `DatabasesFindAllParamsSchema` has no `filter`, so zod strips it, but it's
94
+ * kept so code already passing it still compiles. `zite.auth.findAllUsers`
95
+ * honors it.
102
96
  */
103
97
  filter?: unknown;
104
98
  fields?: Array<FieldSelector<T>>;
@@ -272,6 +266,12 @@ export type EmailBlock = {
272
266
  label: string;
273
267
  href: string;
274
268
  alignment?: "left" | "center" | "right";
269
+ /** A hex or `rgb()` color; defaults to the platform's button color. */
270
+ backgroundColor?: string;
271
+ /** A hex or `rgb()` color; defaults to white. */
272
+ textColor?: string;
273
+ /** Corner radius in pixels; defaults to 6. */
274
+ borderRadius?: number;
275
275
  } | {
276
276
  type: "image";
277
277
  src: string;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * What a call on an org's own AI key used, read from the provider's answer as
3
+ * classic's runtime reads it. For analytics only: the org pays the provider.
4
+ * OpenAI and Anthropic; the host meters Zite's own key itself.
5
+ */
6
+ export type AiProvider = "openai" | "anthropic";
7
+ export type AiUsageRecord = {
8
+ provider: AiProvider;
9
+ model?: string;
10
+ inputTokens?: number;
11
+ outputTokens?: number;
12
+ cachedReadInputTokens?: number;
13
+ cacheCreationInputTokens?: number;
14
+ isStreaming?: true;
15
+ };
16
+ export declare const AI_USAGE_HOSTS: Record<string, AiProvider>;
17
+ /** As classic: an OpenAI chat stream reports its usage only when asked to. The body to send instead, if any. */
18
+ export declare const withStreamUsage: (url: URL, method: string, body: unknown) => string | undefined;
19
+ /** The response to hand the app, and its usage once read; a stream is split so the app reads one copy as it arrives. */
20
+ export declare const meterAiResponse: (provider: AiProvider, response: Response) => {
21
+ response: Response;
22
+ usage: Promise<AiUsageRecord | undefined>;
23
+ };
@@ -0,0 +1,146 @@
1
+ /**
2
+ * What a call on an org's own AI key used, read from the provider's answer as
3
+ * classic's runtime reads it. For analytics only: the org pays the provider.
4
+ * OpenAI and Anthropic; the host meters Zite's own key itself.
5
+ */
6
+ export const AI_USAGE_HOSTS = {
7
+ "api.openai.com": "openai",
8
+ "api.anthropic.com": "anthropic",
9
+ };
10
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
11
+ const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
12
+ /** As classic: an OpenAI chat stream reports its usage only when asked to. The body to send instead, if any. */
13
+ export const withStreamUsage = (url, method, body) => {
14
+ if (method !== "POST" || typeof body !== "string" || !url.pathname.endsWith("/chat/completions"))
15
+ return undefined;
16
+ try {
17
+ const json = JSON.parse(body);
18
+ if (!isRecord(json) || json.stream !== true)
19
+ return undefined;
20
+ const options = isRecord(json.stream_options) ? json.stream_options : {};
21
+ if (options.include_usage === true)
22
+ return undefined;
23
+ return JSON.stringify({ ...json, stream_options: { ...options, include_usage: true } });
24
+ }
25
+ catch {
26
+ return undefined;
27
+ }
28
+ };
29
+ // OpenAI counts cached tokens inside its input; classic takes them apart.
30
+ const tokensFromJson = (provider, body) => {
31
+ const tokens = {};
32
+ if (!isRecord(body))
33
+ return tokens;
34
+ if (provider === "openai") {
35
+ const source = isRecord(body.response) ? body.response : body;
36
+ if (typeof source.model === "string")
37
+ tokens.model = source.model;
38
+ const usage = isRecord(source.usage) ? source.usage : undefined;
39
+ if (!usage)
40
+ return tokens;
41
+ const details = (name) => (isRecord(usage[name]) ? usage[name] : {});
42
+ const cached = details("prompt_tokens_details").cached_tokens ?? details("input_tokens_details").cached_tokens;
43
+ const input = usage.prompt_tokens ?? usage.input_tokens;
44
+ const output = usage.completion_tokens ?? usage.output_tokens;
45
+ if (isNumber(input))
46
+ tokens.inputTokens = input - (isNumber(cached) ? cached : 0);
47
+ if (isNumber(output))
48
+ tokens.outputTokens = output;
49
+ if (isNumber(cached))
50
+ tokens.cachedReadInputTokens = cached;
51
+ return tokens;
52
+ }
53
+ // A stream splits these: message_start has the input, message_delta the running output.
54
+ const message = isRecord(body.message) ? body.message : body;
55
+ if (typeof message.model === "string")
56
+ tokens.model = message.model;
57
+ const usage = isRecord(message.usage) ? message.usage : isRecord(body.usage) ? body.usage : undefined;
58
+ if (!usage)
59
+ return tokens;
60
+ if (isNumber(usage.input_tokens))
61
+ tokens.inputTokens = usage.input_tokens;
62
+ if (isNumber(usage.output_tokens))
63
+ tokens.outputTokens = usage.output_tokens;
64
+ if (isNumber(usage.cache_read_input_tokens))
65
+ tokens.cachedReadInputTokens = usage.cache_read_input_tokens;
66
+ if (isNumber(usage.cache_creation_input_tokens))
67
+ tokens.cacheCreationInputTokens = usage.cache_creation_input_tokens;
68
+ return tokens;
69
+ };
70
+ // Later readings win: Anthropic's output is cumulative, OpenAI's usage comes last.
71
+ const merge = (into, next) => ({
72
+ model: next.model ?? into.model,
73
+ inputTokens: next.inputTokens ?? into.inputTokens,
74
+ outputTokens: next.outputTokens ?? into.outputTokens,
75
+ cachedReadInputTokens: next.cachedReadInputTokens ?? into.cachedReadInputTokens,
76
+ cacheCreationInputTokens: next.cacheCreationInputTokens ?? into.cacheCreationInputTokens,
77
+ });
78
+ const MAX_PENDING_LINE = 1024 * 1024;
79
+ const tokensFromStream = async (provider, stream) => {
80
+ const reader = stream.getReader();
81
+ const decoder = new TextDecoder();
82
+ let pending = "";
83
+ let tokens = {};
84
+ const readLine = (line) => {
85
+ if (!line.startsWith("data:"))
86
+ return;
87
+ const payload = line.slice(5).trim();
88
+ if (!payload || payload === "[DONE]")
89
+ return;
90
+ try {
91
+ tokens = merge(tokens, tokensFromJson(provider, JSON.parse(payload)));
92
+ }
93
+ catch {
94
+ // Not JSON; nothing to count.
95
+ }
96
+ };
97
+ try {
98
+ for (;;) {
99
+ const { done, value } = await reader.read();
100
+ if (done)
101
+ break;
102
+ pending += decoder.decode(value, { stream: true });
103
+ const lines = pending.split("\n");
104
+ pending = lines.pop() ?? "";
105
+ if (pending.length > MAX_PENDING_LINE)
106
+ pending = "";
107
+ lines.forEach(readLine);
108
+ }
109
+ readLine(pending);
110
+ }
111
+ catch {
112
+ // What was read before the stream broke still counts.
113
+ }
114
+ return tokens;
115
+ };
116
+ const counted = (tokens) => tokens.inputTokens !== undefined || tokens.outputTokens !== undefined;
117
+ const usageOf = (provider, tokens, streaming) => counted(tokens)
118
+ ? {
119
+ provider,
120
+ ...Object.fromEntries(Object.entries(tokens).filter(([, value]) => value !== undefined)),
121
+ ...(streaming && { isStreaming: true }),
122
+ }
123
+ : undefined;
124
+ /** The response to hand the app, and its usage once read; a stream is split so the app reads one copy as it arrives. */
125
+ export const meterAiResponse = (provider, response) => {
126
+ const type = response.headers.get("content-type") ?? "";
127
+ if (!response.ok || !response.body)
128
+ return { response, usage: Promise.resolve(undefined) };
129
+ if (type.includes("text/event-stream")) {
130
+ const [forApp, forUs] = response.body.tee();
131
+ return {
132
+ response: new Response(forApp, response),
133
+ usage: tokensFromStream(provider, forUs).then((tokens) => usageOf(provider, tokens, true)),
134
+ };
135
+ }
136
+ if (!type.includes("json"))
137
+ return { response, usage: Promise.resolve(undefined) };
138
+ return {
139
+ response,
140
+ usage: response
141
+ .clone()
142
+ .json()
143
+ .then((json) => usageOf(provider, tokensFromJson(provider, json), false))
144
+ .catch(() => undefined),
145
+ };
146
+ };
@@ -0,0 +1,10 @@
1
+ export type AirtableFieldShape = {
2
+ type: string;
3
+ options?: unknown;
4
+ };
5
+ export declare const isArrayValuedAirtableField: (field: AirtableFieldShape) => boolean;
6
+ export declare const airtableEqualsFormula: ({ field, fieldName, value, }: {
7
+ field: AirtableFieldShape;
8
+ fieldName: string;
9
+ value: string;
10
+ }) => string;
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod';
2
+ const ARRAY_VALUED_AIRTABLE_FIELD_TYPES = new Set([
3
+ 'multipleLookupValues',
4
+ 'multipleSelects',
5
+ 'multipleRecordLinks',
6
+ 'multipleCollaborators',
7
+ 'multipleAttachments',
8
+ ]);
9
+ const resultTypeOptionsSchema = z.object({
10
+ result: z.object({ type: z.string().optional() }).optional(),
11
+ });
12
+ export const isArrayValuedAirtableField = (field) => {
13
+ if (field.type === 'formula' || field.type === 'rollup') {
14
+ const resultType = resultTypeOptionsSchema.safeParse(field.options).data
15
+ ?.result?.type;
16
+ return resultType
17
+ ? ARRAY_VALUED_AIRTABLE_FIELD_TYPES.has(resultType)
18
+ : false;
19
+ }
20
+ return ARRAY_VALUED_AIRTABLE_FIELD_TYPES.has(field.type);
21
+ };
22
+ const ELEMENT_SEPARATOR = ', ';
23
+ export const airtableEqualsFormula = ({ field, fieldName, value, }) => {
24
+ if (!isArrayValuedAirtableField(field)) {
25
+ return `${fieldName}=${value}`;
26
+ }
27
+ const needle = `"${ELEMENT_SEPARATOR}" & ${value} & "${ELEMENT_SEPARATOR}"`;
28
+ const haystack = `"${ELEMENT_SEPARATOR}" & ARRAYJOIN(${fieldName}) & "${ELEMENT_SEPARATOR}"`;
29
+ return `SEARCH(${needle}, ${haystack}) != ""`;
30
+ };
@@ -0,0 +1,54 @@
1
+ /** As `@fillout/zite`'s `IntegrationFieldMappingType`, from zite.lock. */
2
+ export type AirtableFieldMapping = {
3
+ mapping: {
4
+ sdkName: string;
5
+ };
6
+ fieldType?: string;
7
+ fieldName?: string;
8
+ fieldOptions?: Record<string, unknown>;
9
+ };
10
+ export type AirtableFieldMappings = Record<string, AirtableFieldMapping>;
11
+ export type AirtableNameMappings = {
12
+ bases: Record<string, {
13
+ mapping: {
14
+ sdkName: string;
15
+ };
16
+ tables: Record<string, {
17
+ mapping: {
18
+ sdkName: string;
19
+ };
20
+ primaryFieldId?: string;
21
+ fields: AirtableFieldMappings;
22
+ }>;
23
+ }>;
24
+ };
25
+ /** An app's Airtable integration as its build declares it. */
26
+ export type AirtableSettings = {
27
+ baseId: string;
28
+ nameMappings: AirtableNameMappings | null;
29
+ };
30
+ /** Answers one Airtable request; the platform puts the connection's token on it. */
31
+ export type AirtableFetch = (path: string, init: {
32
+ method: string;
33
+ body?: unknown;
34
+ }) => Promise<Response>;
35
+ export type AirtableContext = {
36
+ settings: AirtableSettings;
37
+ fetch: AirtableFetch;
38
+ /** One request's reads, so the same read twice in a request goes to Airtable once. */
39
+ reads?: Map<string, Promise<unknown>>;
40
+ sleep?: (ms: number) => Promise<void>;
41
+ };
42
+ /** The npm SDK's error, whose shape apps (and the goldens) see: not an `Error`. */
43
+ export declare class AirtableError {
44
+ error: string;
45
+ message: string;
46
+ statusCode: number;
47
+ constructor(error: string, message: string, statusCode: number);
48
+ toString(): string;
49
+ }
50
+ export declare function airtableRecordToSdkNames(record: Record<string, any> | undefined, fieldMappings: AirtableFieldMappings | undefined): Record<string, any> | undefined;
51
+ /** A Duration cell (seconds) as HH:mm:ss, keeping seconds and fractions (ZIT-3889). */
52
+ export declare function formatAirtableDuration(durationSeconds: number): string;
53
+ /** One Airtable table call, as classic's dispatch runs it. */
54
+ export declare function executeAirtableCall(context: AirtableContext, methodName: string, params: any): Promise<any>;