@edx/cookie-policy-banner
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -7,3 +7,3 @@ 'use strict'; | ||
var _Object$freeze, _Object$freeze2; | ||
var _Object$freeze, _Object$freeze2, _Object$freeze3; | ||
@@ -16,8 +16,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var LOCALHOST = 'localhost'; | ||
var STAGE_ENVIRONMENTS = ['acceptance.edx.org', 'dev.edx.org', 'extra.edx.org', 'qa.edx.org', 'stage.edx.org']; | ||
var ACCEPTANCE = 'ACCEPTANCE'; | ||
var DEV = 'DEV'; | ||
var EXTRA = 'EXTRA'; | ||
var QA = 'QA'; | ||
var STAGE = 'STAGE'; | ||
var STAGE_ENVIRONMENTS = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, ACCEPTANCE, { baseURL: 'acceptance.edx.org', prefix: 'acceptance' }), _defineProperty(_Object$freeze, DEV, { baseURL: 'dev.edx.org', prefix: 'dev' }), _defineProperty(_Object$freeze, EXTRA, { baseURL: 'extra.edx.org', prefix: 'extra' }), _defineProperty(_Object$freeze, QA, { baseURL: 'qa.edx.org', prefix: 'qa' }), _defineProperty(_Object$freeze, STAGE, { baseURL: 'stage.edx.org', prefix: 'stage' }), _Object$freeze)); | ||
var LANGUAGE_CODES = Object.freeze([ENGLISH_IETF_TAG, SPANISH_IETF_TAG]); | ||
var LANGUAGE_CODES_TO_CONTAINER_ROLE_LABEL = Object.freeze((_Object$freeze = {}, _defineProperty(_Object$freeze, ENGLISH_IETF_TAG, 'Notice about use of cookies on edx.org.'), _defineProperty(_Object$freeze, SPANISH_IETF_TAG, 'Notice about use of cookies on edx.org.'), _Object$freeze)); | ||
var LANGUAGE_CODES_TO_CLOSE_BUTTON_LABEL = Object.freeze((_Object$freeze2 = {}, _defineProperty(_Object$freeze2, ENGLISH_IETF_TAG, 'Close the notice about use of cookies on edx.org.'), _defineProperty(_Object$freeze2, SPANISH_IETF_TAG, 'Close the notice about use of cookies on edx.org.'), _Object$freeze2)); | ||
var LANGUAGE_CODES_TO_CONTAINER_ROLE_LABEL = Object.freeze((_Object$freeze2 = {}, _defineProperty(_Object$freeze2, ENGLISH_IETF_TAG, 'Notice about use of cookies on edx.org.'), _defineProperty(_Object$freeze2, SPANISH_IETF_TAG, 'Notice about use of cookies on edx.org.'), _Object$freeze2)); | ||
var LANGUAGE_CODES_TO_CLOSE_BUTTON_LABEL = Object.freeze((_Object$freeze3 = {}, _defineProperty(_Object$freeze3, ENGLISH_IETF_TAG, 'Close the notice about use of cookies on edx.org.'), _defineProperty(_Object$freeze3, SPANISH_IETF_TAG, 'Close the notice about use of cookies on edx.org.'), _Object$freeze3)); | ||
@@ -43,4 +48,4 @@ var getPolicyHTML = function getPolicyHTML(tag) { | ||
exports.getPolicyHTML = getPolicyHTML; | ||
exports.STAGE_ENVIRONMENTS = STAGE_ENVIRONMENTS; | ||
exports.LOCALHOST = LOCALHOST; | ||
exports.COOKIE_POLICY_VIEWED_NAME = COOKIE_POLICY_VIEWED_NAME; | ||
exports.COOKIE_POLICY_VIEWED_NAME = COOKIE_POLICY_VIEWED_NAME; | ||
exports.STAGE_ENVIRONMENTS = STAGE_ENVIRONMENTS; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.isStage = exports.firstMatchingStageEnvironment = exports.isLocalhost = exports.hasViewedCookieBanner = exports.createHasViewedCookieBanner = exports.getLanguageCode = undefined; | ||
exports.isProduction = exports.getCookieCreationData = exports.firstMatchingStageEnvironment = exports.hasViewedCookieBanner = exports.createHasViewedCookieBanner = exports.getLanguageCode = undefined; | ||
@@ -17,13 +17,9 @@ var _universalCookie = require('universal-cookie'); | ||
var isLocalhost = function isLocalhost() { | ||
return window.location.hostname.indexOf(_constants.LOCALHOST) >= 0; | ||
}; | ||
var firstMatchingStageEnvironment = function firstMatchingStageEnvironment() { | ||
var matches = _constants.STAGE_ENVIRONMENTS.filter(function (environment) { | ||
return window.location.hostname.indexOf(environment) >= 0; | ||
var matches = Object.keys(_constants.STAGE_ENVIRONMENTS).filter(function (key) { | ||
return window.location.hostname.indexOf(_constants.STAGE_ENVIRONMENTS[key].baseURL) >= 0; | ||
}); | ||
if (matches.length > 0) { | ||
return matches[0]; | ||
return _constants.STAGE_ENVIRONMENTS[matches[0]]; | ||
} | ||
@@ -34,12 +30,48 @@ | ||
var isStage = function isStage() { | ||
return !!firstMatchingStageEnvironment(); | ||
// Setting path to '/' to be apply to all subdomains | ||
// Setting maxAge to 2^31 -1 | ||
// because Number.SAFE_MAX_INTEGER does not get processed properly by the browser | ||
// nor does the max Date defined in http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.1 | ||
var buildCookieCreationData = function buildCookieCreationData(_ref) { | ||
var prefix = _ref.prefix, | ||
domain = _ref.domain; | ||
return { | ||
cookieName: prefix + '-' + _constants.COOKIE_POLICY_VIEWED_NAME, | ||
domain: domain, | ||
path: '/', | ||
maxAge: 2147483647 | ||
}; | ||
}; | ||
var isProduction = function isProduction() { | ||
var host = window.location.hostname; | ||
var getCookieCreationData = function getCookieCreationData() { | ||
if (window.location.hostname.indexOf(_constants.LOCALHOST) >= 0) { | ||
return buildCookieCreationData({ | ||
prefix: _constants.LOCALHOST, | ||
domain: _constants.LOCALHOST | ||
}); | ||
} | ||
return !isStage() && host.indexOf('.edx.org') !== -1; | ||
var stageEnvironment = firstMatchingStageEnvironment(); | ||
if (stageEnvironment) { | ||
return buildCookieCreationData({ | ||
prefix: stageEnvironment.prefix, | ||
domain: '.' + stageEnvironment.baseURL | ||
}); | ||
} | ||
if (window.location.hostname.indexOf('.edx.org') >= 0) { | ||
return buildCookieCreationData({ | ||
prefix: 'prod', | ||
domain: '.edx.org' | ||
}); | ||
} | ||
return null; | ||
}; | ||
var isProduction = function isProduction() { | ||
return !firstMatchingStageEnvironment() && window.location.hostname.indexOf(_constants.LOCALHOST) < 0 && window.location.hostname.indexOf('.edx.org') >= 0; | ||
}; | ||
var getLanguageCode = function getLanguageCode() { | ||
@@ -57,21 +89,12 @@ var cookie = new _universalCookie2.default('edx.org'); | ||
var createHasViewedCookieBanner = function createHasViewedCookieBanner() { | ||
var path = '/'; | ||
var cookieCreationData = getCookieCreationData(); | ||
// Setting maxAge to 2^31 -1 | ||
// because Number.SAFE_MAX_INTEGER does not get processed properly by the browser | ||
// nor does the max Date defined in http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.1 | ||
var maxAge = 2147483647; | ||
if (isLocalhost()) { | ||
return new _universalCookie2.default().set(_constants.COOKIE_POLICY_VIEWED_NAME, true, { domain: _constants.LOCALHOST, path: path, maxAge: maxAge }); | ||
if (!!cookieCreationData && !!cookieCreationData.cookieName && !!cookieCreationData.domain && !!cookieCreationData.path && !!cookieCreationData.maxAge) { | ||
return new _universalCookie2.default().set(cookieCreationData.cookieName, true, { | ||
domain: cookieCreationData.domain, | ||
path: cookieCreationData.path, | ||
maxAge: cookieCreationData.maxAge | ||
}); | ||
} | ||
if (isStage()) { | ||
return new _universalCookie2.default().set(_constants.COOKIE_POLICY_VIEWED_NAME, true, { domain: '.' + firstMatchingStageEnvironment(), path: path, maxAge: maxAge }); | ||
} | ||
if (isProduction()) { | ||
return new _universalCookie2.default().set(_constants.COOKIE_POLICY_VIEWED_NAME, true, { domain: '.edx.org', path: path, maxAge: maxAge }); | ||
} | ||
return false; | ||
@@ -81,3 +104,4 @@ }; | ||
var hasViewedCookieBanner = function hasViewedCookieBanner() { | ||
var cookie = new _universalCookie2.default().get(_constants.COOKIE_POLICY_VIEWED_NAME); | ||
var cookieCreationData = getCookieCreationData(); | ||
var cookie = new _universalCookie2.default().get(cookieCreationData.cookieName); | ||
@@ -90,4 +114,4 @@ return !!cookie; | ||
exports.hasViewedCookieBanner = hasViewedCookieBanner; | ||
exports.isLocalhost = isLocalhost; | ||
exports.firstMatchingStageEnvironment = firstMatchingStageEnvironment; | ||
exports.isStage = isStage; | ||
exports.getCookieCreationData = getCookieCreationData; | ||
exports.isProduction = isProduction; |
{ | ||
"name": "@edx/cookie-policy-banner", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "The edX cookie policy banner component implemented in React.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55734
343