@telia-ace/alliance-utilities 1.0.16-next.0 → 1.1.0-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/dist/index.d.ts CHANGED
@@ -32,4 +32,4 @@ type RecordEntries = Record<string, string>;
32
32
  type TranslatorFunction = (key: string, params?: RecordEntries) => string;
33
33
  declare function getTranslator(): Promise<TranslatorFunction>;
34
34
 
35
- export { TranslatorFunction, getCurrentUser, getCurrentWorkspace, getTranslator };
35
+ export { type TranslatorFunction, getCurrentUser, getCurrentWorkspace, getTranslator };
package/dist/index.js CHANGED
@@ -1,93 +1 @@
1
- import { queryObjects, getAppManifest, getAppManifests } from '@telia-ace/alliance-framework';
2
- import { isAllianceError, FrameworkErrorCodes, AllianceError, UtilitiesErrorCodes } from '@telia-ace/alliance-internal-client-utilities';
3
-
4
- // src/get-current-user.ts
5
- var currentUser;
6
- async function getCurrentUser() {
7
- try {
8
- if (!currentUser) {
9
- const query = queryObjects("currentUser");
10
- currentUser = await query.resolve();
11
- }
12
- return {
13
- ...currentUser,
14
- hasPermission(appName, permissionName) {
15
- return !!currentUser?.permissions.find(
16
- ({ permission }) => permission.app.name === appName && permission.name === permissionName
17
- );
18
- },
19
- isSystemAdmin() {
20
- return !!currentUser && currentUser.type === "system-admin";
21
- }
22
- };
23
- } catch (err) {
24
- if (isAllianceError(err) && err?.code === FrameworkErrorCodes.MissingManagedObjectProvider) {
25
- throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingProvider);
26
- } else if (err.message?.includes("No User Found")) {
27
- throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingInDatabase);
28
- } else if (err?.name === "TRPCClientError" && err.message.includes("is not valid JSON")) {
29
- throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingBackend);
30
- } else {
31
- throw err;
32
- }
33
- }
34
- }
35
- async function getCurrentWorkspace() {
36
- const query = queryObjects("currentWorkspace");
37
- return await query.resolve();
38
- }
39
- function getDefaultLocalization(manifest) {
40
- const staticValues = {
41
- "app-name": manifest.name,
42
- "app-description": ""
43
- };
44
- if (!manifest.resources?.localization) {
45
- return staticValues;
46
- }
47
- const localizationKeys = Object.keys(manifest.resources.localization);
48
- const defaults = localizationKeys.reduce((obj, item) => {
49
- obj[item] = manifest.resources.localization[item].value;
50
- return obj;
51
- }, {});
52
- return { ...defaults, ...staticValues };
53
- }
54
- function parseTemplates(message = "", variables) {
55
- return Object.entries(variables).reduce((acc, [key, value]) => {
56
- return acc.replaceAll(`{{${key}}}`, value);
57
- }, message);
58
- }
59
- async function getAppLocalization() {
60
- const manifest = getAppManifest();
61
- const appManifests = getAppManifests();
62
- const defaultLocalization = getDefaultLocalization(manifest);
63
- let localization = {};
64
- if (appManifests?.find(({ name }) => name === "resource-management")) {
65
- localization = await queryObjects("resourceTexts", { app: manifest?.name }).resolve();
66
- }
67
- return Object.keys(defaultLocalization).reduce((acc, key) => {
68
- if (localization[key]) {
69
- acc[key] = localization[key];
70
- }
71
- return acc;
72
- }, defaultLocalization);
73
- }
74
- var localizationStore = {};
75
- async function getTranslator() {
76
- if (Object.keys(localizationStore).length === 0) {
77
- localizationStore = await getAppLocalization();
78
- }
79
- return (key, params) => {
80
- const template = localizationStore[key];
81
- if (template === void 0) {
82
- throw new AllianceError(FrameworkErrorCodes.LocalizationTemplateNotDefined, { key });
83
- }
84
- if (!params || typeof params !== "object" || Object.keys(params).length === 0) {
85
- return template;
86
- }
87
- return parseTemplates(template, params);
88
- };
89
- }
90
-
91
- export { getCurrentUser, getCurrentWorkspace, getTranslator };
92
- //# sourceMappingURL=out.js.map
93
- //# sourceMappingURL=index.js.map
1
+ import{queryObjects as l}from"@telia-ace/alliance-framework";import{AllianceError as a,FrameworkErrorCodes as p,UtilitiesErrorCodes as c,isAllianceError as m}from"@telia-ace/alliance-internal-client-utilities";var o;async function g(){try{return o||(o=await l("currentUser").resolve()),{...o,hasPermission(e,r){return!!o?.permissions.find(({permission:t})=>t.app.name===e&&t.name===r)},isSystemAdmin(){return!!o&&o.type==="system-admin"}}}catch(e){throw m(e)&&e?.code===p.MissingManagedObjectProvider?new a(c.CurrentUserMissingProvider):e.message?.includes("No User Found")?new a(c.CurrentUserMissingInDatabase):e?.name==="TRPCClientError"&&e.message.includes("is not valid JSON")?new a(c.CurrentUserMissingBackend):e}}import{queryObjects as d}from"@telia-ace/alliance-framework";async function f(){return await d("currentWorkspace").resolve()}import{getAppManifest as y,getAppManifests as w,queryObjects as C}from"@telia-ace/alliance-framework";import{AllianceError as E,FrameworkErrorCodes as b}from"@telia-ace/alliance-internal-client-utilities";function k(e){let r={"app-name":e.name,"app-description":""};return e.resources?.localization?{...Object.keys(e.resources.localization).reduce((n,i)=>(n[i]=e.resources.localization[i].value,n),{}),...r}:r}function R(e="",r){return Object.entries(r).reduce((t,[s,n])=>t.replaceAll(`{{${s}}}`,n),e)}async function U(){let e=y(),r=w(),t=k(e),s={};return r?.find(({name:n})=>n==="resource-management")&&(s=await C("resourceTexts",{app:e?.name}).resolve()),Object.keys(t).reduce((n,i)=>(s[i]&&(n[i]=s[i]),n),t)}var u={};async function z(){return Object.keys(u).length===0&&(u=await U()),(e,r)=>{let t=u[e];if(t===void 0)throw new E(b.LocalizationTemplateNotDefined,{key:e});return!r||typeof r!="object"||Object.keys(r).length===0?t:R(t,r)}}export{g as getCurrentUser,f as getCurrentWorkspace,z as getTranslator};
package/package.json CHANGED
@@ -1,33 +1,32 @@
1
1
  {
2
2
  "name": "@telia-ace/alliance-utilities",
3
- "version": "1.0.16-next.0",
3
+ "version": "1.1.0-next.0",
4
4
  "description": "Utilities used by ACE Alliance apps.",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Telia Company AB",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
7
  "type": "module",
8
+ "exports": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
10
14
  "files": [
11
15
  "LICENSE.txt",
12
16
  "README.md",
13
- "CHANGELOG.md",
14
17
  "dist"
15
18
  ],
16
19
  "dependencies": {
17
- "@telia-ace/alliance-framework": "^1.0.15-next.0",
18
- "@telia-ace/alliance-internal-client-utilities": "^1.0.6-next.0"
19
- },
20
- "devDependencies": {
21
- "tsup": "^7.2.0",
22
- "vitest": "^0.34.6"
20
+ "@telia-ace/alliance-framework": "^1.1.0-next.0",
21
+ "@telia-ace/alliance-internal-client-utilities": "^1.1.0-next.0"
23
22
  },
24
23
  "publishConfig": {
25
24
  "access": "public"
26
25
  },
27
26
  "scripts": {
28
27
  "build:dev": "tsup",
29
- "build:prod": "tsup",
30
- "test": "vitest",
31
- "dev": "tsup --watch"
28
+ "build:prod": "tsup --minify",
29
+ "dev": "tsup --watch",
30
+ "test": "vitest"
32
31
  }
33
32
  }
package/CHANGELOG.md DELETED
@@ -1,365 +0,0 @@
1
- # @telia-ace/alliance-utilities
2
-
3
- ## 1.0.16-next.0
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [[`e352474`](https://github.com/telia-company/ace-alliance-sdk/commit/e35247452722e83239813a4edad87a445c6aac4b)]:
8
- - @telia-ace/alliance-internal-client-utilities@1.0.6-next.0
9
- - @telia-ace/alliance-framework@1.0.15-next.0
10
-
11
- ## 1.0.15
12
-
13
- ### Patch Changes
14
-
15
- - 1b9c7a9: Updated the [Translation API](https://alliance.ace.teliacompany.net/-/docs/other/utilities.html#gettranslator) logic for resolving translated texts. The API now prioritizes the currently selected language, defaults to English if not available, and ultimately falls back to the app manifest's default value if necessary.
16
- - 1b9c7a9: Added [predefined](https://alliance.ace.teliacompany.net/-/docs/other/utilities.html#predefined-texts) localized texts, `'app-name'` and `'app-description'`, which are available for all apps.
17
- - 2858c59: Remove GraphQL specific error handling from `getCurrentUser()`.
18
- - Updated dependencies [1b9c7a9]
19
- - @telia-ace/alliance-internal-client-utilities@1.0.5
20
- - @telia-ace/alliance-framework@1.0.14
21
-
22
- ## 1.0.15-next.2
23
-
24
- ### Patch Changes
25
-
26
- - @telia-ace/alliance-framework@1.0.14-next.1
27
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
28
-
29
- ## 1.0.15-next.1
30
-
31
- ### Patch Changes
32
-
33
- - 2858c59: Remove GraphQL specific error handling from `getCurrentUser()`.
34
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
35
-
36
- ## 1.0.15-next.0
37
-
38
- ### Patch Changes
39
-
40
- - 1b9c7a9: Updated the [Translation API](https://alliance.ace.teliacompany.net/-/docs/other/utilities.html#gettranslator) logic for resolving translated texts. The API now prioritizes the currently selected language, defaults to English if not available, and ultimately falls back to the app manifest's default value if necessary.
41
- - 1b9c7a9: Added [predefined](https://alliance.ace.teliacompany.net/-/docs/other/utilities.html#predefined-texts) localized texts, `'app-name'` and `'app-description'`, which are available for all apps.
42
- - Updated dependencies [1b9c7a9]
43
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
44
- - @telia-ace/alliance-framework@1.0.14-next.0
45
-
46
- ## 1.0.14
47
-
48
- ### Patch Changes
49
-
50
- - c2335bc: Replace Vite with Tsup when building packages.
51
- - Updated dependencies [c2335bc]
52
- - Updated dependencies [c2335bc]
53
- - Updated dependencies [c2335bc]
54
- - Updated dependencies [c2335bc]
55
- - Updated dependencies [c2335bc]
56
- - @telia-ace/alliance-framework@1.0.13
57
- - @telia-ace/alliance-internal-client-utilities@1.0.4
58
-
59
- ## 1.0.14-next.1
60
-
61
- ### Patch Changes
62
-
63
- - Updated dependencies [fcb9f45]
64
- - @telia-ace/alliance-framework@1.0.13-next.1
65
- - @telia-ace/alliance-internal-client-utilities@1.0.4-next.0
66
-
67
- ## 1.0.14-next.0
68
-
69
- ### Patch Changes
70
-
71
- - cd44395: Replace Vite with Tsup when building packages.
72
- - Updated dependencies [cd44395]
73
- - Updated dependencies [cd44395]
74
- - Updated dependencies [cd44395]
75
- - Updated dependencies [cd44395]
76
- - @telia-ace/alliance-framework@1.0.13-next.0
77
- - @telia-ace/alliance-internal-client-utilities@1.0.4-next.0
78
-
79
- ## 1.0.13
80
-
81
- ### Patch Changes
82
-
83
- - Updated dependencies [3489aea]
84
- - @telia-ace/alliance-internal-client-utilities@1.0.3
85
- - @telia-ace/alliance-framework@1.0.12
86
-
87
- ## 1.0.13-next.0
88
-
89
- ### Patch Changes
90
-
91
- - Updated dependencies [3489aea]
92
- - @telia-ace/alliance-internal-client-utilities@1.0.3-next.0
93
- - @telia-ace/alliance-framework@1.0.12
94
-
95
- ## 1.0.12
96
-
97
- ### Patch Changes
98
-
99
- - 7a0e643: Add support for `getCurrentWorkspace` utility.
100
- - 8763155: Fix `isSystemAdmin()` utility not checking user type correctly.
101
- - 59f0d3f: Move `getTranslator()` to `@telia-ace/alliance-utilities`.
102
- - 59f0d3f: Remove unnecessary scripts.
103
- - 8763155: Update all dependencies to latest.
104
- - 59f0d3f: Add `getCurrentUser`, move `hasPermission` and `isSystemAdmin` into current user object.
105
- - Updated dependencies [59f0d3f]
106
- - Updated dependencies [9191022]
107
- - Updated dependencies [59f0d3f]
108
- - Updated dependencies [8763155]
109
- - Updated dependencies [3e6c397]
110
- - @telia-ace/alliance-framework@1.0.12
111
- - @telia-ace/alliance-internal-client-utilities@1.0.2
112
-
113
- ## 1.0.12-next.4
114
-
115
- ### Patch Changes
116
-
117
- - 7a0e643: Add support for `getCurrentWorkspace` utility.
118
-
119
- ## 1.0.12-next.3
120
-
121
- ### Patch Changes
122
-
123
- - Updated dependencies [3e6c397]
124
- - @telia-ace/alliance-framework@1.0.12-next.3
125
-
126
- ## 1.0.12-next.2
127
-
128
- ### Patch Changes
129
-
130
- - Updated dependencies [9191022]
131
- - @telia-ace/alliance-framework@1.0.12-next.2
132
-
133
- ## 1.0.12-next.1
134
-
135
- ### Patch Changes
136
-
137
- - 59f0d3f: Move `getTranslator()` to `@telia-ace/alliance-utilities`.
138
- - 59f0d3f: Remove unnecessary scripts.
139
- - 59f0d3f: Add `getCurrentUser`, move `hasPermission` and `isSystemAdmin` into current user object.
140
- - Updated dependencies [59f0d3f]
141
- - Updated dependencies [59f0d3f]
142
- - @telia-ace/alliance-framework@1.0.12-next.1
143
- - @telia-ace/alliance-internal-client-utilities@1.0.2-next.0
144
-
145
- ## 1.0.12-next.0
146
-
147
- ### Patch Changes
148
-
149
- - 8763155: Fix `isSystemAdmin()` utility not checking user type correctly.
150
- - 8763155: Update all dependencies to latest.
151
- - Updated dependencies [8763155]
152
- - @telia-ace/alliance-framework@1.0.12-next.0
153
-
154
- ## 1.0.11
155
-
156
- ### Patch Changes
157
-
158
- - fd378fe: Add `hasPermission(appName: string, permissionName: string): Promise<boolean>` and `isSystemAdmin(): Promise<boolean>` utilities.
159
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
160
- - 511ba31: Add translation text for dev server logging flag description.
161
- - 511ba31: Move internal utility `matchRegExpLike` back to framework package.
162
- - fd378fe: Package has been repurposed to export utility functionalities used by various apps.
163
- - Updated dependencies [511ba31]
164
- - Updated dependencies [d646342]
165
- - Updated dependencies [fd378fe]
166
- - Updated dependencies [236e315]
167
- - Updated dependencies [511ba31]
168
- - @telia-ace/alliance-framework@1.0.11
169
- - @telia-ace/alliance-internal-client-utilities@1.0.1
170
-
171
- ## 1.0.11-next.1
172
-
173
- ### Patch Changes
174
-
175
- - fd378fe: Add `hasPermission(appName: string, permissionName: string): Promise<boolean>` and `isSystemAdmin(): Promise<boolean>` utilities.
176
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
177
- - fd378fe: Package has been repurposed to export utility functionalities used by various apps.
178
- - Updated dependencies [fd378fe]
179
- - @telia-ace/alliance-internal-client-utilities@1.0.1-next.0
180
- - @telia-ace/alliance-framework@1.0.11-next.2
181
-
182
- ## 1.0.11-next.0
183
-
184
- ### Patch Changes
185
-
186
- - 511ba31: Add translation text for dev server logging flag description.
187
- - 511ba31: Move internal utility `matchRegExpLike` back to framework package.
188
-
189
- ## 1.0.10
190
-
191
- ### Patch Changes
192
-
193
- - 1ea5886: Improved handling of URLs.
194
- - 1ea5886: Add `getCurrentLocationInfo()` and `matchRegExpLike()` utility functions.
195
- - 1ea5886: Remove unused translation texts.
196
- - 1ea5886: Add utility types and routing utilities.
197
-
198
- ## 1.0.10-next.3
199
-
200
- ### Patch Changes
201
-
202
- - 2452588: Remove unused translation texts.
203
-
204
- ## 1.0.10-next.2
205
-
206
- ### Patch Changes
207
-
208
- - 1150fac: Improved handling of URLs.
209
-
210
- ## 1.0.10-next.1
211
-
212
- ### Patch Changes
213
-
214
- - c04ce55: Add `getCurrentLocationInfo()` and `matchRegExpLike()` utility functions.
215
-
216
- ## 1.0.10-next.0
217
-
218
- ### Patch Changes
219
-
220
- - cd495d7: Add utility types and routing utilities.
221
-
222
- ## 1.0.9
223
-
224
- ### Patch Changes
225
-
226
- - e04400c: Split utilities into frontend and backend.
227
- - c89a20d: Add Unpacked TypeScript utility.
228
- - 69d2ced: Update all dependencies to latest.
229
-
230
- ## 1.0.9-next.2
231
-
232
- ### Patch Changes
233
-
234
- - 69d2ced: Update all dependencies to latest.
235
-
236
- ## 1.0.9-next.1
237
-
238
- ### Patch Changes
239
-
240
- - c89a20d: Add Unpacked TypeScript utility.
241
-
242
- ## 1.0.9-next.0
243
-
244
- ### Patch Changes
245
-
246
- - e04400c: Split utilities into frontend and backend.
247
-
248
- ## 1.0.8
249
-
250
- ### Patch Changes
251
-
252
- - 3cfe2c7: Change scripts to `<script>:dev|prod|test` for local, production and test environment builds.
253
- - 6f4dfae: Update all dependencies to latest.
254
-
255
- ## 1.0.8-next.1
256
-
257
- ### Patch Changes
258
-
259
- - 6f4dfae: Update all dependencies to latest.
260
-
261
- ## 1.0.8-next.0
262
-
263
- ### Patch Changes
264
-
265
- - 3cfe2c7: Change scripts to `<script>:dev|prod|test` for local, production and test environment builds.
266
-
267
- ## 1.0.7
268
-
269
- ### Patch Changes
270
-
271
- - cc604b0: Relative path support in CSS import vite plugin.
272
- - fea9df3: Update dependencies to latest.
273
-
274
- ## 1.0.7-next.1
275
-
276
- ### Patch Changes
277
-
278
- - cc604b0: Relative path support in CSS import vite plugin.
279
-
280
- ## 1.0.7-next.0
281
-
282
- ### Patch Changes
283
-
284
- - fea9df3: Update dependencies to latest.
285
-
286
- ## 1.0.6
287
-
288
- ### Patch Changes
289
-
290
- - bcb8666: Add new translation text for logging in using dev server.
291
-
292
- ## 1.0.6-next.0
293
-
294
- ### Patch Changes
295
-
296
- - 4c7f3d9: Add new translation text for logging in using dev server.
297
-
298
- ## 1.0.5
299
-
300
- ### Patch Changes
301
-
302
- - c47d82c: Update all deps to latest.
303
-
304
- ## 1.0.5-next.0
305
-
306
- ### Patch Changes
307
-
308
- - 1299e77: Update all deps to latest.
309
-
310
- ## 1.0.4
311
-
312
- ### Patch Changes
313
-
314
- - 20c6d90: Remove unused translation keys.
315
-
316
- ## 1.0.4-next.0
317
-
318
- ### Patch Changes
319
-
320
- - 20c6d90: Remove unused translation keys.
321
-
322
- ## 1.0.3
323
-
324
- ### Patch Changes
325
-
326
- - c1ca5b5: Move translation and text manager to `@telia-ace/alliance-utilities`.
327
- - 9312699: Update dependencies.
328
-
329
- ## 1.0.3-next.1
330
-
331
- ### Patch Changes
332
-
333
- - 9312699: Update dependencies.
334
-
335
- ## 1.0.3-next.0
336
-
337
- ### Patch Changes
338
-
339
- - c1ca5b5: Move translation and text manager to `@telia-ace/alliance-utilities`.
340
-
341
- ## 1.0.2
342
-
343
- ### Patch Changes
344
-
345
- - b23b6b7: Upgrade dependencies.
346
-
347
- ## 1.0.2-next.0
348
-
349
- ### Patch Changes
350
-
351
- - 380d5d0: Upgrade dependencies.
352
-
353
- ## 1.0.1
354
-
355
- ### Patch Changes
356
-
357
- - ddd21be: Update dependencies.
358
-
359
- ## 1.0.1-next.0
360
-
361
- ### Patch Changes
362
-
363
- - d9726c6: Update dependencies.
364
-
365
- ## 1.0.0
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/get-current-user.ts","../src/get-current-workspace.ts","../src/get-translator.ts"],"names":["queryObjects","AllianceError","FrameworkErrorCodes"],"mappings":"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","sourcesContent":["import { queryObjects } from '@telia-ace/alliance-framework';\nimport {\n AllianceError,\n FrameworkErrorCodes,\n UtilitiesErrorCodes,\n isAllianceError,\n} from '@telia-ace/alliance-internal-client-utilities';\n\ntype CurrentUser = {\n displayName: string;\n email: string;\n type: 'system-admin' | 'user';\n objectId: string;\n permissions: { permission: { name: string; app: { name: string } } }[];\n workspaces: { workspace: { name: string; slug: string } }[];\n hasPermission: (appName: string, permissionName: string) => boolean;\n isSystemAdmin: () => boolean;\n};\n\nlet currentUser: CurrentUser;\n\nexport async function getCurrentUser(): Promise<CurrentUser> {\n try {\n if (!currentUser) {\n const query = queryObjects<CurrentUser>('currentUser');\n currentUser = await query.resolve();\n }\n\n return {\n ...currentUser,\n hasPermission(appName, permissionName) {\n return !!currentUser?.permissions.find(\n ({ permission }) =>\n permission.app.name === appName && permission.name === permissionName,\n );\n },\n isSystemAdmin() {\n return !!currentUser && currentUser.type === 'system-admin';\n },\n };\n } catch (err: any) {\n if (\n isAllianceError(err) &&\n err?.code === FrameworkErrorCodes.MissingManagedObjectProvider\n ) {\n throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingProvider);\n } else if (err.message?.includes('No User Found')) {\n throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingInDatabase);\n } else if (err?.name === 'TRPCClientError' && err.message.includes('is not valid JSON')) {\n throw new AllianceError(UtilitiesErrorCodes.CurrentUserMissingBackend);\n } else {\n throw err;\n }\n }\n}\n","import { queryObjects } from '@telia-ace/alliance-framework';\n\ntype CurrentWorkspace = {\n name: string;\n slug: string;\n};\n\nexport async function getCurrentWorkspace() {\n const query = queryObjects<CurrentWorkspace>('currentWorkspace');\n return await query.resolve();\n}\n","import {\n type AppManifest,\n getAppManifest,\n getAppManifests,\n queryObjects,\n} from '@telia-ace/alliance-framework';\nimport { AllianceError, FrameworkErrorCodes } from '@telia-ace/alliance-internal-client-utilities';\n\ntype RecordEntries = Record<string, string>;\nexport type TranslatorFunction = (key: string, params?: RecordEntries) => string;\n\nexport function getDefaultLocalization(manifest: AppManifest): RecordEntries {\n const staticValues: RecordEntries = {\n 'app-name': manifest.name,\n 'app-description': '',\n };\n\n if (!manifest.resources?.localization) {\n return staticValues;\n }\n\n const localizationKeys = Object.keys(manifest.resources.localization);\n const defaults = localizationKeys.reduce((obj: RecordEntries, item: string) => {\n obj[item] = manifest.resources!.localization![item].value;\n\n return obj;\n }, {});\n\n return { ...defaults, ...staticValues };\n}\n\nfunction parseTemplates(message: string = '', variables: RecordEntries) {\n return Object.entries(variables).reduce((acc, [key, value]) => {\n return acc.replaceAll(`{{${key}}}`, value);\n }, message);\n}\n\nasync function getAppLocalization(): Promise<RecordEntries> {\n const manifest = getAppManifest();\n const appManifests = getAppManifests();\n\n const defaultLocalization = getDefaultLocalization(manifest);\n let localization: Record<string, string> = {};\n\n // Dont try to query objects if the resource management app is not installed\n if (appManifests?.find(({ name }) => name === 'resource-management')) {\n localization = await queryObjects('resourceTexts', { app: manifest?.name }).resolve();\n }\n\n return Object.keys(defaultLocalization).reduce<Record<string, string>>((acc, key) => {\n if (localization[key]) {\n acc[key] = localization[key];\n }\n\n return acc;\n }, defaultLocalization);\n}\n\nlet localizationStore: RecordEntries = {};\n\nexport async function getTranslator(): Promise<TranslatorFunction> {\n if (Object.keys(localizationStore).length === 0) {\n localizationStore = await getAppLocalization();\n }\n\n return (key: string, params?: RecordEntries): string => {\n const template = localizationStore[key];\n\n if (template === undefined) {\n throw new AllianceError(FrameworkErrorCodes.LocalizationTemplateNotDefined, { key });\n }\n\n if (!params || typeof params !== 'object' || Object.keys(params).length === 0) {\n return template;\n }\n\n return parseTemplates(template, params);\n };\n}\n"]}