@telia-ace/alliance-internal-node-utilities 1.0.3-next.4 → 1.0.4-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.cjs CHANGED
@@ -1,25 +1,201 @@
1
1
  'use strict';
2
2
 
3
- const nestjsPino = require('nestjs-pino');
4
- const RedisStore = require('connect-redis');
5
- const expressOpenidConnect = require('express-openid-connect');
6
- const redis = require('redis');
7
- const jsonwebtoken = require('jsonwebtoken');
8
- const jsonschema = require('jsonschema');
9
- const node_path = require('node:path');
10
- const node_fs = require('node:fs');
11
- const graphql = require('graphql');
12
- const common = require('@nestjs/common');
13
- const config = require('@nestjs/config');
14
- const _slugify = require('slugify');
15
- const promises = require('node:stream/promises');
3
+ var nestjsPino = require('nestjs-pino');
4
+ var expressSession = require('express-session');
5
+ var expressOpenidConnect = require('express-openid-connect');
6
+ var redis = require('redis');
7
+ var jsonwebtoken = require('jsonwebtoken');
8
+ var jsonschema = require('jsonschema');
9
+ var fs = require('fs');
10
+ var path = require('path');
11
+ var graphql = require('graphql');
12
+ var common = require('@nestjs/common');
13
+ var config = require('@nestjs/config');
14
+ var _slugify = require('slugify');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
17
+
18
+ var _slugify__default = /*#__PURE__*/_interopDefault(_slugify);
16
19
 
17
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
18
-
19
- const RedisStore__default = /*#__PURE__*/_interopDefaultCompat(RedisStore);
20
- const _slugify__default = /*#__PURE__*/_interopDefaultCompat(_slugify);
20
+ var __defProp = Object.defineProperty;
21
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
22
+ var noop = /* @__PURE__ */ __name((_err, _data) => {
23
+ }, "noop");
24
+ var RedisStore = class RedisStore2 extends expressSession.Store {
25
+ static {
26
+ __name(this, "RedisStore");
27
+ }
28
+ constructor(opts) {
29
+ super();
30
+ this.prefix = opts.prefix == null ? "sess:" : opts.prefix;
31
+ this.scanCount = opts.scanCount || 100;
32
+ this.serializer = opts.serializer || JSON;
33
+ this.ttl = opts.ttl || 86400;
34
+ this.disableTTL = opts.disableTTL || false;
35
+ this.disableTouch = opts.disableTouch || false;
36
+ this.client = this.normalizeClient(opts.client);
37
+ }
38
+ // Create a redis and ioredis compatible client
39
+ normalizeClient(client) {
40
+ let isRedis = "scanIterator" in client;
41
+ return {
42
+ get: (key) => client.get(key),
43
+ set: (key, val, ttl) => {
44
+ if (ttl) {
45
+ return isRedis ? client.set(key, val, {
46
+ EX: ttl
47
+ }) : client.set(key, val, "EX", ttl);
48
+ }
49
+ return client.set(key, val);
50
+ },
51
+ del: (key) => client.del(key),
52
+ expire: (key, ttl) => client.expire(key, ttl),
53
+ mget: (keys) => isRedis ? client.mGet(keys) : client.mget(keys),
54
+ scanIterator: (match, count) => {
55
+ if (isRedis)
56
+ return client.scanIterator({
57
+ MATCH: match,
58
+ COUNT: count
59
+ });
60
+ return async function* () {
61
+ let [c, xs] = await client.scan("0", "MATCH", match, "COUNT", count);
62
+ for (let key of xs)
63
+ yield key;
64
+ while (c !== "0") {
65
+ [c, xs] = await client.scan(c, "MATCH", match, "COUNT", count);
66
+ for (let key of xs)
67
+ yield key;
68
+ }
69
+ }();
70
+ }
71
+ };
72
+ }
73
+ async get(sid, cb = noop) {
74
+ let key = this.prefix + sid;
75
+ try {
76
+ let data = await this.client.get(key);
77
+ if (!data)
78
+ return cb();
79
+ return cb(null, await this.serializer.parse(data));
80
+ } catch (err) {
81
+ return cb(err);
82
+ }
83
+ }
84
+ async set(sid, sess, cb = noop) {
85
+ let key = this.prefix + sid;
86
+ let ttl = this._getTTL(sess);
87
+ try {
88
+ let val = this.serializer.stringify(sess);
89
+ if (ttl > 0) {
90
+ if (this.disableTTL)
91
+ await this.client.set(key, val);
92
+ else
93
+ await this.client.set(key, val, ttl);
94
+ return cb();
95
+ } else {
96
+ return this.destroy(sid, cb);
97
+ }
98
+ } catch (err) {
99
+ return cb(err);
100
+ }
101
+ }
102
+ async touch(sid, sess, cb = noop) {
103
+ let key = this.prefix + sid;
104
+ if (this.disableTouch || this.disableTTL)
105
+ return cb();
106
+ try {
107
+ await this.client.expire(key, this._getTTL(sess));
108
+ return cb();
109
+ } catch (err) {
110
+ return cb(err);
111
+ }
112
+ }
113
+ async destroy(sid, cb = noop) {
114
+ let key = this.prefix + sid;
115
+ try {
116
+ await this.client.del([
117
+ key
118
+ ]);
119
+ return cb();
120
+ } catch (err) {
121
+ return cb(err);
122
+ }
123
+ }
124
+ async clear(cb = noop) {
125
+ try {
126
+ let keys = await this._getAllKeys();
127
+ if (!keys.length)
128
+ return cb();
129
+ await this.client.del(keys);
130
+ return cb();
131
+ } catch (err) {
132
+ return cb(err);
133
+ }
134
+ }
135
+ async length(cb = noop) {
136
+ try {
137
+ let keys = await this._getAllKeys();
138
+ return cb(null, keys.length);
139
+ } catch (err) {
140
+ return cb(err);
141
+ }
142
+ }
143
+ async ids(cb = noop) {
144
+ let len = this.prefix.length;
145
+ try {
146
+ let keys = await this._getAllKeys();
147
+ return cb(null, keys.map((k) => k.substring(len)));
148
+ } catch (err) {
149
+ return cb(err);
150
+ }
151
+ }
152
+ async all(cb = noop) {
153
+ let len = this.prefix.length;
154
+ try {
155
+ let keys = await this._getAllKeys();
156
+ if (keys.length === 0)
157
+ return cb(null, []);
158
+ let data = await this.client.mget(keys);
159
+ let results = data.reduce((acc, raw, idx) => {
160
+ if (!raw)
161
+ return acc;
162
+ let sess = this.serializer.parse(raw);
163
+ sess.id = keys[idx].substring(len);
164
+ acc.push(sess);
165
+ return acc;
166
+ }, []);
167
+ return cb(null, results);
168
+ } catch (err) {
169
+ return cb(err);
170
+ }
171
+ }
172
+ _getTTL(sess) {
173
+ if (typeof this.ttl === "function") {
174
+ return this.ttl(sess);
175
+ }
176
+ let ttl;
177
+ if (sess && sess.cookie && sess.cookie.expires) {
178
+ let ms = Number(new Date(sess.cookie.expires)) - Date.now();
179
+ ttl = Math.ceil(ms / 1e3);
180
+ } else {
181
+ ttl = this.ttl;
182
+ }
183
+ return ttl;
184
+ }
185
+ async _getAllKeys() {
186
+ let pattern = this.prefix + "*";
187
+ let keys = [];
188
+ for await (let key of this.client.scanIterator(pattern, this.scanCount)) {
189
+ keys.push(key);
190
+ }
191
+ return keys;
192
+ }
193
+ };
194
+ var esm_default = RedisStore;
21
195
 
22
- var SharedConfigKeys = /* @__PURE__ */ ((SharedConfigKeys2) => {
196
+ // src/constants/config.ts
197
+ exports.SharedConfigKeys = void 0;
198
+ (function(SharedConfigKeys2) {
23
199
  SharedConfigKeys2["AuthCookieName"] = "AUTH_COOKIE_NAME";
24
200
  SharedConfigKeys2["AuthCookieSecret"] = "AUTH_COOKIE_SECRET";
25
201
  SharedConfigKeys2["DbEndpoint"] = "DB_ENDPOINT";
@@ -28,33 +204,30 @@ var SharedConfigKeys = /* @__PURE__ */ ((SharedConfigKeys2) => {
28
204
  SharedConfigKeys2["ServicePort"] = "SERVICE_PORT";
29
205
  SharedConfigKeys2["RedisHost"] = "REDIS_HOST";
30
206
  SharedConfigKeys2["RedisPassword"] = "REDIS_PASSWORD";
31
- return SharedConfigKeys2;
32
- })(SharedConfigKeys || {});
207
+ })(exports.SharedConfigKeys || (exports.SharedConfigKeys = {}));
33
208
 
34
- var AllianceHeaders = /* @__PURE__ */ ((AllianceHeaders2) => {
209
+ // src/constants/headers.ts
210
+ exports.AllianceHeaders = void 0;
211
+ (function(AllianceHeaders2) {
35
212
  AllianceHeaders2["TargetUrl"] = "alliance-target-url";
36
213
  AllianceHeaders2["TargetApp"] = "alliance-target-app";
37
214
  AllianceHeaders2["TargetWorkspace"] = "alliance-target-workspace";
38
- return AllianceHeaders2;
39
- })(AllianceHeaders || {});
40
-
41
- function authMiddleware(configService, {
42
- baseURL = "https://127.0.0.1",
43
- clientSecret,
44
- clientID = " ",
45
- authRequired = true,
46
- authorizationParams = {},
47
- afterCallback,
48
- issuerBaseURL = "https://127.0.0.1"
49
- } = {}) {
50
- const redisClient = redis.createClient({
51
- url: configService.getOrThrow(SharedConfigKeys.RedisHost),
52
- password: configService.get(SharedConfigKeys.RedisPassword)
53
- });
54
- redisClient.connect().catch(console.error);
55
- const redisStore = new RedisStore__default({
56
- client: redisClient
57
- });
215
+ })(exports.AllianceHeaders || (exports.AllianceHeaders = {}));
216
+
217
+ // src/auth/auth.middleware.ts
218
+ function authMiddleware(configService, { baseURL = "https://127.0.0.1", clientSecret, clientID = " ", authRequired = true, authorizationParams = {}, afterCallback, issuerBaseURL = "https://127.0.0.1", sessionCookiePath } = {}) {
219
+ let store;
220
+ const redisHostUrl = configService.get(exports.SharedConfigKeys.RedisHost);
221
+ if (redisHostUrl) {
222
+ const redisClient = redis.createClient({
223
+ url: configService.getOrThrow(exports.SharedConfigKeys.RedisHost),
224
+ password: configService.get(exports.SharedConfigKeys.RedisPassword)
225
+ });
226
+ redisClient.connect().catch(console.error);
227
+ store = new esm_default({
228
+ client: redisClient
229
+ });
230
+ }
58
231
  return expressOpenidConnect.auth({
59
232
  baseURL,
60
233
  clientSecret,
@@ -63,50 +236,45 @@ function authMiddleware(configService, {
63
236
  authorizationParams,
64
237
  afterCallback,
65
238
  issuerBaseURL,
66
- secret: configService.getOrThrow(SharedConfigKeys.AuthCookieSecret),
239
+ secret: configService.getOrThrow(exports.SharedConfigKeys.AuthCookieSecret),
67
240
  session: {
68
- name: configService.getOrThrow(SharedConfigKeys.AuthCookieName),
69
- store: redisStore
241
+ name: configService.getOrThrow(exports.SharedConfigKeys.AuthCookieName),
242
+ // @ts-ignore
243
+ store,
244
+ cookie: {
245
+ path: sessionCookiePath
246
+ }
70
247
  },
71
248
  routes: {
72
249
  callback: "/signin-oidc"
73
250
  }
74
251
  });
75
252
  }
76
-
77
- function createBearerToken({
78
- privateKey,
79
- aud,
80
- sub,
81
- name,
82
- user,
83
- workspace
84
- }) {
85
- const jwt = jsonwebtoken.sign(
86
- {
87
- iss: "Alliance",
88
- aud,
89
- sub,
90
- name,
91
- "https://alliance.teliacompany.net/user_type": user.type,
92
- "https://alliance.teliacompany.net/user_privileges": user.permissions,
93
- "https://alliance.teliacompany.net/workspace": workspace.slug,
94
- "https://alliance.teliacompany.net/workspace_name": workspace.name,
95
- "https://alliance.teliacompany.net/tenant": workspace.slug,
96
- "https://alliance.teliacompany.net/tenant_name": workspace.name
97
- },
98
- privateKey,
99
- {
100
- expiresIn: "1h",
101
- algorithm: "RS256"
102
- }
103
- );
253
+ __name(authMiddleware, "authMiddleware");
254
+ function createBearerToken({ privateKey, aud, sub, name, user, workspace }) {
255
+ const jwt = jsonwebtoken.sign({
256
+ iss: "Alliance",
257
+ aud,
258
+ sub,
259
+ name,
260
+ "https://alliance.teliacompany.net/user_type": user.type,
261
+ "https://alliance.teliacompany.net/user_privileges": user.permissions,
262
+ "https://alliance.teliacompany.net/workspace": workspace.slug,
263
+ "https://alliance.teliacompany.net/workspace_name": workspace.name,
264
+ "https://alliance.teliacompany.net/tenant": workspace.slug,
265
+ "https://alliance.teliacompany.net/tenant_name": workspace.name
266
+ }, privateKey, {
267
+ expiresIn: "1h",
268
+ algorithm: "RS256"
269
+ });
104
270
  return `Bearer ${jwt}`;
105
271
  }
272
+ __name(createBearerToken, "createBearerToken");
106
273
  function getPrivateKey(configService) {
107
- const privateKey = configService.getOrThrow(SharedConfigKeys.JwtPrivateKey);
274
+ const privateKey = configService.getOrThrow(exports.SharedConfigKeys.JwtPrivateKey);
108
275
  return "-----BEGIN RSA PRIVATE KEY-----\n" + privateKey + "\n-----END RSA PRIVATE KEY-----";
109
276
  }
277
+ __name(getPrivateKey, "getPrivateKey");
110
278
  function createSystemUserToken(configService) {
111
279
  return createBearerToken({
112
280
  aud: "system",
@@ -123,7 +291,9 @@ function createSystemUserToken(configService) {
123
291
  privateKey: getPrivateKey(configService)
124
292
  });
125
293
  }
294
+ __name(createSystemUserToken, "createSystemUserToken");
126
295
 
296
+ // src/distribution/cookie-policy.ts
127
297
  function generateCookiePolicyHtml(appManifests) {
128
298
  const cookiePolicyTableRows = [];
129
299
  for (const appName in appManifests) {
@@ -138,8 +308,11 @@ function generateCookiePolicyHtml(appManifests) {
138
308
  }
139
309
  return cookiePolicyHtml.replace("{APP_COOKIES}", cookiePolicyTableRows.join(""));
140
310
  }
311
+ __name(generateCookiePolicyHtml, "generateCookiePolicyHtml");
141
312
  function createCookiePolicyTableRow(key, claimEntry) {
142
- const rows = ["<tr>"];
313
+ const rows = [
314
+ "<tr>"
315
+ ];
143
316
  const { category, purpose, lifespan } = claimEntry;
144
317
  rows.push(`<td>${key}</td>`);
145
318
  rows.push(`<td>${category}</td>`);
@@ -148,7 +321,8 @@ function createCookiePolicyTableRow(key, claimEntry) {
148
321
  rows.push("</tr>");
149
322
  return rows.join("");
150
323
  }
151
- const cookiePolicyHtml = `
324
+ __name(createCookiePolicyTableRow, "createCookiePolicyTableRow");
325
+ var cookiePolicyHtml = `
152
326
  <!DOCTYPE html>
153
327
  <html lang="en">
154
328
  <head>
@@ -436,18 +610,12 @@ const cookiePolicyHtml = `
436
610
  </body>
437
611
  </html>
438
612
  `;
439
-
440
613
  function getJsonSchemas() {
441
- const frameworkDistDirPath = node_path.resolve(
442
- process.cwd(),
443
- "node_modules",
444
- "@telia-ace/alliance-framework",
445
- "dist"
446
- );
447
- const appConfigSchemaPath = node_path.resolve(frameworkDistDirPath, "config.schema.json");
448
- const appManifestSchemaPath = node_path.resolve(frameworkDistDirPath, "manifest.schema.json");
449
- const appConfigSchemaFile = node_fs.readFileSync(appConfigSchemaPath).toString();
450
- const appManifestSchemaFile = node_fs.readFileSync(appManifestSchemaPath).toString();
614
+ const frameworkDistDirPath = path.resolve(process.cwd(), "node_modules", "@telia-ace/alliance-framework", "dist");
615
+ const appConfigSchemaPath = path.resolve(frameworkDistDirPath, "config.schema.json");
616
+ const appManifestSchemaPath = path.resolve(frameworkDistDirPath, "manifest.schema.json");
617
+ const appConfigSchemaFile = fs.readFileSync(appConfigSchemaPath).toString();
618
+ const appManifestSchemaFile = fs.readFileSync(appManifestSchemaPath).toString();
451
619
  const appConfig = JSON.parse(appConfigSchemaFile);
452
620
  const appManifest = JSON.parse(appManifestSchemaFile);
453
621
  return {
@@ -455,14 +623,17 @@ function getJsonSchemas() {
455
623
  appManifest
456
624
  };
457
625
  }
458
-
626
+ __name(getJsonSchemas, "getJsonSchemas");
459
627
  async function createTempModuleAndImport(moduleString, fileName) {
460
- const file = node_path.resolve(process.cwd(), `${fileName}.mjs`);
461
- node_fs.writeFileSync(file, moduleString);
628
+ const file = path.resolve(process.cwd(), `${fileName}.mjs`);
629
+ fs.writeFileSync(file, moduleString);
462
630
  const importedModule = await import(`file:///${file}`);
463
- node_fs.rmSync(file, { force: true });
631
+ fs.rmSync(file, {
632
+ force: true
633
+ });
464
634
  return importedModule;
465
635
  }
636
+ __name(createTempModuleAndImport, "createTempModuleAndImport");
466
637
  async function getAppManifests(apps) {
467
638
  const moduleStringParts = [];
468
639
  const manifestImportVariables = [];
@@ -472,18 +643,18 @@ async function getAppManifests(apps) {
472
643
  moduleStringParts.push(`import ${manifestImportVariable} from '${packageName}/manifest';`);
473
644
  }
474
645
  moduleStringParts.push(`export default [${manifestImportVariables.join(", ")}];`);
475
- const result = await createTempModuleAndImport(
476
- moduleStringParts.join("\n"),
477
- "app-manifests"
478
- );
646
+ const result = await createTempModuleAndImport(moduleStringParts.join("\n"), "app-manifests");
479
647
  return result.default;
480
648
  }
649
+ __name(getAppManifests, "getAppManifests");
481
650
 
651
+ // src/distribution/pkg-json.ts
482
652
  function getPkgJson() {
483
- const packageJson = node_path.resolve(process.cwd(), "package.json");
484
- const pkgJsonFile = node_fs.readFileSync(packageJson).toString();
653
+ const packageJson = path.resolve(process.cwd(), "package.json");
654
+ const pkgJsonFile = fs.readFileSync(packageJson).toString();
485
655
  return JSON.parse(pkgJsonFile);
486
656
  }
657
+ __name(getPkgJson, "getPkgJson");
487
658
  async function getManifests(pkgJson) {
488
659
  if (!pkgJson || !pkgJson.alliance || !pkgJson.alliance.apps) {
489
660
  throw new Error("Alliance apps not defined in package.json.");
@@ -494,12 +665,14 @@ async function getManifests(pkgJson) {
494
665
  return acc;
495
666
  }, {});
496
667
  }
497
-
498
- const PUBLIC_DIR_NAME = "public";
499
- const MANIFESTS_FILE_NAME = "manifests.json";
500
- const COOKIE_POLICY_FILE_NAME = "cookie-policy.html";
501
- const APP_CONFIG_SCHEMA_FILE_NAME = "config.schema.json";
502
- const APP_MANIFEST_SCHEMA_FILE_NAME = "manifest.schema.json";
668
+ __name(getManifests, "getManifests");
669
+
670
+ // src/distribution/create-public-files.ts
671
+ var PUBLIC_DIR_NAME = "public";
672
+ var MANIFESTS_FILE_NAME = "manifests.json";
673
+ var COOKIE_POLICY_FILE_NAME = "cookie-policy.html";
674
+ var APP_CONFIG_SCHEMA_FILE_NAME = "config.schema.json";
675
+ var APP_MANIFEST_SCHEMA_FILE_NAME = "manifest.schema.json";
503
676
  async function createPublicDistributionFiles() {
504
677
  const pkgJson = getPkgJson();
505
678
  const manifests = await getManifests(pkgJson);
@@ -509,29 +682,26 @@ async function createPublicDistributionFiles() {
509
682
  const validationResult = jsonschema.validate(manifest, schemas.appManifest);
510
683
  if (validationResult.errors.length) {
511
684
  const errors = validationResult.errors.map((e) => JSON.stringify(e, null, 2));
512
- throw new Error(
513
- `Validation of app manifest for app '${appName}' failed with the following errors:
514
- ${errors.join(
515
- "\n"
516
- )}`
517
- );
685
+ throw new Error(`Validation of app manifest for app '${appName}' failed with the following errors:
686
+ ${errors.join("\n")}`);
518
687
  }
519
688
  }
520
- const publicDirPath = node_path.resolve(process.cwd(), PUBLIC_DIR_NAME);
521
- if (!node_fs.existsSync(publicDirPath)) {
522
- node_fs.mkdirSync(publicDirPath);
689
+ const publicDirPath = path.resolve(process.cwd(), PUBLIC_DIR_NAME);
690
+ if (!fs.existsSync(publicDirPath)) {
691
+ fs.mkdirSync(publicDirPath);
523
692
  }
524
- const manifestsFilePath = node_path.resolve(publicDirPath, MANIFESTS_FILE_NAME);
525
- node_fs.writeFileSync(manifestsFilePath, JSON.stringify(manifests));
526
- const cookiePolicyFilePath = node_path.resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);
527
- node_fs.writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));
528
- const appConfigSchemaFilePath = node_path.resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);
529
- const appManifestSchemaFilePath = node_path.resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);
530
- node_fs.writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));
531
- node_fs.writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));
693
+ const manifestsFilePath = path.resolve(publicDirPath, MANIFESTS_FILE_NAME);
694
+ fs.writeFileSync(manifestsFilePath, JSON.stringify(manifests));
695
+ const cookiePolicyFilePath = path.resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);
696
+ fs.writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));
697
+ const appConfigSchemaFilePath = path.resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);
698
+ const appManifestSchemaFilePath = path.resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);
699
+ fs.writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));
700
+ fs.writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));
532
701
  }
533
-
534
- var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
702
+ __name(createPublicDistributionFiles, "createPublicDistributionFiles");
703
+ exports.GatewayErrorCodes = void 0;
704
+ (function(GatewayErrorCodes2) {
535
705
  GatewayErrorCodes2[GatewayErrorCodes2["NoObjectId"] = 10001] = "NoObjectId";
536
706
  GatewayErrorCodes2[GatewayErrorCodes2["NoTargetAppHeader"] = 10002] = "NoTargetAppHeader";
537
707
  GatewayErrorCodes2[GatewayErrorCodes2["NoTargetWorkspaceHeader"] = 10003] = "NoTargetWorkspaceHeader";
@@ -544,145 +714,158 @@ var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
544
714
  GatewayErrorCodes2[GatewayErrorCodes2["NoWorkspaceInRequestContext"] = 10010] = "NoWorkspaceInRequestContext";
545
715
  GatewayErrorCodes2[GatewayErrorCodes2["NoUserPermissionsInRequestContext"] = 10012] = "NoUserPermissionsInRequestContext";
546
716
  GatewayErrorCodes2[GatewayErrorCodes2["WorkspacePermissionDenied"] = 10013] = "WorkspacePermissionDenied";
547
- return GatewayErrorCodes2;
548
- })(GatewayErrorCodes || {});
549
- var DatabasesErrorCodes = /* @__PURE__ */ ((DatabasesErrorCodes2) => {
717
+ })(exports.GatewayErrorCodes || (exports.GatewayErrorCodes = {}));
718
+ exports.DatabasesErrorCodes = void 0;
719
+ (function(DatabasesErrorCodes2) {
550
720
  DatabasesErrorCodes2[DatabasesErrorCodes2["NoPublicKey"] = 11e3] = "NoPublicKey";
551
721
  DatabasesErrorCodes2[DatabasesErrorCodes2["NoAuthHeader"] = 11001] = "NoAuthHeader";
552
722
  DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileStore"] = 11002] = "FailedFileStore";
553
723
  DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileRead"] = 11003] = "FailedFileRead";
554
724
  DatabasesErrorCodes2[DatabasesErrorCodes2["NoRecord"] = 11004] = "NoRecord";
555
725
  DatabasesErrorCodes2[DatabasesErrorCodes2["UniqueConstrain"] = 11005] = "UniqueConstrain";
556
- return DatabasesErrorCodes2;
557
- })(DatabasesErrorCodes || {});
558
- var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
726
+ })(exports.DatabasesErrorCodes || (exports.DatabasesErrorCodes = {}));
727
+ exports.PortalErrorCodes = void 0;
728
+ (function(PortalErrorCodes2) {
559
729
  PortalErrorCodes2[PortalErrorCodes2["NoObjectId"] = 12e3] = "NoObjectId";
560
- return PortalErrorCodes2;
561
- })(PortalErrorCodes || {});
562
- const allianceErrors = {
730
+ })(exports.PortalErrorCodes || (exports.PortalErrorCodes = {}));
731
+ var allianceErrors = {
563
732
  // gateway
564
- [10001 /* NoObjectId */]: {
733
+ [10001]: {
565
734
  httpCode: common.HttpStatus.UNAUTHORIZED,
566
735
  message: "No object id available on authenticated user."
567
736
  },
568
- [10002 /* NoTargetAppHeader */]: {
737
+ [10002]: {
569
738
  httpCode: common.HttpStatus.BAD_REQUEST,
570
- message: `Request missing header '${AllianceHeaders.TargetApp}'.`
739
+ message: `Request missing header '${exports.AllianceHeaders.TargetApp}'.`
571
740
  },
572
- [10003 /* NoTargetWorkspaceHeader */]: {
741
+ [10003]: {
573
742
  httpCode: common.HttpStatus.BAD_REQUEST,
574
- message: `Request missing header '${AllianceHeaders.TargetWorkspace}'.`
743
+ message: `Request missing header '${exports.AllianceHeaders.TargetWorkspace}'.`
575
744
  },
576
- [10004 /* NoManifestsInCache */]: {
745
+ [10004]: {
577
746
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
578
747
  message: "App manifests missing in cache."
579
748
  },
580
- [10005 /* NoDevSessionInCache */]: {
749
+ [10005]: {
581
750
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
582
751
  message: "No dev session in memory cache."
583
752
  },
584
- [10006 /* NoManifest */]: {
753
+ [10006]: {
585
754
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
586
755
  message: "Could not find manifest for app '{{appSlug}}'."
587
756
  },
588
- [10007 /* NoRequestContext */]: {
757
+ [10007]: {
589
758
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
590
759
  message: "No request context."
591
760
  },
592
- [10008 /* NoUserInRequestContext */]: {
761
+ [10008]: {
593
762
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
594
763
  message: "No user in request context."
595
764
  },
596
- [10009 /* NoAppInRequestContext */]: {
765
+ [10009]: {
597
766
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
598
767
  message: "No app in request context."
599
768
  },
600
- [10010 /* NoWorkspaceInRequestContext */]: {
769
+ [10010]: {
601
770
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
602
771
  message: "No workspace in request context."
603
772
  },
604
- [10012 /* NoUserPermissionsInRequestContext */]: {
773
+ [10012]: {
605
774
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
606
775
  message: "No user permissions in request context."
607
776
  },
608
- [10013 /* WorkspacePermissionDenied */]: {
777
+ [10013]: {
609
778
  httpCode: common.HttpStatus.FORBIDDEN,
610
779
  message: "User does not have access to the current workspace."
611
780
  },
612
781
  // databases
613
- [11e3 /* NoPublicKey */]: {
782
+ [11e3]: {
614
783
  httpCode: common.HttpStatus.UNAUTHORIZED,
615
784
  message: "No public key available to decode JWT."
616
785
  },
617
- [11001 /* NoAuthHeader */]: {
786
+ [11001]: {
618
787
  httpCode: common.HttpStatus.UNAUTHORIZED,
619
788
  message: "No authorization header found."
620
789
  },
621
- [11002 /* FailedFileStore */]: {
790
+ [11002]: {
622
791
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
623
792
  message: "Error storing file."
624
793
  },
625
- [11003 /* FailedFileRead */]: {
794
+ [11003]: {
626
795
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
627
796
  message: "Error reading file."
628
797
  },
629
- [11004 /* NoRecord */]: {
798
+ [11004]: {
630
799
  httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
631
800
  message: "Missing database record."
632
801
  },
633
- [11005 /* UniqueConstrain */]: {
802
+ [11005]: {
634
803
  httpCode: common.HttpStatus.CONFLICT,
635
804
  message: "Field has to be unique."
636
805
  },
637
806
  // portal
638
- [12e3 /* NoObjectId */]: {
807
+ [12e3]: {
639
808
  httpCode: common.HttpStatus.UNAUTHORIZED,
640
809
  message: "No object id found in user claims."
641
810
  }
642
811
  };
643
812
 
644
- function parseTemplates$1(message, variables) {
813
+ // src/exceptions/alliance-gql.exception.ts
814
+ function parseTemplates(message, variables) {
645
815
  return Object.entries(variables).reduce((acc, [key, value]) => {
646
816
  return acc.replaceAll(`{{${key}}}`, value);
647
817
  }, message);
648
818
  }
649
- class AllianceGqlException extends graphql.GraphQLError {
819
+ __name(parseTemplates, "parseTemplates");
820
+ var AllianceGqlException = class extends graphql.GraphQLError {
821
+ static {
822
+ __name(this, "AllianceGqlException");
823
+ }
824
+ info;
825
+ code;
650
826
  constructor(code, variables = {}, extensions) {
651
827
  const { message } = allianceErrors[code];
652
- super(parseTemplates$1(message, variables), {
828
+ super(parseTemplates(message, variables), {
653
829
  extensions
654
830
  });
655
831
  this.code = code;
656
832
  this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
657
833
  }
658
- }
659
-
660
- function parseTemplates(message, variables) {
834
+ };
835
+ function parseTemplates2(message, variables) {
661
836
  return Object.entries(variables).reduce((acc, [key, value]) => {
662
837
  return acc.replaceAll(`{{${key}}}`, value);
663
838
  }, message);
664
839
  }
665
- class AllianceException extends common.HttpException {
840
+ __name(parseTemplates2, "parseTemplates");
841
+ var AllianceException = class extends common.HttpException {
842
+ static {
843
+ __name(this, "AllianceException");
844
+ }
845
+ info;
846
+ code;
666
847
  constructor(code, variables = {}) {
667
848
  const { message, httpCode } = allianceErrors[code];
668
- super(parseTemplates(message, variables), httpCode);
849
+ super(parseTemplates2(message, variables), httpCode);
669
850
  this.code = code;
670
851
  this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
671
852
  }
672
- }
673
-
674
- var __defProp$2 = Object.defineProperty;
675
- var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
676
- var __decorateClass$2 = (decorators, target, key, kind) => {
677
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
678
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
679
- if (decorator = decorators[i])
680
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
681
- if (kind && result)
682
- __defProp$2(target, key, result);
683
- return result;
684
853
  };
685
- exports.AllianceExceptionFilter = class AllianceExceptionFilter {
854
+ function _ts_decorate(decorators, target, key, desc) {
855
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
856
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
857
+ r = Reflect.decorate(decorators, target, key, desc);
858
+ else
859
+ for (var i = decorators.length - 1; i >= 0; i--)
860
+ if (d = decorators[i])
861
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
862
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
863
+ }
864
+ __name(_ts_decorate, "_ts_decorate");
865
+ exports.AllianceExceptionFilter = class AllianceExceptionFilter2 {
866
+ static {
867
+ __name(this, "AllianceExceptionFilter");
868
+ }
686
869
  catch(exception, host) {
687
870
  const ctx = host.switchToHttp();
688
871
  const response = ctx.getResponse();
@@ -695,23 +878,36 @@ exports.AllianceExceptionFilter = class AllianceExceptionFilter {
695
878
  });
696
879
  }
697
880
  };
698
- exports.AllianceExceptionFilter = __decorateClass$2([
881
+ exports.AllianceExceptionFilter = _ts_decorate([
699
882
  common.Catch(AllianceException)
700
883
  ], exports.AllianceExceptionFilter);
701
-
702
- var __defProp$1 = Object.defineProperty;
703
- var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
704
- var __decorateClass$1 = (decorators, target, key, kind) => {
705
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
706
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
707
- if (decorator = decorators[i])
708
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
709
- if (kind && result)
710
- __defProp$1(target, key, result);
711
- return result;
712
- };
713
- var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
714
- exports.LoggerService = class LoggerService {
884
+ function _ts_decorate2(decorators, target, key, desc) {
885
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
886
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
887
+ r = Reflect.decorate(decorators, target, key, desc);
888
+ else
889
+ for (var i = decorators.length - 1; i >= 0; i--)
890
+ if (d = decorators[i])
891
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
892
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
893
+ }
894
+ __name(_ts_decorate2, "_ts_decorate");
895
+ function _ts_metadata(k, v) {
896
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
897
+ return Reflect.metadata(k, v);
898
+ }
899
+ __name(_ts_metadata, "_ts_metadata");
900
+ function _ts_param(paramIndex, decorator) {
901
+ return function(target, key) {
902
+ decorator(target, key, paramIndex);
903
+ };
904
+ }
905
+ __name(_ts_param, "_ts_param");
906
+ exports.LoggerService = class LoggerService2 {
907
+ static {
908
+ __name(this, "LoggerService");
909
+ }
910
+ logger;
715
911
  constructor(logger) {
716
912
  this.logger = logger;
717
913
  this.log = (...args) => this.logger.info(...args);
@@ -722,35 +918,54 @@ exports.LoggerService = class LoggerService {
722
918
  this.error = (...args) => this.logger.error(...args);
723
919
  this.fatal = (...args) => this.logger.fatal(...args);
724
920
  }
921
+ log;
922
+ trace;
923
+ debug;
924
+ info;
925
+ warn;
926
+ error;
927
+ fatal;
725
928
  };
726
- exports.LoggerService = __decorateClass$1([
929
+ exports.LoggerService = _ts_decorate2([
727
930
  common.Injectable(),
728
- __decorateParam(0, nestjsPino.InjectPinoLogger())
931
+ _ts_param(0, nestjsPino.InjectPinoLogger()),
932
+ _ts_metadata("design:type", Function),
933
+ _ts_metadata("design:paramtypes", [
934
+ typeof nestjsPino.PinoLogger === "undefined" ? Object : nestjsPino.PinoLogger
935
+ ])
729
936
  ], exports.LoggerService);
730
937
 
731
- var __defProp = Object.defineProperty;
732
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
733
- var __decorateClass = (decorators, target, key, kind) => {
734
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
735
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
736
- if (decorator = decorators[i])
737
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
738
- if (kind && result)
739
- __defProp(target, key, result);
740
- return result;
741
- };
742
- exports.LoggerModule = class LoggerModule {
938
+ // src/logging/logging.module.ts
939
+ function _ts_decorate3(decorators, target, key, desc) {
940
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
941
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
942
+ r = Reflect.decorate(decorators, target, key, desc);
943
+ else
944
+ for (var i = decorators.length - 1; i >= 0; i--)
945
+ if (d = decorators[i])
946
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
947
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
948
+ }
949
+ __name(_ts_decorate3, "_ts_decorate");
950
+ exports.LoggerModule = class LoggerModule2 {
951
+ static {
952
+ __name(this, "LoggerModule");
953
+ }
743
954
  static forRoot({ logLevel, redact = true } = {}) {
744
955
  return {
745
- module: exports.LoggerModule,
956
+ module: LoggerModule2,
746
957
  controllers: [],
747
958
  imports: [
748
959
  nestjsPino.LoggerModule.forRootAsync({
749
- imports: [config.ConfigModule],
750
- inject: [config.ConfigService],
960
+ imports: [
961
+ config.ConfigModule
962
+ ],
963
+ inject: [
964
+ config.ConfigService
965
+ ],
751
966
  useFactory: async (configService) => ({
752
967
  pinoHttp: {
753
- level: logLevel || configService.get(SharedConfigKeys.ServiceLogLevel) || "silent",
968
+ level: logLevel || configService.get(exports.SharedConfigKeys.ServiceLogLevel) || "silent",
754
969
  redact: redact ? [
755
970
  "authorization",
756
971
  "headers.authorization",
@@ -762,63 +977,38 @@ exports.LoggerModule = class LoggerModule {
762
977
  })
763
978
  ],
764
979
  global: true,
765
- providers: [exports.LoggerService],
980
+ providers: [
981
+ exports.LoggerService
982
+ ],
766
983
  exports: []
767
984
  };
768
985
  }
769
986
  };
770
- exports.LoggerModule = __decorateClass([
987
+ exports.LoggerModule = _ts_decorate3([
771
988
  common.Module({
772
- providers: [exports.LoggerService],
773
- exports: [exports.LoggerService]
989
+ providers: [
990
+ exports.LoggerService
991
+ ],
992
+ exports: [
993
+ exports.LoggerService
994
+ ]
774
995
  })
775
996
  ], exports.LoggerModule);
776
-
777
997
  function slugify(name) {
778
- return _slugify__default(name, { strict: true, replacement: "-", lower: true });
779
- }
780
-
781
- function viteCssImportPlugin(outFilePath, relativePath = false) {
782
- return {
783
- name: "vite-plugin-css-import",
784
- apply: "build",
785
- enforce: "post",
786
- writeBundle: async (_, bundle) => {
787
- const cssFiles = Object.keys(bundle).filter((fileName) => fileName.endsWith(".css"));
788
- if (!cssFiles.length) {
789
- return;
790
- }
791
- const tempTargetFilePath = node_path.resolve(process.cwd(), `${outFilePath}-temp.js`);
792
- const targetFilePath = node_path.resolve(process.cwd(), `${outFilePath}.js`);
793
- const cssImportStatement = cssFiles.reduce((acc, cssFile) => {
794
- if (relativePath) {
795
- const targetDirname = node_path.dirname(targetFilePath);
796
- const relativePath2 = node_path.relative(targetDirname, cssFile);
797
- return `${acc}import "${relativePath2.replaceAll("\\", "/")}";
798
- `;
799
- }
800
- return `${acc}import "./${cssFile}";
801
- `;
802
- }, "");
803
- const writeStream = node_fs.createWriteStream(tempTargetFilePath);
804
- writeStream.write(cssImportStatement, "utf8");
805
- const readStream = node_fs.createReadStream(targetFilePath);
806
- await promises.pipeline(readStream, writeStream);
807
- node_fs.rmSync(targetFilePath, { force: true });
808
- node_fs.renameSync(tempTargetFilePath, targetFilePath);
809
- writeStream.end();
810
- }
811
- };
998
+ return _slugify__default.default(name, {
999
+ strict: true,
1000
+ replacement: "-",
1001
+ lower: true
1002
+ });
812
1003
  }
1004
+ __name(slugify, "slugify");
813
1005
 
814
- exports.LoggerErrorInterceptor = nestjsPino.LoggerErrorInterceptor;
1006
+ Object.defineProperty(exports, 'LoggerErrorInterceptor', {
1007
+ enumerable: true,
1008
+ get: function () { return nestjsPino.LoggerErrorInterceptor; }
1009
+ });
815
1010
  exports.AllianceException = AllianceException;
816
1011
  exports.AllianceGqlException = AllianceGqlException;
817
- exports.AllianceHeaders = AllianceHeaders;
818
- exports.DatabasesErrorCodes = DatabasesErrorCodes;
819
- exports.GatewayErrorCodes = GatewayErrorCodes;
820
- exports.PortalErrorCodes = PortalErrorCodes;
821
- exports.SharedConfigKeys = SharedConfigKeys;
822
1012
  exports.authMiddleware = authMiddleware;
823
1013
  exports.createBearerToken = createBearerToken;
824
1014
  exports.createPublicDistributionFiles = createPublicDistributionFiles;
@@ -826,4 +1016,5 @@ exports.createSystemUserToken = createSystemUserToken;
826
1016
  exports.getAppManifests = getAppManifests;
827
1017
  exports.getPrivateKey = getPrivateKey;
828
1018
  exports.slugify = slugify;
829
- exports.viteCssImportPlugin = viteCssImportPlugin;
1019
+ //# sourceMappingURL=out.js.map
1020
+ //# sourceMappingURL=index.cjs.map