@stytch/vanilla-js 4.18.2 → 5.0.0

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.
@@ -1264,7 +1264,6 @@ function _getPrototypeOf(o) {
1264
1264
  var TEST_API_URL = 'https://test.stytch.com';
1265
1265
  var LIVE_API_URL = 'https://api.stytch.com';
1266
1266
  var CLIENTSIDE_SERVICES_IFRAME_URL = 'https://js.stytch.com/clientside-services/index.html';
1267
- var STYTCH_WEB_BACKEND_URL = "https://web.stytch.com";
1268
1267
  var STYTCH_DFP_BACKEND_URL = "https://telemetry.stytch.com";
1269
1268
  var STYTCH_DFP_CDN_URL = "https://elements.stytch.com";
1270
1269
  var GOOGLE_ONE_TAP_HOST = 'https://accounts.google.com/gsi';
@@ -4713,132 +4712,6 @@ var HeadlessOAuthClient = /*#__PURE__*/function (_HeadlessOAuthClient$) {
4713
4712
  }
4714
4713
  return _createClass2(HeadlessOAuthClient);
4715
4714
  }(HeadlessOAuthClient$1);
4716
- var version = "4.18.2";
4717
- var NetworkClient = /*#__PURE__*/function () {
4718
- function NetworkClient(_publicToken, _subscriptionDataLayer, baseURL, additionalTelemetryDataFn) {
4719
- _classCallCheck2(this, NetworkClient);
4720
- this._publicToken = _publicToken;
4721
- this._subscriptionDataLayer = _subscriptionDataLayer;
4722
- this.baseURL = baseURL;
4723
- this.additionalTelemetryDataFn = additionalTelemetryDataFn;
4724
- this.updateSessionToken = function () {
4725
- return null;
4726
- };
4727
- this.eventLogger = new EventLogger({
4728
- maxBatchSize: DEFAULT_MAX_BATCH_SIZE,
4729
- intervalDurationMs: DEFAULT_INTERVAL_DURATION_MS,
4730
- logEventURL: this.buildSDKUrl('/events')
4731
- });
4732
- }
4733
- _createClass2(NetworkClient, [{
4734
- key: "logEvent",
4735
- value: function logEvent(_ref4) {
4736
- var name = _ref4.name,
4737
- details = _ref4.details,
4738
- _ref4$error = _ref4.error,
4739
- error = _ref4$error === void 0 ? {} : _ref4$error;
4740
- this.eventLogger.logEvent(this.createTelemetryBlob(), {
4741
- public_token: this._publicToken,
4742
- event_name: name,
4743
- details: details,
4744
- error_code: error.error_code,
4745
- error_description: error.error_description,
4746
- http_status_code: error.http_status_code
4747
- });
4748
- }
4749
- }, {
4750
- key: "createTelemetryBlob",
4751
- value: function createTelemetryBlob() {
4752
- return Object.assign(Object.assign({
4753
- event_id: createEventId(),
4754
- app_session_id: createAppSessionId(),
4755
- persistent_id: createPersistentId(),
4756
- client_sent_at: new Date().toISOString(),
4757
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
4758
- }, this.additionalTelemetryDataFn()), {
4759
- app: {
4760
- identifier: window.location.hostname
4761
- },
4762
- sdk: {
4763
- identifier: 'Stytch.js Javascript SDK',
4764
- version: version
4765
- }
4766
- });
4767
- }
4768
- }, {
4769
- key: "fetchSDK",
4770
- value: function fetchSDK(_ref5) {
4771
- var url = _ref5.url,
4772
- body = _ref5.body,
4773
- errorMessage = _ref5.errorMessage,
4774
- method = _ref5.method;
4775
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee12() {
4776
- var sessionToken, basicAuthHeader, xSDKClientHeader, xSDKParentHostHeader;
4777
- return _regeneratorRuntime2().wrap(function _callee12$(_context12) {
4778
- while (1) switch (_context12.prev = _context12.next) {
4779
- case 0:
4780
- sessionToken = this._subscriptionDataLayer.readSessionCookie().session_token;
4781
- basicAuthHeader = 'Basic ' + window.btoa(this._publicToken + ':' + (sessionToken || this._publicToken));
4782
- xSDKClientHeader = window.btoa(JSON.stringify(this.createTelemetryBlob()));
4783
- xSDKParentHostHeader = window.location.origin;
4784
- return _context12.abrupt("return", baseFetchSDK({
4785
- basicAuthHeader: basicAuthHeader,
4786
- body: body,
4787
- errorMessage: errorMessage,
4788
- finalURL: this.buildSDKUrl(url),
4789
- method: method,
4790
- xSDKClientHeader: xSDKClientHeader,
4791
- xSDKParentHostHeader: xSDKParentHostHeader
4792
- }));
4793
- case 5:
4794
- case "end":
4795
- return _context12.stop();
4796
- }
4797
- }, _callee12, this);
4798
- }));
4799
- }
4800
- }, {
4801
- key: "retriableFetchSDK",
4802
- value: function retriableFetchSDK(_ref6) {
4803
- var url = _ref6.url,
4804
- body = _ref6.body,
4805
- errorMessage = _ref6.errorMessage,
4806
- method = _ref6.method,
4807
- retryCallback = _ref6.retryCallback;
4808
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee59() {
4809
- var sessionToken, basicAuthHeader, xSDKClientHeader, xSDKParentHostHeader;
4810
- return _regeneratorRuntime2().wrap(function _callee59$(_context59) {
4811
- while (1) switch (_context59.prev = _context59.next) {
4812
- case 0:
4813
- sessionToken = this._subscriptionDataLayer.readSessionCookie().session_token;
4814
- basicAuthHeader = 'Basic ' + window.btoa(this._publicToken + ':' + (sessionToken || this._publicToken));
4815
- xSDKClientHeader = window.btoa(JSON.stringify(this.createTelemetryBlob()));
4816
- xSDKParentHostHeader = window.location.origin;
4817
- return _context59.abrupt("return", _retriableFetchSDK({
4818
- basicAuthHeader: basicAuthHeader,
4819
- body: body,
4820
- errorMessage: errorMessage,
4821
- finalURL: this.buildSDKUrl(url),
4822
- method: method,
4823
- xSDKClientHeader: xSDKClientHeader,
4824
- xSDKParentHostHeader: xSDKParentHostHeader,
4825
- retryCallback: retryCallback
4826
- }));
4827
- case 5:
4828
- case "end":
4829
- return _context59.stop();
4830
- }
4831
- }, _callee59, this);
4832
- }));
4833
- }
4834
- }, {
4835
- key: "buildSDKUrl",
4836
- value: function buildSDKUrl(url) {
4837
- return "".concat(this.baseURL, "/sdk/v1").concat(url);
4838
- }
4839
- }]);
4840
- return NetworkClient;
4841
- }();
4842
4715
  var navigatorSupportsFedCM = typeof window !== 'undefined' && 'IdentityCredential' in window;
4843
4716
  var getConfiguredEmbeddedMode = function getConfiguredEmbeddedMode(position) {
4844
4717
  if (position === OneTapPositions.forceLegacyEmbedded) {
@@ -4866,15 +4739,15 @@ var GoogleOneTapClient = /*#__PURE__*/function () {
4866
4739
  }
4867
4740
  }, {
4868
4741
  key: "render",
4869
- value: function render(_ref8) {
4870
- var callback = _ref8.callback,
4871
- onOneTapCancelled = _ref8.onOneTapCancelled,
4872
- style = _ref8.style;
4873
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee60() {
4742
+ value: function render(_ref4) {
4743
+ var callback = _ref4.callback,
4744
+ onOneTapCancelled = _ref4.onOneTapCancelled,
4745
+ style = _ref4.style;
4746
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee12() {
4874
4747
  var _this13 = this;
4875
4748
  var embeddedMode, shouldRenderEmbeddedOneTap, config;
4876
- return _regeneratorRuntime2().wrap(function _callee60$(_context60) {
4877
- while (1) switch (_context60.prev = _context60.next) {
4749
+ return _regeneratorRuntime2().wrap(function _callee12$(_context12) {
4750
+ while (1) switch (_context12.prev = _context12.next) {
4878
4751
  case 0:
4879
4752
  embeddedMode = getConfiguredEmbeddedMode(style.position);
4880
4753
  shouldRenderEmbeddedOneTap = getShouldRenderEmbeddedOneTap(style.position);
@@ -4891,7 +4764,7 @@ var GoogleOneTapClient = /*#__PURE__*/function () {
4891
4764
  config.cancel_on_tap_outside = false;
4892
4765
  }
4893
4766
  this._googleClient.initialize(config);
4894
- return _context60.abrupt("return", new Promise(function (resolve) {
4767
+ return _context12.abrupt("return", new Promise(function (resolve) {
4895
4768
  _this13._googleClient.prompt(function (notification) {
4896
4769
  var _a, _b, _c, _d, _e;
4897
4770
  if (notification.isSkippedMoment()) {
@@ -4920,9 +4793,9 @@ var GoogleOneTapClient = /*#__PURE__*/function () {
4920
4793
  }));
4921
4794
  case 6:
4922
4795
  case "end":
4923
- return _context60.stop();
4796
+ return _context12.stop();
4924
4797
  }
4925
- }, _callee60, this);
4798
+ }, _callee12, this);
4926
4799
  }));
4927
4800
  }
4928
4801
  }, {
@@ -4951,32 +4824,32 @@ var OneTapProvider = /*#__PURE__*/function () {
4951
4824
  _classCallCheck2(this, OneTapProvider);
4952
4825
  this._publicToken = _publicToken;
4953
4826
  this.clientsideServices = clientsideServices;
4954
- this.createOnSuccessHandler = function (_ref9) {
4955
- var loginRedirectUrl = _ref9.loginRedirectUrl,
4956
- signupRedirectUrl = _ref9.signupRedirectUrl,
4957
- onSuccess = _ref9.onSuccess;
4827
+ this.createOnSuccessHandler = function (_ref5) {
4828
+ var loginRedirectUrl = _ref5.loginRedirectUrl,
4829
+ signupRedirectUrl = _ref5.signupRedirectUrl,
4830
+ onSuccess = _ref5.onSuccess;
4958
4831
  return function (response) {
4959
- return __awaiter(_this14, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee61() {
4832
+ return __awaiter(_this14, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee59() {
4960
4833
  var credential, _yield$this$submitGoo, redirect_url;
4961
- return _regeneratorRuntime2().wrap(function _callee61$(_context61) {
4962
- while (1) switch (_context61.prev = _context61.next) {
4834
+ return _regeneratorRuntime2().wrap(function _callee59$(_context59) {
4835
+ while (1) switch (_context59.prev = _context59.next) {
4963
4836
  case 0:
4964
4837
  credential = response.credential;
4965
- _context61.next = 3;
4838
+ _context59.next = 3;
4966
4839
  return this.submitGoogleOneTapToken({
4967
4840
  credential: credential,
4968
4841
  loginRedirectUrl: loginRedirectUrl,
4969
4842
  signupRedirectUrl: signupRedirectUrl
4970
4843
  });
4971
4844
  case 3:
4972
- _yield$this$submitGoo = _context61.sent;
4845
+ _yield$this$submitGoo = _context59.sent;
4973
4846
  redirect_url = _yield$this$submitGoo.redirect_url;
4974
4847
  onSuccess(redirect_url);
4975
4848
  case 6:
4976
4849
  case "end":
4977
- return _context61.stop();
4850
+ return _context59.stop();
4978
4851
  }
4979
- }, _callee61, this);
4852
+ }, _callee59, this);
4980
4853
  }));
4981
4854
  };
4982
4855
  };
@@ -4987,53 +4860,53 @@ var OneTapProvider = /*#__PURE__*/function () {
4987
4860
  _createClass2(OneTapProvider, [{
4988
4861
  key: "createOneTapClient",
4989
4862
  value: function createOneTapClient() {
4990
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee62() {
4863
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee60() {
4991
4864
  var googleClientId, _yield$this$fetchGoog, err, client;
4992
- return _regeneratorRuntime2().wrap(function _callee62$(_context62) {
4993
- while (1) switch (_context62.prev = _context62.next) {
4865
+ return _regeneratorRuntime2().wrap(function _callee60$(_context60) {
4866
+ while (1) switch (_context60.prev = _context60.next) {
4994
4867
  case 0:
4995
- _context62.prev = 0;
4996
- _context62.next = 3;
4868
+ _context60.prev = 0;
4869
+ _context60.next = 3;
4997
4870
  return this.fetchGoogleStart();
4998
4871
  case 3:
4999
- _yield$this$fetchGoog = _context62.sent;
4872
+ _yield$this$fetchGoog = _context60.sent;
5000
4873
  googleClientId = _yield$this$fetchGoog.googleClientId;
5001
- _context62.next = 11;
4874
+ _context60.next = 11;
5002
4875
  break;
5003
4876
  case 7:
5004
- _context62.prev = 7;
5005
- _context62.t0 = _context62["catch"](0);
5006
- err = _context62.t0;
5007
- return _context62.abrupt("return", {
4877
+ _context60.prev = 7;
4878
+ _context60.t0 = _context60["catch"](0);
4879
+ err = _context60.t0;
4880
+ return _context60.abrupt("return", {
5008
4881
  success: false,
5009
4882
  reason: err.error_type
5010
4883
  });
5011
4884
  case 11:
5012
4885
  if (!(googleClientId === '')) {
5013
- _context62.next = 13;
4886
+ _context60.next = 13;
5014
4887
  break;
5015
4888
  }
5016
- return _context62.abrupt("return", {
4889
+ return _context60.abrupt("return", {
5017
4890
  success: false,
5018
4891
  reason: 'oauth_config_not_found'
5019
4892
  });
5020
4893
  case 13:
5021
- _context62.t1 = GoogleOneTapClient;
5022
- _context62.next = 16;
4894
+ _context60.t1 = GoogleOneTapClient;
4895
+ _context60.next = 16;
5023
4896
  return loadGoogleOneTapClient();
5024
4897
  case 16:
5025
- _context62.t2 = _context62.sent;
5026
- _context62.t3 = googleClientId;
5027
- client = new _context62.t1(_context62.t2, _context62.t3);
5028
- return _context62.abrupt("return", {
4898
+ _context60.t2 = _context60.sent;
4899
+ _context60.t3 = googleClientId;
4900
+ client = new _context60.t1(_context60.t2, _context60.t3);
4901
+ return _context60.abrupt("return", {
5029
4902
  success: true,
5030
4903
  client: client
5031
4904
  });
5032
4905
  case 20:
5033
4906
  case "end":
5034
- return _context62.stop();
4907
+ return _context60.stop();
5035
4908
  }
5036
- }, _callee62, this, [[0, 7]]);
4909
+ }, _callee60, this, [[0, 7]]);
5037
4910
  }));
5038
4911
  }
5039
4912
  }, {
@@ -5049,21 +4922,21 @@ var OneTapProvider = /*#__PURE__*/function () {
5049
4922
  }
5050
4923
  }, {
5051
4924
  key: "submitGoogleOneTapToken",
5052
- value: function submitGoogleOneTapToken(_ref10) {
5053
- var credential = _ref10.credential,
5054
- loginRedirectUrl = _ref10.loginRedirectUrl,
5055
- signupRedirectUrl = _ref10.signupRedirectUrl;
5056
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee63() {
4925
+ value: function submitGoogleOneTapToken(_ref6) {
4926
+ var credential = _ref6.credential,
4927
+ loginRedirectUrl = _ref6.loginRedirectUrl,
4928
+ signupRedirectUrl = _ref6.signupRedirectUrl;
4929
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee61() {
5057
4930
  var _yield$this$fetchGoog2, oauthCallbackId;
5058
- return _regeneratorRuntime2().wrap(function _callee63$(_context63) {
5059
- while (1) switch (_context63.prev = _context63.next) {
4931
+ return _regeneratorRuntime2().wrap(function _callee61$(_context61) {
4932
+ while (1) switch (_context61.prev = _context61.next) {
5060
4933
  case 0:
5061
- _context63.next = 2;
4934
+ _context61.next = 2;
5062
4935
  return this.fetchGoogleStart();
5063
4936
  case 2:
5064
- _yield$this$fetchGoog2 = _context63.sent;
4937
+ _yield$this$fetchGoog2 = _context61.sent;
5065
4938
  oauthCallbackId = _yield$this$fetchGoog2.oauthCallbackId;
5066
- return _context63.abrupt("return", this.clientsideServices.oneTapSubmit({
4939
+ return _context61.abrupt("return", this.clientsideServices.oneTapSubmit({
5067
4940
  publicToken: this._publicToken,
5068
4941
  idToken: credential,
5069
4942
  loginRedirectURL: loginRedirectUrl,
@@ -5072,9 +4945,9 @@ var OneTapProvider = /*#__PURE__*/function () {
5072
4945
  }));
5073
4946
  case 5:
5074
4947
  case "end":
5075
- return _context63.stop();
4948
+ return _context61.stop();
5076
4949
  }
5077
- }, _callee63, this);
4950
+ }, _callee61, this);
5078
4951
  }));
5079
4952
  }
5080
4953
  }], [{
@@ -5121,22 +4994,22 @@ var PKCEManager = /*#__PURE__*/function () {
5121
4994
  }, {
5122
4995
  key: "startPKCETransaction",
5123
4996
  value: function startPKCETransaction() {
5124
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee64() {
4997
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee62() {
5125
4998
  var keyPair;
5126
- return _regeneratorRuntime2().wrap(function _callee64$(_context64) {
5127
- while (1) switch (_context64.prev = _context64.next) {
4999
+ return _regeneratorRuntime2().wrap(function _callee62$(_context62) {
5000
+ while (1) switch (_context62.prev = _context62.next) {
5128
5001
  case 0:
5129
- _context64.next = 2;
5002
+ _context62.next = 2;
5130
5003
  return PKCEManager.createProofkeyPair();
5131
5004
  case 2:
5132
- keyPair = _context64.sent;
5005
+ keyPair = _context62.sent;
5133
5006
  this._dataLayer.setItem(this.key(), JSON.stringify(keyPair));
5134
- return _context64.abrupt("return", keyPair);
5007
+ return _context62.abrupt("return", keyPair);
5135
5008
  case 5:
5136
5009
  case "end":
5137
- return _context64.stop();
5010
+ return _context62.stop();
5138
5011
  }
5139
- }, _callee64, this);
5012
+ }, _callee62, this);
5140
5013
  }));
5141
5014
  }
5142
5015
  }, {
@@ -5161,36 +5034,36 @@ var PKCEManager = /*#__PURE__*/function () {
5161
5034
  }], [{
5162
5035
  key: "createProofkeyPair",
5163
5036
  value: function createProofkeyPair() {
5164
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee65() {
5037
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee63() {
5165
5038
  var bytes, codeVerifier, digest;
5166
- return _regeneratorRuntime2().wrap(function _callee65$(_context65) {
5167
- while (1) switch (_context65.prev = _context65.next) {
5039
+ return _regeneratorRuntime2().wrap(function _callee63$(_context63) {
5040
+ while (1) switch (_context63.prev = _context63.next) {
5168
5041
  case 0:
5169
5042
  bytes = new Uint32Array(16);
5170
5043
  window.crypto.getRandomValues(bytes);
5171
5044
  codeVerifier = Array.from(bytes).map(toHex).join('');
5172
- _context65.next = 5;
5045
+ _context63.next = 5;
5173
5046
  return window.crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier));
5174
5047
  case 5:
5175
- digest = _context65.sent;
5176
- return _context65.abrupt("return", {
5048
+ digest = _context63.sent;
5049
+ return _context63.abrupt("return", {
5177
5050
  code_challenge: base64URLEncode(digest),
5178
5051
  code_verifier: codeVerifier
5179
5052
  });
5180
5053
  case 7:
5181
5054
  case "end":
5182
- return _context65.stop();
5055
+ return _context63.stop();
5183
5056
  }
5184
- }, _callee65);
5057
+ }, _callee63);
5185
5058
  }));
5186
5059
  }
5187
5060
  }]);
5188
5061
  return PKCEManager;
5189
5062
  }();
5190
5063
  var createDeepEqual = function createDeepEqual() {
5191
- var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
5192
- _ref11$KEYS_TO_EXCLUD = _ref11.KEYS_TO_EXCLUDE,
5193
- KEYS_TO_EXCLUDE = _ref11$KEYS_TO_EXCLUD === void 0 ? [] : _ref11$KEYS_TO_EXCLUD;
5064
+ var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
5065
+ _ref8$KEYS_TO_EXCLUDE = _ref8.KEYS_TO_EXCLUDE,
5066
+ KEYS_TO_EXCLUDE = _ref8$KEYS_TO_EXCLUDE === void 0 ? [] : _ref8$KEYS_TO_EXCLUDE;
5194
5067
  var deepEqual = function deepEqual(a, b) {
5195
5068
  if (_typeof2(a) !== _typeof2(b)) return false;
5196
5069
  if (a === null || b === null) return a === b;
@@ -5198,14 +5071,14 @@ var createDeepEqual = function createDeepEqual() {
5198
5071
  if (Object.keys(a).length !== Object.keys(b).length || Object.keys(a).some(function (k) {
5199
5072
  return !(k in b);
5200
5073
  })) return false;
5201
- return Object.entries(a).filter(function (_ref12) {
5202
- var _ref13 = _slicedToArray2(_ref12, 1),
5203
- k = _ref13[0];
5074
+ return Object.entries(a).filter(function (_ref9) {
5075
+ var _ref10 = _slicedToArray2(_ref9, 1),
5076
+ k = _ref10[0];
5204
5077
  return !KEYS_TO_EXCLUDE.includes(k);
5205
- }).every(function (_ref14) {
5206
- var _ref15 = _slicedToArray2(_ref14, 2),
5207
- k = _ref15[0],
5208
- v = _ref15[1];
5078
+ }).every(function (_ref11) {
5079
+ var _ref12 = _slicedToArray2(_ref11, 2),
5080
+ k = _ref12[0],
5081
+ v = _ref12[1];
5209
5082
  return deepEqual(v, b[k]);
5210
5083
  });
5211
5084
  }
@@ -5217,15 +5090,14 @@ var isLocalhost = function isLocalhost() {
5217
5090
  return Boolean(window.location.hostname === 'localhost' || window.location.hostname === '[::1]' || window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));
5218
5091
  };
5219
5092
  var buildFinalConfig = function buildFinalConfig(opts) {
5220
- var _a, _b, _c, _d, _e, _f, _g, _h;
5093
+ var _a, _b, _c, _d, _e, _f;
5221
5094
  return {
5222
5095
  cookieOptions: opts === null || opts === void 0 ? void 0 : opts.cookieOptions,
5223
5096
  endpoints: {
5224
- sdkBackendURL: (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _a === void 0 ? void 0 : _a.sdkBackendURL) !== null && _b !== void 0 ? _b : STYTCH_WEB_BACKEND_URL,
5225
- testAPIURL: (_d = (_c = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _c === void 0 ? void 0 : _c.testAPIURL) !== null && _d !== void 0 ? _d : TEST_API_URL,
5226
- liveAPIURL: (_f = (_e = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _e === void 0 ? void 0 : _e.liveAPIURL) !== null && _f !== void 0 ? _f : LIVE_API_URL,
5097
+ testAPIURL: (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _a === void 0 ? void 0 : _a.testAPIURL) !== null && _b !== void 0 ? _b : TEST_API_URL,
5098
+ liveAPIURL: (_d = (_c = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _c === void 0 ? void 0 : _c.liveAPIURL) !== null && _d !== void 0 ? _d : LIVE_API_URL,
5227
5099
  dfpBackendURL: getDFPBackendURL(opts),
5228
- clientsideServicesIframeURL: (_h = (_g = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _g === void 0 ? void 0 : _g.clientsideServicesIframeURL) !== null && _h !== void 0 ? _h : CLIENTSIDE_SERVICES_IFRAME_URL
5100
+ clientsideServicesIframeURL: (_f = (_e = opts === null || opts === void 0 ? void 0 : opts.endpoints) === null || _e === void 0 ? void 0 : _e.clientsideServicesIframeURL) !== null && _f !== void 0 ? _f : CLIENTSIDE_SERVICES_IFRAME_URL
5229
5101
  }
5230
5102
  };
5231
5103
  };
@@ -5533,11 +5405,11 @@ var SubscriptionDataLayer = /*#__PURE__*/function () {
5533
5405
  }
5534
5406
  }], [{
5535
5407
  key: "generateCookieOpts",
5536
- value: function generateCookieOpts(_ref16) {
5537
- var path = _ref16.path,
5538
- domain = _ref16.domain,
5539
- availableToSubdomains = _ref16.availableToSubdomains,
5540
- expiresAt = _ref16.expiresAt;
5408
+ value: function generateCookieOpts(_ref13) {
5409
+ var path = _ref13.path,
5410
+ domain = _ref13.domain,
5411
+ availableToSubdomains = _ref13.availableToSubdomains,
5412
+ expiresAt = _ref13.expiresAt;
5541
5413
  var cookieOpts = {
5542
5414
  expires: new Date(expiresAt),
5543
5415
  sameSite: 'lax'
@@ -5775,18 +5647,135 @@ var internalSymB2C = Symbol["for"]('stytch__internal_b2c');
5775
5647
  var writeB2CInternals = function writeB2CInternals(obj, internals) {
5776
5648
  Object.assign(obj, _defineProperty({}, internalSymB2C, internals));
5777
5649
  };
5778
- var APINetworkClient = /*#__PURE__*/function (_NetworkClient) {
5779
- _inherits2(APINetworkClient, _NetworkClient);
5780
- function APINetworkClient(_publicToken, _subscriptionDataLayer, _liveAPIURL, _testAPIURL, _additionalTelemetryDataFn) {
5781
- _classCallCheck2(this, APINetworkClient);
5782
- var apiBackendURL = _liveAPIURL;
5650
+ var version = "5.0.0";
5651
+ var NetworkClient = /*#__PURE__*/function () {
5652
+ function NetworkClient(_publicToken, _subscriptionDataLayer, _liveAPIURL, _testAPIURL, additionalTelemetryDataFn) {
5653
+ _classCallCheck2(this, NetworkClient);
5654
+ this._publicToken = _publicToken;
5655
+ this._subscriptionDataLayer = _subscriptionDataLayer;
5656
+ this.additionalTelemetryDataFn = additionalTelemetryDataFn;
5657
+ this.updateSessionToken = function () {
5658
+ return null;
5659
+ };
5660
+ this.baseURL = _liveAPIURL;
5783
5661
  if (isTestPublicToken(_publicToken)) {
5784
- apiBackendURL = _testAPIURL;
5662
+ this.baseURL = _testAPIURL;
5785
5663
  }
5786
- return _callSuper2(this, APINetworkClient, [_publicToken, _subscriptionDataLayer, apiBackendURL, _additionalTelemetryDataFn]);
5664
+ this.eventLogger = new EventLogger({
5665
+ maxBatchSize: DEFAULT_MAX_BATCH_SIZE,
5666
+ intervalDurationMs: DEFAULT_INTERVAL_DURATION_MS,
5667
+ logEventURL: this.buildSDKUrl('/events')
5668
+ });
5787
5669
  }
5788
- return _createClass2(APINetworkClient);
5789
- }(NetworkClient);
5670
+ _createClass2(NetworkClient, [{
5671
+ key: "logEvent",
5672
+ value: function logEvent(_ref14) {
5673
+ var name = _ref14.name,
5674
+ details = _ref14.details,
5675
+ _ref14$error = _ref14.error,
5676
+ error = _ref14$error === void 0 ? {} : _ref14$error;
5677
+ this.eventLogger.logEvent(this.createTelemetryBlob(), {
5678
+ public_token: this._publicToken,
5679
+ event_name: name,
5680
+ details: details,
5681
+ error_code: error.error_code,
5682
+ error_description: error.error_description,
5683
+ http_status_code: error.http_status_code
5684
+ });
5685
+ }
5686
+ }, {
5687
+ key: "createTelemetryBlob",
5688
+ value: function createTelemetryBlob() {
5689
+ return Object.assign(Object.assign({
5690
+ event_id: createEventId(),
5691
+ app_session_id: createAppSessionId(),
5692
+ persistent_id: createPersistentId(),
5693
+ client_sent_at: new Date().toISOString(),
5694
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
5695
+ }, this.additionalTelemetryDataFn()), {
5696
+ app: {
5697
+ identifier: window.location.hostname
5698
+ },
5699
+ sdk: {
5700
+ identifier: 'Stytch.js Javascript SDK',
5701
+ version: version
5702
+ }
5703
+ });
5704
+ }
5705
+ }, {
5706
+ key: "fetchSDK",
5707
+ value: function fetchSDK(_ref15) {
5708
+ var url = _ref15.url,
5709
+ body = _ref15.body,
5710
+ errorMessage = _ref15.errorMessage,
5711
+ method = _ref15.method;
5712
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee64() {
5713
+ var sessionToken, basicAuthHeader, xSDKClientHeader, xSDKParentHostHeader;
5714
+ return _regeneratorRuntime2().wrap(function _callee64$(_context64) {
5715
+ while (1) switch (_context64.prev = _context64.next) {
5716
+ case 0:
5717
+ sessionToken = this._subscriptionDataLayer.readSessionCookie().session_token;
5718
+ basicAuthHeader = 'Basic ' + window.btoa(this._publicToken + ':' + (sessionToken || this._publicToken));
5719
+ xSDKClientHeader = window.btoa(JSON.stringify(this.createTelemetryBlob()));
5720
+ xSDKParentHostHeader = window.location.origin;
5721
+ return _context64.abrupt("return", baseFetchSDK({
5722
+ basicAuthHeader: basicAuthHeader,
5723
+ body: body,
5724
+ errorMessage: errorMessage,
5725
+ finalURL: this.buildSDKUrl(url),
5726
+ method: method,
5727
+ xSDKClientHeader: xSDKClientHeader,
5728
+ xSDKParentHostHeader: xSDKParentHostHeader
5729
+ }));
5730
+ case 5:
5731
+ case "end":
5732
+ return _context64.stop();
5733
+ }
5734
+ }, _callee64, this);
5735
+ }));
5736
+ }
5737
+ }, {
5738
+ key: "retriableFetchSDK",
5739
+ value: function retriableFetchSDK(_ref16) {
5740
+ var url = _ref16.url,
5741
+ body = _ref16.body,
5742
+ errorMessage = _ref16.errorMessage,
5743
+ method = _ref16.method,
5744
+ retryCallback = _ref16.retryCallback;
5745
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime2().mark(function _callee65() {
5746
+ var sessionToken, basicAuthHeader, xSDKClientHeader, xSDKParentHostHeader;
5747
+ return _regeneratorRuntime2().wrap(function _callee65$(_context65) {
5748
+ while (1) switch (_context65.prev = _context65.next) {
5749
+ case 0:
5750
+ sessionToken = this._subscriptionDataLayer.readSessionCookie().session_token;
5751
+ basicAuthHeader = 'Basic ' + window.btoa(this._publicToken + ':' + (sessionToken || this._publicToken));
5752
+ xSDKClientHeader = window.btoa(JSON.stringify(this.createTelemetryBlob()));
5753
+ xSDKParentHostHeader = window.location.origin;
5754
+ return _context65.abrupt("return", _retriableFetchSDK({
5755
+ basicAuthHeader: basicAuthHeader,
5756
+ body: body,
5757
+ errorMessage: errorMessage,
5758
+ finalURL: this.buildSDKUrl(url),
5759
+ method: method,
5760
+ xSDKClientHeader: xSDKClientHeader,
5761
+ xSDKParentHostHeader: xSDKParentHostHeader,
5762
+ retryCallback: retryCallback
5763
+ }));
5764
+ case 5:
5765
+ case "end":
5766
+ return _context65.stop();
5767
+ }
5768
+ }, _callee65, this);
5769
+ }));
5770
+ }
5771
+ }, {
5772
+ key: "buildSDKUrl",
5773
+ value: function buildSDKUrl(url) {
5774
+ return "".concat(this.baseURL, "/sdk/v1").concat(url);
5775
+ }
5776
+ }]);
5777
+ return NetworkClient;
5778
+ }();
5790
5779
  var StytchHeadlessClient = /*#__PURE__*/_createClass2(function StytchHeadlessClient(_PUBLIC_TOKEN, options) {
5791
5780
  var _this19 = this;
5792
5781
  _classCallCheck2(this, StytchHeadlessClient);
@@ -5809,8 +5798,7 @@ var StytchHeadlessClient = /*#__PURE__*/_createClass2(function StytchHeadlessCli
5809
5798
  };
5810
5799
  };
5811
5800
  var passwordsPKCEManager = new PKCEManager(this._dataLayer, 'passwords');
5812
- this._networkClient = new NetworkClient(_PUBLIC_TOKEN, this._dataLayer, config.endpoints.sdkBackendURL, additionalTelemetryDataFn);
5813
- this._apiNetworkClient = new APINetworkClient(_PUBLIC_TOKEN, this._dataLayer, config.endpoints.liveAPIURL, config.endpoints.testAPIURL, additionalTelemetryDataFn);
5801
+ this._networkClient = new NetworkClient(_PUBLIC_TOKEN, this._dataLayer, config.endpoints.liveAPIURL, config.endpoints.testAPIURL, additionalTelemetryDataFn);
5814
5802
  var bootstrap = new BootstrapDataManager(_PUBLIC_TOKEN, this._networkClient, this._dataLayer);
5815
5803
  var captcha = new CaptchaProvider(bootstrap.getAsync());
5816
5804
  var dfpProtectedAuth = new DFPProtectedAuthProvider(_PUBLIC_TOKEN, config.endpoints.dfpBackendURL, bootstrap.getAsync(), captcha.executeRecaptcha);
@@ -5826,7 +5814,7 @@ var StytchHeadlessClient = /*#__PURE__*/_createClass2(function StytchHeadlessCli
5826
5814
  testAPIURL: config.endpoints.testAPIURL,
5827
5815
  liveAPIURL: config.endpoints.liveAPIURL
5828
5816
  }, oneTap);
5829
- this.cryptoWallets = new HeadlessCryptoWalletClient(this._networkClient, this._apiNetworkClient, this._subscriptionService, captcha.executeRecaptcha, dfpProtectedAuth, bootstrap.getAsync());
5817
+ this.cryptoWallets = new HeadlessCryptoWalletClient(this._networkClient, this._networkClient, this._subscriptionService, captcha.executeRecaptcha, dfpProtectedAuth, bootstrap.getAsync());
5830
5818
  this.totps = new HeadlessTOTPClient(this._networkClient, this._subscriptionService, dfpProtectedAuth);
5831
5819
  this.webauthn = new HeadlessWebAuthnClient(this._networkClient, this._subscriptionService, dfpProtectedAuth);
5832
5820
  this.passwords = new HeadlessPasswordClient(this._networkClient, this._subscriptionService, passwordsPKCEManager, bootstrap.getAsync(), dfpProtectedAuth);