@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/dist/host.js ADDED
@@ -0,0 +1,587 @@
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 _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
+ }
51
+ function _iterable_to_array(iter) {
52
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
+ }
54
+ function _non_iterable_spread() {
55
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
56
+ }
57
+ function _object_spread(target) {
58
+ for(var i = 1; i < arguments.length; i++){
59
+ var source = arguments[i] != null ? arguments[i] : {};
60
+ var ownKeys = Object.keys(source);
61
+ if (typeof Object.getOwnPropertySymbols === "function") {
62
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
+ }));
65
+ }
66
+ ownKeys.forEach(function(key) {
67
+ _define_property(target, key, source[key]);
68
+ });
69
+ }
70
+ return target;
71
+ }
72
+ function ownKeys(object, enumerableOnly) {
73
+ var keys = Object.keys(object);
74
+ if (Object.getOwnPropertySymbols) {
75
+ var symbols = Object.getOwnPropertySymbols(object);
76
+ if (enumerableOnly) {
77
+ symbols = symbols.filter(function(sym) {
78
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
79
+ });
80
+ }
81
+ keys.push.apply(keys, symbols);
82
+ }
83
+ return keys;
84
+ }
85
+ function _object_spread_props(target, source) {
86
+ source = source != null ? source : {};
87
+ if (Object.getOwnPropertyDescriptors) {
88
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
89
+ } else {
90
+ ownKeys(Object(source)).forEach(function(key) {
91
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
92
+ });
93
+ }
94
+ return target;
95
+ }
96
+ function _to_consumable_array(arr) {
97
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
98
+ }
99
+ function _unsupported_iterable_to_array(o, minLen) {
100
+ if (!o) return;
101
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
102
+ var n = Object.prototype.toString.call(o).slice(8, -1);
103
+ if (n === "Object" && o.constructor) n = o.constructor.name;
104
+ if (n === "Map" || n === "Set") return Array.from(n);
105
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
106
+ }
107
+ function _ts_generator(thisArg, body) {
108
+ var f, y, t, _ = {
109
+ label: 0,
110
+ sent: function() {
111
+ if (t[0] & 1) throw t[1];
112
+ return t[1];
113
+ },
114
+ trys: [],
115
+ ops: []
116
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
117
+ return d(g, "next", {
118
+ value: verb(0)
119
+ }), d(g, "throw", {
120
+ value: verb(1)
121
+ }), d(g, "return", {
122
+ value: verb(2)
123
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
124
+ value: function() {
125
+ return this;
126
+ }
127
+ }), g;
128
+ function verb(n) {
129
+ return function(v) {
130
+ return step([
131
+ n,
132
+ v
133
+ ]);
134
+ };
135
+ }
136
+ function step(op) {
137
+ if (f) throw new TypeError("Generator is already executing.");
138
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
139
+ 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;
140
+ if (y = 0, t) op = [
141
+ op[0] & 2,
142
+ t.value
143
+ ];
144
+ switch(op[0]){
145
+ case 0:
146
+ case 1:
147
+ t = op;
148
+ break;
149
+ case 4:
150
+ _.label++;
151
+ return {
152
+ value: op[1],
153
+ done: false
154
+ };
155
+ case 5:
156
+ _.label++;
157
+ y = op[1];
158
+ op = [
159
+ 0
160
+ ];
161
+ continue;
162
+ case 7:
163
+ op = _.ops.pop();
164
+ _.trys.pop();
165
+ continue;
166
+ default:
167
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
168
+ _ = 0;
169
+ continue;
170
+ }
171
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
172
+ _.label = op[1];
173
+ break;
174
+ }
175
+ if (op[0] === 6 && _.label < t[1]) {
176
+ _.label = t[1];
177
+ t = op;
178
+ break;
179
+ }
180
+ if (t && _.label < t[2]) {
181
+ _.label = t[2];
182
+ _.ops.push(op);
183
+ break;
184
+ }
185
+ if (t[2]) _.ops.pop();
186
+ _.trys.pop();
187
+ continue;
188
+ }
189
+ op = body.call(thisArg, _);
190
+ } catch (e) {
191
+ op = [
192
+ 6,
193
+ e
194
+ ];
195
+ y = 0;
196
+ } finally{
197
+ f = t = 0;
198
+ }
199
+ if (op[0] & 5) throw op[1];
200
+ return {
201
+ value: op[0] ? op[1] : void 0,
202
+ done: true
203
+ };
204
+ }
205
+ }
206
+ import { DEFAULT_SESSION_FIELDS, pickFields } from '@egen-civitas/esm-embed-protocol';
207
+ import { createBus } from './bus.js';
208
+ import { HostConnection } from './connection.js';
209
+ import { buildCoreUrl, buildEmbedSrc, coreSubpath, createRateLimiter, stripSensitive, toAppPath, toCorePath, normalizeAppPath } from './navigation.js';
210
+ var DEFAULT_SANDBOX = 'allow-scripts allow-same-origin allow-forms allow-popups';
211
+ /**
212
+ * Hôte d'une app embarquée : iframe sécurisée, poignée de main v2 (`HostConnection`), navigation partagée,
213
+ * événements de cycle de vie, et pont 1.1 pour les apps qui ne parlent pas encore le protocole 2.
214
+ * Sécurité : messages acceptés seulement de l'iframe elle-même ET de l'origine autorisée ; envoi toujours avec une origine explicite.
215
+ */ export function createEmbedHost(opts) {
216
+ var _opts_window, _opts_navigation_mode, _opts_navigation_mode1, _currentCorePath, _toAppPath, _opts_allowedOrigin, _opts_sandbox, _opts_title, _opts_minHeight;
217
+ var win = (_opts_window = opts.window) !== null && _opts_window !== void 0 ? _opts_window : window;
218
+ var doc = win.document;
219
+ var nav = opts.navigation && ((_opts_navigation_mode = opts.navigation.mode) !== null && _opts_navigation_mode !== void 0 ? _opts_navigation_mode : 'history') !== 'none' ? _object_spread_props(_object_spread({}, opts.navigation), {
220
+ mode: (_opts_navigation_mode1 = opts.navigation.mode) !== null && _opts_navigation_mode1 !== void 0 ? _opts_navigation_mode1 : 'history'
221
+ }) : undefined;
222
+ var spaBase = function spaBase() {
223
+ var _ref;
224
+ var _win_getEgenSpaBase;
225
+ return (_ref = (_win_getEgenSpaBase = win.getEgenSpaBase) === null || _win_getEgenSpaBase === void 0 ? void 0 : _win_getEgenSpaBase.call(win)) !== null && _ref !== void 0 ? _ref : '/';
226
+ };
227
+ var currentCorePath = function currentCorePath() {
228
+ if (!nav) return null;
229
+ var sub = coreSubpath(win.location.pathname, spaBase(), nav.route);
230
+ return sub === null ? null : stripSensitive(sub + win.location.search + win.location.hash, nav.sensitiveParams);
231
+ };
232
+ var lastCorePath = (_currentCorePath = currentCorePath()) !== null && _currentCorePath !== void 0 ? _currentCorePath : '/';
233
+ var initialAppPath = nav ? (_toAppPath = toAppPath(lastCorePath, nav)) !== null && _toAppPath !== void 0 ? _toAppPath : '/' : '/';
234
+ var src = nav ? buildEmbedSrc(opts.src, initialAppPath, nav.mode) : opts.src;
235
+ var origin = (_opts_allowedOrigin = opts.allowedOrigin) !== null && _opts_allowedOrigin !== void 0 ? _opts_allowedOrigin : new URL(src, win.location.href).origin;
236
+ if (origin === '*' || origin === 'null') throw new Error('allowedOrigin invalide : une origine explicite est requise.');
237
+ var sandbox = (_opts_sandbox = opts.sandbox) !== null && _opts_sandbox !== void 0 ? _opts_sandbox : DEFAULT_SANDBOX;
238
+ if (origin === win.location.origin && /allow-scripts/.test(sandbox) && /allow-same-origin/.test(sandbox)) {
239
+ 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 \xe0 sable est sans effet. H\xe9berger l'application sur une autre origine (sous-domaine)."));
240
+ }
241
+ var iframe = doc.createElement('iframe');
242
+ iframe.src = src;
243
+ iframe.title = (_opts_title = opts.title) !== null && _opts_title !== void 0 ? _opts_title : opts.moduleName;
244
+ iframe.setAttribute('sandbox', sandbox);
245
+ iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin');
246
+ iframe.setAttribute('data-egen-fill', '');
247
+ 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");
248
+ var channel = createBus();
249
+ var allowLocation = createRateLimiter();
250
+ var stop = [];
251
+ var seq = 0;
252
+ var legacySeen = false;
253
+ var legacyReady = false;
254
+ var postRaw = function postRaw(message, transfer) {
255
+ var _iframe_contentWindow;
256
+ return (_iframe_contentWindow = iframe.contentWindow) === null || _iframe_contentWindow === void 0 ? void 0 : _iframe_contentWindow.postMessage(message, origin, transfer);
257
+ };
258
+ var legacySend = function legacySend(message) {
259
+ return postRaw({
260
+ egen: 1,
261
+ moduleName: opts.moduleName,
262
+ message: message
263
+ });
264
+ };
265
+ /** Page courante annoncée par l'app → URL du Core (partagé entre le protocole 2 et le pont 1.1). */ var reportLocation = function reportLocation(path, o) {
266
+ if (!nav || !allowLocation()) return;
267
+ if (typeof (o === null || o === void 0 ? void 0 : o.title) === 'string') {
268
+ var _nav_onTitle;
269
+ iframe.title = o.title.slice(0, 200);
270
+ (_nav_onTitle = nav.onTitle) === null || _nav_onTitle === void 0 ? void 0 : _nav_onTitle.call(nav, iframe.title);
271
+ }
272
+ var corePath = toCorePath(path, nav);
273
+ if (!corePath || corePath === lastCorePath) return;
274
+ lastCorePath = corePath;
275
+ win.history[(o === null || o === void 0 ? void 0 : o.replace) ? 'replaceState' : 'pushState'](win.history.state, '', buildCoreUrl(spaBase(), nav.route, corePath));
276
+ };
277
+ var controls = {
278
+ channel: channel,
279
+ report: function report(path, o) {
280
+ return reportLocation(path, o);
281
+ },
282
+ navigate: function navigate(to) {
283
+ var _opts_onNavigate;
284
+ if (normalizeAppPath(to) === null) return;
285
+ ((_opts_onNavigate = opts.onNavigate) !== null && _opts_onNavigate !== void 0 ? _opts_onNavigate : function(t) {
286
+ var _win_singleSpaNavigate;
287
+ return (_win_singleSpaNavigate = win.singleSpaNavigate) === null || _win_singleSpaNavigate === void 0 ? void 0 : _win_singleSpaNavigate.call(win, spaBase() + t.replace(/^\//, ''));
288
+ })(to);
289
+ },
290
+ setTitle: function setTitle(t) {
291
+ return void (iframe.title = String(t).slice(0, 200));
292
+ },
293
+ resize: function resize(h) {
294
+ if (Number.isFinite(h) && h >= 0) iframe.style.height = "".concat(Math.min(Math.ceil(h), 100000), "px");
295
+ }
296
+ };
297
+ var connection = new HostConnection({
298
+ moduleName: opts.moduleName,
299
+ grants: opts.grants,
300
+ providers: opts.providers,
301
+ controls: controls,
302
+ post: postRaw,
303
+ limits: opts.limits,
304
+ hostVersion: opts.hostVersion,
305
+ onConnect: opts.onConnect,
306
+ onClose: opts.onClose
307
+ });
308
+ var sessionFields = function sessionFields() {
309
+ var _opts_grants_session;
310
+ var f = (_opts_grants_session = opts.grants.session) === null || _opts_grants_session === void 0 ? void 0 : _opts_grants_session.fields;
311
+ return Array.isArray(f) && f.length ? f : _to_consumable_array(DEFAULT_SESSION_FIELDS);
312
+ };
313
+ /** Pont 1.1 : mêmes services, ancien format. Inactif dès qu'une connexion v2 est ouverte. */ var handleLegacy = function handleLegacy(data) {
314
+ return _async_to_generator(function() {
315
+ var msg, _, _win_i18next, session, _tmp, locale, _tmp1, _controls_navigate, _controls_resize;
316
+ return _ts_generator(this, function(_state) {
317
+ switch(_state.label){
318
+ case 0:
319
+ if (opts.legacy === false || connection.connected) return [
320
+ 2
321
+ ];
322
+ if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return [
323
+ 2
324
+ ];
325
+ msg = data.message;
326
+ _ = msg.kind;
327
+ switch(_){
328
+ case 'ready':
329
+ return [
330
+ 3,
331
+ 1
332
+ ];
333
+ case 'navigate':
334
+ return [
335
+ 3,
336
+ 8
337
+ ];
338
+ case 'resize':
339
+ return [
340
+ 3,
341
+ 9
342
+ ];
343
+ case 'title':
344
+ return [
345
+ 3,
346
+ 10
347
+ ];
348
+ case 'location':
349
+ return [
350
+ 3,
351
+ 11
352
+ ];
353
+ }
354
+ return [
355
+ 3,
356
+ 12
357
+ ];
358
+ case 1:
359
+ legacySeen = true;
360
+ legacyReady = true;
361
+ if (!opts.providers.session) return [
362
+ 3,
363
+ 3
364
+ ];
365
+ return [
366
+ 4,
367
+ opts.providers.session.get()
368
+ ];
369
+ case 2:
370
+ _tmp = pickFields.apply(void 0, [
371
+ _state.sent(),
372
+ sessionFields()
373
+ ]);
374
+ return [
375
+ 3,
376
+ 4
377
+ ];
378
+ case 3:
379
+ _tmp = undefined;
380
+ _state.label = 4;
381
+ case 4:
382
+ session = _tmp;
383
+ if (!opts.providers.locale) return [
384
+ 3,
385
+ 6
386
+ ];
387
+ return [
388
+ 4,
389
+ opts.providers.locale.get()
390
+ ];
391
+ case 5:
392
+ _tmp1 = _state.sent();
393
+ return [
394
+ 3,
395
+ 7
396
+ ];
397
+ case 6:
398
+ _tmp1 = (_win_i18next = win.i18next) === null || _win_i18next === void 0 ? void 0 : _win_i18next.language;
399
+ _state.label = 7;
400
+ case 7:
401
+ locale = _tmp1;
402
+ legacySend({
403
+ kind: 'init',
404
+ payload: {
405
+ moduleName: opts.moduleName,
406
+ locale: locale,
407
+ spaBase: spaBase(),
408
+ session: session,
409
+ navigation: nav ? {
410
+ mode: nav.mode,
411
+ route: nav.route
412
+ } : undefined
413
+ }
414
+ });
415
+ return [
416
+ 3,
417
+ 12
418
+ ];
419
+ case 8:
420
+ (_controls_navigate = controls.navigate) === null || _controls_navigate === void 0 ? void 0 : _controls_navigate.call(controls, msg.to);
421
+ return [
422
+ 3,
423
+ 12
424
+ ];
425
+ case 9:
426
+ (_controls_resize = controls.resize) === null || _controls_resize === void 0 ? void 0 : _controls_resize.call(controls, msg.height);
427
+ return [
428
+ 3,
429
+ 12
430
+ ];
431
+ case 10:
432
+ if (typeof msg.title === 'string') iframe.title = msg.title.slice(0, 200);
433
+ return [
434
+ 3,
435
+ 12
436
+ ];
437
+ case 11:
438
+ legacySeen = true;
439
+ reportLocation(msg.path, {
440
+ replace: !!msg.replace,
441
+ title: msg.title
442
+ });
443
+ return [
444
+ 3,
445
+ 12
446
+ ];
447
+ case 12:
448
+ return [
449
+ 2
450
+ ];
451
+ }
452
+ });
453
+ })();
454
+ };
455
+ var onMessage = function onMessage(event) {
456
+ if (event.source !== iframe.contentWindow || event.origin !== origin) return;
457
+ if (!connection.handle(event.data)) void handleLegacy(event.data);
458
+ };
459
+ return {
460
+ iframe: iframe,
461
+ connection: connection,
462
+ mount: function mount(container) {
463
+ var _p_session, _p_locale;
464
+ win.addEventListener('message', onMessage);
465
+ stop.push(function() {
466
+ return win.removeEventListener('message', onMessage);
467
+ });
468
+ var onLoad = function onLoad() {
469
+ return connection.hello();
470
+ };
471
+ iframe.addEventListener('load', onLoad);
472
+ stop.push(function() {
473
+ return iframe.removeEventListener('load', onLoad);
474
+ });
475
+ if (nav) {
476
+ var onCoreLocation = function onCoreLocation() {
477
+ var cur = currentCorePath();
478
+ if (cur === null || cur === lastCorePath) return;
479
+ lastCorePath = cur;
480
+ var appPath = toAppPath(cur, nav);
481
+ if (!appPath) return;
482
+ if (connection.connected) channel.emit('goto', {
483
+ path: appPath,
484
+ seq: ++seq
485
+ });
486
+ else if (legacySeen) legacySend({
487
+ kind: 'goto',
488
+ path: appPath,
489
+ seq: ++seq
490
+ });
491
+ else iframe.src = buildEmbedSrc(opts.src, appPath, nav.mode);
492
+ };
493
+ win.addEventListener('single-spa:routing-event', onCoreLocation);
494
+ win.addEventListener('popstate', onCoreLocation);
495
+ stop.push(function() {
496
+ win.removeEventListener('single-spa:routing-event', onCoreLocation);
497
+ win.removeEventListener('popstate', onCoreLocation);
498
+ });
499
+ }
500
+ var onVisibility = function onVisibility() {
501
+ return channel.emit('visibility', !doc.hidden);
502
+ };
503
+ var onFocus = function onFocus() {
504
+ return channel.emit('focus', true);
505
+ };
506
+ var onBlur = function onBlur() {
507
+ return channel.emit('focus', false);
508
+ };
509
+ doc.addEventListener('visibilitychange', onVisibility);
510
+ win.addEventListener('focus', onFocus);
511
+ win.addEventListener('blur', onBlur);
512
+ stop.push(function() {
513
+ doc.removeEventListener('visibilitychange', onVisibility);
514
+ win.removeEventListener('focus', onFocus);
515
+ win.removeEventListener('blur', onBlur);
516
+ });
517
+ // Pont 1.1 : session et langue poussées après `ready`.
518
+ var p = opts.providers;
519
+ if ((_p_session = p.session) === null || _p_session === void 0 ? void 0 : _p_session.subscribe) stop.push(p.session.subscribe(function(s) {
520
+ return legacyReady && !connection.connected && legacySend({
521
+ kind: 'session',
522
+ session: pickFields(s, sessionFields())
523
+ });
524
+ }));
525
+ if ((_p_locale = p.locale) === null || _p_locale === void 0 ? void 0 : _p_locale.subscribe) stop.push(p.locale.subscribe(function(l) {
526
+ return legacyReady && !connection.connected && l && legacySend({
527
+ kind: 'locale',
528
+ locale: l
529
+ });
530
+ }));
531
+ container.appendChild(iframe);
532
+ },
533
+ canLeave: function canLeave() {
534
+ var timeoutMs = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1500;
535
+ return _async_to_generator(function() {
536
+ var r, unused;
537
+ return _ts_generator(this, function(_state) {
538
+ switch(_state.label){
539
+ case 0:
540
+ if (!connection.connected) return [
541
+ 2,
542
+ true
543
+ ];
544
+ _state.label = 1;
545
+ case 1:
546
+ _state.trys.push([
547
+ 1,
548
+ 3,
549
+ ,
550
+ 4
551
+ ]);
552
+ return [
553
+ 4,
554
+ Promise.race([
555
+ connection.callApp('lifecycle', 'canLeave'),
556
+ new Promise(function(res) {
557
+ return setTimeout(res, timeoutMs);
558
+ })
559
+ ])
560
+ ];
561
+ case 2:
562
+ r = _state.sent();
563
+ return [
564
+ 2,
565
+ r === undefined ? true : !!r
566
+ ];
567
+ case 3:
568
+ unused = _state.sent();
569
+ return [
570
+ 2,
571
+ true
572
+ ];
573
+ case 4:
574
+ return [
575
+ 2
576
+ ];
577
+ }
578
+ });
579
+ })();
580
+ },
581
+ destroy: function destroy() {
582
+ while(stop.length)stop.pop()();
583
+ connection.destroy();
584
+ iframe.remove();
585
+ }
586
+ };
587
+ }
@@ -0,0 +1,7 @@
1
+ export * from './bus.js';
2
+ export * from './providers.js';
3
+ export * from './table.js';
4
+ export * from './connection.js';
5
+ export * from './navigation.js';
6
+ export * from './host.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './bus.js';
2
+ export * from './providers.js';
3
+ export * from './table.js';
4
+ export * from './connection.js';
5
+ export * from './navigation.js';
6
+ export * from './host.js';
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Navigation partagée Shell ↔ application embarquée (protocole 1.1, additif).
3
+ *
4
+ * L'URL du Core reste la source de vérité, comme pour une app interne : `<base>/<route>/<chemin-de-l'app>?q#h`.
5
+ * Ce module ne contient que des fonctions pures (aucun accès au DOM), testées isolément.
6
+ */
7
+ import type { NavigationMode } from '@egen-civitas/esm-embed-protocol';
8
+ /** Paramètres jamais recopiés dans l'URL du Core (jetons, codes OAuth…). Comparaison insensible à la casse. */
9
+ export declare const DEFAULT_SENSITIVE_PARAMS: string[];
10
+ export declare const MAX_APP_PATH_LENGTH = 2000;
11
+ /** Mappage optionnel entre l'espace de chemins du Core et celui de l'application (flexibilité par app). */
12
+ export interface PathMap {
13
+ /** Chemin affiché dans le Core (`/dashboard/x`) → chemin interne de l'application. */
14
+ toApp?: (corePath: string) => string;
15
+ /** Chemin interne de l'application → chemin affiché dans le Core. */
16
+ toCore?: (appPath: string) => string;
17
+ }
18
+ export interface NavigationOptions {
19
+ /** Route de la page dans `routes.json` (`penpot`) : le Core est sur `<base>/<route>[/sous-chemin]`. */
20
+ route: string;
21
+ /** `history` (défaut), `hash`, ou `none` pour désactiver (comportement opaque d'origine). */
22
+ mode?: NavigationMode;
23
+ /** Paramètres supplémentaires à ne jamais recopier (s'ajoutent à `DEFAULT_SENSITIVE_PARAMS`). */
24
+ sensitiveParams?: string[];
25
+ pathMap?: PathMap;
26
+ /** Reçoit le titre annoncé par l'application (fil d'Ariane, titre de page). */
27
+ onTitle?: (title: string) => void;
28
+ }
29
+ /** Chemin interne sûr (`/x?y#z`), ou `null` : jamais d'URL absolue, de `//hôte`, d'espaces ni de caractères de contrôle. */
30
+ export declare function normalizeAppPath(input: unknown): string | null;
31
+ /** Retire les paramètres sensibles de la requête (et de la requête portée par le fragment `#/x?token=…`). */
32
+ export declare function stripSensitive(path: string, extra?: string[]): string;
33
+ /**
34
+ * Sous-chemin de l'application déduit de l'URL du Core, ou `null` si le Core n'est pas sur cette page.
35
+ * `pathname=/egen/spa/penpot/dashboard/x`, `spaBase=/egen/spa/`, `route=penpot` → `/dashboard/x` (`/` à la racine).
36
+ */
37
+ export declare function coreSubpath(pathname: string, spaBase: string, route: string): string | null;
38
+ /** URL du Core (chemin seul) pour un chemin d'application : `<base>/<route><chemin>`, sans `/` final superflu. */
39
+ export declare function buildCoreUrl(spaBase: string, route: string, appPath: string): string;
40
+ /**
41
+ * URL de chargement de l'iframe : l'adresse de base de l'application + le chemin interne.
42
+ * `history` : `<origine><chemin-de-base>/<chemin>?q#h` ; `hash` : `<base>#<chemin>`.
43
+ */
44
+ export declare function buildEmbedSrc(baseUrl: string, appPath: string, mode: NavigationMode): string;
45
+ /** Chemin d'application → chemin affiché par le Core (sans paramètres sensibles ; `pathMap.toCore` en dernier). */
46
+ export declare function toCorePath(appPath: unknown, opts: Pick<NavigationOptions, 'pathMap' | 'sensitiveParams'>): string | null;
47
+ /** Chemin lu dans l'URL du Core → chemin d'application (`pathMap.toApp` ; sans paramètres sensibles). */
48
+ export declare function toAppPath(corePath: string, opts: Pick<NavigationOptions, 'pathMap' | 'sensitiveParams'>): string | null;
49
+ /** Garde-fou de débit : au plus `max` messages par fenêtre `windowMs` (History API limitée par les navigateurs). */
50
+ export declare function createRateLimiter(max?: number, windowMs?: number, now?: () => number): () => boolean;
51
+ //# sourceMappingURL=navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,UAgBpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAIxC,2GAA2G;AAC3G,MAAM,WAAW,OAAO;IACtB,sFAAsF;IACtF,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACrC,qEAAqE;IACrE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,uGAAuG;IACvG,KAAK,EAAE,MAAM,CAAC;IACd,6FAA6F;IAC7F,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,iGAAiG;IACjG,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAMD,4HAA4H;AAC5H,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAG9D;AAED,6GAA6G;AAC7G,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,CAqBzE;AAUD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM3F;AAED,kHAAkH;AAClH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKpF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,MAAM,CAe5F;AAED,mHAAmH;AACnH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAAG,MAAM,GAAG,IAAI,CAMxH;AAED,yGAAyG;AACzG,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,iBAAiB,CAAC,GAAG,MAAM,GAAG,IAAI,CAMvH;AAED,oHAAoH;AACpH,wBAAgB,iBAAiB,CAAC,GAAG,SAAK,EAAE,QAAQ,SAAO,EAAE,GAAG,GAAE,MAAM,MAAyB,SAEpF,OAAO,CAOnB"}