@xyne/workflow-sdk 3.2.43 → 3.2.45
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/dist/authz/types.d.ts +8 -2
- package/dist/authz/types.d.ts.map +1 -1
- package/dist/authz/types.js +8 -1
- package/dist/authz/types.js.map +1 -1
- package/dist/client/events-client.d.ts +5 -1
- package/dist/client/events-client.d.ts.map +1 -1
- package/dist/client/events-client.js +6 -2
- package/dist/client/events-client.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/types.d.ts +87 -19
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/workflow-client.d.ts.map +1 -1
- package/dist/client/workflow-client.js +102 -32
- package/dist/client/workflow-client.js.map +1 -1
- package/dist/common/credentials.d.ts +5 -0
- package/dist/common/credentials.d.ts.map +1 -1
- package/dist/common/credentials.js.map +1 -1
- package/dist/conversational-flow/edit.d.ts +6 -4
- package/dist/conversational-flow/edit.d.ts.map +1 -1
- package/dist/conversational-flow/edit.js +60 -7
- package/dist/conversational-flow/edit.js.map +1 -1
- package/dist/conversational-flow/index.d.ts +3 -2
- package/dist/conversational-flow/index.d.ts.map +1 -1
- package/dist/conversational-flow/index.js.map +1 -1
- package/dist/conversational-flow/read.d.ts +2 -0
- package/dist/conversational-flow/read.d.ts.map +1 -1
- package/dist/conversational-flow/read.js +22 -3
- package/dist/conversational-flow/read.js.map +1 -1
- package/dist/conversational-flow/server/conversation-service.d.ts.map +1 -1
- package/dist/conversational-flow/server/conversation-service.js +4 -2
- package/dist/conversational-flow/server/conversation-service.js.map +1 -1
- package/dist/conversational-flow/turn.d.ts +19 -1
- package/dist/conversational-flow/turn.d.ts.map +1 -1
- package/dist/conversational-flow/turn.js +23 -10
- package/dist/conversational-flow/turn.js.map +1 -1
- package/dist/conversational-flow/types.d.ts +2 -1
- package/dist/conversational-flow/types.d.ts.map +1 -1
- package/dist/conversational-flow/types.js.map +1 -1
- package/dist/engine/config-validator.d.ts +15 -0
- package/dist/engine/config-validator.d.ts.map +1 -1
- package/dist/engine/config-validator.js +52 -0
- package/dist/engine/config-validator.js.map +1 -1
- package/dist/events/types.d.ts +37 -4
- package/dist/events/types.d.ts.map +1 -1
- package/dist/events/types.js +11 -1
- package/dist/events/types.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/persistence/in-memory-adapter.d.ts +34 -18
- package/dist/persistence/in-memory-adapter.d.ts.map +1 -1
- package/dist/persistence/in-memory-adapter.js +294 -37
- package/dist/persistence/in-memory-adapter.js.map +1 -1
- package/dist/persistence/types.d.ts +181 -20
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/router/workflow-router.d.ts.map +1 -1
- package/dist/router/workflow-router.js +154 -58
- package/dist/router/workflow-router.js.map +1 -1
- package/dist/runtime/paging.d.ts +29 -0
- package/dist/runtime/paging.d.ts.map +1 -0
- package/dist/runtime/paging.js +34 -0
- package/dist/runtime/paging.js.map +1 -0
- package/dist/runtime/types.d.ts +59 -9
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.d.ts +95 -25
- package/dist/runtime/workflow-runtime.d.ts.map +1 -1
- package/dist/runtime/workflow-runtime.js +350 -147
- package/dist/runtime/workflow-runtime.js.map +1 -1
- package/dist/schema/config-check.d.ts +63 -0
- package/dist/schema/config-check.d.ts.map +1 -0
- package/dist/schema/config-check.js +18 -0
- package/dist/schema/config-check.js.map +1 -0
- package/dist/schema/options.d.ts +6 -6
- package/dist/schema/options.d.ts.map +1 -1
- package/dist/steps/base-step.d.ts +15 -0
- package/dist/steps/base-step.d.ts.map +1 -1
- package/dist/steps/base-step.js.map +1 -1
- package/dist/testing/authz-conformance.d.ts.map +1 -1
- package/dist/testing/authz-conformance.js +10 -5
- package/dist/testing/authz-conformance.js.map +1 -1
- package/dist/triggers/base-trigger.d.ts +15 -0
- package/dist/triggers/base-trigger.d.ts.map +1 -1
- package/dist/triggers/base-trigger.js.map +1 -1
- package/dist/types/approval.d.ts +46 -0
- package/dist/types/approval.d.ts.map +1 -0
- package/dist/types/approval.js +11 -0
- package/dist/types/approval.js.map +1 -0
- package/dist/types/component-ref.d.ts +18 -0
- package/dist/types/component-ref.d.ts.map +1 -0
- package/dist/types/component-ref.js +2 -0
- package/dist/types/component-ref.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/literal.d.ts +19 -0
- package/dist/types/literal.d.ts.map +1 -0
- package/dist/types/literal.js +2 -0
- package/dist/types/literal.js.map +1 -0
- package/dist/types/validation.d.ts +16 -1
- package/dist/types/validation.d.ts.map +1 -1
- package/dist/types/validation.js +15 -0
- package/dist/types/validation.js.map +1 -1
- package/dist/util/approval-gate.d.ts +26 -0
- package/dist/util/approval-gate.d.ts.map +1 -0
- package/dist/util/approval-gate.js +35 -0
- package/dist/util/approval-gate.js.map +1 -0
- package/dist/util/literal-values.d.ts +22 -0
- package/dist/util/literal-values.d.ts.map +1 -0
- package/dist/util/literal-values.js +55 -0
- package/dist/util/literal-values.js.map +1 -0
- package/package.json +1 -1
- package/dist/common/expression-eval.d.ts +0 -35
- package/dist/common/expression-eval.d.ts.map +0 -1
- package/dist/common/expression-eval.js +0 -214
- package/dist/common/expression-eval.js.map +0 -1
- package/dist/common/principal.d.ts +0 -45
- package/dist/common/principal.d.ts.map +0 -1
- package/dist/common/principal.js +0 -9
- package/dist/common/principal.js.map +0 -1
- package/dist/connectors/builtin/steps/repeat.step.d.ts +0 -126
- package/dist/connectors/builtin/steps/repeat.step.d.ts.map +0 -1
- package/dist/connectors/builtin/steps/repeat.step.js +0 -144
- package/dist/connectors/builtin/steps/repeat.step.js.map +0 -1
- package/dist/runtime/execution-event-bus.d.ts +0 -38
- package/dist/runtime/execution-event-bus.d.ts.map +0 -1
- package/dist/runtime/execution-event-bus.js +0 -87
- package/dist/runtime/execution-event-bus.js.map +0 -1
- package/dist/steps/builtin/code.step.d.ts +0 -99
- package/dist/steps/builtin/code.step.d.ts.map +0 -1
- package/dist/steps/builtin/code.step.js +0 -152
- package/dist/steps/builtin/code.step.js.map +0 -1
- package/dist/steps/builtin/conditional.step.d.ts +0 -182
- package/dist/steps/builtin/conditional.step.d.ts.map +0 -1
- package/dist/steps/builtin/conditional.step.js +0 -82
- package/dist/steps/builtin/conditional.step.js.map +0 -1
- package/dist/steps/builtin/dedup.step.d.ts +0 -65
- package/dist/steps/builtin/dedup.step.d.ts.map +0 -1
- package/dist/steps/builtin/dedup.step.js +0 -61
- package/dist/steps/builtin/dedup.step.js.map +0 -1
- package/dist/steps/builtin/http-request.step.d.ts +0 -1020
- package/dist/steps/builtin/http-request.step.d.ts.map +0 -1
- package/dist/steps/builtin/http-request.step.js +0 -491
- package/dist/steps/builtin/http-request.step.js.map +0 -1
- package/dist/steps/builtin/loop.step.d.ts +0 -100
- package/dist/steps/builtin/loop.step.d.ts.map +0 -1
- package/dist/steps/builtin/loop.step.js +0 -73
- package/dist/steps/builtin/loop.step.js.map +0 -1
- package/dist/steps/builtin/map.step.d.ts +0 -148
- package/dist/steps/builtin/map.step.d.ts.map +0 -1
- package/dist/steps/builtin/map.step.js +0 -111
- package/dist/steps/builtin/map.step.js.map +0 -1
- package/dist/steps/builtin/parallel.step.d.ts +0 -246
- package/dist/steps/builtin/parallel.step.d.ts.map +0 -1
- package/dist/steps/builtin/parallel.step.js +0 -175
- package/dist/steps/builtin/parallel.step.js.map +0 -1
- package/dist/steps/builtin/ssrf-guard.d.ts +0 -9
- package/dist/steps/builtin/ssrf-guard.d.ts.map +0 -1
- package/dist/steps/builtin/ssrf-guard.js +0 -115
- package/dist/steps/builtin/ssrf-guard.js.map +0 -1
- package/dist/steps/builtin/switch.step.d.ts +0 -235
- package/dist/steps/builtin/switch.step.d.ts.map +0 -1
- package/dist/steps/builtin/switch.step.js +0 -101
- package/dist/steps/builtin/switch.step.js.map +0 -1
- package/dist/steps/builtin/transform.step.d.ts +0 -247
- package/dist/steps/builtin/transform.step.d.ts.map +0 -1
- package/dist/steps/builtin/transform.step.js +0 -135
- package/dist/steps/builtin/transform.step.js.map +0 -1
- package/dist/steps/builtin/wait.step.d.ts +0 -1072
- package/dist/steps/builtin/wait.step.d.ts.map +0 -1
- package/dist/steps/builtin/wait.step.js +0 -254
- package/dist/steps/builtin/wait.step.js.map +0 -1
- package/dist/steps/step-registry.d.ts +0 -62
- package/dist/steps/step-registry.d.ts.map +0 -1
- package/dist/steps/step-registry.js +0 -103
- package/dist/steps/step-registry.js.map +0 -1
- package/dist/triggers/builtin/default-cron-trigger.d.ts +0 -44
- package/dist/triggers/builtin/default-cron-trigger.d.ts.map +0 -1
- package/dist/triggers/builtin/default-cron-trigger.js +0 -31
- package/dist/triggers/builtin/default-cron-trigger.js.map +0 -1
- package/dist/triggers/builtin/default-event-trigger.d.ts +0 -32
- package/dist/triggers/builtin/default-event-trigger.d.ts.map +0 -1
- package/dist/triggers/builtin/default-event-trigger.js +0 -21
- package/dist/triggers/builtin/default-event-trigger.js.map +0 -1
- package/dist/triggers/builtin/default-manual-trigger.d.ts +0 -45
- package/dist/triggers/builtin/default-manual-trigger.d.ts.map +0 -1
- package/dist/triggers/builtin/default-manual-trigger.js +0 -51
- package/dist/triggers/builtin/default-manual-trigger.js.map +0 -1
- package/dist/triggers/builtin/default-webhook-trigger.d.ts +0 -72
- package/dist/triggers/builtin/default-webhook-trigger.d.ts.map +0 -1
- package/dist/triggers/builtin/default-webhook-trigger.js +0 -91
- package/dist/triggers/builtin/default-webhook-trigger.js.map +0 -1
- package/dist/triggers/builtin/default-webhook-v2-trigger.d.ts +0 -29
- package/dist/triggers/builtin/default-webhook-v2-trigger.d.ts.map +0 -1
- package/dist/triggers/builtin/default-webhook-v2-trigger.js +0 -38
- package/dist/triggers/builtin/default-webhook-v2-trigger.js.map +0 -1
- package/dist/triggers/trigger-registry.d.ts +0 -48
- package/dist/triggers/trigger-registry.d.ts.map +0 -1
- package/dist/triggers/trigger-registry.js +0 -83
- package/dist/triggers/trigger-registry.js.map +0 -1
- package/dist/types/attachment.d.ts +0 -23
- package/dist/types/attachment.d.ts.map +0 -1
- package/dist/types/attachment.js +0 -2
- package/dist/types/attachment.js.map +0 -1
- package/dist/types/resume-payload.d.ts +0 -34
- package/dist/types/resume-payload.d.ts.map +0 -1
- package/dist/types/resume-payload.js +0 -12
- package/dist/types/resume-payload.js.map +0 -1
- package/dist/util/executable-check.d.ts +0 -42
- package/dist/util/executable-check.d.ts.map +0 -1
- package/dist/util/executable-check.js +0 -115
- package/dist/util/executable-check.js.map +0 -1
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
* - Resume paused executions
|
|
12
12
|
* - Process queued jobs (the worker loop body)
|
|
13
13
|
*/
|
|
14
|
-
import { executionTopic, workflowTopic } from '../events/types.js';
|
|
14
|
+
import { executionTopic, workflowTopic, folderTopic } from '../events/types.js';
|
|
15
15
|
import { projectVariables } from '../types/workflow-variable.js';
|
|
16
|
+
import { ValidationIssueCode } from '../types/validation.js';
|
|
17
|
+
import { WorkflowStatus } from '../types/status.js';
|
|
18
|
+
import { approvalGate } from '../util/approval-gate.js';
|
|
16
19
|
import { ConfigValidator } from '../engine/config-validator.js';
|
|
20
|
+
import { literalValues } from '../util/literal-values.js';
|
|
21
|
+
import { resolvePage } from './paging.js';
|
|
17
22
|
import { validateTriggerPayload } from '../common/validate-payload.js';
|
|
18
23
|
import { AccessDeniedError, ResourceNotFoundError } from '../authz/default.js';
|
|
19
24
|
import { EventTrigger } from '../triggers/event-trigger.js';
|
|
@@ -26,7 +31,6 @@ import { matchesTriggerFilter } from '../ingest/filter.js';
|
|
|
26
31
|
import { isDelayedStart, readAnchor, resolveStartAt, startNeedsPayload, startSkipReason, } from '../ingest/start-policy.js';
|
|
27
32
|
import { CronTrigger } from '../triggers/cron-trigger.js';
|
|
28
33
|
import { PauseStep } from '../engine/pause-step.js';
|
|
29
|
-
import { leafStepId } from '../engine/node-path.js';
|
|
30
34
|
/** Why an event was not admitted, for logs and for the error a manual run gets. */
|
|
31
35
|
function reasonOf(decision) {
|
|
32
36
|
if (decision.kind === 'gone')
|
|
@@ -47,48 +51,6 @@ function reasonOf(decision) {
|
|
|
47
51
|
* what reads the world.
|
|
48
52
|
*/
|
|
49
53
|
const EARLY_WAKE_TOLERANCE_MS = 1_000;
|
|
50
|
-
/**
|
|
51
|
-
* The fields whose values are actually known while editing.
|
|
52
|
-
*
|
|
53
|
-
* A sibling field may hold `{{trigger.projectId}}` — a promise about run time,
|
|
54
|
-
* not an id. A loader filtering by it would search for the literal text and
|
|
55
|
-
* quietly find nothing, so references are dropped here and offered separately as
|
|
56
|
-
* `config` for the rare loader that wants the raw text.
|
|
57
|
-
*/
|
|
58
|
-
function literalValues(config) {
|
|
59
|
-
const out = {};
|
|
60
|
-
for (const [key, value] of Object.entries(config)) {
|
|
61
|
-
if (isPlainObject(value)) {
|
|
62
|
-
// Follow the form as deep as a field path can go: `repository.id` is a
|
|
63
|
-
// usable filter even when its neighbour `repository.name` is a reference.
|
|
64
|
-
out[key] = literalValues(value);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (holdsRef(value))
|
|
68
|
-
continue;
|
|
69
|
-
out[key] = value;
|
|
70
|
-
}
|
|
71
|
-
return out;
|
|
72
|
-
}
|
|
73
|
-
function isPlainObject(value) {
|
|
74
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Whether a value is waiting on run time anywhere inside it.
|
|
78
|
-
*
|
|
79
|
-
* An array is all-or-nothing: dropping the one element that holds a reference
|
|
80
|
-
* would hand the loader a shorter list and no sign that it is short, which reads
|
|
81
|
-
* as a narrower filter rather than an unanswerable one.
|
|
82
|
-
*/
|
|
83
|
-
function holdsRef(value) {
|
|
84
|
-
if (typeof value === 'string')
|
|
85
|
-
return value.includes('{{');
|
|
86
|
-
if (Array.isArray(value))
|
|
87
|
-
return value.some(holdsRef);
|
|
88
|
-
if (isPlainObject(value))
|
|
89
|
-
return Object.values(value).some(holdsRef);
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
54
|
function messageOf(err) {
|
|
93
55
|
return err instanceof Error ? err.message : String(err);
|
|
94
56
|
}
|
|
@@ -112,31 +74,10 @@ function inputSchemaOf(config) {
|
|
|
112
74
|
function parseWorkflowConfig(raw) {
|
|
113
75
|
return JSON.parse(raw ?? '{}');
|
|
114
76
|
}
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
*/
|
|
120
|
-
function findStepConfigById(config, id) {
|
|
121
|
-
let found = null;
|
|
122
|
-
const visit = (node) => {
|
|
123
|
-
if (found || node === null || typeof node !== 'object')
|
|
124
|
-
return;
|
|
125
|
-
if (Array.isArray(node)) {
|
|
126
|
-
for (const n of node)
|
|
127
|
-
visit(n);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const obj = node;
|
|
131
|
-
if (typeof obj['id'] === 'string' && typeof obj['type'] === 'string' && obj['id'] === id) {
|
|
132
|
-
found = { id, ...(typeof obj['title'] === 'string' ? { title: obj['title'] } : {}) };
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
for (const v of Object.values(obj))
|
|
136
|
-
visit(v);
|
|
137
|
-
};
|
|
138
|
-
visit(config);
|
|
139
|
-
return found;
|
|
77
|
+
/** The author-given name out of the metadata column, if it has one. */
|
|
78
|
+
function parseWorkflowName(raw) {
|
|
79
|
+
const meta = JSON.parse(raw ?? '{}');
|
|
80
|
+
return typeof meta['name'] === 'string' ? meta['name'] : undefined;
|
|
140
81
|
}
|
|
141
82
|
// ─── WorkflowRuntime ───
|
|
142
83
|
export class WorkflowRuntime {
|
|
@@ -163,6 +104,8 @@ export class WorkflowRuntime {
|
|
|
163
104
|
defaultCronTimezone;
|
|
164
105
|
/** AI builder config — when present, the router includes the ai-builder chat route. */
|
|
165
106
|
aiBuilder;
|
|
107
|
+
/** Which configurations need approval before going live. Host-supplied, always. */
|
|
108
|
+
approval;
|
|
166
109
|
constructor(opts) {
|
|
167
110
|
this.persistence = opts.persistence;
|
|
168
111
|
// No fallback and no cast: the authorizer and the adapter must agree on
|
|
@@ -179,7 +122,8 @@ export class WorkflowRuntime {
|
|
|
179
122
|
this.eventBus = opts.eventBus;
|
|
180
123
|
this.storage = opts.storage;
|
|
181
124
|
this.sandbox = opts.sandbox;
|
|
182
|
-
const config = opts.config
|
|
125
|
+
const config = opts.config;
|
|
126
|
+
this.approval = config.approval;
|
|
183
127
|
this.baseUrl = config.baseUrl ?? '';
|
|
184
128
|
this.allowExecutableUploads = config.allowExecutableUploads ?? false;
|
|
185
129
|
this.defaultCronTimezone = config.defaultCronTimezone ?? 'Asia/Kolkata';
|
|
@@ -203,6 +147,28 @@ export class WorkflowRuntime {
|
|
|
203
147
|
publishEvent(executionId, event) {
|
|
204
148
|
this.publish(executionTopic(executionId), event);
|
|
205
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Announce that a run appeared or changed status, to the workflow's topic and
|
|
152
|
+
* its folder's — the screens that need it are scoped both ways.
|
|
153
|
+
*
|
|
154
|
+
* Fire-and-forget, like every publish here.
|
|
155
|
+
*/
|
|
156
|
+
publishRunChange(workflow, executionId, status) {
|
|
157
|
+
if (!this.eventBus)
|
|
158
|
+
return;
|
|
159
|
+
const event = {
|
|
160
|
+
event: 'run_changed',
|
|
161
|
+
data: {
|
|
162
|
+
workflowId: workflow.id,
|
|
163
|
+
executionId,
|
|
164
|
+
status,
|
|
165
|
+
at: new Date().toISOString(),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
this.publish(workflowTopic(workflow.id), event);
|
|
169
|
+
if (workflow.folderId)
|
|
170
|
+
this.publish(folderTopic(workflow.folderId), event);
|
|
171
|
+
}
|
|
206
172
|
/**
|
|
207
173
|
* Announce that a workflow definition changed.
|
|
208
174
|
*
|
|
@@ -323,11 +289,23 @@ export class WorkflowRuntime {
|
|
|
323
289
|
* `result.valid` is false. Returns structured issues the frontend
|
|
324
290
|
* can render inline in the workflow builder.
|
|
325
291
|
*/
|
|
326
|
-
validateConfig(config) {
|
|
327
|
-
const
|
|
328
|
-
|
|
292
|
+
async validateConfig(ctx, config, workflowId) {
|
|
293
|
+
const result = new ConfigValidator(this.connectors).validate(config);
|
|
294
|
+
if (!result.valid || workflowId === undefined)
|
|
295
|
+
return result;
|
|
296
|
+
const attributes = await this.editingScope(ctx, { workflowId });
|
|
297
|
+
const issues = [...result.issues, ...(await this.checkComponents(ctx, config, attributes))];
|
|
298
|
+
return { valid: issues.length === 0, issues };
|
|
329
299
|
}
|
|
330
300
|
// ─── Workflow Lifecycle ───
|
|
301
|
+
/**
|
|
302
|
+
* Whether this configuration needs a reviewer, and which component types
|
|
303
|
+
* asked for it. The reading of the policy is {@link approvalGate}; this only
|
|
304
|
+
* supplies it with what the configuration is made of.
|
|
305
|
+
*/
|
|
306
|
+
gateFor(config) {
|
|
307
|
+
return approvalGate(this.approval, new ConfigValidator(this.connectors).components(config));
|
|
308
|
+
}
|
|
331
309
|
/**
|
|
332
310
|
* Activate a workflow's trigger.
|
|
333
311
|
*
|
|
@@ -336,24 +314,165 @@ export class WorkflowRuntime {
|
|
|
336
314
|
*
|
|
337
315
|
* Only then is the workflow marked ACTIVE. Webhook ingest and event dispatch
|
|
338
316
|
* both key off that status, so it is what actually turns a workflow on.
|
|
317
|
+
*
|
|
318
|
+
* Unless the deployment's {@link ApprovalConfig} gates this configuration, in
|
|
319
|
+
* which case it goes to PENDING_APPROVAL and none of the above happens yet —
|
|
320
|
+
* a workflow awaiting review must not hold a cron registration.
|
|
321
|
+
*
|
|
322
|
+
* `workflow:activate` stays the maker's action throughout: authorization says
|
|
323
|
+
* whether you may turn workflows on, the policy says whether this one needs a
|
|
324
|
+
* second look first. Neither stands in for the other.
|
|
339
325
|
*/
|
|
340
326
|
async activateWorkflow(ctx, workflowId, opts) {
|
|
341
327
|
// Guard up front, before any external side-effects (webhook/scheduler).
|
|
342
|
-
const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:activate');
|
|
343
|
-
|
|
344
|
-
|
|
328
|
+
const { record, permittedActions } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:activate');
|
|
329
|
+
const gate = this.gateFor(parseWorkflowConfig(record.config));
|
|
330
|
+
// A caller who may approve is approving by activating — otherwise an admin
|
|
331
|
+
// toggling their own workflow would queue a review of their own work.
|
|
332
|
+
// Strict four-eyes is the authorizer's to impose: withhold
|
|
333
|
+
// `workflow:approve` when the caller is the author and this branch stops
|
|
334
|
+
// applying to them.
|
|
335
|
+
if (gate.required && !permittedActions.includes('workflow:approve')) {
|
|
336
|
+
await this.persistence.updateWorkflow(workflowId, {
|
|
337
|
+
status: WorkflowStatus.PENDING_APPROVAL,
|
|
338
|
+
});
|
|
339
|
+
this.log.info(`workflow ${workflowId} submitted for approval — gated by ${gate.gatedBy.join(', ')}`);
|
|
340
|
+
this.publishWorkflowChange(workflowId, 'submitted', opts?.origin);
|
|
341
|
+
return { status: WorkflowStatus.PENDING_APPROVAL, gatedBy: gate.gatedBy };
|
|
342
|
+
}
|
|
343
|
+
await this.activateInternal(ctx, record);
|
|
344
|
+
await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.ACTIVE });
|
|
345
345
|
// After the side-effects, never before: an activation that failed is not a
|
|
346
346
|
// change worth telling anyone about.
|
|
347
347
|
this.publishWorkflowChange(workflowId, 'activated', opts?.origin);
|
|
348
|
+
return { status: WorkflowStatus.ACTIVE, gatedBy: [] };
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Approve a workflow awaiting review and put it live.
|
|
352
|
+
*
|
|
353
|
+
* Approval and activation are one act, deliberately: the checker's consent is
|
|
354
|
+
* expressed by the workflow starting, so there is no "approved but off" state
|
|
355
|
+
* to explain, and no second click for someone to forget. The trigger's
|
|
356
|
+
* side-effects run here — at the moment it actually goes live, not when it
|
|
357
|
+
* was submitted.
|
|
358
|
+
*/
|
|
359
|
+
async approveWorkflow(ctx, workflowId, opts) {
|
|
360
|
+
const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:approve');
|
|
361
|
+
if (record.status !== WorkflowStatus.PENDING_APPROVAL) {
|
|
362
|
+
throw new Error(`Cannot approve workflow ${workflowId}: it is ${record.status}, not awaiting approval`);
|
|
363
|
+
}
|
|
364
|
+
await this.activateInternal(ctx, record);
|
|
365
|
+
await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.ACTIVE });
|
|
366
|
+
this.log.info(`workflow ${workflowId} approved and activated`);
|
|
367
|
+
this.publishWorkflowChange(workflowId, 'approved', opts?.origin);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Decline a workflow awaiting review.
|
|
371
|
+
*
|
|
372
|
+
* REJECTED rather than back to DRAFT, so the author can tell "declined" from
|
|
373
|
+
* "nobody has looked yet". Editing it returns it to DRAFT — see
|
|
374
|
+
* {@link updateWorkflow}. The reason and the reviewer are the host's to
|
|
375
|
+
* record: this runtime has no notion of who anyone is.
|
|
376
|
+
*/
|
|
377
|
+
async rejectWorkflow(ctx, workflowId, opts) {
|
|
378
|
+
const { record } = await this.authorizedWorkflow(ctx, workflowId, 'workflow:approve');
|
|
379
|
+
if (record.status !== WorkflowStatus.PENDING_APPROVAL) {
|
|
380
|
+
throw new Error(`Cannot reject workflow ${workflowId}: it is ${record.status}, not awaiting approval`);
|
|
381
|
+
}
|
|
382
|
+
await this.persistence.updateWorkflow(workflowId, { status: WorkflowStatus.REJECTED });
|
|
383
|
+
this.log.info(`workflow ${workflowId} rejected`);
|
|
384
|
+
this.publishWorkflowChange(workflowId, 'rejected', opts?.origin);
|
|
348
385
|
}
|
|
349
386
|
/**
|
|
350
387
|
* The activation work, already authorized. Used by the guarded
|
|
351
388
|
* {@link activateWorkflow} and by `createWorkflow` (whose create was itself
|
|
352
389
|
* authorized against the target folder).
|
|
353
390
|
*/
|
|
354
|
-
|
|
391
|
+
/**
|
|
392
|
+
* Every component's verdict on the config, merged into issues that path like
|
|
393
|
+
* any other.
|
|
394
|
+
*
|
|
395
|
+
* Components run concurrently and independently: one slow connector must not
|
|
396
|
+
* hold up the rest, and one that throws must not hide what the others found. A
|
|
397
|
+
* rejection becomes a MISCONFIGURED issue rather than an exception — failing
|
|
398
|
+
* closed, because refusing to activate is the safe answer when the check that
|
|
399
|
+
* would have caught a problem could not be made.
|
|
400
|
+
*/
|
|
401
|
+
async checkComponents(ctx, config, attributes) {
|
|
402
|
+
const refs = new ConfigValidator(this.connectors)
|
|
403
|
+
.components(config)
|
|
404
|
+
.map((ref) => ({
|
|
405
|
+
ref,
|
|
406
|
+
impl: ref.kind === 'trigger'
|
|
407
|
+
? this.connectors.getTrigger(ref.type)
|
|
408
|
+
: this.connectors.getStep(ref.type),
|
|
409
|
+
}))
|
|
410
|
+
.filter((entry) => entry.impl.validateConfig !== undefined);
|
|
411
|
+
if (refs.length === 0)
|
|
412
|
+
return [];
|
|
413
|
+
const settled = await Promise.allSettled(refs.map(async ({ ref, impl }) => {
|
|
414
|
+
// A half-configured credential is the component's problem to report, not
|
|
415
|
+
// a reason to crash — the same choice getFieldOptions makes.
|
|
416
|
+
let credentials = {};
|
|
417
|
+
try {
|
|
418
|
+
credentials = await this.credentialResolver.resolve(attributes, impl, ref.config);
|
|
419
|
+
}
|
|
420
|
+
catch (err) {
|
|
421
|
+
this.log.info(`validateConfig for ${ref.kind} "${ref.type}": no usable credential — ${messageOf(err)}`);
|
|
422
|
+
}
|
|
423
|
+
const issues = await impl.validateConfig({
|
|
424
|
+
config: ref.config,
|
|
425
|
+
known: literalValues(ref.config),
|
|
426
|
+
credentials,
|
|
427
|
+
attributes,
|
|
428
|
+
services: this.services,
|
|
429
|
+
caller: ctx,
|
|
430
|
+
});
|
|
431
|
+
return { ref, issues };
|
|
432
|
+
}));
|
|
433
|
+
const out = [];
|
|
434
|
+
settled.forEach((result, index) => {
|
|
435
|
+
const { ref } = refs[index];
|
|
436
|
+
const location = ref.kind === 'trigger'
|
|
437
|
+
? { scope: 'trigger' }
|
|
438
|
+
: { scope: 'step', ...(ref.stepId !== undefined ? { stepId: ref.stepId } : {}) };
|
|
439
|
+
if (result.status === 'rejected') {
|
|
440
|
+
this.log.warn(`validateConfig threw for ${ref.kind} "${ref.type}": ${messageOf(result.reason)}`);
|
|
441
|
+
out.push({
|
|
442
|
+
path: ref.path,
|
|
443
|
+
code: ValidationIssueCode.MISCONFIGURED,
|
|
444
|
+
// Says "unknown", not "wrong" — the author should retry, not go hunting
|
|
445
|
+
// for a mistake that may not exist.
|
|
446
|
+
message: `Could not verify the ${ref.kind} "${ref.type}" — please try again.`,
|
|
447
|
+
location,
|
|
448
|
+
});
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
for (const issue of result.value.issues) {
|
|
452
|
+
out.push({
|
|
453
|
+
path: issue.path ? `${ref.path}.${issue.path}` : ref.path,
|
|
454
|
+
code: ValidationIssueCode.MISCONFIGURED,
|
|
455
|
+
message: issue.message,
|
|
456
|
+
...(issue.path !== undefined
|
|
457
|
+
? { location: { ...location, field: issue.path } }
|
|
458
|
+
: { location }),
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return out;
|
|
463
|
+
}
|
|
464
|
+
async activateInternal(ctx, workflow) {
|
|
355
465
|
const workflowId = workflow.id;
|
|
356
466
|
const config = parseWorkflowConfig(workflow.config);
|
|
467
|
+
const activateAttributes = workflow.attributes;
|
|
468
|
+
// A configuration naming things that do not exist, or that its author may
|
|
469
|
+
// not use, fails here — beside the credential check below and for the same
|
|
470
|
+
// reason: better now than on the first event. Saving is deliberately left
|
|
471
|
+
// alone, because a draft in progress is allowed to be wrong.
|
|
472
|
+
const unresolved = await this.checkComponents(ctx, config, activateAttributes);
|
|
473
|
+
if (unresolved.length > 0) {
|
|
474
|
+
throw new Error(`Cannot activate workflow ${workflowId}: ${unresolved.map((issue) => issue.message).join('; ')}`);
|
|
475
|
+
}
|
|
357
476
|
if (!this.connectors.hasTrigger(config.trigger.type)) {
|
|
358
477
|
throw new Error(`Trigger type "${config.trigger.type}" is not registered`);
|
|
359
478
|
}
|
|
@@ -630,6 +749,10 @@ export class WorkflowRuntime {
|
|
|
630
749
|
throw new Error(`Workflow ${workflowId} not found`);
|
|
631
750
|
}
|
|
632
751
|
await this.require(ctx, 'workflow:run', this.workflowRef(workflow));
|
|
752
|
+
if (workflow.status === WorkflowStatus.PENDING_APPROVAL) {
|
|
753
|
+
throw new Error(`Cannot run workflow ${workflowId}: it is awaiting approval. ` +
|
|
754
|
+
`Deactivate it to keep editing and testing, or wait for a decision.`);
|
|
755
|
+
}
|
|
633
756
|
const config = parseWorkflowConfig(workflow.config);
|
|
634
757
|
const triggerCfg = (config.trigger.config ?? {});
|
|
635
758
|
const inputSchema = triggerCfg['inputSchema'];
|
|
@@ -826,8 +949,40 @@ export class WorkflowRuntime {
|
|
|
826
949
|
*/
|
|
827
950
|
async listWorkflows(ctx, page) {
|
|
828
951
|
const filter = await this.filterFor(ctx, 'workflow');
|
|
829
|
-
const
|
|
830
|
-
|
|
952
|
+
const result = await this.persistence.listWorkflows(filter, {
|
|
953
|
+
...resolvePage(page),
|
|
954
|
+
...(page?.folderId !== undefined ? { folderId: page.folderId } : {}),
|
|
955
|
+
});
|
|
956
|
+
const items = await this.project(ctx, result.items, (wf) => this.workflowRef(wf));
|
|
957
|
+
return {
|
|
958
|
+
items,
|
|
959
|
+
...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
async listPendingWorkflows(ctx, params) {
|
|
963
|
+
const filter = await this.filterFor(ctx, 'workflow');
|
|
964
|
+
const page = await this.persistence.listPendingWorkflows(filter, resolvePage(params));
|
|
965
|
+
const rows = await this.project(ctx, page.items, (wf) => this.workflowRef(wf));
|
|
966
|
+
const items = rows.map((wf) => {
|
|
967
|
+
const config = parseWorkflowConfig(wf.config);
|
|
968
|
+
const name = parseWorkflowName(wf.metadata);
|
|
969
|
+
return {
|
|
970
|
+
workflowId: wf.id,
|
|
971
|
+
// Spread-when-present, like every other optional the SDK returns: a
|
|
972
|
+
// consumer tests presence rather than comparing against a placeholder.
|
|
973
|
+
...(name !== undefined ? { name } : {}),
|
|
974
|
+
folderId: wf.folderId,
|
|
975
|
+
triggerType: config.trigger.type,
|
|
976
|
+
gatedBy: this.gateFor(config).gatedBy,
|
|
977
|
+
submittedAt: wf.updatedAt,
|
|
978
|
+
...(wf.permittedActions !== undefined
|
|
979
|
+
? { permittedActions: wf.permittedActions }
|
|
980
|
+
: {}),
|
|
981
|
+
};
|
|
982
|
+
});
|
|
983
|
+
return page.nextCursor === undefined
|
|
984
|
+
? { items }
|
|
985
|
+
: { items, nextCursor: page.nextCursor };
|
|
831
986
|
}
|
|
832
987
|
/** Workflow counts for the visible set — total + per-folder, for the folder rail. */
|
|
833
988
|
async workflowCounts(ctx) {
|
|
@@ -852,10 +1007,17 @@ export class WorkflowRuntime {
|
|
|
852
1007
|
// exists, so this same decision is what the UI projects onto its "New
|
|
853
1008
|
// workflow" button. Also proves the folder exists — no separate lookup.
|
|
854
1009
|
await this.authorizedFolder(ctx, input.folderId, 'workflow:create');
|
|
855
|
-
const validation = this.
|
|
1010
|
+
const validation = new ConfigValidator(this.connectors).validate(input.config);
|
|
1011
|
+
// Create goes live here, so it is an activation and has to face the same
|
|
1012
|
+
// gate — otherwise "build it fresh" is the way around every other check.
|
|
1013
|
+
const gate = this.gateFor(input.config);
|
|
856
1014
|
const metadata = { ...input.metadata, name: input.name };
|
|
857
1015
|
const id = await this.persistence.createWorkflow({
|
|
858
|
-
|
|
1016
|
+
// A gated configuration lands awaiting review. The promotion below is
|
|
1017
|
+
// what lets someone who may approve create one live, and it has to come
|
|
1018
|
+
// after the insert: the authorizer decides about a workflow, and until
|
|
1019
|
+
// the row exists there is no workflow to decide about.
|
|
1020
|
+
status: gate.required ? WorkflowStatus.PENDING_APPROVAL : WorkflowStatus.ACTIVE,
|
|
859
1021
|
config: JSON.stringify(input.config),
|
|
860
1022
|
metadata: JSON.stringify(metadata),
|
|
861
1023
|
eventType: input.config.trigger.type,
|
|
@@ -863,13 +1025,25 @@ export class WorkflowRuntime {
|
|
|
863
1025
|
folderId: input.folderId,
|
|
864
1026
|
attributes: input.attributes,
|
|
865
1027
|
});
|
|
866
|
-
|
|
1028
|
+
let record = await this.persistence.getWorkflow(id);
|
|
867
1029
|
if (!record)
|
|
868
1030
|
throw new Error('Failed to read created workflow');
|
|
869
|
-
|
|
1031
|
+
let live = !gate.required;
|
|
1032
|
+
if (gate.required) {
|
|
1033
|
+
const permitted = await this.authorizer.permissions(ctx, this.workflowRef(record));
|
|
1034
|
+
if (permitted.includes('workflow:approve')) {
|
|
1035
|
+
await this.persistence.updateWorkflow(id, { status: WorkflowStatus.ACTIVE });
|
|
1036
|
+
record = (await this.persistence.getWorkflow(id)) ?? record;
|
|
1037
|
+
live = true;
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
this.log.info(`created workflow ${id} awaiting approval — gated by ${gate.gatedBy.join(', ')}`);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (live && validation.valid) {
|
|
870
1044
|
try {
|
|
871
1045
|
// Internal post-create activation — already authorized by the create above.
|
|
872
|
-
await this.activateInternal(record);
|
|
1046
|
+
await this.activateInternal(ctx, record);
|
|
873
1047
|
}
|
|
874
1048
|
catch (err) {
|
|
875
1049
|
// Non-fatal — the workflow is created, and its trigger can be activated
|
|
@@ -909,6 +1083,26 @@ export class WorkflowRuntime {
|
|
|
909
1083
|
if (input.config) {
|
|
910
1084
|
update.config = JSON.stringify(input.config);
|
|
911
1085
|
update.eventType = input.config.trigger.type;
|
|
1086
|
+
// An ACTIVE workflow was approved as it stands, so editing it in place
|
|
1087
|
+
// would put something unreviewed live — and it is the obvious way round
|
|
1088
|
+
// the gate: ship something harmless, then edit the rest in. Refusing is
|
|
1089
|
+
// also why a maker cannot take production down by accident: stopping it
|
|
1090
|
+
// stays a separate, deliberate act.
|
|
1091
|
+
//
|
|
1092
|
+
// Only when the NEW configuration is gated. An edit that removes the
|
|
1093
|
+
// gated component, or never had one, is not what this protects — and
|
|
1094
|
+
// under a policy that gates nothing, none of this ever fires.
|
|
1095
|
+
const gate = this.gateFor(input.config);
|
|
1096
|
+
if (gate.required && existing.status === WorkflowStatus.ACTIVE) {
|
|
1097
|
+
throw new Error(`Cannot edit workflow ${workflowId} while it is active: the new configuration ` +
|
|
1098
|
+
`needs approval (${gate.gatedBy.join(', ')}). Deactivate it first.`);
|
|
1099
|
+
}
|
|
1100
|
+
// Editing withdraws a submission and clears a rejection — whatever a
|
|
1101
|
+
// reviewer saw or declined is no longer what is on the table.
|
|
1102
|
+
if (existing.status === WorkflowStatus.PENDING_APPROVAL ||
|
|
1103
|
+
existing.status === WorkflowStatus.REJECTED) {
|
|
1104
|
+
update.status = WorkflowStatus.DRAFT;
|
|
1105
|
+
}
|
|
912
1106
|
}
|
|
913
1107
|
// Update metadata if name or metadata provided
|
|
914
1108
|
if (input.name !== undefined || input.metadata !== undefined) {
|
|
@@ -928,10 +1122,14 @@ export class WorkflowRuntime {
|
|
|
928
1122
|
return updated;
|
|
929
1123
|
}
|
|
930
1124
|
// ─── Folders ───
|
|
931
|
-
/** List folders the caller may see. */
|
|
932
|
-
async listFolders(ctx) {
|
|
933
|
-
const
|
|
934
|
-
|
|
1125
|
+
/** List folders the caller may see, one page at a time. */
|
|
1126
|
+
async listFolders(ctx, page) {
|
|
1127
|
+
const result = await this.persistence.listFolders(await this.filterFor(ctx, 'folder'), resolvePage(page));
|
|
1128
|
+
const items = await this.project(ctx, result.items, (f) => this.folderRef(f));
|
|
1129
|
+
return {
|
|
1130
|
+
items,
|
|
1131
|
+
...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
|
|
1132
|
+
};
|
|
935
1133
|
}
|
|
936
1134
|
/**
|
|
937
1135
|
* Get a single folder by id. Guards `folder:read` and attaches the caller's
|
|
@@ -1078,64 +1276,46 @@ export class WorkflowRuntime {
|
|
|
1078
1276
|
async listExecutions(ctx, params) {
|
|
1079
1277
|
// Executions inherit their workflow's visibility — the adapter joins the
|
|
1080
1278
|
// workflow filter rather than us enumerating workflow ids first.
|
|
1081
|
-
return this.persistence.listExecutions(await this.filterFor(ctx, 'workflow'),
|
|
1279
|
+
return this.persistence.listExecutions(await this.filterFor(ctx, 'workflow'), {
|
|
1280
|
+
...resolvePage(params),
|
|
1281
|
+
...(params.workflowId !== undefined ? { workflowId: params.workflowId } : {}),
|
|
1282
|
+
...(params.status !== undefined ? { status: params.status } : {}),
|
|
1283
|
+
...(params.folderId !== undefined ? { folderId: params.folderId } : {}),
|
|
1284
|
+
});
|
|
1082
1285
|
}
|
|
1083
1286
|
/**
|
|
1084
|
-
*
|
|
1085
|
-
*
|
|
1287
|
+
* One page of the approvals inbox — a pass-through to the adapter, which
|
|
1288
|
+
* answers it in a single joined query.
|
|
1086
1289
|
*/
|
|
1087
|
-
async listPendingApprovals(ctx,
|
|
1088
|
-
// Visible-workflow scoped
|
|
1089
|
-
//
|
|
1090
|
-
//
|
|
1290
|
+
async listPendingApprovals(ctx, params) {
|
|
1291
|
+
// Visible-workflow scoped: any caller who can see the workflow sees its
|
|
1292
|
+
// pending gates. Narrowing this to the step's assignee is P3, and lands as
|
|
1293
|
+
// `visibleFilter(ctx, 'approval')` — this stays the workflow filter until
|
|
1091
1294
|
// approval steps actually carry an assignee.
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
catch { /* ignore */ }
|
|
1117
|
-
if (pausedStep && workflow.config) {
|
|
1118
|
-
try {
|
|
1119
|
-
const leafId = leafStepId(pausedStep.stepName);
|
|
1120
|
-
const stepConfig = findStepConfigById(JSON.parse(workflow.config), leafId);
|
|
1121
|
-
if (stepConfig?.title)
|
|
1122
|
-
pausedStepName = stepConfig.title;
|
|
1123
|
-
else if (stepConfig?.id)
|
|
1124
|
-
pausedStepName = stepConfig.id;
|
|
1125
|
-
}
|
|
1126
|
-
catch { /* ignore */ }
|
|
1127
|
-
}
|
|
1128
|
-
}
|
|
1129
|
-
return {
|
|
1130
|
-
id: exec.id,
|
|
1131
|
-
workflowId: exec.workflowId,
|
|
1132
|
-
...(workflowName !== undefined ? { name: workflowName } : {}),
|
|
1133
|
-
pausedStepName,
|
|
1134
|
-
createdAt: exec.createdAt,
|
|
1135
|
-
...(workflowTags !== undefined ? { tags: workflowTags } : {}),
|
|
1136
|
-
};
|
|
1137
|
-
}));
|
|
1138
|
-
return results;
|
|
1295
|
+
return this.persistence.listPendingApprovals(await this.filterFor(ctx, 'workflow'), {
|
|
1296
|
+
...resolvePage(params),
|
|
1297
|
+
...(params?.workflowIds !== undefined ? { workflowIds: params.workflowIds } : {}),
|
|
1298
|
+
...(params?.stages !== undefined ? { stages: params.stages } : {}),
|
|
1299
|
+
...(params?.tags !== undefined ? { tags: params.tags } : {}),
|
|
1300
|
+
...(params?.search !== undefined ? { search: params.search } : {}),
|
|
1301
|
+
...(params?.sort !== undefined ? { sort: params.sort } : {}),
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
/** How many runs are waiting on a gate this caller can see. */
|
|
1305
|
+
async countPendingApprovals(ctx) {
|
|
1306
|
+
return this.persistence.countPendingApprovals(await this.filterFor(ctx, 'workflow'));
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Filter facets for the approvals inbox, over the whole visible set —
|
|
1310
|
+
* deliberately not derived from a page, which would offer fewer choices the
|
|
1311
|
+
* further someone pages.
|
|
1312
|
+
*/
|
|
1313
|
+
async pendingApprovalFacets(ctx) {
|
|
1314
|
+
return this.persistence.pendingApprovalFacets(await this.filterFor(ctx, 'workflow'));
|
|
1315
|
+
}
|
|
1316
|
+
/** The latest run of each workflow in scope, as one grouped query. */
|
|
1317
|
+
async lastRunByWorkflow(ctx, params = {}) {
|
|
1318
|
+
return this.persistence.lastRunByWorkflow(await this.filterFor(ctx, 'workflow'), params);
|
|
1139
1319
|
}
|
|
1140
1320
|
/**
|
|
1141
1321
|
* Get execution detail including step records.
|
|
@@ -1195,13 +1375,30 @@ export class WorkflowRuntime {
|
|
|
1195
1375
|
}
|
|
1196
1376
|
await this.persistence.updateExecutionStatus(executionId, 'CANCELLED');
|
|
1197
1377
|
this.publishEvent(executionId, { event: 'execution_cancelled', data: {} });
|
|
1378
|
+
// A cancel never passes through `processJob`, so the lists need telling here.
|
|
1379
|
+
const owner = await this.persistence.getWorkflow(exec.workflowId);
|
|
1380
|
+
if (owner)
|
|
1381
|
+
this.publishRunChange(owner, executionId, 'CANCELLED');
|
|
1198
1382
|
this.log.info(`execution ${executionId} cancelled`);
|
|
1199
1383
|
}
|
|
1200
1384
|
/** List the credentials visible to `ctx` as safe, paginated summaries. */
|
|
1201
1385
|
async listCredentials(ctx, page) {
|
|
1202
1386
|
const filter = await this.filterFor(ctx, 'credential');
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1387
|
+
const result = await this.persistence.listCredentials(filter, resolvePage(page));
|
|
1388
|
+
const items = await this.project(ctx, result.items, (credential) => this.credentialRef(credential));
|
|
1389
|
+
return {
|
|
1390
|
+
items,
|
|
1391
|
+
...(result.nextCursor !== undefined ? { nextCursor: result.nextCursor } : {}),
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
/** One visible credential by name — an indexed lookup, not a list scan. */
|
|
1395
|
+
async getCredentialByName(ctx, name) {
|
|
1396
|
+
const filter = await this.filterFor(ctx, 'credential');
|
|
1397
|
+
const record = await this.persistence.getCredentialByName(filter, name);
|
|
1398
|
+
if (!record)
|
|
1399
|
+
return null;
|
|
1400
|
+
const [projected] = await this.project(ctx, [record], (credential) => this.credentialRef(credential));
|
|
1401
|
+
return projected ?? null;
|
|
1205
1402
|
}
|
|
1206
1403
|
/* Create a new credential in the workspace.*/
|
|
1207
1404
|
async createCredential(attributes, input) {
|
|
@@ -1262,6 +1459,10 @@ export class WorkflowRuntime {
|
|
|
1262
1459
|
const final = await this.persistence.getExecution(executionId);
|
|
1263
1460
|
if (!final)
|
|
1264
1461
|
return { status: 'not_found' };
|
|
1462
|
+
// One frame per pass, not per step — a list shows only the run's status.
|
|
1463
|
+
const owner = await this.persistence.getWorkflow(final.workflowId);
|
|
1464
|
+
if (owner)
|
|
1465
|
+
this.publishRunChange(owner, executionId, final.status);
|
|
1265
1466
|
if (final.status === 'EXTERNAL_WAIT') {
|
|
1266
1467
|
// Liveness (level-triggered): if a resume payload was routed to a gate
|
|
1267
1468
|
// *during* this pass — after the walk had already read that node's
|
|
@@ -1370,7 +1571,7 @@ export class WorkflowRuntime {
|
|
|
1370
1571
|
* been authorized against, never from the request body.
|
|
1371
1572
|
*/
|
|
1372
1573
|
async getFieldOptions(ctx, input) {
|
|
1373
|
-
const attributes = await this.
|
|
1574
|
+
const attributes = await this.editingScope(ctx, input);
|
|
1374
1575
|
const component = input.kind === 'step'
|
|
1375
1576
|
? this.connectors.hasStep(input.type)
|
|
1376
1577
|
? this.connectors.getStep(input.type)
|
|
@@ -1436,7 +1637,7 @@ export class WorkflowRuntime {
|
|
|
1436
1637
|
* workspace, and narrowing it per viewer would be a policy the connector
|
|
1437
1638
|
* cannot express and the tenant did not ask for.
|
|
1438
1639
|
*/
|
|
1439
|
-
async
|
|
1640
|
+
async editingScope(ctx, input) {
|
|
1440
1641
|
if (input.workflowId !== undefined) {
|
|
1441
1642
|
const { record } = await this.authorizedWorkflow(ctx, input.workflowId, 'workflow:read');
|
|
1442
1643
|
return record.attributes;
|
|
@@ -1445,7 +1646,7 @@ export class WorkflowRuntime {
|
|
|
1445
1646
|
const { record } = await this.authorizedFolder(ctx, input.folderId, 'workflow:create');
|
|
1446
1647
|
return record.attributes;
|
|
1447
1648
|
}
|
|
1448
|
-
throw new Error('
|
|
1649
|
+
throw new Error('Needs the workflow being edited, or the folder a new one will live in');
|
|
1449
1650
|
}
|
|
1450
1651
|
// ─── Internal ───
|
|
1451
1652
|
/**
|
|
@@ -1659,6 +1860,8 @@ export class WorkflowRuntime {
|
|
|
1659
1860
|
}
|
|
1660
1861
|
: {}),
|
|
1661
1862
|
});
|
|
1863
|
+
// Announced here rather than per call site: every run passes through.
|
|
1864
|
+
this.publishRunChange(workflow, execId, scheduled ? 'SCHEDULED' : 'PENDING');
|
|
1662
1865
|
if (scheduled) {
|
|
1663
1866
|
// The delay is the fast path; `fireAt` on the row is the truth. A host that
|
|
1664
1867
|
// sweeps for overdue runs makes a lost job late rather than lost.
|