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.
- package/dist/cjs/auth/client.d.ts +2 -2
- package/dist/cjs/check/start/sourceRules.js +3 -0
- package/dist/cjs/cli.js +6 -0
- package/dist/cjs/dev/index.js +15 -0
- package/dist/cjs/dev/signin.d.ts +16 -0
- package/dist/cjs/dev/signin.js +76 -0
- package/dist/cjs/internal/appMode.d.ts +11 -0
- package/dist/cjs/internal/appMode.js +4 -1
- package/dist/cjs/internal/appToken.d.ts +17 -0
- package/dist/cjs/internal/appToken.js +26 -0
- package/dist/cjs/internal/platformFetch.d.ts +2 -0
- package/dist/cjs/internal/platformFetch.js +13 -0
- package/dist/cjs/internal/serviceUrls.d.ts +7 -0
- package/dist/cjs/internal/serviceUrls.js +16 -0
- package/dist/cjs/runtime/index.d.ts +1 -1
- package/dist/cjs/start/aiUsage.d.ts +23 -0
- package/dist/cjs/start/aiUsage.js +151 -0
- package/dist/cjs/start/devApp.d.ts +1 -0
- package/dist/cjs/start/devApp.js +6 -0
- package/dist/cjs/start/entries.js +4 -0
- package/dist/cjs/start/provider.d.ts +24 -0
- package/dist/cjs/start/provider.js +159 -0
- package/dist/cjs/start/types.d.ts +302 -0
- package/dist/cjs/start/types.js +2 -0
- package/dist/cjs/sync/lib.js +23 -50
- package/dist/cjs/sync/sdkNames.d.ts +65 -7
- package/dist/cjs/sync/sdkNames.js +76 -12
- package/dist/cjs/sync/sdkNames.test.js +38 -0
- package/dist/cjs/upload/index.js +73 -22
- package/dist/cjs/upload/index.test.js +35 -2
- package/dist/esm/auth/client.d.ts +2 -2
- package/dist/esm/check/start/sourceRules.js +3 -0
- package/dist/esm/cli.js +6 -0
- package/dist/esm/dev/index.js +15 -0
- package/dist/esm/dev/signin.d.ts +16 -0
- package/dist/esm/dev/signin.js +72 -0
- package/dist/esm/internal/appMode.d.ts +11 -0
- package/dist/esm/internal/appMode.js +2 -0
- package/dist/esm/internal/appToken.d.ts +17 -0
- package/dist/esm/internal/appToken.js +22 -0
- package/dist/esm/internal/platformFetch.d.ts +2 -0
- package/dist/esm/internal/platformFetch.js +8 -0
- package/dist/esm/internal/serviceUrls.d.ts +7 -0
- package/dist/esm/internal/serviceUrls.js +12 -0
- package/dist/esm/runtime/index.d.ts +1 -1
- package/dist/esm/signin/conformance.d.ts +100 -0
- package/dist/esm/signin/conformance.js +471 -0
- package/dist/esm/signin/cookies.d.ts +28 -0
- package/dist/esm/signin/cookies.js +59 -0
- package/dist/esm/signin/encoding.d.ts +9 -0
- package/dist/esm/signin/encoding.js +39 -0
- package/dist/esm/signin/endpoints.d.ts +12 -0
- package/dist/esm/signin/endpoints.js +29 -0
- package/dist/esm/signin/http.d.ts +25 -0
- package/dist/esm/signin/http.js +69 -0
- package/dist/esm/signin/index.d.ts +8 -0
- package/dist/esm/signin/index.js +9 -0
- package/dist/esm/signin/keys.d.ts +39 -0
- package/dist/esm/signin/keys.js +80 -0
- package/dist/esm/signin/paths.d.ts +2 -0
- package/dist/esm/signin/paths.js +2 -0
- package/dist/esm/signin/seal.d.ts +8 -0
- package/dist/esm/signin/seal.js +35 -0
- package/dist/esm/signin/signin.d.ts +60 -0
- package/dist/esm/signin/signin.js +340 -0
- package/dist/esm/signin/transport.d.ts +111 -0
- package/dist/esm/signin/transport.js +1 -0
- package/dist/esm/signin/verify.d.ts +77 -0
- package/dist/esm/signin/verify.js +155 -0
- package/dist/esm/start/airtable/built.d.ts +2 -0
- package/dist/esm/start/airtable/built.js +3 -0
- package/dist/esm/start/airtable/index.d.ts +3 -5
- package/dist/esm/start/airtable/index.js +4 -25
- package/dist/esm/start/airtable/settings.d.ts +31 -0
- package/dist/esm/start/airtable/settings.js +110 -0
- package/dist/esm/start/analytics.d.ts +5 -0
- package/dist/esm/start/analytics.js +77 -0
- package/dist/esm/start/data/index.d.ts +21 -9
- package/dist/esm/start/data/index.js +26 -20
- package/dist/esm/start/data/names.d.ts +7 -0
- package/dist/esm/start/data/names.js +15 -0
- package/dist/esm/start/data/types.d.ts +4 -1
- package/dist/esm/start/devApp.d.ts +1 -0
- package/dist/esm/start/devApp.js +3 -0
- package/dist/esm/start/devSignIn.d.ts +1 -0
- package/dist/esm/start/devSignIn.js +3 -0
- package/dist/esm/start/direct.d.ts +44 -0
- package/dist/esm/start/direct.js +442 -0
- package/dist/esm/start/entries.js +4 -0
- package/dist/esm/start/fetch.d.ts +1 -0
- package/dist/esm/start/fetch.js +4 -0
- package/dist/esm/start/instance.js +6 -2
- package/dist/esm/start/localSignIn.d.ts +18 -0
- package/dist/esm/start/localSignIn.js +73 -0
- package/dist/esm/start/outbound.d.ts +9 -1
- package/dist/esm/start/outbound.js +130 -31
- package/dist/esm/start/pageHead.d.ts +36 -0
- package/dist/esm/start/pageHead.js +178 -0
- package/dist/esm/start/provider.d.ts +24 -0
- package/dist/esm/start/provider.js +150 -0
- package/dist/esm/start/router.d.ts +6 -2
- package/dist/esm/start/router.js +41 -2
- package/dist/esm/start/server.d.ts +23 -12
- package/dist/esm/start/server.js +185 -56
- package/dist/esm/start/telemetry.d.ts +13 -0
- package/dist/esm/start/telemetry.js +71 -0
- package/dist/esm/start/types.d.ts +141 -44
- package/dist/esm/start/uploads.d.ts +2 -0
- package/dist/esm/start/uploads.js +52 -0
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/dist/esm/start/vite.d.ts +18 -1
- package/dist/esm/start/vite.js +163 -4
- package/dist/esm/start/workspaceSchema.d.ts +2 -0
- package/dist/esm/start/workspaceSchema.js +3 -0
- package/dist/esm/sync/lib.js +23 -50
- package/dist/esm/sync/sdkNames.d.ts +65 -7
- package/dist/esm/sync/sdkNames.js +73 -11
- package/dist/esm/sync/sdkNames.test.js +38 -0
- package/dist/esm/upload/index.js +74 -23
- package/dist/esm/upload/index.test.js +35 -2
- package/package.json +22 -12
- package/dist/cjs/auth-server/index.d.ts +0 -369
- package/dist/cjs/auth-server/index.js +0 -119
- package/dist/esm/auth-server/index.d.ts +0 -369
- package/dist/esm/auth-server/index.js +0 -116
- package/dist/esm/start/problems.d.ts +0 -19
- package/dist/esm/start/problems.js +0 -8
|
@@ -50,10 +50,7 @@ export type PlatformCallInput = {
|
|
|
50
50
|
/** The access decision the call ran under; the platform may narrow on it but never widens. */
|
|
51
51
|
access: AccessKind;
|
|
52
52
|
};
|
|
53
|
-
/**
|
|
54
|
-
* A call's answer. Errors come back as values: Workers RPC keeps a thrown
|
|
55
|
-
* error's message but drops its code.
|
|
56
|
-
*/
|
|
53
|
+
/** A call's answer. Errors come back as values, so the one the app sees keeps its code. */
|
|
57
54
|
export type PlatformCallResult = {
|
|
58
55
|
value: unknown;
|
|
59
56
|
} | {
|
|
@@ -91,52 +88,119 @@ export type FetchRecord = {
|
|
|
91
88
|
connection?: string;
|
|
92
89
|
/** Sent again with a refreshed token after a 401. */
|
|
93
90
|
retried?: true;
|
|
94
|
-
/** On Zite's own AI key, which the
|
|
91
|
+
/** On Zite's own AI key, which the platform meters itself. */
|
|
95
92
|
ziteAi?: true;
|
|
96
93
|
/** What a call on the org's own AI key used, for analytics. */
|
|
97
94
|
ai?: AiUsageRecord;
|
|
98
95
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
+
*/
|
|
130
127
|
export type PlatformBinding = {
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
/** One batch per request, after its response has ended. */
|
|
134
|
-
runs(batch: {
|
|
135
|
-
runs: RunRecord[];
|
|
136
|
-
}): Promise<void>;
|
|
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>;
|
|
137
130
|
};
|
|
138
131
|
/** A demo is the published build serving a read-only visitor: as live, but every write is refused. */
|
|
139
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
|
+
};
|
|
140
204
|
export type HostInvoke = {
|
|
141
205
|
kind: "webhook" | "describe" | "workflow" | "register" | "warm" | "authHook" | "function";
|
|
142
206
|
name: string;
|
|
@@ -158,8 +222,24 @@ export type HostProps = {
|
|
|
158
222
|
env?: Record<string, string>;
|
|
159
223
|
/** Which connection each token var in `env` holds. */
|
|
160
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>;
|
|
161
227
|
/** A resumed run's first attempt, whose saved steps it replays. */
|
|
162
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>>;
|
|
163
243
|
};
|
|
164
244
|
/** What the host resolved for this request. Set by the generated server entry, never by the browser. */
|
|
165
245
|
export type HostRequestState = {
|
|
@@ -174,6 +254,7 @@ export type HostRequestState = {
|
|
|
174
254
|
/** Classic's connection env vars the host sent, set into `process.env` for the request. */
|
|
175
255
|
env?: Record<string, string>;
|
|
176
256
|
envConnections?: Record<string, string>;
|
|
257
|
+
connectionServices?: Record<string, string>;
|
|
177
258
|
/** A resumed run's first attempt, whose saved steps it replays. */
|
|
178
259
|
runRoot?: string;
|
|
179
260
|
/** The connection each token this request was handed belongs to. */
|
|
@@ -198,8 +279,24 @@ export type HostRequestState = {
|
|
|
198
279
|
airtableReads?: Map<string, Promise<unknown>>;
|
|
199
280
|
/** Records still reading a copy of a body; the flush waits for them. */
|
|
200
281
|
pending?: Promise<void>[];
|
|
201
|
-
|
|
202
|
-
|
|
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>;
|
|
203
292
|
/** This request's router, so a page's status can follow the error it rendered. */
|
|
204
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
|
+
}>;
|
|
205
302
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// A Start page's upload session, asked of the app's own origin: the app's server asks the platform's uploads service on
|
|
2
|
+
// the request's token, which says the app and the mode, so neither the token nor a platform host reaches the browser.
|
|
3
|
+
import { platformFetch } from "../internal/platformFetch.js";
|
|
4
|
+
import { serviceUrl } from "../internal/serviceUrls.js";
|
|
5
|
+
import { textUpTo } from "./analytics.js";
|
|
6
|
+
import { directAccess } from "./direct.js";
|
|
7
|
+
const MAX_SESSION_BYTES = 16 * 1024;
|
|
8
|
+
const UPLOADS_TIMEOUT_MS = 15_000;
|
|
9
|
+
const refused = (status, message) => Response.json({ success: false, message }, { status });
|
|
10
|
+
// As the app's own routes are checked (instance.ts): a cookie rides only on a request from the app's own pages.
|
|
11
|
+
const crossSite = (request) => {
|
|
12
|
+
if (!request.headers.has("cookie"))
|
|
13
|
+
return false;
|
|
14
|
+
const site = request.headers.get("sec-fetch-site");
|
|
15
|
+
if (site !== null)
|
|
16
|
+
return site !== "same-origin";
|
|
17
|
+
return request.headers.get("origin") !== new URL(request.url).origin;
|
|
18
|
+
};
|
|
19
|
+
const sessionBody = (raw) => {
|
|
20
|
+
try {
|
|
21
|
+
const { filename, uploadLength, contentType } = JSON.parse(raw ?? "");
|
|
22
|
+
return JSON.stringify({ filename, uploadLength, contentType });
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export const takeUploadSession = async (request, host) => {
|
|
29
|
+
if (request.method !== "POST")
|
|
30
|
+
return new Response("Method not allowed", { status: 405 });
|
|
31
|
+
if (crossSite(request))
|
|
32
|
+
return refused(403, "Forbidden");
|
|
33
|
+
const access = await directAccess(host);
|
|
34
|
+
if (!access)
|
|
35
|
+
return refused(503, "Uploads need the platform's app token, and this request has none");
|
|
36
|
+
const body = sessionBody(await textUpTo(request, MAX_SESSION_BYTES));
|
|
37
|
+
if (body === undefined)
|
|
38
|
+
return refused(400, "Invalid upload session request");
|
|
39
|
+
try {
|
|
40
|
+
const answer = await platformFetch(new Request(serviceUrl(access.urls, "uploads"), {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { authorization: `Bearer ${access.token}`, "content-type": "application/json" },
|
|
43
|
+
body,
|
|
44
|
+
signal: AbortSignal.timeout(UPLOADS_TIMEOUT_MS),
|
|
45
|
+
}));
|
|
46
|
+
return new Response(answer.body, { status: answer.status, headers: { "content-type": "application/json" } });
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error("[zite] the upload session failed", error);
|
|
50
|
+
return refused(502, "Upload failed");
|
|
51
|
+
}
|
|
52
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.0-start.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.0-start.23";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = "0.10.0-start.
|
|
2
|
+
export const ZITEJS_VERSION = "0.10.0-start.23";
|
package/dist/esm/start/vite.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type PluginOption } from "vite";
|
|
2
|
+
import type { ZiteSchema } from "../sync/lib.js";
|
|
3
|
+
import { type SchemaNames } from "../sync/sdkNames.js";
|
|
4
|
+
import { type BuiltAirtableSettings } from "./airtable/settings.js";
|
|
5
|
+
import type { DataNameMappings } from "./data/types.js";
|
|
6
|
+
/** @internal The workspace's zite.schema.json as a server build carries it; null without one, a throw for one it can't read. */
|
|
7
|
+
export declare const workspaceSchemaNamesOf: (appDir: string) => SchemaNames | null;
|
|
8
|
+
/** @internal The app's Airtable integrations, from its own and its workspace's zite.config.json and zite.lock. */
|
|
9
|
+
export declare const builtAirtableSettingsOf: (appDir: string) => Record<string, BuiltAirtableSettings>;
|
|
10
|
+
/** @internal A workspace's zite.schema.json as the platform's `nameMappings`: the SDK names `.zite/db.ts` was generated with. */
|
|
11
|
+
export declare const workspaceNameMappingsOf: (raw: ZiteSchema) => DataNameMappings;
|
|
12
|
+
/**
|
|
13
|
+
* @internal The sign-in settings `zitejs dev` wrote for the app, for the module `local` mounts; null without them, or
|
|
14
|
+
* when the app's env sets `ZITE_DEV_USER`, whose stand-in wins.
|
|
15
|
+
*/
|
|
16
|
+
export declare const devSignInOf: (appDir: string, appEnv: Record<string, string | undefined>) => Record<string, string> | null;
|
|
17
|
+
/** @internal The app's id in its zite.config.json, which `local` mints dev tokens for; null without one. */
|
|
18
|
+
export declare const devAppIdOf: (appDir: string) => string | null;
|
|
2
19
|
export type ZiteOptions = {
|
|
3
20
|
/** A server entry the caller owns, relative to the app root. By default zite() writes the platform's. */
|
|
4
21
|
serverEntry?: string;
|
package/dist/esm/start/vite.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { loadEnv } from "vite";
|
|
4
|
+
import { parse as parseEnv } from "dotenv";
|
|
3
5
|
import { tanstackStart } from "@tanstack/react-start/plugin/vite";
|
|
4
6
|
import viteReact from "@vitejs/plugin-react";
|
|
5
7
|
import { ziteId } from "../vite/index.js";
|
|
8
|
+
import { schemaNamesOf } from "../sync/sdkNames.js";
|
|
9
|
+
import { nameMappingsOf } from "./data/names.js";
|
|
10
|
+
import { airtableSettingsFrom } from "./airtable/settings.js";
|
|
6
11
|
import { factoryDescriptions } from "./descriptions.js";
|
|
7
12
|
import { registrationHashes } from "./registrationHash.js";
|
|
8
13
|
import { hasAppStart, renderStartInstance, renderStartServerEntry, renderWorkflowModules, START_INSTANCE_ENTRY, START_SERVER_ENTRY, workflowFiles, writeIfChanged, } from "./entries.js";
|
|
@@ -18,6 +23,22 @@ const WORKFLOW_REGISTRY = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]workflowMo
|
|
|
18
23
|
// zitejs's null auth-hooks module, which the build points at the app's `zite.auth.ts`.
|
|
19
24
|
const AUTH_HOOKS_REGISTRY = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]authHooksModule\.js$/;
|
|
20
25
|
const AUTH_HOOKS_FILE = "zite.auth.ts";
|
|
26
|
+
// zitejs's null workspace names, which a server build and `vite dev` fill from the workspace root, where `zitejs/db`
|
|
27
|
+
// comes from too.
|
|
28
|
+
const WORKSPACE_SCHEMA_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]workspaceSchema\.js$/;
|
|
29
|
+
const WORKSPACE_SCHEMA_FILE = "../../zite.schema.json";
|
|
30
|
+
// zitejs's null Airtable settings, which a server build and `vite dev` fill from the app's and the workspace's config.
|
|
31
|
+
const AIRTABLE_SETTINGS_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]airtable[\\/]built\.js$/;
|
|
32
|
+
const APP_LOCK_FILE = "zite.lock";
|
|
33
|
+
const WORKSPACE_CONFIG_FILE = "../../zite.config.json";
|
|
34
|
+
const WORKSPACE_LOCK_FILE = "../../zite.lock";
|
|
35
|
+
// zitejs's null app id, which `vite dev` fills from the app's zite.config.json.
|
|
36
|
+
const DEV_APP_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]devApp\.js$/;
|
|
37
|
+
// zitejs's null sign-in settings, which `vite dev` fills from the `.zite/dev.env` that `zitejs dev` writes.
|
|
38
|
+
const DEV_SIGNIN_MODULE = /[\\/]zitejs[\\/]dist[\\/]esm[\\/]start[\\/]devSignIn\.js$/;
|
|
39
|
+
const DEV_ENV_FILE = ".zite/dev.env";
|
|
40
|
+
const DEV_SIGNIN_KEYS = ["ZITE_SIGNIN", "ZITE_AUTH_SECRET"];
|
|
41
|
+
const APP_CONFIG_FILE = "zite.config.json";
|
|
21
42
|
const SOURCE_LANGS = {
|
|
22
43
|
".ts": "ts",
|
|
23
44
|
".mts": "ts",
|
|
@@ -28,6 +49,64 @@ const SOURCE_LANGS = {
|
|
|
28
49
|
".cjs": "js",
|
|
29
50
|
".jsx": "jsx",
|
|
30
51
|
};
|
|
52
|
+
/** @internal The workspace's zite.schema.json as a server build carries it; null without one, a throw for one it can't read. */
|
|
53
|
+
export const workspaceSchemaNamesOf = (appDir) => {
|
|
54
|
+
const file = path.join(appDir, WORKSPACE_SCHEMA_FILE);
|
|
55
|
+
if (!existsSync(file))
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
return schemaNamesOf(JSON.parse(readFileSync(file, "utf-8")));
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new Error(`[zite] the workspace's zite.schema.json can't be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// As the platform reads them: a file that isn't there or isn't JSON is none.
|
|
65
|
+
const readJson = (file) => {
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(readFileSync(file, "utf-8"));
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/** @internal The app's Airtable integrations, from its own and its workspace's zite.config.json and zite.lock. */
|
|
74
|
+
export const builtAirtableSettingsOf = (appDir) => airtableSettingsFrom({
|
|
75
|
+
appConfig: readJson(path.join(appDir, APP_CONFIG_FILE)),
|
|
76
|
+
appLock: readJson(path.join(appDir, APP_LOCK_FILE)),
|
|
77
|
+
workspaceConfig: readJson(path.join(appDir, WORKSPACE_CONFIG_FILE)),
|
|
78
|
+
workspaceLock: readJson(path.join(appDir, WORKSPACE_LOCK_FILE)),
|
|
79
|
+
hasSchema: existsSync(path.join(appDir, WORKSPACE_SCHEMA_FILE)),
|
|
80
|
+
});
|
|
81
|
+
/** @internal A workspace's zite.schema.json as the platform's `nameMappings`: the SDK names `.zite/db.ts` was generated with. */
|
|
82
|
+
export const workspaceNameMappingsOf = (raw) => nameMappingsOf(schemaNamesOf(raw));
|
|
83
|
+
/**
|
|
84
|
+
* @internal The sign-in settings `zitejs dev` wrote for the app, for the module `local` mounts; null without them, or
|
|
85
|
+
* when the app's env sets `ZITE_DEV_USER`, whose stand-in wins.
|
|
86
|
+
*/
|
|
87
|
+
export const devSignInOf = (appDir, appEnv) => {
|
|
88
|
+
if (appEnv.ZITE_DEV_USER)
|
|
89
|
+
return null;
|
|
90
|
+
let written;
|
|
91
|
+
try {
|
|
92
|
+
written = parseEnv(readFileSync(path.join(appDir, DEV_ENV_FILE), "utf-8"));
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const kept = Object.fromEntries(DEV_SIGNIN_KEYS.flatMap((key) => (written[key] ? [[key, written[key]]] : [])));
|
|
98
|
+
return kept.ZITE_SIGNIN ? kept : null;
|
|
99
|
+
};
|
|
100
|
+
/** @internal The app's id in its zite.config.json, which `local` mints dev tokens for; null without one. */
|
|
101
|
+
export const devAppIdOf = (appDir) => {
|
|
102
|
+
try {
|
|
103
|
+
const { id } = JSON.parse(readFileSync(path.join(appDir, APP_CONFIG_FILE), "utf-8"));
|
|
104
|
+
return typeof id === "string" && id ? id : null;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
31
110
|
// Platform-pinned Worker settings. The deploy uses its own fixed template, so
|
|
32
111
|
// these only have to match it; apps don't carry a wrangler config.
|
|
33
112
|
const WORKER_COMPATIBILITY_DATE = "2026-09-25";
|
|
@@ -63,8 +142,12 @@ export function zite(options = {}) {
|
|
|
63
142
|
// The peer dependency gets zitejs crawled already; this keeps it true if an
|
|
64
143
|
// install drops that. A Node build bundles everything, so externalized
|
|
65
144
|
// libraries can't load the root's React 18 renderer.
|
|
66
|
-
config: (config) => {
|
|
145
|
+
config: (config, { command, mode }) => {
|
|
67
146
|
const root = path.resolve(config.root ?? ".");
|
|
147
|
+
// The `local` provider reads process.env. In workerd, Cloudflare's plugin sets it from the app's .env; on Node, this does.
|
|
148
|
+
if (command === "serve" && options.cloudflare === false) {
|
|
149
|
+
Object.assign(process.env, loadEnv(mode, root, ["ZITE_DEV_", "ZITE_URLS", "ZITE_SIGNIN", "ZITE_AUTH_SECRET"]));
|
|
150
|
+
}
|
|
68
151
|
const src = `${path.join(root, "src")}/`;
|
|
69
152
|
return {
|
|
70
153
|
ssr: { noExternal: options.cloudflare === false ? true : ["zitejs"] },
|
|
@@ -87,8 +170,15 @@ export function zite(options = {}) {
|
|
|
87
170
|
};
|
|
88
171
|
},
|
|
89
172
|
// Each new isolate loads the whole server bundle, so its size is cold-start
|
|
90
|
-
// time; Vite leaves SSR output unminified.
|
|
91
|
-
|
|
173
|
+
// time; Vite leaves SSR output unminified. Under `vite dev`, Cloudflare's
|
|
174
|
+
// plugin would pre-bundle zitejs's server entry, past the modules below
|
|
175
|
+
// that fill zitejs's registries and workspace names.
|
|
176
|
+
configEnvironment: (name, config, { command }) => name !== "ssr"
|
|
177
|
+
? undefined
|
|
178
|
+
: {
|
|
179
|
+
...(options.cloudflare !== false && config.build?.minify === undefined && { build: { minify: true } }),
|
|
180
|
+
...(command === "serve" && { optimizeDeps: { exclude: ["zitejs"] } }),
|
|
181
|
+
},
|
|
92
182
|
};
|
|
93
183
|
// Each server function's `description` option, by name, and each route's file, by route id: for the editor.
|
|
94
184
|
const descriptions = new Map();
|
|
@@ -174,6 +264,71 @@ export function zite(options = {}) {
|
|
|
174
264
|
: "export const authHooksModule = null;\n";
|
|
175
265
|
},
|
|
176
266
|
};
|
|
267
|
+
// The names the build's `zitejs/db` was generated with, from the same commit's schema. Only the server's: a browser
|
|
268
|
+
// never translates a data call, and its bundle carries no table or field id.
|
|
269
|
+
let serving = false;
|
|
270
|
+
const workspaceSchema = {
|
|
271
|
+
name: "zite:workspace-schema",
|
|
272
|
+
configResolved(config) {
|
|
273
|
+
serving = config.command === "serve";
|
|
274
|
+
},
|
|
275
|
+
load(id) {
|
|
276
|
+
if (!WORKSPACE_SCHEMA_MODULE.test(id.split("?")[0]))
|
|
277
|
+
return undefined;
|
|
278
|
+
this.addWatchFile(path.join(appDir, WORKSPACE_SCHEMA_FILE));
|
|
279
|
+
let names = null;
|
|
280
|
+
try {
|
|
281
|
+
if (this.environment?.config.consumer === "server")
|
|
282
|
+
names = workspaceSchemaNamesOf(appDir);
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
// A build fails rather than ship names its client wasn't written against; `vite dev` carries on mid-edit.
|
|
286
|
+
if (!serving)
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
return `export const workspaceSchemaNames = ${JSON.stringify(names)};\n`;
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
// The integrations the app runs itself, from the same commit's config, and only on the server, which calls them.
|
|
293
|
+
const airtableSettings = {
|
|
294
|
+
name: "zite:airtable-settings",
|
|
295
|
+
load(id) {
|
|
296
|
+
if (!AIRTABLE_SETTINGS_MODULE.test(id.split("?")[0]))
|
|
297
|
+
return undefined;
|
|
298
|
+
for (const file of [APP_CONFIG_FILE, APP_LOCK_FILE, WORKSPACE_CONFIG_FILE, WORKSPACE_LOCK_FILE])
|
|
299
|
+
this.addWatchFile(path.join(appDir, file));
|
|
300
|
+
const settings = this.environment?.config.consumer === "server" ? builtAirtableSettingsOf(appDir) : null;
|
|
301
|
+
return `export const builtAirtableSettings = ${JSON.stringify(settings)};\n`;
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
// Under `vite dev` only: a published build is never `local`'s to mint for.
|
|
305
|
+
const devApp = {
|
|
306
|
+
name: "zite:dev-app",
|
|
307
|
+
apply: "serve",
|
|
308
|
+
load(id) {
|
|
309
|
+
if (!DEV_APP_MODULE.test(id.split("?")[0]))
|
|
310
|
+
return undefined;
|
|
311
|
+
this.addWatchFile(path.join(appDir, APP_CONFIG_FILE));
|
|
312
|
+
return `export const devAppId = ${JSON.stringify(devAppIdOf(appDir))};\n`;
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
// Under `vite dev` only, and only to the server: the secret seals the session cookie, and never reaches a browser.
|
|
316
|
+
let devEnv = {};
|
|
317
|
+
const devSignIn = {
|
|
318
|
+
name: "zite:dev-signin",
|
|
319
|
+
apply: "serve",
|
|
320
|
+
configResolved(config) {
|
|
321
|
+
const envDir = typeof config.envDir === "string" ? config.envDir : config.root;
|
|
322
|
+
devEnv = { ...loadEnv(config.mode, envDir, ["ZITE_DEV_USER"]), ...process.env };
|
|
323
|
+
},
|
|
324
|
+
load(id) {
|
|
325
|
+
if (!DEV_SIGNIN_MODULE.test(id.split("?")[0]))
|
|
326
|
+
return undefined;
|
|
327
|
+
this.addWatchFile(path.join(appDir, DEV_ENV_FILE));
|
|
328
|
+
const settings = this.environment?.config.consumer === "server" ? devSignInOf(appDir, devEnv) : null;
|
|
329
|
+
return `export const devSignIn = ${JSON.stringify(settings)};\n`;
|
|
330
|
+
},
|
|
331
|
+
};
|
|
177
332
|
return [
|
|
178
333
|
// First, so ids name lines in the source, before TanStack splits a route's component out of it.
|
|
179
334
|
ziteId(),
|
|
@@ -199,7 +354,7 @@ export function zite(options = {}) {
|
|
|
199
354
|
behavior: "error",
|
|
200
355
|
client: {
|
|
201
356
|
// Appended to TanStack's own.
|
|
202
|
-
specifiers: ["zitejs/start/server", "zitejs/start/worker", "zitejs/start/describe", "zitejs/runtime"],
|
|
357
|
+
specifiers: ["zitejs/start/fetch", "zitejs/start/server", "zitejs/start/worker", "zitejs/start/describe", "zitejs/signin", "zitejs/runtime"],
|
|
203
358
|
// Replaces TanStack's list, so its `**/*.server.*` is restated. File
|
|
204
359
|
// patterns also catch `zitejs/db`, `zitejs/integrations` and `zitejs/meta`,
|
|
205
360
|
// which the aliases above rewrite before specifiers are matched.
|
|
@@ -213,5 +368,9 @@ export function zite(options = {}) {
|
|
|
213
368
|
functionIds,
|
|
214
369
|
workflowRegistry,
|
|
215
370
|
authHooksRegistry,
|
|
371
|
+
workspaceSchema,
|
|
372
|
+
airtableSettings,
|
|
373
|
+
devApp,
|
|
374
|
+
devSignIn,
|
|
216
375
|
];
|
|
217
376
|
}
|
package/dist/esm/sync/lib.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { parse } from "@babel/parser";
|
|
2
|
-
import {
|
|
2
|
+
import { allocateLiveNames, AUTH_USERS_TABLE_ID, describeRenames, normalizeSchemaNames, SdkNameAllocator, toCamelCase, toPascalCase, } from "./sdkNames.js";
|
|
3
3
|
import { CREDENTIAL_FIELDS, OPTIONAL_CREDENTIAL_FIELDS, } from "../integrations/rules.js";
|
|
4
|
-
const AUTH_USERS_TABLE_ID = "zite_user";
|
|
5
4
|
/**
|
|
6
5
|
* What a field's value looks like when a record is READ back.
|
|
7
6
|
*
|
|
@@ -338,62 +337,36 @@ function fieldJsdoc(schemaField, table, schema) {
|
|
|
338
337
|
* name stability across schema changes.
|
|
339
338
|
*/
|
|
340
339
|
export function generateSchema(database, existingSchema) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const existingTable = existingTableById.get(table.id);
|
|
350
|
-
const existingFieldById = new Map();
|
|
351
|
-
for (const f of existingTable?.fields ?? []) {
|
|
352
|
-
existingFieldById.set(f.id, f);
|
|
340
|
+
// A name from the existing schema is locked: it is what the app is compiling
|
|
341
|
+
// against, and only moves if it is reserved or collides.
|
|
342
|
+
const { names, renames } = allocateLiveNames(database.tables, existingSchema);
|
|
343
|
+
if (renames.length > 0) {
|
|
344
|
+
// Never silent: a rename means the accessor a developer would reach for is
|
|
345
|
+
// not the one that got emitted.
|
|
346
|
+
for (const line of describeRenames(renames)) {
|
|
347
|
+
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
353
348
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const
|
|
360
|
-
const { id: _id, order: _order, ...definition } = field;
|
|
349
|
+
}
|
|
350
|
+
const liveTables = new Map(database.tables.map((table) => [table.id, table]));
|
|
351
|
+
return {
|
|
352
|
+
tables: names.tables.map((named) => {
|
|
353
|
+
const table = liveTables.get(named.id);
|
|
354
|
+
const liveFields = new Map(table.fields.map((field) => [field.id, field]));
|
|
361
355
|
return {
|
|
362
|
-
field: { id: field.id, sdkName: "", definition },
|
|
363
|
-
draft: {
|
|
364
|
-
preferred: existing ?? toSdkName(field.name),
|
|
365
|
-
locked: existing !== undefined,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
});
|
|
369
|
-
const existingName = keepValidSdkName(existingTable?.sdkName);
|
|
370
|
-
drafts.push({
|
|
371
|
-
table: {
|
|
372
356
|
id: table.id,
|
|
373
|
-
sdkName:
|
|
357
|
+
sdkName: named.sdkName,
|
|
374
358
|
// Always the live name — never `existingTable?.name`. Locking it the way
|
|
375
359
|
// `sdkName` is locked would freeze it at the first name the table ever
|
|
376
360
|
// had, which is the one thing this is here to avoid.
|
|
377
361
|
name: table.name,
|
|
378
362
|
primaryFieldId: table.primaryFieldId,
|
|
379
|
-
fields:
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
const { tables, renames } = allocateSchemaNames(drafts);
|
|
389
|
-
if (renames.length > 0) {
|
|
390
|
-
// Never silent: a rename means the accessor a developer would reach for is
|
|
391
|
-
// not the one that got emitted.
|
|
392
|
-
for (const line of describeRenames(renames)) {
|
|
393
|
-
console.warn(`[zitejs] SDK name collision resolved: ${line}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return { tables };
|
|
363
|
+
fields: named.fields.map((namedField) => {
|
|
364
|
+
const { id, order: _order, ...definition } = liveFields.get(namedField.id);
|
|
365
|
+
return { id, sdkName: namedField.sdkName, definition };
|
|
366
|
+
}),
|
|
367
|
+
};
|
|
368
|
+
}),
|
|
369
|
+
};
|
|
397
370
|
}
|
|
398
371
|
function generateSentinelSdkTypes() {
|
|
399
372
|
return [
|