1
1
import { config } from 'dotenv' ;
2
2
import { createEnv } from '@t3-oss/env-core' ;
3
3
import { z } from 'zod' ;
4
- import { Base64 } from 'js-base64' ;
5
4
6
- const path = process . env . CI ? '.env.example' : '.env' ;
7
-
8
- console . log ( 'Loading environment variables from' , path ) ;
9
-
10
- config ( { path } ) ;
5
+ config ( { path : process . env . CI ? '.env.example' : '.env' } ) ;
11
6
12
7
const urlArrayTransformer = ( value : string ) => {
13
8
const urlSchema = z . string ( ) . url ( ) ;
@@ -16,108 +11,11 @@ const urlArrayTransformer = (value: string) => {
16
11
return urlArray . map ( url => urlSchema . parse ( url ) ) . sort ( ( a , b ) => a . length - b . length ) ;
17
12
} ;
18
13
19
- export const serverEnvSchema = {
20
- LOG_LEVEL : z . enum ( [ 'debug' , 'info' , 'warn' , 'error' ] ) . default ( 'info' ) ,
21
- NODE_ENV : z . enum ( [ 'development' , 'production' , 'test' , 'local' ] ) , // TODO: remove 'test', 'local'
22
- ENVIRONMENT_NAME : z . enum ( [ 'development' , 'sandbox' , 'production' , 'staging' , 'test' , 'local' ] ) ,
23
- ENV_FILE_NAME : z . string ( ) . optional ( ) ,
24
- BCRYPT_SALT : z . coerce . number ( ) . int ( ) . nonnegative ( ) . or ( z . string ( ) ) ,
25
- PORT : z . coerce . number ( ) ,
26
- DB_URL : z . string ( ) . url ( ) ,
27
- SESSION_SECRET : z . string ( ) ,
28
- HASHING_KEY_SECRET : z . string ( ) . optional ( ) ,
29
- HASHING_KEY_SECRET_BASE64 : z . string ( ) . refine ( Base64 . isValid ) . optional ( ) ,
30
- SESSION_EXPIRATION_IN_MINUTES : z . coerce . number ( ) . nonnegative ( ) . gt ( 0 ) . default ( 60 ) ,
31
- BACKOFFICE_CORS_ORIGIN : z . string ( ) . transform ( urlArrayTransformer ) ,
32
- WORKFLOW_DASHBOARD_CORS_ORIGIN : z . string ( ) . transform ( urlArrayTransformer ) ,
33
- KYB_EXAMPLE_CORS_ORIGIN : z . string ( ) . transform ( urlArrayTransformer ) ,
34
- KYC_EXAMPLE_CORS_ORIGIN : z
35
- . string ( )
36
- . optional ( )
37
- . transform ( value => {
38
- if ( value === undefined ) {
39
- return value ;
40
- }
41
-
42
- return urlArrayTransformer ( value ) ;
43
- } ) ,
44
- AWS_S3_BUCKET_NAME : z . string ( ) . optional ( ) ,
45
- AWS_S3_BUCKET_KEY : z . string ( ) . optional ( ) ,
46
- AWS_S3_BUCKET_SECRET : z . string ( ) . optional ( ) ,
47
- API_KEY : z . string ( ) ,
48
- SENTRY_DSN : z . string ( ) . nullable ( ) . optional ( ) ,
49
- RELEASE : z . string ( ) . nullable ( ) . optional ( ) ,
50
- ADMIN_API_KEY : z . string ( ) . optional ( ) ,
51
- MAIL_ADAPTER : z
52
- . enum ( [ 'sendgrid' , 'log' ] )
53
- . default ( 'sendgrid' )
54
- . describe (
55
- `Which mail adapter to use. Use "log" during development to log emails to the console. In production, use "sendgrid" to send emails via SendGrid.` ,
56
- ) ,
57
- UNIFIED_API_URL : z . string ( ) . url ( ) . describe ( 'The URL of the Unified API.' ) ,
58
- UNIFIED_API_TOKEN : z
59
- . string ( )
60
- . optional ( )
61
- . describe (
62
- 'API token for the Unified API. Used for authenticating outgoing requests to the Unified API.' ,
63
- ) ,
64
- UNIFIED_API_SHARED_SECRET : z
65
- . string ( )
66
- . optional ( )
67
- . describe ( 'Shared secret for the Unified API. Used for verifying incoming callbacks.' ) ,
68
- SALESFORCE_API_VERSION : z . string ( ) . optional ( ) . default ( '58.0' ) . describe ( 'Salesforce API version' ) ,
69
- SALESFORCE_CONSUMER_KEY : z . string ( ) . optional ( ) . describe ( 'Salesforce consumer key' ) ,
70
- SALESFORCE_CONSUMER_SECRET : z . string ( ) . optional ( ) . describe ( 'Salesforce consumer secret' ) ,
71
- APP_API_URL : z . string ( ) . url ( ) . describe ( 'The URL of the workflows-service API' ) ,
72
- COLLECTION_FLOW_URL : z . string ( ) . url ( ) . optional ( ) . describe ( 'The URL of the Collection Flow App' ) ,
73
- WEB_UI_SDK_URL : z . string ( ) . url ( ) . optional ( ) . describe ( 'The URL of the Web UI SDK App' ) ,
74
- DATA_MIGRATION_BUCKET_NAME : z
75
- . string ( )
76
- . optional ( )
77
- . describe ( 'Bucket name of Data migration folders' ) ,
78
- NOTION_API_KEY : z . string ( ) . describe ( 'Notion API key' ) ,
79
- SECRETS_MANAGER_PROVIDER : z
80
- . enum ( [ 'aws-secrets-manager' , 'in-memory' ] )
81
- . default ( 'aws-secrets-manager' )
82
- . describe ( 'Secrets Manager provider' ) ,
83
- AWS_SECRETS_MANAGER_PREFIX : z
84
- . string ( )
85
- . optional ( )
86
- . default ( '/dev/customers/' )
87
- . describe ( 'AWS Secrets Manager prefix' ) ,
88
- ONGOING_REPORTS_LIMIT : z
89
- . number ( )
90
- . optional ( )
91
- . default ( 50 )
92
- . describe ( 'Limit of ongoing reports for each run' ) ,
93
-
94
- // IN_MEMORY is reserved for environment variables
95
- IN_MEMORIES_SECRET_ACQUIRER_ID : z . string ( ) . optional ( ) ,
96
- IN_MEMORIES_SECRET_PRIVATE_KEY : z . string ( ) . optional ( ) ,
97
- IN_MEMORIES_SECRET_CONSUMER_KEY : z . string ( ) . optional ( ) ,
98
- } ;
99
-
100
- if ( ! process . env [ 'ENVIRONMENT_NAME' ] || process . env [ 'ENVIRONMENT_NAME' ] === 'local' ) {
101
- const severEnvVars : Record < string , string > = { } ;
102
-
103
- // Use a for loop to populate severEnvVars
104
- for ( const key of Object . keys ( serverEnvSchema ) ) {
105
- if ( process . env [ key ] ) {
106
- severEnvVars [ key ] = process . env [ key ] as string ;
107
- }
108
- }
109
-
110
- console . log ( 'Environment variables loaded' , severEnvVars ) ;
111
- }
112
-
113
14
export const env = createEnv ( {
114
15
/*
115
16
* clientPrefix is required.
116
17
*/
117
18
clientPrefix : 'PUBLIC_' ,
118
- < << << << HEAD
119
- server : serverEnvSchema ,
120
- = === ===
121
19
server : {
122
20
LOG_LEVEL : z . enum ( [ 'debug' , 'info' , 'warn' , 'error' ] ) . default ( 'info' ) ,
123
21
NODE_ENV : z . enum ( [ 'development' , 'production' , 'test' , 'local' ] ) , // TODO: remove 'test', 'local'
0 commit comments