@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,404 @@
|
|
|
1
|
+
import { a as triggerParams, i as findTriggerNode, t as ActionRunError } from "./errors-bCBfIe7c.mjs";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
|
+
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
4
|
+
import { triggerCacheMs } from "@plitzi/sdk-shared/actions";
|
|
5
|
+
import { onAbort } from "@plitzi/sdk-kernel/http";
|
|
6
|
+
import { serverInputOf } from "@plitzi/sdk-shared/schema";
|
|
7
|
+
// src/engine/runtime/renderFailure.ts
|
|
8
|
+
/**
|
|
9
|
+
* A render run that resolved nothing, carrying what it did.
|
|
10
|
+
*
|
|
11
|
+
* The slice is withheld all the same — `resolveRscData` reads the rejection as the element's error state — but the
|
|
12
|
+
* steps travel with the error, so a page allowed to debug is still shown where the flow broke.
|
|
13
|
+
*/
|
|
14
|
+
var RenderRunFailure = class extends Error {
|
|
15
|
+
summary;
|
|
16
|
+
/**
|
|
17
|
+
* The action answered this visitor with a refusal (`ActionRefusal`): a room closed, data that is another's — the
|
|
18
|
+
* action doing its job, said as a warning, never an error with its stack (a run's log, a guest's every page).
|
|
19
|
+
*/
|
|
20
|
+
refused;
|
|
21
|
+
/**
|
|
22
|
+
* A refusal's own words, written for whoever called: what the element shows the visitor, alone — never the log's
|
|
23
|
+
* line around them ("Action … ended as failed, refused (code): …"), which a page had to split to show.
|
|
24
|
+
*/
|
|
25
|
+
said;
|
|
26
|
+
constructor(message, summary, options) {
|
|
27
|
+
super(message, options);
|
|
28
|
+
this.summary = summary;
|
|
29
|
+
this.refused = options?.refused === true;
|
|
30
|
+
if (options?.said !== void 0) this.said = options.said;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
// src/engine/runtime/renderShare.ts
|
|
34
|
+
/** Keeps the map from growing without bound on a space with many keys: expired entries are dropped on write. */
|
|
35
|
+
var sweep = (entries, now) => {
|
|
36
|
+
entries.forEach((entry, key) => {
|
|
37
|
+
if (!entry.inFlight && (entry.expiresAt === void 0 || entry.expiresAt <= now)) entries.delete(key);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/** What a caller that stopped waiting is answered with: its own end, not the run's. */
|
|
41
|
+
var stoppedWaiting = () => new DOMException("The render was aborted: its page stopped waiting for it", "AbortError");
|
|
42
|
+
/** One caller waiting on a run in flight, until it answers or the caller gives up — whichever comes first. */
|
|
43
|
+
var wait = (entry, inFlight, signal) => {
|
|
44
|
+
entry.waiting += 1;
|
|
45
|
+
let waiting = true;
|
|
46
|
+
const leave = () => {
|
|
47
|
+
if (!waiting) return;
|
|
48
|
+
waiting = false;
|
|
49
|
+
entry.waiting -= 1;
|
|
50
|
+
if (entry.waiting === 0) entry.controller?.abort();
|
|
51
|
+
};
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
const release = onAbort(signal, () => {
|
|
54
|
+
leave();
|
|
55
|
+
reject(stoppedWaiting());
|
|
56
|
+
});
|
|
57
|
+
inFlight.then((value) => {
|
|
58
|
+
waiting = false;
|
|
59
|
+
release();
|
|
60
|
+
resolve(value);
|
|
61
|
+
}, (error) => {
|
|
62
|
+
waiting = false;
|
|
63
|
+
release();
|
|
64
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
var createRenderShare = (now = Date.now) => {
|
|
69
|
+
const entries = /* @__PURE__ */ new Map();
|
|
70
|
+
const run = async (key, ttlMs, produce, signal) => {
|
|
71
|
+
const existing = entries.get(key);
|
|
72
|
+
if (existing?.inFlight) return wait(existing, existing.inFlight, signal);
|
|
73
|
+
if (existing && existing.expiresAt !== void 0 && existing.expiresAt > now()) return existing.value;
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const inFlight = produce(controller.signal);
|
|
76
|
+
const entry = {
|
|
77
|
+
inFlight,
|
|
78
|
+
controller,
|
|
79
|
+
waiting: 0
|
|
80
|
+
};
|
|
81
|
+
entries.set(key, entry);
|
|
82
|
+
inFlight.then((value) => {
|
|
83
|
+
sweep(entries, now());
|
|
84
|
+
if (ttlMs > 0) entries.set(key, {
|
|
85
|
+
value,
|
|
86
|
+
expiresAt: now() + ttlMs,
|
|
87
|
+
waiting: 0
|
|
88
|
+
});
|
|
89
|
+
else if (entries.get(key) === entry) entries.delete(key);
|
|
90
|
+
}, () => {
|
|
91
|
+
if (entries.get(key) === entry) entries.delete(key);
|
|
92
|
+
});
|
|
93
|
+
return wait(entry, inFlight, signal);
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
run,
|
|
97
|
+
size: () => entries.size
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
// src/engine/runtime/renderResolver.ts
|
|
101
|
+
/**
|
|
102
|
+
* What makes two renders the same question.
|
|
103
|
+
*
|
|
104
|
+
* Everything that can change the answer, and nothing else: the space and the version being served, the action,
|
|
105
|
+
* the visitor, and the input the flow will actually see. The USER is in there because an action may read
|
|
106
|
+
* `{{ user.* }}` — sharing across visitors would hand one person another's page — while anonymous visitors, who
|
|
107
|
+
* are most of them, share the one key that matters.
|
|
108
|
+
*/
|
|
109
|
+
var shareKey = (parts) => createHash("sha256").update(JSON.stringify(parts)).digest("hex").slice(0, 32);
|
|
110
|
+
/**
|
|
111
|
+
* Resolves a `runtime: 'server'` element that names an ACTION rather than a connector.
|
|
112
|
+
*
|
|
113
|
+
* This is the read a manifest cannot express: two calls that have to be joined, a field computed from both, a
|
|
114
|
+
* shape that depends on who is looking. The element names an action exactly as it would name a connector, and the
|
|
115
|
+
* page still learns nothing about what happens on the other side.
|
|
116
|
+
*
|
|
117
|
+
* Its input is the page's own context — route params, then query params — plus whatever the element declares, so
|
|
118
|
+
* an action feeding `/blog/:slug` reads `{{ input.slug }}` and needs nothing else; a refresh's own params (what
|
|
119
|
+
* `reloadApi` or a bound `input` asked for) come last and win. The action's own input contract still drops everything
|
|
120
|
+
* it did not declare.
|
|
121
|
+
*/
|
|
122
|
+
var createActionResolver = (lookups, module) => {
|
|
123
|
+
const share = createRenderShare();
|
|
124
|
+
return async ({ element, input: resolved, routeParams, queryParams, spaceId, environment, user, req, signal }) => {
|
|
125
|
+
/**
|
|
126
|
+
* Which version of the space is being rendered — environment AND revision from the same record.
|
|
127
|
+
*
|
|
128
|
+
* Reading one from the deployment and the other from the resolve context would let them disagree, and the
|
|
129
|
+
* combination "this environment, that revision" names a snapshot nobody published.
|
|
130
|
+
*/
|
|
131
|
+
const deployment = req.ctx.spaceDeployment;
|
|
132
|
+
const at = {
|
|
133
|
+
environment: deployment?.environment ?? environment,
|
|
134
|
+
revision: deployment?.revision ?? 0
|
|
135
|
+
};
|
|
136
|
+
const { action: actionId } = element.attributes;
|
|
137
|
+
const bound = resolved ?? serverInputOf(element, {
|
|
138
|
+
routeParams,
|
|
139
|
+
queryParams
|
|
140
|
+
});
|
|
141
|
+
const input = isRecord(bound) ? bound : {};
|
|
142
|
+
if (!actionId) return;
|
|
143
|
+
const entry = await lookups.getAction(spaceId, actionId, at);
|
|
144
|
+
if (!entry) throw new Error(`Action "${actionId}" is not configured for space ${spaceId}`);
|
|
145
|
+
const values = {
|
|
146
|
+
...routeParams,
|
|
147
|
+
...queryParams,
|
|
148
|
+
...input,
|
|
149
|
+
...req.ctx.rscParams
|
|
150
|
+
};
|
|
151
|
+
const trigger = findTriggerNode(entry.document.nodes, "render");
|
|
152
|
+
if (!trigger) throw new Error(`Action "${actionId}" has no "render" trigger: a server provider reads an action through one — give it a render trigger (its access says who may read it), as a "call" trigger is a page's to run`);
|
|
153
|
+
const ttlMs = triggerCacheMs(triggerParams(trigger));
|
|
154
|
+
const key = shareKey([
|
|
155
|
+
spaceId,
|
|
156
|
+
at.environment,
|
|
157
|
+
at.revision,
|
|
158
|
+
entry.id,
|
|
159
|
+
user?.id ?? null,
|
|
160
|
+
values
|
|
161
|
+
]);
|
|
162
|
+
const callerId = user ? `user:${user.id}` : "render";
|
|
163
|
+
let ownRunId;
|
|
164
|
+
/** `stop` is the shared run's: aborted once nobody is waiting for it, this render included. */
|
|
165
|
+
const startRun = async (stop) => {
|
|
166
|
+
/**
|
|
167
|
+
* A key of its own per render, so two visitors are never each other's duplicate.
|
|
168
|
+
*
|
|
169
|
+
* Single-flight exists for the caller who submits twice — a double-click, a retry — and keys on the caller
|
|
170
|
+
* and the input. A render has neither of those to go on: every anonymous visitor of one URL is `render`
|
|
171
|
+
* with the same input, so the derived key made concurrent page loads collide and one of them had its
|
|
172
|
+
* section refused as a duplicate. The busier the page, the more often.
|
|
173
|
+
*/
|
|
174
|
+
const run = await module.guards.begin({
|
|
175
|
+
spaceId,
|
|
176
|
+
actionId: entry.id,
|
|
177
|
+
callerId,
|
|
178
|
+
input,
|
|
179
|
+
idempotencyKey: `render:${randomUUID()}`,
|
|
180
|
+
kind: "render",
|
|
181
|
+
ttlMs: (await module.limitsFor(spaceId, entry.document)).timeoutMs
|
|
182
|
+
});
|
|
183
|
+
ownRunId = run.runId;
|
|
184
|
+
/**
|
|
185
|
+
* The renders giving up end the run, not just the wait for it — all of them: a render another visitor joined is
|
|
186
|
+
* that visitor's answer too.
|
|
187
|
+
*
|
|
188
|
+
* `resolveRscData` stops waiting when an element's budget is gone or the browser hung up, and before this the
|
|
189
|
+
* run carried on to its own timeout — holding a slot and an outbound connection for a page already answered.
|
|
190
|
+
*/
|
|
191
|
+
const releaseRenderStop = onAbort(stop, () => run.controller.abort());
|
|
192
|
+
const startedAt = Date.now();
|
|
193
|
+
const summaryOf = (outcome) => ({
|
|
194
|
+
actionId: entry.id,
|
|
195
|
+
runId: run.runId,
|
|
196
|
+
trigger: "render",
|
|
197
|
+
startedAt,
|
|
198
|
+
endedAt: Date.now(),
|
|
199
|
+
...outcome
|
|
200
|
+
});
|
|
201
|
+
try {
|
|
202
|
+
const result = await module.runAction({
|
|
203
|
+
entry,
|
|
204
|
+
input: values,
|
|
205
|
+
spaceId,
|
|
206
|
+
environment,
|
|
207
|
+
trigger: "render",
|
|
208
|
+
user,
|
|
209
|
+
callerId,
|
|
210
|
+
runId: run.runId,
|
|
211
|
+
at,
|
|
212
|
+
signal: run.controller.signal
|
|
213
|
+
});
|
|
214
|
+
/**
|
|
215
|
+
* A run that did not COMPLETE resolved nothing, and must not look like one that resolved to nothing.
|
|
216
|
+
*
|
|
217
|
+
* A step that throws — an outbound call with no internet behind it, a `flow.fail` guard, a timeout — ends
|
|
218
|
+
* the run with `status: 'failed'` and an empty output, which published as a slice is indistinguishable
|
|
219
|
+
* from a provider that legitimately returned no records. The element then renders its empty state instead
|
|
220
|
+
* of its error one, and the bindings meant for exactly this (`hasError`, `errorMessage`) never fire: the
|
|
221
|
+
* page says "nothing here" when the truth is "this could not be fetched".
|
|
222
|
+
*/
|
|
223
|
+
const summary = summaryOf({
|
|
224
|
+
status: result.status,
|
|
225
|
+
steps: result.steps
|
|
226
|
+
});
|
|
227
|
+
if (result.status !== "completed") {
|
|
228
|
+
const said = result.error ?? result.steps.find((step) => step.status === "failed")?.error;
|
|
229
|
+
throw new RenderRunFailure(`Action "${actionId}" ended as ${result.status}${result.code ? `, refused (${result.code})` : ""}${said ? `: ${said}` : ""}`, summary, result.error === void 0 ? { refused: false } : {
|
|
230
|
+
refused: true,
|
|
231
|
+
said: result.error
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
output: result.output,
|
|
236
|
+
summary
|
|
237
|
+
};
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (error instanceof RenderRunFailure) throw error;
|
|
240
|
+
if (error instanceof ActionRunError) {
|
|
241
|
+
const status = error.reason === "aborted" ? "aborted" : "failed";
|
|
242
|
+
throw new RenderRunFailure(`Action "${actionId}" refused this render: ${error.reason}${error.message && error.message !== error.reason ? ` — ${error.message}` : ""}`, summaryOf({
|
|
243
|
+
status,
|
|
244
|
+
steps: error.steps ?? [],
|
|
245
|
+
error: error.message
|
|
246
|
+
}), { cause: error });
|
|
247
|
+
}
|
|
248
|
+
throw new RenderRunFailure(error instanceof Error ? error.message : String(error), summaryOf({
|
|
249
|
+
status: "failed",
|
|
250
|
+
steps: [],
|
|
251
|
+
error: "Action failed"
|
|
252
|
+
}), { cause: error });
|
|
253
|
+
} finally {
|
|
254
|
+
releaseRenderStop();
|
|
255
|
+
await module.guards.end(run);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
let told = false;
|
|
259
|
+
const record = (summary) => {
|
|
260
|
+
if (!told) {
|
|
261
|
+
told = true;
|
|
262
|
+
(req.ctx.actionRuns ??= []).push({
|
|
263
|
+
...summary,
|
|
264
|
+
elementId: element.id
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* The page stopped waiting — the section's budget ran out — and is answered without it: said NOW, while the page
|
|
270
|
+
* still has the request's runs to send. The run itself ends a moment later, aborted, when the page has gone; told
|
|
271
|
+
* then, a debugger would never hear of the one run it needed to — the slow one.
|
|
272
|
+
*/
|
|
273
|
+
const askedAt = Date.now();
|
|
274
|
+
const stopWaiting = onAbort(signal, () => {
|
|
275
|
+
record({
|
|
276
|
+
actionId: entry.id,
|
|
277
|
+
runId: ownRunId ?? `render:${randomUUID()}`,
|
|
278
|
+
trigger: "render",
|
|
279
|
+
status: "aborted",
|
|
280
|
+
startedAt: askedAt,
|
|
281
|
+
endedAt: Date.now(),
|
|
282
|
+
steps: [],
|
|
283
|
+
error: "Still running when the page stopped waiting for it: it took longer than a section is given"
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
/**
|
|
287
|
+
* Everyone asking the same question at once gets one run, and its answer.
|
|
288
|
+
*
|
|
289
|
+
* Not an optimisation — it is what makes a page survive being read. Without it, a thousand visitors of one URL
|
|
290
|
+
* are a thousand identical flows and a thousand identical outbound requests, arriving at whatever the action
|
|
291
|
+
* reads all in the same instant.
|
|
292
|
+
*/
|
|
293
|
+
try {
|
|
294
|
+
const { output, summary } = await share.run(key, ttlMs, startRun, signal);
|
|
295
|
+
record(summary);
|
|
296
|
+
return output;
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (error instanceof RenderRunFailure) record(error.summary);
|
|
299
|
+
throw error;
|
|
300
|
+
} finally {
|
|
301
|
+
stopWaiting();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
// src/render/protocol.ts
|
|
306
|
+
/** Where a worker answers a page server's server elements (`render.secret`): never a browser's, never routed to it. */
|
|
307
|
+
var RENDER_PATH = "/_render";
|
|
308
|
+
/**
|
|
309
|
+
* The version of what a page server and a worker say to each other at {@link RENDER_PATH}, `major.minor` as the
|
|
310
|
+
* functions protocol's (D14): a minor adds what the other may ignore, a major is refused both ways, naming which side
|
|
311
|
+
* to upgrade — so a rolling deploy says why its sections are empty instead of rendering them wrong.
|
|
312
|
+
*/
|
|
313
|
+
var RENDER_PROTOCOL = "1.0";
|
|
314
|
+
var ENVIRONMENTS = [
|
|
315
|
+
"production",
|
|
316
|
+
"staging",
|
|
317
|
+
"development",
|
|
318
|
+
"main"
|
|
319
|
+
];
|
|
320
|
+
/** A body read as an ask, or what is wrong with it — said to the page server, which wrote it. */
|
|
321
|
+
var readRenderAsk = (body) => {
|
|
322
|
+
if (!isRecord(body)) return "A render ask is a JSON object";
|
|
323
|
+
const { spaceId, environment, revision, element, subtree, routeParams, queryParams, templateData } = body;
|
|
324
|
+
if (typeof spaceId !== "number" || typeof revision !== "number") return "A render ask names its `spaceId` and `revision`, as numbers";
|
|
325
|
+
if (typeof environment !== "string" || !ENVIRONMENTS.some((each) => each === environment)) return `A render ask names its \`environment\`: one of ${ENVIRONMENTS.join(", ")}`;
|
|
326
|
+
if (!isRecord(element) || typeof element.id !== "string" || !isRecord(subtree)) return "A render ask carries its `element` and the `subtree` under it";
|
|
327
|
+
if (!isRecord(routeParams) || !isRecord(queryParams) || !isRecord(templateData)) return "A render ask carries the visit: `routeParams`, `queryParams` and `templateData`";
|
|
328
|
+
return body;
|
|
329
|
+
};
|
|
330
|
+
// src/render/remote.ts
|
|
331
|
+
/** The element and every element under it, by `definition.items`: what a connector's projection reads. */
|
|
332
|
+
var subtreeOf = (flat, rootId) => {
|
|
333
|
+
const subtree = {};
|
|
334
|
+
const pending = [rootId];
|
|
335
|
+
while (pending.length > 0) {
|
|
336
|
+
const id = pending.pop();
|
|
337
|
+
const element = id === void 0 ? void 0 : flat[id];
|
|
338
|
+
if (id === void 0 || !element || id in subtree) continue;
|
|
339
|
+
subtree[id] = element;
|
|
340
|
+
pending.push(...element.definition.items ?? []);
|
|
341
|
+
}
|
|
342
|
+
return subtree;
|
|
343
|
+
};
|
|
344
|
+
var isAnswer = (value) => isRecord(value) && typeof value.ok === "boolean" && Array.isArray(value.runs);
|
|
345
|
+
/**
|
|
346
|
+
* A page's server elements resolved on a worker (RFC 0032, §4.3): each one asked at `/_render`, so this page server runs
|
|
347
|
+
* no action and no connector, and imports nothing of the engine to run. Handed to it with `engineOnWorker({ render })`.
|
|
348
|
+
*
|
|
349
|
+
* What fed the element comes back with its data — the runs, for a page that debugs — and a failure comes back as one:
|
|
350
|
+
* the element shows its error state, a refusal in the action's own words. A worker that does not answer is that
|
|
351
|
+
* element's failure, said with where it was asked.
|
|
352
|
+
*/
|
|
353
|
+
var createRemoteRenderResolver = ({ url, secret }) => {
|
|
354
|
+
const endpoint = `${url.replace(/\/+$/, "")}${RENDER_PATH}`;
|
|
355
|
+
return async ({ element, input, flat, routeParams, queryParams, templateData, req, spaceId, environment, user, signal }) => {
|
|
356
|
+
const deployment = req.ctx.spaceDeployment;
|
|
357
|
+
const ask = {
|
|
358
|
+
protocol: "1.0",
|
|
359
|
+
spaceId,
|
|
360
|
+
environment: deployment?.environment ?? environment,
|
|
361
|
+
revision: deployment?.revision ?? 0,
|
|
362
|
+
element,
|
|
363
|
+
subtree: subtreeOf(flat, element.id),
|
|
364
|
+
...input === void 0 ? {} : { input },
|
|
365
|
+
routeParams,
|
|
366
|
+
queryParams,
|
|
367
|
+
...req.ctx.rscParams ? { rscParams: req.ctx.rscParams } : {},
|
|
368
|
+
templateData: {
|
|
369
|
+
...templateData,
|
|
370
|
+
paintedKeys: [...templateData.paintedKeys]
|
|
371
|
+
},
|
|
372
|
+
...user ? { user } : {}
|
|
373
|
+
};
|
|
374
|
+
let response;
|
|
375
|
+
try {
|
|
376
|
+
response = await fetch(endpoint, {
|
|
377
|
+
method: "POST",
|
|
378
|
+
headers: {
|
|
379
|
+
"content-type": "application/json",
|
|
380
|
+
authorization: `Bearer ${secret}`
|
|
381
|
+
},
|
|
382
|
+
body: JSON.stringify(ask),
|
|
383
|
+
signal
|
|
384
|
+
});
|
|
385
|
+
} catch (error) {
|
|
386
|
+
throw new Error(`The worker at ${endpoint} did not answer element ${element.id}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
387
|
+
}
|
|
388
|
+
const body = await response.json().catch(() => void 0);
|
|
389
|
+
if (!isAnswer(body)) {
|
|
390
|
+
const said = isRecord(body) && typeof body.error === "string" ? body.error : `answered ${String(response.status)}`;
|
|
391
|
+
throw new Error(`The worker at ${endpoint} refused element ${element.id}: ${said}`);
|
|
392
|
+
}
|
|
393
|
+
const runs = body.runs;
|
|
394
|
+
(req.ctx.actionRuns ??= []).push(...runs);
|
|
395
|
+
if (body.ok) return body.data;
|
|
396
|
+
const summary = runs.at(-1);
|
|
397
|
+
if (!summary) throw new Error(body.error);
|
|
398
|
+
throw new RenderRunFailure(body.error, summary, body.said === void 0 ? { refused: body.refused } : {
|
|
399
|
+
refused: body.refused,
|
|
400
|
+
said: body.said
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
export { createActionResolver as a, readRenderAsk as i, RENDER_PATH as n, RENDER_PROTOCOL as r, createRemoteRenderResolver as t };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/engine/jobs/storeClock.ts
|
|
2
|
+
/** How long a reading is trusted before it is taken again. */
|
|
3
|
+
var RESYNC_MS = 3e4;
|
|
4
|
+
/** `read` answers the store's own time in epoch ms: `hello.localTime` on Mongo, `NOW(3)` on MySQL. */
|
|
5
|
+
var createStoreClock = (read, resyncMs = RESYNC_MS) => {
|
|
6
|
+
let offset = 0;
|
|
7
|
+
let readAt = Number.NEGATIVE_INFINITY;
|
|
8
|
+
let pending;
|
|
9
|
+
const sync = async () => {
|
|
10
|
+
const before = Date.now();
|
|
11
|
+
const storeTime = await read();
|
|
12
|
+
const after = Date.now();
|
|
13
|
+
offset = storeTime - Math.round((before + after) / 2);
|
|
14
|
+
readAt = after;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
now: async () => {
|
|
18
|
+
if (Date.now() - readAt >= resyncMs) {
|
|
19
|
+
pending ??= sync().finally(() => {
|
|
20
|
+
pending = void 0;
|
|
21
|
+
});
|
|
22
|
+
await pending;
|
|
23
|
+
}
|
|
24
|
+
return Date.now() + offset;
|
|
25
|
+
},
|
|
26
|
+
resync: () => {
|
|
27
|
+
readAt = Number.NEGATIVE_INFINITY;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export { createStoreClock as t };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { I as fetchConnectorRecords } from "./module-WdDzbjHy.mjs";
|
|
2
|
+
import { getSourceName } from "@plitzi/sdk-shared/dataSource/helpers";
|
|
3
|
+
// src/connectors/projection.ts
|
|
4
|
+
/**
|
|
5
|
+
* Structural keys a page needs regardless of what it binds, so paging and empty states never depend on static
|
|
6
|
+
* analysis. A pager binds `pageInfo.*` and an empty state binds `isEmpty`; both would otherwise be projected away
|
|
7
|
+
* for any page that reads neither.
|
|
8
|
+
*/
|
|
9
|
+
var ALWAYS_KEPT = [
|
|
10
|
+
"pageInfo",
|
|
11
|
+
"isEmpty",
|
|
12
|
+
"hasError",
|
|
13
|
+
"errorMessage"
|
|
14
|
+
];
|
|
15
|
+
var createNode = () => ({
|
|
16
|
+
leaf: false,
|
|
17
|
+
children: /* @__PURE__ */ new Map()
|
|
18
|
+
});
|
|
19
|
+
var insert = (root, segments) => {
|
|
20
|
+
let node = root;
|
|
21
|
+
for (const segment of segments) {
|
|
22
|
+
const key = /^\d+$/.test(segment) ? "*" : segment;
|
|
23
|
+
let next = node.children.get(key);
|
|
24
|
+
if (!next) {
|
|
25
|
+
next = createNode();
|
|
26
|
+
node.children.set(key, next);
|
|
27
|
+
}
|
|
28
|
+
node = next;
|
|
29
|
+
}
|
|
30
|
+
node.leaf = true;
|
|
31
|
+
};
|
|
32
|
+
/** Pulls `<source>.<path>` references out of any string that may carry a twig token. */
|
|
33
|
+
var collectFromTemplate = (value, sourceName, found) => {
|
|
34
|
+
if (typeof value !== "string") return;
|
|
35
|
+
const pattern = new RegExp(`${sourceName}\\.([a-zA-Z0-9_\\-.]+)`, "g");
|
|
36
|
+
for (const match of value.matchAll(pattern)) found.add(match[1].replace(/\.$/, ""));
|
|
37
|
+
};
|
|
38
|
+
var walkUnknown = (value, sourceName, found) => {
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
collectFromTemplate(value, sourceName, found);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
value.forEach((entry) => walkUnknown(entry, sourceName, found));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (value !== null && typeof value === "object") Object.values(value).forEach((entry) => walkUnknown(entry, sourceName, found));
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Collects the paths a page actually reads out of one provider source.
|
|
51
|
+
*
|
|
52
|
+
* Bindings declare `<source>.<path>` directly; transformer params, `when` rules and attribute templates can carry
|
|
53
|
+
* the same reference inside a twig token, so both are scanned. Returning an empty set means nothing statically
|
|
54
|
+
* references the source — the caller must then keep the slice whole rather than serve an empty one.
|
|
55
|
+
*/
|
|
56
|
+
var collectBoundPaths = (flat, rootId, sourceName) => {
|
|
57
|
+
if (!sourceName) return [];
|
|
58
|
+
const found = /* @__PURE__ */ new Set();
|
|
59
|
+
const seen = /* @__PURE__ */ new Set();
|
|
60
|
+
const pending = [rootId];
|
|
61
|
+
const prefix = `${sourceName}.`;
|
|
62
|
+
while (pending.length > 0) {
|
|
63
|
+
const id = pending.pop();
|
|
64
|
+
if (id === void 0 || seen.has(id)) continue;
|
|
65
|
+
seen.add(id);
|
|
66
|
+
const element = flat[id];
|
|
67
|
+
if (!element) continue;
|
|
68
|
+
const { bindings, items } = element.definition;
|
|
69
|
+
Object.values(bindings ?? {}).forEach((categoryBindings) => {
|
|
70
|
+
categoryBindings.forEach((binding) => {
|
|
71
|
+
if (binding.source.startsWith(prefix)) found.add(binding.source.slice(prefix.length));
|
|
72
|
+
walkUnknown(binding.transformers, sourceName, found);
|
|
73
|
+
walkUnknown(binding.when, sourceName, found);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
walkUnknown(element.attributes, sourceName, found);
|
|
77
|
+
if (items) pending.push(...items);
|
|
78
|
+
}
|
|
79
|
+
return [...found];
|
|
80
|
+
};
|
|
81
|
+
var projectNode = (value, node) => {
|
|
82
|
+
if (node.leaf || node.children.size === 0) return value;
|
|
83
|
+
if (Array.isArray(value)) {
|
|
84
|
+
const itemNode = node.children.get("*");
|
|
85
|
+
return value.map((item) => projectNode(item, itemNode ?? node));
|
|
86
|
+
}
|
|
87
|
+
if (value === null || typeof value !== "object") return value;
|
|
88
|
+
const source = value;
|
|
89
|
+
return [...node.children.entries()].reduce((acum, [key, child]) => {
|
|
90
|
+
if (key !== "*" && key in source) acum[key] = projectNode(source[key], child);
|
|
91
|
+
return acum;
|
|
92
|
+
}, {});
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Narrows a provider slice to what the page reads.
|
|
96
|
+
*
|
|
97
|
+
* A CMS entry routinely carries fields nobody bound — author emails, internal notes, unpublished translations.
|
|
98
|
+
* Those would otherwise land in the client store and in the HTML, so anything unreferenced is dropped here. With no
|
|
99
|
+
* declared paths the slice passes through untouched: an empty projection would blank the page, and shipping too
|
|
100
|
+
* much is a smaller failure than rendering nothing.
|
|
101
|
+
*/
|
|
102
|
+
var projectSlice = (slice, paths) => {
|
|
103
|
+
if (paths.length === 0 || slice === null || typeof slice !== "object") return slice;
|
|
104
|
+
const root = createNode();
|
|
105
|
+
paths.forEach((path) => insert(root, path.split(".")));
|
|
106
|
+
ALWAYS_KEPT.forEach((key) => insert(root, [key]));
|
|
107
|
+
return projectNode(slice, root);
|
|
108
|
+
};
|
|
109
|
+
// src/connectors/resolver.ts
|
|
110
|
+
var DEFAULT_PAGE_PARAM = "page";
|
|
111
|
+
var toLimit = (limit, singleRecord) => {
|
|
112
|
+
if (singleRecord) return 1;
|
|
113
|
+
const parsed = typeof limit === "string" ? parseInt(limit, 10) : limit;
|
|
114
|
+
return parsed !== void 0 && !Number.isNaN(parsed) ? parsed : void 0;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Reads the requested page out of the request's query string.
|
|
118
|
+
*
|
|
119
|
+
* Both pagination modes arrive here: URL paging puts the parameter in the visitor's address bar, and append mode
|
|
120
|
+
* puts the same parameter on its `/_rsc` refresh. One code path, so a "load more" window and a shared link of the
|
|
121
|
+
* same page resolve to the same records.
|
|
122
|
+
*/
|
|
123
|
+
var toPage = (queryParams, attributes) => {
|
|
124
|
+
if (attributes.pagination === "none" || attributes.singleRecord) return 1;
|
|
125
|
+
const raw = queryParams[attributes.pageParam ?? DEFAULT_PAGE_PARAM];
|
|
126
|
+
const parsed = raw ? parseInt(raw, 10) : NaN;
|
|
127
|
+
return Number.isNaN(parsed) || parsed < 1 ? 1 : parsed;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Bridges the connector engine into the RSC pipeline: reads the provider element's own configuration, resolves its
|
|
131
|
+
* manifest and credential server-side, and returns the slice the element will publish as a binding source.
|
|
132
|
+
*
|
|
133
|
+
* An element without a connector resolves to nothing rather than failing — an unconfigured provider on a page is a
|
|
134
|
+
* draft, not an error.
|
|
135
|
+
*/
|
|
136
|
+
var createConnectorResolver = ({ getConnector, getCredential, fetchImpl }, outbound) => async ({ element, flat, routeParams, queryParams, spaceId, environment, req }) => {
|
|
137
|
+
const deployment = req.ctx.spaceDeployment;
|
|
138
|
+
const at = {
|
|
139
|
+
environment: deployment?.environment ?? environment,
|
|
140
|
+
revision: deployment?.revision ?? 0
|
|
141
|
+
};
|
|
142
|
+
const attributes = element.attributes;
|
|
143
|
+
const { connector: connectorId, endpoint, resource, limit, singleRecord = false, filters } = attributes;
|
|
144
|
+
if (!connectorId) return;
|
|
145
|
+
const manifest = await getConnector(spaceId, connectorId, at);
|
|
146
|
+
if (!manifest) throw new Error(`Connector "${connectorId}" is not configured for space ${spaceId}`);
|
|
147
|
+
const credential = manifest.credential && getCredential ? await getCredential(spaceId, manifest.credential) : void 0;
|
|
148
|
+
const pageSize = toLimit(limit, singleRecord);
|
|
149
|
+
const page = toPage(queryParams, attributes);
|
|
150
|
+
const pageParam = attributes.pageParam ?? DEFAULT_PAGE_PARAM;
|
|
151
|
+
const { records, pageInfo } = await fetchConnectorRecords({
|
|
152
|
+
manifest,
|
|
153
|
+
endpoint,
|
|
154
|
+
credential,
|
|
155
|
+
query: {
|
|
156
|
+
resource,
|
|
157
|
+
limit: pageSize,
|
|
158
|
+
offset: pageSize === void 0 ? void 0 : (page - 1) * pageSize,
|
|
159
|
+
page,
|
|
160
|
+
cursor: queryParams[`${pageParam}Cursor`],
|
|
161
|
+
filters,
|
|
162
|
+
routeParams,
|
|
163
|
+
queryParams
|
|
164
|
+
},
|
|
165
|
+
fetchImpl,
|
|
166
|
+
outbound
|
|
167
|
+
});
|
|
168
|
+
const slice = {
|
|
169
|
+
...singleRecord ? { record: records[0] } : { records },
|
|
170
|
+
pageInfo,
|
|
171
|
+
isEmpty: records.length === 0,
|
|
172
|
+
hasError: false,
|
|
173
|
+
errorMessage: ""
|
|
174
|
+
};
|
|
175
|
+
if (manifest.projection === "full") return slice;
|
|
176
|
+
return projectSlice(slice, collectBoundPaths(flat, element.id, getSourceName(element.definition.type, element.id)));
|
|
177
|
+
};
|
|
178
|
+
// src/engine/taskCatalog.ts
|
|
179
|
+
/** Drops anything JSON cannot carry, at any depth. Functions are the only such value a task declares today. */
|
|
180
|
+
var jsonSafe = (value) => {
|
|
181
|
+
if (typeof value === "function") return;
|
|
182
|
+
if (Array.isArray(value)) return value.map(jsonSafe).filter((item) => item !== void 0);
|
|
183
|
+
if (value !== null && typeof value === "object") return Object.entries(value).reduce((acum, [key, item]) => {
|
|
184
|
+
const safe = jsonSafe(item);
|
|
185
|
+
if (safe !== void 0) acum[key] = safe;
|
|
186
|
+
return acum;
|
|
187
|
+
}, {});
|
|
188
|
+
return value;
|
|
189
|
+
};
|
|
190
|
+
var describeTask = (task) => ({
|
|
191
|
+
name: task.name,
|
|
192
|
+
namespace: task.namespace,
|
|
193
|
+
action: task.action,
|
|
194
|
+
title: task.title,
|
|
195
|
+
description: task.description,
|
|
196
|
+
origin: task.origin,
|
|
197
|
+
params: jsonSafe(task.params)
|
|
198
|
+
});
|
|
199
|
+
/** The whole catalog, in the order the registry holds it. */
|
|
200
|
+
var describeCatalog = (registry) => registry.list().map(describeTask);
|
|
201
|
+
export { describeTask as n, createConnectorResolver as r, describeCatalog as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { fetchConnectorRecords, rebaseMedia, writeConnectorRecord } from './engine';
|
|
2
|
+
export { createConnectorResolver } from './resolver';
|
|
3
|
+
export { getByPath } from './getByPath';
|
|
4
|
+
export { collectBoundPaths, projectSlice } from './projection';
|
|
5
|
+
export type { FetchConnectorOptions, WriteConnectorOptions } from './engine';
|
|
6
|
+
export type { ConnectorLookups, ProviderPagination } from './resolver';
|
|
7
|
+
export type { ConnectorAuth, ConnectorCredential, ConnectorEndpoints, ConnectorFilter, ConnectorManifest, ConnectorManifestDraft, ConnectorPageInfo, ConnectorPagination, ConnectorQuery, ConnectorReadEndpoint, ConnectorRecord, ConnectorResponseMapping, ConnectorResult, ConnectorWriteEndpoint } from './types';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ConnectorCredential, ConnectorManifest, ConnectorQuery, ConnectorRecord, ConnectorResult } from './types';
|
|
2
|
+
import { OutboundOptions } from '@plitzi/sdk-kernel/outbound';
|
|
3
|
+
export type FetchConnectorOptions = {
|
|
4
|
+
manifest: ConnectorManifest;
|
|
5
|
+
/** Which read endpoint to execute. Defaults to `list`, the one an element addresses when it names none. */
|
|
6
|
+
endpoint?: string;
|
|
7
|
+
credential?: ConnectorCredential;
|
|
8
|
+
query?: ConnectorQuery;
|
|
9
|
+
/** Injected so tests — and a future edge runtime — can supply their own transport. */
|
|
10
|
+
fetchImpl?: typeof fetch;
|
|
11
|
+
/** The deployment's own origins on its network a manifest may name (`outbound.privateOrigins`). */
|
|
12
|
+
outbound?: OutboundOptions;
|
|
13
|
+
};
|
|
14
|
+
export type WriteConnectorOptions = {
|
|
15
|
+
manifest: ConnectorManifest;
|
|
16
|
+
credential?: ConnectorCredential;
|
|
17
|
+
/** Name of the write endpoint to execute, as declared in the manifest. */
|
|
18
|
+
action: string;
|
|
19
|
+
resource?: string;
|
|
20
|
+
recordId?: string;
|
|
21
|
+
values?: Record<string, unknown>;
|
|
22
|
+
fetchImpl?: typeof fetch;
|
|
23
|
+
/** The deployment's own origins on its network a manifest may name (`outbound.privateOrigins`). */
|
|
24
|
+
outbound?: OutboundOptions;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Rebases the relative media paths a CMS returns (`/uploads/cover.jpg`) onto the manifest's media host.
|
|
28
|
+
*
|
|
29
|
+
* The rule is keyed on the property name, not on the value: a body field whose text happens to start with a slash
|
|
30
|
+
* must never be rewritten, and only a name ending in `url`, `src` or `href` claims to hold a location. Protocol
|
|
31
|
+
* relative values are already absolute enough and are left alone.
|
|
32
|
+
*/
|
|
33
|
+
export declare const rebaseMedia: (value: unknown, baseUrl: string) => unknown;
|
|
34
|
+
/**
|
|
35
|
+
* Executes one connector read and normalizes the response into records + page info.
|
|
36
|
+
*
|
|
37
|
+
* Everything provider-specific — the endpoint, the auth header, where the array lives, how paging is expressed —
|
|
38
|
+
* comes from the manifest, so a new CMS is configuration rather than code.
|
|
39
|
+
*/
|
|
40
|
+
export declare const fetchConnectorRecords: ({ manifest, endpoint, credential, query, fetchImpl, outbound }: FetchConnectorOptions) => Promise<ConnectorResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Executes one connector write.
|
|
43
|
+
*
|
|
44
|
+
* An action the manifest does not declare is refused rather than inferred: a connector is read-only until its
|
|
45
|
+
* owner says otherwise, so a form can never reach a provider that was never meant to be written to.
|
|
46
|
+
*/
|
|
47
|
+
export declare const writeConnectorRecord: ({ manifest, credential, action, resource, recordId, values, fetchImpl, outbound }: WriteConnectorOptions) => Promise<ConnectorRecord | undefined>;
|