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
@@ -83,6 +83,7 @@ const FIELD_TYPE_MAP = {
83
83
  formula: "any",
84
84
  created_at: "string",
85
85
  updated_at: "string",
86
+ created_by: "string",
86
87
  updated_by: "string",
87
88
  };
88
89
  /**
@@ -108,7 +109,7 @@ const FIELD_INPUT_TYPE_MAP = {
108
109
  * rather than typed and then refused at runtime.
109
110
  *
110
111
  * Mirrors `COMPUTED_FIELD_TYPES` in the product's own `shared/bases/fields`.
111
- * The first six are rejected by `createRecordDataSchema` — each has a
112
+ * The first seven are rejected by `createRecordDataSchema` — each has a
112
113
  * `refine(val => val == null)`, so a non-null write errors (null is a no-op
113
114
  * clear). `created_at` / `updated_at` are refused differently: they have no
114
115
  * column at all, so a write is silently dropped, which is the worse outcome to
@@ -120,6 +121,7 @@ const READ_ONLY_FIELD_TYPES = new Set([
120
121
  "source",
121
122
  "formula",
122
123
  "autonumber",
124
+ "created_by",
123
125
  "updated_by",
124
126
  "created_at",
125
127
  "updated_at",
@@ -260,13 +262,8 @@ function fieldJsdoc(schemaField, table, schema) {
260
262
  const parts = [];
261
263
  if (table.primaryFieldId === schemaField.id)
262
264
  parts.push("Primary field");
263
- if (def.type === "created_at" ||
264
- def.type === "updated_at" ||
265
- def.type === "lookup" ||
266
- def.type === "formula" ||
267
- def.type === "autonumber") {
265
+ if (READ_ONLY_FIELD_TYPES.has(def.type))
268
266
  parts.push("Read-only");
269
- }
270
267
  if (def.type === "linked_record") {
271
268
  const tpl = def.template;
272
269
  if (tpl.tableId) {
@@ -494,7 +491,12 @@ function buildLinkTableComments(schema) {
494
491
  * Generate .zite/db.ts purely from ZiteSchema.
495
492
  * Pure function — no external data needed beyond what's in the schema file.
496
493
  */
497
- 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 } = {}) {
498
500
  const lines = [];
499
501
  // Defensive, and idempotent: a schema whose names are already unique and
500
502
  // unreserved normalizes to itself. It matters for a `zite.schema.json`
@@ -511,7 +513,13 @@ function generateDbTs(inputSchema) {
511
513
  const tables = schema.tables.filter((table) => table.id !== AUTH_USERS_TABLE_ID);
512
514
  lines.push("// Auto-generated by zitejs generate. Do not edit manually.");
513
515
  lines.push("//");
514
- 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
+ }
515
523
  lines.push('// import { zite } from "zitejs/db";');
516
524
  lines.push("//");
517
525
  lines.push('// Always use "zitejs/db" — never use relative paths like "../../.zite/db".');
@@ -522,9 +530,9 @@ function generateDbTs(inputSchema) {
522
530
  lines.push("// filters: { fieldName: value } for equality, or { fieldName: { <op>: value } }");
523
531
  lines.push("// operators: contains, not, in, notIn, lt, lte, gt, gte");
524
532
  lines.push('// `not: null` means "is set". An empty `in: []` matches nothing; an', "// empty `notIn: []` applies no filter.");
525
- lines.push("// sort is currently IGNORED here — it is stripped before the request.", "// (it does work on zite.auth.findAllUsers). Order in SQL instead.");
533
+ lines.push('// sort: [{ field: "fieldName", direction: "asc" | "desc" }]');
526
534
  lines.push("// limit defaults to 500, max 2000; offset is a row count (a number)");
527
- lines.push('// a filter value of `undefined` is REJECTED (it would query unfiltered', '// and match an arbitrary record). Check the value first.');
535
+ lines.push("// a filter value of `undefined` is REJECTED (it would query unfiltered", "// and match an arbitrary record). Check the value first.");
528
536
  lines.push("// .findOne({ id?, filters?, fields? }) → T | undefined");
529
537
  lines.push("// .create({ record }) → T");
530
538
  lines.push("// .update({ id, record }) → { id: string, fields: Partial<T> }");
@@ -566,7 +574,9 @@ function generateDbTs(inputSchema) {
566
574
  lines.push('// - Auth users are available as "ziteUsers" with id, name, email, firstName, lastName, and image');
567
575
  lines.push("// - Soft-deleted rows are excluded automatically — no WHERE deleted_at IS NULL");
568
576
  lines.push("// - SELECT only — use .create/.update/.delete for writes");
569
- 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.)');
570
580
  lines.push(...buildLinkTableComments(schema));
571
581
  lines.push("import { createTableClient, createSqlClient, createAuthClient } from 'zitejs/runtime';");
572
582
  lines.push("");
@@ -1124,7 +1134,11 @@ function normalizeAirtableLockNames(lock) {
1124
1134
  });
1125
1135
  return { lock: { ...lock, tables }, renames };
1126
1136
  }
1127
- 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") {
1128
1142
  if (inputLock.tables.length === 0)
1129
1143
  return null;
1130
1144
  const { lock, renames } = normalizeAirtableLockNames(inputLock);
@@ -1137,7 +1151,7 @@ function generateAirtableTs(inputLock) {
1137
1151
  "// Auto-generated by zitejs generate from zite.lock. Do not edit manually.",
1138
1152
  "// Airtable SDK — uses createAirtableClient from zitejs/runtime.",
1139
1153
  "//",
1140
- "// Usage in endpoint files (src/api/*.ts) — one client is exported per table:",
1154
+ `// Usage in ${serverCodeIn(runtime)} — one client is exported per table:`,
1141
1155
  `// import { ${lock.tables[0]?.sdkName ?? "TableName"} } from 'zitejs/integrations';`,
1142
1156
  "//",
1143
1157
  "// Always use 'zitejs/integrations' — never a relative path like",
@@ -1232,13 +1246,13 @@ function generateBackendWrapperTs(envVarNames = []) {
1232
1246
  "// Auto-generated type-narrowing wrapper. Do not edit manually.",
1233
1247
  "// Re-exports createEndpoint with context.user typed to the app User.",
1234
1248
  "",
1235
- "import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStep, ZiteStreamInterface, ZiteTrigger, ZiteTriggerContext, ZiteWebhook } from 'zitejs/backend/base';",
1249
+ "import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext, ZiteErrorCode, ZiteSchedule, ZiteStep, ZiteStreamInterface, ZiteTrigger, ZiteTriggerContext, ZiteEndpointInput, ZiteWebhook } from 'zitejs/backend/base';",
1236
1250
  "import type { User } from 'zitejs/auth';",
1237
1251
  "",
1238
1252
  "export type { ZiteErrorCode, ZiteSchedule, ZiteScheduledContext, ZiteStep, ZiteStreamInterface, ZiteTrigger, ZiteWebhook };",
1239
1253
  // A trigger's registration exports are typed against these, and they
1240
1254
  // only reach app code through this file.
1241
- "export type { ZiteTriggerContext, ZiteTriggerDeliveryInfo, ZiteTriggerDeliveryRun, ZiteTriggerRun, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, ZiteTriggerSubscribeResult, ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput } from 'zitejs/backend/base';",
1255
+ "export type { ZiteDatabaseTriggerEvent, ZiteDatabaseTriggerInput, ZiteFormTriggerInput, ZiteTriggerContext, ZiteTriggerDeliveryInfo, ZiteTriggerDeliveryRun, ZiteTriggerRun, ZiteTriggerSubscribe, ZiteTriggerSubscribeInput, ZiteTriggerSubscribeResult, ZiteTriggerUnsubscribe, ZiteTriggerUnsubscribeInput } from 'zitejs/backend/base';",
1242
1256
  // The pre-monorepo SDK put this in scope for every endpoint, so migrated
1243
1257
  // code can name it. `createEndpoint` infers the same thing without it.
1244
1258
  "export type InferSchemaType<T> = T extends { _output: infer U } ? U : T;",
@@ -1326,12 +1340,12 @@ function generateBackendWrapperTs(envVarNames = []) {
1326
1340
  " schedule?: TSchedule;",
1327
1341
  " /** When set, an inbound webhook can also trigger this endpoint. Like `schedule`, it widens `context` — a webhook fire has no session. */",
1328
1342
  " webhook?: TWebhook;",
1329
- " /** When set, a connection's events (registered by this file's own `subscribe` export) or a poll (`every`) also fire this endpoint. Like `webhook`, it widens `context` — a trigger fire has no session. */",
1343
+ " /** When set, a connection's events (registered by this file's own `subscribe` export), a poll (`every`), a change to one of the project's tables (`table`) or a submission to one of its forms (`form`) also fire this endpoint. Like `webhook`, it widens `context` — a trigger fire has no session. */",
1330
1344
  " trigger?: TTrigger;",
1331
1345
  " execute: (",
1332
1346
  " params: {",
1333
- " input: TInput;",
1334
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. Provided by the platform; never define a local stand-in. */",
1347
+ " input: ZiteEndpointInput<TInput, TTrigger>;",
1348
+ ' /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, "2d") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */',
1335
1349
  " step: ZiteStep;",
1336
1350
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1337
1351
  // Mirrors the base module: a trigger's run gets `trigger`.
@@ -1385,12 +1399,12 @@ function findEmailIntegrationId(appConfig, workspaceConfig) {
1385
1399
  * SDK bridge, resolved via the `zitejs/email` alias. `integrationId` is the
1386
1400
  * connected integration's key.
1387
1401
  */
1388
- function generateEmailSdk(integrationId) {
1402
+ function generateEmailSdk(integrationId, runtime = "classic") {
1389
1403
  return [
1390
1404
  "// Auto-generated by zitejs generate from zite.config.json. Do not edit manually.",
1391
1405
  "// Email SDK — sends through the Zite email gateway via the runtime bridge.",
1392
1406
  "//",
1393
- "// Usage in endpoint files (src/api/*.ts):",
1407
+ `// Usage in ${serverCodeIn(runtime)}:`,
1394
1408
  "// import { Email } from 'zitejs/email';",
1395
1409
  "//",
1396
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
@@ -427,44 +443,98 @@ const duplicateIdentifierErrorsIn = (source) => {
427
443
  (0, vitest_1.expect)((0, lib_js_1.findEmailIntegrationId)(undefined, undefined)).toBeUndefined();
428
444
  });
429
445
  });
430
- (0, vitest_1.describe)('generateIntegrationsIndex', () => {
431
- // Not import.meta: this file also compiles to CommonJS. Vitest runs from the repo root.
432
- const runtimePath = (0, path_1.resolve)('src/runtime/index.ts');
433
- /** Type errors in `usage` compiled beside the generated file, `zitejs/runtime` mapped to this source. */
434
- const typeErrorsIn = (generated, usage, airtable) => {
435
- const files = {
436
- '/app/.zite/integrations/index.ts': generated,
437
- ...(airtable ? { '/app/.zite/integrations/airtable.ts': airtable } : {}),
438
- '/app/src/usage.ts': usage,
439
- };
440
- const options = {
441
- strict: true,
442
- noEmit: true,
443
- target: typescript_1.default.ScriptTarget.ES2022,
444
- module: typescript_1.default.ModuleKind.ESNext,
445
- moduleResolution: typescript_1.default.ModuleResolutionKind.Bundler,
446
- skipLibCheck: true,
447
- baseUrl: '/app',
448
- paths: {
449
- 'zitejs/runtime': [runtimePath],
450
- 'zitejs/integrations': ['/app/.zite/integrations/index.ts'],
446
+ // Not import.meta: this file also compiles to CommonJS. Vitest runs from the repo root.
447
+ const runtimePath = (0, path_1.resolve)('src/runtime/index.ts');
448
+ /** Type errors in the `/app/` files, `zitejs/runtime` mapped to this source. */
449
+ const appTypeErrors = (files, paths) => {
450
+ const options = {
451
+ strict: true,
452
+ noEmit: true,
453
+ target: typescript_1.default.ScriptTarget.ES2022,
454
+ module: typescript_1.default.ModuleKind.ESNext,
455
+ moduleResolution: typescript_1.default.ModuleResolutionKind.Bundler,
456
+ skipLibCheck: true,
457
+ baseUrl: '/app',
458
+ paths: { 'zitejs/runtime': [runtimePath], ...paths },
459
+ };
460
+ const host = typescript_1.default.createCompilerHost(options);
461
+ const { getSourceFile, fileExists, readFile, directoryExists } = host;
462
+ host.fileExists = f => f in files || fileExists(f);
463
+ host.directoryExists = d => Object.keys(files).some(f => f.startsWith(`${d}/`)) ||
464
+ (directoryExists?.(d) ?? false);
465
+ host.readFile = f => files[f] ?? readFile(f);
466
+ host.getSourceFile = (f, lang, ...rest) => f in files
467
+ ? typescript_1.default.createSourceFile(f, files[f], lang)
468
+ : getSourceFile(f, lang, ...rest);
469
+ const program = typescript_1.default.createProgram(Object.keys(files), options, host);
470
+ return typescript_1.default
471
+ .getPreEmitDiagnostics(program)
472
+ .filter(d => d.file?.fileName.startsWith('/app/'))
473
+ .map(d => typescript_1.default.flattenDiagnosticMessageText(d.messageText, ' '));
474
+ };
475
+ (0, vitest_1.describe)('generateDbTs created_by and updated_by', () => {
476
+ const schema = {
477
+ tables: [
478
+ {
479
+ id: 'tbl1',
480
+ sdkName: 'tasks',
481
+ fields: [
482
+ {
483
+ id: 'fld1',
484
+ sdkName: 'title',
485
+ definition: { name: 'Title', type: 'single_line_text', template: {} },
486
+ },
487
+ {
488
+ id: 'fld2',
489
+ sdkName: 'createdBy',
490
+ definition: { name: 'Created By', type: 'created_by', template: {} },
491
+ },
492
+ {
493
+ id: 'fld3',
494
+ sdkName: 'updatedBy',
495
+ definition: { name: 'Last Modified By', type: 'updated_by', template: {} },
496
+ },
497
+ ],
451
498
  },
452
- };
453
- const host = typescript_1.default.createCompilerHost(options);
454
- const { getSourceFile, fileExists, readFile, directoryExists } = host;
455
- host.fileExists = f => f in files || fileExists(f);
456
- host.directoryExists = d => Object.keys(files).some(f => f.startsWith(`${d}/`)) ||
457
- (directoryExists?.(d) ?? false);
458
- host.readFile = f => files[f] ?? readFile(f);
459
- host.getSourceFile = (f, lang, ...rest) => f in files
460
- ? typescript_1.default.createSourceFile(f, files[f], lang)
461
- : getSourceFile(f, lang, ...rest);
462
- const program = typescript_1.default.createProgram(Object.keys(files), options, host);
463
- return typescript_1.default
464
- .getPreEmitDiagnostics(program)
465
- .filter(d => d.file?.fileName.startsWith('/app/'))
466
- .map(d => typescript_1.default.flattenDiagnosticMessageText(d.messageText, ' '));
499
+ ],
467
500
  };
501
+ const typeErrorsIn = (usage) => appTypeErrors({ '/app/.zite/db.ts': (0, lib_js_1.generateDbTs)(schema), '/app/src/usage.ts': usage }, { 'zitejs/db': ['/app/.zite/db.ts'] });
502
+ const EQUAL = 'type Equal<A, B> = (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;';
503
+ // TanStack Start's serializability check rejects `unknown`, so a server
504
+ // function returning a raw row failed typecheck while created_by fell through.
505
+ (0, vitest_1.it)('reads both as a user id', () => {
506
+ (0, vitest_1.expect)(typeErrorsIn([
507
+ "import type { TasksRecordType } from 'zitejs/db';",
508
+ EQUAL,
509
+ "export const createdBy: Equal<TasksRecordType['createdBy'], string | undefined> = true;",
510
+ "export const updatedBy: Equal<TasksRecordType['updatedBy'], string | undefined> = true;",
511
+ ].join('\n'))).toEqual([]);
512
+ });
513
+ (0, vitest_1.it)('leaves both out of the input type', () => {
514
+ (0, vitest_1.expect)(typeErrorsIn([
515
+ "import type { TasksRecordInput } from 'zitejs/db';",
516
+ EQUAL,
517
+ "export const writable: Equal<keyof TasksRecordInput, 'title'> = true;",
518
+ ].join('\n'))).toEqual([]);
519
+ });
520
+ (0, vitest_1.it)('filters both by a user id', () => {
521
+ (0, vitest_1.expect)(typeErrorsIn([
522
+ "import { zite } from 'zitejs/db';",
523
+ 'export const mine = (userId: string) => [',
524
+ ' zite.tasks.findAll({ filters: { createdBy: userId } }),',
525
+ ' zite.tasks.findAll({ filters: { updatedBy: { in: [userId] } } }),',
526
+ ' zite.tasks.findOne({ filters: { createdBy: { not: null } } }),',
527
+ '];',
528
+ ].join('\n'))).toEqual([]);
529
+ (0, vitest_1.expect)(typeErrorsIn("import { zite } from 'zitejs/db';\nvoid zite.tasks.findAll({ filters: { createdBy: 42 } });")).toHaveLength(1);
530
+ });
531
+ });
532
+ (0, vitest_1.describe)('generateIntegrationsIndex', () => {
533
+ const typeErrorsIn = (generated, usage, airtable) => appTypeErrors({
534
+ '/app/.zite/integrations/index.ts': generated,
535
+ ...(airtable ? { '/app/.zite/integrations/airtable.ts': airtable } : {}),
536
+ '/app/src/usage.ts': usage,
537
+ }, { 'zitejs/integrations': ['/app/.zite/integrations/index.ts'] });
468
538
  (0, vitest_1.it)('emits the client typed by name', () => {
469
539
  (0, vitest_1.expect)((0, lib_js_1.generateIntegrationsIndex)([
470
540
  { name: 'team', serviceType: 'slack', perUser: false },
@@ -7,7 +7,7 @@ export declare const timeFormatEnum: readonly ["12h", "24h"];
7
7
  export type TimeFormat = (typeof timeFormatEnum)[number];
8
8
  export declare const durationFormatEnum: readonly ["h:mm", "h:mm:ss", "h:mm:ss.s", "h:mm:ss.ss", "h:mm:ss.sss"];
9
9
  export type DurationFormat = (typeof durationFormatEnum)[number];
10
- export declare const fieldTypeEnum: readonly ["currency", "single_line_text", "long_text", "rich_text", "number", "single_select", "multiple_select", "date", "datetime", "checkbox", "attachments", "email", "url", "phone_number", "rating", "duration", "percent", "linked_record", "lookup", "source", "formula", "autonumber", "created_at", "updated_at", "rollup", "updated_by", "user"];
10
+ export declare const fieldTypeEnum: readonly ["currency", "single_line_text", "long_text", "rich_text", "number", "single_select", "multiple_select", "date", "datetime", "checkbox", "attachments", "email", "url", "phone_number", "rating", "duration", "percent", "linked_record", "lookup", "source", "formula", "autonumber", "created_at", "updated_at", "rollup", "created_by", "updated_by", "user"];
11
11
  export type FieldType = (typeof fieldTypeEnum)[number];
12
12
  export declare const fieldTypeSchema: z.ZodEnum<{
13
13
  number: "number";
@@ -35,6 +35,7 @@ export declare const fieldTypeSchema: z.ZodEnum<{
35
35
  created_at: "created_at";
36
36
  updated_at: "updated_at";
37
37
  rollup: "rollup";
38
+ created_by: "created_by";
38
39
  updated_by: "updated_by";
39
40
  user: "user";
40
41
  }>;
@@ -240,6 +241,7 @@ export declare const rollupTemplateSchema: z.ZodObject<{
240
241
  text: "text";
241
242
  }>>;
242
243
  }, z.core.$strip>;
244
+ export declare const createdByTemplateSchema: z.ZodObject<{}, z.core.$strip>;
243
245
  export declare const updatedByTemplateSchema: z.ZodObject<{}, z.core.$strip>;
244
246
  export declare const userTemplateSchema: z.ZodObject<{
245
247
  allowMultiple: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>, z.ZodTransform<boolean, boolean | null | undefined>>;
@@ -554,6 +556,10 @@ export declare const publicFieldDefinitionSchema: z.ZodDiscriminatedUnion<[z.Zod
554
556
  text: "text";
555
557
  }>>;
556
558
  }, z.core.$strip>;
559
+ }, z.core.$strip>, z.ZodObject<{
560
+ name: z.ZodString;
561
+ type: z.ZodLiteral<"created_by">;
562
+ template: z.ZodObject<{}, z.core.$strip>;
557
563
  }, z.core.$strip>, z.ZodObject<{
558
564
  name: z.ZodString;
559
565
  type: z.ZodLiteral<"updated_by">;
@@ -661,6 +667,7 @@ export type FieldTemplateMap = {
661
667
  linked_record: z.infer<typeof linkedRecordTemplateSchema>;
662
668
  lookup: z.infer<typeof lookupTemplateSchema>;
663
669
  rollup: z.infer<typeof rollupTemplateSchema>;
670
+ created_by: z.infer<typeof createdByTemplateSchema>;
664
671
  updated_by: z.infer<typeof updatedByTemplateSchema>;
665
672
  user: z.infer<typeof userTemplateSchema>;
666
673
  source: z.infer<typeof sourceTemplateSchema>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicFieldDefinitionSchema = exports.updatedAtTemplateSchema = exports.createdAtTemplateSchema = exports.autonumberTemplateSchema = exports.formulaTemplateSchema = exports.sourceTemplateSchema = exports.userTemplateSchema = exports.updatedByTemplateSchema = exports.rollupTemplateSchema = exports.lookupTemplateSchema = exports.linkedRecordTemplateSchema = exports.percentTemplateSchema = exports.durationTemplateSchema = exports.ratingTemplateSchema = exports.phoneNumberTemplateSchema = exports.urlTemplateSchema = exports.emailTemplateSchema = exports.attachmentsTemplateSchema = exports.checkboxTemplateSchema = exports.datetimeTemplateSchema = exports.dateTemplateSchema = exports.multipleSelectTemplateSchema = exports.singleSelectTemplateSchema = exports.numberTemplateSchema = exports.richTextTemplateSchema = exports.longTextTemplateSchema = exports.singleLineTextTemplateSchema = exports.currencyTemplateSchema = exports.aiGenerationConfigSchema = exports.selectOptionSchema = exports.fieldTypeSchema = exports.fieldTypeEnum = exports.durationFormatEnum = exports.timeFormatEnum = exports.dateFormatEnum = exports.numberFormatEnum = void 0;
3
+ exports.publicFieldDefinitionSchema = exports.updatedAtTemplateSchema = exports.createdAtTemplateSchema = exports.autonumberTemplateSchema = exports.formulaTemplateSchema = exports.sourceTemplateSchema = exports.userTemplateSchema = exports.updatedByTemplateSchema = exports.createdByTemplateSchema = exports.rollupTemplateSchema = exports.lookupTemplateSchema = exports.linkedRecordTemplateSchema = exports.percentTemplateSchema = exports.durationTemplateSchema = exports.ratingTemplateSchema = exports.phoneNumberTemplateSchema = exports.urlTemplateSchema = exports.emailTemplateSchema = exports.attachmentsTemplateSchema = exports.checkboxTemplateSchema = exports.datetimeTemplateSchema = exports.dateTemplateSchema = exports.multipleSelectTemplateSchema = exports.singleSelectTemplateSchema = exports.numberTemplateSchema = exports.richTextTemplateSchema = exports.longTextTemplateSchema = exports.singleLineTextTemplateSchema = exports.currencyTemplateSchema = exports.aiGenerationConfigSchema = exports.selectOptionSchema = exports.fieldTypeSchema = exports.fieldTypeEnum = exports.durationFormatEnum = exports.timeFormatEnum = exports.dateFormatEnum = exports.numberFormatEnum = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.numberFormatEnum = [
6
6
  "local",
@@ -45,6 +45,7 @@ exports.fieldTypeEnum = [
45
45
  "created_at",
46
46
  "updated_at",
47
47
  "rollup",
48
+ "created_by",
48
49
  "updated_by",
49
50
  "user",
50
51
  ];
@@ -183,6 +184,7 @@ exports.rollupTemplateSchema = zod_1.z.object({
183
184
  .enum(["text", "number", "date", "boolean", "array"])
184
185
  .optional(),
185
186
  });
187
+ exports.createdByTemplateSchema = zod_1.z.object({});
186
188
  exports.updatedByTemplateSchema = zod_1.z.object({});
187
189
  exports.userTemplateSchema = zod_1.z.object({
188
190
  allowMultiple: zod_1.z
@@ -329,6 +331,10 @@ exports.publicFieldDefinitionSchema = zod_1.z.discriminatedUnion("type", [
329
331
  type: zod_1.z.literal("rollup"),
330
332
  template: exports.rollupTemplateSchema,
331
333
  }),
334
+ basePublicFieldSchema.extend({
335
+ type: zod_1.z.literal("created_by"),
336
+ template: exports.createdByTemplateSchema,
337
+ }),
332
338
  basePublicFieldSchema.extend({
333
339
  type: zod_1.z.literal("updated_by"),
334
340
  template: exports.updatedByTemplateSchema,
@@ -253,6 +253,10 @@ export declare const fieldSchema: z.ZodIntersection<z.ZodObject<{
253
253
  text: "text";
254
254
  }>>;
255
255
  }, z.core.$strip>;
256
+ }, z.core.$strip>, z.ZodObject<{
257
+ name: z.ZodString;
258
+ type: z.ZodLiteral<"created_by">;
259
+ template: z.ZodObject<{}, z.core.$strip>;
256
260
  }, z.core.$strip>, z.ZodObject<{
257
261
  name: z.ZodString;
258
262
  type: z.ZodLiteral<"updated_by">;
@@ -605,6 +609,10 @@ export declare const tableSchema: z.ZodObject<{
605
609
  text: "text";
606
610
  }>>;
607
611
  }, z.core.$strip>;
612
+ }, z.core.$strip>, z.ZodObject<{
613
+ name: z.ZodString;
614
+ type: z.ZodLiteral<"created_by">;
615
+ template: z.ZodObject<{}, z.core.$strip>;
608
616
  }, z.core.$strip>, z.ZodObject<{
609
617
  name: z.ZodString;
610
618
  type: z.ZodLiteral<"updated_by">;
@@ -952,6 +960,10 @@ export declare const publicTableDefinitionSchema: z.ZodObject<{
952
960
  text: "text";
953
961
  }>>;
954
962
  }, z.core.$strip>;
963
+ }, z.core.$strip>, z.ZodObject<{
964
+ name: z.ZodString;
965
+ type: z.ZodLiteral<"created_by">;
966
+ template: z.ZodObject<{}, z.core.$strip>;
955
967
  }, z.core.$strip>, z.ZodObject<{
956
968
  name: z.ZodString;
957
969
  type: z.ZodLiteral<"updated_by">;
@@ -1301,6 +1313,10 @@ export declare const databaseSchema: z.ZodObject<{
1301
1313
  text: "text";
1302
1314
  }>>;
1303
1315
  }, z.core.$strip>;
1316
+ }, z.core.$strip>, z.ZodObject<{
1317
+ name: z.ZodString;
1318
+ type: z.ZodLiteral<"created_by">;
1319
+ template: z.ZodObject<{}, z.core.$strip>;
1304
1320
  }, z.core.$strip>, z.ZodObject<{
1305
1321
  name: z.ZodString;
1306
1322
  type: z.ZodLiteral<"updated_by">;
@@ -6,6 +6,7 @@ exports.uploadFile = uploadFile;
6
6
  exports.useUpload = useUpload;
7
7
  const react_1 = require("react");
8
8
  const config_js_1 = require("../auth/config.js");
9
+ const appMode_js_1 = require("../internal/appMode.js");
9
10
  const constants_js_1 = require("../auth/constants.js");
10
11
  class FileUploadError extends Error {
11
12
  constructor(message) {
@@ -14,7 +15,16 @@ class FileUploadError extends Error {
14
15
  }
15
16
  }
16
17
  exports.FileUploadError = FileUploadError;
17
- function getZiteAppMode(hostname) {
18
+ /** As the platform served the page or request; a classic app's from its hostname. */
19
+ function getZiteAppMode() {
20
+ const served = (0, appMode_js_1.platformMode)();
21
+ if (served)
22
+ return served === 'preview' || served === 'validate' ? 'preview' : 'live';
23
+ // On a server, outside any request the platform served: there's no telling a preview from live.
24
+ if (typeof window === 'undefined') {
25
+ throw new FileUploadError('Upload from a page, or from a request the platform is serving');
26
+ }
27
+ const { hostname } = window.location;
18
28
  const maybeId = hostname.split('.')[0];
19
29
  if (maybeId?.startsWith(constants_js_1.ZITE_APP_EDITOR_HOSTNAME_PREFIX))
20
30
  return 'preview';
@@ -82,7 +92,7 @@ function authHeaders() {
82
92
  }
83
93
  async function performUpload(data, filename) {
84
94
  const blob = toUploadBlob(data);
85
- const mode = getZiteAppMode(window.location.hostname);
95
+ const mode = getZiteAppMode();
86
96
  const flowId = (0, config_js_1.getFlowId)();
87
97
  const sessionRes = await fetch((0, config_js_1.getApiUrl)() + '/v1/zite/public/' + flowId + '/upload-session?mode=' + mode, {
88
98
  method: 'POST',
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
+ const node_async_hooks_1 = require("node:async_hooks");
5
+ const appMode_js_1 = require("../internal/appMode.js");
4
6
  const index_js_1 = require("./index.js");
5
7
  vitest_1.vi.mock('../auth/config.js', () => ({
6
8
  getApiUrl: () => 'https://api.example.com',
@@ -93,3 +95,40 @@ const fetchMock = vitest_1.vi.fn();
93
95
  await (0, vitest_1.expect)(upload).rejects.toThrow('File size exceeds maximum of 20 MB');
94
96
  });
95
97
  });
98
+ // SDK-10: a Start app's mode is the platform's, never guessed from where the page is served.
99
+ (0, vitest_1.describe)('the mode an upload goes under', () => {
100
+ const sessionUrl = async () => {
101
+ fetchMock.mockResolvedValueOnce({
102
+ ok: true,
103
+ json: async () => ({ success: true, presignedUrl: 'https://s3.example.com/put', fileUrl: 'https://uploads.zite.com/f.txt' }),
104
+ });
105
+ fetchMock.mockResolvedValueOnce({ ok: true });
106
+ await (0, index_js_1.uploadFile)({ data: 'hi', filename: 'f.txt' });
107
+ return String(fetchMock.mock.calls[0][0]);
108
+ };
109
+ (0, vitest_1.afterEach)(() => (0, appMode_js_1.keepRenderedMode)(undefined));
110
+ (0, vitest_1.it)('is the one the page was rendered in, on any host', async () => {
111
+ (0, appMode_js_1.keepRenderedMode)('preview');
112
+ (0, vitest_1.expect)(await sessionUrl()).toContain('mode=preview');
113
+ });
114
+ (0, vitest_1.it)("is the request's own on the server, where there's no page", async () => {
115
+ vitest_1.vi.stubGlobal('window', undefined);
116
+ const store = new node_async_hooks_1.AsyncLocalStorage();
117
+ globalThis[Symbol.for('zitejs:host-context')] = store;
118
+ try {
119
+ (0, vitest_1.expect)(await store.run({ mode: 'validate' }, sessionUrl)).toContain('mode=preview');
120
+ }
121
+ finally {
122
+ delete globalThis[Symbol.for('zitejs:host-context')];
123
+ }
124
+ });
125
+ (0, vitest_1.it)('is refused on a server outside any request the platform served, never guessed as live', async () => {
126
+ vitest_1.vi.stubGlobal('window', undefined);
127
+ await (0, vitest_1.expect)((0, index_js_1.uploadFile)({ data: 'hi', filename: 'f.txt' })).rejects.toThrow(index_js_1.FileUploadError);
128
+ (0, vitest_1.expect)(fetchMock).not.toHaveBeenCalled();
129
+ });
130
+ (0, vitest_1.it)("is a classic app's from its hostname, as before", async () => {
131
+ vitest_1.vi.stubGlobal('window', { location: { hostname: 'zite-editor-app_123.zite.so' } });
132
+ (0, vitest_1.expect)(await sessionUrl()).toContain('mode=preview');
133
+ });
134
+ });
@@ -75,11 +75,12 @@ function ziteId() {
75
75
  name: "vite-plugin-zite-id",
76
76
  enforce: "pre",
77
77
  async transform(code, id) {
78
- if (!validExtensions.has(path_1.default.extname(id)) ||
79
- id.includes("node_modules")) {
78
+ // TanStack's route code splitting moves a route's component into its own module, `route.tsx?tsr-split=…`.
79
+ const file = id.split("?")[0];
80
+ if (!validExtensions.has(path_1.default.extname(file)) || file.includes("node_modules")) {
80
81
  return null;
81
82
  }
82
- const relativePath = path_1.default.relative(cwd, id);
83
+ const relativePath = path_1.default.relative(cwd, file);
83
84
  try {
84
85
  const ast = (0, parser_1.parse)(code, {
85
86
  sourceType: "module",
@@ -134,6 +135,10 @@ function ziteId() {
134
135
  if (!isTagged) {
135
136
  return;
136
137
  }
138
+ // A module split from one already tagged keeps its tags.
139
+ if (openingElement.attributes?.some((attr) => attr.type === "JSXAttribute" && attr.name?.name === "data-zite-id")) {
140
+ return;
141
+ }
137
142
  const line = openingElement.loc?.start?.line ?? 0;
138
143
  const col = openingElement.loc?.start?.column ?? 0;
139
144
  const dataComponentId = `${relativePath}|${line}|${col}`;
@@ -6,16 +6,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const vitest_1 = require("vitest");
8
8
  const index_js_1 = require("./index.js");
9
- async function transform(code) {
9
+ async function transform(code, file = 'src/App.tsx') {
10
10
  const plugin = (0, index_js_1.ziteId)();
11
11
  const handler = plugin.transform;
12
- const result = await handler(code, path_1.default.join(process.cwd(), 'src/App.tsx'));
12
+ const result = await handler(code, path_1.default.join(process.cwd(), file));
13
13
  if (!result) {
14
14
  throw new Error('transform returned null');
15
15
  }
16
16
  return result.code;
17
17
  }
18
18
  (0, vitest_1.describe)('ziteId', () => {
19
+ (0, vitest_1.it)("tags a route's component that TanStack split into its own module, by the source file", async () => {
20
+ const code = await transform('const a = <p>Hi</p>;', 'src/routes/index.tsx?tsr-split=component');
21
+ (0, vitest_1.expect)(code).toContain('<p data-zite-id="src/routes/index.tsx|1|10" data-zite-editable="true">');
22
+ });
23
+ (0, vitest_1.it)('leaves an element that already has its tag', async () => {
24
+ const code = await transform('const a = <p data-zite-id="src/routes/index.tsx|1|10">Hi</p>;');
25
+ (0, vitest_1.expect)(code.match(/data-zite-id/g)).toHaveLength(1);
26
+ });
19
27
  (0, vitest_1.it)('tags html and svg elements without a component name', async () => {
20
28
  const code = await transform('const a = <div><svg><path d="M0" /></svg><p>Hello</p></div>;');
21
29
  (0, vitest_1.expect)(code).toContain('<div data-zite-id="src/App.tsx|1|10">');
@@ -67,7 +67,7 @@ export declare const signIn: {
67
67
  }, FetchOptions["throw"] extends true ? true : false>>;
68
68
  } & {
69
69
  social: <FetchOptions extends import("better-auth").ClientFetchOption<Partial<{
70
- provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
70
+ provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
71
71
  callbackURL?: string | undefined;
72
72
  newUserCallbackURL?: string | undefined;
73
73
  errorCallbackURL?: string | undefined;
@@ -91,7 +91,7 @@ export declare const signIn: {
91
91
  loginHint?: string | undefined;
92
92
  additionalData?: Record<string, any> | undefined;
93
93
  }> & Record<string, any>, Partial<Record<string, any>> & Record<string, any>, Record<string, any> | undefined>>(data_0: import("better-auth/react").Prettify<{
94
- provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "line" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
94
+ provider: "salesforce" | "slack" | "linear" | "notion" | "linkedin" | "github" | "dropbox" | "line" | (string & {}) | "huggingface" | "apple" | "atlassian" | "cognito" | "discord" | "facebook" | "figma" | "microsoft" | "google" | "spotify" | "twitch" | "twitter" | "kick" | "gitlab" | "tiktok" | "reddit" | "roblox" | "vk" | "zoom" | "kakao" | "naver" | "paybin" | "paypal" | "polar" | "railway" | "vercel" | "wechat";
95
95
  callbackURL?: string | undefined;
96
96
  newUserCallbackURL?: string | undefined;
97
97
  errorCallbackURL?: string | undefined;
@@ -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
  }