@forklaunch/implementation-iam-base 0.1.4 → 0.1.5

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.
Files changed (73) hide show
  1. package/lib/__test__/schemaEquality.test.js +6 -6
  2. package/lib/eject/schemas/index.ts +4 -0
  3. package/lib/eject/schemas/organization.schema.ts +14 -12
  4. package/lib/eject/schemas/permission.schema.ts +7 -1
  5. package/lib/eject/schemas/role.schema.ts +17 -16
  6. package/lib/eject/schemas/user.schema.ts +21 -20
  7. package/lib/eject/services/index.ts +4 -0
  8. package/lib/eject/services/organization.service.ts +6 -6
  9. package/lib/eject/services/permission.service.ts +9 -6
  10. package/lib/eject/services/role.service.ts +6 -6
  11. package/lib/eject/services/user.service.ts +11 -9
  12. package/lib/schemas/index.d.ts +5 -0
  13. package/lib/schemas/index.d.ts.map +1 -0
  14. package/lib/schemas/index.js +4 -0
  15. package/lib/schemas/organization.schema.d.ts +140 -6
  16. package/lib/schemas/organization.schema.d.ts.map +1 -1
  17. package/lib/schemas/organization.schema.js +2 -12
  18. package/lib/schemas/permission.schema.d.ts.map +1 -1
  19. package/lib/schemas/permission.schema.js +2 -12
  20. package/lib/schemas/role.schema.d.ts +28 -4
  21. package/lib/schemas/role.schema.d.ts.map +1 -1
  22. package/lib/schemas/role.schema.js +2 -12
  23. package/lib/schemas/typebox/organization.schema.d.ts +81 -5
  24. package/lib/schemas/typebox/organization.schema.d.ts.map +1 -1
  25. package/lib/schemas/typebox/organization.schema.js +9 -3
  26. package/lib/schemas/typebox/permission.schema.d.ts +21 -0
  27. package/lib/schemas/typebox/permission.schema.d.ts.map +1 -1
  28. package/lib/schemas/typebox/permission.schema.js +5 -0
  29. package/lib/schemas/typebox/role.schema.d.ts +35 -4
  30. package/lib/schemas/typebox/role.schema.d.ts.map +1 -1
  31. package/lib/schemas/typebox/role.schema.js +8 -2
  32. package/lib/schemas/typebox/user.schema.d.ts +64 -4
  33. package/lib/schemas/typebox/user.schema.d.ts.map +1 -1
  34. package/lib/schemas/typebox/user.schema.js +8 -2
  35. package/lib/schemas/user.schema.d.ts +68 -4
  36. package/lib/schemas/user.schema.d.ts.map +1 -1
  37. package/lib/schemas/user.schema.js +2 -12
  38. package/lib/schemas/zod/organization.schema.d.ts +253 -5
  39. package/lib/schemas/zod/organization.schema.d.ts.map +1 -1
  40. package/lib/schemas/zod/organization.schema.js +9 -3
  41. package/lib/schemas/zod/permission.schema.d.ts +21 -0
  42. package/lib/schemas/zod/permission.schema.d.ts.map +1 -1
  43. package/lib/schemas/zod/permission.schema.js +5 -0
  44. package/lib/schemas/zod/role.schema.d.ts +59 -4
  45. package/lib/schemas/zod/role.schema.d.ts.map +1 -1
  46. package/lib/schemas/zod/role.schema.js +8 -2
  47. package/lib/schemas/zod/user.schema.d.ts +140 -4
  48. package/lib/schemas/zod/user.schema.d.ts.map +1 -1
  49. package/lib/schemas/zod/user.schema.js +8 -2
  50. package/lib/services/index.d.ts +5 -0
  51. package/lib/services/index.d.ts.map +1 -0
  52. package/lib/services/index.js +4 -0
  53. package/lib/services/organization.service.d.ts +2 -1
  54. package/lib/services/organization.service.d.ts.map +1 -1
  55. package/lib/services/permission.service.d.ts +2 -1
  56. package/lib/services/permission.service.d.ts.map +1 -1
  57. package/lib/services/role.service.d.ts +2 -1
  58. package/lib/services/role.service.d.ts.map +1 -1
  59. package/lib/services/user.service.d.ts +3 -3
  60. package/lib/services/user.service.d.ts.map +1 -1
  61. package/lib/tsconfig.tsbuildinfo +1 -1
  62. package/package.json +18 -8
  63. package/lib/eject/schemas/zod/organization.schema.ts +0 -49
  64. package/lib/eject/schemas/zod/permission.schema.ts +0 -30
  65. package/lib/eject/schemas/zod/role.schema.ts +0 -36
  66. package/lib/eject/schemas/zod/user.schema.ts +0 -52
  67. package/lib/eject/services/services/organization.service.ts +0 -146
  68. package/lib/eject/services/services/permission.service.ts +0 -349
  69. package/lib/eject/services/services/role.service.ts +0 -182
  70. package/lib/eject/services/services/user.service.ts +0 -225
  71. package/lib/index.d.ts +0 -9
  72. package/lib/index.d.ts.map +0 -1
  73. package/lib/index.js +0 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/implementation-iam-base",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Billing basic implementation for forklaunch",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -12,23 +12,33 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "author": "Forklift Technologies, Inc.",
15
+ "exports": {
16
+ "./schemas": {
17
+ "import": "./lib/schemas/index.js",
18
+ "types": "./lib/schemas/index.d.ts"
19
+ },
20
+ "./services": {
21
+ "import": "./lib/services/index.js",
22
+ "types": "./lib/services/index.d.ts"
23
+ }
24
+ },
15
25
  "files": [
16
26
  "lib/**"
17
27
  ],
18
28
  "dependencies": {
19
- "@forklaunch/common": "^0.2.5",
20
- "@forklaunch/core": "^0.6.0",
21
- "@forklaunch/validator": "^0.4.8",
22
- "@mikro-orm/core": "^6.4.11",
29
+ "@forklaunch/common": "^0.2.6",
30
+ "@forklaunch/core": "^0.6.2",
31
+ "@forklaunch/validator": "^0.4.10",
32
+ "@mikro-orm/core": "^6.4.12",
23
33
  "@sinclair/typebox": "^0.34.33",
24
34
  "ajv": "^8.17.1",
25
35
  "zod": "^3.24.2",
26
- "@forklaunch/interfaces-iam": "0.1.4"
36
+ "@forklaunch/interfaces-iam": "0.1.5"
27
37
  },
28
38
  "devDependencies": {
29
39
  "depcheck": "^1.4.7",
30
40
  "prettier": "^3.5.3",
31
- "typedoc": "^0.28.1"
41
+ "typedoc": "^0.28.2"
32
42
  },
33
43
  "scripts": {
34
44
  "build": "tsc && pnpm package:eject",
@@ -37,7 +47,7 @@
37
47
  "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
38
48
  "lint": "eslint . -c eslint.config.mjs",
39
49
  "lint:fix": "eslint . -c eslint.config.mjs --fix",
40
- "package:eject": "mkdir -p lib/eject && cp -r schemas/zod lib/eject/schemas && cp -r services lib/eject/services",
50
+ "package:eject": "rm -rf lib/eject && mkdir -p lib/eject && cp -r schemas/zod lib/eject/schemas && cp schemas/index.ts lib/eject/schemas && cp -r services lib/eject/services && find lib/eject -type f -name '*.ts' -exec sed -i '' 's|@forklaunch/validator/zod|@{{app_name}}/core|g' {} +",
41
51
  "test": "vitest --passWithNoTests"
42
52
  }
43
53
  }
@@ -1,49 +0,0 @@
1
- import { IdiomaticSchema, LiteralSchema } from '@forklaunch/validator';
2
- import {
3
- array,
4
- date,
5
- enum_,
6
- optional,
7
- string,
8
- unknown,
9
- uuid,
10
- ZodSchemaValidator
11
- } from '@forklaunch/validator/zod';
12
-
13
- export const CreateOrganizationSchema = {
14
- name: string,
15
- domain: string,
16
- subscription: string,
17
- logoUrl: optional(string),
18
- extraFields: optional(unknown)
19
- };
20
-
21
- export const UpdateOrganizationSchema = (uuidId: boolean) => ({
22
- id: uuidId ? uuid : string,
23
- name: optional(string),
24
- domain: optional(string),
25
- subscription: optional(string),
26
- logoUrl: optional(string),
27
- extraFields: optional(unknown)
28
- });
29
-
30
- export const OrganizationSchema =
31
- (uuidId: boolean) =>
32
- <
33
- UserDtoSchema extends IdiomaticSchema<ZodSchemaValidator>,
34
- OrganizationStatus extends Record<string, LiteralSchema>
35
- >(
36
- UserDtoSchema: UserDtoSchema,
37
- OrganizationStatus: OrganizationStatus
38
- ) => ({
39
- id: uuidId ? uuid : string,
40
- name: string,
41
- users: array(UserDtoSchema),
42
- domain: string,
43
- subscription: string,
44
- status: enum_(OrganizationStatus),
45
- logoUrl: optional(string),
46
- extraFields: optional(unknown),
47
- createdAt: optional(date),
48
- updatedAt: optional(date)
49
- });
@@ -1,30 +0,0 @@
1
- import {
2
- array,
3
- date,
4
- optional,
5
- string,
6
- unknown,
7
- uuid
8
- } from '@forklaunch/validator/zod';
9
-
10
- export const CreatePermissionSchema = {
11
- slug: string,
12
- addToRolesIds: optional(array(string)),
13
- extraFields: optional(unknown)
14
- };
15
-
16
- export const UpdatePermissionSchema = (uuidId: boolean) => ({
17
- id: uuidId ? uuid : string,
18
- slug: optional(string),
19
- extraFields: optional(unknown),
20
- addToRolesIds: optional(array(string)),
21
- removeFromRolesIds: optional(array(string))
22
- });
23
-
24
- export const PermissionSchema = (uuidId: boolean) => ({
25
- id: uuidId ? uuid : string,
26
- slug: string,
27
- extraFields: optional(unknown),
28
- createdAt: optional(date),
29
- updatedAt: optional(date)
30
- });
@@ -1,36 +0,0 @@
1
- import { IdiomaticSchema } from '@forklaunch/validator';
2
- import {
3
- array,
4
- date,
5
- optional,
6
- string,
7
- unknown,
8
- uuid,
9
- ZodSchemaValidator
10
- } from '@forklaunch/validator/zod';
11
-
12
- export const CreateRoleSchema = {
13
- name: string,
14
- permissionIds: optional(array(string)),
15
- extraFields: optional(unknown)
16
- };
17
-
18
- export const UpdateRoleSchema = (uuidId: boolean) => ({
19
- id: uuidId ? uuid : string,
20
- name: optional(string),
21
- permissionIds: optional(array(string)),
22
- extraFields: optional(unknown)
23
- });
24
-
25
- export const RoleSchema =
26
- (uuidId: boolean) =>
27
- <PermissionSchema extends IdiomaticSchema<ZodSchemaValidator>>(
28
- PermissionSchema: PermissionSchema
29
- ) => ({
30
- id: uuidId ? uuid : string,
31
- name: string,
32
- permissions: array(PermissionSchema),
33
- extraFields: optional(unknown),
34
- createdAt: optional(date),
35
- updatedAt: optional(date)
36
- });
@@ -1,52 +0,0 @@
1
- import { IdiomaticSchema } from '@forklaunch/validator';
2
- import {
3
- array,
4
- date,
5
- email,
6
- optional,
7
- string,
8
- unknown,
9
- uuid,
10
- ZodSchemaValidator
11
- } from '@forklaunch/validator/zod';
12
-
13
- export const CreateUserSchema = {
14
- email: email,
15
- password: string,
16
- firstName: string,
17
- lastName: string,
18
- organizationId: string,
19
- roleIds: array(string),
20
- phoneNumber: optional(string),
21
- subscription: optional(string),
22
- extraFields: optional(unknown)
23
- };
24
-
25
- export const UpdateUserSchema = (uuidId: boolean) => ({
26
- id: uuidId ? uuid : string,
27
- email: optional(email),
28
- password: optional(string),
29
- firstName: optional(string),
30
- lastName: optional(string),
31
- roleIds: optional(array(string)),
32
- phoneNumber: optional(string),
33
- subscription: optional(string),
34
- extraFields: optional(unknown)
35
- });
36
-
37
- export const UserSchema =
38
- (uuidId: boolean) =>
39
- <RoleDtoSchema extends IdiomaticSchema<ZodSchemaValidator>>(
40
- RoleDtoSchema: RoleDtoSchema
41
- ) => ({
42
- id: uuidId ? uuid : string,
43
- email: email,
44
- firstName: string,
45
- lastName: string,
46
- roles: array(RoleDtoSchema),
47
- phoneNumber: optional(string),
48
- subscription: optional(string),
49
- extraFields: optional(unknown),
50
- createdAt: optional(date),
51
- updatedAt: optional(date)
52
- });
@@ -1,146 +0,0 @@
1
- import {
2
- CreateOrganizationDto,
3
- OrganizationDto,
4
- OrganizationService,
5
- UpdateOrganizationDto
6
- } from '@forklaunch/interfaces-iam';
7
- import { IdDto, InstanceTypeRecord } from '@forklaunch/common';
8
- import {
9
- InternalDtoMapper,
10
- RequestDtoMapperConstructor,
11
- ResponseDtoMapperConstructor,
12
- transformIntoInternalDtoMapper
13
- } from '@forklaunch/core/dtoMapper';
14
- import {
15
- MetricsDefinition,
16
- OpenTelemetryCollector
17
- } from '@forklaunch/core/http';
18
- import { MapNestedDtoArraysToCollections } from '@forklaunch/core/services';
19
- import { AnySchemaValidator } from '@forklaunch/validator';
20
- import { EntityManager } from '@mikro-orm/core';
21
-
22
- export class BaseOrganizationService<
23
- SchemaValidator extends AnySchemaValidator,
24
- OrganizationStatus,
25
- Metrics extends MetricsDefinition = MetricsDefinition,
26
- Dto extends {
27
- OrganizationDtoMapper: OrganizationDto<OrganizationStatus>;
28
- CreateOrganizationDtoMapper: CreateOrganizationDto;
29
- UpdateOrganizationDtoMapper: UpdateOrganizationDto;
30
- } = {
31
- OrganizationDtoMapper: OrganizationDto<OrganizationStatus>;
32
- CreateOrganizationDtoMapper: CreateOrganizationDto;
33
- UpdateOrganizationDtoMapper: UpdateOrganizationDto;
34
- },
35
- Entities extends {
36
- OrganizationDtoMapper: MapNestedDtoArraysToCollections<
37
- OrganizationDto<OrganizationStatus>,
38
- 'users'
39
- >;
40
- CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
41
- OrganizationDto<OrganizationStatus>,
42
- 'users'
43
- >;
44
- UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
45
- OrganizationDto<OrganizationStatus>,
46
- 'users'
47
- >;
48
- } = {
49
- OrganizationDtoMapper: MapNestedDtoArraysToCollections<
50
- OrganizationDto<OrganizationStatus>,
51
- 'users'
52
- >;
53
- CreateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
54
- OrganizationDto<OrganizationStatus>,
55
- 'users'
56
- >;
57
- UpdateOrganizationDtoMapper: MapNestedDtoArraysToCollections<
58
- OrganizationDto<OrganizationStatus>,
59
- 'users'
60
- >;
61
- }
62
- > implements OrganizationService<OrganizationStatus>
63
- {
64
- #dtoMappers: InternalDtoMapper<
65
- InstanceTypeRecord<typeof this.dtoMappers>,
66
- Entities,
67
- Dto
68
- >;
69
-
70
- constructor(
71
- public em: EntityManager,
72
- protected openTelemetryCollector: OpenTelemetryCollector<Metrics>,
73
- protected schemaValidator: SchemaValidator,
74
- protected dtoMappers: {
75
- OrganizationDtoMapper: ResponseDtoMapperConstructor<
76
- SchemaValidator,
77
- Dto['OrganizationDtoMapper'],
78
- Entities['OrganizationDtoMapper']
79
- >;
80
- CreateOrganizationDtoMapper: RequestDtoMapperConstructor<
81
- SchemaValidator,
82
- Dto['CreateOrganizationDtoMapper'],
83
- Entities['CreateOrganizationDtoMapper']
84
- >;
85
- UpdateOrganizationDtoMapper: RequestDtoMapperConstructor<
86
- SchemaValidator,
87
- Dto['UpdateOrganizationDtoMapper'],
88
- Entities['UpdateOrganizationDtoMapper']
89
- >;
90
- }
91
- ) {
92
- this.#dtoMappers = transformIntoInternalDtoMapper(
93
- dtoMappers,
94
- schemaValidator
95
- );
96
- }
97
-
98
- async createOrganization(
99
- organizationDto: Dto['CreateOrganizationDtoMapper'],
100
- em?: EntityManager
101
- ): Promise<Dto['OrganizationDtoMapper']> {
102
- this.openTelemetryCollector.log('info', 'Creating organization');
103
- const organization =
104
- this.#dtoMappers.CreateOrganizationDtoMapper.deserializeDtoToEntity(
105
- organizationDto
106
- );
107
- await (em ?? this.em).transactional(async (innerEm) => {
108
- await innerEm.persist(organization);
109
- });
110
-
111
- return this.#dtoMappers.OrganizationDtoMapper.serializeEntityToDto(
112
- organization
113
- );
114
- }
115
-
116
- async getOrganization(
117
- idDto: IdDto,
118
- em?: EntityManager
119
- ): Promise<Dto['OrganizationDtoMapper']> {
120
- const organization = await (em ?? this.em).findOneOrFail(
121
- 'Organization',
122
- idDto
123
- );
124
- return this.#dtoMappers.OrganizationDtoMapper.serializeEntityToDto(
125
- organization as Entities['OrganizationDtoMapper']
126
- );
127
- }
128
-
129
- async updateOrganization(
130
- organizationDto: Dto['UpdateOrganizationDtoMapper'],
131
- em?: EntityManager
132
- ): Promise<Dto['OrganizationDtoMapper']> {
133
- const updatedOrganization =
134
- this.#dtoMappers.UpdateOrganizationDtoMapper.deserializeDtoToEntity(
135
- organizationDto
136
- );
137
- await (em ?? this.em).upsert(updatedOrganization);
138
- return this.#dtoMappers.OrganizationDtoMapper.serializeEntityToDto(
139
- updatedOrganization
140
- );
141
- }
142
-
143
- async deleteOrganization(idDto: IdDto, em?: EntityManager): Promise<void> {
144
- await (em ?? this.em).nativeDelete('Organization', idDto);
145
- }
146
- }