@egen-civitas/esm-embed-host 0.0.0-stage → 0.1.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 +14 -0
- package/README.md +31 -2
- package/dist/bus.d.ts +8 -0
- package/dist/bus.d.ts.map +1 -0
- package/dist/bus.js +64 -0
- package/dist/connection.d.ts +40 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +366 -0
- package/dist/host.d.ts +45 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +587 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/navigation.d.ts +51 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +153 -0
- package/dist/providers.d.ts +101 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +301 -0
- package/dist/table.d.ts +36 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +673 -0
- package/package.json +71 -3
- package/src/__tests__/harness.ts +42 -0
- package/src/bus.ts +28 -0
- package/src/connection.ts +132 -0
- package/src/host.ts +231 -0
- package/src/index.ts +6 -0
- package/src/navigation.ts +163 -0
- package/src/providers.ts +127 -0
- package/src/table.ts +199 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @egen-civitas/esm-embed-host
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 744cd20: Nouveau paquet `esm-embed-host` (iframe sécurisée, poignée de main v2, grants appliqués, fournisseurs, `createFetchApiProvider`, navigation partagée, compatibilité du pont 1.1). Protocole : `pickFields`, refus `UNAVAILABLE`, réponse trop volumineuse signalée à l'appelant.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [10f0584]
|
|
12
|
+
- Updated dependencies [744cd20]
|
|
13
|
+
- Updated dependencies [cf9d90d]
|
|
14
|
+
- @egen-civitas/esm-embed-protocol@0.1.0
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @egen-civitas/esm-embed-host
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Hôte (côté Shell/Core) des applications **embarquées** : iframe sécurisée, poignée de main v2, application des grants,
|
|
4
|
+
fournisseurs de capacités, navigation partagée Core ↔ app, et compatibilité du pont 1.1 (`esm-nextjs-utils`).
|
|
5
|
+
Spécification : `docs/integration-apps/17-sdk-embed-protocole-v2.md` du dépôt Core.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { effectiveGrants } from '@egen-civitas/esm-embed-protocol';
|
|
9
|
+
import { createEmbedHost, createFetchApiProvider } from '@egen-civitas/esm-embed-host';
|
|
10
|
+
|
|
11
|
+
const grants = effectiveGrants(manifest.capabilities, { theme: {}, notifications: {}, events: { publish: ['app.studio.*'] } });
|
|
12
|
+
|
|
13
|
+
const host = createEmbedHost({
|
|
14
|
+
moduleName: manifest.name,
|
|
15
|
+
src: manifest.url,
|
|
16
|
+
grants,
|
|
17
|
+
navigation: { route: manifest.route, mode: manifest.navigation.mode },
|
|
18
|
+
providers: {
|
|
19
|
+
session: { get, subscribe }, // services du Core
|
|
20
|
+
theme: { get, subscribe },
|
|
21
|
+
notifications: { show: (n, from) => toast(n) },
|
|
22
|
+
events: { publish: bus.publish, subscribe: bus.subscribe },
|
|
23
|
+
api: createFetchApiProvider({ baseUrl: API_URL, getHeaders: authHeaders }),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
host.mount(container); // …; host.destroy() au démontage
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **Moindre privilège** : la table d'appels de la connexion ne contient que les capacités accordées **et** servies. Une capacité accordée sans fournisseur est refusée (`UNAVAILABLE`).
|
|
30
|
+
- **Jamais de jeton ni de `sessionId`** : `session` est filtrée par liste blanche ; `api.fetch` s'exécute côté Core (`createFetchApiProvider`), sans cookies ni authentification vers les hôtes externes, sans redirection.
|
|
31
|
+
- **Pont 1.1** : une app qui ne parle pas le protocole 2 continue de fonctionner (`ready`, `location`, `navigate`, `resize`, `title`). Désactivable : `legacy: false`.
|
|
32
|
+
- `HostConnection` est indépendante du DOM (testable avec le vrai client, voir `src/__tests__/harness.ts`).
|
package/dist/bus.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Unsub } from './providers.js';
|
|
2
|
+
/** Bus interne hôte → app (navigation.goto, lifecycle.visibility/focus). */
|
|
3
|
+
export interface Bus {
|
|
4
|
+
on(name: string, cb: (v: unknown) => void): Unsub;
|
|
5
|
+
emit(name: string, value?: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export declare function createBus(): Bus;
|
|
8
|
+
//# sourceMappingURL=bus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bus.d.ts","sourceRoot":"","sources":["../src/bus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,4EAA4E;AAC5E,MAAM,WAAW,GAAG;IAClB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,GAAG,KAAK,CAAC;IAClD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC3C;AAED,wBAAgB,SAAS,IAAI,GAAG,CAmB/B"}
|
package/dist/bus.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function _iterable_to_array(iter) {
|
|
10
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
11
|
+
}
|
|
12
|
+
function _non_iterable_spread() {
|
|
13
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
14
|
+
}
|
|
15
|
+
function _to_consumable_array(arr) {
|
|
16
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
17
|
+
}
|
|
18
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
19
|
+
if (!o) return;
|
|
20
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
21
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
22
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
23
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
24
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
25
|
+
}
|
|
26
|
+
export function createBus() {
|
|
27
|
+
var map = new Map();
|
|
28
|
+
return {
|
|
29
|
+
on: function on(name, cb) {
|
|
30
|
+
var set = map.get(name);
|
|
31
|
+
if (!set) map.set(name, set = new Set());
|
|
32
|
+
set.add(cb);
|
|
33
|
+
return function() {
|
|
34
|
+
return set.delete(cb);
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
emit: function emit(name, value) {
|
|
38
|
+
var _map_get;
|
|
39
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
40
|
+
try {
|
|
41
|
+
for(var _iterator = _to_consumable_array((_map_get = map.get(name)) !== null && _map_get !== void 0 ? _map_get : [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
42
|
+
var cb = _step.value;
|
|
43
|
+
try {
|
|
44
|
+
cb(value);
|
|
45
|
+
} catch (unused) {
|
|
46
|
+
/* un abonné fautif ne doit pas bloquer les autres */ }
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
_didIteratorError = true;
|
|
50
|
+
_iteratorError = err;
|
|
51
|
+
} finally{
|
|
52
|
+
try {
|
|
53
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
54
|
+
_iterator.return();
|
|
55
|
+
}
|
|
56
|
+
} finally{
|
|
57
|
+
if (_didIteratorError) {
|
|
58
|
+
throw _iteratorError;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
import type { HostProviders } from './providers.js';
|
|
3
|
+
import { type HostControls } from './table.js';
|
|
4
|
+
export type ConnectionState = 'idle' | 'hello' | 'connected' | 'closed';
|
|
5
|
+
export interface ConnectionOptions {
|
|
6
|
+
moduleName: string;
|
|
7
|
+
grants: EffectiveGrants;
|
|
8
|
+
providers: HostProviders;
|
|
9
|
+
controls: HostControls;
|
|
10
|
+
/** Envoi vers l'iframe (l'origine cible explicite est fixée par l'appelant). */
|
|
11
|
+
post(message: unknown, transfer?: Transferable[]): void;
|
|
12
|
+
limits?: Partial<Limits>;
|
|
13
|
+
hostVersion?: string;
|
|
14
|
+
onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
|
|
15
|
+
onClose?(reason: string): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Connexion hôte ↔ une app embarquée, indépendante du DOM : l'appelant filtre déjà la source et l'origine
|
|
19
|
+
* (`event.source === iframe.contentWindow`, `event.origin === origine autorisée`) et lui remet `event.data`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class HostConnection {
|
|
22
|
+
private readonly o;
|
|
23
|
+
state: ConnectionState;
|
|
24
|
+
private nonce?;
|
|
25
|
+
private rpc?;
|
|
26
|
+
private cleanup?;
|
|
27
|
+
constructor(o: ConnectionOptions);
|
|
28
|
+
/** Nouvelle poignée de main (à chaque chargement de l'iframe) : ferme toute connexion précédente. */
|
|
29
|
+
hello(): void;
|
|
30
|
+
/** Traite un message de poignée de main v2 ; `true` si le message est de la famille v2 (consommé). */
|
|
31
|
+
handle(data: unknown): boolean;
|
|
32
|
+
private open;
|
|
33
|
+
/** Appel hôte → app (ex. `lifecycle.canLeave`) ; `undefined` si l'app n'est pas connectée en v2. */
|
|
34
|
+
callApp<T = unknown>(cap: string, method: string, args?: unknown[]): Promise<T | undefined>;
|
|
35
|
+
get connected(): boolean;
|
|
36
|
+
/** Ferme la connexion courante (rechargement de l'iframe) sans détruire l'objet. */
|
|
37
|
+
reset(): void;
|
|
38
|
+
destroy(): void;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,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;IAMb,OAAO,CAAC,QAAQ,CAAC,CAAC;IAL9B,KAAK,EAAE,eAAe,CAAU;IAChC,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,GAAG,CAAC,CAAc;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAa;gBAEA,CAAC,EAAE,iBAAiB;IAEjD,qGAAqG;IACrG,KAAK,IAAI,IAAI;IAOb,sGAAsG;IACtG,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO;IAe9B,OAAO,CAAC,IAAI;IAuCZ,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;IASb,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _class_call_check(instance, Constructor) {
|
|
39
|
+
if (!(instance instanceof Constructor)) {
|
|
40
|
+
throw new TypeError("Cannot call a class as a function");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function _defineProperties(target, props) {
|
|
44
|
+
for(var i = 0; i < props.length; i++){
|
|
45
|
+
var descriptor = props[i];
|
|
46
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
47
|
+
descriptor.configurable = true;
|
|
48
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
49
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
53
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
54
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
55
|
+
return Constructor;
|
|
56
|
+
}
|
|
57
|
+
function _define_property(obj, key, value) {
|
|
58
|
+
if (key in obj) {
|
|
59
|
+
Object.defineProperty(obj, key, {
|
|
60
|
+
value: value,
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
obj[key] = value;
|
|
67
|
+
}
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
function _iterable_to_array(iter) {
|
|
71
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
72
|
+
}
|
|
73
|
+
function _non_iterable_spread() {
|
|
74
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
75
|
+
}
|
|
76
|
+
function _to_consumable_array(arr) {
|
|
77
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
78
|
+
}
|
|
79
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
80
|
+
if (!o) return;
|
|
81
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
82
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
83
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
84
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
85
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
86
|
+
}
|
|
87
|
+
function _ts_generator(thisArg, body) {
|
|
88
|
+
var f, y, t, _ = {
|
|
89
|
+
label: 0,
|
|
90
|
+
sent: function() {
|
|
91
|
+
if (t[0] & 1) throw t[1];
|
|
92
|
+
return t[1];
|
|
93
|
+
},
|
|
94
|
+
trys: [],
|
|
95
|
+
ops: []
|
|
96
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
97
|
+
return d(g, "next", {
|
|
98
|
+
value: verb(0)
|
|
99
|
+
}), d(g, "throw", {
|
|
100
|
+
value: verb(1)
|
|
101
|
+
}), d(g, "return", {
|
|
102
|
+
value: verb(2)
|
|
103
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
104
|
+
value: function() {
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
}), g;
|
|
108
|
+
function verb(n) {
|
|
109
|
+
return function(v) {
|
|
110
|
+
return step([
|
|
111
|
+
n,
|
|
112
|
+
v
|
|
113
|
+
]);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function step(op) {
|
|
117
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
118
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
119
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
120
|
+
if (y = 0, t) op = [
|
|
121
|
+
op[0] & 2,
|
|
122
|
+
t.value
|
|
123
|
+
];
|
|
124
|
+
switch(op[0]){
|
|
125
|
+
case 0:
|
|
126
|
+
case 1:
|
|
127
|
+
t = op;
|
|
128
|
+
break;
|
|
129
|
+
case 4:
|
|
130
|
+
_.label++;
|
|
131
|
+
return {
|
|
132
|
+
value: op[1],
|
|
133
|
+
done: false
|
|
134
|
+
};
|
|
135
|
+
case 5:
|
|
136
|
+
_.label++;
|
|
137
|
+
y = op[1];
|
|
138
|
+
op = [
|
|
139
|
+
0
|
|
140
|
+
];
|
|
141
|
+
continue;
|
|
142
|
+
case 7:
|
|
143
|
+
op = _.ops.pop();
|
|
144
|
+
_.trys.pop();
|
|
145
|
+
continue;
|
|
146
|
+
default:
|
|
147
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
148
|
+
_ = 0;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
152
|
+
_.label = op[1];
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
156
|
+
_.label = t[1];
|
|
157
|
+
t = op;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
if (t && _.label < t[2]) {
|
|
161
|
+
_.label = t[2];
|
|
162
|
+
_.ops.push(op);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
if (t[2]) _.ops.pop();
|
|
166
|
+
_.trys.pop();
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
op = body.call(thisArg, _);
|
|
170
|
+
} catch (e) {
|
|
171
|
+
op = [
|
|
172
|
+
6,
|
|
173
|
+
e
|
|
174
|
+
];
|
|
175
|
+
y = 0;
|
|
176
|
+
} finally{
|
|
177
|
+
f = t = 0;
|
|
178
|
+
}
|
|
179
|
+
if (op[0] & 5) throw op[1];
|
|
180
|
+
return {
|
|
181
|
+
value: op[0] ? op[1] : void 0,
|
|
182
|
+
done: true
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
import { EGEN_EMBED_PROTOCOL, RpcEndpoint, createNonce, negotiateCapabilities, negotiateProtocol, parseConnect, parseEnvelope, validateCall, wrapHandshake } from '@egen-civitas/esm-embed-protocol';
|
|
187
|
+
import { availableCapabilities, createCapabilityTable } from './table.js';
|
|
188
|
+
/**
|
|
189
|
+
* Connexion hôte ↔ une app embarquée, indépendante du DOM : l'appelant filtre déjà la source et l'origine
|
|
190
|
+
* (`event.source === iframe.contentWindow`, `event.origin === origine autorisée`) et lui remet `event.data`.
|
|
191
|
+
*/ export var HostConnection = /*#__PURE__*/ function() {
|
|
192
|
+
"use strict";
|
|
193
|
+
function HostConnection(o) {
|
|
194
|
+
_class_call_check(this, HostConnection);
|
|
195
|
+
_define_property(this, "o", void 0);
|
|
196
|
+
_define_property(this, "state", void 0);
|
|
197
|
+
_define_property(this, "nonce", void 0);
|
|
198
|
+
_define_property(this, "rpc", void 0);
|
|
199
|
+
_define_property(this, "cleanup", void 0);
|
|
200
|
+
this.o = o;
|
|
201
|
+
this.state = 'idle';
|
|
202
|
+
}
|
|
203
|
+
_create_class(HostConnection, [
|
|
204
|
+
{
|
|
205
|
+
/** Nouvelle poignée de main (à chaque chargement de l'iframe) : ferme toute connexion précédente. */ key: "hello",
|
|
206
|
+
value: function hello() {
|
|
207
|
+
this.reset();
|
|
208
|
+
this.nonce = createNonce();
|
|
209
|
+
this.state = 'hello';
|
|
210
|
+
this.o.post(wrapHandshake(this.o.moduleName, {
|
|
211
|
+
kind: 'hello',
|
|
212
|
+
nonce: this.nonce,
|
|
213
|
+
protocols: [
|
|
214
|
+
EGEN_EMBED_PROTOCOL,
|
|
215
|
+
1
|
|
216
|
+
],
|
|
217
|
+
hostVersion: this.o.hostVersion
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
/** Traite un message de poignée de main v2 ; `true` si le message est de la famille v2 (consommé). */ key: "handle",
|
|
223
|
+
value: function handle(data) {
|
|
224
|
+
var env = parseEnvelope(data);
|
|
225
|
+
if (!env || env.egen !== EGEN_EMBED_PROTOCOL || env.moduleName !== this.o.moduleName) return false;
|
|
226
|
+
var m = env.message;
|
|
227
|
+
if (m.kind === 'probe') {
|
|
228
|
+
if (this.state === 'idle') this.hello();
|
|
229
|
+
else if (this.state === 'hello' && this.nonce) this.o.post(wrapHandshake(this.o.moduleName, {
|
|
230
|
+
kind: 'hello',
|
|
231
|
+
nonce: this.nonce,
|
|
232
|
+
protocols: [
|
|
233
|
+
EGEN_EMBED_PROTOCOL,
|
|
234
|
+
1
|
|
235
|
+
],
|
|
236
|
+
hostVersion: this.o.hostVersion
|
|
237
|
+
}));
|
|
238
|
+
} else if (m.kind === 'connect' && this.state === 'hello') {
|
|
239
|
+
var c = parseConnect(m);
|
|
240
|
+
if (!c || c.nonce !== this.nonce || negotiateProtocol(c.protocol, [
|
|
241
|
+
EGEN_EMBED_PROTOCOL
|
|
242
|
+
]) === null) return true;
|
|
243
|
+
this.open(c.requested);
|
|
244
|
+
}
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
key: "open",
|
|
250
|
+
value: function open(requested) {
|
|
251
|
+
var _this = this;
|
|
252
|
+
var _this_o_onConnect, _this_o;
|
|
253
|
+
var avail = availableCapabilities(this.o.providers);
|
|
254
|
+
var _negotiateCapabilities = negotiateCapabilities(requested, this.o.grants), g0 = _negotiateCapabilities.granted, d0 = _negotiateCapabilities.denied;
|
|
255
|
+
var denied = _to_consumable_array(d0);
|
|
256
|
+
var granted = [];
|
|
257
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
258
|
+
try {
|
|
259
|
+
for(var _iterator = g0[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
260
|
+
var g = _step.value;
|
|
261
|
+
if (avail.has(g.id)) granted.push(g);
|
|
262
|
+
else denied.push({
|
|
263
|
+
id: g.id,
|
|
264
|
+
reason: 'UNAVAILABLE'
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
} catch (err) {
|
|
268
|
+
_didIteratorError = true;
|
|
269
|
+
_iteratorError = err;
|
|
270
|
+
} finally{
|
|
271
|
+
try {
|
|
272
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
273
|
+
_iterator.return();
|
|
274
|
+
}
|
|
275
|
+
} finally{
|
|
276
|
+
if (_didIteratorError) {
|
|
277
|
+
throw _iteratorError;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
var _createCapabilityTable = createCapabilityTable({
|
|
282
|
+
moduleName: this.o.moduleName,
|
|
283
|
+
granted: granted,
|
|
284
|
+
providers: this.o.providers,
|
|
285
|
+
controls: this.o.controls,
|
|
286
|
+
callApp: function callApp(cap, method, args) {
|
|
287
|
+
if (!_this.rpc) return Promise.reject(new Error('non connecté'));
|
|
288
|
+
return _this.rpc.call(cap, method, args);
|
|
289
|
+
}
|
|
290
|
+
}), table = _createCapabilityTable.table, subscribe = _createCapabilityTable.subscribe, cleanup = _createCapabilityTable.cleanup;
|
|
291
|
+
var _ref = new MessageChannel(), port1 = _ref.port1, port2 = _ref.port2;
|
|
292
|
+
this.cleanup = cleanup;
|
|
293
|
+
this.rpc = new RpcEndpoint({
|
|
294
|
+
port: port1,
|
|
295
|
+
handlers: table,
|
|
296
|
+
onSubscribe: subscribe,
|
|
297
|
+
validate: function validate(cap, method, args) {
|
|
298
|
+
return validateCall(cap, method, args, 'app-to-host');
|
|
299
|
+
},
|
|
300
|
+
limits: this.o.limits,
|
|
301
|
+
onClose: function onClose(reason) {
|
|
302
|
+
var _this_cleanup, _this1, _this_o_onClose, _this_o;
|
|
303
|
+
(_this_cleanup = (_this1 = _this).cleanup) === null || _this_cleanup === void 0 ? void 0 : _this_cleanup.call(_this1);
|
|
304
|
+
_this.cleanup = undefined;
|
|
305
|
+
if (_this.state !== 'closed') _this.state = 'idle';
|
|
306
|
+
(_this_o_onClose = (_this_o = _this.o).onClose) === null || _this_o_onClose === void 0 ? void 0 : _this_o_onClose.call(_this_o, reason);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
this.state = 'connected';
|
|
310
|
+
this.o.post(wrapHandshake(this.o.moduleName, {
|
|
311
|
+
kind: 'port',
|
|
312
|
+
nonce: this.nonce,
|
|
313
|
+
protocol: EGEN_EMBED_PROTOCOL,
|
|
314
|
+
granted: granted,
|
|
315
|
+
denied: denied,
|
|
316
|
+
hostVersion: this.o.hostVersion
|
|
317
|
+
}), [
|
|
318
|
+
port2
|
|
319
|
+
]);
|
|
320
|
+
(_this_o_onConnect = (_this_o = this.o).onConnect) === null || _this_o_onConnect === void 0 ? void 0 : _this_o_onConnect.call(_this_o, granted, denied);
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
key: "callApp",
|
|
325
|
+
value: /** Appel hôte → app (ex. `lifecycle.canLeave`) ; `undefined` si l'app n'est pas connectée en v2. */ function callApp(_0, _1) {
|
|
326
|
+
return _async_to_generator(function(cap, method) {
|
|
327
|
+
var args;
|
|
328
|
+
var _arguments = arguments;
|
|
329
|
+
return _ts_generator(this, function(_state) {
|
|
330
|
+
args = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : [];
|
|
331
|
+
return [
|
|
332
|
+
2,
|
|
333
|
+
this.rpc && !this.rpc.closed ? this.rpc.call(cap, method, args) : undefined
|
|
334
|
+
];
|
|
335
|
+
});
|
|
336
|
+
}).apply(this, arguments);
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
key: "connected",
|
|
341
|
+
get: function get() {
|
|
342
|
+
return this.state === 'connected' && !!this.rpc && !this.rpc.closed;
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
/** Ferme la connexion courante (rechargement de l'iframe) sans détruire l'objet. */ key: "reset",
|
|
347
|
+
value: function reset() {
|
|
348
|
+
var _this_rpc, _this_cleanup, _this;
|
|
349
|
+
(_this_rpc = this.rpc) === null || _this_rpc === void 0 ? void 0 : _this_rpc.close();
|
|
350
|
+
this.rpc = undefined;
|
|
351
|
+
(_this_cleanup = (_this = this).cleanup) === null || _this_cleanup === void 0 ? void 0 : _this_cleanup.call(_this);
|
|
352
|
+
this.cleanup = undefined;
|
|
353
|
+
this.nonce = undefined;
|
|
354
|
+
if (this.state !== 'closed') this.state = 'idle';
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
key: "destroy",
|
|
359
|
+
value: function destroy() {
|
|
360
|
+
this.reset();
|
|
361
|
+
this.state = 'closed';
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
]);
|
|
365
|
+
return HostConnection;
|
|
366
|
+
}();
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
import { HostConnection } from './connection.js';
|
|
3
|
+
import { type NavigationOptions } from './navigation.js';
|
|
4
|
+
import type { HostProviders } from './providers.js';
|
|
5
|
+
export interface EmbedHostOptions {
|
|
6
|
+
/** Nom du module (= `name` du manifeste). */
|
|
7
|
+
moduleName: string;
|
|
8
|
+
/** URL de base de l'application embarquée. */
|
|
9
|
+
src: string;
|
|
10
|
+
/** Origine autorisée (défaut : origine de `src`). Jamais `*`. */
|
|
11
|
+
allowedOrigin?: string;
|
|
12
|
+
/** Grants effectifs (`effectiveGrants(manifeste.capabilities, approuvés)`). */
|
|
13
|
+
grants: EffectiveGrants;
|
|
14
|
+
providers: HostProviders;
|
|
15
|
+
/** Attribut `sandbox` (défaut : scripts, même origine, formulaires, popups). */
|
|
16
|
+
sandbox?: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
minHeight?: number;
|
|
19
|
+
/** Navigation partagée Core ↔ app (URL du Core = source de vérité). Absent ou `none` : opaque. */
|
|
20
|
+
navigation?: NavigationOptions;
|
|
21
|
+
/** Navigation demandée par l'app vers le Core (défaut : `singleSpaNavigate`). */
|
|
22
|
+
onNavigate?: (to: string) => void;
|
|
23
|
+
limits?: Partial<Limits>;
|
|
24
|
+
hostVersion?: string;
|
|
25
|
+
/** Accepter aussi les apps qui parlent encore le pont 1.1 (défaut : oui). */
|
|
26
|
+
legacy?: boolean;
|
|
27
|
+
window?: Window;
|
|
28
|
+
onConnect?(granted: CapabilityGranted[], denied: CapabilityDenied[]): void;
|
|
29
|
+
onClose?(reason: string): void;
|
|
30
|
+
}
|
|
31
|
+
export interface EmbedHost {
|
|
32
|
+
readonly iframe: HTMLIFrameElement;
|
|
33
|
+
readonly connection: HostConnection;
|
|
34
|
+
mount(container: Element): void;
|
|
35
|
+
/** 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). */
|
|
36
|
+
canLeave(timeoutMs?: number): Promise<boolean>;
|
|
37
|
+
destroy(): void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
|
|
41
|
+
* événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
|
|
42
|
+
* Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createEmbedHost(opts: EmbedHostOptions): EmbedHost;
|
|
45
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,gBAAgB,EAAE,KAAK,iBAAiB,EAAE,KAAK,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAExK,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAwH,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/K,OAAO,KAAK,EAAE,aAAa,EAAS,MAAM,gBAAgB,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAC/B,6CAA6C;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,gFAAgF;IAChF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kGAAkG;IAClG,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,iFAAiF;IACjF,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,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,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,OAAO,IAAI,IAAI,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAoLjE"}
|