govuk_publishing_components 37.6.0 → 37.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +1 -1
- data/app/views/govuk_publishing_components/components/_contents_list.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/govuk-single-consent/README.md +157 -0
- data/node_modules/govuk-single-consent/dist/singleconsent.cjs.js +419 -0
- data/node_modules/govuk-single-consent/dist/singleconsent.esm.js +417 -0
- data/node_modules/govuk-single-consent/dist/singleconsent.iife.js +431 -0
- data/node_modules/govuk-single-consent/dist/singleconsent.iife.min.js +1 -0
- data/node_modules/govuk-single-consent/package.json +56 -0
- metadata +7 -1
@@ -0,0 +1,431 @@
|
|
1
|
+
(function (exports) {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
var DEFAULT_TIMEOUT = 10000;
|
5
|
+
function request(url, options, onSuccess, onError) {
|
6
|
+
try {
|
7
|
+
var req = new XMLHttpRequest();
|
8
|
+
var isTimeout = false;
|
9
|
+
options = options || {};
|
10
|
+
req.onreadystatechange = function () {
|
11
|
+
if (req.readyState === req.DONE) {
|
12
|
+
if (req.status >= 200 && req.status < 400) {
|
13
|
+
var jsonResponse = void 0;
|
14
|
+
try {
|
15
|
+
jsonResponse = JSON.parse(req.responseText);
|
16
|
+
onSuccess(jsonResponse);
|
17
|
+
}
|
18
|
+
catch (error) {
|
19
|
+
return onError(error);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
else if (req.status === 0 && req.timeout > 0) {
|
23
|
+
// Possible timeout, waiting for ontimeout event
|
24
|
+
// Timeout will throw a status = 0 request
|
25
|
+
// onreadystatechange preempts ontimeout
|
26
|
+
// And we can't know for sure at this stage if it's a timeout
|
27
|
+
setTimeout(function () {
|
28
|
+
if (isTimeout) {
|
29
|
+
return;
|
30
|
+
}
|
31
|
+
return onError(new Error('Request to ' + url + ' failed with status: ' + req.status));
|
32
|
+
}, 500);
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
return onError(new Error('Request to ' + url + ' failed with status: ' + req.status));
|
36
|
+
}
|
37
|
+
}
|
38
|
+
};
|
39
|
+
req.open(options.method || 'GET', url, true);
|
40
|
+
if (options.timeout) {
|
41
|
+
req.timeout = options.timeout;
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
req.timeout = DEFAULT_TIMEOUT;
|
45
|
+
}
|
46
|
+
req.ontimeout = function () {
|
47
|
+
isTimeout = true;
|
48
|
+
return onError(new Error('Request to ' + url + ' timed out'));
|
49
|
+
};
|
50
|
+
var headers = options.headers || {};
|
51
|
+
for (var name in headers) {
|
52
|
+
req.setRequestHeader(name, headers[name]);
|
53
|
+
}
|
54
|
+
req.send(options.body || null);
|
55
|
+
}
|
56
|
+
catch (error) {
|
57
|
+
return onError(error);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
function addUrlParameter(url, name, value) {
|
61
|
+
url = parseUrl(url);
|
62
|
+
var newParam = name.concat('=', value);
|
63
|
+
var modified = false;
|
64
|
+
findByKey(name, url.params, function (index) {
|
65
|
+
url.params[index] = newParam;
|
66
|
+
modified = true;
|
67
|
+
});
|
68
|
+
if (!modified) {
|
69
|
+
url.params.push(newParam);
|
70
|
+
}
|
71
|
+
return buildUrl(url);
|
72
|
+
}
|
73
|
+
function removeUrlParameter(url, name) {
|
74
|
+
url = parseUrl(url);
|
75
|
+
findByKey(name, url.params, function (index) {
|
76
|
+
url.params.splice(index--, 1);
|
77
|
+
});
|
78
|
+
return buildUrl(url);
|
79
|
+
}
|
80
|
+
function parseUrl(url) {
|
81
|
+
var parts = url.split('?');
|
82
|
+
return {
|
83
|
+
address: parts[0],
|
84
|
+
params: (parts[1] || '').split('&').filter(Boolean),
|
85
|
+
};
|
86
|
+
}
|
87
|
+
function buildUrl(parts) {
|
88
|
+
return [parts.address, parts.params.join('&')].join('?').replace(/\??$/, '');
|
89
|
+
}
|
90
|
+
function findByKey(key, keyvals, callback) {
|
91
|
+
key += '=';
|
92
|
+
for (var index = 0; keyvals.length > index; index++) {
|
93
|
+
if (keyvals[index].trim().slice(0, key.length) === key) {
|
94
|
+
var value = keyvals[index].trim().slice(key.length);
|
95
|
+
if (callback) {
|
96
|
+
callback(index, value);
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
return value;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function isCrossOrigin(link) {
|
105
|
+
return (link.protocol !== window.location.protocol ||
|
106
|
+
link.hostname !== window.location.hostname ||
|
107
|
+
(link.port || '80') !== (window.location.port || '80'));
|
108
|
+
}
|
109
|
+
function getOriginFromLink(link) {
|
110
|
+
var origin = link.protocol.concat('//', link.hostname);
|
111
|
+
if (link.port && link.port !== '80' && link.port !== '443') {
|
112
|
+
origin = origin.concat(':', link.port);
|
113
|
+
}
|
114
|
+
return origin;
|
115
|
+
}
|
116
|
+
function isBrowser() {
|
117
|
+
return typeof module === 'undefined';
|
118
|
+
}
|
119
|
+
function setCookie(_a) {
|
120
|
+
var name = _a.name, value = _a.value, lifetime = _a.lifetime;
|
121
|
+
// const encodedValue = encodeURIComponent(value)
|
122
|
+
var encodedValue = value;
|
123
|
+
document.cookie = name
|
124
|
+
.concat('=', encodedValue)
|
125
|
+
.concat('; path=/', '; max-age='.concat(lifetime.toString()), document.location.protocol === 'https:' ? '; Secure' : '');
|
126
|
+
}
|
127
|
+
function getCookie(name, defaultValue) {
|
128
|
+
name += '=';
|
129
|
+
var cookies = document.cookie.split(';');
|
130
|
+
var cookie = null;
|
131
|
+
for (var i = 0; i < cookies.length; i++) {
|
132
|
+
var currentCookie = cookies[i].trim();
|
133
|
+
if (currentCookie.indexOf(name) === 0) {
|
134
|
+
cookie = currentCookie;
|
135
|
+
break;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
if (cookie) {
|
139
|
+
return decodeURIComponent(cookie.trim().slice(name.length));
|
140
|
+
}
|
141
|
+
return defaultValue || null;
|
142
|
+
}
|
143
|
+
function validateConsentObject(response) {
|
144
|
+
try {
|
145
|
+
if (typeof response !== 'object' || response === null) {
|
146
|
+
return false;
|
147
|
+
}
|
148
|
+
var expectedKeys = ['essential', 'settings', 'usage', 'campaigns'];
|
149
|
+
var allKeysPresent = true;
|
150
|
+
var responseKeysCount = 0;
|
151
|
+
for (var i = 0; i < expectedKeys.length; i++) {
|
152
|
+
if (!(expectedKeys[i] in response)) {
|
153
|
+
allKeysPresent = false;
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
var allValuesBoolean = true;
|
158
|
+
for (var key in response) {
|
159
|
+
if (response.hasOwnProperty(key)) {
|
160
|
+
responseKeysCount++;
|
161
|
+
if (typeof response[key] !== 'boolean') {
|
162
|
+
allValuesBoolean = false;
|
163
|
+
break;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
var correctNumberOfKeys = responseKeysCount === expectedKeys.length;
|
168
|
+
}
|
169
|
+
catch (err) {
|
170
|
+
return false;
|
171
|
+
}
|
172
|
+
return allKeysPresent && allValuesBoolean && correctNumberOfKeys;
|
173
|
+
}
|
174
|
+
|
175
|
+
var COOKIE_DAYS = 365;
|
176
|
+
var GovConsentConfig = /** @class */ (function () {
|
177
|
+
function GovConsentConfig(baseUrl) {
|
178
|
+
this.uidFromCookie = findByKey(GovConsentConfig.UID_KEY, document.cookie.split(';'));
|
179
|
+
this.uidFromUrl = findByKey(GovConsentConfig.UID_KEY, parseUrl(location.href).params);
|
180
|
+
this.baseUrl = baseUrl;
|
181
|
+
}
|
182
|
+
GovConsentConfig.UID_KEY = 'gov_singleconsent_uid';
|
183
|
+
GovConsentConfig.CONSENTS_COOKIE_NAME = 'cookies_policy';
|
184
|
+
GovConsentConfig.PREFERENCES_SET_COOKIE_NAME = 'cookies_preferences_set';
|
185
|
+
GovConsentConfig.COOKIE_LIFETIME = COOKIE_DAYS * 24 * 60 * 60;
|
186
|
+
return GovConsentConfig;
|
187
|
+
}());
|
188
|
+
|
189
|
+
var ApiV1 = /** @class */ (function () {
|
190
|
+
function ApiV1(baseUrl) {
|
191
|
+
this.version = 'v1';
|
192
|
+
this.baseUrl = baseUrl;
|
193
|
+
}
|
194
|
+
ApiV1.prototype.buildUrl = function (endpoint, pathParam) {
|
195
|
+
var url = "".concat(this.baseUrl, "/api/").concat(this.version).concat(endpoint);
|
196
|
+
if (pathParam) {
|
197
|
+
url += "/".concat(pathParam);
|
198
|
+
}
|
199
|
+
return url;
|
200
|
+
};
|
201
|
+
ApiV1.prototype.origins = function () {
|
202
|
+
return this.buildUrl(ApiV1.Routes.origins);
|
203
|
+
};
|
204
|
+
ApiV1.prototype.consents = function (id) {
|
205
|
+
return this.buildUrl(ApiV1.Routes.consents, id || '');
|
206
|
+
};
|
207
|
+
ApiV1.Routes = {
|
208
|
+
origins: '/origins',
|
209
|
+
consents: '/consent',
|
210
|
+
};
|
211
|
+
return ApiV1;
|
212
|
+
}());
|
213
|
+
|
214
|
+
var GovSingleConsent = /** @class */ (function () {
|
215
|
+
function GovSingleConsent(consentsUpdateCallback, baseUrlOrEnv) {
|
216
|
+
/**
|
217
|
+
Initialises _GovConsent object by performing the following:
|
218
|
+
1. Removes 'uid' from URL.
|
219
|
+
2. Sets 'uid' attribute from cookie or URL.
|
220
|
+
3. Fetches consent status from API if 'uid' exists.
|
221
|
+
4. Notifies event listeners with API response.
|
222
|
+
|
223
|
+
@arg baseUrl: string - the domain of where the single consent API is. Required.
|
224
|
+
@arg consentsUpdateCallback: function(consents, consentsPreferencesSet, error) - callback when the consents are updated
|
225
|
+
"consents": this is the consents object. It has the following properties: "essential", "usage", "campaigns", "settings". Each property is a boolean.
|
226
|
+
"consentsPreferencesSet": true if the consents have been set for this user and this domain. Typically, only display the cookie banner if this is true.
|
227
|
+
"error": if an error occurred, this is the error object. Otherwise, this is null.
|
228
|
+
*/
|
229
|
+
this.cachedConsentsCookie = null;
|
230
|
+
this.validateConstructorArguments(baseUrlOrEnv, consentsUpdateCallback);
|
231
|
+
var baseUrl = this.resolveBaseUrl(baseUrlOrEnv);
|
232
|
+
this._consentsUpdateCallback = consentsUpdateCallback;
|
233
|
+
this.config = new GovConsentConfig(baseUrl);
|
234
|
+
this.urls = new ApiV1(this.config.baseUrl);
|
235
|
+
window.cachedConsentsCookie = null;
|
236
|
+
this.hideUIDParameter();
|
237
|
+
this.initialiseUIDandConsents();
|
238
|
+
}
|
239
|
+
GovSingleConsent.prototype.validateConstructorArguments = function (baseUrlOrEnv, consentsUpdateCallback) {
|
240
|
+
if (!baseUrlOrEnv) {
|
241
|
+
throw new Error('Argument baseUrl is required');
|
242
|
+
}
|
243
|
+
if (typeof baseUrlOrEnv !== 'string') {
|
244
|
+
throw new Error('Argument baseUrl must be a string');
|
245
|
+
}
|
246
|
+
if (!consentsUpdateCallback) {
|
247
|
+
throw new Error('Argument consentsUpdateCallback is required');
|
248
|
+
}
|
249
|
+
if (typeof consentsUpdateCallback !== 'function') {
|
250
|
+
throw new Error('Argument consentsUpdateCallback must be a function');
|
251
|
+
}
|
252
|
+
};
|
253
|
+
GovSingleConsent.prototype.resolveBaseUrl = function (baseUrlOrEnv) {
|
254
|
+
if (baseUrlOrEnv === 'staging') {
|
255
|
+
return 'https://gds-single-consent-staging.app';
|
256
|
+
}
|
257
|
+
else if (baseUrlOrEnv === 'production') {
|
258
|
+
return 'https://gds-single-consent.app';
|
259
|
+
}
|
260
|
+
// If not "staging" or "production", assume it's a custom URL
|
261
|
+
return baseUrlOrEnv;
|
262
|
+
};
|
263
|
+
GovSingleConsent.prototype.initialiseUIDandConsents = function () {
|
264
|
+
var currentUID = this.getCurrentUID();
|
265
|
+
if (this.isNewUID(currentUID)) {
|
266
|
+
this.handleNewUID(currentUID);
|
267
|
+
}
|
268
|
+
if (this.uid) {
|
269
|
+
this.fetchAndUpdateConsents();
|
270
|
+
}
|
271
|
+
else {
|
272
|
+
this._consentsUpdateCallback(null, false, null);
|
273
|
+
}
|
274
|
+
};
|
275
|
+
GovSingleConsent.prototype.handleNewUID = function (newUID) {
|
276
|
+
this.uid = newUID;
|
277
|
+
this.updateLinksEventHandlers(newUID);
|
278
|
+
this.setUIDCookie(newUID);
|
279
|
+
};
|
280
|
+
GovSingleConsent.prototype.isNewUID = function (currentUID) {
|
281
|
+
return currentUID && currentUID !== this.uid;
|
282
|
+
};
|
283
|
+
GovSingleConsent.prototype.fetchAndUpdateConsents = function () {
|
284
|
+
var _this = this;
|
285
|
+
var consentsUrl = this.urls.consents(this.uid);
|
286
|
+
request(consentsUrl, { timeout: 1000 }, function (jsonResponse) {
|
287
|
+
if (!validateConsentObject(jsonResponse.status)) {
|
288
|
+
var error = new Error('Invalid consents object returned from the API: ' + JSON.stringify(jsonResponse));
|
289
|
+
return _this.defaultToRejectAllConsents(error);
|
290
|
+
}
|
291
|
+
var consents = jsonResponse.status;
|
292
|
+
_this.updateBrowserConsents(consents);
|
293
|
+
_this._consentsUpdateCallback(consents, GovSingleConsent.isConsentPreferencesSet(), null);
|
294
|
+
}, function (error) { return _this.defaultToRejectAllConsents(error); });
|
295
|
+
};
|
296
|
+
GovSingleConsent.prototype.getCurrentUID = function () {
|
297
|
+
// Get the current uid from URL or from the cookie if it exists
|
298
|
+
return this.config.uidFromUrl || this.config.uidFromCookie;
|
299
|
+
};
|
300
|
+
GovSingleConsent.prototype.setConsents = function (consents) {
|
301
|
+
var _this = this;
|
302
|
+
if (!consents) {
|
303
|
+
throw new Error('consents is required in GovSingleConsent.setConsents()');
|
304
|
+
}
|
305
|
+
var successCallback = function (response) {
|
306
|
+
if (!response.uid) {
|
307
|
+
throw new Error('No UID returned from the API');
|
308
|
+
}
|
309
|
+
if (_this.isNewUID(response.uid)) {
|
310
|
+
_this.handleNewUID(response.uid);
|
311
|
+
}
|
312
|
+
_this.updateBrowserConsents(consents);
|
313
|
+
_this._consentsUpdateCallback(consents, GovSingleConsent.isConsentPreferencesSet(), null);
|
314
|
+
};
|
315
|
+
var url = this.urls.consents(this.uid);
|
316
|
+
request(url, {
|
317
|
+
method: 'POST',
|
318
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
319
|
+
body: 'status='.concat(JSON.stringify(consents)),
|
320
|
+
}, successCallback, function (error) { return _this.defaultToRejectAllConsents(error); });
|
321
|
+
};
|
322
|
+
GovSingleConsent.prototype.defaultToRejectAllConsents = function (error) {
|
323
|
+
this.updateBrowserConsents(GovSingleConsent.REJECT_ALL);
|
324
|
+
this._consentsUpdateCallback(GovSingleConsent.REJECT_ALL, GovSingleConsent.isConsentPreferencesSet(), error);
|
325
|
+
};
|
326
|
+
GovSingleConsent.getConsents = function () {
|
327
|
+
if (window.cachedConsentsCookie) {
|
328
|
+
return window.cachedConsentsCookie;
|
329
|
+
}
|
330
|
+
var cookieValue = getCookie(GovConsentConfig.CONSENTS_COOKIE_NAME, null);
|
331
|
+
if (cookieValue) {
|
332
|
+
return JSON.parse(cookieValue);
|
333
|
+
}
|
334
|
+
return null;
|
335
|
+
};
|
336
|
+
GovSingleConsent.hasConsentedToEssential = function () {
|
337
|
+
var consents = GovSingleConsent.getConsents();
|
338
|
+
return consents === null || consents === void 0 ? void 0 : consents.essential;
|
339
|
+
};
|
340
|
+
GovSingleConsent.hasConsentedToUsage = function () {
|
341
|
+
var consents = GovSingleConsent.getConsents();
|
342
|
+
return consents === null || consents === void 0 ? void 0 : consents.usage;
|
343
|
+
};
|
344
|
+
GovSingleConsent.hasConsentedToCampaigns = function () {
|
345
|
+
var consents = GovSingleConsent.getConsents();
|
346
|
+
return consents === null || consents === void 0 ? void 0 : consents.campaigns;
|
347
|
+
};
|
348
|
+
GovSingleConsent.hasConsentedToSettings = function () {
|
349
|
+
var consents = GovSingleConsent.getConsents();
|
350
|
+
return consents === null || consents === void 0 ? void 0 : consents.settings;
|
351
|
+
};
|
352
|
+
GovSingleConsent.isConsentPreferencesSet = function () {
|
353
|
+
var value = getCookie(GovConsentConfig.PREFERENCES_SET_COOKIE_NAME, null);
|
354
|
+
return value === 'true';
|
355
|
+
};
|
356
|
+
GovSingleConsent.prototype.updateLinksEventHandlers = function (currentUID) {
|
357
|
+
var _this = this;
|
358
|
+
request(this.urls.origins(), {},
|
359
|
+
// Update links with UID
|
360
|
+
function (origins) { return _this.addUIDtoCrossOriginLinks(origins, currentUID); }, function (error) {
|
361
|
+
throw error;
|
362
|
+
});
|
363
|
+
};
|
364
|
+
GovSingleConsent.prototype.addUIDtoCrossOriginLinks = function (origins, uid) {
|
365
|
+
/**
|
366
|
+
* Adds uid URL parameter to consent sharing links.
|
367
|
+
* Only links with known origins are updated.
|
368
|
+
*/
|
369
|
+
var links = document.querySelectorAll('a[href]');
|
370
|
+
Array.prototype.forEach.call(links, function (link) {
|
371
|
+
if (isCrossOrigin(link) &&
|
372
|
+
origins.indexOf(getOriginFromLink(link)) >= 0) {
|
373
|
+
link.addEventListener('click', function (event) {
|
374
|
+
event.target.href = addUrlParameter(event.target.href, GovConsentConfig.UID_KEY, uid);
|
375
|
+
});
|
376
|
+
}
|
377
|
+
});
|
378
|
+
};
|
379
|
+
GovSingleConsent.prototype.setUIDCookie = function (uid) {
|
380
|
+
setCookie({
|
381
|
+
name: GovConsentConfig.UID_KEY,
|
382
|
+
value: uid,
|
383
|
+
lifetime: GovConsentConfig.COOKIE_LIFETIME,
|
384
|
+
});
|
385
|
+
};
|
386
|
+
GovSingleConsent.prototype.updateBrowserConsents = function (consents) {
|
387
|
+
this.setConsentsCookie(consents);
|
388
|
+
this.setPreferencesSetCookie(true);
|
389
|
+
window.cachedConsentsCookie = consents;
|
390
|
+
};
|
391
|
+
GovSingleConsent.prototype.setConsentsCookie = function (consents) {
|
392
|
+
setCookie({
|
393
|
+
name: GovConsentConfig.CONSENTS_COOKIE_NAME,
|
394
|
+
value: JSON.stringify(consents),
|
395
|
+
lifetime: GovConsentConfig.COOKIE_LIFETIME,
|
396
|
+
});
|
397
|
+
};
|
398
|
+
GovSingleConsent.prototype.setPreferencesSetCookie = function (value) {
|
399
|
+
setCookie({
|
400
|
+
name: GovConsentConfig.PREFERENCES_SET_COOKIE_NAME,
|
401
|
+
value: value.toString(),
|
402
|
+
lifetime: GovConsentConfig.COOKIE_LIFETIME,
|
403
|
+
});
|
404
|
+
};
|
405
|
+
GovSingleConsent.prototype.hideUIDParameter = function () {
|
406
|
+
history.replaceState(null, null, removeUrlParameter(location.href, GovConsentConfig.UID_KEY));
|
407
|
+
};
|
408
|
+
GovSingleConsent.ACCEPT_ALL = {
|
409
|
+
essential: true,
|
410
|
+
usage: true,
|
411
|
+
campaigns: true,
|
412
|
+
settings: true,
|
413
|
+
};
|
414
|
+
GovSingleConsent.REJECT_ALL = {
|
415
|
+
essential: true,
|
416
|
+
usage: false,
|
417
|
+
campaigns: false,
|
418
|
+
settings: false,
|
419
|
+
};
|
420
|
+
return GovSingleConsent;
|
421
|
+
}());
|
422
|
+
|
423
|
+
if (isBrowser()) {
|
424
|
+
window.GovSingleConsent = GovSingleConsent;
|
425
|
+
}
|
426
|
+
|
427
|
+
exports.GovSingleConsent = GovSingleConsent;
|
428
|
+
|
429
|
+
return exports;
|
430
|
+
|
431
|
+
})({});
|
@@ -0,0 +1 @@
|
|
1
|
+
!function(t){"use strict";function e(t,e,n,o){try{var s=new XMLHttpRequest,r=!1;e=e||{},s.onreadystatechange=function(){if(s.readyState===s.DONE)if(s.status>=200&&s.status<400){var e=void 0;try{e=JSON.parse(s.responseText),n(e)}catch(t){return o(t)}}else{if(!(0===s.status&&s.timeout>0))return o(new Error("Request to "+t+" failed with status: "+s.status));setTimeout((function(){if(!r)return o(new Error("Request to "+t+" failed with status: "+s.status))}),500)}},s.open(e.method||"GET",t,!0),e.timeout?s.timeout=e.timeout:s.timeout=1e4,s.ontimeout=function(){return r=!0,o(new Error("Request to "+t+" timed out"))};var i=e.headers||{};for(var a in i)s.setRequestHeader(a,i[a]);s.send(e.body||null)}catch(t){return o(t)}}function n(t){var e=t.split("?");return{address:e[0],params:(e[1]||"").split("&").filter(Boolean)}}function o(t){return[t.address,t.params.join("&")].join("?").replace(/\??$/,"")}function s(t,e,n){t+="=";for(var o=0;e.length>o;o++)if(e[o].trim().slice(0,t.length)===t){var s=e[o].trim().slice(t.length);if(!n)return s;n(o,s)}}function r(t){var e=t.name,n=t.value,o=t.lifetime,s=n;document.cookie=e.concat("=",s).concat("; path=/","; max-age=".concat(o.toString()),"https:"===document.location.protocol?"; Secure":"")}function i(t,e){t+="=";for(var n=document.cookie.split(";"),o=null,s=0;s<n.length;s++){var r=n[s].trim();if(0===r.indexOf(t)){o=r;break}}return o?decodeURIComponent(o.trim().slice(t.length)):e||null}var a=function(){function t(e){this.uidFromCookie=s(t.UID_KEY,document.cookie.split(";")),this.uidFromUrl=s(t.UID_KEY,n(location.href).params),this.baseUrl=e}return t.UID_KEY="gov_singleconsent_uid",t.CONSENTS_COOKIE_NAME="cookies_policy",t.PREFERENCES_SET_COOKIE_NAME="cookies_preferences_set",t.COOKIE_LIFETIME=31536e3,t}(),u=function(){function t(t){this.version="v1",this.baseUrl=t}return t.prototype.buildUrl=function(t,e){var n="".concat(this.baseUrl,"/api/").concat(this.version).concat(t);return e&&(n+="/".concat(e)),n},t.prototype.origins=function(){return this.buildUrl(t.Routes.origins)},t.prototype.consents=function(e){return this.buildUrl(t.Routes.consents,e||"")},t.Routes={origins:"/origins",consents:"/consent"},t}(),c=function(){function t(t,e){this.cachedConsentsCookie=null,this.validateConstructorArguments(e,t);var n=this.resolveBaseUrl(e);this._consentsUpdateCallback=t,this.config=new a(n),this.urls=new u(this.config.baseUrl),window.cachedConsentsCookie=null,this.hideUIDParameter(),this.initialiseUIDandConsents()}return t.prototype.validateConstructorArguments=function(t,e){if(!t)throw new Error("Argument baseUrl is required");if("string"!=typeof t)throw new Error("Argument baseUrl must be a string");if(!e)throw new Error("Argument consentsUpdateCallback is required");if("function"!=typeof e)throw new Error("Argument consentsUpdateCallback must be a function")},t.prototype.resolveBaseUrl=function(t){return"staging"===t?"https://gds-single-consent-staging.app":"production"===t?"https://gds-single-consent.app":t},t.prototype.initialiseUIDandConsents=function(){var t=this.getCurrentUID();this.isNewUID(t)&&this.handleNewUID(t),this.uid?this.fetchAndUpdateConsents():this._consentsUpdateCallback(null,!1,null)},t.prototype.handleNewUID=function(t){this.uid=t,this.updateLinksEventHandlers(t),this.setUIDCookie(t)},t.prototype.isNewUID=function(t){return t&&t!==this.uid},t.prototype.fetchAndUpdateConsents=function(){var n=this;e(this.urls.consents(this.uid),{timeout:1e3},(function(e){if(!function(t){try{if("object"!=typeof t||null===t)return!1;for(var e=["essential","settings","usage","campaigns"],n=!0,o=0,s=0;s<e.length;s++)if(!(e[s]in t)){n=!1;break}var r=!0;for(var i in t)if(t.hasOwnProperty(i)&&(o++,"boolean"!=typeof t[i])){r=!1;break}var a=o===e.length}catch(t){return!1}return n&&r&&a}(e.status)){var o=new Error("Invalid consents object returned from the API: "+JSON.stringify(e));return n.defaultToRejectAllConsents(o)}var s=e.status;n.updateBrowserConsents(s),n._consentsUpdateCallback(s,t.isConsentPreferencesSet(),null)}),(function(t){return n.defaultToRejectAllConsents(t)}))},t.prototype.getCurrentUID=function(){return this.config.uidFromUrl||this.config.uidFromCookie},t.prototype.setConsents=function(n){var o=this;if(!n)throw new Error("consents is required in GovSingleConsent.setConsents()");e(this.urls.consents(this.uid),{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"status=".concat(JSON.stringify(n))},(function(e){if(!e.uid)throw new Error("No UID returned from the API");o.isNewUID(e.uid)&&o.handleNewUID(e.uid),o.updateBrowserConsents(n),o._consentsUpdateCallback(n,t.isConsentPreferencesSet(),null)}),(function(t){return o.defaultToRejectAllConsents(t)}))},t.prototype.defaultToRejectAllConsents=function(e){this.updateBrowserConsents(t.REJECT_ALL),this._consentsUpdateCallback(t.REJECT_ALL,t.isConsentPreferencesSet(),e)},t.getConsents=function(){if(window.cachedConsentsCookie)return window.cachedConsentsCookie;var t=i(a.CONSENTS_COOKIE_NAME,null);return t?JSON.parse(t):null},t.hasConsentedToEssential=function(){var e=t.getConsents();return null==e?void 0:e.essential},t.hasConsentedToUsage=function(){var e=t.getConsents();return null==e?void 0:e.usage},t.hasConsentedToCampaigns=function(){var e=t.getConsents();return null==e?void 0:e.campaigns},t.hasConsentedToSettings=function(){var e=t.getConsents();return null==e?void 0:e.settings},t.isConsentPreferencesSet=function(){return"true"===i(a.PREFERENCES_SET_COOKIE_NAME,null)},t.prototype.updateLinksEventHandlers=function(t){var n=this;e(this.urls.origins(),{},(function(e){return n.addUIDtoCrossOriginLinks(e,t)}),(function(t){throw t}))},t.prototype.addUIDtoCrossOriginLinks=function(t,e){var r=document.querySelectorAll("a[href]");Array.prototype.forEach.call(r,(function(r){(function(t){return t.protocol!==window.location.protocol||t.hostname!==window.location.hostname||(t.port||"80")!==(window.location.port||"80")})(r)&&t.indexOf(function(t){var e=t.protocol.concat("//",t.hostname);return t.port&&"80"!==t.port&&"443"!==t.port&&(e=e.concat(":",t.port)),e}(r))>=0&&r.addEventListener("click",(function(t){t.target.href=function(t,e,r){t=n(t);var i=e.concat("=",r),a=!1;return s(e,t.params,(function(e){t.params[e]=i,a=!0})),a||t.params.push(i),o(t)}(t.target.href,a.UID_KEY,e)}))}))},t.prototype.setUIDCookie=function(t){r({name:a.UID_KEY,value:t,lifetime:a.COOKIE_LIFETIME})},t.prototype.updateBrowserConsents=function(t){this.setConsentsCookie(t),this.setPreferencesSetCookie(!0),window.cachedConsentsCookie=t},t.prototype.setConsentsCookie=function(t){r({name:a.CONSENTS_COOKIE_NAME,value:JSON.stringify(t),lifetime:a.COOKIE_LIFETIME})},t.prototype.setPreferencesSetCookie=function(t){r({name:a.PREFERENCES_SET_COOKIE_NAME,value:t.toString(),lifetime:a.COOKIE_LIFETIME})},t.prototype.hideUIDParameter=function(){var t;history.replaceState(null,null,(t=location.href,s(a.UID_KEY,(t=n(t)).params,(function(e){t.params.splice(e--,1)})),o(t)))},t.ACCEPT_ALL={essential:!0,usage:!0,campaigns:!0,settings:!0},t.REJECT_ALL={essential:!0,usage:!1,campaigns:!1,settings:!1},t}();"undefined"==typeof module&&(window.GovSingleConsent=c),t.GovSingleConsent=c}({});
|
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"name": "govuk-single-consent",
|
3
|
+
"version": "3.0.9",
|
4
|
+
"main": "dist/singleconsent.cjs.js",
|
5
|
+
"module": "dist/singleconsent.esm.js",
|
6
|
+
"browser": "dist/singleconsent.iife.js",
|
7
|
+
"engines": {
|
8
|
+
"node": ">=18.0.0"
|
9
|
+
},
|
10
|
+
"description": "Client code for the Cookie Consent Sharing API",
|
11
|
+
"scripts": {
|
12
|
+
"test": "jest",
|
13
|
+
"format": "prettier --write .",
|
14
|
+
"lint": "eslint . --fix",
|
15
|
+
"build": "npx rollup --config rollup.config.mjs",
|
16
|
+
"publish-package": "sh ./scripts/publish-package.sh"
|
17
|
+
},
|
18
|
+
"files": [
|
19
|
+
"dist/*"
|
20
|
+
],
|
21
|
+
"sideEffects": false,
|
22
|
+
"repository": {
|
23
|
+
"type": "git",
|
24
|
+
"url": "git+https://github.com/alphagov/consent-api.git"
|
25
|
+
},
|
26
|
+
"author": {
|
27
|
+
"name": "Andy Driver",
|
28
|
+
"email": "andy.driver@digital.cabinet-office.gov.uk"
|
29
|
+
},
|
30
|
+
"license": "SEE LICENSE IN ../LICENSE",
|
31
|
+
"bugs": {
|
32
|
+
"url": "https://github.com/alphagov/consent-api/issues"
|
33
|
+
},
|
34
|
+
"homepage": "https://github.com/alphagov/consent-api/client/#readme",
|
35
|
+
"devDependencies": {
|
36
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
37
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
38
|
+
"@rollup/plugin-terser": "^0.4.4",
|
39
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
40
|
+
"@types/jest": "^29.5.6",
|
41
|
+
"@types/jsdom": "^21.1.4",
|
42
|
+
"@types/xhr-mock": "^2.0.0",
|
43
|
+
"eslint": "^8.51.0",
|
44
|
+
"jest": "^29.6.1",
|
45
|
+
"jest-environment-jsdom": "^29.6.1",
|
46
|
+
"jest-environment-jsdom-global": "^4.0.0",
|
47
|
+
"jsdom": "^22.1.0",
|
48
|
+
"jsdom-global": "^3.0.2",
|
49
|
+
"prettier": "^3.0.3",
|
50
|
+
"rollup": "^4.1.5",
|
51
|
+
"ts-jest": "^29.1.1",
|
52
|
+
"tslib": "^2.6.2",
|
53
|
+
"typescript": "^5.2.2",
|
54
|
+
"xhr-mock": "^2.5.1"
|
55
|
+
}
|
56
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 37.6.
|
4
|
+
version: 37.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -1602,6 +1602,12 @@ files:
|
|
1602
1602
|
- node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js
|
1603
1603
|
- node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js.map
|
1604
1604
|
- node_modules/govuk-frontend/package.json
|
1605
|
+
- node_modules/govuk-single-consent/README.md
|
1606
|
+
- node_modules/govuk-single-consent/dist/singleconsent.cjs.js
|
1607
|
+
- node_modules/govuk-single-consent/dist/singleconsent.esm.js
|
1608
|
+
- node_modules/govuk-single-consent/dist/singleconsent.iife.js
|
1609
|
+
- node_modules/govuk-single-consent/dist/singleconsent.iife.min.js
|
1610
|
+
- node_modules/govuk-single-consent/package.json
|
1605
1611
|
- node_modules/sortablejs/LICENSE
|
1606
1612
|
- node_modules/sortablejs/README.md
|
1607
1613
|
- node_modules/sortablejs/Sortable.js
|