@candlerip/shared3 0.0.136 → 0.0.138
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/aws/app-config/get-app-config/index.d.ts +10 -1
- package/src/aws/app-config/get-app-config/index.js +101 -1
- package/src/aws/s3/person-image-worker/index.js +26 -14
- package/src/aws/s3/worker/index.js +5 -5
- package/src/backend/environment/load-env-file/index.d.ts +7 -1
- package/src/backend/environment/load-env-file/index.js +34 -1
- package/src/environment/environment-variables/config.d.ts +73 -11
- package/src/environment/environment-variables/config.js +73 -36
- package/src/environment/environment-variables/singleton.d.ts +4 -63
- package/src/environment/environment-variables/singleton.js +2 -3
- package/src/environment/environment-variables/type.d.ts +6 -10
- package/src/environment/index.d.ts +0 -2
- package/src/environment/index.js +0 -2
- package/src/error/custom-error/compose-custom-error/index.js +11 -6
- package/src/error/custom-error/compose-custom-error/type.d.ts +4 -1
- package/src/error/custom-error/worker/index.js +4 -2
- package/src/type/index.d.ts +1 -0
- package/src/type/index.js +1 -0
- package/src/type/readonly/index.d.ts +1 -0
- package/src/type/readonly/index.js +1 -0
- package/src/type/readonly/remove-readonly/index.d.ts +5 -0
- package/src/aws/app-config/get-app-config/util.d.ts +0 -10
- package/src/aws/app-config/get-app-config/util.js +0 -101
- package/src/backend/environment/load-env-file/util.d.ts +0 -6
- package/src/backend/environment/load-env-file/util.js +0 -29
- package/src/environment/environment-variable/config.d.ts +0 -29
- package/src/environment/environment-variable/config.js +0 -29
- package/src/environment/environment-variable/index.d.ts +0 -1
- package/src/environment/environment-variable/index.js +0 -1
- package/src/environment/environment-variable-name/config.d.ts +0 -2
- package/src/environment/environment-variable-name/config.js +0 -2
- package/src/environment/environment-variable-name/index.d.ts +0 -2
- package/src/environment/environment-variable-name/index.js +0 -2
- package/src/environment/environment-variable-name/type.d.ts +0 -2
- /package/src/{environment/environment-variable-name/type.js → type/readonly/remove-readonly/index.js} +0 -0
package/package.json
CHANGED
@@ -1 +1,10 @@
|
|
1
|
-
|
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
|
-
|
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',
|
23
|
-
|
24
|
-
|
25
|
-
|
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',
|
42
|
-
|
43
|
-
|
44
|
-
|
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',
|
67
|
-
|
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',
|
89
|
-
|
90
|
-
|
91
|
-
|
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',
|
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',
|
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',
|
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',
|
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',
|
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
|
-
|
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,34 @@
|
|
1
|
-
|
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
|
+
else {
|
28
|
+
data[key] = parsed[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
return {
|
32
|
+
data: data,
|
33
|
+
};
|
34
|
+
};
|
@@ -1,12 +1,74 @@
|
|
1
|
-
export declare const
|
2
|
-
readonly app:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
2
|
-
app:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
'
|
12
|
-
'
|
13
|
-
'
|
14
|
-
'
|
15
|
-
'
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
'
|
26
|
-
|
27
|
-
|
28
|
-
'
|
29
|
-
'
|
30
|
-
|
31
|
-
|
32
|
-
'
|
33
|
-
|
34
|
-
|
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
|
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(
|
10
|
-
const isProduction = () => isProd(
|
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 {
|
3
|
-
|
3
|
+
import { ENVIRONMENT_VARIABLES } from './config.js';
|
4
|
+
type Type = RemoveReadonly<typeof ENVIRONMENT_VARIABLES>;
|
4
5
|
export type EnvironmentVariables = {
|
5
|
-
[key in keyof
|
6
|
-
[key2 in
|
6
|
+
[key in keyof Type]: {
|
7
|
+
[key2 in keyof Type[key]]: TypeMap<Type[key][key2]>;
|
7
8
|
};
|
8
9
|
};
|
9
|
-
|
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 {};
|
package/src/environment/index.js
CHANGED
@@ -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,
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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'],
|
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,
|
10
|
+
return composeCustomErrorFunc(message, {
|
11
|
+
info: _info,
|
12
|
+
projectName: _projectName,
|
13
|
+
});
|
12
14
|
};
|
13
15
|
const composeInfo = (info) => {
|
14
16
|
if (!_info && !info) {
|
package/src/type/index.d.ts
CHANGED
package/src/type/index.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './remove-readonly/index.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './remove-readonly/index.js';
|
@@ -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';
|
File without changes
|