@mondart/nestjs-common-module-iam 1.0.0 → 3.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 +7 -4
- package/dist/constants/iam-decorator-key.const.d.ts.map +1 -1
- package/dist/constants/iam-decorator-key.const.js +8 -5
- package/dist/constants/iam-decorator-key.const.js.map +1 -1
- package/dist/decorators/allow-iam.decorator.d.ts +3 -0
- package/dist/decorators/allow-iam.decorator.d.ts.map +1 -0
- package/dist/decorators/allow-iam.decorator.js +8 -0
- package/dist/decorators/allow-iam.decorator.js.map +1 -0
- package/dist/decorators/iam-entity-access.decorator.d.ts +4 -0
- package/dist/decorators/iam-entity-access.decorator.d.ts.map +1 -0
- package/dist/decorators/iam-entity-access.decorator.js +10 -0
- package/dist/decorators/iam-entity-access.decorator.js.map +1 -0
- package/dist/decorators/public-iam.decorators.d.ts +2 -0
- package/dist/decorators/public-iam.decorators.d.ts.map +1 -0
- package/dist/decorators/public-iam.decorators.js +8 -0
- package/dist/decorators/public-iam.decorators.js.map +1 -0
- package/dist/guards/iam-context.guard.d.ts +3 -4
- package/dist/guards/iam-context.guard.d.ts.map +1 -1
- package/dist/guards/iam-context.guard.js +22 -71
- package/dist/guards/iam-context.guard.js.map +1 -1
- package/dist/helpers/user-owner.helper.d.ts +12 -0
- package/dist/helpers/user-owner.helper.d.ts.map +1 -0
- package/dist/helpers/user-owner.helper.js +55 -0
- package/dist/helpers/user-owner.helper.js.map +1 -0
- package/dist/iam-context.module.d.ts.map +1 -1
- package/dist/iam-context.module.js +2 -0
- package/dist/iam-context.module.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/iam-entity-access.interface.d.ts +38 -0
- package/dist/interfaces/iam-entity-access.interface.d.ts.map +1 -0
- package/dist/interfaces/iam-entity-access.interface.js +3 -0
- package/dist/interfaces/iam-entity-access.interface.js.map +1 -0
- package/dist/pipes/iam-find-one-query-scope.pipe.d.ts +10 -0
- package/dist/pipes/iam-find-one-query-scope.pipe.d.ts.map +1 -0
- package/dist/pipes/{iam-paginate-query.pipe.js → iam-find-one-query-scope.pipe.js} +22 -24
- package/dist/pipes/iam-find-one-query-scope.pipe.js.map +1 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.d.ts +11 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.d.ts.map +1 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.js +48 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.js.map +1 -0
- package/dist/services/iam-entity-access.service.d.ts +22 -0
- package/dist/services/iam-entity-access.service.d.ts.map +1 -0
- package/dist/services/iam-entity-access.service.js +250 -0
- package/dist/services/iam-entity-access.service.js.map +1 -0
- package/dist/types/iam-entity-access.type.d.ts +19 -0
- package/dist/types/iam-entity-access.type.d.ts.map +1 -0
- package/dist/types/iam-entity-access.type.js +4 -0
- package/dist/types/iam-entity-access.type.js.map +1 -0
- package/package.json +16 -3
- package/dist/decorators/get-owner-id.decorator.d.ts +0 -2
- package/dist/decorators/get-owner-id.decorator.d.ts.map +0 -1
- package/dist/decorators/get-owner-id.decorator.js +0 -13
- package/dist/decorators/get-owner-id.decorator.js.map +0 -1
- package/dist/decorators/iam-public.decorator.d.ts +0 -2
- package/dist/decorators/iam-public.decorator.d.ts.map +0 -1
- package/dist/decorators/iam-public.decorator.js +0 -8
- package/dist/decorators/iam-public.decorator.js.map +0 -1
- package/dist/decorators/owns-entity.decorator.d.ts +0 -10
- package/dist/decorators/owns-entity.decorator.d.ts.map +0 -1
- package/dist/decorators/owns-entity.decorator.js +0 -8
- package/dist/decorators/owns-entity.decorator.js.map +0 -1
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts +0 -3
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts.map +0 -1
- package/dist/decorators/set-iam-route-user-type.decorator.js +0 -8
- package/dist/decorators/set-iam-route-user-type.decorator.js.map +0 -1
- package/dist/pipes/iam-paginate-query.pipe.d.ts +0 -8
- package/dist/pipes/iam-paginate-query.pipe.d.ts.map +0 -1
- package/dist/pipes/iam-paginate-query.pipe.js.map +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
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.IamPaginateQueryScopePipe = 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_entity_access_service_1 = require("../services/iam-entity-access.service");
|
|
20
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
21
|
+
let IamPaginateQueryScopePipe = class IamPaginateQueryScopePipe {
|
|
22
|
+
constructor(request, iamEntityAccessService) {
|
|
23
|
+
this.request = request;
|
|
24
|
+
this.iamEntityAccessService = iamEntityAccessService;
|
|
25
|
+
}
|
|
26
|
+
transform(value) {
|
|
27
|
+
const query = value;
|
|
28
|
+
const scopeOptions = this.request[iam_decorator_key_const_1.IAM_REQUEST_ENTITY_SCOPE_OPTIONS_KEY];
|
|
29
|
+
if (!scopeOptions) {
|
|
30
|
+
return query;
|
|
31
|
+
}
|
|
32
|
+
const iamContext = (0, nestjs_common_module_core_1.getIamContext)(this.request);
|
|
33
|
+
const currentUserType = this.request[iam_decorator_key_const_1.IAM_REQUEST_USER_TYPE_KEY];
|
|
34
|
+
query[iam_decorator_key_const_1.IAM_QUERY_SCOPE_WHERE_KEY] =
|
|
35
|
+
this.iamEntityAccessService.buildScopeWhere(scopeOptions, this.request, iamContext, currentUserType);
|
|
36
|
+
if (typeof scopeOptions.withDeleted === 'boolean') {
|
|
37
|
+
query.withDeleted = scopeOptions.withDeleted;
|
|
38
|
+
}
|
|
39
|
+
return query;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.IamPaginateQueryScopePipe = IamPaginateQueryScopePipe;
|
|
43
|
+
exports.IamPaginateQueryScopePipe = IamPaginateQueryScopePipe = __decorate([
|
|
44
|
+
(0, common_1.Injectable)({ scope: common_1.Scope.REQUEST }),
|
|
45
|
+
__param(0, (0, common_1.Inject)(core_1.REQUEST)),
|
|
46
|
+
__metadata("design:paramtypes", [Object, iam_entity_access_service_1.IamEntityAccessService])
|
|
47
|
+
], IamPaginateQueryScopePipe);
|
|
48
|
+
//# sourceMappingURL=iam-paginate-query-scope.pipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-paginate-query-scope.pipe.js","sourceRoot":"","sources":["../../src/pipes/iam-paginate-query-scope.pipe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0E;AAC1E,uCAAuC;AAEvC,kFAAmE;AAEnE,qFAA+E;AAG/E,kFAI8C;AAIvC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAIpC,YAEmB,OAAY,EACZ,sBAA8C;QAD9C,YAAO,GAAP,OAAO,CAAK;QACZ,2BAAsB,GAAtB,sBAAsB,CAAwB;IAC9D,CAAC;IAEJ,SAAS,CAAC,KAAoB;QAC5B,MAAM,KAAK,GAAG,KAAkC,CAAC;QAEjD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,8DAAoC,CAEzD,CAAC;QAEd,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAClC,mDAAyB,CACP,CAAC;QAErB,KAAK,CAAC,mDAAyB,CAAC;YAC9B,IAAI,CAAC,sBAAsB,CAAC,eAAe,CACzC,YAAY,EACZ,IAAI,CAAC,OAAO,EACZ,UAAU,EACV,eAAe,CAChB,CAAC;QAEJ,IAAI,OAAO,YAAY,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAClD,KAAK,CAAC,WAAW,GAAG,YAAY,CAAC,WAAW,CAAC;QAC/C,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAzCY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;IAMhC,WAAA,IAAA,eAAM,EAAC,cAAO,CAAC,CAAA;6CAEyB,kDAAsB;GAPtD,yBAAyB,CAyCrC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DataSource, FindOptionsWhere } from 'typeorm';
|
|
2
|
+
import { IamUserTypeEnum } from '../enums/iam-user-type.enum';
|
|
3
|
+
import { ApplyIamEntityScopeOptions, RequireIamEntityAccessOptions } from '../interfaces/iam-entity-access.interface';
|
|
4
|
+
export declare class IamEntityAccessService {
|
|
5
|
+
private readonly dataSource;
|
|
6
|
+
constructor(dataSource: DataSource);
|
|
7
|
+
resolveUserType(iamContext: any, allowedUserTypes: IamUserTypeEnum[]): IamUserTypeEnum;
|
|
8
|
+
hasEntityAccess<T>(options: RequireIamEntityAccessOptions<T>, req: any, iamContext: any, userType: IamUserTypeEnum): Promise<boolean>;
|
|
9
|
+
buildScopeWhere<T>(options: ApplyIamEntityScopeOptions<T>, req: any, iamContext?: any, userType?: IamUserTypeEnum): FindOptionsWhere<T> | FindOptionsWhere<T>[] | undefined;
|
|
10
|
+
private buildScopedWhere;
|
|
11
|
+
private buildWhereFromBranches;
|
|
12
|
+
private buildAllMatchWhere;
|
|
13
|
+
private buildNullFieldsWhere;
|
|
14
|
+
private buildBaseWhere;
|
|
15
|
+
private normalizeWhereResult;
|
|
16
|
+
private getValueFromSource;
|
|
17
|
+
private getValueByPath;
|
|
18
|
+
private castValue;
|
|
19
|
+
private normalizeEntityId;
|
|
20
|
+
private hasValue;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=iam-entity-access.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.service.d.ts","sourceRoot":"","sources":["../../src/services/iam-entity-access.service.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAU,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,0BAA0B,EAE1B,6BAA6B,EAC9B,MAAM,2CAA2C,CAAC;AAOnD,qBACa,sBAAsB;IAG/B,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,UAAU;IAGzC,eAAe,CACb,UAAU,EAAE,GAAG,EACf,gBAAgB,EAAE,eAAe,EAAE,GAClC,eAAe;IA0BZ,eAAe,CAAC,CAAC,EACrB,OAAO,EAAE,6BAA6B,CAAC,CAAC,CAAC,EACzC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,GAAG,EACf,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,CAAC;IAoDnB,eAAe,CAAC,CAAC,EACf,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,EACtC,GAAG,EAAE,GAAG,EACR,UAAU,GAAE,GAAwB,EACpC,QAAQ,CAAC,EAAE,eAAe,GACzB,gBAAgB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS;IAQ1D,OAAO,CAAC,gBAAgB;IAmExB,OAAO,CAAC,sBAAsB;IAyC9B,OAAO,CAAC,kBAAkB;IAqC1B,OAAO,CAAC,oBAAoB;IAa5B,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,oBAAoB;IAU5B,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,SAAS;IAiCjB,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,QAAQ;CAGjB"}
|
|
@@ -0,0 +1,250 @@
|
|
|
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.IamEntityAccessService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const nestjs_common_module_core_1 = require("@mondart/nestjs-common-module-core");
|
|
18
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
19
|
+
const typeorm_2 = require("typeorm");
|
|
20
|
+
const iam_user_type_enum_1 = require("../enums/iam-user-type.enum");
|
|
21
|
+
let IamEntityAccessService = class IamEntityAccessService {
|
|
22
|
+
constructor(dataSource) {
|
|
23
|
+
this.dataSource = dataSource;
|
|
24
|
+
}
|
|
25
|
+
resolveUserType(iamContext, allowedUserTypes) {
|
|
26
|
+
if (this.hasValue(iamContext?.agentId) || iamContext?.isAgent) {
|
|
27
|
+
return iam_user_type_enum_1.IamUserTypeEnum.AGENT;
|
|
28
|
+
}
|
|
29
|
+
if (this.hasValue(iamContext?.userId) || iamContext?.user) {
|
|
30
|
+
return iam_user_type_enum_1.IamUserTypeEnum.USER;
|
|
31
|
+
}
|
|
32
|
+
if (this.hasValue(iamContext?.guestId) ||
|
|
33
|
+
this.hasValue(iamContext?.guest?.id)) {
|
|
34
|
+
return iam_user_type_enum_1.IamUserTypeEnum.GUEST;
|
|
35
|
+
}
|
|
36
|
+
if (allowedUserTypes.includes(iam_user_type_enum_1.IamUserTypeEnum.GUEST)) {
|
|
37
|
+
return iam_user_type_enum_1.IamUserTypeEnum.GUEST;
|
|
38
|
+
}
|
|
39
|
+
throw new common_1.UnauthorizedException();
|
|
40
|
+
}
|
|
41
|
+
async hasEntityAccess(options, req, iamContext, userType) {
|
|
42
|
+
const rawEntityId = this.getValueFromSource(options.lookup.valueFrom, {
|
|
43
|
+
req,
|
|
44
|
+
iamContext,
|
|
45
|
+
userType,
|
|
46
|
+
});
|
|
47
|
+
const entityId = this.normalizeEntityId(rawEntityId);
|
|
48
|
+
if (!this.hasValue(entityId)) {
|
|
49
|
+
throw new common_1.BadRequestException('Missing entity identifier');
|
|
50
|
+
}
|
|
51
|
+
const repo = this.dataSource.getRepository(options.entity);
|
|
52
|
+
const baseWhere = {
|
|
53
|
+
[options.lookup.field]: entityId,
|
|
54
|
+
};
|
|
55
|
+
const exists = await repo.exists({
|
|
56
|
+
where: baseWhere,
|
|
57
|
+
});
|
|
58
|
+
if (!exists) {
|
|
59
|
+
throw new common_1.NotFoundException(nestjs_common_module_core_1.MessageFormatter.replace(nestjs_common_module_core_1.SharedMessages.RESOURCE_NOT_FOUND, options.resourceName ?? 'Resource'));
|
|
60
|
+
}
|
|
61
|
+
const scopedWhere = this.buildScopedWhere(options, req, iamContext, userType, {
|
|
62
|
+
lookupField: options.lookup.field,
|
|
63
|
+
entityId,
|
|
64
|
+
});
|
|
65
|
+
if (scopedWhere === undefined) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return repo.exists({
|
|
69
|
+
where: scopedWhere,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
buildScopeWhere(options, req, iamContext = (0, nestjs_common_module_core_1.getIamContext)(req), userType) {
|
|
73
|
+
const resolvedUserType = userType ??
|
|
74
|
+
this.resolveUserType(iamContext, Object.values(iam_user_type_enum_1.IamUserTypeEnum));
|
|
75
|
+
return this.buildScopedWhere(options, req, iamContext, resolvedUserType);
|
|
76
|
+
}
|
|
77
|
+
buildScopedWhere(options, req, iamContext, userType, lookup) {
|
|
78
|
+
if (userType === iam_user_type_enum_1.IamUserTypeEnum.AGENT) {
|
|
79
|
+
const agentAccess = options.access.agent;
|
|
80
|
+
if (!agentAccess || agentAccess.bypass !== false) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const where = this.buildWhereFromBranches({
|
|
84
|
+
branches: agentAccess.anyOf ?? [],
|
|
85
|
+
req,
|
|
86
|
+
iamContext,
|
|
87
|
+
userType,
|
|
88
|
+
lookup,
|
|
89
|
+
});
|
|
90
|
+
if (!where.length) {
|
|
91
|
+
throw new common_1.ForbiddenException();
|
|
92
|
+
}
|
|
93
|
+
return this.normalizeWhereResult(where);
|
|
94
|
+
}
|
|
95
|
+
if (userType === iam_user_type_enum_1.IamUserTypeEnum.USER) {
|
|
96
|
+
const where = this.buildWhereFromBranches({
|
|
97
|
+
branches: options.access.user?.anyOf ?? [],
|
|
98
|
+
req,
|
|
99
|
+
iamContext,
|
|
100
|
+
userType,
|
|
101
|
+
lookup,
|
|
102
|
+
});
|
|
103
|
+
if (!where.length) {
|
|
104
|
+
throw new common_1.ForbiddenException();
|
|
105
|
+
}
|
|
106
|
+
return this.normalizeWhereResult(where);
|
|
107
|
+
}
|
|
108
|
+
if (userType === iam_user_type_enum_1.IamUserTypeEnum.GUEST) {
|
|
109
|
+
const where = this.buildWhereFromBranches({
|
|
110
|
+
branches: options.access.guest?.anyOf ?? [],
|
|
111
|
+
req,
|
|
112
|
+
iamContext,
|
|
113
|
+
userType,
|
|
114
|
+
lookup,
|
|
115
|
+
});
|
|
116
|
+
if (!where.length) {
|
|
117
|
+
throw new common_1.ForbiddenException();
|
|
118
|
+
}
|
|
119
|
+
return this.normalizeWhereResult(where);
|
|
120
|
+
}
|
|
121
|
+
throw new common_1.ForbiddenException();
|
|
122
|
+
}
|
|
123
|
+
buildWhereFromBranches(params) {
|
|
124
|
+
const { branches, req, iamContext, userType, lookup } = params;
|
|
125
|
+
return branches.reduce((items, branch) => {
|
|
126
|
+
if ('nullFields' in branch) {
|
|
127
|
+
items.push(this.buildNullFieldsWhere(branch.nullFields, lookup));
|
|
128
|
+
return items;
|
|
129
|
+
}
|
|
130
|
+
if ('all' in branch) {
|
|
131
|
+
const where = this.buildAllMatchWhere({
|
|
132
|
+
matches: branch.all,
|
|
133
|
+
req,
|
|
134
|
+
iamContext,
|
|
135
|
+
userType,
|
|
136
|
+
lookup,
|
|
137
|
+
});
|
|
138
|
+
if (where) {
|
|
139
|
+
items.push(where);
|
|
140
|
+
}
|
|
141
|
+
return items;
|
|
142
|
+
}
|
|
143
|
+
return items;
|
|
144
|
+
}, []);
|
|
145
|
+
}
|
|
146
|
+
buildAllMatchWhere(params) {
|
|
147
|
+
const { matches, req, iamContext, userType, lookup } = params;
|
|
148
|
+
if (!matches.length) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const where = this.buildBaseWhere(lookup);
|
|
152
|
+
for (const match of matches) {
|
|
153
|
+
const rawValue = this.getValueFromSource(match.valueFrom, {
|
|
154
|
+
req,
|
|
155
|
+
iamContext,
|
|
156
|
+
userType,
|
|
157
|
+
});
|
|
158
|
+
const value = this.castValue(rawValue, match.cast);
|
|
159
|
+
if (!this.hasValue(value)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
where[match.field] = value;
|
|
163
|
+
}
|
|
164
|
+
return where;
|
|
165
|
+
}
|
|
166
|
+
buildNullFieldsWhere(fields, lookup) {
|
|
167
|
+
return fields.reduce((where, field) => {
|
|
168
|
+
where[field] = (0, typeorm_2.IsNull)();
|
|
169
|
+
return where;
|
|
170
|
+
}, this.buildBaseWhere(lookup));
|
|
171
|
+
}
|
|
172
|
+
buildBaseWhere(lookup) {
|
|
173
|
+
if (!lookup) {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
[lookup.lookupField]: lookup.entityId,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
normalizeWhereResult(where) {
|
|
181
|
+
if (where.length === 1) {
|
|
182
|
+
return where[0];
|
|
183
|
+
}
|
|
184
|
+
return where;
|
|
185
|
+
}
|
|
186
|
+
getValueFromSource(source, context) {
|
|
187
|
+
if (typeof source === 'function') {
|
|
188
|
+
return source(context);
|
|
189
|
+
}
|
|
190
|
+
if (source.startsWith('iam.')) {
|
|
191
|
+
return this.getValueByPath(context.iamContext, source.slice(4));
|
|
192
|
+
}
|
|
193
|
+
if (source.startsWith('req.')) {
|
|
194
|
+
return this.getValueByPath(context.req, source.slice(4));
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
getValueByPath(source, path) {
|
|
199
|
+
return path.split('.').reduce((current, key) => {
|
|
200
|
+
return current?.[key];
|
|
201
|
+
}, source);
|
|
202
|
+
}
|
|
203
|
+
castValue(value, cast) {
|
|
204
|
+
if (!this.hasValue(value)) {
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
if (cast === 'string') {
|
|
208
|
+
return String(value);
|
|
209
|
+
}
|
|
210
|
+
if (cast === 'number') {
|
|
211
|
+
const numberValue = Number(value);
|
|
212
|
+
return Number.isNaN(numberValue) ? undefined : numberValue;
|
|
213
|
+
}
|
|
214
|
+
if (cast === 'boolean') {
|
|
215
|
+
if (value === true || value === false) {
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
if (value === 'true') {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
if (value === 'false') {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
return Boolean(value);
|
|
225
|
+
}
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
normalizeEntityId(value) {
|
|
229
|
+
if (!this.hasValue(value)) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
if (typeof value === 'bigint') {
|
|
236
|
+
return value.toString();
|
|
237
|
+
}
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
hasValue(value) {
|
|
241
|
+
return value !== null && value !== undefined && value !== '';
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
exports.IamEntityAccessService = IamEntityAccessService;
|
|
245
|
+
exports.IamEntityAccessService = IamEntityAccessService = __decorate([
|
|
246
|
+
(0, common_1.Injectable)(),
|
|
247
|
+
__param(0, (0, typeorm_1.InjectDataSource)()),
|
|
248
|
+
__metadata("design:paramtypes", [typeorm_2.DataSource])
|
|
249
|
+
], IamEntityAccessService);
|
|
250
|
+
//# sourceMappingURL=iam-entity-access.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.service.js","sourceRoot":"","sources":["../../src/services/iam-entity-access.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAMwB;AACxB,kFAI4C;AAC5C,6CAAmD;AACnD,qCAA+D;AAC/D,oEAA8D;AAavD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,YAEmB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IACtC,CAAC;IAEJ,eAAe,CACb,UAAe,EACf,gBAAmC;QAEnC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,UAAU,EAAE,OAAO,EAAE,CAAC;YAC9D,OAAO,oCAAe,CAAC,KAAK,CAAC;QAC/B,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,UAAU,EAAE,IAAI,EAAE,CAAC;YAC1D,OAAO,oCAAe,CAAC,IAAI,CAAC;QAC9B,CAAC;QAED,IACE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;YAClC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,EACpC,CAAC;YACD,OAAO,oCAAe,CAAC,KAAK,CAAC;QAC/B,CAAC;QAKD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,oCAAe,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,OAAO,oCAAe,CAAC,KAAK,CAAC;QAC/B,CAAC;QAED,MAAM,IAAI,8BAAqB,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,eAAe,CACnB,OAAyC,EACzC,GAAQ,EACR,UAAe,EACf,QAAyB;QAEzB,MAAM,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE;YACpE,GAAG;YACH,UAAU;YACV,QAAQ;SACT,CAAC,CAAC;QAEH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
+
import { FindOptionsWhere } from 'typeorm';
|
|
3
|
+
import { PaginateQuery } from 'nestjs-paginate';
|
|
4
|
+
import { IAM_QUERY_SCOPE_WHERE_KEY } from '../constants/iam-decorator-key.const';
|
|
5
|
+
export type AccessValueCast = 'string' | 'number' | 'boolean';
|
|
6
|
+
export type AccessValueSource = `iam.${string}` | `req.${string}` | ((ctx: IamAccessValueContext) => unknown);
|
|
7
|
+
export type EntityAccessBranch<T = any> = {
|
|
8
|
+
all: EntityFieldMatch<T>[];
|
|
9
|
+
} | {
|
|
10
|
+
nullFields: (keyof T & string)[];
|
|
11
|
+
};
|
|
12
|
+
export type IamScopedWhere<T = any> = FindOptionsWhere<T> | FindOptionsWhere<T>[] | undefined;
|
|
13
|
+
export type IamScopedPaginateQuery<T = any> = PaginateQuery & {
|
|
14
|
+
[IAM_QUERY_SCOPE_WHERE_KEY]?: IamScopedWhere<T>;
|
|
15
|
+
};
|
|
16
|
+
export type IamScopedFindOneQuery<T = any> = Record<string, any> & {
|
|
17
|
+
[IAM_QUERY_SCOPE_WHERE_KEY]?: IamScopedWhere<T>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=iam-entity-access.type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.type.d.ts","sourceRoot":"","sources":["../../src/types/iam-entity-access.type.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAEjF,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GACzB,OAAO,MAAM,EAAE,GACf,OAAO,MAAM,EAAE,GACf,CAAC,CAAC,GAAG,EAAE,qBAAqB,KAAK,OAAO,CAAC,CAAC;AAE9C,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,GAAG,IAClC;IACE,GAAG,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;CAC5B,GACD;IACE,UAAU,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;CAClC,CAAC;AAEN,MAAM,MAAM,cAAc,CAAC,CAAC,GAAG,GAAG,IAC9B,gBAAgB,CAAC,CAAC,CAAC,GACnB,gBAAgB,CAAC,CAAC,CAAC,EAAE,GACrB,SAAS,CAAC;AAEd,MAAM,MAAM,sBAAsB,CAAC,CAAC,GAAG,GAAG,IAAI,aAAa,GAAG;IAC5D,CAAC,yBAAyB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACjE,CAAC,yBAAyB,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;CACjD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.type.js","sourceRoot":"","sources":["../../src/types/iam-entity-access.type.ts"],"names":[],"mappings":";;AAMA,kFAAiF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondart/nestjs-common-module-iam",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Reusable IAM (Identity and Access Management) utilities for NestJS.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Mondart"
|
|
@@ -14,7 +14,11 @@
|
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "tsc -p tsconfig.json"
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"test:watch": "jest --watch",
|
|
20
|
+
"test:cov": "jest --coverage",
|
|
21
|
+
"test:debug": "node --inspect-brk -r ts-node/register ./node_modules/.bin/jest --runInBand"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
24
|
"@mondart/nestjs-common-module-core": "^3.1.0"
|
|
@@ -33,5 +37,14 @@
|
|
|
33
37
|
},
|
|
34
38
|
"publishConfig": {
|
|
35
39
|
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@nestjs/testing": "^11.1.27",
|
|
43
|
+
"@types/jest": "^30.0.0",
|
|
44
|
+
"@types/supertest": "^7.2.0",
|
|
45
|
+
"jest": "^30.4.2",
|
|
46
|
+
"supertest": "^7.2.2",
|
|
47
|
+
"ts-jest": "^29.4.11",
|
|
48
|
+
"ts-node": "^10.9.2"
|
|
36
49
|
}
|
|
37
|
-
}
|
|
50
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iam-paginate-query.pipe.js","sourceRoot":"","sources":["../../src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