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