@rudderstack/analytics-js 3.11.6 → 3.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/npm/legacy/bundled/cjs/index.cjs +52 -33
- package/dist/npm/legacy/bundled/esm/index.mjs +52 -33
- package/dist/npm/legacy/bundled/umd/index.js +52 -33
- package/dist/npm/legacy/cjs/index.cjs +52 -33
- package/dist/npm/legacy/content-script/cjs/index.cjs +52 -33
- package/dist/npm/legacy/content-script/esm/index.mjs +52 -33
- package/dist/npm/legacy/content-script/umd/index.js +52 -33
- package/dist/npm/legacy/esm/index.mjs +52 -33
- package/dist/npm/legacy/umd/index.js +52 -33
- package/dist/npm/modern/bundled/cjs/index.cjs +52 -33
- package/dist/npm/modern/bundled/esm/index.mjs +52 -33
- package/dist/npm/modern/bundled/umd/index.js +52 -33
- package/dist/npm/modern/cjs/index.cjs +51 -32
- package/dist/npm/modern/content-script/cjs/index.cjs +52 -33
- package/dist/npm/modern/content-script/esm/index.mjs +52 -33
- package/dist/npm/modern/content-script/umd/index.js +52 -33
- package/dist/npm/modern/esm/index.mjs +51 -32
- package/dist/npm/modern/umd/index.js +51 -32
- 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,59 +366,37 @@
|
|
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
|
367
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const
|
372
|
+
*/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,
|
368
373
|
// use it as name and set category to undefined
|
369
|
-
if(isString(
|
374
|
+
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
370
375
|
// and set some proper defaults
|
371
376
|
// Also, to clone the incoming object type arguments
|
372
377
|
if(!isDefined(payload.category)){payload.category=undefined;}if(!isDefined(payload.name)){payload.name=undefined;}payload.properties=payload.properties?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}const nameForProperties=isString(payload.name)?payload.name:payload.properties.name;const categoryForProperties=isString(payload.category)?payload.category:payload.properties.category;// add name and category to properties
|
373
378
|
payload.properties=mergeDeepRight(isObjectLiteralAndNotNull(payload.properties)?payload.properties:{},{...(nameForProperties&&{name:nameForProperties}),...(categoryForProperties&&{category:categoryForProperties})});return payload;};/*
|
374
379
|
* Normalise the overloaded arguments of the track call facade
|
375
|
-
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const
|
380
|
+
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const payload={name:event,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.properties=undefined;payload.options=undefined;payload.callback=properties;}// Rest of the code is just to clean up undefined values
|
376
381
|
// and set some proper defaults
|
377
382
|
// Also, to clone the incoming object type arguments
|
378
383
|
payload.properties=isDefinedAndNotNull(payload.properties)?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
379
384
|
* Normalise the overloaded arguments of the identify call facade
|
380
|
-
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const
|
385
|
+
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const payload={userId:userId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.userId=userId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.userId=userId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(userId)||isNull(userId)){// Explicitly set null to prevent resetting the existing value
|
381
386
|
// in the Analytics class
|
382
|
-
payload.userId=null;payload.traits=
|
387
|
+
payload.userId=null;payload.traits=userId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
383
388
|
// and set some proper defaults
|
384
389
|
// Also, to clone the incoming object type arguments
|
385
390
|
payload.userId=tryStringify(payload.userId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
386
391
|
* Normalise the overloaded arguments of the alias call facade
|
387
|
-
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const
|
392
|
+
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const payload={to,from:from,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.to=to;payload.from=from;payload.options=undefined;payload.callback=options;}if(isFunction(from)){payload.to=to;payload.from=undefined;payload.options=undefined;payload.callback=from;}else if(isObjectLiteralAndNotNull(from)||isNull(from)){payload.to=to;payload.from=undefined;payload.options=from;}// Rest of the code is just to clean up undefined values
|
388
393
|
// and set some proper defaults
|
389
394
|
// Also, to clone the incoming object type arguments
|
390
395
|
if(isDefined(payload.to)){payload.to=tryStringify(payload.to);}if(isDefined(payload.from)){payload.from=tryStringify(payload.from);}else {payload.from=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
391
396
|
* Normalise the overloaded arguments of the group call facade
|
392
|
-
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const
|
397
|
+
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const payload={groupId:groupId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.groupId=groupId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.groupId=groupId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(groupId)||isNull(groupId)){// Explicitly set null to prevent resetting the existing value
|
393
398
|
// in the Analytics class
|
394
|
-
payload.groupId=null;payload.traits=
|
399
|
+
payload.groupId=null;payload.traits=groupId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
395
400
|
// and set some proper defaults
|
396
401
|
// Also, to clone the incoming object type arguments
|
397
402
|
payload.groupId=tryStringify(payload.groupId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};
|
@@ -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.7';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
|
|
@@ -694,7 +713,7 @@
|
|
694
713
|
if(isFunction(globalThis.URL)){// eslint-disable-next-line no-new
|
695
714
|
new URL(url);}return URL_PATTERN.test(url);}catch(e){return false;}};
|
696
715
|
|
697
|
-
const isErrRetryable=details=>{let isRetryableNWFailure=false;if(details?.error&&details?.xhr){const xhrStatus=details.xhr.status;// same as in v1.1
|
716
|
+
const isErrRetryable=details=>{let isRetryableNWFailure=false;if(details?.error&&details?.xhr){const xhrStatus=getSanitizedValue(details.xhr).status;// same as in v1.1
|
698
717
|
isRetryableNWFailure=xhrStatus===429||xhrStatus>=500&&xhrStatus<600;}return isRetryableNWFailure;};
|
699
718
|
|
700
719
|
const userIdKey='rl_user_id';const userTraitsKey='rl_trait';const anonymousUserIdKey='rl_anonymous_id';const groupIdKey='rl_group_id';const groupTraitsKey='rl_group_trait';const pageInitialReferrerKey='rl_page_init_referrer';const pageInitialReferringDomainKey='rl_page_init_referring_domain';const sessionInfoKey='rl_session';const authTokenKey='rl_auth_token';const COOKIE_KEYS={userId:userIdKey,userTraits:userTraitsKey,anonymousId:anonymousUserIdKey,groupId:groupIdKey,groupTraits:groupTraitsKey,initialReferrer:pageInitialReferrerKey,initialReferringDomain:pageInitialReferringDomainKey,sessionInfo:sessionInfoKey,authToken:authTokenKey};const ENCRYPTION_PREFIX_V3='RS_ENC_v3_';
|
@@ -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,59 +351,37 @@ 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
|
352
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const
|
357
|
+
*/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,
|
353
358
|
// use it as name and set category to undefined
|
354
|
-
if(isString(
|
359
|
+
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
355
360
|
// and set some proper defaults
|
356
361
|
// Also, to clone the incoming object type arguments
|
357
362
|
if(!isDefined(payload.category)){payload.category=undefined;}if(!isDefined(payload.name)){payload.name=undefined;}payload.properties=payload.properties?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}const nameForProperties=isString(payload.name)?payload.name:payload.properties.name;const categoryForProperties=isString(payload.category)?payload.category:payload.properties.category;// add name and category to properties
|
358
363
|
payload.properties=mergeDeepRight(isObjectLiteralAndNotNull(payload.properties)?payload.properties:{},{...(nameForProperties&&{name:nameForProperties}),...(categoryForProperties&&{category:categoryForProperties})});return payload;};/*
|
359
364
|
* Normalise the overloaded arguments of the track call facade
|
360
|
-
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const
|
365
|
+
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const payload={name:event,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.properties=undefined;payload.options=undefined;payload.callback=properties;}// Rest of the code is just to clean up undefined values
|
361
366
|
// and set some proper defaults
|
362
367
|
// Also, to clone the incoming object type arguments
|
363
368
|
payload.properties=isDefinedAndNotNull(payload.properties)?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
364
369
|
* Normalise the overloaded arguments of the identify call facade
|
365
|
-
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const
|
370
|
+
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const payload={userId:userId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.userId=userId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.userId=userId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(userId)||isNull(userId)){// Explicitly set null to prevent resetting the existing value
|
366
371
|
// in the Analytics class
|
367
|
-
payload.userId=null;payload.traits=
|
372
|
+
payload.userId=null;payload.traits=userId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
368
373
|
// and set some proper defaults
|
369
374
|
// Also, to clone the incoming object type arguments
|
370
375
|
payload.userId=tryStringify(payload.userId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
371
376
|
* Normalise the overloaded arguments of the alias call facade
|
372
|
-
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const
|
377
|
+
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const payload={to,from:from,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.to=to;payload.from=from;payload.options=undefined;payload.callback=options;}if(isFunction(from)){payload.to=to;payload.from=undefined;payload.options=undefined;payload.callback=from;}else if(isObjectLiteralAndNotNull(from)||isNull(from)){payload.to=to;payload.from=undefined;payload.options=from;}// Rest of the code is just to clean up undefined values
|
373
378
|
// and set some proper defaults
|
374
379
|
// Also, to clone the incoming object type arguments
|
375
380
|
if(isDefined(payload.to)){payload.to=tryStringify(payload.to);}if(isDefined(payload.from)){payload.from=tryStringify(payload.from);}else {payload.from=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
376
381
|
* Normalise the overloaded arguments of the group call facade
|
377
|
-
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const
|
382
|
+
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const payload={groupId:groupId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.groupId=groupId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.groupId=groupId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(groupId)||isNull(groupId)){// Explicitly set null to prevent resetting the existing value
|
378
383
|
// in the Analytics class
|
379
|
-
payload.groupId=null;payload.traits=
|
384
|
+
payload.groupId=null;payload.traits=groupId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
380
385
|
// and set some proper defaults
|
381
386
|
// Also, to clone the incoming object type arguments
|
382
387
|
payload.groupId=tryStringify(payload.groupId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};
|
@@ -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.7';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,59 +357,37 @@
|
|
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
|
358
|
-
*/const pageArgumentsToCallOptions=(category,name,properties,options,callback)=>{const
|
363
|
+
*/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,
|
359
364
|
// use it as name and set category to undefined
|
360
|
-
if(isString(
|
365
|
+
if(isString(category)&&!isString(name)){payload.category=undefined;payload.name=category;}// Rest of the code is just to clean up undefined values
|
361
366
|
// and set some proper defaults
|
362
367
|
// Also, to clone the incoming object type arguments
|
363
368
|
if(!isDefined(payload.category)){payload.category=undefined;}if(!isDefined(payload.name)){payload.name=undefined;}payload.properties=payload.properties?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}const nameForProperties=isString(payload.name)?payload.name:payload.properties.name;const categoryForProperties=isString(payload.category)?payload.category:payload.properties.category;// add name and category to properties
|
364
369
|
payload.properties=mergeDeepRight(isObjectLiteralAndNotNull(payload.properties)?payload.properties:{},{...(nameForProperties&&{name:nameForProperties}),...(categoryForProperties&&{category:categoryForProperties})});return payload;};/*
|
365
370
|
* Normalise the overloaded arguments of the track call facade
|
366
|
-
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const
|
371
|
+
*/const trackArgumentsToCallOptions=(event,properties,options,callback)=>{const payload={name:event,properties:properties,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.properties=properties;payload.options=undefined;payload.callback=options;}if(isFunction(properties)){payload.properties=undefined;payload.options=undefined;payload.callback=properties;}// Rest of the code is just to clean up undefined values
|
367
372
|
// and set some proper defaults
|
368
373
|
// Also, to clone the incoming object type arguments
|
369
374
|
payload.properties=isDefinedAndNotNull(payload.properties)?clone(payload.properties):{};if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
370
375
|
* Normalise the overloaded arguments of the identify call facade
|
371
|
-
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const
|
376
|
+
*/const identifyArgumentsToCallOptions=(userId,traits,options,callback)=>{const payload={userId:userId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.userId=userId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.userId=userId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(userId)||isNull(userId)){// Explicitly set null to prevent resetting the existing value
|
372
377
|
// in the Analytics class
|
373
|
-
payload.userId=null;payload.traits=
|
378
|
+
payload.userId=null;payload.traits=userId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
374
379
|
// and set some proper defaults
|
375
380
|
// Also, to clone the incoming object type arguments
|
376
381
|
payload.userId=tryStringify(payload.userId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
377
382
|
* Normalise the overloaded arguments of the alias call facade
|
378
|
-
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const
|
383
|
+
*/const aliasArgumentsToCallOptions=(to,from,options,callback)=>{const payload={to,from:from,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.to=to;payload.from=from;payload.options=undefined;payload.callback=options;}if(isFunction(from)){payload.to=to;payload.from=undefined;payload.options=undefined;payload.callback=from;}else if(isObjectLiteralAndNotNull(from)||isNull(from)){payload.to=to;payload.from=undefined;payload.options=from;}// Rest of the code is just to clean up undefined values
|
379
384
|
// and set some proper defaults
|
380
385
|
// Also, to clone the incoming object type arguments
|
381
386
|
if(isDefined(payload.to)){payload.to=tryStringify(payload.to);}if(isDefined(payload.from)){payload.from=tryStringify(payload.from);}else {payload.from=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};/*
|
382
387
|
* Normalise the overloaded arguments of the group call facade
|
383
|
-
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const
|
388
|
+
*/const groupArgumentsToCallOptions=(groupId,traits,options,callback)=>{const payload={groupId:groupId,traits:traits,options:options,callback:undefined};if(isFunction(callback)){payload.callback=callback;}if(isFunction(options)){payload.groupId=groupId;payload.traits=traits;payload.options=undefined;payload.callback=options;}if(isFunction(traits)){payload.groupId=groupId;payload.traits=undefined;payload.options=undefined;payload.callback=traits;}if(isObjectLiteralAndNotNull(groupId)||isNull(groupId)){// Explicitly set null to prevent resetting the existing value
|
384
389
|
// in the Analytics class
|
385
|
-
payload.groupId=null;payload.traits=
|
390
|
+
payload.groupId=null;payload.traits=groupId;if(!isFunction(traits)){payload.options=traits;}else {payload.options=undefined;}}// Rest of the code is just to clean up undefined values
|
386
391
|
// and set some proper defaults
|
387
392
|
// Also, to clone the incoming object type arguments
|
388
393
|
payload.groupId=tryStringify(payload.groupId);if(isObjectLiteralAndNotNull(payload.traits)){payload.traits=clone(payload.traits);}else {payload.traits=undefined;}if(isDefined(payload.options)){payload.options=clone(payload.options);}else {payload.options=undefined;}return payload;};
|
@@ -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.7';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
|
|