@forklaunch/implementation-iam-base 0.6.3 → 0.6.4
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 +733 -334
- package/lib/domain/schemas/index.d.ts +733 -334
- package/lib/domain/schemas/index.js +90 -58
- package/lib/domain/schemas/index.mjs +40 -36
- package/lib/domain/types/index.d.mts +166 -71
- package/lib/domain/types/index.d.ts +166 -71
- package/lib/domain/types/index.js +8 -4
- package/lib/eject/services/user.service.ts +16 -30
- package/lib/services/index.d.mts +250 -81
- package/lib/services/index.d.ts +250 -81
- package/lib/services/index.js +192 -171
- package/lib/services/index.mjs +177 -169
- package/package.json +8 -8
package/lib/services/index.mjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// services/organization.service.ts
|
|
2
|
-
import {
|
|
3
|
-
evaluateTelemetryOptions
|
|
4
|
-
} from "@forklaunch/core/http";
|
|
2
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
5
3
|
var BaseOrganizationService = class {
|
|
6
4
|
// protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
7
5
|
evaluatedTelemetryOptions;
|
|
@@ -14,16 +12,18 @@ var BaseOrganizationService = class {
|
|
|
14
12
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
15
13
|
this.schemaValidator = schemaValidator;
|
|
16
14
|
this.mappers = mappers;
|
|
17
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
16
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
17
|
+
: {
|
|
18
|
+
logging: false,
|
|
19
|
+
metrics: false,
|
|
20
|
+
tracing: false
|
|
21
|
+
};
|
|
22
22
|
}
|
|
23
23
|
async createOrganization(organizationDto, em, ...args) {
|
|
24
24
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
25
25
|
this.openTelemetryCollector.info(
|
|
26
|
-
|
|
26
|
+
'Creating organization',
|
|
27
27
|
organizationDto
|
|
28
28
|
);
|
|
29
29
|
}
|
|
@@ -41,31 +41,30 @@ var BaseOrganizationService = class {
|
|
|
41
41
|
}
|
|
42
42
|
async getOrganization(idDto, em) {
|
|
43
43
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
44
|
-
this.openTelemetryCollector.info(
|
|
44
|
+
this.openTelemetryCollector.info('Getting organization', idDto);
|
|
45
45
|
}
|
|
46
46
|
const organization = await (em ?? this.em).findOneOrFail(
|
|
47
|
-
|
|
47
|
+
'Organization',
|
|
48
48
|
idDto,
|
|
49
49
|
{
|
|
50
|
-
populate: [
|
|
50
|
+
populate: ['id', '*']
|
|
51
51
|
}
|
|
52
52
|
);
|
|
53
|
-
return this.mappers.OrganizationMapper.toDto(
|
|
54
|
-
organization
|
|
55
|
-
);
|
|
53
|
+
return this.mappers.OrganizationMapper.toDto(organization);
|
|
56
54
|
}
|
|
57
55
|
async updateOrganization(organizationDto, em, ...args) {
|
|
58
56
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
59
57
|
this.openTelemetryCollector.info(
|
|
60
|
-
|
|
58
|
+
'Updating organization',
|
|
61
59
|
organizationDto
|
|
62
60
|
);
|
|
63
61
|
}
|
|
64
|
-
const updatedOrganization =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const updatedOrganization =
|
|
63
|
+
await this.mappers.UpdateOrganizationMapper.toEntity(
|
|
64
|
+
organizationDto,
|
|
65
|
+
em ?? this.em,
|
|
66
|
+
...args
|
|
67
|
+
);
|
|
69
68
|
if (em) {
|
|
70
69
|
await em.persist(updatedOrganization);
|
|
71
70
|
} else {
|
|
@@ -75,20 +74,18 @@ var BaseOrganizationService = class {
|
|
|
75
74
|
}
|
|
76
75
|
async deleteOrganization(idDto, em) {
|
|
77
76
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
78
|
-
this.openTelemetryCollector.info(
|
|
77
|
+
this.openTelemetryCollector.info('Deleting organization', idDto);
|
|
79
78
|
}
|
|
80
79
|
if (em) {
|
|
81
|
-
await em.nativeDelete(
|
|
80
|
+
await em.nativeDelete('Organization', idDto);
|
|
82
81
|
} else {
|
|
83
|
-
await this.em.nativeDelete(
|
|
82
|
+
await this.em.nativeDelete('Organization', idDto);
|
|
84
83
|
}
|
|
85
84
|
}
|
|
86
85
|
};
|
|
87
86
|
|
|
88
87
|
// services/permission.service.ts
|
|
89
|
-
import {
|
|
90
|
-
evaluateTelemetryOptions as evaluateTelemetryOptions2
|
|
91
|
-
} from "@forklaunch/core/http";
|
|
88
|
+
import { evaluateTelemetryOptions as evaluateTelemetryOptions2 } from '@forklaunch/core/http';
|
|
92
89
|
var BasePermissionService = class {
|
|
93
90
|
evaluatedTelemetryOptions;
|
|
94
91
|
em;
|
|
@@ -96,17 +93,26 @@ var BasePermissionService = class {
|
|
|
96
93
|
openTelemetryCollector;
|
|
97
94
|
schemaValidator;
|
|
98
95
|
mappers;
|
|
99
|
-
constructor(
|
|
96
|
+
constructor(
|
|
97
|
+
em,
|
|
98
|
+
roleServiceFactory,
|
|
99
|
+
openTelemetryCollector,
|
|
100
|
+
schemaValidator,
|
|
101
|
+
mappers,
|
|
102
|
+
options
|
|
103
|
+
) {
|
|
100
104
|
this.em = em;
|
|
101
105
|
this.roleServiceFactory = roleServiceFactory;
|
|
102
106
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
103
107
|
this.schemaValidator = schemaValidator;
|
|
104
108
|
this.mappers = mappers;
|
|
105
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
110
|
+
? evaluateTelemetryOptions2(options.telemetry).enabled
|
|
111
|
+
: {
|
|
112
|
+
logging: false,
|
|
113
|
+
metrics: false,
|
|
114
|
+
tracing: false
|
|
115
|
+
};
|
|
110
116
|
}
|
|
111
117
|
// start: global helper functions
|
|
112
118
|
async updateRolesWithPermissions(roles, permissions) {
|
|
@@ -120,33 +126,32 @@ var BasePermissionService = class {
|
|
|
120
126
|
async removePermissionsFromRoles(roles, permissions) {
|
|
121
127
|
return Promise.all(
|
|
122
128
|
roles.map(async (role) => {
|
|
123
|
-
permissions.forEach(
|
|
124
|
-
|
|
129
|
+
permissions.forEach((permission) =>
|
|
130
|
+
role.permissions.remove(permission)
|
|
125
131
|
);
|
|
126
132
|
return role;
|
|
127
133
|
})
|
|
128
134
|
);
|
|
129
135
|
}
|
|
130
136
|
async getBatchRoles(roles, em) {
|
|
131
|
-
return roles
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
return roles
|
|
138
|
+
? await Promise.all(
|
|
139
|
+
(await this.roleServiceFactory().getBatchRoles(roles, em)).map(
|
|
140
|
+
async (role) => {
|
|
141
|
+
return (em ?? this.em).merge(
|
|
142
|
+
await this.mappers.RoleEntityMapper.toEntity(
|
|
143
|
+
role,
|
|
144
|
+
em ?? this.em
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
: [];
|
|
143
151
|
}
|
|
144
152
|
// end: global helper functions
|
|
145
153
|
// start: createPermission helper functions
|
|
146
|
-
async createPermissionEntity({
|
|
147
|
-
permission,
|
|
148
|
-
addToRoles
|
|
149
|
-
}) {
|
|
154
|
+
async createPermissionEntity({ permission, addToRoles }) {
|
|
150
155
|
let roles = [];
|
|
151
156
|
if (addToRoles) {
|
|
152
157
|
roles = await this.updateRolesWithPermissions(addToRoles, [permission]);
|
|
@@ -162,14 +167,16 @@ var BasePermissionService = class {
|
|
|
162
167
|
...args
|
|
163
168
|
)
|
|
164
169
|
),
|
|
165
|
-
addToRoles: permissionDto.addToRolesIds
|
|
170
|
+
addToRoles: permissionDto.addToRolesIds
|
|
171
|
+
? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em)
|
|
172
|
+
: []
|
|
166
173
|
};
|
|
167
174
|
}
|
|
168
175
|
// end: createPermission helper functions
|
|
169
176
|
async createPermission(createPermissionEntity, em, ...args) {
|
|
170
177
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
171
178
|
this.openTelemetryCollector.info(
|
|
172
|
-
|
|
179
|
+
'Creating permission',
|
|
173
180
|
createPermissionEntity
|
|
174
181
|
);
|
|
175
182
|
}
|
|
@@ -190,7 +197,7 @@ var BasePermissionService = class {
|
|
|
190
197
|
async createBatchPermissions(permissionDtos, em) {
|
|
191
198
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
192
199
|
this.openTelemetryCollector.info(
|
|
193
|
-
|
|
200
|
+
'Creating batch permissions',
|
|
194
201
|
permissionDtos
|
|
195
202
|
);
|
|
196
203
|
}
|
|
@@ -218,7 +225,10 @@ var BasePermissionService = class {
|
|
|
218
225
|
})
|
|
219
226
|
);
|
|
220
227
|
roles.forEach((role) => {
|
|
221
|
-
if (
|
|
228
|
+
if (
|
|
229
|
+
rolesCache[role.id] &&
|
|
230
|
+
role.permissions !== rolesCache[role.id].permissions
|
|
231
|
+
) {
|
|
222
232
|
role.permissions.getItems().forEach((permission2) => {
|
|
223
233
|
if (!rolesCache[role.id].permissions.contains(permission2)) {
|
|
224
234
|
rolesCache[role.id].permissions.add(permission2);
|
|
@@ -237,29 +247,25 @@ var BasePermissionService = class {
|
|
|
237
247
|
await this.em.persistAndFlush(entities);
|
|
238
248
|
}
|
|
239
249
|
return Promise.all(
|
|
240
|
-
permissions.map(
|
|
241
|
-
|
|
250
|
+
permissions.map(async (permission) =>
|
|
251
|
+
this.mappers.PermissionMapper.toDto(permission)
|
|
242
252
|
)
|
|
243
253
|
);
|
|
244
254
|
}
|
|
245
255
|
async getPermission(idDto, em) {
|
|
246
256
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
247
|
-
this.openTelemetryCollector.info(
|
|
257
|
+
this.openTelemetryCollector.info('Getting permission', idDto);
|
|
248
258
|
}
|
|
249
|
-
const permission = await (em ?? this.em).findOneOrFail(
|
|
250
|
-
return this.mappers.PermissionMapper.toDto(
|
|
251
|
-
permission
|
|
252
|
-
);
|
|
259
|
+
const permission = await (em ?? this.em).findOneOrFail('Permission', idDto);
|
|
260
|
+
return this.mappers.PermissionMapper.toDto(permission);
|
|
253
261
|
}
|
|
254
262
|
async getBatchPermissions(idsDto, em) {
|
|
255
263
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
256
|
-
this.openTelemetryCollector.info(
|
|
264
|
+
this.openTelemetryCollector.info('Getting batch permissions', idsDto);
|
|
257
265
|
}
|
|
258
266
|
return Promise.all(
|
|
259
|
-
(await (em ?? this.em).find(
|
|
260
|
-
|
|
261
|
-
permission
|
|
262
|
-
)
|
|
267
|
+
(await (em ?? this.em).find('Permission', idsDto)).map((permission) =>
|
|
268
|
+
this.mappers.PermissionMapper.toDto(permission)
|
|
263
269
|
)
|
|
264
270
|
);
|
|
265
271
|
}
|
|
@@ -270,8 +276,12 @@ var BasePermissionService = class {
|
|
|
270
276
|
em ?? this.em,
|
|
271
277
|
...args
|
|
272
278
|
);
|
|
273
|
-
const addToRoles = permissionDto.addToRolesIds
|
|
274
|
-
|
|
279
|
+
const addToRoles = permissionDto.addToRolesIds
|
|
280
|
+
? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em)
|
|
281
|
+
: [];
|
|
282
|
+
const removeFromRoles = permissionDto.removeFromRolesIds
|
|
283
|
+
? await this.getBatchRoles({ ids: permissionDto.removeFromRolesIds }, em)
|
|
284
|
+
: [];
|
|
275
285
|
let roles = [];
|
|
276
286
|
roles = roles.concat(
|
|
277
287
|
await this.updateRolesWithPermissions(addToRoles, [permission])
|
|
@@ -287,7 +297,7 @@ var BasePermissionService = class {
|
|
|
287
297
|
// end: updatePermission helper functions
|
|
288
298
|
async updatePermission(permissionDto, em) {
|
|
289
299
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
290
|
-
this.openTelemetryCollector.info(
|
|
300
|
+
this.openTelemetryCollector.info('Updating permission', permissionDto);
|
|
291
301
|
}
|
|
292
302
|
const { permission, roles } = await this.updatePermissionDto(permissionDto);
|
|
293
303
|
const entities = await (em ?? this.em).upsertMany([permission, ...roles]);
|
|
@@ -301,7 +311,7 @@ var BasePermissionService = class {
|
|
|
301
311
|
async updateBatchPermissions(permissionDtos, em) {
|
|
302
312
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
303
313
|
this.openTelemetryCollector.info(
|
|
304
|
-
|
|
314
|
+
'Updating batch permissions',
|
|
305
315
|
permissionDtos
|
|
306
316
|
);
|
|
307
317
|
}
|
|
@@ -309,9 +319,13 @@ var BasePermissionService = class {
|
|
|
309
319
|
const permissions = [];
|
|
310
320
|
await (em ?? this.em).transactional(async (em2) => {
|
|
311
321
|
permissionDtos.map(async (updatePermissionDto) => {
|
|
312
|
-
const { permission, roles } =
|
|
322
|
+
const { permission, roles } =
|
|
323
|
+
await this.updatePermissionDto(updatePermissionDto);
|
|
313
324
|
roles.forEach((role) => {
|
|
314
|
-
if (
|
|
325
|
+
if (
|
|
326
|
+
rolesCache[role.id] &&
|
|
327
|
+
role.permissions !== rolesCache[role.id].permissions
|
|
328
|
+
) {
|
|
315
329
|
role.permissions.getItems().forEach((permission2) => {
|
|
316
330
|
if (!rolesCache[role.id].permissions.contains(permission2)) {
|
|
317
331
|
rolesCache[role.id].permissions.add(permission2);
|
|
@@ -331,31 +345,29 @@ var BasePermissionService = class {
|
|
|
331
345
|
}
|
|
332
346
|
});
|
|
333
347
|
return Promise.all(
|
|
334
|
-
permissions.map(
|
|
335
|
-
|
|
348
|
+
permissions.map((permission) =>
|
|
349
|
+
this.mappers.PermissionMapper.toDto(permission)
|
|
336
350
|
)
|
|
337
351
|
);
|
|
338
352
|
}
|
|
339
353
|
async deletePermission(idDto, em) {
|
|
340
354
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
341
|
-
this.openTelemetryCollector.info(
|
|
355
|
+
this.openTelemetryCollector.info('Deleting permission', idDto);
|
|
342
356
|
}
|
|
343
|
-
await (em ?? this.em).nativeDelete(
|
|
357
|
+
await (em ?? this.em).nativeDelete('Permission', idDto);
|
|
344
358
|
}
|
|
345
359
|
async deleteBatchPermissions(idsDto, em) {
|
|
346
360
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
347
|
-
this.openTelemetryCollector.info(
|
|
361
|
+
this.openTelemetryCollector.info('Deleting batch permissions', idsDto);
|
|
348
362
|
}
|
|
349
|
-
await (em ?? this.em).nativeDelete(
|
|
363
|
+
await (em ?? this.em).nativeDelete('Permission', {
|
|
350
364
|
id: { $in: idsDto.ids }
|
|
351
365
|
});
|
|
352
366
|
}
|
|
353
367
|
};
|
|
354
368
|
|
|
355
369
|
// services/role.service.ts
|
|
356
|
-
import {
|
|
357
|
-
evaluateTelemetryOptions as evaluateTelemetryOptions3
|
|
358
|
-
} from "@forklaunch/core/http";
|
|
370
|
+
import { evaluateTelemetryOptions as evaluateTelemetryOptions3 } from '@forklaunch/core/http';
|
|
359
371
|
var BaseRoleService = class {
|
|
360
372
|
evaluatedTelemetryOptions;
|
|
361
373
|
em;
|
|
@@ -367,15 +379,17 @@ var BaseRoleService = class {
|
|
|
367
379
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
368
380
|
this.schemaValidator = schemaValidator;
|
|
369
381
|
this.mappers = mappers;
|
|
370
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
382
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
383
|
+
? evaluateTelemetryOptions3(options.telemetry).enabled
|
|
384
|
+
: {
|
|
385
|
+
logging: false,
|
|
386
|
+
metrics: false,
|
|
387
|
+
tracing: false
|
|
388
|
+
};
|
|
375
389
|
}
|
|
376
390
|
async createRole(roleDto, em, ...args) {
|
|
377
391
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
378
|
-
this.openTelemetryCollector.info(
|
|
392
|
+
this.openTelemetryCollector.info('Creating role', roleDto);
|
|
379
393
|
}
|
|
380
394
|
const role = await this.mappers.CreateRoleMapper.toEntity(
|
|
381
395
|
roleDto,
|
|
@@ -391,11 +405,11 @@ var BaseRoleService = class {
|
|
|
391
405
|
}
|
|
392
406
|
async createBatchRoles(roleDtos, em, ...args) {
|
|
393
407
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
394
|
-
this.openTelemetryCollector.info(
|
|
408
|
+
this.openTelemetryCollector.info('Creating batch roles', roleDtos);
|
|
395
409
|
}
|
|
396
410
|
const roles = await Promise.all(
|
|
397
|
-
roleDtos.map(
|
|
398
|
-
|
|
411
|
+
roleDtos.map(async (roleDto) =>
|
|
412
|
+
this.mappers.CreateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
399
413
|
)
|
|
400
414
|
);
|
|
401
415
|
if (em) {
|
|
@@ -409,34 +423,34 @@ var BaseRoleService = class {
|
|
|
409
423
|
}
|
|
410
424
|
async getRole({ id }, em) {
|
|
411
425
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
412
|
-
this.openTelemetryCollector.info(
|
|
426
|
+
this.openTelemetryCollector.info('Getting role', { id });
|
|
413
427
|
}
|
|
414
|
-
const role = await (em ?? this.em).findOneOrFail(
|
|
415
|
-
populate: [
|
|
428
|
+
const role = await (em ?? this.em).findOneOrFail('Role', id, {
|
|
429
|
+
populate: ['id', '*']
|
|
416
430
|
});
|
|
417
431
|
return this.mappers.RoleMapper.toDto(role);
|
|
418
432
|
}
|
|
419
433
|
async getBatchRoles({ ids }, em) {
|
|
420
434
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
421
|
-
this.openTelemetryCollector.info(
|
|
435
|
+
this.openTelemetryCollector.info('Getting batch roles', { ids });
|
|
422
436
|
}
|
|
423
437
|
return Promise.all(
|
|
424
|
-
(
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
)
|
|
438
|
+
(
|
|
439
|
+
await (em ?? this.em).find(
|
|
440
|
+
'Role',
|
|
441
|
+
{
|
|
442
|
+
id: { $in: ids }
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
populate: ['id', '*']
|
|
446
|
+
}
|
|
447
|
+
)
|
|
448
|
+
).map((role) => this.mappers.RoleMapper.toDto(role))
|
|
435
449
|
);
|
|
436
450
|
}
|
|
437
451
|
async updateRole(roleDto, em, ...args) {
|
|
438
452
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
439
|
-
this.openTelemetryCollector.info(
|
|
453
|
+
this.openTelemetryCollector.info('Updating role', roleDto);
|
|
440
454
|
}
|
|
441
455
|
const role = await this.mappers.UpdateRoleMapper.toEntity(
|
|
442
456
|
roleDto,
|
|
@@ -452,11 +466,11 @@ var BaseRoleService = class {
|
|
|
452
466
|
}
|
|
453
467
|
async updateBatchRoles(roleDtos, em, ...args) {
|
|
454
468
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
455
|
-
this.openTelemetryCollector.info(
|
|
469
|
+
this.openTelemetryCollector.info('Updating batch roles', roleDtos);
|
|
456
470
|
}
|
|
457
471
|
const roles = await Promise.all(
|
|
458
|
-
roleDtos.map(
|
|
459
|
-
|
|
472
|
+
roleDtos.map(async (roleDto) =>
|
|
473
|
+
this.mappers.UpdateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
460
474
|
)
|
|
461
475
|
);
|
|
462
476
|
if (em) {
|
|
@@ -465,55 +479,59 @@ var BaseRoleService = class {
|
|
|
465
479
|
await this.em.persistAndFlush(roles);
|
|
466
480
|
}
|
|
467
481
|
return Promise.all(
|
|
468
|
-
roles.map(
|
|
469
|
-
(role) => this.mappers.RoleMapper.toDto(role)
|
|
470
|
-
)
|
|
482
|
+
roles.map((role) => this.mappers.RoleMapper.toDto(role))
|
|
471
483
|
);
|
|
472
484
|
}
|
|
473
485
|
async deleteRole(idDto, em) {
|
|
474
486
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
475
|
-
this.openTelemetryCollector.info(
|
|
487
|
+
this.openTelemetryCollector.info('Deleting role', idDto);
|
|
476
488
|
}
|
|
477
|
-
await (em ?? this.em).nativeDelete(
|
|
489
|
+
await (em ?? this.em).nativeDelete('Role', idDto);
|
|
478
490
|
}
|
|
479
491
|
async deleteBatchRoles(idsDto, em) {
|
|
480
492
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
481
|
-
this.openTelemetryCollector.info(
|
|
493
|
+
this.openTelemetryCollector.info('Deleting batch roles', idsDto);
|
|
482
494
|
}
|
|
483
|
-
await (em ?? this.em).nativeDelete(
|
|
495
|
+
await (em ?? this.em).nativeDelete('Role', { id: { $in: idsDto.ids } });
|
|
484
496
|
}
|
|
485
497
|
};
|
|
486
498
|
|
|
487
499
|
// services/user.service.ts
|
|
488
|
-
import {
|
|
489
|
-
evaluateTelemetryOptions as evaluateTelemetryOptions4
|
|
490
|
-
} from "@forklaunch/core/http";
|
|
500
|
+
import { evaluateTelemetryOptions as evaluateTelemetryOptions4 } from '@forklaunch/core/http';
|
|
491
501
|
var BaseUserService = class {
|
|
492
502
|
evaluatedTelemetryOptions;
|
|
493
503
|
em;
|
|
494
|
-
passwordEncryptionPublicKeyPath;
|
|
495
504
|
roleServiceFactory;
|
|
496
505
|
organizationServiceFactory;
|
|
497
506
|
openTelemetryCollector;
|
|
498
507
|
schemaValidator;
|
|
499
508
|
mappers;
|
|
500
|
-
constructor(
|
|
509
|
+
constructor(
|
|
510
|
+
em,
|
|
511
|
+
roleServiceFactory,
|
|
512
|
+
organizationServiceFactory,
|
|
513
|
+
openTelemetryCollector,
|
|
514
|
+
schemaValidator,
|
|
515
|
+
mappers,
|
|
516
|
+
options
|
|
517
|
+
) {
|
|
501
518
|
this.em = em;
|
|
502
|
-
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
503
519
|
this.roleServiceFactory = roleServiceFactory;
|
|
504
520
|
this.organizationServiceFactory = organizationServiceFactory;
|
|
505
521
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
506
522
|
this.schemaValidator = schemaValidator;
|
|
507
523
|
this.mappers = mappers;
|
|
508
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
524
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
525
|
+
? evaluateTelemetryOptions4(options.telemetry).enabled
|
|
526
|
+
: {
|
|
527
|
+
logging: false,
|
|
528
|
+
metrics: false,
|
|
529
|
+
tracing: false
|
|
530
|
+
};
|
|
513
531
|
}
|
|
514
532
|
async createUser(userDto, em, ...args) {
|
|
515
533
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
516
|
-
this.openTelemetryCollector.info(
|
|
534
|
+
this.openTelemetryCollector.info('Creating user', userDto);
|
|
517
535
|
}
|
|
518
536
|
const user = await this.mappers.CreateUserMapper.toEntity(
|
|
519
537
|
userDto,
|
|
@@ -529,11 +547,11 @@ var BaseUserService = class {
|
|
|
529
547
|
}
|
|
530
548
|
async createBatchUsers(userDtos, em, ...args) {
|
|
531
549
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
532
|
-
this.openTelemetryCollector.info(
|
|
550
|
+
this.openTelemetryCollector.info('Creating batch users', userDtos);
|
|
533
551
|
}
|
|
534
552
|
const users = await Promise.all(
|
|
535
|
-
userDtos.map(
|
|
536
|
-
|
|
553
|
+
userDtos.map(async (createUserDto) =>
|
|
554
|
+
this.mappers.CreateUserMapper.toEntity(
|
|
537
555
|
createUserDto,
|
|
538
556
|
em ?? this.em,
|
|
539
557
|
...args
|
|
@@ -551,28 +569,28 @@ var BaseUserService = class {
|
|
|
551
569
|
}
|
|
552
570
|
async getUser(idDto, em) {
|
|
553
571
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
554
|
-
this.openTelemetryCollector.info(
|
|
572
|
+
this.openTelemetryCollector.info('Getting user', idDto);
|
|
555
573
|
}
|
|
556
|
-
const user = await (em ?? this.em).findOneOrFail(
|
|
557
|
-
populate: [
|
|
574
|
+
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
575
|
+
populate: ['id', '*']
|
|
558
576
|
});
|
|
559
577
|
return this.mappers.UserMapper.toDto(user);
|
|
560
578
|
}
|
|
561
579
|
async getBatchUsers(idsDto, em) {
|
|
562
580
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
563
|
-
this.openTelemetryCollector.info(
|
|
581
|
+
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
564
582
|
}
|
|
565
583
|
return Promise.all(
|
|
566
|
-
(
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
)
|
|
584
|
+
(
|
|
585
|
+
await (em ?? this.em).find('User', idsDto, {
|
|
586
|
+
populate: ['id', '*']
|
|
587
|
+
})
|
|
588
|
+
).map((user) => this.mappers.UserMapper.toDto(user))
|
|
571
589
|
);
|
|
572
590
|
}
|
|
573
591
|
async updateUser(userDto, em, ...args) {
|
|
574
592
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
575
|
-
this.openTelemetryCollector.info(
|
|
593
|
+
this.openTelemetryCollector.info('Updating user', userDto);
|
|
576
594
|
}
|
|
577
595
|
const user = await this.mappers.UpdateUserMapper.toEntity(
|
|
578
596
|
userDto,
|
|
@@ -588,11 +606,11 @@ var BaseUserService = class {
|
|
|
588
606
|
}
|
|
589
607
|
async updateBatchUsers(userDtos, em, ...args) {
|
|
590
608
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
591
|
-
this.openTelemetryCollector.info(
|
|
609
|
+
this.openTelemetryCollector.info('Updating batch users', userDtos);
|
|
592
610
|
}
|
|
593
611
|
const users = await Promise.all(
|
|
594
|
-
userDtos.map(
|
|
595
|
-
|
|
612
|
+
userDtos.map(async (updateUserDto) =>
|
|
613
|
+
this.mappers.UpdateUserMapper.toEntity(
|
|
596
614
|
updateUserDto,
|
|
597
615
|
em ?? this.em,
|
|
598
616
|
...args
|
|
@@ -610,43 +628,33 @@ var BaseUserService = class {
|
|
|
610
628
|
}
|
|
611
629
|
async deleteUser(idDto, em) {
|
|
612
630
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
613
|
-
this.openTelemetryCollector.info(
|
|
631
|
+
this.openTelemetryCollector.info('Deleting user', idDto);
|
|
614
632
|
}
|
|
615
|
-
await (em ?? this.em).nativeDelete(
|
|
633
|
+
await (em ?? this.em).nativeDelete('User', idDto);
|
|
616
634
|
}
|
|
617
635
|
async deleteBatchUsers(idsDto, em) {
|
|
618
636
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
619
|
-
this.openTelemetryCollector.info(
|
|
637
|
+
this.openTelemetryCollector.info('Deleting batch users', idsDto);
|
|
620
638
|
}
|
|
621
|
-
await (em ?? this.em).nativeDelete(
|
|
639
|
+
await (em ?? this.em).nativeDelete('User', idsDto);
|
|
622
640
|
}
|
|
623
|
-
async
|
|
641
|
+
async surfaceRoles(idDto, em) {
|
|
624
642
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
625
|
-
this.openTelemetryCollector.info(
|
|
626
|
-
idDto
|
|
627
|
-
roleId
|
|
643
|
+
this.openTelemetryCollector.info('Surfacing user roles', {
|
|
644
|
+
idDto
|
|
628
645
|
});
|
|
629
646
|
}
|
|
630
|
-
const user = await this.getUser(idDto);
|
|
631
|
-
|
|
632
|
-
return roleId == role.id;
|
|
633
|
-
}).length === 0) {
|
|
634
|
-
throw new Error(`User ${idDto.id} does not have role ${roleId}`);
|
|
635
|
-
}
|
|
647
|
+
const user = await this.getUser(idDto, em);
|
|
648
|
+
return user.roles;
|
|
636
649
|
}
|
|
637
|
-
async
|
|
650
|
+
async surfacePermissions(idDto, em) {
|
|
638
651
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
639
|
-
this.openTelemetryCollector.info(
|
|
640
|
-
idDto
|
|
641
|
-
permissionId
|
|
652
|
+
this.openTelemetryCollector.info('Surfacing user permissions', {
|
|
653
|
+
idDto
|
|
642
654
|
});
|
|
643
655
|
}
|
|
644
|
-
const user = await this.getUser(idDto);
|
|
645
|
-
|
|
646
|
-
throw new Error(
|
|
647
|
-
`User ${idDto.id} does not have permission ${permissionId}`
|
|
648
|
-
);
|
|
649
|
-
}
|
|
656
|
+
const user = await this.getUser(idDto, em);
|
|
657
|
+
return user.roles.map((role) => role.permissions).flat();
|
|
650
658
|
}
|
|
651
659
|
};
|
|
652
660
|
export {
|