@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.
- package/CHANGELOG.md +19 -0
- package/dist/npm/legacy/bundled/cjs/index.cjs +43 -24
- package/dist/npm/legacy/bundled/esm/index.mjs +43 -24
- package/dist/npm/legacy/bundled/umd/index.js +43 -24
- package/dist/npm/legacy/cjs/index.cjs +43 -24
- package/dist/npm/legacy/content-script/cjs/index.cjs +43 -24
- package/dist/npm/legacy/content-script/esm/index.mjs +43 -24
- package/dist/npm/legacy/content-script/umd/index.js +43 -24
- package/dist/npm/legacy/esm/index.mjs +43 -24
- package/dist/npm/legacy/umd/index.js +43 -24
- package/dist/npm/modern/bundled/cjs/index.cjs +43 -24
- package/dist/npm/modern/bundled/esm/index.mjs +43 -24
- package/dist/npm/modern/bundled/umd/index.js +43 -24
- package/dist/npm/modern/cjs/index.cjs +43 -24
- package/dist/npm/modern/content-script/cjs/index.cjs +43 -24
- package/dist/npm/modern/content-script/esm/index.mjs +43 -24
- package/dist/npm/modern/content-script/umd/index.js +43 -24
- package/dist/npm/modern/esm/index.mjs +43 -24
- package/dist/npm/modern/umd/index.js +43 -24
- package/package.json +1 -1
@@ -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.
|
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
|
|
@@ -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
|
@@ -324,28 +351,6 @@ const trim=value=>value.replace(/^\s+|\s+$/gm,'');const removeDoubleSpaces=value
|
|
324
351
|
* @returns base64 encoded string
|
325
352
|
*/const toBase64=value=>bytesToBase64(new TextEncoder().encode(value));
|
326
353
|
|
327
|
-
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.`;
|
328
|
-
|
329
|
-
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
|
330
|
-
// eslint-disable-next-line func-names
|
331
|
-
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.
|
332
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
333
|
-
// @ts-ignore-next-line
|
334
|
-
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;};};/**
|
335
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
336
|
-
*
|
337
|
-
* @param {*} value input
|
338
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
339
|
-
* @param {function} logger optional logger methods for warning
|
340
|
-
* @returns string
|
341
|
-
*/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;}};/**
|
342
|
-
* Recursively traverses an object similar to JSON.stringify,
|
343
|
-
* sanitizing BigInts and circular references
|
344
|
-
* @param value Input object
|
345
|
-
* @param logger Logger instance
|
346
|
-
* @returns Sanitized value
|
347
|
-
*/const getSanitizedValue=(value,logger)=>value;
|
348
|
-
|
349
354
|
// if yes make them null instead of omitting in overloaded cases
|
350
355
|
/*
|
351
356
|
* Normalise the overloaded arguments of the page call facade
|
@@ -424,6 +429,20 @@ const getFormattedTimestamp=date=>date.toISOString();/**
|
|
424
429
|
* @returns ISO formatted timestamp string
|
425
430
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
426
431
|
|
432
|
+
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
|
433
|
+
// eslint-disable-next-line func-names
|
434
|
+
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.
|
435
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
436
|
+
// @ts-ignore-next-line
|
437
|
+
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;};};/**
|
438
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
439
|
+
*
|
440
|
+
* @param {*} value input
|
441
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
442
|
+
* @param {function} logger optional logger methods for warning
|
443
|
+
* @returns string
|
444
|
+
*/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;}};
|
445
|
+
|
427
446
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
428
447
|
* Get mutated error with issue prepended to error message
|
429
448
|
* @param err Original error
|
@@ -431,7 +450,7 @@ const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
|
431
450
|
* @returns Instance of Error with message prepended with issue
|
432
451
|
*/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}));};
|
433
452
|
|
434
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
453
|
+
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';
|
435
454
|
|
436
455
|
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';
|
437
456
|
|
@@ -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
|
@@ -330,28 +357,6 @@
|
|
330
357
|
* @returns base64 encoded string
|
331
358
|
*/const toBase64=value=>bytesToBase64(new TextEncoder().encode(value));
|
332
359
|
|
333
|
-
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.`;
|
334
|
-
|
335
|
-
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
|
336
|
-
// eslint-disable-next-line func-names
|
337
|
-
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.
|
338
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
339
|
-
// @ts-ignore-next-line
|
340
|
-
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;};};/**
|
341
|
-
* Utility method for JSON stringify object excluding null values & circular references
|
342
|
-
*
|
343
|
-
* @param {*} value input
|
344
|
-
* @param {boolean} excludeNull if it should exclude nul or not
|
345
|
-
* @param {function} logger optional logger methods for warning
|
346
|
-
* @returns string
|
347
|
-
*/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;}};/**
|
348
|
-
* Recursively traverses an object similar to JSON.stringify,
|
349
|
-
* sanitizing BigInts and circular references
|
350
|
-
* @param value Input object
|
351
|
-
* @param logger Logger instance
|
352
|
-
* @returns Sanitized value
|
353
|
-
*/const getSanitizedValue=(value,logger)=>value;
|
354
|
-
|
355
360
|
// if yes make them null instead of omitting in overloaded cases
|
356
361
|
/*
|
357
362
|
* Normalise the overloaded arguments of the page call facade
|
@@ -430,6 +435,20 @@
|
|
430
435
|
* @returns ISO formatted timestamp string
|
431
436
|
*/const getCurrentTimeFormatted=()=>getFormattedTimestamp(new Date());
|
432
437
|
|
438
|
+
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
|
439
|
+
// eslint-disable-next-line func-names
|
440
|
+
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.
|
441
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
442
|
+
// @ts-ignore-next-line
|
443
|
+
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;};};/**
|
444
|
+
* Utility method for JSON stringify object excluding null values & circular references
|
445
|
+
*
|
446
|
+
* @param {*} value input
|
447
|
+
* @param {boolean} excludeNull if it should exclude nul or not
|
448
|
+
* @param {function} logger optional logger methods for warning
|
449
|
+
* @returns string
|
450
|
+
*/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;}};
|
451
|
+
|
433
452
|
const MANUAL_ERROR_IDENTIFIER='[MANUAL ERROR]';/**
|
434
453
|
* Get mutated error with issue prepended to error message
|
435
454
|
* @param err Original error
|
@@ -437,7 +456,7 @@
|
|
437
456
|
* @returns Instance of Error with message prepended with issue
|
438
457
|
*/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}));};
|
439
458
|
|
440
|
-
const APP_NAME='RudderLabs JavaScript SDK';const APP_VERSION='3.11.
|
459
|
+
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';
|
441
460
|
|
442
461
|
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';
|
443
462
|
|