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