@egen-civitas/esm-embed-host 0.7.0 → 0.9.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 +29 -0
- package/dist/host.d.ts +12 -3
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +197 -11
- package/dist/table.d.ts +9 -2
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +97 -6
- package/package.json +3 -3
- package/src/host.ts +76 -8
- package/src/table.ts +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @egen-civitas/esm-embed-host
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- bd63b5d: Cycle de vie (B5), additif : état commun (`connecting`, `ready`, `active`, `hidden`, `closing`, `closed`, `failed`, `standalone`), `lifecycle.onBeforeLeave` (plusieurs gardes, un garde défaillant ne bloque jamais), `onClosing` (≤ 2 s, au mieux en iframe), `onError`, `onStateChange`, alias `onVisibilityChange`/`onFocusChange` ; nouvelle méthode hôte → app `lifecycle.closing` et `host.close()` (fermeture ordonnée) ; `connect({ onDiagnostic })` et `app.state` dans le SDK ; visibilité locale en mode autonome.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [bd63b5d]
|
|
12
|
+
- @egen-civitas/esm-embed-protocol@0.9.0
|
|
13
|
+
|
|
14
|
+
## 0.8.0
|
|
15
|
+
|
|
16
|
+
### Minor Changes
|
|
17
|
+
|
|
18
|
+
- 177a545: Navigation étendue (B4), additive : `navigate(to, options)` renvoie `{ status: 'done' | 'blocked' }` (replace, newTab, query, hash, relativeTo), nouvelles méthodes `current`, `exists`, `back`, `canGoBack`, `intent`, `link` ; l'hôte sert `current`/`back`/`canGoBack` par défaut et `exists`/`intent` via `routeExists`/`intents` ; garde de sortie (`canLeave`) avant de quitter l'app ; code `NOT_FOUND` sur route ou intent inconnu. Un Shell plus ancien répond `UNKNOWN_METHOD` pour les nouvelles méthodes.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [177a545]
|
|
23
|
+
- @egen-civitas/esm-embed-protocol@0.8.0
|
|
24
|
+
|
|
25
|
+
## 0.7.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [d74087b]
|
|
30
|
+
- @egen-civitas/esm-embed-protocol@0.7.0
|
|
31
|
+
|
|
3
32
|
## 0.7.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
package/dist/host.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
|
|
1
|
+
import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits, type NavigateOptions } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
import { HostConnection } from './connection.js';
|
|
3
3
|
import { type NavigationOptions } from './navigation.js';
|
|
4
4
|
import type { HostProviders } from './providers.js';
|
|
@@ -21,8 +21,12 @@ export interface EmbedHostOptions {
|
|
|
21
21
|
minHeight?: number;
|
|
22
22
|
/** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
|
|
23
23
|
navigation?: NavigationOptions;
|
|
24
|
-
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
|
|
25
|
-
onNavigate?: (to: string) => void;
|
|
24
|
+
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`, ou `replaceState` si `options.replace`). */
|
|
25
|
+
onNavigate?: (to: string, options?: NavigateOptions) => void;
|
|
26
|
+
/** Table des routes du Shell : `navigation.exists` et `NOT_FOUND` sur `navigate`. Absente : `exists` non servie. */
|
|
27
|
+
routeExists?: (path: string) => boolean | Promise<boolean>;
|
|
28
|
+
/** Correspondance d'intents (`objet-action`) → chemin du Shell, gouvernée par l'opérateur. `null` : intent inconnu (`NOT_FOUND`). */
|
|
29
|
+
intents?: (slug: string, params: Record<string, unknown>) => string | null | Promise<string | null>;
|
|
26
30
|
/** Où écrire les diagnostics de poignée de main (défaut : `console`). */
|
|
27
31
|
logger?: Pick<Console, 'warn'>;
|
|
28
32
|
/**
|
|
@@ -44,6 +48,11 @@ export interface EmbedHost {
|
|
|
44
48
|
mount(container: Element): void;
|
|
45
49
|
/** L'app accepte-t-elle qu'on la quitte ? `true` si non connectée, sans réponse, ou en cas d'erreur (on ne piège jamais l'utilisateur). */
|
|
46
50
|
canLeave(timeoutMs?: number): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Fermeture ordonnée : laisse à l'app `lifecycle.closing` (≤ `timeoutMs`, défaut 2 s) pour nettoyer, puis détruit l'hôte.
|
|
53
|
+
* Au mieux — une app muette ou plus ancienne n'empêche jamais la fermeture. `destroy()` reste la fermeture immédiate.
|
|
54
|
+
*/
|
|
55
|
+
close(timeoutMs?: number): Promise<void>;
|
|
47
56
|
destroy(): void;
|
|
48
57
|
}
|
|
49
58
|
/**
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2F,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,YAAY,EAAE,KAAK,MAAM,EAAE,KAAK,eAAe,EAAyC,MAAM,kCAAkC,CAAC;AAE7S,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAwH,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/K,OAAO,KAAK,EAA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,iBAAiB,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IAC3E,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,KAAK,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,2IAA2I;IAC3I,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C;;;OAGG;IACH,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,IAAI,IAAI,CAAC;CACjB;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAwOjE"}
|
package/dist/host.js
CHANGED
|
@@ -203,7 +203,7 @@ function _ts_generator(thisArg, body) {
|
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
-
import { EGEN_EMBED_PROTOCOL, parseEnvelope, sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
|
|
206
|
+
import { EGEN_EMBED_PROTOCOL, EmbedError, buildInternalHref, parseEnvelope, sanitizeIframeRights } from '@egen-civitas/esm-embed-protocol';
|
|
207
207
|
import { createBus } from './bus.js';
|
|
208
208
|
import { HostConnection } from './connection.js';
|
|
209
209
|
import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath } from './navigation.js';
|
|
@@ -272,19 +272,155 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
|
|
|
272
272
|
lastCorePath = corePath;
|
|
273
273
|
win.history[(o === null || o === void 0 ? void 0 : o.replace) ? 'replaceState' : 'pushState'](win.history.state, '', buildCoreUrl(spaBase(), nav.route, corePath));
|
|
274
274
|
};
|
|
275
|
-
var
|
|
275
|
+
/** `navigate` / `intent` : résolution du chemin, existence, garde de sortie, puis exécution. */ var performNavigate = function performNavigate(to, options) {
|
|
276
|
+
return _async_to_generator(function() {
|
|
277
|
+
var _opts_onNavigate, target, corePath, href, pathOnly, _tmp, staying, _tmp1, go;
|
|
278
|
+
return _ts_generator(this, function(_state) {
|
|
279
|
+
switch(_state.label){
|
|
280
|
+
case 0:
|
|
281
|
+
target = to;
|
|
282
|
+
if ((options === null || options === void 0 ? void 0 : options.relativeTo) === 'app') {
|
|
283
|
+
corePath = nav ? toCorePath(to, nav) : null;
|
|
284
|
+
if (!nav || !corePath) return [
|
|
285
|
+
2,
|
|
286
|
+
{
|
|
287
|
+
status: 'blocked',
|
|
288
|
+
reason: 'forbidden-by-shell'
|
|
289
|
+
}
|
|
290
|
+
];
|
|
291
|
+
target = '/' + buildCoreUrl(spaBase(), nav.route, corePath).slice(spaBase().length).replace(/^\//, '');
|
|
292
|
+
}
|
|
293
|
+
if (normalizeAppPath(target) === null) return [
|
|
294
|
+
2,
|
|
295
|
+
{
|
|
296
|
+
status: 'blocked',
|
|
297
|
+
reason: 'forbidden-by-shell'
|
|
298
|
+
}
|
|
299
|
+
];
|
|
300
|
+
href = options && (options.query || options.hash) ? buildInternalHref(target, {
|
|
301
|
+
query: options.query,
|
|
302
|
+
hash: options.hash
|
|
303
|
+
}) : target;
|
|
304
|
+
pathOnly = href.split(/[?#]/, 1)[0];
|
|
305
|
+
_tmp = opts.routeExists;
|
|
306
|
+
if (!_tmp) return [
|
|
307
|
+
3,
|
|
308
|
+
2
|
|
309
|
+
];
|
|
310
|
+
return [
|
|
311
|
+
4,
|
|
312
|
+
opts.routeExists(pathOnly)
|
|
313
|
+
];
|
|
314
|
+
case 1:
|
|
315
|
+
_tmp = !_state.sent();
|
|
316
|
+
_state.label = 2;
|
|
317
|
+
case 2:
|
|
318
|
+
if (_tmp) throw new EmbedError('NOT_FOUND', "Route inconnue : ".concat(pathOnly));
|
|
319
|
+
if ((options === null || options === void 0 ? void 0 : options.target) === 'newTab') {
|
|
320
|
+
win.open(spaBase() + href.replace(/^\//, ''), '_blank', 'noopener,noreferrer');
|
|
321
|
+
return [
|
|
322
|
+
2,
|
|
323
|
+
{
|
|
324
|
+
status: 'done',
|
|
325
|
+
path: href
|
|
326
|
+
}
|
|
327
|
+
];
|
|
328
|
+
}
|
|
329
|
+
staying = (options === null || options === void 0 ? void 0 : options.relativeTo) === 'app' || !!nav && coreSubpath(spaBase() + pathOnly.replace(/^\//, ''), spaBase(), nav.route) !== null;
|
|
330
|
+
_tmp1 = !staying;
|
|
331
|
+
if (!_tmp1) return [
|
|
332
|
+
3,
|
|
333
|
+
4
|
|
334
|
+
];
|
|
335
|
+
return [
|
|
336
|
+
4,
|
|
337
|
+
api.canLeave()
|
|
338
|
+
];
|
|
339
|
+
case 3:
|
|
340
|
+
_tmp1 = !_state.sent();
|
|
341
|
+
_state.label = 4;
|
|
342
|
+
case 4:
|
|
343
|
+
if (_tmp1) return [
|
|
344
|
+
2,
|
|
345
|
+
{
|
|
346
|
+
status: 'blocked',
|
|
347
|
+
reason: 'dirty-declined'
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
go = (_opts_onNavigate = opts.onNavigate) !== null && _opts_onNavigate !== void 0 ? _opts_onNavigate : function(t, o) {
|
|
351
|
+
var _win_singleSpaNavigate;
|
|
352
|
+
if (o === null || o === void 0 ? void 0 : o.replace) {
|
|
353
|
+
win.history.replaceState(win.history.state, '', spaBase() + t.replace(/^\//, ''));
|
|
354
|
+
win.dispatchEvent(new PopStateEvent('popstate'));
|
|
355
|
+
} else (_win_singleSpaNavigate = win.singleSpaNavigate) === null || _win_singleSpaNavigate === void 0 ? void 0 : _win_singleSpaNavigate.call(win, spaBase() + t.replace(/^\//, ''));
|
|
356
|
+
};
|
|
357
|
+
if (options === null || options === void 0 ? void 0 : options.replace) go(href, options);
|
|
358
|
+
else go(href);
|
|
359
|
+
return [
|
|
360
|
+
2,
|
|
361
|
+
{
|
|
362
|
+
status: 'done',
|
|
363
|
+
path: href
|
|
364
|
+
}
|
|
365
|
+
];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
})();
|
|
369
|
+
};
|
|
370
|
+
var controls = _object_spread_props(_object_spread(_object_spread_props(_object_spread({
|
|
276
371
|
channel: channel,
|
|
277
372
|
report: function report(path, o) {
|
|
278
373
|
return reportLocation(path, o);
|
|
279
374
|
},
|
|
280
|
-
navigate: function navigate(to) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
375
|
+
navigate: function navigate(to, options) {
|
|
376
|
+
return performNavigate(to, options);
|
|
377
|
+
}
|
|
378
|
+
}, nav ? {
|
|
379
|
+
current: function current() {
|
|
380
|
+
var _toAppPath;
|
|
381
|
+
var u = new URL((_toAppPath = toAppPath(lastCorePath, nav)) !== null && _toAppPath !== void 0 ? _toAppPath : '/', 'http://app.invalid');
|
|
382
|
+
return {
|
|
383
|
+
path: u.pathname,
|
|
384
|
+
query: Object.fromEntries(u.searchParams),
|
|
385
|
+
hash: u.hash,
|
|
386
|
+
app: opts.moduleName,
|
|
387
|
+
title: iframe.title
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
} : {}, opts.routeExists ? {
|
|
391
|
+
exists: function exists(path) {
|
|
392
|
+
return !!opts.routeExists(path);
|
|
393
|
+
}
|
|
394
|
+
} : {}), {
|
|
395
|
+
back: function back() {
|
|
396
|
+
return void win.history.back();
|
|
287
397
|
},
|
|
398
|
+
canGoBack: function canGoBack() {
|
|
399
|
+
return win.history.length > 1;
|
|
400
|
+
}
|
|
401
|
+
}), opts.intents ? {
|
|
402
|
+
intent: function intent(slug, params, options) {
|
|
403
|
+
return _async_to_generator(function() {
|
|
404
|
+
var target;
|
|
405
|
+
return _ts_generator(this, function(_state) {
|
|
406
|
+
switch(_state.label){
|
|
407
|
+
case 0:
|
|
408
|
+
return [
|
|
409
|
+
4,
|
|
410
|
+
opts.intents(slug, params !== null && params !== void 0 ? params : {})
|
|
411
|
+
];
|
|
412
|
+
case 1:
|
|
413
|
+
target = _state.sent();
|
|
414
|
+
if (target === null || normalizeAppPath(target) === null) throw new EmbedError('NOT_FOUND', "Intent inconnu : ".concat(slug));
|
|
415
|
+
return [
|
|
416
|
+
2,
|
|
417
|
+
performNavigate(target, options)
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
})();
|
|
422
|
+
}
|
|
423
|
+
} : {}), {
|
|
288
424
|
notFound: function notFound(path) {
|
|
289
425
|
if (!opts.onNotFound || !allowLocation()) return;
|
|
290
426
|
var normalized = path === undefined ? null : normalizeAppPath(path);
|
|
@@ -299,7 +435,7 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
|
|
|
299
435
|
resize: function resize(h) {
|
|
300
436
|
if (Number.isFinite(h) && h >= 0) iframe.style.height = "".concat(Math.min(Math.ceil(h), 100000), "px");
|
|
301
437
|
}
|
|
302
|
-
};
|
|
438
|
+
});
|
|
303
439
|
var connection = new HostConnection({
|
|
304
440
|
moduleName: opts.moduleName,
|
|
305
441
|
grants: opts.grants,
|
|
@@ -334,7 +470,7 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
|
|
|
334
470
|
warnOnce("name:".concat(envelope.moduleName), "[egen-embed] message ignor\xe9 : l'app s'annonce \xab ".concat(envelope.moduleName, " \xbb mais le Core attend \xab ").concat(opts.moduleName, " \xbb. ") + "La d\xe9claration verrouill\xe9e c\xf4t\xe9 Core est p\xe9rim\xe9e, ou l'app utilise un autre nom que celui de son egen-config.json : " + "relancer \xab yarn external:sync \xbb apr\xe8s tout changement de d\xe9claration.");
|
|
335
471
|
}
|
|
336
472
|
};
|
|
337
|
-
|
|
473
|
+
var api = {
|
|
338
474
|
iframe: iframe,
|
|
339
475
|
connection: connection,
|
|
340
476
|
mount: function mount(container) {
|
|
@@ -436,10 +572,60 @@ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensi
|
|
|
436
572
|
});
|
|
437
573
|
})();
|
|
438
574
|
},
|
|
575
|
+
close: function close() {
|
|
576
|
+
var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 2000;
|
|
577
|
+
return _async_to_generator(function() {
|
|
578
|
+
var unused;
|
|
579
|
+
return _ts_generator(this, function(_state) {
|
|
580
|
+
switch(_state.label){
|
|
581
|
+
case 0:
|
|
582
|
+
if (!connection.connected) return [
|
|
583
|
+
3,
|
|
584
|
+
4
|
|
585
|
+
];
|
|
586
|
+
_state.label = 1;
|
|
587
|
+
case 1:
|
|
588
|
+
_state.trys.push([
|
|
589
|
+
1,
|
|
590
|
+
3,
|
|
591
|
+
,
|
|
592
|
+
4
|
|
593
|
+
]);
|
|
594
|
+
return [
|
|
595
|
+
4,
|
|
596
|
+
Promise.race([
|
|
597
|
+
connection.callApp('lifecycle', 'closing'),
|
|
598
|
+
new Promise(function(res) {
|
|
599
|
+
return setTimeout(res, timeoutMs);
|
|
600
|
+
})
|
|
601
|
+
])
|
|
602
|
+
];
|
|
603
|
+
case 2:
|
|
604
|
+
_state.sent();
|
|
605
|
+
return [
|
|
606
|
+
3,
|
|
607
|
+
4
|
|
608
|
+
];
|
|
609
|
+
case 3:
|
|
610
|
+
unused = _state.sent();
|
|
611
|
+
return [
|
|
612
|
+
3,
|
|
613
|
+
4
|
|
614
|
+
];
|
|
615
|
+
case 4:
|
|
616
|
+
api.destroy();
|
|
617
|
+
return [
|
|
618
|
+
2
|
|
619
|
+
];
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
})();
|
|
623
|
+
},
|
|
439
624
|
destroy: function destroy() {
|
|
440
625
|
while(stop.length)stop.pop()();
|
|
441
626
|
connection.destroy();
|
|
442
627
|
iframe.remove();
|
|
443
628
|
}
|
|
444
629
|
};
|
|
630
|
+
return api;
|
|
445
631
|
}
|
package/dist/table.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CapabilityGranted, type CapabilityId, type HandlerTable, type SubscribeHandler } from '@egen-civitas/esm-embed-protocol';
|
|
1
|
+
import { type CapabilityGranted, type CapabilityId, type HandlerTable, type NavigateOptions, type NavigationResult, type RouteInfo, type SubscribeHandler } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
import type { Bus } from './bus.js';
|
|
3
3
|
import type { HostProviders } from './providers.js';
|
|
4
4
|
/** Actions du Shell pilotées par les capacités `navigation` et `lifecycle`. */
|
|
@@ -7,7 +7,14 @@ export interface HostControls {
|
|
|
7
7
|
replace?: boolean;
|
|
8
8
|
title?: string;
|
|
9
9
|
}): void;
|
|
10
|
-
|
|
10
|
+
/** Navigation demandée par l'app. Sans résultat renvoyé, l'hôte répond `{ status: 'done' }`. */
|
|
11
|
+
navigate?(to: string, options?: NavigateOptions): NavigationResult | void | Promise<NavigationResult | void>;
|
|
12
|
+
/** Lecture/gardes de navigation (B4) : servies seulement si fournies ; sinon `UNKNOWN_METHOD` côté app. */
|
|
13
|
+
current?(): RouteInfo | Promise<RouteInfo>;
|
|
14
|
+
exists?(path: string): boolean | Promise<boolean>;
|
|
15
|
+
back?(result?: unknown): void | Promise<void>;
|
|
16
|
+
canGoBack?(): boolean | Promise<boolean>;
|
|
17
|
+
intent?(slug: string, params?: Record<string, unknown>, options?: NavigateOptions): NavigationResult | Promise<NavigationResult>;
|
|
11
18
|
/** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
|
|
12
19
|
notFound?(path?: string): void;
|
|
13
20
|
setTitle?(title: 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,EAOL,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAEjB,KAA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|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
38
51
|
function _iterable_to_array_limit(arr, i) {
|
|
39
52
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
40
53
|
if (_i == null) return;
|
|
@@ -62,6 +75,45 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
62
75
|
function _non_iterable_rest() {
|
|
63
76
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
77
|
}
|
|
78
|
+
function _object_spread(target) {
|
|
79
|
+
for(var i = 1; i < arguments.length; i++){
|
|
80
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
|
+
var ownKeys = Object.keys(source);
|
|
82
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
84
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
ownKeys.forEach(function(key) {
|
|
88
|
+
_define_property(target, key, source[key]);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
function ownKeys(object, enumerableOnly) {
|
|
94
|
+
var keys = Object.keys(object);
|
|
95
|
+
if (Object.getOwnPropertySymbols) {
|
|
96
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
97
|
+
if (enumerableOnly) {
|
|
98
|
+
symbols = symbols.filter(function(sym) {
|
|
99
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
keys.push.apply(keys, symbols);
|
|
103
|
+
}
|
|
104
|
+
return keys;
|
|
105
|
+
}
|
|
106
|
+
function _object_spread_props(target, source) {
|
|
107
|
+
source = source != null ? source : {};
|
|
108
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
109
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
110
|
+
} else {
|
|
111
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
112
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return target;
|
|
116
|
+
}
|
|
65
117
|
function _sliced_to_array(arr, i) {
|
|
66
118
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
67
119
|
}
|
|
@@ -402,15 +454,54 @@ var list = function list(cfg, key) {
|
|
|
402
454
|
};
|
|
403
455
|
}
|
|
404
456
|
if (cfgOf.has('navigation')) {
|
|
405
|
-
table.navigation = {
|
|
457
|
+
table.navigation = _object_spread_props(_object_spread({
|
|
406
458
|
report: function report(path, opts) {
|
|
407
459
|
var _c_report;
|
|
408
460
|
return (_c_report = c.report) === null || _c_report === void 0 ? void 0 : _c_report.call(c, path, opts);
|
|
409
461
|
},
|
|
410
|
-
navigate: function navigate(to) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
462
|
+
navigate: function navigate(to, options) {
|
|
463
|
+
return _async_to_generator(function() {
|
|
464
|
+
var _ref, _c_navigate;
|
|
465
|
+
return _ts_generator(this, function(_state) {
|
|
466
|
+
switch(_state.label){
|
|
467
|
+
case 0:
|
|
468
|
+
return [
|
|
469
|
+
4,
|
|
470
|
+
(_c_navigate = c.navigate) === null || _c_navigate === void 0 ? void 0 : _c_navigate.call(c, to, options)
|
|
471
|
+
];
|
|
472
|
+
case 1:
|
|
473
|
+
return [
|
|
474
|
+
2,
|
|
475
|
+
(_ref = _state.sent()) !== null && _ref !== void 0 ? _ref : {
|
|
476
|
+
status: 'done',
|
|
477
|
+
path: to
|
|
478
|
+
}
|
|
479
|
+
];
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
})();
|
|
483
|
+
}
|
|
484
|
+
}, c.current ? {
|
|
485
|
+
current: function current() {
|
|
486
|
+
return c.current();
|
|
487
|
+
}
|
|
488
|
+
} : {}, c.exists ? {
|
|
489
|
+
exists: function exists(path) {
|
|
490
|
+
return c.exists(path);
|
|
491
|
+
}
|
|
492
|
+
} : {}, c.back ? {
|
|
493
|
+
back: function back(result) {
|
|
494
|
+
return c.back(result);
|
|
495
|
+
}
|
|
496
|
+
} : {}, c.canGoBack ? {
|
|
497
|
+
canGoBack: function canGoBack() {
|
|
498
|
+
return c.canGoBack();
|
|
499
|
+
}
|
|
500
|
+
} : {}, c.intent ? {
|
|
501
|
+
intent: function intent(slug, params, options) {
|
|
502
|
+
return c.intent(slug, params, options);
|
|
503
|
+
}
|
|
504
|
+
} : {}), {
|
|
414
505
|
notFound: function notFound(path) {
|
|
415
506
|
var _c_notFound;
|
|
416
507
|
return (_c_notFound = c.notFound) === null || _c_notFound === void 0 ? void 0 : _c_notFound.call(c, path);
|
|
@@ -423,7 +514,7 @@ var list = function list(cfg, key) {
|
|
|
423
514
|
var _c_resize;
|
|
424
515
|
return (_c_resize = c.resize) === null || _c_resize === void 0 ? void 0 : _c_resize.call(c, h);
|
|
425
516
|
}
|
|
426
|
-
};
|
|
517
|
+
});
|
|
427
518
|
}
|
|
428
519
|
if (cfgOf.has('lifecycle')) table.lifecycle = {
|
|
429
520
|
ready: function ready() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egen-civitas/esm-embed-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.10.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.9.0"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/host.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EGEN_EMBED_PROTOCOL, parseEnvelope, sanitizeIframeRights, type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits } from '@egen-civitas/esm-embed-protocol';
|
|
1
|
+
import { EGEN_EMBED_PROTOCOL, EmbedError, buildInternalHref, parseEnvelope, sanitizeIframeRights, type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type IframeRights, type Limits, type NavigateOptions, type NavigationResult, type RouteInfo } from '@egen-civitas/esm-embed-protocol';
|
|
2
2
|
import { createBus } from './bus.js';
|
|
3
3
|
import { HostConnection } from './connection.js';
|
|
4
4
|
import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath, type NavigationOptions } from './navigation.js';
|
|
@@ -24,8 +24,12 @@ export interface EmbedHostOptions {
|
|
|
24
24
|
minHeight?: number;
|
|
25
25
|
/** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
|
|
26
26
|
navigation?: NavigationOptions;
|
|
27
|
-
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
|
|
28
|
-
onNavigate?: (to: string) => void;
|
|
27
|
+
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`, ou `replaceState` si `options.replace`). */
|
|
28
|
+
onNavigate?: (to: string, options?: NavigateOptions) => void;
|
|
29
|
+
/** Table des routes du Shell : `navigation.exists` et `NOT_FOUND` sur `navigate`. Absente : `exists` non servie. */
|
|
30
|
+
routeExists?: (path: string) => boolean | Promise<boolean>;
|
|
31
|
+
/** Correspondance d'intents (`objet-action`) → chemin du Shell, gouvernée par l'opérateur. `null` : intent inconnu (`NOT_FOUND`). */
|
|
32
|
+
intents?: (slug: string, params: Record<string, unknown>) => string | null | Promise<string | null>;
|
|
29
33
|
/** Où écrire les diagnostics de poignée de main (défaut : `console`). */
|
|
30
34
|
logger?: Pick<Console, 'warn'>;
|
|
31
35
|
/**
|
|
@@ -46,6 +50,11 @@ export interface EmbedHost {
|
|
|
46
50
|
mount(container: Element): void;
|
|
47
51
|
/** L'app accepte-t-elle qu'on la quitte ? `true` si non connectée, sans réponse, ou en cas d'erreur (on ne piège jamais l'utilisateur). */
|
|
48
52
|
canLeave(timeoutMs?: number): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Fermeture ordonnée : laisse à l'app `lifecycle.closing` (≤ `timeoutMs`, défaut 2 s) pour nettoyer, puis détruit l'hôte.
|
|
55
|
+
* Au mieux — une app muette ou plus ancienne n'empêche jamais la fermeture. `destroy()` reste la fermeture immédiate.
|
|
56
|
+
*/
|
|
57
|
+
close(timeoutMs?: number): Promise<void>;
|
|
49
58
|
destroy(): void;
|
|
50
59
|
}
|
|
51
60
|
|
|
@@ -107,13 +116,61 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
107
116
|
win.history[o?.replace ? 'replaceState' : 'pushState'](win.history.state, '', buildCoreUrl(spaBase(), nav.route, corePath));
|
|
108
117
|
};
|
|
109
118
|
|
|
119
|
+
/** `navigate` / `intent` : résolution du chemin, existence, garde de sortie, puis exécution. */
|
|
120
|
+
const performNavigate = async (to: string, options?: NavigateOptions): Promise<NavigationResult> => {
|
|
121
|
+
let target = to;
|
|
122
|
+
if (options?.relativeTo === 'app') {
|
|
123
|
+
const corePath = nav ? toCorePath(to, nav) : null;
|
|
124
|
+
if (!nav || !corePath) return { status: 'blocked', reason: 'forbidden-by-shell' };
|
|
125
|
+
target = '/' + buildCoreUrl(spaBase(), nav.route, corePath).slice(spaBase().length).replace(/^\//, '');
|
|
126
|
+
}
|
|
127
|
+
if (normalizeAppPath(target) === null) return { status: 'blocked', reason: 'forbidden-by-shell' };
|
|
128
|
+
const href = options && (options.query || options.hash) ? buildInternalHref(target, { query: options.query, hash: options.hash }) : target;
|
|
129
|
+
const pathOnly = href.split(/[?#]/, 1)[0]!;
|
|
130
|
+
if (opts.routeExists && !(await opts.routeExists(pathOnly))) throw new EmbedError('NOT_FOUND', `Route inconnue : ${pathOnly}`);
|
|
131
|
+
if (options?.target === 'newTab') {
|
|
132
|
+
win.open(spaBase() + href.replace(/^\//, ''), '_blank', 'noopener,noreferrer');
|
|
133
|
+
return { status: 'done', path: href };
|
|
134
|
+
}
|
|
135
|
+
const staying = options?.relativeTo === 'app' || (!!nav && coreSubpath(spaBase() + pathOnly.replace(/^\//, ''), spaBase(), nav.route) !== null);
|
|
136
|
+
if (!staying && !(await api.canLeave())) return { status: 'blocked', reason: 'dirty-declined' };
|
|
137
|
+
const go =
|
|
138
|
+
opts.onNavigate ??
|
|
139
|
+
((t: string, o?: NavigateOptions) => {
|
|
140
|
+
if (o?.replace) {
|
|
141
|
+
win.history.replaceState(win.history.state, '', spaBase() + t.replace(/^\//, ''));
|
|
142
|
+
win.dispatchEvent(new PopStateEvent('popstate'));
|
|
143
|
+
} else (win as any).singleSpaNavigate?.(spaBase() + t.replace(/^\//, ''));
|
|
144
|
+
});
|
|
145
|
+
if (options?.replace) go(href, options);
|
|
146
|
+
else go(href);
|
|
147
|
+
return { status: 'done', path: href };
|
|
148
|
+
};
|
|
149
|
+
|
|
110
150
|
const controls: HostControls = {
|
|
111
151
|
channel,
|
|
112
152
|
report: (path, o) => reportLocation(path, o),
|
|
113
|
-
navigate: (to) =>
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
153
|
+
navigate: (to, options) => performNavigate(to, options),
|
|
154
|
+
...(nav
|
|
155
|
+
? {
|
|
156
|
+
current: (): RouteInfo => {
|
|
157
|
+
const u = new URL(toAppPath(lastCorePath, nav) ?? '/', 'http://app.invalid');
|
|
158
|
+
return { path: u.pathname, query: Object.fromEntries(u.searchParams), hash: u.hash, app: opts.moduleName, title: iframe.title };
|
|
159
|
+
},
|
|
160
|
+
}
|
|
161
|
+
: {}),
|
|
162
|
+
...(opts.routeExists ? { exists: (path: string) => !!opts.routeExists!(path) } : {}),
|
|
163
|
+
back: () => void win.history.back(),
|
|
164
|
+
canGoBack: () => win.history.length > 1,
|
|
165
|
+
...(opts.intents
|
|
166
|
+
? {
|
|
167
|
+
intent: async (slug: string, params?: Record<string, unknown>, options?: NavigateOptions): Promise<NavigationResult> => {
|
|
168
|
+
const target = await opts.intents!(slug, params ?? {});
|
|
169
|
+
if (target === null || normalizeAppPath(target) === null) throw new EmbedError('NOT_FOUND', `Intent inconnu : ${slug}`);
|
|
170
|
+
return performNavigate(target, options);
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
: {}),
|
|
117
174
|
notFound: (path) => {
|
|
118
175
|
if (!opts.onNotFound || !allowLocation()) return;
|
|
119
176
|
const normalized = path === undefined ? null : normalizeAppPath(path);
|
|
@@ -172,7 +229,7 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
172
229
|
}
|
|
173
230
|
};
|
|
174
231
|
|
|
175
|
-
|
|
232
|
+
const api: EmbedHost = {
|
|
176
233
|
iframe,
|
|
177
234
|
connection,
|
|
178
235
|
mount(container) {
|
|
@@ -224,10 +281,21 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
224
281
|
return true;
|
|
225
282
|
}
|
|
226
283
|
},
|
|
284
|
+
async close(timeoutMs = 2000) {
|
|
285
|
+
if (connection.connected) {
|
|
286
|
+
try {
|
|
287
|
+
await Promise.race([connection.callApp('lifecycle', 'closing'), new Promise<void>((res) => setTimeout(res, timeoutMs))]);
|
|
288
|
+
} catch {
|
|
289
|
+
/* app plus ancienne (UNKNOWN_METHOD), déjà fermée, en erreur : la fermeture continue */
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
api.destroy();
|
|
293
|
+
},
|
|
227
294
|
destroy() {
|
|
228
295
|
while (stop.length) stop.pop()!();
|
|
229
296
|
connection.destroy();
|
|
230
297
|
iframe.remove();
|
|
231
298
|
},
|
|
232
299
|
};
|
|
300
|
+
return api;
|
|
233
301
|
}
|
package/src/table.ts
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
type CapabilityId,
|
|
10
10
|
type GrantConfig,
|
|
11
11
|
type HandlerTable,
|
|
12
|
+
type NavigateOptions,
|
|
13
|
+
type NavigationResult,
|
|
14
|
+
type RouteInfo,
|
|
12
15
|
type SubscribeHandler,
|
|
13
16
|
} from '@egen-civitas/esm-embed-protocol';
|
|
14
17
|
import type { Bus } from './bus.js';
|
|
@@ -17,7 +20,14 @@ import type { CallerContext, HostProviders } from './providers.js';
|
|
|
17
20
|
/** Actions du Shell pilotées par les capacités `navigation` et `lifecycle`. */
|
|
18
21
|
export interface HostControls {
|
|
19
22
|
report?(path: string, opts?: { replace?: boolean; title?: string }): void;
|
|
20
|
-
|
|
23
|
+
/** Navigation demandée par l'app. Sans résultat renvoyé, l'hôte répond `{ status: 'done' }`. */
|
|
24
|
+
navigate?(to: string, options?: NavigateOptions): NavigationResult | void | Promise<NavigationResult | void>;
|
|
25
|
+
/** Lecture/gardes de navigation (B4) : servies seulement si fournies ; sinon `UNKNOWN_METHOD` côté app. */
|
|
26
|
+
current?(): RouteInfo | Promise<RouteInfo>;
|
|
27
|
+
exists?(path: string): boolean | Promise<boolean>;
|
|
28
|
+
back?(result?: unknown): void | Promise<void>;
|
|
29
|
+
canGoBack?(): boolean | Promise<boolean>;
|
|
30
|
+
intent?(slug: string, params?: Record<string, unknown>, options?: NavigateOptions): NavigationResult | Promise<NavigationResult>;
|
|
21
31
|
/** L'app signale une page introuvable (`path` : chemin de l'app, absent = page courante). */
|
|
22
32
|
notFound?(path?: string): void;
|
|
23
33
|
setTitle?(title: string): void;
|
|
@@ -117,7 +127,12 @@ export function createCapabilityTable(o: TableOptions): { table: HandlerTable; s
|
|
|
117
127
|
if (cfgOf.has('navigation')) {
|
|
118
128
|
table.navigation = {
|
|
119
129
|
report: (path: string, opts?: { replace?: boolean; title?: string }) => c.report?.(path, opts),
|
|
120
|
-
navigate: (to: string) => c.navigate?.(to),
|
|
130
|
+
navigate: async (to: string, options?: NavigateOptions): Promise<NavigationResult> => (await c.navigate?.(to, options)) ?? { status: 'done', path: to },
|
|
131
|
+
...(c.current ? { current: () => c.current!() } : {}),
|
|
132
|
+
...(c.exists ? { exists: (path: string) => c.exists!(path) } : {}),
|
|
133
|
+
...(c.back ? { back: (result?: unknown) => c.back!(result) } : {}),
|
|
134
|
+
...(c.canGoBack ? { canGoBack: () => c.canGoBack!() } : {}),
|
|
135
|
+
...(c.intent ? { intent: (slug: string, params?: Record<string, unknown>, options?: NavigateOptions) => c.intent!(slug, params, options) } : {}),
|
|
121
136
|
notFound: (path?: string) => c.notFound?.(path),
|
|
122
137
|
setTitle: (t: string) => c.setTitle?.(t),
|
|
123
138
|
resize: (h: number) => c.resize?.(h),
|