hof 20.0.0-beta.15 → 20.0.0-beta.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,5 +5,6 @@ module.exports = {
5
5
  clearSession: require('./clear-session'),
6
6
  date: require('./date'),
7
7
  emailer: require('./emailer'),
8
- summary: require('./summary')
8
+ summary: require('./summary'),
9
+ notify: require('./notify')
9
10
  };
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ const Notify = require('./notify');
4
+ const Hogan = require('hogan.js');
5
+ const fs = require('fs');
6
+
7
+ module.exports = config => {
8
+ const notify = new Notify(config);
9
+ config.parse = config.parse || (data => data);
10
+
11
+ if (!config.recipient) {
12
+ throw new Error('Email recipient must be defined');
13
+ }
14
+ if (typeof config.template !== 'string') {
15
+ throw new Error('Email template must be defined');
16
+ }
17
+
18
+ return superclass => class NotifyBehaviour extends superclass {
19
+ successHandler(req, res, next) {
20
+ Promise.resolve()
21
+ .then(() => {
22
+ return new Promise((resolve, reject) => {
23
+ fs.readFile(config.template, (err, template) => err ? reject(err) : resolve(template.toString('utf8')));
24
+ });
25
+ })
26
+ .then(template => {
27
+ const data = config.parse(req.sessionModel.toJSON(), req.translate);
28
+ return Hogan.compile(template).render(data);
29
+ })
30
+ .then(body => {
31
+ const settings = { body };
32
+
33
+ if (typeof config.recipient === 'function') {
34
+ settings.recipient = config.recipient(req.sessionModel.toJSON());
35
+ } else {
36
+ settings.recipient = req.sessionModel.get(config.recipient) || config.recipient;
37
+ }
38
+ if (typeof settings.recipient !== 'string' || !settings.recipient.includes('@')) {
39
+ throw new Error('hof-behaviour-emailer: invalid recipient');
40
+ }
41
+
42
+ if (typeof config.subject === 'function') {
43
+ settings.subject = config.subject(req.sessionModel.toJSON(), req.translate);
44
+ } else {
45
+ settings.subject = config.subject;
46
+ }
47
+
48
+ return settings;
49
+ })
50
+ .then(settings => {
51
+ return notify.send(settings);
52
+ })
53
+ .then(() => {
54
+ super.successHandler(req, res, next);
55
+ }, next);
56
+ }
57
+ };
58
+ };
59
+
60
+ module.exports.Notify = Notify;
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+ const NotifyClient = require('notifications-node-client').NotifyClient;
3
+ const uuid = require('uuid');
4
+
5
+ module.exports = class Notify {
6
+ constructor(opts) {
7
+ const options = opts || {};
8
+ this.options = options;
9
+ this.notifyClient = new NotifyClient(options.notifyApiKey);
10
+ this.notifyTemplate = options.notifyTemplate;
11
+ }
12
+
13
+ send(email) {
14
+ const reference = uuid.v1();
15
+
16
+ return this.notifyClient.sendEmail(this.notifyTemplate, email.recipient, {
17
+ personalisation: {
18
+ 'email-subject': email.subject,
19
+ 'email-body': email.body
20
+ },
21
+ reference });
22
+ }
23
+ };
24
+
25
+ module.exports.NotifyClient = NotifyClient;
@@ -1,5 +1,5 @@
1
1
  <div id="{{id}}-group" class="{{#compound}} form-group-compound{{/compound}}{{#formGroupClassName}}{{formGroupClassName}}{{/formGroupClassName}}{{#error}} govuk-form-group--error{{/error}}">
2
- {{#isPageHeading}}<h1 class="govuk-label-wrapper">{{/isPageHeading}}<label for="{{id}}" class="{{labelClassName}}">
2
+ {{#isPageHeading}}<h1 class="govuk-label-wrapper">{{/isPageHeading}}<label for="{{id}}" class="{{labelClassName}}{{#isPageHeading}}govuk-label--l{{/isPageHeading}}">
3
3
  {{{label}}}
4
4
  </label>
5
5
  {{#isPageHeading}}</h1>{{/isPageHeading}}
@@ -2,7 +2,7 @@
2
2
  <div class="govuk-character-count" data-module="govuk-character-count" data-maxlength="{{maxlength}}">
3
3
  {{/maxlength}}
4
4
  <div id="{{id}}-group" class="{{#compound}}form-group-compound {{/compound}}{{#formGroupClassName}}{{formGroupClassName}}{{/formGroupClassName}}{{#error}} govuk-form-group--error{{/error}}">
5
- {{#isPageHeading}}<h1 class="govuk-label-wrapper">{{/isPageHeading}}<label for="{{id}}" class="{{labelClassName}}">
5
+ {{#isPageHeading}}<h1 class="govuk-label-wrapper">{{/isPageHeading}}<label for="{{id}}" class="{{labelClassName}}{{#isPageHeading}}govuk-label--l{{/isPageHeading}}">
6
6
  {{{label}}}
7
7
  {{#error}}
8
8
  <p id="{{id}}-error" class="govuk-error-message">
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hof",
3
3
  "description": "A bootstrap for HOF projects",
4
- "version": "20.0.0-beta.15",
4
+ "version": "20.0.0-beta.18",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",
@@ -79,6 +79,7 @@
79
79
  "nodemailer-ses-transport": "^1.5.0",
80
80
  "nodemailer-smtp-transport": "^2.7.4",
81
81
  "nodemailer-stub-transport": "^1.1.0",
82
+ "notifications-node-client": "^5.1.1",
82
83
  "redis": "^3.1.2",
83
84
  "reqres": "^3.0.1",
84
85
  "request": "^2.79.0",
@@ -0,0 +1,224 @@
1
+ {
2
+ "fields": {
3
+ "landing-page-radio": {
4
+ "legend": "Which form would you like to explore?",
5
+ "options": {
6
+ "basic-form": {
7
+ "label": "Basic form"
8
+ },
9
+ "complex-form": {
10
+ "label": "Complex form"
11
+ },
12
+ "build-your-own-form": {
13
+ "label": "Build your own form"
14
+ }
15
+ }
16
+ },
17
+ "name": {
18
+ "label": "Full name"
19
+ },
20
+ "dateOfBirth": {
21
+ "legend": "Date of birth",
22
+ "hint": "For example, 31 10 1990"
23
+ },
24
+ "building": {
25
+ "label": "Building and street"
26
+ },
27
+ "street": {
28
+ "label": "Address line 2"
29
+ },
30
+ "townOrCity": {
31
+ "label": "Town or city"
32
+ },
33
+ "postcode": {
34
+ "label": "Postcode"
35
+ },
36
+ "incomeTypes": {
37
+ "label": "Sources of income",
38
+ "legend": "Select the options where you receive income from",
39
+ "hint": "Select all options that apply to you.",
40
+ "options": {
41
+ "salary": {
42
+ "label": "Salary"
43
+ },
44
+ "universal_credit": {
45
+ "label": "Universal Credit"
46
+ },
47
+ "child_benefit": {
48
+ "label": "Child Benefit"
49
+ },
50
+ "housing_benefit": {
51
+ "label": "Housing Benefit"
52
+ },
53
+ "other": {
54
+ "label": "Other"
55
+ }
56
+ }
57
+ },
58
+ "countryOfHearing": {
59
+ "label": "Country of hearing",
60
+ "options": {
61
+ "englandAndWales": {
62
+ "label": "England and Wales"
63
+ },
64
+ "scotland": {
65
+ "label": "Scotland"
66
+ },
67
+ "northernIreland": {
68
+ "label": "Northern Ireland"
69
+ }
70
+ }
71
+ },
72
+ "email": {
73
+ "label": "Email address"
74
+ },
75
+ "phone": {
76
+ "label": "Phone number",
77
+ "hint": "International phone numbers require the international dialling code, for example +33235066182"
78
+ },
79
+ "int-phone-number": {
80
+ "legend": "International phone number"
81
+ },
82
+ "complaintDetails": {
83
+ "label": "Complaint details"
84
+ },
85
+ "countrySelect": {
86
+ "label": "Select a country",
87
+ "hint": "Start to type the country name and options will appear"
88
+ },
89
+ "appealStages": {
90
+ "label": "Appeal stage",
91
+ "options": {
92
+ "null": "Select..."
93
+ }
94
+ }
95
+ },
96
+ "journey": {
97
+ "header": "HOF Bootstrap Sandbox Form"
98
+ },
99
+ "pages": {
100
+ "landing-page": {
101
+ "header": "Landing page",
102
+ "intro": "Choose one of the options below and press continue."
103
+ },
104
+ "build-your-own-form": {
105
+ "title": "Build your own form",
106
+ "subheader": "Access the build your own form guidance link"
107
+ },
108
+ "name": {
109
+ "header": "What is your full name?"
110
+ },
111
+ "dob": {
112
+ "header": "What is your date of birth?"
113
+ },
114
+ "address": {
115
+ "header": "What is your address in the UK?",
116
+ "intro": "If you have no fixed address, enter an address where we can contact you."
117
+ },
118
+ "checkboxes": {
119
+ "header": "Where does your money come from each month?"
120
+ },
121
+ "radio": {
122
+ "header": "What country was the appeal lodged?"
123
+ },
124
+ "country-select": {
125
+ "header": "What country is your address located?"
126
+ },
127
+ "email": {
128
+ "header": "Enter your email address"
129
+ },
130
+ "phone-number": {
131
+ "header": "Enter your phone number"
132
+ },
133
+ "text-input-area": {
134
+ "header": "What are the details of your complaint?",
135
+ "intro": "Briefly summarise your complaint. Include anything that can help our investigation."
136
+ },
137
+ "select": {
138
+ "header": "What is the appeal stage?",
139
+ "intro": "Choose an appeal stage from the drop down menu"
140
+ },
141
+ "confirm": {
142
+ "header": "Check your answers before submitting your application.",
143
+ "sections": {
144
+ "applicantsDetails": {
145
+ "header": "Applicant's details"
146
+ },
147
+ "address": {
148
+ "header": "Address"
149
+ },
150
+ "income": {
151
+ "header": "Income"
152
+ },
153
+ "appealDetails": {
154
+ "header": "Appeal details"
155
+ },
156
+ "countrySelect": {
157
+ "header": "Country of residence"
158
+ },
159
+ "contactDetails": {
160
+ "header": "Contact details"
161
+ },
162
+ "complaintDetails": {
163
+ "header": "Complaint details"
164
+ }
165
+ }
166
+ },
167
+ "confirmation": {
168
+ "title": "Application sent",
169
+ "alert": "Application sent",
170
+ "subheader": "What happens next",
171
+ "content": "We’ll contact you with the decision of your application or if we need more information from you."
172
+ }
173
+ },
174
+ "validation": {
175
+ "landing-page-radio": {
176
+ "required": "Select an option below and press continue"
177
+ },
178
+ "name": {
179
+ "default": "Enter your full name"
180
+ },
181
+ "dateOfBirth": {
182
+ "default": "Enter your date of birth in the correct format; for example, 31 10 1990",
183
+ "after": "Enter a date after 1 1 1900",
184
+ "before": "Enter a date that is in the past"
185
+ },
186
+ "building": {
187
+ "default": "Enter details of your building and street"
188
+ },
189
+ "townOrCity": {
190
+ "default": "Enter a town or city",
191
+ "regex": "Enter a town or city without including digits"
192
+ },
193
+ "postcode": {
194
+ "default": "Enter your postcode"
195
+ },
196
+ "incomeTypes": {
197
+ "default": "Select all options that apply to you."
198
+ },
199
+ "countryOfHearing": {
200
+ "default": "Select where the appeal hearing is to be held"
201
+ },
202
+ "countrySelect": {
203
+ "default": "Enter a valid country of residence",
204
+ "required": "Enter your country of residence"
205
+ },
206
+ "email": {
207
+ "default": "Enter your email address in the correct format"
208
+ },
209
+ "phone": {
210
+ "default": "Enter your phone number"
211
+ },
212
+ "int-phone-number": {
213
+ "required": "Enter an international phone number",
214
+ "internationalPhoneNumber": "Enter a valid international phone number"
215
+ },
216
+ "complaintDetails": {
217
+ "default": "Enter details about why you are making a complaint",
218
+ "maxlength": "Keep to the 5000 character limit"
219
+ },
220
+ "appealStages": {
221
+ "required": "Select an appeal stage from the list"
222
+ }
223
+ }
224
+ }