@mondart/nestjs-common-module 1.1.70 → 1.1.72
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/dist/decorators/get-agent.decorator.d.ts +1 -0
- package/dist/decorators/get-agent.decorator.js +24 -0
- package/dist/decorators/get-store-id.decorator.d.ts +1 -0
- package/dist/decorators/get-store-id.decorator.js +12 -0
- package/dist/decorators/get-user.decorator.d.ts +1 -0
- package/dist/decorators/get-user.decorator.js +23 -0
- package/dist/decorators/iam-context.decorator.d.ts +1 -0
- package/dist/decorators/iam-context.decorator.js +44 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.js +5 -0
- package/dist/dto/response/iam-context.dto.d.ts +13 -0
- package/dist/dto/response/iam-context.dto.js +71 -0
- package/dist/dto/response/index.d.ts +1 -0
- package/dist/dto/response/index.js +1 -0
- package/dist/interfaces/get-agent.interface.d.ts +7 -0
- package/dist/interfaces/get-agent.interface.js +2 -0
- package/dist/interfaces/get-user.interface.d.ts +6 -0
- package/dist/interfaces/get-user.interface.js +2 -0
- package/dist/interfaces/index.d.ts +6 -1
- package/dist/interfaces/index.js +6 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GetAgent: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAgent = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.GetAgent = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
const injectedPayload = request?.headers?.['injectedpayload'];
|
|
8
|
+
if (injectedPayload) {
|
|
9
|
+
const data = JSON.parse(injectedPayload);
|
|
10
|
+
const token = request?.headers?.['authorization'];
|
|
11
|
+
if (data) {
|
|
12
|
+
if (data?.is_agent)
|
|
13
|
+
request.agent = {
|
|
14
|
+
agentId: data?.sub,
|
|
15
|
+
isAgent: data?.is_agent,
|
|
16
|
+
storeIds: data?.store_ids,
|
|
17
|
+
groupsMembership: data?.groups_membership,
|
|
18
|
+
token,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
delete request?.headers?.['authorization'];
|
|
22
|
+
}
|
|
23
|
+
return request?.agent ? request?.agent : null;
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GetStoreId: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetStoreId = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.GetStoreId = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
const stringData = request?.headers?.['store_id'];
|
|
8
|
+
if (stringData) {
|
|
9
|
+
return { storeId: Number(stringData) ?? null };
|
|
10
|
+
}
|
|
11
|
+
return { storeId: null };
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GetUser: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetUser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.GetUser = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
const injectedPayload = request?.headers?.['injectedpayload'];
|
|
8
|
+
if (injectedPayload) {
|
|
9
|
+
const data = JSON.parse(injectedPayload);
|
|
10
|
+
const token = request?.headers?.['authorization'];
|
|
11
|
+
if (data) {
|
|
12
|
+
if (!data?.is_agent && (data?.contact_id || data?.store_id))
|
|
13
|
+
request.user = {
|
|
14
|
+
contactId: data?.contact_id,
|
|
15
|
+
storeId: data?.store_id,
|
|
16
|
+
isAgent: data?.is_agent ?? false,
|
|
17
|
+
token,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
delete request?.headers?.['authorization'];
|
|
21
|
+
}
|
|
22
|
+
return request?.user ? request?.user : null;
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const IamContext: (...dataOrPipes: unknown[]) => ParameterDecorator;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IamContext = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const crypto_1 = require("crypto");
|
|
6
|
+
const iam_context_dto_1 = require("../dto/response/iam-context.dto");
|
|
7
|
+
exports.IamContext = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
8
|
+
const request = ctx.switchToHttp().getRequest();
|
|
9
|
+
const iam = new iam_context_dto_1.IamContextDto();
|
|
10
|
+
const injectedPayload = request?.headers?.['injectedpayload'];
|
|
11
|
+
iam.ip =
|
|
12
|
+
request?.headers['x-forwarded-for'] ||
|
|
13
|
+
request?.socket?.remoteAddress ||
|
|
14
|
+
null;
|
|
15
|
+
iam.requestId = request?.headers['request-id'] ?? (0, crypto_1.randomUUID)();
|
|
16
|
+
iam.timestamp = new Date(request?.headers?.['timestamp']);
|
|
17
|
+
if (injectedPayload) {
|
|
18
|
+
const data = JSON.parse(injectedPayload);
|
|
19
|
+
const token = request?.headers?.['authorization'];
|
|
20
|
+
if (data) {
|
|
21
|
+
if (!data?.is_agent && (data?.contact_id || data?.store_id)) {
|
|
22
|
+
iam.user = {
|
|
23
|
+
userId: data?.sub,
|
|
24
|
+
contactId: data?.contact_id,
|
|
25
|
+
storeId: data?.store_id,
|
|
26
|
+
token,
|
|
27
|
+
};
|
|
28
|
+
iam.userId = data?.sub;
|
|
29
|
+
}
|
|
30
|
+
else if (data?.is_agent) {
|
|
31
|
+
iam.agent = {
|
|
32
|
+
agentId: data?.sub,
|
|
33
|
+
isAgent: data?.is_agent,
|
|
34
|
+
storeIds: data?.store_ids,
|
|
35
|
+
groupsMembership: data?.groups_membership,
|
|
36
|
+
token,
|
|
37
|
+
};
|
|
38
|
+
iam.agentId = data?.sub;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
delete request?.headers?.['authorization'];
|
|
42
|
+
}
|
|
43
|
+
return iam;
|
|
44
|
+
});
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export * from './validations';
|
|
2
2
|
export * from './swagger-api-response.decorator';
|
|
3
|
+
export * from './entity-order.decorator';
|
|
4
|
+
export * from './get-agent.decorator';
|
|
5
|
+
export * from './get-store-id.decorator';
|
|
6
|
+
export * from './get-user.decorator';
|
|
7
|
+
export * from './iam-context.decorator';
|
package/dist/decorators/index.js
CHANGED
|
@@ -16,3 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./validations"), exports);
|
|
18
18
|
__exportStar(require("./swagger-api-response.decorator"), exports);
|
|
19
|
+
__exportStar(require("./entity-order.decorator"), exports);
|
|
20
|
+
__exportStar(require("./get-agent.decorator"), exports);
|
|
21
|
+
__exportStar(require("./get-store-id.decorator"), exports);
|
|
22
|
+
__exportStar(require("./get-user.decorator"), exports);
|
|
23
|
+
__exportStar(require("./iam-context.decorator"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { GetUserInterface } from '../../interfaces/get-user.interface';
|
|
2
|
+
import { GetAgentInterface } from '../../interfaces/get-agent.interface';
|
|
3
|
+
export declare class IamContextDto {
|
|
4
|
+
timestamp: Date;
|
|
5
|
+
requestId: string;
|
|
6
|
+
ip?: string;
|
|
7
|
+
user?: GetUserInterface;
|
|
8
|
+
userId: string;
|
|
9
|
+
contactId: number;
|
|
10
|
+
agent?: GetAgentInterface;
|
|
11
|
+
agentId: string;
|
|
12
|
+
constructor(init?: Partial<any>);
|
|
13
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.IamContextDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
class IamContextDto {
|
|
17
|
+
constructor(init) {
|
|
18
|
+
this.ip = init?.ip;
|
|
19
|
+
this.agent = init?.agent;
|
|
20
|
+
if (init?.agent?.agentId)
|
|
21
|
+
this.agentId = init?.agent?.agentId;
|
|
22
|
+
this.user = init?.user;
|
|
23
|
+
if (init?.user?.contactId)
|
|
24
|
+
this.contactId = init?.user?.contactId;
|
|
25
|
+
if (init?.user?.userId)
|
|
26
|
+
this.userId = init?.user?.userId;
|
|
27
|
+
this.requestId = init?.requestId ?? (0, crypto_1.randomUUID)();
|
|
28
|
+
this.timestamp = init?.timestamp ?? new Date();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.IamContextDto = IamContextDto;
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, swagger_1.ApiResponseProperty)({ type: Date }),
|
|
34
|
+
(0, class_validator_1.IsDate)(),
|
|
35
|
+
__metadata("design:type", Date)
|
|
36
|
+
], IamContextDto.prototype, "timestamp", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, swagger_1.ApiResponseProperty)({ type: String }),
|
|
39
|
+
(0, class_validator_1.IsString)(),
|
|
40
|
+
__metadata("design:type", String)
|
|
41
|
+
], IamContextDto.prototype, "requestId", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, swagger_1.ApiResponseProperty)({ type: String }),
|
|
44
|
+
(0, class_validator_1.IsString)(),
|
|
45
|
+
__metadata("design:type", String)
|
|
46
|
+
], IamContextDto.prototype, "ip", void 0);
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, swagger_1.ApiResponseProperty)({ type: Object }),
|
|
49
|
+
(0, class_validator_1.IsObject)(),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], IamContextDto.prototype, "user", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, swagger_1.ApiResponseProperty)({ type: String }),
|
|
54
|
+
(0, class_validator_1.IsString)(),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], IamContextDto.prototype, "userId", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, swagger_1.ApiResponseProperty)({ type: Number }),
|
|
59
|
+
(0, class_validator_1.IsNumber)(),
|
|
60
|
+
__metadata("design:type", Number)
|
|
61
|
+
], IamContextDto.prototype, "contactId", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, swagger_1.ApiResponseProperty)({ type: Object }),
|
|
64
|
+
(0, class_validator_1.IsObject)(),
|
|
65
|
+
__metadata("design:type", Object)
|
|
66
|
+
], IamContextDto.prototype, "agent", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, swagger_1.ApiResponseProperty)({ type: String }),
|
|
69
|
+
(0, class_validator_1.IsString)(),
|
|
70
|
+
__metadata("design:type", String)
|
|
71
|
+
], IamContextDto.prototype, "agentId", void 0);
|
|
@@ -21,3 +21,4 @@ __exportStar(require("./success-response.dto"), exports);
|
|
|
21
21
|
__exportStar(require("./validation.dto"), exports);
|
|
22
22
|
__exportStar(require("./kafka-success-response.dto"), exports);
|
|
23
23
|
__exportStar(require("./kafka-failed-response.dto"), exports);
|
|
24
|
+
__exportStar(require("./iam-context.dto"), exports);
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export * from './crud-service.option';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './custom-validation-arguments.interface';
|
|
3
|
+
export * from './get-agent.interface';
|
|
4
|
+
export * from './get-user.interface';
|
|
5
|
+
export * from './kafka-failed-response.interface';
|
|
6
|
+
export * from './kafka-success-response.interface';
|
|
7
|
+
export * from './pagination-query';
|
package/dist/interfaces/index.js
CHANGED
|
@@ -15,4 +15,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./crud-service.option"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./custom-validation-arguments.interface"), exports);
|
|
19
|
+
__exportStar(require("./get-agent.interface"), exports);
|
|
20
|
+
__exportStar(require("./get-user.interface"), exports);
|
|
21
|
+
__exportStar(require("./kafka-failed-response.interface"), exports);
|
|
22
|
+
__exportStar(require("./kafka-success-response.interface"), exports);
|
|
23
|
+
__exportStar(require("./pagination-query"), exports);
|