@telia-ace/alliance-utilities 1.0.16 → 1.1.0-next.1

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,29 +1,32 @@
1
1
  {
2
2
  "name": "@telia-ace/alliance-utilities",
3
- "version": "1.0.16",
3
+ "version": "1.1.0-next.1",
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",
18
- "@telia-ace/alliance-internal-client-utilities": "^1.0.6"
20
+ "@telia-ace/alliance-framework": "^1.1.0-next.1",
21
+ "@telia-ace/alliance-internal-client-utilities": "^1.1.0-next.0"
19
22
  },
20
23
  "publishConfig": {
21
24
  "access": "public"
22
25
  },
23
26
  "scripts": {
24
27
  "build:dev": "tsup",
25
- "build:prod": "tsup",
26
- "test": "vitest",
27
- "dev": "tsup --watch"
28
+ "build:prod": "tsup --minify",
29
+ "dev": "tsup --watch",
30
+ "test": "vitest"
28
31
  }
29
32
  }
package/CHANGELOG.md DELETED
@@ -1,373 +0,0 @@
1
- # @telia-ace/alliance-utilities
2
-
3
- ## 1.0.16
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [[`f8a0a8c`](https://github.com/telia-company/ace-alliance-sdk/commit/f8a0a8cfa9173037bba2731fa80540f698eaf680)]:
8
- - @telia-ace/alliance-internal-client-utilities@1.0.6
9
- - @telia-ace/alliance-framework@1.0.15
10
-
11
- ## 1.0.16-next.0
12
-
13
- ### Patch Changes
14
-
15
- - Updated dependencies [[`e352474`](https://github.com/telia-company/ace-alliance-sdk/commit/e35247452722e83239813a4edad87a445c6aac4b)]:
16
- - @telia-ace/alliance-internal-client-utilities@1.0.6-next.0
17
- - @telia-ace/alliance-framework@1.0.15-next.0
18
-
19
- ## 1.0.15
20
-
21
- ### Patch Changes
22
-
23
- - 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.
24
- - 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.
25
- - 2858c59: Remove GraphQL specific error handling from `getCurrentUser()`.
26
- - Updated dependencies [1b9c7a9]
27
- - @telia-ace/alliance-internal-client-utilities@1.0.5
28
- - @telia-ace/alliance-framework@1.0.14
29
-
30
- ## 1.0.15-next.2
31
-
32
- ### Patch Changes
33
-
34
- - @telia-ace/alliance-framework@1.0.14-next.1
35
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
36
-
37
- ## 1.0.15-next.1
38
-
39
- ### Patch Changes
40
-
41
- - 2858c59: Remove GraphQL specific error handling from `getCurrentUser()`.
42
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
43
-
44
- ## 1.0.15-next.0
45
-
46
- ### Patch Changes
47
-
48
- - 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.
49
- - 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.
50
- - Updated dependencies [1b9c7a9]
51
- - @telia-ace/alliance-internal-client-utilities@1.0.5-next.0
52
- - @telia-ace/alliance-framework@1.0.14-next.0
53
-
54
- ## 1.0.14
55
-
56
- ### Patch Changes
57
-
58
- - c2335bc: Replace Vite with Tsup when building packages.
59
- - Updated dependencies [c2335bc]
60
- - Updated dependencies [c2335bc]
61
- - Updated dependencies [c2335bc]
62
- - Updated dependencies [c2335bc]
63
- - Updated dependencies [c2335bc]
64
- - @telia-ace/alliance-framework@1.0.13
65
- - @telia-ace/alliance-internal-client-utilities@1.0.4
66
-
67
- ## 1.0.14-next.1
68
-
69
- ### Patch Changes
70
-
71
- - Updated dependencies [fcb9f45]
72
- - @telia-ace/alliance-framework@1.0.13-next.1
73
- - @telia-ace/alliance-internal-client-utilities@1.0.4-next.0
74
-
75
- ## 1.0.14-next.0
76
-
77
- ### Patch Changes
78
-
79
- - cd44395: Replace Vite with Tsup when building packages.
80
- - Updated dependencies [cd44395]
81
- - Updated dependencies [cd44395]
82
- - Updated dependencies [cd44395]
83
- - Updated dependencies [cd44395]
84
- - @telia-ace/alliance-framework@1.0.13-next.0
85
- - @telia-ace/alliance-internal-client-utilities@1.0.4-next.0
86
-
87
- ## 1.0.13
88
-
89
- ### Patch Changes
90
-
91
- - Updated dependencies [3489aea]
92
- - @telia-ace/alliance-internal-client-utilities@1.0.3
93
- - @telia-ace/alliance-framework@1.0.12
94
-
95
- ## 1.0.13-next.0
96
-
97
- ### Patch Changes
98
-
99
- - Updated dependencies [3489aea]
100
- - @telia-ace/alliance-internal-client-utilities@1.0.3-next.0
101
- - @telia-ace/alliance-framework@1.0.12
102
-
103
- ## 1.0.12
104
-
105
- ### Patch Changes
106
-
107
- - 7a0e643: Add support for `getCurrentWorkspace` utility.
108
- - 8763155: Fix `isSystemAdmin()` utility not checking user type correctly.
109
- - 59f0d3f: Move `getTranslator()` to `@telia-ace/alliance-utilities`.
110
- - 59f0d3f: Remove unnecessary scripts.
111
- - 8763155: Update all dependencies to latest.
112
- - 59f0d3f: Add `getCurrentUser`, move `hasPermission` and `isSystemAdmin` into current user object.
113
- - Updated dependencies [59f0d3f]
114
- - Updated dependencies [9191022]
115
- - Updated dependencies [59f0d3f]
116
- - Updated dependencies [8763155]
117
- - Updated dependencies [3e6c397]
118
- - @telia-ace/alliance-framework@1.0.12
119
- - @telia-ace/alliance-internal-client-utilities@1.0.2
120
-
121
- ## 1.0.12-next.4
122
-
123
- ### Patch Changes
124
-
125
- - 7a0e643: Add support for `getCurrentWorkspace` utility.
126
-
127
- ## 1.0.12-next.3
128
-
129
- ### Patch Changes
130
-
131
- - Updated dependencies [3e6c397]
132
- - @telia-ace/alliance-framework@1.0.12-next.3
133
-
134
- ## 1.0.12-next.2
135
-
136
- ### Patch Changes
137
-
138
- - Updated dependencies [9191022]
139
- - @telia-ace/alliance-framework@1.0.12-next.2
140
-
141
- ## 1.0.12-next.1
142
-
143
- ### Patch Changes
144
-
145
- - 59f0d3f: Move `getTranslator()` to `@telia-ace/alliance-utilities`.
146
- - 59f0d3f: Remove unnecessary scripts.
147
- - 59f0d3f: Add `getCurrentUser`, move `hasPermission` and `isSystemAdmin` into current user object.
148
- - Updated dependencies [59f0d3f]
149
- - Updated dependencies [59f0d3f]
150
- - @telia-ace/alliance-framework@1.0.12-next.1
151
- - @telia-ace/alliance-internal-client-utilities@1.0.2-next.0
152
-
153
- ## 1.0.12-next.0
154
-
155
- ### Patch Changes
156
-
157
- - 8763155: Fix `isSystemAdmin()` utility not checking user type correctly.
158
- - 8763155: Update all dependencies to latest.
159
- - Updated dependencies [8763155]
160
- - @telia-ace/alliance-framework@1.0.12-next.0
161
-
162
- ## 1.0.11
163
-
164
- ### Patch Changes
165
-
166
- - fd378fe: Add `hasPermission(appName: string, permissionName: string): Promise<boolean>` and `isSystemAdmin(): Promise<boolean>` utilities.
167
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
168
- - 511ba31: Add translation text for dev server logging flag description.
169
- - 511ba31: Move internal utility `matchRegExpLike` back to framework package.
170
- - fd378fe: Package has been repurposed to export utility functionalities used by various apps.
171
- - Updated dependencies [511ba31]
172
- - Updated dependencies [d646342]
173
- - Updated dependencies [fd378fe]
174
- - Updated dependencies [236e315]
175
- - Updated dependencies [511ba31]
176
- - @telia-ace/alliance-framework@1.0.11
177
- - @telia-ace/alliance-internal-client-utilities@1.0.1
178
-
179
- ## 1.0.11-next.1
180
-
181
- ### Patch Changes
182
-
183
- - fd378fe: Add `hasPermission(appName: string, permissionName: string): Promise<boolean>` and `isSystemAdmin(): Promise<boolean>` utilities.
184
- - fd378fe: Move internal utilities from `@telia-ace/alliance-utilities` to `@telia-ace/alliance-internal-client-utilities` and `@telia-ace/alliance-internal-node-utilities`.
185
- - fd378fe: Package has been repurposed to export utility functionalities used by various apps.
186
- - Updated dependencies [fd378fe]
187
- - @telia-ace/alliance-internal-client-utilities@1.0.1-next.0
188
- - @telia-ace/alliance-framework@1.0.11-next.2
189
-
190
- ## 1.0.11-next.0
191
-
192
- ### Patch Changes
193
-
194
- - 511ba31: Add translation text for dev server logging flag description.
195
- - 511ba31: Move internal utility `matchRegExpLike` back to framework package.
196
-
197
- ## 1.0.10
198
-
199
- ### Patch Changes
200
-
201
- - 1ea5886: Improved handling of URLs.
202
- - 1ea5886: Add `getCurrentLocationInfo()` and `matchRegExpLike()` utility functions.
203
- - 1ea5886: Remove unused translation texts.
204
- - 1ea5886: Add utility types and routing utilities.
205
-
206
- ## 1.0.10-next.3
207
-
208
- ### Patch Changes
209
-
210
- - 2452588: Remove unused translation texts.
211
-
212
- ## 1.0.10-next.2
213
-
214
- ### Patch Changes
215
-
216
- - 1150fac: Improved handling of URLs.
217
-
218
- ## 1.0.10-next.1
219
-
220
- ### Patch Changes
221
-
222
- - c04ce55: Add `getCurrentLocationInfo()` and `matchRegExpLike()` utility functions.
223
-
224
- ## 1.0.10-next.0
225
-
226
- ### Patch Changes
227
-
228
- - cd495d7: Add utility types and routing utilities.
229
-
230
- ## 1.0.9
231
-
232
- ### Patch Changes
233
-
234
- - e04400c: Split utilities into frontend and backend.
235
- - c89a20d: Add Unpacked TypeScript utility.
236
- - 69d2ced: Update all dependencies to latest.
237
-
238
- ## 1.0.9-next.2
239
-
240
- ### Patch Changes
241
-
242
- - 69d2ced: Update all dependencies to latest.
243
-
244
- ## 1.0.9-next.1
245
-
246
- ### Patch Changes
247
-
248
- - c89a20d: Add Unpacked TypeScript utility.
249
-
250
- ## 1.0.9-next.0
251
-
252
- ### Patch Changes
253
-
254
- - e04400c: Split utilities into frontend and backend.
255
-
256
- ## 1.0.8
257
-
258
- ### Patch Changes
259
-
260
- - 3cfe2c7: Change scripts to `<script>:dev|prod|test` for local, production and test environment builds.
261
- - 6f4dfae: Update all dependencies to latest.
262
-
263
- ## 1.0.8-next.1
264
-
265
- ### Patch Changes
266
-
267
- - 6f4dfae: Update all dependencies to latest.
268
-
269
- ## 1.0.8-next.0
270
-
271
- ### Patch Changes
272
-
273
- - 3cfe2c7: Change scripts to `<script>:dev|prod|test` for local, production and test environment builds.
274
-
275
- ## 1.0.7
276
-
277
- ### Patch Changes
278
-
279
- - cc604b0: Relative path support in CSS import vite plugin.
280
- - fea9df3: Update dependencies to latest.
281
-
282
- ## 1.0.7-next.1
283
-
284
- ### Patch Changes
285
-
286
- - cc604b0: Relative path support in CSS import vite plugin.
287
-
288
- ## 1.0.7-next.0
289
-
290
- ### Patch Changes
291
-
292
- - fea9df3: Update dependencies to latest.
293
-
294
- ## 1.0.6
295
-
296
- ### Patch Changes
297
-
298
- - bcb8666: Add new translation text for logging in using dev server.
299
-
300
- ## 1.0.6-next.0
301
-
302
- ### Patch Changes
303
-
304
- - 4c7f3d9: Add new translation text for logging in using dev server.
305
-
306
- ## 1.0.5
307
-
308
- ### Patch Changes
309
-
310
- - c47d82c: Update all deps to latest.
311
-
312
- ## 1.0.5-next.0
313
-
314
- ### Patch Changes
315
-
316
- - 1299e77: Update all deps to latest.
317
-
318
- ## 1.0.4
319
-
320
- ### Patch Changes
321
-
322
- - 20c6d90: Remove unused translation keys.
323
-
324
- ## 1.0.4-next.0
325
-
326
- ### Patch Changes
327
-
328
- - 20c6d90: Remove unused translation keys.
329
-
330
- ## 1.0.3
331
-
332
- ### Patch Changes
333
-
334
- - c1ca5b5: Move translation and text manager to `@telia-ace/alliance-utilities`.
335
- - 9312699: Update dependencies.
336
-
337
- ## 1.0.3-next.1
338
-
339
- ### Patch Changes
340
-
341
- - 9312699: Update dependencies.
342
-
343
- ## 1.0.3-next.0
344
-
345
- ### Patch Changes
346
-
347
- - c1ca5b5: Move translation and text manager to `@telia-ace/alliance-utilities`.
348
-
349
- ## 1.0.2
350
-
351
- ### Patch Changes
352
-
353
- - b23b6b7: Upgrade dependencies.
354
-
355
- ## 1.0.2-next.0
356
-
357
- ### Patch Changes
358
-
359
- - 380d5d0: Upgrade dependencies.
360
-
361
- ## 1.0.1
362
-
363
- ### Patch Changes
364
-
365
- - ddd21be: Update dependencies.
366
-
367
- ## 1.0.1-next.0
368
-
369
- ### Patch Changes
370
-
371
- - d9726c6: Update dependencies.
372
-
373
- ## 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"]}