@forklaunch/implementation-iam-base 0.3.1 → 0.3.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/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/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/eject/types/iamDto.types.ts +43 -0
- package/lib/eject/types/iamEntities.types.ts +49 -0
- package/lib/schemas/index.d.mts +61 -61
- package/lib/schemas/index.d.ts +61 -61
- package/lib/schemas/index.js +32 -32
- package/lib/schemas/index.mjs +28 -28
- package/lib/services/index.d.mts +110 -134
- package/lib/services/index.d.ts +110 -134
- package/lib/services/index.js +46 -54
- package/lib/services/index.mjs +50 -58
- package/package.json +9 -8
|
@@ -15,7 +15,7 @@ export const CreateOrganizationSchema = {
|
|
|
15
15
|
domain: string,
|
|
16
16
|
subscription: string,
|
|
17
17
|
logoUrl: optional(string),
|
|
18
|
-
|
|
18
|
+
providerFields: optional(unknown)
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const UpdateOrganizationSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
@@ -24,7 +24,7 @@ export const UpdateOrganizationSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
|
24
24
|
domain: optional(string),
|
|
25
25
|
subscription: optional(string),
|
|
26
26
|
logoUrl: optional(string),
|
|
27
|
-
|
|
27
|
+
providerFields: optional(unknown)
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
export const OrganizationSchema =
|
|
@@ -39,7 +39,7 @@ export const OrganizationSchema =
|
|
|
39
39
|
subscription: string,
|
|
40
40
|
status: enum_(organizationStatus),
|
|
41
41
|
logoUrl: optional(string),
|
|
42
|
-
|
|
42
|
+
providerFields: optional(unknown),
|
|
43
43
|
createdAt: optional(date),
|
|
44
44
|
updatedAt: optional(date)
|
|
45
45
|
});
|
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
export const CreatePermissionSchema = {
|
|
11
11
|
slug: string,
|
|
12
12
|
addToRolesIds: optional(array(string)),
|
|
13
|
-
|
|
13
|
+
providerFields: optional(unknown)
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const UpdatePermissionSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
17
17
|
id: uuidId ? uuid : string,
|
|
18
18
|
slug: optional(string),
|
|
19
|
-
|
|
19
|
+
providerFields: optional(unknown),
|
|
20
20
|
addToRolesIds: optional(array(string)),
|
|
21
21
|
removeFromRolesIds: optional(array(string))
|
|
22
22
|
});
|
|
@@ -24,7 +24,7 @@ export const UpdatePermissionSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
|
24
24
|
export const PermissionSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
25
25
|
id: uuidId ? uuid : string,
|
|
26
26
|
slug: string,
|
|
27
|
-
|
|
27
|
+
providerFields: optional(unknown),
|
|
28
28
|
createdAt: optional(date),
|
|
29
29
|
updatedAt: optional(date)
|
|
30
30
|
});
|
|
@@ -11,21 +11,21 @@ import { PermissionSchema } from './permission.schema';
|
|
|
11
11
|
export const CreateRoleSchema = {
|
|
12
12
|
name: string,
|
|
13
13
|
permissionIds: optional(array(string)),
|
|
14
|
-
|
|
14
|
+
providerFields: optional(unknown)
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const UpdateRoleSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
18
18
|
id: uuidId ? uuid : string,
|
|
19
19
|
name: optional(string),
|
|
20
20
|
permissionIds: optional(array(string)),
|
|
21
|
-
|
|
21
|
+
providerFields: optional(unknown)
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
export const RoleSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
25
25
|
id: uuidId ? uuid : string,
|
|
26
26
|
name: string,
|
|
27
27
|
permissions: array(PermissionSchema({ uuidId })),
|
|
28
|
-
|
|
28
|
+
providerFields: optional(unknown),
|
|
29
29
|
createdAt: optional(date),
|
|
30
30
|
updatedAt: optional(date)
|
|
31
31
|
});
|
|
@@ -18,7 +18,7 @@ export const CreateUserSchema = {
|
|
|
18
18
|
roleIds: array(string),
|
|
19
19
|
phoneNumber: optional(string),
|
|
20
20
|
subscription: optional(string),
|
|
21
|
-
|
|
21
|
+
providerFields: optional(unknown)
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const UpdateUserSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
@@ -30,7 +30,7 @@ export const UpdateUserSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
|
30
30
|
roleIds: optional(array(string)),
|
|
31
31
|
phoneNumber: optional(string),
|
|
32
32
|
subscription: optional(string),
|
|
33
|
-
|
|
33
|
+
providerFields: optional(unknown)
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
export const UserSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
@@ -41,7 +41,7 @@ export const UserSchema = ({ uuidId }: { uuidId: boolean }) => ({
|
|
|
41
41
|
roles: array(RoleSchema({ uuidId })),
|
|
42
42
|
phoneNumber: optional(string),
|
|
43
43
|
subscription: optional(string),
|
|
44
|
-
|
|
44
|
+
providerFields: optional(unknown),
|
|
45
45
|
createdAt: optional(date),
|
|
46
46
|
updatedAt: optional(date)
|
|
47
47
|
});
|
|
@@ -5,69 +5,27 @@ import {
|
|
|
5
5
|
OpenTelemetryCollector,
|
|
6
6
|
TelemetryOptions
|
|
7
7
|
} from '@forklaunch/core/http';
|
|
8
|
-
import {
|
|
9
|
-
InternalDtoMapper,
|
|
10
|
-
RequestDtoMapperConstructor,
|
|
11
|
-
ResponseDtoMapperConstructor,
|
|
12
|
-
transformIntoInternalDtoMapper
|
|
13
|
-
} from '@forklaunch/core/mappers';
|
|
14
|
-
import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
|
|
15
8
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
16
9
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
InternalMapper,
|
|
11
|
+
RequestMapperConstructor,
|
|
12
|
+
ResponseMapperConstructor,
|
|
13
|
+
transformIntoInternalMapper
|
|
14
|
+
} from '@forklaunch/internal';
|
|
21
15
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
22
16
|
import { EntityManager } from '@mikro-orm/core';
|
|
17
|
+
import { OrganizationDtos } from '../types/iamDto.types';
|
|
18
|
+
import { OrganizationEntities } from '../types/iamEntities.types';
|
|
23
19
|
|
|
24
20
|
export class BaseOrganizationService<
|
|
25
21
|
SchemaValidator extends AnySchemaValidator,
|
|
26
22
|
OrganizationStatus,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
CreateOrganizationDtoMapper: CreateOrganizationDto;
|
|
31
|
-
UpdateOrganizationDtoMapper: UpdateOrganizationDto;
|
|
32
|
-
} = {
|
|
33
|
-
OrganizationDtoMapper: OrganizationDto<OrganizationStatus>;
|
|
34
|
-
CreateOrganizationDtoMapper: CreateOrganizationDto;
|
|
35
|
-
UpdateOrganizationDtoMapper: UpdateOrganizationDto;
|
|
36
|
-
},
|
|
37
|
-
Entities extends {
|
|
38
|
-
OrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
39
|
-
OrganizationDto<OrganizationStatus>,
|
|
40
|
-
'users'
|
|
41
|
-
>;
|
|
42
|
-
CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
43
|
-
OrganizationDto<OrganizationStatus>,
|
|
44
|
-
'users'
|
|
45
|
-
>;
|
|
46
|
-
UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
47
|
-
OrganizationDto<OrganizationStatus>,
|
|
48
|
-
'users'
|
|
49
|
-
>;
|
|
50
|
-
} = {
|
|
51
|
-
OrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
52
|
-
OrganizationDto<OrganizationStatus>,
|
|
53
|
-
'users'
|
|
54
|
-
>;
|
|
55
|
-
CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
56
|
-
OrganizationDto<OrganizationStatus>,
|
|
57
|
-
'users'
|
|
58
|
-
>;
|
|
59
|
-
UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
|
|
60
|
-
OrganizationDto<OrganizationStatus>,
|
|
61
|
-
'users'
|
|
62
|
-
>;
|
|
63
|
-
}
|
|
23
|
+
MapperEntities extends OrganizationEntities<OrganizationStatus>,
|
|
24
|
+
MapperDtos extends
|
|
25
|
+
OrganizationDtos<OrganizationStatus> = OrganizationDtos<OrganizationStatus>
|
|
64
26
|
> implements OrganizationService<OrganizationStatus>
|
|
65
27
|
{
|
|
66
|
-
|
|
67
|
-
InstanceTypeRecord<typeof this.mappers>,
|
|
68
|
-
Entities,
|
|
69
|
-
Dto
|
|
70
|
-
>;
|
|
28
|
+
protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
71
29
|
private evaluatedTelemetryOptions: {
|
|
72
30
|
logging?: boolean;
|
|
73
31
|
metrics?: boolean;
|
|
@@ -76,30 +34,38 @@ export class BaseOrganizationService<
|
|
|
76
34
|
|
|
77
35
|
constructor(
|
|
78
36
|
public em: EntityManager,
|
|
79
|
-
protected openTelemetryCollector: OpenTelemetryCollector<
|
|
37
|
+
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
80
38
|
protected schemaValidator: SchemaValidator,
|
|
81
39
|
protected mappers: {
|
|
82
|
-
|
|
40
|
+
OrganizationMapper: ResponseMapperConstructor<
|
|
83
41
|
SchemaValidator,
|
|
84
|
-
|
|
85
|
-
|
|
42
|
+
MapperDtos['OrganizationMapper'],
|
|
43
|
+
MapperEntities['OrganizationMapper']
|
|
86
44
|
>;
|
|
87
|
-
|
|
45
|
+
CreateOrganizationMapper: RequestMapperConstructor<
|
|
88
46
|
SchemaValidator,
|
|
89
|
-
|
|
90
|
-
|
|
47
|
+
MapperDtos['CreateOrganizationMapper'],
|
|
48
|
+
MapperEntities['CreateOrganizationMapper'],
|
|
49
|
+
(
|
|
50
|
+
dto: MapperDtos['CreateOrganizationMapper'],
|
|
51
|
+
em: EntityManager
|
|
52
|
+
) => Promise<MapperEntities['CreateOrganizationMapper']>
|
|
91
53
|
>;
|
|
92
|
-
|
|
54
|
+
UpdateOrganizationMapper: RequestMapperConstructor<
|
|
93
55
|
SchemaValidator,
|
|
94
|
-
|
|
95
|
-
|
|
56
|
+
MapperDtos['UpdateOrganizationMapper'],
|
|
57
|
+
MapperEntities['UpdateOrganizationMapper'],
|
|
58
|
+
(
|
|
59
|
+
dto: MapperDtos['UpdateOrganizationMapper'],
|
|
60
|
+
em: EntityManager
|
|
61
|
+
) => Promise<MapperEntities['UpdateOrganizationMapper']>
|
|
96
62
|
>;
|
|
97
63
|
},
|
|
98
64
|
options?: {
|
|
99
65
|
telemetry?: TelemetryOptions;
|
|
100
66
|
}
|
|
101
67
|
) {
|
|
102
|
-
this
|
|
68
|
+
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
103
69
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
104
70
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
105
71
|
: {
|
|
@@ -110,9 +76,9 @@ export class BaseOrganizationService<
|
|
|
110
76
|
}
|
|
111
77
|
|
|
112
78
|
async createOrganization(
|
|
113
|
-
organizationDto:
|
|
79
|
+
organizationDto: MapperDtos['CreateOrganizationMapper'],
|
|
114
80
|
em?: EntityManager
|
|
115
|
-
): Promise<
|
|
81
|
+
): Promise<MapperDtos['OrganizationMapper']> {
|
|
116
82
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
117
83
|
this.openTelemetryCollector.info(
|
|
118
84
|
'Creating organization',
|
|
@@ -121,7 +87,7 @@ export class BaseOrganizationService<
|
|
|
121
87
|
}
|
|
122
88
|
|
|
123
89
|
const organization =
|
|
124
|
-
await this
|
|
90
|
+
await this._mappers.CreateOrganizationMapper.deserializeDtoToEntity(
|
|
125
91
|
organizationDto,
|
|
126
92
|
em ?? this.em
|
|
127
93
|
);
|
|
@@ -132,15 +98,13 @@ export class BaseOrganizationService<
|
|
|
132
98
|
await this.em.persistAndFlush(organization);
|
|
133
99
|
}
|
|
134
100
|
|
|
135
|
-
return this
|
|
136
|
-
organization
|
|
137
|
-
);
|
|
101
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(organization);
|
|
138
102
|
}
|
|
139
103
|
|
|
140
104
|
async getOrganization(
|
|
141
105
|
idDto: IdDto,
|
|
142
106
|
em?: EntityManager
|
|
143
|
-
): Promise<
|
|
107
|
+
): Promise<MapperDtos['OrganizationMapper']> {
|
|
144
108
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
145
109
|
this.openTelemetryCollector.info('Getting organization', idDto);
|
|
146
110
|
}
|
|
@@ -150,15 +114,15 @@ export class BaseOrganizationService<
|
|
|
150
114
|
idDto
|
|
151
115
|
);
|
|
152
116
|
|
|
153
|
-
return this
|
|
154
|
-
organization as
|
|
117
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(
|
|
118
|
+
organization as MapperEntities['OrganizationMapper']
|
|
155
119
|
);
|
|
156
120
|
}
|
|
157
121
|
|
|
158
122
|
async updateOrganization(
|
|
159
|
-
organizationDto:
|
|
123
|
+
organizationDto: MapperDtos['UpdateOrganizationMapper'],
|
|
160
124
|
em?: EntityManager
|
|
161
|
-
): Promise<
|
|
125
|
+
): Promise<MapperDtos['OrganizationMapper']> {
|
|
162
126
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
163
127
|
this.openTelemetryCollector.info(
|
|
164
128
|
'Updating organization',
|
|
@@ -167,7 +131,7 @@ export class BaseOrganizationService<
|
|
|
167
131
|
}
|
|
168
132
|
|
|
169
133
|
const updatedOrganization =
|
|
170
|
-
await this
|
|
134
|
+
await this._mappers.UpdateOrganizationMapper.deserializeDtoToEntity(
|
|
171
135
|
organizationDto,
|
|
172
136
|
em ?? this.em
|
|
173
137
|
);
|
|
@@ -178,7 +142,7 @@ export class BaseOrganizationService<
|
|
|
178
142
|
await this.em.persistAndFlush(updatedOrganization);
|
|
179
143
|
}
|
|
180
144
|
|
|
181
|
-
return this
|
|
145
|
+
return this._mappers.OrganizationMapper.serializeEntityToDto(
|
|
182
146
|
updatedOrganization
|
|
183
147
|
);
|
|
184
148
|
}
|