@stytch/vanilla-js 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/b2b/package.json +6 -0
- package/dist/b2b/index.esm.js +2 -2
- package/dist/b2b/index.js +2 -2
- package/dist/index.esm.js +1 -1
- package/dist/index.headless.esm.js +3 -3
- package/dist/index.headless.js +3 -3
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/index.headless.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";function e(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(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 t(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&&r(e,t)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(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=i(e);if(t){var s=i(this).constructor;r=Reflect.construct(n,arguments,s)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}(this,r)}}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(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,o,i,s,a=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw o}}return a}}(e,t)||a(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 a(e,t){if(e){if("string"==typeof e)return c(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)?c(e,t):void 0}}function c(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 u(e){return u="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},u(e)}function l(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */l=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",a=o.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,o){var i=t&&t.prototype instanceof f?t:f,s=Object.create(i.prototype),a=new E(o||[]);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 m(){}var y={};c(y,i,(function(){return this}));var _=Object.getPrototypeOf,g=_&&_(_(C([])));g&&g!==t&&r.call(g,i)&&(y=g);var b=m.prototype=f.prototype=Object.create(y);function w(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function o(n,i,s,a){var c=d(e[n],e,i);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==u(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,s,a)}),(function(e){o("throw",e,s,a)})):t.resolve(h).then((function(e){l.value=e,s(l)}),(function(e){return o("throw",e,s,a)}))}a(c.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return i=i?i.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=x(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 x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=d(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,p;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=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 o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return v.prototype=m,n(b,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:v,configurable:!0}),v.displayName=c(m,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,m):(e.__proto__=m,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,o,i){void 0===i&&(i=Promise);var s=new k(h(t,r,n,o),i);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,i,(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,E.prototype={constructor:E,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(T),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.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),T(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 o=n.arg;T(r)}return o}}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 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"!==u(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===u(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=_(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,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,i=e},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function m(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,o,i,s,a=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw o}}return a}}(e,t)||_(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 y(e){return y="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},y(e)}function _(e,t){if(e){if("string"==typeof e)return g(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)?g(e,t):void 0}}function g(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 b(){
|
|
1
|
+
"use strict";function e(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(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 t(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&&r(e,t)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function n(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=i(e);if(t){var s=i(this).constructor;r=Reflect.construct(n,arguments,s)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}(this,r)}}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function s(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,o,i,s,a=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw o}}return a}}(e,t)||a(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 a(e,t){if(e){if("string"==typeof e)return c(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)?c(e,t):void 0}}function c(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 u(e){return u="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},u(e)}function l(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */l=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",a=o.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,o){var i=t&&t.prototype instanceof f?t:f,s=Object.create(i.prototype),a=new E(o||[]);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 y(){}var _={};c(_,i,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(C([])));g&&g!==t&&r.call(g,i)&&(_=g);var b=y.prototype=f.prototype=Object.create(_);function w(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function o(n,i,s,a){var c=d(e[n],e,i);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==u(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,s,a)}),(function(e){o("throw",e,s,a)})):t.resolve(h).then((function(e){l.value=e,s(l)}),(function(e){return o("throw",e,s,a)}))}a(c.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return i=i?i.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=x(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 x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var o=d(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,p;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=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 o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return v.prototype=y,n(b,"constructor",{value:y,configurable:!0}),n(y,"constructor",{value:v,configurable:!0}),v.displayName=c(y,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,y):(e.__proto__=y,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,o,i){void 0===i&&(i=Promise);var s=new k(h(t,r,n,o),i);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,i,(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,E.prototype={constructor:E,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(T),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.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),T(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 o=n.arg;T(r)}return o}}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 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"!==u(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==u(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"===u(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,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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 i,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,i=e},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function y(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,o,i,s,a=[],c=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw o}}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 _(e){return _="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},_(e)}function m(e,t){if(e){if("string"==typeof e)return g(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)?g(e,t):void 0}}function g(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 b(){
|
|
2
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},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",a=o.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,o){var i=t&&t.prototype instanceof d?t:d,s=Object.create(i.prototype),a=new E(o||[]);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,i,(function(){return this}));var m=Object.getPrototypeOf,_=m&&m(m(C([])));_&&_!==t&&r.call(_,i)&&(v=_);var g=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 o(n,i,s,a){var c=l(e[n],e,i);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==y(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,s,a)}),(function(e){o("throw",e,s,a)})):t.resolve(h).then((function(e){u.value=e,s(u)}),(function(e){return o("throw",e,s,a)}))}a(c.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return i=i?i.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=x(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 x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,h;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=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 o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=f,n(g,"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(g),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,o,i){void 0===i&&(i=Promise);var s=new k(u(t,r,n,o),i);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},w(g),c(g,a,"Generator"),c(g,i,(function(){return this})),c(g,"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,E.prototype={constructor:E,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(T),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.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),T(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 o=n.arg;T(r)}return o}}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,(o=n.key,i=void 0,i=function(e,t){if("object"!==y(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==y(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===y(i)?i:String(i)),n)}var o,i}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 x(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&&A(e,t)}function O(e){var t=P();return function(){var r,n=R(e);if(t){var o=R(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===y(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return T(e)}(this,r)}}function T(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function E(e){var t="function"==typeof Map?new Map:void 0;return E=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}}),A(n,e)},E(e)}function C(e,t,r){return C=P()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&A(o,r.prototype),o},C.apply(null,arguments)}function P(){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 A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function R(e){return R=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},R(e)}Object.defineProperty(exports,"__esModule",{value:!0});var j,L,D,I,M,U,N="https://accounts.google.com/gsi",K="".concat(N,"/client");!function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(j||(j={})),function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch"}(L||(L={})),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"}(D||(D={})),function(e){e.embedded="embedded",e.floating="floating"}(I||(I={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(M||(M={})),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"}(U||(U={}));var F,B=function(e){x(r,E(Error));var t=O(r);function r(e,n){var o;return S(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(T(o),r.prototype),o}return k(r)}(),q=function(e){x(r,E(Error));var t=O(r);function r(e,n){var o;return S(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return k(r)}(),W=function(e){x(r,E(Error));var t=O(r);function r(e){var n,o;S(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var i=null===(o=e.body)||void 0===o?void 0:o.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(i),n}return k(r)}(),G=function(e){x(r,E(Error));var t=O(r);function r(e){var n;S(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return k(r)}(),H=["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"}(F||(F={}));var J=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(B,t);case"StytchSDKSchemaError":return e.inflate(W,t);case"StytchSDKAPIError":return e.inflate(G,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}();function z(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 o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function V(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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 Y,$=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?ue.warn("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 V(this,void 0,void 0,b().mark((function r(){var n,o,i=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,o=new MessageChannel,r.abrupt("return",new Promise((function(r,s){var a;o.port1.onmessage=function(e){var t=e.data;o.port1.close(),t.success?r(t.payload):s(J.unmarshall(t.error))};var c={method:e,args:t};null===(a=n.contentWindow)||void 0===a||a.postMessage(c,i.iframeURL,[o.port2])})));case 5:case"end":return r.stop()}}),r,this)})))}}]),e}(),X=new Uint8Array(16);function Z(){if(!Y&&!(Y="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 Y(X)}var Q=/^(?:[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 ee=[],te=0;te<256;++te)ee.push((te+256).toString(16).substr(1));function re(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(ee[e[t+0]]+ee[e[t+1]]+ee[e[t+2]]+ee[e[t+3]]+"-"+ee[e[t+4]]+ee[e[t+5]]+"-"+ee[e[t+6]]+ee[e[t+7]]+"-"+ee[e[t+8]]+ee[e[t+9]]+"-"+ee[e[t+10]]+ee[e[t+11]]+ee[e[t+12]]+ee[e[t+13]]+ee[e[t+14]]+ee[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Q.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function ne(e,t,r){var n=(e=e||{}).random||(e.rng||Z)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return re(n)}var oe={};function ie(e,t){return V(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]=se(e,t),r.abrupt("return",oe[e]);case 4:case"end":return r.stop()}}),r)})))}function se(e,t){return new Promise((function(r,n){var o=function(e){var t=ae(e);if(t[0])return t[0]}(e);if(o&&"true"===o.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 i=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);i.addEventListener("load",(function(){i.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)))}})),i.addEventListener("error",(function(t){n(new Error("".concat(e," could not be loaded: ").concat(t)))}))}))}var ae=function(e){return document.querySelectorAll('script[src="'.concat(e,'"]'))};var ce=["[Stytch]"],ue={debug:function(){return false},log:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=console).log.apply(e,ce.concat(r))},warn: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,ce.concat(r))},error: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,ce.concat(r))}},le="\nYou can find your public token at https://stytch.com/dashboard/api-keys.",he=function(e){var t={isObject:function(r,n){var o="object"===y(n)&&!Array.isArray(n)&&null!==n;if(!o)throw new q(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 q(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 q(e,r+" must be an array of strings.");var o,i=v(n);try{for(i.s();!(o=i.n()).done;){if("string"!=typeof o.value)throw new q(e,r+" must be an array of strings.")}}catch(e){i.e(e)}finally{i.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 q(e,r+" must be a number.");return t},isOptionalNumber:function(e,r){return void 0===r?t:t.isNumber(e,r)}};return t},de=function(e){return z(e,["request_id","status_code"])},pe=function(e){return z(e,["__user"])};function fe(e){var t=e.method,r=e.errorMessage,n=e.finalURL,o=e.basicAuthHeader,i=e.xSDKClientHeader,s=e.xSDKParentHostHeader,a=e.body;return V(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:o,"Content-Type":"application/json","X-SDK-Client":i},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 B(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 B(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 W(h);case 26:throw new G(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 B(r,"Invalid response from the Stytch servers.");case 37:case"end":return e.stop()}}),e,null,[[3,9],[15,21],[27,34]])})))}var ve=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(){var t=function(t){return function(r){return e.isUnrecoverableError(r)?Promise.reject(r):new Promise((function(r){return setTimeout(r,e.timeoutForAttempt(t))})).then((function(){return n._headlessSessionClient.authenticate()}))}};return n._headlessSessionClient.authenticate().catch(t(0)).catch(t(1)).catch(t(2)).catch(t(3)).catch(t(4))},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(){ue.warn("Session background refresh failed. Signalling to app that user is logged out."),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 Math.floor(350*Math.random())-175+2e3*Math.pow(2,e)}},{key:"isUnrecoverableError",value:function(e){return H.includes(e.error_type)}}]),e}();ve.REFRESH_INTERVAL_MS=18e4;var me=15,ye=800,_e=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 V(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 V(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=de(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 V(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 he("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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 7:case"end":return t.stop()}}),t,this)})))},this.deleteEmail=function(e){return V(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deletePhoneNumber=function(e){return V(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteTOTP=function(e){return V(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteOAuthRegistration=function(e){return V(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteWebauthnRegistration=function(e){return V(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.onChange=function(e){return n._subscriptionService.subscribeToState((function(t){var r;return e(null!==(r=null==t?void 0:t.user)&&void 0!==r?r:null)}))}})),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){return n._subscriptionService.subscribeToState((function(t){var r;return e(null!==(r=null==t?void 0:t.session)&&void 0!==r?r:null)}))},this.revoke=function(e){return V(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)||H.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 V(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}),t.abrupt("return",pe(n));case 9:throw t.prev=9,t.t0=t.catch(0),H.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()}}]),e}(),we=Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),ke=function(){function e(t,r,n){var o=this,i=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)};S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=i,this.executeRecaptcha=s,this.email={loginOrCreate:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return V(o,void 0,void 0,b().mark((function r(){var n,o,i,s;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,o=n.pkceRequiredForEmailMagicLinks,i=void 0,!o){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:i=r.sent;case 9:return r.t0=Object,r.t1=Object.assign({},t),r.t2=e,r.t3=i,r.next=15,this.executeRecaptcha();case 15:return r.t4=r.sent,r.t5={email:r.t2,code_challenge:r.t3,captcha_token:r.t4},s=r.t0.assign.call(r.t0,r.t1,r.t5),r.abrupt("return",this._networkClient.fetchSDK({url:"/magic_links/email/login_or_create",body:s,errorMessage:"Failed to send magic link",method:"POST"}));case 19:case"end":return r.stop()}}),r,this)})))},send:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return V(o,void 0,void 0,b().mark((function r(){var n,o,i,s,a,c;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,o=n.pkceRequiredForEmailMagicLinks,i=void 0,!o){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:i=r.sent;case 9:return r.t0=Object,r.t1=Object.assign({},t),r.t2=e,r.t3=i,r.next=15,this.executeRecaptcha();case 15:return r.t4=r.sent,r.t5={email:r.t2,code_challenge:r.t3,captcha_token:r.t4},s=r.t0.assign.call(r.t0,r.t1,r.t5),a=!!this._subscriptionService.getSession(),c=a?"/magic_links/email/send/secondary":"/magic_links/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:c,body:s,errorMessage:"Failed to send magic link",method:"POST"}));case 21:case"end":return r.stop()}}),r,this)})))}},this.authenticate=function(e,t){return V(o,void 0,void 0,b().mark((function r(){var n,o,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=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:o,errorMessage:"Failed to authenticate token.",method:"POST"});case 7:return i=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),r.abrupt("return",pe(i));case 11:case"end":return r.stop()}}),r,this)})))}}return k(e,[{key:"getCodeChallenge",value:function(){return V(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)})))}}]),e}(),Se=k((function e(t,r){var n=this,o=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=o,this.sms={loginOrCreate:function(e,t){return V(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/sms/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return V(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/sms/send/secondary":"/otps/sms/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 V(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/whatsapp/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return V(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/whatsapp/send/secondary":"/otps/whatsapp/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 V(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/email/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return V(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/email/send/secondary":"/otps/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 V(n,void 0,void 0,b().mark((function n(){var o,i;return b().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return he("stytch.otps.authenticate").isString("Code",e).isNumber("session_duration_minutes",r.session_duration_minutes),o=Object.assign({token:e,method_id:t},r),n.next=4,this._networkClient.fetchSDK({url:"/otps/authenticate",body:o,errorMessage:"Failed to authenticate token.",method:"POST"});case 4:return i=n.sent,this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),n.abrupt("return",pe(i));case 7:case"end":return n.stop()}}),n,this)})))}})),xe=function(){function e(t,r,n,o,i){S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._dynamicConfig=o,this._config=i,this.google={start:this.startOAuthFlow(L.Google)},this.apple={start:this.startOAuthFlow(L.Apple)},this.microsoft={start:this.startOAuthFlow(L.Microsoft)},this.github={start:this.startOAuthFlow(L.Github)},this.gitlab={start:this.startOAuthFlow(L.GitLab)},this.facebook={start:this.startOAuthFlow(L.Facebook)},this.discord={start:this.startOAuthFlow(L.Discord)},this.slack={start:this.startOAuthFlow(L.Slack)},this.amazon={start:this.startOAuthFlow(L.Amazon)},this.bitbucket={start:this.startOAuthFlow(L.Bitbucket)},this.linkedin={start:this.startOAuthFlow(L.LinkedIn)},this.coinbase={start:this.startOAuthFlow(L.Coinbase)},this.twitch={start:this.startOAuthFlow(L.Twitch)}}return k(e,[{key:"authenticate",value:function(e,t){return V(this,void 0,void 0,b().mark((function r(){var n,o;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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)||ue.warn("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 o=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:de(o.__user)},session_token:o.session_token,session_jwt:o.session_jwt}),r.abrupt("return",pe(o));case 11:case"end":return r.stop()}}),r,this)})))}},{key:"getBaseApiUrl",value:function(){return V(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,o=r.signup_redirect_url,i=r.custom_scopes;return V(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:i,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:i&&(he("startOAuthFlow").isStringArray("custom_scopes",i),u.searchParams.set("custom_scopes",i.join(" "))),n&&u.searchParams.set("login_redirect_url",n),o&&u.searchParams.set("signup_redirect_url",o),window.location.href=u.toString();case 23:case"end":return t.stop()}}),t,this)})))}}}]),e}(),Oe=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 V(this,void 0,void 0,b().mark((function t(){var r,n,o;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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,o=r?"/crypto_wallets/authenticate/start/secondary":"/crypto_wallets/authenticate/start/primary",t.abrupt("return",this._networkClient.fetchSDK({url:o,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 V(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 he("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:de(r.__user)},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}(),Te=function(){function e(t,r){S(this,e),this._networkClient=t,this._subscriptionService=r}return k(e,[{key:"create",value:function(e){return V(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 he("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",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return V(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 he("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}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"recoveryCodes",value:function(){return V(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 V(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 he("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}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}();function Ee(e){for(var t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),o=new ArrayBuffer(n.length),i=new Uint8Array(o),s=0;s<n.length;s++)i[s]=n.charCodeAt(s);return o}function Ce(e){var t,r="",n=v(new Uint8Array(e));try{for(n.s();!(t=n.n()).done;){var o=t.value;r+=String.fromCharCode(o)}}catch(e){n.e(e)}finally{n.f()}return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var Pe="copy",Ae="convert";function Re(e,t,r){if(t===Pe)return r;if(t===Ae)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={},o=0,i=Object.entries(t);o<i.length;o++){var s=m(i[o],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 je(e,t){return{required:!0,schema:e,derive:t}}function Le(e){return{required:!0,schema:e}}function De(e){return{required:!1,schema:e}}var Ie={type:Le(Pe),id:Le(Ae),transports:De(Pe)},Me={appid:De(Pe),appidExclude:De(Pe),credProps:De(Pe)},Ue={appid:De(Pe),appidExclude:De(Pe),credProps:De(Pe)},Ne={publicKey:Le({rp:Le(Pe),user:Le({id:Le(Ae),name:Le(Pe),displayName:Le(Pe)}),challenge:Le(Ae),pubKeyCredParams:Le(Pe),timeout:De(Pe),excludeCredentials:De([Ie]),authenticatorSelection:De(Pe),attestation:De(Pe),extensions:De(Me)}),signal:De(Pe)},Ke={type:Le(Pe),id:Le(Pe),rawId:Le(Ae),authenticatorAttachment:De(Pe),response:Le({clientDataJSON:Le(Ae),attestationObject:Le(Ae),transports:je(Pe,(function(e){var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]}))}),clientExtensionResults:je(Ue,(function(e){return e.getClientExtensionResults()}))},Fe={mediation:De(Pe),publicKey:Le({challenge:Le(Ae),timeout:De(Pe),rpId:De(Pe),allowCredentials:De([Ie]),userVerification:De(Pe),extensions:De(Me)}),signal:De(Pe)},Be={type:Le(Pe),id:Le(Pe),rawId:Le(Ae),authenticatorAttachment:De(Pe),response:Le({clientDataJSON:Le(Ae),authenticatorData:Le(Ae),signature:Le(Ae),userHandle:Le(Ae)}),clientExtensionResults:je(Ue,(function(e){return e.getClientExtensionResults()}))};function qe(e){return Re(Ee,Ne,e)}function We(e){return Re(Ce,Ke,e)}function Ge(e){return V(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(qe(e));case 2:return r=t.sent,t.abrupt("return",We(r));case 4:case"end":return t.stop()}}),t)})))}function He(e){return Re(Ee,Fe,e)}function Je(e){return Re(Ce,Be,e)}function ze(e){return V(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",Je(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 V(this,void 0,void 0,b().mark((function r(){var n,o,i,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=n.public_key_credential_creation_options,r.next=7,Ge({publicKey:JSON.parse(o)});case 7:return i=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(i)}});case 10:return s=r.sent,this._subscriptionService.updateUser(s.__user),r.abrupt("return",pe(s));case 13:case"end":return r.stop()}}),r,this)})))}},{key:"authenticate",value:function(e){var t;return V(this,void 0,void 0,b().mark((function r(){var n,o,i,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=n.public_key_credential_request_options,r.next=7,ze({publicKey:JSON.parse(o)});case 7:return i=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(i),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}),r.abrupt("return",pe(s));case 13:case"end":return r.stop()}}),r,this)})))}}]),e}(),Ye=Promise.resolve({pkceRequiredForPasswordResets:!1}),$e=function(){function e(t,r,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ye,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:function(){return Promise.resolve(void 0)};S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=o,this.executeRecaptcha=i}return k(e,[{key:"getCodeChallenge",value:function(){return V(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:"create",value:function(e){return V(this,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 he("stytch.passwords.create").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,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:r}});case 6:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.session,user:n.user},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",pe(n));case 9:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return V(this,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 he("stytch.passwords.authenticate").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,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:r}});case 6:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.session,user:n.user},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",pe(n));case 9:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmailStart",value:function(e){return V(this,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 he("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.executeRecaptcha();case 6:return n=t.sent,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:n}}));case 8:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmail",value:function(e){return V(this,void 0,void 0,b().mark((function t(){var r,n,o,i;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("stytch.passwords.resetByEmail").isString("token",e.token).isString("password",e.password).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,this._pkceManager.getPKPair();case 6:return n=t.sent,o=null==n?void 0:n.code_verifier,t.next=10,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:r,code_verifier:o}});case 10:return i=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),t.abrupt("return",pe(i));case 14:case"end":return t.stop()}}),t,this)})))}},{key:"resetByExistingPassword",value:function(e){return V(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 he("stytch.passwords.resetByExistingPassword").isString("email",e.email).isString("existing_password",e.existing_password).isString("new_password",e.new_password),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}});case 3:return r=t.sent,t.abrupt("return",pe(r));case 5:case"end":return t.stop()}}),t,this)})))}},{key:"resetBySession",value:function(e){return V(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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 V(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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 Xe(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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())}))}Promise.resolve({pkceRequiredForEmailMagicLinks:!1});var Ze=function(){function e(t,r,n,o){h(this,e),this._publicToken=t,this._subscriptionDataLayer=r,this.baseURL=n,this.additionalTelemetryDataFn=o,this.updateSessionToken=function(){return null},this.eventLogger=new _e({maxBatchSize:me,intervalDurationMs:ye,logEventURL:this.buildSDKUrl("/events")})}return p(e,[{key:"logEvent",value:function(e){var t=e.name,r=e.details,n=e.error,o=void 0===n?{}:n;this.eventLogger.logEvent(this.createTelemetryBlob(),{public_token:this._publicToken,event_name:t,details:r,error_code:o.error_code,error_description:o.error_description,http_status_code:o.http_status_code})}},{key:"createTelemetryBlob",value:function(){return Object.assign(Object.assign({event_id:"event-id-".concat(ne()),app_session_id:"app-session-id-".concat(ne()),persistent_id:"persistent-id-".concat(ne()),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:"0.11.0"}})}},{key:"fetchSDK",value:function(e){var t=e.url,r=e.body,n=e.errorMessage,o=e.method;return Xe(this,void 0,void 0,l().mark((function e(){var i,s,a,c;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this._subscriptionDataLayer.readSessionCookie().session_token,s="Basic "+window.btoa(this._publicToken+":"+(i||this._publicToken)),a=window.btoa(JSON.stringify(this.createTelemetryBlob())),c=window.location.origin,e.abrupt("return",fe({basicAuthHeader:s,body:r,errorMessage:n,finalURL:this.buildSDKUrl(t),method:o,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}(),Qe=function(e){return(document.cookie?document.cookie.split("; "):[]).filter((function(t){var r=s(t.split("="),1)[0];return e===r})).length>1};
|
|
3
|
+
b=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",a=o.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,o){var i=t&&t.prototype instanceof d?t:d,s=Object.create(i.prototype),a=new E(o||[]);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,i,(function(){return this}));var y=Object.getPrototypeOf,m=y&&y(y(C([])));m&&m!==t&&r.call(m,i)&&(v=m);var g=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 o(n,i,s,a){var c=l(e[n],e,i);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==_(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,s,a)}),(function(e){o("throw",e,s,a)})):t.resolve(h).then((function(e){u.value=e,s(u)}),(function(e){return o("throw",e,s,a)}))}a(c.arg)}var i;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return i=i?i.then(n,n):n()}})}function S(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return P()}for(r.method=o,r.arg=i;;){var s=r.delegate;if(s){var a=x(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 x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=l(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,h;var i=o.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function O(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 T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=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 o.next=o}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=f,n(g,"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(g),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,o,i){void 0===i&&(i=Promise);var s=new k(u(t,r,n,o),i);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},w(g),c(g,a,"Generator"),c(g,i,(function(){return this})),c(g,"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,E.prototype={constructor:E,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(T),!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 o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var a=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(a&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.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),T(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 o=n.arg;T(r)}return o}}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,(o=n.key,i=void 0,i=function(e,t){if("object"!==_(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===_(i)?i:String(i)),n)}var o,i}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 x(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&&A(e,t)}function O(e){var t=P();return function(){var r,n=j(e);if(t){var o=j(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===_(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return T(e)}(this,r)}}function T(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function E(e){var t="function"==typeof Map?new Map:void 0;return E=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,j(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),A(n,e)},E(e)}function C(e,t,r){return C=P()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&A(o,r.prototype),o},C.apply(null,arguments)}function P(){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 A(e,t){return A=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},A(e,t)}function j(e){return j=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},j(e)}Object.defineProperty(exports,"__esModule",{value:!0});var R,L,D,I,M,U,N="https://accounts.google.com/gsi",K="".concat(N,"/client");!function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(R||(R={})),function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch"}(L||(L={})),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"}(D||(D={})),function(e){e.embedded="embedded",e.floating="floating"}(I||(I={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(M||(M={})),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"}(U||(U={}));var F,B=function(e){x(r,E(Error));var t=O(r);function r(e,n){var o;return S(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(T(o),r.prototype),o}return k(r)}(),q=function(e){x(r,E(Error));var t=O(r);function r(e,n){var o;return S(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return k(r)}(),W=function(e){x(r,E(Error));var t=O(r);function r(e){var n,o;S(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var i=null===(o=e.body)||void 0===o?void 0:o.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(i),n}return k(r)}(),G=function(e){x(r,E(Error));var t=O(r);function r(e){var n;S(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return k(r)}(),H=["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"}(F||(F={}));var J=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(B,t);case"StytchSDKSchemaError":return e.inflate(W,t);case"StytchSDKAPIError":return e.inflate(G,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}();function V(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 o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function z(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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 Y,$=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?ue.warn("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 z(this,void 0,void 0,b().mark((function r(){var n,o,i=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,o=new MessageChannel,r.abrupt("return",new Promise((function(r,s){var a;o.port1.onmessage=function(e){var t=e.data;o.port1.close(),t.success?r(t.payload):s(J.unmarshall(t.error))};var c={method:e,args:t};null===(a=n.contentWindow)||void 0===a||a.postMessage(c,i.iframeURL,[o.port2])})));case 5:case"end":return r.stop()}}),r,this)})))}}]),e}(),X=new Uint8Array(16);function Z(){if(!Y&&!(Y="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 Y(X)}var Q=/^(?:[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 ee=[],te=0;te<256;++te)ee.push((te+256).toString(16).substr(1));function re(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(ee[e[t+0]]+ee[e[t+1]]+ee[e[t+2]]+ee[e[t+3]]+"-"+ee[e[t+4]]+ee[e[t+5]]+"-"+ee[e[t+6]]+ee[e[t+7]]+"-"+ee[e[t+8]]+ee[e[t+9]]+"-"+ee[e[t+10]]+ee[e[t+11]]+ee[e[t+12]]+ee[e[t+13]]+ee[e[t+14]]+ee[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&Q.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function ne(e,t,r){var n=(e=e||{}).random||(e.rng||Z)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return re(n)}var oe={};function ie(e,t){return z(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]=se(e,t),r.abrupt("return",oe[e]);case 4:case"end":return r.stop()}}),r)})))}function se(e,t){return new Promise((function(r,n){var o=function(e){var t=ae(e);if(t[0])return t[0]}(e);if(o&&"true"===o.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 i=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);i.addEventListener("load",(function(){i.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)))}})),i.addEventListener("error",(function(t){n(new Error("".concat(e," could not be loaded: ").concat(t)))}))}))}var ae=function(e){return document.querySelectorAll('script[src="'.concat(e,'"]'))};var ce=["[Stytch]"],ue={debug:function(){return false},log:function(){for(var e,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=console).log.apply(e,ce.concat(r))},warn: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,ce.concat(r))},error: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,ce.concat(r))}},le="\nYou can find your public token at https://stytch.com/dashboard/api-keys.",he=function(e){var t={isObject:function(r,n){var o="object"===_(n)&&!Array.isArray(n)&&null!==n;if(!o)throw new q(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 q(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 q(e,r+" must be an array of strings.");var o,i=v(n);try{for(i.s();!(o=i.n()).done;){if("string"!=typeof o.value)throw new q(e,r+" must be an array of strings.")}}catch(e){i.e(e)}finally{i.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 q(e,r+" must be a number.");return t},isOptionalNumber:function(e,r){return void 0===r?t:t.isNumber(e,r)}};return t},de=function(e){return V(e,["request_id","status_code"])},pe=function(e){return V(e,["__user"])};function fe(e){var t=e.method,r=e.errorMessage,n=e.finalURL,o=e.basicAuthHeader,i=e.xSDKClientHeader,s=e.xSDKParentHostHeader,a=e.body;return z(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:o,"Content-Type":"application/json","X-SDK-Client":i},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 B(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 B(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 W(h);case 26:throw new G(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 B(r,"Invalid response from the Stytch servers.");case 37:case"end":return e.stop()}}),e,null,[[3,9],[15,21],[27,34]])})))}var ve=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(){var t=function(t){return function(r){return e.isUnrecoverableError(r)?Promise.reject(r):new Promise((function(r){return setTimeout(r,e.timeoutForAttempt(t))})).then((function(){return n._headlessSessionClient.authenticate()}))}};return n._headlessSessionClient.authenticate().catch(t(0)).catch(t(1)).catch(t(2)).catch(t(3)).catch(t(4))},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(){ue.warn("Session background refresh failed. Signalling to app that user is logged out."),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 Math.floor(350*Math.random())-175+2e3*Math.pow(2,e)}},{key:"isUnrecoverableError",value:function(e){return H.includes(e.error_type)}}]),e}();ve.REFRESH_INTERVAL_MS=18e4;var ye=15,_e=800,me=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 z(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 z(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=de(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 z(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 he("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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 7:case"end":return t.stop()}}),t,this)})))},this.deleteEmail=function(e){return z(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deletePhoneNumber=function(e){return z(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteTOTP=function(e){return z(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteOAuthRegistration=function(e){return z(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))},this.deleteWebauthnRegistration=function(e){return z(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=de(r.__user),this._subscriptionService.updateUser(n),t.abrupt("return",pe(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 z(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)||H.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 z(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}),t.abrupt("return",pe(n));case 9:throw t.prev=9,t.t0=t.catch(0),H.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 o=this,i=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)};S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=i,this.executeRecaptcha=s,this.email={loginOrCreate:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return z(o,void 0,void 0,b().mark((function r(){var n,o,i,s;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,o=n.pkceRequiredForEmailMagicLinks,i=void 0,!o){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:i=r.sent;case 9:return r.t0=Object,r.t1=Object.assign({},t),r.t2=e,r.t3=i,r.next=15,this.executeRecaptcha();case 15:return r.t4=r.sent,r.t5={email:r.t2,code_challenge:r.t3,captcha_token:r.t4},s=r.t0.assign.call(r.t0,r.t1,r.t5),r.abrupt("return",this._networkClient.fetchSDK({url:"/magic_links/email/login_or_create",body:s,errorMessage:"Failed to send magic link",method:"POST"}));case 19:case"end":return r.stop()}}),r,this)})))},send:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return z(o,void 0,void 0,b().mark((function r(){var n,o,i,s,a,c;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,o=n.pkceRequiredForEmailMagicLinks,i=void 0,!o){r.next=9;break}return r.next=8,this.getCodeChallenge();case 8:i=r.sent;case 9:return r.t0=Object,r.t1=Object.assign({},t),r.t2=e,r.t3=i,r.next=15,this.executeRecaptcha();case 15:return r.t4=r.sent,r.t5={email:r.t2,code_challenge:r.t3,captcha_token:r.t4},s=r.t0.assign.call(r.t0,r.t1,r.t5),a=!!this._subscriptionService.getSession(),c=a?"/magic_links/email/send/secondary":"/magic_links/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:c,body:s,errorMessage:"Failed to send magic link",method:"POST"}));case 21:case"end":return r.stop()}}),r,this)})))}},this.authenticate=function(e,t){return z(o,void 0,void 0,b().mark((function r(){var n,o,i;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=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:o,errorMessage:"Failed to authenticate token.",method:"POST"});case 7:return i=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),r.abrupt("return",pe(i));case 11:case"end":return r.stop()}}),r,this)})))}}return k(e,[{key:"getCodeChallenge",value:function(){return z(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)})))}}]),e}(),Se=k((function e(t,r){var n=this,o=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=o,this.sms={loginOrCreate:function(e,t){return z(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/sms/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return z(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/sms/send/secondary":"/otps/sms/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 z(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/whatsapp/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return z(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{phone_number:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/whatsapp/send/secondary":"/otps/whatsapp/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 z(n,void 0,void 0,b().mark((function r(){var n,o;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,o=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),r.abrupt("return",this._networkClient.fetchSDK({url:"/otps/email/login_or_create",body:o,errorMessage:"Failed to send one time passcode",method:"POST"}));case 5:case"end":return r.stop()}}),r,this)})))},send:function(e,t){return z(n,void 0,void 0,b().mark((function r(){var n,o,i,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,o=Object.assign(Object.assign({},t),{email:e,captcha_token:n}),i=!!this._subscriptionService.getSession(),s=i?"/otps/email/send/secondary":"/otps/email/send/primary",r.abrupt("return",this._networkClient.fetchSDK({url:s,body:o,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 z(n,void 0,void 0,b().mark((function n(){var o,i;return b().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return he("stytch.otps.authenticate").isString("Code",e).isNumber("session_duration_minutes",r.session_duration_minutes),o=Object.assign({token:e,method_id:t},r),n.next=4,this._networkClient.fetchSDK({url:"/otps/authenticate",body:o,errorMessage:"Failed to authenticate token.",method:"POST"});case 4:return i=n.sent,this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),n.abrupt("return",pe(i));case 7:case"end":return n.stop()}}),n,this)})))}})),xe=function(){function e(t,r,n,o,i){S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._dynamicConfig=o,this._config=i,this.google={start:this.startOAuthFlow(L.Google)},this.apple={start:this.startOAuthFlow(L.Apple)},this.microsoft={start:this.startOAuthFlow(L.Microsoft)},this.github={start:this.startOAuthFlow(L.Github)},this.gitlab={start:this.startOAuthFlow(L.GitLab)},this.facebook={start:this.startOAuthFlow(L.Facebook)},this.discord={start:this.startOAuthFlow(L.Discord)},this.slack={start:this.startOAuthFlow(L.Slack)},this.amazon={start:this.startOAuthFlow(L.Amazon)},this.bitbucket={start:this.startOAuthFlow(L.Bitbucket)},this.linkedin={start:this.startOAuthFlow(L.LinkedIn)},this.coinbase={start:this.startOAuthFlow(L.Coinbase)},this.twitch={start:this.startOAuthFlow(L.Twitch)}}return k(e,[{key:"authenticate",value:function(e,t){return z(this,void 0,void 0,b().mark((function r(){var n,o;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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)||ue.warn("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 o=r.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:o.session,user:de(o.__user)},session_token:o.session_token,session_jwt:o.session_jwt}),r.abrupt("return",pe(o));case 11:case"end":return r.stop()}}),r,this)})))}},{key:"getBaseApiUrl",value:function(){return z(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,o=r.signup_redirect_url,i=r.custom_scopes;return z(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:i,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:i&&(he("startOAuthFlow").isStringArray("custom_scopes",i),u.searchParams.set("custom_scopes",i.join(" "))),n&&u.searchParams.set("login_redirect_url",n),o&&u.searchParams.set("signup_redirect_url",o),window.location.href=u.toString();case 23:case"end":return t.stop()}}),t,this)})))}}}]),e}(),Oe=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 z(this,void 0,void 0,b().mark((function t(){var r,n,o;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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,o=r?"/crypto_wallets/authenticate/start/secondary":"/crypto_wallets/authenticate/start/primary",t.abrupt("return",this._networkClient.fetchSDK({url:o,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 z(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 he("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:de(r.__user)},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}(),Te=function(){function e(t,r){S(this,e),this._networkClient=t,this._subscriptionService=r}return k(e,[{key:"create",value:function(e){return z(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 he("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",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return z(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 he("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}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}},{key:"recoveryCodes",value:function(){return z(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 z(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 he("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}),t.abrupt("return",pe(r));case 6:case"end":return t.stop()}}),t,this)})))}}]),e}();function Ee(e){for(var t="==".slice(0,(4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r),o=new ArrayBuffer(n.length),i=new Uint8Array(o),s=0;s<n.length;s++)i[s]=n.charCodeAt(s);return o}function Ce(e){var t,r="",n=v(new Uint8Array(e));try{for(n.s();!(t=n.n()).done;){var o=t.value;r+=String.fromCharCode(o)}}catch(e){n.e(e)}finally{n.f()}return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}var Pe="copy",Ae="convert";function je(e,t,r){if(t===Pe)return r;if(t===Ae)return e(r);if(t instanceof Array)return r.map((function(r){return je(e,t[0],r)}));if(t instanceof Object){for(var n={},o=0,i=Object.entries(t);o<i.length;o++){var s=y(i[o],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]=je(e,c.schema,r[a]):n[a]=null;else if(c.required)throw new Error("Missing key: ".concat(a))}return n}}function Re(e,t){return{required:!0,schema:e,derive:t}}function Le(e){return{required:!0,schema:e}}function De(e){return{required:!1,schema:e}}var Ie={type:Le(Pe),id:Le(Ae),transports:De(Pe)},Me={appid:De(Pe),appidExclude:De(Pe),credProps:De(Pe)},Ue={appid:De(Pe),appidExclude:De(Pe),credProps:De(Pe)},Ne={publicKey:Le({rp:Le(Pe),user:Le({id:Le(Ae),name:Le(Pe),displayName:Le(Pe)}),challenge:Le(Ae),pubKeyCredParams:Le(Pe),timeout:De(Pe),excludeCredentials:De([Ie]),authenticatorSelection:De(Pe),attestation:De(Pe),extensions:De(Me)}),signal:De(Pe)},Ke={type:Le(Pe),id:Le(Pe),rawId:Le(Ae),authenticatorAttachment:De(Pe),response:Le({clientDataJSON:Le(Ae),attestationObject:Le(Ae),transports:Re(Pe,(function(e){var t;return(null==(t=e.getTransports)?void 0:t.call(e))||[]}))}),clientExtensionResults:Re(Ue,(function(e){return e.getClientExtensionResults()}))},Fe={mediation:De(Pe),publicKey:Le({challenge:Le(Ae),timeout:De(Pe),rpId:De(Pe),allowCredentials:De([Ie]),userVerification:De(Pe),extensions:De(Me)}),signal:De(Pe)},Be={type:Le(Pe),id:Le(Pe),rawId:Le(Ae),authenticatorAttachment:De(Pe),response:Le({clientDataJSON:Le(Ae),authenticatorData:Le(Ae),signature:Le(Ae),userHandle:Le(Ae)}),clientExtensionResults:Re(Ue,(function(e){return e.getClientExtensionResults()}))};function qe(e){return je(Ee,Ne,e)}function We(e){return je(Ce,Ke,e)}function Ge(e){return z(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(qe(e));case 2:return r=t.sent,t.abrupt("return",We(r));case 4:case"end":return t.stop()}}),t)})))}function He(e){return je(Ee,Fe,e)}function Je(e){return je(Ce,Be,e)}function Ve(e){return z(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",Je(r));case 4:case"end":return t.stop()}}),t)})))}var ze=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 z(this,void 0,void 0,b().mark((function r(){var n,o,i,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=n.public_key_credential_creation_options,r.next=7,Ge({publicKey:JSON.parse(o)});case 7:return i=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(i)}});case 10:return s=r.sent,this._subscriptionService.updateUser(s.__user),r.abrupt("return",pe(s));case 13:case"end":return r.stop()}}),r,this)})))}},{key:"authenticate",value:function(e){var t;return z(this,void 0,void 0,b().mark((function r(){var n,o,i,s;return b().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return he("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,o=n.public_key_credential_request_options,r.next=7,Ve({publicKey:JSON.parse(o)});case 7:return i=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(i),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}),r.abrupt("return",pe(s));case 13:case"end":return r.stop()}}),r,this)})))}}]),e}(),Ye=Promise.resolve({pkceRequiredForPasswordResets:!1}),$e=function(){function e(t,r,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:Ye,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:function(){return Promise.resolve(void 0)};S(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=o,this.executeRecaptcha=i}return k(e,[{key:"getCodeChallenge",value:function(){return z(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:"create",value:function(e){return z(this,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 he("stytch.passwords.create").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,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:r}});case 6:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.session,user:n.user},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",pe(n));case 9:case"end":return t.stop()}}),t,this)})))}},{key:"authenticate",value:function(e){return z(this,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 he("stytch.passwords.authenticate").isString("password",e.password).isString("email",e.email).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,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:r}});case 6:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.session,user:n.user},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",pe(n));case 9:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmailStart",value:function(e){return z(this,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 he("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.executeRecaptcha();case 6:return n=t.sent,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:n}}));case 8:case"end":return t.stop()}}),t,this)})))}},{key:"resetByEmail",value:function(e){return z(this,void 0,void 0,b().mark((function t(){var r,n,o,i;return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("stytch.passwords.resetByEmail").isString("token",e.token).isString("password",e.password).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this.executeRecaptcha();case 3:return r=t.sent,t.next=6,this._pkceManager.getPKPair();case 6:return n=t.sent,o=null==n?void 0:n.code_verifier,t.next=10,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:r,code_verifier:o}});case 10:return i=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:i.session,user:i.user},session_token:i.session_token,session_jwt:i.session_jwt}),t.abrupt("return",pe(i));case 14:case"end":return t.stop()}}),t,this)})))}},{key:"resetByExistingPassword",value:function(e){return z(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 he("stytch.passwords.resetByExistingPassword").isString("email",e.email).isString("existing_password",e.existing_password).isString("new_password",e.new_password),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}});case 3:return r=t.sent,t.abrupt("return",pe(r));case 5:case"end":return t.stop()}}),t,this)})))}},{key:"resetBySession",value:function(e){return z(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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 z(this,void 0,void 0,b().mark((function t(){return b().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return he("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 Xe(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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())}))}Promise.resolve({pkceRequiredForEmailMagicLinks:!1});var Ze=function(){function e(t,r,n,o){h(this,e),this._publicToken=t,this._subscriptionDataLayer=r,this.baseURL=n,this.additionalTelemetryDataFn=o,this.updateSessionToken=function(){return null},this.eventLogger=new me({maxBatchSize:ye,intervalDurationMs:_e,logEventURL:this.buildSDKUrl("/events")})}return p(e,[{key:"logEvent",value:function(e){var t=e.name,r=e.details,n=e.error,o=void 0===n?{}:n;this.eventLogger.logEvent(this.createTelemetryBlob(),{public_token:this._publicToken,event_name:t,details:r,error_code:o.error_code,error_description:o.error_description,http_status_code:o.http_status_code})}},{key:"createTelemetryBlob",value:function(){return Object.assign(Object.assign({event_id:"event-id-".concat(ne()),app_session_id:"app-session-id-".concat(ne()),persistent_id:"persistent-id-".concat(ne()),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:"0.11.2"}})}},{key:"fetchSDK",value:function(e){var t=e.url,r=e.body,n=e.errorMessage,o=e.method;return Xe(this,void 0,void 0,l().mark((function e(){var i,s,a,c;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=this._subscriptionDataLayer.readSessionCookie().session_token,s="Basic "+window.btoa(this._publicToken+":"+(i||this._publicToken)),a=window.btoa(JSON.stringify(this.createTelemetryBlob())),c=window.location.origin,e.abrupt("return",fe({basicAuthHeader:s,body:r,errorMessage:n,finalURL:this.buildSDKUrl(t),method:o,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}(),Qe=function(e){return(document.cookie?document.cookie.split("; "):[]).filter((function(t){var r=s(t.split("="),1)[0];return e===r})).length>1};
|
|
4
4
|
/*! js-cookie v3.0.1 | MIT */
|
|
5
|
-
function et(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 tt=function e(t,r){function n(e,n,o){if("undefined"!=typeof document){"number"==typeof(o=et({},r,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+i}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},o=0;o<r.length;o++){var i=r[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",et({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,et({},this.attributes,t))},withConverter:function(t){return e(et({},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:"/"}),rt="stytch_sdk_state_",nt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"".concat(rt).concat(e).concat(t?"::".concat(t):"")},ot=function(){function e(t,r){var n=this;h(this,e),this.browserSessionStorage={getItem:function(e){return sessionStorage.getItem(nt(n.publicToken,e))},setItem:function(e,t){return sessionStorage.setItem(nt(n.publicToken,e),t)},removeItem:function(e){return sessionStorage.removeItem(nt(n.publicToken,e))}},this.publicToken=t,this.state=null,this.subscriptions={},(null==r?void 0:r.cookieOptions)?(he("SubscriptionDataLayer").isOptionalString("cookieOptions.opaqueTokenCookieName",r.cookieOptions.opaqueTokenCookieName).isOptionalString("cookieOptions.jwtCookieName",r.cookieOptions.jwtCookieName).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._opaqueTokenCookieName=null,this._jwtCookieName=null,this._cookiePath=null,this._cookieAvailableToSubdomains=!1);var o=localStorage.getItem(nt(this.publicToken));if(o){var i;try{i=JSON.parse(o)}catch(e){return this.syncToLocalStorage(),void this.removeSessionCookie()}this.state=i}else this.removeSessionCookie()}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:"readSessionCookie",value:function(){return{session_token:tt.get(this.opaqueTokenCookieName),session_jwt:tt.get(this.jwtCookieName)}}},{key:"writeSessionCookie",value:function(t){var r,n,o,i,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});tt.set(this.opaqueTokenCookieName,a,u),tt.set(this.jwtCookieName,c,u);var l=e.generateCookieOpts({expiresAt:null!==(i=null===(o=null==s?void 0:s.session)||void 0===o?void 0:o.expires_at)&&void 0!==i?i:"",availableToSubdomains:!this._cookieAvailableToSubdomains,path:this._cookiePath});Qe(this.jwtCookieName)&&tt.remove(this.jwtCookieName,l),Qe(this.opaqueTokenCookieName)&&tt.remove(this.opaqueTokenCookieName,l),Qe(this.jwtCookieName)&&ue.warn("Could not remove extraneous JWT cookie. This might happen if the cookie has been set using multiple `path` settings, and may produce unwanted behavior."),Qe(this.opaqueTokenCookieName)&&ue.warn("Could not remove extraneous opaque token cookie.")}},{key:"removeSessionCookie",value:function(){var t=this;[!0,!1].forEach((function(r){[t._cookiePath,null].forEach((function(n){var o=e.generateCookieOpts({expiresAt:new Date(0).toString(),availableToSubdomains:r,path:n});tt.remove(t.opaqueTokenCookieName,o),tt.remove(t.jwtCookieName,o)}))}))}},{key:"syncToLocalStorage",value:function(){localStorage.setItem(nt(this.publicToken),JSON.stringify(this.state))}},{key:"getItem",value:function(e){return localStorage.getItem(nt(this.publicToken,e))}},{key:"setItem",value:function(e,t){return localStorage.setItem(nt(this.publicToken,e),t)}},{key:"removeItem",value:function(e){return localStorage.removeItem(nt(this.publicToken,e))}}],[{key:"generateCookieOpts",value:function(e){var t=e.path,r=e.availableToSubdomains,n=e.expiresAt,o={expires:new Date(n),sameSite:"lax"};return t&&(o.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}$/))?o.secure=!1:(r&&(o.domain=window.location.host),o.secure=!0),o}}]),e}(),it=function(e){t(o,ot);var r=n(o);function o(){return h(this,o),r.apply(this,arguments)}return p(o)}(),st=Symbol.for("__stytch_DataLayer"),at=function(e,t){var r,n=((r=window)[st]||(r[st]={}),r[st]);return n[e]||(n[e]=new it(e,t)),n[e]},ct=function(e,t){Object.values(e).forEach((function(e){return e(t)}))},ut=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 y(r)===y(n)&&(null===r||null===n?r===n:"object"===y(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=m(e,1)[0];return!t.includes(r)})).every((function(t){var r=m(t,2),o=r[0],i=r[1];return e(i,n[o])})):r===n)}}({KEYS_TO_EXCLUDE:["last_accessed_at"]}),lt=function(){function e(t,r){var n,o=this;h(this,e),this._publicToken=t,this._datalayer=r,this._listen=function(e){e.key===nt(o._publicToken)&&(null!==e.newValue?o._updateStateAndTokensInternal(JSON.parse(e.newValue)):o.destroyState())},window.addEventListener("storage",this._listen);var i=null===(n=this._datalayer.state)||void 0===n?void 0:n.session;i&&Date.parse(i.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 t&&r?{session_token:t,session_jwt:r}:null}},{key:"destroyState",value:function(){this.updateStateAndTokens({state:null,session_token:null,session_jwt:null})}},{key:"_updateStateAndTokensInternal",value:function(e){var t=e.state,r=this._datalayer.state;this._datalayer.state=t||null,ut(r,e.state)||ct(this._datalayer.subscriptions,e.state)}},{key:"updateStateAndTokens",value:function(e){e.state?this._datalayer.writeSessionCookie(e):this._datalayer.removeSessionCookie(),this._updateStateAndTokensInternal(e),this._datalayer.syncToLocalStorage()}},{key:"updateState",value:function(e){var t=this._datalayer.state,r=Object.assign(Object.assign({},this._datalayer.state),e);this._datalayer.state=r,ut(t,r)||(ct(this._datalayer.subscriptions,r),this._datalayer.syncToLocalStorage())}},{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}(),ht=function(e){t(o,lt);var r=n(o);function o(){var e;return h(this,o),(e=r.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(o)}();function dt(e){var t=e.toString(16);return 1===t.length&&(t="0"+t),t}var pt=function(){function t(e,r){h(this,t),this._dataLayer=e,this.namespace=r}return p(t,[{key:"key",value:function(){return"PKCE_VERIFIER:"+this.namespace}},{key:"startPKCETransaction",value:function(){return Xe(this,void 0,void 0,l().mark((function e(){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.createProofkeyPair();case 2:return r=e.sent,this._dataLayer.setItem(this.key(),JSON.stringify(r)),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)})))}},{key:"getPKPair",value:function(){var e=this._dataLayer.getItem(this.key());if(null!==e)try{return JSON.parse(e)}catch(e){return void ue.warn("Found malformed Proof Key pair in localstorage.")}}},{key:"clearPKPair",value:function(){return this._dataLayer.removeItem(this.key())}}],[{key:"createProofkeyPair",value:function(){return Xe(this,void 0,void 0,l().mark((function t(){var r,n,o;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=new Uint32Array(16),window.crypto.getRandomValues(r),n=Array.from(r).map(dt).join(""),t.next=5,window.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(n));case 5:return o=t.sent,t.abrupt("return",{code_challenge:(i=o,s=void 0,btoa((s=String.fromCharCode).call.apply(s,[null].concat(e(new Uint8Array(i))))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),code_verifier:n});case 7:case"end":return t.stop()}var i,s}),t)})))}}]),t}(),ft="bootstrap",vt=function(){return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1}},mt=function(){function e(t,r,n){var o=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 o._dataLayer.setItem(ft,JSON.stringify(e)),e})).catch((function(e){return ue.error(e),vt()}))}return p(e,[{key:"getSync",value:function(){var e=this._dataLayer.getItem(ft);if(null===e)return vt();try{return JSON.parse(e)}catch(e){return vt()}}},{key:"getAsync",value:function(){return this._bootstrapDataPromise}}],[{key:"mapBootstrapData",value:function(e){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}}}]),e}(),yt=p((function e(t){var r=this;h(this,e),this.bootstrapPromise=t,this.executeRecaptcha=function(){return Xe(r,void 0,void 0,l().mark((function e(){var t,r,n,o;return l().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,o=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(o,{action:"LOGIN"}));case 11:case"end":return e.stop()}}),e,this)})))},this.state=t.then((function(e){return Xe(r,void 0,void 0,l().mark((function t(){return l().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,ie("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)})))}))}));function _t(e){return _t="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},_t(e)}function gt(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,(o=n.key,i=void 0,i=function(e,t){if("object"!==_t(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==_t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===_t(i)?i:String(i)),n)}var o,i}function bt(e,t,r){return t&>(e.prototype,t),r&>(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function wt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function kt(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&&Ct(e,t)}function St(e){var t=Et();return function(){var r,n=Pt(e);if(t){var o=Pt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===_t(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return xt(e)}(this,r)}}function xt(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ot(e){var t="function"==typeof Map?new Map:void 0;return Ot=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 Tt(e,arguments,Pt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ct(n,e)},Ot(e)}function Tt(e,t,r){return Tt=Et()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&Ct(o,r.prototype),o},Tt.apply(null,arguments)}function Et(){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 Ct(e,t){return Ct=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ct(e,t)}function Pt(e){return Pt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Pt(e)}exports.Products=void 0,function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(exports.Products||(exports.Products={})),exports.OAuthProviders=void 0,function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch"}(exports.OAuthProviders||(exports.OAuthProviders={})),exports.Wallets=void 0,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"}(exports.Wallets||(exports.Wallets={})),exports.OneTapPositions=void 0,function(e){e.embedded="embedded",e.floating="floating"}(exports.OneTapPositions||(exports.OneTapPositions={})),exports.OTPMethods=void 0,function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(exports.OTPMethods||(exports.OTPMethods={})),exports.StytchEventType=void 0,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"}(exports.StytchEventType||(exports.StytchEventType={}));var At=function(e){kt(r,Ot(Error));var t=St(r);function r(e,n){var o;return wt(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(xt(o),r.prototype),o}return bt(r)}(),Rt=function(e){kt(r,Ot(Error));var t=St(r);function r(e,n){var o;return wt(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return bt(r)}(),jt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n,o;wt(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var i=null===(o=e.body)||void 0===o?void 0:o.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(i),n}return bt(r)}(),Lt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n;wt(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return bt(r)}(),Dt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n;return wt(this,r),(n=t.call(this)).name="StytchSDKNativeError",n.error_type=e,n.message="".concat(e),n}return bt(r)}();exports.BiometricsErrors=void 0,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"}(exports.BiometricsErrors||(exports.BiometricsErrors={}));var It=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 Xe(this,void 0,void 0,l().mark((function e(){var o,i=this;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={client_id:this._clientId,callback:t,auto_select:!1,context:"use",itp_support:!0},n.position===exports.OneTapPositions.embedded&&(o.prompt_parent_id="google-parent-prompt",o.cancel_on_tap_outside=!1),this._googleClient.initialize(o),e.abrupt("return",new Promise((function(e){i._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()}):(i.styleFrame(n),e({success:!0}))}))})));case 4:case"end":return e.stop()}}),e,this)})))}},{key:"styleFrame",value:function(e){e.position===exports.OneTapPositions.embedded&&Array.from(document.getElementsByTagName("iframe")).forEach((function(e){e.src.includes(N)&&(e.style.width="100%")}))}}]),e}(),Mt=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,o=e.onSuccess;return function(e){return Xe(n,void 0,void 0,l().mark((function n(){var i,s,a;return l().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.credential,n.next=3,this.submitGoogleOneTapToken({credential:i,loginRedirectUrl:t,signupRedirectUrl:r});case 3:s=n.sent,a=s.redirect_url,o(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 Xe(this,void 0,void 0,l().mark((function e(){var t,r,n,o;return l().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=It,e.next=16,ie(K,(function(){return window.google.accounts.id}));case 16:return e.t2=e.sent,e.t3=this._publicToken,e.t4=t,o=new e.t1(e.t2,e.t3,e.t4),e.abrupt("return",{success:!0,client:o});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 Xe(this,void 0,void 0,l().mark((function e(){var o,i;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.fetchGoogleStart();case 2:return o=e.sent,i=o.oauthCallbackId,e.abrupt("return",this.clientsideServices.oneTapSubmit({publicToken:this._publicToken,idToken:t,loginRedirectURL:r,oauthCallbackID:i,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}(),Ut=Symbol.for("stytch__internal"),Nt=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}({},Ut,t))},Kt=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 $(this.iframeURL),this._frameClient}},{key:"call",value:function(e,t){return this.frameClient.call(e,[t])}}]),e}(),Ft=function(){function e(t){h(this,e),this._networkClient=t}return p(e,[{key:"search",value:function(e){return this._networkClient.fetchSDK({url:"/users/search",method:"POST",body:{email:e},errorMessage:"Error searching for user ".concat(e)})}}]),e}(),Bt=function(e){t(i,xe);var r=n(i);function i(e,t,n,s,a,c){var u;return h(this,i),(u=r.call(this,e,t,n,s,a))._oneTap=c,u.startOneTap=function(e){return Xe(o(u),void 0,void 0,l().mark((function t(){var r,n,o;return l().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,o=this._oneTap.createOnSuccessHandler({signupRedirectUrl:e.signup_redirect_url,loginRedirectUrl:e.login_redirect_url,onSuccess:this._oneTap.RedirectOnSuccess}),t.abrupt("return",n.render({style:{position:exports.OneTapPositions.floating},onOneTapCancelled:e.onOneTapCancelled,callback:o}));case 8:case"end":return t.stop()}}),t,this)})))},u.googleOneTap={start:u.startOneTap},u}return p(i)}(),qt=p((function e(t,r){var n,o=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)?ue.warn("Public token is malformed. Expected a string, got ".concat(y(n),".").concat(le)):""===n?ue.warn('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(le)):n.startsWith("public-token-")||ue.warn('Public token is malformed. Expected "public-token-...", got '.concat(n,".").concat(le));var i,s,a,c,u,l,d,p,f,v=r,m={cookieOptions:null==(i=v)?void 0:i.cookieOptions,endpoints:{sdkBackendURL:null!==(a=null===(s=null==i?void 0:i.endpoints)||void 0===s?void 0:s.sdkBackendURL)&&void 0!==a?a:"https://web.stytch.com",testAPIURL:null!==(u=null===(c=null==i?void 0:i.endpoints)||void 0===c?void 0:c.testAPIURL)&&void 0!==u?u:"https://test.stytch.com",liveAPIURL:null!==(d=null===(l=null==i?void 0:i.endpoints)||void 0===l?void 0:l.liveAPIURL)&&void 0!==d?d:"https://api.stytch.com",clientsideServicesIframeURL:null!==(f=null===(p=null==i?void 0:i.endpoints)||void 0===p?void 0:p.clientsideServicesIframeURL)&&void 0!==f?f:"https://js.stytch.com/clientside-services/index.html"}};this._dataLayer=at(t,v),this._subscriptionService=new ht(t,this._dataLayer);this._networkClient=new Ze(t,this._dataLayer,m.endpoints.sdkBackendURL,(function(){var e,t,r,n;return{stytch_user_id:null===(t=null===(e=o._dataLayer.state)||void 0===e?void 0:e.user)||void 0===t?void 0:t.user_id,stytch_session_id:null===(n=null===(r=o._dataLayer.state)||void 0===r?void 0:r.session)||void 0===n?void 0:n.session_id}}));var _=new mt(t,this._networkClient,this._dataLayer),g=new yt(_.getAsync()),b=new Kt(m.endpoints.clientsideServicesIframeURL),w=new Mt(t,b),k=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 pt(this._dataLayer,"magic_links"),_.getAsync(),g.executeRecaptcha),this.otps=new Se(this._networkClient,this._subscriptionService,g.executeRecaptcha),this.oauth=new Bt(this._networkClient,this._subscriptionService,new pt(this._dataLayer,"oauth"),_.getAsync(),{publicToken:t,testAPIURL:m.endpoints.testAPIURL,liveAPIURL:m.endpoints.liveAPIURL},w),this.cryptoWallets=new Oe(this._networkClient,this._subscriptionService,g.executeRecaptcha),this.totps=new Te(this._networkClient,this._subscriptionService),this.webauthn=new Ve(this._networkClient,this._subscriptionService),this.passwords=new $e(this._networkClient,this._subscriptionService,new pt(this._dataLayer,"passwords"),_.getAsync(),g.executeRecaptcha),this._sessionManager=new ve(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}}),Nt(this,{bootstrap:_,clientsideServices:b,captcha:g,oneTap:w,userSearch:k,publicToken:t})}));exports.SDKAPIUnreachableError=At,exports.StytchHeadlessClient=qt,exports.StytchSDKAPIError=Lt,exports.StytchSDKNativeError=Dt,exports.StytchSDKSchemaError=jt,exports.StytchSDKUsageError=Rt,exports.UNRECOVERABLE_ERROR_TYPES=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];
|
|
5
|
+
function et(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 tt=function e(t,r){function n(e,n,o){if("undefined"!=typeof document){"number"==typeof(o=et({},r,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var s in o)o[s]&&(i+="; "+s,!0!==o[s]&&(i+="="+o[s].split(";")[0]));return document.cookie=e+"="+t.write(n,e)+i}}return Object.create({set:n,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},o=0;o<r.length;o++){var i=r[o].split("="),s=i.slice(1).join("=");try{var a=decodeURIComponent(i[0]);if(n[a]=t.read(s,a),e===a)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",et({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,et({},this.attributes,t))},withConverter:function(t){return e(et({},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:"/"}),rt="stytch_sdk_state_",nt=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"".concat(rt).concat(e).concat(t?"::".concat(t):"")},ot=function(){function e(t,r){var n=this;h(this,e),this.browserSessionStorage={getItem:function(e){return sessionStorage.getItem(nt(n.publicToken,e))},setItem:function(e,t){return sessionStorage.setItem(nt(n.publicToken,e),t)},removeItem:function(e){return sessionStorage.removeItem(nt(n.publicToken,e))}},this.publicToken=t,this.state=null,this.subscriptions={},(null==r?void 0:r.cookieOptions)?(he("SubscriptionDataLayer").isOptionalString("cookieOptions.opaqueTokenCookieName",r.cookieOptions.opaqueTokenCookieName).isOptionalString("cookieOptions.jwtCookieName",r.cookieOptions.jwtCookieName).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._opaqueTokenCookieName=null,this._jwtCookieName=null,this._cookiePath=null,this._cookieAvailableToSubdomains=!1);var o=localStorage.getItem(nt(this.publicToken));if(o){var i;try{i=JSON.parse(o)}catch(e){return this.syncToLocalStorage(),void this.removeSessionCookie()}this.state=i}else this.removeSessionCookie()}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:"readSessionCookie",value:function(){return{session_token:tt.get(this.opaqueTokenCookieName),session_jwt:tt.get(this.jwtCookieName)}}},{key:"writeSessionCookie",value:function(t){var r,n,o,i,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});tt.set(this.opaqueTokenCookieName,a,u),tt.set(this.jwtCookieName,c,u);var l=e.generateCookieOpts({expiresAt:null!==(i=null===(o=null==s?void 0:s.session)||void 0===o?void 0:o.expires_at)&&void 0!==i?i:"",availableToSubdomains:!this._cookieAvailableToSubdomains,path:this._cookiePath});Qe(this.jwtCookieName)&&tt.remove(this.jwtCookieName,l),Qe(this.opaqueTokenCookieName)&&tt.remove(this.opaqueTokenCookieName,l),Qe(this.jwtCookieName)&&ue.warn("Could not remove extraneous JWT cookie. This might happen if the cookie has been set using multiple `path` settings, and may produce unwanted behavior."),Qe(this.opaqueTokenCookieName)&&ue.warn("Could not remove extraneous opaque token cookie.")}},{key:"removeSessionCookie",value:function(){var t=this;[!0,!1].forEach((function(r){[t._cookiePath,null].forEach((function(n){var o=e.generateCookieOpts({expiresAt:new Date(0).toString(),availableToSubdomains:r,path:n});tt.remove(t.opaqueTokenCookieName,o),tt.remove(t.jwtCookieName,o)}))}))}},{key:"syncToLocalStorage",value:function(){localStorage.setItem(nt(this.publicToken),JSON.stringify(this.state))}},{key:"getItem",value:function(e){return localStorage.getItem(nt(this.publicToken,e))}},{key:"setItem",value:function(e,t){return localStorage.setItem(nt(this.publicToken,e),t)}},{key:"removeItem",value:function(e){return localStorage.removeItem(nt(this.publicToken,e))}}],[{key:"generateCookieOpts",value:function(e){var t=e.path,r=e.availableToSubdomains,n=e.expiresAt,o={expires:new Date(n),sameSite:"lax"};return t&&(o.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}$/))?o.secure=!1:(r&&(o.domain=window.location.host),o.secure=!0),o}}]),e}(),it=function(e){t(o,ot);var r=n(o);function o(){return h(this,o),r.apply(this,arguments)}return p(o)}(),st=Symbol.for("__stytch_DataLayer"),at=function(e,t){var r,n=((r=window)[st]||(r[st]={}),r[st]);return n[e]||(n[e]=new it(e,t)),n[e]},ct=function(e,t){Object.values(e).forEach((function(e){return e(t)}))},ut=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 _(r)===_(n)&&(null===r||null===n?r===n:"object"===_(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=y(e,1)[0];return!t.includes(r)})).every((function(t){var r=y(t,2),o=r[0],i=r[1];return e(i,n[o])})):r===n)}}({KEYS_TO_EXCLUDE:["last_accessed_at"]}),lt=function(){function e(t,r){var n,o=this;h(this,e),this._publicToken=t,this._datalayer=r,this._listen=function(e){if(e.key===nt(o._publicToken))if(null!==e.newValue&&"null"!==e.newValue){var t=JSON.parse(e.newValue);o.updateState(t)}else o.destroyState()},window.addEventListener("storage",this._listen);var i=null===(n=this._datalayer.state)||void 0===n?void 0:n.session;i&&Date.parse(i.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 t&&r?{session_token:t,session_jwt:r}:null}},{key:"destroyState",value:function(){this.updateStateAndTokens({state:null,session_token:null,session_jwt: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,ut(t,r)||ct(this._datalayer.subscriptions,r)}},{key:"updateStateAndTokens",value:function(e){e.state?this._datalayer.writeSessionCookie(e):this._datalayer.removeSessionCookie(),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,ut(t,r)||(ct(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(),o=Object.assign(Object.assign({},n),{session_token:t,session_jwt:r});t&&r?this._datalayer.writeSessionCookie(o):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}(),ht=function(e){t(o,lt);var r=n(o);function o(){var e;return h(this,o),(e=r.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(o)}();function dt(e){var t=e.toString(16);return 1===t.length&&(t="0"+t),t}var pt=function(){function t(e,r){h(this,t),this._dataLayer=e,this.namespace=r}return p(t,[{key:"key",value:function(){return"PKCE_VERIFIER:"+this.namespace}},{key:"startPKCETransaction",value:function(){return Xe(this,void 0,void 0,l().mark((function e(){var r;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.createProofkeyPair();case 2:return r=e.sent,this._dataLayer.setItem(this.key(),JSON.stringify(r)),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)})))}},{key:"getPKPair",value:function(){var e=this._dataLayer.getItem(this.key());if(null!==e)try{return JSON.parse(e)}catch(e){return void ue.warn("Found malformed Proof Key pair in localstorage.")}}},{key:"clearPKPair",value:function(){return this._dataLayer.removeItem(this.key())}}],[{key:"createProofkeyPair",value:function(){return Xe(this,void 0,void 0,l().mark((function t(){var r,n,o;return l().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=new Uint32Array(16),window.crypto.getRandomValues(r),n=Array.from(r).map(dt).join(""),t.next=5,window.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(n));case 5:return o=t.sent,t.abrupt("return",{code_challenge:(i=o,s=void 0,btoa((s=String.fromCharCode).call.apply(s,[null].concat(e(new Uint8Array(i))))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),code_verifier:n});case 7:case"end":return t.stop()}var i,s}),t)})))}}]),t}(),ft="bootstrap",vt=function(){return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1}},yt=function(){function e(t,r,n){var o=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 o._dataLayer.setItem(ft,JSON.stringify(e)),e})).catch((function(e){return ue.error(e),vt()}))}return p(e,[{key:"getSync",value:function(){var e=this._dataLayer.getItem(ft);if(null===e)return vt();try{return JSON.parse(e)}catch(e){return vt()}}},{key:"getAsync",value:function(){return this._bootstrapDataPromise}}],[{key:"mapBootstrapData",value:function(e){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}}}]),e}(),_t=p((function e(t){var r=this;h(this,e),this.bootstrapPromise=t,this.executeRecaptcha=function(){return Xe(r,void 0,void 0,l().mark((function e(){var t,r,n,o;return l().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,o=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(o,{action:"LOGIN"}));case 11:case"end":return e.stop()}}),e,this)})))},this.state=t.then((function(e){return Xe(r,void 0,void 0,l().mark((function t(){return l().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,ie("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)})))}))}));function mt(e){return mt="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},mt(e)}function gt(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,(o=n.key,i=void 0,i=function(e,t){if("object"!==mt(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==mt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===mt(i)?i:String(i)),n)}var o,i}function bt(e,t,r){return t&>(e.prototype,t),r&>(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function wt(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function kt(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&&Ct(e,t)}function St(e){var t=Et();return function(){var r,n=Pt(e);if(t){var o=Pt(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===mt(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return xt(e)}(this,r)}}function xt(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ot(e){var t="function"==typeof Map?new Map:void 0;return Ot=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 Tt(e,arguments,Pt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),Ct(n,e)},Ot(e)}function Tt(e,t,r){return Tt=Et()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&Ct(o,r.prototype),o},Tt.apply(null,arguments)}function Et(){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 Ct(e,t){return Ct=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},Ct(e,t)}function Pt(e){return Pt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Pt(e)}exports.Products=void 0,function(e){e.emailMagicLinks="emailMagicLinks",e.oauth="oauth",e.otp="otp",e.crypto="crypto",e.passwords="passwords"}(exports.Products||(exports.Products={})),exports.OAuthProviders=void 0,function(e){e.Google="google",e.Microsoft="microsoft",e.Apple="apple",e.Github="github",e.GitLab="gitlab",e.Facebook="facebook",e.Discord="discord",e.Slack="slack",e.Amazon="amazon",e.Bitbucket="bitbucket",e.LinkedIn="linkedin",e.Coinbase="coinbase",e.Twitch="twitch"}(exports.OAuthProviders||(exports.OAuthProviders={})),exports.Wallets=void 0,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"}(exports.Wallets||(exports.Wallets={})),exports.OneTapPositions=void 0,function(e){e.embedded="embedded",e.floating="floating"}(exports.OneTapPositions||(exports.OneTapPositions={})),exports.OTPMethods=void 0,function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(exports.OTPMethods||(exports.OTPMethods={})),exports.StytchEventType=void 0,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"}(exports.StytchEventType||(exports.StytchEventType={}));var At=function(e){kt(r,Ot(Error));var t=St(r);function r(e,n){var o;return wt(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(xt(o),r.prototype),o}return bt(r)}(),jt=function(e){kt(r,Ot(Error));var t=St(r);function r(e,n){var o;return wt(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return bt(r)}(),Rt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n,o;wt(this,r),(n=t.call(this)).name="StytchSDKSchemaError";var i=null===(o=e.body)||void 0===o?void 0:o.map((function(e){return"".concat(e.dataPath,": ").concat(e.message)})).join("\n");return n.message="[400] Request does not match expected schema\n".concat(i),n}return bt(r)}(),Lt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n;wt(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,s=e.error_message,a=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=s,n.error_url=a,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(s,"\n")+"See ".concat(a," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return bt(r)}(),Dt=function(e){kt(r,Ot(Error));var t=St(r);function r(e){var n;return wt(this,r),(n=t.call(this)).name="StytchSDKNativeError",n.error_type=e,n.message="".concat(e),n}return bt(r)}();exports.BiometricsErrors=void 0,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"}(exports.BiometricsErrors||(exports.BiometricsErrors={}));var It=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 Xe(this,void 0,void 0,l().mark((function e(){var o,i=this;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={client_id:this._clientId,callback:t,auto_select:!1,context:"use",itp_support:!0},n.position===exports.OneTapPositions.embedded&&(o.prompt_parent_id="google-parent-prompt",o.cancel_on_tap_outside=!1),this._googleClient.initialize(o),e.abrupt("return",new Promise((function(e){i._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()}):(i.styleFrame(n),e({success:!0}))}))})));case 4:case"end":return e.stop()}}),e,this)})))}},{key:"styleFrame",value:function(e){e.position===exports.OneTapPositions.embedded&&Array.from(document.getElementsByTagName("iframe")).forEach((function(e){e.src.includes(N)&&(e.style.width="100%")}))}}]),e}(),Mt=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,o=e.onSuccess;return function(e){return Xe(n,void 0,void 0,l().mark((function n(){var i,s,a;return l().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.credential,n.next=3,this.submitGoogleOneTapToken({credential:i,loginRedirectUrl:t,signupRedirectUrl:r});case 3:s=n.sent,a=s.redirect_url,o(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 Xe(this,void 0,void 0,l().mark((function e(){var t,r,n,o;return l().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=It,e.next=16,ie(K,(function(){return window.google.accounts.id}));case 16:return e.t2=e.sent,e.t3=this._publicToken,e.t4=t,o=new e.t1(e.t2,e.t3,e.t4),e.abrupt("return",{success:!0,client:o});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 Xe(this,void 0,void 0,l().mark((function e(){var o,i;return l().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.fetchGoogleStart();case 2:return o=e.sent,i=o.oauthCallbackId,e.abrupt("return",this.clientsideServices.oneTapSubmit({publicToken:this._publicToken,idToken:t,loginRedirectURL:r,oauthCallbackID:i,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}(),Ut=Symbol.for("stytch__internal"),Nt=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}({},Ut,t))},Kt=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 $(this.iframeURL),this._frameClient}},{key:"call",value:function(e,t){return this.frameClient.call(e,[t])}}]),e}(),Ft=function(){function e(t){h(this,e),this._networkClient=t}return p(e,[{key:"search",value:function(e){return this._networkClient.fetchSDK({url:"/users/search",method:"POST",body:{email:e},errorMessage:"Error searching for user ".concat(e)})}}]),e}(),Bt=function(e){t(i,xe);var r=n(i);function i(e,t,n,s,a,c){var u;return h(this,i),(u=r.call(this,e,t,n,s,a))._oneTap=c,u.startOneTap=function(e){return Xe(o(u),void 0,void 0,l().mark((function t(){var r,n,o;return l().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,o=this._oneTap.createOnSuccessHandler({signupRedirectUrl:e.signup_redirect_url,loginRedirectUrl:e.login_redirect_url,onSuccess:this._oneTap.RedirectOnSuccess}),t.abrupt("return",n.render({style:{position:exports.OneTapPositions.floating},onOneTapCancelled:e.onOneTapCancelled,callback:o}));case 8:case"end":return t.stop()}}),t,this)})))},u.googleOneTap={start:u.startOneTap},u}return p(i)}(),qt=p((function e(t,r){var n,o=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)?ue.warn("Public token is malformed. Expected a string, got ".concat(_(n),".").concat(le)):""===n?ue.warn('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(le)):n.startsWith("public-token-")||ue.warn('Public token is malformed. Expected "public-token-...", got '.concat(n,".").concat(le));var i,s,a,c,u,l,d,p,f,v=r,y={cookieOptions:null==(i=v)?void 0:i.cookieOptions,endpoints:{sdkBackendURL:null!==(a=null===(s=null==i?void 0:i.endpoints)||void 0===s?void 0:s.sdkBackendURL)&&void 0!==a?a:"https://web.stytch.com",testAPIURL:null!==(u=null===(c=null==i?void 0:i.endpoints)||void 0===c?void 0:c.testAPIURL)&&void 0!==u?u:"https://test.stytch.com",liveAPIURL:null!==(d=null===(l=null==i?void 0:i.endpoints)||void 0===l?void 0:l.liveAPIURL)&&void 0!==d?d:"https://api.stytch.com",clientsideServicesIframeURL:null!==(f=null===(p=null==i?void 0:i.endpoints)||void 0===p?void 0:p.clientsideServicesIframeURL)&&void 0!==f?f:"https://js.stytch.com/clientside-services/index.html"}};this._dataLayer=at(t,v),this._subscriptionService=new ht(t,this._dataLayer);this._networkClient=new Ze(t,this._dataLayer,y.endpoints.sdkBackendURL,(function(){var e,t,r,n;return{stytch_user_id:null===(t=null===(e=o._dataLayer.state)||void 0===e?void 0:e.user)||void 0===t?void 0:t.user_id,stytch_session_id:null===(n=null===(r=o._dataLayer.state)||void 0===r?void 0:r.session)||void 0===n?void 0:n.session_id}}));var m=new yt(t,this._networkClient,this._dataLayer),g=new _t(m.getAsync()),b=new Kt(y.endpoints.clientsideServicesIframeURL),w=new Mt(t,b),k=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 pt(this._dataLayer,"magic_links"),m.getAsync(),g.executeRecaptcha),this.otps=new Se(this._networkClient,this._subscriptionService,g.executeRecaptcha),this.oauth=new Bt(this._networkClient,this._subscriptionService,new pt(this._dataLayer,"oauth"),m.getAsync(),{publicToken:t,testAPIURL:y.endpoints.testAPIURL,liveAPIURL:y.endpoints.liveAPIURL},w),this.cryptoWallets=new Oe(this._networkClient,this._subscriptionService,g.executeRecaptcha),this.totps=new Te(this._networkClient,this._subscriptionService),this.webauthn=new ze(this._networkClient,this._subscriptionService),this.passwords=new $e(this._networkClient,this._subscriptionService,new pt(this._dataLayer,"passwords"),m.getAsync(),g.executeRecaptcha),this._sessionManager=new ve(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}}),Nt(this,{bootstrap:m,clientsideServices:b,captcha:g,oneTap:w,userSearch:k,publicToken:t})}));exports.SDKAPIUnreachableError=At,exports.StytchHeadlessClient=qt,exports.StytchSDKAPIError=Lt,exports.StytchSDKNativeError=Dt,exports.StytchSDKSchemaError=Rt,exports.StytchSDKUsageError=jt,exports.UNRECOVERABLE_ERROR_TYPES=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];
|