@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.
- package/CHANGELOG.md +18 -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,54 @@
|
|
|
1
|
+
import { createEmailSender } from './email';
|
|
2
|
+
import { createRedactor } from './scope';
|
|
3
|
+
import { createSigning } from './signing';
|
|
4
|
+
import { FunctionJobsService } from '../../functions/jobs';
|
|
5
|
+
import { LaterDeps } from '../jobs/later';
|
|
6
|
+
import { ActionRunRequest, ActionsConfig, ActionTaskContext, ResolvedActionLimits } from '../types';
|
|
7
|
+
import { RunUser } from '@plitzi/sdk-shared';
|
|
8
|
+
import { ActionKvStore } from '@plitzi/sdk-shared/functions';
|
|
9
|
+
/**
|
|
10
|
+
* Counts outbound calls, refuses past the budget, caps what one answer — and all of the run's answers together — may
|
|
11
|
+
* carry back, and stamps the run's lineage on every one of them.
|
|
12
|
+
*
|
|
13
|
+
* The budget stops a loop from turning one run into a hundred requests. The lineage header is what makes the
|
|
14
|
+
* OTHER loop detectable: an action whose HTTP step reaches its own space's webhook arrives carrying the chain
|
|
15
|
+
* that led there, and the run it would start refuses itself. It names the space's own actions to a backend that
|
|
16
|
+
* space configured, which is the cost of catching a cycle nothing else can see.
|
|
17
|
+
*
|
|
18
|
+
* Every ceiling lives HERE rather than in each task, because this is the only door a task has to the outside
|
|
19
|
+
* world — a task that had to remember to count its own bytes is a task that will forget.
|
|
20
|
+
*/
|
|
21
|
+
export declare const createRunFetch: (base: typeof fetch, signal: AbortSignal, limits: ResolvedActionLimits, lineage: string[],
|
|
22
|
+
/**
|
|
23
|
+
* Told once per budget, the first time a request or an answer is refused for it. A task reading many sources usually
|
|
24
|
+
* catches a failed fetch and goes on with the rest, which made the budget invisible: twenty sources answered, the
|
|
25
|
+
* rest "failed" like a network error, and nothing anywhere named the limit.
|
|
26
|
+
*/
|
|
27
|
+
onBudgetSpent?: (message: string) => void) => typeof fetch;
|
|
28
|
+
/** What a task's context is made of that outlives one run: the server's stores and the run's redactor. */
|
|
29
|
+
export type TaskContextDeps = {
|
|
30
|
+
kv: ActionKvStore;
|
|
31
|
+
email: ReturnType<typeof createEmailSender>;
|
|
32
|
+
redactor: ReturnType<typeof createRedactor>;
|
|
33
|
+
/** Absent when the deployment gave no `signingSecret`: its spaces then sign nothing. */
|
|
34
|
+
signing?: ReturnType<typeof createSigning>;
|
|
35
|
+
/** What runs set for later go through: the module's queue, read when asked. */
|
|
36
|
+
later: LaterDeps;
|
|
37
|
+
/** The space's jobs, for a function's `ctx.jobs`. */
|
|
38
|
+
jobs?: FunctionJobsService;
|
|
39
|
+
/** The run's time limit moved by what it waited for the platform's capacity (`ActionTaskContext.waited`). */
|
|
40
|
+
waited?: (ms: number) => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Who and what the context is for — a run's request, or anything shaped like one (a function's route, a job's slice,
|
|
44
|
+
* whose user is who started it and holds no session).
|
|
45
|
+
*/
|
|
46
|
+
export type TaskContextRequest = Pick<ActionRunRequest, 'runId' | 'spaceId' | 'environment' | 'trigger' | 'callerId' | 'at' | 'emit' | 'origin'> & {
|
|
47
|
+
user?: RunUser;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* What a task runs with — the one place it is made, for a step of a run and for a function answering a route alike:
|
|
51
|
+
* every secret it resolves registered with the redactor, the space's `kv` namespace, the run's outbound budget, the
|
|
52
|
+
* space's channels. Everything but `log`, which is the STEP's: each step keeps what it logged.
|
|
53
|
+
*/
|
|
54
|
+
export declare const taskContextFor: (config: ActionsConfig, { kv, email, redactor, signing, later, jobs, waited }: TaskContextDeps, request: TaskContextRequest, signal: AbortSignal, runFetch: typeof fetch) => ((scope: Record<string, unknown>) => Omit<ActionTaskContext, "log">);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ActionTriggerParams, ActionTriggerType, ElementInteraction } from '@plitzi/sdk-shared';
|
|
2
|
+
/**
|
|
3
|
+
* The step that starts a flow, for one way in.
|
|
4
|
+
*
|
|
5
|
+
* An action holds its ways in as trigger STEPS, exactly as an element holds `onClick` and `onSubmit` in one node
|
|
6
|
+
* map — so finding the entry point means finding the trigger whose kind matches what fired, not reading a list
|
|
7
|
+
* beside the flow. An action with no step for that kind cannot be started that way, and that is the whole of the
|
|
8
|
+
* "does it declare this trigger" check.
|
|
9
|
+
*/
|
|
10
|
+
export declare const findTriggerNode: (nodes: Record<string, ElementInteraction>, kind: ActionTriggerType) => ElementInteraction | undefined;
|
|
11
|
+
/** What a trigger step carries: who may start it, what it takes, and whatever its kind needs. */
|
|
12
|
+
export declare const triggerParams: (node: ElementInteraction) => ActionTriggerParams;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ActionTaskOrigin, ActionTaskRegistry, RegisteredTask } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A task as an editor renders it.
|
|
4
|
+
*
|
|
5
|
+
* `run` is dropped rather than left to JSON to discard silently — it is server code. `params` goes over as it is,
|
|
6
|
+
* because it is already the `InteractionCallbackParam` map the builder's WorkflowNode draws.
|
|
7
|
+
*
|
|
8
|
+
* What does not survive the trip is a FUNCTION-valued param: a `when`, or options computed from another param.
|
|
9
|
+
* Those are a task author's way of saying "this field depends on that one", and a catalog served over the wire
|
|
10
|
+
* keeps only the static half — worth knowing when writing a deployment task meant to be authored visually.
|
|
11
|
+
*
|
|
12
|
+
* They are STRIPPED here rather than left for the transport to choke on: a JSON scalar refuses a function outright,
|
|
13
|
+
* so `http.request` — whose `body` is hidden on GET — took the whole catalog down with it.
|
|
14
|
+
*/
|
|
15
|
+
export type ActionTaskDescriptor = {
|
|
16
|
+
name: string;
|
|
17
|
+
namespace: string;
|
|
18
|
+
action: string;
|
|
19
|
+
title: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
/** The deployment's step, or one of the space's own functions. */
|
|
22
|
+
origin: ActionTaskOrigin;
|
|
23
|
+
/** Serializable params only — see above. */
|
|
24
|
+
params: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export declare const describeTask: (task: RegisteredTask) => ActionTaskDescriptor;
|
|
27
|
+
/** The whole catalog, in the order the registry holds it. */
|
|
28
|
+
export declare const describeCatalog: (registry: ActionTaskRegistry) => ActionTaskDescriptor[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ActionTask } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* The tasks `sdk-server` itself ships: the ones that are mechanism rather than policy.
|
|
4
|
+
*
|
|
5
|
+
* Anything needing an account somewhere the deployment owns — AI, object storage — is the DEPLOYMENT's, registered
|
|
6
|
+
* through `actions.tasks`. `email.send` is shipped because the account is the SPACE's: it sends through an SMTP server
|
|
7
|
+
* the space holds as a credential, so every server can offer it. `db.query` sits in between — the task is shipped,
|
|
8
|
+
* the engine driver is the deployment's, and the registry offers it only when one was given.
|
|
9
|
+
*/
|
|
10
|
+
export declare const builtinTasks: ActionTask<Record<string, unknown>>[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ActionTaskContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a task's own params, with its own credential in scope.
|
|
4
|
+
*
|
|
5
|
+
* This is the shape every task that talks to a third party takes — `http.request` today, `apiCall` and whatever
|
|
6
|
+
* else tomorrow — and it exists so each of them does not invent its own answer to the same question.
|
|
7
|
+
*
|
|
8
|
+
* The credential is resolved HERE, inside the task, and never enters the flow scope. That is the whole point:
|
|
9
|
+
* a secret in the run's scope is interpolable by every other node, including the one that returns values to the
|
|
10
|
+
* browser, and no amount of care in this task would stop that. What a flow can reach is what its tasks chose to
|
|
11
|
+
* hand back — a credential is not that.
|
|
12
|
+
*
|
|
13
|
+
* Tasks using this declare `rawParams: true`, because the runner must not have resolved the params first: a
|
|
14
|
+
* `{{credential.*}}` token would then have been spent against a scope that has no credential in it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const renderTaskParams: <T extends Record<string, unknown>>(params: T, ctx: ActionTaskContext, credentialId?: string) => Promise<T>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActionTask } from '../types';
|
|
2
|
+
export declare const taskName: (task: Pick<ActionTask, "namespace" | "action">) => string;
|
|
3
|
+
/**
|
|
4
|
+
* What is wrong with a task's name, or nothing — one rule for a deployment's tasks at boot and a space's own when its
|
|
5
|
+
* functions are built. A malformed name is unreachable from any document; one in a namespace taken by another task
|
|
6
|
+
* set silently changes what every action using that set does.
|
|
7
|
+
*/
|
|
8
|
+
export declare const taskNameProblem: (task: Pick<ActionTask, "namespace" | "action">, reserved?: ReadonlySet<string>) => string | undefined;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ActionTask } from '../types';
|
|
2
|
+
export declare const NO_REALTIME = "This runner has no realtime channels: one made with `createActionsModule` publishes when it is given `realtime: createActionRealtime({ getOfflineData, pubsub, kv })`, with the page servers' own pubsub and kv";
|
|
3
|
+
export declare const realtimeTasks: ActionTask<Record<string, unknown>>[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ActionTaskRegistry } from '../types';
|
|
2
|
+
import { FunctionsDefinition } from '@plitzi/sdk-shared/functions';
|
|
3
|
+
/** The shipped tasks that are only real when the deployment supplied what they run through. */
|
|
4
|
+
export type TaskRegistryOptions = {
|
|
5
|
+
/** At least one database driver is registered, so `db.query` has an engine to run against. */
|
|
6
|
+
db?: boolean;
|
|
7
|
+
/** The server halves of the plugins this server ships, by plugin type: their tasks are `<type>.<action>`. */
|
|
8
|
+
plugins?: Readonly<Record<string, FunctionsDefinition>>;
|
|
9
|
+
/** Measure the native functions' invocations against a sandbox's limits, and say one past them (`nativeTasks`). */
|
|
10
|
+
measureNative?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Builds the set of tasks this server can run.
|
|
14
|
+
*
|
|
15
|
+
* Validation is at BOOT and it throws, because every alternative is worse: a task registered under a malformed
|
|
16
|
+
* name is unreachable from any document, and one shadowing a built-in silently changes what every existing action
|
|
17
|
+
* in that deployment does. Both are invisible until a run misbehaves in production.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createTaskRegistry: (functions?: readonly FunctionsDefinition[], { db, plugins, measureNative }?: TaskRegistryOptions) => ActionTaskRegistry;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EngineServerConfig } from '../../types';
|
|
2
|
+
import { ActionsModule } from '../module';
|
|
3
|
+
import { RawResponse } from '@plitzi/sdk-kernel/http';
|
|
4
|
+
import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-kernel/types';
|
|
5
|
+
import { ActionErrorReason } from '@plitzi/sdk-shared';
|
|
6
|
+
export type ActionCallDeps = {
|
|
7
|
+
req: SSRRequest;
|
|
8
|
+
res: SSRResponseHelpers;
|
|
9
|
+
/** The raw response, for the streaming path alone: SSE cannot go through the one-shot helpers. */
|
|
10
|
+
raw: RawResponse;
|
|
11
|
+
config: EngineServerConfig;
|
|
12
|
+
module: ActionsModule;
|
|
13
|
+
/** The request's own signal: a caller that hangs up stops the run rather than paying for it to finish. */
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
/** Who is asking, for the single-flight key and for cancellation ownership. */
|
|
16
|
+
callerId: string;
|
|
17
|
+
lineage: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* How a refusal reaches the caller.
|
|
21
|
+
*
|
|
22
|
+
* Every reason maps to a status the client can act on without parsing prose — a 409 means "your other run is still
|
|
23
|
+
* going", a 429 means "come back", a 508 means "you built a loop". `recursion` is the one worth the unusual code:
|
|
24
|
+
* 508 Loop Detected says exactly what happened, and anything else would read as a server fault.
|
|
25
|
+
*/
|
|
26
|
+
export declare const STATUS_BY_REASON: Record<ActionErrorReason, number>;
|
|
27
|
+
/**
|
|
28
|
+
* Handles an action-addressed call.
|
|
29
|
+
*
|
|
30
|
+
* The browser names an action and hands it inputs. Everything that decides whether the run may happen — the
|
|
31
|
+
* document, the access rule, the input contract, the lineage — is the runner's, so a deployment mounting its own
|
|
32
|
+
* trigger cannot end up with a weaker set of checks than this endpoint applies.
|
|
33
|
+
*/
|
|
34
|
+
export declare const handleActionCall: (deps: ActionCallDeps) => Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ActionsModule } from '../module';
|
|
2
|
+
import { SSRResponseHelpers } from '@plitzi/sdk-kernel/types';
|
|
3
|
+
export type ActionCancelDeps = {
|
|
4
|
+
res: SSRResponseHelpers;
|
|
5
|
+
module: ActionsModule;
|
|
6
|
+
runId: string;
|
|
7
|
+
callerId: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Stops a run in flight.
|
|
11
|
+
*
|
|
12
|
+
* The socket closing already aborts a run, so this exists for the cases it cannot cover: a mobile client whose
|
|
13
|
+
* peer is gone without the server seeing it for minutes, and a run started in one tab that the visitor wants to
|
|
14
|
+
* stop from another. Ownership is checked in the guards — a run id travels to the browser, and holding one must
|
|
15
|
+
* not let anybody stop somebody else's run.
|
|
16
|
+
*
|
|
17
|
+
* A run that is not there, or is not the caller's, answers 404 either way: distinguishing them would turn this
|
|
18
|
+
* into an oracle for which run ids are live.
|
|
19
|
+
*
|
|
20
|
+
* Awaited because the run is usually somewhere else: behind a load balancer the tab asking to stop a checkout
|
|
21
|
+
* almost never reaches the replica running it, so the cancel is left in the shared store for the one that is.
|
|
22
|
+
*/
|
|
23
|
+
export declare const handleActionCancel: ({ res, module, runId, callerId }: ActionCancelDeps) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ActionsModule } from '../module';
|
|
2
|
+
import { SSRResponseHelpers } from '@plitzi/sdk-kernel/types';
|
|
3
|
+
import { SpaceRevision } from '@plitzi/sdk-shared';
|
|
4
|
+
export type ActionCatalogDeps = {
|
|
5
|
+
res: SSRResponseHelpers;
|
|
6
|
+
module: ActionsModule;
|
|
7
|
+
/** The space asking, as of the revision it is serving: its own functions are part of what it can run. */
|
|
8
|
+
spaceId?: number;
|
|
9
|
+
at?: SpaceRevision;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Serves the tasks this server can run.
|
|
13
|
+
*
|
|
14
|
+
* The editor asks the SERVER what steps exist instead of holding a hardcoded list, and that is the whole reason a
|
|
15
|
+
* self-hoster's own task appears in their builder with no fork: registering it is publishing it. It also means a
|
|
16
|
+
* deployment with no database driver never offers `db.query` — the catalog is what that deployment actually has,
|
|
17
|
+
* not what the SDK could imagine.
|
|
18
|
+
*
|
|
19
|
+
* Session-gated by the pipeline: the catalog names a deployment's server-side capabilities, which is not something
|
|
20
|
+
* to hand an anonymous visitor.
|
|
21
|
+
*/
|
|
22
|
+
export declare const handleActionCatalog: ({ res, module, spaceId, at }: ActionCatalogDeps) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RawResponse } from '@plitzi/sdk-kernel/http';
|
|
2
|
+
import { ActionStreamFrame } from '@plitzi/sdk-shared';
|
|
3
|
+
export type ActionStream = {
|
|
4
|
+
/** Sends one frame. Silently drops once the socket is gone — a stream writing into a closed peer is not an error
|
|
5
|
+
* worth failing a run over. */
|
|
6
|
+
send: (frame: ActionStreamFrame) => void;
|
|
7
|
+
/** Ends the stream and stops the heartbeat. */
|
|
8
|
+
close: () => void;
|
|
9
|
+
/** Whether the peer is still there. */
|
|
10
|
+
isOpen: () => boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Opens a run's Server-Sent Events response.
|
|
14
|
+
*
|
|
15
|
+
* The run's id travels on the response head rather than in a frame: a streaming step returns as soon as the stream
|
|
16
|
+
* OPENS — that is what makes it a stream — so anything it learns from a frame arrives after the flow has already
|
|
17
|
+
* carried on. The head is the one place a caller can read the id in time to cancel the run it just started.
|
|
18
|
+
*/
|
|
19
|
+
export declare const openStream: (raw: RawResponse, onAbort: () => void, runId: string) => ActionStream;
|
|
20
|
+
/** Whether this caller asked for a stream. The negotiation is the client's, so a page that cannot read one never
|
|
21
|
+
* gets one by accident. */
|
|
22
|
+
export declare const wantsStream: (accept: string | string[] | undefined) => boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ActionWebhookVerification } from '@plitzi/sdk-shared';
|
|
2
|
+
export type SignatureCheck = {
|
|
3
|
+
ok: true;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
reason: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Checks an inbound webhook signature against the RAW body.
|
|
10
|
+
*
|
|
11
|
+
* Raw, before parsing, because a signature covers bytes: `JSON.parse` then `JSON.stringify` reorders keys and
|
|
12
|
+
* drops whitespace, and the digest of the result is not the digest the sender computed. That is the single most
|
|
13
|
+
* common way a webhook verification is written wrong, and it fails closed — which is why it is worth naming here
|
|
14
|
+
* rather than trusting every caller to remember.
|
|
15
|
+
*/
|
|
16
|
+
export declare const verifySignature: (verification: ActionWebhookVerification, secret: string, headers: Record<string, string | string[] | undefined>, rawBody: string) => SignatureCheck;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EngineServerConfig } from '../../types';
|
|
2
|
+
import { ActionsModule } from '../module';
|
|
3
|
+
import { SSRRequest, SSRResponseHelpers } from '@plitzi/sdk-kernel/types';
|
|
4
|
+
export type ActionWebhookDeps = {
|
|
5
|
+
req: SSRRequest;
|
|
6
|
+
res: SSRResponseHelpers;
|
|
7
|
+
config: EngineServerConfig;
|
|
8
|
+
module: ActionsModule;
|
|
9
|
+
signal: AbortSignal;
|
|
10
|
+
actionId: string;
|
|
11
|
+
/** The caller's address: a webhook has no session, so this is all there is to rate limit by. */
|
|
12
|
+
callerId: string;
|
|
13
|
+
lineage: string[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Handles an inbound webhook.
|
|
17
|
+
*
|
|
18
|
+
* The public face of an action, and the one an attacker can reach without a session — so everything that costs
|
|
19
|
+
* anything happens after the signature is checked, in this order: the action must exist and declare the trigger,
|
|
20
|
+
* the rate limit must allow it, the signature must verify, and only then does a run start.
|
|
21
|
+
*
|
|
22
|
+
* The answer is deliberately thin. A sender needs to know it was accepted; it has no business learning whether an
|
|
23
|
+
* action exists, why a run failed, or what the flow did — and a 404 that distinguishes "no such action" from
|
|
24
|
+
* "wrong signature" is an oracle for both.
|
|
25
|
+
*/
|
|
26
|
+
export declare const handleActionWebhook: (deps: ActionWebhookDeps) => Promise<void>;
|