@rudderstack/analytics-js 3.11.11 → 3.11.12
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/dist/npm/legacy/bundled/cjs/index.cjs +46 -39
- package/dist/npm/legacy/bundled/esm/index.mjs +46 -39
- package/dist/npm/legacy/bundled/umd/index.js +46 -39
- package/dist/npm/legacy/cjs/index.cjs +46 -39
- package/dist/npm/legacy/content-script/cjs/index.cjs +46 -39
- package/dist/npm/legacy/content-script/esm/index.mjs +46 -39
- package/dist/npm/legacy/content-script/umd/index.js +46 -39
- package/dist/npm/legacy/esm/index.mjs +46 -39
- package/dist/npm/legacy/umd/index.js +46 -39
- package/dist/npm/modern/bundled/cjs/index.cjs +46 -39
- package/dist/npm/modern/bundled/esm/index.mjs +46 -39
- package/dist/npm/modern/bundled/umd/index.js +46 -39
- package/dist/npm/modern/cjs/index.cjs +46 -39
- package/dist/npm/modern/content-script/cjs/index.cjs +46 -39
- package/dist/npm/modern/content-script/esm/index.mjs +46 -39
- package/dist/npm/modern/content-script/umd/index.js +46 -39
- package/dist/npm/modern/esm/index.mjs +46 -39
- package/dist/npm/modern/umd/index.js +46 -39
- package/package.json +1 -1
@@ -909,10 +909,54 @@
|
|
909
909
|
* @returns decoded string
|
910
910
|
*/var fromBase64=function fromBase64(value){return new TextDecoder().decode(base64ToBytes(value));};
|
911
911
|
|
912
|
+
var LOG_CONTEXT_SEPARATOR=':: ';var SCRIPT_ALREADY_EXISTS_ERROR=function SCRIPT_ALREADY_EXISTS_ERROR(id){return "A script with the id \"".concat(id,"\" is already loaded. Skipping the loading of this script to prevent conflicts.");};var SCRIPT_LOAD_ERROR=function SCRIPT_LOAD_ERROR(id,url){return "Failed to load the script with the id \"".concat(id,"\" from URL \"").concat(url,"\".");};var SCRIPT_LOAD_TIMEOUT_ERROR=function SCRIPT_LOAD_TIMEOUT_ERROR(id,url,timeout){return "A timeout of ".concat(timeout," ms occurred while trying to load the script with id \"").concat(id,"\" from URL \"").concat(url,"\".");};var CIRCULAR_REFERENCE_WARNING=function CIRCULAR_REFERENCE_WARNING(context,key){return "".concat(context).concat(LOG_CONTEXT_SEPARATOR,"A circular reference has been detected in the object and the property \"").concat(key,"\" has been dropped from the output.");};var JSON_STRINGIFY_WARNING="Failed to convert the value to a JSON string.";
|
913
|
+
|
914
|
+
var JSON_STRINGIFY='JSONStringify';var BIG_INT_PLACEHOLDER='[BigInt]';var CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';var getCircularReplacer=function getCircularReplacer(excludeNull,excludeKeys,logger){var ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
915
|
+
// eslint-disable-next-line func-names
|
916
|
+
return function(key,value){if(excludeKeys!==null&&excludeKeys!==void 0&&excludeKeys.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(_typeof(value)!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
917
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
918
|
+
// @ts-ignore-next-line
|
919
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger===null||logger===void 0||logger.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
920
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
921
|
+
*
|
922
|
+
* @param {*} value input
|
923
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
924
|
+
* @param {function} logger optional logger methods for warning
|
925
|
+
* @returns string
|
926
|
+
*/var stringifyWithoutCircular=function stringifyWithoutCircular(value,excludeNull,excludeKeys,logger){try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger===null||logger===void 0||logger.warn(JSON_STRINGIFY_WARNING,err);return null;}};/**
|
927
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
928
|
+
*
|
929
|
+
* @param {*} value input value
|
930
|
+
* @param {boolean} excludeNull optional flag to exclude null values
|
931
|
+
* @param {string[]} excludeKeys optional array of keys to exclude
|
932
|
+
* @returns string
|
933
|
+
*/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;});};var getReplacer=function getReplacer(logger){var ancestors=[];// Array to track ancestor objects
|
934
|
+
// Using a regular function to use `this` for the parent context
|
935
|
+
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
936
|
+
}// `this` is the object that value is contained in, i.e., its direct parent.
|
937
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
938
|
+
// @ts-ignore-next-line
|
939
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
940
|
+
}// Check for circular references (if the value is already in the ancestors)
|
941
|
+
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
942
|
+
ancestors.push(value);return value;};};var _traverseWithThis=function traverseWithThis(obj,replacer){// Create a new result object or array
|
943
|
+
var result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
944
|
+
// eslint-disable-next-line no-restricted-syntax
|
945
|
+
for(var key in obj){if(Object.hasOwnProperty.call(obj,key)){var value=obj[key];// Recursively apply the replacer and traversal
|
946
|
+
var sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
947
|
+
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=_traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
948
|
+
* Recursively traverses an object similar to JSON.stringify,
|
949
|
+
* sanitizing BigInts and circular references
|
950
|
+
* @param value Input object
|
951
|
+
* @param logger Logger instance
|
952
|
+
* @returns Sanitized value
|
953
|
+
*/var getSanitizedValue=function getSanitizedValue(value,logger){var replacer=getReplacer();// This is needed for registering the first ancestor
|
954
|
+
var newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return _traverseWithThis(value,replacer);}return newValue;};var tempUtil=function tempUtil(){stringifyData();};
|
955
|
+
|
912
956
|
// if yes make them null instead of omitting in overloaded cases
|
913
957
|
/*
|
914
958
|
* Normalise the overloaded arguments of the page call facade
|
915
|
-
*/var pageArgumentsToCallOptions=function pageArgumentsToCallOptions(category,name,properties,options,callback){var payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
959
|
+
*/var pageArgumentsToCallOptions=function pageArgumentsToCallOptions(category,name,properties,options,callback){tempUtil();var payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
916
960
|
// use it as name and set category to undefined
|
917
961
|
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
918
962
|
// and set some proper defaults
|
@@ -987,43 +1031,6 @@
|
|
987
1031
|
* @returns ISO formatted timestamp string
|
988
1032
|
*/var getCurrentTimeFormatted=function getCurrentTimeFormatted(){return getFormattedTimestamp(new Date());};
|
989
1033
|
|
990
|
-
var LOG_CONTEXT_SEPARATOR=':: ';var SCRIPT_ALREADY_EXISTS_ERROR=function SCRIPT_ALREADY_EXISTS_ERROR(id){return "A script with the id \"".concat(id,"\" is already loaded. Skipping the loading of this script to prevent conflicts.");};var SCRIPT_LOAD_ERROR=function SCRIPT_LOAD_ERROR(id,url){return "Failed to load the script with the id \"".concat(id,"\" from URL \"").concat(url,"\".");};var SCRIPT_LOAD_TIMEOUT_ERROR=function SCRIPT_LOAD_TIMEOUT_ERROR(id,url,timeout){return "A timeout of ".concat(timeout," ms occurred while trying to load the script with id \"").concat(id,"\" from URL \"").concat(url,"\".");};var CIRCULAR_REFERENCE_WARNING=function CIRCULAR_REFERENCE_WARNING(context,key){return "".concat(context).concat(LOG_CONTEXT_SEPARATOR,"A circular reference has been detected in the object and the property \"").concat(key,"\" has been dropped from the output.");};var JSON_STRINGIFY_WARNING="Failed to convert the value to a JSON string.";
|
991
|
-
|
992
|
-
var JSON_STRINGIFY='JSONStringify';var BIG_INT_PLACEHOLDER='[BigInt]';var CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';var getCircularReplacer=function getCircularReplacer(excludeNull,excludeKeys,logger){var ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
993
|
-
// eslint-disable-next-line func-names
|
994
|
-
return function(key,value){if(excludeKeys!==null&&excludeKeys!==void 0&&excludeKeys.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(_typeof(value)!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
995
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
996
|
-
// @ts-ignore-next-line
|
997
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger===null||logger===void 0||logger.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
998
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
999
|
-
*
|
1000
|
-
* @param {*} value input
|
1001
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
1002
|
-
* @param {function} logger optional logger methods for warning
|
1003
|
-
* @returns string
|
1004
|
-
*/var stringifyWithoutCircular=function stringifyWithoutCircular(value,excludeNull,excludeKeys,logger){try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger===null||logger===void 0||logger.warn(JSON_STRINGIFY_WARNING,err);return null;}};var getReplacer=function getReplacer(logger){var ancestors=[];// Array to track ancestor objects
|
1005
|
-
// Using a regular function to use `this` for the parent context
|
1006
|
-
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
1007
|
-
}// `this` is the object that value is contained in, i.e., its direct parent.
|
1008
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
1009
|
-
// @ts-ignore-next-line
|
1010
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
1011
|
-
}// Check for circular references (if the value is already in the ancestors)
|
1012
|
-
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
1013
|
-
ancestors.push(value);return value;};};var _traverseWithThis=function traverseWithThis(obj,replacer){// Create a new result object or array
|
1014
|
-
var result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
1015
|
-
// eslint-disable-next-line no-restricted-syntax
|
1016
|
-
for(var key in obj){if(Object.hasOwnProperty.call(obj,key)){var value=obj[key];// Recursively apply the replacer and traversal
|
1017
|
-
var sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
1018
|
-
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=_traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
1019
|
-
* Recursively traverses an object similar to JSON.stringify,
|
1020
|
-
* sanitizing BigInts and circular references
|
1021
|
-
* @param value Input object
|
1022
|
-
* @param logger Logger instance
|
1023
|
-
* @returns Sanitized value
|
1024
|
-
*/var getSanitizedValue=function getSanitizedValue(value,logger){var replacer=getReplacer();// This is needed for registering the first ancestor
|
1025
|
-
var newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return _traverseWithThis(value,replacer);}return newValue;};
|
1026
|
-
|
1027
1034
|
var MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
1028
1035
|
* Get mutated error with issue prepended to error message
|
1029
1036
|
* @param err Original error
|
@@ -1031,7 +1038,7 @@
|
|
1031
1038
|
* @returns Instance of Error with message prepended with issue
|
1032
1039
|
*/var getMutatedError=function getMutatedError(err,issue){var finalError=err;if(!isTypeOfError(err)){finalError=new Error("".concat(issue,": ").concat(stringifyWithoutCircular(err)));}else {finalError.message="".concat(issue,": ").concat(err.message);}return finalError;};var dispatchErrorEvent=function dispatchErrorEvent(error){if(isTypeOfError(error)){var _error$stack;error.stack="".concat((_error$stack=error.stack)!==null&&_error$stack!==void 0?_error$stack:'',"\n").concat(MANUAL_ERROR_IDENTIFIER);}globalThis.dispatchEvent(new ErrorEvent('error',{error:error}));};
|
1033
1040
|
|
1034
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.11.
|
1041
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.11.12';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
1035
1042
|
|
1036
1043
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
1037
1044
|
|
@@ -341,10 +341,54 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
|
|
341
341
|
* @returns decoded string
|
342
342
|
*/const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
|
343
343
|
|
344
|
+
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
345
|
+
|
346
|
+
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
347
|
+
// eslint-disable-next-line func-names
|
348
|
+
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
349
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
350
|
+
// @ts-ignore-next-line
|
351
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
352
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
353
|
+
*
|
354
|
+
* @param {*} value input
|
355
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
356
|
+
* @param {function} logger optional logger methods for warning
|
357
|
+
* @returns string
|
358
|
+
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};/**
|
359
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
360
|
+
*
|
361
|
+
* @param {*} value input value
|
362
|
+
* @param {boolean} excludeNull optional flag to exclude null values
|
363
|
+
* @param {string[]} excludeKeys optional array of keys to exclude
|
364
|
+
* @returns string
|
365
|
+
*/const stringifyData=(value,excludeNull=true,excludeKeys=[])=>JSON.stringify(value,(key,value)=>{if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;});const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
366
|
+
// Using a regular function to use `this` for the parent context
|
367
|
+
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
368
|
+
}// `this` is the object that value is contained in, i.e., its direct parent.
|
369
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
370
|
+
// @ts-ignore-next-line
|
371
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
372
|
+
}// Check for circular references (if the value is already in the ancestors)
|
373
|
+
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
374
|
+
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
375
|
+
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
376
|
+
// eslint-disable-next-line no-restricted-syntax
|
377
|
+
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
378
|
+
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
379
|
+
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
380
|
+
* Recursively traverses an object similar to JSON.stringify,
|
381
|
+
* sanitizing BigInts and circular references
|
382
|
+
* @param value Input object
|
383
|
+
* @param logger Logger instance
|
384
|
+
* @returns Sanitized value
|
385
|
+
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
386
|
+
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};const tempUtil=()=>{stringifyData();};
|
387
|
+
|
344
388
|
// if yes make them null instead of omitting in overloaded cases
|
345
389
|
/*
|
346
390
|
* Normalise the overloaded arguments of the page call facade
|
347
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
391
|
+
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{tempUtil();const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
348
392
|
// use it as name and set category to undefined
|
349
393
|
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
350
394
|
// and set some proper defaults
|
@@ -419,43 +463,6 @@ const getFormattedTimestamp=date=>date.toISOString();/**
|
|
419
463
|
* @returns ISO formatted timestamp string
|
420
464
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
421
465
|
|
422
|
-
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
423
|
-
|
424
|
-
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
425
|
-
// eslint-disable-next-line func-names
|
426
|
-
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
427
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
428
|
-
// @ts-ignore-next-line
|
429
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
430
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
431
|
-
*
|
432
|
-
* @param {*} value input
|
433
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
434
|
-
* @param {function} logger optional logger methods for warning
|
435
|
-
* @returns string
|
436
|
-
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
437
|
-
// Using a regular function to use `this` for the parent context
|
438
|
-
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
439
|
-
}// `this` is the object that value is contained in, i.e., its direct parent.
|
440
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
441
|
-
// @ts-ignore-next-line
|
442
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
443
|
-
}// Check for circular references (if the value is already in the ancestors)
|
444
|
-
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
445
|
-
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
446
|
-
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
447
|
-
// eslint-disable-next-line no-restricted-syntax
|
448
|
-
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
449
|
-
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
450
|
-
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
451
|
-
* Recursively traverses an object similar to JSON.stringify,
|
452
|
-
* sanitizing BigInts and circular references
|
453
|
-
* @param value Input object
|
454
|
-
* @param logger Logger instance
|
455
|
-
* @returns Sanitized value
|
456
|
-
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
457
|
-
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
|
458
|
-
|
459
466
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
460
467
|
* Get mutated error with issue prepended to error message
|
461
468
|
* @param err Original error
|
@@ -463,7 +470,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
|
463
470
|
* @returns Instance of Error with message prepended with issue
|
464
471
|
*/const getMutatedError=(err,issue)=>{let finalError=err;if(!isTypeOfError(err)){finalError=new Error(`${issue}: ${stringifyWithoutCircular(err)}`);}else {finalError.message=`${issue}: ${err.message}`;}return finalError;};const dispatchErrorEvent=error=>{if(isTypeOfError(error)){error.stack=`${error.stack??''}\n${MANUAL_ERROR_IDENTIFIER}`;}globalThis.dispatchEvent(new ErrorEvent('error',{error}));};
|
465
472
|
|
466
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
473
|
+
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.12';const APP_NAMESPACE='com.rudderlabs.javascript';const MODULE_TYPE='npm';const ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';const ADBLOCK_PAGE_NAME='ad-block page request';const ADBLOCK_PAGE_PATH='/ad-blocked';const GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';const CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
467
474
|
|
468
475
|
const QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';const QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';const QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';const QUERY_PARAM_USER_ID_KEY='ajs_uid';const QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
469
476
|
|
@@ -337,10 +337,54 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
|
|
337
337
|
* @returns decoded string
|
338
338
|
*/const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
|
339
339
|
|
340
|
+
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
341
|
+
|
342
|
+
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
343
|
+
// eslint-disable-next-line func-names
|
344
|
+
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
345
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
346
|
+
// @ts-ignore-next-line
|
347
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
348
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
349
|
+
*
|
350
|
+
* @param {*} value input
|
351
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
352
|
+
* @param {function} logger optional logger methods for warning
|
353
|
+
* @returns string
|
354
|
+
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};/**
|
355
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
356
|
+
*
|
357
|
+
* @param {*} value input value
|
358
|
+
* @param {boolean} excludeNull optional flag to exclude null values
|
359
|
+
* @param {string[]} excludeKeys optional array of keys to exclude
|
360
|
+
* @returns string
|
361
|
+
*/const stringifyData=(value,excludeNull=true,excludeKeys=[])=>JSON.stringify(value,(key,value)=>{if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;});const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
362
|
+
// Using a regular function to use `this` for the parent context
|
363
|
+
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
364
|
+
}// `this` is the object that value is contained in, i.e., its direct parent.
|
365
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
366
|
+
// @ts-ignore-next-line
|
367
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
368
|
+
}// Check for circular references (if the value is already in the ancestors)
|
369
|
+
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
370
|
+
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
371
|
+
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
372
|
+
// eslint-disable-next-line no-restricted-syntax
|
373
|
+
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
374
|
+
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
375
|
+
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
376
|
+
* Recursively traverses an object similar to JSON.stringify,
|
377
|
+
* sanitizing BigInts and circular references
|
378
|
+
* @param value Input object
|
379
|
+
* @param logger Logger instance
|
380
|
+
* @returns Sanitized value
|
381
|
+
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
382
|
+
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};const tempUtil=()=>{stringifyData();};
|
383
|
+
|
340
384
|
// if yes make them null instead of omitting in overloaded cases
|
341
385
|
/*
|
342
386
|
* Normalise the overloaded arguments of the page call facade
|
343
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
387
|
+
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{tempUtil();const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
344
388
|
// use it as name and set category to undefined
|
345
389
|
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
346
390
|
// and set some proper defaults
|
@@ -415,43 +459,6 @@ const getFormattedTimestamp=date=>date.toISOString();/**
|
|
415
459
|
* @returns ISO formatted timestamp string
|
416
460
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
417
461
|
|
418
|
-
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
419
|
-
|
420
|
-
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
421
|
-
// eslint-disable-next-line func-names
|
422
|
-
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
423
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
424
|
-
// @ts-ignore-next-line
|
425
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
426
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
427
|
-
*
|
428
|
-
* @param {*} value input
|
429
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
430
|
-
* @param {function} logger optional logger methods for warning
|
431
|
-
* @returns string
|
432
|
-
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
433
|
-
// Using a regular function to use `this` for the parent context
|
434
|
-
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
435
|
-
}// `this` is the object that value is contained in, i.e., its direct parent.
|
436
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
437
|
-
// @ts-ignore-next-line
|
438
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
439
|
-
}// Check for circular references (if the value is already in the ancestors)
|
440
|
-
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
441
|
-
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
442
|
-
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
443
|
-
// eslint-disable-next-line no-restricted-syntax
|
444
|
-
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
445
|
-
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
446
|
-
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
447
|
-
* Recursively traverses an object similar to JSON.stringify,
|
448
|
-
* sanitizing BigInts and circular references
|
449
|
-
* @param value Input object
|
450
|
-
* @param logger Logger instance
|
451
|
-
* @returns Sanitized value
|
452
|
-
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
453
|
-
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
|
454
|
-
|
455
462
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
456
463
|
* Get mutated error with issue prepended to error message
|
457
464
|
* @param err Original error
|
@@ -459,7 +466,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
|
459
466
|
* @returns Instance of Error with message prepended with issue
|
460
467
|
*/const getMutatedError=(err,issue)=>{let finalError=err;if(!isTypeOfError(err)){finalError=new Error(`${issue}: ${stringifyWithoutCircular(err)}`);}else {finalError.message=`${issue}: ${err.message}`;}return finalError;};const dispatchErrorEvent=error=>{if(isTypeOfError(error)){error.stack=`${error.stack??''}\n${MANUAL_ERROR_IDENTIFIER}`;}globalThis.dispatchEvent(new ErrorEvent('error',{error}));};
|
461
468
|
|
462
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
469
|
+
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.12';const APP_NAMESPACE='com.rudderlabs.javascript';const MODULE_TYPE='npm';const ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';const ADBLOCK_PAGE_NAME='ad-block page request';const ADBLOCK_PAGE_PATH='/ad-blocked';const GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';const CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
463
470
|
|
464
471
|
const QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';const QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';const QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';const QUERY_PARAM_USER_ID_KEY='ajs_uid';const QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
465
472
|
|
@@ -343,10 +343,54 @@
|
|
343
343
|
* @returns decoded string
|
344
344
|
*/const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
|
345
345
|
|
346
|
+
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
347
|
+
|
348
|
+
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
349
|
+
// eslint-disable-next-line func-names
|
350
|
+
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
351
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
352
|
+
// @ts-ignore-next-line
|
353
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
354
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
355
|
+
*
|
356
|
+
* @param {*} value input
|
357
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
358
|
+
* @param {function} logger optional logger methods for warning
|
359
|
+
* @returns string
|
360
|
+
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};/**
|
361
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
362
|
+
*
|
363
|
+
* @param {*} value input value
|
364
|
+
* @param {boolean} excludeNull optional flag to exclude null values
|
365
|
+
* @param {string[]} excludeKeys optional array of keys to exclude
|
366
|
+
* @returns string
|
367
|
+
*/const stringifyData=(value,excludeNull=true,excludeKeys=[])=>JSON.stringify(value,(key,value)=>{if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;});const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
368
|
+
// Using a regular function to use `this` for the parent context
|
369
|
+
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
370
|
+
}// `this` is the object that value is contained in, i.e., its direct parent.
|
371
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
372
|
+
// @ts-ignore-next-line
|
373
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
374
|
+
}// Check for circular references (if the value is already in the ancestors)
|
375
|
+
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
376
|
+
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
377
|
+
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
378
|
+
// eslint-disable-next-line no-restricted-syntax
|
379
|
+
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
380
|
+
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
381
|
+
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
382
|
+
* Recursively traverses an object similar to JSON.stringify,
|
383
|
+
* sanitizing BigInts and circular references
|
384
|
+
* @param value Input object
|
385
|
+
* @param logger Logger instance
|
386
|
+
* @returns Sanitized value
|
387
|
+
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
388
|
+
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};const tempUtil=()=>{stringifyData();};
|
389
|
+
|
346
390
|
// if yes make them null instead of omitting in overloaded cases
|
347
391
|
/*
|
348
392
|
* Normalise the overloaded arguments of the page call facade
|
349
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
393
|
+
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{tempUtil();const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
350
394
|
// use it as name and set category to undefined
|
351
395
|
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
352
396
|
// and set some proper defaults
|
@@ -421,43 +465,6 @@
|
|
421
465
|
* @returns ISO formatted timestamp string
|
422
466
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
423
467
|
|
424
|
-
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
425
|
-
|
426
|
-
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
427
|
-
// eslint-disable-next-line func-names
|
428
|
-
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
429
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
430
|
-
// @ts-ignore-next-line
|
431
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
432
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
433
|
-
*
|
434
|
-
* @param {*} value input
|
435
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
436
|
-
* @param {function} logger optional logger methods for warning
|
437
|
-
* @returns string
|
438
|
-
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
439
|
-
// Using a regular function to use `this` for the parent context
|
440
|
-
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
441
|
-
}// `this` is the object that value is contained in, i.e., its direct parent.
|
442
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
443
|
-
// @ts-ignore-next-line
|
444
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
445
|
-
}// Check for circular references (if the value is already in the ancestors)
|
446
|
-
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
447
|
-
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
448
|
-
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
449
|
-
// eslint-disable-next-line no-restricted-syntax
|
450
|
-
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
451
|
-
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
452
|
-
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
453
|
-
* Recursively traverses an object similar to JSON.stringify,
|
454
|
-
* sanitizing BigInts and circular references
|
455
|
-
* @param value Input object
|
456
|
-
* @param logger Logger instance
|
457
|
-
* @returns Sanitized value
|
458
|
-
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
459
|
-
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
|
460
|
-
|
461
468
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
462
469
|
* Get mutated error with issue prepended to error message
|
463
470
|
* @param err Original error
|
@@ -465,7 +472,7 @@
|
|
465
472
|
* @returns Instance of Error with message prepended with issue
|
466
473
|
*/const getMutatedError=(err,issue)=>{let finalError=err;if(!isTypeOfError(err)){finalError=new Error(`${issue}: ${stringifyWithoutCircular(err)}`);}else {finalError.message=`${issue}: ${err.message}`;}return finalError;};const dispatchErrorEvent=error=>{if(isTypeOfError(error)){error.stack=`${error.stack??''}\n${MANUAL_ERROR_IDENTIFIER}`;}globalThis.dispatchEvent(new ErrorEvent('error',{error}));};
|
467
474
|
|
468
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
475
|
+
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.12';const APP_NAMESPACE='com.rudderlabs.javascript';const MODULE_TYPE='npm';const ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';const ADBLOCK_PAGE_NAME='ad-block page request';const ADBLOCK_PAGE_PATH='/ad-blocked';const GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';const CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
469
476
|
|
470
477
|
const QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';const QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';const QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';const QUERY_PARAM_USER_ID_KEY='ajs_uid';const QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
471
478
|
|
@@ -332,10 +332,54 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
|
|
332
332
|
* @returns base64 encoded string
|
333
333
|
*/const toBase64=value=>bytesToBase64(new TextEncoder().encode(value));
|
334
334
|
|
335
|
+
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
336
|
+
|
337
|
+
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
338
|
+
// eslint-disable-next-line func-names
|
339
|
+
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
340
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
341
|
+
// @ts-ignore-next-line
|
342
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
343
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
344
|
+
*
|
345
|
+
* @param {*} value input
|
346
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
347
|
+
* @param {function} logger optional logger methods for warning
|
348
|
+
* @returns string
|
349
|
+
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};/**
|
350
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
351
|
+
*
|
352
|
+
* @param {*} value input value
|
353
|
+
* @param {boolean} excludeNull optional flag to exclude null values
|
354
|
+
* @param {string[]} excludeKeys optional array of keys to exclude
|
355
|
+
* @returns string
|
356
|
+
*/const stringifyData=(value,excludeNull=true,excludeKeys=[])=>JSON.stringify(value,(key,value)=>{if(excludeNull&&isNull(value)||excludeKeys.includes(key)){return undefined;}return value;});const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
357
|
+
// Using a regular function to use `this` for the parent context
|
358
|
+
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
359
|
+
}// `this` is the object that value is contained in, i.e., its direct parent.
|
360
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
361
|
+
// @ts-ignore-next-line
|
362
|
+
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
363
|
+
}// Check for circular references (if the value is already in the ancestors)
|
364
|
+
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
365
|
+
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
366
|
+
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
367
|
+
// eslint-disable-next-line no-restricted-syntax
|
368
|
+
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
369
|
+
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
370
|
+
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
371
|
+
* Recursively traverses an object similar to JSON.stringify,
|
372
|
+
* sanitizing BigInts and circular references
|
373
|
+
* @param value Input object
|
374
|
+
* @param logger Logger instance
|
375
|
+
* @returns Sanitized value
|
376
|
+
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
377
|
+
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};const tempUtil=()=>{stringifyData();};
|
378
|
+
|
335
379
|
// if yes make them null instead of omitting in overloaded cases
|
336
380
|
/*
|
337
381
|
* Normalise the overloaded arguments of the page call facade
|
338
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
382
|
+
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{tempUtil();const payload={category:category,name:name,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.category=category;payload.name=name;payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.category=category;payload.name=name;payload.properties=undefined;payload.options=undefined;payload.callback=properties;}if(isFunction(name)){payload.category=category;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=name;}if(isFunction(category)){payload.category=undefined;payload.name=undefined;payload.properties=undefined;payload.options=undefined;payload.callback=category;}if(isObjectLiteralAndNotNull(category)){payload.name=undefined;payload.category=undefined;payload.properties=category;if(!isFunction(name)){payload.options=name;}else {payload.options=undefined;}}else if(isObjectLiteralAndNotNull(name)){payload.name=undefined;payload.properties=name;if(!isFunction(properties)){payload.options=properties;}else {payload.options=undefined;}}// if the category argument alone is provided b/w category and name,
|
339
383
|
// use it as name and set category to undefined
|
340
384
|
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
341
385
|
// and set some proper defaults
|
@@ -410,43 +454,6 @@ const getFormattedTimestamp=date=>date.toISOString();/**
|
|
410
454
|
* @returns ISO formatted timestamp string
|
411
455
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
412
456
|
|
413
|
-
const LOG_CONTEXT_SEPARATOR=':: ';const SCRIPT_ALREADY_EXISTS_ERROR=id=>`A script with the id "${id}" is already loaded. Skipping the loading of this script to prevent conflicts.`;const SCRIPT_LOAD_ERROR=(id,url)=>`Failed to load the script with the id "${id}" from URL "${url}".`;const SCRIPT_LOAD_TIMEOUT_ERROR=(id,url,timeout)=>`A timeout of ${timeout} ms occurred while trying to load the script with id "${id}" from URL "${url}".`;const CIRCULAR_REFERENCE_WARNING=(context,key)=>`${context}${LOG_CONTEXT_SEPARATOR}A circular reference has been detected in the object and the property "${key}" has been dropped from the output.`;const JSON_STRINGIFY_WARNING=`Failed to convert the value to a JSON string.`;
|
414
|
-
|
415
|
-
const JSON_STRINGIFY='JSONStringify';const BIG_INT_PLACEHOLDER='[BigInt]';const CIRCULAR_REFERENCE_PLACEHOLDER='[Circular Reference]';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
|
416
|
-
// eslint-disable-next-line func-names
|
417
|
-
return function(key,value){if(excludeKeys?.includes(key)){return undefined;}if(excludeNull&&isNullOrUndefined(value)){return undefined;}if(typeof value!=='object'||isNull(value)){return value;}// `this` is the object that value is contained in, i.e., its direct parent.
|
418
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
419
|
-
// @ts-ignore-next-line
|
420
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();}if(ancestors.includes(value)){logger?.warn(CIRCULAR_REFERENCE_WARNING(JSON_STRINGIFY,key));return CIRCULAR_REFERENCE_PLACEHOLDER;}ancestors.push(value);return value;};};/**
|
421
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
422
|
-
*
|
423
|
-
* @param {*} value input
|
424
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
425
|
-
* @param {function} logger optional logger methods for warning
|
426
|
-
* @returns string
|
427
|
-
*/const stringifyWithoutCircular=(value,excludeNull,excludeKeys,logger)=>{try{return JSON.stringify(value,getCircularReplacer(excludeNull,excludeKeys,logger));}catch(err){logger?.warn(JSON_STRINGIFY_WARNING,err);return null;}};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
|
428
|
-
// Using a regular function to use `this` for the parent context
|
429
|
-
return function replacer(key,value){if(isBigInt(value)){return BIG_INT_PLACEHOLDER;// Replace BigInt values
|
430
|
-
}// `this` is the object that value is contained in, i.e., its direct parent.
|
431
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
432
|
-
// @ts-ignore-next-line
|
433
|
-
while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
|
434
|
-
}// Check for circular references (if the value is already in the ancestors)
|
435
|
-
if(ancestors.includes(value)){return CIRCULAR_REFERENCE_PLACEHOLDER;}// Add current value to ancestors
|
436
|
-
ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
|
437
|
-
const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
|
438
|
-
// eslint-disable-next-line no-restricted-syntax
|
439
|
-
for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
|
440
|
-
const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
|
441
|
-
if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
|
442
|
-
* Recursively traverses an object similar to JSON.stringify,
|
443
|
-
* sanitizing BigInts and circular references
|
444
|
-
* @param value Input object
|
445
|
-
* @param logger Logger instance
|
446
|
-
* @returns Sanitized value
|
447
|
-
*/const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
|
448
|
-
const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
|
449
|
-
|
450
457
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
451
458
|
* Get mutated error with issue prepended to error message
|
452
459
|
* @param err Original error
|
@@ -454,7 +461,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
|
454
461
|
* @returns Instance of Error with message prepended with issue
|
455
462
|
*/const getMutatedError=(err,issue)=>{let finalError=err;if(!isTypeOfError(err)){finalError=new Error(`${issue}: ${stringifyWithoutCircular(err)}`);}else {finalError.message=`${issue}: ${err.message}`;}return finalError;};const dispatchErrorEvent=error=>{if(isTypeOfError(error)){error.stack=`${error.stack??''}\n${MANUAL_ERROR_IDENTIFIER}`;}globalThis.dispatchEvent(new ErrorEvent('error',{error}));};
|
456
463
|
|
457
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
464
|
+
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.12';const APP_NAMESPACE='com.rudderlabs.javascript';const MODULE_TYPE='npm';const ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';const ADBLOCK_PAGE_NAME='ad-block page request';const ADBLOCK_PAGE_PATH='/ad-blocked';const GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';const CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
458
465
|
|
459
466
|
const QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';const QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';const QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';const QUERY_PARAM_USER_ID_KEY='ajs_uid';const QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
460
467
|
|