@britannica/cam-utils
Advanced tools
Comparing version 3.0.0-beta.3 to 3.0.0-beta.4
@@ -11,3 +11,3 @@ 'use strict'; | ||
const CAM_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_EXPIRATION_DAYS = 365; | ||
@@ -20,2 +20,4 @@ const CAM_LOGIN_REDIRECT_URL_COOKIE = 'CAMLoginRedirectUrl'; | ||
let cookieDomain = CAM_DEFAULT_COOKIE_DOMAIN; | ||
const Environment = { | ||
@@ -52,2 +54,3 @@ DEV: 'dev', | ||
* @param {number} expires | ||
* @param {string} domain | ||
* @returns {object} | ||
@@ -58,8 +61,14 @@ */ | ||
env = Environment.DEV, | ||
{ secure = false, expires = CAM_DEFAULT_EXPIRATION_DAYS } = {} | ||
{ | ||
secure = window.location.protocol === 'https:', | ||
expires = CAM_DEFAULT_EXPIRATION_DAYS, | ||
domain = CAM_DEFAULT_COOKIE_DOMAIN, | ||
} = {} | ||
) { | ||
if (!Object.values(Environment).includes(env)) { | ||
throw new Error(`Unknown environment: ${env}`); | ||
throw new Error(`Unknown environment: "${env}"`); | ||
} | ||
cookieDomain = domain; | ||
return { | ||
@@ -70,3 +79,3 @@ ...authConfigurations[env], | ||
expires, | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain, | ||
}, | ||
@@ -84,3 +93,3 @@ }; | ||
Cookies__default['default'].set(cookie, value, { | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain: cookieDomain, | ||
expires: CAM_DEFAULT_EXPIRATION_DAYS, | ||
@@ -118,3 +127,3 @@ }); | ||
function clearRedirectUrl(type) { | ||
Cookies__default['default'].remove(type, { domain: CAM_COOKIE_DOMAIN }); | ||
Cookies__default['default'].remove(type, { domain: cookieDomain }); | ||
} | ||
@@ -151,6 +160,6 @@ | ||
.filter((key) => key.startsWith('CognitoIdentityServiceProvider.') || key === CAM_LEGACY_AUTH_COOKIE) | ||
.forEach((cookie) => Cookies__default['default'].remove(cookie, { domain: CAM_COOKIE_DOMAIN })); | ||
.forEach((cookie) => Cookies__default['default'].remove(cookie, { domain: cookieDomain })); | ||
} | ||
exports.CAM_COOKIE_DOMAIN = CAM_COOKIE_DOMAIN; | ||
exports.CAM_DEFAULT_COOKIE_DOMAIN = CAM_DEFAULT_COOKIE_DOMAIN; | ||
exports.CAM_DEFAULT_EXPIRATION_DAYS = CAM_DEFAULT_EXPIRATION_DAYS; | ||
@@ -168,3 +177,4 @@ exports.CAM_LEGACY_AUTH_COOKIE = CAM_LEGACY_AUTH_COOKIE; | ||
exports.getRedirectUrl = getRedirectUrl; | ||
exports.setCookie = setCookie; | ||
exports.setProductName = setProductName; | ||
exports.setRedirectUrl = setRedirectUrl; |
import Cookies from 'js-cookie'; | ||
const CAM_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_EXPIRATION_DAYS = 365; | ||
@@ -11,2 +11,4 @@ const CAM_LOGIN_REDIRECT_URL_COOKIE = 'CAMLoginRedirectUrl'; | ||
let cookieDomain = CAM_DEFAULT_COOKIE_DOMAIN; | ||
const Environment = { | ||
@@ -43,2 +45,3 @@ DEV: 'dev', | ||
* @param {number} expires | ||
* @param {string} domain | ||
* @returns {object} | ||
@@ -49,8 +52,14 @@ */ | ||
env = Environment.DEV, | ||
{ secure = false, expires = CAM_DEFAULT_EXPIRATION_DAYS } = {} | ||
{ | ||
secure = window.location.protocol === 'https:', | ||
expires = CAM_DEFAULT_EXPIRATION_DAYS, | ||
domain = CAM_DEFAULT_COOKIE_DOMAIN, | ||
} = {} | ||
) { | ||
if (!Object.values(Environment).includes(env)) { | ||
throw new Error(`Unknown environment: ${env}`); | ||
throw new Error(`Unknown environment: "${env}"`); | ||
} | ||
cookieDomain = domain; | ||
return { | ||
@@ -61,3 +70,3 @@ ...authConfigurations[env], | ||
expires, | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain, | ||
}, | ||
@@ -75,3 +84,3 @@ }; | ||
Cookies.set(cookie, value, { | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain: cookieDomain, | ||
expires: CAM_DEFAULT_EXPIRATION_DAYS, | ||
@@ -109,3 +118,3 @@ }); | ||
function clearRedirectUrl(type) { | ||
Cookies.remove(type, { domain: CAM_COOKIE_DOMAIN }); | ||
Cookies.remove(type, { domain: cookieDomain }); | ||
} | ||
@@ -142,5 +151,5 @@ | ||
.filter((key) => key.startsWith('CognitoIdentityServiceProvider.') || key === CAM_LEGACY_AUTH_COOKIE) | ||
.forEach((cookie) => Cookies.remove(cookie, { domain: CAM_COOKIE_DOMAIN })); | ||
.forEach((cookie) => Cookies.remove(cookie, { domain: cookieDomain })); | ||
} | ||
export { CAM_COOKIE_DOMAIN, CAM_DEFAULT_EXPIRATION_DAYS, CAM_LEGACY_AUTH_COOKIE, CAM_LOGIN_REDIRECT_URL_COOKIE, CAM_LOGOUT_REDIRECT_URL_COOKIE, CAM_PRODUCT_NAME_COOKIE, CAM_SIGN_UP_REDIRECT_URL_COOKIE, Environment, clearAuthCookies, clearRedirectUrl, getAuthConfiguration, getProductName, getRedirectUrl, setProductName, setRedirectUrl }; | ||
export { CAM_DEFAULT_COOKIE_DOMAIN, CAM_DEFAULT_EXPIRATION_DAYS, CAM_LEGACY_AUTH_COOKIE, CAM_LOGIN_REDIRECT_URL_COOKIE, CAM_LOGOUT_REDIRECT_URL_COOKIE, CAM_PRODUCT_NAME_COOKIE, CAM_SIGN_UP_REDIRECT_URL_COOKIE, Environment, clearAuthCookies, clearRedirectUrl, getAuthConfiguration, getProductName, getRedirectUrl, setCookie, setProductName, setRedirectUrl }; |
@@ -175,3 +175,3 @@ (function (global, factory) { | ||
const CAM_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_COOKIE_DOMAIN = '.britannica.com'; | ||
const CAM_DEFAULT_EXPIRATION_DAYS = 365; | ||
@@ -184,2 +184,4 @@ const CAM_LOGIN_REDIRECT_URL_COOKIE = 'CAMLoginRedirectUrl'; | ||
let cookieDomain = CAM_DEFAULT_COOKIE_DOMAIN; | ||
const Environment = { | ||
@@ -216,2 +218,3 @@ DEV: 'dev', | ||
* @param {number} expires | ||
* @param {string} domain | ||
* @returns {object} | ||
@@ -222,8 +225,14 @@ */ | ||
env = Environment.DEV, | ||
{ secure = false, expires = CAM_DEFAULT_EXPIRATION_DAYS } = {} | ||
{ | ||
secure = window.location.protocol === 'https:', | ||
expires = CAM_DEFAULT_EXPIRATION_DAYS, | ||
domain = CAM_DEFAULT_COOKIE_DOMAIN, | ||
} = {} | ||
) { | ||
if (!Object.values(Environment).includes(env)) { | ||
throw new Error(`Unknown environment: ${env}`); | ||
throw new Error(`Unknown environment: "${env}"`); | ||
} | ||
cookieDomain = domain; | ||
return { | ||
@@ -234,3 +243,3 @@ ...authConfigurations[env], | ||
expires, | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain, | ||
}, | ||
@@ -248,3 +257,3 @@ }; | ||
js_cookie.set(cookie, value, { | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain: cookieDomain, | ||
expires: CAM_DEFAULT_EXPIRATION_DAYS, | ||
@@ -282,3 +291,3 @@ }); | ||
function clearRedirectUrl(type) { | ||
js_cookie.remove(type, { domain: CAM_COOKIE_DOMAIN }); | ||
js_cookie.remove(type, { domain: cookieDomain }); | ||
} | ||
@@ -315,6 +324,6 @@ | ||
.filter((key) => key.startsWith('CognitoIdentityServiceProvider.') || key === CAM_LEGACY_AUTH_COOKIE) | ||
.forEach((cookie) => js_cookie.remove(cookie, { domain: CAM_COOKIE_DOMAIN })); | ||
.forEach((cookie) => js_cookie.remove(cookie, { domain: cookieDomain })); | ||
} | ||
exports.CAM_COOKIE_DOMAIN = CAM_COOKIE_DOMAIN; | ||
exports.CAM_DEFAULT_COOKIE_DOMAIN = CAM_DEFAULT_COOKIE_DOMAIN; | ||
exports.CAM_DEFAULT_EXPIRATION_DAYS = CAM_DEFAULT_EXPIRATION_DAYS; | ||
@@ -332,2 +341,3 @@ exports.CAM_LEGACY_AUTH_COOKIE = CAM_LEGACY_AUTH_COOKIE; | ||
exports.getRedirectUrl = getRedirectUrl; | ||
exports.setCookie = setCookie; | ||
exports.setProductName = setProductName; | ||
@@ -334,0 +344,0 @@ exports.setRedirectUrl = setRedirectUrl; |
{ | ||
"name": "@britannica/cam-utils", | ||
"version": "3.0.0-beta.3", | ||
"version": "3.0.0-beta.4", | ||
"description": "Consumer Account Management (CAM) auth configuration and utilities", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/britannica/cam-utils.git", |
import Cookies from 'js-cookie'; | ||
export const CAM_COOKIE_DOMAIN = '.britannica.com'; | ||
export const CAM_DEFAULT_COOKIE_DOMAIN = '.britannica.com'; | ||
export const CAM_DEFAULT_EXPIRATION_DAYS = 365; | ||
@@ -11,2 +11,4 @@ export const CAM_LOGIN_REDIRECT_URL_COOKIE = 'CAMLoginRedirectUrl'; | ||
let cookieDomain = CAM_DEFAULT_COOKIE_DOMAIN; | ||
export const Environment = { | ||
@@ -43,2 +45,3 @@ DEV: 'dev', | ||
* @param {number} expires | ||
* @param {string} domain | ||
* @returns {object} | ||
@@ -49,8 +52,14 @@ */ | ||
env = Environment.DEV, | ||
{ secure = false, expires = CAM_DEFAULT_EXPIRATION_DAYS } = {} | ||
{ | ||
secure = window.location.protocol === 'https:', | ||
expires = CAM_DEFAULT_EXPIRATION_DAYS, | ||
domain = CAM_DEFAULT_COOKIE_DOMAIN, | ||
} = {} | ||
) { | ||
if (!Object.values(Environment).includes(env)) { | ||
throw new Error(`Unknown environment: ${env}`); | ||
throw new Error(`Unknown environment: "${env}"`); | ||
} | ||
cookieDomain = domain; | ||
return { | ||
@@ -61,3 +70,3 @@ ...authConfigurations[env], | ||
expires, | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain, | ||
}, | ||
@@ -73,5 +82,5 @@ }; | ||
function setCookie(cookie, value) { | ||
export function setCookie(cookie, value) { | ||
Cookies.set(cookie, value, { | ||
domain: CAM_COOKIE_DOMAIN, | ||
domain: cookieDomain, | ||
expires: CAM_DEFAULT_EXPIRATION_DAYS, | ||
@@ -109,3 +118,3 @@ }); | ||
export function clearRedirectUrl(type) { | ||
Cookies.remove(type, { domain: CAM_COOKIE_DOMAIN }); | ||
Cookies.remove(type, { domain: cookieDomain }); | ||
} | ||
@@ -142,3 +151,3 @@ | ||
.filter((key) => key.startsWith('CognitoIdentityServiceProvider.') || key === CAM_LEGACY_AUTH_COOKIE) | ||
.forEach((cookie) => Cookies.remove(cookie, { domain: CAM_COOKIE_DOMAIN })); | ||
.forEach((cookie) => Cookies.remove(cookie, { domain: cookieDomain })); | ||
} |
25001
694