hof 20.4.1 → 21.0.0-axios-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +0 -13
- package/config/hof-defaults.js +0 -8
- package/frontend/govuk-template/build/govuk_template.html +4 -3
- package/frontend/template-partials/views/partials/head.html +10 -5
- package/lib/ga-tag.js +7 -33
- package/middleware/cookies.js +0 -2
- package/model/apis/axios-settings.js +9 -0
- package/model/apis/html-to-pdf-converter.js +9 -8
- package/model/index.js +29 -28
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
## 2024-02-29, Version 20.4.0 (Stable), @sulthan-ahmed
|
2
|
-
* Update version of govuk-frontend to 3.15
|
3
|
-
- this adds the new crown for the King
|
4
|
-
- this supports a lot of changes from the govuk design system
|
5
|
-
* Adds support for Google tag manager
|
6
|
-
* Fixes accessibility issues
|
7
|
-
* Sandbox area for testing hof changes
|
8
|
-
* Updates patch and minor versions including
|
9
|
-
- libphonenumber to 1.9.44
|
10
|
-
- nodemailer to 6.9.9
|
11
|
-
- ip to 1.1.9
|
12
|
-
- es5-ext to 0.10.63
|
13
|
-
|
14
1
|
## 2020-06-02, Version 16.0.0 (Stable), @andymoody
|
15
2
|
* Update version of helmet to 3.22.0
|
16
3
|
* Update version of i18n-future to 2.0.0
|
package/config/hof-defaults.js
CHANGED
@@ -22,14 +22,6 @@ const defaults = {
|
|
22
22
|
env: process.env.NODE_ENV || 'development',
|
23
23
|
gaTagId: process.env.GA_TAG || 'Test-GA-Tag',
|
24
24
|
ga4TagId: process.env.GA_4_TAG,
|
25
|
-
// added to allow support for multiple HOF forms using GTM to customize how they track page views
|
26
|
-
gtm: {
|
27
|
-
tagId: process.env.GTM_TAG || false,
|
28
|
-
config: {},
|
29
|
-
composePageName: function (page, convertPage) {
|
30
|
-
return convertPage(page);
|
31
|
-
}
|
32
|
-
},
|
33
25
|
gaCrossDomainTrackingTagId: process.env.GDS_CROSS_DOMAIN_GA_TAG,
|
34
26
|
loglevel: process.env.LOG_LEVEL || 'info',
|
35
27
|
ignoreMiddlewareLogs: ['/healthz'],
|
@@ -41,12 +41,13 @@
|
|
41
41
|
<a href="{{{ homepageUrl }}}" title="{{ logoLinkTitle }}" id="logo" class="govuk-header__link govuk-header__link--homepage" target="_blank" data-module="track-click" data-track-category="homeLinkClicked" data-track-action="homeHeader">
|
42
42
|
<span class="govuk-header__logotype">
|
43
43
|
<!--[if gt IE 8]><!-->
|
44
|
-
<svg aria-hidden="true" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg
|
45
|
-
<path fill="currentColor" fill-rule="evenodd"
|
44
|
+
<svg aria-hidden="true" focusable="false" class="govuk-header__logotype-crown" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 132 97" height="30" width="36">
|
45
|
+
<path fill="currentColor" fill-rule="evenodd" d="M25 30.2c3.5 1.5 7.7-.2 9.1-3.7 1.5-3.6-.2-7.8-3.9-9.2-3.6-1.4-7.6.3-9.1 3.9-1.4 3.5.3 7.5 3.9 9zM9 39.5c3.6 1.5 7.8-.2 9.2-3.7 1.5-3.6-.2-7.8-3.9-9.1-3.6-1.5-7.6.2-9.1 3.8-1.4 3.5.3 7.5 3.8 9zM4.4 57.2c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.5-1.5-7.6.3-9.1 3.8-1.4 3.5.3 7.6 3.9 9.1zm38.3-21.4c3.5 1.5 7.7-.2 9.1-3.8 1.5-3.6-.2-7.7-3.9-9.1-3.6-1.5-7.6.3-9.1 3.8-1.3 3.6.4 7.7 3.9 9.1zm64.4-5.6c-3.6 1.5-7.8-.2-9.1-3.7-1.5-3.6.2-7.8 3.8-9.2 3.6-1.4 7.7.3 9.2 3.9 1.3 3.5-.4 7.5-3.9 9zm15.9 9.3c-3.6 1.5-7.7-.2-9.1-3.7-1.5-3.6.2-7.8 3.7-9.1 3.6-1.5 7.7.2 9.2 3.8 1.5 3.5-.3 7.5-3.8 9zm4.7 17.7c-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6-11.6-9.4-6.2 3.7-8.5 3.6-14.7-4.6-20.8-5.8 7.6-5 13.9 2.2 21.1-4.7-2.6-11.9.1-7.7 8.8 2.3-5.5 7.1-4.2 8.1.5.7 3.3-1.3 7.1-5.7 7.9-3.5.7-9-1.8-13.5-11.2 2.5.1 4.7 1.3 7.5 3.3l-4.7-15.4c-1.2 4.4-2.7 7.2-4.3 8.7-1.1-3-.9-5.3 0-10.2l-9.5 3.4c5 6.9 9.9 16.7 14 33.5 14.8-2.1 30.8-3.2 47.7-3.2z"></path>
|
46
46
|
</svg>
|
47
47
|
<!--<![endif]-->
|
48
|
+
<!--<![endif]-->
|
48
49
|
<!--[if IE 8]>
|
49
|
-
<img src="{{ assetPath }}images/govuk-logotype-
|
50
|
+
<img src="{{ assetPath }}images/govuk-logotype-crown.png" class="govuk-header__logotype-crown-fallback-image" width="36" height="32">
|
50
51
|
<![endif]-->
|
51
52
|
</span>
|
52
53
|
<span class="govuk-header__logotype-text">
|
@@ -1,13 +1,18 @@
|
|
1
1
|
{{#gtmTagId}}
|
2
2
|
{{#cookiesAccepted}}
|
3
|
-
|
3
|
+
{{#isETA}}
|
4
|
+
<!-- Google Tag Manager Data Layer for ETA -->
|
4
5
|
<script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
|
5
6
|
var dataLayer = window.dataLayer || [];
|
6
|
-
dataLayer.push(
|
7
|
-
|
8
|
-
|
7
|
+
dataLayer.push({
|
8
|
+
'event': 'pageLoad',
|
9
|
+
'pageName': 'ETA | Customer Contact Webform | {{gtm-page}}',
|
10
|
+
'applicationType': 'ETA | Customer Contact',
|
11
|
+
'environmentType': '{{environmentType}}'
|
12
|
+
});
|
9
13
|
</script>
|
10
|
-
<!-- End Google Tag Manager Data Layer
|
14
|
+
<!-- End Google Tag Manager Data Layer for ETA -->
|
15
|
+
{{/isETA}}
|
11
16
|
|
12
17
|
<!-- Google Tag Manager -->
|
13
18
|
<script {{#nonce}}nonce="{{nonce}}"{{/nonce}}>
|
package/lib/ga-tag.js
CHANGED
@@ -2,16 +2,6 @@
|
|
2
2
|
|
3
3
|
const _ = require('lodash');
|
4
4
|
|
5
|
-
const convertToGTMPage = text => {
|
6
|
-
// Remove leading and trailing slashes
|
7
|
-
let str = text.replace(/^\/|\/$/g, '');
|
8
|
-
// Replace hyphens with spaces and capitalize each word
|
9
|
-
str = str.replace(/-+/g, ' ').replace(/(^|\s)\S/g, function (match) {
|
10
|
-
return match.toUpperCase();
|
11
|
-
});
|
12
|
-
return str;
|
13
|
-
};
|
14
|
-
|
15
5
|
const pageView = (path, pageMap) => pageMap.get(path) || path;
|
16
6
|
|
17
7
|
const createUris = routes => {
|
@@ -52,35 +42,19 @@ const setupPageMap = routes => {
|
|
52
42
|
module.exports = (app, config) => {
|
53
43
|
const gaTagId = config.gaTagId;
|
54
44
|
const ga4TagId = config.ga4TagId;
|
55
|
-
const gtm = config.gtm;
|
56
45
|
const gaCrossDomainTrackingTagId = config.gaCrossDomainTrackingTagId;
|
57
46
|
const routes = config.routes;
|
58
47
|
|
59
|
-
if (gaTagId || ga4TagId
|
48
|
+
if (gaTagId || ga4TagId) {
|
60
49
|
const pageMap = setupPageMap(routes);
|
61
50
|
|
62
51
|
app.use((req, res, next) => {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
ga4TagId: ga4TagId,
|
70
|
-
gaCrossDomainTrackingTagId: gaCrossDomainTrackingTagId,
|
71
|
-
'ga-id': gaTagId,
|
72
|
-
'ga-page': page
|
73
|
-
};
|
74
|
-
|
75
|
-
// Adding extra properties if a GTM TAG is available
|
76
|
-
if (gtm.tagId) {
|
77
|
-
gtm.config.pageName = gtm.composePageName(page, convertToGTMPage);
|
78
|
-
Object.assign(properties, {
|
79
|
-
gtmConfig: JSON.stringify(gtm.config),
|
80
|
-
gtmTagId: gtm.tagId
|
81
|
-
});
|
82
|
-
}
|
83
|
-
res.locals = Object.assign(res.locals, properties);
|
52
|
+
res.locals.gaAllowDebug = config.env === 'development';
|
53
|
+
res.locals.gaTagId = gaTagId;
|
54
|
+
res.locals.ga4TagId = ga4TagId;
|
55
|
+
res.locals.gaCrossDomainTrackingTagId = gaCrossDomainTrackingTagId;
|
56
|
+
res.locals['ga-id'] = gaTagId;
|
57
|
+
res.locals['ga-page'] = pageView(req.path, pageMap);
|
84
58
|
next();
|
85
59
|
});
|
86
60
|
}
|
package/middleware/cookies.js
CHANGED
@@ -22,8 +22,6 @@ module.exports = options => {
|
|
22
22
|
const reqIsCookieCheckRedirect = req.query[paramName] !== undefined;
|
23
23
|
|
24
24
|
if (reqIncludesCookies || isHealthcheckUrl(req.path, healthcheckUrls)) {
|
25
|
-
const prefs = 'cookie_preferences' in req.cookies ? JSON.parse(req.cookies.cookie_preferences) : {};
|
26
|
-
res.locals.cookiesAccepted = Boolean(prefs.usage);
|
27
25
|
next();
|
28
26
|
} else if (req.cookies === undefined || (!Object.keys(req.cookies).length && reqIsCookieCheckRedirect)) {
|
29
27
|
const err = new Error('Cookies required');
|
@@ -17,17 +17,18 @@ module.exports = class PDFModel extends Model {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
handleResponse(response, callback) {
|
20
|
-
if (isPdf(Buffer.from(response.
|
21
|
-
return this.parseResponse(response.
|
20
|
+
if (isPdf(Buffer.from(response.data))) {
|
21
|
+
return this.parseResponse(response.status, response.data, callback);
|
22
22
|
}
|
23
23
|
const err = new Error();
|
24
|
-
|
25
|
-
|
26
|
-
err.
|
24
|
+
|
25
|
+
if (parseInt(response.status, 10) === 400) {
|
26
|
+
err.title = response.status;
|
27
|
+
err.message = response.statusText;
|
27
28
|
} else {
|
28
|
-
err.body = response.
|
29
|
+
err.body = response.data;
|
29
30
|
}
|
30
|
-
err.status = response.
|
31
|
-
return callback(err, null, response.
|
31
|
+
err.status = response.status;
|
32
|
+
return callback(err, null, response.status);
|
32
33
|
}
|
33
34
|
};
|
package/model/index.js
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
const _ = require('lodash');
|
5
|
-
const
|
5
|
+
const axios = require('axios').default;
|
6
6
|
const url = require('url');
|
7
7
|
const EventEmitter = require('events').EventEmitter;
|
8
8
|
|
9
|
+
const axiosSetting = require('./apis/axios-settings');
|
10
|
+
|
9
11
|
const REFERENCE = /^\$ref:/;
|
10
12
|
|
11
13
|
function timeDiff(from, to, d) {
|
@@ -27,7 +29,7 @@ module.exports = class Model extends EventEmitter {
|
|
27
29
|
this.set(attributes, {
|
28
30
|
silent: true
|
29
31
|
});
|
30
|
-
this._request =
|
32
|
+
this._request = axios;
|
31
33
|
}
|
32
34
|
|
33
35
|
save(options, callback) {
|
@@ -47,7 +49,6 @@ module.exports = class Model extends EventEmitter {
|
|
47
49
|
'Content-Type': 'application/json',
|
48
50
|
'Content-Length': Buffer.byteLength(data)
|
49
51
|
}, reqConf.headers || {});
|
50
|
-
|
51
52
|
return this.request(reqConf, data, callback);
|
52
53
|
});
|
53
54
|
}
|
@@ -94,22 +95,23 @@ module.exports = class Model extends EventEmitter {
|
|
94
95
|
|
95
96
|
let settings = Object.assign({}, originalSettings);
|
96
97
|
settings.timeout = settings.timeout || this.options.timeout;
|
97
|
-
settings
|
98
|
-
settings
|
99
|
-
|
100
|
-
settings = _.omit(settings, urlKeys, 'data', 'url');
|
98
|
+
settings = axiosSetting(settings, body)
|
99
|
+
settings = _.omit(settings, urlKeys);
|
101
100
|
this.emit('sync', originalSettings);
|
102
101
|
|
103
102
|
const promise = Promise.resolve().then(() => this.auth()).then(authData => {
|
104
|
-
|
105
|
-
if (typeof
|
106
|
-
const auth =
|
107
|
-
|
103
|
+
let authVal = authData;
|
104
|
+
if (typeof authVal === 'string') {
|
105
|
+
const auth = authVal.split(':');
|
106
|
+
authVal = {
|
108
107
|
user: auth.shift(),
|
109
108
|
pass: auth.join(':'),
|
110
109
|
sendImmediately: true
|
111
110
|
};
|
112
111
|
}
|
112
|
+
if(authVal) {
|
113
|
+
settings.headers = Object.assign({}, settings.headers, {Authorization: `Bearer ${authVal.bearer}`});
|
114
|
+
}
|
113
115
|
})
|
114
116
|
.then(() => {
|
115
117
|
const startTime = process.hrtime();
|
@@ -124,7 +126,6 @@ module.exports = class Model extends EventEmitter {
|
|
124
126
|
|
125
127
|
const endTime = process.hrtime();
|
126
128
|
const responseTime = timeDiff(startTime, endTime);
|
127
|
-
|
128
129
|
if (err) {
|
129
130
|
this.emit('fail', err, data, originalSettings, statusCode, responseTime);
|
130
131
|
} else {
|
@@ -136,23 +137,23 @@ module.exports = class Model extends EventEmitter {
|
|
136
137
|
resolve(data);
|
137
138
|
}
|
138
139
|
};
|
139
|
-
|
140
|
-
this._request(settings
|
141
|
-
|
140
|
+
|
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);
|
148
|
+
});
|
149
|
+
}).catch(err => {
|
142
150
|
if (err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
|
143
151
|
err.message = 'Connection timed out';
|
144
152
|
err.status = 504;
|
145
153
|
}
|
146
|
-
err.status = err.status ||
|
154
|
+
err.status = err.status || 503;
|
147
155
|
return _callback(err, null, err.status);
|
148
|
-
}
|
149
|
-
return this.handleResponse(response, (error, data, status) => {
|
150
|
-
if (error) {
|
151
|
-
error.headers = response.headers;
|
152
|
-
}
|
153
|
-
_callback(error, data, status);
|
154
156
|
});
|
155
|
-
});
|
156
157
|
});
|
157
158
|
});
|
158
159
|
|
@@ -165,13 +166,13 @@ module.exports = class Model extends EventEmitter {
|
|
165
166
|
handleResponse(response, callback) {
|
166
167
|
let data = {};
|
167
168
|
try {
|
168
|
-
data = JSON.parse(response.
|
169
|
+
data = typeof response.data === 'object' ? response.data : JSON.parse(response.data || '{}');
|
169
170
|
} catch (err) {
|
170
|
-
err.status = response.
|
171
|
-
err.body = response.
|
172
|
-
return callback(err, null, response.
|
171
|
+
err.status = response.status;
|
172
|
+
err.body = response.data;
|
173
|
+
return callback(err, null, response.status);
|
173
174
|
}
|
174
|
-
return this.parseResponse(response.
|
175
|
+
return this.parseResponse(response.status, data, callback);
|
175
176
|
}
|
176
177
|
|
177
178
|
parseResponse(statusCode, data, callback) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "hof",
|
3
3
|
"description": "A bootstrap for HOF projects",
|
4
|
-
"version": "
|
4
|
+
"version": "21.0.0-axios-beta.1",
|
5
5
|
"license": "MIT",
|
6
6
|
"main": "index.js",
|
7
7
|
"author": "HomeOffice",
|
@@ -32,10 +32,12 @@
|
|
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"
|
35
|
+
"postversion": "git push && git push --tags",
|
36
|
+
"test-single": "mocha"
|
36
37
|
},
|
37
38
|
"dependencies": {
|
38
39
|
"aliasify": "^2.1.0",
|
40
|
+
"axios": "^1.5.1",
|
39
41
|
"bluebird": "^3.7.2",
|
40
42
|
"body-parser": "^1.15.1",
|
41
43
|
"browserify": "^17.0.0",
|
@@ -57,7 +59,7 @@
|
|
57
59
|
"findup": "^0.1.5",
|
58
60
|
"glob": "^7.2.0",
|
59
61
|
"govuk-elements-sass": "^3.1.3",
|
60
|
-
"govuk-frontend": "3.
|
62
|
+
"govuk-frontend": "3.14",
|
61
63
|
"govuk_template_mustache": "^0.26.0",
|
62
64
|
"helmet": "^3.22.0",
|
63
65
|
"hogan-express-strict": "^0.5.4",
|
@@ -66,7 +68,7 @@
|
|
66
68
|
"i18n-future": "^2.0.0",
|
67
69
|
"i18n-lookup": "^0.1.0",
|
68
70
|
"is-pdf": "^1.0.0",
|
69
|
-
"libphonenumber-js": "^1.9.
|
71
|
+
"libphonenumber-js": "^1.9.37",
|
70
72
|
"lodash": "^4.17.21",
|
71
73
|
"markdown-it": "^12.3.2",
|
72
74
|
"minimatch": "^3.0.7",
|
@@ -80,9 +82,9 @@
|
|
80
82
|
"nodemailer-smtp-transport": "^2.7.4",
|
81
83
|
"nodemailer-stub-transport": "^1.1.0",
|
82
84
|
"notifications-node-client": "^6.0.0",
|
85
|
+
"object-mapper": "^6.2.0",
|
83
86
|
"redis": "^3.1.2",
|
84
87
|
"reqres": "^3.0.1",
|
85
|
-
"request": "^2.79.0",
|
86
88
|
"rimraf": "^3.0.2",
|
87
89
|
"sass": "^1.56.2",
|
88
90
|
"serve-static": "^1.14.1",
|
@@ -96,7 +98,6 @@
|
|
96
98
|
"@cucumber/cucumber": "^7.3.0",
|
97
99
|
"@cucumber/pretty-formatter": "^1.0.0-alpha.1",
|
98
100
|
"@types/jest": "^26.0.14",
|
99
|
-
"@xmldom/xmldom": "~0.8.4",
|
100
101
|
"chai": "^3.5.0",
|
101
102
|
"chai-as-promised": "^7.1.1",
|
102
103
|
"chai-subset": "^1.6.0",
|
@@ -123,13 +124,14 @@
|
|
123
124
|
"playwright": "^1.16.3",
|
124
125
|
"postcode": "0.2.2",
|
125
126
|
"proxyquire": "^1.7.11",
|
126
|
-
"release-it": "^
|
127
|
+
"release-it": "^14.10.0",
|
127
128
|
"sinon": "^11.1.1",
|
128
129
|
"sinon-chai": "^3.7.0",
|
129
130
|
"supertest": "^3.0.0",
|
130
131
|
"travis-conditions": "0.0.0",
|
131
132
|
"watchify": "^4.0.0",
|
132
|
-
"webdriverio": "^4.14.4"
|
133
|
+
"webdriverio": "^4.14.4",
|
134
|
+
"xmldom": "^0.6.0"
|
133
135
|
},
|
134
136
|
"mocha": {
|
135
137
|
"reporter": "spec",
|