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