@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.
Files changed (142) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +80 -2
  3. package/dist/build/esbuild.d.ts +16 -0
  4. package/dist/build/index.d.ts +1 -0
  5. package/dist/build/index.mjs +35 -0
  6. package/dist/cache/CompressedFileCache.d.ts +18 -0
  7. package/dist/cache/TtlCache.d.ts +65 -0
  8. package/dist/cache/index.d.ts +3 -0
  9. package/dist/cache/index.mjs +1 -0
  10. package/dist/chunks/TtlCache-J_jG9oL9.mjs +200 -0
  11. package/dist/chunks/channel-DnVf7PJB.mjs +190 -0
  12. package/dist/chunks/csrf-BLWcaYOV.mjs +295 -0
  13. package/dist/chunks/link-C9wyDS9H.mjs +124 -0
  14. package/dist/chunks/query-DGbrN3mN.mjs +20 -0
  15. package/dist/chunks/scopes-Co6ZjhAm.mjs +46 -0
  16. package/dist/chunks/serverLog-BKaKjjc4.mjs +137 -0
  17. package/dist/chunks/session-B-dTEjeG.mjs +253 -0
  18. package/dist/chunks/sessionActivity-Ch7xuQ_o.mjs +43 -0
  19. package/dist/chunks/spaceDeployment-J2IMLfij.mjs +76 -0
  20. package/dist/chunks/stage-y6deE9LJ.mjs +345 -0
  21. package/dist/chunks/supervisor-Dh34v1vq.mjs +117 -0
  22. package/dist/chunks/tail-D-USrZIR.mjs +55 -0
  23. package/dist/chunks/tokens-CBd5tXut.mjs +262 -0
  24. package/dist/data/index.d.ts +2 -0
  25. package/dist/data/index.mjs +68 -0
  26. package/dist/data/projectData.d.ts +21 -0
  27. package/dist/deployment/hostDeployment.d.ts +8 -0
  28. package/dist/deployment/index.d.ts +3 -0
  29. package/dist/deployment/index.mjs +19 -0
  30. package/dist/deployment/spaceDeployment.d.ts +11 -0
  31. package/dist/engine/index.d.ts +2 -0
  32. package/dist/engine/index.mjs +1 -0
  33. package/dist/engine/page.d.ts +49 -0
  34. package/dist/engine/rsc.d.ts +32 -0
  35. package/dist/files/atomicFile.d.ts +10 -0
  36. package/dist/files/index.d.ts +1 -0
  37. package/dist/files/index.mjs +32 -0
  38. package/dist/http/bearer.d.ts +5 -0
  39. package/dist/http/buildResponseHelpers.d.ts +23 -0
  40. package/dist/http/closeOnSignals.d.ts +28 -0
  41. package/dist/http/compress.d.ts +20 -0
  42. package/dist/http/dispatcher.d.ts +15 -0
  43. package/dist/http/drain.d.ts +18 -0
  44. package/dist/http/fleet/channel.d.ts +103 -0
  45. package/dist/http/fleet/link.d.ts +28 -0
  46. package/dist/http/fleet/role.d.ts +46 -0
  47. package/dist/http/fleet/supervisor.d.ts +29 -0
  48. package/dist/http/freePort.d.ts +24 -0
  49. package/dist/http/health.d.ts +21 -0
  50. package/dist/http/index.d.ts +48 -0
  51. package/dist/http/index.mjs +1313 -0
  52. package/dist/http/middlewares/auth.d.ts +2 -0
  53. package/dist/http/middlewares/basicAuth.d.ts +6 -0
  54. package/dist/http/mimeTypes.d.ts +13 -0
  55. package/dist/http/navigation.d.ts +14 -0
  56. package/dist/http/onAbort.d.ts +12 -0
  57. package/dist/http/probes.d.ts +4 -0
  58. package/dist/http/requestParser.d.ts +22 -0
  59. package/dist/http/runMiddlewares.d.ts +6 -0
  60. package/dist/http/securityHeaders.d.ts +18 -0
  61. package/dist/http/server.d.ts +39 -0
  62. package/dist/http/socketResponse.d.ts +18 -0
  63. package/dist/http/sse.d.ts +26 -0
  64. package/dist/http/stages/crossSiteWrites.d.ts +24 -0
  65. package/dist/http/stages/health.d.ts +11 -0
  66. package/dist/http/stages/middlewares.d.ts +3 -0
  67. package/dist/http/stages/static.d.ts +4 -0
  68. package/dist/http/staticFiles.d.ts +3 -0
  69. package/dist/http/stopping.d.ts +11 -0
  70. package/dist/http/transports.d.ts +31 -0
  71. package/dist/http/types.d.ts +29 -0
  72. package/dist/http/unusedPort.d.ts +10 -0
  73. package/dist/http/webExchange.d.ts +18 -0
  74. package/dist/http/wsFrame.d.ts +3 -0
  75. package/dist/identity/accounts.d.ts +278 -0
  76. package/dist/identity/authorize.d.ts +96 -0
  77. package/dist/identity/credentials.d.ts +40 -0
  78. package/dist/identity/csrf.d.ts +139 -0
  79. package/dist/identity/debugAuthorization.d.ts +24 -0
  80. package/dist/identity/domains.d.ts +41 -0
  81. package/dist/identity/identity.d.ts +119 -0
  82. package/dist/identity/index.d.ts +21 -0
  83. package/dist/identity/index.mjs +731 -0
  84. package/dist/identity/passwords.d.ts +15 -0
  85. package/dist/identity/previewToken.d.ts +21 -0
  86. package/dist/identity/requestIdentity.d.ts +14 -0
  87. package/dist/identity/scopes.d.ts +56 -0
  88. package/dist/identity/session.d.ts +185 -0
  89. package/dist/identity/sessionActivity.d.ts +11 -0
  90. package/dist/identity/spaceTokens.d.ts +174 -0
  91. package/dist/index.d.ts +17 -0
  92. package/dist/index.mjs +1 -0
  93. package/dist/log/index.d.ts +3 -0
  94. package/dist/log/index.mjs +3 -0
  95. package/dist/log/serverLog.d.ts +49 -0
  96. package/dist/log/tail.d.ts +43 -0
  97. package/dist/mysql/accounts.d.ts +4 -0
  98. package/dist/mysql/admin.d.ts +58 -0
  99. package/dist/mysql/config.d.ts +82 -0
  100. package/dist/mysql/identities.d.ts +35 -0
  101. package/dist/mysql/index.d.ts +7 -0
  102. package/dist/mysql/index.mjs +1203 -0
  103. package/dist/mysql/pool.d.ts +3 -0
  104. package/dist/mysql/query.d.ts +12 -0
  105. package/dist/mysql/schema.d.ts +43 -0
  106. package/dist/mysql/sessions.d.ts +23 -0
  107. package/dist/mysql/spaceTokens.d.ts +11 -0
  108. package/dist/mysql/store.d.ts +66 -0
  109. package/dist/outbound/index.d.ts +4 -0
  110. package/dist/outbound/index.mjs +314 -0
  111. package/dist/outbound/inside.d.ts +36 -0
  112. package/dist/outbound/outboundGuard.d.ts +69 -0
  113. package/dist/pubsub/index.d.ts +3 -0
  114. package/dist/pubsub/index.mjs +76 -0
  115. package/dist/pubsub/memoryPubSub.d.ts +10 -0
  116. package/dist/pubsub/redisPubSub.d.ts +24 -0
  117. package/dist/stats/index.d.ts +9 -0
  118. package/dist/stats/index.mjs +228 -0
  119. package/dist/stats/load.d.ts +31 -0
  120. package/dist/stats/memory.d.ts +20 -0
  121. package/dist/stats/pools.d.ts +15 -0
  122. package/dist/stats/recorder.d.ts +34 -0
  123. package/dist/stats/stage.d.ts +15 -0
  124. package/dist/stats/types.d.ts +309 -0
  125. package/dist/testing/certificates.d.ts +21 -0
  126. package/dist/testing/fleet.d.ts +28 -0
  127. package/dist/testing/goneRuns.d.ts +5 -0
  128. package/dist/testing/index.d.ts +5 -0
  129. package/dist/testing/index.mjs +270 -0
  130. package/dist/testing/keys.d.ts +2 -0
  131. package/dist/testing/runNames.d.ts +10 -0
  132. package/dist/tokens/index.d.ts +2 -0
  133. package/dist/tokens/index.mjs +1 -0
  134. package/dist/tokens/tokens.d.ts +190 -0
  135. package/dist/types/adapters.d.ts +388 -0
  136. package/dist/types/config.d.ts +240 -0
  137. package/dist/types/index.d.ts +5 -0
  138. package/dist/types/index.mjs +1 -0
  139. package/dist/types/log.d.ts +119 -0
  140. package/dist/types/oauth.d.ts +246 -0
  141. package/dist/types/pipeline.d.ts +239 -0
  142. package/package.json +67 -3
@@ -0,0 +1,239 @@
1
+ import { SSRMeterDecision, SSRSpaceDeployment } from './adapters';
2
+ import { ActionRunSummary, FontHead, PluginEntry, SSRUser, SpaceScope } from '@plitzi/sdk-shared';
3
+ import { SpaceChange } from '@plitzi/sdk-shared/history';
4
+ import { PageHeadTags } from '@plitzi/sdk-shared/schema';
5
+ import { IncomingHttpHeaders } from 'node:http';
6
+ export type ServerEnvironment = 'development' | 'production' | 'staging' | 'local';
7
+ export type SSRHeaders = IncomingHttpHeaders & {
8
+ ':authority'?: string;
9
+ ':method'?: string;
10
+ ':path'?: string;
11
+ ':scheme'?: string;
12
+ };
13
+ export type SSRRequest = {
14
+ method: string;
15
+ path: string;
16
+ search: string;
17
+ url: string;
18
+ hostname: string;
19
+ protocol: 'http' | 'https';
20
+ headers: SSRHeaders;
21
+ query: Record<string, string>;
22
+ /** Raw request body. Populated only for endpoints that consume it (e.g. the login/logout handlers). */
23
+ body?: string;
24
+ /**
25
+ * The client's address, when the host resolved one — through the proxies it sits behind. Forgeable by a direct
26
+ * client like every forwarded header, so it names things (a session in a device list) and never decides anything.
27
+ */
28
+ ip?: string;
29
+ ctx: SSRContext;
30
+ };
31
+ /** A body's compressed forms, by content encoding — filled as they are first asked for. */
32
+ export type CompressedBodies = Partial<Record<'br' | 'gzip', Buffer>>;
33
+ export type SSRResponseHelpers = {
34
+ status: number;
35
+ /** Multi-valued for the headers that genuinely are, `Set-Cookie` above all — see `setHeader`. */
36
+ headers: Record<string, string | string[]>;
37
+ /** An array sets the header once per entry, which `Set-Cookie` needs: a response that grants a session writes
38
+ * several, and collapsing them into one string would produce a single malformed cookie. */
39
+ setHeader: (name: string, value: string | string[]) => void;
40
+ setStatus: (code: number) => void;
41
+ /**
42
+ * A `Buffer` is sent byte for byte and never compressed: it is how a binary reaches the wire — a font file, an
43
+ * image — and what it holds is usually compressed already. A string keeps the encoding negotiation.
44
+ *
45
+ * `compressed` is where this body's compressed forms are kept, for a body that is sent again unchanged — a cached
46
+ * page, a static file. The first send of each encoding compresses and stores it; every later one sends the stored
47
+ * bytes. Without it a cache hit recompressed the same page on every request, which was nearly all the CPU a cached
48
+ * page cost.
49
+ *
50
+ * A function is a body read only when it is needed: when the stored form for this request's encoding is missing, or
51
+ * the client takes no compression. A static file is then read from disk once per encoding, not on every request.
52
+ */
53
+ send: (body: string | Buffer | (() => string), options?: {
54
+ compressed?: CompressedBodies;
55
+ }) => void;
56
+ write: (chunk: string | Buffer) => void;
57
+ end: () => void;
58
+ /**
59
+ * A `103 Early Hints` with these `Link` values, before the response itself: what the page will ask for, fetched while
60
+ * it is still being rendered. Nothing on a transport that cannot send one, or once the response has begun.
61
+ */
62
+ earlyHints?: (links: string[]) => void;
63
+ };
64
+ export type SSRCredential = {
65
+ provider: string;
66
+ data: unknown;
67
+ };
68
+ export type SSRTemplateProps = {
69
+ /** The render's script nonce, written on each of the template's own scripts (`SSRServerConfig.scriptPolicy`). */
70
+ nonce?: string;
71
+ /**
72
+ * The page's script policy, said on `<html data-plitzi-script-policy>`: what every copy of the SDK's shared code a page
73
+ * loads — the builder's, a plugin's own — reads to hold itself to it (`startMarkupPolicies`).
74
+ */
75
+ scriptPolicy?: 'report-only' | 'enforce';
76
+ title?: string;
77
+ /** Meta description for the document, and the share-preview text derived from it. */
78
+ description?: string;
79
+ /**
80
+ * The head's tags besides the title and the JSON-LD — description, robots, Open Graph and card, the canonical
81
+ * address, the icon, the browser's colour, the language — as `pageHeadTags` decides them. The server's own.
82
+ */
83
+ head?: PageHeadTags;
84
+ jsPath?: string;
85
+ cssPath?: string;
86
+ /** Font Awesome's rules, after `cssPath`; its fonts are files beside it, fetched only for a style the page uses. */
87
+ iconsCssPath?: string;
88
+ /**
89
+ * Where the page fetches the space from, when it travels beside the document rather than in its payload: the
90
+ * page preloads it, and the bootstrap reads it before hydrating.
91
+ */
92
+ spaceDocumentPath?: string;
93
+ /**
94
+ * The space's compiled stylesheet, when the page links it rather than carrying it (`style.cacheHref`): a template
95
+ * puts it in the head, where it is applied from the page's first frame.
96
+ */
97
+ styleSheetPath?: string;
98
+ builderJsPath?: string;
99
+ builderCssPath?: string;
100
+ plugins?: PluginEntry[];
101
+ react?: string;
102
+ reactJsx?: string;
103
+ reactDom?: string;
104
+ reactDomClient?: string;
105
+ reactCompilerRuntime?: string;
106
+ /** When true the client-side <script> block is omitted — useful for inspecting raw SSR HTML. */
107
+ ssrOnly?: boolean;
108
+ /** The page listens for what the server tells it changed — with `livePages` on (`updatePages`, `reloadPages`). */
109
+ livePages?: boolean;
110
+ /** The draft the page shows (`?__pt=<id>`), named in its listening address so it hears its own changes alone. */
111
+ liveDraft?: string;
112
+ /** The page's plugins can be swapped where they are drawn — a server developing (`devMode`) with `livePages` on. */
113
+ hotPlugins?: boolean;
114
+ debugMode?: boolean;
115
+ /**
116
+ * The theme class this document wears on `<html>` — `dark`, `light`, or nothing at all.
117
+ *
118
+ * The theme is kept in a cookie, so the server that renders the document already knows it: the page arrives
119
+ * painted correctly, with no blocking script in the head and no first paint in the other theme. Empty is not a
120
+ * failure — it is `system`, and the stylesheet's `prefers-color-scheme` queries answer it.
121
+ */
122
+ themeClass?: string;
123
+ /**
124
+ * The document's web fonts: `fontsToHead(style.fonts, ...)` from this package.
125
+ *
126
+ * In the template rather than left to the SDK because a page paints before its JavaScript exists. A face
127
+ * requested at hydration arrives after the text it is for has already been drawn in a fallback, which is a
128
+ * reflow the visitor watches happen.
129
+ */
130
+ fonts?: FontHead;
131
+ };
132
+ /** A resolved space token: which space, what the bearer may do, and (for `agent`) the member who consented.
133
+ * `canWrite` is computed by the consumer from its own authorization model — the MCP never derives it. */
134
+ export type SSRGrant = {
135
+ spaceId: number;
136
+ scope: SpaceScope;
137
+ userId?: number;
138
+ /** For an `agent` grant, the application the member connected (`Claude`): what its writes are recorded and shown as. */
139
+ client?: string;
140
+ canWrite: boolean;
141
+ /**
142
+ * Whether it may write and play the space's tests — every role that writes may, and a tester's role (`Can test`) may
143
+ * with nothing else: the MCP saves the tests alone through it, never another change.
144
+ */
145
+ canTest?: boolean;
146
+ /** Why `canWrite` is false, in the consumer's words, said to the agent in place of the MCP's own: a role that views
147
+ * or edits only the content never had the right to change the design — it did not lose it. */
148
+ readOnlyReason?: string;
149
+ };
150
+ /** A page of a space's change history, newest first; `nextBefore` reads further back, null at the end. */
151
+ export type SSRChangePage = {
152
+ changes: SpaceChange[];
153
+ nextBefore: number | null;
154
+ };
155
+ /** What to read of the history: older than `before`, only the changes that touched `entityId`, `limit` at a time. */
156
+ export type SSRChangeQuery = {
157
+ before?: number;
158
+ entityId?: string;
159
+ limit: number;
160
+ };
161
+ /** Who a write is made for and which request made it, for a consumer that records its changes. Every document one
162
+ * request writes shares its `batch`: one `plitzi_apply`, read back as one change. `client` is the application that
163
+ * wrote it for them (`SSRGrant.client`). */
164
+ export type SSRWriteContext = {
165
+ userId?: number;
166
+ batch: string;
167
+ client?: string;
168
+ };
169
+ /**
170
+ * A session, as the thing that issued it describes it. Deliberately free of transport: whoever mints one says what
171
+ * the credentials are and when they die, and the server decides how they are carried — which is what lets a
172
+ * deployment bring its own identity source without also reimplementing cookies.
173
+ */
174
+ export type SSRSession = {
175
+ token: string;
176
+ /** Unix seconds. */
177
+ expiresAt: number;
178
+ refreshToken?: string;
179
+ refreshExpiresAt?: number;
180
+ };
181
+ export type SSRMiddlewareNext = () => Promise<void> | void;
182
+ export type SSRMiddleware = (req: SSRRequest, res: SSRResponseHelpers, next: SSRMiddlewareNext) => Promise<void> | void;
183
+ export type SSRContext = {
184
+ spaceDeployment?: SSRSpaceDeployment;
185
+ user?: SSRUser;
186
+ /** What {@link SSRAdapters.meter} answered for this request, so the render reads the decision instead of
187
+ * asking for it a second time. */
188
+ meter?: SSRMeterDecision;
189
+ /**
190
+ * The runs this request's server elements started, as the action resolver ran them. Read once the render or the
191
+ * refresh is done, and handed on only to a page whose debugging is authorized.
192
+ */
193
+ actionRuns?: ActionRunSummary[];
194
+ /**
195
+ * This server previews a run of agents and answers its snapshot at `RUN_STATUS_PATH` (`plitzi run preview`): said to a
196
+ * page that may debug, so its dev tools ask for the run — and no other page's ask a server that has none.
197
+ */
198
+ runStatus?: true;
199
+ /**
200
+ * This request renders a draft session minted for a test runner (`DraftEntry.inspected`): the page carries the
201
+ * space's state bridge, `window.__plitzi`, with no panel or badge.
202
+ */
203
+ inspectedDraft?: true;
204
+ /**
205
+ * What a refresh of server data asked for beside the page's own address (`/_rsc?location=…&q=…`): a provider's
206
+ * `input`, a page window. What the provider asks for this time, so it wins over the `input` the element was saved
207
+ * with — the query string of the page does not.
208
+ */
209
+ rscParams?: Record<string, string>;
210
+ /**
211
+ * What this request spent before the page was rendered — each middleware, the metering — in ms, kept only by a
212
+ * development server: it goes out in the page's `Server-Timing` beside the render's own phases.
213
+ */
214
+ timings?: {
215
+ name: string;
216
+ dur: number;
217
+ }[];
218
+ /**
219
+ * A server provider read this response's data with the visitor's own cookies (`rsc.visitorCredentials`): it is kept
220
+ * for nobody, the page nor its refresh — a later visit would show what a write since made untrue.
221
+ */
222
+ readAsVisitor?: boolean;
223
+ };
224
+ /**
225
+ * How this deployment's session cookies are named and scoped. Every field has a working default derived from the
226
+ * request host, so a server that says nothing still gets a correct cookie; the function forms exist for deployments
227
+ * whose naming varies by environment or host, which is a policy only they know.
228
+ */
229
+ export type SSRAuthCookie = {
230
+ name?: string | ((hostname: string) => string);
231
+ /** Return undefined for a host-only cookie. Defaults to the registrable domain, so sibling sub-domains share it. */
232
+ domain?: string | ((hostname: string) => string | undefined);
233
+ sameSite?: 'lax' | 'none';
234
+ secure?: boolean;
235
+ /** Path the refresh credential is confined to, so it never rides along on ordinary traffic. Defaults to `/auth`. */
236
+ refreshPath?: string;
237
+ /** Suffix of the readable companion cookie that carries only expiries. Defaults to `_hint`. */
238
+ hintSuffix?: string;
239
+ };
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-kernel",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.39.2",
4
+ "license": "AGPL-3.0",
5
+ "description": "What every Plitzi server process is built on: the HTTP pipeline, health and shutdown, the host → deployment resolution, and verifying who a request is.",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "exports": {
10
+ ".": {
11
+ "@plitzi/source": "./src/index.ts",
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "default": "./dist/index.mjs"
15
+ },
16
+ "./*": {
17
+ "@plitzi/source": "./src/*/index.ts",
18
+ "types": "./dist/*/index.d.ts",
19
+ "import": "./dist/*/index.mjs",
20
+ "default": "./dist/*/index.mjs"
21
+ }
22
+ },
23
+ "repository": {
24
+ "type": "https",
25
+ "url": "https://github.com/plitzi/plitzi-workspace.git"
26
+ },
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "engines": {
30
+ "node": "^24.22.1 || >=26.12.1"
31
+ },
32
+ "scripts": {
33
+ "lint": "eslint --cache --cache-location .eslintcache --cache-strategy content ./src",
34
+ "typecheck": "tsc -p tsconfig.app.json --noEmit --incremental --tsBuildInfoFile .tsbuildinfo/app.tsbuildinfo",
35
+ "test": "vitest run",
36
+ "build:dev": "vite build --mode development",
37
+ "build:prod": "vite build"
38
+ },
39
+ "dependencies": {
40
+ "@plitzi/sdk-shared": "0.39.2",
41
+ "jsonwebtoken": "^9.0.3",
42
+ "undici": "^8.12.4",
43
+ "ws": "^8.22.2"
44
+ },
45
+ "peerDependencies": {
46
+ "esbuild": "^0.28.2",
47
+ "mysql2": "^3"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "esbuild": {
51
+ "optional": true
52
+ },
53
+ "mysql2": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@types/jsonwebtoken": "^9.0.10",
59
+ "@types/node": "^26.6.6",
60
+ "@types/ws": "^8.18.2",
61
+ "esbuild": "^0.28.2",
62
+ "eslint": "^9.39.5",
63
+ "eslint-plugin-import": "^2.32.0",
64
+ "mysql2": "^3.24.6",
65
+ "typescript": "^6.0.3",
66
+ "vite": "^8.3.7",
67
+ "vite-plugin-dts": "^5.1.2",
68
+ "vitest": "^5.1.0"
69
+ }
6
70
  }