@egen-civitas/esm-embed-host 0.2.0 → 0.4.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 +33 -0
- package/README.md +6 -7
- package/dist/connection.d.ts +0 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +4 -14
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +27 -84
- package/dist/providers.d.ts +15 -49
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +6 -300
- package/dist/table.d.ts +1 -4
- package/dist/table.d.ts.map +1 -1
- package/dist/table.js +38 -251
- package/package.json +3 -3
- package/src/connection.ts +1 -11
- package/src/host.ts +7 -11
- package/src/providers.ts +13 -88
- package/src/table.ts +23 -73
package/dist/table.js
CHANGED
|
@@ -6,9 +6,6 @@ function _array_like_to_array(arr, len) {
|
|
|
6
6
|
function _array_with_holes(arr) {
|
|
7
7
|
if (Array.isArray(arr)) return arr;
|
|
8
8
|
}
|
|
9
|
-
function _array_without_holes(arr) {
|
|
10
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
11
|
-
}
|
|
12
9
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
13
10
|
try {
|
|
14
11
|
var info = gen[key](arg);
|
|
@@ -38,9 +35,6 @@ function _async_to_generator(fn) {
|
|
|
38
35
|
});
|
|
39
36
|
};
|
|
40
37
|
}
|
|
41
|
-
function _iterable_to_array(iter) {
|
|
42
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
43
|
-
}
|
|
44
38
|
function _iterable_to_array_limit(arr, i) {
|
|
45
39
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
46
40
|
if (_i == null) return;
|
|
@@ -68,15 +62,9 @@ function _iterable_to_array_limit(arr, i) {
|
|
|
68
62
|
function _non_iterable_rest() {
|
|
69
63
|
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
70
64
|
}
|
|
71
|
-
function _non_iterable_spread() {
|
|
72
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
73
|
-
}
|
|
74
65
|
function _sliced_to_array(arr, i) {
|
|
75
66
|
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
76
67
|
}
|
|
77
|
-
function _to_consumable_array(arr) {
|
|
78
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
79
|
-
}
|
|
80
68
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
81
69
|
if (!o) return;
|
|
82
70
|
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
@@ -184,7 +172,7 @@ function _ts_generator(thisArg, body) {
|
|
|
184
172
|
};
|
|
185
173
|
}
|
|
186
174
|
}
|
|
187
|
-
import { CAPABILITIES,
|
|
175
|
+
import { CAPABILITIES, createSlidingLimiter, notificationPolicy, EmbedError, slotAllowed, topicAllowed } from '@egen-civitas/esm-embed-protocol';
|
|
188
176
|
/** Capacités que l'hôte sait servir avec ces fournisseurs. `navigation`, `lifecycle` et `telemetry` sont toujours servies. */ export function availableCapabilities(p) {
|
|
189
177
|
var s = new Set([
|
|
190
178
|
'navigation',
|
|
@@ -192,10 +180,6 @@ import { CAPABILITIES, DEFAULT_SESSION_FIELDS, EmbedError, pathAllowed, pickFiel
|
|
|
192
180
|
'telemetry'
|
|
193
181
|
]);
|
|
194
182
|
var map = [
|
|
195
|
-
[
|
|
196
|
-
'session',
|
|
197
|
-
p.session
|
|
198
|
-
],
|
|
199
183
|
[
|
|
200
184
|
'tenant',
|
|
201
185
|
p.tenant
|
|
@@ -204,10 +188,6 @@ import { CAPABILITIES, DEFAULT_SESSION_FIELDS, EmbedError, pathAllowed, pickFiel
|
|
|
204
188
|
'locale',
|
|
205
189
|
p.locale
|
|
206
190
|
],
|
|
207
|
-
[
|
|
208
|
-
'theme',
|
|
209
|
-
p.theme
|
|
210
|
-
],
|
|
211
191
|
[
|
|
212
192
|
'config',
|
|
213
193
|
p.config
|
|
@@ -216,10 +196,6 @@ import { CAPABILITIES, DEFAULT_SESSION_FIELDS, EmbedError, pathAllowed, pickFiel
|
|
|
216
196
|
'flags',
|
|
217
197
|
p.flags
|
|
218
198
|
],
|
|
219
|
-
[
|
|
220
|
-
'permissions',
|
|
221
|
-
p.permissions
|
|
222
|
-
],
|
|
223
199
|
[
|
|
224
200
|
'events',
|
|
225
201
|
p.events
|
|
@@ -233,12 +209,8 @@ import { CAPABILITIES, DEFAULT_SESSION_FIELDS, EmbedError, pathAllowed, pickFiel
|
|
|
233
209
|
p.dialogs
|
|
234
210
|
],
|
|
235
211
|
[
|
|
236
|
-
'
|
|
237
|
-
p.
|
|
238
|
-
],
|
|
239
|
-
[
|
|
240
|
-
'ai-tools',
|
|
241
|
-
p.aiTools
|
|
212
|
+
'extensions',
|
|
213
|
+
p.extensions
|
|
242
214
|
]
|
|
243
215
|
];
|
|
244
216
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
@@ -266,16 +238,9 @@ import { CAPABILITIES, DEFAULT_SESSION_FIELDS, EmbedError, pathAllowed, pickFiel
|
|
|
266
238
|
var list = function list(cfg, key) {
|
|
267
239
|
return Array.isArray(cfg === null || cfg === void 0 ? void 0 : cfg[key]) ? cfg[key] : [];
|
|
268
240
|
};
|
|
269
|
-
function normOrigin(u) {
|
|
270
|
-
try {
|
|
271
|
-
return new URL(u).origin;
|
|
272
|
-
} catch (unused) {
|
|
273
|
-
return u;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
241
|
/**
|
|
277
242
|
* Construit la table de dispatch FERMÉE d'une connexion : seules les capacités accordées (et servies) y figurent,
|
|
278
|
-
* chaque méthode applique son grant (
|
|
243
|
+
* chaque méthode applique son grant (sujets d'événements, slots découvrables, drapeaux).
|
|
279
244
|
*/ export function createCapabilityTable(o) {
|
|
280
245
|
var p = o.providers, c = o.controls;
|
|
281
246
|
var ctx = {
|
|
@@ -288,39 +253,9 @@ function normOrigin(u) {
|
|
|
288
253
|
];
|
|
289
254
|
}));
|
|
290
255
|
var table = {};
|
|
291
|
-
var registeredTools = new Set();
|
|
292
|
-
var sessionFields = function sessionFields() {
|
|
293
|
-
var f = list(cfgOf.get('session'), 'fields');
|
|
294
|
-
return f.length ? f : _to_consumable_array(DEFAULT_SESSION_FIELDS);
|
|
295
|
-
};
|
|
296
|
-
var pick = function pick(s) {
|
|
297
|
-
return pickFields(s, sessionFields());
|
|
298
|
-
};
|
|
299
256
|
var denied = function denied(msg) {
|
|
300
257
|
return new EmbedError('DENIED', msg);
|
|
301
258
|
};
|
|
302
|
-
if (cfgOf.has('session') && p.session) table.session = {
|
|
303
|
-
get: function get() {
|
|
304
|
-
return _async_to_generator(function() {
|
|
305
|
-
return _ts_generator(this, function(_state) {
|
|
306
|
-
switch(_state.label){
|
|
307
|
-
case 0:
|
|
308
|
-
return [
|
|
309
|
-
4,
|
|
310
|
-
p.session.get()
|
|
311
|
-
];
|
|
312
|
-
case 1:
|
|
313
|
-
return [
|
|
314
|
-
2,
|
|
315
|
-
pick.apply(void 0, [
|
|
316
|
-
_state.sent()
|
|
317
|
-
])
|
|
318
|
-
];
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
})();
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
259
|
if (cfgOf.has('tenant') && p.tenant) table.tenant = {
|
|
325
260
|
get: function get() {
|
|
326
261
|
return _async_to_generator(function() {
|
|
@@ -345,18 +280,6 @@ function normOrigin(u) {
|
|
|
345
280
|
})();
|
|
346
281
|
}
|
|
347
282
|
};
|
|
348
|
-
if (cfgOf.has('theme') && p.theme) table.theme = {
|
|
349
|
-
get: function get() {
|
|
350
|
-
return _async_to_generator(function() {
|
|
351
|
-
return _ts_generator(this, function(_state) {
|
|
352
|
-
return [
|
|
353
|
-
2,
|
|
354
|
-
p.theme.get()
|
|
355
|
-
];
|
|
356
|
-
});
|
|
357
|
-
})();
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
283
|
if (cfgOf.has('config') && p.config) table.config = {
|
|
361
284
|
get: function get() {
|
|
362
285
|
return _async_to_generator(function() {
|
|
@@ -369,18 +292,18 @@ function normOrigin(u) {
|
|
|
369
292
|
})();
|
|
370
293
|
}
|
|
371
294
|
};
|
|
372
|
-
if (cfgOf.has('
|
|
373
|
-
var
|
|
374
|
-
table.
|
|
375
|
-
|
|
295
|
+
if (cfgOf.has('flags') && p.flags) {
|
|
296
|
+
var names = list(cfgOf.get('flags'), 'names');
|
|
297
|
+
table.flags = {
|
|
298
|
+
isEnabled: function isEnabled(name) {
|
|
376
299
|
return _async_to_generator(function() {
|
|
377
300
|
return _ts_generator(this, function(_state) {
|
|
378
301
|
switch(_state.label){
|
|
379
302
|
case 0:
|
|
380
|
-
if (!
|
|
303
|
+
if (!names.includes(name)) throw denied("Drapeau non accessible : ".concat(name));
|
|
381
304
|
return [
|
|
382
305
|
4,
|
|
383
|
-
p.
|
|
306
|
+
p.flags.isEnabled(name)
|
|
384
307
|
];
|
|
385
308
|
case 1:
|
|
386
309
|
return [
|
|
@@ -393,23 +316,36 @@ function normOrigin(u) {
|
|
|
393
316
|
}
|
|
394
317
|
};
|
|
395
318
|
}
|
|
396
|
-
if (cfgOf.has('
|
|
397
|
-
var
|
|
398
|
-
table.
|
|
399
|
-
|
|
319
|
+
if (cfgOf.has('events') && p.events) {
|
|
320
|
+
var pub = list(cfgOf.get('events'), 'publish');
|
|
321
|
+
table.events = {
|
|
322
|
+
publish: function publish(topic, payload) {
|
|
323
|
+
if (!topicAllowed(pub, topic)) throw denied("Publication non autoris\xe9e sur : ".concat(topic));
|
|
324
|
+
p.events.publish(topic, payload, ctx);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (cfgOf.has('notifications') && p.notifications) {
|
|
329
|
+
// Anti-spam : une iframe ne doit pas pouvoir inonder l'interface du Core (ni imiter des messages système en rafale).
|
|
330
|
+
var policy = notificationPolicy(cfgOf.get('notifications'));
|
|
331
|
+
var allow = createSlidingLimiter(policy.rate.max, policy.rate.perSeconds);
|
|
332
|
+
table.notifications = {
|
|
333
|
+
show: function show(n) {
|
|
400
334
|
return _async_to_generator(function() {
|
|
335
|
+
var _tmp;
|
|
401
336
|
return _ts_generator(this, function(_state) {
|
|
402
337
|
switch(_state.label){
|
|
403
338
|
case 0:
|
|
404
|
-
if (!
|
|
339
|
+
if (!allow()) throw new EmbedError('RATE_LIMITED', 'Trop de notifications');
|
|
340
|
+
_tmp = {};
|
|
405
341
|
return [
|
|
406
342
|
4,
|
|
407
|
-
p.
|
|
343
|
+
p.notifications.show(n, ctx)
|
|
408
344
|
];
|
|
409
345
|
case 1:
|
|
410
346
|
return [
|
|
411
347
|
2,
|
|
412
|
-
|
|
348
|
+
(_tmp.displayed = _state.sent() !== false, _tmp)
|
|
413
349
|
];
|
|
414
350
|
}
|
|
415
351
|
});
|
|
@@ -417,35 +353,6 @@ function normOrigin(u) {
|
|
|
417
353
|
}
|
|
418
354
|
};
|
|
419
355
|
}
|
|
420
|
-
if (cfgOf.has('events') && p.events) {
|
|
421
|
-
var pub = list(cfgOf.get('events'), 'publish');
|
|
422
|
-
table.events = {
|
|
423
|
-
publish: function publish(topic, payload) {
|
|
424
|
-
if (!topicAllowed(pub, topic)) throw denied("Publication non autoris\xe9e sur : ".concat(topic));
|
|
425
|
-
p.events.publish(topic, payload, ctx);
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
}
|
|
429
|
-
if (cfgOf.has('notifications') && p.notifications) table.notifications = {
|
|
430
|
-
show: function show(n) {
|
|
431
|
-
return _async_to_generator(function() {
|
|
432
|
-
return _ts_generator(this, function(_state) {
|
|
433
|
-
switch(_state.label){
|
|
434
|
-
case 0:
|
|
435
|
-
return [
|
|
436
|
-
4,
|
|
437
|
-
p.notifications.show(n, ctx)
|
|
438
|
-
];
|
|
439
|
-
case 1:
|
|
440
|
-
return [
|
|
441
|
-
2,
|
|
442
|
-
void _state.sent()
|
|
443
|
-
];
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
})();
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
356
|
if (cfgOf.has('dialogs') && p.dialogs) table.dialogs = {
|
|
450
357
|
confirm: function confirm(d) {
|
|
451
358
|
return _async_to_generator(function() {
|
|
@@ -466,126 +373,22 @@ function normOrigin(u) {
|
|
|
466
373
|
})();
|
|
467
374
|
}
|
|
468
375
|
};
|
|
469
|
-
if (cfgOf.has('
|
|
470
|
-
var
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
return h.toLowerCase();
|
|
474
|
-
});
|
|
475
|
-
var paths = list(cfg, 'paths');
|
|
476
|
-
table.api = {
|
|
477
|
-
fetch: function fetch(req) {
|
|
376
|
+
if (cfgOf.has('extensions') && p.extensions) {
|
|
377
|
+
var discover = list(cfgOf.get('extensions'), 'discover');
|
|
378
|
+
table.extensions = {
|
|
379
|
+
list: function list(slot) {
|
|
478
380
|
return _async_to_generator(function() {
|
|
479
|
-
var _req_headers, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, h;
|
|
480
381
|
return _ts_generator(this, function(_state) {
|
|
481
|
-
if (
|
|
482
|
-
// Sans liste de chemins (deny-by-default) une app ne peut PAS appeler l'API du Core avec la session de l'utilisateur.
|
|
483
|
-
if (req.path !== undefined && !pathAllowed(paths, req.path)) throw denied("Chemin d'API non autoris\xe9 par le grant de l'app : ".concat(req.path));
|
|
484
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
485
|
-
try {
|
|
486
|
-
for(_iterator = Object.keys((_req_headers = req.headers) !== null && _req_headers !== void 0 ? _req_headers : {})[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
487
|
-
h = _step.value;
|
|
488
|
-
if (!headers.includes(h.toLowerCase())) throw denied("En-t\xeate non autoris\xe9 : ".concat(h));
|
|
489
|
-
}
|
|
490
|
-
} catch (err) {
|
|
491
|
-
_didIteratorError = true;
|
|
492
|
-
_iteratorError = err;
|
|
493
|
-
} finally{
|
|
494
|
-
try {
|
|
495
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
496
|
-
_iterator.return();
|
|
497
|
-
}
|
|
498
|
-
} finally{
|
|
499
|
-
if (_didIteratorError) {
|
|
500
|
-
throw _iteratorError;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
382
|
+
if (!slotAllowed(discover, slot)) throw denied("Slot non d\xe9couvrable par le grant de l'app : ".concat(slot));
|
|
504
383
|
return [
|
|
505
384
|
2,
|
|
506
|
-
p.
|
|
385
|
+
p.extensions.list(slot)
|
|
507
386
|
];
|
|
508
387
|
});
|
|
509
388
|
})();
|
|
510
389
|
}
|
|
511
390
|
};
|
|
512
391
|
}
|
|
513
|
-
if (cfgOf.has('ai-tools') && p.aiTools) {
|
|
514
|
-
var allowed = list(cfgOf.get('ai-tools'), 'tools');
|
|
515
|
-
table['ai-tools'] = {
|
|
516
|
-
register: function register(tools) {
|
|
517
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
518
|
-
try {
|
|
519
|
-
for(var _iterator = tools[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
520
|
-
var t = _step.value;
|
|
521
|
-
if (!topicAllowed(allowed, t.name)) throw denied("Outil non autoris\xe9 : ".concat(t.name));
|
|
522
|
-
}
|
|
523
|
-
} catch (err) {
|
|
524
|
-
_didIteratorError = true;
|
|
525
|
-
_iteratorError = err;
|
|
526
|
-
} finally{
|
|
527
|
-
try {
|
|
528
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
529
|
-
_iterator.return();
|
|
530
|
-
}
|
|
531
|
-
} finally{
|
|
532
|
-
if (_didIteratorError) {
|
|
533
|
-
throw _iteratorError;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
p.aiTools.register(o.moduleName, tools, function(name, args) {
|
|
538
|
-
return o.callApp('ai-tools', 'invoke', [
|
|
539
|
-
name,
|
|
540
|
-
args
|
|
541
|
-
]);
|
|
542
|
-
});
|
|
543
|
-
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
544
|
-
try {
|
|
545
|
-
for(var _iterator1 = tools[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
546
|
-
var t1 = _step1.value;
|
|
547
|
-
registeredTools.add(t1.name);
|
|
548
|
-
}
|
|
549
|
-
} catch (err) {
|
|
550
|
-
_didIteratorError1 = true;
|
|
551
|
-
_iteratorError1 = err;
|
|
552
|
-
} finally{
|
|
553
|
-
try {
|
|
554
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
555
|
-
_iterator1.return();
|
|
556
|
-
}
|
|
557
|
-
} finally{
|
|
558
|
-
if (_didIteratorError1) {
|
|
559
|
-
throw _iteratorError1;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
unregister: function unregister(names) {
|
|
565
|
-
p.aiTools.unregister(o.moduleName, names);
|
|
566
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
567
|
-
try {
|
|
568
|
-
for(var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
569
|
-
var n = _step.value;
|
|
570
|
-
registeredTools.delete(n);
|
|
571
|
-
}
|
|
572
|
-
} catch (err) {
|
|
573
|
-
_didIteratorError = true;
|
|
574
|
-
_iteratorError = err;
|
|
575
|
-
} finally{
|
|
576
|
-
try {
|
|
577
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
578
|
-
_iterator.return();
|
|
579
|
-
}
|
|
580
|
-
} finally{
|
|
581
|
-
if (_didIteratorError) {
|
|
582
|
-
throw _iteratorError;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
392
|
if (cfgOf.has('telemetry')) {
|
|
590
393
|
table.telemetry = {
|
|
591
394
|
log: function log(level, message, extra) {
|
|
@@ -629,22 +432,15 @@ function normOrigin(u) {
|
|
|
629
432
|
var desc = CAPABILITIES[cap];
|
|
630
433
|
if (!cfg || !desc || !table[cap]) return undefined;
|
|
631
434
|
if (cap === 'events') return topicAllowed(list(cfg, 'subscribe'), ev) ? p.events.subscribe(ev, emit) : undefined;
|
|
435
|
+
if (cap === 'extensions') return slotAllowed(list(cfg, 'discover'), ev) && p.extensions.subscribe ? p.extensions.subscribe(ev, emit) : undefined;
|
|
632
436
|
if (!desc.events.includes(ev)) return undefined;
|
|
633
437
|
switch(cap){
|
|
634
|
-
case 'session':
|
|
635
|
-
var _p_session_subscribe, _p_session;
|
|
636
|
-
return (_p_session_subscribe = (_p_session = p.session).subscribe) === null || _p_session_subscribe === void 0 ? void 0 : _p_session_subscribe.call(_p_session, function(v) {
|
|
637
|
-
return emit(pick(v));
|
|
638
|
-
});
|
|
639
438
|
case 'tenant':
|
|
640
439
|
var _p_tenant_subscribe, _p_tenant;
|
|
641
440
|
return (_p_tenant_subscribe = (_p_tenant = p.tenant).subscribe) === null || _p_tenant_subscribe === void 0 ? void 0 : _p_tenant_subscribe.call(_p_tenant, emit);
|
|
642
441
|
case 'locale':
|
|
643
442
|
var _p_locale_subscribe, _p_locale;
|
|
644
443
|
return (_p_locale_subscribe = (_p_locale = p.locale).subscribe) === null || _p_locale_subscribe === void 0 ? void 0 : _p_locale_subscribe.call(_p_locale, emit);
|
|
645
|
-
case 'theme':
|
|
646
|
-
var _p_theme_subscribe, _p_theme;
|
|
647
|
-
return (_p_theme_subscribe = (_p_theme = p.theme).subscribe) === null || _p_theme_subscribe === void 0 ? void 0 : _p_theme_subscribe.call(_p_theme, emit);
|
|
648
444
|
case 'config':
|
|
649
445
|
var _p_config_subscribe, _p_config;
|
|
650
446
|
return (_p_config_subscribe = (_p_config = p.config).subscribe) === null || _p_config_subscribe === void 0 ? void 0 : _p_config_subscribe.call(_p_config, emit);
|
|
@@ -653,11 +449,6 @@ function normOrigin(u) {
|
|
|
653
449
|
return (_p_flags_subscribe = (_p_flags = p.flags).subscribe) === null || _p_flags_subscribe === void 0 ? void 0 : _p_flags_subscribe.call(_p_flags, function() {
|
|
654
450
|
return emit();
|
|
655
451
|
});
|
|
656
|
-
case 'permissions':
|
|
657
|
-
var _p_permissions_subscribe, _p_permissions;
|
|
658
|
-
return (_p_permissions_subscribe = (_p_permissions = p.permissions).subscribe) === null || _p_permissions_subscribe === void 0 ? void 0 : _p_permissions_subscribe.call(_p_permissions, function() {
|
|
659
|
-
return emit();
|
|
660
|
-
});
|
|
661
452
|
case 'navigation':
|
|
662
453
|
case 'lifecycle':
|
|
663
454
|
return c.channel.on(ev, emit);
|
|
@@ -667,10 +458,6 @@ function normOrigin(u) {
|
|
|
667
458
|
};
|
|
668
459
|
return {
|
|
669
460
|
table: table,
|
|
670
|
-
subscribe: subscribe
|
|
671
|
-
cleanup: function cleanup() {
|
|
672
|
-
if (registeredTools.size && p.aiTools) p.aiTools.unregister(o.moduleName, _to_consumable_array(registeredTools));
|
|
673
|
-
registeredTools.clear();
|
|
674
|
-
}
|
|
461
|
+
subscribe: subscribe
|
|
675
462
|
};
|
|
676
463
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egen-civitas/esm-embed-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.3.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.4.0"
|
|
73
73
|
}
|
|
74
74
|
}
|
package/src/connection.ts
CHANGED
|
@@ -39,7 +39,6 @@ export class HostConnection {
|
|
|
39
39
|
state: ConnectionState = 'idle';
|
|
40
40
|
private nonce?: string;
|
|
41
41
|
private rpc?: RpcEndpoint;
|
|
42
|
-
private cleanup?: () => void;
|
|
43
42
|
|
|
44
43
|
constructor(private readonly o: ConnectionOptions) {}
|
|
45
44
|
|
|
@@ -76,18 +75,13 @@ export class HostConnection {
|
|
|
76
75
|
if (avail.has(g.id)) granted.push(g);
|
|
77
76
|
else denied.push({ id: g.id, reason: 'UNAVAILABLE' });
|
|
78
77
|
}
|
|
79
|
-
const { table, subscribe
|
|
78
|
+
const { table, subscribe } = createCapabilityTable({
|
|
80
79
|
moduleName: this.o.moduleName,
|
|
81
80
|
granted,
|
|
82
81
|
providers: this.o.providers,
|
|
83
82
|
controls: this.o.controls,
|
|
84
|
-
callApp: (cap, method, args) => {
|
|
85
|
-
if (!this.rpc) return Promise.reject(new Error('non connecté'));
|
|
86
|
-
return this.rpc.call(cap, method, args);
|
|
87
|
-
},
|
|
88
83
|
});
|
|
89
84
|
const { port1, port2 } = new MessageChannel();
|
|
90
|
-
this.cleanup = cleanup;
|
|
91
85
|
this.rpc = new RpcEndpoint({
|
|
92
86
|
port: port1,
|
|
93
87
|
handlers: table,
|
|
@@ -95,8 +89,6 @@ export class HostConnection {
|
|
|
95
89
|
validate: (cap, method, args) => validateCall(cap, method, args, 'app-to-host'),
|
|
96
90
|
limits: this.o.limits,
|
|
97
91
|
onClose: (reason) => {
|
|
98
|
-
this.cleanup?.();
|
|
99
|
-
this.cleanup = undefined;
|
|
100
92
|
if (this.state !== 'closed') this.state = 'idle';
|
|
101
93
|
this.o.onClose?.(reason);
|
|
102
94
|
},
|
|
@@ -119,8 +111,6 @@ export class HostConnection {
|
|
|
119
111
|
reset(): void {
|
|
120
112
|
this.rpc?.close();
|
|
121
113
|
this.rpc = undefined;
|
|
122
|
-
this.cleanup?.();
|
|
123
|
-
this.cleanup = undefined;
|
|
124
114
|
this.nonce = undefined;
|
|
125
115
|
if (this.state !== 'closed') this.state = 'idle';
|
|
126
116
|
}
|
package/src/host.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type CapabilityDenied, type CapabilityGranted, type EffectiveGrants, type Limits } 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';
|
|
@@ -124,12 +124,10 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
124
124
|
onClose: opts.onClose,
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
/** Pont 1.1 : mêmes services, ancien format. Inactif dès qu'une connexion v2 est ouverte. */
|
|
127
|
+
/**
|
|
128
|
+
* Pont 1.1 : compatibilité des apps qui ne parlent pas encore le protocole 2. La session n'est PLUS transmise (règle d'or,
|
|
129
|
+
* doc 17 §2) : une app obtient son identité auprès de Keycloak. Seuls restent la langue, la navigation, le titre et la hauteur.
|
|
130
|
+
*/
|
|
133
131
|
const handleLegacy = async (data: any) => {
|
|
134
132
|
if (opts.legacy === false || connection.connected) return;
|
|
135
133
|
if (!data || data.egen !== 1 || data.moduleName !== opts.moduleName || !data.message || typeof data.message.kind !== 'string') return;
|
|
@@ -138,9 +136,8 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
138
136
|
case 'ready': {
|
|
139
137
|
legacySeen = true;
|
|
140
138
|
legacyReady = true;
|
|
141
|
-
const session = opts.providers.session ? pickFields(await opts.providers.session.get(), sessionFields()) : undefined;
|
|
142
139
|
const locale = opts.providers.locale ? await opts.providers.locale.get() : (win as any).i18next?.language;
|
|
143
|
-
legacySend({ kind: 'init', payload: { moduleName: opts.moduleName, locale, spaBase: spaBase(),
|
|
140
|
+
legacySend({ kind: 'init', payload: { moduleName: opts.moduleName, locale, spaBase: spaBase(), navigation: nav ? { mode: nav.mode, route: nav.route } : undefined } });
|
|
144
141
|
break;
|
|
145
142
|
}
|
|
146
143
|
case 'navigate':
|
|
@@ -206,9 +203,8 @@ export function createEmbedHost(opts: EmbedHostOptions): EmbedHost {
|
|
|
206
203
|
win.removeEventListener('blur', onBlur);
|
|
207
204
|
});
|
|
208
205
|
|
|
209
|
-
// Pont 1.1 :
|
|
206
|
+
// Pont 1.1 : la langue est poussée après `ready`.
|
|
210
207
|
const p = opts.providers;
|
|
211
|
-
if (p.session?.subscribe) stop.push(p.session.subscribe((s) => legacyReady && !connection.connected && legacySend({ kind: 'session', session: pickFields(s, sessionFields()) })));
|
|
212
208
|
if (p.locale?.subscribe) stop.push(p.locale.subscribe((l) => legacyReady && !connection.connected && l && legacySend({ kind: 'locale', locale: l })));
|
|
213
209
|
|
|
214
210
|
container.appendChild(iframe);
|