@telia-ace/alliance-internal-client-utilities 1.0.5-next.0 → 1.0.6-next.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,17 @@
1
1
  # @telia-ace/alliance-internal-client-utilities
2
2
 
3
+ ## 1.0.6-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Move CLI translation utilities from internal client utilities. ([#437](https://github.com/telia-company/ace-alliance-sdk/pull/437))
8
+
9
+ ## 1.0.5
10
+
11
+ ### Patch Changes
12
+
13
+ - 1b9c7a9: Fix select field placeholders not using localized texts.
14
+
3
15
  ## 1.0.5-next.0
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -41,55 +41,6 @@ declare function getCurrentLocationInfo(): {
41
41
  };
42
42
  declare function getRuntimeRootUrl(): string;
43
43
 
44
- type Translations = {
45
- [key in TranslationsKey]: string;
46
- };
47
- declare enum TranslationsKey {
48
- AlreadyExists = 0,
49
- ApiGatewayPortDescription = 1,
50
- ApiServerModeDescription = 2,
51
- AppConfigurationPath = 3,
52
- AppCreated = 4,
53
- AppEntryBuildOptionDescription = 5,
54
- AppNameInquiry = 6,
55
- BuildDescription = 7,
56
- BuildModeOptionDescription = 8,
57
- BuildWatchDescription = 9,
58
- CreateAppDescription = 10,
59
- CreateWorkspaceDescription = 11,
60
- DevServerOpenDescription = 12,
61
- DevServerPortDescription = 13,
62
- DevServerLoggingDescription = 14,
63
- Done = 15,
64
- FetchPackageVersionError = 16,
65
- ManifestEntryBuildOptionDescription = 17,
66
- MissingTranslationKey = 18,
67
- NoAppName = 19,
68
- NoAppNameFound = 20,
69
- NoAppOrWorkspaceInCurrentDirectory = 21,
70
- NoWorkspaceName = 22,
71
- OperationCancelled = 23,
72
- ServeDescription = 24,
73
- ServedStopped = 25,
74
- ServerGatewayMode = 26,
75
- ServerMode = 27,
76
- ServerModeInquiry = 28,
77
- ServerProxyMode = 29,
78
- StopServerInstructions = 30,
79
- TemplateFrameworkInquiry = 31,
80
- TemplateLanguageInquiry = 32,
81
- UnrecognizedCommand = 33,
82
- WorkspaceCreated = 34,
83
- WorkspaceNameInquiry = 35
84
- }
85
-
86
- type TextArgs = (string | number)[];
87
- declare class Texts {
88
- protected static getTranslations: () => Translations;
89
- protected static getTranslation: (key: TranslationsKey, ...args: TextArgs) => string;
90
- static get: (key?: TranslationsKey, ...args: TextArgs) => string;
91
- }
92
-
93
44
  declare function vocaIconsToOptions(vocaIcons: any, selected: string): VocaOption[];
94
45
  type VocaIcon = {
95
46
  name: string;
@@ -123,4 +74,4 @@ declare function friendlyUserName(user: {
123
74
  declare function classNames(...classes: string[]): string;
124
75
  declare function props(properties: object): Record<string, string | number | boolean>;
125
76
 
126
- export { AllianceError, FrameworkErrorCodes, Promisable, Serializeable, SerializeableObject, TextArgs, Texts, TranslationsKey, Unpacked, UtilitiesErrorCodes, ValueTypes, VocaButtonVariant, VocaIcon, VocaOption, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
77
+ export { AllianceError, FrameworkErrorCodes, Promisable, Serializeable, SerializeableObject, Unpacked, UtilitiesErrorCodes, ValueTypes, VocaButtonVariant, VocaIcon, VocaOption, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
package/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // src/exceptions.ts
5
- var FrameworkErrorCodes;
6
- (function(FrameworkErrorCodes2) {
2
+ var FrameworkErrorCodes = /* @__PURE__ */ ((FrameworkErrorCodes2) => {
7
3
  FrameworkErrorCodes2[FrameworkErrorCodes2["AlreadyInitialized"] = 1e3] = "AlreadyInitialized";
8
4
  FrameworkErrorCodes2[FrameworkErrorCodes2["NoAppName"] = 1001] = "NoAppName";
9
5
  FrameworkErrorCodes2[FrameworkErrorCodes2["MissingAppController"] = 1002] = "MissingAppController";
@@ -18,48 +14,44 @@ var FrameworkErrorCodes;
18
14
  FrameworkErrorCodes2[FrameworkErrorCodes2["StorageCategoryNotAllowed"] = 1011] = "StorageCategoryNotAllowed";
19
15
  FrameworkErrorCodes2[FrameworkErrorCodes2["LocalizationTemplateNotDefined"] = 1012] = "LocalizationTemplateNotDefined";
20
16
  FrameworkErrorCodes2[FrameworkErrorCodes2["NonViewOperation"] = 1013] = "NonViewOperation";
21
- })(FrameworkErrorCodes || (FrameworkErrorCodes = {}));
22
- var UtilitiesErrorCodes;
23
- (function(UtilitiesErrorCodes2) {
17
+ return FrameworkErrorCodes2;
18
+ })(FrameworkErrorCodes || {});
19
+ var UtilitiesErrorCodes = /* @__PURE__ */ ((UtilitiesErrorCodes2) => {
24
20
  UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingProvider"] = 2e3] = "CurrentUserMissingProvider";
25
21
  UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserGatewayNotStarted"] = 2001] = "CurrentUserGatewayNotStarted";
26
22
  UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingBackend"] = 2002] = "CurrentUserMissingBackend";
27
23
  UtilitiesErrorCodes2[UtilitiesErrorCodes2["CurrentUserMissingInDatabase"] = 2003] = "CurrentUserMissingInDatabase";
28
- })(UtilitiesErrorCodes || (UtilitiesErrorCodes = {}));
24
+ return UtilitiesErrorCodes2;
25
+ })(UtilitiesErrorCodes || {});
29
26
  function parseTemplates(message, variables) {
30
27
  return Object.entries(variables).reduce((acc, [key, value]) => {
31
28
  return acc.replaceAll(`{{${key}}}`, value);
32
29
  }, message);
33
30
  }
34
- __name(parseTemplates, "parseTemplates");
35
31
  var allianceErrors = {
36
32
  // framework
37
- [1e3]: "The runtime has already been initialized",
38
- [1001]: "App name is not defined on global scope",
39
- [1002]: "No app controller registered for app '{{app}}'",
40
- [1003]: "No capability '{{capability}}' enabled for app '{{app}}'",
41
- [1004]: "No managed object provider registered for object '{{object}}'",
42
- [1005]: "The current apps manifest is not defined on global scope",
43
- [1006]: "Could not find the root element in the DOM",
44
- [1007]: "Could not find view with id '{{id}}' on view controller for app '{{app}}'",
45
- [1008]: "Cookie key '{{key}}' not present in manifest, cookie has not been set",
46
- [1009]: "Cookies categorized as '{{category}}' are not allowed by the user, cookie '{{key}}' has not been set",
47
- [1010]: "Storage key '{{key}}' not present in manifest, item has not been stored",
48
- [1011]: "Storage categorized as '{{category}}' is not allowed by the user, item '{{key}}' has not been stored",
49
- [1012]: "The translation template, referred by the key '{{key}}' is being used in app, but is not defined in the manifest.",
50
- [1013]: "The capability '{{capability}}', requested by an alliance-view element, did not return a View Operation.",
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.",
51
47
  // utilities
52
- [2e3]: "No managed object provider registered for object 'currentUser'",
53
- [2001]: "Could not access the gateway when querying 'currentUser'",
54
- [2002]: "Could not access the required backend when querying 'currentUser'",
55
- [2003]: "Could not locate the authenticated user in the Alliance database"
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"
56
52
  };
57
53
  var ALLIANCE_ERROR_NAME = "AllianceError";
58
54
  var AllianceError = class extends Error {
59
- static {
60
- __name(this, "AllianceError");
61
- }
62
- code;
63
55
  constructor(code, variables = {}) {
64
56
  const message = parseTemplates(allianceErrors[code], variables);
65
57
  const info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
@@ -73,7 +65,6 @@ var AllianceError = class extends Error {
73
65
  function isAllianceError(error) {
74
66
  return !!error.code && error.name === ALLIANCE_ERROR_NAME;
75
67
  }
76
- __name(isAllianceError, "isAllianceError");
77
68
 
78
69
  // src/routing.ts
79
70
  function createQueryString(args) {
@@ -94,13 +85,11 @@ function createQueryString(args) {
94
85
  }
95
86
  return `?${new URLSearchParams(filteredArgs)}`;
96
87
  }
97
- __name(createQueryString, "createQueryString");
98
88
  function getCurrentPath() {
99
89
  const runtimeRootUrl = getRuntimeRootUrl();
100
90
  const { href, search } = window.location;
101
91
  return href.replace(runtimeRootUrl, "").replace(search, "");
102
92
  }
103
- __name(getCurrentPath, "getCurrentPath");
104
93
  function createCapabilityPath(app = "", capability = "", args = {}) {
105
94
  const rootPath = getRuntimeRootUrl().replace(location.origin, "");
106
95
  const queryString = createQueryString(args);
@@ -112,7 +101,6 @@ function createCapabilityPath(app = "", capability = "", args = {}) {
112
101
  }
113
102
  return `${rootPath}/${app}/${capability}${queryString}`;
114
103
  }
115
- __name(createCapabilityPath, "createCapabilityPath");
116
104
  function getCurrentLocationInfo() {
117
105
  const currentPath = getCurrentPath();
118
106
  const [app = "", capability = ""] = currentPath.split("/").filter((part) => !!part);
@@ -121,113 +109,12 @@ function getCurrentLocationInfo() {
121
109
  capability
122
110
  };
123
111
  }
124
- __name(getCurrentLocationInfo, "getCurrentLocationInfo");
125
112
  function getRuntimeRootUrl() {
126
113
  if (globalThis.__ALLIANCE_RUNTIME_ROOT_URL) {
127
114
  return globalThis.__ALLIANCE_RUNTIME_ROOT_URL;
128
115
  }
129
116
  return window.origin;
130
117
  }
131
- __name(getRuntimeRootUrl, "getRuntimeRootUrl");
132
-
133
- // src/translations.ts
134
- var TranslationsKey;
135
- (function(TranslationsKey2) {
136
- TranslationsKey2[TranslationsKey2["AlreadyExists"] = 0] = "AlreadyExists";
137
- TranslationsKey2[TranslationsKey2["ApiGatewayPortDescription"] = 1] = "ApiGatewayPortDescription";
138
- TranslationsKey2[TranslationsKey2["ApiServerModeDescription"] = 2] = "ApiServerModeDescription";
139
- TranslationsKey2[TranslationsKey2["AppConfigurationPath"] = 3] = "AppConfigurationPath";
140
- TranslationsKey2[TranslationsKey2["AppCreated"] = 4] = "AppCreated";
141
- TranslationsKey2[TranslationsKey2["AppEntryBuildOptionDescription"] = 5] = "AppEntryBuildOptionDescription";
142
- TranslationsKey2[TranslationsKey2["AppNameInquiry"] = 6] = "AppNameInquiry";
143
- TranslationsKey2[TranslationsKey2["BuildDescription"] = 7] = "BuildDescription";
144
- TranslationsKey2[TranslationsKey2["BuildModeOptionDescription"] = 8] = "BuildModeOptionDescription";
145
- TranslationsKey2[TranslationsKey2["BuildWatchDescription"] = 9] = "BuildWatchDescription";
146
- TranslationsKey2[TranslationsKey2["CreateAppDescription"] = 10] = "CreateAppDescription";
147
- TranslationsKey2[TranslationsKey2["CreateWorkspaceDescription"] = 11] = "CreateWorkspaceDescription";
148
- TranslationsKey2[TranslationsKey2["DevServerOpenDescription"] = 12] = "DevServerOpenDescription";
149
- TranslationsKey2[TranslationsKey2["DevServerPortDescription"] = 13] = "DevServerPortDescription";
150
- TranslationsKey2[TranslationsKey2["DevServerLoggingDescription"] = 14] = "DevServerLoggingDescription";
151
- TranslationsKey2[TranslationsKey2["Done"] = 15] = "Done";
152
- TranslationsKey2[TranslationsKey2["FetchPackageVersionError"] = 16] = "FetchPackageVersionError";
153
- TranslationsKey2[TranslationsKey2["ManifestEntryBuildOptionDescription"] = 17] = "ManifestEntryBuildOptionDescription";
154
- TranslationsKey2[TranslationsKey2["MissingTranslationKey"] = 18] = "MissingTranslationKey";
155
- TranslationsKey2[TranslationsKey2["NoAppName"] = 19] = "NoAppName";
156
- TranslationsKey2[TranslationsKey2["NoAppNameFound"] = 20] = "NoAppNameFound";
157
- TranslationsKey2[TranslationsKey2["NoAppOrWorkspaceInCurrentDirectory"] = 21] = "NoAppOrWorkspaceInCurrentDirectory";
158
- TranslationsKey2[TranslationsKey2["NoWorkspaceName"] = 22] = "NoWorkspaceName";
159
- TranslationsKey2[TranslationsKey2["OperationCancelled"] = 23] = "OperationCancelled";
160
- TranslationsKey2[TranslationsKey2["ServeDescription"] = 24] = "ServeDescription";
161
- TranslationsKey2[TranslationsKey2["ServedStopped"] = 25] = "ServedStopped";
162
- TranslationsKey2[TranslationsKey2["ServerGatewayMode"] = 26] = "ServerGatewayMode";
163
- TranslationsKey2[TranslationsKey2["ServerMode"] = 27] = "ServerMode";
164
- TranslationsKey2[TranslationsKey2["ServerModeInquiry"] = 28] = "ServerModeInquiry";
165
- TranslationsKey2[TranslationsKey2["ServerProxyMode"] = 29] = "ServerProxyMode";
166
- TranslationsKey2[TranslationsKey2["StopServerInstructions"] = 30] = "StopServerInstructions";
167
- TranslationsKey2[TranslationsKey2["TemplateFrameworkInquiry"] = 31] = "TemplateFrameworkInquiry";
168
- TranslationsKey2[TranslationsKey2["TemplateLanguageInquiry"] = 32] = "TemplateLanguageInquiry";
169
- TranslationsKey2[TranslationsKey2["UnrecognizedCommand"] = 33] = "UnrecognizedCommand";
170
- TranslationsKey2[TranslationsKey2["WorkspaceCreated"] = 34] = "WorkspaceCreated";
171
- TranslationsKey2[TranslationsKey2["WorkspaceNameInquiry"] = 35] = "WorkspaceNameInquiry";
172
- })(TranslationsKey || (TranslationsKey = {}));
173
- var en = {
174
- [15]: "Done",
175
- [22]: "No workspace name provided!",
176
- [19]: "No app name provided!",
177
- [0]: "File or directory '{0}' already exists!",
178
- [21]: "Could not find any app entry file at '{0}'!",
179
- [33]: "Unrecognized command(s) {0}!",
180
- [34]: "Workspace was created at path '{0}'!",
181
- [4]: "App was created at path '{0}'!",
182
- [25]: "Server stopped.",
183
- [11]: "Creates an Alliance Workspace in the current directory.",
184
- [10]: "Creates an Alliance Application in the current directory or Alliance Workspace.",
185
- [24]: "Starts a Alliance development server using the current directory package.json.",
186
- [7]: "Builds an Alliance Application using Vite.",
187
- [35]: "Enter the name of your workspace",
188
- [28]: "Which server mode do you want to use?",
189
- [6]: "Enter the name of your app",
190
- [18]: "No translation key provided!",
191
- [23]: "Operation cancelled.",
192
- [30]: "Press CTRL + C to stop the server.\n",
193
- [32]: "Select preferred language",
194
- [31]: "Select preferred framework template",
195
- [13]: "The port that the dev server should use.",
196
- [14]: "Whether the dev server and browser console should output more log information or not (false).",
197
- [1]: "The port that the api gateway should use.",
198
- [2]: "Which components to start. [server|server-proxy|server-gateway].",
199
- [12]: "Whether the dev server should automatically open in your browser or not.",
200
- [9]: "Whether the build should start watching and rebuild when files change or not.",
201
- [5]: "The entry file for the app (./src/app).",
202
- [17]: "The entry file for the app manifest (./src/manifest).",
203
- [8]: "Which mode to use when building the app.",
204
- [16]: "Failed to fetch package info from the NPM registry for package '${0}'!",
205
- [20]: "Could not find app name in manifest.",
206
- [3]: "The path to the app configuration file.",
207
- [27]: "Server",
208
- [29]: "Server with proxy",
209
- [26]: "Server with gateway"
210
- };
211
-
212
- // src/texts.ts
213
- var Texts = class _Texts {
214
- static {
215
- __name(this, "Texts");
216
- }
217
- static getTranslations = () => {
218
- return en;
219
- };
220
- static getTranslation = (key, ...args) => {
221
- const translations = _Texts.getTranslations();
222
- const translation = translations[key];
223
- if (!translation)
224
- throw new Error(`Could not find text with given key '${key}'.`);
225
- const formattedTranslation = args.reduce((acc, curr, index) => acc.toString().replace(`{${index}}`, curr.toString()), translation);
226
- return formattedTranslation.toString();
227
- };
228
- static get = (key = TranslationsKey.MissingTranslationKey, ...args) => this.getTranslation(key, ...args);
229
- };
230
- var texts_default = Texts;
231
118
 
232
119
  // src/ui.ts
233
120
  function vocaIconsToOptions(vocaIcons, selected) {
@@ -237,9 +124,7 @@ function vocaIconsToOptions(vocaIcons, selected) {
237
124
  selected: selected === name
238
125
  }));
239
126
  }
240
- __name(vocaIconsToOptions, "vocaIconsToOptions");
241
- var VocaButtonVariant;
242
- (function(VocaButtonVariant2) {
127
+ var VocaButtonVariant = /* @__PURE__ */ ((VocaButtonVariant2) => {
243
128
  VocaButtonVariant2["Primary"] = "primary";
244
129
  VocaButtonVariant2["Secondary"] = "secondary";
245
130
  VocaButtonVariant2["Expressive"] = "expressive";
@@ -249,30 +134,32 @@ var VocaButtonVariant;
249
134
  VocaButtonVariant2["SecondaryWhite"] = "secondary-white";
250
135
  VocaButtonVariant2["ExpressiveWhite"] = "expressive-white";
251
136
  VocaButtonVariant2["TertiaryPurple"] = "tertiary-purple";
252
- })(VocaButtonVariant || (VocaButtonVariant = {}));
137
+ return VocaButtonVariant2;
138
+ })(VocaButtonVariant || {});
253
139
  function getVocaIcon(vocaIcons, name) {
254
140
  const icon = Object.values(vocaIcons).find((icon2) => icon2.name === name);
255
141
  return icon;
256
142
  }
257
- __name(getVocaIcon, "getVocaIcon");
258
143
  function mapToVocaOptions(items, mapper, placeholder) {
259
- return items.reduce((acc, item) => {
260
- acc.push({
261
- disabled: false,
262
- selected: false,
263
- ...mapper(item)
264
- });
265
- return acc;
266
- }, placeholder ? [
267
- {
268
- label: placeholder,
269
- value: "",
270
- disabled: true,
271
- selected: true
272
- }
273
- ] : []);
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
+ );
274
162
  }
275
- __name(mapToVocaOptions, "mapToVocaOptions");
276
163
  function onEnter(fn) {
277
164
  return (e) => {
278
165
  if (e.key === "Enter") {
@@ -280,7 +167,6 @@ function onEnter(fn) {
280
167
  }
281
168
  };
282
169
  }
283
- __name(onEnter, "onEnter");
284
170
  function friendlyUserName(user, format = "all") {
285
171
  const { email, displayName } = user;
286
172
  const hasDisplayName = displayName && displayName !== "unknown";
@@ -307,21 +193,21 @@ function friendlyUserName(user, format = "all") {
307
193
  }
308
194
  return "<UNKNOWN USER>";
309
195
  }
310
- __name(friendlyUserName, "friendlyUserName");
311
196
  function classNames(...classes) {
312
197
  return classes.filter((c) => !!c).join(" ");
313
198
  }
314
- __name(classNames, "classNames");
315
199
  function props(properties) {
316
- return Object.entries(properties).reduce((acc, [key, value]) => {
317
- if (typeof value !== "object" && typeof value !== "function") {
318
- acc[key] = value;
319
- }
320
- return acc;
321
- }, {});
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
+ );
322
209
  }
323
- __name(props, "props");
324
210
 
325
- export { AllianceError, FrameworkErrorCodes, texts_default as Texts, TranslationsKey, UtilitiesErrorCodes, VocaButtonVariant, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
211
+ export { AllianceError, FrameworkErrorCodes, UtilitiesErrorCodes, VocaButtonVariant, classNames, createCapabilityPath, friendlyUserName, getCurrentLocationInfo, getRuntimeRootUrl, getVocaIcon, isAllianceError, mapToVocaOptions, onEnter, props, vocaIconsToOptions };
326
212
  //# sourceMappingURL=out.js.map
327
213
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/exceptions.ts","../src/routing.ts","../src/translations.ts","../src/texts.ts","../src/ui.ts"],"names":["FrameworkErrorCodes","UtilitiesErrorCodes","parseTemplates","message","variables","Object","entries","reduce","acc","key","value","replaceAll","allianceErrors","ALLIANCE_ERROR_NAME","AllianceError","Error","constructor","code","info","name","stack","isAllianceError","error","createQueryString","args","filteredArgs","entry","JSON","stringify","keys","length","URLSearchParams","getCurrentPath","runtimeRootUrl","getRuntimeRootUrl","href","search","window","location","replace","createCapabilityPath","app","capability","rootPath","origin","queryString","getCurrentLocationInfo","currentPath","split","filter","part","globalThis","__ALLIANCE_RUNTIME_ROOT_URL","TranslationsKey","en","Texts","getTranslations","getTranslation","translations","translation","formattedTranslation","curr","index","toString","get","MissingTranslationKey","vocaIconsToOptions","vocaIcons","selected","mapToVocaOptions","values","label","VocaButtonVariant","getVocaIcon","icon","find","items","mapper","placeholder","item","push","disabled","onEnter","fn","e","friendlyUserName","user","format","email","displayName","hasDisplayName","hasEmail","classNames","classes","c","join","props","properties"],"mappings":";;;;;UAAYA,sBAAAA;;;;;;;;;;;;;;;GAAAA,wBAAAA,sBAAAA,CAAAA,EAAAA;;UAiBAC,sBAAAA;;;;;GAAAA,wBAAAA,sBAAAA,CAAAA,EAAAA;AASZ,SAASC,eAAeC,SAAiBC,WAAiC;AACtE,SAAOC,OAAOC,QAAQF,SAAAA,EAAWG,OAAO,CAACC,KAAK,CAACC,KAAKC,KAAAA,MAAM;AACtD,WAAOF,IAAIG,WAAW,KAAKF,GAAAA,M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AM,EAAEC,OAAOC,YAAW,IAAKH;AAE/B,QAAMI,iBAAiBD,eAAeA,gBAAgB;AACtD,QAAME,WAAW,CAAC,CAACH;AAEnB,UAAQD,QAAAA;IACJ,KAAK,OAAO;AACR,UAAIG,kBAAkBC,UAAU;AAC5B,eAAO,GAAGF,WAAAA,KAAgBD,KAAAA;MAC9B,WAAWE,gBAAgB;AACvB,eAAOD;MACX,WAAWE,UAAU;AACjB,eAAOH;MACX;AACA;IACJ;IACA,KAAK,UAAU;AACX,UAAIE,gBAAgB;AAChB,eAAOD;MACX,WAAWE,UAAU;AACjB,eAAOH;MACX;AACA;IACJ;EACJ;AAEA,SAAO;AACX;AA/BgBH;AAiCT,SAASO,cAAcC,SAAiB;AAC3C,SAAOA,QAAQ5C,OAAO,CAAC6C,MAAM,CAAC,CAACA,CAAAA,EAAGC,KAAK,GAAA;AAC3C;AAFgBH;AAIT,SAASI,MAAMC,YAAkB;AACpC,SAAO5F,OAAOC,QAAQ2F,UAAAA,EAAY1F,OAC9B,CAACC,KAAK,CAACC,KAAKC,KAAAA,MAAM;AACd,QAAI,OAAOA,UAAU,YAAY,OAAOA,UAAU,YAAY;AAC1DF,UAAIC,GAAAA,IAAOC;IACf;AAEA,WAAOF;EACX,GACA,CAAC,CAAA;AAET;AAXgBwF","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 type Translations = {\n [key in TranslationsKey]: string;\n};\n\nexport enum TranslationsKey {\n AlreadyExists,\n ApiGatewayPortDescription,\n ApiServerModeDescription,\n AppConfigurationPath,\n AppCreated,\n AppEntryBuildOptionDescription,\n AppNameInquiry,\n BuildDescription,\n BuildModeOptionDescription,\n BuildWatchDescription,\n CreateAppDescription,\n CreateWorkspaceDescription,\n DevServerOpenDescription,\n DevServerPortDescription,\n DevServerLoggingDescription,\n Done,\n FetchPackageVersionError,\n ManifestEntryBuildOptionDescription,\n MissingTranslationKey,\n NoAppName,\n NoAppNameFound,\n NoAppOrWorkspaceInCurrentDirectory,\n NoWorkspaceName,\n OperationCancelled,\n ServeDescription,\n ServedStopped,\n ServerGatewayMode,\n ServerMode,\n ServerModeInquiry,\n ServerProxyMode,\n StopServerInstructions,\n TemplateFrameworkInquiry,\n TemplateLanguageInquiry,\n UnrecognizedCommand,\n WorkspaceCreated,\n WorkspaceNameInquiry,\n}\n\nexport const en: Translations = {\n [TranslationsKey.Done]: 'Done',\n [TranslationsKey.NoWorkspaceName]: 'No workspace name provided!',\n [TranslationsKey.NoAppName]: 'No app name provided!',\n [TranslationsKey.AlreadyExists]: \"File or directory '{0}' already exists!\",\n [TranslationsKey.NoAppOrWorkspaceInCurrentDirectory]:\n \"Could not find any app entry file at '{0}'!\",\n [TranslationsKey.UnrecognizedCommand]: 'Unrecognized command(s) {0}!',\n [TranslationsKey.WorkspaceCreated]: \"Workspace was created at path '{0}'!\",\n [TranslationsKey.AppCreated]: \"App was created at path '{0}'!\",\n [TranslationsKey.ServedStopped]: 'Server stopped.',\n [TranslationsKey.CreateWorkspaceDescription]:\n 'Creates an Alliance Workspace in the current directory.',\n [TranslationsKey.CreateAppDescription]:\n 'Creates an Alliance Application in the current directory or Alliance Workspace.',\n [TranslationsKey.ServeDescription]:\n 'Starts a Alliance development server using the current directory package.json.',\n [TranslationsKey.BuildDescription]: 'Builds an Alliance Application using Vite.',\n [TranslationsKey.WorkspaceNameInquiry]: 'Enter the name of your workspace',\n [TranslationsKey.ServerModeInquiry]: 'Which server mode do you want to use?',\n [TranslationsKey.AppNameInquiry]: 'Enter the name of your app',\n [TranslationsKey.MissingTranslationKey]: 'No translation key provided!',\n [TranslationsKey.OperationCancelled]: 'Operation cancelled.',\n [TranslationsKey.StopServerInstructions]: 'Press CTRL + C to stop the server.\\n',\n [TranslationsKey.TemplateLanguageInquiry]: 'Select preferred language',\n [TranslationsKey.TemplateFrameworkInquiry]: 'Select preferred framework template',\n [TranslationsKey.DevServerPortDescription]: 'The port that the dev server should use.',\n [TranslationsKey.DevServerLoggingDescription]:\n 'Whether the dev server and browser console should output more log information or not (false).',\n [TranslationsKey.ApiGatewayPortDescription]: 'The port that the api gateway should use.',\n [TranslationsKey.ApiServerModeDescription]:\n 'Which components to start. [server|server-proxy|server-gateway].',\n [TranslationsKey.DevServerOpenDescription]:\n 'Whether the dev server should automatically open in your browser or not.',\n [TranslationsKey.BuildWatchDescription]:\n 'Whether the build should start watching and rebuild when files change or not.',\n [TranslationsKey.AppEntryBuildOptionDescription]: 'The entry file for the app (./src/app).',\n [TranslationsKey.ManifestEntryBuildOptionDescription]:\n 'The entry file for the app manifest (./src/manifest).',\n [TranslationsKey.BuildModeOptionDescription]: 'Which mode to use when building the app.',\n [TranslationsKey.FetchPackageVersionError]:\n \"Failed to fetch package info from the NPM registry for package '${0}'!\",\n [TranslationsKey.NoAppNameFound]: 'Could not find app name in manifest.',\n [TranslationsKey.AppConfigurationPath]: 'The path to the app configuration file.',\n [TranslationsKey.ServerMode]: 'Server',\n [TranslationsKey.ServerProxyMode]: 'Server with proxy',\n [TranslationsKey.ServerGatewayMode]: 'Server with gateway',\n};\n","import { type Translations, TranslationsKey, en } from './translations';\n\nexport type TextArgs = (string | number)[];\n\nexport class Texts {\n protected static getTranslations = (): Translations => {\n return en;\n };\n\n protected static getTranslation = (key: TranslationsKey, ...args: TextArgs): string => {\n const translations = Texts.getTranslations();\n const translation = translations[key];\n\n if (!translation) throw new Error(`Could not find text with given key '${key}'.`);\n\n const formattedTranslation = args.reduce(\n (acc, curr, index) => acc.toString().replace(`{${index}}`, curr.toString()),\n translation,\n );\n\n return formattedTranslation.toString();\n };\n\n public static get = (\n key: TranslationsKey = TranslationsKey.MissingTranslationKey,\n ...args: TextArgs\n ) => this.getTranslation(key, ...args);\n}\n\nexport default Texts;\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"]}
1
+ {"version":3,"sources":["../src/exceptions.ts","../src/routing.ts","../src/ui.ts"],"names":["FrameworkErrorCodes","UtilitiesErrorCodes","VocaButtonVariant","icon"],"mappings":";AAAO,IAAK,sBAAL,kBAAKA,yBAAL;AACH,EAAAA,0CAAA,wBAAqB,OAArB;AACA,EAAAA,0CAAA,eAAY,QAAZ;AACA,EAAAA,0CAAA,0BAAuB,QAAvB;AACA,EAAAA,0CAAA,4BAAyB,QAAzB;AACA,EAAAA,0CAAA,kCAA+B,QAA/B;AACA,EAAAA,0CAAA,gBAAa,QAAb;AACA,EAAAA,0CAAA,mBAAgB,QAAhB;AACA,EAAAA,0CAAA,YAAS,QAAT;AACA,EAAAA,0CAAA,yBAAsB,QAAtB;AACA,EAAAA,0CAAA,8BAA2B,QAA3B;AACA,EAAAA,0CAAA,0BAAuB,QAAvB;AACA,EAAAA,0CAAA,+BAA4B,QAA5B;AACA,EAAAA,0CAAA,oCAAiC,QAAjC;AACA,EAAAA,0CAAA,sBAAmB,QAAnB;AAdQ,SAAAA;AAAA,GAAA;AAiBL,IAAK,sB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EACX;AACJ;AAEO,SAAS,QAAQ,IAAgC;AACpD,SAAO,CAAC,MAAqB;AACzB,QAAI,EAAE,QAAQ,SAAS;AACnB,SAAG,CAAC;AAAA,IACR;AAAA,EACJ;AACJ;AAEO,SAAS,iBACZ,MACA,SAA2B,OAC7B;AACE,QAAM,EAAE,OAAO,YAAY,IAAI;AAE/B,QAAM,iBAAiB,eAAe,gBAAgB;AACtD,QAAM,WAAW,CAAC,CAAC;AAEnB,UAAQ,QAAQ;AAAA,IACZ,KAAK,OAAO;AACR,UAAI,kBAAkB,UAAU;AAC5B,eAAO,GAAG,WAAW,KAAK,KAAK;AAAA,MACnC,WAAW,gBAAgB;AACvB,eAAO;AAAA,MACX,WAAW,UAAU;AACjB,eAAO;AAAA,MACX;AACA;AAAA,IACJ;AAAA,IACA,KAAK,UAAU;AACX,UAAI,gBAAgB;AAChB,eAAO;AAAA,MACX,WAAW,UAAU;AACjB,eAAO;AAAA,MACX;AACA;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AACX;AAEO,SAAS,cAAc,SAAmB;AAC7C,SAAO,QAAQ,OAAO,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/alliance-internal-client-utilities",
3
- "version": "1.0.5-next.0",
3
+ "version": "1.0.6-next.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",
@@ -14,8 +14,8 @@
14
14
  "dist"
15
15
  ],
16
16
  "devDependencies": {
17
- "@telia-ace/alliance-internal-node-utilities": "1.0.5-next.0",
18
- "tsup": "^7.2.0"
17
+ "tsup": "^7.2.0",
18
+ "@telia-ace/alliance-internal-node-utilities": "^1.0.6-next.0"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"