@powerhousedao/switchboard 6.2.3-dev.84 → 6.2.3-dev.85
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/.tsbuild/test/workflow/waitpoint-routes.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-routes.test.d.ts.map +1 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts +2 -0
- package/.tsbuild/test/workflow/waitpoint-runtime.test.d.ts.map +1 -0
- package/.tsbuild/tsconfig.tsbuildinfo +1 -1
- package/CHANGELOG.md +13 -0
- package/dist/index.mjs +11 -8
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/attachments.mjs +3 -3
- package/dist/plugins/workflows.mjs +3 -3
- package/dist/{server-B3qhPKNn.mjs → server-YNY3Qw9a.mjs} +4 -4
- package/dist/{server-B3qhPKNn.mjs.map → server-YNY3Qw9a.mjs.map} +1 -1
- package/dist/server.mjs +3 -3
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -1
- package/dist/{workflows-B1VsL5Lo.mjs → workflows-DkIrfmdn.mjs} +445 -9
- package/dist/workflows-DkIrfmdn.mjs.map +1 -0
- package/package.json +16 -16
- package/test/goldens/packages.graphql +1 -1
- package/test/goldens/privacy.graphql +1 -1
- package/test/goldens/reactor-drive-nodes.graphql +1 -1
- package/test/goldens/resolvers.json +4 -0
- package/test/goldens/supergraph.graphql +95 -1
- package/test/goldens/workflow-runtime.graphql +95 -1
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/workflow/resolvers.test.ts +106 -0
- package/test/workflow/waitpoint-routes.test.ts +284 -0
- package/test/workflow/waitpoint-runtime.test.ts +204 -0
- package/dist/workflows-B1VsL5Lo.mjs.map +0 -1
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as StoredDocumentsRefusedError, r as resolveUnsupportedStoredDocuments } from "./from-env-BO0n9R02.mjs";
|
|
3
|
-
import { a as resolvePgliteStorageDirs, i as isPortAvailable, l as applySwitchboardReactorDefaults, n as deriveAttachmentServiceConfig, o as startSwitchboard, r as initSwitchboardProcess, t as createReactorKysely } from "./server-
|
|
3
|
+
import { a as resolvePgliteStorageDirs, i as isPortAvailable, l as applySwitchboardReactorDefaults, n as deriveAttachmentServiceConfig, o as startSwitchboard, r as initSwitchboardProcess, t as createReactorKysely } from "./server-YNY3Qw9a.mjs";
|
|
4
4
|
export { StoredDocumentsRefusedError, applySwitchboardReactorDefaults, createReactorKysely, deriveAttachmentServiceConfig, initSwitchboardProcess, isPortAvailable, resolvePgliteStorageDirs, resolveUnsupportedStoredDocuments, startSwitchboard };
|
|
5
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
6
|
-
//# debugId=
|
|
5
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="08f0a326-294b-5287-a9a0-7d660e42f79b")}catch(e){}}();
|
|
6
|
+
//# debugId=08f0a326-294b-5287-a9a0-7d660e42f79b
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-runtime-7GaJ13c9.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"workflow-runtime-7GaJ13c9.d.mts","names":[],"sources":["../src/workflow-runtime.mts"],"mappings":";;;;;;;;;KAsEY;EACN;;EAEA;EACA;;UAgQW;EACf,UAAU;;;WAGD,UAAU;;;EAGnB;EACA,SAAS;EACT,QAAQ"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c8f32b53-08da-5217-b7ec-200b108fa949")}catch(e){}}();
|
|
3
3
|
import { REACTOR_SCHEMA, supportsLiveReadModelRegistration } from "@powerhousedao/reactor";
|
|
4
4
|
import { AuthorizationPolicy, BaseSubgraph, ForbiddenError, callerSubject, createCanonicalDocumentIdResolver } from "@powerhousedao/reactor-api";
|
|
5
5
|
import { hostname } from "node:os";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { parseRef } from "@powerhousedao/reactor-attachments";
|
|
8
|
+
import { waitpointRecord } from "@powerhousedao/reactor-workflow";
|
|
8
9
|
import { GraphQLError, Kind } from "graphql";
|
|
9
10
|
import { gql } from "graphql-tag";
|
|
10
11
|
//#region src/fatal-shutdown.mts
|
|
@@ -72,7 +73,7 @@ function triggerFatalShutdown(kind, err, proc = process) {
|
|
|
72
73
|
//#endregion
|
|
73
74
|
//#region src/workflow/oauth-callback.ts
|
|
74
75
|
const OAUTH_CALLBACK_PATH = "oauth/callback";
|
|
75
|
-
function escapeHtml(text) {
|
|
76
|
+
function escapeHtml$1(text) {
|
|
76
77
|
return text.replace(/[&<>"']/g, (char) => ({
|
|
77
78
|
"&": "&",
|
|
78
79
|
"<": "<",
|
|
@@ -87,7 +88,7 @@ function resultPage(ok, detail) {
|
|
|
87
88
|
<html><head><meta charset="utf-8"><title>${title}</title>
|
|
88
89
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
89
90
|
<style>body{font:15px system-ui,sans-serif;margin:0;display:grid;place-items:center;min-height:100vh;background:#fafafa;color:#222}main{max-width:28rem;padding:1.5rem;text-align:center}h1{font-size:1.1rem}</style>
|
|
90
|
-
</head><body><main><h1>${title}</h1><p>${ok ? "You can close this window." : escapeHtml(detail ?? "The sign-in did not finish.")}</p></main>
|
|
91
|
+
</head><body><main><h1>${title}</h1><p>${ok ? "You can close this window." : escapeHtml$1(detail ?? "The sign-in did not finish.")}</p></main>
|
|
91
92
|
${ok ? "<script>setTimeout(function(){window.close()},600)<\/script>" : ""}
|
|
92
93
|
</body></html>`;
|
|
93
94
|
}
|
|
@@ -130,6 +131,297 @@ function callbackUrlOf(http) {
|
|
|
130
131
|
return `${http.baseUrl.replace(/\/+$/, "")}/${OAUTH_CALLBACK_PATH}`;
|
|
131
132
|
}
|
|
132
133
|
//#endregion
|
|
134
|
+
//#region src/workflow/waitpoint-routes.ts
|
|
135
|
+
const WAITPOINT_PATH = "waitpoints";
|
|
136
|
+
const MAX_REASON_LENGTH = 2e3;
|
|
137
|
+
const MAX_BODY_BYTES = 1048576;
|
|
138
|
+
const PAGE_HEADERS = {
|
|
139
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'",
|
|
140
|
+
"x-content-type-options": "nosniff",
|
|
141
|
+
"cache-control": "no-store",
|
|
142
|
+
"referrer-policy": "no-referrer"
|
|
143
|
+
};
|
|
144
|
+
const DROPPED_HEADERS = /* @__PURE__ */ new Set([
|
|
145
|
+
"authorization",
|
|
146
|
+
"cookie",
|
|
147
|
+
"proxy-authorization"
|
|
148
|
+
]);
|
|
149
|
+
function waitpointBaseUrlOf(http) {
|
|
150
|
+
const url = `${http.baseUrl.replace(/\/+$/, "")}/${WAITPOINT_PATH}`;
|
|
151
|
+
return URL.canParse(url) ? url : void 0;
|
|
152
|
+
}
|
|
153
|
+
function registerWaitpointRoutes(http, runtime) {
|
|
154
|
+
const route = (method, subPath) => http.route({
|
|
155
|
+
method,
|
|
156
|
+
path: [
|
|
157
|
+
WAITPOINT_PATH,
|
|
158
|
+
":token",
|
|
159
|
+
subPath
|
|
160
|
+
].filter(Boolean).join("/"),
|
|
161
|
+
auth: "public",
|
|
162
|
+
maxBodyBytes: MAX_BODY_BYTES,
|
|
163
|
+
handler: (request, ctx) => handleWaitpointRequest(runtime, request, ctx.params.token, subPath)
|
|
164
|
+
});
|
|
165
|
+
return [
|
|
166
|
+
route([
|
|
167
|
+
"GET",
|
|
168
|
+
"HEAD",
|
|
169
|
+
"POST"
|
|
170
|
+
], ""),
|
|
171
|
+
route([
|
|
172
|
+
"GET",
|
|
173
|
+
"HEAD",
|
|
174
|
+
"POST"
|
|
175
|
+
], "sync"),
|
|
176
|
+
route([
|
|
177
|
+
"GET",
|
|
178
|
+
"HEAD",
|
|
179
|
+
"POST"
|
|
180
|
+
], "confirm")
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
async function handleWaitpointRequest(runtime, request, token, subPath) {
|
|
184
|
+
const method = request.method.toUpperCase();
|
|
185
|
+
const url = new URL(request.url);
|
|
186
|
+
const queryParams = Object.fromEntries(url.searchParams);
|
|
187
|
+
if (method === "GET" || method === "HEAD") {
|
|
188
|
+
if (subPath === "confirm") return confirmPage(runtime, token, queryParams, "");
|
|
189
|
+
if (subPath === "") return confirmPage(runtime, token, queryParams, url.pathname.endsWith("/") ? "confirm" : `${encodeURIComponent(token)}/confirm`);
|
|
190
|
+
return json(405, "Use POST to resume, or open the /confirm page", { allow: "POST" });
|
|
191
|
+
}
|
|
192
|
+
const headers = headerRecord(request);
|
|
193
|
+
const body = await readBody(request, headers["content-type"]);
|
|
194
|
+
const html = subPath === "confirm" && fromBrowser(headers);
|
|
195
|
+
let payloadBody = body;
|
|
196
|
+
if (subPath === "confirm") {
|
|
197
|
+
const action = queryParams.action;
|
|
198
|
+
if (action !== "approve" && action !== "disapprove") return refuse(html, 400, "Nothing was recorded", "This link needs to say whether you approve or disapprove. Open it in a browser and use one of the buttons.");
|
|
199
|
+
const reason = readReason(body) || queryParams.reason || void 0;
|
|
200
|
+
if (reason !== void 0 && reason.length > 2e3) return refuse(html, 400, "Your reason is too long", `Keep it under ${MAX_REASON_LENGTH} characters and submit again. Nothing was recorded.`);
|
|
201
|
+
if (reason !== void 0) {
|
|
202
|
+
queryParams.reason = reason;
|
|
203
|
+
payloadBody = {
|
|
204
|
+
...body && typeof body === "object" ? body : {},
|
|
205
|
+
reason
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const payload = {
|
|
210
|
+
body: payloadBody,
|
|
211
|
+
headers,
|
|
212
|
+
queryParams
|
|
213
|
+
};
|
|
214
|
+
if (subPath === "sync") {
|
|
215
|
+
const { status, reply } = await runtime.resumeWaitpointByTokenSync(token, payload);
|
|
216
|
+
if (status === "resumed" && reply) return replyResponse(reply);
|
|
217
|
+
return status === "resumed" ? json(200, recordedMessage(queryParams.action), void 0, status) : json(status === "already" ? 200 : 410, status === "already" ? "This request was already responded to." : "This request is no longer waiting.", void 0, status);
|
|
218
|
+
}
|
|
219
|
+
const { status } = await runtime.resumeWaitpointByToken(token, payload);
|
|
220
|
+
if (status === "resumed") {
|
|
221
|
+
const message = recordedMessage(queryParams.action);
|
|
222
|
+
return html ? page(200, {
|
|
223
|
+
title: "Response recorded",
|
|
224
|
+
message,
|
|
225
|
+
tone: "done"
|
|
226
|
+
}) : json(200, message, void 0, status);
|
|
227
|
+
}
|
|
228
|
+
if (status === "already") return html ? page(200, ALREADY) : json(200, "This request was already responded to.", void 0, status);
|
|
229
|
+
return html ? page(410, EXPIRED) : json(410, "This request is no longer waiting.", void 0, status);
|
|
230
|
+
}
|
|
231
|
+
async function confirmPage(runtime, token, queryParams, target) {
|
|
232
|
+
const described = await runtime.describeWaitpointByToken(token);
|
|
233
|
+
if (!described) return page(404, {
|
|
234
|
+
title: "Link not found",
|
|
235
|
+
message: "This link is not valid, or it has been removed.",
|
|
236
|
+
tone: "closed"
|
|
237
|
+
});
|
|
238
|
+
if (described.status === "COMPLETED" || described.status === "CONSUMED") return page(200, {
|
|
239
|
+
...ALREADY,
|
|
240
|
+
context: described
|
|
241
|
+
});
|
|
242
|
+
if (described.status === "CANCELLED") return page(200, {
|
|
243
|
+
title: "Run cancelled",
|
|
244
|
+
message: "This run was cancelled. There is nothing left to do here.",
|
|
245
|
+
tone: "closed",
|
|
246
|
+
context: described
|
|
247
|
+
});
|
|
248
|
+
if (described.status === "EXPIRED") return page(200, {
|
|
249
|
+
...EXPIRED,
|
|
250
|
+
context: described
|
|
251
|
+
});
|
|
252
|
+
return page(200, {
|
|
253
|
+
title: "Confirm your response",
|
|
254
|
+
message: "This workflow is paused and waiting for your response.",
|
|
255
|
+
tone: "open",
|
|
256
|
+
context: described,
|
|
257
|
+
form: {
|
|
258
|
+
approveUrl: actionUrl(target, queryParams, "approve"),
|
|
259
|
+
disapproveUrl: actionUrl(target, queryParams, "disapprove")
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function actionUrl(target, queryParams, action) {
|
|
264
|
+
const params = new URLSearchParams(queryParams);
|
|
265
|
+
params.set("action", action);
|
|
266
|
+
return `${target}?${params.toString()}`;
|
|
267
|
+
}
|
|
268
|
+
function headerRecord(request) {
|
|
269
|
+
const headers = {};
|
|
270
|
+
request.headers.forEach((value, name) => {
|
|
271
|
+
if (!DROPPED_HEADERS.has(name)) headers[name] = value;
|
|
272
|
+
});
|
|
273
|
+
return headers;
|
|
274
|
+
}
|
|
275
|
+
async function readBody(request, contentType = "") {
|
|
276
|
+
const text = await request.text();
|
|
277
|
+
if (text === "") return void 0;
|
|
278
|
+
if (contentType.startsWith("application/x-www-form-urlencoded")) return Object.fromEntries(new URLSearchParams(text));
|
|
279
|
+
if (contentType.includes("json")) try {
|
|
280
|
+
return JSON.parse(text);
|
|
281
|
+
} catch {
|
|
282
|
+
return text;
|
|
283
|
+
}
|
|
284
|
+
return text;
|
|
285
|
+
}
|
|
286
|
+
function fromBrowser(headers) {
|
|
287
|
+
return (headers["content-type"] ?? "").startsWith("application/x-www-form-urlencoded") || (headers.accept ?? "").includes("text/html");
|
|
288
|
+
}
|
|
289
|
+
function readReason(body) {
|
|
290
|
+
if (!body || typeof body !== "object") return void 0;
|
|
291
|
+
const reason = body.reason;
|
|
292
|
+
return typeof reason === "string" ? reason : void 0;
|
|
293
|
+
}
|
|
294
|
+
function recordedMessage(action) {
|
|
295
|
+
if (action === "approve") return "You approved this request.";
|
|
296
|
+
if (action === "disapprove") return "You disapproved this request.";
|
|
297
|
+
return "Your response has been recorded.";
|
|
298
|
+
}
|
|
299
|
+
function refuse(html, status, title, message) {
|
|
300
|
+
return html ? page(status, {
|
|
301
|
+
title,
|
|
302
|
+
message,
|
|
303
|
+
tone: "closed"
|
|
304
|
+
}) : json(status, message);
|
|
305
|
+
}
|
|
306
|
+
function replyResponse(reply) {
|
|
307
|
+
const body = [
|
|
308
|
+
204,
|
|
309
|
+
205,
|
|
310
|
+
304
|
|
311
|
+
].includes(reply.status) ? void 0 : reply.body;
|
|
312
|
+
return new Response(body ?? null, {
|
|
313
|
+
status: reply.status,
|
|
314
|
+
headers: {
|
|
315
|
+
"cache-control": "no-store",
|
|
316
|
+
...reply.headers,
|
|
317
|
+
...body !== void 0 ? { "content-type": reply.contentType ?? "text/plain" } : {}
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function json(status, message, headers, outcome) {
|
|
322
|
+
return new Response(JSON.stringify(outcome ? {
|
|
323
|
+
status: outcome,
|
|
324
|
+
message
|
|
325
|
+
} : { message }), {
|
|
326
|
+
status,
|
|
327
|
+
headers: {
|
|
328
|
+
"content-type": "application/json",
|
|
329
|
+
"cache-control": "no-store",
|
|
330
|
+
...headers
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
const ALREADY = {
|
|
335
|
+
title: "Already responded",
|
|
336
|
+
message: "This request was already responded to. There is nothing left to do here.",
|
|
337
|
+
tone: "closed"
|
|
338
|
+
};
|
|
339
|
+
const EXPIRED = {
|
|
340
|
+
title: "Request expired",
|
|
341
|
+
message: "This request is no longer waiting for a response.",
|
|
342
|
+
tone: "closed"
|
|
343
|
+
};
|
|
344
|
+
function page(status, content) {
|
|
345
|
+
return new Response(renderPage(content), {
|
|
346
|
+
status,
|
|
347
|
+
headers: {
|
|
348
|
+
"content-type": "text/html; charset=utf-8",
|
|
349
|
+
...PAGE_HEADERS
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
function escapeHtml(value) {
|
|
354
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
355
|
+
}
|
|
356
|
+
const STYLE = `
|
|
357
|
+
:root { color-scheme: light dark; --bg: #fafafa; --card: #fff; --fg: #0a0a0a; --muted: #6b7280; --line: #e5e7eb; --ok: #059669; --no: #dc2626; }
|
|
358
|
+
@media (prefers-color-scheme: dark) { :root { --bg: #0a0a0a; --card: #171717; --fg: #fafafa; --muted: #a3a3a3; --line: #262626; } }
|
|
359
|
+
* { box-sizing: border-box; }
|
|
360
|
+
body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); color: var(--fg); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
|
361
|
+
main { width: 440px; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
|
|
362
|
+
h1 { font-size: 20px; margin: 0 0 8px; }
|
|
363
|
+
p { margin: 0 0 16px; color: var(--muted); }
|
|
364
|
+
dl { margin: 0 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
|
|
365
|
+
dt { color: var(--muted); } dd { margin: 0; overflow-wrap: anywhere; }
|
|
366
|
+
.description { color: var(--fg); white-space: pre-line; }
|
|
367
|
+
label { display: block; font-weight: 500; margin-bottom: 4px; }
|
|
368
|
+
textarea { width: 100%; min-height: 72px; resize: vertical; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: inherit; font: inherit; }
|
|
369
|
+
.actions { display: flex; gap: 8px; margin-top: 16px; }
|
|
370
|
+
button { flex: 1; height: 36px; border: 0; border-radius: 8px; color: #fff; font: inherit; font-weight: 500; cursor: pointer; }
|
|
371
|
+
.approve { background: var(--ok); } .disapprove { background: var(--no); }
|
|
372
|
+
.done h1 { color: var(--ok); }
|
|
373
|
+
`;
|
|
374
|
+
function formatTime(iso) {
|
|
375
|
+
if (!iso) return void 0;
|
|
376
|
+
const time = new Date(iso);
|
|
377
|
+
if (Number.isNaN(time.getTime())) return void 0;
|
|
378
|
+
return `${time.toLocaleString("en-GB", {
|
|
379
|
+
dateStyle: "medium",
|
|
380
|
+
timeStyle: "short",
|
|
381
|
+
timeZone: "UTC"
|
|
382
|
+
})} UTC`;
|
|
383
|
+
}
|
|
384
|
+
function contextRows(context) {
|
|
385
|
+
const started = formatTime(context.startedAt);
|
|
386
|
+
return [
|
|
387
|
+
["Workflow", context.workflowName || void 0],
|
|
388
|
+
["Step", context.actionName && context.actionName.toLowerCase() !== context.stepName.toLowerCase() ? `${context.stepName} · ${context.actionName}` : context.stepName],
|
|
389
|
+
["Started", started && context.triggerName ? `${started}, by ${context.triggerName}` : started],
|
|
390
|
+
["Waiting since", formatTime(context.waitingSince)],
|
|
391
|
+
["Expires", formatTime(context.expiresAt)]
|
|
392
|
+
].filter((row) => row[1] !== void 0).map(([term, value]) => `<dt>${term}</dt><dd>${escapeHtml(value)}</dd>`).join("");
|
|
393
|
+
}
|
|
394
|
+
function renderPage({ title, message, tone, context, form }) {
|
|
395
|
+
const description = context?.workflowDescription ? `<p class="description">${escapeHtml(context.workflowDescription)}</p>` : "";
|
|
396
|
+
const details = context ? `${description}<dl>${contextRows(context)}</dl>` : "";
|
|
397
|
+
const actions = form ? `<form method="post">
|
|
398
|
+
<label for="reason">Reason (optional)</label>
|
|
399
|
+
<textarea id="reason" name="reason" maxlength="${MAX_REASON_LENGTH}"></textarea>
|
|
400
|
+
<div class="actions">
|
|
401
|
+
<button type="submit" class="disapprove" formaction="${escapeHtml(form.disapproveUrl)}">Disapprove</button>
|
|
402
|
+
<button type="submit" class="approve" formaction="${escapeHtml(form.approveUrl)}">Approve</button>
|
|
403
|
+
</div>
|
|
404
|
+
</form>` : "";
|
|
405
|
+
return `<!doctype html>
|
|
406
|
+
<html lang="en">
|
|
407
|
+
<head>
|
|
408
|
+
<meta charset="utf-8">
|
|
409
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
410
|
+
<meta name="robots" content="noindex">
|
|
411
|
+
<title>${escapeHtml(title)}</title>
|
|
412
|
+
<style>${STYLE}</style>
|
|
413
|
+
</head>
|
|
414
|
+
<body>
|
|
415
|
+
<main class="${tone}">
|
|
416
|
+
<h1>${escapeHtml(title)}</h1>
|
|
417
|
+
<p>${escapeHtml(message)}</p>
|
|
418
|
+
${details}
|
|
419
|
+
${actions}
|
|
420
|
+
</main>
|
|
421
|
+
</body>
|
|
422
|
+
</html>`;
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
133
425
|
//#region src/workflow/resolvers.ts
|
|
134
426
|
const PIECE_SOURCES = [
|
|
135
427
|
"local",
|
|
@@ -212,7 +504,7 @@ function toStepRecord(row) {
|
|
|
212
504
|
versionNote: row.version_note
|
|
213
505
|
};
|
|
214
506
|
}
|
|
215
|
-
function toRunRecord(row, steps) {
|
|
507
|
+
function toRunRecord(row, steps, waitpoints) {
|
|
216
508
|
return {
|
|
217
509
|
id: row.id,
|
|
218
510
|
workflowId: row.workflow_id,
|
|
@@ -228,7 +520,53 @@ function toRunRecord(row, steps) {
|
|
|
228
520
|
rerunOf: row.rerun_of,
|
|
229
521
|
warnings: row.warnings,
|
|
230
522
|
warningNotes: parseJson(row.warning_notes) ?? [],
|
|
231
|
-
steps: steps.map(toStepRecord)
|
|
523
|
+
steps: steps.map(toStepRecord),
|
|
524
|
+
waitpoints
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function waitpointLoader(runtime) {
|
|
528
|
+
const cache = /* @__PURE__ */ new Map();
|
|
529
|
+
let batch = null;
|
|
530
|
+
return (runId) => {
|
|
531
|
+
const cached = cache.get(runId);
|
|
532
|
+
if (cached) return cached;
|
|
533
|
+
if (!batch) {
|
|
534
|
+
const ids = [];
|
|
535
|
+
batch = {
|
|
536
|
+
ids,
|
|
537
|
+
rows: new Promise((tick) => {
|
|
538
|
+
Promise.resolve().then(() => process.nextTick(tick));
|
|
539
|
+
}).then(async () => {
|
|
540
|
+
batch = null;
|
|
541
|
+
const store = await runtime.store();
|
|
542
|
+
return store ? store.listWaitpointsForRuns(ids) : /* @__PURE__ */ new Map();
|
|
543
|
+
})
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
batch.ids.push(runId);
|
|
547
|
+
const promise = batch.rows.then((rows) => (rows.get(runId) ?? []).map(waitpointRecord));
|
|
548
|
+
cache.set(runId, promise);
|
|
549
|
+
return promise;
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function toRunPayload(row, steps) {
|
|
553
|
+
return {
|
|
554
|
+
runId: row.id,
|
|
555
|
+
status: row.status,
|
|
556
|
+
error: row.error,
|
|
557
|
+
errorName: row.error_name,
|
|
558
|
+
steps: steps.map((step) => ({
|
|
559
|
+
stepId: step.step_id,
|
|
560
|
+
key: step.step_key,
|
|
561
|
+
pieceName: step.piece_name,
|
|
562
|
+
blockName: step.block_name,
|
|
563
|
+
status: step.status,
|
|
564
|
+
input: parseJson(step.input),
|
|
565
|
+
output: parseJson(step.output),
|
|
566
|
+
port: step.port,
|
|
567
|
+
error: step.error,
|
|
568
|
+
errorName: step.error_name
|
|
569
|
+
}))
|
|
232
570
|
};
|
|
233
571
|
}
|
|
234
572
|
const UNKNOWN_ACCESS = {
|
|
@@ -268,6 +606,15 @@ function returnUrlFor(requested, ctx) {
|
|
|
268
606
|
return url.href;
|
|
269
607
|
}
|
|
270
608
|
const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) => {
|
|
609
|
+
const loaders = /* @__PURE__ */ new WeakMap();
|
|
610
|
+
const loadWaitpoints = (runId, ctx) => {
|
|
611
|
+
let load = loaders.get(ctx);
|
|
612
|
+
if (!load) {
|
|
613
|
+
load = waitpointLoader(runtime);
|
|
614
|
+
loaders.set(ctx, load);
|
|
615
|
+
}
|
|
616
|
+
return load(runId);
|
|
617
|
+
};
|
|
271
618
|
return {
|
|
272
619
|
Query: { workflowRuntime: () => ({}) },
|
|
273
620
|
WorkflowRuntimeQueries: {
|
|
@@ -359,8 +706,14 @@ const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) =>
|
|
|
359
706
|
run: async (_parent, args, ctx) => {
|
|
360
707
|
const record = await runtime.run(args.id, ctx);
|
|
361
708
|
return record ? toRunRecord(record.row, record.steps) : null;
|
|
362
|
-
}
|
|
709
|
+
},
|
|
710
|
+
waitingRuns: async (_parent, args, ctx) => (await runtime.waitingRuns({
|
|
711
|
+
driveId: args.driveId ?? void 0,
|
|
712
|
+
workflowId: args.workflowId ?? void 0,
|
|
713
|
+
first: args.first ?? void 0
|
|
714
|
+
}, ctx)).map(({ run, waitpoints }) => toRunRecord(run.row, run.steps, waitpoints))
|
|
363
715
|
},
|
|
716
|
+
WorkflowRunRecord: { waitpoints: (parent, _args, ctx) => parent.waitpoints ?? loadWaitpoints(parent.id, ctx) },
|
|
364
717
|
Mutation: { workflowRuntime: () => ({}) },
|
|
365
718
|
WorkflowRuntimeMutations: {
|
|
366
719
|
fire: (_parent, args, ctx) => runtime.fire(args.workflowId, args.payload, "manual", void 0, ctx),
|
|
@@ -373,6 +726,14 @@ const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) =>
|
|
|
373
726
|
cancelTriggerTest: (_parent, args, ctx) => runtime.cancelTriggerTestFor(args.workflowId, ctx),
|
|
374
727
|
testStep: (_parent, args, ctx) => syncAware(() => runtime.testStep(args.workflowId, args.stepId, ctx, { driveId: args.driveId ?? void 0 })),
|
|
375
728
|
rerun: (_parent, args, ctx) => runtime.rerun(args.runId, ctx),
|
|
729
|
+
resolveWaitpoint: (_parent, args, ctx) => runtime.resolveWaitpoint(args.waitpointId, {
|
|
730
|
+
approved: args.approved,
|
|
731
|
+
...args.reason ? { reason: args.reason } : {}
|
|
732
|
+
}, ctx),
|
|
733
|
+
cancelRun: async (_parent, args, ctx) => {
|
|
734
|
+
const record = await runtime.cancelRun(args.runId, ctx);
|
|
735
|
+
return toRunPayload(record.row, record.steps);
|
|
736
|
+
},
|
|
376
737
|
createSecret: (_parent, args, ctx) => syncAware(() => runtime.createSecret({
|
|
377
738
|
value: args.value,
|
|
378
739
|
label: args.label ?? void 0,
|
|
@@ -450,6 +811,15 @@ const schema = gql`
|
|
|
450
811
|
): WorkflowRunResultPage!
|
|
451
812
|
run(id: String!): WorkflowRunRecord
|
|
452
813
|
"""
|
|
814
|
+
WAITING runs, each with its waitpoints. Scope them to one
|
|
815
|
+
workflow, or to every workflow a drive holds; workflowId wins.
|
|
816
|
+
"""
|
|
817
|
+
waitingRuns(
|
|
818
|
+
driveId: String
|
|
819
|
+
workflowId: String
|
|
820
|
+
first: Int
|
|
821
|
+
): [WorkflowRunRecord!]!
|
|
822
|
+
"""
|
|
453
823
|
The descriptor (props, auth, ports) of one action or trigger, as the
|
|
454
824
|
version that runs it describes it; triggers come back under "trigger".
|
|
455
825
|
"""
|
|
@@ -800,6 +1170,10 @@ const schema = gql`
|
|
|
800
1170
|
workflowVersion: Int!
|
|
801
1171
|
triggerKind: String!
|
|
802
1172
|
triggerPayload: Unknown
|
|
1173
|
+
"""
|
|
1174
|
+
PENDING | RUNNING | WAITING | SUCCEEDED | FAILED | CANCELLED. WAITING: paused
|
|
1175
|
+
at a waitpoint (approval, webhook or delay); the run holds no worker.
|
|
1176
|
+
"""
|
|
803
1177
|
status: String!
|
|
804
1178
|
error: String
|
|
805
1179
|
errorName: String
|
|
@@ -812,6 +1186,48 @@ const schema = gql`
|
|
|
812
1186
|
"Steps that ran a fallback piece version, edges on ports nothing emits."
|
|
813
1187
|
warningNotes: [String!]!
|
|
814
1188
|
steps: [WorkflowStepRunRecord!]!
|
|
1189
|
+
"Where the run paused, resolved ones included."
|
|
1190
|
+
waitpoints: [WaitpointRecord!]!
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
"Who may decide an approval, and how the editor renders it."
|
|
1194
|
+
type ApprovalRequest {
|
|
1195
|
+
title: String!
|
|
1196
|
+
"Markdown."
|
|
1197
|
+
body: String
|
|
1198
|
+
approveLabel: String!
|
|
1199
|
+
rejectLabel: String!
|
|
1200
|
+
"none | reject | both"
|
|
1201
|
+
reasonRequiredOn: String!
|
|
1202
|
+
"DIDs allowed to decide; empty means anyone with write access."
|
|
1203
|
+
approvers: [String!]!
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
"A point where a run paused, and how it resumes."
|
|
1207
|
+
type WaitpointRecord {
|
|
1208
|
+
id: String!
|
|
1209
|
+
runId: String!
|
|
1210
|
+
workflowId: String!
|
|
1211
|
+
stepId: String!
|
|
1212
|
+
stepKey: String!
|
|
1213
|
+
stepPath: String!
|
|
1214
|
+
pieceName: String!
|
|
1215
|
+
blockName: String!
|
|
1216
|
+
"DELAY | WEBHOOK"
|
|
1217
|
+
type: String!
|
|
1218
|
+
"approval | webhook | delay"
|
|
1219
|
+
kind: String!
|
|
1220
|
+
"PENDING | COMPLETED | CONSUMED | EXPIRED | CANCELLED"
|
|
1221
|
+
status: String!
|
|
1222
|
+
createdAt: String!
|
|
1223
|
+
"DELAY only: when the run resumes."
|
|
1224
|
+
resumeAt: String
|
|
1225
|
+
expiresAt: String
|
|
1226
|
+
resolvedAt: String
|
|
1227
|
+
"The DID that resolved it from the editor."
|
|
1228
|
+
decidedBy: String
|
|
1229
|
+
"Set by the Request approval block; null otherwise."
|
|
1230
|
+
approval: ApprovalRequest
|
|
815
1231
|
}
|
|
816
1232
|
|
|
817
1233
|
input WorkflowRunsPagingInput {
|
|
@@ -913,6 +1329,21 @@ const schema = gql`
|
|
|
913
1329
|
"""
|
|
914
1330
|
rerun(runId: String!): WorkflowRunPayload!
|
|
915
1331
|
"""
|
|
1332
|
+
Approves or rejects a PENDING WEBHOOK waitpoint, resuming its run. Needs
|
|
1333
|
+
write access to the workflow; with approvers listed, the caller's DID must
|
|
1334
|
+
be one. reason may be required, per approval.reasonRequiredOn.
|
|
1335
|
+
"""
|
|
1336
|
+
resolveWaitpoint(
|
|
1337
|
+
waitpointId: String!
|
|
1338
|
+
approved: Boolean!
|
|
1339
|
+
reason: String
|
|
1340
|
+
): WaitpointRecord!
|
|
1341
|
+
"""
|
|
1342
|
+
Cancels a WAITING or PENDING run and its open waitpoints. A RUNNING run
|
|
1343
|
+
cannot be cancelled yet.
|
|
1344
|
+
"""
|
|
1345
|
+
cancelRun(runId: String!): WorkflowRunPayload
|
|
1346
|
+
"""
|
|
916
1347
|
Mints a managed secret for a connection or workflow document and returns
|
|
917
1348
|
its ref; only that document resolves it. The value is stored encrypted
|
|
918
1349
|
and is never readable back over any API.
|
|
@@ -1305,6 +1736,7 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1305
1736
|
modelEntries: (documentType) => models.modelEntries(documentType)
|
|
1306
1737
|
} : {},
|
|
1307
1738
|
webhooks: deps.webhooks,
|
|
1739
|
+
waitpointBaseUrl: deps.http ? waitpointBaseUrlOf(deps.http) : void 0,
|
|
1308
1740
|
attachments: deps.attachments,
|
|
1309
1741
|
canReadAttachmentRef: attachmentReadPolicy(deps.attachmentAccess),
|
|
1310
1742
|
logger: deps.logger,
|
|
@@ -1317,6 +1749,7 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1317
1749
|
if (registration.tornDown) return;
|
|
1318
1750
|
registration.tornDown = true;
|
|
1319
1751
|
routes.oauthCallback?.dispose();
|
|
1752
|
+
for (const handle of routes.waitpoints ?? []) handle.dispose();
|
|
1320
1753
|
runtime.shutdown();
|
|
1321
1754
|
registration.detach?.();
|
|
1322
1755
|
};
|
|
@@ -1326,7 +1759,10 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1326
1759
|
if (triggers.status === "available") deps.logger.info(`Workflow trigger read model registered (${engine.WORKFLOW_TRIGGERS_READ_MODEL}, ${engine.WORKFLOW_TRIGGERS_READ_MODEL_STAGE})`);
|
|
1327
1760
|
else deps.logger.error("Workflow document triggers are NOT armed (@reason): this reactor's read-model coordinator takes no live registration, so no document operation reaches the runtime. Webhook and schedule triggers are unaffected.", triggers.reason);
|
|
1328
1761
|
let stopped = false;
|
|
1329
|
-
if (deps.http)
|
|
1762
|
+
if (deps.http) {
|
|
1763
|
+
routes.oauthCallback = registerOAuthCallback(deps.http, runtime);
|
|
1764
|
+
routes.waitpoints = registerWaitpointRoutes(deps.http, runtime);
|
|
1765
|
+
}
|
|
1330
1766
|
return {
|
|
1331
1767
|
subgraph: createWorkflowRuntimeSubgraph(runtime, deps.http ? { callbackUrl: callbackUrlOf(deps.http) } : void 0, access),
|
|
1332
1768
|
get triggers() {
|
|
@@ -1463,5 +1899,5 @@ const workflowsPlugin = createWorkflowsPlugin({});
|
|
|
1463
1899
|
//#endregion
|
|
1464
1900
|
export { workflowsPlugin as a, WORKFLOW_TELEMETRY_SCOPE as c, isWorkflowSingletonConflict as d, modelManifestSource as f, triggerFatalShutdown as g, installFatalErrorShutdown as h, workflowsDriveDeclaration as i, assertWorkflowPackageLoadable as l, workflowSingletonLossHandler as m, WORKFLOW_STUDIO_EDITOR_ID as n, workflowsPluginConfigSchema as o, retryWorkflowSingleton as p, createWorkflowsPlugin as r, WORKFLOW_PACKAGE_NAME as s, DEFAULT_WORKFLOWS_DRIVE as t, composeWorkflowRuntime as u };
|
|
1465
1901
|
|
|
1466
|
-
//# sourceMappingURL=workflows-
|
|
1467
|
-
//# debugId=
|
|
1902
|
+
//# sourceMappingURL=workflows-DkIrfmdn.mjs.map
|
|
1903
|
+
//# debugId=c8f32b53-08da-5217-b7ec-200b108fa949
|