@lenne.tech/nest-server 8.4.0 → 8.5.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/core/common/decorators/restricted.decorator.d.ts +3 -2
- package/dist/core/common/decorators/restricted.decorator.js +29 -8
- package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
- package/dist/core/common/helpers/service.helper.d.ts +1 -0
- package/dist/core/common/helpers/service.helper.js +18 -2
- package/dist/core/common/helpers/service.helper.js.map +1 -1
- package/dist/core/common/interfaces/service-options.interface.d.ts +1 -1
- package/dist/core/common/services/module.service.js +14 -8
- package/dist/core/common/services/module.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/common/decorators/restricted.decorator.ts +50 -14
- package/src/core/common/helpers/service.helper.ts +17 -2
- package/src/core/common/interfaces/service-options.interface.ts +3 -3
- package/src/core/common/services/module.service.ts +17 -9
|
@@ -6,8 +6,8 @@ export declare type RestrictedType = (string | RequireAtLeastOne<{
|
|
|
6
6
|
roles?: string | string[];
|
|
7
7
|
processType?: ProcessType;
|
|
8
8
|
}, 'memberOf' | 'roles'>)[];
|
|
9
|
-
export declare const Restricted: (...rolesOrMember: RestrictedType) => PropertyDecorator;
|
|
10
|
-
export declare const getRestricted: (object: unknown, propertyKey
|
|
9
|
+
export declare const Restricted: (...rolesOrMember: RestrictedType) => ClassDecorator & PropertyDecorator;
|
|
10
|
+
export declare const getRestricted: (object: unknown, propertyKey?: string) => RestrictedType;
|
|
11
11
|
export declare const checkRestricted: (data: any, user: {
|
|
12
12
|
id: any;
|
|
13
13
|
hasRole: (roles: string[]) => boolean;
|
|
@@ -15,5 +15,6 @@ export declare const checkRestricted: (data: any, user: {
|
|
|
15
15
|
dbObject?: any;
|
|
16
16
|
ignoreUndefined?: boolean;
|
|
17
17
|
processType?: ProcessType;
|
|
18
|
+
removeUndefinedFromResultArray?: boolean;
|
|
18
19
|
throwError?: boolean;
|
|
19
20
|
}, processedObjects?: any[]) => any;
|
|
@@ -11,12 +11,15 @@ const Restricted = (...rolesOrMember) => {
|
|
|
11
11
|
};
|
|
12
12
|
exports.Restricted = Restricted;
|
|
13
13
|
const getRestricted = (object, propertyKey) => {
|
|
14
|
+
if (!propertyKey) {
|
|
15
|
+
return Reflect.getMetadata(restrictedMetaKey, object);
|
|
16
|
+
}
|
|
14
17
|
return Reflect.getMetadata(restrictedMetaKey, object, propertyKey);
|
|
15
18
|
};
|
|
16
19
|
exports.getRestricted = getRestricted;
|
|
17
20
|
const checkRestricted = (data, user, options = {}, processedObjects = []) => {
|
|
18
|
-
var _a
|
|
19
|
-
const config = Object.assign({ ignoreUndefined: true, throwError: true }, options);
|
|
21
|
+
var _a;
|
|
22
|
+
const config = Object.assign({ ignoreUndefined: true, removeUndefinedFromResultArray: true, throwError: true }, options);
|
|
20
23
|
if (!data || typeof data !== 'object') {
|
|
21
24
|
return data;
|
|
22
25
|
}
|
|
@@ -25,13 +28,14 @@ const checkRestricted = (data, user, options = {}, processedObjects = []) => {
|
|
|
25
28
|
}
|
|
26
29
|
processedObjects.push(data);
|
|
27
30
|
if (Array.isArray(data)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (data[propertyKey] === undefined && config.ignoreUndefined) {
|
|
32
|
-
continue;
|
|
31
|
+
let result = data.map((item) => (0, exports.checkRestricted)(item, user, config, processedObjects));
|
|
32
|
+
if (!config.throwError && config.removeUndefinedFromResultArray) {
|
|
33
|
+
result = result.filter((item) => item !== undefined);
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
const validateRestricted = (restricted) => {
|
|
38
|
+
var _a, _b;
|
|
35
39
|
let valid = true;
|
|
36
40
|
if (restricted === null || restricted === void 0 ? void 0 : restricted.length) {
|
|
37
41
|
valid = false;
|
|
@@ -53,6 +57,7 @@ const checkRestricted = (data, user, options = {}, processedObjects = []) => {
|
|
|
53
57
|
});
|
|
54
58
|
if (roles.length) {
|
|
55
59
|
if ((user === null || user === void 0 ? void 0 : user.hasRole(roles)) ||
|
|
60
|
+
((user === null || user === void 0 ? void 0 : user.id) && roles.includes(role_enum_1.RoleEnum.S_USER)) ||
|
|
56
61
|
(roles.includes(role_enum_1.RoleEnum.S_CREATOR) && (0, db_helper_1.getIncludedIds)((_a = config.dbObject) === null || _a === void 0 ? void 0 : _a.createdBy, user))) {
|
|
57
62
|
valid = true;
|
|
58
63
|
}
|
|
@@ -91,6 +96,22 @@ const checkRestricted = (data, user, options = {}, processedObjects = []) => {
|
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
}
|
|
99
|
+
return valid;
|
|
100
|
+
};
|
|
101
|
+
const objectRestrictions = (0, exports.getRestricted)(data.constructor);
|
|
102
|
+
const objectIsValid = validateRestricted(objectRestrictions);
|
|
103
|
+
if (!objectIsValid) {
|
|
104
|
+
if (config.throwError) {
|
|
105
|
+
throw new common_1.UnauthorizedException('The current user has no access rights for ' + ((_a = data.constructor) === null || _a === void 0 ? void 0 : _a.name));
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
for (const propertyKey of Object.keys(data)) {
|
|
110
|
+
if (data[propertyKey] === undefined && config.ignoreUndefined) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const restricted = (0, exports.getRestricted)(data, propertyKey);
|
|
114
|
+
const valid = validateRestricted(restricted);
|
|
94
115
|
if (valid) {
|
|
95
116
|
data[propertyKey] = (0, exports.checkRestricted)(data[propertyKey], user, config, processedObjects);
|
|
96
117
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restricted.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/restricted.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,2CAAuD;AAEvD,kDAA8C;AAC9C,oDAAsD;AAMtD,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"restricted.decorator.js","sourceRoot":"","sources":["../../../../src/core/common/decorators/restricted.decorator.ts"],"names":[],"mappings":";;;AAAA,4BAA0B;AAC1B,2CAAuD;AAEvD,kDAA8C;AAC9C,oDAAsD;AAMtD,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AA2BxC,MAAM,UAAU,GAAG,CAAC,GAAG,aAA6B,EAAsC,EAAE;IACjG,OAAO,OAAO,CAAC,QAAQ,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,UAAU,cAErB;AAKK,MAAM,aAAa,GAAG,CAAC,MAAe,EAAE,WAAoB,EAAkB,EAAE;IACrF,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;KACvD;IACD,OAAO,OAAO,CAAC,WAAW,CAAC,iBAAiB,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACrE,CAAC,CAAC;AALW,QAAA,aAAa,iBAKxB;AAMK,MAAM,eAAe,GAAG,CAC7B,IAAS,EACT,IAAwD,EACxD,UAMI,EAAE,EACN,mBAA0B,EAAE,EAC5B,EAAE;;IACF,MAAM,MAAM,mBACV,eAAe,EAAE,IAAI,EACrB,8BAA8B,EAAE,IAAI,EACpC,UAAU,EAAE,IAAI,IACb,OAAO,CACX,CAAC;IAGF,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;QACrC,OAAO,IAAI,CAAC;KACb;IAGD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;QACnC,OAAO,IAAI,CAAC;KACb;IACD,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAG5B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QAEvB,IAAI,MAAM,GAAG,IAAI,CAAC,GA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gB,CAAC,CAAC;SACxF;aAAM;YAEL,IAAI,MAAM,CAAC,UAAU,EAAE;gBACrB,MAAM,IAAI,8BAAqB,CAAC,4CAA4C,GAAG,WAAW,CAAC,CAAC;aAC7F;YAGD,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;SAC1B;KACF;IAGD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAlKW,QAAA,eAAe,mBAkK1B"}
|
|
@@ -29,6 +29,7 @@ export declare function prepareInput<T = any>(input: T, currentUser: {
|
|
|
29
29
|
clone?: boolean;
|
|
30
30
|
getNewArray?: boolean;
|
|
31
31
|
removeUndefined?: boolean;
|
|
32
|
+
targetModel?: new (...args: any[]) => T;
|
|
32
33
|
}): Promise<T>;
|
|
33
34
|
export declare function prepareOutput<T = {
|
|
34
35
|
[key: string]: any;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prepareOutput = exports.prepareInput = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const bcrypt = require("bcrypt");
|
|
6
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
7
|
const _ = require("lodash");
|
|
7
8
|
const role_enum_1 = require("../enums/role.enum");
|
|
8
9
|
class ServiceHelper {
|
|
@@ -15,6 +16,7 @@ class ServiceHelper {
|
|
|
15
16
|
}
|
|
16
17
|
exports.default = ServiceHelper;
|
|
17
18
|
async function prepareInput(input, currentUser, options = {}) {
|
|
19
|
+
var _a;
|
|
18
20
|
const config = Object.assign({ checkRoles: false, clone: false, create: false, getNewArray: false, removeUndefined: false }, options);
|
|
19
21
|
if (typeof input !== 'object') {
|
|
20
22
|
return input;
|
|
@@ -31,6 +33,14 @@ async function prepareInput(input, currentUser, options = {}) {
|
|
|
31
33
|
input = _.cloneDeep(input);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
36
|
+
if (config.targetModel && !(input instanceof config.targetModel)) {
|
|
37
|
+
if ((_a = config.targetModel) === null || _a === void 0 ? void 0 : _a.map) {
|
|
38
|
+
input = await config.targetModel.map(input);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
input = (0, class_transformer_1.plainToInstance)(config.targetModel, input);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
34
44
|
if (config.removeUndefined) {
|
|
35
45
|
Object.keys(input).forEach((key) => input[key] === undefined && delete input[key]);
|
|
36
46
|
}
|
|
@@ -62,6 +72,7 @@ async function prepareInput(input, currentUser, options = {}) {
|
|
|
62
72
|
}
|
|
63
73
|
exports.prepareInput = prepareInput;
|
|
64
74
|
async function prepareOutput(output, options = {}) {
|
|
75
|
+
var _a;
|
|
65
76
|
const config = Object.assign({ clone: false, getNewArray: false, removeUndefined: false, targetModel: undefined }, options);
|
|
66
77
|
if (typeof output !== 'object') {
|
|
67
78
|
return output;
|
|
@@ -78,8 +89,13 @@ async function prepareOutput(output, options = {}) {
|
|
|
78
89
|
output = _.cloneDeep(output);
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
|
-
if (config.targetModel) {
|
|
82
|
-
|
|
92
|
+
if (config.targetModel && !(output instanceof config.targetModel)) {
|
|
93
|
+
if ((_a = config.targetModel) === null || _a === void 0 ? void 0 : _a.map) {
|
|
94
|
+
output = await config.targetModel.map(output);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
output = (0, class_transformer_1.plainToInstance)(config.targetModel, output);
|
|
98
|
+
}
|
|
83
99
|
}
|
|
84
100
|
if (output.password) {
|
|
85
101
|
output.password = undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/service.helper.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,iCAAiC;AACjC,4BAA4B;AAC5B,kDAA8C;AAM9C,MAAqB,aAAa;IAIhC,MAAM,CAAC,KAAK,CAAC,YAAY,CACvB,KAAQ,EACR,WAA+C,EAC/C,UAMI,EAAE;QAEN,OAAO,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAKD,MAAM,CAAC,KAAK,CAAC,aAAa,CACxB,MAAW,EACX,UAMI,EAAE;QAEN,OAAO,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AAjCD,gCAiCC;AAKM,KAAK,UAAU,YAAY,CAChC,KAAQ,EACR,WAA+C,EAC/C,
|
|
1
|
+
{"version":3,"file":"service.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/service.helper.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,iCAAiC;AACjC,yDAAoD;AACpD,4BAA4B;AAC5B,kDAA8C;AAM9C,MAAqB,aAAa;IAIhC,MAAM,CAAC,KAAK,CAAC,YAAY,CACvB,KAAQ,EACR,WAA+C,EAC/C,UAMI,EAAE;QAEN,OAAO,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAKD,MAAM,CAAC,KAAK,CAAC,aAAa,CACxB,MAAW,EACX,UAMI,EAAE;QAEN,OAAO,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;CACF;AAjCD,gCAiCC;AAKM,KAAK,UAAU,YAAY,CAChC,KAAQ,EACR,WAA+C,EAC/C,UAOI,EAAE;;IAGN,MAAM,MAAM,mBACV,UAAU,EAAE,KAAK,EACjB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,KAAK,EAClB,eAAe,EAAE,KAAK,IACnB,OAAO,CACX,CAAC;IAGF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IAGD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,cAAc,GAAG,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,YAAY,CAAC,IA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EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;KACvF;IAGD,OAAO,MAAM,CAAC;AAChB,CAAC;AAtED,sCAsEC"}
|
|
@@ -10,6 +10,7 @@ export interface ServiceOptions {
|
|
|
10
10
|
};
|
|
11
11
|
fieldSelection?: FieldSelection;
|
|
12
12
|
inputType?: new (...params: any[]) => any;
|
|
13
|
+
outputType?: new (...params: any[]) => any;
|
|
13
14
|
processFieldSelection?: {
|
|
14
15
|
model?: new (...args: any[]) => any;
|
|
15
16
|
dbModel?: Model<any>;
|
|
@@ -29,6 +30,5 @@ export interface ServiceOptions {
|
|
|
29
30
|
targetModel?: new (...args: any[]) => any;
|
|
30
31
|
};
|
|
31
32
|
pubSub?: boolean;
|
|
32
|
-
resultType?: new (...params: any[]) => any;
|
|
33
33
|
roles?: string | string[];
|
|
34
34
|
}
|
|
@@ -18,7 +18,11 @@ class ModuleService {
|
|
|
18
18
|
async process(serviceFunc, options) {
|
|
19
19
|
const config = Object.assign({ checkRights: true, dbObject: options === null || options === void 0 ? void 0 : options.dbObject, input: options === null || options === void 0 ? void 0 : options.input, processFieldSelection: {}, prepareInput: {}, prepareOutput: {}, pubSub: true }, options === null || options === void 0 ? void 0 : options.serviceOptions);
|
|
20
20
|
if (config.prepareInput && this.prepareInput) {
|
|
21
|
-
|
|
21
|
+
const opts = config.prepareInput;
|
|
22
|
+
if (!opts.targetModel && config.inputType) {
|
|
23
|
+
opts.targetModel = config.inputType;
|
|
24
|
+
}
|
|
25
|
+
await this.prepareInput(config.input, opts);
|
|
22
26
|
}
|
|
23
27
|
if (config.dbObject && config.checkRights && this.checkRights) {
|
|
24
28
|
if (typeof config.dbObject === 'string' || config.dbObject instanceof mongoose_1.Types.ObjectId) {
|
|
@@ -31,7 +35,7 @@ class ModuleService {
|
|
|
31
35
|
if (config.input && config.checkRights && this.checkRights) {
|
|
32
36
|
const opts = { dbObject: config.dbObject, processType: process_type_enum_1.ProcessType.INPUT, roles: config.roles };
|
|
33
37
|
if (config.inputType) {
|
|
34
|
-
opts.metatype = config.
|
|
38
|
+
opts.metatype = config.inputType;
|
|
35
39
|
}
|
|
36
40
|
config.input = await this.checkRights(config.input, config.currentUser, opts);
|
|
37
41
|
}
|
|
@@ -40,10 +44,11 @@ class ModuleService {
|
|
|
40
44
|
await this.processFieldSelection(result, config.fieldSelection, config.processFieldSelection);
|
|
41
45
|
}
|
|
42
46
|
if (config.prepareOutput && this.prepareOutput) {
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const opts = config.prepareOutput;
|
|
48
|
+
if (!opts.targetModel && config.outputType) {
|
|
49
|
+
opts.targetModel = config.outputType;
|
|
45
50
|
}
|
|
46
|
-
result = await this.prepareOutput(result,
|
|
51
|
+
result = await this.prepareOutput(result, opts);
|
|
47
52
|
}
|
|
48
53
|
if (config.checkRights && this.checkRights) {
|
|
49
54
|
const opts = {
|
|
@@ -52,15 +57,16 @@ class ModuleService {
|
|
|
52
57
|
roles: config.roles,
|
|
53
58
|
throwError: false,
|
|
54
59
|
};
|
|
55
|
-
if (config.
|
|
56
|
-
opts.metatype = config.
|
|
60
|
+
if (config.outputType) {
|
|
61
|
+
opts.metatype = config.outputType;
|
|
57
62
|
}
|
|
58
63
|
result = await this.checkRights(result, config.currentUser, opts);
|
|
59
64
|
}
|
|
60
65
|
return result;
|
|
61
66
|
}
|
|
62
67
|
async prepareInput(input, options = {}) {
|
|
63
|
-
|
|
68
|
+
const config = Object.assign({ targetModel: this.mainModelConstructor }, options === null || options === void 0 ? void 0 : options.prepareInput);
|
|
69
|
+
return (0, service_helper_1.prepareInput)(input, options.currentUser, config);
|
|
64
70
|
}
|
|
65
71
|
async prepareOutput(output, options = {}) {
|
|
66
72
|
const config = Object.assign({ targetModel: this.mainModelConstructor }, options === null || options === void 0 ? void 0 : options.prepareOutput);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.service.js","sourceRoot":"","sources":["../../../../src/core/common/services/module.service.ts"],"names":[],"mappings":";;;AAAA,uCAAkD;AAClD,kEAAyD;AACzD,oDAA+D;AAC/D,0DAAgD;AAChD,8DAAwE;AAQxE,MAAsB,aAAa;IAcjC,YAAsB,OAGrB;QACC,IAAI,CAAC,WAAW,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC;QACxC,IAAI,CAAC,oBAAoB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,CAAC;IAC5D,CAAC;IAKD,WAAW,CACT,KAAU,EACV,WAA+D,EAC/D,OAMC;QAED,MAAM,MAAM,mBACV,QAAQ,EAAE,IAAI,CAAC,oBAAoB,IAChC,OAAO,CACX,CAAC;QACF,OAAO,IAAA,oBAAK,EAAC,KAAK,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAUD,KAAK,CAAC,OAAO,CACX,WAAoG,EACpG,OAKC;QAGD,MAAM,MAAM,mBACV,WAAW,EAAE,IAAI,EACjB,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAC3B,KAAK,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EACrB,qBAAqB,EAAE,EAAE,EACzB,YAAY,EAAE,EAAE,EAChB,aAAa,EAAE,EAAE,EACjB,MAAM,EAAE,IAAI,IACT,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,CAC3B,CAAC;QAGF,IAAI,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,EAAE;YAC5C,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"module.service.js","sourceRoot":"","sources":["../../../../src/core/common/services/module.service.ts"],"names":[],"mappings":";;;AAAA,uCAAkD;AAClD,kEAAyD;AACzD,oDAA+D;AAC/D,0DAAgD;AAChD,8DAAwE;AAQxE,MAAsB,aAAa;IAcjC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