hof 21.0.1-axios-beta → 21.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/codeReviewChecklist.md +22 -0
  3. package/config/hof-defaults.js +8 -0
  4. package/frontend/govuk-template/build/govuk_template.html +20 -22
  5. package/frontend/template-mixins/mixins/template-mixins.js +1 -0
  6. package/frontend/template-mixins/partials/forms/checkbox.html +5 -0
  7. package/frontend/template-mixins/partials/forms/input-text-group.html +1 -1
  8. package/frontend/template-mixins/partials/forms/select.html +6 -6
  9. package/frontend/template-mixins/partials/forms/textarea-group.html +4 -4
  10. package/frontend/template-partials/views/partials/gatag.html +0 -1
  11. package/frontend/template-partials/views/partials/head.html +23 -0
  12. package/lib/ga-tag.js +33 -7
  13. package/middleware/cookies.js +2 -0
  14. package/model/apis/axios-settings.js +21 -0
  15. package/model/apis/html-to-pdf-converter.js +1 -0
  16. package/model/index.js +96 -80
  17. package/package.json +7 -8
  18. package/pull_request.md +16 -0
  19. package/sandbox/package.json +1 -1
  20. package/sandbox/yarn.lock +14 -9
  21. package/.nyc_output/4fc007c9-d6c8-4614-89ce-04c7d6ce9fe5.json +0 -1
  22. package/.nyc_output/processinfo/4fc007c9-d6c8-4614-89ce-04c7d6ce9fe5.json +0 -1
  23. package/.nyc_output/processinfo/index.json +0 -1
  24. package/sandbox/apps/sandbox/translations/en/default.json +0 -224
  25. package/sandbox/public/css/app.css +0 -2793
  26. package/sandbox/public/images/icons/icon-caret-left.png +0 -0
  27. package/sandbox/public/images/icons/icon-complete.png +0 -0
  28. package/sandbox/public/images/icons/icon-cross-remove-sign.png +0 -0
  29. package/sandbox/public/js/bundle.js +0 -32888
package/model/index.js CHANGED
@@ -5,7 +5,7 @@ const _ = require('lodash');
5
5
  const axios = require('axios').default;
6
6
  const url = require('url');
7
7
  const EventEmitter = require('events').EventEmitter;
8
-
8
+ const axiosSetting = require('./apis/axios-settings');
9
9
  const REFERENCE = /^\$ref:/;
10
10
 
11
11
  function timeDiff(from, to, d) {
@@ -30,7 +30,7 @@ module.exports = class Model extends EventEmitter {
30
30
  this._request = axios;
31
31
  }
32
32
 
33
- save(options, callback) {
33
+ async save(options, callback) {
34
34
  if (typeof options === 'function' && arguments.length === 1) {
35
35
  callback = options;
36
36
  options = {};
@@ -38,20 +38,18 @@ module.exports = class Model extends EventEmitter {
38
38
  options = {};
39
39
  }
40
40
 
41
- return this.prepare().then(data => {
42
- data = JSON.stringify(data);
43
- const reqConf = this.requestConfig(options);
44
- reqConf.method = options.method || 'POST';
45
-
46
- reqConf.headers = Object.assign({
47
- 'Content-Type': 'application/json',
48
- 'Content-Length': Buffer.byteLength(data)
49
- }, reqConf.headers || {});
50
- return this.request(reqConf, data, callback);
51
- });
41
+ let data = await this.prepare();
42
+ data = JSON.stringify(data);
43
+ const reqConf = this.requestConfig(options);
44
+ reqConf.method = options.method || 'POST';
45
+ reqConf.headers = Object.assign({
46
+ 'Content-Type': 'application/json',
47
+ 'Content-Length': Buffer.byteLength(data)
48
+ }, reqConf.headers || {});
49
+ return await this.request(reqConf, data, callback);
52
50
  }
53
51
 
54
- fetch(options, callback) {
52
+ async fetch(options, callback) {
55
53
  if (typeof options === 'function' && arguments.length === 1) {
56
54
  callback = options;
57
55
  options = {};
@@ -60,10 +58,10 @@ module.exports = class Model extends EventEmitter {
60
58
  }
61
59
  const reqConf = this.requestConfig(options);
62
60
  reqConf.method = options.method || 'GET';
63
- return this.request(reqConf, callback);
61
+ return await this.request(reqConf, callback);
64
62
  }
65
63
 
66
- delete(options, callback) {
64
+ async delete(options, callback) {
67
65
  if (typeof options === 'function' && arguments.length === 1) {
68
66
  callback = options;
69
67
  options = {};
@@ -72,7 +70,7 @@ module.exports = class Model extends EventEmitter {
72
70
  }
73
71
  const reqConf = this.requestConfig(options);
74
72
  reqConf.method = options.method || 'DELETE';
75
- return this.request(reqConf, callback);
73
+ return await this.request(reqConf, callback);
76
74
  }
77
75
 
78
76
  requestConfig(options) {
@@ -85,104 +83,122 @@ module.exports = class Model extends EventEmitter {
85
83
  });
86
84
  }
87
85
 
88
- request(originalSettings, body, callback) {
86
+ async request(originalSettings, body, callback) {
89
87
  if (typeof body === 'function' && arguments.length === 2) {
90
88
  callback = body;
91
89
  body = undefined;
92
90
  }
91
+
93
92
  let settings = Object.assign({}, originalSettings);
94
93
  settings.timeout = settings.timeout || this.options.timeout;
95
- settings.url = settings.uri || settings.url || url.format(settings);
96
- settings.data = settings.body || body || settings.data;
94
+ settings = axiosSetting(settings, body);
97
95
  settings = _.omit(settings, urlKeys);
98
96
  this.emit('sync', originalSettings);
99
97
 
100
- const promise = Promise.resolve().then(() => this.auth()).then(authData => {
98
+ try {
99
+ const authData = await this.auth();
101
100
  let authVal = authData;
102
101
  if (typeof authVal === 'string') {
103
- const auth = authVal.split(':');
102
+ const [user, ...rest] = authVal.split(':');
104
103
  authVal = {
105
- user: auth.shift(),
106
- pass: auth.join(':'),
104
+ user,
105
+ pass: rest.join(':'),
107
106
  sendImmediately: true
108
107
  };
109
108
  }
110
- if(authVal) {
111
- settings.headers = Object.assign({}, settings.headers, {Authorization: `Bearer ${authVal.bearer}`});
109
+ if (authVal) {
110
+ settings.headers = {
111
+ ...settings.headers,
112
+ Authorization: `Bearer ${authVal.bearer}`
113
+ };
112
114
  }
113
- })
114
- .then(() => {
115
- const startTime = process.hrtime();
116
- let timeoutTimer;
117
-
118
- return new Promise((resolve, reject) => {
119
- const _callback = (err, data, statusCode) => {
120
- if (timeoutTimer) {
121
- clearTimeout(timeoutTimer);
122
- timeoutTimer = null;
123
- }
124
115
 
125
- const endTime = process.hrtime();
126
- const responseTime = timeDiff(startTime, endTime);
127
- if (err) {
128
- this.emit('fail', err, data, originalSettings, statusCode, responseTime);
129
- } else {
130
- this.emit('success', data, originalSettings, statusCode, responseTime);
131
- }
132
- if (err) {
133
- reject(err);
134
- } else {
135
- resolve(data);
136
- }
137
- };
138
-
139
- this._request(settings)
140
- .then(response => {
141
- return this.handleResponse(response, (error, data, status) => {
142
- if (error) {
143
- error.headers = response.headers;
144
- }
145
- _callback(error, data, status);
116
+ const startTime = process.hrtime();
117
+ let timeoutTimer;
118
+
119
+ if (timeoutTimer) {
120
+ clearTimeout(timeoutTimer);
121
+ timeoutTimer = null;
122
+ }
123
+
124
+ const data = await new Promise((resolve, reject) => {
125
+ const _callback = (err, responseData, statusCode) => {
126
+ if (timeoutTimer) {
127
+ clearTimeout(timeoutTimer);
128
+ timeoutTimer = null;
129
+ }
130
+
131
+ const endTime = process.hrtime();
132
+ const responseTime = timeDiff(startTime, endTime);
133
+ if (err) {
134
+ this.emit('fail', err, responseData, originalSettings, statusCode, responseTime);
135
+ reject(err);
136
+ } else {
137
+ this.emit('success', responseData, originalSettings, statusCode, responseTime);
138
+ resolve(responseData);
139
+ }
140
+ };
141
+
142
+ this._request(settings)
143
+ .then(response => {
144
+ return this.handleResponse(response)
145
+ .then(responseData => _callback(null, responseData, response.status))
146
+ .catch(error => {
147
+ error.headers = response.headers;
148
+ _callback(error, null, response.status);
146
149
  });
147
- }).catch(err => {
148
- if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
149
- err.message = 'Connection timed out';
150
- err.status = 504;
151
- }
152
- err.status = err.status || 503;
153
- return _callback(err, null, err.status);
154
- });
155
- });
150
+ })
151
+ .catch(err => {
152
+ if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
153
+ err.message = 'Connection timed out';
154
+ err.status = 504;
155
+ }
156
+ err.status = err.status || 503;
157
+ return _callback(err, null, err.status);
158
+ });
156
159
  });
157
160
 
158
- if (typeof callback === 'function') {
159
- return promise.then(data => callback(null, data), callback);
161
+ if (typeof callback === 'function') {
162
+ callback(null, data);
163
+ }
164
+ return data;
165
+ } catch (error) {
166
+ if (typeof callback === 'function') {
167
+ callback(error);
168
+ }
169
+ return error;
160
170
  }
161
- return promise;
162
171
  }
163
172
 
164
- handleResponse(response, callback) {
165
- let data = {};
173
+ async handleResponse(response) {
174
+ let data = null;
166
175
  try {
167
- data = typeof response.data === 'object' ? response.data : JSON.parse(response.data || '{}');
176
+ if (typeof response.data === 'object') {
177
+ data = response.data;
178
+ } else if (typeof response.data === 'string' && response.data.trim() !== '') {
179
+ data = JSON.parse(response.data);
180
+ } else {
181
+ data = {};
182
+ }
168
183
  } catch (err) {
184
+ err.message = 'Failed to parse response data';
169
185
  err.status = response.status;
170
186
  err.body = response.data;
171
- return callback(err, null, response.status);
187
+ throw err;
172
188
  }
173
- return this.parseResponse(response.status, data, callback);
189
+ return await this.parseResponse(response.status, data);
174
190
  }
175
191
 
176
- parseResponse(statusCode, data, callback) {
192
+ async parseResponse(statusCode, data) {
177
193
  if (statusCode < 400) {
178
194
  try {
179
- data = this.parse(data);
180
- callback(null, data, statusCode);
195
+ data = await this.parse(data);
196
+ return data;
181
197
  } catch (err) {
182
- callback(err, null, statusCode);
198
+ throw err;
183
199
  }
184
200
  } else {
185
- callback(this.parseError(statusCode, data), data, statusCode);
201
+ throw this.parseError(statusCode, data);
186
202
  }
187
203
  }
188
204
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hof",
3
3
  "description": "A bootstrap for HOF projects",
4
- "version": "21.0.1-axios-beta",
4
+ "version": "21.0.1",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "author": "HomeOffice",
@@ -32,8 +32,7 @@
32
32
  "test:acceptance_browser": "ACCEPTANCE_WITH_BROWSER=true TAGS=\"${TAGS:=@feature}\" yarn run test:cucumber",
33
33
  "test:cucumber": "cucumber-js -f @cucumber/pretty-formatter \"sandbox/test/_features/**/*.feature\" --require sandbox/test/_features/test.setup.js --require \"sandbox/test/_features/step_definitions/**/*.js\" --tags $TAGS",
34
34
  "ci": "travis-conditions",
35
- "postversion": "git push && git push --tags",
36
- "test-single":"mocha"
35
+ "postversion": "git push && git push --tags"
37
36
  },
38
37
  "dependencies": {
39
38
  "aliasify": "^2.1.0",
@@ -59,7 +58,7 @@
59
58
  "findup": "^0.1.5",
60
59
  "glob": "^7.2.0",
61
60
  "govuk-elements-sass": "^3.1.3",
62
- "govuk-frontend": "3.14",
61
+ "govuk-frontend": "3.15",
63
62
  "govuk_template_mustache": "^0.26.0",
64
63
  "helmet": "^3.22.0",
65
64
  "hogan-express-strict": "^0.5.4",
@@ -68,7 +67,7 @@
68
67
  "i18n-future": "^2.0.0",
69
68
  "i18n-lookup": "^0.1.0",
70
69
  "is-pdf": "^1.0.0",
71
- "libphonenumber-js": "^1.9.37",
70
+ "libphonenumber-js": "^1.9.44",
72
71
  "lodash": "^4.17.21",
73
72
  "markdown-it": "^12.3.2",
74
73
  "minimatch": "^3.0.7",
@@ -97,6 +96,7 @@
97
96
  "@cucumber/cucumber": "^7.3.0",
98
97
  "@cucumber/pretty-formatter": "^1.0.0-alpha.1",
99
98
  "@types/jest": "^26.0.14",
99
+ "@xmldom/xmldom": "~0.8.4",
100
100
  "chai": "^3.5.0",
101
101
  "chai-as-promised": "^7.1.1",
102
102
  "chai-subset": "^1.6.0",
@@ -123,14 +123,13 @@
123
123
  "playwright": "^1.16.3",
124
124
  "postcode": "0.2.2",
125
125
  "proxyquire": "^1.7.11",
126
- "release-it": "^14.10.0",
126
+ "release-it": "^16.2.1",
127
127
  "sinon": "^11.1.1",
128
128
  "sinon-chai": "^3.7.0",
129
129
  "supertest": "^3.0.0",
130
130
  "travis-conditions": "0.0.0",
131
131
  "watchify": "^4.0.0",
132
- "webdriverio": "^4.14.4",
133
- "xmldom": "^0.6.0"
132
+ "webdriverio": "^4.14.4"
134
133
  },
135
134
  "mocha": {
136
135
  "reporter": "spec",
@@ -0,0 +1,16 @@
1
+ ## What?
2
+ ## Why?
3
+ ## How?
4
+ ## Testing?
5
+ ## Screenshots (optional)
6
+ ## Anything Else? (optional)
7
+ ## Check list
8
+
9
+ - [ ] I have reviewed my own pull request for linting issues (e.g. adding new lines)
10
+ - [ ] I have written tests (if relevant)
11
+ - [ ] I have created a JIRA number for my branch
12
+ - [ ] I have created a JIRA number for my commit
13
+ - [ ] I have followed the chris beams method for my commit https://cbea.ms/git-commit/
14
+ here is an [example commit](https://github.com/UKHomeOfficeForms/hof/commit/810959f391187c7c4af6db262bcd143b50093a6e)
15
+ - [ ] Ensure drone builds are green especially tests
16
+ - [ ] I will squash the commits before merging
@@ -16,7 +16,7 @@
16
16
  "author": "",
17
17
  "dependencies": {
18
18
  "govuk-frontend": "3.14",
19
- "jquery": "^3.6.0",
19
+ "jquery": "^3.7.1",
20
20
  "sass": "^1.53.0",
21
21
  "typeahead-aria": "^1.0.4"
22
22
  },
package/sandbox/yarn.lock CHANGED
@@ -34,11 +34,11 @@ brace-expansion@^1.1.7:
34
34
  concat-map "0.0.1"
35
35
 
36
36
  braces@~3.0.2:
37
- version "3.0.2"
38
- resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
39
- integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
37
+ version "3.0.3"
38
+ resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
39
+ integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
40
40
  dependencies:
41
- fill-range "^7.0.1"
41
+ fill-range "^7.1.1"
42
42
 
43
43
  "chokidar@>=3.0.0 <4.0.0", chokidar@^3.5.2:
44
44
  version "3.5.3"
@@ -67,10 +67,10 @@ debug@^3.2.7:
67
67
  dependencies:
68
68
  ms "^2.1.1"
69
69
 
70
- fill-range@^7.0.1:
71
- version "7.0.1"
72
- resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
73
- integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
70
+ fill-range@^7.1.1:
71
+ version "7.1.1"
72
+ resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
73
+ integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
74
74
  dependencies:
75
75
  to-regex-range "^5.0.1"
76
76
 
@@ -130,11 +130,16 @@ is-number@^7.0.0:
130
130
  resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b"
131
131
  integrity sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==
132
132
 
133
- jquery@>=1.11, jquery@^3.6.0:
133
+ jquery@>=1.11:
134
134
  version "3.6.0"
135
135
  resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470"
136
136
  integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==
137
137
 
138
+ jquery@^3.7.1:
139
+ version "3.7.1"
140
+ resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.7.1.tgz#083ef98927c9a6a74d05a6af02806566d16274de"
141
+ integrity sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==
142
+
138
143
  minimatch@^3.0.4:
139
144
  version "3.1.2"
140
145
  resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"