@forklaunch/implementation-iam-base 0.6.0 → 0.6.2
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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -8,18 +8,14 @@ var __export = (target, all) => {
|
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
12
|
for (let key of __getOwnPropNames(from))
|
|
13
13
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
15
|
}
|
|
19
16
|
return to;
|
|
20
17
|
};
|
|
21
|
-
var __toCommonJS = (mod) =>
|
|
22
|
-
__copyProps(__defProp({}, '__esModule', { value: true }), mod);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// services/index.ts
|
|
25
21
|
var services_exports = {};
|
|
@@ -32,7 +28,7 @@ __export(services_exports, {
|
|
|
32
28
|
module.exports = __toCommonJS(services_exports);
|
|
33
29
|
|
|
34
30
|
// services/organization.service.ts
|
|
35
|
-
var import_http = require(
|
|
31
|
+
var import_http = require("@forklaunch/core/http");
|
|
36
32
|
var BaseOrganizationService = class {
|
|
37
33
|
// protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
38
34
|
evaluatedTelemetryOptions;
|
|
@@ -45,18 +41,16 @@ var BaseOrganizationService = class {
|
|
|
45
41
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
46
42
|
this.schemaValidator = schemaValidator;
|
|
47
43
|
this.mappers = mappers;
|
|
48
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
49
|
-
|
|
50
|
-
:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
tracing: false
|
|
54
|
-
};
|
|
44
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
45
|
+
logging: false,
|
|
46
|
+
metrics: false,
|
|
47
|
+
tracing: false
|
|
48
|
+
};
|
|
55
49
|
}
|
|
56
50
|
async createOrganization(organizationDto, em, ...args) {
|
|
57
51
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
58
52
|
this.openTelemetryCollector.info(
|
|
59
|
-
|
|
53
|
+
"Creating organization",
|
|
60
54
|
organizationDto
|
|
61
55
|
);
|
|
62
56
|
}
|
|
@@ -74,30 +68,31 @@ var BaseOrganizationService = class {
|
|
|
74
68
|
}
|
|
75
69
|
async getOrganization(idDto, em) {
|
|
76
70
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
77
|
-
this.openTelemetryCollector.info(
|
|
71
|
+
this.openTelemetryCollector.info("Getting organization", idDto);
|
|
78
72
|
}
|
|
79
73
|
const organization = await (em ?? this.em).findOneOrFail(
|
|
80
|
-
|
|
74
|
+
"Organization",
|
|
81
75
|
idDto,
|
|
82
76
|
{
|
|
83
|
-
populate: [
|
|
77
|
+
populate: ["id", "*"]
|
|
84
78
|
}
|
|
85
79
|
);
|
|
86
|
-
return this.mappers.OrganizationMapper.toDto(
|
|
80
|
+
return this.mappers.OrganizationMapper.toDto(
|
|
81
|
+
organization
|
|
82
|
+
);
|
|
87
83
|
}
|
|
88
84
|
async updateOrganization(organizationDto, em, ...args) {
|
|
89
85
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
86
|
this.openTelemetryCollector.info(
|
|
91
|
-
|
|
87
|
+
"Updating organization",
|
|
92
88
|
organizationDto
|
|
93
89
|
);
|
|
94
90
|
}
|
|
95
|
-
const updatedOrganization =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
);
|
|
91
|
+
const updatedOrganization = await this.mappers.UpdateOrganizationMapper.toEntity(
|
|
92
|
+
organizationDto,
|
|
93
|
+
em ?? this.em,
|
|
94
|
+
...args
|
|
95
|
+
);
|
|
101
96
|
if (em) {
|
|
102
97
|
await em.persist(updatedOrganization);
|
|
103
98
|
} else {
|
|
@@ -107,18 +102,18 @@ var BaseOrganizationService = class {
|
|
|
107
102
|
}
|
|
108
103
|
async deleteOrganization(idDto, em) {
|
|
109
104
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
110
|
-
this.openTelemetryCollector.info(
|
|
105
|
+
this.openTelemetryCollector.info("Deleting organization", idDto);
|
|
111
106
|
}
|
|
112
107
|
if (em) {
|
|
113
|
-
await em.nativeDelete(
|
|
108
|
+
await em.nativeDelete("Organization", idDto);
|
|
114
109
|
} else {
|
|
115
|
-
await this.em.nativeDelete(
|
|
110
|
+
await this.em.nativeDelete("Organization", idDto);
|
|
116
111
|
}
|
|
117
112
|
}
|
|
118
113
|
};
|
|
119
114
|
|
|
120
115
|
// services/permission.service.ts
|
|
121
|
-
var import_http2 = require(
|
|
116
|
+
var import_http2 = require("@forklaunch/core/http");
|
|
122
117
|
var BasePermissionService = class {
|
|
123
118
|
evaluatedTelemetryOptions;
|
|
124
119
|
em;
|
|
@@ -126,26 +121,17 @@ var BasePermissionService = class {
|
|
|
126
121
|
openTelemetryCollector;
|
|
127
122
|
schemaValidator;
|
|
128
123
|
mappers;
|
|
129
|
-
constructor(
|
|
130
|
-
em,
|
|
131
|
-
roleServiceFactory,
|
|
132
|
-
openTelemetryCollector,
|
|
133
|
-
schemaValidator,
|
|
134
|
-
mappers,
|
|
135
|
-
options
|
|
136
|
-
) {
|
|
124
|
+
constructor(em, roleServiceFactory, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
137
125
|
this.em = em;
|
|
138
126
|
this.roleServiceFactory = roleServiceFactory;
|
|
139
127
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
140
128
|
this.schemaValidator = schemaValidator;
|
|
141
129
|
this.mappers = mappers;
|
|
142
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
143
|
-
|
|
144
|
-
:
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
tracing: false
|
|
148
|
-
};
|
|
130
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http2.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
131
|
+
logging: false,
|
|
132
|
+
metrics: false,
|
|
133
|
+
tracing: false
|
|
134
|
+
};
|
|
149
135
|
}
|
|
150
136
|
// start: global helper functions
|
|
151
137
|
async updateRolesWithPermissions(roles, permissions) {
|
|
@@ -159,32 +145,33 @@ var BasePermissionService = class {
|
|
|
159
145
|
async removePermissionsFromRoles(roles, permissions) {
|
|
160
146
|
return Promise.all(
|
|
161
147
|
roles.map(async (role) => {
|
|
162
|
-
permissions.forEach(
|
|
163
|
-
role.permissions.remove(permission)
|
|
148
|
+
permissions.forEach(
|
|
149
|
+
(permission) => role.permissions.remove(permission)
|
|
164
150
|
);
|
|
165
151
|
return role;
|
|
166
152
|
})
|
|
167
153
|
);
|
|
168
154
|
}
|
|
169
155
|
async getBatchRoles(roles, em) {
|
|
170
|
-
return roles
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
)
|
|
183
|
-
: [];
|
|
156
|
+
return roles ? await Promise.all(
|
|
157
|
+
(await this.roleServiceFactory().getBatchRoles(roles, em)).map(
|
|
158
|
+
async (role) => {
|
|
159
|
+
return (em ?? this.em).merge(
|
|
160
|
+
await this.mappers.RoleEntityMapper.toEntity(
|
|
161
|
+
role,
|
|
162
|
+
em ?? this.em
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
) : [];
|
|
184
168
|
}
|
|
185
169
|
// end: global helper functions
|
|
186
170
|
// start: createPermission helper functions
|
|
187
|
-
async createPermissionEntity({
|
|
171
|
+
async createPermissionEntity({
|
|
172
|
+
permission,
|
|
173
|
+
addToRoles
|
|
174
|
+
}) {
|
|
188
175
|
let roles = [];
|
|
189
176
|
if (addToRoles) {
|
|
190
177
|
roles = await this.updateRolesWithPermissions(addToRoles, [permission]);
|
|
@@ -200,16 +187,14 @@ var BasePermissionService = class {
|
|
|
200
187
|
...args
|
|
201
188
|
)
|
|
202
189
|
),
|
|
203
|
-
addToRoles: permissionDto.addToRolesIds
|
|
204
|
-
? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em)
|
|
205
|
-
: []
|
|
190
|
+
addToRoles: permissionDto.addToRolesIds ? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em) : []
|
|
206
191
|
};
|
|
207
192
|
}
|
|
208
193
|
// end: createPermission helper functions
|
|
209
194
|
async createPermission(createPermissionEntity, em, ...args) {
|
|
210
195
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
211
196
|
this.openTelemetryCollector.info(
|
|
212
|
-
|
|
197
|
+
"Creating permission",
|
|
213
198
|
createPermissionEntity
|
|
214
199
|
);
|
|
215
200
|
}
|
|
@@ -230,7 +215,7 @@ var BasePermissionService = class {
|
|
|
230
215
|
async createBatchPermissions(permissionDtos, em) {
|
|
231
216
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
232
217
|
this.openTelemetryCollector.info(
|
|
233
|
-
|
|
218
|
+
"Creating batch permissions",
|
|
234
219
|
permissionDtos
|
|
235
220
|
);
|
|
236
221
|
}
|
|
@@ -258,10 +243,7 @@ var BasePermissionService = class {
|
|
|
258
243
|
})
|
|
259
244
|
);
|
|
260
245
|
roles.forEach((role) => {
|
|
261
|
-
if (
|
|
262
|
-
rolesCache[role.id] &&
|
|
263
|
-
role.permissions !== rolesCache[role.id].permissions
|
|
264
|
-
) {
|
|
246
|
+
if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
|
|
265
247
|
role.permissions.getItems().forEach((permission2) => {
|
|
266
248
|
if (!rolesCache[role.id].permissions.contains(permission2)) {
|
|
267
249
|
rolesCache[role.id].permissions.add(permission2);
|
|
@@ -280,25 +262,29 @@ var BasePermissionService = class {
|
|
|
280
262
|
await this.em.persistAndFlush(entities);
|
|
281
263
|
}
|
|
282
264
|
return Promise.all(
|
|
283
|
-
permissions.map(
|
|
284
|
-
this.mappers.PermissionMapper.toDto(permission)
|
|
265
|
+
permissions.map(
|
|
266
|
+
async (permission) => this.mappers.PermissionMapper.toDto(permission)
|
|
285
267
|
)
|
|
286
268
|
);
|
|
287
269
|
}
|
|
288
270
|
async getPermission(idDto, em) {
|
|
289
271
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
290
|
-
this.openTelemetryCollector.info(
|
|
272
|
+
this.openTelemetryCollector.info("Getting permission", idDto);
|
|
291
273
|
}
|
|
292
|
-
const permission = await (em ?? this.em).findOneOrFail(
|
|
293
|
-
return this.mappers.PermissionMapper.toDto(
|
|
274
|
+
const permission = await (em ?? this.em).findOneOrFail("Permission", idDto);
|
|
275
|
+
return this.mappers.PermissionMapper.toDto(
|
|
276
|
+
permission
|
|
277
|
+
);
|
|
294
278
|
}
|
|
295
279
|
async getBatchPermissions(idsDto, em) {
|
|
296
280
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
297
|
-
this.openTelemetryCollector.info(
|
|
281
|
+
this.openTelemetryCollector.info("Getting batch permissions", idsDto);
|
|
298
282
|
}
|
|
299
283
|
return Promise.all(
|
|
300
|
-
(await (em ?? this.em).find(
|
|
301
|
-
this.mappers.PermissionMapper.toDto(
|
|
284
|
+
(await (em ?? this.em).find("Permission", idsDto)).map(
|
|
285
|
+
(permission) => this.mappers.PermissionMapper.toDto(
|
|
286
|
+
permission
|
|
287
|
+
)
|
|
302
288
|
)
|
|
303
289
|
);
|
|
304
290
|
}
|
|
@@ -309,12 +295,8 @@ var BasePermissionService = class {
|
|
|
309
295
|
em ?? this.em,
|
|
310
296
|
...args
|
|
311
297
|
);
|
|
312
|
-
const addToRoles = permissionDto.addToRolesIds
|
|
313
|
-
|
|
314
|
-
: [];
|
|
315
|
-
const removeFromRoles = permissionDto.removeFromRolesIds
|
|
316
|
-
? await this.getBatchRoles({ ids: permissionDto.removeFromRolesIds }, em)
|
|
317
|
-
: [];
|
|
298
|
+
const addToRoles = permissionDto.addToRolesIds ? await this.getBatchRoles({ ids: permissionDto.addToRolesIds }, em) : [];
|
|
299
|
+
const removeFromRoles = permissionDto.removeFromRolesIds ? await this.getBatchRoles({ ids: permissionDto.removeFromRolesIds }, em) : [];
|
|
318
300
|
let roles = [];
|
|
319
301
|
roles = roles.concat(
|
|
320
302
|
await this.updateRolesWithPermissions(addToRoles, [permission])
|
|
@@ -330,7 +312,7 @@ var BasePermissionService = class {
|
|
|
330
312
|
// end: updatePermission helper functions
|
|
331
313
|
async updatePermission(permissionDto, em) {
|
|
332
314
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
333
|
-
this.openTelemetryCollector.info(
|
|
315
|
+
this.openTelemetryCollector.info("Updating permission", permissionDto);
|
|
334
316
|
}
|
|
335
317
|
const { permission, roles } = await this.updatePermissionDto(permissionDto);
|
|
336
318
|
const entities = await (em ?? this.em).upsertMany([permission, ...roles]);
|
|
@@ -344,7 +326,7 @@ var BasePermissionService = class {
|
|
|
344
326
|
async updateBatchPermissions(permissionDtos, em) {
|
|
345
327
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
346
328
|
this.openTelemetryCollector.info(
|
|
347
|
-
|
|
329
|
+
"Updating batch permissions",
|
|
348
330
|
permissionDtos
|
|
349
331
|
);
|
|
350
332
|
}
|
|
@@ -352,13 +334,9 @@ var BasePermissionService = class {
|
|
|
352
334
|
const permissions = [];
|
|
353
335
|
await (em ?? this.em).transactional(async (em2) => {
|
|
354
336
|
permissionDtos.map(async (updatePermissionDto) => {
|
|
355
|
-
const { permission, roles } =
|
|
356
|
-
await this.updatePermissionDto(updatePermissionDto);
|
|
337
|
+
const { permission, roles } = await this.updatePermissionDto(updatePermissionDto);
|
|
357
338
|
roles.forEach((role) => {
|
|
358
|
-
if (
|
|
359
|
-
rolesCache[role.id] &&
|
|
360
|
-
role.permissions !== rolesCache[role.id].permissions
|
|
361
|
-
) {
|
|
339
|
+
if (rolesCache[role.id] && role.permissions !== rolesCache[role.id].permissions) {
|
|
362
340
|
role.permissions.getItems().forEach((permission2) => {
|
|
363
341
|
if (!rolesCache[role.id].permissions.contains(permission2)) {
|
|
364
342
|
rolesCache[role.id].permissions.add(permission2);
|
|
@@ -378,29 +356,29 @@ var BasePermissionService = class {
|
|
|
378
356
|
}
|
|
379
357
|
});
|
|
380
358
|
return Promise.all(
|
|
381
|
-
permissions.map(
|
|
382
|
-
this.mappers.PermissionMapper.toDto(permission)
|
|
359
|
+
permissions.map(
|
|
360
|
+
(permission) => this.mappers.PermissionMapper.toDto(permission)
|
|
383
361
|
)
|
|
384
362
|
);
|
|
385
363
|
}
|
|
386
364
|
async deletePermission(idDto, em) {
|
|
387
365
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
388
|
-
this.openTelemetryCollector.info(
|
|
366
|
+
this.openTelemetryCollector.info("Deleting permission", idDto);
|
|
389
367
|
}
|
|
390
|
-
await (em ?? this.em).nativeDelete(
|
|
368
|
+
await (em ?? this.em).nativeDelete("Permission", idDto);
|
|
391
369
|
}
|
|
392
370
|
async deleteBatchPermissions(idsDto, em) {
|
|
393
371
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
394
|
-
this.openTelemetryCollector.info(
|
|
372
|
+
this.openTelemetryCollector.info("Deleting batch permissions", idsDto);
|
|
395
373
|
}
|
|
396
|
-
await (em ?? this.em).nativeDelete(
|
|
374
|
+
await (em ?? this.em).nativeDelete("Permission", {
|
|
397
375
|
id: { $in: idsDto.ids }
|
|
398
376
|
});
|
|
399
377
|
}
|
|
400
378
|
};
|
|
401
379
|
|
|
402
380
|
// services/role.service.ts
|
|
403
|
-
var import_http3 = require(
|
|
381
|
+
var import_http3 = require("@forklaunch/core/http");
|
|
404
382
|
var BaseRoleService = class {
|
|
405
383
|
evaluatedTelemetryOptions;
|
|
406
384
|
em;
|
|
@@ -412,17 +390,15 @@ var BaseRoleService = class {
|
|
|
412
390
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
413
391
|
this.schemaValidator = schemaValidator;
|
|
414
392
|
this.mappers = mappers;
|
|
415
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
416
|
-
|
|
417
|
-
:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
tracing: false
|
|
421
|
-
};
|
|
393
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http3.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
394
|
+
logging: false,
|
|
395
|
+
metrics: false,
|
|
396
|
+
tracing: false
|
|
397
|
+
};
|
|
422
398
|
}
|
|
423
399
|
async createRole(roleDto, em, ...args) {
|
|
424
400
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
425
|
-
this.openTelemetryCollector.info(
|
|
401
|
+
this.openTelemetryCollector.info("Creating role", roleDto);
|
|
426
402
|
}
|
|
427
403
|
const role = await this.mappers.CreateRoleMapper.toEntity(
|
|
428
404
|
roleDto,
|
|
@@ -438,11 +414,11 @@ var BaseRoleService = class {
|
|
|
438
414
|
}
|
|
439
415
|
async createBatchRoles(roleDtos, em, ...args) {
|
|
440
416
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
441
|
-
this.openTelemetryCollector.info(
|
|
417
|
+
this.openTelemetryCollector.info("Creating batch roles", roleDtos);
|
|
442
418
|
}
|
|
443
419
|
const roles = await Promise.all(
|
|
444
|
-
roleDtos.map(
|
|
445
|
-
this.mappers.CreateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
420
|
+
roleDtos.map(
|
|
421
|
+
async (roleDto) => this.mappers.CreateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
446
422
|
)
|
|
447
423
|
);
|
|
448
424
|
if (em) {
|
|
@@ -456,34 +432,34 @@ var BaseRoleService = class {
|
|
|
456
432
|
}
|
|
457
433
|
async getRole({ id }, em) {
|
|
458
434
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
459
|
-
this.openTelemetryCollector.info(
|
|
435
|
+
this.openTelemetryCollector.info("Getting role", { id });
|
|
460
436
|
}
|
|
461
|
-
const role = await (em ?? this.em).findOneOrFail(
|
|
462
|
-
populate: [
|
|
437
|
+
const role = await (em ?? this.em).findOneOrFail("Role", id, {
|
|
438
|
+
populate: ["id", "*"]
|
|
463
439
|
});
|
|
464
440
|
return this.mappers.RoleMapper.toDto(role);
|
|
465
441
|
}
|
|
466
442
|
async getBatchRoles({ ids }, em) {
|
|
467
443
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
468
|
-
this.openTelemetryCollector.info(
|
|
444
|
+
this.openTelemetryCollector.info("Getting batch roles", { ids });
|
|
469
445
|
}
|
|
470
446
|
return Promise.all(
|
|
471
|
-
(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
{
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
)
|
|
481
|
-
)
|
|
447
|
+
(await (em ?? this.em).find(
|
|
448
|
+
"Role",
|
|
449
|
+
{
|
|
450
|
+
id: { $in: ids }
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
populate: ["id", "*"]
|
|
454
|
+
}
|
|
455
|
+
)).map(
|
|
456
|
+
(role) => this.mappers.RoleMapper.toDto(role)
|
|
457
|
+
)
|
|
482
458
|
);
|
|
483
459
|
}
|
|
484
460
|
async updateRole(roleDto, em, ...args) {
|
|
485
461
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
486
|
-
this.openTelemetryCollector.info(
|
|
462
|
+
this.openTelemetryCollector.info("Updating role", roleDto);
|
|
487
463
|
}
|
|
488
464
|
const role = await this.mappers.UpdateRoleMapper.toEntity(
|
|
489
465
|
roleDto,
|
|
@@ -499,11 +475,11 @@ var BaseRoleService = class {
|
|
|
499
475
|
}
|
|
500
476
|
async updateBatchRoles(roleDtos, em, ...args) {
|
|
501
477
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
502
|
-
this.openTelemetryCollector.info(
|
|
478
|
+
this.openTelemetryCollector.info("Updating batch roles", roleDtos);
|
|
503
479
|
}
|
|
504
480
|
const roles = await Promise.all(
|
|
505
|
-
roleDtos.map(
|
|
506
|
-
this.mappers.UpdateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
481
|
+
roleDtos.map(
|
|
482
|
+
async (roleDto) => this.mappers.UpdateRoleMapper.toEntity(roleDto, em ?? this.em, ...args)
|
|
507
483
|
)
|
|
508
484
|
);
|
|
509
485
|
if (em) {
|
|
@@ -512,25 +488,27 @@ var BaseRoleService = class {
|
|
|
512
488
|
await this.em.persistAndFlush(roles);
|
|
513
489
|
}
|
|
514
490
|
return Promise.all(
|
|
515
|
-
roles.map(
|
|
491
|
+
roles.map(
|
|
492
|
+
(role) => this.mappers.RoleMapper.toDto(role)
|
|
493
|
+
)
|
|
516
494
|
);
|
|
517
495
|
}
|
|
518
496
|
async deleteRole(idDto, em) {
|
|
519
497
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
520
|
-
this.openTelemetryCollector.info(
|
|
498
|
+
this.openTelemetryCollector.info("Deleting role", idDto);
|
|
521
499
|
}
|
|
522
|
-
await (em ?? this.em).nativeDelete(
|
|
500
|
+
await (em ?? this.em).nativeDelete("Role", idDto);
|
|
523
501
|
}
|
|
524
502
|
async deleteBatchRoles(idsDto, em) {
|
|
525
503
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
526
|
-
this.openTelemetryCollector.info(
|
|
504
|
+
this.openTelemetryCollector.info("Deleting batch roles", idsDto);
|
|
527
505
|
}
|
|
528
|
-
await (em ?? this.em).nativeDelete(
|
|
506
|
+
await (em ?? this.em).nativeDelete("Role", { id: { $in: idsDto.ids } });
|
|
529
507
|
}
|
|
530
508
|
};
|
|
531
509
|
|
|
532
510
|
// services/user.service.ts
|
|
533
|
-
var import_http4 = require(
|
|
511
|
+
var import_http4 = require("@forklaunch/core/http");
|
|
534
512
|
var BaseUserService = class {
|
|
535
513
|
evaluatedTelemetryOptions;
|
|
536
514
|
em;
|
|
@@ -540,16 +518,7 @@ var BaseUserService = class {
|
|
|
540
518
|
openTelemetryCollector;
|
|
541
519
|
schemaValidator;
|
|
542
520
|
mappers;
|
|
543
|
-
constructor(
|
|
544
|
-
em,
|
|
545
|
-
passwordEncryptionPublicKeyPath,
|
|
546
|
-
roleServiceFactory,
|
|
547
|
-
organizationServiceFactory,
|
|
548
|
-
openTelemetryCollector,
|
|
549
|
-
schemaValidator,
|
|
550
|
-
mappers,
|
|
551
|
-
options
|
|
552
|
-
) {
|
|
521
|
+
constructor(em, passwordEncryptionPublicKeyPath, roleServiceFactory, organizationServiceFactory, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
553
522
|
this.em = em;
|
|
554
523
|
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
555
524
|
this.roleServiceFactory = roleServiceFactory;
|
|
@@ -557,17 +526,15 @@ var BaseUserService = class {
|
|
|
557
526
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
558
527
|
this.schemaValidator = schemaValidator;
|
|
559
528
|
this.mappers = mappers;
|
|
560
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
561
|
-
|
|
562
|
-
:
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
tracing: false
|
|
566
|
-
};
|
|
529
|
+
this.evaluatedTelemetryOptions = options?.telemetry ? (0, import_http4.evaluateTelemetryOptions)(options.telemetry).enabled : {
|
|
530
|
+
logging: false,
|
|
531
|
+
metrics: false,
|
|
532
|
+
tracing: false
|
|
533
|
+
};
|
|
567
534
|
}
|
|
568
535
|
async createUser(userDto, em, ...args) {
|
|
569
536
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
570
|
-
this.openTelemetryCollector.info(
|
|
537
|
+
this.openTelemetryCollector.info("Creating user", userDto);
|
|
571
538
|
}
|
|
572
539
|
const user = await this.mappers.CreateUserMapper.toEntity(
|
|
573
540
|
userDto,
|
|
@@ -583,11 +550,11 @@ var BaseUserService = class {
|
|
|
583
550
|
}
|
|
584
551
|
async createBatchUsers(userDtos, em, ...args) {
|
|
585
552
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
586
|
-
this.openTelemetryCollector.info(
|
|
553
|
+
this.openTelemetryCollector.info("Creating batch users", userDtos);
|
|
587
554
|
}
|
|
588
555
|
const users = await Promise.all(
|
|
589
|
-
userDtos.map(
|
|
590
|
-
this.mappers.CreateUserMapper.toEntity(
|
|
556
|
+
userDtos.map(
|
|
557
|
+
async (createUserDto) => this.mappers.CreateUserMapper.toEntity(
|
|
591
558
|
createUserDto,
|
|
592
559
|
em ?? this.em,
|
|
593
560
|
...args
|
|
@@ -605,28 +572,28 @@ var BaseUserService = class {
|
|
|
605
572
|
}
|
|
606
573
|
async getUser(idDto, em) {
|
|
607
574
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
608
|
-
this.openTelemetryCollector.info(
|
|
575
|
+
this.openTelemetryCollector.info("Getting user", idDto);
|
|
609
576
|
}
|
|
610
|
-
const user = await (em ?? this.em).findOneOrFail(
|
|
611
|
-
populate: [
|
|
577
|
+
const user = await (em ?? this.em).findOneOrFail("User", idDto, {
|
|
578
|
+
populate: ["id", "*"]
|
|
612
579
|
});
|
|
613
580
|
return this.mappers.UserMapper.toDto(user);
|
|
614
581
|
}
|
|
615
582
|
async getBatchUsers(idsDto, em) {
|
|
616
583
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
617
|
-
this.openTelemetryCollector.info(
|
|
584
|
+
this.openTelemetryCollector.info("Getting batch users", idsDto);
|
|
618
585
|
}
|
|
619
586
|
return Promise.all(
|
|
620
|
-
(
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
)
|
|
587
|
+
(await (em ?? this.em).find("User", idsDto, {
|
|
588
|
+
populate: ["id", "*"]
|
|
589
|
+
})).map(
|
|
590
|
+
(user) => this.mappers.UserMapper.toDto(user)
|
|
591
|
+
)
|
|
625
592
|
);
|
|
626
593
|
}
|
|
627
594
|
async updateUser(userDto, em, ...args) {
|
|
628
595
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
629
|
-
this.openTelemetryCollector.info(
|
|
596
|
+
this.openTelemetryCollector.info("Updating user", userDto);
|
|
630
597
|
}
|
|
631
598
|
const user = await this.mappers.UpdateUserMapper.toEntity(
|
|
632
599
|
userDto,
|
|
@@ -642,11 +609,11 @@ var BaseUserService = class {
|
|
|
642
609
|
}
|
|
643
610
|
async updateBatchUsers(userDtos, em, ...args) {
|
|
644
611
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
645
|
-
this.openTelemetryCollector.info(
|
|
612
|
+
this.openTelemetryCollector.info("Updating batch users", userDtos);
|
|
646
613
|
}
|
|
647
614
|
const users = await Promise.all(
|
|
648
|
-
userDtos.map(
|
|
649
|
-
this.mappers.UpdateUserMapper.toEntity(
|
|
615
|
+
userDtos.map(
|
|
616
|
+
async (updateUserDto) => this.mappers.UpdateUserMapper.toEntity(
|
|
650
617
|
updateUserDto,
|
|
651
618
|
em ?? this.em,
|
|
652
619
|
...args
|
|
@@ -664,46 +631,39 @@ var BaseUserService = class {
|
|
|
664
631
|
}
|
|
665
632
|
async deleteUser(idDto, em) {
|
|
666
633
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
667
|
-
this.openTelemetryCollector.info(
|
|
634
|
+
this.openTelemetryCollector.info("Deleting user", idDto);
|
|
668
635
|
}
|
|
669
|
-
await (em ?? this.em).nativeDelete(
|
|
636
|
+
await (em ?? this.em).nativeDelete("User", idDto);
|
|
670
637
|
}
|
|
671
638
|
async deleteBatchUsers(idsDto, em) {
|
|
672
639
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
673
|
-
this.openTelemetryCollector.info(
|
|
640
|
+
this.openTelemetryCollector.info("Deleting batch users", idsDto);
|
|
674
641
|
}
|
|
675
|
-
await (em ?? this.em).nativeDelete(
|
|
642
|
+
await (em ?? this.em).nativeDelete("User", idsDto);
|
|
676
643
|
}
|
|
677
644
|
async verifyHasRole(idDto, roleId) {
|
|
678
645
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
679
|
-
this.openTelemetryCollector.info(
|
|
646
|
+
this.openTelemetryCollector.info("Verifying user has role", {
|
|
680
647
|
idDto,
|
|
681
648
|
roleId
|
|
682
649
|
});
|
|
683
650
|
}
|
|
684
651
|
const user = await this.getUser(idDto);
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}).length === 0
|
|
689
|
-
) {
|
|
652
|
+
if (user.roles.filter((role) => {
|
|
653
|
+
return roleId == role.id;
|
|
654
|
+
}).length === 0) {
|
|
690
655
|
throw new Error(`User ${idDto.id} does not have role ${roleId}`);
|
|
691
656
|
}
|
|
692
657
|
}
|
|
693
658
|
async verifyHasPermission(idDto, permissionId) {
|
|
694
659
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
695
|
-
this.openTelemetryCollector.info(
|
|
660
|
+
this.openTelemetryCollector.info("Verifying user has permission", {
|
|
696
661
|
idDto,
|
|
697
662
|
permissionId
|
|
698
663
|
});
|
|
699
664
|
}
|
|
700
665
|
const user = await this.getUser(idDto);
|
|
701
|
-
if (
|
|
702
|
-
user.roles
|
|
703
|
-
.map((role) => role.permissions.map((permission) => permission.id))
|
|
704
|
-
.flat()
|
|
705
|
-
.filter((id) => id == permissionId).length === 0
|
|
706
|
-
) {
|
|
666
|
+
if (user.roles.map((role) => role.permissions.map((permission) => permission.id)).flat().filter((id) => id == permissionId).length === 0) {
|
|
707
667
|
throw new Error(
|
|
708
668
|
`User ${idDto.id} does not have permission ${permissionId}`
|
|
709
669
|
);
|
|
@@ -711,10 +671,9 @@ var BaseUserService = class {
|
|
|
711
671
|
}
|
|
712
672
|
};
|
|
713
673
|
// Annotate the CommonJS export names for ESM import in node:
|
|
714
|
-
0 &&
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
});
|
|
674
|
+
0 && (module.exports = {
|
|
675
|
+
BaseOrganizationService,
|
|
676
|
+
BasePermissionService,
|
|
677
|
+
BaseRoleService,
|
|
678
|
+
BaseUserService
|
|
679
|
+
});
|