hof 21.0.20-axios-beta → 21.1.0-deindex-toggle-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/model/index.js CHANGED
@@ -5,9 +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
-
9
8
  const axiosSetting = require('./apis/axios-settings');
10
-
11
9
  const REFERENCE = /^\$ref:/;
12
10
 
13
11
  function timeDiff(from, to, d) {
@@ -32,7 +30,7 @@ module.exports = class Model extends EventEmitter {
32
30
  this._request = axios;
33
31
  }
34
32
 
35
- save(options, callback) {
33
+ async save(options, callback) {
36
34
  if (typeof options === 'function' && arguments.length === 1) {
37
35
  callback = options;
38
36
  options = {};
@@ -40,20 +38,18 @@ module.exports = class Model extends EventEmitter {
40
38
  options = {};
41
39
  }
42
40
 
43
- return this.prepare().then(data => {
44
- data = JSON.stringify(data);
45
- const reqConf = this.requestConfig(options);
46
- reqConf.method = options.method || 'POST';
47
-
48
- reqConf.headers = Object.assign({
49
- 'Content-Type': 'application/json',
50
- 'Content-Length': Buffer.byteLength(data)
51
- }, reqConf.headers || {});
52
- return this.request(reqConf, data, callback);
53
- });
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);
54
50
  }
55
51
 
56
- fetch(options, callback) {
52
+ async fetch(options, callback) {
57
53
  if (typeof options === 'function' && arguments.length === 1) {
58
54
  callback = options;
59
55
  options = {};
@@ -62,10 +58,10 @@ module.exports = class Model extends EventEmitter {
62
58
  }
63
59
  const reqConf = this.requestConfig(options);
64
60
  reqConf.method = options.method || 'GET';
65
- return this.request(reqConf, callback);
61
+ return await this.request(reqConf, callback);
66
62
  }
67
63
 
68
- delete(options, callback) {
64
+ async delete(options, callback) {
69
65
  if (typeof options === 'function' && arguments.length === 1) {
70
66
  callback = options;
71
67
  options = {};
@@ -74,7 +70,7 @@ module.exports = class Model extends EventEmitter {
74
70
  }
75
71
  const reqConf = this.requestConfig(options);
76
72
  reqConf.method = options.method || 'DELETE';
77
- return this.request(reqConf, callback);
73
+ return await this.request(reqConf, callback);
78
74
  }
79
75
 
80
76
  requestConfig(options) {
@@ -87,7 +83,7 @@ module.exports = class Model extends EventEmitter {
87
83
  });
88
84
  }
89
85
 
90
- request(originalSettings, body, callback) {
86
+ async request(originalSettings, body, callback) {
91
87
  if (typeof body === 'function' && arguments.length === 2) {
92
88
  callback = body;
93
89
  body = undefined;
@@ -99,92 +95,110 @@ module.exports = class Model extends EventEmitter {
99
95
  settings = _.omit(settings, urlKeys);
100
96
  this.emit('sync', originalSettings);
101
97
 
102
- const promise = Promise.resolve().then(() => this.auth()).then(authData => {
98
+ try {
99
+ const authData = await this.auth();
103
100
  let authVal = authData;
104
101
  if (typeof authVal === 'string') {
105
- const auth = authVal.split(':');
102
+ const [user, ...rest] = authVal.split(':');
106
103
  authVal = {
107
- user: auth.shift(),
108
- pass: auth.join(':'),
104
+ user,
105
+ pass: rest.join(':'),
109
106
  sendImmediately: true
110
107
  };
111
108
  }
112
- if(authVal) {
113
- 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
+ };
114
114
  }
115
- })
116
- .then(() => {
117
- const startTime = process.hrtime();
118
- let timeoutTimer;
119
-
120
- return new Promise((resolve, reject) => {
121
- const _callback = (err, data, statusCode) => {
122
- if (timeoutTimer) {
123
- clearTimeout(timeoutTimer);
124
- timeoutTimer = null;
125
- }
126
115
 
127
- const endTime = process.hrtime();
128
- const responseTime = timeDiff(startTime, endTime);
129
- if (err) {
130
- this.emit('fail', err, data, originalSettings, statusCode, responseTime);
131
- } else {
132
- this.emit('success', data, originalSettings, statusCode, responseTime);
133
- }
134
- if (err) {
135
- reject(err);
136
- } else {
137
- resolve(data);
138
- }
139
- };
140
- console.log('settings ::', settings);
141
- this._request(settings)
142
- .then(response => {
143
- return this.handleResponse(response, (error, data, status) => {
144
- if (error) {
145
- error.headers = response.headers;
146
- }
147
- _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);
148
149
  });
149
- }).catch(err => {
150
- if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
151
- err.message = 'Connection timed out';
152
- err.status = 504;
153
- }
154
- err.status = err.status || 503;
155
- return _callback(err, null, err.status);
156
- });
157
- });
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
+ });
158
159
  });
159
160
 
160
- if (typeof callback === 'function') {
161
- 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;
162
170
  }
163
- return promise;
164
171
  }
165
172
 
166
- handleResponse(response, callback) {
167
- let data = {};
173
+ async handleResponse(response) {
174
+ let data = null;
168
175
  try {
169
- 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
+ }
170
183
  } catch (err) {
184
+ err.message = 'Failed to parse response data';
171
185
  err.status = response.status;
172
186
  err.body = response.data;
173
- return callback(err, null, response.status);
187
+ throw err;
174
188
  }
175
- return this.parseResponse(response.status, data, callback);
189
+ return await this.parseResponse(response.status, data);
176
190
  }
177
191
 
178
- parseResponse(statusCode, data, callback) {
192
+ async parseResponse(statusCode, data) {
179
193
  if (statusCode < 400) {
180
194
  try {
181
- data = this.parse(data);
182
- callback(null, data, statusCode);
195
+ data = await this.parse(data);
196
+ return data;
183
197
  } catch (err) {
184
- callback(err, null, statusCode);
198
+ throw err;
185
199
  }
186
200
  } else {
187
- callback(this.parseError(statusCode, data), data, statusCode);
201
+ throw this.parseError(statusCode, data);
188
202
  }
189
203
  }
190
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.20-axios-beta",
4
+ "version": "21.1.0-deindex-toggle-beta",
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",
@@ -54,12 +53,12 @@
54
53
  "duplexify": "^3.5.0",
55
54
  "express": "^4.17.1",
56
55
  "express-healthcheck": "^0.1.0",
57
- "express-partial-templates": "^0.2.0",
56
+ "express-partial-templates": "^0.2.1",
58
57
  "express-session": "^1.13.0",
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",
@@ -81,8 +80,7 @@
81
80
  "nodemailer-ses-transport": "^1.5.1",
82
81
  "nodemailer-smtp-transport": "^2.7.4",
83
82
  "nodemailer-stub-transport": "^1.1.0",
84
- "notifications-node-client": "^6.0.0",
85
- "object-mapper": "^6.2.0",
83
+ "notifications-node-client": "^8.2.0",
86
84
  "redis": "^3.1.2",
87
85
  "reqres": "^3.0.1",
88
86
  "rimraf": "^3.0.2",
@@ -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
  },
@@ -5627,6 +5627,11 @@ input[type=number] {
5627
5627
  vertical-align: top;
5628
5628
  }
5629
5629
 
5630
+ .govuk-header__logotype-crown[width="32"] {
5631
+ top: -3px;
5632
+ margin-right: 2px;
5633
+ }
5634
+
5630
5635
  .govuk-header__logotype-crown-fallback-image {
5631
5636
  width: 36px;
5632
5637
  height: 32px;
@@ -5634,6 +5639,11 @@ input[type=number] {
5634
5639
  vertical-align: bottom;
5635
5640
  }
5636
5641
 
5642
+ .govuk-header__logotype-crown-fallback-image[width="32"] {
5643
+ width: 32px;
5644
+ height: 30px;
5645
+ }
5646
+
5637
5647
  .govuk-header__product-name {
5638
5648
  font-family: "GDS Transport", arial, sans-serif;
5639
5649
  -webkit-font-smoothing: antialiased;