@candlerip/shared3 0.0.37 → 0.0.39

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": "@candlerip/shared3",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -1,8 +1,7 @@
1
1
  import { CustomError } from '../../../error/index.js';
2
- export interface ErrorLog extends CustomError {
2
+ export interface ErrorLog {
3
3
  _id: string;
4
- errorId: string;
5
- serviceName: string;
4
+ customError: CustomError;
6
5
  createdAt: Date;
7
6
  updatedAt: Date;
8
7
  }
@@ -1,21 +1,14 @@
1
1
  import * as dotenv from 'dotenv';
2
2
  import { NUMBER_ENVIRONMENT_VARIABLE_NAMES } from '../../../environment-variable-name/index.js';
3
+ import { CustomErrorWorker } from '../../../../error/index.js';
3
4
  export const loadEnvFile = (environmentMode) => {
4
- const props = { environmentMode };
5
+ CustomErrorWorker.addInfo({ environmentMode });
5
6
  const fileName = `.env.${environmentMode}`;
6
7
  const envFile = dotenv.config({ path: `./${fileName}` });
7
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
9
  const { error, parsed } = envFile;
9
10
  if (error || !parsed) {
10
- return {
11
- customError: {
12
- info: {
13
- error,
14
- },
15
- message: `Error loading ${fileName}`,
16
- props,
17
- },
18
- };
11
+ return CustomErrorWorker.compose(`Error loading ${fileName}`, { error });
19
12
  }
20
13
  NUMBER_ENVIRONMENT_VARIABLE_NAMES.forEach((it) => {
21
14
  if (parsed[it]) {
@@ -1 +1 @@
1
- export declare const NUMBER_ENVIRONMENT_VARIABLE_NAMES: ("APP_NAME" | "CACHE_SERVICE_PORT" | "DATABASE_URL" | "DICTIONARY_SERVICE_PORT" | "DOMAIN_NAME" | "FRONTEND_URL" | "LOGGER_SERVICE_PORT" | "RABBITMQ_MANAGEMENT_PORT" | "RABBITMQ_PORT" | "RABBITMQ_PWD" | "RABBITMQ_URL" | "RABBITMQ_USER" | "REDIS_PORT" | "REDIS_PWD" | "REDIS_URL" | "S3_IMAGES_BUCKET_NAME")[];
1
+ export declare const NUMBER_ENVIRONMENT_VARIABLE_NAMES: ("CACHE_SERVICE_PORT" | "LOGGER_SERVICE_PORT" | "RABBITMQ_PORT" | "RABBITMQ_MANAGEMENT_PORT" | "REDIS_PORT" | "APP_NAME" | "DOMAIN_NAME" | "S3_IMAGES_BUCKET_NAME" | "DATABASE_URL" | "REDIS_PWD" | "REDIS_URL" | "DICTIONARY_SERVICE_PORT" | "FRONTEND_URL" | "RABBITMQ_URL" | "RABBITMQ_PWD" | "RABBITMQ_USER")[];
@@ -1,6 +1,7 @@
1
+ import { ProjectName } from '../../../project/index.js';
1
2
  export interface CustomError {
2
- err?: unknown;
3
+ id: string;
3
4
  info?: Record<string, unknown>;
4
5
  message: string;
5
- props?: Record<string, unknown>;
6
+ projectName: ProjectName;
6
7
  }
@@ -1,2 +1,3 @@
1
1
  export * from './domains/index.js';
2
2
  export * from './utils/index.js';
3
+ export * from './workers/index.js';
@@ -1,2 +1,3 @@
1
1
  export * from './domains/index.js';
2
2
  export * from './utils/index.js';
3
+ export * from './workers/index.js';
@@ -1,12 +1,8 @@
1
1
  export const consoleCustomError = (customError) => {
2
2
  console.error('***ERROR***:', customError.message);
3
- if (customError.err) {
4
- console.error('ERR:', customError.err);
5
- }
3
+ console.error('ID:', customError.id);
4
+ console.error('PROJECT_NAME:', customError.projectName);
6
5
  if (customError.info) {
7
6
  console.error('INFO:', customError.info);
8
7
  }
9
- if (customError.props) {
10
- console.error('PROPS:', customError.props);
11
- }
12
8
  };
@@ -0,0 +1,2 @@
1
+ import { ICustomErrorWorker } from './types.js';
2
+ export declare const CustomErrorWorker: ICustomErrorWorker;
@@ -0,0 +1,29 @@
1
+ export const CustomErrorWorker = (() => {
2
+ let projectName;
3
+ let info;
4
+ const addInfo = (infoInput) => {
5
+ info = {
6
+ ...info,
7
+ ...infoInput,
8
+ };
9
+ };
10
+ const compose = (message, infoInput) => ({
11
+ customError: {
12
+ id: Math.random().toString(16).slice(2).toUpperCase(),
13
+ info: {
14
+ ...info,
15
+ ...infoInput,
16
+ },
17
+ message,
18
+ projectName,
19
+ },
20
+ });
21
+ const init = (projectNameInput) => {
22
+ projectName = projectNameInput;
23
+ };
24
+ return {
25
+ addInfo,
26
+ compose,
27
+ init,
28
+ };
29
+ })();
@@ -0,0 +1,11 @@
1
+ import { CustomError } from '../../domains/index.js';
2
+ export interface ICustomErrorWorker {
3
+ addInfo: AddInfo;
4
+ compose: Compose;
5
+ init: Init;
6
+ }
7
+ export type AddInfo = (props: CustomError['info']) => void;
8
+ export type Compose = (message: CustomError['message'], info?: CustomError['info']) => {
9
+ customError: CustomError;
10
+ };
11
+ export type Init = (projectName: CustomError['projectName']) => void;
@@ -0,0 +1 @@
1
+ export * from './custom-error-worker/index.js';
@@ -0,0 +1 @@
1
+ export * from './custom-error-worker/index.js';