@merkaly/api 0.1.5 → 0.1.9-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/package.json CHANGED
@@ -1,87 +1,80 @@
1
1
  {
2
2
  "name": "@merkaly/api",
3
- "version": "0.1.5",
3
+ "version": "0.1.9-2",
4
4
  "description": "NestJS Backend ApiRest Service",
5
5
  "author": "Randy Tellez Galan <kronhyx@gmail.com>",
6
6
  "license": "UNLICENSED",
7
7
  "main": "src",
8
- "files": [
9
- "!src/app.*.*",
10
- "!src/**/*.module.*",
11
- "!src/**/*.controller.*",
12
- "!src/**/*.repository.*",
13
- "src/**/*.entity.ts",
14
- "src/**/*.validator.ts"
15
- ],
16
8
  "scripts": {
17
- "prebuild": "npm run clean",
18
- "prepack": "npm run build",
19
- "build": "tsc --b",
9
+ "prebuild": "yarn run clean",
10
+ "prepack": "yarn build",
11
+ "build": "nest build",
20
12
  "clean": "tsc -b --clean",
21
13
  "start": "nest start --preserveWatchOutput",
22
- "dev": "npm run clean && npm start -- --watch",
23
- "start:debug": "npm run dev -- --debug ",
14
+ "dev": "yarn run clean && npm start -- --watch",
15
+ "start:debug": "yarn dev -- --debug ",
24
16
  "start:prod": "node dist/index.js",
25
17
  "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" . ",
26
18
  "test": "jest",
27
- "test:watch": "npm run test -- --watch",
28
- "test:cov": "npm run test -- --coverage",
19
+ "test:watch": "yarn test -- --watch",
20
+ "test:cov": "yarn test -- --coverage",
29
21
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
30
- "semantic-release": "npm run build:package && semantic-release"
22
+ "semantic-release": "yarn run build:package && semantic-release"
31
23
  },
32
24
  "dependencies": {
25
+ "@nestjs/axios": "^0.0.5",
33
26
  "@nestjs/swagger": "^5.0.9",
34
27
  "@types/auth0": "^2.33.4",
35
- "@types/node": "^16.0.0",
28
+ "@types/node": "^17.0.2",
36
29
  "auth0": "^2.35.0",
37
- "class-transformer": "^0.4.0",
30
+ "class-transformer": "^0.5.1",
38
31
  "class-validator": "^0.13.1",
39
- "fireorm": "^0.22.0",
32
+ "fireorm": "^0.23.0",
40
33
  "reflect-metadata": "^0.1.13"
41
34
  },
42
35
  "devDependencies": {
43
- "@commitlint/config-conventional": "^13.1.0",
36
+ "@commitlint/config-conventional": "^16.0.0",
44
37
  "@elastic/elasticsearch": "^7.13.0",
45
- "@nestjs/cli": "8.1.1",
46
- "@nestjs/common": "8.0.6",
38
+ "@nestjs/cli": "8.2.0",
39
+ "@nestjs/common": "8.2.6",
47
40
  "@nestjs/config": "^1.0.0",
48
- "@nestjs/core": "8.0.6",
41
+ "@nestjs/core": "8.2.6",
49
42
  "@nestjs/elasticsearch": "8.0.0",
50
43
  "@nestjs/event-emitter": "^1.0.0",
51
44
  "@nestjs/jwt": "8.0.0",
52
- "@nestjs/passport": "8.0.1",
53
- "@nestjs/platform-express": "8.0.6",
54
- "@nestjs/schematics": "8.0.2",
55
- "@nestjs/testing": "8.0.6",
56
- "@semantic-release/exec": "^5.0.0",
57
- "@semantic-release/git": "^9.0.0",
45
+ "@nestjs/passport": "8.1.0",
46
+ "@nestjs/platform-express": "8.2.6",
47
+ "@nestjs/schematics": "8.0.5",
48
+ "@nestjs/testing": "8.2.6",
49
+ "@semantic-release/exec": "^6.0.1",
50
+ "@semantic-release/git": "^10.0.0",
58
51
  "@types/express": "^4.17.12",
59
- "@types/faker": "^5.5.6",
52
+ "@types/faker": "^5.5.9",
60
53
  "@types/jest": "^27.0.0",
61
54
  "@types/multer": "^1.4.7",
62
55
  "@types/passport-jwt": "^3.0.5",
63
56
  "@types/supertest": "^2.0.11",
64
- "@typescript-eslint/eslint-plugin": "4.29.2",
65
- "@typescript-eslint/parser": "4.29.2",
57
+ "@typescript-eslint/eslint-plugin": "4.33.0",
58
+ "@typescript-eslint/parser": "4.33.0",
59
+ "commitlint": "^16.1.0",
66
60
  "eslint": "7.32.0",
67
61
  "eslint-plugin-import": "^2.23.4",
68
62
  "faker": "^5.5.3",
69
- "firebase": "^8.6.8",
70
- "firebase-admin": "^9.9.0",
63
+ "firebase": "^9.0.0",
64
+ "firebase-admin": "^10.0.2",
71
65
  "husky": "^7.0.0",
72
- "jest": "27.0.6",
66
+ "jest": "27.4.7",
73
67
  "passport": "^0.4.1",
74
68
  "passport-jwt": "^4.0.0",
75
69
  "rimraf": "^3.0.2",
76
70
  "rxjs": "^7.2.0",
77
- "semantic-release": "^17.4.4",
71
+ "semantic-release": "^18.0.0",
78
72
  "supertest": "^6.1.3",
79
73
  "swagger-ui-express": "^4.1.5",
80
- "ts-jest": "27.0.5",
74
+ "ts-jest": "27.1.3",
81
75
  "ts-loader": "^9.2.3",
82
76
  "ts-node": "^10.0.0",
83
- "tsconfig-paths": "^3.9.0",
84
- "typescript": "^4.3.4"
77
+ "tsconfig-paths": "^3.9.0"
85
78
  },
86
79
  "repository": {
87
80
  "type": "git",
@@ -0,0 +1,2 @@
1
+ export declare type AddOrganizationMembers = string[];
2
+ export declare type RemoveOrganizationMembers = string[];
@@ -0,0 +1,3 @@
1
+ export type AddOrganizationMembers = string[]
2
+
3
+ export type RemoveOrganizationMembers = string[]
@@ -1,3 +1,4 @@
1
+ import { Organization } from 'auth0';
1
2
  import AppEntity from '../../app.entity';
2
3
  export interface OrganizationBrandingColors {
3
4
  page_background: string;
@@ -7,9 +8,10 @@ export interface OrganizationBranding {
7
8
  logo_url: string;
8
9
  colors: OrganizationBrandingColors;
9
10
  }
10
- export declare class OrganizationEntity extends AppEntity {
11
+ export declare class OrganizationEntity extends AppEntity implements Organization {
11
12
  static readonly $path = "organizations";
12
13
  name: string;
13
14
  display_name: string;
14
15
  branding: OrganizationBranding;
16
+ metadata: Record<string, string>;
15
17
  }
@@ -1,3 +1,4 @@
1
+ import { Organization } from 'auth0'
1
2
  import AppEntity from '../../app.entity'
2
3
 
3
4
  export interface OrganizationBrandingColors {
@@ -10,7 +11,7 @@ export interface OrganizationBranding {
10
11
  colors: OrganizationBrandingColors
11
12
  }
12
13
 
13
- export class OrganizationEntity extends AppEntity {
14
+ export class OrganizationEntity extends AppEntity implements Organization {
14
15
  static readonly $path = 'organizations'
15
16
 
16
17
  public name: string
@@ -18,4 +19,6 @@ export class OrganizationEntity extends AppEntity {
18
19
  public display_name: string
19
20
 
20
21
  public branding: OrganizationBranding
22
+
23
+ public metadata: Record<string, string>
21
24
  }
@@ -1,41 +1,52 @@
1
+ import { ApiProperty } from '@nestjs/swagger'
1
2
  import { IsHexColor, IsOptional, IsString, IsUrl } from 'class-validator'
3
+ import { company, image, internet, lorem } from 'faker'
2
4
 
3
5
  export class CreateOrganizationValidator {
4
6
 
5
7
  @IsString()
8
+ @ApiProperty({ example: lorem.word(8) })
6
9
  name: string
7
10
 
8
11
  @IsString()
12
+ @ApiProperty({ example: company.companyName() })
9
13
  display_name: string
10
14
 
11
15
  @IsUrl({})
12
16
  @IsOptional()
17
+ @ApiProperty({ required: false, example: image.avatar() })
13
18
  logo_url?: string
14
19
 
15
20
  @IsHexColor()
16
21
  @IsOptional()
22
+ @ApiProperty({ required: false, example: internet.color() })
17
23
  primary_color?: string
18
24
 
19
25
  @IsHexColor()
20
26
  @IsOptional()
27
+ @ApiProperty({ required: false, example: internet.color() })
21
28
  secondary_color?: string
22
29
  }
23
30
 
24
31
  export class UpdateOrganizationValidator {
25
32
  @IsString()
26
33
  @IsOptional()
34
+ @ApiProperty({ required: false })
27
35
  display_name?: string
28
36
 
29
37
  @IsUrl()
30
38
  @IsOptional()
39
+ @ApiProperty({ required: false, example: image.avatar() })
31
40
  logo_url?: string
32
41
 
33
42
  @IsHexColor()
34
43
  @IsOptional()
44
+ @ApiProperty({ required: false, example: internet.color() })
35
45
  primary_color?: string
36
46
 
37
47
  @IsString()
38
48
  @IsHexColor()
39
49
  @IsOptional()
50
+ @ApiProperty({ required: false, example: internet.color() })
40
51
  secondary_color?: string
41
52
  }
@@ -1,4 +1,2 @@
1
- export declare class AddRoleUserValidator {
2
- name: string;
3
- description: string;
4
- }
1
+ export declare type AddRoleUsers = string[];
2
+ export declare type RemoveRoleUsers = string[];
@@ -1,10 +1,3 @@
1
- import { IsOptional, IsString } from 'class-validator'
1
+ export type AddRoleUsers = string[]
2
2
 
3
- export class AddRoleUserValidator {
4
- @IsString()
5
- name: string
6
-
7
- @IsString()
8
- @IsOptional()
9
- description: string
10
- }
3
+ export type RemoveRoleUsers = string[]
@@ -1,4 +1,2 @@
1
- export declare class AddRoleValidator {
2
- name: string;
3
- description: string;
4
- }
1
+ export declare type AddUserRole = string[];
2
+ export declare type RemoveUserRole = string[];
@@ -1,10 +1,3 @@
1
- import { IsOptional, IsString } from 'class-validator'
1
+ export type AddUserRole = string[]
2
2
 
3
- export class AddRoleValidator {
4
- @IsString()
5
- name: string
6
-
7
- @IsString()
8
- @IsOptional()
9
- description: string
10
- }
3
+ export type RemoveUserRole = string[]
@@ -2,10 +2,10 @@ import { UpdateUserData, UserData } from 'auth0';
2
2
  export declare class CreateUserValidator implements UserData {
3
3
  email: string;
4
4
  password: string;
5
- phone_number: string;
6
5
  name: string;
7
6
  }
8
7
  export declare class UpdateUserValidator implements UpdateUserData {
9
- phone_number: string;
10
- name: string;
8
+ name?: string;
9
+ nickname?: string;
10
+ picture?: string;
11
11
  }
@@ -1,5 +1,5 @@
1
1
  import { UpdateUserData, UserData } from 'auth0'
2
- import { IsEmail, IsOptional, IsString } from 'class-validator'
2
+ import { IsEmail, IsOptional, IsString, IsUrl } from 'class-validator'
3
3
 
4
4
  export class CreateUserValidator implements UserData {
5
5
  @IsEmail()
@@ -8,10 +8,6 @@ export class CreateUserValidator implements UserData {
8
8
  @IsString()
9
9
  password: string
10
10
 
11
- @IsOptional()
12
- @IsString()
13
- phone_number: string
14
-
15
11
  @IsOptional()
16
12
  @IsString()
17
13
  name: string
@@ -21,9 +17,13 @@ export class CreateUserValidator implements UserData {
21
17
  export class UpdateUserValidator implements UpdateUserData {
22
18
  @IsOptional()
23
19
  @IsString()
24
- phone_number: string
20
+ name?: string
25
21
 
26
22
  @IsOptional()
27
23
  @IsString()
28
- name: string
24
+ nickname?: string
25
+
26
+ @IsOptional()
27
+ @IsUrl()
28
+ picture?: string
29
29
  }
package/src/app.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { EventEmitter2 } from '@nestjs/event-emitter';
2
+ import { event, eventNS } from 'eventemitter2';
3
+ export declare enum AbstractEvent {
4
+ ENTITY_LISTED = "entity.*.listed",
5
+ ENTITY_READED = "entity.*.readed",
6
+ ENTITY_CREATED = "entity.*.created",
7
+ ENTITY_UPDATED = "entity.*.updated",
8
+ ENTITY_DELETED = "entity.*.deleted",
9
+ ENTITY_NOT_FOUND = "entity.*.not_found",
10
+ ENTITY_SYNCED = "entity.*.synced"
11
+ }
12
+ export default class AppEmitter {
13
+ protected readonly emitter: EventEmitter2;
14
+ emit(event: event | eventNS, ...values: any[]): boolean;
15
+ private handleAllEvents;
16
+ }
@@ -0,0 +1,27 @@
1
+ import { Inject, Injectable, Logger } from '@nestjs/common'
2
+ import { EventEmitter2, OnEvent } from '@nestjs/event-emitter'
3
+ import { event, eventNS } from 'eventemitter2'
4
+
5
+ export enum AbstractEvent {
6
+ ENTITY_LISTED = 'entity.*.listed',
7
+ ENTITY_READED = 'entity.*.readed',
8
+ ENTITY_CREATED = 'entity.*.created',
9
+ ENTITY_UPDATED = 'entity.*.updated',
10
+ ENTITY_DELETED = 'entity.*.deleted',
11
+ ENTITY_NOT_FOUND = 'entity.*.not_found',
12
+ ENTITY_SYNCED = 'entity.*.synced',
13
+ }
14
+
15
+ @Injectable()
16
+ export default class AppEmitter {
17
+ @Inject() protected readonly emitter: EventEmitter2
18
+
19
+ public emit (event: event | eventNS, ...values: any[]) {
20
+ return this.emitter.emit(event, values)
21
+ }
22
+
23
+ @OnEvent('*.*.*')
24
+ private handleAllEvents (payload: any, name: string) {
25
+ return Logger.debug(`Event '${name}' has emitted an ${typeof payload}`, AppEmitter.name)
26
+ }
27
+ }
@@ -0,0 +1,7 @@
1
+ import { TransformFnParams } from 'class-transformer';
2
+ import { IEntity } from 'fireorm';
3
+ export default abstract class AppEntity implements IEntity {
4
+ static readonly $path: string;
5
+ id: string;
6
+ static transformSubCollection({ value }: TransformFnParams): string;
7
+ }
package/src/app.entity.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TransformFnParams } from 'class-transformer'
2
- import { firestore } from 'firebase-admin'
3
2
  import { IEntity } from 'fireorm'
4
3
 
5
4
  export default abstract class AppEntity implements IEntity {
@@ -11,10 +10,4 @@ export default abstract class AppEntity implements IEntity {
11
10
  return value.path
12
11
  }
13
12
 
14
- public static async setReference (value: string): Promise<any> {
15
- const { ref } = await firestore().collection(this.$path).doc(value).get()
16
-
17
- return ref
18
- }
19
-
20
13
  }
@@ -0,0 +1,3 @@
1
+ import { RouteTree } from '@nestjs/core/router/interfaces/routes.interface';
2
+ declare const routes: RouteTree[];
3
+ export default routes;
@@ -0,0 +1,61 @@
1
+ import { RouteTree } from '@nestjs/core/router/interfaces/routes.interface'
2
+ import { $AccountPath, OrganizationEntity, RoleEntity, UserEntity } from './account'
3
+ import AccountModule from './account/account.module'
4
+ import { $AuthPath as AccountAuthPath } from './account/auth'
5
+ import AuthModule from './account/auth/auth.module'
6
+ import MemberModule from './account/organizations/members/member.module'
7
+ import OrganizationModule from './account/organizations/organization.module'
8
+ import RoleModule from './account/roles/role.module'
9
+ import RoleUserModule from './account/roles/users/user.module'
10
+ import UserRoleModule from './account/users/roles/role.module'
11
+ import UserModule from './account/users/user.module'
12
+ import { $InventoryPath, ProductEntity } from './inventory'
13
+ import BrandModule from './inventory/brands/brand.module'
14
+ import CategoryModule from './inventory/categories/category.module'
15
+ import InventoryModule from './inventory/inventory.module'
16
+ import MediaModule from './inventory/products/media/media.module'
17
+ import ProductModule from './inventory/products/product.module'
18
+ import VariantModule from './inventory/products/variants/variant.module'
19
+ import PropertyModule from './inventory/properties/property.module'
20
+ import { $StorePath, OrderEntity } from './store'
21
+ import CartModule from './store/carts/cart.module'
22
+ import ItemModule from './store/orders/items/item.module'
23
+ import OrderModule from './store/orders/order.module'
24
+ import StoreModule from './store/store.module'
25
+
26
+ const addModule = (module, children = [], path = '/'): RouteTree => ({ path, module, children })
27
+
28
+ const routes = [
29
+ addModule(AuthModule, [], AccountAuthPath),
30
+
31
+ addModule(AccountModule, [
32
+ addModule(UserModule, [
33
+ addModule(UserRoleModule, [], UserEntity.$path)
34
+ ]),
35
+ addModule(OrganizationModule, [
36
+ addModule(MemberModule, [], OrganizationEntity.$path)
37
+ ]),
38
+ addModule(RoleModule, [
39
+ addModule(RoleUserModule, [], RoleEntity.$path)
40
+ ])
41
+ ], $AccountPath),
42
+
43
+ addModule(InventoryModule, [
44
+ addModule(BrandModule),
45
+ addModule(CategoryModule),
46
+ addModule(PropertyModule),
47
+ addModule(ProductModule, [
48
+ addModule(VariantModule, [], ProductEntity.$path),
49
+ addModule(MediaModule, [], ProductEntity.$path)
50
+ ])
51
+ ], $InventoryPath),
52
+
53
+ addModule(StoreModule, [
54
+ addModule(CartModule),
55
+ addModule(OrderModule, [
56
+ addModule(ItemModule, [], OrderEntity.$path)
57
+ ])
58
+ ], $StorePath)
59
+ ]
60
+
61
+ export default routes
package/src/app.ts DELETED
@@ -1,40 +0,0 @@
1
- import { ClassSerializerInterceptor, Logger, ValidationPipe } from '@nestjs/common'
2
- import { NestApplication, NestFactory, Reflector } from '@nestjs/core'
3
- import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
4
- import { credential, initializeApp } from 'firebase-admin'
5
- import { initialize } from 'fireorm'
6
- // import AuthGuard from './account/auth/auth.guard'
7
- import AppConfig from './app.config'
8
- import AppModule from './app.module'
9
-
10
- (async () => {
11
- //Initializing Firebase connection
12
- const firebase = initializeApp({
13
- credential: credential.applicationDefault(),
14
- storageBucket: AppConfig.firebase.storageBucket
15
- })
16
-
17
- initialize(firebase.firestore())
18
-
19
- const app = await NestFactory.create(AppModule, { cors: true })
20
-
21
- const builder = new DocumentBuilder()
22
- .setTitle(AppConfig.server.name)
23
- .setDescription(AppConfig.server.description)
24
- .setVersion(AppConfig.server.version)
25
- .build()
26
-
27
- //Creating Swagger Doc for API
28
- const document = SwaggerModule.createDocument(app, builder)
29
- SwaggerModule.setup('/', app, document)
30
-
31
- const reflector = app.get(Reflector)
32
- // const authGuard = app.get(AuthGuard)
33
-
34
- return app
35
- .useGlobalInterceptors(new ClassSerializerInterceptor(reflector))
36
- // .useGlobalGuards(authGuard)
37
- .useGlobalPipes(new ValidationPipe({ whitelist: true }))
38
- .listen(AppConfig.server.port)
39
- .then(() => Logger.verbose(`Running on port: ${AppConfig.server.port}`, NestApplication.name))
40
- })()