@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { OrganizationDtos } from './iamDto.types';
|
|
3
|
+
import { OrganizationEntities } from './iamEntities.types';
|
|
4
|
+
|
|
5
|
+
export type OrganizationMappers<
|
|
6
|
+
OrganizationStatus,
|
|
7
|
+
MapperEntities extends OrganizationEntities<OrganizationStatus>,
|
|
8
|
+
MapperDomains extends OrganizationDtos<OrganizationStatus>
|
|
9
|
+
> = {
|
|
10
|
+
OrganizationMapper: {
|
|
11
|
+
toDto: (
|
|
12
|
+
entity: MapperEntities['OrganizationMapper']
|
|
13
|
+
) => Promise<MapperDomains['OrganizationMapper']>;
|
|
14
|
+
};
|
|
15
|
+
CreateOrganizationMapper: {
|
|
16
|
+
toEntity: (
|
|
17
|
+
dto: MapperDomains['CreateOrganizationMapper'],
|
|
18
|
+
em: EntityManager,
|
|
19
|
+
...args: unknown[]
|
|
20
|
+
) => Promise<MapperEntities['CreateOrganizationMapper']>;
|
|
21
|
+
};
|
|
22
|
+
UpdateOrganizationMapper: {
|
|
23
|
+
toEntity: (
|
|
24
|
+
dto: MapperDomains['UpdateOrganizationMapper'],
|
|
25
|
+
em: EntityManager,
|
|
26
|
+
...args: unknown[]
|
|
27
|
+
) => Promise<MapperEntities['UpdateOrganizationMapper']>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { PermissionDtos } from './iamDto.types';
|
|
3
|
+
import { PermissionEntities } from './iamEntities.types';
|
|
4
|
+
|
|
5
|
+
export type PermissionMappers<
|
|
6
|
+
MapperEntities extends PermissionEntities,
|
|
7
|
+
MapperDomains extends PermissionDtos
|
|
8
|
+
> = {
|
|
9
|
+
PermissionMapper: {
|
|
10
|
+
toDto: (
|
|
11
|
+
entity: MapperEntities['PermissionMapper']
|
|
12
|
+
) => Promise<MapperDomains['PermissionMapper']>;
|
|
13
|
+
};
|
|
14
|
+
CreatePermissionMapper: {
|
|
15
|
+
toEntity: (
|
|
16
|
+
dto: MapperDomains['CreatePermissionMapper'],
|
|
17
|
+
em: EntityManager,
|
|
18
|
+
...args: unknown[]
|
|
19
|
+
) => Promise<MapperEntities['CreatePermissionMapper']>;
|
|
20
|
+
};
|
|
21
|
+
UpdatePermissionMapper: {
|
|
22
|
+
toEntity: (
|
|
23
|
+
dto: MapperDomains['UpdatePermissionMapper'],
|
|
24
|
+
em: EntityManager,
|
|
25
|
+
...args: unknown[]
|
|
26
|
+
) => Promise<MapperEntities['UpdatePermissionMapper']>;
|
|
27
|
+
};
|
|
28
|
+
RoleEntityMapper: {
|
|
29
|
+
toEntity: (
|
|
30
|
+
dto: MapperDomains['RoleEntityMapper'],
|
|
31
|
+
em: EntityManager,
|
|
32
|
+
...args: unknown[]
|
|
33
|
+
) => Promise<MapperEntities['RoleEntityMapper']>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { RoleDtos } from './iamDto.types';
|
|
3
|
+
import { RoleEntities } from './iamEntities.types';
|
|
4
|
+
|
|
5
|
+
export type RoleMappers<
|
|
6
|
+
MapperEntities extends RoleEntities,
|
|
7
|
+
MapperDomains extends RoleDtos
|
|
8
|
+
> = {
|
|
9
|
+
RoleMapper: {
|
|
10
|
+
toDto: (
|
|
11
|
+
entity: MapperEntities['RoleMapper']
|
|
12
|
+
) => Promise<MapperDomains['RoleMapper']>;
|
|
13
|
+
};
|
|
14
|
+
CreateRoleMapper: {
|
|
15
|
+
toEntity: (
|
|
16
|
+
dto: MapperDomains['CreateRoleMapper'],
|
|
17
|
+
em: EntityManager,
|
|
18
|
+
...args: unknown[]
|
|
19
|
+
) => Promise<MapperEntities['CreateRoleMapper']>;
|
|
20
|
+
};
|
|
21
|
+
UpdateRoleMapper: {
|
|
22
|
+
toEntity: (
|
|
23
|
+
dto: MapperDomains['UpdateRoleMapper'],
|
|
24
|
+
em: EntityManager,
|
|
25
|
+
...args: unknown[]
|
|
26
|
+
) => Promise<MapperEntities['UpdateRoleMapper']>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { EntityManager } from '@mikro-orm/core';
|
|
2
|
+
import { UserDtos } from './iamDto.types';
|
|
3
|
+
import { UserEntities } from './iamEntities.types';
|
|
4
|
+
|
|
5
|
+
export type UserMappers<
|
|
6
|
+
MapperEntities extends UserEntities,
|
|
7
|
+
MapperDomains extends UserDtos
|
|
8
|
+
> = {
|
|
9
|
+
UserMapper: {
|
|
10
|
+
toDto: (
|
|
11
|
+
entity: MapperEntities['UserMapper']
|
|
12
|
+
) => Promise<MapperDomains['UserMapper']>;
|
|
13
|
+
};
|
|
14
|
+
CreateUserMapper: {
|
|
15
|
+
toEntity: (
|
|
16
|
+
dto: MapperDomains['CreateUserMapper'],
|
|
17
|
+
em: EntityManager,
|
|
18
|
+
...args: unknown[]
|
|
19
|
+
) => Promise<MapperEntities['CreateUserMapper']>;
|
|
20
|
+
};
|
|
21
|
+
UpdateUserMapper: {
|
|
22
|
+
toEntity: (
|
|
23
|
+
dto: MapperDomains['UpdateUserMapper'],
|
|
24
|
+
em: EntityManager,
|
|
25
|
+
...args: unknown[]
|
|
26
|
+
) => Promise<MapperEntities['UpdateUserMapper']>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IdDto
|
|
1
|
+
import { IdDto } from '@forklaunch/common';
|
|
2
2
|
import {
|
|
3
3
|
evaluateTelemetryOptions,
|
|
4
4
|
MetricsDefinition,
|
|
@@ -7,25 +7,25 @@ import {
|
|
|
7
7
|
} from '@forklaunch/core/http';
|
|
8
8
|
import { OrganizationService } from '@forklaunch/interfaces-iam/interfaces';
|
|
9
9
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
transformIntoInternalMapper
|
|
14
|
-
} from '@forklaunch/internal';
|
|
10
|
+
CreateOrganizationDto,
|
|
11
|
+
UpdateOrganizationDto
|
|
12
|
+
} from '@forklaunch/interfaces-iam/types';
|
|
15
13
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
16
14
|
import { EntityManager } from '@mikro-orm/core';
|
|
17
15
|
import { OrganizationDtos } from '../domain/types/iamDto.types';
|
|
18
16
|
import { OrganizationEntities } from '../domain/types/iamEntities.types';
|
|
17
|
+
import { OrganizationMappers } from '../domain/types/organization.mapper.types';
|
|
19
18
|
|
|
20
19
|
export class BaseOrganizationService<
|
|
21
20
|
SchemaValidator extends AnySchemaValidator,
|
|
22
|
-
OrganizationStatus,
|
|
23
|
-
MapperEntities extends
|
|
24
|
-
|
|
21
|
+
OrganizationStatus = unknown,
|
|
22
|
+
MapperEntities extends
|
|
23
|
+
OrganizationEntities<OrganizationStatus> = OrganizationEntities<OrganizationStatus>,
|
|
24
|
+
MapperDomains extends
|
|
25
25
|
OrganizationDtos<OrganizationStatus> = OrganizationDtos<OrganizationStatus>
|
|
26
26
|
> implements OrganizationService<OrganizationStatus>
|
|
27
27
|
{
|
|
28
|
-
protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
28
|
+
// protected _mappers: InternalMapper<InstanceTypeRecord<typeof this.mappers>>;
|
|
29
29
|
private evaluatedTelemetryOptions: {
|
|
30
30
|
logging?: boolean;
|
|
31
31
|
metrics?: boolean;
|
|
@@ -34,61 +34,21 @@ export class BaseOrganizationService<
|
|
|
34
34
|
public em: EntityManager;
|
|
35
35
|
protected openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
36
36
|
protected schemaValidator: SchemaValidator;
|
|
37
|
-
protected mappers:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
>;
|
|
43
|
-
CreateOrganizationMapper: RequestMapperConstructor<
|
|
44
|
-
SchemaValidator,
|
|
45
|
-
MapperDtos['CreateOrganizationMapper'],
|
|
46
|
-
MapperEntities['CreateOrganizationMapper'],
|
|
47
|
-
(
|
|
48
|
-
dto: MapperDtos['CreateOrganizationMapper'],
|
|
49
|
-
em: EntityManager
|
|
50
|
-
) => Promise<MapperEntities['CreateOrganizationMapper']>
|
|
51
|
-
>;
|
|
52
|
-
UpdateOrganizationMapper: RequestMapperConstructor<
|
|
53
|
-
SchemaValidator,
|
|
54
|
-
MapperDtos['UpdateOrganizationMapper'],
|
|
55
|
-
MapperEntities['UpdateOrganizationMapper'],
|
|
56
|
-
(
|
|
57
|
-
dto: MapperDtos['UpdateOrganizationMapper'],
|
|
58
|
-
em: EntityManager
|
|
59
|
-
) => Promise<MapperEntities['UpdateOrganizationMapper']>
|
|
60
|
-
>;
|
|
61
|
-
};
|
|
37
|
+
protected mappers: OrganizationMappers<
|
|
38
|
+
OrganizationStatus,
|
|
39
|
+
MapperEntities,
|
|
40
|
+
MapperDomains
|
|
41
|
+
>;
|
|
62
42
|
|
|
63
43
|
constructor(
|
|
64
44
|
em: EntityManager,
|
|
65
45
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
66
46
|
schemaValidator: SchemaValidator,
|
|
67
|
-
mappers:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
>;
|
|
73
|
-
CreateOrganizationMapper: RequestMapperConstructor<
|
|
74
|
-
SchemaValidator,
|
|
75
|
-
MapperDtos['CreateOrganizationMapper'],
|
|
76
|
-
MapperEntities['CreateOrganizationMapper'],
|
|
77
|
-
(
|
|
78
|
-
dto: MapperDtos['CreateOrganizationMapper'],
|
|
79
|
-
em: EntityManager
|
|
80
|
-
) => Promise<MapperEntities['CreateOrganizationMapper']>
|
|
81
|
-
>;
|
|
82
|
-
UpdateOrganizationMapper: RequestMapperConstructor<
|
|
83
|
-
SchemaValidator,
|
|
84
|
-
MapperDtos['UpdateOrganizationMapper'],
|
|
85
|
-
MapperEntities['UpdateOrganizationMapper'],
|
|
86
|
-
(
|
|
87
|
-
dto: MapperDtos['UpdateOrganizationMapper'],
|
|
88
|
-
em: EntityManager
|
|
89
|
-
) => Promise<MapperEntities['UpdateOrganizationMapper']>
|
|
90
|
-
>;
|
|
91
|
-
},
|
|
47
|
+
mappers: OrganizationMappers<
|
|
48
|
+
OrganizationStatus,
|
|
49
|
+
MapperEntities,
|
|
50
|
+
MapperDomains
|
|
51
|
+
>,
|
|
92
52
|
options?: {
|
|
93
53
|
telemetry?: TelemetryOptions;
|
|
94
54
|
}
|
|
@@ -97,7 +57,6 @@ export class BaseOrganizationService<
|
|
|
97
57
|
this.openTelemetryCollector = openTelemetryCollector;
|
|
98
58
|
this.schemaValidator = schemaValidator;
|
|
99
59
|
this.mappers = mappers;
|
|
100
|
-
this._mappers = transformIntoInternalMapper(mappers, schemaValidator);
|
|
101
60
|
this.evaluatedTelemetryOptions = options?.telemetry
|
|
102
61
|
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
103
62
|
: {
|
|
@@ -108,9 +67,10 @@ export class BaseOrganizationService<
|
|
|
108
67
|
}
|
|
109
68
|
|
|
110
69
|
async createOrganization(
|
|
111
|
-
organizationDto:
|
|
112
|
-
em?: EntityManager
|
|
113
|
-
|
|
70
|
+
organizationDto: CreateOrganizationDto,
|
|
71
|
+
em?: EntityManager,
|
|
72
|
+
...args: unknown[]
|
|
73
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
114
74
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
115
75
|
this.openTelemetryCollector.info(
|
|
116
76
|
'Creating organization',
|
|
@@ -118,11 +78,11 @@ export class BaseOrganizationService<
|
|
|
118
78
|
);
|
|
119
79
|
}
|
|
120
80
|
|
|
121
|
-
const organization =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
81
|
+
const organization = await this.mappers.CreateOrganizationMapper.toEntity(
|
|
82
|
+
organizationDto,
|
|
83
|
+
em ?? this.em,
|
|
84
|
+
...args
|
|
85
|
+
);
|
|
126
86
|
|
|
127
87
|
if (em) {
|
|
128
88
|
await em.persist(organization);
|
|
@@ -130,13 +90,13 @@ export class BaseOrganizationService<
|
|
|
130
90
|
await this.em.persistAndFlush(organization);
|
|
131
91
|
}
|
|
132
92
|
|
|
133
|
-
return this.
|
|
93
|
+
return this.mappers.OrganizationMapper.toDto(organization);
|
|
134
94
|
}
|
|
135
95
|
|
|
136
96
|
async getOrganization(
|
|
137
97
|
idDto: IdDto,
|
|
138
98
|
em?: EntityManager
|
|
139
|
-
): Promise<
|
|
99
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
140
100
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
141
101
|
this.openTelemetryCollector.info('Getting organization', idDto);
|
|
142
102
|
}
|
|
@@ -149,15 +109,16 @@ export class BaseOrganizationService<
|
|
|
149
109
|
}
|
|
150
110
|
);
|
|
151
111
|
|
|
152
|
-
return this.
|
|
112
|
+
return this.mappers.OrganizationMapper.toDto(
|
|
153
113
|
organization as MapperEntities['OrganizationMapper']
|
|
154
114
|
);
|
|
155
115
|
}
|
|
156
116
|
|
|
157
117
|
async updateOrganization(
|
|
158
|
-
organizationDto:
|
|
159
|
-
em?: EntityManager
|
|
160
|
-
|
|
118
|
+
organizationDto: UpdateOrganizationDto,
|
|
119
|
+
em?: EntityManager,
|
|
120
|
+
...args: unknown[]
|
|
121
|
+
): Promise<MapperDomains['OrganizationMapper']> {
|
|
161
122
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
162
123
|
this.openTelemetryCollector.info(
|
|
163
124
|
'Updating organization',
|
|
@@ -166,9 +127,10 @@ export class BaseOrganizationService<
|
|
|
166
127
|
}
|
|
167
128
|
|
|
168
129
|
const updatedOrganization =
|
|
169
|
-
await this.
|
|
130
|
+
await this.mappers.UpdateOrganizationMapper.toEntity(
|
|
170
131
|
organizationDto,
|
|
171
|
-
em ?? this.em
|
|
132
|
+
em ?? this.em,
|
|
133
|
+
...args
|
|
172
134
|
);
|
|
173
135
|
|
|
174
136
|
if (em) {
|
|
@@ -177,9 +139,7 @@ export class BaseOrganizationService<
|
|
|
177
139
|
await this.em.persistAndFlush(updatedOrganization);
|
|
178
140
|
}
|
|
179
141
|
|
|
180
|
-
return this.
|
|
181
|
-
updatedOrganization
|
|
182
|
-
);
|
|
142
|
+
return this.mappers.OrganizationMapper.toDto(updatedOrganization);
|
|
183
143
|
}
|
|
184
144
|
|
|
185
145
|
async deleteOrganization(idDto: IdDto, em?: EntityManager): Promise<void> {
|