xcally-nest-library 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xcally-nest-library",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
26
26
  "test:e2e": "jest --config ./test/jest-e2e.json",
27
27
  "lib:link": "pnpm link --global",
28
- "lib:unlink": "pnpm unlink xcally-nest-libs"
28
+ "lib:unlink": "pnpm unlink xcally-nest-libs --global"
29
29
  },
30
30
  "dependencies": {
31
31
  "@nestjs/axios": "^3.0.2",
@@ -1,5 +1,5 @@
1
1
  import { plainToClass } from 'class-transformer';
2
- import { IsEnum, IsNumber, IsBoolean, IsString, validateSync, NotContains } from 'class-validator';
2
+ import { IsEnum, IsNumber, IsBoolean, IsString, validateSync, NotContains, IsDefined } from 'class-validator';
3
3
 
4
4
  enum EnvironmentType {
5
5
  Dev = 'development',
@@ -10,6 +10,7 @@ enum EnvironmentType {
10
10
  }
11
11
 
12
12
  class EnvironmentVariables {
13
+ @IsDefined()
13
14
  @IsEnum(EnvironmentType)
14
15
  NODE_ENV: EnvironmentType;
15
16
 
@@ -94,4 +94,14 @@ export class GenericRepository<E extends ObjectLiteral> {
94
94
  id: Equal(id),
95
95
  } as unknown as FindOptionsWhere<E>);
96
96
  }
97
+
98
+ /**
99
+ * Removes an entity from the database based on its ID.
100
+ *
101
+ * @param id - The ID of the entity to remove.
102
+ * @returns A promise that resolves when the entity is successfully removed.
103
+ */
104
+ async remove(id: number): Promise<void> {
105
+ await this.repository.delete(id);
106
+ }
97
107
  }
@@ -10,7 +10,8 @@ export class LogRequestInterceptor implements NestInterceptor {
10
10
  const req = context.switchToHttp().getRequest();
11
11
  this.logger.info('Before Middleware...', {
12
12
  traceId: req?.local?.traceId,
13
- className: 'LogRequestInterceptor',
13
+ className: this.constructor.name,
14
+ methodName: 'intercept',
14
15
  });
15
16
  const now = Date.now();
16
17
 
@@ -22,6 +23,7 @@ export class LogRequestInterceptor implements NestInterceptor {
22
23
  this.logger.info(`After Middleware... ${method} ${url} ${Date.now() - now}ms`, {
23
24
  traceId: req?.local?.traceId,
24
25
  className: 'LogRequestInterceptor',
26
+ methodName: 'intercept',
25
27
  }),
26
28
  ),
27
29
  );
@@ -2,57 +2,52 @@
2
2
  import { Logger } from 'winston';
3
3
  import { IWinstonLogger } from './winston.interface';
4
4
  import { TraceLog } from './winston.decorator';
5
+ import { LoggerCtx } from '../../types';
5
6
 
6
- export interface Meta {
7
- traceId: string; // Ensures traceId is always present
8
- className?: string;
9
- methodName?: string;
10
- [key: string]: any; // Allows for any number of additional properties
11
- }
12
7
  export class WinstonLoggerService implements IWinstonLogger {
13
8
  constructor(private readonly logger: Logger) {}
14
9
 
15
10
  @TraceLog()
16
- info(message: string, meta: Meta): void {
11
+ info(message: string, meta: LoggerCtx): void {
17
12
  this.logger.info(message, meta);
18
13
  }
19
14
  @TraceLog()
20
- warn(message: string, meta: Meta): void {
15
+ warn(message: string, meta: LoggerCtx): void {
21
16
  this.logger.warn(message, meta);
22
17
  }
23
18
  @TraceLog()
24
- help(message: string, meta: Meta): void {
19
+ help(message: string, meta: LoggerCtx): void {
25
20
  this.logger.help(message, meta);
26
21
  }
27
22
  @TraceLog()
28
- data(message: string, meta: Meta): void {
23
+ data(message: string, meta: LoggerCtx): void {
29
24
  this.logger.data(message, meta);
30
25
  }
31
26
  @TraceLog()
32
- debug(message: string, meta: Meta): void {
27
+ debug(message: string, meta: LoggerCtx): void {
33
28
  this.logger.debug(message, meta);
34
29
  }
35
- prompt(message: string, meta: Meta): void {
30
+ prompt(message: string, meta: LoggerCtx): void {
36
31
  this.logger.prompt(message, meta);
37
32
  }
38
33
  @TraceLog()
39
- http(message: string, meta: Meta): void {
34
+ http(message: string, meta: LoggerCtx): void {
40
35
  this.logger.http(message, meta);
41
36
  }
42
37
  @TraceLog()
43
- verbose(message: string, meta: Meta): void {
38
+ verbose(message: string, meta: LoggerCtx): void {
44
39
  this.logger.verbose(message, meta);
45
40
  }
46
41
  @TraceLog()
47
- input(message: string, meta: Meta): void {
42
+ input(message: string, meta: LoggerCtx): void {
48
43
  this.logger.input(message, meta);
49
44
  }
50
45
  @TraceLog()
51
- silly(message: string, meta: Meta): void {
46
+ silly(message: string, meta: LoggerCtx): void {
52
47
  this.logger.silly(message, meta);
53
48
  }
54
49
  @TraceLog()
55
- error(message: string, meta: Meta): void {
50
+ error(message: string, meta: LoggerCtx): void {
56
51
  this.logger.error(message, meta);
57
52
  }
58
53
 
@@ -5,14 +5,12 @@ export const X_REQUEST_ID_HEADER = 'X-Request-ID';
5
5
  export const X_RESPONSE_ID_HEADER = 'X-Response-ID';
6
6
  import { ConfigurableModuleBuilder } from '@nestjs/common';
7
7
  import { RouteInfo } from '@nestjs/common/interfaces';
8
+ import { Ctx } from '../../types';
8
9
 
9
10
  interface CtxLocal {
10
- local: CtxLocalTraceID;
11
+ local: Ctx;
11
12
  }
12
- interface CtxLocalTraceID {
13
- traceId: string;
14
- }
15
- type CtxLocalRequest = Request & CtxLocal;
13
+ type CtxLocalRequest = Request & Ctx;
16
14
 
17
15
  export interface TracingModuleOptions {
18
16
  routes: (string | RouteInfo)[];
package/src/types/auth.ts CHANGED
@@ -1,9 +1,37 @@
1
+ export type UserPermission = {
2
+ sectionId: number;
3
+ name: string;
4
+ category: string;
5
+ crudPermissions: Array<'r' | 'e' | 'd'>;
6
+ };
7
+
1
8
  export type User = {
2
- roles: ERoles[];
9
+ id: number;
10
+ role: Role;
3
11
  name: string;
12
+ userProfileId: number;
13
+ permissions: UserPermission[];
14
+ // tenant:Tenant
15
+ };
16
+
17
+ export type Ctx = {
18
+ traceId: string;
19
+ user?: User;
20
+ auth?: Auth;
4
21
  };
5
22
 
6
- export enum ERoles {
7
- admin = 'admin',
8
- user = 'user',
23
+ export type LoggerCtx = Ctx & {
24
+ className: string;
25
+ methodName: string;
26
+ [key: string]: any; // Allows for any number of additional properties
27
+ };
28
+
29
+ export enum Role {
30
+ User = 'user',
31
+ Admin = 'admin',
32
+ Agent = 'agent',
9
33
  }
34
+
35
+ export type Auth = {
36
+ token: string;
37
+ };