@candlerip/shared3 0.0.136 → 0.0.137

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/src/aws/app-config/get-app-config/index.d.ts +10 -1
  3. package/src/aws/app-config/get-app-config/index.js +101 -1
  4. package/src/aws/s3/person-image-worker/index.js +26 -14
  5. package/src/aws/s3/worker/index.js +5 -5
  6. package/src/backend/environment/load-env-file/index.d.ts +7 -1
  7. package/src/backend/environment/load-env-file/index.js +31 -1
  8. package/src/environment/environment-variables/config.d.ts +73 -11
  9. package/src/environment/environment-variables/config.js +73 -36
  10. package/src/environment/environment-variables/singleton.d.ts +4 -63
  11. package/src/environment/environment-variables/singleton.js +2 -3
  12. package/src/environment/environment-variables/type.d.ts +6 -10
  13. package/src/environment/index.d.ts +0 -2
  14. package/src/environment/index.js +0 -2
  15. package/src/error/custom-error/compose-custom-error/index.js +11 -6
  16. package/src/error/custom-error/compose-custom-error/type.d.ts +4 -1
  17. package/src/error/custom-error/worker/index.js +4 -2
  18. package/src/type/index.d.ts +1 -0
  19. package/src/type/index.js +1 -0
  20. package/src/type/readonly/index.d.ts +1 -0
  21. package/src/type/readonly/index.js +1 -0
  22. package/src/type/readonly/remove-readonly/index.d.ts +5 -0
  23. package/src/aws/app-config/get-app-config/util.d.ts +0 -10
  24. package/src/aws/app-config/get-app-config/util.js +0 -101
  25. package/src/backend/environment/load-env-file/util.d.ts +0 -6
  26. package/src/backend/environment/load-env-file/util.js +0 -29
  27. package/src/environment/environment-variable/config.d.ts +0 -29
  28. package/src/environment/environment-variable/config.js +0 -29
  29. package/src/environment/environment-variable/index.d.ts +0 -1
  30. package/src/environment/environment-variable/index.js +0 -1
  31. package/src/environment/environment-variable-name/config.d.ts +0 -2
  32. package/src/environment/environment-variable-name/config.js +0 -2
  33. package/src/environment/environment-variable-name/index.d.ts +0 -2
  34. package/src/environment/environment-variable-name/index.js +0 -2
  35. package/src/environment/environment-variable-name/type.d.ts +0 -2
  36. /package/src/{environment/environment-variable-name/type.js → type/readonly/remove-readonly/index.js} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@candlerip/shared3",
3
- "version": "0.0.136",
3
+ "version": "0.0.137",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.js",
@@ -1 +1,10 @@
1
- export * from './util.js';
1
+ import { EnvironmentMode, EnvironmentVariables } from '../../../environment/index.js';
2
+ import { CustomError } from '../../../error/index.js';
3
+ export declare const getAppConfig: <T extends keyof EnvironmentVariables>(props: {
4
+ environmentMode: EnvironmentMode;
5
+ projectName: T;
6
+ }) => Promise<{
7
+ data: EnvironmentVariables[T];
8
+ } | {
9
+ customError: CustomError;
10
+ }>;
@@ -1 +1,101 @@
1
- export * from './util.js';
1
+ import * as appConfigDataSdk from '@aws-sdk/client-appconfigdata';
2
+ import * as appConfigSdk from '@aws-sdk/client-appconfig';
3
+ import { customErrorWorker } from '../../../error/index.js';
4
+ export const getAppConfig = async (props) => {
5
+ const { environmentMode, projectName } = props;
6
+ const { composeCustomError } = customErrorWorker(props);
7
+ let client;
8
+ let resp;
9
+ client = new appConfigSdk.AppConfigClient();
10
+ try {
11
+ resp = await client.send(new appConfigSdk.ListApplicationsCommand());
12
+ }
13
+ catch (err) {
14
+ return {
15
+ customError: composeCustomError('Error during list AppConfig Applications', { err }),
16
+ };
17
+ }
18
+ const applications = resp.Items;
19
+ if (!applications) {
20
+ return {
21
+ customError: composeCustomError('No AppConfig Applications found'),
22
+ };
23
+ }
24
+ const application = applications.find((it) => it.Name === projectName);
25
+ if (!application) {
26
+ return {
27
+ customError: composeCustomError('AppConfig Application not found'),
28
+ };
29
+ }
30
+ const applicationId = application.Id;
31
+ try {
32
+ resp = await client.send(new appConfigSdk.ListEnvironmentsCommand({ ApplicationId: applicationId }));
33
+ }
34
+ catch (err) {
35
+ return {
36
+ customError: composeCustomError('Error during list AppConfig Environments', { err }),
37
+ };
38
+ }
39
+ const environments = resp.Items;
40
+ if (!environments) {
41
+ return {
42
+ customError: composeCustomError('No AppConfig Environments found'),
43
+ };
44
+ }
45
+ const environment = environments.find((it) => it.Name === environmentMode);
46
+ if (!environment) {
47
+ return {
48
+ customError: composeCustomError('AppConfig Environment not found'),
49
+ };
50
+ }
51
+ const environmentId = environment.Id;
52
+ try {
53
+ resp = await client.send(new appConfigSdk.ListConfigurationProfilesCommand({ ApplicationId: applicationId }));
54
+ }
55
+ catch (err) {
56
+ return {
57
+ customError: composeCustomError('Error during list AppConfig Configuration Profiles', { err }),
58
+ };
59
+ }
60
+ const configurationProfiles = resp.Items;
61
+ if (!configurationProfiles) {
62
+ return {
63
+ customError: composeCustomError('No AppConfig Configuration Profiles found'),
64
+ };
65
+ }
66
+ const configurationProfile = configurationProfiles.find((it) => it.Name === `${environmentMode}-profile`);
67
+ if (!configurationProfile) {
68
+ return {
69
+ customError: composeCustomError('AppConfig Configuration Profile not found'),
70
+ };
71
+ }
72
+ const configurationProfileId = configurationProfile.Id;
73
+ client = new appConfigDataSdk.AppConfigDataClient();
74
+ try {
75
+ resp = await client.send(new appConfigDataSdk.StartConfigurationSessionCommand({
76
+ ApplicationIdentifier: applicationId,
77
+ EnvironmentIdentifier: environmentId,
78
+ ConfigurationProfileIdentifier: configurationProfileId,
79
+ }));
80
+ }
81
+ catch (err) {
82
+ return {
83
+ customError: composeCustomError('Error during get AppConfig initial configuration token', { err }),
84
+ };
85
+ }
86
+ const ConfigurationToken = resp.InitialConfigurationToken;
87
+ let appConfig;
88
+ try {
89
+ resp = await client.send(new appConfigDataSdk.GetLatestConfigurationCommand({ ConfigurationToken }));
90
+ const appConfigStr = new TextDecoder().decode(resp.Configuration);
91
+ appConfig = JSON.parse(appConfigStr);
92
+ }
93
+ catch (err) {
94
+ return {
95
+ customError: composeCustomError('Error during get AppConfig', { err }),
96
+ };
97
+ }
98
+ return {
99
+ data: appConfig,
100
+ };
101
+ };
@@ -19,10 +19,13 @@ export const PersonImageWorker = (() => {
19
19
  const errors = resp.filter((it) => it);
20
20
  if (errors.length > 0) {
21
21
  return {
22
- customError: composeCustomError('Errors during delete person images', 'backend', {
23
- errors,
24
- personImages,
25
- personId,
22
+ customError: composeCustomError('Errors during delete person images', {
23
+ info: {
24
+ errors,
25
+ personId,
26
+ personImages,
27
+ },
28
+ projectName: 'backend',
26
29
  }),
27
30
  };
28
31
  }
@@ -38,10 +41,13 @@ export const PersonImageWorker = (() => {
38
41
  const errors = resp.filter((it) => 'customError' in it);
39
42
  if (errors.length > 0) {
40
43
  return {
41
- customError: composeCustomError('Errors during get person images', 'backend', {
42
- errors,
43
- personImages,
44
- personId,
44
+ customError: composeCustomError('Errors during get person images', {
45
+ info: {
46
+ errors,
47
+ personId,
48
+ personImages,
49
+ },
50
+ projectName: 'backend',
45
51
  }),
46
52
  };
47
53
  }
@@ -63,8 +69,11 @@ export const PersonImageWorker = (() => {
63
69
  }
64
70
  catch (err) {
65
71
  return {
66
- customError: composeCustomError('Error during image convertion', 'backend', {
67
- err,
72
+ customError: composeCustomError('Error during image convertion', {
73
+ info: {
74
+ err,
75
+ },
76
+ projectName: 'backend',
68
77
  }),
69
78
  };
70
79
  }
@@ -85,10 +94,13 @@ export const PersonImageWorker = (() => {
85
94
  const errors = resp.filter((it) => it);
86
95
  if (errors.length > 0) {
87
96
  return {
88
- customError: composeCustomError('Errors during update person images', 'backend', {
89
- errors,
90
- images,
91
- personId,
97
+ customError: composeCustomError('Errors during update person images', {
98
+ info: {
99
+ errors,
100
+ images,
101
+ personId,
102
+ },
103
+ projectName: 'backend',
92
104
  }),
93
105
  };
94
106
  }
@@ -19,7 +19,7 @@ export class S3Worker {
19
19
  }
20
20
  catch (err) {
21
21
  return {
22
- customError: composeCustomError('Cannot delete file in S3', 'backend', { err, bucketName: this.bucketName, key }),
22
+ customError: composeCustomError('Cannot delete file in S3', { info: { bucketName: this.bucketName, err, key }, projectName: 'backend' }),
23
23
  };
24
24
  }
25
25
  return;
@@ -33,14 +33,14 @@ export class S3Worker {
33
33
  }));
34
34
  if (!response) {
35
35
  return {
36
- customError: composeCustomError('Error during get image from S3', 'backend', { key }),
36
+ customError: composeCustomError('Error during get image from S3', { info: { key }, projectName: 'backend' }),
37
37
  };
38
38
  }
39
39
  stream = response.Body;
40
40
  }
41
41
  catch (err) {
42
42
  return {
43
- customError: composeCustomError('Cannot get file from S3', 'backend', { err, key }),
43
+ customError: composeCustomError('Cannot get file from S3', { info: { err, key }, projectName: 'backend' }),
44
44
  };
45
45
  }
46
46
  return {
@@ -60,7 +60,7 @@ export class S3Worker {
60
60
  }
61
61
  catch (err) {
62
62
  return {
63
- customError: composeCustomError('Cannot get file from S3', 'backend', { err, key }),
63
+ customError: composeCustomError('Cannot get file from S3', { info: { err, key }, projectName: 'backend' }),
64
64
  };
65
65
  }
66
66
  return { base64Image };
@@ -77,7 +77,7 @@ export class S3Worker {
77
77
  }
78
78
  catch (err) {
79
79
  return {
80
- customError: composeCustomError('Cannot upload file to S3', 'backend', { err, file: fileBuffer, key, options }),
80
+ customError: composeCustomError('Cannot upload file to S3', { info: { err, file: fileBuffer, key, options }, projectName: 'backend' }),
81
81
  };
82
82
  }
83
83
  return;
@@ -1 +1,7 @@
1
- export * from './util.js';
1
+ import { EnvironmentMode, EnvironmentVariables } from '../../../environment/index.js';
2
+ import { CustomError } from '../../../error/index.js';
3
+ export declare const loadEnvFile: <P extends keyof EnvironmentVariables, Envs extends EnvironmentVariables[P]>(environmentMode: EnvironmentMode, projectName: P) => {
4
+ data: EnvironmentVariables[P];
5
+ } | {
6
+ customError: CustomError;
7
+ };
@@ -1 +1,31 @@
1
- export * from './util.js';
1
+ import * as dotenv from 'dotenv';
2
+ import { ENVIRONMENT_VARIABLES } from '../../../environment/index.js';
3
+ import { composeCustomError } from '../../../error/index.js';
4
+ export const loadEnvFile = (environmentMode, projectName) => {
5
+ const fileName = `.env.${environmentMode}`;
6
+ const config = ENVIRONMENT_VARIABLES[projectName];
7
+ const envFile = dotenv.config({ path: `./${fileName}` });
8
+ const { error: err, parsed } = envFile;
9
+ if (err || !parsed) {
10
+ return {
11
+ customError: composeCustomError(`Error loading ${fileName}`, {
12
+ info: {
13
+ environmentMode,
14
+ err,
15
+ },
16
+ }),
17
+ };
18
+ }
19
+ const data = {};
20
+ Object.keys(parsed).forEach((key) => {
21
+ if (config[key] === 'boolean') {
22
+ data[key] = Boolean(parsed[key] === 'true');
23
+ }
24
+ else if (config[key] === 'number') {
25
+ data[key] = parseInt(parsed[key]);
26
+ }
27
+ });
28
+ return {
29
+ data: data,
30
+ };
31
+ };
@@ -1,12 +1,74 @@
1
- export declare const ENVIRONMENT_VARIABLES_CONFIG: {
2
- readonly app: readonly ["APP_PORT", "AUTH0_BASE_URL", "AUTH0_CLIENT_ID", "AUTH0_CLIENT_SECRET", "AUTH0_ISSUER_BASE_URL", "AUTH0_SECRET", "BACKEND_URL", "DATABASE_URL", "NODE_ENV", "RABBITMQ_URL", "REDIS_PWD", "REDIS_URL", "S3_IMAGES_BUCKET_NAME"];
3
- readonly 'cache-service': readonly ["CACHE_ENABLED", "CACHE_SERVICE_PORT", "DATABASE_URL", "NODE_ENV", "RABBITMQ_URL", "REDIS_PWD", "REDIS_URL"];
4
- readonly images: readonly ["NODE_ENV", "S3_IMAGES_BUCKET_NAME"];
5
- readonly 'images-init': readonly ["FRONTEND_URL", "NODE_ENV", "S3_IMAGES_BUCKET_NAME"];
6
- readonly 'logger-service': readonly ["DATABASE_URL", "LOGGER_SERVICE_PORT", "NODE_ENV", "RABBITMQ_URL"];
7
- readonly nginx: readonly ["APP_PORT", "NODE_ENV"];
8
- readonly rabbitmq: readonly ["RABBITMQ_PORT", "RABBITMQ_MANAGEMENT_PORT", "NODE_ENV", "RABBITMQ_PWD", "RABBITMQ_USER"];
9
- readonly redis: readonly ["NODE_ENV", "REDIS_PORT", "REDIS_PWD"];
10
- readonly server: readonly ["APP_PORT", "API_GATEWAY_PORT", "CACHE_SERVICE_PORT", "LOGGER_SERVICE_PORT", "NODE_ENV", "RABBITMQ_PORT", "RABBITMQ_MANAGEMENT_PORT", "REDIS_PORT"];
11
- readonly 'server-init': readonly ["APP_NAME", "DOMAIN_NAME", "NODE_ENV", "S3_IMAGES_BUCKET_NAME"];
1
+ export declare const ENVIRONMENT_VARIABLES: {
2
+ readonly app: {
3
+ readonly APP_PORT: "number";
4
+ readonly AUTH0_BASE_URL: "string";
5
+ readonly AUTH0_CLIENT_ID: "string";
6
+ readonly AUTH0_CLIENT_SECRET: "string";
7
+ readonly AUTH0_ISSUER_BASE_URL: "string";
8
+ readonly AUTH0_SECRET: "string";
9
+ readonly BACKEND_URL: "string";
10
+ readonly DATABASE_URL: "string";
11
+ readonly GOOGLE_MAPS_API_KEY: "string";
12
+ readonly NODE_ENV: "EnvironmentMode";
13
+ readonly RABBITMQ_URL: "string";
14
+ readonly REDIS_PWD: "string";
15
+ readonly REDIS_URL: "string";
16
+ readonly S3_IMAGES_BUCKET_NAME: "string";
17
+ };
18
+ readonly 'cache-service': {
19
+ readonly CACHE_ENABLED: "boolean";
20
+ readonly CACHE_SERVICE_PORT: "number";
21
+ readonly DATABASE_URL: "string";
22
+ readonly NODE_ENV: "EnvironmentMode";
23
+ readonly RABBITMQ_URL: "string";
24
+ readonly REDIS_PWD: "string";
25
+ readonly REDIS_URL: "string";
26
+ };
27
+ readonly images: {
28
+ readonly NODE_ENV: "EnvironmentMode";
29
+ readonly S3_IMAGES_BUCKET_NAME: "string";
30
+ };
31
+ readonly 'images-init': {
32
+ readonly FRONTEND_URL: "string";
33
+ readonly NODE_ENV: "EnvironmentMode";
34
+ readonly S3_IMAGES_BUCKET_NAME: "string";
35
+ };
36
+ readonly 'logger-service': {
37
+ readonly DATABASE_URL: "string";
38
+ readonly LOGGER_SERVICE_PORT: "number";
39
+ readonly NODE_ENV: "EnvironmentMode";
40
+ readonly RABBITMQ_URL: "string";
41
+ };
42
+ readonly nginx: {
43
+ readonly APP_PORT: "number";
44
+ readonly NODE_ENV: "EnvironmentMode";
45
+ };
46
+ readonly rabbitmq: {
47
+ readonly RABBITMQ_PORT: "number";
48
+ readonly RABBITMQ_MANAGEMENT_PORT: "number";
49
+ readonly NODE_ENV: "EnvironmentMode";
50
+ readonly RABBITMQ_PWD: "string";
51
+ readonly RABBITMQ_USER: "string";
52
+ };
53
+ readonly redis: {
54
+ readonly NODE_ENV: "EnvironmentMode";
55
+ readonly REDIS_PORT: "number";
56
+ readonly REDIS_PWD: "string";
57
+ };
58
+ readonly server: {
59
+ readonly APP_PORT: "number";
60
+ readonly API_GATEWAY_PORT: "number";
61
+ readonly CACHE_SERVICE_PORT: "number";
62
+ readonly LOGGER_SERVICE_PORT: "number";
63
+ readonly NODE_ENV: "EnvironmentMode";
64
+ readonly RABBITMQ_PORT: "number";
65
+ readonly RABBITMQ_MANAGEMENT_PORT: "number";
66
+ readonly REDIS_PORT: "number";
67
+ };
68
+ readonly 'server-init': {
69
+ readonly APP_NAME: "string";
70
+ readonly DOMAIN_NAME: "string";
71
+ readonly NODE_ENV: "EnvironmentMode";
72
+ readonly S3_IMAGES_BUCKET_NAME: "string";
73
+ };
12
74
  };
@@ -1,37 +1,74 @@
1
- export const ENVIRONMENT_VARIABLES_CONFIG = {
2
- app: [
3
- 'APP_PORT',
4
- 'AUTH0_BASE_URL',
5
- 'AUTH0_CLIENT_ID',
6
- 'AUTH0_CLIENT_SECRET',
7
- 'AUTH0_ISSUER_BASE_URL',
8
- 'AUTH0_SECRET',
9
- 'BACKEND_URL',
10
- 'DATABASE_URL',
11
- 'NODE_ENV',
12
- 'RABBITMQ_URL',
13
- 'REDIS_PWD',
14
- 'REDIS_URL',
15
- 'S3_IMAGES_BUCKET_NAME',
16
- ],
17
- 'cache-service': ['CACHE_ENABLED', 'CACHE_SERVICE_PORT', 'DATABASE_URL', 'NODE_ENV', 'RABBITMQ_URL', 'REDIS_PWD', 'REDIS_URL'],
18
- images: ['NODE_ENV', 'S3_IMAGES_BUCKET_NAME'],
19
- 'images-init': ['FRONTEND_URL', 'NODE_ENV', 'S3_IMAGES_BUCKET_NAME'],
20
- 'logger-service': ['DATABASE_URL', 'LOGGER_SERVICE_PORT', 'NODE_ENV', 'RABBITMQ_URL'],
21
- nginx: ['APP_PORT', 'NODE_ENV'],
22
- rabbitmq: ['RABBITMQ_PORT', 'RABBITMQ_MANAGEMENT_PORT', 'NODE_ENV', 'RABBITMQ_PWD', 'RABBITMQ_USER'],
23
- redis: ['NODE_ENV', 'REDIS_PORT', 'REDIS_PWD'],
24
- server: [
25
- 'APP_PORT',
26
- 'API_GATEWAY_PORT',
27
- 'CACHE_SERVICE_PORT',
28
- 'LOGGER_SERVICE_PORT',
29
- 'NODE_ENV',
30
- 'RABBITMQ_PORT',
31
- 'RABBITMQ_MANAGEMENT_PORT',
32
- 'REDIS_PORT',
33
- ],
34
- 'server-init': ['APP_NAME', 'DOMAIN_NAME', 'NODE_ENV', 'S3_IMAGES_BUCKET_NAME'],
1
+ export const ENVIRONMENT_VARIABLES = {
2
+ app: {
3
+ APP_PORT: 'number',
4
+ AUTH0_BASE_URL: 'string',
5
+ AUTH0_CLIENT_ID: 'string',
6
+ AUTH0_CLIENT_SECRET: 'string',
7
+ AUTH0_ISSUER_BASE_URL: 'string',
8
+ AUTH0_SECRET: 'string',
9
+ BACKEND_URL: 'string',
10
+ DATABASE_URL: 'string',
11
+ GOOGLE_MAPS_API_KEY: 'string',
12
+ NODE_ENV: 'EnvironmentMode',
13
+ RABBITMQ_URL: 'string',
14
+ REDIS_PWD: 'string',
15
+ REDIS_URL: 'string',
16
+ S3_IMAGES_BUCKET_NAME: 'string',
17
+ },
18
+ 'cache-service': {
19
+ CACHE_ENABLED: 'boolean',
20
+ CACHE_SERVICE_PORT: 'number',
21
+ DATABASE_URL: 'string',
22
+ NODE_ENV: 'EnvironmentMode',
23
+ RABBITMQ_URL: 'string',
24
+ REDIS_PWD: 'string',
25
+ REDIS_URL: 'string',
26
+ },
27
+ images: {
28
+ NODE_ENV: 'EnvironmentMode',
29
+ S3_IMAGES_BUCKET_NAME: 'string',
30
+ },
31
+ 'images-init': {
32
+ FRONTEND_URL: 'string',
33
+ NODE_ENV: 'EnvironmentMode',
34
+ S3_IMAGES_BUCKET_NAME: 'string',
35
+ },
36
+ 'logger-service': {
37
+ DATABASE_URL: 'string',
38
+ LOGGER_SERVICE_PORT: 'number',
39
+ NODE_ENV: 'EnvironmentMode',
40
+ RABBITMQ_URL: 'string',
41
+ },
42
+ nginx: {
43
+ APP_PORT: 'number',
44
+ NODE_ENV: 'EnvironmentMode',
45
+ },
46
+ rabbitmq: {
47
+ RABBITMQ_PORT: 'number',
48
+ RABBITMQ_MANAGEMENT_PORT: 'number',
49
+ NODE_ENV: 'EnvironmentMode',
50
+ RABBITMQ_PWD: 'string',
51
+ RABBITMQ_USER: 'string',
52
+ },
53
+ redis: {
54
+ NODE_ENV: 'EnvironmentMode',
55
+ REDIS_PORT: 'number',
56
+ REDIS_PWD: 'string',
57
+ },
58
+ server: {
59
+ APP_PORT: 'number',
60
+ API_GATEWAY_PORT: 'number',
61
+ CACHE_SERVICE_PORT: 'number',
62
+ LOGGER_SERVICE_PORT: 'number',
63
+ NODE_ENV: 'EnvironmentMode',
64
+ RABBITMQ_PORT: 'number',
65
+ RABBITMQ_MANAGEMENT_PORT: 'number',
66
+ REDIS_PORT: 'number',
67
+ },
68
+ 'server-init': {
69
+ APP_NAME: 'string',
70
+ DOMAIN_NAME: 'string',
71
+ NODE_ENV: 'EnvironmentMode',
72
+ S3_IMAGES_BUCKET_NAME: 'string',
73
+ },
35
74
  };
36
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
- const CHECK = ENVIRONMENT_VARIABLES_CONFIG;
@@ -1,68 +1,9 @@
1
1
  import { EnvironmentVariables } from './type.js';
2
+ type Envs = EnvironmentVariables[keyof EnvironmentVariables];
2
3
  export declare const EnvironmentVariablesSingleton: {
3
- get: <T extends keyof EnvironmentVariables = never>() => EnvironmentVariables[T];
4
- init: (envs: {
5
- APP_PORT: number;
6
- AUTH0_BASE_URL: string;
7
- AUTH0_CLIENT_ID: string;
8
- AUTH0_CLIENT_SECRET: string;
9
- AUTH0_ISSUER_BASE_URL: string;
10
- AUTH0_SECRET: string;
11
- BACKEND_URL: string;
12
- DATABASE_URL: string;
13
- NODE_ENV: "development" | "production";
14
- RABBITMQ_URL: string;
15
- REDIS_PWD: string;
16
- REDIS_URL: string;
17
- S3_IMAGES_BUCKET_NAME: string;
18
- } | {
19
- CACHE_ENABLED: boolean;
20
- CACHE_SERVICE_PORT: number;
21
- DATABASE_URL: string;
22
- NODE_ENV: "development" | "production";
23
- RABBITMQ_URL: string;
24
- REDIS_PWD: string;
25
- REDIS_URL: string;
26
- } | {
27
- NODE_ENV: "development" | "production";
28
- S3_IMAGES_BUCKET_NAME: string;
29
- } | {
30
- FRONTEND_URL: string;
31
- NODE_ENV: "development" | "production";
32
- S3_IMAGES_BUCKET_NAME: string;
33
- } | {
34
- DATABASE_URL: string;
35
- LOGGER_SERVICE_PORT: number;
36
- NODE_ENV: "development" | "production";
37
- RABBITMQ_URL: string;
38
- } | {
39
- APP_PORT: number;
40
- NODE_ENV: "development" | "production";
41
- } | {
42
- NODE_ENV: "development" | "production";
43
- RABBITMQ_MANAGEMENT_PORT: number;
44
- RABBITMQ_PORT: number;
45
- RABBITMQ_PWD: string;
46
- RABBITMQ_USER: string;
47
- } | {
48
- NODE_ENV: "development" | "production";
49
- REDIS_PORT: number;
50
- REDIS_PWD: string;
51
- } | {
52
- API_GATEWAY_PORT: number;
53
- APP_PORT: number;
54
- CACHE_SERVICE_PORT: number;
55
- LOGGER_SERVICE_PORT: number;
56
- NODE_ENV: "development" | "production";
57
- RABBITMQ_MANAGEMENT_PORT: number;
58
- RABBITMQ_PORT: number;
59
- REDIS_PORT: number;
60
- } | {
61
- APP_NAME: string;
62
- DOMAIN_NAME: string;
63
- NODE_ENV: "development" | "production";
64
- S3_IMAGES_BUCKET_NAME: string;
65
- }) => void;
4
+ get: <T extends keyof EnvironmentVariables>() => EnvironmentVariables[T];
5
+ init: (envs: Envs) => void;
66
6
  isDevelopment: () => boolean;
67
7
  isProduction: () => boolean;
68
8
  };
9
+ export {};
@@ -1,13 +1,12 @@
1
1
  import { isDevelopment as isDev, isProduction as isProd } from '../environment-mode/index.js';
2
2
  export const EnvironmentVariablesSingleton = (() => {
3
- const _NODE_ENV = process.env.NODE_ENV;
4
3
  let _envs;
5
4
  const get = () => _envs;
6
5
  const init = (envs) => {
7
6
  _envs = envs;
8
7
  };
9
- const isDevelopment = () => isDev(_NODE_ENV);
10
- const isProduction = () => isProd(_NODE_ENV);
8
+ const isDevelopment = () => isDev(_envs.NODE_ENV);
9
+ const isProduction = () => isProd(_envs.NODE_ENV);
11
10
  return {
12
11
  get,
13
12
  init,
@@ -1,15 +1,11 @@
1
+ import { RemoveReadonly } from '../../type/index.js';
1
2
  import { EnvironmentMode } from '../environment-mode/index.js';
2
- import { ENVIRONMENT_VARIABLE_CONFIG } from '../environment-variable/config.js';
3
- import { ENVIRONMENT_VARIABLES_CONFIG } from './config.js';
3
+ import { ENVIRONMENT_VARIABLES } from './config.js';
4
+ type Type = RemoveReadonly<typeof ENVIRONMENT_VARIABLES>;
4
5
  export type EnvironmentVariables = {
5
- [key in keyof typeof ENVIRONMENT_VARIABLES_CONFIG]: {
6
- [key2 in (typeof ENVIRONMENT_VARIABLES_CONFIG)[key][number]]: TypeMap[(typeof ENVIRONMENT_VARIABLE_CONFIG)[key2]];
6
+ [key in keyof Type]: {
7
+ [key2 in keyof Type[key]]: TypeMap<Type[key][key2]>;
7
8
  };
8
9
  };
9
- interface TypeMap {
10
- boolean: boolean;
11
- EnvironmentMode: EnvironmentMode;
12
- number: number;
13
- string: string;
14
- }
10
+ type TypeMap<T> = T extends 'boolean' ? boolean : T extends 'EnvironmentMode' ? EnvironmentMode : T extends 'number' ? number : string;
15
11
  export {};
@@ -1,4 +1,2 @@
1
1
  export * from './environment-mode/index.js';
2
- export * from './environment-variable/index.js';
3
- export * from './environment-variable-name/index.js';
4
2
  export * from './environment-variables/index.js';
@@ -1,4 +1,2 @@
1
1
  export * from './environment-mode/index.js';
2
- export * from './environment-variable/index.js';
3
- export * from './environment-variable-name/index.js';
4
2
  export * from './environment-variables/index.js';
@@ -1,7 +1,12 @@
1
+ import { ProjectSingleton } from '../../../project/index.js';
1
2
  import { serializeInfo } from '../serialize-info/index.js';
2
- export const composeCustomError = (message, projectName, info) => ({
3
- id: Math.random().toString(16).slice(2).toUpperCase(),
4
- info: serializeInfo(info),
5
- message,
6
- projectName,
7
- });
3
+ export const composeCustomError = (message, options) => {
4
+ const info = options?.info;
5
+ const projectName = options?.projectName ?? ProjectSingleton.getProjectName();
6
+ return {
7
+ id: Math.random().toString(16).slice(2).toUpperCase(),
8
+ info: serializeInfo(info),
9
+ message,
10
+ projectName,
11
+ };
12
+ };
@@ -1,2 +1,5 @@
1
1
  import { CustomError } from '../type.js';
2
- export type ComposeCustomError = (message: CustomError['message'], projectName: CustomError['projectName'], info?: CustomError['info']) => CustomError;
2
+ export type ComposeCustomError = (message: CustomError['message'], options?: {
3
+ projectName?: CustomError['projectName'];
4
+ info?: CustomError['info'];
5
+ }) => CustomError;
@@ -1,4 +1,3 @@
1
- import { ProjectSingleton } from '../../../project/index.js';
2
1
  import { composeCustomError as composeCustomErrorFunc } from '../compose-custom-error/index.js';
3
2
  export const customErrorWorker = (info) => {
4
3
  let _info = info;
@@ -8,7 +7,10 @@ export const customErrorWorker = (info) => {
8
7
  };
9
8
  const composeCustomError = (message, info) => {
10
9
  composeInfo(info);
11
- return composeCustomErrorFunc(message, _projectName ?? ProjectSingleton.getProjectName(), _info);
10
+ return composeCustomErrorFunc(message, {
11
+ info: _info,
12
+ projectName: _projectName,
13
+ });
12
14
  };
13
15
  const composeInfo = (info) => {
14
16
  if (!_info && !info) {
@@ -1,5 +1,6 @@
1
1
  export * from './array/index.js';
2
2
  export * from './object/index.js';
3
+ export * from './readonly/index.js';
3
4
  export * from './string/index.js';
4
5
  export * from './type/index.js';
5
6
  export * from './undefined/index.js';
package/src/type/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './array/index.js';
2
2
  export * from './object/index.js';
3
+ export * from './readonly/index.js';
3
4
  export * from './string/index.js';
4
5
  export * from './type/index.js';
5
6
  export * from './undefined/index.js';
@@ -0,0 +1 @@
1
+ export * from './remove-readonly/index.js';
@@ -0,0 +1 @@
1
+ export * from './remove-readonly/index.js';
@@ -0,0 +1,5 @@
1
+ export type RemoveReadonly<T> = {
2
+ -readonly [k in keyof T]: {
3
+ -readonly [k2 in keyof T[k]]: T[k][k2];
4
+ };
5
+ };
@@ -1,10 +0,0 @@
1
- import { EnvironmentMode, EnvironmentVariables } from '../../../environment/index.js';
2
- import { CustomError } from '../../../error/index.js';
3
- export declare const getAppConfig: <T extends keyof EnvironmentVariables>(props: {
4
- environmentMode: EnvironmentMode;
5
- projectName: T;
6
- }) => Promise<{
7
- data: EnvironmentVariables[T];
8
- } | {
9
- customError: CustomError;
10
- }>;
@@ -1,101 +0,0 @@
1
- import * as appConfigDataSdk from '@aws-sdk/client-appconfigdata';
2
- import * as appConfigSdk from '@aws-sdk/client-appconfig';
3
- import { customErrorWorker } from '../../../error/index.js';
4
- export const getAppConfig = async (props) => {
5
- const { environmentMode, projectName } = props;
6
- const { composeCustomError } = customErrorWorker(props);
7
- let client;
8
- let resp;
9
- client = new appConfigSdk.AppConfigClient();
10
- try {
11
- resp = await client.send(new appConfigSdk.ListApplicationsCommand());
12
- }
13
- catch (err) {
14
- return {
15
- customError: composeCustomError('Error during list AppConfig Applications', { err }),
16
- };
17
- }
18
- const applications = resp.Items;
19
- if (!applications) {
20
- return {
21
- customError: composeCustomError('No AppConfig Applications found'),
22
- };
23
- }
24
- const application = applications.find((it) => it.Name === projectName);
25
- if (!application) {
26
- return {
27
- customError: composeCustomError('AppConfig Application not found'),
28
- };
29
- }
30
- const applicationId = application.Id;
31
- try {
32
- resp = await client.send(new appConfigSdk.ListEnvironmentsCommand({ ApplicationId: applicationId }));
33
- }
34
- catch (err) {
35
- return {
36
- customError: composeCustomError('Error during list AppConfig Environments', { err }),
37
- };
38
- }
39
- const environments = resp.Items;
40
- if (!environments) {
41
- return {
42
- customError: composeCustomError('No AppConfig Environments found'),
43
- };
44
- }
45
- const environment = environments.find((it) => it.Name === environmentMode);
46
- if (!environment) {
47
- return {
48
- customError: composeCustomError('AppConfig Environment not found'),
49
- };
50
- }
51
- const environmentId = environment.Id;
52
- try {
53
- resp = await client.send(new appConfigSdk.ListConfigurationProfilesCommand({ ApplicationId: applicationId }));
54
- }
55
- catch (err) {
56
- return {
57
- customError: composeCustomError('Error during list AppConfig Configuration Profiles', { err }),
58
- };
59
- }
60
- const configurationProfiles = resp.Items;
61
- if (!configurationProfiles) {
62
- return {
63
- customError: composeCustomError('No AppConfig Configuration Profiles found'),
64
- };
65
- }
66
- const configurationProfile = configurationProfiles.find((it) => it.Name === `${environmentMode}-profile`);
67
- if (!configurationProfile) {
68
- return {
69
- customError: composeCustomError('AppConfig Configuration Profile not found'),
70
- };
71
- }
72
- const configurationProfileId = configurationProfile.Id;
73
- client = new appConfigDataSdk.AppConfigDataClient();
74
- try {
75
- resp = await client.send(new appConfigDataSdk.StartConfigurationSessionCommand({
76
- ApplicationIdentifier: applicationId,
77
- EnvironmentIdentifier: environmentId,
78
- ConfigurationProfileIdentifier: configurationProfileId,
79
- }));
80
- }
81
- catch (err) {
82
- return {
83
- customError: composeCustomError('Error during get AppConfig initial configuration token', { err }),
84
- };
85
- }
86
- const ConfigurationToken = resp.InitialConfigurationToken;
87
- let appConfig;
88
- try {
89
- resp = await client.send(new appConfigDataSdk.GetLatestConfigurationCommand({ ConfigurationToken }));
90
- const appConfigStr = new TextDecoder().decode(resp.Configuration);
91
- appConfig = JSON.parse(appConfigStr);
92
- }
93
- catch (err) {
94
- return {
95
- customError: composeCustomError('Error during get AppConfig', { err }),
96
- };
97
- }
98
- return {
99
- data: appConfig,
100
- };
101
- };
@@ -1,6 +0,0 @@
1
- import { CustomError, EnvironmentMode, EnvironmentVariables } from '@candlerip/shared3';
2
- export declare const loadEnvFile: <P extends keyof EnvironmentVariables, D = EnvironmentVariables[P]>(environmentMode: EnvironmentMode, projectName: P) => {
3
- data: D;
4
- } | {
5
- customError: CustomError;
6
- };
@@ -1,29 +0,0 @@
1
- import { customErrorWorker, ENVIRONMENT_VARIABLES_CONFIG, ENVIRONMENT_VARIABLE_CONFIG, } from '@candlerip/shared3';
2
- import * as dotenv from 'dotenv';
3
- export const loadEnvFile = (environmentMode, projectName) => {
4
- const { composeCustomError } = customErrorWorker({ environmentMode });
5
- const fileName = `.env.${environmentMode}`;
6
- const envFile = dotenv.config({ path: `./${fileName}` });
7
- const { error: err, parsed } = envFile;
8
- if (err || !parsed) {
9
- return {
10
- customError: composeCustomError(`Error loading ${fileName}`, { err }),
11
- };
12
- }
13
- const environmentVariables = ENVIRONMENT_VARIABLES_CONFIG[projectName];
14
- return {
15
- data: environmentVariables.reduce((acc, key) => {
16
- const data = {};
17
- if (ENVIRONMENT_VARIABLE_CONFIG[key] === 'boolean') {
18
- data[key] = Boolean(parsed[key] === 'true');
19
- }
20
- else if (ENVIRONMENT_VARIABLE_CONFIG[key] === 'number') {
21
- data[key] = parseInt(parsed[key]);
22
- }
23
- else {
24
- data[key] = parsed[key];
25
- }
26
- return { ...acc, ...data };
27
- }, {}),
28
- };
29
- };
@@ -1,29 +0,0 @@
1
- export declare const ENVIRONMENT_VARIABLE_CONFIG: {
2
- readonly API_GATEWAY_PORT: "number";
3
- readonly APP_NAME: "string";
4
- readonly APP_PORT: "number";
5
- readonly AUTHENTICATION_AUDIENCE: "string";
6
- readonly AUTHENTICATION_DOMAIN: "string";
7
- readonly AUTH0_BASE_URL: "string";
8
- readonly AUTH0_CLIENT_ID: "string";
9
- readonly AUTH0_CLIENT_SECRET: "string";
10
- readonly AUTH0_ISSUER_BASE_URL: "string";
11
- readonly AUTH0_SECRET: "string";
12
- readonly BACKEND_URL: "string";
13
- readonly CACHE_ENABLED: "boolean";
14
- readonly CACHE_SERVICE_PORT: "number";
15
- readonly DATABASE_URL: "string";
16
- readonly DOMAIN_NAME: "string";
17
- readonly FRONTEND_URL: "string";
18
- readonly LOGGER_SERVICE_PORT: "number";
19
- readonly NODE_ENV: "EnvironmentMode";
20
- readonly RABBITMQ_MANAGEMENT_PORT: "number";
21
- readonly RABBITMQ_PORT: "number";
22
- readonly RABBITMQ_PWD: "string";
23
- readonly RABBITMQ_URL: "string";
24
- readonly RABBITMQ_USER: "string";
25
- readonly REDIS_PORT: "number";
26
- readonly REDIS_PWD: "string";
27
- readonly REDIS_URL: "string";
28
- readonly S3_IMAGES_BUCKET_NAME: "string";
29
- };
@@ -1,29 +0,0 @@
1
- export const ENVIRONMENT_VARIABLE_CONFIG = {
2
- API_GATEWAY_PORT: 'number',
3
- APP_NAME: 'string',
4
- APP_PORT: 'number',
5
- AUTHENTICATION_AUDIENCE: 'string',
6
- AUTHENTICATION_DOMAIN: 'string',
7
- AUTH0_BASE_URL: 'string',
8
- AUTH0_CLIENT_ID: 'string',
9
- AUTH0_CLIENT_SECRET: 'string',
10
- AUTH0_ISSUER_BASE_URL: 'string',
11
- AUTH0_SECRET: 'string',
12
- BACKEND_URL: 'string',
13
- CACHE_ENABLED: 'boolean',
14
- CACHE_SERVICE_PORT: 'number',
15
- DATABASE_URL: 'string',
16
- DOMAIN_NAME: 'string',
17
- FRONTEND_URL: 'string',
18
- LOGGER_SERVICE_PORT: 'number',
19
- NODE_ENV: 'EnvironmentMode',
20
- RABBITMQ_MANAGEMENT_PORT: 'number',
21
- RABBITMQ_PORT: 'number',
22
- RABBITMQ_PWD: 'string',
23
- RABBITMQ_URL: 'string',
24
- RABBITMQ_USER: 'string',
25
- REDIS_PORT: 'number',
26
- REDIS_PWD: 'string',
27
- REDIS_URL: 'string',
28
- S3_IMAGES_BUCKET_NAME: 'string',
29
- };
@@ -1 +0,0 @@
1
- export * from './config.js';
@@ -1 +0,0 @@
1
- export * from './config.js';
@@ -1,2 +0,0 @@
1
- import { ENVIRONMENT_VARIABLE_CONFIG } from '../environment-variable/config.js';
2
- export declare const ENVIRONMENT_VARIABLE_NAMES: Array<keyof typeof ENVIRONMENT_VARIABLE_CONFIG>;
@@ -1,2 +0,0 @@
1
- import { ENVIRONMENT_VARIABLE_CONFIG } from '../environment-variable/config.js';
2
- export const ENVIRONMENT_VARIABLE_NAMES = Object.keys(ENVIRONMENT_VARIABLE_CONFIG);
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './type.js';
@@ -1,2 +0,0 @@
1
- export * from './config.js';
2
- export * from './type.js';
@@ -1,2 +0,0 @@
1
- import { ENVIRONMENT_VARIABLE_NAMES } from './config.js';
2
- export type EnvironmentVariableName = (typeof ENVIRONMENT_VARIABLE_NAMES)[number];