@egen-civitas/esm-nextjs-utils 0.0.0-stage → 0.2.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 ADDED
@@ -0,0 +1,14 @@
1
+ # @egen-civitas/esm-nextjs-utils
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0371cd7: Nouveau paquet `esm-nextjs-utils` : intégration d'applications autonomes (Next.js, SSR, routeur propre) par iframe et pont `postMessage` sécurisé. `getEmbedLifecycle` / `getSyncLifecycle` côté Shell (langue, session filtrée sans `sessionId`, navigation limitée aux chemins internes, hauteur, titre) ; `createEgenBridge` (entrée `/client`) côté application embarquée. Origines explicites obligatoires, jamais « * ».
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [d9b2c40]
12
+ - Updated dependencies [f71c7f8]
13
+ - @egen-civitas/esm-globals@2.5.0
14
+ - @egen-civitas/esm-integration-utils@0.2.0
package/README.md CHANGED
@@ -1,3 +1,71 @@
1
- # Temporary Holding Version
1
+ # @egen-civitas/esm-nextjs-utils
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Intégration à EGEN d'une **application autonome** (Next.js, rendu serveur, routeur propre) affichée dans une **iframe** reliée au Shell par un pont `postMessage` sécurisé. Fonctionne avec n'importe quelle application web ; pensé pour Next.js.
4
+
5
+ ## Pourquoi une iframe
6
+
7
+ Next.js possède son routeur, son rendu serveur et son compilateur. Le plugin Module Federation de Next (`@module-federation/nextjs-mf` 8.9) ne couvre que Next 12 à 15, alors que Next courant est la 16 : produire un conteneur Module Federation à partir du compilateur Next n'est donc pas une base fiable. L'iframe garde l'application intacte (SSR compris) et ne dépend pas de ses internes.
8
+
9
+ Ce que l'on perd : pas de partage de contexte React, de dépendances ni de styles avec le Shell ; tout passe par le pont.
10
+
11
+ ## Côté Shell (le `routes.json` et l'export)
12
+
13
+ ```ts
14
+ // src/start.ts de l'app « enveloppe » (peut être minuscule)
15
+ import { getSyncLifecycle } from '@egen-civitas/esm-nextjs-utils';
16
+
17
+ export const root = getSyncLifecycle({
18
+ moduleName: '@acme/esm-mon-next', // = name du package.json
19
+ featureName: 'mon-next',
20
+ url: 'https://next.exemple.org/app', // origine autorisée = origine de l'URL
21
+ });
22
+ ```
23
+ `routes.json` : `{ "pages": [{ "component": "root", "routeRegex": "^mon-next(/.*)?$" }] }`.
24
+
25
+ Options : `allowedOrigin`, `sessionFields` (défaut : `authenticated, locale, allowedLocales, user.uuid, user.display, user.username` ; **jamais** `sessionId`), `sandbox`, `title`, `minHeight`, `onNavigate`.
26
+
27
+ ## Côté application embarquée (Next.js)
28
+
29
+ ```tsx
30
+ 'use client';
31
+ import { useEffect, useState } from 'react';
32
+ import { createEgenBridge, type EgenBridge } from '@egen-civitas/esm-nextjs-utils/client';
33
+
34
+ export function useEgen() {
35
+ const [state, setState] = useState<any>({});
36
+ const [bridge, setBridge] = useState<EgenBridge>();
37
+ useEffect(() => { // navigateur uniquement, jamais pendant le rendu serveur
38
+ const b = createEgenBridge({
39
+ moduleName: '@acme/esm-mon-next',
40
+ allowedHostOrigins: ['https://shell.exemple.org'],
41
+ });
42
+ const off = b.subscribe(setState);
43
+ const stopResize = b.autoResize();
44
+ setBridge(b);
45
+ return () => { off(); stopResize(); b.destroy(); };
46
+ }, []);
47
+ return { ...state, bridge }; // locale, session, spaBase ; bridge.navigate('/accueil')
48
+ }
49
+ ```
50
+
51
+ ## Protocole (v1)
52
+
53
+ Enveloppe `{ egen: 1, moduleName, message }`.
54
+ Shell → app : `init { moduleName, locale, spaBase, session? }`, `session`, `locale`.
55
+ App → Shell : `ready`, `navigate { to }`, `resize { height }`, `title { title }`.
56
+
57
+ ## Sécurité
58
+
59
+ - Un message n'est traité que s'il vient **de l'iframe elle-même ET de l'origine autorisée** (côté app : de `window.parent` ET d'une origine listée). Aucune origine `*` acceptée ; envoi toujours avec une origine cible explicite.
60
+ - Navigation demandée par l'app : **chemins internes uniquement** (`/x`) ; `//hôte`, URL absolues et `javascript:` sont ignorés.
61
+ - `sessionId` n'est jamais transmis ; la session est filtrée par liste blanche.
62
+ - Iframe `sandbox` par défaut (`allow-scripts allow-same-origin allow-forms allow-popups`). Si l'application a la **même origine** que le Shell, ces deux options annulent le bac à sable : héberger l'app sur une autre origine (sous-domaine) ; un avertissement est journalisé sinon.
63
+
64
+ ## Exploitation (à ne pas oublier)
65
+
66
+ - L'application doit **autoriser l'affichage dans une iframe** par le Shell : `Content-Security-Policy: frame-ancestors https://shell.exemple.org` (et pas de `X-Frame-Options: DENY/SAMEORIGIN`). C'est la cause n°1 d'une iframe vide.
67
+ - Le CSP du Shell doit autoriser `frame-src` vers l'application.
68
+ - Authentification : les cookies tiers sont bloqués par les navigateurs entre sites distincts. Préférer le **même site** (sous-domaines d'un même domaine) ou une session propre à l'application.
69
+ - Les apps natives (Android/iOS) exigent un contenu embarqué : une iframe distante n'y est pas adaptée.
70
+
71
+ Tests : `yarn test` (fenêtres simulées ; l'exécution inter-fenêtres dans un vrai navigateur reste à valider).
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Côté application embarquée (Next.js ou autre) : s'exécute DANS l'iframe, sans dépendance au Framework.
3
+ * Ne l'utiliser que côté navigateur (dans un `useEffect` pour Next.js : pas pendant le rendu serveur).
4
+ */
5
+ import { type EmbedInit } from './protocol.js';
6
+ export type { EmbedInit } from './protocol.js';
7
+ export interface EgenBridgeOptions {
8
+ /** Nom du module (identique à `moduleName` du lifecycle côté Shell). */
9
+ moduleName: string;
10
+ /** Origines du Shell autorisées. Obligatoire, jamais « * ». */
11
+ allowedHostOrigins: string[];
12
+ }
13
+ export interface EgenBridge {
14
+ /** Résolue à la réception des données initiales du Shell. */
15
+ ready: Promise<EmbedInit>;
16
+ /** Dernières données connues (session, langue). */
17
+ getState(): Partial<EmbedInit>;
18
+ /** S'abonne aux changements (session, langue) ; renvoie le désabonnement. */
19
+ subscribe(listener: (state: Partial<EmbedInit>) => void): () => void;
20
+ /** Demande une navigation du Shell vers un chemin interne (`/accueil`). */
21
+ navigate(to: string): void;
22
+ /** Annonce la hauteur du contenu (le Shell redimensionne l'iframe). */
23
+ setHeight(height: number): void;
24
+ /** Annonce un titre accessible pour l'iframe. */
25
+ setTitle(title: string): void;
26
+ /** Annonce automatiquement la hauteur du document (ResizeObserver). */
27
+ autoResize(): () => void;
28
+ destroy(): void;
29
+ }
30
+ export declare function createEgenBridge(opts: EgenBridgeOptions): EgenBridge;
31
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAoB,KAAK,SAAS,EAAsC,MAAM,eAAe,CAAC;AAErG,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,6DAA6D;IAC7D,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/B,6EAA6E;IAC7E,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACrE,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,uEAAuE;IACvE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uEAAuE;IACvE,UAAU,IAAI,MAAM,IAAI,CAAC;IACzB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,UAAU,CA4DpE"}
package/dist/client.js ADDED
@@ -0,0 +1,158 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _object_spread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _define_property(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ function ownKeys(object, enumerableOnly) {
30
+ var keys = Object.keys(object);
31
+ if (Object.getOwnPropertySymbols) {
32
+ var symbols = Object.getOwnPropertySymbols(object);
33
+ if (enumerableOnly) {
34
+ symbols = symbols.filter(function(sym) {
35
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
36
+ });
37
+ }
38
+ keys.push.apply(keys, symbols);
39
+ }
40
+ return keys;
41
+ }
42
+ function _object_spread_props(target, source) {
43
+ source = source != null ? source : {};
44
+ if (Object.getOwnPropertyDescriptors) {
45
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
46
+ } else {
47
+ ownKeys(Object(source)).forEach(function(key) {
48
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
49
+ });
50
+ }
51
+ return target;
52
+ }
53
+ /**
54
+ * Côté application embarquée (Next.js ou autre) : s'exécute DANS l'iframe, sans dépendance au Framework.
55
+ * Ne l'utiliser que côté navigateur (dans un `useEffect` pour Next.js : pas pendant le rendu serveur).
56
+ */ import { isEnvelope, wrap } from './protocol.js';
57
+ export function createEgenBridge(opts) {
58
+ var _opts_allowedHostOrigins;
59
+ if (!((_opts_allowedHostOrigins = opts.allowedHostOrigins) === null || _opts_allowedHostOrigins === void 0 ? void 0 : _opts_allowedHostOrigins.length) || opts.allowedHostOrigins.some(function(o) {
60
+ return o === '*' || o === 'null';
61
+ })) {
62
+ throw new Error('allowedHostOrigins : au moins une origine explicite est requise (jamais « * »).');
63
+ }
64
+ var host = window.parent;
65
+ if (host === window) throw new Error("createEgenBridge doit s'exécuter dans une iframe affichée par le Shell EGEN.");
66
+ var state = {};
67
+ var listeners = new Set();
68
+ var resolveReady;
69
+ var ready = new Promise(function(r) {
70
+ return resolveReady = r;
71
+ });
72
+ // L'origine du Shell n'est connue qu'à la première réponse : le message `ready` est donc envoyé à chaque origine autorisée.
73
+ var hostOrigin;
74
+ var emit = function emit() {
75
+ return listeners.forEach(function(l) {
76
+ return l(state);
77
+ });
78
+ };
79
+ var onMessage = function onMessage(event) {
80
+ if (event.source !== host || !opts.allowedHostOrigins.includes(event.origin)) return;
81
+ if (!isEnvelope(event.data, opts.moduleName)) return;
82
+ hostOrigin = event.origin;
83
+ var msg = event.data.message;
84
+ if (msg.kind === 'init') {
85
+ state = _object_spread({}, msg.payload);
86
+ resolveReady(msg.payload);
87
+ emit();
88
+ } else if (msg.kind === 'session') {
89
+ state = _object_spread_props(_object_spread({}, state), {
90
+ session: msg.session
91
+ });
92
+ emit();
93
+ } else if (msg.kind === 'locale') {
94
+ state = _object_spread_props(_object_spread({}, state), {
95
+ locale: msg.locale
96
+ });
97
+ emit();
98
+ }
99
+ };
100
+ window.addEventListener('message', onMessage);
101
+ var send = function send(message) {
102
+ var targets = hostOrigin ? [
103
+ hostOrigin
104
+ ] : opts.allowedHostOrigins;
105
+ targets.forEach(function(o) {
106
+ return host.postMessage(wrap(opts.moduleName, message), o);
107
+ });
108
+ };
109
+ send({
110
+ kind: 'ready'
111
+ });
112
+ return {
113
+ ready: ready,
114
+ getState: function getState() {
115
+ return state;
116
+ },
117
+ subscribe: function subscribe(l) {
118
+ listeners.add(l);
119
+ return function() {
120
+ return listeners.delete(l);
121
+ };
122
+ },
123
+ navigate: function navigate(to) {
124
+ return send({
125
+ kind: 'navigate',
126
+ to: to
127
+ });
128
+ },
129
+ setHeight: function setHeight(height) {
130
+ return send({
131
+ kind: 'resize',
132
+ height: height
133
+ });
134
+ },
135
+ setTitle: function setTitle(title) {
136
+ return send({
137
+ kind: 'title',
138
+ title: title
139
+ });
140
+ },
141
+ autoResize: function autoResize() {
142
+ var ro = new ResizeObserver(function() {
143
+ return send({
144
+ kind: 'resize',
145
+ height: document.documentElement.scrollHeight
146
+ });
147
+ });
148
+ ro.observe(document.documentElement);
149
+ return function() {
150
+ return ro.disconnect();
151
+ };
152
+ },
153
+ destroy: function destroy() {
154
+ window.removeEventListener('message', onMessage);
155
+ listeners.clear();
156
+ }
157
+ };
158
+ }
package/dist/host.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import type { LifeCycles } from 'single-spa';
2
+ import { type LifecycleExport, type LifecycleOptions } from '@egen-civitas/esm-integration-utils';
3
+ export interface EmbedLifecycleOptions extends LifecycleOptions {
4
+ /** URL de l'application embarquée (ou fonction des props Single-SPA). */
5
+ url: string | ((props: Record<string, any>) => string);
6
+ /** Origine autorisée pour les messages (défaut : origine de `url`). Jamais de « * ». */
7
+ allowedOrigin?: string;
8
+ /** Champs de session transmis (notation pointée). Défaut : `DEFAULT_SESSION_FIELDS` (sans `sessionId`). */
9
+ sessionFields?: string[];
10
+ /** Attribut `sandbox` de l'iframe (défaut : scripts + même origine + formulaires + popups). */
11
+ sandbox?: string;
12
+ /** Titre accessible de l'iframe. */
13
+ title?: string;
14
+ /** Hauteur minimale en px tant que l'application n'a pas annoncé la sienne (défaut 400). */
15
+ minHeight?: number;
16
+ /** Navigation demandée par l'application (défaut : `singleSpaNavigate(spaBase + chemin)`). */
17
+ onNavigate?: (to: string) => void;
18
+ }
19
+ /** Chemin relatif interne uniquement (`/x`), jamais d'URL absolue ni `//hôte`. */
20
+ export declare function isSafeInternalPath(to: unknown): to is string;
21
+ /**
22
+ * Lifecycles Single-SPA qui affichent une application autonome (ex. Next.js avec SSR) dans une iframe
23
+ * et la relient au Shell par un pont `postMessage` :
24
+ * Shell → app : langue, session filtrée ; app → Shell : prêt, navigation, hauteur, titre.
25
+ * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours
26
+ * avec une origine cible explicite ; navigation limitée aux chemins internes.
27
+ */
28
+ export declare function getEmbedLifecycle(userOpts: EmbedLifecycleOptions): LifeCycles;
29
+ /** Export prêt pour `routes.json` : fonction → promesse de lifecycles. */
30
+ export declare function getSyncLifecycle(options: EmbedLifecycleOptions): LifecycleExport;
31
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAML,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAEtB,MAAM,qCAAqC,CAAC;AAG7C,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D,yEAAyE;IACzE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,CAAC;IACvD,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2GAA2G;IAC3G,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4FAA4F;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8FAA8F;IAC9F,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAKD,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,MAAM,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,UAAU,CA6F7E;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,GAAG,eAAe,CAEhF"}
package/dist/host.js ADDED
@@ -0,0 +1,125 @@
1
+ import { assertLifecycleOptions, resolveMountTarget, toLifecycleExport, watchSession, watchTranslations } from '@egen-civitas/esm-integration-utils';
2
+ import { DEFAULT_SESSION_FIELDS, isEnvelope, pickFields, wrap } from './protocol.js';
3
+ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
4
+ var SAFE_PATH = /^\/(?!\/)[^\s\\]*$/;
5
+ /** Chemin relatif interne uniquement (`/x`), jamais d'URL absolue ni `//hôte`. */ export function isSafeInternalPath(to) {
6
+ return typeof to === 'string' && SAFE_PATH.test(to);
7
+ }
8
+ /**
9
+ * Lifecycles Single-SPA qui affichent une application autonome (ex. Next.js avec SSR) dans une iframe
10
+ * et la relient au Shell par un pont `postMessage` :
11
+ * Shell → app : langue, session filtrée ; app → Shell : prêt, navigation, hauteur, titre.
12
+ * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours
13
+ * avec une origine cible explicite ; navigation limitée aux chemins internes.
14
+ */ export function getEmbedLifecycle(userOpts) {
15
+ var _opts_sessionFields;
16
+ assertLifecycleOptions(userOpts);
17
+ var opts = userOpts;
18
+ var fields = (_opts_sessionFields = opts.sessionFields) !== null && _opts_sessionFields !== void 0 ? _opts_sessionFields : DEFAULT_SESSION_FIELDS;
19
+ var mounted = new Map();
20
+ return {
21
+ bootstrap: function bootstrap() {
22
+ return Promise.resolve();
23
+ },
24
+ mount: function mount(props) {
25
+ var _opts_allowedOrigin, _opts_sandbox, _opts_title, _opts_minHeight;
26
+ var target = resolveMountTarget(props);
27
+ var src = typeof opts.url === 'function' ? opts.url(props) : opts.url;
28
+ var origin = (_opts_allowedOrigin = opts.allowedOrigin) !== null && _opts_allowedOrigin !== void 0 ? _opts_allowedOrigin : new URL(src, window.location.href).origin;
29
+ if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
30
+ var sandbox = (_opts_sandbox = opts.sandbox) !== null && _opts_sandbox !== void 0 ? _opts_sandbox : DEFAULT_SANDBOX;
31
+ if (origin === window.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
32
+ console.warn("[egen] ".concat(opts.moduleName, " : application embarqu\xe9e de m\xeame origine que le Shell avec \xab allow-scripts allow-same-origin \xbb : ") + "le bac à sable est sans effet. Héberger l'application sur une autre origine (sous-domaine).");
33
+ }
34
+ var iframe = document.createElement('iframe');
35
+ iframe.src = src;
36
+ iframe.title = (_opts_title = opts.title) !== null && _opts_title !== void 0 ? _opts_title : opts.featureName;
37
+ iframe.setAttribute('sandbox', sandbox);
38
+ iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
39
+ iframe.style.cssText = "width:100%;border:0;display:block;min-height:".concat((_opts_minHeight = opts.minHeight) !== null && _opts_minHeight !== void 0 ? _opts_minHeight : 400, "px");
40
+ var send = function send(message) {
41
+ var _iframe_contentWindow;
42
+ return (_iframe_contentWindow = iframe.contentWindow) === null || _iframe_contentWindow === void 0 ? void 0 : _iframe_contentWindow.postMessage(wrap(opts.moduleName, message), origin);
43
+ };
44
+ var stop = [];
45
+ var ready = false;
46
+ var lastSession;
47
+ var onMessage = function onMessage(event) {
48
+ if (event.source !== iframe.contentWindow || event.origin !== origin) return;
49
+ if (!isEnvelope(event.data, opts.moduleName)) return;
50
+ var msg = event.data.message;
51
+ switch(msg.kind){
52
+ case 'ready':
53
+ var _ref;
54
+ var _window_i18next, _window_getEgenSpaBase, _window;
55
+ ready = true;
56
+ send({
57
+ kind: 'init',
58
+ payload: {
59
+ moduleName: opts.moduleName,
60
+ locale: (_window_i18next = window.i18next) === null || _window_i18next === void 0 ? void 0 : _window_i18next.language,
61
+ spaBase: (_ref = (_window_getEgenSpaBase = (_window = window).getEgenSpaBase) === null || _window_getEgenSpaBase === void 0 ? void 0 : _window_getEgenSpaBase.call(_window)) !== null && _ref !== void 0 ? _ref : '/',
62
+ session: lastSession
63
+ }
64
+ });
65
+ break;
66
+ case 'navigate':
67
+ if (isSafeInternalPath(msg.to)) {
68
+ var _opts_onNavigate;
69
+ ((_opts_onNavigate = opts.onNavigate) !== null && _opts_onNavigate !== void 0 ? _opts_onNavigate : function(to) {
70
+ var _ref;
71
+ var _window_getEgenSpaBase, _window, _window_singleSpaNavigate, _window1;
72
+ return (_window_singleSpaNavigate = (_window1 = window).singleSpaNavigate) === null || _window_singleSpaNavigate === void 0 ? void 0 : _window_singleSpaNavigate.call(_window1, ((_ref = (_window_getEgenSpaBase = (_window = window).getEgenSpaBase) === null || _window_getEgenSpaBase === void 0 ? void 0 : _window_getEgenSpaBase.call(_window)) !== null && _ref !== void 0 ? _ref : '/') + to.replace(/^\//, ''));
73
+ })(msg.to);
74
+ }
75
+ break;
76
+ case 'resize':
77
+ if (Number.isFinite(msg.height) && msg.height >= 0) iframe.style.height = "".concat(Math.min(Math.ceil(msg.height), 100000), "px");
78
+ break;
79
+ case 'title':
80
+ if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
81
+ break;
82
+ }
83
+ };
84
+ window.addEventListener('message', onMessage);
85
+ stop.push(function() {
86
+ return window.removeEventListener('message', onMessage);
87
+ });
88
+ stop.push(watchSession(function(session) {
89
+ lastSession = pickFields(session, fields);
90
+ if (ready) send({
91
+ kind: 'session',
92
+ session: lastSession
93
+ });
94
+ }));
95
+ stop.push(watchTranslations(function() {
96
+ var _window_i18next;
97
+ var locale = (_window_i18next = window.i18next) === null || _window_i18next === void 0 ? void 0 : _window_i18next.language;
98
+ if (ready && locale) send({
99
+ kind: 'locale',
100
+ locale: locale
101
+ });
102
+ }));
103
+ target.appendChild(iframe);
104
+ mounted.set(props.name, {
105
+ iframe: iframe,
106
+ stop: stop
107
+ });
108
+ return Promise.resolve();
109
+ },
110
+ unmount: function unmount(props) {
111
+ var m = mounted.get(props.name);
112
+ if (m) {
113
+ m.stop.forEach(function(s) {
114
+ return s();
115
+ });
116
+ m.iframe.remove();
117
+ mounted.delete(props.name);
118
+ }
119
+ return Promise.resolve();
120
+ }
121
+ };
122
+ }
123
+ /** Export prêt pour `routes.json` : fonction → promesse de lifecycles. */ export function getSyncLifecycle(options) {
124
+ return toLifecycleExport(getEmbedLifecycle(options));
125
+ }
@@ -0,0 +1,3 @@
1
+ export * from './host.js';
2
+ export * from './protocol.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './host.js';
2
+ export * from './protocol.js';