From 5172cbd70bb4e9a655989f5015140ec455cf556c Mon Sep 17 00:00:00 2001 From: Aman Agarwal Date: Fri, 13 Dec 2024 04:22:12 +0530 Subject: [PATCH 1/4] fix(email_verification): should refresh email verification is called once per second --- .../emailverification.6bb70c065a3e900daf8f.js | 1 + .../emailverification.82f788ef8c6e54629d91.js | 1 - .../emailVerificationClaim.d.ts | 1 + .../emailVerificationClaim.js | 6 ++- .../emailVerificationClaim.ts | 10 ++++- test/unit/emailverificationclaim.test.js | 43 +++++++++++++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 bundle/emailverification.6bb70c065a3e900daf8f.js delete mode 100644 bundle/emailverification.82f788ef8c6e54629d91.js diff --git a/bundle/emailverification.6bb70c065a3e900daf8f.js b/bundle/emailverification.6bb70c065a3e900daf8f.js new file mode 100644 index 00000000..07040a76 --- /dev/null +++ b/bundle/emailverification.6bb70c065a3e900daf8f.js @@ -0,0 +1 @@ +"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{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)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);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 a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+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,a=e.action,s=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:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=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:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288: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])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]a-1e3)return!1;if(n.shouldRefreshLastCalled=a,e=null!=e?e:(10,Math.max(10,u.DateProviderReference.getReferenceOrThrow().dateProvider.getThresholdInSeconds())),void 0!==t&&t ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var s=n.getValueFromPayload(r,o);if(void 0===s)return!0;var l=n.getLastFetchedTime(r,o);return void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=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 a(e){try{u(r.next(e))}catch(e){i(e)}}function s(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(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{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),a=n(1260),s=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 a.default("");return void 0!==e.apiGatewayPath&&(r=new a.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 a.default(n):new a.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,s.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.14.0",t.supported_fdi=["3.1","4.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),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},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))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},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=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file diff --git a/bundle/emailverification.82f788ef8c6e54629d91.js b/bundle/emailverification.82f788ef8c6e54629d91.js deleted file mode 100644 index 1ff9c746..00000000 --- a/bundle/emailverification.82f788ef8c6e54629d91.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{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)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);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 a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+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,a=e.action,s=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:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=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:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288: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])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1] ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var a=n.getValueFromPayload(r,o);if(void 0===a)return!0;var s=i.now(),l=n.getLastFetchedTime(r,o);return void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=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 a(e){try{u(r.next(e))}catch(e){i(e)}}function s(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(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{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),a=n(1260),s=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 a.default("");return void 0!==e.apiGatewayPath&&(r=new a.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 a.default(n):new a.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,s.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.14.0",t.supported_fdi=["3.1","4.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),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},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))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},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=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file diff --git a/lib/build/recipe/emailverification/emailVerificationClaim.d.ts b/lib/build/recipe/emailverification/emailVerificationClaim.d.ts index 04dd0a5e..0f884d44 100644 --- a/lib/build/recipe/emailverification/emailVerificationClaim.d.ts +++ b/lib/build/recipe/emailverification/emailVerificationClaim.d.ts @@ -8,4 +8,5 @@ export declare class EmailVerificationClaimClass extends BooleanClaim { validators: BooleanClaim["validators"] & { isVerified: (refetchTimeOnFalseInSeconds?: number, maxAgeInSeconds?: number) => SessionClaimValidator; }; + shouldRefreshLastCalled?: number; } diff --git a/lib/build/recipe/emailverification/emailVerificationClaim.js b/lib/build/recipe/emailverification/emailVerificationClaim.js index 51739f1a..c1134f5f 100644 --- a/lib/build/recipe/emailverification/emailVerificationClaim.js +++ b/lib/build/recipe/emailverification/emailVerificationClaim.js @@ -215,6 +215,11 @@ var EmailVerificationClaimClass = /** @class */ (function (_super) { refresh: _this.refresh, shouldRefresh: function (payload, userContext) { var DateProvider = dateProvider_1.DateProviderReference.getReferenceOrThrow().dateProvider; + var currentTime = DateProvider.now(); + if (_this.shouldRefreshLastCalled && _this.shouldRefreshLastCalled > currentTime - 1000) { + return false; + } + _this.shouldRefreshLastCalled = currentTime; refetchTimeOnFalseInSeconds = refetchTimeOnFalseInSeconds !== null && refetchTimeOnFalseInSeconds !== void 0 ? refetchTimeOnFalseInSeconds @@ -237,7 +242,6 @@ var EmailVerificationClaimClass = /** @class */ (function (_super) { if (value === undefined) { return true; } - var currentTime = DateProvider.now(); var lastRefetchTime = _this.getLastFetchedTime(payload, userContext); if (maxAgeInSeconds !== undefined) { if (lastRefetchTime < currentTime - maxAgeInSeconds * 1000) { diff --git a/lib/ts/recipe/emailverification/emailVerificationClaim.ts b/lib/ts/recipe/emailverification/emailVerificationClaim.ts index 68d62e3f..613e46b7 100644 --- a/lib/ts/recipe/emailverification/emailVerificationClaim.ts +++ b/lib/ts/recipe/emailverification/emailVerificationClaim.ts @@ -28,6 +28,13 @@ export class EmailVerificationClaimClass extends BooleanClaim { refresh: this.refresh, shouldRefresh: (payload, userContext) => { const DateProvider = DateProviderReference.getReferenceOrThrow().dateProvider; + const currentTime = DateProvider.now(); + + if (this.shouldRefreshLastCalled && this.shouldRefreshLastCalled > currentTime - 1000) { + return false; + } + + this.shouldRefreshLastCalled = currentTime; refetchTimeOnFalseInSeconds = refetchTimeOnFalseInSeconds ?? getThresholdAwareDefaultValue(10); @@ -49,7 +56,6 @@ export class EmailVerificationClaimClass extends BooleanClaim { return true; } - const currentTime = DateProvider.now(); const lastRefetchTime = this.getLastFetchedTime(payload, userContext)!; if (maxAgeInSeconds !== undefined) { @@ -82,4 +88,6 @@ export class EmailVerificationClaimClass extends BooleanClaim { validators!: BooleanClaim["validators"] & { isVerified: (refetchTimeOnFalseInSeconds?: number, maxAgeInSeconds?: number) => SessionClaimValidator; }; + + shouldRefreshLastCalled?: number; } diff --git a/test/unit/emailverificationclaim.test.js b/test/unit/emailverificationclaim.test.js index f33fd86b..24dd3f8f 100644 --- a/test/unit/emailverificationclaim.test.js +++ b/test/unit/emailverificationclaim.test.js @@ -17,6 +17,20 @@ import EmailVerification from "../../recipe/emailverification"; import SuperTokens from "../../lib/build/supertokens"; import assert from "assert"; +/* + * Delay function is used in case of email verification claim as we have added a debouncing + * mechanism that shouldRefresh will return false if multiple calls are done in 1000ms. + * Hence adding delay after each email verification or shouldRefresh calls will result in + * correct tests. + * Test for checking when the shouldRefresh returning false when called multiple times in 1000ms + * is added. + */ +const delay = async () => { + return new Promise((resolve) => { + setTimeout(resolve, 1000); + }); +}; + describe("EmailVerificationClaim test", function () { jsdom({ url: "http://localhost.org" }); @@ -35,6 +49,7 @@ describe("EmailVerificationClaim test", function () { }); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshUndefined = await validator.shouldRefresh({}); assert.strictEqual(shouldRefreshUndefined, true); }); @@ -49,9 +64,11 @@ describe("EmailVerificationClaim test", function () { }); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(10, 200); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ "st-ev": { v: true, t: Date.now() - 199 * 1000 }, }); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ "st-ev": { v: true, t: Date.now() - 201 * 1000 }, }); @@ -69,9 +86,11 @@ describe("EmailVerificationClaim test", function () { }); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(8); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ "st-ev": { v: false, t: Date.now() - 7 * 1000 }, }); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ "st-ev": { v: false, t: Date.now() - 9 * 1000 }, }); @@ -90,14 +109,38 @@ describe("EmailVerificationClaim test", function () { // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ "st-ev": { v: false, t: Date.now() - 9 * 1000 }, }); + await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ "st-ev": { v: false, t: Date.now() - 11 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); }); + + it("shouldRefresh should return false if called before 1000ms", async function () { + SuperTokens.init({ + appInfo: { + appName: "SuperTokens", + apiDomain: "api.supertokens.io", + }, + recipeList: [EmailVerification.init()], + }); + + // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds + const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); + await delay(); // Added for correct results, since shouldRefresh is debounced + const shouldRefresh = await validator.shouldRefresh({ + "st-ev": { v: false, t: Date.now() - 11 * 1000 }, + }); + const shouldRefreshAgain = await validator.shouldRefresh({ + "st-ev": { v: false, t: Date.now() - 11 * 1000 }, + }); + assert.strictEqual(shouldRefresh, true); + assert.strictEqual(shouldRefreshAgain, false); + }); }); }); From fb6e67a280affee2a3aa0dca8e0d739aab971708 Mon Sep 17 00:00:00 2001 From: Aman Agarwal Date: Fri, 13 Dec 2024 04:25:28 +0530 Subject: [PATCH 2/4] fix(email_verification): change log updated --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 077d81e2..b0b0d6bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +- Added a debounced mechanism in should refresh email verification to limit verification call to once per second. + ## [0.14.0] - 2024-10-07 - Added the OAuth2Provider recipe From 525cb008e599eea03df779ec5480812981708956 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Sun, 15 Dec 2024 17:45:53 +0100 Subject: [PATCH 3/4] fix: made existing tests require no changes and fixed EmailVerification recipe reset --- .../emailverification.6bb70c065a3e900daf8f.js | 1 - .../emailverification.7cd6a51e06782defcef5.js | 1 + .../emailVerificationClaim.js | 4 +- lib/build/recipe/emailverification/index.d.ts | 2 +- lib/build/recipe/emailverification/index.js | 8 +- lib/build/recipe/emailverification/recipe.js | 4 +- .../emailVerificationClaim.ts | 5 +- lib/ts/recipe/emailverification/index.ts | 4 +- lib/ts/recipe/emailverification/recipe.ts | 4 +- test/unit/emailverificationclaim.test.js | 89 ++++++++----------- 10 files changed, 60 insertions(+), 62 deletions(-) delete mode 100644 bundle/emailverification.6bb70c065a3e900daf8f.js create mode 100644 bundle/emailverification.7cd6a51e06782defcef5.js diff --git a/bundle/emailverification.6bb70c065a3e900daf8f.js b/bundle/emailverification.6bb70c065a3e900daf8f.js deleted file mode 100644 index 07040a76..00000000 --- a/bundle/emailverification.6bb70c065a3e900daf8f.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{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)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);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 a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+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,a=e.action,s=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:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=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:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288: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])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]a-1e3)return!1;if(n.shouldRefreshLastCalled=a,e=null!=e?e:(10,Math.max(10,u.DateProviderReference.getReferenceOrThrow().dateProvider.getThresholdInSeconds())),void 0!==t&&t ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var s=n.getValueFromPayload(r,o);if(void 0===s)return!0;var l=n.getLastFetchedTime(r,o);return void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=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 a(e){try{u(r.next(e))}catch(e){i(e)}}function s(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(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{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),a=n(1260),s=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 a.default("");return void 0!==e.apiGatewayPath&&(r=new a.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 a.default(n):new a.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,s.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.14.0",t.supported_fdi=["3.1","4.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),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},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))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},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=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file diff --git a/bundle/emailverification.7cd6a51e06782defcef5.js b/bundle/emailverification.7cd6a51e06782defcef5.js new file mode 100644 index 00000000..32b1659a --- /dev/null +++ b/bundle/emailverification.7cd6a51e06782defcef5.js @@ -0,0 +1 @@ +"use strict";var supertokensEmailVerification;(self.webpackChunksupertokens_web_js=self.webpackChunksupertokens_web_js||[]).push([[537,560],{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)}},5941:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.PostSuperTokensInitCallbacks=void 0;var n=function(){function e(){}return e.addPostInitCallback=function(t){e.postInitCallbacks.push(t)},e.runPostInitCallbacks=function(){for(var t=0,n=e.postInitCallbacks;t0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=300)throw f;return void 0===u?[3,4]:(d=f.clone(),[4,u({requestInit:l,url:e,fetchResponse:d})]);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 a.default(t),s="".concat(n.appInfo.apiDomain.getAsStringDangerous()).concat(o).concat(i.getAsStringDangerous());return void 0===r?s:s+"?"+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,a=e.action,s=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:a,userContext:u}))];case 1:return o=t.sent(),void 0===s||void 0===s.preAPIHook?[2,o]:[2,s.preAPIHook({url:o.url,requestInit:o.requestInit,userContext:u})]}}))}))}},e.preparePostAPIHook=function(e){var n=e.recipePostAPIHook,a=e.action,s=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:s,action:a}))];case 1:return t.sent(),[2]}}))}))}},e}();t.default=l},1199:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EMAILVERIFICATION_CLAIM_ID=void 0,t.EMAILVERIFICATION_CLAIM_ID="st-ev"},3288: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])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]a-1e3)return!1;if(e=null!=e?e:(10,Math.max(10,u.DateProviderReference.getReferenceOrThrow().dateProvider.getThresholdInSeconds())),void 0!==t&&t ".concat(i.getThresholdInSeconds()));if(e ".concat(i.getThresholdInSeconds()));var s=n.getValueFromPayload(r,o);if(void 0===s)return n.shouldRefreshLastCalled=a,!0;var l=n.getLastFetchedTime(r,o);return(void 0!==t&&l0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=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 a(e){try{u(r.next(e))}catch(e){i(e)}}function s(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(a,s)}u((r=r.apply(e,t||[])).next())}))},r=this&&this.__generator||function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)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 a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]{Object.defineProperty(t,"__esModule",{value:!0}),t.SessionClaimValidatorStore=void 0;var r=n(6376);Object.defineProperty(t,"SessionClaimValidatorStore",{enumerable:!0,get:function(){return r.SessionClaimValidatorStore}})},8122:(e,t,n)=>{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),a=n(1260),s=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 a.default("");return void 0!==e.apiGatewayPath&&(r=new a.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 a.default(n):new a.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,s.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.14.0",t.supported_fdi=["3.1","4.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),a=i.default.getClaimValidatorsAddedByOtherRecipes(),s=o.default.recipeImpl.getGlobalClaimValidators({claimValidatorsAddedByOtherRecipes:a,userContext:n});return void 0!==e?e(s,n):s}},9236:(e,t,n)=>{t.__esModule=!0,function(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}(n(2519))},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))},6376:(e,t,n)=>{function r(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}t.__esModule=!0;let o=n(2582);void 0!==o.default?r(o):r({default:o,...o})},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=(5857,e(e.s=5857));supertokensEmailVerification=t}]); \ No newline at end of file diff --git a/lib/build/recipe/emailverification/emailVerificationClaim.js b/lib/build/recipe/emailverification/emailVerificationClaim.js index c1134f5f..8adbbdb6 100644 --- a/lib/build/recipe/emailverification/emailVerificationClaim.js +++ b/lib/build/recipe/emailverification/emailVerificationClaim.js @@ -219,7 +219,6 @@ var EmailVerificationClaimClass = /** @class */ (function (_super) { if (_this.shouldRefreshLastCalled && _this.shouldRefreshLastCalled > currentTime - 1000) { return false; } - _this.shouldRefreshLastCalled = currentTime; refetchTimeOnFalseInSeconds = refetchTimeOnFalseInSeconds !== null && refetchTimeOnFalseInSeconds !== void 0 ? refetchTimeOnFalseInSeconds @@ -240,16 +239,19 @@ var EmailVerificationClaimClass = /** @class */ (function (_super) { } var value = _this.getValueFromPayload(payload, userContext); if (value === undefined) { + _this.shouldRefreshLastCalled = currentTime; return true; } var lastRefetchTime = _this.getLastFetchedTime(payload, userContext); if (maxAgeInSeconds !== undefined) { if (lastRefetchTime < currentTime - maxAgeInSeconds * 1000) { + _this.shouldRefreshLastCalled = currentTime; return true; } } if (value === false) { if (lastRefetchTime < currentTime - refetchTimeOnFalseInSeconds * 1000) { + _this.shouldRefreshLastCalled = currentTime; return true; } } diff --git a/lib/build/recipe/emailverification/index.d.ts b/lib/build/recipe/emailverification/index.d.ts index 5b633145..937161ad 100644 --- a/lib/build/recipe/emailverification/index.d.ts +++ b/lib/build/recipe/emailverification/index.d.ts @@ -2,7 +2,7 @@ import { RecipeInterface, PreAPIHookContext, PostAPIHookContext, UserInput } fro import { RecipeFunctionOptions } from "../recipeModule/types"; import { EmailVerificationClaimClass } from "./emailVerificationClaim"; export default class RecipeWrapper { - static EmailVerificationClaim: EmailVerificationClaimClass; + static get EmailVerificationClaim(): EmailVerificationClaimClass; static init( config?: UserInput ): import("../../types").CreateRecipeFunction; diff --git a/lib/build/recipe/emailverification/index.js b/lib/build/recipe/emailverification/index.js index f394696c..26d4c602 100644 --- a/lib/build/recipe/emailverification/index.js +++ b/lib/build/recipe/emailverification/index.js @@ -34,6 +34,13 @@ Object.defineProperty(exports, "EmailVerificationClaimClass", { }); var RecipeWrapper = /** @class */ (function () { function RecipeWrapper() {} + Object.defineProperty(RecipeWrapper, "EmailVerificationClaim", { + get: function () { + return recipe_1.default.EmailVerificationClaim; + }, + enumerable: false, + configurable: true, + }); RecipeWrapper.init = function (config) { return recipe_1.default.init(config); }; @@ -124,7 +131,6 @@ var RecipeWrapper = /** @class */ (function () { }) ); }; - RecipeWrapper.EmailVerificationClaim = recipe_1.default.EmailVerificationClaim; return RecipeWrapper; })(); exports.default = RecipeWrapper; diff --git a/lib/build/recipe/emailverification/recipe.js b/lib/build/recipe/emailverification/recipe.js index 733435d9..3a9f661f 100644 --- a/lib/build/recipe/emailverification/recipe.js +++ b/lib/build/recipe/emailverification/recipe.js @@ -77,7 +77,9 @@ var Recipe = /** @class */ (function () { return; } Recipe.instance = undefined; - return; + Recipe.EmailVerificationClaim = new emailVerificationClaim_1.EmailVerificationClaimClass(function () { + return Recipe.getInstanceOrThrow().recipeImplementation; + }); }; Recipe.RECIPE_ID = "emailverification"; Recipe.EmailVerificationClaim = new emailVerificationClaim_1.EmailVerificationClaimClass(function () { diff --git a/lib/ts/recipe/emailverification/emailVerificationClaim.ts b/lib/ts/recipe/emailverification/emailVerificationClaim.ts index 613e46b7..8c3847e6 100644 --- a/lib/ts/recipe/emailverification/emailVerificationClaim.ts +++ b/lib/ts/recipe/emailverification/emailVerificationClaim.ts @@ -34,8 +34,6 @@ export class EmailVerificationClaimClass extends BooleanClaim { return false; } - this.shouldRefreshLastCalled = currentTime; - refetchTimeOnFalseInSeconds = refetchTimeOnFalseInSeconds ?? getThresholdAwareDefaultValue(10); if (maxAgeInSeconds !== undefined && maxAgeInSeconds < DateProvider.getThresholdInSeconds()) { @@ -53,6 +51,7 @@ export class EmailVerificationClaimClass extends BooleanClaim { const value = this.getValueFromPayload(payload, userContext); if (value === undefined) { + this.shouldRefreshLastCalled = currentTime; return true; } @@ -60,12 +59,14 @@ export class EmailVerificationClaimClass extends BooleanClaim { if (maxAgeInSeconds !== undefined) { if (lastRefetchTime < currentTime - maxAgeInSeconds * 1000) { + this.shouldRefreshLastCalled = currentTime; return true; } } if (value === false) { if (lastRefetchTime < currentTime - refetchTimeOnFalseInSeconds * 1000) { + this.shouldRefreshLastCalled = currentTime; return true; } } diff --git a/lib/ts/recipe/emailverification/index.ts b/lib/ts/recipe/emailverification/index.ts index ecf61520..a7aa0de4 100644 --- a/lib/ts/recipe/emailverification/index.ts +++ b/lib/ts/recipe/emailverification/index.ts @@ -19,7 +19,9 @@ import { getNormalisedUserContext } from "../../utils"; import { EmailVerificationClaimClass } from "./emailVerificationClaim"; export default class RecipeWrapper { - static EmailVerificationClaim = Recipe.EmailVerificationClaim; + static get EmailVerificationClaim() { + return Recipe.EmailVerificationClaim; + } static init(config?: UserInput) { return Recipe.init(config); diff --git a/lib/ts/recipe/emailverification/recipe.ts b/lib/ts/recipe/emailverification/recipe.ts index a6e0cb0e..06baf7ab 100644 --- a/lib/ts/recipe/emailverification/recipe.ts +++ b/lib/ts/recipe/emailverification/recipe.ts @@ -85,7 +85,9 @@ export default class Recipe implements RecipeModule Recipe.getInstanceOrThrow().recipeImplementation + ); } } diff --git a/test/unit/emailverificationclaim.test.js b/test/unit/emailverificationclaim.test.js index 24dd3f8f..a415a536 100644 --- a/test/unit/emailverificationclaim.test.js +++ b/test/unit/emailverificationclaim.test.js @@ -14,6 +14,7 @@ */ import jsdom from "mocha-jsdom"; import EmailVerification from "../../recipe/emailverification"; +import EmailVerificationRecipe from "../../lib/build/recipe/emailverification/recipe"; import SuperTokens from "../../lib/build/supertokens"; import assert from "assert"; @@ -25,10 +26,27 @@ import assert from "assert"; * Test for checking when the shouldRefresh returning false when called multiple times in 1000ms * is added. */ +let delayCounter = 0; const delay = async () => { - return new Promise((resolve) => { - setTimeout(resolve, 1000); - }); + ++delayCounter; +}; + +const commonConfig = { + appInfo: { + appName: "SuperTokens", + apiDomain: "api.supertokens.io", + }, + dateProvider: function () { + return { + getThresholdInSeconds: function () { + return 7; + }, + now: function () { + return Date.now() + delayCounter * 1000; + }, + }; + }, + recipeList: [EmailVerification.init()], }; describe("EmailVerificationClaim test", function () { @@ -36,108 +54,73 @@ describe("EmailVerificationClaim test", function () { beforeEach(function () { SuperTokens.reset(); + EmailVerificationRecipe.reset(); + delayCounter = 0; }); describe("EmailVerification Claim", function () { it("value should be refreshed if it is undefined", async function () { - SuperTokens.init({ - appInfo: { - appName: "SuperTokens", - apiDomain: "api.supertokens.io", - }, - recipeList: [EmailVerification.init()], - }); + SuperTokens.init(commonConfig); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshUndefined = await validator.shouldRefresh({}); assert.strictEqual(shouldRefreshUndefined, true); }); it("value should be refreshed as per maxAgeInSeconds if it is provided", async function () { - SuperTokens.init({ - appInfo: { - appName: "SuperTokens", - apiDomain: "api.supertokens.io", - }, - recipeList: [EmailVerification.init()], - }); + SuperTokens.init(commonConfig); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(10, 200); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: true, t: Date.now() - 199 * 1000 }, + "st-ev": { v: true, t: Date.now() + delayCounter * 1000 - 199 * 1000 }, }); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: true, t: Date.now() - 201 * 1000 }, + "st-ev": { v: true, t: Date.now() + delayCounter * 1000 - 201 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); }); it("value should be refreshed as per refetchTimeOnFalseInSeconds if it is provided", async function () { - SuperTokens.init({ - appInfo: { - appName: "SuperTokens", - apiDomain: "api.supertokens.io", - }, - recipeList: [EmailVerification.init()], - }); + SuperTokens.init(commonConfig); const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(8); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 7 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 7 * 1000 }, }); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 9 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 9 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); }); it("value should be refreshed as per default the refetchTimeOnFalseInSeconds if it is not provided", async function () { - SuperTokens.init({ - appInfo: { - appName: "SuperTokens", - apiDomain: "api.supertokens.io", - }, - recipeList: [EmailVerification.init()], - }); + SuperTokens.init(commonConfig); // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 9 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 9 * 1000 }, }); await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); }); it("shouldRefresh should return false if called before 1000ms", async function () { - SuperTokens.init({ - appInfo: { - appName: "SuperTokens", - apiDomain: "api.supertokens.io", - }, - recipeList: [EmailVerification.init()], - }); + SuperTokens.init(commonConfig); // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); - await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefresh = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, }); const shouldRefreshAgain = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, }); assert.strictEqual(shouldRefresh, true); assert.strictEqual(shouldRefreshAgain, false); From 88aac6d2012f0b8679685bfd3567b494db06e7d6 Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Sun, 15 Dec 2024 17:48:33 +0100 Subject: [PATCH 4/4] test: removed some unnecessary test changes --- test/unit/emailverificationclaim.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/emailverificationclaim.test.js b/test/unit/emailverificationclaim.test.js index a415a536..f9b8ea82 100644 --- a/test/unit/emailverificationclaim.test.js +++ b/test/unit/emailverificationclaim.test.js @@ -72,10 +72,10 @@ describe("EmailVerificationClaim test", function () { const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(10, 200); const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: true, t: Date.now() + delayCounter * 1000 - 199 * 1000 }, + "st-ev": { v: true, t: Date.now() - 199 * 1000 }, }); const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: true, t: Date.now() + delayCounter * 1000 - 201 * 1000 }, + "st-ev": { v: true, t: Date.now() - 201 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); @@ -86,10 +86,10 @@ describe("EmailVerificationClaim test", function () { const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(8); const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 7 * 1000 }, + "st-ev": { v: false, t: Date.now() - 7 * 1000 }, }); const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 9 * 1000 }, + "st-ev": { v: false, t: Date.now() - 9 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); @@ -101,11 +101,11 @@ describe("EmailVerificationClaim test", function () { // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); const shouldRefreshValid = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 9 * 1000 }, + "st-ev": { v: false, t: Date.now() - 9 * 1000 }, }); await delay(); // Added for correct results, since shouldRefresh is debounced const shouldRefreshExpired = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() - 11 * 1000 }, }); assert.strictEqual(shouldRefreshValid, false); assert.strictEqual(shouldRefreshExpired, true); @@ -117,10 +117,10 @@ describe("EmailVerificationClaim test", function () { // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); const shouldRefresh = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() - 11 * 1000 }, }); const shouldRefreshAgain = await validator.shouldRefresh({ - "st-ev": { v: false, t: Date.now() + delayCounter * 1000 - 11 * 1000 }, + "st-ev": { v: false, t: Date.now() - 11 * 1000 }, }); assert.strictEqual(shouldRefresh, true); assert.strictEqual(shouldRefreshAgain, false);