@usearazzo/runner 1.0.1-alpha.28 → 1.0.1-alpha.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usearazzo/runner",
3
- "version": "1.0.1-alpha.28",
3
+ "version": "1.0.1-alpha.29",
4
4
  "description": "Runner for Arazzo Workflows.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -73,8 +73,8 @@
73
73
  "@swaggerexpert/json-pointer": "^3.0.2",
74
74
  "@swaggerexpert/jsonpath": "^4.0.5",
75
75
  "@swaggerexpert/media-types": "^1.0.2",
76
- "@usearazzo/parser": "1.0.1-alpha.28",
77
- "@usearazzo/resolver": "1.0.1-alpha.28",
76
+ "@usearazzo/parser": "1.0.1-alpha.29",
77
+ "@usearazzo/resolver": "1.0.1-alpha.29",
78
78
  "@xmldom/xmldom": "^0.9.12",
79
79
  "fontoxpath": "^3.34.0",
80
80
  "ramda": "^0.32.0",
@@ -94,5 +94,5 @@
94
94
  "devDependencies": {
95
95
  "swagger-client": "^3.39.0"
96
96
  },
97
- "gitHead": "a6908027adcc7a67f773a453431dae704eba60f7"
97
+ "gitHead": "113b0d571325f56bb364e7fc9a492e7e6d08dfee"
98
98
  }
@@ -17,6 +17,8 @@ var _ArazzoRunnerError = _interopRequireDefault(require("./ArazzoRunnerError.cjs
17
17
  class ExecutionError extends _ArazzoRunnerError.default {
18
18
  /** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
19
19
  static Aborted = 'aborted';
20
+ /** Two `executeOptions` entries name source descriptions that point at the same document. */
21
+ static AmbiguousExecuteOptions = 'ambiguous-execute-options';
20
22
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
21
23
  static AmbiguousTarget = 'ambiguous-target';
22
24
  /** The `dependsOn` edges alone form a cycle between workflows. */
@@ -51,7 +53,7 @@ class ExecutionError extends _ArazzoRunnerError.default {
51
53
  static StepBudget = 'step-budget';
52
54
  /** An action declares a `type` other than `end`, `goto` or `retry`. */
53
55
  static UnknownActionType = 'unknown-action-type';
54
- /** `execute` received an option it does not know. */
56
+ /** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
55
57
  static UnknownExecuteOption = 'unknown-execute-option';
56
58
  /** A step produced a transition the workflow executor does not recognize. */
57
59
  static UnknownTransitionKind = 'unknown-transition-kind';
@@ -10,6 +10,8 @@ import ArazzoRunnerError from "./ArazzoRunnerError.mjs";
10
10
  class ExecutionError extends ArazzoRunnerError {
11
11
  /** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
12
12
  static Aborted = 'aborted';
13
+ /** Two `executeOptions` entries name source descriptions that point at the same document. */
14
+ static AmbiguousExecuteOptions = 'ambiguous-execute-options';
13
15
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
14
16
  static AmbiguousTarget = 'ambiguous-target';
15
17
  /** The `dependsOn` edges alone form a cycle between workflows. */
@@ -44,7 +46,7 @@ class ExecutionError extends ArazzoRunnerError {
44
46
  static StepBudget = 'step-budget';
45
47
  /** An action declares a `type` other than `end`, `goto` or `retry`. */
46
48
  static UnknownActionType = 'unknown-action-type';
47
- /** `execute` received an option it does not know. */
49
+ /** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
48
50
  static UnknownExecuteOption = 'unknown-execute-option';
49
51
  /** A step produced a transition the workflow executor does not recognize. */
50
52
  static UnknownTransitionKind = 'unknown-transition-kind';
@@ -46,6 +46,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
46
46
  // the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
47
47
  const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
48
48
 
49
+ /**
50
+ * The credential for one security scheme, in the form the vendored
51
+ * swagger-client applies it: the key or token itself (or `{ value }`) for an
52
+ * `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
53
+ * basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
54
+ * or `openIdConnect` scheme.
55
+ * @public
56
+ */
57
+
58
+ /**
59
+ * Credentials for the security schemes of an OpenAPI document, keyed by the
60
+ * scheme name under `components.securitySchemes` (`securityDefinitions` in
61
+ * OpenAPI 2.0).
62
+ * @public
63
+ */
64
+
49
65
  /**
50
66
  * Options for executing an OpenAPI operation.
51
67
  *
@@ -55,11 +71,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
55
71
  * building the request and sending it.
56
72
  *
57
73
  * Typed here are the options the runner itself drives and the ones callers
58
- * routinely reach for. The rest of `buildRequest`'s surface (`securities`,
59
- * `scheme`, `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is
60
- * deliberately left untyped and passes through the bag's open tail unchanged —
61
- * see {@link OpenAPIOperationExecuteOptionsBag}. Authentication in particular
62
- * is not modeled: Arazzo is auth-agnostic, so credentials are applied with a
74
+ * routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
75
+ * `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
76
+ * left untyped and passes through the bag's open tail unchanged — see
77
+ * {@link OpenAPIOperationExecuteOptionsBag}.
78
+ *
79
+ * Arazzo is auth-agnostic, so credentials come from outside the workflow:
80
+ * static ones for the security schemes the OpenAPI document declares go in
81
+ * `securities`, and anything computed per request is applied with a
63
82
  * {@link RequestInterceptor}.
64
83
  * @public
65
84
  */
@@ -72,11 +91,9 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
72
91
  * the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
73
92
  * `attachContentTypeForEmptyPayload`, …) passes through untouched.
74
93
  *
75
- * Nothing routine belongs in the tail. Credentials go through a
76
- * {@link RequestInterceptor} and `server` covers every case that once needed a
77
- * `contextUrl`, so reaching for either of those here means an edge case: tests
78
- * standing in for a document fetched over HTTP, or credentials applied from the
79
- * document's own security schemes.
94
+ * Nothing routine belongs in the tail. `server` covers every case that once
95
+ * needed a `contextUrl`, so reaching for that here means an edge case: tests
96
+ * standing in for a document fetched over HTTP.
80
97
  *
81
98
  * Two kinds of entry are inert rather than honored, since the executor owns
82
99
  * what they used to control. The operation target always comes from the
@@ -36,6 +36,22 @@ const UNDECLARED_LOCATIONS = new Set(['header', 'query', 'cookie', 'path']);
36
36
  // the header parameters OpenAPI 3 says SHALL be ignored, which buildRequest drops
37
37
  const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
38
38
 
39
+ /**
40
+ * The credential for one security scheme, in the form the vendored
41
+ * swagger-client applies it: the key or token itself (or `{ value }`) for an
42
+ * `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
43
+ * basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
44
+ * or `openIdConnect` scheme.
45
+ * @public
46
+ */
47
+
48
+ /**
49
+ * Credentials for the security schemes of an OpenAPI document, keyed by the
50
+ * scheme name under `components.securitySchemes` (`securityDefinitions` in
51
+ * OpenAPI 2.0).
52
+ * @public
53
+ */
54
+
39
55
  /**
40
56
  * Options for executing an OpenAPI operation.
41
57
  *
@@ -45,11 +61,14 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
45
61
  * building the request and sending it.
46
62
  *
47
63
  * Typed here are the options the runner itself drives and the ones callers
48
- * routinely reach for. The rest of `buildRequest`'s surface (`securities`,
49
- * `scheme`, `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is
50
- * deliberately left untyped and passes through the bag's open tail unchanged —
51
- * see {@link OpenAPIOperationExecuteOptionsBag}. Authentication in particular
52
- * is not modeled: Arazzo is auth-agnostic, so credentials are applied with a
64
+ * routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
65
+ * `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
66
+ * left untyped and passes through the bag's open tail unchanged — see
67
+ * {@link OpenAPIOperationExecuteOptionsBag}.
68
+ *
69
+ * Arazzo is auth-agnostic, so credentials come from outside the workflow:
70
+ * static ones for the security schemes the OpenAPI document declares go in
71
+ * `securities`, and anything computed per request is applied with a
53
72
  * {@link RequestInterceptor}.
54
73
  * @public
55
74
  */
@@ -62,11 +81,9 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
62
81
  * the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
63
82
  * `attachContentTypeForEmptyPayload`, …) passes through untouched.
64
83
  *
65
- * Nothing routine belongs in the tail. Credentials go through a
66
- * {@link RequestInterceptor} and `server` covers every case that once needed a
67
- * `contextUrl`, so reaching for either of those here means an edge case: tests
68
- * standing in for a document fetched over HTTP, or credentials applied from the
69
- * document's own security schemes.
84
+ * Nothing routine belongs in the tail. `server` covers every case that once
85
+ * needed a `contextUrl`, so reaching for that here means an edge case: tests
86
+ * standing in for a document fetched over HTTP.
70
87
  *
71
88
  * Two kinds of entry are inert rather than honored, since the executor owns
72
89
  * what they used to control. The operation target always comes from the
@@ -65,6 +65,13 @@ const STEP_TARGET_FIELDS = exports.STEP_TARGET_FIELDS = ['operationId', 'operati
65
65
  * @internal
66
66
  */
67
67
 
68
+ /**
69
+ * The execute options of a step: the opaque bag forwarded to the operation
70
+ * executor, or a function returning it for the operation the step was located
71
+ * to.
72
+ * @public
73
+ */
74
+
68
75
  /**
69
76
  * Executes a single Arazzo step that invokes an OpenAPI operation.
70
77
  *
@@ -127,7 +134,9 @@ class StepExecutor {
127
134
  * `executeOptions` is an opaque bag passed through to the operation executor
128
135
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
129
136
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
130
- * take precedence over it.
137
+ * take precedence over it. A function is called with the operation the step
138
+ * was located to and returns the bag, for options that depend on which API
139
+ * the step calls.
131
140
  *
132
141
  * A `signal` in that bag is honored here and not only at the transport: an
133
142
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -169,6 +178,7 @@ class StepExecutor {
169
178
  // Pointer) locator that the operation executor extracts, normalizes,
170
179
  // assembles into a standalone doc, and runs.
171
180
  const locator = await this.#locateOperation(step, scope);
181
+ const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
172
182
 
173
183
  // resolve parameters and request body against the pre-request context.
174
184
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -182,7 +192,7 @@ class StepExecutor {
182
192
  // still reach this line — and this is the last moment before the step has a
183
193
  // live side effect. The signal stays in the bag, so a request already in
184
194
  // flight is aborted by the transport as before.
185
- const signal = (0, _abort.readAbortSignal)(executeOptions);
195
+ const signal = (0, _abort.readAbortSignal)(operationOptions);
186
196
  (0, _abort.throwIfAborted)(signal, scope);
187
197
 
188
198
  // the Arazzo-derived parameters and request body are spread after the opaque
@@ -191,7 +201,7 @@ class StepExecutor {
191
201
  let response;
192
202
  try {
193
203
  response = await this.#operationExecutor.execute(locator, {
194
- ...executeOptions,
204
+ ...operationOptions,
195
205
  parameters,
196
206
  ...this.#requestBodyOptions(requestBody)
197
207
  });
@@ -58,6 +58,13 @@ export const STEP_TARGET_FIELDS = ['operationId', 'operationPath', 'workflowId']
58
58
  * @internal
59
59
  */
60
60
 
61
+ /**
62
+ * The execute options of a step: the opaque bag forwarded to the operation
63
+ * executor, or a function returning it for the operation the step was located
64
+ * to.
65
+ * @public
66
+ */
67
+
61
68
  /**
62
69
  * Executes a single Arazzo step that invokes an OpenAPI operation.
63
70
  *
@@ -120,7 +127,9 @@ class StepExecutor {
120
127
  * `executeOptions` is an opaque bag passed through to the operation executor
121
128
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
122
129
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
123
- * take precedence over it.
130
+ * take precedence over it. A function is called with the operation the step
131
+ * was located to and returns the bag, for options that depend on which API
132
+ * the step calls.
124
133
  *
125
134
  * A `signal` in that bag is honored here and not only at the transport: an
126
135
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -162,6 +171,7 @@ class StepExecutor {
162
171
  // Pointer) locator that the operation executor extracts, normalizes,
163
172
  // assembles into a standalone doc, and runs.
164
173
  const locator = await this.#locateOperation(step, scope);
174
+ const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
165
175
 
166
176
  // resolve parameters and request body against the pre-request context.
167
177
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -175,7 +185,7 @@ class StepExecutor {
175
185
  // still reach this line — and this is the last moment before the step has a
176
186
  // live side effect. The signal stays in the bag, so a request already in
177
187
  // flight is aborted by the transport as before.
178
- const signal = readAbortSignal(executeOptions);
188
+ const signal = readAbortSignal(operationOptions);
179
189
  throwIfAborted(signal, scope);
180
190
 
181
191
  // the Arazzo-derived parameters and request body are spread after the opaque
@@ -184,7 +194,7 @@ class StepExecutor {
184
194
  let response;
185
195
  try {
186
196
  response = await this.#operationExecutor.execute(locator, {
187
- ...executeOptions,
197
+ ...operationOptions,
188
198
  parameters,
189
199
  ...this.#requestBodyOptions(requestBody)
190
200
  });
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  exports.settledResult = settledResult;
10
10
  var _apidomCore = require("@speclynx/apidom-core");
11
+ var _ramdaAdjunct = require("ramda-adjunct");
11
12
  var _apidomDatamodel = require("@speclynx/apidom-datamodel");
12
13
  var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
13
14
  var _RuntimeExpressionEvaluator = _interopRequireDefault(require("../expression/RuntimeExpressionEvaluator.cjs"));
@@ -197,23 +198,21 @@ class WorkflowExecutor {
197
198
  */
198
199
  async execute(workflowId, options = {}) {
199
200
  this.#rejectUnknownOptions(options);
200
-
201
- // a signal in the opaque bag was the only channel before this option existed,
202
- // and it still reaches the transport. Absorbing it here is what makes it a
203
- // whole cancellation rather than half of one: read only at dispatch, it would
204
- // abort requests while the loop walked on through the remaining steps.
205
- const signal = options.signal ?? (0, _abort.readAbortSignal)(options.executeOptions ?? {});
201
+ const {
202
+ signal
203
+ } = options;
204
+ const executeOptions = this.#executeOptionsByDocument(options.executeOptions ?? {});
206
205
  const scope = {
207
- // the first-class signal is also spread into the opaque bag, because that
208
- // bag is how anything reaches the transport: the executor's own checks
209
- // stop the run at the next boundary, and this is what cancels the request
210
- // already in flight. Spread last, so it wins over one passed in the bag.
211
- executeOptions: {
212
- ...options.executeOptions,
213
- ...(signal === undefined ? {} : {
214
- signal
215
- })
216
- },
206
+ // the signal is put into every step's opaque bag, because that bag is
207
+ // how anything reaches the transport: the executor's own checks stop the
208
+ // run at the next boundary, and this is what cancels the request already
209
+ // in flight. Set even when absent, so a `signal` in an entry never
210
+ // stands in for it: that one would cancel the steps of a single API and
211
+ // leave the run walking on.
212
+ executeOptions: locator => ({
213
+ ...executeOptions.get(locator.document.uri),
214
+ signal
215
+ }),
217
216
  dependencyInputs: options.dependencyInputs ?? {},
218
217
  runDependencies: options.runDependencies ?? true,
219
218
  signal,
@@ -232,6 +231,41 @@ class WorkflowExecutor {
232
231
  }), 'root');
233
232
  }
234
233
 
234
+ /**
235
+ * Resolves the `executeOptions` entries to the documents they configure,
236
+ * keyed by canonical document URI.
237
+ *
238
+ * Every way an entry can fail to name exactly one OpenAPI document throws
239
+ * here, before the run starts: sent to no API or to two, its options would
240
+ * be missing or misdirected with nothing to show for it until a request
241
+ * failed.
242
+ */
243
+ #executeOptionsByDocument(executeOptions) {
244
+ const byDocument = new Map();
245
+ const fail = (name, problem, reason) => {
246
+ throw new _ExecutionError.default(`executeOptions is keyed by source description name, and "${name}" ${problem}`, {
247
+ reason
248
+ });
249
+ };
250
+ for (const [name, options] of Object.entries(executeOptions)) {
251
+ const uri = this.#document.resolveSourceDescriptionURI(name);
252
+ if (uri === undefined) {
253
+ return fail(name, `names no source description with a url in the Arazzo document at "${this.#document.uri}"`, _ExecutionError.default.SourceDescriptionNotFound);
254
+ }
255
+ if (this.#document.resolveSourceDescriptionField(name, 'type') === 'arazzo') {
256
+ fail(name, 'names an Arazzo document', _ExecutionError.default.SourceDescriptionNotOpenAPI);
257
+ }
258
+ if (!(0, _ramdaAdjunct.isPlainObject)(options)) {
259
+ fail(name, 'is not given an object of options', _ExecutionError.default.UnknownExecuteOption);
260
+ }
261
+ if (byDocument.has(uri)) {
262
+ fail(name, `points at "${uri}", which another entry already configures`, _ExecutionError.default.AmbiguousExecuteOptions);
263
+ }
264
+ byDocument.set(uri, options);
265
+ }
266
+ return byDocument;
267
+ }
268
+
235
269
  /**
236
270
  * Rejects an options bag carrying keys this method does not recognize.
237
271
  *
@@ -1,4 +1,5 @@
1
1
  import { toValue } from '@speclynx/apidom-core';
2
+ import { isPlainObject } from 'ramda-adjunct';
2
3
  import { isArrayElement, isObjectElement, isStringElement } from '@speclynx/apidom-datamodel';
3
4
  import { isFailureActionElement, isParameterElement, isStepElement, isSuccessActionElement } from '@speclynx/apidom-ns-arazzo-1';
4
5
  import RuntimeExpressionEvaluator from "../expression/RuntimeExpressionEvaluator.mjs";
@@ -14,7 +15,7 @@ import WorkflowCallStack from "./WorkflowCallStack.mjs";
14
15
  import StepTransitionInterpreter, { actionTargets } from "./StepTransitionInterpreter.mjs";
15
16
  import ExecutionError from "../errors/ExecutionError.mjs";
16
17
  import ResolverError from "../errors/ResolverError.mjs";
17
- import { readAbortSignal, throwIfAborted } from "./abort.mjs";
18
+ import { throwIfAborted } from "./abort.mjs";
18
19
  /**
19
20
  * Options for the WorkflowExecutor.
20
21
  * @public
@@ -183,23 +184,21 @@ class WorkflowExecutor {
183
184
  */
184
185
  async execute(workflowId, options = {}) {
185
186
  this.#rejectUnknownOptions(options);
186
-
187
- // a signal in the opaque bag was the only channel before this option existed,
188
- // and it still reaches the transport. Absorbing it here is what makes it a
189
- // whole cancellation rather than half of one: read only at dispatch, it would
190
- // abort requests while the loop walked on through the remaining steps.
191
- const signal = options.signal ?? readAbortSignal(options.executeOptions ?? {});
187
+ const {
188
+ signal
189
+ } = options;
190
+ const executeOptions = this.#executeOptionsByDocument(options.executeOptions ?? {});
192
191
  const scope = {
193
- // the first-class signal is also spread into the opaque bag, because that
194
- // bag is how anything reaches the transport: the executor's own checks
195
- // stop the run at the next boundary, and this is what cancels the request
196
- // already in flight. Spread last, so it wins over one passed in the bag.
197
- executeOptions: {
198
- ...options.executeOptions,
199
- ...(signal === undefined ? {} : {
200
- signal
201
- })
202
- },
192
+ // the signal is put into every step's opaque bag, because that bag is
193
+ // how anything reaches the transport: the executor's own checks stop the
194
+ // run at the next boundary, and this is what cancels the request already
195
+ // in flight. Set even when absent, so a `signal` in an entry never
196
+ // stands in for it: that one would cancel the steps of a single API and
197
+ // leave the run walking on.
198
+ executeOptions: locator => ({
199
+ ...executeOptions.get(locator.document.uri),
200
+ signal
201
+ }),
203
202
  dependencyInputs: options.dependencyInputs ?? {},
204
203
  runDependencies: options.runDependencies ?? true,
205
204
  signal,
@@ -218,6 +217,41 @@ class WorkflowExecutor {
218
217
  }), 'root');
219
218
  }
220
219
 
220
+ /**
221
+ * Resolves the `executeOptions` entries to the documents they configure,
222
+ * keyed by canonical document URI.
223
+ *
224
+ * Every way an entry can fail to name exactly one OpenAPI document throws
225
+ * here, before the run starts: sent to no API or to two, its options would
226
+ * be missing or misdirected with nothing to show for it until a request
227
+ * failed.
228
+ */
229
+ #executeOptionsByDocument(executeOptions) {
230
+ const byDocument = new Map();
231
+ const fail = (name, problem, reason) => {
232
+ throw new ExecutionError(`executeOptions is keyed by source description name, and "${name}" ${problem}`, {
233
+ reason
234
+ });
235
+ };
236
+ for (const [name, options] of Object.entries(executeOptions)) {
237
+ const uri = this.#document.resolveSourceDescriptionURI(name);
238
+ if (uri === undefined) {
239
+ return fail(name, `names no source description with a url in the Arazzo document at "${this.#document.uri}"`, ExecutionError.SourceDescriptionNotFound);
240
+ }
241
+ if (this.#document.resolveSourceDescriptionField(name, 'type') === 'arazzo') {
242
+ fail(name, 'names an Arazzo document', ExecutionError.SourceDescriptionNotOpenAPI);
243
+ }
244
+ if (!isPlainObject(options)) {
245
+ fail(name, 'is not given an object of options', ExecutionError.UnknownExecuteOption);
246
+ }
247
+ if (byDocument.has(uri)) {
248
+ fail(name, `points at "${uri}", which another entry already configures`, ExecutionError.AmbiguousExecuteOptions);
249
+ }
250
+ byDocument.set(uri, options);
251
+ }
252
+ return byDocument;
253
+ }
254
+
221
255
  /**
222
256
  * Rejects an options bag carrying keys this method does not recognize.
223
257
  *
package/types/runner.d.ts CHANGED
@@ -816,6 +816,8 @@ export declare type DocumentRegistryProviderOptions = PartialDeep<ApiDOMReferenc
816
816
  export declare class ExecutionError extends ArazzoRunnerError {
817
817
  /** The run was cancelled through its `AbortSignal`; the signal's reason is the `cause`. */
818
818
  static readonly Aborted: "aborted";
819
+ /** Two `executeOptions` entries name source descriptions that point at the same document. */
820
+ static readonly AmbiguousExecuteOptions: "ambiguous-execute-options";
819
821
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
820
822
  static readonly AmbiguousTarget: "ambiguous-target";
821
823
  /** The `dependsOn` edges alone form a cycle between workflows. */
@@ -850,7 +852,7 @@ export declare class ExecutionError extends ArazzoRunnerError {
850
852
  static readonly StepBudget: "step-budget";
851
853
  /** An action declares a `type` other than `end`, `goto` or `retry`. */
852
854
  static readonly UnknownActionType: "unknown-action-type";
853
- /** `execute` received an option it does not know. */
855
+ /** `execute` received an option it does not know, or an `executeOptions` entry that is not an object. */
854
856
  static readonly UnknownExecuteOption: "unknown-execute-option";
855
857
  /** A step produced a transition the workflow executor does not recognize. */
856
858
  static readonly UnknownTransitionKind: "unknown-transition-kind";
@@ -1150,11 +1152,14 @@ export declare type OpenAPIOperationElement = OperationElement | OperationElemen
1150
1152
  * building the request and sending it.
1151
1153
  *
1152
1154
  * Typed here are the options the runner itself drives and the ones callers
1153
- * routinely reach for. The rest of `buildRequest`'s surface (`securities`,
1154
- * `scheme`, `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is
1155
- * deliberately left untyped and passes through the bag's open tail unchanged —
1156
- * see {@link OpenAPIOperationExecuteOptionsBag}. Authentication in particular
1157
- * is not modeled: Arazzo is auth-agnostic, so credentials are applied with a
1155
+ * routinely reach for. The rest of `buildRequest`'s surface (`scheme`,
1156
+ * `parameterBuilders`, `attachContentTypeForEmptyPayload`, …) is deliberately
1157
+ * left untyped and passes through the bag's open tail unchanged — see
1158
+ * {@link OpenAPIOperationExecuteOptionsBag}.
1159
+ *
1160
+ * Arazzo is auth-agnostic, so credentials come from outside the workflow:
1161
+ * static ones for the security schemes the OpenAPI document declares go in
1162
+ * `securities`, and anything computed per request is applied with a
1158
1163
  * {@link RequestInterceptor}.
1159
1164
  * @public
1160
1165
  */
@@ -1199,6 +1204,13 @@ export declare interface OpenAPIOperationExecuteOptions {
1199
1204
  * a declared server — an override carries no declared variables.
1200
1205
  */
1201
1206
  readonly serverVariables?: Record<string, string>;
1207
+ /**
1208
+ * Credentials for the security schemes of the operation's OpenAPI document.
1209
+ * Only the schemes the operation requires are applied, each where its
1210
+ * scheme says (header, query or cookie); an operation with an empty
1211
+ * `security` gets none.
1212
+ */
1213
+ readonly securities?: OpenAPIOperationSecurities;
1202
1214
  readonly signal?: AbortSignal;
1203
1215
  readonly requestInterceptor?: RequestInterceptor;
1204
1216
  }
@@ -1211,11 +1223,9 @@ export declare interface OpenAPIOperationExecuteOptions {
1211
1223
  * the rest of `buildRequest`'s surface (`scheme`, `parameterBuilders`,
1212
1224
  * `attachContentTypeForEmptyPayload`, …) passes through untouched.
1213
1225
  *
1214
- * Nothing routine belongs in the tail. Credentials go through a
1215
- * {@link RequestInterceptor} and `server` covers every case that once needed a
1216
- * `contextUrl`, so reaching for either of those here means an edge case: tests
1217
- * standing in for a document fetched over HTTP, or credentials applied from the
1218
- * document's own security schemes.
1226
+ * Nothing routine belongs in the tail. `server` covers every case that once
1227
+ * needed a `contextUrl`, so reaching for that here means an edge case: tests
1228
+ * standing in for a document fetched over HTTP.
1219
1229
  *
1220
1230
  * Two kinds of entry are inert rather than honored, since the executor owns
1221
1231
  * what they used to control. The operation target always comes from the
@@ -1609,6 +1619,33 @@ export declare class OpenAPIOperationResponseNormalizer {
1609
1619
  normalize(response: Response, request?: OpenAPIOperationRequestInfo): Promise<OpenAPIOperationResponse>;
1610
1620
  }
1611
1621
 
1622
+ /**
1623
+ * Credentials for the security schemes of an OpenAPI document, keyed by the
1624
+ * scheme name under `components.securitySchemes` (`securityDefinitions` in
1625
+ * OpenAPI 2.0).
1626
+ * @public
1627
+ */
1628
+ export declare interface OpenAPIOperationSecurities {
1629
+ readonly authorized: Readonly<Record<string, OpenAPIOperationSecurityCredential>>;
1630
+ }
1631
+
1632
+ /**
1633
+ * The credential for one security scheme, in the form the vendored
1634
+ * swagger-client applies it: the key or token itself (or `{ value }`) for an
1635
+ * `apiKey` or an `http` bearer scheme, `{ username, password }` for an `http`
1636
+ * basic scheme, and `{ token: { access_token, token_type } }` for an `oauth2`
1637
+ * or `openIdConnect` scheme.
1638
+ * @public
1639
+ */
1640
+ export declare type OpenAPIOperationSecurityCredential = string | {
1641
+ readonly value: string;
1642
+ } | {
1643
+ readonly username: string;
1644
+ readonly password: string;
1645
+ } | {
1646
+ readonly token: Readonly<Record<string, string>>;
1647
+ };
1648
+
1612
1649
  /**
1613
1650
  * Union of PathItemElement across all supported OpenAPI versions.
1614
1651
  * @public
@@ -2174,6 +2211,14 @@ export declare abstract class SourceDescriptionsLocatorNormalizer {
2174
2211
  } | undefined;
2175
2212
  }
2176
2213
 
2214
+ /**
2215
+ * The execute options of a step: the opaque bag forwarded to the operation
2216
+ * executor, or a function returning it for the operation the step was located
2217
+ * to.
2218
+ * @public
2219
+ */
2220
+ export declare type StepExecuteOptions = Record<string, unknown> | ((locator: OpenAPIOperationLocator) => Record<string, unknown>);
2221
+
2177
2222
  /**
2178
2223
  * The outcome of executing a single step.
2179
2224
  * @public
@@ -2260,7 +2305,9 @@ export declare class StepExecutor {
2260
2305
  * `executeOptions` is an opaque bag passed through to the operation executor
2261
2306
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
2262
2307
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
2263
- * take precedence over it.
2308
+ * take precedence over it. A function is called with the operation the step
2309
+ * was located to and returns the bag, for options that depend on which API
2310
+ * the step calls.
2264
2311
  *
2265
2312
  * A `signal` in that bag is honored here and not only at the transport: an
2266
2313
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -2272,7 +2319,7 @@ export declare class StepExecutor {
2272
2319
  * here then carries it alongside the `stepId`, since step ids are only
2273
2320
  * unique within a workflow. The workflow executor always passes it.
2274
2321
  */
2275
- execute(step: StepElement, state: ContextSource, executeOptions?: Record<string, unknown>, workflowId?: string): Promise<StepExecutionResult>;
2322
+ execute(step: StepElement, state: ContextSource, executeOptions?: StepExecuteOptions, workflowId?: string): Promise<StepExecutionResult>;
2276
2323
  /**
2277
2324
  * Throws {@link ResolverError} unless the step's `successCriteria` is absent
2278
2325
  * or a list of Criterion Objects: `malformed-criteria` for one that is
@@ -2505,10 +2552,23 @@ export declare interface WorkflowExecuteOptions {
2505
2552
  */
2506
2553
  readonly inputs?: Record<string, unknown>;
2507
2554
  /**
2508
- * The opaque client-specific bag forwarded verbatim to every
2509
- * {@link StepExecutor.execute} (e.g. a `server` to run against).
2555
+ * Execute options addressed to an API: keyed by the `name` of a source
2556
+ * description of the entry document, each entry the opaque client-specific
2557
+ * bag forwarded verbatim to {@link StepExecutor.execute} for the steps that
2558
+ * call an operation of the OpenAPI document that name points at (e.g. a
2559
+ * `server` to run against, or the credentials of its security schemes).
2560
+ *
2561
+ * An entry configures a document, not a name: a step of another Arazzo
2562
+ * document calling the same OpenAPI document gets the entry whatever name it
2563
+ * knows the document by, and one calling a different document under the same
2564
+ * name gets nothing. Steps of an API without an entry get no options.
2565
+ *
2566
+ * A key naming no source description, one naming a source description that
2567
+ * has no `url` or is not an OpenAPI document, two keys pointing at the same
2568
+ * document, and an entry that is not an object all throw before the first
2569
+ * request.
2510
2570
  */
2511
- readonly executeOptions?: Record<string, unknown>;
2571
+ readonly executeOptions?: Record<string, Record<string, unknown>>;
2512
2572
  /**
2513
2573
  * Inputs for the workflows run implicitly to satisfy `dependsOn`, keyed by
2514
2574
  * the `dependsOn` entry as written — the bare workflowId for a
@@ -2551,11 +2611,10 @@ export declare interface WorkflowExecuteOptions {
2551
2611
  * is not something the steps did, and the steps that never ran were not
2552
2612
  * decided against.
2553
2613
  *
2554
- * The signal is also forwarded to the transport (through the same
2555
- * `executeOptions` bag it may be passed in), so the request in flight when the
2556
- * abort lands is cancelled rather than merely awaited. A `signal` passed in
2557
- * that bag instead is observed here too — it cancels the run just as this
2558
- * option does — and this option wins when both are given.
2614
+ * The signal is also forwarded to the transport with every step's execute
2615
+ * options, so the request in flight when the abort lands is cancelled rather
2616
+ * than merely awaited. This option is the only way to cancel a run: a
2617
+ * `signal` in an `executeOptions` entry is dropped.
2559
2618
  */
2560
2619
  readonly signal?: AbortSignal;
2561
2620
  }