@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,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password hashing that a deployment does not have to choose, and by default does not even have to know about:
|
|
3
|
+
* this is what `createAuthApi` uses when nobody says otherwise.
|
|
4
|
+
*
|
|
5
|
+
* `scrypt` from the standard library, so this costs no dependency and nothing has to be compiled. It is a memory-hard
|
|
6
|
+
* KDF and an entirely respectable answer; argon2 or bcrypt are better ones, and a deployment that wants either passes
|
|
7
|
+
* its own `verifyPassword`/`hashPassword` to `createAuth` — nothing here assumes an algorithm.
|
|
8
|
+
*
|
|
9
|
+
* The format is `scrypt$<salt>$<hash>`, tagged so a later change of algorithm can recognise what it is looking at
|
|
10
|
+
* instead of guessing from the shape.
|
|
11
|
+
*/
|
|
12
|
+
export declare const hashPassword: (plain: string) => Promise<string>;
|
|
13
|
+
export declare const verifyPassword: (plain: string, stored: string) => Promise<boolean>;
|
|
14
|
+
/** Opaque single-use strings, for validation and password-reset links. */
|
|
15
|
+
export declare const generateToken: () => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SSRRequest } from '../types';
|
|
2
|
+
export declare const PREVIEW_TOKEN_PARAM = "__pt";
|
|
3
|
+
/**
|
|
4
|
+
* Where a REUSABLE draft token is remembered for the rest of the visit.
|
|
5
|
+
*
|
|
6
|
+
* The query param alone previews one URL, which is all a screenshot ever needed. A person iterating does more than
|
|
7
|
+
* look at one URL: they follow a link, the SDK asks `/_rsc` for fresh data, they press back. Every one of those is a
|
|
8
|
+
* request without the param, and answering the saved space to a browser that is looking at a draft is the kind of
|
|
9
|
+
* confusion that gets reported as "the preview randomly reverts".
|
|
10
|
+
*
|
|
11
|
+
* `HttpOnly` because nothing in the page has any use for it, and `SameSite=Lax` so another site cannot cause a draft
|
|
12
|
+
* to be resolved in a visitor's browser. It is set only for a token the store minted as reusable.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PREVIEW_COOKIE = "plitzi_draft";
|
|
15
|
+
/**
|
|
16
|
+
* The draft this request is looking at, whichever way it says so.
|
|
17
|
+
*
|
|
18
|
+
* The query param wins: it is how a session is STARTED, and re-minting while an older one is still in the cookie has
|
|
19
|
+
* to answer the new draft or the loop shows stale work.
|
|
20
|
+
*/
|
|
21
|
+
export declare const readDraftToken: (req: SSRRequest) => string | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SSRRequest, SSRResponseHelpers } from '../types';
|
|
2
|
+
import { SSRUser } from '@plitzi/sdk-shared';
|
|
3
|
+
/**
|
|
4
|
+
* Who a request is, as every server that serves a space asks it (RFC 0032, §11 Q6): one object, so a page server and a
|
|
5
|
+
* worker are configured with the same answer. `createAuth` makes one (`ssrIdentityAdapters`); a deployment with its own
|
|
6
|
+
* accounts writes its own. Absent, every request is a guest's.
|
|
7
|
+
*/
|
|
8
|
+
export type RequestIdentity = {
|
|
9
|
+
/**
|
|
10
|
+
* The person a request carries a live session for, with the roles and permissions it was granted; else nobody. With
|
|
11
|
+
* `res`, a session cookie found over for good is cleared on it (`SSRAdapters.getUser`).
|
|
12
|
+
*/
|
|
13
|
+
getUser: (req: SSRRequest, res?: SSRResponseHelpers) => Promise<SSRUser | undefined>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every credential this server mints is a JWT built from REGISTERED claims (RFC 7519) plus `scope` (RFC 6749). There
|
|
3
|
+
* are no bespoke `typ`/`data`/`version` claims: anyone who has read a JWT before can read one of these.
|
|
4
|
+
*
|
|
5
|
+
* iss which deployment minted it — the environment boundary
|
|
6
|
+
* sub who or what it is about: a user id, or a space id
|
|
7
|
+
* aud the API audiences it is meant for
|
|
8
|
+
* scope what it is and what it may do (below)
|
|
9
|
+
* exp / iat / nbf / jti lifetime and identity, as usual
|
|
10
|
+
*
|
|
11
|
+
* The one custom claim is `origins`, because JWT registers nothing for "the web origins this credential may be
|
|
12
|
+
* presented from" — it is what binds a public render token to its domains.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SCOPES: {
|
|
15
|
+
readonly user: "user";
|
|
16
|
+
readonly refresh: "refresh";
|
|
17
|
+
readonly widget: "widget";
|
|
18
|
+
readonly spaceRender: "space:render";
|
|
19
|
+
readonly spaceAgent: "space:agent";
|
|
20
|
+
/**
|
|
21
|
+
* A SERVER that renders this space as its own — self-hosting. Secret by construction, which is the whole reason it
|
|
22
|
+
* exists apart from `space:render`: see {@link SpaceScope}.
|
|
23
|
+
*/
|
|
24
|
+
readonly spaceHost: "space:host";
|
|
25
|
+
/** A sign-in that got the password right and still owes a second factor. Carries no authority of its own. */
|
|
26
|
+
readonly mfa: "mfa";
|
|
27
|
+
};
|
|
28
|
+
export type TokenScope = (typeof SCOPES)[keyof typeof SCOPES];
|
|
29
|
+
/**
|
|
30
|
+
* What a space credential IS, and the distinction the other two are defined against.
|
|
31
|
+
*
|
|
32
|
+
* `render` is **public**: it ships in the clear inside every published page, so anybody who views source has it. The
|
|
33
|
+
* only thing that keeps a copied one from working is that a browser is made to state where it is presenting from and
|
|
34
|
+
* that statement is checked — a control that exists solely because browsers enforce it, and that means nothing to a
|
|
35
|
+
* client which simply does not send the header.
|
|
36
|
+
*
|
|
37
|
+
* `host` is that same read access for a server, and it is **secret**: shown once when it is issued, never embedded in
|
|
38
|
+
* a page, held only by the deployment operator. Self-hosting needs a credential that survives having no Origin to
|
|
39
|
+
* check, and a public one cannot be it — a render key lifted from someone else's page would otherwise be enough to
|
|
40
|
+
* serve a byte-identical clone of their site from anywhere.
|
|
41
|
+
*
|
|
42
|
+
* `agent` writes, on behalf of the member who consented.
|
|
43
|
+
*/
|
|
44
|
+
export type SpaceScope = 'render' | 'agent' | 'host';
|
|
45
|
+
/** The scopes that are safe to present with no `Origin` header, because they are not public to begin with. */
|
|
46
|
+
export declare const OFF_BROWSER_SPACE_SCOPES: readonly SpaceScope[];
|
|
47
|
+
/** Why a credential was refused. A reason rather than a status, because each transport maps it onto its own. */
|
|
48
|
+
export type AuthFailure = 'missing' | 'malformed' | 'expired' | 'outdated' | 'revoked' | 'wrong-type' | 'scope-mismatch' | 'issuer-not-allowed' | 'origin-not-allowed' | 'domain-not-allowed' | 'inactive'
|
|
49
|
+
/**
|
|
50
|
+
* The password was right and the address has never answered. Separate from `inactive` because it is the one
|
|
51
|
+
* refusal whose owner can clear it themselves, and a screen that cannot tell them apart has to guess.
|
|
52
|
+
*/
|
|
53
|
+
| 'unverified'
|
|
54
|
+
/** The password was right, and the account's organization signs it in through its own single sign-on instead. */
|
|
55
|
+
| 'sso-required';
|
|
56
|
+
export declare const authFailureMessage: Record<AuthFailure, string>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { SSRAuthCookie, SSRRequest, SSRSession, SSRSpaceDeployment } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Anything that can carry `Set-Cookie`. Express `Response` and this server's own helpers both satisfy it, which is
|
|
4
|
+
* what lets one writer serve both — a deployment that wrote its own would drift from the one SSR uses, and a session
|
|
5
|
+
* established on one side would be invisible to the other.
|
|
6
|
+
*/
|
|
7
|
+
export interface CookieSink {
|
|
8
|
+
setHeader: (name: string, value: string | string[]) => void;
|
|
9
|
+
getHeader?: (name: string) => string | string[] | number | undefined;
|
|
10
|
+
headers?: Record<string, string | string[] | number | undefined>;
|
|
11
|
+
}
|
|
12
|
+
export type SessionCookieParams = {
|
|
13
|
+
name: string;
|
|
14
|
+
domain?: string;
|
|
15
|
+
secure: boolean;
|
|
16
|
+
sameSite: 'lax' | 'none';
|
|
17
|
+
refreshPath: string;
|
|
18
|
+
hintSuffix: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Whether the host is a loopback name or a `.localhost` sibling. Local hosts get no Domain on their cookies (browsers
|
|
22
|
+
* refuse one on a single-label host) and no Secure over plain http.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isLocalHost: (hostname: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether the host is this machine as another device on its network reaches it: a private address, or the name
|
|
27
|
+
* mDNS gives it (`studio.local` — one label before `.local`, so a deployment's own `app.example.local` sub-domains,
|
|
28
|
+
* which share cookies across siblings over https, are not taken for one). Such a server is opened over plain http
|
|
29
|
+
* from a tablet, and gets the local cookie profile: a Secure cookie written over http is dropped.
|
|
30
|
+
*/
|
|
31
|
+
export declare const isPrivateNetworkHost: (hostname: string) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* The last two labels of the host, so a session established on one sub-domain is carried by its siblings — an app
|
|
34
|
+
* and the API it talks to are rarely the same host. Local and IP hosts get no domain at all: browsers refuse a
|
|
35
|
+
* Domain on a single-label host, and one written for an address would never be sent back to it.
|
|
36
|
+
*
|
|
37
|
+
* A domain whose sub-domains belong to different people — the one a deployment serves its spaces on, like
|
|
38
|
+
* `*.plitzi.app` — is not one to share a cookie across: a session of one space's visitor would reach every other's.
|
|
39
|
+
* Such a deployment says so with `authCookie.domain`, answering this for its own hosts and nothing for the rest.
|
|
40
|
+
*/
|
|
41
|
+
export declare const registrableDomain: (hostname: string) => string | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The request a cookie is written for: its host and, on a page server once it is known, the deployment the host
|
|
44
|
+
* resolved to (`req.ctx.spaceDeployment`).
|
|
45
|
+
*/
|
|
46
|
+
export type CookieRequest = {
|
|
47
|
+
hostname: string;
|
|
48
|
+
ctx?: {
|
|
49
|
+
spaceDeployment?: Pick<SSRSpaceDeployment, 'security'>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Everything about how a session cookie is written, derived from the request host unless the deployment says
|
|
54
|
+
* otherwise. The defaults are the ones a server on a real domain needs: a cookie shared across sub-domains — an app and
|
|
55
|
+
* the API it talks to are rarely the same host — Secure, and `SameSite=Lax`. Sub-domains of one site are the same site,
|
|
56
|
+
* so `Lax` reaches all of them; what it keeps the cookie from is a request another site's page makes, which carried it
|
|
57
|
+
* as a third-party cookie (Lighthouse: "Uses third-party cookies"), to the API and to every other host of the domain,
|
|
58
|
+
* a CDN's included. A deployment whose pages need the session inside another site's page — a space in an iframe there,
|
|
59
|
+
* an app on another site than its API — says `sameSite: 'none'`; a domain that lets other sites frame its pages
|
|
60
|
+
* (`security.frameAncestors` of its deployment) gets it on that host alone. A local server — this machine, or this machine as its
|
|
61
|
+
* network reaches it — is not Secure, which plain http would drop.
|
|
62
|
+
*/
|
|
63
|
+
export declare const sessionCookieParams: (req: CookieRequest, config?: SSRAuthCookie) => SessionCookieParams;
|
|
64
|
+
/** The readable companion cookie's name — the one a page is told to look for (`server.auth.sessionHintCookie`). */
|
|
65
|
+
export declare const sessionHintCookieName: (params: SessionCookieParams) => string;
|
|
66
|
+
/**
|
|
67
|
+
* The value of the readable companion cookie: `<access expiry>.<refresh expiry>`, unix seconds, refresh optional.
|
|
68
|
+
*
|
|
69
|
+
* It exists because the session cookie is httpOnly — correctly — which leaves a page unable to tell whether the
|
|
70
|
+
* browser holds a session at all. Answering that costs a request per page load otherwise, and the answer is usually
|
|
71
|
+
* "nobody is signed in". This carries no credential: any script that can read it could have asked the backend the
|
|
72
|
+
* same question with `credentials: 'include'`.
|
|
73
|
+
*/
|
|
74
|
+
export declare const sessionHintValue: (expiresAt: number, refreshExpiresAt?: number) => string;
|
|
75
|
+
export type SessionHint = {
|
|
76
|
+
/** Unix seconds the access credential dies at. */
|
|
77
|
+
expiresAt: number;
|
|
78
|
+
/** Unix seconds renewal stops being possible at, when the session has a refresh half. */
|
|
79
|
+
refreshExpiresAt?: number;
|
|
80
|
+
};
|
|
81
|
+
/** {@link sessionHintValue} read back — the same reading `@plitzi/sdk-auth` gives it in the browser. */
|
|
82
|
+
export declare const parseSessionHint: (value: string | undefined) => SessionHint | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Adds to `Set-Cookie` rather than replacing it. A handler may already have written one — clearing an OAuth flow
|
|
85
|
+
* before granting the session it produced is exactly that — and replacing the header would silently drop it.
|
|
86
|
+
*/
|
|
87
|
+
export declare const appendCookies: (res: CookieSink, cookies: string[]) => void;
|
|
88
|
+
/**
|
|
89
|
+
* Writes a granted session onto the response: the credential itself, the refresh half confined to its own path, and
|
|
90
|
+
* the readable hint. One call, because the three only make sense together — a hint that outlives its session sends
|
|
91
|
+
* clients to renew something that is gone, and one that dies early signs out a live session.
|
|
92
|
+
*/
|
|
93
|
+
export declare const writeSessionCookies: (req: CookieRequest, res: CookieSink, session: SSRSession, config?: SSRAuthCookie) => void;
|
|
94
|
+
/** Ends the session in this browser. Every cookie the grant wrote is cleared, the readable one included. */
|
|
95
|
+
export declare const clearSessionCookies: (req: CookieRequest, res: CookieSink, config?: SSRAuthCookie) => void;
|
|
96
|
+
/**
|
|
97
|
+
* The cookie a social sign-in leaves behind while the browser is away at the provider. Same family, same policy, so
|
|
98
|
+
* it is written here rather than by whoever happens to be driving the flow. Path `/` because a deployment may serve
|
|
99
|
+
* its API under a prefix, and the callback would then miss a cookie scoped to `/auth`.
|
|
100
|
+
*/
|
|
101
|
+
export declare const writeFlowCookie: (req: CookieRequest, res: CookieSink, value: string, ttlSeconds: number, config?: SSRAuthCookie) => void;
|
|
102
|
+
export declare const clearFlowCookie: (req: CookieRequest, res: CookieSink, config?: SSRAuthCookie) => void;
|
|
103
|
+
/** The value that flow cookie carries, for the callback leg. */
|
|
104
|
+
export declare const readFlowCookie: (req: SSRRequest | (CookieRequest & {
|
|
105
|
+
headers: {
|
|
106
|
+
cookie?: string;
|
|
107
|
+
};
|
|
108
|
+
}), config?: SSRAuthCookie) => string | undefined;
|
|
109
|
+
/** The session credential this request carries, for an adapter that resolves identity from it. */
|
|
110
|
+
export declare const readSessionToken: (req: SSRRequest | (CookieRequest & {
|
|
111
|
+
headers: {
|
|
112
|
+
cookie?: string;
|
|
113
|
+
};
|
|
114
|
+
}), config?: SSRAuthCookie) => string | undefined;
|
|
115
|
+
/** The renewal credential, which rides in its own cookie confined to the refresh path. */
|
|
116
|
+
export declare const readRefreshToken: (req: SSRRequest | (CookieRequest & {
|
|
117
|
+
headers: {
|
|
118
|
+
cookie?: string;
|
|
119
|
+
};
|
|
120
|
+
}), config?: SSRAuthCookie) => string | undefined;
|
|
121
|
+
/** What the readable companion cookie says about this browser's session, without presenting any credential. */
|
|
122
|
+
export declare const readSessionHint: (req: SSRRequest | (CookieRequest & {
|
|
123
|
+
headers: {
|
|
124
|
+
cookie?: string;
|
|
125
|
+
};
|
|
126
|
+
}), config?: SSRAuthCookie) => SessionHint | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* How long a page server holds off sending a browser to renew again. Long enough to cover the round trip there and
|
|
129
|
+
* back, short enough that a renewal which failed for a passing reason is retried on a later visit.
|
|
130
|
+
*/
|
|
131
|
+
export declare const RENEWAL_GUARD_SECONDS = 30;
|
|
132
|
+
/**
|
|
133
|
+
* Marks a browser as having just been sent to renew its session, so the page it comes back to is rendered rather
|
|
134
|
+
* than bounced again. Every renewal that can fail without ending the session — the refresh cookie not reaching the
|
|
135
|
+
* endpoint, the store being down — would otherwise send the visitor round in a loop.
|
|
136
|
+
*/
|
|
137
|
+
export declare const writeRenewalGuard: (req: CookieRequest, res: CookieSink, config?: SSRAuthCookie) => void;
|
|
138
|
+
/**
|
|
139
|
+
* Where a renewal sends the browser back to: a path on this host, or a page on any host this session's cookies are
|
|
140
|
+
* scoped to — the only hosts that could have sent a browser here to renew, since the hint that triggers it rides on
|
|
141
|
+
* the same cookie domain. Anything else is an open redirect, and goes to `/` instead.
|
|
142
|
+
*/
|
|
143
|
+
export declare const sessionReturnTarget: (req: CookieRequest, target: unknown, config?: SSRAuthCookie) => string;
|
|
144
|
+
export declare const readRenewalGuard: (req: SSRRequest | (CookieRequest & {
|
|
145
|
+
headers: {
|
|
146
|
+
cookie?: string;
|
|
147
|
+
};
|
|
148
|
+
}), config?: SSRAuthCookie) => boolean;
|
|
149
|
+
/** Anything a credential can be read off: this server's own request, an Express one, a bare `node:http` one. */
|
|
150
|
+
export type CookieCarrier = SSRRequest | {
|
|
151
|
+
headers: {
|
|
152
|
+
cookie?: string;
|
|
153
|
+
authorization?: string;
|
|
154
|
+
};
|
|
155
|
+
hostname: string;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* The cookie side of a session with this deployment's naming already bound in.
|
|
159
|
+
*
|
|
160
|
+
* The functions above take the naming on every call, which is right for the server's own internals and tedious for a
|
|
161
|
+
* host that answers dozens of requests with the same configuration. Nothing here knows about any framework: it takes
|
|
162
|
+
* a request that can be read and something that can carry `Set-Cookie`, which is as true of `node:http` as it is of
|
|
163
|
+
* Express — a self-hoster running neither still gets the whole cycle.
|
|
164
|
+
*/
|
|
165
|
+
export declare const createSessionCookies: (config?: SSRAuthCookie) => {
|
|
166
|
+
write: (req: CookieRequest, res: CookieSink, session: SSRSession) => void;
|
|
167
|
+
clear: (req: CookieRequest, res: CookieSink) => void;
|
|
168
|
+
/** Holds a social sign-in between its two legs: the CSRF nonce and the PKCE verifier. */
|
|
169
|
+
writeFlow: (req: CookieRequest, res: CookieSink, value: string, ttlSeconds: number) => void;
|
|
170
|
+
clearFlow: (req: CookieRequest, res: CookieSink) => void;
|
|
171
|
+
readFlow: (req: CookieCarrier) => string | undefined;
|
|
172
|
+
returnTarget: (req: CookieRequest, target: unknown) => string;
|
|
173
|
+
/**
|
|
174
|
+
* The session credential from `Authorization: Bearer` or the cookie, so one endpoint serves a bearer client and a
|
|
175
|
+
* browser. The header wins: a caller that went to the trouble of presenting one means it.
|
|
176
|
+
*/
|
|
177
|
+
resolveSessionToken: (req: CookieCarrier) => string | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* The renewal credential from the request body (`refresh_token`, for API clients) or its cookie (for browsers).
|
|
180
|
+
* The body wins when both are present, mirroring how the session credential is resolved. `body` is whatever the
|
|
181
|
+
* host parsed — this only reads one field off it, so a host that parses JSON its own way still fits.
|
|
182
|
+
*/
|
|
183
|
+
resolveRefreshToken: (req: CookieCarrier, body?: unknown) => string | undefined;
|
|
184
|
+
};
|
|
185
|
+
export type SessionCookies = ReturnType<typeof createSessionCookies>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When a session was last used, to the resolution a device list needs.
|
|
3
|
+
*
|
|
4
|
+
* "Active 3 minutes ago" against "active last March" is what tells somebody which of their devices is the one they do
|
|
5
|
+
* not recognise — and the time a session was CREATED says neither: a laptop signed in a month ago and used this morning
|
|
6
|
+
* reads as a month-old session. Recording every request would be a write per request on the hottest read in the
|
|
7
|
+
* system, so a store records it at most once per this many seconds, on the lookup it already makes.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SESSION_ACTIVITY_RESOLUTION_SECONDS = 300;
|
|
10
|
+
/** Whether a session last seen at `lastActiveAt` (unix seconds, absent when never) is due a new record at `now`. */
|
|
11
|
+
export declare const activityDue: (lastActiveAt: number | null | undefined, now: number) => boolean;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { SpaceScope } from './scopes';
|
|
2
|
+
import { Tokens } from '../tokens/tokens';
|
|
3
|
+
/**
|
|
4
|
+
* A stored space credential, as whatever stores them reports one. `origins` is already parsed: how a deployment keeps
|
|
5
|
+
* the list (a joined column, a join table, a JSON blob) is its business and never leaks into the rules below.
|
|
6
|
+
*/
|
|
7
|
+
export interface SpaceTokenRecord {
|
|
8
|
+
id: number;
|
|
9
|
+
token: string;
|
|
10
|
+
scope: SpaceScope;
|
|
11
|
+
/** The space's public credential — the one published sites embed. Exactly one row per space carries this. */
|
|
12
|
+
isDefault: boolean;
|
|
13
|
+
origins: string[];
|
|
14
|
+
/** Unix seconds, or null for a credential that never expires. */
|
|
15
|
+
expiresAt: number | null;
|
|
16
|
+
userId?: number | null;
|
|
17
|
+
createdAt?: number;
|
|
18
|
+
updatedAt?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface SpaceTokenAdapters {
|
|
21
|
+
loadDefault: (spaceId: number) => Promise<SpaceTokenRecord | undefined>;
|
|
22
|
+
find: (spaceId: number, tokenId: number) => Promise<SpaceTokenRecord | undefined>;
|
|
23
|
+
list: (spaceId: number) => Promise<SpaceTokenRecord[]>;
|
|
24
|
+
save: (id: number, values: {
|
|
25
|
+
token: string;
|
|
26
|
+
origins?: string[];
|
|
27
|
+
expiresAt?: number | null;
|
|
28
|
+
}) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Store a NEW credential beside the space's public one. Only the secret scopes are ever created this way — the
|
|
31
|
+
* public row is created with the space and rotated in place thereafter — so a deployment that issues none may
|
|
32
|
+
* leave it out and `issueHost` refuses.
|
|
33
|
+
*/
|
|
34
|
+
create?: (values: {
|
|
35
|
+
spaceId: number;
|
|
36
|
+
token: string;
|
|
37
|
+
scope: SpaceScope;
|
|
38
|
+
origins: string[];
|
|
39
|
+
expiresAt: number | null;
|
|
40
|
+
}) => Promise<SpaceTokenRecord>;
|
|
41
|
+
remove: (id: number) => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* The domain list is two policies at once — where the credential may be presented, and who may frame the space — so
|
|
44
|
+
* a deployment that caches either gets told the moment it changes, rather than serving the old one until its TTL.
|
|
45
|
+
*/
|
|
46
|
+
onDomainsChanged?: (spaceId: number) => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The floor a space is always reachable on: the platform-owned domain it is published under. Merged into every list so
|
|
50
|
+
* narrowing the domains to a custom one cannot lock a published site out of its own credential. Which domains those
|
|
51
|
+
* are is the deployment's to say — the rule that they are never dropped is not.
|
|
52
|
+
*/
|
|
53
|
+
export interface SpaceTokenContext {
|
|
54
|
+
spaceId: number;
|
|
55
|
+
defaultDomains: string[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* What a handler answers. The success body is typed per handler so a binding can reshape it — Plitzi's `GET /token`
|
|
59
|
+
* serves the bare credential for compatibility with its own older API — without casting its way back to it.
|
|
60
|
+
*/
|
|
61
|
+
export type SpaceTokenOutcome<B extends object = object> = {
|
|
62
|
+
ok: true;
|
|
63
|
+
status?: number;
|
|
64
|
+
body: B;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
status: number;
|
|
68
|
+
body: {
|
|
69
|
+
error: string;
|
|
70
|
+
} & Record<string, unknown>;
|
|
71
|
+
};
|
|
72
|
+
export type SpaceTokenSummary = Omit<SpaceTokenRecord, 'token' | 'origins'> & {
|
|
73
|
+
domains?: string[];
|
|
74
|
+
label?: string;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The lifecycle of a space's own credentials, over whatever stores them.
|
|
78
|
+
*
|
|
79
|
+
* Minting one is `tokens.generateSpaceToken`; everything around it is here, and it is all rule rather than storage:
|
|
80
|
+
* a credential whose claims changed is a **different credential**, so every edit below re-mints and the previous one
|
|
81
|
+
* stops working the instant it returns. Saying that once, in one place, is the point — a self-hoster who has to
|
|
82
|
+
* rediscover it discovers it as a published site that went dark.
|
|
83
|
+
*/
|
|
84
|
+
export declare const createSpaceTokenApi: ({ tokens, adapters }: {
|
|
85
|
+
tokens: Tokens;
|
|
86
|
+
adapters: SpaceTokenAdapters;
|
|
87
|
+
}) => {
|
|
88
|
+
/**
|
|
89
|
+
* The space's public credential, rotated in place when it no longer verifies. Rotating on *outdated* and not only
|
|
90
|
+
* on expired is what this endpoint exists for: a site stranded on a credential from a previous token version would
|
|
91
|
+
* otherwise have no way back — nothing else can hand it a working one.
|
|
92
|
+
*/
|
|
93
|
+
read(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
94
|
+
token: string;
|
|
95
|
+
domains: string[];
|
|
96
|
+
}>>;
|
|
97
|
+
/**
|
|
98
|
+
* Replace the public credential with a fresh one, keeping everything it declared. This is the control that expiry
|
|
99
|
+
* is often mistaken for: a render credential is meant to outlive any deadline, so revoking a leaked one is an act,
|
|
100
|
+
* not a wait.
|
|
101
|
+
*/
|
|
102
|
+
rotate(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
103
|
+
token: string;
|
|
104
|
+
domains: string[];
|
|
105
|
+
warning: string;
|
|
106
|
+
}>>;
|
|
107
|
+
/**
|
|
108
|
+
* Issue a **host** credential: the space's read access for a SERVER that renders it as its own.
|
|
109
|
+
*
|
|
110
|
+
* A separate credential rather than letting the public one do it, because the two are protected by different
|
|
111
|
+
* things and only one of them can be published. A `render` token is safe in a page precisely because it is held
|
|
112
|
+
* to the origins it declares — a check that only means anything when a browser is the one making the claim. A
|
|
113
|
+
* server has no origin to state, so admitting the public token without one would make a key lifted from anybody's
|
|
114
|
+
* published page enough to serve a byte-identical clone of their site. This one is admitted without an origin
|
|
115
|
+
* because possessing it is itself the proof, which is only true while it stays secret: it is returned once, never
|
|
116
|
+
* embedded, and revocable on its own row.
|
|
117
|
+
*
|
|
118
|
+
* `label` is what the owner will read in the list when deciding which one to revoke — the deployment it was
|
|
119
|
+
* issued to. It is stored where a render token keeps its domains, since a host credential is bound to none.
|
|
120
|
+
*/
|
|
121
|
+
issueHost(context: SpaceTokenContext, label: unknown, { expiresAt }?: {
|
|
122
|
+
expiresAt?: number | null;
|
|
123
|
+
}): Promise<SpaceTokenOutcome<{
|
|
124
|
+
id: number;
|
|
125
|
+
token: string;
|
|
126
|
+
label: string;
|
|
127
|
+
expiresAt: number | null;
|
|
128
|
+
warning: string;
|
|
129
|
+
}>>;
|
|
130
|
+
readDomains(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
131
|
+
domains: string[];
|
|
132
|
+
}>>;
|
|
133
|
+
setDomains(context: SpaceTokenContext, domains: unknown): Promise<SpaceTokenOutcome<{
|
|
134
|
+
token: string;
|
|
135
|
+
domains: string[];
|
|
136
|
+
warning?: string;
|
|
137
|
+
}>>;
|
|
138
|
+
readExpiry(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
139
|
+
expiresAt: number | null;
|
|
140
|
+
neverExpires: boolean;
|
|
141
|
+
}>>;
|
|
142
|
+
/**
|
|
143
|
+
* When the public credential should stop working — or never, which is the default. Both are legitimate: a site
|
|
144
|
+
* deployed once and left alone wants no deadline (an expiry there is a scheduled outage), while a campaign page
|
|
145
|
+
* meant to go quiet, or a credential handed to an agency for a fixed engagement, wants one.
|
|
146
|
+
*/
|
|
147
|
+
setExpiry(context: SpaceTokenContext, expiresInDays: unknown): Promise<SpaceTokenOutcome<{
|
|
148
|
+
token: string;
|
|
149
|
+
expiresAt: number | null;
|
|
150
|
+
neverExpires: boolean;
|
|
151
|
+
warning: string;
|
|
152
|
+
}>>;
|
|
153
|
+
/**
|
|
154
|
+
* The space's credentials, so a leak can be seen and acted on. Never the secrets themselves: an `agent` grant
|
|
155
|
+
* writes and a `host` grant serves the space from somebody else's server, so listing either would turn
|
|
156
|
+
* permission to read into a way to obtain it. The public one is published by construction and has its own
|
|
157
|
+
* endpoint.
|
|
158
|
+
*/
|
|
159
|
+
list(context: SpaceTokenContext): Promise<SpaceTokenOutcome<{
|
|
160
|
+
tokens: SpaceTokenSummary[];
|
|
161
|
+
}>>;
|
|
162
|
+
/**
|
|
163
|
+
* Revoke one credential. Dropping the record IS the revocation: every grant is looked up as it is verified, so it
|
|
164
|
+
* stops working at once whatever its claims still say.
|
|
165
|
+
*
|
|
166
|
+
* The public credential is deliberately not revocable this way — removing it leaves the published site with no
|
|
167
|
+
* credential at all, and replacing it is what a leak of that one calls for.
|
|
168
|
+
*/
|
|
169
|
+
revoke(context: SpaceTokenContext, tokenId: number): Promise<SpaceTokenOutcome<{
|
|
170
|
+
message: string;
|
|
171
|
+
tokenId: number;
|
|
172
|
+
}>>;
|
|
173
|
+
};
|
|
174
|
+
export type SpaceTokenApi = ReturnType<typeof createSpaceTokenApi>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@plitzi/sdk-kernel`: what every Plitzi server process is built on, and nothing else (RFC 0032).
|
|
3
|
+
*
|
|
4
|
+
* Its entries are its folders, each imported on its own so a process loads only what it uses:
|
|
5
|
+
*
|
|
6
|
+
* - `./http`: the server, the pipeline and its stages, health, drain, the fleet of workers, security headers
|
|
7
|
+
* - `./identity`: who a request is — session cookies, CSRF, origins; who may reach what
|
|
8
|
+
* - `./tokens`: minting and verifying tokens (it loads `jsonwebtoken`, which the rest does not)
|
|
9
|
+
* - `./deployment`: which deployment a request's host is
|
|
10
|
+
* - `./cache`: the bounded caches a server keeps
|
|
11
|
+
* - `./log`, `./outbound`, `./build`: the server's log, where a request somebody else wrote may go, esbuild
|
|
12
|
+
* - `./testing`: what the packages built on this test with
|
|
13
|
+
*
|
|
14
|
+
* The root carries the types a server is written against, and no code.
|
|
15
|
+
*/
|
|
16
|
+
export type { BaseContext, BuildContext, HttpServer, HttpServerParts, Stage } from './http';
|
|
17
|
+
export type { DeployedContext, DeploymentAdapters } from './deployment';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as isLogged, c as serverLog, i as defaultLogLevel, n as configureServerLog, o as logLevelOf, r as consoleLogger, s as renderLogEvent, t as SLOW_RUN_MS } from "../chunks/serverLog-BKaKjjc4.mjs";
|
|
2
|
+
import { a as readLogTail, i as logQueryOf, r as keepLogLine, t as LOG_TAIL_SIZE } from "../chunks/tail-D-USrZIR.mjs";
|
|
3
|
+
export { LOG_TAIL_SIZE, SLOW_RUN_MS, configureServerLog, consoleLogger, defaultLogLevel, isLogged, keepLogLine, logLevelOf, logQueryOf, readLogTail, renderLogEvent, serverLog };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LogLevel, ServerLogEvent, ServerLogger } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* From how long a run that worked is worth a line of its own, unless the deployment says (`configureServerLog`'s
|
|
4
|
+
* `slowRunMs`): below it, a run that completed is `debug` — on a busy space every schedule and every call said
|
|
5
|
+
* `completed 40ms ok`, and buried what went wrong — and at it, `warn`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SLOW_RUN_MS = 1000;
|
|
8
|
+
/** One line for any {@link ServerLogEvent}: an HTTP request reads as an access-log line
|
|
9
|
+
* (`[SSR] 203.0.113.7 GET /pricing 200 12ms ok`), the MCP events as what happened inside one
|
|
10
|
+
* (`[MCP] tools/call plitzi_apply {operations:[3]} 41ms ok`), a server action as what its flow did
|
|
11
|
+
* (`[Action] send-invoice via call space=1 completed 12ms ok`) and a refused one as what turned it away
|
|
12
|
+
* (`[Action] checkout via webhook space=1 REFUSED invalid_signature`). Rendering is a pure format — the dispatcher
|
|
13
|
+
* already stripped query values, collected no headers, cookies or tokens, summarised tool args by shape and
|
|
14
|
+
* reduced a run to its steps; the client IP it does carry is personal data, so a sink that persists these lines
|
|
15
|
+
* must say so. */
|
|
16
|
+
export declare const renderLogEvent: (event: ServerLogEvent) => string;
|
|
17
|
+
/**
|
|
18
|
+
* How severe an event is: what it says it is, or — for a request, a tool call, a run — whether it went wrong. A
|
|
19
|
+
* refusal is never `ok` yet never the server's failure: the caller was turned away, which is a `warn`. A run that
|
|
20
|
+
* worked is `debug`, unless it was slow ({@link SLOW_RUN_MS}): then `warn`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const logLevelOf: (event: ServerLogEvent) => LogLevel;
|
|
23
|
+
/** Whether a server at `threshold` says something at `level`. */
|
|
24
|
+
export declare const isLogged: (threshold: LogLevel | "silent", level: LogLevel) => boolean;
|
|
25
|
+
/** What a server says when the deployment did not choose: what went wrong in production, more while developing. */
|
|
26
|
+
export declare const defaultLogLevel: (devMode?: boolean) => LogLevel;
|
|
27
|
+
/** A drop-in `SSRServerConfig.logger` for consumers that just want the log on the console. Consumers with their
|
|
28
|
+
* own logging stack should pass their own sink instead and read the structured event. */
|
|
29
|
+
export declare const consoleLogger: ServerLogger;
|
|
30
|
+
/**
|
|
31
|
+
* The process's threshold and sink — and, with `slowRunMs`, from how long a run that worked is said as slow (a
|
|
32
|
+
* positive number of ms; {@link SLOW_RUN_MS} by default). Refused when it is not one, saying what was given.
|
|
33
|
+
*/
|
|
34
|
+
export declare const configureServerLog: (options: {
|
|
35
|
+
level: LogLevel | "silent";
|
|
36
|
+
logger?: ServerLogger;
|
|
37
|
+
slowRunMs?: number;
|
|
38
|
+
}) => void;
|
|
39
|
+
/** The server's own voice: `serverLog.error('RSC', 'element failed to resolve', error)`. Below the threshold, nothing. */
|
|
40
|
+
export declare const serverLog: {
|
|
41
|
+
error: (scope: string, message: string, cause?: unknown) => void;
|
|
42
|
+
warn: (scope: string, message: string, cause?: unknown) => void;
|
|
43
|
+
info: (scope: string, message: string, cause?: unknown) => void;
|
|
44
|
+
debug: (scope: string, message: string, cause?: unknown) => void;
|
|
45
|
+
/** Whether a level would be said — to skip building a costly message nobody will read. */
|
|
46
|
+
enabled: (level: LogLevel) => boolean;
|
|
47
|
+
/** Hands an event to a sink the consumer wired itself (`onRun`, `onReject`) only when the process would say it. */
|
|
48
|
+
emit: (logger: ServerLogger, event: ServerLogEvent) => void;
|
|
49
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LogLevel, ServerLogEvent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* The last lines a process said, every level included — what its console leaves out too: a probe answered, a run that
|
|
4
|
+
* worked. Kept in memory and read behind the process's stats secret (`GET /_stats/logs`), so an operator reads ONE
|
|
5
|
+
* instance's log from the back-office without a log shipper, and without the console saying everything to everybody.
|
|
6
|
+
*
|
|
7
|
+
* A line is kept as it renders — the dispatcher already stripped query values, headers, cookies and tokens; a request's
|
|
8
|
+
* client IP is on it, so what reads it is staff's alone.
|
|
9
|
+
*/
|
|
10
|
+
/** One line of a process's log, numbered so a reader asks only for what came after the last one it has. */
|
|
11
|
+
export type LogLine = {
|
|
12
|
+
seq: number;
|
|
13
|
+
/** ISO 8601, UTC. */
|
|
14
|
+
at: string;
|
|
15
|
+
level: LogLevel;
|
|
16
|
+
/** What said it: `request`, `run`, `reject`, `tool`, `resource`, `message`, or the deployment's own (`app`). */
|
|
17
|
+
kind: string;
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
export type LogQuery = {
|
|
21
|
+
/** Only lines after this one. */
|
|
22
|
+
since?: number;
|
|
23
|
+
/** Only lines at this level or more severe: `warn` is warnings and errors. */
|
|
24
|
+
level?: LogLevel;
|
|
25
|
+
/** At most this many, the newest. Default and ceiling {@link LOG_TAIL_SIZE}. */
|
|
26
|
+
limit?: number;
|
|
27
|
+
/** Only lines whose text holds this, case aside. */
|
|
28
|
+
q?: string;
|
|
29
|
+
};
|
|
30
|
+
/** How many lines a process keeps: a busy minute of a page server, an hour of a quiet worker. */
|
|
31
|
+
export declare const LOG_TAIL_SIZE = 1000;
|
|
32
|
+
/** Keeps a line said by the deployment's own logger (`kind: 'app'`) beside the kernel's. */
|
|
33
|
+
export declare const keepLogLine: (level: LogLevel, text: string, kind?: string) => void;
|
|
34
|
+
/** Keeps an event, rendered, at its own level. */
|
|
35
|
+
export declare const keepLogEvent: (event: ServerLogEvent, level: LogLevel, text: string) => void;
|
|
36
|
+
/** What a reader asked for, oldest first, and the newest line's number — what it asks `since` next. */
|
|
37
|
+
export declare const readLogTail: ({ since, level, limit, q }?: LogQuery) => {
|
|
38
|
+
lines: LogLine[];
|
|
39
|
+
last: number;
|
|
40
|
+
kept: number;
|
|
41
|
+
};
|
|
42
|
+
/** A log query from a request's query string, every value checked: what it cannot read is left at its default. */
|
|
43
|
+
export declare const logQueryOf: (query: Record<string, string | undefined>) => LogQuery;
|