@telia-ace/alliance-internal-node-utilities 1.0.4 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @telia-ace/alliance-internal-node-utilities
2
2
 
3
+ ## 1.0.5-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 2858c59: Replace GraphQL and NestJS utilities.
8
+
9
+ ## 1.0.5-next.0
10
+
11
+ ### Patch Changes
12
+
13
+ - 321a5d6: Replace `@telia-ace/alliance-databases`, using NestJS + GraphQL, with `@telia-ace/alliance-data`, using Expess 5 + tRPC.
14
+
3
15
  ## 1.0.4
4
16
 
5
17
  ### Patch Changes
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 { GraphQLError } from 'graphql';
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
- type Settings = {
12
- baseURL?: ConfigParams['baseURL'];
13
- clientID?: ConfigParams['clientID'];
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
- AuthCookieName = "AUTH_COOKIE_NAME",
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
- AuthCookieSecret = "AUTH_COOKIE_SECRET",
18
+ AUTH_COOKIE_SECRET: z.ZodDefault<z.ZodString>;
55
19
  /**
56
- * Endpoint to use when communicating with the databases GraphQL API
20
+ * Endpoint to use when communicating with the Data API
57
21
  */
58
- DbEndpoint = "DB_ENDPOINT",
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/vK8Sw0p51Uq/3k0tazh7bLGkWNMBLY3BqFiNRMMnCqHJfvGIUi/itNXNe2kbP7H3rbyQTu4O7yH/ZAMitdpF2KLucVRlFxrQ/ggZjxwEGso4JUnCwmAnoKct/uupKz9Y2PMTr00WWN79aPfD4LcKi570VJqBT3ISSucdwFLY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OAAOjXv6SZDHGU5xiXhUOfIXq0a0OmHv4rIXZv3pPZmGs5k+rA0uGAfH7riiIHBkWxmQ3ivty9lPVgAHobIvvaQmbxNeVVnRxAoGAUzUmcBiUAiODfjulrpYvWG0tCn5B//yk7g1Tm3Chrh9huA1qGEN3jDoqSsTd5k4Yi5foyAZt5ORgoiUVm4IsfS56aoxIco1CtFG3zeMQRy4uKzTsvUTOdsJ4RlQdjNwpngXR44VL0WelgCDqTqJwn5ubzPvuIHuTj3cBpmJCjOo="
63
27
  */
64
- JwtPrivateKey = "JWT_PRIVATE_KEY",
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
- ServiceLogLevel = "SERVICE_LOG_LEVEL",
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
- ServicePort = "SERVICE_PORT",
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
- RedisHost = "REDIS_HOST",
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?: string | undefined;
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 enum GatewayErrorCodes {
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,69 +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 DatabasesErrorCodes {
155
+ declare enum DataErrorCode {
146
156
  NoPublicKey = 11000,
147
157
  NoAuthHeader = 11001,
148
- FailedFileStore = 11002,
149
- FailedFileRead = 11003,
150
- NoRecord = 11004,
151
- UniqueConstrain = 11005
158
+ FailedFileUpload = 11002,
159
+ FailedFileDownload = 11003
152
160
  }
153
- declare enum PortalErrorCodes {
161
+ declare enum PortalErrorCode {
154
162
  NoObjectId = 12000
155
163
  }
156
- type ErrorCodes = GatewayErrorCodes | DatabasesErrorCodes | PortalErrorCodes;
157
-
158
- declare class AllianceGqlException extends GraphQLError {
159
- info: string;
160
- code: ErrorCodes;
161
- constructor(code: ErrorCodes, variables?: Record<string, string>, extensions?: any);
162
- }
164
+ type ErrorCode = GatewayErrorCode | DataErrorCode | PortalErrorCode;
163
165
 
164
- declare class AllianceException extends HttpException {
166
+ declare class AllianceError extends Error {
167
+ errorCode: ErrorCode;
165
168
  info: string;
166
- code: ErrorCodes;
167
- constructor(code: ErrorCodes, variables?: Record<string, string>);
168
- }
169
-
170
- declare class AllianceExceptionFilter implements ExceptionFilter {
171
- catch(exception: AllianceException, host: ArgumentsHost): void;
172
- }
173
-
174
- type LooseObject = Record<string, any>;
175
-
176
- declare function getAppManifests(apps: string[]): Promise<LooseObject[]>;
177
-
178
- declare class RedisHealthIndicator extends HealthIndicator {
179
- private configService;
180
- constructor(configService: ConfigService);
181
- isHealthy(): Promise<HealthIndicatorResult>;
182
- private getRedisClient;
183
- }
184
-
185
- type ModuleSettings = {
186
- logLevel?: string;
187
- redact?: boolean;
188
- };
189
- declare class LoggerModule {
190
- static forRoot({ logLevel, redact }?: ModuleSettings): DynamicModule;
191
- }
192
-
193
- declare class LoggerService {
194
- private readonly logger;
195
- constructor(logger: PinoLogger);
196
- private logFn;
197
- log: (msg: string, context?: Record<string, any>) => void;
198
- trace: (msg: string, context?: Record<string, any>) => void;
199
- debug: (msg: string, context?: Record<string, any>) => void;
200
- info: (msg: string, context?: Record<string, any>) => void;
201
- warn: (msg: string, context?: Record<string, any>) => void;
202
- error: (msg: string, context?: Record<string, any>) => void;
203
- fatal: (msg: string, context?: Record<string, any>) => void;
169
+ statusCode: number;
170
+ constructor(errorCode: ErrorCode, variables?: Record<string, string>);
204
171
  }
172
+ declare function requestErrorHandler(logger: Logger): ErrorRequestHandler;
205
173
 
206
- declare function slugify(name: string): string;
207
-
208
- export { AllianceException, AllianceExceptionFilter, AllianceGqlException, AllianceHeaders, Settings as AuthMiddlewareSettings, DatabasesErrorCodes, 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 };