@telia-ace/alliance-internal-node-utilities 1.0.5 → 1.0.6
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 +16 -0
- package/dist/index.d.ts +65 -32
- package/dist/index.js +78 -53
- package/dist/index.js.map +1 -1
- package/package.json +2 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @telia-ace/alliance-internal-node-utilities
|
|
2
2
|
|
|
3
|
+
## 1.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Use `slugify` from internal node utilities. ([#440](https://github.com/telia-company/ace-alliance-sdk/pull/440))
|
|
8
|
+
|
|
9
|
+
- Move public key related utilities to internal node utilities package. ([#440](https://github.com/telia-company/ace-alliance-sdk/pull/440))
|
|
10
|
+
|
|
11
|
+
## 1.0.6-next.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Use `slugify` from internal node utilities. ([#437](https://github.com/telia-company/ace-alliance-sdk/pull/437))
|
|
16
|
+
|
|
17
|
+
- Move public key related utilities to internal node utilities package. ([#437](https://github.com/telia-company/ace-alliance-sdk/pull/437))
|
|
18
|
+
|
|
3
19
|
## 1.0.5
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
3
3
|
|
|
4
|
+
type BearerTokenSettings = {
|
|
5
|
+
privateKey: string;
|
|
6
|
+
aud: string;
|
|
7
|
+
sub: string;
|
|
8
|
+
name: string;
|
|
9
|
+
user: {
|
|
10
|
+
type: string;
|
|
11
|
+
permissions: string[];
|
|
12
|
+
email: string;
|
|
13
|
+
};
|
|
14
|
+
workspace: {
|
|
15
|
+
name: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
};
|
|
18
|
+
expiration?: string;
|
|
19
|
+
};
|
|
20
|
+
declare const zKeyConfig: z.ZodObject<Pick<{
|
|
21
|
+
AUTH_COOKIE_NAME: z.ZodDefault<z.ZodString>;
|
|
22
|
+
AUTH_COOKIE_SECRET: z.ZodDefault<z.ZodString>;
|
|
23
|
+
DB_ENDPOINT: z.ZodString;
|
|
24
|
+
JWT_PRIVATE_KEY: z.ZodDefault<z.ZodString>;
|
|
25
|
+
JWT_PUBLIC_CSP_KEY: z.ZodDefault<z.ZodString>;
|
|
26
|
+
SERVICE_LOG_LEVEL: z.ZodDefault<z.ZodEnum<["silent", "fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
27
|
+
SERVICE_PORT: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
28
|
+
REDIS_HOST: z.ZodString;
|
|
29
|
+
REDIS_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
30
|
+
}, "JWT_PRIVATE_KEY" | "JWT_PUBLIC_CSP_KEY">, "strip", z.ZodTypeAny, {
|
|
31
|
+
JWT_PRIVATE_KEY: string;
|
|
32
|
+
JWT_PUBLIC_CSP_KEY: string;
|
|
33
|
+
}, {
|
|
34
|
+
JWT_PRIVATE_KEY?: string | undefined;
|
|
35
|
+
JWT_PUBLIC_CSP_KEY?: string | undefined;
|
|
36
|
+
}>;
|
|
37
|
+
declare function createBearerToken({ privateKey, aud, sub, name, user, workspace, expiration, }: BearerTokenSettings): string;
|
|
38
|
+
type BearerTokenContent = {
|
|
39
|
+
iss: 'Alliance';
|
|
40
|
+
aud: string;
|
|
41
|
+
sub: string;
|
|
42
|
+
name: string;
|
|
43
|
+
'https://alliance.teliacompany.net/user_type': string;
|
|
44
|
+
'https://alliance.teliacompany.net/user_email': string;
|
|
45
|
+
'https://alliance.teliacompany.net/user_privileges': string[];
|
|
46
|
+
'https://alliance.teliacompany.net/workspace': string;
|
|
47
|
+
'https://alliance.teliacompany.net/workspace_name': string;
|
|
48
|
+
};
|
|
49
|
+
declare function getPrivateKey(config: Pick<z.infer<typeof zKeyConfig>, 'JWT_PRIVATE_KEY'>): string;
|
|
50
|
+
declare function createSystemUserToken(config: Pick<z.infer<typeof zKeyConfig>, 'JWT_PRIVATE_KEY'>): string;
|
|
51
|
+
type PublicKeys = {
|
|
52
|
+
pkcs: string;
|
|
53
|
+
spki: string;
|
|
54
|
+
csp: string;
|
|
55
|
+
};
|
|
56
|
+
declare function createPublicKeys(config: z.infer<typeof zKeyConfig>): PublicKeys;
|
|
57
|
+
declare function getCleanPublicKey(type: keyof PublicKeys, keys: PublicKeys): string;
|
|
58
|
+
|
|
4
59
|
declare const zBooleanEnum: z.ZodEffects<z.ZodEnum<["true", "false"]>, boolean, "true" | "false">;
|
|
5
60
|
declare const zNonEmptyString: z.ZodString;
|
|
6
61
|
declare const zSharedConfig: z.ZodObject<{
|
|
@@ -26,6 +81,12 @@ declare const zSharedConfig: z.ZodObject<{
|
|
|
26
81
|
* Optional, defaults to "MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLYNqnOkQnEa8O8xbthQhiI0k1GGJT+GCQcATUPeEbaCFXonOrJm+CyuMmQWYLFF3NbE5NllU1jz9PYHzp2hAgAx8WGeretTvpEA1dE2gvXNESGbQ8FxQIDAQABAoIBAAjTJmud1348eGAfLV8CRaij2MAxxenJ9/ozVXfcPIa2+fCelsuBSv8pwbYODvNoVT7xpcs2nwccGI6JgnBl09EhqlMWCT7w7GLT2aBy3A/T6JF76xJICQGzDfWPYygMtlyhv0YqZDUjjFlJHun+/ysqIUMY81AR0FLUAEc6yw41Chc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|
|
28
83
|
JWT_PRIVATE_KEY: z.ZodDefault<z.ZodString>;
|
|
84
|
+
/**
|
|
85
|
+
* Public key type used by old versions of .NET.
|
|
86
|
+
*
|
|
87
|
+
* Optional, defaults to "BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"
|
|
88
|
+
*/
|
|
89
|
+
JWT_PUBLIC_CSP_KEY: z.ZodDefault<z.ZodString>;
|
|
29
90
|
/**
|
|
30
91
|
* Log level to output
|
|
31
92
|
*
|
|
@@ -55,6 +116,7 @@ declare const zSharedConfig: z.ZodObject<{
|
|
|
55
116
|
AUTH_COOKIE_SECRET: string;
|
|
56
117
|
DB_ENDPOINT: string;
|
|
57
118
|
JWT_PRIVATE_KEY: string;
|
|
119
|
+
JWT_PUBLIC_CSP_KEY: string;
|
|
58
120
|
SERVICE_LOG_LEVEL: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
59
121
|
SERVICE_PORT: number;
|
|
60
122
|
REDIS_HOST: string;
|
|
@@ -65,6 +127,7 @@ declare const zSharedConfig: z.ZodObject<{
|
|
|
65
127
|
AUTH_COOKIE_NAME?: string | undefined;
|
|
66
128
|
AUTH_COOKIE_SECRET?: string | undefined;
|
|
67
129
|
JWT_PRIVATE_KEY?: string | undefined;
|
|
130
|
+
JWT_PUBLIC_CSP_KEY?: string | undefined;
|
|
68
131
|
SERVICE_LOG_LEVEL?: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace" | undefined;
|
|
69
132
|
SERVICE_PORT?: string | undefined;
|
|
70
133
|
REDIS_PASSWORD?: string | undefined;
|
|
@@ -76,39 +139,9 @@ declare enum AllianceHeaders {
|
|
|
76
139
|
TargetWorkspace = "alliance-target-workspace"
|
|
77
140
|
}
|
|
78
141
|
|
|
79
|
-
type BearerTokenSettings = {
|
|
80
|
-
privateKey: string;
|
|
81
|
-
aud: string;
|
|
82
|
-
sub: string;
|
|
83
|
-
name: string;
|
|
84
|
-
user: {
|
|
85
|
-
type: string;
|
|
86
|
-
permissions: string[];
|
|
87
|
-
email: string;
|
|
88
|
-
};
|
|
89
|
-
workspace: {
|
|
90
|
-
name: string;
|
|
91
|
-
slug: string;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
declare function createBearerToken({ privateKey, aud, sub, name, user, workspace, }: BearerTokenSettings): string;
|
|
95
|
-
type BearerTokenContent = {
|
|
96
|
-
iss: 'Alliance';
|
|
97
|
-
aud: string;
|
|
98
|
-
sub: string;
|
|
99
|
-
name: string;
|
|
100
|
-
'https://alliance.teliacompany.net/user_type': string;
|
|
101
|
-
'https://alliance.teliacompany.net/user_email': string;
|
|
102
|
-
'https://alliance.teliacompany.net/user_privileges': string[];
|
|
103
|
-
'https://alliance.teliacompany.net/workspace': string;
|
|
104
|
-
'https://alliance.teliacompany.net/workspace_name': string;
|
|
105
|
-
};
|
|
106
|
-
declare function getPrivateKey(config: Pick<z.infer<typeof zSharedConfig>, 'JWT_PRIVATE_KEY'>): string;
|
|
107
|
-
declare function createSystemUserToken(config: Pick<z.infer<typeof zSharedConfig>, 'JWT_PRIVATE_KEY'>): string;
|
|
108
|
-
|
|
109
142
|
declare function createPublicDistributionFiles(): Promise<void>;
|
|
110
143
|
|
|
111
|
-
declare function slugify(
|
|
144
|
+
declare function slugify(value: string, replacement?: string): string;
|
|
112
145
|
|
|
113
146
|
type LogFn = (msg: string, obj?: any) => void;
|
|
114
147
|
type PartialConfig = Pick<z.infer<typeof zSharedConfig>, 'SERVICE_LOG_LEVEL'>;
|
|
@@ -171,4 +204,4 @@ declare class AllianceError extends Error {
|
|
|
171
204
|
}
|
|
172
205
|
declare function requestErrorHandler(logger: Logger): ErrorRequestHandler;
|
|
173
206
|
|
|
174
|
-
export { AllianceError, AllianceHeaders, BearerTokenContent, DataErrorCode, GatewayErrorCode, Logger, createBearerToken, createLogger, createPublicDistributionFiles, createSystemUserToken, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
|
207
|
+
export { AllianceError, AllianceHeaders, BearerTokenContent, DataErrorCode, GatewayErrorCode, Logger, PublicKeys, createBearerToken, createLogger, createPublicDistributionFiles, createPublicKeys, createSystemUserToken, getCleanPublicKey, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
+
import { createPublicKey } from 'node:crypto';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { validate } from 'jsonschema';
|
|
4
5
|
import { existsSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
|
|
@@ -7,56 +8,6 @@ import _slugify from 'slugify';
|
|
|
7
8
|
import pino from 'pino';
|
|
8
9
|
|
|
9
10
|
// src/auth/tokens.ts
|
|
10
|
-
function createBearerToken({
|
|
11
|
-
privateKey,
|
|
12
|
-
aud,
|
|
13
|
-
sub,
|
|
14
|
-
name,
|
|
15
|
-
user,
|
|
16
|
-
workspace
|
|
17
|
-
}) {
|
|
18
|
-
const token = jwt.sign(
|
|
19
|
-
{
|
|
20
|
-
iss: "Alliance",
|
|
21
|
-
aud,
|
|
22
|
-
sub,
|
|
23
|
-
name,
|
|
24
|
-
"https://alliance.teliacompany.net/user_type": user.type,
|
|
25
|
-
"https://alliance.teliacompany.net/user_email": user.email,
|
|
26
|
-
"https://alliance.teliacompany.net/user_privileges": user.permissions,
|
|
27
|
-
"https://alliance.teliacompany.net/workspace": workspace.slug,
|
|
28
|
-
"https://alliance.teliacompany.net/workspace_name": workspace.name,
|
|
29
|
-
"https://alliance.teliacompany.net/tenant": workspace.slug,
|
|
30
|
-
"https://alliance.teliacompany.net/tenant_name": workspace.name
|
|
31
|
-
},
|
|
32
|
-
privateKey,
|
|
33
|
-
{
|
|
34
|
-
expiresIn: "1h",
|
|
35
|
-
algorithm: "RS256"
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
return `Bearer ${token}`;
|
|
39
|
-
}
|
|
40
|
-
function getPrivateKey(config) {
|
|
41
|
-
return "-----BEGIN RSA PRIVATE KEY-----\n" + config.JWT_PRIVATE_KEY + "\n-----END RSA PRIVATE KEY-----";
|
|
42
|
-
}
|
|
43
|
-
function createSystemUserToken(config) {
|
|
44
|
-
return createBearerToken({
|
|
45
|
-
aud: "system",
|
|
46
|
-
sub: "system",
|
|
47
|
-
name: "system",
|
|
48
|
-
workspace: {
|
|
49
|
-
slug: "system",
|
|
50
|
-
name: "system"
|
|
51
|
-
},
|
|
52
|
-
user: {
|
|
53
|
-
type: "system",
|
|
54
|
-
permissions: [],
|
|
55
|
-
email: "system"
|
|
56
|
-
},
|
|
57
|
-
privateKey: getPrivateKey(config)
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
11
|
var zBooleanEnum = z.enum(["true", "false"]).transform((strBool) => strBool === "true");
|
|
61
12
|
var zNonEmptyString = z.string().min(1);
|
|
62
13
|
var zSharedConfig = z.object({
|
|
@@ -84,6 +35,14 @@ var zSharedConfig = z.object({
|
|
|
84
35
|
JWT_PRIVATE_KEY: zNonEmptyString.default(
|
|
85
36
|
"MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k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mMHQ0qCedXU8z35huTnRGSDV81gmzyhtQsezgoTWp8Cy6HHKjG6fKasWlx2SKKk8m+Eu3c396QQKBgBMY2asq4M7VU+RiUXCwHwTe+4Wjda7PGvcdTw6Du3vYyVNVxXtr2AG+8uPIjnVQFT6ZApSqToEOAAOjXv6SZDHGU5xiXhUOfIXq0a0OmHv4rIXZv3pPZmGs5k+rA0uGAfH7riiIHBkWxmQ3ivty9lPVgAHobIvvaQmbxNeVVnRxAoGAUzUmcBiUAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo="
|
|
86
37
|
),
|
|
38
|
+
/**
|
|
39
|
+
* Public key type used by old versions of .NET.
|
|
40
|
+
*
|
|
41
|
+
* Optional, defaults to "BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"
|
|
42
|
+
*/
|
|
43
|
+
JWT_PUBLIC_CSP_KEY: z.string().min(1).default(
|
|
44
|
+
"BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw"
|
|
45
|
+
),
|
|
87
46
|
/**
|
|
88
47
|
* Log level to output
|
|
89
48
|
*
|
|
@@ -118,6 +77,72 @@ var AllianceHeaders = /* @__PURE__ */ ((AllianceHeaders2) => {
|
|
|
118
77
|
return AllianceHeaders2;
|
|
119
78
|
})(AllianceHeaders || {});
|
|
120
79
|
|
|
80
|
+
// src/auth/tokens.ts
|
|
81
|
+
zSharedConfig.pick({ JWT_PRIVATE_KEY: true, JWT_PUBLIC_CSP_KEY: true });
|
|
82
|
+
function createBearerToken({
|
|
83
|
+
privateKey,
|
|
84
|
+
aud,
|
|
85
|
+
sub,
|
|
86
|
+
name,
|
|
87
|
+
user,
|
|
88
|
+
workspace,
|
|
89
|
+
expiration = "1h"
|
|
90
|
+
}) {
|
|
91
|
+
const token = jwt.sign(
|
|
92
|
+
{
|
|
93
|
+
iss: "Alliance",
|
|
94
|
+
aud,
|
|
95
|
+
sub,
|
|
96
|
+
name,
|
|
97
|
+
"https://alliance.teliacompany.net/user_type": user.type,
|
|
98
|
+
"https://alliance.teliacompany.net/user_email": user.email,
|
|
99
|
+
"https://alliance.teliacompany.net/user_privileges": user.permissions,
|
|
100
|
+
"https://alliance.teliacompany.net/workspace": workspace.slug,
|
|
101
|
+
"https://alliance.teliacompany.net/workspace_name": workspace.name,
|
|
102
|
+
"https://alliance.teliacompany.net/tenant": workspace.slug,
|
|
103
|
+
"https://alliance.teliacompany.net/tenant_name": workspace.name
|
|
104
|
+
},
|
|
105
|
+
privateKey,
|
|
106
|
+
{
|
|
107
|
+
expiresIn: expiration,
|
|
108
|
+
algorithm: "RS256"
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
return `Bearer ${token}`;
|
|
112
|
+
}
|
|
113
|
+
function getPrivateKey(config) {
|
|
114
|
+
return "-----BEGIN RSA PRIVATE KEY-----\n" + config.JWT_PRIVATE_KEY + "\n-----END RSA PRIVATE KEY-----";
|
|
115
|
+
}
|
|
116
|
+
function createSystemUserToken(config) {
|
|
117
|
+
return createBearerToken({
|
|
118
|
+
aud: "system",
|
|
119
|
+
sub: "system",
|
|
120
|
+
name: "system",
|
|
121
|
+
workspace: {
|
|
122
|
+
slug: "system",
|
|
123
|
+
name: "system"
|
|
124
|
+
},
|
|
125
|
+
user: {
|
|
126
|
+
type: "system",
|
|
127
|
+
permissions: [],
|
|
128
|
+
email: "system"
|
|
129
|
+
},
|
|
130
|
+
privateKey: getPrivateKey(config)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function createPublicKeys(config) {
|
|
134
|
+
const priv = getPrivateKey(config);
|
|
135
|
+
const generatedKey = createPublicKey(priv);
|
|
136
|
+
return {
|
|
137
|
+
pkcs: generatedKey.export({ type: "pkcs1", format: "pem" }).toString().trim(),
|
|
138
|
+
spki: generatedKey.export({ type: "spki", format: "pem" }).toString().trim(),
|
|
139
|
+
csp: config.JWT_PUBLIC_CSP_KEY
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function getCleanPublicKey(type, keys) {
|
|
143
|
+
return keys[type].replace("-----BEGIN RSA PUBLIC KEY-----", "").replace("-----END RSA PUBLIC KEY-----", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim().replaceAll("\n", "");
|
|
144
|
+
}
|
|
145
|
+
|
|
121
146
|
// src/distribution/cookie-policy.ts
|
|
122
147
|
function generateCookiePolicyHtml(appManifests) {
|
|
123
148
|
const cookiePolicyTableRows = [];
|
|
@@ -525,8 +550,8 @@ ${errors2.join(
|
|
|
525
550
|
writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));
|
|
526
551
|
writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));
|
|
527
552
|
}
|
|
528
|
-
function slugify(
|
|
529
|
-
return _slugify(
|
|
553
|
+
function slugify(value, replacement = "-") {
|
|
554
|
+
return _slugify(value, { strict: true, replacement, lower: true });
|
|
530
555
|
}
|
|
531
556
|
function logFn(instance) {
|
|
532
557
|
return (level) => {
|
|
@@ -707,6 +732,6 @@ function requestErrorHandler(logger) {
|
|
|
707
732
|
};
|
|
708
733
|
}
|
|
709
734
|
|
|
710
|
-
export { AllianceError, AllianceHeaders, DataErrorCode, GatewayErrorCode, createBearerToken, createLogger, createPublicDistributionFiles, createSystemUserToken, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
|
735
|
+
export { AllianceError, AllianceHeaders, DataErrorCode, GatewayErrorCode, createBearerToken, createLogger, createPublicDistributionFiles, createPublicKeys, createSystemUserToken, getCleanPublicKey, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
|
711
736
|
//# sourceMappingURL=out.js.map
|
|
712
737
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth/tokens.ts","../src/constants/config.ts","../src/constants/headers.ts","../src/distribution/create-public-files.ts","../src/distribution/cookie-policy.ts","../src/distribution/json-schemas.ts","../src/distribution/pkg-json.ts","../src/distribution/get-app-manifests.ts","../src/slugify.ts","../src/logger.ts","../src/errors/codes.ts","../src/errors/errors.ts"],"names":["AllianceHeaders","writeFileSync","resolve","readFileSync","errors","GatewayErrorCode","DataErrorCode"],"mappings":";AAAA,OAAO,SAAS;AAkBT,SAAS,kBAAkB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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AA,MACX,SAAS,IAAI;AAAA,MACb,QAAQ,IAAI,UAAU,IAAI,cAAc,IAAI;AAAA,MAC5C,MAAM,IAAI;AAAA,IACd;AAEA,WAAO,MAAM,iCAAiC;AAAA,MAC1C,KAAK,IAAI;AAAA,MACT,MAAM,IAAI;AAAA,MACV;AAAA,IACJ,CAAC;AAED,WAAO,IAAI,OAAO,MAAM,MAAM,EAAE,KAAK,KAAK;AAAA,EAC9C;AACJ","sourcesContent":["import jwt from 'jsonwebtoken';\nimport type { z } from 'zod';\n\nimport type { zSharedConfig } from '@/constants';\n\ntype BearerTokenSettings = {\n privateKey: string;\n aud: string;\n sub: string;\n name: string;\n user: {\n type: string;\n permissions: string[];\n email: string;\n };\n workspace: { name: string; slug: string };\n};\n\nexport function createBearerToken({\n privateKey,\n aud,\n sub,\n name,\n user,\n workspace,\n}: BearerTokenSettings) {\n const token = jwt.sign(\n {\n iss: 'Alliance',\n aud,\n sub,\n name,\n 'https://alliance.teliacompany.net/user_type': user.type,\n 'https://alliance.teliacompany.net/user_email': user.email,\n 'https://alliance.teliacompany.net/user_privileges': user.permissions,\n 'https://alliance.teliacompany.net/workspace': workspace.slug,\n 'https://alliance.teliacompany.net/workspace_name': workspace.name,\n 'https://alliance.teliacompany.net/tenant': workspace.slug,\n 'https://alliance.teliacompany.net/tenant_name': workspace.name,\n } as BearerTokenContent,\n privateKey,\n {\n expiresIn: '1h',\n algorithm: 'RS256',\n },\n );\n\n return `Bearer ${token}`;\n}\n\nexport type BearerTokenContent = {\n iss: 'Alliance';\n aud: string;\n sub: string;\n name: string;\n 'https://alliance.teliacompany.net/user_type': string;\n 'https://alliance.teliacompany.net/user_email': string;\n 'https://alliance.teliacompany.net/user_privileges': string[];\n 'https://alliance.teliacompany.net/workspace': string;\n 'https://alliance.teliacompany.net/workspace_name': string;\n};\n\nexport function getPrivateKey(config: Pick<z.infer<typeof zSharedConfig>, 'JWT_PRIVATE_KEY'>) {\n return (\n '-----BEGIN RSA PRIVATE KEY-----\\n' +\n config.JWT_PRIVATE_KEY +\n '\\n-----END RSA PRIVATE KEY-----'\n );\n}\n\nexport function createSystemUserToken(\n config: Pick<z.infer<typeof zSharedConfig>, 'JWT_PRIVATE_KEY'>,\n) {\n return createBearerToken({\n aud: 'system',\n sub: 'system',\n name: 'system',\n workspace: {\n slug: 'system',\n name: 'system',\n },\n user: {\n type: 'system',\n permissions: [],\n email: 'system',\n },\n privateKey: getPrivateKey(config),\n });\n}\n","import { z } from 'zod';\n\nexport const zBooleanEnum = z.enum(['true', 'false']).transform((strBool) => strBool === 'true');\n\nexport const zNonEmptyString = z.string().min(1);\n\nexport const zSharedConfig = z.object({\n /**\n * Name for the cookie storing the user session\n *\n * Optional, defaults to \"alliance-auth\"\n */\n AUTH_COOKIE_NAME: zNonEmptyString.default('alliance-auth'),\n /**\n * Secret to use when signing the user session cookie\n *\n * Optional, defaults to \"zlLZBlk7wt8lypP5lA4D\"\n */\n AUTH_COOKIE_SECRET: zNonEmptyString.default('zlLZBlk7wt8lypP5lA4D'),\n /**\n * Endpoint to use when communicating with the Data API\n */\n DB_ENDPOINT: zNonEmptyString,\n /**\n * Private key to use when signing JWT tokens\n *\n * Optional, defaults to \"MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLYNqnOkQnEa8O8xbthQhiI0k1GGJT+GCQcATUPeEbaCFXonOrJm+CyuMmQWYLFF3NbE5NllU1jz9PYHzp2hAgAx8WGeretTvpEA1dE2gvXNESGbQ8FxQIDAQABAoIBAAjTJmud1348eGAfLV8CRaij2MAxxenJ9/ozVXfcPIa2+fCelsuBSv8pwb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6m3pXj25prXJWIrB6DyGuL/HQmHzffQkOeXmwFGHFXyiIFOIITX4z8b9lMnavgUZoPDY+ZFsxp6I7vMn75AetB8wYXpOFFeCG/Ck/VSIYP7oAN8kLw8EHdOuNbZYbu34bUCgYBYd14ZOBiZZS4yUlrJ2tc6atOgoNJ4OcTO8LcXXaHYEmenUF9iAf4UGygSoyDJ1CvtW9kLCK+4g7xlFx/dsVkU4qq9PyIA2tNmMHQ0qCedXU8z35huTnRGSDV81gmzyhtQsezgoTWp8Cy6HHKjG6fKasWlx2SKKk8m+Eu3c396QQKBgBMY2asq4M7VU+RiUXCwHwTe+4Wjda7PGvcdTw6Du3vYyVNVxXtr2AG+8uPIjnVQFT6ZApSqToEOAAOjXv6SZDHGU5xiXhUOfIXq0a0OmHv4rIXZv3pPZmGs5k+rA0uGAfH7riiIHBkWxmQ3ivty9lPVgAHobIvvaQmbxNeVVnRxAoGAUzUmcBiUAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo=',\n ),\n /**\n * Log level to output\n *\n * Supports \"silent\" | \"fatal\" | \"error\" | \"warn\" | \"info\" | \"debug\" | \"trace\"\n *\n * Optional, defaults to \"trace\"\n */\n SERVICE_LOG_LEVEL: z\n .enum(['silent', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'])\n .default('trace'),\n /**\n * Port to run the service on.\n *\n * Optional, defaults to \"3000\"\n */\n SERVICE_PORT: zNonEmptyString.transform(Number).default('3000'),\n /**\n * Url to redis server to use when storing / reading user session information.\n */\n REDIS_HOST: zNonEmptyString,\n /**\n * Password to redis server to use when storing / reading user session information.\n *\n * Optional\n */\n REDIS_PASSWORD: zNonEmptyString.optional(),\n});\n","export enum AllianceHeaders {\n TargetUrl = 'alliance-target-url',\n TargetApp = 'alliance-target-app',\n TargetWorkspace = 'alliance-target-workspace',\n}\n","import { validate } from 'jsonschema';\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport { generateCookiePolicyHtml } from './cookie-policy';\nimport { getJsonSchemas } from './json-schemas';\nimport { getManifests, getPkgJson } from './pkg-json';\n\nconst PUBLIC_DIR_NAME = 'public';\nconst MANIFESTS_FILE_NAME = 'manifests.json';\nconst COOKIE_POLICY_FILE_NAME = 'cookie-policy.html';\nconst APP_CONFIG_SCHEMA_FILE_NAME = 'config.schema.json';\nconst APP_MANIFEST_SCHEMA_FILE_NAME = 'manifest.schema.json';\n\nexport async function createPublicDistributionFiles() {\n const pkgJson = getPkgJson();\n const manifests = await getManifests(pkgJson);\n const schemas = getJsonSchemas();\n\n // Validate all app schemas\n for (const appName in manifests) {\n const manifest = manifests[appName];\n\n const validationResult = validate(manifest, schemas.appManifest);\n\n if (validationResult.errors.length) {\n const errors = validationResult.errors.map((e) => JSON.stringify(e, null, 2));\n throw new Error(\n `Validation of app manifest for app '${appName}' failed with the following errors:\\n${errors.join(\n '\\n',\n )}`,\n );\n }\n }\n\n // Make sure public dir exists\n const publicDirPath = resolve(process.cwd(), PUBLIC_DIR_NAME);\n if (!existsSync(publicDirPath)) {\n mkdirSync(publicDirPath);\n }\n\n // Create manifests file\n const manifestsFilePath = resolve(publicDirPath, MANIFESTS_FILE_NAME);\n writeFileSync(manifestsFilePath, JSON.stringify(manifests));\n\n // Create cookie policy document\n const cookiePolicyFilePath = resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);\n writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));\n\n // Create JSON schema files\n const appConfigSchemaFilePath = resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);\n const appManifestSchemaFilePath = resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);\n writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));\n writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));\n}\n","import type { LooseObject } from '@/types';\n\nexport function generateCookiePolicyHtml(appManifests: LooseObject) {\n const cookiePolicyTableRows: string[] = [];\n\n for (const appName in appManifests) {\n const manifest = appManifests[appName];\n if (!manifest.storage) {\n continue;\n }\n\n for (const [key, value] of Object.entries(manifest.storage)) {\n const tableRow = createCookiePolicyTableRow(key, value as LooseObject);\n cookiePolicyTableRows.push(tableRow);\n }\n }\n\n return cookiePolicyHtml.replace('{APP_COOKIES}', cookiePolicyTableRows.join(''));\n}\n\nfunction createCookiePolicyTableRow(key: string, claimEntry: LooseObject) {\n const rows = ['<tr>'];\n const { category, purpose, lifespan } = claimEntry;\n rows.push(`<td>${key}</td>`);\n rows.push(`<td>${category}</td>`);\n rows.push(`<td>${purpose}</td>`);\n rows.push(`<td>${lifespan}</td>`);\n rows.push('</tr>');\n return rows.join('');\n}\n\nconst cookiePolicyHtml = `\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>ACE Alliance - Cookie Policy</title>\n <link\n rel=\"icon\"\n href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGcElEQVRYha2Xe4xUVx3HP7/fPTOzDLO7sw8RlzWlZEtp2dCy0qIVWltKU/UPDZH6ijXWEK2odPcPa2qbhpi2kSa7blSStsFUjNq0lWCMaVMx8rAm22IJMJRHCqFC6BJ22eEx+5p7z88/7sywC7uwgCe5mXsz5/y+j/M753eOcJ2tK5sDyBrME2gBmkBq43/tnMERgXdAjrbn518yXq4RNA3cB/J54HNiMhfEicm4oAYghmHexN4Dew5k01giUybQlc1h0CbI9zC+Imi9mCAIYhoHsnI4KcNjYoDhxWPxsxFY1Z5vHQVwVwSu3Qdid4E8rSb3i6mqKYwBjpWX1V/QZBiYYWIIiifCw8Mm/vS7L/W237FqJno58M5srgmxP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KPeqDP7bF/rfa2xLvHrLN6sfmr08o0GDqAaCIYRD3g/sD/1Hb49w7K1hev89otEoTi6To+V5n3l3Mryru1r3vpjn8KbCZjU5MLbfuBCd2VyzIHsTgauZ3pAkkXIanScc6Tf1RfRiJyYHN4Iq/O2PZ/zc71Rpz89P+30bz4QmdltHvvXQpARKJB5R0w0XSvL4cjwV+FnLU+HiZ2tUpxtbf9Tnj20vOJPo2fZ8688u7n3pmdB42Yt/xUuESVQ+yVJexZNtVmbQ2JYIH9zcGC5/pd71Hxjxm5f1cnzboDPx7xs8M9G4CSV1ZnOZICE7GNXbKweTMU7EA6USoemeVLhgTYame1Nu4MBI2PN0ng+3DDovIZFG5w37bEe+dc+UCQC8/ZtjzX07i/88saU4J8yLXiAhaCC+fn7Sz/7iNFq+mqZ6TuD6do+Gu7vPcuQvBRf62LlIQ2/Y1zvyra9OhnPZSf1g58k5I6ftDSnqnNFTaOACqmclfP0tSa3KBjrc5/2Hbwz7Q38ocHLniDM8XjxeIrxG3rA16vXXj529dVKMK2bVL2fkmhrmJ/9cPy91Z2ZGwhMqQx95TudC8gdCZx4obbMVAhqNGvaoCr99bKD1svGntK4647vg84J8X021PBXlK5gJGJWr11GDb3fkW7dPJfaUi3539iARxSUCz4AsERMVpHwDxMTyhq0HftGRbz071bhXfeooXVJvBR4EbgSGgR6Bt9qvArjc/gfZzPoCTDB+AgAAAABJRU5ErkJggg==\"\n />\n <style>\n @charset \"UTF-8\";\n @import 'https://cdn.voca.teliacompany.com/fonts/TeliaSansV10/TeliaSans.css';\n @import 'https://fonts.googleapis.com/css?family=Reenie+Beanie';\n\n body {\n font-family: TeliaSans, Helvetica, Arial, Lucida Grande, sans-serif;\n }\n\n body > div {\n max-width: 1000px;\n margin: 0 auto;\n padding: 0 40px 40px;\n }\n </style>\n </head>\n\n <body>\n <div>\n <h1>Cookie Policy</h1>\n <p>\n On our websites, we use cookies and other similar technologies. You can choose\n whether you want to allow our websites to store cookies on your computer or not. You\n can change your choices at any time.\n </p>\n\n <h2>Your consent is required</h2>\n <p>\n You choose whether you want to accept cookies on your device or not. Your consent is\n required for the use of cookies, but not for such cookies that are necessary to\n enable the service that you as a user have requested. If you do not accept our use\n of cookies, or if you have previously approved our use and have changed your mind,\n you can return to your cookie settings at any time and change your choices. You do\n this by clicking on the cookie button/link. You may also need to change the settings\n in your browser and manually delete cookies to clear your device of previously\n stored cookies.\n </p>\n\n <h2>What are cookies?</h2>\n <p>\n A cookie is a small text file that is stored on your computer by the web browser\n while browsing a website. When we refer to cookies (“cookies”) in this policy, other\n similar technologies and tools that retrieve and store information in your browser,\n and in some cases forward such information to third parties, in a manner similar to\n cookies. Examples are pixels, local storage, session storage and fingerprinting.\n </p>\n <p>\n The websites will “remember” and “recognize” you. This can be done by placing\n cookies in three different ways;\n </p>\n <ul>\n <li>The session ends, ie until you close the window in your browser.</li>\n <li>\n Time-limited, ie the cookie has a predetermined lifespan. The time may vary\n between different cookies.\n </li>\n <li>\n Until further notice, ie the information remains until you choose to delete it\n yourself. This applies to local storage.\n </li>\n </ul>\n <p>You can always go into your browser and delete already stored cookies yourself.</p>\n\n <h3>Third Party Cookies</h3>\n <p>\n We use third-party cookies on our websites. Third-party cookies are stored by\n someone other than the person responsible for the website, in this case by a company\n other than Telia.\n </p>\n <p>\n Telia uses external platforms to communicate digitally, these include the Google\n Marketing Platform and others. The platforms use both first- and third-party cookies\n as well as similar techniques to advertise and follow up the results of the\n advertising.\n </p>\n <p>\n A third-party cookie can be used by several websites to understand and track how you\n browse between different websites. Telia receives information from these cookies,\n but the information can also be used for other purposes determined by third parties.\n Third-party cookies found on our website are covered by each third-party privacy\n policy. Feel free to read these to understand what other purposes the information\n can be used for. Links are in our Cookie Table.\n </p>\n <p>\n For information about which third-party cookies are used on our websites, see our\n Cookie Table. For more information on how Telia handles personal data in connection\n with transfers to third parties, read our Privacy Policy.\n </p>\n\n <h2>Cookies on our websites</h2>\n <p>\n In order for you to have better control over which cookies are used on the websites,\n and thus be able to more easily decide how cookies should be used when you visit our\n websites, we have identified four different categories of cookies. These categories\n are defined based on the purposes for the use of the cookies.\n </p>\n <p>\n In our Cookie Table, you can also see which category each cookie belongs to, for\n what purposes it is used and for how long it is active.\n </p>\n <p>\n We have identified the following four categories of cookies. All categories contain\n cookies which means that data is shared with third parties.\n </p>\n\n <h3>Necessary</h3>\n <p>\n These cookies are needed for our app to work in a secure and correct way. Necessary\n cookies enable you to use our app and us to provide the service you request.\n Necessary cookies make basic functions of the app possible, for example, identifying\n you when you log into My Telia, detecting repeated failed login attempts,\n identifying where you are in the buying process and remembering the items put into\n your shopping basket.\n </p>\n\n <h3>Functionality</h3>\n <p>\n These cookies let us to enable some useful functionalities to make the user\n experience better, for example, to remember your login details and settings.\n </p>\n\n <h3>Analytics</h3>\n <p>\n These cookies give us information about how you use our app and allow us to improve\n the user experience.\n </p>\n\n <h3>Marketing</h3>\n <p>\n These cookies help us and our partners to display personalized and relevant ads\n based on your browsing behavior on our website and in our app, even when you later\n visit other (third parties’) websites. These cookies are used to evaluate the\n effectiveness of our marketingcampaigns, as well as for targeted marketing and\n profiling, regardless of which device(s) you have used. Information collected for\n this purpose may also be combined with other customer and traffic data we have about\n you, if you have given your consent that we may use your traffic data for marketing\n purpose and have not objected to the use of your customer data for marketing\n purposes.\n </p>\n\n <h2>Manage settings</h2>\n <p>\n We save your cookie consent for 12 months. Then we will ask you again. Please note\n that some cookies have a lifespan that exceeds these 12 months. You may therefore\n need to change the settings in your browser and manually delete all cookies.\n </p>\n <p>\n More information on how to turn off cookies can be found in the instructions for\n your browser.\n </p>\n <ul>\n <li>\n <a\n href=\"https://support.google.com/accounts/answer/61416?co=GENIE.Platform%3DDesktop&hl=en\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Google Chrome</a\n >\n </li>\n <li>\n <a\n href=\"https://privacy.microsoft.com/en-us/windows-10-microsoft-edge-and-privacy\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Microsoft Edge</a\n >\n </li>\n <li>\n <a\n href=\"https://support.mozilla.org/en-US/kb/enable-and-disable-cookies-website-preferences\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Mozilla Firefox</a\n >\n </li>\n <li>\n <a\n href=\"https://support.microsoft.com/en-gb/help/17442/windows-internet-explorer-delete-manage-cookies\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Microsoft Internet Explorer</a\n >\n </li>\n <li>\n <a\n href=\"https://www.opera.com/help/tutorials/security/privacy/\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Opera</a\n >\n </li>\n <li>\n <a\n href=\"https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Apple Safari</a\n >\n </li>\n </ul>\n\n <h3>Do Not Track-signals</h3>\n <p>\n If you have chosen to turn on the Do Not Track function in your browser, we will not\n automatically place cookies for marketing on your device. You make other choices in\n your cookie settings.\n </p>\n\n <h3>If you block cookies</h3>\n <p>\n If you choose not to accept our use of cookies, the functionality and performance of\n our websites may deteriorate as certain functions are dependent on cookies. A\n blocking of cookies can therefore mean that the websites’ services do not work as\n they should.\n </p>\n\n <h3>Your security with us</h3>\n <p>\n If you want to read more about your rights and how we protect your privacy, go to\n our privacy policy for\n <a\n href=\"https://www.telia.se/dam/jcr:df2eeb83-50ce-4383-89fc-0613f7615796/Integritetspolicy-privatkunder.pdf\"\n >private customers</a\n >\n (C2B) or\n <a\n href=\"https://www.telia.se/dam/jcr:95b2b4a5-82ca-436b-90e0-873e0a864118/Telia-integritetspolicy-foretag.pdf\"\n >corporate customers</a\n >\n (B2B). You are always welcome to contact us at\n <a href=\"mailto:dpo-se@teliacompany.com\">dpo-se@teliacompany.com</a> if you have any\n questions.\n </p>\n <p>Our cookie policy may change in the future.</p>\n <p>\n More information about cookies can be found at the Swedish Post and Telecom\n Authority (PTS).\n </p>\n\n <h2>Our Cookie Table</h2>\n <p>\n Below, you will find a list of the cookies and similar technologies that we use on\n this website. These cookies are stored on your device by us.\n </p>\n <table>\n <thead>\n <tr>\n <th>Cookie</th>\n <th>Category</th>\n <th>Purpose</th>\n <th>Lifespan</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>alliance-session-v1</td>\n <td>necessary</td>\n <td>Contains the authenticated user.</td>\n <td>1 day</td>\n </tr>\n {APP_COOKIES}\n </tbody>\n </table>\n <style>\n table {\n width: 100%;\n border: 1px solid rgba(0, 0, 0, 0.15);\n }\n th, td {\n text-align: left;\n padding: 3px;\n }\n </style>\n </div>\n </body>\n</html>\n`;\n","import type { Schema } from 'jsonschema';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\ntype JsonSchemas = {\n appConfig: Schema;\n appManifest: Schema;\n};\n\nexport function getJsonSchemas(): JsonSchemas {\n const frameworkDistDirPath = resolve(\n process.cwd(),\n 'node_modules',\n '@telia-ace/alliance-framework',\n 'dist',\n );\n const appConfigSchemaPath = resolve(frameworkDistDirPath, 'config.schema.json');\n const appManifestSchemaPath = resolve(frameworkDistDirPath, 'manifest.schema.json');\n const appConfigSchemaFile = readFileSync(appConfigSchemaPath).toString();\n const appManifestSchemaFile = readFileSync(appManifestSchemaPath).toString();\n const appConfig = JSON.parse(appConfigSchemaFile);\n const appManifest = JSON.parse(appManifestSchemaFile);\n\n return {\n appConfig,\n appManifest,\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport type { LooseObject } from '@/types';\n\nimport { getAppManifests } from './get-app-manifests';\n\ntype PkgJson = LooseObject & {\n name: string;\n version: string;\n};\n\nexport type AlliancePortalDistPkgJson = PkgJson & {\n alliance?: {\n apps?: string[];\n };\n};\n\nexport function getPkgJson(): AlliancePortalDistPkgJson {\n const packageJson = resolve(process.cwd(), 'package.json');\n const pkgJsonFile = readFileSync(packageJson).toString();\n return JSON.parse(pkgJsonFile);\n}\n\nexport async function getManifests(pkgJson: AlliancePortalDistPkgJson) {\n if (!pkgJson || !pkgJson.alliance || !pkgJson.alliance.apps) {\n throw new Error('Alliance apps not defined in package.json.');\n }\n\n const manifestArray = await getAppManifests(pkgJson.alliance.apps);\n\n return manifestArray.reduce((acc, curr: LooseObject) => {\n acc[curr.name] = curr;\n\n return acc;\n }, {});\n}\n","import { rmSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport type { LooseObject } from '../types';\n\nasync function createTempModuleAndImport<T>(moduleString: string, fileName: string): Promise<T> {\n const file = resolve(process.cwd(), `${fileName}.mjs`);\n writeFileSync(file, moduleString);\n const importedModule = await import(`file:///${file}`);\n rmSync(file, { force: true });\n return importedModule;\n}\n\n// Creates a temporary ES module and imports app manifests for all requested apps\n// This reusable utility can access all node modules available in the directory where it is ran\nexport async function getAppManifests(apps: string[]): Promise<LooseObject[]> {\n const moduleStringParts = [];\n const manifestImportVariables = [];\n\n for (const packageName of apps) {\n const manifestImportVariable = `app${apps.indexOf(packageName)}`;\n manifestImportVariables.push(manifestImportVariable);\n moduleStringParts.push(`import ${manifestImportVariable} from '${packageName}/manifest';`);\n }\n\n moduleStringParts.push(`export default [${manifestImportVariables.join(', ')}];`);\n\n const result = await createTempModuleAndImport<{ default: LooseObject[] }>(\n moduleStringParts.join('\\n'),\n 'app-manifests',\n );\n\n return result.default;\n}\n","import _slugify from 'slugify';\n\nexport function slugify(name: string) {\n return _slugify(name, { strict: true, replacement: '-', lower: true });\n}\n","import type { RequestHandler } from 'express';\nimport pino from 'pino';\nimport type { z } from 'zod';\n\nimport type { zSharedConfig } from './constants';\n\ntype LogFn = (msg: string, obj?: any) => void;\ntype PartialConfig = Pick<z.infer<typeof zSharedConfig>, 'SERVICE_LOG_LEVEL'>;\n\nexport type Logger = {\n fatal: LogFn;\n error: LogFn;\n warn: LogFn;\n info: LogFn;\n debug: LogFn;\n trace: LogFn;\n silent: LogFn;\n child(): Logger;\n level: PartialConfig['SERVICE_LOG_LEVEL'];\n};\n\nfunction logFn(\n instance: ReturnType<typeof pino>,\n): (level: PartialConfig['SERVICE_LOG_LEVEL']) => LogFn {\n return (level) => {\n return (msg: string, data?: any): void => instance[level]({ ...data, msg });\n };\n}\n\nexport function createLogger(config: PartialConfig) {\n const instance = pino({\n level: config.SERVICE_LOG_LEVEL,\n redact: [\n 'authorization',\n 'headers.authorization',\n 'req.headers.authorization',\n 'res.headers.authorization',\n 'req.headers.cookie',\n 'res.headers[\"set-cookie\"]',\n ],\n });\n\n return {\n fatal: logFn(instance)('fatal'),\n error: logFn(instance)('error'),\n warn: logFn(instance)('warn'),\n info: logFn(instance)('info'),\n debug: logFn(instance)('debug'),\n trace: logFn(instance)('trace'),\n silent: logFn(instance)('silent'),\n child: () => createLogger(config),\n level: config.SERVICE_LOG_LEVEL,\n };\n}\n\nexport function requestLoggerHandler(logger: Logger): RequestHandler {\n return (req, _, next) => {\n logger.trace('received request', {\n url: req.url,\n params: req.params,\n query: req.query,\n body: req.body,\n });\n\n return next();\n };\n}\n","import { AllianceHeaders } from '@/constants';\n\nexport enum GatewayErrorCode {\n NoObjectId = 10001,\n NoTargetAppHeader = 10002,\n NoTargetWorkspaceHeader = 10003,\n NoManifestsInCache = 10004,\n NoDevSessionInCache = 10005,\n NoManifest = 10006,\n NoRequestContext = 10007,\n NoUserInRequestContext = 10008,\n NoAppInRequestContext = 10009,\n NoWorkspaceInRequestContext = 10010,\n NoUserPermissionsInRequestContext = 10012,\n WorkspacePermissionDenied = 10013,\n NoTargetUrlHeader = 10014,\n NoSessionInRedisCache = 10015,\n}\n\nexport enum DataErrorCode {\n NoPublicKey = 11000,\n NoAuthHeader = 11001,\n FailedFileUpload = 11002,\n FailedFileDownload = 11003,\n}\n\nexport enum PortalErrorCode {\n NoObjectId = 12000,\n}\n\nexport type ErrorCode = GatewayErrorCode | DataErrorCode | PortalErrorCode;\n\ntype Errors = {\n [key in ErrorCode]: {\n statusCode: number;\n msg: string;\n };\n};\n\nexport const errors: Errors = {\n [GatewayErrorCode.NoObjectId]: {\n statusCode: 401,\n msg: 'No object id available on authenticated user.',\n },\n [GatewayErrorCode.NoTargetAppHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetApp}'.`,\n },\n [GatewayErrorCode.NoTargetWorkspaceHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetWorkspace}'.`,\n },\n [GatewayErrorCode.NoTargetUrlHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetUrl}'.`,\n },\n [GatewayErrorCode.NoManifestsInCache]: {\n statusCode: 500,\n msg: 'App manifests missing in cache.',\n },\n [GatewayErrorCode.NoDevSessionInCache]: {\n statusCode: 500,\n msg: 'No dev session in memory cache.',\n },\n [GatewayErrorCode.NoSessionInRedisCache]: {\n statusCode: 401,\n msg: 'Could not find user session in Redis server.',\n },\n [GatewayErrorCode.NoManifest]: {\n statusCode: 500,\n msg: \"Could not find manifest for app '{{appSlug}}'.\",\n },\n [GatewayErrorCode.NoRequestContext]: {\n statusCode: 500,\n msg: 'No request context.',\n },\n [GatewayErrorCode.NoUserInRequestContext]: {\n statusCode: 500,\n msg: 'No user in request context.',\n },\n [GatewayErrorCode.NoAppInRequestContext]: {\n statusCode: 500,\n msg: 'No app in request context.',\n },\n [GatewayErrorCode.NoWorkspaceInRequestContext]: {\n statusCode: 500,\n msg: 'No workspace in request context.',\n },\n [GatewayErrorCode.NoUserPermissionsInRequestContext]: {\n statusCode: 500,\n msg: 'No user permissions in request context.',\n },\n [GatewayErrorCode.WorkspacePermissionDenied]: {\n statusCode: 403,\n msg: 'User does not have access to the current workspace.',\n },\n\n [DataErrorCode.NoPublicKey]: {\n statusCode: 401,\n msg: 'No public key available to decode JWT.',\n },\n [DataErrorCode.NoAuthHeader]: {\n statusCode: 401,\n msg: 'No authorization header found.',\n },\n [DataErrorCode.FailedFileUpload]: {\n statusCode: 500,\n msg: 'Something went wrong when trying to upload a file to the S3 storage.',\n },\n [DataErrorCode.FailedFileDownload]: {\n statusCode: 500,\n msg: 'Something went wrong when trying to download a file to the S3 storage.',\n },\n\n [PortalErrorCode.NoObjectId]: {\n statusCode: 401,\n msg: 'No object id found in user claims.',\n },\n};\n","import type { ErrorRequestHandler } from 'express';\n\nimport type { Logger } from '@/logger';\n\nimport { type ErrorCode, errors } from './codes';\n\nexport class AllianceError extends Error {\n public info: string = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${this.errorCode}`;\n public statusCode: number;\n constructor(\n public errorCode: ErrorCode,\n variables: Record<string, string> = {},\n ) {\n const { msg, statusCode } = errors[errorCode];\n const message = parseTemplates(msg, variables);\n super(message);\n this.message = message;\n this.statusCode = statusCode;\n }\n}\n\nfunction parseTemplates(message: string, variables: Record<string, string>) {\n return Object.entries(variables).reduce((acc, [key, value]) => {\n return acc.replaceAll(`{{${key}}}`, value);\n }, message);\n}\n\nexport function requestErrorHandler(logger: Logger): ErrorRequestHandler {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (err, req, res, _next) => {\n const error = {\n cause: err.cause,\n message: err.message,\n status: err.status || err.statusCode || err.code,\n info: err.info,\n };\n\n logger.error('error when processing request', {\n url: req.url,\n body: req.body,\n error,\n });\n\n return res.status(error.status).json(error);\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/auth/tokens.ts","../src/constants/config.ts","../src/constants/headers.ts","../src/distribution/create-public-files.ts","../src/distribution/cookie-policy.ts","../src/distribution/json-schemas.ts","../src/distribution/pkg-json.ts","../src/distribution/get-app-manifests.ts","../src/slugify.ts","../src/logger.ts","../src/errors/codes.ts","../src/errors/errors.ts"],"names":["AllianceHeaders","writeFileSync","resolve","readFileSync","errors","GatewayErrorCode","DataErrorCode"],"mappings":";AAAA,OAAO,SAAS;AAChB,SAAS,uBAAuB;;;ACDhC,SAAS,SAAS;AAEX,IAAM,eAAe,EAAE,KAAK,CAAC,QAAQ,OAAO,CAAC,EAAE,UAAU,CAAC,YAAY,YAAY,MAAM;AAExF,IAAM,kBAAkB,EAAE,OAAO,EAAE,IAAI,CAAC;AAExC,IAAM,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EAEA,CAAC,qBAA0B,GAAG;AAAA,IAC1B,YAAY;AAAA,IACZ,KAAK;AAAA,EACT;AACJ;;;AChHO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAGrC,YACW,WACP,YAAoC,CAAC,GACvC;AACE,UAAM,EAAE,KAAK,WAAW,IAAI,OAAO,SAAS;AAC5C,UAAM,UAAU,eAAe,KAAK,SAAS;AAC7C,UAAM,OAAO;AALN;AAHX,SAAO,OAAe,sEAAsE,KAAK,SAAS;AAStG,SAAK,UAAU;AACf,SAAK,aAAa;AAAA,EACtB;AACJ;AAEA,SAAS,eAAe,SAAiB,WAAmC;AACxE,SAAO,OAAO,QAAQ,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AAC3D,WAAO,IAAI,WAAW,KAAK,GAAG,MAAM,KAAK;AAAA,EAC7C,GAAG,OAAO;AACd;AAEO,SAAS,oBAAoB,QAAqC;AAErE,SAAO,CAAC,KAAK,KAAK,KAAK,UAAU;AAC7B,UAAM,QAAQ;AAAA,MACV,OAAO,IAAI;AAAA,MACX,SAAS,IAAI;AAAA,MACb,QAAQ,IAAI,UAAU,IAAI,cAAc,IAAI;AAAA,MAC5C,MAAM,IAAI;AAAA,IACd;AAEA,WAAO,MAAM,iCAAiC;AAAA,MAC1C,KAAK,IAAI;AAAA,MACT,MAAM,IAAI;AAAA,MACV;AAAA,IACJ,CAAC;AAED,WAAO,IAAI,OAAO,MAAM,MAAM,EAAE,KAAK,KAAK;AAAA,EAC9C;AACJ","sourcesContent":["import jwt from 'jsonwebtoken';\nimport { createPublicKey } from 'node:crypto';\nimport type { z } from 'zod';\n\nimport { zSharedConfig } from '@/constants';\n\ntype BearerTokenSettings = {\n privateKey: string;\n aud: string;\n sub: string;\n name: string;\n user: {\n type: string;\n permissions: string[];\n email: string;\n };\n workspace: { name: string; slug: string };\n expiration?: string;\n};\n\nconst zKeyConfig = zSharedConfig.pick({ JWT_PRIVATE_KEY: true, JWT_PUBLIC_CSP_KEY: true });\n\nexport function createBearerToken({\n privateKey,\n aud,\n sub,\n name,\n user,\n workspace,\n expiration = '1h',\n}: BearerTokenSettings) {\n const token = jwt.sign(\n {\n iss: 'Alliance',\n aud,\n sub,\n name,\n 'https://alliance.teliacompany.net/user_type': user.type,\n 'https://alliance.teliacompany.net/user_email': user.email,\n 'https://alliance.teliacompany.net/user_privileges': user.permissions,\n 'https://alliance.teliacompany.net/workspace': workspace.slug,\n 'https://alliance.teliacompany.net/workspace_name': workspace.name,\n 'https://alliance.teliacompany.net/tenant': workspace.slug,\n 'https://alliance.teliacompany.net/tenant_name': workspace.name,\n } as BearerTokenContent,\n privateKey,\n {\n expiresIn: expiration,\n algorithm: 'RS256',\n },\n );\n\n return `Bearer ${token}`;\n}\n\nexport type BearerTokenContent = {\n iss: 'Alliance';\n aud: string;\n sub: string;\n name: string;\n 'https://alliance.teliacompany.net/user_type': string;\n 'https://alliance.teliacompany.net/user_email': string;\n 'https://alliance.teliacompany.net/user_privileges': string[];\n 'https://alliance.teliacompany.net/workspace': string;\n 'https://alliance.teliacompany.net/workspace_name': string;\n};\n\nexport function getPrivateKey(config: Pick<z.infer<typeof zKeyConfig>, 'JWT_PRIVATE_KEY'>) {\n return (\n '-----BEGIN RSA PRIVATE KEY-----\\n' +\n config.JWT_PRIVATE_KEY +\n '\\n-----END RSA PRIVATE KEY-----'\n );\n}\n\nexport function createSystemUserToken(config: Pick<z.infer<typeof zKeyConfig>, 'JWT_PRIVATE_KEY'>) {\n return createBearerToken({\n aud: 'system',\n sub: 'system',\n name: 'system',\n workspace: {\n slug: 'system',\n name: 'system',\n },\n user: {\n type: 'system',\n permissions: [],\n email: 'system',\n },\n privateKey: getPrivateKey(config),\n });\n}\n\nexport type PublicKeys = {\n pkcs: string;\n spki: string;\n csp: string;\n};\n\nexport function createPublicKeys(config: z.infer<typeof zKeyConfig>): PublicKeys {\n const priv = getPrivateKey(config);\n const generatedKey = createPublicKey(priv);\n\n return {\n pkcs: generatedKey.export({ type: 'pkcs1', format: 'pem' }).toString().trim(),\n spki: generatedKey.export({ type: 'spki', format: 'pem' }).toString().trim(),\n csp: config.JWT_PUBLIC_CSP_KEY,\n };\n}\n\nexport function getCleanPublicKey(type: keyof PublicKeys, keys: PublicKeys): string {\n return keys[type]\n .replace('-----BEGIN RSA PUBLIC KEY-----', '')\n .replace('-----END RSA PUBLIC KEY-----', '')\n .replace('-----BEGIN PUBLIC KEY-----', '')\n .replace('-----END PUBLIC KEY-----', '')\n .trim()\n .replaceAll('\\n', '');\n}\n","import { z } from 'zod';\n\nexport const zBooleanEnum = z.enum(['true', 'false']).transform((strBool) => strBool === 'true');\n\nexport const zNonEmptyString = z.string().min(1);\n\nexport const zSharedConfig = z.object({\n /**\n * Name for the cookie storing the user session\n *\n * Optional, defaults to \"alliance-auth\"\n */\n AUTH_COOKIE_NAME: zNonEmptyString.default('alliance-auth'),\n /**\n * Secret to use when signing the user session cookie\n *\n * Optional, defaults to \"zlLZBlk7wt8lypP5lA4D\"\n */\n AUTH_COOKIE_SECRET: zNonEmptyString.default('zlLZBlk7wt8lypP5lA4D'),\n /**\n * Endpoint to use when communicating with the Data API\n */\n DB_ENDPOINT: zNonEmptyString,\n /**\n * Private key to use when signing JWT tokens\n *\n * Optional, defaults to \"MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLYNqnOkQnEa8O8xbthQhiI0k1GGJT+GCQcATUPeEbaCFXonOrJm+CyuMmQWYLFF3NbE5NllU1jz9PYHzp2hAgAx8WGeretTvpEA1dE2gvXNESGbQ8FxQIDAQABAoIBAAjTJmud1348eGAfL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cgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw\"\n */\n JWT_PUBLIC_CSP_KEY: z\n .string()\n .min(1)\n .default(\n 'BgIAAACkAABSU0ExAAgAAAEAAQDFBQ9thkQ01wvaRFcDRPpOrbd6hsXHAAiEdjof2NPPY02VZZMTW3MXxYJZkMm4suCbyeqc6FUI2kZ4DzUBHCQY/pQYRk3SiBhCYbvFvMNrxAmRzqk22FLAHedKEnJPgZpU9J6LCrfgw/do/d5YFk2vE/PYWD8rqev+LaegJ2DCwkklOMoaBByPGQj+0BoXZVRx7qLYRdq1IgNk/yHvDu5OkLyt97E/G2l7zdW04i9SiPF+yaEKJ8NEjViowY0tAdNYpLFsezhrLU3ev0rVeUrDEq+8f8uPUaYnAT8t+tmgcgkFi+SzQr2YQmrZ7SMKTuIqJ2CAoTqUmNBC3znOjmqw',\n ),\n /**\n * Log level to output\n *\n * Supports \"silent\" | \"fatal\" | \"error\" | \"warn\" | \"info\" | \"debug\" | \"trace\"\n *\n * Optional, defaults to \"trace\"\n */\n SERVICE_LOG_LEVEL: z\n .enum(['silent', 'fatal', 'error', 'warn', 'info', 'debug', 'trace'])\n .default('trace'),\n /**\n * Port to run the service on.\n *\n * Optional, defaults to \"3000\"\n */\n SERVICE_PORT: zNonEmptyString.transform(Number).default('3000'),\n /**\n * Url to redis server to use when storing / reading user session information.\n */\n REDIS_HOST: zNonEmptyString,\n /**\n * Password to redis server to use when storing / reading user session information.\n *\n * Optional\n */\n REDIS_PASSWORD: zNonEmptyString.optional(),\n});\n","export enum AllianceHeaders {\n TargetUrl = 'alliance-target-url',\n TargetApp = 'alliance-target-app',\n TargetWorkspace = 'alliance-target-workspace',\n}\n","import { validate } from 'jsonschema';\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport { generateCookiePolicyHtml } from './cookie-policy';\nimport { getJsonSchemas } from './json-schemas';\nimport { getManifests, getPkgJson } from './pkg-json';\n\nconst PUBLIC_DIR_NAME = 'public';\nconst MANIFESTS_FILE_NAME = 'manifests.json';\nconst COOKIE_POLICY_FILE_NAME = 'cookie-policy.html';\nconst APP_CONFIG_SCHEMA_FILE_NAME = 'config.schema.json';\nconst APP_MANIFEST_SCHEMA_FILE_NAME = 'manifest.schema.json';\n\nexport async function createPublicDistributionFiles() {\n const pkgJson = getPkgJson();\n const manifests = await getManifests(pkgJson);\n const schemas = getJsonSchemas();\n\n // Validate all app schemas\n for (const appName in manifests) {\n const manifest = manifests[appName];\n\n const validationResult = validate(manifest, schemas.appManifest);\n\n if (validationResult.errors.length) {\n const errors = validationResult.errors.map((e) => JSON.stringify(e, null, 2));\n throw new Error(\n `Validation of app manifest for app '${appName}' failed with the following errors:\\n${errors.join(\n '\\n',\n )}`,\n );\n }\n }\n\n // Make sure public dir exists\n const publicDirPath = resolve(process.cwd(), PUBLIC_DIR_NAME);\n if (!existsSync(publicDirPath)) {\n mkdirSync(publicDirPath);\n }\n\n // Create manifests file\n const manifestsFilePath = resolve(publicDirPath, MANIFESTS_FILE_NAME);\n writeFileSync(manifestsFilePath, JSON.stringify(manifests));\n\n // Create cookie policy document\n const cookiePolicyFilePath = resolve(publicDirPath, COOKIE_POLICY_FILE_NAME);\n writeFileSync(cookiePolicyFilePath, generateCookiePolicyHtml(manifests));\n\n // Create JSON schema files\n const appConfigSchemaFilePath = resolve(publicDirPath, APP_CONFIG_SCHEMA_FILE_NAME);\n const appManifestSchemaFilePath = resolve(publicDirPath, APP_MANIFEST_SCHEMA_FILE_NAME);\n writeFileSync(appConfigSchemaFilePath, JSON.stringify(schemas.appConfig));\n writeFileSync(appManifestSchemaFilePath, JSON.stringify(schemas.appManifest));\n}\n","import type { LooseObject } from '@/types';\n\nexport function generateCookiePolicyHtml(appManifests: LooseObject) {\n const cookiePolicyTableRows: string[] = [];\n\n for (const appName in appManifests) {\n const manifest = appManifests[appName];\n if (!manifest.storage) {\n continue;\n }\n\n for (const [key, value] of Object.entries(manifest.storage)) {\n const tableRow = createCookiePolicyTableRow(key, value as LooseObject);\n cookiePolicyTableRows.push(tableRow);\n }\n }\n\n return cookiePolicyHtml.replace('{APP_COOKIES}', cookiePolicyTableRows.join(''));\n}\n\nfunction createCookiePolicyTableRow(key: string, claimEntry: LooseObject) {\n const rows = ['<tr>'];\n const { category, purpose, lifespan } = claimEntry;\n rows.push(`<td>${key}</td>`);\n rows.push(`<td>${category}</td>`);\n rows.push(`<td>${purpose}</td>`);\n rows.push(`<td>${lifespan}</td>`);\n rows.push('</tr>');\n return rows.join('');\n}\n\nconst cookiePolicyHtml = `\n<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>ACE Alliance - Cookie Policy</title>\n <link\n rel=\"icon\"\n href=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAGcElEQVRYha2Xe4xUVx3HP7/fPTOzDLO7sw8RlzWlZEtp2dCy0qIVWltKU/UPDZH6ijXWEK2odPcPa2qbhpi2kSa7blSStsFUjNq0lWCMaVMx8rAm22IJMJRHCqFC6BJ22eEx+5p7z88/7sywC7uwgCe5mXsz5/y+j/M753eOcJ2tK5sDyBrME2gBmkBq43/tnMERgXdAjrbn518yXq4RNA3cB/J54HNiMhfEicm4oAYghmHexN4Dew5k01giUybQlc1h0CbI9zC+Imi9mCAIYhoHsnI4KcNjYoDhxWPxsxFY1Z5vHQVwVwSu3Qdid4E8rSb3i6mqKYwBjpWX1V/QZBiYYWIIiifCw8Mm/vS7L/W237FqJno58M5srgmxP4npjsAHDwTeaeAdagGBdwQWoBYgFqCmqGlMqvTE3+U+ipbeE+ngB42Lde6kDnRmcwisAHlBfdBYCYxStp3y7xjTJ51RA0XxgGCkasQFSfkW8NQlBDqzORVYK6ZPqAU6ThUyqd0TN7mQDRZ/CULzvVVeRO68xIGubE6BbjH9oVqA+thaQccpvjLwRDTit2RG/fxVG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wV+FnLU+HiZ2tUpxtbf9Tnj20vOJPo2fZ8688u7n3pmdB42Yt/xUuESVQ+yVJexZNtVmbQ2JYIH9zcGC5/pd71Hxjxm5f1cnzboDPx7xs8M9G4CSV1ZnOZICE7GNXbKweTMU7EA6USoemeVLhgTYame1Nu4MBI2PN0ng+3DDovIZFG5w37bEe+dc+UCQC8/ZtjzX07i/88saU4J8yLXiAhaCC+fn7Sz/7iNFq+mqZ6TuD6do+Gu7vPcuQvBRf62LlIQ2/Y1zvyra9OhnPZSf1g58k5I6ftDSnqnNFTaOACqmclfP0tSa3KBjrc5/2Hbwz7Q38ocHLniDM8XjxeIrxG3rA16vXXj529dVKMK2bVL2fkmhrmJ/9cPy91Z2ZGwhMqQx95TudC8gdCZx4obbMVAhqNGvaoCr99bKD1svGntK4647vg84J8X021PBXlK5gJGJWr11GDb3fkW7dPJfaUi3539iARxSUCz4AsERMVpHwDxMTyhq0HftGRbz071bhXfeooXVJvBR4EbgSGgR6Bt9qvArjc/gfZzPoCTDB+AgAAAABJRU5ErkJggg==\"\n />\n <style>\n @charset \"UTF-8\";\n @import 'https://cdn.voca.teliacompany.com/fonts/TeliaSansV10/TeliaSans.css';\n @import 'https://fonts.googleapis.com/css?family=Reenie+Beanie';\n\n body {\n font-family: TeliaSans, Helvetica, Arial, Lucida Grande, sans-serif;\n }\n\n body > div {\n max-width: 1000px;\n margin: 0 auto;\n padding: 0 40px 40px;\n }\n </style>\n </head>\n\n <body>\n <div>\n <h1>Cookie Policy</h1>\n <p>\n On our websites, we use cookies and other similar technologies. You can choose\n whether you want to allow our websites to store cookies on your computer or not. You\n can change your choices at any time.\n </p>\n\n <h2>Your consent is required</h2>\n <p>\n You choose whether you want to accept cookies on your device or not. Your consent is\n required for the use of cookies, but not for such cookies that are necessary to\n enable the service that you as a user have requested. If you do not accept our use\n of cookies, or if you have previously approved our use and have changed your mind,\n you can return to your cookie settings at any time and change your choices. You do\n this by clicking on the cookie button/link. You may also need to change the settings\n in your browser and manually delete cookies to clear your device of previously\n stored cookies.\n </p>\n\n <h2>What are cookies?</h2>\n <p>\n A cookie is a small text file that is stored on your computer by the web browser\n while browsing a website. When we refer to cookies (“cookies”) in this policy, other\n similar technologies and tools that retrieve and store information in your browser,\n and in some cases forward such information to third parties, in a manner similar to\n cookies. Examples are pixels, local storage, session storage and fingerprinting.\n </p>\n <p>\n The websites will “remember” and “recognize” you. This can be done by placing\n cookies in three different ways;\n </p>\n <ul>\n <li>The session ends, ie until you close the window in your browser.</li>\n <li>\n Time-limited, ie the cookie has a predetermined lifespan. The time may vary\n between different cookies.\n </li>\n <li>\n Until further notice, ie the information remains until you choose to delete it\n yourself. This applies to local storage.\n </li>\n </ul>\n <p>You can always go into your browser and delete already stored cookies yourself.</p>\n\n <h3>Third Party Cookies</h3>\n <p>\n We use third-party cookies on our websites. Third-party cookies are stored by\n someone other than the person responsible for the website, in this case by a company\n other than Telia.\n </p>\n <p>\n Telia uses external platforms to communicate digitally, these include the Google\n Marketing Platform and others. The platforms use both first- and third-party cookies\n as well as similar techniques to advertise and follow up the results of the\n advertising.\n </p>\n <p>\n A third-party cookie can be used by several websites to understand and track how you\n browse between different websites. Telia receives information from these cookies,\n but the information can also be used for other purposes determined by third parties.\n Third-party cookies found on our website are covered by each third-party privacy\n policy. Feel free to read these to understand what other purposes the information\n can be used for. Links are in our Cookie Table.\n </p>\n <p>\n For information about which third-party cookies are used on our websites, see our\n Cookie Table. For more information on how Telia handles personal data in connection\n with transfers to third parties, read our Privacy Policy.\n </p>\n\n <h2>Cookies on our websites</h2>\n <p>\n In order for you to have better control over which cookies are used on the websites,\n and thus be able to more easily decide how cookies should be used when you visit our\n websites, we have identified four different categories of cookies. These categories\n are defined based on the purposes for the use of the cookies.\n </p>\n <p>\n In our Cookie Table, you can also see which category each cookie belongs to, for\n what purposes it is used and for how long it is active.\n </p>\n <p>\n We have identified the following four categories of cookies. All categories contain\n cookies which means that data is shared with third parties.\n </p>\n\n <h3>Necessary</h3>\n <p>\n These cookies are needed for our app to work in a secure and correct way. Necessary\n cookies enable you to use our app and us to provide the service you request.\n Necessary cookies make basic functions of the app possible, for example, identifying\n you when you log into My Telia, detecting repeated failed login attempts,\n identifying where you are in the buying process and remembering the items put into\n your shopping basket.\n </p>\n\n <h3>Functionality</h3>\n <p>\n These cookies let us to enable some useful functionalities to make the user\n experience better, for example, to remember your login details and settings.\n </p>\n\n <h3>Analytics</h3>\n <p>\n These cookies give us information about how you use our app and allow us to improve\n the user experience.\n </p>\n\n <h3>Marketing</h3>\n <p>\n These cookies help us and our partners to display personalized and relevant ads\n based on your browsing behavior on our website and in our app, even when you later\n visit other (third parties’) websites. These cookies are used to evaluate the\n effectiveness of our marketingcampaigns, as well as for targeted marketing and\n profiling, regardless of which device(s) you have used. Information collected for\n this purpose may also be combined with other customer and traffic data we have about\n you, if you have given your consent that we may use your traffic data for marketing\n purpose and have not objected to the use of your customer data for marketing\n purposes.\n </p>\n\n <h2>Manage settings</h2>\n <p>\n We save your cookie consent for 12 months. Then we will ask you again. Please note\n that some cookies have a lifespan that exceeds these 12 months. You may therefore\n need to change the settings in your browser and manually delete all cookies.\n </p>\n <p>\n More information on how to turn off cookies can be found in the instructions for\n your browser.\n </p>\n <ul>\n <li>\n <a\n href=\"https://support.google.com/accounts/answer/61416?co=GENIE.Platform%3DDesktop&hl=en\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Google Chrome</a\n >\n </li>\n <li>\n <a\n href=\"https://privacy.microsoft.com/en-us/windows-10-microsoft-edge-and-privacy\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Microsoft Edge</a\n >\n </li>\n <li>\n <a\n href=\"https://support.mozilla.org/en-US/kb/enable-and-disable-cookies-website-preferences\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Mozilla Firefox</a\n >\n </li>\n <li>\n <a\n href=\"https://support.microsoft.com/en-gb/help/17442/windows-internet-explorer-delete-manage-cookies\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Microsoft Internet Explorer</a\n >\n </li>\n <li>\n <a\n href=\"https://www.opera.com/help/tutorials/security/privacy/\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Opera</a\n >\n </li>\n <li>\n <a\n href=\"https://support.apple.com/guide/safari/manage-cookies-and-website-data-sfri11471/mac\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >Apple Safari</a\n >\n </li>\n </ul>\n\n <h3>Do Not Track-signals</h3>\n <p>\n If you have chosen to turn on the Do Not Track function in your browser, we will not\n automatically place cookies for marketing on your device. You make other choices in\n your cookie settings.\n </p>\n\n <h3>If you block cookies</h3>\n <p>\n If you choose not to accept our use of cookies, the functionality and performance of\n our websites may deteriorate as certain functions are dependent on cookies. A\n blocking of cookies can therefore mean that the websites’ services do not work as\n they should.\n </p>\n\n <h3>Your security with us</h3>\n <p>\n If you want to read more about your rights and how we protect your privacy, go to\n our privacy policy for\n <a\n href=\"https://www.telia.se/dam/jcr:df2eeb83-50ce-4383-89fc-0613f7615796/Integritetspolicy-privatkunder.pdf\"\n >private customers</a\n >\n (C2B) or\n <a\n href=\"https://www.telia.se/dam/jcr:95b2b4a5-82ca-436b-90e0-873e0a864118/Telia-integritetspolicy-foretag.pdf\"\n >corporate customers</a\n >\n (B2B). You are always welcome to contact us at\n <a href=\"mailto:dpo-se@teliacompany.com\">dpo-se@teliacompany.com</a> if you have any\n questions.\n </p>\n <p>Our cookie policy may change in the future.</p>\n <p>\n More information about cookies can be found at the Swedish Post and Telecom\n Authority (PTS).\n </p>\n\n <h2>Our Cookie Table</h2>\n <p>\n Below, you will find a list of the cookies and similar technologies that we use on\n this website. These cookies are stored on your device by us.\n </p>\n <table>\n <thead>\n <tr>\n <th>Cookie</th>\n <th>Category</th>\n <th>Purpose</th>\n <th>Lifespan</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>alliance-session-v1</td>\n <td>necessary</td>\n <td>Contains the authenticated user.</td>\n <td>1 day</td>\n </tr>\n {APP_COOKIES}\n </tbody>\n </table>\n <style>\n table {\n width: 100%;\n border: 1px solid rgba(0, 0, 0, 0.15);\n }\n th, td {\n text-align: left;\n padding: 3px;\n }\n </style>\n </div>\n </body>\n</html>\n`;\n","import type { Schema } from 'jsonschema';\nimport { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\ntype JsonSchemas = {\n appConfig: Schema;\n appManifest: Schema;\n};\n\nexport function getJsonSchemas(): JsonSchemas {\n const frameworkDistDirPath = resolve(\n process.cwd(),\n 'node_modules',\n '@telia-ace/alliance-framework',\n 'dist',\n );\n const appConfigSchemaPath = resolve(frameworkDistDirPath, 'config.schema.json');\n const appManifestSchemaPath = resolve(frameworkDistDirPath, 'manifest.schema.json');\n const appConfigSchemaFile = readFileSync(appConfigSchemaPath).toString();\n const appManifestSchemaFile = readFileSync(appManifestSchemaPath).toString();\n const appConfig = JSON.parse(appConfigSchemaFile);\n const appManifest = JSON.parse(appManifestSchemaFile);\n\n return {\n appConfig,\n appManifest,\n };\n}\n","import { readFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport type { LooseObject } from '@/types';\n\nimport { getAppManifests } from './get-app-manifests';\n\ntype PkgJson = LooseObject & {\n name: string;\n version: string;\n};\n\nexport type AlliancePortalDistPkgJson = PkgJson & {\n alliance?: {\n apps?: string[];\n };\n};\n\nexport function getPkgJson(): AlliancePortalDistPkgJson {\n const packageJson = resolve(process.cwd(), 'package.json');\n const pkgJsonFile = readFileSync(packageJson).toString();\n return JSON.parse(pkgJsonFile);\n}\n\nexport async function getManifests(pkgJson: AlliancePortalDistPkgJson) {\n if (!pkgJson || !pkgJson.alliance || !pkgJson.alliance.apps) {\n throw new Error('Alliance apps not defined in package.json.');\n }\n\n const manifestArray = await getAppManifests(pkgJson.alliance.apps);\n\n return manifestArray.reduce((acc, curr: LooseObject) => {\n acc[curr.name] = curr;\n\n return acc;\n }, {});\n}\n","import { rmSync, writeFileSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nimport type { LooseObject } from '../types';\n\nasync function createTempModuleAndImport<T>(moduleString: string, fileName: string): Promise<T> {\n const file = resolve(process.cwd(), `${fileName}.mjs`);\n writeFileSync(file, moduleString);\n const importedModule = await import(`file:///${file}`);\n rmSync(file, { force: true });\n return importedModule;\n}\n\n// Creates a temporary ES module and imports app manifests for all requested apps\n// This reusable utility can access all node modules available in the directory where it is ran\nexport async function getAppManifests(apps: string[]): Promise<LooseObject[]> {\n const moduleStringParts = [];\n const manifestImportVariables = [];\n\n for (const packageName of apps) {\n const manifestImportVariable = `app${apps.indexOf(packageName)}`;\n manifestImportVariables.push(manifestImportVariable);\n moduleStringParts.push(`import ${manifestImportVariable} from '${packageName}/manifest';`);\n }\n\n moduleStringParts.push(`export default [${manifestImportVariables.join(', ')}];`);\n\n const result = await createTempModuleAndImport<{ default: LooseObject[] }>(\n moduleStringParts.join('\\n'),\n 'app-manifests',\n );\n\n return result.default;\n}\n","import _slugify from 'slugify';\n\nexport function slugify(value: string, replacement: string = '-') {\n return _slugify(value, { strict: true, replacement, lower: true });\n}\n","import type { RequestHandler } from 'express';\nimport pino from 'pino';\nimport type { z } from 'zod';\n\nimport type { zSharedConfig } from './constants';\n\ntype LogFn = (msg: string, obj?: any) => void;\ntype PartialConfig = Pick<z.infer<typeof zSharedConfig>, 'SERVICE_LOG_LEVEL'>;\n\nexport type Logger = {\n fatal: LogFn;\n error: LogFn;\n warn: LogFn;\n info: LogFn;\n debug: LogFn;\n trace: LogFn;\n silent: LogFn;\n child(): Logger;\n level: PartialConfig['SERVICE_LOG_LEVEL'];\n};\n\nfunction logFn(\n instance: ReturnType<typeof pino>,\n): (level: PartialConfig['SERVICE_LOG_LEVEL']) => LogFn {\n return (level) => {\n return (msg: string, data?: any): void => instance[level]({ ...data, msg });\n };\n}\n\nexport function createLogger(config: PartialConfig) {\n const instance = pino({\n level: config.SERVICE_LOG_LEVEL,\n redact: [\n 'authorization',\n 'headers.authorization',\n 'req.headers.authorization',\n 'res.headers.authorization',\n 'req.headers.cookie',\n 'res.headers[\"set-cookie\"]',\n ],\n });\n\n return {\n fatal: logFn(instance)('fatal'),\n error: logFn(instance)('error'),\n warn: logFn(instance)('warn'),\n info: logFn(instance)('info'),\n debug: logFn(instance)('debug'),\n trace: logFn(instance)('trace'),\n silent: logFn(instance)('silent'),\n child: () => createLogger(config),\n level: config.SERVICE_LOG_LEVEL,\n };\n}\n\nexport function requestLoggerHandler(logger: Logger): RequestHandler {\n return (req, _, next) => {\n logger.trace('received request', {\n url: req.url,\n params: req.params,\n query: req.query,\n body: req.body,\n });\n\n return next();\n };\n}\n","import { AllianceHeaders } from '@/constants';\n\nexport enum GatewayErrorCode {\n NoObjectId = 10001,\n NoTargetAppHeader = 10002,\n NoTargetWorkspaceHeader = 10003,\n NoManifestsInCache = 10004,\n NoDevSessionInCache = 10005,\n NoManifest = 10006,\n NoRequestContext = 10007,\n NoUserInRequestContext = 10008,\n NoAppInRequestContext = 10009,\n NoWorkspaceInRequestContext = 10010,\n NoUserPermissionsInRequestContext = 10012,\n WorkspacePermissionDenied = 10013,\n NoTargetUrlHeader = 10014,\n NoSessionInRedisCache = 10015,\n}\n\nexport enum DataErrorCode {\n NoPublicKey = 11000,\n NoAuthHeader = 11001,\n FailedFileUpload = 11002,\n FailedFileDownload = 11003,\n}\n\nexport enum PortalErrorCode {\n NoObjectId = 12000,\n}\n\nexport type ErrorCode = GatewayErrorCode | DataErrorCode | PortalErrorCode;\n\ntype Errors = {\n [key in ErrorCode]: {\n statusCode: number;\n msg: string;\n };\n};\n\nexport const errors: Errors = {\n [GatewayErrorCode.NoObjectId]: {\n statusCode: 401,\n msg: 'No object id available on authenticated user.',\n },\n [GatewayErrorCode.NoTargetAppHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetApp}'.`,\n },\n [GatewayErrorCode.NoTargetWorkspaceHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetWorkspace}'.`,\n },\n [GatewayErrorCode.NoTargetUrlHeader]: {\n statusCode: 400,\n msg: `Request missing header '${AllianceHeaders.TargetUrl}'.`,\n },\n [GatewayErrorCode.NoManifestsInCache]: {\n statusCode: 500,\n msg: 'App manifests missing in cache.',\n },\n [GatewayErrorCode.NoDevSessionInCache]: {\n statusCode: 500,\n msg: 'No dev session in memory cache.',\n },\n [GatewayErrorCode.NoSessionInRedisCache]: {\n statusCode: 401,\n msg: 'Could not find user session in Redis server.',\n },\n [GatewayErrorCode.NoManifest]: {\n statusCode: 500,\n msg: \"Could not find manifest for app '{{appSlug}}'.\",\n },\n [GatewayErrorCode.NoRequestContext]: {\n statusCode: 500,\n msg: 'No request context.',\n },\n [GatewayErrorCode.NoUserInRequestContext]: {\n statusCode: 500,\n msg: 'No user in request context.',\n },\n [GatewayErrorCode.NoAppInRequestContext]: {\n statusCode: 500,\n msg: 'No app in request context.',\n },\n [GatewayErrorCode.NoWorkspaceInRequestContext]: {\n statusCode: 500,\n msg: 'No workspace in request context.',\n },\n [GatewayErrorCode.NoUserPermissionsInRequestContext]: {\n statusCode: 500,\n msg: 'No user permissions in request context.',\n },\n [GatewayErrorCode.WorkspacePermissionDenied]: {\n statusCode: 403,\n msg: 'User does not have access to the current workspace.',\n },\n\n [DataErrorCode.NoPublicKey]: {\n statusCode: 401,\n msg: 'No public key available to decode JWT.',\n },\n [DataErrorCode.NoAuthHeader]: {\n statusCode: 401,\n msg: 'No authorization header found.',\n },\n [DataErrorCode.FailedFileUpload]: {\n statusCode: 500,\n msg: 'Something went wrong when trying to upload a file to the S3 storage.',\n },\n [DataErrorCode.FailedFileDownload]: {\n statusCode: 500,\n msg: 'Something went wrong when trying to download a file to the S3 storage.',\n },\n\n [PortalErrorCode.NoObjectId]: {\n statusCode: 401,\n msg: 'No object id found in user claims.',\n },\n};\n","import type { ErrorRequestHandler } from 'express';\n\nimport type { Logger } from '@/logger';\n\nimport { type ErrorCode, errors } from './codes';\n\nexport class AllianceError extends Error {\n public info: string = `https://github.com/telia-company/ace-alliance-sdk/wiki/error-codes#${this.errorCode}`;\n public statusCode: number;\n constructor(\n public errorCode: ErrorCode,\n variables: Record<string, string> = {},\n ) {\n const { msg, statusCode } = errors[errorCode];\n const message = parseTemplates(msg, variables);\n super(message);\n this.message = message;\n this.statusCode = statusCode;\n }\n}\n\nfunction parseTemplates(message: string, variables: Record<string, string>) {\n return Object.entries(variables).reduce((acc, [key, value]) => {\n return acc.replaceAll(`{{${key}}}`, value);\n }, message);\n}\n\nexport function requestErrorHandler(logger: Logger): ErrorRequestHandler {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (err, req, res, _next) => {\n const error = {\n cause: err.cause,\n message: err.message,\n status: err.status || err.statusCode || err.code,\n info: err.info,\n };\n\n logger.error('error when processing request', {\n url: req.url,\n body: req.body,\n error,\n });\n\n return res.status(error.status).json(error);\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/alliance-internal-node-utilities",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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",
|
|
@@ -21,17 +21,7 @@
|
|
|
21
21
|
"zod": "^3.22.4"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@types/jsonwebtoken": "^9.0.3",
|
|
26
|
-
"@types/node": "^20.8.5",
|
|
27
|
-
"minimist": "^1.2.8",
|
|
28
|
-
"remark-parse": "^11.0.0",
|
|
29
|
-
"remark-stringify": "^11.0.0",
|
|
30
|
-
"slackify-markdown": "^4.4.0",
|
|
31
|
-
"tiny-glob": "^0.2.9",
|
|
32
|
-
"tsup": "^7.2.0",
|
|
33
|
-
"unified": "^11.0.3",
|
|
34
|
-
"@telia-ace/alliance-internal-node-utilities": "^1.0.5"
|
|
24
|
+
"@telia-ace/alliance-internal-node-utilities": "^1.0.6"
|
|
35
25
|
},
|
|
36
26
|
"publishConfig": {
|
|
37
27
|
"access": "public"
|