@stytch/vanilla-js 2.0.1 → 2.0.3

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.
@@ -1,5 +1,4229 @@
1
- function e(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||r(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||r(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&o(e,t)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function s(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=c(e);if(t){var i=c(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===l(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return a(e)}(this,r)}}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */u=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function h(e,t,r,i){var o=t&&t.prototype instanceof f?t:f,s=Object.create(o.prototype),a=new x(i||[]);return n(s,"_invoke",{value:S(e,r,a)}),s}function d(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=h;var p={};function f(){}function v(){}function _(){}var m={};c(m,o,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(C([])));g&&g!==t&&r.call(g,o)&&(m=g);var b=_.prototype=f.prototype=Object.create(m);function w(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function i(n,o,s,a){var c=d(e[n],e,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==l(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){i("next",e,s,a)}),(function(e){i("throw",e,s,a)})):t.resolve(h).then((function(e){u.value=e,s(u)}),(function(e){return i("throw",e,s,a)}))}a(c.arg)}var o;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){i(e,r,t,n)}))}return o=o?o.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return A()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=O(s,r);if(a){if(a===p)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=d(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=d(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,p;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function C(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}return v.prototype=_,n(b,"constructor",{value:_,configurable:!0}),n(_,"constructor",{value:v,configurable:!0}),v.displayName=c(_,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,_):(e.__proto__=_,c(e,a,"GeneratorFunction")),e.prototype=Object.create(b),e},e.awrap=function(e){return{__await:e}},w(k.prototype),c(k.prototype,s,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var s=new k(h(t,r,n,i),o);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},w(b),c(b,a,"Generator"),c(b,o,(function(){return this})),c(b,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=C,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},e}function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function d(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,f(n.key),n)}}function p(e,t,r){return t&&d(e.prototype,t),r&&d(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e){var t=function(e,t){if("object"!==l(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==l(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===l(t)?t:String(t)}function v(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=m(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){a=!0,o=e},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw o}}}}function _(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}(e,t)||m(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function m(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function b(){
2
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3
- b=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",a=i.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,r){return e[t]=r}}function u(e,t,r,i){var o=t&&t.prototype instanceof d?t:d,s=Object.create(o.prototype),a=new x(i||[]);return n(s,"_invoke",{value:S(e,r,a)}),s}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var h={};function d(){}function p(){}function f(){}var v={};c(v,o,(function(){return this}));var _=Object.getPrototypeOf,m=_&&_(_(C([])));m&&m!==t&&r.call(m,o)&&(v=m);var y=f.prototype=d.prototype=Object.create(v);function w(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function i(n,o,s,a){var c=l(e[n],e,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==g(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){i("next",e,s,a)}),(function(e){i("throw",e,s,a)})):t.resolve(h).then((function(e){u.value=e,s(u)}),(function(e){return i("throw",e,s,a)}))}a(c.arg)}var o;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){i(e,r,t,n)}))}return o=o?o.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return A()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=O(s,r);if(a){if(a===h)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var i=l(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,h;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function C(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}return p.prototype=f,n(y,"constructor",{value:f,configurable:!0}),n(f,"constructor",{value:p,configurable:!0}),p.displayName=c(f,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,c(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},w(k.prototype),c(k.prototype,s,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var s=new k(u(t,r,n,i),o);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},w(y),c(y,a,"Generator"),c(y,o,(function(){return this})),c(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=C,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=r.call(o,"catchLoc"),c=r.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,h):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),h},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},e}function w(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(i=n.key,o=void 0,o=function(e,t){if("object"!==g(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==g(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"),"symbol"===g(o)?o:String(o)),n)}var i,o}function k(e,t,r){return t&&w(e.prototype,t),r&&w(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function S(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function O(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&P(e,t)}function T(e){var t=A();return function(){var r,n=R(e);if(t){var i=R(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===g(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return E(e)}(this,r)}}function E(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function x(e){var t="function"==typeof Map?new Map:void 0;return x=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return C(e,arguments,R(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),P(n,e)},x(e)}function C(e,t,r){return C=A()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&P(i,r.prototype),i},C.apply(null,arguments)}function A(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}function R(e){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},R(e)}var L,I="https://accounts.google.com/gsi",B="".concat(I,"/client");function j(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function D(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}var N=new Uint8Array(16);function M(){if(!L&&!(L="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return L(N)}var F=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var U,K,G,q,W,H,Y=[],z=0;z<256;++z)Y.push((z+256).toString(16).substr(1));function V(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(Y[e[t+0]]+Y[e[t+1]]+Y[e[t+2]]+Y[e[t+3]]+"-"+Y[e[t+4]]+Y[e[t+5]]+"-"+Y[e[t+6]]+Y[e[t+7]]+"-"+Y[e[t+8]]+Y[e[t+9]]+"-"+Y[e[t+10]]+Y[e[t+11]]+Y[e[t+12]]+Y[e[t+13]]+Y[e[t+14]]+Y[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&F.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function J(e,t,r){var n=(e=e||{}).random||(e.rng||M)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var i=0;i<16;++i)t[r+i]=n[i];return t}return V(n)}!function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(U||(U={})),function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Salesforce="salesforce",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch",e.Twitter="twitter",e.TikTok="tiktok",e.Snapchat="snapchat",e.Figma="figma",e.Yahoo="yahoo"}(K||(K={})),function(e){e.Vessel="Vessel",e.Phantom="Phantom",e.Metamask="Metamask",e.Coinbase="Coinbase",e.Binance="Binance",e.GenericEthereumWallet="Other Ethereum Wallet",e.GenericSolanaWallet="Other Solana Wallet"}(G||(G={})),function(e){e.embedded="embedded",e.floating="floating"}(q||(q={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(W||(W={})),function(e){e.MagicLinkLoginOrCreateEvent="MAGIC_LINK_LOGIN_OR_CREATE",e.OTPsLoginOrCreateEvent="OTP_LOGIN_OR_CREATE",e.OTPsAuthenticate="OTP_AUTHENTICATE",e.CryptoWalletAuthenticateStart="CRYPTO_WALLET_AUTHENTICATE_START",e.CryptoWalletAuthenticate="CRYPTO_WALLET_AUTHENTICATE",e.PasswordCreate="PASSWORD_CREATE",e.PasswordAuthenticate="PASSWORD_AUTHENTICATE",e.PasswordResetByEmailStart="PASSWORD_RESET_BY_EMAIL_START",e.PasswordResetByEmail="PASSWORD_RESET_BY_EMAIL",e.B2BMagicLinkEmailLoginOrSignup="B2B_MAGIC_LINK_EMAIL_LOGIN_OR_SIGNUP",e.B2BMagicLinkAuthenticate="B2B_MAGIC_LINK_AUTHENTICATE",e.B2BMagicLinkEmailDiscoverySend="B2B_MAGIC_LINK_EMAIL_DISCOVERY_SEND",e.B2BMagicLinkDiscoveryAuthenticate="B2B_MAGIC_LINK_DISCOVERY_AUTHENTICATE",e.B2BSSOStart="B2B_SSO_START",e.B2BSSOAuthenticate="B2B_SSO_AUTHENTICATE",e.B2BOAuthAuthenticate="B2B_SSO_AUTHENTICATE",e.B2BOAuthDiscoveryAuthenticate="B2B_OAUTH_DISCOVERY_AUTHENTICATE",e.B2BDiscoveryOrganizationsCreate="B2B_DISCOVERY_ORGANIZATIONS_CREATE",e.B2BDiscoveryIntermediateSessionExchange="B2B_DISCOVERY_INTERMEDIATE_SESSION_EXCHANGE",e.B2BPasswordAuthenticate="B2B_PASSWORD_AUTHENTICATE",e.B2BPasswordResetByEmailStart="B2B_PASSWORD_RESET_BY_EMAIL_START",e.B2BPasswordResetByEmail="B2B_PASSWORD_RESET_BY_EMAIL",e.B2BPasswordResetBySession="B2B_PASSWORD_RESET_BY_SESSION"}(H||(H={}));var X,$,Z,Q,ee=function(e){O(r,x(Error));var t=T(r);function r(e,n){var i;return S(this,r),(i=t.call(this,e+"\n"+n)).message=e+"\n"+n,i.name="SDKAPIUnreachableError",i.details=n,Object.setPrototypeOf(E(i),r.prototype),i}return k(r)}(),te=function(e){O(r,x(Error));var t=T(r);function r(e,n){var i;return S(this,r),(i=t.call(this)).name="StytchSDKUsageError",i.message="Invalid call to ".concat(e,"\n")+n,i}return k(r)}(),re=function(e){O(r,x(Error));var t=T(r);function r(e){var n,i;S(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var o=null===(i=e.body)||void 0===i?void 0:i.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(o),n}return k(r)}(),ne=function(e){O(r,x(Error));var t=T(r);function r(e){var n;S(this,r),(n=t.call(this)).name="StytchSDKAPIError";var i=e.status_code,o=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=o,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=i,n.message="[".concat(i,"] ").concat(o,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return k(r)}(),ie=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];!function(e){e.BiometricsSensorError="biometrics_sensor_error",e.DeviceCredentialsNotAllowed="device_credentials_not_allowed",e.DeviceHardwareError="device_hardware_error",e.InternalError="internal_error",e.KeyInvalidated="key_invalidated",e.KeystoreUnavailable="keystore_unavailable",e.NoBiometricsEnrolled="no_biometrics_enrolled",e.NoBiometricsRegistration="no_biometrics_registration",e.SessionExpired="session_expired",e.UserCancellation="user_cancellation",e.UserLockedOut="user_locked_out",e.BiometricsNotAvailable="biometrics_not_available"}(X||(X={})),function(e){e.emailMagicLinks="emailMagicLinks",e.sso="sso",e.passwords="passwords",e.oauth="oauth"}($||($={})),function(e){e.Discovery="Discovery",e.Organization="Organization",e.PasswordReset="PasswordReset"}(Z||(Z={})),function(e){e.Google="google",e.Microsoft="microsoft"}(Q||(Q={}));var oe={};function se(e,t){return D(this,void 0,void 0,b().mark((function r(){return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(void 0===oe[e]){r.next=2;break}return r.abrupt("return",oe[e]);case 2:return oe[e]=ae(e,t),r.abrupt("return",oe[e]);case 4:case"end":return r.stop()}}),r)})))}function ae(e,t){return new Promise((function(r,n){var i=function(e){var t=ce(e);if(t[0])return t[0]}(e);if(i&&"true"===i.dataset.loaded)try{r(t())}catch(t){return n(new Error("".concat(e," already loaded, but module was not found in global scope: ").concat(t)))}var o=function(e){var t=document.createElement("script");return t.setAttribute("src",e),t.setAttribute("async","true"),t.setAttribute("defer","true"),document.head.appendChild(t),t}(e);o.addEventListener("load",(function(){o.dataset.loaded="true";try{r(t())}catch(t){n(new Error("".concat(e," was loaded, but module was not found in global scope: ").concat(t)))}})),o.addEventListener("error",(function(t){n(new Error("".concat(e," could not be loaded: ").concat(t)))}))}))}var ce=function(e){return document.querySelectorAll('script[src="'.concat(e,'"]'))};var ue=["[Stytch]"],le=function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=console).warn.apply(e,ue.concat(r))},he=function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=console).error.apply(e,ue.concat(r))},de="\nYou can find your public token at https://stytch.com/dashboard/api-keys.",pe=function(e){var t={isObject:function(r,n){var i="object"===g(n)&&!Array.isArray(n)&&null!==n;if(!i)throw new te(e,r+" must be an object.");return t},isOptionalObject:function(e,r){return void 0===r?t:t.isObject(e,r)},isString:function(r,n){if("string"!=typeof n)throw new te(e,r+" must be a string.");return t},isOptionalString:function(e,r){return void 0===r?t:t.isString(e,r)},isStringArray:function(r,n){if(!Array.isArray(n))throw new te(e,r+" must be an array of strings.");var i,o=v(n);try{for(o.s();!(i=o.n()).done;){if("string"!=typeof i.value)throw new te(e,r+" must be an array of strings.")}}catch(e){o.e(e)}finally{o.f()}return t},isOptionalStringArray:function(e,r){return void 0===r?t:t.isStringArray(e,r)},isNumber:function(r,n){if("number"!=typeof n)throw new te(e,r+" must be a number.");return t},isOptionalNumber:function(e,r){return void 0===r?t:t.isNumber(e,r)},isBoolean:function(r,n){if("boolean"!=typeof n)throw new te(e,r+" must be a boolean.");return t},isOptionalBoolean:function(e,r){return void 0===r?t:t.isBoolean(e,r)}};return t},fe=function(e){return j(e,["request_id","status_code"])},ve=function(e){return j(e,["__user"])},_e=k((function e(t,r,n){var i=this;S(this,e),this.bootstrapPromise=n,this.isEnabled=function(){return D(i,void 0,void 0,b().mark((function e(){return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.state.then((function(e){return e.enabled})));case 1:case"end":return e.stop()}}),e,this)})))},this.getTelemetryID=function(){return D(i,void 0,void 0,b().mark((function e(){var t,r,n,i;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.state;case 2:if(t=e.sent,r=t.publicToken,n=t.enabled,i=t.dfpBackendURL,n){e.next=8;break}return e.abrupt("return",void 0);case 8:return e.next=10,window.GetTelemetryID(r,"".concat(i,"/submit"));case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e,this)})))},this.state=n.then((function(e){return D(i,void 0,void 0,b().mark((function n(){return b().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(e.runDFPProtectedAuth){n.next=2;break}return n.abrupt("return",{publicToken:t,dfpBackendURL:r,enabled:!1,loaded:!1});case 2:return n.next=4,void se("".concat("https://elements.stytch.com","/telemetry.js"),(function(){return window}));case 4:return n.abrupt("return",{publicToken:t,dfpBackendURL:r,enabled:!0,loaded:!0});case 5:case"end":return n.stop()}}),n)})))}))})),me=function(){function e(){S(this,e)}return k(e,null,[{key:"marshall",value:function(e){return Object.assign(Object.assign({},e),{name:e.name,message:e.message,stack:e.stack})}},{key:"inflate",value:function(e,t){var r=new e(t);return Object.assign(r,t),Object.setPrototypeOf(r,e.prototype),r}},{key:"unmarshall",value:function(t){if("name"in t)switch(t.name){case"SDKAPIUnreachableError":return e.inflate(ee,t);case"StytchSDKSchemaError":return e.inflate(re,t);case"StytchSDKAPIError":return e.inflate(ne,t);case"TypeError":return e.inflate(TypeError,t);case"SyntaxError":return e.inflate(SyntaxError,t);case"ReferenceError":return e.inflate(ReferenceError,t);case"RangeError":return e.inflate(RangeError,t);case"EvalError":return e.inflate(EvalError,t);case"URIError":return e.inflate(URIError,t)}return e.inflate(Error,t)}}]),e}(),ye=function(){function e(t){S(this,e),this.maxBatchSize=t.maxBatchSize,this.logEventURL=t.logEventURL,setInterval(this.flush.bind(this),t.intervalDurationMs),this.batch=[]}return k(e,[{key:"logEvent",value:function(e,t){this.batch.push({telemetry:e,event:t}),this.batch.length>=this.maxBatchSize&&this.flush()}},{key:"flush",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.batch.length){e.next=2;break}return e.abrupt("return");case 2:return t=this.batch,this.batch=[],e.prev=4,e.next=7,fetch(this.logEventURL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});case 7:e.next=11;break;case 9:e.prev=9,e.t0=e.catch(4);case 11:case"end":return e.stop()}}),e,this,[[4,9]])})))}}]),e}(),ge=k((function e(t,r){var n=this;S(this,e),this._networkClient=t,this._subscriptionService=r,this.get=function(){return D(n,void 0,void 0,b().mark((function e(){var t,r;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._networkClient.fetchSDK({url:"/users/me",errorMessage:"Failed to retrieve user info.",method:"GET"});case 2:return t=e.sent,r=fe(t),this._subscriptionService.updateUser(r),e.abrupt("return",r);case 6:case"end":return e.stop()}}),e,this)})))},this.getSync=function(){return n._subscriptionService.getUser()},this.update=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.user.update").isOptionalObject("untrusted_metadata",e.untrusted_metadata),t.next=3,this._networkClient.fetchSDK({url:"/users/me",body:e,errorMessage:"Failed to update user.",method:"PUT"});case 3:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 7:case"end":return t.stop()}}),t,this)})))},this.deleteEmail=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/emails/".concat(e),errorMessage:"Failed to delete email.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deletePhoneNumber=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/phone_numbers/".concat(e),errorMessage:"Failed to delete phone number.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteTOTP=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/totps/".concat(e),errorMessage:"Failed to delete TOTP.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteOAuthRegistration=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/oauth/".concat(e),errorMessage:"Failed to delete OAuth registration.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteWebauthnRegistration=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/webauthn_registrations/".concat(e),errorMessage:"Failed to delete WebAuthn registration.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteBiometricRegistration=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._networkClient.fetchSDK({url:"/users/biometric_registrations/".concat(e),errorMessage:"Failed to delete Biometric registration.",method:"DELETE"});case 2:return r=t.sent,n=fe(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))},this.onChange=function(e){var t=n._subscriptionService.getUser();return n._subscriptionService.subscribeToState((function(r){var n;(null==r?void 0:r.user)!==t&&(t=null!==(n=null==r?void 0:r.user)&&void 0!==n?n:null,e(t))}))}})),be=function(){function e(t,r){var n=this;S(this,e),this._networkClient=t,this._subscriptionService=r,this.getSync=function(){return n._subscriptionService.getSession()},this.onChange=function(e){var t=n._subscriptionService.getSession();return n._subscriptionService.subscribeToState((function(r){var n;(null==r?void 0:r.session)!==t&&(t=null!==(n=null==r?void 0:r.session)&&void 0!==n?n:null,e(t))}))},this.revoke=function(e){return D(n,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this._networkClient.fetchSDK({url:"/sessions/revoke",errorMessage:"Error revoking session",method:"POST"});case 3:return r=t.sent,this._subscriptionService.destroyState(),t.abrupt("return",r);case 8:throw t.prev=8,t.t0=t.catch(0),((null==e?void 0:e.forceClear)||ie.includes(t.t0.error_type))&&this._subscriptionService.destroyState(),t.t0;case 12:case"end":return t.stop()}}),t,this,[[0,8]])})))},this.authenticate=function(e){return D(n,void 0,void 0,b().mark((function t(){var r,n;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,r={session_duration_minutes:null==e?void 0:e.session_duration_minutes},t.next=4,this._networkClient.fetchSDK({url:"/sessions/authenticate",body:r,errorMessage:"Error authenticating session",method:"POST"});case 4:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.session,user:n.user},session_token:n.session_token,session_jwt:n.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(n));case 9:throw t.prev=9,t.t0=t.catch(0),ie.includes(t.t0.error_type)&&this._subscriptionService.destroyState(),t.t0;case 13:case"end":return t.stop()}}),t,this,[[0,9]])})))}}return k(e,[{key:"getTokens",value:function(){return this._subscriptionService.getTokens()}},{key:"updateSession",value:function(e){this._subscriptionService.updateTokens(e)}}]),e}(),we=Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),ke=function(){function e(t,r,n){var i=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:we,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:function(){return Promise.resolve(void 0)},a=arguments.length>5?arguments[5]:void 0;S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=o,this.executeRecaptcha=s,this._dfpProtectedAuth=a,this.email={loginOrCreate:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return D(i,void 0,void 0,b().mark((function r(){var n,i,o,s,a,c,u;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._config;case 2:if(n=r.sent,i=n.pkceRequiredForEmailMagicLinks,o=void 0,!i){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:o=r.sent;case 9:return r.next=11,this.getDFPTelemetryIDAndCaptcha();case 11:return s=r.sent,a=s.dfp_telemetry_id,c=s.captcha_token,u=Object.assign(Object.assign({},t),{email:e,code_challenge:o,captcha_token:c,dfp_telemetry_id:a}),r.abrupt("return",this._networkClient.fetchSDK({url:"/magic_links/email/login_or_create",body:u,errorMessage:"Failed to send magic link",method:"POST"}));case 16:case"end":return r.stop()}}),r,this)})))},send:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return D(i,void 0,void 0,b().mark((function r(){var n,i,o,s,a,c,u,l,h;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._config;case 2:if(n=r.sent,i=n.pkceRequiredForEmailMagicLinks,o=void 0,!i){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:o=r.sent;case 9:return r.next=11,this.getDFPTelemetryIDAndCaptcha();case 11:return s=r.sent,a=s.dfp_telemetry_id,c=s.captcha_token,u=Object.assign(Object.assign({},t),{email:e,code_challenge:o,captcha_token:c,dfp_telemetry_id:a}),l=!!this._subscriptionService.getSession(),h=l?"/magic_links/email/send/secondary":"/magic_links/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:h,body:u,errorMessage:"Failed to send magic link",method:"POST"}));case 18:case"end":return r.stop()}}),r,this)})))}},this.authenticate=function(e,t){return D(i,void 0,void 0,b().mark((function r(){var n,i,o;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return pe("stytch.magicLinks.authenticate").isString("Token",e).isNumber("session_duration_minutes",t.session_duration_minutes),r.next=3,this._pkceManager.getPKPair();case 3:return n=r.sent,i=Object.assign({token:e,code_verifier:null==n?void 0:n.code_verifier},t),r.next=7,this._networkClient.fetchSDK({url:"/magic_links/authenticate",body:i,errorMessage:"Failed to authenticate token.",method:"POST"});case 7:return o=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:o.user},session_token:o.session_token,session_jwt:o.session_jwt,intermediate_session_token:null}),r.abrupt("return",ve(o));case 11:case"end":return r.stop()}}),r,this)})))}}return k(e,[{key:"getCodeChallenge",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._pkceManager.getPKPair();case 2:if(!(t=e.sent)){e.next=5;break}return e.abrupt("return",t.code_challenge);case 5:return e.next=7,this._pkceManager.startPKCETransaction();case 7:return t=e.sent,e.abrupt("return",t.code_challenge);case 9:case"end":return e.stop()}}),e,this)})))}},{key:"getDFPTelemetryIDAndCaptcha",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t,r;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=void 0,r=void 0,e.t0=this._dfpProtectedAuth,!e.t0){e.next=7;break}return e.next=6,this._dfpProtectedAuth.isEnabled();case 6:e.t0=e.sent;case 7:if(!e.t0){e.next=13;break}return e.next=10,this._dfpProtectedAuth.getTelemetryID();case 10:t=e.sent,e.next=16;break;case 13:return e.next=15,this.executeRecaptcha();case 15:r=e.sent;case 16:return e.abrupt("return",{dfp_telemetry_id:t,captcha_token:r});case 17:case"end":return e.stop()}}),e,this)})))}}]),e}(),Se=k((function e(t,r){var n=this,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){return Promise.resolve(void 0)};S(this,e),this._networkClient=t,this._subscriptionService=r,this.executeRecaptcha=i,this.sms={loginOrCreate:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/sms/login_or_create",body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i,o,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),o=!!this._subscriptionService.getSession(),s=o?"/otps/sms/send/secondary":"/otps/sms/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 7:case"end":return r.stop()}}),r,this)})))}},this.whatsapp={loginOrCreate:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/whatsapp/login_or_create",body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i,o,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),o=!!this._subscriptionService.getSession(),s=o?"/otps/whatsapp/send/secondary":"/otps/whatsapp/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 7:case"end":return r.stop()}}),r,this)})))}},this.email={loginOrCreate:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/email/login_or_create",body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return D(n,void 0,void 0,b().mark((function r(){var n,i,o,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.executeRecaptcha();case 2:return n=r.sent,i=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),o=!!this._subscriptionService.getSession(),s=o?"/otps/email/send/secondary":"/otps/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:i,errorMessage:"Failed to send one time passcode",method:"POST"}));case 7:case"end":return r.stop()}}),r,this)})))}},this.authenticate=function(e,t,r){return D(n,void 0,void 0,b().mark((function n(){var i,o;return b().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return pe("stytch.otps.authenticate").isString("Code",e).isNumber("session_duration_minutes",r.session_duration_minutes),i=Object.assign({token:e,method_id:t},r),n.next=4,this._networkClient.fetchSDK({url:"/otps/authenticate",body:i,errorMessage:"Failed to authenticate token.",method:"POST"});case 4:return o=n.sent,this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:o.user},session_token:o.session_token,session_jwt:o.session_jwt,intermediate_session_token:null}),n.abrupt("return",ve(o));case 7:case"end":return n.stop()}}),n,this)})))}})),Oe=function(){function e(t,r,n,i,o){S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._dynamicConfig=i,this._config=o,this.google={start:this.startOAuthFlow(K.Google)},this.apple={start:this.startOAuthFlow(K.Apple)},this.microsoft={start:this.startOAuthFlow(K.Microsoft)},this.github={start:this.startOAuthFlow(K.Github)},this.gitlab={start:this.startOAuthFlow(K.GitLab)},this.facebook={start:this.startOAuthFlow(K.Facebook)},this.discord={start:this.startOAuthFlow(K.Discord)},this.salesforce={start:this.startOAuthFlow(K.Salesforce)},this.slack={start:this.startOAuthFlow(K.Slack)},this.amazon={start:this.startOAuthFlow(K.Amazon)},this.bitbucket={start:this.startOAuthFlow(K.Bitbucket)},this.linkedin={start:this.startOAuthFlow(K.LinkedIn)},this.coinbase={start:this.startOAuthFlow(K.Coinbase)},this.twitch={start:this.startOAuthFlow(K.Twitch)},this.twitter={start:this.startOAuthFlow(K.Twitter)},this.tiktok={start:this.startOAuthFlow(K.TikTok)},this.snapchat={start:this.startOAuthFlow(K.Snapchat)},this.figma={start:this.startOAuthFlow(K.Figma)},this.yahoo={start:this.startOAuthFlow(K.Yahoo)}}return k(e,[{key:"authenticate",value:function(e,t){return D(this,void 0,void 0,b().mark((function r(){var n,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return pe("stytch.oauth.authenticate").isString("Token",e).isNumber("session_duration_minutes",t.session_duration_minutes),r.next=3,this._pkceManager.getPKPair();case 3:return(n=r.sent)||le("No code verifier found in local storage for OAuth flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."),r.next=7,this._networkClient.fetchSDK({url:"/oauth/authenticate",method:"POST",body:Object.assign({token:e,code_verifier:null==n?void 0:n.code_verifier},t),errorMessage:"Failed to authenticate token"});case 7:return i=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:fe(i.__user)},session_token:i.session_token,session_jwt:i.session_jwt,intermediate_session_token:null}),r.abrupt("return",ve(i));case 11:case"end":return r.stop()}}),r,this)})))}},{key:"getBaseApiUrl",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t,r;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._dynamicConfig;case 2:if(t=e.sent,!(r=t.cnameDomain)){e.next=6;break}return e.abrupt("return","https://".concat(r));case 6:if(!this._config.publicToken.includes("public-token-test")){e.next=8;break}return e.abrupt("return",this._config.testAPIURL);case 8:return e.abrupt("return",this._config.liveAPIURL);case 9:case"end":return e.stop()}}),e,this)})))}},{key:"startOAuthFlow",value:function(e){var t=this;return function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=r.login_redirect_url,i=r.signup_redirect_url,o=r.custom_scopes;return D(t,void 0,void 0,b().mark((function t(){var r,s,a,c,u,l;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._dynamicConfig;case 2:return r=t.sent,s=r.cnameDomain,a=r.pkceRequiredForOAuth,t.next=7,this.getBaseApiUrl();case 7:if(c=t.sent,this._networkClient.logEvent({name:"start_oauth_flow",details:{provider_type:e,custom_scopes:o,cname_domain:s,pkce:a}}),(u=new URL("".concat(c,"/v1/public/oauth/").concat(e,"/start"))).searchParams.set("public_token",this._config.publicToken),!a){t.next=18;break}return t.next=14,this._pkceManager.startPKCETransaction();case 14:l=t.sent,u.searchParams.set("code_challenge",l.code_challenge),t.next=19;break;case 18:this._pkceManager.clearPKPair();case 19:o&&(pe("startOAuthFlow").isStringArray("custom_scopes",o),u.searchParams.set("custom_scopes",o.join(" "))),n&&u.searchParams.set("login_redirect_url",n),i&&u.searchParams.set("signup_redirect_url",i),window.location.href=u.toString();case 23:case"end":return t.stop()}}),t,this)})))}}}]),e}(),Te=function(){function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){return Promise.resolve(void 0)};S(this,e),this._networkClient=t,this._subscriptionService=r,this.executeRecaptcha=n}return k(e,[{key:"authenticateStart",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r,n,i;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.cryptoWallets.authenticateStart").isString("crypto_wallet_address",e.crypto_wallet_address).isString("crypto_wallet_type",e.crypto_wallet_type),r=!!this._subscriptionService.getSession(),t.next=4,this.executeRecaptcha();case 4:return n=t.sent,i=r?"/crypto_wallets/authenticate/start/secondary":"/crypto_wallets/authenticate/start/primary",t.abrupt("return",this._networkClient.fetchSDK({url:i,method:"POST",errorMessage:"Failed to start wallet authentication.",body:{crypto_wallet_address:e.crypto_wallet_address,crypto_wallet_type:e.crypto_wallet_type,captcha_token:n}}));case 7:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.cryptoWallets.authenticate").isString("signature",e.signature).isString("crypto_wallet_address",e.crypto_wallet_address).isString("crypto_wallet_type",e.crypto_wallet_type).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._networkClient.fetchSDK({url:"/crypto_wallets/authenticate",method:"POST",errorMessage:"Failed to authenticate.",body:{session_duration_minutes:e.session_duration_minutes,crypto_wallet_address:e.crypto_wallet_address,crypto_wallet_type:e.crypto_wallet_type,signature:e.signature}});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.session,user:fe(r.__user)},session_token:r.session_token,session_jwt:r.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}(),Ee=function(){function e(t,r){S(this,e),this._networkClient=t,this._subscriptionService=r}return k(e,[{key:"create",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.totps.create").isNumber("expiration_minutes",e.expiration_minutes),t.next=3,this._networkClient.fetchSDK({url:"/totps",method:"POST",errorMessage:"Failed to create TOTP",body:{expiration_minutes:e.expiration_minutes}});case 3:return r=t.sent,this._subscriptionService.updateUser(r.__user),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.totps.authenticate").isNumber("session_duration_minutes",e.session_duration_minutes).isString("totp_code",e.totp_code),t.next=3,this._networkClient.fetchSDK({url:"/totps/authenticate",method:"POST",errorMessage:"Failed to authenticate TOTP",body:{session_duration_minutes:e.session_duration_minutes,totp_code:e.totp_code}});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.session,user:r.__user},session_token:r.session_token,session_jwt:r.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"recoveryCodes",value:function(){return D(this,void 0,void 0,b().mark((function e(){return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this._networkClient.fetchSDK({url:"/totps/recovery_codes",method:"POST",errorMessage:"Failed to retrieve recovery codes"}));case 1:case"end":return e.stop()}}),e,this)})))}},{key:"recover",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.totps.recover").isNumber("session_duration_minutes",e.session_duration_minutes).isString("recovery_code",e.recovery_code),t.next=3,this._networkClient.fetchSDK({url:"/totps/recover",method:"POST",errorMessage:"Failed to recover TOTP",body:{session_duration_minutes:e.session_duration_minutes,recovery_code:e.recovery_code}});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.session,user:r.__user},session_token:r.session_token,session_jwt:r.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}();function xe(e){for(var t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),i=new ArrayBuffer(n.length),o=new Uint8Array(i),s=0;s<n.length;s++)o[s]=n.charCodeAt(s);return i}function Ce(e){var t,r="",n=v(new Uint8Array(e));try{for(n.s();!(t=n.n()).done;){var i=t.value;r+=String.fromCharCode(i)}}catch(e){n.e(e)}finally{n.f()}return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var Ae="copy",Pe="convert";function Re(e,t,r){if(t===Ae)return r;if(t===Pe)return e(r);if(t instanceof Array)return r.map((function(r){return Re(e,t[0],r)}));if(t instanceof Object){for(var n={},i=0,o=Object.entries(t);i<o.length;i++){var s=_(o[i],2),a=s[0],c=s[1];if(c.derive){var u=c.derive(r);void 0!==u&&(r[a]=u)}if(a in r)null!=r[a]?n[a]=Re(e,c.schema,r[a]):n[a]=null;else if(c.required)throw new Error("Missing key: ".concat(a))}return n}}function Le(e,t){return{required:!0,schema:e,derive:t}}function Ie(e){return{required:!0,schema:e}}function Be(e){return{required:!1,schema:e}}var je={type:Ie(Ae),id:Ie(Pe),transports:Be(Ae)},De={appid:Be(Ae),appidExclude:Be(Ae),credProps:Be(Ae)},Ne={appid:Be(Ae),appidExclude:Be(Ae),credProps:Be(Ae)},Me={publicKey:Ie({rp:Ie(Ae),user:Ie({id:Ie(Pe),name:Ie(Ae),displayName:Ie(Ae)}),challenge:Ie(Pe),pubKeyCredParams:Ie(Ae),timeout:Be(Ae),excludeCredentials:Be([je]),authenticatorSelection:Be(Ae),attestation:Be(Ae),extensions:Be(De)}),signal:Be(Ae)},Fe={type:Ie(Ae),id:Ie(Ae),rawId:Ie(Pe),authenticatorAttachment:Be(Ae),response:Ie({clientDataJSON:Ie(Pe),attestationObject:Ie(Pe),transports:Le(Ae,(function(e){var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]}))}),clientExtensionResults:Le(Ne,(function(e){return e.getClientExtensionResults()}))},Ue={mediation:Be(Ae),publicKey:Ie({challenge:Ie(Pe),timeout:Be(Ae),rpId:Be(Ae),allowCredentials:Be([je]),userVerification:Be(Ae),extensions:Be(De)}),signal:Be(Ae)},Ke={type:Ie(Ae),id:Ie(Ae),rawId:Ie(Pe),authenticatorAttachment:Be(Ae),response:Ie({clientDataJSON:Ie(Pe),authenticatorData:Ie(Pe),signature:Ie(Pe),userHandle:Ie(Pe)}),clientExtensionResults:Le(Ne,(function(e){return e.getClientExtensionResults()}))};function Ge(e){return Re(xe,Me,e)}function qe(e){return Re(Ce,Fe,e)}function We(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,navigator.credentials.create(Ge(e));case 2:return r=t.sent,t.abrupt("return",qe(r));case 4:case"end":return t.stop()}}),t)})))}function He(e){return Re(xe,Ue,e)}function Ye(e){return Re(Ce,Ke,e)}function ze(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,navigator.credentials.get(He(e));case 2:return r=t.sent,t.abrupt("return",Ye(r));case 4:case"end":return t.stop()}}),t)})))}var Ve=function(){function e(t,r){S(this,e),this._networkClient=t,this._subscriptionService=r}return k(e,[{key:"register",value:function(e){var t;return D(this,void 0,void 0,b().mark((function r(){var n,i,o,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return pe("stytch.webauthn.register").isOptionalString("domain",null==e?void 0:e.domain).isOptionalString("authenticator_type",null==e?void 0:e.authenticator_type),r.next=3,this._networkClient.fetchSDK({url:"/webauthn/register/start",method:"POST",errorMessage:"Failed to start WebAuthn registration",body:{domain:null!==(t=null==e?void 0:e.domain)&&void 0!==t?t:window.location.hostname,authenticator_type:null==e?void 0:e.authenticator_type}});case 3:return n=r.sent,i=n.public_key_credential_creation_options,r.next=7,We({publicKey:JSON.parse(i)});case 7:return o=r.sent,r.next=10,this._networkClient.fetchSDK({url:"/webauthn/register",method:"POST",errorMessage:"Failed to register WebAuthn device",body:{public_key_credential:JSON.stringify(o)}});case 10:return s=r.sent,this._subscriptionService.updateUser(s.__user),r.abrupt("return",ve(s));case 13:case"end":return r.stop()}}),r,this)})))}},{key:"authenticate",value:function(e){var t;return D(this,void 0,void 0,b().mark((function r(){var n,i,o,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return pe("stytch.webauthn.register").isOptionalString("domain",e.domain).isNumber("session_duration_minutes",e.session_duration_minutes),r.next=3,this._networkClient.fetchSDK({url:"/webauthn/authenticate/start",method:"POST",errorMessage:"Failed to start WebAuthn authentication",body:{domain:null!==(t=e.domain)&&void 0!==t?t:window.location.hostname}});case 3:return n=r.sent,i=n.public_key_credential_request_options,r.next=7,ze({publicKey:JSON.parse(i)});case 7:return o=r.sent,r.next=10,this._networkClient.fetchSDK({url:"/webauthn/authenticate",method:"POST",errorMessage:"Failed to authenticate WebAuthn device",body:{public_key_credential:JSON.stringify(o),session_duration_minutes:e.session_duration_minutes}});case 10:return s=r.sent,this._subscriptionService.updateStateAndTokens({state:{session:s.session,user:s.__user},session_token:s.session_token,session_jwt:s.session_jwt,intermediate_session_token:null}),r.abrupt("return",ve(s));case 13:case"end":return r.stop()}}),r,this)})))}}]),e}(),Je=Promise.resolve({pkceRequiredForPasswordResets:!1}),Xe=function(){function e(t,r,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Je,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:function(){return Promise.resolve(void 0)},s=arguments.length>5?arguments[5]:void 0;S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=i,this.executeRecaptcha=o,this._dfpProtectedAuth=s}return k(e,[{key:"getCodeChallenge",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t,r;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._config;case 2:if(t=e.sent,t.pkceRequiredForPasswordResets){e.next=6;break}return e.abrupt("return",void 0);case 6:return e.next=8,this._pkceManager.getPKPair();case 8:if(!(r=e.sent)){e.next=11;break}return e.abrupt("return",r.code_challenge);case 11:return e.next=13,this._pkceManager.startPKCETransaction();case 13:return r=e.sent,e.abrupt("return",r.code_challenge);case 15:case"end":return e.stop()}}),e,this)})))}},{key:"getDFPTelemetryIDAndCaptcha",value:function(){return D(this,void 0,void 0,b().mark((function e(){var t,r;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=void 0,r=void 0,e.t0=this._dfpProtectedAuth,!e.t0){e.next=7;break}return e.next=6,this._dfpProtectedAuth.isEnabled();case 6:e.t0=e.sent;case 7:if(!e.t0){e.next=13;break}return e.next=10,this._dfpProtectedAuth.getTelemetryID();case 10:t=e.sent,e.next=16;break;case 13:return e.next=15,this.executeRecaptcha();case 15:r=e.sent;case 16:return e.abrupt("return",{dfp_telemetry_id:t,captcha_token:r});case 17:case"end":return e.stop()}}),e,this)})))}},{key:"create",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r,n,i,o;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.create").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.getDFPTelemetryIDAndCaptcha();case 3:return r=t.sent,n=r.dfp_telemetry_id,i=r.captcha_token,t.next=8,this._networkClient.fetchSDK({url:"/passwords",method:"POST",errorMessage:"Failed to create password.",body:{email:e.email,password:e.password,session_duration_minutes:e.session_duration_minutes,captcha_token:i,dfp_telemetry_id:n}});case 8:return o=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:o.user},session_token:o.session_token,session_jwt:o.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(o));case 11:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r,n,i,o;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.authenticate").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.getDFPTelemetryIDAndCaptcha();case 3:return r=t.sent,n=r.dfp_telemetry_id,i=r.captcha_token,t.next=8,this._networkClient.fetchSDK({url:"/passwords/authenticate",method:"POST",errorMessage:"Failed to authenticate password.",body:{email:e.email,password:e.password,session_duration_minutes:e.session_duration_minutes,captcha_token:i,dfp_telemetry_id:n}});case 8:return o=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:o.user},session_token:o.session_token,session_jwt:o.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(o));case 11:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmailStart",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r,n,i,o;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.resetByEmailStart").isString("email",e.email).isOptionalString("login_redirect_url",e.login_redirect_url).isOptionalString("reset_password_redirect_url",e.reset_password_redirect_url).isOptionalString("reset_password_template_id",e.reset_password_template_id).isOptionalNumber("reset_password_expiration_minutes",e.reset_password_expiration_minutes),t.next=3,this.getCodeChallenge();case 3:return r=t.sent,t.next=6,this.getDFPTelemetryIDAndCaptcha();case 6:return n=t.sent,i=n.dfp_telemetry_id,o=n.captcha_token,t.abrupt("return",this._networkClient.fetchSDK({url:"/passwords/email/reset/start",method:"POST",errorMessage:"Failed to start password reset flow.",body:{email:e.email,login_redirect_url:e.login_redirect_url,reset_password_redirect_url:e.reset_password_redirect_url,reset_password_expiration_minutes:e.reset_password_expiration_minutes,reset_password_template_id:e.reset_password_template_id,code_challenge:r,captcha_token:o,dfp_telemetry_id:i}}));case 10:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmail",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r,n,i,o,s,a;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.resetByEmail").isString("token",e.token).isString("password",e.password).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.getDFPTelemetryIDAndCaptcha();case 3:return r=t.sent,n=r.dfp_telemetry_id,i=r.captcha_token,t.next=8,this._pkceManager.getPKPair();case 8:return o=t.sent,s=null==o?void 0:o.code_verifier,t.next=12,this._networkClient.fetchSDK({url:"/passwords/email/reset",method:"POST",errorMessage:"Failed to reset password.",body:{token:e.token,password:e.password,session_duration_minutes:e.session_duration_minutes,captcha_token:i,code_verifier:s,dfp_telemetry_id:n}});case 12:return a=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:a.session,user:a.user},session_token:a.session_token,session_jwt:a.session_jwt,intermediate_session_token:null}),t.abrupt("return",ve(a));case 16:case"end":return t.stop()}}),t,this)})))}},{key:"resetByExistingPassword",value:function(e){return D(this,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.resetByExistingPassword").isString("email",e.email).isString("existing_password",e.existing_password).isString("new_password",e.new_password).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._networkClient.fetchSDK({url:"/passwords/existing_password/reset",method:"POST",errorMessage:"Failed to reset password.",body:{email:e.email,existing_password:e.existing_password,new_password:e.new_password,session_duration_minutes:e.session_duration_minutes}});case 3:return r=t.sent,t.abrupt("return",ve(r));case 5:case"end":return t.stop()}}),t,this)})))}},{key:"resetBySession",value:function(e){return D(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.resetBySession").isString("password",e.password),t.next=3,this._networkClient.fetchSDK({url:"/passwords/session/reset",method:"POST",errorMessage:"Failed to reset session.",body:{password:e.password}});case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)})))}},{key:"strengthCheck",value:function(e){return D(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return pe("stytch.passwords.strengthCheck").isOptionalString("email",e.email).isString("password",e.password),t.abrupt("return",this._networkClient.fetchSDK({url:"/passwords/strength_check",method:"POST",errorMessage:"Failed to check password strength.",body:{email:e.email,password:e.password}}));case 2:case"end":return t.stop()}}),t,this)})))}}]),e}();function $e(e){var t=e.method,r=e.errorMessage,n=e.finalURL,i=e.basicAuthHeader,o=e.xSDKClientHeader,s=e.xSDKParentHostHeader,a=e.body;return D(this,void 0,void 0,b().mark((function e(){var c,u,l,h,d;return b().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={Authorization:i,"Content-Type":"application/json","X-SDK-Client":o},s&&(c["X-SDK-Parent-Host"]=s),u={method:t,headers:c,body:a&&JSON.stringify(a)},e.prev=3,e.next=6,fetch(n,u);case 6:l=e.sent,e.next=14;break;case 9:if(e.prev=9,e.t0=e.catch(3),"Failed to fetch"!==e.t0.message){e.next=13;break}throw new ee(r,"Unable to contact the Stytch servers. Are you online?");case 13:throw e.t0;case 14:if(200===l.status){e.next=27;break}return e.prev=15,e.next=18,l.json();case 18:h=e.sent,e.next=24;break;case 21:throw e.prev=21,e.t1=e.catch(15),new ee(r,"Invalid or no response from server");case 24:if(!("body"in h||"params"in h||"query"in h)){e.next=26;break}throw new re(h);case 26:throw new ne(h);case 27:return e.prev=27,e.next=30,l.json();case 30:return d=e.sent,e.abrupt("return",d.data);case 34:throw e.prev=34,e.t2=e.catch(27),new ee(r,"Invalid response from the Stytch servers.");case 37:case"end":return e.stop()}}),e,null,[[3,9],[15,21],[27,34]])})))}Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),Promise.resolve({pkceRequiredForPasswordResets:!1});var Ze=function(){function e(t){S(this,e),this.iframeURL=t,this.createIframe()}return k(e,[{key:"createIframe",value:function(){var e=document.querySelector('[src~="'.concat(this.iframeURL,'"]'));e?le("It looks like you're creating multiple copies of the Stytch client. This behavior is unsupported, and unintended side effects may occur. Make sure you are creating the Stytch client at the global level, and not inside a component's render function."):((e=document.createElement("iframe")).src=this.iframeURL,e.style.position="absolute",e.style.width="0",e.style.height="0",e.style.border="0",document.body.appendChild(e)),"true"!==e.dataset.loaded?this.frame=new Promise((function(t){e.addEventListener("load",(function(){e.dataset.loaded="true",t(e)}),{once:!0})})):this.frame=Promise.resolve(e)}},{key:"call",value:function(e,t){return D(this,void 0,void 0,b().mark((function r(){var n,i,o=this;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.frame;case 2:return n=r.sent,i=new MessageChannel,r.abrupt("return",new Promise((function(r,s){var a;i.port1.onmessage=function(e){var t=e.data;i.port1.close(),t.success?r(t.payload):s(me.unmarshall(t.error))};var c={method:e,args:t};null===(a=n.contentWindow)||void 0===a||a.postMessage(c,o.iframeURL,[i.port2])})));case 5:case"end":return r.stop()}}),r,this)})))}}]),e}(),Qe=function(){function e(t,r){var n=this;S(this,e),this._subscriptionService=t,this._headlessSessionClient=r,this._onDataChange=function(e){(null==e?void 0:e.session)?n.scheduleBackgroundRefresh():n.cancelBackgroundRefresh()},this._reauthenticateWithBackoff=function(){return D(n,void 0,void 0,b().mark((function t(){var r;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=0;case 1:return t.prev=2,t.next=5,this._headlessSessionClient.authenticate();case 5:return t.abrupt("return",t.sent);case 8:if(t.prev=8,t.t0=t.catch(2),!e.isUnrecoverableError(t.t0)){t.next=12;break}return t.abrupt("return",Promise.reject(t.t0));case 12:return r++,t.next=15,new Promise((function(t){return setTimeout(t,e.timeoutForAttempt(r))}));case 15:t.next=1;break;case 17:case"end":return t.stop()}}),t,this,[[2,8]])})))},this.timeout=null,this._subscriptionService.subscribeToState(this._onDataChange)}return k(e,[{key:"performBackgroundRefresh",value:function(){var e=this;this._reauthenticateWithBackoff().then((function(){e.scheduleBackgroundRefresh()})).catch((function(t){le("Session background refresh failed. Signalling to app that user is logged out.",{error:t}),e._subscriptionService.destroyState()}))}},{key:"scheduleBackgroundRefresh",value:function(){var t=this;this.cancelBackgroundRefresh(),this.timeout=setTimeout((function(){t.performBackgroundRefresh()}),e.REFRESH_INTERVAL_MS)}},{key:"cancelBackgroundRefresh",value:function(){null!==this.timeout&&(clearTimeout(this.timeout),this.timeout=null)}}],[{key:"timeoutForAttempt",value:function(e){return e=Math.min(e,7),Math.floor(350*Math.random())-175+2e3*Math.pow(2,e)}},{key:"isUnrecoverableError",value:function(e){return ie.includes(e.error_type)}}]),e}();Qe.REFRESH_INTERVAL_MS=18e4;var et="bootstrap",tt=function(){function e(t,r,n){var i=this;h(this,e),this._publicToken=t,this._networkClient=r,this._dataLayer=n,this._bootstrapDataPromise=this._networkClient.fetchSDK({url:"/projects/bootstrap/".concat(this._publicToken),method:"GET",errorMessage:"Error fetching bootstrap data for SDK for ".concat(this._publicToken)}).then(e.mapBootstrapData).then((function(e){return i._dataLayer.setItem(et,JSON.stringify(e)),e})).catch((function(e){return he(e),{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1,slugPattern:null,createOrganizationEnabled:!1,passwordConfig:null,runDFPProtectedAuth:!1}}))}return p(e,[{key:"getSync",value:function(){var e=this._dataLayer.getItem(et);if(null===e)return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1,slugPattern:null,createOrganizationEnabled:!1,passwordConfig:null,runDFPProtectedAuth:!1};try{return JSON.parse(e)}catch(e){return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1,slugPattern:null,createOrganizationEnabled:!1,passwordConfig:null,runDFPProtectedAuth:!1}}}},{key:"getAsync",value:function(){return this._bootstrapDataPromise}}],[{key:"mapBootstrapData",value:function(e){var t=null!==e.password_config?{ludsComplexity:e.password_config.luds_complexity,ludsMinimumCount:e.password_config.luds_minimum_count}:null;return{displayWatermark:!e.disable_sdk_watermark,captchaSettings:e.captcha_settings,cnameDomain:e.cname_domain,emailDomains:e.email_domains,pkceRequiredForEmailMagicLinks:e.pkce_required_for_email_magic_links,pkceRequiredForPasswordResets:e.pkce_required_for_password_resets,pkceRequiredForOAuth:e.pkce_required_for_oauth,pkceRequiredForSso:e.pkce_required_for_sso,slugPattern:e.slug_pattern,createOrganizationEnabled:e.create_organization_enabled,passwordConfig:t,runDFPProtectedAuth:"ENABLED"===e.dfp_protected_auth_enabled||"PASSIVE"===e.dfp_protected_auth_enabled}}}]),e}();function rt(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}var nt,it,ot,st,at,ct,ut=p((function e(t){var r=this;h(this,e),this.bootstrapPromise=t,this.executeRecaptcha=function(){return rt(r,void 0,void 0,u().mark((function e(){var t,r,n,i;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.state;case 2:if(t=e.sent,r=t.captchaClient,n=t.configured,i=t.siteKey,n){e.next=8;break}return e.abrupt("return",void 0);case 8:return e.next=10,new Promise((function(e){return r.ready(e)}));case 10:return e.abrupt("return",r.execute(i,{action:"LOGIN"}));case 11:case"end":return e.stop()}}),e,this)})))},this.state=t.then((function(e){return rt(r,void 0,void 0,u().mark((function t(){return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(e.captchaSettings.enabled){t.next=2;break}return t.abrupt("return",{configured:!1});case 2:return t.next=4,r=e.captchaSettings.siteKey,se("https://www.google.com/recaptcha/enterprise.js?render=".concat(r),(function(){return window.grecaptcha.enterprise}));case 4:return t.t0=t.sent,t.t1=e.captchaSettings.siteKey,t.abrupt("return",{configured:!0,captchaClient:t.t0,siteKey:t.t1});case 7:case"end":return t.stop()}var r}),t)})))}))})),lt=function(){function e(t){var r=this;h(this,e),this.iframeURL=t,this.oneTapStart=function(e){return r.call("oneTapStart",e)},this.oneTapSubmit=function(e){return r.call("oneTapSubmit",e)}}return p(e,[{key:"frameClient",get:function(){var e;return this._frameClient=null!==(e=this._frameClient)&&void 0!==e?e:new Ze(this.iframeURL),this._frameClient}},{key:"call",value:function(e,t){return this.frameClient.call(e,[t])}}]),e}();function ht(e){return ht="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ht(e)}function dt(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(i=n.key,o=void 0,o=function(e,t){if("object"!==ht(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==ht(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(i,"string"),"symbol"===ht(o)?o:String(o)),n)}var i,o}function pt(e,t,r){return t&&dt(e.prototype,t),r&&dt(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function ft(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function vt(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&wt(e,t)}function _t(e){var t=bt();return function(){var r,n=kt(e);if(t){var i=kt(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===ht(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return mt(e)}(this,r)}}function mt(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function yt(e){var t="function"==typeof Map?new Map:void 0;return yt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return gt(e,arguments,kt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),wt(n,e)},yt(e)}function gt(e,t,r){return gt=bt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&wt(i,r.prototype),i},gt.apply(null,arguments)}function bt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function wt(e,t){return wt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},wt(e,t)}function kt(e){return kt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},kt(e)}!function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(nt||(nt={})),function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Salesforce="salesforce",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch",e.Twitter="twitter",e.TikTok="tiktok",e.Snapchat="snapchat",e.Figma="figma",e.Yahoo="yahoo"}(it||(it={})),function(e){e.Vessel="Vessel",e.Phantom="Phantom",e.Metamask="Metamask",e.Coinbase="Coinbase",e.Binance="Binance",e.GenericEthereumWallet="Other Ethereum Wallet",e.GenericSolanaWallet="Other Solana Wallet"}(ot||(ot={})),function(e){e.embedded="embedded",e.floating="floating"}(st||(st={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(at||(at={})),function(e){e.MagicLinkLoginOrCreateEvent="MAGIC_LINK_LOGIN_OR_CREATE",e.OTPsLoginOrCreateEvent="OTP_LOGIN_OR_CREATE",e.OTPsAuthenticate="OTP_AUTHENTICATE",e.CryptoWalletAuthenticateStart="CRYPTO_WALLET_AUTHENTICATE_START",e.CryptoWalletAuthenticate="CRYPTO_WALLET_AUTHENTICATE",e.PasswordCreate="PASSWORD_CREATE",e.PasswordAuthenticate="PASSWORD_AUTHENTICATE",e.PasswordResetByEmailStart="PASSWORD_RESET_BY_EMAIL_START",e.PasswordResetByEmail="PASSWORD_RESET_BY_EMAIL",e.B2BMagicLinkEmailLoginOrSignup="B2B_MAGIC_LINK_EMAIL_LOGIN_OR_SIGNUP",e.B2BMagicLinkAuthenticate="B2B_MAGIC_LINK_AUTHENTICATE",e.B2BMagicLinkEmailDiscoverySend="B2B_MAGIC_LINK_EMAIL_DISCOVERY_SEND",e.B2BMagicLinkDiscoveryAuthenticate="B2B_MAGIC_LINK_DISCOVERY_AUTHENTICATE",e.B2BSSOStart="B2B_SSO_START",e.B2BSSOAuthenticate="B2B_SSO_AUTHENTICATE",e.B2BOAuthAuthenticate="B2B_SSO_AUTHENTICATE",e.B2BOAuthDiscoveryAuthenticate="B2B_OAUTH_DISCOVERY_AUTHENTICATE",e.B2BDiscoveryOrganizationsCreate="B2B_DISCOVERY_ORGANIZATIONS_CREATE",e.B2BDiscoveryIntermediateSessionExchange="B2B_DISCOVERY_INTERMEDIATE_SESSION_EXCHANGE",e.B2BPasswordAuthenticate="B2B_PASSWORD_AUTHENTICATE",e.B2BPasswordResetByEmailStart="B2B_PASSWORD_RESET_BY_EMAIL_START",e.B2BPasswordResetByEmail="B2B_PASSWORD_RESET_BY_EMAIL",e.B2BPasswordResetBySession="B2B_PASSWORD_RESET_BY_SESSION"}(ct||(ct={}));var St,Ot,Tt,Et,xt=function(e){vt(r,yt(Error));var t=_t(r);function r(e,n){var i;return ft(this,r),(i=t.call(this,e+"\n"+n)).message=e+"\n"+n,i.name="SDKAPIUnreachableError",i.details=n,Object.setPrototypeOf(mt(i),r.prototype),i}return pt(r)}(),Ct=function(e){vt(r,yt(Error));var t=_t(r);function r(e,n){var i;return ft(this,r),(i=t.call(this)).name="StytchSDKUsageError",i.message="Invalid call to ".concat(e,"\n")+n,i}return pt(r)}(),At=function(e){vt(r,yt(Error));var t=_t(r);function r(e){var n,i;ft(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var o=null===(i=e.body)||void 0===i?void 0:i.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(o),n}return pt(r)}(),Pt=function(e){vt(r,yt(Error));var t=_t(r);function r(e){var n;ft(this,r),(n=t.call(this)).name="StytchSDKAPIError";var i=e.status_code,o=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=o,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=i,n.message="[".concat(i,"] ").concat(o,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return pt(r)}(),Rt=function(e){vt(r,yt(Error));var t=_t(r);function r(e){var n;return ft(this,r),(n=t.call(this)).name="StytchSDKNativeError",n.error_type=e,n.message="".concat(e),n}return pt(r)}(),Lt=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];!function(e){e.BiometricsSensorError="biometrics_sensor_error",e.DeviceCredentialsNotAllowed="device_credentials_not_allowed",e.DeviceHardwareError="device_hardware_error",e.InternalError="internal_error",e.KeyInvalidated="key_invalidated",e.KeystoreUnavailable="keystore_unavailable",e.NoBiometricsEnrolled="no_biometrics_enrolled",e.NoBiometricsRegistration="no_biometrics_registration",e.SessionExpired="session_expired",e.UserCancellation="user_cancellation",e.UserLockedOut="user_locked_out",e.BiometricsNotAvailable="biometrics_not_available"}(St||(St={})),function(e){e.emailMagicLinks="emailMagicLinks",e.sso="sso",e.passwords="passwords",e.oauth="oauth"}(Ot||(Ot={})),function(e){e.Discovery="Discovery",e.Organization="Organization",e.PasswordReset="PasswordReset"}(Tt||(Tt={})),function(e){e.Google="google",e.Microsoft="microsoft"}(Et||(Et={}));var It=function(e){i(r,Oe);var t=s(r);function r(e,n,i,o,s,c){var l;return h(this,r),(l=t.call(this,e,n,i,o,s))._oneTap=c,l.startOneTap=function(e){return rt(a(l),void 0,void 0,u().mark((function t(){var r,n,i;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._oneTap.createOneTapClient();case 2:if((r=t.sent).success){t.next=5;break}throw new Error("One Tap could not load: ".concat(r.reason));case 5:return n=r.client,i=this._oneTap.createOnSuccessHandler({signupRedirectUrl:e.signup_redirect_url,loginRedirectUrl:e.login_redirect_url,onSuccess:this._oneTap.RedirectOnSuccess}),t.abrupt("return",n.render({style:{position:st.floating},onOneTapCancelled:e.onOneTapCancelled,callback:i}));case 8:case"end":return t.stop()}}),t,this)})))},l.googleOneTap={start:l.startOneTap},l}return p(r)}(),Bt=function(){function e(t,r,n,i){h(this,e),this._publicToken=t,this._subscriptionDataLayer=r,this.baseURL=n,this.additionalTelemetryDataFn=i,this.updateSessionToken=function(){return null},this.eventLogger=new ye({maxBatchSize:15,intervalDurationMs:800,logEventURL:this.buildSDKUrl("/events")})}return p(e,[{key:"logEvent",value:function(e){var t=e.name,r=e.details,n=e.error,i=void 0===n?{}:n;this.eventLogger.logEvent(this.createTelemetryBlob(),{public_token:this._publicToken,event_name:t,details:r,error_code:i.error_code,error_description:i.error_description,http_status_code:i.http_status_code})}},{key:"createTelemetryBlob",value:function(){return Object.assign(Object.assign({event_id:"event-id-".concat(J()),app_session_id:"app-session-id-".concat(J()),persistent_id:"persistent-id-".concat(J()),client_sent_at:(new Date).toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone},this.additionalTelemetryDataFn()),{app:{identifier:window.location.hostname},sdk:{identifier:"Stytch.js Javascript SDK",version:"2.0.1"}})}},{key:"fetchSDK",value:function(e){var t=e.url,r=e.body,n=e.errorMessage,i=e.method;return rt(this,void 0,void 0,u().mark((function e(){var o,s,a,c;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=this._subscriptionDataLayer.readSessionCookie().session_token,s="Basic "+window.btoa(this._publicToken+":"+(o||this._publicToken)),a=window.btoa(JSON.stringify(this.createTelemetryBlob())),c=window.location.origin,e.abrupt("return",$e({basicAuthHeader:s,body:r,errorMessage:n,finalURL:this.buildSDKUrl(t),method:i,xSDKClientHeader:a,xSDKParentHostHeader:c}));case 5:case"end":return e.stop()}}),e,this)})))}},{key:"buildSDKUrl",value:function(e){return"".concat(this.baseURL,"/sdk/v1").concat(e)}}]),e}(),jt=function(){function e(t,r,n){h(this,e),this._googleClient=t,this._publicToken=r,this._clientId=n}return p(e,[{key:"cancel",value:function(){this._googleClient.cancel()}},{key:"render",value:function(e){var t=e.callback,r=e.onOneTapCancelled,n=e.style;return rt(this,void 0,void 0,u().mark((function e(){var i,o=this;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={client_id:this._clientId,callback:t,auto_select:!1,context:"use",itp_support:!0},n.position===st.embedded&&(i.prompt_parent_id="google-parent-prompt",i.cancel_on_tap_outside=!1),this._googleClient.initialize(i),e.abrupt("return",new Promise((function(e){o._googleClient.prompt((function(t){return t.isSkippedMoment()?("user_cancel"===t.getSkippedReason()&&(null==r||r()),e({success:!1,reason:t.getSkippedReason()})):t.isNotDisplayed()?e({success:!1,reason:t.getNotDisplayedReason()}):(o.styleFrame(n),e({success:!0}))}))})));case 4:case"end":return e.stop()}}),e,this)})))}},{key:"styleFrame",value:function(e){e.position===st.embedded&&Array.from(document.getElementsByTagName("iframe")).forEach((function(e){e.src.includes(I)&&(e.style.width="100%")}))}}]),e}(),Dt=function(){function e(t,r){var n=this;h(this,e),this._publicToken=t,this.clientsideServices=r,this.createOnSuccessHandler=function(e){var t=e.loginRedirectUrl,r=e.signupRedirectUrl,i=e.onSuccess;return function(e){return rt(n,void 0,void 0,u().mark((function n(){var o,s,a;return u().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=e.credential,n.next=3,this.submitGoogleOneTapToken({credential:o,loginRedirectUrl:t,signupRedirectUrl:r});case 3:s=n.sent,a=s.redirect_url,i(a);case 6:case"end":return n.stop()}}),n,this)})))}},this.RedirectOnSuccess=function(e){window.location.href=e}}return p(e,[{key:"createOneTapClient",value:function(){return rt(this,void 0,void 0,u().mark((function e(){var t,r,n,i;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this.fetchGoogleStart();case 3:r=e.sent,t=r.googleClientId,e.next=11;break;case 7:return e.prev=7,e.t0=e.catch(0),n=e.t0,e.abrupt("return",{success:!1,reason:n.error_type});case 11:if(""!==t){e.next=13;break}return e.abrupt("return",{success:!1,reason:"oauth_config_not_found"});case 13:return e.t1=jt,e.next=16,se(B,(function(){return window.google.accounts.id}));case 16:return e.t2=e.sent,e.t3=this._publicToken,e.t4=t,i=new e.t1(e.t2,e.t3,e.t4),e.abrupt("return",{success:!0,client:i});case 21:case"end":return e.stop()}}),e,this,[[0,7]])})))}},{key:"fetchGoogleStart",value:function(){return this.googleConfig||(this.googleConfig=this.clientsideServices.oneTapStart({publicToken:this._publicToken})),this.googleConfig}},{key:"submitGoogleOneTapToken",value:function(e){var t=e.credential,r=e.loginRedirectUrl,n=e.signupRedirectUrl;return rt(this,void 0,void 0,u().mark((function e(){var i,o;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.fetchGoogleStart();case 2:return i=e.sent,o=i.oauthCallbackId,e.abrupt("return",this.clientsideServices.oneTapSubmit({publicToken:this._publicToken,idToken:t,loginRedirectURL:r,oauthCallbackID:o,signupRedirectURL:n}));case 5:case"end":return e.stop()}}),e,this)})))}}],[{key:"WillGoogleOneTapShowBannerForUA",value:function(e){var t=function(e,t){return-1!==e.indexOf(t)},r=t(e,"iPad")||t(e,"Android")&&!t(e,"Mobile")||t(e,"Silk"),n=t(e,"iPod")||t(e,"iPhone")||t(e,"Android")||t(e,"IEMobile");return!r&&n}},{key:"WillGoogleOneTapShowEmbedded",value:function(){return!e.WillGoogleOneTapShowBannerForUA(navigator.userAgent)}}]),e}();function Nt(e){var t=e.toString(16);return 1===t.length&&(t="0"+t),t}var Mt=function(){function e(t,r){h(this,e),this._dataLayer=t,this.namespace=r}return p(e,[{key:"key",value:function(){return"PKCE_VERIFIER:"+this.namespace}},{key:"startPKCETransaction",value:function(){return rt(this,void 0,void 0,u().mark((function t(){var r;return u().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.createProofkeyPair();case 2:return r=t.sent,this._dataLayer.setItem(this.key(),JSON.stringify(r)),t.abrupt("return",r);case 5:case"end":return t.stop()}}),t,this)})))}},{key:"getPKPair",value:function(){var e=this._dataLayer.getItem(this.key());if(null!==e)try{return JSON.parse(e)}catch(e){return void le("Found malformed Proof Key pair in localstorage.")}}},{key:"clearPKPair",value:function(){return this._dataLayer.removeItem(this.key())}}],[{key:"createProofkeyPair",value:function(){return rt(this,void 0,void 0,u().mark((function e(){var r,n,i;return u().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new Uint32Array(16),window.crypto.getRandomValues(r),n=Array.from(r).map(Nt).join(""),e.next=5,window.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(n));case 5:return i=e.sent,e.abrupt("return",{code_challenge:(o=i,s=void 0,btoa((s=String.fromCharCode).call.apply(s,[null].concat(t(new Uint8Array(o))))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),code_verifier:n});case 7:case"end":return e.stop()}var o,s}),e)})))}}]),e}(),Ft=function(){function e(t){h(this,e),this._networkClient=t}return p(e,[{key:"searchUser",value:function(e){return this._networkClient.fetchSDK({url:"/users/search",method:"POST",body:{email:e},errorMessage:"Error searching for user ".concat(e)})}},{key:"searchOrganization",value:function(e){return this._networkClient.fetchSDK({url:"/b2b/organizations/search",method:"POST",body:{organization_slug:e},errorMessage:"Error searching slug"})}},{key:"searchMember",value:function(e,t){return this._networkClient.fetchSDK({url:"/b2b/organizations/members/search",method:"POST",body:{email_address:e,organization_id:t},errorMessage:"Error searching for member ".concat(e)})}}]),e}(),Ut=function(t){return(document.cookie?document.cookie.split("; "):[]).filter((function(r){var n=e(r.split("="),1)[0];return t===n})).length>1};
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
22
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
24
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
25
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
26
+ function e(e, t) {
27
+ var _n = "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
28
+ if (!_n) {
29
+ if (Array.isArray(e) || (_n = r(e)) || t && e && "number" == typeof e.length) {
30
+ _n && (e = _n);
31
+ var i = 0,
32
+ s = function s() {};
33
+ return {
34
+ s: s,
35
+ n: function n() {
36
+ return i >= e.length ? {
37
+ done: !0
38
+ } : {
39
+ done: !1,
40
+ value: e[i++]
41
+ };
42
+ },
43
+ e: function e(_e2) {
44
+ throw _e2;
45
+ },
46
+ f: s
47
+ };
48
+ }
49
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
50
+ }
51
+ var o,
52
+ a = !0,
53
+ c = !1;
54
+ return {
55
+ s: function s() {
56
+ _n = _n.call(e);
57
+ },
58
+ n: function n() {
59
+ var e = _n.next();
60
+ return a = e.done, e;
61
+ },
62
+ e: function e(_e3) {
63
+ c = !0, o = _e3;
64
+ },
65
+ f: function f() {
66
+ try {
67
+ a || null == _n["return"] || _n["return"]();
68
+ } finally {
69
+ if (c) throw o;
70
+ }
71
+ }
72
+ };
73
+ }
74
+ function t(e, t) {
75
+ return function (e) {
76
+ if (Array.isArray(e)) return e;
77
+ }(e) || function (e, t) {
78
+ var r = null == e ? null : "undefined" != typeof Symbol && e[Symbol.iterator] || e["@@iterator"];
79
+ if (null != r) {
80
+ var n,
81
+ i,
82
+ s,
83
+ o,
84
+ a = [],
85
+ c = !0,
86
+ u = !1;
87
+ try {
88
+ if (s = (r = r.call(e)).next, 0 === t) {
89
+ if (Object(r) !== r) return;
90
+ c = !1;
91
+ } else for (; !(c = (n = s.call(r)).done) && (a.push(n.value), a.length !== t); c = !0);
92
+ } catch (e) {
93
+ u = !0, i = e;
94
+ } finally {
95
+ try {
96
+ if (!c && null != r["return"] && (o = r["return"](), Object(o) !== o)) return;
97
+ } finally {
98
+ if (u) throw i;
99
+ }
100
+ }
101
+ return a;
102
+ }
103
+ }(e, t) || r(e, t) || function () {
104
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
105
+ }();
106
+ }
107
+ function r(e, t) {
108
+ if (e) {
109
+ if ("string" == typeof e) return n(e, t);
110
+ var r = Object.prototype.toString.call(e).slice(8, -1);
111
+ return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? n(e, t) : void 0;
112
+ }
113
+ }
114
+ function n(e, t) {
115
+ (null == t || t > e.length) && (t = e.length);
116
+ for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
117
+ return n;
118
+ }
119
+ function i(e) {
120
+ return i = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) {
121
+ return _typeof(e);
122
+ } : function (e) {
123
+ return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : _typeof(e);
124
+ }, i(e);
125
+ }
126
+ function s() {
127
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
128
+ s = function s() {
129
+ return e;
130
+ };
131
+ var e = {},
132
+ t = Object.prototype,
133
+ r = t.hasOwnProperty,
134
+ n = Object.defineProperty || function (e, t, r) {
135
+ e[t] = r.value;
136
+ },
137
+ o = "function" == typeof Symbol ? Symbol : {},
138
+ a = o.iterator || "@@iterator",
139
+ c = o.asyncIterator || "@@asyncIterator",
140
+ u = o.toStringTag || "@@toStringTag";
141
+ function l(e, t, r) {
142
+ return Object.defineProperty(e, t, {
143
+ value: r,
144
+ enumerable: !0,
145
+ configurable: !0,
146
+ writable: !0
147
+ }), e[t];
148
+ }
149
+ try {
150
+ l({}, "");
151
+ } catch (e) {
152
+ l = function l(e, t, r) {
153
+ return e[t] = r;
154
+ };
155
+ }
156
+ function d(e, t, r, i) {
157
+ var s = t && t.prototype instanceof f ? t : f,
158
+ o = Object.create(s.prototype),
159
+ a = new E(i || []);
160
+ return n(o, "_invoke", {
161
+ value: S(e, r, a)
162
+ }), o;
163
+ }
164
+ function h(e, t, r) {
165
+ try {
166
+ return {
167
+ type: "normal",
168
+ arg: e.call(t, r)
169
+ };
170
+ } catch (e) {
171
+ return {
172
+ type: "throw",
173
+ arg: e
174
+ };
175
+ }
176
+ }
177
+ e.wrap = d;
178
+ var p = {};
179
+ function f() {}
180
+ function _() {}
181
+ function v() {}
182
+ var m = {};
183
+ l(m, a, function () {
184
+ return this;
185
+ });
186
+ var y = Object.getPrototypeOf,
187
+ g = y && y(y(x([])));
188
+ g && g !== t && r.call(g, a) && (m = g);
189
+ var b = v.prototype = f.prototype = Object.create(m);
190
+ function k(e) {
191
+ ["next", "throw", "return"].forEach(function (t) {
192
+ l(e, t, function (e) {
193
+ return this._invoke(t, e);
194
+ });
195
+ });
196
+ }
197
+ function w(e, t) {
198
+ function s(n, o, a, c) {
199
+ var u = h(e[n], e, o);
200
+ if ("throw" !== u.type) {
201
+ var l = u.arg,
202
+ d = l.value;
203
+ return d && "object" == i(d) && r.call(d, "__await") ? t.resolve(d.__await).then(function (e) {
204
+ s("next", e, a, c);
205
+ }, function (e) {
206
+ s("throw", e, a, c);
207
+ }) : t.resolve(d).then(function (e) {
208
+ l.value = e, a(l);
209
+ }, function (e) {
210
+ return s("throw", e, a, c);
211
+ });
212
+ }
213
+ c(u.arg);
214
+ }
215
+ var o;
216
+ n(this, "_invoke", {
217
+ value: function value(e, r) {
218
+ function n() {
219
+ return new t(function (t, n) {
220
+ s(e, r, t, n);
221
+ });
222
+ }
223
+ return o = o ? o.then(n, n) : n();
224
+ }
225
+ });
226
+ }
227
+ function S(e, t, r) {
228
+ var n = "suspendedStart";
229
+ return function (i, s) {
230
+ if ("executing" === n) throw new Error("Generator is already running");
231
+ if ("completed" === n) {
232
+ if ("throw" === i) throw s;
233
+ return A();
234
+ }
235
+ for (r.method = i, r.arg = s;;) {
236
+ var o = r.delegate;
237
+ if (o) {
238
+ var a = T(o, r);
239
+ if (a) {
240
+ if (a === p) continue;
241
+ return a;
242
+ }
243
+ }
244
+ if ("next" === r.method) r.sent = r._sent = r.arg;else if ("throw" === r.method) {
245
+ if ("suspendedStart" === n) throw n = "completed", r.arg;
246
+ r.dispatchException(r.arg);
247
+ } else "return" === r.method && r.abrupt("return", r.arg);
248
+ n = "executing";
249
+ var c = h(e, t, r);
250
+ if ("normal" === c.type) {
251
+ if (n = r.done ? "completed" : "suspendedYield", c.arg === p) continue;
252
+ return {
253
+ value: c.arg,
254
+ done: r.done
255
+ };
256
+ }
257
+ "throw" === c.type && (n = "completed", r.method = "throw", r.arg = c.arg);
258
+ }
259
+ };
260
+ }
261
+ function T(e, t) {
262
+ var r = t.method,
263
+ n = e.iterator[r];
264
+ if (void 0 === n) return t.delegate = null, "throw" === r && e.iterator["return"] && (t.method = "return", t.arg = void 0, T(e, t), "throw" === t.method) || "return" !== r && (t.method = "throw", t.arg = new TypeError("The iterator does not provide a '" + r + "' method")), p;
265
+ var i = h(n, e.iterator, t.arg);
266
+ if ("throw" === i.type) return t.method = "throw", t.arg = i.arg, t.delegate = null, p;
267
+ var s = i.arg;
268
+ return s ? s.done ? (t[e.resultName] = s.value, t.next = e.nextLoc, "return" !== t.method && (t.method = "next", t.arg = void 0), t.delegate = null, p) : s : (t.method = "throw", t.arg = new TypeError("iterator result is not an object"), t.delegate = null, p);
269
+ }
270
+ function O(e) {
271
+ var t = {
272
+ tryLoc: e[0]
273
+ };
274
+ 1 in e && (t.catchLoc = e[1]), 2 in e && (t.finallyLoc = e[2], t.afterLoc = e[3]), this.tryEntries.push(t);
275
+ }
276
+ function C(e) {
277
+ var t = e.completion || {};
278
+ t.type = "normal", delete t.arg, e.completion = t;
279
+ }
280
+ function E(e) {
281
+ this.tryEntries = [{
282
+ tryLoc: "root"
283
+ }], e.forEach(O, this), this.reset(!0);
284
+ }
285
+ function x(e) {
286
+ if (e) {
287
+ var t = e[a];
288
+ if (t) return t.call(e);
289
+ if ("function" == typeof e.next) return e;
290
+ if (!isNaN(e.length)) {
291
+ var n = -1,
292
+ i = function t() {
293
+ for (; ++n < e.length;) if (r.call(e, n)) return t.value = e[n], t.done = !1, t;
294
+ return t.value = void 0, t.done = !0, t;
295
+ };
296
+ return i.next = i;
297
+ }
298
+ }
299
+ return {
300
+ next: A
301
+ };
302
+ }
303
+ function A() {
304
+ return {
305
+ value: void 0,
306
+ done: !0
307
+ };
308
+ }
309
+ return _.prototype = v, n(b, "constructor", {
310
+ value: v,
311
+ configurable: !0
312
+ }), n(v, "constructor", {
313
+ value: _,
314
+ configurable: !0
315
+ }), _.displayName = l(v, u, "GeneratorFunction"), e.isGeneratorFunction = function (e) {
316
+ var t = "function" == typeof e && e.constructor;
317
+ return !!t && (t === _ || "GeneratorFunction" === (t.displayName || t.name));
318
+ }, e.mark = function (e) {
319
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, v) : (e.__proto__ = v, l(e, u, "GeneratorFunction")), e.prototype = Object.create(b), e;
320
+ }, e.awrap = function (e) {
321
+ return {
322
+ __await: e
323
+ };
324
+ }, k(w.prototype), l(w.prototype, c, function () {
325
+ return this;
326
+ }), e.AsyncIterator = w, e.async = function (t, r, n, i, s) {
327
+ void 0 === s && (s = Promise);
328
+ var o = new w(d(t, r, n, i), s);
329
+ return e.isGeneratorFunction(r) ? o : o.next().then(function (e) {
330
+ return e.done ? e.value : o.next();
331
+ });
332
+ }, k(b), l(b, u, "Generator"), l(b, a, function () {
333
+ return this;
334
+ }), l(b, "toString", function () {
335
+ return "[object Generator]";
336
+ }), e.keys = function (e) {
337
+ var t = Object(e),
338
+ r = [];
339
+ for (var n in t) r.push(n);
340
+ return r.reverse(), function e() {
341
+ for (; r.length;) {
342
+ var n = r.pop();
343
+ if (n in t) return e.value = n, e.done = !1, e;
344
+ }
345
+ return e.done = !0, e;
346
+ };
347
+ }, e.values = x, E.prototype = {
348
+ constructor: E,
349
+ reset: function reset(e) {
350
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = void 0, this.done = !1, this.delegate = null, this.method = "next", this.arg = void 0, this.tryEntries.forEach(C), !e) for (var t in this) "t" === t.charAt(0) && r.call(this, t) && !isNaN(+t.slice(1)) && (this[t] = void 0);
351
+ },
352
+ stop: function stop() {
353
+ this.done = !0;
354
+ var e = this.tryEntries[0].completion;
355
+ if ("throw" === e.type) throw e.arg;
356
+ return this.rval;
357
+ },
358
+ dispatchException: function dispatchException(e) {
359
+ if (this.done) throw e;
360
+ var t = this;
361
+ function n(r, n) {
362
+ return o.type = "throw", o.arg = e, t.next = r, n && (t.method = "next", t.arg = void 0), !!n;
363
+ }
364
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
365
+ var s = this.tryEntries[i],
366
+ o = s.completion;
367
+ if ("root" === s.tryLoc) return n("end");
368
+ if (s.tryLoc <= this.prev) {
369
+ var a = r.call(s, "catchLoc"),
370
+ c = r.call(s, "finallyLoc");
371
+ if (a && c) {
372
+ if (this.prev < s.catchLoc) return n(s.catchLoc, !0);
373
+ if (this.prev < s.finallyLoc) return n(s.finallyLoc);
374
+ } else if (a) {
375
+ if (this.prev < s.catchLoc) return n(s.catchLoc, !0);
376
+ } else {
377
+ if (!c) throw new Error("try statement without catch or finally");
378
+ if (this.prev < s.finallyLoc) return n(s.finallyLoc);
379
+ }
380
+ }
381
+ }
382
+ },
383
+ abrupt: function abrupt(e, t) {
384
+ for (var n = this.tryEntries.length - 1; n >= 0; --n) {
385
+ var i = this.tryEntries[n];
386
+ if (i.tryLoc <= this.prev && r.call(i, "finallyLoc") && this.prev < i.finallyLoc) {
387
+ var s = i;
388
+ break;
389
+ }
390
+ }
391
+ s && ("break" === e || "continue" === e) && s.tryLoc <= t && t <= s.finallyLoc && (s = null);
392
+ var o = s ? s.completion : {};
393
+ return o.type = e, o.arg = t, s ? (this.method = "next", this.next = s.finallyLoc, p) : this.complete(o);
394
+ },
395
+ complete: function complete(e, t) {
396
+ if ("throw" === e.type) throw e.arg;
397
+ return "break" === e.type || "continue" === e.type ? this.next = e.arg : "return" === e.type ? (this.rval = this.arg = e.arg, this.method = "return", this.next = "end") : "normal" === e.type && t && (this.next = t), p;
398
+ },
399
+ finish: function finish(e) {
400
+ for (var t = this.tryEntries.length - 1; t >= 0; --t) {
401
+ var r = this.tryEntries[t];
402
+ if (r.finallyLoc === e) return this.complete(r.completion, r.afterLoc), C(r), p;
403
+ }
404
+ },
405
+ "catch": function _catch(e) {
406
+ for (var t = this.tryEntries.length - 1; t >= 0; --t) {
407
+ var r = this.tryEntries[t];
408
+ if (r.tryLoc === e) {
409
+ var n = r.completion;
410
+ if ("throw" === n.type) {
411
+ var i = n.arg;
412
+ C(r);
413
+ }
414
+ return i;
415
+ }
416
+ }
417
+ throw new Error("illegal catch attempt");
418
+ },
419
+ delegateYield: function delegateYield(e, t, r) {
420
+ return this.delegate = {
421
+ iterator: x(e),
422
+ resultName: t,
423
+ nextLoc: r
424
+ }, "next" === this.method && (this.arg = void 0), p;
425
+ }
426
+ }, e;
427
+ }
428
+ function o(e, t) {
429
+ for (var r = 0; r < t.length; r++) {
430
+ var n = t[r];
431
+ n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, (s = n.key, o = void 0, o = function (e, t) {
432
+ if ("object" !== i(e) || null === e) return e;
433
+ var r = e[Symbol.toPrimitive];
434
+ if (void 0 !== r) {
435
+ var n = r.call(e, t || "default");
436
+ if ("object" !== i(n)) return n;
437
+ throw new TypeError("@@toPrimitive must return a primitive value.");
438
+ }
439
+ return ("string" === t ? String : Number)(e);
440
+ }(s, "string"), "symbol" === i(o) ? o : String(o)), n);
441
+ }
442
+ var s, o;
443
+ }
444
+ function a(e, t, r) {
445
+ return t && o(e.prototype, t), r && o(e, r), Object.defineProperty(e, "prototype", {
446
+ writable: !1
447
+ }), e;
448
+ }
449
+ function c(e, t) {
450
+ if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
451
+ }
452
+ function u(e, t) {
453
+ if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
454
+ e.prototype = Object.create(t && t.prototype, {
455
+ constructor: {
456
+ value: e,
457
+ writable: !0,
458
+ configurable: !0
459
+ }
460
+ }), Object.defineProperty(e, "prototype", {
461
+ writable: !1
462
+ }), t && _(e, t);
463
+ }
464
+ function l(e) {
465
+ var t = f();
466
+ return function () {
467
+ var r,
468
+ n = v(e);
469
+ if (t) {
470
+ var s = v(this).constructor;
471
+ r = Reflect.construct(n, arguments, s);
472
+ } else r = n.apply(this, arguments);
473
+ return function (e, t) {
474
+ if (t && ("object" === i(t) || "function" == typeof t)) return t;
475
+ if (void 0 !== t) throw new TypeError("Derived constructors may only return object or undefined");
476
+ return d(e);
477
+ }(this, r);
478
+ };
479
+ }
480
+ function d(e) {
481
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
482
+ return e;
483
+ }
484
+ function h(e) {
485
+ var t = "function" == typeof Map ? new Map() : void 0;
486
+ return h = function h(e) {
487
+ if (null === e || (r = e, -1 === Function.toString.call(r).indexOf("[native code]"))) return e;
488
+ var r;
489
+ if ("function" != typeof e) throw new TypeError("Super expression must either be null or a function");
490
+ if (void 0 !== t) {
491
+ if (t.has(e)) return t.get(e);
492
+ t.set(e, n);
493
+ }
494
+ function n() {
495
+ return p(e, arguments, v(this).constructor);
496
+ }
497
+ return n.prototype = Object.create(e.prototype, {
498
+ constructor: {
499
+ value: n,
500
+ enumerable: !1,
501
+ writable: !0,
502
+ configurable: !0
503
+ }
504
+ }), _(n, e);
505
+ }, h(e);
506
+ }
507
+ function p(e, t, r) {
508
+ return p = f() ? Reflect.construct.bind() : function (e, t, r) {
509
+ var n = [null];
510
+ n.push.apply(n, t);
511
+ var i = new (Function.bind.apply(e, n))();
512
+ return r && _(i, r.prototype), i;
513
+ }, p.apply(null, arguments);
514
+ }
515
+ function f() {
516
+ if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
517
+ if (Reflect.construct.sham) return !1;
518
+ if ("function" == typeof Proxy) return !0;
519
+ try {
520
+ return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})), !0;
521
+ } catch (e) {
522
+ return !1;
523
+ }
524
+ }
525
+ function _(e, t) {
526
+ return _ = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (e, t) {
527
+ return e.__proto__ = t, e;
528
+ }, _(e, t);
529
+ }
530
+ function v(e) {
531
+ return v = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (e) {
532
+ return e.__proto__ || Object.getPrototypeOf(e);
533
+ }, v(e);
534
+ }
535
+ var m,
536
+ y = "https://accounts.google.com/gsi",
537
+ g = "".concat(y, "/client");
538
+ function b(e, t) {
539
+ var r = {};
540
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
541
+ if (null != e && "function" == typeof Object.getOwnPropertySymbols) {
542
+ var i = 0;
543
+ for (n = Object.getOwnPropertySymbols(e); i < n.length; i++) t.indexOf(n[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[i]) && (r[n[i]] = e[n[i]]);
544
+ }
545
+ return r;
546
+ }
547
+ function k(e, t, r, n) {
548
+ return new (r || (r = Promise))(function (i, s) {
549
+ function o(e) {
550
+ try {
551
+ c(n.next(e));
552
+ } catch (e) {
553
+ s(e);
554
+ }
555
+ }
556
+ function a(e) {
557
+ try {
558
+ c(n["throw"](e));
559
+ } catch (e) {
560
+ s(e);
561
+ }
562
+ }
563
+ function c(e) {
564
+ var t;
565
+ e.done ? i(e.value) : (t = e.value, t instanceof r ? t : new r(function (e) {
566
+ e(t);
567
+ })).then(o, a);
568
+ }
569
+ c((n = n.apply(e, t || [])).next());
570
+ });
571
+ }
572
+ var w = new Uint8Array(16);
573
+ function S() {
574
+ if (!m && !(m = "undefined" != typeof crypto && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || "undefined" != typeof msCrypto && "function" == typeof msCrypto.getRandomValues && msCrypto.getRandomValues.bind(msCrypto))) throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
575
+ return m(w);
576
+ }
577
+ var T = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
578
+ for (var O, C, E, x, A, P, R = [], D = 0; D < 256; ++D) R.push((D + 256).toString(16).substr(1));
579
+ function B(e) {
580
+ var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 0,
581
+ r = (R[e[t + 0]] + R[e[t + 1]] + R[e[t + 2]] + R[e[t + 3]] + "-" + R[e[t + 4]] + R[e[t + 5]] + "-" + R[e[t + 6]] + R[e[t + 7]] + "-" + R[e[t + 8]] + R[e[t + 9]] + "-" + R[e[t + 10]] + R[e[t + 11]] + R[e[t + 12]] + R[e[t + 13]] + R[e[t + 14]] + R[e[t + 15]]).toLowerCase();
582
+ if (!function (e) {
583
+ return "string" == typeof e && T.test(e);
584
+ }(r)) throw TypeError("Stringified UUID is invalid");
585
+ return r;
586
+ }
587
+ function I(e, t, r) {
588
+ var n = (e = e || {}).random || (e.rng || S)();
589
+ if (n[6] = 15 & n[6] | 64, n[8] = 63 & n[8] | 128, t) {
590
+ r = r || 0;
591
+ for (var i = 0; i < 16; ++i) t[r + i] = n[i];
592
+ return t;
593
+ }
594
+ return B(n);
595
+ }
596
+ !function (e) {
597
+ e.emailMagicLinks = "emailMagicLinks", e.oauth = "oauth", e.otp = "otp", e.crypto = "crypto", e.passwords = "passwords";
598
+ }(O || (O = {})), function (e) {
599
+ e.Google = "google", e.Microsoft = "microsoft", e.Apple = "apple", e.Github = "github", e.GitLab = "gitlab", e.Facebook = "facebook", e.Discord = "discord", e.Salesforce = "salesforce", e.Slack = "slack", e.Amazon = "amazon", e.Bitbucket = "bitbucket", e.LinkedIn = "linkedin", e.Coinbase = "coinbase", e.Twitch = "twitch", e.Twitter = "twitter", e.TikTok = "tiktok", e.Snapchat = "snapchat", e.Figma = "figma", e.Yahoo = "yahoo";
600
+ }(C || (C = {})), function (e) {
601
+ e.Vessel = "Vessel", e.Phantom = "Phantom", e.Metamask = "Metamask", e.Coinbase = "Coinbase", e.Binance = "Binance", e.GenericEthereumWallet = "Other Ethereum Wallet", e.GenericSolanaWallet = "Other Solana Wallet";
602
+ }(E || (E = {})), function (e) {
603
+ e.embedded = "embedded", e.floating = "floating";
604
+ }(x || (x = {})), function (e) {
605
+ e.SMS = "sms", e.WhatsApp = "whatsapp", e.Email = "email";
606
+ }(A || (A = {})), function (e) {
607
+ e.MagicLinkLoginOrCreateEvent = "MAGIC_LINK_LOGIN_OR_CREATE", e.OTPsLoginOrCreateEvent = "OTP_LOGIN_OR_CREATE", e.OTPsAuthenticate = "OTP_AUTHENTICATE", e.CryptoWalletAuthenticateStart = "CRYPTO_WALLET_AUTHENTICATE_START", e.CryptoWalletAuthenticate = "CRYPTO_WALLET_AUTHENTICATE", e.PasswordCreate = "PASSWORD_CREATE", e.PasswordAuthenticate = "PASSWORD_AUTHENTICATE", e.PasswordResetByEmailStart = "PASSWORD_RESET_BY_EMAIL_START", e.PasswordResetByEmail = "PASSWORD_RESET_BY_EMAIL", e.B2BMagicLinkEmailLoginOrSignup = "B2B_MAGIC_LINK_EMAIL_LOGIN_OR_SIGNUP", e.B2BMagicLinkAuthenticate = "B2B_MAGIC_LINK_AUTHENTICATE", e.B2BMagicLinkEmailDiscoverySend = "B2B_MAGIC_LINK_EMAIL_DISCOVERY_SEND", e.B2BMagicLinkDiscoveryAuthenticate = "B2B_MAGIC_LINK_DISCOVERY_AUTHENTICATE", e.B2BSSOStart = "B2B_SSO_START", e.B2BSSOAuthenticate = "B2B_SSO_AUTHENTICATE", e.B2BOAuthAuthenticate = "B2B_SSO_AUTHENTICATE", e.B2BOAuthDiscoveryAuthenticate = "B2B_OAUTH_DISCOVERY_AUTHENTICATE", e.B2BDiscoveryOrganizationsCreate = "B2B_DISCOVERY_ORGANIZATIONS_CREATE", e.B2BDiscoveryIntermediateSessionExchange = "B2B_DISCOVERY_INTERMEDIATE_SESSION_EXCHANGE", e.B2BPasswordAuthenticate = "B2B_PASSWORD_AUTHENTICATE", e.B2BPasswordResetByEmailStart = "B2B_PASSWORD_RESET_BY_EMAIL_START", e.B2BPasswordResetByEmail = "B2B_PASSWORD_RESET_BY_EMAIL", e.B2BPasswordResetBySession = "B2B_PASSWORD_RESET_BY_SESSION";
608
+ }(P || (P = {}));
609
+ var L,
610
+ j,
611
+ M,
612
+ N,
613
+ F = function (e) {
614
+ u(r, h(Error));
615
+ var t = l(r);
616
+ function r(e, n) {
617
+ var i;
618
+ return c(this, r), (i = t.call(this, e + "\n" + n)).message = e + "\n" + n, i.name = "SDKAPIUnreachableError", i.details = n, Object.setPrototypeOf(d(i), r.prototype), i;
619
+ }
620
+ return a(r);
621
+ }(),
622
+ U = function (e) {
623
+ u(r, h(Error));
624
+ var t = l(r);
625
+ function r(e, n) {
626
+ var i;
627
+ return c(this, r), (i = t.call(this)).name = "StytchSDKUsageError", i.message = "Invalid call to ".concat(e, "\n") + n, i;
628
+ }
629
+ return a(r);
630
+ }(),
631
+ K = function (e) {
632
+ u(r, h(Error));
633
+ var t = l(r);
634
+ function r(e) {
635
+ var n, i;
636
+ c(this, r), (n = t.call(this)).name = "StytchSDKSchemaError";
637
+ var s = null === (i = e.body) || void 0 === i ? void 0 : i.map(function (e) {
638
+ return "".concat(e.dataPath, ": ").concat(e.message);
639
+ }).join("\n");
640
+ return n.message = "[400] Request does not match expected schema\n".concat(s), n;
641
+ }
642
+ return a(r);
643
+ }(),
644
+ q = function (e) {
645
+ u(r, h(Error));
646
+ var t = l(r);
647
+ function r(e) {
648
+ var n;
649
+ c(this, r), (n = t.call(this)).name = "StytchSDKAPIError";
650
+ var i = e.status_code,
651
+ s = e.error_type,
652
+ o = e.error_message,
653
+ a = e.error_url,
654
+ u = e.request_id;
655
+ return n.error_type = s, n.error_message = o, n.error_url = a, n.request_id = u, n.status_code = i, n.message = "[".concat(i, "] ").concat(s, "\n") + "".concat(o, "\n") + "See ".concat(a, " for more information.\n") + (u ? "request_id: ".concat(u, "\n") : ""), n;
656
+ }
657
+ return a(r);
658
+ }(),
659
+ W = ["unauthorized_credentials", "user_unauthenticated", "invalid_secret_authentication", "session_not_found"];
660
+ !function (e) {
661
+ e.BiometricsSensorError = "biometrics_sensor_error", e.DeviceCredentialsNotAllowed = "device_credentials_not_allowed", e.DeviceHardwareError = "device_hardware_error", e.InternalError = "internal_error", e.KeyInvalidated = "key_invalidated", e.KeystoreUnavailable = "keystore_unavailable", e.NoBiometricsEnrolled = "no_biometrics_enrolled", e.NoBiometricsRegistration = "no_biometrics_registration", e.SessionExpired = "session_expired", e.UserCancellation = "user_cancellation", e.UserLockedOut = "user_locked_out", e.BiometricsNotAvailable = "biometrics_not_available";
662
+ }(L || (L = {})), function (e) {
663
+ e.emailMagicLinks = "emailMagicLinks", e.sso = "sso", e.passwords = "passwords", e.oauth = "oauth";
664
+ }(j || (j = {})), function (e) {
665
+ e.Discovery = "Discovery", e.Organization = "Organization", e.PasswordReset = "PasswordReset";
666
+ }(M || (M = {})), function (e) {
667
+ e.Google = "google", e.Microsoft = "microsoft";
668
+ }(N || (N = {}));
669
+ var G = {};
670
+ function H(e, t) {
671
+ return k(this, void 0, void 0, s().mark(function r() {
672
+ return s().wrap(function (r) {
673
+ for (;;) switch (r.prev = r.next) {
674
+ case 0:
675
+ if (void 0 === G[e]) {
676
+ r.next = 2;
677
+ break;
678
+ }
679
+ return r.abrupt("return", G[e]);
680
+ case 2:
681
+ return G[e] = z(e, t), r.abrupt("return", G[e]);
682
+ case 4:
683
+ case "end":
684
+ return r.stop();
685
+ }
686
+ }, r);
687
+ }));
688
+ }
689
+ function z(e, t) {
690
+ return new Promise(function (r, n) {
691
+ var i = function (e) {
692
+ var t = Y(e);
693
+ if (t[0]) return t[0];
694
+ }(e);
695
+ if (i && "true" === i.dataset.loaded) try {
696
+ r(t());
697
+ } catch (t) {
698
+ return n(new Error("".concat(e, " already loaded, but module was not found in global scope: ").concat(t)));
699
+ }
700
+ var s = function (e) {
701
+ var t = document.createElement("script");
702
+ return t.setAttribute("src", e), t.setAttribute("async", "true"), t.setAttribute("defer", "true"), document.head.appendChild(t), t;
703
+ }(e);
704
+ s.addEventListener("load", function () {
705
+ s.dataset.loaded = "true";
706
+ try {
707
+ r(t());
708
+ } catch (t) {
709
+ n(new Error("".concat(e, " was loaded, but module was not found in global scope: ").concat(t)));
710
+ }
711
+ }), s.addEventListener("error", function (t) {
712
+ n(new Error("".concat(e, " could not be loaded: ").concat(t)));
713
+ });
714
+ });
715
+ }
716
+ var Y = function Y(e) {
717
+ return document.querySelectorAll('script[src="'.concat(e, '"]'));
718
+ };
719
+ var V = ["[Stytch]"],
720
+ J = function J() {
721
+ for (var e, t = arguments.length, r = new Array(t), n = 0; n < t; n++) r[n] = arguments[n];
722
+ return (e = console).warn.apply(e, V.concat(r));
723
+ },
724
+ $ = function $() {
725
+ for (var e, t = arguments.length, r = new Array(t), n = 0; n < t; n++) r[n] = arguments[n];
726
+ return (e = console).error.apply(e, V.concat(r));
727
+ },
728
+ X = "\nYou can find your public token at https://stytch.com/dashboard/api-keys.",
729
+ Z = function Z(t) {
730
+ var r = {
731
+ isObject: function isObject(e, n) {
732
+ var s = "object" === i(n) && !Array.isArray(n) && null !== n;
733
+ if (!s) throw new U(t, e + " must be an object.");
734
+ return r;
735
+ },
736
+ isOptionalObject: function isOptionalObject(e, t) {
737
+ return void 0 === t ? r : r.isObject(e, t);
738
+ },
739
+ isString: function isString(e, n) {
740
+ if ("string" != typeof n) throw new U(t, e + " must be a string.");
741
+ return r;
742
+ },
743
+ isOptionalString: function isOptionalString(e, t) {
744
+ return void 0 === t ? r : r.isString(e, t);
745
+ },
746
+ isStringArray: function isStringArray(n, i) {
747
+ if (!Array.isArray(i)) throw new U(t, n + " must be an array of strings.");
748
+ var s,
749
+ o = e(i);
750
+ try {
751
+ for (o.s(); !(s = o.n()).done;) {
752
+ if ("string" != typeof s.value) throw new U(t, n + " must be an array of strings.");
753
+ }
754
+ } catch (e) {
755
+ o.e(e);
756
+ } finally {
757
+ o.f();
758
+ }
759
+ return r;
760
+ },
761
+ isOptionalStringArray: function isOptionalStringArray(e, t) {
762
+ return void 0 === t ? r : r.isStringArray(e, t);
763
+ },
764
+ isNumber: function isNumber(e, n) {
765
+ if ("number" != typeof n) throw new U(t, e + " must be a number.");
766
+ return r;
767
+ },
768
+ isOptionalNumber: function isOptionalNumber(e, t) {
769
+ return void 0 === t ? r : r.isNumber(e, t);
770
+ },
771
+ isBoolean: function isBoolean(e, n) {
772
+ if ("boolean" != typeof n) throw new U(t, e + " must be a boolean.");
773
+ return r;
774
+ },
775
+ isOptionalBoolean: function isOptionalBoolean(e, t) {
776
+ return void 0 === t ? r : r.isBoolean(e, t);
777
+ }
778
+ };
779
+ return r;
780
+ },
781
+ Q = function Q(e) {
782
+ return b(e, ["request_id", "status_code"]);
783
+ },
784
+ ee = function ee(e) {
785
+ return b(e, ["__user"]);
786
+ },
787
+ te = a(function e(t, r, n) {
788
+ var i = this;
789
+ c(this, e), this.bootstrapPromise = n, this.isEnabled = function () {
790
+ return k(i, void 0, void 0, s().mark(function e() {
791
+ return s().wrap(function (e) {
792
+ for (;;) switch (e.prev = e.next) {
793
+ case 0:
794
+ return e.abrupt("return", this.state.then(function (e) {
795
+ return e.enabled;
796
+ }));
797
+ case 1:
798
+ case "end":
799
+ return e.stop();
800
+ }
801
+ }, e, this);
802
+ }));
803
+ }, this.getTelemetryID = function () {
804
+ return k(i, void 0, void 0, s().mark(function e() {
805
+ var t, r, n, i;
806
+ return s().wrap(function (e) {
807
+ for (;;) switch (e.prev = e.next) {
808
+ case 0:
809
+ return e.next = 2, this.state;
810
+ case 2:
811
+ if (t = e.sent, r = t.publicToken, n = t.enabled, i = t.dfpBackendURL, n) {
812
+ e.next = 8;
813
+ break;
814
+ }
815
+ return e.abrupt("return", void 0);
816
+ case 8:
817
+ return e.next = 10, window.GetTelemetryID(r, "".concat(i, "/submit"));
818
+ case 10:
819
+ return e.abrupt("return", e.sent);
820
+ case 11:
821
+ case "end":
822
+ return e.stop();
823
+ }
824
+ }, e, this);
825
+ }));
826
+ }, this.state = n.then(function (e) {
827
+ return k(i, void 0, void 0, s().mark(function n() {
828
+ return s().wrap(function (n) {
829
+ for (;;) switch (n.prev = n.next) {
830
+ case 0:
831
+ if (e.runDFPProtectedAuth) {
832
+ n.next = 2;
833
+ break;
834
+ }
835
+ return n.abrupt("return", {
836
+ publicToken: t,
837
+ dfpBackendURL: r,
838
+ enabled: !1,
839
+ loaded: !1
840
+ });
841
+ case 2:
842
+ return n.next = 4, void H("".concat("https://elements.stytch.com", "/telemetry.js"), function () {
843
+ return window;
844
+ });
845
+ case 4:
846
+ return n.abrupt("return", {
847
+ publicToken: t,
848
+ dfpBackendURL: r,
849
+ enabled: !0,
850
+ loaded: !0
851
+ });
852
+ case 5:
853
+ case "end":
854
+ return n.stop();
855
+ }
856
+ }, n);
857
+ }));
858
+ });
859
+ }),
860
+ re = function () {
861
+ function e() {
862
+ c(this, e);
863
+ }
864
+ return a(e, null, [{
865
+ key: "marshall",
866
+ value: function value(e) {
867
+ return Object.assign(Object.assign({}, e), {
868
+ name: e.name,
869
+ message: e.message,
870
+ stack: e.stack
871
+ });
872
+ }
873
+ }, {
874
+ key: "inflate",
875
+ value: function value(e, t) {
876
+ var r = new e(t);
877
+ return Object.assign(r, t), Object.setPrototypeOf(r, e.prototype), r;
878
+ }
879
+ }, {
880
+ key: "unmarshall",
881
+ value: function value(t) {
882
+ if ("name" in t) switch (t.name) {
883
+ case "SDKAPIUnreachableError":
884
+ return e.inflate(F, t);
885
+ case "StytchSDKSchemaError":
886
+ return e.inflate(K, t);
887
+ case "StytchSDKAPIError":
888
+ return e.inflate(q, t);
889
+ case "TypeError":
890
+ return e.inflate(TypeError, t);
891
+ case "SyntaxError":
892
+ return e.inflate(SyntaxError, t);
893
+ case "ReferenceError":
894
+ return e.inflate(ReferenceError, t);
895
+ case "RangeError":
896
+ return e.inflate(RangeError, t);
897
+ case "EvalError":
898
+ return e.inflate(EvalError, t);
899
+ case "URIError":
900
+ return e.inflate(URIError, t);
901
+ }
902
+ return e.inflate(Error, t);
903
+ }
904
+ }]), e;
905
+ }(),
906
+ ne = function () {
907
+ function e(t) {
908
+ c(this, e), this.maxBatchSize = t.maxBatchSize, this.logEventURL = t.logEventURL, setInterval(this.flush.bind(this), t.intervalDurationMs), this.batch = [];
909
+ }
910
+ return a(e, [{
911
+ key: "logEvent",
912
+ value: function value(e, t) {
913
+ this.batch.push({
914
+ telemetry: e,
915
+ event: t
916
+ }), this.batch.length >= this.maxBatchSize && this.flush();
917
+ }
918
+ }, {
919
+ key: "flush",
920
+ value: function value() {
921
+ return k(this, void 0, void 0, s().mark(function e() {
922
+ var t;
923
+ return s().wrap(function (e) {
924
+ for (;;) switch (e.prev = e.next) {
925
+ case 0:
926
+ if (this.batch.length) {
927
+ e.next = 2;
928
+ break;
929
+ }
930
+ return e.abrupt("return");
931
+ case 2:
932
+ return t = this.batch, this.batch = [], e.prev = 4, e.next = 7, fetch(this.logEventURL, {
933
+ method: "POST",
934
+ headers: {
935
+ "Content-Type": "application/json"
936
+ },
937
+ body: JSON.stringify(t)
938
+ });
939
+ case 7:
940
+ e.next = 11;
941
+ break;
942
+ case 9:
943
+ e.prev = 9, e.t0 = e["catch"](4);
944
+ case 11:
945
+ case "end":
946
+ return e.stop();
947
+ }
948
+ }, e, this, [[4, 9]]);
949
+ }));
950
+ }
951
+ }]), e;
952
+ }(),
953
+ ie = a(function e(t, r) {
954
+ var n = this;
955
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this.get = function () {
956
+ return k(n, void 0, void 0, s().mark(function e() {
957
+ var t, r;
958
+ return s().wrap(function (e) {
959
+ for (;;) switch (e.prev = e.next) {
960
+ case 0:
961
+ return e.next = 2, this._networkClient.fetchSDK({
962
+ url: "/users/me",
963
+ errorMessage: "Failed to retrieve user info.",
964
+ method: "GET"
965
+ });
966
+ case 2:
967
+ return t = e.sent, r = Q(t), this._subscriptionService.updateUser(r), e.abrupt("return", r);
968
+ case 6:
969
+ case "end":
970
+ return e.stop();
971
+ }
972
+ }, e, this);
973
+ }));
974
+ }, this.getSync = function () {
975
+ return n._subscriptionService.getUser();
976
+ }, this.update = function (e) {
977
+ return k(n, void 0, void 0, s().mark(function t() {
978
+ var r, n;
979
+ return s().wrap(function (t) {
980
+ for (;;) switch (t.prev = t.next) {
981
+ case 0:
982
+ return Z("stytch.user.update").isOptionalObject("untrusted_metadata", e.untrusted_metadata), t.next = 3, this._networkClient.fetchSDK({
983
+ url: "/users/me",
984
+ body: e,
985
+ errorMessage: "Failed to update user.",
986
+ method: "PUT"
987
+ });
988
+ case 3:
989
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
990
+ case 7:
991
+ case "end":
992
+ return t.stop();
993
+ }
994
+ }, t, this);
995
+ }));
996
+ }, this.deleteEmail = function (e) {
997
+ return k(n, void 0, void 0, s().mark(function t() {
998
+ var r, n;
999
+ return s().wrap(function (t) {
1000
+ for (;;) switch (t.prev = t.next) {
1001
+ case 0:
1002
+ return t.next = 2, this._networkClient.fetchSDK({
1003
+ url: "/users/emails/".concat(e),
1004
+ errorMessage: "Failed to delete email.",
1005
+ method: "DELETE"
1006
+ });
1007
+ case 2:
1008
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1009
+ case 6:
1010
+ case "end":
1011
+ return t.stop();
1012
+ }
1013
+ }, t, this);
1014
+ }));
1015
+ }, this.deletePhoneNumber = function (e) {
1016
+ return k(n, void 0, void 0, s().mark(function t() {
1017
+ var r, n;
1018
+ return s().wrap(function (t) {
1019
+ for (;;) switch (t.prev = t.next) {
1020
+ case 0:
1021
+ return t.next = 2, this._networkClient.fetchSDK({
1022
+ url: "/users/phone_numbers/".concat(e),
1023
+ errorMessage: "Failed to delete phone number.",
1024
+ method: "DELETE"
1025
+ });
1026
+ case 2:
1027
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1028
+ case 6:
1029
+ case "end":
1030
+ return t.stop();
1031
+ }
1032
+ }, t, this);
1033
+ }));
1034
+ }, this.deleteTOTP = function (e) {
1035
+ return k(n, void 0, void 0, s().mark(function t() {
1036
+ var r, n;
1037
+ return s().wrap(function (t) {
1038
+ for (;;) switch (t.prev = t.next) {
1039
+ case 0:
1040
+ return t.next = 2, this._networkClient.fetchSDK({
1041
+ url: "/users/totps/".concat(e),
1042
+ errorMessage: "Failed to delete TOTP.",
1043
+ method: "DELETE"
1044
+ });
1045
+ case 2:
1046
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1047
+ case 6:
1048
+ case "end":
1049
+ return t.stop();
1050
+ }
1051
+ }, t, this);
1052
+ }));
1053
+ }, this.deleteOAuthRegistration = function (e) {
1054
+ return k(n, void 0, void 0, s().mark(function t() {
1055
+ var r, n;
1056
+ return s().wrap(function (t) {
1057
+ for (;;) switch (t.prev = t.next) {
1058
+ case 0:
1059
+ return t.next = 2, this._networkClient.fetchSDK({
1060
+ url: "/users/oauth/".concat(e),
1061
+ errorMessage: "Failed to delete OAuth registration.",
1062
+ method: "DELETE"
1063
+ });
1064
+ case 2:
1065
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1066
+ case 6:
1067
+ case "end":
1068
+ return t.stop();
1069
+ }
1070
+ }, t, this);
1071
+ }));
1072
+ }, this.deleteWebauthnRegistration = function (e) {
1073
+ return k(n, void 0, void 0, s().mark(function t() {
1074
+ var r, n;
1075
+ return s().wrap(function (t) {
1076
+ for (;;) switch (t.prev = t.next) {
1077
+ case 0:
1078
+ return t.next = 2, this._networkClient.fetchSDK({
1079
+ url: "/users/webauthn_registrations/".concat(e),
1080
+ errorMessage: "Failed to delete WebAuthn registration.",
1081
+ method: "DELETE"
1082
+ });
1083
+ case 2:
1084
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1085
+ case 6:
1086
+ case "end":
1087
+ return t.stop();
1088
+ }
1089
+ }, t, this);
1090
+ }));
1091
+ }, this.deleteBiometricRegistration = function (e) {
1092
+ return k(n, void 0, void 0, s().mark(function t() {
1093
+ var r, n;
1094
+ return s().wrap(function (t) {
1095
+ for (;;) switch (t.prev = t.next) {
1096
+ case 0:
1097
+ return t.next = 2, this._networkClient.fetchSDK({
1098
+ url: "/users/biometric_registrations/".concat(e),
1099
+ errorMessage: "Failed to delete Biometric registration.",
1100
+ method: "DELETE"
1101
+ });
1102
+ case 2:
1103
+ return r = t.sent, n = Q(r.__user), this._subscriptionService.updateUser(n), t.abrupt("return", ee(r));
1104
+ case 6:
1105
+ case "end":
1106
+ return t.stop();
1107
+ }
1108
+ }, t, this);
1109
+ }));
1110
+ }, this.onChange = function (e) {
1111
+ var t = n._subscriptionService.getUser();
1112
+ return n._subscriptionService.subscribeToState(function (r) {
1113
+ var n;
1114
+ (null == r ? void 0 : r.user) !== t && (t = null !== (n = null == r ? void 0 : r.user) && void 0 !== n ? n : null, e(t));
1115
+ });
1116
+ };
1117
+ }),
1118
+ se = function () {
1119
+ function e(t, r) {
1120
+ var n = this;
1121
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this.getSync = function () {
1122
+ return n._subscriptionService.getSession();
1123
+ }, this.onChange = function (e) {
1124
+ var t = n._subscriptionService.getSession();
1125
+ return n._subscriptionService.subscribeToState(function (r) {
1126
+ var n;
1127
+ (null == r ? void 0 : r.session) !== t && (t = null !== (n = null == r ? void 0 : r.session) && void 0 !== n ? n : null, e(t));
1128
+ });
1129
+ }, this.revoke = function (e) {
1130
+ return k(n, void 0, void 0, s().mark(function t() {
1131
+ var r;
1132
+ return s().wrap(function (t) {
1133
+ for (;;) switch (t.prev = t.next) {
1134
+ case 0:
1135
+ return t.prev = 0, t.next = 3, this._networkClient.fetchSDK({
1136
+ url: "/sessions/revoke",
1137
+ errorMessage: "Error revoking session",
1138
+ method: "POST"
1139
+ });
1140
+ case 3:
1141
+ return r = t.sent, this._subscriptionService.destroyState(), t.abrupt("return", r);
1142
+ case 8:
1143
+ throw t.prev = 8, t.t0 = t["catch"](0), ((null == e ? void 0 : e.forceClear) || W.includes(t.t0.error_type)) && this._subscriptionService.destroyState(), t.t0;
1144
+ case 12:
1145
+ case "end":
1146
+ return t.stop();
1147
+ }
1148
+ }, t, this, [[0, 8]]);
1149
+ }));
1150
+ }, this.authenticate = function (e) {
1151
+ return k(n, void 0, void 0, s().mark(function t() {
1152
+ var r, n;
1153
+ return s().wrap(function (t) {
1154
+ for (;;) switch (t.prev = t.next) {
1155
+ case 0:
1156
+ return t.prev = 0, r = {
1157
+ session_duration_minutes: null == e ? void 0 : e.session_duration_minutes
1158
+ }, t.next = 4, this._networkClient.fetchSDK({
1159
+ url: "/sessions/authenticate",
1160
+ body: r,
1161
+ errorMessage: "Error authenticating session",
1162
+ method: "POST"
1163
+ });
1164
+ case 4:
1165
+ return n = t.sent, this._subscriptionService.updateStateAndTokens({
1166
+ state: {
1167
+ session: n.session,
1168
+ user: n.user
1169
+ },
1170
+ session_token: n.session_token,
1171
+ session_jwt: n.session_jwt,
1172
+ intermediate_session_token: null
1173
+ }), t.abrupt("return", ee(n));
1174
+ case 9:
1175
+ throw t.prev = 9, t.t0 = t["catch"](0), W.includes(t.t0.error_type) && this._subscriptionService.destroyState(), t.t0;
1176
+ case 13:
1177
+ case "end":
1178
+ return t.stop();
1179
+ }
1180
+ }, t, this, [[0, 9]]);
1181
+ }));
1182
+ };
1183
+ }
1184
+ return a(e, [{
1185
+ key: "getTokens",
1186
+ value: function value() {
1187
+ return this._subscriptionService.getTokens();
1188
+ }
1189
+ }, {
1190
+ key: "updateSession",
1191
+ value: function value(e) {
1192
+ this._subscriptionService.updateTokens(e);
1193
+ }
1194
+ }]), e;
1195
+ }(),
1196
+ oe = Promise.resolve({
1197
+ pkceRequiredForEmailMagicLinks: !1
1198
+ }),
1199
+ ae = function () {
1200
+ function e(t, r, n) {
1201
+ var i = this,
1202
+ o = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : oe,
1203
+ a = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : function () {
1204
+ return Promise.resolve(void 0);
1205
+ },
1206
+ u = arguments.length > 5 ? arguments[5] : void 0;
1207
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this._pkceManager = n, this._config = o, this.executeRecaptcha = a, this._dfpProtectedAuth = u, this.retryWithCaptchaAndDFP = function (e, t) {
1208
+ return k(i, void 0, void 0, s().mark(function r() {
1209
+ var n, i;
1210
+ return s().wrap(function (r) {
1211
+ for (;;) switch (r.prev = r.next) {
1212
+ case 0:
1213
+ if (n = this._dfpProtectedAuth, r.t0 = n, !r.t0) {
1214
+ r.next = 6;
1215
+ break;
1216
+ }
1217
+ return r.next = 5, n.isEnabled();
1218
+ case 5:
1219
+ r.t0 = r.sent;
1220
+ case 6:
1221
+ if (i = r.t0, e.type !== Be.RequiredCatcha || !i) {
1222
+ r.next = 16;
1223
+ break;
1224
+ }
1225
+ if (!t.body) {
1226
+ r.next = 15;
1227
+ break;
1228
+ }
1229
+ return r.next = 11, n.getTelemetryID();
1230
+ case 11:
1231
+ return t.body.dfp_telemetry_id = r.sent, r.next = 14, this.executeRecaptcha();
1232
+ case 14:
1233
+ t.body.captcha_token = r.sent;
1234
+ case 15:
1235
+ return r.abrupt("return", t);
1236
+ case 16:
1237
+ throw new Error("Unable to query captcha and/or dfp telemetry ID");
1238
+ case 17:
1239
+ case "end":
1240
+ return r.stop();
1241
+ }
1242
+ }, r, this);
1243
+ }));
1244
+ }, this.email = {
1245
+ loginOrCreate: function loginOrCreate(e) {
1246
+ var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
1247
+ return k(i, void 0, void 0, s().mark(function r() {
1248
+ var n, i, o, a, c, u, l;
1249
+ return s().wrap(function (r) {
1250
+ for (;;) switch (r.prev = r.next) {
1251
+ case 0:
1252
+ return r.next = 2, this._config;
1253
+ case 2:
1254
+ if (n = r.sent, i = n.pkceRequiredForEmailMagicLinks, o = void 0, !i) {
1255
+ r.next = 9;
1256
+ break;
1257
+ }
1258
+ return r.next = 8, this.getCodeChallenge();
1259
+ case 8:
1260
+ o = r.sent;
1261
+ case 9:
1262
+ return r.next = 11, this.getDFPTelemetryIDAndCaptcha();
1263
+ case 11:
1264
+ return a = r.sent, c = a.dfp_telemetry_id, u = a.captcha_token, l = Object.assign(Object.assign({}, t), {
1265
+ email: e,
1266
+ code_challenge: o,
1267
+ captcha_token: u,
1268
+ dfp_telemetry_id: c
1269
+ }), r.abrupt("return", this._networkClient.retriableFetchSDK({
1270
+ url: "/magic_links/email/login_or_create",
1271
+ body: l,
1272
+ errorMessage: "Failed to send magic link",
1273
+ method: "POST",
1274
+ retryCallback: this.retryWithCaptchaAndDFP
1275
+ }));
1276
+ case 16:
1277
+ case "end":
1278
+ return r.stop();
1279
+ }
1280
+ }, r, this);
1281
+ }));
1282
+ },
1283
+ send: function send(e) {
1284
+ var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
1285
+ return k(i, void 0, void 0, s().mark(function r() {
1286
+ var n, i, o, a, c, u, l, d, h;
1287
+ return s().wrap(function (r) {
1288
+ for (;;) switch (r.prev = r.next) {
1289
+ case 0:
1290
+ return r.next = 2, this._config;
1291
+ case 2:
1292
+ if (n = r.sent, i = n.pkceRequiredForEmailMagicLinks, o = void 0, !i) {
1293
+ r.next = 9;
1294
+ break;
1295
+ }
1296
+ return r.next = 8, this.getCodeChallenge();
1297
+ case 8:
1298
+ o = r.sent;
1299
+ case 9:
1300
+ return r.next = 11, this.getDFPTelemetryIDAndCaptcha();
1301
+ case 11:
1302
+ return a = r.sent, c = a.dfp_telemetry_id, u = a.captcha_token, l = Object.assign(Object.assign({}, t), {
1303
+ email: e,
1304
+ code_challenge: o,
1305
+ captcha_token: u,
1306
+ dfp_telemetry_id: c
1307
+ }), d = !!this._subscriptionService.getSession(), h = d ? "/magic_links/email/send/secondary" : "/magic_links/email/send/primary", r.abrupt("return", this._networkClient.retriableFetchSDK({
1308
+ url: h,
1309
+ body: l,
1310
+ errorMessage: "Failed to send magic link",
1311
+ method: "POST",
1312
+ retryCallback: this.retryWithCaptchaAndDFP
1313
+ }));
1314
+ case 18:
1315
+ case "end":
1316
+ return r.stop();
1317
+ }
1318
+ }, r, this);
1319
+ }));
1320
+ }
1321
+ }, this.authenticate = function (e, t) {
1322
+ return k(i, void 0, void 0, s().mark(function r() {
1323
+ var n, i, o;
1324
+ return s().wrap(function (r) {
1325
+ for (;;) switch (r.prev = r.next) {
1326
+ case 0:
1327
+ return Z("stytch.magicLinks.authenticate").isString("Token", e).isNumber("session_duration_minutes", t.session_duration_minutes), r.next = 3, this._pkceManager.getPKPair();
1328
+ case 3:
1329
+ return n = r.sent, i = Object.assign({
1330
+ token: e,
1331
+ code_verifier: null == n ? void 0 : n.code_verifier
1332
+ }, t), r.next = 7, this._networkClient.fetchSDK({
1333
+ url: "/magic_links/authenticate",
1334
+ body: i,
1335
+ errorMessage: "Failed to authenticate token.",
1336
+ method: "POST"
1337
+ });
1338
+ case 7:
1339
+ return o = r.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({
1340
+ state: {
1341
+ session: o.session,
1342
+ user: o.user
1343
+ },
1344
+ session_token: o.session_token,
1345
+ session_jwt: o.session_jwt,
1346
+ intermediate_session_token: null
1347
+ }), r.abrupt("return", ee(o));
1348
+ case 11:
1349
+ case "end":
1350
+ return r.stop();
1351
+ }
1352
+ }, r, this);
1353
+ }));
1354
+ };
1355
+ }
1356
+ return a(e, [{
1357
+ key: "getCodeChallenge",
1358
+ value: function value() {
1359
+ return k(this, void 0, void 0, s().mark(function e() {
1360
+ var t;
1361
+ return s().wrap(function (e) {
1362
+ for (;;) switch (e.prev = e.next) {
1363
+ case 0:
1364
+ return e.next = 2, this._pkceManager.getPKPair();
1365
+ case 2:
1366
+ if (!(t = e.sent)) {
1367
+ e.next = 5;
1368
+ break;
1369
+ }
1370
+ return e.abrupt("return", t.code_challenge);
1371
+ case 5:
1372
+ return e.next = 7, this._pkceManager.startPKCETransaction();
1373
+ case 7:
1374
+ return t = e.sent, e.abrupt("return", t.code_challenge);
1375
+ case 9:
1376
+ case "end":
1377
+ return e.stop();
1378
+ }
1379
+ }, e, this);
1380
+ }));
1381
+ }
1382
+ }, {
1383
+ key: "getDFPTelemetryIDAndCaptcha",
1384
+ value: function value() {
1385
+ return k(this, void 0, void 0, s().mark(function e() {
1386
+ var t, r;
1387
+ return s().wrap(function (e) {
1388
+ for (;;) switch (e.prev = e.next) {
1389
+ case 0:
1390
+ if (t = void 0, r = void 0, e.t0 = this._dfpProtectedAuth, !e.t0) {
1391
+ e.next = 7;
1392
+ break;
1393
+ }
1394
+ return e.next = 6, this._dfpProtectedAuth.isEnabled();
1395
+ case 6:
1396
+ e.t0 = e.sent;
1397
+ case 7:
1398
+ if (!e.t0) {
1399
+ e.next = 13;
1400
+ break;
1401
+ }
1402
+ return e.next = 10, this._dfpProtectedAuth.getTelemetryID();
1403
+ case 10:
1404
+ t = e.sent, e.next = 16;
1405
+ break;
1406
+ case 13:
1407
+ return e.next = 15, this.executeRecaptcha();
1408
+ case 15:
1409
+ r = e.sent;
1410
+ case 16:
1411
+ return e.abrupt("return", {
1412
+ dfp_telemetry_id: t,
1413
+ captcha_token: r
1414
+ });
1415
+ case 17:
1416
+ case "end":
1417
+ return e.stop();
1418
+ }
1419
+ }, e, this);
1420
+ }));
1421
+ }
1422
+ }]), e;
1423
+ }(),
1424
+ ce = a(function e(t, r) {
1425
+ var n = this,
1426
+ i = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : function () {
1427
+ return Promise.resolve(void 0);
1428
+ };
1429
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this.executeRecaptcha = i, this.sms = {
1430
+ loginOrCreate: function loginOrCreate(e, t) {
1431
+ return k(n, void 0, void 0, s().mark(function r() {
1432
+ var n, i;
1433
+ return s().wrap(function (r) {
1434
+ for (;;) switch (r.prev = r.next) {
1435
+ case 0:
1436
+ return r.next = 2, this.executeRecaptcha();
1437
+ case 2:
1438
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1439
+ phone_number: e,
1440
+ captcha_token: n
1441
+ }), r.abrupt("return", this._networkClient.fetchSDK({
1442
+ url: "/otps/sms/login_or_create",
1443
+ body: i,
1444
+ errorMessage: "Failed to send one time passcode",
1445
+ method: "POST"
1446
+ }));
1447
+ case 5:
1448
+ case "end":
1449
+ return r.stop();
1450
+ }
1451
+ }, r, this);
1452
+ }));
1453
+ },
1454
+ send: function send(e, t) {
1455
+ return k(n, void 0, void 0, s().mark(function r() {
1456
+ var n, i, o, a;
1457
+ return s().wrap(function (r) {
1458
+ for (;;) switch (r.prev = r.next) {
1459
+ case 0:
1460
+ return r.next = 2, this.executeRecaptcha();
1461
+ case 2:
1462
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1463
+ phone_number: e,
1464
+ captcha_token: n
1465
+ }), o = !!this._subscriptionService.getSession(), a = o ? "/otps/sms/send/secondary" : "/otps/sms/send/primary", r.abrupt("return", this._networkClient.fetchSDK({
1466
+ url: a,
1467
+ body: i,
1468
+ errorMessage: "Failed to send one time passcode",
1469
+ method: "POST"
1470
+ }));
1471
+ case 7:
1472
+ case "end":
1473
+ return r.stop();
1474
+ }
1475
+ }, r, this);
1476
+ }));
1477
+ }
1478
+ }, this.whatsapp = {
1479
+ loginOrCreate: function loginOrCreate(e, t) {
1480
+ return k(n, void 0, void 0, s().mark(function r() {
1481
+ var n, i;
1482
+ return s().wrap(function (r) {
1483
+ for (;;) switch (r.prev = r.next) {
1484
+ case 0:
1485
+ return r.next = 2, this.executeRecaptcha();
1486
+ case 2:
1487
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1488
+ phone_number: e,
1489
+ captcha_token: n
1490
+ }), r.abrupt("return", this._networkClient.fetchSDK({
1491
+ url: "/otps/whatsapp/login_or_create",
1492
+ body: i,
1493
+ errorMessage: "Failed to send one time passcode",
1494
+ method: "POST"
1495
+ }));
1496
+ case 5:
1497
+ case "end":
1498
+ return r.stop();
1499
+ }
1500
+ }, r, this);
1501
+ }));
1502
+ },
1503
+ send: function send(e, t) {
1504
+ return k(n, void 0, void 0, s().mark(function r() {
1505
+ var n, i, o, a;
1506
+ return s().wrap(function (r) {
1507
+ for (;;) switch (r.prev = r.next) {
1508
+ case 0:
1509
+ return r.next = 2, this.executeRecaptcha();
1510
+ case 2:
1511
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1512
+ phone_number: e,
1513
+ captcha_token: n
1514
+ }), o = !!this._subscriptionService.getSession(), a = o ? "/otps/whatsapp/send/secondary" : "/otps/whatsapp/send/primary", r.abrupt("return", this._networkClient.fetchSDK({
1515
+ url: a,
1516
+ body: i,
1517
+ errorMessage: "Failed to send one time passcode",
1518
+ method: "POST"
1519
+ }));
1520
+ case 7:
1521
+ case "end":
1522
+ return r.stop();
1523
+ }
1524
+ }, r, this);
1525
+ }));
1526
+ }
1527
+ }, this.email = {
1528
+ loginOrCreate: function loginOrCreate(e, t) {
1529
+ return k(n, void 0, void 0, s().mark(function r() {
1530
+ var n, i;
1531
+ return s().wrap(function (r) {
1532
+ for (;;) switch (r.prev = r.next) {
1533
+ case 0:
1534
+ return r.next = 2, this.executeRecaptcha();
1535
+ case 2:
1536
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1537
+ email: e,
1538
+ captcha_token: n
1539
+ }), r.abrupt("return", this._networkClient.fetchSDK({
1540
+ url: "/otps/email/login_or_create",
1541
+ body: i,
1542
+ errorMessage: "Failed to send one time passcode",
1543
+ method: "POST"
1544
+ }));
1545
+ case 5:
1546
+ case "end":
1547
+ return r.stop();
1548
+ }
1549
+ }, r, this);
1550
+ }));
1551
+ },
1552
+ send: function send(e, t) {
1553
+ return k(n, void 0, void 0, s().mark(function r() {
1554
+ var n, i, o, a;
1555
+ return s().wrap(function (r) {
1556
+ for (;;) switch (r.prev = r.next) {
1557
+ case 0:
1558
+ return r.next = 2, this.executeRecaptcha();
1559
+ case 2:
1560
+ return n = r.sent, i = Object.assign(Object.assign({}, t), {
1561
+ email: e,
1562
+ captcha_token: n
1563
+ }), o = !!this._subscriptionService.getSession(), a = o ? "/otps/email/send/secondary" : "/otps/email/send/primary", r.abrupt("return", this._networkClient.fetchSDK({
1564
+ url: a,
1565
+ body: i,
1566
+ errorMessage: "Failed to send one time passcode",
1567
+ method: "POST"
1568
+ }));
1569
+ case 7:
1570
+ case "end":
1571
+ return r.stop();
1572
+ }
1573
+ }, r, this);
1574
+ }));
1575
+ }
1576
+ }, this.authenticate = function (e, t, r) {
1577
+ return k(n, void 0, void 0, s().mark(function n() {
1578
+ var i, o;
1579
+ return s().wrap(function (n) {
1580
+ for (;;) switch (n.prev = n.next) {
1581
+ case 0:
1582
+ return Z("stytch.otps.authenticate").isString("Code", e).isNumber("session_duration_minutes", r.session_duration_minutes), i = Object.assign({
1583
+ token: e,
1584
+ method_id: t
1585
+ }, r), n.next = 4, this._networkClient.fetchSDK({
1586
+ url: "/otps/authenticate",
1587
+ body: i,
1588
+ errorMessage: "Failed to authenticate token.",
1589
+ method: "POST"
1590
+ });
1591
+ case 4:
1592
+ return o = n.sent, this._subscriptionService.updateStateAndTokens({
1593
+ state: {
1594
+ session: o.session,
1595
+ user: o.user
1596
+ },
1597
+ session_token: o.session_token,
1598
+ session_jwt: o.session_jwt,
1599
+ intermediate_session_token: null
1600
+ }), n.abrupt("return", ee(o));
1601
+ case 7:
1602
+ case "end":
1603
+ return n.stop();
1604
+ }
1605
+ }, n, this);
1606
+ }));
1607
+ };
1608
+ }),
1609
+ ue = function () {
1610
+ function e(t, r, n, i, s) {
1611
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this._pkceManager = n, this._dynamicConfig = i, this._config = s, this.google = {
1612
+ start: this.startOAuthFlow(C.Google)
1613
+ }, this.apple = {
1614
+ start: this.startOAuthFlow(C.Apple)
1615
+ }, this.microsoft = {
1616
+ start: this.startOAuthFlow(C.Microsoft)
1617
+ }, this.github = {
1618
+ start: this.startOAuthFlow(C.Github)
1619
+ }, this.gitlab = {
1620
+ start: this.startOAuthFlow(C.GitLab)
1621
+ }, this.facebook = {
1622
+ start: this.startOAuthFlow(C.Facebook)
1623
+ }, this.discord = {
1624
+ start: this.startOAuthFlow(C.Discord)
1625
+ }, this.salesforce = {
1626
+ start: this.startOAuthFlow(C.Salesforce)
1627
+ }, this.slack = {
1628
+ start: this.startOAuthFlow(C.Slack)
1629
+ }, this.amazon = {
1630
+ start: this.startOAuthFlow(C.Amazon)
1631
+ }, this.bitbucket = {
1632
+ start: this.startOAuthFlow(C.Bitbucket)
1633
+ }, this.linkedin = {
1634
+ start: this.startOAuthFlow(C.LinkedIn)
1635
+ }, this.coinbase = {
1636
+ start: this.startOAuthFlow(C.Coinbase)
1637
+ }, this.twitch = {
1638
+ start: this.startOAuthFlow(C.Twitch)
1639
+ }, this.twitter = {
1640
+ start: this.startOAuthFlow(C.Twitter)
1641
+ }, this.tiktok = {
1642
+ start: this.startOAuthFlow(C.TikTok)
1643
+ }, this.snapchat = {
1644
+ start: this.startOAuthFlow(C.Snapchat)
1645
+ }, this.figma = {
1646
+ start: this.startOAuthFlow(C.Figma)
1647
+ }, this.yahoo = {
1648
+ start: this.startOAuthFlow(C.Yahoo)
1649
+ };
1650
+ }
1651
+ return a(e, [{
1652
+ key: "authenticate",
1653
+ value: function value(e, t) {
1654
+ return k(this, void 0, void 0, s().mark(function r() {
1655
+ var n, i;
1656
+ return s().wrap(function (r) {
1657
+ for (;;) switch (r.prev = r.next) {
1658
+ case 0:
1659
+ return Z("stytch.oauth.authenticate").isString("Token", e).isNumber("session_duration_minutes", t.session_duration_minutes), r.next = 3, this._pkceManager.getPKPair();
1660
+ case 3:
1661
+ return (n = r.sent) || J("No code verifier found in local storage for OAuth flow.\nConsider using stytch.oauth.$provider.start() to add PKCE to your OAuth flows for added security.\nSee https://stytch.com/docs/oauth#guides_pkce for more information."), r.next = 7, this._networkClient.fetchSDK({
1662
+ url: "/oauth/authenticate",
1663
+ method: "POST",
1664
+ body: Object.assign({
1665
+ token: e,
1666
+ code_verifier: null == n ? void 0 : n.code_verifier
1667
+ }, t),
1668
+ errorMessage: "Failed to authenticate token"
1669
+ });
1670
+ case 7:
1671
+ return i = r.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({
1672
+ state: {
1673
+ session: i.session,
1674
+ user: Q(i.__user)
1675
+ },
1676
+ session_token: i.session_token,
1677
+ session_jwt: i.session_jwt,
1678
+ intermediate_session_token: null
1679
+ }), r.abrupt("return", ee(i));
1680
+ case 11:
1681
+ case "end":
1682
+ return r.stop();
1683
+ }
1684
+ }, r, this);
1685
+ }));
1686
+ }
1687
+ }, {
1688
+ key: "getBaseApiUrl",
1689
+ value: function value() {
1690
+ return k(this, void 0, void 0, s().mark(function e() {
1691
+ var t, r;
1692
+ return s().wrap(function (e) {
1693
+ for (;;) switch (e.prev = e.next) {
1694
+ case 0:
1695
+ return e.next = 2, this._dynamicConfig;
1696
+ case 2:
1697
+ if (t = e.sent, !(r = t.cnameDomain)) {
1698
+ e.next = 6;
1699
+ break;
1700
+ }
1701
+ return e.abrupt("return", "https://".concat(r));
1702
+ case 6:
1703
+ if (!this._config.publicToken.includes("public-token-test")) {
1704
+ e.next = 8;
1705
+ break;
1706
+ }
1707
+ return e.abrupt("return", this._config.testAPIURL);
1708
+ case 8:
1709
+ return e.abrupt("return", this._config.liveAPIURL);
1710
+ case 9:
1711
+ case "end":
1712
+ return e.stop();
1713
+ }
1714
+ }, e, this);
1715
+ }));
1716
+ }
1717
+ }, {
1718
+ key: "startOAuthFlow",
1719
+ value: function value(e) {
1720
+ var t = this;
1721
+ return function () {
1722
+ var r = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {},
1723
+ n = r.login_redirect_url,
1724
+ i = r.signup_redirect_url,
1725
+ o = r.custom_scopes;
1726
+ return k(t, void 0, void 0, s().mark(function t() {
1727
+ var r, a, c, u, l, d;
1728
+ return s().wrap(function (t) {
1729
+ for (;;) switch (t.prev = t.next) {
1730
+ case 0:
1731
+ return t.next = 2, this._dynamicConfig;
1732
+ case 2:
1733
+ return r = t.sent, a = r.cnameDomain, c = r.pkceRequiredForOAuth, t.next = 7, this.getBaseApiUrl();
1734
+ case 7:
1735
+ if (u = t.sent, this._networkClient.logEvent({
1736
+ name: "start_oauth_flow",
1737
+ details: {
1738
+ provider_type: e,
1739
+ custom_scopes: o,
1740
+ cname_domain: a,
1741
+ pkce: c
1742
+ }
1743
+ }), (l = new URL("".concat(u, "/v1/public/oauth/").concat(e, "/start"))).searchParams.set("public_token", this._config.publicToken), !c) {
1744
+ t.next = 18;
1745
+ break;
1746
+ }
1747
+ return t.next = 14, this._pkceManager.startPKCETransaction();
1748
+ case 14:
1749
+ d = t.sent, l.searchParams.set("code_challenge", d.code_challenge), t.next = 19;
1750
+ break;
1751
+ case 18:
1752
+ this._pkceManager.clearPKPair();
1753
+ case 19:
1754
+ o && (Z("startOAuthFlow").isStringArray("custom_scopes", o), l.searchParams.set("custom_scopes", o.join(" "))), n && l.searchParams.set("login_redirect_url", n), i && l.searchParams.set("signup_redirect_url", i), window.location.href = l.toString();
1755
+ case 23:
1756
+ case "end":
1757
+ return t.stop();
1758
+ }
1759
+ }, t, this);
1760
+ }));
1761
+ };
1762
+ }
1763
+ }]), e;
1764
+ }(),
1765
+ le = function () {
1766
+ function e(t, r) {
1767
+ var n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : function () {
1768
+ return Promise.resolve(void 0);
1769
+ };
1770
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this.executeRecaptcha = n;
1771
+ }
1772
+ return a(e, [{
1773
+ key: "authenticateStart",
1774
+ value: function value(e) {
1775
+ return k(this, void 0, void 0, s().mark(function t() {
1776
+ var r, n, i;
1777
+ return s().wrap(function (t) {
1778
+ for (;;) switch (t.prev = t.next) {
1779
+ case 0:
1780
+ return Z("stytch.cryptoWallets.authenticateStart").isString("crypto_wallet_address", e.crypto_wallet_address).isString("crypto_wallet_type", e.crypto_wallet_type), r = !!this._subscriptionService.getSession(), t.next = 4, this.executeRecaptcha();
1781
+ case 4:
1782
+ return n = t.sent, i = r ? "/crypto_wallets/authenticate/start/secondary" : "/crypto_wallets/authenticate/start/primary", t.abrupt("return", this._networkClient.fetchSDK({
1783
+ url: i,
1784
+ method: "POST",
1785
+ errorMessage: "Failed to start wallet authentication.",
1786
+ body: {
1787
+ crypto_wallet_address: e.crypto_wallet_address,
1788
+ crypto_wallet_type: e.crypto_wallet_type,
1789
+ captcha_token: n
1790
+ }
1791
+ }));
1792
+ case 7:
1793
+ case "end":
1794
+ return t.stop();
1795
+ }
1796
+ }, t, this);
1797
+ }));
1798
+ }
1799
+ }, {
1800
+ key: "authenticate",
1801
+ value: function value(e) {
1802
+ return k(this, void 0, void 0, s().mark(function t() {
1803
+ var r;
1804
+ return s().wrap(function (t) {
1805
+ for (;;) switch (t.prev = t.next) {
1806
+ case 0:
1807
+ return Z("stytch.cryptoWallets.authenticate").isString("signature", e.signature).isString("crypto_wallet_address", e.crypto_wallet_address).isString("crypto_wallet_type", e.crypto_wallet_type).isNumber("session_duration_minutes", e.session_duration_minutes), t.next = 3, this._networkClient.fetchSDK({
1808
+ url: "/crypto_wallets/authenticate",
1809
+ method: "POST",
1810
+ errorMessage: "Failed to authenticate.",
1811
+ body: {
1812
+ session_duration_minutes: e.session_duration_minutes,
1813
+ crypto_wallet_address: e.crypto_wallet_address,
1814
+ crypto_wallet_type: e.crypto_wallet_type,
1815
+ signature: e.signature
1816
+ }
1817
+ });
1818
+ case 3:
1819
+ return r = t.sent, this._subscriptionService.updateStateAndTokens({
1820
+ state: {
1821
+ session: r.session,
1822
+ user: Q(r.__user)
1823
+ },
1824
+ session_token: r.session_token,
1825
+ session_jwt: r.session_jwt,
1826
+ intermediate_session_token: null
1827
+ }), t.abrupt("return", ee(r));
1828
+ case 6:
1829
+ case "end":
1830
+ return t.stop();
1831
+ }
1832
+ }, t, this);
1833
+ }));
1834
+ }
1835
+ }]), e;
1836
+ }(),
1837
+ de = function () {
1838
+ function e(t, r) {
1839
+ c(this, e), this._networkClient = t, this._subscriptionService = r;
1840
+ }
1841
+ return a(e, [{
1842
+ key: "create",
1843
+ value: function value(e) {
1844
+ return k(this, void 0, void 0, s().mark(function t() {
1845
+ var r;
1846
+ return s().wrap(function (t) {
1847
+ for (;;) switch (t.prev = t.next) {
1848
+ case 0:
1849
+ return Z("stytch.totps.create").isNumber("expiration_minutes", e.expiration_minutes), t.next = 3, this._networkClient.fetchSDK({
1850
+ url: "/totps",
1851
+ method: "POST",
1852
+ errorMessage: "Failed to create TOTP",
1853
+ body: {
1854
+ expiration_minutes: e.expiration_minutes
1855
+ }
1856
+ });
1857
+ case 3:
1858
+ return r = t.sent, this._subscriptionService.updateUser(r.__user), t.abrupt("return", ee(r));
1859
+ case 6:
1860
+ case "end":
1861
+ return t.stop();
1862
+ }
1863
+ }, t, this);
1864
+ }));
1865
+ }
1866
+ }, {
1867
+ key: "authenticate",
1868
+ value: function value(e) {
1869
+ return k(this, void 0, void 0, s().mark(function t() {
1870
+ var r;
1871
+ return s().wrap(function (t) {
1872
+ for (;;) switch (t.prev = t.next) {
1873
+ case 0:
1874
+ return Z("stytch.totps.authenticate").isNumber("session_duration_minutes", e.session_duration_minutes).isString("totp_code", e.totp_code), t.next = 3, this._networkClient.fetchSDK({
1875
+ url: "/totps/authenticate",
1876
+ method: "POST",
1877
+ errorMessage: "Failed to authenticate TOTP",
1878
+ body: {
1879
+ session_duration_minutes: e.session_duration_minutes,
1880
+ totp_code: e.totp_code
1881
+ }
1882
+ });
1883
+ case 3:
1884
+ return r = t.sent, this._subscriptionService.updateStateAndTokens({
1885
+ state: {
1886
+ session: r.session,
1887
+ user: r.__user
1888
+ },
1889
+ session_token: r.session_token,
1890
+ session_jwt: r.session_jwt,
1891
+ intermediate_session_token: null
1892
+ }), t.abrupt("return", ee(r));
1893
+ case 6:
1894
+ case "end":
1895
+ return t.stop();
1896
+ }
1897
+ }, t, this);
1898
+ }));
1899
+ }
1900
+ }, {
1901
+ key: "recoveryCodes",
1902
+ value: function value() {
1903
+ return k(this, void 0, void 0, s().mark(function e() {
1904
+ return s().wrap(function (e) {
1905
+ for (;;) switch (e.prev = e.next) {
1906
+ case 0:
1907
+ return e.abrupt("return", this._networkClient.fetchSDK({
1908
+ url: "/totps/recovery_codes",
1909
+ method: "POST",
1910
+ errorMessage: "Failed to retrieve recovery codes"
1911
+ }));
1912
+ case 1:
1913
+ case "end":
1914
+ return e.stop();
1915
+ }
1916
+ }, e, this);
1917
+ }));
1918
+ }
1919
+ }, {
1920
+ key: "recover",
1921
+ value: function value(e) {
1922
+ return k(this, void 0, void 0, s().mark(function t() {
1923
+ var r;
1924
+ return s().wrap(function (t) {
1925
+ for (;;) switch (t.prev = t.next) {
1926
+ case 0:
1927
+ return Z("stytch.totps.recover").isNumber("session_duration_minutes", e.session_duration_minutes).isString("recovery_code", e.recovery_code), t.next = 3, this._networkClient.fetchSDK({
1928
+ url: "/totps/recover",
1929
+ method: "POST",
1930
+ errorMessage: "Failed to recover TOTP",
1931
+ body: {
1932
+ session_duration_minutes: e.session_duration_minutes,
1933
+ recovery_code: e.recovery_code
1934
+ }
1935
+ });
1936
+ case 3:
1937
+ return r = t.sent, this._subscriptionService.updateStateAndTokens({
1938
+ state: {
1939
+ session: r.session,
1940
+ user: r.__user
1941
+ },
1942
+ session_token: r.session_token,
1943
+ session_jwt: r.session_jwt,
1944
+ intermediate_session_token: null
1945
+ }), t.abrupt("return", ee(r));
1946
+ case 6:
1947
+ case "end":
1948
+ return t.stop();
1949
+ }
1950
+ }, t, this);
1951
+ }));
1952
+ }
1953
+ }]), e;
1954
+ }();
1955
+ function he(e) {
1956
+ for (var t = "==".slice(0, (4 - e.length % 4) % 4), r = e.replace(/-/g, "+").replace(/_/g, "/") + t, n = atob(r), i = new ArrayBuffer(n.length), s = new Uint8Array(i), o = 0; o < n.length; o++) s[o] = n.charCodeAt(o);
1957
+ return i;
1958
+ }
1959
+ function pe(t) {
1960
+ var r,
1961
+ n = "",
1962
+ i = e(new Uint8Array(t));
1963
+ try {
1964
+ for (i.s(); !(r = i.n()).done;) {
1965
+ var s = r.value;
1966
+ n += String.fromCharCode(s);
1967
+ }
1968
+ } catch (e) {
1969
+ i.e(e);
1970
+ } finally {
1971
+ i.f();
1972
+ }
1973
+ return btoa(n).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
1974
+ }
1975
+ var fe = "copy",
1976
+ _e = "convert";
1977
+ function ve(e, r, n) {
1978
+ if (r === fe) return n;
1979
+ if (r === _e) return e(n);
1980
+ if (r instanceof Array) return n.map(function (t) {
1981
+ return ve(e, r[0], t);
1982
+ });
1983
+ if (r instanceof Object) {
1984
+ for (var i = {}, s = 0, o = Object.entries(r); s < o.length; s++) {
1985
+ var a = t(o[s], 2),
1986
+ c = a[0],
1987
+ u = a[1];
1988
+ if (u.derive) {
1989
+ var l = u.derive(n);
1990
+ void 0 !== l && (n[c] = l);
1991
+ }
1992
+ if (c in n) null != n[c] ? i[c] = ve(e, u.schema, n[c]) : i[c] = null;else if (u.required) throw new Error("Missing key: ".concat(c));
1993
+ }
1994
+ return i;
1995
+ }
1996
+ }
1997
+ function me(e, t) {
1998
+ return {
1999
+ required: !0,
2000
+ schema: e,
2001
+ derive: t
2002
+ };
2003
+ }
2004
+ function ye(e) {
2005
+ return {
2006
+ required: !0,
2007
+ schema: e
2008
+ };
2009
+ }
2010
+ function ge(e) {
2011
+ return {
2012
+ required: !1,
2013
+ schema: e
2014
+ };
2015
+ }
2016
+ var be = {
2017
+ type: ye(fe),
2018
+ id: ye(_e),
2019
+ transports: ge(fe)
2020
+ },
2021
+ ke = {
2022
+ appid: ge(fe),
2023
+ appidExclude: ge(fe),
2024
+ credProps: ge(fe)
2025
+ },
2026
+ we = {
2027
+ appid: ge(fe),
2028
+ appidExclude: ge(fe),
2029
+ credProps: ge(fe)
2030
+ },
2031
+ Se = {
2032
+ publicKey: ye({
2033
+ rp: ye(fe),
2034
+ user: ye({
2035
+ id: ye(_e),
2036
+ name: ye(fe),
2037
+ displayName: ye(fe)
2038
+ }),
2039
+ challenge: ye(_e),
2040
+ pubKeyCredParams: ye(fe),
2041
+ timeout: ge(fe),
2042
+ excludeCredentials: ge([be]),
2043
+ authenticatorSelection: ge(fe),
2044
+ attestation: ge(fe),
2045
+ extensions: ge(ke)
2046
+ }),
2047
+ signal: ge(fe)
2048
+ },
2049
+ Te = {
2050
+ type: ye(fe),
2051
+ id: ye(fe),
2052
+ rawId: ye(_e),
2053
+ authenticatorAttachment: ge(fe),
2054
+ response: ye({
2055
+ clientDataJSON: ye(_e),
2056
+ attestationObject: ye(_e),
2057
+ transports: me(fe, function (e) {
2058
+ var t;
2059
+ return (null == (t = e.getTransports) ? void 0 : t.call(e)) || [];
2060
+ })
2061
+ }),
2062
+ clientExtensionResults: me(we, function (e) {
2063
+ return e.getClientExtensionResults();
2064
+ })
2065
+ },
2066
+ Oe = {
2067
+ mediation: ge(fe),
2068
+ publicKey: ye({
2069
+ challenge: ye(_e),
2070
+ timeout: ge(fe),
2071
+ rpId: ge(fe),
2072
+ allowCredentials: ge([be]),
2073
+ userVerification: ge(fe),
2074
+ extensions: ge(ke)
2075
+ }),
2076
+ signal: ge(fe)
2077
+ },
2078
+ Ce = {
2079
+ type: ye(fe),
2080
+ id: ye(fe),
2081
+ rawId: ye(_e),
2082
+ authenticatorAttachment: ge(fe),
2083
+ response: ye({
2084
+ clientDataJSON: ye(_e),
2085
+ authenticatorData: ye(_e),
2086
+ signature: ye(_e),
2087
+ userHandle: ye(_e)
2088
+ }),
2089
+ clientExtensionResults: me(we, function (e) {
2090
+ return e.getClientExtensionResults();
2091
+ })
2092
+ };
2093
+ function Ee(e) {
2094
+ return ve(he, Se, e);
2095
+ }
2096
+ function xe(e) {
2097
+ return ve(pe, Te, e);
2098
+ }
2099
+ function Ae(e) {
2100
+ return k(this, void 0, void 0, s().mark(function t() {
2101
+ var r;
2102
+ return s().wrap(function (t) {
2103
+ for (;;) switch (t.prev = t.next) {
2104
+ case 0:
2105
+ return t.next = 2, navigator.credentials.create(Ee(e));
2106
+ case 2:
2107
+ return r = t.sent, t.abrupt("return", xe(r));
2108
+ case 4:
2109
+ case "end":
2110
+ return t.stop();
2111
+ }
2112
+ }, t);
2113
+ }));
2114
+ }
2115
+ function Pe(e) {
2116
+ return ve(he, Oe, e);
2117
+ }
2118
+ function Re(e) {
2119
+ return ve(pe, Ce, e);
2120
+ }
2121
+ function De(e) {
2122
+ return k(this, void 0, void 0, s().mark(function t() {
2123
+ var r;
2124
+ return s().wrap(function (t) {
2125
+ for (;;) switch (t.prev = t.next) {
2126
+ case 0:
2127
+ return t.next = 2, navigator.credentials.get(Pe(e));
2128
+ case 2:
2129
+ return r = t.sent, t.abrupt("return", Re(r));
2130
+ case 4:
2131
+ case "end":
2132
+ return t.stop();
2133
+ }
2134
+ }, t);
2135
+ }));
2136
+ }
2137
+ var Be,
2138
+ Ie = function () {
2139
+ function e(t, r) {
2140
+ c(this, e), this._networkClient = t, this._subscriptionService = r;
2141
+ }
2142
+ return a(e, [{
2143
+ key: "register",
2144
+ value: function value(e) {
2145
+ var t;
2146
+ return k(this, void 0, void 0, s().mark(function r() {
2147
+ var n, i, o, a;
2148
+ return s().wrap(function (r) {
2149
+ for (;;) switch (r.prev = r.next) {
2150
+ case 0:
2151
+ return Z("stytch.webauthn.register").isOptionalString("domain", null == e ? void 0 : e.domain).isOptionalString("authenticator_type", null == e ? void 0 : e.authenticator_type), r.next = 3, this._networkClient.fetchSDK({
2152
+ url: "/webauthn/register/start",
2153
+ method: "POST",
2154
+ errorMessage: "Failed to start WebAuthn registration",
2155
+ body: {
2156
+ domain: null !== (t = null == e ? void 0 : e.domain) && void 0 !== t ? t : window.location.hostname,
2157
+ authenticator_type: null == e ? void 0 : e.authenticator_type
2158
+ }
2159
+ });
2160
+ case 3:
2161
+ return n = r.sent, i = n.public_key_credential_creation_options, r.next = 7, Ae({
2162
+ publicKey: JSON.parse(i)
2163
+ });
2164
+ case 7:
2165
+ return o = r.sent, r.next = 10, this._networkClient.fetchSDK({
2166
+ url: "/webauthn/register",
2167
+ method: "POST",
2168
+ errorMessage: "Failed to register WebAuthn device",
2169
+ body: {
2170
+ public_key_credential: JSON.stringify(o)
2171
+ }
2172
+ });
2173
+ case 10:
2174
+ return a = r.sent, this._subscriptionService.updateUser(a.__user), r.abrupt("return", ee(a));
2175
+ case 13:
2176
+ case "end":
2177
+ return r.stop();
2178
+ }
2179
+ }, r, this);
2180
+ }));
2181
+ }
2182
+ }, {
2183
+ key: "authenticate",
2184
+ value: function value(e) {
2185
+ var t;
2186
+ return k(this, void 0, void 0, s().mark(function r() {
2187
+ var n, i, o, a;
2188
+ return s().wrap(function (r) {
2189
+ for (;;) switch (r.prev = r.next) {
2190
+ case 0:
2191
+ return Z("stytch.webauthn.register").isOptionalString("domain", e.domain).isNumber("session_duration_minutes", e.session_duration_minutes), r.next = 3, this._networkClient.fetchSDK({
2192
+ url: "/webauthn/authenticate/start",
2193
+ method: "POST",
2194
+ errorMessage: "Failed to start WebAuthn authentication",
2195
+ body: {
2196
+ domain: null !== (t = e.domain) && void 0 !== t ? t : window.location.hostname
2197
+ }
2198
+ });
2199
+ case 3:
2200
+ return n = r.sent, i = n.public_key_credential_request_options, r.next = 7, De({
2201
+ publicKey: JSON.parse(i)
2202
+ });
2203
+ case 7:
2204
+ return o = r.sent, r.next = 10, this._networkClient.fetchSDK({
2205
+ url: "/webauthn/authenticate",
2206
+ method: "POST",
2207
+ errorMessage: "Failed to authenticate WebAuthn device",
2208
+ body: {
2209
+ public_key_credential: JSON.stringify(o),
2210
+ session_duration_minutes: e.session_duration_minutes
2211
+ }
2212
+ });
2213
+ case 10:
2214
+ return a = r.sent, this._subscriptionService.updateStateAndTokens({
2215
+ state: {
2216
+ session: a.session,
2217
+ user: a.__user
2218
+ },
2219
+ session_token: a.session_token,
2220
+ session_jwt: a.session_jwt,
2221
+ intermediate_session_token: null
2222
+ }), r.abrupt("return", ee(a));
2223
+ case 13:
2224
+ case "end":
2225
+ return r.stop();
2226
+ }
2227
+ }, r, this);
2228
+ }));
2229
+ }
2230
+ }]), e;
2231
+ }(),
2232
+ Le = Promise.resolve({
2233
+ pkceRequiredForPasswordResets: !1
2234
+ }),
2235
+ je = function () {
2236
+ function e(t, r, n) {
2237
+ var i = this,
2238
+ o = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : Le,
2239
+ a = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : function () {
2240
+ return Promise.resolve(void 0);
2241
+ },
2242
+ u = arguments.length > 5 ? arguments[5] : void 0;
2243
+ c(this, e), this._networkClient = t, this._subscriptionService = r, this._pkceManager = n, this._config = o, this.executeRecaptcha = a, this._dfpProtectedAuth = u, this.retryWithCaptchaAndDFP = function (e, t) {
2244
+ return k(i, void 0, void 0, s().mark(function r() {
2245
+ var n, i;
2246
+ return s().wrap(function (r) {
2247
+ for (;;) switch (r.prev = r.next) {
2248
+ case 0:
2249
+ if (n = this._dfpProtectedAuth, r.t0 = n, !r.t0) {
2250
+ r.next = 6;
2251
+ break;
2252
+ }
2253
+ return r.next = 5, n.isEnabled();
2254
+ case 5:
2255
+ r.t0 = r.sent;
2256
+ case 6:
2257
+ if (i = r.t0, e.type !== Be.RequiredCatcha || !i) {
2258
+ r.next = 16;
2259
+ break;
2260
+ }
2261
+ if (!t.body) {
2262
+ r.next = 15;
2263
+ break;
2264
+ }
2265
+ return r.next = 11, n.getTelemetryID();
2266
+ case 11:
2267
+ return t.body.dfp_telemetry_id = r.sent, r.next = 14, this.executeRecaptcha();
2268
+ case 14:
2269
+ t.body.captcha_token = r.sent;
2270
+ case 15:
2271
+ return r.abrupt("return", t);
2272
+ case 16:
2273
+ throw new Error("Unable to query captcha and/or dfp telemetry ID");
2274
+ case 17:
2275
+ case "end":
2276
+ return r.stop();
2277
+ }
2278
+ }, r, this);
2279
+ }));
2280
+ };
2281
+ }
2282
+ return a(e, [{
2283
+ key: "getCodeChallenge",
2284
+ value: function value() {
2285
+ return k(this, void 0, void 0, s().mark(function e() {
2286
+ var t, r;
2287
+ return s().wrap(function (e) {
2288
+ for (;;) switch (e.prev = e.next) {
2289
+ case 0:
2290
+ return e.next = 2, this._config;
2291
+ case 2:
2292
+ if (t = e.sent, t.pkceRequiredForPasswordResets) {
2293
+ e.next = 6;
2294
+ break;
2295
+ }
2296
+ return e.abrupt("return", void 0);
2297
+ case 6:
2298
+ return e.next = 8, this._pkceManager.getPKPair();
2299
+ case 8:
2300
+ if (!(r = e.sent)) {
2301
+ e.next = 11;
2302
+ break;
2303
+ }
2304
+ return e.abrupt("return", r.code_challenge);
2305
+ case 11:
2306
+ return e.next = 13, this._pkceManager.startPKCETransaction();
2307
+ case 13:
2308
+ return r = e.sent, e.abrupt("return", r.code_challenge);
2309
+ case 15:
2310
+ case "end":
2311
+ return e.stop();
2312
+ }
2313
+ }, e, this);
2314
+ }));
2315
+ }
2316
+ }, {
2317
+ key: "getDFPTelemetryIDAndCaptcha",
2318
+ value: function value() {
2319
+ return k(this, void 0, void 0, s().mark(function e() {
2320
+ var t, r;
2321
+ return s().wrap(function (e) {
2322
+ for (;;) switch (e.prev = e.next) {
2323
+ case 0:
2324
+ if (t = void 0, r = void 0, e.t0 = this._dfpProtectedAuth, !e.t0) {
2325
+ e.next = 7;
2326
+ break;
2327
+ }
2328
+ return e.next = 6, this._dfpProtectedAuth.isEnabled();
2329
+ case 6:
2330
+ e.t0 = e.sent;
2331
+ case 7:
2332
+ if (!e.t0) {
2333
+ e.next = 13;
2334
+ break;
2335
+ }
2336
+ return e.next = 10, this._dfpProtectedAuth.getTelemetryID();
2337
+ case 10:
2338
+ t = e.sent, e.next = 16;
2339
+ break;
2340
+ case 13:
2341
+ return e.next = 15, this.executeRecaptcha();
2342
+ case 15:
2343
+ r = e.sent;
2344
+ case 16:
2345
+ return e.abrupt("return", {
2346
+ dfp_telemetry_id: t,
2347
+ captcha_token: r
2348
+ });
2349
+ case 17:
2350
+ case "end":
2351
+ return e.stop();
2352
+ }
2353
+ }, e, this);
2354
+ }));
2355
+ }
2356
+ }, {
2357
+ key: "create",
2358
+ value: function value(e) {
2359
+ return k(this, void 0, void 0, s().mark(function t() {
2360
+ var r, n, i, o;
2361
+ return s().wrap(function (t) {
2362
+ for (;;) switch (t.prev = t.next) {
2363
+ case 0:
2364
+ return Z("stytch.passwords.create").isString("password", e.password).isString("email", e.email).isNumber("session_duration_minutes", e.session_duration_minutes), t.next = 3, this.getDFPTelemetryIDAndCaptcha();
2365
+ case 3:
2366
+ return r = t.sent, n = r.dfp_telemetry_id, i = r.captcha_token, t.next = 8, this._networkClient.retriableFetchSDK({
2367
+ url: "/passwords",
2368
+ method: "POST",
2369
+ errorMessage: "Failed to create password.",
2370
+ body: {
2371
+ email: e.email,
2372
+ password: e.password,
2373
+ session_duration_minutes: e.session_duration_minutes,
2374
+ captcha_token: i,
2375
+ dfp_telemetry_id: n
2376
+ },
2377
+ retryCallback: this.retryWithCaptchaAndDFP
2378
+ });
2379
+ case 8:
2380
+ return o = t.sent, this._subscriptionService.updateStateAndTokens({
2381
+ state: {
2382
+ session: o.session,
2383
+ user: o.user
2384
+ },
2385
+ session_token: o.session_token,
2386
+ session_jwt: o.session_jwt,
2387
+ intermediate_session_token: null
2388
+ }), t.abrupt("return", ee(o));
2389
+ case 11:
2390
+ case "end":
2391
+ return t.stop();
2392
+ }
2393
+ }, t, this);
2394
+ }));
2395
+ }
2396
+ }, {
2397
+ key: "authenticate",
2398
+ value: function value(e) {
2399
+ return k(this, void 0, void 0, s().mark(function t() {
2400
+ var r, n, i, o;
2401
+ return s().wrap(function (t) {
2402
+ for (;;) switch (t.prev = t.next) {
2403
+ case 0:
2404
+ return Z("stytch.passwords.authenticate").isString("password", e.password).isString("email", e.email).isNumber("session_duration_minutes", e.session_duration_minutes), t.next = 3, this.getDFPTelemetryIDAndCaptcha();
2405
+ case 3:
2406
+ return r = t.sent, n = r.dfp_telemetry_id, i = r.captcha_token, t.next = 8, this._networkClient.retriableFetchSDK({
2407
+ url: "/passwords/authenticate",
2408
+ method: "POST",
2409
+ errorMessage: "Failed to authenticate password.",
2410
+ body: {
2411
+ email: e.email,
2412
+ password: e.password,
2413
+ session_duration_minutes: e.session_duration_minutes,
2414
+ captcha_token: i,
2415
+ dfp_telemetry_id: n
2416
+ },
2417
+ retryCallback: this.retryWithCaptchaAndDFP
2418
+ });
2419
+ case 8:
2420
+ return o = t.sent, this._subscriptionService.updateStateAndTokens({
2421
+ state: {
2422
+ session: o.session,
2423
+ user: o.user
2424
+ },
2425
+ session_token: o.session_token,
2426
+ session_jwt: o.session_jwt,
2427
+ intermediate_session_token: null
2428
+ }), t.abrupt("return", ee(o));
2429
+ case 11:
2430
+ case "end":
2431
+ return t.stop();
2432
+ }
2433
+ }, t, this);
2434
+ }));
2435
+ }
2436
+ }, {
2437
+ key: "resetByEmailStart",
2438
+ value: function value(e) {
2439
+ return k(this, void 0, void 0, s().mark(function t() {
2440
+ var r, n, i, o;
2441
+ return s().wrap(function (t) {
2442
+ for (;;) switch (t.prev = t.next) {
2443
+ case 0:
2444
+ return Z("stytch.passwords.resetByEmailStart").isString("email", e.email).isOptionalString("login_redirect_url", e.login_redirect_url).isOptionalString("reset_password_redirect_url", e.reset_password_redirect_url).isOptionalString("reset_password_template_id", e.reset_password_template_id).isOptionalNumber("reset_password_expiration_minutes", e.reset_password_expiration_minutes), t.next = 3, this.getCodeChallenge();
2445
+ case 3:
2446
+ return r = t.sent, t.next = 6, this.getDFPTelemetryIDAndCaptcha();
2447
+ case 6:
2448
+ return n = t.sent, i = n.dfp_telemetry_id, o = n.captcha_token, t.abrupt("return", this._networkClient.retriableFetchSDK({
2449
+ url: "/passwords/email/reset/start",
2450
+ method: "POST",
2451
+ errorMessage: "Failed to start password reset flow.",
2452
+ body: {
2453
+ email: e.email,
2454
+ login_redirect_url: e.login_redirect_url,
2455
+ reset_password_redirect_url: e.reset_password_redirect_url,
2456
+ reset_password_expiration_minutes: e.reset_password_expiration_minutes,
2457
+ reset_password_template_id: e.reset_password_template_id,
2458
+ code_challenge: r,
2459
+ captcha_token: o,
2460
+ dfp_telemetry_id: i
2461
+ },
2462
+ retryCallback: this.retryWithCaptchaAndDFP
2463
+ }));
2464
+ case 10:
2465
+ case "end":
2466
+ return t.stop();
2467
+ }
2468
+ }, t, this);
2469
+ }));
2470
+ }
2471
+ }, {
2472
+ key: "resetByEmail",
2473
+ value: function value(e) {
2474
+ return k(this, void 0, void 0, s().mark(function t() {
2475
+ var r, n, i, o, a, c;
2476
+ return s().wrap(function (t) {
2477
+ for (;;) switch (t.prev = t.next) {
2478
+ case 0:
2479
+ return Z("stytch.passwords.resetByEmail").isString("token", e.token).isString("password", e.password).isNumber("session_duration_minutes", e.session_duration_minutes), t.next = 3, this.getDFPTelemetryIDAndCaptcha();
2480
+ case 3:
2481
+ return r = t.sent, n = r.dfp_telemetry_id, i = r.captcha_token, t.next = 8, this._pkceManager.getPKPair();
2482
+ case 8:
2483
+ return o = t.sent, a = null == o ? void 0 : o.code_verifier, t.next = 12, this._networkClient.retriableFetchSDK({
2484
+ url: "/passwords/email/reset",
2485
+ method: "POST",
2486
+ errorMessage: "Failed to reset password.",
2487
+ body: {
2488
+ token: e.token,
2489
+ password: e.password,
2490
+ session_duration_minutes: e.session_duration_minutes,
2491
+ captcha_token: i,
2492
+ code_verifier: a,
2493
+ dfp_telemetry_id: n
2494
+ },
2495
+ retryCallback: this.retryWithCaptchaAndDFP
2496
+ });
2497
+ case 12:
2498
+ return c = t.sent, this._pkceManager.clearPKPair(), this._subscriptionService.updateStateAndTokens({
2499
+ state: {
2500
+ session: c.session,
2501
+ user: c.user
2502
+ },
2503
+ session_token: c.session_token,
2504
+ session_jwt: c.session_jwt,
2505
+ intermediate_session_token: null
2506
+ }), t.abrupt("return", ee(c));
2507
+ case 16:
2508
+ case "end":
2509
+ return t.stop();
2510
+ }
2511
+ }, t, this);
2512
+ }));
2513
+ }
2514
+ }, {
2515
+ key: "resetByExistingPassword",
2516
+ value: function value(e) {
2517
+ return k(this, void 0, void 0, s().mark(function t() {
2518
+ var r;
2519
+ return s().wrap(function (t) {
2520
+ for (;;) switch (t.prev = t.next) {
2521
+ case 0:
2522
+ return Z("stytch.passwords.resetByExistingPassword").isString("email", e.email).isString("existing_password", e.existing_password).isString("new_password", e.new_password).isNumber("session_duration_minutes", e.session_duration_minutes), t.next = 3, this._networkClient.fetchSDK({
2523
+ url: "/passwords/existing_password/reset",
2524
+ method: "POST",
2525
+ errorMessage: "Failed to reset password.",
2526
+ body: {
2527
+ email: e.email,
2528
+ existing_password: e.existing_password,
2529
+ new_password: e.new_password,
2530
+ session_duration_minutes: e.session_duration_minutes
2531
+ }
2532
+ });
2533
+ case 3:
2534
+ return r = t.sent, this._subscriptionService.updateStateAndTokens({
2535
+ state: {
2536
+ session: r.session,
2537
+ user: r.user
2538
+ },
2539
+ session_token: r.session_token,
2540
+ session_jwt: r.session_jwt,
2541
+ intermediate_session_token: null
2542
+ }), t.abrupt("return", ee(r));
2543
+ case 6:
2544
+ case "end":
2545
+ return t.stop();
2546
+ }
2547
+ }, t, this);
2548
+ }));
2549
+ }
2550
+ }, {
2551
+ key: "resetBySession",
2552
+ value: function value(e) {
2553
+ return k(this, void 0, void 0, s().mark(function t() {
2554
+ var r;
2555
+ return s().wrap(function (t) {
2556
+ for (;;) switch (t.prev = t.next) {
2557
+ case 0:
2558
+ return Z("stytch.passwords.resetBySession").isString("password", e.password), t.next = 3, this._networkClient.fetchSDK({
2559
+ url: "/passwords/session/reset",
2560
+ method: "POST",
2561
+ errorMessage: "Failed to reset session.",
2562
+ body: {
2563
+ password: e.password
2564
+ }
2565
+ });
2566
+ case 3:
2567
+ return r = t.sent, this._subscriptionService.updateStateAndTokens({
2568
+ state: {
2569
+ session: r.session,
2570
+ user: r.user
2571
+ },
2572
+ session_token: r.session_token,
2573
+ session_jwt: r.session_jwt,
2574
+ intermediate_session_token: null
2575
+ }), t.abrupt("return", r);
2576
+ case 6:
2577
+ case "end":
2578
+ return t.stop();
2579
+ }
2580
+ }, t, this);
2581
+ }));
2582
+ }
2583
+ }, {
2584
+ key: "strengthCheck",
2585
+ value: function value(e) {
2586
+ return k(this, void 0, void 0, s().mark(function t() {
2587
+ return s().wrap(function (t) {
2588
+ for (;;) switch (t.prev = t.next) {
2589
+ case 0:
2590
+ return Z("stytch.passwords.strengthCheck").isOptionalString("email", e.email).isString("password", e.password), t.abrupt("return", this._networkClient.fetchSDK({
2591
+ url: "/passwords/strength_check",
2592
+ method: "POST",
2593
+ errorMessage: "Failed to check password strength.",
2594
+ body: {
2595
+ email: e.email,
2596
+ password: e.password
2597
+ }
2598
+ }));
2599
+ case 2:
2600
+ case "end":
2601
+ return t.stop();
2602
+ }
2603
+ }, t, this);
2604
+ }));
2605
+ }
2606
+ }]), e;
2607
+ }();
2608
+ Promise.resolve({
2609
+ pkceRequiredForEmailMagicLinks: !1
2610
+ }), Promise.resolve({
2611
+ pkceRequiredForPasswordResets: !1
2612
+ }), function (e) {
2613
+ e.RequiredCatcha = "Catcha Required";
2614
+ }(Be || (Be = {}));
2615
+ var Me = function (e) {
2616
+ u(r, h(Error));
2617
+ var t = l(r);
2618
+ function r(e) {
2619
+ var n;
2620
+ return c(this, r), (n = t.call(this, e)).type = e, n;
2621
+ }
2622
+ return a(r);
2623
+ }();
2624
+ function Ne(e) {
2625
+ var t = e.method,
2626
+ r = e.errorMessage,
2627
+ n = e.finalURL,
2628
+ i = e.basicAuthHeader,
2629
+ o = e.xSDKClientHeader,
2630
+ a = e.xSDKParentHostHeader,
2631
+ c = e.body;
2632
+ return k(this, void 0, void 0, s().mark(function e() {
2633
+ var u, l, d, h, p, f;
2634
+ return s().wrap(function (e) {
2635
+ for (;;) switch (e.prev = e.next) {
2636
+ case 0:
2637
+ return u = {
2638
+ Authorization: i,
2639
+ "Content-Type": "application/json",
2640
+ "X-SDK-Client": o
2641
+ }, a && (u["X-SDK-Parent-Host"] = a), l = {
2642
+ method: t,
2643
+ headers: u,
2644
+ body: c && JSON.stringify(c)
2645
+ }, e.prev = 3, e.next = 6, fetch(n, l);
2646
+ case 6:
2647
+ d = e.sent, e.next = 14;
2648
+ break;
2649
+ case 9:
2650
+ if (e.prev = 9, e.t0 = e["catch"](3), "Failed to fetch" !== e.t0.message) {
2651
+ e.next = 13;
2652
+ break;
2653
+ }
2654
+ throw new F(r, "Unable to contact the Stytch servers. Are you online?");
2655
+ case 13:
2656
+ throw e.t0;
2657
+ case 14:
2658
+ if (403 !== d.status) {
2659
+ e.next = 27;
2660
+ break;
2661
+ }
2662
+ return e.prev = 15, e.next = 18, d.text();
2663
+ case 18:
2664
+ h = e.sent, e.next = 24;
2665
+ break;
2666
+ case 21:
2667
+ throw e.prev = 21, e.t1 = e["catch"](15), new F(r, "Invalid response from the Stytch servers.");
2668
+ case 24:
2669
+ if (!h.includes("Captcha required")) {
2670
+ e.next = 26;
2671
+ break;
2672
+ }
2673
+ throw new Me(Be.RequiredCatcha);
2674
+ case 26:
2675
+ throw new F(r, "Invalid response from the Stytch servers.");
2676
+ case 27:
2677
+ if (200 === d.status) {
2678
+ e.next = 40;
2679
+ break;
2680
+ }
2681
+ return e.prev = 28, e.next = 31, d.json();
2682
+ case 31:
2683
+ p = e.sent, e.next = 37;
2684
+ break;
2685
+ case 34:
2686
+ throw e.prev = 34, e.t2 = e["catch"](28), new F(r, "Invalid or no response from server");
2687
+ case 37:
2688
+ if (!("body" in p || "params" in p || "query" in p)) {
2689
+ e.next = 39;
2690
+ break;
2691
+ }
2692
+ throw new K(p);
2693
+ case 39:
2694
+ throw new q(p);
2695
+ case 40:
2696
+ return e.prev = 40, e.next = 43, d.json();
2697
+ case 43:
2698
+ return f = e.sent, e.abrupt("return", f.data);
2699
+ case 47:
2700
+ throw e.prev = 47, e.t3 = e["catch"](40), new F(r, "Invalid response from the Stytch servers.");
2701
+ case 50:
2702
+ case "end":
2703
+ return e.stop();
2704
+ }
2705
+ }, e, null, [[3, 9], [15, 21], [28, 34], [40, 47]]);
2706
+ }));
2707
+ }
2708
+ var Fe = function () {
2709
+ function e(t) {
2710
+ c(this, e), this.iframeURL = t, this.createIframe();
2711
+ }
2712
+ return a(e, [{
2713
+ key: "createIframe",
2714
+ value: function value() {
2715
+ var e = document.querySelector('[src~="'.concat(this.iframeURL, '"]'));
2716
+ e ? J("It looks like you're creating multiple copies of the Stytch client. This behavior is unsupported, and unintended side effects may occur. Make sure you are creating the Stytch client at the global level, and not inside a component's render function.") : ((e = document.createElement("iframe")).src = this.iframeURL, e.style.position = "absolute", e.style.width = "0", e.style.height = "0", e.style.border = "0", document.body.appendChild(e)), "true" !== e.dataset.loaded ? this.frame = new Promise(function (t) {
2717
+ e.addEventListener("load", function () {
2718
+ e.dataset.loaded = "true", t(e);
2719
+ }, {
2720
+ once: !0
2721
+ });
2722
+ }) : this.frame = Promise.resolve(e);
2723
+ }
2724
+ }, {
2725
+ key: "call",
2726
+ value: function value(e, t) {
2727
+ return k(this, void 0, void 0, s().mark(function r() {
2728
+ var n,
2729
+ i,
2730
+ o = this;
2731
+ return s().wrap(function (r) {
2732
+ for (;;) switch (r.prev = r.next) {
2733
+ case 0:
2734
+ return r.next = 2, this.frame;
2735
+ case 2:
2736
+ return n = r.sent, i = new MessageChannel(), r.abrupt("return", new Promise(function (r, s) {
2737
+ var a;
2738
+ i.port1.onmessage = function (e) {
2739
+ var t = e.data;
2740
+ i.port1.close(), t.success ? r(t.payload) : s(re.unmarshall(t.error));
2741
+ };
2742
+ var c = {
2743
+ method: e,
2744
+ args: t
2745
+ };
2746
+ null === (a = n.contentWindow) || void 0 === a || a.postMessage(c, o.iframeURL, [i.port2]);
2747
+ }));
2748
+ case 5:
2749
+ case "end":
2750
+ return r.stop();
2751
+ }
2752
+ }, r, this);
2753
+ }));
2754
+ }
2755
+ }]), e;
2756
+ }(),
2757
+ Ue = function () {
2758
+ function e(t, r) {
2759
+ var n = this;
2760
+ c(this, e), this._subscriptionService = t, this._headlessSessionClient = r, this._onDataChange = function (e) {
2761
+ (null == e ? void 0 : e.session) ? n.scheduleBackgroundRefresh() : n.cancelBackgroundRefresh();
2762
+ }, this._reauthenticateWithBackoff = function () {
2763
+ return k(n, void 0, void 0, s().mark(function t() {
2764
+ var r;
2765
+ return s().wrap(function (t) {
2766
+ for (;;) switch (t.prev = t.next) {
2767
+ case 0:
2768
+ r = 0;
2769
+ case 1:
2770
+ return t.prev = 2, t.next = 5, this._headlessSessionClient.authenticate();
2771
+ case 5:
2772
+ return t.abrupt("return", t.sent);
2773
+ case 8:
2774
+ if (t.prev = 8, t.t0 = t["catch"](2), !e.isUnrecoverableError(t.t0)) {
2775
+ t.next = 12;
2776
+ break;
2777
+ }
2778
+ return t.abrupt("return", Promise.reject(t.t0));
2779
+ case 12:
2780
+ return r++, t.next = 15, new Promise(function (t) {
2781
+ return setTimeout(t, e.timeoutForAttempt(r));
2782
+ });
2783
+ case 15:
2784
+ t.next = 1;
2785
+ break;
2786
+ case 17:
2787
+ case "end":
2788
+ return t.stop();
2789
+ }
2790
+ }, t, this, [[2, 8]]);
2791
+ }));
2792
+ }, this.timeout = null, this._subscriptionService.subscribeToState(this._onDataChange);
2793
+ }
2794
+ return a(e, [{
2795
+ key: "performBackgroundRefresh",
2796
+ value: function value() {
2797
+ var e = this;
2798
+ this._reauthenticateWithBackoff().then(function () {
2799
+ e.scheduleBackgroundRefresh();
2800
+ })["catch"](function (t) {
2801
+ J("Session background refresh failed. Signalling to app that user is logged out.", {
2802
+ error: t
2803
+ }), e._subscriptionService.destroyState();
2804
+ });
2805
+ }
2806
+ }, {
2807
+ key: "scheduleBackgroundRefresh",
2808
+ value: function value() {
2809
+ var t = this;
2810
+ this.cancelBackgroundRefresh(), this.timeout = setTimeout(function () {
2811
+ t.performBackgroundRefresh();
2812
+ }, e.REFRESH_INTERVAL_MS);
2813
+ }
2814
+ }, {
2815
+ key: "cancelBackgroundRefresh",
2816
+ value: function value() {
2817
+ null !== this.timeout && (clearTimeout(this.timeout), this.timeout = null);
2818
+ }
2819
+ }], [{
2820
+ key: "timeoutForAttempt",
2821
+ value: function value(e) {
2822
+ return e = Math.min(e, 7), Math.floor(350 * Math.random()) - 175 + 2e3 * Math.pow(2, e);
2823
+ }
2824
+ }, {
2825
+ key: "isUnrecoverableError",
2826
+ value: function value(e) {
2827
+ return W.includes(e.error_type);
2828
+ }
2829
+ }]), e;
2830
+ }();
2831
+ Ue.REFRESH_INTERVAL_MS = 18e4;
2832
+ var Ke = "bootstrap";
2833
+ var qe = /*#__PURE__*/function () {
2834
+ function qe(e, t, r) {
2835
+ var _this = this;
2836
+ _classCallCheck(this, qe);
2837
+ this._publicToken = e, this._networkClient = t, this._dataLayer = r, this._bootstrapDataPromise = this._networkClient.fetchSDK({
2838
+ url: "/projects/bootstrap/".concat(this._publicToken),
2839
+ method: "GET",
2840
+ errorMessage: "Error fetching bootstrap data for SDK for ".concat(this._publicToken)
2841
+ }).then(qe.mapBootstrapData).then(function (e) {
2842
+ return _this._dataLayer.setItem(Ke, JSON.stringify(e)), e;
2843
+ })["catch"](function (e) {
2844
+ return $(e), {
2845
+ displayWatermark: !1,
2846
+ cnameDomain: null,
2847
+ emailDomains: ["stytch.com"],
2848
+ captchaSettings: {
2849
+ enabled: !1
2850
+ },
2851
+ pkceRequiredForEmailMagicLinks: !1,
2852
+ pkceRequiredForPasswordResets: !1,
2853
+ pkceRequiredForOAuth: !1,
2854
+ pkceRequiredForSso: !1,
2855
+ slugPattern: null,
2856
+ createOrganizationEnabled: !1,
2857
+ passwordConfig: null,
2858
+ runDFPProtectedAuth: !1
2859
+ };
2860
+ });
2861
+ }
2862
+ _createClass(qe, [{
2863
+ key: "getSync",
2864
+ value: function getSync() {
2865
+ var e = this._dataLayer.getItem(Ke);
2866
+ if (null === e) return {
2867
+ displayWatermark: !1,
2868
+ cnameDomain: null,
2869
+ emailDomains: ["stytch.com"],
2870
+ captchaSettings: {
2871
+ enabled: !1
2872
+ },
2873
+ pkceRequiredForEmailMagicLinks: !1,
2874
+ pkceRequiredForPasswordResets: !1,
2875
+ pkceRequiredForOAuth: !1,
2876
+ pkceRequiredForSso: !1,
2877
+ slugPattern: null,
2878
+ createOrganizationEnabled: !1,
2879
+ passwordConfig: null,
2880
+ runDFPProtectedAuth: !1
2881
+ };
2882
+ try {
2883
+ return JSON.parse(e);
2884
+ } catch (e) {
2885
+ return {
2886
+ displayWatermark: !1,
2887
+ cnameDomain: null,
2888
+ emailDomains: ["stytch.com"],
2889
+ captchaSettings: {
2890
+ enabled: !1
2891
+ },
2892
+ pkceRequiredForEmailMagicLinks: !1,
2893
+ pkceRequiredForPasswordResets: !1,
2894
+ pkceRequiredForOAuth: !1,
2895
+ pkceRequiredForSso: !1,
2896
+ slugPattern: null,
2897
+ createOrganizationEnabled: !1,
2898
+ passwordConfig: null,
2899
+ runDFPProtectedAuth: !1
2900
+ };
2901
+ }
2902
+ }
2903
+ }, {
2904
+ key: "getAsync",
2905
+ value: function getAsync() {
2906
+ return this._bootstrapDataPromise;
2907
+ }
2908
+ }], [{
2909
+ key: "mapBootstrapData",
2910
+ value: function mapBootstrapData(e) {
2911
+ var t;
2912
+ var r = null !== e.password_config ? {
2913
+ ludsComplexity: e.password_config.luds_complexity,
2914
+ ludsMinimumCount: e.password_config.luds_minimum_count
2915
+ } : null;
2916
+ return {
2917
+ displayWatermark: !e.disable_sdk_watermark,
2918
+ captchaSettings: e.captcha_settings,
2919
+ cnameDomain: e.cname_domain,
2920
+ emailDomains: e.email_domains,
2921
+ pkceRequiredForEmailMagicLinks: e.pkce_required_for_email_magic_links,
2922
+ pkceRequiredForPasswordResets: e.pkce_required_for_password_resets,
2923
+ pkceRequiredForOAuth: e.pkce_required_for_oauth,
2924
+ pkceRequiredForSso: e.pkce_required_for_sso,
2925
+ slugPattern: e.slug_pattern,
2926
+ createOrganizationEnabled: e.create_organization_enabled,
2927
+ passwordConfig: r,
2928
+ runDFPProtectedAuth: null !== (t = e.dfp_protected_auth_enabled) && void 0 !== t && t
2929
+ };
2930
+ }
2931
+ }]);
2932
+ return qe;
2933
+ }();
2934
+ function We(e, t, r, n) {
2935
+ return new (r || (r = Promise))(function (i, s) {
2936
+ function o(e) {
2937
+ try {
2938
+ c(n.next(e));
2939
+ } catch (e) {
2940
+ s(e);
2941
+ }
2942
+ }
2943
+ function a(e) {
2944
+ try {
2945
+ c(n["throw"](e));
2946
+ } catch (e) {
2947
+ s(e);
2948
+ }
2949
+ }
2950
+ function c(e) {
2951
+ var t;
2952
+ e.done ? i(e.value) : (t = e.value, t instanceof r ? t : new r(function (e) {
2953
+ e(t);
2954
+ })).then(o, a);
2955
+ }
2956
+ c((n = n.apply(e, t || [])).next());
2957
+ });
2958
+ }
2959
+ var Ge = /*#__PURE__*/_createClass(function Ge(e) {
2960
+ var _this2 = this;
2961
+ _classCallCheck(this, Ge);
2962
+ this.bootstrapPromise = e, this.executeRecaptcha = function () {
2963
+ return We(_this2, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2964
+ var _yield$this$state, e, t, r;
2965
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2966
+ while (1) switch (_context.prev = _context.next) {
2967
+ case 0:
2968
+ _context.next = 2;
2969
+ return this.state;
2970
+ case 2:
2971
+ _yield$this$state = _context.sent;
2972
+ e = _yield$this$state.captchaClient;
2973
+ t = _yield$this$state.configured;
2974
+ r = _yield$this$state.siteKey;
2975
+ if (!t) {
2976
+ _context.next = 10;
2977
+ break;
2978
+ }
2979
+ _context.next = 9;
2980
+ return new Promise(function (t) {
2981
+ return e.ready(t);
2982
+ });
2983
+ case 9:
2984
+ return _context.abrupt("return", e.execute(r, {
2985
+ action: "LOGIN"
2986
+ }));
2987
+ case 10:
2988
+ case "end":
2989
+ return _context.stop();
2990
+ }
2991
+ }, _callee, this);
2992
+ }));
2993
+ }, this.state = e.then(function (e) {
2994
+ return We(_this2, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
2995
+ var t;
2996
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
2997
+ while (1) switch (_context2.prev = _context2.next) {
2998
+ case 0:
2999
+ if (!e.captchaSettings.enabled) {
3000
+ _context2.next = 9;
3001
+ break;
3002
+ }
3003
+ _context2.t1 = !0;
3004
+ _context2.next = 4;
3005
+ return t = e.captchaSettings.siteKey, H("https://www.google.com/recaptcha/enterprise.js?render=".concat(t), function () {
3006
+ return window.grecaptcha.enterprise;
3007
+ });
3008
+ case 4:
3009
+ _context2.t2 = _context2.sent;
3010
+ _context2.t3 = e.captchaSettings.siteKey;
3011
+ _context2.t0 = {
3012
+ configured: _context2.t1,
3013
+ captchaClient: _context2.t2,
3014
+ siteKey: _context2.t3
3015
+ };
3016
+ _context2.next = 10;
3017
+ break;
3018
+ case 9:
3019
+ _context2.t0 = {
3020
+ configured: !1
3021
+ };
3022
+ case 10:
3023
+ return _context2.abrupt("return", _context2.t0);
3024
+ case 11:
3025
+ case "end":
3026
+ return _context2.stop();
3027
+ }
3028
+ }, _callee2);
3029
+ }));
3030
+ });
3031
+ });
3032
+ var He = /*#__PURE__*/function () {
3033
+ function He(e) {
3034
+ var _this3 = this;
3035
+ _classCallCheck(this, He);
3036
+ this.iframeURL = e, this.oneTapStart = function (e) {
3037
+ return _this3.call("oneTapStart", e);
3038
+ }, this.oneTapSubmit = function (e) {
3039
+ return _this3.call("oneTapSubmit", e);
3040
+ };
3041
+ }
3042
+ _createClass(He, [{
3043
+ key: "frameClient",
3044
+ get: function get() {
3045
+ var e;
3046
+ return this._frameClient = null !== (e = this._frameClient) && void 0 !== e ? e : new Fe(this.iframeURL), this._frameClient;
3047
+ }
3048
+ }, {
3049
+ key: "call",
3050
+ value: function call(e, t) {
3051
+ return this.frameClient.call(e, [t]);
3052
+ }
3053
+ }]);
3054
+ return He;
3055
+ }();
3056
+ function ze(e) {
3057
+ return ze = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (e) {
3058
+ return _typeof(e);
3059
+ } : function (e) {
3060
+ return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : _typeof(e);
3061
+ }, ze(e);
3062
+ }
3063
+ function Ye(e, t) {
3064
+ for (var r = 0; r < t.length; r++) {
3065
+ var n = t[r];
3066
+ n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, (i = n.key, s = void 0, s = function (e, t) {
3067
+ if ("object" !== ze(e) || null === e) return e;
3068
+ var r = e[Symbol.toPrimitive];
3069
+ if (void 0 !== r) {
3070
+ var n = r.call(e, t || "default");
3071
+ if ("object" !== ze(n)) return n;
3072
+ throw new TypeError("@@toPrimitive must return a primitive value.");
3073
+ }
3074
+ return ("string" === t ? String : Number)(e);
3075
+ }(i, "string"), "symbol" === ze(s) ? s : String(s)), n);
3076
+ }
3077
+ var i, s;
3078
+ }
3079
+ function Ve(e, t, r) {
3080
+ return t && Ye(e.prototype, t), r && Ye(e, r), Object.defineProperty(e, "prototype", {
3081
+ writable: !1
3082
+ }), e;
3083
+ }
3084
+ function Je(e, t) {
3085
+ if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
3086
+ }
3087
+ function $e(e, t) {
3088
+ if ("function" != typeof t && null !== t) throw new TypeError("Super expression must either be null or a function");
3089
+ e.prototype = Object.create(t && t.prototype, {
3090
+ constructor: {
3091
+ value: e,
3092
+ writable: !0,
3093
+ configurable: !0
3094
+ }
3095
+ }), Object.defineProperty(e, "prototype", {
3096
+ writable: !1
3097
+ }), t && rt(e, t);
3098
+ }
3099
+ function Xe(e) {
3100
+ var t = tt();
3101
+ return function () {
3102
+ var r,
3103
+ n = nt(e);
3104
+ if (t) {
3105
+ var i = nt(this).constructor;
3106
+ r = Reflect.construct(n, arguments, i);
3107
+ } else r = n.apply(this, arguments);
3108
+ return function (e, t) {
3109
+ if (t && ("object" === ze(t) || "function" == typeof t)) return t;
3110
+ if (void 0 !== t) throw new TypeError("Derived constructors may only return object or undefined");
3111
+ return Ze(e);
3112
+ }(this, r);
3113
+ };
3114
+ }
3115
+ function Ze(e) {
3116
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3117
+ return e;
3118
+ }
3119
+ function Qe(e) {
3120
+ var t = "function" == typeof Map ? new Map() : void 0;
3121
+ return Qe = function Qe(e) {
3122
+ if (null === e || (r = e, -1 === Function.toString.call(r).indexOf("[native code]"))) return e;
3123
+ var r;
3124
+ if ("function" != typeof e) throw new TypeError("Super expression must either be null or a function");
3125
+ if (void 0 !== t) {
3126
+ if (t.has(e)) return t.get(e);
3127
+ t.set(e, n);
3128
+ }
3129
+ function n() {
3130
+ return et(e, arguments, nt(this).constructor);
3131
+ }
3132
+ return n.prototype = Object.create(e.prototype, {
3133
+ constructor: {
3134
+ value: n,
3135
+ enumerable: !1,
3136
+ writable: !0,
3137
+ configurable: !0
3138
+ }
3139
+ }), rt(n, e);
3140
+ }, Qe(e);
3141
+ }
3142
+ function et(e, t, r) {
3143
+ return et = tt() ? Reflect.construct.bind() : function (e, t, r) {
3144
+ var n = [null];
3145
+ n.push.apply(n, t);
3146
+ var i = new (Function.bind.apply(e, n))();
3147
+ return r && rt(i, r.prototype), i;
3148
+ }, et.apply(null, arguments);
3149
+ }
3150
+ function tt() {
3151
+ if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
3152
+ if (Reflect.construct.sham) return !1;
3153
+ if ("function" == typeof Proxy) return !0;
3154
+ try {
3155
+ return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})), !0;
3156
+ } catch (e) {
3157
+ return !1;
3158
+ }
3159
+ }
3160
+ function rt(e, t) {
3161
+ return rt = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (e, t) {
3162
+ return e.__proto__ = t, e;
3163
+ }, rt(e, t);
3164
+ }
3165
+ function nt(e) {
3166
+ return nt = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (e) {
3167
+ return e.__proto__ || Object.getPrototypeOf(e);
3168
+ }, nt(e);
3169
+ }
3170
+ var it, st, ot, at, ct, ut;
3171
+ !function (e) {
3172
+ e.emailMagicLinks = "emailMagicLinks", e.oauth = "oauth", e.otp = "otp", e.crypto = "crypto", e.passwords = "passwords";
3173
+ }(it || (it = {})), function (e) {
3174
+ e.Google = "google", e.Microsoft = "microsoft", e.Apple = "apple", e.Github = "github", e.GitLab = "gitlab", e.Facebook = "facebook", e.Discord = "discord", e.Salesforce = "salesforce", e.Slack = "slack", e.Amazon = "amazon", e.Bitbucket = "bitbucket", e.LinkedIn = "linkedin", e.Coinbase = "coinbase", e.Twitch = "twitch", e.Twitter = "twitter", e.TikTok = "tiktok", e.Snapchat = "snapchat", e.Figma = "figma", e.Yahoo = "yahoo";
3175
+ }(st || (st = {})), function (e) {
3176
+ e.Vessel = "Vessel", e.Phantom = "Phantom", e.Metamask = "Metamask", e.Coinbase = "Coinbase", e.Binance = "Binance", e.GenericEthereumWallet = "Other Ethereum Wallet", e.GenericSolanaWallet = "Other Solana Wallet";
3177
+ }(ot || (ot = {})), function (e) {
3178
+ e.embedded = "embedded", e.floating = "floating";
3179
+ }(at || (at = {})), function (e) {
3180
+ e.SMS = "sms", e.WhatsApp = "whatsapp", e.Email = "email";
3181
+ }(ct || (ct = {})), function (e) {
3182
+ e.MagicLinkLoginOrCreateEvent = "MAGIC_LINK_LOGIN_OR_CREATE", e.OTPsLoginOrCreateEvent = "OTP_LOGIN_OR_CREATE", e.OTPsAuthenticate = "OTP_AUTHENTICATE", e.CryptoWalletAuthenticateStart = "CRYPTO_WALLET_AUTHENTICATE_START", e.CryptoWalletAuthenticate = "CRYPTO_WALLET_AUTHENTICATE", e.PasswordCreate = "PASSWORD_CREATE", e.PasswordAuthenticate = "PASSWORD_AUTHENTICATE", e.PasswordResetByEmailStart = "PASSWORD_RESET_BY_EMAIL_START", e.PasswordResetByEmail = "PASSWORD_RESET_BY_EMAIL", e.B2BMagicLinkEmailLoginOrSignup = "B2B_MAGIC_LINK_EMAIL_LOGIN_OR_SIGNUP", e.B2BMagicLinkAuthenticate = "B2B_MAGIC_LINK_AUTHENTICATE", e.B2BMagicLinkEmailDiscoverySend = "B2B_MAGIC_LINK_EMAIL_DISCOVERY_SEND", e.B2BMagicLinkDiscoveryAuthenticate = "B2B_MAGIC_LINK_DISCOVERY_AUTHENTICATE", e.B2BSSOStart = "B2B_SSO_START", e.B2BSSOAuthenticate = "B2B_SSO_AUTHENTICATE", e.B2BOAuthAuthenticate = "B2B_SSO_AUTHENTICATE", e.B2BOAuthDiscoveryAuthenticate = "B2B_OAUTH_DISCOVERY_AUTHENTICATE", e.B2BDiscoveryOrganizationsCreate = "B2B_DISCOVERY_ORGANIZATIONS_CREATE", e.B2BDiscoveryIntermediateSessionExchange = "B2B_DISCOVERY_INTERMEDIATE_SESSION_EXCHANGE", e.B2BPasswordAuthenticate = "B2B_PASSWORD_AUTHENTICATE", e.B2BPasswordResetByEmailStart = "B2B_PASSWORD_RESET_BY_EMAIL_START", e.B2BPasswordResetByEmail = "B2B_PASSWORD_RESET_BY_EMAIL", e.B2BPasswordResetBySession = "B2B_PASSWORD_RESET_BY_SESSION";
3183
+ }(ut || (ut = {}));
3184
+ var lt,
3185
+ dt,
3186
+ ht,
3187
+ pt,
3188
+ ft = function (e) {
3189
+ $e(r, Qe(Error));
3190
+ var t = Xe(r);
3191
+ function r(e, n) {
3192
+ var i;
3193
+ return Je(this, r), (i = t.call(this, e + "\n" + n)).message = e + "\n" + n, i.name = "SDKAPIUnreachableError", i.details = n, Object.setPrototypeOf(Ze(i), r.prototype), i;
3194
+ }
3195
+ return Ve(r);
3196
+ }(),
3197
+ _t = function (e) {
3198
+ $e(r, Qe(Error));
3199
+ var t = Xe(r);
3200
+ function r(e, n) {
3201
+ var i;
3202
+ return Je(this, r), (i = t.call(this)).name = "StytchSDKUsageError", i.message = "Invalid call to ".concat(e, "\n") + n, i;
3203
+ }
3204
+ return Ve(r);
3205
+ }(),
3206
+ vt = function (e) {
3207
+ $e(r, Qe(Error));
3208
+ var t = Xe(r);
3209
+ function r(e) {
3210
+ var n, i;
3211
+ Je(this, r), (n = t.call(this)).name = "StytchSDKSchemaError";
3212
+ var s = null === (i = e.body) || void 0 === i ? void 0 : i.map(function (e) {
3213
+ return "".concat(e.dataPath, ": ").concat(e.message);
3214
+ }).join("\n");
3215
+ return n.message = "[400] Request does not match expected schema\n".concat(s), n;
3216
+ }
3217
+ return Ve(r);
3218
+ }(),
3219
+ mt = function (e) {
3220
+ $e(r, Qe(Error));
3221
+ var t = Xe(r);
3222
+ function r(e) {
3223
+ var n;
3224
+ Je(this, r), (n = t.call(this)).name = "StytchSDKAPIError";
3225
+ var i = e.status_code,
3226
+ s = e.error_type,
3227
+ o = e.error_message,
3228
+ a = e.error_url,
3229
+ c = e.request_id;
3230
+ return n.error_type = s, n.error_message = o, n.error_url = a, n.request_id = c, n.status_code = i, n.message = "[".concat(i, "] ").concat(s, "\n") + "".concat(o, "\n") + "See ".concat(a, " for more information.\n") + (c ? "request_id: ".concat(c, "\n") : ""), n;
3231
+ }
3232
+ return Ve(r);
3233
+ }(),
3234
+ yt = function (e) {
3235
+ $e(r, Qe(Error));
3236
+ var t = Xe(r);
3237
+ function r(e) {
3238
+ var n;
3239
+ return Je(this, r), (n = t.call(this)).name = "StytchSDKNativeError", n.error_type = e, n.message = "".concat(e), n;
3240
+ }
3241
+ return Ve(r);
3242
+ }(),
3243
+ gt = ["unauthorized_credentials", "user_unauthenticated", "invalid_secret_authentication", "session_not_found"];
3244
+ !function (e) {
3245
+ e.BiometricsSensorError = "biometrics_sensor_error", e.DeviceCredentialsNotAllowed = "device_credentials_not_allowed", e.DeviceHardwareError = "device_hardware_error", e.InternalError = "internal_error", e.KeyInvalidated = "key_invalidated", e.KeystoreUnavailable = "keystore_unavailable", e.NoBiometricsEnrolled = "no_biometrics_enrolled", e.NoBiometricsRegistration = "no_biometrics_registration", e.SessionExpired = "session_expired", e.UserCancellation = "user_cancellation", e.UserLockedOut = "user_locked_out", e.BiometricsNotAvailable = "biometrics_not_available";
3246
+ }(lt || (lt = {})), function (e) {
3247
+ e.emailMagicLinks = "emailMagicLinks", e.sso = "sso", e.passwords = "passwords", e.oauth = "oauth";
3248
+ }(dt || (dt = {})), function (e) {
3249
+ e.Discovery = "Discovery", e.Organization = "Organization", e.PasswordReset = "PasswordReset";
3250
+ }(ht || (ht = {})), function (e) {
3251
+ e.Google = "google", e.Microsoft = "microsoft";
3252
+ }(pt || (pt = {}));
3253
+ var bt = /*#__PURE__*/function (_ue) {
3254
+ _inherits(bt, _ue);
3255
+ var _super = _createSuper(bt);
3256
+ function bt(e, t, r, n, i, s) {
3257
+ var _this4;
3258
+ _classCallCheck(this, bt);
3259
+ _this4 = _super.call(this, e, t, r, n, i), _this4._oneTap = s, _this4.startOneTap = function (e) {
3260
+ return We(_assertThisInitialized(_this4), void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
3261
+ var t, r, n;
3262
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3263
+ while (1) switch (_context3.prev = _context3.next) {
3264
+ case 0:
3265
+ _context3.next = 2;
3266
+ return this._oneTap.createOneTapClient();
3267
+ case 2:
3268
+ t = _context3.sent;
3269
+ if (t.success) {
3270
+ _context3.next = 5;
3271
+ break;
3272
+ }
3273
+ throw new Error("One Tap could not load: ".concat(t.reason));
3274
+ case 5:
3275
+ r = t.client, n = this._oneTap.createOnSuccessHandler({
3276
+ signupRedirectUrl: e.signup_redirect_url,
3277
+ loginRedirectUrl: e.login_redirect_url,
3278
+ onSuccess: this._oneTap.RedirectOnSuccess
3279
+ });
3280
+ return _context3.abrupt("return", r.render({
3281
+ style: {
3282
+ position: at.floating
3283
+ },
3284
+ onOneTapCancelled: e.onOneTapCancelled,
3285
+ callback: n
3286
+ }));
3287
+ case 7:
3288
+ case "end":
3289
+ return _context3.stop();
3290
+ }
3291
+ }, _callee3, this);
3292
+ }));
3293
+ }, _this4.googleOneTap = {
3294
+ start: _this4.startOneTap
3295
+ };
3296
+ return _this4;
3297
+ }
3298
+ return _createClass(bt);
3299
+ }(ue);
3300
+ var kt = /*#__PURE__*/function () {
3301
+ function kt(e, t, r, n) {
3302
+ _classCallCheck(this, kt);
3303
+ this._publicToken = e, this._subscriptionDataLayer = t, this.baseURL = r, this.additionalTelemetryDataFn = n, this.updateSessionToken = function () {
3304
+ return null;
3305
+ }, this.eventLogger = new ne({
3306
+ maxBatchSize: 15,
3307
+ intervalDurationMs: 800,
3308
+ logEventURL: this.buildSDKUrl("/events")
3309
+ });
3310
+ }
3311
+ _createClass(kt, [{
3312
+ key: "logEvent",
3313
+ value: function logEvent(_ref) {
3314
+ var e = _ref.name,
3315
+ t = _ref.details,
3316
+ _ref$error = _ref.error,
3317
+ r = _ref$error === void 0 ? {} : _ref$error;
3318
+ this.eventLogger.logEvent(this.createTelemetryBlob(), {
3319
+ public_token: this._publicToken,
3320
+ event_name: e,
3321
+ details: t,
3322
+ error_code: r.error_code,
3323
+ error_description: r.error_description,
3324
+ http_status_code: r.http_status_code
3325
+ });
3326
+ }
3327
+ }, {
3328
+ key: "createTelemetryBlob",
3329
+ value: function createTelemetryBlob() {
3330
+ return Object.assign(Object.assign({
3331
+ event_id: "event-id-".concat(I()),
3332
+ app_session_id: "app-session-id-".concat(I()),
3333
+ persistent_id: "persistent-id-".concat(I()),
3334
+ client_sent_at: new Date().toISOString(),
3335
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
3336
+ }, this.additionalTelemetryDataFn()), {
3337
+ app: {
3338
+ identifier: window.location.hostname
3339
+ },
3340
+ sdk: {
3341
+ identifier: "Stytch.js Javascript SDK",
3342
+ version: "2.0.3"
3343
+ }
3344
+ });
3345
+ }
3346
+ }, {
3347
+ key: "fetchSDK",
3348
+ value: function fetchSDK(_ref2) {
3349
+ var e = _ref2.url,
3350
+ t = _ref2.body,
3351
+ r = _ref2.errorMessage,
3352
+ n = _ref2.method;
3353
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
3354
+ var i, s, o, a;
3355
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3356
+ while (1) switch (_context4.prev = _context4.next) {
3357
+ case 0:
3358
+ i = this._subscriptionDataLayer.readSessionCookie().session_token, s = "Basic " + window.btoa(this._publicToken + ":" + (i || this._publicToken)), o = window.btoa(JSON.stringify(this.createTelemetryBlob())), a = window.location.origin;
3359
+ return _context4.abrupt("return", Ne({
3360
+ basicAuthHeader: s,
3361
+ body: t,
3362
+ errorMessage: r,
3363
+ finalURL: this.buildSDKUrl(e),
3364
+ method: n,
3365
+ xSDKClientHeader: o,
3366
+ xSDKParentHostHeader: a
3367
+ }));
3368
+ case 2:
3369
+ case "end":
3370
+ return _context4.stop();
3371
+ }
3372
+ }, _callee4, this);
3373
+ }));
3374
+ }
3375
+ }, {
3376
+ key: "retriableFetchSDK",
3377
+ value: function retriableFetchSDK(_ref3) {
3378
+ var e = _ref3.url,
3379
+ t = _ref3.body,
3380
+ r = _ref3.errorMessage,
3381
+ n = _ref3.method,
3382
+ i = _ref3.retryCallback;
3383
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
3384
+ var o, a, c, u;
3385
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
3386
+ while (1) switch (_context5.prev = _context5.next) {
3387
+ case 0:
3388
+ o = this._subscriptionDataLayer.readSessionCookie().session_token, a = "Basic " + window.btoa(this._publicToken + ":" + (o || this._publicToken)), c = window.btoa(JSON.stringify(this.createTelemetryBlob())), u = window.location.origin;
3389
+ return _context5.abrupt("return", function (e) {
3390
+ var t = e.method,
3391
+ r = e.errorMessage,
3392
+ n = e.finalURL,
3393
+ i = e.basicAuthHeader,
3394
+ o = e.xSDKClientHeader,
3395
+ a = e.xSDKParentHostHeader,
3396
+ c = e.body,
3397
+ u = e.retryCallback;
3398
+ return k(this, void 0, void 0, s().mark(function e() {
3399
+ var l;
3400
+ return s().wrap(function (e) {
3401
+ for (;;) switch (e.prev = e.next) {
3402
+ case 0:
3403
+ return l = {
3404
+ method: t,
3405
+ errorMessage: r,
3406
+ finalURL: n,
3407
+ basicAuthHeader: i,
3408
+ xSDKClientHeader: o,
3409
+ xSDKParentHostHeader: a,
3410
+ body: c
3411
+ }, e.prev = 1, e.next = 4, Ne(l);
3412
+ case 4:
3413
+ case 15:
3414
+ return e.abrupt("return", e.sent);
3415
+ case 7:
3416
+ if (e.prev = 7, e.t0 = e["catch"](1), !(e.t0 instanceof Me)) {
3417
+ e.next = 16;
3418
+ break;
3419
+ }
3420
+ return e.next = 12, u(e.t0, l);
3421
+ case 12:
3422
+ return l = e.sent, e.next = 15, Ne(l);
3423
+ case 16:
3424
+ throw e.t0;
3425
+ case 17:
3426
+ case "end":
3427
+ return e.stop();
3428
+ }
3429
+ }, e, null, [[1, 7]]);
3430
+ }));
3431
+ }({
3432
+ basicAuthHeader: a,
3433
+ body: t,
3434
+ errorMessage: r,
3435
+ finalURL: this.buildSDKUrl(e),
3436
+ method: n,
3437
+ xSDKClientHeader: c,
3438
+ xSDKParentHostHeader: u,
3439
+ retryCallback: i
3440
+ }));
3441
+ case 2:
3442
+ case "end":
3443
+ return _context5.stop();
3444
+ }
3445
+ }, _callee5, this);
3446
+ }));
3447
+ }
3448
+ }, {
3449
+ key: "buildSDKUrl",
3450
+ value: function buildSDKUrl(e) {
3451
+ return "".concat(this.baseURL, "/sdk/v1").concat(e);
3452
+ }
3453
+ }]);
3454
+ return kt;
3455
+ }();
3456
+ var wt = /*#__PURE__*/function () {
3457
+ function wt(e, t, r) {
3458
+ _classCallCheck(this, wt);
3459
+ this._googleClient = e, this._publicToken = t, this._clientId = r;
3460
+ }
3461
+ _createClass(wt, [{
3462
+ key: "cancel",
3463
+ value: function cancel() {
3464
+ this._googleClient.cancel();
3465
+ }
3466
+ }, {
3467
+ key: "render",
3468
+ value: function render(_ref4) {
3469
+ var e = _ref4.callback,
3470
+ t = _ref4.onOneTapCancelled,
3471
+ r = _ref4.style;
3472
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
3473
+ var _this5 = this;
3474
+ var n;
3475
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
3476
+ while (1) switch (_context6.prev = _context6.next) {
3477
+ case 0:
3478
+ n = {
3479
+ client_id: this._clientId,
3480
+ callback: e,
3481
+ auto_select: !1,
3482
+ context: "use",
3483
+ itp_support: !0
3484
+ };
3485
+ return _context6.abrupt("return", (r.position === at.embedded && (n.prompt_parent_id = "google-parent-prompt", n.cancel_on_tap_outside = !1), this._googleClient.initialize(n), new Promise(function (e) {
3486
+ _this5._googleClient.prompt(function (n) {
3487
+ return n.isSkippedMoment() ? ("user_cancel" === n.getSkippedReason() && (null == t || t()), e({
3488
+ success: !1,
3489
+ reason: n.getSkippedReason()
3490
+ })) : n.isNotDisplayed() ? e({
3491
+ success: !1,
3492
+ reason: n.getNotDisplayedReason()
3493
+ }) : (_this5.styleFrame(r), e({
3494
+ success: !0
3495
+ }));
3496
+ });
3497
+ })));
3498
+ case 2:
3499
+ case "end":
3500
+ return _context6.stop();
3501
+ }
3502
+ }, _callee6, this);
3503
+ }));
3504
+ }
3505
+ }, {
3506
+ key: "styleFrame",
3507
+ value: function styleFrame(e) {
3508
+ e.position === at.embedded && Array.from(document.getElementsByTagName("iframe")).forEach(function (e) {
3509
+ e.src.includes(y) && (e.style.width = "100%");
3510
+ });
3511
+ }
3512
+ }]);
3513
+ return wt;
3514
+ }();
3515
+ var St = /*#__PURE__*/function () {
3516
+ function St(e, t) {
3517
+ var _this6 = this;
3518
+ _classCallCheck(this, St);
3519
+ this._publicToken = e, this.clientsideServices = t, this.createOnSuccessHandler = function (_ref5) {
3520
+ var e = _ref5.loginRedirectUrl,
3521
+ t = _ref5.signupRedirectUrl,
3522
+ r = _ref5.onSuccess;
3523
+ return function (n) {
3524
+ return We(_this6, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
3525
+ var i, _yield$this$submitGoo, s;
3526
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
3527
+ while (1) switch (_context7.prev = _context7.next) {
3528
+ case 0:
3529
+ i = n.credential;
3530
+ _context7.next = 3;
3531
+ return this.submitGoogleOneTapToken({
3532
+ credential: i,
3533
+ loginRedirectUrl: e,
3534
+ signupRedirectUrl: t
3535
+ });
3536
+ case 3:
3537
+ _yield$this$submitGoo = _context7.sent;
3538
+ s = _yield$this$submitGoo.redirect_url;
3539
+ r(s);
3540
+ case 6:
3541
+ case "end":
3542
+ return _context7.stop();
3543
+ }
3544
+ }, _callee7, this);
3545
+ }));
3546
+ };
3547
+ }, this.RedirectOnSuccess = function (e) {
3548
+ window.location.href = e;
3549
+ };
3550
+ }
3551
+ _createClass(St, [{
3552
+ key: "createOneTapClient",
3553
+ value: function createOneTapClient() {
3554
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
3555
+ var e, _yield$this$fetchGoog;
3556
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
3557
+ while (1) switch (_context8.prev = _context8.next) {
3558
+ case 0:
3559
+ _context8.prev = 0;
3560
+ _context8.next = 3;
3561
+ return this.fetchGoogleStart();
3562
+ case 3:
3563
+ _yield$this$fetchGoog = _context8.sent;
3564
+ e = _yield$this$fetchGoog.googleClientId;
3565
+ _context8.next = 10;
3566
+ break;
3567
+ case 7:
3568
+ _context8.prev = 7;
3569
+ _context8.t0 = _context8["catch"](0);
3570
+ return _context8.abrupt("return", {
3571
+ success: !1,
3572
+ reason: _context8.t0.error_type
3573
+ });
3574
+ case 10:
3575
+ if (!("" === e)) {
3576
+ _context8.next = 12;
3577
+ break;
3578
+ }
3579
+ return _context8.abrupt("return", {
3580
+ success: !1,
3581
+ reason: "oauth_config_not_found"
3582
+ });
3583
+ case 12:
3584
+ _context8.t1 = !0;
3585
+ _context8.t2 = wt;
3586
+ _context8.next = 16;
3587
+ return H(g, function () {
3588
+ return window.google.accounts.id;
3589
+ });
3590
+ case 16:
3591
+ _context8.t3 = _context8.sent;
3592
+ _context8.t4 = this._publicToken;
3593
+ _context8.t5 = e;
3594
+ _context8.t6 = new _context8.t2(_context8.t3, _context8.t4, _context8.t5);
3595
+ return _context8.abrupt("return", {
3596
+ success: _context8.t1,
3597
+ client: _context8.t6
3598
+ });
3599
+ case 21:
3600
+ case "end":
3601
+ return _context8.stop();
3602
+ }
3603
+ }, _callee8, this, [[0, 7]]);
3604
+ }));
3605
+ }
3606
+ }, {
3607
+ key: "fetchGoogleStart",
3608
+ value: function fetchGoogleStart() {
3609
+ return this.googleConfig || (this.googleConfig = this.clientsideServices.oneTapStart({
3610
+ publicToken: this._publicToken
3611
+ })), this.googleConfig;
3612
+ }
3613
+ }, {
3614
+ key: "submitGoogleOneTapToken",
3615
+ value: function submitGoogleOneTapToken(_ref6) {
3616
+ var e = _ref6.credential,
3617
+ t = _ref6.loginRedirectUrl,
3618
+ r = _ref6.signupRedirectUrl;
3619
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
3620
+ var _yield$this$fetchGoog2, n;
3621
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
3622
+ while (1) switch (_context9.prev = _context9.next) {
3623
+ case 0:
3624
+ _context9.next = 2;
3625
+ return this.fetchGoogleStart();
3626
+ case 2:
3627
+ _yield$this$fetchGoog2 = _context9.sent;
3628
+ n = _yield$this$fetchGoog2.oauthCallbackId;
3629
+ return _context9.abrupt("return", this.clientsideServices.oneTapSubmit({
3630
+ publicToken: this._publicToken,
3631
+ idToken: e,
3632
+ loginRedirectURL: t,
3633
+ oauthCallbackID: n,
3634
+ signupRedirectURL: r
3635
+ }));
3636
+ case 5:
3637
+ case "end":
3638
+ return _context9.stop();
3639
+ }
3640
+ }, _callee9, this);
3641
+ }));
3642
+ }
3643
+ }], [{
3644
+ key: "WillGoogleOneTapShowBannerForUA",
3645
+ value: function WillGoogleOneTapShowBannerForUA(e) {
3646
+ var t = function t(e, _t2) {
3647
+ return -1 !== e.indexOf(_t2);
3648
+ },
3649
+ r = t(e, "iPad") || t(e, "Android") && !t(e, "Mobile") || t(e, "Silk"),
3650
+ n = t(e, "iPod") || t(e, "iPhone") || t(e, "Android") || t(e, "IEMobile");
3651
+ return !r && n;
3652
+ }
3653
+ }, {
3654
+ key: "WillGoogleOneTapShowEmbedded",
3655
+ value: function WillGoogleOneTapShowEmbedded() {
3656
+ return !St.WillGoogleOneTapShowBannerForUA(navigator.userAgent);
3657
+ }
3658
+ }]);
3659
+ return St;
3660
+ }();
3661
+ function Tt(e) {
3662
+ var t = e.toString(16);
3663
+ return 1 === t.length && (t = "0" + t), t;
3664
+ }
3665
+ var Ot = /*#__PURE__*/function () {
3666
+ function Ot(e, t) {
3667
+ _classCallCheck(this, Ot);
3668
+ this._dataLayer = e, this.namespace = t;
3669
+ }
3670
+ _createClass(Ot, [{
3671
+ key: "key",
3672
+ value: function key() {
3673
+ return "PKCE_VERIFIER:" + this.namespace;
3674
+ }
3675
+ }, {
3676
+ key: "startPKCETransaction",
3677
+ value: function startPKCETransaction() {
3678
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
3679
+ var e;
3680
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
3681
+ while (1) switch (_context10.prev = _context10.next) {
3682
+ case 0:
3683
+ _context10.next = 2;
3684
+ return Ot.createProofkeyPair();
3685
+ case 2:
3686
+ e = _context10.sent;
3687
+ return _context10.abrupt("return", (this._dataLayer.setItem(this.key(), JSON.stringify(e)), e));
3688
+ case 4:
3689
+ case "end":
3690
+ return _context10.stop();
3691
+ }
3692
+ }, _callee10, this);
3693
+ }));
3694
+ }
3695
+ }, {
3696
+ key: "getPKPair",
3697
+ value: function getPKPair() {
3698
+ var e = this._dataLayer.getItem(this.key());
3699
+ if (null !== e) try {
3700
+ return JSON.parse(e);
3701
+ } catch (e) {
3702
+ return void J("Found malformed Proof Key pair in localstorage.");
3703
+ }
3704
+ }
3705
+ }, {
3706
+ key: "clearPKPair",
3707
+ value: function clearPKPair() {
3708
+ return this._dataLayer.removeItem(this.key());
3709
+ }
3710
+ }], [{
3711
+ key: "createProofkeyPair",
3712
+ value: function createProofkeyPair() {
3713
+ return We(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
3714
+ var _String$fromCharCode;
3715
+ var e, t, r, n;
3716
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
3717
+ while (1) switch (_context11.prev = _context11.next) {
3718
+ case 0:
3719
+ e = new Uint32Array(16);
3720
+ window.crypto.getRandomValues(e);
3721
+ t = Array.from(e).map(Tt).join("");
3722
+ _context11.next = 5;
3723
+ return window.crypto.subtle.digest("SHA-256", new TextEncoder().encode(t));
3724
+ case 5:
3725
+ r = _context11.sent;
3726
+ return _context11.abrupt("return", {
3727
+ code_challenge: (n = r, btoa((_String$fromCharCode = String.fromCharCode).call.apply(_String$fromCharCode, [null].concat(_toConsumableArray(new Uint8Array(n))))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")),
3728
+ code_verifier: t
3729
+ });
3730
+ case 7:
3731
+ case "end":
3732
+ return _context11.stop();
3733
+ }
3734
+ }, _callee11);
3735
+ }));
3736
+ }
3737
+ }]);
3738
+ return Ot;
3739
+ }();
3740
+ var Ct = /*#__PURE__*/function () {
3741
+ function Ct(e) {
3742
+ _classCallCheck(this, Ct);
3743
+ this._networkClient = e;
3744
+ }
3745
+ _createClass(Ct, [{
3746
+ key: "searchUser",
3747
+ value: function searchUser(e) {
3748
+ return this._networkClient.fetchSDK({
3749
+ url: "/users/search",
3750
+ method: "POST",
3751
+ body: {
3752
+ email: e
3753
+ },
3754
+ errorMessage: "Error searching for user ".concat(e)
3755
+ });
3756
+ }
3757
+ }, {
3758
+ key: "searchOrganization",
3759
+ value: function searchOrganization(e) {
3760
+ return this._networkClient.fetchSDK({
3761
+ url: "/b2b/organizations/search",
3762
+ method: "POST",
3763
+ body: {
3764
+ organization_slug: e
3765
+ },
3766
+ errorMessage: "Error searching slug"
3767
+ });
3768
+ }
3769
+ }, {
3770
+ key: "searchMember",
3771
+ value: function searchMember(e, t) {
3772
+ return this._networkClient.fetchSDK({
3773
+ url: "/b2b/organizations/members/search",
3774
+ method: "POST",
3775
+ body: {
3776
+ email_address: e,
3777
+ organization_id: t
3778
+ },
3779
+ errorMessage: "Error searching for member ".concat(e)
3780
+ });
3781
+ }
3782
+ }]);
3783
+ return Ct;
3784
+ }();
3785
+ var Et = function Et(e) {
3786
+ return (document.cookie ? document.cookie.split("; ") : []).filter(function (t) {
3787
+ var _t$split = t.split("="),
3788
+ _t$split2 = _slicedToArray(_t$split, 1),
3789
+ r = _t$split2[0];
3790
+ return e === r;
3791
+ }).length > 1;
3792
+ };
4
3793
  /*! js-cookie v3.0.1 | MIT */
5
- function Kt(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}var Gt=function e(t,r){function n(e,n,i){if("undefined"!=typeof document){"number"==typeof(i=Kt({},r,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var o="";for(var s in i)i[s]&&(o+="; "+s,!0!==i[s]&&(o+="="+i[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+o}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},i=0;i<r.length;i++){var o=r[i].split("="),s=o.slice(1).join("=");try{var a=decodeURIComponent(o[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",Kt({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,Kt({},this.attributes,t))},withConverter:function(t){return e(Kt({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"}),qt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"".concat("stytch_sdk_state_").concat(e).concat(t?"::".concat(t):"")},Wt=function(){function e(t,r){var n=this;h(this,e),this.browserSessionStorage={getItem:function(e){return sessionStorage.getItem(qt(n.publicToken,e))},setItem:function(e,t){return sessionStorage.setItem(qt(n.publicToken,e),t)},removeItem:function(e){return sessionStorage.removeItem(qt(n.publicToken,e))}},this.publicToken=t,this.state=null,this.subscriptions={},(null==r?void 0:r.cookieOptions)?(pe("SubscriptionDataLayer").isOptionalString("cookieOptions.opaqueTokenCookieName",r.cookieOptions.opaqueTokenCookieName).isOptionalString("cookieOptions.jwtCookieName",r.cookieOptions.jwtCookieName).isOptionalString("cookieOptions.istCookieName",r.cookieOptions.istCookieName).isOptionalString("cookieOptions.path",r.cookieOptions.path),this._jwtCookieName=r.cookieOptions.jwtCookieName||null,this._opaqueTokenCookieName=r.cookieOptions.opaqueTokenCookieName||null,this._cookiePath=r.cookieOptions.path||null,this._cookieAvailableToSubdomains=r.cookieOptions.availableToSubdomains||!1,this._istCookieName=r.cookieOptions.istCookieName||null):(this._opaqueTokenCookieName=null,this._jwtCookieName=null,this._cookiePath=null,this._cookieAvailableToSubdomains=!1,this._istCookieName=null);var i,o=localStorage.getItem(qt(this.publicToken));if(!o)return this.removeSessionCookie(),void this.removeISTCookie();try{i=JSON.parse(o)}catch(e){return this.syncToLocalStorage(),this.removeSessionCookie(),void this.removeISTCookie()}this.state=i}return p(e,[{key:"opaqueTokenCookieName",get:function(){var e;return null!==(e=this._opaqueTokenCookieName)&&void 0!==e?e:"stytch_session"}},{key:"jwtCookieName",get:function(){var e;return null!==(e=this._jwtCookieName)&&void 0!==e?e:"stytch_session_jwt"}},{key:"istCookieName",get:function(){var e;return null!==(e=this._istCookieName)&&void 0!==e?e:"stytch_intermediate_session_token"}},{key:"readSessionCookie",value:function(){return{session_token:Gt.get(this.opaqueTokenCookieName),session_jwt:Gt.get(this.jwtCookieName)}}},{key:"readIntermediateSessionTokenCookie",value:function(){return Gt.get(this.istCookieName)}},{key:"writeSessionCookie",value:function(t){var r,n,i,o,s=t.state,a=t.session_token,c=t.session_jwt,u=e.generateCookieOpts({expiresAt:null!==(n=null===(r=null==s?void 0:s.session)||void 0===r?void 0:r.expires_at)&&void 0!==n?n:"",availableToSubdomains:this._cookieAvailableToSubdomains,path:this._cookiePath});Gt.set(this.opaqueTokenCookieName,a,u),Gt.set(this.jwtCookieName,c,u);var l=e.generateCookieOpts({expiresAt:null!==(o=null===(i=null==s?void 0:s.session)||void 0===i?void 0:i.expires_at)&&void 0!==o?o:"",availableToSubdomains:!this._cookieAvailableToSubdomains,path:this._cookiePath});Ut(this.jwtCookieName)&&Gt.remove(this.jwtCookieName,l),Ut(this.opaqueTokenCookieName)&&Gt.remove(this.opaqueTokenCookieName,l),Ut(this.jwtCookieName)&&le("Could not remove extraneous JWT cookie. This might happen if the cookie has been set using multiple `path` settings, and may produce unwanted behavior."),Ut(this.opaqueTokenCookieName)&&le("Could not remove extraneous opaque token cookie.")}},{key:"writeIntermediateSessionTokenCookie",value:function(t){var r=new Date(Date.now()+6e5),n=e.generateCookieOpts({expiresAt:r.toString(),availableToSubdomains:this._cookieAvailableToSubdomains,path:this._cookiePath});Gt.set(this.istCookieName,t,n)}},{key:"removeSessionCookie",value:function(){this.removeCookies([this.opaqueTokenCookieName,this.jwtCookieName])}},{key:"removeISTCookie",value:function(){this.removeCookies([this.istCookieName])}},{key:"removeCookies",value:function(t){var r=this;[!0,!1].forEach((function(n){[r._cookiePath,null].forEach((function(r){var i=e.generateCookieOpts({expiresAt:new Date(0).toString(),availableToSubdomains:n,path:r});t.forEach((function(e){Gt.remove(e,i)}))}))}))}},{key:"syncToLocalStorage",value:function(){localStorage.setItem(qt(this.publicToken),JSON.stringify(this.state))}},{key:"getItem",value:function(e){return localStorage.getItem(qt(this.publicToken,e))}},{key:"setItem",value:function(e,t){return localStorage.setItem(qt(this.publicToken,e),t)}},{key:"removeItem",value:function(e){return localStorage.removeItem(qt(this.publicToken,e))}}],[{key:"generateCookieOpts",value:function(e){var t=e.path,r=e.availableToSubdomains,n=e.expiresAt,i={expires:new Date(n),sameSite:"lax"};return t&&(i.path=t),Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/))?i.secure=!1:(r&&(i.domain=window.location.host),i.secure=!0),i}}]),e}(),Ht=function(e){i(r,Wt);var t=s(r);function r(){return h(this,r),t.apply(this,arguments)}return p(r)}(),Yt=Symbol.for("__stytch_DataLayer"),zt=function(e,t){var r,n=((r=window)[Yt]||(r[Yt]={}),r[Yt]);return n[e]||(n[e]=new Ht(e,t)),n[e]},Vt=function(e,t){Object.values(e).forEach((function(e){return e(t)}))},Jt=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).KEYS_TO_EXCLUDE,t=void 0===e?[]:e;return function e(r,n){return g(r)===g(n)&&(null===r||null===n?r===n:"object"===g(r)?Object.keys(r).length===Object.keys(n).length&&!Object.keys(r).some((function(e){return!(e in n)}))&&Object.entries(r).filter((function(e){var r=_(e,1)[0];return!t.includes(r)})).every((function(t){var r=_(t,2),i=r[0],o=r[1];return e(o,n[i])})):r===n)}}({KEYS_TO_EXCLUDE:["last_accessed_at"]}),Xt=function(){function e(t,r){var n,i=this;h(this,e),this._publicToken=t,this._datalayer=r,this._listen=function(e){if(e.key===qt(i._publicToken))if(null!==e.newValue&&"null"!==e.newValue){var t=JSON.parse(e.newValue);i.updateState(t)}else i.destroyState()},window.addEventListener("storage",this._listen);var o=null===(n=this._datalayer.state)||void 0===n?void 0:n.session;o&&Date.parse(o.expires_at)<Date.now()?this.destroyState():this._datalayer.readSessionCookie().session_token||this.destroyState()}return p(e,[{key:"getTokens",value:function(){var e=this._datalayer.readSessionCookie(),t=e.session_token,r=e.session_jwt;return"string"!=typeof t||"string"!=typeof r?null:{session_token:t,session_jwt:r}}},{key:"getIntermediateSessionToken",value:function(){return this._datalayer.readIntermediateSessionTokenCookie()||null}},{key:"destroyState",value:function(){this.updateStateAndTokens({state:null,session_token:null,session_jwt:null,intermediate_session_token:null})}},{key:"_updateStateAndTokensInternal",value:function(e){var t=this._datalayer.state,r=null===e.state?null:Object.assign(Object.assign({},this._datalayer.state),e.state);this._datalayer.state=r,Jt(t,r)||Vt(this._datalayer.subscriptions,r)}},{key:"updateStateAndTokens",value:function(e){e.state?(this._datalayer.writeSessionCookie(e),this._datalayer.removeISTCookie()):e.intermediate_session_token?(this._datalayer.writeIntermediateSessionTokenCookie(e.intermediate_session_token),this._datalayer.removeSessionCookie()):(this._datalayer.removeSessionCookie(),this._datalayer.removeISTCookie()),this._updateStateAndTokensInternal(e),this._datalayer.syncToLocalStorage()}},{key:"updateState",value:function(e){var t=this._datalayer.state,r=null===e?null:Object.assign(Object.assign({},this._datalayer.state),e);this._datalayer.state=r,Jt(t,r)||(Vt(this._datalayer.subscriptions,r),this._datalayer.syncToLocalStorage())}},{key:"updateTokens",value:function(e){var t=e.session_token,r=e.session_jwt,n=this._datalayer.readSessionCookie(),i=Object.assign(Object.assign({},n),{session_token:t,session_jwt:r});t||r?(this._datalayer.writeSessionCookie(i),this._datalayer.removeISTCookie()):this._datalayer.removeSessionCookie()}},{key:"subscribeToState",value:function(e){return t=this._datalayer.subscriptions,r=e,n=Math.random().toString(36).slice(-10),t[n]=r,function(){return delete t[n]};var t,r,n}},{key:"getState",value:function(){return this._datalayer.state}},{key:"destroy",value:function(){window.removeEventListener("storage",this._listen)}},{key:"syncFromDeviceStorage",value:function(){return null}}]),e}(),$t=function(e){i(r,Xt);var t=s(r);function r(){var e;return h(this,r),(e=t.apply(this,arguments)).updateUser=function(t){return e.updateState({user:t})},e.getUser=function(){var t,r;return null!==(r=null===(t=e.getState())||void 0===t?void 0:t.user)&&void 0!==r?r:null},e.getSession=function(){var t,r;return null!==(r=null===(t=e.getState())||void 0===t?void 0:t.session)&&void 0!==r?r:null},e}return p(r)}(),Zt=Symbol.for("stytch__internal_b2c"),Qt=function(e,t){Object.assign(e,function(e,t,r){return(t=f(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},Zt,t))},er=p((function e(t,r){var n,i=this;h(this,e),function(e){var t="StytchUIClient"===e?"import { createStytchUIClient } from '@stytch/nextjs/ui';\n \nconst stytch = createStytchUIClient('public-token-...');\n":"import { createStytchHeadlessClient } from '@stytch/nextjs/ui';\n \nconst stytch = createStytchHeadlessClient('public-token-...');\n";if("undefined"==typeof window)throw new Error("The ".concat(e," is not compatible with server-side environments.\nIf using nextjs, use the create").concat(e," method instead.\n```\n").concat(t,"\n```\n"))}("StytchHeadlessClient"),"string"!=typeof(n=t)?le("Public token is malformed. Expected a string, got ".concat(g(n),".").concat(de)):""===n?le('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(de)):n.startsWith("public-token-")||le('Public token is malformed. Expected "public-token-...", got '.concat(n,".").concat(de));var o,s,a,c,u,l,d,p,f,v,_,m=r,y={cookieOptions:null==(o=m)?void 0:o.cookieOptions,endpoints:{sdkBackendURL:null!==(a=null===(s=null==o?void 0:o.endpoints)||void 0===s?void 0:s.sdkBackendURL)&&void 0!==a?a:"https://web.stytch.com",testAPIURL:null!==(u=null===(c=null==o?void 0:o.endpoints)||void 0===c?void 0:c.testAPIURL)&&void 0!==u?u:"https://test.stytch.com",liveAPIURL:null!==(d=null===(l=null==o?void 0:o.endpoints)||void 0===l?void 0:l.liveAPIURL)&&void 0!==d?d:"https://api.stytch.com",dfpBackendURL:null!==(f=null===(p=null==o?void 0:o.endpoints)||void 0===p?void 0:p.dfpBackendURL)&&void 0!==f?f:"https://telemetry.stytch.com",clientsideServicesIframeURL:null!==(_=null===(v=null==o?void 0:o.endpoints)||void 0===v?void 0:v.clientsideServicesIframeURL)&&void 0!==_?_:"https://js.stytch.com/clientside-services/index.html"}};this._dataLayer=zt(t,m),this._subscriptionService=new $t(t,this._dataLayer);this._networkClient=new Bt(t,this._dataLayer,y.endpoints.sdkBackendURL,(function(){var e,t,r,n;return{stytch_user_id:null===(t=null===(e=i._dataLayer.state)||void 0===e?void 0:e.user)||void 0===t?void 0:t.user_id,stytch_session_id:null===(n=null===(r=i._dataLayer.state)||void 0===r?void 0:r.session)||void 0===n?void 0:n.session_id}}));var b=new tt(t,this._networkClient,this._dataLayer),w=new ut(b.getAsync()),k=new _e(t,y.endpoints.dfpBackendURL,b.getAsync()),S=new lt(y.endpoints.clientsideServicesIframeURL),O=new Dt(t,S),T=new Ft(this._networkClient);this.user=new ge(this._networkClient,this._subscriptionService),this.session=new be(this._networkClient,this._subscriptionService),this.magicLinks=new ke(this._networkClient,this._subscriptionService,new Mt(this._dataLayer,"magic_links"),b.getAsync(),w.executeRecaptcha,k),this.otps=new Se(this._networkClient,this._subscriptionService,w.executeRecaptcha),this.oauth=new It(this._networkClient,this._subscriptionService,new Mt(this._dataLayer,"oauth"),b.getAsync(),{publicToken:t,testAPIURL:y.endpoints.testAPIURL,liveAPIURL:y.endpoints.liveAPIURL},O),this.cryptoWallets=new Te(this._networkClient,this._subscriptionService,w.executeRecaptcha),this.totps=new Ee(this._networkClient,this._subscriptionService),this.webauthn=new Ve(this._networkClient,this._subscriptionService),this.passwords=new Xe(this._networkClient,this._subscriptionService,new Mt(this._dataLayer,"passwords"),b.getAsync(),w.executeRecaptcha,k),this._sessionManager=new Qe(this._subscriptionService,this.session),this._dataLayer.readSessionCookie().session_token&&this._sessionManager.performBackgroundRefresh(),this._networkClient.logEvent({name:"sdk_instance_instantiated",details:{event_callback_registered:!1,error_callback_registered:!1,success_callback_registered:!1}}),Qt(this,{bootstrap:b,clientsideServices:S,captcha:w,oneTap:O,searchManager:T,publicToken:t,dataLayer:this._dataLayer,networkClient:this._networkClient})}));export{Tt as AuthFlowType,Et as B2BOAuthProviders,Ot as B2BProducts,St as BiometricsErrors,it as OAuthProviders,at as OTPMethods,st as OneTapPositions,nt as Products,xt as SDKAPIUnreachableError,ct as StytchEventType,er as StytchHeadlessClient,Pt as StytchSDKAPIError,Rt as StytchSDKNativeError,At as StytchSDKSchemaError,Ct as StytchSDKUsageError,Lt as UNRECOVERABLE_ERROR_TYPES,ot as Wallets};
3794
+ function xt(e) {
3795
+ for (var t = 1; t < arguments.length; t++) {
3796
+ var r = arguments[t];
3797
+ for (var n in r) e[n] = r[n];
3798
+ }
3799
+ return e;
3800
+ }
3801
+ var At = function e(t, r) {
3802
+ function n(e, n, i) {
3803
+ if ("undefined" != typeof document) {
3804
+ "number" == typeof (i = xt({}, r, i)).expires && (i.expires = new Date(Date.now() + 864e5 * i.expires)), i.expires && (i.expires = i.expires.toUTCString()), e = encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
3805
+ var s = "";
3806
+ for (var o in i) i[o] && (s += "; " + o, !0 !== i[o] && (s += "=" + i[o].split(";")[0]));
3807
+ return document.cookie = e + "=" + t.write(n, e) + s;
3808
+ }
3809
+ }
3810
+ return Object.create({
3811
+ set: n,
3812
+ get: function get(e) {
3813
+ if ("undefined" != typeof document && (!arguments.length || e)) {
3814
+ for (var r = document.cookie ? document.cookie.split("; ") : [], n = {}, i = 0; i < r.length; i++) {
3815
+ var s = r[i].split("="),
3816
+ o = s.slice(1).join("=");
3817
+ try {
3818
+ var a = decodeURIComponent(s[0]);
3819
+ if (n[a] = t.read(o, a), e === a) break;
3820
+ } catch (e) {}
3821
+ }
3822
+ return e ? n[e] : n;
3823
+ }
3824
+ },
3825
+ remove: function remove(e, t) {
3826
+ n(e, "", xt({}, t, {
3827
+ expires: -1
3828
+ }));
3829
+ },
3830
+ withAttributes: function withAttributes(t) {
3831
+ return e(this.converter, xt({}, this.attributes, t));
3832
+ },
3833
+ withConverter: function withConverter(t) {
3834
+ return e(xt({}, this.converter, t), this.attributes);
3835
+ }
3836
+ }, {
3837
+ attributes: {
3838
+ value: Object.freeze(r)
3839
+ },
3840
+ converter: {
3841
+ value: Object.freeze(t)
3842
+ }
3843
+ });
3844
+ }({
3845
+ read: function read(e) {
3846
+ return '"' === e[0] && (e = e.slice(1, -1)), e.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
3847
+ },
3848
+ write: function write(e) {
3849
+ return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
3850
+ }
3851
+ }, {
3852
+ path: "/"
3853
+ });
3854
+ var Pt = function Pt(e) {
3855
+ var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
3856
+ return "stytch_sdk_state_".concat(e).concat(t ? "::".concat(t) : "");
3857
+ };
3858
+ var Rt = /*#__PURE__*/function () {
3859
+ function Rt(e, t) {
3860
+ var _this7 = this;
3861
+ _classCallCheck(this, Rt);
3862
+ this.browserSessionStorage = {
3863
+ getItem: function getItem(e) {
3864
+ return sessionStorage.getItem(Pt(_this7.publicToken, e));
3865
+ },
3866
+ setItem: function setItem(e, t) {
3867
+ return sessionStorage.setItem(Pt(_this7.publicToken, e), t);
3868
+ },
3869
+ removeItem: function removeItem(e) {
3870
+ return sessionStorage.removeItem(Pt(_this7.publicToken, e));
3871
+ }
3872
+ }, this.publicToken = e, this.state = null, this.subscriptions = {}, (null == t ? void 0 : t.cookieOptions) ? (Z("SubscriptionDataLayer").isOptionalString("cookieOptions.opaqueTokenCookieName", t.cookieOptions.opaqueTokenCookieName).isOptionalString("cookieOptions.jwtCookieName", t.cookieOptions.jwtCookieName).isOptionalString("cookieOptions.istCookieName", t.cookieOptions.istCookieName).isOptionalString("cookieOptions.path", t.cookieOptions.path), this._jwtCookieName = t.cookieOptions.jwtCookieName || null, this._opaqueTokenCookieName = t.cookieOptions.opaqueTokenCookieName || null, this._cookiePath = t.cookieOptions.path || null, this._cookieAvailableToSubdomains = t.cookieOptions.availableToSubdomains || !1, this._istCookieName = t.cookieOptions.istCookieName || null) : (this._opaqueTokenCookieName = null, this._jwtCookieName = null, this._cookiePath = null, this._cookieAvailableToSubdomains = !1, this._istCookieName = null);
3873
+ var r = localStorage.getItem(Pt(this.publicToken));
3874
+ if (!r) return this.removeSessionCookie(), void this.removeISTCookie();
3875
+ var n;
3876
+ try {
3877
+ n = JSON.parse(r);
3878
+ } catch (e) {
3879
+ return this.syncToLocalStorage(), this.removeSessionCookie(), void this.removeISTCookie();
3880
+ }
3881
+ this.state = n;
3882
+ }
3883
+ _createClass(Rt, [{
3884
+ key: "opaqueTokenCookieName",
3885
+ get: function get() {
3886
+ var e;
3887
+ return null !== (e = this._opaqueTokenCookieName) && void 0 !== e ? e : "stytch_session";
3888
+ }
3889
+ }, {
3890
+ key: "jwtCookieName",
3891
+ get: function get() {
3892
+ var e;
3893
+ return null !== (e = this._jwtCookieName) && void 0 !== e ? e : "stytch_session_jwt";
3894
+ }
3895
+ }, {
3896
+ key: "istCookieName",
3897
+ get: function get() {
3898
+ var e;
3899
+ return null !== (e = this._istCookieName) && void 0 !== e ? e : "stytch_intermediate_session_token";
3900
+ }
3901
+ }, {
3902
+ key: "readSessionCookie",
3903
+ value: function readSessionCookie() {
3904
+ return {
3905
+ session_token: At.get(this.opaqueTokenCookieName),
3906
+ session_jwt: At.get(this.jwtCookieName)
3907
+ };
3908
+ }
3909
+ }, {
3910
+ key: "readIntermediateSessionTokenCookie",
3911
+ value: function readIntermediateSessionTokenCookie() {
3912
+ return At.get(this.istCookieName);
3913
+ }
3914
+ }, {
3915
+ key: "writeSessionCookie",
3916
+ value: function writeSessionCookie(e) {
3917
+ var t, r, n, i;
3918
+ var s = e.state,
3919
+ o = e.session_token,
3920
+ a = e.session_jwt,
3921
+ c = Rt.generateCookieOpts({
3922
+ expiresAt: null !== (r = null === (t = null == s ? void 0 : s.session) || void 0 === t ? void 0 : t.expires_at) && void 0 !== r ? r : "",
3923
+ availableToSubdomains: this._cookieAvailableToSubdomains,
3924
+ path: this._cookiePath
3925
+ });
3926
+ At.set(this.opaqueTokenCookieName, o, c), At.set(this.jwtCookieName, a, c);
3927
+ var u = Rt.generateCookieOpts({
3928
+ expiresAt: null !== (i = null === (n = null == s ? void 0 : s.session) || void 0 === n ? void 0 : n.expires_at) && void 0 !== i ? i : "",
3929
+ availableToSubdomains: !this._cookieAvailableToSubdomains,
3930
+ path: this._cookiePath
3931
+ });
3932
+ Et(this.jwtCookieName) && At.remove(this.jwtCookieName, u), Et(this.opaqueTokenCookieName) && At.remove(this.opaqueTokenCookieName, u), Et(this.jwtCookieName) && J("Could not remove extraneous JWT cookie. This might happen if the cookie has been set using multiple `path` settings, and may produce unwanted behavior."), Et(this.opaqueTokenCookieName) && J("Could not remove extraneous opaque token cookie.");
3933
+ }
3934
+ }, {
3935
+ key: "writeIntermediateSessionTokenCookie",
3936
+ value: function writeIntermediateSessionTokenCookie(e) {
3937
+ var t = new Date(Date.now() + 6e5),
3938
+ r = Rt.generateCookieOpts({
3939
+ expiresAt: t.toString(),
3940
+ availableToSubdomains: this._cookieAvailableToSubdomains,
3941
+ path: this._cookiePath
3942
+ });
3943
+ At.set(this.istCookieName, e, r);
3944
+ }
3945
+ }, {
3946
+ key: "removeSessionCookie",
3947
+ value: function removeSessionCookie() {
3948
+ this.removeCookies([this.opaqueTokenCookieName, this.jwtCookieName]);
3949
+ }
3950
+ }, {
3951
+ key: "removeISTCookie",
3952
+ value: function removeISTCookie() {
3953
+ this.removeCookies([this.istCookieName]);
3954
+ }
3955
+ }, {
3956
+ key: "removeCookies",
3957
+ value: function removeCookies(e) {
3958
+ var _this8 = this;
3959
+ [!0, !1].forEach(function (t) {
3960
+ [_this8._cookiePath, null].forEach(function (r) {
3961
+ var n = Rt.generateCookieOpts({
3962
+ expiresAt: new Date(0).toString(),
3963
+ availableToSubdomains: t,
3964
+ path: r
3965
+ });
3966
+ e.forEach(function (e) {
3967
+ At.remove(e, n);
3968
+ });
3969
+ });
3970
+ });
3971
+ }
3972
+ }, {
3973
+ key: "syncToLocalStorage",
3974
+ value: function syncToLocalStorage() {
3975
+ localStorage.setItem(Pt(this.publicToken), JSON.stringify(this.state));
3976
+ }
3977
+ }, {
3978
+ key: "getItem",
3979
+ value: function getItem(e) {
3980
+ return localStorage.getItem(Pt(this.publicToken, e));
3981
+ }
3982
+ }, {
3983
+ key: "setItem",
3984
+ value: function setItem(e, t) {
3985
+ return localStorage.setItem(Pt(this.publicToken, e), t);
3986
+ }
3987
+ }, {
3988
+ key: "removeItem",
3989
+ value: function removeItem(e) {
3990
+ return localStorage.removeItem(Pt(this.publicToken, e));
3991
+ }
3992
+ }], [{
3993
+ key: "generateCookieOpts",
3994
+ value: function generateCookieOpts(_ref7) {
3995
+ var e = _ref7.path,
3996
+ t = _ref7.availableToSubdomains,
3997
+ r = _ref7.expiresAt;
3998
+ var n = {
3999
+ expires: new Date(r),
4000
+ sameSite: "lax"
4001
+ };
4002
+ return e && (n.path = e), Boolean("localhost" === window.location.hostname || "[::1]" === window.location.hostname || window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)) ? n.secure = !1 : (t && (n.domain = window.location.host), n.secure = !0), n;
4003
+ }
4004
+ }]);
4005
+ return Rt;
4006
+ }();
4007
+ var Dt = /*#__PURE__*/function (_Rt) {
4008
+ _inherits(Dt, _Rt);
4009
+ var _super2 = _createSuper(Dt);
4010
+ function Dt() {
4011
+ _classCallCheck(this, Dt);
4012
+ return _super2.apply(this, arguments);
4013
+ }
4014
+ return _createClass(Dt);
4015
+ }(Rt);
4016
+ var Bt = Symbol["for"]("__stytch_DataLayer"),
4017
+ It = function It(e, t) {
4018
+ var r = function () {
4019
+ var e = window;
4020
+ return e[Bt] || (e[Bt] = {}), e[Bt];
4021
+ }();
4022
+ return r[e] || (r[e] = new Dt(e, t)), r[e];
4023
+ },
4024
+ Lt = function Lt(e, t) {
4025
+ Object.values(e).forEach(function (e) {
4026
+ return e(t);
4027
+ });
4028
+ },
4029
+ jt = function () {
4030
+ var e = (arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {}).KEYS_TO_EXCLUDE,
4031
+ r = void 0 === e ? [] : e;
4032
+ return function e(n, s) {
4033
+ return i(n) === i(s) && (null === n || null === s ? n === s : "object" === i(n) ? Object.keys(n).length === Object.keys(s).length && !Object.keys(n).some(function (e) {
4034
+ return !(e in s);
4035
+ }) && Object.entries(n).filter(function (e) {
4036
+ var n = t(e, 1)[0];
4037
+ return !r.includes(n);
4038
+ }).every(function (r) {
4039
+ var n = t(r, 2),
4040
+ i = n[0],
4041
+ o = n[1];
4042
+ return e(o, s[i]);
4043
+ }) : n === s);
4044
+ };
4045
+ }({
4046
+ KEYS_TO_EXCLUDE: ["last_accessed_at"]
4047
+ });
4048
+ var Mt = /*#__PURE__*/function () {
4049
+ function Mt(e, t) {
4050
+ var _this9 = this;
4051
+ _classCallCheck(this, Mt);
4052
+ var r;
4053
+ this._publicToken = e, this._datalayer = t, this._listen = function (e) {
4054
+ if (e.key !== Pt(_this9._publicToken)) return;
4055
+ if (null === e.newValue || "null" === e.newValue) return void _this9.destroyState();
4056
+ var t = JSON.parse(e.newValue);
4057
+ _this9.updateState(t);
4058
+ }, window.addEventListener("storage", this._listen);
4059
+ var n = null === (r = this._datalayer.state) || void 0 === r ? void 0 : r.session;
4060
+ if (n && Date.parse(n.expires_at) < Date.now()) return void this.destroyState();
4061
+ var _this$_datalayer$read = this._datalayer.readSessionCookie(),
4062
+ i = _this$_datalayer$read.session_token;
4063
+ i || this.destroyState();
4064
+ }
4065
+ _createClass(Mt, [{
4066
+ key: "getTokens",
4067
+ value: function getTokens() {
4068
+ var _this$_datalayer$read2 = this._datalayer.readSessionCookie(),
4069
+ e = _this$_datalayer$read2.session_token,
4070
+ t = _this$_datalayer$read2.session_jwt;
4071
+ return "string" != typeof e || "string" != typeof t ? null : {
4072
+ session_token: e,
4073
+ session_jwt: t
4074
+ };
4075
+ }
4076
+ }, {
4077
+ key: "getIntermediateSessionToken",
4078
+ value: function getIntermediateSessionToken() {
4079
+ return this._datalayer.readIntermediateSessionTokenCookie() || null;
4080
+ }
4081
+ }, {
4082
+ key: "destroyState",
4083
+ value: function destroyState() {
4084
+ this.updateStateAndTokens({
4085
+ state: null,
4086
+ session_token: null,
4087
+ session_jwt: null,
4088
+ intermediate_session_token: null
4089
+ });
4090
+ }
4091
+ }, {
4092
+ key: "_updateStateAndTokensInternal",
4093
+ value: function _updateStateAndTokensInternal(e) {
4094
+ var t = this._datalayer.state,
4095
+ r = null === e.state ? null : Object.assign(Object.assign({}, this._datalayer.state), e.state);
4096
+ this._datalayer.state = r, jt(t, r) || Lt(this._datalayer.subscriptions, r);
4097
+ }
4098
+ }, {
4099
+ key: "updateStateAndTokens",
4100
+ value: function updateStateAndTokens(e) {
4101
+ e.state ? (this._datalayer.writeSessionCookie(e), this._datalayer.removeISTCookie()) : e.intermediate_session_token ? (this._datalayer.writeIntermediateSessionTokenCookie(e.intermediate_session_token), this._datalayer.removeSessionCookie()) : (this._datalayer.removeSessionCookie(), this._datalayer.removeISTCookie()), this._updateStateAndTokensInternal(e), this._datalayer.syncToLocalStorage();
4102
+ }
4103
+ }, {
4104
+ key: "updateState",
4105
+ value: function updateState(e) {
4106
+ var t = this._datalayer.state,
4107
+ r = null === e ? null : Object.assign(Object.assign({}, this._datalayer.state), e);
4108
+ this._datalayer.state = r, jt(t, r) || (Lt(this._datalayer.subscriptions, r), this._datalayer.syncToLocalStorage());
4109
+ }
4110
+ }, {
4111
+ key: "updateTokens",
4112
+ value: function updateTokens(e) {
4113
+ var t = e.session_token,
4114
+ r = e.session_jwt,
4115
+ n = this._datalayer.readSessionCookie(),
4116
+ i = Object.assign(Object.assign({}, n), {
4117
+ session_token: t,
4118
+ session_jwt: r
4119
+ });
4120
+ t || r ? (this._datalayer.writeSessionCookie(i), this._datalayer.removeISTCookie()) : this._datalayer.removeSessionCookie();
4121
+ }
4122
+ }, {
4123
+ key: "subscribeToState",
4124
+ value: function subscribeToState(e) {
4125
+ return function (e, t) {
4126
+ var r = Math.random().toString(36).slice(-10);
4127
+ return e[r] = t, function () {
4128
+ return delete e[r];
4129
+ };
4130
+ }(this._datalayer.subscriptions, e);
4131
+ }
4132
+ }, {
4133
+ key: "getState",
4134
+ value: function getState() {
4135
+ return this._datalayer.state;
4136
+ }
4137
+ }, {
4138
+ key: "destroy",
4139
+ value: function destroy() {
4140
+ window.removeEventListener("storage", this._listen);
4141
+ }
4142
+ }, {
4143
+ key: "syncFromDeviceStorage",
4144
+ value: function syncFromDeviceStorage() {
4145
+ return null;
4146
+ }
4147
+ }]);
4148
+ return Mt;
4149
+ }();
4150
+ var Nt = /*#__PURE__*/function (_Mt) {
4151
+ _inherits(Nt, _Mt);
4152
+ var _super3 = _createSuper(Nt);
4153
+ function Nt() {
4154
+ var _this10;
4155
+ _classCallCheck(this, Nt);
4156
+ _this10 = _super3.apply(this, arguments), _this10.updateUser = function (e) {
4157
+ return _this10.updateState({
4158
+ user: e
4159
+ });
4160
+ }, _this10.getUser = function () {
4161
+ var e, t;
4162
+ return null !== (t = null === (e = _this10.getState()) || void 0 === e ? void 0 : e.user) && void 0 !== t ? t : null;
4163
+ }, _this10.getSession = function () {
4164
+ var e, t;
4165
+ return null !== (t = null === (e = _this10.getState()) || void 0 === e ? void 0 : e.session) && void 0 !== t ? t : null;
4166
+ };
4167
+ return _this10;
4168
+ }
4169
+ return _createClass(Nt);
4170
+ }(Mt);
4171
+ var Ft = Symbol["for"]("stytch__internal_b2c");
4172
+ var Ut = /*#__PURE__*/_createClass(function Ut(e, t) {
4173
+ var _this11 = this;
4174
+ _classCallCheck(this, Ut);
4175
+ var r;
4176
+ !function (e) {
4177
+ var t = "StytchUIClient" === e ? "import { createStytchUIClient } from '@stytch/nextjs/ui';\n \nconst stytch = createStytchUIClient('public-token-...');\n" : "import { createStytchHeadlessClient } from '@stytch/nextjs/ui';\n \nconst stytch = createStytchHeadlessClient('public-token-...');\n";
4178
+ if ("undefined" == typeof window) throw new Error("The ".concat(e, " is not compatible with server-side environments.\nIf using nextjs, use the create").concat(e, " method instead.\n```\n").concat(t, "\n```\n"));
4179
+ }("StytchHeadlessClient"), "string" != typeof (r = e) ? J("Public token is malformed. Expected a string, got ".concat(i(r), ".").concat(X)) : "" === r ? J('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(X)) : r.startsWith("public-token-") || J('Public token is malformed. Expected "public-token-...", got '.concat(r, ".").concat(X));
4180
+ var n = t,
4181
+ s = {
4182
+ cookieOptions: null == (o = n) ? void 0 : o.cookieOptions,
4183
+ endpoints: {
4184
+ sdkBackendURL: null !== (c = null === (a = null == o ? void 0 : o.endpoints) || void 0 === a ? void 0 : a.sdkBackendURL) && void 0 !== c ? c : "https://web.stytch.com",
4185
+ testAPIURL: null !== (l = null === (u = null == o ? void 0 : o.endpoints) || void 0 === u ? void 0 : u.testAPIURL) && void 0 !== l ? l : "https://test.stytch.com",
4186
+ liveAPIURL: null !== (h = null === (d = null == o ? void 0 : o.endpoints) || void 0 === d ? void 0 : d.liveAPIURL) && void 0 !== h ? h : "https://api.stytch.com",
4187
+ dfpBackendURL: null !== (f = null === (p = null == o ? void 0 : o.endpoints) || void 0 === p ? void 0 : p.dfpBackendURL) && void 0 !== f ? f : "https://telemetry.stytch.com",
4188
+ clientsideServicesIframeURL: null !== (v = null === (_ = null == o ? void 0 : o.endpoints) || void 0 === _ ? void 0 : _.clientsideServicesIframeURL) && void 0 !== v ? v : "https://js.stytch.com/clientside-services/index.html"
4189
+ }
4190
+ };
4191
+ var o, a, c, u, l, d, h, p, f, _, v;
4192
+ this._dataLayer = It(e, n), this._subscriptionService = new Nt(e, this._dataLayer);
4193
+ this._networkClient = new kt(e, this._dataLayer, s.endpoints.sdkBackendURL, function () {
4194
+ var e, t, r, n;
4195
+ return {
4196
+ stytch_user_id: null === (t = null === (e = _this11._dataLayer.state) || void 0 === e ? void 0 : e.user) || void 0 === t ? void 0 : t.user_id,
4197
+ stytch_session_id: null === (n = null === (r = _this11._dataLayer.state) || void 0 === r ? void 0 : r.session) || void 0 === n ? void 0 : n.session_id
4198
+ };
4199
+ });
4200
+ var m = new qe(e, this._networkClient, this._dataLayer),
4201
+ y = new Ge(m.getAsync()),
4202
+ g = new te(e, s.endpoints.dfpBackendURL, m.getAsync()),
4203
+ b = new He(s.endpoints.clientsideServicesIframeURL),
4204
+ k = new St(e, b),
4205
+ w = new Ct(this._networkClient);
4206
+ var S, T;
4207
+ this.user = new ie(this._networkClient, this._subscriptionService), this.session = new se(this._networkClient, this._subscriptionService), this.magicLinks = new ae(this._networkClient, this._subscriptionService, new Ot(this._dataLayer, "magic_links"), m.getAsync(), y.executeRecaptcha, g), this.otps = new ce(this._networkClient, this._subscriptionService, y.executeRecaptcha), this.oauth = new bt(this._networkClient, this._subscriptionService, new Ot(this._dataLayer, "oauth"), m.getAsync(), {
4208
+ publicToken: e,
4209
+ testAPIURL: s.endpoints.testAPIURL,
4210
+ liveAPIURL: s.endpoints.liveAPIURL
4211
+ }, k), this.cryptoWallets = new le(this._networkClient, this._subscriptionService, y.executeRecaptcha), this.totps = new de(this._networkClient, this._subscriptionService), this.webauthn = new Ie(this._networkClient, this._subscriptionService), this.passwords = new je(this._networkClient, this._subscriptionService, new Ot(this._dataLayer, "passwords"), m.getAsync(), y.executeRecaptcha, g), this._sessionManager = new Ue(this._subscriptionService, this.session), this._dataLayer.readSessionCookie().session_token && this._sessionManager.performBackgroundRefresh(), this._networkClient.logEvent({
4212
+ name: "sdk_instance_instantiated",
4213
+ details: {
4214
+ event_callback_registered: !1,
4215
+ error_callback_registered: !1,
4216
+ success_callback_registered: !1
4217
+ }
4218
+ }), S = this, T = {
4219
+ bootstrap: m,
4220
+ clientsideServices: b,
4221
+ captcha: y,
4222
+ oneTap: k,
4223
+ searchManager: w,
4224
+ publicToken: e,
4225
+ dataLayer: this._dataLayer,
4226
+ networkClient: this._networkClient
4227
+ }, Object.assign(S, _defineProperty({}, Ft, T));
4228
+ });
4229
+ export { ht as AuthFlowType, pt as B2BOAuthProviders, dt as B2BProducts, lt as BiometricsErrors, st as OAuthProviders, ct as OTPMethods, at as OneTapPositions, it as Products, ft as SDKAPIUnreachableError, ut as StytchEventType, Ut as StytchHeadlessClient, mt as StytchSDKAPIError, yt as StytchSDKNativeError, vt as StytchSDKSchemaError, _t as StytchSDKUsageError, gt as UNRECOVERABLE_ERROR_TYPES, ot as Wallets };