-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
361 lines (331 loc) · 8.66 KB
/
index.ts
File metadata and controls
361 lines (331 loc) · 8.66 KB
1
2
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import { resolve } from 'node:path'
import convict, { type SchemaObj } from 'convict'
import { type LevelWithSilent } from 'pino'
import 'dotenv/config'
const isProduction = process.env.NODE_ENV === 'production'
const isDev = process.env.NODE_ENV !== 'production'
const isTest = process.env.NODE_ENV === 'test'
export const config = convict({
appDir: {
format: String,
default: resolve(import.meta.dirname, '../server')
},
publicDir: {
format: String,
default: isTest
? resolve(import.meta.dirname, '../../test/fixtures')
: resolve(import.meta.dirname, '../../.public')
},
/**
* Server
*/
port: {
format: 'port',
default: null,
env: 'PORT'
} as SchemaObj<number>,
env: {
doc: 'The application environment.',
format: ['production', 'development', 'test'],
default: null,
env: 'NODE_ENV'
} as SchemaObj<'production' | 'development' | 'test'>,
cdpEnvironment: {
doc: 'The CDP environment the app is currently in, with the addition of "local"',
format: [
'local',
'infra-dev',
'management',
'dev',
'test',
'perf-test',
'ext-test',
'prod'
],
default: null,
env: 'ENVIRONMENT'
} as SchemaObj<
| 'local'
| 'infra-dev'
| 'management'
| 'dev'
| 'test'
| 'perf-test'
| 'ext-test'
| 'prod'
>,
enforceCsrf: {
format: Boolean,
default: null,
env: 'ENFORCE_CSRF'
} as SchemaObj<boolean>,
/**
* Helper flags
*/
isProduction: {
doc: 'If this application running in the production environment',
format: Boolean,
default: isProduction
},
isDevelopment: {
doc: 'If this application running in the development environment',
format: Boolean,
default: isDev
},
isTest: {
doc: 'If this application running in the test environment',
format: Boolean,
default: isTest
},
/**
* Service
*/
serviceName: {
doc: 'Applications Service Name',
format: String,
default: 'Submit a form to Defra'
},
serviceVersion: {
doc: 'The service version, this variable is injected into your docker container in CDP environments',
format: String,
default: null,
env: 'SERVICE_VERSION'
} as SchemaObj<string>,
phaseTag: {
format: String,
default: null, // Accepts "alpha" |"beta" | ""
env: 'PHASE_TAG'
} as SchemaObj<string>,
/**
* Session storage
* Redis integration is optional, but recommended for production environments.
*/
sessionTimeout: {
format: Number,
default: null,
env: 'SESSION_TIMEOUT'
} as SchemaObj<number>,
confirmationSessionTimeout: {
format: Number,
default: null,
env: 'CONFIRMATION_SESSION_TIMEOUT'
} as SchemaObj<number>,
sessionCookiePassword: {
format: String,
default: null,
sensitive: true,
env: 'SESSION_COOKIE_PASSWORD'
} as SchemaObj<string>,
redis: {
host: {
doc: 'Redis cache host',
format: String,
default: null,
env: 'REDIS_HOST'
} as SchemaObj<string>,
username: {
doc: 'Redis cache username',
format: String,
default: null,
env: 'REDIS_USERNAME'
} as SchemaObj<string>,
password: {
doc: 'Redis cache password',
format: '*',
default: null,
sensitive: true,
env: 'REDIS_PASSWORD'
} as SchemaObj<string>,
keyPrefix: {
doc: 'Redis cache key prefix name used to isolate the cached results across multiple clients',
format: String,
default: null,
env: 'REDIS_KEY_PREFIX'
} as SchemaObj<string>,
useSingleInstanceCache: {
doc: 'Redis use single cache (non-clustered)',
format: Boolean,
default: null,
env: 'USE_SINGLE_INSTANCE_CACHE'
} as SchemaObj<boolean>
},
tracing: {
header: {
doc: 'Tracing header name',
format: String,
default: null,
env: 'TRACING_HEADER'
} as SchemaObj<string>
},
/**
* AWS SNS Configuration
*/
awsRegion: {
format: String,
default: null,
env: 'AWS_REGION'
} as SchemaObj<string>,
snsAdapterTopicArn: {
format: String,
default: null,
env: 'SNS_ADAPTER_TOPIC_ARN'
} as SchemaObj<string>,
snsSaveTopicArn: {
format: String,
default: null,
env: 'SNS_SAVE_TOPIC_ARN'
} as SchemaObj<string>,
snsEndpoint: {
format: String,
default: null,
env: 'SNS_ENDPOINT'
} as SchemaObj<string>,
snsFormTopicArnMap: {
doc: 'JSON object mapping formId to SNS topic ARN for per-form additional topic routing',
format: String,
default: null,
env: 'SNS_FORM_TOPIC_ARN_MAP'
} as SchemaObj<string>,
/**
* API integrations
*/
baseUrl: {
format: String,
default: null,
env: 'BASE_URL'
} as SchemaObj<string>,
managerUrl: {
format: String,
default: null,
env: 'MANAGER_URL'
} as SchemaObj<string>,
designerUrl: {
format: String,
default: null,
env: 'DESIGNER_URL'
} as SchemaObj<string>,
submissionUrl: {
format: String,
default: null,
env: 'SUBMISSION_URL'
} as SchemaObj<string>,
uploaderUrl: {
format: String,
default: null,
env: 'UPLOADER_URL'
} as SchemaObj<string>,
uploaderBucketName: {
format: String,
default: null,
env: 'UPLOADER_BUCKET_NAME'
} as SchemaObj<string>,
paymentProviderUrl: {
doc: 'Base URL of the hosted payment provider (GOV.UK Pay) users are redirected to after submitting the payment form. Used to allow the redirect target in the form-action CSP directive.',
format: String,
default: null,
env: 'PAYMENT_PROVIDER_URL'
} as SchemaObj<string>,
/**
* Logging
*/
log: {
enabled: {
doc: 'Is logging enabled',
format: Boolean,
default: null,
env: 'LOG_ENABLED'
} as SchemaObj<boolean>,
level: {
doc: 'Logging level',
format: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],
default: null,
env: 'LOG_LEVEL'
} as SchemaObj<LevelWithSilent>,
format: {
doc: 'Format to output logs in.',
format: ['ecs', 'pino-pretty'],
default: null,
env: 'LOG_FORMAT'
} as SchemaObj<'ecs' | 'pino-pretty'>,
redact: {
doc: 'Log paths to redact',
format: Array,
default: isProduction
? ['req.headers.authorization', 'req.headers.cookie', 'res.headers']
: ['req', 'res', 'responseTime']
}
},
stagingPrefix: {
doc: 'Prefix for staging files in S3',
format: String,
default: null,
env: 'STAGING_PREFIX'
} as SchemaObj<string>,
serviceBannerText: {
doc: 'Service banner text used to show a maintenance message on all pages when set',
format: String,
default: null,
nullable: true,
env: 'SERVICE_BANNER_TEXT'
} as SchemaObj<string | null>,
googleTagManagerContainerId: {
doc: 'Google Tag Manager container ID to be used when a user has opted in to additional cookies',
format: String,
default: null,
nullable: true,
env: 'GOOGLE_TAG_MANAGER_CONTAINER_ID'
} as SchemaObj<string | null>,
googleAnalyticsContainerId: {
doc: 'Google Analytics container ID suffix (from the GA4 measurement ID, without the G- prefix) used to display the exact cookie name on the cookies page',
format: String,
default: null,
nullable: true,
env: 'GOOGLE_ANALYTICS_CONTAINER_ID'
} as SchemaObj<string | null>,
saveAndExitExpiryDays: {
format: Number,
default: null,
env: 'SAVE_AND_EXIT_EXPIRY_IN_DAYS'
} as SchemaObj<number>,
storeCompletedApplicationsFor: {
format: String,
default: null,
env: 'STORE_COMPLETED_APPLICATIONS_FOR'
} as SchemaObj<string>,
storeFeedbackFor: {
format: String,
default: null,
env: 'STORE_FEEDBACK_FOR'
} as SchemaObj<string>,
ordnanceSurveyApiKey: {
doc: 'The ordnance survey api key used by the postcode lookup and maps plugin',
format: String,
default: null,
env: 'ORDNANCE_SURVEY_API_KEY'
} as SchemaObj<string>,
ordnanceSurveyApiSecret: {
doc: 'The ordnance survey api secret used by the maps plugin',
format: String,
default: null,
env: 'ORDNANCE_SURVEY_API_SECRET'
} as SchemaObj<string>,
useMapsFeature: {
doc: 'Feature flag to control maps',
format: Boolean,
default: null,
env: 'USE_MAPS_FEATURE'
} as SchemaObj<boolean>,
feedbackViaEmail: {
doc: 'The email address (not including the mailto prefix) for feedback when the built-in CSAT form is disabled.',
format: String,
default: null,
env: 'FEEDBACK_VIA_EMAIL'
} as SchemaObj<string>,
privateKeyForSecrets: {
doc: 'The private key used to decrypt secret values',
format: String,
default: null,
env: 'PRIVATE_KEY_FOR_SECRETS'
} as SchemaObj<string>
})
config.validate({ allowed: 'strict' })