@forklaunch/implementation-iam-base 0.3.1 → 0.3.2
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/eject/domain/schemas/organization.schema.ts +3 -3
- package/lib/eject/domain/schemas/permission.schema.ts +3 -3
- package/lib/eject/domain/schemas/role.schema.ts +3 -3
- package/lib/eject/domain/schemas/user.schema.ts +3 -3
- package/lib/eject/services/organization.service.ts +41 -77
- package/lib/eject/services/permission.service.ts +80 -104
- package/lib/eject/services/role.service.ts +51 -81
- package/lib/eject/services/user.service.ts +51 -74
- package/lib/eject/types/iamDto.types.ts +43 -0
- package/lib/eject/types/iamEntities.types.ts +49 -0
- package/lib/schemas/index.d.mts +61 -61
- package/lib/schemas/index.d.ts +61 -61
- package/lib/schemas/index.js +32 -32
- package/lib/schemas/index.mjs +28 -28
- package/lib/services/index.d.mts +110 -134
- package/lib/services/index.d.ts +110 -134
- package/lib/services/index.js +46 -54
- package/lib/services/index.mjs +50 -58
- package/package.json +9 -8
package/lib/services/index.js
CHANGED
|
@@ -29,21 +29,21 @@ module.exports = __toCommonJS(services_exports);
|
|
|
29
29
|
|
|
30
30
|
// services/organization.service.ts
|
|
31
31
|
var import_http = require("@forklaunch/core/http");
|
|
32
|
-
var
|
|
32
|
+
var import_internal = require("@forklaunch/internal");
|
|
33
33
|
var BaseOrganizationService = class {
|
|
34
34
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
35
35
|
this.em = em;
|
|
36
36
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
37
37
|
this.schemaValidator = schemaValidator;
|
|
38
38
|
this.mappers = mappers;
|
|
39
|
-
this
|
|
39
|
+
this._mappers = (0, import_internal.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
40
40
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
41
41
|
logging: false,
|
|
42
42
|
metrics: false,
|
|
43
43
|
tracing: false
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
_mappers;
|
|
47
47
|
evaluatedTelemetryOptions;
|
|
48
48
|
async createOrganization(organizationDto, em) {
|
|
49
49
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -52,7 +52,7 @@ var BaseOrganizationService = class {
|
|
|
52
52
|
organizationDto
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
const organization = await this
|
|
55
|
+
const organization = await this._mappers.CreateOrganizationMapper.deserializeDtoToEntity(
|
|
56
56
|
organizationDto,
|
|
57
57
|
em ?? this.em
|
|
58
58
|
);
|
|
@@ -61,9 +61,7 @@ var BaseOrganizationService = class {
|
|
|
61
61
|
} else {
|
|
62
62
|
await this.em.persistAndFlush(organization);
|
|
63
63
|
}
|
|
64
|
-
return this
|
|
65
|
-
organization
|
|
66
|
-
);
|
|
64
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(organization);
|
|
67
65
|
}
|
|
68
66
|
async getOrganization(idDto, em) {
|
|
69
67
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -73,7 +71,7 @@ var BaseOrganizationService = class {
|
|
|
73
71
|
"Organization",
|
|
74
72
|
idDto
|
|
75
73
|
);
|
|
76
|
-
return this
|
|
74
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(
|
|
77
75
|
organization
|
|
78
76
|
);
|
|
79
77
|
}
|
|
@@ -84,7 +82,7 @@ var BaseOrganizationService = class {
|
|
|
84
82
|
organizationDto
|
|
85
83
|
);
|
|
86
84
|
}
|
|
87
|
-
const updatedOrganization = await this
|
|
85
|
+
const updatedOrganization = await this._mappers.UpdateOrganizationMapper.deserializeDtoToEntity(
|
|
88
86
|
organizationDto,
|
|
89
87
|
em ?? this.em
|
|
90
88
|
);
|
|
@@ -93,7 +91,7 @@ var BaseOrganizationService = class {
|
|
|
93
91
|
} else {
|
|
94
92
|
await this.em.persistAndFlush(updatedOrganization);
|
|
95
93
|
}
|
|
96
|
-
return this
|
|
94
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(
|
|
97
95
|
updatedOrganization
|
|
98
96
|
);
|
|
99
97
|
}
|
|
@@ -111,7 +109,7 @@ var BaseOrganizationService = class {
|
|
|
111
109
|
|
|
112
110
|
// services/permission.service.ts
|
|
113
111
|
var import_http2 = require("@forklaunch/core/http");
|
|
114
|
-
var
|
|
112
|
+
var import_internal2 = require("@forklaunch/internal");
|
|
115
113
|
var BasePermissionService = class {
|
|
116
114
|
constructor(em, roleServiceFactory, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
117
115
|
this.em = em;
|
|
@@ -119,14 +117,14 @@ var BasePermissionService = class {
|
|
|
119
117
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
120
118
|
this.schemaValidator = schemaValidator;
|
|
121
119
|
this.mappers = mappers;
|
|
122
|
-
this
|
|
120
|
+
this._mappers = (0, import_internal2.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
123
121
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
124
122
|
logging: false,
|
|
125
123
|
metrics: false,
|
|
126
124
|
tracing: false
|
|
127
125
|
};
|
|
128
126
|
}
|
|
129
|
-
|
|
127
|
+
_mappers;
|
|
130
128
|
evaluatedTelemetryOptions;
|
|
131
129
|
// start: global helper functions
|
|
132
130
|
async updateRolesWithPermissions(roles, permissions) {
|
|
@@ -152,7 +150,7 @@ var BasePermissionService = class {
|
|
|
152
150
|
(await this.roleServiceFactory().getBatchRoles(roleIds, em)).map(
|
|
153
151
|
async (role) => {
|
|
154
152
|
return (em ?? this.em).merge(
|
|
155
|
-
await this
|
|
153
|
+
await this._mappers.RoleEntityMapper.deserializeDtoToEntity(
|
|
156
154
|
role,
|
|
157
155
|
em ?? this.em
|
|
158
156
|
)
|
|
@@ -176,7 +174,7 @@ var BasePermissionService = class {
|
|
|
176
174
|
async extractCreatePermissionDtoToEntityData(permissionDto, em) {
|
|
177
175
|
return {
|
|
178
176
|
permission: (em ?? this.em).merge(
|
|
179
|
-
await this
|
|
177
|
+
await this._mappers.CreatePermissionMapper.deserializeDtoToEntity(
|
|
180
178
|
permissionDto,
|
|
181
179
|
em ?? this.em
|
|
182
180
|
)
|
|
@@ -200,7 +198,7 @@ var BasePermissionService = class {
|
|
|
200
198
|
} else {
|
|
201
199
|
await this.em.persistAndFlush([permission, ...roles]);
|
|
202
200
|
}
|
|
203
|
-
return this
|
|
201
|
+
return this._mappers.PermissionMapper.serializeEntityToDto(permission);
|
|
204
202
|
}
|
|
205
203
|
async createBatchPermissions(permissionDtos, em) {
|
|
206
204
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -239,7 +237,7 @@ var BasePermissionService = class {
|
|
|
239
237
|
}
|
|
240
238
|
return Promise.all(
|
|
241
239
|
permissions.map(
|
|
242
|
-
async (permission) => this
|
|
240
|
+
async (permission) => this._mappers.PermissionMapper.serializeEntityToDto(permission)
|
|
243
241
|
)
|
|
244
242
|
);
|
|
245
243
|
}
|
|
@@ -248,7 +246,7 @@ var BasePermissionService = class {
|
|
|
248
246
|
this.openTelemetryCollector.info("Getting permission", idDto);
|
|
249
247
|
}
|
|
250
248
|
const permission = await (em ?? this.em).findOneOrFail("Permission", idDto);
|
|
251
|
-
return this
|
|
249
|
+
return this._mappers.PermissionMapper.serializeEntityToDto(
|
|
252
250
|
permission
|
|
253
251
|
);
|
|
254
252
|
}
|
|
@@ -258,7 +256,7 @@ var BasePermissionService = class {
|
|
|
258
256
|
}
|
|
259
257
|
return Promise.all(
|
|
260
258
|
(await (em ?? this.em).find("Permission", idsDto)).map(
|
|
261
|
-
(permission) => this
|
|
259
|
+
(permission) => this._mappers.PermissionMapper.serializeEntityToDto(
|
|
262
260
|
permission
|
|
263
261
|
)
|
|
264
262
|
)
|
|
@@ -266,7 +264,7 @@ var BasePermissionService = class {
|
|
|
266
264
|
}
|
|
267
265
|
// start: updatePermission helper functions
|
|
268
266
|
updatePermissionDto = async (permissionDto, em) => {
|
|
269
|
-
const permission = await this
|
|
267
|
+
const permission = await this._mappers.UpdatePermissionMapper.deserializeDtoToEntity(
|
|
270
268
|
permissionDto,
|
|
271
269
|
em ?? this.em
|
|
272
270
|
);
|
|
@@ -296,7 +294,7 @@ var BasePermissionService = class {
|
|
|
296
294
|
} else {
|
|
297
295
|
await this.em.persistAndFlush(entities);
|
|
298
296
|
}
|
|
299
|
-
return this
|
|
297
|
+
return this._mappers.PermissionMapper.serializeEntityToDto(permission);
|
|
300
298
|
}
|
|
301
299
|
async updateBatchPermissions(permissionDtos, em) {
|
|
302
300
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -332,7 +330,7 @@ var BasePermissionService = class {
|
|
|
332
330
|
});
|
|
333
331
|
return Promise.all(
|
|
334
332
|
permissions.map(
|
|
335
|
-
(permission) => this
|
|
333
|
+
(permission) => this._mappers.PermissionMapper.serializeEntityToDto(permission)
|
|
336
334
|
)
|
|
337
335
|
);
|
|
338
336
|
}
|
|
@@ -354,27 +352,27 @@ var BasePermissionService = class {
|
|
|
354
352
|
|
|
355
353
|
// services/role.service.ts
|
|
356
354
|
var import_http3 = require("@forklaunch/core/http");
|
|
357
|
-
var
|
|
355
|
+
var import_internal3 = require("@forklaunch/internal");
|
|
358
356
|
var BaseRoleService = class {
|
|
359
357
|
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
360
358
|
this.em = em;
|
|
361
359
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
362
360
|
this.schemaValidator = schemaValidator;
|
|
363
361
|
this.mappers = mappers;
|
|
364
|
-
this
|
|
362
|
+
this._mappers = (0, import_internal3.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
365
363
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
366
364
|
logging: false,
|
|
367
365
|
metrics: false,
|
|
368
366
|
tracing: false
|
|
369
367
|
};
|
|
370
368
|
}
|
|
371
|
-
|
|
369
|
+
_mappers;
|
|
372
370
|
evaluatedTelemetryOptions;
|
|
373
371
|
async createRole(roleDto, em) {
|
|
374
372
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
375
373
|
this.openTelemetryCollector.info("Creating role", roleDto);
|
|
376
374
|
}
|
|
377
|
-
const role = await this
|
|
375
|
+
const role = await this._mappers.CreateRoleMapper.deserializeDtoToEntity(
|
|
378
376
|
roleDto,
|
|
379
377
|
em ?? this.em
|
|
380
378
|
);
|
|
@@ -383,7 +381,7 @@ var BaseRoleService = class {
|
|
|
383
381
|
} else {
|
|
384
382
|
await this.em.persistAndFlush(role);
|
|
385
383
|
}
|
|
386
|
-
return this
|
|
384
|
+
return this._mappers.RoleMapper.serializeEntityToDto(role);
|
|
387
385
|
}
|
|
388
386
|
async createBatchRoles(roleDtos, em) {
|
|
389
387
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -391,7 +389,7 @@ var BaseRoleService = class {
|
|
|
391
389
|
}
|
|
392
390
|
const roles = await Promise.all(
|
|
393
391
|
roleDtos.map(
|
|
394
|
-
async (roleDto) => this
|
|
392
|
+
async (roleDto) => this._mappers.CreateRoleMapper.deserializeDtoToEntity(
|
|
395
393
|
roleDto,
|
|
396
394
|
em ?? this.em
|
|
397
395
|
)
|
|
@@ -403,9 +401,7 @@ var BaseRoleService = class {
|
|
|
403
401
|
await this.em.persistAndFlush(roles);
|
|
404
402
|
}
|
|
405
403
|
return Promise.all(
|
|
406
|
-
roles.map(
|
|
407
|
-
(role) => this.#mappers.RoleDtoMapper.serializeEntityToDto(role)
|
|
408
|
-
)
|
|
404
|
+
roles.map((role) => this._mappers.RoleMapper.serializeEntityToDto(role))
|
|
409
405
|
);
|
|
410
406
|
}
|
|
411
407
|
async getRole({ id }, em) {
|
|
@@ -415,7 +411,7 @@ var BaseRoleService = class {
|
|
|
415
411
|
const role = await (em ?? this.em).findOneOrFail("Role", id, {
|
|
416
412
|
populate: ["id", "*"]
|
|
417
413
|
});
|
|
418
|
-
return this
|
|
414
|
+
return this._mappers.RoleMapper.serializeEntityToDto(
|
|
419
415
|
role
|
|
420
416
|
);
|
|
421
417
|
}
|
|
@@ -433,7 +429,7 @@ var BaseRoleService = class {
|
|
|
433
429
|
populate: ["id", "*"]
|
|
434
430
|
}
|
|
435
431
|
)).map(
|
|
436
|
-
(role) => this
|
|
432
|
+
(role) => this._mappers.RoleMapper.serializeEntityToDto(
|
|
437
433
|
role
|
|
438
434
|
)
|
|
439
435
|
)
|
|
@@ -443,7 +439,7 @@ var BaseRoleService = class {
|
|
|
443
439
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
444
440
|
this.openTelemetryCollector.info("Updating role", roleDto);
|
|
445
441
|
}
|
|
446
|
-
const role = await this
|
|
442
|
+
const role = await this._mappers.UpdateRoleMapper.deserializeDtoToEntity(
|
|
447
443
|
roleDto,
|
|
448
444
|
em ?? this.em
|
|
449
445
|
);
|
|
@@ -452,7 +448,7 @@ var BaseRoleService = class {
|
|
|
452
448
|
} else {
|
|
453
449
|
await this.em.persistAndFlush(role);
|
|
454
450
|
}
|
|
455
|
-
return this
|
|
451
|
+
return this._mappers.RoleMapper.serializeEntityToDto(role);
|
|
456
452
|
}
|
|
457
453
|
async updateBatchRoles(roleDtos, em) {
|
|
458
454
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -460,7 +456,7 @@ var BaseRoleService = class {
|
|
|
460
456
|
}
|
|
461
457
|
const roles = await Promise.all(
|
|
462
458
|
roleDtos.map(
|
|
463
|
-
async (roleDto) => this
|
|
459
|
+
async (roleDto) => this._mappers.UpdateRoleMapper.deserializeDtoToEntity(
|
|
464
460
|
roleDto,
|
|
465
461
|
em ?? this.em
|
|
466
462
|
)
|
|
@@ -473,7 +469,7 @@ var BaseRoleService = class {
|
|
|
473
469
|
}
|
|
474
470
|
return Promise.all(
|
|
475
471
|
roles.map(
|
|
476
|
-
(role) => this
|
|
472
|
+
(role) => this._mappers.RoleMapper.serializeEntityToDto(
|
|
477
473
|
role
|
|
478
474
|
)
|
|
479
475
|
)
|
|
@@ -495,7 +491,7 @@ var BaseRoleService = class {
|
|
|
495
491
|
|
|
496
492
|
// services/user.service.ts
|
|
497
493
|
var import_http4 = require("@forklaunch/core/http");
|
|
498
|
-
var
|
|
494
|
+
var import_internal4 = require("@forklaunch/internal");
|
|
499
495
|
var BaseUserService = class {
|
|
500
496
|
constructor(em, passwordEncryptionPublicKeyPath, roleServiceFactory, organizationServiceFactory, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
501
497
|
this.em = em;
|
|
@@ -506,20 +502,20 @@ var BaseUserService = class {
|
|
|
506
502
|
this.schemaValidator = schemaValidator;
|
|
507
503
|
this.mappers = mappers;
|
|
508
504
|
this.options = options;
|
|
509
|
-
this
|
|
505
|
+
this._mappers = (0, import_internal4.transformIntoInternalMapper)(mappers, schemaValidator);
|
|
510
506
|
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
511
507
|
logging: false,
|
|
512
508
|
metrics: false,
|
|
513
509
|
tracing: false
|
|
514
510
|
};
|
|
515
511
|
}
|
|
516
|
-
|
|
512
|
+
_mappers;
|
|
517
513
|
evaluatedTelemetryOptions;
|
|
518
514
|
async createUser(userDto, em) {
|
|
519
515
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
520
516
|
this.openTelemetryCollector.info("Creating user", userDto);
|
|
521
517
|
}
|
|
522
|
-
const user = await this
|
|
518
|
+
const user = await this._mappers.CreateUserMapper.deserializeDtoToEntity(
|
|
523
519
|
userDto,
|
|
524
520
|
em ?? this.em
|
|
525
521
|
);
|
|
@@ -528,7 +524,7 @@ var BaseUserService = class {
|
|
|
528
524
|
} else {
|
|
529
525
|
await this.em.persistAndFlush(user);
|
|
530
526
|
}
|
|
531
|
-
return this
|
|
527
|
+
return this._mappers.UserMapper.serializeEntityToDto(user);
|
|
532
528
|
}
|
|
533
529
|
async createBatchUsers(userDtos, em) {
|
|
534
530
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -536,7 +532,7 @@ var BaseUserService = class {
|
|
|
536
532
|
}
|
|
537
533
|
const users = await Promise.all(
|
|
538
534
|
userDtos.map(
|
|
539
|
-
async (createUserDto) => this
|
|
535
|
+
async (createUserDto) => this._mappers.CreateUserMapper.deserializeDtoToEntity(
|
|
540
536
|
createUserDto,
|
|
541
537
|
em ?? this.em
|
|
542
538
|
)
|
|
@@ -548,9 +544,7 @@ var BaseUserService = class {
|
|
|
548
544
|
await this.em.persistAndFlush(users);
|
|
549
545
|
}
|
|
550
546
|
return Promise.all(
|
|
551
|
-
users.map(
|
|
552
|
-
(user) => this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
553
|
-
)
|
|
547
|
+
users.map((user) => this._mappers.UserMapper.serializeEntityToDto(user))
|
|
554
548
|
);
|
|
555
549
|
}
|
|
556
550
|
async getUser(idDto, em) {
|
|
@@ -560,7 +554,7 @@ var BaseUserService = class {
|
|
|
560
554
|
const user = await (em ?? this.em).findOneOrFail("User", idDto, {
|
|
561
555
|
populate: ["id", "*"]
|
|
562
556
|
});
|
|
563
|
-
return this
|
|
557
|
+
return this._mappers.UserMapper.serializeEntityToDto(
|
|
564
558
|
user
|
|
565
559
|
);
|
|
566
560
|
}
|
|
@@ -572,7 +566,7 @@ var BaseUserService = class {
|
|
|
572
566
|
(await (em ?? this.em).find("User", idsDto, {
|
|
573
567
|
populate: ["id", "*"]
|
|
574
568
|
})).map(
|
|
575
|
-
(user) => this
|
|
569
|
+
(user) => this._mappers.UserMapper.serializeEntityToDto(
|
|
576
570
|
user
|
|
577
571
|
)
|
|
578
572
|
)
|
|
@@ -582,7 +576,7 @@ var BaseUserService = class {
|
|
|
582
576
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
583
577
|
this.openTelemetryCollector.info("Updating user", userDto);
|
|
584
578
|
}
|
|
585
|
-
const user = await this
|
|
579
|
+
const user = await this._mappers.UpdateUserMapper.deserializeDtoToEntity(
|
|
586
580
|
userDto,
|
|
587
581
|
em ?? this.em
|
|
588
582
|
);
|
|
@@ -591,7 +585,7 @@ var BaseUserService = class {
|
|
|
591
585
|
} else {
|
|
592
586
|
await this.em.persistAndFlush(user);
|
|
593
587
|
}
|
|
594
|
-
return this
|
|
588
|
+
return this._mappers.UserMapper.serializeEntityToDto(user);
|
|
595
589
|
}
|
|
596
590
|
async updateBatchUsers(userDtos, em) {
|
|
597
591
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -599,7 +593,7 @@ var BaseUserService = class {
|
|
|
599
593
|
}
|
|
600
594
|
const users = await Promise.all(
|
|
601
595
|
userDtos.map(
|
|
602
|
-
async (updateUserDto) => this
|
|
596
|
+
async (updateUserDto) => this._mappers.UpdateUserMapper.deserializeDtoToEntity(
|
|
603
597
|
updateUserDto,
|
|
604
598
|
em ?? this.em
|
|
605
599
|
)
|
|
@@ -611,9 +605,7 @@ var BaseUserService = class {
|
|
|
611
605
|
await this.em.persistAndFlush(users);
|
|
612
606
|
}
|
|
613
607
|
return Promise.all(
|
|
614
|
-
users.map(
|
|
615
|
-
(user) => this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
616
|
-
)
|
|
608
|
+
users.map((user) => this._mappers.UserMapper.serializeEntityToDto(user))
|
|
617
609
|
);
|
|
618
610
|
}
|
|
619
611
|
async deleteUser(idDto, em) {
|