bv-ui-core 2.9.11 → 2.9.12
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/lib/cookie/index.js
CHANGED
|
@@ -16,29 +16,19 @@ var store = {};
|
|
|
16
16
|
* @param {Number} days The cookie lifespan in days.
|
|
17
17
|
* @param {String} [domain] The domain for the cookie.
|
|
18
18
|
* @param {Boolean} [secure] Whether this is a secure cookie.
|
|
19
|
-
* @param {String} [sameSite='Lax'] The SameSite attribute ('Strict', 'Lax', or 'None'). Defaults to 'Lax'.
|
|
20
19
|
*/
|
|
21
|
-
function createCookie (name, value, days, domain, secure
|
|
20
|
+
function createCookie (name, value, days, domain, secure) {
|
|
22
21
|
var date = new Date();
|
|
23
22
|
|
|
24
23
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
25
24
|
var expires = days ? ';expires=' + date.toGMTString() : '';
|
|
26
25
|
|
|
27
|
-
// Determine if the cookie should be secure.
|
|
28
|
-
// Force the Secure flag if the page is loaded over HTTPS, OR if the explicit `secure` argument is true.
|
|
29
|
-
// This ensures that all cookies (including BVBRANDID) set by this library are secure in production environments.
|
|
30
|
-
var isSecure = secure || (global.location && global.location.protocol === 'https:');
|
|
31
|
-
|
|
32
|
-
// SameSite=None requires the Secure flag, so we fallback to 'Lax' if not secure.
|
|
33
|
-
var sameSiteValue = (sameSite === 'None' && !isSecure) ? 'Lax' : sameSite;
|
|
34
|
-
|
|
35
26
|
var c = encodeURIComponent(name) + '=' +
|
|
36
27
|
encodeURIComponent(value) +
|
|
37
28
|
expires +
|
|
38
29
|
';path=/' +
|
|
39
30
|
(domain ? (';domain=' + domain) : '') +
|
|
40
|
-
(
|
|
41
|
-
';SameSite=' + sameSiteValue;
|
|
31
|
+
(secure ? (';secure') : '');
|
|
42
32
|
|
|
43
33
|
global.document.cookie = c;
|
|
44
34
|
}
|
|
@@ -75,7 +65,7 @@ function readCookie (name) {
|
|
|
75
65
|
function removeCookie (name, domain) {
|
|
76
66
|
delete store[name];
|
|
77
67
|
if (domain) {
|
|
78
|
-
createCookie(name,
|
|
68
|
+
createCookie(name, null, -1, domain);
|
|
79
69
|
}
|
|
80
70
|
else {
|
|
81
71
|
createCookie(name, '', -1);
|
|
@@ -83,23 +73,23 @@ function removeCookie (name, domain) {
|
|
|
83
73
|
}
|
|
84
74
|
|
|
85
75
|
module.exports = {
|
|
86
|
-
create: function (name, value, days, domain, secure
|
|
76
|
+
create: function (name, value, days, domain, secure) {
|
|
87
77
|
store[name] = value;
|
|
88
78
|
var consentPresent = cookieConsent.getConsent(name);
|
|
89
79
|
if (consentPresent) {
|
|
90
|
-
createCookie(name, value, days, domain, secure
|
|
80
|
+
createCookie(name, value, days, domain, secure);
|
|
91
81
|
}
|
|
92
|
-
cookieConsent.subscribe(name,
|
|
82
|
+
cookieConsent.subscribe(name,'add',function (consent) {
|
|
93
83
|
if (consent) {
|
|
94
|
-
createCookie(name,
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
removeCookie(name,
|
|
98
|
-
}
|
|
99
|
-
})
|
|
84
|
+
createCookie(name,value,days,domain,secure);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
removeCookie(name,domain)
|
|
88
|
+
}
|
|
89
|
+
})
|
|
100
90
|
|
|
101
91
|
cookieConsent.subscribe(name, 'enable', function () {
|
|
102
|
-
createCookie(name, value, days, domain, secure
|
|
92
|
+
createCookie(name, value, days, domain, secure);
|
|
103
93
|
});
|
|
104
94
|
|
|
105
95
|
cookieConsent.subscribe(name, 'disable', function () {
|
package/lib/global/index.js
CHANGED
|
@@ -18,7 +18,7 @@ var getGlobal = function () {
|
|
|
18
18
|
windows object during transpilation with __esModule being set. Below code would support
|
|
19
19
|
global import in all bundle use cases
|
|
20
20
|
*/
|
|
21
|
-
if (globalObj && globalObj.__esModule) {
|
|
21
|
+
if (globalObj && globalObj.__esModule && typeof window !== 'undefined' && globalObj !== window) {
|
|
22
22
|
const proxyGlobal = new Proxy(globalObj, {
|
|
23
23
|
get: function (target, prop) {
|
|
24
24
|
if (prop === 'default') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bv-ui-core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.12",
|
|
4
4
|
"license": "Apache 2.0",
|
|
5
5
|
"description": "Bazaarvoice UI-related JavaScript",
|
|
6
6
|
"repository": {
|
|
@@ -33,12 +33,14 @@
|
|
|
33
33
|
"karma-firefox-launcher": "^1.1.0",
|
|
34
34
|
"karma-htmlfile-reporter": "^0.3.6",
|
|
35
35
|
"karma-mocha": "^1.3.0",
|
|
36
|
+
"karma-phantomjs-launcher": "^1.0.4",
|
|
36
37
|
"karma-sinon": "^1.0.5",
|
|
37
38
|
"karma-sinon-chai": "^1.3.4",
|
|
38
39
|
"karma-webpack": "^1.7.0",
|
|
39
40
|
"lodash": "^4.17.10",
|
|
40
41
|
"mocha": "^5.2.0",
|
|
41
42
|
"node-libs-browser": "1.0.0",
|
|
43
|
+
"phantomjs": "^2.1.7",
|
|
42
44
|
"sinon": "^4.5.0",
|
|
43
45
|
"sinon-chai": "^2.14.0",
|
|
44
46
|
"webpack": "^1.15.0"
|
|
@@ -43,149 +43,3 @@ describe('lib/cookie', function () {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
});
|
|
46
|
-
|
|
47
|
-
describe('lib/cookie secure flag behavior', function () {
|
|
48
|
-
var originalProtocol;
|
|
49
|
-
|
|
50
|
-
beforeEach(function () {
|
|
51
|
-
// Store original protocol to restore after each test
|
|
52
|
-
originalProtocol = global.location && global.location.protocol;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
afterEach(function () {
|
|
56
|
-
// Restore original protocol
|
|
57
|
-
if (global.location) {
|
|
58
|
-
// Some browsers don't allow direct assignment to location.protocol
|
|
59
|
-
// so we use Object.defineProperty where possible
|
|
60
|
-
try {
|
|
61
|
-
Object.defineProperty(global.location, 'protocol', {
|
|
62
|
-
value: originalProtocol,
|
|
63
|
-
writable: true,
|
|
64
|
-
configurable: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
// If we can't restore, tests may need to run in isolation
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// Clean up test cookies
|
|
72
|
-
deleteCookie('test%20secure');
|
|
73
|
-
deleteCookie('test%20https');
|
|
74
|
-
deleteCookie('test%20http');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should set secure flag when secure=true is explicitly passed', function () {
|
|
78
|
-
cookieConsent.initConsent({
|
|
79
|
-
'test secure': true
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Create cookie with explicit secure=true
|
|
83
|
-
cookie.create('test secure', 'securevalue', 1, null, true);
|
|
84
|
-
|
|
85
|
-
// Note: We can't directly check if secure flag was set via document.cookie
|
|
86
|
-
// because secure cookies are not visible in document.cookie on http pages.
|
|
87
|
-
// This test verifies the function doesn't throw when secure=true is passed.
|
|
88
|
-
expect(true).to.equal(true);
|
|
89
|
-
|
|
90
|
-
// Clean up
|
|
91
|
-
deleteCookie('test%20secure');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should automatically set secure flag on HTTPS pages', function () {
|
|
95
|
-
// Skip if we can't modify location.protocol
|
|
96
|
-
if (!global.location) {
|
|
97
|
-
this.skip();
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
Object.defineProperty(global.location, 'protocol', {
|
|
103
|
-
value: 'https:',
|
|
104
|
-
writable: true,
|
|
105
|
-
configurable: true
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
// Browser doesn't allow protocol modification, skip test
|
|
110
|
-
this.skip();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
cookieConsent.initConsent({
|
|
115
|
-
'test https': true
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
// Create cookie without explicit secure flag - should auto-secure on HTTPS
|
|
119
|
-
cookie.create('test https', 'httpsvalue', 1);
|
|
120
|
-
|
|
121
|
-
// The cookie creation should succeed without errors
|
|
122
|
-
// On actual HTTPS, the secure flag would be set automatically
|
|
123
|
-
expect(true).to.equal(true);
|
|
124
|
-
|
|
125
|
-
// Clean up
|
|
126
|
-
deleteCookie('test%20https');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should NOT set secure flag on HTTP pages when secure param is not passed', function () {
|
|
130
|
-
// Skip if we can't modify location.protocol
|
|
131
|
-
if (!global.location) {
|
|
132
|
-
this.skip();
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
Object.defineProperty(global.location, 'protocol', {
|
|
138
|
-
value: 'http:',
|
|
139
|
-
writable: true,
|
|
140
|
-
configurable: true
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
// Browser doesn't allow protocol modification, skip test
|
|
145
|
-
this.skip();
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
cookieConsent.initConsent({
|
|
150
|
-
'test http': true
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// Create cookie without secure flag on HTTP
|
|
154
|
-
cookie.create('test http', 'httpvalue', 1);
|
|
155
|
-
|
|
156
|
-
// Cookie should be readable (not secure, so visible on HTTP)
|
|
157
|
-
expect(global.document.cookie).to.have.string('test%20http=httpvalue');
|
|
158
|
-
|
|
159
|
-
// Clean up
|
|
160
|
-
deleteCookie('test%20http');
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should handle missing global.location gracefully', function () {
|
|
164
|
-
var originalLocation = global.location;
|
|
165
|
-
|
|
166
|
-
// Temporarily remove location
|
|
167
|
-
try {
|
|
168
|
-
delete global.location;
|
|
169
|
-
}
|
|
170
|
-
catch (e) {
|
|
171
|
-
// Can't delete location in some environments, skip
|
|
172
|
-
this.skip();
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
cookieConsent.initConsent({
|
|
177
|
-
'test nolocation': true
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
// Should not throw when global.location is undefined
|
|
181
|
-
expect(function () {
|
|
182
|
-
cookie.create('test nolocation', 'value', 1);
|
|
183
|
-
}).to.not.throw();
|
|
184
|
-
|
|
185
|
-
// Restore location
|
|
186
|
-
global.location = originalLocation;
|
|
187
|
-
|
|
188
|
-
// Clean up
|
|
189
|
-
deleteCookie('test%20nolocation');
|
|
190
|
-
});
|
|
191
|
-
});
|
|
@@ -24,4 +24,23 @@ describe('lib/global', function () {
|
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
+
it('should not wrap window in a Proxy when globalObj is window even if __esModule is set', function () {
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
window.__esModule = true;
|
|
30
|
+
var result = require('../../../lib/global');
|
|
31
|
+
// When globalObj === window, the proxy branch should be skipped,
|
|
32
|
+
// so the result should be strictly equal to window.
|
|
33
|
+
expect(result).to.equal(window);
|
|
34
|
+
delete window.__esModule;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return the global object directly when __esModule is not set', function () {
|
|
39
|
+
if (typeof window !== 'undefined') {
|
|
40
|
+
delete window.__esModule;
|
|
41
|
+
var result = require('../../../lib/global');
|
|
42
|
+
expect(result).to.equal(window);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
27
46
|
});
|