@forklaunch/implementation-iam-base 0.2.0 → 0.2.2
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 +63 -9
- package/lib/eject/services/permission.service.ts +136 -63
- package/lib/eject/services/role.service.ts +106 -22
- package/lib/eject/services/user.service.ts +96 -31
- package/lib/services/organization.service.d.ts +6 -1
- package/lib/services/organization.service.d.ts.map +1 -1
- package/lib/services/organization.service.js +47 -9
- package/lib/services/permission.service.d.ts +24 -13
- package/lib/services/permission.service.d.ts.map +1 -1
- package/lib/services/permission.service.js +95 -41
- package/lib/services/role.service.d.ts +8 -3
- package/lib/services/role.service.d.ts.map +1 -1
- package/lib/services/role.service.js +83 -22
- package/lib/services/user.service.d.ts +18 -22
- package/lib/services/user.service.d.ts.map +1 -1
- package/lib/services/user.service.js +75 -21
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
1
2
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
3
|
export class BaseUserService {
|
|
3
4
|
em;
|
|
@@ -7,7 +8,9 @@ export class BaseUserService {
|
|
|
7
8
|
openTelemetryCollector;
|
|
8
9
|
schemaValidator;
|
|
9
10
|
mappers;
|
|
11
|
+
options;
|
|
10
12
|
#mappers;
|
|
13
|
+
evaluatedTelemetryOptions;
|
|
11
14
|
constructor(
|
|
12
15
|
em,
|
|
13
16
|
passwordEncryptionPublicKeyPath,
|
|
@@ -15,7 +18,8 @@ export class BaseUserService {
|
|
|
15
18
|
organizationServiceFactory,
|
|
16
19
|
openTelemetryCollector,
|
|
17
20
|
schemaValidator,
|
|
18
|
-
mappers
|
|
21
|
+
mappers,
|
|
22
|
+
options
|
|
19
23
|
) {
|
|
20
24
|
this.em = em;
|
|
21
25
|
this.passwordEncryptionPublicKeyPath = passwordEncryptionPublicKeyPath;
|
|
@@ -24,30 +28,48 @@ export class BaseUserService {
|
|
|
24
28
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
25
29
|
this.schemaValidator = schemaValidator;
|
|
26
30
|
this.mappers = mappers;
|
|
31
|
+
this.options = options;
|
|
27
32
|
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
33
|
+
this.evaluatedTelemetryOptions = options?.telemetry
|
|
34
|
+
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
35
|
+
: {
|
|
36
|
+
logging: false,
|
|
37
|
+
metrics: false,
|
|
38
|
+
tracing: false
|
|
39
|
+
};
|
|
28
40
|
}
|
|
29
41
|
async createUser(userDto, em) {
|
|
42
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
43
|
+
this.openTelemetryCollector.info('Creating user', userDto);
|
|
44
|
+
}
|
|
30
45
|
const user = await this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
31
46
|
userDto,
|
|
32
|
-
this.
|
|
47
|
+
em ?? this.em
|
|
33
48
|
);
|
|
34
|
-
|
|
49
|
+
if (em) {
|
|
35
50
|
await em.persist(user);
|
|
36
|
-
}
|
|
51
|
+
} else {
|
|
52
|
+
await this.em.persistAndFlush(user);
|
|
53
|
+
}
|
|
37
54
|
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
38
55
|
}
|
|
39
56
|
async createBatchUsers(userDtos, em) {
|
|
57
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
58
|
+
this.openTelemetryCollector.info('Creating batch users', userDtos);
|
|
59
|
+
}
|
|
40
60
|
const users = await Promise.all(
|
|
41
61
|
userDtos.map(async (createUserDto) =>
|
|
42
62
|
this.#mappers.CreateUserDtoMapper.deserializeDtoToEntity(
|
|
43
63
|
createUserDto,
|
|
44
|
-
this.
|
|
64
|
+
em ?? this.em
|
|
45
65
|
)
|
|
46
66
|
)
|
|
47
67
|
);
|
|
48
|
-
|
|
68
|
+
if (em) {
|
|
49
69
|
await em.persist(users);
|
|
50
|
-
}
|
|
70
|
+
} else {
|
|
71
|
+
await this.em.persistAndFlush(users);
|
|
72
|
+
}
|
|
51
73
|
return Promise.all(
|
|
52
74
|
users.map((user) =>
|
|
53
75
|
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
@@ -55,12 +77,18 @@ export class BaseUserService {
|
|
|
55
77
|
);
|
|
56
78
|
}
|
|
57
79
|
async getUser(idDto, em) {
|
|
80
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
81
|
+
this.openTelemetryCollector.info('Getting user', idDto);
|
|
82
|
+
}
|
|
58
83
|
const user = await (em ?? this.em).findOneOrFail('User', idDto, {
|
|
59
84
|
populate: ['id', '*']
|
|
60
85
|
});
|
|
61
86
|
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
62
87
|
}
|
|
63
88
|
async getBatchUsers(idsDto, em) {
|
|
89
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
|
+
this.openTelemetryCollector.info('Getting batch users', idsDto);
|
|
91
|
+
}
|
|
64
92
|
return Promise.all(
|
|
65
93
|
(
|
|
66
94
|
await (em ?? this.em).find('User', idsDto, {
|
|
@@ -70,27 +98,37 @@ export class BaseUserService {
|
|
|
70
98
|
);
|
|
71
99
|
}
|
|
72
100
|
async updateUser(userDto, em) {
|
|
73
|
-
|
|
101
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
102
|
+
this.openTelemetryCollector.info('Updating user', userDto);
|
|
103
|
+
}
|
|
104
|
+
const user = await this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
74
105
|
userDto,
|
|
75
|
-
this.
|
|
106
|
+
em ?? this.em
|
|
76
107
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
108
|
+
if (em) {
|
|
109
|
+
await em.persist(user);
|
|
110
|
+
} else {
|
|
111
|
+
await this.em.persistAndFlush(user);
|
|
112
|
+
}
|
|
80
113
|
return this.#mappers.UserDtoMapper.serializeEntityToDto(user);
|
|
81
114
|
}
|
|
82
115
|
async updateBatchUsers(userDtos, em) {
|
|
83
|
-
|
|
116
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
117
|
+
this.openTelemetryCollector.info('Updating batch users', userDtos);
|
|
118
|
+
}
|
|
119
|
+
const users = await Promise.all(
|
|
84
120
|
userDtos.map(async (updateUserDto) =>
|
|
85
121
|
this.#mappers.UpdateUserDtoMapper.deserializeDtoToEntity(
|
|
86
122
|
updateUserDto,
|
|
87
|
-
this.
|
|
123
|
+
em ?? this.em
|
|
88
124
|
)
|
|
89
125
|
)
|
|
90
126
|
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
127
|
+
if (em) {
|
|
128
|
+
await em.persist(users);
|
|
129
|
+
} else {
|
|
130
|
+
await this.em.persistAndFlush(users);
|
|
131
|
+
}
|
|
94
132
|
return Promise.all(
|
|
95
133
|
users.map((user) =>
|
|
96
134
|
this.#mappers.UserDtoMapper.serializeEntityToDto(user)
|
|
@@ -98,14 +136,24 @@ export class BaseUserService {
|
|
|
98
136
|
);
|
|
99
137
|
}
|
|
100
138
|
async deleteUser(idDto, em) {
|
|
101
|
-
|
|
102
|
-
|
|
139
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
140
|
+
this.openTelemetryCollector.info('Deleting user', idDto);
|
|
141
|
+
}
|
|
142
|
+
await (em ?? this.em).nativeDelete('User', idDto);
|
|
103
143
|
}
|
|
104
144
|
async deleteBatchUsers(idsDto, em) {
|
|
105
|
-
|
|
106
|
-
|
|
145
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
146
|
+
this.openTelemetryCollector.info('Deleting batch users', idsDto);
|
|
147
|
+
}
|
|
148
|
+
await (em ?? this.em).nativeDelete('User', idsDto);
|
|
107
149
|
}
|
|
108
150
|
async verifyHasRole(idDto, roleId) {
|
|
151
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
152
|
+
this.openTelemetryCollector.info('Verifying user has role', {
|
|
153
|
+
idDto,
|
|
154
|
+
roleId
|
|
155
|
+
});
|
|
156
|
+
}
|
|
109
157
|
const user = await this.getUser(idDto);
|
|
110
158
|
if (
|
|
111
159
|
user.roles.filter((role) => {
|
|
@@ -116,6 +164,12 @@ export class BaseUserService {
|
|
|
116
164
|
}
|
|
117
165
|
}
|
|
118
166
|
async verifyHasPermission(idDto, permissionId) {
|
|
167
|
+
if (this.evaluatedTelemetryOptions.logging) {
|
|
168
|
+
this.openTelemetryCollector.info('Verifying user has permission', {
|
|
169
|
+
idDto,
|
|
170
|
+
permissionId
|
|
171
|
+
});
|
|
172
|
+
}
|
|
119
173
|
const user = await this.getUser(idDto);
|
|
120
174
|
if (
|
|
121
175
|
user.roles
|