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