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