Skip to content

Commit 10e4422

Browse files
committed
add optional
Signed-off-by: rockito10 <[email protected]>
1 parent dce1c43 commit 10e4422

File tree

5 files changed

+241
-211
lines changed

5 files changed

+241
-211
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ module.exports = {
101101
'prefer-template': 'error',
102102
quotes: ['warn', 'single', { allowTemplateLiterals: true }]
103103
}
104-
};
104+
};

config.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

config/Validator.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import validator from 'validator';
2+
3+
interface ValidationResponse {
4+
message: string;
5+
success: boolean;
6+
received: string;
7+
}
8+
9+
// interface Params {
10+
// message?: string
11+
// }
12+
13+
export class Validator {
14+
protocol = (protocol: string): ValidationResponse => {
15+
const success = ['http', 'https'].includes(protocol);
16+
17+
return {
18+
message: `Invalid protocol. Must be 'http' or 'https'.`,
19+
success,
20+
received: protocol
21+
};
22+
};
23+
24+
port = (port: string): ValidationResponse => {
25+
const portNumber = Number(port);
26+
const success = validator.isNumeric(port) && 1024 < portNumber && 65536 > portNumber;
27+
28+
return {
29+
message: 'Invalid port. Must be a number between 1024 and 65536.',
30+
success,
31+
received: port
32+
};
33+
};
34+
// port = (value: string, { message } : Params): ValidationResponse => {
35+
// const portNumber = Number(value);
36+
// const success = validator.isNumeric(value) && 1024 < portNumber && 65536 > portNumber;
37+
38+
// return {
39+
// message: message || 'Invalid port. Must be a number between 1024 and 65536.',
40+
// received: value,
41+
// success
42+
// };
43+
// };
44+
45+
host = (host: string): ValidationResponse => {
46+
const domainRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z]{2,})+$/;
47+
48+
const success = validator.isIP(host) || domainRegex.test(host) || 'localhost' === host;
49+
50+
return {
51+
message: 'Invalid host. Check the IP address.',
52+
received: host,
53+
success
54+
};
55+
};
56+
57+
endpoint = (endpoint: string): ValidationResponse => {
58+
const [host, port] = endpoint.split(':');
59+
60+
const { message: hostMessage, success: hostSuccess } = this.host(host);
61+
const { message: portMessage, success: portSuccess } = this.port(port);
62+
63+
return {
64+
message: `Invalid endpoint: ${hostSuccess ? '' : hostMessage} ${portSuccess ? '' : portMessage}`,
65+
received: endpoint,
66+
success: hostSuccess && portSuccess
67+
};
68+
};
69+
70+
url = (url: string): ValidationResponse => ({
71+
message: `Invalid URL.`,
72+
received: url,
73+
success: validator.isURL(url) || url.startsWith('http:/localhost') // FIXME:
74+
});
75+
76+
number = (numberString: string): ValidationResponse => ({
77+
message: `Invalid number.`,
78+
received: numberString,
79+
success: validator.isNumeric(numberString)
80+
});
81+
82+
notEmpty = (val: string): ValidationResponse => ({
83+
// stub method, filler
84+
message: ``,
85+
received: val,
86+
success: true
87+
});
88+
89+
email = (email: string): ValidationResponse => {
90+
const success = validator.isEmail(email);
91+
92+
return {
93+
message: `Invalid email. Must be in the form [email protected]`,
94+
received: email,
95+
success
96+
};
97+
};
98+
}

config/config.ts

Lines changed: 135 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,144 @@
1-
import { Validator, ConfigSchema } from './env-validation';
1+
import { ConfigSchema } from './env-validation';
2+
3+
import { Validator } from './Validator';
24

35
// --------------------------------------------------------------------------------
46

57
const v = new Validator();
68

79
const mySchema = new ConfigSchema({
8-
API_GATEWAY_PROTOCOL: v.protocol,
9-
API_GATEWAY_HOST: v.host,
10-
API_GATEWAY_PORT: v.port,
11-
API_GATEWAY_PROTOCOL_SECURE: v.protocol,
12-
API_ENDPOINT: v.endpoint,
13-
14-
FRONT_END_URL: v.url,
15-
16-
MOBILE_APP: v.exists,
17-
MOBILE_APP_NAME: v.exists,
18-
MOBILE_APP_DOWNLOAD_URL: v.url,
19-
PLAY_STORE_DOWNLOAD_LINK: v.url,
20-
IOS_DOWNLOAD_LINK: v.url,
21-
22-
PLATFORM_NAME: v.exists,
23-
POWERED_BY: v.exists,
24-
PLATFORM_WEB_URL: v.url,
25-
POWERED_BY_URL: v.url,
26-
UPLOAD_LOGO_HOST: v.host,
27-
BRAND_LOGO: v.url,
28-
PLATFORM_ADMIN_EMAIL: v.email,
29-
30-
SOCKET_HOST: v.host
10+
API_GATEWAY_PROTOCOL: { method: v.protocol },
11+
API_GATEWAY_HOST: { method: v.host },
12+
API_GATEWAY_PORT: { method: v.port },
13+
API_GATEWAY_PROTOCOL_SECURE: { method: v.protocol },
14+
API_ENDPOINT: { method: v.endpoint },
15+
16+
FRONT_END_URL: { method: v.url },
17+
18+
MOBILE_APP: { method: v.notEmpty },
19+
MOBILE_APP_NAME: { method: v.notEmpty },
20+
MOBILE_APP_DOWNLOAD_URL: { method: v.url },
21+
PLAY_STORE_DOWNLOAD_LINK: { method: v.url }, // tiene forma concret}a
22+
IOS_DOWNLOAD_LINK: { method: v.url }, // tiene forma concret}a
23+
24+
PLATFORM_NAME: { method: v.notEmpty },
25+
POWERED_BY: { method: v.notEmpty },
26+
PLATFORM_WEB_URL: { method: v.url },
27+
POWERED_BY_URL: { method: v.url },
28+
UPLOAD_LOGO_HOST: { method: v.host },
29+
BRAND_LOGO: { method: v.url },
30+
PLATFORM_ADMIN_EMAIL: { method: v.email },
31+
32+
SOCKET_HOST: { method: v.host },
33+
34+
NATS_HOST: { method: v.host },
35+
NATS_PORT: { method: v.port },
36+
NATS_URL: { method: v.url },
37+
38+
REDIS_HOST: { method: v.host },
39+
REDIS_PORT: { method: v.port },
40+
41+
WALLET_STORAGE_HOST: { method: v.host },
42+
WALLET_STORAGE_PORT: { method: v.port },
43+
WALLET_STORAGE_USER: { method: v.notEmpty },
44+
WALLET_STORAGE_PASSWORD: { method: v.notEmpty },
45+
46+
CRYPTO_PRIVATE_KEY: { method: v.notEmpty },
47+
PLATFORM_URL: { method: v.url }, // debe tener la forma https://devapi.credebl.i}d
48+
PLATFORM_PROFILE_MODE: { method: v.notEmpty },
49+
50+
PUBLIC_LOCALHOST_URL: { method: v.url }, // tiene que ser localhost sí o s
51+
PUBLIC_DEV_API_URL: { method: v.url }, //en el env tienen una forma específic}a
52+
PUBLIC_QA_API_URL: { method: v.url }, //en el env tienen una forma específic}a
53+
PUBLIC_PRODUCTION_API_URL: { method: v.url }, //en el env tienen una forma específic}a
54+
PUBLIC_SANDBOX_API_URL: { method: v.url }, //en el env tienen una forma específic}a
55+
PUBLIC_PLATFORM_SUPPORT_EMAIL: { method: v.email },
56+
57+
AFJ_VERSION: { method: v.notEmpty }, // también tiene una forma concret}a
58+
59+
PLATFORM_WALLET_NAME: { method: v.notEmpty },
60+
PLATFORM_WALLET_PASSWORD: { method: v.notEmpty },
61+
PLATFORM_SEED: { method: v.notEmpty },
62+
PLATFORM_ID: { method: v.number },
63+
64+
POOL_DATABASE_URL: { method: v.postgresUrl }, // postgre}s
65+
DATABASE_URL: { method: v.posgresUrl },
66+
67+
AWS_ACCESS_KEY: { method: v.notEmpty, optional: true },
68+
AWS_SECRET_KEY: { method: v.notEmpty, optional: true },
69+
AWS_REGION: { method: v.notEmpty, optional: true },
70+
AWS_BUCKET: { method: v.notEmpty, optional: true },
71+
72+
AWS_PUBLIC_ACCESS_KEY: { method: v.notEmpty, optional: true },
73+
AWS_PUBLIC_SECRET_KEY: { method: v.notEmpty, optional: true },
74+
AWS_PUBLIC_REGION: { method: v.notEmpty, optional: true },
75+
AWS_ORG_LOGO_BUCKET_NAME: { method: v.notEmpty, optional: true },
76+
77+
AWS_S3_STOREOBJECT_ACCESS_KEY: { method: v.notEmpty },
78+
AWS_S3_STOREOBJECT_SECRET_KEY: { method: v.notEmpty },
79+
AWS_S3_STOREOBJECT_REGION: { method: v.notEmpty },
80+
AWS_S3_STOREOBJECT_BUCKET: { method: v.notEmpty },
81+
82+
SHORTENED_URL_DOMAIN: { method: v.url }, // tiene una forma concret}
83+
DEEPLINK_DOMAIN: { method: v.notEmpty }, //tiene una forma concret}
84+
85+
ENABLE_CORS_IP_LIST: { method: v.multipleUrl },
86+
87+
USER_NKEY_SEED: { method: v.notEmpty },
88+
API_GATEWAY_NKEY_SEED: { method: v.notEmpty },
89+
ORGANIZATION_NKEY_SEED: { method: v.notEmpty },
90+
AGENT_PROVISIONING_NKEY_SEED: { method: v.notEmpty },
91+
AGENT_SERVICE_NKEY_SEED: { method: v.notEmpty },
92+
VERIFICATION_NKEY_SEED: { method: v.notEmpty },
93+
LEDGER_NKEY_SEED: { method: v.notEmpty },
94+
ISSUANCE_NKEY_SEED: { method: v.notEmpty },
95+
CONNECTION_NKEY_SEED: { method: v.notEmpty },
96+
ECOSYSTEM_NKEY_SEED: { method: v.notEmpty },
97+
CREDENTAILDEFINITION_NKEY_SEED: { method: v.notEmpty },
98+
SCHEMA_NKEY_SEED: { method: v.notEmpty },
99+
UTILITIES_NKEY_SEED: { method: v.notEmpty },
100+
CLOUD_WALLET_NKEY_SEED: { method: v.notEmpty },
101+
GEOLOCATION_NKEY_SEED: { method: v.notEmpty },
102+
NOTIFICATION_NKEY_SEED: { method: v.notEmpty },
103+
104+
KEYCLOAK_DOMAIN: { method: v.domain },
105+
KEYCLOAK_ADMIN_URL: { method: v.url },
106+
KEYCLOAK_MASTER_REALM: { method: v.notEmpty },
107+
KEYCLOAK_MANAGEMENT_CLIENT_ID: { method: v.notEmpty },
108+
KEYCLOAK_MANAGEMENT_CLIENT_SECRET: { method: v.notEmpty },
109+
KEYCLOAK_REALM: { method: v.notEmpty },
110+
111+
SCHEMA_FILE_SERVER_URL: { method: v.notEmpty }, // tiene una forma concret}a
112+
SCHEMA_FILE_SERVER_TOKEN: { method: v.notEmpty },
113+
114+
GEO_LOCATION_MASTER_DATA_IMPORT_SCRIPT: { method: v.location },
115+
UPDATE_CLIENT_CREDENTIAL_SCRIPT: { method: v.location },
116+
117+
AFJ_AGENT_TOKEN_PATH: { method: v.existsLocation },
118+
AFJ_AGENT_SPIN_UP: { method: v.existsLocation },
119+
AFJ_AGENT_ENDPOINT_PATH: { method: v.existsLocation },
120+
121+
AFJ_AGENT_TOKEN_PATH: { method: v.location, optional: true },
122+
AFJ_AGENT_SPIN_UP: { method: v.location, optional: true },
123+
AFJ_AGENT_ENDPOINT_PATH: { method: v.location, optional: true },
124+
125+
AGENT_PROTOCOL: { method: v.protocol },
126+
OOB_BATCH_SIZE: { method: v.number },
127+
PROOF_REQ_CONN_LIMIT: { method: v.number },
128+
MAX_ORG_LIMIT: { method: v.number },
129+
FIDO_API_ENDPOINT: { method: v.endpoint },
130+
131+
IS_ECOSYSTEM_ENABLE: { method: v.boolean },
132+
CONSOLE_LOG_FLAG: { method: v.boolean },
133+
ELK_LOG: { method: v.boolean },
134+
LOG_LEVEL: { method: v.notEmpty },
135+
ELK_LOG_PATH: { method: v.url },
136+
ELK_USERNAME: { method: v.notEmpty },
137+
ELK_PASSWORD: { method: v.notEmpty },
138+
139+
ORGANIZATION: { method: v.notEmpty },
140+
CONTEXT: { method: v.notEmpty },
141+
APP: { method: v.notEmpty }
31142
});
32143

33144
const { errors, success, data } = mySchema.safeParse();

0 commit comments

Comments
 (0)