react-cookie-kit
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -25,2 +25,5 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
import { animations, consentsSources, consentStatuses, cookieTypes, positions } from "xcoobee-cookie-kit-core/src/configs"; | ||
import { clearAccessToken } from "xcoobee-cookie-kit-core/src/AccessTokenManager"; | ||
import { clearLocale, clearCountryCode } from "xcoobee-cookie-kit-core/src/LocaleManager"; | ||
import cookieConsentsCache from "xcoobee-cookie-kit-core/src/cookieConsentsCache"; | ||
import CookieConsentShape from "./lib/CookieConsentShape"; | ||
@@ -30,2 +33,19 @@ import CookieKitPopup from "./CookieKitPopup"; | ||
function reset() { | ||
clearAccessToken(); | ||
clearLocale(); | ||
clearCountryCode(); | ||
cookieConsentsCache.clear(); | ||
window.location.reload(); | ||
} | ||
function ResetButton() { | ||
var className = "xb-cookie-kit__button xb-cookie-kit__reset-button"; | ||
return React.createElement("button", { | ||
type: "button", | ||
className: className, | ||
onClick: reset | ||
}, "Reset"); | ||
} | ||
var CookieKit = | ||
@@ -249,2 +269,3 @@ /*#__PURE__*/ | ||
termsUrl = _this$props2.termsUrl, | ||
testMode = _this$props2.testMode, | ||
textMessage = _this$props2.textMessage; | ||
@@ -258,3 +279,4 @@ var _this$state = this.state, | ||
var renderPopup = isOpen || consentsSource === "unknown" && !hasClosed; | ||
var renderButton = !renderPopup; // console.log("animation:", animation); | ||
var renderButton = !renderPopup; | ||
var renderResetButton = testMode && (accessToken || cookieConsentsCache.get()); // console.log("animation:", animation); | ||
// console.log("consentsSource:", consentsSource); | ||
@@ -290,3 +312,3 @@ // console.log("hasClosed:", hasClosed); | ||
className: cx("".concat(BLOCK, "__cookie-icon"), "".concat(BLOCK, "__cookie-icon--").concat(animation), _defineProperty({}, "".concat(BLOCK, "__pulsing"), pulsing)) | ||
}))); | ||
})), renderResetButton && React.createElement(ResetButton, null)); | ||
} | ||
@@ -293,0 +315,0 @@ }]); |
@@ -27,2 +27,4 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
import CookieConsentsManager from "xcoobee-cookie-kit-core/src/CookieConsentsManager"; | ||
import { getCountryCode, saveCountryCode } from "xcoobee-cookie-kit-core/src/LocaleManager"; | ||
import CookieManager from "xcoobee-cookie-kit-core/src/CookieManager"; | ||
import NotAuthorizedError from "xcoobee-cookie-kit-core/src/NotAuthorizedError"; | ||
@@ -35,2 +37,8 @@ import { xckDomain } from "./configs"; | ||
function callCookieManagingFunctions(consentSettings) { | ||
CookieManager.xckClearCookies(consentSettings); | ||
CookieManager.xckHandleXbeeScriptTags(consentSettings); | ||
CookieManager.xckHandleXbeeCookieTags(consentSettings); | ||
} | ||
function callCookieHandler(cookieHandler, consentSettings) { | ||
@@ -84,17 +92,2 @@ if (typeof cookieHandler === "string") { | ||
function refresh() { | ||
clearAccessToken(); | ||
cookieConsentsCache.clear(); | ||
window.location.reload(); | ||
} | ||
function RefreshButton() { | ||
var className = "xb-cookie-kit__button xb-cookie-kit__refresh-button"; | ||
return React.createElement("button", { | ||
type: "button", | ||
className: className, | ||
onClick: refresh | ||
}, "Refresh"); | ||
} | ||
var CookieKitContainer = | ||
@@ -159,15 +152,53 @@ /*#__PURE__*/ | ||
cookieConsents: null, | ||
countryCode: null, | ||
countryCode: getCountryCode(), | ||
initializing: true | ||
}; | ||
CookieConsentsManager.fetchCountryCode().catch(function (error) { | ||
// console.log("CookieKitContainer#constructor#fetchCountryCode#catch"); | ||
console.error(error); | ||
return null; | ||
}).then(function (countryCode) { | ||
// console.log("CookieKitContainer#constructor#fetchCountryCode#then"); | ||
_this.setState({ | ||
countryCode: countryCode | ||
}); | ||
if (props.cssAutoLoad) { | ||
var linkDom = document.createElement("link"); | ||
linkDom.setAttribute("rel", "stylesheet"); | ||
linkDom.setAttribute("href", "".concat(xckDomain, "/").concat(cssHref)); | ||
document.head.appendChild(linkDom); | ||
} | ||
return _this; | ||
} | ||
_createClass(CookieKitContainer, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
if (this.state.countryCode) { | ||
this.getCookieConsents(); | ||
} else { | ||
CookieConsentsManager.fetchCountryCode().catch(function (error) { | ||
// console.log("CookieKitContainer#componentDidMount#fetchCountryCode#catch"); | ||
console.error(error); | ||
return null; | ||
}).then(function (countryCode) { | ||
saveCountryCode(countryCode); | ||
_this2.setState({ | ||
countryCode: countryCode | ||
}); | ||
_this2.getCookieConsents(); | ||
}).catch(handleErrors); | ||
} | ||
} // componentDidUpdate(prevProps, prevState) { | ||
// console.log("CookieKitContainer#componentDidUpdate"); | ||
// if (this.props !== prevProps) { | ||
// console.log("props changed:"); | ||
// console.dir(this.props); | ||
// } | ||
// if (this.state !== prevState) { | ||
// console.log("state changed:"); | ||
// console.dir(this.state); | ||
// } | ||
// } | ||
}, { | ||
key: "getCookieConsents", | ||
value: function getCookieConsents() { | ||
var cachedCookieConsents = cookieConsentsCache.get(); | ||
@@ -177,45 +208,17 @@ | ||
// console.log("Using cached cookie consents!"); | ||
_this.setCookieConsents("cached", cachedCookieConsents); | ||
this.setCookieConsents("cached", cachedCookieConsents); | ||
return; | ||
} | ||
var campaignReference = _this.props.campaignReference; | ||
var campaignReference = this.props.campaignReference; | ||
var isConnected = !!campaignReference; | ||
var accessToken = _this.state.accessToken; | ||
var accessToken = this.state.accessToken; | ||
if (isConnected && accessToken) { | ||
_this.resolveConnectedCookieConsents().catch(handleErrors); | ||
this.resolveConnectedCookieConsents().catch(handleErrors); | ||
} else { | ||
_this.fallBackToHostDefaults(); | ||
this.fallBackToHostDefaults(); | ||
} | ||
}).catch(handleErrors); | ||
if (props.cssAutoLoad) { | ||
var linkDom = document.createElement("link"); | ||
linkDom.setAttribute("rel", "stylesheet"); | ||
linkDom.setAttribute("href", "".concat(xckDomain, "/").concat(cssHref)); | ||
document.head.appendChild(linkDom); | ||
} | ||
return _this; | ||
} // componentDidMount() { | ||
// // console.log("CookieKitContainer#componentDidMount"); | ||
// // console.dir(this.props); | ||
// // console.dir(this.state); | ||
// } | ||
// componentDidUpdate(prevProps, prevState) { | ||
// console.log("CookieKitContainer#componentDidUpdate"); | ||
// if (this.props !== prevProps) { | ||
// console.log("props changed:"); | ||
// console.dir(this.props); | ||
// } | ||
// if (this.state !== prevState) { | ||
// console.log("state changed:"); | ||
// console.dir(this.state); | ||
// } | ||
// } | ||
_createClass(CookieKitContainer, [{ | ||
}, { | ||
key: "getConsentStatus", | ||
@@ -246,2 +249,4 @@ value: function getConsentStatus() { | ||
value: function setCookieConsents(consentsSource, cookieConsents) { | ||
var _this3 = this; | ||
// console.log("CookieKitContainer#setCookieConsents"); | ||
@@ -255,4 +260,5 @@ cookieConsentsCache.put(cookieConsents); | ||
initializing: false | ||
}, function () { | ||
return _this3.callCallbacks(cookieConsents); | ||
}); | ||
this.callCallbacks(cookieConsents); | ||
} | ||
@@ -270,2 +276,3 @@ }, { | ||
}); | ||
callCookieManagingFunctions(consentSettings); | ||
@@ -313,3 +320,3 @@ if (cookieHandler) { | ||
value: function resolveConnectedCookieConsents() { | ||
var _this2 = this; | ||
var _this4 = this; | ||
@@ -330,3 +337,3 @@ // console.log("CookieKitContainer#resolveConnectedCookieConsents"); | ||
if (usersSavedCookieConsents) { | ||
_this2.setCookieConsents("usersSaved", usersSavedCookieConsents); | ||
_this4.setCookieConsents("usersSaved", usersSavedCookieConsents); | ||
@@ -347,3 +354,3 @@ return; | ||
if (crowdAiCookieConsents) { | ||
_this2.setCookieConsents("crowdAi", crowdAiCookieConsents); | ||
_this4.setCookieConsents("crowdAi", crowdAiCookieConsents); | ||
@@ -356,3 +363,3 @@ return; | ||
if (usersDefaultCookieConsents) { | ||
_this2.setCookieConsents("usersDefaults", usersDefaultCookieConsents); | ||
_this4.setCookieConsents("usersDefaults", usersDefaultCookieConsents); | ||
@@ -362,7 +369,7 @@ return; | ||
_this2.fallBackToHostDefaults(); | ||
_this4.fallBackToHostDefaults(); | ||
}); | ||
}); | ||
} else { | ||
_this2.fallBackToHostDefaults(); | ||
_this4.fallBackToHostDefaults(); | ||
} | ||
@@ -381,3 +388,2 @@ }); | ||
hideOnComplete = _this$props3.hideOnComplete, | ||
position = _this$props3.position, | ||
privacyUrl = _this$props3.privacyUrl, | ||
@@ -394,3 +400,3 @@ requestDataTypes = _this$props3.requestDataTypes, | ||
initializing = _this$state2.initializing; | ||
var renderRefreshButton = testMode && (accessToken || cookieConsentsCache.get()); // console.log("initializing:", initializing); | ||
var position = positions.includes(this.props.position) ? this.props.position : positions[0]; // console.log("initializing:", initializing); | ||
@@ -414,4 +420,5 @@ return React.createElement(React.Fragment, null, !initializing && React.createElement(React.Fragment, null, React.createElement(CookieKit, { | ||
termsUrl: termsUrl, | ||
testMode: testMode, | ||
textMessage: textMessage | ||
}), renderRefreshButton && React.createElement(RefreshButton, null))); | ||
}))); | ||
} | ||
@@ -418,0 +425,0 @@ }]); |
@@ -28,2 +28,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
import renderText from "xcoobee-cookie-kit-core/src/renderText"; | ||
import { getLocale, saveLocale } from "xcoobee-cookie-kit-core/src/LocaleManager"; | ||
import closeIcon from "./assets/close-icon.svg"; | ||
@@ -64,2 +65,4 @@ import xbLogo from "./assets/xcoobee-logo.svg"; | ||
}); | ||
saveLocale(locale); | ||
}); | ||
@@ -122,3 +125,3 @@ | ||
consentSettings: _consentSettings, | ||
selectedLocale: "EN", | ||
selectedLocale: getLocale() || "EN", | ||
isShown: false | ||
@@ -125,0 +128,0 @@ }; |
{ | ||
"name": "react-cookie-kit", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Cookie Consent Management for Websites using ReactJS.", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"react-country-flag": "^1.0.1", | ||
"xcoobee-cookie-kit-core": "^1.0.8" | ||
"xcoobee-cookie-kit-core": "^1.0.9" | ||
}, | ||
@@ -38,0 +38,0 @@ "devDependencies": { |
@@ -14,2 +14,6 @@ # React Cookie Kit | ||
## Video | ||
[Cookie Kit Tutorial](https://www.youtube.com/watch?v=X2DNrckHLBI) | ||
## The XcooBee Cookie Kit | ||
@@ -16,0 +20,0 @@ |
Sorry, the diff of this file is not supported yet
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
151476
1517
88