@rudderstack/analytics-js-cookies
Advanced tools
Comparing version 0.3.14 to 0.4.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [0.4.0](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.14...@rudderstack/analytics-js-cookies@0.4.0) (2024-11-08) | ||
### Dependency Updates | ||
* `@rudderstack/analytics-js-common` updated to version `3.12.0` | ||
### Features | ||
* sanitize input data ([#1902](https://github.com/rudderlabs/rudder-sdk-js/issues/1902)) ([b71c44a](https://github.com/rudderlabs/rudder-sdk-js/commit/b71c44ae61f6c35cadc6523b918e1a574e32bc23)) | ||
## [0.3.14](https://github.com/rudderlabs/rudder-sdk-js/compare/@rudderstack/analytics-js-cookies@0.3.13...@rudderstack/analytics-js-cookies@0.3.14) (2024-11-07) | ||
@@ -7,0 +17,0 @@ |
@@ -88,25 +88,11 @@ (function (global, factory) { | ||
} | ||
function _typeof(o) { | ||
"@babel/helpers - typeof"; | ||
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { | ||
return typeof o; | ||
} : function (o) { | ||
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; | ||
}, _typeof(o); | ||
} | ||
var getCircularReplacer=function getCircularReplacer(excludeNull,excludeKeys,logger){var ancestors=[];// Here we do not want to use arrow function to use "this" in function context | ||
// eslint-disable-next-line func-names | ||
return function(key,value){if(_typeof(value)!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent. | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore-next-line | ||
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){return '[Circular Reference]';}ancestors.push(value);return value;};};/** | ||
/** | ||
* Utility method for JSON stringify object excluding null values & circular references | ||
* | ||
* @param {*} value input | ||
* @param {boolean} excludeNull if it should exclude nul or not | ||
* @param {function} logger optional logger methods for warning | ||
* @param {*} value input value | ||
* @param {boolean} excludeNull optional flag to exclude null values | ||
* @param {string[]} excludeKeys optional array of keys to exclude | ||
* @returns string | ||
*/var stringifyWithoutCircular=function stringifyWithoutCircular(value,excludeNull,excludeKeys,logger){try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){return null;}}; | ||
*/var stringifyData=function stringifyData(value){var excludeNull=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var excludeKeys=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];return JSON.stringify(value,function(key,value){if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;});}; | ||
@@ -134,3 +120,3 @@ var userIdKey='rl_user_id';var userTraitsKey='rl_trait';var anonymousUserIdKey='rl_anonymous_id';var groupIdKey='rl_group_id';var groupTraitsKey='rl_group_trait';var pageInitialReferrerKey='rl_page_init_referrer';var pageInitialReferringDomainKey='rl_page_init_referring_domain';var sessionInfoKey='rl_session';var authTokenKey='rl_auth_token';var COOKIE_KEYS={userId:userIdKey,userTraits:userTraitsKey,anonymousId:anonymousUserIdKey,groupId:groupIdKey,groupTraits:groupTraitsKey,initialReferrer:pageInitialReferrerKey,initialReferringDomain:pageInitialReferringDomainKey,sessionInfo:sessionInfoKey,authToken:authTokenKey};var ENCRYPTION_PREFIX_V3='RS_ENC_v3_'; | ||
var getEncryptedValueInternal=function getEncryptedValueInternal(value,encryptFn,debug){var fallbackValue=null;try{var strValue=stringifyWithoutCircular(value,false);if(isNull(strValue)){return null;}return encryptFn(strValue);}catch(err){if(debug){console.error('Error occurred during encryption: ',err);}return fallbackValue;}};var getDecryptedValueInternal=function getDecryptedValueInternal(value,decryptFn,debug){var fallbackValue=null;try{var decryptedVal=decryptFn(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){if(debug){console.error('Error occurred during decryption: ',err);}return fallbackValue;}};var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};var getEncryptedValueBrowser=function getEncryptedValueBrowser(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getEncryptedValueInternal(value,encryptBrowser,debug);};var getDecryptedValueBrowser=function getDecryptedValueBrowser(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getDecryptedValueInternal(value,decryptBrowser,debug);};var getDecryptedCookieBrowser=function getDecryptedCookieBrowser(cookieKey){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValueBrowser(cookie(cookieKey),debug);}return null;};var encrypt=function encrypt(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(Buffer.from(value,'utf-8').toString('base64'));};var decrypt=function decrypt(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return Buffer.from(value.substring(ENCRYPTION_PREFIX_V3.length),'base64').toString('utf-8');}return value;};var getDecryptedValue=function getDecryptedValue(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getDecryptedValueInternal(value,decrypt,debug);};var getEncryptedValue=function getEncryptedValue(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getEncryptedValueInternal(value,encrypt,debug);}; | ||
var getEncryptedValueInternal=function getEncryptedValueInternal(value,encryptFn,debug){var fallbackValue=null;try{var strValue=stringifyData(value,false);if(isNull(strValue)){return null;}return encryptFn(strValue);}catch(err){if(debug){console.error('Error occurred during encryption: ',err);}return fallbackValue;}};var getDecryptedValueInternal=function getDecryptedValueInternal(value,decryptFn,debug){var fallbackValue=null;try{var decryptedVal=decryptFn(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){if(debug){console.error('Error occurred during decryption: ',err);}return fallbackValue;}};var encryptBrowser=function encryptBrowser(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(toBase64(value));};var decryptBrowser=function decryptBrowser(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};var getEncryptedValueBrowser=function getEncryptedValueBrowser(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getEncryptedValueInternal(value,encryptBrowser,debug);};var getDecryptedValueBrowser=function getDecryptedValueBrowser(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getDecryptedValueInternal(value,decryptBrowser,debug);};var getDecryptedCookieBrowser=function getDecryptedCookieBrowser(cookieKey){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValueBrowser(cookie(cookieKey),debug);}return null;};var encrypt=function encrypt(value){return "".concat(ENCRYPTION_PREFIX_V3).concat(Buffer.from(value,'utf-8').toString('base64'));};var decrypt=function decrypt(value){if(value!==null&&value!==void 0&&value.startsWith(ENCRYPTION_PREFIX_V3)){return Buffer.from(value.substring(ENCRYPTION_PREFIX_V3.length),'base64').toString('utf-8');}return value;};var getDecryptedValue=function getDecryptedValue(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getDecryptedValueInternal(value,decrypt,debug);};var getEncryptedValue=function getEncryptedValue(value){var debug=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return getEncryptedValueInternal(value,encrypt,debug);}; | ||
@@ -137,0 +123,0 @@ exports.anonymousUserIdKey = anonymousUserIdKey; |
@@ -45,15 +45,10 @@ (function (global, factory) { | ||
const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context | ||
// eslint-disable-next-line func-names | ||
return function(key,value){if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent. | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore-next-line | ||
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){return '[Circular Reference]';}ancestors.push(value);return value;};};/** | ||
/** | ||
* Utility method for JSON stringify object excluding null values & circular references | ||
* | ||
* @param {*} value input | ||
* @param {boolean} excludeNull if it should exclude nul or not | ||
* @param {function} logger optional logger methods for warning | ||
* @param {*} value input value | ||
* @param {boolean} excludeNull optional flag to exclude null values | ||
* @param {string[]} excludeKeys optional array of keys to exclude | ||
* @returns string | ||
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){return null;}}; | ||
*/const stringifyData=(value,excludeNull=true,excludeKeys=[])=>JSON.stringify(value,(key,value)=>{if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;}); | ||
@@ -81,3 +76,3 @@ const userIdKey='rl_user_id';const userTraitsKey='rl_trait';const anonymousUserIdKey='rl_anonymous_id';const groupIdKey='rl_group_id';const groupTraitsKey='rl_group_trait';const pageInitialReferrerKey='rl_page_init_referrer';const pageInitialReferringDomainKey='rl_page_init_referring_domain';const sessionInfoKey='rl_session';const authTokenKey='rl_auth_token';const COOKIE_KEYS={userId:userIdKey,userTraits:userTraitsKey,anonymousId:anonymousUserIdKey,groupId:groupIdKey,groupTraits:groupTraitsKey,initialReferrer:pageInitialReferrerKey,initialReferringDomain:pageInitialReferringDomainKey,sessionInfo:sessionInfoKey,authToken:authTokenKey};const ENCRYPTION_PREFIX_V3='RS_ENC_v3_'; | ||
const getEncryptedValueInternal=(value,encryptFn,debug)=>{const fallbackValue=null;try{const strValue=stringifyWithoutCircular(value,false);if(isNull(strValue)){return null;}return encryptFn(strValue);}catch(err){if(debug){console.error('Error occurred during encryption: ',err);}return fallbackValue;}};const getDecryptedValueInternal=(value,decryptFn,debug)=>{const fallbackValue=null;try{const decryptedVal=decryptFn(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){if(debug){console.error('Error occurred during decryption: ',err);}return fallbackValue;}};const encryptBrowser=value=>`${ENCRYPTION_PREFIX_V3}${toBase64(value)}`;const decryptBrowser=value=>{if(value?.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getEncryptedValueBrowser=(value,debug=false)=>getEncryptedValueInternal(value,encryptBrowser,debug);const getDecryptedValueBrowser=(value,debug=false)=>getDecryptedValueInternal(value,decryptBrowser,debug);const getDecryptedCookieBrowser=(cookieKey,debug=false)=>{if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValueBrowser(cookie(cookieKey),debug);}return null;};const encrypt=value=>`${ENCRYPTION_PREFIX_V3}${Buffer.from(value,'utf-8').toString('base64')}`;const decrypt=value=>{if(value?.startsWith(ENCRYPTION_PREFIX_V3)){return Buffer.from(value.substring(ENCRYPTION_PREFIX_V3.length),'base64').toString('utf-8');}return value;};const getDecryptedValue=(value,debug=false)=>getDecryptedValueInternal(value,decrypt,debug);const getEncryptedValue=(value,debug=false)=>getEncryptedValueInternal(value,encrypt,debug); | ||
const getEncryptedValueInternal=(value,encryptFn,debug)=>{const fallbackValue=null;try{const strValue=stringifyData(value,false);if(isNull(strValue)){return null;}return encryptFn(strValue);}catch(err){if(debug){console.error('Error occurred during encryption: ',err);}return fallbackValue;}};const getDecryptedValueInternal=(value,decryptFn,debug)=>{const fallbackValue=null;try{const decryptedVal=decryptFn(value);if(isNullOrUndefined(decryptedVal)){return fallbackValue;}return JSON.parse(decryptedVal);}catch(err){if(debug){console.error('Error occurred during decryption: ',err);}return fallbackValue;}};const encryptBrowser=value=>`${ENCRYPTION_PREFIX_V3}${toBase64(value)}`;const decryptBrowser=value=>{if(value?.startsWith(ENCRYPTION_PREFIX_V3)){return fromBase64(value.substring(ENCRYPTION_PREFIX_V3.length));}return value;};const getEncryptedValueBrowser=(value,debug=false)=>getEncryptedValueInternal(value,encryptBrowser,debug);const getDecryptedValueBrowser=(value,debug=false)=>getDecryptedValueInternal(value,decryptBrowser,debug);const getDecryptedCookieBrowser=(cookieKey,debug=false)=>{if(Object.values(COOKIE_KEYS).includes(cookieKey)){return getDecryptedValueBrowser(cookie(cookieKey),debug);}return null;};const encrypt=value=>`${ENCRYPTION_PREFIX_V3}${Buffer.from(value,'utf-8').toString('base64')}`;const decrypt=value=>{if(value?.startsWith(ENCRYPTION_PREFIX_V3)){return Buffer.from(value.substring(ENCRYPTION_PREFIX_V3.length),'base64').toString('utf-8');}return value;};const getDecryptedValue=(value,debug=false)=>getDecryptedValueInternal(value,decrypt,debug);const getEncryptedValue=(value,debug=false)=>getEncryptedValueInternal(value,encrypt,debug); | ||
@@ -84,0 +79,0 @@ exports.anonymousUserIdKey = anonymousUserIdKey; |
{ | ||
"name": "@rudderstack/analytics-js-cookies", | ||
"version": "0.3.14", | ||
"version": "0.4.0", | ||
"description": "RudderStack JavaScript SDK Cookies Utilities", | ||
@@ -5,0 +5,0 @@ "main": "dist/npm/modern/cjs/index.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
71406
661