@egen-civitas/sdk 0.0.0-stage → 0.2.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 +15 -0
- package/README.md +33 -2
- package/dist/app.d.ts +53 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +169 -0
- package/dist/connect.d.ts +23 -0
- package/dist/connect.d.ts.map +1 -0
- package/dist/connect.js +316 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/standalone.d.ts +35 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +412 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +1 -0
- package/package.json +62 -3
- package/src/app.ts +98 -0
- package/src/connect.ts +73 -0
- package/src/errors.ts +14 -0
- package/src/index.ts +8 -0
- package/src/standalone.ts +104 -0
- package/src/version.ts +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @egen-civitas/sdk
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d74087b: Réforme SDK EGEN (lots A/B) : façade `@egen-civitas/sdk` (`connect`, `EgenApp`, `EgenError`, modes embarqué/autonome, `required`, `diagnose`) ;
|
|
8
|
+
manifeste v2 additif et codes d'erreur additionnels (repli `INTERNAL` côté ancien hôte) ; `sdkVersion` dérivé du package.json ;
|
|
9
|
+
référence des capacités générée depuis le catalogue ; transport du client abstrait (`RpcLike`).
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [d74087b]
|
|
14
|
+
- @egen-civitas/esm-embed-protocol@0.7.0
|
|
15
|
+
- @egen-civitas/esm-embed-client@0.8.0
|
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @egen-civitas/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Point d'entrée unique pour développer une application intégrée au Shell EGEN.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { connect } from '@egen-civitas/sdk';
|
|
7
|
+
|
|
8
|
+
const egen = await connect({
|
|
9
|
+
moduleName: '@acme/dossier-app',
|
|
10
|
+
hostOrigins: ['https://egen.exemple.org'],
|
|
11
|
+
capabilities: ['navigation', 'notifications', 'tenant'],
|
|
12
|
+
required: ['navigation'], // échoue (EgenError DENIED) si non accordée
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
egen.mode; // 'embedded' | 'standalone'
|
|
16
|
+
await egen.navigation.report('/dossiers/42');
|
|
17
|
+
await egen.notify({ kind: 'success', title: 'Enregistré' }, localToast);
|
|
18
|
+
console.table(egen.diagnose()); // pistes lisibles en cas de refus / d'absence de Shell
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Modes
|
|
22
|
+
|
|
23
|
+
| Mode | Quand | Comportement |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `embedded` | page dans une iframe du Shell | protocole v2 (MessageChannel, nonce, grants) via `@egen-civitas/esm-embed-client` |
|
|
26
|
+
| `standalone` | hors Shell, ou Shell muet en `auto` | runtime local : navigation → History, événements locaux, `notify` → affichage local, le reste est refusé `UNSUPPORTED_IN_MODE` |
|
|
27
|
+
|
|
28
|
+
`mode: 'auto'` (défaut) choisit seul ; `'embedded'` exige le Shell (`TIMEOUT` sinon) ; `'standalone'` ne tente jamais de connexion.
|
|
29
|
+
|
|
30
|
+
## Compatibilité
|
|
31
|
+
|
|
32
|
+
`connectToEgen` et `EgenClient` restent exportés (aucune app existante à migrer). Les erreurs sont les `EmbedError` du protocole
|
|
33
|
+
(`EgenError` en est l'alias ; `isEgenError(e, code?)`). La référence des capacités est générée :
|
|
34
|
+
`@egen-civitas/esm-embed-protocol/docs/CAPABILITIES.generated.md`.
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { EgenClient } from '@egen-civitas/esm-embed-client';
|
|
2
|
+
import type { CapabilityDenied, CapabilityId } from '@egen-civitas/esm-embed-protocol';
|
|
3
|
+
export type EgenMode = 'embedded' | 'standalone';
|
|
4
|
+
export interface Diagnosis {
|
|
5
|
+
mode: EgenMode;
|
|
6
|
+
/** `true` seulement si une connexion au Shell est établie. */
|
|
7
|
+
connected: boolean;
|
|
8
|
+
moduleName: string;
|
|
9
|
+
sdkVersion: string;
|
|
10
|
+
protocol: number | undefined;
|
|
11
|
+
granted: string[];
|
|
12
|
+
denied: CapabilityDenied[];
|
|
13
|
+
/** Pistes lisibles pour comprendre un comportement inattendu. */
|
|
14
|
+
hints: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Application connectée à EGEN. Même surface quel que soit le mode : le code de l'app ne change pas selon qu'elle tourne
|
|
18
|
+
* dans le Shell (`embedded`) ou seule (`standalone`). `client` donne accès au client embarqué sous-jacent (échappatoire).
|
|
19
|
+
*/
|
|
20
|
+
export declare class EgenApp {
|
|
21
|
+
private readonly note?;
|
|
22
|
+
readonly mode: EgenMode;
|
|
23
|
+
readonly sdkVersion = "0.2.0";
|
|
24
|
+
readonly client: EgenClient;
|
|
25
|
+
readonly tenant: EgenClient['tenant'];
|
|
26
|
+
readonly locale: EgenClient['locale'];
|
|
27
|
+
readonly navigation: EgenClient['navigation'];
|
|
28
|
+
readonly events: EgenClient['events'];
|
|
29
|
+
readonly notifications: EgenClient['notifications'];
|
|
30
|
+
readonly dialogs: EgenClient['dialogs'];
|
|
31
|
+
readonly flags: EgenClient['flags'];
|
|
32
|
+
readonly config: EgenClient['config'];
|
|
33
|
+
readonly telemetry: EgenClient['telemetry'];
|
|
34
|
+
readonly lifecycle: EgenClient['lifecycle'];
|
|
35
|
+
readonly extensions: EgenClient['extensions'];
|
|
36
|
+
constructor(client: EgenClient, mode: EgenMode, note?: string | undefined);
|
|
37
|
+
get moduleName(): string;
|
|
38
|
+
/** Connexion au Shell établie (toujours `false` en mode autonome). */
|
|
39
|
+
get connected(): boolean;
|
|
40
|
+
get closed(): boolean;
|
|
41
|
+
/** Le Core affiche-t-il seul les notifications de l'app ? (voir `EgenClient.coreDisplaysNotifications`). */
|
|
42
|
+
get coreDisplaysNotifications(): boolean;
|
|
43
|
+
has(id: CapabilityId): boolean;
|
|
44
|
+
get capabilities(): {
|
|
45
|
+
granted: CapabilityId[];
|
|
46
|
+
denied: CapabilityDenied[];
|
|
47
|
+
};
|
|
48
|
+
/** Notification sans doublon : Core si disponible, sinon `local`. */
|
|
49
|
+
notify: EgenClient['notify'];
|
|
50
|
+
diagnose(): Diagnosis;
|
|
51
|
+
close(): void;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +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,GAAG,SAAS,CAAC;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,iEAAiE;IACjE,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,OAAO;IAiB8B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAhBtE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,UAAU,WAAe;IAClC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAE5B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC5C,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;gBAElC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAmB,IAAI,CAAC,EAAE,MAAM,YAAA;IAgB9E,IAAI,UAAU,IAAI,MAAM,CAEvB;IACD,sEAAsE;IACtE,IAAI,SAAS,IAAI,OAAO,CAEvB;IACD,IAAI,MAAM,IAAI,OAAO,CAEpB;IACD,4GAA4G;IAC5G,IAAI,yBAAyB,IAAI,OAAO,CAEvC;IAED,GAAG,CAAC,EAAE,EAAE,YAAY,GAAG,OAAO;IAG9B,IAAI,YAAY,IAAI;QAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;KAAE,CAE1E;IAED,qEAAqE;IACrE,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAsD;IAElF,QAAQ,IAAI,SAAS;IAarB,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/app.js
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function _defineProperties(target, props) {
|
|
7
|
+
for(var i = 0; i < props.length; i++){
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
12
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
16
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
+
return Constructor;
|
|
19
|
+
}
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
import { SDK_VERSION } from './version.js';
|
|
34
|
+
/**
|
|
35
|
+
* Application connectée à EGEN. Même surface quel que soit le mode : le code de l'app ne change pas selon qu'elle tourne
|
|
36
|
+
* dans le Shell (`embedded`) ou seule (`standalone`). `client` donne accès au client embarqué sous-jacent (échappatoire).
|
|
37
|
+
*/ export var EgenApp = /*#__PURE__*/ function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
function EgenApp(client, mode, note) {
|
|
40
|
+
var _this = this;
|
|
41
|
+
_class_call_check(this, EgenApp);
|
|
42
|
+
_define_property(this, "note", void 0);
|
|
43
|
+
_define_property(this, "mode", void 0);
|
|
44
|
+
_define_property(this, "sdkVersion", void 0);
|
|
45
|
+
_define_property(this, "client", void 0);
|
|
46
|
+
_define_property(this, "tenant", void 0);
|
|
47
|
+
_define_property(this, "locale", void 0);
|
|
48
|
+
_define_property(this, "navigation", void 0);
|
|
49
|
+
_define_property(this, "events", void 0);
|
|
50
|
+
_define_property(this, "notifications", void 0);
|
|
51
|
+
_define_property(this, "dialogs", void 0);
|
|
52
|
+
_define_property(this, "flags", void 0);
|
|
53
|
+
_define_property(this, "config", void 0);
|
|
54
|
+
_define_property(this, "telemetry", void 0);
|
|
55
|
+
_define_property(this, "lifecycle", void 0);
|
|
56
|
+
_define_property(this, "extensions", void 0);
|
|
57
|
+
/** Notification sans doublon : Core si disponible, sinon `local`. */ _define_property(this, "notify", void 0);
|
|
58
|
+
this.note = note;
|
|
59
|
+
this.sdkVersion = SDK_VERSION;
|
|
60
|
+
this.notify = function(toast, local) {
|
|
61
|
+
return _this.client.notify(toast, local);
|
|
62
|
+
};
|
|
63
|
+
this.client = client;
|
|
64
|
+
this.mode = mode;
|
|
65
|
+
this.tenant = client.tenant;
|
|
66
|
+
this.locale = client.locale;
|
|
67
|
+
this.navigation = client.navigation;
|
|
68
|
+
this.events = client.events;
|
|
69
|
+
this.notifications = client.notifications;
|
|
70
|
+
this.dialogs = client.dialogs;
|
|
71
|
+
this.flags = client.flags;
|
|
72
|
+
this.config = client.config;
|
|
73
|
+
this.telemetry = client.telemetry;
|
|
74
|
+
this.lifecycle = client.lifecycle;
|
|
75
|
+
this.extensions = client.extensions;
|
|
76
|
+
}
|
|
77
|
+
_create_class(EgenApp, [
|
|
78
|
+
{
|
|
79
|
+
key: "moduleName",
|
|
80
|
+
get: function get() {
|
|
81
|
+
return this.client.moduleName;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "connected",
|
|
86
|
+
get: /** Connexion au Shell établie (toujours `false` en mode autonome). */ function get() {
|
|
87
|
+
return this.client.connected;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
key: "closed",
|
|
92
|
+
get: function get() {
|
|
93
|
+
return this.client.closed;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "coreDisplaysNotifications",
|
|
98
|
+
get: /** Le Core affiche-t-il seul les notifications de l'app ? (voir `EgenClient.coreDisplaysNotifications`). */ function get() {
|
|
99
|
+
return this.client.coreDisplaysNotifications;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: "has",
|
|
104
|
+
value: function has(id) {
|
|
105
|
+
return this.client.has(id);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
key: "capabilities",
|
|
110
|
+
get: function get() {
|
|
111
|
+
return {
|
|
112
|
+
granted: this.client.capabilities.map(function(g) {
|
|
113
|
+
return g.id;
|
|
114
|
+
}),
|
|
115
|
+
denied: this.client.denied
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
key: "diagnose",
|
|
121
|
+
value: function diagnose() {
|
|
122
|
+
var _this_note;
|
|
123
|
+
var denied = this.client.denied;
|
|
124
|
+
var hints = [];
|
|
125
|
+
if (this.mode === 'standalone') hints.push((_this_note = this.note) !== null && _this_note !== void 0 ? _this_note : "Mode autonome : l'app n'est pas connectée au Shell EGEN.");
|
|
126
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
127
|
+
try {
|
|
128
|
+
for(var _iterator = denied[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
129
|
+
var d = _step.value;
|
|
130
|
+
if (d.reason === 'NOT_APPROVED') hints.push("\xab ".concat(d.id, " \xbb : non approuv\xe9e par l'op\xe9rateur (external-apps.json)."));
|
|
131
|
+
else if (d.reason === 'UNAVAILABLE') hints.push("\xab ".concat(d.id, " \xbb : le Shell ne sert pas cette capacit\xe9 (h\xf4te plus ancien ?)."));
|
|
132
|
+
else if (d.reason === 'VERSION') hints.push("\xab ".concat(d.id, " \xbb : version de capacit\xe9 non prise en charge par le Shell."));
|
|
133
|
+
else hints.push("\xab ".concat(d.id, " \xbb : inconnue du Shell (SDK plus r\xe9cent que le Shell ?)."));
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
_didIteratorError = true;
|
|
137
|
+
_iteratorError = err;
|
|
138
|
+
} finally{
|
|
139
|
+
try {
|
|
140
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
141
|
+
_iterator.return();
|
|
142
|
+
}
|
|
143
|
+
} finally{
|
|
144
|
+
if (_didIteratorError) {
|
|
145
|
+
throw _iteratorError;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
mode: this.mode,
|
|
151
|
+
connected: this.connected,
|
|
152
|
+
moduleName: this.moduleName,
|
|
153
|
+
sdkVersion: this.sdkVersion,
|
|
154
|
+
protocol: this.client.protocol,
|
|
155
|
+
granted: this.capabilities.granted,
|
|
156
|
+
denied: denied,
|
|
157
|
+
hints: hints
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
key: "close",
|
|
163
|
+
value: function close() {
|
|
164
|
+
this.client.close();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
]);
|
|
168
|
+
return EgenApp;
|
|
169
|
+
}();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ConnectOptions as EmbeddedOptions } from '@egen-civitas/esm-embed-client';
|
|
2
|
+
import { type CapabilityId } from '@egen-civitas/esm-embed-protocol';
|
|
3
|
+
import { EgenApp, type EgenMode } from './app.js';
|
|
4
|
+
import { type StandaloneOptions } from './standalone.js';
|
|
5
|
+
export interface ConnectOptions extends Omit<EmbeddedOptions, 'hostOrigins'> {
|
|
6
|
+
/** Origines EXACTES du Shell. Obligatoire pour le mode embarqué ; sans elles, `auto` reste en mode autonome. */
|
|
7
|
+
hostOrigins?: string[];
|
|
8
|
+
/**
|
|
9
|
+
* `auto` (défaut) : embarqué si la page est dans une iframe, autonome sinon ou si le Shell ne répond pas ;
|
|
10
|
+
* `embedded` : exige le Shell (échec explicite sinon) ; `standalone` : n'essaie jamais de se connecter.
|
|
11
|
+
*/
|
|
12
|
+
mode?: 'auto' | EgenMode;
|
|
13
|
+
/** Capacités sans lesquelles l'app ne peut pas fonctionner : `connect()` échoue si l'une manque. */
|
|
14
|
+
required?: CapabilityId[];
|
|
15
|
+
/** Comportement hors Shell. */
|
|
16
|
+
standalone?: StandaloneOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Point d'entrée unique du SDK. Retourne toujours une `EgenApp` utilisable, sauf si `required` n'est pas satisfait
|
|
20
|
+
* ou si `mode: 'embedded'` est exigé sans Shell (erreurs typées `EgenError`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function connect(options: ConnectOptions): Promise<EgenApp>;
|
|
23
|
+
//# sourceMappingURL=connect.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/connect.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
+
try {
|
|
11
|
+
var info = gen[key](arg);
|
|
12
|
+
var value = info.value;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
reject(error);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (info.done) {
|
|
18
|
+
resolve(value);
|
|
19
|
+
} else {
|
|
20
|
+
Promise.resolve(value).then(_next, _throw);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function _async_to_generator(fn) {
|
|
24
|
+
return function() {
|
|
25
|
+
var self = this, args = arguments;
|
|
26
|
+
return new Promise(function(resolve, reject) {
|
|
27
|
+
var gen = fn.apply(self, args);
|
|
28
|
+
function _next(value) {
|
|
29
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
+
}
|
|
31
|
+
function _throw(err) {
|
|
32
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
+
}
|
|
34
|
+
_next(undefined);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) {
|
|
40
|
+
Object.defineProperty(obj, key, {
|
|
41
|
+
value: value,
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true
|
|
45
|
+
});
|
|
46
|
+
} else {
|
|
47
|
+
obj[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
function _iterable_to_array(iter) {
|
|
52
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
53
|
+
}
|
|
54
|
+
function _non_iterable_spread() {
|
|
55
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
56
|
+
}
|
|
57
|
+
function _object_spread(target) {
|
|
58
|
+
for(var i = 1; i < arguments.length; i++){
|
|
59
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
60
|
+
var ownKeys = Object.keys(source);
|
|
61
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
62
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
63
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
ownKeys.forEach(function(key) {
|
|
67
|
+
_define_property(target, key, source[key]);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
function ownKeys(object, enumerableOnly) {
|
|
73
|
+
var keys = Object.keys(object);
|
|
74
|
+
if (Object.getOwnPropertySymbols) {
|
|
75
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
76
|
+
if (enumerableOnly) {
|
|
77
|
+
symbols = symbols.filter(function(sym) {
|
|
78
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
keys.push.apply(keys, symbols);
|
|
82
|
+
}
|
|
83
|
+
return keys;
|
|
84
|
+
}
|
|
85
|
+
function _object_spread_props(target, source) {
|
|
86
|
+
source = source != null ? source : {};
|
|
87
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
88
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
89
|
+
} else {
|
|
90
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
91
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
function _to_consumable_array(arr) {
|
|
97
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
98
|
+
}
|
|
99
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
100
|
+
if (!o) return;
|
|
101
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
102
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
103
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
104
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
105
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
106
|
+
}
|
|
107
|
+
function _ts_generator(thisArg, body) {
|
|
108
|
+
var f, y, t, _ = {
|
|
109
|
+
label: 0,
|
|
110
|
+
sent: function() {
|
|
111
|
+
if (t[0] & 1) throw t[1];
|
|
112
|
+
return t[1];
|
|
113
|
+
},
|
|
114
|
+
trys: [],
|
|
115
|
+
ops: []
|
|
116
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
117
|
+
return d(g, "next", {
|
|
118
|
+
value: verb(0)
|
|
119
|
+
}), d(g, "throw", {
|
|
120
|
+
value: verb(1)
|
|
121
|
+
}), d(g, "return", {
|
|
122
|
+
value: verb(2)
|
|
123
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
124
|
+
value: function() {
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
}), g;
|
|
128
|
+
function verb(n) {
|
|
129
|
+
return function(v) {
|
|
130
|
+
return step([
|
|
131
|
+
n,
|
|
132
|
+
v
|
|
133
|
+
]);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function step(op) {
|
|
137
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
138
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
139
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
140
|
+
if (y = 0, t) op = [
|
|
141
|
+
op[0] & 2,
|
|
142
|
+
t.value
|
|
143
|
+
];
|
|
144
|
+
switch(op[0]){
|
|
145
|
+
case 0:
|
|
146
|
+
case 1:
|
|
147
|
+
t = op;
|
|
148
|
+
break;
|
|
149
|
+
case 4:
|
|
150
|
+
_.label++;
|
|
151
|
+
return {
|
|
152
|
+
value: op[1],
|
|
153
|
+
done: false
|
|
154
|
+
};
|
|
155
|
+
case 5:
|
|
156
|
+
_.label++;
|
|
157
|
+
y = op[1];
|
|
158
|
+
op = [
|
|
159
|
+
0
|
|
160
|
+
];
|
|
161
|
+
continue;
|
|
162
|
+
case 7:
|
|
163
|
+
op = _.ops.pop();
|
|
164
|
+
_.trys.pop();
|
|
165
|
+
continue;
|
|
166
|
+
default:
|
|
167
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
168
|
+
_ = 0;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
172
|
+
_.label = op[1];
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
176
|
+
_.label = t[1];
|
|
177
|
+
t = op;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
if (t && _.label < t[2]) {
|
|
181
|
+
_.label = t[2];
|
|
182
|
+
_.ops.push(op);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (t[2]) _.ops.pop();
|
|
186
|
+
_.trys.pop();
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
op = body.call(thisArg, _);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
op = [
|
|
192
|
+
6,
|
|
193
|
+
e
|
|
194
|
+
];
|
|
195
|
+
y = 0;
|
|
196
|
+
} finally{
|
|
197
|
+
f = t = 0;
|
|
198
|
+
}
|
|
199
|
+
if (op[0] & 5) throw op[1];
|
|
200
|
+
return {
|
|
201
|
+
value: op[0] ? op[1] : void 0,
|
|
202
|
+
done: true
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
import { EgenClient, connectToEgen } from '@egen-civitas/esm-embed-client';
|
|
207
|
+
import { EmbedError, CAPABILITIES, CAPABILITY_IDS } from '@egen-civitas/esm-embed-protocol';
|
|
208
|
+
import { EgenApp } from './app.js';
|
|
209
|
+
import { STANDALONE_CAPABILITIES, createStandaloneRuntime } from './standalone.js';
|
|
210
|
+
var inIframe = function inIframe(w) {
|
|
211
|
+
if (w !== undefined) return true; // fenêtre injectée (tests) : on suppose un hôte
|
|
212
|
+
try {
|
|
213
|
+
return typeof window !== 'undefined' && window.parent !== window;
|
|
214
|
+
} catch (unused) {
|
|
215
|
+
return true; // accès à window.parent refusé : on est bien dans un cadre d'une autre origine
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
function localClient(options) {
|
|
219
|
+
var _options_capabilities, _options_required;
|
|
220
|
+
var requested = ((_options_capabilities = options.capabilities) !== null && _options_capabilities !== void 0 ? _options_capabilities : CAPABILITY_IDS.filter(function(id) {
|
|
221
|
+
return CAPABILITIES[id].defaultGrant;
|
|
222
|
+
})).map(function(c) {
|
|
223
|
+
return typeof c === 'string' ? c : c.id;
|
|
224
|
+
});
|
|
225
|
+
var ids = new Set(_to_consumable_array(requested).concat(_to_consumable_array((_options_required = options.required) !== null && _options_required !== void 0 ? _options_required : [])));
|
|
226
|
+
var granted = _to_consumable_array(ids).filter(function(id) {
|
|
227
|
+
return STANDALONE_CAPABILITIES.includes(id);
|
|
228
|
+
}).map(function(id) {
|
|
229
|
+
return {
|
|
230
|
+
id: id,
|
|
231
|
+
version: CAPABILITIES[id].version,
|
|
232
|
+
config: id === 'notifications' ? {
|
|
233
|
+
exclusive: false
|
|
234
|
+
} : {}
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
var denied = _to_consumable_array(ids).filter(function(id) {
|
|
238
|
+
return !STANDALONE_CAPABILITIES.includes(id);
|
|
239
|
+
}).map(function(id) {
|
|
240
|
+
return {
|
|
241
|
+
id: id,
|
|
242
|
+
reason: 'UNAVAILABLE'
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
return new EgenClient({
|
|
246
|
+
connected: false,
|
|
247
|
+
moduleName: options.moduleName,
|
|
248
|
+
granted: granted,
|
|
249
|
+
denied: denied,
|
|
250
|
+
rpc: createStandaloneRuntime(options.standalone)
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function enforceRequired(app, required) {
|
|
254
|
+
var missing = (required !== null && required !== void 0 ? required : []).filter(function(id) {
|
|
255
|
+
return !app.has(id);
|
|
256
|
+
});
|
|
257
|
+
if (missing.length) {
|
|
258
|
+
app.close();
|
|
259
|
+
throw new EmbedError('DENIED', "Capacit\xe9s requises non accord\xe9es (".concat(app.mode, ") : ").concat(missing.join(', ')));
|
|
260
|
+
}
|
|
261
|
+
return app;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Point d'entrée unique du SDK. Retourne toujours une `EgenApp` utilisable, sauf si `required` n'est pas satisfait
|
|
265
|
+
* ou si `mode: 'embedded'` est exigé sans Shell (erreurs typées `EgenError`).
|
|
266
|
+
*/ export function connect(options) {
|
|
267
|
+
return _async_to_generator(function() {
|
|
268
|
+
var _options_mode, mode, standalone, origins, client;
|
|
269
|
+
return _ts_generator(this, function(_state) {
|
|
270
|
+
switch(_state.label){
|
|
271
|
+
case 0:
|
|
272
|
+
if (!options || typeof options.moduleName !== 'string' || !options.moduleName) throw new EmbedError('INVALID_ARGS', 'connect : moduleName est obligatoire');
|
|
273
|
+
mode = (_options_mode = options.mode) !== null && _options_mode !== void 0 ? _options_mode : 'auto';
|
|
274
|
+
standalone = function standalone(note) {
|
|
275
|
+
return enforceRequired(new EgenApp(localClient(options), 'standalone', note), options.required);
|
|
276
|
+
};
|
|
277
|
+
if (mode === 'standalone') return [
|
|
278
|
+
2,
|
|
279
|
+
standalone('Mode autonome demandé explicitement.')
|
|
280
|
+
];
|
|
281
|
+
origins = options.hostOrigins;
|
|
282
|
+
if (!origins || origins.length === 0) {
|
|
283
|
+
if (mode === 'embedded') throw new EmbedError('INVALID_ARGS', 'connect : hostOrigins est obligatoire en mode embedded');
|
|
284
|
+
return [
|
|
285
|
+
2,
|
|
286
|
+
standalone('Aucune origine de Shell fournie (hostOrigins) : mode autonome.')
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
if (!inIframe(options.window)) {
|
|
290
|
+
if (mode === 'embedded') throw new EmbedError('UNSUPPORTED_IN_MODE', "connect : mode embedded exigé mais la page n'est pas dans une iframe du Shell");
|
|
291
|
+
return [
|
|
292
|
+
2,
|
|
293
|
+
standalone("Page ouverte hors d'une iframe : mode autonome.")
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
return [
|
|
297
|
+
4,
|
|
298
|
+
connectToEgen(_object_spread_props(_object_spread({}, options), {
|
|
299
|
+
hostOrigins: origins
|
|
300
|
+
}))
|
|
301
|
+
];
|
|
302
|
+
case 1:
|
|
303
|
+
client = _state.sent();
|
|
304
|
+
if (client.connected) return [
|
|
305
|
+
2,
|
|
306
|
+
enforceRequired(new EgenApp(client, 'embedded'), options.required)
|
|
307
|
+
];
|
|
308
|
+
if (mode === 'embedded') throw new EmbedError('TIMEOUT', "Aucune r\xe9ponse du Shell pour \xab ".concat(options.moduleName, " \xbb (voir les pistes de diagnostic dans la console)"));
|
|
309
|
+
return [
|
|
310
|
+
2,
|
|
311
|
+
standalone("Le Shell n'a pas répondu à la poignée de main : mode autonome.")
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
})();
|
|
316
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EmbedError, type ErrorCode } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Erreur typée du SDK. C'est la MÊME classe que celle du protocole : toute erreur levée par le client
|
|
4
|
+
* embarqué est donc reconnue par `instanceof EgenError` / `isEgenError`.
|
|
5
|
+
* Codes : DENIED, UNKNOWN_CAPABILITY, UNKNOWN_METHOD, INVALID_ARGS, TIMEOUT, RATE_LIMITED, TOO_LARGE, CLOSED, INTERNAL,
|
|
6
|
+
* NOT_FOUND, CANCELLED, QUOTA_EXCEEDED, UNSUPPORTED_IN_MODE.
|
|
7
|
+
*/
|
|
8
|
+
export { EmbedError as EgenError };
|
|
9
|
+
export type EgenErrorCode = ErrorCode;
|
|
10
|
+
export declare function isEgenError(e: unknown, code?: EgenErrorCode): e is EmbedError;
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE9E;;;;;GAKG;AACH,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,CAAC;AACnC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC;AAEtC,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,CAAC,IAAI,UAAU,CAE7E"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
function _instanceof(left, right) {
|
|
2
|
+
"@swc/helpers - instanceof";
|
|
3
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
4
|
+
return !!right[Symbol.hasInstance](left);
|
|
5
|
+
} else {
|
|
6
|
+
return left instanceof right;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
import { EmbedError } from '@egen-civitas/esm-embed-protocol';
|
|
10
|
+
/**
|
|
11
|
+
* Erreur typée du SDK. C'est la MÊME classe que celle du protocole : toute erreur levée par le client
|
|
12
|
+
* embarqué est donc reconnue par `instanceof EgenError` / `isEgenError`.
|
|
13
|
+
* Codes : DENIED, UNKNOWN_CAPABILITY, UNKNOWN_METHOD, INVALID_ARGS, TIMEOUT, RATE_LIMITED, TOO_LARGE, CLOSED, INTERNAL,
|
|
14
|
+
* NOT_FOUND, CANCELLED, QUOTA_EXCEEDED, UNSUPPORTED_IN_MODE.
|
|
15
|
+
*/ export { EmbedError as EgenError };
|
|
16
|
+
export function isEgenError(e, code) {
|
|
17
|
+
return _instanceof(e, EmbedError) && (code === undefined || e.code === code);
|
|
18
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { connect, type ConnectOptions } from './connect.js';
|
|
2
|
+
export { EgenApp, type Diagnosis, type EgenMode } from './app.js';
|
|
3
|
+
export { EgenError, isEgenError, type EgenErrorCode } from './errors.js';
|
|
4
|
+
export { createStandaloneRuntime, STANDALONE_CAPABILITIES, type StandaloneOptions } from './standalone.js';
|
|
5
|
+
export { SDK_VERSION } from './version.js';
|
|
6
|
+
export { connectToEgen, EgenClient } from '@egen-civitas/esm-embed-client';
|
|
7
|
+
export type { CapabilityId, CapabilityDenied, CapabilityGranted } from '@egen-civitas/esm-embed-protocol';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|