@forklaunch/implementation-iam-base 0.8.21 → 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.
@@ -35,7 +35,7 @@ var BaseOrganizationService = class {
35
35
  if (em) {
36
36
  await em.persist(organization);
37
37
  } else {
38
- await this.em.persistAndFlush(organization);
38
+ await this.em.persist(organization).flush();
39
39
  }
40
40
  return this.mappers.OrganizationMapper.toDto(organization);
41
41
  }
@@ -44,11 +44,8 @@ var BaseOrganizationService = class {
44
44
  this.openTelemetryCollector.info("Getting organization", idDto);
45
45
  }
46
46
  const organization = await (em ?? this.em).findOneOrFail(
47
- "Organization",
48
- idDto,
49
- {
50
- populate: ["id", "*"]
51
- }
47
+ this.mappers.OrganizationMapper.entity,
48
+ idDto
52
49
  );
53
50
  return this.mappers.OrganizationMapper.toDto(
54
51
  organization
@@ -69,7 +66,7 @@ var BaseOrganizationService = class {
69
66
  if (em) {
70
67
  await em.persist(updatedOrganization);
71
68
  } else {
72
- await this.em.persistAndFlush(updatedOrganization);
69
+ await this.em.persist(updatedOrganization).flush();
73
70
  }
74
71
  return this.mappers.OrganizationMapper.toDto(updatedOrganization);
75
72
  }
@@ -78,9 +75,15 @@ var BaseOrganizationService = class {
78
75
  this.openTelemetryCollector.info("Deleting organization", idDto);
79
76
  }
80
77
  if (em) {
81
- await em.nativeDelete("Organization", idDto);
78
+ await em.nativeDelete(
79
+ this.mappers.OrganizationMapper.entity,
80
+ idDto
81
+ );
82
82
  } else {
83
- await this.em.nativeDelete("Organization", idDto);
83
+ await this.em.nativeDelete(
84
+ this.mappers.OrganizationMapper.entity,
85
+ idDto
86
+ );
84
87
  }
85
88
  }
86
89
  };
@@ -112,7 +115,7 @@ var BasePermissionService = class {
112
115
  async updateRolesWithPermissions(roles, permissions) {
113
116
  return Promise.all(
114
117
  roles.map(async (role) => {
115
- permissions.forEach((permission) => role.permissions.add(permission));
118
+ permissions.forEach((permission) => role.permissions?.add(permission));
116
119
  return role;
117
120
  })
118
121
  );
@@ -121,7 +124,7 @@ var BasePermissionService = class {
121
124
  return Promise.all(
122
125
  roles.map(async (role) => {
123
126
  permissions.forEach(
124
- (permission) => role.permissions.remove(permission)
127
+ (permission) => role.permissions?.remove(permission)
125
128
  );
126
129
  return role;
127
130
  })
@@ -151,7 +154,10 @@ var BasePermissionService = class {
151
154
  if (addToRoles) {
152
155
  roles = await this.updateRolesWithPermissions(addToRoles, [permission]);
153
156
  }
154
- return { permission, roles };
157
+ return {
158
+ permission,
159
+ roles
160
+ };
155
161
  }
156
162
  async extractCreatePermissionEntityToEntityData(permissionDto, em, ...args) {
157
163
  return {
@@ -183,7 +189,7 @@ var BasePermissionService = class {
183
189
  if (em) {
184
190
  await em.persist([permission, ...roles]);
185
191
  } else {
186
- await this.em.persistAndFlush([permission, ...roles]);
192
+ await this.em.persist([permission, ...roles]).flush();
187
193
  }
188
194
  return this.mappers.PermissionMapper.toDto(permission);
189
195
  }
@@ -205,23 +211,23 @@ var BasePermissionService = class {
205
211
  );
206
212
  await Promise.all(
207
213
  roles.map(async (role) => {
208
- if (!role.permissions.isInitialized()) {
209
- return role.permissions.init();
214
+ if (!role.permissions?.isInitialized()) {
215
+ return role.permissions?.init();
210
216
  }
211
217
  })
212
218
  );
213
219
  await Promise.all(
214
220
  roles.map(async (role) => {
215
- if (!role.permissions.isInitialized()) {
216
- return role.permissions.init();
221
+ if (!role.permissions?.isInitialized()) {
222
+ return role.permissions?.init();
217
223
  }
218
224
  })
219
225
  );
220
226
  roles.forEach((role) => {
221
227
  if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
222
- role.permissions.getItems().forEach((permission2) => {
223
- if (!rolesCache[role.id].permissions.contains(permission2)) {
224
- rolesCache[role.id].permissions.add(permission2);
228
+ role.permissions?.getItems().forEach((permission2) => {
229
+ if (!rolesCache[role.id].permissions?.contains(permission2)) {
230
+ rolesCache[role.id].permissions?.add(permission2);
225
231
  }
226
232
  });
227
233
  } else {
@@ -234,7 +240,7 @@ var BasePermissionService = class {
234
240
  if (em) {
235
241
  await em.persist(entities);
236
242
  } else {
237
- await this.em.persistAndFlush(entities);
243
+ await this.em.persist(entities).flush();
238
244
  }
239
245
  return Promise.all(
240
246
  permissions.map(
@@ -246,7 +252,10 @@ var BasePermissionService = class {
246
252
  if (this.evaluatedTelemetryOptions.logging) {
247
253
  this.openTelemetryCollector.info("Getting permission", idDto);
248
254
  }
249
- const permission = await (em ?? this.em).findOneOrFail("Permission", idDto);
255
+ const permission = await (em ?? this.em).findOneOrFail(
256
+ this.mappers.PermissionMapper.entity,
257
+ idDto
258
+ );
250
259
  return this.mappers.PermissionMapper.toDto(
251
260
  permission
252
261
  );
@@ -256,9 +265,12 @@ var BasePermissionService = class {
256
265
  this.openTelemetryCollector.info("Getting batch permissions", idsDto);
257
266
  }
258
267
  return Promise.all(
259
- (await (em ?? this.em).find("Permission", {
260
- id: { $in: idsDto.ids }
261
- })).map(
268
+ (await (em ?? this.em).find(
269
+ this.mappers.PermissionMapper.entity,
270
+ {
271
+ id: { $in: idsDto.ids }
272
+ }
273
+ )).map(
262
274
  (permission) => this.mappers.PermissionMapper.toDto(
263
275
  permission
264
276
  )
@@ -276,10 +288,14 @@ var BasePermissionService = class {
276
288
  const removeFromRoles = permissionDto.removeFromRolesIds ? await this.getBatchRoles({ ids: permissionDto.removeFromRolesIds }, em) : [];
277
289
  let roles = [];
278
290
  roles = roles.concat(
279
- await this.updateRolesWithPermissions(addToRoles, [permission])
291
+ await this.updateRolesWithPermissions(addToRoles, [
292
+ permission
293
+ ])
280
294
  );
281
295
  roles = roles.concat(
282
- await this.removePermissionsFromRoles(removeFromRoles, [permission])
296
+ await this.removePermissionsFromRoles(removeFromRoles, [
297
+ permission
298
+ ])
283
299
  );
284
300
  return {
285
301
  permission,
@@ -296,7 +312,7 @@ var BasePermissionService = class {
296
312
  if (em) {
297
313
  await em.persist(entities);
298
314
  } else {
299
- await this.em.persistAndFlush(entities);
315
+ await this.em.persist(entities).flush();
300
316
  }
301
317
  return this.mappers.PermissionMapper.toDto(permission);
302
318
  }
@@ -314,9 +330,9 @@ var BasePermissionService = class {
314
330
  const { permission, roles } = await this.updatePermissionDto(updatePermissionDto);
315
331
  roles.forEach((role) => {
316
332
  if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
317
- role.permissions.getItems().forEach((permission2) => {
318
- if (!rolesCache[role.id].permissions.contains(permission2)) {
319
- rolesCache[role.id].permissions.add(permission2);
333
+ role.permissions?.getItems().forEach((permission2) => {
334
+ if (!rolesCache[role.id].permissions?.contains(permission2)) {
335
+ rolesCache[role.id].permissions?.add(permission2);
320
336
  }
321
337
  });
322
338
  } else {
@@ -329,7 +345,7 @@ var BasePermissionService = class {
329
345
  if (em2) {
330
346
  await em2.persist(entities);
331
347
  } else {
332
- await this.em.persistAndFlush(entities);
348
+ await this.em.persist(entities).flush();
333
349
  }
334
350
  });
335
351
  return Promise.all(
@@ -342,15 +358,21 @@ var BasePermissionService = class {
342
358
  if (this.evaluatedTelemetryOptions.logging) {
343
359
  this.openTelemetryCollector.info("Deleting permission", idDto);
344
360
  }
345
- await (em ?? this.em).nativeDelete("Permission", idDto);
361
+ await (em ?? this.em).nativeDelete(
362
+ this.mappers.PermissionMapper.entity,
363
+ idDto
364
+ );
346
365
  }
347
366
  async deleteBatchPermissions(idsDto, em) {
348
367
  if (this.evaluatedTelemetryOptions.logging) {
349
368
  this.openTelemetryCollector.info("Deleting batch permissions", idsDto);
350
369
  }
351
- await (em ?? this.em).nativeDelete("Permission", {
352
- id: { $in: idsDto.ids }
353
- });
370
+ await (em ?? this.em).nativeDelete(
371
+ this.mappers.PermissionMapper.entity,
372
+ {
373
+ id: { $in: idsDto.ids }
374
+ }
375
+ );
354
376
  }
355
377
  };
356
378
 
@@ -387,7 +409,7 @@ var BaseRoleService = class {
387
409
  if (em) {
388
410
  await em.persist(role);
389
411
  } else {
390
- await this.em.persistAndFlush(role);
412
+ await this.em.persist(role).flush();
391
413
  }
392
414
  return this.mappers.RoleMapper.toDto(role);
393
415
  }
@@ -403,7 +425,7 @@ var BaseRoleService = class {
403
425
  if (em) {
404
426
  await em.persist(roles);
405
427
  } else {
406
- await this.em.persistAndFlush(roles);
428
+ await this.em.persist(roles).flush();
407
429
  }
408
430
  return Promise.all(
409
431
  roles.map((role) => this.mappers.RoleMapper.toDto(role))
@@ -413,10 +435,16 @@ var BaseRoleService = class {
413
435
  if (this.evaluatedTelemetryOptions.logging) {
414
436
  this.openTelemetryCollector.info("Getting role", { id });
415
437
  }
416
- const role = await (em ?? this.em).findOneOrFail("Role", id, {
417
- populate: ["id", "*"]
418
- });
419
- return this.mappers.RoleMapper.toDto(role);
438
+ const role = await (em ?? this.em).findOneOrFail(
439
+ this.mappers.RoleMapper.entity,
440
+ id,
441
+ {
442
+ populate: ["id", "*"]
443
+ }
444
+ );
445
+ return this.mappers.RoleMapper.toDto(
446
+ role
447
+ );
420
448
  }
421
449
  async getBatchRoles({ ids }, em) {
422
450
  if (this.evaluatedTelemetryOptions.logging) {
@@ -424,7 +452,7 @@ var BaseRoleService = class {
424
452
  }
425
453
  return Promise.all(
426
454
  (await (em ?? this.em).find(
427
- "Role",
455
+ this.mappers.RoleMapper.entity,
428
456
  {
429
457
  id: { $in: ids }
430
458
  },
@@ -432,7 +460,9 @@ var BaseRoleService = class {
432
460
  populate: ["id", "*"]
433
461
  }
434
462
  )).map(
435
- (role) => this.mappers.RoleMapper.toDto(role)
463
+ (role) => this.mappers.RoleMapper.toDto(
464
+ role
465
+ )
436
466
  )
437
467
  );
438
468
  }
@@ -448,7 +478,7 @@ var BaseRoleService = class {
448
478
  if (em) {
449
479
  await em.persist(role);
450
480
  } else {
451
- await this.em.persistAndFlush(role);
481
+ await this.em.persist(role).flush();
452
482
  }
453
483
  return this.mappers.RoleMapper.toDto(role);
454
484
  }
@@ -464,25 +494,31 @@ var BaseRoleService = class {
464
494
  if (em) {
465
495
  await em.persist(roles);
466
496
  } else {
467
- await this.em.persistAndFlush(roles);
497
+ await this.em.persist(roles).flush();
468
498
  }
469
499
  return Promise.all(
470
- roles.map(
471
- (role) => this.mappers.RoleMapper.toDto(role)
472
- )
500
+ roles.map((role) => this.mappers.RoleMapper.toDto(role))
473
501
  );
474
502
  }
475
503
  async deleteRole(idDto, em) {
476
504
  if (this.evaluatedTelemetryOptions.logging) {
477
505
  this.openTelemetryCollector.info("Deleting role", idDto);
478
506
  }
479
- await (em ?? this.em).nativeDelete("Role", idDto);
507
+ await (em ?? this.em).nativeDelete(
508
+ this.mappers.RoleMapper.entity,
509
+ idDto
510
+ );
480
511
  }
481
512
  async deleteBatchRoles(idsDto, em) {
482
513
  if (this.evaluatedTelemetryOptions.logging) {
483
514
  this.openTelemetryCollector.info("Deleting batch roles", idsDto);
484
515
  }
485
- await (em ?? this.em).nativeDelete("Role", { id: { $in: idsDto.ids } });
516
+ await (em ?? this.em).nativeDelete(
517
+ this.mappers.RoleMapper.entity,
518
+ {
519
+ id: { $in: idsDto.ids }
520
+ }
521
+ );
486
522
  }
487
523
  };
488
524
 
@@ -523,7 +559,7 @@ var BaseUserService = class {
523
559
  if (em) {
524
560
  await em.persist(user);
525
561
  } else {
526
- await this.em.persistAndFlush(user);
562
+ await this.em.persist(user).flush();
527
563
  }
528
564
  return this.mappers.UserMapper.toDto(user);
529
565
  }
@@ -543,42 +579,52 @@ var BaseUserService = class {
543
579
  if (em) {
544
580
  await em.persist(users);
545
581
  } else {
546
- await this.em.persistAndFlush(users);
582
+ await this.em.persist(users).flush();
547
583
  }
548
584
  return Promise.all(
549
585
  users.map((user) => this.mappers.UserMapper.toDto(user))
550
586
  );
551
587
  }
552
588
  async getOrganizationIdByUserId(idDto, em) {
553
- const user = await (em ?? this.em).findOne("User", idDto, {
554
- populate: ["id", "organization"]
555
- });
589
+ const user = await (em ?? this.em).findOne(
590
+ this.mappers.UserMapper.entity,
591
+ idDto,
592
+ {
593
+ populate: ["id", "organization"]
594
+ }
595
+ );
556
596
  return user?.organization?.id;
557
597
  }
558
598
  async getUser(idDto, em) {
559
599
  if (this.evaluatedTelemetryOptions.logging) {
560
600
  this.openTelemetryCollector.info("Getting user", idDto);
561
601
  }
562
- const user = await (em ?? this.em).findOneOrFail("User", idDto, {
563
- populate: ["id", "*"]
564
- });
565
- return this.mappers.UserMapper.toDto(user);
602
+ const user = await (em ?? this.em).findOneOrFail(
603
+ this.mappers.UserMapper.entity,
604
+ idDto,
605
+ {
606
+ populate: ["id", "*"]
607
+ }
608
+ );
609
+ return this.mappers.UserMapper.toDto(
610
+ user
611
+ );
566
612
  }
567
613
  async getBatchUsers(idsDto, em) {
568
614
  if (this.evaluatedTelemetryOptions.logging) {
569
615
  this.openTelemetryCollector.info("Getting batch users", idsDto);
570
616
  }
571
- const filter = {
572
- id: { $in: idsDto.ids },
573
- ...idsDto.organization && {
574
- organization: idsDto.organization
575
- }
576
- };
577
617
  return Promise.all(
578
- (await (em ?? this.em).find("User", filter, {
579
- populate: ["id", "*"]
580
- })).map(
581
- (user) => this.mappers.UserMapper.toDto(user)
618
+ (await (em ?? this.em).find(
619
+ this.mappers.UserMapper.entity,
620
+ idsDto,
621
+ {
622
+ populate: ["id", "*"]
623
+ }
624
+ )).map(
625
+ (user) => this.mappers.UserMapper.toDto(
626
+ user
627
+ )
582
628
  )
583
629
  );
584
630
  }
@@ -594,7 +640,7 @@ var BaseUserService = class {
594
640
  if (em) {
595
641
  await em.persist(user);
596
642
  } else {
597
- await this.em.persistAndFlush(user);
643
+ await this.em.persist(user).flush();
598
644
  }
599
645
  return this.mappers.UserMapper.toDto(user);
600
646
  }
@@ -614,7 +660,7 @@ var BaseUserService = class {
614
660
  if (em) {
615
661
  await em.persist(users);
616
662
  } else {
617
- await this.em.persistAndFlush(users);
663
+ await this.em.persist(users).flush();
618
664
  }
619
665
  return Promise.all(
620
666
  users.map((user) => this.mappers.UserMapper.toDto(user))
@@ -631,7 +677,10 @@ var BaseUserService = class {
631
677
  organization: idDto.organization
632
678
  }
633
679
  };
634
- await (em ?? this.em).nativeDelete("User", filter);
680
+ await (em ?? this.em).nativeDelete(
681
+ this.mappers.UserMapper.entity,
682
+ filter
683
+ );
635
684
  }
636
685
  async deleteBatchUsers(idsDto, em) {
637
686
  if (this.evaluatedTelemetryOptions.logging) {
@@ -641,10 +690,13 @@ var BaseUserService = class {
641
690
  ...idsDto,
642
691
  id: { $in: idsDto.ids },
643
692
  ...idsDto.organization && {
644
- organization: idsDto.organization
693
+ organization: idsDto.organization.id
645
694
  }
646
695
  };
647
- await (em ?? this.em).nativeDelete("User", filter);
696
+ await (em ?? this.em).nativeDelete(
697
+ this.mappers.UserMapper.entity,
698
+ filter
699
+ );
648
700
  }
649
701
  async surfaceRoles(idDto, em) {
650
702
  if (this.evaluatedTelemetryOptions.logging) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-iam-base",
3
- "version": "0.8.21",
3
+ "version": "0.9.0",
4
4
  "description": "IAM basic implementation for forklaunch",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -36,18 +36,19 @@
36
36
  "lib/**"
37
37
  ],
38
38
  "dependencies": {
39
- "@forklaunch/common": "^0.6.35",
40
- "@forklaunch/core": "^0.18.8",
41
- "@forklaunch/internal": "^0.3.35",
42
- "@forklaunch/validator": "^0.10.35",
43
- "@mikro-orm/core": "^6.6.9",
39
+ "@forklaunch/common": "^0.7.5",
40
+ "@forklaunch/core": "^0.19.5",
41
+ "@forklaunch/internal": "^0.4.5",
42
+ "@forklaunch/validator": "^0.11.5",
43
+ "@mikro-orm/core": "7.0.4",
44
44
  "@sinclair/typebox": "^0.34.48",
45
45
  "ajv": "^8.18.0",
46
+ "uuid": "^13.0.0",
46
47
  "zod": "^4.3.6",
47
- "@forklaunch/interfaces-iam": "0.8.20"
48
+ "@forklaunch/interfaces-iam": "0.9.0"
48
49
  },
49
50
  "devDependencies": {
50
- "@typescript/native-preview": "7.0.0-dev.20260311.1",
51
+ "@typescript/native-preview": "7.0.0-dev.20260320.1",
51
52
  "depcheck": "^1.4.7",
52
53
  "prettier": "^3.8.1",
53
54
  "typedoc": "^0.28.17"