@telia-ace/alliance-internal-node-utilities 1.0.5-next.0 → 1.0.5-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +89 -115
- package/dist/index.js +271 -613
- package/dist/index.js.map +1 -1
- package/package.json +5 -14
- package/dist/index.cjs +0 -1074
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -200
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,67 +1,31 @@
|
|
|
1
|
-
import { PinoLogger } from 'nestjs-pino';
|
|
2
|
-
export { LoggerErrorInterceptor } from 'nestjs-pino';
|
|
3
|
-
import { ConfigService } from '@nestjs/config';
|
|
4
|
-
import { RequestHandler } from 'express';
|
|
5
|
-
import { ConfigParams, CookieConfigParams } from 'express-openid-connect';
|
|
6
1
|
import { z } from 'zod';
|
|
7
|
-
import {
|
|
8
|
-
import { HttpException, ExceptionFilter, ArgumentsHost, DynamicModule } from '@nestjs/common';
|
|
9
|
-
import { HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus';
|
|
2
|
+
import { RequestHandler, ErrorRequestHandler } from 'express';
|
|
10
3
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
clientSecret?: ConfigParams['clientSecret'];
|
|
15
|
-
authRequired?: ConfigParams['authRequired'];
|
|
16
|
-
authorizationParams?: ConfigParams['authorizationParams'];
|
|
17
|
-
afterCallback?: ConfigParams['afterCallback'];
|
|
18
|
-
issuerBaseURL?: ConfigParams['issuerBaseURL'];
|
|
19
|
-
sessionCookiePath?: CookieConfigParams['path'];
|
|
20
|
-
};
|
|
21
|
-
declare function authMiddleware(configService: ConfigService, { baseURL, clientSecret, clientID, authRequired, authorizationParams, afterCallback, issuerBaseURL, sessionCookiePath, }?: Settings): RequestHandler;
|
|
22
|
-
|
|
23
|
-
type BearerTokenSettings = {
|
|
24
|
-
privateKey: string;
|
|
25
|
-
aud: string;
|
|
26
|
-
sub: string;
|
|
27
|
-
name: string;
|
|
28
|
-
user: {
|
|
29
|
-
type: string;
|
|
30
|
-
permissions: string[];
|
|
31
|
-
email: string;
|
|
32
|
-
};
|
|
33
|
-
workspace: {
|
|
34
|
-
name: string;
|
|
35
|
-
slug: string;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
declare function createBearerToken({ privateKey, aud, sub, name, user, workspace, }: BearerTokenSettings): string;
|
|
39
|
-
declare function getPrivateKey(configService: ConfigService): string;
|
|
40
|
-
declare function createSystemUserToken(configService: ConfigService): string;
|
|
41
|
-
|
|
42
|
-
declare enum SharedConfigKeys {
|
|
4
|
+
declare const zBooleanEnum: z.ZodEffects<z.ZodEnum<["true", "false"]>, boolean, "true" | "false">;
|
|
5
|
+
declare const zNonEmptyString: z.ZodString;
|
|
6
|
+
declare const zSharedConfig: z.ZodObject<{
|
|
43
7
|
/**
|
|
44
8
|
* Name for the cookie storing the user session
|
|
45
9
|
*
|
|
46
10
|
* Optional, defaults to "alliance-auth"
|
|
47
11
|
*/
|
|
48
|
-
|
|
12
|
+
AUTH_COOKIE_NAME: z.ZodDefault<z.ZodString>;
|
|
49
13
|
/**
|
|
50
14
|
* Secret to use when signing the user session cookie
|
|
51
15
|
*
|
|
52
16
|
* Optional, defaults to "zlLZBlk7wt8lypP5lA4D"
|
|
53
17
|
*/
|
|
54
|
-
|
|
18
|
+
AUTH_COOKIE_SECRET: z.ZodDefault<z.ZodString>;
|
|
55
19
|
/**
|
|
56
20
|
* Endpoint to use when communicating with the Data API
|
|
57
21
|
*/
|
|
58
|
-
|
|
22
|
+
DB_ENDPOINT: z.ZodString;
|
|
59
23
|
/**
|
|
60
24
|
* Private key to use when signing JWT tokens
|
|
61
25
|
*
|
|
62
26
|
* Optional, defaults to "MIIEogIBAAKCAQEAsGqOzjnfQtCYlDqhgGAnKuJOCiPt2WpCmL1Cs+SLBQlyoNn6LT8BJ6ZRj8t/vK8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U4qq9PyIA2tNmMHQ0qCedXU8z35huTnRGSDV81gmzyhtQsezgoTWp8Cy6HHKjG6fKasWlx2SKKk8m+Eu3c396QQKBgBMY2asq4M7VU+RiUXCwHwTe+4Wjda7PGvcdTw6Du3vYyVNVxXtr2AG+8uPIjnVQFT6ZApSqToEOAAOjXv6SZDHGU5xiXhUOfIXq0a0OmHv4rIXZv3pPZmGs5k+rA0uGAfH7riiIHBkWxmQ3ivty9lPVgAHobIvvaQmbxNeVVnRxAoGAUzUmcBiUAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo="
|
|
63
27
|
*/
|
|
64
|
-
|
|
28
|
+
JWT_PRIVATE_KEY: z.ZodDefault<z.ZodString>;
|
|
65
29
|
/**
|
|
66
30
|
* Log level to output
|
|
67
31
|
*
|
|
@@ -69,36 +33,22 @@ declare enum SharedConfigKeys {
|
|
|
69
33
|
*
|
|
70
34
|
* Optional, defaults to "trace"
|
|
71
35
|
*/
|
|
72
|
-
|
|
36
|
+
SERVICE_LOG_LEVEL: z.ZodDefault<z.ZodEnum<["silent", "fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
73
37
|
/**
|
|
74
38
|
* Port to run the service on.
|
|
75
39
|
*
|
|
76
40
|
* Optional, defaults to "3000"
|
|
77
41
|
*/
|
|
78
|
-
|
|
42
|
+
SERVICE_PORT: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
79
43
|
/**
|
|
80
44
|
* Url to redis server to use when storing / reading user session information.
|
|
81
|
-
*
|
|
82
|
-
* Optional
|
|
83
45
|
*/
|
|
84
|
-
|
|
46
|
+
REDIS_HOST: z.ZodString;
|
|
85
47
|
/**
|
|
86
48
|
* Password to redis server to use when storing / reading user session information.
|
|
87
49
|
*
|
|
88
50
|
* Optional
|
|
89
51
|
*/
|
|
90
|
-
RedisPassword = "REDIS_PASSWORD"
|
|
91
|
-
}
|
|
92
|
-
declare const zBooleanEnum: z.ZodEffects<z.ZodEnum<["true", "false"]>, boolean, "true" | "false">;
|
|
93
|
-
declare const zNonEmptyString: z.ZodString;
|
|
94
|
-
declare const zSharedConfig: z.ZodObject<{
|
|
95
|
-
AUTH_COOKIE_NAME: z.ZodDefault<z.ZodString>;
|
|
96
|
-
AUTH_COOKIE_SECRET: z.ZodDefault<z.ZodString>;
|
|
97
|
-
DB_ENDPOINT: z.ZodString;
|
|
98
|
-
JWT_PRIVATE_KEY: z.ZodDefault<z.ZodString>;
|
|
99
|
-
SERVICE_LOG_LEVEL: z.ZodDefault<z.ZodEnum<["silent", "fatal", "error", "warn", "info", "debug", "trace"]>>;
|
|
100
|
-
SERVICE_PORT: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
|
|
101
|
-
REDIS_HOST: z.ZodOptional<z.ZodString>;
|
|
102
52
|
REDIS_PASSWORD: z.ZodOptional<z.ZodString>;
|
|
103
53
|
}, "strip", z.ZodTypeAny, {
|
|
104
54
|
AUTH_COOKIE_NAME: string;
|
|
@@ -107,16 +57,16 @@ declare const zSharedConfig: z.ZodObject<{
|
|
|
107
57
|
JWT_PRIVATE_KEY: string;
|
|
108
58
|
SERVICE_LOG_LEVEL: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
109
59
|
SERVICE_PORT: number;
|
|
110
|
-
REDIS_HOST
|
|
60
|
+
REDIS_HOST: string;
|
|
111
61
|
REDIS_PASSWORD?: string | undefined;
|
|
112
62
|
}, {
|
|
113
63
|
DB_ENDPOINT: string;
|
|
64
|
+
REDIS_HOST: string;
|
|
114
65
|
AUTH_COOKIE_NAME?: string | undefined;
|
|
115
66
|
AUTH_COOKIE_SECRET?: string | undefined;
|
|
116
67
|
JWT_PRIVATE_KEY?: string | undefined;
|
|
117
68
|
SERVICE_LOG_LEVEL?: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace" | undefined;
|
|
118
69
|
SERVICE_PORT?: string | undefined;
|
|
119
|
-
REDIS_HOST?: string | undefined;
|
|
120
70
|
REDIS_PASSWORD?: string | undefined;
|
|
121
71
|
}>;
|
|
122
72
|
|
|
@@ -126,9 +76,67 @@ declare enum AllianceHeaders {
|
|
|
126
76
|
TargetWorkspace = "alliance-target-workspace"
|
|
127
77
|
}
|
|
128
78
|
|
|
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
|
+
|
|
129
109
|
declare function createPublicDistributionFiles(): Promise<void>;
|
|
130
110
|
|
|
131
|
-
declare
|
|
111
|
+
declare function slugify(name: string): string;
|
|
112
|
+
|
|
113
|
+
type LogFn = (msg: string, obj?: any) => void;
|
|
114
|
+
type PartialConfig = Pick<z.infer<typeof zSharedConfig>, 'SERVICE_LOG_LEVEL'>;
|
|
115
|
+
type Logger = {
|
|
116
|
+
fatal: LogFn;
|
|
117
|
+
error: LogFn;
|
|
118
|
+
warn: LogFn;
|
|
119
|
+
info: LogFn;
|
|
120
|
+
debug: LogFn;
|
|
121
|
+
trace: LogFn;
|
|
122
|
+
silent: LogFn;
|
|
123
|
+
child(): Logger;
|
|
124
|
+
level: PartialConfig['SERVICE_LOG_LEVEL'];
|
|
125
|
+
};
|
|
126
|
+
declare function createLogger(config: PartialConfig): {
|
|
127
|
+
fatal: LogFn;
|
|
128
|
+
error: LogFn;
|
|
129
|
+
warn: LogFn;
|
|
130
|
+
info: LogFn;
|
|
131
|
+
debug: LogFn;
|
|
132
|
+
trace: LogFn;
|
|
133
|
+
silent: LogFn;
|
|
134
|
+
child: () => any;
|
|
135
|
+
level: "silent" | "fatal" | "error" | "warn" | "info" | "debug" | "trace";
|
|
136
|
+
};
|
|
137
|
+
declare function requestLoggerHandler(logger: Logger): RequestHandler;
|
|
138
|
+
|
|
139
|
+
declare enum GatewayErrorCode {
|
|
132
140
|
NoObjectId = 10001,
|
|
133
141
|
NoTargetAppHeader = 10002,
|
|
134
142
|
NoTargetWorkspaceHeader = 10003,
|
|
@@ -140,61 +148,27 @@ declare enum GatewayErrorCodes {
|
|
|
140
148
|
NoAppInRequestContext = 10009,
|
|
141
149
|
NoWorkspaceInRequestContext = 10010,
|
|
142
150
|
NoUserPermissionsInRequestContext = 10012,
|
|
143
|
-
WorkspacePermissionDenied = 10013
|
|
151
|
+
WorkspacePermissionDenied = 10013,
|
|
152
|
+
NoTargetUrlHeader = 10014,
|
|
153
|
+
NoSessionInRedisCache = 10015
|
|
144
154
|
}
|
|
145
|
-
declare enum
|
|
146
|
-
|
|
155
|
+
declare enum DataErrorCode {
|
|
156
|
+
NoPublicKey = 11000,
|
|
157
|
+
NoAuthHeader = 11001,
|
|
158
|
+
FailedFileUpload = 11002,
|
|
159
|
+
FailedFileDownload = 11003
|
|
147
160
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
declare class AllianceGqlException extends GraphQLError {
|
|
151
|
-
info: string;
|
|
152
|
-
code: ErrorCodes;
|
|
153
|
-
constructor(code: ErrorCodes, variables?: Record<string, string>, extensions?: any);
|
|
161
|
+
declare enum PortalErrorCode {
|
|
162
|
+
NoObjectId = 12000
|
|
154
163
|
}
|
|
164
|
+
type ErrorCode = GatewayErrorCode | DataErrorCode | PortalErrorCode;
|
|
155
165
|
|
|
156
|
-
declare class
|
|
166
|
+
declare class AllianceError extends Error {
|
|
167
|
+
errorCode: ErrorCode;
|
|
157
168
|
info: string;
|
|
158
|
-
|
|
159
|
-
constructor(
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
declare class AllianceExceptionFilter implements ExceptionFilter {
|
|
163
|
-
catch(exception: AllianceException, host: ArgumentsHost): void;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
type LooseObject = Record<string, any>;
|
|
167
|
-
|
|
168
|
-
declare function getAppManifests(apps: string[]): Promise<LooseObject[]>;
|
|
169
|
-
|
|
170
|
-
declare class RedisHealthIndicator extends HealthIndicator {
|
|
171
|
-
private configService;
|
|
172
|
-
constructor(configService: ConfigService);
|
|
173
|
-
isHealthy(): Promise<HealthIndicatorResult>;
|
|
174
|
-
private getRedisClient;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
type ModuleSettings = {
|
|
178
|
-
logLevel?: string;
|
|
179
|
-
redact?: boolean;
|
|
180
|
-
};
|
|
181
|
-
declare class LoggerModule {
|
|
182
|
-
static forRoot({ logLevel, redact }?: ModuleSettings): DynamicModule;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
declare class LoggerService {
|
|
186
|
-
private readonly logger;
|
|
187
|
-
constructor(logger: PinoLogger);
|
|
188
|
-
private logFn;
|
|
189
|
-
log: (msg: string, context?: Record<string, any>) => void;
|
|
190
|
-
trace: (msg: string, context?: Record<string, any>) => void;
|
|
191
|
-
debug: (msg: string, context?: Record<string, any>) => void;
|
|
192
|
-
info: (msg: string, context?: Record<string, any>) => void;
|
|
193
|
-
warn: (msg: string, context?: Record<string, any>) => void;
|
|
194
|
-
error: (msg: string, context?: Record<string, any>) => void;
|
|
195
|
-
fatal: (msg: string, context?: Record<string, any>) => void;
|
|
169
|
+
statusCode: number;
|
|
170
|
+
constructor(errorCode: ErrorCode, variables?: Record<string, string>);
|
|
196
171
|
}
|
|
172
|
+
declare function requestErrorHandler(logger: Logger): ErrorRequestHandler;
|
|
197
173
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export { AllianceException, AllianceExceptionFilter, AllianceGqlException, AllianceHeaders, Settings as AuthMiddlewareSettings, GatewayErrorCodes, LoggerModule, LoggerService, PortalErrorCodes, RedisHealthIndicator, SharedConfigKeys, authMiddleware, createBearerToken, createPublicDistributionFiles, createSystemUserToken, getAppManifests, getPrivateKey, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|
|
174
|
+
export { AllianceError, AllianceHeaders, BearerTokenContent, DataErrorCode, GatewayErrorCode, Logger, createBearerToken, createLogger, createPublicDistributionFiles, createSystemUserToken, getPrivateKey, requestErrorHandler, requestLoggerHandler, slugify, zBooleanEnum, zNonEmptyString, zSharedConfig };
|