zitejs 0.10.0-start.21 → 0.10.0-start.23

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 (128) hide show
  1. package/dist/cjs/auth/client.d.ts +2 -2
  2. package/dist/cjs/check/start/sourceRules.js +3 -0
  3. package/dist/cjs/cli.js +6 -0
  4. package/dist/cjs/dev/index.js +15 -0
  5. package/dist/cjs/dev/signin.d.ts +16 -0
  6. package/dist/cjs/dev/signin.js +76 -0
  7. package/dist/cjs/internal/appMode.d.ts +11 -0
  8. package/dist/cjs/internal/appMode.js +4 -1
  9. package/dist/cjs/internal/appToken.d.ts +17 -0
  10. package/dist/cjs/internal/appToken.js +26 -0
  11. package/dist/cjs/internal/platformFetch.d.ts +2 -0
  12. package/dist/cjs/internal/platformFetch.js +13 -0
  13. package/dist/cjs/internal/serviceUrls.d.ts +7 -0
  14. package/dist/cjs/internal/serviceUrls.js +16 -0
  15. package/dist/cjs/runtime/index.d.ts +1 -1
  16. package/dist/cjs/start/aiUsage.d.ts +23 -0
  17. package/dist/cjs/start/aiUsage.js +151 -0
  18. package/dist/cjs/start/devApp.d.ts +1 -0
  19. package/dist/cjs/start/devApp.js +6 -0
  20. package/dist/cjs/start/entries.js +4 -0
  21. package/dist/cjs/start/provider.d.ts +24 -0
  22. package/dist/cjs/start/provider.js +159 -0
  23. package/dist/cjs/start/types.d.ts +302 -0
  24. package/dist/cjs/start/types.js +2 -0
  25. package/dist/cjs/sync/lib.js +23 -50
  26. package/dist/cjs/sync/sdkNames.d.ts +65 -7
  27. package/dist/cjs/sync/sdkNames.js +76 -12
  28. package/dist/cjs/sync/sdkNames.test.js +38 -0
  29. package/dist/cjs/upload/index.js +73 -22
  30. package/dist/cjs/upload/index.test.js +35 -2
  31. package/dist/esm/auth/client.d.ts +2 -2
  32. package/dist/esm/check/start/sourceRules.js +3 -0
  33. package/dist/esm/cli.js +6 -0
  34. package/dist/esm/dev/index.js +15 -0
  35. package/dist/esm/dev/signin.d.ts +16 -0
  36. package/dist/esm/dev/signin.js +72 -0
  37. package/dist/esm/internal/appMode.d.ts +11 -0
  38. package/dist/esm/internal/appMode.js +2 -0
  39. package/dist/esm/internal/appToken.d.ts +17 -0
  40. package/dist/esm/internal/appToken.js +22 -0
  41. package/dist/esm/internal/platformFetch.d.ts +2 -0
  42. package/dist/esm/internal/platformFetch.js +8 -0
  43. package/dist/esm/internal/serviceUrls.d.ts +7 -0
  44. package/dist/esm/internal/serviceUrls.js +12 -0
  45. package/dist/esm/runtime/index.d.ts +1 -1
  46. package/dist/esm/signin/conformance.d.ts +100 -0
  47. package/dist/esm/signin/conformance.js +471 -0
  48. package/dist/esm/signin/cookies.d.ts +28 -0
  49. package/dist/esm/signin/cookies.js +59 -0
  50. package/dist/esm/signin/encoding.d.ts +9 -0
  51. package/dist/esm/signin/encoding.js +39 -0
  52. package/dist/esm/signin/endpoints.d.ts +12 -0
  53. package/dist/esm/signin/endpoints.js +29 -0
  54. package/dist/esm/signin/http.d.ts +25 -0
  55. package/dist/esm/signin/http.js +69 -0
  56. package/dist/esm/signin/index.d.ts +8 -0
  57. package/dist/esm/signin/index.js +9 -0
  58. package/dist/esm/signin/keys.d.ts +39 -0
  59. package/dist/esm/signin/keys.js +80 -0
  60. package/dist/esm/signin/paths.d.ts +2 -0
  61. package/dist/esm/signin/paths.js +2 -0
  62. package/dist/esm/signin/seal.d.ts +8 -0
  63. package/dist/esm/signin/seal.js +35 -0
  64. package/dist/esm/signin/signin.d.ts +60 -0
  65. package/dist/esm/signin/signin.js +340 -0
  66. package/dist/esm/signin/transport.d.ts +111 -0
  67. package/dist/esm/signin/transport.js +1 -0
  68. package/dist/esm/signin/verify.d.ts +77 -0
  69. package/dist/esm/signin/verify.js +155 -0
  70. package/dist/esm/start/airtable/built.d.ts +2 -0
  71. package/dist/esm/start/airtable/built.js +3 -0
  72. package/dist/esm/start/airtable/index.d.ts +3 -5
  73. package/dist/esm/start/airtable/index.js +4 -25
  74. package/dist/esm/start/airtable/settings.d.ts +31 -0
  75. package/dist/esm/start/airtable/settings.js +110 -0
  76. package/dist/esm/start/analytics.d.ts +5 -0
  77. package/dist/esm/start/analytics.js +77 -0
  78. package/dist/esm/start/data/index.d.ts +21 -9
  79. package/dist/esm/start/data/index.js +26 -20
  80. package/dist/esm/start/data/names.d.ts +7 -0
  81. package/dist/esm/start/data/names.js +15 -0
  82. package/dist/esm/start/data/types.d.ts +4 -1
  83. package/dist/esm/start/devApp.d.ts +1 -0
  84. package/dist/esm/start/devApp.js +3 -0
  85. package/dist/esm/start/devSignIn.d.ts +1 -0
  86. package/dist/esm/start/devSignIn.js +3 -0
  87. package/dist/esm/start/direct.d.ts +44 -0
  88. package/dist/esm/start/direct.js +442 -0
  89. package/dist/esm/start/entries.js +4 -0
  90. package/dist/esm/start/fetch.d.ts +1 -0
  91. package/dist/esm/start/fetch.js +4 -0
  92. package/dist/esm/start/instance.js +6 -2
  93. package/dist/esm/start/localSignIn.d.ts +18 -0
  94. package/dist/esm/start/localSignIn.js +73 -0
  95. package/dist/esm/start/outbound.d.ts +9 -1
  96. package/dist/esm/start/outbound.js +130 -31
  97. package/dist/esm/start/pageHead.d.ts +36 -0
  98. package/dist/esm/start/pageHead.js +178 -0
  99. package/dist/esm/start/provider.d.ts +24 -0
  100. package/dist/esm/start/provider.js +150 -0
  101. package/dist/esm/start/router.d.ts +6 -2
  102. package/dist/esm/start/router.js +41 -2
  103. package/dist/esm/start/server.d.ts +23 -12
  104. package/dist/esm/start/server.js +185 -56
  105. package/dist/esm/start/telemetry.d.ts +13 -0
  106. package/dist/esm/start/telemetry.js +71 -0
  107. package/dist/esm/start/types.d.ts +141 -44
  108. package/dist/esm/start/uploads.d.ts +2 -0
  109. package/dist/esm/start/uploads.js +52 -0
  110. package/dist/esm/start/version.d.ts +1 -1
  111. package/dist/esm/start/version.js +1 -1
  112. package/dist/esm/start/vite.d.ts +18 -1
  113. package/dist/esm/start/vite.js +163 -4
  114. package/dist/esm/start/workspaceSchema.d.ts +2 -0
  115. package/dist/esm/start/workspaceSchema.js +3 -0
  116. package/dist/esm/sync/lib.js +23 -50
  117. package/dist/esm/sync/sdkNames.d.ts +65 -7
  118. package/dist/esm/sync/sdkNames.js +73 -11
  119. package/dist/esm/sync/sdkNames.test.js +38 -0
  120. package/dist/esm/upload/index.js +74 -23
  121. package/dist/esm/upload/index.test.js +35 -2
  122. package/package.json +22 -12
  123. package/dist/cjs/auth-server/index.d.ts +0 -369
  124. package/dist/cjs/auth-server/index.js +0 -119
  125. package/dist/esm/auth-server/index.d.ts +0 -369
  126. package/dist/esm/auth-server/index.js +0 -116
  127. package/dist/esm/start/problems.d.ts +0 -19
  128. package/dist/esm/start/problems.js +0 -8
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.localPlatform = exports.mintDevToken = exports.resetDevToken = exports.localModeOf = exports.localUrls = exports.LOCAL_ENV = exports.ziteProvider = void 0;
4
+ // The one place zitejs knows where the platform is. `zite`: Zite's dispatcher hands each request its app token, the
5
+ // platform's URLs and who is calling, in props. `local`: a developer's machine, with a dev token the backend minted.
6
+ const appToken_js_1 = require("../internal/appToken.js");
7
+ const platformFetch_js_1 = require("../internal/platformFetch.js");
8
+ const devApp_js_1 = require("./devApp.js");
9
+ // A streamed answer can outlive the request's deadline, which the token's expiry follows.
10
+ const RENEW_WITHIN_MS = 30_000;
11
+ const expiresWithin = (token, ms) => {
12
+ const claims = (0, appToken_js_1.appTokenClaims)(token);
13
+ return claims !== undefined && claims.exp * 1000 - Date.now() < ms;
14
+ };
15
+ const URL_NAMES = ["baseRunner", "backend", "aiGateway", "runs", "email", "pdf", "uploads", "steps"];
16
+ // `local` may leave out the AI gateway (a call on Zite's AI key is then refused), `runs` (a preview sends no analytics,
17
+ // and `local` keeps no run detail) and each service's own URL (the backend then answers it).
18
+ const OPTIONAL_URLS = new Set(["aiGateway", "runs", "email", "pdf", "uploads", "steps"]);
19
+ const trimmed = (urls) => Object.fromEntries(URL_NAMES.flatMap((name) => (urls[name] ? [[name, urls[name].replace(/\/+$/, "")]] : [])));
20
+ const ziteProvider = (props) => {
21
+ let current = props.appToken;
22
+ let renewing;
23
+ const renew = async () => {
24
+ try {
25
+ const fresh = await props.platform.appToken();
26
+ return typeof fresh === "string" && fresh ? fresh : undefined;
27
+ }
28
+ catch (error) {
29
+ // The token held still serves until it expires.
30
+ console.error("[zite] couldn't renew the app token", error);
31
+ return undefined;
32
+ }
33
+ };
34
+ return {
35
+ kind: "zite",
36
+ urls: props.urls && trimmed(props.urls),
37
+ user: () => props.user,
38
+ token: async () => {
39
+ if (!current || !expiresWithin(current, RENEW_WITHIN_MS))
40
+ return current;
41
+ renewing ??= renew().finally(() => (renewing = undefined));
42
+ current = (await renewing) ?? current;
43
+ return current;
44
+ },
45
+ };
46
+ };
47
+ exports.ziteProvider = ziteProvider;
48
+ /** What `local` reads, documented in `zitejs`'s help. */
49
+ exports.LOCAL_ENV = { token: "ZITE_DEV_TOKEN", apiKey: "ZITE_DEV_API_KEY", urls: "ZITE_URLS", user: "ZITE_DEV_USER" };
50
+ const processEnv = () => globalThis.process?.env;
51
+ /** `ZITE_URLS`, or a throw saying what it must name. */
52
+ const localUrls = (raw) => {
53
+ let parsed;
54
+ try {
55
+ parsed = JSON.parse(raw ?? "");
56
+ }
57
+ catch {
58
+ parsed = undefined;
59
+ }
60
+ const given = (parsed ?? {});
61
+ const isUrl = (value) => typeof value === "string" && /^https?:\/\//.test(value);
62
+ if (URL_NAMES.some((name) => (given[name] === undefined ? !OPTIONAL_URLS.has(name) : !isUrl(given[name])))) {
63
+ throw new Error(`${exports.LOCAL_ENV.urls} must be JSON naming the baseRunner and backend URLs, and may name aiGateway, runs, email, pdf, uploads and steps`);
64
+ }
65
+ return trimmed(given);
66
+ };
67
+ exports.localUrls = localUrls;
68
+ const localUser = (raw) => {
69
+ if (!raw)
70
+ return null;
71
+ let given;
72
+ try {
73
+ given = JSON.parse(raw);
74
+ }
75
+ catch {
76
+ given = undefined;
77
+ }
78
+ if (typeof given?.id !== "string" || typeof given.email !== "string") {
79
+ throw new Error(`${exports.LOCAL_ENV.user} must be JSON with the stand-in user's id and email`);
80
+ }
81
+ const roles = Array.isArray(given.roles) ? given.roles : [];
82
+ return {
83
+ id: given.id,
84
+ email: given.email,
85
+ name: typeof given.name === "string" ? given.name : given.email,
86
+ roles: roles.map((role) => (typeof role === "string" ? { id: role, name: role } : role)),
87
+ isInternal: given.isInternal === true,
88
+ };
89
+ };
90
+ const MODES = new Set(["live", "preview", "demo"]);
91
+ /** The mode a dev token names; preview for one it doesn't. */
92
+ const localModeOf = (claims) => MODES.has(claims?.mode) ? claims?.mode : "preview";
93
+ exports.localModeOf = localModeOf;
94
+ // The backend mints them for 15 minutes.
95
+ const RENEW_DEV_TOKEN_WITHIN_MS = 60_000;
96
+ const MINT_TIMEOUT_MS = 10_000;
97
+ // Per isolate, only a minted token, never a pending mint: Workers ties a request's I/O to that request.
98
+ let held;
99
+ /** For tests: forget the minted dev token. */
100
+ const resetDevToken = () => {
101
+ held = undefined;
102
+ };
103
+ exports.resetDevToken = resetDevToken;
104
+ const mintDevToken = async (backend, appId, apiKey) => {
105
+ const response = await (0, platformFetch_js_1.platformFetch)(new Request(`${backend}/v1/start/apps/${encodeURIComponent(appId)}/dev-token`, {
106
+ method: "POST",
107
+ headers: { authorization: `Bearer ${apiKey}` },
108
+ signal: AbortSignal.timeout(MINT_TIMEOUT_MS),
109
+ }));
110
+ const answer = (await response.json().catch(() => null));
111
+ if (response.ok && typeof answer?.token === "string")
112
+ return answer.token;
113
+ const why = [answer?.message, answer?.error].find((text) => typeof text === "string");
114
+ throw new Error(`The backend didn't mint a dev token for app ${appId} with ${exports.LOCAL_ENV.apiKey}: ${response.status}${why ? ` ${why}` : ""}`);
115
+ };
116
+ exports.mintDevToken = mintDevToken;
117
+ /** The app's dev token, minted with the developer's key, and minted again when it's about to expire. */
118
+ const mintedDevToken = (backend, appId, apiKey) => {
119
+ const key = `${backend} ${appId} ${apiKey}`;
120
+ let minting;
121
+ return async () => {
122
+ const current = held?.key === key ? held.token : undefined;
123
+ if (current && !expiresWithin(current, RENEW_DEV_TOKEN_WITHIN_MS))
124
+ return current;
125
+ minting ??= (0, exports.mintDevToken)(backend, appId, apiKey).finally(() => (minting = undefined));
126
+ try {
127
+ const token = await minting;
128
+ held = { key, token };
129
+ return token;
130
+ }
131
+ catch (error) {
132
+ if (!current || expiresWithin(current, 0))
133
+ throw error;
134
+ console.error("[zite] couldn't renew the dev token; using the one held until it expires", error);
135
+ return current;
136
+ }
137
+ };
138
+ };
139
+ // A given dev token is used as it is. A key mints them only under `vite dev`, which knows the app's id.
140
+ const localToken = (env, appId) => {
141
+ const given = env[exports.LOCAL_ENV.token];
142
+ if (given)
143
+ return () => async () => given;
144
+ const apiKey = env[exports.LOCAL_ENV.apiKey];
145
+ return apiKey && appId ? (backend) => mintedDevToken(backend, appId, apiKey) : undefined;
146
+ };
147
+ /**
148
+ * `local` when the developer set a dev token, or a key to mint them with, else undefined. Throws on env it can't read,
149
+ * so a typo fails loudly rather than signing nobody in.
150
+ */
151
+ const localPlatform = (env = processEnv() ?? {}, appId = devApp_js_1.devAppId) => {
152
+ const token = localToken(env, appId);
153
+ if (!token)
154
+ return undefined;
155
+ const urls = (0, exports.localUrls)(env[exports.LOCAL_ENV.urls]);
156
+ const user = localUser(env[exports.LOCAL_ENV.user]);
157
+ return { kind: "local", urls, user: () => user, token: token(urls.backend) };
158
+ };
159
+ exports.localPlatform = localPlatform;
@@ -0,0 +1,302 @@
1
+ import type { AiUsageRecord } from "./aiUsage.js";
2
+ export type Role = {
3
+ id: string;
4
+ name: string;
5
+ };
6
+ /** As classic's `context.user`, plus `name`. */
7
+ export type User = {
8
+ id: string;
9
+ email: string;
10
+ /** First and last name, or the email when neither is set. */
11
+ name: string;
12
+ firstName?: string;
13
+ lastName?: string;
14
+ /** The built-in roles, then the ones assigned on the Members tab. */
15
+ roles: ReadonlyArray<Role>;
16
+ /** A member of the workspace's team, not an external user. */
17
+ isInternal: boolean;
18
+ };
19
+ /** One server function call, as the platform's run log shows it. Input and output are truncated JSON. */
20
+ export type RunRecord = {
21
+ fn: string;
22
+ name?: string;
23
+ nested: boolean;
24
+ startedAt: number;
25
+ durationMs: number;
26
+ input?: string;
27
+ output?: string;
28
+ error?: {
29
+ code: string;
30
+ message: string;
31
+ stack?: string;
32
+ };
33
+ /** A workflow's steps, as they ran, replayed or failed. */
34
+ steps?: {
35
+ name: string;
36
+ status: "ran" | "memoized" | "failed";
37
+ durationMs?: number;
38
+ at: number;
39
+ }[];
40
+ /** The step a failed workflow stopped in, where a resume picks up. */
41
+ failedStep?: string;
42
+ };
43
+ export type AccessKind = "signedIn" | "anyone" | "webhook" | "workflow";
44
+ /** One data, integration or email call. Who is calling is the platform's to know, never the app's to say. */
45
+ export type PlatformCallInput = {
46
+ integrationId: string;
47
+ className: string;
48
+ methodName: string;
49
+ params: unknown;
50
+ /** The access decision the call ran under; the platform may narrow on it but never widens. */
51
+ access: AccessKind;
52
+ };
53
+ /** A call's answer. Errors come back as values, so the one the app sees keeps its code. */
54
+ export type PlatformCallResult = {
55
+ value: unknown;
56
+ } | {
57
+ error: {
58
+ code: string;
59
+ message: string;
60
+ userFacingMessage?: string;
61
+ };
62
+ };
63
+ /** One data call the app's own dispatch made, for its run's detail. */
64
+ export type CallRecord = {
65
+ integrationId: string;
66
+ className: string;
67
+ methodName: string;
68
+ at: number;
69
+ durationMs: number;
70
+ inputs?: string;
71
+ outputs?: string;
72
+ error?: {
73
+ code: string;
74
+ message: string;
75
+ };
76
+ };
77
+ /** An outbound fetch, by host and path (never its query), with the connection whose token it carried. */
78
+ export type FetchRecord = {
79
+ at: number;
80
+ method: string;
81
+ /** Whole, with every secret the request knows redacted. */
82
+ url: string;
83
+ /** As classic's run log shows it: cut short, secrets redacted. */
84
+ requestBody?: string;
85
+ status?: number;
86
+ durationMs: number;
87
+ error?: string;
88
+ connection?: string;
89
+ /** Sent again with a refreshed token after a 401. */
90
+ retried?: true;
91
+ /** On Zite's own AI key, which the platform meters itself. */
92
+ ziteAi?: true;
93
+ /** What a call on the org's own AI key used, for analytics. */
94
+ ai?: AiUsageRecord;
95
+ };
96
+ /**
97
+ * Where the platform's services answer this app: `aiGateway` takes calls on Zite's AI key, `runs` a live page's
98
+ * analytics and each request's run detail. `email`, `pdf`, `uploads` (the upload session) and `steps` (a workflow
99
+ * run's saved steps) are each that service's own endpoint, which the platform picks per workspace; without one, the
100
+ * backend's route answers it.
101
+ */
102
+ export type PlatformUrls = {
103
+ baseRunner: string;
104
+ backend: string;
105
+ aiGateway?: string;
106
+ runs?: string;
107
+ email?: string;
108
+ pdf?: string;
109
+ uploads?: string;
110
+ steps?: string;
111
+ };
112
+ /**
113
+ * Where the platform is for one request, and what reaches it: Zite's dispatcher through props, or a developer's
114
+ * machine through env. The only zitejs code that knows which.
115
+ */
116
+ export type PlatformProvider = {
117
+ kind: "zite" | "local";
118
+ /** The request's app token, renewed when it's about to expire; undefined when the host sent none. */
119
+ token(): Promise<string | undefined>;
120
+ user(): User | null;
121
+ urls: PlatformUrls | undefined;
122
+ };
123
+ /**
124
+ * What the host hands each request beside its app token: the token's renewal, for an answer that outlives the one it
125
+ * was dispatched with. Its presence in props is what marks a request the host dispatched.
126
+ */
127
+ export type PlatformBinding = {
128
+ /** The request's app token, signed again when it's about to expire; null once it can't be. */
129
+ appToken(): Promise<string | null>;
130
+ };
131
+ /** A demo is the published build serving a read-only visitor: as live, but every write is refused. */
132
+ export type HostMode = "live" | "preview" | "demo" | "validate";
133
+ /**
134
+ * The build's page settings, as the platform baked them at publish from the app's settings and name. What the settings
135
+ * set (`seo*`, `favicon`, an installable app's) replaces what a page sets; the rest fills what it leaves out.
136
+ */
137
+ export type PagePlan = {
138
+ fallbackTitle: string;
139
+ seoTitle?: string;
140
+ fallbackDescription: string;
141
+ seoDescription?: string;
142
+ /** A social image: the app's thumbnail, else its screenshot. */
143
+ image?: string;
144
+ seoImage?: string;
145
+ favicon?: string;
146
+ /** For a page with no icon of its own and none configured. */
147
+ defaultFavicon: string;
148
+ /** An installable app's; unset otherwise. */
149
+ appleTouchIcon?: string;
150
+ /** Served at `/manifest.webmanifest` when the app is installable. */
151
+ manifest: {
152
+ theme_color: string;
153
+ short_name: string;
154
+ } | null;
155
+ };
156
+ /** `ZiteMeta.getWorkspace()`'s answer: where the app and its workspace are in Zite. */
157
+ export type ZiteWorkspace = {
158
+ workspaceHomeUrl: string;
159
+ editorUrl: string;
160
+ appPublicIdentifier: string;
161
+ projectPublicIdentifier: string;
162
+ };
163
+ /** A marketplace demo's listing, which the platform's runtime shows the visitor. */
164
+ export type DemoListing = {
165
+ listingSlug: string;
166
+ listingUrl: string;
167
+ };
168
+ /** What the platform adds to every page's head. A host that sends none writes its tags into the HTML itself. */
169
+ export type HostPage = {
170
+ plan: PagePlan;
171
+ /** The platform's runtime script, which the editor's preview and the badge run on. */
172
+ runtimeUrl?: string;
173
+ demo?: DemoListing;
174
+ };
175
+ /** The platform's head entries for one request, as the page renders them and carries them to the browser. */
176
+ export type PlatformHead = {
177
+ title: string;
178
+ description: string;
179
+ image?: string;
180
+ icon: string;
181
+ /** Which of those the app's settings set, so they replace what a page sets. */
182
+ fromSettings: {
183
+ title: boolean;
184
+ description: boolean;
185
+ image: boolean;
186
+ icon: boolean;
187
+ };
188
+ /** An installable app's, which replaces a page's own as its manifest and app metadata do. */
189
+ appleTouchIcon?: string;
190
+ manifest?: {
191
+ themeColor: string;
192
+ shortName: string;
193
+ };
194
+ runtimeUrl?: string;
195
+ demo?: DemoListing;
196
+ /** Zite's badge, as the org's plan says. */
197
+ branding: boolean;
198
+ analytics: {
199
+ appId: string;
200
+ enabled: boolean;
201
+ endpointUrl: string;
202
+ };
203
+ };
204
+ export type HostInvoke = {
205
+ kind: "webhook" | "describe" | "workflow" | "register" | "warm" | "authHook" | "function";
206
+ name: string;
207
+ };
208
+ /** The per-request props the host dispatches with. Only the host can set them. */
209
+ export type HostProps = {
210
+ platform: PlatformBinding;
211
+ requestId: string;
212
+ user: User | null;
213
+ mode: HostMode;
214
+ invoke: HostInvoke | null;
215
+ /** The app's live URL, demo included: `process.env.ZITE_APP_URL`. */
216
+ appUrl?: string;
217
+ /** The app's database: `process.env.ZITE_BASE_ID`. */
218
+ baseId?: string;
219
+ /** An editor preview's access, which zitejs keeps on the app's links and calls. */
220
+ previewClaim?: string;
221
+ /** `process.env` as classic sets it: connections' vars, then the user's own secrets. */
222
+ env?: Record<string, string>;
223
+ /** Which connection each token var in `env` holds. */
224
+ envConnections?: Record<string, string>;
225
+ /** Each connection's service, which the calls made with its token are counted under. */
226
+ connectionServices?: Record<string, string>;
227
+ /** A resumed run's first attempt, whose saved steps it replays. */
228
+ runRoot?: string;
229
+ /** This request's app token, sent only to `urls`. */
230
+ appToken?: string;
231
+ urls?: PlatformUrls;
232
+ /** Sent with a page or route request by a host that leaves its head to zitejs. */
233
+ page?: HostPage;
234
+ /** The app's access mode, from the platform's records: an internal app serves no page or call to nobody. */
235
+ accessMode?: "internal" | "external";
236
+ /** `ZiteMeta.getWorkspace()`'s answer, from the build's config; absent for a build published before it was kept. */
237
+ workspace?: ZiteWorkspace;
238
+ /**
239
+ * `integrations.get`'s answers, by connection name, real as classic's, when the host already loaded them for the
240
+ * request: a registration's one connection, and none for a demo. Without them the app asks the backend on its token.
241
+ */
242
+ connections?: Record<string, Record<string, unknown>>;
243
+ };
244
+ /** What the host resolved for this request. Set by the generated server entry, never by the browser. */
245
+ export type HostRequestState = {
246
+ requestId: string;
247
+ url: string;
248
+ user: User | null;
249
+ mode: HostMode;
250
+ invoke: HostInvoke | null;
251
+ appUrl?: string;
252
+ baseId?: string;
253
+ previewClaim?: string;
254
+ /** Classic's connection env vars the host sent, set into `process.env` for the request. */
255
+ env?: Record<string, string>;
256
+ envConnections?: Record<string, string>;
257
+ connectionServices?: Record<string, string>;
258
+ /** A resumed run's first attempt, whose saved steps it replays. */
259
+ runRoot?: string;
260
+ /** The connection each token this request was handed belongs to. */
261
+ connectionTokens?: Map<string, string>;
262
+ /** `integrations.get`'s answers this request, by name. */
263
+ connectionAnswers?: Map<string, unknown>;
264
+ /** One refresh per connection per request, however many calls got a 401. */
265
+ refreshing?: Map<string, Promise<string | undefined>>;
266
+ /** The outbound fetches, flushed with its runs. */
267
+ fetches?: FetchRecord[];
268
+ /** The secrets its fetch log redacts, longest first; cleared when a connection is learned. */
269
+ secretValues?: string[];
270
+ /** The isolate's refresh count `secretValues` was read at. */
271
+ secretsAt?: number;
272
+ /** How much of its fetch log is bodies so far. */
273
+ fetchLogChars?: number;
274
+ /** Filled by run capture, flushed to the platform once the response ends. */
275
+ runs: RunRecord[];
276
+ /** The data calls this request made, flushed with its runs. */
277
+ calls?: CallRecord[];
278
+ /** This request's Airtable reads, so the same one twice goes out once. */
279
+ airtableReads?: Map<string, Promise<unknown>>;
280
+ /** Records still reading a copy of a body; the flush waits for them. */
281
+ pending?: Promise<void>[];
282
+ provider?: PlatformProvider;
283
+ /** The request context's, which keeps a send going after the response. */
284
+ waitUntil?: (promise: Promise<unknown>) => void;
285
+ /** This request's base-runner calls in flight, capped as the host once capped them; base-runner's per-app bucket bounds the app. */
286
+ dataSlots?: {
287
+ data: () => Promise<() => void>;
288
+ sql: () => Promise<() => void>;
289
+ };
290
+ /** This request's calls on Zite's AI key waiting on the gateway's answer, capped as the host once capped them. */
291
+ aiSlots?: () => Promise<() => void>;
292
+ /** This request's router, so a page's status can follow the error it rendered. */
293
+ router?: unknown;
294
+ /** The platform's head entries for its pages; unset when the host writes them itself. */
295
+ head?: PlatformHead;
296
+ workspace?: ZiteWorkspace;
297
+ connections?: Record<string, Record<string, unknown>>;
298
+ /** The backend's connections, asked once this request when the host didn't hand them over. */
299
+ connectionsLoad?: Promise<{
300
+ connections: Record<string, Record<string, unknown>>;
301
+ }>;
302
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -13,7 +13,6 @@ exports.generateIntegrationsIndex = generateIntegrationsIndex;
13
13
  const parser_1 = require("@babel/parser");
14
14
  const sdkNames_js_1 = require("./sdkNames.js");
15
15
  const rules_js_1 = require("../integrations/rules.js");
16
- const AUTH_USERS_TABLE_ID = "zite_user";
17
16
  /**
18
17
  * What a field's value looks like when a record is READ back.
19
18
  *
@@ -353,62 +352,36 @@ function fieldJsdoc(schemaField, table, schema) {
353
352
  * name stability across schema changes.
354
353
  */
355
354
  function generateSchema(database, existingSchema) {
356
- const existingTableById = new Map();
357
- for (const t of existingSchema?.tables ?? []) {
358
- existingTableById.set(t.id, t);
359
- }
360
- const drafts = [];
361
- for (const table of database.tables) {
362
- if (table.id === AUTH_USERS_TABLE_ID)
363
- continue;
364
- const existingTable = existingTableById.get(table.id);
365
- const existingFieldById = new Map();
366
- for (const f of existingTable?.fields ?? []) {
367
- existingFieldById.set(f.id, f);
355
+ // A name from the existing schema is locked: it is what the app is compiling
356
+ // against, and only moves if it is reserved or collides.
357
+ const { names, renames } = (0, sdkNames_js_1.allocateLiveNames)(database.tables, existingSchema);
358
+ if (renames.length > 0) {
359
+ // Never silent: a rename means the accessor a developer would reach for is
360
+ // not the one that got emitted.
361
+ for (const line of (0, sdkNames_js_1.describeRenames)(renames)) {
362
+ console.warn(`[zitejs] SDK name collision resolved: ${line}`);
368
363
  }
369
- // `sdkName` is filled in by `allocateSchemaNames` below; the draft carries
370
- // what each name would like to be and whether user code already depends on
371
- // it. A name from the existing schema is locked — it is what the app is
372
- // compiling against — and only moves if it is reserved or collides.
373
- const fields = table.fields.map((field) => {
374
- const existing = (0, sdkNames_js_1.keepValidSdkName)(existingFieldById.get(field.id)?.sdkName);
375
- const { id: _id, order: _order, ...definition } = field;
364
+ }
365
+ const liveTables = new Map(database.tables.map((table) => [table.id, table]));
366
+ return {
367
+ tables: names.tables.map((named) => {
368
+ const table = liveTables.get(named.id);
369
+ const liveFields = new Map(table.fields.map((field) => [field.id, field]));
376
370
  return {
377
- field: { id: field.id, sdkName: "", definition },
378
- draft: {
379
- preferred: existing ?? (0, sdkNames_js_1.toSdkName)(field.name),
380
- locked: existing !== undefined,
381
- },
382
- };
383
- });
384
- const existingName = (0, sdkNames_js_1.keepValidSdkName)(existingTable?.sdkName);
385
- drafts.push({
386
- table: {
387
371
  id: table.id,
388
- sdkName: "",
372
+ sdkName: named.sdkName,
389
373
  // Always the live name — never `existingTable?.name`. Locking it the way
390
374
  // `sdkName` is locked would freeze it at the first name the table ever
391
375
  // had, which is the one thing this is here to avoid.
392
376
  name: table.name,
393
377
  primaryFieldId: table.primaryFieldId,
394
- fields: [],
395
- },
396
- draft: {
397
- preferred: existingName ?? (0, sdkNames_js_1.toSdkName)(table.name),
398
- locked: existingName !== undefined,
399
- },
400
- fields,
401
- });
402
- }
403
- const { tables, renames } = (0, sdkNames_js_1.allocateSchemaNames)(drafts);
404
- if (renames.length > 0) {
405
- // Never silent: a rename means the accessor a developer would reach for is
406
- // not the one that got emitted.
407
- for (const line of (0, sdkNames_js_1.describeRenames)(renames)) {
408
- console.warn(`[zitejs] SDK name collision resolved: ${line}`);
409
- }
410
- }
411
- return { tables };
378
+ fields: named.fields.map((namedField) => {
379
+ const { id, order: _order, ...definition } = liveFields.get(namedField.id);
380
+ return { id, sdkName: namedField.sdkName, definition };
381
+ }),
382
+ };
383
+ }),
384
+ };
412
385
  }
413
386
  function generateSentinelSdkTypes() {
414
387
  return [
@@ -510,7 +483,7 @@ function generateDbTs(inputSchema, { hasStartApps = false } = {}) {
510
483
  console.warn(`[zitejs] Repaired SDK name in zite.schema.json: ${line}`);
511
484
  }
512
485
  }
513
- const tables = schema.tables.filter((table) => table.id !== AUTH_USERS_TABLE_ID);
486
+ const tables = schema.tables.filter((table) => table.id !== sdkNames_js_1.AUTH_USERS_TABLE_ID);
514
487
  lines.push("// Auto-generated by zitejs generate. Do not edit manually.");
515
488
  lines.push("//");
516
489
  if (hasStartApps) {