Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/features/configuration-based/page-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Currently supported event types:

## Payload

forms-engine-plugin sends a standardised payload to each API configured with page events. The latest version of our payload [can be found in our outputFormatters module by opening the latest version, e.g. `v2.ts`](https://github.com/DEFRA/forms-engine-plugin/tree/main/src/server/plugins/engine/outputFormatters/machine). Our payload contains some metadata about the payload, along with a "data" section that contains the main body of the form as a JSON object, an array of repeatable pages, and a file ID and download link for all files submitted.
forms-engine-plugin sends a standardised payload to each API configured with page events. The latest version of our payload [can be found in our outputFormatters module by opening the latest version, e.g. `v2.js`](https://github.com/DEFRA/forms-engine-plugin/tree/main/src/server/plugins/engine/outputFormatters/machine). Our payload contains some metadata about the payload, along with a "data" section that contains the main body of the form as a JSON object, an array of repeatable pages, and a file ID and download link for all files submitted.

The payload takes the following shape:

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"test:watch": "jest --color --watch",
"client:watch": "NODE_ENV=development npm run build:client -- --watch",
"server:watch": "NODE_ENV=development tsx watch --clear-screen=false --enable-source-maps --exclude \"**/*.test.*\"",
"server:watch:dev": "npm run server:watch -- ./src/index.ts",
"server:watch:debug": "npm run server:watch -- --inspect-wait ./src/index.ts",
"server:watch:dev": "npm run server:watch -- ./src/index.js",
"server:watch:debug": "npm run server:watch -- --inspect-wait ./src/index.js",
"prestart": "npm run build",
"start": "NODE_ENV=${NODE_ENV:-production} node --enable-source-maps ./.server",
"setup:husky": "node -e \"try { (await import('husky')).default() } catch (e) { if (e.code !== 'ERR_MODULE_NOT_FOUND') throw e }\" --input-type module"
Expand Down
76 changes: 40 additions & 36 deletions src/config/index.ts → src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { resolve } from 'node:path'

import convict, { type SchemaObj } from 'convict'
import { type LevelWithSilent } from 'pino'
import convict from 'convict'

import 'dotenv/config'

Expand Down Expand Up @@ -86,19 +85,19 @@
format: String,
default: 'Digital Express Toolkit'
},
serviceVersion: {
serviceVersion: /** @type {SchemaObj<string>} */ ({
doc: 'The service version, this variable is injected into your docker container in CDP environments',
format: String,
nullable: true,
default: '',
env: 'SERVICE_VERSION'
} as SchemaObj<string>,
feedbackLink: {
}),
feedbackLink: /** @type {SchemaObj<string>} */ ({
doc: 'Used in your phase banner. Can be a URL or more commonly mailto mailto:feedback@department.gov.uk',
format: String,
default: '',
env: 'FEEDBACK_LINK'
} as SchemaObj<string>,
}),
phaseTag: {
format: String,
default: 'beta', // Accepts "alpha" |"beta" | ""
Expand All @@ -116,86 +115,86 @@
},
confirmationSessionTimeout: {
format: Number,
default: oneMinute * 20,

Check warning on line 118 in src/config/index.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

No magic number: 20.

See more on https://sonarcloud.io/project/issues?id=DEFRA_forms-engine-plugin&issues=AaIPdVrZjkK2xe4mbVWu&open=AaIPdVrZjkK2xe4mbVWu&pullRequest=507
env: 'CONFIRMATION_SESSION_TIMEOUT'
},
sessionCookiePassword: {
sessionCookiePassword: /** @type {SchemaObj<string>} */ ({
format: String,
default: '',
sensitive: true,
env: 'SESSION_COOKIE_PASSWORD'
} as SchemaObj<string>,
}),
redis: {
host: {
host: /** @type {SchemaObj<string>} */ ({
doc: 'Redis cache host',
format: String,
default: '',
env: 'REDIS_HOST'
} as SchemaObj<string>,
username: {
}),
username: /** @type {SchemaObj<string>} */ ({
doc: 'Redis cache username',
format: String,
default: '',
env: 'REDIS_USERNAME'
} as SchemaObj<string>,
password: {
}),
password: /** @type {SchemaObj<string>} */ ({
doc: 'Redis cache password',
format: '*',
default: '',
sensitive: true,
env: 'REDIS_PASSWORD'
} as SchemaObj<string>,
keyPrefix: {
}),
keyPrefix: /** @type {SchemaObj<string>} */ ({
doc: 'Redis cache key prefix name used to isolate the cached results across multiple clients',
format: String,
default: '',
env: 'REDIS_KEY_PREFIX'
} as SchemaObj<string>
})
},
tracing: {
header: {
header: /** @type {SchemaObj<string>} */ ({
doc: 'Tracing header name',
format: String,
default: 'x-cdp-request-id',
env: 'TRACING_HEADER'
} as SchemaObj<string>
})
},

/**
* Email outputs
* Email outputs will use notify to send an email to a single inbox.
*/
notifyTemplateId: {
notifyTemplateId: /** @type {SchemaObj<string>} */ ({
format: String,
default: '',
env: 'NOTIFY_TEMPLATE_ID'
} as SchemaObj<string>,
notifyAPIKey: {
}),
notifyAPIKey: /** @type {SchemaObj<string>} */ ({
format: String,
default: '',
env: 'NOTIFY_API_KEY'
} as SchemaObj<string>,
}),

/**
* API integrations
*/
designerUrl: {
designerUrl: /** @type {SchemaObj<string>} */ ({
format: String,
default: 'http://localhost:3000',
env: 'DESIGNER_URL'
} as SchemaObj<string>,
}),

submissionUrl: {
submissionUrl: /** @type {SchemaObj<string>} */ ({
format: String,
default: 'http://localhost:3002',
env: 'SUBMISSION_URL'
} as SchemaObj<string>,
}),

uploaderUrl: {
uploaderUrl: /** @type {SchemaObj<string>} */ ({
format: String,
default: 'http://localhost:7337',
env: 'UPLOADER_URL'
} as SchemaObj<string>,
}),

uploaderBucketName: {
format: String,
Expand All @@ -213,18 +212,18 @@
default: !isTest,
env: 'LOG_ENABLED'
},
level: {
level: /** @type {SchemaObj<LevelWithSilent>} */ ({
doc: 'Logging level',
format: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],
default: 'info',
env: 'LOG_LEVEL'
} as SchemaObj<LevelWithSilent>,
format: {
}),
format: /** @type {SchemaObj<'ecs' | 'pino-pretty'>} */ ({
doc: 'Format to output logs in.',
format: ['ecs', 'pino-pretty'],
default: isProduction ? 'ecs' : 'pino-pretty',
env: 'LOG_FORMAT'
} as SchemaObj<'ecs' | 'pino-pretty'>,
}),
redact: {
doc: 'Log paths to redact',
format: Array,
Expand All @@ -247,20 +246,25 @@
env: 'STAGING_PREFIX'
},

submissionEmailAddress: {
submissionEmailAddress: /** @type {SchemaObj<string>} */ ({
doc: 'Email address to send the form to (local devtool only)',
format: String,
default: '',
env: 'SUBMISSION_EMAIL_ADDRESS'
} as SchemaObj<string>,
}),

ordnanceSurveyApiKey: {
ordnanceSurveyApiKey: /** @type {SchemaObj<string | undefined>} */ ({
doc: 'The ordnance survey api key used by the postcode lookup and maps plugin',
format: String,
nullable: true,
default: undefined,

Check warning on line 260 in src/config/index.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use null instead.

See more on https://sonarcloud.io/project/issues?id=DEFRA_forms-engine-plugin&issues=AaIPdVrZjkK2xe4mbVWv&open=AaIPdVrZjkK2xe4mbVWv&pullRequest=507
env: 'ORDNANCE_SURVEY_API_KEY'
} as SchemaObj<string | undefined>
})
})

config.validate({ allowed: 'strict' })

/**
* @import { SchemaObj } from 'convict'
* @import { LevelWithSilent } from 'pino'
*/
2 changes: 1 addition & 1 deletion src/index.ts → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
server.logger.info(`Access your frontend on http://localhost:${port}`)
}

startServer().catch((error: unknown) => {
startServer().catch((/** @type {unknown} */ error) => {

Check warning on line 37 in src/index.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer top-level await over using a promise chain.

See more on https://sonarcloud.io/project/issues?id=DEFRA_forms-engine-plugin&issues=AaIPdVrXjkK2xe4mbVWt&open=AaIPdVrXjkK2xe4mbVWt&pullRequest=507
const err = getErrorMessage(error)
logger.info('Server failed to start :(')
logger.error(error, `[serverStartup] Server failed to start: ${err}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { getTraceId } from '@defra/hapi-tracing'
import { ecsFormat } from '@elastic/ecs-pino-format'
import { type Options } from 'hapi-pino'
import { type LoggerOptions, type TransportSingleOptions } from 'pino'

import { config } from '~/src/config/index.js'

const logConfig = config.get('log')
const serviceName = config.get('serviceName')
const serviceVersion = config.get('serviceVersion')

const formatters: {
ecs: Omit<LoggerOptions, 'mixin' | 'transport'>
'pino-pretty': { transport: TransportSingleOptions }
} = {
/**
* @type {{
* ecs: Omit<LoggerOptions, 'mixin' | 'transport'>
* 'pino-pretty': { transport: TransportSingleOptions }
* }}
*/
const formatters = {
ecs: {
...ecsFormat(),
base: {
Expand All @@ -26,7 +27,7 @@ const formatters: {
'pino-pretty': { transport: { target: 'pino-pretty' } }
}

export const loggerOptions = {
export const loggerOptions = /** @satisfies {Options} */ ({
enabled: logConfig.enabled,
ignorePaths: ['/health'],
redact: {
Expand All @@ -36,11 +37,17 @@ export const loggerOptions = {
level: logConfig.level,
...formatters[logConfig.format],
mixin() {
const mixinValues: { trace?: { id: string } } = {}
/** @type {{ trace?: { id: string } }} */
const mixinValues = {}
const traceId = getTraceId()
if (traceId) {
mixinValues.trace = { id: traceId }
}
return mixinValues
}
} satisfies Options
})

/**
* @import { Options } from 'hapi-pino'
* @import { LoggerOptions, TransportSingleOptions } from 'pino'
*/
15 changes: 15 additions & 0 deletions src/server/common/helpers/logging/request-logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import hapiPino from 'hapi-pino'

import { loggerOptions } from '~/src/server/common/helpers/logging/logger-options.js'

/** @type {{ plugin: Plugin<Options>, options: typeof loggerOptions }} */
export const requestLogger =
/** @satisfies {ServerRegisterPluginObject<Options>} */ ({
plugin: hapiPino,
options: loggerOptions
})

/**
* @import { Plugin, ServerRegisterPluginObject } from '@hapi/hapi'
* @import { Options } from 'hapi-pino'
*/
9 changes: 0 additions & 9 deletions src/server/common/helpers/logging/request-logger.ts

This file was deleted.

Loading
Loading