@telia-ace/alliance-internal-node-utilities 1.0.1 → 1.0.2-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.mjs CHANGED
@@ -1,5 +1,783 @@
1
- import{InjectPinoLogger as S,LoggerModule as b}from"nestjs-pino";export{LoggerErrorInterceptor}from"nestjs-pino";import{sign as x}from"jsonwebtoken";import{HttpStatus as a,Catch as q,HttpException as L,Injectable as P,Module as w}from"@nestjs/common";import{ConfigModule as U,ConfigService as k}from"@nestjs/config";import{createWriteStream as j,createReadStream as H,rmSync as D,renameSync as V}from"node:fs";import{resolve as h,dirname as M,relative as K}from"node:path";import{pipeline as $}from"node:stream/promises";var l=(e=>(e.AuthAuthority="AUTH_AUTHORITY",e.AuthCookieName="AUTH_COOKIE_NAME",e.AuthCookieSecret="AUTH_COOKIE_SECRET",e.DbEndpoint="DB_ENDPOINT",e.JwtPrivateKey="JWT_PRIVATE_KEY",e.ServiceLogLevel="SERVICE_LOG_LEVEL",e.ServicePort="SERVICE_PORT",e))(l||{});function N({privateKey:e,aud:t,sub:s,name:r,user:o,workspace:n}){return`Bearer ${x({iss:"Alliance",aud:t,sub:s,name:r,"https://alliance.teliacompany.net/user_type":o.type,"https://alliance.teliacompany.net/user_privileges":o.permissions,"https://alliance.teliacompany.net/workspace":n.slug,"https://alliance.teliacompany.net/workspace_name":n.name,"https://alliance.teliacompany.net/tenant":n.slug,"https://alliance.teliacompany.net/tenant_name":n.name},e,{expiresIn:"1h",algorithm:"RS256"})}`}function E(e){return`-----BEGIN RSA PRIVATE KEY-----
2
- `+e.getOrThrow(l.JwtPrivateKey)+`
3
- -----END RSA PRIVATE KEY-----`}function W(e){return N({aud:"system",sub:"system",name:"system",workspace:{slug:"system",name:"system"},user:{type:"system",permissions:[]},privateKey:E(e)})}var u=(e=>(e.TargetUrl="alliance-target-url",e.TargetApp="alliance-target-app",e.TargetWorkspace="alliance-target-workspace",e))(u||{}),B=Object.defineProperty,z=Object.getOwnPropertyDescriptor,J=(e,t,s,r)=>{for(var o=r>1?void 0:r?z(t,s):t,n=e.length-1,i;n>=0;n--)(i=e[n])&&(o=(r?i(t,s,o):i(o))||o);return r&&o&&B(t,s,o),o},f=(e=>(e[e.NoMatchingEndpoint=1e4]="NoMatchingEndpoint",e[e.NoObjectId=10001]="NoObjectId",e[e.NoTargetAppHeader=10002]="NoTargetAppHeader",e[e.NoTargetWorkspaceHeader=10003]="NoTargetWorkspaceHeader",e[e.NoManifestsInCache=10004]="NoManifestsInCache",e[e.NoDevSessionInCache=10005]="NoDevSessionInCache",e[e.NoManifest=10006]="NoManifest",e[e.NoRequestContext=10007]="NoRequestContext",e[e.NoUserInRequestContext=10008]="NoUserInRequestContext",e[e.NoAppInRequestContext=10009]="NoAppInRequestContext",e[e.NoWorkspaceInRequestContext=10010]="NoWorkspaceInRequestContext",e[e.NoManifestInRequestContext=10011]="NoManifestInRequestContext",e[e.NoUserPermissionsInRequestContext=10012]="NoUserPermissionsInRequestContext",e))(f||{}),C=(e=>(e[e.NoPublicKey=11e3]="NoPublicKey",e[e.NoAuthHeader=11001]="NoAuthHeader",e))(C||{}),A=(e=>(e[e.NoObjectId=12e3]="NoObjectId",e))(A||{});const Y={[1e4]:{httpCode:a.BAD_REQUEST,message:"Could not find endpoint matching request in app manifest."},[10001]:{httpCode:a.UNAUTHORIZED,message:"No object id available on authenticated user."},[10002]:{httpCode:a.BAD_REQUEST,message:`Request missing header '${u.TargetApp}'.`},[10003]:{httpCode:a.BAD_REQUEST,message:`Request missing header '${u.TargetWorkspace}'.`},[10004]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"App manifests missing in cache."},[10005]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No dev session in memory cache."},[10006]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"Could not find manifest for app '{{appSlug}}'."},[10007]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No request context."},[10008]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No user in request context."},[10009]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No app in request context."},[10010]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No workspace in request context."},[10011]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No manifest in request context."},[10012]:{httpCode:a.INTERNAL_SERVER_ERROR,message:"No user permissions in request context."},[11e3]:{httpCode:a.UNAUTHORIZED,message:"No public key available to decode JWT."},[11001]:{httpCode:a.UNAUTHORIZED,message:"No authorization header found."},[12e3]:{httpCode:a.UNAUTHORIZED,message:"No object id found in user claims."}};function Z(e,t){return Object.entries(t).reduce((s,[r,o])=>s.replaceAll(`{{${r}}}`,o),e)}class I extends L{constructor(t,s={}){const{message:r,httpCode:o}=Y[t];super(Z(r,s),o),this.code=t,this.info=`https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${t}`}}let m=class{catch(e,t){const s=t.switchToHttp().getResponse(),r=e.getStatus();s.status(r).json({httpCode:r,code:e.code,info:e.info,message:e.message})}};m=J([q(I)],m);var G=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,y=(e,t,s,r)=>{for(var o=r>1?void 0:r?Q(t,s):t,n=e.length-1,i;n>=0;n--)(i=e[n])&&(o=(r?i(t,s,o):i(o))||o);return r&&o&&G(t,s,o),o},F=(e,t)=>(s,r)=>t(s,r,e);let c=class{constructor(e){this.logger=e,this.log=(...t)=>this.logger.info(...t),this.trace=(...t)=>this.logger.trace(...t),this.debug=(...t)=>this.logger.debug(...t),this.info=(...t)=>this.logger.info(...t),this.warn=(...t)=>this.logger.warn(...t),this.error=(...t)=>this.logger.error(...t),this.fatal=(...t)=>this.logger.fatal(...t)}};c=y([P(),F(0,S())],c);let g=class{static forRoot({logLevel:e,redact:t=!0}={}){return{module:g,controllers:[],imports:[b.forRootAsync({imports:[U],inject:[k],useFactory:async s=>({pinoHttp:{level:e||s.get(l.ServiceLogLevel)||"silent",redact:t?["authorization","headers.authorization","req.headers.authorization","req.remoteAddress","req.remotePort"]:[],transport:{target:"pino-pretty",options:{colorize:!0,colorizeObjects:!0}}}})})],global:!0,providers:[c],exports:[]}}};g=y([w({providers:[c],exports:[c]})],g);function X(e,t=!1){return{name:"vite-plugin-css-import",apply:"build",enforce:"post",writeBundle:async(s,r)=>{const o=Object.keys(r).filter(p=>p.endsWith(".css"));if(!o.length)return;const n=h(process.cwd(),`${e}-temp.js`),i=h(process.cwd(),`${e}.js`),T=o.reduce((p,R)=>{if(t){const _=M(i),O=K(_,R);return`${p}import "${O.replaceAll("\\","/")}";
4
- `}return`${p}import "./${R}";
5
- `},""),d=j(n);d.write(T,"utf8");const v=H(i);await $(v,d),D(i,{force:!0}),V(n,i),d.end()}}}export{I as AllianceException,m as AllianceExceptionFilter,u as AllianceHeaders,C as DatabasesErrorCodes,f as GatewayErrorCodes,g as LoggerModule,c as LoggerService,A as PortalErrorCodes,l as SharedConfigKeys,N as createBearerToken,W as createSystemUserToken,E as getPrivateKey,X as viteCssImportPlugin};
1
+ import { InjectPinoLogger, LoggerModule as LoggerModule$1 } from 'nestjs-pino';
2
+ export { LoggerErrorInterceptor } from 'nestjs-pino';
3
+ import { auth } from 'express-openid-connect';
4
+ import { sign } from 'jsonwebtoken';
5
+ import { validate } from 'jsonschema';
6
+ import { resolve, dirname, relative } from 'node:path';
7
+ import { readFileSync, writeFileSync, rmSync, existsSync, mkdirSync, createWriteStream, createReadStream, renameSync } from 'node:fs';
8
+ import { HttpStatus, HttpException, Catch, Injectable, Module } from '@nestjs/common';
9
+ import { ConfigModule, ConfigService } from '@nestjs/config';
10
+ import _slugify from 'slugify';
11
+ import { pipeline } from 'node:stream/promises';
12
+
13
+ var SharedConfigKeys = /* @__PURE__ */ ((SharedConfigKeys2) => {
14
+ SharedConfigKeys2["AuthAuthority"] = "AUTH_AUTHORITY";
15
+ SharedConfigKeys2["AuthCookieName"] = "AUTH_COOKIE_NAME";
16
+ SharedConfigKeys2["AuthCookieSecret"] = "AUTH_COOKIE_SECRET";
17
+ SharedConfigKeys2["DbEndpoint"] = "DB_ENDPOINT";
18
+ SharedConfigKeys2["JwtPrivateKey"] = "JWT_PRIVATE_KEY";
19
+ SharedConfigKeys2["ServiceLogLevel"] = "SERVICE_LOG_LEVEL";
20
+ SharedConfigKeys2["ServicePort"] = "SERVICE_PORT";
21
+ return SharedConfigKeys2;
22
+ })(SharedConfigKeys || {});
23
+
24
+ var AllianceHeaders = /* @__PURE__ */ ((AllianceHeaders2) => {
25
+ AllianceHeaders2["TargetUrl"] = "alliance-target-url";
26
+ AllianceHeaders2["TargetApp"] = "alliance-target-app";
27
+ AllianceHeaders2["TargetWorkspace"] = "alliance-target-workspace";
28
+ return AllianceHeaders2;
29
+ })(AllianceHeaders || {});
30
+
31
+ function authMiddleware(configService, {
32
+ baseURL = "https://127.0.0.1",
33
+ clientSecret,
34
+ clientID = " ",
35
+ authRequired = true,
36
+ authorizationParams = {},
37
+ afterCallback
38
+ } = {}) {
39
+ return auth({
40
+ baseURL,
41
+ clientSecret,
42
+ clientID,
43
+ authRequired,
44
+ authorizationParams,
45
+ afterCallback,
46
+ issuerBaseURL: `${configService.getOrThrow(
47
+ SharedConfigKeys.AuthAuthority
48
+ )}/.well-known/openid-configuration`,
49
+ secret: configService.getOrThrow(SharedConfigKeys.AuthCookieSecret),
50
+ session: {
51
+ name: configService.getOrThrow(SharedConfigKeys.AuthCookieName)
52
+ },
53
+ routes: {
54
+ callback: "/signin-oidc"
55
+ }
56
+ });
57
+ }
58
+
59
+ function createBearerToken({
60
+ privateKey,
61
+ aud,
62
+ sub,
63
+ name,
64
+ user,
65
+ workspace
66
+ }) {
67
+ const jwt = sign(
68
+ {
69
+ iss: "Alliance",
70
+ aud,
71
+ sub,
72
+ name,
73
+ "https://alliance.teliacompany.net/user_type": user.type,
74
+ "https://alliance.teliacompany.net/user_privileges": user.permissions,
75
+ "https://alliance.teliacompany.net/workspace": workspace.slug,
76
+ "https://alliance.teliacompany.net/workspace_name": workspace.name,
77
+ "https://alliance.teliacompany.net/tenant": workspace.slug,
78
+ "https://alliance.teliacompany.net/tenant_name": workspace.name
79
+ },
80
+ privateKey,
81
+ {
82
+ expiresIn: "1h",
83
+ algorithm: "RS256"
84
+ }
85
+ );
86
+ return `Bearer ${jwt}`;
87
+ }
88
+ function getPrivateKey(configService) {
89
+ const privateKey = configService.getOrThrow(SharedConfigKeys.JwtPrivateKey);
90
+ return "-----BEGIN RSA PRIVATE KEY-----\n" + privateKey + "\n-----END RSA PRIVATE KEY-----";
91
+ }
92
+ function createSystemUserToken(configService) {
93
+ return createBearerToken({
94
+ aud: "system",
95
+ sub: "system",
96
+ name: "system",
97
+ workspace: {
98
+ slug: "system",
99
+ name: "system"
100
+ },
101
+ user: {
102
+ type: "system",
103
+ permissions: []
104
+ },
105
+ privateKey: getPrivateKey(configService)
106
+ });
107
+ }
108
+
109
+ function generateCookiePolicyHtml(appManifests) {
110
+ const cookiePolicyTableRows = [];
111
+ for (const appName in appManifests) {
112
+ const manifest = appManifests[appName];
113
+ if (!manifest.storage) {
114
+ continue;
115
+ }
116
+ for (const [key, value] of Object.entries(manifest.storage)) {
117
+ const tableRow = createCookiePolicyTableRow(key, value);
118
+ cookiePolicyTableRows.push(tableRow);
119
+ }
120
+ }
121
+ return cookiePolicyHtml.replace("{APP_COOKIES}", cookiePolicyTableRows.join(""));
122
+ }
123
+ function createCookiePolicyTableRow(key, claimEntry) {
124
+ const rows = ["<tr>"];
125
+ const { category, purpose, lifespan } = claimEntry;
126
+ rows.push(`<td>${key}</td>`);
127
+ rows.push(`<td>${category}</td>`);
128
+ rows.push(`<td>${purpose}</td>`);
129
+ rows.push(`<td>${lifespan}</td>`);
130
+ rows.push("</tr>");
131
+ return rows.join("");
132
+ }
133
+ const cookiePolicyHtml = `
134
+ <!DOCTYPE html>
135
+ <html lang="en">
136
+ <head>
137
+ <meta charset="UTF-8" />
138
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
139
+ <title>ACE Alliance - Cookie Policy</title>
140
+ <link
141
+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8X021PBXlK5gJGJWr11GDb3fkW7dPJfaUi3539iARxSUCz4AsERMVpHwDxMTyhq0HftGRbz071bhXfeooXVJvBR4EbgSGgR6Bt9qvArjc/gfZzPoCTDB+AgAAAABJRU5ErkJggg=="
143
+ />
144
+ <style>
145
+ @charset "UTF-8";
146
+ @import 'https://cdn.voca.teliacompany.com/fonts/TeliaSansV10/TeliaSans.css';
147
+ @import 'https://fonts.googleapis.com/css?family=Reenie+Beanie';
148
+
149
+ body {
150
+ font-family: TeliaSans, Helvetica, Arial, Lucida Grande, sans-serif;
151
+ }
152
+
153
+ body > div {
154
+ max-width: 1000px;
155
+ margin: 0 auto;
156
+ padding: 0 40px 40px;
157
+ }
158
+ </style>
159
+ </head>
160
+
161
+ <body>
162
+ <div>
163
+ <h1>Cookie Policy</h1>
164
+ <p>
165
+ On our websites, we use cookies and other similar technologies. You can choose
166
+ whether you want to allow our websites to store cookies on your computer or not. You
167
+ can change your choices at any time.
168
+ </p>
169
+
170
+ <h2>Your consent is required</h2>
171
+ <p>
172
+ You choose whether you want to accept cookies on your device or not. Your consent is
173
+ required for the use of cookies, but not for such cookies that are necessary to
174
+ enable the service that you as a user have requested. If you do not accept our use
175
+ of cookies, or if you have previously approved our use and have changed your mind,
176
+ you can return to your cookie settings at any time and change your choices. You do
177
+ this by clicking on the cookie button/link. You may also need to change the settings
178
+ in your browser and manually delete cookies to clear your device of previously
179
+ stored cookies.
180
+ </p>
181
+
182
+ <h2>What are cookies?</h2>
183
+ <p>
184
+ A cookie is a small text file that is stored on your computer by the web browser
185
+ while browsing a website. When we refer to cookies (\u201Ccookies\u201D) in this policy, other
186
+ similar technologies and tools that retrieve and store information in your browser,
187
+ and in some cases forward such information to third parties, in a manner similar to
188
+ cookies. Examples are pixels, local storage, session storage and fingerprinting.
189
+ </p>
190
+ <p>
191
+ The websites will \u201Cremember\u201D and \u201Crecognize\u201D you. This can be done by placing
192
+ cookies in three different ways;
193
+ </p>
194
+ <ul>
195
+ <li>The session ends, ie until you close the window in your browser.</li>
196
+ <li>
197
+ Time-limited, ie the cookie has a predetermined lifespan. The time may vary
198
+ between different cookies.
199
+ </li>
200
+ <li>
201
+ Until further notice, ie the information remains until you choose to delete it
202
+ yourself. This applies to local storage.
203
+ </li>
204
+ </ul>
205
+ <p>You can always go into your browser and delete already stored cookies yourself.</p>
206
+
207
+ <h3>Third Party Cookies</h3>
208
+ <p>
209
+ We use third-party cookies on our websites. Third-party cookies are stored by
210
+ someone other than the person responsible for the website, in this case by a company
211
+ other than Telia.
212
+ </p>
213
+ <p>
214
+ Telia uses external platforms to communicate digitally, these include the Google
215
+ Marketing Platform and others. The platforms use both first- and third-party cookies
216
+ as well as similar techniques to advertise and follow up the results of the
217
+ advertising.
218
+ </p>
219
+ <p>
220
+ A third-party cookie can be used by several websites to understand and track how you
221
+ browse between different websites. Telia receives information from these cookies,
222
+ but the information can also be used for other purposes determined by third parties.
223
+ Third-party cookies found on our website are covered by each third-party privacy
224
+ policy. Feel free to read these to understand what other purposes the information
225
+ can be used for. Links are in our Cookie Table.
226
+ </p>
227
+ <p>
228
+ For information about which third-party cookies are used on our websites, see our
229
+ Cookie Table. For more information on how Telia handles personal data in connection
230
+ with transfers to third parties, read our Privacy Policy.
231
+ </p>
232
+
233
+ <h2>Cookies on our websites</h2>
234
+ <p>
235
+ In order for you to have better control over which cookies are used on the websites,
236
+ and thus be able to more easily decide how cookies should be used when you visit our
237
+ websites, we have identified four different categories of cookies. These categories
238
+ are defined based on the purposes for the use of the cookies.
239
+ </p>
240
+ <p>
241
+ In our Cookie Table, you can also see which category each cookie belongs to, for
242
+ what purposes it is used and for how long it is active.
243
+ </p>
244
+ <p>
245
+ We have identified the following four categories of cookies. All categories contain
246
+ cookies which means that data is shared with third parties.
247
+ </p>
248
+
249
+ <h3>Necessary</h3>
250
+ <p>
251
+ These cookies are needed for our app to work in a secure and correct way. Necessary
252
+ cookies enable you to use our app and us to provide the service you request.
253
+ Necessary cookies make basic functions of the app possible, for example, identifying
254
+ you when you log into My Telia, detecting repeated failed login attempts,
255
+ identifying where you are in the buying process and remembering the items put into
256
+ your shopping basket.
257
+ </p>
258
+
259
+ <h3>Functionality</h3>
260
+ <p>
261
+ These cookies let us to enable some useful functionalities to make the user
262
+ experience better, for example, to remember your login details and settings.
263
+ </p>
264
+
265
+ <h3>Analytics</h3>
266
+ <p>
267
+ These cookies give us information about how you use our app and allow us to improve
268
+ the user experience.
269
+ </p>
270
+
271
+ <h3>Marketing</h3>
272
+ <p>
273
+ These cookies help us and our partners to display personalized and relevant ads
274
+ based on your browsing behavior on our website and in our app, even when you later
275
+ visit other (third parties\u2019) websites. These cookies are used to evaluate the
276
+ effectiveness of our marketingcampaigns, as well as for targeted marketing and
277
+ profiling, regardless of which device(s) you have used. Information collected for
278
+ this purpose may also be combined with other customer and traffic data we have about
279
+ you, if you have given your consent that we may use your traffic data for marketing
280
+ purpose and have not objected to the use of your customer data for marketing
281
+ purposes.
282
+ </p>
283
+
284
+ <h2>Manage settings</h2>
285
+ <p>
286
+ We save your cookie consent for 12 months. Then we will ask you again. Please note
287
+ that some cookies have a lifespan that exceeds these 12 months. You may therefore
288
+ need to change the settings in your browser and manually delete all cookies.
289
+ </p>
290
+ <p>
291
+ More information on how to turn off cookies can be found in the instructions for
292
+ your browser.
293
+ </p>
294
+ <ul>
295
+ <li>
296
+ <a
297
+ href="https://support.google.com/accounts/answer/61416?co=GENIE.Platform%3DDesktop&amp;hl=en"
298
+ target="_blank"
299
+ rel="noopener noreferrer"
300
+ >Google Chrome</a
301
+ >
302
+ </li>
303
+ <li>
304
+ <a
305
+ href="https://privacy.microsoft.com/en-us/windows-10-microsoft-edge-and-privacy"
306
+ target="_blank"
307
+ rel="noopener noreferrer"
308
+ >Microsoft Edge</a
309
+ >
310
+ </li>
311
+ <li>
312
+ <a
313
+ href="https://support.mozilla.org/en-US/kb/enable-and-disable-cookies-website-preferences"
314
+ target="_blank"
315
+ rel="noopener noreferrer"
316
+ >Mozilla Firefox</a
317
+ >
318
+ </li>
319
+ <li>
320
+ <a
321
+ href="https://support.microsoft.com/en-gb/help/17442/windows-internet-explorer-delete-manage-cookies"
322
+ target="_blank"
323
+ rel="noopener noreferrer"
324
+ >Microsoft Internet Explorer</a
325
+ >
326
+ </li>
327
+ <li>
328
+ <a
329
+ href="https://www.opera.com/help/tutorials/security/privacy/"
330
+ target="_blank"
331
+ rel="noopener noreferrer"
332
+ >Opera</a
333
+ >
334
+ </li>
335
+ <li>
336
+ <a
337
+ href="https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac"
338
+ target="_blank"
339
+ rel="noopener noreferrer"
340
+ >Apple Safari</a
341
+ >
342
+ </li>
343
+ </ul>
344
+
345
+ <h3>Do Not Track-signals</h3>
346
+ <p>
347
+ If you have chosen to turn on the Do Not Track function in your browser, we will not
348
+ automatically place cookies for marketing on your device. You make other choices in
349
+ your cookie settings.
350
+ </p>
351
+
352
+ <h3>If you block cookies</h3>
353
+ <p>
354
+ If you choose not to accept our use of cookies, the functionality and performance of
355
+ our websites may deteriorate as certain functions are dependent on cookies. A
356
+ blocking of cookies can therefore mean that the websites\u2019 services do not work as
357
+ they should.
358
+ </p>
359
+
360
+ <h3>Your security with us</h3>
361
+ <p>
362
+ If you want to read more about your rights and how we protect your privacy, go to
363
+ our privacy policy for
364
+ <a
365
+ href="https://www.telia.se/dam/jcr:df2eeb83-50ce-4383-89fc-0613f7615796/Integritetspolicy-privatkunder.pdf"
366
+ >private customers</a
367
+ >
368
+ (C2B) or
369
+ <a
370
+ href="https://www.telia.se/dam/jcr:95b2b4a5-82ca-436b-90e0-873e0a864118/Telia-integritetspolicy-foretag.pdf"
371
+ >corporate customers</a
372
+ >
373
+ (B2B). You are always welcome to contact us at
374
+ <a href="mailto:dpo-se@teliacompany.com">dpo-se@teliacompany.com</a> if you have any
375
+ questions.
376
+ </p>
377
+ <p>Our cookie policy may change in the future.</p>
378
+ <p>
379
+ More information about cookies can be found at the Swedish Post and Telecom
380
+ Authority (PTS).
381
+ </p>
382
+
383
+ <h2>Our Cookie Table</h2>
384
+ <p>
385
+ Below, you will find a list of the cookies and similar technologies that we use on
386
+ this website. These cookies are stored on your device by us.
387
+ </p>
388
+ <table>
389
+ <thead>
390
+ <tr>
391
+ <th>Cookie</th>
392
+ <th>Category</th>
393
+ <th>Purpose</th>
394
+ <th>Lifespan</th>
395
+ </tr>
396
+ </thead>
397
+ <tbody>
398
+ <tr>
399
+ <td>alliance-session-v1</td>
400
+ <td>necessary</td>
401
+ <td>Contains the authenticated user.</td>
402
+ <td>1 day</td>
403
+ </tr>
404
+ {APP_COOKIES}
405
+ </tbody>
406
+ </table>
407
+ <style>
408
+ table {
409
+ width: 100%;
410
+ border: 1px solid rgba(0, 0, 0, 0.15);
411
+ }
412
+ th, td {
413
+ text-align: left;
414
+ padding: 3px;
415
+ }
416
+ </style>
417
+ </div>
418
+ </body>
419
+ </html>
420
+ `;
421
+
422
+ function getJsonSchemas() {
423
+ const frameworkDistDirPath = resolve(
424
+ process.cwd(),
425
+ "node_modules",
426
+ "@telia-ace/alliance-framework",
427
+ "dist"
428
+ );
429
+ const appConfigSchemaPath = resolve(frameworkDistDirPath, "config.schema.json");
430
+ const appManifestSchemaPath = resolve(frameworkDistDirPath, "manifest.schema.json");
431
+ const appConfigSchemaFile = readFileSync(appConfigSchemaPath).toString();
432
+ const appManifestSchemaFile = readFileSync(appManifestSchemaPath).toString();
433
+ const appConfig = JSON.parse(appConfigSchemaFile);
434
+ const appManifest = JSON.parse(appManifestSchemaFile);
435
+ return {
436
+ appConfig,
437
+ appManifest
438
+ };
439
+ }
440
+
441
+ async function createTempModuleAndImport(moduleString, fileName) {
442
+ const file = resolve(process.cwd(), `${fileName}.mjs`);
443
+ writeFileSync(file, moduleString);
444
+ const importedModule = await import(`file:///${file}`);
445
+ rmSync(file, { force: true });
446
+ return importedModule;
447
+ }
448
+ async function getAppManifests(apps) {
449
+ const moduleStringParts = [];
450
+ const manifestImportVariables = [];
451
+ for (const packageName of apps) {
452
+ const manifestImportVariable = `app${apps.indexOf(packageName)}`;
453
+ manifestImportVariables.push(manifestImportVariable);
454
+ moduleStringParts.push(`import ${manifestImportVariable} from '${packageName}/manifest';`);
455
+ }
456
+ moduleStringParts.push(`export default [${manifestImportVariables.join(", ")}];`);
457
+ const result = await createTempModuleAndImport(
458
+ moduleStringParts.join("\n"),
459
+ "app-manifests"
460
+ );
461
+ return result.default;
462
+ }
463
+
464
+ function getPkgJson() {
465
+ const packageJson = resolve(process.cwd(), "package.json");
466
+ const pkgJsonFile = readFileSync(packageJson).toString();
467
+ return JSON.parse(pkgJsonFile);
468
+ }
469
+ async function getManifests(pkgJson) {
470
+ if (!pkgJson || !pkgJson.alliance || !pkgJson.alliance.apps) {
471
+ throw new Error("Alliance apps not defined in package.json.");
472
+ }
473
+ const manifestArray = await getAppManifests(pkgJson.alliance.apps);
474
+ return manifestArray.reduce((acc, curr) => {
475
+ acc[curr.name] = curr;
476
+ return acc;
477
+ }, {});
478
+ }
479
+
480
+ const PUBLIC_DIR_NAME = "public";
481
+ const MANIFESTS_FILE_NAME = "manifests.json";
482
+ const COOKIE_POLICY_FILE_NAME = "cookie-policy.html";
483
+ const APP_CONFIG_SCHEMA_FILE_NAME = "config.schema.json";
484
+ const APP_MANIFEST_SCHEMA_FILE_NAME = "manifest.schema.json";
485
+ async function createPublicDistributionFiles() {
486
+ const pkgJson = getPkgJson();
487
+ const manifests = await getManifests(pkgJson);
488
+ const schemas = getJsonSchemas();
489
+ for (const appName in manifests) {
490
+ const manifest = manifests[appName];
491
+ const validationResult = validate(manifest, schemas.appManifest);
492
+ if (validationResult.errors.length) {
493
+ const errors = validationResult.errors.map((e) => JSON.stringify(e, null, 2));
494
+ throw new Error(
495
+ `Validation of app manifest for app '${appName}' failed with the following errors:
496
+ ${errors.join(
497
+ "\n"
498
+ )}`
499
+ );
500
+ }
501
+ }
502
+ const publicDirPath = resolve(process.cwd(), PUBLIC_DIR_NAME);
503
+ if (!existsSync(publicDirPath)) {
504
+ mkdirSync(publicDirPath);
505
+ }
506
+ const manifestsFilePath = resolve(publicDirPath, MANIFESTS_FILE_NAME);
507
+ writeFileSync(manifestsFilePath, JSON.stringify(manifests));
508
+ const cookiePolicyFilePath = resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);
509
+ writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));
510
+ const appConfigSchemaFilePath = resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);
511
+ const appManifestSchemaFilePath = resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);
512
+ writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));
513
+ writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));
514
+ }
515
+
516
+ var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
517
+ GatewayErrorCodes2[GatewayErrorCodes2["NoMatchingEndpoint"] = 1e4] = "NoMatchingEndpoint";
518
+ GatewayErrorCodes2[GatewayErrorCodes2["NoObjectId"] = 10001] = "NoObjectId";
519
+ GatewayErrorCodes2[GatewayErrorCodes2["NoTargetAppHeader"] = 10002] = "NoTargetAppHeader";
520
+ GatewayErrorCodes2[GatewayErrorCodes2["NoTargetWorkspaceHeader"] = 10003] = "NoTargetWorkspaceHeader";
521
+ GatewayErrorCodes2[GatewayErrorCodes2["NoManifestsInCache"] = 10004] = "NoManifestsInCache";
522
+ GatewayErrorCodes2[GatewayErrorCodes2["NoDevSessionInCache"] = 10005] = "NoDevSessionInCache";
523
+ GatewayErrorCodes2[GatewayErrorCodes2["NoManifest"] = 10006] = "NoManifest";
524
+ GatewayErrorCodes2[GatewayErrorCodes2["NoRequestContext"] = 10007] = "NoRequestContext";
525
+ GatewayErrorCodes2[GatewayErrorCodes2["NoUserInRequestContext"] = 10008] = "NoUserInRequestContext";
526
+ GatewayErrorCodes2[GatewayErrorCodes2["NoAppInRequestContext"] = 10009] = "NoAppInRequestContext";
527
+ GatewayErrorCodes2[GatewayErrorCodes2["NoWorkspaceInRequestContext"] = 10010] = "NoWorkspaceInRequestContext";
528
+ GatewayErrorCodes2[GatewayErrorCodes2["NoManifestInRequestContext"] = 10011] = "NoManifestInRequestContext";
529
+ GatewayErrorCodes2[GatewayErrorCodes2["NoUserPermissionsInRequestContext"] = 10012] = "NoUserPermissionsInRequestContext";
530
+ return GatewayErrorCodes2;
531
+ })(GatewayErrorCodes || {});
532
+ var DatabasesErrorCodes = /* @__PURE__ */ ((DatabasesErrorCodes2) => {
533
+ DatabasesErrorCodes2[DatabasesErrorCodes2["NoPublicKey"] = 11e3] = "NoPublicKey";
534
+ DatabasesErrorCodes2[DatabasesErrorCodes2["NoAuthHeader"] = 11001] = "NoAuthHeader";
535
+ DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileStore"] = 11002] = "FailedFileStore";
536
+ DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileRead"] = 11003] = "FailedFileRead";
537
+ return DatabasesErrorCodes2;
538
+ })(DatabasesErrorCodes || {});
539
+ var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
540
+ PortalErrorCodes2[PortalErrorCodes2["NoObjectId"] = 12e3] = "NoObjectId";
541
+ return PortalErrorCodes2;
542
+ })(PortalErrorCodes || {});
543
+ const allianceErrors = {
544
+ // gateway
545
+ [1e4 /* NoMatchingEndpoint */]: {
546
+ httpCode: HttpStatus.BAD_REQUEST,
547
+ message: "Could not find endpoint matching request in app manifest."
548
+ },
549
+ [10001 /* NoObjectId */]: {
550
+ httpCode: HttpStatus.UNAUTHORIZED,
551
+ message: "No object id available on authenticated user."
552
+ },
553
+ [10002 /* NoTargetAppHeader */]: {
554
+ httpCode: HttpStatus.BAD_REQUEST,
555
+ message: `Request missing header '${AllianceHeaders.TargetApp}'.`
556
+ },
557
+ [10003 /* NoTargetWorkspaceHeader */]: {
558
+ httpCode: HttpStatus.BAD_REQUEST,
559
+ message: `Request missing header '${AllianceHeaders.TargetWorkspace}'.`
560
+ },
561
+ [10004 /* NoManifestsInCache */]: {
562
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
563
+ message: "App manifests missing in cache."
564
+ },
565
+ [10005 /* NoDevSessionInCache */]: {
566
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
567
+ message: "No dev session in memory cache."
568
+ },
569
+ [10006 /* NoManifest */]: {
570
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
571
+ message: "Could not find manifest for app '{{appSlug}}'."
572
+ },
573
+ [10007 /* NoRequestContext */]: {
574
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
575
+ message: "No request context."
576
+ },
577
+ [10008 /* NoUserInRequestContext */]: {
578
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
579
+ message: "No user in request context."
580
+ },
581
+ [10009 /* NoAppInRequestContext */]: {
582
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
583
+ message: "No app in request context."
584
+ },
585
+ [10010 /* NoWorkspaceInRequestContext */]: {
586
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
587
+ message: "No workspace in request context."
588
+ },
589
+ [10011 /* NoManifestInRequestContext */]: {
590
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
591
+ message: "No manifest in request context."
592
+ },
593
+ [10012 /* NoUserPermissionsInRequestContext */]: {
594
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
595
+ message: "No user permissions in request context."
596
+ },
597
+ // databases
598
+ [11e3 /* NoPublicKey */]: {
599
+ httpCode: HttpStatus.UNAUTHORIZED,
600
+ message: "No public key available to decode JWT."
601
+ },
602
+ [11001 /* NoAuthHeader */]: {
603
+ httpCode: HttpStatus.UNAUTHORIZED,
604
+ message: "No authorization header found."
605
+ },
606
+ [11002 /* FailedFileStore */]: {
607
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
608
+ message: "Error storing file."
609
+ },
610
+ [11003 /* FailedFileRead */]: {
611
+ httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
612
+ message: "Error reading file."
613
+ },
614
+ // portal
615
+ [12e3 /* NoObjectId */]: {
616
+ httpCode: HttpStatus.UNAUTHORIZED,
617
+ message: "No object id found in user claims."
618
+ }
619
+ };
620
+
621
+ function parseTemplates(message, variables) {
622
+ return Object.entries(variables).reduce((acc, [key, value]) => {
623
+ return acc.replaceAll(`{{${key}}}`, value);
624
+ }, message);
625
+ }
626
+ class AllianceException extends HttpException {
627
+ constructor(code, variables = {}) {
628
+ const { message, httpCode } = allianceErrors[code];
629
+ super(parseTemplates(message, variables), httpCode);
630
+ this.code = code;
631
+ this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
632
+ }
633
+ }
634
+
635
+ var __defProp$2 = Object.defineProperty;
636
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
637
+ var __decorateClass$2 = (decorators, target, key, kind) => {
638
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
639
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
640
+ if (decorator = decorators[i])
641
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
642
+ if (kind && result)
643
+ __defProp$2(target, key, result);
644
+ return result;
645
+ };
646
+ let AllianceExceptionFilter = class {
647
+ catch(exception, host) {
648
+ const ctx = host.switchToHttp();
649
+ const response = ctx.getResponse();
650
+ const status = exception.getStatus();
651
+ response.status && response.status(status).json({
652
+ httpCode: status,
653
+ code: exception.code,
654
+ info: exception.info,
655
+ message: exception.message
656
+ });
657
+ }
658
+ };
659
+ AllianceExceptionFilter = __decorateClass$2([
660
+ Catch(AllianceException)
661
+ ], AllianceExceptionFilter);
662
+
663
+ var __defProp$1 = Object.defineProperty;
664
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
665
+ var __decorateClass$1 = (decorators, target, key, kind) => {
666
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
667
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
668
+ if (decorator = decorators[i])
669
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
670
+ if (kind && result)
671
+ __defProp$1(target, key, result);
672
+ return result;
673
+ };
674
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
675
+ let LoggerService = class {
676
+ constructor(logger) {
677
+ this.logger = logger;
678
+ this.log = (...args) => this.logger.info(...args);
679
+ this.trace = (...args) => this.logger.trace(...args);
680
+ this.debug = (...args) => this.logger.debug(...args);
681
+ this.info = (...args) => this.logger.info(...args);
682
+ this.warn = (...args) => this.logger.warn(...args);
683
+ this.error = (...args) => this.logger.error(...args);
684
+ this.fatal = (...args) => this.logger.fatal(...args);
685
+ }
686
+ };
687
+ LoggerService = __decorateClass$1([
688
+ Injectable(),
689
+ __decorateParam(0, InjectPinoLogger())
690
+ ], LoggerService);
691
+
692
+ var __defProp = Object.defineProperty;
693
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
694
+ var __decorateClass = (decorators, target, key, kind) => {
695
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
696
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
697
+ if (decorator = decorators[i])
698
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
699
+ if (kind && result)
700
+ __defProp(target, key, result);
701
+ return result;
702
+ };
703
+ let LoggerModule = class {
704
+ static forRoot({ logLevel, redact = true } = {}) {
705
+ return {
706
+ module: LoggerModule,
707
+ controllers: [],
708
+ imports: [
709
+ LoggerModule$1.forRootAsync({
710
+ imports: [ConfigModule],
711
+ inject: [ConfigService],
712
+ useFactory: async (configService) => ({
713
+ pinoHttp: {
714
+ level: logLevel || configService.get(SharedConfigKeys.ServiceLogLevel) || "silent",
715
+ redact: redact ? [
716
+ "authorization",
717
+ "headers.authorization",
718
+ "req.headers.authorization",
719
+ "req.remoteAddress",
720
+ "req.remotePort"
721
+ ] : [],
722
+ transport: {
723
+ target: "pino-pretty",
724
+ options: {
725
+ colorize: true,
726
+ colorizeObjects: true
727
+ }
728
+ }
729
+ }
730
+ })
731
+ })
732
+ ],
733
+ global: true,
734
+ providers: [LoggerService],
735
+ exports: []
736
+ };
737
+ }
738
+ };
739
+ LoggerModule = __decorateClass([
740
+ Module({
741
+ providers: [LoggerService],
742
+ exports: [LoggerService]
743
+ })
744
+ ], LoggerModule);
745
+
746
+ function slugify(name) {
747
+ return _slugify(name, { strict: true, replacement: "-", lower: true });
748
+ }
749
+
750
+ function viteCssImportPlugin(outFilePath, relativePath = false) {
751
+ return {
752
+ name: "vite-plugin-css-import",
753
+ apply: "build",
754
+ enforce: "post",
755
+ writeBundle: async (_, bundle) => {
756
+ const cssFiles = Object.keys(bundle).filter((fileName) => fileName.endsWith(".css"));
757
+ if (!cssFiles.length) {
758
+ return;
759
+ }
760
+ const tempTargetFilePath = resolve(process.cwd(), `${outFilePath}-temp.js`);
761
+ const targetFilePath = resolve(process.cwd(), `${outFilePath}.js`);
762
+ const cssImportStatement = cssFiles.reduce((acc, cssFile) => {
763
+ if (relativePath) {
764
+ const targetDirname = dirname(targetFilePath);
765
+ const relativePath2 = relative(targetDirname, cssFile);
766
+ return `${acc}import "${relativePath2.replaceAll("\\", "/")}";
767
+ `;
768
+ }
769
+ return `${acc}import "./${cssFile}";
770
+ `;
771
+ }, "");
772
+ const writeStream = createWriteStream(tempTargetFilePath);
773
+ writeStream.write(cssImportStatement, "utf8");
774
+ const readStream = createReadStream(targetFilePath);
775
+ await pipeline(readStream, writeStream);
776
+ rmSync(targetFilePath, { force: true });
777
+ renameSync(tempTargetFilePath, targetFilePath);
778
+ writeStream.end();
779
+ }
780
+ };
781
+ }
782
+
783
+ export { AllianceException, AllianceExceptionFilter, AllianceHeaders, DatabasesErrorCodes, GatewayErrorCodes, LoggerModule, LoggerService, PortalErrorCodes, SharedConfigKeys, authMiddleware, createBearerToken, createPublicDistributionFiles, createSystemUserToken, getAppManifests, getPrivateKey, slugify, viteCssImportPlugin };