@egen-civitas/esm-embed-testing 0.5.0 → 0.6.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,16 @@
1
1
  # @egen-civitas/esm-embed-testing
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a240fc: `egen-embed-check --probe` vérifie aussi la déclaration publiée à `<url>/egen-config.json` (voie normale, doc 17 §7) : présence (404 = information sur le second recours), absence de redirection, JSON et forme valides selon le protocole, écart avec la déclaration contrôlée (champs nommés) et rappel `Cache-Control: no-store` (le Core fige son SHA-256).
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [1e9983d]
12
+ - @egen-civitas/esm-embed-protocol@0.5.1
13
+
3
14
  ## 0.5.0
4
15
 
5
16
  ### Minor Changes
@@ -13,7 +13,7 @@ if (args.includes('--help') || !opt('--manifest')) {
13
13
  Usage : egen-embed-check --manifest egen-config.json [--shell https://egen.exemple.org] [--probe] [--allow-localhost]
14
14
 
15
15
  --shell origine du Shell EGEN (contrôle CSP frame-ancestors)
16
- --probe interroge l'URL de l'app (en-têtes X-Frame-Options / CSP)
16
+ --probe interroge l'URL de l'app : en-têtes X-Frame-Options / CSP, et déclaration publiée à <url>/egen-config.json
17
17
  --allow-localhost tolère http://localhost (développement)
18
18
 
19
19
  Code de sortie : 1 si au moins une erreur.`);
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,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,CA6D1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,+CAA+C;IAC/C,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,CA8D1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
package/dist/check.js CHANGED
@@ -35,12 +35,40 @@ function _async_to_generator(fn) {
35
35
  });
36
36
  };
37
37
  }
38
+ function _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
38
51
  function _iterable_to_array(iter) {
39
52
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
40
53
  }
41
54
  function _non_iterable_spread() {
42
55
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
43
56
  }
57
+ function _object_spread(target) {
58
+ for(var i = 1; i < arguments.length; i++){
59
+ var source = arguments[i] != null ? arguments[i] : {};
60
+ var ownKeys = Object.keys(source);
61
+ if (typeof Object.getOwnPropertySymbols === "function") {
62
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
63
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
64
+ }));
65
+ }
66
+ ownKeys.forEach(function(key) {
67
+ _define_property(target, key, source[key]);
68
+ });
69
+ }
70
+ return target;
71
+ }
44
72
  function _to_consumable_array(arr) {
45
73
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
46
74
  }
@@ -277,7 +305,7 @@ import { CAPABILITIES, patternCovers, validateManifest } from '@egen-civitas/esm
277
305
  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
306
  if (!o.probe) return [
279
307
  3,
280
- 4
308
+ 6
281
309
  ];
282
310
  f = (_o_fetchImpl = o.fetchImpl) !== null && _o_fetchImpl !== void 0 ? _o_fetchImpl : fetch;
283
311
  _state.label = 1;
@@ -321,6 +349,16 @@ import { CAPABILITIES, patternCovers, validateManifest } from '@egen-civitas/esm
321
349
  4
322
350
  ];
323
351
  case 4:
352
+ return [
353
+ 4,
354
+ probeDeclaration(f, m, add, {
355
+ allowInsecureLocalhost: o.allowInsecureLocalhost
356
+ })
357
+ ];
358
+ case 5:
359
+ _state.sent();
360
+ _state.label = 6;
361
+ case 6:
324
362
  return [
325
363
  2,
326
364
  issues
@@ -334,3 +372,121 @@ export var hasErrors = function hasErrors(issues) {
334
372
  return i.level === 'error';
335
373
  });
336
374
  };
375
+ var sameJson = function sameJson(a, b) {
376
+ return JSON.stringify(a) === JSON.stringify(b);
377
+ };
378
+ /**
379
+ * Voie normale (doc 17 §7) : l'app sert elle-même `<url>/egen-config.json`. On vérifie qu'il est publié, valide,
380
+ * identique à la déclaration contrôlée, et jamais mis en cache (le Core en fige le SHA-256).
381
+ */ function probeDeclaration(f, m, add, manifestOptions) {
382
+ return _async_to_generator(function() {
383
+ var declared, _res_headers_get, res, served, unused, result, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, drift, cache, e;
384
+ return _ts_generator(this, function(_state) {
385
+ switch(_state.label){
386
+ case 0:
387
+ declared = "".concat(m.url.replace(/\/+$/, ''), "/egen-config.json");
388
+ _state.label = 1;
389
+ case 1:
390
+ _state.trys.push([
391
+ 1,
392
+ 7,
393
+ ,
394
+ 8
395
+ ]);
396
+ return [
397
+ 4,
398
+ f(declared, {
399
+ redirect: 'manual',
400
+ signal: AbortSignal.timeout(10000)
401
+ })
402
+ ];
403
+ case 2:
404
+ res = _state.sent();
405
+ if (res.status === 404) {
406
+ add('info', "/egen-config.json n'est pas publié à la racine de l'app : voie normale = l'app sert sa déclaration ; sinon l'opérateur la déclare côté Core (second recours, `declaration` dans external-apps.json)");
407
+ return [
408
+ 2
409
+ ];
410
+ }
411
+ if (res.status >= 300) {
412
+ add('warn', "/egen-config.json r\xe9pond HTTP ".concat(res.status, " : le Core doit pouvoir le lire directement (pas de redirection)"));
413
+ return [
414
+ 2
415
+ ];
416
+ }
417
+ _state.label = 3;
418
+ case 3:
419
+ _state.trys.push([
420
+ 3,
421
+ 5,
422
+ ,
423
+ 6
424
+ ]);
425
+ return [
426
+ 4,
427
+ res.json()
428
+ ];
429
+ case 4:
430
+ served = _state.sent();
431
+ return [
432
+ 3,
433
+ 6
434
+ ];
435
+ case 5:
436
+ unused = _state.sent();
437
+ add('error', '/egen-config.json publié : JSON invalide');
438
+ return [
439
+ 2
440
+ ];
441
+ case 6:
442
+ result = validateManifest(served, manifestOptions);
443
+ if (!result.ok) {
444
+ _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
445
+ try {
446
+ for(_iterator = result.errors[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
447
+ _$e = _step.value;
448
+ add('error', "/egen-config.json publi\xe9 invalide : ".concat(_$e));
449
+ }
450
+ } catch (err) {
451
+ _didIteratorError = true;
452
+ _iteratorError = err;
453
+ } finally{
454
+ try {
455
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
456
+ _iterator.return();
457
+ }
458
+ } finally{
459
+ if (_didIteratorError) {
460
+ throw _iteratorError;
461
+ }
462
+ }
463
+ }
464
+ return [
465
+ 2
466
+ ];
467
+ }
468
+ drift = Object.keys(_object_spread({}, m, result.manifest)).filter(function(k) {
469
+ return !sameJson(m[k], result.manifest[k]);
470
+ });
471
+ if (drift.length) add('warn', "La d\xe9claration publi\xe9e diff\xe8re de celle contr\xf4l\xe9e (champs : ".concat(drift.join(', '), ")"));
472
+ cache = (_res_headers_get = res.headers.get('cache-control')) !== null && _res_headers_get !== void 0 ? _res_headers_get : '';
473
+ if (!/no-store|no-cache|max-age=0/i.test(cache)) add('info', "/egen-config.json sans « Cache-Control: no-store » : le Core fige son SHA-256, une version en cache provoque un rejet au démarrage");
474
+ return [
475
+ 3,
476
+ 8
477
+ ];
478
+ case 7:
479
+ e = _state.sent();
480
+ add('warn', "/egen-config.json injoignable (".concat(e.message, ")"));
481
+ return [
482
+ 3,
483
+ 8
484
+ ];
485
+ case 8:
486
+ return [
487
+ 2
488
+ ];
489
+ }
490
+ });
491
+ })();
492
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/esm-embed-testing",
3
- "version": "0.5.0",
3
+ "version": "0.6.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",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "@egen-civitas/esm-embed-client": "^0.3.1",
80
80
  "@egen-civitas/esm-embed-host": "^0.5.0",
81
- "@egen-civitas/esm-embed-protocol": "^0.5.0"
81
+ "@egen-civitas/esm-embed-protocol": "^0.5.1"
82
82
  },
83
83
  "bin": {
84
84
  "egen-embed-check": "bin/egen-embed-check.mjs",
package/src/check.ts CHANGED
@@ -79,8 +79,55 @@ export async function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]> {
79
79
  } catch (e) {
80
80
  add('warn', `URL de l'app injoignable (${(e as Error).message})`);
81
81
  }
82
+ await probeDeclaration(f, m, add, { allowInsecureLocalhost: o.allowInsecureLocalhost });
82
83
  }
83
84
  return issues;
84
85
  }
85
86
 
86
87
  export const hasErrors = (issues: CheckIssue[]) => issues.some((i) => i.level === 'error');
88
+
89
+ const sameJson = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
90
+
91
+ /**
92
+ * Voie normale (doc 17 §7) : l'app sert elle-même `<url>/egen-config.json`. On vérifie qu'il est publié, valide,
93
+ * identique à la déclaration contrôlée, et jamais mis en cache (le Core en fige le SHA-256).
94
+ */
95
+ async function probeDeclaration(
96
+ f: typeof fetch,
97
+ m: EmbedManifest,
98
+ add: (level: CheckIssue['level'], message: string) => void,
99
+ manifestOptions: Parameters<typeof validateManifest>[1]
100
+ ): Promise<void> {
101
+ const declared = `${m.url.replace(/\/+$/, '')}/egen-config.json`;
102
+ try {
103
+ const res = await f(declared, { redirect: 'manual', signal: AbortSignal.timeout(10_000) });
104
+ if (res.status === 404) {
105
+ add('info', "/egen-config.json n'est pas publié à la racine de l'app : voie normale = l'app sert sa déclaration ; sinon l'opérateur la déclare côté Core (second recours, `declaration` dans external-apps.json)");
106
+ return;
107
+ }
108
+ if (res.status >= 300) {
109
+ add('warn', `/egen-config.json répond HTTP ${res.status} : le Core doit pouvoir le lire directement (pas de redirection)`);
110
+ return;
111
+ }
112
+ let served: unknown;
113
+ try {
114
+ served = await res.json();
115
+ } catch {
116
+ add('error', '/egen-config.json publié : JSON invalide');
117
+ return;
118
+ }
119
+ const result = validateManifest(served, manifestOptions);
120
+ if (!result.ok) {
121
+ for (const e of result.errors) add('error', `/egen-config.json publié invalide : ${e}`);
122
+ return;
123
+ }
124
+ const drift = Object.keys({ ...(m as object), ...(result.manifest as object) }).filter(
125
+ (k) => !sameJson((m as unknown as Record<string, unknown>)[k], (result.manifest as unknown as Record<string, unknown>)[k])
126
+ );
127
+ if (drift.length) add('warn', `La déclaration publiée diffère de celle contrôlée (champs : ${drift.join(', ')})`);
128
+ const cache = res.headers.get('cache-control') ?? '';
129
+ if (!/no-store|no-cache|max-age=0/i.test(cache)) add('info', "/egen-config.json sans « Cache-Control: no-store » : le Core fige son SHA-256, une version en cache provoque un rejet au démarrage");
130
+ } catch (e) {
131
+ add('warn', `/egen-config.json injoignable (${(e as Error).message})`);
132
+ }
133
+ }