@plitzi/sdk-actions 0.0.0-stage → 0.39.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +54 -2
- package/dist/chunks/credentials-DwxZeAvH.mjs +27 -0
- package/dist/chunks/errors-bCBfIe7c.mjs +54 -0
- package/dist/chunks/grants-BsD-WlLE.mjs +168 -0
- package/dist/chunks/load-DBWRZn7G.mjs +48 -0
- package/dist/chunks/module-WdDzbjHy.mjs +7032 -0
- package/dist/chunks/queueDocument-xYz-KZ5V.mjs +21 -0
- package/dist/chunks/queueRules-BCCVgeUE.mjs +487 -0
- package/dist/chunks/remote-DopPgCMK.mjs +404 -0
- package/dist/chunks/storeClock-Btm7EaVm.mjs +31 -0
- package/dist/chunks/taskCatalog-S1IozUTD.mjs +201 -0
- package/dist/connectors/connectors.d.ts +7 -0
- package/dist/connectors/engine.d.ts +47 -0
- package/dist/connectors/getByPath.d.ts +8 -0
- package/dist/connectors/projection.d.ts +18 -0
- package/dist/connectors/resolver.d.ts +27 -0
- package/dist/connectors/types.d.ts +19 -0
- package/dist/engine/configSeam.d.ts +10 -0
- package/dist/engine/connectorWrite.d.ts +12 -0
- package/dist/engine/fileStore.d.ts +60 -0
- package/dist/engine/fleet.d.ts +20 -0
- package/dist/engine/jobs/calls.d.ts +49 -0
- package/dist/engine/jobs/claimSpaces.d.ts +10 -0
- package/dist/engine/jobs/codeMarks.d.ts +10 -0
- package/dist/engine/jobs/endings.d.ts +42 -0
- package/dist/engine/jobs/failureStreak.d.ts +15 -0
- package/dist/engine/jobs/fileQueue.d.ts +34 -0
- package/dist/engine/jobs/flow.d.ts +11 -0
- package/dist/engine/jobs/jobs.d.ts +36 -0
- package/dist/engine/jobs/later.d.ts +27 -0
- package/dist/engine/jobs/memoryNeeds.d.ts +24 -0
- package/dist/engine/jobs/memoryQueue.d.ts +33 -0
- package/dist/engine/jobs/memoryWatch.d.ts +21 -0
- package/dist/engine/jobs/notNow.d.ts +39 -0
- package/dist/engine/jobs/queueDocument.d.ts +15 -0
- package/dist/engine/jobs/queueRules.d.ts +64 -0
- package/dist/engine/jobs/scheduler.d.ts +70 -0
- package/dist/engine/jobs/schedules.d.ts +24 -0
- package/dist/engine/jobs/storeClock.d.ts +16 -0
- package/dist/engine/jobs/wake.d.ts +6 -0
- package/dist/engine/jobs/worker.d.ts +99 -0
- package/dist/engine/module.d.ts +96 -0
- package/dist/engine/moduleFor.d.ts +3 -0
- package/dist/engine/runtime/check.d.ts +24 -0
- package/dist/engine/runtime/credentials.d.ts +8 -0
- package/dist/engine/runtime/deadline.d.ts +19 -0
- package/dist/engine/runtime/email.d.ts +38 -0
- package/dist/engine/runtime/errors.d.ts +28 -0
- package/dist/engine/runtime/fileKv.d.ts +35 -0
- package/dist/engine/runtime/flags.d.ts +16 -0
- package/dist/engine/runtime/guards.d.ts +190 -0
- package/dist/engine/runtime/kvList.d.ts +28 -0
- package/dist/engine/runtime/kvStore.d.ts +36 -0
- package/dist/engine/runtime/limits.d.ts +12 -0
- package/dist/engine/runtime/memoryKv.d.ts +28 -0
- package/dist/engine/runtime/namespaceKv.d.ts +9 -0
- package/dist/engine/runtime/precheck.d.ts +28 -0
- package/dist/engine/runtime/rateLimit.d.ts +9 -0
- package/dist/engine/runtime/redisKv.d.ts +27 -0
- package/dist/engine/runtime/renderFailure.d.ts +24 -0
- package/dist/engine/runtime/renderResolver.d.ts +16 -0
- package/dist/engine/runtime/renderShare.d.ts +12 -0
- package/dist/engine/runtime/report.d.ts +15 -0
- package/dist/engine/runtime/runAction.d.ts +26 -0
- package/dist/engine/runtime/runLogger.d.ts +37 -0
- package/dist/engine/runtime/runStats.d.ts +8 -0
- package/dist/engine/runtime/scope.d.ts +40 -0
- package/dist/engine/runtime/signing.d.ts +27 -0
- package/dist/engine/runtime/taskContext.d.ts +54 -0
- package/dist/engine/runtime/triggers.d.ts +12 -0
- package/dist/engine/taskCatalog.d.ts +28 -0
- package/dist/engine/tasks/auth.d.ts +2 -0
- package/dist/engine/tasks/builtins.d.ts +10 -0
- package/dist/engine/tasks/connector.d.ts +2 -0
- package/dist/engine/tasks/db.d.ts +2 -0
- package/dist/engine/tasks/email.d.ts +2 -0
- package/dist/engine/tasks/flow.d.ts +3 -0
- package/dist/engine/tasks/helpers.d.ts +16 -0
- package/dist/engine/tasks/http.d.ts +2 -0
- package/dist/engine/tasks/kv.d.ts +2 -0
- package/dist/engine/tasks/list.d.ts +2 -0
- package/dist/engine/tasks/names.d.ts +8 -0
- package/dist/engine/tasks/realtime.d.ts +3 -0
- package/dist/engine/tasks/registry.d.ts +19 -0
- package/dist/engine/tasks/transform.d.ts +2 -0
- package/dist/engine/transport/callHandler.d.ts +34 -0
- package/dist/engine/transport/cancelHandler.d.ts +23 -0
- package/dist/engine/transport/catalogHandler.d.ts +22 -0
- package/dist/engine/transport/stream.d.ts +22 -0
- package/dist/engine/transport/verifySignature.d.ts +16 -0
- package/dist/engine/transport/webhookHandler.d.ts +26 -0
- package/dist/engine/types.d.ts +442 -0
- package/dist/functions/build.d.ts +27 -0
- package/dist/functions/capabilities.d.ts +11 -0
- package/dist/functions/config.d.ts +111 -0
- package/dist/functions/context.d.ts +15 -0
- package/dist/functions/index.d.ts +17 -0
- package/dist/functions/index.mjs +461 -0
- package/dist/functions/jobControl.d.ts +22 -0
- package/dist/functions/jobs.d.ts +104 -0
- package/dist/functions/load.d.ts +22 -0
- package/dist/functions/local.d.ts +36 -0
- package/dist/functions/manifest.d.ts +32 -0
- package/dist/functions/native.d.ts +13 -0
- package/dist/functions/oauth.d.ts +33 -0
- package/dist/functions/routes.d.ts +50 -0
- package/dist/functions/runner/remote.d.ts +26 -0
- package/dist/functions/scope.d.ts +28 -0
- package/dist/functions/space.d.ts +41 -0
- package/dist/functions/tryEntry.d.ts +9 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.mjs +545 -0
- package/dist/mongo/claimable.d.ts +5 -0
- package/dist/mongo/index.d.ts +4 -0
- package/dist/mongo/index.mjs +779 -0
- package/dist/mongo/jobQueue.d.ts +38 -0
- package/dist/mongo/kv.d.ts +15 -0
- package/dist/mysql/index.d.ts +5 -0
- package/dist/mysql/index.mjs +808 -0
- package/dist/mysql/jobQueue.d.ts +40 -0
- package/dist/mysql/kv.d.ts +18 -0
- package/dist/mysql/rows.d.ts +64 -0
- package/dist/mysql/schema.d.ts +28 -0
- package/dist/mysql/summary.d.ts +7 -0
- package/dist/realtime/declarations.d.ts +11 -0
- package/dist/realtime/failure.d.ts +6 -0
- package/dist/realtime/grants.d.ts +22 -0
- package/dist/realtime/handlers.d.ts +86 -0
- package/dist/realtime/hub.d.ts +71 -0
- package/dist/realtime/index.d.ts +105 -0
- package/dist/realtime/index.mjs +824 -0
- package/dist/realtime/jobs.d.ts +18 -0
- package/dist/realtime/message.d.ts +3 -0
- package/dist/realtime/presence.d.ts +33 -0
- package/dist/realtime/retained.d.ts +21 -0
- package/dist/realtime/socket.d.ts +30 -0
- package/dist/render/index.d.ts +10 -0
- package/dist/render/index.mjs +1 -0
- package/dist/render/protocol.d.ts +47 -0
- package/dist/render/remote.d.ts +16 -0
- package/dist/runtimes/bundle.d.ts +29 -0
- package/dist/runtimes/index.d.ts +3 -0
- package/dist/runtimes/index.mjs +229 -0
- package/dist/runtimes/stages.d.ts +52 -0
- package/dist/sqlite/index.d.ts +4 -0
- package/dist/sqlite/index.mjs +160 -0
- package/dist/sqlite/jobQueue.d.ts +35 -0
- package/dist/sqlite/kv.d.ts +34 -0
- package/dist/sqlite/open.d.ts +3 -0
- package/dist/types/config.d.ts +293 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/jobs.d.ts +317 -0
- package/dist/worker/elsewhere.d.ts +16 -0
- package/dist/worker/index.d.ts +5 -0
- package/dist/worker/index.mjs +1703 -0
- package/dist/worker/origin.d.ts +12 -0
- package/dist/worker/pageEngine.d.ts +11 -0
- package/dist/worker/stages/action.d.ts +24 -0
- package/dist/worker/stages/cors.d.ts +9 -0
- package/dist/worker/stages/forward.d.ts +12 -0
- package/dist/worker/stages/functionRoutes.d.ts +10 -0
- package/dist/worker/stages/queuedCalls.d.ts +15 -0
- package/dist/worker/stages/realtime.d.ts +9 -0
- package/dist/worker/stages/render.d.ts +9 -0
- package/dist/worker/worker.d.ts +39 -0
- package/package.json +76 -3
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { ActionEmailSender } from './runtime/email';
|
|
2
|
+
import { SpaceSigning } from './runtime/signing';
|
|
3
|
+
import { FunctionsConfig } from '../functions/config';
|
|
4
|
+
import { ActionJobsConfig, EngineConfig } from '../types';
|
|
5
|
+
import { ProjectDataLookup } from '@plitzi/sdk-kernel/data';
|
|
6
|
+
import { OutboundOptions } from '@plitzi/sdk-kernel/outbound';
|
|
7
|
+
import { ActionEmailConfig, Job, ActionEntry, ActionLimits, ActionRejectRecord, ActionRunRecord, ActionRunLimit, ActionRunStatus, ActionRunStep, ActionTriggerType, ConnectorManifest, Environment, FunctionJobManifest, FunctionJobView, InteractionCallbackParam, InteractionNode, InteractionNodeStatus, RunUser, Schema, SpaceRevision } from '@plitzi/sdk-shared';
|
|
8
|
+
import { ActionKvStore, LaterAnswer, LaterRequest, FunctionJobs, FunctionPresence, FunctionVisitor, SpaceFunctions } from '@plitzi/sdk-shared/functions';
|
|
9
|
+
/** How a deployment runs what a clock starts: the one in `@plitzi/sdk-actions/types`. */
|
|
10
|
+
export type { ActionJobsConfig };
|
|
11
|
+
/** Resolved secret material, as the connector engine already models it. */
|
|
12
|
+
export type ActionCredential = Record<string, string>;
|
|
13
|
+
/**
|
|
14
|
+
* A connector with its secret already resolved.
|
|
15
|
+
*
|
|
16
|
+
* Handed over as one thing because the engine needs both, and a task holding only the manifest would have to go
|
|
17
|
+
* looking for the credential itself — which is exactly the lookup that must not be open to a task. Authorizing
|
|
18
|
+
* the connector authorizes the credential it names: that is what the `/_action` write endpoint has always done.
|
|
19
|
+
*/
|
|
20
|
+
export type ResolvedConnector = {
|
|
21
|
+
manifest: ConnectorManifest;
|
|
22
|
+
credential?: ActionCredential;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A connection to a database that is NOT this deployment's.
|
|
26
|
+
*
|
|
27
|
+
* Registered by the deployment, one per engine it supports, and reached only through a credential the space
|
|
28
|
+
* declared — which is the whole security position of `db.query`: a flow queries a database its owner configured,
|
|
29
|
+
* never the one holding other tenants' spaces.
|
|
30
|
+
*
|
|
31
|
+
* `params` are BOUND, never interpolated. The task refuses a statement containing a template for exactly that
|
|
32
|
+
* reason, and a driver that pastes them into the SQL itself would undo the rule from the other end.
|
|
33
|
+
*/
|
|
34
|
+
export type ActionDbDriver = {
|
|
35
|
+
/** Engine name a credential names, e.g. `mysql`, `postgres`. */
|
|
36
|
+
engine: string;
|
|
37
|
+
query: (dsn: string, sql: string, params: unknown[], signal: AbortSignal) => Promise<unknown[]>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Where a deployment keeps the `kv` tasks' data — Redis, Memcached, a table, whatever it already runs.
|
|
41
|
+
*
|
|
42
|
+
* Deliberately the DUMBEST possible surface: six operations over strings, with no rule to obey. Everything that
|
|
43
|
+
* decides how a counter behaves — the key prefixing, the JSON round trip, and the one rule a rate limit lives or
|
|
44
|
+
* dies by — is `createKvStore`'s, above this. An adapter that had to remember "extend the TTL only when the
|
|
45
|
+
* counter did not exist" would be an adapter each deployment gets to write that rule wrongly in.
|
|
46
|
+
*
|
|
47
|
+
* Making it a seam at all is what keeps rate limiting and idempotency across replicas a deployment's decision
|
|
48
|
+
* rather than a silent no-op: the in-process default counts only its own replica, and honestly says so.
|
|
49
|
+
*/
|
|
50
|
+
export type ActionKvAdapter = {
|
|
51
|
+
/** The stored string, or undefined when the key is absent OR has expired. */
|
|
52
|
+
get: (key: string) => Promise<string | undefined>;
|
|
53
|
+
set: (key: string, value: string, ttlSeconds?: number) => Promise<void>;
|
|
54
|
+
delete: (key: string) => Promise<void>;
|
|
55
|
+
/** Adds to a counter and answers the NEW total. Must be atomic — this is what get-then-set cannot be. */
|
|
56
|
+
increment: (key: string, amount: number) => Promise<number>;
|
|
57
|
+
/** Sets a lifetime on a key that already exists. When to call it is decided above, never here. */
|
|
58
|
+
expire: (key: string, ttlSeconds: number) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Writes `next` only if the key still holds `expected` — or, with `expected` undefined, only if it holds nothing (a
|
|
61
|
+
* key past its lifetime holds nothing). Answers whether it wrote. Must be atomic: it is what lets two writers
|
|
62
|
+
* read, change and write the same value without one of them silently undoing the other.
|
|
63
|
+
*/
|
|
64
|
+
swap: (key: string, expected: string | undefined, next: string, ttlSeconds?: number) => Promise<boolean>;
|
|
65
|
+
};
|
|
66
|
+
/** Re-exported so the module's files import one place. One type for actions and connectors: it is one concept. */
|
|
67
|
+
export type { SpaceRevision } from '@plitzi/sdk-shared';
|
|
68
|
+
/**
|
|
69
|
+
* How the server reaches a space's actions. Structurally identical in spirit to `ConnectorLookups`: the module
|
|
70
|
+
* never learns where a deployment stores anything.
|
|
71
|
+
*/
|
|
72
|
+
export type ActionLookups = {
|
|
73
|
+
getAction: (spaceId: number, actionId: string, at?: SpaceRevision) => Promise<ActionEntry | undefined>;
|
|
74
|
+
/** Only the builder's catalog, the MCP and the scheduler need the list; a page call never asks for it. */
|
|
75
|
+
listActions?: (spaceId: number, at?: SpaceRevision) => Promise<ActionEntry[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Which spaces have something scheduled, for the periodic reconcile.
|
|
78
|
+
*
|
|
79
|
+
* Optional, and a safety net rather than the mechanism: a deployment keeps the schedule rows current by calling
|
|
80
|
+
* `reconcile` whenever a space's actions change, and this is what catches the write that did not happen — a
|
|
81
|
+
* restore from backup, a row edited by hand, a deploy that missed a save. Absent, nothing reconciles on a timer
|
|
82
|
+
* and the rows are exactly as correct as the calls that wrote them.
|
|
83
|
+
*/
|
|
84
|
+
listScheduledSpaces?: () => Promise<number[]>;
|
|
85
|
+
getCredential?: (spaceId: number, identifier: string) => Promise<ActionCredential | undefined>;
|
|
86
|
+
getConnector?: (spaceId: number, connectorId: string, at?: SpaceRevision) => Promise<ConnectorManifest | undefined>;
|
|
87
|
+
/**
|
|
88
|
+
* The space's own functions as of that revision — the bundle and what it declared when saved, run by the deployment's
|
|
89
|
+
* sandbox (`functions.runner`), or by the space's own runtime when it answers one with a `runner` of its own. Only
|
|
90
|
+
* asked when a run names a task the deployment does not have, or a request a path under `/fn/`.
|
|
91
|
+
*/
|
|
92
|
+
getFunctions?: (spaceId: number, at?: SpaceRevision) => Promise<SpaceFunctions | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* The server halves of the plugins the space uses, as of that revision, by plugin type — each built and checked as a
|
|
95
|
+
* plugin's (`prepareFunctions` with its `scope`) and run in the same sandbox as the space's own, with a plugin's
|
|
96
|
+
* narrower `ctx`. Asked like `getFunctions`: for a task the deployment does not have, or a path under
|
|
97
|
+
* `/fn/plugins/<type>/`.
|
|
98
|
+
*/
|
|
99
|
+
getPluginFunctions?: (spaceId: number, at?: SpaceRevision) => Promise<Record<string, SpaceFunctions> | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* The space's own data as of that revision: its files' text by path (`products.json`), for a provider resolved on the
|
|
102
|
+
* server whose `query` is `/data/<file>` and for a function's `ctx.data` — the platform's `dataDir`, and what a
|
|
103
|
+
* self-hosted server derives from its own when it is given none. Absent, neither reads anything here.
|
|
104
|
+
*/
|
|
105
|
+
getData?: ProjectDataLookup;
|
|
106
|
+
/**
|
|
107
|
+
* One person of the space, by username or id — public fields alone (`FunctionVisitor`), and only of someone who
|
|
108
|
+
* belongs to it: what a function's `ctx.visitors.get` reads. Absent, a server with an `auth` of its own answers its
|
|
109
|
+
* accounts; else nobody is read.
|
|
110
|
+
*/
|
|
111
|
+
getVisitor?: (spaceId: number, environment: string, who: string | number) => Promise<FunctionVisitor | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* The feature flags the space declares as of that revision, for a flow that reads `{{ flags.<name> }}`. Only asked
|
|
114
|
+
* for a run whose document names `flags` at all. Absent, such a flow sees no flags — and the server says so.
|
|
115
|
+
*/
|
|
116
|
+
getFlags?: (spaceId: number, at?: SpaceRevision) => Promise<Schema['flags']>;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The only door a task has to the outside world.
|
|
120
|
+
*
|
|
121
|
+
* `credential` and `connector` answer solely for identifiers the running document declared, so a task cannot reach
|
|
122
|
+
* a secret the action did not ask for — the check lives here rather than in each task, where it would be optional.
|
|
123
|
+
* `fetch` is the run's own: abort-wired and counted against the request budget.
|
|
124
|
+
*/
|
|
125
|
+
export type ActionTaskContext = {
|
|
126
|
+
runId: string;
|
|
127
|
+
spaceId: number;
|
|
128
|
+
environment: Environment;
|
|
129
|
+
trigger: ActionTriggerType;
|
|
130
|
+
/** Who is asking, as the session named them — or, for a job's slice, who started it. Never the session itself. */
|
|
131
|
+
user?: RunUser;
|
|
132
|
+
/**
|
|
133
|
+
* Who is asking, as the transport identified them: `user:<id>` for a session, `ip:<address>` for everyone else,
|
|
134
|
+
* and `render` or `schedule` for the runs no visitor started.
|
|
135
|
+
*
|
|
136
|
+
* A task that must happen once per PERSON has nothing else to key on — a `public` action has no session, and an
|
|
137
|
+
* identifier the caller sent is not an identity. Coarse by construction, since a shared address is one caller,
|
|
138
|
+
* and personal data when it is one: a task that stores it is storing that.
|
|
139
|
+
*/
|
|
140
|
+
callerId: string;
|
|
141
|
+
signal: AbortSignal;
|
|
142
|
+
/**
|
|
143
|
+
* Tells the run it waited this long for the platform's capacity — a runner's queue, a turn at its CPU — which is not the
|
|
144
|
+
* run's to spend: its time limit moves by it. Absent where nothing is timed (a function's route keeps its own).
|
|
145
|
+
*/
|
|
146
|
+
waited?: (ms: number) => void;
|
|
147
|
+
/**
|
|
148
|
+
* The flow scope as the current node sees it: `input`, every previous node's result by id, `user`, and the
|
|
149
|
+
* credentials the document declared. Read-only, and present because a `rawParams` task has to render templates
|
|
150
|
+
* against something.
|
|
151
|
+
*/
|
|
152
|
+
scope: Readonly<Record<string, unknown>>;
|
|
153
|
+
credential: (identifier: string) => Promise<ActionCredential | undefined>;
|
|
154
|
+
connector: (connectorId: string) => Promise<ResolvedConnector | undefined>;
|
|
155
|
+
fetch: typeof fetch;
|
|
156
|
+
/**
|
|
157
|
+
* What an authored request may reach from here, handed to `fetchOutbound` with every one: the deployment's own
|
|
158
|
+
* origins on its network (`outbound.privateOrigins`) and nothing else private. Absent, nothing private.
|
|
159
|
+
*/
|
|
160
|
+
outbound?: OutboundOptions;
|
|
161
|
+
/** Key/value storage, namespaced to this space by the runner — a key one space writes is a key only it reads. */
|
|
162
|
+
kv: ActionKvStore;
|
|
163
|
+
/** The database engines this deployment registered, for the `db.query` task. */
|
|
164
|
+
dbDrivers: ActionDbDriver[];
|
|
165
|
+
/** How `email.send` reaches a space's SMTP server, under the deployment's limits. */
|
|
166
|
+
email: ActionEmailSender;
|
|
167
|
+
/** Pushes a `data` frame to a streaming caller. A no-op when nobody negotiated a stream. */
|
|
168
|
+
emit: (chunk: unknown) => void;
|
|
169
|
+
/**
|
|
170
|
+
* A line for whoever reads the run: kept on the step that said it (`logs`), redacted like the rest of it, and shown
|
|
171
|
+
* wherever the run is — the builder's Try, the run history.
|
|
172
|
+
*/
|
|
173
|
+
log: (line: string) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Publishes on one of this space's realtime channels, as the server — `undefined` when the server has none. What
|
|
176
|
+
* the `realtime.publish` task sends through.
|
|
177
|
+
*/
|
|
178
|
+
publish?: (topic: string, type: string, data: unknown) => Promise<void>;
|
|
179
|
+
/** Who is on a topic of a `presence: true` channel of this space, on every replica — `undefined` with no channels. */
|
|
180
|
+
presence?: (topic: string) => Promise<FunctionPresence>;
|
|
181
|
+
/** One person of the space, public fields alone — `undefined` when the server tells no visitor apart. */
|
|
182
|
+
visitor?: (who: string | number) => Promise<FunctionVisitor | undefined>;
|
|
183
|
+
/**
|
|
184
|
+
* A grant for one topic of a `grant: true` channel of this space — what `realtime.grant` hands the page, once the
|
|
185
|
+
* flow has decided the visitor may be there. `undefined` when the server has no realtime channels.
|
|
186
|
+
*/
|
|
187
|
+
grant?: (topic: string, ttlSeconds?: number) => Promise<string>;
|
|
188
|
+
/** Revokes `grant` for `topic` — or every grant for it, naming none — and lets go whoever is on it with one. */
|
|
189
|
+
revoke?: (topic: string, grant?: string) => Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Starts one of this space's actions in so many seconds, by its `later` trigger (`jobs/later.ts`) — `undefined` when
|
|
192
|
+
* the server runs no jobs. What `flow.later` and a function's `ctx.later` go through.
|
|
193
|
+
*/
|
|
194
|
+
later?: (request: LaterRequest) => Promise<LaterAnswer>;
|
|
195
|
+
/** Drops the runs waiting under `key`, and answers how many. */
|
|
196
|
+
cancelLater?: (key: string) => Promise<number>;
|
|
197
|
+
/**
|
|
198
|
+
* The space's jobs, for code over the jobs it declares (`functions/jobs.ts`) — `undefined` when the server runs no
|
|
199
|
+
* jobs. What a function's `ctx.jobs` goes through.
|
|
200
|
+
*/
|
|
201
|
+
jobs?: (declared: Readonly<Record<string, FunctionJobManifest>>) => FunctionJobs;
|
|
202
|
+
/** Signs with the space's own key (`ActionsConfig.signingSecret`) — `undefined` when the deployment gave none. */
|
|
203
|
+
sign?: SpaceSigning['sign'];
|
|
204
|
+
verify?: SpaceSigning['verify'];
|
|
205
|
+
/** Encrypts what the platform keeps for the space and its code must not read — `undefined` with no signingSecret. */
|
|
206
|
+
seal?: SpaceSigning['seal'];
|
|
207
|
+
open?: SpaceSigning['open'];
|
|
208
|
+
/**
|
|
209
|
+
* The public origin of the request that started the run (`https://shop.example.com`), as the server resolved it —
|
|
210
|
+
* where a visitor is sent back to (after an OAuth consent). `undefined` for a run no request started: a schedule, a
|
|
211
|
+
* job.
|
|
212
|
+
*/
|
|
213
|
+
origin?: string;
|
|
214
|
+
/** Where OAuth providers send a visitor back, when the deployment fixed it (`functions.oauth.callbackOrigin`). */
|
|
215
|
+
oauthCallbackOrigin?: string;
|
|
216
|
+
/**
|
|
217
|
+
* One file of the space's data (`products.json`), parsed, as of the run's revision — read-only, and refused when
|
|
218
|
+
* the deployment keeps no data (`lookups.getData`, or `dataDir`). One lookup per run, whichever step reads it.
|
|
219
|
+
*/
|
|
220
|
+
data: (file: string) => Promise<unknown>;
|
|
221
|
+
};
|
|
222
|
+
/** How the actions module reaches the server's realtime channels. Set by `createServer`, never by a deployment. */
|
|
223
|
+
export type ActionRealtime = {
|
|
224
|
+
publish: (space: {
|
|
225
|
+
spaceId: number;
|
|
226
|
+
environment: string;
|
|
227
|
+
}, topic: string, type: string, data: unknown) => Promise<void>;
|
|
228
|
+
grant: (space: {
|
|
229
|
+
spaceId: number;
|
|
230
|
+
environment: string;
|
|
231
|
+
}, topic: string, ttlSeconds?: number) => Promise<string>;
|
|
232
|
+
revoke: (space: {
|
|
233
|
+
spaceId: number;
|
|
234
|
+
environment: string;
|
|
235
|
+
}, topic: string, grant?: string) => Promise<void>;
|
|
236
|
+
presence?: (space: {
|
|
237
|
+
spaceId: number;
|
|
238
|
+
environment: string;
|
|
239
|
+
}, topic: string) => Promise<FunctionPresence>;
|
|
240
|
+
/** Says a job of the space's functions as it is now, on its own topic (`$job:<id>`), kept for a page that joins. */
|
|
241
|
+
publishJob?: (space: {
|
|
242
|
+
spaceId: number;
|
|
243
|
+
environment: string;
|
|
244
|
+
}, jobId: string, view: FunctionJobView) => Promise<void>;
|
|
245
|
+
/** Hands the realtime the way to a job, for the door of its topic: who started it, and who its `watch` lets in. */
|
|
246
|
+
watchJobs?: (lookup: (spaceId: number, jobId: string) => Promise<Job | undefined>) => void;
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* One step a server action can take.
|
|
250
|
+
*
|
|
251
|
+
* `params` is the same `InteractionCallbackParam` map the builder's WorkflowNode already renders, which is what
|
|
252
|
+
* lets a deployment's own task appear in its editor without a single change there.
|
|
253
|
+
*/
|
|
254
|
+
export type ActionTask<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
255
|
+
/** Addressed in a node as `<namespace>.<action>`. */
|
|
256
|
+
namespace: string;
|
|
257
|
+
action: string;
|
|
258
|
+
title: string;
|
|
259
|
+
description?: string;
|
|
260
|
+
params: Record<keyof T, InteractionCallbackParam<T>>;
|
|
261
|
+
/**
|
|
262
|
+
* Receive params BEFORE twig resolution. Only for a task whose whole job is to render a template — resolving
|
|
263
|
+
* first would consume the very tokens it exists to interpret. The client engine special-cases `twigTemplate` by
|
|
264
|
+
* name for this; a flag is the same rule without the name check.
|
|
265
|
+
*/
|
|
266
|
+
rawParams?: boolean;
|
|
267
|
+
run: (params: T, ctx: ActionTaskContext) => unknown;
|
|
268
|
+
};
|
|
269
|
+
/** A task with its addressable name resolved, as the registry stores and lists it. */
|
|
270
|
+
/**
|
|
271
|
+
* Whose task it is: the deployment's — shipped with the server, or its own native functions — or the space's, from the
|
|
272
|
+
* functions it saved. The run treats both alike; an editor lists them apart, as the platform's steps and the space's own.
|
|
273
|
+
*/
|
|
274
|
+
/** Whose step it is: the deployment's, the space's own functions', or the server half of a plugin the space uses. */
|
|
275
|
+
export type ActionTaskOrigin = 'deployment' | 'space' | 'plugin';
|
|
276
|
+
export type RegisteredTask = ActionTask<Record<string, unknown>> & {
|
|
277
|
+
name: string;
|
|
278
|
+
origin: ActionTaskOrigin;
|
|
279
|
+
};
|
|
280
|
+
export type ActionTaskRegistry = {
|
|
281
|
+
get: (name: string) => RegisteredTask | undefined;
|
|
282
|
+
list: () => RegisteredTask[];
|
|
283
|
+
};
|
|
284
|
+
/** What a deployment hands to `createServer` under `actions`. Absent → the module is never constructed. */
|
|
285
|
+
export type ActionsConfig = {
|
|
286
|
+
lookups: ActionLookups;
|
|
287
|
+
/** The flags this deployment decides — the server's own `flags`, which a flow sees the way a page does. */
|
|
288
|
+
flags?: EngineConfig['flags'];
|
|
289
|
+
/** Code of the server's own, and the sandbox for the spaces' — see `FunctionsConfig`. */
|
|
290
|
+
functions?: FunctionsConfig;
|
|
291
|
+
/**
|
|
292
|
+
* Ceilings a space's plan (`limitsFor`) and a per-action document may tighten but never exceed. A deployment that
|
|
293
|
+
* sells more to some spaces than to others sets these to what its largest plan sells, and `limitsFor` to each.
|
|
294
|
+
*/
|
|
295
|
+
limits?: ActionLimits;
|
|
296
|
+
/**
|
|
297
|
+
* What one run of that space's actions may spend — its plan's, each at most `limits`; an unset one is `limits`'. Read
|
|
298
|
+
* on every run, so a deployment caches what it answers. Absent, every space gets `limits`.
|
|
299
|
+
*/
|
|
300
|
+
limitsFor?: (spaceId: number) => Promise<ActionLimits | undefined>;
|
|
301
|
+
/**
|
|
302
|
+
* Whether that space may start a run now — its plan's allowance of runs for the period not spent — or why not, asked
|
|
303
|
+
* before every run but a page's render (which its page view already pays for). A refusal is the run's, `quota`: a
|
|
304
|
+
* call answered 402, a job set aside. Absent, every run may start.
|
|
305
|
+
*/
|
|
306
|
+
admitRun?: (spaceId: number) => Promise<string | undefined>;
|
|
307
|
+
/**
|
|
308
|
+
* How many runs may be in flight at once. Counted per space and for the process as a whole.
|
|
309
|
+
*
|
|
310
|
+
* `memoryShare` is the share of this process's memory limit (its container's, else V8's heap limit) past which it
|
|
311
|
+
* takes no new run, of either kind: 0.85 by default. A slot ceiling counts runs, not what they hold, and runs reading
|
|
312
|
+
* large answers can fill a process long before its slots — refusing the next one (`over_capacity`, with a retry) is
|
|
313
|
+
* what keeps the process alive for the runs already in it.
|
|
314
|
+
*/
|
|
315
|
+
concurrency?: {
|
|
316
|
+
perSpace?: number;
|
|
317
|
+
perProcess?: number;
|
|
318
|
+
renderPerProcess?: number;
|
|
319
|
+
memoryShare?: number;
|
|
320
|
+
};
|
|
321
|
+
/** Where the `kv` tasks keep things. Omitted → an in-process Map, which is per-replica by definition. */
|
|
322
|
+
kv?: ActionKvAdapter;
|
|
323
|
+
/**
|
|
324
|
+
* Scheduled runs, and the durable queue they go through. See {@link ActionJobsConfig}.
|
|
325
|
+
*
|
|
326
|
+
* On by default wherever `lookups.listActions` is answerable, because a deployment that can list its actions can
|
|
327
|
+
* schedule them and the old behaviour — a `schedule` trigger that silently did nothing unless the deployment
|
|
328
|
+
* built a timer and a lock of its own — was a trigger the editor offered and the server did not honour. `false`
|
|
329
|
+
* turns it off for a replica that must only serve pages.
|
|
330
|
+
*/
|
|
331
|
+
jobs?: ActionJobsConfig | false;
|
|
332
|
+
/** Inbound webhooks are public, so they are counted per caller per minute. Default 60. */
|
|
333
|
+
rateLimit?: {
|
|
334
|
+
webhookPerMinute?: number;
|
|
335
|
+
};
|
|
336
|
+
/** The deployment's own origins on its network a flow's request may reach (`outbound.privateOrigins`), validated. */
|
|
337
|
+
outbound?: OutboundOptions;
|
|
338
|
+
/** Database engines this deployment lets a flow reach. Empty → the `db.query` task is not offered at all. */
|
|
339
|
+
dbDrivers?: ActionDbDriver[];
|
|
340
|
+
/** The limits on `email.send`: messages per space per day, and whether an SMTP host may be on a private network. */
|
|
341
|
+
email?: ActionEmailConfig;
|
|
342
|
+
/**
|
|
343
|
+
* Called once per run that started, for a deployment that keeps a record.
|
|
344
|
+
*
|
|
345
|
+
* Best-effort by contract: it is awaited but never allowed to fail a run — a logging outage must not take an
|
|
346
|
+
* action down, which is the same rule metering follows.
|
|
347
|
+
*/
|
|
348
|
+
onRun?: (record: ActionRunRecord) => void | Promise<void>;
|
|
349
|
+
/**
|
|
350
|
+
* Called once per request that was REFUSED before it became a run.
|
|
351
|
+
*
|
|
352
|
+
* Its own hook rather than a status on `onRun`, because the two answer different questions and a deployment
|
|
353
|
+
* wants them in different places: runs are history, refusals are a fault report. Without it a webhook rejected
|
|
354
|
+
* for a bad signature is invisible to everyone but whoever reads the process log — which is nobody, on the
|
|
355
|
+
* afternoon the integration is being set up.
|
|
356
|
+
*
|
|
357
|
+
* Everything is reported, including the refusals that are somebody else retrying politely. Which of them are
|
|
358
|
+
* worth keeping is a policy the deployment owns; the mechanism does not decide it by staying quiet.
|
|
359
|
+
*/
|
|
360
|
+
onReject?: (record: ActionRejectRecord) => void | Promise<void>;
|
|
361
|
+
/**
|
|
362
|
+
* How long a COMPLETED run's answer may be replayed to a caller that asks for it again by the same key.
|
|
363
|
+
*
|
|
364
|
+
* Off by default, and it only ever applies to an explicit key — an `idempotencyKey` on the call, or the
|
|
365
|
+
* delivery id a webhook sender stamps. A derived key is a hash of the input, and two identical calls a minute
|
|
366
|
+
* apart are usually two things somebody wants to happen twice.
|
|
367
|
+
*
|
|
368
|
+
* Needs a shared {@link ActionKvAdapter} to mean anything across replicas, exactly as single-flight does.
|
|
369
|
+
*/
|
|
370
|
+
idempotency?: {
|
|
371
|
+
replayTtlMs?: number;
|
|
372
|
+
};
|
|
373
|
+
fetchImpl?: typeof fetch;
|
|
374
|
+
/** The server's realtime channels, for the `realtime.publish` task. Set by `createServer`. */
|
|
375
|
+
realtime?: ActionRealtime;
|
|
376
|
+
/**
|
|
377
|
+
* What each space's signatures are made from (`ctx.sign` / `ctx.verify` in its functions): at least 32 characters,
|
|
378
|
+
* the SAME on every replica — a key one signed is checked by whichever the next request reaches. Each space and
|
|
379
|
+
* environment signs with a key derived from it, so none can vouch for another. Absent, spaces sign nothing.
|
|
380
|
+
*/
|
|
381
|
+
signingSecret?: string;
|
|
382
|
+
};
|
|
383
|
+
/** Re-exported so the module's own files import one place, and a deployment writing an `onRun` or an `onReject`
|
|
384
|
+
* sees the same shapes the module emits. */
|
|
385
|
+
export type { ActionEmailConfig, ActionEmailDelivery, ActionEmailMessage, ActionEmailTransport, ActionRejectRecord, ActionRunRecord } from '@plitzi/sdk-shared';
|
|
386
|
+
export type ResolvedActionLimits = Required<ActionLimits>;
|
|
387
|
+
export type ActionRunRequest = {
|
|
388
|
+
entry: ActionEntry;
|
|
389
|
+
input: Record<string, unknown>;
|
|
390
|
+
spaceId: number;
|
|
391
|
+
environment: Environment;
|
|
392
|
+
trigger: ActionTriggerType;
|
|
393
|
+
/** Who asks: the session's person — or, for a call kept in the queue, who made it, as the session said then. */
|
|
394
|
+
user?: RunUser;
|
|
395
|
+
/** Who is asking. Stated by whatever started the run — see {@link ActionTaskContext.callerId}. */
|
|
396
|
+
callerId: string;
|
|
397
|
+
/** The public origin of the request that started it — see {@link ActionTaskContext.origin}. */
|
|
398
|
+
origin?: string;
|
|
399
|
+
runId: string;
|
|
400
|
+
/** Chain of run ids that caused this one; a run naming its own action is refused before its first node. */
|
|
401
|
+
lineage?: string[];
|
|
402
|
+
/**
|
|
403
|
+
* The published version this run belongs to, when a page started it.
|
|
404
|
+
*
|
|
405
|
+
* The action was read as of this revision, so the connectors it calls are read as of it too — a flow and the
|
|
406
|
+
* manifests it goes through are one published thing, and mixing versions inside one run is the discrepancy in
|
|
407
|
+
* miniature.
|
|
408
|
+
*/
|
|
409
|
+
at?: SpaceRevision;
|
|
410
|
+
/**
|
|
411
|
+
* The flags a tester forced, for a run started from a page allowed to debug — the same `qa` layer the page was
|
|
412
|
+
* drawn with, so a forced feature is not on in the page and off in the flow behind it. Never what the SDK's own
|
|
413
|
+
* `flags` say: those are the browser's claim, and a flow does not take a claim as a fact.
|
|
414
|
+
*/
|
|
415
|
+
forcedFlags?: Record<string, boolean>;
|
|
416
|
+
emit?: (chunk: unknown) => void;
|
|
417
|
+
/** Reports each step as it settles, for a caller watching the run happen. Absent for a plain request/response. */
|
|
418
|
+
onNode?: (id: string, status: InteractionNodeStatus) => void;
|
|
419
|
+
signal?: AbortSignal;
|
|
420
|
+
};
|
|
421
|
+
export type ActionRunResult = {
|
|
422
|
+
runId: string;
|
|
423
|
+
status: ActionRunStatus;
|
|
424
|
+
/** Projected down to the document's declared `output`. Never the raw flow scope. */
|
|
425
|
+
output: Record<string, unknown>;
|
|
426
|
+
/** The same shape the dev-tools Interactions panel renders. Redacted before it leaves the process. */
|
|
427
|
+
trace: InteractionNode[];
|
|
428
|
+
/**
|
|
429
|
+
* What the run did, step by step, without what any step was given or returned — the part a debugger may show to
|
|
430
|
+
* anybody allowed to debug the page. The trace above is for authoring and development servers alone.
|
|
431
|
+
*/
|
|
432
|
+
steps: ActionRunStep[];
|
|
433
|
+
/** Why the run failed, when a step said so for the caller (`ActionRefusal`). Absent for every other failure. */
|
|
434
|
+
error?: string;
|
|
435
|
+
/**
|
|
436
|
+
* The refusal's code, when its step gave one (`refuse('banned', …)`): what a page tells refusals apart by — a run's
|
|
437
|
+
* specs could only read their words.
|
|
438
|
+
*/
|
|
439
|
+
code?: string;
|
|
440
|
+
/** The limit that stopped it, when one did (`ActionRunLimit`): what a job is retried by, or not. */
|
|
441
|
+
limit?: ActionRunLimit;
|
|
442
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FunctionsProblem } from '@plitzi/sdk-shared';
|
|
2
|
+
import { FunctionsDefinition } from '@plitzi/sdk-shared/functions';
|
|
3
|
+
/** A space's functions source: its files under `functions/`, by path (`index.ts`, `lib/feed.ts`). */
|
|
4
|
+
export type FunctionsSource = Record<string, string>;
|
|
5
|
+
/** One bundle, built from a source: a single web-standard ES module whose default export is the definition. */
|
|
6
|
+
export type FunctionsBuild = {
|
|
7
|
+
code: string;
|
|
8
|
+
bytes: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class FunctionsBuildError extends Error {
|
|
11
|
+
readonly problems: FunctionsProblem[];
|
|
12
|
+
constructor(problems: FunctionsProblem[]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The definitions of `files`, merged into one — what a bundle exports by default. Printed into the bundle from itself,
|
|
16
|
+
* so it uses nothing outside: two tasks of one id or two routes of one path are refused, naming both files; the hosts
|
|
17
|
+
* code may reach are every file's together; a file whose default export is not a definition is no definition.
|
|
18
|
+
*/
|
|
19
|
+
export declare const mergeFunctions: (files: [string, unknown][]) => FunctionsDefinition;
|
|
20
|
+
/** The most a bundle may weigh: well under the smallest provider a runner may be (Workers take 3 MB compressed). */
|
|
21
|
+
export declare const MAX_FUNCTIONS_BYTES = 1000000;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a space's functions into one bundle — the only way code reaches a runner, so what runs is always what the
|
|
24
|
+
* source says. Web-standard and self-contained: the space's own files, and the contract; a Node built-in or any other
|
|
25
|
+
* package is refused with where it was imported, because no runner could provide it.
|
|
26
|
+
*/
|
|
27
|
+
export declare const buildFunctions: (source: FunctionsSource) => Promise<FunctionsBuild>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FunctionContext, FunctionCall } from '@plitzi/sdk-shared/functions';
|
|
2
|
+
/**
|
|
3
|
+
* A call as the code sent it, read into what it claims to be — every field checked, because it was written by the
|
|
4
|
+
* space's code and carried by a runner, and neither is trusted here. The only place a call is read.
|
|
5
|
+
*/
|
|
6
|
+
export declare const readCall: (value: unknown) => FunctionCall;
|
|
7
|
+
/**
|
|
8
|
+
* Answers one call from a space's code with the run's own {@link FunctionContext} — the same object a self-hosted
|
|
9
|
+
* server hands its functions, so the sandbox can do exactly what native code can and not one thing more.
|
|
10
|
+
*/
|
|
11
|
+
export declare const answerCall: (ctx: FunctionContext, call: FunctionCall) => Promise<unknown>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { FunctionJobLimits } from './jobs';
|
|
2
|
+
import { Environment, FunctionAskedLimits } from '@plitzi/sdk-shared';
|
|
3
|
+
import { FunctionsDefinition, FunctionLimits, FunctionRunner, FunctionUsage } from '@plitzi/sdk-shared/functions';
|
|
4
|
+
/**
|
|
5
|
+
* One invocation of a space's task, as metering sees it: what it spent, and the memory it ran with (its size) — what a
|
|
6
|
+
* deployment bills by, as memory over the time it was held.
|
|
7
|
+
*/
|
|
8
|
+
export type FunctionUsageRecord = {
|
|
9
|
+
spaceId: number;
|
|
10
|
+
/** Which build of the space it ran, as its run did: what a deployment files what it spent under. */
|
|
11
|
+
environment: Environment;
|
|
12
|
+
task: string;
|
|
13
|
+
ok: boolean;
|
|
14
|
+
usage: FunctionUsage;
|
|
15
|
+
memoryMb: number;
|
|
16
|
+
};
|
|
17
|
+
/** Why a space may not run code now (`FunctionsConfig.admit`): which limit it reached, and what to say. */
|
|
18
|
+
export type FunctionRefusal = {
|
|
19
|
+
limit: 'cpuBudget' | 'quota';
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* A server's functions. `native` is code the deployment trusts, loaded in its own process with the context narrowed to
|
|
24
|
+
* a function's; the spaces' own code — which nobody here reviewed — only ever runs in the sandbox (`runner`).
|
|
25
|
+
*/
|
|
26
|
+
export type FunctionsConfig = {
|
|
27
|
+
native?: FunctionsDefinition[];
|
|
28
|
+
/**
|
|
29
|
+
* Say when an invocation of `native` spends more than a sandbox would let it — calls to `ctx`, CPU, time, the bytes it
|
|
30
|
+
* answers — naming the limit, once per task: a project's own server, whose functions are a hosted space's, runs them
|
|
31
|
+
* natively and held to nothing, and what passed there would fail hosted. Measured, never enforced.
|
|
32
|
+
*/
|
|
33
|
+
measureNative?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* The server halves of the plugins this server ships, by plugin type — loaded natively like `native`, but each with a
|
|
36
|
+
* plugin's narrower `ctx` (its own `kv` and limits, signatures only it verifies, none of the space's credentials or
|
|
37
|
+
* channels). Their tasks are `<type>.<action>`, their routes answer under `/fn/plugins/<type>/`.
|
|
38
|
+
*/
|
|
39
|
+
plugins?: Record<string, FunctionsDefinition>;
|
|
40
|
+
/**
|
|
41
|
+
* Where the spaces' own functions run: `createRemoteRunner` for the runner service, a provider's adapter, or
|
|
42
|
+
* `createIsolateRunner` only where this process holds nothing a space must not reach. Absent, spaces have no
|
|
43
|
+
* functions here — their tasks are not offered and none of their code runs.
|
|
44
|
+
*/
|
|
45
|
+
runner?: FunctionRunner;
|
|
46
|
+
/**
|
|
47
|
+
* The most one invocation may spend on this deployment ({@link DEFAULT_FUNCTION_CEILINGS} for each unset): what a
|
|
48
|
+
* task may ask for in CPU, time and memory, and what every invocation gets of the rest. A space's plan may allow less, never
|
|
49
|
+
* more.
|
|
50
|
+
*/
|
|
51
|
+
limits?: Partial<FunctionLimits>;
|
|
52
|
+
/**
|
|
53
|
+
* Asked before each invocation: why this space may not run code right now, and which limit that is — its account's CPU
|
|
54
|
+
* for the minute spent (`cpuBudget`: it waits, a route answers 429), or its plan's compute for the period (`quota`, a
|
|
55
|
+
* paywall: a step stops at it, a route answers 402, a job is set aside) — or nothing. What keeps one space's loop from
|
|
56
|
+
* slowing everybody else's on the same runner, and a plan from spending past what it sold.
|
|
57
|
+
*/
|
|
58
|
+
admit?: (spaceId: number) => Promise<FunctionRefusal | undefined>;
|
|
59
|
+
/** Told what each invocation spent, however it ended: what `admit` budgets by, and what a deployment meters. */
|
|
60
|
+
onUsage?: (record: FunctionUsageRecord) => void;
|
|
61
|
+
/** The spaces' jobs (`defineFunctions({ jobs })`): what each may spend. */
|
|
62
|
+
jobs?: {
|
|
63
|
+
/**
|
|
64
|
+
* What one space's jobs may spend — its plan's — each unset one `DEFAULT_FUNCTION_JOB_LIMITS`'. `pool` names the
|
|
65
|
+
* spaces whose running jobs count together: an account's.
|
|
66
|
+
*/
|
|
67
|
+
limitsFor?: (spaceId: number) => Promise<Partial<FunctionJobLimits> | undefined>;
|
|
68
|
+
};
|
|
69
|
+
/** The spaces' OAuth connections (`ctx.oauth`). */
|
|
70
|
+
oauth?: {
|
|
71
|
+
/**
|
|
72
|
+
* The origin every provider sends a visitor back to (`<origin>/fn/oauth/callback`), whichever address they opened
|
|
73
|
+
* the space on — the one address to register, which a server reached on several (`localhost`, its loopback, its
|
|
74
|
+
* address on the network) needs. The visitor is then sent on to the address they started from. Only for a server
|
|
75
|
+
* of one space, such as a project's (`serveProject` sets its `publicUrl`): one of many spaces tells them apart by
|
|
76
|
+
* host, and answers each callback on the space's own. Left out, the address the visitor started on.
|
|
77
|
+
*/
|
|
78
|
+
callbackOrigin?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/** What an invocation gets unless its task asks for more CPU, time or a larger size. */
|
|
82
|
+
export declare const DEFAULT_FUNCTION_LIMITS: FunctionLimits;
|
|
83
|
+
/**
|
|
84
|
+
* The most a deployment lets one invocation have, unless it says otherwise: two seconds of CPU and half a minute of
|
|
85
|
+
* time, and the largest size, for a task that asks; the rest as every invocation gets it.
|
|
86
|
+
*/
|
|
87
|
+
export declare const DEFAULT_FUNCTION_CEILINGS: FunctionLimits;
|
|
88
|
+
/** A deployment's ceilings, each unset one the default's. */
|
|
89
|
+
export declare const functionCeilings: (ceilings?: Partial<FunctionLimits>) => FunctionLimits;
|
|
90
|
+
/**
|
|
91
|
+
* What one invocation of a space may spend: the CPU, time and size its task asked for — the default's when it asked for
|
|
92
|
+
* none — and the rest as the deployment gives it; never above the space's plan, nor above the deployment's ceilings.
|
|
93
|
+
* A plan's memory is the largest size a task may ask for, never what every invocation is given: the runner keeps an
|
|
94
|
+
* invocation's memory whole while it runs, so each one given the plan's would leave room for a few at once. A size past
|
|
95
|
+
* it is refused before it runs ({@link functionSizeRefusal}), never quietly made smaller.
|
|
96
|
+
*/
|
|
97
|
+
export declare const functionLimitsFor: (ceilings?: Partial<FunctionLimits>, space?: Partial<FunctionLimits>, asked?: FunctionAskedLimits) => FunctionLimits;
|
|
98
|
+
/**
|
|
99
|
+
* Why a task may not run at the size it asked for — its space's plan, or this server, allows less memory — or nothing.
|
|
100
|
+
* Said before it runs, naming the size that fits and the plan, so its author can choose either.
|
|
101
|
+
*/
|
|
102
|
+
export declare const functionSizeRefusal: (ceilings?: Partial<FunctionLimits>, space?: Partial<FunctionLimits>, asked?: FunctionAskedLimits) => string | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* What one invocation may spend (`functionLimitsFor`) and, when the size it asked for is past what its plan or this
|
|
105
|
+
* server allows, why it may not run (`functionSizeRefusal`) — the one call every place that invokes makes, so none runs
|
|
106
|
+
* a refused size quietly made smaller.
|
|
107
|
+
*/
|
|
108
|
+
export declare const invocationLimitsFor: (ceilings?: Partial<FunctionLimits>, space?: Partial<FunctionLimits>, asked?: FunctionAskedLimits) => {
|
|
109
|
+
limits: FunctionLimits;
|
|
110
|
+
sizeRefusal?: string;
|
|
111
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FunctionScope } from './scope';
|
|
2
|
+
import { ActionTaskContext } from '../engine/types';
|
|
3
|
+
import { FunctionJobManifest, FunctionOAuthConnection } from '@plitzi/sdk-shared';
|
|
4
|
+
import { FunctionContext } from '@plitzi/sdk-shared/functions';
|
|
5
|
+
/**
|
|
6
|
+
* How the values a function logs read as one line — the one formatting of it, for native functions and for the
|
|
7
|
+
* sandbox's, whose guest only makes each value safe to send.
|
|
8
|
+
*/
|
|
9
|
+
export declare const lineOf: (values: readonly unknown[]) => string;
|
|
10
|
+
/**
|
|
11
|
+
* What a space's code is handed, built from the run's own context: the one place a {@link FunctionContext} is made.
|
|
12
|
+
* A self-hosted server hands it to the code directly; the platform answers the sandbox's calls with it. With a `scope`,
|
|
13
|
+
* it is a plugin's code, and gets the plugin's corner of the space (`./scope`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const functionContextFor: (ctx: ActionTaskContext, hosts: readonly string[], scope?: FunctionScope, oauth?: Readonly<Record<string, FunctionOAuthConnection>>, jobs?: Readonly<Record<string, FunctionJobManifest>>) => FunctionContext;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { buildFunctions, FunctionsBuildError } from './build';
|
|
2
|
+
export { DEFAULT_FUNCTION_CEILINGS, DEFAULT_FUNCTION_LIMITS } from './config';
|
|
3
|
+
export { DEFAULT_FUNCTION_JOB_LIMITS } from './jobs';
|
|
4
|
+
export { loadFunctions, loadFunctionsSource, readFunctionsDir } from './load';
|
|
5
|
+
export { createLocalFunctions } from './local';
|
|
6
|
+
export { createRemoteRunner } from './runner/remote';
|
|
7
|
+
export { functionTryEntry, TRY_STEP } from './tryEntry';
|
|
8
|
+
export { functionsInHand } from './space';
|
|
9
|
+
export { readManifest } from './manifest';
|
|
10
|
+
export { oauthCallbackUrlOn } from './oauth';
|
|
11
|
+
export type { FunctionsSource, FunctionsBuild } from './build';
|
|
12
|
+
export type { FunctionRefusal, FunctionsConfig, FunctionUsageRecord } from './config';
|
|
13
|
+
export type { FunctionJobLimits } from './jobs';
|
|
14
|
+
export type { LocalFunctions, LocalFunctionsOptions } from './local';
|
|
15
|
+
export type { ManifestReading } from './manifest';
|
|
16
|
+
export type { RemoteRunnerOptions } from './runner/remote';
|
|
17
|
+
export type { PreparedFunctions } from './space';
|