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