@candlerip/shared3 0.0.122 → 0.0.123
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/util.js +33 -11
- package/src/backend/cache/cache/singleton.js +24 -8
- package/src/backend/database/mutation/error-log/create-error-log/util.js +3 -1
- package/src/backend/database/mutation/translation/get-translations/util.js +11 -7
- package/src/backend/database/mutation/translation/get-translations-as-dictionary/util.js +3 -1
- package/src/backend/environment/load-env-file/util.js +3 -1
- package/src/backend/message-broker/message-broker/singleton.js +3 -1
- package/src/dictionary/language/default.d.ts +2 -0
- package/src/dictionary/language/default.js +1 -0
- package/src/dictionary/language/index.d.ts +1 -0
- package/src/dictionary/language/index.js +1 -0
- package/src/error/custom-error/compose-custom-error/index.d.ts +2 -0
- package/src/error/custom-error/compose-custom-error/index.js +7 -0
- package/src/error/custom-error/compose-custom-error/type.d.ts +2 -0
- package/src/error/custom-error/compose-custom-error/type.js +1 -0
- package/src/error/custom-error/index.d.ts +3 -1
- package/src/error/custom-error/index.js +3 -1
- package/src/error/custom-error/serialize-info/index.d.ts +2 -0
- package/src/error/custom-error/serialize-info/index.js +9 -0
- package/src/error/custom-error/serialize-info/type.d.ts +2 -0
- package/src/error/custom-error/serialize-info/type.js +1 -0
- package/src/error/custom-error/worker/index.d.ts +6 -0
- package/src/error/custom-error/worker/index.js +19 -0
- package/src/error/custom-error/worker/type.d.ts +3 -0
- package/src/error/custom-error/worker/type.js +1 -0
- package/src/type/array/validate.js +9 -3
- package/src/type/string/comma-separated/validate.js +9 -3
- package/src/type/string/validate.js +9 -3
- package/src/type/type/validate.js +9 -3
- package/src/error/custom-error/worker.d.ts +0 -7
- package/src/error/custom-error/worker.js +0 -34
package/package.json
CHANGED
@@ -11,45 +11,63 @@ export const getAppConfig = async (props) => {
|
|
11
11
|
resp = await client.send(new appConfigSdk.ListApplicationsCommand());
|
12
12
|
}
|
13
13
|
catch (err) {
|
14
|
-
return
|
14
|
+
return {
|
15
|
+
customError: composeCustomError('Error during list AppConfig Applications', { err }),
|
16
|
+
};
|
15
17
|
}
|
16
18
|
const applications = resp.Items;
|
17
19
|
if (!applications) {
|
18
|
-
return
|
20
|
+
return {
|
21
|
+
customError: composeCustomError('No AppConfig Applications found'),
|
22
|
+
};
|
19
23
|
}
|
20
24
|
const application = applications.find((it) => it.Name === projectName);
|
21
25
|
if (!application) {
|
22
|
-
return
|
26
|
+
return {
|
27
|
+
customError: composeCustomError('AppConfig Application not found'),
|
28
|
+
};
|
23
29
|
}
|
24
30
|
const applicationId = application.Id;
|
25
31
|
try {
|
26
32
|
resp = await client.send(new appConfigSdk.ListEnvironmentsCommand({ ApplicationId: applicationId }));
|
27
33
|
}
|
28
34
|
catch (err) {
|
29
|
-
return
|
35
|
+
return {
|
36
|
+
customError: composeCustomError('Error during list AppConfig Environments', { err }),
|
37
|
+
};
|
30
38
|
}
|
31
39
|
const environments = resp.Items;
|
32
40
|
if (!environments) {
|
33
|
-
return
|
41
|
+
return {
|
42
|
+
customError: composeCustomError('No AppConfig Environments found'),
|
43
|
+
};
|
34
44
|
}
|
35
45
|
const environment = environments.find((it) => it.Name === environmentMode);
|
36
46
|
if (!environment) {
|
37
|
-
return
|
47
|
+
return {
|
48
|
+
customError: composeCustomError('AppConfig Environment not found'),
|
49
|
+
};
|
38
50
|
}
|
39
51
|
const environmentId = environment.Id;
|
40
52
|
try {
|
41
53
|
resp = await client.send(new appConfigSdk.ListConfigurationProfilesCommand({ ApplicationId: applicationId }));
|
42
54
|
}
|
43
55
|
catch (err) {
|
44
|
-
return
|
56
|
+
return {
|
57
|
+
customError: composeCustomError('Error during list AppConfig Configuration Profiles', { err }),
|
58
|
+
};
|
45
59
|
}
|
46
60
|
const configurationProfiles = resp.Items;
|
47
61
|
if (!configurationProfiles) {
|
48
|
-
return
|
62
|
+
return {
|
63
|
+
customError: composeCustomError('No AppConfig Configuration Profiles found'),
|
64
|
+
};
|
49
65
|
}
|
50
66
|
const configurationProfile = configurationProfiles.find((it) => it.Name === `${environmentMode}-profile`);
|
51
67
|
if (!configurationProfile) {
|
52
|
-
return
|
68
|
+
return {
|
69
|
+
customError: composeCustomError('AppConfig Configuration Profile not found'),
|
70
|
+
};
|
53
71
|
}
|
54
72
|
const configurationProfileId = configurationProfile.Id;
|
55
73
|
client = new appConfigDataSdk.AppConfigDataClient();
|
@@ -61,7 +79,9 @@ export const getAppConfig = async (props) => {
|
|
61
79
|
}));
|
62
80
|
}
|
63
81
|
catch (err) {
|
64
|
-
return
|
82
|
+
return {
|
83
|
+
customError: composeCustomError('Error during get AppConfig initial configuration token', { err }),
|
84
|
+
};
|
65
85
|
}
|
66
86
|
const ConfigurationToken = resp.InitialConfigurationToken;
|
67
87
|
let appConfig;
|
@@ -71,7 +91,9 @@ export const getAppConfig = async (props) => {
|
|
71
91
|
appConfig = JSON.parse(appConfigStr);
|
72
92
|
}
|
73
93
|
catch (err) {
|
74
|
-
return
|
94
|
+
return {
|
95
|
+
customError: composeCustomError('Error during get AppConfig', { err }),
|
96
|
+
};
|
75
97
|
}
|
76
98
|
return {
|
77
99
|
data: appConfig,
|
@@ -8,10 +8,14 @@ export const CacheSingleton = (() => {
|
|
8
8
|
let _customErrorWorker;
|
9
9
|
const checkErrorStatus = () => {
|
10
10
|
if (!_isEnabled) {
|
11
|
-
return
|
11
|
+
return {
|
12
|
+
customError: _customErrorWorker.composeCustomError('Cache disabled'),
|
13
|
+
};
|
12
14
|
}
|
13
15
|
if (_err) {
|
14
|
-
return
|
16
|
+
return {
|
17
|
+
customError: _customErrorWorker.composeCustomError('Error connect Cache', { err: _err }),
|
18
|
+
};
|
15
19
|
}
|
16
20
|
return;
|
17
21
|
};
|
@@ -44,10 +48,14 @@ export const CacheSingleton = (() => {
|
|
44
48
|
}
|
45
49
|
}
|
46
50
|
catch (err) {
|
47
|
-
return
|
51
|
+
return {
|
52
|
+
customError: _customErrorWorker.composeCustomError('Error get data from Redis', { err }),
|
53
|
+
};
|
48
54
|
}
|
49
55
|
if (!data) {
|
50
|
-
return
|
56
|
+
return {
|
57
|
+
customError: _customErrorWorker.composeCustomError('No data in Redis'),
|
58
|
+
};
|
51
59
|
}
|
52
60
|
return {
|
53
61
|
data,
|
@@ -63,17 +71,23 @@ export const CacheSingleton = (() => {
|
|
63
71
|
try {
|
64
72
|
const cache = await _client.mGet(keys);
|
65
73
|
if (!isArray(cache, isString)) {
|
66
|
-
return
|
74
|
+
return {
|
75
|
+
customError: _customErrorWorker.composeCustomError('Error get data from redis', { cache }),
|
76
|
+
};
|
67
77
|
}
|
68
78
|
cache.forEach((it, i) => {
|
69
79
|
data[keys[i]] = JSON.parse(it);
|
70
80
|
});
|
71
81
|
}
|
72
82
|
catch (err) {
|
73
|
-
return
|
83
|
+
return {
|
84
|
+
customError: _customErrorWorker.composeCustomError('Error get data from redis', { err }),
|
85
|
+
};
|
74
86
|
}
|
75
87
|
if (Object.keys(data).length !== keys.length) {
|
76
|
-
return
|
88
|
+
return {
|
89
|
+
customError: _customErrorWorker.composeCustomError('Missing data from redis', { data }),
|
90
|
+
};
|
77
91
|
}
|
78
92
|
return {
|
79
93
|
data,
|
@@ -89,7 +103,9 @@ export const CacheSingleton = (() => {
|
|
89
103
|
await _client.set(key, JSON.stringify(data));
|
90
104
|
}
|
91
105
|
catch (err) {
|
92
|
-
return
|
106
|
+
return {
|
107
|
+
customError: _customErrorWorker.composeCustomError('Error set data to redis', { err }),
|
108
|
+
};
|
93
109
|
}
|
94
110
|
return {
|
95
111
|
data: null,
|
@@ -7,7 +7,9 @@ export const createErrorLog = async (customError) => {
|
|
7
7
|
data = await getErrorLogModel().create({ customError });
|
8
8
|
}
|
9
9
|
catch (err) {
|
10
|
-
return
|
10
|
+
return {
|
11
|
+
customError: composeCustomError('Create error log failed', { err }),
|
12
|
+
};
|
11
13
|
}
|
12
14
|
return {
|
13
15
|
data,
|
@@ -13,15 +13,19 @@ export const getTranslations = async (ids) => {
|
|
13
13
|
resp = await getTranslationLogModel().find(query);
|
14
14
|
}
|
15
15
|
catch (err) {
|
16
|
-
return
|
16
|
+
return {
|
17
|
+
customError: _customErrorWorker.composeCustomError('Get translations failed', { err, query }),
|
18
|
+
};
|
17
19
|
}
|
18
20
|
if (ids && resp.length !== ids.length) {
|
19
|
-
return
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
return {
|
22
|
+
customError: _customErrorWorker.composeCustomError('Missing ids from translations', {
|
23
|
+
info: {
|
24
|
+
missing: ids.filter((it) => !resp.find((it2) => it2.id === it)).join(', '),
|
25
|
+
value: ids,
|
26
|
+
},
|
27
|
+
}),
|
28
|
+
};
|
25
29
|
}
|
26
30
|
const data = resp.map((it) => ({ ...it, _id: it._id.toString() }));
|
27
31
|
return {
|
@@ -43,7 +43,9 @@ export const getTranslationsAsDictionary = async (language, ids) => {
|
|
43
43
|
data = await getTranslationLogModel().aggregate(aggregates);
|
44
44
|
}
|
45
45
|
catch (err) {
|
46
|
-
return
|
46
|
+
return {
|
47
|
+
customError: _customErrorWorker.composeCustomError('Get translations failed', { err }),
|
48
|
+
};
|
47
49
|
}
|
48
50
|
return {
|
49
51
|
data: data[0],
|
@@ -6,7 +6,9 @@ export const loadEnvFile = (environmentMode, projectName) => {
|
|
6
6
|
const envFile = dotenv.config({ path: `./${fileName}` });
|
7
7
|
const { error: err, parsed } = envFile;
|
8
8
|
if (err || !parsed) {
|
9
|
-
return
|
9
|
+
return {
|
10
|
+
customError: composeCustomError(`Error loading ${fileName}`, { err }),
|
11
|
+
};
|
10
12
|
}
|
11
13
|
const environmentVariables = ENVIRONMENT_VARIABLES_CONFIG[projectName];
|
12
14
|
return {
|
@@ -8,7 +8,9 @@ export const MessageBrokerSingleton = (() => {
|
|
8
8
|
let _customErrorWorker;
|
9
9
|
const checkErrorStatus = () => {
|
10
10
|
if (_errorMessage) {
|
11
|
-
return
|
11
|
+
return {
|
12
|
+
customError: _customErrorWorker.composeCustomError(_errorMessage),
|
13
|
+
};
|
12
14
|
}
|
13
15
|
return;
|
14
16
|
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export const DEFAULT_LANGUAGE = 'en';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { ProjectSingleton } from '../../../project/index.js';
|
2
|
+
import { composeCustomError as composeCustomErrorFunc } from '../compose-custom-error/index.js';
|
3
|
+
export const customErrorWorker = (info) => {
|
4
|
+
let _info = info;
|
5
|
+
const addInfo = (info) => {
|
6
|
+
_info = {
|
7
|
+
..._info,
|
8
|
+
...info,
|
9
|
+
};
|
10
|
+
};
|
11
|
+
const composeCustomError = (message, info) => composeCustomErrorFunc(message, ProjectSingleton.getProjectName(), {
|
12
|
+
..._info,
|
13
|
+
...info,
|
14
|
+
});
|
15
|
+
return {
|
16
|
+
addInfo,
|
17
|
+
composeCustomError,
|
18
|
+
};
|
19
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -2,13 +2,19 @@ import { customErrorWorker } from '../../error/index.js';
|
|
2
2
|
export const validateArray = (data, name, valid) => {
|
3
3
|
const { composeCustomError } = customErrorWorker({ data, name, valid });
|
4
4
|
if (!data) {
|
5
|
-
return
|
5
|
+
return {
|
6
|
+
customError: composeCustomError(`Missing ${name}`),
|
7
|
+
};
|
6
8
|
}
|
7
9
|
if (!Array.isArray(data)) {
|
8
|
-
return
|
10
|
+
return {
|
11
|
+
customError: composeCustomError(`Invalid ${name}`),
|
12
|
+
};
|
9
13
|
}
|
10
14
|
if (!data.every((it) => valid.includes(it))) {
|
11
|
-
return
|
15
|
+
return {
|
16
|
+
customError: composeCustomError(`Invalid ${name}`),
|
17
|
+
};
|
12
18
|
}
|
13
19
|
return {
|
14
20
|
data,
|
@@ -4,14 +4,20 @@ import { isString } from '../type-guard.js';
|
|
4
4
|
export const validateCommaSeparatedString = (data, name, valid) => {
|
5
5
|
const { composeCustomError } = customErrorWorker({ data, name, valid });
|
6
6
|
if (!data) {
|
7
|
-
return
|
7
|
+
return {
|
8
|
+
customError: composeCustomError(`Missing ${name}`),
|
9
|
+
};
|
8
10
|
}
|
9
11
|
if (!isString(data)) {
|
10
|
-
return
|
12
|
+
return {
|
13
|
+
customError: composeCustomError(`${name} not string`),
|
14
|
+
};
|
11
15
|
}
|
12
16
|
const parsedArr = data.split(',');
|
13
17
|
if (parsedArr.length === 0) {
|
14
|
-
return
|
18
|
+
return {
|
19
|
+
customError: composeCustomError(`Invalid ${name}`),
|
20
|
+
};
|
15
21
|
}
|
16
22
|
return validateArray(parsedArr, name, valid);
|
17
23
|
};
|
@@ -3,14 +3,20 @@ import { isString } from './type-guard.js';
|
|
3
3
|
export const validateString = (data, name, regexp) => {
|
4
4
|
const { composeCustomError } = customErrorWorker({ data, name, regexp: JSON.stringify(regexp) });
|
5
5
|
if (!data) {
|
6
|
-
return
|
6
|
+
return {
|
7
|
+
customError: composeCustomError(`Missing ${name}`),
|
8
|
+
};
|
7
9
|
}
|
8
10
|
if (!isString(data)) {
|
9
|
-
return
|
11
|
+
return {
|
12
|
+
customError: composeCustomError(`${name} not string`),
|
13
|
+
};
|
10
14
|
}
|
11
15
|
if (regexp) {
|
12
16
|
if (!regexp.test(data)) {
|
13
|
-
return
|
17
|
+
return {
|
18
|
+
customError: composeCustomError(`Invalid ${name}`),
|
19
|
+
};
|
14
20
|
}
|
15
21
|
}
|
16
22
|
return {
|
@@ -4,13 +4,19 @@ export const validateType = (data, name, valids) => {
|
|
4
4
|
const _customErrorWorker = customErrorWorker();
|
5
5
|
_customErrorWorker.addInfo({ data, name, valids });
|
6
6
|
if (!data) {
|
7
|
-
return
|
7
|
+
return {
|
8
|
+
customError: _customErrorWorker.composeCustomError(`Missing ${name}`),
|
9
|
+
};
|
8
10
|
}
|
9
11
|
if (!isString(data)) {
|
10
|
-
return
|
12
|
+
return {
|
13
|
+
customError: _customErrorWorker.composeCustomError(`Invalid ${name}`),
|
14
|
+
};
|
11
15
|
}
|
12
16
|
if (!valids.includes(data)) {
|
13
|
-
return
|
17
|
+
return {
|
18
|
+
customError: _customErrorWorker.composeCustomError(`Invalid ${name}`),
|
19
|
+
};
|
14
20
|
}
|
15
21
|
return {
|
16
22
|
data: data,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
import { CustomError } from './type.js';
|
2
|
-
export declare const customErrorWorker: (info?: CustomError["info"]) => {
|
3
|
-
addInfo: (info?: CustomError["info"]) => void;
|
4
|
-
composeCustomError: (message: CustomError["message"], info?: CustomError["info"]) => {
|
5
|
-
customError: CustomError;
|
6
|
-
};
|
7
|
-
};
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { ProjectSingleton } from '../../project/index.js';
|
2
|
-
export const customErrorWorker = (info) => {
|
3
|
-
let _info = info;
|
4
|
-
const _serializeInfo = (info) => {
|
5
|
-
if (!info) {
|
6
|
-
return;
|
7
|
-
}
|
8
|
-
if (info?.err) {
|
9
|
-
info.err = JSON.stringify(info?.err, Object.getOwnPropertyNames(info?.err));
|
10
|
-
}
|
11
|
-
return info;
|
12
|
-
};
|
13
|
-
const addInfo = (info) => {
|
14
|
-
_info = {
|
15
|
-
..._info,
|
16
|
-
..._serializeInfo(info),
|
17
|
-
};
|
18
|
-
};
|
19
|
-
const composeCustomError = (message, info) => ({
|
20
|
-
customError: {
|
21
|
-
id: Math.random().toString(16).slice(2).toUpperCase(),
|
22
|
-
info: {
|
23
|
-
..._info,
|
24
|
-
..._serializeInfo(info),
|
25
|
-
},
|
26
|
-
message,
|
27
|
-
projectName: ProjectSingleton.getProjectName(),
|
28
|
-
},
|
29
|
-
});
|
30
|
-
return {
|
31
|
-
addInfo,
|
32
|
-
composeCustomError,
|
33
|
-
};
|
34
|
-
};
|