@egen-civitas/sdk 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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @egen-civitas/sdk
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bd63b5d: Cycle de vie (B5), additif : état commun (`connecting`, `ready`, `active`, `hidden`, `closing`, `closed`, `failed`, `standalone`), `lifecycle.onBeforeLeave` (plusieurs gardes, un garde défaillant ne bloque jamais), `onClosing` (≤ 2 s, au mieux en iframe), `onError`, `onStateChange`, alias `onVisibilityChange`/`onFocusChange` ; nouvelle méthode hôte → app `lifecycle.closing` et `host.close()` (fermeture ordonnée) ; `connect({ onDiagnostic })` et `app.state` dans le SDK ; visibilité locale en mode autonome.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [bd63b5d]
12
+ - @egen-civitas/esm-embed-protocol@0.9.0
13
+ - @egen-civitas/esm-embed-client@0.10.0
14
+
15
+ ## 0.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 177a545: Navigation étendue (B4), additive : `navigate(to, options)` renvoie `{ status: 'done' | 'blocked' }` (replace, newTab, query, hash, relativeTo), nouvelles méthodes `current`, `exists`, `back`, `canGoBack`, `intent`, `link` ; l'hôte sert `current`/`back`/`canGoBack` par défaut et `exists`/`intent` via `routeExists`/`intents` ; garde de sortie (`canLeave`) avant de quitter l'app ; code `NOT_FOUND` sur route ou intent inconnu. Un Shell plus ancien répond `UNKNOWN_METHOD` pour les nouvelles méthodes.
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies [177a545]
24
+ - @egen-civitas/esm-embed-protocol@0.8.0
25
+ - @egen-civitas/esm-embed-client@0.9.0
26
+
3
27
  ## 0.2.0
4
28
 
5
29
  ### Minor Changes
package/dist/app.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { EgenClient } from '@egen-civitas/esm-embed-client';
2
- import type { CapabilityDenied, CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import type { CapabilityDenied, CapabilityId, LifecycleState } from '@egen-civitas/esm-embed-protocol';
3
3
  export type EgenMode = 'embedded' | 'standalone';
4
4
  export interface Diagnosis {
5
5
  mode: EgenMode;
6
+ state: LifecycleState;
6
7
  /** `true` seulement si une connexion au Shell est établie. */
7
8
  connected: boolean;
8
9
  moduleName: string;
@@ -20,7 +21,7 @@ export interface Diagnosis {
20
21
  export declare class EgenApp {
21
22
  private readonly note?;
22
23
  readonly mode: EgenMode;
23
- readonly sdkVersion = "0.2.0";
24
+ readonly sdkVersion = "0.4.0";
24
25
  readonly client: EgenClient;
25
26
  readonly tenant: EgenClient['tenant'];
26
27
  readonly locale: EgenClient['locale'];
@@ -37,6 +38,8 @@ export declare class EgenApp {
37
38
  get moduleName(): string;
38
39
  /** Connexion au Shell établie (toujours `false` en mode autonome). */
39
40
  get connected(): boolean;
41
+ /** État du cycle de vie (spec §6.1). */
42
+ get state(): LifecycleState;
40
43
  get closed(): boolean;
41
44
  /** Le Core affiche-t-il seul les notifications de l'app ? (voir `EgenClient.coreDisplaysNotifications`). */
42
45
  get coreDisplaysNotifications(): boolean;
package/dist/app.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGvF,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;AAEjD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM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}
package/dist/app.js CHANGED
@@ -87,6 +87,12 @@ import { SDK_VERSION } from './version.js';
87
87
  return this.client.connected;
88
88
  }
89
89
  },
90
+ {
91
+ key: "state",
92
+ get: /** État du cycle de vie (spec §6.1). */ function get() {
93
+ return this.client.lifecycle.state;
94
+ }
95
+ },
90
96
  {
91
97
  key: "closed",
92
98
  get: function get() {
@@ -148,6 +154,7 @@ import { SDK_VERSION } from './version.js';
148
154
  }
149
155
  return {
150
156
  mode: this.mode,
157
+ state: this.state,
151
158
  connected: this.connected,
152
159
  moduleName: this.moduleName,
153
160
  sdkVersion: this.sdkVersion,
package/dist/connect.d.ts CHANGED
@@ -1,7 +1,15 @@
1
1
  import { type ConnectOptions as EmbeddedOptions } from '@egen-civitas/esm-embed-client';
2
- import { type CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import { EmbedError, type CapabilityId, type LifecycleState } from '@egen-civitas/esm-embed-protocol';
3
3
  import { EgenApp, type EgenMode } from './app.js';
4
4
  import { type StandaloneOptions } from './standalone.js';
5
+ /** Transitions d'état et erreurs de protocole (spec §6 / §497) : `connecting` et `failed` n'existent qu'ici. */
6
+ export type DiagnosticEvent = {
7
+ type: 'state';
8
+ state: LifecycleState;
9
+ } | {
10
+ type: 'error';
11
+ error: EmbedError;
12
+ };
5
13
  export interface ConnectOptions extends Omit<EmbeddedOptions, 'hostOrigins'> {
6
14
  /** Origines EXACTES du Shell. Obligatoire pour le mode embarqué ; sans elles, `auto` reste en mode autonome. */
7
15
  hostOrigins?: string[];
@@ -14,6 +22,8 @@ export interface ConnectOptions extends Omit<EmbeddedOptions, 'hostOrigins'> {
14
22
  required?: CapabilityId[];
15
23
  /** Comportement hors Shell. */
16
24
  standalone?: StandaloneOptions;
25
+ /** Reçoit les transitions d'état (`connecting` → `ready`/`standalone`/`failed` → …) et les erreurs de protocole. */
26
+ onDiagnostic?: (e: DiagnosticEvent) => void;
17
27
  }
18
28
  /**
19
29
  * Point d'entrée unique du SDK. Retourne toujours une `EgenApp` utilisable, sauf si `required` n'est pas satisfait
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,cAAc,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAA4C,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAoD,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3G,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC;IAC1E,gHAAgH;IAChH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,oGAAoG;IACpG,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,+BAA+B;IAC/B,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AA8BD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBvE"}
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,cAAc,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACnH,OAAO,EAAE,UAAU,EAAgC,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACpI,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAoD,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3G,gHAAgH;AAChH,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAE9G,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC;IAC1E,gHAAgH;IAChH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACzB,oGAAoG;IACpG,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,+BAA+B;IAC/B,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,oHAAoH;IACpH,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;CAC7C;AA8BD;;;GAGG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBvE"}
package/dist/connect.js CHANGED
@@ -48,6 +48,14 @@ function _define_property(obj, key, value) {
48
48
  }
49
49
  return obj;
50
50
  }
51
+ function _instanceof(left, right) {
52
+ "@swc/helpers - instanceof";
53
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
54
+ return !!right[Symbol.hasInstance](left);
55
+ } else {
56
+ return left instanceof right;
57
+ }
58
+ }
51
59
  function _iterable_to_array(iter) {
52
60
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
53
61
  }
@@ -264,6 +272,76 @@ function enforceRequired(app, required) {
264
272
  * Point d'entrée unique du SDK. Retourne toujours une `EgenApp` utilisable, sauf si `required` n'est pas satisfait
265
273
  * ou si `mode: 'embedded'` est exigé sans Shell (erreurs typées `EgenError`).
266
274
  */ export function connect(options) {
275
+ return _async_to_generator(function() {
276
+ var emit, app, e;
277
+ return _ts_generator(this, function(_state) {
278
+ switch(_state.label){
279
+ case 0:
280
+ emit = function emit(e) {
281
+ try {
282
+ var _options_onDiagnostic;
283
+ options === null || options === void 0 ? void 0 : (_options_onDiagnostic = options.onDiagnostic) === null || _options_onDiagnostic === void 0 ? void 0 : _options_onDiagnostic.call(options, e);
284
+ } catch (unused) {
285
+ /* un observateur ne casse jamais la connexion */ }
286
+ };
287
+ emit({
288
+ type: 'state',
289
+ state: 'connecting'
290
+ });
291
+ _state.label = 1;
292
+ case 1:
293
+ _state.trys.push([
294
+ 1,
295
+ 3,
296
+ ,
297
+ 4
298
+ ]);
299
+ return [
300
+ 4,
301
+ connectInner(options)
302
+ ];
303
+ case 2:
304
+ app = _state.sent();
305
+ emit({
306
+ type: 'state',
307
+ state: app.state
308
+ });
309
+ app.client.lifecycle.onStateChange(function(state) {
310
+ return emit({
311
+ type: 'state',
312
+ state: state
313
+ });
314
+ });
315
+ app.client.lifecycle.onError(function(error) {
316
+ return emit({
317
+ type: 'error',
318
+ error: error
319
+ });
320
+ });
321
+ return [
322
+ 2,
323
+ app
324
+ ];
325
+ case 3:
326
+ e = _state.sent();
327
+ emit({
328
+ type: 'state',
329
+ state: 'failed'
330
+ });
331
+ if (_instanceof(e, EmbedError)) emit({
332
+ type: 'error',
333
+ error: e
334
+ });
335
+ throw e;
336
+ case 4:
337
+ return [
338
+ 2
339
+ ];
340
+ }
341
+ });
342
+ })();
343
+ }
344
+ function connectInner(options) {
267
345
  return _async_to_generator(function() {
268
346
  var _options_mode, mode, standalone, origins, client;
269
347
  return _ts_generator(this, function(_state) {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { connect, type ConnectOptions } from './connect.js';
1
+ export { connect, type ConnectOptions, type DiagnosticEvent } from './connect.js';
2
2
  export { EgenApp, type Diagnosis, type EgenMode } from './app.js';
3
3
  export { EgenError, isEgenError, type EgenErrorCode } from './errors.js';
4
4
  export { createStandaloneRuntime, STANDALONE_CAPABILITIES, type StandaloneOptions } from './standalone.js';
5
5
  export { SDK_VERSION } from './version.js';
6
6
  export { connectToEgen, EgenClient } from '@egen-civitas/esm-embed-client';
7
- export type { CapabilityId, CapabilityDenied, CapabilityGranted } from '@egen-civitas/esm-embed-protocol';
7
+ export type { LifecycleState, CapabilityId, CapabilityDenied, CapabilityGranted } from '@egen-civitas/esm-embed-protocol';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
@@ -22,7 +22,13 @@ export interface StandaloneOptions {
22
22
  navigator?: {
23
23
  language?: string;
24
24
  };
25
+ location?: Pick<Location, 'pathname' | 'search' | 'hash'>;
26
+ open?: Window['open'];
25
27
  };
28
+ /** Table des routes locale (`navigation.exists`, `NOT_FOUND`). Absente : `exists` indisponible. */
29
+ routeExists?: (path: string) => boolean | Promise<boolean>;
30
+ /** Intents `objet-action` → chemin local (`null` : inconnu). Absent : `intent` indisponible. */
31
+ intents?: (slug: string, params: Record<string, unknown>) => string | null | Promise<string | null>;
26
32
  }
27
33
  /**
28
34
  * Runtime local qui sert les capacités du catalogue sans Shell. Il respecte la validation d'arguments du protocole
@@ -1 +1 @@
1
- {"version":3,"file":"standalone.d.ts","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC/F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAE9D,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpC,mHAAmH;AACnH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,wDAAwD;IACxD,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,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G,sEAAsE;IACtE,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,GAAG,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAChE,oDAAoD;IACpD,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC,GAAG;QAAE,SAAS,CAAC,EAAE;YAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IACxK,mGAAmG;IACnG,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3D,gGAAgG;IAChG,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACrG;AAID;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,GAAE,iBAAsB,GAAG,OAAO,CAyG7E;AAED,qDAAqD;AACrD,eAAO,MAAM,uBAAuB,EAAE,SAAS,YAAY,EAAwI,CAAC"}
@@ -200,17 +200,24 @@ function _ts_generator(thisArg, body) {
200
200
  };
201
201
  }
202
202
  }
203
- import { EmbedError, validateCall } from '@egen-civitas/esm-embed-protocol';
203
+ import { EmbedError, buildInternalHref, validateCall } from '@egen-civitas/esm-embed-protocol';
204
204
  /**
205
205
  * Runtime local qui sert les capacités du catalogue sans Shell. Il respecte la validation d'arguments du protocole
206
206
  * (mêmes `INVALID_ARGS` qu'avec un hôte) ; ce qui n'a pas de sens hors Shell est refusé avec `UNSUPPORTED_IN_MODE`.
207
207
  */ export function createStandaloneRuntime() {
208
208
  var opts = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
209
209
  var _opts_window;
210
+ var _doc_addEventListener;
210
211
  var win = (_opts_window = opts.window) !== null && _opts_window !== void 0 ? _opts_window : typeof window !== 'undefined' ? window : undefined;
211
212
  var listeners = new Map();
212
213
  var closed = false;
213
214
  var seq = 0;
215
+ // Visibilité locale (spec §6.2 : `document.visibilitychange` en mode autonome).
216
+ var doc = win === null || win === void 0 ? void 0 : win.document;
217
+ var onVisibility = function onVisibility() {
218
+ return emit('lifecycle', 'visibility', !(doc === null || doc === void 0 ? void 0 : doc.hidden));
219
+ };
220
+ doc === null || doc === void 0 ? void 0 : (_doc_addEventListener = doc.addEventListener) === null || _doc_addEventListener === void 0 ? void 0 : _doc_addEventListener.call(doc, 'visibilitychange', onVisibility);
214
221
  var emit = function emit(cap, ev, v) {
215
222
  var _listeners_get;
216
223
  return (_listeners_get = listeners.get("".concat(cap, ":").concat(ev))) === null || _listeners_get === void 0 ? void 0 : _listeners_get.forEach(function(cb) {
@@ -220,6 +227,51 @@ import { EmbedError, validateCall } from '@egen-civitas/esm-embed-protocol';
220
227
  var unsupported = function unsupported(what) {
221
228
  return new EmbedError('UNSUPPORTED_IN_MODE', "".concat(what, " : indisponible hors du Shell EGEN (mode autonome)"));
222
229
  };
230
+ var navigateLocal = function navigateLocal(to, o) {
231
+ return _async_to_generator(function() {
232
+ var _win_open, href, pathOnly, _tmp;
233
+ return _ts_generator(this, function(_state) {
234
+ switch(_state.label){
235
+ case 0:
236
+ href = o && (o.query || o.hash) ? buildInternalHref(to, {
237
+ query: o.query,
238
+ hash: o.hash
239
+ }) : to;
240
+ pathOnly = href.split(/[?#]/, 1)[0];
241
+ _tmp = opts.routeExists;
242
+ if (!_tmp) return [
243
+ 3,
244
+ 2
245
+ ];
246
+ return [
247
+ 4,
248
+ opts.routeExists(pathOnly)
249
+ ];
250
+ case 1:
251
+ _tmp = !_state.sent();
252
+ _state.label = 2;
253
+ case 2:
254
+ if (_tmp) throw new EmbedError('NOT_FOUND', "Route inconnue : ".concat(pathOnly));
255
+ if ((o === null || o === void 0 ? void 0 : o.target) === 'newTab') win === null || win === void 0 ? void 0 : (_win_open = win.open) === null || _win_open === void 0 ? void 0 : _win_open.call(win, href, '_blank', 'noopener,noreferrer');
256
+ else {
257
+ if (o === null || o === void 0 ? void 0 : o.replace) win === null || win === void 0 ? void 0 : win.history.replaceState(null, '', href);
258
+ else win === null || win === void 0 ? void 0 : win.history.pushState(null, '', href);
259
+ emit('navigation', 'goto', {
260
+ path: href,
261
+ seq: ++seq
262
+ });
263
+ }
264
+ return [
265
+ 2,
266
+ {
267
+ status: 'done',
268
+ path: href
269
+ }
270
+ ];
271
+ }
272
+ });
273
+ })();
274
+ };
223
275
  var handlers = {
224
276
  tenant: {
225
277
  get: function get() {
@@ -324,12 +376,69 @@ import { EmbedError, validateCall } from '@egen-civitas/esm-embed-protocol';
324
376
  if (title && win) win.document.title = title;
325
377
  },
326
378
  navigate: function navigate(param) {
327
- var _param = _sliced_to_array(param, 1), to = _param[0];
328
- win === null || win === void 0 ? void 0 : win.history.pushState(null, '', to);
329
- emit('navigation', 'goto', {
330
- path: to,
331
- seq: ++seq
332
- });
379
+ var _param = _sliced_to_array(param, 2), to = _param[0], o = _param[1];
380
+ return navigateLocal(to, o);
381
+ },
382
+ current: function current() {
383
+ var _ref, _ref1, _ref2;
384
+ var l = win === null || win === void 0 ? void 0 : win.location;
385
+ var u = new URL("".concat((_ref = l === null || l === void 0 ? void 0 : l.pathname) !== null && _ref !== void 0 ? _ref : '/').concat((_ref1 = l === null || l === void 0 ? void 0 : l.search) !== null && _ref1 !== void 0 ? _ref1 : '').concat((_ref2 = l === null || l === void 0 ? void 0 : l.hash) !== null && _ref2 !== void 0 ? _ref2 : ''), 'http://app.invalid');
386
+ return {
387
+ path: u.pathname,
388
+ query: Object.fromEntries(u.searchParams),
389
+ hash: u.hash,
390
+ title: win === null || win === void 0 ? void 0 : win.document.title
391
+ };
392
+ },
393
+ exists: function exists(param) {
394
+ var _param = _sliced_to_array(param, 1), path = _param[0];
395
+ return _async_to_generator(function() {
396
+ return _ts_generator(this, function(_state) {
397
+ switch(_state.label){
398
+ case 0:
399
+ if (!opts.routeExists) throw unsupported('navigation.exists');
400
+ return [
401
+ 4,
402
+ opts.routeExists(path)
403
+ ];
404
+ case 1:
405
+ return [
406
+ 2,
407
+ !!_state.sent()
408
+ ];
409
+ }
410
+ });
411
+ })();
412
+ },
413
+ back: function back() {
414
+ return void (win === null || win === void 0 ? void 0 : win.history.back());
415
+ },
416
+ canGoBack: function canGoBack() {
417
+ var _ref;
418
+ return ((_ref = win === null || win === void 0 ? void 0 : win.history.length) !== null && _ref !== void 0 ? _ref : 0) > 1;
419
+ },
420
+ intent: function intent(param) {
421
+ var _param = _sliced_to_array(param, 3), slug = _param[0], params = _param[1], o = _param[2];
422
+ return _async_to_generator(function() {
423
+ var target;
424
+ return _ts_generator(this, function(_state) {
425
+ switch(_state.label){
426
+ case 0:
427
+ if (!opts.intents) throw unsupported('navigation.intent');
428
+ return [
429
+ 4,
430
+ opts.intents(slug, params !== null && params !== void 0 ? params : {})
431
+ ];
432
+ case 1:
433
+ target = _state.sent();
434
+ if (target === null) throw new EmbedError('NOT_FOUND', "Intent inconnu : ".concat(slug));
435
+ return [
436
+ 2,
437
+ navigateLocal(target, o)
438
+ ];
439
+ }
440
+ });
441
+ })();
333
442
  },
334
443
  notFound: function notFound() {
335
444
  return undefined;
@@ -392,6 +501,8 @@ import { EmbedError, validateCall } from '@egen-civitas/esm-embed-protocol';
392
501
  })();
393
502
  },
394
503
  close: function close() {
504
+ var _doc_removeEventListener;
505
+ doc === null || doc === void 0 ? void 0 : (_doc_removeEventListener = doc.removeEventListener) === null || _doc_removeEventListener === void 0 ? void 0 : _doc_removeEventListener.call(doc, 'visibilitychange', onVisibility);
395
506
  closed = true;
396
507
  listeners.clear();
397
508
  }
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Version de la façade SDK. Générée depuis le package.json par `scripts/sync-sdk-version.mjs` ; `version.test.ts` garde la cohérence. */
2
- export declare const SDK_VERSION = "0.2.0";
2
+ export declare const SDK_VERSION = "0.4.0";
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- /** Version de la façade SDK. Générée depuis le package.json par `scripts/sync-sdk-version.mjs` ; `version.test.ts` garde la cohérence. */ export var SDK_VERSION = '0.2.0';
1
+ /** Version de la façade SDK. Générée depuis le package.json par `scripts/sync-sdk-version.mjs` ; `version.test.ts` garde la cohérence. */ export var SDK_VERSION = '0.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egen-civitas/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "EGEN Developer SDK — point d'entrée unique pour les applications intégrées au Shell EGEN : connect(), EgenApp, EgenError, modes embarqué et autonome.",
6
6
  "type": "module",
@@ -47,12 +47,12 @@
47
47
  "access": "public"
48
48
  },
49
49
  "dependencies": {
50
- "@egen-civitas/esm-embed-client": "^0.8.0",
51
- "@egen-civitas/esm-embed-protocol": "^0.7.0"
50
+ "@egen-civitas/esm-embed-client": "^0.10.0",
51
+ "@egen-civitas/esm-embed-protocol": "^0.9.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@egen-civitas/esm-embed-host": "^0.7.1",
55
- "@egen-civitas/esm-embed-testing": "^0.7.4",
54
+ "@egen-civitas/esm-embed-host": "^0.9.0",
55
+ "@egen-civitas/esm-embed-testing": "^0.7.6",
56
56
  "@swc/cli": "0.8.1",
57
57
  "@swc/core": "1.15.21",
58
58
  "@types/node": "^20",
package/src/app.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import type { EgenClient } from '@egen-civitas/esm-embed-client';
2
- import type { CapabilityDenied, CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import type { CapabilityDenied, CapabilityId, LifecycleState } from '@egen-civitas/esm-embed-protocol';
3
3
  import { SDK_VERSION } from './version.js';
4
4
 
5
5
  export type EgenMode = 'embedded' | 'standalone';
6
6
 
7
7
  export interface Diagnosis {
8
8
  mode: EgenMode;
9
+ state: LifecycleState;
9
10
  /** `true` seulement si une connexion au Shell est établie. */
10
11
  connected: boolean;
11
12
  moduleName: string;
@@ -61,6 +62,10 @@ export class EgenApp {
61
62
  get connected(): boolean {
62
63
  return this.client.connected;
63
64
  }
65
+ /** État du cycle de vie (spec §6.1). */
66
+ get state(): LifecycleState {
67
+ return this.client.lifecycle.state;
68
+ }
64
69
  get closed(): boolean {
65
70
  return this.client.closed;
66
71
  }
@@ -89,7 +94,7 @@ export class EgenApp {
89
94
  else if (d.reason === 'VERSION') hints.push(`« ${d.id} » : version de capacité non prise en charge par le Shell.`);
90
95
  else hints.push(`« ${d.id} » : inconnue du Shell (SDK plus récent que le Shell ?).`);
91
96
  }
92
- return { mode: this.mode, connected: this.connected, moduleName: this.moduleName, sdkVersion: this.sdkVersion, protocol: this.client.protocol, granted: this.capabilities.granted, denied, hints };
97
+ return { mode: this.mode, state: this.state, connected: this.connected, moduleName: this.moduleName, sdkVersion: this.sdkVersion, protocol: this.client.protocol, granted: this.capabilities.granted, denied, hints };
93
98
  }
94
99
 
95
100
  close(): void {
package/src/connect.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  import { EgenClient, connectToEgen, type ConnectOptions as EmbeddedOptions } from '@egen-civitas/esm-embed-client';
2
- import { EmbedError, CAPABILITIES, CAPABILITY_IDS, type CapabilityId } from '@egen-civitas/esm-embed-protocol';
2
+ import { EmbedError, CAPABILITIES, CAPABILITY_IDS, type CapabilityId, type LifecycleState } from '@egen-civitas/esm-embed-protocol';
3
3
  import { EgenApp, type EgenMode } from './app.js';
4
4
  import { STANDALONE_CAPABILITIES, createStandaloneRuntime, type StandaloneOptions } from './standalone.js';
5
5
 
6
+ /** Transitions d'état et erreurs de protocole (spec §6 / §497) : `connecting` et `failed` n'existent qu'ici. */
7
+ export type DiagnosticEvent = { type: 'state'; state: LifecycleState } | { type: 'error'; error: EmbedError };
8
+
6
9
  export interface ConnectOptions extends Omit<EmbeddedOptions, 'hostOrigins'> {
7
10
  /** Origines EXACTES du Shell. Obligatoire pour le mode embarqué ; sans elles, `auto` reste en mode autonome. */
8
11
  hostOrigins?: string[];
@@ -15,6 +18,8 @@ export interface ConnectOptions extends Omit<EmbeddedOptions, 'hostOrigins'> {
15
18
  required?: CapabilityId[];
16
19
  /** Comportement hors Shell. */
17
20
  standalone?: StandaloneOptions;
21
+ /** Reçoit les transitions d'état (`connecting` → `ready`/`standalone`/`failed` → …) et les erreurs de protocole. */
22
+ onDiagnostic?: (e: DiagnosticEvent) => void;
18
23
  }
19
24
 
20
25
  const inIframe = (w?: unknown): boolean => {
@@ -50,6 +55,28 @@ function enforceRequired(app: EgenApp, required: CapabilityId[] | undefined): Eg
50
55
  * ou si `mode: 'embedded'` est exigé sans Shell (erreurs typées `EgenError`).
51
56
  */
52
57
  export async function connect(options: ConnectOptions): Promise<EgenApp> {
58
+ const emit = (e: DiagnosticEvent) => {
59
+ try {
60
+ options?.onDiagnostic?.(e);
61
+ } catch {
62
+ /* un observateur ne casse jamais la connexion */
63
+ }
64
+ };
65
+ emit({ type: 'state', state: 'connecting' });
66
+ try {
67
+ const app = await connectInner(options);
68
+ emit({ type: 'state', state: app.state });
69
+ app.client.lifecycle.onStateChange((state) => emit({ type: 'state', state }));
70
+ app.client.lifecycle.onError((error) => emit({ type: 'error', error }));
71
+ return app;
72
+ } catch (e) {
73
+ emit({ type: 'state', state: 'failed' });
74
+ if (e instanceof EmbedError) emit({ type: 'error', error: e });
75
+ throw e;
76
+ }
77
+ }
78
+
79
+ async function connectInner(options: ConnectOptions): Promise<EgenApp> {
53
80
  if (!options || typeof options.moduleName !== 'string' || !options.moduleName) throw new EmbedError('INVALID_ARGS', 'connect : moduleName est obligatoire');
54
81
  const mode = options.mode ?? 'auto';
55
82
  const standalone = (note: string) => enforceRequired(new EgenApp(localClient(options), 'standalone', note), options.required);
package/src/index.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { connect, type ConnectOptions } from './connect.js';
1
+ export { connect, type ConnectOptions, type DiagnosticEvent } from './connect.js';
2
2
  export { EgenApp, type Diagnosis, type EgenMode } from './app.js';
3
3
  export { EgenError, isEgenError, type EgenErrorCode } from './errors.js';
4
4
  export { createStandaloneRuntime, STANDALONE_CAPABILITIES, type StandaloneOptions } from './standalone.js';
5
5
  export { SDK_VERSION } from './version.js';
6
6
  // Compatibilité : les apps existantes gardent `connectToEgen` / `EgenClient` (dépréciation : voir roadmap §4).
7
7
  export { connectToEgen, EgenClient } from '@egen-civitas/esm-embed-client';
8
- export type { CapabilityId, CapabilityDenied, CapabilityGranted } from '@egen-civitas/esm-embed-protocol';
8
+ export type { LifecycleState, CapabilityId, CapabilityDenied, CapabilityGranted } from '@egen-civitas/esm-embed-protocol';
package/src/standalone.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EmbedError, validateCall, type CapabilityId } from '@egen-civitas/esm-embed-protocol';
1
+ import { EmbedError, buildInternalHref, validateCall, type CapabilityId, type NavigateOptions } from '@egen-civitas/esm-embed-protocol';
2
2
  import type { RpcLike } from '@egen-civitas/esm-embed-client';
3
3
 
4
4
  type Json = Record<string, unknown>;
@@ -16,7 +16,11 @@ export interface StandaloneOptions {
16
16
  /** Reçoit `telemetry.log` / `telemetry.metric` (défaut : ignorés). */
17
17
  onTelemetry?: (kind: 'log' | 'metric', data: unknown[]) => void;
18
18
  /** Injectables pour les tests / hors navigateur. */
19
- window?: Pick<Window, 'history' | 'document'> & { navigator?: { language?: string } };
19
+ window?: Pick<Window, 'history' | 'document'> & { navigator?: { language?: string }; location?: Pick<Location, 'pathname' | 'search' | 'hash'>; open?: Window['open'] };
20
+ /** Table des routes locale (`navigation.exists`, `NOT_FOUND`). Absente : `exists` indisponible. */
21
+ routeExists?: (path: string) => boolean | Promise<boolean>;
22
+ /** Intents `objet-action` → chemin local (`null` : inconnu). Absent : `intent` indisponible. */
23
+ intents?: (slug: string, params: Record<string, unknown>) => string | null | Promise<string | null>;
20
24
  }
21
25
 
22
26
  type Handler = (args: unknown[]) => unknown | Promise<unknown>;
@@ -30,9 +34,26 @@ export function createStandaloneRuntime(opts: StandaloneOptions = {}): RpcLike {
30
34
  const listeners = new Map<string, Set<(v: unknown) => void>>();
31
35
  let closed = false;
32
36
  let seq = 0;
37
+ // Visibilité locale (spec §6.2 : `document.visibilitychange` en mode autonome).
38
+ const doc = win?.document as (Document & { hidden?: boolean }) | undefined;
39
+ const onVisibility = () => emit('lifecycle', 'visibility', !doc?.hidden);
40
+ doc?.addEventListener?.('visibilitychange', onVisibility);
33
41
  const emit = (cap: string, ev: string, v: unknown) => listeners.get(`${cap}:${ev}`)?.forEach((cb) => cb(v));
34
42
  const unsupported = (what: string) => new EmbedError('UNSUPPORTED_IN_MODE', `${what} : indisponible hors du Shell EGEN (mode autonome)`);
35
43
 
44
+ const navigateLocal = async (to: string, o?: NavigateOptions) => {
45
+ const href = o && (o.query || o.hash) ? buildInternalHref(to, { query: o.query, hash: o.hash }) : to;
46
+ const pathOnly = href.split(/[?#]/, 1)[0]!;
47
+ if (opts.routeExists && !(await opts.routeExists(pathOnly))) throw new EmbedError('NOT_FOUND', `Route inconnue : ${pathOnly}`);
48
+ if (o?.target === 'newTab') win?.open?.(href, '_blank', 'noopener,noreferrer');
49
+ else {
50
+ if (o?.replace) win?.history.replaceState(null, '', href);
51
+ else win?.history.pushState(null, '', href);
52
+ emit('navigation', 'goto', { path: href, seq: ++seq });
53
+ }
54
+ return { status: 'done' as const, path: href };
55
+ };
56
+
36
57
  const handlers: Record<string, Record<string, Handler>> = {
37
58
  tenant: { get: () => ({ id: opts.tenantId ?? null }) },
38
59
  locale: { get: () => opts.locale ?? win?.navigator?.language ?? 'fr' },
@@ -61,9 +82,23 @@ export function createStandaloneRuntime(opts: StandaloneOptions = {}): RpcLike {
61
82
  if (win) (replace ? win.history.replaceState : win.history.pushState).call(win.history, null, '', path as string);
62
83
  if (title && win) win.document.title = title;
63
84
  },
64
- navigate: ([to]) => {
65
- win?.history.pushState(null, '', to as string);
66
- emit('navigation', 'goto', { path: to, seq: ++seq });
85
+ navigate: ([to, o]) => navigateLocal(to as string, o as NavigateOptions | undefined),
86
+ current: () => {
87
+ const l = win?.location;
88
+ const u = new URL(`${l?.pathname ?? '/'}${l?.search ?? ''}${l?.hash ?? ''}`, 'http://app.invalid');
89
+ return { path: u.pathname, query: Object.fromEntries(u.searchParams), hash: u.hash, title: win?.document.title };
90
+ },
91
+ exists: async ([path]) => {
92
+ if (!opts.routeExists) throw unsupported('navigation.exists');
93
+ return !!(await opts.routeExists(path as string));
94
+ },
95
+ back: () => void win?.history.back(),
96
+ canGoBack: () => (win?.history.length ?? 0) > 1,
97
+ intent: async ([slug, params, o]) => {
98
+ if (!opts.intents) throw unsupported('navigation.intent');
99
+ const target = await opts.intents(slug as string, (params as Json | undefined) ?? {});
100
+ if (target === null) throw new EmbedError('NOT_FOUND', `Intent inconnu : ${slug}`);
101
+ return navigateLocal(target, o as NavigateOptions | undefined);
67
102
  },
68
103
  notFound: () => undefined,
69
104
  setTitle: ([t]) => {
@@ -94,6 +129,7 @@ export function createStandaloneRuntime(opts: StandaloneOptions = {}): RpcLike {
94
129
  return () => void set!.delete(cb);
95
130
  },
96
131
  close() {
132
+ doc?.removeEventListener?.('visibilitychange', onVisibility);
97
133
  closed = true;
98
134
  listeners.clear();
99
135
  },
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Version de la façade SDK. Générée depuis le package.json par `scripts/sync-sdk-version.mjs` ; `version.test.ts` garde la cohérence. */
2
- export const SDK_VERSION = '0.2.0';
2
+ export const SDK_VERSION = '0.4.0';