@6thbridge/utils 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import { AuthenticationTypes, ClientEntity, UserEntity } from "../types";
2
+ export type AuthorizationClientResponse = Pick<ClientEntity, 'name' | 'clientId' | 'logo' | 'email' | 'status'>;
3
+ export type AuthorizationUserResponse = Pick<UserEntity, 'clientId' | 'name' | 'email' | 'firstName' | 'lastName' | 'roleId'> & {
4
+ userId: string;
5
+ };
6
+ export declare class ValidateUserAccessDTO {
7
+ domain: string;
8
+ secret: string;
9
+ requestClientId: string;
10
+ contextClientId: string;
11
+ country: string;
12
+ currency: string;
13
+ token: string;
14
+ }
15
+ export declare class ValidateUserAccessResponseDTO {
16
+ domain: string;
17
+ country: string;
18
+ currency: string;
19
+ locale: string;
20
+ requestClientId: string;
21
+ contextClientId: string;
22
+ contextClient: AuthorizationClientResponse;
23
+ requestClient: AuthorizationClientResponse;
24
+ authenticationType: AuthenticationTypes;
25
+ requestUserId: string;
26
+ contextUserId: string;
27
+ requestUser: AuthorizationUserResponse;
28
+ contextUser: AuthorizationUserResponse;
29
+ permissions: string;
30
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidateUserAccessResponseDTO = exports.ValidateUserAccessDTO = void 0;
4
+ class ValidateUserAccessDTO {
5
+ }
6
+ exports.ValidateUserAccessDTO = ValidateUserAccessDTO;
7
+ class ValidateUserAccessResponseDTO {
8
+ }
9
+ exports.ValidateUserAccessResponseDTO = ValidateUserAccessResponseDTO;
10
+ //# sourceMappingURL=authentication.entity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.entity.js","sourceRoot":"","sources":["../../src/types/authentication.entity.ts"],"names":[],"mappings":";;;AAIA,MAAa,qBAAqB;CAQjC;AARD,sDAQC;AAED,MAAa,6BAA6B;CAezC;AAfD,sEAeC"}
@@ -2,25 +2,26 @@ import { RequestUserEntity } from './user.entity';
2
2
  import { RequestClientEntity } from './client.entity';
3
3
  import express from 'express';
4
4
  import { LoggerInterface } from '../logger';
5
+ import { RabbitMQClient } from '../index';
6
+ import { AuthorizationClientResponse, AuthorizationUserResponse, ValidateUserAccessResponseDTO } from "./authentication.entity";
5
7
  export declare const INTERNAL_REQUEST_SOURCE = "internal";
6
8
  export declare class ContextEntity {
7
9
  requestSource?: string;
8
10
  clientId?: string;
9
11
  requestClientId?: string;
10
12
  contextClientId?: string;
11
- requestClient?: RequestClientEntity;
12
- contextClient?: RequestClientEntity;
13
+ requestClient?: RequestClientEntity | AuthorizationClientResponse;
14
+ contextClient?: RequestClientEntity | AuthorizationClientResponse;
13
15
  requestId?: string;
14
16
  authenticationType?: string;
15
17
  permissions?: string[];
16
- features?: string[];
17
18
  os?: string;
18
19
  platform?: string;
19
20
  version?: string;
20
21
  request: express.Request | undefined | any;
21
22
  data?: any;
22
- requestUser?: RequestUserEntity;
23
- contextUser?: RequestUserEntity;
23
+ requestUser?: RequestUserEntity | AuthorizationUserResponse;
24
+ contextUser?: RequestUserEntity | AuthorizationUserResponse;
24
25
  contextUserId?: string;
25
26
  requestUserId?: string;
26
27
  userId?: string;
@@ -30,16 +31,9 @@ export declare class ContextEntity {
30
31
  countryCode?: string;
31
32
  locale?: string;
32
33
  origin?: string;
33
- broker?: any;
34
- [key: string]: any;
34
+ broker?: RabbitMQClient;
35
35
  constructor();
36
36
  static fromRequest(req: express.Request): ContextEntity;
37
+ static fromAuthorizationResult(req: express.Request, result: ValidateUserAccessResponseDTO): ContextEntity;
37
38
  clone(): this;
38
- getClientId(): string | undefined;
39
- createDefaultLogger(): void;
40
- hasPermission(permission: string): boolean;
41
- hasFeature(feature: string): boolean;
42
- getUserId(): string;
43
- getRequestClientId(): string;
44
- getContextClientId(): string;
45
39
  }
@@ -33,7 +33,7 @@ class ContextEntity {
33
33
  this.logger = new logger_1.Logger({});
34
34
  }
35
35
  static fromRequest(req) {
36
- var _a, _b, _c, _d, _e;
36
+ var _a, _b, _c, _d;
37
37
  const context = new ContextEntity();
38
38
  context.requestSource = req.headers.source;
39
39
  context.authenticationType = req.headers['authentication-type'];
@@ -49,12 +49,10 @@ class ContextEntity {
49
49
  context.platform = req.headers.platform;
50
50
  context.version = req.headers.version;
51
51
  context.request = req;
52
- context.data = req.body;
53
52
  context.currencyCode = req.headers['x-currency-code'];
54
53
  context.countryCode = req.headers['x-country-code'];
55
54
  context.locale = req.headers['x-locale-id'] || 'en';
56
55
  context.permissions = ((_d = req.headers.permissions) === null || _d === void 0 ? void 0 : _d.split(',')) || [];
57
- context.features = ((_e = req.headers.features) === null || _e === void 0 ? void 0 : _e.split(',')) || [];
58
56
  context.logger = new logger_1.Logger({
59
57
  requestId: context.requestId,
60
58
  requestClientId: context.requestClientId,
@@ -66,41 +64,45 @@ class ContextEntity {
66
64
  });
67
65
  return context;
68
66
  }
69
- clone() {
70
- return _.cloneDeep(this);
71
- }
72
- getClientId() {
73
- return this.contextClientId || this.requestClientId || this.contextClientId;
74
- }
75
- createDefaultLogger() {
76
- var _a;
77
- this.logger = new logger_1.Logger({
78
- requestId: this.requestId,
79
- requestClientId: this.requestClientId,
80
- contextClientId: this.contextClientId,
81
- userId: this.userId,
82
- ip: this.ip,
83
- url: (_a = this.request) === null || _a === void 0 ? void 0 : _a.originalUrl,
84
- requestSource: this.requestSource,
67
+ static fromAuthorizationResult(req, result) {
68
+ const context = new ContextEntity();
69
+ context.requestSource = req.headers.source;
70
+ context.authenticationType = result.authenticationType;
71
+ context.requestClientId = result.requestClientId;
72
+ context.contextClientId = result.contextClientId;
73
+ context.requestClient = result.requestClient;
74
+ context.contextClient = result.contextClient;
75
+ context.requestUserId = result.requestUserId;
76
+ context.contextUserId = result.contextUserId;
77
+ context.requestUser = result.requestUser;
78
+ context.contextUser = result.contextUser;
79
+ context.requestId = req.headers['x-request-id'] || (0, crypto_1.randomUUID)();
80
+ context.ip = req.headers['cf-connecting-ip'] || req.ip;
81
+ context.os = req.headers.os;
82
+ context.platform = req.headers.platform;
83
+ context.version = req.headers.version;
84
+ context.request = req;
85
+ context.currencyCode = req.headers['x-currency-code'] || result.currency;
86
+ context.countryCode = req.headers['x-country-code'] || result.country;
87
+ context.locale = req.headers['x-locale-id'] || result.locale || 'en';
88
+ context.permissions = result.permissions.split(",") || [];
89
+ context.logger = new logger_1.Logger({
90
+ requestId: context.requestId,
91
+ requestClientId: context.requestClientId,
92
+ contextClientId: context.contextClientId,
93
+ userId: context.requestUserId,
94
+ ip: context.ip,
95
+ url: context.request.originalUrl,
96
+ requestSource: context.requestSource,
85
97
  });
98
+ //Deprecated fields
99
+ context.data = req.body;
100
+ context.userId = result.requestUserId;
101
+ context.clientId = result.requestClientId;
102
+ return context;
86
103
  }
87
- hasPermission(permission) {
88
- var _a;
89
- return ((_a = this.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission)) || false;
90
- }
91
- hasFeature(feature) {
92
- var _a;
93
- return ((_a = this.features) === null || _a === void 0 ? void 0 : _a.includes(feature)) || false;
94
- }
95
- getUserId() {
96
- var _a, _b;
97
- return ((_a = this === null || this === void 0 ? void 0 : this.contextUser) === null || _a === void 0 ? void 0 : _a.userId) || ((_b = this === null || this === void 0 ? void 0 : this.requestUser) === null || _b === void 0 ? void 0 : _b.userId) || (this === null || this === void 0 ? void 0 : this.userId) || '';
98
- }
99
- getRequestClientId() {
100
- return this.requestClientId || this.clientId || '';
101
- }
102
- getContextClientId() {
103
- return this.contextClientId || this.clientId || '';
104
+ clone() {
105
+ return _.cloneDeep(this);
104
106
  }
105
107
  }
106
108
  exports.ContextEntity = ContextEntity;
@@ -1 +1 @@
1
- {"version":3,"file":"context.entity.js","sourceRoot":"","sources":["../../src/types/context.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAA4B;AAK5B,mCAAoC;AACpC,6CAA0C;AAE7B,QAAA,uBAAuB,GAAG,UAAU,CA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;YAC5B,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,MAAM,EAAE,OAAO,CAAC,aAAa;YAC7B,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,WAAW;YAChC,aAAa,EAAE,OAAO,CAAC,aAAa;SACrC,CAAC,CAAC;QAEH,mBAAmB;QACnB,OAAO,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACxB,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;QACtC,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,eAAe,CAAC;QAE1C,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,KAAK;QACH,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF;AA7GD,sCA6GC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@6thbridge/utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "simple interface for the our commonly used functions",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,5 +0,0 @@
1
- import { RabbitMQ, RabbitMQInit } from './rabbitmq';
2
- export interface MessageBrokerInterface {
3
- init(config: any): Promise<MessageBrokerInterface>;
4
- }
5
- export { RabbitMQInit, RabbitMQ };
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RabbitMQ = void 0;
4
- const rabbitmq_1 = require("./rabbitmq");
5
- Object.defineProperty(exports, "RabbitMQ", { enumerable: true, get: function () { return rabbitmq_1.RabbitMQ; } });
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/brokers/index.ts"],"names":[],"mappings":";;;AAAA,yCAAkD;AAM3B,yFANf,mBAAQ,OAMe"}
@@ -1,205 +0,0 @@
1
- import { BrokerDeadLetterPayloadEntity, BrokerRetryEntity } from '../types';
2
- import { IAmqpConnectionManager } from 'amqp-connection-manager/dist/types/AmqpConnectionManager';
3
- /**
4
- * @deprecated
5
- */
6
- export type RabbitMQInit = {
7
- url?: string;
8
- heartbeat?: number;
9
- retryCountBeforeExit?: number;
10
- [x: string]: any;
11
- };
12
- /**
13
- * @deprecated
14
- */
15
- export declare class RabbitMQ {
16
- private static instance;
17
- private channel;
18
- private connection;
19
- private retryCountBeforeExit;
20
- private constructor();
21
- /**
22
- * Get the singleton instance of RabbitMQ
23
- * @returns {RabbitMQ} The singleton instance
24
- */
25
- static getInstance(): RabbitMQ;
26
- /**
27
- *
28
- * @param {Object} options
29
- * @param {string} options.url
30
- * @param {number} options.retryCountBeforeExit
31
- * @param {number} options.heartbeat
32
- * @return {Promise<null|*|undefined>}
33
- */
34
- static init(options?: RabbitMQInit): Promise<IAmqpConnectionManager>;
35
- /**
36
- *
37
- * @param {Object} options
38
- * @param {string} options.url
39
- * @param {number} options.retryCountBeforeExit
40
- * @param {number} options.heartbeat
41
- * @return {Promise<null|*|undefined>}
42
- */
43
- init(options?: RabbitMQInit): Promise<IAmqpConnectionManager>;
44
- /**
45
- * Static version of createChannel
46
- */
47
- static createChannel(callback: any): Promise<{
48
- data: any;
49
- error?: undefined;
50
- } | {
51
- error: any;
52
- data?: undefined;
53
- }>;
54
- createChannel(callback: any): Promise<{
55
- data: any;
56
- error?: undefined;
57
- } | {
58
- error: any;
59
- data?: undefined;
60
- }>;
61
- /**
62
- * Static version of createQueue
63
- */
64
- static createQueue(queueName: string | string[], options?: any): Promise<{
65
- data: boolean;
66
- error?: undefined;
67
- } | {
68
- error: any;
69
- data?: undefined;
70
- }>;
71
- createQueue(queueName: string | string[], options?: any): Promise<{
72
- data: boolean;
73
- error?: undefined;
74
- } | {
75
- error: any;
76
- data?: undefined;
77
- }>;
78
- /**
79
- * Static version of sendToQueue
80
- */
81
- static sendToQueue(channelName: string, payload: any, options?: {
82
- persistent: boolean;
83
- }): Promise<{
84
- data: any;
85
- error?: undefined;
86
- } | {
87
- error: any;
88
- data?: undefined;
89
- }>;
90
- sendToQueue(channelName: string, payload: any, options?: {
91
- persistent: boolean;
92
- }): Promise<{
93
- data: any;
94
- error?: undefined;
95
- } | {
96
- error: any;
97
- data?: undefined;
98
- }>;
99
- /**
100
- * Static version of assertExchange
101
- */
102
- static assertExchange(exchangeName: string, exchangeType?: string, option?: any): Promise<{
103
- data: any;
104
- error?: undefined;
105
- } | {
106
- error: any;
107
- data?: undefined;
108
- }>;
109
- /**
110
- *
111
- * @param {string} exchangeName
112
- * @param {string} exchangeType (fanout, direct, topic)
113
- * @param {Object} option
114
- * @return {Promise<{error: *}|{data: ({data}|{error: *})}>}
115
- */
116
- assertExchange(exchangeName: string, exchangeType?: string, option?: any): Promise<{
117
- data: any;
118
- error?: undefined;
119
- } | {
120
- error: any;
121
- data?: undefined;
122
- }>;
123
- /**
124
- * Static version of assertQueue
125
- */
126
- static assertQueue(exchangeName: string, queueName?: string, bindKey?: string, queueOption?: any): Promise<{
127
- data: any;
128
- error?: undefined;
129
- } | {
130
- error: any;
131
- data?: undefined;
132
- }>;
133
- /***
134
- *
135
- * @param {string} exchangeName
136
- * @param {string} queueName
137
- * @param {Object} queueOption
138
- * @param {string} bindKey
139
- * @return {Promise<{data: *}|{error: *}>}
140
- */
141
- assertQueue(exchangeName: string, queueName?: string, bindKey?: string, queueOption?: any): Promise<{
142
- data: any;
143
- error?: undefined;
144
- } | {
145
- error: any;
146
- data?: undefined;
147
- }>;
148
- /**
149
- * Static version of publishToExchange
150
- */
151
- static publishToExchange(exchangeName: string, routeKey: string | undefined, payload: any): Promise<{
152
- data: any;
153
- error?: undefined;
154
- } | {
155
- error: any;
156
- data?: undefined;
157
- }>;
158
- /**
159
- *
160
- * @param {string} exchangeName
161
- * @param {string} routeKey
162
- * @param {string} payload
163
- * @return Promise<*>
164
- */
165
- publishToExchange(exchangeName: string, routeKey: string | undefined, payload: any): Promise<{
166
- data: any;
167
- error?: undefined;
168
- } | {
169
- error: any;
170
- data?: undefined;
171
- }>;
172
- /**
173
- * Static version of listen
174
- */
175
- static listen(channelName: string, options: any, callback: any): Promise<void>;
176
- /**
177
- *
178
- * @param {string} channelName
179
- * @param {Object} options
180
- * @param {function} callback
181
- * @param {number} prefetch
182
- * @return {null}
183
- */
184
- listen(channelName: string, options: any, callback: any): Promise<void>;
185
- /**
186
- * Static version of sendToDeadLetter
187
- */
188
- static sendToDeadLetter(deadLetterEntity: BrokerDeadLetterPayloadEntity): Promise<void>;
189
- sendToDeadLetter(deadLetterEntity: BrokerDeadLetterPayloadEntity): Promise<void>;
190
- /**
191
- * Static version of sendToRetry
192
- */
193
- static sendToRetry(retryEntity: BrokerRetryEntity): Promise<void>;
194
- sendToRetry(retryEntity: BrokerRetryEntity): Promise<void>;
195
- /**
196
- * Static version of requeueDeadLetter
197
- */
198
- static requeueDeadLetter(deadLetterQueueName: string, queueOptions?: any): Promise<void>;
199
- requeueDeadLetter(deadLetterQueueName: string, queueOptions?: any): Promise<void>;
200
- /**
201
- * Static version of close
202
- */
203
- static close(): void;
204
- close(): void;
205
- }