zitejs 0.10.2 → 0.10.4
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/meta/index.d.ts +11 -0
- package/dist/cjs/meta/index.js +14 -0
- package/dist/cjs/start/build/entries.d.ts +5 -8
- package/dist/cjs/start/build/entries.js +25 -32
- package/dist/cjs/start/build/roleIds.d.ts +1 -0
- package/dist/cjs/start/build/roleIds.js +3 -2
- package/dist/cjs/start/describe/schema.d.ts +1 -0
- package/dist/cjs/start/describe/schema.js +2 -0
- package/dist/cjs/start/frames.d.ts +63 -0
- package/dist/cjs/start/frames.js +297 -0
- package/dist/cjs/start/protocol.d.ts +3 -3
- package/dist/cjs/start/protocol.js +10 -6
- package/dist/cjs/start/serve/provider.js +3 -1
- package/dist/cjs/start/types.d.ts +33 -15
- package/dist/esm/meta/index.d.ts +11 -0
- package/dist/esm/meta/index.js +10 -0
- package/dist/esm/start/build/entries.d.ts +5 -8
- package/dist/esm/start/build/entries.js +24 -31
- package/dist/esm/start/build/roleIds.d.ts +1 -0
- package/dist/esm/start/build/roleIds.js +1 -1
- package/dist/esm/start/build/vite.d.ts +1 -1
- package/dist/esm/start/build/vite.js +27 -16
- package/dist/esm/start/describe/describe.d.ts +2 -0
- package/dist/esm/start/describe/describe.js +2 -0
- package/dist/esm/start/describe/schema.d.ts +1 -0
- package/dist/esm/start/describe/schema.js +2 -0
- package/dist/esm/start/entries/node/server.d.ts +3 -0
- package/dist/esm/start/entries/node/server.js +9 -0
- package/dist/esm/start/entries/worker/server.d.ts +3 -0
- package/dist/esm/start/entries/worker/server.js +7 -0
- package/dist/esm/start/frames.d.ts +63 -0
- package/dist/esm/start/frames.js +290 -0
- package/dist/esm/start/platform/runLog.d.ts +4 -2
- package/dist/esm/start/platform/runLog.js +17 -4
- package/dist/esm/start/platform/telemetry.d.ts +6 -7
- package/dist/esm/start/platform/telemetry.js +11 -15
- package/dist/esm/start/protocol.d.ts +3 -3
- package/dist/esm/start/protocol.js +4 -5
- package/dist/esm/start/serve/console.d.ts +5 -0
- package/dist/esm/start/serve/console.js +60 -0
- package/dist/esm/start/serve/fetch.js +4 -1
- package/dist/esm/start/serve/provider.js +3 -1
- package/dist/esm/start/serve/server.d.ts +4 -3
- package/dist/esm/start/serve/server.js +46 -25
- package/dist/esm/start/types.d.ts +33 -15
- package/dist/esm/start/version.d.ts +1 -1
- package/dist/esm/start/version.js +1 -1
- package/package.json +6 -1
- package/tsconfig/start.json +1 -1
|
@@ -2,6 +2,7 @@ import type { StepEventStatus, StepSuspension } from '../steps/index.js';
|
|
|
2
2
|
import type { AiUsageRecord } from './platform/aiUsage.js';
|
|
3
3
|
import type { AirtableCache } from './platform/airtable/cache.js';
|
|
4
4
|
import type { InvokeKind } from './protocol.js';
|
|
5
|
+
import type { ZiteWorkspace } from '../meta/index.js';
|
|
5
6
|
export type Role = {
|
|
6
7
|
id: string;
|
|
7
8
|
name: string;
|
|
@@ -40,6 +41,22 @@ export type RunRecord = {
|
|
|
40
41
|
/** A durable call that stopped short of the end, which the run's next call carries on from. */
|
|
41
42
|
suspended?: StepSuspension;
|
|
42
43
|
};
|
|
44
|
+
/** One console call made while a request ran, as classic's run log keeps it. */
|
|
45
|
+
export type ConsoleRecord = {
|
|
46
|
+
level: 'log' | 'info' | 'warn' | 'error';
|
|
47
|
+
message: string;
|
|
48
|
+
at: number;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* What a request's code reports of itself for its row in the run log: its top-level run, the one that failed if any
|
|
52
|
+
* did, and its console. The host writes the row from what it saw, and adds this.
|
|
53
|
+
*/
|
|
54
|
+
export type RunReport = {
|
|
55
|
+
input?: string;
|
|
56
|
+
output?: string;
|
|
57
|
+
error?: RunRecord['error'];
|
|
58
|
+
console?: ConsoleRecord[];
|
|
59
|
+
};
|
|
43
60
|
/** One step of a workflow call, as zitejs/steps reports it. `failed` marks a replayed final failure. */
|
|
44
61
|
export type StepRecord = {
|
|
45
62
|
name: string;
|
|
@@ -122,9 +139,9 @@ export type FetchRecord = {
|
|
|
122
139
|
};
|
|
123
140
|
/**
|
|
124
141
|
* Where the platform's services answer this app: `gateway` takes calls on a key Zite pays for, `runs` a live page's
|
|
125
|
-
* analytics and each request's
|
|
126
|
-
* saved steps) and `schedules` are each that service's own endpoint, which the platform picks per workspace and
|
|
127
|
-
* host names on every dispatch: a call to one it doesn't name fails.
|
|
142
|
+
* analytics and each request's calls and fetches. `email`, `pdf`, `uploads` (the upload session), `steps` (a workflow
|
|
143
|
+
* run's saved steps) and `schedules` are each that service's own endpoint, which the platform picks per workspace and
|
|
144
|
+
* the host names on every dispatch: a call to one it doesn't name fails.
|
|
128
145
|
*/
|
|
129
146
|
export type PlatformUrls = {
|
|
130
147
|
baseRunner: string;
|
|
@@ -161,8 +178,11 @@ export type ExpiringToken = {
|
|
|
161
178
|
* was dispatched with. Its presence in props is what marks a request the host dispatched.
|
|
162
179
|
*/
|
|
163
180
|
export type PlatformBinding = {
|
|
164
|
-
/**
|
|
165
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Answers the request's app token as an `ExpiringToken`'s JSON, signed again when it's about to expire, or null once
|
|
183
|
+
* it can't be. The host never reads what it's sent.
|
|
184
|
+
*/
|
|
185
|
+
fetch(url: string): Promise<Response>;
|
|
166
186
|
};
|
|
167
187
|
/** A demo is the published build serving a read-only visitor: as live, but every write is refused. */
|
|
168
188
|
export type HostMode = 'live' | 'preview' | 'demo' | 'validate';
|
|
@@ -219,13 +239,7 @@ export type SiteHead = {
|
|
|
219
239
|
/** An installable app's, served at `/manifest.webmanifest`. */
|
|
220
240
|
manifest?: WebManifest;
|
|
221
241
|
};
|
|
222
|
-
|
|
223
|
-
export type ZiteWorkspace = {
|
|
224
|
-
workspaceHomeUrl: string;
|
|
225
|
-
editorUrl: string;
|
|
226
|
-
appPublicIdentifier: string;
|
|
227
|
-
projectPublicIdentifier: string;
|
|
228
|
-
};
|
|
242
|
+
export type { ZiteWorkspace };
|
|
229
243
|
/** A marketplace demo's listing, which the platform's runtime shows the visitor. */
|
|
230
244
|
export type DemoListing = {
|
|
231
245
|
listingSlug: string;
|
|
@@ -337,7 +351,7 @@ export type HostRequestState = {
|
|
|
337
351
|
connectionAnswers?: Map<string, unknown>;
|
|
338
352
|
/** One refresh per connection per request, however many calls got a 401. */
|
|
339
353
|
refreshing?: Map<string, Promise<string | undefined>>;
|
|
340
|
-
/** The outbound fetches,
|
|
354
|
+
/** The outbound fetches, sent with its calls. */
|
|
341
355
|
fetches?: FetchRecord[];
|
|
342
356
|
/** The secrets its fetch log redacts, longest first; cleared when a connection is learned. */
|
|
343
357
|
secretValues?: string[];
|
|
@@ -345,9 +359,13 @@ export type HostRequestState = {
|
|
|
345
359
|
secretsAt?: number;
|
|
346
360
|
/** How much of its fetch log is bodies so far. */
|
|
347
361
|
fetchLogChars?: number;
|
|
348
|
-
/** Filled by run capture
|
|
362
|
+
/** Filled by run capture; the top-level one goes in the request's report. */
|
|
349
363
|
runs: RunRecord[];
|
|
350
|
-
/**
|
|
364
|
+
/** Its console, for the request's report. */
|
|
365
|
+
console?: ConsoleRecord[];
|
|
366
|
+
/** How much of `console` is messages so far. */
|
|
367
|
+
consoleChars?: number;
|
|
368
|
+
/** The data calls this request made, sent to the runs service once the response ends. */
|
|
351
369
|
calls?: CallRecord[];
|
|
352
370
|
/** This request's Airtable reads, so the same one twice goes out once. */
|
|
353
371
|
airtableReads?: Map<string, Promise<unknown>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ZiteWorkspace = {
|
|
2
|
+
workspaceHomeUrl: string;
|
|
3
|
+
editorUrl: string;
|
|
4
|
+
appPublicIdentifier: string;
|
|
5
|
+
projectPublicIdentifier: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class ZiteMeta {
|
|
8
|
+
/** Workspace home + this app's editor URL for *this* clone. */
|
|
9
|
+
static getWorkspace(): Promise<ZiteWorkspace>;
|
|
10
|
+
}
|
|
11
|
+
export declare const Meta: typeof ZiteMeta;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RESERVED_INTEGRATION_IDS } from '../internal/reservedIds.js';
|
|
2
|
+
import { getSdkCall } from '../internal/sdkCall.js';
|
|
3
|
+
const META_SDK_INTEGRATION_ID = RESERVED_INTEGRATION_IDS.meta;
|
|
4
|
+
export class ZiteMeta {
|
|
5
|
+
/** Workspace home + this app's editor URL for *this* clone. */
|
|
6
|
+
static getWorkspace() {
|
|
7
|
+
return getSdkCall()(META_SDK_INTEGRATION_ID, 'ZiteMeta', 'getWorkspace', {});
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const Meta = ZiteMeta;
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { type SourceDir } from '../../sourceRoots.js';
|
|
2
|
-
export declare const START_SERVER_ENTRY = ".zite/server.ts";
|
|
3
2
|
export declare const START_INSTANCE_ENTRY = ".zite/start.ts";
|
|
4
|
-
export type StartTarget = 'cloudflare' | 'node';
|
|
5
|
-
/**
|
|
6
|
-
* The server entry every Start app builds with. Platform-owned: regenerated,
|
|
7
|
-
* never edited. On Workers it's an entrypoint, so the host can hand each fetch
|
|
8
|
-
* its props; on Node, a plain fetch handler.
|
|
9
|
-
*/
|
|
10
|
-
export declare const renderStartServerEntry: (target?: StartTarget) => string;
|
|
11
3
|
/** The start instance: the platform's middleware, then the app's own `src/start.ts` when it has one. */
|
|
12
4
|
export declare const renderStartInstance: (hasAppStart: boolean) => string;
|
|
13
5
|
export declare const hasAppStart: (appDir: string) => boolean;
|
|
@@ -20,6 +12,11 @@ export declare const workspaceHasStartApps: () => boolean;
|
|
|
20
12
|
* `dev` all write them. Returns the ones that changed.
|
|
21
13
|
*/
|
|
22
14
|
export declare function writeStartFiles(appDir: string): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Where an app's role ids are typed: beside the zite.permissions.json they come from, so a workspace's apps share one
|
|
17
|
+
* file. Without one, the workspace root; a single app is its own.
|
|
18
|
+
*/
|
|
19
|
+
export declare const rolesDirOf: (appDir: string) => string;
|
|
23
20
|
export declare function regenerateStartEntries(app: SourceDir): void;
|
|
24
21
|
/**
|
|
25
22
|
* App modules that mention createAutomation or createProviderTrigger: what the workflow registry imports. Describe
|
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync, } from 'node:fs';
|
|
2
2
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
3
3
|
import { listSourceDirs } from '../../sourceRoots.js';
|
|
4
|
-
import { renderRoleIds, START_ROLES_FILE, workspaceRoleIds, } from './roleIds.js';
|
|
5
|
-
export const START_SERVER_ENTRY = '.zite/server.ts';
|
|
4
|
+
import { findPermissionsFile, renderRoleIds, START_ROLES_FILE, workspaceRoleIds, } from './roleIds.js';
|
|
6
5
|
export const START_INSTANCE_ENTRY = '.zite/start.ts';
|
|
7
6
|
const APP_START_FILES = ['src/start.ts', 'src/start.tsx'];
|
|
8
|
-
/**
|
|
9
|
-
* The server entry every Start app builds with. Platform-owned: regenerated,
|
|
10
|
-
* never edited. On Workers it's an entrypoint, so the host can hand each fetch
|
|
11
|
-
* its props; on Node, a plain fetch handler.
|
|
12
|
-
*/
|
|
13
|
-
export const renderStartServerEntry = (target = 'cloudflare') => target === 'cloudflare'
|
|
14
|
-
? `// Generated by zitejs for TanStack Start apps. The platform owns this file.
|
|
15
|
-
// First, so an SDK client an app module builds as it loads gets zitejs's fetch.
|
|
16
|
-
import 'zitejs/start/fetch';
|
|
17
|
-
import handler from '@tanstack/react-start/server-entry';
|
|
18
|
-
import { createZiteWorker } from 'zitejs/start/worker';
|
|
19
|
-
import { getRouter } from '../src/router';
|
|
20
|
-
|
|
21
|
-
export default createZiteWorker({ handler, getRouter });
|
|
22
|
-
`
|
|
23
|
-
: `// Generated by zitejs for TanStack Start apps. The platform owns this file.
|
|
24
|
-
// First, so an SDK client an app module builds as it loads gets zitejs's fetch.
|
|
25
|
-
import 'zitejs/start/fetch';
|
|
26
|
-
import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
|
|
27
|
-
import { createZiteFetch } from 'zitejs/start/server';
|
|
28
|
-
import { getRouter } from '../src/router';
|
|
29
|
-
|
|
30
|
-
export default createServerEntry({ fetch: createZiteFetch({ handler, getRouter }) });
|
|
31
|
-
`;
|
|
32
7
|
const START_INSTANCE_HEADER = `// Generated by zitejs for TanStack Start apps. The platform owns this file.
|
|
33
8
|
// TanStack's start-instance file, the only place Start 1.169 registers global middleware. Generated so the platform's
|
|
34
9
|
// CSRF check and run log can't be dropped; the app's own src/start.ts composes after them.
|
|
@@ -87,13 +62,31 @@ export const workspaceHasStartApps = () => listSourceDirs().some(isStartApp);
|
|
|
87
62
|
* `dev` all write them. Returns the ones that changed.
|
|
88
63
|
*/
|
|
89
64
|
export function writeStartFiles(appDir) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
65
|
+
const rolesDir = rolesDirOf(appDir);
|
|
66
|
+
return [
|
|
67
|
+
...(writeIfChanged(appDir, START_INSTANCE_ENTRY, renderStartInstance(hasAppStart(appDir)))
|
|
68
|
+
? [START_INSTANCE_ENTRY]
|
|
69
|
+
: []),
|
|
70
|
+
...(writeIfChanged(rolesDir, START_ROLES_FILE, renderRoleIds(workspaceRoleIds(appDir)))
|
|
71
|
+
? [relative(appDir, join(rolesDir, START_ROLES_FILE))]
|
|
72
|
+
: []),
|
|
94
73
|
];
|
|
95
|
-
return files.flatMap(([file, content]) => writeIfChanged(appDir, file, content) ? [file] : []);
|
|
96
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Where an app's role ids are typed: beside the zite.permissions.json they come from, so a workspace's apps share one
|
|
77
|
+
* file. Without one, the workspace root; a single app is its own.
|
|
78
|
+
*/
|
|
79
|
+
export const rolesDirOf = (appDir) => {
|
|
80
|
+
const permissions = findPermissionsFile(appDir);
|
|
81
|
+
if (permissions)
|
|
82
|
+
return dirname(permissions);
|
|
83
|
+
for (let at = resolve(appDir);; at = dirname(at)) {
|
|
84
|
+
if (readConfig(at)?.project !== undefined)
|
|
85
|
+
return at;
|
|
86
|
+
if (dirname(at) === at)
|
|
87
|
+
return resolve(appDir);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
97
90
|
export function regenerateStartEntries(app) {
|
|
98
91
|
if (!isStartApp(app))
|
|
99
92
|
return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const START_ROLES_FILE = ".zite/roles.d.ts";
|
|
2
2
|
/** The roles every workspace has without defining them, as the platform names them. */
|
|
3
3
|
export declare const BUILTIN_ROLE_IDS: readonly ["builtin:all-team-members", "builtin:all-users"];
|
|
4
|
+
export declare const findPermissionsFile: (appDir: string) => string | undefined;
|
|
4
5
|
/**
|
|
5
6
|
* The built-ins, then the roles the nearest `zite.permissions.json` defines. None at all when there's no readable
|
|
6
7
|
* file, so role ids stay plain strings: a missing or broken file would otherwise type every role the app names as a
|
|
@@ -8,7 +8,7 @@ export const BUILTIN_ROLE_IDS = [
|
|
|
8
8
|
];
|
|
9
9
|
const PERMISSIONS_FILE = 'zite.permissions.json';
|
|
10
10
|
// The workspace root's in a monorepo, above apps/<dir>/.
|
|
11
|
-
const findPermissionsFile = (appDir) => {
|
|
11
|
+
export const findPermissionsFile = (appDir) => {
|
|
12
12
|
for (let dir = resolve(appDir);; dir = dirname(dir)) {
|
|
13
13
|
const file = join(dir, PERMISSIONS_FILE);
|
|
14
14
|
if (existsSync(file))
|
|
@@ -41,7 +41,7 @@ export declare const devSignInOf: (appDir: string, appEnv: Record<string, string
|
|
|
41
41
|
/** @internal The app's id in its zite.config.json, which `local` mints dev tokens for; null without one. */
|
|
42
42
|
export declare const devAppIdOf: (appDir: string) => string | null;
|
|
43
43
|
export type ZiteOptions = {
|
|
44
|
-
/** A server entry the caller owns, relative to the app root. By default
|
|
44
|
+
/** A server entry the caller owns, relative to the app root. By default the app builds on zitejs's own. */
|
|
45
45
|
serverEntry?: string;
|
|
46
46
|
/** Build for Cloudflare Workers, the target the platform deploys. Defaults to true; false builds for Node. */
|
|
47
47
|
cloudflare?: boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
3
4
|
import { loadEnv } from 'vite';
|
|
4
5
|
import { parse as parseEnv } from 'dotenv';
|
|
5
6
|
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
@@ -13,7 +14,7 @@ import { sourceRootOf } from '../../sourceRoots.js';
|
|
|
13
14
|
import { registrationHashes } from './registrationHash.js';
|
|
14
15
|
import { sdkPatches } from './sdkPatches.js';
|
|
15
16
|
import { siteHeadOf } from './siteHead.js';
|
|
16
|
-
import { hasAppStart, renderStartInstance,
|
|
17
|
+
import { hasAppStart, renderStartInstance, renderWorkflowModules, START_INSTANCE_ENTRY, workflowFiles, writeIfChanged, } from './entries.js';
|
|
17
18
|
// Must match the literals in ../serve/server.ts and ../describe/describe.ts, which the build rewrites.
|
|
18
19
|
const FN_IDS_TOKEN = '__ZITE_FN_IDS__';
|
|
19
20
|
const FN_DESCRIPTIONS_LITERAL = /(["'`])__ZITE_FN_DESCRIPTIONS__\1/;
|
|
@@ -176,13 +177,12 @@ const loadCloudflare = async (main) => {
|
|
|
176
177
|
};
|
|
177
178
|
/** The one plugin a Zite app's `vite.config.ts` uses. */
|
|
178
179
|
export function zite(options = {}) {
|
|
179
|
-
const serverEntry = options.serverEntry ?? START_SERVER_ENTRY;
|
|
180
|
-
// Platform-owned, so they're rewritten whenever they differ. Sandboxes run the
|
|
181
|
-
// image's zitejs for `generate`, which may predate Start; the plugin can't.
|
|
182
180
|
const appDir = process.cwd();
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
const serverEntry = options.serverEntry
|
|
182
|
+
? path.join(appDir, options.serverEntry)
|
|
183
|
+
: fileURLToPath(new URL(`../entries/${options.cloudflare === false ? 'node' : 'worker'}/server.js`, import.meta.url));
|
|
184
|
+
// Platform-owned, so it's rewritten whenever it differs. Sandboxes run the
|
|
185
|
+
// image's zitejs for `generate`, which may predate Start; the plugin can't.
|
|
186
186
|
writeIfChanged(appDir, START_INSTANCE_ENTRY, renderStartInstance(hasAppStart(appDir)));
|
|
187
187
|
// Every server function TanStack's compiler found, from its own hook, by id.
|
|
188
188
|
const ids = new Map();
|
|
@@ -225,10 +225,6 @@ export function zite(options = {}) {
|
|
|
225
225
|
find: /^zitejs\/email$/,
|
|
226
226
|
replacement: path.join(root, '.zite/integrations/email.ts'),
|
|
227
227
|
},
|
|
228
|
-
{
|
|
229
|
-
find: /^zitejs\/meta$/,
|
|
230
|
-
replacement: path.join(root, '.zite/meta.ts'),
|
|
231
|
-
},
|
|
232
228
|
// Classic's actions run on better-auth's client; Start's call the sign-in module's routes.
|
|
233
229
|
{ find: /^zitejs\/auth$/, replacement: 'zitejs/start/auth' },
|
|
234
230
|
],
|
|
@@ -418,12 +414,27 @@ export function zite(options = {}) {
|
|
|
418
414
|
return `export const devSignIn = ${JSON.stringify(settings)};\n`;
|
|
419
415
|
},
|
|
420
416
|
};
|
|
417
|
+
// The built-in server entry imports the app's router through this.
|
|
418
|
+
const appRouter = {
|
|
419
|
+
name: 'zite:app-router',
|
|
420
|
+
enforce: 'pre',
|
|
421
|
+
resolveId(id) {
|
|
422
|
+
return id === 'virtual:zite/app-router'
|
|
423
|
+
? this.resolve(path.join(appDir, 'src', 'router'))
|
|
424
|
+
: undefined;
|
|
425
|
+
},
|
|
426
|
+
};
|
|
421
427
|
return [
|
|
422
428
|
// First, so ids name lines in the source, before TanStack splits a route's component out of it.
|
|
423
429
|
ziteId(),
|
|
430
|
+
appRouter,
|
|
424
431
|
tanstackStart({
|
|
425
|
-
// TanStack resolves
|
|
426
|
-
server: {
|
|
432
|
+
// TanStack resolves its entries from the app's src/, and only as relative paths.
|
|
433
|
+
server: {
|
|
434
|
+
entry: path
|
|
435
|
+
.relative(path.join(appDir, 'src'), serverEntry)
|
|
436
|
+
.replace(/\.ts$/, ''),
|
|
437
|
+
},
|
|
427
438
|
start: { entry: `../${START_INSTANCE_ENTRY.replace(/\.ts$/, '')}` },
|
|
428
439
|
serverFns: {
|
|
429
440
|
generateFunctionId: ({ filename, functionName }) => {
|
|
@@ -456,15 +467,15 @@ export function zite(options = {}) {
|
|
|
456
467
|
'zitejs/start/worker',
|
|
457
468
|
'zitejs/start/describe',
|
|
458
469
|
'zitejs/runtime',
|
|
470
|
+
'zitejs/meta',
|
|
459
471
|
],
|
|
460
472
|
// Replaces TanStack's list, so its `**/*.server.*` is restated. File
|
|
461
|
-
// patterns also catch `zitejs/db
|
|
462
|
-
//
|
|
473
|
+
// patterns also catch `zitejs/db` and `zitejs/integrations`, which the
|
|
474
|
+
// aliases above rewrite before specifiers are matched.
|
|
463
475
|
files: [
|
|
464
476
|
'**/*.server.*',
|
|
465
477
|
'**/.zite/db.ts',
|
|
466
478
|
'**/.zite/integrations/**',
|
|
467
|
-
'**/.zite/meta.ts',
|
|
468
479
|
],
|
|
469
480
|
},
|
|
470
481
|
// Replaces TanStack's empty list; its `**/*.client.*` files stay.
|
|
@@ -59,6 +59,8 @@ export type Description = {
|
|
|
59
59
|
authHooks: AuthHookName[];
|
|
60
60
|
/** What's wrong with the app as a whole, beside any one function, route or workflow. */
|
|
61
61
|
problems: string[];
|
|
62
|
+
/** The zitejs the build's server code was bundled from. */
|
|
63
|
+
runtimeVersion: string;
|
|
62
64
|
};
|
|
63
65
|
/** What the build knows of the app beside its code: its access mode, and whether it's a standalone automation. */
|
|
64
66
|
export type AppFacts = {
|
|
@@ -6,6 +6,7 @@ import { runWithStartContext } from '@tanstack/start-storage-context';
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import { ziteMiddlewareKind, } from '../middlewareKind.js';
|
|
8
8
|
import { isZiteRouter } from '../router.js';
|
|
9
|
+
import { ZITEJS_VERSION } from '../version.js';
|
|
9
10
|
import { loadAuthHooks } from '../serve/authHooks.js';
|
|
10
11
|
import { loadProviderTriggers, } from '../automations/workflowRun.js';
|
|
11
12
|
import { isProviderTrigger, } from '../automations/workflow.js';
|
|
@@ -368,5 +369,6 @@ export async function describeApp(opts) {
|
|
|
368
369
|
workflows,
|
|
369
370
|
authHooks: Object.keys(await loadAuthHooks()),
|
|
370
371
|
problems,
|
|
372
|
+
runtimeVersion: ZITEJS_VERSION,
|
|
371
373
|
};
|
|
372
374
|
}
|
|
@@ -172,4 +172,6 @@ export const describeOutputSchema = z.object({
|
|
|
172
172
|
workflows: z.array(describedWorkflowSchema),
|
|
173
173
|
authHooks: z.array(authHookNameSchema),
|
|
174
174
|
problems: z.array(z.string()),
|
|
175
|
+
/** The zitejs the build's server code was bundled from. */
|
|
176
|
+
runtimeVersion: z.string(),
|
|
175
177
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The server entry a Start app builds with off Workers: a plain fetch handler.
|
|
2
|
+
// First, so an SDK client an app module builds as it loads gets zitejs's fetch.
|
|
3
|
+
import '../../serve/fetch.js';
|
|
4
|
+
import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
|
|
5
|
+
import { getRouter } from 'virtual:zite/app-router';
|
|
6
|
+
import { createZiteFetch } from '../../serve/server.js';
|
|
7
|
+
export default createServerEntry({
|
|
8
|
+
fetch: createZiteFetch({ handler, getRouter }),
|
|
9
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The server entry every Start app builds with on Workers: an entrypoint, so the host can hand each fetch its props.
|
|
2
|
+
// First, so an SDK client an app module builds as it loads gets zitejs's fetch.
|
|
3
|
+
import '../../serve/fetch.js';
|
|
4
|
+
import handler from '@tanstack/react-start/server-entry';
|
|
5
|
+
import { getRouter } from 'virtual:zite/app-router';
|
|
6
|
+
import { createZiteWorker } from '../../serve/worker.js';
|
|
7
|
+
export default createZiteWorker({ handler, getRouter });
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { RunReport } from './types.js';
|
|
2
|
+
export declare const FRAME: {
|
|
3
|
+
readonly head: 1;
|
|
4
|
+
readonly chunk: 2;
|
|
5
|
+
readonly end: 3;
|
|
6
|
+
readonly report: 4;
|
|
7
|
+
readonly fail: 5;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* What the host decides an answer by, in place of reading its headers. The status travels here because a 204 or a 304
|
|
11
|
+
* can't carry the frames as its body.
|
|
12
|
+
*/
|
|
13
|
+
export type AnswerHead = {
|
|
14
|
+
status: number;
|
|
15
|
+
contentType: string | null;
|
|
16
|
+
/** The body's length as the app declared it, for the host to declare again; the frames are longer. */
|
|
17
|
+
contentLength: number | null;
|
|
18
|
+
/** What the edge's page cache decides by: the host writes these over the app's own, so no one reads those. */
|
|
19
|
+
cacheControl: string | null;
|
|
20
|
+
vary: string | null;
|
|
21
|
+
setCookies: string[];
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The app's answer as the host reads it: its headers as they are, and its body in frames. `report` is asked once the
|
|
25
|
+
* body has ended cleanly; a body that fails or is cancelled stops the frames short of `end`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const framedAnswer: (response: Response,
|
|
28
|
+
/** Given what failed the body, when it failed. */
|
|
29
|
+
report: (failure?: unknown) => Promise<RunReport | null>) => Response;
|
|
30
|
+
/** An answer that breaks the protocol, which only a broken or hostile build sends. */
|
|
31
|
+
export declare class MalformedAnswer extends Error {
|
|
32
|
+
}
|
|
33
|
+
/** The app's own body failed partway, with the app's message for why. */
|
|
34
|
+
export declare class AnswerFailed extends Error {
|
|
35
|
+
}
|
|
36
|
+
/** How a decoded body stopped: at `end`, cancelled by its reader, or with what stopped it. */
|
|
37
|
+
export type BodyEnd = {
|
|
38
|
+
outcome: 'ok' | 'canceled';
|
|
39
|
+
} | {
|
|
40
|
+
outcome: 'error';
|
|
41
|
+
error: unknown;
|
|
42
|
+
};
|
|
43
|
+
export type DecodedAnswer = {
|
|
44
|
+
head: AnswerHead;
|
|
45
|
+
/** The body's chunks as they arrive. It closes at `end` and errors on anything else. */
|
|
46
|
+
body: ReadableStream<Uint8Array>;
|
|
47
|
+
ended: Promise<BodyEnd>;
|
|
48
|
+
/**
|
|
49
|
+
* The report's JSON once the body has ended, cleanly or with the app's `AnswerFailed`: null without one, past its
|
|
50
|
+
* cap, or when the answer broke off. A frame that breaks the protocol rejects it.
|
|
51
|
+
*/
|
|
52
|
+
report: Promise<string | null>;
|
|
53
|
+
};
|
|
54
|
+
/** The most of a `head` and a `report` payload `decodeAnswer` holds, in bytes. */
|
|
55
|
+
export type AnswerCaps = {
|
|
56
|
+
head: number;
|
|
57
|
+
report: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Reads an answer's head, then hands on its body's chunks as they arrive, never holding one, and reads its report once
|
|
61
|
+
* the body has ended. A missing, oversized or malformed head rejects.
|
|
62
|
+
*/
|
|
63
|
+
export declare const decodeAnswer: (stream: ReadableStream<Uint8Array> | null, caps: AnswerCaps) => Promise<DecodedAnswer>;
|