@telia-ace/alliance-internal-client-utilities 1.0.5 → 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,11 @@
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
+
3
9
  ## 1.0.5
4
10
 
5
11
  ### 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
@@ -116,111 +116,6 @@ function getRuntimeRootUrl() {
116
116
  return window.origin;
117
117
  }
118
118
 
119
- // src/translations.ts
120
- var TranslationsKey = /* @__PURE__ */ ((TranslationsKey2) => {
121
- TranslationsKey2[TranslationsKey2["AlreadyExists"] = 0] = "AlreadyExists";
122
- TranslationsKey2[TranslationsKey2["ApiGatewayPortDescription"] = 1] = "ApiGatewayPortDescription";
123
- TranslationsKey2[TranslationsKey2["ApiServerModeDescription"] = 2] = "ApiServerModeDescription";
124
- TranslationsKey2[TranslationsKey2["AppConfigurationPath"] = 3] = "AppConfigurationPath";
125
- TranslationsKey2[TranslationsKey2["AppCreated"] = 4] = "AppCreated";
126
- TranslationsKey2[TranslationsKey2["AppEntryBuildOptionDescription"] = 5] = "AppEntryBuildOptionDescription";
127
- TranslationsKey2[TranslationsKey2["AppNameInquiry"] = 6] = "AppNameInquiry";
128
- TranslationsKey2[TranslationsKey2["BuildDescription"] = 7] = "BuildDescription";
129
- TranslationsKey2[TranslationsKey2["BuildModeOptionDescription"] = 8] = "BuildModeOptionDescription";
130
- TranslationsKey2[TranslationsKey2["BuildWatchDescription"] = 9] = "BuildWatchDescription";
131
- TranslationsKey2[TranslationsKey2["CreateAppDescription"] = 10] = "CreateAppDescription";
132
- TranslationsKey2[TranslationsKey2["CreateWorkspaceDescription"] = 11] = "CreateWorkspaceDescription";
133
- TranslationsKey2[TranslationsKey2["DevServerOpenDescription"] = 12] = "DevServerOpenDescription";
134
- TranslationsKey2[TranslationsKey2["DevServerPortDescription"] = 13] = "DevServerPortDescription";
135
- TranslationsKey2[TranslationsKey2["DevServerLoggingDescription"] = 14] = "DevServerLoggingDescription";
136
- TranslationsKey2[TranslationsKey2["Done"] = 15] = "Done";
137
- TranslationsKey2[TranslationsKey2["FetchPackageVersionError"] = 16] = "FetchPackageVersionError";
138
- TranslationsKey2[TranslationsKey2["ManifestEntryBuildOptionDescription"] = 17] = "ManifestEntryBuildOptionDescription";
139
- TranslationsKey2[TranslationsKey2["MissingTranslationKey"] = 18] = "MissingTranslationKey";
140
- TranslationsKey2[TranslationsKey2["NoAppName"] = 19] = "NoAppName";
141
- TranslationsKey2[TranslationsKey2["NoAppNameFound"] = 20] = "NoAppNameFound";
142
- TranslationsKey2[TranslationsKey2["NoAppOrWorkspaceInCurrentDirectory"] = 21] = "NoAppOrWorkspaceInCurrentDirectory";
143
- TranslationsKey2[TranslationsKey2["NoWorkspaceName"] = 22] = "NoWorkspaceName";
144
- TranslationsKey2[TranslationsKey2["OperationCancelled"] = 23] = "OperationCancelled";
145
- TranslationsKey2[TranslationsKey2["ServeDescription"] = 24] = "ServeDescription";
146
- TranslationsKey2[TranslationsKey2["ServedStopped"] = 25] = "ServedStopped";
147
- TranslationsKey2[TranslationsKey2["ServerGatewayMode"] = 26] = "ServerGatewayMode";
148
- TranslationsKey2[TranslationsKey2["ServerMode"] = 27] = "ServerMode";
149
- TranslationsKey2[TranslationsKey2["ServerModeInquiry"] = 28] = "ServerModeInquiry";
150
- TranslationsKey2[TranslationsKey2["ServerProxyMode"] = 29] = "ServerProxyMode";
151
- TranslationsKey2[TranslationsKey2["StopServerInstructions"] = 30] = "StopServerInstructions";
152
- TranslationsKey2[TranslationsKey2["TemplateFrameworkInquiry"] = 31] = "TemplateFrameworkInquiry";
153
- TranslationsKey2[TranslationsKey2["TemplateLanguageInquiry"] = 32] = "TemplateLanguageInquiry";
154
- TranslationsKey2[TranslationsKey2["UnrecognizedCommand"] = 33] = "UnrecognizedCommand";
155
- TranslationsKey2[TranslationsKey2["WorkspaceCreated"] = 34] = "WorkspaceCreated";
156
- TranslationsKey2[TranslationsKey2["WorkspaceNameInquiry"] = 35] = "WorkspaceNameInquiry";
157
- return TranslationsKey2;
158
- })(TranslationsKey || {});
159
- var en = {
160
- [15 /* Done */]: "Done",
161
- [22 /* NoWorkspaceName */]: "No workspace name provided!",
162
- [19 /* NoAppName */]: "No app name provided!",
163
- [0 /* AlreadyExists */]: "File or directory '{0}' already exists!",
164
- [21 /* NoAppOrWorkspaceInCurrentDirectory */]: "Could not find any app entry file at '{0}'!",
165
- [33 /* UnrecognizedCommand */]: "Unrecognized command(s) {0}!",
166
- [34 /* WorkspaceCreated */]: "Workspace was created at path '{0}'!",
167
- [4 /* AppCreated */]: "App was created at path '{0}'!",
168
- [25 /* ServedStopped */]: "Server stopped.",
169
- [11 /* CreateWorkspaceDescription */]: "Creates an Alliance Workspace in the current directory.",
170
- [10 /* CreateAppDescription */]: "Creates an Alliance Application in the current directory or Alliance Workspace.",
171
- [24 /* ServeDescription */]: "Starts a Alliance development server using the current directory package.json.",
172
- [7 /* BuildDescription */]: "Builds an Alliance Application using Vite.",
173
- [35 /* WorkspaceNameInquiry */]: "Enter the name of your workspace",
174
- [28 /* ServerModeInquiry */]: "Which server mode do you want to use?",
175
- [6 /* AppNameInquiry */]: "Enter the name of your app",
176
- [18 /* MissingTranslationKey */]: "No translation key provided!",
177
- [23 /* OperationCancelled */]: "Operation cancelled.",
178
- [30 /* StopServerInstructions */]: "Press CTRL + C to stop the server.\n",
179
- [32 /* TemplateLanguageInquiry */]: "Select preferred language",
180
- [31 /* TemplateFrameworkInquiry */]: "Select preferred framework template",
181
- [13 /* DevServerPortDescription */]: "The port that the dev server should use.",
182
- [14 /* DevServerLoggingDescription */]: "Whether the dev server and browser console should output more log information or not (false).",
183
- [1 /* ApiGatewayPortDescription */]: "The port that the api gateway should use.",
184
- [2 /* ApiServerModeDescription */]: "Which components to start. [server|server-proxy|server-gateway].",
185
- [12 /* DevServerOpenDescription */]: "Whether the dev server should automatically open in your browser or not.",
186
- [9 /* BuildWatchDescription */]: "Whether the build should start watching and rebuild when files change or not.",
187
- [5 /* AppEntryBuildOptionDescription */]: "The entry file for the app (./src/app).",
188
- [17 /* ManifestEntryBuildOptionDescription */]: "The entry file for the app manifest (./src/manifest).",
189
- [8 /* BuildModeOptionDescription */]: "Which mode to use when building the app.",
190
- [16 /* FetchPackageVersionError */]: "Failed to fetch package info from the NPM registry for package '${0}'!",
191
- [20 /* NoAppNameFound */]: "Could not find app name in manifest.",
192
- [3 /* AppConfigurationPath */]: "The path to the app configuration file.",
193
- [27 /* ServerMode */]: "Server",
194
- [29 /* ServerProxyMode */]: "Server with proxy",
195
- [26 /* ServerGatewayMode */]: "Server with gateway"
196
- };
197
-
198
- // src/texts.ts
199
- var Texts = class _Texts {
200
- static {
201
- this.getTranslations = () => {
202
- return en;
203
- };
204
- }
205
- static {
206
- this.getTranslation = (key, ...args) => {
207
- const translations = _Texts.getTranslations();
208
- const translation = translations[key];
209
- if (!translation)
210
- throw new Error(`Could not find text with given key '${key}'.`);
211
- const formattedTranslation = args.reduce(
212
- (acc, curr, index) => acc.toString().replace(`{${index}}`, curr.toString()),
213
- translation
214
- );
215
- return formattedTranslation.toString();
216
- };
217
- }
218
- static {
219
- this.get = (key = 18 /* MissingTranslationKey */, ...args) => this.getTranslation(key, ...args);
220
- }
221
- };
222
- var texts_default = Texts;
223
-
224
119
  // src/ui.ts
225
120
  function vocaIconsToOptions(vocaIcons, selected) {
226
121
  return mapToVocaOptions(Object.values(vocaIcons), ({ name }) => ({
@@ -313,6 +208,6 @@ function props(properties) {
313
208
  );
314
209
  }
315
210
 
316
- 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 };
317
212
  //# sourceMappingURL=out.js.map
318
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","TranslationsKey","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,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AO,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 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":";A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Q,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",
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",
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "devDependencies": {
17
17
  "tsup": "^7.2.0",
18
- "@telia-ace/alliance-internal-node-utilities": "^1.0.5"
18
+ "@telia-ace/alliance-internal-node-utilities": "^1.0.6-next.0"
19
19
  },
20
20
  "publishConfig": {
21
21
  "access": "public"