@@ -2,8 +2,10 @@ import convict, { type Config as TConfig } from 'convict';
2
2
import { config } from 'dotenv' ;
3
3
4
4
import { AppEnvironment } from '~/libs/enums/enums.js' ;
5
+ import { ConfigValidationError } from '~/libs/exceptions/exceptions.js' ;
5
6
import { type ILogger } from '~/libs/packages/logger/logger.js' ;
6
7
8
+ import { FormatRegex } from './libs/enums/enums.js' ;
7
9
import { type IConfig } from './libs/interfaces/interfaces.js' ;
8
10
import { type EnvironmentSchema } from './libs/types/types.js' ;
9
11
@@ -28,6 +30,28 @@ class Config implements IConfig {
28
30
}
29
31
30
32
private get envSchema ( ) : TConfig < EnvironmentSchema > {
33
+ convict . addFormat ( {
34
+ name : 'boolean_string' ,
35
+ validate : ( value : string , schema : convict . SchemaObj ) => {
36
+ if ( value !== 'true' && value !== 'false' ) {
37
+ throw new ConfigValidationError ( {
38
+ message : `Invalid ${ schema . env ?? '' } format` ,
39
+ } ) ;
40
+ }
41
+ } ,
42
+ } ) ;
43
+
44
+ convict . addFormat ( {
45
+ name : 'email' ,
46
+ validate : ( value : string , schema : convict . SchemaObj ) => {
47
+ if ( ! FormatRegex . EMAIL . test ( value ) ) {
48
+ throw new ConfigValidationError ( {
49
+ message : `Invalid ${ schema . env ?? '' } format` ,
50
+ } ) ;
51
+ }
52
+ } ,
53
+ } ) ;
54
+
31
55
return convict < EnvironmentSchema > ( {
32
56
APP : {
33
57
ENVIRONMENT : {
@@ -83,6 +107,40 @@ class Config implements IConfig {
83
107
default : null ,
84
108
} ,
85
109
} ,
110
+ MAILER : {
111
+ SENDGRID_API_KEY : {
112
+ doc : 'Twilio SendGrid API key' ,
113
+ format : String ,
114
+ env : 'SENDGRID_API_KEY' ,
115
+ default : null ,
116
+ } ,
117
+ SENDGRID_USER : {
118
+ doc : 'Twilio SendGrid SMTP username' ,
119
+ format : String ,
120
+ env : 'SENDGRID_USER' ,
121
+ default : 'apikey' ,
122
+ } ,
123
+ SMTP_TLS : {
124
+ doc : 'Whether SMTP connection uses TLS' ,
125
+ env : 'SMTP_TLS' ,
126
+ format : 'boolean_string' ,
127
+ default : true ,
128
+ } ,
129
+ SENDGRID_SENDER_EMAIL : {
130
+ doc : 'Sendgrid verified sender email' ,
131
+ env : 'SENDGRID_SENDER_EMAIL' ,
132
+ format : 'email' ,
133
+ default : null ,
134
+ } ,
135
+ } ,
136
+ API : {
137
+ GOOGLE_MAPS_API_KEY : {
138
+ doc : 'Key for Google maps API' ,
139
+ format : String ,
140
+ env : 'GOOGLE_MAPS_API_KEY' ,
141
+ default : null ,
142
+ } ,
143
+ } ,
86
144
} ) ;
87
145
}
88
146
}
0 commit comments