@plitzi/sdk-shared 0.38.24 → 0.39.0

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 (194) hide show
  1. package/CHANGELOG.md +146 -1
  2. package/dist/actions/functions.d.ts +22 -1
  3. package/dist/actions/functions.mjs +3 -3
  4. package/dist/actions/index.d.ts +1 -1
  5. package/dist/actions/index.mjs +7 -7
  6. package/dist/auth/failureChannel.mjs +1 -0
  7. package/dist/auth/index.d.ts +1 -1
  8. package/dist/auth/index.mjs +2 -2
  9. package/dist/auth/visitorRoles.d.ts +8 -0
  10. package/dist/auth/visitorRoles.mjs +5 -2
  11. package/dist/authoring/declare.d.ts +34 -1
  12. package/dist/authoring/elementCallbacks.d.ts +13 -0
  13. package/dist/authoring/elementCallbacks.mjs +11 -5
  14. package/dist/authoring/index.mjs +3 -3
  15. package/dist/authoring/paramSpec.d.ts +1 -0
  16. package/dist/dataSource/getBindingsDetails.d.ts +1 -1
  17. package/dist/dataSource/getBindingsDetails.mjs +1 -1
  18. package/dist/dataSource/globalSources.d.ts +1 -1
  19. package/dist/dataSource/index.d.ts +1 -2
  20. package/dist/dataSource/index.mjs +1 -1
  21. package/dist/dataSource/utility/arrayMap.mjs +1 -1
  22. package/dist/dataSource/utility/capitalize.mjs +1 -1
  23. package/dist/dataSource/utility/styleSelector.mjs +5 -3
  24. package/dist/dataSource/utility/styleVariant.mjs +17 -13
  25. package/dist/dataSource/variables/index.d.ts +2 -0
  26. package/dist/dataSource/variables/index.mjs +1 -0
  27. package/dist/dataSource/{resolveVariables.d.ts → variables/resolveVariables.d.ts} +1 -1
  28. package/dist/dataSource/{resolveVariables.mjs → variables/resolveVariables.mjs} +1 -1
  29. package/dist/devTools/chrome.d.ts +6 -0
  30. package/dist/devTools/chrome.mjs +2 -2
  31. package/dist/devTools/index.mjs +5 -5
  32. package/dist/devTools/sight/index.d.ts +1 -0
  33. package/dist/devTools/sight/index.mjs +1 -0
  34. package/dist/devTools/sight/sight.d.ts +28 -0
  35. package/dist/devTools/sight/sight.mjs +127 -0
  36. package/dist/devTools/utils/PlitziConsole.d.ts +14 -0
  37. package/dist/devTools/utils/PlitziConsole.mjs +20 -3
  38. package/dist/flags/flagsCookie.mjs +4 -4
  39. package/dist/flags/resolveFlags.d.ts +1 -1
  40. package/dist/helpers/index.mjs +19 -19
  41. package/dist/helpers/ruleEvaluator.d.ts +2 -0
  42. package/dist/helpers/ruleEvaluator.mjs +2 -2
  43. package/dist/helpers/scroll.d.ts +10 -0
  44. package/dist/helpers/scroll.mjs +2 -2
  45. package/dist/helpers/twigWrapper/Evaluator/Evaluator.mjs +90 -88
  46. package/dist/helpers/twigWrapper/Evaluator/helpers.d.ts +6 -0
  47. package/dist/helpers/twigWrapper/Evaluator/helpers.mjs +11 -2
  48. package/dist/helpers/twigWrapper/filters/arrays.d.ts +2 -0
  49. package/dist/helpers/twigWrapper/filters/arrays.mjs +66 -0
  50. package/dist/helpers/twigWrapper/filters/catalog/index.d.ts +17 -0
  51. package/dist/helpers/twigWrapper/filters/catalog/index.mjs +351 -0
  52. package/dist/helpers/twigWrapper/filters/dateParts.d.ts +25 -0
  53. package/dist/helpers/twigWrapper/filters/dateParts.mjs +56 -0
  54. package/dist/helpers/twigWrapper/filters/dates.d.ts +2 -0
  55. package/dist/helpers/twigWrapper/filters/dates.mjs +97 -0
  56. package/dist/helpers/twigWrapper/filters/filters.d.ts +3 -13
  57. package/dist/helpers/twigWrapper/filters/filters.mjs +25 -483
  58. package/dist/helpers/twigWrapper/filters/hashing.d.ts +3 -0
  59. package/dist/helpers/twigWrapper/filters/hashing.mjs +101 -0
  60. package/dist/helpers/twigWrapper/filters/index.mjs +4 -1
  61. package/dist/helpers/twigWrapper/filters/misc.d.ts +5 -0
  62. package/dist/helpers/twigWrapper/filters/misc.mjs +52 -0
  63. package/dist/helpers/twigWrapper/filters/numbers.d.ts +2 -0
  64. package/dist/helpers/twigWrapper/filters/numbers.mjs +36 -0
  65. package/dist/helpers/twigWrapper/filters/objects.d.ts +3 -0
  66. package/dist/helpers/twigWrapper/filters/objects.mjs +61 -0
  67. package/dist/helpers/twigWrapper/filters/raw.d.ts +8 -0
  68. package/dist/helpers/twigWrapper/filters/raw.mjs +7 -0
  69. package/dist/helpers/twigWrapper/filters/strings.d.ts +7 -0
  70. package/dist/helpers/twigWrapper/filters/strings.mjs +79 -0
  71. package/dist/helpers/twigWrapper/filters/types.d.ts +5 -0
  72. package/dist/helpers/twigWrapper/filters/types.mjs +4 -0
  73. package/dist/helpers/twigWrapper/filters/values.d.ts +12 -0
  74. package/dist/helpers/twigWrapper/filters/values.mjs +17 -0
  75. package/dist/helpers/twigWrapper/inspectTemplate.d.ts +5 -0
  76. package/dist/helpers/twigWrapper/inspectTemplate.mjs +39 -20
  77. package/dist/helpers/utils.d.ts +4 -0
  78. package/dist/helpers/utils.mjs +3 -5
  79. package/dist/navigation/index.d.ts +2 -0
  80. package/dist/navigation/index.mjs +2 -1
  81. package/dist/navigation/sitemap.d.ts +16 -0
  82. package/dist/navigation/sitemap.mjs +25 -0
  83. package/dist/network/entitlements.d.ts +101 -0
  84. package/dist/network/entitlements.mjs +4 -0
  85. package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.d.ts +31 -0
  86. package/dist/network/graphql/builder/Mutations/Space/SpaceRunE2eTestsMutation.mjs +13 -0
  87. package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.d.ts +5 -0
  88. package/dist/network/graphql/builder/Mutations/Space/SpaceSetTestsMutation.mjs +11 -0
  89. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.d.ts +1 -1
  90. package/dist/network/graphql/builder/Mutations/Space/SpaceUpdateSettingsMutation.mjs +1 -1
  91. package/dist/network/graphql/builder/Mutations/index.d.ts +5 -0
  92. package/dist/network/graphql/builder/Mutations/index.mjs +150 -146
  93. package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.d.ts +40 -0
  94. package/dist/network/graphql/builder/Queries/Space/SpaceTestsQuery.mjs +24 -0
  95. package/dist/network/graphql/builder/Queries/index.d.ts +3 -0
  96. package/dist/network/graphql/builder/Queries/index.mjs +44 -42
  97. package/dist/network/graphql/sdk/Queries/InitQuery.d.ts +3 -1
  98. package/dist/network/graphql/sdk/Queries/InitQuery.mjs +1 -1
  99. package/dist/network/index.d.ts +1 -0
  100. package/dist/network/index.mjs +9 -8
  101. package/dist/network/spaceEvents.d.ts +20 -1
  102. package/dist/network/spaceEvents.mjs +12 -0
  103. package/dist/project/index.mjs +8 -5
  104. package/dist/project/layout/check.d.ts +22 -0
  105. package/dist/project/layout/check.mjs +60 -0
  106. package/dist/project/{layout.d.ts → layout/codes.d.ts} +3 -66
  107. package/dist/project/layout/codes.mjs +108 -0
  108. package/dist/project/layout/contents.d.ts +10 -0
  109. package/dist/project/layout/contents.mjs +31 -0
  110. package/dist/project/layout/files.d.ts +31 -0
  111. package/dist/project/layout/files.mjs +49 -0
  112. package/dist/project/layout/folders.d.ts +4 -0
  113. package/dist/project/layout/folders.mjs +69 -0
  114. package/dist/project/layout/index.d.ts +16 -0
  115. package/dist/project/layout/index.mjs +5 -0
  116. package/dist/project/layout/plugins.d.ts +46 -0
  117. package/dist/project/layout/plugins.mjs +99 -0
  118. package/dist/project/layout/vendor.d.ts +15 -0
  119. package/dist/project/layout/vendor.mjs +34 -0
  120. package/dist/project/pages/index.d.ts +8 -0
  121. package/dist/project/pages/index.mjs +14 -0
  122. package/dist/project/paths/index.d.ts +52 -4
  123. package/dist/project/paths/index.mjs +2 -2
  124. package/dist/project/root.d.ts +6 -0
  125. package/dist/project/root.mjs +11 -10
  126. package/dist/realtime/client.mjs +104 -91
  127. package/dist/realtime/presence.d.ts +2 -2
  128. package/dist/realtime/presence.mjs +27 -21
  129. package/dist/runs/index.d.ts +73 -0
  130. package/dist/runs/index.mjs +6 -0
  131. package/dist/runs/report.d.ts +56 -0
  132. package/dist/runs/report.mjs +17 -0
  133. package/dist/schema/index.d.ts +6 -0
  134. package/dist/schema/index.mjs +18 -12
  135. package/dist/schema/motion.d.ts +25 -0
  136. package/dist/schema/motion.mjs +47 -19
  137. package/dist/schema/pageAccess.d.ts +6 -0
  138. package/dist/schema/pageAccess.mjs +8 -3
  139. package/dist/schema/pageHead.d.ts +64 -0
  140. package/dist/schema/pageHead.mjs +68 -0
  141. package/dist/schema/providerAnswer.d.ts +17 -0
  142. package/dist/schema/providerAnswer.mjs +4 -0
  143. package/dist/schema/providerWhen.d.ts +36 -0
  144. package/dist/schema/providerWhen.mjs +58 -0
  145. package/dist/schema/schemaSettings.d.ts +14 -0
  146. package/dist/schema/schemaSettings.mjs +4 -0
  147. package/dist/schema/serverElements.d.ts +20 -1
  148. package/dist/schema/serverElements.mjs +41 -28
  149. package/dist/schema/serverInput.d.ts +34 -0
  150. package/dist/schema/serverInput.mjs +60 -0
  151. package/dist/schema/serverQuery.d.ts +47 -0
  152. package/dist/schema/serverQuery.mjs +70 -0
  153. package/dist/server/index.mjs +5 -5
  154. package/dist/server/rsc/refreshRsc.d.ts +6 -2
  155. package/dist/server/rsc/refreshRsc.mjs +75 -59
  156. package/dist/server/rsc/useRscSync.mjs +22 -18
  157. package/dist/source/export.d.ts +1 -1
  158. package/dist/state/runtimeStatePersist.mjs +25 -17
  159. package/dist/store/renderSettings.d.ts +2 -0
  160. package/dist/store/renderSettings.mjs +13 -5
  161. package/dist/store/storeHooks.d.ts +45 -45
  162. package/dist/style/index.mjs +16 -16
  163. package/dist/style/styleConstants.d.ts +12 -2
  164. package/dist/style/styleConstants.mjs +20 -0
  165. package/dist/style/styleStates.d.ts +5 -0
  166. package/dist/style/styleStates.mjs +21 -5
  167. package/dist/types/ActionTypes.d.ts +26 -3
  168. package/dist/types/AuthTypes.d.ts +19 -1
  169. package/dist/types/CommonTypes.d.ts +3 -2
  170. package/dist/types/ElementTypes.d.ts +1 -1
  171. package/dist/types/InteractionTypes.d.ts +10 -1
  172. package/dist/types/JobTypes.d.ts +2 -1
  173. package/dist/types/OAuthTypes.d.ts +246 -0
  174. package/dist/types/OAuthTypes.mjs +0 -0
  175. package/dist/types/PluginTypes.d.ts +2 -0
  176. package/dist/types/PreviewTypes.d.ts +71 -0
  177. package/dist/types/PreviewTypes.mjs +0 -0
  178. package/dist/types/RealtimeTypes.d.ts +11 -0
  179. package/dist/types/SchemaTypes.d.ts +56 -0
  180. package/dist/types/ServerAdapterTypes.d.ts +345 -0
  181. package/dist/types/ServerAdapterTypes.mjs +0 -0
  182. package/dist/types/ServerConfigTypes.d.ts +527 -0
  183. package/dist/types/ServerConfigTypes.mjs +0 -0
  184. package/dist/types/ServerLogTypes.d.ts +119 -0
  185. package/dist/types/ServerLogTypes.mjs +0 -0
  186. package/dist/types/ServerTypes.d.ts +30 -1215
  187. package/dist/types/StoreTypes.d.ts +39 -1
  188. package/dist/types/TestTypes.d.ts +249 -0
  189. package/dist/types/TestTypes.mjs +0 -0
  190. package/dist/types/index.d.ts +6 -0
  191. package/eslint.config.mjs +3 -1
  192. package/package.json +2 -2
  193. package/setupTests.ts +4 -3
  194. package/dist/project/layout.mjs +0 -394
@@ -0,0 +1,527 @@
1
+ import { ActionEmailConfig, ActionLimits, ActionRejectRecord, ActionRunRecord } from './ActionTypes';
2
+ import { Environment, ServerAuth } from './CommonTypes';
3
+ import { JobQueue } from './JobTypes';
4
+ import { DraftStore, SSRPreviewConfig } from './PreviewTypes';
5
+ import { SSRRealtimeConfig } from './RealtimeTypes';
6
+ import { Schema } from './SchemaTypes';
7
+ import { SSRAdapters, SSRPageAdapters, SpaceRevision } from './ServerAdapterTypes';
8
+ import { LogLevel, ServerLogger } from './ServerLogTypes';
9
+ import { PluginSource, SSRAuthCookie, SSRFontsConfig, SSRImagesConfig, SSRMiddleware, SSRTemplateFn, ServerEnvironment, ServerServices } from './ServerTypes';
10
+ /**
11
+ * How the server reaches a space's actions, and what it may run.
12
+ *
13
+ * Typed loosely for the same reason `ConnectorLookupsConfig` is — the document is executed by
14
+ * `@plitzi/sdk-server`'s actions module and the shared types stay free of its internals. Shaped as `ActionLookups`
15
+ * there.
16
+ */
17
+ export type ActionLookupsConfig = {
18
+ getAction: (spaceId: number, actionId: string, at?: SpaceRevision) => Promise<unknown>;
19
+ listActions?: (spaceId: number, at?: SpaceRevision) => Promise<unknown[]>;
20
+ /** Which spaces have something scheduled — the periodic reconcile's safety net. See `ActionLookups`. */
21
+ listScheduledSpaces?: () => Promise<number[]>;
22
+ getCredential?: (spaceId: number, identifier: string) => Promise<Record<string, string> | undefined>;
23
+ getConnector?: (spaceId: number, connectorId: string, at?: SpaceRevision) => Promise<unknown>;
24
+ /** The space's own functions as of that revision — `SpaceFunctions` in `@plitzi/sdk-server/functions`. */
25
+ getFunctions?: (spaceId: number, at?: SpaceRevision) => Promise<unknown>;
26
+ /** The server halves of the plugins the space uses, by plugin type — a `SpaceFunctions` each. */
27
+ getPluginFunctions?: (spaceId: number, at?: SpaceRevision) => Promise<unknown>;
28
+ /**
29
+ * The space's own data as of that revision — what a project keeps in `src/data/`, kept privately and frozen with each
30
+ * publish — as its files' text by path (`products.json`). A provider resolved on the server whose `query` is
31
+ * `/data/<file>` reads it, and a function's `ctx.data`; no browser is answered it. Given none, `dataDir` is read.
32
+ */
33
+ getData?: (spaceId: number, at?: SpaceRevision) => Promise<unknown>;
34
+ /** The feature flags the space declares as of that revision — what a flow reads as `{{ flags.<name> }}`. */
35
+ getFlags?: (spaceId: number, at?: SpaceRevision) => Promise<Schema['flags']>;
36
+ /**
37
+ * One person of the space by username or id — `{ id, username, name?, avatar? }`, only of someone who belongs to it
38
+ * (its visitors and members, as the deployment knows them): a function's `ctx.visitors.get`. Whatever else is
39
+ * answered is dropped before code sees it. Given none, a server with an `auth` answers its own accounts.
40
+ */
41
+ getVisitor?: (spaceId: number, environment: string, who: string | number) => Promise<unknown>;
42
+ };
43
+ export type SSRActionConfig = {
44
+ /** URL path for the write endpoint, and the base for the action-addressed routes. Defaults to '/_action'. */
45
+ path?: string;
46
+ /**
47
+ * Supplying these is what turns server actions on: without a way to read a document there is nothing to run, and
48
+ * the endpoint keeps answering element-addressed connector writes alone.
49
+ */
50
+ lookups?: ActionLookupsConfig;
51
+ /** Ceilings for every run this server accepts. A document may tighten them, never widen them. */
52
+ limits?: ActionLimits;
53
+ /**
54
+ * Concurrency ceilings.
55
+ *
56
+ * `perSpace`/`perProcess` count CALLS — a click, a webhook, a schedule — where one run is somebody asking for
57
+ * work and one space's callers must not starve another's. A `render` is counted only by `renderPerProcess`,
58
+ * because it arrives because people are reading the page: a ceiling per space there would refuse the five
59
+ * hundredth visitor of a page that is simply doing well.
60
+ */
61
+ concurrency?: {
62
+ perSpace?: number;
63
+ perProcess?: number;
64
+ renderPerProcess?: number;
65
+ };
66
+ /** Inbound webhooks are public by construction, so they are counted per caller per minute. Default 60. */
67
+ rateLimit?: {
68
+ webhookPerMinute?: number;
69
+ };
70
+ /**
71
+ * Database engines a flow may reach, shaped as `ActionDbDriver` in `@plitzi/sdk-server/actions`.
72
+ *
73
+ * Omitted leaves the `db.query` task unregistered entirely. What a driver connects to is always a database the
74
+ * SPACE declared as a credential — never this deployment's own, which no credential a space holds can name.
75
+ */
76
+ dbDrivers?: unknown[];
77
+ /**
78
+ * The limits on `email.send`, which sends through the SMTP credential a step names, and optionally how a message
79
+ * leaves. Omitted keeps the defaults: 200 messages per space per day, no SMTP host on a private network, and the
80
+ * server's own SMTP connection. See {@link ActionEmailConfig}.
81
+ */
82
+ email?: ActionEmailConfig;
83
+ /**
84
+ * Called once per run that STARTED — completed, failed or aborted — for a deployment that keeps a record.
85
+ * Shaped as `ActionRunRecord` in `@plitzi/sdk-server/actions`.
86
+ *
87
+ * A refused request is not a run and is not reported here; it goes to {@link SSRActionConfig.onReject}.
88
+ */
89
+ onRun?: (record: ActionRunRecord) => void | Promise<void>;
90
+ /**
91
+ * Called once per request that was REFUSED before it became a run — a webhook whose signature did not verify, a
92
+ * caller over the rate limit, an action nobody may start. Shaped as `ActionRejectRecord`.
93
+ *
94
+ * Its own hook because it answers a different question from `onRun`: runs are history, refusals are a fault
95
+ * report, and the one that matters most — a signature that does not match — is otherwise indistinguishable
96
+ * from the integration simply never firing. Everything is reported; which refusals are worth keeping (a
97
+ * duplicate delivery is a polite retry, not a fault) is the deployment's to decide.
98
+ */
99
+ onReject?: (record: ActionRejectRecord) => void | Promise<void>;
100
+ /**
101
+ * Replaying a finished run's answer to a caller that asks again with the same key, for this many milliseconds.
102
+ *
103
+ * Off unless set, and it only ever applies to a key the CALLER named — an `idempotencyKey` on the call or the
104
+ * delivery id a webhook sender stamps. Single-flight already refuses a retry that arrives while the first run
105
+ * is going; this is for the one that arrives after it finished, which is how every provider retries.
106
+ */
107
+ idempotency?: {
108
+ replayTtlMs?: number;
109
+ };
110
+ /**
111
+ * What each space's functions sign with (`ctx.sign` / `ctx.verify`): at least 32 characters, the same on every
112
+ * replica. Each space and environment signs with a key derived from it. Absent, spaces sign nothing.
113
+ */
114
+ signingSecret?: string;
115
+ /**
116
+ * Where the `kv` tasks keep things — shaped as `ActionKvAdapter` in `@plitzi/sdk-server/actions`.
117
+ *
118
+ * Six operations over strings, with no rule to obey: Redis, Memcached, a table, whatever this deployment
119
+ * already runs. How a counter BEHAVES — the key prefixing, the JSON round trip, and the rule that a window's
120
+ * lifetime is set once by whoever created it — belongs to the server, not to the thing it writes into.
121
+ *
122
+ * Omitted leaves an in-process Map, which counts only its own replica. That is fine for one; for a cluster it is
123
+ * a rate limit that multiplies by the number of them, so a multi-replica deployment supplies a shared one.
124
+ */
125
+ kv?: {
126
+ get: (key: string) => Promise<string | undefined>;
127
+ set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
128
+ delete: (key: string) => Promise<void>;
129
+ increment: (key: string, amount: number) => Promise<number>;
130
+ expire: (key: string, ttlSeconds: number) => Promise<void>;
131
+ /** Writes `next` only if the key holds `expected` (nothing, when undefined); answers whether it wrote. Atomic. */
132
+ swap: (key: string, expected: string | undefined, next: string, ttlSeconds?: number) => Promise<boolean>;
133
+ };
134
+ /**
135
+ * Scheduled runs: the durable queue they wait in, how many this replica runs at once, and whether it produces.
136
+ *
137
+ * On wherever `lookups.listActions` is answerable — a `schedule` trigger the editor offers is a trigger the
138
+ * server honours, which before this it only did if the deployment wrote a timer and a distributed lock of its
139
+ * own. With no `queue` it runs over this process's memory: right for one replica, and wrong for two, because
140
+ * each then keeps its own schedules and the nightly email goes out once per replica.
141
+ *
142
+ * `false` turns it off for a replica that must only serve pages.
143
+ */
144
+ jobs?: SSRActionJobsConfig | false;
145
+ };
146
+ /**
147
+ * How this deployment runs what a clock starts.
148
+ *
149
+ * Every default here is a safe one for a single machine; the two a cluster has to think about are `queue` — which
150
+ * must be shared, or the replicas do not see each other's work — and `workers`, which is how fast a backlog
151
+ * drains. Nothing in this config is a clock: the queue's own is the only one the scheduling path reads, so
152
+ * replicas in different countries agree about what has run without agreeing about what time it is.
153
+ */
154
+ export type SSRActionJobsConfig = {
155
+ /** Shaped as `JobQueue`. Omitted → this process's memory. */
156
+ queue?: JobQueue;
157
+ /** Jobs this replica runs at once. Default 4; `0` produces without consuming. */
158
+ workers?: number;
159
+ /** Whether this replica sweeps due schedules into the queue. Default true. */
160
+ produce?: boolean;
161
+ /** The spaces this server schedules for, when it serves a known few — the self-hosted shape. */
162
+ spaces?: number[];
163
+ /** How often a free worker looks for a job. Default 1s. */
164
+ pollMs?: number;
165
+ /** How often this replica looks for due schedules. Default 15s. */
166
+ schedulePollMs?: number;
167
+ /** How long a claim is held before another replica may take the job over — the failover window. Default 30s. */
168
+ leaseMs?: number;
169
+ /** Attempts a job gets before it is left for an operator as `dead`. Default 3. */
170
+ maxAttempts?: number;
171
+ /** First retry delay, doubling per attempt, up to `maxMs`. Defaults to 30s and 15 minutes. */
172
+ backoff?: {
173
+ baseMs?: number;
174
+ maxMs?: number;
175
+ };
176
+ /** Which environment scheduled runs execute in. Default `main`. */
177
+ environment?: Environment;
178
+ /** How often schedules are re-derived from documents. Default 15 minutes. */
179
+ reconcileMs?: number;
180
+ /** Names this replica in the job history. Defaults to the pid and a random suffix. */
181
+ workerId?: string;
182
+ onError?: (error: unknown) => void;
183
+ };
184
+ /**
185
+ * How the server reaches a space's connectors: the manifest that describes one, and the credential it authenticates
186
+ * with. Shaped as `ConnectorLookups` in `@plitzi/sdk-server`; typed loosely here so the shared types stay free of the
187
+ * server's internals.
188
+ *
189
+ * Top-level, and not under `action`, because BOTH directions need them. Supplying them is what makes the write
190
+ * endpoint able to authorize a write — a write can only be checked against a manifest — and it is also all the server
191
+ * needs to answer a server-driven element's READ, so `adapters.getRscData` is derived from them unless a deployment
192
+ * supplies its own. They lived under `action` when writes were the only caller, which left every deployment building
193
+ * that read half by hand out of `createConnectorResolver` and `resolveRscData` — from these very lookups, passed a
194
+ * second time.
195
+ */
196
+ export type ConnectorLookupsConfig = {
197
+ getConnector: (spaceId: number, connectorId: string, at?: SpaceRevision) => Promise<unknown>;
198
+ getCredential?: (spaceId: number, identifier: string) => Promise<Record<string, string> | undefined>;
199
+ fetchImpl?: typeof fetch;
200
+ };
201
+ export type SSRHealthConfig = {
202
+ path?: string;
203
+ /** Replaces the identity payload entirely. `check` still merges over it. */
204
+ payload?: Record<string, unknown>;
205
+ name?: string;
206
+ version?: string;
207
+ role?: string;
208
+ /**
209
+ * Which of the servers that answer with this name this one is — a project's copy in another folder, a replica —
210
+ * answered as `Instance`: a tool reaching a port tells the server it meant from another of the same name by it.
211
+ */
212
+ instance?: string;
213
+ /**
214
+ * Live state, read on every probe and merged over the payload — the stores this process depends on, a queue
215
+ * depth, whatever only this deployment can know. Returning `healthy: false` answers **503**, which is what turns
216
+ * the endpoint from a liveness check into a readiness one: an orchestrator stops routing to a replica whose
217
+ * database has gone, instead of sending it traffic it can only fail.
218
+ *
219
+ * A check that throws is itself an unhealthy answer, and is reported as one rather than as a 500.
220
+ */
221
+ check?: () => Record<string, unknown> | Promise<Record<string, unknown>>;
222
+ };
223
+ /** Response compression. Every field has a default; supply only what this deployment wants different. */
224
+ export type SSRCompressionConfig = {
225
+ /**
226
+ * Which encodings this server will use, most preferred first — the first one the client accepts wins. Default
227
+ * `['br', 'gzip']`. `['gzip']` for a client or proxy that mishandles Brotli; `[]` disables compression, same as
228
+ * `compression: false`.
229
+ */
230
+ encodings?: ('br' | 'gzip')[];
231
+ /** Responses smaller than this many bytes go out uncompressed. Default 1024. */
232
+ threshold?: number;
233
+ /**
234
+ * Brotli quality, 0–11, for a body compressed on every request — a page rendered for this request alone. Default 5:
235
+ * 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
236
+ * 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.
237
+ */
238
+ brotliQuality?: number;
239
+ /**
240
+ * Brotli quality, 0–11, for a body compressed once and kept — a cached page, a static file such as the SDK bundle.
241
+ * Default 6: paid once, and every later response is that much smaller (the SDK bundle 10% under quality 4), for
242
+ * the same memory as 4. 9 needs ~40 MB more to compress the bundle, which a 128 MB server does not have; 10 and
243
+ * 11 cost seconds, which the request that fills the cache would wait for.
244
+ */
245
+ keptBrotliQuality?: number;
246
+ /** Gzip level, 0–9. Default 6. */
247
+ gzipLevel?: number;
248
+ };
249
+ export type SSRRscConfig = {
250
+ /** Whether the RSC endpoint is active. Defaults to true when adapters.getRscData is provided. */
251
+ enabled?: boolean;
252
+ /** URL path for the RSC endpoint. Defaults to '/_rsc'. */
253
+ path?: string;
254
+ /** Server-side cache TTL for RSC responses in milliseconds. Defaults to 30 000. Set to 0 to disable. */
255
+ cacheTtlMs?: number;
256
+ /**
257
+ * How long ONE server element may take before the page is answered without it. Defaults to 5 000.
258
+ *
259
+ * It is the page's ceiling, and it wins over the producer's own: an action may be allowed ten seconds of its
260
+ * own (`action.limits.timeoutMs`) and still be cut off here, because a section is worth waiting for only as
261
+ * long as the visitor is. Whichever is tighter decides, and now that the budget CANCELS what it stops waiting
262
+ * for, being cut here ends the run rather than leaving it to finish for nobody.
263
+ *
264
+ * Raise it for a deployment whose sections are genuinely slow and worth the wait; lower it to keep a page fast
265
+ * at the cost of showing more empty sections when a provider is having a bad day.
266
+ */
267
+ elementTimeoutMs?: number;
268
+ };
269
+ /**
270
+ * What the requests a space's documents write may reach from inside this server — a server provider's `query`, an
271
+ * action's `http.request`, a connector, a function's `fetch`, a plugin's address.
272
+ *
273
+ * Each is typed by whoever edits a space and sent from a trusted network position, so none reaches a private address
274
+ * (`localhost`, this server's own network, the cloud's metadata) — but the deployment's own storage, CDN or API may sit
275
+ * on that network, put there by whoever runs it. Those origins are named here, and only they are reached.
276
+ */
277
+ export type SSROutboundConfig = {
278
+ /**
279
+ * Origins on this server's own network a space's requests may reach: `http://localhost:9000` for a local S3, the
280
+ * cluster's `http://api.internal` — an origin (`scheme://host:port`), no path. Everything else private stays closed.
281
+ */
282
+ privateOrigins?: string[];
283
+ };
284
+ export type SSRServerConfig = {
285
+ port?: number;
286
+ host?: string;
287
+ httpVersion?: 1 | 2 | 3;
288
+ tls?: {
289
+ key: Buffer | string;
290
+ cert: Buffer | string;
291
+ minVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
292
+ };
293
+ environment?: ServerEnvironment;
294
+ /** Served to anyone who asks, as it is: pictures, a favicon, what a page fetches in the browser. */
295
+ publicDir?: string;
296
+ /**
297
+ * The project's own data, never served as files: a provider resolved on the server (`runtime: 'server'`) whose
298
+ * `query` is `/data/<file>` reads `<dataDir>/<file>`, and the page arrives with it. Nobody downloads the folder; what
299
+ * a provider reads goes into the page it renders, though — data a page must not carry is a server action's to read,
300
+ * answering only what is shown: a function reads it with `ctx.data('<file>')`. It is the space's data lookup
301
+ * (`action.lookups.getData`) when the deployment gives none.
302
+ */
303
+ dataDir?: string;
304
+ static?: Record<string, string>;
305
+ devMode?: boolean;
306
+ /**
307
+ * Every page this server renders listens for what changes under it: new documents for the space it shows, swapped
308
+ * where it stands (`updatePages`), or everything loaded again (`reloadPages`) — the edit loop of a project that
309
+ * authors its space in code, a page an agent keeps rewriting (`createAuthoringHost`). Off unless asked for, `devMode`
310
+ * included: each open page holds a connection to the server for it, which a server whose space never changes under
311
+ * it would only pay for.
312
+ */
313
+ livePages?: boolean;
314
+ /** Authorizes debugging on the pages this server renders. An SSR page loads the very same SDK, so this is the
315
+ * server-side face of the SDK's `debugMode` prop: the page decides, and the visitor's 'plitzi_debug' cookie can
316
+ * only narrow it. Left unset, `devMode` authorizes it — a development server debugs without being told to — and
317
+ * so does a space whose settings switched `devTools` on. Set, it decides for every space: `false` is a refusal
318
+ * no space can turn around. */
319
+ debugMode?: boolean;
320
+ /**
321
+ * The feature flags this deployment decides, by name — the `server` layer: above what each space declares, below
322
+ * the SDK embedding a page and a tester with the dev tools. Only for flags a space declares; an override of one it
323
+ * does not is ignored, and the page says so in its console.
324
+ *
325
+ * A function when one server renders several spaces and they do not share their flags: it is asked per render.
326
+ */
327
+ flags?: Record<string, boolean> | ((space: {
328
+ spaceId: number;
329
+ environment: Environment;
330
+ }) => Record<string, boolean>);
331
+ cacheTtlMs?: number;
332
+ loginPath?: string | false;
333
+ middlewares?: SSRMiddleware[];
334
+ logoutPath?: string | false;
335
+ /** Where a page signs its person out on every device (`endSessions`). Defaults to `/auth/logout-everywhere`. */
336
+ logoutEverywherePath?: string | false;
337
+ /** Where a browser-obtained credential is handed over. Defaults to `/auth/exchange`; served only when the
338
+ * `exchangeCredential` adapter is supplied. */
339
+ exchangePath?: string | false;
340
+ /**
341
+ * Signing visitors in by redirect, through an OAuth 2.1 authorization server — see {@link SSRSignInConfig}. Served
342
+ * only with the `exchangeCredential` adapter, which is what turns what comes back into a session on this host.
343
+ */
344
+ signIn?: SSRSignInConfig;
345
+ /**
346
+ * The sign-in this server's pages are told about (`server.auth`), so a space that declares no `userProvider` signs
347
+ * in with nothing to declare. `createServer({ auth })` fills it from the kernel's `basePath`; name it yourself when
348
+ * the `/auth` flows are served by another host. The session hint cookie is added per request, named for the host.
349
+ */
350
+ pageAuth?: Omit<ServerAuth, 'sessionHintCookie'>;
351
+ /** Naming and scope of the session cookies this server writes. See {@link SSRAuthCookie}. */
352
+ authCookie?: SSRAuthCookie;
353
+ templateFn?: SSRTemplateFn;
354
+ plugins?: Record<string, PluginSource>;
355
+ /** Where the plugins it builds are kept. Default: `tmp/.sdk-plugins` under the working directory. */
356
+ pluginsCacheDir?: string;
357
+ pluginsTtlMs?: number;
358
+ /** Auto-download and cache plugins declared in the schema's offlineData.plugins list. Default: true. */
359
+ autoLoadSchemaPlugins?: boolean;
360
+ /**
361
+ * What the requests a space's documents write may reach from inside this server. See {@link SSROutboundConfig}.
362
+ */
363
+ outbound?: SSROutboundConfig;
364
+ /** Where this deployment serves the font files a space uploaded — see {@link SSRFontsConfig}. */
365
+ fonts?: SSRFontsConfig;
366
+ /** Remote pictures resized by this server — see {@link SSRImagesConfig}. Absent, images keep their own `src`. */
367
+ images?: SSRImagesConfig;
368
+ /** Omit client-side JS from the rendered page — useful for verifying SSR HTML without hydration. Default: false. */
369
+ ssrOnly?: boolean;
370
+ /** Stream HTML to the client as React renders, reducing TTFB. Default: false. */
371
+ streaming?: boolean;
372
+ /** Controls iframe embedding via CSP frame-ancestors (and X-Frame-Options for legacy browsers).
373
+ * 'DENY' — no site may embed this server (default).
374
+ * 'SAMEORIGIN' — only the same origin may embed it.
375
+ * string[] — explicit list of allowed origins, e.g. ['https://app.example.com', 'https://preview.example.com'].
376
+ * false — no restriction; headers are omitted. */
377
+ frameOptions?: 'DENY' | 'SAMEORIGIN' | string[] | false;
378
+ /** RSC (React Server Components) endpoint configuration. */
379
+ rsc?: SSRRscConfig;
380
+ /** Write endpoint for server-driven providers. Absent means the server serves reads only. */
381
+ action?: SSRActionConfig;
382
+ /**
383
+ * The server's code: its own (`native`), the server halves of the plugins it ships (`plugins`, by plugin type), the
384
+ * runner the spaces' code runs on, and the ceilings. Built by `@plitzi/sdk-server/functions` (`loadFunctions`), and
385
+ * checked as the server starts.
386
+ */
387
+ functions?: {
388
+ native?: unknown[];
389
+ plugins?: Record<string, unknown>;
390
+ runner?: unknown;
391
+ limits?: Record<string, number>;
392
+ /** What the spaces' jobs may spend, per space (its plan): see `FunctionJobLimits` in `@plitzi/sdk-server/functions`. */
393
+ jobs?: {
394
+ limitsFor?: (spaceId: number) => Promise<Record<string, unknown> | undefined>;
395
+ };
396
+ /** `ctx.oauth`: where providers send a visitor back — see `FunctionsConfig` in `@plitzi/sdk-server/functions`. */
397
+ oauth?: {
398
+ callbackOrigin?: string;
399
+ };
400
+ };
401
+ /** Realtime channels the spaces declare — see {@link SSRRealtimeConfig}. On, in memory, when absent. */
402
+ realtime?: SSRRealtimeConfig;
403
+ /**
404
+ * The writes a page of another origin may cause here. None, by default: a browser's POST, PUT, PATCH or DELETE that it
405
+ * says a page of another origin caused (`Sec-Fetch-Site` `cross-site` or `same-site` — another port of this host, a
406
+ * sibling sub-domain — or a foreign `Origin`) is refused 403 `reason: 'foreign'` —
407
+ * a session cookie or none, because a server holding credentials of its own, or a tool nobody signs in to, acts for
408
+ * whoever reaches it. A request with `Authorization`, and one that is not a browser's (a webhook, a script), are never
409
+ * asked. With `auth`, the deployment's `identity.platformOrigins` count as its own too.
410
+ */
411
+ crossSiteWrites?: {
412
+ /** Origins whose pages may write here, exactly as a browser sends them — `https://app.example.com`. */
413
+ origins?: string[];
414
+ /** Paths any origin may post to: a form other sites embed by design. */
415
+ paths?: (path: string) => boolean;
416
+ };
417
+ /** Connector manifest and credential lookups — see {@link ConnectorLookupsConfig}. They serve the RSC read path
418
+ * and the `/_action` write endpoint alike; without them neither can reach a connector. */
419
+ connectors?: ConnectorLookupsConfig;
420
+ /** Receives a {@link ServerLogEvent} for every HTTP request this server answers — whatever stage answered it
421
+ * and whatever the outcome — plus every MCP tool call and resource read inside those requests. Without it the
422
+ * server reports nothing per request (the MCP events still reach the console when `MCP_DEBUG=1`). Everything
423
+ * else the server has to say — a failure, a plugin rebuilt — comes here too as a `message` event, and goes to the
424
+ * console when there is no logger. */
425
+ logger?: ServerLogger;
426
+ /**
427
+ * The least severe thing worth saying — see {@link LogLevel}. `error` by default, `info` with `devMode`: a server
428
+ * in production reports what went wrong and nothing else, unless asked. A request that was answered is `info`, one
429
+ * that failed `error`; a refused action is `warn`. Below the level nothing is built, so a quiet server pays nothing
430
+ * per request for the log it is not keeping.
431
+ */
432
+ logLevel?: LogLevel | 'silent';
433
+ /**
434
+ * How responses are compressed. Omit for Brotli where the client takes it and gzip otherwise; `false` never
435
+ * compresses, which is what to use when a proxy or CDN in front already does it.
436
+ */
437
+ compression?: SSRCompressionConfig | false;
438
+ /**
439
+ * What to do when the server cannot take its port. Without it the server prints what went wrong, what to do about
440
+ * it, and exits non-zero — because a process whose server never bound is not running, and the alternative is a raw
441
+ * `EADDRINUSE` stack that says nothing about which port or which server.
442
+ *
443
+ * Supply this to keep the process alive and decide for yourself: an embedder that starts several servers, a
444
+ * supervisor that retries, a test that asserts the failure. Handling it here replaces the exit entirely.
445
+ */
446
+ onListenError?: (error: NodeJS.ErrnoException, context: {
447
+ port: number;
448
+ host: string;
449
+ label: string;
450
+ }) => void;
451
+ /**
452
+ * How many processes serve this port. Node runs JavaScript on one thread, so one process renders on one core however
453
+ * many the machine has; each worker is a whole server of its own, and the connections are spread between them —
454
+ * more requests a second, and less time waiting behind another render.
455
+ *
456
+ * `true` / `'auto'`: one per core the process may actually use (a container's CPU quota included). `false`: one
457
+ * process. A number: that many, lowered to the cores there are (more only take turns on the same cores). Default: on
458
+ * under `NODE_ENV=production`, off otherwise — a development server and a test runner stay one process. The
459
+ * `SDK_SERVER_WORKERS` environment variable sets it when this does not.
460
+ *
461
+ * The workers are one server — one replica — and behave as one:
462
+ *
463
+ * - The stores kept in memory by default (an action's `kv`, the job queue, draft previews, the sign-in rate
464
+ * limit) are the primary's, and each worker reaches them over the cluster channel. A store the deployment
465
+ * supplies (Redis, a table) is used as it is.
466
+ * - The scheduler and the job consumers run in one worker only, so a schedule fires once and `jobs.workers` is the
467
+ * whole server's concurrency; if that worker dies, its replacement takes them over.
468
+ * - `server.cache.invalidate()`, `server.plugins.register()` and `server.plugins.invalidate()` reach every worker,
469
+ * whichever process calls them.
470
+ *
471
+ * Per worker: the rendered-page cache (each renders a page once), the plugin components, and the action run caps
472
+ * (`action.concurrency`: `perSpace`, `perProcess`, `renderPerProcess`), which a cluster of replicas already counts
473
+ * per replica. A plugin registered with a `component` stays in the process that registered it — register those
474
+ * where the server is created.
475
+ */
476
+ workers?: boolean | number | 'auto';
477
+ adapters: SSRAdapters;
478
+ /** Which request-handling services this server mounts: `ssr` on by default, `rsc` whenever
479
+ * `adapters.getRscData` exists. Stages a companion package contributes are deliberately NOT flags here —
480
+ * handing them over is the decision. Only createServer reads these as written; the surface factories pin what
481
+ * their name promises (a page server serves pages; a dedicated MCP server serves MCP alone). */
482
+ services?: ServerServices;
483
+ /** Liveness/readiness endpoint for standalone servers (k8s probes). A stage always answers `path`
484
+ * (default /health) with the generic identity payload built from `name`/`version`/`role`
485
+ * ({ Server, Version, role }); pass an explicit `payload` to override it entirely, or `check` to add what can
486
+ * only be known per request. See {@link SSRHealthConfig}. */
487
+ health?: SSRHealthConfig;
488
+ /** Cache-buster appended as ?v=<assetVersion> to all default SDK asset URLs (jsPath, cssPath, react vendor). Compute from file mtime or package version at startup. */
489
+ assetVersion?: string;
490
+ /** The draft-preview endpoint, and the store behind it. The draft is WRITTEN by an MCP tool and RENDERED here,
491
+ * so this is the one piece of that feature the page server owns: `@plitzi/sdk-mcp` carries everything else in
492
+ * its own options, and a deployment that never installs it leaves both unset.
493
+ *
494
+ * `preview` mounts the endpoint (off unless `enabled`); `draftStore` backs the tokens and defaults to an
495
+ * in-memory store — inject a shared one (e.g. Redis) for multi-replica correctness. */
496
+ preview?: SSRPreviewConfig;
497
+ draftStore?: DraftStore;
498
+ };
499
+ /** The same config as seen by a server that serves PAGES: its adapters answer for a page request. This is what
500
+ * `createServer` from `@plitzi/sdk-server` takes and what the SSR stages are handed, so a page stage reaches
501
+ * `getOfflineData` without asking whether it is there — while a stage typed to the bare context (anything from
502
+ * `@plitzi/sdk-mcp`, which also runs in servers that have neither) still has to check. */
503
+ /**
504
+ * A visitor signs in somewhere else and comes back signed in HERE: `GET <path>?return=/somewhere` sends them to the
505
+ * authorization server, and `GET <path>/callback` takes the code it answers with, redeems it server to server and
506
+ * hands the token to `exchangeCredential` — which is what makes the session, on this host, for this space.
507
+ *
508
+ * This server registers itself with the authorization server (RFC 7591) as the host the visitor is on, and proves the
509
+ * exchange with PKCE. The state travels in a `__Host-` cookie, which no sibling host can set: a sign-in somebody else
510
+ * started cannot be finished in this browser.
511
+ */
512
+ export type SSRSignInConfig = {
513
+ /** What `exchangeCredential` knows the tokens by. */
514
+ provider: string;
515
+ /** Where the visitor's browser is sent: the authorization server's `/authorize`, as the public reaches it. */
516
+ authorizeUrl: string;
517
+ /** Where this server registers itself and redeems codes — reachable from here, which may be a private address. */
518
+ registerUrl: string;
519
+ tokenUrl: string;
520
+ /** What to ask for, for the space being signed into. */
521
+ scope: (spaceId: number) => string;
522
+ /** Where the flow answers. Default `/auth/sign-in`; the authorization server sends people back to `<path>/callback`. */
523
+ path?: string;
524
+ };
525
+ export type SSRPageServerConfig = SSRServerConfig & {
526
+ adapters: SSRPageAdapters;
527
+ };
File without changes
@@ -0,0 +1,119 @@
1
+ import { ActionRejectReason, ActionRunStatus, ActionTriggerType } from './ActionTypes';
2
+ import { Environment } from './CommonTypes';
3
+ /** What every log event carries, whatever layer it came from. */
4
+ /**
5
+ * How much a server says, from least to most: each level includes every one above it. `error` is what a production
6
+ * server shows unless told otherwise — something went wrong — and `warn`, `info` (every request answered, every
7
+ * plugin built) and `debug` are asked for. `silent` says nothing at all.
8
+ */
9
+ export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
10
+ type ServerLogEventBase = {
11
+ /** Wall-clock duration of the work the event describes, in milliseconds. */
12
+ durationMs: number;
13
+ /** False when the work threw or answered an error status. */
14
+ ok: boolean;
15
+ /** The error message when `ok` is false — never the request payload. */
16
+ error?: string;
17
+ /** ISO-8601 timestamp of when the event was emitted. */
18
+ timestamp: string;
19
+ };
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 {};
File without changes