@composed-di/core 0.5.1-alpha → 0.5.2-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/redactingEventListener.d.ts +57 -0
- package/dist/redactingEventListener.d.ts.map +1 -0
- package/dist/redactingEventListener.js +89 -0
- package/dist/redactingEventListener.js.map +1 -0
- package/dist/serviceModule.d.ts +2 -2
- package/dist/serviceModule.d.ts.map +1 -1
- package/dist/serviceModule.js.map +1 -1
- package/dist/serviceModuleListener.d.ts +133 -0
- package/dist/serviceModuleListener.d.ts.map +1 -0
- package/dist/serviceModuleListener.js +3 -0
- package/dist/serviceModuleListener.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/redactingEventListener.ts +132 -0
- package/src/serviceModule.ts +5 -5
- package/src/{serviceEventListener.ts → serviceModuleListener.ts} +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export * from './serviceModule';
|
|
|
3
3
|
export * from './serviceFactory';
|
|
4
4
|
export * from './serviceScope';
|
|
5
5
|
export * from './serviceSelector';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './serviceModuleListener';
|
|
7
|
+
export * from './redactingEventListener';
|
|
7
8
|
export * from './errors';
|
|
8
9
|
export * from './utils';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,8 @@ __exportStar(require("./serviceModule"), exports);
|
|
|
19
19
|
__exportStar(require("./serviceFactory"), exports);
|
|
20
20
|
__exportStar(require("./serviceScope"), exports);
|
|
21
21
|
__exportStar(require("./serviceSelector"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./serviceModuleListener"), exports);
|
|
23
|
+
__exportStar(require("./redactingEventListener"), exports);
|
|
23
24
|
__exportStar(require("./errors"), exports);
|
|
24
25
|
__exportStar(require("./utils"), exports);
|
|
25
26
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,mDAAiC;AACjC,iDAA+B;AAC/B,oDAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,kDAAgC;AAChC,mDAAiC;AACjC,iDAA+B;AAC/B,oDAAkC;AAClC,0DAAwC;AACxC,2DAAyC;AACzC,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DisposeContext, EventSpan, InitializeContext, MethodCallContext, ServiceModuleListener } from './serviceModuleListener';
|
|
2
|
+
import type { ServiceKey } from './serviceKey';
|
|
3
|
+
/**
|
|
4
|
+
* The placeholder that replaces redacted values in event contexts and
|
|
5
|
+
* outcomes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const REDACTED_VALUE = "[redacted]";
|
|
8
|
+
/**
|
|
9
|
+
* Marks a service — or specific properties of it — as sensitive, so the
|
|
10
|
+
* values flowing through its events are replaced with {@link REDACTED_VALUE}.
|
|
11
|
+
*/
|
|
12
|
+
export interface RedactionRule<T> {
|
|
13
|
+
/**
|
|
14
|
+
* The service key whose values must be redacted. Matched by key
|
|
15
|
+
* identity, like everywhere else in the container.
|
|
16
|
+
*/
|
|
17
|
+
key: ServiceKey<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Property names to redact. Optional: when omitted, ALL properties of
|
|
20
|
+
* the service are redacted, along with its initialize result (the
|
|
21
|
+
* service instance itself may carry credentials or config).
|
|
22
|
+
*/
|
|
23
|
+
properties?: Extract<keyof T, string>[];
|
|
24
|
+
}
|
|
25
|
+
export declare function redactionRule<T>(key: ServiceKey<T>, properties?: Extract<keyof T, string>[]): RedactionRule<T>;
|
|
26
|
+
/**
|
|
27
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
28
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
29
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
30
|
+
* EventOutcome are replaced with {@link REDACTED_VALUE}, so the delegate
|
|
31
|
+
* never sees the sensitive data — whatever it captures or exports is
|
|
32
|
+
* already scrubbed.
|
|
33
|
+
*
|
|
34
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
35
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const listener = new RedactingEventListener(
|
|
40
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
41
|
+
* [
|
|
42
|
+
* { key: SecretClientKey }, // whole service is sensitive
|
|
43
|
+
* { key: VaultKey, properties: ['getSecret'] }, // only these calls
|
|
44
|
+
* ],
|
|
45
|
+
* );
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class RedactingEventListener implements ServiceModuleListener {
|
|
49
|
+
private readonly delegate;
|
|
50
|
+
private readonly rules;
|
|
51
|
+
constructor(delegate: ServiceModuleListener, rules: readonly RedactionRule<any>[]);
|
|
52
|
+
onInitialize(context: InitializeContext): EventSpan | void;
|
|
53
|
+
onDispose(context: DisposeContext): EventSpan | void;
|
|
54
|
+
onMethodCall(context: MethodCallContext): EventSpan | void;
|
|
55
|
+
private isRedacted;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=redactingEventListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactingEventListener.d.ts","sourceRoot":"","sources":["../src/redactingEventListener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,SAAS,EACT,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B;;;OAGG;IACH,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IAEnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;CACzC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAE9G;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAEhE,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;gBADL,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,SAAS,aAAa,CAAC,GAAG,CAAC,EAAE;IAGvD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI;IAU1D,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI;IAKpD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI;IAc1D,OAAO,CAAC,UAAU;CAYnB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RedactingEventListener = exports.REDACTED_VALUE = void 0;
|
|
4
|
+
exports.redactionRule = redactionRule;
|
|
5
|
+
/**
|
|
6
|
+
* The placeholder that replaces redacted values in event contexts and
|
|
7
|
+
* outcomes.
|
|
8
|
+
*/
|
|
9
|
+
exports.REDACTED_VALUE = '[redacted]';
|
|
10
|
+
function redactionRule(key, properties) {
|
|
11
|
+
return { key, properties };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
15
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
16
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
17
|
+
* EventOutcome are replaced with {@link REDACTED_VALUE}, so the delegate
|
|
18
|
+
* never sees the sensitive data — whatever it captures or exports is
|
|
19
|
+
* already scrubbed.
|
|
20
|
+
*
|
|
21
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
22
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const listener = new RedactingEventListener(
|
|
27
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
28
|
+
* [
|
|
29
|
+
* { key: SecretClientKey }, // whole service is sensitive
|
|
30
|
+
* { key: VaultKey, properties: ['getSecret'] }, // only these calls
|
|
31
|
+
* ],
|
|
32
|
+
* );
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
class RedactingEventListener {
|
|
36
|
+
constructor(delegate, rules) {
|
|
37
|
+
this.delegate = delegate;
|
|
38
|
+
this.rules = rules;
|
|
39
|
+
}
|
|
40
|
+
onInitialize(context) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
// The initialize result is the service instance itself, so it is
|
|
43
|
+
// redacted only when the whole service is sensitive — a rule without
|
|
44
|
+
// `properties`.
|
|
45
|
+
return redactSpan((_b = (_a = this.delegate).onInitialize) === null || _b === void 0 ? void 0 : _b.call(_a, context), this.isRedacted(context.key));
|
|
46
|
+
}
|
|
47
|
+
onDispose(context) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
// Dispose carries no arguments and no result value; nothing to redact.
|
|
50
|
+
return (_b = (_a = this.delegate).onDispose) === null || _b === void 0 ? void 0 : _b.call(_a, context);
|
|
51
|
+
}
|
|
52
|
+
onMethodCall(context) {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const redacted = this.isRedacted(context.key, context.functionName);
|
|
55
|
+
const span = (_b = (_a = this.delegate).onMethodCall) === null || _b === void 0 ? void 0 : _b.call(_a, redacted
|
|
56
|
+
? // Replace each argument rather than the whole array, so the
|
|
57
|
+
Object.assign(Object.assign({}, context), { args: context.args.map(() => exports.REDACTED_VALUE) }) : context);
|
|
58
|
+
return redactSpan(span, redacted);
|
|
59
|
+
}
|
|
60
|
+
// 1. Si expiro el dbr `EXPIRED` el cron debe mandar a `FACE_MISMATCH`?
|
|
61
|
+
// 2. Si hubo un matchLevel intermediario el cron debe mandar a `FACE_MISMATCH`? (Probablemente no)
|
|
62
|
+
isRedacted(key, propertyName) {
|
|
63
|
+
return this.rules.some((rule) => {
|
|
64
|
+
var _a;
|
|
65
|
+
return rule.key === key &&
|
|
66
|
+
// A rule without `properties` redacts everything on the key,
|
|
67
|
+
// including initialize — where no property name is passed —
|
|
68
|
+
// while a rule with `properties` matches only those calls.
|
|
69
|
+
(rule.properties === undefined ||
|
|
70
|
+
(propertyName !== undefined &&
|
|
71
|
+
((_a = rule.properties) === null || _a === void 0 ? void 0 : _a.includes(propertyName))));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.RedactingEventListener = RedactingEventListener;
|
|
76
|
+
/**
|
|
77
|
+
* Wraps the delegate's EventSpan so success values are redacted before
|
|
78
|
+
* `end` sees them. `run` (and any future fields) pass through untouched.
|
|
79
|
+
*/
|
|
80
|
+
function redactSpan(span, redacted) {
|
|
81
|
+
if (!redacted || !(span === null || span === void 0 ? void 0 : span.end)) {
|
|
82
|
+
return span;
|
|
83
|
+
}
|
|
84
|
+
const end = span.end.bind(span);
|
|
85
|
+
return Object.assign(Object.assign({}, span), { end: (outcome) => end(outcome.type === 'success'
|
|
86
|
+
? { type: 'success', value: exports.REDACTED_VALUE }
|
|
87
|
+
: outcome) });
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=redactingEventListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactingEventListener.js","sourceRoot":"","sources":["../src/redactingEventListener.ts"],"names":[],"mappings":";;;AAmCA,sCAEC;AA3BD;;;GAGG;AACU,QAAA,cAAc,GAAG,YAAY,CAAC;AAqB3C,SAAgB,aAAa,CAAI,GAAkB,EAAE,UAAuC;IAC1F,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,sBAAsB;IACjC,YACmB,QAA+B,EAC/B,KAAoC;QADpC,aAAQ,GAAR,QAAQ,CAAuB;QAC/B,UAAK,GAAL,KAAK,CAA+B;IACpD,CAAC;IAEJ,YAAY,CAAC,OAA0B;;QACrC,iEAAiE;QACjE,qEAAqE;QACrE,gBAAgB;QAChB,OAAO,UAAU,CACf,MAAA,MAAA,IAA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AAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,CAAA,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,uCACK,IAAI,KACP,GAAG,EAAE,CAAC,OAAqB,EAAE,EAAE,CAC7B,GAAG,CACD,OAAO,CAAC,IAAI,KAAK,SAAS;YACxB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,sBAAc,EAAE;YAC5C,CAAC,CAAC,OAAO,CACZ,IACH;AACJ,CAAC"}
|
package/dist/serviceModule.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServiceKey } from './serviceKey';
|
|
2
2
|
import { ServiceFactory } from './serviceFactory';
|
|
3
3
|
import { ServiceScope } from './serviceScope';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ServiceModuleListener } from './serviceModuleListener';
|
|
5
5
|
type GenericFactory = ServiceFactory<unknown, readonly ServiceKey<any>[]>;
|
|
6
6
|
/**
|
|
7
7
|
* ServiceModule is a container for service factories and manages dependency resolution.
|
|
@@ -65,7 +65,7 @@ export declare class ServiceModule {
|
|
|
65
65
|
* @return A new ServiceModule containing the deduplicated factories.
|
|
66
66
|
* @throws {ServiceModuleInitError} If circular or missing dependencies are detected during module creation.
|
|
67
67
|
*/
|
|
68
|
-
static from(entries: (ServiceModule | GenericFactory)[], listener?:
|
|
68
|
+
static from(entries: (ServiceModule | GenericFactory)[], listener?: ServiceModuleListener): ServiceModule;
|
|
69
69
|
}
|
|
70
70
|
export {};
|
|
71
71
|
//# sourceMappingURL=serviceModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceModule.d.ts","sourceRoot":"","sources":["../src/serviceModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAEV,
|
|
1
|
+
{"version":3,"file":"serviceModule.d.ts","sourceRoot":"","sources":["../src/serviceModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAEV,qBAAqB,EACtB,MAAM,yBAAyB,CAAC;AAEjC,KAAK,cAAc,GAAG,cAAc,CAAC,OAAO,EAAE,SAAS,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAG1E;;;;;;;GAOG;AACH,qBAAa,aAAa;IAMJ,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE;IALxD;;;;OAIG;IACH,OAAO;IAOP;;;;;;OAMG;IACU,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IA2BnD;;;;;OAKG;IACU,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAWhE;;;;;;;;;OASG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,YAAY;IAQnC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,CAAC,aAAa,GAAG,cAAc,CAAC,EAAE,EAC3C,QAAQ,CAAC,EAAE,qBAAqB,GAC/B,aAAa;CAsBjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceModule.js","sourceRoot":"","sources":["../src/serviceModule.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,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SAAS,YAAY,CAAI,IAAsB,EAAE,EAAW;IAC1D,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,GAAG,EAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AACzC,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,KAAa;;IAChC,MAAM,IAAI,GAAG,MAAA,KAAK,CAAC,WAAW,0CAAE,IAAI,CAAC;IACrC,OAAO,IAAI,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ServiceKey } from './serviceKey';
|
|
2
|
+
/**
|
|
3
|
+
* A handle representing a single in-flight operation (initialization,
|
|
4
|
+
* disposal, or method call), returned by a ServiceEventListener when the
|
|
5
|
+
* operation starts.
|
|
6
|
+
*
|
|
7
|
+
* `end` is invoked exactly once when the operation finishes, so
|
|
8
|
+
* implementations can close over per-call state (a start time, a span
|
|
9
|
+
* handle, a correlation id) without any bookkeeping to pair concurrent
|
|
10
|
+
* start/finish events.
|
|
11
|
+
*/
|
|
12
|
+
export interface EventSpan {
|
|
13
|
+
/**
|
|
14
|
+
* Optional wrapper around the operation itself. When present, the module
|
|
15
|
+
* invokes the operation as `run(() => operation())`, so the listener can
|
|
16
|
+
* establish ambient state that the operation body and its async
|
|
17
|
+
* continuations inherit — this is what lets spans of nested service
|
|
18
|
+
* calls form a parent-child hierarchy.
|
|
19
|
+
*
|
|
20
|
+
* Implementations must invoke `fn` exactly once, synchronously, and
|
|
21
|
+
* return its result unchanged (for async operations, the promise itself).
|
|
22
|
+
* `end` is still delivered separately when the operation finishes.
|
|
23
|
+
*
|
|
24
|
+
* @param fn - A thunk that performs the operation.
|
|
25
|
+
* @return The value returned by `fn`.
|
|
26
|
+
*/
|
|
27
|
+
run?<T>(fn: () => T): T;
|
|
28
|
+
/**
|
|
29
|
+
* Invoked exactly once when the operation finishes, whether it succeeded
|
|
30
|
+
* or failed. For methods that return a promise, this fires when the
|
|
31
|
+
* promise settles, not when the method returns. On failure, the error is
|
|
32
|
+
* rethrown to the caller after this is invoked.
|
|
33
|
+
*
|
|
34
|
+
* Whether to retain or log the outcome is the implementation's choice;
|
|
35
|
+
* values are passed by reference, so implementations must not mutate them.
|
|
36
|
+
*
|
|
37
|
+
* @param outcome - How the operation finished, and its value or error.
|
|
38
|
+
* @return void
|
|
39
|
+
*/
|
|
40
|
+
end?(outcome: EventOutcome): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How an operation finished, delivered to EventSpan.end: `success` carries
|
|
44
|
+
* the value produced by the operation (the return or resolved value for
|
|
45
|
+
* method calls, the service instance for initialize, undefined for
|
|
46
|
+
* dispose); `failure` carries the error that was thrown or rejected.
|
|
47
|
+
*/
|
|
48
|
+
export type EventOutcome = {
|
|
49
|
+
type: 'success';
|
|
50
|
+
value: unknown;
|
|
51
|
+
} | {
|
|
52
|
+
type: 'failure';
|
|
53
|
+
error: unknown;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Context of a service initialization, delivered to onInitialize.
|
|
57
|
+
* Future fields are added here rather than as extra parameters.
|
|
58
|
+
*/
|
|
59
|
+
export interface InitializeContext {
|
|
60
|
+
/**
|
|
61
|
+
* The unique identifier of the service that is being initialized.
|
|
62
|
+
*/
|
|
63
|
+
key: ServiceKey<unknown>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Context of a service disposal, delivered to onDispose.
|
|
67
|
+
* Future fields are added here rather than as extra parameters.
|
|
68
|
+
*/
|
|
69
|
+
export interface DisposeContext {
|
|
70
|
+
/**
|
|
71
|
+
* The unique identifier of the service that is being disposed.
|
|
72
|
+
*/
|
|
73
|
+
key: ServiceKey<unknown>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Context of a method invocation, delivered to onMethodCall.
|
|
77
|
+
* Future fields are added here rather than as extra parameters.
|
|
78
|
+
*/
|
|
79
|
+
export interface MethodCallContext {
|
|
80
|
+
/**
|
|
81
|
+
* The unique identifier of the service the method belongs to.
|
|
82
|
+
*/
|
|
83
|
+
key: ServiceKey<unknown>;
|
|
84
|
+
/**
|
|
85
|
+
* The name of the class implementing the service (the instance's
|
|
86
|
+
* constructor name), which may differ from `key.name`. Undefined for
|
|
87
|
+
* services that are not instances of a named class, such as plain
|
|
88
|
+
* object literals.
|
|
89
|
+
*/
|
|
90
|
+
className?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The name of the method that is being called.
|
|
93
|
+
*/
|
|
94
|
+
functionName: string;
|
|
95
|
+
/**
|
|
96
|
+
* The arguments the method was invoked with, passed by reference;
|
|
97
|
+
* implementations must not mutate them.
|
|
98
|
+
*/
|
|
99
|
+
args: readonly unknown[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Interface for listening to service events. Implement this interface to
|
|
103
|
+
* observe lifecycle events and method calls of services in a module.
|
|
104
|
+
*
|
|
105
|
+
* Each method is invoked when the corresponding operation starts and may
|
|
106
|
+
* return an EventSpan that is notified when that operation finishes.
|
|
107
|
+
* Returning nothing opts out of completion tracking for that call.
|
|
108
|
+
*/
|
|
109
|
+
export interface ServiceModuleListener {
|
|
110
|
+
/**
|
|
111
|
+
* Invoked at the start of the initialization process for a specific service.
|
|
112
|
+
*
|
|
113
|
+
* @param context - Context of the initialization, including the service key.
|
|
114
|
+
* @return An EventSpan notified when initialization finishes, or void.
|
|
115
|
+
*/
|
|
116
|
+
onInitialize?(context: InitializeContext): EventSpan | void;
|
|
117
|
+
/**
|
|
118
|
+
* Invoked when the disposal process for a service starts.
|
|
119
|
+
*
|
|
120
|
+
* @param context - Context of the disposal, including the service key.
|
|
121
|
+
* @return An EventSpan notified when disposal finishes, or void.
|
|
122
|
+
*/
|
|
123
|
+
onDispose?(context: DisposeContext): EventSpan | void;
|
|
124
|
+
/**
|
|
125
|
+
* Invoked when a method call starts on a service instance.
|
|
126
|
+
*
|
|
127
|
+
* @param context - Context of the invocation, including the service key,
|
|
128
|
+
* the method name, and its arguments.
|
|
129
|
+
* @return An EventSpan notified when the call finishes, or void.
|
|
130
|
+
*/
|
|
131
|
+
onMethodCall?(context: MethodCallContext): EventSpan | void;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=serviceModuleListener.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceModuleListener.d.ts","sourceRoot":"","sources":["../src/serviceModuleListener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAExB;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACtB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAEzB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,IAAI,EAAE,SAAS,OAAO,EAAE,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,YAAY,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC;IAE5D;;;;;OAKG;IACH,SAAS,CAAC,CAAC,OAAO,EAAE,cAAc,GAAG,SAAS,GAAG,IAAI,CAAC;IAEtD;;;;;;OAMG;IACH,YAAY,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAAC;CAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serviceModuleListener.js","sourceRoot":"","sources":["../src/serviceModuleListener.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './serviceModule';
|
|
|
3
3
|
export * from './serviceFactory';
|
|
4
4
|
export * from './serviceScope';
|
|
5
5
|
export * from './serviceSelector';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './serviceModuleListener';
|
|
7
|
+
export * from './redactingEventListener';
|
|
7
8
|
export * from './errors';
|
|
8
9
|
export * from './utils';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DisposeContext,
|
|
3
|
+
EventOutcome,
|
|
4
|
+
EventSpan,
|
|
5
|
+
InitializeContext,
|
|
6
|
+
MethodCallContext,
|
|
7
|
+
ServiceModuleListener,
|
|
8
|
+
} from './serviceModuleListener';
|
|
9
|
+
import type { ServiceKey } from './serviceKey';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The placeholder that replaces redacted values in event contexts and
|
|
13
|
+
* outcomes.
|
|
14
|
+
*/
|
|
15
|
+
export const REDACTED_VALUE = '[redacted]';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Marks a service — or specific properties of it — as sensitive, so the
|
|
19
|
+
* values flowing through its events are replaced with {@link REDACTED_VALUE}.
|
|
20
|
+
*/
|
|
21
|
+
export interface RedactionRule<T> {
|
|
22
|
+
/**
|
|
23
|
+
* The service key whose values must be redacted. Matched by key
|
|
24
|
+
* identity, like everywhere else in the container.
|
|
25
|
+
*/
|
|
26
|
+
key: ServiceKey<T>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Property names to redact. Optional: when omitted, ALL properties of
|
|
30
|
+
* the service are redacted, along with its initialize result (the
|
|
31
|
+
* service instance itself may carry credentials or config).
|
|
32
|
+
*/
|
|
33
|
+
properties?: Extract<keyof T, string>[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function redactionRule<T>(key: ServiceKey<T>, properties?: Extract<keyof T, string>[]): RedactionRule<T> {
|
|
37
|
+
return { key, properties };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A ServiceEventListener decorator that redacts sensitive values before
|
|
42
|
+
* they reach the wrapped listener. Works with any implementation via
|
|
43
|
+
* delegation: arguments in MethodCallContext and success values in
|
|
44
|
+
* EventOutcome are replaced with {@link REDACTED_VALUE}, so the delegate
|
|
45
|
+
* never sees the sensitive data — whatever it captures or exports is
|
|
46
|
+
* already scrubbed.
|
|
47
|
+
*
|
|
48
|
+
* Failure outcomes are passed through unchanged so error reporting keeps
|
|
49
|
+
* working; keep secrets out of error messages at the throwing site.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const listener = new RedactingEventListener(
|
|
54
|
+
* new OTELEventListener({ captureArguments: true, captureResults: true }),
|
|
55
|
+
* [
|
|
56
|
+
* { key: SecretClientKey }, // whole service is sensitive
|
|
57
|
+
* { key: VaultKey, properties: ['getSecret'] }, // only these calls
|
|
58
|
+
* ],
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export class RedactingEventListener implements ServiceModuleListener {
|
|
63
|
+
constructor(
|
|
64
|
+
private readonly delegate: ServiceModuleListener,
|
|
65
|
+
private readonly rules: readonly RedactionRule<any>[],
|
|
66
|
+
) {}
|
|
67
|
+
|
|
68
|
+
onInitialize(context: InitializeContext): EventSpan | void {
|
|
69
|
+
// The initialize result is the service instance itself, so it is
|
|
70
|
+
// redacted only when the whole service is sensitive — a rule without
|
|
71
|
+
// `properties`.
|
|
72
|
+
return redactSpan(
|
|
73
|
+
this.delegate.onInitialize?.(context),
|
|
74
|
+
this.isRedacted(context.key),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
onDispose(context: DisposeContext): EventSpan | void {
|
|
79
|
+
// Dispose carries no arguments and no result value; nothing to redact.
|
|
80
|
+
return this.delegate.onDispose?.(context);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
onMethodCall(context: MethodCallContext): EventSpan | void {
|
|
84
|
+
const redacted = this.isRedacted(context.key, context.functionName);
|
|
85
|
+
const span = this.delegate.onMethodCall?.(
|
|
86
|
+
redacted
|
|
87
|
+
? // Replace each argument rather than the whole array, so the
|
|
88
|
+
// delegate still sees the call's arity.
|
|
89
|
+
{ ...context, args: context.args.map(() => REDACTED_VALUE) }
|
|
90
|
+
: context,
|
|
91
|
+
);
|
|
92
|
+
return redactSpan(span, redacted);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 1. Si expiro el dbr `EXPIRED` el cron debe mandar a `FACE_MISMATCH`?
|
|
96
|
+
// 2. Si hubo un matchLevel intermediario el cron debe mandar a `FACE_MISMATCH`? (Probablemente no)
|
|
97
|
+
private isRedacted(key: ServiceKey<any>, propertyName?: string): boolean {
|
|
98
|
+
return this.rules.some(
|
|
99
|
+
(rule) =>
|
|
100
|
+
rule.key === key &&
|
|
101
|
+
// A rule without `properties` redacts everything on the key,
|
|
102
|
+
// including initialize — where no property name is passed —
|
|
103
|
+
// while a rule with `properties` matches only those calls.
|
|
104
|
+
(rule.properties === undefined ||
|
|
105
|
+
(propertyName !== undefined &&
|
|
106
|
+
rule.properties?.includes(propertyName))),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Wraps the delegate's EventSpan so success values are redacted before
|
|
113
|
+
* `end` sees them. `run` (and any future fields) pass through untouched.
|
|
114
|
+
*/
|
|
115
|
+
function redactSpan(
|
|
116
|
+
span: EventSpan | void,
|
|
117
|
+
redacted: boolean,
|
|
118
|
+
): EventSpan | void {
|
|
119
|
+
if (!redacted || !span?.end) {
|
|
120
|
+
return span;
|
|
121
|
+
}
|
|
122
|
+
const end = span.end.bind(span);
|
|
123
|
+
return {
|
|
124
|
+
...span,
|
|
125
|
+
end: (outcome: EventOutcome) =>
|
|
126
|
+
end(
|
|
127
|
+
outcome.type === 'success'
|
|
128
|
+
? { type: 'success', value: REDACTED_VALUE }
|
|
129
|
+
: outcome,
|
|
130
|
+
),
|
|
131
|
+
};
|
|
132
|
+
}
|
package/src/serviceModule.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { ServiceSelector } from './serviceSelector';
|
|
|
5
5
|
import { ServiceFactoryNotFoundError, ServiceModuleInitError } from './errors';
|
|
6
6
|
import type {
|
|
7
7
|
EventSpan,
|
|
8
|
-
|
|
9
|
-
} from './
|
|
8
|
+
ServiceModuleListener,
|
|
9
|
+
} from './serviceModuleListener';
|
|
10
10
|
|
|
11
11
|
type GenericFactory = ServiceFactory<unknown, readonly ServiceKey<any>[]>;
|
|
12
12
|
type GenericKey = ServiceKey<any>;
|
|
@@ -123,7 +123,7 @@ export class ServiceModule {
|
|
|
123
123
|
*/
|
|
124
124
|
static from(
|
|
125
125
|
entries: (ServiceModule | GenericFactory)[],
|
|
126
|
-
listener?:
|
|
126
|
+
listener?: ServiceModuleListener,
|
|
127
127
|
): ServiceModule {
|
|
128
128
|
// Flatten entries and keep only the last factory for each ServiceKey
|
|
129
129
|
const flattened = entries.flatMap((e) =>
|
|
@@ -277,7 +277,7 @@ function isSuitable<T, D extends readonly ServiceKey<any>[]>(
|
|
|
277
277
|
* @return A new service factory that provides the same dependencies but includes event notification logic.
|
|
278
278
|
*/
|
|
279
279
|
function makeObservable<T, D extends readonly ServiceKey<any>[]>(
|
|
280
|
-
listener:
|
|
280
|
+
listener: ServiceModuleListener,
|
|
281
281
|
delegate: ServiceFactory<any, D>,
|
|
282
282
|
): ServiceFactory<T, D> {
|
|
283
283
|
const key = delegate.provides;
|
|
@@ -330,7 +330,7 @@ function makeObservable<T, D extends readonly ServiceKey<any>[]>(
|
|
|
330
330
|
*/
|
|
331
331
|
function observeMethodCalls(
|
|
332
332
|
thing: any,
|
|
333
|
-
listener:
|
|
333
|
+
listener: ServiceModuleListener,
|
|
334
334
|
key: ServiceKey<unknown>,
|
|
335
335
|
): any {
|
|
336
336
|
if (typeof thing !== 'object' || thing === null) {
|
|
@@ -111,7 +111,7 @@ export interface MethodCallContext {
|
|
|
111
111
|
* return an EventSpan that is notified when that operation finishes.
|
|
112
112
|
* Returning nothing opts out of completion tracking for that call.
|
|
113
113
|
*/
|
|
114
|
-
export interface
|
|
114
|
+
export interface ServiceModuleListener {
|
|
115
115
|
/**
|
|
116
116
|
* Invoked at the start of the initialization process for a specific service.
|
|
117
117
|
*
|