@telia-ace/alliance-internal-node-utilities 1.0.3-next.0 → 1.0.3-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/auth/auth.middleware.d.ts +2 -1
- package/dist/constants/config.d.ts +2 -2
- package/dist/exceptions/alliance-gql.exception.d.ts +7 -0
- package/dist/exceptions/codes.d.ts +2 -3
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/index.cjs +40 -23
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +39 -24
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @telia-ace/alliance-internal-node-utilities
|
|
2
2
|
|
|
3
|
+
## 1.0.3-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f2aafe4: Store user session in Redis cache to avoid hitting cookie size limits (https://github.com/telia-company/ace-alliance-sdk/issues/377).
|
|
8
|
+
|
|
9
|
+
## 1.0.3-next.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- ba11e1f: Remove unused error codes.
|
|
14
|
+
|
|
3
15
|
## 1.0.3-next.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -8,6 +8,7 @@ type Settings = {
|
|
|
8
8
|
authRequired?: ConfigParams['authRequired'];
|
|
9
9
|
authorizationParams?: ConfigParams['authorizationParams'];
|
|
10
10
|
afterCallback?: ConfigParams['afterCallback'];
|
|
11
|
+
issuerBaseURL?: ConfigParams['issuerBaseURL'];
|
|
11
12
|
};
|
|
12
|
-
export declare function authMiddleware(configService: ConfigService, { baseURL, clientSecret, clientID, authRequired, authorizationParams, afterCallback, }?: Settings): RequestHandler;
|
|
13
|
+
export declare function authMiddleware(configService: ConfigService, { baseURL, clientSecret, clientID, authRequired, authorizationParams, afterCallback, issuerBaseURL, }?: Settings): RequestHandler;
|
|
13
14
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare enum SharedConfigKeys {
|
|
2
|
-
AuthAuthority = "AUTH_AUTHORITY",
|
|
3
2
|
AuthCookieName = "AUTH_COOKIE_NAME",
|
|
4
3
|
AuthCookieSecret = "AUTH_COOKIE_SECRET",
|
|
5
4
|
DbEndpoint = "DB_ENDPOINT",
|
|
6
5
|
JwtPrivateKey = "JWT_PRIVATE_KEY",
|
|
7
6
|
ServiceLogLevel = "SERVICE_LOG_LEVEL",
|
|
8
|
-
ServicePort = "SERVICE_PORT"
|
|
7
|
+
ServicePort = "SERVICE_PORT",
|
|
8
|
+
RedisHost = "REDIS_HOST"
|
|
9
9
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { GraphQLError } from 'graphql';
|
|
2
|
+
import { ErrorCodes } from './codes';
|
|
3
|
+
export declare class AllianceGqlException extends GraphQLError {
|
|
4
|
+
info: string;
|
|
5
|
+
code: ErrorCodes;
|
|
6
|
+
constructor(code: ErrorCodes, variables?: Record<string, string>, extensions?: any);
|
|
7
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { HttpStatus } from '@nestjs/common';
|
|
2
2
|
export declare enum GatewayErrorCodes {
|
|
3
|
-
NoMatchingEndpoint = 10000,
|
|
4
3
|
NoObjectId = 10001,
|
|
5
4
|
NoTargetAppHeader = 10002,
|
|
6
5
|
NoTargetWorkspaceHeader = 10003,
|
|
@@ -11,7 +10,6 @@ export declare enum GatewayErrorCodes {
|
|
|
11
10
|
NoUserInRequestContext = 10008,
|
|
12
11
|
NoAppInRequestContext = 10009,
|
|
13
12
|
NoWorkspaceInRequestContext = 10010,
|
|
14
|
-
NoManifestInRequestContext = 10011,
|
|
15
13
|
NoUserPermissionsInRequestContext = 10012,
|
|
16
14
|
WorkspacePermissionDenied = 10013
|
|
17
15
|
}
|
|
@@ -20,7 +18,8 @@ export declare enum DatabasesErrorCodes {
|
|
|
20
18
|
NoAuthHeader = 11001,
|
|
21
19
|
FailedFileStore = 11002,
|
|
22
20
|
FailedFileRead = 11003,
|
|
23
|
-
NoRecord = 11004
|
|
21
|
+
NoRecord = 11004,
|
|
22
|
+
UniqueConstrain = 11005
|
|
24
23
|
}
|
|
25
24
|
export declare enum PortalErrorCodes {
|
|
26
25
|
NoObjectId = 12000
|
package/dist/index.cjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const nestjsPino = require('nestjs-pino');
|
|
4
|
+
const RedisStore = require('connect-redis');
|
|
4
5
|
const expressOpenidConnect = require('express-openid-connect');
|
|
6
|
+
const redis = require('redis');
|
|
5
7
|
const jsonwebtoken = require('jsonwebtoken');
|
|
6
8
|
const jsonschema = require('jsonschema');
|
|
7
9
|
const node_path = require('node:path');
|
|
8
10
|
const node_fs = require('node:fs');
|
|
11
|
+
const graphql = require('graphql');
|
|
9
12
|
const common = require('@nestjs/common');
|
|
10
13
|
const config = require('@nestjs/config');
|
|
11
14
|
const _slugify = require('slugify');
|
|
@@ -13,16 +16,17 @@ const promises = require('node:stream/promises');
|
|
|
13
16
|
|
|
14
17
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
18
|
|
|
19
|
+
const RedisStore__default = /*#__PURE__*/_interopDefaultCompat(RedisStore);
|
|
16
20
|
const _slugify__default = /*#__PURE__*/_interopDefaultCompat(_slugify);
|
|
17
21
|
|
|
18
22
|
var SharedConfigKeys = /* @__PURE__ */ ((SharedConfigKeys2) => {
|
|
19
|
-
SharedConfigKeys2["AuthAuthority"] = "AUTH_AUTHORITY";
|
|
20
23
|
SharedConfigKeys2["AuthCookieName"] = "AUTH_COOKIE_NAME";
|
|
21
24
|
SharedConfigKeys2["AuthCookieSecret"] = "AUTH_COOKIE_SECRET";
|
|
22
25
|
SharedConfigKeys2["DbEndpoint"] = "DB_ENDPOINT";
|
|
23
26
|
SharedConfigKeys2["JwtPrivateKey"] = "JWT_PRIVATE_KEY";
|
|
24
27
|
SharedConfigKeys2["ServiceLogLevel"] = "SERVICE_LOG_LEVEL";
|
|
25
28
|
SharedConfigKeys2["ServicePort"] = "SERVICE_PORT";
|
|
29
|
+
SharedConfigKeys2["RedisHost"] = "REDIS_HOST";
|
|
26
30
|
return SharedConfigKeys2;
|
|
27
31
|
})(SharedConfigKeys || {});
|
|
28
32
|
|
|
@@ -39,8 +43,16 @@ function authMiddleware(configService, {
|
|
|
39
43
|
clientID = " ",
|
|
40
44
|
authRequired = true,
|
|
41
45
|
authorizationParams = {},
|
|
42
|
-
afterCallback
|
|
46
|
+
afterCallback,
|
|
47
|
+
issuerBaseURL = "https://127.0.0.1"
|
|
43
48
|
} = {}) {
|
|
49
|
+
const redisClient = redis.createClient({
|
|
50
|
+
url: configService.getOrThrow(SharedConfigKeys.RedisHost)
|
|
51
|
+
});
|
|
52
|
+
redisClient.connect().catch(console.error);
|
|
53
|
+
const redisStore = new RedisStore__default({
|
|
54
|
+
client: redisClient
|
|
55
|
+
});
|
|
44
56
|
return expressOpenidConnect.auth({
|
|
45
57
|
baseURL,
|
|
46
58
|
clientSecret,
|
|
@@ -48,12 +60,11 @@ function authMiddleware(configService, {
|
|
|
48
60
|
authRequired,
|
|
49
61
|
authorizationParams,
|
|
50
62
|
afterCallback,
|
|
51
|
-
issuerBaseURL
|
|
52
|
-
SharedConfigKeys.AuthAuthority
|
|
53
|
-
)}/.well-known/openid-configuration`,
|
|
63
|
+
issuerBaseURL,
|
|
54
64
|
secret: configService.getOrThrow(SharedConfigKeys.AuthCookieSecret),
|
|
55
65
|
session: {
|
|
56
|
-
name: configService.getOrThrow(SharedConfigKeys.AuthCookieName)
|
|
66
|
+
name: configService.getOrThrow(SharedConfigKeys.AuthCookieName),
|
|
67
|
+
store: redisStore
|
|
57
68
|
},
|
|
58
69
|
routes: {
|
|
59
70
|
callback: "/signin-oidc"
|
|
@@ -519,7 +530,6 @@ ${errors.join(
|
|
|
519
530
|
}
|
|
520
531
|
|
|
521
532
|
var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
|
|
522
|
-
GatewayErrorCodes2[GatewayErrorCodes2["NoMatchingEndpoint"] = 1e4] = "NoMatchingEndpoint";
|
|
523
533
|
GatewayErrorCodes2[GatewayErrorCodes2["NoObjectId"] = 10001] = "NoObjectId";
|
|
524
534
|
GatewayErrorCodes2[GatewayErrorCodes2["NoTargetAppHeader"] = 10002] = "NoTargetAppHeader";
|
|
525
535
|
GatewayErrorCodes2[GatewayErrorCodes2["NoTargetWorkspaceHeader"] = 10003] = "NoTargetWorkspaceHeader";
|
|
@@ -530,7 +540,6 @@ var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
|
|
|
530
540
|
GatewayErrorCodes2[GatewayErrorCodes2["NoUserInRequestContext"] = 10008] = "NoUserInRequestContext";
|
|
531
541
|
GatewayErrorCodes2[GatewayErrorCodes2["NoAppInRequestContext"] = 10009] = "NoAppInRequestContext";
|
|
532
542
|
GatewayErrorCodes2[GatewayErrorCodes2["NoWorkspaceInRequestContext"] = 10010] = "NoWorkspaceInRequestContext";
|
|
533
|
-
GatewayErrorCodes2[GatewayErrorCodes2["NoManifestInRequestContext"] = 10011] = "NoManifestInRequestContext";
|
|
534
543
|
GatewayErrorCodes2[GatewayErrorCodes2["NoUserPermissionsInRequestContext"] = 10012] = "NoUserPermissionsInRequestContext";
|
|
535
544
|
GatewayErrorCodes2[GatewayErrorCodes2["WorkspacePermissionDenied"] = 10013] = "WorkspacePermissionDenied";
|
|
536
545
|
return GatewayErrorCodes2;
|
|
@@ -541,6 +550,7 @@ var DatabasesErrorCodes = /* @__PURE__ */ ((DatabasesErrorCodes2) => {
|
|
|
541
550
|
DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileStore"] = 11002] = "FailedFileStore";
|
|
542
551
|
DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileRead"] = 11003] = "FailedFileRead";
|
|
543
552
|
DatabasesErrorCodes2[DatabasesErrorCodes2["NoRecord"] = 11004] = "NoRecord";
|
|
553
|
+
DatabasesErrorCodes2[DatabasesErrorCodes2["UniqueConstrain"] = 11005] = "UniqueConstrain";
|
|
544
554
|
return DatabasesErrorCodes2;
|
|
545
555
|
})(DatabasesErrorCodes || {});
|
|
546
556
|
var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
|
|
@@ -549,10 +559,6 @@ var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
|
|
|
549
559
|
})(PortalErrorCodes || {});
|
|
550
560
|
const allianceErrors = {
|
|
551
561
|
// gateway
|
|
552
|
-
[1e4 /* NoMatchingEndpoint */]: {
|
|
553
|
-
httpCode: common.HttpStatus.BAD_REQUEST,
|
|
554
|
-
message: "Could not find endpoint matching request in app manifest."
|
|
555
|
-
},
|
|
556
562
|
[10001 /* NoObjectId */]: {
|
|
557
563
|
httpCode: common.HttpStatus.UNAUTHORIZED,
|
|
558
564
|
message: "No object id available on authenticated user."
|
|
@@ -593,10 +599,6 @@ const allianceErrors = {
|
|
|
593
599
|
httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
594
600
|
message: "No workspace in request context."
|
|
595
601
|
},
|
|
596
|
-
[10011 /* NoManifestInRequestContext */]: {
|
|
597
|
-
httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
598
|
-
message: "No manifest in request context."
|
|
599
|
-
},
|
|
600
602
|
[10012 /* NoUserPermissionsInRequestContext */]: {
|
|
601
603
|
httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
602
604
|
message: "No user permissions in request context."
|
|
@@ -626,6 +628,10 @@ const allianceErrors = {
|
|
|
626
628
|
httpCode: common.HttpStatus.INTERNAL_SERVER_ERROR,
|
|
627
629
|
message: "Missing database record."
|
|
628
630
|
},
|
|
631
|
+
[11005 /* UniqueConstrain */]: {
|
|
632
|
+
httpCode: common.HttpStatus.CONFLICT,
|
|
633
|
+
message: "Field has to be unique."
|
|
634
|
+
},
|
|
629
635
|
// portal
|
|
630
636
|
[12e3 /* NoObjectId */]: {
|
|
631
637
|
httpCode: common.HttpStatus.UNAUTHORIZED,
|
|
@@ -633,6 +639,22 @@ const allianceErrors = {
|
|
|
633
639
|
}
|
|
634
640
|
};
|
|
635
641
|
|
|
642
|
+
function parseTemplates$1(message, variables) {
|
|
643
|
+
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
644
|
+
return acc.replaceAll(`{{${key}}}`, value);
|
|
645
|
+
}, message);
|
|
646
|
+
}
|
|
647
|
+
class AllianceGqlException extends graphql.GraphQLError {
|
|
648
|
+
constructor(code, variables = {}, extensions) {
|
|
649
|
+
const { message } = allianceErrors[code];
|
|
650
|
+
super(parseTemplates$1(message, variables), {
|
|
651
|
+
extensions
|
|
652
|
+
});
|
|
653
|
+
this.code = code;
|
|
654
|
+
this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
636
658
|
function parseTemplates(message, variables) {
|
|
637
659
|
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
638
660
|
return acc.replaceAll(`{{${key}}}`, value);
|
|
@@ -727,13 +749,7 @@ exports.LoggerModule = class LoggerModule {
|
|
|
727
749
|
useFactory: async (configService) => ({
|
|
728
750
|
pinoHttp: {
|
|
729
751
|
level: logLevel || configService.get(SharedConfigKeys.ServiceLogLevel) || "silent",
|
|
730
|
-
redact: redact ? [
|
|
731
|
-
"authorization",
|
|
732
|
-
"headers.authorization",
|
|
733
|
-
"req.headers.authorization",
|
|
734
|
-
"req.remoteAddress",
|
|
735
|
-
"req.remotePort"
|
|
736
|
-
] : [],
|
|
752
|
+
redact: redact ? ["authorization", "headers.authorization", "req", "res"] : [],
|
|
737
753
|
transport: {
|
|
738
754
|
target: "pino-pretty",
|
|
739
755
|
options: {
|
|
@@ -797,6 +813,7 @@ function viteCssImportPlugin(outFilePath, relativePath = false) {
|
|
|
797
813
|
|
|
798
814
|
exports.LoggerErrorInterceptor = nestjsPino.LoggerErrorInterceptor;
|
|
799
815
|
exports.AllianceException = AllianceException;
|
|
816
|
+
exports.AllianceGqlException = AllianceGqlException;
|
|
800
817
|
exports.AllianceHeaders = AllianceHeaders;
|
|
801
818
|
exports.DatabasesErrorCodes = DatabasesErrorCodes;
|
|
802
819
|
exports.GatewayErrorCodes = GatewayErrorCodes;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { LoggerErrorInterceptor } from 'nestjs-pino';
|
|
|
2
2
|
export { authMiddleware, createBearerToken, createSystemUserToken, getPrivateKey } from './auth';
|
|
3
3
|
export { AllianceHeaders, SharedConfigKeys } from './constants';
|
|
4
4
|
export { createPublicDistributionFiles } from './distribution';
|
|
5
|
-
export { AllianceException, AllianceExceptionFilter, DatabasesErrorCodes, GatewayErrorCodes, PortalErrorCodes, } from './exceptions';
|
|
5
|
+
export { AllianceException, AllianceExceptionFilter, AllianceGqlException, DatabasesErrorCodes, GatewayErrorCodes, PortalErrorCodes, } from './exceptions';
|
|
6
6
|
export { getAppManifests } from './get-app-manifests';
|
|
7
7
|
export { LoggerModule, LoggerService } from './logging';
|
|
8
8
|
export { slugify } from './slugify';
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { InjectPinoLogger, LoggerModule as LoggerModule$1 } from 'nestjs-pino';
|
|
2
2
|
export { LoggerErrorInterceptor } from 'nestjs-pino';
|
|
3
|
+
import RedisStore from 'connect-redis';
|
|
3
4
|
import { auth } from 'express-openid-connect';
|
|
5
|
+
import { createClient } from 'redis';
|
|
4
6
|
import { sign } from 'jsonwebtoken';
|
|
5
7
|
import { validate } from 'jsonschema';
|
|
6
8
|
import { resolve, dirname, relative } from 'node:path';
|
|
7
9
|
import { readFileSync, writeFileSync, rmSync, existsSync, mkdirSync, createWriteStream, createReadStream, renameSync } from 'node:fs';
|
|
10
|
+
import { GraphQLError } from 'graphql';
|
|
8
11
|
import { HttpStatus, HttpException, Catch, Injectable, Module } from '@nestjs/common';
|
|
9
12
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
10
13
|
import _slugify from 'slugify';
|
|
11
14
|
import { pipeline } from 'node:stream/promises';
|
|
12
15
|
|
|
13
16
|
var SharedConfigKeys = /* @__PURE__ */ ((SharedConfigKeys2) => {
|
|
14
|
-
SharedConfigKeys2["AuthAuthority"] = "AUTH_AUTHORITY";
|
|
15
17
|
SharedConfigKeys2["AuthCookieName"] = "AUTH_COOKIE_NAME";
|
|
16
18
|
SharedConfigKeys2["AuthCookieSecret"] = "AUTH_COOKIE_SECRET";
|
|
17
19
|
SharedConfigKeys2["DbEndpoint"] = "DB_ENDPOINT";
|
|
18
20
|
SharedConfigKeys2["JwtPrivateKey"] = "JWT_PRIVATE_KEY";
|
|
19
21
|
SharedConfigKeys2["ServiceLogLevel"] = "SERVICE_LOG_LEVEL";
|
|
20
22
|
SharedConfigKeys2["ServicePort"] = "SERVICE_PORT";
|
|
23
|
+
SharedConfigKeys2["RedisHost"] = "REDIS_HOST";
|
|
21
24
|
return SharedConfigKeys2;
|
|
22
25
|
})(SharedConfigKeys || {});
|
|
23
26
|
|
|
@@ -34,8 +37,16 @@ function authMiddleware(configService, {
|
|
|
34
37
|
clientID = " ",
|
|
35
38
|
authRequired = true,
|
|
36
39
|
authorizationParams = {},
|
|
37
|
-
afterCallback
|
|
40
|
+
afterCallback,
|
|
41
|
+
issuerBaseURL = "https://127.0.0.1"
|
|
38
42
|
} = {}) {
|
|
43
|
+
const redisClient = createClient({
|
|
44
|
+
url: configService.getOrThrow(SharedConfigKeys.RedisHost)
|
|
45
|
+
});
|
|
46
|
+
redisClient.connect().catch(console.error);
|
|
47
|
+
const redisStore = new RedisStore({
|
|
48
|
+
client: redisClient
|
|
49
|
+
});
|
|
39
50
|
return auth({
|
|
40
51
|
baseURL,
|
|
41
52
|
clientSecret,
|
|
@@ -43,12 +54,11 @@ function authMiddleware(configService, {
|
|
|
43
54
|
authRequired,
|
|
44
55
|
authorizationParams,
|
|
45
56
|
afterCallback,
|
|
46
|
-
issuerBaseURL
|
|
47
|
-
SharedConfigKeys.AuthAuthority
|
|
48
|
-
)}/.well-known/openid-configuration`,
|
|
57
|
+
issuerBaseURL,
|
|
49
58
|
secret: configService.getOrThrow(SharedConfigKeys.AuthCookieSecret),
|
|
50
59
|
session: {
|
|
51
|
-
name: configService.getOrThrow(SharedConfigKeys.AuthCookieName)
|
|
60
|
+
name: configService.getOrThrow(SharedConfigKeys.AuthCookieName),
|
|
61
|
+
store: redisStore
|
|
52
62
|
},
|
|
53
63
|
routes: {
|
|
54
64
|
callback: "/signin-oidc"
|
|
@@ -514,7 +524,6 @@ ${errors.join(
|
|
|
514
524
|
}
|
|
515
525
|
|
|
516
526
|
var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
|
|
517
|
-
GatewayErrorCodes2[GatewayErrorCodes2["NoMatchingEndpoint"] = 1e4] = "NoMatchingEndpoint";
|
|
518
527
|
GatewayErrorCodes2[GatewayErrorCodes2["NoObjectId"] = 10001] = "NoObjectId";
|
|
519
528
|
GatewayErrorCodes2[GatewayErrorCodes2["NoTargetAppHeader"] = 10002] = "NoTargetAppHeader";
|
|
520
529
|
GatewayErrorCodes2[GatewayErrorCodes2["NoTargetWorkspaceHeader"] = 10003] = "NoTargetWorkspaceHeader";
|
|
@@ -525,7 +534,6 @@ var GatewayErrorCodes = /* @__PURE__ */ ((GatewayErrorCodes2) => {
|
|
|
525
534
|
GatewayErrorCodes2[GatewayErrorCodes2["NoUserInRequestContext"] = 10008] = "NoUserInRequestContext";
|
|
526
535
|
GatewayErrorCodes2[GatewayErrorCodes2["NoAppInRequestContext"] = 10009] = "NoAppInRequestContext";
|
|
527
536
|
GatewayErrorCodes2[GatewayErrorCodes2["NoWorkspaceInRequestContext"] = 10010] = "NoWorkspaceInRequestContext";
|
|
528
|
-
GatewayErrorCodes2[GatewayErrorCodes2["NoManifestInRequestContext"] = 10011] = "NoManifestInRequestContext";
|
|
529
537
|
GatewayErrorCodes2[GatewayErrorCodes2["NoUserPermissionsInRequestContext"] = 10012] = "NoUserPermissionsInRequestContext";
|
|
530
538
|
GatewayErrorCodes2[GatewayErrorCodes2["WorkspacePermissionDenied"] = 10013] = "WorkspacePermissionDenied";
|
|
531
539
|
return GatewayErrorCodes2;
|
|
@@ -536,6 +544,7 @@ var DatabasesErrorCodes = /* @__PURE__ */ ((DatabasesErrorCodes2) => {
|
|
|
536
544
|
DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileStore"] = 11002] = "FailedFileStore";
|
|
537
545
|
DatabasesErrorCodes2[DatabasesErrorCodes2["FailedFileRead"] = 11003] = "FailedFileRead";
|
|
538
546
|
DatabasesErrorCodes2[DatabasesErrorCodes2["NoRecord"] = 11004] = "NoRecord";
|
|
547
|
+
DatabasesErrorCodes2[DatabasesErrorCodes2["UniqueConstrain"] = 11005] = "UniqueConstrain";
|
|
539
548
|
return DatabasesErrorCodes2;
|
|
540
549
|
})(DatabasesErrorCodes || {});
|
|
541
550
|
var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
|
|
@@ -544,10 +553,6 @@ var PortalErrorCodes = /* @__PURE__ */ ((PortalErrorCodes2) => {
|
|
|
544
553
|
})(PortalErrorCodes || {});
|
|
545
554
|
const allianceErrors = {
|
|
546
555
|
// gateway
|
|
547
|
-
[1e4 /* NoMatchingEndpoint */]: {
|
|
548
|
-
httpCode: HttpStatus.BAD_REQUEST,
|
|
549
|
-
message: "Could not find endpoint matching request in app manifest."
|
|
550
|
-
},
|
|
551
556
|
[10001 /* NoObjectId */]: {
|
|
552
557
|
httpCode: HttpStatus.UNAUTHORIZED,
|
|
553
558
|
message: "No object id available on authenticated user."
|
|
@@ -588,10 +593,6 @@ const allianceErrors = {
|
|
|
588
593
|
httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
589
594
|
message: "No workspace in request context."
|
|
590
595
|
},
|
|
591
|
-
[10011 /* NoManifestInRequestContext */]: {
|
|
592
|
-
httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
593
|
-
message: "No manifest in request context."
|
|
594
|
-
},
|
|
595
596
|
[10012 /* NoUserPermissionsInRequestContext */]: {
|
|
596
597
|
httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
597
598
|
message: "No user permissions in request context."
|
|
@@ -621,6 +622,10 @@ const allianceErrors = {
|
|
|
621
622
|
httpCode: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
622
623
|
message: "Missing database record."
|
|
623
624
|
},
|
|
625
|
+
[11005 /* UniqueConstrain */]: {
|
|
626
|
+
httpCode: HttpStatus.CONFLICT,
|
|
627
|
+
message: "Field has to be unique."
|
|
628
|
+
},
|
|
624
629
|
// portal
|
|
625
630
|
[12e3 /* NoObjectId */]: {
|
|
626
631
|
httpCode: HttpStatus.UNAUTHORIZED,
|
|
@@ -628,6 +633,22 @@ const allianceErrors = {
|
|
|
628
633
|
}
|
|
629
634
|
};
|
|
630
635
|
|
|
636
|
+
function parseTemplates$1(message, variables) {
|
|
637
|
+
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
638
|
+
return acc.replaceAll(`{{${key}}}`, value);
|
|
639
|
+
}, message);
|
|
640
|
+
}
|
|
641
|
+
class AllianceGqlException extends GraphQLError {
|
|
642
|
+
constructor(code, variables = {}, extensions) {
|
|
643
|
+
const { message } = allianceErrors[code];
|
|
644
|
+
super(parseTemplates$1(message, variables), {
|
|
645
|
+
extensions
|
|
646
|
+
});
|
|
647
|
+
this.code = code;
|
|
648
|
+
this.info = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${code}`;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
631
652
|
function parseTemplates(message, variables) {
|
|
632
653
|
return Object.entries(variables).reduce((acc, [key, value]) => {
|
|
633
654
|
return acc.replaceAll(`{{${key}}}`, value);
|
|
@@ -722,13 +743,7 @@ let LoggerModule = class {
|
|
|
722
743
|
useFactory: async (configService) => ({
|
|
723
744
|
pinoHttp: {
|
|
724
745
|
level: logLevel || configService.get(SharedConfigKeys.ServiceLogLevel) || "silent",
|
|
725
|
-
redact: redact ? [
|
|
726
|
-
"authorization",
|
|
727
|
-
"headers.authorization",
|
|
728
|
-
"req.headers.authorization",
|
|
729
|
-
"req.remoteAddress",
|
|
730
|
-
"req.remotePort"
|
|
731
|
-
] : [],
|
|
746
|
+
redact: redact ? ["authorization", "headers.authorization", "req", "res"] : [],
|
|
732
747
|
transport: {
|
|
733
748
|
target: "pino-pretty",
|
|
734
749
|
options: {
|
|
@@ -790,4 +805,4 @@ function viteCssImportPlugin(outFilePath, relativePath = false) {
|
|
|
790
805
|
};
|
|
791
806
|
}
|
|
792
807
|
|
|
793
|
-
export { AllianceException, AllianceExceptionFilter, AllianceHeaders, DatabasesErrorCodes, GatewayErrorCodes, LoggerModule, LoggerService, PortalErrorCodes, SharedConfigKeys, authMiddleware, createBearerToken, createPublicDistributionFiles, createSystemUserToken, getAppManifests, getPrivateKey, slugify, viteCssImportPlugin };
|
|
808
|
+
export { AllianceException, AllianceExceptionFilter, AllianceGqlException, AllianceHeaders, DatabasesErrorCodes, GatewayErrorCodes, LoggerModule, LoggerService, PortalErrorCodes, SharedConfigKeys, authMiddleware, createBearerToken, createPublicDistributionFiles, createSystemUserToken, getAppManifests, getPrivateKey, slugify, viteCssImportPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/alliance-internal-node-utilities",
|
|
3
|
-
"version": "1.0.3-next.
|
|
3
|
+
"version": "1.0.3-next.2",
|
|
4
4
|
"description": "Utilities used internally by packages developed by team Alliance.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Telia Company AB",
|
|
@@ -16,16 +16,21 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@nestjs/common": "^10.1.0",
|
|
18
18
|
"@nestjs/config": "^3.0.0",
|
|
19
|
+
"connect-redis": "^7.1.0",
|
|
19
20
|
"express-openid-connect": "^2.16.0",
|
|
21
|
+
"express-session": "^1.17.3",
|
|
22
|
+
"graphql": "^16.7.1",
|
|
20
23
|
"jsonschema": "^1.4.1",
|
|
21
24
|
"jsonwebtoken": "^9.0.1",
|
|
22
25
|
"nestjs-pino": "^3.3.0",
|
|
23
26
|
"pino-http": "^8.3.3",
|
|
24
27
|
"pino-pretty": "^10.1.0",
|
|
28
|
+
"redis": "^4.6.8",
|
|
25
29
|
"slugify": "^1.6.6"
|
|
26
30
|
},
|
|
27
31
|
"devDependencies": {
|
|
28
32
|
"@types/express": "^4.17.17",
|
|
33
|
+
"@types/express-session": "^1.17.1",
|
|
29
34
|
"@types/jsonwebtoken": "^9.0.2",
|
|
30
35
|
"@types/node": "^20.4.2",
|
|
31
36
|
"minimist": "^1.2.8",
|