@powerhousedao/switchboard 6.2.3-dev.83 → 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/oauth-apps-config.test.d.ts +2 -0
- package/.tsbuild/test/workflow/oauth-apps-config.test.d.ts.map +1 -0
- 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 +24 -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-ChIFIbah.mjs → server-YNY3Qw9a.mjs} +39 -22
- package/dist/server-YNY3Qw9a.mjs.map +1 -0
- package/dist/server.d.mts +9 -1
- package/dist/server.d.mts.map +1 -1
- package/dist/server.mjs +3 -3
- package/dist/workflow-runtime-7GaJ13c9.d.mts.map +1 -1
- package/dist/{workflows-COM3MKfD.mjs → workflows-DkIrfmdn.mjs} +475 -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 +5 -0
- package/test/goldens/supergraph.graphql +116 -1
- package/test/goldens/workflow-runtime.graphql +116 -1
- package/test/redact-webhook-path.test.ts +9 -0
- package/test/workflow/oauth-apps-config.test.ts +66 -0
- package/test/workflow/oauth.test.ts +81 -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/server-ChIFIbah.mjs.map +0 -1
- package/dist/workflows-COM3MKfD.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: {
|
|
@@ -305,6 +652,15 @@ const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) =>
|
|
|
305
652
|
secret: (_parent, args, ctx) => runtime.secretStat(args.ref, ctx),
|
|
306
653
|
secrets: (_parent, _args, ctx) => runtime.listSecrets(ctx),
|
|
307
654
|
oauthRedirectUri: () => oauth?.callbackUrl ?? null,
|
|
655
|
+
oauthSignIn: async (_parent, args) => {
|
|
656
|
+
let redirectUri;
|
|
657
|
+
try {
|
|
658
|
+
redirectUri = redirectUriFor(oauth, args.redirectUri);
|
|
659
|
+
} catch {
|
|
660
|
+
return "NONE";
|
|
661
|
+
}
|
|
662
|
+
return (await runtime.oauthSignInMode(args.appId, redirectUri)).toUpperCase();
|
|
663
|
+
},
|
|
308
664
|
host: () => ({
|
|
309
665
|
id: `switchboard@${hostname()}`,
|
|
310
666
|
label: hostname()
|
|
@@ -350,8 +706,14 @@ const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) =>
|
|
|
350
706
|
run: async (_parent, args, ctx) => {
|
|
351
707
|
const record = await runtime.run(args.id, ctx);
|
|
352
708
|
return record ? toRunRecord(record.row, record.steps) : null;
|
|
353
|
-
}
|
|
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))
|
|
354
715
|
},
|
|
716
|
+
WorkflowRunRecord: { waitpoints: (parent, _args, ctx) => parent.waitpoints ?? loadWaitpoints(parent.id, ctx) },
|
|
355
717
|
Mutation: { workflowRuntime: () => ({}) },
|
|
356
718
|
WorkflowRuntimeMutations: {
|
|
357
719
|
fire: (_parent, args, ctx) => runtime.fire(args.workflowId, args.payload, "manual", void 0, ctx),
|
|
@@ -364,6 +726,14 @@ const getResolvers = (runtime, oauth, access = UNKNOWN_ACCESS, assertCanRead) =>
|
|
|
364
726
|
cancelTriggerTest: (_parent, args, ctx) => runtime.cancelTriggerTestFor(args.workflowId, ctx),
|
|
365
727
|
testStep: (_parent, args, ctx) => syncAware(() => runtime.testStep(args.workflowId, args.stepId, ctx, { driveId: args.driveId ?? void 0 })),
|
|
366
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
|
+
},
|
|
367
737
|
createSecret: (_parent, args, ctx) => syncAware(() => runtime.createSecret({
|
|
368
738
|
value: args.value,
|
|
369
739
|
label: args.label ?? void 0,
|
|
@@ -441,6 +811,15 @@ const schema = gql`
|
|
|
441
811
|
): WorkflowRunResultPage!
|
|
442
812
|
run(id: String!): WorkflowRunRecord
|
|
443
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
|
+
"""
|
|
444
823
|
The descriptor (props, auth, ports) of one action or trigger, as the
|
|
445
824
|
version that runs it describes it; triggers come back under "trigger".
|
|
446
825
|
"""
|
|
@@ -547,6 +926,13 @@ const schema = gql`
|
|
|
547
926
|
"""
|
|
548
927
|
oauthRedirectUri: String
|
|
549
928
|
"""
|
|
929
|
+
How startOAuth would sign in with the publisher's OAuth2 app appId (a
|
|
930
|
+
connection's oauth_app) on this host, so an editor can tell before it
|
|
931
|
+
opens one. redirectUri as for startOAuth. NONE for an app this host does
|
|
932
|
+
not know, or when it cannot name its callback.
|
|
933
|
+
"""
|
|
934
|
+
oauthSignIn(appId: String!, redirectUri: String): OAuthSignInMode!
|
|
935
|
+
"""
|
|
550
936
|
The switchboard this runtime lives in: what an app records as the runner
|
|
551
937
|
of the workflows and connections it sets up here.
|
|
552
938
|
"""
|
|
@@ -571,6 +957,20 @@ const schema = gql`
|
|
|
571
957
|
error: String
|
|
572
958
|
}
|
|
573
959
|
|
|
960
|
+
"""
|
|
961
|
+
How a host signs in with a publisher's OAuth2 app: DESKTOP, the app's
|
|
962
|
+
desktop client for a callback to this machine; WEB, its web client, whose
|
|
963
|
+
file this host has; RELAY, through the app's relay, which forwards the
|
|
964
|
+
provider's answer here and exchanges codes without this host holding the
|
|
965
|
+
secret; NONE, not at all.
|
|
966
|
+
"""
|
|
967
|
+
enum OAuthSignInMode {
|
|
968
|
+
DESKTOP
|
|
969
|
+
WEB
|
|
970
|
+
RELAY
|
|
971
|
+
NONE
|
|
972
|
+
}
|
|
973
|
+
|
|
574
974
|
type OAuthStart {
|
|
575
975
|
state: String!
|
|
576
976
|
"Where to send the user to sign in."
|
|
@@ -770,6 +1170,10 @@ const schema = gql`
|
|
|
770
1170
|
workflowVersion: Int!
|
|
771
1171
|
triggerKind: String!
|
|
772
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
|
+
"""
|
|
773
1177
|
status: String!
|
|
774
1178
|
error: String
|
|
775
1179
|
errorName: String
|
|
@@ -782,6 +1186,48 @@ const schema = gql`
|
|
|
782
1186
|
"Steps that ran a fallback piece version, edges on ports nothing emits."
|
|
783
1187
|
warningNotes: [String!]!
|
|
784
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
|
|
785
1231
|
}
|
|
786
1232
|
|
|
787
1233
|
input WorkflowRunsPagingInput {
|
|
@@ -883,6 +1329,21 @@ const schema = gql`
|
|
|
883
1329
|
"""
|
|
884
1330
|
rerun(runId: String!): WorkflowRunPayload!
|
|
885
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
|
+
"""
|
|
886
1347
|
Mints a managed secret for a connection or workflow document and returns
|
|
887
1348
|
its ref; only that document resolves it. The value is stored encrypted
|
|
888
1349
|
and is never readable back over any API.
|
|
@@ -1275,6 +1736,7 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1275
1736
|
modelEntries: (documentType) => models.modelEntries(documentType)
|
|
1276
1737
|
} : {},
|
|
1277
1738
|
webhooks: deps.webhooks,
|
|
1739
|
+
waitpointBaseUrl: deps.http ? waitpointBaseUrlOf(deps.http) : void 0,
|
|
1278
1740
|
attachments: deps.attachments,
|
|
1279
1741
|
canReadAttachmentRef: attachmentReadPolicy(deps.attachmentAccess),
|
|
1280
1742
|
logger: deps.logger,
|
|
@@ -1287,6 +1749,7 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1287
1749
|
if (registration.tornDown) return;
|
|
1288
1750
|
registration.tornDown = true;
|
|
1289
1751
|
routes.oauthCallback?.dispose();
|
|
1752
|
+
for (const handle of routes.waitpoints ?? []) handle.dispose();
|
|
1290
1753
|
runtime.shutdown();
|
|
1291
1754
|
registration.detach?.();
|
|
1292
1755
|
};
|
|
@@ -1296,7 +1759,10 @@ async function composeClaimed(engine, deps, lease, loss) {
|
|
|
1296
1759
|
if (triggers.status === "available") deps.logger.info(`Workflow trigger read model registered (${engine.WORKFLOW_TRIGGERS_READ_MODEL}, ${engine.WORKFLOW_TRIGGERS_READ_MODEL_STAGE})`);
|
|
1297
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);
|
|
1298
1761
|
let stopped = false;
|
|
1299
|
-
if (deps.http)
|
|
1762
|
+
if (deps.http) {
|
|
1763
|
+
routes.oauthCallback = registerOAuthCallback(deps.http, runtime);
|
|
1764
|
+
routes.waitpoints = registerWaitpointRoutes(deps.http, runtime);
|
|
1765
|
+
}
|
|
1300
1766
|
return {
|
|
1301
1767
|
subgraph: createWorkflowRuntimeSubgraph(runtime, deps.http ? { callbackUrl: callbackUrlOf(deps.http) } : void 0, access),
|
|
1302
1768
|
get triggers() {
|
|
@@ -1433,5 +1899,5 @@ const workflowsPlugin = createWorkflowsPlugin({});
|
|
|
1433
1899
|
//#endregion
|
|
1434
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 };
|
|
1435
1901
|
|
|
1436
|
-
//# sourceMappingURL=workflows-
|
|
1437
|
-
//# debugId=
|
|
1902
|
+
//# sourceMappingURL=workflows-DkIrfmdn.mjs.map
|
|
1903
|
+
//# debugId=c8f32b53-08da-5217-b7ec-200b108fa949
|