diff --git a/package.json b/package.json index 0240d5b8f..cc3a83e97 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "@graphql-codegen/typescript-operations": "^3.0.4", "@types/bcryptjs": "^2.4.2", "@types/google-libphonenumber": "^7.4.23", + "@types/handlebars": "^4.1.0", "@types/hapi__inert": "^5.2.3", "@types/jsonwebtoken": "^8.5.8", "@types/react-intl": "^3.0.0", @@ -162,4 +163,4 @@ "minimist": "^1.2.2", "acorn": "^6.4.1" } -} \ No newline at end of file +} diff --git a/src/form/common/custom-validation-conditionals/custom-handlebars.ts b/src/form/common/custom-validation-conditionals/custom-handlebars.ts new file mode 100644 index 000000000..2233c23bb --- /dev/null +++ b/src/form/common/custom-validation-conditionals/custom-handlebars.ts @@ -0,0 +1,15 @@ +import * as Handlebars from 'handlebars' + +export const loud: Handlebars.HelperDelegate = function ( + this: any, + value: string +) { + return value.toUpperCase() +} + +export const quiet: Handlebars.HelperDelegate = function ( + this: any, + value: string +) { + return value.toLowerCase() +} diff --git a/src/form/common/custom-validation-conditionals/handlebars-handler.ts b/src/form/common/custom-validation-conditionals/handlebars-handler.ts new file mode 100644 index 000000000..47105937b --- /dev/null +++ b/src/form/common/custom-validation-conditionals/handlebars-handler.ts @@ -0,0 +1,14 @@ +import { buildTypeScriptToJavaScript } from '@countryconfig/utils' +import * as Hapi from '@hapi/hapi' +import { join } from 'path' + +export async function handlebarsHandler( + request: Hapi.Request, + h: Hapi.ResponseToolkit +) { + return h + .response( + await buildTypeScriptToJavaScript(join(__dirname, 'custom-handlebars.ts')) + ) + .type('text/javascript') +} diff --git a/src/index.ts b/src/index.ts index e68e37612..a37f40183 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,6 +50,7 @@ import { applicationConfigHandler } from './api/application/handler' import { validatorsHandler } from './form/common/custom-validation-conditionals/validators-handler' import { conditionalsHandler } from './form/common/custom-validation-conditionals/conditionals-handler' import { COUNTRY_WIDE_CRUDE_DEATH_RATE } from './api/application/application-config-default' +import { handlebarsHandler } from './form/common/custom-validation-conditionals/handlebars-handler' export interface ITokenPayload { sub: string @@ -302,6 +303,17 @@ export async function createServer() { } }) + server.route({ + method: 'GET', + path: '/handlebars.js', + handler: handlebarsHandler, + options: { + auth: false, + tags: ['api'], + description: 'Serves handlebars as JS' + } + }) + server.route({ method: 'GET', path: '/content/{application}', diff --git a/yarn.lock b/yarn.lock index 89f18b878..d4faf6ba1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3211,6 +3211,13 @@ dependencies: "@types/node" "*" +"@types/handlebars@^4.1.0": + version "4.1.0" + resolved "https://registry.yarnpkg.com/@types/handlebars/-/handlebars-4.1.0.tgz#3fcce9bf88f85fe73dc932240ab3fb682c624850" + integrity sha512-gq9YweFKNNB1uFK71eRqsd4niVkXrxHugqWFQkeLRJvGjnxsLr16bYtcsG4tOFwmYi0Bax+wCkbf1reUfdl4kA== + dependencies: + handlebars "*" + "@types/hapi-pino@^6.3.0": version "6.4.0" resolved "https://registry.yarnpkg.com/@types/hapi-pino/-/hapi-pino-6.4.0.tgz#3e1103918812d8bd8d4f189b68d08c086eafe74c" @@ -6020,6 +6027,18 @@ growly@^1.3.0: resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" integrity sha512-+xGQY0YyAWCnqy7Cd++hc2JqMYzlm0dG30Jd0beaA64sROr8C4nt8Yc9V5Ro3avlSUDTN0ulqP/VBKi1/lLygw== +handlebars@*: + version "4.7.8" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9" + integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ== + dependencies: + minimist "^1.2.5" + neo-async "^2.6.2" + source-map "^0.6.1" + wordwrap "^1.0.0" + optionalDependencies: + uglify-js "^3.1.4" + handlebars@^4.7.7: version "4.7.7" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1" @@ -7899,7 +7918,7 @@ ndjson@^1.4.0: split2 "^2.1.0" through2 "^2.0.3" -neo-async@^2.6.0: +neo-async@^2.6.0, neo-async@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==