@rudderstack/analytics-js 3.11.6 → 3.11.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -269,6 +269,10 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
269
269
  * @param value input value
270
270
  * @returns boolean
271
271
  */const isNullOrUndefined=value=>isNull(value)||isUndefined(value);/**
272
+ * Checks if the input is a BigInt
273
+ * @param value input value
274
+ * @returns True if the input is a BigInt
275
+ */const isBigInt=value=>typeof value==='bigint';/**
272
276
  * A function to check given value is defined
273
277
  * @param value input value
274
278
  * @returns boolean
@@ -286,6 +290,8 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
286
290
  * @returns true if the input is an instance of Error and false otherwise
287
291
  */const isTypeOfError=obj=>obj instanceof Error;
288
292
 
293
+ 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.`;
294
+
289
295
  const getValueByPath=(obj,keyPath)=>{const pathParts=keyPath.split('.');return path(pathParts,obj);};const hasValueByPath=(obj,path)=>Boolean(getValueByPath(obj,path));const isObject=value=>typeof value==='object';/**
290
296
  * Checks if the input is an object literal or built-in object type and not null
291
297
  * @param value Input value
@@ -307,7 +313,28 @@ mergeDeepRight(mergedArray[index],value):value;});return mergedArray;};const mer
307
313
  * A utility to recursively remove undefined and null values from an object
308
314
  * @param obj input object
309
315
  * @returns a new object
310
- */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};
316
+ */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
317
+ // Using a regular function to use `this` for the parent context
318
+ return function replacer(key,value){if(isBigInt(value)){return '[BigInt]';// Replace BigInt values
319
+ }// `this` is the object that value is contained in, i.e., its direct parent.
320
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
321
+ // @ts-ignore-next-line
322
+ while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
323
+ }// Check for circular references (if the value is already in the ancestors)
324
+ if(ancestors.includes(value)){return '[Circular Reference]';}// Add current value to ancestors
325
+ ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
326
+ const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
327
+ // eslint-disable-next-line no-restricted-syntax
328
+ for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
329
+ const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
330
+ if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
331
+ * Recursively traverses an object similar to JSON.stringify,
332
+ * sanitizing BigInts and circular references
333
+ * @param value Input object
334
+ * @param logger Logger instance
335
+ * @returns Sanitized value
336
+ */const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
337
+ const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
311
338
 
312
339
  const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value=>value.replace(/ {2,}/g,' ');const removeLeadingPeriod=value=>value.replace(/^\.+/,'');/**
313
340
  * A function to convert values to string
@@ -333,28 +360,6 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
333
360
  * @returns decoded string
334
361
  */const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
335
362
 
336
- 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.`;
337
-
338
- const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
339
- // eslint-disable-next-line func-names
340
- 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.
341
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
342
- // @ts-ignore-next-line
343
- 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]';}ancestors.push(value);return value;};};/**
344
- * Utility method for JSON stringify object excluding null values & circular references
345
- *
346
- * @param {*} value input
347
- * @param {boolean} excludeNull if it should exclude nul or not
348
- * @param {function} logger optional logger methods for warning
349
- * @returns string
350
- */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;}};/**
351
- * Recursively traverses an object similar to JSON.stringify,
352
- * sanitizing BigInts and circular references
353
- * @param value Input object
354
- * @param logger Logger instance
355
- * @returns Sanitized value
356
- */const getSanitizedValue=(value,logger)=>value;
357
-
358
363
  // if yes make them null instead of omitting in overloaded cases
359
364
  /*
360
365
  * Normalise the overloaded arguments of the page call facade
@@ -433,6 +438,20 @@ const getFormattedTimestamp=date=>date.toISOString();/**
433
438
  * @returns ISO formatted timestamp string
434
439
  */const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
435
440
 
441
+ const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
442
+ // eslint-disable-next-line func-names
443
+ 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.
444
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
445
+ // @ts-ignore-next-line
446
+ 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]';}ancestors.push(value);return value;};};/**
447
+ * Utility method for JSON stringify object excluding null values & circular references
448
+ *
449
+ * @param {*} value input
450
+ * @param {boolean} excludeNull if it should exclude nul or not
451
+ * @param {function} logger optional logger methods for warning
452
+ * @returns string
453
+ */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;}};
454
+
436
455
  const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
437
456
  * Get mutated error with issue prepended to error message
438
457
  * @param err Original error
@@ -440,7 +459,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
440
459
  * @returns Instance of Error with message prepended with issue
441
460
  */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}));};
442
461
 
443
- const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.6';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';
462
+ const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.8';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';
444
463
 
445
464
  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';
446
465
 
@@ -275,6 +275,10 @@
275
275
  * @param value input value
276
276
  * @returns boolean
277
277
  */const isNullOrUndefined=value=>isNull(value)||isUndefined(value);/**
278
+ * Checks if the input is a BigInt
279
+ * @param value input value
280
+ * @returns True if the input is a BigInt
281
+ */const isBigInt=value=>typeof value==='bigint';/**
278
282
  * A function to check given value is defined
279
283
  * @param value input value
280
284
  * @returns boolean
@@ -292,6 +296,8 @@
292
296
  * @returns true if the input is an instance of Error and false otherwise
293
297
  */const isTypeOfError=obj=>obj instanceof Error;
294
298
 
299
+ 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.`;
300
+
295
301
  const getValueByPath=(obj,keyPath)=>{const pathParts=keyPath.split('.');return path(pathParts,obj);};const hasValueByPath=(obj,path)=>Boolean(getValueByPath(obj,path));const isObject=value=>typeof value==='object';/**
296
302
  * Checks if the input is an object literal or built-in object type and not null
297
303
  * @param value Input value
@@ -313,7 +319,28 @@
313
319
  * A utility to recursively remove undefined and null values from an object
314
320
  * @param obj input object
315
321
  * @returns a new object
316
- */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};
322
+ */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
323
+ // Using a regular function to use `this` for the parent context
324
+ return function replacer(key,value){if(isBigInt(value)){return '[BigInt]';// Replace BigInt values
325
+ }// `this` is the object that value is contained in, i.e., its direct parent.
326
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
327
+ // @ts-ignore-next-line
328
+ while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
329
+ }// Check for circular references (if the value is already in the ancestors)
330
+ if(ancestors.includes(value)){return '[Circular Reference]';}// Add current value to ancestors
331
+ ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
332
+ const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
333
+ // eslint-disable-next-line no-restricted-syntax
334
+ for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
335
+ const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
336
+ if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
337
+ * Recursively traverses an object similar to JSON.stringify,
338
+ * sanitizing BigInts and circular references
339
+ * @param value Input object
340
+ * @param logger Logger instance
341
+ * @returns Sanitized value
342
+ */const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
343
+ const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
317
344
 
318
345
  const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value=>value.replace(/ {2,}/g,' ');const removeLeadingPeriod=value=>value.replace(/^\.+/,'');/**
319
346
  * A function to convert values to string
@@ -339,28 +366,6 @@
339
366
  * @returns decoded string
340
367
  */const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
341
368
 
342
- 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.`;
343
-
344
- const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
345
- // eslint-disable-next-line func-names
346
- 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.
347
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
348
- // @ts-ignore-next-line
349
- 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]';}ancestors.push(value);return value;};};/**
350
- * Utility method for JSON stringify object excluding null values & circular references
351
- *
352
- * @param {*} value input
353
- * @param {boolean} excludeNull if it should exclude nul or not
354
- * @param {function} logger optional logger methods for warning
355
- * @returns string
356
- */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;}};/**
357
- * Recursively traverses an object similar to JSON.stringify,
358
- * sanitizing BigInts and circular references
359
- * @param value Input object
360
- * @param logger Logger instance
361
- * @returns Sanitized value
362
- */const getSanitizedValue=(value,logger)=>value;
363
-
364
369
  // if yes make them null instead of omitting in overloaded cases
365
370
  /*
366
371
  * Normalise the overloaded arguments of the page call facade
@@ -439,6 +444,20 @@
439
444
  * @returns ISO formatted timestamp string
440
445
  */const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
441
446
 
447
+ const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
448
+ // eslint-disable-next-line func-names
449
+ 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.
450
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
451
+ // @ts-ignore-next-line
452
+ 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]';}ancestors.push(value);return value;};};/**
453
+ * Utility method for JSON stringify object excluding null values & circular references
454
+ *
455
+ * @param {*} value input
456
+ * @param {boolean} excludeNull if it should exclude nul or not
457
+ * @param {function} logger optional logger methods for warning
458
+ * @returns string
459
+ */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;}};
460
+
442
461
  const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
443
462
  * Get mutated error with issue prepended to error message
444
463
  * @param err Original error
@@ -446,7 +465,7 @@
446
465
  * @returns Instance of Error with message prepended with issue
447
466
  */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}));};
448
467
 
449
- const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.6';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';
468
+ const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.8';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';
450
469
 
451
470
  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';
452
471
 
@@ -273,6 +273,10 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
273
273
  * @param value input value
274
274
  * @returns boolean
275
275
  */const isNullOrUndefined=value=>isNull(value)||isUndefined(value);/**
276
+ * Checks if the input is a BigInt
277
+ * @param value input value
278
+ * @returns True if the input is a BigInt
279
+ */const isBigInt=value=>typeof value==='bigint';/**
276
280
  * A function to check given value is defined
277
281
  * @param value input value
278
282
  * @returns boolean
@@ -290,6 +294,8 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
290
294
  * @returns true if the input is an instance of Error and false otherwise
291
295
  */const isTypeOfError=obj=>obj instanceof Error;
292
296
 
297
+ 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.`;
298
+
293
299
  const getValueByPath=(obj,keyPath)=>{const pathParts=keyPath.split('.');return path(pathParts,obj);};const hasValueByPath=(obj,path)=>Boolean(getValueByPath(obj,path));const isObject=value=>typeof value==='object';/**
294
300
  * Checks if the input is an object literal or built-in object type and not null
295
301
  * @param value Input value
@@ -311,7 +317,28 @@ mergeDeepRight(mergedArray[index],value):value;});return mergedArray;};const mer
311
317
  * A utility to recursively remove undefined and null values from an object
312
318
  * @param obj input object
313
319
  * @returns a new object
314
- */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};
320
+ */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
321
+ // Using a regular function to use `this` for the parent context
322
+ return function replacer(key,value){if(isBigInt(value)){return '[BigInt]';// Replace BigInt values
323
+ }// `this` is the object that value is contained in, i.e., its direct parent.
324
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
325
+ // @ts-ignore-next-line
326
+ while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
327
+ }// Check for circular references (if the value is already in the ancestors)
328
+ if(ancestors.includes(value)){return '[Circular Reference]';}// Add current value to ancestors
329
+ ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
330
+ const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
331
+ // eslint-disable-next-line no-restricted-syntax
332
+ for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
333
+ const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
334
+ if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
335
+ * Recursively traverses an object similar to JSON.stringify,
336
+ * sanitizing BigInts and circular references
337
+ * @param value Input object
338
+ * @param logger Logger instance
339
+ * @returns Sanitized value
340
+ */const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
341
+ const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
315
342
 
316
343
  const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value=>value.replace(/ {2,}/g,' ');const removeLeadingPeriod=value=>value.replace(/^\.+/,'');/**
317
344
  * A function to convert values to string
@@ -328,28 +355,6 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
328
355
  * @returns base64 encoded string
329
356
  */const toBase64=value=>bytesToBase64(new TextEncoder().encode(value));
330
357
 
331
- 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.`;
332
-
333
- const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
334
- // eslint-disable-next-line func-names
335
- 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.
336
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
337
- // @ts-ignore-next-line
338
- 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]';}ancestors.push(value);return value;};};/**
339
- * Utility method for JSON stringify object excluding null values & circular references
340
- *
341
- * @param {*} value input
342
- * @param {boolean} excludeNull if it should exclude nul or not
343
- * @param {function} logger optional logger methods for warning
344
- * @returns string
345
- */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;}};/**
346
- * Recursively traverses an object similar to JSON.stringify,
347
- * sanitizing BigInts and circular references
348
- * @param value Input object
349
- * @param logger Logger instance
350
- * @returns Sanitized value
351
- */const getSanitizedValue=(value,logger)=>value;
352
-
353
358
  // if yes make them null instead of omitting in overloaded cases
354
359
  /*
355
360
  * Normalise the overloaded arguments of the page call facade
@@ -428,6 +433,20 @@ const getFormattedTimestamp=date=>date.toISOString();/**
428
433
  * @returns ISO formatted timestamp string
429
434
  */const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
430
435
 
436
+ const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
437
+ // eslint-disable-next-line func-names
438
+ 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.
439
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
440
+ // @ts-ignore-next-line
441
+ 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]';}ancestors.push(value);return value;};};/**
442
+ * Utility method for JSON stringify object excluding null values & circular references
443
+ *
444
+ * @param {*} value input
445
+ * @param {boolean} excludeNull if it should exclude nul or not
446
+ * @param {function} logger optional logger methods for warning
447
+ * @returns string
448
+ */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;}};
449
+
431
450
  const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
432
451
  * Get mutated error with issue prepended to error message
433
452
  * @param err Original error
@@ -435,7 +454,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
435
454
  * @returns Instance of Error with message prepended with issue
436
455
  */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}));};
437
456
 
438
- const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.6';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';
457
+ const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.8';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';
439
458
 
440
459
  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';
441
460
 
@@ -273,6 +273,10 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
273
273
  * @param value input value
274
274
  * @returns boolean
275
275
  */const isNullOrUndefined=value=>isNull(value)||isUndefined(value);/**
276
+ * Checks if the input is a BigInt
277
+ * @param value input value
278
+ * @returns True if the input is a BigInt
279
+ */const isBigInt=value=>typeof value==='bigint';/**
276
280
  * A function to check given value is defined
277
281
  * @param value input value
278
282
  * @returns boolean
@@ -290,6 +294,8 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
290
294
  * @returns true if the input is an instance of Error and false otherwise
291
295
  */const isTypeOfError=obj=>obj instanceof Error;
292
296
 
297
+ 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.`;
298
+
293
299
  const getValueByPath=(obj,keyPath)=>{const pathParts=keyPath.split('.');return path(pathParts,obj);};const hasValueByPath=(obj,path)=>Boolean(getValueByPath(obj,path));const isObject=value=>typeof value==='object';/**
294
300
  * Checks if the input is an object literal or built-in object type and not null
295
301
  * @param value Input value
@@ -311,7 +317,28 @@ mergeDeepRight(mergedArray[index],value):value;});return mergedArray;};const mer
311
317
  * A utility to recursively remove undefined and null values from an object
312
318
  * @param obj input object
313
319
  * @returns a new object
314
- */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};
320
+ */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
321
+ // Using a regular function to use `this` for the parent context
322
+ return function replacer(key,value){if(isBigInt(value)){return '[BigInt]';// Replace BigInt values
323
+ }// `this` is the object that value is contained in, i.e., its direct parent.
324
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
325
+ // @ts-ignore-next-line
326
+ while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
327
+ }// Check for circular references (if the value is already in the ancestors)
328
+ if(ancestors.includes(value)){return '[Circular Reference]';}// Add current value to ancestors
329
+ ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
330
+ const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
331
+ // eslint-disable-next-line no-restricted-syntax
332
+ for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
333
+ const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
334
+ if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
335
+ * Recursively traverses an object similar to JSON.stringify,
336
+ * sanitizing BigInts and circular references
337
+ * @param value Input object
338
+ * @param logger Logger instance
339
+ * @returns Sanitized value
340
+ */const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
341
+ const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
315
342
 
316
343
  const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value=>value.replace(/ {2,}/g,' ');const removeLeadingPeriod=value=>value.replace(/^\.+/,'');/**
317
344
  * A function to convert values to string
@@ -337,28 +364,6 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
337
364
  * @returns decoded string
338
365
  */const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
339
366
 
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 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]';}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
- * Recursively traverses an object similar to JSON.stringify,
356
- * sanitizing BigInts and circular references
357
- * @param value Input object
358
- * @param logger Logger instance
359
- * @returns Sanitized value
360
- */const getSanitizedValue=(value,logger)=>value;
361
-
362
367
  // if yes make them null instead of omitting in overloaded cases
363
368
  /*
364
369
  * Normalise the overloaded arguments of the page call facade
@@ -437,6 +442,20 @@ const getFormattedTimestamp=date=>date.toISOString();/**
437
442
  * @returns ISO formatted timestamp string
438
443
  */const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
439
444
 
445
+ const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
446
+ // eslint-disable-next-line func-names
447
+ 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.
448
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
449
+ // @ts-ignore-next-line
450
+ 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]';}ancestors.push(value);return value;};};/**
451
+ * Utility method for JSON stringify object excluding null values & circular references
452
+ *
453
+ * @param {*} value input
454
+ * @param {boolean} excludeNull if it should exclude nul or not
455
+ * @param {function} logger optional logger methods for warning
456
+ * @returns string
457
+ */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;}};
458
+
440
459
  const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
441
460
  * Get mutated error with issue prepended to error message
442
461
  * @param err Original error
@@ -444,7 +463,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
444
463
  * @returns Instance of Error with message prepended with issue
445
464
  */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}));};
446
465
 
447
- const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.6';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';
466
+ const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.8';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';
448
467
 
449
468
  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';
450
469
 
@@ -269,6 +269,10 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
269
269
  * @param value input value
270
270
  * @returns boolean
271
271
  */const isNullOrUndefined=value=>isNull(value)||isUndefined(value);/**
272
+ * Checks if the input is a BigInt
273
+ * @param value input value
274
+ * @returns True if the input is a BigInt
275
+ */const isBigInt=value=>typeof value==='bigint';/**
272
276
  * A function to check given value is defined
273
277
  * @param value input value
274
278
  * @returns boolean
@@ -286,6 +290,8 @@ const isFunction=value=>typeof value==='function'&&Boolean(value.constructor&&va
286
290
  * @returns true if the input is an instance of Error and false otherwise
287
291
  */const isTypeOfError=obj=>obj instanceof Error;
288
292
 
293
+ 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.`;
294
+
289
295
  const getValueByPath=(obj,keyPath)=>{const pathParts=keyPath.split('.');return path(pathParts,obj);};const hasValueByPath=(obj,path)=>Boolean(getValueByPath(obj,path));const isObject=value=>typeof value==='object';/**
290
296
  * Checks if the input is an object literal or built-in object type and not null
291
297
  * @param value Input value
@@ -307,7 +313,28 @@ mergeDeepRight(mergedArray[index],value):value;});return mergedArray;};const mer
307
313
  * A utility to recursively remove undefined and null values from an object
308
314
  * @param obj input object
309
315
  * @returns a new object
310
- */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};
316
+ */const removeUndefinedAndNullValues=obj=>{const result=pickBy(isDefinedAndNotNull,obj);Object.keys(result).forEach(key=>{const value=result[key];if(isObjectLiteralAndNotNull(value)){result[key]=removeUndefinedAndNullValues(value);}});return result;};const getReplacer=logger=>{const ancestors=[];// Array to track ancestor objects
317
+ // Using a regular function to use `this` for the parent context
318
+ return function replacer(key,value){if(isBigInt(value)){return '[BigInt]';// Replace BigInt values
319
+ }// `this` is the object that value is contained in, i.e., its direct parent.
320
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
321
+ // @ts-ignore-next-line
322
+ while(ancestors.length>0&&ancestors[ancestors.length-1]!==this){ancestors.pop();// Remove ancestors that are no longer part of the chain
323
+ }// Check for circular references (if the value is already in the ancestors)
324
+ if(ancestors.includes(value)){return '[Circular Reference]';}// Add current value to ancestors
325
+ ancestors.push(value);return value;};};const traverseWithThis=(obj,replacer)=>{// Create a new result object or array
326
+ const result=Array.isArray(obj)?[]:{};// Traverse object properties or array elements
327
+ // eslint-disable-next-line no-restricted-syntax
328
+ for(const key in obj){if(Object.hasOwnProperty.call(obj,key)){const value=obj[key];// Recursively apply the replacer and traversal
329
+ const sanitizedValue=replacer.call(obj,key,value);// If the value is an object or array, continue traversal
330
+ if(isObjectLiteralAndNotNull(sanitizedValue)||Array.isArray(sanitizedValue)){result[key]=traverseWithThis(sanitizedValue,replacer);}else {result[key]=sanitizedValue;}}}return result;};/**
331
+ * Recursively traverses an object similar to JSON.stringify,
332
+ * sanitizing BigInts and circular references
333
+ * @param value Input object
334
+ * @param logger Logger instance
335
+ * @returns Sanitized value
336
+ */const getSanitizedValue=(value,logger)=>{const replacer=getReplacer();// This is needed for registering the first ancestor
337
+ const newValue=replacer.call(value,'',value);if(isObjectLiteralAndNotNull(value)||Array.isArray(value)){return traverseWithThis(value,replacer);}return newValue;};
311
338
 
312
339
  const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value=>value.replace(/ {2,}/g,' ');const removeLeadingPeriod=value=>value.replace(/^\.+/,'');/**
313
340
  * A function to convert values to string
@@ -333,28 +360,6 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
333
360
  * @returns decoded string
334
361
  */const fromBase64=value=>new TextDecoder().decode(base64ToBytes(value));
335
362
 
336
- 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.`;
337
-
338
- const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
339
- // eslint-disable-next-line func-names
340
- 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.
341
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
342
- // @ts-ignore-next-line
343
- 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]';}ancestors.push(value);return value;};};/**
344
- * Utility method for JSON stringify object excluding null values & circular references
345
- *
346
- * @param {*} value input
347
- * @param {boolean} excludeNull if it should exclude nul or not
348
- * @param {function} logger optional logger methods for warning
349
- * @returns string
350
- */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;}};/**
351
- * Recursively traverses an object similar to JSON.stringify,
352
- * sanitizing BigInts and circular references
353
- * @param value Input object
354
- * @param logger Logger instance
355
- * @returns Sanitized value
356
- */const getSanitizedValue=(value,logger)=>value;
357
-
358
363
  // if yes make them null instead of omitting in overloaded cases
359
364
  /*
360
365
  * Normalise the overloaded arguments of the page call facade
@@ -433,6 +438,20 @@ const getFormattedTimestamp=date=>date.toISOString();/**
433
438
  * @returns ISO formatted timestamp string
434
439
  */const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
435
440
 
441
+ const JSON_STRINGIFY='JSONStringify';const getCircularReplacer=(excludeNull,excludeKeys,logger)=>{const ancestors=[];// Here we do not want to use arrow function to use "this" in function context
442
+ // eslint-disable-next-line func-names
443
+ 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.
444
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
445
+ // @ts-ignore-next-line
446
+ 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]';}ancestors.push(value);return value;};};/**
447
+ * Utility method for JSON stringify object excluding null values & circular references
448
+ *
449
+ * @param {*} value input
450
+ * @param {boolean} excludeNull if it should exclude nul or not
451
+ * @param {function} logger optional logger methods for warning
452
+ * @returns string
453
+ */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;}};
454
+
436
455
  const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
437
456
  * Get mutated error with issue prepended to error message
438
457
  * @param err Original error
@@ -440,7 +459,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
440
459
  * @returns Instance of Error with message prepended with issue
441
460
  */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}));};
442
461
 
443
- const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.6';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';
462
+ const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.8';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';
444
463
 
445
464
  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';
446
465