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

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.29",
3
+ "version": "1.0.1-alpha.31",
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.29",
77
- "@usearazzo/resolver": "1.0.1-alpha.29",
76
+ "@usearazzo/parser": "1.0.1-alpha.31",
77
+ "@usearazzo/resolver": "1.0.1-alpha.31",
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": "113b0d571325f56bb364e7fc9a492e7e6d08dfee"
97
+ "gitHead": "ff411e3bd2734c6f6c6d9b9cbe83e9b65dfe53f0"
98
98
  }
@@ -17,7 +17,7 @@ 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. */
20
+ /** A step without an `executeOptions` entry of its own reaches a document that several entries configure. */
21
21
  static AmbiguousExecuteOptions = 'ambiguous-execute-options';
22
22
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
23
23
  static AmbiguousTarget = 'ambiguous-target';
@@ -10,7 +10,7 @@ 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. */
13
+ /** A step without an `executeOptions` entry of its own reaches a document that several entries configure. */
14
14
  static AmbiguousExecuteOptions = 'ambiguous-execute-options';
15
15
  /** A step or a `goto`/`retry` action declares more than one mutually exclusive target. */
16
16
  static AmbiguousTarget = 'ambiguous-target';
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _ramda = require("ramda");
8
9
  var _apidomCore = require("@speclynx/apidom-core");
9
10
  var _apidomDatamodel = require("@speclynx/apidom-datamodel");
10
11
  var _empty = require("@speclynx/apidom-reference/configuration/empty");
@@ -22,12 +23,42 @@ var _OpenAPIDocumentAssembler = _interopRequireDefault(require("../assembler/Ope
22
23
  var _ClientError = _interopRequireDefault(require("../errors/ClientError.cjs"));
23
24
  // @ts-expect-error vendored swagger-client bundle has no type declarations
24
25
 
26
+ /**
27
+ * The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
28
+ * of the workflow it belongs to when the caller names one (step ids are only
29
+ * unique within a workflow).
30
+ * @public
31
+ */
32
+
33
+ /**
34
+ * Identifies the request a {@link RequestInterceptor} receives, so an
35
+ * interceptor can target one operation or one step without matching on the
36
+ * expanded URL.
37
+ *
38
+ * `operation` is always present: it is the operation's locator — its canonical
39
+ * OpenAPI document URI, the JSON Pointer to it and, when the locator carries
40
+ * one, the source description it was located through — plus the `operationId`
41
+ * the document declares, if any. `step` is present only when the request is
42
+ * issued for an Arazzo step, i.e. through the step executor (and so the runner); an
43
+ * {@link OpenAPIOperationExecutor} used on its own receives it only when its
44
+ * caller passes `step` in the execute options. Absent fields are omitted, never
45
+ * `undefined`.
46
+ * @public
47
+ */
48
+
25
49
  /**
26
50
  * Decorates the built request before it is handed to the {@link HTTPClient}.
27
51
  *
28
52
  * Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
29
53
  * place or return a replacement; returning nothing keeps the received request.
30
- * May be synchronous or asynchronous.
54
+ * May be synchronous or asynchronous. The second argument identifies what the
55
+ * request is for (see {@link RequestContext}); an interceptor that has no use
56
+ * for it may declare only the first.
57
+ *
58
+ * Interceptors run after the body is serialized (a plain-object or array body
59
+ * is already a JSON string, so a signature covers the exact bytes sent) and
60
+ * after newlines in header values are squashed, and before the request is
61
+ * captured for `$request.*` and handed to the transport.
31
62
  * @public
32
63
  */
33
64
 
@@ -95,12 +126,12 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
95
126
  * needed a `contextUrl`, so reaching for that here means an edge case: tests
96
127
  * standing in for a document fetched over HTTP.
97
128
  *
98
- * Two kinds of entry are inert rather than honored, since the executor owns
129
+ * Two kinds of entry are dropped rather than honored, since the executor owns
99
130
  * what they used to control. The operation target always comes from the
100
131
  * locator, so `operationId`/`operationPath` have no effect; and the options
101
132
  * only swagger-client's `execute()` ever read — `userFetch` and
102
133
  * `responseInterceptor`, which the runner replaces with `httpClient` and
103
- * `responseNormalizer` — reach `buildRequest` but nothing acts on them.
134
+ * `responseNormalizer` — never reach `buildRequest`.
104
135
  * @public
105
136
  */
106
137
 
@@ -168,14 +199,36 @@ class OpenAPIOperationExecutor {
168
199
  const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
169
200
  const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
170
201
 
171
- // the interceptor is consumed here, and the target always comes from the
172
- // locator, so both operation keys are dropped rather than rest
202
+ // the interceptor and step are consumed here, the target always comes from
203
+ // the locator, and the transport is the httpClient, so none of these
204
+ // reach buildRequest
173
205
  const {
174
206
  requestInterceptor,
175
- operationId: _,
176
- operationPath: __,
177
- ...rest
207
+ step
178
208
  } = executeOptions;
209
+ const rest = (0, _ramda.omit)(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
210
+ const declaredOperationId = (0, _apidomCore.toValue)(operation.operationId);
211
+ const context = {
212
+ operation: {
213
+ documentURI: locator.document.uri,
214
+ jsonPointer: locator.jsonPointer,
215
+ ...(typeof declaredOperationId === 'string' ? {
216
+ operationId: declaredOperationId
217
+ } : {}),
218
+ ...(locator.sourceDescription === undefined ? {} : {
219
+ sourceDescription: {
220
+ ...locator.sourceDescription
221
+ }
222
+ })
223
+ },
224
+ // a copy, so an interceptor editing it cannot rewrite the caller's object
225
+ // (the step executor reuses it to attribute errors)
226
+ ...(step === undefined ? {} : {
227
+ step: {
228
+ ...step
229
+ }
230
+ })
231
+ };
179
232
 
180
233
  // each step derives the next options rather than editing in place
181
234
  const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
@@ -206,7 +259,7 @@ class OpenAPIOperationExecutor {
206
259
  request.headers['Content-Type'] = authoredContentType;
207
260
  }
208
261
  this.#deliverHeadersAndCookies(request, undeclared);
209
- request = await this.#finalizeRequest(request, requestInterceptor);
262
+ request = await this.#finalizeRequest(request, requestInterceptor, context);
210
263
 
211
264
  // capture the request as sent, so `$url` / `$method` / `$request.*` can be
212
265
  // evaluated after execution; headers are copied so a transport-side
@@ -583,7 +636,7 @@ class OpenAPIOperationExecutor {
583
636
  * `http()`, which also fetch and throw on a non-2xx. Diff against those two
584
637
  * when bumping swagger-client.
585
638
  */
586
- async #finalizeRequest(request, perCallInterceptor) {
639
+ async #finalizeRequest(request, perCallInterceptor, context) {
587
640
  let finalized = request;
588
641
 
589
642
  // JSON-encode plain-object and array bodies, exactly as swagger-client's
@@ -602,8 +655,8 @@ class OpenAPIOperationExecutor {
602
655
  finalized.headers[headerName] = value.replace(/\n+/g, ' ');
603
656
  }
604
657
  });
605
- finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
606
- finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
658
+ finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
659
+ finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
607
660
 
608
661
  // for multipart/form-data, remove the built content-type so the transport
609
662
  // sets one carrying the correct boundary
@@ -1,3 +1,4 @@
1
+ import { omit } from 'ramda';
1
2
  import { toValue } from '@speclynx/apidom-core';
2
3
  import { isArrayElement, isObjectElement } from '@speclynx/apidom-datamodel';
3
4
  import { url as urlUtils } from '@speclynx/apidom-reference/configuration/empty';
@@ -15,12 +16,40 @@ import OpenAPIOperationExtractor from "../extractor/OpenAPIOperationExtractor.mj
15
16
  import OpenAPIOperationNormalizer from "../normalizer/OpenAPIOperationNormalizer.mjs";
16
17
  import OpenAPIDocumentAssembler from "../assembler/OpenAPIDocumentAssembler.mjs";
17
18
  import ClientError from "../errors/ClientError.mjs";
19
+ /**
20
+ * The Arazzo step a request is issued for: its `stepId`, and the `workflowId`
21
+ * of the workflow it belongs to when the caller names one (step ids are only
22
+ * unique within a workflow).
23
+ * @public
24
+ */
25
+ /**
26
+ * Identifies the request a {@link RequestInterceptor} receives, so an
27
+ * interceptor can target one operation or one step without matching on the
28
+ * expanded URL.
29
+ *
30
+ * `operation` is always present: it is the operation's locator — its canonical
31
+ * OpenAPI document URI, the JSON Pointer to it and, when the locator carries
32
+ * one, the source description it was located through — plus the `operationId`
33
+ * the document declares, if any. `step` is present only when the request is
34
+ * issued for an Arazzo step, i.e. through the step executor (and so the runner); an
35
+ * {@link OpenAPIOperationExecutor} used on its own receives it only when its
36
+ * caller passes `step` in the execute options. Absent fields are omitted, never
37
+ * `undefined`.
38
+ * @public
39
+ */
18
40
  /**
19
41
  * Decorates the built request before it is handed to the {@link HTTPClient}.
20
42
  *
21
43
  * Receives the finalized {@link OpenAPIOperationRequest} and may mutate it in
22
44
  * place or return a replacement; returning nothing keeps the received request.
23
- * May be synchronous or asynchronous.
45
+ * May be synchronous or asynchronous. The second argument identifies what the
46
+ * request is for (see {@link RequestContext}); an interceptor that has no use
47
+ * for it may declare only the first.
48
+ *
49
+ * Interceptors run after the body is serialized (a plain-object or array body
50
+ * is already a JSON string, so a signature covers the exact bytes sent) and
51
+ * after newlines in header values are squashed, and before the request is
52
+ * captured for `$request.*` and handed to the transport.
24
53
  * @public
25
54
  */
26
55
  /**
@@ -85,12 +114,12 @@ const IGNORED_HEADERS = new Set(['accept', 'authorization', 'content-type']);
85
114
  * needed a `contextUrl`, so reaching for that here means an edge case: tests
86
115
  * standing in for a document fetched over HTTP.
87
116
  *
88
- * Two kinds of entry are inert rather than honored, since the executor owns
117
+ * Two kinds of entry are dropped rather than honored, since the executor owns
89
118
  * what they used to control. The operation target always comes from the
90
119
  * locator, so `operationId`/`operationPath` have no effect; and the options
91
120
  * only swagger-client's `execute()` ever read — `userFetch` and
92
121
  * `responseInterceptor`, which the runner replaces with `httpClient` and
93
- * `responseNormalizer` — reach `buildRequest` but nothing acts on them.
122
+ * `responseNormalizer` — never reach `buildRequest`.
94
123
  * @public
95
124
  */
96
125
 
@@ -158,14 +187,36 @@ class OpenAPIOperationExecutor {
158
187
  const normalizedOperation = await this.#operationNormalizer.normalize(operation, locator.document);
159
188
  const assembled = this.#documentAssembler.assemble(normalizedOperation, locator.document);
160
189
 
161
- // the interceptor is consumed here, and the target always comes from the
162
- // locator, so both operation keys are dropped rather than rest
190
+ // the interceptor and step are consumed here, the target always comes from
191
+ // the locator, and the transport is the httpClient, so none of these
192
+ // reach buildRequest
163
193
  const {
164
194
  requestInterceptor,
165
- operationId: _,
166
- operationPath: __,
167
- ...rest
195
+ step
168
196
  } = executeOptions;
197
+ const rest = omit(['requestInterceptor', 'step', 'operationId', 'operationPath', 'userFetch', 'responseInterceptor'], executeOptions);
198
+ const declaredOperationId = toValue(operation.operationId);
199
+ const context = {
200
+ operation: {
201
+ documentURI: locator.document.uri,
202
+ jsonPointer: locator.jsonPointer,
203
+ ...(typeof declaredOperationId === 'string' ? {
204
+ operationId: declaredOperationId
205
+ } : {}),
206
+ ...(locator.sourceDescription === undefined ? {} : {
207
+ sourceDescription: {
208
+ ...locator.sourceDescription
209
+ }
210
+ })
211
+ },
212
+ // a copy, so an interceptor editing it cannot rewrite the caller's object
213
+ // (the step executor reuses it to attribute errors)
214
+ ...(step === undefined ? {} : {
215
+ step: {
216
+ ...step
217
+ }
218
+ })
219
+ };
169
220
 
170
221
  // each step derives the next options rather than editing in place
171
222
  const withServer = this.#applyServerOptions(rest, normalizedOperation, locator.document);
@@ -196,7 +247,7 @@ class OpenAPIOperationExecutor {
196
247
  request.headers['Content-Type'] = authoredContentType;
197
248
  }
198
249
  this.#deliverHeadersAndCookies(request, undeclared);
199
- request = await this.#finalizeRequest(request, requestInterceptor);
250
+ request = await this.#finalizeRequest(request, requestInterceptor, context);
200
251
 
201
252
  // capture the request as sent, so `$url` / `$method` / `$request.*` can be
202
253
  // evaluated after execution; headers are copied so a transport-side
@@ -573,7 +624,7 @@ class OpenAPIOperationExecutor {
573
624
  * `http()`, which also fetch and throw on a non-2xx. Diff against those two
574
625
  * when bumping swagger-client.
575
626
  */
576
- async #finalizeRequest(request, perCallInterceptor) {
627
+ async #finalizeRequest(request, perCallInterceptor, context) {
577
628
  let finalized = request;
578
629
 
579
630
  // JSON-encode plain-object and array bodies, exactly as swagger-client's
@@ -592,8 +643,8 @@ class OpenAPIOperationExecutor {
592
643
  finalized.headers[headerName] = value.replace(/\n+/g, ' ');
593
644
  }
594
645
  });
595
- finalized = (await this.#requestInterceptor?.(finalized)) ?? finalized;
596
- finalized = (await perCallInterceptor?.(finalized)) ?? finalized;
646
+ finalized = (await this.#requestInterceptor?.(finalized, context)) ?? finalized;
647
+ finalized = (await perCallInterceptor?.(finalized, context)) ?? finalized;
597
648
 
598
649
  // for multipart/form-data, remove the built content-type so the transport
599
650
  // sets one carrying the correct boundary
@@ -25,6 +25,13 @@ var _SourceDescriptionsLocatorNormalizer = _interopRequireDefault(require("./Sou
25
25
  * @public
26
26
  */
27
27
 
28
+ /**
29
+ * A source description as an Arazzo document declares it: its `name`, and the
30
+ * URI of the Arazzo document that declares it. Names are local to their
31
+ * document, so the pair identifies one source description across a run.
32
+ * @public
33
+ */
34
+
28
35
  /**
29
36
  * Normalizes a step's OpenAPI operation locator to a canonical
30
37
  * {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
@@ -89,8 +96,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
89
96
  * locate an operation in the acquired OpenAPI document.
90
97
  */
91
98
  async normalizeOperationPath(operationPath, document, scope) {
99
+ let sourceName;
92
100
  for (const expression of (0, _arazzoRuntimeExpression.extract)(operationPath) ?? []) {
93
101
  const parsed = this.parseSourceDescriptionsExpression(expression);
102
+ // only the source whose url the path is built from names its document
103
+ if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
94
104
  if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
95
105
  throw new _ExecutionError.default(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
96
106
  ...scope,
@@ -139,7 +149,13 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
139
149
  }
140
150
  return {
141
151
  document: source,
142
- jsonPointer
152
+ jsonPointer,
153
+ ...(sourceName === undefined ? {} : {
154
+ sourceDescription: {
155
+ name: sourceName,
156
+ documentURI: document.uri
157
+ }
158
+ })
143
159
  };
144
160
  }
145
161
  async #resolveSourced(expression, document, scope) {
@@ -164,7 +180,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
164
180
  }
165
181
  return {
166
182
  document: openapiDocument,
167
- jsonPointer
183
+ jsonPointer,
184
+ sourceDescription: {
185
+ name: sourceName,
186
+ documentURI: document.uri
187
+ }
168
188
  };
169
189
  }
170
190
 
@@ -181,7 +201,10 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
181
201
  * until the first OpenAPI source is reached.
182
202
  */
183
203
  async #resolvePlainOperationId(operationId, document, scope) {
184
- for (const uri of document.sourceDescriptionURIs()) {
204
+ for (const [name, {
205
+ uri
206
+ }] of document.sourceDescriptionIndex) {
207
+ if (uri === undefined) continue;
185
208
  const source = await this.registry.acquire(uri);
186
209
  if (!_OpenAPIDocument.default.is(source)) continue;
187
210
  const jsonPointer = source.operationIndex.get(operationId);
@@ -193,7 +216,11 @@ class OpenAPIOperationLocatorNormalizer extends _SourceDescriptionsLocatorNormal
193
216
  }
194
217
  return {
195
218
  document: source,
196
- jsonPointer
219
+ jsonPointer,
220
+ sourceDescription: {
221
+ name,
222
+ documentURI: document.uri
223
+ }
197
224
  };
198
225
  }
199
226
 
@@ -17,6 +17,12 @@ import SourceDescriptionsLocatorNormalizer from "./SourceDescriptionsLocatorNorm
17
17
  * single canonical form.
18
18
  * @public
19
19
  */
20
+ /**
21
+ * A source description as an Arazzo document declares it: its `name`, and the
22
+ * URI of the Arazzo document that declares it. Names are local to their
23
+ * document, so the pair identifies one source description across a run.
24
+ * @public
25
+ */
20
26
  /**
21
27
  * Normalizes a step's OpenAPI operation locator to a canonical
22
28
  * {@link OpenAPIOperationLocator} — the OpenAPI document and a JSON Pointer to
@@ -81,8 +87,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
81
87
  * locate an operation in the acquired OpenAPI document.
82
88
  */
83
89
  async normalizeOperationPath(operationPath, document, scope) {
90
+ let sourceName;
84
91
  for (const expression of extract(operationPath) ?? []) {
85
92
  const parsed = this.parseSourceDescriptionsExpression(expression);
93
+ // only the source whose url the path is built from names its document
94
+ if (parsed?.reference === 'url') sourceName ??= parsed.sourceName;
86
95
  if (parsed !== undefined && document.resolveSourceDescriptionURI(parsed.sourceName) === undefined) {
87
96
  throw new ExecutionError(`operationPath "${operationPath}" names source description "${parsed.sourceName}", which the Arazzo document at "${document.uri}" does not define`, {
88
97
  ...scope,
@@ -131,7 +140,13 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
131
140
  }
132
141
  return {
133
142
  document: source,
134
- jsonPointer
143
+ jsonPointer,
144
+ ...(sourceName === undefined ? {} : {
145
+ sourceDescription: {
146
+ name: sourceName,
147
+ documentURI: document.uri
148
+ }
149
+ })
135
150
  };
136
151
  }
137
152
  async #resolveSourced(expression, document, scope) {
@@ -156,7 +171,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
156
171
  }
157
172
  return {
158
173
  document: openapiDocument,
159
- jsonPointer
174
+ jsonPointer,
175
+ sourceDescription: {
176
+ name: sourceName,
177
+ documentURI: document.uri
178
+ }
160
179
  };
161
180
  }
162
181
 
@@ -173,7 +192,10 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
173
192
  * until the first OpenAPI source is reached.
174
193
  */
175
194
  async #resolvePlainOperationId(operationId, document, scope) {
176
- for (const uri of document.sourceDescriptionURIs()) {
195
+ for (const [name, {
196
+ uri
197
+ }] of document.sourceDescriptionIndex) {
198
+ if (uri === undefined) continue;
177
199
  const source = await this.registry.acquire(uri);
178
200
  if (!OpenAPIDocument.is(source)) continue;
179
201
  const jsonPointer = source.operationIndex.get(operationId);
@@ -185,7 +207,11 @@ class OpenAPIOperationLocatorNormalizer extends SourceDescriptionsLocatorNormali
185
207
  }
186
208
  return {
187
209
  document: source,
188
- jsonPointer
210
+ jsonPointer,
211
+ sourceDescription: {
212
+ name,
213
+ documentURI: document.uri
214
+ }
189
215
  };
190
216
  }
191
217
 
@@ -68,7 +68,7 @@ const STEP_TARGET_FIELDS = exports.STEP_TARGET_FIELDS = ['operationId', 'operati
68
68
  /**
69
69
  * The execute options of a step: the opaque bag forwarded to the operation
70
70
  * executor, or a function returning it for the operation the step was located
71
- * to.
71
+ * to, called with the step it is located for.
72
72
  * @public
73
73
  */
74
74
 
@@ -135,8 +135,8 @@ class StepExecutor {
135
135
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
136
136
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
137
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.
138
+ * was located to and the step's `stepId` / `workflowId`, and returns the bag,
139
+ * for options that depend on which API the step calls.
140
140
  *
141
141
  * A `signal` in that bag is honored here and not only at the transport: an
142
142
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -178,7 +178,11 @@ class StepExecutor {
178
178
  // Pointer) locator that the operation executor extracts, normalizes,
179
179
  // assembles into a standalone doc, and runs.
180
180
  const locator = await this.#locateOperation(step, scope);
181
- const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
181
+ const operationOptions =
182
+ // a copy, so the function cannot rewrite the scope this step attributes its errors to
183
+ typeof executeOptions === 'function' ? executeOptions(locator, {
184
+ ...scope
185
+ }) : executeOptions;
182
186
 
183
187
  // resolve parameters and request body against the pre-request context.
184
188
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -195,15 +199,17 @@ class StepExecutor {
195
199
  const signal = (0, _abort.readAbortSignal)(operationOptions);
196
200
  (0, _abort.throwIfAborted)(signal, scope);
197
201
 
198
- // the Arazzo-derived parameters and request body are spread after the opaque
199
- // executeOptions bag so they take precedence over it. the operation executor
200
- // then forces the operation target on top of this before executing.
202
+ // the Arazzo-derived parameters, request body and step identity are spread
203
+ // after the opaque executeOptions bag so they take precedence over it. the
204
+ // operation executor then forces the operation target on top of this
205
+ // before executing.
201
206
  let response;
202
207
  try {
203
208
  response = await this.#operationExecutor.execute(locator, {
204
209
  ...operationOptions,
205
210
  parameters,
206
- ...this.#requestBodyOptions(requestBody)
211
+ ...this.#requestBodyOptions(requestBody),
212
+ step: scope
207
213
  });
208
214
  } catch (error) {
209
215
  // a transport that honors the signal rejects the request it was told to
@@ -61,7 +61,7 @@ export const STEP_TARGET_FIELDS = ['operationId', 'operationPath', 'workflowId']
61
61
  /**
62
62
  * The execute options of a step: the opaque bag forwarded to the operation
63
63
  * executor, or a function returning it for the operation the step was located
64
- * to.
64
+ * to, called with the step it is located for.
65
65
  * @public
66
66
  */
67
67
 
@@ -128,8 +128,8 @@ class StepExecutor {
128
128
  * (e.g. a `server` to run the step against, or an `AbortSignal`). The
129
129
  * Arazzo-derived options (`operationId`, `parameters`, `requestBody`) always
130
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.
131
+ * was located to and the step's `stepId` / `workflowId`, and returns the bag,
132
+ * for options that depend on which API the step calls.
133
133
  *
134
134
  * A `signal` in that bag is honored here and not only at the transport: an
135
135
  * already-aborted signal throws with reason `ExecutionError.Aborted` instead of issuing a
@@ -171,7 +171,11 @@ class StepExecutor {
171
171
  // Pointer) locator that the operation executor extracts, normalizes,
172
172
  // assembles into a standalone doc, and runs.
173
173
  const locator = await this.#locateOperation(step, scope);
174
- const operationOptions = typeof executeOptions === 'function' ? executeOptions(locator) : executeOptions;
174
+ const operationOptions =
175
+ // a copy, so the function cannot rewrite the scope this step attributes its errors to
176
+ typeof executeOptions === 'function' ? executeOptions(locator, {
177
+ ...scope
178
+ }) : executeOptions;
175
179
 
176
180
  // resolve parameters and request body against the pre-request context.
177
181
  // keyed by '{in}.{name}' rather than bare name, so two parameters that
@@ -188,15 +192,17 @@ class StepExecutor {
188
192
  const signal = readAbortSignal(operationOptions);
189
193
  throwIfAborted(signal, scope);
190
194
 
191
- // the Arazzo-derived parameters and request body are spread after the opaque
192
- // executeOptions bag so they take precedence over it. the operation executor
193
- // then forces the operation target on top of this before executing.
195
+ // the Arazzo-derived parameters, request body and step identity are spread
196
+ // after the opaque executeOptions bag so they take precedence over it. the
197
+ // operation executor then forces the operation target on top of this
198
+ // before executing.
194
199
  let response;
195
200
  try {
196
201
  response = await this.#operationExecutor.execute(locator, {
197
202
  ...operationOptions,
198
203
  parameters,
199
- ...this.#requestBodyOptions(requestBody)
204
+ ...this.#requestBodyOptions(requestBody),
205
+ step: scope
200
206
  });
201
207
  } catch (error) {
202
208
  // a transport that honors the signal rejects the request it was told to