@egen-civitas/esm-embed-host 0.11.0 → 0.12.0
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 +11 -0
- package/dist/connection.d.ts +1 -0
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +41 -1
- package/dist/providers.d.ts +19 -1
- package/dist/providers.d.ts.map +1 -1
- package/dist/table.d.ts +2 -0
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +191 -4
- package/package.json +3 -3
- package/src/connection.ts +16 -1
- package/src/providers.ts +15 -1
- package/src/table.ts +80 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @egen-civitas/esm-embed-host
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ff2b3de: Audit du Shell (A6) : `HostProviders.audit` reçoit des événements SANS charge utile (`connection.opened|closed`, `call`, `subscribe` : module, capacité, méthode, résultat, durée). Télémétrie étendue (B9) : `telemetry.error`, `trace` (mesure sans gêner le résultat) et `health` ; politique opérateur du grant `telemetry` (`levels`, `sampleRate`, jamais d'échantillonnage des erreurs/health), plafonds de confidentialité (message 2000, pile 4096, détail 500, contexte 8 Kio), masquage `redact` par le Shell, repli sur `log`/`metric` pour un fournisseur plus ancien ; `diagnose()` expose `rttMs` et `recentErrors`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [ff2b3de]
|
|
12
|
+
- @egen-civitas/esm-embed-protocol@0.12.0
|
|
13
|
+
|
|
3
14
|
## 0.11.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/dist/connection.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class HostConnection {
|
|
|
29
29
|
/** Traite un message de poignée de main v2 ; `true` si le message est de la famille v2 (consommé). */
|
|
30
30
|
handle(data: unknown): boolean;
|
|
31
31
|
private open;
|
|
32
|
+
private audit;
|
|
32
33
|
/** Appel hôte → app (ex. `lifecycle.canLeave`) ; `undefined` si l'app n'est pas connectée en v2. */
|
|
33
34
|
callApp<T = unknown>(cap: string, method: string, args?: unknown[]): Promise<T | undefined>;
|
|
34
35
|
get connected(): boolean;
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,MAAM,EACZ,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAgD,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7F,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,gFAAgF;IAChF,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IACxD,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IAC3E,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;GAGG;AACH,qBAAa,cAAc;IAKb,OAAO,CAAC,QAAQ,CAAC,CAAC;IAJ9B,KAAK,EAAE,eAAe,CAAU;IAChC,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,GAAG,CAAC,CAAc;gBAEG,CAAC,EAAE,iBAAiB;IAEjD,qGAAqG;IACrG,KAAK,IAAI,IAAI;IAOb,sGAAsG;IACtG,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAe9B,OAAO,CAAC,IAAI;IAsCZ,OAAO,CAAC,KAAK;IAQb,oGAAoG;IAC9F,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIrG,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,oFAAoF;IACpF,KAAK,IAAI,IAAI;IAOb,OAAO,IAAI,IAAI;CAIhB"}
|
package/dist/connection.js
CHANGED
|
@@ -287,12 +287,28 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
|
|
|
287
287
|
handlers: table,
|
|
288
288
|
onSubscribe: subscribe,
|
|
289
289
|
validate: function validate(cap, method, args) {
|
|
290
|
-
|
|
290
|
+
var invalid = validateCall(cap, method, args, 'app-to-host');
|
|
291
|
+
if (invalid) _this.audit({
|
|
292
|
+
kind: 'call',
|
|
293
|
+
moduleName: _this.o.moduleName,
|
|
294
|
+
ts: Date.now(),
|
|
295
|
+
capability: cap,
|
|
296
|
+
method: method,
|
|
297
|
+
outcome: 'INVALID_ARGS',
|
|
298
|
+
durationMs: 0
|
|
299
|
+
});
|
|
300
|
+
return invalid;
|
|
291
301
|
},
|
|
292
302
|
limits: this.o.limits,
|
|
293
303
|
onClose: function onClose(reason) {
|
|
294
304
|
var _this_o_onClose, _this_o;
|
|
295
305
|
if (_this.state !== 'closed') _this.state = 'idle';
|
|
306
|
+
_this.audit({
|
|
307
|
+
kind: 'connection.closed',
|
|
308
|
+
moduleName: _this.o.moduleName,
|
|
309
|
+
ts: Date.now(),
|
|
310
|
+
reason: reason
|
|
311
|
+
});
|
|
296
312
|
(_this_o_onClose = (_this_o = _this.o).onClose) === null || _this_o_onClose === void 0 ? void 0 : _this_o_onClose.call(_this_o, reason);
|
|
297
313
|
}
|
|
298
314
|
});
|
|
@@ -307,9 +323,33 @@ import { availableCapabilities, createCapabilityTable } from './table.js';
|
|
|
307
323
|
}), [
|
|
308
324
|
port2
|
|
309
325
|
]);
|
|
326
|
+
this.audit({
|
|
327
|
+
kind: 'connection.opened',
|
|
328
|
+
moduleName: this.o.moduleName,
|
|
329
|
+
ts: Date.now(),
|
|
330
|
+
granted: granted.map(function(g) {
|
|
331
|
+
return g.id;
|
|
332
|
+
}),
|
|
333
|
+
denied: denied.map(function(d) {
|
|
334
|
+
return {
|
|
335
|
+
id: d.id,
|
|
336
|
+
reason: d.reason
|
|
337
|
+
};
|
|
338
|
+
})
|
|
339
|
+
});
|
|
310
340
|
(_this_o_onConnect = (_this_o = this.o).onConnect) === null || _this_o_onConnect === void 0 ? void 0 : _this_o_onConnect.call(_this_o, granted, denied);
|
|
311
341
|
}
|
|
312
342
|
},
|
|
343
|
+
{
|
|
344
|
+
key: "audit",
|
|
345
|
+
value: function audit(e) {
|
|
346
|
+
try {
|
|
347
|
+
var _this_o_providers_audit, _this_o_providers;
|
|
348
|
+
(_this_o_providers_audit = (_this_o_providers = this.o.providers).audit) === null || _this_o_providers_audit === void 0 ? void 0 : _this_o_providers_audit.call(_this_o_providers, e);
|
|
349
|
+
} catch (unused) {
|
|
350
|
+
/* l'audit n'interrompt jamais la connexion */ }
|
|
351
|
+
}
|
|
352
|
+
},
|
|
313
353
|
{
|
|
314
354
|
key: "callApp",
|
|
315
355
|
value: /** Appel hôte → app (ex. `lifecycle.canLeave`) ; `undefined` si l'app n'est pas connectée en v2. */ function callApp(_0, _1) {
|
package/dist/providers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EnvironmentInfo, NotificationCloseReason, PublishOptions } from '@egen-civitas/esm-embed-protocol';
|
|
1
|
+
import type { AuditEvent, EnvironmentInfo, NotificationCloseReason, PublishOptions } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
export type Unsub = () => void;
|
|
3
3
|
/** Valeur lisible et observable fournie par le Core. */
|
|
4
4
|
export interface Watchable<T> {
|
|
@@ -63,6 +63,11 @@ export interface HostProviders {
|
|
|
63
63
|
config?: Watchable<Record<string, unknown>>;
|
|
64
64
|
/** Environnement du Shell pour `config.environment()` : clés FERMÉES (D-09). Absent : non servi (`UNKNOWN_METHOD`). */
|
|
65
65
|
environment?: () => EnvironmentInfo | Promise<EnvironmentInfo>;
|
|
66
|
+
/**
|
|
67
|
+
* Journal d'audit du Shell (A6) : reçoit des événements SANS charge utile (voir `AuditEvent`). Synchrone, jamais bloquant :
|
|
68
|
+
* une exception du récepteur est avalée et ne perturbe jamais l'app.
|
|
69
|
+
*/
|
|
70
|
+
audit?: (e: AuditEvent) => void;
|
|
66
71
|
flags?: {
|
|
67
72
|
isEnabled(name: string): boolean | Promise<boolean>;
|
|
68
73
|
subscribe?(cb: () => void): Unsub;
|
|
@@ -97,9 +102,22 @@ export interface HostProviders {
|
|
|
97
102
|
list(slot: string): ExtensionInfo[] | Promise<ExtensionInfo[]>;
|
|
98
103
|
subscribe?(slot: string, cb: (list: ExtensionInfo[]) => void): Unsub;
|
|
99
104
|
};
|
|
105
|
+
/**
|
|
106
|
+
* Télémétrie. `log` et `metric` sont obligatoires ; `error`, `trace` et `health` sont optionnels : absents, l'hôte les ramène
|
|
107
|
+
* à `log`/`metric` (un fournisseur plus ancien reste valide). Le `moduleName` d'attribution est posé par l'hôte (`from`).
|
|
108
|
+
* `redact` (optionnel) masque les données d'une app AVANT tout envoi ; s'il lève, les données sont abandonnées.
|
|
109
|
+
*/
|
|
100
110
|
telemetry?: {
|
|
101
111
|
log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
102
112
|
metric(name: string, value: number, tags: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
113
|
+
error?(e: {
|
|
114
|
+
name: string;
|
|
115
|
+
message: string;
|
|
116
|
+
stack?: string;
|
|
117
|
+
}, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
118
|
+
trace?(name: string, durationMs: number, ok: boolean, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
119
|
+
health?(status: 'ok' | 'degraded' | 'failing', detail: string | undefined, from: CallerContext): void;
|
|
120
|
+
redact?(data: Record<string, unknown>, kind: 'log' | 'metric' | 'error' | 'trace', from: CallerContext): Record<string, unknown>;
|
|
103
121
|
};
|
|
104
122
|
}
|
|
105
123
|
//# sourceMappingURL=providers.d.ts.map
|
package/dist/providers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAC7H,MAAM,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC;AAE/B,wDAAwD;AACxD,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC;CAC3C;AAED,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,E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E,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;QAClI,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;QAC3H,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,GAAG,UAAU,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;QACtG,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAClI,CAAC;CACH"}
|
package/dist/table.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface HostControls {
|
|
|
19
19
|
supported?: string[];
|
|
20
20
|
default?: string;
|
|
21
21
|
};
|
|
22
|
+
/** Source d'aléa de l'échantillonnage de télémétrie (défaut `Math.random`) ; injectable pour des tests déterministes. */
|
|
23
|
+
random?: () => number;
|
|
22
24
|
intent?(slug: string, params?: Record<string, unknown>, options?: NavigateOptions): NavigationResult | Promise<NavigationResult>;
|
|
23
25
|
/** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
|
|
24
26
|
notFound?(path?: string): void;
|
package/dist/table.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../src/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EA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EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjI,6FAA6F;IAC7F,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,IAAI,IAAI,CAAC;IACjB,6DAA6D;IAC7D,OAAO,EAAE,GAAG,CAAC;CACd;AAED,8HAA8H;AAC9H,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,aAAa,GAAG,GAAG,CAAC,YAAY,CAAC,CAczE;AAID,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,SAAS,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,YAAY,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,gBAAgB,CAAA;CAAE,CAqP3G"}
|
package/dist/table.js
CHANGED
|
@@ -6,6 +6,9 @@ function _array_like_to_array(arr, len) {
|
|
|
6
6
|
function _array_with_holes(arr) {
|
|
7
7
|
if (Array.isArray(arr)) return arr;
|
|
8
8
|
}
|
|
9
|
+
function _array_without_holes(arr) {
|
|
10
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
+
}
|
|
9
12
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
13
|
try {
|
|
11
14
|
var info = gen[key](arg);
|
|
@@ -48,6 +51,17 @@ function _define_property(obj, key, value) {
|
|
|
48
51
|
}
|
|
49
52
|
return obj;
|
|
50
53
|
}
|
|
54
|
+
function _instanceof(left, right) {
|
|
55
|
+
"@swc/helpers - instanceof";
|
|
56
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
57
|
+
return !!right[Symbol.hasInstance](left);
|
|
58
|
+
} else {
|
|
59
|
+
return left instanceof right;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function _iterable_to_array(iter) {
|
|
63
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
64
|
+
}
|
|
51
65
|
function _iterable_to_array_limit(arr, i) {
|
|
52
66
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
67
|
if (_i == null) return;
|
|
@@ -75,6 +89,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
75
89
|
function _non_iterable_rest() {
|
|
76
90
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
91
|
}
|
|
92
|
+
function _non_iterable_spread() {
|
|
93
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
94
|
+
}
|
|
78
95
|
function _object_spread(target) {
|
|
79
96
|
for(var i = 1; i < arguments.length; i++){
|
|
80
97
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -117,6 +134,9 @@ function _object_spread_props(target, source) {
|
|
|
117
134
|
function _sliced_to_array(arr, i) {
|
|
118
135
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
119
136
|
}
|
|
137
|
+
function _to_consumable_array(arr) {
|
|
138
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
139
|
+
}
|
|
120
140
|
function _type_of(obj) {
|
|
121
141
|
"@swc/helpers - typeof";
|
|
122
142
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
@@ -228,7 +248,7 @@ function _ts_generator(thisArg, body) {
|
|
|
228
248
|
};
|
|
229
249
|
}
|
|
230
250
|
}
|
|
231
|
-
import { buildFallbackChain, CAPABILITIES, createSlidingLimiter, notificationPolicy, EmbedError, slotAllowed, topicAllowed } from '@egen-civitas/esm-embed-protocol';
|
|
251
|
+
import { TELEMETRY_LIMITS, buildFallbackChain, capContext, telemetryPolicy, truncateText, CAPABILITIES, createSlidingLimiter, notificationPolicy, EmbedError, slotAllowed, topicAllowed } from '@egen-civitas/esm-embed-protocol';
|
|
232
252
|
/** Capacités que l'hôte sait servir avec ces fournisseurs. `navigation`, `lifecycle` et `telemetry` sont toujours servies. */ export function availableCapabilities(p) {
|
|
233
253
|
var s = new Set([
|
|
234
254
|
'navigation',
|
|
@@ -592,14 +612,67 @@ var list = function list(cfg, key) {
|
|
|
592
612
|
};
|
|
593
613
|
}
|
|
594
614
|
if (cfgOf.has('telemetry')) {
|
|
615
|
+
var _c_random;
|
|
616
|
+
var policy1 = telemetryPolicy(cfgOf.get('telemetry'));
|
|
617
|
+
var random = (_c_random = c.random) !== null && _c_random !== void 0 ? _c_random : Math.random;
|
|
618
|
+
var sampled = function sampled() {
|
|
619
|
+
return policy1.sampleRate >= 1 || random() < policy1.sampleRate;
|
|
620
|
+
};
|
|
621
|
+
/** Plafonne le contexte (8 Kio) puis laisse le Shell le masquer ; si le masquage échoue, les données sont abandonnées. */ var clean = function clean(data, kind) {
|
|
622
|
+
var _p_telemetry;
|
|
623
|
+
var capped = capContext(data);
|
|
624
|
+
if (!capped || !((_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.redact)) return capped;
|
|
625
|
+
try {
|
|
626
|
+
return p.telemetry.redact(capped, kind, ctx);
|
|
627
|
+
} catch (unused) {
|
|
628
|
+
return undefined;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
595
631
|
table.telemetry = {
|
|
596
632
|
log: function log(level, message, extra) {
|
|
597
633
|
var _p_telemetry;
|
|
598
|
-
|
|
634
|
+
if (!policy1.levels.includes(level)) return; // niveau non autorisé par l'opérateur : ignoré sans erreur
|
|
635
|
+
if ((level === 'debug' || level === 'info') && !sampled()) return;
|
|
636
|
+
(_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.log(level, truncateText(message, TELEMETRY_LIMITS.message), clean(extra, 'log'), ctx);
|
|
599
637
|
},
|
|
600
638
|
metric: function metric(name, value, tags) {
|
|
601
639
|
var _p_telemetry;
|
|
602
|
-
|
|
640
|
+
if (!sampled()) return;
|
|
641
|
+
(_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.metric(name, value, clean(tags, 'metric'), ctx);
|
|
642
|
+
},
|
|
643
|
+
// Erreurs et santé ne sont jamais échantillonnées : on ne perd pas un signal de panne.
|
|
644
|
+
error: function error(e, extra) {
|
|
645
|
+
var _p_telemetry, _p_telemetry1;
|
|
646
|
+
var _$err = _object_spread({
|
|
647
|
+
name: truncateText(e.name, 100),
|
|
648
|
+
message: truncateText(e.message, TELEMETRY_LIMITS.message)
|
|
649
|
+
}, e.stack !== undefined ? {
|
|
650
|
+
stack: truncateText(e.stack, TELEMETRY_LIMITS.stack)
|
|
651
|
+
} : {});
|
|
652
|
+
var data = clean(extra, 'error');
|
|
653
|
+
if ((_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.error) p.telemetry.error(_$err, data, ctx);
|
|
654
|
+
else (_p_telemetry1 = p.telemetry) === null || _p_telemetry1 === void 0 ? void 0 : _p_telemetry1.log('error', "".concat(_$err.name, ": ").concat(_$err.message), _object_spread({
|
|
655
|
+
errorType: _$err.name
|
|
656
|
+
}, _$err.stack ? {
|
|
657
|
+
stack: _$err.stack
|
|
658
|
+
} : {}, data !== null && data !== void 0 ? data : {}), ctx);
|
|
659
|
+
},
|
|
660
|
+
trace: function trace(name, durationMs, ok, extra) {
|
|
661
|
+
var _p_telemetry, _p_telemetry1;
|
|
662
|
+
if (!sampled()) return;
|
|
663
|
+
var data = clean(extra, 'trace');
|
|
664
|
+
if ((_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.trace) p.telemetry.trace(name, durationMs, ok, data, ctx);
|
|
665
|
+
else (_p_telemetry1 = p.telemetry) === null || _p_telemetry1 === void 0 ? void 0 : _p_telemetry1.metric("trace.".concat(name), durationMs, _object_spread({
|
|
666
|
+
ok: ok
|
|
667
|
+
}, data !== null && data !== void 0 ? data : {}), ctx);
|
|
668
|
+
},
|
|
669
|
+
health: function health(status, detail) {
|
|
670
|
+
var _p_telemetry, _p_telemetry1;
|
|
671
|
+
var d = detail === undefined ? undefined : truncateText(detail, TELEMETRY_LIMITS.detail);
|
|
672
|
+
if ((_p_telemetry = p.telemetry) === null || _p_telemetry === void 0 ? void 0 : _p_telemetry.health) p.telemetry.health(status, d, ctx);
|
|
673
|
+
else (_p_telemetry1 = p.telemetry) === null || _p_telemetry1 === void 0 ? void 0 : _p_telemetry1.log(status === 'ok' ? 'info' : status === 'degraded' ? 'warn' : 'error', "health: ".concat(status), d === undefined ? undefined : {
|
|
674
|
+
detail: d
|
|
675
|
+
}, ctx);
|
|
603
676
|
}
|
|
604
677
|
};
|
|
605
678
|
}
|
|
@@ -726,9 +799,123 @@ var list = function list(cfg, key) {
|
|
|
726
799
|
return undefined;
|
|
727
800
|
}
|
|
728
801
|
};
|
|
802
|
+
var audit = function audit(e) {
|
|
803
|
+
try {
|
|
804
|
+
var _p_audit;
|
|
805
|
+
(_p_audit = p.audit) === null || _p_audit === void 0 ? void 0 : _p_audit.call(p, e);
|
|
806
|
+
} catch (unused) {
|
|
807
|
+
/* l'audit n'interrompt jamais un appel */ }
|
|
808
|
+
};
|
|
809
|
+
if (p.audit) {
|
|
810
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
811
|
+
try {
|
|
812
|
+
var _loop = function() {
|
|
813
|
+
var _step_value = _sliced_to_array(_step.value, 2), capability = _step_value[0], methods = _step_value[1];
|
|
814
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
815
|
+
try {
|
|
816
|
+
var _loop = function() {
|
|
817
|
+
var _step_value = _sliced_to_array(_step1.value, 2), method = _step_value[0], fn = _step_value[1];
|
|
818
|
+
methods[method] = function() {
|
|
819
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
820
|
+
args[_key] = arguments[_key];
|
|
821
|
+
}
|
|
822
|
+
return _async_to_generator(function() {
|
|
823
|
+
var ts, outcome, e;
|
|
824
|
+
return _ts_generator(this, function(_state) {
|
|
825
|
+
switch(_state.label){
|
|
826
|
+
case 0:
|
|
827
|
+
ts = Date.now();
|
|
828
|
+
outcome = 'ok';
|
|
829
|
+
_state.label = 1;
|
|
830
|
+
case 1:
|
|
831
|
+
_state.trys.push([
|
|
832
|
+
1,
|
|
833
|
+
3,
|
|
834
|
+
4,
|
|
835
|
+
5
|
|
836
|
+
]);
|
|
837
|
+
return [
|
|
838
|
+
4,
|
|
839
|
+
fn.apply(void 0, _to_consumable_array(args))
|
|
840
|
+
];
|
|
841
|
+
case 2:
|
|
842
|
+
return [
|
|
843
|
+
2,
|
|
844
|
+
_state.sent()
|
|
845
|
+
];
|
|
846
|
+
case 3:
|
|
847
|
+
e = _state.sent();
|
|
848
|
+
outcome = _instanceof(e, EmbedError) ? e.code : 'INTERNAL';
|
|
849
|
+
throw e;
|
|
850
|
+
case 4:
|
|
851
|
+
audit({
|
|
852
|
+
kind: 'call',
|
|
853
|
+
moduleName: o.moduleName,
|
|
854
|
+
ts: ts,
|
|
855
|
+
capability: capability,
|
|
856
|
+
method: method,
|
|
857
|
+
outcome: outcome,
|
|
858
|
+
durationMs: Date.now() - ts
|
|
859
|
+
});
|
|
860
|
+
return [
|
|
861
|
+
7
|
|
862
|
+
];
|
|
863
|
+
case 5:
|
|
864
|
+
return [
|
|
865
|
+
2
|
|
866
|
+
];
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
})();
|
|
870
|
+
};
|
|
871
|
+
};
|
|
872
|
+
for(var _iterator = Object.entries(methods)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion = (_step1 = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
873
|
+
} catch (err) {
|
|
874
|
+
_didIteratorError = true;
|
|
875
|
+
_iteratorError = err;
|
|
876
|
+
} finally{
|
|
877
|
+
try {
|
|
878
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
879
|
+
_iterator.return();
|
|
880
|
+
}
|
|
881
|
+
} finally{
|
|
882
|
+
if (_didIteratorError) {
|
|
883
|
+
throw _iteratorError;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
// Chaque méthode servie est enveloppée : qui (module), quoi (capacité.méthode), résultat, durée — jamais les arguments.
|
|
889
|
+
for(var _iterator = Object.entries(table)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
890
|
+
} catch (err) {
|
|
891
|
+
_didIteratorError = true;
|
|
892
|
+
_iteratorError = err;
|
|
893
|
+
} finally{
|
|
894
|
+
try {
|
|
895
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
896
|
+
_iterator.return();
|
|
897
|
+
}
|
|
898
|
+
} finally{
|
|
899
|
+
if (_didIteratorError) {
|
|
900
|
+
throw _iteratorError;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
var auditedSubscribe = function auditedSubscribe(cap, ev, emit) {
|
|
906
|
+
var off = subscribe(cap, ev, emit);
|
|
907
|
+
audit({
|
|
908
|
+
kind: 'subscribe',
|
|
909
|
+
moduleName: o.moduleName,
|
|
910
|
+
ts: Date.now(),
|
|
911
|
+
capability: cap,
|
|
912
|
+
outcome: off ? 'ok' : 'DENIED'
|
|
913
|
+
});
|
|
914
|
+
return off;
|
|
915
|
+
};
|
|
729
916
|
return {
|
|
730
917
|
table: table,
|
|
731
|
-
subscribe: subscribe
|
|
918
|
+
subscribe: p.audit ? auditedSubscribe : subscribe
|
|
732
919
|
};
|
|
733
920
|
}
|
|
734
921
|
var ENVIRONMENTS = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egen-civitas/esm-embed-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Hôte (côté Shell/Core) des applications embarquées : iframe sécurisée, poignée de main v2, grants, fournisseurs de capacités, navigation partagée, compatibilité du pont 1.1.",
|
|
6
6
|
"type": "module",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@egen-civitas/esm-embed-client": "^0.
|
|
60
|
+
"@egen-civitas/esm-embed-client": "^0.13.0",
|
|
61
61
|
"@swc/cli": "0.8.1",
|
|
62
62
|
"@swc/core": "1.15.21",
|
|
63
63
|
"@types/node": "^20",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"vitest": "^4.1.2"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@egen-civitas/esm-embed-protocol": "^0.
|
|
72
|
+
"@egen-civitas/esm-embed-protocol": "^0.12.0"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/connection.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
parseEnvelope,
|
|
9
9
|
validateCall,
|
|
10
10
|
wrapHandshake,
|
|
11
|
+
type AuditEvent,
|
|
11
12
|
type CapabilityDenied,
|
|
12
13
|
type CapabilityGranted,
|
|
13
14
|
type EffectiveGrants,
|
|
@@ -86,18 +87,32 @@ export class HostConnection {
|
|
|
86
87
|
port: port1,
|
|
87
88
|
handlers: table,
|
|
88
89
|
onSubscribe: subscribe,
|
|
89
|
-
validate: (cap, method, args) =>
|
|
90
|
+
validate: (cap, method, args) => {
|
|
91
|
+
const invalid = validateCall(cap, method, args, 'app-to-host');
|
|
92
|
+
if (invalid) this.audit({ kind: 'call', moduleName: this.o.moduleName, ts: Date.now(), capability: cap, method, outcome: 'INVALID_ARGS', durationMs: 0 });
|
|
93
|
+
return invalid;
|
|
94
|
+
},
|
|
90
95
|
limits: this.o.limits,
|
|
91
96
|
onClose: (reason) => {
|
|
92
97
|
if (this.state !== 'closed') this.state = 'idle';
|
|
98
|
+
this.audit({ kind: 'connection.closed', moduleName: this.o.moduleName, ts: Date.now(), reason });
|
|
93
99
|
this.o.onClose?.(reason);
|
|
94
100
|
},
|
|
95
101
|
});
|
|
96
102
|
this.state = 'connected';
|
|
97
103
|
this.o.post(wrapHandshake(this.o.moduleName, { kind: 'port', nonce: this.nonce!, protocol: EGEN_EMBED_PROTOCOL, granted, denied, hostVersion: this.o.hostVersion }), [port2]);
|
|
104
|
+
this.audit({ kind: 'connection.opened', moduleName: this.o.moduleName, ts: Date.now(), granted: granted.map((g) => g.id), denied: denied.map((d) => ({ id: d.id, reason: d.reason })) });
|
|
98
105
|
this.o.onConnect?.(granted, denied);
|
|
99
106
|
}
|
|
100
107
|
|
|
108
|
+
private audit(e: AuditEvent): void {
|
|
109
|
+
try {
|
|
110
|
+
this.o.providers.audit?.(e);
|
|
111
|
+
} catch {
|
|
112
|
+
/* l'audit n'interrompt jamais la connexion */
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
101
116
|
/** Appel hôte → app (ex. `lifecycle.canLeave`) ; `undefined` si l'app n'est pas connectée en v2. */
|
|
102
117
|
async callApp<T = unknown>(cap: string, method: string, args: unknown[] = []): Promise<T | undefined> {
|
|
103
118
|
return this.rpc && !this.rpc.closed ? this.rpc.call<T>(cap, method, args) : undefined;
|
package/src/providers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EnvironmentInfo, NotificationCloseReason, PublishOptions } from '@egen-civitas/esm-embed-protocol';
|
|
1
|
+
import type { AuditEvent, EnvironmentInfo, NotificationCloseReason, PublishOptions } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
export type Unsub = () => void;
|
|
3
3
|
|
|
4
4
|
/** Valeur lisible et observable fournie par le Core. */
|
|
@@ -63,6 +63,11 @@ export interface HostProviders {
|
|
|
63
63
|
config?: Watchable<Record<string, unknown>>;
|
|
64
64
|
/** Environnement du Shell pour `config.environment()` : clés FERMÉES (D-09). Absent : non servi (`UNKNOWN_METHOD`). */
|
|
65
65
|
environment?: () => EnvironmentInfo | Promise<EnvironmentInfo>;
|
|
66
|
+
/**
|
|
67
|
+
* Journal d'audit du Shell (A6) : reçoit des événements SANS charge utile (voir `AuditEvent`). Synchrone, jamais bloquant :
|
|
68
|
+
* une exception du récepteur est avalée et ne perturbe jamais l'app.
|
|
69
|
+
*/
|
|
70
|
+
audit?: (e: AuditEvent) => void;
|
|
66
71
|
flags?: { isEnabled(name: string): boolean | Promise<boolean>; subscribe?(cb: () => void): Unsub };
|
|
67
72
|
/**
|
|
68
73
|
* Bus d'événements du Shell. `publish`/`subscribe` historiques inchangés ; les paramètres ajoutés sont optionnels (un fournisseur
|
|
@@ -82,8 +87,17 @@ export interface HostProviders {
|
|
|
82
87
|
};
|
|
83
88
|
/** Extensions attachées à un slot du Core (apps internes, framework, autres apps) : métadonnées seulement, jamais le rendu. */
|
|
84
89
|
extensions?: { list(slot: string): ExtensionInfo[] | Promise<ExtensionInfo[]>; subscribe?(slot: string, cb: (list: ExtensionInfo[]) => void): Unsub };
|
|
90
|
+
/**
|
|
91
|
+
* Télémétrie. `log` et `metric` sont obligatoires ; `error`, `trace` et `health` sont optionnels : absents, l'hôte les ramène
|
|
92
|
+
* à `log`/`metric` (un fournisseur plus ancien reste valide). Le `moduleName` d'attribution est posé par l'hôte (`from`).
|
|
93
|
+
* `redact` (optionnel) masque les données d'une app AVANT tout envoi ; s'il lève, les données sont abandonnées.
|
|
94
|
+
*/
|
|
85
95
|
telemetry?: {
|
|
86
96
|
log(level: 'debug' | 'info' | 'warn' | 'error', message: string, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
87
97
|
metric(name: string, value: number, tags: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
98
|
+
error?(e: { name: string; message: string; stack?: string }, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
99
|
+
trace?(name: string, durationMs: number, ok: boolean, ctx: Record<string, unknown> | undefined, from: CallerContext): void;
|
|
100
|
+
health?(status: 'ok' | 'degraded' | 'failing', detail: string | undefined, from: CallerContext): void;
|
|
101
|
+
redact?(data: Record<string, unknown>, kind: 'log' | 'metric' | 'error' | 'trace', from: CallerContext): Record<string, unknown>;
|
|
88
102
|
};
|
|
89
103
|
}
|
package/src/table.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
TELEMETRY_LIMITS,
|
|
2
3
|
buildFallbackChain,
|
|
4
|
+
capContext,
|
|
5
|
+
telemetryPolicy,
|
|
6
|
+
truncateText,
|
|
3
7
|
CAPABILITIES,
|
|
4
8
|
createSlidingLimiter,
|
|
5
9
|
notificationPolicy,
|
|
@@ -11,6 +15,7 @@ import {
|
|
|
11
15
|
type GrantConfig,
|
|
12
16
|
type HandlerTable,
|
|
13
17
|
type EnvironmentInfo,
|
|
18
|
+
type AuditOutcome,
|
|
14
19
|
type NavigateOptions,
|
|
15
20
|
type NotificationCloseReason,
|
|
16
21
|
type PublishOptions,
|
|
@@ -33,6 +38,8 @@ export interface HostControls {
|
|
|
33
38
|
canGoBack?(): boolean | Promise<boolean>;
|
|
34
39
|
/** Langues gérées par l'app (`manifest.locales`) et langue par défaut du Shell : alimentent `locale.fallbackChain`. */
|
|
35
40
|
locales?: { supported?: string[]; default?: string };
|
|
41
|
+
/** Source d'aléa de l'échantillonnage de télémétrie (défaut `Math.random`) ; injectable pour des tests déterministes. */
|
|
42
|
+
random?: () => number;
|
|
36
43
|
intent?(slug: string, params?: Record<string, unknown>, options?: NavigateOptions): NavigationResult | Promise<NavigationResult>;
|
|
37
44
|
/** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
|
|
38
45
|
notFound?(path?: string): void;
|
|
@@ -183,9 +190,47 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
|
|
|
183
190
|
};
|
|
184
191
|
}
|
|
185
192
|
if (cfgOf.has('telemetry')) {
|
|
193
|
+
const policy = telemetryPolicy(cfgOf.get('telemetry'));
|
|
194
|
+
const random = c.random ?? Math.random;
|
|
195
|
+
const sampled = () => policy.sampleRate >= 1 || random() < policy.sampleRate;
|
|
196
|
+
/** Plafonne le contexte (8 Kio) puis laisse le Shell le masquer ; si le masquage échoue, les données sont abandonnées. */
|
|
197
|
+
const clean = (data: Record<string, unknown> | undefined, kind: 'log' | 'metric' | 'error' | 'trace'): Record<string, unknown> | undefined => {
|
|
198
|
+
const capped = capContext(data);
|
|
199
|
+
if (!capped || !p.telemetry?.redact) return capped;
|
|
200
|
+
try {
|
|
201
|
+
return p.telemetry.redact(capped, kind, ctx);
|
|
202
|
+
} catch {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
186
206
|
table.telemetry = {
|
|
187
|
-
log: (level: any, message: string, extra?: Record<string, unknown>) =>
|
|
188
|
-
|
|
207
|
+
log: (level: any, message: string, extra?: Record<string, unknown>) => {
|
|
208
|
+
if (!policy.levels.includes(level)) return; // niveau non autorisé par l'opérateur : ignoré sans erreur
|
|
209
|
+
if ((level === 'debug' || level === 'info') && !sampled()) return;
|
|
210
|
+
p.telemetry?.log(level, truncateText(message, TELEMETRY_LIMITS.message), clean(extra, 'log'), ctx);
|
|
211
|
+
},
|
|
212
|
+
metric: (name: string, value: number, tags?: Record<string, unknown>) => {
|
|
213
|
+
if (!sampled()) return;
|
|
214
|
+
p.telemetry?.metric(name, value, clean(tags, 'metric'), ctx);
|
|
215
|
+
},
|
|
216
|
+
// Erreurs et santé ne sont jamais échantillonnées : on ne perd pas un signal de panne.
|
|
217
|
+
error: (e: { name: string; message: string; stack?: string }, extra?: Record<string, unknown>) => {
|
|
218
|
+
const err = { name: truncateText(e.name, 100), message: truncateText(e.message, TELEMETRY_LIMITS.message), ...(e.stack !== undefined ? { stack: truncateText(e.stack, TELEMETRY_LIMITS.stack) } : {}) };
|
|
219
|
+
const data = clean(extra, 'error');
|
|
220
|
+
if (p.telemetry?.error) p.telemetry.error(err, data, ctx);
|
|
221
|
+
else p.telemetry?.log('error', `${err.name}: ${err.message}`, { errorType: err.name, ...(err.stack ? { stack: err.stack } : {}), ...(data ?? {}) }, ctx);
|
|
222
|
+
},
|
|
223
|
+
trace: (name: string, durationMs: number, ok: boolean, extra?: Record<string, unknown>) => {
|
|
224
|
+
if (!sampled()) return;
|
|
225
|
+
const data = clean(extra, 'trace');
|
|
226
|
+
if (p.telemetry?.trace) p.telemetry.trace(name, durationMs, ok, data, ctx);
|
|
227
|
+
else p.telemetry?.metric(`trace.${name}`, durationMs, { ok, ...(data ?? {}) }, ctx);
|
|
228
|
+
},
|
|
229
|
+
health: (status: 'ok' | 'degraded' | 'failing', detail?: string) => {
|
|
230
|
+
const d = detail === undefined ? undefined : truncateText(detail, TELEMETRY_LIMITS.detail);
|
|
231
|
+
if (p.telemetry?.health) p.telemetry.health(status, d, ctx);
|
|
232
|
+
else p.telemetry?.log(status === 'ok' ? 'info' : status === 'degraded' ? 'warn' : 'error', `health: ${status}`, d === undefined ? undefined : { detail: d }, ctx);
|
|
233
|
+
},
|
|
189
234
|
};
|
|
190
235
|
}
|
|
191
236
|
if (cfgOf.has('navigation')) {
|
|
@@ -244,9 +289,41 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
|
|
|
244
289
|
}
|
|
245
290
|
};
|
|
246
291
|
|
|
292
|
+
const audit = (e: Parameters<NonNullable<HostProviders['audit']>>[0]) => {
|
|
293
|
+
try {
|
|
294
|
+
p.audit?.(e);
|
|
295
|
+
} catch {
|
|
296
|
+
/* l'audit n'interrompt jamais un appel */
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
if (p.audit) {
|
|
300
|
+
// Chaque méthode servie est enveloppée : qui (module), quoi (capacité.méthode), résultat, durée — jamais les arguments.
|
|
301
|
+
for (const [capability, methods] of Object.entries(table)) {
|
|
302
|
+
for (const [method, fn] of Object.entries(methods)) {
|
|
303
|
+
methods[method] = async (...args: unknown[]) => {
|
|
304
|
+
const ts = Date.now();
|
|
305
|
+
let outcome: AuditOutcome = 'ok';
|
|
306
|
+
try {
|
|
307
|
+
return await fn(...args);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
outcome = e instanceof EmbedError ? e.code : 'INTERNAL';
|
|
310
|
+
throw e;
|
|
311
|
+
} finally {
|
|
312
|
+
audit({ kind: 'call', moduleName: o.moduleName, ts, capability, method, outcome, durationMs: Date.now() - ts });
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const auditedSubscribe: SubscribeHandler = (cap, ev, emit) => {
|
|
319
|
+
const off = subscribe(cap, ev, emit);
|
|
320
|
+
audit({ kind: 'subscribe', moduleName: o.moduleName, ts: Date.now(), capability: cap, outcome: off ? 'ok' : 'DENIED' });
|
|
321
|
+
return off;
|
|
322
|
+
};
|
|
323
|
+
|
|
247
324
|
return {
|
|
248
325
|
table,
|
|
249
|
-
subscribe,
|
|
326
|
+
subscribe: p.audit ? auditedSubscribe : subscribe,
|
|
250
327
|
};
|
|
251
328
|
}
|
|
252
329
|
|