@beehexa/hexasync-template-validate 2611.8.3 → 2612.3.1
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/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/validate/answerAgentTool.d.ts +15 -3
- package/dist/validate/answerAgentTool.d.ts.map +1 -1
- package/dist/validate/answerAgentTool.js +71 -15
- package/dist/validate/answerAgentTool.js.map +1 -1
- package/dist/validate/boundedAgentTool.d.ts +1 -1
- package/dist/validate/boundedAgentTool.d.ts.map +1 -1
- package/dist/validate/boundedAgentTool.js +18 -2
- package/dist/validate/boundedAgentTool.js.map +1 -1
- package/dist/validate/buildValidationModel.d.ts +3 -2
- package/dist/validate/buildValidationModel.d.ts.map +1 -1
- package/dist/validate/buildValidationModel.js +2 -2
- package/dist/validate/buildValidationModel.js.map +1 -1
- package/dist/validate/frontendFailureReferences.d.ts +6 -0
- package/dist/validate/frontendFailureReferences.d.ts.map +1 -0
- package/dist/validate/frontendFailureReferences.js +456 -0
- package/dist/validate/frontendFailureReferences.js.map +1 -0
- package/dist/validate/frontendReferences.d.ts +12 -1
- package/dist/validate/frontendReferences.d.ts.map +1 -1
- package/dist/validate/frontendReferences.js +119 -22
- package/dist/validate/frontendReferences.js.map +1 -1
- package/dist/validate/frontendTypeKnowledge.d.ts +6 -2
- package/dist/validate/frontendTypeKnowledge.d.ts.map +1 -1
- package/dist/validate/frontendTypeKnowledge.js +39 -7
- package/dist/validate/frontendTypeKnowledge.js.map +1 -1
- package/dist/validate/model.d.ts.map +1 -1
- package/dist/validate/model.js +2 -1
- package/dist/validate/model.js.map +1 -1
- package/dist/validate/registry.d.ts +6 -6
- package/dist/validate/registry.d.ts.map +1 -1
- package/dist/validate/registry.js +10 -5
- package/dist/validate/registry.js.map +1 -1
- package/dist/validate/retrieve.d.ts +1 -1
- package/dist/validate/rule.d.ts +9 -1
- package/dist/validate/rule.d.ts.map +1 -1
- package/dist/validate/ruleCatalog.d.ts.map +1 -1
- package/dist/validate/ruleCatalog.js +23 -13
- package/dist/validate/ruleCatalog.js.map +1 -1
- package/dist/validate/rules/groupedFrontend.d.ts +2 -2
- package/dist/validate/rules/groupedFrontend.d.ts.map +1 -1
- package/dist/validate/rules/groupedFrontend.js +523 -100
- package/dist/validate/rules/groupedFrontend.js.map +1 -1
- package/dist/validate/sourceLocator.d.ts +5 -1
- package/dist/validate/sourceLocator.d.ts.map +1 -1
- package/dist/validate/sourceLocator.js +13 -0
- package/dist/validate/sourceLocator.js.map +1 -1
- package/package.json +10 -8
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
import { FRONTEND_SELECTED_METADATA_FIELDS, FRONTEND_UNPROCESSED_RESULT_TYPES } from '@beehexa/hexasync-template-context';
|
|
1
2
|
import { normalizeFrontendStepFlags } from '../frontendFlags.js';
|
|
2
3
|
import { CONNECTOR_WORKFLOW_KEYS, locateFrontendWorkflows } from '@beehexa/hexasync-template-frontend-flow';
|
|
3
4
|
import { frontendOutputReferences } from '../frontendReferences.js';
|
|
5
|
+
import { expressionOutputReferenceCandidates } from '../frontendFailureReferences.js';
|
|
4
6
|
const own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
5
7
|
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
8
|
const text = (value) => typeof value === 'string' && value.length > 0;
|
|
9
|
+
const flowKey = (value) => text(value) && value.length <= 128 && /^[A-Z][A-Z0-9_]*$/.test(value);
|
|
7
10
|
const guidance = {
|
|
8
11
|
1: 'Use a key-only FrontendFlow envelope with title, action.label, string completionVersion and nonempty steps. Omission and [] are valid; null is not.',
|
|
9
12
|
2: 'Use only true, false, "true" or "false" for root/dryRun; omit an unset flag. Metadata expressions are not coerced.',
|
|
10
13
|
3: 'dependsOn must contain distinct existing keys in this group, without self-links or cycles. Array order does not imply a prerequisite.',
|
|
11
14
|
4: 'Use distinct flow-local step keys and exactly one root: true. Step syntax is type/root/metadata, not the worker dialect.',
|
|
12
|
-
5: 'Route only to a step in this flow. Correct the literal next/onCancelled/IF/SWITCH target; a prerequisite does not share steps.',
|
|
13
|
-
6: 'RETURN is terminal: SUCCESS needs object/jsonata:: outputs, FAILED needs error {code,message}, CANCELLED has neither. No next
|
|
14
|
-
7: '
|
|
15
|
-
8: 'Every grouped
|
|
15
|
+
5: 'Route only to a step in this flow, by its exact key. Correct the literal next/onCancelled/IF/SWITCH target; a prerequisite does not share steps. Only {{ }}/{% %} Liquid or a jsonata:: prefix is dynamic; liquid:: and ${…} render literally.',
|
|
16
|
+
6: 'RETURN is terminal: SUCCESS needs object/jsonata:: outputs, FAILED needs error {code,message} with nonempty strings, CANCELLED has neither. No next or onCancelled; grouped RETURN forbids top-level outputs, direct RETURN tolerates only absent, null or []. FAIL is terminal too: metadata is exactly {code,message} with a literal ^[A-Z][A-Z0-9_]*$ code and a nonblank message; next/onCancelled only absent or null, outputs only absent, null or [].',
|
|
17
|
+
7: 'API_PROXY metadata is exactly {connectionId, url, method, headers?, queries?, body?, responseFilters?} (responseFilters is a literal object in the worker data.responseFilters grammar — parser ID -> output key -> {expression: string, acceptedStatuses?: status-key strings}, run by the connector hook, not the browser — or a whole-member templated string that maps to one; acceptHttpStatuses is refused: every provider status comes back as an answer with outputs.<KEY>.outcome): a literal connectionId is a GUID naming a connectors[].id, url is relative to the connection (no : before the first /, ? or #, never //), method is GET/POST/PUT/PATCH/DELETE/HEAD/OPTIONS. Profile, credential and transport are host- and gateway-owned; no step-level url/method/profile/connection/header/credential members and no dry run. It runs only in getReadyFlows. Failures never follow next and an unknown outcome is never resent.',
|
|
18
|
+
8: 'Every grouped step must route to an explicit RETURN or FAIL — a missing, null or blank next/arm/default or a blank onCancelled is rejected even on an unreachable step. Runtime exhaustion is MISSING_RETURN, never success.',
|
|
16
19
|
9: 'Static validation cannot certify a dynamic route or loop terminates or succeeds. Runtime exhaustion remains MISSING_RETURN.',
|
|
17
|
-
10: 'Frontend outputs belong only to nonterminal steps in the enclosing workflow. Prerequisites and sibling workflows do not inject data; worker _outputs is a different namespace.
|
|
18
|
-
11: 'Uncertain focus/root bindings, opaque or incomplete producer selectors, namespace predicates and duplicate local keys cannot establish one output owner statically. Keep ownership uncertain; runtime mapping still checks it.',
|
|
20
|
+
10: 'Frontend outputs belong only to nonterminal steps in the enclosing workflow. Prerequisites and sibling workflows do not inject data; worker _outputs is a different namespace.',
|
|
21
|
+
11: 'Uncertain focus/root bindings, opaque or incomplete producer selectors, whole-namespace reads, namespace predicates and duplicate local keys cannot establish one output owner statically; RECORDS_FORM search.items sees only the search response, so an outputs read there names a response member (read workflow values in search.request, label or fill). Keep ownership uncertain; runtime mapping still checks it.',
|
|
22
|
+
13: 'An API or GATEWAY_API step can fail in a controlled way, and an API_PROXY answer with any outcome (even error), then follows its plain next (classify outputs.<KEY>.outcome and results.body; an API_PROXY failure always ends the run), so a literal next straight into a SUCCESS RETURN would report success. Route through an IF step or a next branch object ({if, then, else}) that classifies the result, or to a FAILED RETURN, a FAIL step or an intermediate step.',
|
|
23
|
+
14: 'A failed API or GATEWAY_API needs a possible recovery route: a failed arm, an output read in its own next, or a reachable step that can read its result. This static advice does not prove that a branch executes. At runtime the failure stays unread until an actual workflow expression uses that run\'s output; comments, literals, unused branches and response-only projections do not handle it. Classify outputs.<KEY>.errorCode or _response.statusCode where you recover, or end the run failed.',
|
|
19
24
|
};
|
|
25
|
+
/** Profiles.api publication and dashboard admission: a FAIL code is a fixed literal, never templated. */
|
|
26
|
+
const FAIL_CODE = /^[A-Z][A-Z0-9_]*$/;
|
|
20
27
|
function closed(value, allowed, path, rule, emit) {
|
|
21
28
|
for (const key of Object.keys(value)) {
|
|
22
29
|
if (!allowed.includes(key))
|
|
@@ -55,30 +62,183 @@ function jsonValue(value) {
|
|
|
55
62
|
}
|
|
56
63
|
return true;
|
|
57
64
|
}
|
|
58
|
-
|
|
59
|
-
|
|
65
|
+
const API_PROXY_MEMBERS = ['connectionId', 'url', 'method', 'headers', 'queries', 'body', 'responseFilters'];
|
|
66
|
+
const API_PROXY_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
|
|
67
|
+
const API_PROXY_STEP_FORBIDDEN = ['url', 'method', 'profile', 'profileId', 'connection', 'connectionId', 'header', 'headers', 'credential', 'credentialId', 'credentials'];
|
|
68
|
+
/** Liquid tag or jsonata:: prefix: mapped at runtime (dashboard `mapPureValue`), so only checked after mapping. */
|
|
69
|
+
const templated = (value) => value.includes('{{') || value.includes('{%') || value.startsWith('jsonata::');
|
|
70
|
+
/** A `**Variable**` placeholder is substituted at deployment, so its final value is not known while authoring. */
|
|
71
|
+
const placeholder = (value) => /^\*\*[^*]+\*\*$/.test(value);
|
|
72
|
+
/** The gateway route binds `{connectionId:guid}`; a literal id is a GUID in its 8-4-4-4-12 form. */
|
|
73
|
+
const CONNECTION_ID = /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/;
|
|
74
|
+
/**
|
|
75
|
+
* The gateway refuses a url with any `:` before the first `/`, `?` or `#` (a scheme such as `https:` or `mailto:`).
|
|
76
|
+
* For a Liquid-templated url only the literal text before the first tag is known while authoring.
|
|
77
|
+
*/
|
|
78
|
+
function schemeLike(url) {
|
|
79
|
+
const tag = url.search(/\{\{|\{%/);
|
|
80
|
+
const literal = tag < 0 ? url : url.slice(0, tag);
|
|
81
|
+
const delimiter = literal.search(/[/?#]/);
|
|
82
|
+
return (delimiter < 0 ? literal : literal.slice(0, delimiter)).includes(':');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Story 7.5 dashboard admission of API_PROXY (`groupedWorkflowDefinition.ts`), plus the authoring-only connector
|
|
86
|
+
* check: a literal connectionId must be a GUID naming a declared `connectors[].id`; a templated one cannot be checked.
|
|
87
|
+
*/
|
|
88
|
+
function apiProxyStep(step, path, emit, grouped, connectorIds) {
|
|
89
|
+
// connectorIds holds token-form AND output-form ids: a declared `**Variable**` id and its substituted literal both verify.
|
|
90
|
+
if (!grouped)
|
|
91
|
+
emit(7, [...path, 'type'], 'API_PROXY runs only inside getReadyFlows; a direct step array has no profile context and fails it with MISSING_PROFILE_CONTEXT.');
|
|
92
|
+
for (const key of API_PROXY_STEP_FORBIDDEN) {
|
|
93
|
+
if (own(step, key))
|
|
94
|
+
emit(7, [...path, key], `API_PROXY refuses step-level ${key}; the request shape lives in metadata and the profile, connection credential and transport are host- and gateway-owned.`);
|
|
95
|
+
}
|
|
96
|
+
if (step.dryRun === true || step.dryRun === 'true')
|
|
97
|
+
emit(7, [...path, 'dryRun'], 'API_PROXY cannot run as a dry run.');
|
|
98
|
+
if (!object(step.metadata)) {
|
|
99
|
+
emit(7, [...path, 'metadata'], 'API_PROXY metadata must be an object.');
|
|
60
100
|
return;
|
|
61
|
-
|
|
101
|
+
}
|
|
102
|
+
const metadata = step.metadata;
|
|
103
|
+
const at = [...path, 'metadata'];
|
|
104
|
+
closed(metadata, API_PROXY_MEMBERS, at, 7, emit);
|
|
105
|
+
const connectionId = metadata.connectionId;
|
|
106
|
+
if (typeof connectionId !== 'string' || connectionId.trim() === '') {
|
|
107
|
+
emit(7, [...at, 'connectionId'], 'API_PROXY requires a nonblank connectionId naming one of this template\'s connectors[].id.');
|
|
108
|
+
}
|
|
109
|
+
else if (templated(connectionId) || placeholder(connectionId)) {
|
|
110
|
+
if (connectorIds !== undefined && !connectorIds.has(connectionId))
|
|
111
|
+
emit(7, [...at, 'connectionId'], 'connectionId is templated or a **Variable** placeholder, so the editor cannot check that it is a GUID naming a declared connector; a wrong id fails the step at the gateway.', 'low');
|
|
112
|
+
}
|
|
113
|
+
else if (!CONNECTION_ID.test(connectionId)) {
|
|
114
|
+
emit(7, [...at, 'connectionId'], 'connectionId must be a GUID such as 55555555-5555-4555-8555-555555555555: the gateway route accepts only a GUID connection id.');
|
|
115
|
+
}
|
|
116
|
+
else if (connectorIds !== undefined && !connectorIds.has(connectionId)) {
|
|
117
|
+
emit(7, [...at, 'connectionId'], `connectionId ${connectionId} is not the id of any connectors[] entry in this template.`);
|
|
118
|
+
}
|
|
119
|
+
const url = metadata.url;
|
|
120
|
+
if (typeof url !== 'string' || url.trim() === '')
|
|
121
|
+
emit(7, [...at, 'url'], 'API_PROXY requires a url relative to the connection, for example /v1/orders.');
|
|
122
|
+
else if (!url.startsWith('jsonata::') && (schemeLike(url) || /^\s*[\\/]{2}/.test(url)))
|
|
123
|
+
emit(7, [...at, 'url'], 'API_PROXY url must be relative to the connection (for example /v1/orders); a : before the first /, ? or # (a scheme) or a leading // names a host and is refused because the connection decides the host.');
|
|
124
|
+
else if (!templated(url) && /[\s\\\u0000-\u001f\u007f-\u009f]/.test(url))
|
|
125
|
+
emit(7, [...at, 'url'], 'API_PROXY url must not contain whitespace, control characters or a backslash.');
|
|
126
|
+
const method = metadata.method;
|
|
127
|
+
if (typeof method !== 'string' || method.trim() === '')
|
|
128
|
+
emit(7, [...at, 'method'], `API_PROXY requires method: one of ${API_PROXY_METHODS.join(', ')}.`);
|
|
129
|
+
else if (!templated(method) && !API_PROXY_METHODS.includes(method.toUpperCase()))
|
|
130
|
+
emit(7, [...at, 'method'], `API_PROXY method must be one of ${API_PROXY_METHODS.join(', ')}.`);
|
|
131
|
+
const mapped = (value) => typeof value === 'string' && templated(value);
|
|
132
|
+
if (own(metadata, 'headers') && !mapped(metadata.headers)) {
|
|
133
|
+
if (!object(metadata.headers))
|
|
134
|
+
emit(7, [...at, 'headers'], 'API_PROXY headers must be an object whose values are strings or lists of strings.');
|
|
135
|
+
else
|
|
136
|
+
for (const [name, value] of Object.entries(metadata.headers)) {
|
|
137
|
+
if (typeof value !== 'string' && !mapped(value) && !(Array.isArray(value) && value.every((item) => typeof item === 'string')))
|
|
138
|
+
emit(7, [...at, 'headers', name], 'A header value must be a string or a list of strings.');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (own(metadata, 'queries') && !object(metadata.queries) && !mapped(metadata.queries))
|
|
142
|
+
emit(7, [...at, 'queries'], 'API_PROXY queries must be an object.');
|
|
143
|
+
if (own(metadata, 'body') && !jsonValue(metadata.body))
|
|
144
|
+
emit(7, [...at, 'body'], 'API_PROXY body must be JSON data.');
|
|
145
|
+
if (own(metadata, 'responseFilters') && !mapped(metadata.responseFilters)) {
|
|
146
|
+
if (!object(metadata.responseFilters))
|
|
147
|
+
emit(7, [...at, 'responseFilters'], 'API_PROXY responseFilters must be an object shaped like a worker API step data.responseFilters (for example {jsonata: {name: {expression: \'data.id\'}}}) or a templated string that maps to one; the gateway refuses any other value with INVALID_RESPONSE_FILTERS.');
|
|
148
|
+
else
|
|
149
|
+
literalResponseFilters(metadata.responseFilters, [...at, 'responseFilters'], emit);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Parser IDs of the canonical worker filter grammar (`assets/responseFilters/responseFilters.json`), exact case. */
|
|
153
|
+
const RESPONSE_FILTER_PARSERS = ['jsonata', 'jsonpath', 'xpath', 'scriban', 'scriban_xml', 'regex_replace', 'base64', 'raw_text'];
|
|
154
|
+
/**
|
|
155
|
+
* A literal responseFilters object reaches the connector hook unchanged, so it must already be in the canonical worker
|
|
156
|
+
* grammar: parser ID -> output key -> {expression: string, acceptedStatuses?: string[] | null}, nothing else.
|
|
157
|
+
*/
|
|
158
|
+
function literalResponseFilters(filters, at, emit) {
|
|
159
|
+
const grammar = 'parser ID -> output key -> {expression, acceptedStatuses?}, as a worker API step data.responseFilters';
|
|
160
|
+
for (const [parser, group] of Object.entries(filters)) {
|
|
161
|
+
const groupAt = [...at, parser];
|
|
162
|
+
if (!RESPONSE_FILTER_PARSERS.includes(parser)) {
|
|
163
|
+
emit(7, groupAt, `${parser} is not a response-filter parser ID; use one of ${RESPONSE_FILTER_PARSERS.join(', ')} (exact case).`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (!object(group)) {
|
|
167
|
+
emit(7, groupAt, `responseFilters.${parser} must be an object of output key -> {expression, acceptedStatuses?} (${grammar}).`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
for (const [output, leaf] of Object.entries(group)) {
|
|
171
|
+
const leafAt = [...groupAt, output];
|
|
172
|
+
if (!object(leaf)) {
|
|
173
|
+
emit(7, leafAt, `Response filter ${parser}.${output} must be an object {expression, acceptedStatuses?}, not a bare expression.`);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
for (const member of Object.keys(leaf)) {
|
|
177
|
+
if (member !== 'expression' && member !== 'acceptedStatuses')
|
|
178
|
+
emit(7, [...leafAt, member], `Response filter ${parser}.${output} allows only expression and acceptedStatuses.`);
|
|
179
|
+
}
|
|
180
|
+
if (typeof leaf.expression !== 'string')
|
|
181
|
+
emit(7, [...leafAt, 'expression'], `Response filter ${parser}.${output} requires a string expression (base64 and raw_text ignore its content but still require it).`);
|
|
182
|
+
const statuses = leaf.acceptedStatuses;
|
|
183
|
+
if (statuses === undefined || statuses === null)
|
|
184
|
+
continue;
|
|
185
|
+
if (!Array.isArray(statuses)) {
|
|
186
|
+
emit(7, [...leafAt, 'acceptedStatuses'], 'acceptedStatuses must be a list of status-key strings, null or omitted.');
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
for (const [index, status] of statuses.entries()) {
|
|
190
|
+
if (typeof status !== 'string')
|
|
191
|
+
emit(7, [...leafAt, 'acceptedStatuses', String(index)], `acceptedStatuses lists status-key strings, never raw status numbers such as ${JSON.stringify(status)}. API_PROXY has no acceptHttpStatuses, so omit acceptedStatuses to keep the output for every status.`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function specialStep(step, path, emit, grouped, connectorIds) {
|
|
197
|
+
if (step.type === 'API_PROXY') {
|
|
198
|
+
apiProxyStep(step, path, emit, grouped, connectorIds);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (step.type !== 'RETURN' && step.type !== 'FAIL')
|
|
202
|
+
return;
|
|
203
|
+
const rule = 6;
|
|
62
204
|
closed(step, ['key', 'type', 'root', 'dryRun', 'name', 'description', 'arguments', 'metadata', 'outputs', 'msg', 'repeatableCount', 'repeatableDetailCount', 'status', 'next', 'onCancelled'], path, rule, emit);
|
|
205
|
+
if (step.type === 'RETURN') {
|
|
206
|
+
for (const key of ['next', 'onCancelled']) {
|
|
207
|
+
if (own(step, key))
|
|
208
|
+
emit(rule, [...path, key], `RETURN forbids ${key}, even when empty or null.`);
|
|
209
|
+
}
|
|
210
|
+
if (own(step, 'outputs')) {
|
|
211
|
+
if (grouped)
|
|
212
|
+
emit(rule, [...path, 'outputs'], 'Grouped RETURN forbids outputs, even when empty or null.');
|
|
213
|
+
else if (step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
214
|
+
emit(rule, [...path, 'outputs'], 'RETURN forbids output processors; outputs must be absent, null or [].');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (step.type === 'FAIL') {
|
|
218
|
+
// Same tolerance as profiles.api publication and dashboard admission: routes may be absent or null only,
|
|
219
|
+
// output processors absent, null or [] only.
|
|
220
|
+
for (const key of ['next', 'onCancelled']) {
|
|
221
|
+
if (own(step, key) && step[key] !== null)
|
|
222
|
+
emit(rule, [...path, key], `FAIL is terminal: ${key} must be absent or null.`);
|
|
223
|
+
}
|
|
224
|
+
if (own(step, 'outputs') && step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
225
|
+
emit(rule, [...path, 'outputs'], 'FAIL forbids output processors; outputs must be absent, null or [].');
|
|
226
|
+
}
|
|
63
227
|
if (!object(step.metadata)) {
|
|
64
228
|
emit(rule, [...path, 'metadata'], `${step.type} metadata must be an object.`);
|
|
65
229
|
return;
|
|
66
230
|
}
|
|
67
231
|
const metadata = step.metadata;
|
|
68
232
|
const at = [...path, 'metadata'];
|
|
69
|
-
if (step.type === '
|
|
70
|
-
closed(metadata, ['
|
|
71
|
-
if (
|
|
72
|
-
emit(rule, [...at, '
|
|
73
|
-
if (
|
|
74
|
-
emit(rule, [...at, '
|
|
233
|
+
if (step.type === 'FAIL') {
|
|
234
|
+
closed(metadata, ['code', 'message'], at, rule, emit);
|
|
235
|
+
if (typeof metadata.code !== 'string' || !FAIL_CODE.test(metadata.code))
|
|
236
|
+
emit(rule, [...at, 'code'], 'FAIL code must be a literal string matching ^[A-Z][A-Z0-9_]*$; a templated code is not accepted.');
|
|
237
|
+
if (typeof metadata.message !== 'string' || metadata.message.trim() === '')
|
|
238
|
+
emit(rule, [...at, 'message'], 'FAIL message must be a nonblank string.');
|
|
75
239
|
return;
|
|
76
240
|
}
|
|
77
241
|
closed(metadata, ['status', 'outputs', 'error'], at, rule, emit);
|
|
78
|
-
for (const key of ['next', 'onCancelled', 'outputs']) {
|
|
79
|
-
if (own(step, key))
|
|
80
|
-
emit(rule, [...path, key], `RETURN forbids ${key}, even when empty or null.`);
|
|
81
|
-
}
|
|
82
242
|
const status = metadata.status;
|
|
83
243
|
if (status !== 'SUCCESS' && status !== 'FAILED' && status !== 'CANCELLED')
|
|
84
244
|
emit(rule, [...at, 'status'], 'RETURN status must be exactly SUCCESS, FAILED or CANCELLED.');
|
|
@@ -96,9 +256,11 @@ function specialStep(step, path, emit) {
|
|
|
96
256
|
}
|
|
97
257
|
else {
|
|
98
258
|
closed(metadata.error, ['code', 'message'], [...at, 'error'], rule, emit);
|
|
259
|
+
// Dashboard grouped admission requires nonempty trimmed code and message strings.
|
|
99
260
|
for (const key of ['code', 'message']) {
|
|
100
|
-
|
|
101
|
-
|
|
261
|
+
const value = metadata.error[key];
|
|
262
|
+
if (typeof value !== 'string' || value.trim() === '')
|
|
263
|
+
emit(rule, [...at, 'error', key], `FAILED error.${key} must be a nonempty string.`);
|
|
102
264
|
}
|
|
103
265
|
}
|
|
104
266
|
}
|
|
@@ -106,9 +268,247 @@ function specialStep(step, path, emit) {
|
|
|
106
268
|
emit(rule, [...at, 'error'], 'Only FAILED may declare error.');
|
|
107
269
|
}
|
|
108
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Mirrors the dashboard's grouped admission and `calculateNextProcessKey`: only a Liquid tag or an explicit
|
|
273
|
+
* `jsonata::` prefix makes a route dynamic. Any other text — `liquid::X`, `${X}`, ` X` — renders literally at runtime,
|
|
274
|
+
* so it is a literal key matched exactly.
|
|
275
|
+
*/
|
|
276
|
+
const dynamicRoute = (route) => route.includes('{{') || route.includes('{%') || route.startsWith('jsonata::');
|
|
277
|
+
/**
|
|
278
|
+
* Remote-action step types whose ordinary outcome includes a controlled failure — the dashboard's
|
|
279
|
+
* `FALLIBLE_STEP_TYPES` (`groupedWorkflowDefinition.ts`). API_PROXY is fallible because any gateway 200 answer — outcome
|
|
280
|
+
* error included — advances to `next`; its failures never route. Local
|
|
281
|
+
* transforms, storage, navigation, pass-through steps, WAIT, IF/SWITCH and terminals are not checked.
|
|
282
|
+
*/
|
|
283
|
+
const FALLIBLE_STEP_TYPES = { API: true, GATEWAY_API: true, API_PROXY: true };
|
|
284
|
+
const outputProcessorTypes = {
|
|
285
|
+
jsonata: true, liquid: true, GET_LOCAL_STORAGE: true, SET_LOCAL_STORAGE: true,
|
|
286
|
+
};
|
|
287
|
+
function collectStrings(value, into, seen, metadataType = '', root = true, language, projection = false, transformedKeys = false, path) {
|
|
288
|
+
const selected = Object.hasOwn(FRONTEND_SELECTED_METADATA_FIELDS, metadataType)
|
|
289
|
+
? FRONTEND_SELECTED_METADATA_FIELDS[metadataType] : undefined;
|
|
290
|
+
if ((selected !== undefined || metadataType === 'RECORDS_FORM_SEARCH') && !object(value))
|
|
291
|
+
return;
|
|
292
|
+
if (['FORM_FIELD', 'FORM_VALIDATION'].includes(metadataType) && !Array.isArray(value) && !object(value))
|
|
293
|
+
return;
|
|
294
|
+
if (typeof value === 'string') {
|
|
295
|
+
const forcedLiquid = metadataType === 'OUTPUT_GET_LOCAL_STORAGE' || metadataType === 'OUTPUT_SET_LOCAL_STORAGE';
|
|
296
|
+
const expression = { text: value, language: language ?? (forcedLiquid || !value.startsWith('jsonata::') ? 'liquid' : 'jsonata') };
|
|
297
|
+
if (path !== undefined)
|
|
298
|
+
expression.path = path;
|
|
299
|
+
into.push(expression);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (value === null || typeof value !== 'object' || seen.has(value))
|
|
303
|
+
return;
|
|
304
|
+
const type = (root || projection) && object(value) && typeof value.type === 'string' ? value.type.toUpperCase() : '';
|
|
305
|
+
if (root && type === 'RETURN' && object(value) && object(value.metadata) && value.metadata.status === 'CANCELLED')
|
|
306
|
+
return;
|
|
307
|
+
seen.add(value);
|
|
308
|
+
for (const [key, item] of Object.entries(value)) {
|
|
309
|
+
if (root && type && !['metadata', 'arguments', 'outputs', 'next', 'onCancelled', 'name', 'description'].includes(key))
|
|
310
|
+
continue;
|
|
311
|
+
if (root && ['RETURN', 'FAIL'].includes(type) && key !== 'metadata' && key !== 'arguments')
|
|
312
|
+
continue;
|
|
313
|
+
if (selected && !selected.includes(key))
|
|
314
|
+
continue;
|
|
315
|
+
if (['IF', 'SWITCH', 'JSONATA', 'LIQUID', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM'].includes(metadataType) &&
|
|
316
|
+
typeof item !== 'string')
|
|
317
|
+
continue;
|
|
318
|
+
if (metadataType === 'RETURN' && key !== (object(value) && value.status === 'FAILED' ? 'error' : 'outputs'))
|
|
319
|
+
continue;
|
|
320
|
+
if (metadataType === 'FAIL' && key !== 'code' && key !== 'message')
|
|
321
|
+
continue;
|
|
322
|
+
if (metadataType === 'FORM' && ((key === 'notice' && typeof item !== 'string') ||
|
|
323
|
+
(key === 'fields' && !Array.isArray(item))))
|
|
324
|
+
continue;
|
|
325
|
+
if (metadataType === 'FORM_VALIDATION' && !Array.isArray(value) &&
|
|
326
|
+
(!object(value) || value.type !== 'API' || !['metadata', 'isOk', 'message'].includes(key)))
|
|
327
|
+
continue;
|
|
328
|
+
if ((metadataType === 'SHOW_INFO' || metadataType === 'INTEGRATION_APP_MANAGEMENT') && typeof item !== 'string')
|
|
329
|
+
continue;
|
|
330
|
+
if (metadataType === 'RECORDS_FORM' && key === 'search' && path === undefined &&
|
|
331
|
+
(!object(value) || !object(value.allow) || value.allow.add !== true))
|
|
332
|
+
continue;
|
|
333
|
+
if (metadataType === 'RECORDS_FORM_SEARCH' && key === 'items') {
|
|
334
|
+
// A located scope finding may name response-owned data; it can never be a recovery witness.
|
|
335
|
+
if (path !== undefined && typeof item === 'string')
|
|
336
|
+
into.push({ text: item, language: 'jsonata', path: [...path, key], responseFocused: true });
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (metadataType === 'RECORDS_FORM_SEARCH' && !['request', 'label', 'fill'].includes(key))
|
|
340
|
+
continue;
|
|
341
|
+
if (root && key === 'outputs' && FRONTEND_UNPROCESSED_RESULT_TYPES[type] === true)
|
|
342
|
+
continue;
|
|
343
|
+
if (projection && !Array.isArray(value) && (key !== 'metadata' || !object(value) ||
|
|
344
|
+
typeof value.type !== 'string' || !Object.hasOwn(outputProcessorTypes, value.type)))
|
|
345
|
+
continue;
|
|
346
|
+
if (['OUTPUT_JSONATA', 'OUTPUT_LIQUID'].includes(metadataType) && key !== 'expression')
|
|
347
|
+
continue;
|
|
348
|
+
// A literal API_PROXY responseFilters object is hook-owned (its Scriban/JSONata run in the connector hook, never in
|
|
349
|
+
// the browser), so it holds no frontend reads; only a whole-member mapped string is a workflow expression.
|
|
350
|
+
if (metadataType === 'API_PROXY' && key === 'responseFilters' && typeof item !== 'string')
|
|
351
|
+
continue;
|
|
352
|
+
const fieldPath = path === undefined ? undefined : [...path, key];
|
|
353
|
+
if (transformedKeys && (key.startsWith('jsonata::') || key.includes('{{') || key.includes('{%'))) {
|
|
354
|
+
collectStrings(key, into, seen, '', false, undefined, false, false, fieldPath);
|
|
355
|
+
}
|
|
356
|
+
let fieldLanguage;
|
|
357
|
+
let fieldValue = item;
|
|
358
|
+
if (typeof item === 'string') {
|
|
359
|
+
if ((metadataType === 'IF' && key === 'condition') || (metadataType === 'SWITCH' && key === 'expression')) {
|
|
360
|
+
const trimmed = item.trim();
|
|
361
|
+
fieldLanguage = 'liquid';
|
|
362
|
+
if (trimmed.startsWith('${') && trimmed.endsWith('}')) {
|
|
363
|
+
fieldLanguage = 'liquid-jsonata';
|
|
364
|
+
fieldValue = trimmed.slice(2, -1);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else if (key === 'expression' &&
|
|
368
|
+
['JSONATA', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM'].includes(metadataType)) {
|
|
369
|
+
fieldLanguage = 'liquid-jsonata';
|
|
370
|
+
}
|
|
371
|
+
else if ((key === 'expression' && ['LIQUID', 'OUTPUT_LIQUID'].includes(metadataType)) ||
|
|
372
|
+
(metadataType === 'RECORDS_FORM_SEARCH' && key === 'label')) {
|
|
373
|
+
fieldLanguage = 'liquid';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
// Only the step's own metadata fields use their handler grammar. Nested data and ordinary
|
|
377
|
+
// output processors use generic first-stage transforms; response-only second passes aren't root reads.
|
|
378
|
+
const childProjection = (projection && Array.isArray(value)) ||
|
|
379
|
+
(root && key === 'outputs' && Array.isArray(item) && type !== 'RETURN' && type !== 'FAIL');
|
|
380
|
+
const childMetadataType = (metadataType === 'FORM' && key === 'fields') ||
|
|
381
|
+
(metadataType === 'FORM_FIELD' && Array.isArray(value)) ? 'FORM_FIELD'
|
|
382
|
+
: (metadataType === 'FORM_FIELD' && key === 'validations') ||
|
|
383
|
+
(metadataType === 'FORM_VALIDATION' && Array.isArray(value)) ? 'FORM_VALIDATION'
|
|
384
|
+
: metadataType === 'RECORDS_FORM' && key === 'search' ? 'RECORDS_FORM_SEARCH'
|
|
385
|
+
: (root || projection) && key === 'metadata' ? `${projection ? 'OUTPUT_' : ''}${type}` : '';
|
|
386
|
+
const childKeys = metadataType === 'FORM_FIELD' && key === 'validations' ? false :
|
|
387
|
+
(metadataType === 'FORM_VALIDATION' && key === 'metadata') || transformedKeys || (root && key === 'arguments') ||
|
|
388
|
+
(metadataType === 'RECORDS_FORM' && key === 'initial') ||
|
|
389
|
+
(root && key === 'metadata' &&
|
|
390
|
+
!['IF', 'SWITCH', 'JSONATA', 'LIQUID', 'SINGLE_CHOICE_FORM', 'MULTIPLE_CHOICE_FORM', 'RETURN', 'FAIL', 'RECORDS_FORM'].includes(type)) ||
|
|
391
|
+
(['RETURN', 'FAIL'].includes(metadataType) && (key === 'outputs' || key === 'error'));
|
|
392
|
+
collectStrings(fieldValue, into, seen, childMetadataType, false, fieldLanguage, childProjection, childKeys, fieldPath);
|
|
393
|
+
}
|
|
394
|
+
// Active-path cycle detection must not suppress a shared value's different owning-field grammar.
|
|
395
|
+
seen.delete(value);
|
|
396
|
+
}
|
|
397
|
+
/** Every route target a step can take: `next` arms, `onCancelled`, IF then/else, SWITCH cases/default. */
|
|
398
|
+
function routeTargets(step) {
|
|
399
|
+
const into = [];
|
|
400
|
+
const visit = (route, seen) => {
|
|
401
|
+
if (typeof route === 'string') {
|
|
402
|
+
if (route)
|
|
403
|
+
into.push(route);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (!object(route) || seen.has(route))
|
|
407
|
+
return;
|
|
408
|
+
seen.add(route);
|
|
409
|
+
for (const arm of ['then', 'else', 'success', 'failed'])
|
|
410
|
+
visit(route[arm], seen);
|
|
411
|
+
};
|
|
412
|
+
visit(step.next, new Set());
|
|
413
|
+
visit(step.onCancelled, new Set());
|
|
414
|
+
const metadata = step.metadata;
|
|
415
|
+
if (!object(metadata))
|
|
416
|
+
return into;
|
|
417
|
+
if (step.type === 'IF') {
|
|
418
|
+
visit(metadata.then, new Set());
|
|
419
|
+
visit(metadata.else, new Set());
|
|
420
|
+
}
|
|
421
|
+
if (step.type === 'SWITCH') {
|
|
422
|
+
if (object(metadata.cases))
|
|
423
|
+
for (const target of Object.values(metadata.cases))
|
|
424
|
+
visit(target, new Set());
|
|
425
|
+
visit(metadata.default, new Set());
|
|
426
|
+
}
|
|
427
|
+
return into;
|
|
428
|
+
}
|
|
429
|
+
/** One candidate at a time, including rejected syntax; an empty candidate still permits cancellation. */
|
|
430
|
+
function* failureConsumerWitnesses(nodes, key) {
|
|
431
|
+
const node = nodes.get(key);
|
|
432
|
+
if (!node?.fallible)
|
|
433
|
+
return;
|
|
434
|
+
if (node.explicitFailed) {
|
|
435
|
+
yield true;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
for (const { text, language } of node.ownNext) {
|
|
439
|
+
for (const candidate of expressionOutputReferenceCandidates(text, language))
|
|
440
|
+
yield candidate.has(key);
|
|
441
|
+
}
|
|
442
|
+
const visited = new Set(), pending = [...node.targets];
|
|
443
|
+
while (pending.length) {
|
|
444
|
+
const next = pending.pop();
|
|
445
|
+
if (visited.has(next))
|
|
446
|
+
continue;
|
|
447
|
+
const reader = nodes.get(next);
|
|
448
|
+
if (!reader)
|
|
449
|
+
continue;
|
|
450
|
+
visited.add(next);
|
|
451
|
+
for (const { text, language } of reader.readers) {
|
|
452
|
+
for (const candidate of expressionOutputReferenceCandidates(text, language))
|
|
453
|
+
yield candidate.has(key);
|
|
454
|
+
}
|
|
455
|
+
pending.push(...reader.targets);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Match the runtime's potential eligibility, never actual consumption. Snapshot primitive fields before
|
|
460
|
+
* yielding; complete structural choices can require exponential total work, so hosts may cancel the run.
|
|
461
|
+
*/
|
|
462
|
+
async function potentialRecoverySteps(steps, options) {
|
|
463
|
+
options.signal?.throwIfAborted();
|
|
464
|
+
const nodes = new Map();
|
|
465
|
+
for (const step of steps) {
|
|
466
|
+
if (!step || typeof step.key !== 'string' || nodes.has(step.key))
|
|
467
|
+
continue;
|
|
468
|
+
const ownNext = [], readers = [];
|
|
469
|
+
collectStrings(step.next, ownNext, new Set());
|
|
470
|
+
collectStrings(step, readers, new Set());
|
|
471
|
+
nodes.set(step.key, {
|
|
472
|
+
fallible: typeof step.type === 'string' && Object.hasOwn(FALLIBLE_STEP_TYPES, step.type),
|
|
473
|
+
ownNext, readers, targets: routeTargets(step),
|
|
474
|
+
explicitFailed: object(step.next) && own(step.next, 'failed'),
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
const keys = [...nodes.keys()];
|
|
478
|
+
for (const node of nodes.values())
|
|
479
|
+
if (node.targets.some(dynamicRoute))
|
|
480
|
+
node.targets = keys;
|
|
481
|
+
const consumed = new Set();
|
|
482
|
+
for (const [key, node] of nodes) {
|
|
483
|
+
if (!node.fallible)
|
|
484
|
+
continue;
|
|
485
|
+
const candidates = failureConsumerWitnesses(nodes, key);
|
|
486
|
+
try {
|
|
487
|
+
while (true) {
|
|
488
|
+
options.signal?.throwIfAborted();
|
|
489
|
+
const candidate = candidates.next();
|
|
490
|
+
options.signal?.throwIfAborted();
|
|
491
|
+
if (candidate.done)
|
|
492
|
+
break;
|
|
493
|
+
if (candidate.value) {
|
|
494
|
+
consumed.add(key);
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
498
|
+
setTimeout(resolve, 0);
|
|
499
|
+
await promise;
|
|
500
|
+
options.signal?.throwIfAborted();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
finally {
|
|
504
|
+
candidates.return(undefined);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
return consumed;
|
|
508
|
+
}
|
|
109
509
|
/** Inspect only routing fields; never walk user payloads looking for something that resembles a step. */
|
|
110
510
|
function routes(step, path, keys, emit) {
|
|
111
|
-
if (step.type === 'RETURN')
|
|
511
|
+
if (step.type === 'RETURN' || step.type === 'FAIL')
|
|
112
512
|
return { targets: [], exits: [], uncertain: [] };
|
|
113
513
|
const pending = [];
|
|
114
514
|
const exits = [];
|
|
@@ -116,10 +516,11 @@ function routes(step, path, keys, emit) {
|
|
|
116
516
|
const targets = [];
|
|
117
517
|
const metadata = object(step.metadata) ? step.metadata : {};
|
|
118
518
|
if (step.type === 'IF' || step.type === 'SWITCH') {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
519
|
+
if (own(step, 'next'))
|
|
520
|
+
emit(5, [...path, 'next'], `${step.type} routes through metadata and forbids next.`);
|
|
521
|
+
// Dashboard admission ignores an empty processor list here, so only a non-empty one is a defect.
|
|
522
|
+
if (own(step, 'outputs') && step.outputs !== null && !(Array.isArray(step.outputs) && step.outputs.length === 0))
|
|
523
|
+
emit(5, [...path, 'outputs'], `${step.type} routes through metadata and forbids output processors; outputs may only be absent, null or [].`);
|
|
123
524
|
closed(metadata, step.type === 'IF' ? ['condition', 'then', 'else'] : ['expression', 'cases', 'default'], [...path, 'metadata'], 5, emit);
|
|
124
525
|
const expression = step.type === 'IF' ? 'condition' : 'expression';
|
|
125
526
|
if (typeof metadata[expression] !== 'string')
|
|
@@ -152,10 +553,11 @@ function routes(step, path, keys, emit) {
|
|
|
152
553
|
else {
|
|
153
554
|
pending.push({ value: step.next, path: [...path, 'next'] });
|
|
154
555
|
}
|
|
155
|
-
|
|
556
|
+
// A declared string onCancelled is a route (blank → certain exit, as admission treats it); null/absent declares none.
|
|
557
|
+
if (typeof step.onCancelled === 'string') {
|
|
156
558
|
pending.push({ value: step.onCancelled, path: [...path, 'onCancelled'] });
|
|
157
559
|
}
|
|
158
|
-
else if (step.onCancelled != null
|
|
560
|
+
else if (step.onCancelled != null) {
|
|
159
561
|
emit(5, [...path, 'onCancelled'], 'onCancelled must be a string route when declared.');
|
|
160
562
|
}
|
|
161
563
|
const entered = new Set();
|
|
@@ -170,11 +572,11 @@ function routes(step, path, keys, emit) {
|
|
|
170
572
|
exits.push([...route.path]);
|
|
171
573
|
}
|
|
172
574
|
else if (typeof value === 'string') {
|
|
173
|
-
if (
|
|
575
|
+
if (dynamicRoute(value)) {
|
|
174
576
|
uncertain.push([...route.path]);
|
|
175
577
|
}
|
|
176
578
|
else {
|
|
177
|
-
const target = keys.get(value
|
|
579
|
+
const target = keys.get(value);
|
|
178
580
|
if (target === undefined)
|
|
179
581
|
emit(5, route.path, `Literal route ${JSON.stringify(value)} does not name a step in this flow.`);
|
|
180
582
|
else
|
|
@@ -202,7 +604,7 @@ function routes(step, path, keys, emit) {
|
|
|
202
604
|
}
|
|
203
605
|
return { targets, exits, uncertain };
|
|
204
606
|
}
|
|
205
|
-
function checkSteps(flow, path, emit) {
|
|
607
|
+
async function checkSteps(flow, path, emit, options, connectorIds) {
|
|
206
608
|
if (!Array.isArray(flow.steps) || flow.steps.length === 0)
|
|
207
609
|
return;
|
|
208
610
|
const keys = new Map();
|
|
@@ -234,7 +636,7 @@ function checkSteps(flow, path, emit) {
|
|
|
234
636
|
if (own(step, workerKey))
|
|
235
637
|
emit(4, [...at, workerKey], `Worker member ${workerKey} is not frontend syntax.`);
|
|
236
638
|
}
|
|
237
|
-
specialStep(step, at, emit);
|
|
639
|
+
specialStep(step, at, emit, true, connectorIds);
|
|
238
640
|
}
|
|
239
641
|
if (roots.length === 0)
|
|
240
642
|
emit(4, [...path, 'steps'], 'Grouped flow has no true root.');
|
|
@@ -242,10 +644,45 @@ function checkSteps(flow, path, emit) {
|
|
|
242
644
|
for (const index of roots)
|
|
243
645
|
emit(4, [...path, 'steps', String(index), 'root'], 'Grouped flow has multiple true roots.');
|
|
244
646
|
}
|
|
245
|
-
if (!steps.some((step) => step?.type === 'RETURN'))
|
|
246
|
-
emit(8, [...path, 'steps'], 'Grouped flow is missing RETURN.');
|
|
647
|
+
if (!steps.some((step) => step?.type === 'RETURN' || step?.type === 'FAIL'))
|
|
648
|
+
emit(8, [...path, 'steps'], 'Grouped flow is missing RETURN or FAIL.');
|
|
649
|
+
// Mirrors the dashboard's grouped admission: a controlled API/GATEWAY_API failure follows its plain `next`, so a
|
|
650
|
+
// literal `next` straight into a SUCCESS RETURN would succeed the run. Classify the outcome first (IF or a next
|
|
651
|
+
// branch object). Templated routes, FAILED RETURNs, FAIL steps and intermediate steps stay allowed.
|
|
652
|
+
const straightToSuccess = new Set();
|
|
653
|
+
for (const [index, step] of steps.entries()) {
|
|
654
|
+
if (!step || typeof step.type !== 'string' || !Object.hasOwn(FALLIBLE_STEP_TYPES, step.type) || typeof step.next !== 'string')
|
|
655
|
+
continue;
|
|
656
|
+
const route = step.next;
|
|
657
|
+
if (!route.trim() || dynamicRoute(route))
|
|
658
|
+
continue;
|
|
659
|
+
const target = keys.has(route) ? steps[keys.get(route)] : undefined;
|
|
660
|
+
if (target?.type === 'RETURN' && object(target.metadata) && target.metadata.status === 'SUCCESS') {
|
|
661
|
+
straightToSuccess.add(index);
|
|
662
|
+
emit(13, [...path, 'steps', String(index), 'next'], `${step.type} step ${String(step.key)} must not lead straight to a SUCCESS RETURN (${route}); classify its outcome first.`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
// The dashboard routes a grouped step's failure only when it is consumed; any other failure ends the run failed.
|
|
666
|
+
// A step already reported by FFE-13 is not reported twice.
|
|
667
|
+
const consumed = await potentialRecoverySteps(steps, options);
|
|
668
|
+
const firstIndex = new Map();
|
|
669
|
+
for (const [index, step] of steps.entries())
|
|
670
|
+
if (step && typeof step.key === 'string' && !firstIndex.has(step.key))
|
|
671
|
+
firstIndex.set(step.key, index);
|
|
672
|
+
for (const [key, index] of firstIndex) {
|
|
673
|
+
const step = steps[index];
|
|
674
|
+
// API_PROXY failures never route (they always end the run), so recovery advice does not apply; FFE-13 still does.
|
|
675
|
+
if (typeof step.type !== 'string' || !Object.hasOwn(FALLIBLE_STEP_TYPES, step.type) || step.type === 'API_PROXY' || straightToSuccess.has(index) || consumed.has(key))
|
|
676
|
+
continue;
|
|
677
|
+
emit(14, [...path, 'steps', String(index)], `Failed step ${key}'s failure is not read by any reachable step, so the run will fail. A ${String(step.type)} failure is handled only where a step reachable from ${key} reads outputs.${key}; read it where you recover, or leave it unread only to end the run failed on purpose.`);
|
|
678
|
+
}
|
|
247
679
|
const graph = steps.map((step, index) => step ? routes(step, [...path, 'steps', String(index)], keys, emit) : undefined);
|
|
248
|
-
//
|
|
680
|
+
// A certain exit is rejected on every step, reachable or not — the dashboard's grouped admission and the canonical
|
|
681
|
+
// graph both refuse it, so certifying only the reachable ones would pass a declaration the runtime rejects.
|
|
682
|
+
for (const edges of graph)
|
|
683
|
+
for (const exit of edges?.exits ?? [])
|
|
684
|
+
emit(8, exit, 'Statically certain implicit exit without RETURN (MISSING_RETURN).');
|
|
685
|
+
// Only known reachable paths establish uncertainty; unknown routing never proves success or reachability.
|
|
249
686
|
const reached = new Set();
|
|
250
687
|
const pending = roots.length === 1 ? [...roots] : [];
|
|
251
688
|
while (pending.length) {
|
|
@@ -256,8 +693,6 @@ function checkSteps(flow, path, emit) {
|
|
|
256
693
|
const edges = graph[index];
|
|
257
694
|
if (!edges)
|
|
258
695
|
continue;
|
|
259
|
-
for (const exit of edges.exits)
|
|
260
|
-
emit(8, exit, 'Statically certain implicit exit without RETURN (MISSING_RETURN).');
|
|
261
696
|
for (const at of edges.uncertain)
|
|
262
697
|
emit(9, at, 'Dynamic or cyclic route is statically uncertain; termination and success are not certified.');
|
|
263
698
|
pending.push(...edges.targets);
|
|
@@ -303,8 +738,8 @@ function checkDependencies(flows, emit) {
|
|
|
303
738
|
const seen = new Set();
|
|
304
739
|
for (const [dependencyIndex, dependency] of flow.dependsOn.entries()) {
|
|
305
740
|
const path = [...at, String(dependencyIndex)];
|
|
306
|
-
if (!
|
|
307
|
-
emit(3, path, 'Dependency must
|
|
741
|
+
if (!flowKey(dependency)) {
|
|
742
|
+
emit(3, path, 'Dependency must match ^[A-Z][A-Z0-9_]*$ with at most 128 characters.');
|
|
308
743
|
continue;
|
|
309
744
|
}
|
|
310
745
|
if (seen.has(dependency))
|
|
@@ -344,84 +779,72 @@ function checkDependencies(flows, emit) {
|
|
|
344
779
|
}
|
|
345
780
|
}
|
|
346
781
|
}
|
|
347
|
-
/** Scope
|
|
782
|
+
/** Scope and possible recovery share one owning-field walk; literal configuration is never code. */
|
|
348
783
|
function checkOutputScope(steps, base, emit) {
|
|
349
784
|
const local = new Map();
|
|
350
785
|
for (const step of steps) {
|
|
351
|
-
if (!object(step) || !text(step.key) || step.type === 'RETURN')
|
|
786
|
+
if (!object(step) || !text(step.key) || step.type === 'RETURN' || step.type === 'FAIL')
|
|
352
787
|
continue;
|
|
353
788
|
local.set(step.key, (local.get(step.key) ?? 0) + 1);
|
|
354
789
|
}
|
|
355
790
|
for (const [index, step] of steps.entries()) {
|
|
356
791
|
if (!object(step))
|
|
357
792
|
continue;
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
if (
|
|
365
|
-
|
|
793
|
+
const fields = [];
|
|
794
|
+
collectStrings(step, fields, new Set(), '', true, undefined, false, false, [...base, String(index)]);
|
|
795
|
+
for (const field of fields) {
|
|
796
|
+
// Passing a root path above makes every collected field located, including transformed keys.
|
|
797
|
+
const path = field.path;
|
|
798
|
+
const references = frontendOutputReferences(field.text, field.language);
|
|
799
|
+
if (field.responseFocused) {
|
|
800
|
+
if (references.length)
|
|
801
|
+
emit(11, path, 'search.items is evaluated against the search response, not this workflow: an outputs/_outputs read here names a response member, valid only if the response has one. Read workflow values in search.request, label or fill instead.');
|
|
366
802
|
continue;
|
|
367
803
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
// member, so a same-flow read is no more valid than a sibling one and must not certify.
|
|
378
|
-
const rawJsonata = frame.path.length === base.length + 3 &&
|
|
379
|
-
frame.path[base.length + 1] === 'metadata' &&
|
|
380
|
-
frame.path[base.length + 2] === 'expression' &&
|
|
381
|
-
(step.type === 'JSONATA' || step.type === 'SINGLE_CHOICE_FORM' || step.type === 'MULTIPLE_CHOICE_FORM');
|
|
382
|
-
const responseFocused = step.type === 'RECORDS_FORM' && frame.path.length === base.length + 4 &&
|
|
383
|
-
frame.path[base.length + 1] === 'metadata' && frame.path[base.length + 2] === 'search' &&
|
|
384
|
-
frame.path[base.length + 3] === 'items';
|
|
385
|
-
const references = frontendOutputReferences(frame.value, rawJsonata);
|
|
386
|
-
if (responseFocused) {
|
|
387
|
-
if (references.length)
|
|
388
|
-
emit(10, frame.path, 'search.items is evaluated against the search response, not this workflow: an outputs/_outputs read here names a response member. Read workflow values in search.request, label or fill instead.');
|
|
389
|
-
continue;
|
|
390
|
-
}
|
|
391
|
-
for (const reference of references) {
|
|
392
|
-
if (reference.rootCertainty === 'uncertain')
|
|
393
|
-
emit(11, frame.path, 'Output ownership is statically uncertain; lexical focus, root rebinding or opaque template output prevents establishing the workflow root.');
|
|
394
|
-
else if (reference.namespace === '_outputs')
|
|
395
|
-
emit(10, frame.path, 'Worker _outputs is not a frontend output namespace.');
|
|
396
|
-
else if (reference.key === undefined || (local.get(reference.key) ?? 0) > 1)
|
|
397
|
-
emit(11, frame.path, 'Output ownership is statically uncertain; a predicate, computed or incomplete producer selector, or duplicate local key cannot establish one producer.');
|
|
398
|
-
else if (!local.has(reference.key))
|
|
399
|
-
emit(10, frame.path, `Output ${reference.key} is not produced by a nonterminal step in this workflow.`);
|
|
400
|
-
}
|
|
401
|
-
continue;
|
|
804
|
+
for (const reference of references) {
|
|
805
|
+
if (reference.rootCertainty === 'uncertain')
|
|
806
|
+
emit(11, path, 'Output ownership is statically uncertain; lexical focus, root rebinding or opaque template output prevents establishing the workflow root.');
|
|
807
|
+
else if (reference.namespace === '_outputs')
|
|
808
|
+
emit(10, path, 'Worker _outputs is not a frontend output namespace.');
|
|
809
|
+
else if (reference.key === undefined || (local.get(reference.key) ?? 0) > 1)
|
|
810
|
+
emit(11, path, 'Output ownership is statically uncertain; a predicate, computed or incomplete producer selector, or duplicate local key cannot establish one producer.');
|
|
811
|
+
else if (!local.has(reference.key))
|
|
812
|
+
emit(10, path, `Output ${reference.key} is not produced by a nonterminal step in this workflow.`);
|
|
402
813
|
}
|
|
403
|
-
if ((!object(frame.value) && !Array.isArray(frame.value)) || active.has(frame.value))
|
|
404
|
-
continue;
|
|
405
|
-
active.add(frame.value);
|
|
406
|
-
pending.push({ leave: frame.value });
|
|
407
|
-
for (const [key, value] of Object.entries(frame.value))
|
|
408
|
-
pending.push({ value, path: [...frame.path, key] });
|
|
409
814
|
}
|
|
410
815
|
}
|
|
411
816
|
}
|
|
817
|
+
/**
|
|
818
|
+
* Literal `connectors[].id` values of the composed document. `undefined` (no connectors array) means the ids are not
|
|
819
|
+
* known here — a partial file may inherit them — so the connector check is skipped rather than guessed.
|
|
820
|
+
*/
|
|
821
|
+
function declaredConnectorIds(...documents) {
|
|
822
|
+
let ids;
|
|
823
|
+
for (const document of documents) {
|
|
824
|
+
if (!object(document) || !Array.isArray(document.connectors))
|
|
825
|
+
continue;
|
|
826
|
+
ids ??= new Set();
|
|
827
|
+
for (const connector of document.connectors)
|
|
828
|
+
if (object(connector) && typeof connector.id === 'string')
|
|
829
|
+
ids.add(connector.id);
|
|
830
|
+
}
|
|
831
|
+
return ids;
|
|
832
|
+
}
|
|
412
833
|
export const groupedFrontendRule = {
|
|
413
834
|
id: 'FFE',
|
|
414
835
|
family: 'FFE',
|
|
415
|
-
run(ctx) {
|
|
836
|
+
async run(ctx, options = {}) {
|
|
416
837
|
const document = ctx.tokenForm;
|
|
417
838
|
if (!object(document))
|
|
418
839
|
return [];
|
|
419
840
|
const issues = [];
|
|
420
841
|
const group = document.getReadyFlows;
|
|
421
|
-
|
|
842
|
+
// Token form keeps `**Variable**` ids; output form carries their substituted literals (connectorIdentity.ts).
|
|
843
|
+
const connectorIds = declaredConnectorIds(document, ctx.outputForm);
|
|
844
|
+
const emit = (rule, path, message, severity) => {
|
|
422
845
|
const flow = Array.isArray(group) ? group[Number(path[0])] : undefined;
|
|
423
846
|
issues.push({
|
|
424
|
-
ruleId: `FFE-${rule}`, family: 'FFE', severity: rule === 9 ? 'low' : 'high',
|
|
847
|
+
ruleId: `FFE-${rule}`, family: 'FFE', severity: severity ?? (rule === 9 ? 'low' : rule === 14 ? 'medium' : 'high'),
|
|
425
848
|
parentKey: 'getReadyFlows', idOrKey: object(flow) && text(flow.key) ? flow.key : undefined,
|
|
426
849
|
componentPath: path,
|
|
427
850
|
message: `getReadyFlows${path.map((part) => `[${JSON.stringify(part)}]`).join('')}: ${message}`,
|
|
@@ -439,8 +862,8 @@ export const groupedFrontendRule = {
|
|
|
439
862
|
continue;
|
|
440
863
|
}
|
|
441
864
|
closed(flow, ['key', 'title', 'description', 'action', 'completionVersion', 'dependsOn', 'steps'], at, 1, emit);
|
|
442
|
-
if (!
|
|
443
|
-
emit(1, [...at, 'key'], 'Flow key must match ^[A-Z][A-Z0-9_]
|
|
865
|
+
if (!flowKey(flow.key))
|
|
866
|
+
emit(1, [...at, 'key'], 'Flow key must match ^[A-Z][A-Z0-9_]*$ with at most 128 characters.');
|
|
444
867
|
if (typeof flow.title !== 'string')
|
|
445
868
|
emit(1, [...at, 'title'], 'title must be a string.');
|
|
446
869
|
if (!text(flow.completionVersion))
|
|
@@ -458,7 +881,7 @@ export const groupedFrontendRule = {
|
|
|
458
881
|
}
|
|
459
882
|
if (!Array.isArray(flow.steps) || flow.steps.length === 0)
|
|
460
883
|
emit(1, [...at, 'steps'], 'steps must be a nonempty array.');
|
|
461
|
-
checkSteps(flow, at, emit);
|
|
884
|
+
await checkSteps(flow, at, emit, options, connectorIds);
|
|
462
885
|
}
|
|
463
886
|
checkDependencies(group, emit);
|
|
464
887
|
}
|
|
@@ -468,10 +891,10 @@ export const groupedFrontendRule = {
|
|
|
468
891
|
for (const [index, step] of steps.entries()) {
|
|
469
892
|
if (!object(step))
|
|
470
893
|
continue;
|
|
471
|
-
specialStep(step, [...base, String(index)], (rule, path, message) => issues.push({
|
|
472
|
-
ruleId: `FFE-${rule}`, family: 'FFE', severity: 'high', parentKey, idOrKey,
|
|
473
|
-
componentPath: path, message: `${parentKey}
|
|
474
|
-
}));
|
|
894
|
+
specialStep(step, [...base, String(index)], (rule, path, message, severity) => issues.push({
|
|
895
|
+
ruleId: `FFE-${rule}`, family: 'FFE', severity: severity ?? 'high', parentKey, idOrKey,
|
|
896
|
+
componentPath: path, message: `${parentKey ? `${parentKey}.` : ''}${path.join('.')}: ${message}`, why: `${guidance[rule]} See hexasync://docs/frontend/FRONTEND-FLOWS.`,
|
|
897
|
+
}), false, connectorIds);
|
|
475
898
|
}
|
|
476
899
|
};
|
|
477
900
|
const locations = locateFrontendWorkflows(document);
|
|
@@ -481,7 +904,7 @@ export const groupedFrontendRule = {
|
|
|
481
904
|
checkOutputScope(location.steps, path, (rule, componentPath, message) => issues.push({
|
|
482
905
|
ruleId: `FFE-${rule}`, family: 'FFE', severity: rule === 11 ? 'low' : 'high',
|
|
483
906
|
parentKey, idOrKey: location.flowKey ?? location.ownerKey, componentPath,
|
|
484
|
-
message: `${parentKey}
|
|
907
|
+
message: `${parentKey ? `${parentKey}.` : ''}${componentPath.join('.')}: ${message}`,
|
|
485
908
|
why: `${guidance[rule]} See hexasync://docs/frontend/FRONTEND-FLOWS.`,
|
|
486
909
|
}));
|
|
487
910
|
if (location.groupKey)
|