@candlerip/shared3 0.0.25 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. package/package.json +2 -1
  2. package/src/environment/env-file/index.d.ts +1 -0
  3. package/src/environment/env-file/index.js +1 -0
  4. package/src/environment/env-file/utils/index.d.ts +1 -0
  5. package/src/environment/env-file/utils/index.js +1 -0
  6. package/src/environment/env-file/utils/load-env-file/index.d.ts +2 -0
  7. package/src/environment/env-file/utils/load-env-file/index.js +26 -0
  8. package/src/environment/env-file/utils/load-env-file/types.d.ts +9 -0
  9. package/src/environment/env-file/utils/load-env-file/types.js +1 -0
  10. package/src/environment/environment-variables/domains/index.d.ts +1 -0
  11. package/src/environment/environment-variables/index.d.ts +1 -0
  12. package/src/environment/environment-variables/index.js +1 -0
  13. package/src/environment/environment-variables/workers/environment-variables-worker/index.d.ts +2 -0
  14. package/src/environment/environment-variables/workers/environment-variables-worker/index.js +20 -0
  15. package/src/environment/environment-variables/workers/environment-variables-worker/types.d.ts +9 -0
  16. package/src/environment/environment-variables/workers/environment-variables-worker/types.js +1 -0
  17. package/src/environment/environment-variables/workers/index.d.ts +1 -0
  18. package/src/environment/environment-variables/workers/index.js +1 -0
  19. package/src/environment/index.d.ts +1 -0
  20. package/src/environment/index.js +1 -0
  21. package/src/project/project-config/domains/backend-project-config/index.d.ts +1 -1
  22. package/src/project/project-name/configs/index.d.ts +1 -1
  23. package/src/project/project-name/configs/index.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@types/node": "^22.5.5",
25
+ "dotenv": "^16.4.5",
25
26
  "eslint": "^8.57.0",
26
27
  "globals": "^15.9.0",
27
28
  "prettier": "^3.3.2",
@@ -0,0 +1 @@
1
+ export * from './utils/index.js';
@@ -0,0 +1 @@
1
+ export * from './utils/index.js';
@@ -0,0 +1 @@
1
+ export * from './load-env-file/index.js';
@@ -0,0 +1 @@
1
+ export * from './load-env-file/index.js';
@@ -0,0 +1,2 @@
1
+ import { LoadEnvFile } from './types.js';
2
+ export declare const loadEnvFile: LoadEnvFile;
@@ -0,0 +1,26 @@
1
+ import * as dotenv from 'dotenv';
2
+ export const loadEnvFile = (environmentMode, options) => {
3
+ const props = { environmentMode, options };
4
+ const integers = options?.integers;
5
+ const fileName = `.env.${environmentMode}`;
6
+ const envFile = dotenv.config({ path: `./${fileName}` });
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ const { error, parsed } = envFile;
9
+ if (error || !parsed) {
10
+ return {
11
+ customError: {
12
+ info: {
13
+ error,
14
+ },
15
+ message: `Error loading ${fileName}`,
16
+ props,
17
+ },
18
+ };
19
+ }
20
+ if (integers) {
21
+ integers.forEach((it) => (parsed[it] = parseInt(parsed[it])));
22
+ }
23
+ return {
24
+ data: parsed,
25
+ };
26
+ };
@@ -0,0 +1,9 @@
1
+ import { CustomError } from '../../../../error/index.js';
2
+ import { EnvironmentMode } from '../../../environment-mode/index.js';
3
+ export type LoadEnvFile = <T extends Record<string, unknown>>(environmentMode: EnvironmentMode, options?: {
4
+ integers?: string[];
5
+ }) => {
6
+ data: T;
7
+ } | {
8
+ customError: CustomError;
9
+ };
@@ -7,6 +7,7 @@ export interface EnvironmentVariables {
7
7
  DICTIONARY_SERVICE_PORT: number;
8
8
  DOMAIN_NAME: string;
9
9
  FRONTEND_URL: string;
10
+ LOGGER_SERVICE_PORT: string;
10
11
  REDIS_URL: string;
11
12
  S3_IMAGES_BUCKET_NAME: string;
12
13
  }
@@ -1 +1,2 @@
1
1
  export * from './domains/index.js';
2
+ export * from './workers/index.js';
@@ -1 +1,2 @@
1
1
  export * from './domains/index.js';
2
+ export * from './workers/index.js';
@@ -0,0 +1,2 @@
1
+ import { IEnvironmentVariablesWorker } from './types.js';
2
+ export declare const EnvironmentVariablesWorker: IEnvironmentVariablesWorker;
@@ -0,0 +1,20 @@
1
+ import { loadEnvFile } from '../../../env-file/index.js';
2
+ export const EnvironmentVariablesWorker = (() => {
3
+ let envs;
4
+ const getEnvs = () => envs;
5
+ const init = () => {
6
+ const ENVIRONMENT_MODE = process.env.ENVIRONMENT_MODE;
7
+ const resp = loadEnvFile(ENVIRONMENT_MODE);
8
+ if ('customError' in resp) {
9
+ return resp;
10
+ }
11
+ envs = {
12
+ ...resp.data,
13
+ ENVIRONMENT_MODE,
14
+ };
15
+ };
16
+ return {
17
+ getEnvs,
18
+ init,
19
+ };
20
+ })();
@@ -0,0 +1,9 @@
1
+ import { CustomError } from '../../../../error/index.js';
2
+ export type IEnvironmentVariablesWorker = {
3
+ getEnvs: GetEnvs;
4
+ init: Init;
5
+ };
6
+ export type GetEnvs = <T = never>() => T;
7
+ export type Init = () => undefined | {
8
+ customError: CustomError;
9
+ };
@@ -0,0 +1 @@
1
+ export * from './environment-variables-worker/index.js';
@@ -0,0 +1 @@
1
+ export * from './environment-variables-worker/index.js';
@@ -1,2 +1,3 @@
1
+ export * from './env-file/index.js';
1
2
  export * from './environment-mode/index.js';
2
3
  export * from './environment-variables/index.js';
@@ -1,2 +1,3 @@
1
+ export * from './env-file/index.js';
1
2
  export * from './environment-mode/index.js';
2
3
  export * from './environment-variables/index.js';
@@ -1,2 +1,2 @@
1
1
  import { EnvironmentVariables } from '../../../../environment/index.js';
2
- export type BackendProjectConfig = Pick<EnvironmentVariables, 'CACHE_SERVICE_PORT' | 'REDIS_PORT'>;
2
+ export type BackendProjectConfig = Pick<EnvironmentVariables, 'CACHE_SERVICE_PORT' | 'LOGGER_SERVICE_PORT' | 'REDIS_PORT'>;
@@ -1 +1 @@
1
- export declare const PROJECT_NAMES: readonly ["backend-init", "backend", "cache-service", "dictionary-service", "config", "images", "images-init", "logger", "redis", "shared", "shared-aws", "shared-backend"];
1
+ export declare const PROJECT_NAMES: readonly ["backend-init", "backend", "cache-service", "dictionary-service", "config", "images", "images-init", "logger-service", "redis", "shared", "shared-aws", "shared-backend"];
@@ -6,7 +6,7 @@ export const PROJECT_NAMES = [
6
6
  'config',
7
7
  'images',
8
8
  'images-init',
9
- 'logger',
9
+ 'logger-service',
10
10
  'redis',
11
11
  'shared',
12
12
  'shared-aws',