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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { HostRequestState, PagePlan, PlatformCallInput, PlatformCallResult, PlatformUrls } from "./types.js";
|
|
2
|
+
export type DirectAccess = {
|
|
3
|
+
token: string;
|
|
4
|
+
urls: PlatformUrls;
|
|
5
|
+
};
|
|
6
|
+
type Connection = Record<string, unknown> & {
|
|
7
|
+
status?: unknown;
|
|
8
|
+
message?: unknown;
|
|
9
|
+
userFacingMessage?: unknown;
|
|
10
|
+
connectUrl?: unknown;
|
|
11
|
+
};
|
|
12
|
+
type Connections = {
|
|
13
|
+
connections: Record<string, Connection>;
|
|
14
|
+
env: Record<string, string>;
|
|
15
|
+
envConnections: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
/** Thrown for a platform call on a request that has no token or no platform URLs. */
|
|
18
|
+
export declare class NoPlatformError extends Error {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
/** The request's token and where to send it, renewed first if it's about to expire; undefined without either. */
|
|
22
|
+
export declare const directAccess: (host: HostRequestState) => Promise<DirectAccess | undefined>;
|
|
23
|
+
/** At most `max` at once, the rest in turn; each take resolves with its release. */
|
|
24
|
+
export declare const limiter: (max: number) => () => Promise<() => void>;
|
|
25
|
+
/** The app's own data dispatch's requests, to base-runner on the token, which says the base, mode and user. */
|
|
26
|
+
export declare const directDataFetch: (host: HostRequestState) => ({ method, path, body }: {
|
|
27
|
+
method: string;
|
|
28
|
+
path: string;
|
|
29
|
+
body?: string;
|
|
30
|
+
}) => Promise<Response>;
|
|
31
|
+
/**
|
|
32
|
+
* The backend's `GET connections` on the token, once per reuse window: all `local` has, and what an app on Zite asks
|
|
33
|
+
* when the host didn't hand them over. Stale if the backend didn't answer.
|
|
34
|
+
*/
|
|
35
|
+
export declare const connectionsOnToken: (access: DirectAccess) => Promise<Connections>;
|
|
36
|
+
/** The build's page settings for `local`, which has no host to send them; null when the backend has none to give. */
|
|
37
|
+
export declare const localPagePlan: (access: DirectAccess) => Promise<PagePlan | null>;
|
|
38
|
+
/** For tests: forget what this isolate learned. */
|
|
39
|
+
export declare const resetLocalConnections: () => void;
|
|
40
|
+
/** A platform call on the token; a throw without one. Errors come back as values, as the relay's did. */
|
|
41
|
+
export declare const directCall: (host: HostRequestState, input: PlatformCallInput) => Promise<PlatformCallResult>;
|
|
42
|
+
/** After a provider answered 401: the connection refreshed by the backend. */
|
|
43
|
+
export declare const refreshConnection: (host: HostRequestState, name: string) => Promise<PlatformCallResult>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
// Data and services on the request's app token, sent straight to the platform. Each answer is shaped as the host's relay
|
|
2
|
+
// shaped it, so what an app sees didn't change when the relay went. A request with no token or platform URLs reaches
|
|
3
|
+
// nothing: the host dispatches every request with both, and `local` mints its own.
|
|
4
|
+
import { appTokenClaims } from "../internal/appToken.js";
|
|
5
|
+
import { platformFetch } from "../internal/platformFetch.js";
|
|
6
|
+
import { serviceUrl } from "../internal/serviceUrls.js";
|
|
7
|
+
import { INTEGRATIONS_PLATFORM_ID } from "./credentials.js";
|
|
8
|
+
import { DEMO_UNAVAILABLE_MESSAGE } from "./data/dispatch.js";
|
|
9
|
+
import { isZiteErrorCode } from "./errors.js";
|
|
10
|
+
import { errorOf, preview } from "./runLog.js";
|
|
11
|
+
import { STEP_RESULT_MAX_BYTES } from "./steps.js";
|
|
12
|
+
import { sendRunReport } from "./telemetry.js";
|
|
13
|
+
const STEPS_INTEGRATION_ID = "__steps__";
|
|
14
|
+
const META_INTEGRATION_ID = "__meta__";
|
|
15
|
+
// Unpublished from zitejs; classic answers it as an integration it can't find.
|
|
16
|
+
const NOTIFICATIONS_INTEGRATION_ID = "__notifications__";
|
|
17
|
+
const PDF_INTEGRATION_ID = "__pdf__";
|
|
18
|
+
const SCHEDULES_INTEGRATION_ID = "__schedules__";
|
|
19
|
+
const BACKEND_TIMEOUT_MS = 5_000;
|
|
20
|
+
// Attachments take up to 30 s each, and a render 30 s, as on classic.
|
|
21
|
+
const SDK_TIMEOUT_MS = 90_000;
|
|
22
|
+
// One request's fan-out, as the host once capped it; base-runner's per-app bucket is what bounds an app.
|
|
23
|
+
const DATA_CONCURRENCY = 16;
|
|
24
|
+
const SQL_CONCURRENCY = 4;
|
|
25
|
+
const SQL_PATH = /\/sql(?:\?|$)/;
|
|
26
|
+
class PlatformError extends Error {
|
|
27
|
+
route;
|
|
28
|
+
status;
|
|
29
|
+
constructor(route, status) {
|
|
30
|
+
super(`${route} answered ${status}`);
|
|
31
|
+
this.route = route;
|
|
32
|
+
this.status = status;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const DEMO_REFUSED = { error: { code: "FORBIDDEN", message: DEMO_UNAVAILABLE_MESSAGE } };
|
|
36
|
+
/** Thrown for a platform call on a request that has no token or no platform URLs. */
|
|
37
|
+
export class NoPlatformError extends Error {
|
|
38
|
+
constructor() {
|
|
39
|
+
super("This request has no app token or platform URLs: Zite didn't dispatch it, or its host predates this zitejs");
|
|
40
|
+
this.name = "NoPlatformError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The request's token and where to send it, renewed first if it's about to expire; undefined without either. */
|
|
44
|
+
export const directAccess = async (host) => {
|
|
45
|
+
const urls = host.provider?.urls;
|
|
46
|
+
const token = urls ? await host.provider?.token() : undefined;
|
|
47
|
+
return urls && token ? { token, urls } : undefined;
|
|
48
|
+
};
|
|
49
|
+
const send = (access, url, init) => platformFetch(new Request(url, {
|
|
50
|
+
method: init.method,
|
|
51
|
+
headers: { authorization: `Bearer ${access.token}`, "content-type": "application/json" },
|
|
52
|
+
body: init.body,
|
|
53
|
+
...(init.timeoutMs && { signal: AbortSignal.timeout(init.timeoutMs) }),
|
|
54
|
+
}));
|
|
55
|
+
const platformJson = async (access, method, url, route, body) => {
|
|
56
|
+
const response = await send(access, url, {
|
|
57
|
+
method,
|
|
58
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
59
|
+
timeoutMs: BACKEND_TIMEOUT_MS,
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok)
|
|
62
|
+
throw new PlatformError(route, response.status);
|
|
63
|
+
return (await response.json());
|
|
64
|
+
};
|
|
65
|
+
const backendJson = (access, method, path, body) => platformJson(access, method, `${access.urls.backend}/v1/start/app${path}`, path, body);
|
|
66
|
+
/** At most `max` at once, the rest in turn; each take resolves with its release. */
|
|
67
|
+
export const limiter = (max) => {
|
|
68
|
+
let active = 0;
|
|
69
|
+
const waiting = [];
|
|
70
|
+
return async () => {
|
|
71
|
+
if (active < max)
|
|
72
|
+
active++;
|
|
73
|
+
else
|
|
74
|
+
await new Promise((resolve) => waiting.push(resolve));
|
|
75
|
+
let released = false;
|
|
76
|
+
return () => {
|
|
77
|
+
if (released)
|
|
78
|
+
return;
|
|
79
|
+
released = true;
|
|
80
|
+
const next = waiting.shift();
|
|
81
|
+
if (next)
|
|
82
|
+
next();
|
|
83
|
+
else
|
|
84
|
+
active--;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** The app's own data dispatch's requests, to base-runner on the token, which says the base, mode and user. */
|
|
89
|
+
export const directDataFetch = (host) => async ({ method, path, body }) => {
|
|
90
|
+
const slots = (host.dataSlots ??= { data: limiter(DATA_CONCURRENCY), sql: limiter(SQL_CONCURRENCY) });
|
|
91
|
+
const release = await (SQL_PATH.test(path) ? slots.sql : slots.data)();
|
|
92
|
+
try {
|
|
93
|
+
const access = await directAccess(host);
|
|
94
|
+
if (!access)
|
|
95
|
+
throw new NoPlatformError();
|
|
96
|
+
return await send(access, `${access.urls.baseRunner}${path}`, { method, body });
|
|
97
|
+
}
|
|
98
|
+
finally {
|
|
99
|
+
release();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/** As the host answered a demo: email pretends to succeed; schedules and connections act as the author, so are refused. */
|
|
103
|
+
const demoAnswer = (input) => {
|
|
104
|
+
if (input.className === "Email" && input.methodName === "send")
|
|
105
|
+
return { value: { success: true } };
|
|
106
|
+
if (input.integrationId === SCHEDULES_INTEGRATION_ID || input.integrationId === INTEGRATIONS_PLATFORM_ID)
|
|
107
|
+
return DEMO_REFUSED;
|
|
108
|
+
return undefined;
|
|
109
|
+
};
|
|
110
|
+
const sdkRoute = (host, input) => input.className === "Email" && input.methodName === "send"
|
|
111
|
+
? { route: "email", body: { integrationId: input.integrationId, params: input.params, mode: host.mode } }
|
|
112
|
+
: input.integrationId === PDF_INTEGRATION_ID && input.methodName === "renderHtml"
|
|
113
|
+
? { route: "pdf", body: { params: input.params } }
|
|
114
|
+
: input.integrationId === SCHEDULES_INTEGRATION_ID
|
|
115
|
+
? { route: "schedules", body: { methodName: input.methodName, params: input.params } }
|
|
116
|
+
: undefined;
|
|
117
|
+
// A 4xx naming a ZiteError code, or any 400, says what the app got wrong, as its error; anything else is ours.
|
|
118
|
+
const sdk = async (access, { route, body }) => {
|
|
119
|
+
const url = route === "schedules" ? `${access.urls.backend}/v1/start/app/schedules` : serviceUrl(access.urls, route);
|
|
120
|
+
const response = await send(access, url, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
body: JSON.stringify(body),
|
|
123
|
+
timeoutMs: SDK_TIMEOUT_MS,
|
|
124
|
+
});
|
|
125
|
+
const answer = (await response.json().catch(() => null));
|
|
126
|
+
const message = typeof answer?.error === "string" ? answer.error : `The ${route === "pdf" ? "PDF" : route} call failed`;
|
|
127
|
+
if (response.status >= 400 && response.status < 500 && isZiteErrorCode(answer?.code))
|
|
128
|
+
return { error: { code: answer.code, message } };
|
|
129
|
+
if (response.status === 400)
|
|
130
|
+
return { error: { code: "BAD_REQUEST", message } };
|
|
131
|
+
if (!response.ok)
|
|
132
|
+
throw new PlatformError(route, response.status);
|
|
133
|
+
return { value: answer };
|
|
134
|
+
};
|
|
135
|
+
/** `step.run`'s saves and a resumed run's read of them; the workflow and run come from the token. */
|
|
136
|
+
const steps = async (host, access, { methodName, params }) => {
|
|
137
|
+
const refused = (message) => ({ error: { code: "BAD_REQUEST", message } });
|
|
138
|
+
if (host.invoke?.kind !== "workflow")
|
|
139
|
+
return refused("step.run runs only in a workflow");
|
|
140
|
+
// Before any step's value leaves the app: with no workspace database there's nowhere to keep it.
|
|
141
|
+
if (appTokenClaims(access.token)?.base === null)
|
|
142
|
+
return refused("Durable steps need the workspace database, and this app has none");
|
|
143
|
+
const url = serviceUrl(access.urls, "steps");
|
|
144
|
+
if (methodName === "load") {
|
|
145
|
+
return { value: (await platformJson(access, "GET", url, "steps")).memos };
|
|
146
|
+
}
|
|
147
|
+
if (methodName !== "persist")
|
|
148
|
+
return refused(`Unknown steps method: ${methodName}`);
|
|
149
|
+
const { name, value, durationMs } = (params ?? {});
|
|
150
|
+
if (typeof name !== "string" || name.length === 0 || name.length > 255)
|
|
151
|
+
return refused("A step needs a name of 1 to 255 characters");
|
|
152
|
+
if (new TextEncoder().encode(JSON.stringify(value ?? null)).length > STEP_RESULT_MAX_BYTES) {
|
|
153
|
+
return refused(`step "${name}" returned more than ${STEP_RESULT_MAX_BYTES / 1024}KB`);
|
|
154
|
+
}
|
|
155
|
+
await platformJson(access, "POST", url, "steps", {
|
|
156
|
+
workflow: host.invoke.name,
|
|
157
|
+
name,
|
|
158
|
+
value: value ?? null,
|
|
159
|
+
...(Number.isInteger(durationMs) && durationMs >= 0 && { durationMs }),
|
|
160
|
+
});
|
|
161
|
+
return { value: { persisted: true } };
|
|
162
|
+
};
|
|
163
|
+
// Per isolate, as the host keeps them: until the token's settings version moves, or a minute without one.
|
|
164
|
+
const CONNECTIONS_REUSE_MS = 60_000;
|
|
165
|
+
const CONNECTIONS_MAX_AGE_MS = 10 * 60_000;
|
|
166
|
+
// Only answers, never a pending call: Workers ties a request's I/O to that request.
|
|
167
|
+
let tokenHeld;
|
|
168
|
+
/**
|
|
169
|
+
* The backend's `GET connections` on the token, once per reuse window: all `local` has, and what an app on Zite asks
|
|
170
|
+
* when the host didn't hand them over. Stale if the backend didn't answer.
|
|
171
|
+
*/
|
|
172
|
+
export const connectionsOnToken = async (access) => {
|
|
173
|
+
const claims = appTokenClaims(access.token);
|
|
174
|
+
const key = `${claims?.app ?? ""}:${claims?.build ?? ""}:${claims?.ver ?? ""}`;
|
|
175
|
+
const reuseMs = typeof claims?.ver === "number" ? CONNECTIONS_MAX_AGE_MS : CONNECTIONS_REUSE_MS;
|
|
176
|
+
if (tokenHeld?.key === key && Date.now() - tokenHeld.at < reuseMs)
|
|
177
|
+
return tokenHeld.answer;
|
|
178
|
+
try {
|
|
179
|
+
const answer = await backendJson(access, "GET", "/connections");
|
|
180
|
+
tokenHeld = {
|
|
181
|
+
key,
|
|
182
|
+
at: Date.now(),
|
|
183
|
+
answer: { connections: answer.connections ?? {}, env: answer.env ?? {}, envConnections: answer.envConnections ?? {} },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (!tokenHeld)
|
|
188
|
+
throw error;
|
|
189
|
+
console.error("[zite] couldn't refresh connections; using the last ones", error);
|
|
190
|
+
}
|
|
191
|
+
return tokenHeld.answer;
|
|
192
|
+
};
|
|
193
|
+
// A dev token names the newest build, whose page settings change only with another.
|
|
194
|
+
const PAGE_REUSE_MS = 60_000;
|
|
195
|
+
let localPage;
|
|
196
|
+
/** The build's page settings for `local`, which has no host to send them; null when the backend has none to give. */
|
|
197
|
+
export const localPagePlan = async (access) => {
|
|
198
|
+
const claims = appTokenClaims(access.token);
|
|
199
|
+
const key = `${claims?.app ?? ""}:${claims?.build ?? ""}`;
|
|
200
|
+
if (localPage?.key === key && Date.now() - localPage.at < PAGE_REUSE_MS)
|
|
201
|
+
return localPage.plan;
|
|
202
|
+
let plan = null;
|
|
203
|
+
try {
|
|
204
|
+
plan = (await backendJson(access, "GET", "/page")).page ?? null;
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error("[zite] couldn't load the app's page settings, so its pages get none of the platform's head", error);
|
|
208
|
+
}
|
|
209
|
+
localPage = { key, at: Date.now(), plan };
|
|
210
|
+
return plan;
|
|
211
|
+
};
|
|
212
|
+
// The app's place in Zite, which moves only with the app, and with it the dev token's base.
|
|
213
|
+
let localWorkspace;
|
|
214
|
+
/** `ZiteMeta.getWorkspace()` for `local`, which has no build config in props: the backend's, for the dev token's app. */
|
|
215
|
+
const localWorkspaceOf = async (access) => {
|
|
216
|
+
const claims = appTokenClaims(access.token);
|
|
217
|
+
const key = `${claims?.app ?? ""}:${claims?.base ?? ""}`;
|
|
218
|
+
if (localWorkspace?.key === key)
|
|
219
|
+
return localWorkspace.workspace;
|
|
220
|
+
const { workspace } = await backendJson(access, "GET", "/workspace");
|
|
221
|
+
if (workspace)
|
|
222
|
+
localWorkspace = { key, workspace };
|
|
223
|
+
return workspace;
|
|
224
|
+
};
|
|
225
|
+
/** `ZiteMeta`'s one method, as the host answered it from the build's config. */
|
|
226
|
+
const metaAnswer = (methodName, workspace) => {
|
|
227
|
+
if (methodName !== "getWorkspace")
|
|
228
|
+
return { error: { code: "BAD_REQUEST", message: `Unknown ZiteMeta method: ${methodName}` } };
|
|
229
|
+
return workspace
|
|
230
|
+
? { value: workspace }
|
|
231
|
+
: { error: { code: "INTERNAL_ERROR", message: "Publish the app again to use ZiteMeta.getWorkspace" } };
|
|
232
|
+
};
|
|
233
|
+
/** For tests: forget what this isolate learned. */
|
|
234
|
+
export const resetLocalConnections = () => {
|
|
235
|
+
refreshed.clear();
|
|
236
|
+
tokenHeld = undefined;
|
|
237
|
+
localPage = undefined;
|
|
238
|
+
localWorkspace = undefined;
|
|
239
|
+
};
|
|
240
|
+
const notFound = (name) => ({ error: { code: "BAD_REQUEST", message: `Integration ${name} not found` } });
|
|
241
|
+
const nameOf = ({ methodName, params }) => {
|
|
242
|
+
const name = params?.name;
|
|
243
|
+
return methodName === "get" && typeof name === "string" && name ? name : undefined;
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* `integrations.get` as the host answered it, from the connections the request was handed. A connection that needs
|
|
247
|
+
* reconnecting fails with classic's error, which visitors can see; the link to reconnect is a note for the run log,
|
|
248
|
+
* which only the owner reads.
|
|
249
|
+
*/
|
|
250
|
+
const connectionAnswer = (connections, name) => {
|
|
251
|
+
const answer = Object.hasOwn(connections, name) ? connections[name] : undefined;
|
|
252
|
+
if (!answer)
|
|
253
|
+
return { result: notFound(name) };
|
|
254
|
+
if (answer.status !== "unavailable")
|
|
255
|
+
return { result: { value: answer } };
|
|
256
|
+
const message = String(answer.message);
|
|
257
|
+
return {
|
|
258
|
+
result: {
|
|
259
|
+
error: {
|
|
260
|
+
code: "INTERNAL_ERROR",
|
|
261
|
+
message,
|
|
262
|
+
...(typeof answer.userFacingMessage === "string" && { userFacingMessage: answer.userFacingMessage }),
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
...(typeof answer.connectUrl === "string" && { note: `${message}; reconnect at ${answer.connectUrl}` }),
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
const MAX_REFRESHED = 50;
|
|
269
|
+
// A connection refreshed after a 401, by name, with the copy the host handed over when it was: later requests in the
|
|
270
|
+
// isolate use it rather than that copy, which failed, until the host hands over a different one.
|
|
271
|
+
const refreshed = new Map();
|
|
272
|
+
const keepRefreshed = (name, from, connection) => {
|
|
273
|
+
refreshed.delete(name);
|
|
274
|
+
refreshed.set(name, { from: JSON.stringify(from), connection });
|
|
275
|
+
if (refreshed.size > MAX_REFRESHED)
|
|
276
|
+
refreshed.delete(refreshed.keys().next().value);
|
|
277
|
+
};
|
|
278
|
+
const withRefreshed = (given, name) => {
|
|
279
|
+
const held = refreshed.get(name);
|
|
280
|
+
if (!held || !Object.hasOwn(given, name))
|
|
281
|
+
return given;
|
|
282
|
+
if (JSON.stringify(given[name]) !== held.from) {
|
|
283
|
+
refreshed.delete(name);
|
|
284
|
+
return given;
|
|
285
|
+
}
|
|
286
|
+
return { ...given, [name]: held.connection };
|
|
287
|
+
};
|
|
288
|
+
// As the host's run log kept it: a connection's values are its secrets, so only its status is shown.
|
|
289
|
+
const redactedConnection = (value) => value && typeof value === "object" && value.status === "connected"
|
|
290
|
+
? Object.fromEntries(Object.entries(value).map(([key, field]) => [key, key !== "status" && typeof field === "string" ? "[redacted]" : field]))
|
|
291
|
+
: value;
|
|
292
|
+
/** A call answered in the app, kept for the run's detail, which goes with the response's. */
|
|
293
|
+
const noted = (host, input, result, { outputs = preview, note } = {}) => {
|
|
294
|
+
(host.calls ??= []).push({
|
|
295
|
+
integrationId: input.integrationId,
|
|
296
|
+
className: input.className,
|
|
297
|
+
methodName: input.methodName,
|
|
298
|
+
at: Date.now(),
|
|
299
|
+
durationMs: 0,
|
|
300
|
+
inputs: preview(input.params),
|
|
301
|
+
...("value" in result ? { outputs: outputs(result.value) } : { error: { code: result.error.code, message: note ?? result.error.message } }),
|
|
302
|
+
});
|
|
303
|
+
return result;
|
|
304
|
+
};
|
|
305
|
+
const UNLOADED = {
|
|
306
|
+
error: { code: "INTERNAL_ERROR", message: "The app's connections couldn't be loaded; try again in a moment" },
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* `integrations.get`'s set: the host's, with any refreshed since, when it handed them over; else the backend's on the
|
|
310
|
+
* token, asked on the first call. Undefined when they couldn't be loaded. A registration is handed its one connection
|
|
311
|
+
* or nothing, since the backend's answer would name the rest.
|
|
312
|
+
*/
|
|
313
|
+
const connectionsOf = async (host, name) => {
|
|
314
|
+
if (host.connections)
|
|
315
|
+
return withRefreshed(host.connections, name);
|
|
316
|
+
if (host.invoke?.kind === "register")
|
|
317
|
+
return undefined;
|
|
318
|
+
const access = await directAccess(host);
|
|
319
|
+
if (!access)
|
|
320
|
+
throw new NoPlatformError();
|
|
321
|
+
try {
|
|
322
|
+
return (await (host.connectionsLoad ??= connectionsOnToken(access))).connections;
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
console.error("[zite] couldn't load the app's connections", error);
|
|
326
|
+
return undefined;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
/** `integrations.get`: one answer from whichever set the request has, recorded with the connection's values redacted. */
|
|
330
|
+
const integrationsGet = async (host, input) => {
|
|
331
|
+
const name = nameOf(input);
|
|
332
|
+
const connections = name ? await connectionsOf(host, name) : undefined;
|
|
333
|
+
const answered = !name
|
|
334
|
+
? { result: { error: { code: "BAD_REQUEST", message: "integrations.get(name): name must be a non-empty string" } } }
|
|
335
|
+
: connections
|
|
336
|
+
? connectionAnswer(connections, name)
|
|
337
|
+
: { result: UNLOADED };
|
|
338
|
+
return noted(host, input, answered.result, { outputs: (value) => preview(redactedConnection(value)), note: answered.note });
|
|
339
|
+
};
|
|
340
|
+
const somethingWentWrong = (host, input, error) => {
|
|
341
|
+
console.error("[zite] platform call failed", {
|
|
342
|
+
requestId: host.requestId,
|
|
343
|
+
call: `${input.className}.${input.methodName}`,
|
|
344
|
+
error: errorOf(error).message,
|
|
345
|
+
});
|
|
346
|
+
return { error: { code: "INTERNAL_ERROR", message: "Something went wrong" } };
|
|
347
|
+
};
|
|
348
|
+
// Sent as the call ends rather than with the response's flush, which a request past its deadline never reaches.
|
|
349
|
+
// `local` has no run log to send it to.
|
|
350
|
+
const report = (host, record) => {
|
|
351
|
+
if (host.provider?.kind === "local") {
|
|
352
|
+
(host.calls ??= []).push(record);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const sent = sendRunReport(host, { runs: [], calls: [record] }).catch((error) => console.error("[zite] couldn't record a platform call", error));
|
|
356
|
+
host.waitUntil?.(sent);
|
|
357
|
+
};
|
|
358
|
+
// The platform calls a request made, failures included, for its run, as the host once recorded the ones it relayed.
|
|
359
|
+
const recorded = async (host, input, run) => {
|
|
360
|
+
const at = Date.now();
|
|
361
|
+
const result = await run().catch((error) => somethingWentWrong(host, input, error));
|
|
362
|
+
report(host, {
|
|
363
|
+
integrationId: input.integrationId,
|
|
364
|
+
className: input.className,
|
|
365
|
+
methodName: input.methodName,
|
|
366
|
+
at,
|
|
367
|
+
durationMs: Date.now() - at,
|
|
368
|
+
inputs: preview(input.params),
|
|
369
|
+
...("value" in result ? { outputs: preview(result.value) } : { error: { code: result.error.code, message: result.error.message } }),
|
|
370
|
+
});
|
|
371
|
+
return result;
|
|
372
|
+
};
|
|
373
|
+
/** A platform call on the token; a throw without one. Errors come back as values, as the relay's did. */
|
|
374
|
+
export const directCall = async (host, input) => {
|
|
375
|
+
const demo = host.mode === "demo" ? demoAnswer(input) : undefined;
|
|
376
|
+
if (demo)
|
|
377
|
+
return demo;
|
|
378
|
+
// Only what leaves the app: an answer from props needs no token, so it outlives the dispatch's.
|
|
379
|
+
const access = async () => {
|
|
380
|
+
const granted = await directAccess(host);
|
|
381
|
+
if (!granted)
|
|
382
|
+
throw new NoPlatformError();
|
|
383
|
+
return granted;
|
|
384
|
+
};
|
|
385
|
+
try {
|
|
386
|
+
if (input.integrationId === STEPS_INTEGRATION_ID)
|
|
387
|
+
return await steps(host, await access(), input);
|
|
388
|
+
if (input.integrationId === META_INTEGRATION_ID) {
|
|
389
|
+
// Without props' answer, a request Zite didn't dispatch still fails loudly, and `local` asks the backend.
|
|
390
|
+
let workspace = host.workspace;
|
|
391
|
+
if (!workspace) {
|
|
392
|
+
const granted = await access();
|
|
393
|
+
if (host.provider?.kind === "local" && input.methodName === "getWorkspace")
|
|
394
|
+
workspace = await localWorkspaceOf(granted);
|
|
395
|
+
}
|
|
396
|
+
return noted(host, input, metaAnswer(input.methodName, workspace));
|
|
397
|
+
}
|
|
398
|
+
if (input.integrationId === INTEGRATIONS_PLATFORM_ID)
|
|
399
|
+
return await integrationsGet(host, input);
|
|
400
|
+
const route = sdkRoute(host, input);
|
|
401
|
+
if (route) {
|
|
402
|
+
const granted = await access();
|
|
403
|
+
return await recorded(host, input, () => sdk(granted, route));
|
|
404
|
+
}
|
|
405
|
+
if (input.integrationId === NOTIFICATIONS_INTEGRATION_ID)
|
|
406
|
+
return notFound(NOTIFICATIONS_INTEGRATION_ID);
|
|
407
|
+
return { error: { code: "NOT_FOUND", message: `${input.className}.${input.methodName} isn't served yet` } };
|
|
408
|
+
}
|
|
409
|
+
catch (error) {
|
|
410
|
+
if (error instanceof NoPlatformError)
|
|
411
|
+
throw error;
|
|
412
|
+
return somethingWentWrong(host, input, error);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
/** After a provider answered 401: the connection refreshed by the backend. */
|
|
416
|
+
export const refreshConnection = async (host, name) => {
|
|
417
|
+
const access = await directAccess(host);
|
|
418
|
+
if (!access)
|
|
419
|
+
return { error: { code: "INTERNAL_ERROR", message: new NoPlatformError().message } };
|
|
420
|
+
if (host.mode === "demo")
|
|
421
|
+
return DEMO_REFUSED;
|
|
422
|
+
let fresh;
|
|
423
|
+
try {
|
|
424
|
+
fresh = (await backendJson(access, "POST", `/connections/${encodeURIComponent(name)}/refresh`)).connection;
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
return error instanceof PlatformError && error.status === 404
|
|
428
|
+
? notFound(name)
|
|
429
|
+
: { error: { code: "INTERNAL_ERROR", message: `Integration ${name} could not be refreshed` } };
|
|
430
|
+
}
|
|
431
|
+
// Over whichever set the request read: the host's copy is replaced until the host hands over another, the backend's
|
|
432
|
+
// answer in place.
|
|
433
|
+
const given = host.connections;
|
|
434
|
+
if (fresh && given && Object.hasOwn(given, name))
|
|
435
|
+
keepRefreshed(name, given[name], fresh);
|
|
436
|
+
else if (fresh && !given && tokenHeld) {
|
|
437
|
+
tokenHeld.answer = { ...tokenHeld.answer, connections: { ...tokenHeld.answer.connections, [name]: fresh } };
|
|
438
|
+
}
|
|
439
|
+
if (fresh?.status !== "connected")
|
|
440
|
+
return { error: { code: "INTERNAL_ERROR", message: `Integration ${name} is not connected` } };
|
|
441
|
+
return { value: fresh };
|
|
442
|
+
};
|
|
@@ -11,6 +11,8 @@ const APP_START_FILES = ["src/start.ts", "src/start.tsx"];
|
|
|
11
11
|
*/
|
|
12
12
|
export const renderStartServerEntry = (target = "cloudflare") => target === "cloudflare"
|
|
13
13
|
? `// Generated by zitejs for TanStack Start apps. The platform owns this file.
|
|
14
|
+
// First, so an SDK client an app module builds as it loads gets zitejs's fetch.
|
|
15
|
+
import 'zitejs/start/fetch';
|
|
14
16
|
import handler from '@tanstack/react-start/server-entry';
|
|
15
17
|
import { createZiteWorker } from 'zitejs/start/worker';
|
|
16
18
|
import { getRouter } from '../src/router';
|
|
@@ -19,6 +21,8 @@ import { startInstance } from './start';
|
|
|
19
21
|
export default createZiteWorker({ handler, getRouter, startInstance });
|
|
20
22
|
`
|
|
21
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';
|
|
22
26
|
import handler, { createServerEntry } from '@tanstack/react-start/server-entry';
|
|
23
27
|
import { createZiteFetch } from 'zitejs/start/server';
|
|
24
28
|
import { getRouter } from '../src/router';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The generated server entry's first import: an SDK client an app builds at load (`new OpenAI()` at a module's top
|
|
2
|
+
// level) keeps the fetch it found then, so the wrapper must already be in place.
|
|
3
|
+
import { watchOutboundFetches } from "./outbound.js";
|
|
4
|
+
watchOutboundFetches();
|
|
@@ -8,8 +8,12 @@ import { isSignInRequired, loginHref, setFailedStatus } from "./index.js";
|
|
|
8
8
|
import { errorOf, preview } from "./runLog.js";
|
|
9
9
|
import { currentHost } from "./host.js";
|
|
10
10
|
import { getHost, inScope } from "./scope.js";
|
|
11
|
-
// TanStack drops its default CSRF check once an app has a start instance.
|
|
12
|
-
|
|
11
|
+
// TanStack drops its default CSRF check once an app has a start instance. Server functions, and every other unsafe
|
|
12
|
+
// request a browser's cookies ride on: the app's own routes too, as Zite's front checks them.
|
|
13
|
+
const SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
|
|
14
|
+
const csrf = createCsrfMiddleware({
|
|
15
|
+
filter: (ctx) => ctx.handlerType === "serverFn" || (!SAFE_METHODS.has(ctx.request.method) && ctx.request.headers.has("cookie")),
|
|
16
|
+
});
|
|
13
17
|
// The app's own request middleware runs inside this one. On a server-function request
|
|
14
18
|
// what it throws crosses to the browser as thrown, and only an Error goes through the
|
|
15
19
|
// zite-error adapter.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IdentityClaims, SignIn } from "../signin/index.js";
|
|
2
|
+
import type { PlatformUrls, User } from "./types.js";
|
|
3
|
+
/** What the module reads, from env or from the `.zite/dev.env` that `zitejs dev` writes. */
|
|
4
|
+
export declare const LOCAL_SIGNIN_ENV: {
|
|
5
|
+
readonly config: "ZITE_SIGNIN";
|
|
6
|
+
readonly secret: "ZITE_AUTH_SECRET";
|
|
7
|
+
};
|
|
8
|
+
type Env = Record<string, string | undefined>;
|
|
9
|
+
/** Where the backend serves the platform's public keys, for an unknown `kid`. */
|
|
10
|
+
export declare const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
11
|
+
/**
|
|
12
|
+
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
13
|
+
* set: the stand-in wins, with no network, as agent sandboxes need.
|
|
14
|
+
*/
|
|
15
|
+
export declare const localSignIn: (env: Env, urls: PlatformUrls, request: Request) => Promise<SignIn | undefined>;
|
|
16
|
+
/** The identity as app code reads it. Off Zite no role names are known, so each role is named by its id. */
|
|
17
|
+
export declare const userOfIdentity: (claims: IdentityClaims | null) => User | null;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The sign-in module mounted in the app, off Zite (T5 design §5.9). On Zite the dispatcher's own copy runs and this
|
|
2
|
+
// is never reached: a request with props never selects `local`.
|
|
3
|
+
import { platformFetch } from "../internal/platformFetch.js";
|
|
4
|
+
import { devSignIn } from "./devSignIn.js";
|
|
5
|
+
import { LOCAL_ENV } from "./provider.js";
|
|
6
|
+
/** What the module reads, from env or from the `.zite/dev.env` that `zitejs dev` writes. */
|
|
7
|
+
export const LOCAL_SIGNIN_ENV = { config: "ZITE_SIGNIN", secret: "ZITE_AUTH_SECRET" };
|
|
8
|
+
const configOf = (raw) => {
|
|
9
|
+
let given;
|
|
10
|
+
try {
|
|
11
|
+
given = JSON.parse(raw);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
given = undefined;
|
|
15
|
+
}
|
|
16
|
+
const config = (given ?? {});
|
|
17
|
+
const optional = ["redirectUri", "secret", "keysUrl"].every((name) => config[name] === undefined || typeof config[name] === "string");
|
|
18
|
+
if (typeof config.issuer !== "string" || typeof config.clientId !== "string" || !optional) {
|
|
19
|
+
throw new Error(`${LOCAL_SIGNIN_ENV.config} must be JSON naming the issuer and clientId, and may name redirectUri, secret and keysUrl`);
|
|
20
|
+
}
|
|
21
|
+
return config;
|
|
22
|
+
};
|
|
23
|
+
/** Where the backend serves the platform's public keys, for an unknown `kid`. */
|
|
24
|
+
export const SIGNING_KEYS_PATH = "/v1/zite/public/start/signing-keys";
|
|
25
|
+
const send = (request) => platformFetch(request);
|
|
26
|
+
/**
|
|
27
|
+
* The module for this request, when the env names an issuer; undefined otherwise, and whenever `ZITE_DEV_USER` is
|
|
28
|
+
* set: the stand-in wins, with no network, as agent sandboxes need.
|
|
29
|
+
*/
|
|
30
|
+
export const localSignIn = async (env, urls, request) => {
|
|
31
|
+
if (env[LOCAL_ENV.user])
|
|
32
|
+
return undefined;
|
|
33
|
+
const raw = env[LOCAL_SIGNIN_ENV.config] ?? devSignIn?.[LOCAL_SIGNIN_ENV.config];
|
|
34
|
+
if (!raw)
|
|
35
|
+
return undefined;
|
|
36
|
+
const secret = env[LOCAL_SIGNIN_ENV.secret] ?? devSignIn?.[LOCAL_SIGNIN_ENV.secret];
|
|
37
|
+
if (!secret)
|
|
38
|
+
throw new Error(`${LOCAL_SIGNIN_ENV.config} needs ${LOCAL_SIGNIN_ENV.secret}, which seals the session cookie: run \`zitejs dev\` to write both`);
|
|
39
|
+
const config = configOf(raw);
|
|
40
|
+
const [app = "", mode] = config.clientId.split(":");
|
|
41
|
+
// Only the developer's client for now; a self-hosted one comes with private key JWT.
|
|
42
|
+
if (mode !== "dev")
|
|
43
|
+
throw new Error(`${LOCAL_SIGNIN_ENV.config} names ${config.clientId}; off Zite the client is <app>:dev`);
|
|
44
|
+
const { aesGcmSealer, createSignIn, httpTransport, remoteIdentityKeys } = await import("../signin/index.js");
|
|
45
|
+
const sealer = aesGcmSealer(secret);
|
|
46
|
+
return createSignIn({
|
|
47
|
+
issuer: config.issuer,
|
|
48
|
+
clientId: config.clientId,
|
|
49
|
+
app,
|
|
50
|
+
mode,
|
|
51
|
+
ver: "any",
|
|
52
|
+
redirectUri: config.redirectUri,
|
|
53
|
+
keys: remoteIdentityKeys(config.keysUrl ?? `${urls.backend}${SIGNING_KEYS_PATH}`, { fetch: send }),
|
|
54
|
+
cookies: { secure: new URL(request.url).protocol === "https:", framed: false },
|
|
55
|
+
transport: httpTransport({
|
|
56
|
+
issuer: config.issuer,
|
|
57
|
+
clientId: config.clientId,
|
|
58
|
+
clientAuth: config.secret ? { kind: "secret", secret: config.secret } : { kind: "none" },
|
|
59
|
+
sealer,
|
|
60
|
+
fetch: send,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/** The identity as app code reads it. Off Zite no role names are known, so each role is named by its id. */
|
|
65
|
+
export const userOfIdentity = (claims) => claims && {
|
|
66
|
+
id: claims.sub,
|
|
67
|
+
email: claims.email,
|
|
68
|
+
name: claims.name,
|
|
69
|
+
...(claims.firstName !== undefined && { firstName: claims.firstName }),
|
|
70
|
+
...(claims.lastName !== undefined && { lastName: claims.lastName }),
|
|
71
|
+
roles: claims.roles.map((id) => ({ id, name: id })),
|
|
72
|
+
isInternal: claims.isInternal,
|
|
73
|
+
};
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
* it: logged, every secret it knows redacted, with the connection whose token
|
|
4
4
|
* it carries and what an org's own AI key used; a 401 on a connection's token
|
|
5
5
|
* refreshed and sent once more; and a call on Zite's own AI key sent to the
|
|
6
|
-
*
|
|
6
|
+
* AI gateway on the request's app token.
|
|
7
7
|
*/
|
|
8
8
|
import type { HostRequestState } from "./types.js";
|
|
9
|
+
/** At the gateway, the connection a call on Zite's AI key bills to: the marker's, which the token takes the place of. */
|
|
10
|
+
export declare const AI_CONNECTION_HEADER = "x-zite-ai-connection";
|
|
9
11
|
/** An `integrations.get` answer, whose values name the calls that carry them. */
|
|
10
12
|
export declare const rememberConnection: (host: HostRequestState, name: string, connection: unknown) => void;
|
|
13
|
+
/** An `integrations.get` answer with each token this isolate has since refreshed swapped for its replacement. */
|
|
14
|
+
export declare const withRefreshedTokens: (answer: unknown) => unknown;
|
|
15
|
+
/** A connection on Zite's AI key as `integrations.get` answers it, its `baseUrl` at the provider's gateway. */
|
|
16
|
+
export declare const withAiGatewayUrl: (host: HostRequestState, answer: unknown) => unknown;
|
|
11
17
|
export declare const createOutboundFetch: (nativeFetch: typeof fetch) => typeof fetch;
|
|
18
|
+
/** Wraps the global fetch once. Next patches fetch for the same reason: the run log must hear of each. */
|
|
19
|
+
export declare const watchOutboundFetches: () => void;
|