@forklaunch/implementation-iam-base 0.8.24 → 0.9.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/lib/domain/schemas/index.d.mts +8 -2
- package/lib/domain/schemas/index.d.ts +8 -2
- package/lib/domain/schemas/index.js +4 -2
- package/lib/domain/schemas/index.mjs +4 -2
- package/lib/domain/types/index.d.mts +186 -28
- package/lib/domain/types/index.d.ts +186 -28
- package/lib/eject/domain/schemas/user.schema.ts +2 -1
- package/lib/eject/domain/types/iamEntities.types.ts +54 -36
- package/lib/eject/domain/types/organization.mapper.types.ts +7 -4
- package/lib/eject/domain/types/permission.mapper.types.ts +9 -5
- package/lib/eject/domain/types/role.mapper.types.ts +7 -4
- package/lib/eject/domain/types/user.mapper.types.ts +7 -4
- package/lib/eject/services/organization.service.ts +27 -19
- package/lib/eject/services/permission.service.ts +82 -57
- package/lib/eject/services/role.service.ts +36 -18
- package/lib/eject/services/user.service.ts +54 -42
- package/lib/services/index.d.mts +9 -10
- package/lib/services/index.d.ts +9 -10
- package/lib/services/index.js +127 -75
- package/lib/services/index.mjs +127 -75
- package/package.json +9 -8
package/lib/services/index.js
CHANGED
|
@@ -63,7 +63,7 @@ var BaseOrganizationService = class {
|
|
|
63
63
|
if (em) {
|
|
64
64
|
await em.persist(organization);
|
|
65
65
|
} else {
|
|
66
|
-
await this.em.
|
|
66
|
+
await this.em.persist(organization).flush();
|
|
67
67
|
}
|
|
68
68
|
return this.mappers.OrganizationMapper.toDto(organization);
|
|
69
69
|
}
|
|
@@ -72,11 +72,8 @@ var BaseOrganizationService = class {
|
|
|
72
72
|
this.openTelemetryCollector.info("Getting organization", idDto);
|
|
73
73
|
}
|
|
74
74
|
const organization = await (em ?? this.em).findOneOrFail(
|
|
75
|
-
|
|
76
|
-
idDto
|
|
77
|
-
{
|
|
78
|
-
populate: ["id", "*"]
|
|
79
|
-
}
|
|
75
|
+
this.mappers.OrganizationMapper.entity,
|
|
76
|
+
idDto
|
|
80
77
|
);
|
|
81
78
|
return this.mappers.OrganizationMapper.toDto(
|
|
82
79
|
organization
|
|
@@ -97,7 +94,7 @@ var BaseOrganizationService = class {
|
|
|
97
94
|
if (em) {
|
|
98
95
|
await em.persist(updatedOrganization);
|
|
99
96
|
} else {
|
|
100
|
-
await this.em.
|
|
97
|
+
await this.em.persist(updatedOrganization).flush();
|
|
101
98
|
}
|
|
102
99
|
return this.mappers.OrganizationMapper.toDto(updatedOrganization);
|
|
103
100
|
}
|
|
@@ -106,9 +103,15 @@ var BaseOrganizationService = class {
|
|
|
106
103
|
this.openTelemetryCollector.info("Deleting organization", idDto);
|
|
107
104
|
}
|
|
108
105
|
if (em) {
|
|
109
|
-
await em.nativeDelete(
|
|
106
|
+
await em.nativeDelete(
|
|
107
|
+
this.mappers.OrganizationMapper.entity,
|
|
108
|
+
idDto
|
|
109
|
+
);
|
|
110
110
|
} else {
|
|
111
|
-
await this.em.nativeDelete(
|
|
111
|
+
await this.em.nativeDelete(
|
|
112
|
+
this.mappers.OrganizationMapper.entity,
|
|
113
|
+
idDto
|
|
114
|
+
);
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
};
|
|
@@ -138,7 +141,7 @@ var BasePermissionService = class {
|
|
|
138
141
|
async updateRolesWithPermissions(roles, permissions) {
|
|
139
142
|
return Promise.all(
|
|
140
143
|
roles.map(async (role) => {
|
|
141
|
-
permissions.forEach((permission) => role.permissions
|
|
144
|
+
permissions.forEach((permission) => role.permissions?.add(permission));
|
|
142
145
|
return role;
|
|
143
146
|
})
|
|
144
147
|
);
|
|
@@ -147,7 +150,7 @@ var BasePermissionService = class {
|
|
|
147
150
|
return Promise.all(
|
|
148
151
|
roles.map(async (role) => {
|
|
149
152
|
permissions.forEach(
|
|
150
|
-
(permission) => role.permissions
|
|
153
|
+
(permission) => role.permissions?.remove(permission)
|
|
151
154
|
);
|
|
152
155
|
return role;
|
|
153
156
|
})
|
|
@@ -177,7 +180,10 @@ var BasePermissionService = class {
|
|
|
177
180
|
if (addToRoles) {
|
|
178
181
|
roles = await this.updateRolesWithPermissions(addToRoles, [permission]);
|
|
179
182
|
}
|
|
180
|
-
return {
|
|
183
|
+
return {
|
|
184
|
+
permission,
|
|
185
|
+
roles
|
|
186
|
+
};
|
|
181
187
|
}
|
|
182
188
|
async extractCreatePermissionEntityToEntityData(permissionDto, em, ...args) {
|
|
183
189
|
return {
|
|
@@ -209,7 +215,7 @@ var BasePermissionService = class {
|
|
|
209
215
|
if (em) {
|
|
210
216
|
await em.persist([permission, ...roles]);
|
|
211
217
|
} else {
|
|
212
|
-
await this.em.
|
|
218
|
+
await this.em.persist([permission, ...roles]).flush();
|
|
213
219
|
}
|
|
214
220
|
return this.mappers.PermissionMapper.toDto(permission);
|
|
215
221
|
}
|
|
@@ -231,23 +237,23 @@ var BasePermissionService = class {
|
|
|
231
237
|
);
|
|
232
238
|
await Promise.all(
|
|
233
239
|
roles.map(async (role) => {
|
|
234
|
-
if (!role.permissions
|
|
235
|
-
return role.permissions
|
|
240
|
+
if (!role.permissions?.isInitialized()) {
|
|
241
|
+
return role.permissions?.init();
|
|
236
242
|
}
|
|
237
243
|
})
|
|
238
244
|
);
|
|
239
245
|
await Promise.all(
|
|
240
246
|
roles.map(async (role) => {
|
|
241
|
-
if (!role.permissions
|
|
242
|
-
return role.permissions
|
|
247
|
+
if (!role.permissions?.isInitialized()) {
|
|
248
|
+
return role.permissions?.init();
|
|
243
249
|
}
|
|
244
250
|
})
|
|
245
251
|
);
|
|
246
252
|
roles.forEach((role) => {
|
|
247
253
|
if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
|
|
248
|
-
role.permissions
|
|
249
|
-
if (!rolesCache[role.id].permissions
|
|
250
|
-
rolesCache[role.id].permissions
|
|
254
|
+
role.permissions?.getItems().forEach((permission2) => {
|
|
255
|
+
if (!rolesCache[role.id].permissions?.contains(permission2)) {
|
|
256
|
+
rolesCache[role.id].permissions?.add(permission2);
|
|
251
257
|
}
|
|
252
258
|
});
|
|
253
259
|
} else {
|
|
@@ -260,7 +266,7 @@ var BasePermissionService = class {
|
|
|
260
266
|
if (em) {
|
|
261
267
|
await em.persist(entities);
|
|
262
268
|
} else {
|
|
263
|
-
await this.em.
|
|
269
|
+
await this.em.persist(entities).flush();
|
|
264
270
|
}
|
|
265
271
|
return Promise.all(
|
|
266
272
|
permissions.map(
|
|
@@ -272,7 +278,10 @@ var BasePermissionService = class {
|
|
|
272
278
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
273
279
|
this.openTelemetryCollector.info("Getting permission", idDto);
|
|
274
280
|
}
|
|
275
|
-
const permission = await (em ?? this.em).findOneOrFail(
|
|
281
|
+
const permission = await (em ?? this.em).findOneOrFail(
|
|
282
|
+
this.mappers.PermissionMapper.entity,
|
|
283
|
+
idDto
|
|
284
|
+
);
|
|
276
285
|
return this.mappers.PermissionMapper.toDto(
|
|
277
286
|
permission
|
|
278
287
|
);
|
|
@@ -282,9 +291,12 @@ var BasePermissionService = class {
|
|
|
282
291
|
this.openTelemetryCollector.info("Getting batch permissions", idsDto);
|
|
283
292
|
}
|
|
284
293
|
return Promise.all(
|
|
285
|
-
(await (em ?? this.em).find(
|
|
286
|
-
|
|
287
|
-
|
|
294
|
+
(await (em ?? this.em).find(
|
|
295
|
+
this.mappers.PermissionMapper.entity,
|
|
296
|
+
{
|
|
297
|
+
id: { $in: idsDto.ids }
|
|
298
|
+
}
|
|
299
|
+
)).map(
|
|
288
300
|
(permission) => this.mappers.PermissionMapper.toDto(
|
|
289
301
|
permission
|
|
290
302
|
)
|
|
@@ -302,10 +314,14 @@ var BasePermissionService = class {
|
|
|
302
314
|
const removeFromRoles = permissionDto.removeFromRolesIds ? await this.getBatchRoles({ ids: permissionDto.removeFromRolesIds }, em) : [];
|
|
303
315
|
let roles = [];
|
|
304
316
|
roles = roles.concat(
|
|
305
|
-
await this.updateRolesWithPermissions(addToRoles, [
|
|
317
|
+
await this.updateRolesWithPermissions(addToRoles, [
|
|
318
|
+
permission
|
|
319
|
+
])
|
|
306
320
|
);
|
|
307
321
|
roles = roles.concat(
|
|
308
|
-
await this.removePermissionsFromRoles(removeFromRoles, [
|
|
322
|
+
await this.removePermissionsFromRoles(removeFromRoles, [
|
|
323
|
+
permission
|
|
324
|
+
])
|
|
309
325
|
);
|
|
310
326
|
return {
|
|
311
327
|
permission,
|
|
@@ -322,7 +338,7 @@ var BasePermissionService = class {
|
|
|
322
338
|
if (em) {
|
|
323
339
|
await em.persist(entities);
|
|
324
340
|
} else {
|
|
325
|
-
await this.em.
|
|
341
|
+
await this.em.persist(entities).flush();
|
|
326
342
|
}
|
|
327
343
|
return this.mappers.PermissionMapper.toDto(permission);
|
|
328
344
|
}
|
|
@@ -340,9 +356,9 @@ var BasePermissionService = class {
|
|
|
340
356
|
const { permission, roles } = await this.updatePermissionDto(updatePermissionDto);
|
|
341
357
|
roles.forEach((role) => {
|
|
342
358
|
if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
|
|
343
|
-
role.permissions
|
|
344
|
-
if (!rolesCache[role.id].permissions
|
|
345
|
-
rolesCache[role.id].permissions
|
|
359
|
+
role.permissions?.getItems().forEach((permission2) => {
|
|
360
|
+
if (!rolesCache[role.id].permissions?.contains(permission2)) {
|
|
361
|
+
rolesCache[role.id].permissions?.add(permission2);
|
|
346
362
|
}
|
|
347
363
|
});
|
|
348
364
|
} else {
|
|
@@ -355,7 +371,7 @@ var BasePermissionService = class {
|
|
|
355
371
|
if (em2) {
|
|
356
372
|
await em2.persist(entities);
|
|
357
373
|
} else {
|
|
358
|
-
await this.em.
|
|
374
|
+
await this.em.persist(entities).flush();
|
|
359
375
|
}
|
|
360
376
|
});
|
|
361
377
|
return Promise.all(
|
|
@@ -368,15 +384,21 @@ var BasePermissionService = class {
|
|
|
368
384
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
369
385
|
this.openTelemetryCollector.info("Deleting permission", idDto);
|
|
370
386
|
}
|
|
371
|
-
await (em ?? this.em).nativeDelete(
|
|
387
|
+
await (em ?? this.em).nativeDelete(
|
|
388
|
+
this.mappers.PermissionMapper.entity,
|
|
389
|
+
idDto
|
|
390
|
+
);
|
|
372
391
|
}
|
|
373
392
|
async deleteBatchPermissions(idsDto, em) {
|
|
374
393
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
375
394
|
this.openTelemetryCollector.info("Deleting batch permissions", idsDto);
|
|
376
395
|
}
|
|
377
|
-
await (em ?? this.em).nativeDelete(
|
|
378
|
-
|
|
379
|
-
|
|
396
|
+
await (em ?? this.em).nativeDelete(
|
|
397
|
+
this.mappers.PermissionMapper.entity,
|
|
398
|
+
{
|
|
399
|
+
id: { $in: idsDto.ids }
|
|
400
|
+
}
|
|
401
|
+
);
|
|
380
402
|
}
|
|
381
403
|
};
|
|
382
404
|
|
|
@@ -411,7 +433,7 @@ var BaseRoleService = class {
|
|
|
411
433
|
if (em) {
|
|
412
434
|
await em.persist(role);
|
|
413
435
|
} else {
|
|
414
|
-
await this.em.
|
|
436
|
+
await this.em.persist(role).flush();
|
|
415
437
|
}
|
|
416
438
|
return this.mappers.RoleMapper.toDto(role);
|
|
417
439
|
}
|
|
@@ -427,7 +449,7 @@ var BaseRoleService = class {
|
|
|
427
449
|
if (em) {
|
|
428
450
|
await em.persist(roles);
|
|
429
451
|
} else {
|
|
430
|
-
await this.em.
|
|
452
|
+
await this.em.persist(roles).flush();
|
|
431
453
|
}
|
|
432
454
|
return Promise.all(
|
|
433
455
|
roles.map((role) => this.mappers.RoleMapper.toDto(role))
|
|
@@ -437,10 +459,16 @@ var BaseRoleService = class {
|
|
|
437
459
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
438
460
|
this.openTelemetryCollector.info("Getting role", { id });
|
|
439
461
|
}
|
|
440
|
-
const role = await (em ?? this.em).findOneOrFail(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
462
|
+
const role = await (em ?? this.em).findOneOrFail(
|
|
463
|
+
this.mappers.RoleMapper.entity,
|
|
464
|
+
id,
|
|
465
|
+
{
|
|
466
|
+
populate: ["id", "*"]
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
return this.mappers.RoleMapper.toDto(
|
|
470
|
+
role
|
|
471
|
+
);
|
|
444
472
|
}
|
|
445
473
|
async getBatchRoles({ ids }, em) {
|
|
446
474
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -448,7 +476,7 @@ var BaseRoleService = class {
|
|
|
448
476
|
}
|
|
449
477
|
return Promise.all(
|
|
450
478
|
(await (em ?? this.em).find(
|
|
451
|
-
|
|
479
|
+
this.mappers.RoleMapper.entity,
|
|
452
480
|
{
|
|
453
481
|
id: { $in: ids }
|
|
454
482
|
},
|
|
@@ -456,7 +484,9 @@ var BaseRoleService = class {
|
|
|
456
484
|
populate: ["id", "*"]
|
|
457
485
|
}
|
|
458
486
|
)).map(
|
|
459
|
-
(role) => this.mappers.RoleMapper.toDto(
|
|
487
|
+
(role) => this.mappers.RoleMapper.toDto(
|
|
488
|
+
role
|
|
489
|
+
)
|
|
460
490
|
)
|
|
461
491
|
);
|
|
462
492
|
}
|
|
@@ -472,7 +502,7 @@ var BaseRoleService = class {
|
|
|
472
502
|
if (em) {
|
|
473
503
|
await em.persist(role);
|
|
474
504
|
} else {
|
|
475
|
-
await this.em.
|
|
505
|
+
await this.em.persist(role).flush();
|
|
476
506
|
}
|
|
477
507
|
return this.mappers.RoleMapper.toDto(role);
|
|
478
508
|
}
|
|
@@ -488,25 +518,31 @@ var BaseRoleService = class {
|
|
|
488
518
|
if (em) {
|
|
489
519
|
await em.persist(roles);
|
|
490
520
|
} else {
|
|
491
|
-
await this.em.
|
|
521
|
+
await this.em.persist(roles).flush();
|
|
492
522
|
}
|
|
493
523
|
return Promise.all(
|
|
494
|
-
roles.map(
|
|
495
|
-
(role) => this.mappers.RoleMapper.toDto(role)
|
|
496
|
-
)
|
|
524
|
+
roles.map((role) => this.mappers.RoleMapper.toDto(role))
|
|
497
525
|
);
|
|
498
526
|
}
|
|
499
527
|
async deleteRole(idDto, em) {
|
|
500
528
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
501
529
|
this.openTelemetryCollector.info("Deleting role", idDto);
|
|
502
530
|
}
|
|
503
|
-
await (em ?? this.em).nativeDelete(
|
|
531
|
+
await (em ?? this.em).nativeDelete(
|
|
532
|
+
this.mappers.RoleMapper.entity,
|
|
533
|
+
idDto
|
|
534
|
+
);
|
|
504
535
|
}
|
|
505
536
|
async deleteBatchRoles(idsDto, em) {
|
|
506
537
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
507
538
|
this.openTelemetryCollector.info("Deleting batch roles", idsDto);
|
|
508
539
|
}
|
|
509
|
-
await (em ?? this.em).nativeDelete(
|
|
540
|
+
await (em ?? this.em).nativeDelete(
|
|
541
|
+
this.mappers.RoleMapper.entity,
|
|
542
|
+
{
|
|
543
|
+
id: { $in: idsDto.ids }
|
|
544
|
+
}
|
|
545
|
+
);
|
|
510
546
|
}
|
|
511
547
|
};
|
|
512
548
|
|
|
@@ -545,7 +581,7 @@ var BaseUserService = class {
|
|
|
545
581
|
if (em) {
|
|
546
582
|
await em.persist(user);
|
|
547
583
|
} else {
|
|
548
|
-
await this.em.
|
|
584
|
+
await this.em.persist(user).flush();
|
|
549
585
|
}
|
|
550
586
|
return this.mappers.UserMapper.toDto(user);
|
|
551
587
|
}
|
|
@@ -565,42 +601,52 @@ var BaseUserService = class {
|
|
|
565
601
|
if (em) {
|
|
566
602
|
await em.persist(users);
|
|
567
603
|
} else {
|
|
568
|
-
await this.em.
|
|
604
|
+
await this.em.persist(users).flush();
|
|
569
605
|
}
|
|
570
606
|
return Promise.all(
|
|
571
607
|
users.map((user) => this.mappers.UserMapper.toDto(user))
|
|
572
608
|
);
|
|
573
609
|
}
|
|
574
610
|
async getOrganizationIdByUserId(idDto, em) {
|
|
575
|
-
const user = await (em ?? this.em).findOne(
|
|
576
|
-
|
|
577
|
-
|
|
611
|
+
const user = await (em ?? this.em).findOne(
|
|
612
|
+
this.mappers.UserMapper.entity,
|
|
613
|
+
idDto,
|
|
614
|
+
{
|
|
615
|
+
populate: ["id", "organization"]
|
|
616
|
+
}
|
|
617
|
+
);
|
|
578
618
|
return user?.organization?.id;
|
|
579
619
|
}
|
|
580
620
|
async getUser(idDto, em) {
|
|
581
621
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
582
622
|
this.openTelemetryCollector.info("Getting user", idDto);
|
|
583
623
|
}
|
|
584
|
-
const user = await (em ?? this.em).findOneOrFail(
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
624
|
+
const user = await (em ?? this.em).findOneOrFail(
|
|
625
|
+
this.mappers.UserMapper.entity,
|
|
626
|
+
idDto,
|
|
627
|
+
{
|
|
628
|
+
populate: ["id", "*"]
|
|
629
|
+
}
|
|
630
|
+
);
|
|
631
|
+
return this.mappers.UserMapper.toDto(
|
|
632
|
+
user
|
|
633
|
+
);
|
|
588
634
|
}
|
|
589
635
|
async getBatchUsers(idsDto, em) {
|
|
590
636
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
591
637
|
this.openTelemetryCollector.info("Getting batch users", idsDto);
|
|
592
638
|
}
|
|
593
|
-
const filter = {
|
|
594
|
-
id: { $in: idsDto.ids },
|
|
595
|
-
...idsDto.organization && {
|
|
596
|
-
organization: idsDto.organization
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
639
|
return Promise.all(
|
|
600
|
-
(await (em ?? this.em).find(
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
640
|
+
(await (em ?? this.em).find(
|
|
641
|
+
this.mappers.UserMapper.entity,
|
|
642
|
+
idsDto,
|
|
643
|
+
{
|
|
644
|
+
populate: ["id", "*"]
|
|
645
|
+
}
|
|
646
|
+
)).map(
|
|
647
|
+
(user) => this.mappers.UserMapper.toDto(
|
|
648
|
+
user
|
|
649
|
+
)
|
|
604
650
|
)
|
|
605
651
|
);
|
|
606
652
|
}
|
|
@@ -616,7 +662,7 @@ var BaseUserService = class {
|
|
|
616
662
|
if (em) {
|
|
617
663
|
await em.persist(user);
|
|
618
664
|
} else {
|
|
619
|
-
await this.em.
|
|
665
|
+
await this.em.persist(user).flush();
|
|
620
666
|
}
|
|
621
667
|
return this.mappers.UserMapper.toDto(user);
|
|
622
668
|
}
|
|
@@ -636,7 +682,7 @@ var BaseUserService = class {
|
|
|
636
682
|
if (em) {
|
|
637
683
|
await em.persist(users);
|
|
638
684
|
} else {
|
|
639
|
-
await this.em.
|
|
685
|
+
await this.em.persist(users).flush();
|
|
640
686
|
}
|
|
641
687
|
return Promise.all(
|
|
642
688
|
users.map((user) => this.mappers.UserMapper.toDto(user))
|
|
@@ -653,7 +699,10 @@ var BaseUserService = class {
|
|
|
653
699
|
organization: idDto.organization
|
|
654
700
|
}
|
|
655
701
|
};
|
|
656
|
-
await (em ?? this.em).nativeDelete(
|
|
702
|
+
await (em ?? this.em).nativeDelete(
|
|
703
|
+
this.mappers.UserMapper.entity,
|
|
704
|
+
filter
|
|
705
|
+
);
|
|
657
706
|
}
|
|
658
707
|
async deleteBatchUsers(idsDto, em) {
|
|
659
708
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -663,10 +712,13 @@ var BaseUserService = class {
|
|
|
663
712
|
...idsDto,
|
|
664
713
|
id: { $in: idsDto.ids },
|
|
665
714
|
...idsDto.organization && {
|
|
666
|
-
organization: idsDto.organization
|
|
715
|
+
organization: idsDto.organization.id
|
|
667
716
|
}
|
|
668
717
|
};
|
|
669
|
-
await (em ?? this.em).nativeDelete(
|
|
718
|
+
await (em ?? this.em).nativeDelete(
|
|
719
|
+
this.mappers.UserMapper.entity,
|
|
720
|
+
filter
|
|
721
|
+
);
|
|
670
722
|
}
|
|
671
723
|
async surfaceRoles(idDto, em) {
|
|
672
724
|
if (this.evaluatedTelemetryOptions.logging) {
|