@plitzi/sdk-actions 0.0.0-stage → 0.39.3

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 (168) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +54 -2
  3. package/dist/chunks/credentials-DwxZeAvH.mjs +27 -0
  4. package/dist/chunks/errors-bCBfIe7c.mjs +54 -0
  5. package/dist/chunks/grants-BsD-WlLE.mjs +168 -0
  6. package/dist/chunks/load-DBWRZn7G.mjs +48 -0
  7. package/dist/chunks/module-WdDzbjHy.mjs +7032 -0
  8. package/dist/chunks/queueDocument-xYz-KZ5V.mjs +21 -0
  9. package/dist/chunks/queueRules-BCCVgeUE.mjs +487 -0
  10. package/dist/chunks/remote-DopPgCMK.mjs +404 -0
  11. package/dist/chunks/storeClock-Btm7EaVm.mjs +31 -0
  12. package/dist/chunks/taskCatalog-S1IozUTD.mjs +201 -0
  13. package/dist/connectors/connectors.d.ts +7 -0
  14. package/dist/connectors/engine.d.ts +47 -0
  15. package/dist/connectors/getByPath.d.ts +8 -0
  16. package/dist/connectors/projection.d.ts +18 -0
  17. package/dist/connectors/resolver.d.ts +27 -0
  18. package/dist/connectors/types.d.ts +19 -0
  19. package/dist/engine/configSeam.d.ts +10 -0
  20. package/dist/engine/connectorWrite.d.ts +12 -0
  21. package/dist/engine/fileStore.d.ts +60 -0
  22. package/dist/engine/fleet.d.ts +20 -0
  23. package/dist/engine/jobs/calls.d.ts +49 -0
  24. package/dist/engine/jobs/claimSpaces.d.ts +10 -0
  25. package/dist/engine/jobs/codeMarks.d.ts +10 -0
  26. package/dist/engine/jobs/endings.d.ts +42 -0
  27. package/dist/engine/jobs/failureStreak.d.ts +15 -0
  28. package/dist/engine/jobs/fileQueue.d.ts +34 -0
  29. package/dist/engine/jobs/flow.d.ts +11 -0
  30. package/dist/engine/jobs/jobs.d.ts +36 -0
  31. package/dist/engine/jobs/later.d.ts +27 -0
  32. package/dist/engine/jobs/memoryNeeds.d.ts +24 -0
  33. package/dist/engine/jobs/memoryQueue.d.ts +33 -0
  34. package/dist/engine/jobs/memoryWatch.d.ts +21 -0
  35. package/dist/engine/jobs/notNow.d.ts +39 -0
  36. package/dist/engine/jobs/queueDocument.d.ts +15 -0
  37. package/dist/engine/jobs/queueRules.d.ts +64 -0
  38. package/dist/engine/jobs/scheduler.d.ts +70 -0
  39. package/dist/engine/jobs/schedules.d.ts +24 -0
  40. package/dist/engine/jobs/storeClock.d.ts +16 -0
  41. package/dist/engine/jobs/wake.d.ts +6 -0
  42. package/dist/engine/jobs/worker.d.ts +99 -0
  43. package/dist/engine/module.d.ts +96 -0
  44. package/dist/engine/moduleFor.d.ts +3 -0
  45. package/dist/engine/runtime/check.d.ts +24 -0
  46. package/dist/engine/runtime/credentials.d.ts +8 -0
  47. package/dist/engine/runtime/deadline.d.ts +19 -0
  48. package/dist/engine/runtime/email.d.ts +38 -0
  49. package/dist/engine/runtime/errors.d.ts +28 -0
  50. package/dist/engine/runtime/fileKv.d.ts +35 -0
  51. package/dist/engine/runtime/flags.d.ts +16 -0
  52. package/dist/engine/runtime/guards.d.ts +190 -0
  53. package/dist/engine/runtime/kvList.d.ts +28 -0
  54. package/dist/engine/runtime/kvStore.d.ts +36 -0
  55. package/dist/engine/runtime/limits.d.ts +12 -0
  56. package/dist/engine/runtime/memoryKv.d.ts +28 -0
  57. package/dist/engine/runtime/namespaceKv.d.ts +9 -0
  58. package/dist/engine/runtime/precheck.d.ts +28 -0
  59. package/dist/engine/runtime/rateLimit.d.ts +9 -0
  60. package/dist/engine/runtime/redisKv.d.ts +27 -0
  61. package/dist/engine/runtime/renderFailure.d.ts +24 -0
  62. package/dist/engine/runtime/renderResolver.d.ts +16 -0
  63. package/dist/engine/runtime/renderShare.d.ts +12 -0
  64. package/dist/engine/runtime/report.d.ts +15 -0
  65. package/dist/engine/runtime/runAction.d.ts +26 -0
  66. package/dist/engine/runtime/runLogger.d.ts +37 -0
  67. package/dist/engine/runtime/runStats.d.ts +8 -0
  68. package/dist/engine/runtime/scope.d.ts +40 -0
  69. package/dist/engine/runtime/signing.d.ts +27 -0
  70. package/dist/engine/runtime/taskContext.d.ts +54 -0
  71. package/dist/engine/runtime/triggers.d.ts +12 -0
  72. package/dist/engine/taskCatalog.d.ts +28 -0
  73. package/dist/engine/tasks/auth.d.ts +2 -0
  74. package/dist/engine/tasks/builtins.d.ts +10 -0
  75. package/dist/engine/tasks/connector.d.ts +2 -0
  76. package/dist/engine/tasks/db.d.ts +2 -0
  77. package/dist/engine/tasks/email.d.ts +2 -0
  78. package/dist/engine/tasks/flow.d.ts +3 -0
  79. package/dist/engine/tasks/helpers.d.ts +16 -0
  80. package/dist/engine/tasks/http.d.ts +2 -0
  81. package/dist/engine/tasks/kv.d.ts +2 -0
  82. package/dist/engine/tasks/list.d.ts +2 -0
  83. package/dist/engine/tasks/names.d.ts +8 -0
  84. package/dist/engine/tasks/realtime.d.ts +3 -0
  85. package/dist/engine/tasks/registry.d.ts +19 -0
  86. package/dist/engine/tasks/transform.d.ts +2 -0
  87. package/dist/engine/transport/callHandler.d.ts +34 -0
  88. package/dist/engine/transport/cancelHandler.d.ts +23 -0
  89. package/dist/engine/transport/catalogHandler.d.ts +22 -0
  90. package/dist/engine/transport/stream.d.ts +22 -0
  91. package/dist/engine/transport/verifySignature.d.ts +16 -0
  92. package/dist/engine/transport/webhookHandler.d.ts +26 -0
  93. package/dist/engine/types.d.ts +442 -0
  94. package/dist/functions/build.d.ts +27 -0
  95. package/dist/functions/capabilities.d.ts +11 -0
  96. package/dist/functions/config.d.ts +111 -0
  97. package/dist/functions/context.d.ts +15 -0
  98. package/dist/functions/index.d.ts +17 -0
  99. package/dist/functions/index.mjs +461 -0
  100. package/dist/functions/jobControl.d.ts +22 -0
  101. package/dist/functions/jobs.d.ts +104 -0
  102. package/dist/functions/load.d.ts +22 -0
  103. package/dist/functions/local.d.ts +36 -0
  104. package/dist/functions/manifest.d.ts +32 -0
  105. package/dist/functions/native.d.ts +13 -0
  106. package/dist/functions/oauth.d.ts +33 -0
  107. package/dist/functions/routes.d.ts +50 -0
  108. package/dist/functions/runner/remote.d.ts +26 -0
  109. package/dist/functions/scope.d.ts +28 -0
  110. package/dist/functions/space.d.ts +41 -0
  111. package/dist/functions/tryEntry.d.ts +9 -0
  112. package/dist/index.d.ts +47 -0
  113. package/dist/index.mjs +545 -0
  114. package/dist/mongo/claimable.d.ts +5 -0
  115. package/dist/mongo/index.d.ts +4 -0
  116. package/dist/mongo/index.mjs +779 -0
  117. package/dist/mongo/jobQueue.d.ts +38 -0
  118. package/dist/mongo/kv.d.ts +15 -0
  119. package/dist/mysql/index.d.ts +5 -0
  120. package/dist/mysql/index.mjs +808 -0
  121. package/dist/mysql/jobQueue.d.ts +40 -0
  122. package/dist/mysql/kv.d.ts +18 -0
  123. package/dist/mysql/rows.d.ts +64 -0
  124. package/dist/mysql/schema.d.ts +28 -0
  125. package/dist/mysql/summary.d.ts +7 -0
  126. package/dist/realtime/declarations.d.ts +11 -0
  127. package/dist/realtime/failure.d.ts +6 -0
  128. package/dist/realtime/grants.d.ts +22 -0
  129. package/dist/realtime/handlers.d.ts +86 -0
  130. package/dist/realtime/hub.d.ts +71 -0
  131. package/dist/realtime/index.d.ts +105 -0
  132. package/dist/realtime/index.mjs +824 -0
  133. package/dist/realtime/jobs.d.ts +18 -0
  134. package/dist/realtime/message.d.ts +3 -0
  135. package/dist/realtime/presence.d.ts +33 -0
  136. package/dist/realtime/retained.d.ts +21 -0
  137. package/dist/realtime/socket.d.ts +30 -0
  138. package/dist/render/index.d.ts +10 -0
  139. package/dist/render/index.mjs +1 -0
  140. package/dist/render/protocol.d.ts +47 -0
  141. package/dist/render/remote.d.ts +16 -0
  142. package/dist/runtimes/bundle.d.ts +29 -0
  143. package/dist/runtimes/index.d.ts +3 -0
  144. package/dist/runtimes/index.mjs +229 -0
  145. package/dist/runtimes/stages.d.ts +52 -0
  146. package/dist/sqlite/index.d.ts +4 -0
  147. package/dist/sqlite/index.mjs +160 -0
  148. package/dist/sqlite/jobQueue.d.ts +35 -0
  149. package/dist/sqlite/kv.d.ts +34 -0
  150. package/dist/sqlite/open.d.ts +3 -0
  151. package/dist/types/config.d.ts +293 -0
  152. package/dist/types/index.d.ts +2 -0
  153. package/dist/types/index.mjs +1 -0
  154. package/dist/types/jobs.d.ts +317 -0
  155. package/dist/worker/elsewhere.d.ts +16 -0
  156. package/dist/worker/index.d.ts +5 -0
  157. package/dist/worker/index.mjs +1703 -0
  158. package/dist/worker/origin.d.ts +12 -0
  159. package/dist/worker/pageEngine.d.ts +11 -0
  160. package/dist/worker/stages/action.d.ts +24 -0
  161. package/dist/worker/stages/cors.d.ts +9 -0
  162. package/dist/worker/stages/forward.d.ts +12 -0
  163. package/dist/worker/stages/functionRoutes.d.ts +10 -0
  164. package/dist/worker/stages/queuedCalls.d.ts +15 -0
  165. package/dist/worker/stages/realtime.d.ts +9 -0
  166. package/dist/worker/stages/render.d.ts +9 -0
  167. package/dist/worker/worker.d.ts +39 -0
  168. package/package.json +76 -3
@@ -0,0 +1,190 @@
1
+ import { MemoryReading } from '@plitzi/sdk-kernel/stats';
2
+ import { ActionCallResult } from '@plitzi/sdk-shared';
3
+ /**
4
+ * Which budget a run draws on.
5
+ *
6
+ * `call` is somebody ASKING for work — a click, a webhook, a schedule — and one space's callers hammering is a
7
+ * problem that belongs to that space. `render` is somebody LOOKING at a page, which is traffic: it scales with
8
+ * how popular the space is, and a ceiling per space would cap a successful page rather than an abusive one.
9
+ */
10
+ export type RunKind = 'call' | 'render';
11
+ /** A run currently holding a slot, and the handle that can stop it. */
12
+ /** What a run answered its caller: the call's result, and the reason a step wrote for the caller when it refused. */
13
+ export type RunAnswer = ActionCallResult & {
14
+ error?: string;
15
+ };
16
+ export type ActiveRun = {
17
+ runId: string;
18
+ runKey: string;
19
+ kind: RunKind;
20
+ spaceId: number;
21
+ actionId: string;
22
+ callerId: string;
23
+ controller: AbortController;
24
+ expiresAt: number;
25
+ /**
26
+ * Whether the caller NAMED this run's key rather than having it derived from what they sent.
27
+ *
28
+ * It is what decides whether the answer may be replayed: a sender that stamps a delivery id is telling us which
29
+ * request this is, so answering the retry with the first result is exactly right. A derived key is a hash of
30
+ * the input, and two identical calls a minute apart are usually two things somebody meant to happen twice.
31
+ */
32
+ explicitKey: boolean;
33
+ /**
34
+ * What the run answers, once it ends — `undefined` for one that ended with no answer (it threw): what a second
35
+ * identical call while it runs waits for, instead of being refused (`join`).
36
+ */
37
+ answered: Promise<RunAnswer | undefined>;
38
+ /** Settles `answered`: called by `end`. */
39
+ settle: (outcome: RunAnswer | undefined) => void;
40
+ };
41
+ /**
42
+ * The half of a key/value store the guards need, and nothing more.
43
+ *
44
+ * The same methods `ActionKvAdapter` already declares, so a deployment that configured `action.kv` has already
45
+ * provided this: no second store to stand up, and no adapter change. `increment` is what takes a single-flight
46
+ * key; `get`/`set` are what carry a cancellation and a replayable answer between replicas.
47
+ */
48
+ export type RunKeyStore = {
49
+ get: (key: string) => Promise<string | undefined>;
50
+ set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
51
+ increment: (key: string, amount: number) => Promise<number>;
52
+ expire: (key: string, ttlSeconds: number) => Promise<void>;
53
+ delete: (key: string) => Promise<void>;
54
+ };
55
+ export type RunGuardsConfig = {
56
+ /**
57
+ * Concurrent CALLS one space may have in flight — its fair share of the process: a job worker gives it more of the
58
+ * slots no other space's work waits for (`spare`), keeping this many free for the next that comes. Renders are not
59
+ * counted here — see {@link RunKind}.
60
+ */
61
+ perSpace?: number;
62
+ /** Concurrent calls this process will carry, across every space. */
63
+ perProcess?: number;
64
+ /**
65
+ * Concurrent RENDERS this process will carry, across every space — the only ceiling renders have.
66
+ *
67
+ * What a render threatens is the box, never the space it belongs to: five hundred people reading one page at
68
+ * once is that page working. So this is sized for a machine, and it is the number a deployment tunes when it
69
+ * knows its own — the default is deliberately generous, and each slot is held for at most one run's timeout.
70
+ */
71
+ renderPerProcess?: number;
72
+ /**
73
+ * The share of the process's memory limit past which it starts no new run, of either kind: 0.85 by default.
74
+ *
75
+ * The slot ceilings count runs, not what they hold, and runs reading large answers fill a process long before its
76
+ * slots do. Refusing the next run is what keeps the process alive for the runs already in it.
77
+ */
78
+ memoryShare?: number;
79
+ /** How the process's memory is read: by default its resident memory against {@link processMemoryLimit}. */
80
+ readMemory?: () => MemoryReading;
81
+ };
82
+ export type BeginRunParams = {
83
+ spaceId: number;
84
+ actionId: string;
85
+ callerId: string;
86
+ input: Record<string, unknown>;
87
+ idempotencyKey?: string;
88
+ /**
89
+ * The key names the WORK, not who asked.
90
+ *
91
+ * True only for a webhook, where the key is the SENDER's delivery id and the signature that let the request in
92
+ * is what authenticated it: the same delivery retried from another of a provider's addresses is the same
93
+ * delivery, and scoping it per caller would run it twice.
94
+ *
95
+ * Everywhere else the key is a string the caller made up, so it is scoped to them. Without that, a visitor who
96
+ * learns or guesses another's key collides with their single-flight and — where a deployment set a replay
97
+ * window — is handed the answer their run produced.
98
+ */
99
+ sharedKey?: boolean;
100
+ ttlMs: number;
101
+ /** Which budget this run draws on. Defaults to `call`: a trigger that says nothing is somebody asking. */
102
+ kind?: RunKind;
103
+ /**
104
+ * Taken in a slot this process had spare — no other space's work waiting for it (`room().spare`): counted against
105
+ * the process, never against its space's share (`perSpace`). A job worker's, which knows what waits.
106
+ */
107
+ spare?: boolean;
108
+ };
109
+ /** What a deployment may set about replaying a finished run. Off unless it says otherwise. */
110
+ export type RunIdempotency = {
111
+ replayTtlMs?: number;
112
+ };
113
+ export type RunGuards = {
114
+ begin: (params: BeginRunParams) => Promise<ActiveRun>;
115
+ /**
116
+ * The answer of the run this same call already started in this process, waited for — `undefined` when none runs
117
+ * here (another replica holds it, or it ended). A page that calls the same action with the same input twice at once
118
+ * (loaded at two widths, two tabs, two components) is answered twice by one run, never refused: a run's room logged
119
+ * a 409 on every second load, and acceptance checks failed on it at random.
120
+ */
121
+ join: (params: BeginRunParams) => Promise<RunAnswer | undefined> | undefined;
122
+ /** Releases the key, and — for a run the caller keyed itself — remembers the answer for {@link RunIdempotency}. */
123
+ end: (run: ActiveRun, outcome?: RunAnswer) => Promise<void>;
124
+ get: (runId: string) => ActiveRun | undefined;
125
+ /** The answer a run with this key already produced, when it is still within the replay window. */
126
+ replay: (params: BeginRunParams) => Promise<ActionCallResult | undefined>;
127
+ /** Stops a run: here if this process holds it, and through the store if another one does. */
128
+ cancel: (runId: string, callerId: string) => Promise<boolean>;
129
+ active: () => number;
130
+ /** Runs in flight against what this process takes at once, by kind: what its stats report as its slots. */
131
+ slots: () => {
132
+ calls: {
133
+ used: number;
134
+ of: number;
135
+ };
136
+ renders: {
137
+ used: number;
138
+ of: number;
139
+ };
140
+ };
141
+ /**
142
+ * The room this process has for more calls: how many more it takes, the spaces already at their share, and how many it
143
+ * may take past a share while no other space's work waits (`spare`) — what a job worker claims by, so it never takes a
144
+ * job only to hand it back refused, nor leaves a slot idle that a waiting job could have.
145
+ */
146
+ room: () => {
147
+ calls: number;
148
+ fullSpaces: number[];
149
+ spare: number;
150
+ };
151
+ };
152
+ export declare const DEFAULT_GUARDS: {
153
+ perSpace: number;
154
+ perProcess: number;
155
+ renderPerProcess: number;
156
+ memoryShare: number;
157
+ };
158
+ /**
159
+ * Where a cancellation is left for whichever replica is actually running the flow.
160
+ *
161
+ * Exported because the RUNNER is what reads it, at every step boundary, and the two must not each spell the key
162
+ * their own way — a cancel written under one name and read under another is a stop button that does nothing.
163
+ */
164
+ export declare const runCancelKey: (runId: string) => string;
165
+ export declare const deriveRunKey: ({ spaceId, actionId, callerId, input, idempotencyKey, sharedKey }: BeginRunParams) => string;
166
+ /**
167
+ * Single-flight, concurrency caps and cancellation, in one place.
168
+ *
169
+ * The client engine already refuses re-entry — `InteractionsManager` drops a trigger that fires while its own flow
170
+ * is still running — and this is the same rule keyed by what identifies a RUN rather than a DOM event. Without it
171
+ * a client that retries, reconnects or simply double-clicks turns one intent into many runs, and a streaming
172
+ * caller can turn it into an unbounded loop.
173
+ *
174
+ * **What is shared and what is not**, when a store is handed over:
175
+ *
176
+ * - **Single-flight is**, because per replica it is not a guarantee at all: the same double-click behind a load
177
+ * balancer lands on two of them and both run. The key is taken with `increment`, which is the one atomic
178
+ * test-and-set every adapter already has to provide — the holder is whoever's increment answered `1` — and it
179
+ * carries the run's own timeout as its lifetime, so a replica that dies holding one frees it by expiring.
180
+ * - **The caps are not.** Counting them across replicas needs a decrementing counter, and a run that dies without
181
+ * decrementing throttles a healthy space until somebody notices. A ceiling that is per replica is a number a
182
+ * deployment can multiply and reason about; one that leaks is not. So `perSpace` is per replica, deliberately,
183
+ * and a cluster's real ceiling is that times the number of them.
184
+ * - **Cancellation is**, in one direction. Only the process running a flow holds the `AbortController` that stops
185
+ * it, so a `DELETE` that lands anywhere else leaves a FLAG in the store and the run reads it at its next step
186
+ * boundary. Behind a load balancer that is the normal case rather than the exotic one: the tab that wants to
187
+ * stop a checkout almost never reaches the replica running it.
188
+ * - **A finished answer is**, when the caller named the key and the deployment set a replay window.
189
+ */
190
+ export declare const createRunGuards: (config?: RunGuardsConfig, store?: RunKeyStore, idempotency?: RunIdempotency) => RunGuards;
@@ -0,0 +1,28 @@
1
+ import { KvListEntry, KvListPutOptions, KvListRange } from '@plitzi/sdk-shared/functions';
2
+ /**
3
+ * The most a list holds. A list is one value of the store, read and written whole, so it is for what a page shows at
4
+ * once — the latest twenty, a leaderboard, a gallery — not for a table.
5
+ */
6
+ export declare const MAX_LIST_ENTRIES = 500;
7
+ /**
8
+ * Its largest size, as JSON. Every store holds far more; this is what a list is read and written whole for — a page's
9
+ * worth of entries, each an id and what the page shows — and past it, a list is being used as a table.
10
+ */
11
+ export declare const MAX_LIST_BYTES = 128000;
12
+ /**
13
+ * Why an id is no list entry's — said with the id refused and the marks allowed quoted: "… : _ . @ -" ending the line
14
+ * read as cut short, and a run's id with a '|' took three rounds to find.
15
+ */
16
+ export declare const listIdProblem: (id: unknown) => string | undefined;
17
+ /** The entries a stored list holds — none for a key that holds nothing, or something that is not a list. */
18
+ export declare const parseList: (raw: string | undefined) => KvListEntry[];
19
+ /**
20
+ * The list with `entry` in it — replacing the one with its id — sorted and cut to the highest `keep`, and what the cut
21
+ * dropped; `undefined` when `higherOnly` keeps the one there. Refused, with what to do instead, when the result would
22
+ * be larger than a list may be.
23
+ */
24
+ export declare const withEntry: (entries: KvListEntry[], entry: KvListEntry, { keep, higherOnly }?: KvListPutOptions) => {
25
+ kept: KvListEntry[];
26
+ dropped: KvListEntry[];
27
+ } | undefined;
28
+ export declare const rangeOf: (entries: KvListEntry[], { offset, limit, order }?: KvListRange) => KvListEntry[];
@@ -0,0 +1,36 @@
1
+ import { ActionKvAdapter } from '../types';
2
+ import { ActionKvStore } from '@plitzi/sdk-shared/functions';
3
+ export type KvStoreConfig = {
4
+ /**
5
+ * Prefixed onto every key before it reaches the adapter. Defaults to `kv:`.
6
+ *
7
+ * The store a deployment hands over usually holds other things — a page cache, a session index — and a flow
8
+ * writing `visits:home` must not be able to land on one of them.
9
+ */
10
+ prefix?: string;
11
+ };
12
+ /**
13
+ * The `kv` tasks, over whatever a deployment gave them to write into.
14
+ *
15
+ * The adapter is transport: strings in, strings out. Everything a counter's BEHAVIOUR depends on is here, in one
16
+ * place, for every deployment at once — which is the point of the split. Three rules:
17
+ *
18
+ * 1. **Values round-trip through JSON**, so a flow reads back what it wrote instead of its own `toString`. A value
19
+ * written by something else is answered as the string it is rather than failing.
20
+ * 2. **A counter's TTL is set once, by whoever created it, and never extended.** A window refreshed on every hit
21
+ * never closes while traffic keeps arriving — which is a rate limit that stops limiting exactly when it is
22
+ * being leant on. The counter is the one that created it precisely when the increment returns its own amount,
23
+ * so this needs no conditional-expire support from the adapter and works the same on Redis, Memcached or a
24
+ * table.
25
+ * 3. **Nothing is caught.** This is not a cache: a miss means the rate limit did not count and the idempotency key
26
+ * was not seen, so an adapter that cannot answer fails the run rather than being read as "no value".
27
+ *
28
+ * A list is one value, changed only by `swap`: read, change, write back if nobody wrote in between, and read again if
29
+ * somebody did. Every adapter can do that much, so lists work on all of them without a command of their own. They
30
+ * live under `list:` rather than beside the values, so no key a flow writes can be one.
31
+ */
32
+ /** What every key is prefixed with unless the store was given another. */
33
+ export declare const DEFAULT_KV_PREFIX = "kv:";
34
+ /** Where a list lives, after the prefix: its own segment, so a list and a value of the same name never meet. */
35
+ export declare const LIST_SEGMENT = "list:";
36
+ export declare const createKvStore: (adapter: ActionKvAdapter, { prefix }?: KvStoreConfig) => ActionKvStore;
@@ -0,0 +1,12 @@
1
+ import { ResolvedActionLimits } from '../types';
2
+ import { ActionLimits } from '@plitzi/sdk-shared';
3
+ export declare const DEFAULT_LIMITS: ResolvedActionLimits;
4
+ /**
5
+ * Merges a document's limits, and its space's, over the deployment's.
6
+ *
7
+ * Each may only ever TIGHTEN: the deployment is the party paying for the connection, the slot and the outbound
8
+ * traffic. The space's are what its plan sells (`ActionsConfig.limitsFor`) — up to the deployment's, never past them —
9
+ * and an authored document is customer input. Letting either widen would make every ceiling advisory — which is the
10
+ * same as not having one.
11
+ */
12
+ export declare const resolveLimits: (deployment?: ActionLimits, document?: ActionLimits, space?: ActionLimits) => ResolvedActionLimits;
@@ -0,0 +1,28 @@
1
+ import { ActionKvAdapter } from '../types';
2
+ import { StoreMethods } from '@plitzi/sdk-kernel/http';
3
+ /** A value and, when it has one, the instant (epoch ms) it stops being one. */
4
+ export type KvEntry = {
5
+ value: string;
6
+ expiresAt?: number;
7
+ };
8
+ /** Every method of the store, for the copy a server's workers share (`FleetStores`, `core/server/fleet/link.ts`). */
9
+ export declare const KV_METHODS: StoreMethods<ActionKvAdapter>;
10
+ /**
11
+ * The store's rules over a map somebody holds: what `createMemoryKv` is, and what a store that keeps the map
12
+ * somewhere (`createFileKv`) is too — so the two answer identically and differ only in where the map lives.
13
+ *
14
+ * An adapter like any other: it stores strings and obeys no rules of its own. What a counter DOES lives in
15
+ * `createKvStore`, so the in-process store and a deployment's own behave identically rather than nearly so.
16
+ *
17
+ * `changed` is told after every write that changed the map — an expired entry swept or read past included.
18
+ */
19
+ export declare const createMapKv: (entries: Map<string, KvEntry>, changed?: () => void) => ActionKvAdapter;
20
+ /**
21
+ * The `kv` tasks' fallback store: in this process, and nowhere else — gone when it stops.
22
+ *
23
+ * Real enough for a single replica and for local work, and deliberately not pretending otherwise — a deployment
24
+ * running several replicas passes an adapter over something shared, because a counter that only counts its own
25
+ * replica is a rate limit that multiplies by the number of them. One that must survive a restart passes
26
+ * `createFileKv` (one process) or `createSqliteKv` (`@plitzi/sdk-actions/sqlite`).
27
+ */
28
+ export declare const createMemoryKv: () => ActionKvAdapter;
@@ -0,0 +1,9 @@
1
+ import { ActionKvStore } from '@plitzi/sdk-shared/functions';
2
+ /** Every key `store` is asked for, under `prefix`: a space's own keys, or a plugin's inside the space's. */
3
+ export declare const prefixKv: (store: ActionKvStore, prefix: string) => ActionKvStore;
4
+ export declare const namespaceKv: (store: ActionKvStore, spaceId: number) => ActionKvStore;
5
+ /**
6
+ * Every key a space's store holds, as patterns over the adapter's keys (`createKvStore`'s `prefix`, `kv:` unless it was
7
+ * given another) — for whoever has to let all of them go at once: a space that is deleted, or reset to how it started.
8
+ */
9
+ export declare const spaceKvPatterns: (spaceId: number, prefix?: string) => string[];
@@ -0,0 +1,28 @@
1
+ import { ActionEntry, ActionTriggerType, ElementInteraction, RunUser } from '@plitzi/sdk-shared';
2
+ export type PrecheckParams = {
3
+ trigger: ActionTriggerType;
4
+ input: Record<string, unknown>;
5
+ /** Who asks, as the session named them — or, for a call kept in the queue, as it named them then. */
6
+ user?: RunUser;
7
+ /** Chain of run ids that caused this one. A run naming its own action is a loop. */
8
+ lineage?: string[];
9
+ };
10
+ /** The entry point that was cleared, and the input that survived its contract. */
11
+ export type PrecheckResult = {
12
+ trigger: ElementInteraction;
13
+ values: Record<string, unknown>;
14
+ };
15
+ /**
16
+ * Everything that decides whether a run may happen at all, before it costs anything.
17
+ *
18
+ * One implementation, two callers, on purpose. The RUNNER calls it because a deployment mounting its own trigger
19
+ * goes straight there, and a check that lived only in the endpoint would be a check a custom trigger silently
20
+ * skips. The ENDPOINT calls it first because these are pure and cheap, and a refusal that has already taken a
21
+ * concurrency slot and a metering event teaches callers to retry harder for something that was never going to run.
22
+ *
23
+ * Everything it reads about the caller — may they, and with what — is on the TRIGGER STEP, so an action reachable
24
+ * both by a signed webhook and by a page call answers each on its own terms instead of on the loosest of the two.
25
+ *
26
+ * Returns the entry point and the coerced input, so neither caller has to find or validate either twice.
27
+ */
28
+ export declare const precheckRun: (entry: ActionEntry, params: PrecheckParams) => PrecheckResult;
@@ -0,0 +1,9 @@
1
+ import { RateCount, RateLimit, ActionKvStore } from '@plitzi/sdk-shared/functions';
2
+ /**
3
+ * Counts one more of `bucket` in the current window and says whether it was within the limit — the one count behind
4
+ * the `flow.rateLimit` step and a function's `ctx.rateLimit`, so a flow and code limiting the same bucket count
5
+ * together. Refusing is the caller's: a step refuses the run, a function decides what to answer.
6
+ */
7
+ export declare const countRate: (kv: ActionKvStore, callerId: string, bucket: string, { most, perSeconds, per }: RateLimit) => Promise<RateCount>;
8
+ /** A count past its limit, refused with the limit's own words when it says some; within it, or with none, as counted. */
9
+ export declare const refusedOver: (count: RateCount, limit: RateLimit) => RateCount;
@@ -0,0 +1,27 @@
1
+ import { ActionKvAdapter } from '../types';
2
+ /**
3
+ * The commands this adapter sends, typed by shape rather than by a client library: ioredis answers them as they are,
4
+ * and any client that speaks them does. `eval` is for `swap`, the one operation Redis has no single command for.
5
+ */
6
+ export type RedisKvClient = {
7
+ get: (key: string) => Promise<string | null>;
8
+ set: {
9
+ (key: string, value: string): Promise<unknown>;
10
+ (key: string, value: string, mode: 'EX', seconds: number): Promise<unknown>;
11
+ };
12
+ del: (key: string) => Promise<number>;
13
+ incrby: (key: string, amount: number) => Promise<number>;
14
+ expire: (key: string, seconds: number) => Promise<number>;
15
+ eval: (script: string, keys: number, ...args: (string | number)[]) => Promise<unknown>;
16
+ };
17
+ export type RedisKvOptions = {
18
+ /** Put in front of every key, for a Redis that holds other things too. None when absent. */
19
+ prefix?: string;
20
+ };
21
+ /**
22
+ * An {@link ActionKvAdapter} over Redis: each operation one command, and `swap` one script.
23
+ *
24
+ * `client` may be a function, for a deployment whose connection comes and goes — it is asked on every call, and a
25
+ * client it cannot give is its to refuse (throwing), never this adapter's to read as "no value".
26
+ */
27
+ export declare const createRedisKv: (client: RedisKvClient | (() => RedisKvClient), { prefix }?: RedisKvOptions) => ActionKvAdapter;
@@ -0,0 +1,24 @@
1
+ import { ActionRunSummary } from '@plitzi/sdk-shared';
2
+ /**
3
+ * A render run that resolved nothing, carrying what it did.
4
+ *
5
+ * The slice is withheld all the same — `resolveRscData` reads the rejection as the element's error state — but the
6
+ * steps travel with the error, so a page allowed to debug is still shown where the flow broke.
7
+ */
8
+ export declare class RenderRunFailure extends Error {
9
+ readonly summary: ActionRunSummary;
10
+ /**
11
+ * The action answered this visitor with a refusal (`ActionRefusal`): a room closed, data that is another's — the
12
+ * action doing its job, said as a warning, never an error with its stack (a run's log, a guest's every page).
13
+ */
14
+ readonly refused: boolean;
15
+ /**
16
+ * A refusal's own words, written for whoever called: what the element shows the visitor, alone — never the log's
17
+ * line around them ("Action … ended as failed, refused (code): …"), which a page had to split to show.
18
+ */
19
+ readonly said?: string;
20
+ constructor(message: string, summary: ActionRunSummary, options?: ErrorOptions & {
21
+ refused?: boolean;
22
+ said?: string;
23
+ });
24
+ }
@@ -0,0 +1,16 @@
1
+ import { ActionsModule } from '../module';
2
+ import { ActionLookups } from '../types';
3
+ import { RscElementResolver } from '@plitzi/sdk-kernel/engine';
4
+ /**
5
+ * Resolves a `runtime: 'server'` element that names an ACTION rather than a connector.
6
+ *
7
+ * This is the read a manifest cannot express: two calls that have to be joined, a field computed from both, a
8
+ * shape that depends on who is looking. The element names an action exactly as it would name a connector, and the
9
+ * page still learns nothing about what happens on the other side.
10
+ *
11
+ * Its input is the page's own context — route params, then query params — plus whatever the element declares, so
12
+ * an action feeding `/blog/:slug` reads `{{ input.slug }}` and needs nothing else; a refresh's own params (what
13
+ * `reloadApi` or a bound `input` asked for) come last and win. The action's own input contract still drops everything
14
+ * it did not declare.
15
+ */
16
+ export declare const createActionResolver: (lookups: ActionLookups, module: ActionsModule) => RscElementResolver;
@@ -0,0 +1,12 @@
1
+ export type RenderShare = {
2
+ /**
3
+ * Runs `produce`, or joins whatever is already producing the same key. `ttlMs` of 0 keeps nothing afterwards.
4
+ *
5
+ * `signal` is this caller's: aborted, the caller stops waiting — and the run is stopped (`produce`'s own signal)
6
+ * only once every caller waiting on it has. One visitor who gave up must not cost the others their answer.
7
+ */
8
+ run: (key: string, ttlMs: number, produce: (signal: AbortSignal) => Promise<unknown>, signal?: AbortSignal) => Promise<unknown>;
9
+ /** Entries currently held, for a deployment that wants to see it. */
10
+ size: () => number;
11
+ };
12
+ export declare const createRenderShare: (now?: () => number) => RenderShare;
@@ -0,0 +1,15 @@
1
+ import { EngineServerConfig } from '../../types';
2
+ import { ActionRejectRecord } from '@plitzi/sdk-shared';
3
+ /**
4
+ * Reports a request that never became a run.
5
+ *
6
+ * Its own function rather than a call at each refusal so the two transports cannot end up reporting different
7
+ * things — and so the rule that a report may not fail the answer is written once. A deployment's sink throwing
8
+ * must not turn a clean 401 into a 500: the caller was refused either way, and the refusal is the part that has
9
+ * to reach them.
10
+ *
11
+ * Nothing is filtered here. A duplicate delivery is a well-behaved sender retrying and an invalid signature is a
12
+ * broken integration, but which of those is worth a row in somebody's activity feed is a policy, and policies
13
+ * belong to the deployment.
14
+ */
15
+ export declare const reportReject: (config: EngineServerConfig, record: ActionRejectRecord) => Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { TaskContextRequest } from './taskContext';
2
+ import { FunctionJobsService } from '../../functions/jobs';
3
+ import { JobQueue } from '../../types';
4
+ import { ActionRunRequest, ActionRunResult, ActionsConfig, ActionTaskContext, ActionTaskRegistry } from '../types';
5
+ export type ActionRunner = {
6
+ runAction: (request: ActionRunRequest) => Promise<ActionRunResult>;
7
+ };
8
+ /**
9
+ * What a function answering a route runs with: the context a run's step gets — the same stores, the same redaction, the
10
+ * same outbound budget under the deployment's ceilings — for work that is not a flow.
11
+ */
12
+ export type TaskContextSource = (request: TaskContextRequest, signal: AbortSignal, lineage: string[]) => Omit<ActionTaskContext, 'log'>;
13
+ /**
14
+ * Builds the runner every trigger goes through.
15
+ *
16
+ * Every check that decides whether a run may happen at all — the trigger and whether it is on, access, lineage,
17
+ * input contract — lives HERE rather than in a transport, because a deployment mounting its own trigger calls this
18
+ * directly. A check in the endpoint would be a check a custom trigger silently skips.
19
+ */
20
+ export declare const createActionRunner: (config: ActionsConfig, registryFor: (request: ActionRunRequest) => ActionTaskRegistry | Promise<ActionTaskRegistry>, baseFetch?: typeof fetch,
21
+ /** The queue runs set for later go into, read when asked: it is made after the runner, and a server may run none. */
22
+ jobsQueue?: () => JobQueue | undefined,
23
+ /** The space's jobs, for a function's `ctx.jobs` — made beside the runner, and reading back its `taskContext`. */
24
+ functionJobs?: FunctionJobsService) => ActionRunner & {
25
+ taskContext: TaskContextSource;
26
+ };
@@ -0,0 +1,37 @@
1
+ import { ServerLogger } from '@plitzi/sdk-kernel/types';
2
+ import { ActionRejectRecord, ActionRunRecord } from '@plitzi/sdk-shared';
3
+ /**
4
+ * `onRun`, wired into the log stream the server already reports through.
5
+ *
6
+ * Without an `onRun` a deployment gets nothing at all about its flows: the request log says a call was answered,
7
+ * and a run started by a webhook or a schedule has no request to say anything about. This is the smallest useful
8
+ * answer to that, and it needs no store — whatever sink is already collecting `ServerLogEvent`s (a console, a
9
+ * file, a log shipper) starts carrying runs too, because a run is emitted as one more event on the same stream.
10
+ *
11
+ * What it reports is the SHAPE of the run — which steps ran and how each ended — and never what they held. A
12
+ * deployment that wants run HISTORY rather than run logs keeps its own `onRun` and writes rows; the two compose,
13
+ * since `onRun` is one function.
14
+ *
15
+ * Held to the server's `logLevel` like everything else on the stream: a run that completed is `debug` — or `warn` when it
16
+ * was slow (`SLOW_RUN_MS`) — and one that did not is `error`.
17
+ *
18
+ * Never throws: the runner treats the record as best-effort, and a logging outage must not take an action down.
19
+ */
20
+ export declare const createRunLogger: (logger: ServerLogger) => (record: ActionRunRecord) => void;
21
+ /**
22
+ * `onReject`, wired into the same log stream.
23
+ *
24
+ * The refusals are the half a deployment notices it is missing at the worst possible moment: an integration is
25
+ * being set up, every delivery is answered 401, and nothing anywhere says which check refused it. This puts them
26
+ * on the stream the server already reports through, as their own `kind` so a sink can route them somewhere
27
+ * louder than a run.
28
+ *
29
+ * It carries no body, no signature and no header — what went wrong is `reason`, and `detail` is the server's own
30
+ * words about it.
31
+ *
32
+ * A refusal is a `warn`: the caller was turned away, the server did not fail.
33
+ *
34
+ * Never throws, for the same reason the run logger does not: the caller was refused either way, and a sink's
35
+ * problem must not become the response's.
36
+ */
37
+ export declare const createRejectLogger: (logger: ServerLogger) => (record: ActionRejectRecord) => void;
@@ -0,0 +1,8 @@
1
+ import { ActionRunRecord } from '../types';
2
+ import { StatsRecorder } from '@plitzi/sdk-kernel/stats';
3
+ /**
4
+ * The deployment's `onRun` with the process's stats fed first (`stats`): each run's duration, how it ended, and
5
+ * which action of which space it was — what a slow minute on the pools' screen is traced back to.
6
+ * A stats update cannot throw, so the deployment's own record is never kept from running.
7
+ */
8
+ export declare const recordedRun: (stats: StatsRecorder, onRun?: (record: ActionRunRecord) => void | Promise<void>) => (record: ActionRunRecord) => Promise<void>;
@@ -0,0 +1,40 @@
1
+ import { ActionCredential } from '../types';
2
+ import { ActionField, RunUser } from '@plitzi/sdk-shared';
3
+ export type FieldValidation = {
4
+ values: Record<string, unknown>;
5
+ missing: string[];
6
+ invalid: string[];
7
+ };
8
+ /**
9
+ * Coerces a value bag against declared fields.
10
+ *
11
+ * Undeclared keys are DROPPED rather than passed through, and this is what makes twig-in-params safe: every token
12
+ * a node interpolates resolves against values that survived a contract someone wrote down. A pass-through bag
13
+ * would let a caller inject whatever a template happens to reference.
14
+ */
15
+ export declare const applyFields: (fields: Record<string, ActionField>, raw: Record<string, unknown>) => FieldValidation;
16
+ /** The visitor as a flow sees them. The token is deliberately absent — see the `auth.currentUser` task. */
17
+ export declare const projectUser: (user?: RunUser) => {
18
+ id: number;
19
+ username: string;
20
+ email: string;
21
+ verified: boolean;
22
+ permissions: string[];
23
+ roles: string[];
24
+ } | undefined;
25
+ /**
26
+ * Redacts every secret the run has actually resolved, wherever it appears, at any depth.
27
+ *
28
+ * Keyed on the VALUES rather than on field names, because a secret does not stay in the field it came from: it
29
+ * travels into a header a node built, into an error a provider echoed back, and from there into the trace and the
30
+ * log. Matching names would redact the one place it was already safe.
31
+ *
32
+ * It learns as the run goes rather than being built up front from a declared list. That is what makes dropping
33
+ * the declaration safe: a credential is registered the moment the task that needed it resolved one, which is
34
+ * always before that task's own result is redacted — and what was never resolved was never at risk.
35
+ */
36
+ export declare const createRedactor: () => {
37
+ /** Everything long enough to be a secret rather than a flag. Short values would redact ordinary text. */
38
+ add: (credential: ActionCredential) => void;
39
+ redact: <T>(value: T) => T;
40
+ };
@@ -0,0 +1,27 @@
1
+ /** A space's signatures: made with a key of its own that the server keeps, which its code never holds. */
2
+ export type SpaceSigning = {
3
+ /** HMAC-SHA-256 of `value` with the space's key, base64url. */
4
+ sign: (value: string) => Promise<string>;
5
+ /** Whether `signature` is what `sign` answers for `value` — compared in constant time. */
6
+ verify: (value: string, signature: string) => Promise<boolean>;
7
+ /**
8
+ * `value` encrypted (AES-256-GCM) with a key of the space's own that no signature reaches: what the platform keeps for
9
+ * a space and its code must not read — an OAuth token in the space's `kv`. base64url, a fresh IV each time.
10
+ */
11
+ seal: (value: string) => string;
12
+ /** What `seal` encrypted — `undefined` for anything it did not, or that was changed since. */
13
+ open: (sealed: string) => string | undefined;
14
+ };
15
+ /** A signing secret is what every link and key a space hands out stands on: as long as a 256-bit key written out. */
16
+ export declare const MIN_SIGNING_SECRET_LENGTH = 32;
17
+ /**
18
+ * Signing for every space, from the one secret the deployment holds (`signingSecret`).
19
+ *
20
+ * Each space and environment signs with a key derived from it, never with the secret itself: what one space signed
21
+ * another cannot vouch for, nor production for what a preview signed. Every replica derives the same keys from the
22
+ * same secret, so a signature made on one is verified on any.
23
+ */
24
+ export declare const createSigning: (secret: string) => ({ spaceId, environment }: {
25
+ spaceId: number;
26
+ environment: string;
27
+ }) => SpaceSigning;