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