@forklaunch/implementation-iam-base 0.1.17 → 0.2.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/eject/services/organization.service.ts +75 -21
- package/lib/eject/services/permission.service.ts +169 -89
- package/lib/eject/services/role.service.ts +126 -42
- package/lib/eject/services/user.service.ts +128 -58
- package/lib/services/organization.service.d.ts +11 -6
- package/lib/services/organization.service.d.ts.map +1 -1
- package/lib/services/organization.service.js +56 -18
- package/lib/services/permission.service.d.ts +29 -18
- package/lib/services/permission.service.d.ts.map +1 -1
- package/lib/services/permission.service.js +125 -64
- package/lib/services/role.service.d.ts +10 -5
- package/lib/services/role.service.d.ts.map +1 -1
- package/lib/services/role.service.js +102 -36
- package/lib/services/user.service.d.ts +23 -27
- package/lib/services/user.service.d.ts.map +1 -1
- package/lib/services/user.service.js +102 -43
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
evaluateTelemetryOptions,
|
|
2
3
|
MetricsDefinition,
|
|
3
|
-
OpenTelemetryCollector
|
|
4
|
+
OpenTelemetryCollector,
|
|
5
|
+
TelemetryOptions
|
|
4
6
|
} from '@forklaunch/core/http';
|
|
5
7
|
import { RoleService } from '@forklaunch/interfaces-iam/interfaces';
|
|
6
8
|
import { EntityManager } from '@mikro-orm/core';
|
|
@@ -55,17 +57,22 @@ export class BaseRoleService<
|
|
|
55
57
|
}
|
|
56
58
|
> implements RoleService
|
|
57
59
|
{
|
|
58
|
-
#
|
|
59
|
-
InstanceTypeRecord<typeof this.
|
|
60
|
+
#mappers: InternalDtoMapper<
|
|
61
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
60
62
|
Entities,
|
|
61
63
|
Dto
|
|
62
64
|
>;
|
|
65
|
+
private evaluatedTelemetryOptions: {
|
|
66
|
+
logging?: boolean;
|
|
67
|
+
metrics?: boolean;
|
|
68
|
+
tracing?: boolean;
|
|
69
|
+
};
|
|
63
70
|
|
|
64
71
|
constructor(
|
|
65
72
|
public em: EntityManager,
|
|
66
73
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
67
74
|
protected schemaValidator: SchemaValidator,
|
|
68
|
-
protected
|
|
75
|
+
protected mappers: {
|
|
69
76
|
RoleDtoMapper: ResponseDtoMapperConstructor<
|
|
70
77
|
SchemaValidator,
|
|
71
78
|
Dto['RoleDtoMapper'],
|
|
@@ -81,58 +88,106 @@ export class BaseRoleService<
|
|
|
81
88
|
Dto['UpdateRoleDtoMapper'],
|
|
82
89
|
Entities['UpdateRoleDtoMapper']
|
|
83
90
|
>;
|
|
91
|
+
},
|
|
92
|
+
options?: {
|
|
93
|
+
telemetry?: TelemetryOptions;
|
|
84
94
|
}
|
|
85
95
|
) {
|
|
86
|
-
this.#
|
|
96
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
97
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
98
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
99
|
+
: {
|
|
100
|
+
logging: false,
|
|
101
|
+
metrics: false,
|
|
102
|
+
tracing: false
|
|
103
|
+
};
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
async createRole(
|
|
90
107
|
roleDto: Dto['CreateRoleDtoMapper'],
|
|
91
108
|
em?: EntityManager
|
|
92
109
|
): Promise<Dto['RoleDtoMapper']> {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
110
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
111
|
+
this.openTelemetryCollector.info('Creating role', roleDto);
|
|
112
|
+
}
|
|
113
|
+
const role = await this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(
|
|
114
|
+
roleDto,
|
|
115
|
+
em ?? this.em
|
|
99
116
|
);
|
|
117
|
+
|
|
118
|
+
if (em) {
|
|
119
|
+
await em.persist(role);
|
|
120
|
+
} else {
|
|
121
|
+
await this.em.persistAndFlush(role);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
100
125
|
}
|
|
101
126
|
|
|
102
127
|
async createBatchRoles(
|
|
103
128
|
roleDtos: Dto['CreateRoleDtoMapper'][],
|
|
104
129
|
em?: EntityManager
|
|
105
130
|
): Promise<Dto['RoleDtoMapper'][]> {
|
|
131
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
132
|
+
this.openTelemetryCollector.info('Creating batch roles', roleDtos);
|
|
133
|
+
}
|
|
134
|
+
|
|
106
135
|
const roles = await Promise.all(
|
|
107
136
|
roleDtos.map(async (roleDto) =>
|
|
108
|
-
this.#
|
|
137
|
+
this.#mappers.CreateRoleDtoMapper.deserializeDtoToEntity(
|
|
138
|
+
roleDto,
|
|
139
|
+
em ?? this.em
|
|
140
|
+
)
|
|
109
141
|
)
|
|
110
142
|
);
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
143
|
+
|
|
144
|
+
if (em) {
|
|
145
|
+
await em.persist(roles);
|
|
146
|
+
} else {
|
|
147
|
+
await this.em.persistAndFlush(roles);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return Promise.all(
|
|
151
|
+
roles.map((role) =>
|
|
152
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(role)
|
|
115
153
|
)
|
|
116
154
|
);
|
|
117
155
|
}
|
|
118
156
|
|
|
119
|
-
async getRole(
|
|
120
|
-
|
|
157
|
+
async getRole({ id }: IdDto, em?: EntityManager): Promise<RoleDto> {
|
|
158
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
159
|
+
this.openTelemetryCollector.info('Getting role', { id });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const role = await (em ?? this.em).findOneOrFail('Role', id, {
|
|
121
163
|
populate: ['id', '*']
|
|
122
164
|
});
|
|
123
|
-
|
|
165
|
+
|
|
166
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
124
167
|
role as Entities['RoleDtoMapper']
|
|
125
168
|
);
|
|
126
169
|
}
|
|
127
170
|
|
|
128
|
-
async getBatchRoles(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
171
|
+
async getBatchRoles({ ids }: IdsDto, em?: EntityManager): Promise<RoleDto[]> {
|
|
172
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
173
|
+
this.openTelemetryCollector.info('Getting batch roles', { ids });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return Promise.all(
|
|
177
|
+
(
|
|
178
|
+
await (em ?? this.em).find(
|
|
179
|
+
'Role',
|
|
180
|
+
{
|
|
181
|
+
id: { $in: ids }
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
populate: ['id', '*']
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
).map((role) =>
|
|
188
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
189
|
+
role as Entities['RoleDtoMapper']
|
|
190
|
+
)
|
|
136
191
|
)
|
|
137
192
|
);
|
|
138
193
|
}
|
|
@@ -141,39 +196,68 @@ export class BaseRoleService<
|
|
|
141
196
|
roleDto: Dto['UpdateRoleDtoMapper'],
|
|
142
197
|
em?: EntityManager
|
|
143
198
|
): Promise<Dto['RoleDtoMapper']> {
|
|
144
|
-
|
|
145
|
-
roleDto
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
199
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
200
|
+
this.openTelemetryCollector.info('Updating role', roleDto);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const role = await this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(
|
|
204
|
+
roleDto,
|
|
205
|
+
em ?? this.em
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (em) {
|
|
209
|
+
await em.persist(role);
|
|
210
|
+
} else {
|
|
211
|
+
await this.em.persistAndFlush(role);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return this.#mappers.RoleDtoMapper.serializeEntityToDto(role);
|
|
151
215
|
}
|
|
152
216
|
|
|
153
217
|
async updateBatchRoles(
|
|
154
218
|
roleDtos: Dto['UpdateRoleDtoMapper'][],
|
|
155
219
|
em?: EntityManager
|
|
156
220
|
): Promise<Dto['RoleDtoMapper'][]> {
|
|
157
|
-
|
|
221
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
222
|
+
this.openTelemetryCollector.info('Updating batch roles', roleDtos);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const roles = await Promise.all(
|
|
158
226
|
roleDtos.map(async (roleDto) =>
|
|
159
|
-
this.#
|
|
227
|
+
this.#mappers.UpdateRoleDtoMapper.deserializeDtoToEntity(
|
|
228
|
+
roleDto,
|
|
229
|
+
em ?? this.em
|
|
230
|
+
)
|
|
160
231
|
)
|
|
161
232
|
);
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this
|
|
167
|
-
|
|
233
|
+
|
|
234
|
+
if (em) {
|
|
235
|
+
await em.persist(roles);
|
|
236
|
+
} else {
|
|
237
|
+
await this.em.persistAndFlush(roles);
|
|
238
|
+
}
|
|
239
|
+
return Promise.all(
|
|
240
|
+
roles.map((role) =>
|
|
241
|
+
this.#mappers.RoleDtoMapper.serializeEntityToDto(
|
|
242
|
+
role as Entities['RoleDtoMapper']
|
|
243
|
+
)
|
|
168
244
|
)
|
|
169
245
|
);
|
|
170
246
|
}
|
|
171
247
|
|
|
172
248
|
async deleteRole(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
249
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
250
|
+
this.openTelemetryCollector.info('Deleting role', idDto);
|
|
251
|
+
}
|
|
252
|
+
|
|
173
253
|
await (em ?? this.em).nativeDelete('Role', idDto);
|
|
174
254
|
}
|
|
175
255
|
|
|
176
256
|
async deleteBatchRoles(idsDto: IdsDto, em?: EntityManager): Promise<void> {
|
|
257
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
258
|
+
this.openTelemetryCollector.info('Deleting batch roles', idsDto);
|
|
259
|
+
}
|
|
260
|
+
|
|
177
261
|
await (em ?? this.em).nativeDelete('Role', { id: { $in: idsDto.ids } });
|
|
178
262
|
}
|
|
179
263
|
}
|
|
@@ -5,16 +5,18 @@ import {
|
|
|
5
5
|
} from '@forklaunch/interfaces-iam/interfaces';
|
|
6
6
|
|
|
7
7
|
import { IdDto, IdsDto, InstanceTypeRecord } from '@forklaunch/common';
|
|
8
|
+
import {
|
|
9
|
+
evaluateTelemetryOptions,
|
|
10
|
+
MetricsDefinition,
|
|
11
|
+
OpenTelemetryCollector,
|
|
12
|
+
TelemetryOptions
|
|
13
|
+
} from '@forklaunch/core/http';
|
|
8
14
|
import {
|
|
9
15
|
InternalDtoMapper,
|
|
10
16
|
RequestDtoMapperConstructor,
|
|
11
17
|
ResponseDtoMapperConstructor,
|
|
12
18
|
transformIntoInternalDtoMapper
|
|
13
19
|
} from '@forklaunch/core/mappers';
|
|
14
|
-
import {
|
|
15
|
-
MetricsDefinition,
|
|
16
|
-
OpenTelemetryCollector
|
|
17
|
-
} from '@forklaunch/core/http';
|
|
18
20
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
19
21
|
import {
|
|
20
22
|
CreateUserDto,
|
|
@@ -48,11 +50,16 @@ export class BaseUserService<
|
|
|
48
50
|
}
|
|
49
51
|
> implements UserService
|
|
50
52
|
{
|
|
51
|
-
#
|
|
52
|
-
InstanceTypeRecord<typeof this.
|
|
53
|
+
#mappers: InternalDtoMapper<
|
|
54
|
+
InstanceTypeRecord<typeof this.mappers>,
|
|
53
55
|
Entities,
|
|
54
56
|
Dto
|
|
55
57
|
>;
|
|
58
|
+
private evaluatedTelemetryOptions: {
|
|
59
|
+
logging?: boolean;
|
|
60
|
+
metrics?: boolean;
|
|
61
|
+
tracing?: boolean;
|
|
62
|
+
};
|
|
56
63
|
|
|
57
64
|
constructor(
|
|
58
65
|
public em: EntityManager,
|
|
@@ -61,7 +68,7 @@ export class BaseUserService<
|
|
|
61
68
|
protected organizationServiceFactory: () => OrganizationService<OrganizationStatus>,
|
|
62
69
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
63
70
|
protected schemaValidator: SchemaValidator,
|
|
64
|
-
protected
|
|
71
|
+
protected mappers: {
|
|
65
72
|
UserDtoMapper: ResponseDtoMapperConstructor<
|
|
66
73
|
SchemaValidator,
|
|
67
74
|
Dto['UserDtoMapper'],
|
|
@@ -70,59 +77,77 @@ export class BaseUserService<
|
|
|
70
77
|
CreateUserDtoMapper: RequestDtoMapperConstructor<
|
|
71
78
|
SchemaValidator,
|
|
72
79
|
Dto['CreateUserDtoMapper'],
|
|
73
|
-
Entities['CreateUserDtoMapper']
|
|
74
|
-
(
|
|
75
|
-
dto: never,
|
|
76
|
-
passwordEncryptionPublicKeyPath: string
|
|
77
|
-
) => Entities['UpdateUserDtoMapper']
|
|
80
|
+
Entities['CreateUserDtoMapper']
|
|
78
81
|
>;
|
|
79
82
|
UpdateUserDtoMapper: RequestDtoMapperConstructor<
|
|
80
83
|
SchemaValidator,
|
|
81
84
|
Dto['UpdateUserDtoMapper'],
|
|
82
|
-
Entities['UpdateUserDtoMapper']
|
|
83
|
-
(
|
|
84
|
-
dto: never,
|
|
85
|
-
passwordEncryptionPublicKeyPath: string
|
|
86
|
-
) => Entities['UpdateUserDtoMapper']
|
|
85
|
+
Entities['UpdateUserDtoMapper']
|
|
87
86
|
>;
|
|
87
|
+
},
|
|
88
|
+
readonly options?: {
|
|
89
|
+
telemetry?: TelemetryOptions;
|
|
88
90
|
}
|
|
89
91
|
) {
|
|
90
|
-
this.#
|
|
92
|
+
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
93
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
94
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
95
|
+
: {
|
|
96
|
+
logging: false,
|
|
97
|
+
metrics: false,
|
|
98
|
+
tracing: false
|
|
99
|
+
};
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
async createUser(
|
|
94
103
|
userDto: Dto['CreateUserDtoMapper'],
|
|
95
104
|
em?: EntityManager
|
|
96
105
|
): Promise<Dto['UserDtoMapper']> {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
107
|
+
this.openTelemetryCollector.info('Creating user', userDto);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const user = await this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
111
|
+
userDto,
|
|
112
|
+
em ?? this.em
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (em) {
|
|
103
116
|
await em.persist(user);
|
|
104
|
-
}
|
|
105
|
-
|
|
117
|
+
} else {
|
|
118
|
+
await this.em.persistAndFlush(user);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
async createBatchUsers(
|
|
109
125
|
userDtos: Dto['CreateUserDtoMapper'][],
|
|
110
126
|
em?: EntityManager
|
|
111
127
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
128
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
129
|
+
this.openTelemetryCollector.info('Creating batch users', userDtos);
|
|
130
|
+
}
|
|
131
|
+
|
|
112
132
|
const users = await Promise.all(
|
|
113
133
|
userDtos.map(async (createUserDto) =>
|
|
114
|
-
this.#
|
|
134
|
+
this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
115
135
|
createUserDto,
|
|
116
|
-
this.
|
|
136
|
+
em ?? this.em
|
|
117
137
|
)
|
|
118
138
|
)
|
|
119
139
|
);
|
|
120
|
-
|
|
140
|
+
|
|
141
|
+
if (em) {
|
|
121
142
|
await em.persist(users);
|
|
122
|
-
}
|
|
143
|
+
} else {
|
|
144
|
+
await this.em.persistAndFlush(users);
|
|
145
|
+
}
|
|
123
146
|
|
|
124
|
-
return
|
|
125
|
-
|
|
147
|
+
return Promise.all(
|
|
148
|
+
users.map((user) =>
|
|
149
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
150
|
+
)
|
|
126
151
|
);
|
|
127
152
|
}
|
|
128
153
|
|
|
@@ -130,10 +155,15 @@ export class BaseUserService<
|
|
|
130
155
|
idDto: IdDto,
|
|
131
156
|
em?: EntityManager
|
|
132
157
|
): Promise<Dto['UserDtoMapper']> {
|
|
158
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
159
|
+
this.openTelemetryCollector.info('Getting user', idDto);
|
|
160
|
+
}
|
|
161
|
+
|
|
133
162
|
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
134
163
|
populate: ['id', '*']
|
|
135
164
|
});
|
|
136
|
-
|
|
165
|
+
|
|
166
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(
|
|
137
167
|
user as Entities['UserDtoMapper']
|
|
138
168
|
);
|
|
139
169
|
}
|
|
@@ -142,13 +172,19 @@ export class BaseUserService<
|
|
|
142
172
|
idsDto: IdsDto,
|
|
143
173
|
em?: EntityManager
|
|
144
174
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
175
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
176
|
+
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return Promise.all(
|
|
180
|
+
(
|
|
181
|
+
await (em ?? this.em).find('User', idsDto, {
|
|
182
|
+
populate: ['id', '*']
|
|
183
|
+
})
|
|
184
|
+
).map((user) =>
|
|
185
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(
|
|
186
|
+
user as Entities['UserDtoMapper']
|
|
187
|
+
)
|
|
152
188
|
)
|
|
153
189
|
);
|
|
154
190
|
}
|
|
@@ -157,47 +193,75 @@ export class BaseUserService<
|
|
|
157
193
|
userDto: Dto['UpdateUserDtoMapper'],
|
|
158
194
|
em?: EntityManager
|
|
159
195
|
): Promise<Dto['UserDtoMapper']> {
|
|
160
|
-
|
|
196
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
197
|
+
this.openTelemetryCollector.info('Updating user', userDto);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const user = await this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
161
201
|
userDto,
|
|
162
|
-
this.
|
|
202
|
+
em ?? this.em
|
|
163
203
|
);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
204
|
+
|
|
205
|
+
if (em) {
|
|
206
|
+
await em.persist(user);
|
|
207
|
+
} else {
|
|
208
|
+
await this.em.persistAndFlush(user);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
168
212
|
}
|
|
169
213
|
|
|
170
214
|
async updateBatchUsers(
|
|
171
215
|
userDtos: UpdateUserDto[],
|
|
172
216
|
em?: EntityManager
|
|
173
217
|
): Promise<Dto['UserDtoMapper'][]> {
|
|
174
|
-
|
|
218
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
219
|
+
this.openTelemetryCollector.info('Updating batch users', userDtos);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const users = await Promise.all(
|
|
175
223
|
userDtos.map(async (updateUserDto) =>
|
|
176
|
-
this.#
|
|
224
|
+
this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
177
225
|
updateUserDto,
|
|
178
|
-
this.
|
|
226
|
+
em ?? this.em
|
|
179
227
|
)
|
|
180
228
|
)
|
|
181
229
|
);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this
|
|
230
|
+
|
|
231
|
+
if (em) {
|
|
232
|
+
await em.persist(users);
|
|
233
|
+
} else {
|
|
234
|
+
await this.em.persistAndFlush(users);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return Promise.all(
|
|
238
|
+
users.map((user) =>
|
|
239
|
+
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
240
|
+
)
|
|
187
241
|
);
|
|
188
242
|
}
|
|
189
243
|
|
|
190
244
|
async deleteUser(idDto: IdDto, em?: EntityManager): Promise<void> {
|
|
191
|
-
|
|
192
|
-
|
|
245
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
246
|
+
this.openTelemetryCollector.info('Deleting user', idDto);
|
|
247
|
+
}
|
|
248
|
+
await (em ?? this.em).nativeDelete('User', idDto);
|
|
193
249
|
}
|
|
194
250
|
|
|
195
251
|
async deleteBatchUsers(idsDto: IdsDto, em?: EntityManager): Promise<void> {
|
|
196
|
-
|
|
197
|
-
|
|
252
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
253
|
+
this.openTelemetryCollector.info('Deleting batch users', idsDto);
|
|
254
|
+
}
|
|
255
|
+
await (em ?? this.em).nativeDelete('User', idsDto);
|
|
198
256
|
}
|
|
199
257
|
|
|
200
258
|
async verifyHasRole(idDto: IdDto, roleId: string): Promise<void> {
|
|
259
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
260
|
+
this.openTelemetryCollector.info('Verifying user has role', {
|
|
261
|
+
idDto,
|
|
262
|
+
roleId
|
|
263
|
+
});
|
|
264
|
+
}
|
|
201
265
|
const user = await this.getUser(idDto);
|
|
202
266
|
if (
|
|
203
267
|
user.roles.filter((role) => {
|
|
@@ -209,6 +273,12 @@ export class BaseUserService<
|
|
|
209
273
|
}
|
|
210
274
|
|
|
211
275
|
async verifyHasPermission(idDto: IdDto, permissionId: string): Promise<void> {
|
|
276
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
277
|
+
this.openTelemetryCollector.info('Verifying user has permission', {
|
|
278
|
+
idDto,
|
|
279
|
+
permissionId
|
|
280
|
+
});
|
|
281
|
+
}
|
|
212
282
|
const user = await this.getUser(idDto);
|
|
213
283
|
if (
|
|
214
284
|
user.roles
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { IdDto } from '@forklaunch/common';
|
|
2
|
+
import {
|
|
3
|
+
MetricsDefinition,
|
|
4
|
+
OpenTelemetryCollector,
|
|
5
|
+
TelemetryOptions
|
|
6
|
+
} from '@forklaunch/core/http';
|
|
2
7
|
import {
|
|
3
8
|
RequestDtoMapperConstructor,
|
|
4
9
|
ResponseDtoMapperConstructor
|
|
5
10
|
} from '@forklaunch/core/mappers';
|
|
6
|
-
import {
|
|
7
|
-
MetricsDefinition,
|
|
8
|
-
OpenTelemetryCollector
|
|
9
|
-
} from '@forklaunch/core/http';
|
|
10
11
|
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
11
12
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
12
13
|
import {
|
|
@@ -62,7 +63,7 @@ export declare class BaseOrganizationService<
|
|
|
62
63
|
em: EntityManager;
|
|
63
64
|
protected openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
64
65
|
protected schemaValidator: SchemaValidator;
|
|
65
|
-
protected
|
|
66
|
+
protected mappers: {
|
|
66
67
|
OrganizationDtoMapper: ResponseDtoMapperConstructor<
|
|
67
68
|
SchemaValidator,
|
|
68
69
|
Dto['OrganizationDtoMapper'],
|
|
@@ -79,11 +80,12 @@ export declare class BaseOrganizationService<
|
|
|
79
80
|
Entities['UpdateOrganizationDtoMapper']
|
|
80
81
|
>;
|
|
81
82
|
};
|
|
83
|
+
private evaluatedTelemetryOptions;
|
|
82
84
|
constructor(
|
|
83
85
|
em: EntityManager,
|
|
84
86
|
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
85
87
|
schemaValidator: SchemaValidator,
|
|
86
|
-
|
|
88
|
+
mappers: {
|
|
87
89
|
OrganizationDtoMapper: ResponseDtoMapperConstructor<
|
|
88
90
|
SchemaValidator,
|
|
89
91
|
Dto['OrganizationDtoMapper'],
|
|
@@ -99,6 +101,9 @@ export declare class BaseOrganizationService<
|
|
|
99
101
|
Dto['UpdateOrganizationDtoMapper'],
|
|
100
102
|
Entities['UpdateOrganizationDtoMapper']
|
|
101
103
|
>;
|
|
104
|
+
},
|
|
105
|
+
options?: {
|
|
106
|
+
telemetry?: TelemetryOptions;
|
|
102
107
|
}
|
|
103
108
|
);
|
|
104
109
|
createOrganization(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../services/organization.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"organization.service.d.ts","sourceRoot":"","sources":["../../services/organization.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAEL,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,2BAA2B,EAC3B,4BAA4B,EAE7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB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