@telia-ace/alliance-internal-client-utilities 1.0.6 → 1.1.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/dist/index.d.ts CHANGED
@@ -74,4 +74,4 @@ declare function friendlyUserName(user: {
74
74
  declare function classNames(...classes: string[]): string;
75
75
  declare function props(properties: object): Record<string, string | number | boolean>;
76
76
 
77
- export { AllianceError, FrameworkErrorCodes, Promisable, Serializeable, SerializeableObject, Unpacked, UtilitiesErrorCodes, ValueTypes, VocaButtonVariant, VocaIcon, VocaOption, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
77
+ export { AllianceError, FrameworkErrorCodes, type Promisable, type Serializeable, type SerializeableObject, type Unpacked, UtilitiesErrorCodes, type ValueTypes, VocaButtonVariant, type VocaIcon, type VocaOption, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
package/dist/index.js CHANGED
@@ -1,213 +1,2 @@
1
- // src/exceptions.ts
2
- var FrameworkErrorCodes = /* @__PURE__ */ ((FrameworkErrorCodes2) => {
3
- FrameworkErrorCodes2[FrameworkErrorCodes2["AlreadyInitialized"] = 1e3] = "AlreadyInitialized";
4
- FrameworkErrorCodes2[FrameworkErrorCodes2["NoAppName"] = 1001] = "NoAppName";
5
- FrameworkErrorCodes2[FrameworkErrorCodes2["MissingAppController"] = 1002] = "MissingAppController";
6
- FrameworkErrorCodes2[FrameworkErrorCodes2["MissingCapabilityOnApp"] = 1003] = "MissingCapabilityOnApp";
7
- FrameworkErrorCodes2[FrameworkErrorCodes2["MissingManagedObjectProvider"] = 1004] = "MissingManagedObjectProvider";
8
- FrameworkErrorCodes2[FrameworkErrorCodes2["NoManifest"] = 1005] = "NoManifest";
9
- FrameworkErrorCodes2[FrameworkErrorCodes2["NoRootElement"] = 1006] = "NoRootElement";
10
- FrameworkErrorCodes2[FrameworkErrorCodes2["NoView"] = 1007] = "NoView";
11
- FrameworkErrorCodes2[FrameworkErrorCodes2["CookieKeyNotDefined"] = 1008] = "CookieKeyNotDefined";
12
- FrameworkErrorCodes2[FrameworkErrorCodes2["CookieCategoryNotAllowed"] = 1009] = "CookieCategoryNotAllowed";
13
- FrameworkErrorCodes2[FrameworkErrorCodes2["StorageKeyNotDefined"] = 1010] = "StorageKeyNotDefined";
14
- FrameworkErrorCodes2[FrameworkErrorCodes2["StorageCategoryNotAllowed"] = 1011] = "StorageCategoryNotAllowed";
15
- FrameworkErrorCodes2[FrameworkErrorCodes2["LocalizationTemplateNotDefined"] = 1012] = "LocalizationTemplateNotDefined";
16
- FrameworkErrorCodes2[FrameworkErrorCodes2["NonViewOperation"] = 1013] = "NonViewOperation";
17
- return FrameworkErrorCodes2;
18
- })(FrameworkErrorCodes || {});
19
- var UtilitiesErrorCodes = /* @__PURE__ */ ((UtilitiesErrorCodes2) => {
20
- UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingProvider"] = 2e3] = "CurrentUserMissingProvider";
21
- UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserGatewayNotStarted"] = 2001] = "CurrentUserGatewayNotStarted";
22
- UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingBackend"] = 2002] = "CurrentUserMissingBackend";
23
- UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingInDatabase"] = 2003] = "CurrentUserMissingInDatabase";
24
- return UtilitiesErrorCodes2;
25
- })(UtilitiesErrorCodes || {});
26
- function parseTemplates(message, variables) {
27
- return Object.entries(variables).reduce((acc, [key, value]) => {
28
- return acc.replaceAll(`{{${key}}}`, value);
29
- }, message);
30
- }
31
- var allianceErrors = {
32
- // framework
33
- [1e3 /* AlreadyInitialized */]: "The runtime has already been initialized",
34
- [1001 /* NoAppName */]: "App name is not defined on global scope",
35
- [1002 /* MissingAppController */]: "No app controller registered for app '{{app}}'",
36
- [1003 /* MissingCapabilityOnApp */]: "No capability '{{capability}}' enabled for app '{{app}}'",
37
- [1004 /* MissingManagedObjectProvider */]: "No managed object provider registered for object '{{object}}'",
38
- [1005 /* NoManifest */]: "The current apps manifest is not defined on global scope",
39
- [1006 /* NoRootElement */]: "Could not find the root element in the DOM",
40
- [1007 /* NoView */]: "Could not find view with id '{{id}}' on view controller for app '{{app}}'",
41
- [1008 /* CookieKeyNotDefined */]: "Cookie key '{{key}}' not present in manifest, cookie has not been set",
42
- [1009 /* CookieCategoryNotAllowed */]: "Cookies categorized as '{{category}}' are not allowed by the user, cookie '{{key}}' has not been set",
43
- [1010 /* StorageKeyNotDefined */]: "Storage key '{{key}}' not present in manifest, item has not been stored",
44
- [1011 /* StorageCategoryNotAllowed */]: "Storage categorized as '{{category}}' is not allowed by the user, item '{{key}}' has not been stored",
45
- [1012 /* LocalizationTemplateNotDefined */]: "The translation template, referred by the key '{{key}}' is being used in app, but is not defined in the manifest.",
46
- [1013 /* NonViewOperation */]: "The capability '{{capability}}', requested by an alliance-view element, did not return a View Operation.",
47
- // utilities
48
- [2e3 /* CurrentUserMissingProvider */]: "No managed object provider registered for object 'currentUser'",
49
- [2001 /* CurrentUserGatewayNotStarted */]: "Could not access the gateway when querying 'currentUser'",
50
- [2002 /* CurrentUserMissingBackend */]: "Could not access the required backend when querying 'currentUser'",
51
- [2003 /* CurrentUserMissingInDatabase */]: "Could not locate the authenticated user in the Alliance database"
52
- };
53
- var ALLIANCE_ERROR_NAME = "AllianceError";
54
- var AllianceError = class extends Error {
55
- constructor(code, variables = {}) {
56
- const message = parseTemplates(allianceErrors[code], variables);
57
- const info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
58
- super(message);
59
- this.code = code;
60
- this.name = ALLIANCE_ERROR_NAME;
61
- this.stack = `[${code}] - ${message}
62
- ` + info;
63
- }
64
- };
65
- function isAllianceError(error) {
66
- return !!error.code && error.name === ALLIANCE_ERROR_NAME;
67
- }
68
-
69
- // src/routing.ts
70
- function createQueryString(args) {
71
- const entries = Object.entries(args);
72
- const filteredArgs = entries.reduce((acc, entry) => {
73
- const [key, value] = entry;
74
- if (typeof value === "undefined") {
75
- return acc;
76
- } else if (typeof value === "object" && value !== null) {
77
- acc[key] = JSON.stringify(value);
78
- } else {
79
- acc[key] = value;
80
- }
81
- return acc;
82
- }, {});
83
- if (!Object.keys(filteredArgs).length) {
84
- return "";
85
- }
86
- return `?${new URLSearchParams(filteredArgs)}`;
87
- }
88
- function getCurrentPath() {
89
- const runtimeRootUrl = getRuntimeRootUrl();
90
- const { href, search } = window.location;
91
- return href.replace(runtimeRootUrl, "").replace(search, "");
92
- }
93
- function createCapabilityPath(app = "", capability = "", args = {}) {
94
- const rootPath = getRuntimeRootUrl().replace(location.origin, "");
95
- const queryString = createQueryString(args);
96
- if (!app) {
97
- return `${rootPath}${queryString}`;
98
- }
99
- if (!capability) {
100
- return `${rootPath}/${app}${queryString}`;
101
- }
102
- return `${rootPath}/${app}/${capability}${queryString}`;
103
- }
104
- function getCurrentLocationInfo() {
105
- const currentPath = getCurrentPath();
106
- const [app = "", capability = ""] = currentPath.split("/").filter((part) => !!part);
107
- return {
108
- app,
109
- capability
110
- };
111
- }
112
- function getRuntimeRootUrl() {
113
- if (globalThis.__ALLIANCE_RUNTIME_ROOT_URL) {
114
- return globalThis.__ALLIANCE_RUNTIME_ROOT_URL;
115
- }
116
- return window.origin;
117
- }
118
-
119
- // src/ui.ts
120
- function vocaIconsToOptions(vocaIcons, selected) {
121
- return mapToVocaOptions(Object.values(vocaIcons), ({ name }) => ({
122
- label: name,
123
- value: name,
124
- selected: selected === name
125
- }));
126
- }
127
- var VocaButtonVariant = /* @__PURE__ */ ((VocaButtonVariant2) => {
128
- VocaButtonVariant2["Primary"] = "primary";
129
- VocaButtonVariant2["Secondary"] = "secondary";
130
- VocaButtonVariant2["Expressive"] = "expressive";
131
- VocaButtonVariant2["Destructive"] = "destructive";
132
- VocaButtonVariant2["Text"] = "text";
133
- VocaButtonVariant2["PrimaryWhite"] = "primary-white";
134
- VocaButtonVariant2["SecondaryWhite"] = "secondary-white";
135
- VocaButtonVariant2["ExpressiveWhite"] = "expressive-white";
136
- VocaButtonVariant2["TertiaryPurple"] = "tertiary-purple";
137
- return VocaButtonVariant2;
138
- })(VocaButtonVariant || {});
139
- function getVocaIcon(vocaIcons, name) {
140
- const icon = Object.values(vocaIcons).find((icon2) => icon2.name === name);
141
- return icon;
142
- }
143
- function mapToVocaOptions(items, mapper, placeholder) {
144
- return items.reduce(
145
- (acc, item) => {
146
- acc.push({
147
- disabled: false,
148
- selected: false,
149
- ...mapper(item)
150
- });
151
- return acc;
152
- },
153
- placeholder ? [
154
- {
155
- label: placeholder,
156
- value: "",
157
- disabled: true,
158
- selected: true
159
- }
160
- ] : []
161
- );
162
- }
163
- function onEnter(fn) {
164
- return (e) => {
165
- if (e.key === "Enter") {
166
- fn(e);
167
- }
168
- };
169
- }
170
- function friendlyUserName(user, format = "all") {
171
- const { email, displayName } = user;
172
- const hasDisplayName = displayName && displayName !== "unknown";
173
- const hasEmail = !!email;
174
- switch (format) {
175
- case "all": {
176
- if (hasDisplayName && hasEmail) {
177
- return `${displayName} (${email})`;
178
- } else if (hasDisplayName) {
179
- return displayName;
180
- } else if (hasEmail) {
181
- return email;
182
- }
183
- break;
184
- }
185
- case "single": {
186
- if (hasDisplayName) {
187
- return displayName;
188
- } else if (hasEmail) {
189
- return email;
190
- }
191
- break;
192
- }
193
- }
194
- return "<UNKNOWN USER>";
195
- }
196
- function classNames(...classes) {
197
- return classes.filter((c) => !!c).join(" ");
198
- }
199
- function props(properties) {
200
- return Object.entries(properties).reduce(
201
- (acc, [key, value]) => {
202
- if (typeof value !== "object" && typeof value !== "function") {
203
- acc[key] = value;
204
- }
205
- return acc;
206
- },
207
- {}
208
- );
209
- }
210
-
211
- export { AllianceError, FrameworkErrorCodes, UtilitiesErrorCodes, VocaButtonVariant, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
212
- //# sourceMappingURL=out.js.map
213
- //# sourceMappingURL=index.js.map
1
+ var p=(r=>(r[r.AlreadyInitialized=1e3]="AlreadyInitialized",r[r.NoAppName=1001]="NoAppName",r[r.MissingAppController=1002]="MissingAppController",r[r.MissingCapabilityOnApp=1003]="MissingCapabilityOnApp",r[r.MissingManagedObjectProvider=1004]="MissingManagedObjectProvider",r[r.NoManifest=1005]="NoManifest",r[r.NoRootElement=1006]="NoRootElement",r[r.NoView=1007]="NoView",r[r.CookieKeyNotDefined=1008]="CookieKeyNotDefined",r[r.CookieCategoryNotAllowed=1009]="CookieCategoryNotAllowed",r[r.StorageKeyNotDefined=1010]="StorageKeyNotDefined",r[r.StorageCategoryNotAllowed=1011]="StorageCategoryNotAllowed",r[r.LocalizationTemplateNotDefined=1012]="LocalizationTemplateNotDefined",r[r.NonViewOperation=1013]="NonViewOperation",r))(p||{}),u=(o=>(o[o.CurrentUserMissingProvider=2e3]="CurrentUserMissingProvider",o[o.CurrentUserGatewayNotStarted=2001]="CurrentUserGatewayNotStarted",o[o.CurrentUserMissingBackend=2002]="CurrentUserMissingBackend",o[o.CurrentUserMissingInDatabase=2003]="CurrentUserMissingInDatabase",o))(u||{});function y(e,i){return Object.entries(i).reduce((t,[n,o])=>t.replaceAll(`{{${n}}}`,o),e)}var f={1e3:"The runtime has already been initialized",1001:"App name is not defined on global scope",1002:"No app controller registered for app '{{app}}'",1003:"No capability '{{capability}}' enabled for app '{{app}}'",1004:"No managed object provider registered for object '{{object}}'",1005:"The current apps manifest is not defined on global scope",1006:"Could not find the root element in the DOM",1007:"Could not find view with id '{{id}}' on view controller for app '{{app}}'",1008:"Cookie key '{{key}}' not present in manifest, cookie has not been set",1009:"Cookies categorized as '{{category}}' are not allowed by the user, cookie '{{key}}' has not been set",1010:"Storage key '{{key}}' not present in manifest, item has not been stored",1011:"Storage categorized as '{{category}}' is not allowed by the user, item '{{key}}' has not been stored",1012:"The translation template, referred by the key '{{key}}' is being used in app, but is not defined in the manifest.",1013:"The capability '{{capability}}', requested by an alliance-view element, did not return a View Operation.",2e3:"No managed object provider registered for object 'currentUser'",2001:"Could not access the gateway when querying 'currentUser'",2002:"Could not access the required backend when querying 'currentUser'",2003:"Could not locate the authenticated user in the Alliance database"},d="AllianceError",c=class extends Error{constructor(t,n={}){let o=y(f[t],n),a=`https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${t}`;super(o);this.code=t;this.name=d,this.stack=`[${t}] - ${o}
2
+ `+a}};function b(e){return!!e.code&&e.name===d}function h(e){let t=Object.entries(e).reduce((n,o)=>{let[a,l]=o;return typeof l>"u"||(typeof l=="object"&&l!==null?n[a]=JSON.stringify(l):n[a]=l),n},{});return Object.keys(t).length?`?${new URLSearchParams(t)}`:""}function N(){let e=g(),{href:i,search:t}=window.location;return i.replace(e,"").replace(t,"")}function A(e="",i="",t={}){let n=g().replace(location.origin,""),o=h(t);return e?i?`${n}/${e}/${i}${o}`:`${n}/${e}${o}`:`${n}${o}`}function v(){let e=N(),[i="",t=""]=e.split("/").filter(n=>!!n);return{app:i,capability:t}}function g(){return globalThis.__ALLIANCE_RUNTIME_ROOT_URL?globalThis.__ALLIANCE_RUNTIME_ROOT_URL:window.origin}function U(e,i){return O(Object.values(e),({name:t})=>({label:t,value:t,selected:i===t}))}var m=(s=>(s.Primary="primary",s.Secondary="secondary",s.Expressive="expressive",s.Destructive="destructive",s.Text="text",s.PrimaryWhite="primary-white",s.SecondaryWhite="secondary-white",s.ExpressiveWhite="expressive-white",s.TertiaryPurple="tertiary-purple",s))(m||{});function C(e,i){return Object.values(e).find(n=>n.name===i)}function O(e,i,t){return e.reduce((n,o)=>(n.push({disabled:!1,selected:!1,...i(o)}),n),t?[{label:t,value:"",disabled:!0,selected:!0}]:[])}function j(e){return i=>{i.key==="Enter"&&e(i)}}function R(e,i="all"){let{email:t,displayName:n}=e,o=n&&n!=="unknown",a=!!t;switch(i){case"all":{if(o&&a)return`${n} (${t})`;if(o)return n;if(a)return t;break}case"single":{if(o)return n;if(a)return t;break}}return"<UNKNOWN USER>"}function M(...e){return e.filter(i=>!!i).join(" ")}function w(e){return Object.entries(e).reduce((i,[t,n])=>(typeof n!="object"&&typeof n!="function"&&(i[t]=n),i),{})}export{c as AllianceError,p as FrameworkErrorCodes,u as UtilitiesErrorCodes,m as VocaButtonVariant,M as classNames,A as createCapabilityPath,R as friendlyUserName,v as getCurrentLocationInfo,g as getRuntimeRootUrl,C as getVocaIcon,b as isAllianceError,O as mapToVocaOptions,j as onEnter,w as props,U as vocaIconsToOptions};
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@telia-ace/alliance-internal-client-utilities",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "Utilities used internally by packages developed by team Alliance.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
7
+ "type": "module",
8
+ "exports": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
7
12
  "main": "./dist/index.js",
8
13
  "types": "./dist/index.d.ts",
9
- "type": "module",
10
14
  "files": [
11
15
  "LICENSE.txt",
12
16
  "README.md",
13
- "CHANGELOG.md",
14
17
  "dist"
15
18
  ],
16
- "devDependencies": {
17
- "@telia-ace/alliance-internal-node-utilities": "^1.0.6"
18
- },
19
19
  "publishConfig": {
20
20
  "access": "public"
21
21
  },
22
22
  "scripts": {
23
- "build:dev": "tsup",
24
- "build:prod": "tsup",
23
+ "build:dev": "tsup --minify",
24
+ "build:prod": "tsup --minify",
25
25
  "dev": "tsup --watch"
26
26
  }
27
27
  }
package/CHANGELOG.md DELETED
@@ -1,73 +0,0 @@
1
- # @telia-ace/alliance-internal-client-utilities
2
-
3
- ## 1.0.6
4
-
5
- ### Patch Changes
6
-
7
- - Move CLI translation utilities from internal client utilities. ([#440](https://github.com/telia-company/ace-alliance-sdk/pull/440))
8
-
9
- ## 1.0.6-next.0
10
-
11
- ### Patch Changes
12
-
13
- - Move CLI translation utilities from internal client utilities. ([#437](https://github.com/telia-company/ace-alliance-sdk/pull/437))
14
-
15
- ## 1.0.5
16
-
17
- ### Patch Changes
18
-
19
- - 1b9c7a9: Fix select field placeholders not using localized texts.
20
-
21
- ## 1.0.5-next.0
22
-
23
- ### Patch Changes
24
-
25
- - 1b9c7a9: Fix select field placeholders not using localized texts.
26
-
27
- ## 1.0.4
28
-
29
- ### Patch Changes
30
-
31
- - c2335bc: Replace Vite with Tsup when building packages.
32
-
33
- ## 1.0.4-next.0
34
-
35
- ### Patch Changes
36
-
37
- - cd44395: Replace Vite with Tsup when building packages.
38
-
39
- ## 1.0.3
40
-
41
- ### Patch Changes
42
-
43
- - 3489aea: Introduced GraphQL error exception.
44
-
45
- ## 1.0.3-next.0
46
-
47
- ### Patch Changes
48
-
49
- - 3489aea: Introduced GraphQL error exception.
50
-
51
- ## 1.0.2
52
-
53
- ### Patch Changes
54
-
55
- - 59f0d3f: Remove unnecessary scripts.
56
-
57
- ## 1.0.2-next.0
58
-
59
- ### Patch Changes
60
-
61
- - 59f0d3f: Remove unnecessary scripts.
62
-
63
- ## 1.0.1
64
-
65
- ### Patch Changes
66
-
67
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
68
-
69
- ## 1.0.1-next.0
70
-
71
- ### Patch Changes
72
-
73
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/exceptions.ts","../src/routing.ts","../src/ui.ts"],"names":["FrameworkErrorCodes","UtilitiesErrorCodes","VocaButtonVariant","icon"],"mappings":";AAAO,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AAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG;AAC9C;AAEO,SAAS,MAAM,YAAoB;AACtC,SAAO,OAAO,QAAQ,UAAU,EAAE;AAAA,IAC9B,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACnB,UAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YAAY;AAC1D,YAAI,GAAG,IAAI;AAAA,MACf;AAEA,aAAO;AAAA,IACX;AAAA,IACA,CAAC;AAAA,EACL;AACJ","sourcesContent":["export enum FrameworkErrorCodes {\n AlreadyInitialized = 1000,\n NoAppName = 1001,\n MissingAppController = 1002,\n MissingCapabilityOnApp = 1003,\n MissingManagedObjectProvider = 1004,\n NoManifest = 1005,\n NoRootElement = 1006,\n NoView = 1007,\n CookieKeyNotDefined = 1008,\n CookieCategoryNotAllowed = 1009,\n StorageKeyNotDefined = 1010,\n StorageCategoryNotAllowed = 1011,\n LocalizationTemplateNotDefined = 1012,\n NonViewOperation = 1013,\n}\n\nexport enum UtilitiesErrorCodes {\n CurrentUserMissingProvider = 2000,\n CurrentUserGatewayNotStarted = 2001,\n CurrentUserMissingBackend = 2002,\n CurrentUserMissingInDatabase = 2003,\n}\n\ntype ErrorCodes = UtilitiesErrorCodes | FrameworkErrorCodes;\n\nfunction parseTemplates(message: string, variables: Record<string, string>) {\n return Object.entries(variables).reduce((acc, [key, value]) => {\n return acc.replaceAll(`{{${key}}}`, value);\n }, message);\n}\n\nconst allianceErrors: Record<ErrorCodes, string> = {\n // framework\n [FrameworkErrorCodes.AlreadyInitialized]: 'The runtime has already been initialized',\n [FrameworkErrorCodes.NoAppName]: 'App name is not defined on global scope',\n [FrameworkErrorCodes.MissingAppController]: \"No app controller registered for app '{{app}}'\",\n [FrameworkErrorCodes.MissingCapabilityOnApp]:\n \"No capability '{{capability}}' enabled for app '{{app}}'\",\n [FrameworkErrorCodes.MissingManagedObjectProvider]:\n \"No managed object provider registered for object '{{object}}'\",\n [FrameworkErrorCodes.NoManifest]: 'The current apps manifest is not defined on global scope',\n [FrameworkErrorCodes.NoRootElement]: 'Could not find the root element in the DOM',\n [FrameworkErrorCodes.NoView]:\n \"Could not find view with id '{{id}}' on view controller for app '{{app}}'\",\n [FrameworkErrorCodes.CookieKeyNotDefined]:\n \"Cookie key '{{key}}' not present in manifest, cookie has not been set\",\n [FrameworkErrorCodes.CookieCategoryNotAllowed]:\n \"Cookies categorized as '{{category}}' are not allowed by the user, cookie '{{key}}' has not been set\",\n [FrameworkErrorCodes.StorageKeyNotDefined]:\n \"Storage key '{{key}}' not present in manifest, item has not been stored\",\n [FrameworkErrorCodes.StorageCategoryNotAllowed]:\n \"Storage categorized as '{{category}}' is not allowed by the user, item '{{key}}' has not been stored\",\n [FrameworkErrorCodes.LocalizationTemplateNotDefined]:\n \"The translation template, referred by the key '{{key}}' is being used in app, but is not defined in the manifest.\",\n [FrameworkErrorCodes.NonViewOperation]:\n \"The capability '{{capability}}', requested by an alliance-view element, did not return a View Operation.\",\n // utilities\n [UtilitiesErrorCodes.CurrentUserMissingProvider]:\n \"No managed object provider registered for object 'currentUser'\",\n [UtilitiesErrorCodes.CurrentUserGatewayNotStarted]:\n \"Could not access the gateway when querying 'currentUser'\",\n [UtilitiesErrorCodes.CurrentUserMissingBackend]:\n \"Could not access the required backend when querying 'currentUser'\",\n [UtilitiesErrorCodes.CurrentUserMissingInDatabase]:\n 'Could not locate the authenticated user in the Alliance database',\n};\n\nconst ALLIANCE_ERROR_NAME = 'AllianceError';\n\nexport class AllianceError extends Error {\n constructor(\n public code: ErrorCodes,\n variables: Record<string, string> = {},\n ) {\n const message = parseTemplates(allianceErrors[code], variables);\n const info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;\n super(message);\n\n this.name = ALLIANCE_ERROR_NAME;\n this.stack = `[${code}] - ${message}` + '\\n' + info;\n }\n}\n\nexport function isAllianceError(error: any): error is AllianceError {\n return !!error.code && error.name === ALLIANCE_ERROR_NAME;\n}\n","import type { SerializeableObject } from './types';\n\nfunction createQueryString(args: SerializeableObject) {\n const entries = Object.entries(args);\n\n const filteredArgs = entries.reduce<SerializeableObject>((acc, entry) => {\n const [key, value] = entry;\n\n if (typeof value === 'undefined') {\n return acc;\n } else if (typeof value === 'object' && value !== null) {\n acc[key] = JSON.stringify(value);\n } else {\n acc[key] = value;\n }\n\n return acc;\n }, {});\n\n if (!Object.keys(filteredArgs).length) {\n return '';\n }\n\n return `?${new URLSearchParams(filteredArgs as Record<string, any>)}`;\n}\n\nfunction getCurrentPath() {\n const runtimeRootUrl = getRuntimeRootUrl();\n const { href, search } = window.location;\n\n return href.replace(runtimeRootUrl, '').replace(search, '');\n}\n\nexport function createCapabilityPath(\n app: string = '',\n capability: string = '',\n args: SerializeableObject = {},\n) {\n const rootPath = getRuntimeRootUrl().replace(location.origin, '');\n const queryString = createQueryString(args);\n\n if (!app) {\n return `${rootPath}${queryString}`;\n }\n\n if (!capability) {\n return `${rootPath}/${app}${queryString}`;\n }\n\n return `${rootPath}/${app}/${capability}${queryString}`;\n}\n\nexport function getCurrentLocationInfo() {\n const currentPath = getCurrentPath();\n const [app = '', capability = ''] = currentPath.split('/').filter((part) => !!part);\n\n return {\n app,\n capability,\n };\n}\n\nexport function getRuntimeRootUrl(): string {\n // @ts-ignore\n if (globalThis.__ALLIANCE_RUNTIME_ROOT_URL) {\n // @ts-ignore\n return globalThis.__ALLIANCE_RUNTIME_ROOT_URL;\n }\n return window.origin;\n}\n","export function vocaIconsToOptions(vocaIcons: any, selected: string) {\n return mapToVocaOptions(Object.values(vocaIcons), ({ name }: any) => ({\n label: name,\n value: name,\n selected: selected === name,\n }));\n}\n\nexport type VocaIcon = { name: string; svg: string };\n\nexport enum VocaButtonVariant {\n Primary = 'primary',\n Secondary = 'secondary',\n Expressive = 'expressive',\n Destructive = 'destructive',\n Text = 'text',\n PrimaryWhite = 'primary-white',\n SecondaryWhite = 'secondary-white',\n ExpressiveWhite = 'expressive-white',\n TertiaryPurple = 'tertiary-purple',\n}\n\nexport type VocaOption = { label: string; value: string; disabled?: boolean; selected?: boolean };\n\nexport function getVocaIcon(vocaIcons: any, name: string) {\n const icon = Object.values(vocaIcons).find((icon: any) => icon.name === name);\n return icon as VocaIcon;\n}\n\nexport type Unpacked<T> = T extends (infer U)[] ? U : T;\n\nexport function mapToVocaOptions<T>(\n items: T,\n mapper: (item: Unpacked<T>) => VocaOption,\n placeholder?: string,\n): VocaOption[] {\n return (items as []).reduce<VocaOption[]>(\n (acc, item) => {\n acc.push({\n disabled: false,\n selected: false,\n ...mapper(item),\n });\n\n return acc;\n },\n placeholder\n ? [\n {\n label: placeholder,\n value: '',\n disabled: true,\n selected: true,\n },\n ]\n : [],\n );\n}\n\nexport function onEnter(fn: (e: KeyboardEvent) => void) {\n return (e: KeyboardEvent) => {\n if (e.key === 'Enter') {\n fn(e);\n }\n };\n}\n\nexport function friendlyUserName(\n user: { email: string; displayName: string },\n format: 'single' | 'all' = 'all',\n) {\n const { email, displayName } = user;\n\n const hasDisplayName = displayName && displayName !== 'unknown';\n const hasEmail = !!email;\n\n switch (format) {\n case 'all': {\n if (hasDisplayName && hasEmail) {\n return `${displayName} (${email})`;\n } else if (hasDisplayName) {\n return displayName;\n } else if (hasEmail) {\n return email;\n }\n break;\n }\n case 'single': {\n if (hasDisplayName) {\n return displayName;\n } else if (hasEmail) {\n return email;\n }\n break;\n }\n }\n\n return '<UNKNOWN USER>';\n}\n\nexport function classNames(...classes: string[]) {\n return classes.filter((c) => !!c).join(' ');\n}\n\nexport function props(properties: object) {\n return Object.entries(properties).reduce<Record<string, string | boolean | number>>(\n (acc, [key, value]) => {\n if (typeof value !== 'object' && typeof value !== 'function') {\n acc[key] = value;\n }\n\n return acc;\n },\n {},\n );\n}\n"]}