@plitzi/sdk-kernel 0.0.0-stage → 0.39.2
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/CHANGELOG.md +10 -0
- package/README.md +80 -2
- package/dist/build/esbuild.d.ts +16 -0
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.mjs +35 -0
- package/dist/cache/CompressedFileCache.d.ts +18 -0
- package/dist/cache/TtlCache.d.ts +65 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.mjs +1 -0
- package/dist/chunks/TtlCache-J_jG9oL9.mjs +200 -0
- package/dist/chunks/channel-DnVf7PJB.mjs +190 -0
- package/dist/chunks/csrf-BLWcaYOV.mjs +295 -0
- package/dist/chunks/link-C9wyDS9H.mjs +124 -0
- package/dist/chunks/query-DGbrN3mN.mjs +20 -0
- package/dist/chunks/scopes-Co6ZjhAm.mjs +46 -0
- package/dist/chunks/serverLog-BKaKjjc4.mjs +137 -0
- package/dist/chunks/session-B-dTEjeG.mjs +253 -0
- package/dist/chunks/sessionActivity-Ch7xuQ_o.mjs +43 -0
- package/dist/chunks/spaceDeployment-J2IMLfij.mjs +76 -0
- package/dist/chunks/stage-y6deE9LJ.mjs +345 -0
- package/dist/chunks/supervisor-Dh34v1vq.mjs +117 -0
- package/dist/chunks/tail-D-USrZIR.mjs +55 -0
- package/dist/chunks/tokens-CBd5tXut.mjs +262 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.mjs +68 -0
- package/dist/data/projectData.d.ts +21 -0
- package/dist/deployment/hostDeployment.d.ts +8 -0
- package/dist/deployment/index.d.ts +3 -0
- package/dist/deployment/index.mjs +19 -0
- package/dist/deployment/spaceDeployment.d.ts +11 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.mjs +1 -0
- package/dist/engine/page.d.ts +49 -0
- package/dist/engine/rsc.d.ts +32 -0
- package/dist/files/atomicFile.d.ts +10 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.mjs +32 -0
- package/dist/http/bearer.d.ts +5 -0
- package/dist/http/buildResponseHelpers.d.ts +23 -0
- package/dist/http/closeOnSignals.d.ts +28 -0
- package/dist/http/compress.d.ts +20 -0
- package/dist/http/dispatcher.d.ts +15 -0
- package/dist/http/drain.d.ts +18 -0
- package/dist/http/fleet/channel.d.ts +103 -0
- package/dist/http/fleet/link.d.ts +28 -0
- package/dist/http/fleet/role.d.ts +46 -0
- package/dist/http/fleet/supervisor.d.ts +29 -0
- package/dist/http/freePort.d.ts +24 -0
- package/dist/http/health.d.ts +21 -0
- package/dist/http/index.d.ts +48 -0
- package/dist/http/index.mjs +1313 -0
- package/dist/http/middlewares/auth.d.ts +2 -0
- package/dist/http/middlewares/basicAuth.d.ts +6 -0
- package/dist/http/mimeTypes.d.ts +13 -0
- package/dist/http/navigation.d.ts +14 -0
- package/dist/http/onAbort.d.ts +12 -0
- package/dist/http/probes.d.ts +4 -0
- package/dist/http/requestParser.d.ts +22 -0
- package/dist/http/runMiddlewares.d.ts +6 -0
- package/dist/http/securityHeaders.d.ts +18 -0
- package/dist/http/server.d.ts +39 -0
- package/dist/http/socketResponse.d.ts +18 -0
- package/dist/http/sse.d.ts +26 -0
- package/dist/http/stages/crossSiteWrites.d.ts +24 -0
- package/dist/http/stages/health.d.ts +11 -0
- package/dist/http/stages/middlewares.d.ts +3 -0
- package/dist/http/stages/static.d.ts +4 -0
- package/dist/http/staticFiles.d.ts +3 -0
- package/dist/http/stopping.d.ts +11 -0
- package/dist/http/transports.d.ts +31 -0
- package/dist/http/types.d.ts +29 -0
- package/dist/http/unusedPort.d.ts +10 -0
- package/dist/http/webExchange.d.ts +18 -0
- package/dist/http/wsFrame.d.ts +3 -0
- package/dist/identity/accounts.d.ts +278 -0
- package/dist/identity/authorize.d.ts +96 -0
- package/dist/identity/credentials.d.ts +40 -0
- package/dist/identity/csrf.d.ts +139 -0
- package/dist/identity/debugAuthorization.d.ts +24 -0
- package/dist/identity/domains.d.ts +41 -0
- package/dist/identity/identity.d.ts +119 -0
- package/dist/identity/index.d.ts +21 -0
- package/dist/identity/index.mjs +731 -0
- package/dist/identity/passwords.d.ts +15 -0
- package/dist/identity/previewToken.d.ts +21 -0
- package/dist/identity/requestIdentity.d.ts +14 -0
- package/dist/identity/scopes.d.ts +56 -0
- package/dist/identity/session.d.ts +185 -0
- package/dist/identity/sessionActivity.d.ts +11 -0
- package/dist/identity/spaceTokens.d.ts +174 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +1 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.mjs +3 -0
- package/dist/log/serverLog.d.ts +49 -0
- package/dist/log/tail.d.ts +43 -0
- package/dist/mysql/accounts.d.ts +4 -0
- package/dist/mysql/admin.d.ts +58 -0
- package/dist/mysql/config.d.ts +82 -0
- package/dist/mysql/identities.d.ts +35 -0
- package/dist/mysql/index.d.ts +7 -0
- package/dist/mysql/index.mjs +1203 -0
- package/dist/mysql/pool.d.ts +3 -0
- package/dist/mysql/query.d.ts +12 -0
- package/dist/mysql/schema.d.ts +43 -0
- package/dist/mysql/sessions.d.ts +23 -0
- package/dist/mysql/spaceTokens.d.ts +11 -0
- package/dist/mysql/store.d.ts +66 -0
- package/dist/outbound/index.d.ts +4 -0
- package/dist/outbound/index.mjs +314 -0
- package/dist/outbound/inside.d.ts +36 -0
- package/dist/outbound/outboundGuard.d.ts +69 -0
- package/dist/pubsub/index.d.ts +3 -0
- package/dist/pubsub/index.mjs +76 -0
- package/dist/pubsub/memoryPubSub.d.ts +10 -0
- package/dist/pubsub/redisPubSub.d.ts +24 -0
- package/dist/stats/index.d.ts +9 -0
- package/dist/stats/index.mjs +228 -0
- package/dist/stats/load.d.ts +31 -0
- package/dist/stats/memory.d.ts +20 -0
- package/dist/stats/pools.d.ts +15 -0
- package/dist/stats/recorder.d.ts +34 -0
- package/dist/stats/stage.d.ts +15 -0
- package/dist/stats/types.d.ts +309 -0
- package/dist/testing/certificates.d.ts +21 -0
- package/dist/testing/fleet.d.ts +28 -0
- package/dist/testing/goneRuns.d.ts +5 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.mjs +270 -0
- package/dist/testing/keys.d.ts +2 -0
- package/dist/testing/runNames.d.ts +10 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.mjs +1 -0
- package/dist/tokens/tokens.d.ts +190 -0
- package/dist/types/adapters.d.ts +388 -0
- package/dist/types/config.d.ts +240 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/log.d.ts +119 -0
- package/dist/types/oauth.d.ts +246 -0
- package/dist/types/pipeline.d.ts +239 -0
- package/package.json +67 -3
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { SSRAdapters } from './adapters';
|
|
2
|
+
import { LogLevel, ServerLogger } from './log';
|
|
3
|
+
import { SSRMiddleware, ServerEnvironment } from './pipeline';
|
|
4
|
+
import { StatsConfig } from '../stats/types';
|
|
5
|
+
import { ServerFlags } from '@plitzi/sdk-shared/flags';
|
|
6
|
+
/**
|
|
7
|
+
* What every Plitzi server process is configured with (RFC 0032, D12): its transport, its log, its health, the headers
|
|
8
|
+
* it answers with, what it may reach, and the adapters it asks. A page server's configuration and the actions engine's
|
|
9
|
+
* are both this and their own.
|
|
10
|
+
*/
|
|
11
|
+
export type ServerBaseConfig = {
|
|
12
|
+
port?: number;
|
|
13
|
+
host?: string;
|
|
14
|
+
httpVersion?: 1 | 2 | 3;
|
|
15
|
+
tls?: {
|
|
16
|
+
key: Buffer | string;
|
|
17
|
+
cert: Buffer | string;
|
|
18
|
+
minVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
|
|
19
|
+
};
|
|
20
|
+
environment?: ServerEnvironment;
|
|
21
|
+
/** Served to anyone who asks, as it is: pictures, a favicon, what a page fetches in the browser. */
|
|
22
|
+
publicDir?: string;
|
|
23
|
+
/**
|
|
24
|
+
* The project's own data, never served as files: a provider resolved on the server (`runtime: 'server'`) whose
|
|
25
|
+
* `query` is `/data/<file>` reads `<dataDir>/<file>`, and the page arrives with it. Nobody downloads the folder; what
|
|
26
|
+
* a provider reads goes into the page it renders, though — data a page must not carry is a server action's to read,
|
|
27
|
+
* answering only what is shown: a function reads it with `ctx.data('<file>')`. It is the space's data lookup
|
|
28
|
+
* (`action.lookups.getData`) when the deployment gives none.
|
|
29
|
+
*/
|
|
30
|
+
dataDir?: string;
|
|
31
|
+
static?: Record<string, string>;
|
|
32
|
+
devMode?: boolean;
|
|
33
|
+
/** Authorizes debugging on the pages this server renders. An SSR page loads the very same SDK, so this is the
|
|
34
|
+
* server-side face of the SDK's `debugMode` prop: the page decides, and the visitor's 'plitzi_debug' cookie can
|
|
35
|
+
* only narrow it. Left unset, `devMode` authorizes it — a development server debugs without being told to — and
|
|
36
|
+
* so does a space whose settings switched `devTools` on. Set, it decides for every space: `false` is a refusal
|
|
37
|
+
* no space can turn around. */
|
|
38
|
+
debugMode?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The feature flags this deployment decides, by name — the `server` layer: above what each space declares, below
|
|
41
|
+
* the SDK embedding a page and a tester with the dev tools. Only for flags a space declares; an override of one it
|
|
42
|
+
* does not is ignored, and the page says so in its console.
|
|
43
|
+
*
|
|
44
|
+
* A function when one server renders several spaces and they do not share their flags: it is asked per render.
|
|
45
|
+
*/
|
|
46
|
+
flags?: ServerFlags;
|
|
47
|
+
/** How long a rendered page, its schema data and a basic-auth check are kept, in ms. Default 300 000; `0` keeps none. */
|
|
48
|
+
cacheTtlMs?: number;
|
|
49
|
+
middlewares?: SSRMiddleware[];
|
|
50
|
+
/**
|
|
51
|
+
* What the requests a space's documents write may reach from inside this server. See {@link SSROutboundConfig}.
|
|
52
|
+
*/
|
|
53
|
+
outbound?: SSROutboundConfig;
|
|
54
|
+
/** Controls iframe embedding via CSP frame-ancestors (and X-Frame-Options for legacy browsers).
|
|
55
|
+
* 'DENY' — no site may embed this server (default).
|
|
56
|
+
* 'SAMEORIGIN' — only the same origin may embed it.
|
|
57
|
+
* string[] — explicit list of allowed origins, e.g. ['https://app.example.com', 'https://preview.example.com'].
|
|
58
|
+
* false — no restriction; headers are omitted. */
|
|
59
|
+
frameOptions?: 'DENY' | 'SAMEORIGIN' | string[] | false;
|
|
60
|
+
/**
|
|
61
|
+
* `Strict-Transport-Security` on every response over https: browsers then refuse the site over plain http, and ask it
|
|
62
|
+
* over https from the first request. A year, with every sub-domain, by default; `preload` only once the domain is
|
|
63
|
+
* submitted to the browsers' list. Never on this machine nor on a domain no public CA certifies (`.local`, `.test`,
|
|
64
|
+
* `.localhost`): a browser told so would refuse a development certificate with no way past it. `false` sends none.
|
|
65
|
+
*/
|
|
66
|
+
hsts?: false | {
|
|
67
|
+
maxAge?: number;
|
|
68
|
+
includeSubDomains?: boolean;
|
|
69
|
+
preload?: boolean;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* `Cross-Origin-Opener-Policy`: a page opened from another site, or that opens one, is put in a browsing context of
|
|
73
|
+
* its own — the other cannot reach it through `window.opener`. `same-origin-allow-popups` by default, which keeps what
|
|
74
|
+
* a page opens (a payment, a sign-in with another provider) able to answer it; `same-origin` isolates those too.
|
|
75
|
+
* `false` sends none.
|
|
76
|
+
*/
|
|
77
|
+
crossOriginOpenerPolicy?: false | 'same-origin' | 'same-origin-allow-popups' | 'unsafe-none';
|
|
78
|
+
/**
|
|
79
|
+
* The writes a page of another origin may cause here. None, by default: a browser's POST, PUT, PATCH or DELETE that it
|
|
80
|
+
* says a page of another origin caused (`Sec-Fetch-Site` `cross-site` or `same-site` — another port of this host, a
|
|
81
|
+
* sibling sub-domain — or a foreign `Origin`) is refused 403 `reason: 'foreign'` —
|
|
82
|
+
* a session cookie or none, because a server holding credentials of its own, or a tool nobody signs in to, acts for
|
|
83
|
+
* whoever reaches it. A request with `Authorization`, and one that is not a browser's (a webhook, a script), are never
|
|
84
|
+
* asked. With `auth`, the deployment's `identity.platformOrigins` count as its own too.
|
|
85
|
+
*/
|
|
86
|
+
crossSiteWrites?: {
|
|
87
|
+
/** Origins whose pages may write here, exactly as a browser sends them — `https://app.example.com`. */
|
|
88
|
+
origins?: string[];
|
|
89
|
+
/** Paths any origin may post to: a form other sites embed by design. */
|
|
90
|
+
paths?: (path: string) => boolean;
|
|
91
|
+
};
|
|
92
|
+
/** Receives a {@link ServerLogEvent} for every HTTP request this server answers — whatever stage answered it
|
|
93
|
+
* and whatever the outcome — plus every MCP tool call and resource read inside those requests. Without it the
|
|
94
|
+
* server reports nothing per request (the MCP events still reach the console when `MCP_DEBUG=1`). Everything
|
|
95
|
+
* else the server has to say — a failure, a plugin rebuilt — comes here too as a `message` event, and goes to the
|
|
96
|
+
* console when there is no logger. */
|
|
97
|
+
logger?: ServerLogger;
|
|
98
|
+
/**
|
|
99
|
+
* The least severe thing worth saying — see {@link LogLevel}. `error` by default, `info` with `devMode`: a server
|
|
100
|
+
* in production reports what went wrong and nothing else, unless asked. A request that was answered is `info`, one
|
|
101
|
+
* that failed `error`; a refused action is `warn`. Below the level nothing is built, so a quiet server pays nothing
|
|
102
|
+
* per request for the log it is not keeping.
|
|
103
|
+
*/
|
|
104
|
+
logLevel?: LogLevel | 'silent';
|
|
105
|
+
/**
|
|
106
|
+
* How it stops when told to (`close()`, a SIGTERM through `closeOnSignals`): for `announceMs` it keeps serving with
|
|
107
|
+
* `/health` answering 503 — so a load balancer takes it out of rotation before its port closes; 0 by default, 5000
|
|
108
|
+
* behind one — and then what it is answering has `graceMs` to finish before it is cut: 10000 by default, and at least
|
|
109
|
+
* the longest action it runs (a call cut halfway is a run lost). Its orchestrator's own grace (a pod's
|
|
110
|
+
* `terminationGracePeriodSeconds`) is longer than the two together.
|
|
111
|
+
*/
|
|
112
|
+
shutdown?: {
|
|
113
|
+
announceMs?: number;
|
|
114
|
+
graceMs?: number;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* From how many ms a run that worked is said as slow, at `warn`, with its steps; below it a run that worked is `debug`.
|
|
118
|
+
* 1000 by default (`SLOW_RUN_MS`): raise it where the actions are slow on purpose — a report, an import.
|
|
119
|
+
*/
|
|
120
|
+
slowRunMs?: number;
|
|
121
|
+
/**
|
|
122
|
+
* How responses are compressed. Omit for Brotli where the client takes it and gzip otherwise; `false` never
|
|
123
|
+
* compresses, which is what to use when a proxy or CDN in front already does it.
|
|
124
|
+
*/
|
|
125
|
+
compression?: SSRCompressionConfig | false;
|
|
126
|
+
/**
|
|
127
|
+
* What to do when the server cannot take its port. Without it the server prints what went wrong, what to do about
|
|
128
|
+
* it, and exits non-zero — because a process whose server never bound is not running, and the alternative is a raw
|
|
129
|
+
* `EADDRINUSE` stack that says nothing about which port or which server.
|
|
130
|
+
*
|
|
131
|
+
* Supply this to keep the process alive and decide for yourself: an embedder that starts several servers, a
|
|
132
|
+
* supervisor that retries, a test that asserts the failure. Handling it here replaces the exit entirely.
|
|
133
|
+
*/
|
|
134
|
+
onListenError?: (error: NodeJS.ErrnoException, context: {
|
|
135
|
+
port: number;
|
|
136
|
+
host: string;
|
|
137
|
+
label: string;
|
|
138
|
+
}) => void;
|
|
139
|
+
/**
|
|
140
|
+
* How many processes serve this port. Node runs JavaScript on one thread, so one process renders on one core however
|
|
141
|
+
* many the machine has; each worker is a whole server of its own, and the connections are spread between them —
|
|
142
|
+
* more requests a second, and less time waiting behind another render.
|
|
143
|
+
*
|
|
144
|
+
* `true` / `'auto'`: one per core the process may actually use (a container's CPU quota included). `false`: one
|
|
145
|
+
* process. A number: that many, lowered to the cores there are (more only take turns on the same cores). Default: on
|
|
146
|
+
* under `NODE_ENV=production`, off otherwise — a development server and a test runner stay one process. The
|
|
147
|
+
* `SDK_SERVER_WORKERS` environment variable sets it when this does not.
|
|
148
|
+
*
|
|
149
|
+
* The workers are one server — one replica — and behave as one:
|
|
150
|
+
*
|
|
151
|
+
* - The stores kept in memory by default (an action's `kv`, the job queue, draft previews, the sign-in rate
|
|
152
|
+
* limit) are the primary's, and each worker reaches them over the cluster channel. A store the deployment
|
|
153
|
+
* supplies (Redis, a table) is used as it is.
|
|
154
|
+
* - The scheduler and the job consumers run in one worker only, so a schedule fires once and `jobs.workers` is the
|
|
155
|
+
* whole server's concurrency; if that worker dies, its replacement takes them over.
|
|
156
|
+
* - `server.cache.invalidate()`, `server.plugins.register()` and `server.plugins.invalidate()` reach every worker,
|
|
157
|
+
* whichever process calls them.
|
|
158
|
+
*
|
|
159
|
+
* Per worker: the rendered-page cache (each renders a page once), the plugin components, and the action run caps
|
|
160
|
+
* (`action.concurrency`: `perSpace`, `perProcess`, `renderPerProcess`), which a cluster of replicas already counts
|
|
161
|
+
* per replica. A plugin registered with a `component` stays in the process that registered it — register those
|
|
162
|
+
* where the server is created.
|
|
163
|
+
*/
|
|
164
|
+
workers?: boolean | number | 'auto';
|
|
165
|
+
adapters: SSRAdapters;
|
|
166
|
+
/** Liveness/readiness endpoint for standalone servers (k8s probes). A stage always answers `path`
|
|
167
|
+
* (default /health) with the generic identity payload built from `name`/`version`/`role`
|
|
168
|
+
* ({ Server, Version, role }); pass an explicit `payload` to override it entirely, or `check` to add what can
|
|
169
|
+
* only be known per request. See {@link SSRHealthConfig}. */
|
|
170
|
+
health?: SSRHealthConfig;
|
|
171
|
+
/**
|
|
172
|
+
* This process's stats (`GET /_stats`, behind `secret`): its pool and instance, its load, how its work went over the
|
|
173
|
+
* last minute, quarter and hour, and whether that is healthy — what `readPools` reads of every process alike. Absent,
|
|
174
|
+
* it keeps none and answers nothing there.
|
|
175
|
+
*/
|
|
176
|
+
stats?: StatsConfig;
|
|
177
|
+
};
|
|
178
|
+
export type SSRHealthConfig = {
|
|
179
|
+
path?: string;
|
|
180
|
+
/** Replaces the identity payload entirely. `check` still merges over it. */
|
|
181
|
+
payload?: Record<string, unknown>;
|
|
182
|
+
name?: string;
|
|
183
|
+
version?: string;
|
|
184
|
+
role?: string;
|
|
185
|
+
/**
|
|
186
|
+
* Which of the servers that answer with this name this one is — a project's copy in another folder, a replica —
|
|
187
|
+
* answered as `Instance`: a tool reaching a port tells the server it meant from another of the same name by it.
|
|
188
|
+
*/
|
|
189
|
+
instance?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Live state, read on every probe and merged over the payload — the stores this process depends on, a queue
|
|
192
|
+
* depth, whatever only this deployment can know. Returning `healthy: false` answers **503**, which is what turns
|
|
193
|
+
* the endpoint from a liveness check into a readiness one: an orchestrator stops routing to a replica whose
|
|
194
|
+
* database has gone, instead of sending it traffic it can only fail.
|
|
195
|
+
*
|
|
196
|
+
* A check that throws is itself an unhealthy answer, and is reported as one rather than as a 500.
|
|
197
|
+
*/
|
|
198
|
+
check?: () => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
199
|
+
};
|
|
200
|
+
/** Response compression. Every field has a default; supply only what this deployment wants different. */
|
|
201
|
+
export type SSRCompressionConfig = {
|
|
202
|
+
/**
|
|
203
|
+
* Which encodings this server will use, most preferred first — the first one the client accepts wins. Default
|
|
204
|
+
* `['br', 'gzip']`. `['gzip']` for a client or proxy that mishandles Brotli; `[]` disables compression, same as
|
|
205
|
+
* `compression: false`.
|
|
206
|
+
*/
|
|
207
|
+
encodings?: ('br' | 'gzip')[];
|
|
208
|
+
/** Responses smaller than this many bytes go out uncompressed. Default 1024. */
|
|
209
|
+
threshold?: number;
|
|
210
|
+
/**
|
|
211
|
+
* Brotli quality, 0–11, for a body compressed on every request — a page rendered for this request alone. Default 5:
|
|
212
|
+
* the first quality under gzip's size for the CPU gzip spends — 2 came out larger than gzip on a 220 KB page (36 KB
|
|
213
|
+
* against 31; 5: 29). On half a core it costs ~0.1 ms a page, 5–8% of the pages a second of a 6 KB page.
|
|
214
|
+
*/
|
|
215
|
+
brotliQuality?: number;
|
|
216
|
+
/**
|
|
217
|
+
* Brotli quality, 0–11, for a body compressed once and kept — a cached page, a static file such as the SDK bundle.
|
|
218
|
+
* Default 6: paid once, and every later response is that much smaller (the SDK bundle 10% under quality 4), for
|
|
219
|
+
* the same memory as 4. 9 needs ~40 MB more to compress the bundle, which a 128 MB server does not have; 10 and
|
|
220
|
+
* 11 cost seconds, which the request that fills the cache would wait for.
|
|
221
|
+
*/
|
|
222
|
+
keptBrotliQuality?: number;
|
|
223
|
+
/** Gzip level, 0–9. Default 6. */
|
|
224
|
+
gzipLevel?: number;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* What the requests a space's documents write may reach from inside this server — a server provider's `query`, an
|
|
228
|
+
* action's `http.request`, a connector, a function's `fetch`, a plugin's address.
|
|
229
|
+
*
|
|
230
|
+
* Each is typed by whoever edits a space and sent from a trusted network position, so none reaches a private address
|
|
231
|
+
* (`localhost`, this server's own network, the cloud's metadata) — but the deployment's own storage, CDN or API may sit
|
|
232
|
+
* on that network, put there by whoever runs it. Those origins are named here, and only they are reached.
|
|
233
|
+
*/
|
|
234
|
+
export type SSROutboundConfig = {
|
|
235
|
+
/**
|
|
236
|
+
* Origins on this server's own network a space's requests may reach: `http://localhost:9000` for a local S3, the
|
|
237
|
+
* cluster's `http://api.internal` — an origin (`scheme://host:port`), no path. Everything else private stays closed.
|
|
238
|
+
*/
|
|
239
|
+
privateOrigins?: string[];
|
|
240
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ComponentCatalog, ComponentCatalogEntry, MeteredKind, SSRAdapters, SSRDeploymentSecurity, SSRMeterDecision, SSRMeterEvent, SSRPageAdapters, SSRRscContext, SSRScriptPolicyReport, SSRSpaceDeployment } from './adapters';
|
|
2
|
+
export type { SSRCompressionConfig, SSRHealthConfig, SSROutboundConfig, ServerBaseConfig } from './config';
|
|
3
|
+
export type { ActionRejectLogEvent, ActionRunLogEvent, LogLevel, McpResourceLogEvent, McpToolLogEvent, ServerLogEvent, ServerLogger, ServerMessageLogEvent, ServerRequestLogEvent } from './log';
|
|
4
|
+
export type { OAuthAdapters, OAuthBranding, OAuthConfig, OAuthConsentView, OAuthGrantTarget, OAuthGuestConfig, OAuthIssueContext, OAuthStore, OAuthUser } from './oauth';
|
|
5
|
+
export type { CompressedBodies, SSRChangePage, SSRAuthCookie, SSRChangeQuery, SSRContext, SSRCredential, SSRGrant, SSRHeaders, SSRMiddleware, SSRMiddlewareNext, SSRRequest, SSRResponseHelpers, SSRSession, SSRTemplateProps, SSRWriteContext, ServerEnvironment } from './pipeline';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ActionRejectReason, ActionRunStatus, ActionTriggerType, Environment } from '@plitzi/sdk-shared';
|
|
2
|
+
type ServerLogEventBase = {
|
|
3
|
+
/** Wall-clock duration of the work the event describes, in milliseconds. */
|
|
4
|
+
durationMs: number;
|
|
5
|
+
/** False when the work threw or answered an error status. */
|
|
6
|
+
ok: boolean;
|
|
7
|
+
/** The error message when `ok` is false — never the request payload. */
|
|
8
|
+
error?: string;
|
|
9
|
+
/** ISO-8601 timestamp of when the event was emitted. */
|
|
10
|
+
timestamp: string;
|
|
11
|
+
};
|
|
12
|
+
/** What every log event carries, whatever layer it came from. */
|
|
13
|
+
/**
|
|
14
|
+
* How much a server says, from least to most: each level includes every one above it. `error` is what a production
|
|
15
|
+
* server shows unless told otherwise — something went wrong — and `warn` (a refusal, a slow run), `info` (every request
|
|
16
|
+
* answered, every plugin built) and `debug` (every run that worked, every probe answered) are asked for. `silent` says
|
|
17
|
+
* nothing at all.
|
|
18
|
+
*/
|
|
19
|
+
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
|
|
20
|
+
/** One HTTP request served by ANY Plitzi server — SSR pages, RSC, plugin assets, the preview endpoint, MCP —
|
|
21
|
+
* emitted by the dispatcher once the request is answered, including the ones that failed or were rejected. */
|
|
22
|
+
export type ServerRequestLogEvent = ServerLogEventBase & {
|
|
23
|
+
kind: 'request';
|
|
24
|
+
/** Which server answered — the dispatcher label, e.g. 'SSR' or 'MCP'. */
|
|
25
|
+
server: string;
|
|
26
|
+
method: string;
|
|
27
|
+
/** Request path with query VALUES stripped and only the keys kept, e.g. '/search?q&page'. */
|
|
28
|
+
path: string;
|
|
29
|
+
/** The operation inside the request, when the answering stage names one — e.g. the MCP JSON-RPC method. */
|
|
30
|
+
operation?: string;
|
|
31
|
+
/** The HTTP status the server answered with. */
|
|
32
|
+
status: number;
|
|
33
|
+
/** The client the request came from, resolved through the proxies the deployment sits behind. Empty when no
|
|
34
|
+
* address could be determined. It IS personal data — see the note on {@link ServerLogEvent}. */
|
|
35
|
+
clientIp?: string;
|
|
36
|
+
};
|
|
37
|
+
/** One plitzi_* tool call inside an MCP request. Reported separately from the request because a failing tool
|
|
38
|
+
* still answers HTTP 200 — the failure lives in the JSON-RPC payload, so only this event exposes it. */
|
|
39
|
+
export type McpToolLogEvent = ServerLogEventBase & {
|
|
40
|
+
kind: 'tool';
|
|
41
|
+
/** The tool name, e.g. 'plitzi_apply'. */
|
|
42
|
+
name: string;
|
|
43
|
+
/** A compact SHAPE summary of the arguments — keys, value types and array lengths, never values. Set
|
|
44
|
+
* `MCP_LOG_ARGS=1` to dump the real arguments instead; they may carry user content, so it stays opt-in. */
|
|
45
|
+
argsSummary?: string;
|
|
46
|
+
};
|
|
47
|
+
/** One plitzi:// resource read inside an MCP request, named by the URI the request asked for. */
|
|
48
|
+
export type McpResourceLogEvent = ServerLogEventBase & {
|
|
49
|
+
kind: 'resource';
|
|
50
|
+
/** The resource URI that was read, e.g. 'plitzi://element/hero_1'. */
|
|
51
|
+
name: string;
|
|
52
|
+
};
|
|
53
|
+
/** One server action run that STARTED — completed, failed or aborted.
|
|
54
|
+
*
|
|
55
|
+
* Its own event rather than a line on the request that triggered it, for the same reason a tool call is: the
|
|
56
|
+
* request is answered either way, and a run started by a schedule or a webhook has a request that says nothing
|
|
57
|
+
* about it. Where the request log answers "was this call served", this answers "what did the flow do".
|
|
58
|
+
*
|
|
59
|
+
* Carries the SHAPE of the run and never its data: which steps ran and how each ended, never what they
|
|
60
|
+
* returned. A refused run is absent by design — a 409 is not a run, and logging one buries the real ones under
|
|
61
|
+
* retries. */
|
|
62
|
+
export type ActionRunLogEvent = ServerLogEventBase & {
|
|
63
|
+
kind: 'run';
|
|
64
|
+
/** The action's identifier, as the space stores it. */
|
|
65
|
+
name: string;
|
|
66
|
+
spaceId: number;
|
|
67
|
+
environment: Environment;
|
|
68
|
+
/** What started it: a page call, a webhook, a schedule, a render, a trigger the deployment mounted. */
|
|
69
|
+
trigger: ActionTriggerType;
|
|
70
|
+
status: ActionRunStatus;
|
|
71
|
+
/** Who asked, when a session carried it. Absent for a webhook, a schedule or an anonymous visitor. */
|
|
72
|
+
userId?: number;
|
|
73
|
+
/** Each step as `action:status`, in order — enough to see where a flow stopped without keeping what it held. */
|
|
74
|
+
steps: string[];
|
|
75
|
+
};
|
|
76
|
+
/** One request that was REFUSED before it became a run — a webhook whose signature did not verify, a caller over
|
|
77
|
+
* its rate limit, an action nobody may start.
|
|
78
|
+
*
|
|
79
|
+
* Separate from {@link ActionRunLogEvent} because it is a different question: that one says what a flow did,
|
|
80
|
+
* this one says why a flow never happened. It is the only place an integration that is failing at the door
|
|
81
|
+
* shows up at all — the request log answers 401 and says nothing about which check refused it.
|
|
82
|
+
*
|
|
83
|
+
* `durationMs` is 0 and `ok` is always false: nothing ran, and a refusal is not a success on anybody's dashboard. */
|
|
84
|
+
export type ActionRejectLogEvent = ServerLogEventBase & {
|
|
85
|
+
kind: 'reject';
|
|
86
|
+
/** The action's identifier, as the request named it — it need not exist. */
|
|
87
|
+
name: string;
|
|
88
|
+
spaceId: number;
|
|
89
|
+
environment: Environment;
|
|
90
|
+
trigger: ActionTriggerType;
|
|
91
|
+
/** Which check refused it. */
|
|
92
|
+
reason: ActionRejectReason;
|
|
93
|
+
/** Who asked, as the transport identifies them — a session subject or an address. */
|
|
94
|
+
callerId?: string;
|
|
95
|
+
};
|
|
96
|
+
/** Everything a Plitzi server reports about the work it does, as ONE stream: the HTTP requests it answers, plus
|
|
97
|
+
* the MCP tool calls, resource reads and server-action runs that happen inside them. Wire a single sink via
|
|
98
|
+
* `SSRServerConfig.logger` and switch on `kind` — a consumer can render it, ship it to a dashboard or drop the
|
|
99
|
+
* kinds it does not want.
|
|
100
|
+
*
|
|
101
|
+
* Payload-free by construction: no headers, cookies, tokens nor request body ever reach an event, query values
|
|
102
|
+
* are stripped from paths, tool arguments are reduced to their shape and a run to its steps. Two fields are NOT
|
|
103
|
+
* anonymous and a consumer shipping these events must handle them accordingly: `clientIp` on a request event, and
|
|
104
|
+
* the request path, which is kept verbatim because it is what makes the log usable. */
|
|
105
|
+
/** Anything else the server has to say — a plugin rebuilt, a manifest that would not load — at its own level. */
|
|
106
|
+
export type ServerMessageLogEvent = {
|
|
107
|
+
kind: 'message';
|
|
108
|
+
level: LogLevel;
|
|
109
|
+
/** What is speaking: `SSR`, `RSC`, `Actions`, `auth`… — what a line used to start with in brackets. */
|
|
110
|
+
scope: string;
|
|
111
|
+
message: string;
|
|
112
|
+
ok: boolean;
|
|
113
|
+
error?: string;
|
|
114
|
+
timestamp: string;
|
|
115
|
+
};
|
|
116
|
+
export type ServerLogEvent = ServerRequestLogEvent | McpToolLogEvent | McpResourceLogEvent | ActionRunLogEvent | ActionRejectLogEvent | ServerMessageLogEvent;
|
|
117
|
+
/** The sink a consumer provides to receive every {@link ServerLogEvent} (see `SSRServerConfig.logger`). */
|
|
118
|
+
export type ServerLogger = (event: ServerLogEvent) => void;
|
|
119
|
+
export {};
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { SSRRequest, SSRResponseHelpers } from './pipeline';
|
|
2
|
+
/** A key/value store with per-entry expiry, backing the OAuth layer's short-lived protocol state (registered
|
|
3
|
+
* clients, authorization codes, refresh grants). Values are opaque strings the SDK serialises itself. A
|
|
4
|
+
* multi-replica deployment MUST inject a shared implementation — a code minted on one replica is redeemed on
|
|
5
|
+
* whichever replica the token request lands on. */
|
|
6
|
+
export type OAuthStore = {
|
|
7
|
+
put: (key: string, value: string, ttlSeconds: number) => void | Promise<void>;
|
|
8
|
+
get: (key: string) => (string | undefined) | Promise<string | undefined>;
|
|
9
|
+
drop: (key: string) => void | Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/** Someone who got through {@link OAuthAdapters.authenticate}. `id` is what the other adapters key off; `label`
|
|
12
|
+
* is shown back on the consent screen so the user can see who they are about to grant access as. */
|
|
13
|
+
export type OAuthUser = {
|
|
14
|
+
id: string;
|
|
15
|
+
label: string;
|
|
16
|
+
};
|
|
17
|
+
/** One thing the user may grant the client access to — a Plitzi space, or whatever else a deployment scopes its
|
|
18
|
+
* tokens by. `value` is the opaque handle the SDK round-trips back to {@link OAuthAdapters.issueToken}; only the
|
|
19
|
+
* consumer interprets it. A deployment whose public surface is useful on its own (plitzi_render needs no space)
|
|
20
|
+
* can offer a target that grants nothing, so the user is never forced to pick one. */
|
|
21
|
+
export type OAuthGrantTarget = {
|
|
22
|
+
value: string;
|
|
23
|
+
label: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
};
|
|
26
|
+
/** What the OAuth layer cannot resolve on its own: who the user is, what they may grant, and the bearer to mint
|
|
27
|
+
* for them. The SDK owns the protocol (discovery, registration, PKCE, code exchange); the consumer owns identity
|
|
28
|
+
* and issues a token its own `adapters.getGrant` will accept back. */
|
|
29
|
+
export type OAuthAdapters = {
|
|
30
|
+
/**
|
|
31
|
+
* Who the browser making this request already is, from whatever session it carries.
|
|
32
|
+
*
|
|
33
|
+
* This server has no sign-in of its own: it reads an existing session and sends anyone it cannot identify to
|
|
34
|
+
* {@link OAuthConfig.signInUrl}, which brings them back. That is what lets a deployment have ONE sign-in screen
|
|
35
|
+
* for every surface — and it is what makes SSO somebody else's problem, because whatever established the
|
|
36
|
+
* session is no longer this flow's business.
|
|
37
|
+
*
|
|
38
|
+
* It replaced a username/password form this server used to render and check itself. Two sign-ins against one
|
|
39
|
+
* account store is two places to add a provider, to rate-limit, and to get a password check subtly wrong.
|
|
40
|
+
*
|
|
41
|
+
* Return undefined for "nobody is signed in". Never throw for that — an unreadable session is the ordinary
|
|
42
|
+
* first visit.
|
|
43
|
+
*/
|
|
44
|
+
identify: (req: SSRRequest) => Promise<OAuthUser | undefined>;
|
|
45
|
+
/**
|
|
46
|
+
* What this user may grant access to. An empty list ends the flow with `access_denied`.
|
|
47
|
+
*
|
|
48
|
+
* `request.scope` is what the client asked for, so one deployment can offer different choices to different
|
|
49
|
+
* clients — a native client signing in as the person, and the same client asking which space to work in.
|
|
50
|
+
*/
|
|
51
|
+
grantTargets: (user: OAuthUser, request: {
|
|
52
|
+
scope?: string;
|
|
53
|
+
}) => Promise<OAuthGrantTarget[]>;
|
|
54
|
+
/**
|
|
55
|
+
* End whatever session {@link OAuthAdapters.identify} was reading, so the person can connect as somebody else.
|
|
56
|
+
*
|
|
57
|
+
* Optional, and its absence is what takes the offer off the grant screen: a deployment that cannot end a session
|
|
58
|
+
* from here should not show a button that pretends to. Clear the cookies on `res` and revoke at the source —
|
|
59
|
+
* forgetting the cookie alone leaves the credential working for anyone who already copied it.
|
|
60
|
+
*
|
|
61
|
+
* Whoever reaches that screen arrived from another application, so this is the only way out of the wrong account
|
|
62
|
+
* that does not mean abandoning the connection and starting over from the host.
|
|
63
|
+
*/
|
|
64
|
+
signOut?: (req: SSRRequest, res: SSRResponseHelpers) => void | Promise<void>;
|
|
65
|
+
/** Mint the bearer the client will send on every request. Return undefined to deny the grant. */
|
|
66
|
+
issueToken: (user: OAuthUser, target: OAuthGrantTarget, context: OAuthIssueContext) => Promise<{
|
|
67
|
+
token: string;
|
|
68
|
+
expiresInSeconds?: number;
|
|
69
|
+
} | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* End a credential {@link OAuthAdapters.issueToken} minted, when its grant is revoked (RFC 7009).
|
|
72
|
+
*
|
|
73
|
+
* Optional, for a credential that ends on its own. Without it, revoking a grant stops it being RENEWED, and what
|
|
74
|
+
* was already issued keeps working until it expires — which a person who just signed a device out reads as the
|
|
75
|
+
* sign-out not having happened, because the device is still there in their list.
|
|
76
|
+
*/
|
|
77
|
+
revokeToken?: (credential: string) => Promise<void>;
|
|
78
|
+
store: OAuthStore;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Who a credential is being issued to, beyond the person: which application, from where, and — on a renewal — which
|
|
82
|
+
* credential it takes the place of.
|
|
83
|
+
*
|
|
84
|
+
* This is what lets a deployment tell its user WHICH of their devices a credential lives on. The application names
|
|
85
|
+
* itself when it registers (RFC 7591 `client_name`, `software_id`); the request is the one the credential is being
|
|
86
|
+
* issued on — at consent, the person's browser, which for a loopback client is the same machine.
|
|
87
|
+
*/
|
|
88
|
+
export type OAuthIssueContext = {
|
|
89
|
+
client: {
|
|
90
|
+
clientId: string;
|
|
91
|
+
/** What the application registered as: `Plitzi CLI on dev-laptop`, `Claude`. */
|
|
92
|
+
name: string;
|
|
93
|
+
/** RFC 7591 `software_id`, when it sent one: a stable name for the SOFTWARE, the same on every machine. */
|
|
94
|
+
softwareId?: string;
|
|
95
|
+
};
|
|
96
|
+
request?: {
|
|
97
|
+
userAgent?: string;
|
|
98
|
+
ip?: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Where the code of THIS grant is sent: the `redirect_uri` of the authorization request, at consent. A deployment
|
|
102
|
+
* whose credential is only good at certain addresses checks it here — registering a client is open to anybody, and
|
|
103
|
+
* the address it names is the one thing that says who will receive what the person agreed to. Absent on a renewal.
|
|
104
|
+
*/
|
|
105
|
+
redirectUri?: string;
|
|
106
|
+
/**
|
|
107
|
+
* The credential this grant last issued, on a renewal. A deployment that keeps a row per credential updates that
|
|
108
|
+
* row rather than adding one, so a device renewing every hour stays one device.
|
|
109
|
+
*/
|
|
110
|
+
replaces?: string;
|
|
111
|
+
};
|
|
112
|
+
/** A connection a visitor may take WITHOUT signing in, for a server whose public surface needs no identity — the
|
|
113
|
+
* MCP App, the tool and resource listings, the guide. The consent screen offers it as a second button beside the
|
|
114
|
+
* sign-in, and the grant is whatever `target` grants: point it at a target that carries no space, never at one
|
|
115
|
+
* that does, since nobody proved who they are. */
|
|
116
|
+
export type OAuthGuestConfig = {
|
|
117
|
+
/** Handed straight to {@link OAuthAdapters.issueToken} when a visitor takes the guest connection. */
|
|
118
|
+
target: OAuthGrantTarget;
|
|
119
|
+
/** Button text. Defaults to 'Continue without an account'. */
|
|
120
|
+
label?: string;
|
|
121
|
+
/** Who the grant is issued as. Defaults to `{ id: 'guest', label: 'Guest' }`. */
|
|
122
|
+
user?: OAuthUser;
|
|
123
|
+
};
|
|
124
|
+
/** What the grant screen shows around the form. */
|
|
125
|
+
export type OAuthBranding = {
|
|
126
|
+
/** Shown as the heading, e.g. 'Plitzi'. Defaults to 'Plitzi'. */
|
|
127
|
+
productName?: string;
|
|
128
|
+
/** Absolute or same-origin URL of a logo to show above the heading. */
|
|
129
|
+
logoUrl?: string;
|
|
130
|
+
/** Extra CSS appended to the page's own, for a deployment that wants its own look without replacing the page. */
|
|
131
|
+
css?: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Everything the GRANT screen needs to render itself.
|
|
135
|
+
*
|
|
136
|
+
* One screen, and deliberately only one: this server asks what to connect, never who somebody is. Signing in
|
|
137
|
+
* happens on {@link OAuthConfig.signInUrl}, wherever the deployment keeps it.
|
|
138
|
+
*/
|
|
139
|
+
export type OAuthConsentView = {
|
|
140
|
+
/** Where the form must POST to (the authorize endpoint). */
|
|
141
|
+
action: string;
|
|
142
|
+
/** Hidden fields the form MUST round-trip verbatim, or the flow cannot be resumed. */
|
|
143
|
+
hidden: Record<string, string>;
|
|
144
|
+
/** What this account may grant. Empty for a visitor who has not signed in, who is offered `guest` instead. */
|
|
145
|
+
targets: OAuthGrantTarget[];
|
|
146
|
+
/**
|
|
147
|
+
* Offered when the deployment allows a guest connection. The form submits a `guest` field for it (any non-empty
|
|
148
|
+
* value), which is what tells the server to grant the guest target rather than a chosen one.
|
|
149
|
+
*
|
|
150
|
+
* It is the reason an unidentified visitor is shown this screen at all rather than being sent straight to
|
|
151
|
+
* sign-in: a guest has no session and never will, so a redirect they cannot come back from would take the
|
|
152
|
+
* option away entirely.
|
|
153
|
+
*/
|
|
154
|
+
guest?: {
|
|
155
|
+
label: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
};
|
|
158
|
+
/** Who is signed in. Absent for a visitor taking the guest connection. */
|
|
159
|
+
user?: OAuthUser;
|
|
160
|
+
/** Where to send somebody who wants to sign in first. Shown when `user` is absent. */
|
|
161
|
+
signInUrl?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Whether to offer "use another account" — shown only when the deployment can act on it, which means it supplied
|
|
164
|
+
* {@link OAuthAdapters.signOut}.
|
|
165
|
+
*
|
|
166
|
+
* A submit BUTTON in the same form rather than a link, and that is not decoration. Ending a session is a state
|
|
167
|
+
* change, so it may not hang off a URL anything can navigate to: a `<img src>` on any page on the internet would
|
|
168
|
+
* then be able to sign a visitor out. Posting it here keeps it a same-origin form submission carrying the request
|
|
169
|
+
* back, exactly like granting does.
|
|
170
|
+
*/
|
|
171
|
+
canSwitchUser?: boolean;
|
|
172
|
+
/** A message to show the user. */
|
|
173
|
+
error?: string;
|
|
174
|
+
/**
|
|
175
|
+
* Who is asking, and where the grant goes if the person says yes.
|
|
176
|
+
*
|
|
177
|
+
* Anybody can register a client, call it anything and send somebody this screen on the deployment's own domain, so
|
|
178
|
+
* the name alone proves nothing. The host the code is sent back to is the one fact the requester cannot choose
|
|
179
|
+
* freely, and it is what tells "the app I just opened" apart from a stranger's server.
|
|
180
|
+
*/
|
|
181
|
+
client: {
|
|
182
|
+
/** What the client registered itself as. Chosen by the client, so it is shown as a claim. */
|
|
183
|
+
name: string;
|
|
184
|
+
/** The host of the `redirect_uri` the grant is delivered to. */
|
|
185
|
+
redirectHost: string;
|
|
186
|
+
/** The grant goes back to an app listening on this computer (RFC 8252 loopback), not to a server. */
|
|
187
|
+
loopback: boolean;
|
|
188
|
+
};
|
|
189
|
+
branding: OAuthBranding;
|
|
190
|
+
};
|
|
191
|
+
/** OAuth 2.1 authorization for the MCP server (RFC 9728 discovery + RFC 7591 dynamic client registration +
|
|
192
|
+
* authorization code with PKCE). ENTIRELY OPTIONAL: without this config no endpoint is mounted, discovery keeps
|
|
193
|
+
* answering 404 and the server stays anonymous, which is a working setup — the public surface (handshake, tool
|
|
194
|
+
* and resource listing, the guide, plitzi_render) never needed a token. Configure it only to let a remote host
|
|
195
|
+
* that cannot send custom headers — Claude Desktop, ChatGPT — obtain a space-scoped one.
|
|
196
|
+
*
|
|
197
|
+
* Configuring it also protects the MCP endpoint: a JSON-RPC call that presents no verifiable bearer is answered
|
|
198
|
+
* with RFC 6750's 401 challenge rather than the anonymous surface, because that 401 is the only thing a host runs
|
|
199
|
+
* its flow off — it ignores a `WWW-Authenticate` header on a 200, and a server that never sends one is treated as
|
|
200
|
+
* needing no authorization at all, leaving a completed grant with nowhere to attach. Offer a grant target that
|
|
201
|
+
* carries no space ({@link OAuthGrantTarget}) so the public surface stays one consent away. */
|
|
202
|
+
export type OAuthConfig = {
|
|
203
|
+
adapters: OAuthAdapters;
|
|
204
|
+
/** The issuer/resource identifier published in the metadata documents. Defaults to the origin the request came
|
|
205
|
+
* in on, which is correct whenever the server owns its sub-domain; set it when a proxy rewrites the host. */
|
|
206
|
+
issuer?: string;
|
|
207
|
+
/** Scope names advertised and echoed back on the token. Defaults to ['plitzi']. */
|
|
208
|
+
scopes?: string[];
|
|
209
|
+
/** How long an authorization code stays redeemable, in seconds. Default 60 — codes are one-shot and redeemed
|
|
210
|
+
* immediately. */
|
|
211
|
+
codeTtlSeconds?: number;
|
|
212
|
+
/** How long a refresh grant lives, in seconds. Default 30 days. Set 0 to issue no refresh tokens. */
|
|
213
|
+
refreshTtlSeconds?: number;
|
|
214
|
+
/** Offer a connection that needs no account — see {@link OAuthGuestConfig}. Omit to require sign-in. */
|
|
215
|
+
guest?: OAuthGuestConfig;
|
|
216
|
+
branding?: OAuthBranding;
|
|
217
|
+
/**
|
|
218
|
+
* The sign-in screen this server sends unidentified visitors to.
|
|
219
|
+
*
|
|
220
|
+
* The whole authorization request rides along as a `redirect` query param, so signing in is an ordinary
|
|
221
|
+
* navigation that lands back on the `/authorize` it left — this server keeps no session of its own for a flow
|
|
222
|
+
* that is one page long.
|
|
223
|
+
*
|
|
224
|
+
* Required, because {@link OAuthAdapters.identify} is: a server that does not check passwords and has nowhere
|
|
225
|
+
* to send somebody who has not signed in cannot start the flow at all.
|
|
226
|
+
*/
|
|
227
|
+
signInUrl: string;
|
|
228
|
+
/**
|
|
229
|
+
* Hand the client the credential `issueToken` minted, instead of an opaque handle to it.
|
|
230
|
+
*
|
|
231
|
+
* Off by default, which is right whenever the credential is worth more than the connection — a space token
|
|
232
|
+
* reaches the platform, and a client that never holds one cannot leak one. Turn it ON when the credential IS
|
|
233
|
+
* what the client should hold: a native app granted the person's own session is holding exactly what a browser
|
|
234
|
+
* holds, and wrapping it costs a store read on every request and gives a second thing to revoke.
|
|
235
|
+
*/
|
|
236
|
+
directTokens?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Accept only loopback `redirect_uri`s (`http://127.0.0.1:<port>/…`, RFC 8252 §7.3), at registration and again at
|
|
239
|
+
* `/authorize`.
|
|
240
|
+
*
|
|
241
|
+
* Turn it on when every client is a native app on the person's own machine — a CLI, a desktop app — and above all
|
|
242
|
+
* with {@link directTokens}, where the grant IS the person's session. Registration is open to anybody, so with https
|
|
243
|
+
* redirects allowed a stranger's server can register, send somebody the link, and collect what they approve.
|
|
244
|
+
*/
|
|
245
|
+
loopbackRedirectsOnly?: boolean;
|
|
246
|
+
};
|