@stytch/vanilla-js 0.11.2 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -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 +6 -5
package/dist/b2b/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";function e(t){return e="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(t)}function t(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||h(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){if("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&&n(e,t)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function o(t){var r=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 n,o=i(t);if(r){var a=i(this).constructor;n=Reflect.construct(o,arguments,a)}else n=o.apply(this,arguments);return function(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(this,n)}}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function a(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */a=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function l(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,r){return e[t]=r}}function h(e,t,r,n){var i=t&&t.prototype instanceof p?t:p,a=Object.create(i.prototype),s=new T(n||[]);return o(a,"_invoke",{value:S(e,r,s)}),a}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=h;var d={};function p(){}function v(){}function m(){}var y={};l(y,s,(function(){return this}));var _=Object.getPrototypeOf,b=_&&_(_(P([])));b&&b!==r&&n.call(b,s)&&(y=b);var g=m.prototype=p.prototype=Object.create(y);function k(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function w(t,r){function i(o,a,s,c){var u=f(t[o],t,a);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==e(h)&&n.call(h,"__await")?r.resolve(h.__await).then((function(e){i("next",e,s,c)}),(function(e){i("throw",e,s,c)})):r.resolve(h).then((function(e){l.value=e,s(l)}),(function(e){return i("throw",e,s,c)}))}c(u.arg)}var a;o(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){i(e,t,r,n)}))}return a=a?a.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 C()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=O(a,r);if(s){if(s===d)continue;return s}}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=f(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var o=f(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;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,d):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function E(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function P(e){if(e){var t=e[s];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,o=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return o.next=o}}return{next:C}}function C(){return{value:void 0,done:!0}}return v.prototype=m,o(g,"constructor",{value:m,configurable:!0}),o(m,"constructor",{value:v,configurable:!0}),v.displayName=l(m,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,l(e,u,"GeneratorFunction")),e.prototype=Object.create(g),e},t.awrap=function(e){return{__await:e}},k(w.prototype),l(w.prototype,c,(function(){return this})),t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(h(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(g),l(g,u,"Generator"),l(g,s,(function(){return this})),l(g,"toString",(function(){return"[object Generator]"})),t.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}},t.values=P,T.prototype={constructor:T,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(x),!e)for(var t in this)"t"===t.charAt(0)&&n.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 r(r,n){return a.type="throw",a.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],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.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 a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},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),d},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),x(r),d}},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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},t}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(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,d(n.key),n)}}function u(e,t,r){return t&&c(e.prototype,t),r&&c(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(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,a,s=[],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)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(e,t)||h(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 h(e,t){if(e){if("string"==typeof e)return f(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)?f(e,t):void 0}}function f(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 d(t){var r=function(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,r||"default");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"===e(r)?r:String(r)}function p(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,a,s=[],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)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw o}}return s}}(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 v(e){return v="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},v(e)}function m(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
3
|
-
_=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",a=o.asyncIterator||"@@asyncIterator",s=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 f?t:f,a=Object.create(i.prototype),s=new T(o||[]);return n(a,"_invoke",{value:S(e,r,s)}),a}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 f(){}function d(){}function p(){}var m={};c(m,i,(function(){return this}));var y=Object.getPrototypeOf,b=y&&y(y(P([])));b&&b!==t&&r.call(b,i)&&(m=b);var g=p.prototype=f.prototype=Object.create(m);function k(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function o(n,i,a,s){var c=l(e[n],e,i);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==v(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,a,s)}),(function(e){o("throw",e,a,s)})):t.resolve(h).then((function(e){u.value=e,a(u)}),(function(e){return o("throw",e,a,s)}))}s(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 C()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=O(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var 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 E(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function P(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:C}}function C(){return{value:void 0,done:!0}}return d.prototype=p,n(g,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:d,configurable:!0}),d.displayName=c(p,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},k(w.prototype),c(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(g),c(g,s,"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=P,T.prototype={constructor:T,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(x),!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 a.type="throw",a.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],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){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 a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},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),x(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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},e}function b(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"!==v(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==v(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===v(i)?i:String(i)),n)}var o,i}function g(e,t,r){return t&&b(e.prototype,t),r&&b(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&P(e,t)}function S(e){var t=T();return function(){var r,n=C(e);if(t){var o=C(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===v(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 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 x(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),P(n,e)},E(e)}function x(e,t,r){return x=T()?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&&P(o,r.prototype),o},x.apply(null,arguments)}function T(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}Object.defineProperty(exports,"__esModule",{value:!0});var j,L,A,R,I,D;!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"}(A||(A={})),function(e){e.embedded="embedded",e.floating="floating"}(R||(R={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(I||(I={})),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"}(D||(D={}));var N,M,B=function(e){w(r,E(Error));var t=S(r);function r(e,n){var o;return k(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(O(o),r.prototype),o}return g(r)}(),U=function(e){w(r,E(Error));var t=S(r);function r(e,n){var o;return k(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return g(r)}(),K=function(e){w(r,E(Error));var t=S(r);function r(e){var n,o;k(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 g(r)}(),F=function(e){w(r,E(Error));var t=S(r);function r(e){var n;k(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,a=e.error_message,s=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=a,n.error_url=s,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(a,"\n")+"See ".concat(s," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return g(r)}(),q=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];function z(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(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(a,s)}c((n=n.apply(e,t||[])).next())}))}!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"}(N||(N={}));var G=new Uint8Array(16);function W(){if(!M&&!(M="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return M(G)}var H=/^(?:[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 V=[],Y=0;Y<256;++Y)V.push((Y+256).toString(16).substr(1));function J(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(V[e[t+0]]+V[e[t+1]]+V[e[t+2]]+V[e[t+3]]+"-"+V[e[t+4]]+V[e[t+5]]+"-"+V[e[t+6]]+V[e[t+7]]+"-"+V[e[t+8]]+V[e[t+9]]+"-"+V[e[t+10]]+V[e[t+11]]+V[e[t+12]]+V[e[t+13]]+V[e[t+14]]+V[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&H.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function $(e,t,r){var n=(e=e||{}).random||(e.rng||W)();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 J(n)}var X=["[Stytch]"],Z={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,X.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,X.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,X.concat(r))}},Q="\nYou can find your public token at https://stytch.com/dashboard/api-keys.",ee=function(e){var t={isObject:function(r,n){var o="object"===v(n)&&!Array.isArray(n)&&null!==n;if(!o)throw new U(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 U(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 U(e,r+" must be an array of strings.");var o,i=function(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,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}(n);try{for(i.s();!(o=i.n()).done;){if("string"!=typeof o.value)throw new U(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 U(e,r+" must be a number.");return t},isOptionalNumber:function(e,r){return void 0===r?t:t.isNumber(e,r)}};return t};function te(e){var t=e.method,r=e.errorMessage,n=e.finalURL,o=e.basicAuthHeader,i=e.xSDKClientHeader,a=e.xSDKParentHostHeader,s=e.body;return z(this,void 0,void 0,_().mark((function e(){var c,u,l,h,f;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={Authorization:o,"Content-Type":"application/json","X-SDK-Client":i},a&&(c["X-SDK-Parent-Host"]=a),u={method:t,headers:c,body:s&&JSON.stringify(s)},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 K(h);case 26:throw new F(h);case 27:return e.prev=27,e.next=30,l.json();case 30:return f=e.sent,e.abrupt("return",f.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 re=function(){function e(t,r){var n=this;k(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 g(e,[{key:"performBackgroundRefresh",value:function(){var e=this;this._reauthenticateWithBackoff().then((function(){e.scheduleBackgroundRefresh()})).catch((function(){Z.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 q.includes(e.error_type)}}]),e}();re.REFRESH_INTERVAL_MS=18e4;var ne=15,oe=800,ie=function(){function e(t){k(this,e),this.maxBatchSize=t.maxBatchSize,this.logEventURL=t.logEventURL,setInterval(this.flush.bind(this),t.intervalDurationMs),this.batch=[]}return g(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,_().mark((function e(){var t;return _().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}();Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),Promise.resolve({pkceRequiredForPasswordResets:!1});var ae=Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),se=function(){function e(t,r,n){var o=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ae;k(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=i,this.email={loginOrSignup:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.magicLinks.email.loginOrSignup").isString("email",e.email_address).isString("organization_id",e.organization_id).isOptionalString("login_redirect_url",e.login_redirect_url).isOptionalString("login_template_id",e.login_template_id).isOptionalString("signup_redirect_url",e.signup_redirect_url).isOptionalString("signup_template_id",e.signup_template_id),t.next=3,this.getCodeChallenge();case 3:return r=t.sent,n=Object.assign(Object.assign({},e),{pkce_code_challenge:r}),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/magic_links/email/login_or_signup",body:n,errorMessage:"Failed to send magic link",method:"POST"}));case 6:case"end":return t.stop()}}),t,this)})))},discovery:{send:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.magicLinks.email.discovery.send").isString("email_address",e.email_address).isOptionalString("discovery_redirect_url",e.discovery_redirect_url).isOptionalString("login_template_id",e.login_template_id),t.next=3,this.getCodeChallenge();case 3:return r=t.sent,n=Object.assign(Object.assign({},e),{pkce_code_challenge:r}),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/magic_links/email/discovery/send",body:n,errorMessage:"Failed to send discovery magic link",method:"POST"}));case 6:case"end":return t.stop()}}),t,this)})))}}},this.authenticate=function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n,o;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.magicLinks.authenticate").isString("magic_links_token",e.magic_links_token).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._pkceManager.getPKPair();case 3:return r=t.sent,n=Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),t.next=7,this._networkClient.fetchSDK({url:"/b2b/magic_links/authenticate",body:n,errorMessage:"Failed to authenticate token",method:"POST"});case 7:return o=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:o.member_session,member:o.member},session_token:o.session_token,session_jwt:o.session_jwt}),t.abrupt("return",o);case 11:case"end":return t.stop()}}),t,this)})))},this.discovery={authenticate:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n,o;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.magicLinks.discovery.authenticate").isString("discovery_magic_links_token",e.discovery_magic_links_token),t.next=3,this._pkceManager.getPKPair();case 3:return r=t.sent,n=Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),t.next=7,this._networkClient.fetchSDK({url:"/b2b/magic_links/discovery/authenticate",body:n,errorMessage:"Failed to authenticate intermediate magic link token",method:"POST"});case 7:return o=t.sent,this._pkceManager.clearPKPair(),t.abrupt("return",o);case 10:case"end":return t.stop()}}),t,this)})))}}}return g(e,[{key:"getCodeChallenge",value:function(){return z(this,void 0,void 0,_().mark((function e(){var t,r;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._config;case 2:if(t=e.sent,t.pkceRequiredForEmailMagicLinks){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)})))}}]),e}(),ce=g((function e(t,r){var n=this;k(this,e),this._networkClient=t,this._subscriptionService=r,this.get=function(){return z(n,void 0,void 0,_().mark((function e(){var t;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._networkClient.fetchSDK({url:"/b2b/organizations/members/me",errorMessage:"Failed to retrieve member info.",method:"GET"});case 2:return t=e.sent,this._subscriptionService.updateMember(t.member),e.abrupt("return",t.member);case 5:case"end":return e.stop()}}),e,this)})))},this.getSync=function(){return n._subscriptionService.getMember()},this.onChange=function(e){return n._subscriptionService.subscribeToState((function(t){var r;return e(null!==(r=null==t?void 0:t.member)&&void 0!==r?r:null)}))}})),ue=function(){function e(t,r,n,o,i){k(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._dynamicConfig=o,this._config=i}return g(e,[{key:"authenticate",value:function(e){return z(this,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.sso.authenticate").isString("sso_token",e.sso_token).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._pkceManager.getPKPair();case 3:return(r=t.sent)||Z.warn("No code verifier found in local storage for SSO 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."),t.next=7,this._networkClient.fetchSDK({url:"/sso/authenticate",method:"POST",body:Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),errorMessage:"Failed to authenticate token"});case 7:return n=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:n.member_session,member:n.member},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",n);case 11:case"end":return t.stop()}}),t,this)})))}},{key:"getBaseApiUrl",value:function(){return z(this,void 0,void 0,_().mark((function e(){return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._config.publicToken.includes("public-token-test")){e.next=2;break}return e.abrupt("return",this._config.testAPIURL);case 2:return e.abrupt("return",this._config.liveAPIURL);case 3:case"end":return e.stop()}}),e,this)})))}},{key:"start",value:function(e){var t=e.connection_id,r=e.login_redirect_url,n=e.signup_redirect_url;return z(this,void 0,void 0,_().mark((function e(){var o,i,a,s,c;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._dynamicConfig;case 2:return o=e.sent,i=o.pkceRequiredForSso,e.next=6,this.getBaseApiUrl();case 6:if(a=e.sent,(s=new URL("".concat(a,"/v1/public/sso/start"))).searchParams.set("public_token",this._config.publicToken),s.searchParams.set("connection_id",t),!i){e.next=17;break}return e.next=13,this._pkceManager.startPKCETransaction();case 13:c=e.sent,s.searchParams.set("pkce_code_challenge",c.code_challenge),e.next=18;break;case 17:this._pkceManager.clearPKPair();case 18:r&&s.searchParams.set("login_redirect_url",r),n&&s.searchParams.set("signup_redirect_url",n),window.location.href=s.toString();case 21:case"end":return e.stop()}}),e,this)})))}}]),e}(),le=g((function e(t){var r=this;k(this,e),this._networkClient=t,this.get=function(){return z(r,void 0,void 0,_().mark((function e(){var t;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._networkClient.fetchSDK({url:"/b2b/organizations/me",errorMessage:"Failed to retrieve organization info.",method:"GET"});case 2:return t=e.sent,e.abrupt("return",t.organization);case 4:case"end":return e.stop()}}),e,this)})))}})),he=function(){function e(t,r){var n=this;k(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 z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this._networkClient.fetchSDK({url:"/b2b/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)||q.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,_().mark((function t(){var r,n;return _().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:"/b2b/sessions/authenticate",body:r,errorMessage:"Error authenticating session",method:"POST"});case 4:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.member_session,member:n.member},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",n);case 9:throw t.prev=9,t.t0=t.catch(0),q.includes(t.t0.error_type)&&this._subscriptionService.destroyState(),t.t0;case 13:case"end":return t.stop()}}),t,this,[[0,9]])})))},this.exchange=function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.sessions.exchange").isString("organization_id",e.organization_id).isNumber("session_duration_minutes",e.session_duration_minutes),t.prev=1,t.next=4,this._networkClient.fetchSDK({url:"/b2b/sessions/exchange",body:e,errorMessage:"Failed to exchange session",method:"POST"});case 4:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 9:throw t.prev=9,t.t0=t.catch(1),t.t0;case 12:case"end":return t.stop()}}),t,this,[[1,9]])})))}}return g(e,[{key:"getTokens",value:function(){return this._subscriptionService.getTokens()}}]),e}(),fe=g((function e(t,r){var n=this;k(this,e),this._networkClient=t,this._subscriptionService=r,this.organizations={list:function(e){return z(n,void 0,void 0,_().mark((function t(){return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.discovery.organizations.list").isOptionalString("intermediate_session_token",e.intermediate_session_token),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/discovery/organizations",body:e,errorMessage:"Failed to retrieve discovered organizations",method:"POST"}));case 2:case"end":return t.stop()}}),t,this)})))},create:function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.discovery.organizations.create").isString("intermediate_session_token",e.intermediate_session_token).isNumber("session_duration_minutes",e.session_duration_minutes).isString("organization_name",e.organization_name).isString("organization_slug",e.organization_slug).isOptionalString("organization_logo_url",e.organization_logo_url).isOptionalString("sso_jit_provisioning",e.sso_jit_provisioning).isOptionalStringArray("email_allowed_domains",e.email_allowed_domains).isOptionalString("email_invites",e.email_invites).isOptionalString("auth_methods",e.auth_methods).isOptionalStringArray("allowed_auth_methods",e.allowed_auth_methods),t.next=3,this._networkClient.fetchSDK({url:"/b2b/discovery/organizations/create",body:e,errorMessage:"Failed to create organization and member",method:"POST"});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t,this)})))}},this.intermediateSessions={exchange:function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return ee("stytch.discovery.intermediateSessions.exchange").isString("intermediate_session_token",e.intermediate_session_token).isString("organization_id",e.organization_id).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._networkClient.fetchSDK({url:"/b2b/discovery/intermediate_sessions/exchange",body:e,errorMessage:"Failed to exchange intermediate session",method:"POST"});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t,this)})))}}})),de=Symbol.for("stytch__internal"),pe=function(e,t){Object.assign(e,function(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},de,t))},ve=function(e){return(document.cookie?document.cookie.split("; "):[]).filter((function(t){var r=l(t.split("="),1)[0];return e===r})).length>1};function me(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(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(a,s)}c((n=n.apply(e,t||[])).next())}))}var ye=function(){function e(t,r,n,o){s(this,e),this._publicToken=t,this._subscriptionDataLayer=r,this.baseURL=n,this.additionalTelemetryDataFn=o,this.updateSessionToken=function(){return null},this.eventLogger=new ie({maxBatchSize:ne,intervalDurationMs:oe,logEventURL:this.buildSDKUrl("/events")})}return u(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($()),app_session_id:"app-session-id-".concat($()),persistent_id:"persistent-id-".concat($()),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 me(this,void 0,void 0,a().mark((function e(){var i,s,c,u;return a().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)),c=window.btoa(JSON.stringify(this.createTelemetryBlob())),u=window.location.origin,e.abrupt("return",te({basicAuthHeader:s,body:r,errorMessage:n,finalURL:this.buildSDKUrl(t),method:o,xSDKClientHeader:c,xSDKParentHostHeader:u}));case 5:case"end":return e.stop()}}),e,this)})))}},{key:"buildSDKUrl",value:function(e){return"".concat(this.baseURL,"/sdk/v1").concat(e)}}]),e}();
|
|
3
|
+
_=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",a=o.asyncIterator||"@@asyncIterator",s=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 f?t:f,a=Object.create(i.prototype),s=new T(o||[]);return n(a,"_invoke",{value:S(e,r,s)}),a}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 f(){}function d(){}function p(){}var m={};c(m,i,(function(){return this}));var y=Object.getPrototypeOf,b=y&&y(y(P([])));b&&b!==t&&r.call(b,i)&&(m=b);var g=p.prototype=f.prototype=Object.create(m);function k(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function w(e,t){function o(n,i,a,s){var c=l(e[n],e,i);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==v(h)&&r.call(h,"__await")?t.resolve(h.__await).then((function(e){o("next",e,a,s)}),(function(e){o("throw",e,a,s)})):t.resolve(h).then((function(e){u.value=e,a(u)}),(function(e){return o("throw",e,a,s)}))}s(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 C()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=O(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=l(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function O(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var 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 E(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function P(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:C}}function C(){return{value:void 0,done:!0}}return d.prototype=p,n(g,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:d,configurable:!0}),d.displayName=c(p,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},k(w.prototype),c(w.prototype,a,(function(){return this})),e.AsyncIterator=w,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},k(g),c(g,s,"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=P,T.prototype={constructor:T,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(x),!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 a.type="throw",a.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],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),c=r.call(i,"finallyLoc");if(s&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){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 a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},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),x(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;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},e}function b(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"!==v(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==v(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===v(i)?i:String(i)),n)}var o,i}function g(e,t,r){return t&&b(e.prototype,t),r&&b(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function w(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&P(e,t)}function S(e){var t=T();return function(){var r,n=C(e);if(t){var o=C(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===v(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 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 x(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),P(n,e)},E(e)}function x(e,t,r){return x=T()?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&&P(o,r.prototype),o},x.apply(null,arguments)}function T(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function P(e,t){return P=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},P(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}Object.defineProperty(exports,"__esModule",{value:!0});var j,L,A,R,I,D;!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"}(A||(A={})),function(e){e.embedded="embedded",e.floating="floating"}(R||(R={})),function(e){e.SMS="sms",e.WhatsApp="whatsapp",e.Email="email"}(I||(I={})),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"}(D||(D={}));var N,M,B=function(e){w(r,E(Error));var t=S(r);function r(e,n){var o;return k(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(O(o),r.prototype),o}return g(r)}(),U=function(e){w(r,E(Error));var t=S(r);function r(e,n){var o;return k(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return g(r)}(),K=function(e){w(r,E(Error));var t=S(r);function r(e){var n,o;k(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 g(r)}(),F=function(e){w(r,E(Error));var t=S(r);function r(e){var n;k(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,a=e.error_message,s=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=a,n.error_url=s,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(a,"\n")+"See ".concat(s," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return g(r)}(),q=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];function z(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(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(a,s)}c((n=n.apply(e,t||[])).next())}))}!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"}(N||(N={}));var W=new Uint8Array(16);function G(){if(!M&&!(M="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return M(W)}var H=/^(?:[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 V=[],Y=0;Y<256;++Y)V.push((Y+256).toString(16).substr(1));function J(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(V[e[t+0]]+V[e[t+1]]+V[e[t+2]]+V[e[t+3]]+"-"+V[e[t+4]]+V[e[t+5]]+"-"+V[e[t+6]]+V[e[t+7]]+"-"+V[e[t+8]]+V[e[t+9]]+"-"+V[e[t+10]]+V[e[t+11]]+V[e[t+12]]+V[e[t+13]]+V[e[t+14]]+V[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&H.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function $(e,t,r){var n=(e=e||{}).random||(e.rng||G)();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 J(n)}var X=["[Stytch]"],Z=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,X.concat(r))},Q=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,X.concat(r))},ee="\nYou can find your public token at https://stytch.com/dashboard/api-keys.",te=function(e){var t={isObject:function(r,n){var o="object"===v(n)&&!Array.isArray(n)&&null!==n;if(!o)throw new U(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 U(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 U(e,r+" must be an array of strings.");var o,i=function(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,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}(n);try{for(i.s();!(o=i.n()).done;){if("string"!=typeof o.value)throw new U(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 U(e,r+" must be a number.");return t},isOptionalNumber:function(e,r){return void 0===r?t:t.isNumber(e,r)}};return t};function re(e){var t=e.method,r=e.errorMessage,n=e.finalURL,o=e.basicAuthHeader,i=e.xSDKClientHeader,a=e.xSDKParentHostHeader,s=e.body;return z(this,void 0,void 0,_().mark((function e(){var c,u,l,h,f;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={Authorization:o,"Content-Type":"application/json","X-SDK-Client":i},a&&(c["X-SDK-Parent-Host"]=a),u={method:t,headers:c,body:s&&JSON.stringify(s)},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 K(h);case 26:throw new F(h);case 27:return e.prev=27,e.next=30,l.json();case 30:return f=e.sent,e.abrupt("return",f.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 ne=function(){function e(t,r){var n=this;k(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 g(e,[{key:"performBackgroundRefresh",value:function(){var e=this;this._reauthenticateWithBackoff().then((function(){e.scheduleBackgroundRefresh()})).catch((function(){Z("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 q.includes(e.error_type)}}]),e}();ne.REFRESH_INTERVAL_MS=18e4;var oe=function(){function e(t){k(this,e),this.maxBatchSize=t.maxBatchSize,this.logEventURL=t.logEventURL,setInterval(this.flush.bind(this),t.intervalDurationMs),this.batch=[]}return g(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,_().mark((function e(){var t;return _().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}();Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),Promise.resolve({pkceRequiredForPasswordResets:!1});var ie=Promise.resolve({pkceRequiredForEmailMagicLinks:!1}),ae=function(){function e(t,r,n){var o=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:ie;k(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._config=i,this.email={loginOrSignup:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.magicLinks.email.loginOrSignup").isString("email",e.email_address).isString("organization_id",e.organization_id).isOptionalString("login_redirect_url",e.login_redirect_url).isOptionalString("login_template_id",e.login_template_id).isOptionalString("signup_redirect_url",e.signup_redirect_url).isOptionalString("signup_template_id",e.signup_template_id).isOptionalString("locale",e.locale),t.next=3,this.getCodeChallenge();case 3:return r=t.sent,n=Object.assign(Object.assign({},e),{pkce_code_challenge:r}),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/magic_links/email/login_or_signup",body:n,errorMessage:"Failed to send magic link",method:"POST"}));case 6:case"end":return t.stop()}}),t,this)})))},discovery:{send:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.magicLinks.email.discovery.send").isString("email_address",e.email_address).isOptionalString("discovery_redirect_url",e.discovery_redirect_url).isOptionalString("login_template_id",e.login_template_id).isOptionalString("locale",e.locale),t.next=3,this.getCodeChallenge();case 3:return r=t.sent,n=Object.assign(Object.assign({},e),{pkce_code_challenge:r}),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/magic_links/email/discovery/send",body:n,errorMessage:"Failed to send discovery magic link",method:"POST"}));case 6:case"end":return t.stop()}}),t,this)})))}}},this.authenticate=function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n,o;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.magicLinks.authenticate").isString("magic_links_token",e.magic_links_token).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._pkceManager.getPKPair();case 3:return r=t.sent,n=Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),t.next=7,this._networkClient.fetchSDK({url:"/b2b/magic_links/authenticate",body:n,errorMessage:"Failed to authenticate token",method:"POST"});case 7:return o=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:o.member_session,member:o.member},session_token:o.session_token,session_jwt:o.session_jwt}),t.abrupt("return",o);case 11:case"end":return t.stop()}}),t,this)})))},this.discovery={authenticate:function(e){return z(o,void 0,void 0,_().mark((function t(){var r,n,o;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.magicLinks.discovery.authenticate").isString("discovery_magic_links_token",e.discovery_magic_links_token),t.next=3,this._pkceManager.getPKPair();case 3:return r=t.sent,n=Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),t.next=7,this._networkClient.fetchSDK({url:"/b2b/magic_links/discovery/authenticate",body:n,errorMessage:"Failed to authenticate intermediate magic link token",method:"POST"});case 7:return o=t.sent,this._pkceManager.clearPKPair(),t.abrupt("return",o);case 10:case"end":return t.stop()}}),t,this)})))}}}return g(e,[{key:"getCodeChallenge",value:function(){return z(this,void 0,void 0,_().mark((function e(){var t,r;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._config;case 2:if(t=e.sent,t.pkceRequiredForEmailMagicLinks){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)})))}}]),e}(),se=g((function e(t,r){var n=this;k(this,e),this._networkClient=t,this._subscriptionService=r,this.get=function(){return z(n,void 0,void 0,_().mark((function e(){var t;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._networkClient.fetchSDK({url:"/b2b/organizations/members/me",errorMessage:"Failed to retrieve member info.",method:"GET"});case 2:return t=e.sent,this._subscriptionService.updateMember(t.member),e.abrupt("return",t.member);case 5:case"end":return e.stop()}}),e,this)})))},this.getSync=function(){return n._subscriptionService.getMember()},this.onChange=function(e){return n._subscriptionService.subscribeToState((function(t){var r;return e(null!==(r=null==t?void 0:t.member)&&void 0!==r?r:null)}))}})),ce=function(){function e(t,r,n,o,i){k(this,e),this._networkClient=t,this._subscriptionService=r,this._pkceManager=n,this._dynamicConfig=o,this._config=i}return g(e,[{key:"authenticate",value:function(e){return z(this,void 0,void 0,_().mark((function t(){var r,n;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.sso.authenticate").isString("sso_token",e.sso_token).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._pkceManager.getPKPair();case 3:return(r=t.sent)||Z("No code verifier found in local storage for SSO 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."),t.next=7,this._networkClient.fetchSDK({url:"/sso/authenticate",method:"POST",body:Object.assign({pkce_code_verifier:null==r?void 0:r.code_verifier},e),errorMessage:"Failed to authenticate token"});case 7:return n=t.sent,this._pkceManager.clearPKPair(),this._subscriptionService.updateStateAndTokens({state:{session:n.member_session,member:n.member},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",n);case 11:case"end":return t.stop()}}),t,this)})))}},{key:"getBaseApiUrl",value:function(){return z(this,void 0,void 0,_().mark((function e(){return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._config.publicToken.includes("public-token-test")){e.next=2;break}return e.abrupt("return",this._config.testAPIURL);case 2:return e.abrupt("return",this._config.liveAPIURL);case 3:case"end":return e.stop()}}),e,this)})))}},{key:"start",value:function(e){var t=e.connection_id,r=e.login_redirect_url,n=e.signup_redirect_url;return z(this,void 0,void 0,_().mark((function e(){var o,i,a,s,c;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._dynamicConfig;case 2:return o=e.sent,i=o.pkceRequiredForSso,e.next=6,this.getBaseApiUrl();case 6:if(a=e.sent,(s=new URL("".concat(a,"/v1/public/sso/start"))).searchParams.set("public_token",this._config.publicToken),s.searchParams.set("connection_id",t),!i){e.next=17;break}return e.next=13,this._pkceManager.startPKCETransaction();case 13:c=e.sent,s.searchParams.set("pkce_code_challenge",c.code_challenge),e.next=18;break;case 17:this._pkceManager.clearPKPair();case 18:r&&s.searchParams.set("login_redirect_url",r),n&&s.searchParams.set("signup_redirect_url",n),window.location.href=s.toString();case 21:case"end":return e.stop()}}),e,this)})))}}]),e}(),ue=g((function e(t){var r=this;k(this,e),this._networkClient=t,this.get=function(){return z(r,void 0,void 0,_().mark((function e(){var t;return _().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._networkClient.fetchSDK({url:"/b2b/organizations/me",errorMessage:"Failed to retrieve organization info.",method:"GET"});case 2:return t=e.sent,e.abrupt("return",t.organization);case 4:case"end":return e.stop()}}),e,this)})))}})),le=function(){function e(t,r){var n=this;k(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 z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this._networkClient.fetchSDK({url:"/b2b/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)||q.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,_().mark((function t(){var r,n;return _().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:"/b2b/sessions/authenticate",body:r,errorMessage:"Error authenticating session",method:"POST"});case 4:return n=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:n.member_session,member:n.member},session_token:n.session_token,session_jwt:n.session_jwt}),t.abrupt("return",n);case 9:throw t.prev=9,t.t0=t.catch(0),q.includes(t.t0.error_type)&&this._subscriptionService.destroyState(),t.t0;case 13:case"end":return t.stop()}}),t,this,[[0,9]])})))},this.exchange=function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.sessions.exchange").isString("organization_id",e.organization_id).isNumber("session_duration_minutes",e.session_duration_minutes),t.prev=1,t.next=4,this._networkClient.fetchSDK({url:"/b2b/sessions/exchange",body:e,errorMessage:"Failed to exchange session",method:"POST"});case 4:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 9:throw t.prev=9,t.t0=t.catch(1),t.t0;case 12:case"end":return t.stop()}}),t,this,[[1,9]])})))}}return g(e,[{key:"getTokens",value:function(){return this._subscriptionService.getTokens()}}]),e}(),he=g((function e(t,r){var n=this;k(this,e),this._networkClient=t,this._subscriptionService=r,this.organizations={list:function(e){return z(n,void 0,void 0,_().mark((function t(){return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.discovery.organizations.list").isOptionalString("intermediate_session_token",e.intermediate_session_token),t.abrupt("return",this._networkClient.fetchSDK({url:"/b2b/discovery/organizations",body:e,errorMessage:"Failed to retrieve discovered organizations",method:"POST"}));case 2:case"end":return t.stop()}}),t,this)})))},create:function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.discovery.organizations.create").isString("intermediate_session_token",e.intermediate_session_token).isNumber("session_duration_minutes",e.session_duration_minutes).isString("organization_name",e.organization_name).isString("organization_slug",e.organization_slug).isOptionalString("organization_logo_url",e.organization_logo_url).isOptionalString("sso_jit_provisioning",e.sso_jit_provisioning).isOptionalStringArray("email_allowed_domains",e.email_allowed_domains).isOptionalString("email_invites",e.email_invites).isOptionalString("auth_methods",e.auth_methods).isOptionalStringArray("allowed_auth_methods",e.allowed_auth_methods),t.next=3,this._networkClient.fetchSDK({url:"/b2b/discovery/organizations/create",body:e,errorMessage:"Failed to create organization and member",method:"POST"});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t,this)})))}},this.intermediateSessions={exchange:function(e){return z(n,void 0,void 0,_().mark((function t(){var r;return _().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return te("stytch.discovery.intermediateSessions.exchange").isString("intermediate_session_token",e.intermediate_session_token).isString("organization_id",e.organization_id).isNumber("session_duration_minutes",e.session_duration_minutes),t.next=3,this._networkClient.fetchSDK({url:"/b2b/discovery/intermediate_sessions/exchange",body:e,errorMessage:"Failed to exchange intermediate session",method:"POST"});case 3:return r=t.sent,this._subscriptionService.updateStateAndTokens({state:{session:r.member_session,member:r.member},session_token:r.session_token,session_jwt:r.session_jwt}),t.abrupt("return",r);case 6:case"end":return t.stop()}}),t,this)})))}}})),fe=Symbol.for("stytch__internal"),de=function(e,t){Object.assign(e,function(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},fe,t))},pe=function(e){return(document.cookie?document.cookie.split("; "):[]).filter((function(t){var r=l(t.split("="),1)[0];return e===r})).length>1};function ve(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(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(a,s)}c((n=n.apply(e,t||[])).next())}))}var me=function(){function e(t,r,n,o){s(this,e),this._publicToken=t,this._subscriptionDataLayer=r,this.baseURL=n,this.additionalTelemetryDataFn=o,this.updateSessionToken=function(){return null},this.eventLogger=new oe({maxBatchSize:15,intervalDurationMs:800,logEventURL:this.buildSDKUrl("/events")})}return u(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($()),app_session_id:"app-session-id-".concat($()),persistent_id:"persistent-id-".concat($()),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.3"}})}},{key:"fetchSDK",value:function(e){var t=e.url,r=e.body,n=e.errorMessage,o=e.method;return ve(this,void 0,void 0,a().mark((function e(){var i,s,c,u;return a().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)),c=window.btoa(JSON.stringify(this.createTelemetryBlob())),u=window.location.origin,e.abrupt("return",re({basicAuthHeader:s,body:r,errorMessage:n,finalURL:this.buildSDKUrl(t),method:o,xSDKClientHeader:c,xSDKParentHostHeader:u}));case 5:case"end":return e.stop()}}),e,this)})))}},{key:"buildSDKUrl",value:function(e){return"".concat(this.baseURL,"/sdk/v1").concat(e)}}]),e}();
|
|
4
4
|
/*! js-cookie v3.0.1 | MIT */
|
|
5
|
-
function _e(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 be=function e(t,r){function n(e,n,o){if("undefined"!=typeof document){"number"==typeof(o=_e({},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 a in o)o[a]&&(i+="; "+a,!0!==o[a]&&(i+="="+o[a].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("="),a=i.slice(1).join("=");try{var s=decodeURIComponent(i[0]);if(n[s]=t.read(a,s),e===s)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",_e({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,_e({},this.attributes,t))},withConverter:function(t){return e(_e({},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:"/"}),ge="stytch_sdk_state_",ke=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"".concat(ge).concat(e).concat(t?"::".concat(t):"")},we=function(){function e(t,r){var n=this;s(this,e),this.browserSessionStorage={getItem:function(e){return sessionStorage.getItem(ke(n.publicToken,e))},setItem:function(e,t){return sessionStorage.setItem(ke(n.publicToken,e),t)},removeItem:function(e){return sessionStorage.removeItem(ke(n.publicToken,e))}},this.publicToken=t,this.state=null,this.subscriptions={},(null==r?void 0:r.cookieOptions)?(ee("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(ke(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 u(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:be.get(this.opaqueTokenCookieName),session_jwt:be.get(this.jwtCookieName)}}},{key:"writeSessionCookie",value:function(t){var r,n,o,i,a=t.state,s=t.session_token,c=t.session_jwt,u=e.generateCookieOpts({expiresAt:null!==(n=null===(r=null==a?void 0:a.session)||void 0===r?void 0:r.expires_at)&&void 0!==n?n:"",availableToSubdomains:this._cookieAvailableToSubdomains,path:this._cookiePath});be.set(this.opaqueTokenCookieName,s,u),be.set(this.jwtCookieName,c,u);var l=e.generateCookieOpts({expiresAt:null!==(i=null===(o=null==a?void 0:a.session)||void 0===o?void 0:o.expires_at)&&void 0!==i?i:"",availableToSubdomains:!this._cookieAvailableToSubdomains,path:this._cookiePath});ve(this.jwtCookieName)&&be.remove(this.jwtCookieName,l),ve(this.opaqueTokenCookieName)&&be.remove(this.opaqueTokenCookieName,l),ve(this.jwtCookieName)&&Z.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."),ve(this.opaqueTokenCookieName)&&Z.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});be.remove(t.opaqueTokenCookieName,o),be.remove(t.jwtCookieName,o)}))}))}},{key:"syncToLocalStorage",value:function(){localStorage.setItem(ke(this.publicToken),JSON.stringify(this.state))}},{key:"getItem",value:function(e){return localStorage.getItem(ke(this.publicToken,e))}},{key:"setItem",value:function(e,t){return localStorage.setItem(ke(this.publicToken,e),t)}},{key:"removeItem",value:function(e){return localStorage.removeItem(ke(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}(),Se=function(e){r(n,we);var t=o(n);function n(){return s(this,n),t.apply(this,arguments)}return u(n)}(),Oe=Symbol.for("__stytch_b2b_DataLayer"),Ee=function(e,t){var r,n=((r=window)[Oe]||(r[Oe]={}),r[Oe]);return n[e]||(n[e]=new Se(e,t)),n[e]},xe=function(e,t){Object.values(e).forEach((function(e){return e(t)}))},Te=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 v(r)===v(n)&&(null===r||null===n?r===n:"object"===v(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=p(e,1)[0];return!t.includes(r)})).every((function(t){var r=p(t,2),o=r[0],i=r[1];return e(i,n[o])})):r===n)}}({KEYS_TO_EXCLUDE:["last_accessed_at"]}),Pe=function(){function e(t,r){var n,o=this;s(this,e),this._publicToken=t,this._datalayer=r,this._listen=function(e){if(e.key===ke(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 u(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,Te(t,r)||xe(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,Te(t,r)||(xe(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}(),Ce=function(e){r(n,Pe);var t=o(n);function n(){var e;return s(this,n),(e=t.apply(this,arguments)).updateMember=function(t){return e.updateState({member:t})},e.getMember=function(){var t,r;return null!==(r=null===(t=e.getState())||void 0===t?void 0:t.member)&&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 u(n)}();function je(e){var t=e.toString(16);return 1===t.length&&(t="0"+t),t}var Le=function(){function e(t,r){s(this,e),this._dataLayer=t,this.namespace=r}return u(e,[{key:"key",value:function(){return"PKCE_VERIFIER:"+this.namespace}},{key:"startPKCETransaction",value:function(){return me(this,void 0,void 0,a().mark((function t(){var r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.createProofkeyPair();case 2:return r=t.sent,this._dataLayer.setItem(this.key(),JSON.stringify(r)),t.abrupt("return",r);case 5:case"end":return t.stop()}}),t,this)})))}},{key:"getPKPair",value:function(){var e=this._dataLayer.getItem(this.key());if(null!==e)try{return JSON.parse(e)}catch(e){return void Z.warn("Found malformed Proof Key pair in localstorage.")}}},{key:"clearPKPair",value:function(){return this._dataLayer.removeItem(this.key())}}],[{key:"createProofkeyPair",value:function(){return me(this,void 0,void 0,a().mark((function e(){var r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new Uint32Array(16),window.crypto.getRandomValues(r),n=Array.from(r).map(je).join(""),e.next=5,window.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(n));case 5:return o=e.sent,e.abrupt("return",{code_challenge:(i=o,a=void 0,btoa((a=String.fromCharCode).call.apply(a,[null].concat(t(new Uint8Array(i))))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),code_verifier:n});case 7:case"end":return e.stop()}var i,a}),e)})))}}]),e}(),Ae="bootstrap",Re=function(){return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1}},Ie=function(){function e(t,r,n){var o=this;s(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(Ae,JSON.stringify(e)),e})).catch((function(e){return Z.error(e),Re()}))}return u(e,[{key:"getSync",value:function(){var e=this._dataLayer.getItem(Ae);if(null===e)return Re();try{return JSON.parse(e)}catch(e){return Re()}}},{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}(),De=u((function e(t,r){var n,o=this;s(this,e),function(e){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("import { createStytchB2BHeadlessClient } from '@stytch/nextjs/b2b';\n \n const stytch = createStytchB2BHeadlessClient('public-token-...');\n ","\n```\n"))}("StytchB2BHeadlessClient"),"string"!=typeof(n=t)?Z.warn("Public token is malformed. Expected a string, got ".concat(v(n),".").concat(Q)):""===n?Z.warn('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(Q)):n.startsWith("public-token-")||Z.warn('Public token is malformed. Expected "public-token-...", got '.concat(n,".").concat(Q));var i,a,c,u,l,h,f,d,p,m=r,y={cookieOptions:null==(i=m)?void 0:i.cookieOptions,endpoints:{sdkBackendURL:null!==(c=null===(a=null==i?void 0:i.endpoints)||void 0===a?void 0:a.sdkBackendURL)&&void 0!==c?c:"https://web.stytch.com",testAPIURL:null!==(l=null===(u=null==i?void 0:i.endpoints)||void 0===u?void 0:u.testAPIURL)&&void 0!==l?l:"https://test.stytch.com",liveAPIURL:null!==(f=null===(h=null==i?void 0:i.endpoints)||void 0===h?void 0:h.liveAPIURL)&&void 0!==f?f:"https://api.stytch.com",clientsideServicesIframeURL:null!==(p=null===(d=null==i?void 0:i.endpoints)||void 0===d?void 0:d.clientsideServicesIframeURL)&&void 0!==p?p:"https://js.stytch.com/clientside-services/index.html"}};this._dataLayer=Ee(t,m),this._subscriptionService=new Ce(t,this._dataLayer);this._networkClient=new ye(t,this._dataLayer,y.endpoints.sdkBackendURL,(function(){var e,t,r,n;return{stytch_member_id:null===(t=null===(e=o._dataLayer.state)||void 0===e?void 0:e.member)||void 0===t?void 0:t.member_id,stytch_member_session_id:null===(n=null===(r=o._dataLayer.state)||void 0===r?void 0:r.session)||void 0===n?void 0:n.member_session_id}}));var _=new Ie(t,this._networkClient,this._dataLayer);this.organization=new le(this._networkClient),this.member=new ce(this._networkClient,this._subscriptionService),this.session=new he(this._networkClient,this._subscriptionService),this.magicLinks=new se(this._networkClient,this._subscriptionService,new Le(this._dataLayer,"magic_links"),_.getAsync()),this.sso=new ue(this._networkClient,this._subscriptionService,new Le(this._dataLayer,"sso"),_.getAsync(),{publicToken:t,testAPIURL:y.endpoints.testAPIURL,liveAPIURL:y.endpoints.liveAPIURL}),this.discovery=new fe(this._networkClient,this._subscriptionService),this._sessionManager=new re(this._subscriptionService,this.session),this._dataLayer.readSessionCookie().session_token&&this._sessionManager.performBackgroundRefresh(),this._networkClient.logEvent({name:"b2b_sdk_instance_instantiated",details:{event_callback_registered:!1,error_callback_registered:!1,success_callback_registered:!1}}),pe(this,{bootstrap:_,publicToken:t})}));function Ne(e){return Ne="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},Ne(e)}function Me(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"!==Ne(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Ne(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Ne(i)?i:String(i)),n)}var o,i}function Be(e,t,r){return t&&Me(e.prototype,t),r&&Me(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ue(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Ke(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&&He(e,t)}function Fe(e){var t=We();return function(){var r,n=Ve(e);if(t){var o=Ve(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===Ne(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return qe(e)}(this,r)}}function qe(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ze(e){var t="function"==typeof Map?new Map:void 0;return ze=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 Ge(e,arguments,Ve(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),He(n,e)},ze(e)}function Ge(e,t,r){return Ge=We()?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&&He(o,r.prototype),o},Ge.apply(null,arguments)}function We(){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 He(e,t){return He=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},He(e,t)}function Ve(e){return Ve=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Ve(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 Ye=function(e){Ke(r,ze(Error));var t=Fe(r);function r(e,n){var o;return Ue(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(qe(o),r.prototype),o}return Be(r)}(),Je=function(e){Ke(r,ze(Error));var t=Fe(r);function r(e,n){var o;return Ue(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return Be(r)}(),$e=function(e){Ke(r,ze(Error));var t=Fe(r);function r(e){var n,o;Ue(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 Be(r)}(),Xe=function(e){Ke(r,ze(Error));var t=Fe(r);function r(e){var n;Ue(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,a=e.error_message,s=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=a,n.error_url=s,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(a,"\n")+"See ".concat(s," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return Be(r)}(),Ze=function(e){Ke(r,ze(Error));var t=Fe(r);function r(e){var n;return Ue(this,r),(n=t.call(this)).name="StytchSDKNativeError",n.error_type=e,n.message="".concat(e),n}return Be(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={})),exports.SDKAPIUnreachableError=Ye,exports.StytchB2BHeadlessClient=De,exports.StytchSDKAPIError=Xe,exports.StytchSDKNativeError=Ze,exports.StytchSDKSchemaError=$e,exports.StytchSDKUsageError=Je,exports.UNRECOVERABLE_ERROR_TYPES=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];
|
|
5
|
+
function ye(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 _e=function e(t,r){function n(e,n,o){if("undefined"!=typeof document){"number"==typeof(o=ye({},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 a in o)o[a]&&(i+="; "+a,!0!==o[a]&&(i+="="+o[a].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("="),a=i.slice(1).join("=");try{var s=decodeURIComponent(i[0]);if(n[s]=t.read(a,s),e===s)break}catch(e){}}return e?n[e]:n}},remove:function(e,t){n(e,"",ye({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,ye({},this.attributes,t))},withConverter:function(t){return e(ye({},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:"/"}),be=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return"".concat("stytch_sdk_state_").concat(e).concat(t?"::".concat(t):"")},ge=function(){function e(t,r){var n=this;s(this,e),this.browserSessionStorage={getItem:function(e){return sessionStorage.getItem(be(n.publicToken,e))},setItem:function(e,t){return sessionStorage.setItem(be(n.publicToken,e),t)},removeItem:function(e){return sessionStorage.removeItem(be(n.publicToken,e))}},this.publicToken=t,this.state=null,this.subscriptions={},(null==r?void 0:r.cookieOptions)?(te("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(be(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 u(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:_e.get(this.opaqueTokenCookieName),session_jwt:_e.get(this.jwtCookieName)}}},{key:"writeSessionCookie",value:function(t){var r,n,o,i,a=t.state,s=t.session_token,c=t.session_jwt,u=e.generateCookieOpts({expiresAt:null!==(n=null===(r=null==a?void 0:a.session)||void 0===r?void 0:r.expires_at)&&void 0!==n?n:"",availableToSubdomains:this._cookieAvailableToSubdomains,path:this._cookiePath});_e.set(this.opaqueTokenCookieName,s,u),_e.set(this.jwtCookieName,c,u);var l=e.generateCookieOpts({expiresAt:null!==(i=null===(o=null==a?void 0:a.session)||void 0===o?void 0:o.expires_at)&&void 0!==i?i:"",availableToSubdomains:!this._cookieAvailableToSubdomains,path:this._cookiePath});pe(this.jwtCookieName)&&_e.remove(this.jwtCookieName,l),pe(this.opaqueTokenCookieName)&&_e.remove(this.opaqueTokenCookieName,l),pe(this.jwtCookieName)&&Z("Could not remove extraneous JWT cookie. This might happen if the cookie has been set using multiple `path` settings, and may produce unwanted behavior."),pe(this.opaqueTokenCookieName)&&Z("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});_e.remove(t.opaqueTokenCookieName,o),_e.remove(t.jwtCookieName,o)}))}))}},{key:"syncToLocalStorage",value:function(){localStorage.setItem(be(this.publicToken),JSON.stringify(this.state))}},{key:"getItem",value:function(e){return localStorage.getItem(be(this.publicToken,e))}},{key:"setItem",value:function(e,t){return localStorage.setItem(be(this.publicToken,e),t)}},{key:"removeItem",value:function(e){return localStorage.removeItem(be(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}(),ke=function(e){r(n,ge);var t=o(n);function n(){return s(this,n),t.apply(this,arguments)}return u(n)}(),we=Symbol.for("__stytch_b2b_DataLayer"),Se=function(e,t){var r,n=((r=window)[we]||(r[we]={}),r[we]);return n[e]||(n[e]=new ke(e,t)),n[e]},Oe=function(e,t){Object.values(e).forEach((function(e){return e(t)}))},Ee=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 v(r)===v(n)&&(null===r||null===n?r===n:"object"===v(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=p(e,1)[0];return!t.includes(r)})).every((function(t){var r=p(t,2),o=r[0],i=r[1];return e(i,n[o])})):r===n)}}({KEYS_TO_EXCLUDE:["last_accessed_at"]}),xe=function(){function e(t,r){var n,o=this;s(this,e),this._publicToken=t,this._datalayer=r,this._listen=function(e){if(e.key===be(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 u(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,Ee(t,r)||Oe(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,Ee(t,r)||(Oe(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}(),Te=function(e){r(n,xe);var t=o(n);function n(){var e;return s(this,n),(e=t.apply(this,arguments)).updateMember=function(t){return e.updateState({member:t})},e.getMember=function(){var t,r;return null!==(r=null===(t=e.getState())||void 0===t?void 0:t.member)&&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 u(n)}();function Pe(e){var t=e.toString(16);return 1===t.length&&(t="0"+t),t}var Ce=function(){function e(t,r){s(this,e),this._dataLayer=t,this.namespace=r}return u(e,[{key:"key",value:function(){return"PKCE_VERIFIER:"+this.namespace}},{key:"startPKCETransaction",value:function(){return ve(this,void 0,void 0,a().mark((function t(){var r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.createProofkeyPair();case 2:return r=t.sent,this._dataLayer.setItem(this.key(),JSON.stringify(r)),t.abrupt("return",r);case 5:case"end":return t.stop()}}),t,this)})))}},{key:"getPKPair",value:function(){var e=this._dataLayer.getItem(this.key());if(null!==e)try{return JSON.parse(e)}catch(e){return void Z("Found malformed Proof Key pair in localstorage.")}}},{key:"clearPKPair",value:function(){return this._dataLayer.removeItem(this.key())}}],[{key:"createProofkeyPair",value:function(){return ve(this,void 0,void 0,a().mark((function e(){var r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new Uint32Array(16),window.crypto.getRandomValues(r),n=Array.from(r).map(Pe).join(""),e.next=5,window.crypto.subtle.digest("SHA-256",(new TextEncoder).encode(n));case 5:return o=e.sent,e.abrupt("return",{code_challenge:(i=o,a=void 0,btoa((a=String.fromCharCode).call.apply(a,[null].concat(t(new Uint8Array(i))))).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")),code_verifier:n});case 7:case"end":return e.stop()}var i,a}),e)})))}}]),e}(),je="bootstrap",Le=function(){function e(t,r,n){var o=this;s(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(je,JSON.stringify(e)),e})).catch((function(e){return Q(e),{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1}}))}return u(e,[{key:"getSync",value:function(){var e=this._dataLayer.getItem(je);if(null===e)return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1};try{return JSON.parse(e)}catch(e){return{displayWatermark:!1,cnameDomain:null,emailDomains:["stytch.com"],captchaSettings:{enabled:!1},pkceRequiredForEmailMagicLinks:!1,pkceRequiredForPasswordResets:!1,pkceRequiredForOAuth:!1,pkceRequiredForSso:!1}}}},{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}(),Ae=u((function e(t,r){var n,o=this;s(this,e),function(e){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("import { createStytchB2BHeadlessClient } from '@stytch/nextjs/b2b';\n \n const stytch = createStytchB2BHeadlessClient('public-token-...');\n ","\n```\n"))}("StytchB2BHeadlessClient"),"string"!=typeof(n=t)?Z("Public token is malformed. Expected a string, got ".concat(v(n),".").concat(ee)):""===n?Z('Public token is malformed. Expected "public-token-...", got an empty string.'.concat(ee)):n.startsWith("public-token-")||Z('Public token is malformed. Expected "public-token-...", got '.concat(n,".").concat(ee));var i,a,c,u,l,h,f,d,p,m=r,y={cookieOptions:null==(i=m)?void 0:i.cookieOptions,endpoints:{sdkBackendURL:null!==(c=null===(a=null==i?void 0:i.endpoints)||void 0===a?void 0:a.sdkBackendURL)&&void 0!==c?c:"https://web.stytch.com",testAPIURL:null!==(l=null===(u=null==i?void 0:i.endpoints)||void 0===u?void 0:u.testAPIURL)&&void 0!==l?l:"https://test.stytch.com",liveAPIURL:null!==(f=null===(h=null==i?void 0:i.endpoints)||void 0===h?void 0:h.liveAPIURL)&&void 0!==f?f:"https://api.stytch.com",clientsideServicesIframeURL:null!==(p=null===(d=null==i?void 0:i.endpoints)||void 0===d?void 0:d.clientsideServicesIframeURL)&&void 0!==p?p:"https://js.stytch.com/clientside-services/index.html"}};this._dataLayer=Se(t,m),this._subscriptionService=new Te(t,this._dataLayer);this._networkClient=new me(t,this._dataLayer,y.endpoints.sdkBackendURL,(function(){var e,t,r,n;return{stytch_member_id:null===(t=null===(e=o._dataLayer.state)||void 0===e?void 0:e.member)||void 0===t?void 0:t.member_id,stytch_member_session_id:null===(n=null===(r=o._dataLayer.state)||void 0===r?void 0:r.session)||void 0===n?void 0:n.member_session_id}}));var _=new Le(t,this._networkClient,this._dataLayer);this.organization=new ue(this._networkClient),this.member=new se(this._networkClient,this._subscriptionService),this.session=new le(this._networkClient,this._subscriptionService),this.magicLinks=new ae(this._networkClient,this._subscriptionService,new Ce(this._dataLayer,"magic_links"),_.getAsync()),this.sso=new ce(this._networkClient,this._subscriptionService,new Ce(this._dataLayer,"sso"),_.getAsync(),{publicToken:t,testAPIURL:y.endpoints.testAPIURL,liveAPIURL:y.endpoints.liveAPIURL}),this.discovery=new he(this._networkClient,this._subscriptionService),this._sessionManager=new ne(this._subscriptionService,this.session),this._dataLayer.readSessionCookie().session_token&&this._sessionManager.performBackgroundRefresh(),this._networkClient.logEvent({name:"b2b_sdk_instance_instantiated",details:{event_callback_registered:!1,error_callback_registered:!1,success_callback_registered:!1}}),de(this,{bootstrap:_,publicToken:t})}));function Re(e){return Re="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},Re(e)}function Ie(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"!==Re(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==Re(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(o,"string"),"symbol"===Re(i)?i:String(i)),n)}var o,i}function De(e,t,r){return t&&Ie(e.prototype,t),r&&Ie(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function Ne(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function Me(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&&ze(e,t)}function Be(e){var t=qe();return function(){var r,n=We(e);if(t){var o=We(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===Re(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return Ue(e)}(this,r)}}function Ue(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Ke(e){var t="function"==typeof Map?new Map:void 0;return Ke=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 Fe(e,arguments,We(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),ze(n,e)},Ke(e)}function Fe(e,t,r){return Fe=qe()?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&&ze(o,r.prototype),o},Fe.apply(null,arguments)}function qe(){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 ze(e,t){return ze=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},ze(e,t)}function We(e){return We=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},We(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 Ge=function(e){Me(r,Ke(Error));var t=Be(r);function r(e,n){var o;return Ne(this,r),(o=t.call(this,e+"\n"+n)).message=e+"\n"+n,o.name="SDKAPIUnreachableError",o.details=n,Object.setPrototypeOf(Ue(o),r.prototype),o}return De(r)}(),He=function(e){Me(r,Ke(Error));var t=Be(r);function r(e,n){var o;return Ne(this,r),(o=t.call(this)).name="StytchSDKUsageError",o.message="Invalid call to ".concat(e,"\n")+n,o}return De(r)}(),Ve=function(e){Me(r,Ke(Error));var t=Be(r);function r(e){var n,o;Ne(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 De(r)}(),Ye=function(e){Me(r,Ke(Error));var t=Be(r);function r(e){var n;Ne(this,r),(n=t.call(this)).name="StytchSDKAPIError";var o=e.status_code,i=e.error_type,a=e.error_message,s=e.error_url,c=e.request_id;return n.error_type=i,n.error_message=a,n.error_url=s,n.request_id=c,n.status_code=o,n.message="[".concat(o,"] ").concat(i,"\n")+"".concat(a,"\n")+"See ".concat(s," for more information.\n")+(c?"request_id: ".concat(c,"\n"):""),n}return De(r)}(),Je=function(e){Me(r,Ke(Error));var t=Be(r);function r(e){var n;return Ne(this,r),(n=t.call(this)).name="StytchSDKNativeError",n.error_type=e,n.message="".concat(e),n}return De(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={})),exports.SDKAPIUnreachableError=Ge,exports.StytchB2BHeadlessClient=Ae,exports.StytchSDKAPIError=Ye,exports.StytchSDKNativeError=Je,exports.StytchSDKSchemaError=Ve,exports.StytchSDKUsageError=He,exports.UNRECOVERABLE_ERROR_TYPES=["unauthorized_credentials","user_unauthenticated","invalid_secret_authentication","session_not_found"];
|