@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.
- 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
|
@@ -13,7 +13,12 @@ import {
|
|
|
13
13
|
} from '@forklaunch/core/http';
|
|
14
14
|
import { CreateUserDto, UpdateUserDto } from '@forklaunch/interfaces-iam/types';
|
|
15
15
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
EntityManager,
|
|
18
|
+
FilterQuery,
|
|
19
|
+
InferEntity
|
|
20
|
+
} from '@mikro-orm/core';
|
|
21
|
+
import { User } from '../persistence/entities';
|
|
17
22
|
import { UserDtos } from '../domain/types/iamDto.types';
|
|
18
23
|
import { UserEntities } from '../domain/types/iamEntities.types';
|
|
19
24
|
import { UserMappers } from '../domain/types/user.mapper.types';
|
|
@@ -23,8 +28,7 @@ export class BaseUserService<
|
|
|
23
28
|
OrganizationStatus = unknown,
|
|
24
29
|
MapperEntities extends UserEntities = UserEntities,
|
|
25
30
|
MapperDomains extends UserDtos = UserDtos
|
|
26
|
-
> implements UserService
|
|
27
|
-
{
|
|
31
|
+
> implements UserService {
|
|
28
32
|
private evaluatedTelemetryOptions: {
|
|
29
33
|
logging?: boolean;
|
|
30
34
|
metrics?: boolean;
|
|
@@ -81,7 +85,7 @@ export class BaseUserService<
|
|
|
81
85
|
if (em) {
|
|
82
86
|
await em.persist(user);
|
|
83
87
|
} else {
|
|
84
|
-
await this.em.
|
|
88
|
+
await this.em.persist(user).flush();
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
return this.mappers.UserMapper.toDto(user);
|
|
@@ -109,7 +113,7 @@ export class BaseUserService<
|
|
|
109
113
|
if (em) {
|
|
110
114
|
await em.persist(users);
|
|
111
115
|
} else {
|
|
112
|
-
await this.em.
|
|
116
|
+
await this.em.persist(users).flush();
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
return Promise.all(
|
|
@@ -121,50 +125,58 @@ export class BaseUserService<
|
|
|
121
125
|
idDto: IdDto,
|
|
122
126
|
em?: EntityManager
|
|
123
127
|
): Promise<string | undefined> {
|
|
124
|
-
const user = await (em ?? this.em).findOne(
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
const user = await (em ?? this.em).findOne(
|
|
129
|
+
this.mappers.UserMapper.entity as typeof User,
|
|
130
|
+
idDto,
|
|
131
|
+
{
|
|
132
|
+
populate: ['id', 'organization']
|
|
133
|
+
}
|
|
134
|
+
);
|
|
127
135
|
return user?.organization?.id;
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
async getUser(
|
|
131
|
-
idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
139
|
+
idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>,
|
|
132
140
|
em?: EntityManager
|
|
133
141
|
): Promise<MapperDomains['UserMapper']> {
|
|
134
142
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
135
143
|
this.openTelemetryCollector.info('Getting user', idDto);
|
|
136
144
|
}
|
|
137
145
|
|
|
138
|
-
const user = await (em ?? this.em).findOneOrFail(
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
const user = await (em ?? this.em).findOneOrFail(
|
|
147
|
+
this.mappers.UserMapper.entity as typeof User,
|
|
148
|
+
idDto,
|
|
149
|
+
{
|
|
150
|
+
populate: ['id', '*']
|
|
151
|
+
}
|
|
152
|
+
);
|
|
141
153
|
|
|
142
|
-
return this.mappers.UserMapper.toDto(
|
|
154
|
+
return this.mappers.UserMapper.toDto(
|
|
155
|
+
user as InferEntity<MapperEntities['UserMapper']>
|
|
156
|
+
);
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
async getBatchUsers(
|
|
146
|
-
idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']
|
|
160
|
+
idsDto: IdsDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>,
|
|
147
161
|
em?: EntityManager
|
|
148
162
|
): Promise<MapperDomains['UserMapper'][]> {
|
|
149
163
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
150
164
|
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
151
165
|
}
|
|
152
166
|
|
|
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
|
-
|
|
161
167
|
return Promise.all(
|
|
162
168
|
(
|
|
163
|
-
await (em ?? this.em).find(
|
|
164
|
-
|
|
165
|
-
|
|
169
|
+
await (em ?? this.em).find(
|
|
170
|
+
this.mappers.UserMapper.entity as typeof User,
|
|
171
|
+
idsDto,
|
|
172
|
+
{
|
|
173
|
+
populate: ['id', '*']
|
|
174
|
+
}
|
|
175
|
+
)
|
|
166
176
|
).map((user) =>
|
|
167
|
-
this.mappers.UserMapper.toDto(
|
|
177
|
+
this.mappers.UserMapper.toDto(
|
|
178
|
+
user as InferEntity<MapperEntities['UserMapper']>
|
|
179
|
+
)
|
|
168
180
|
)
|
|
169
181
|
);
|
|
170
182
|
}
|
|
@@ -187,7 +199,7 @@ export class BaseUserService<
|
|
|
187
199
|
if (em) {
|
|
188
200
|
await em.persist(user);
|
|
189
201
|
} else {
|
|
190
|
-
await this.em.
|
|
202
|
+
await this.em.persist(user).flush();
|
|
191
203
|
}
|
|
192
204
|
|
|
193
205
|
return this.mappers.UserMapper.toDto(user);
|
|
@@ -215,7 +227,7 @@ export class BaseUserService<
|
|
|
215
227
|
if (em) {
|
|
216
228
|
await em.persist(users);
|
|
217
229
|
} else {
|
|
218
|
-
await this.em.
|
|
230
|
+
await this.em.persist(users).flush();
|
|
219
231
|
}
|
|
220
232
|
|
|
221
233
|
return Promise.all(
|
|
@@ -224,10 +236,7 @@ export class BaseUserService<
|
|
|
224
236
|
}
|
|
225
237
|
|
|
226
238
|
async deleteUser(
|
|
227
|
-
idDto: IdDto & { organization?: { id: string } }
|
|
228
|
-
MapperEntities['UserMapper']
|
|
229
|
-
> &
|
|
230
|
-
object,
|
|
239
|
+
idDto: IdDto & { organization?: { id: string } },
|
|
231
240
|
em?: EntityManager
|
|
232
241
|
): Promise<void> {
|
|
233
242
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -240,16 +249,16 @@ export class BaseUserService<
|
|
|
240
249
|
...(idDto.organization && {
|
|
241
250
|
organization: idDto.organization
|
|
242
251
|
})
|
|
243
|
-
}
|
|
252
|
+
};
|
|
244
253
|
|
|
245
|
-
await (em ?? this.em).nativeDelete(
|
|
254
|
+
await (em ?? this.em).nativeDelete(
|
|
255
|
+
this.mappers.UserMapper.entity as typeof User,
|
|
256
|
+
filter
|
|
257
|
+
);
|
|
246
258
|
}
|
|
247
259
|
|
|
248
260
|
async deleteBatchUsers(
|
|
249
|
-
idsDto: IdsDto & { organization?: { id: string } }
|
|
250
|
-
MapperEntities['UserMapper']
|
|
251
|
-
> &
|
|
252
|
-
object,
|
|
261
|
+
idsDto: IdsDto & { organization?: { id: string } },
|
|
253
262
|
em?: EntityManager
|
|
254
263
|
): Promise<void> {
|
|
255
264
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -260,15 +269,18 @@ export class BaseUserService<
|
|
|
260
269
|
...idsDto,
|
|
261
270
|
id: { $in: idsDto.ids },
|
|
262
271
|
...(idsDto.organization && {
|
|
263
|
-
organization: idsDto.organization
|
|
272
|
+
organization: idsDto.organization.id
|
|
264
273
|
})
|
|
265
274
|
};
|
|
266
275
|
|
|
267
|
-
await (em ?? this.em).nativeDelete(
|
|
276
|
+
await (em ?? this.em).nativeDelete(
|
|
277
|
+
this.mappers.UserMapper.entity as typeof User,
|
|
278
|
+
filter
|
|
279
|
+
);
|
|
268
280
|
}
|
|
269
281
|
|
|
270
282
|
async surfaceRoles(
|
|
271
|
-
idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
283
|
+
idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>,
|
|
272
284
|
em?: EntityManager
|
|
273
285
|
): Promise<MapperDomains['UserMapper']['roles']> {
|
|
274
286
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -281,7 +293,7 @@ export class BaseUserService<
|
|
|
281
293
|
}
|
|
282
294
|
|
|
283
295
|
async surfacePermissions(
|
|
284
|
-
idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
296
|
+
idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>,
|
|
285
297
|
em?: EntityManager
|
|
286
298
|
): Promise<MapperDomains['UserMapper']['roles'][0]['permissions']> {
|
|
287
299
|
if (this.evaluatedTelemetryOptions.logging) {
|
package/lib/services/index.d.mts
CHANGED
|
@@ -5,9 +5,8 @@ export * from '@forklaunch/interfaces-iam/interfaces';
|
|
|
5
5
|
import { CreateOrganizationDto, UpdateOrganizationDto, CreatePermissionDto, UpdatePermissionDto, CreateRoleDto, RoleDto, UpdateRoleDto, CreateUserDto, UpdateUserDto } from '@forklaunch/interfaces-iam/types';
|
|
6
6
|
export * from '@forklaunch/interfaces-iam/types';
|
|
7
7
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
8
|
-
import { EntityManager, FilterQuery } from '@mikro-orm/core';
|
|
8
|
+
import { EntityManager, FilterQuery, InferEntity } from '@mikro-orm/core';
|
|
9
9
|
import { OrganizationEntities, OrganizationDtos, OrganizationMappers, PermissionEntities, PermissionDtos, PermissionMappers, RoleEntities, RoleDtos, RoleMappers, UserEntities, UserDtos, UserMappers } from '../domain/types/index.mjs';
|
|
10
|
-
import '@forklaunch/core/services';
|
|
11
10
|
|
|
12
11
|
declare class BaseOrganizationService<SchemaValidator extends AnySchemaValidator, OrganizationStatus = unknown, MapperEntities extends OrganizationEntities<OrganizationStatus> = OrganizationEntities<OrganizationStatus>, MapperDomains extends OrganizationDtos<OrganizationStatus> = OrganizationDtos<OrganizationStatus>> implements OrganizationService<OrganizationStatus> {
|
|
13
12
|
private evaluatedTelemetryOptions;
|
|
@@ -19,9 +18,9 @@ declare class BaseOrganizationService<SchemaValidator extends AnySchemaValidator
|
|
|
19
18
|
telemetry?: TelemetryOptions;
|
|
20
19
|
});
|
|
21
20
|
createOrganization(organizationDto: CreateOrganizationDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['OrganizationMapper']>;
|
|
22
|
-
getOrganization(idDto: IdDto
|
|
21
|
+
getOrganization(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['OrganizationMapper']>>, em?: EntityManager): Promise<MapperDomains['OrganizationMapper']>;
|
|
23
22
|
updateOrganization(organizationDto: UpdateOrganizationDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['OrganizationMapper']>;
|
|
24
|
-
deleteOrganization(idDto: IdDto
|
|
23
|
+
deleteOrganization(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['OrganizationMapper']>>, em?: EntityManager): Promise<void>;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
declare class BasePermissionService<SchemaValidator extends AnySchemaValidator, MapperEntities extends PermissionEntities = PermissionEntities, MapperDomains extends PermissionDtos = PermissionDtos> implements PermissionService {
|
|
@@ -83,22 +82,22 @@ declare class BaseUserService<SchemaValidator extends AnySchemaValidator, Organi
|
|
|
83
82
|
createUser(userDto: CreateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
|
|
84
83
|
createBatchUsers(userDtos: CreateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
|
|
85
84
|
getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string | undefined>;
|
|
86
|
-
getUser(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
87
|
-
getBatchUsers(idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']
|
|
85
|
+
getUser(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']>;
|
|
86
|
+
getBatchUsers(idsDto: IdsDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
|
|
88
87
|
updateUser(userDto: UpdateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
|
|
89
88
|
updateBatchUsers(userDtos: UpdateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
|
|
90
89
|
deleteUser(idDto: IdDto & {
|
|
91
90
|
organization?: {
|
|
92
91
|
id: string;
|
|
93
92
|
};
|
|
94
|
-
}
|
|
93
|
+
}, em?: EntityManager): Promise<void>;
|
|
95
94
|
deleteBatchUsers(idsDto: IdsDto & {
|
|
96
95
|
organization?: {
|
|
97
96
|
id: string;
|
|
98
97
|
};
|
|
99
|
-
}
|
|
100
|
-
surfaceRoles(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
101
|
-
surfacePermissions(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
98
|
+
}, em?: EntityManager): Promise<void>;
|
|
99
|
+
surfaceRoles(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles']>;
|
|
100
|
+
surfacePermissions(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles'][0]['permissions']>;
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
export { BaseOrganizationService, BasePermissionService, BaseRoleService, BaseUserService };
|
package/lib/services/index.d.ts
CHANGED
|
@@ -5,9 +5,8 @@ export * from '@forklaunch/interfaces-iam/interfaces';
|
|
|
5
5
|
import { CreateOrganizationDto, UpdateOrganizationDto, CreatePermissionDto, UpdatePermissionDto, CreateRoleDto, RoleDto, UpdateRoleDto, CreateUserDto, UpdateUserDto } from '@forklaunch/interfaces-iam/types';
|
|
6
6
|
export * from '@forklaunch/interfaces-iam/types';
|
|
7
7
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
8
|
-
import { EntityManager, FilterQuery } from '@mikro-orm/core';
|
|
8
|
+
import { EntityManager, FilterQuery, InferEntity } from '@mikro-orm/core';
|
|
9
9
|
import { OrganizationEntities, OrganizationDtos, OrganizationMappers, PermissionEntities, PermissionDtos, PermissionMappers, RoleEntities, RoleDtos, RoleMappers, UserEntities, UserDtos, UserMappers } from '../domain/types/index.js';
|
|
10
|
-
import '@forklaunch/core/services';
|
|
11
10
|
|
|
12
11
|
declare class BaseOrganizationService<SchemaValidator extends AnySchemaValidator, OrganizationStatus = unknown, MapperEntities extends OrganizationEntities<OrganizationStatus> = OrganizationEntities<OrganizationStatus>, MapperDomains extends OrganizationDtos<OrganizationStatus> = OrganizationDtos<OrganizationStatus>> implements OrganizationService<OrganizationStatus> {
|
|
13
12
|
private evaluatedTelemetryOptions;
|
|
@@ -19,9 +18,9 @@ declare class BaseOrganizationService<SchemaValidator extends AnySchemaValidator
|
|
|
19
18
|
telemetry?: TelemetryOptions;
|
|
20
19
|
});
|
|
21
20
|
createOrganization(organizationDto: CreateOrganizationDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['OrganizationMapper']>;
|
|
22
|
-
getOrganization(idDto: IdDto
|
|
21
|
+
getOrganization(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['OrganizationMapper']>>, em?: EntityManager): Promise<MapperDomains['OrganizationMapper']>;
|
|
23
22
|
updateOrganization(organizationDto: UpdateOrganizationDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['OrganizationMapper']>;
|
|
24
|
-
deleteOrganization(idDto: IdDto
|
|
23
|
+
deleteOrganization(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['OrganizationMapper']>>, em?: EntityManager): Promise<void>;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
declare class BasePermissionService<SchemaValidator extends AnySchemaValidator, MapperEntities extends PermissionEntities = PermissionEntities, MapperDomains extends PermissionDtos = PermissionDtos> implements PermissionService {
|
|
@@ -83,22 +82,22 @@ declare class BaseUserService<SchemaValidator extends AnySchemaValidator, Organi
|
|
|
83
82
|
createUser(userDto: CreateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
|
|
84
83
|
createBatchUsers(userDtos: CreateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
|
|
85
84
|
getOrganizationIdByUserId(idDto: IdDto, em?: EntityManager): Promise<string | undefined>;
|
|
86
|
-
getUser(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
87
|
-
getBatchUsers(idsDto: IdsDto & FilterQuery<MapperEntities['UserMapper']
|
|
85
|
+
getUser(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']>;
|
|
86
|
+
getBatchUsers(idsDto: IdsDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper'][]>;
|
|
88
87
|
updateUser(userDto: UpdateUserDto, em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper']>;
|
|
89
88
|
updateBatchUsers(userDtos: UpdateUserDto[], em?: EntityManager, ...args: unknown[]): Promise<MapperDomains['UserMapper'][]>;
|
|
90
89
|
deleteUser(idDto: IdDto & {
|
|
91
90
|
organization?: {
|
|
92
91
|
id: string;
|
|
93
92
|
};
|
|
94
|
-
}
|
|
93
|
+
}, em?: EntityManager): Promise<void>;
|
|
95
94
|
deleteBatchUsers(idsDto: IdsDto & {
|
|
96
95
|
organization?: {
|
|
97
96
|
id: string;
|
|
98
97
|
};
|
|
99
|
-
}
|
|
100
|
-
surfaceRoles(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
101
|
-
surfacePermissions(idDto: IdDto & FilterQuery<MapperEntities['UserMapper']
|
|
98
|
+
}, em?: EntityManager): Promise<void>;
|
|
99
|
+
surfaceRoles(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles']>;
|
|
100
|
+
surfacePermissions(idDto: IdDto & FilterQuery<InferEntity<MapperEntities['UserMapper']>>, em?: EntityManager): Promise<MapperDomains['UserMapper']['roles'][0]['permissions']>;
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
export { BaseOrganizationService, BasePermissionService, BaseRoleService, BaseUserService };
|