diff --git a/CHANGELOG.md b/CHANGELOG.md index 4548046f..9d1060f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed ThirdPartyEmailPassword and ThirdPartyPasswordless recipes - Dropped support for FDI version 1.X - Added support for FDI version 2.0 and 3.0 +- Removed `createCode`, `resendCode` and `consumeCode` from the exports of `recipe/passwordless/utils` ## [0.10.1] - 2024-04-08 diff --git a/bundle/passwordless.js b/bundle/passwordless.js index b5dc1902..fcf533ae 100644 --- a/bundle/passwordless.js +++ b/bundle/passwordless.js @@ -1 +1 @@ -"use strict";var supertokensPasswordless;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[87],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY=void 0,t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY="supertokens-passwordless-loginAttemptInfo"},6525:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.11.0",t.supported_fdi=["2.0","3.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6525,e(e.s=6525));supertokensPasswordless=t}]); \ No newline at end of file +"use strict";var supertokensPasswordless;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[87],{7611:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.SSR_ERROR=t.DEFAULT_API_BASE_PATH=void 0,t.DEFAULT_API_BASE_PATH="/auth",t.SSR_ERROR="\nIf you are trying to use this method doing server-side-rendering, please make sure you move this method inside a componentDidMount method or useEffect hook."},2173:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=n(942);t.default=r.STGeneralError},7992:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e,t){void 0===t&&(t=!1),e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");var r=new URL(e);return t?r.hostname.startsWith("localhost")||(o=r.hostname,/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(o))?"http://"+r.host:"https://"+r.host:r.protocol+"//"+r.host}catch(e){}var o;if(e.startsWith("/"))throw new Error("Please provide a valid domain name");if(0===e.indexOf(".")&&(e=e.substr(1)),(-1!==e.indexOf(".")||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://")){e="https://"+e;try{return new URL(e),n(e,!0)}catch(e){}}throw new Error("Please provide a valid domain name")}t.default=function(e){var t=this;this.getAsStringDangerous=function(){return t.value},this.value=n(e)}},1260:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});function n(e){e=e.trim();try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error("Error converting to proper URL");return"/"===(e=new URL(e).pathname).charAt(e.length-1)?e.substr(0,e.length-1):e}catch(e){}if((function(e){if(-1===e.indexOf(".")||e.startsWith("/"))return!1;try{return-1!==new URL(e).hostname.indexOf(".")}catch(e){}try{return-1!==new URL("http://"+e).hostname.indexOf(".")}catch(e){}return!1}(e)||e.startsWith("localhost"))&&!e.startsWith("http://")&&!e.startsWith("https://"))return n(e="http://"+e);"/"!==e.charAt(0)&&(e="/"+e);try{return new URL("http://example.com"+e),n("http://example.com"+e)}catch(e){throw new Error("Please provide a valid URL path")}}t.default=function e(t){var r=this;this.startsWith=function(e){return r.value.startsWith(e.value)},this.appendPath=function(t){return new e(r.value+t.value)},this.getAsStringDangerous=function(){return r.value},this.value=n(t)}},634:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(p=f.clone(),[4,u({requestInit:c,url:e,fetchResponse:p})]);case 3:i.sent(),i.label=4;case 4:return[2,f]}}))}))},this.callPreAPIHook=function(e){return o(n,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:return void 0===e.preAPIHook?[2,{url:e.url,requestInit:e.requestInit}]:[4,e.preAPIHook({url:e.url,requestInit:e.requestInit})];case 1:return[2,t.sent()]}}))}))},this.getFullUrl=function(e,t,r){var o=n.appInfo.apiBasePath.getAsStringDangerous();void 0!==e&&"public"!==e&&(o="".concat(o,"/").concat(e));var i=new s.default(t),a="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?a:a+"?"+new URLSearchParams(r)},this.getResponseJsonOrThrowGeneralError=function(e){return o(n,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return[4,e.clone().json()];case 1:if("GENERAL_ERROR"===(t=r.sent()).status)throw n=void 0===t.message?"No Error Message Provided":t.message,new u.default(n);return[2,t]}}))}))}}var t;return t=e,e.preparePreAPIHook=function(e){var n=e.recipePreAPIHook,s=e.action,a=e.options,u=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){var o;return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{action:s,userContext:u}))];case 1:return o=t.sent(),void 0===a||void 0===a.preAPIHook?[2,o]:[2,a.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,s=e.action,a=e.userContext;return function(e){return o(void 0,void 0,void 0,(function(){return i(t,(function(t){switch(t.label){case 0:return[4,n(r(r({},e),{userContext:a,action:s}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=c},7725:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseAuthRecipe=void 0;var r=n(6069);t.normaliseAuthRecipe=function(e){return(0,r.normaliseRecipeModuleConfig)(e)}},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},6984:function(e,t,n){var r,o=this&&this.__extends||(r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY=void 0,t.PASSWORDLESS_LOGIN_ATTEMPT_INFO_STORAGE_KEY="supertokens-passwordless-loginAttemptInfo"},6525:function(e,t,n){var r=this&&this.__assign||function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0});t.default=function(e){this.config=e}},6069:function(e,t){var n=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{u(r.next(e))}catch(e){i(e)}}function a(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.normaliseUser=t.normaliseUserResponse=t.getGlobalClaimValidators=t.getHashFromLocation=t.getNormalisedUserContext=t.checkForSSRErrorAndAppendIfNeeded=t.getAllQueryParams=t.getQueryParams=t.isTest=t.normaliseInputAppInfoOrThrowError=t.appendQueryParamsToURL=void 0;var r=n(7528),o=n(7611),i=n(7992),s=n(1260),a=n(5811);function u(e,t){if("loginMethods"in t)return t;var n=void 0!==t.email?[t.email]:[],r=void 0!==t.phoneNumber?[t.phoneNumber]:[],o=void 0!==t.thirdParty?[t.thirdParty]:[];return{id:t.id,emails:n,phoneNumbers:r,thirdParty:o,isPrimaryUser:!1,tenantIds:t.tenantIds,timeJoined:t.timeJoined,loginMethods:[{recipeId:e,recipeUserId:t.id,timeJoined:t.timeJoined,tenantIds:t.tenantIds,email:t.email,phoneNumber:t.email}]}}t.appendQueryParamsToURL=function(e,t){if(void 0===t)return e;try{var n=new URL(e);return Object.entries(t).forEach((function(e){var t=e[0],r=e[1];n.searchParams.set(t,r)})),n.href}catch(n){var r=e.startsWith("/")?"http:localhost":"http://localhost/",o=new URL("".concat(r).concat(e));return Object.entries(t).forEach((function(e){var t=e[0],n=e[1];o.searchParams.set(t,n)})),"".concat(o.pathname).concat(o.search)}},t.normaliseInputAppInfoOrThrowError=function(e){if(void 0===e)throw new Error("Please provide the appInfo object when calling supertokens.init");if(void 0===e.apiDomain)throw new Error("Please provide your apiDomain inside the appInfo object when calling supertokens.init");if(void 0===e.appName)throw new Error("Please provide your appName inside the appInfo object when calling supertokens.init");var t,n,r=new s.default("");return void 0!==e.apiGatewayPath&&(r=new s.default(e.apiGatewayPath)),{appName:e.appName,apiDomain:new i.default(e.apiDomain),apiBasePath:r.appendPath((t=o.DEFAULT_API_BASE_PATH,n=e.apiBasePath,void 0!==n?new s.default(n):new s.default(t)))}},t.isTest=function(){try{return"testing"===process.env.TEST_MODE}catch(e){return!1}},t.getQueryParams=function(e){var t=new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch()).get(e);if(null!==t)return t},t.getAllQueryParams=function(){return new URLSearchParams(r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getSearch())},t.checkForSSRErrorAndAppendIfNeeded=function(e){return"undefined"==typeof window&&(e+=o.SSR_ERROR),e},t.getNormalisedUserContext=function(e){return void 0===e?{}:e},t.getHashFromLocation=function(){return r.WindowHandlerReference.getReferenceOrThrow().windowHandler.location.getHash().substring(1)},t.getGlobalClaimValidators=function(e){var t=e.overrideGlobalClaimValidators,n=e.userContext;return(0,a.getGlobalClaimValidators)(t,n)},t.normaliseUserResponse=function(e,t){return"createdNewRecipeUser"in t?t:{createdNewRecipeUser:t.createdNewUser,user:u(e,t.user)}},t.normaliseUser=u},255:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.supported_fdi=t.package_version=void 0,t.package_version="0.11.0",t.supported_fdi=["2.0","3.0"]},7528:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.WindowHandlerReference=void 0;var r=n(9092);Object.defineProperty(t,"WindowHandlerReference",{enumerable:!0,get:function(){return r.WindowHandlerReference}})},4328:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getGlobalClaimValidators=void 0;var r=n(2652),o=n(788),i=n(2582);t.getGlobalClaimValidators=function(e,t){var n=(0,r.getNormalisedUserContext)(t),s=i.default.getClaimValidatorsAddedByOtherRecipes(),a=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:s,userContext:n});return void 0!==e?e(a,n):a}},942:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(6398);void 0!==o.default?r(o):r({default:o,...o})},5811:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(4328))},9092:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(7860))}},e=>{var t=(6525,e(e.s=6525));supertokensPasswordless=t}]); \ No newline at end of file diff --git a/lib/build/recipe/passwordless/index.js b/lib/build/recipe/passwordless/index.js index c9eaf98a..74e79fba 100644 --- a/lib/build/recipe/passwordless/index.js +++ b/lib/build/recipe/passwordless/index.js @@ -176,7 +176,6 @@ exports.clearLoginAttemptInfo = var utils_1 = require("../../utils"); var recipe_1 = require("../multitenancy/recipe"); var recipe_2 = require("./recipe"); -var UtilFunctions = require("./utils"); var RecipeWrapper = /** @class */ (function () { function RecipeWrapper() {} RecipeWrapper.init = function (config) { @@ -199,15 +198,48 @@ var RecipeWrapper = /** @class */ (function () { */ RecipeWrapper.createCode = function (input) { return __awaiter(this, void 0, void 0, function () { - var recipe; + var recipe, recipeImplementation, normalisedUserContext, tenantId, createCodeResponse; return __generator(this, function (_a) { - recipe = recipe_2.default.getInstanceOrThrow(); - return [ - 2 /*return*/, - UtilFunctions.createCode( - __assign(__assign({}, input), { recipeImplementation: recipe.recipeImplementation }) - ), - ]; + switch (_a.label) { + case 0: + recipe = recipe_2.default.getInstanceOrThrow(); + recipeImplementation = recipe.recipeImplementation; + normalisedUserContext = (0, utils_1.getNormalisedUserContext)(input.userContext); + return [ + 4 /*yield*/, + recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: input.userContext, + }), + ]; + case 1: + tenantId = _a.sent(); + return [ + 4 /*yield*/, + recipeImplementation.createCode( + __assign(__assign({}, input), { userContext: normalisedUserContext }) + ), + ]; + case 2: + createCodeResponse = _a.sent(); + if (!(createCodeResponse.status === "OK")) return [3 /*break*/, 4]; + return [ + 4 /*yield*/, + recipeImplementation.setLoginAttemptInfo({ + attemptInfo: { + tenantId: tenantId, + deviceId: createCodeResponse.deviceId, + preAuthSessionId: createCodeResponse.preAuthSessionId, + flowType: createCodeResponse.flowType, + }, + userContext: normalisedUserContext, + }), + ]; + case 3: + _a.sent(); + _a.label = 4; + case 4: + return [2 /*return*/, createCodeResponse]; + } }); }); }; @@ -230,15 +262,44 @@ var RecipeWrapper = /** @class */ (function () { */ RecipeWrapper.resendCode = function (input) { return __awaiter(this, void 0, void 0, function () { - var recipe; + var recipe, recipeImplementation, normalisedUserContext, previousAttemptInfo; return __generator(this, function (_a) { - recipe = recipe_2.default.getInstanceOrThrow(); - return [ - 2 /*return*/, - UtilFunctions.resendCode( - __assign(__assign({}, input), { recipeImplementation: recipe.recipeImplementation }) - ), - ]; + switch (_a.label) { + case 0: + recipe = recipe_2.default.getInstanceOrThrow(); + recipeImplementation = recipe.recipeImplementation; + normalisedUserContext = (0, utils_1.getNormalisedUserContext)( + input === null || input === void 0 ? void 0 : input.userContext + ); + return [ + 4 /*yield*/, + recipeImplementation.getLoginAttemptInfo({ + userContext: normalisedUserContext, + }), + ]; + case 1: + previousAttemptInfo = _a.sent(); + /** + * If previousAttemptInfo is undefined then local storage was probably cleared by another tab. + * In this case we use empty strings when calling the API because we want to + * return "RESTART_FLOW_ERROR" + */ + return [ + 2 /*return*/, + recipeImplementation.resendCode( + __assign(__assign({}, input), { + tenantId: + previousAttemptInfo === null || previousAttemptInfo === void 0 + ? void 0 + : previousAttemptInfo.tenantId, + userContext: normalisedUserContext, + deviceId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.deviceId, + preAuthSessionId: + previousAttemptInfo === undefined ? "" : previousAttemptInfo.preAuthSessionId, + }) + ), + ]; + } }); }); }; @@ -270,15 +331,79 @@ var RecipeWrapper = /** @class */ (function () { */ RecipeWrapper.consumeCode = function (input) { return __awaiter(this, void 0, void 0, function () { - var recipe; + var recipe, + recipeImplementation, + userContext, + additionalParams, + attemptInfoFromStorage, + linkCode, + tenantId, + preAuthSessionId; return __generator(this, function (_a) { - recipe = recipe_2.default.getInstanceOrThrow(); - return [ - 2 /*return*/, - UtilFunctions.consumeCode( - __assign(__assign({}, input), { recipeImplementation: recipe.recipeImplementation }) - ), - ]; + switch (_a.label) { + case 0: + recipe = recipe_2.default.getInstanceOrThrow(); + recipeImplementation = recipe.recipeImplementation; + userContext = (0, utils_1.getNormalisedUserContext)( + input === null || input === void 0 ? void 0 : input.userContext + ); + if (!(input !== undefined && "userInputCode" in input)) return [3 /*break*/, 2]; + return [ + 4 /*yield*/, + recipeImplementation.getLoginAttemptInfo({ + userContext: userContext, + }), + ]; + case 1: + attemptInfoFromStorage = _a.sent(); + /** + * If attemptInfoFromStorage is undefined then local storage was probably cleared by another tab. + * In this case we use empty strings when calling the API because we want to + * return "RESTART_FLOW_ERROR" + * + * Note: We dont do this for the linkCode flow because that does not depend on local storage. + */ + additionalParams = { + userInputCode: input.userInputCode, + deviceId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.deviceId, + preAuthSessionId: + attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.preAuthSessionId, + tenantId: + attemptInfoFromStorage === null || attemptInfoFromStorage === void 0 + ? void 0 + : attemptInfoFromStorage.tenantId, + }; + return [3 /*break*/, 3]; + case 2: + linkCode = recipeImplementation.getLinkCodeFromURL({ + userContext: userContext, + }); + tenantId = recipeImplementation.getTenantIdFromURL({ + userContext: userContext, + }); + preAuthSessionId = recipeImplementation.getPreAuthSessionIdFromURL({ + userContext: userContext, + }); + additionalParams = { + tenantId: tenantId, + linkCode: linkCode, + preAuthSessionId: preAuthSessionId, + }; + _a.label = 3; + case 3: + return [ + 2 /*return*/, + recipeImplementation.consumeCode( + __assign( + { + userContext: userContext, + options: input === null || input === void 0 ? void 0 : input.options, + }, + additionalParams + ) + ), + ]; + } }); }); }; diff --git a/lib/build/recipe/passwordless/utils.d.ts b/lib/build/recipe/passwordless/utils.d.ts index daeb4ded..0d9453eb 100644 --- a/lib/build/recipe/passwordless/utils.d.ts +++ b/lib/build/recipe/passwordless/utils.d.ts @@ -1,83 +1,2 @@ -import { User } from "../../types"; -import { RecipeFunctionOptions } from "../recipeModule/types"; -import { InputType, NormalisedInputType, PasswordlessFlowType, RecipeInterface } from "./types"; +import { InputType, NormalisedInputType } from "./types"; export declare function normaliseUserInput(config: InputType): NormalisedInputType; -/** - * These functions are helper functions so that the logic can be exposed from both - * passwordless and thirdpartypasswordless recipes without having to duplicate code. - * After removing the combination recipes these could be moved into the index file, - * but it is not necessary - * TODO - */ -export declare function createCode( - input: - | { - email: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } - | { - phoneNumber: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } -): Promise< - | { - status: "OK"; - deviceId: string; - preAuthSessionId: string; - flowType: PasswordlessFlowType; - fetchResponse: Response; - } - | { - status: "SIGN_IN_UP_NOT_ALLOWED"; - reason: string; - fetchResponse: Response; - } ->; -export declare function resendCode(input: { - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; -}): Promise<{ - status: "OK" | "RESTART_FLOW_ERROR"; - fetchResponse: Response; -}>; -export declare function consumeCode( - input: - | { - userInputCode: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } - | { - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } -): Promise< - | { - status: "OK"; - createdNewRecipeUser: boolean; - user: User; - fetchResponse: Response; - } - | { - status: "INCORRECT_USER_INPUT_CODE_ERROR" | "EXPIRED_USER_INPUT_CODE_ERROR"; - failedCodeInputAttemptCount: number; - maximumCodeInputAttempts: number; - fetchResponse: Response; - } - | { - status: "RESTART_FLOW_ERROR"; - fetchResponse: Response; - } - | { - status: "SIGN_IN_UP_NOT_ALLOWED"; - reason: string; - fetchResponse: Response; - } ->; diff --git a/lib/build/recipe/passwordless/utils.js b/lib/build/recipe/passwordless/utils.js index 4adb0e55..284e6c28 100644 --- a/lib/build/recipe/passwordless/utils.js +++ b/lib/build/recipe/passwordless/utils.js @@ -27,142 +27,9 @@ var __assign = }; return __assign.apply(this, arguments); }; -var __awaiter = - (this && this.__awaiter) || - function (thisArg, _arguments, P, generator) { - function adopt(value) { - return value instanceof P - ? value - : new P(function (resolve) { - resolve(value); - }); - } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { - try { - step(generator.next(value)); - } catch (e) { - reject(e); - } - } - function rejected(value) { - try { - step(generator["throw"](value)); - } catch (e) { - reject(e); - } - } - function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); - } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); - }; -var __generator = - (this && this.__generator) || - function (thisArg, body) { - var _ = { - label: 0, - sent: function () { - if (t[0] & 1) throw t[1]; - return t[1]; - }, - trys: [], - ops: [], - }, - f, - y, - t, - g; - return ( - (g = { next: verb(0), throw: verb(1), return: verb(2) }), - typeof Symbol === "function" && - (g[Symbol.iterator] = function () { - return this; - }), - g - ); - function verb(n) { - return function (v) { - return step([n, v]); - }; - } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) - try { - if ( - ((f = 1), - y && - (t = - op[0] & 2 - ? y["return"] - : op[0] - ? y["throw"] || ((t = y["return"]) && t.call(y), 0) - : y.next) && - !(t = t.call(y, op[1])).done) - ) - return t; - if (((y = 0), t)) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: - case 1: - t = op; - break; - case 4: - _.label++; - return { value: op[1], done: false }; - case 5: - _.label++; - y = op[1]; - op = [0]; - continue; - case 7: - op = _.ops.pop(); - _.trys.pop(); - continue; - default: - if ( - !((t = _.trys), (t = t.length > 0 && t[t.length - 1])) && - (op[0] === 6 || op[0] === 2) - ) { - _ = 0; - continue; - } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { - _.label = op[1]; - break; - } - if (op[0] === 6 && _.label < t[1]) { - _.label = t[1]; - t = op; - break; - } - if (t && _.label < t[2]) { - _.label = t[2]; - _.ops.push(op); - break; - } - if (t[2]) _.ops.pop(); - _.trys.pop(); - continue; - } - op = body.call(thisArg, _); - } catch (e) { - op = [6, e]; - y = 0; - } finally { - f = t = 0; - } - if (op[0] & 5) throw op[1]; - return { value: op[0] ? op[1] : void 0, done: true }; - } - }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.consumeCode = exports.resendCode = exports.createCode = exports.normaliseUserInput = void 0; -var utils_1 = require("../../utils"); -var utils_2 = require("../authRecipe/utils"); -var recipe_1 = require("../multitenancy/recipe"); +exports.normaliseUserInput = void 0; +var utils_1 = require("../authRecipe/utils"); function normaliseUserInput(config) { var override = __assign( { @@ -172,161 +39,6 @@ function normaliseUserInput(config) { }, config.override ); - return __assign(__assign({}, (0, utils_2.normaliseAuthRecipe)(config)), { override: override }); + return __assign(__assign({}, (0, utils_1.normaliseAuthRecipe)(config)), { override: override }); } exports.normaliseUserInput = normaliseUserInput; -/** - * These functions are helper functions so that the logic can be exposed from both - * passwordless and thirdpartypasswordless recipes without having to duplicate code. - * After removing the combination recipes these could be moved into the index file, - * but it is not necessary - * TODO - */ -function createCode(input) { - return __awaiter(this, void 0, void 0, function () { - var normalisedUserContext, tenantId, createCodeResponse; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - normalisedUserContext = (0, utils_1.getNormalisedUserContext)(input.userContext); - return [ - 4 /*yield*/, - recipe_1.default.getInstanceOrThrow().recipeImplementation.getTenantId({ - userContext: input.userContext, - }), - ]; - case 1: - tenantId = _a.sent(); - return [ - 4 /*yield*/, - input.recipeImplementation.createCode( - __assign(__assign({}, input), { userContext: normalisedUserContext }) - ), - ]; - case 2: - createCodeResponse = _a.sent(); - if (!(createCodeResponse.status === "OK")) return [3 /*break*/, 4]; - return [ - 4 /*yield*/, - input.recipeImplementation.setLoginAttemptInfo({ - attemptInfo: { - tenantId: tenantId, - deviceId: createCodeResponse.deviceId, - preAuthSessionId: createCodeResponse.preAuthSessionId, - flowType: createCodeResponse.flowType, - }, - userContext: normalisedUserContext, - }), - ]; - case 3: - _a.sent(); - _a.label = 4; - case 4: - return [2 /*return*/, createCodeResponse]; - } - }); - }); -} -exports.createCode = createCode; -function resendCode(input) { - return __awaiter(this, void 0, void 0, function () { - var normalisedUserContext, previousAttemptInfo; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - normalisedUserContext = (0, utils_1.getNormalisedUserContext)(input.userContext); - return [ - 4 /*yield*/, - input.recipeImplementation.getLoginAttemptInfo({ - userContext: normalisedUserContext, - }), - ]; - case 1: - previousAttemptInfo = _a.sent(); - /** - * If previousAttemptInfo is undefined then local storage was probably cleared by another tab. - * In this case we use empty strings when calling the API because we want to - * return "RESTART_FLOW_ERROR" - */ - return [ - 2 /*return*/, - input.recipeImplementation.resendCode( - __assign(__assign({}, input), { - tenantId: - previousAttemptInfo === null || previousAttemptInfo === void 0 - ? void 0 - : previousAttemptInfo.tenantId, - userContext: normalisedUserContext, - deviceId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.deviceId, - preAuthSessionId: - previousAttemptInfo === undefined ? "" : previousAttemptInfo.preAuthSessionId, - }) - ), - ]; - } - }); - }); -} -exports.resendCode = resendCode; -function consumeCode(input) { - return __awaiter(this, void 0, void 0, function () { - var normalisedUserContext, additionalParams, attemptInfoFromStorage, linkCode, tenantId, preAuthSessionId; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - normalisedUserContext = (0, utils_1.getNormalisedUserContext)(input.userContext); - if (!("userInputCode" in input)) return [3 /*break*/, 2]; - return [ - 4 /*yield*/, - input.recipeImplementation.getLoginAttemptInfo({ - userContext: normalisedUserContext, - }), - ]; - case 1: - attemptInfoFromStorage = _a.sent(); - /** - * If attemptInfoFromStorage is undefined then local storage was probably cleared by another tab. - * In this case we use empty strings when calling the API because we want to - * return "RESTART_FLOW_ERROR" - * - * Note: We dont do this for the linkCode flow because that does not depend on local storage. - */ - additionalParams = { - userInputCode: input.userInputCode, - deviceId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.deviceId, - preAuthSessionId: - attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.preAuthSessionId, - tenantId: - attemptInfoFromStorage === null || attemptInfoFromStorage === void 0 - ? void 0 - : attemptInfoFromStorage.tenantId, - }; - return [3 /*break*/, 3]; - case 2: - linkCode = input.recipeImplementation.getLinkCodeFromURL({ - userContext: input.userContext, - }); - tenantId = input.recipeImplementation.getTenantIdFromURL({ - userContext: input.userContext, - }); - preAuthSessionId = input.recipeImplementation.getPreAuthSessionIdFromURL({ - userContext: input.userContext, - }); - additionalParams = { - tenantId: tenantId, - linkCode: linkCode, - preAuthSessionId: preAuthSessionId, - }; - _a.label = 3; - case 3: - return [ - 2 /*return*/, - input.recipeImplementation.consumeCode( - __assign({ userContext: normalisedUserContext, options: input.options }, additionalParams) - ), - ]; - } - }); - }); -} -exports.consumeCode = consumeCode; diff --git a/lib/ts/recipe/passwordless/index.ts b/lib/ts/recipe/passwordless/index.ts index 7b0a6343..bf377fc8 100644 --- a/lib/ts/recipe/passwordless/index.ts +++ b/lib/ts/recipe/passwordless/index.ts @@ -26,7 +26,7 @@ import { PreAndPostAPIHookAction, UserInput, } from "./types"; -import * as UtilFunctions from "./utils"; + export default class RecipeWrapper { static init(config?: UserInput) { return Recipe.init(config); @@ -66,11 +66,31 @@ export default class RecipeWrapper { } > { const recipe: Recipe = Recipe.getInstanceOrThrow(); + const recipeImplementation = recipe.recipeImplementation; + + const normalisedUserContext = getNormalisedUserContext(input.userContext); - return UtilFunctions.createCode({ + const tenantId = await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ + userContext: input.userContext, + }); + const createCodeResponse = await recipeImplementation.createCode({ ...input, - recipeImplementation: recipe.recipeImplementation, + userContext: normalisedUserContext, }); + + if (createCodeResponse.status === "OK") { + await recipeImplementation.setLoginAttemptInfo({ + attemptInfo: { + tenantId, + deviceId: createCodeResponse.deviceId, + preAuthSessionId: createCodeResponse.preAuthSessionId, + flowType: createCodeResponse.flowType, + }, + userContext: normalisedUserContext, + }); + } + + return createCodeResponse; } /** @@ -95,10 +115,25 @@ export default class RecipeWrapper { fetchResponse: Response; }> { const recipe: Recipe = Recipe.getInstanceOrThrow(); + const recipeImplementation = recipe.recipeImplementation; + + const normalisedUserContext = getNormalisedUserContext(input?.userContext); - return UtilFunctions.resendCode({ + const previousAttemptInfo = await recipeImplementation.getLoginAttemptInfo({ + userContext: normalisedUserContext, + }); + + /** + * If previousAttemptInfo is undefined then local storage was probably cleared by another tab. + * In this case we use empty strings when calling the API because we want to + * return "RESTART_FLOW_ERROR" + */ + return recipeImplementation.resendCode({ ...input, - recipeImplementation: recipe.recipeImplementation, + tenantId: previousAttemptInfo?.tenantId, + userContext: normalisedUserContext, + deviceId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.deviceId, + preAuthSessionId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.preAuthSessionId, }); } @@ -156,10 +191,65 @@ export default class RecipeWrapper { | { status: "SIGN_IN_UP_NOT_ALLOWED"; reason: string; fetchResponse: Response } > { const recipe: Recipe = Recipe.getInstanceOrThrow(); + const recipeImplementation = recipe.recipeImplementation; + const userContext = getNormalisedUserContext(input?.userContext); - return UtilFunctions.consumeCode({ - ...input, - recipeImplementation: recipe.recipeImplementation, + let additionalParams: + | { + tenantId: string | undefined; + userInputCode: string; + deviceId: string; + preAuthSessionId: string; + } + | { + tenantId: string | undefined; + linkCode: string; + preAuthSessionId: string; + }; + + if (input !== undefined && "userInputCode" in input) { + const attemptInfoFromStorage = await recipeImplementation.getLoginAttemptInfo({ + userContext: userContext, + }); + + /** + * If attemptInfoFromStorage is undefined then local storage was probably cleared by another tab. + * In this case we use empty strings when calling the API because we want to + * return "RESTART_FLOW_ERROR" + * + * Note: We dont do this for the linkCode flow because that does not depend on local storage. + */ + + additionalParams = { + userInputCode: input.userInputCode, + deviceId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.deviceId, + preAuthSessionId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.preAuthSessionId, + tenantId: attemptInfoFromStorage?.tenantId, + }; + } else { + const linkCode = recipeImplementation.getLinkCodeFromURL({ + userContext, + }); + + const tenantId = recipeImplementation.getTenantIdFromURL({ + userContext, + }); + + const preAuthSessionId = recipeImplementation.getPreAuthSessionIdFromURL({ + userContext: userContext, + }); + + additionalParams = { + tenantId, + linkCode, + preAuthSessionId, + }; + } + + return recipeImplementation.consumeCode({ + userContext: userContext, + options: input?.options, + ...additionalParams, }); } diff --git a/lib/ts/recipe/passwordless/utils.ts b/lib/ts/recipe/passwordless/utils.ts index 74984e79..ee430362 100644 --- a/lib/ts/recipe/passwordless/utils.ts +++ b/lib/ts/recipe/passwordless/utils.ts @@ -13,12 +13,8 @@ * under the License. */ -import { User } from "../../types"; -import { getNormalisedUserContext } from "../../utils"; import { normaliseAuthRecipe } from "../authRecipe/utils"; -import Multitenancy from "../multitenancy/recipe"; -import { RecipeFunctionOptions } from "../recipeModule/types"; -import { InputType, NormalisedInputType, PasswordlessFlowType, RecipeInterface } from "./types"; +import { InputType, NormalisedInputType, RecipeInterface } from "./types"; export function normaliseUserInput(config: InputType): NormalisedInputType { let override = { @@ -31,182 +27,3 @@ export function normaliseUserInput(config: InputType): NormalisedInputType { override, }; } - -/** - * These functions are helper functions so that the logic can be exposed from both - * passwordless and thirdpartypasswordless recipes without having to duplicate code. - * After removing the combination recipes these could be moved into the index file, - * but it is not necessary - * TODO - */ - -export async function createCode( - input: - | { - email: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } - | { - phoneNumber: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } -): Promise< - | { - status: "OK"; - deviceId: string; - preAuthSessionId: string; - flowType: PasswordlessFlowType; - fetchResponse: Response; - } - | { - status: "SIGN_IN_UP_NOT_ALLOWED"; - reason: string; - fetchResponse: Response; - } -> { - const normalisedUserContext = getNormalisedUserContext(input.userContext); - - const tenantId = await Multitenancy.getInstanceOrThrow().recipeImplementation.getTenantId({ - userContext: input.userContext, - }); - const createCodeResponse = await input.recipeImplementation.createCode({ - ...input, - userContext: normalisedUserContext, - }); - - if (createCodeResponse.status === "OK") { - await input.recipeImplementation.setLoginAttemptInfo({ - attemptInfo: { - tenantId, - deviceId: createCodeResponse.deviceId, - preAuthSessionId: createCodeResponse.preAuthSessionId, - flowType: createCodeResponse.flowType, - }, - userContext: normalisedUserContext, - }); - } - - return createCodeResponse; -} - -export async function resendCode(input: { - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; -}): Promise<{ - status: "OK" | "RESTART_FLOW_ERROR"; - fetchResponse: Response; -}> { - const normalisedUserContext = getNormalisedUserContext(input.userContext); - - const previousAttemptInfo = await input.recipeImplementation.getLoginAttemptInfo({ - userContext: normalisedUserContext, - }); - - /** - * If previousAttemptInfo is undefined then local storage was probably cleared by another tab. - * In this case we use empty strings when calling the API because we want to - * return "RESTART_FLOW_ERROR" - */ - return input.recipeImplementation.resendCode({ - ...input, - tenantId: previousAttemptInfo?.tenantId, - userContext: normalisedUserContext, - deviceId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.deviceId, - preAuthSessionId: previousAttemptInfo === undefined ? "" : previousAttemptInfo.preAuthSessionId, - }); -} - -export async function consumeCode( - input: - | { - userInputCode: string; - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } - | { - userContext?: any; - options?: RecipeFunctionOptions; - recipeImplementation: RecipeInterface; - } -): Promise< - | { - status: "OK"; - createdNewRecipeUser: boolean; - user: User; - fetchResponse: Response; - } - | { - status: "INCORRECT_USER_INPUT_CODE_ERROR" | "EXPIRED_USER_INPUT_CODE_ERROR"; - failedCodeInputAttemptCount: number; - maximumCodeInputAttempts: number; - fetchResponse: Response; - } - | { status: "RESTART_FLOW_ERROR"; fetchResponse: Response } - | { status: "SIGN_IN_UP_NOT_ALLOWED"; reason: string; fetchResponse: Response } -> { - const normalisedUserContext = getNormalisedUserContext(input.userContext); - - let additionalParams: - | { - tenantId: string | undefined; - userInputCode: string; - deviceId: string; - preAuthSessionId: string; - } - | { - tenantId: string | undefined; - linkCode: string; - preAuthSessionId: string; - }; - - if ("userInputCode" in input) { - const attemptInfoFromStorage = await input.recipeImplementation.getLoginAttemptInfo({ - userContext: normalisedUserContext, - }); - - /** - * If attemptInfoFromStorage is undefined then local storage was probably cleared by another tab. - * In this case we use empty strings when calling the API because we want to - * return "RESTART_FLOW_ERROR" - * - * Note: We dont do this for the linkCode flow because that does not depend on local storage. - */ - - additionalParams = { - userInputCode: input.userInputCode, - deviceId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.deviceId, - preAuthSessionId: attemptInfoFromStorage === undefined ? "" : attemptInfoFromStorage.preAuthSessionId, - tenantId: attemptInfoFromStorage?.tenantId, - }; - } else { - const linkCode = input.recipeImplementation.getLinkCodeFromURL({ - userContext: input.userContext, - }); - - const tenantId = input.recipeImplementation.getTenantIdFromURL({ - userContext: input.userContext, - }); - - const preAuthSessionId = input.recipeImplementation.getPreAuthSessionIdFromURL({ - userContext: input.userContext, - }); - - additionalParams = { - tenantId, - linkCode, - preAuthSessionId, - }; - } - - return input.recipeImplementation.consumeCode({ - userContext: normalisedUserContext, - options: input.options, - ...additionalParams, - }); -} diff --git a/test/unit/exports.test.js b/test/unit/exports.test.js index 40414fec..909edc22 100644 --- a/test/unit/exports.test.js +++ b/test/unit/exports.test.js @@ -74,15 +74,6 @@ describe("Exports", function () { }); describe("Passwordless", function () { - it("Utils", function () { - let _default = require("../../recipe/passwordless/utils"); - let { consumeCode, createCode, resendCode } = require("../../recipe/passwordless/utils"); - - assert(createCode !== undefined && _default.createCode !== undefined); - assert(consumeCode !== undefined && _default.consumeCode !== undefined); - assert(resendCode !== undefined && _default.resendCode !== undefined); - }); - it("Index", function () { let _default = require("../../recipe/passwordless"); let { diff --git a/test/with-typescript/index.ts b/test/with-typescript/index.ts index d7c53cd6..426fc988 100644 --- a/test/with-typescript/index.ts +++ b/test/with-typescript/index.ts @@ -912,21 +912,6 @@ const passwordlessRecipeImplementation = PasswordlessRecipeImplementation({ recipeId: passwordlessId, }); -PasswordlessUtils.consumeCode({ - userInputCode: "", - recipeImplementation: passwordlessRecipeImplementation, -}); - -PasswordlessUtils.createCode({ - email: "", - recipeImplementation: passwordlessRecipeImplementation, - phoneNumber: "", -}); - -PasswordlessUtils.resendCode({ - recipeImplementation: passwordlessRecipeImplementation, -}); - /** * Calling recipe functions exported from recipe/index files */