@forklaunch/interfaces-iam 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 forklaunch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './interfaces/organization.service.interface';
2
+ export * from './interfaces/permission.service.interface';
3
+ export * from './interfaces/role.service.interface';
4
+ export * from './interfaces/user.service.interface';
@@ -0,0 +1,45 @@
1
+ import { IdDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+ import { UserDto } from './user.service.interface';
4
+
5
+ export type CreateOrganizationDto = {
6
+ name: string;
7
+ domain: string;
8
+ subscription: string;
9
+ logoUrl?: string;
10
+ extraFields?: unknown;
11
+ };
12
+ export type UpdateOrganizationDto = IdDto & Partial<CreateOrganizationDto>;
13
+ export type OrganizationDto<OrganizationStatus> = IdDto &
14
+ CreateOrganizationDto &
15
+ Partial<RecordTimingDto> & {
16
+ users: UserDto[];
17
+ status: OrganizationStatus[keyof OrganizationStatus];
18
+ };
19
+
20
+ export type OrganizationServiceParameters<OrganizationStatus> = {
21
+ CreateOrganizationDto: CreateOrganizationDto;
22
+ OrganizationDto: OrganizationDto<OrganizationStatus>;
23
+ UpdateOrganizationDto: UpdateOrganizationDto;
24
+ IdDto: IdDto;
25
+ };
26
+
27
+ export interface OrganizationService<
28
+ OrganizationStatus,
29
+ Params extends
30
+ OrganizationServiceParameters<OrganizationStatus> = OrganizationServiceParameters<OrganizationStatus>
31
+ > {
32
+ createOrganization(
33
+ organizationDto: Params['CreateOrganizationDto'],
34
+ em?: EntityManager
35
+ ): Promise<Params['OrganizationDto']>;
36
+ getOrganization(
37
+ idDto: Params['IdDto'],
38
+ em?: EntityManager
39
+ ): Promise<Params['OrganizationDto']>;
40
+ updateOrganization(
41
+ organizationDto: Params['UpdateOrganizationDto'],
42
+ em?: EntityManager
43
+ ): Promise<Params['OrganizationDto']>;
44
+ deleteOrganization(idDto: Params['IdDto'], em?: EntityManager): Promise<void>;
45
+ }
@@ -0,0 +1,58 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+
4
+ export type CreatePermissionDto = {
5
+ slug: string;
6
+ addToRolesIds?: string[];
7
+ extraFields?: unknown;
8
+ };
9
+ export type UpdatePermissionDto = IdDto &
10
+ Partial<CreatePermissionDto> & {
11
+ removeFromRolesIds?: string[];
12
+ };
13
+ export type PermissionDto = IdDto &
14
+ Partial<RecordTimingDto> & {
15
+ slug: string;
16
+ };
17
+
18
+ export type PermissionServiceParameters = {
19
+ CreatePermissionDto: CreatePermissionDto;
20
+ PermissionDto: PermissionDto;
21
+ UpdatePermissionDto: UpdatePermissionDto;
22
+ IdDto: IdDto;
23
+ IdsDto: IdsDto;
24
+ };
25
+
26
+ export interface PermissionService<
27
+ Params extends PermissionServiceParameters = PermissionServiceParameters
28
+ > {
29
+ createPermission(
30
+ permissionDto: Params['CreatePermissionDto'],
31
+ em?: EntityManager
32
+ ): Promise<Params['PermissionDto']>;
33
+ createBatchPermissions(
34
+ permissionDtos: Params['CreatePermissionDto'][],
35
+ em?: EntityManager
36
+ ): Promise<Params['PermissionDto'][]>;
37
+ getPermission(
38
+ idDto: Params['IdDto'],
39
+ em?: EntityManager
40
+ ): Promise<Params['PermissionDto']>;
41
+ getBatchPermissions(
42
+ idsDto: Params['IdsDto'],
43
+ em?: EntityManager
44
+ ): Promise<Params['PermissionDto'][]>;
45
+ updatePermission(
46
+ permissionDto: Params['UpdatePermissionDto'],
47
+ em?: EntityManager
48
+ ): Promise<Params['PermissionDto']>;
49
+ updateBatchPermissions(
50
+ permissionDtos: Params['UpdatePermissionDto'][],
51
+ em?: EntityManager
52
+ ): Promise<Params['PermissionDto'][]>;
53
+ deletePermission(idDto: Params['IdDto'], em?: EntityManager): Promise<void>;
54
+ deleteBatchPermissions(
55
+ idsDto: Params['IdsDto'],
56
+ em?: EntityManager
57
+ ): Promise<void>;
58
+ }
@@ -0,0 +1,54 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+ import { PermissionDto } from './permission.service.interface';
4
+
5
+ export type CreateRoleDto = {
6
+ name: string;
7
+ permissionsIds?: PermissionDto[];
8
+ extraFields?: unknown;
9
+ };
10
+ export type UpdateRoleDto = IdDto & Partial<CreateRoleDto>;
11
+ export type RoleDto = IdDto &
12
+ Omit<CreateRoleDto, 'permissionsIds'> &
13
+ Partial<RecordTimingDto> & {
14
+ permissions: PermissionDto[];
15
+ };
16
+
17
+ export type RoleServiceParameters = {
18
+ CreateRoleDto: CreateRoleDto;
19
+ RoleDto: RoleDto;
20
+ UpdateRoleDto: UpdateRoleDto;
21
+ IdDto: IdDto;
22
+ IdsDto: IdsDto;
23
+ };
24
+
25
+ export interface RoleService<
26
+ Params extends RoleServiceParameters = RoleServiceParameters
27
+ > {
28
+ createRole(
29
+ roleDto: Params['CreateRoleDto'],
30
+ em?: EntityManager
31
+ ): Promise<Params['RoleDto']>;
32
+ createBatchRoles(
33
+ roleDtos: Params['CreateRoleDto'][],
34
+ em?: EntityManager
35
+ ): Promise<Params['RoleDto'][]>;
36
+ getRole(
37
+ idDto: Params['IdDto'],
38
+ em?: EntityManager
39
+ ): Promise<Params['RoleDto']>;
40
+ getBatchRoles(
41
+ idsDto: Params['IdsDto'],
42
+ em?: EntityManager
43
+ ): Promise<Params['RoleDto'][]>;
44
+ updateRole(
45
+ roleDto: Params['UpdateRoleDto'],
46
+ em?: EntityManager
47
+ ): Promise<Params['RoleDto']>;
48
+ updateBatchRoles(
49
+ roleDtos: Params['UpdateRoleDto'][],
50
+ em?: EntityManager
51
+ ): Promise<Params['RoleDto'][]>;
52
+ deleteRole(idDto: Params['IdDto'], em?: EntityManager): Promise<void>;
53
+ deleteBatchRoles(idsDto: Params['IdsDto'], em?: EntityManager): Promise<void>;
54
+ }
@@ -0,0 +1,73 @@
1
+ import { IdDto, IdsDto, RecordTimingDto } from '@forklaunch/common';
2
+ import { EntityManager } from '@mikro-orm/core';
3
+ import { RoleDto } from './role.service.interface';
4
+
5
+ export type CreateUserDto = {
6
+ email: string;
7
+ password: string;
8
+ firstName: string;
9
+ lastName: string;
10
+ organizationId: string;
11
+ roleIds: string[];
12
+ phoneNumber?: string;
13
+ subscription?: string;
14
+ extraFields?: unknown;
15
+ };
16
+ export type UpdateUserDto = IdDto &
17
+ Partial<Omit<CreateUserDto, 'organizationId'>>;
18
+
19
+ export type UserDto = IdDto &
20
+ Omit<CreateUserDto, 'roleIds' | 'password' | 'organizationId'> &
21
+ Partial<RecordTimingDto> & {
22
+ roles: RoleDto[];
23
+ };
24
+
25
+ export type UserServiceParameters = {
26
+ CreateUserDto: CreateUserDto;
27
+ UserDto: UserDto;
28
+ UpdateUserDto: UpdateUserDto;
29
+ IdDto: IdDto;
30
+ IdsDto: IdsDto;
31
+ };
32
+
33
+ export interface UserService<
34
+ Params extends UserServiceParameters = UserServiceParameters
35
+ > {
36
+ createUser(
37
+ userDto: Params['CreateUserDto'],
38
+ em?: EntityManager
39
+ ): Promise<Params['UserDto']>;
40
+ createBatchUsers(
41
+ userDtos: Params['CreateUserDto'][],
42
+ em?: EntityManager
43
+ ): Promise<Params['UserDto'][]>;
44
+ getUser(
45
+ idDto: Params['IdDto'],
46
+ em?: EntityManager
47
+ ): Promise<Params['UserDto']>;
48
+ getBatchUsers(
49
+ idsDto: Params['IdsDto'],
50
+ em?: EntityManager
51
+ ): Promise<Params['UserDto'][]>;
52
+ updateUser(
53
+ userDto: Params['UpdateUserDto'],
54
+ em?: EntityManager
55
+ ): Promise<Params['UserDto']>;
56
+ updateBatchUsers(
57
+ userDtos: Params['UpdateUserDto'][],
58
+ em?: EntityManager
59
+ ): Promise<Params['UserDto'][]>;
60
+ deleteUser(idDto: Params['IdDto'], em?: EntityManager): Promise<void>;
61
+ deleteBatchUsers(idsDto: Params['IdsDto'], em?: EntityManager): Promise<void>;
62
+
63
+ verifyHasRole(
64
+ idDto: Params['IdDto'],
65
+ roleId: string,
66
+ em?: EntityManager
67
+ ): Promise<void>;
68
+ verifyHasPermission(
69
+ idDto: Params['IdDto'],
70
+ permissionId: string,
71
+ em?: EntityManager
72
+ ): Promise<void>;
73
+ }
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@forklaunch/interfaces-iam",
3
+ "version": "0.1.0",
4
+ "description": "IAM interfaces for forklaunch",
5
+ "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/forklaunch/forklaunch-js/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/forklaunch/forklaunch-js.git"
12
+ },
13
+ "license": "MIT",
14
+ "author": "Forklift Technologies, Inc.",
15
+ "main": "server.ts",
16
+ "dependencies": {
17
+ "@forklaunch/common": "^0.2.5",
18
+ "@mikro-orm/core": "^6.4.11"
19
+ },
20
+ "devDependencies": {
21
+ "depcheck": "^1.4.7",
22
+ "prettier": "^3.5.3",
23
+ "typedoc": "^0.28.1"
24
+ },
25
+ "mikro-orm": {
26
+ "configPaths": [
27
+ "./mikro-orm.config.ts",
28
+ "./dist/mikro-orm.config.js"
29
+ ]
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "clean": "rm -rf dist pnpm.lock.yaml node_modules",
34
+ "docs": "typedoc --out docs *",
35
+ "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
36
+ "lint": "eslint . -c eslint.config.mjs",
37
+ "lint:fix": "eslint . -c eslint.config.mjs --fix",
38
+ "start": "ENV_FILE_PATH=.env.local NODE_OPTIONS='--import=tsx' node dist/server.js",
39
+ "start:bun": "bun run migrate:up && bun dist/server.js",
40
+ "test": "vitest --passWithNoTests"
41
+ }
42
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "exclude": ["node_modules", "dist", "eslint.config.mjs"]
7
+ }