@mondart/nestjs-common-module-iam 1.0.0
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/constants/iam-decorator-key.const.d.ts +5 -0
- package/dist/constants/iam-decorator-key.const.d.ts.map +1 -0
- package/dist/constants/iam-decorator-key.const.js +8 -0
- package/dist/constants/iam-decorator-key.const.js.map +1 -0
- package/dist/decorators/get-owner-id.decorator.d.ts +2 -0
- package/dist/decorators/get-owner-id.decorator.d.ts.map +1 -0
- package/dist/decorators/get-owner-id.decorator.js +13 -0
- package/dist/decorators/get-owner-id.decorator.js.map +1 -0
- package/dist/decorators/iam-public.decorator.d.ts +2 -0
- package/dist/decorators/iam-public.decorator.d.ts.map +1 -0
- package/dist/decorators/iam-public.decorator.js +8 -0
- package/dist/decorators/iam-public.decorator.js.map +1 -0
- package/dist/decorators/owns-entity.decorator.d.ts +10 -0
- package/dist/decorators/owns-entity.decorator.d.ts.map +1 -0
- package/dist/decorators/owns-entity.decorator.js +8 -0
- package/dist/decorators/owns-entity.decorator.js.map +1 -0
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts +3 -0
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts.map +1 -0
- package/dist/decorators/set-iam-route-user-type.decorator.js +8 -0
- package/dist/decorators/set-iam-route-user-type.decorator.js.map +1 -0
- package/dist/enums/iam-user-type.enum.d.ts +6 -0
- package/dist/enums/iam-user-type.enum.d.ts.map +1 -0
- package/dist/enums/iam-user-type.enum.js +10 -0
- package/dist/enums/iam-user-type.enum.js.map +1 -0
- package/dist/guards/iam-context.guard.d.ts +11 -0
- package/dist/guards/iam-context.guard.d.ts.map +1 -0
- package/dist/guards/iam-context.guard.js +109 -0
- package/dist/guards/iam-context.guard.js.map +1 -0
- package/dist/iam-context.module.d.ts +3 -0
- package/dist/iam-context.module.d.ts.map +1 -0
- package/dist/iam-context.module.js +26 -0
- package/dist/iam-context.module.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/pipes/iam-paginate-query.pipe.d.ts +8 -0
- package/dist/pipes/iam-paginate-query.pipe.d.ts.map +1 -0
- package/dist/pipes/iam-paginate-query.pipe.js +47 -0
- package/dist/pipes/iam-paginate-query.pipe.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const IAM_PUBLIC_ROUTE = "iamPublicRoute";
|
|
2
|
+
export declare const IAM_ROUTE_USER_TYPE = "iamRouteUserType";
|
|
3
|
+
export declare const IAM_PRIVATE_ROUTE = "iamPrivateRoute";
|
|
4
|
+
export declare const IAM_OWN_ROUTE = "iamOwnRoute";
|
|
5
|
+
//# sourceMappingURL=iam-decorator-key.const.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-decorator-key.const.d.ts","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AACjD,eAAO,MAAM,mBAAmB,qBAAqB,CAAC;AACtD,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AACnD,eAAO,MAAM,aAAa,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IAM_OWN_ROUTE = exports.IAM_PRIVATE_ROUTE = exports.IAM_ROUTE_USER_TYPE = exports.IAM_PUBLIC_ROUTE = void 0;
|
|
4
|
+
exports.IAM_PUBLIC_ROUTE = 'iamPublicRoute';
|
|
5
|
+
exports.IAM_ROUTE_USER_TYPE = 'iamRouteUserType';
|
|
6
|
+
exports.IAM_PRIVATE_ROUTE = 'iamPrivateRoute';
|
|
7
|
+
exports.IAM_OWN_ROUTE = 'iamOwnRoute';
|
|
8
|
+
//# sourceMappingURL=iam-decorator-key.const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-decorator-key.const.js","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,gBAAgB,CAAC;AACpC,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AACzC,QAAA,iBAAiB,GAAG,iBAAiB,CAAC;AACtC,QAAA,aAAa,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-owner-id.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/get-owner-id.decorator.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,mDAU/B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetOwnerIdDecorator = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const nestjs_common_module_core_1 = require("@mondart/nestjs-common-module-core");
|
|
6
|
+
exports.GetOwnerIdDecorator = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
7
|
+
const request = ctx.switchToHttp().getRequest();
|
|
8
|
+
if (!request.isOwnerRoute)
|
|
9
|
+
return null;
|
|
10
|
+
const iamContext = (0, nestjs_common_module_core_1.getIamContext)(request);
|
|
11
|
+
return iamContext?.user?.contactId;
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=get-owner-id.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-owner-id.decorator.js","sourceRoot":"","sources":["../../src/decorators/get-owner-id.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwE;AACxE,kFAAmE;AAEtD,QAAA,mBAAmB,GAAG,IAAA,6BAAoB,EACrD,CAAC,IAAa,EAAE,GAAqB,EAAE,EAAE;IACvC,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;IAEhD,IAAI,CAAC,OAAO,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAEvC,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;AACrC,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-public.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/iam-public.decorator.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,wDACC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IamPublicRouteDecorator = void 0;
|
|
4
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const IamPublicRouteDecorator = () => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_PUBLIC_ROUTE, true);
|
|
7
|
+
exports.IamPublicRouteDecorator = IamPublicRouteDecorator;
|
|
8
|
+
//# sourceMappingURL=iam-public.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-public.decorator.js","sourceRoot":"","sources":["../../src/decorators/iam-public.decorator.ts"],"names":[],"mappings":";;;AAAA,kFAAwE;AACxE,2CAA6C;AAEtC,MAAM,uBAAuB,GAAG,GAAG,EAAE,CAC1C,IAAA,oBAAW,EAAC,0CAAgB,EAAE,IAAI,CAAC,CAAC;AADzB,QAAA,uBAAuB,2BACE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseModelEntity } from '@mondart/nestjs-common-module-core';
|
|
2
|
+
export declare const OWNS_ENTITY_KEY = "owns_entity";
|
|
3
|
+
export interface OwnsEntityOptions<T extends BaseModelEntity = BaseModelEntity> {
|
|
4
|
+
entity: new (...args: any[]) => T;
|
|
5
|
+
entityPropertyKey: keyof T;
|
|
6
|
+
requestEntityId: (req: any) => string | number;
|
|
7
|
+
ownerPropertyKey: keyof T;
|
|
8
|
+
}
|
|
9
|
+
export declare const OwnsEntity: <T extends BaseModelEntity = BaseModelEntity>(option: OwnsEntityOptions<T>) => import("@nestjs/common").CustomDecorator<string>;
|
|
10
|
+
//# sourceMappingURL=owns-entity.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owns-entity.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/owns-entity.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAE7C,MAAM,WAAW,iBAAiB,CAChC,CAAC,SAAS,eAAe,GAAG,eAAe;IAE3C,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IAClC,iBAAiB,EAAE,MAAM,CAAC,CAAC;IAC3B,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,MAAM,CAAC;IAC/C,gBAAgB,EAAE,MAAM,CAAC,CAAC;CAC3B;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,eAAe,GAAG,eAAe,EACpE,QAAQ,iBAAiB,CAAC,CAAC,CAAC,qDACW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OwnsEntity = exports.OWNS_ENTITY_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.OWNS_ENTITY_KEY = 'owns_entity';
|
|
6
|
+
const OwnsEntity = (option) => (0, common_1.SetMetadata)(exports.OWNS_ENTITY_KEY, option);
|
|
7
|
+
exports.OwnsEntity = OwnsEntity;
|
|
8
|
+
//# sourceMappingURL=owns-entity.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"owns-entity.decorator.js","sourceRoot":"","sources":["../../src/decorators/owns-entity.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAGhC,QAAA,eAAe,GAAG,aAAa,CAAC;AAWtC,MAAM,UAAU,GAAG,CACxB,MAA4B,EAC5B,EAAE,CAAC,IAAA,oBAAW,EAAC,uBAAe,EAAE,MAAM,CAAC,CAAC;AAF7B,QAAA,UAAU,cAEmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-iam-route-user-type.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/set-iam-route-user-type.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,eAAO,MAAM,4BAA4B,GAAI,WAAW,eAAe,EAAE,qDAC5B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SetIamRouteUserTypeDecorator = void 0;
|
|
4
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const SetIamRouteUserTypeDecorator = (userTypes) => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_ROUTE_USER_TYPE, userTypes);
|
|
7
|
+
exports.SetIamRouteUserTypeDecorator = SetIamRouteUserTypeDecorator;
|
|
8
|
+
//# sourceMappingURL=set-iam-route-user-type.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-iam-route-user-type.decorator.js","sourceRoot":"","sources":["../../src/decorators/set-iam-route-user-type.decorator.ts"],"names":[],"mappings":";;;AAAA,kFAA2E;AAC3E,2CAA6C;AAGtC,MAAM,4BAA4B,GAAG,CAAC,SAA4B,EAAE,EAAE,CAC3E,IAAA,oBAAW,EAAC,6CAAmB,EAAE,SAAS,CAAC,CAAC;AADjC,QAAA,4BAA4B,gCACK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-user-type.enum.d.ts","sourceRoot":"","sources":["../../src/enums/iam-user-type.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;CAChB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IamUserTypeEnum = void 0;
|
|
4
|
+
var IamUserTypeEnum;
|
|
5
|
+
(function (IamUserTypeEnum) {
|
|
6
|
+
IamUserTypeEnum["AGENT"] = "AGENT";
|
|
7
|
+
IamUserTypeEnum["USER"] = "USER";
|
|
8
|
+
IamUserTypeEnum["GUEST"] = "GUEST";
|
|
9
|
+
})(IamUserTypeEnum || (exports.IamUserTypeEnum = IamUserTypeEnum = {}));
|
|
10
|
+
//# sourceMappingURL=iam-user-type.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-user-type.enum.js","sourceRoot":"","sources":["../../src/enums/iam-user-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,gCAAa,CAAA;IACb,kCAAe,CAAA;AACjB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { Reflector } from '@nestjs/core';
|
|
3
|
+
import { DataSource } from 'typeorm';
|
|
4
|
+
export declare class IamContextGuard implements CanActivate {
|
|
5
|
+
private readonly reflector;
|
|
6
|
+
private readonly dataSource;
|
|
7
|
+
constructor(reflector: Reflector, dataSource: DataSource);
|
|
8
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
+
private checkOwnership;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=iam-context.guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context.guard.d.ts","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAKjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAiBzC,OAAO,EAAE,UAAU,EAAU,MAAM,SAAS,CAAC;AAE7C,qBACa,eAAgB,YAAW,WAAW;IAE/C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAFV,SAAS,EAAE,SAAS,EAEpB,UAAU,EAAE,UAAU;IAGnC,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;YAgEhD,cAAc;CA6C7B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.IamContextGuard = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
18
|
+
const nestjs_common_module_core_1 = require("@mondart/nestjs-common-module-core");
|
|
19
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
20
|
+
const iam_user_type_enum_1 = require("../enums/iam-user-type.enum");
|
|
21
|
+
const owns_entity_decorator_1 = require("../decorators/owns-entity.decorator");
|
|
22
|
+
const constants_1 = require("@nestjs/common/constants");
|
|
23
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
24
|
+
const typeorm_2 = require("typeorm");
|
|
25
|
+
let IamContextGuard = class IamContextGuard {
|
|
26
|
+
constructor(reflector, dataSource) {
|
|
27
|
+
this.reflector = reflector;
|
|
28
|
+
this.dataSource = dataSource;
|
|
29
|
+
}
|
|
30
|
+
async canActivate(context) {
|
|
31
|
+
const request = context.switchToHttp().getRequest();
|
|
32
|
+
const iamContext = (0, nestjs_common_module_core_1.getIamContext)(request);
|
|
33
|
+
const iaPublicRoute = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_PUBLIC_ROUTE, [context.getHandler(), context.getClass()]);
|
|
34
|
+
if (iaPublicRoute)
|
|
35
|
+
return true;
|
|
36
|
+
const userType = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_ROUTE_USER_TYPE, [
|
|
37
|
+
context.getHandler(),
|
|
38
|
+
context.getClass(),
|
|
39
|
+
]) || [];
|
|
40
|
+
if (iamContext.agentId) {
|
|
41
|
+
if (userType.includes(iam_user_type_enum_1.IamUserTypeEnum.AGENT)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new common_1.ForbiddenException();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (userType.includes(iam_user_type_enum_1.IamUserTypeEnum.USER) ||
|
|
49
|
+
userType.includes(iam_user_type_enum_1.IamUserTypeEnum.GUEST)) {
|
|
50
|
+
const options = this.reflector.getAllAndOverride(owns_entity_decorator_1.OWNS_ENTITY_KEY, [context.getHandler(), context.getClass()]);
|
|
51
|
+
if (options) {
|
|
52
|
+
const isOwner = await this.checkOwnership(options.entity.name, options.entityPropertyKey, options.requestEntityId(request), options.ownerPropertyKey, iamContext?.user?.contactId);
|
|
53
|
+
const controllerPath = this.reflector.getAllAndOverride(constants_1.PATH_METADATA, [
|
|
54
|
+
context.getHandler(),
|
|
55
|
+
context.getClass(),
|
|
56
|
+
]) ?? '';
|
|
57
|
+
if (!isOwner) {
|
|
58
|
+
throw new common_1.ForbiddenException(`You do not own this ${controllerPath}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new common_1.ForbiddenException();
|
|
65
|
+
}
|
|
66
|
+
throw new common_1.UnauthorizedException();
|
|
67
|
+
}
|
|
68
|
+
async checkOwnership(entity, entityPropertyKey, entityId, ownerPropertyKey, ownerId) {
|
|
69
|
+
if (!entityId)
|
|
70
|
+
return true;
|
|
71
|
+
const queryRunner = this.dataSource.createQueryRunner();
|
|
72
|
+
await queryRunner.connect();
|
|
73
|
+
await queryRunner.startTransaction('READ UNCOMMITTED');
|
|
74
|
+
try {
|
|
75
|
+
const entityManager = queryRunner.manager;
|
|
76
|
+
const isExists = await entityManager.getRepository(entity).exists({
|
|
77
|
+
where: {
|
|
78
|
+
[entityPropertyKey]: entityId,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
if (!isExists) {
|
|
82
|
+
throw new common_1.NotFoundException(nestjs_common_module_core_1.MessageFormatter.replace(nestjs_common_module_core_1.SharedMessages.RESOURCE_NOT_FOUND, 'Cart'));
|
|
83
|
+
}
|
|
84
|
+
const isBlongeToOwner = await entityManager.getRepository(entity).exists({
|
|
85
|
+
where: {
|
|
86
|
+
[entityPropertyKey]: entityId,
|
|
87
|
+
[ownerPropertyKey]: ownerId || (0, typeorm_2.IsNull)(),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
await queryRunner.commitTransaction();
|
|
91
|
+
return isBlongeToOwner;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
await queryRunner.rollbackTransaction();
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
await queryRunner.release();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.IamContextGuard = IamContextGuard;
|
|
103
|
+
exports.IamContextGuard = IamContextGuard = __decorate([
|
|
104
|
+
(0, common_1.Injectable)(),
|
|
105
|
+
__param(1, (0, typeorm_1.InjectDataSource)()),
|
|
106
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
107
|
+
typeorm_2.DataSource])
|
|
108
|
+
], IamContextGuard);
|
|
109
|
+
//# sourceMappingURL=iam-context.guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context.guard.js","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAyC;AACzC,kFAI4C;AAC5C,kFAG8C;AAC9C,oEAA8D;AAC9D,+EAG6C;AAC7C,wDAAyD;AACzD,6CAAmD;AACnD,qCAA6C;AAGtC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YACmB,SAAoB,EAEpB,UAAsB;QAFtB,cAAS,GAAT,SAAS,CAAW;QAEpB,eAAU,GAAV,UAAU,CAAY;IACtC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,OAAO,CAAC,CAA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gB,CAAC,EAAE,OAAO,IAAI,IAAA,gBAAM,GAAE;iBACxC;aACF,CAAC,CAAC;YAEH,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;YAEtC,OAAO,eAAe,CAAC;QACzB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;YACxC,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;CACF,CAAA;AApHY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,0BAAgB,GAAE,CAAA;qCADS,gBAAS;QAER,oBAAU;GAJ9B,eAAe,CAoH3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context.module.d.ts","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":"AAIA,qBAQa,gBAAgB;CAAG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IamContextModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const iam_context_guard_1 = require("./guards/iam-context.guard");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
let IamContextModule = class IamContextModule {
|
|
14
|
+
};
|
|
15
|
+
exports.IamContextModule = IamContextModule;
|
|
16
|
+
exports.IamContextModule = IamContextModule = __decorate([
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
providers: [
|
|
19
|
+
{
|
|
20
|
+
provide: core_1.APP_GUARD,
|
|
21
|
+
useClass: iam_context_guard_1.IamContextGuard,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
})
|
|
25
|
+
], IamContextModule);
|
|
26
|
+
//# sourceMappingURL=iam-context.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context.module.js","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,kEAA6D;AAC7D,uCAAyC;AAUlC,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAR5B,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT;gBACE,OAAO,EAAE,gBAAS;gBAClB,QAAQ,EAAE,mCAAe;aAC1B;SACF;KACF,CAAC;GACW,gBAAgB,CAAG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './decorators/get-owner-id.decorator';
|
|
2
|
+
export * from './decorators/iam-public.decorator';
|
|
3
|
+
export * from './decorators/owns-entity.decorator';
|
|
4
|
+
export * from './decorators/set-iam-route-user-type.decorator';
|
|
5
|
+
export * from './enums/iam-user-type.enum';
|
|
6
|
+
export * from './guards/iam-context.guard';
|
|
7
|
+
export * from './pipes/iam-paginate-query.pipe';
|
|
8
|
+
export * from './iam-context.module';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gDAAgD,CAAC;AAC/D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decorators/get-owner-id.decorator"), exports);
|
|
18
|
+
__exportStar(require("./decorators/iam-public.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/owns-entity.decorator"), exports);
|
|
20
|
+
__exportStar(require("./decorators/set-iam-route-user-type.decorator"), exports);
|
|
21
|
+
__exportStar(require("./enums/iam-user-type.enum"), exports);
|
|
22
|
+
__exportStar(require("./guards/iam-context.guard"), exports);
|
|
23
|
+
__exportStar(require("./pipes/iam-paginate-query.pipe"), exports);
|
|
24
|
+
__exportStar(require("./iam-context.module"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sEAAoD;AACpD,oEAAkD;AAClD,qEAAmD;AACnD,iFAA+D;AAC/D,6DAA2C;AAC3C,6DAA2C;AAC3C,kEAAgD;AAChD,uDAAqC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PipeTransform, ArgumentMetadata } from '@nestjs/common';
|
|
2
|
+
import { PaginateQuery } from 'nestjs-paginate';
|
|
3
|
+
export declare class IamPaginateQueryPipe implements PipeTransform {
|
|
4
|
+
private readonly request;
|
|
5
|
+
constructor(request: Request);
|
|
6
|
+
transform(value: PaginateQuery, metadata: ArgumentMetadata): PaginateQuery;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=iam-paginate-query.pipe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-paginate-query.pipe.d.ts","sourceRoot":"","sources":["../../src/pipes/iam-paginate-query.pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD,qBACa,oBAAqB,YAAW,aAAa;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAE9D,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB;CAoB3D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.IamPaginateQueryPipe = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const core_1 = require("@nestjs/core");
|
|
18
|
+
const nestjs_common_module_core_1 = require("@mondart/nestjs-common-module-core");
|
|
19
|
+
let IamPaginateQueryPipe = class IamPaginateQueryPipe {
|
|
20
|
+
constructor(request) {
|
|
21
|
+
this.request = request;
|
|
22
|
+
}
|
|
23
|
+
transform(value, metadata) {
|
|
24
|
+
const iamContext = (0, nestjs_common_module_core_1.getIamContext)(this.request);
|
|
25
|
+
if (!iamContext?.isAgent && iamContext?.user) {
|
|
26
|
+
const { storeId, contactId } = iamContext.user;
|
|
27
|
+
value.filter = {
|
|
28
|
+
contactId: `$eq:${contactId}`,
|
|
29
|
+
storeId: `$eq:${storeId}`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (!iamContext?.isAgent && !iamContext?.user) {
|
|
33
|
+
value.filter = {
|
|
34
|
+
contactId: `$null`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
value.withDeleted = true;
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.IamPaginateQueryPipe = IamPaginateQueryPipe;
|
|
42
|
+
exports.IamPaginateQueryPipe = IamPaginateQueryPipe = __decorate([
|
|
43
|
+
(0, common_1.Injectable)(),
|
|
44
|
+
__param(0, (0, common_1.Inject)(core_1.REQUEST)),
|
|
45
|
+
__metadata("design:paramtypes", [Request])
|
|
46
|
+
], IamPaginateQueryPipe);
|
|
47
|
+
//# sourceMappingURL=iam-paginate-query.pipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-paginate-query.pipe.js","sourceRoot":"","sources":["../../src/pipes/iam-paginate-query.pipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKwB;AAExB,uCAAuC;AACvC,kFAAmE;AAG5D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC/B,YAA8C,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAElE,SAAS,CAAC,KAAoB,EAAE,QAA0B;QACxD,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE/C,IAAI,CAAC,UAAU,EAAE,OAAO,IAAI,UAAU,EAAE,IAAI,EAAE,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;YAC/C,KAAK,CAAC,MAAM,GAAG;gBACb,SAAS,EAAE,OAAO,SAAS,EAAE;gBAC7B,OAAO,EAAE,OAAO,OAAO,EAAE;aAC1B,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,OAAO,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;YAC9C,KAAK,CAAC,MAAM,GAAG;gBACb,SAAS,EAAE,OAAO;aAEnB,CAAC;QACJ,CAAC;QACD,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAvBY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;qCAA2B,OAAO;GADnD,oBAAoB,CAuBhC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mondart/nestjs-common-module-iam",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Reusable IAM (Identity and Access Management) utilities for NestJS.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Mondart"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@mondart/nestjs-common-module-core": "^3.1.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@nestjs/common": "^11.1.10",
|
|
24
|
+
"@nestjs/core": "^11.1.10",
|
|
25
|
+
"@nestjs/swagger": "^11.0.3",
|
|
26
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
27
|
+
"class-transformer": "^0.5.1",
|
|
28
|
+
"class-validator": "^0.14.3",
|
|
29
|
+
"nestjs-paginate": "^12.8.3",
|
|
30
|
+
"reflect-metadata": "^0.2.0",
|
|
31
|
+
"rxjs": "^7.8.2",
|
|
32
|
+
"typeorm": "^0.3.28"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
}
|
|
37
|
+
}
|