@egen-civitas/esm-embed-testing 0.2.0 → 0.3.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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @egen-civitas/esm-embed-testing
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 36eb684: **Changement incompatible : le SDK est recentré sur ce dont le Core est lui-même la source.** Retrait des capacités `session`, `permissions`, `theme` et `api` (identité, droits, thème et appels API viennent de Keycloak, des backends et du service de thèmes ; le Core ne les relaie pas, ce qui supprime une classe entière de failles). Retrait de `pickFields`, des chemins d'API, de `createFetchApiProvider`, des hooks `useEgenSession`/`useEgenTheme`, et de la session dans le pont 1.1. Une demande de capacité retirée est rejetée avec la raison et la voie à suivre (`REMOVED_CAPABILITIES`).
8
+
9
+ Ajout de la capacité `extensions` (découverte des extensions d'un slot, grants `discover`/`contribute` par slot) et des contributions déclaratives `extensions[]` du manifeste (composants d'une app embarquée injectés dans les slots du Core), avec validation (`iconUrl` même origine, 4 Ko de meta) et `allowedContributions`. Hooks React `useEgenLocale`, `useEgenTenant`, `useEgenExtensions`.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [36eb684]
14
+ - @egen-civitas/esm-embed-protocol@0.3.0
15
+ - @egen-civitas/esm-embed-client@0.2.0
16
+ - @egen-civitas/esm-embed-host@0.3.0
17
+
3
18
  ## 0.2.0
4
19
 
5
20
  ### Minor Changes
package/README.md CHANGED
@@ -11,14 +11,14 @@ import { connectToEgen } from '@egen-civitas/esm-embed-client';
11
11
  import { createTestHost } from '@egen-civitas/esm-embed-testing';
12
12
 
13
13
  const sim = createTestHost({
14
- session: { authenticated: true, user: { display: 'Sam' } },
14
+ locale: 'fr',
15
15
  manifestCapabilities: { notifications: {} },
16
16
  approved: { notifications: {} },
17
17
  });
18
- const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['session', 'notifications'] });
18
+ const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['locale', 'notifications'] });
19
19
  await egen.notifications.show({ kind: 'success', title: 'OK' });
20
20
  expect(sim.notifications).toEqual([{ kind: 'success', title: 'OK' }]);
21
- sim.emit.theme({ mode: 'dark', tokens: { '--primary': '#000' } }); // le Core pousse un changement
21
+ sim.emit.locale('en'); // le Core pousse un changement
22
22
  ```
23
23
 
24
24
  `sim.calls` (journal des services sollicités), `sim.published`, `sim.tools` + `sim.invokeTool()` (agent IA), `sim.emit.*`.
@@ -38,4 +38,4 @@ npx egen-embed-sim --app http://localhost:3000 --manifest egen-app.json
38
38
  # → déclarez dans l'app : hostOrigins: ['http://127.0.0.1:4100']
39
39
  ```
40
40
 
41
- Page avec votre app dans une iframe, l'hôte EGEN réel (`esm-embed-host`), des boutons (thème, langue, session, événement) et le journal de tous les échanges. Par défaut les capacités demandées par le manifeste sont approuvées ; `--strict` n'approuve que les capacités « par défaut ».
41
+ Page avec votre app dans une iframe, l'hôte EGEN réel (`esm-embed-host`), des boutons (langue, événement, extensions) et le journal de tous les échanges. Par défaut les capacités demandées par le manifeste sont approuvées ; `--strict` n'approuve que les capacités « par défaut ».
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,2GAA2G;IAC3G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,+HAA+H;AAC/H,wBAAsB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CA2D1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,2GAA2G;IAC3G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,+HAA+H;AAC/H,wBAAsB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAuD1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
package/dist/check.js CHANGED
@@ -1,3 +1,11 @@
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
+ }
1
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
10
  try {
3
11
  var info = gen[key](arg);
@@ -27,6 +35,23 @@ function _async_to_generator(fn) {
27
35
  });
28
36
  };
29
37
  }
38
+ function _iterable_to_array(iter) {
39
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
40
+ }
41
+ function _non_iterable_spread() {
42
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
43
+ }
44
+ function _to_consumable_array(arr) {
45
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
46
+ }
47
+ function _unsupported_iterable_to_array(o, minLen) {
48
+ if (!o) return;
49
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
50
+ var n = Object.prototype.toString.call(o).slice(8, -1);
51
+ if (n === "Object" && o.constructor) n = o.constructor.name;
52
+ if (n === "Map" || n === "Set") return Array.from(n);
53
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
54
+ }
30
55
  function _ts_generator(thisArg, body) {
31
56
  var f, y, t, _ = {
32
57
  label: 0,
@@ -126,10 +151,10 @@ function _ts_generator(thisArg, body) {
126
151
  };
127
152
  }
128
153
  }
129
- import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest } from '@egen-civitas/esm-embed-protocol';
154
+ import { CAPABILITIES, patternCovers, validateManifest } from '@egen-civitas/esm-embed-protocol';
130
155
  /** Vérificateur d'app embarquée (`egen-embed-check`) : manifeste, hygiène des capacités demandées, intégrabilité en iframe. */ export function checkEmbedApp(o) {
131
156
  return _async_to_generator(function() {
132
- var _caps_session, _caps_events, _caps_aitools, _caps_api, _caps_api1, issues, add, r, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, m, caps, needApproval, fields, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, f, pub, own, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, p, tools, apiPaths, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, p1, hosts, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, h, _o_fetchImpl, f1, _res_headers_get, _exec_, _exec, res, xfo, csp, fa, tokens, e;
157
+ var _m_extensions, _m_extensions1, _caps_events, _caps_aitools, _caps_extensions, issues, add, r, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, m, caps, needApproval, pub, own, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, p, tools, slots, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, _$e1, discover, _o_fetchImpl, f, _res_headers_get, _exec_, _exec, res, xfo, csp, fa, tokens, e;
133
158
  return _ts_generator(this, function(_state) {
134
159
  switch(_state.label){
135
160
  case 0:
@@ -175,13 +200,15 @@ import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest
175
200
  return !CAPABILITIES[id].defaultGrant;
176
201
  });
177
202
  if (needApproval.length) add('info', "Capacit\xe9s \xe0 faire approuver par l'op\xe9rateur (grants) : ".concat(needApproval.join(', ')));
178
- fields = (_caps_session = caps.session) === null || _caps_session === void 0 ? void 0 : _caps_session.fields;
179
- if (Array.isArray(fields)) {
203
+ pub = (_caps_events = caps.events) === null || _caps_events === void 0 ? void 0 : _caps_events.publish;
204
+ if (Array.isArray(pub)) {
205
+ own = "app.".concat(m.route, ".*");
180
206
  _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
181
207
  try {
182
- for(_iterator1 = fields[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
183
- f = _step1.value;
184
- if (FORBIDDEN_SESSION_FIELDS.includes(String(f).split('.')[0])) add('error', "session.fields : \xab ".concat(f, " \xbb ne sera jamais transmis (identifiant de session ou jeton)"));
208
+ for(_iterator1 = pub[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
209
+ p = _step1.value;
210
+ if (p === '*' || /^\*/.test(String(p))) add('error', "events.publish : le motif \xab ".concat(p, " \xbb n'est pas support\xe9 (nommer le pr\xe9fixe, ex. ").concat(own, ")"));
211
+ else if (!patternCovers(own, String(p).replace(/\.\*$/, '.x'))) add('warn', "events.publish : \xab ".concat(p, " \xbb sort de l'espace conseill\xe9 ").concat(own));
185
212
  }
186
213
  } catch (err) {
187
214
  _didIteratorError1 = true;
@@ -198,89 +225,44 @@ import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest
198
225
  }
199
226
  }
200
227
  }
201
- pub = (_caps_events = caps.events) === null || _caps_events === void 0 ? void 0 : _caps_events.publish;
202
- if (Array.isArray(pub)) {
203
- own = "app.".concat(m.route, ".*");
204
- _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
205
- try {
206
- for(_iterator2 = pub[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
207
- p = _step2.value;
208
- if (p === '*' || /^\*/.test(String(p))) add('error', "events.publish : le motif \xab ".concat(p, " \xbb n'est pas support\xe9 (nommer le pr\xe9fixe, ex. ").concat(own, ")"));
209
- else if (!patternCovers(own, String(p).replace(/\.\*$/, '.x'))) add('warn', "events.publish : \xab ".concat(p, " \xbb sort de l'espace conseill\xe9 ").concat(own));
210
- }
211
- } catch (err) {
212
- _didIteratorError2 = true;
213
- _iteratorError2 = err;
214
- } finally{
215
- try {
216
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
217
- _iterator2.return();
218
- }
219
- } finally{
220
- if (_didIteratorError2) {
221
- throw _iteratorError2;
222
- }
223
- }
224
- }
225
- }
226
228
  tools = (_caps_aitools = caps['ai-tools']) === null || _caps_aitools === void 0 ? void 0 : _caps_aitools.tools;
227
229
  if (Array.isArray(tools) && tools.some(function(t) {
228
230
  return !String(t).includes('.');
229
231
  })) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
230
- if (caps.api && !(Array.isArray(caps.api.paths) && caps.api.paths.length) && !(Array.isArray(caps.api.hosts) && caps.api.hosts.length)) add('warn', 'api : ni paths ni hosts demandés : aucun appel ne sera possible (deny-by-default)');
231
- apiPaths = (_caps_api = caps.api) === null || _caps_api === void 0 ? void 0 : _caps_api.paths;
232
- if (Array.isArray(apiPaths)) {
233
- _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
234
- try {
235
- for(_iterator3 = apiPaths[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
236
- p1 = _step3.value;
237
- if (p1 === '/*' || p1 === '*') add('warn', "api.paths : \xab ".concat(p1, " \xbb ouvre toute l'API du Core avec la session de l'utilisateur ; nommer les chemins n\xe9cessaires"));
238
- }
239
- } catch (err) {
240
- _didIteratorError3 = true;
241
- _iteratorError3 = err;
242
- } finally{
243
- try {
244
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
245
- _iterator3.return();
246
- }
247
- } finally{
248
- if (_didIteratorError3) {
249
- throw _iteratorError3;
250
- }
251
- }
232
+ slots = _to_consumable_array(new Set(((_m_extensions = m.extensions) !== null && _m_extensions !== void 0 ? _m_extensions : []).map(function(e) {
233
+ return e.slot;
234
+ })));
235
+ if (slots.length) add('info', "Contributions d'extension : l'op\xe9rateur doit approuver les slots (extensions.contribute) : ".concat(slots.join(', ')));
236
+ _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
237
+ try {
238
+ for(_iterator2 = ((_m_extensions1 = m.extensions) !== null && _m_extensions1 !== void 0 ? _m_extensions1 : [])[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
239
+ _$e1 = _step2.value;
240
+ if (_$e1.view) add('info', "Extension \xab ".concat(_$e1.name, " \xbb : la vue ").concat(_$e1.view, " sera affich\xe9e dans une iframe du Core (frame-ancestors \xe0 autoriser pour le Shell, hauteur via navigation.resize)"));
252
241
  }
253
- }
254
- hosts = (_caps_api1 = caps.api) === null || _caps_api1 === void 0 ? void 0 : _caps_api1.hosts;
255
- if (Array.isArray(hosts)) {
256
- _iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined;
242
+ } catch (err) {
243
+ _didIteratorError2 = true;
244
+ _iteratorError2 = err;
245
+ } finally{
257
246
  try {
258
- for(_iterator4 = hosts[Symbol.iterator](); !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true){
259
- h = _step4.value;
260
- if (!/^https:\/\//i.test(String(h))) add('error', "api.hosts : \xab ".concat(h, " \xbb doit \xeatre une origine https"));
247
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
248
+ _iterator2.return();
261
249
  }
262
- } catch (err) {
263
- _didIteratorError4 = true;
264
- _iteratorError4 = err;
265
250
  } finally{
266
- try {
267
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
268
- _iterator4.return();
269
- }
270
- } finally{
271
- if (_didIteratorError4) {
272
- throw _iteratorError4;
273
- }
251
+ if (_didIteratorError2) {
252
+ throw _iteratorError2;
274
253
  }
275
254
  }
276
255
  }
256
+ discover = (_caps_extensions = caps.extensions) === null || _caps_extensions === void 0 ? void 0 : _caps_extensions.discover;
257
+ if (Array.isArray(discover) && discover.some(function(s) {
258
+ return s === '*';
259
+ })) add('error', "extensions.discover : le motif « * » n'est pas supporté (nommer les slots)");
277
260
  if (m.technology === 'nextjs' && m.navigation.mode === 'none') add('info', 'Next.js avec navigation « none » : l’URL du Core ne reflétera pas la page courante (partage de lien, F5)');
278
- if (!caps.lifecycle && !caps.navigation) add('info', 'Aucune capacité navigation/lifecycle demandée : l’app ne pourra ni redimensionner l’iframe ni signaler qu’elle est prête (valeurs par défaut accordées si utilisées)');
279
261
  if (!o.probe) return [
280
262
  3,
281
263
  4
282
264
  ];
283
- f1 = (_o_fetchImpl = o.fetchImpl) !== null && _o_fetchImpl !== void 0 ? _o_fetchImpl : fetch;
265
+ f = (_o_fetchImpl = o.fetchImpl) !== null && _o_fetchImpl !== void 0 ? _o_fetchImpl : fetch;
284
266
  _state.label = 1;
285
267
  case 1:
286
268
  _state.trys.push([
@@ -291,7 +273,7 @@ import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest
291
273
  ]);
292
274
  return [
293
275
  4,
294
- f1(m.url, {
276
+ f(m.url, {
295
277
  redirect: 'manual',
296
278
  signal: AbortSignal.timeout(10000)
297
279
  })
@@ -202,7 +202,7 @@ import { createTestHost } from './test-host.js';
202
202
  4,
203
203
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
204
204
  capabilities: [
205
- 'session'
205
+ 'tenant'
206
206
  ]
207
207
  }))
208
208
  ];
@@ -243,7 +243,7 @@ import { createTestHost } from './test-host.js';
243
243
  expect(c.connected).toBe(false);
244
244
  return [
245
245
  4,
246
- expect(c.session.get()).rejects.toMatchObject({
246
+ expect(c.tenant.get()).rejects.toMatchObject({
247
247
  code: 'DENIED'
248
248
  })
249
249
  ];
@@ -321,47 +321,39 @@ import { createTestHost } from './test-host.js';
321
321
  });
322
322
  })();
323
323
  });
324
- it('session : champs listés seulement, jamais de sessionId', function() {
324
+ it('règle d’or : identité, droits, thème et api ne sont pas des capacités du SDK', function() {
325
325
  return _async_to_generator(function() {
326
- var sim, c, s;
326
+ var sim, c;
327
327
  return _ts_generator(this, function(_state) {
328
328
  switch(_state.label){
329
329
  case 0:
330
- sim = createTestHost({
331
- session: {
332
- authenticated: true,
333
- sessionId: 'SECRET',
334
- user: {
335
- uuid: 'u',
336
- display: 'Sam',
337
- email: 'e@x.y'
338
- }
339
- }
340
- });
330
+ sim = createTestHost();
341
331
  return [
342
332
  4,
343
333
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
344
334
  capabilities: [
345
- 'session'
335
+ 'tenant',
336
+ 'session',
337
+ 'theme',
338
+ 'permissions',
339
+ 'api'
346
340
  ]
347
341
  }))
348
342
  ];
349
343
  case 1:
350
344
  c = _state.sent();
351
- return [
352
- 4,
353
- c.session.get()
354
- ];
355
- case 2:
356
- s = _state.sent();
357
- expect(JSON.stringify(s)).not.toMatch(/SECRET|e@x\.y/);
358
- expect(s).toMatchObject({
359
- authenticated: true,
360
- user: {
361
- uuid: 'u',
362
- display: 'Sam'
363
- }
364
- });
345
+ expect(c.has('tenant')).toBe(true);
346
+ expect(c.denied.map(function(d) {
347
+ return d.id;
348
+ }).sort()).toEqual([
349
+ 'api',
350
+ 'permissions',
351
+ 'session',
352
+ 'theme'
353
+ ]);
354
+ expect(c.denied.every(function(d) {
355
+ return d.reason === 'UNKNOWN';
356
+ })).toBe(true);
365
357
  c.close();
366
358
  sim.destroy();
367
359
  return [
@@ -382,25 +374,26 @@ import { createTestHost } from './test-host.js';
382
374
  4,
383
375
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
384
376
  capabilities: [
385
- 'session',
386
- 'api',
377
+ 'tenant',
378
+ 'events',
387
379
  'notifications'
388
380
  ]
389
381
  }))
390
382
  ];
391
383
  case 1:
392
384
  c = _state.sent();
393
- expect(c.has('api')).toBe(false);
385
+ expect(c.has('events')).toBe(false);
394
386
  expect(c.denied.map(function(d) {
395
387
  return d.id;
396
388
  }).sort()).toEqual([
397
- 'api',
389
+ 'events',
398
390
  'notifications'
399
391
  ]);
400
392
  return [
401
393
  4,
402
- expect(c.api.fetch({
403
- path: '/x'
394
+ expect(c.notifications.show({
395
+ kind: 'info',
396
+ title: 'x'
404
397
  })).rejects.toMatchObject({
405
398
  code: 'DENIED'
406
399
  })
@@ -408,7 +401,7 @@ import { createTestHost } from './test-host.js';
408
401
  case 2:
409
402
  _state.sent();
410
403
  expect(sim.calls.some(function(x) {
411
- return x.cap === 'api';
404
+ return x.cap === 'notifications';
412
405
  })).toBe(false);
413
406
  c.close();
414
407
  sim.destroy();
@@ -419,59 +412,43 @@ import { createTestHost } from './test-host.js';
419
412
  });
420
413
  })();
421
414
  });
422
- it('changements poussés par l’hôte (thème)', function() {
415
+ it('changements poussés par l’hôte (langue)', function() {
423
416
  return _async_to_generator(function() {
424
- var sim, c, themes;
417
+ var sim, c, seen;
425
418
  return _ts_generator(this, function(_state) {
426
419
  switch(_state.label){
427
420
  case 0:
428
421
  sim = createTestHost({
429
- theme: {
430
- mode: 'light',
431
- tokens: {
432
- '--p': '#fff'
433
- }
434
- }
422
+ locale: 'fr'
435
423
  });
436
424
  return [
437
425
  4,
438
426
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
439
427
  capabilities: [
440
- 'session',
441
- 'theme'
428
+ 'locale'
442
429
  ]
443
430
  }))
444
431
  ];
445
432
  case 1:
446
433
  c = _state.sent();
447
- themes = [];
434
+ seen = [];
448
435
  return [
449
436
  4,
450
- c.theme.onChange(function(x) {
451
- return themes.push(x);
437
+ c.locale.onChange(function(x) {
438
+ return seen.push(x);
452
439
  })
453
440
  ];
454
441
  case 2:
455
442
  _state.sent();
456
- sim.emit.theme({
457
- mode: 'dark',
458
- tokens: {
459
- '--p': '#000'
460
- }
461
- });
443
+ sim.emit.locale('en');
462
444
  return [
463
445
  4,
464
446
  tick()
465
447
  ];
466
448
  case 3:
467
449
  _state.sent();
468
- expect(themes).toEqual([
469
- {
470
- mode: 'dark',
471
- tokens: {
472
- '--p': '#000'
473
- }
474
- }
450
+ expect(seen).toEqual([
451
+ 'en'
475
452
  ]);
476
453
  c.close();
477
454
  sim.destroy();
@@ -482,20 +459,37 @@ import { createTestHost } from './test-host.js';
482
459
  });
483
460
  })();
484
461
  });
485
- it('thème : variables CSS invalides ignorées (pas d’injection)', function() {
462
+ it('extensions : découverte limitée aux slots approuvés', function() {
486
463
  return _async_to_generator(function() {
487
- var set, sim, c;
464
+ var list, sim, c;
488
465
  return _ts_generator(this, function(_state) {
489
466
  switch(_state.label){
490
467
  case 0:
491
- set = {};
468
+ list = [
469
+ {
470
+ name: 'nav-x',
471
+ moduleName: '@egen/esm-x-app',
472
+ meta: {
473
+ label: 'X'
474
+ }
475
+ }
476
+ ];
492
477
  sim = createTestHost({
493
- theme: {
494
- mode: 'dark',
495
- tokens: {
496
- '--ok': '#111',
497
- color: 'red',
498
- '--bad': 'x;}body{display:none'
478
+ extensions: {
479
+ 'topbar-nav-slot': list
480
+ },
481
+ manifestCapabilities: {
482
+ extensions: {
483
+ discover: [
484
+ 'topbar-nav-slot'
485
+ ]
486
+ }
487
+ },
488
+ approved: {
489
+ extensions: {
490
+ discover: [
491
+ 'topbar-nav-slot'
492
+ ]
499
493
  }
500
494
  }
501
495
  });
@@ -503,7 +497,7 @@ import { createTestHost } from './test-host.js';
503
497
  4,
504
498
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
505
499
  capabilities: [
506
- 'theme'
500
+ 'extensions'
507
501
  ]
508
502
  }))
509
503
  ];
@@ -511,19 +505,18 @@ import { createTestHost } from './test-host.js';
511
505
  c = _state.sent();
512
506
  return [
513
507
  4,
514
- c.theme.sync({
515
- style: {
516
- setProperty: function setProperty(k, v) {
517
- return set[k] = v;
518
- }
519
- }
520
- })
508
+ expect(c.extensions.list('topbar-nav-slot')).resolves.toEqual(list)
521
509
  ];
522
510
  case 2:
523
511
  _state.sent();
524
- expect(set).toEqual({
525
- '--ok': '#111'
526
- });
512
+ return [
513
+ 4,
514
+ expect(c.extensions.list('shell-rail-left-slot')).rejects.toMatchObject({
515
+ code: 'DENIED'
516
+ })
517
+ ];
518
+ case 3:
519
+ _state.sent();
527
520
  c.close();
528
521
  sim.destroy();
529
522
  return [
@@ -544,7 +537,7 @@ import { createTestHost } from './test-host.js';
544
537
  4,
545
538
  connect(_object_spread_props(_object_spread({}, sim.connectOptions), {
546
539
  capabilities: [
547
- 'session'
540
+ 'tenant'
548
541
  ]
549
542
  }))
550
543
  ];
@@ -553,7 +546,7 @@ import { createTestHost } from './test-host.js';
553
546
  c.close();
554
547
  return [
555
548
  4,
556
- expect(c.session.get()).rejects.toMatchObject({
549
+ expect(c.tenant.get()).rejects.toMatchObject({
557
550
  code: 'DENIED'
558
551
  })
559
552
  ];
package/dist/server.d.ts CHANGED
@@ -8,7 +8,6 @@ export interface SimulatorOptions {
8
8
  manifest?: unknown;
9
9
  /** Approuver toutes les capacités demandées (défaut) ou seulement celles « par défaut » (`strict`). */
10
10
  strict?: boolean;
11
- session?: Record<string, unknown>;
12
11
  }
13
12
  export interface Simulator {
14
13
  url: string;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAOtD,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4GAA4G;IAC5G,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uGAAuG;IACvG,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAkBD,wBAAsB,cAAc,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAyC5E"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAOtD,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,4GAA4G;IAC5G,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uGAAuG;IACvG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAkBD,wBAAsB,cAAc,CAAC,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAyC5E"}
package/dist/server.js CHANGED
@@ -168,7 +168,7 @@ function approvedFor(manifest, strict) {
168
168
  }
169
169
  export function startSimulator(o) {
170
170
  return _async_to_generator(function() {
171
- var _ref, _o_session, _o_host, appUrl, manifest, r, config, roots, server, addr;
171
+ var _ref, _o_host, appUrl, manifest, r, config, roots, server, addr;
172
172
  return _ts_generator(this, function(_state) {
173
173
  switch(_state.label){
174
174
  case 0:
@@ -185,15 +185,18 @@ export function startSimulator(o) {
185
185
  moduleName: (_ref = manifest === null || manifest === void 0 ? void 0 : manifest.name) !== null && _ref !== void 0 ? _ref : '@acme/esm-sim-app',
186
186
  manifestCapabilities: manifest === null || manifest === void 0 ? void 0 : manifest.capabilities,
187
187
  approved: approvedFor(manifest, !!o.strict),
188
- session: (_o_session = o.session) !== null && _o_session !== void 0 ? _o_session : {
189
- authenticated: true,
190
- locale: 'fr',
191
- user: {
192
- uuid: 'sim-user',
193
- display: 'Utilisateur simulé',
194
- username: 'sim'
195
- },
196
- sessionId: 'NE-DOIT-JAMAIS-ETRE-VISIBLE'
188
+ extensions: {
189
+ 'topbar-nav-slot': [
190
+ {
191
+ name: 'nav-demo',
192
+ moduleName: '@egen/esm-demo-app',
193
+ order: 1,
194
+ meta: {
195
+ label: 'Démo',
196
+ route: 'demo'
197
+ }
198
+ }
199
+ ]
197
200
  }
198
201
  };
199
202
  roots = {
@@ -307,4 +310,4 @@ export function startSimulator(o) {
307
310
  });
308
311
  })();
309
312
  }
310
- var PAGE = "<!doctype html><html lang=\"fr\"><head><meta charset=\"utf-8\"><title>EGEN — simulateur de Shell</title>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<script type=\"importmap\">{\"imports\":{\"@egen-civitas/esm-embed-protocol\":\"/vendor/protocol/index.js\"}}</script>\n<style>\n:root{color-scheme:light dark;--b:#d0d7de;font-family:system-ui,sans-serif}\nbody{margin:0;display:grid;grid-template-columns:1fr 360px;height:100vh}\n#stage{min-width:0;display:flex}#stage iframe{flex:1;border:0}\naside{border-left:1px solid var(--b);padding:12px;overflow:auto;font-size:13px}\nbutton{margin:2px 4px 2px 0;padding:4px 8px;cursor:pointer}\npre{white-space:pre-wrap;word-break:break-word;font-size:12px;max-height:50vh;overflow:auto;border:1px solid var(--b);padding:6px;border-radius:6px}\n.toast{border:1px solid var(--b);border-radius:6px;padding:6px;margin:4px 0}\nh1{font-size:14px;margin:0 0 8px}h2{font-size:12px;margin:12px 0 4px;text-transform:uppercase;opacity:.7}\n</style></head><body>\n<div id=\"stage\"></div>\n<aside><h1>Simulateur de Shell EGEN</h1>\n<div id=\"info\"></div>\n<h2>Pousser vers l'app</h2>\n<button id=\"theme\">Th\xe8me clair/sombre</button><button id=\"locale\">Langue fr/en</button><button id=\"session\">Session (autre nom)</button><button id=\"event\">\xc9v\xe9nement core.sim.ping</button>\n<h2>Notifications</h2><div id=\"toasts\"></div>\n<h2>Journal des \xe9changes</h2><pre id=\"log\"></pre></aside>\n<script type=\"module\">\nimport { effectiveGrants } from '@egen-civitas/esm-embed-protocol';\nimport { createEmbedHost } from '/vendor/host/index.js';\nconst cfg = await (await fetch('/api/config')).json();\nconst $ = (id) => document.getElementById(id);\nconst log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };\nconst watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };\nconst session = watch(cfg.session), theme = watch({ mode: 'light', tokens: { '--primary': '#2563eb', '--background': '#ffffff', '--foreground': '#111111' } }), locale = watch('fr');\nconst tenant = watch({ id: 'sim-tenant' }), conf = watch({});\nconst topics = new Map();\nconst wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));\nconst providers = {\n session: wrap('session', session), theme: wrap('theme', theme), locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),\n flags: wrap('flags', { isEnabled: () => true }), permissions: wrap('permissions', { can: () => true }),\n events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },\n notifications: { show: (n) => { log('← notifications.show', n); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); } },\n dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },\n api: { fetch: async (r) => { log('← api.fetch', r); return { status: 200, headers: { 'content-type': 'application/json' }, body: JSON.stringify({ simulated: true, request: r }) }; } },\n telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },\n aiTools: { register: (m, t) => log('← ai-tools.register', t.map((x) => x.name)), unregister: (m, n) => log('← ai-tools.unregister', n) },\n};\nconst grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);\n$('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins \xe0 d\xe9clarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacit\xe9s accord\xe9es</b> ' + Object.keys(grants).join(', ');\nconst host = createEmbedHost({ moduleName: cfg.moduleName, src: cfg.app, grants, providers, onConnect: (g, d) => log('✔ connect\xe9', { accord\xe9es: g.map((x) => x.id), refus\xe9es: d }), onClose: (r) => log('✖ ferm\xe9', r) });\nhost.mount($('stage'));\n$('theme').onclick = () => { const t = theme.get(); const dark = t.mode !== 'dark'; theme.set({ mode: dark ? 'dark' : 'light', tokens: { ...t.tokens, '--background': dark ? '#0b0b0f' : '#ffffff', '--foreground': dark ? '#f5f5f5' : '#111111' } }); };\n$('locale').onclick = () => locale.set(locale.get() === 'fr' ? 'en' : 'fr');\n$('session').onclick = () => { const s = session.get(); session.set({ ...s, user: { ...s.user, display: 'Autre ' + Math.floor(Math.random() * 100) } }); };\n$('event').onclick = () => (topics.get('core.sim.ping') || []).forEach((f) => f({ at: Date.now() }));\n</script></body></html>";
313
+ var PAGE = "<!doctype html><html lang=\"fr\"><head><meta charset=\"utf-8\"><title>EGEN — simulateur de Shell</title>\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n<script type=\"importmap\">{\"imports\":{\"@egen-civitas/esm-embed-protocol\":\"/vendor/protocol/index.js\"}}</script>\n<style>\n:root{color-scheme:light dark;--b:#d0d7de;font-family:system-ui,sans-serif}\nbody{margin:0;display:grid;grid-template-columns:1fr 360px;height:100vh}\n#stage{min-width:0;display:flex}#stage iframe{flex:1;border:0}\naside{border-left:1px solid var(--b);padding:12px;overflow:auto;font-size:13px}\nbutton{margin:2px 4px 2px 0;padding:4px 8px;cursor:pointer}\npre{white-space:pre-wrap;word-break:break-word;font-size:12px;max-height:50vh;overflow:auto;border:1px solid var(--b);padding:6px;border-radius:6px}\n.toast{border:1px solid var(--b);border-radius:6px;padding:6px;margin:4px 0}\nh1{font-size:14px;margin:0 0 8px}h2{font-size:12px;margin:12px 0 4px;text-transform:uppercase;opacity:.7}\n</style></head><body>\n<div id=\"stage\"></div>\n<aside><h1>Simulateur de Shell EGEN</h1>\n<div id=\"info\"></div>\n<h2>Pousser vers l'app</h2>\n<button id=\"locale\">Langue fr/en</button><button id=\"event\">\xc9v\xe9nement core.sim.ping</button><button id=\"ext\">Changer les extensions de topbar-nav-slot</button>\n<h2>Notifications</h2><div id=\"toasts\"></div>\n<h2>Journal des \xe9changes</h2><pre id=\"log\"></pre></aside>\n<script type=\"module\">\nimport { effectiveGrants } from '@egen-civitas/esm-embed-protocol';\nimport { createEmbedHost } from '/vendor/host/index.js';\nconst cfg = await (await fetch('/api/config')).json();\nconst $ = (id) => document.getElementById(id);\nconst log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };\nconst watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };\nconst locale = watch('fr'), tenant = watch({ id: 'sim-tenant' }), conf = watch({});\nconst topics = new Map();\nconst extState = new Map(Object.entries(cfg.extensions)), extSubs = new Map();\nconst wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));\nconst providers = {\n locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),\n flags: wrap('flags', { isEnabled: () => true }),\n extensions: { list: (slot) => { log('← extensions.list', slot); return extState.get(slot) || []; }, subscribe: (slot, cb) => { const s = extSubs.get(slot) || new Set(); s.add(cb); extSubs.set(slot, s); return () => s.delete(cb); } },\n events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },\n notifications: { show: (n) => { log('← notifications.show', n); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); } },\n dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },\n telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },\n aiTools: { register: (m, t) => log('← ai-tools.register', t.map((x) => x.name)), unregister: (m, n) => log('← ai-tools.unregister', n) },\n};\nconst grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);\n$('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins \xe0 d\xe9clarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacit\xe9s accord\xe9es</b> ' + Object.keys(grants).join(', ');\nconst host = createEmbedHost({ moduleName: cfg.moduleName, src: cfg.app, grants, providers, onConnect: (g, d) => log('✔ connect\xe9', { accord\xe9es: g.map((x) => x.id), refus\xe9es: d }), onClose: (r) => log('✖ ferm\xe9', r) });\nhost.mount($('stage'));\n$('locale').onclick = () => locale.set(locale.get() === 'fr' ? 'en' : 'fr');\n$('event').onclick = () => (topics.get('core.sim.ping') || []).forEach((f) => f({ at: Date.now() }));\n$('ext').onclick = () => { const n = [{ name: 'nav-' + Math.floor(Math.random() * 100), moduleName: '@egen/esm-demo-app', meta: { label: 'Nouvelle extension' } }]; extState.set('topbar-nav-slot', n); (extSubs.get('topbar-nav-slot') || []).forEach((f) => f(n)); };\n</script></body></html>";
@@ -1,6 +1,6 @@
1
1
  import { type ApprovedGrants, type CapabilityId, type GrantConfig } from '@egen-civitas/esm-embed-protocol';
2
2
  import type { ConnectOptions } from '@egen-civitas/esm-embed-client';
3
- import { HostConnection, type ApiRequest, type ApiResponse, type ThemeState } from '@egen-civitas/esm-embed-host';
3
+ import { HostConnection, type ExtensionInfo } from '@egen-civitas/esm-embed-host';
4
4
  export interface TestHostOptions {
5
5
  moduleName?: string;
6
6
  /** Origine simulée du Shell (à mettre dans `hostOrigins` de l'app). */
@@ -9,17 +9,14 @@ export interface TestHostOptions {
9
9
  manifestCapabilities?: Partial<Record<CapabilityId, GrantConfig>>;
10
10
  /** Plafond fixé par l'opérateur (défaut : rien d'approuvé hors capacités « par défaut »). */
11
11
  approved?: ApprovedGrants;
12
- session?: Record<string, unknown>;
13
12
  tenant?: {
14
13
  id: string | null;
15
14
  };
16
15
  locale?: string;
17
- theme?: ThemeState;
18
16
  config?: Record<string, unknown>;
19
17
  flags?: Record<string, boolean>;
20
- /** Permissions que l'utilisateur simulé possède. */
21
- permissions?: string[];
22
- api?: (req: ApiRequest) => ApiResponse | Promise<ApiResponse>;
18
+ /** Extensions attachées à chaque slot (`{ 'topbar-nav-slot': [...] }`). */
19
+ extensions?: Record<string, ExtensionInfo[]>;
23
20
  confirm?: boolean | ((d: {
24
21
  title: string;
25
22
  message: string;
@@ -52,12 +49,11 @@ export interface TestHost {
52
49
  }>;
53
50
  /** Pousse un changement vers l'app (comme le ferait le Core). */
54
51
  emit: {
55
- session(v: Record<string, unknown>): void;
56
52
  tenant(v: {
57
53
  id: string | null;
58
54
  }): void;
59
55
  locale(v: string): void;
60
- theme(v: ThemeState): void;
56
+ extensions(slot: string, list: ExtensionInfo[]): void;
61
57
  config(v: Record<string, unknown>): void;
62
58
  event(topic: string, payload?: unknown): void;
63
59
  goto(path: string): void;
@@ -72,8 +68,8 @@ export interface TestHost {
72
68
  * relié à votre app par de fausses fenêtres et un vrai `MessageChannel`. Aucun navigateur, aucun Core.
73
69
  *
74
70
  * ```ts
75
- * const sim = createTestHost({ session: { authenticated: true, user: { display: 'Sam' } } });
76
- * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['session'] });
71
+ * const sim = createTestHost({ locale: 'fr', tenant: { id: 'acme' } });
72
+ * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['locale', 'tenant'] });
77
73
  * ```
78
74
  */
79
75
  export declare function createTestHost(o?: TestHostOptions): TestHost;
@@ -1 +1 @@
1
- {"version":3,"file":"test-host.d.ts","sourceRoot":"","sources":["../src/test-host.ts"],"names":[],"mappings":"AAAA,OA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,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;QACzC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;KACpC,CAAC;IACF,qDAAqD;IACrD,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3E,OAAO,IAAI,IAAI,CAAC;CACjB;AAeD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAE,eAAoB,GAAG,QAAQ,CAiJhE"}
package/dist/test-host.js CHANGED
@@ -153,12 +153,12 @@ function watchable(initial) {
153
153
  * relié à votre app par de fausses fenêtres et un vrai `MessageChannel`. Aucun navigateur, aucun Core.
154
154
  *
155
155
  * ```ts
156
- * const sim = createTestHost({ session: { authenticated: true, user: { display: 'Sam' } } });
157
- * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['session'] });
156
+ * const sim = createTestHost({ locale: 'fr', tenant: { id: 'acme' } });
157
+ * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['locale', 'tenant'] });
158
158
  * ```
159
159
  */ export function createTestHost() {
160
160
  var o = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
161
- var _o_moduleName, _o_origin, _o_session, _o_tenant, _o_locale, _o_theme, _o_config, _o_approved;
161
+ var _o_moduleName, _o_origin, _o_tenant, _o_locale, _o_extensions, _o_config, _o_approved;
162
162
  var moduleName = (_o_moduleName = o.moduleName) !== null && _o_moduleName !== void 0 ? _o_moduleName : '@acme/esm-test-app';
163
163
  var origin = (_o_origin = o.origin) !== null && _o_origin !== void 0 ? _o_origin : 'https://shell.test';
164
164
  var calls = [];
@@ -176,17 +176,12 @@ function watchable(initial) {
176
176
  args: args
177
177
  });
178
178
  };
179
- var session = watchable((_o_session = o.session) !== null && _o_session !== void 0 ? _o_session : {
180
- authenticated: true
181
- });
182
179
  var tenant = watchable((_o_tenant = o.tenant) !== null && _o_tenant !== void 0 ? _o_tenant : {
183
180
  id: null
184
181
  });
185
182
  var locale = watchable((_o_locale = o.locale) !== null && _o_locale !== void 0 ? _o_locale : 'fr');
186
- var theme = watchable((_o_theme = o.theme) !== null && _o_theme !== void 0 ? _o_theme : {
187
- mode: 'light',
188
- tokens: {}
189
- });
183
+ var extList = new Map(Object.entries((_o_extensions = o.extensions) !== null && _o_extensions !== void 0 ? _o_extensions : {}));
184
+ var extSubs = new Map();
190
185
  var config = watchable((_o_config = o.config) !== null && _o_config !== void 0 ? _o_config : {});
191
186
  var flagSubs = new Set();
192
187
  var eventSubs = new Map();
@@ -201,10 +196,8 @@ function watchable(initial) {
201
196
  };
202
197
  };
203
198
  var providers = {
204
- session: wrapWatch('session', session),
205
199
  tenant: wrapWatch('tenant', tenant),
206
200
  locale: wrapWatch('locale', locale),
207
- theme: wrapWatch('theme', theme),
208
201
  config: wrapWatch('config', config),
209
202
  flags: {
210
203
  isEnabled: function isEnabled(n) {
@@ -218,11 +211,19 @@ function watchable(initial) {
218
211
  };
219
212
  }
220
213
  },
221
- permissions: {
222
- can: function can(p) {
223
- var _o_permissions;
224
- log('permissions', 'can', p);
225
- return !!((_o_permissions = o.permissions) === null || _o_permissions === void 0 ? void 0 : _o_permissions.includes(p));
214
+ extensions: {
215
+ list: function list(slot) {
216
+ var _extList_get;
217
+ log('extensions', 'list', slot);
218
+ return (_extList_get = extList.get(slot)) !== null && _extList_get !== void 0 ? _extList_get : [];
219
+ },
220
+ subscribe: function subscribe(slot, cb) {
221
+ var set = extSubs.get(slot);
222
+ if (!set) extSubs.set(slot, set = new Set());
223
+ set.add(cb);
224
+ return function() {
225
+ return void set.delete(cb);
226
+ };
226
227
  }
227
228
  },
228
229
  events: {
@@ -256,25 +257,6 @@ function watchable(initial) {
256
257
  return typeof o.confirm === 'function' ? o.confirm(d) : (_o_confirm = o.confirm) !== null && _o_confirm !== void 0 ? _o_confirm : true;
257
258
  }
258
259
  },
259
- api: {
260
- fetch: function fetch(req) {
261
- return _async_to_generator(function() {
262
- return _ts_generator(this, function(_state) {
263
- log('api', 'fetch', req);
264
- return [
265
- 2,
266
- o.api ? o.api(req) : {
267
- status: 200,
268
- headers: {
269
- 'content-type': 'application/json'
270
- },
271
- body: '{}'
272
- }
273
- ];
274
- });
275
- })();
276
- }
277
- },
278
260
  telemetry: {
279
261
  log: function log1(l, m, c) {
280
262
  return log('telemetry', 'log', l, m, c);
@@ -397,17 +379,18 @@ function watchable(initial) {
397
379
  published: published,
398
380
  tools: tools,
399
381
  emit: {
400
- session: function session1(v) {
401
- return session.set(v);
402
- },
403
382
  tenant: function tenant1(v) {
404
383
  return tenant.set(v);
405
384
  },
406
385
  locale: function locale1(v) {
407
386
  return locale.set(v);
408
387
  },
409
- theme: function theme1(v) {
410
- return theme.set(v);
388
+ extensions: function extensions(slot, list) {
389
+ var _extSubs_get;
390
+ extList.set(slot, list);
391
+ (_extSubs_get = extSubs.get(slot)) === null || _extSubs_get === void 0 ? void 0 : _extSubs_get.forEach(function(cb) {
392
+ return cb(list);
393
+ });
411
394
  },
412
395
  config: function config1(v) {
413
396
  return config.set(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-testing",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Développer et tester une app embarquée sans le Core : hôte de test en mémoire, suite de conformité du protocole v2, simulateur de Shell (egen-embed-sim).",
6
6
  "type": "module",
@@ -76,9 +76,9 @@
76
76
  "vitest": "^4.1.2"
77
77
  },
78
78
  "dependencies": {
79
- "@egen-civitas/esm-embed-client": "^0.1.1",
80
- "@egen-civitas/esm-embed-host": "^0.2.0",
81
- "@egen-civitas/esm-embed-protocol": "^0.2.0"
79
+ "@egen-civitas/esm-embed-client": "^0.2.0",
80
+ "@egen-civitas/esm-embed-host": "^0.3.0",
81
+ "@egen-civitas/esm-embed-protocol": "^0.3.0"
82
82
  },
83
83
  "bin": {
84
84
  "egen-embed-check": "bin/egen-embed-check.mjs",
package/src/check.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest, type EmbedManifest } from '@egen-civitas/esm-embed-protocol';
1
+ import { CAPABILITIES, patternCovers, validateManifest, type EmbedManifest } from '@egen-civitas/esm-embed-protocol';
2
2
 
3
3
  export interface CheckIssue {
4
4
  level: 'error' | 'warn' | 'info';
@@ -32,9 +32,6 @@ export async function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]> {
32
32
  const needApproval = Object.keys(caps).filter((id) => !CAPABILITIES[id as keyof typeof CAPABILITIES].defaultGrant);
33
33
  if (needApproval.length) add('info', `Capacités à faire approuver par l'opérateur (grants) : ${needApproval.join(', ')}`);
34
34
 
35
- const fields = caps.session?.fields;
36
- if (Array.isArray(fields)) for (const f of fields) if (FORBIDDEN_SESSION_FIELDS.includes(String(f).split('.')[0])) add('error', `session.fields : « ${f} » ne sera jamais transmis (identifiant de session ou jeton)`);
37
-
38
35
  const pub = caps.events?.publish;
39
36
  if (Array.isArray(pub)) {
40
37
  const own = `app.${m.route}.*`;
@@ -46,14 +43,13 @@ export async function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]> {
46
43
  const tools = caps['ai-tools']?.tools;
47
44
  if (Array.isArray(tools) && tools.some((t) => !String(t).includes('.'))) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
48
45
 
49
- if (caps.api && !(Array.isArray(caps.api.paths) && caps.api.paths.length) && !(Array.isArray(caps.api.hosts) && caps.api.hosts.length)) add('warn', 'api : ni paths ni hosts demandés : aucun appel ne sera possible (deny-by-default)');
50
- const apiPaths = caps.api?.paths;
51
- if (Array.isArray(apiPaths)) for (const p of apiPaths) if (p === '/*' || p === '*') add('warn', `api.paths : « ${p} » ouvre toute l'API du Core avec la session de l'utilisateur ; nommer les chemins nécessaires`);
52
- const hosts = caps.api?.hosts;
53
- if (Array.isArray(hosts)) for (const h of hosts) if (!/^https:\/\//i.test(String(h))) add('error', `api.hosts : « ${h} » doit être une origine https`);
46
+ const slots = [...new Set((m.extensions ?? []).map((e) => e.slot))];
47
+ if (slots.length) add('info', `Contributions d'extension : l'opérateur doit approuver les slots (extensions.contribute) : ${slots.join(', ')}`);
48
+ for (const e of m.extensions ?? []) if (e.view) add('info', `Extension « ${e.name} » : la vue ${e.view} sera affichée dans une iframe du Core (frame-ancestors à autoriser pour le Shell, hauteur via navigation.resize)`);
49
+ const discover = caps.extensions?.discover;
50
+ if (Array.isArray(discover) && discover.some((s) => s === '*')) add('error', "extensions.discover : le motif « * » n'est pas supporté (nommer les slots)");
54
51
 
55
52
  if (m.technology === 'nextjs' && m.navigation.mode === 'none') add('info', 'Next.js avec navigation « none » : l’URL du Core ne reflétera pas la page courante (partage de lien, F5)');
56
- if (!caps.lifecycle && !caps.navigation) add('info', 'Aucune capacité navigation/lifecycle demandée : l’app ne pourra ni redimensionner l’iframe ni signaler qu’elle est prête (valeurs par défaut accordées si utilisées)');
57
53
 
58
54
  if (o.probe) {
59
55
  const f = o.fetchImpl ?? fetch;
@@ -20,7 +20,7 @@ export function defineConformance(connect: ConnectFn, t: ConformanceApi): void {
20
20
  describe('conformité protocole v2 (client)', () => {
21
21
  it('poignée de main : connecté en protocole 2', async () => {
22
22
  const sim = createTestHost();
23
- const c = await connect({ ...sim.connectOptions, capabilities: ['session'] });
23
+ const c = await connect({ ...sim.connectOptions, capabilities: ['tenant'] });
24
24
  expect(c.connected).toBe(true);
25
25
  expect(c.protocol).toBe(2);
26
26
  c.close();
@@ -32,7 +32,7 @@ export function defineConformance(connect: ConnectFn, t: ConformanceApi): void {
32
32
  const silent = { postMessage: () => undefined };
33
33
  const c = await connect({ ...sim.connectOptions, host: silent as any, timeoutMs: 80 });
34
34
  expect(c.connected).toBe(false);
35
- await expect(c.session.get()).rejects.toMatchObject({ code: 'DENIED' });
35
+ await expect(c.tenant.get()).rejects.toMatchObject({ code: 'DENIED' });
36
36
  sim.destroy();
37
37
  });
38
38
 
@@ -50,54 +50,54 @@ export function defineConformance(connect: ConnectFn, t: ConformanceApi): void {
50
50
  sim.destroy();
51
51
  });
52
52
 
53
- it('session : champs listés seulement, jamais de sessionId', async () => {
54
- const sim = createTestHost({ session: { authenticated: true, sessionId: 'SECRET', user: { uuid: 'u', display: 'Sam', email: 'e@x.y' } } });
55
- const c = await connect({ ...sim.connectOptions, capabilities: ['session'] });
56
- const s = await c.session.get();
57
- expect(JSON.stringify(s)).not.toMatch(/SECRET|e@x\.y/);
58
- expect(s).toMatchObject({ authenticated: true, user: { uuid: 'u', display: 'Sam' } });
53
+ it('règle d’or : identité, droits, thème et api ne sont pas des capacités du SDK', async () => {
54
+ const sim = createTestHost();
55
+ const c = await connect({ ...sim.connectOptions, capabilities: ['tenant', 'session', 'theme', 'permissions', 'api'] as any });
56
+ expect(c.has('tenant')).toBe(true);
57
+ expect(c.denied.map((d) => d.id).sort()).toEqual(['api', 'permissions', 'session', 'theme']);
58
+ expect(c.denied.every((d) => d.reason === 'UNKNOWN')).toBe(true);
59
59
  c.close();
60
60
  sim.destroy();
61
61
  });
62
62
 
63
63
  it('moindre privilège : capacité non approuvée refusée à la négociation et localement', async () => {
64
64
  const sim = createTestHost();
65
- const c = await connect({ ...sim.connectOptions, capabilities: ['session', 'api', 'notifications'] });
66
- expect(c.has('api')).toBe(false);
67
- expect(c.denied.map((d) => d.id).sort()).toEqual(['api', 'notifications']);
68
- await expect(c.api.fetch({ path: '/x' })).rejects.toMatchObject({ code: 'DENIED' });
69
- expect(sim.calls.some((x) => x.cap === 'api')).toBe(false);
65
+ const c = await connect({ ...sim.connectOptions, capabilities: ['tenant', 'events', 'notifications'] });
66
+ expect(c.has('events')).toBe(false);
67
+ expect(c.denied.map((d) => d.id).sort()).toEqual(['events', 'notifications']);
68
+ await expect(c.notifications.show({ kind: 'info', title: 'x' })).rejects.toMatchObject({ code: 'DENIED' });
69
+ expect(sim.calls.some((x) => x.cap === 'notifications')).toBe(false);
70
70
  c.close();
71
71
  sim.destroy();
72
72
  });
73
73
 
74
- it('changements poussés par l’hôte (thème)', async () => {
75
- const sim = createTestHost({ theme: { mode: 'light', tokens: { '--p': '#fff' } } });
76
- const c = await connect({ ...sim.connectOptions, capabilities: ['session', 'theme'] });
77
- const themes: unknown[] = [];
78
- await c.theme.onChange((x) => themes.push(x));
79
- sim.emit.theme({ mode: 'dark', tokens: { '--p': '#000' } });
74
+ it('changements poussés par l’hôte (langue)', async () => {
75
+ const sim = createTestHost({ locale: 'fr' });
76
+ const c = await connect({ ...sim.connectOptions, capabilities: ['locale'] });
77
+ const seen: unknown[] = [];
78
+ await c.locale.onChange((x) => seen.push(x));
79
+ sim.emit.locale('en');
80
80
  await tick();
81
- expect(themes).toEqual([{ mode: 'dark', tokens: { '--p': '#000' } }]);
81
+ expect(seen).toEqual(['en']);
82
82
  c.close();
83
83
  sim.destroy();
84
84
  });
85
85
 
86
- it('thème : variables CSS invalides ignorées (pas d’injection)', async () => {
87
- const set: Record<string, string> = {};
88
- const sim = createTestHost({ theme: { mode: 'dark', tokens: { '--ok': '#111', color: 'red', '--bad': 'x;}body{display:none' } } });
89
- const c = await connect({ ...sim.connectOptions, capabilities: ['theme'] });
90
- await c.theme.sync({ style: { setProperty: (k: string, v: string) => (set[k] = v) } });
91
- expect(set).toEqual({ '--ok': '#111' });
86
+ it('extensions : découverte limitée aux slots approuvés', async () => {
87
+ const list = [{ name: 'nav-x', moduleName: '@egen/esm-x-app', meta: { label: 'X' } }];
88
+ const sim = createTestHost({ extensions: { 'topbar-nav-slot': list }, manifestCapabilities: { extensions: { discover: ['topbar-nav-slot'] } }, approved: { extensions: { discover: ['topbar-nav-slot'] } } });
89
+ const c = await connect({ ...sim.connectOptions, capabilities: ['extensions'] });
90
+ await expect(c.extensions.list('topbar-nav-slot')).resolves.toEqual(list);
91
+ await expect(c.extensions.list('shell-rail-left-slot')).rejects.toMatchObject({ code: 'DENIED' });
92
92
  c.close();
93
93
  sim.destroy();
94
94
  });
95
95
 
96
96
  it('fermeture : appels suivants rejetés', async () => {
97
97
  const sim = createTestHost();
98
- const c = await connect({ ...sim.connectOptions, capabilities: ['session'] });
98
+ const c = await connect({ ...sim.connectOptions, capabilities: ['tenant'] });
99
99
  c.close();
100
- await expect(c.session.get()).rejects.toMatchObject({ code: 'DENIED' });
100
+ await expect(c.tenant.get()).rejects.toMatchObject({ code: 'DENIED' });
101
101
  sim.destroy();
102
102
  });
103
103
  });
package/src/server.ts CHANGED
@@ -14,7 +14,6 @@ export interface SimulatorOptions {
14
14
  manifest?: unknown;
15
15
  /** Approuver toutes les capacités demandées (défaut) ou seulement celles « par défaut » (`strict`). */
16
16
  strict?: boolean;
17
- session?: Record<string, unknown>;
18
17
  }
19
18
 
20
19
  export interface Simulator {
@@ -52,7 +51,7 @@ export async function startSimulator(o: SimulatorOptions): Promise<Simulator> {
52
51
  moduleName: manifest?.name ?? '@acme/esm-sim-app',
53
52
  manifestCapabilities: manifest?.capabilities,
54
53
  approved: approvedFor(manifest, !!o.strict),
55
- session: o.session ?? { authenticated: true, locale: 'fr', user: { uuid: 'sim-user', display: 'Utilisateur simulé', username: 'sim' }, sessionId: 'NE-DOIT-JAMAIS-ETRE-VISIBLE' },
54
+ extensions: { 'topbar-nav-slot': [{ name: 'nav-demo', moduleName: '@egen/esm-demo-app', order: 1, meta: { label: 'Démo', route: 'demo' } }] },
56
55
  };
57
56
  const roots: Record<string, string> = { protocol: pkgDist('@egen-civitas/esm-embed-protocol'), host: pkgDist('@egen-civitas/esm-embed-host') };
58
57
 
@@ -99,7 +98,7 @@ h1{font-size:14px;margin:0 0 8px}h2{font-size:12px;margin:12px 0 4px;text-transf
99
98
  <aside><h1>Simulateur de Shell EGEN</h1>
100
99
  <div id="info"></div>
101
100
  <h2>Pousser vers l'app</h2>
102
- <button id="theme">Thème clair/sombre</button><button id="locale">Langue fr/en</button><button id="session">Session (autre nom)</button><button id="event">Événement core.sim.ping</button>
101
+ <button id="locale">Langue fr/en</button><button id="event">Événement core.sim.ping</button><button id="ext">Changer les extensions de topbar-nav-slot</button>
103
102
  <h2>Notifications</h2><div id="toasts"></div>
104
103
  <h2>Journal des échanges</h2><pre id="log"></pre></aside>
105
104
  <script type="module">
@@ -109,17 +108,17 @@ const cfg = await (await fetch('/api/config')).json();
109
108
  const $ = (id) => document.getElementById(id);
110
109
  const log = (...a) => { $('log').textContent = new Date().toLocaleTimeString() + ' ' + a.map((x) => typeof x === 'string' ? x : JSON.stringify(x)).join(' ') + '\\n' + $('log').textContent; };
111
110
  const watch = (v) => { const s = new Set(); return { get: () => v, subscribe: (cb) => (s.add(cb), () => s.delete(cb)), set: (n) => { v = n; s.forEach((f) => f(n)); } }; };
112
- const session = watch(cfg.session), theme = watch({ mode: 'light', tokens: { '--primary': '#2563eb', '--background': '#ffffff', '--foreground': '#111111' } }), locale = watch('fr');
113
- const tenant = watch({ id: 'sim-tenant' }), conf = watch({});
111
+ const locale = watch('fr'), tenant = watch({ id: 'sim-tenant' }), conf = watch({});
114
112
  const topics = new Map();
113
+ const extState = new Map(Object.entries(cfg.extensions)), extSubs = new Map();
115
114
  const wrap = (cap, p) => Object.fromEntries(Object.entries(p).map(([k, f]) => [k, typeof f === 'function' ? (...a) => { log('←', cap + '.' + k, a); return f(...a); } : f]));
116
115
  const providers = {
117
- session: wrap('session', session), theme: wrap('theme', theme), locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),
118
- flags: wrap('flags', { isEnabled: () => true }), permissions: wrap('permissions', { can: () => true }),
116
+ locale: wrap('locale', locale), tenant: wrap('tenant', tenant), config: wrap('config', conf),
117
+ flags: wrap('flags', { isEnabled: () => true }),
118
+ extensions: { list: (slot) => { log('← extensions.list', slot); return extState.get(slot) || []; }, subscribe: (slot, cb) => { const s = extSubs.get(slot) || new Set(); s.add(cb); extSubs.set(slot, s); return () => s.delete(cb); } },
119
119
  events: { publish: (t, p, c) => { log('← events.publish', t, p, 'de', c.moduleName); (topics.get(t) || []).forEach((f) => f(p)); }, subscribe: (t, cb) => { log('← events.subscribe', t); const l = topics.get(t) || []; l.push(cb); topics.set(t, l); return () => topics.set(t, (topics.get(t) || []).filter((f) => f !== cb)); } },
120
120
  notifications: { show: (n) => { log('← notifications.show', n); const d = document.createElement('div'); d.className = 'toast'; d.textContent = '[' + n.kind + '] ' + n.title + (n.subtitle ? ' — ' + n.subtitle : ''); $('toasts').prepend(d); } },
121
121
  dialogs: { confirm: (d) => { log('← dialogs.confirm', d); return confirm(d.title + '\\n\\n' + d.message); } },
122
- api: { fetch: async (r) => { log('← api.fetch', r); return { status: 200, headers: { 'content-type': 'application/json' }, body: JSON.stringify({ simulated: true, request: r }) }; } },
123
122
  telemetry: { log: (...a) => log('← telemetry.log', a.slice(0, 3)), metric: (...a) => log('← telemetry.metric', a.slice(0, 3)) },
124
123
  aiTools: { register: (m, t) => log('← ai-tools.register', t.map((x) => x.name)), unregister: (m, n) => log('← ai-tools.unregister', n) },
125
124
  };
@@ -127,8 +126,7 @@ const grants = effectiveGrants(cfg.manifestCapabilities, cfg.approved);
127
126
  $('info').innerHTML = '<b>App</b> ' + cfg.app + '<br><b>Module</b> ' + cfg.moduleName + '<br><b>hostOrigins à déclarer dans l’app</b> <code>' + location.origin + '</code><br><b>Capacités accordées</b> ' + Object.keys(grants).join(', ');
128
127
  const host = createEmbedHost({ moduleName: cfg.moduleName, src: cfg.app, grants, providers, onConnect: (g, d) => log('✔ connecté', { accordées: g.map((x) => x.id), refusées: d }), onClose: (r) => log('✖ fermé', r) });
129
128
  host.mount($('stage'));
130
- $('theme').onclick = () => { const t = theme.get(); const dark = t.mode !== 'dark'; theme.set({ mode: dark ? 'dark' : 'light', tokens: { ...t.tokens, '--background': dark ? '#0b0b0f' : '#ffffff', '--foreground': dark ? '#f5f5f5' : '#111111' } }); };
131
129
  $('locale').onclick = () => locale.set(locale.get() === 'fr' ? 'en' : 'fr');
132
- $('session').onclick = () => { const s = session.get(); session.set({ ...s, user: { ...s.user, display: 'Autre ' + Math.floor(Math.random() * 100) } }); };
133
130
  $('event').onclick = () => (topics.get('core.sim.ping') || []).forEach((f) => f({ at: Date.now() }));
131
+ $('ext').onclick = () => { const n = [{ name: 'nav-' + Math.floor(Math.random() * 100), moduleName: '@egen/esm-demo-app', meta: { label: 'Nouvelle extension' } }]; extState.set('topbar-nav-slot', n); (extSubs.get('topbar-nav-slot') || []).forEach((f) => f(n)); };
134
132
  </script></body></html>`;
package/src/test-host.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { effectiveGrants, type ApprovedGrants, type CapabilityId, type GrantConfig } from '@egen-civitas/esm-embed-protocol';
2
2
  import type { ConnectOptions } from '@egen-civitas/esm-embed-client';
3
- import { createBus, HostConnection, type ApiRequest, type ApiResponse, type HostProviders, type ThemeState } from '@egen-civitas/esm-embed-host';
3
+ import { createBus, HostConnection, type ExtensionInfo, type HostProviders } from '@egen-civitas/esm-embed-host';
4
4
 
5
5
  export interface TestHostOptions {
6
6
  moduleName?: string;
@@ -10,15 +10,12 @@ export interface TestHostOptions {
10
10
  manifestCapabilities?: Partial<Record<CapabilityId, GrantConfig>>;
11
11
  /** Plafond fixé par l'opérateur (défaut : rien d'approuvé hors capacités « par défaut »). */
12
12
  approved?: ApprovedGrants;
13
- session?: Record<string, unknown>;
14
13
  tenant?: { id: string | null };
15
14
  locale?: string;
16
- theme?: ThemeState;
17
15
  config?: Record<string, unknown>;
18
16
  flags?: Record<string, boolean>;
19
- /** Permissions que l'utilisateur simulé possède. */
20
- permissions?: string[];
21
- api?: (req: ApiRequest) => ApiResponse | Promise<ApiResponse>;
17
+ /** Extensions attachées à chaque slot (`{ 'topbar-nav-slot': [...] }`). */
18
+ extensions?: Record<string, ExtensionInfo[]>;
22
19
  confirm?: boolean | ((d: { title: string; message: string; danger?: boolean }) => boolean);
23
20
  }
24
21
 
@@ -39,10 +36,9 @@ export interface TestHost {
39
36
  tools: Map<string, { description: string }>;
40
37
  /** Pousse un changement vers l'app (comme le ferait le Core). */
41
38
  emit: {
42
- session(v: Record<string, unknown>): void;
43
39
  tenant(v: { id: string | null }): void;
44
40
  locale(v: string): void;
45
- theme(v: ThemeState): void;
41
+ extensions(slot: string, list: ExtensionInfo[]): void;
46
42
  config(v: Record<string, unknown>): void;
47
43
  event(topic: string, payload?: unknown): void;
48
44
  goto(path: string): void;
@@ -71,8 +67,8 @@ function watchable<T>(initial: T) {
71
67
  * relié à votre app par de fausses fenêtres et un vrai `MessageChannel`. Aucun navigateur, aucun Core.
72
68
  *
73
69
  * ```ts
74
- * const sim = createTestHost({ session: { authenticated: true, user: { display: 'Sam' } } });
75
- * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['session'] });
70
+ * const sim = createTestHost({ locale: 'fr', tenant: { id: 'acme' } });
71
+ * const egen = await connectToEgen({ ...sim.connectOptions, capabilities: ['locale', 'tenant'] });
76
72
  * ```
77
73
  */
78
74
  export function createTestHost(o: TestHostOptions = {}): TestHost {
@@ -85,10 +81,10 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
85
81
  const toolInvokers = new Map<string, (name: string, args: Record<string, unknown>) => Promise<unknown>>();
86
82
  const log = (cap: string, method: string, ...args: unknown[]) => void calls.push({ cap, method, args });
87
83
 
88
- const session = watchable<Record<string, unknown> | undefined>(o.session ?? { authenticated: true });
89
84
  const tenant = watchable(o.tenant ?? { id: null });
90
85
  const locale = watchable(o.locale ?? 'fr');
91
- const theme = watchable<ThemeState>(o.theme ?? { mode: 'light', tokens: {} });
86
+ const extList = new Map<string, ExtensionInfo[]>(Object.entries(o.extensions ?? {}));
87
+ const extSubs = new Map<string, Set<(l: ExtensionInfo[]) => void>>();
92
88
  const config = watchable(o.config ?? {});
93
89
  const flagSubs = new Set<() => void>();
94
90
  const eventSubs = new Map<string, Set<(p: unknown) => void>>();
@@ -103,10 +99,8 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
103
99
  });
104
100
 
105
101
  const providers: HostProviders = {
106
- session: wrapWatch('session', session),
107
102
  tenant: wrapWatch('tenant', tenant),
108
103
  locale: wrapWatch('locale', locale),
109
- theme: wrapWatch('theme', theme),
110
104
  config: wrapWatch('config', config),
111
105
  flags: {
112
106
  isEnabled: (n) => {
@@ -115,10 +109,16 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
115
109
  },
116
110
  subscribe: (cb) => (flagSubs.add(cb), () => void flagSubs.delete(cb)),
117
111
  },
118
- permissions: {
119
- can: (p) => {
120
- log('permissions', 'can', p);
121
- return !!o.permissions?.includes(p);
112
+ extensions: {
113
+ list: (slot) => {
114
+ log('extensions', 'list', slot);
115
+ return extList.get(slot) ?? [];
116
+ },
117
+ subscribe: (slot, cb) => {
118
+ let set = extSubs.get(slot);
119
+ if (!set) extSubs.set(slot, (set = new Set()));
120
+ set.add(cb);
121
+ return () => void set!.delete(cb);
122
122
  },
123
123
  },
124
124
  events: {
@@ -145,12 +145,6 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
145
145
  return typeof o.confirm === 'function' ? o.confirm(d) : (o.confirm ?? true);
146
146
  },
147
147
  },
148
- api: {
149
- fetch: async (req) => {
150
- log('api', 'fetch', req);
151
- return o.api ? o.api(req) : { status: 200, headers: { 'content-type': 'application/json' }, body: '{}' };
152
- },
153
- },
154
148
  telemetry: { log: (l, m, c) => log('telemetry', 'log', l, m, c), metric: (n, v, t) => log('telemetry', 'metric', n, v, t) },
155
149
  aiTools: {
156
150
  register: (_m, list, invoke) => {
@@ -204,10 +198,12 @@ export function createTestHost(o: TestHostOptions = {}): TestHost {
204
198
  published,
205
199
  tools,
206
200
  emit: {
207
- session: (v) => session.set(v),
208
201
  tenant: (v) => tenant.set(v),
209
202
  locale: (v) => locale.set(v),
210
- theme: (v) => theme.set(v),
203
+ extensions: (slot, list) => {
204
+ extList.set(slot, list);
205
+ extSubs.get(slot)?.forEach((cb) => cb(list));
206
+ },
211
207
  config: (v) => config.set(v),
212
208
  event: (topic, payload) => eventSubs.get(topic)?.forEach((cb) => cb(payload)),
213
209
  goto: (path) => channel.emit('goto', { path, seq: Date.now() }),