easywork-common-lib 1.0.1032 → 1.0.1034
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/entities/all-activities.entity.d.ts +2 -1
- package/dist/entities/all-activities.entity.js +4 -4
- package/dist/entities/all-activities.entity.js.map +1 -1
- package/dist/entities/role-audit-log.entity.d.ts +2 -2
- package/dist/entities/role-audit-log.entity.js +2 -2
- package/dist/modules/authorization/authorization.module.d.ts +2 -2
- package/dist/modules/authorization/usage-example.d.ts +35 -0
- package/dist/modules/authorization/usage-example.js +180 -0
- package/dist/modules/authorization/usage-example.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { BaseEntity } from "typeorm";
|
|
1
2
|
import { TaskCRM } from "./helpers/tools/task_crm.entity";
|
|
2
3
|
import { EventCRM } from "./helpers/tools/event_crm.entity";
|
|
3
4
|
import { MeetingCRM } from "./helpers/meeting_crm.entity";
|
|
4
5
|
import { CommentBase } from "../common/database/comment.base.entity";
|
|
5
6
|
import { AllActivitiesType, ActivityStatus } from "../common/enums/common.enum";
|
|
6
|
-
export declare class AllActivities {
|
|
7
|
+
export declare class AllActivities extends BaseEntity {
|
|
7
8
|
id: string;
|
|
8
9
|
type: AllActivitiesType;
|
|
9
10
|
title: string;
|
|
@@ -18,7 +18,7 @@ const event_crm_entity_1 = require("./helpers/tools/event_crm.entity");
|
|
|
18
18
|
const meeting_crm_entity_1 = require("./helpers/meeting_crm.entity");
|
|
19
19
|
const comment_base_entity_1 = require("../common/database/comment.base.entity");
|
|
20
20
|
const common_enum_1 = require("../common/enums/common.enum");
|
|
21
|
-
let AllActivities = class AllActivities {
|
|
21
|
+
let AllActivities = class AllActivities extends typeorm_1.BaseEntity {
|
|
22
22
|
id;
|
|
23
23
|
type;
|
|
24
24
|
title;
|
|
@@ -254,8 +254,8 @@ __decorate([
|
|
|
254
254
|
], AllActivities.prototype, "activitySummary", null);
|
|
255
255
|
exports.AllActivities = AllActivities = __decorate([
|
|
256
256
|
(0, typeorm_1.Entity)(),
|
|
257
|
-
(0, typeorm_1.Index)([
|
|
258
|
-
(0, typeorm_1.Index)([
|
|
259
|
-
(0, typeorm_1.Index)([
|
|
257
|
+
(0, typeorm_1.Index)(["type"]),
|
|
258
|
+
(0, typeorm_1.Index)(["activityDate"]),
|
|
259
|
+
(0, typeorm_1.Index)(["status"])
|
|
260
260
|
], AllActivities);
|
|
261
261
|
//# sourceMappingURL=all-activities.entity.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"all-activities.entity.js","sourceRoot":"","sources":["../../src/entities/all-activities.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"all-activities.entity.js","sourceRoot":"","sources":["../../src/entities/all-activities.entity.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAUiB;AACjB,yDAAoD;AACpD,6CAA8C;AAE9C,qEAA0D;AAC1D,uEAA4D;AAC5D,qEAA0D;AAC1D,gFAAqE;AACrE,6DAAgF;AAMzE,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,oBAAU;IAO3C,EAAE,CAAS;IASX,IAAI,CAAoB;IAOxB,KAAK,CAAS;IAQd,WAAW,CAAU;IAQrB,YAAY,CAAQ;IAYpB,MAAM,CAAkB;IAQxB,QAAQ,CAAU;IAMlB,SAAS,CAAU;IAKnB,OAAO,CAAW;IAKlB,UAAU,CAAU;IAKpB,QAAQ,CAAY;IAKpB,YAAY,CAAU;IAKtB,UAAU,CAAc;IAKxB,SAAS,CAAU;IAKnB,OAAO,CAAe;IAYtB,QAAQ,CAAuB;IAQ/B,SAAS,CAAO;IAOhB,SAAS,CAAO;IAGhB,IACI,cAAc;QAMhB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,+BAAiB,CAAC,QAAQ;gBAC7B,OAAO,IAAI,CAAC,OAAO,CAAC;YACtB,KAAK,+BAAiB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M,GAAE;;;iDAWR;AAGD;IAAC,IAAA,0BAAM,GAAE;;;oDAqBR;wBA5MU,aAAa;IAJzB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,CAAC,MAAM,CAAC,CAAC;IACf,IAAA,eAAK,EAAC,CAAC,cAAc,CAAC,CAAC;IACvB,IAAA,eAAK,EAAC,CAAC,QAAQ,CAAC,CAAC;GACL,aAAa,CA6MzB"}
|
|
@@ -15,9 +15,9 @@ export declare enum AuditStatus {
|
|
|
15
15
|
export declare class RoleAuditLog {
|
|
16
16
|
id: number;
|
|
17
17
|
performedBy: User;
|
|
18
|
-
performedById:
|
|
18
|
+
performedById: string;
|
|
19
19
|
targetUser: User;
|
|
20
|
-
targetUserId:
|
|
20
|
+
targetUserId: string;
|
|
21
21
|
description: string;
|
|
22
22
|
oldValue: any;
|
|
23
23
|
newValue: any;
|
|
@@ -63,7 +63,7 @@ __decorate([
|
|
|
63
63
|
example: 123,
|
|
64
64
|
}),
|
|
65
65
|
(0, typeorm_1.Column)({ name: 'performed_by_id' }),
|
|
66
|
-
__metadata("design:type",
|
|
66
|
+
__metadata("design:type", String)
|
|
67
67
|
], RoleAuditLog.prototype, "performedById", void 0);
|
|
68
68
|
__decorate([
|
|
69
69
|
(0, swagger_1.ApiProperty)({
|
|
@@ -80,7 +80,7 @@ __decorate([
|
|
|
80
80
|
example: 456,
|
|
81
81
|
}),
|
|
82
82
|
(0, typeorm_1.Column)({ name: 'target_user_id' }),
|
|
83
|
-
__metadata("design:type",
|
|
83
|
+
__metadata("design:type", String)
|
|
84
84
|
], RoleAuditLog.prototype, "targetUserId", void 0);
|
|
85
85
|
__decorate([
|
|
86
86
|
(0, swagger_1.ApiProperty)({
|
|
@@ -19,8 +19,8 @@ export declare class AuthorizationModule {
|
|
|
19
19
|
}): {
|
|
20
20
|
module: typeof AuthorizationModule;
|
|
21
21
|
imports: import("@nestjs/common").DynamicModule[];
|
|
22
|
-
providers: (typeof
|
|
23
|
-
exports: (typeof
|
|
22
|
+
providers: (typeof TaskAuthorizationService | typeof PolicyAuthorizationService | typeof LeadAuthorizationService | typeof ContactAuthorizationService | typeof ResourceAuthorizationFactory | typeof PermissionEvaluatorService | typeof ResourceAuthorizationService | typeof ResourceAccessFilterService | typeof DynamicFilterService | typeof PermissionCacheService | typeof AuthorizationService)[];
|
|
23
|
+
exports: (typeof TaskAuthorizationService | typeof PolicyAuthorizationService | typeof LeadAuthorizationService | typeof ContactAuthorizationService | typeof ResourceAuthorizationFactory | typeof PermissionEvaluatorService | typeof ResourceAuthorizationService | typeof ResourceAccessFilterService | typeof DynamicFilterService | typeof PermissionCacheService | typeof AuthorizationService)[];
|
|
24
24
|
global: boolean;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare class AppModule {
|
|
2
|
+
}
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { ContactAuthorizationService, ResourceAuthorizationFactory, PermissionAction } from 'easywork-common-lib/modules';
|
|
5
|
+
import { Contact, SubGroup, User } from 'easywork-common-lib/entities';
|
|
6
|
+
export declare class ContactService {
|
|
7
|
+
private contactRepository;
|
|
8
|
+
private subGroupRepository;
|
|
9
|
+
private readonly contactAuthService;
|
|
10
|
+
private readonly authFactory;
|
|
11
|
+
constructor(contactRepository: Repository<Contact>, subGroupRepository: Repository<SubGroup>, contactAuthService: ContactAuthorizationService, authFactory: ResourceAuthorizationFactory);
|
|
12
|
+
getAllContacts(user: User): Promise<Contact[]>;
|
|
13
|
+
getContactById(id: string, user: User): Promise<Contact>;
|
|
14
|
+
}
|
|
15
|
+
export declare class PoliciesService {
|
|
16
|
+
private subGroupRepository;
|
|
17
|
+
private readonly authFactory;
|
|
18
|
+
constructor(subGroupRepository: Repository<SubGroup>, authFactory: ResourceAuthorizationFactory);
|
|
19
|
+
getAllPolicies(user: User): Promise<any>;
|
|
20
|
+
}
|
|
21
|
+
import { AuthorizationService } from 'easywork-common-lib/modules';
|
|
22
|
+
export declare class GenericResourceService {
|
|
23
|
+
private readonly authService;
|
|
24
|
+
constructor(authService: AuthorizationService);
|
|
25
|
+
checkUserAccess(user: User, action: PermissionAction, resource: string): Promise<any>;
|
|
26
|
+
validateMultiplePermissions(user: User): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export declare class ContactController {
|
|
29
|
+
private readonly contactService;
|
|
30
|
+
constructor(contactService: ContactService);
|
|
31
|
+
getAllContacts(user: User): Promise<Contact[]>;
|
|
32
|
+
getContactById(id: string, user: User): Promise<Contact>;
|
|
33
|
+
}
|
|
34
|
+
export declare class ContactModule {
|
|
35
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
var _a, _b, _c, _d, _e, _f;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ContactModule = exports.ContactController = exports.GenericResourceService = exports.PoliciesService = exports.ContactService = exports.AppModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const modules_1 = require("easywork-common-lib/modules");
|
|
19
|
+
let AppModule = class AppModule {
|
|
20
|
+
};
|
|
21
|
+
exports.AppModule = AppModule;
|
|
22
|
+
exports.AppModule = AppModule = __decorate([
|
|
23
|
+
(0, common_1.Module)({
|
|
24
|
+
imports: [
|
|
25
|
+
modules_1.AuthorizationModule,
|
|
26
|
+
modules_1.AuthorizationModule.forRoot({
|
|
27
|
+
cache: {
|
|
28
|
+
ttl: 600,
|
|
29
|
+
max: 2000,
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
})
|
|
34
|
+
], AppModule);
|
|
35
|
+
const common_2 = require("@nestjs/common");
|
|
36
|
+
const typeorm_1 = require("typeorm");
|
|
37
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
38
|
+
const modules_2 = require("easywork-common-lib/modules");
|
|
39
|
+
const entities_1 = require("easywork-common-lib/entities");
|
|
40
|
+
let ContactService = class ContactService {
|
|
41
|
+
contactRepository;
|
|
42
|
+
subGroupRepository;
|
|
43
|
+
contactAuthService;
|
|
44
|
+
authFactory;
|
|
45
|
+
constructor(contactRepository, subGroupRepository, contactAuthService, authFactory) {
|
|
46
|
+
this.contactRepository = contactRepository;
|
|
47
|
+
this.subGroupRepository = subGroupRepository;
|
|
48
|
+
this.contactAuthService = contactAuthService;
|
|
49
|
+
this.authFactory = authFactory;
|
|
50
|
+
}
|
|
51
|
+
async getAllContacts(user) {
|
|
52
|
+
const queryBuilder = this.contactRepository
|
|
53
|
+
.createQueryBuilder('contact');
|
|
54
|
+
await this.contactAuthService.applyContactPermissionFilters(queryBuilder, user, {
|
|
55
|
+
action: modules_2.PermissionAction.READ,
|
|
56
|
+
subGroupRepository: this.subGroupRepository,
|
|
57
|
+
});
|
|
58
|
+
return queryBuilder.getMany();
|
|
59
|
+
}
|
|
60
|
+
async getContactById(id, user) {
|
|
61
|
+
const contact = await this.contactRepository.findOne({ where: { id } });
|
|
62
|
+
if (!contact) {
|
|
63
|
+
throw new Error('Contact not found');
|
|
64
|
+
}
|
|
65
|
+
await this.contactAuthService.validateContactAccess(user, modules_2.PermissionAction.READ, contact, this.subGroupRepository);
|
|
66
|
+
return contact;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.ContactService = ContactService;
|
|
70
|
+
exports.ContactService = ContactService = __decorate([
|
|
71
|
+
(0, common_2.Injectable)(),
|
|
72
|
+
__param(0, (0, typeorm_2.InjectRepository)(entities_1.Contact)),
|
|
73
|
+
__param(1, (0, typeorm_2.InjectRepository)(entities_1.SubGroup)),
|
|
74
|
+
__metadata("design:paramtypes", [typeorm_1.Repository,
|
|
75
|
+
typeorm_1.Repository, typeof (_a = typeof modules_2.ContactAuthorizationService !== "undefined" && modules_2.ContactAuthorizationService) === "function" ? _a : Object, typeof (_b = typeof modules_2.ResourceAuthorizationFactory !== "undefined" && modules_2.ResourceAuthorizationFactory) === "function" ? _b : Object])
|
|
76
|
+
], ContactService);
|
|
77
|
+
let PoliciesService = class PoliciesService {
|
|
78
|
+
subGroupRepository;
|
|
79
|
+
authFactory;
|
|
80
|
+
constructor(subGroupRepository, authFactory) {
|
|
81
|
+
this.subGroupRepository = subGroupRepository;
|
|
82
|
+
this.authFactory = authFactory;
|
|
83
|
+
}
|
|
84
|
+
async getAllPolicies(user) {
|
|
85
|
+
const queryBuilder = this.policyRepository
|
|
86
|
+
.createQueryBuilder('policy');
|
|
87
|
+
const policyAuth = this.authFactory.forPolicy(this.subGroupRepository);
|
|
88
|
+
await policyAuth.applyPermissionFilters(queryBuilder, user, {
|
|
89
|
+
action: modules_2.PermissionAction.READ,
|
|
90
|
+
});
|
|
91
|
+
return queryBuilder.getMany();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.PoliciesService = PoliciesService;
|
|
95
|
+
exports.PoliciesService = PoliciesService = __decorate([
|
|
96
|
+
(0, common_2.Injectable)(),
|
|
97
|
+
__param(0, (0, typeorm_2.InjectRepository)(entities_1.SubGroup)),
|
|
98
|
+
__metadata("design:paramtypes", [typeorm_1.Repository, typeof (_c = typeof modules_2.ResourceAuthorizationFactory !== "undefined" && modules_2.ResourceAuthorizationFactory) === "function" ? _c : Object])
|
|
99
|
+
], PoliciesService);
|
|
100
|
+
const modules_3 = require("easywork-common-lib/modules");
|
|
101
|
+
let GenericResourceService = class GenericResourceService {
|
|
102
|
+
authService;
|
|
103
|
+
constructor(authService) {
|
|
104
|
+
this.authService = authService;
|
|
105
|
+
}
|
|
106
|
+
async checkUserAccess(user, action, resource) {
|
|
107
|
+
const result = await this.authService.canAccess({
|
|
108
|
+
user,
|
|
109
|
+
action,
|
|
110
|
+
resource,
|
|
111
|
+
});
|
|
112
|
+
return result.allowed;
|
|
113
|
+
}
|
|
114
|
+
async validateMultiplePermissions(user) {
|
|
115
|
+
const results = await this.authService.canAccessMultiple([
|
|
116
|
+
{ user, action: modules_2.PermissionAction.READ, resource: 'contact' },
|
|
117
|
+
{ user, action: modules_2.PermissionAction.CREATE, resource: 'lead' },
|
|
118
|
+
{ user, action: modules_2.PermissionAction.UPDATE, resource: 'policy' },
|
|
119
|
+
]);
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
exports.GenericResourceService = GenericResourceService;
|
|
124
|
+
exports.GenericResourceService = GenericResourceService = __decorate([
|
|
125
|
+
(0, common_2.Injectable)(),
|
|
126
|
+
__metadata("design:paramtypes", [typeof (_d = typeof modules_3.AuthorizationService !== "undefined" && modules_3.AuthorizationService) === "function" ? _d : Object])
|
|
127
|
+
], GenericResourceService);
|
|
128
|
+
const common_3 = require("@nestjs/common");
|
|
129
|
+
const modules_4 = require("easywork-common-lib/modules");
|
|
130
|
+
const your_auth_decorator_1 = require("your-auth-decorator");
|
|
131
|
+
let ContactController = class ContactController {
|
|
132
|
+
contactService;
|
|
133
|
+
constructor(contactService) {
|
|
134
|
+
this.contactService = contactService;
|
|
135
|
+
}
|
|
136
|
+
async getAllContacts(user) {
|
|
137
|
+
return this.contactService.getAllContacts(user);
|
|
138
|
+
}
|
|
139
|
+
async getContactById(id, user) {
|
|
140
|
+
return this.contactService.getContactById(id, user);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.ContactController = ContactController;
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, common_3.Get)(),
|
|
146
|
+
__param(0, (0, your_auth_decorator_1.CurrentUser)()),
|
|
147
|
+
__metadata("design:type", Function),
|
|
148
|
+
__metadata("design:paramtypes", [typeof (_e = typeof entities_1.User !== "undefined" && entities_1.User) === "function" ? _e : Object]),
|
|
149
|
+
__metadata("design:returntype", Promise)
|
|
150
|
+
], ContactController.prototype, "getAllContacts", null);
|
|
151
|
+
__decorate([
|
|
152
|
+
(0, common_3.Get)(':id'),
|
|
153
|
+
__param(0, (0, common_3.Param)('id')),
|
|
154
|
+
__param(1, (0, your_auth_decorator_1.CurrentUser)()),
|
|
155
|
+
__metadata("design:type", Function),
|
|
156
|
+
__metadata("design:paramtypes", [String, typeof (_f = typeof entities_1.User !== "undefined" && entities_1.User) === "function" ? _f : Object]),
|
|
157
|
+
__metadata("design:returntype", Promise)
|
|
158
|
+
], ContactController.prototype, "getContactById", null);
|
|
159
|
+
exports.ContactController = ContactController = __decorate([
|
|
160
|
+
(0, common_3.Controller)('contacts'),
|
|
161
|
+
(0, common_3.UseGuards)(modules_4.EnhancedRolesPolicyGuard),
|
|
162
|
+
__metadata("design:paramtypes", [ContactService])
|
|
163
|
+
], ContactController);
|
|
164
|
+
let ContactModule = class ContactModule {
|
|
165
|
+
};
|
|
166
|
+
exports.ContactModule = ContactModule;
|
|
167
|
+
exports.ContactModule = ContactModule = __decorate([
|
|
168
|
+
(0, common_1.Module)({
|
|
169
|
+
imports: [
|
|
170
|
+
TypeOrmModule.forFeature([entities_1.Contact, entities_1.Lead, Policy]),
|
|
171
|
+
],
|
|
172
|
+
controllers: [ContactController],
|
|
173
|
+
providers: [
|
|
174
|
+
ContactService,
|
|
175
|
+
PoliciesService,
|
|
176
|
+
GenericResourceService,
|
|
177
|
+
],
|
|
178
|
+
})
|
|
179
|
+
], ContactModule);
|
|
180
|
+
//# sourceMappingURL=usage-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-example.js","sourceRoot":"","sources":["../../../src/modules/authorization/usage-example.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiBA,2CAAwC;AACxC,yDAAkE;AAoB3D,IAAM,SAAS,GAAf,MAAM,SAAS;CAAG,CAAA;AAAZ,8BAAS;oBAAT,SAAS;IAlBrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YAEP,6BAAmB;YAGnB,6BAAmB,CAAC,OAAO,CAAC;gBAC1B,KAAK,EAAE;oBACL,GAAG,EAAE,GAAG;oBACR,GAAG,EAAE,IAAI;iBAEV;aACF,CAAC;SAGH;KAEF,CAAC;GACW,SAAS,CAAG;AAMzB,2CAA4C;AAC5C,qCAAqC;AACrC,6CAAmD;AACnD,yDAKqC;AACrC,2DAA6E;AAGtE,IAAM,cAAc,GAApB,MAAM,cAAc;IAGf;IAGA;IAGS;IACA;IATnB,YAEU,iBAAsC,EAGtC,kBAAwC,EAG/B,kBAA+C,EAC/C,WAAyC;QAPlD,sBAAiB,GAAjB,iBAAiB,CAAqB;QAGtC,uBAAkB,GAAlB,kBAAkB,CAAsB;QAG/B,uBAAkB,GAAlB,kBAAkB,CAA6B;QAC/C,gBAAW,GAAX,WAAW,CAA8B;IACzD,CAAC;IAEJ,KAAK,CAAC,cAAc,CAAC,IAAU;QAC7B,MAAM,YAAY,GAAG,IAAI,CAAC,iBAAiB;aACxC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAGjC,MAAM,IAAI,CAAC,kBAAkB,CAAC,6BAA6B,CACzD,YAAY,EACZ,IAAI,EACJ;YACE,MAAM,EAAE,0BAAgB,CAAC,IAAI;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC5C,CACF,CAAC;QAEF,OAAO,YAAY,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