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