@usearazzo/runner 1.0.1-alpha.33 → 1.0.1-alpha.34

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +10 -1
  3. package/dist/arazzo-runner.browser.js +1112 -231
  4. package/dist/arazzo-runner.browser.min.js +1 -1
  5. package/package.json +16 -15
  6. package/src/ArazzoRunner.cjs +26 -3
  7. package/src/ArazzoRunner.mjs +26 -3
  8. package/src/client/OpenAPIOperationResponse.cjs +9 -0
  9. package/src/client/OpenAPIOperationResponse.mjs +9 -0
  10. package/src/document/APIDocument.cjs +53 -0
  11. package/src/document/APIDocument.mjs +53 -0
  12. package/src/executor/OpenAPIOperationExecutor.cjs +66 -6
  13. package/src/executor/OpenAPIOperationExecutor.mjs +66 -6
  14. package/src/executor/StepExecutor.cjs +16 -2
  15. package/src/executor/StepExecutor.mjs +16 -2
  16. package/src/executor/StepRetryRunner.cjs +5 -3
  17. package/src/executor/StepRetryRunner.mjs +5 -3
  18. package/src/executor/StepTransitionInterpreter.cjs +1 -1
  19. package/src/executor/StepTransitionInterpreter.mjs +1 -1
  20. package/src/executor/WorkflowCallStack.cjs +1 -1
  21. package/src/executor/WorkflowCallStack.mjs +1 -1
  22. package/src/executor/WorkflowExecutor.cjs +269 -53
  23. package/src/executor/WorkflowExecutor.mjs +269 -53
  24. package/src/index.cjs +7 -0
  25. package/src/index.mjs +2 -0
  26. package/src/observability/ArazzoRunnerEvent.cjs +5 -0
  27. package/src/observability/ArazzoRunnerEvent.mjs +1 -0
  28. package/src/observability/DocumentRegistryEvent.cjs +5 -0
  29. package/src/observability/DocumentRegistryEvent.mjs +1 -0
  30. package/src/observability/EventChannel.cjs +96 -0
  31. package/src/observability/EventChannel.mjs +91 -0
  32. package/src/observability/OpenAPIOperationEvent.cjs +5 -0
  33. package/src/observability/OpenAPIOperationEvent.mjs +1 -0
  34. package/src/observability/Redactor.cjs +213 -0
  35. package/src/observability/Redactor.mjs +208 -0
  36. package/src/observability/WorkflowExecutionEvent.cjs +5 -0
  37. package/src/observability/WorkflowExecutionEvent.mjs +1 -0
  38. package/src/registry/DocumentRegistry.cjs +22 -3
  39. package/src/registry/DocumentRegistry.mjs +22 -3
  40. package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
  41. package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
  42. package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
  43. package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
  44. package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
  45. package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
  46. package/types/runner.d.ts +705 -5
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _ramdaAdjunct = require("ramda-adjunct");
8
+ /**
9
+ * An event without its `timestamp`, which the channel stamps. Distributes over
10
+ * a union, so each member keeps its own discriminated shape.
11
+ * @internal
12
+ */
13
+
14
+ /**
15
+ * Options for the EventChannel.
16
+ * @internal
17
+ */
18
+
19
+ /**
20
+ * Delivers a building block's events to its observer: stamps each with the
21
+ * block's clock, snapshots it, and hands it over synchronously, without
22
+ * awaiting anything.
23
+ *
24
+ * A block holds a channel only when it was given an observer (see
25
+ * {@link EventChannel.open}), and emits through `this.#events?.emit(...)`: with
26
+ * no channel, optional chaining skips evaluating the event too, so an
27
+ * unobserved run builds no events at all.
28
+ * @internal
29
+ */
30
+ class EventChannel {
31
+ static #DEFAULT_NOW = () => performance.now();
32
+
33
+ /**
34
+ * A channel to `options.observer`, or `undefined` when there is none.
35
+ */
36
+ static open(options) {
37
+ const {
38
+ observer,
39
+ now
40
+ } = options;
41
+ return observer === undefined ? undefined : new EventChannel({
42
+ observer,
43
+ now
44
+ });
45
+ }
46
+
47
+ /**
48
+ * A frozen deep copy of the plain objects and arrays in `value`; anything
49
+ * else, an ApiDOM element above all, is shared as it is. The run keeps
50
+ * using the objects an event describes (the trace's records, the outputs,
51
+ * the context a request interceptor receives, the transition it acts on),
52
+ * so handing out the originals would let an observer change the run.
53
+ */
54
+ static #snapshot(value, copies) {
55
+ if (!Array.isArray(value) && !(0, _ramdaAdjunct.isPlainObject)(value)) return value;
56
+ const seen = copies.get(value);
57
+ if (seen !== undefined) return seen;
58
+ const copy = Array.isArray(value) ? [] : {};
59
+ copies.set(value, copy);
60
+ for (const [key, item] of Object.entries(value)) {
61
+ // defined, not assigned: assigning an own `__proto__` key (JSON.parse
62
+ // makes one) would set the copy's prototype instead of copying it.
63
+ Object.defineProperty(copy, key, {
64
+ value: EventChannel.#snapshot(item, copies),
65
+ enumerable: true,
66
+ writable: true,
67
+ configurable: true
68
+ });
69
+ }
70
+ return Object.freeze(copy);
71
+ }
72
+ #observer;
73
+ #now;
74
+ constructor(options) {
75
+ this.#observer = options.observer;
76
+ this.#now = options.now ?? EventChannel.#DEFAULT_NOW;
77
+ }
78
+
79
+ /**
80
+ * Emits the event. `timestamp` is the clock reading the event describes,
81
+ * when the caller already took one (so a start/settled pair matches a
82
+ * recorded duration exactly); otherwise the clock is read now.
83
+ */
84
+ emit(event, timestamp) {
85
+ // an absent optional field of the event itself is omitted, never present as
86
+ // undefined; undefined values inside its data (an output that resolved to
87
+ // undefined) are kept.
88
+ const fields = Object.entries(event).filter(([, value]) => value !== undefined);
89
+ const stamped = {
90
+ ...Object.fromEntries(fields),
91
+ timestamp: timestamp ?? this.#now()
92
+ };
93
+ this.#observer(EventChannel.#snapshot(stamped, new WeakMap()));
94
+ }
95
+ }
96
+ var _default = exports.default = EventChannel;
@@ -0,0 +1,91 @@
1
+ import { isPlainObject } from 'ramda-adjunct';
2
+
3
+ /**
4
+ * An event without its `timestamp`, which the channel stamps. Distributes over
5
+ * a union, so each member keeps its own discriminated shape.
6
+ * @internal
7
+ */
8
+
9
+ /**
10
+ * Options for the EventChannel.
11
+ * @internal
12
+ */
13
+
14
+ /**
15
+ * Delivers a building block's events to its observer: stamps each with the
16
+ * block's clock, snapshots it, and hands it over synchronously, without
17
+ * awaiting anything.
18
+ *
19
+ * A block holds a channel only when it was given an observer (see
20
+ * {@link EventChannel.open}), and emits through `this.#events?.emit(...)`: with
21
+ * no channel, optional chaining skips evaluating the event too, so an
22
+ * unobserved run builds no events at all.
23
+ * @internal
24
+ */
25
+ class EventChannel {
26
+ static #DEFAULT_NOW = () => performance.now();
27
+
28
+ /**
29
+ * A channel to `options.observer`, or `undefined` when there is none.
30
+ */
31
+ static open(options) {
32
+ const {
33
+ observer,
34
+ now
35
+ } = options;
36
+ return observer === undefined ? undefined : new EventChannel({
37
+ observer,
38
+ now
39
+ });
40
+ }
41
+
42
+ /**
43
+ * A frozen deep copy of the plain objects and arrays in `value`; anything
44
+ * else, an ApiDOM element above all, is shared as it is. The run keeps
45
+ * using the objects an event describes (the trace's records, the outputs,
46
+ * the context a request interceptor receives, the transition it acts on),
47
+ * so handing out the originals would let an observer change the run.
48
+ */
49
+ static #snapshot(value, copies) {
50
+ if (!Array.isArray(value) && !isPlainObject(value)) return value;
51
+ const seen = copies.get(value);
52
+ if (seen !== undefined) return seen;
53
+ const copy = Array.isArray(value) ? [] : {};
54
+ copies.set(value, copy);
55
+ for (const [key, item] of Object.entries(value)) {
56
+ // defined, not assigned: assigning an own `__proto__` key (JSON.parse
57
+ // makes one) would set the copy's prototype instead of copying it.
58
+ Object.defineProperty(copy, key, {
59
+ value: EventChannel.#snapshot(item, copies),
60
+ enumerable: true,
61
+ writable: true,
62
+ configurable: true
63
+ });
64
+ }
65
+ return Object.freeze(copy);
66
+ }
67
+ #observer;
68
+ #now;
69
+ constructor(options) {
70
+ this.#observer = options.observer;
71
+ this.#now = options.now ?? EventChannel.#DEFAULT_NOW;
72
+ }
73
+
74
+ /**
75
+ * Emits the event. `timestamp` is the clock reading the event describes,
76
+ * when the caller already took one (so a start/settled pair matches a
77
+ * recorded duration exactly); otherwise the clock is read now.
78
+ */
79
+ emit(event, timestamp) {
80
+ // an absent optional field of the event itself is omitted, never present as
81
+ // undefined; undefined values inside its data (an output that resolved to
82
+ // undefined) are kept.
83
+ const fields = Object.entries(event).filter(([, value]) => value !== undefined);
84
+ const stamped = {
85
+ ...Object.fromEntries(fields),
86
+ timestamp: timestamp ?? this.#now()
87
+ };
88
+ this.#observer(EventChannel.#snapshot(stamped, new WeakMap()));
89
+ }
90
+ }
91
+ export default EventChannel;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _ramdaAdjunct = require("ramda-adjunct");
8
+ var _apidomDatamodel = require("@speclynx/apidom-datamodel");
9
+ var _arazzoRuntimeExpression = require("@swaggerexpert/arazzo-runtime-expression");
10
+ var _jsonPointer = require("@swaggerexpert/json-pointer");
11
+ var _mediaTypes = require("@swaggerexpert/media-types");
12
+ /**
13
+ * The parts of a parsed runtime expression that name what it reads.
14
+ */
15
+
16
+ /**
17
+ * A parsed media type, lowercased by the parser.
18
+ */
19
+
20
+ /**
21
+ * Options for the Redactor.
22
+ * @public
23
+ */
24
+
25
+ /**
26
+ * Masks credentials in events before they leave the process.
27
+ *
28
+ * Events carry what the run saw, credentials included, like the request a
29
+ * request interceptor receives. Pass every event through
30
+ * {@link Redactor.event} before logging, exporting or writing it.
31
+ *
32
+ * It masks by name, whatever the event:
33
+ *
34
+ * - the value of any field whose name matches a pattern: headers, query
35
+ * parameters, body and output fields, at any depth;
36
+ * - a criterion value whose runtime expression reads a matching name, in its
37
+ * base or in any token of its JSON Pointer (`$inputs.password`,
38
+ * `$steps.login.outputs.token#/value`);
39
+ * - in every absolute URL, as `URL` parses it, the userinfo and the matching
40
+ * query and fragment parameters;
41
+ * - a request or response body that is JSON or a URL-encoded form, field by
42
+ * field, and any other body, or any object that is not plain data, whole.
43
+ *
44
+ * A credential under a name no pattern matches is carried as it is. The
45
+ * masked value is `REDACTED`.
46
+ * @public
47
+ */
48
+ class Redactor {
49
+ static CENSOR = 'REDACTED';
50
+
51
+ /**
52
+ * Elastic APM's `sanitizeFieldNames` defaults, with `*secret*` for its exact
53
+ * `secret` (which misses OAuth's `client_secret`), plus the signed-URL query
54
+ * parameters OpenTelemetry's HTTP conventions mask.
55
+ */
56
+ static defaultFields = Object.freeze(['password', 'passwd', 'pwd', '*secret*', '*key', '*token*', '*session*', '*credit*', '*card*', '*auth*', 'set-cookie', '*principal*', 'pw', 'pass', 'connect.sid', 'cookie', 'AWSAccessKeyId', 'Signature', 'sig', 'X-Goog-Signature']);
57
+ #patterns;
58
+ #matches = new Map();
59
+ constructor(options = {}) {
60
+ this.#patterns = (options.fields ?? Redactor.defaultFields).map(Redactor.#compile);
61
+ }
62
+
63
+ /**
64
+ * A masked copy of the event.
65
+ */
66
+ event(event) {
67
+ return this.#walk(event, new WeakSet());
68
+ }
69
+ #walk(value, seen) {
70
+ if (typeof value === 'string') return URL.canParse(value) ? this.#url(value) : value;
71
+ if (typeof value !== 'object' || value === null) return value;
72
+ // an ApiDOM element (a selected action) is the document's own, and a date
73
+ // holds no credential; any other object that is not plain data cannot be
74
+ // walked field by field.
75
+ if ((0, _apidomDatamodel.isElement)(value) || value instanceof Date) return value;
76
+ if (!Array.isArray(value) && !(0, _ramdaAdjunct.isPlainObject)(value)) return Redactor.CENSOR;
77
+ // only the objects on the current path: a shared, acyclic one is walked
78
+ // again where it reappears, a cycle is cut.
79
+ if (seen.has(value)) return Redactor.CENSOR;
80
+ seen.add(value);
81
+ try {
82
+ return Array.isArray(value) ? value.map(item => this.#walk(item, seen)) : this.#fields(value, seen);
83
+ } finally {
84
+ seen.delete(value);
85
+ }
86
+ }
87
+ #fields(object, seen) {
88
+ const redacted = {};
89
+ for (const [name, item] of Object.entries(object)) {
90
+ let masked;
91
+ if (this.#masks(name)) masked = Redactor.CENSOR;else if (name === 'body' && (0, _ramdaAdjunct.isPlainObject)(object.headers)) {
92
+ masked = this.#body(item, object.headers, seen);
93
+ } else masked = this.#walk(item, seen);
94
+ // defined, not assigned, so an own `__proto__` key stays data
95
+ Object.defineProperty(redacted, name, {
96
+ value: masked,
97
+ enumerable: true,
98
+ writable: true,
99
+ configurable: true
100
+ });
101
+ }
102
+ return redacted;
103
+ }
104
+
105
+ /**
106
+ * Whether a name matches a pattern. A runtime expression matches when any
107
+ * name it reads does.
108
+ */
109
+ #masks(name) {
110
+ let matches = this.#matches.get(name);
111
+ if (matches === undefined) {
112
+ const names = name.startsWith('$') ? Redactor.#namesRead(name) : [name];
113
+ matches = names.some(candidate => this.#patterns.some(pattern => pattern.test(candidate)));
114
+ this.#matches.set(name, matches);
115
+ }
116
+ return matches;
117
+ }
118
+
119
+ /**
120
+ * The absolute URL with its userinfo and matching query and fragment
121
+ * parameters masked. A URL with nothing to mask comes back exactly as it
122
+ * was, not normalized.
123
+ */
124
+ #url(value) {
125
+ const url = new URL(value);
126
+ let masked = false;
127
+ if (url.username !== '' || url.password !== '') {
128
+ url.username = Redactor.CENSOR;
129
+ url.password = Redactor.CENSOR;
130
+ masked = true;
131
+ }
132
+ const query = this.#params(url.search.slice(1));
133
+ if (query !== undefined) {
134
+ url.search = query;
135
+ masked = true;
136
+ }
137
+ const fragment = this.#params(url.hash.slice(1));
138
+ if (fragment !== undefined) {
139
+ url.hash = fragment;
140
+ masked = true;
141
+ }
142
+ return masked ? url.href : value;
143
+ }
144
+
145
+ /**
146
+ * A body masked by what its `Content-Type` says it is.
147
+ */
148
+ #body(body, headers, seen) {
149
+ if (typeof body !== 'string' || body === '') return this.#walk(body, seen);
150
+ const mediaType = Redactor.#contentType(headers);
151
+ if (mediaType?.subtype === 'json' || mediaType?.suffix === 'json') {
152
+ try {
153
+ return JSON.stringify(this.#walk(JSON.parse(body), seen));
154
+ } catch {
155
+ return Redactor.CENSOR;
156
+ }
157
+ }
158
+ if (mediaType?.type === 'application' && mediaType.subtype === 'x-www-form-urlencoded') {
159
+ return this.#params(body) ?? body;
160
+ }
161
+ return Redactor.CENSOR;
162
+ }
163
+
164
+ /**
165
+ * URL-encoded `name=value` pairs with matching values masked, or
166
+ * `undefined` when none matches, so the caller keeps the text as it was.
167
+ */
168
+ #params(text) {
169
+ let masked = false;
170
+ const params = [...new URLSearchParams(text)].map(([name, value]) => {
171
+ if (!this.#masks(name)) return [name, value];
172
+ masked = true;
173
+ return [name, Redactor.CENSOR];
174
+ });
175
+ return masked ? new URLSearchParams(params).toString() : undefined;
176
+ }
177
+ static #contentType(headers) {
178
+ const name = Object.keys(headers).find(key => key.toLowerCase() === 'content-type');
179
+ if (name === undefined) return undefined;
180
+ try {
181
+ return (0, _mediaTypes.parse)(headers[name], {
182
+ type: 'media-type'
183
+ }).tree;
184
+ } catch {
185
+ return undefined;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Every name a runtime expression reads: the header, query, path, input,
191
+ * output or component name, and each token of its JSON Pointer, e.g.
192
+ * `token` and `value` for `$steps.login.outputs.token#/value`. A string
193
+ * that does not parse as an expression is its own name.
194
+ */
195
+ static #namesRead(expression) {
196
+ let tree;
197
+ try {
198
+ tree = (0, _arazzoRuntimeExpression.parse)(expression).tree;
199
+ } catch {
200
+ return [expression];
201
+ }
202
+ if (tree === undefined) return [expression];
203
+ const reference = tree.source?.reference;
204
+ const tokens = (tree.jsonPointer ?? reference?.jsonPointer)?.referenceTokens ?? [];
205
+ const names = [reference?.token, reference?.name, tree.name, tree.outputName, tree.fieldName, tree.componentName, ...tokens.map(token => (0, _jsonPointer.unescape)(token.value))];
206
+ return names.filter(name => name !== undefined);
207
+ }
208
+ static #compile(pattern) {
209
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
210
+ return new RegExp(`^${escaped}$`, 'i');
211
+ }
212
+ }
213
+ var _default = exports.default = Redactor;
@@ -0,0 +1,208 @@
1
+ import { isPlainObject } from 'ramda-adjunct';
2
+ import { isElement } from '@speclynx/apidom-datamodel';
3
+ import { parse as parseExpression } from '@swaggerexpert/arazzo-runtime-expression';
4
+ import { unescape as unescapeToken } from '@swaggerexpert/json-pointer';
5
+ import { parse as parseMediaType } from '@swaggerexpert/media-types';
6
+
7
+ /**
8
+ * The parts of a parsed runtime expression that name what it reads.
9
+ */
10
+
11
+ /**
12
+ * A parsed media type, lowercased by the parser.
13
+ */
14
+
15
+ /**
16
+ * Options for the Redactor.
17
+ * @public
18
+ */
19
+
20
+ /**
21
+ * Masks credentials in events before they leave the process.
22
+ *
23
+ * Events carry what the run saw, credentials included, like the request a
24
+ * request interceptor receives. Pass every event through
25
+ * {@link Redactor.event} before logging, exporting or writing it.
26
+ *
27
+ * It masks by name, whatever the event:
28
+ *
29
+ * - the value of any field whose name matches a pattern: headers, query
30
+ * parameters, body and output fields, at any depth;
31
+ * - a criterion value whose runtime expression reads a matching name, in its
32
+ * base or in any token of its JSON Pointer (`$inputs.password`,
33
+ * `$steps.login.outputs.token#/value`);
34
+ * - in every absolute URL, as `URL` parses it, the userinfo and the matching
35
+ * query and fragment parameters;
36
+ * - a request or response body that is JSON or a URL-encoded form, field by
37
+ * field, and any other body, or any object that is not plain data, whole.
38
+ *
39
+ * A credential under a name no pattern matches is carried as it is. The
40
+ * masked value is `REDACTED`.
41
+ * @public
42
+ */
43
+ class Redactor {
44
+ static CENSOR = 'REDACTED';
45
+
46
+ /**
47
+ * Elastic APM's `sanitizeFieldNames` defaults, with `*secret*` for its exact
48
+ * `secret` (which misses OAuth's `client_secret`), plus the signed-URL query
49
+ * parameters OpenTelemetry's HTTP conventions mask.
50
+ */
51
+ static defaultFields = Object.freeze(['password', 'passwd', 'pwd', '*secret*', '*key', '*token*', '*session*', '*credit*', '*card*', '*auth*', 'set-cookie', '*principal*', 'pw', 'pass', 'connect.sid', 'cookie', 'AWSAccessKeyId', 'Signature', 'sig', 'X-Goog-Signature']);
52
+ #patterns;
53
+ #matches = new Map();
54
+ constructor(options = {}) {
55
+ this.#patterns = (options.fields ?? Redactor.defaultFields).map(Redactor.#compile);
56
+ }
57
+
58
+ /**
59
+ * A masked copy of the event.
60
+ */
61
+ event(event) {
62
+ return this.#walk(event, new WeakSet());
63
+ }
64
+ #walk(value, seen) {
65
+ if (typeof value === 'string') return URL.canParse(value) ? this.#url(value) : value;
66
+ if (typeof value !== 'object' || value === null) return value;
67
+ // an ApiDOM element (a selected action) is the document's own, and a date
68
+ // holds no credential; any other object that is not plain data cannot be
69
+ // walked field by field.
70
+ if (isElement(value) || value instanceof Date) return value;
71
+ if (!Array.isArray(value) && !isPlainObject(value)) return Redactor.CENSOR;
72
+ // only the objects on the current path: a shared, acyclic one is walked
73
+ // again where it reappears, a cycle is cut.
74
+ if (seen.has(value)) return Redactor.CENSOR;
75
+ seen.add(value);
76
+ try {
77
+ return Array.isArray(value) ? value.map(item => this.#walk(item, seen)) : this.#fields(value, seen);
78
+ } finally {
79
+ seen.delete(value);
80
+ }
81
+ }
82
+ #fields(object, seen) {
83
+ const redacted = {};
84
+ for (const [name, item] of Object.entries(object)) {
85
+ let masked;
86
+ if (this.#masks(name)) masked = Redactor.CENSOR;else if (name === 'body' && isPlainObject(object.headers)) {
87
+ masked = this.#body(item, object.headers, seen);
88
+ } else masked = this.#walk(item, seen);
89
+ // defined, not assigned, so an own `__proto__` key stays data
90
+ Object.defineProperty(redacted, name, {
91
+ value: masked,
92
+ enumerable: true,
93
+ writable: true,
94
+ configurable: true
95
+ });
96
+ }
97
+ return redacted;
98
+ }
99
+
100
+ /**
101
+ * Whether a name matches a pattern. A runtime expression matches when any
102
+ * name it reads does.
103
+ */
104
+ #masks(name) {
105
+ let matches = this.#matches.get(name);
106
+ if (matches === undefined) {
107
+ const names = name.startsWith('$') ? Redactor.#namesRead(name) : [name];
108
+ matches = names.some(candidate => this.#patterns.some(pattern => pattern.test(candidate)));
109
+ this.#matches.set(name, matches);
110
+ }
111
+ return matches;
112
+ }
113
+
114
+ /**
115
+ * The absolute URL with its userinfo and matching query and fragment
116
+ * parameters masked. A URL with nothing to mask comes back exactly as it
117
+ * was, not normalized.
118
+ */
119
+ #url(value) {
120
+ const url = new URL(value);
121
+ let masked = false;
122
+ if (url.username !== '' || url.password !== '') {
123
+ url.username = Redactor.CENSOR;
124
+ url.password = Redactor.CENSOR;
125
+ masked = true;
126
+ }
127
+ const query = this.#params(url.search.slice(1));
128
+ if (query !== undefined) {
129
+ url.search = query;
130
+ masked = true;
131
+ }
132
+ const fragment = this.#params(url.hash.slice(1));
133
+ if (fragment !== undefined) {
134
+ url.hash = fragment;
135
+ masked = true;
136
+ }
137
+ return masked ? url.href : value;
138
+ }
139
+
140
+ /**
141
+ * A body masked by what its `Content-Type` says it is.
142
+ */
143
+ #body(body, headers, seen) {
144
+ if (typeof body !== 'string' || body === '') return this.#walk(body, seen);
145
+ const mediaType = Redactor.#contentType(headers);
146
+ if (mediaType?.subtype === 'json' || mediaType?.suffix === 'json') {
147
+ try {
148
+ return JSON.stringify(this.#walk(JSON.parse(body), seen));
149
+ } catch {
150
+ return Redactor.CENSOR;
151
+ }
152
+ }
153
+ if (mediaType?.type === 'application' && mediaType.subtype === 'x-www-form-urlencoded') {
154
+ return this.#params(body) ?? body;
155
+ }
156
+ return Redactor.CENSOR;
157
+ }
158
+
159
+ /**
160
+ * URL-encoded `name=value` pairs with matching values masked, or
161
+ * `undefined` when none matches, so the caller keeps the text as it was.
162
+ */
163
+ #params(text) {
164
+ let masked = false;
165
+ const params = [...new URLSearchParams(text)].map(([name, value]) => {
166
+ if (!this.#masks(name)) return [name, value];
167
+ masked = true;
168
+ return [name, Redactor.CENSOR];
169
+ });
170
+ return masked ? new URLSearchParams(params).toString() : undefined;
171
+ }
172
+ static #contentType(headers) {
173
+ const name = Object.keys(headers).find(key => key.toLowerCase() === 'content-type');
174
+ if (name === undefined) return undefined;
175
+ try {
176
+ return parseMediaType(headers[name], {
177
+ type: 'media-type'
178
+ }).tree;
179
+ } catch {
180
+ return undefined;
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Every name a runtime expression reads: the header, query, path, input,
186
+ * output or component name, and each token of its JSON Pointer, e.g.
187
+ * `token` and `value` for `$steps.login.outputs.token#/value`. A string
188
+ * that does not parse as an expression is its own name.
189
+ */
190
+ static #namesRead(expression) {
191
+ let tree;
192
+ try {
193
+ tree = parseExpression(expression).tree;
194
+ } catch {
195
+ return [expression];
196
+ }
197
+ if (tree === undefined) return [expression];
198
+ const reference = tree.source?.reference;
199
+ const tokens = (tree.jsonPointer ?? reference?.jsonPointer)?.referenceTokens ?? [];
200
+ const names = [reference?.token, reference?.name, tree.name, tree.outputName, tree.fieldName, tree.componentName, ...tokens.map(token => unescapeToken(token.value))];
201
+ return names.filter(name => name !== undefined);
202
+ }
203
+ static #compile(pattern) {
204
+ const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
205
+ return new RegExp(`^${escaped}$`, 'i');
206
+ }
207
+ }
208
+ export default Redactor;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -15,6 +15,7 @@ var _DocumentLoadError = _interopRequireDefault(require("../errors/DocumentLoadE
15
15
  var _InvalidEntryDocumentError = _interopRequireDefault(require("../errors/InvalidEntryDocumentError.cjs"));
16
16
  var _UnmatchedProviderError = _interopRequireDefault(require("../errors/UnmatchedProviderError.cjs"));
17
17
  var constants = _interopRequireWildcard(require("../constants.cjs"));
18
+ var _EventChannel = _interopRequireDefault(require("../observability/EventChannel.cjs"));
18
19
  /**
19
20
  * Options for the DocumentRegistry.
20
21
  * @public
@@ -32,8 +33,13 @@ class DocumentRegistry {
32
33
  #documents = new Map();
33
34
  #loading = new Map();
34
35
  #providers;
36
+ #events;
35
37
  constructor(options = {}) {
36
38
  this.#providers = options.providers ?? [new _ArazzoDocumentRegistryProvider.default(), new _OpenAPIDocumentRegistryProvider.default()];
39
+ this.#events = _EventChannel.default.open({
40
+ observer: options.observer,
41
+ now: options.now
42
+ });
37
43
  }
38
44
 
39
45
  /**
@@ -79,12 +85,15 @@ class DocumentRegistry {
79
85
  * caches it.
80
86
  */
81
87
  async #load(canonicalURI) {
88
+ this.#events?.emit({
89
+ type: 'document-load-start',
90
+ uri: canonicalURI
91
+ });
82
92
  for (const provider of this.#providers) {
93
+ let document;
83
94
  try {
84
95
  if (await provider.canProvide(canonicalURI)) {
85
- const document = await provider.provide(canonicalURI);
86
- this.#set(canonicalURI, document);
87
- return document;
96
+ document = await provider.provide(canonicalURI);
88
97
  }
89
98
  } catch (error) {
90
99
  // a document that cannot be read or loaded fails in ApiDOM or the parser;
@@ -95,6 +104,16 @@ class DocumentRegistry {
95
104
  cause: error
96
105
  });
97
106
  }
107
+ if (document !== undefined) {
108
+ // outside the try, so an observer's own error is not a failed load, and
109
+ // before caching, so a run it aborts leaves no half-registered document.
110
+ this.#events?.emit({
111
+ type: 'document-load-settled',
112
+ uri: canonicalURI
113
+ });
114
+ this.#set(canonicalURI, document);
115
+ return document;
116
+ }
98
117
  }
99
118
  throw new _UnmatchedProviderError.default(`No provider can handle the document at "${canonicalURI}"`, {
100
119
  uri: canonicalURI