@forklaunch/implementation-iam-base 0.8.10 → 0.8.12

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.
@@ -120,11 +120,11 @@ export class BaseUserService<
120
120
  async getOrganizationIdByUserId(
121
121
  idDto: IdDto,
122
122
  em?: EntityManager
123
- ): Promise<string> {
124
- const user = await (em ?? this.em).findOneOrFail('User', idDto, {
123
+ ): Promise<string | undefined> {
124
+ const user = await (em ?? this.em).findOne('User', idDto, {
125
125
  populate: ['id', 'organization']
126
126
  });
127
- return user.organization?.id;
127
+ return user?.organization?.id;
128
128
  }
129
129
 
130
130
  async getUser(
@@ -143,22 +143,26 @@ export class BaseUserService<
143
143
  }
144
144
 
145
145
  async getBatchUsers(
146
- idsDto: IdsDto,
146
+ idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']>,
147
147
  em?: EntityManager
148
148
  ): Promise<MapperDomains['UserMapper'][]> {
149
149
  if (this.evaluatedTelemetryOptions.logging) {
150
150
  this.openTelemetryCollector.info('Getting batch users', idsDto);
151
151
  }
152
152
 
153
+ // Build filter with organization constraint if provided
154
+ const filter: FilterQuery<MapperEntities['UserMapper']> = {
155
+ id: { $in: idsDto.ids },
156
+ ...((idsDto as any).organization && {
157
+ organization: (idsDto as any).organization
158
+ })
159
+ };
160
+
153
161
  return Promise.all(
154
162
  (
155
- await (em ?? this.em).find(
156
- 'User',
157
- { id: { $in: idsDto.ids } },
158
- {
159
- populate: ['id', '*']
160
- }
161
- )
163
+ await (em ?? this.em).find('User', filter, {
164
+ populate: ['id', '*']
165
+ })
162
166
  ).map((user) =>
163
167
  this.mappers.UserMapper.toDto(user as MapperEntities['UserMapper'])
164
168
  )
@@ -219,18 +223,46 @@ export class BaseUserService<
219
223
  );
220
224
  }
221
225
 
222
- async deleteUser(idDto: IdDto, em?: EntityManager): Promise<void> {
226
+ async deleteUser(
227
+ idDto: IdDto & { organization?: { id: string } } & FilterQuery<
228
+ MapperEntities['UserMapper']
229
+ > & object,
230
+ em?: EntityManager
231
+ ): Promise<void> {
223
232
  if (this.evaluatedTelemetryOptions.logging) {
224
233
  this.openTelemetryCollector.info('Deleting user', idDto);
225
234
  }
226
- await (em ?? this.em).nativeDelete('User', idDto);
235
+
236
+ const filter = {
237
+ ...idDto,
238
+ id: idDto.id,
239
+ ...(idDto.organization && {
240
+ organization: idDto.organization
241
+ })
242
+ } as FilterQuery<MapperEntities['UserMapper']>;
243
+
244
+ await (em ?? this.em).nativeDelete('User', filter);
227
245
  }
228
246
 
229
- async deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void> {
247
+ async deleteBatchUsers(
248
+ idsDto: IdsDto & { organization?: { id: string } } & FilterQuery<
249
+ MapperEntities['UserMapper']
250
+ > & object,
251
+ em?: EntityManager
252
+ ): Promise<void> {
230
253
  if (this.evaluatedTelemetryOptions.logging) {
231
254
  this.openTelemetryCollector.info('Deleting batch users', idsDto);
232
255
  }
233
- await (em ?? this.em).nativeDelete('User', { id: { $in: idsDto.ids } });
256
+
257
+ const filter = {
258
+ ...idsDto,
259
+ id: { $in: idsDto.ids },
260
+ ...(idsDto.organization && {
261
+ organization: idsDto.organization
262
+ })
263
+ };
264
+
265
+ await (em ?? this.em).nativeDelete('User', filter);
234
266
  }
235
267
 
236
268
  async surfaceRoles(
@@ -256,6 +288,6 @@ export class BaseUserService<
256
288
  });
257
289
  }
258
290
  const user = await this.getUser(idDto, em);
259
- return user.roles.map((role) => role.permissions).flat();
291
+ return user.roles.flatMap((role) => role.permissions);
260
292
  }
261
293
  }
@@ -82,13 +82,21 @@ declare class BaseUserService<SchemaValidator extends AnySchemaValidator, Organi
82
82
  });
83
83
  createUser(userDto: CreateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
84
84
  createBatchUsers(userDtos: CreateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
85
- getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string>;
85
+ getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string | undefined>;
86
86
  getUser(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']>;
87
- getBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
87
+ getBatchUsers(idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
88
88
  updateUser(userDto: UpdateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
89
89
  updateBatchUsers(userDtos: UpdateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
90
- deleteUser(idDto: IdDto, em?: EntityManager): Promise<void>;
91
- deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void>;
90
+ deleteUser(idDto: IdDto & {
91
+ organization?: {
92
+ id: string;
93
+ };
94
+ } & FilterQuery<MapperEntities['UserMapper']> & object, em?: EntityManager): Promise<void>;
95
+ deleteBatchUsers(idsDto: IdsDto & {
96
+ organization?: {
97
+ id: string;
98
+ };
99
+ } & FilterQuery<MapperEntities['UserMapper']> & object, em?: EntityManager): Promise<void>;
92
100
  surfaceRoles(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles']>;
93
101
  surfacePermissions(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles'][0]['permissions']>;
94
102
  }
@@ -82,13 +82,21 @@ declare class BaseUserService<SchemaValidator extends AnySchemaValidator, Organi
82
82
  });
83
83
  createUser(userDto: CreateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
84
84
  createBatchUsers(userDtos: CreateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
85
- getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string>;
85
+ getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string | undefined>;
86
86
  getUser(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']>;
87
- getBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
87
+ getBatchUsers(idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
88
88
  updateUser(userDto: UpdateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
89
89
  updateBatchUsers(userDtos: UpdateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
90
- deleteUser(idDto: IdDto, em?: EntityManager): Promise<void>;
91
- deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void>;
90
+ deleteUser(idDto: IdDto & {
91
+ organization?: {
92
+ id: string;
93
+ };
94
+ } & FilterQuery<MapperEntities['UserMapper']> & object, em?: EntityManager): Promise<void>;
95
+ deleteBatchUsers(idsDto: IdsDto & {
96
+ organization?: {
97
+ id: string;
98
+ };
99
+ } & FilterQuery<MapperEntities['UserMapper']> & object, em?: EntityManager): Promise<void>;
92
100
  surfaceRoles(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles']>;
93
101
  surfacePermissions(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles'][0]['permissions']>;
94
102
  }
@@ -572,10 +572,10 @@ var BaseUserService = class {
572
572
  );
573
573
  }
574
574
  async getOrganizationIdByUserId(idDto, em) {
575
- const user = await (em ?? this.em).findOneOrFail("User", idDto, {
575
+ const user = await (em ?? this.em).findOne("User", idDto, {
576
576
  populate: ["id", "organization"]
577
577
  });
578
- return user.organization?.id;
578
+ return user?.organization?.id;
579
579
  }
580
580
  async getUser(idDto, em) {
581
581
  if (this.evaluatedTelemetryOptions.logging) {
@@ -590,14 +590,16 @@ var BaseUserService = class {
590
590
  if (this.evaluatedTelemetryOptions.logging) {
591
591
  this.openTelemetryCollector.info("Getting batch users", idsDto);
592
592
  }
593
+ const filter = {
594
+ id: { $in: idsDto.ids },
595
+ ...idsDto.organization && {
596
+ organization: idsDto.organization
597
+ }
598
+ };
593
599
  return Promise.all(
594
- (await (em ?? this.em).find(
595
- "User",
596
- { id: { $in: idsDto.ids } },
597
- {
598
- populate: ["id", "*"]
599
- }
600
- )).map(
600
+ (await (em ?? this.em).find("User", filter, {
601
+ populate: ["id", "*"]
602
+ })).map(
601
603
  (user) => this.mappers.UserMapper.toDto(user)
602
604
  )
603
605
  );
@@ -644,13 +646,27 @@ var BaseUserService = class {
644
646
  if (this.evaluatedTelemetryOptions.logging) {
645
647
  this.openTelemetryCollector.info("Deleting user", idDto);
646
648
  }
647
- await (em ?? this.em).nativeDelete("User", idDto);
649
+ const filter = {
650
+ ...idDto,
651
+ id: idDto.id,
652
+ ...idDto.organization && {
653
+ organization: idDto.organization
654
+ }
655
+ };
656
+ await (em ?? this.em).nativeDelete("User", filter);
648
657
  }
649
658
  async deleteBatchUsers(idsDto, em) {
650
659
  if (this.evaluatedTelemetryOptions.logging) {
651
660
  this.openTelemetryCollector.info("Deleting batch users", idsDto);
652
661
  }
653
- await (em ?? this.em).nativeDelete("User", { id: { $in: idsDto.ids } });
662
+ const filter = {
663
+ ...idsDto,
664
+ id: { $in: idsDto.ids },
665
+ ...idsDto.organization && {
666
+ organization: idsDto.organization
667
+ }
668
+ };
669
+ await (em ?? this.em).nativeDelete("User", filter);
654
670
  }
655
671
  async surfaceRoles(idDto, em) {
656
672
  if (this.evaluatedTelemetryOptions.logging) {
@@ -668,7 +684,7 @@ var BaseUserService = class {
668
684
  });
669
685
  }
670
686
  const user = await this.getUser(idDto, em);
671
- return user.roles.map((role) => role.permissions).flat();
687
+ return user.roles.flatMap((role) => role.permissions);
672
688
  }
673
689
  };
674
690
 
@@ -550,10 +550,10 @@ var BaseUserService = class {
550
550
  );
551
551
  }
552
552
  async getOrganizationIdByUserId(idDto, em) {
553
- const user = await (em ?? this.em).findOneOrFail("User", idDto, {
553
+ const user = await (em ?? this.em).findOne("User", idDto, {
554
554
  populate: ["id", "organization"]
555
555
  });
556
- return user.organization?.id;
556
+ return user?.organization?.id;
557
557
  }
558
558
  async getUser(idDto, em) {
559
559
  if (this.evaluatedTelemetryOptions.logging) {
@@ -568,14 +568,16 @@ var BaseUserService = class {
568
568
  if (this.evaluatedTelemetryOptions.logging) {
569
569
  this.openTelemetryCollector.info("Getting batch users", idsDto);
570
570
  }
571
+ const filter = {
572
+ id: { $in: idsDto.ids },
573
+ ...idsDto.organization && {
574
+ organization: idsDto.organization
575
+ }
576
+ };
571
577
  return Promise.all(
572
- (await (em ?? this.em).find(
573
- "User",
574
- { id: { $in: idsDto.ids } },
575
- {
576
- populate: ["id", "*"]
577
- }
578
- )).map(
578
+ (await (em ?? this.em).find("User", filter, {
579
+ populate: ["id", "*"]
580
+ })).map(
579
581
  (user) => this.mappers.UserMapper.toDto(user)
580
582
  )
581
583
  );
@@ -622,13 +624,27 @@ var BaseUserService = class {
622
624
  if (this.evaluatedTelemetryOptions.logging) {
623
625
  this.openTelemetryCollector.info("Deleting user", idDto);
624
626
  }
625
- await (em ?? this.em).nativeDelete("User", idDto);
627
+ const filter = {
628
+ ...idDto,
629
+ id: idDto.id,
630
+ ...idDto.organization && {
631
+ organization: idDto.organization
632
+ }
633
+ };
634
+ await (em ?? this.em).nativeDelete("User", filter);
626
635
  }
627
636
  async deleteBatchUsers(idsDto, em) {
628
637
  if (this.evaluatedTelemetryOptions.logging) {
629
638
  this.openTelemetryCollector.info("Deleting batch users", idsDto);
630
639
  }
631
- await (em ?? this.em).nativeDelete("User", { id: { $in: idsDto.ids } });
640
+ const filter = {
641
+ ...idsDto,
642
+ id: { $in: idsDto.ids },
643
+ ...idsDto.organization && {
644
+ organization: idsDto.organization
645
+ }
646
+ };
647
+ await (em ?? this.em).nativeDelete("User", filter);
632
648
  }
633
649
  async surfaceRoles(idDto, em) {
634
650
  if (this.evaluatedTelemetryOptions.logging) {
@@ -646,7 +662,7 @@ var BaseUserService = class {
646
662
  });
647
663
  }
648
664
  const user = await this.getUser(idDto, em);
649
- return user.roles.map((role) => role.permissions).flat();
665
+ return user.roles.flatMap((role) => role.permissions);
650
666
  }
651
667
  };
652
668
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-iam-base",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "description": "IAM basic implementation for forklaunch",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -36,18 +36,18 @@
36
36
  "lib/**"
37
37
  ],
38
38
  "dependencies": {
39
- "@forklaunch/common": "^0.6.27",
40
- "@forklaunch/core": "^0.17.3",
41
- "@forklaunch/internal": "^0.3.27",
42
- "@forklaunch/validator": "^0.10.27",
43
- "@mikro-orm/core": "^6.6.5",
44
- "@sinclair/typebox": "^0.34.47",
39
+ "@forklaunch/common": "^0.6.28",
40
+ "@forklaunch/core": "^0.18.1",
41
+ "@forklaunch/internal": "^0.3.28",
42
+ "@forklaunch/validator": "^0.10.28",
43
+ "@mikro-orm/core": "^6.6.6",
44
+ "@sinclair/typebox": "^0.34.48",
45
45
  "ajv": "^8.17.1",
46
46
  "zod": "^4.3.6",
47
- "@forklaunch/interfaces-iam": "0.8.10"
47
+ "@forklaunch/interfaces-iam": "0.8.12"
48
48
  },
49
49
  "devDependencies": {
50
- "@typescript/native-preview": "7.0.0-dev.20260122.4",
50
+ "@typescript/native-preview": "7.0.0-dev.20260204.1",
51
51
  "depcheck": "^1.4.7",
52
52
  "prettier": "^3.8.1",
53
53
  "typedoc": "^0.28.16"