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