rudder-sdk-js 2.12.1 → 2.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +115 -106
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -71,6 +71,8 @@ declare module "rudder-sdk-js" {
71
71
  loadIntegration?: boolean;
72
72
  // Defaults to false
73
73
  secureCookie?: boolean;
74
+ // Defaults to "Lax" (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite)
75
+ sameSiteCookie?: string;
74
76
  logLevel?: string;
75
77
  getSourceConfig?: () =>
76
78
  | string
@@ -85,6 +87,8 @@ declare module "rudder-sdk-js" {
85
87
  beaconQueueOptions?: beaconQueueOptions;
86
88
  cookieConsentManager?: cookieConsentManager;
87
89
  anonymousIdOptions?: anonymousIdOptions;
90
+ // defaults to https://cdn.rudderlabs.com/v1.1/js-integrations
91
+ destSDKBaseURL?: string;
88
92
  }
89
93
 
90
94
  /**
package/index.js CHANGED
@@ -4598,20 +4598,26 @@
4598
4598
  var LOG_LEVEL_DEBUG = 2;
4599
4599
  var LOG_LEVEL_WARN = 3;
4600
4600
  var LOG_LEVEL_ERROR = 4;
4601
- var LOG_LEVEL = LOG_LEVEL_ERROR;
4601
+ var DEF_LOG_LEVEL = LOG_LEVEL_ERROR;
4602
+ var LOG_LEVEL = DEF_LOG_LEVEL;
4602
4603
  var logger = {
4603
4604
  setLogLevel: function setLogLevel(logLevel) {
4604
4605
  switch (logLevel.toUpperCase()) {
4605
4606
  case 'INFO':
4606
4607
  LOG_LEVEL = LOG_LEVEL_INFO;
4607
- return;
4608
+ break;
4608
4609
 
4609
4610
  case 'DEBUG':
4610
4611
  LOG_LEVEL = LOG_LEVEL_DEBUG;
4611
- return;
4612
+ break;
4612
4613
 
4613
4614
  case 'WARN':
4614
4615
  LOG_LEVEL = LOG_LEVEL_WARN;
4616
+ break;
4617
+
4618
+ default:
4619
+ LOG_LEVEL = DEF_LOG_LEVEL;
4620
+ break;
4615
4621
  }
4616
4622
  },
4617
4623
  info: function info() {
@@ -4980,7 +4986,7 @@
4980
4986
 
4981
4987
  // Reserved Keywords for properties/traits
4982
4988
  var RESERVED_KEYS = ['anonymous_id', 'id', 'sent_at', 'received_at', 'timestamp', 'original_timestamp', 'event_text', 'event'];
4983
- var CONFIG_URL = 'https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.12.1';
4989
+ var CONFIG_URL = 'https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.12.2';
4984
4990
  var CDN_INT_DIR = 'js-integrations';
4985
4991
  var DEST_SDK_BASE_URL = "https://cdn.rudderlabs.com/v1.1/".concat(CDN_INT_DIR);
4986
4992
  var MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
@@ -4989,6 +4995,7 @@
4989
4995
  var POLYFILL_URL = 'https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.find%2CArray.prototype.includes%2CPromise%2CString.prototype.endsWith%2CString.prototype.includes%2CString.prototype.startsWith%2CObject.entries%2CObject.values%2CElement.prototype.dataset%2CString.prototype.replaceAll';
4990
4996
  var DEFAULT_ERROR_REPORT_PROVIDER = 'bugsnag';
4991
4997
  var ERROR_REPORT_PROVIDERS = [DEFAULT_ERROR_REPORT_PROVIDER];
4998
+ var SAMESITE_COOKIE_OPTS = ['Lax', 'None', 'Strict'];
4992
4999
 
4993
5000
  var aes = {exports: {}};
4994
5001
 
@@ -9767,7 +9774,7 @@
9767
9774
  function StoreLocal(options) {
9768
9775
  _classCallCheck(this, StoreLocal);
9769
9776
 
9770
- this._options = {};
9777
+ this.sOpts = {};
9771
9778
  this.enabled = this.checkSupportAvailability();
9772
9779
  this.options(options);
9773
9780
  }
@@ -9782,12 +9789,13 @@
9782
9789
  value: function options() {
9783
9790
  var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9784
9791
 
9785
- if (arguments.length === 0) return this._options;
9792
+ if (arguments.length === 0) return this.sOpts;
9786
9793
  defaults$3.exports(_options, {
9787
9794
  enabled: true
9788
9795
  });
9789
9796
  this.enabled = _options.enabled && this.enabled;
9790
- this._options = _options;
9797
+ this.sOpts = _options;
9798
+ return this.sOpts;
9791
9799
  }
9792
9800
  /**
9793
9801
  *
@@ -10630,7 +10638,7 @@
10630
10638
  this.build = '1.0.0';
10631
10639
  this.name = 'RudderLabs JavaScript SDK';
10632
10640
  this.namespace = 'com.rudderlabs.javascript';
10633
- this.version = '2.12.1';
10641
+ this.version = '2.12.2';
10634
10642
  });
10635
10643
 
10636
10644
  /* eslint-disable max-classes-per-file */
@@ -10639,7 +10647,7 @@
10639
10647
  _classCallCheck(this, RudderLibraryInfo);
10640
10648
 
10641
10649
  this.name = 'RudderLabs JavaScript SDK';
10642
- this.version = '2.12.1';
10650
+ this.version = '2.12.2';
10643
10651
  }); // Operating System information class
10644
10652
 
10645
10653
 
@@ -12607,9 +12615,6 @@
12607
12615
  handleError(new Error("request failed with status: ".concat(xhr.status).concat(xhr.statusText, " for url: ").concat(url)));
12608
12616
  queueFn(new Error("request failed with status: ".concat(xhr.status).concat(xhr.statusText, " for url: ").concat(url)));
12609
12617
  } else {
12610
- // logger.debug(
12611
- // `====== request processed successfully: ${xhr.status}`
12612
- // );
12613
12618
  queueFn(null, xhr.status);
12614
12619
  }
12615
12620
  }
@@ -12730,7 +12735,7 @@
12730
12735
  }, {
12731
12736
  key: "flushQueue",
12732
12737
  value: function flushQueue(batch) {
12733
- batch.map(function (event) {
12738
+ batch.forEach(function (event) {
12734
12739
  event.sentAt = new Date().toISOString();
12735
12740
  });
12736
12741
  var data = {
@@ -12740,9 +12745,11 @@
12740
12745
  var blob = new Blob([payload], {
12741
12746
  type: 'text/plain'
12742
12747
  });
12743
- navigator.sendBeacon("".concat(this.url, "?writeKey=").concat(this.writekey), blob); // if (!isPushed) {
12744
- // logger.debug("Unable to send data");
12745
- // }
12748
+ var isPushed = navigator.sendBeacon("".concat(this.url, "?writeKey=").concat(this.writekey), blob);
12749
+
12750
+ if (!isPushed) {
12751
+ handleError(new Error("Unable to queue data to browser's beacon queue"));
12752
+ }
12746
12753
 
12747
12754
  this.setQueue([]);
12748
12755
  this.clearTimer();
@@ -12843,6 +12850,8 @@
12843
12850
 
12844
12851
  var eventRepository = new EventRepository();
12845
12852
 
12853
+ /* eslint-disable no-bitwise */
12854
+
12846
12855
  /**
12847
12856
  * @description This is utility function for crc32 algorithm
12848
12857
  * @version v1.0.0
@@ -12851,7 +12860,7 @@
12851
12860
  /**
12852
12861
  * @description generate crc table
12853
12862
  * @params none
12854
- * @returns arrray of CRC table
12863
+ * @returns array of CRC table
12855
12864
  */
12856
12865
  var makeCRCTable = function makeCRCTable() {
12857
12866
  var crcTable = [];
@@ -12872,7 +12881,7 @@
12872
12881
  /**
12873
12882
  *
12874
12883
  * @param {string} str
12875
- * @returns {Bystream} crc32
12884
+ * @returns {Bytestream} crc32
12876
12885
  */
12877
12886
 
12878
12887
 
@@ -12945,38 +12954,15 @@
12945
12954
  var CHECKSUM_OFFSET_MAX_MIN = 1;
12946
12955
  var VALID_VERSION = 1;
12947
12956
  var DELIMITER = '*';
12948
- /**
12949
- * Return the key value pairs
12950
- * @param {string} value
12951
- * @return {?Object<string, string>}
12952
- */
12953
-
12954
- function parseLinker(value) {
12955
- var linkerObj = parseLinkerParamValue(value);
12956
-
12957
- if (!linkerObj) {
12958
- return null;
12959
- }
12960
-
12961
- var checksum = linkerObj.checksum,
12962
- serializedIds = linkerObj.serializedIds;
12963
-
12964
- if (!isCheckSumValid(serializedIds, checksum)) {
12965
- return null;
12966
- }
12967
-
12968
- return deserialize(serializedIds);
12969
- }
12970
12957
  /**
12971
12958
  * Parse the linker param value to version checksum and serializedParams
12972
12959
  * @param {string} value
12973
12960
  * @return {?Object}
12974
12961
  */
12975
12962
 
12976
-
12977
12963
  function parseLinkerParamValue(value) {
12978
12964
  var parts = value.split(DELIMITER);
12979
- var isEven = parts.length % 2 == 0;
12965
+ var isEven = parts.length % 2 === 0;
12980
12966
 
12981
12967
  if (parts.length < 4 || !isEven) {
12982
12968
  // Format <version>*<checksum>*<key1>*<value1>
@@ -12998,28 +12984,6 @@
12998
12984
  serializedIds: serializedIds
12999
12985
  };
13000
12986
  }
13001
- /**
13002
- * Check if the checksum is valid with time offset tolerance.
13003
- * @param {string} serializedIds
13004
- * @param {string} checksum
13005
- * @return {boolean}
13006
- */
13007
-
13008
-
13009
- function isCheckSumValid(serializedIds, checksum) {
13010
- var userAgent = USER_INTERFACE.getUserAgent();
13011
- var language = USER_INTERFACE.getUserLanguage();
13012
-
13013
- for (var i = 0; i <= CHECKSUM_OFFSET_MAX_MIN; i++) {
13014
- var calculateCheckSum = getCheckSum(serializedIds, i, userAgent, language);
13015
-
13016
- if (calculateCheckSum == checksum) {
13017
- return true;
13018
- }
13019
- }
13020
-
13021
- return false;
13022
- }
13023
12987
  /**
13024
12988
  * Deserialize the serializedIds and return keyValue pairs.
13025
12989
  * @param {string} serializedIds
@@ -13035,53 +12999,96 @@
13035
12999
  var key = params[i];
13036
13000
  var valid = KEY_VALIDATOR.test(key);
13037
13001
 
13038
- if (!valid) {
13039
- continue;
13040
- }
13002
+ if (valid) {
13003
+ var value = decode(params[i + 1]); // const value = params[i + 1];
13041
13004
 
13042
- var value = decode(params[i + 1]); // const value = params[i + 1];
13043
-
13044
- keyValuePairs[key] = value;
13005
+ keyValuePairs[key] = value;
13006
+ }
13045
13007
  }
13046
13008
 
13047
13009
  return keyValuePairs;
13048
13010
  }
13011
+ /**
13012
+ * Generates a semi-unique value for page visitor.
13013
+ * @return {string}
13014
+ */
13015
+
13016
+
13017
+ function getFingerprint(userAgent, language) {
13018
+ var date = new Date();
13019
+ var timezone = date.getTimezoneOffset();
13020
+ return [userAgent, timezone, language].join(DELIMITER);
13021
+ }
13022
+ /**
13023
+ * Rounded time used to check if t2 - t1 is within our time tolerance.
13024
+ * @return {number}
13025
+ */
13026
+
13027
+
13028
+ function getMinSinceEpoch() {
13029
+ // Timestamp in minutes, floored.
13030
+ return Math.floor(Date.now() / 60000);
13031
+ }
13049
13032
  /**
13050
13033
  * Create a unique checksum hashing the fingerprint and a few other values.
13051
13034
  * @param {string} serializedIds
13052
- * @param {number=} opt_offsetMin
13035
+ * @param {number=} optOffsetMin
13053
13036
  * @return {string}
13054
13037
  */
13055
13038
 
13056
13039
 
13057
- function getCheckSum(serializedIds, opt_offsetMin, userAgent, language) {
13040
+ function getCheckSum(serializedIds, optOffsetMin, userAgent, language) {
13058
13041
  var fingerprint = getFingerprint(userAgent, language);
13059
- var offset = opt_offsetMin || 0;
13042
+ var offset = optOffsetMin || 0;
13060
13043
  var timestamp = getMinSinceEpoch() - offset;
13061
13044
  var crc = crc32([fingerprint, timestamp, serializedIds].join(DELIMITER)); // Encoded to base36 for less bytes.
13062
13045
 
13063
13046
  return crc.toString(36);
13064
13047
  }
13065
13048
  /**
13066
- * Generates a semi-unique value for page visitor.
13067
- * @return {string}
13049
+ * Check if the checksum is valid with time offset tolerance.
13050
+ * @param {string} serializedIds
13051
+ * @param {string} checksum
13052
+ * @return {boolean}
13068
13053
  */
13069
13054
 
13070
13055
 
13071
- function getFingerprint(userAgent, language) {
13072
- var date = new Date();
13073
- var timezone = date.getTimezoneOffset();
13074
- return [userAgent, timezone, language].join(DELIMITER);
13056
+ function isCheckSumValid(serializedIds, checksum) {
13057
+ var userAgent = USER_INTERFACE.getUserAgent();
13058
+ var language = USER_INTERFACE.getUserLanguage();
13059
+
13060
+ for (var i = 0; i <= CHECKSUM_OFFSET_MAX_MIN; i += 1) {
13061
+ var calculateCheckSum = getCheckSum(serializedIds, i, userAgent, language);
13062
+
13063
+ if (calculateCheckSum === checksum) {
13064
+ return true;
13065
+ }
13066
+ }
13067
+
13068
+ return false;
13075
13069
  }
13076
13070
  /**
13077
- * Rounded time used to check if t2 - t1 is within our time tolerance.
13078
- * @return {number}
13071
+ * Return the key value pairs
13072
+ * @param {string} value
13073
+ * @return {?Object<string, string>}
13079
13074
  */
13080
13075
 
13081
13076
 
13082
- function getMinSinceEpoch() {
13083
- // Timestamp in minutes, floored.
13084
- return Math.floor(Date.now() / 60000);
13077
+ function parseLinker(value) {
13078
+ var linkerObj = parseLinkerParamValue(value);
13079
+
13080
+ if (!linkerObj) {
13081
+ return null;
13082
+ }
13083
+
13084
+ var checksum = linkerObj.checksum,
13085
+ serializedIds = linkerObj.serializedIds;
13086
+
13087
+ if (!isCheckSumValid(serializedIds, checksum)) {
13088
+ return null;
13089
+ }
13090
+
13091
+ return deserialize(serializedIds);
13085
13092
  }
13086
13093
 
13087
13094
  // map b/w the names of integrations coming from config plane to
@@ -13310,7 +13317,7 @@
13310
13317
  var devHosts = ['localhost', '127.0.0.1', '[::1]'];
13311
13318
  window.rsBugsnagClient = window.Bugsnag.start({
13312
13319
  apiKey: API_KEY,
13313
- appVersion: '2.12.1',
13320
+ appVersion: '2.12.2',
13314
13321
  // Set SDK version as the app version
13315
13322
  metadata: META_DATA,
13316
13323
  onError: function onError(event) {
@@ -13457,18 +13464,16 @@
13457
13464
  // "All integrations loaded dynamically",
13458
13465
  // this.dynamicallyLoadedIntegrations
13459
13466
  // );
13460
- return resolve(_this);
13461
- }
13462
-
13463
- if (time >= 2 * MAX_WAIT_FOR_INTEGRATION_LOAD) {
13467
+ resolve(_this);
13468
+ } else if (time >= 2 * MAX_WAIT_FOR_INTEGRATION_LOAD) {
13464
13469
  // logger.debug("Max wait for dynamically loaded integrations over")
13465
- return resolve(_this);
13470
+ resolve(_this);
13471
+ } else {
13472
+ _this.pause(INTEGRATION_LOAD_CHECK_INTERVAL).then(function () {
13473
+ // logger.debug("Check if all integration SDKs are loaded after pause")
13474
+ return _this.allModulesInitialized(time + INTEGRATION_LOAD_CHECK_INTERVAL).then(resolve);
13475
+ });
13466
13476
  }
13467
-
13468
- return _this.pause(INTEGRATION_LOAD_CHECK_INTERVAL).then(function () {
13469
- // logger.debug("Check if all integration SDKs are loaded after pause")
13470
- return _this.allModulesInitialized(time + INTEGRATION_LOAD_CHECK_INTERVAL).then(resolve);
13471
- });
13472
13477
  });
13473
13478
  }
13474
13479
  /**
@@ -13742,20 +13747,18 @@
13742
13747
  // logger.debug("===integration loaded successfully====", instance.name)
13743
13748
  _this3.successfullyLoadedIntegration.push(instance);
13744
13749
 
13745
- return resolve(_this3);
13746
- }
13747
-
13748
- if (time >= MAX_WAIT_FOR_INTEGRATION_LOAD) {
13750
+ resolve(_this3);
13751
+ } else if (time >= MAX_WAIT_FOR_INTEGRATION_LOAD) {
13749
13752
  // logger.debug("====max wait over====")
13750
13753
  _this3.failedToBeLoadedIntegration.push(instance);
13751
13754
 
13752
- return resolve(_this3);
13755
+ resolve(_this3);
13756
+ } else {
13757
+ _this3.pause(INTEGRATION_LOAD_CHECK_INTERVAL).then(function () {
13758
+ // logger.debug("====after pause, again checking====")
13759
+ return _this3.isInitialized(instance, time + INTEGRATION_LOAD_CHECK_INTERVAL).then(resolve);
13760
+ });
13753
13761
  }
13754
-
13755
- return _this3.pause(INTEGRATION_LOAD_CHECK_INTERVAL).then(function () {
13756
- // logger.debug("====after pause, again checking====")
13757
- return _this3.isInitialized(instance, time + INTEGRATION_LOAD_CHECK_INTERVAL).then(resolve);
13758
- });
13759
13762
  });
13760
13763
  }
13761
13764
  /**
@@ -14296,12 +14299,18 @@
14296
14299
  });
14297
14300
  }
14298
14301
 
14299
- if (options && options.secureCookie) {
14302
+ if (options && typeof options.secureCookie === 'boolean') {
14300
14303
  storageOptions = _objectSpread2(_objectSpread2({}, storageOptions), {}, {
14301
14304
  secure: options.secureCookie
14302
14305
  });
14303
14306
  }
14304
14307
 
14308
+ if (options && SAMESITE_COOKIE_OPTS.includes(options.sameSiteCookie)) {
14309
+ storageOptions = _objectSpread2(_objectSpread2({}, storageOptions), {}, {
14310
+ samesite: options.sameSiteCookie
14311
+ });
14312
+ }
14313
+
14305
14314
  this.storage.options(storageOptions);
14306
14315
 
14307
14316
  if (options && options.integrations) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rudder-sdk-js",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "RudderStack Javascript SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",