@usearazzo/runner 1.0.1-alpha.33 → 1.0.1-alpha.35
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/CHANGELOG.md +22 -0
- package/README.md +15 -1
- package/dist/arazzo-runner.browser.js +1516 -265
- package/dist/arazzo-runner.browser.min.js +1 -1
- package/package.json +64 -18
- package/src/ArazzoRunner.cjs +26 -3
- package/src/ArazzoRunner.mjs +26 -3
- package/src/client/OpenAPIOperationResponse.cjs +9 -0
- package/src/client/OpenAPIOperationResponse.mjs +9 -0
- package/src/document/APIDocument.cjs +53 -0
- package/src/document/APIDocument.mjs +53 -0
- package/src/errors/ExecutionError.cjs +2 -0
- package/src/errors/ExecutionError.mjs +2 -0
- package/src/executor/OpenAPIOperationExecutor.cjs +77 -6
- package/src/executor/OpenAPIOperationExecutor.mjs +77 -6
- package/src/executor/StepExecutor.cjs +16 -2
- package/src/executor/StepExecutor.mjs +16 -2
- package/src/executor/StepRetryRunner.cjs +5 -3
- package/src/executor/StepRetryRunner.mjs +5 -3
- package/src/executor/StepTransitionInterpreter.cjs +1 -1
- package/src/executor/StepTransitionInterpreter.mjs +1 -1
- package/src/executor/WorkflowCallStack.cjs +1 -1
- package/src/executor/WorkflowCallStack.mjs +1 -1
- package/src/executor/WorkflowExecutor.cjs +447 -89
- package/src/executor/WorkflowExecutor.mjs +447 -89
- package/src/index.cjs +21 -0
- package/src/index.mjs +4 -0
- package/src/observability/ArazzoRunnerEvent.cjs +5 -0
- package/src/observability/ArazzoRunnerEvent.mjs +1 -0
- package/src/observability/DocumentRegistryEvent.cjs +5 -0
- package/src/observability/DocumentRegistryEvent.mjs +1 -0
- package/src/observability/EventChannel.cjs +106 -0
- package/src/observability/EventChannel.mjs +98 -0
- package/src/observability/OpenAPIOperationEvent.cjs +5 -0
- package/src/observability/OpenAPIOperationEvent.mjs +1 -0
- package/src/observability/Redactor.cjs +215 -0
- package/src/observability/Redactor.mjs +210 -0
- package/src/observability/WorkflowExecutionEvent.cjs +5 -0
- package/src/observability/WorkflowExecutionEvent.mjs +1 -0
- package/src/observability/combineObservers.cjs +18 -0
- package/src/observability/combineObservers.mjs +12 -0
- package/src/observability/instrument.cjs +159 -0
- package/src/observability/instrument.mjs +144 -0
- package/src/observability/logging/LoggingObserver.cjs +177 -0
- package/src/observability/logging/LoggingObserver.mjs +172 -0
- package/src/observability/logging/index.cjs +13 -0
- package/src/observability/logging/index.mjs +1 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.cjs +321 -0
- package/src/observability/opentelemetry/ArazzoRunnerInstrumentation.mjs +313 -0
- package/src/observability/opentelemetry/index.cjs +13 -0
- package/src/observability/opentelemetry/index.mjs +1 -0
- package/src/observability/stream/EventStream.cjs +112 -0
- package/src/observability/stream/EventStream.mjs +107 -0
- package/src/observability/stream/index.cjs +13 -0
- package/src/observability/stream/index.mjs +1 -0
- package/src/registry/DocumentRegistry.cjs +27 -3
- package/src/registry/DocumentRegistry.mjs +27 -3
- package/src/registry/providers/ArazzoDocumentRegistryProvider.cjs +20 -0
- package/src/registry/providers/ArazzoDocumentRegistryProvider.mjs +21 -1
- package/src/registry/providers/DocumentRegistryProvider.cjs +14 -0
- package/src/registry/providers/DocumentRegistryProvider.mjs +14 -0
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.cjs +27 -5
- package/src/registry/providers/OpenAPIDocumentRegistryProvider.mjs +27 -5
- package/src/version.cjs +9 -0
- package/src/version.mjs +3 -0
- package/types/observability/logging/LoggingObserver.d.ts +82 -0
- package/types/observability/logging/index.d.ts +2 -0
- package/types/observability/opentelemetry/ArazzoRunnerInstrumentation.d.ts +84 -0
- package/types/observability/opentelemetry/index.d.ts +2 -0
- package/types/observability/stream/EventStream.d.ts +68 -0
- package/types/observability/stream/index.d.ts +2 -0
- package/types/runner.d.ts +802 -5
package/src/index.cjs
CHANGED
|
@@ -281,6 +281,12 @@ Object.defineProperty(exports, "OutputResolver", {
|
|
|
281
281
|
return _OutputResolver.default;
|
|
282
282
|
}
|
|
283
283
|
});
|
|
284
|
+
Object.defineProperty(exports, "Redactor", {
|
|
285
|
+
enumerable: true,
|
|
286
|
+
get: function () {
|
|
287
|
+
return _Redactor.default;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
284
290
|
Object.defineProperty(exports, "RegexCriterionEvaluator", {
|
|
285
291
|
enumerable: true,
|
|
286
292
|
get: function () {
|
|
@@ -365,12 +371,24 @@ Object.defineProperty(exports, "XPathCriterionEvaluator", {
|
|
|
365
371
|
return _XPathCriterionEvaluator.default;
|
|
366
372
|
}
|
|
367
373
|
});
|
|
374
|
+
Object.defineProperty(exports, "combineObservers", {
|
|
375
|
+
enumerable: true,
|
|
376
|
+
get: function () {
|
|
377
|
+
return _combineObservers.default;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
368
380
|
Object.defineProperty(exports, "httpClientFetch", {
|
|
369
381
|
enumerable: true,
|
|
370
382
|
get: function () {
|
|
371
383
|
return _HTTPClientFetch.default;
|
|
372
384
|
}
|
|
373
385
|
});
|
|
386
|
+
Object.defineProperty(exports, "instrument", {
|
|
387
|
+
enumerable: true,
|
|
388
|
+
get: function () {
|
|
389
|
+
return _instrument.default;
|
|
390
|
+
}
|
|
391
|
+
});
|
|
374
392
|
Object.defineProperty(exports, "settledResult", {
|
|
375
393
|
enumerable: true,
|
|
376
394
|
get: function () {
|
|
@@ -425,6 +443,9 @@ var _OpenAPIOperationExecutor = _interopRequireDefault(require("./executor/OpenA
|
|
|
425
443
|
var _SourceDescriptionsLocatorNormalizer = _interopRequireDefault(require("./executor/SourceDescriptionsLocatorNormalizer.cjs"));
|
|
426
444
|
var _OpenAPIOperationLocatorNormalizer = _interopRequireDefault(require("./executor/OpenAPIOperationLocatorNormalizer.cjs"));
|
|
427
445
|
var _ArazzoWorkflowLocatorNormalizer = _interopRequireDefault(require("./executor/ArazzoWorkflowLocatorNormalizer.cjs"));
|
|
446
|
+
var _combineObservers = _interopRequireDefault(require("./observability/combineObservers.cjs"));
|
|
447
|
+
var _instrument = _interopRequireDefault(require("./observability/instrument.cjs"));
|
|
448
|
+
var _Redactor = _interopRequireDefault(require("./observability/Redactor.cjs"));
|
|
428
449
|
var _ArazzoRunnerError = _interopRequireDefault(require("./errors/ArazzoRunnerError.cjs"));
|
|
429
450
|
var _AssemblerError = _interopRequireDefault(require("./errors/AssemblerError.cjs"));
|
|
430
451
|
var _ClientError = _interopRequireDefault(require("./errors/ClientError.cjs"));
|
package/src/index.mjs
CHANGED
|
@@ -61,6 +61,10 @@ export { default as OpenAPIOperationExecutor } from "./executor/OpenAPIOperation
|
|
|
61
61
|
export { default as SourceDescriptionsLocatorNormalizer } from "./executor/SourceDescriptionsLocatorNormalizer.mjs";
|
|
62
62
|
export { default as OpenAPIOperationLocatorNormalizer } from "./executor/OpenAPIOperationLocatorNormalizer.mjs";
|
|
63
63
|
export { default as ArazzoWorkflowLocatorNormalizer } from "./executor/ArazzoWorkflowLocatorNormalizer.mjs";
|
|
64
|
+
/* Observability */
|
|
65
|
+
export { default as combineObservers } from "./observability/combineObservers.mjs";
|
|
66
|
+
export { default as instrument } from "./observability/instrument.mjs";
|
|
67
|
+
export { default as Redactor } from "./observability/Redactor.mjs";
|
|
64
68
|
/* Errors */
|
|
65
69
|
export { default as ArazzoRunnerError } from "./errors/ArazzoRunnerError.mjs";
|
|
66
70
|
export { default as AssemblerError } from "./errors/AssemblerError.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
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 _instrument = require("./instrument.cjs");
|
|
9
|
+
/**
|
|
10
|
+
* An event without its `timestamp`, which the channel stamps. Distributes over
|
|
11
|
+
* a union, so each member keeps its own discriminated shape.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for the EventChannel.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Delivers a building block's events to its observer, then to the
|
|
22
|
+
* process-wide observers {@link instrument} registered: stamps each with the
|
|
23
|
+
* block's clock, snapshots it, and hands it over synchronously, without
|
|
24
|
+
* awaiting anything.
|
|
25
|
+
*
|
|
26
|
+
* A block emits only while {@link EventChannel.hasObservers}:
|
|
27
|
+
* `if (this.#events.hasObservers) this.#events.emit({...})`, so an unobserved
|
|
28
|
+
* run builds no events at all, like `diagnostics_channel`'s `hasSubscribers`.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
class EventChannel {
|
|
32
|
+
static #DEFAULT_NOW = () => performance.now();
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A frozen deep copy of the plain objects and arrays in `value`; anything
|
|
36
|
+
* else, an ApiDOM element above all, is shared as it is. The run keeps
|
|
37
|
+
* using the objects an event describes (the trace's records, the outputs,
|
|
38
|
+
* the context a request interceptor receives, the transition it acts on),
|
|
39
|
+
* so handing out the originals would let an observer change the run.
|
|
40
|
+
*/
|
|
41
|
+
static #snapshot(value, copies) {
|
|
42
|
+
if (!Array.isArray(value) && !(0, _ramdaAdjunct.isPlainObject)(value)) return value;
|
|
43
|
+
const seen = copies.get(value);
|
|
44
|
+
if (seen !== undefined) return seen;
|
|
45
|
+
const copy = Array.isArray(value) ? [] : {};
|
|
46
|
+
copies.set(value, copy);
|
|
47
|
+
for (const [key, item] of Object.entries(value)) {
|
|
48
|
+
// defined, not assigned: assigning an own `__proto__` key (JSON.parse
|
|
49
|
+
// makes one) would set the copy's prototype instead of copying it.
|
|
50
|
+
Object.defineProperty(copy, key, {
|
|
51
|
+
value: EventChannel.#snapshot(item, copies),
|
|
52
|
+
enumerable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
configurable: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return Object.freeze(copy);
|
|
58
|
+
}
|
|
59
|
+
#observer;
|
|
60
|
+
#now;
|
|
61
|
+
constructor(options) {
|
|
62
|
+
this.#observer = options.observer;
|
|
63
|
+
this.#now = options.now ?? EventChannel.#DEFAULT_NOW;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether anyone observes the channel: its own observer or a process-wide
|
|
68
|
+
* one. Read per event, so hooks registered mid-run apply from the next
|
|
69
|
+
* event on.
|
|
70
|
+
*/
|
|
71
|
+
get hasObservers() {
|
|
72
|
+
return this.#observer !== undefined || (0, _instrument.isInstrumented)();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Emits the event. `timestamp` is the clock reading the event describes,
|
|
77
|
+
* when the caller already took one (so a start/settled pair matches a
|
|
78
|
+
* recorded duration exactly); otherwise the clock is read now.
|
|
79
|
+
*/
|
|
80
|
+
emit(event, timestamp) {
|
|
81
|
+
// an absent optional field of the event itself is omitted, never present as
|
|
82
|
+
// undefined; undefined values inside its data (an output that resolved to
|
|
83
|
+
// undefined) are kept.
|
|
84
|
+
const fields = Object.entries(event).filter(([, value]) => value !== undefined);
|
|
85
|
+
const stamped = {
|
|
86
|
+
...Object.fromEntries(fields),
|
|
87
|
+
timestamp: timestamp ?? this.#now()
|
|
88
|
+
};
|
|
89
|
+
const snapshot = EventChannel.#snapshot(stamped, new WeakMap());
|
|
90
|
+
// process-wide observers see the event even when the block's own throws,
|
|
91
|
+
// so a buggy observer cannot leave a trace incomplete; the block's own
|
|
92
|
+
// error is the one that aborts what emitted the event
|
|
93
|
+
try {
|
|
94
|
+
this.#observer?.(snapshot);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
try {
|
|
97
|
+
(0, _instrument.notify)(snapshot);
|
|
98
|
+
} catch {
|
|
99
|
+
// the block's own observer failed first
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
(0, _instrument.notify)(snapshot);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
var _default = exports.default = EventChannel;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isPlainObject } from 'ramda-adjunct';
|
|
2
|
+
import { isInstrumented, notify } from "./instrument.mjs";
|
|
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
|
+
* Options for the EventChannel.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Delivers a building block's events to its observer, then to the
|
|
14
|
+
* process-wide observers {@link instrument} registered: stamps each with the
|
|
15
|
+
* block's clock, snapshots it, and hands it over synchronously, without
|
|
16
|
+
* awaiting anything.
|
|
17
|
+
*
|
|
18
|
+
* A block emits only while {@link EventChannel.hasObservers}:
|
|
19
|
+
* `if (this.#events.hasObservers) this.#events.emit({...})`, so an unobserved
|
|
20
|
+
* run builds no events at all, like `diagnostics_channel`'s `hasSubscribers`.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
class EventChannel {
|
|
24
|
+
static #DEFAULT_NOW = () => performance.now();
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A frozen deep copy of the plain objects and arrays in `value`; anything
|
|
28
|
+
* else, an ApiDOM element above all, is shared as it is. The run keeps
|
|
29
|
+
* using the objects an event describes (the trace's records, the outputs,
|
|
30
|
+
* the context a request interceptor receives, the transition it acts on),
|
|
31
|
+
* so handing out the originals would let an observer change the run.
|
|
32
|
+
*/
|
|
33
|
+
static #snapshot(value, copies) {
|
|
34
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return value;
|
|
35
|
+
const seen = copies.get(value);
|
|
36
|
+
if (seen !== undefined) return seen;
|
|
37
|
+
const copy = Array.isArray(value) ? [] : {};
|
|
38
|
+
copies.set(value, copy);
|
|
39
|
+
for (const [key, item] of Object.entries(value)) {
|
|
40
|
+
// defined, not assigned: assigning an own `__proto__` key (JSON.parse
|
|
41
|
+
// makes one) would set the copy's prototype instead of copying it.
|
|
42
|
+
Object.defineProperty(copy, key, {
|
|
43
|
+
value: EventChannel.#snapshot(item, copies),
|
|
44
|
+
enumerable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return Object.freeze(copy);
|
|
50
|
+
}
|
|
51
|
+
#observer;
|
|
52
|
+
#now;
|
|
53
|
+
constructor(options) {
|
|
54
|
+
this.#observer = options.observer;
|
|
55
|
+
this.#now = options.now ?? EventChannel.#DEFAULT_NOW;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Whether anyone observes the channel: its own observer or a process-wide
|
|
60
|
+
* one. Read per event, so hooks registered mid-run apply from the next
|
|
61
|
+
* event on.
|
|
62
|
+
*/
|
|
63
|
+
get hasObservers() {
|
|
64
|
+
return this.#observer !== undefined || isInstrumented();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Emits the event. `timestamp` is the clock reading the event describes,
|
|
69
|
+
* when the caller already took one (so a start/settled pair matches a
|
|
70
|
+
* recorded duration exactly); otherwise the clock is read now.
|
|
71
|
+
*/
|
|
72
|
+
emit(event, timestamp) {
|
|
73
|
+
// an absent optional field of the event itself is omitted, never present as
|
|
74
|
+
// undefined; undefined values inside its data (an output that resolved to
|
|
75
|
+
// undefined) are kept.
|
|
76
|
+
const fields = Object.entries(event).filter(([, value]) => value !== undefined);
|
|
77
|
+
const stamped = {
|
|
78
|
+
...Object.fromEntries(fields),
|
|
79
|
+
timestamp: timestamp ?? this.#now()
|
|
80
|
+
};
|
|
81
|
+
const snapshot = EventChannel.#snapshot(stamped, new WeakMap());
|
|
82
|
+
// process-wide observers see the event even when the block's own throws,
|
|
83
|
+
// so a buggy observer cannot leave a trace incomplete; the block's own
|
|
84
|
+
// error is the one that aborts what emitted the event
|
|
85
|
+
try {
|
|
86
|
+
this.#observer?.(snapshot);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
try {
|
|
89
|
+
notify(snapshot);
|
|
90
|
+
} catch {
|
|
91
|
+
// the block's own observer failed first
|
|
92
|
+
}
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
notify(snapshot);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export default EventChannel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,215 @@
|
|
|
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 settled event's `error` is carried as it is, the error `execute` rejects
|
|
45
|
+
* with. A credential under a name no pattern matches is carried as it is. The
|
|
46
|
+
* masked value is `REDACTED`.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
class Redactor {
|
|
50
|
+
static CENSOR = 'REDACTED';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Elastic APM's `sanitizeFieldNames` defaults, with `*secret*` for its exact
|
|
54
|
+
* `secret` (which misses OAuth's `client_secret`), plus the signed-URL query
|
|
55
|
+
* parameters OpenTelemetry's HTTP conventions mask.
|
|
56
|
+
*/
|
|
57
|
+
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']);
|
|
58
|
+
#patterns;
|
|
59
|
+
#matches = new Map();
|
|
60
|
+
constructor(options = {}) {
|
|
61
|
+
this.#patterns = (options.fields ?? Redactor.defaultFields).map(Redactor.#compile);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A masked copy of the event.
|
|
66
|
+
*/
|
|
67
|
+
event(event) {
|
|
68
|
+
return this.#walk(event, new WeakSet());
|
|
69
|
+
}
|
|
70
|
+
#walk(value, seen) {
|
|
71
|
+
if (typeof value === 'string') return URL.canParse(value) ? this.#url(value) : value;
|
|
72
|
+
if (typeof value !== 'object' || value === null) return value;
|
|
73
|
+
// an ApiDOM element (a selected action) is the document's own, a date
|
|
74
|
+
// holds no credential, and an error is the one `execute` rejects with,
|
|
75
|
+
// unmasked; any other object that is not plain data cannot be walked
|
|
76
|
+
// field by field.
|
|
77
|
+
if ((0, _apidomDatamodel.isElement)(value) || value instanceof Date || value instanceof Error) return value;
|
|
78
|
+
if (!Array.isArray(value) && !(0, _ramdaAdjunct.isPlainObject)(value)) return Redactor.CENSOR;
|
|
79
|
+
// only the objects on the current path: a shared, acyclic one is walked
|
|
80
|
+
// again where it reappears, a cycle is cut.
|
|
81
|
+
if (seen.has(value)) return Redactor.CENSOR;
|
|
82
|
+
seen.add(value);
|
|
83
|
+
try {
|
|
84
|
+
return Array.isArray(value) ? value.map(item => this.#walk(item, seen)) : this.#fields(value, seen);
|
|
85
|
+
} finally {
|
|
86
|
+
seen.delete(value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
#fields(object, seen) {
|
|
90
|
+
const redacted = {};
|
|
91
|
+
for (const [name, item] of Object.entries(object)) {
|
|
92
|
+
let masked;
|
|
93
|
+
if (this.#masks(name)) masked = Redactor.CENSOR;else if (name === 'body' && (0, _ramdaAdjunct.isPlainObject)(object.headers)) {
|
|
94
|
+
masked = this.#body(item, object.headers, seen);
|
|
95
|
+
} else masked = this.#walk(item, seen);
|
|
96
|
+
// defined, not assigned, so an own `__proto__` key stays data
|
|
97
|
+
Object.defineProperty(redacted, name, {
|
|
98
|
+
value: masked,
|
|
99
|
+
enumerable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return redacted;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether a name matches a pattern. A runtime expression matches when any
|
|
109
|
+
* name it reads does.
|
|
110
|
+
*/
|
|
111
|
+
#masks(name) {
|
|
112
|
+
let matches = this.#matches.get(name);
|
|
113
|
+
if (matches === undefined) {
|
|
114
|
+
const names = name.startsWith('$') ? Redactor.#namesRead(name) : [name];
|
|
115
|
+
matches = names.some(candidate => this.#patterns.some(pattern => pattern.test(candidate)));
|
|
116
|
+
this.#matches.set(name, matches);
|
|
117
|
+
}
|
|
118
|
+
return matches;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The absolute URL with its userinfo and matching query and fragment
|
|
123
|
+
* parameters masked. A URL with nothing to mask comes back exactly as it
|
|
124
|
+
* was, not normalized.
|
|
125
|
+
*/
|
|
126
|
+
#url(value) {
|
|
127
|
+
const url = new URL(value);
|
|
128
|
+
let masked = false;
|
|
129
|
+
if (url.username !== '' || url.password !== '') {
|
|
130
|
+
url.username = Redactor.CENSOR;
|
|
131
|
+
url.password = Redactor.CENSOR;
|
|
132
|
+
masked = true;
|
|
133
|
+
}
|
|
134
|
+
const query = this.#params(url.search.slice(1));
|
|
135
|
+
if (query !== undefined) {
|
|
136
|
+
url.search = query;
|
|
137
|
+
masked = true;
|
|
138
|
+
}
|
|
139
|
+
const fragment = this.#params(url.hash.slice(1));
|
|
140
|
+
if (fragment !== undefined) {
|
|
141
|
+
url.hash = fragment;
|
|
142
|
+
masked = true;
|
|
143
|
+
}
|
|
144
|
+
return masked ? url.href : value;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A body masked by what its `Content-Type` says it is.
|
|
149
|
+
*/
|
|
150
|
+
#body(body, headers, seen) {
|
|
151
|
+
if (typeof body !== 'string' || body === '') return this.#walk(body, seen);
|
|
152
|
+
const mediaType = Redactor.#contentType(headers);
|
|
153
|
+
if (mediaType?.subtype === 'json' || mediaType?.suffix === 'json') {
|
|
154
|
+
try {
|
|
155
|
+
return JSON.stringify(this.#walk(JSON.parse(body), seen));
|
|
156
|
+
} catch {
|
|
157
|
+
return Redactor.CENSOR;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (mediaType?.type === 'application' && mediaType.subtype === 'x-www-form-urlencoded') {
|
|
161
|
+
return this.#params(body) ?? body;
|
|
162
|
+
}
|
|
163
|
+
return Redactor.CENSOR;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* URL-encoded `name=value` pairs with matching values masked, or
|
|
168
|
+
* `undefined` when none matches, so the caller keeps the text as it was.
|
|
169
|
+
*/
|
|
170
|
+
#params(text) {
|
|
171
|
+
let masked = false;
|
|
172
|
+
const params = [...new URLSearchParams(text)].map(([name, value]) => {
|
|
173
|
+
if (!this.#masks(name)) return [name, value];
|
|
174
|
+
masked = true;
|
|
175
|
+
return [name, Redactor.CENSOR];
|
|
176
|
+
});
|
|
177
|
+
return masked ? new URLSearchParams(params).toString() : undefined;
|
|
178
|
+
}
|
|
179
|
+
static #contentType(headers) {
|
|
180
|
+
const name = Object.keys(headers).find(key => key.toLowerCase() === 'content-type');
|
|
181
|
+
if (name === undefined) return undefined;
|
|
182
|
+
try {
|
|
183
|
+
return (0, _mediaTypes.parse)(headers[name], {
|
|
184
|
+
type: 'media-type'
|
|
185
|
+
}).tree;
|
|
186
|
+
} catch {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Every name a runtime expression reads: the header, query, path, input,
|
|
193
|
+
* output or component name, and each token of its JSON Pointer, e.g.
|
|
194
|
+
* `token` and `value` for `$steps.login.outputs.token#/value`. A string
|
|
195
|
+
* that does not parse as an expression is its own name.
|
|
196
|
+
*/
|
|
197
|
+
static #namesRead(expression) {
|
|
198
|
+
let tree;
|
|
199
|
+
try {
|
|
200
|
+
tree = (0, _arazzoRuntimeExpression.parse)(expression).tree;
|
|
201
|
+
} catch {
|
|
202
|
+
return [expression];
|
|
203
|
+
}
|
|
204
|
+
if (tree === undefined) return [expression];
|
|
205
|
+
const reference = tree.source?.reference;
|
|
206
|
+
const tokens = (tree.jsonPointer ?? reference?.jsonPointer)?.referenceTokens ?? [];
|
|
207
|
+
const names = [reference?.token, reference?.name, tree.name, tree.outputName, tree.fieldName, tree.componentName, ...tokens.map(token => (0, _jsonPointer.unescape)(token.value))];
|
|
208
|
+
return names.filter(name => name !== undefined);
|
|
209
|
+
}
|
|
210
|
+
static #compile(pattern) {
|
|
211
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
|
|
212
|
+
return new RegExp(`^${escaped}$`, 'i');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
var _default = exports.default = Redactor;
|