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
|
@@ -6,7 +6,8 @@ import { callPlatform } from '../platform/calls.js';
|
|
|
6
6
|
import { takeAnalytics } from '../platform/analytics.js';
|
|
7
7
|
import { takeUploadSession } from './uploads.js';
|
|
8
8
|
import { UPLOAD_SESSION_PATH } from '../../internal/serviceUrls.js';
|
|
9
|
-
import {
|
|
9
|
+
import { sendEvents } from '../platform/telemetry.js';
|
|
10
|
+
import { errorOf, runReportOf } from '../platform/runLog.js';
|
|
10
11
|
import { ANALYTICS_PATH, MANIFEST_PATH, manifestAnswer, opensPage, platformHeadOf, } from './pageHead.js';
|
|
11
12
|
import { builtSiteHead } from '../build/placeholders/siteHead.js';
|
|
12
13
|
import { ziteProvider } from './provider.js';
|
|
@@ -16,8 +17,8 @@ import { hostContextFromLocal, loadLocal } from './local/load.js';
|
|
|
16
17
|
import { createInvoker, headerInvoke } from './invoke.js';
|
|
17
18
|
import { getHost, requireRequest, runWithHost } from './scope.js';
|
|
18
19
|
import { installRequestEnv } from './requestEnv.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
20
|
+
import { installConsoleCapture } from './console.js';
|
|
21
|
+
import { framedAnswer } from '../frames.js';
|
|
21
22
|
import { loadUnfinishedWorkflows, loadWorkflows, } from '../automations/workflowRun.js';
|
|
22
23
|
export { runWithHost } from './scope.js';
|
|
23
24
|
export { describeApp } from '../describe/describe.js';
|
|
@@ -135,9 +136,9 @@ export const builtFunctionDescriptions = () => parseBuiltJson('__ZITE_FN_DESCRIP
|
|
|
135
136
|
export const builtRouteFiles = () => parseBuiltJson('__ZITE_ROUTE_FILES__');
|
|
136
137
|
/** Each registry module's registration hash, by its path, written in by `zite()` at build from the module graph. */
|
|
137
138
|
export const builtRegistrationHashes = () => parseBuiltJson('__ZITE_REGISTRATION_HASHES__');
|
|
138
|
-
// Server functions also run while a streamed page renders, so
|
|
139
|
-
//
|
|
140
|
-
// failed. A TransformStream's flush hears only the first.
|
|
139
|
+
// Server functions also run while a streamed page renders, so what a request
|
|
140
|
+
// did is known only once the body ends: read to the end, cancelled by the reader
|
|
141
|
+
// or failed. A TransformStream's flush hears only the first.
|
|
141
142
|
const onBodyEnd = (response, done) => {
|
|
142
143
|
if (!response.body) {
|
|
143
144
|
done();
|
|
@@ -184,15 +185,18 @@ const pageStatus = (host) => {
|
|
|
184
185
|
};
|
|
185
186
|
// The platform binding is what only the host's dispatch carries.
|
|
186
187
|
const isDispatched = (props) => !!props?.platform;
|
|
188
|
+
const noReport = async () => null;
|
|
187
189
|
/**
|
|
188
190
|
* The handlers of a Start app's server entry. A request the host dispatched
|
|
189
|
-
* carries its identity, app token and platform URLs in props
|
|
190
|
-
* developer's dev token or API key
|
|
191
|
-
* anything else (describe under `vite
|
|
191
|
+
* carries its identity, app token and platform URLs in props, and is answered
|
|
192
|
+
* in frames (../frames.ts). Without props, a developer's dev token or API key
|
|
193
|
+
* in env selects the `local` provider; anything else (describe under `vite
|
|
194
|
+
* preview`, tests) uses `provider` if one is given.
|
|
192
195
|
*/
|
|
193
196
|
export function createZiteHandlers(options) {
|
|
194
197
|
installPlatformTransport();
|
|
195
198
|
installRequestEnv();
|
|
199
|
+
installConsoleCapture();
|
|
196
200
|
// Loaded on first use, so a page request never pays for importing workflow modules.
|
|
197
201
|
let workflows;
|
|
198
202
|
const loadedWorkflows = () => (workflows ??= loadWorkflows());
|
|
@@ -201,7 +205,8 @@ export function createZiteHandlers(options) {
|
|
|
201
205
|
functionIds: builtFunctionIds,
|
|
202
206
|
handler: options.handler,
|
|
203
207
|
});
|
|
204
|
-
|
|
208
|
+
// A bare Response is one the platform answered before any app code ran.
|
|
209
|
+
const answer = async (incoming, ctx) => {
|
|
205
210
|
const given = ctx?.props;
|
|
206
211
|
const props = isDispatched(given) ? given : undefined;
|
|
207
212
|
const local = props ? undefined : localPlatform();
|
|
@@ -253,7 +258,7 @@ export function createZiteHandlers(options) {
|
|
|
253
258
|
request,
|
|
254
259
|
workflows: await loadedWorkflows(),
|
|
255
260
|
unfinishedWorkflows: await loadUnfinishedWorkflows(),
|
|
256
|
-
})
|
|
261
|
+
}));
|
|
257
262
|
}
|
|
258
263
|
let response = await runWithHost(host, () => invoke(host, request) ?? options.handler.fetch(request));
|
|
259
264
|
const status = response.status === 500 ? pageStatus(host) : undefined;
|
|
@@ -268,26 +273,42 @@ export function createZiteHandlers(options) {
|
|
|
268
273
|
response = asDemoRefusal(response);
|
|
269
274
|
if (mounted)
|
|
270
275
|
response = withSetCookies(response, mounted.signedIn.setCookies);
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
await Promise.all(host.pending ?? []);
|
|
279
|
-
if (!host.runs.length && !host.calls?.length && !host.fetches?.length)
|
|
276
|
+
let settled = Promise.resolve();
|
|
277
|
+
response = onBodyEnd(response, () => {
|
|
278
|
+
// An own AI key's usage lands on its fetch only once its answer is read.
|
|
279
|
+
settled = Promise.all(host.pending ?? []);
|
|
280
|
+
const sent = settled
|
|
281
|
+
.then(() => {
|
|
282
|
+
if (!host.calls?.length && !host.fetches?.length)
|
|
280
283
|
return;
|
|
281
|
-
|
|
282
|
-
runs: host.runs,
|
|
284
|
+
return sendEvents(host, {
|
|
283
285
|
...(host.calls?.length && { calls: host.calls }),
|
|
284
286
|
...(host.fetches?.length && { fetches: host.fetches }),
|
|
285
287
|
});
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
+
})
|
|
289
|
+
.catch((error) => {
|
|
290
|
+
console.error("[zite] couldn't report the request's calls and fetches", error);
|
|
288
291
|
});
|
|
289
|
-
ctx?.waitUntil(
|
|
292
|
+
ctx?.waitUntil(sent);
|
|
290
293
|
});
|
|
294
|
+
return {
|
|
295
|
+
response,
|
|
296
|
+
report: async (failure) => {
|
|
297
|
+
await settled;
|
|
298
|
+
const report = runReportOf(host);
|
|
299
|
+
// A body that failed after its route returned has no failed run: its failure is the report's error.
|
|
300
|
+
if (failure === undefined || report?.error)
|
|
301
|
+
return report;
|
|
302
|
+
return { ...report, error: errorOf(failure) };
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
const fetch = async (request, _env, ctx) => {
|
|
307
|
+
const answered = await answer(request, ctx);
|
|
308
|
+
const { response, report } = answered instanceof Response
|
|
309
|
+
? { response: answered, report: noReport }
|
|
310
|
+
: answered;
|
|
311
|
+
return isDispatched(ctx?.props) ? framedAnswer(response, report) : response;
|
|
291
312
|
};
|
|
292
313
|
return { fetch };
|
|
293
314
|
}
|
|
@@ -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>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ZITEJS_VERSION = "0.10.
|
|
1
|
+
export declare const ZITEJS_VERSION = "0.10.4";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Written by scripts/write-version.mjs from package.json.
|
|
2
|
-
export const ZITEJS_VERSION = '0.10.
|
|
2
|
+
export const ZITEJS_VERSION = '0.10.4';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zitejs",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "The Zite framework — build apps on Zite Database",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -79,6 +79,11 @@
|
|
|
79
79
|
"import": "./dist/esm/pdf/index.js",
|
|
80
80
|
"require": "./dist/cjs/pdf/index.js"
|
|
81
81
|
},
|
|
82
|
+
"./meta": {
|
|
83
|
+
"types": "./dist/esm/meta/index.d.ts",
|
|
84
|
+
"import": "./dist/esm/meta/index.js",
|
|
85
|
+
"require": "./dist/cjs/meta/index.js"
|
|
86
|
+
},
|
|
82
87
|
"./schedules": {
|
|
83
88
|
"types": "./dist/esm/schedules/index.d.ts",
|
|
84
89
|
"import": "./dist/esm/schedules/index.js",
|
package/tsconfig/start.json
CHANGED
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"zitejs/db": ["${configDir}/../../.zite/db.ts"],
|
|
25
25
|
"zitejs/integrations": ["${configDir}/.zite/integrations/index.ts"],
|
|
26
26
|
"zitejs/email": ["${configDir}/.zite/integrations/email.ts"],
|
|
27
|
-
"zitejs/meta": ["${configDir}/.zite/meta.ts"],
|
|
28
27
|
"react": ["${configDir}/node_modules/@types/react"],
|
|
29
28
|
"react/*": ["${configDir}/node_modules/@types/react/*"],
|
|
30
29
|
"react-dom": ["${configDir}/node_modules/@types/react-dom"],
|
|
@@ -34,6 +33,7 @@
|
|
|
34
33
|
"include": [
|
|
35
34
|
"${configDir}/src",
|
|
36
35
|
"${configDir}/.zite/*.d.ts",
|
|
36
|
+
"${configDir}/../../.zite/*.d.ts",
|
|
37
37
|
"${configDir}/vite.config.ts"
|
|
38
38
|
],
|
|
39
39
|
"exclude": ["${configDir}/node_modules", "${configDir}/dist"]
|