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