From d49ae9c8f9f1eea3bfcf96346564c332f12f26d3 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 6 Jul 2023 15:48:09 +0530 Subject: [PATCH 01/14] fix: passwordless --- .../emailpassword/api/implementation.js | 16 +++---- lib/build/recipe/emailpassword/index.d.ts | 22 +++++++++ lib/build/recipe/emailpassword/index.js | 41 ++++++++++++++++- lib/build/recipe/emailpassword/utils.d.ts | 6 +++ lib/build/recipe/emailpassword/utils.js | 15 ++++++- .../emailpassword/api/implementation.ts | 16 +++---- lib/ts/recipe/emailpassword/index.ts | 45 +++++++++++++++++++ lib/ts/recipe/emailpassword/utils.ts | 18 ++++++++ 8 files changed, 159 insertions(+), 20 deletions(-) diff --git a/lib/build/recipe/emailpassword/api/implementation.js b/lib/build/recipe/emailpassword/api/implementation.js index 4d89c70f9..c4dfe76af 100644 --- a/lib/build/recipe/emailpassword/api/implementation.js +++ b/lib/build/recipe/emailpassword/api/implementation.js @@ -38,6 +38,7 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const logger_1 = require("../../../logger"); const session_1 = __importDefault(require("../../session")); +const utils_1 = require("../utils"); function getAPIImplementation() { return { emailExistsGET: function ({ email, tenantId, options, userContext }) { @@ -69,15 +70,12 @@ function getAPIImplementation() { status: "OK", }; } - let passwordResetLink = - options.appInfo.websiteDomain.getAsStringDangerous() + - options.appInfo.websiteBasePath.getAsStringDangerous() + - "/reset-password?token=" + - response.token + - "&rid=" + - options.recipeId + - "&tenantId=" + - tenantId; + let passwordResetLink = utils_1.getPasswordResetLink({ + appInfo: options.appInfo, + token: response.token, + recipeId: options.recipeId, + tenantId, + }); logger_1.logDebugMessage(`Sending password reset email to ${email}`); yield options.emailDelivery.ingredientInterfaceImpl.sendEmail({ type: "PASSWORD_RESET", diff --git a/lib/build/recipe/emailpassword/index.d.ts b/lib/build/recipe/emailpassword/index.d.ts index f698c2a55..e0d377998 100644 --- a/lib/build/recipe/emailpassword/index.d.ts +++ b/lib/build/recipe/emailpassword/index.d.ts @@ -77,6 +77,26 @@ export default class Wrapper { failureReason: string; } >; + static generatePasswordResetLink( + userId: string, + tenantId?: string, + userContext?: any + ): Promise< + | { + status: "OK"; + link: string; + } + | { + status: "UNKNOWN_USER_ID_ERROR"; + } + >; + static sendPasswordResetEmail( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ + status: string; + }>; static sendEmail( input: TypeEmailPasswordEmailDeliveryInput & { userContext?: any; @@ -93,4 +113,6 @@ export declare let createResetPasswordToken: typeof Wrapper.createResetPasswordT export declare let resetPasswordUsingToken: typeof Wrapper.resetPasswordUsingToken; export declare let updateEmailOrPassword: typeof Wrapper.updateEmailOrPassword; export type { RecipeInterface, User, APIOptions, APIInterface }; +export declare let generatePasswordResetLink: typeof Wrapper.generatePasswordResetLink; +export declare let sendPasswordResetEmail: typeof Wrapper.sendPasswordResetEmail; export declare let sendEmail: typeof Wrapper.sendEmail; diff --git a/lib/build/recipe/emailpassword/index.js b/lib/build/recipe/emailpassword/index.js index 92f34945d..67be66745 100644 --- a/lib/build/recipe/emailpassword/index.js +++ b/lib/build/recipe/emailpassword/index.js @@ -50,10 +50,11 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendEmail = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUserByEmail = exports.getUserById = exports.signIn = exports.signUp = exports.Error = exports.init = void 0; +exports.sendEmail = exports.sendPasswordResetEmail = exports.generatePasswordResetLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUserByEmail = exports.getUserById = exports.signIn = exports.signUp = exports.Error = exports.init = void 0; const recipe_1 = __importDefault(require("./recipe")); const error_1 = __importDefault(require("./error")); const constants_1 = require("../multitenancy/constants"); +const utils_1 = require("./utils"); class Wrapper { static signUp(email, password, tenantId, userContext) { return recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.signUp({ @@ -104,6 +105,42 @@ class Wrapper { .getInstanceOrThrowError() .recipeInterfaceImpl.updateEmailOrPassword(Object.assign({ userContext: {} }, input)); } + static generatePasswordResetLink(userId, tenantId, userContext) { + return __awaiter(this, void 0, void 0, function* () { + let token = yield exports.createResetPasswordToken(userId, tenantId, userContext); + if (token.status === "UNKNOWN_USER_ID_ERROR") { + return token; + } + const recipeInstance = recipe_1.default.getInstanceOrThrowError(); + return { + status: "OK", + link: utils_1.getPasswordResetLink({ + appInfo: recipeInstance.getAppInfo(), + recipeId: recipeInstance.getRecipeId(), + token: token.token, + tenantId: tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId, + }), + }; + }); + } + static sendPasswordResetEmail(userId, tenantId, userContext) { + return __awaiter(this, void 0, void 0, function* () { + let link = yield exports.generatePasswordResetLink(userId, tenantId, userContext); + if (link.status === "UNKNOWN_USER_ID_ERROR") { + return link; + } + yield exports.sendEmail({ + passwordResetLink: link.link, + type: "PASSWORD_RESET", + user: yield exports.getUserById(userId, userContext), + tenantId, + userContext, + }); + return { + status: "OK", + }; + }); + } static sendEmail(input) { return __awaiter(this, void 0, void 0, function* () { let recipeInstance = recipe_1.default.getInstanceOrThrowError(); @@ -127,4 +164,6 @@ exports.getUserByEmail = Wrapper.getUserByEmail; exports.createResetPasswordToken = Wrapper.createResetPasswordToken; exports.resetPasswordUsingToken = Wrapper.resetPasswordUsingToken; exports.updateEmailOrPassword = Wrapper.updateEmailOrPassword; +exports.generatePasswordResetLink = Wrapper.generatePasswordResetLink; +exports.sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; exports.sendEmail = Wrapper.sendEmail; diff --git a/lib/build/recipe/emailpassword/utils.d.ts b/lib/build/recipe/emailpassword/utils.d.ts index c48cdc96d..5e01cc47d 100644 --- a/lib/build/recipe/emailpassword/utils.d.ts +++ b/lib/build/recipe/emailpassword/utils.d.ts @@ -21,3 +21,9 @@ export declare function defaultPasswordValidator( export declare function defaultEmailValidator( value: any ): Promise<"Development bug: Please make sure the email field yields a string" | "Email is invalid" | undefined>; +export declare function getPasswordResetLink(input: { + appInfo: NormalisedAppinfo; + token: string; + recipeId: string; + tenantId: string; +}): string; diff --git a/lib/build/recipe/emailpassword/utils.js b/lib/build/recipe/emailpassword/utils.js index e50c8f7bb..064ecd8ea 100644 --- a/lib/build/recipe/emailpassword/utils.js +++ b/lib/build/recipe/emailpassword/utils.js @@ -50,7 +50,7 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.defaultEmailValidator = exports.defaultPasswordValidator = exports.normaliseSignUpFormFields = exports.validateAndNormaliseUserInput = void 0; +exports.getPasswordResetLink = exports.defaultEmailValidator = exports.defaultPasswordValidator = exports.normaliseSignUpFormFields = exports.validateAndNormaliseUserInput = void 0; const constants_1 = require("./constants"); const backwardCompatibility_1 = __importDefault(require("./emaildelivery/services/backwardCompatibility")); function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { @@ -256,3 +256,16 @@ function defaultEmailValidator(value) { }); } exports.defaultEmailValidator = defaultEmailValidator; +function getPasswordResetLink(input) { + return ( + input.appInfo.websiteDomain.getAsStringDangerous() + + input.appInfo.websiteBasePath.getAsStringDangerous() + + "/reset-password?token=" + + input.token + + "&rid=" + + input.recipeId + + "&tenantId=" + + input.tenantId + ); +} +exports.getPasswordResetLink = getPasswordResetLink; diff --git a/lib/ts/recipe/emailpassword/api/implementation.ts b/lib/ts/recipe/emailpassword/api/implementation.ts index b6828c5c5..0f4e78071 100644 --- a/lib/ts/recipe/emailpassword/api/implementation.ts +++ b/lib/ts/recipe/emailpassword/api/implementation.ts @@ -3,6 +3,7 @@ import { logDebugMessage } from "../../../logger"; import Session from "../../session"; import { SessionContainerInterface } from "../../session/types"; import { GeneralErrorResponse } from "../../../types"; +import { getPasswordResetLink } from "../utils"; export default function getAPIImplementation(): APIInterface { return { @@ -70,15 +71,12 @@ export default function getAPIImplementation(): APIInterface { }; } - let passwordResetLink = - options.appInfo.websiteDomain.getAsStringDangerous() + - options.appInfo.websiteBasePath.getAsStringDangerous() + - "/reset-password?token=" + - response.token + - "&rid=" + - options.recipeId + - "&tenantId=" + - tenantId; + let passwordResetLink = getPasswordResetLink({ + appInfo: options.appInfo, + token: response.token, + recipeId: options.recipeId, + tenantId, + }); logDebugMessage(`Sending password reset email to ${email}`); await options.emailDelivery.ingredientInterfaceImpl.sendEmail({ diff --git a/lib/ts/recipe/emailpassword/index.ts b/lib/ts/recipe/emailpassword/index.ts index d0b465758..1de6e44aa 100644 --- a/lib/ts/recipe/emailpassword/index.ts +++ b/lib/ts/recipe/emailpassword/index.ts @@ -17,6 +17,7 @@ import Recipe from "./recipe"; import SuperTokensError from "./error"; import { RecipeInterface, User, APIOptions, APIInterface, TypeEmailPasswordEmailDeliveryInput } from "./types"; import { DEFAULT_TENANT_ID } from "../multitenancy/constants"; +import { getPasswordResetLink } from "./utils"; export default class Wrapper { static init = Recipe.init; @@ -86,6 +87,46 @@ export default class Wrapper { }); } + static async generatePasswordResetLink( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ status: "OK"; link: string } | { status: "UNKNOWN_USER_ID_ERROR" }> { + let token = await createResetPasswordToken(userId, tenantId, userContext); + if (token.status === "UNKNOWN_USER_ID_ERROR") { + return token; + } + + const recipeInstance = Recipe.getInstanceOrThrowError(); + return { + status: "OK", + link: getPasswordResetLink({ + appInfo: recipeInstance.getAppInfo(), + recipeId: recipeInstance.getRecipeId(), + token: token.token, + tenantId: tenantId === undefined ? DEFAULT_TENANT_ID : tenantId, + }), + }; + } + + static async sendPasswordResetEmail(userId: string, tenantId?: string, userContext?: any) { + let link = await generatePasswordResetLink(userId, tenantId, userContext); + if (link.status === "UNKNOWN_USER_ID_ERROR") { + return link; + } + await sendEmail({ + passwordResetLink: link.link, + type: "PASSWORD_RESET", + user: (await getUserById(userId, userContext))!, + tenantId, + userContext, + }); + + return { + status: "OK", + }; + } + static async sendEmail(input: TypeEmailPasswordEmailDeliveryInput & { userContext?: any }) { let recipeInstance = Recipe.getInstanceOrThrowError(); return await recipeInstance.emailDelivery.ingredientInterfaceImpl.sendEmail({ @@ -116,4 +157,8 @@ export let updateEmailOrPassword = Wrapper.updateEmailOrPassword; export type { RecipeInterface, User, APIOptions, APIInterface }; +export let generatePasswordResetLink = Wrapper.generatePasswordResetLink; + +export let sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; + export let sendEmail = Wrapper.sendEmail; diff --git a/lib/ts/recipe/emailpassword/utils.ts b/lib/ts/recipe/emailpassword/utils.ts index 27cade323..0e93633ba 100644 --- a/lib/ts/recipe/emailpassword/utils.ts +++ b/lib/ts/recipe/emailpassword/utils.ts @@ -255,3 +255,21 @@ export async function defaultEmailValidator(value: any) { return undefined; } + +export function getPasswordResetLink(input: { + appInfo: NormalisedAppinfo; + token: string; + recipeId: string; + tenantId: string; +}): string { + return ( + input.appInfo.websiteDomain.getAsStringDangerous() + + input.appInfo.websiteBasePath.getAsStringDangerous() + + "/reset-password?token=" + + input.token + + "&rid=" + + input.recipeId + + "&tenantId=" + + input.tenantId + ); +} From bb579472c050459eea539bfdf85a1a737af09326 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 6 Jul 2023 15:57:57 +0530 Subject: [PATCH 02/14] fix: password reset in tpep --- lib/build/recipe/emailpassword/index.d.ts | 2 +- .../recipe/thirdpartyemailpassword/index.d.ts | 22 +++++++++ .../recipe/thirdpartyemailpassword/index.js | 41 +++++++++++++++- lib/ts/recipe/emailpassword/index.ts | 6 ++- .../recipe/thirdpartyemailpassword/index.ts | 49 +++++++++++++++++++ 5 files changed, 117 insertions(+), 3 deletions(-) diff --git a/lib/build/recipe/emailpassword/index.d.ts b/lib/build/recipe/emailpassword/index.d.ts index e0d377998..4e2174de0 100644 --- a/lib/build/recipe/emailpassword/index.d.ts +++ b/lib/build/recipe/emailpassword/index.d.ts @@ -95,7 +95,7 @@ export default class Wrapper { tenantId?: string, userContext?: any ): Promise<{ - status: string; + status: "OK" | "UNKNOWN_USER_ID_ERROR"; }>; static sendEmail( input: TypeEmailPasswordEmailDeliveryInput & { diff --git a/lib/build/recipe/thirdpartyemailpassword/index.d.ts b/lib/build/recipe/thirdpartyemailpassword/index.d.ts index 7d81dc0c8..c9735b39b 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.d.ts +++ b/lib/build/recipe/thirdpartyemailpassword/index.d.ts @@ -106,6 +106,26 @@ export default class Wrapper { failureReason: string; } >; + static generatePasswordResetLink( + userId: string, + tenantId?: string, + userContext?: any + ): Promise< + | { + status: "OK"; + link: string; + } + | { + status: "UNKNOWN_USER_ID_ERROR"; + } + >; + static sendPasswordResetEmail( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ + status: "OK" | "UNKNOWN_USER_ID_ERROR"; + }>; static sendEmail( input: TypeEmailPasswordEmailDeliveryInput & { userContext?: any; @@ -125,4 +145,6 @@ export declare let createResetPasswordToken: typeof Wrapper.createResetPasswordT export declare let resetPasswordUsingToken: typeof Wrapper.resetPasswordUsingToken; export declare let updateEmailOrPassword: typeof Wrapper.updateEmailOrPassword; export type { RecipeInterface, TypeProvider, User, APIInterface, EmailPasswordAPIOptions, ThirdPartyAPIOptions }; +export declare let generatePasswordResetLink: typeof Wrapper.generatePasswordResetLink; +export declare let sendPasswordResetEmail: typeof Wrapper.sendPasswordResetEmail; export declare let sendEmail: typeof Wrapper.sendEmail; diff --git a/lib/build/recipe/thirdpartyemailpassword/index.js b/lib/build/recipe/thirdpartyemailpassword/index.js index 573585073..221bc7969 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.js +++ b/lib/build/recipe/thirdpartyemailpassword/index.js @@ -50,10 +50,11 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendEmail = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUsersByEmail = exports.getUserByThirdPartyInfo = exports.getUserById = exports.thirdPartyManuallyCreateOrUpdateUser = exports.thirdPartyGetProvider = exports.emailPasswordSignIn = exports.emailPasswordSignUp = exports.Error = exports.init = void 0; +exports.sendEmail = exports.sendPasswordResetEmail = exports.generatePasswordResetLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUsersByEmail = exports.getUserByThirdPartyInfo = exports.getUserById = exports.thirdPartyManuallyCreateOrUpdateUser = exports.thirdPartyGetProvider = exports.emailPasswordSignIn = exports.emailPasswordSignUp = exports.Error = exports.init = void 0; const recipe_1 = __importDefault(require("./recipe")); const error_1 = __importDefault(require("./error")); const constants_1 = require("../multitenancy/constants"); +const utils_1 = require("../emailpassword/utils"); class Wrapper { static thirdPartyGetProvider(thirdPartyId, clientType, tenantId, userContext = {}) { return __awaiter(this, void 0, void 0, function* () { @@ -128,6 +129,42 @@ class Wrapper { .getInstanceOrThrowError() .recipeInterfaceImpl.updateEmailOrPassword(Object.assign({ userContext: {} }, input)); } + static generatePasswordResetLink(userId, tenantId, userContext) { + return __awaiter(this, void 0, void 0, function* () { + let token = yield exports.createResetPasswordToken(userId, tenantId, userContext); + if (token.status === "UNKNOWN_USER_ID_ERROR") { + return token; + } + const recipeInstance = recipe_1.default.getInstanceOrThrowError(); + return { + status: "OK", + link: utils_1.getPasswordResetLink({ + appInfo: recipeInstance.getAppInfo(), + recipeId: recipeInstance.getRecipeId(), + token: token.token, + tenantId: tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId, + }), + }; + }); + } + static sendPasswordResetEmail(userId, tenantId, userContext) { + return __awaiter(this, void 0, void 0, function* () { + let link = yield exports.generatePasswordResetLink(userId, tenantId, userContext); + if (link.status === "UNKNOWN_USER_ID_ERROR") { + return link; + } + yield exports.sendEmail({ + passwordResetLink: link.link, + type: "PASSWORD_RESET", + user: yield exports.getUserById(userId, userContext), + tenantId, + userContext, + }); + return { + status: "OK", + }; + }); + } static sendEmail(input) { return __awaiter(this, void 0, void 0, function* () { return yield recipe_1.default.getInstanceOrThrowError().emailDelivery.ingredientInterfaceImpl.sendEmail( @@ -153,4 +190,6 @@ exports.getUsersByEmail = Wrapper.getUsersByEmail; exports.createResetPasswordToken = Wrapper.createResetPasswordToken; exports.resetPasswordUsingToken = Wrapper.resetPasswordUsingToken; exports.updateEmailOrPassword = Wrapper.updateEmailOrPassword; +exports.generatePasswordResetLink = Wrapper.generatePasswordResetLink; +exports.sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; exports.sendEmail = Wrapper.sendEmail; diff --git a/lib/ts/recipe/emailpassword/index.ts b/lib/ts/recipe/emailpassword/index.ts index 1de6e44aa..cf630907f 100644 --- a/lib/ts/recipe/emailpassword/index.ts +++ b/lib/ts/recipe/emailpassword/index.ts @@ -109,7 +109,11 @@ export default class Wrapper { }; } - static async sendPasswordResetEmail(userId: string, tenantId?: string, userContext?: any) { + static async sendPasswordResetEmail( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ status: "OK" | "UNKNOWN_USER_ID_ERROR" }> { let link = await generatePasswordResetLink(userId, tenantId, userContext); if (link.status === "UNKNOWN_USER_ID_ERROR") { return link; diff --git a/lib/ts/recipe/thirdpartyemailpassword/index.ts b/lib/ts/recipe/thirdpartyemailpassword/index.ts index 756bd361e..ed412362b 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/index.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/index.ts @@ -19,6 +19,7 @@ import { RecipeInterface, User, APIInterface, EmailPasswordAPIOptions, ThirdPart import { TypeProvider } from "../thirdparty/types"; import { TypeEmailPasswordEmailDeliveryInput } from "../emailpassword/types"; import { DEFAULT_TENANT_ID } from "../multitenancy/constants"; +import { getPasswordResetLink } from "../emailpassword/utils"; export default class Wrapper { static init = Recipe.init; @@ -129,6 +130,50 @@ export default class Wrapper { }); } + static async generatePasswordResetLink( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ status: "OK"; link: string } | { status: "UNKNOWN_USER_ID_ERROR" }> { + let token = await createResetPasswordToken(userId, tenantId, userContext); + if (token.status === "UNKNOWN_USER_ID_ERROR") { + return token; + } + + const recipeInstance = Recipe.getInstanceOrThrowError(); + return { + status: "OK", + link: getPasswordResetLink({ + appInfo: recipeInstance.getAppInfo(), + recipeId: recipeInstance.getRecipeId(), + token: token.token, + tenantId: tenantId === undefined ? DEFAULT_TENANT_ID : tenantId, + }), + }; + } + + static async sendPasswordResetEmail( + userId: string, + tenantId?: string, + userContext?: any + ): Promise<{ status: "OK" | "UNKNOWN_USER_ID_ERROR" }> { + let link = await generatePasswordResetLink(userId, tenantId, userContext); + if (link.status === "UNKNOWN_USER_ID_ERROR") { + return link; + } + await sendEmail({ + passwordResetLink: link.link, + type: "PASSWORD_RESET", + user: (await getUserById(userId, userContext))!, + tenantId, + userContext, + }); + + return { + status: "OK", + }; + } + static async sendEmail(input: TypeEmailPasswordEmailDeliveryInput & { userContext?: any }) { return await Recipe.getInstanceOrThrowError().emailDelivery.ingredientInterfaceImpl.sendEmail({ userContext: {}, @@ -164,4 +209,8 @@ export let updateEmailOrPassword = Wrapper.updateEmailOrPassword; export type { RecipeInterface, TypeProvider, User, APIInterface, EmailPasswordAPIOptions, ThirdPartyAPIOptions }; +export let generatePasswordResetLink = Wrapper.generatePasswordResetLink; + +export let sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; + export let sendEmail = Wrapper.sendEmail; From 53eb0225b5470ee23baf1b7983a6e1ce98b3ca7b Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 6 Jul 2023 16:02:07 +0530 Subject: [PATCH 03/14] fix: rename functions --- lib/build/recipe/emailpassword/index.d.ts | 8 ++++---- lib/build/recipe/emailpassword/index.js | 12 ++++++------ lib/build/recipe/thirdpartyemailpassword/index.d.ts | 8 ++++---- lib/build/recipe/thirdpartyemailpassword/index.js | 12 ++++++------ lib/ts/recipe/emailpassword/index.ts | 10 +++++----- lib/ts/recipe/thirdpartyemailpassword/index.ts | 10 +++++----- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/lib/build/recipe/emailpassword/index.d.ts b/lib/build/recipe/emailpassword/index.d.ts index 4e2174de0..654045cc6 100644 --- a/lib/build/recipe/emailpassword/index.d.ts +++ b/lib/build/recipe/emailpassword/index.d.ts @@ -77,7 +77,7 @@ export default class Wrapper { failureReason: string; } >; - static generatePasswordResetLink( + static createResetPasswordLink( userId: string, tenantId?: string, userContext?: any @@ -90,7 +90,7 @@ export default class Wrapper { status: "UNKNOWN_USER_ID_ERROR"; } >; - static sendPasswordResetEmail( + static sendResetPasswordEmail( userId: string, tenantId?: string, userContext?: any @@ -113,6 +113,6 @@ export declare let createResetPasswordToken: typeof Wrapper.createResetPasswordT export declare let resetPasswordUsingToken: typeof Wrapper.resetPasswordUsingToken; export declare let updateEmailOrPassword: typeof Wrapper.updateEmailOrPassword; export type { RecipeInterface, User, APIOptions, APIInterface }; -export declare let generatePasswordResetLink: typeof Wrapper.generatePasswordResetLink; -export declare let sendPasswordResetEmail: typeof Wrapper.sendPasswordResetEmail; +export declare let createResetPasswordLink: typeof Wrapper.createResetPasswordLink; +export declare let sendResetPasswordEmail: typeof Wrapper.sendResetPasswordEmail; export declare let sendEmail: typeof Wrapper.sendEmail; diff --git a/lib/build/recipe/emailpassword/index.js b/lib/build/recipe/emailpassword/index.js index 67be66745..c942897ef 100644 --- a/lib/build/recipe/emailpassword/index.js +++ b/lib/build/recipe/emailpassword/index.js @@ -50,7 +50,7 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendEmail = exports.sendPasswordResetEmail = exports.generatePasswordResetLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUserByEmail = exports.getUserById = exports.signIn = exports.signUp = exports.Error = exports.init = void 0; +exports.sendEmail = exports.sendResetPasswordEmail = exports.createResetPasswordLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUserByEmail = exports.getUserById = exports.signIn = exports.signUp = exports.Error = exports.init = void 0; const recipe_1 = __importDefault(require("./recipe")); const error_1 = __importDefault(require("./error")); const constants_1 = require("../multitenancy/constants"); @@ -105,7 +105,7 @@ class Wrapper { .getInstanceOrThrowError() .recipeInterfaceImpl.updateEmailOrPassword(Object.assign({ userContext: {} }, input)); } - static generatePasswordResetLink(userId, tenantId, userContext) { + static createResetPasswordLink(userId, tenantId, userContext) { return __awaiter(this, void 0, void 0, function* () { let token = yield exports.createResetPasswordToken(userId, tenantId, userContext); if (token.status === "UNKNOWN_USER_ID_ERROR") { @@ -123,9 +123,9 @@ class Wrapper { }; }); } - static sendPasswordResetEmail(userId, tenantId, userContext) { + static sendResetPasswordEmail(userId, tenantId, userContext) { return __awaiter(this, void 0, void 0, function* () { - let link = yield exports.generatePasswordResetLink(userId, tenantId, userContext); + let link = yield exports.createResetPasswordLink(userId, tenantId, userContext); if (link.status === "UNKNOWN_USER_ID_ERROR") { return link; } @@ -164,6 +164,6 @@ exports.getUserByEmail = Wrapper.getUserByEmail; exports.createResetPasswordToken = Wrapper.createResetPasswordToken; exports.resetPasswordUsingToken = Wrapper.resetPasswordUsingToken; exports.updateEmailOrPassword = Wrapper.updateEmailOrPassword; -exports.generatePasswordResetLink = Wrapper.generatePasswordResetLink; -exports.sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; +exports.createResetPasswordLink = Wrapper.createResetPasswordLink; +exports.sendResetPasswordEmail = Wrapper.sendResetPasswordEmail; exports.sendEmail = Wrapper.sendEmail; diff --git a/lib/build/recipe/thirdpartyemailpassword/index.d.ts b/lib/build/recipe/thirdpartyemailpassword/index.d.ts index c9735b39b..31b452ae9 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.d.ts +++ b/lib/build/recipe/thirdpartyemailpassword/index.d.ts @@ -106,7 +106,7 @@ export default class Wrapper { failureReason: string; } >; - static generatePasswordResetLink( + static createResetPasswordLink( userId: string, tenantId?: string, userContext?: any @@ -119,7 +119,7 @@ export default class Wrapper { status: "UNKNOWN_USER_ID_ERROR"; } >; - static sendPasswordResetEmail( + static sendResetPasswordEmail( userId: string, tenantId?: string, userContext?: any @@ -145,6 +145,6 @@ export declare let createResetPasswordToken: typeof Wrapper.createResetPasswordT export declare let resetPasswordUsingToken: typeof Wrapper.resetPasswordUsingToken; export declare let updateEmailOrPassword: typeof Wrapper.updateEmailOrPassword; export type { RecipeInterface, TypeProvider, User, APIInterface, EmailPasswordAPIOptions, ThirdPartyAPIOptions }; -export declare let generatePasswordResetLink: typeof Wrapper.generatePasswordResetLink; -export declare let sendPasswordResetEmail: typeof Wrapper.sendPasswordResetEmail; +export declare let createResetPasswordLink: typeof Wrapper.createResetPasswordLink; +export declare let sendResetPasswordEmail: typeof Wrapper.sendResetPasswordEmail; export declare let sendEmail: typeof Wrapper.sendEmail; diff --git a/lib/build/recipe/thirdpartyemailpassword/index.js b/lib/build/recipe/thirdpartyemailpassword/index.js index 221bc7969..c3eca86f7 100644 --- a/lib/build/recipe/thirdpartyemailpassword/index.js +++ b/lib/build/recipe/thirdpartyemailpassword/index.js @@ -50,7 +50,7 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.sendEmail = exports.sendPasswordResetEmail = exports.generatePasswordResetLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUsersByEmail = exports.getUserByThirdPartyInfo = exports.getUserById = exports.thirdPartyManuallyCreateOrUpdateUser = exports.thirdPartyGetProvider = exports.emailPasswordSignIn = exports.emailPasswordSignUp = exports.Error = exports.init = void 0; +exports.sendEmail = exports.sendResetPasswordEmail = exports.createResetPasswordLink = exports.updateEmailOrPassword = exports.resetPasswordUsingToken = exports.createResetPasswordToken = exports.getUsersByEmail = exports.getUserByThirdPartyInfo = exports.getUserById = exports.thirdPartyManuallyCreateOrUpdateUser = exports.thirdPartyGetProvider = exports.emailPasswordSignIn = exports.emailPasswordSignUp = exports.Error = exports.init = void 0; const recipe_1 = __importDefault(require("./recipe")); const error_1 = __importDefault(require("./error")); const constants_1 = require("../multitenancy/constants"); @@ -129,7 +129,7 @@ class Wrapper { .getInstanceOrThrowError() .recipeInterfaceImpl.updateEmailOrPassword(Object.assign({ userContext: {} }, input)); } - static generatePasswordResetLink(userId, tenantId, userContext) { + static createResetPasswordLink(userId, tenantId, userContext) { return __awaiter(this, void 0, void 0, function* () { let token = yield exports.createResetPasswordToken(userId, tenantId, userContext); if (token.status === "UNKNOWN_USER_ID_ERROR") { @@ -147,9 +147,9 @@ class Wrapper { }; }); } - static sendPasswordResetEmail(userId, tenantId, userContext) { + static sendResetPasswordEmail(userId, tenantId, userContext) { return __awaiter(this, void 0, void 0, function* () { - let link = yield exports.generatePasswordResetLink(userId, tenantId, userContext); + let link = yield exports.createResetPasswordLink(userId, tenantId, userContext); if (link.status === "UNKNOWN_USER_ID_ERROR") { return link; } @@ -190,6 +190,6 @@ exports.getUsersByEmail = Wrapper.getUsersByEmail; exports.createResetPasswordToken = Wrapper.createResetPasswordToken; exports.resetPasswordUsingToken = Wrapper.resetPasswordUsingToken; exports.updateEmailOrPassword = Wrapper.updateEmailOrPassword; -exports.generatePasswordResetLink = Wrapper.generatePasswordResetLink; -exports.sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; +exports.createResetPasswordLink = Wrapper.createResetPasswordLink; +exports.sendResetPasswordEmail = Wrapper.sendResetPasswordEmail; exports.sendEmail = Wrapper.sendEmail; diff --git a/lib/ts/recipe/emailpassword/index.ts b/lib/ts/recipe/emailpassword/index.ts index cf630907f..064cf7afb 100644 --- a/lib/ts/recipe/emailpassword/index.ts +++ b/lib/ts/recipe/emailpassword/index.ts @@ -87,7 +87,7 @@ export default class Wrapper { }); } - static async generatePasswordResetLink( + static async createResetPasswordLink( userId: string, tenantId?: string, userContext?: any @@ -109,12 +109,12 @@ export default class Wrapper { }; } - static async sendPasswordResetEmail( + static async sendResetPasswordEmail( userId: string, tenantId?: string, userContext?: any ): Promise<{ status: "OK" | "UNKNOWN_USER_ID_ERROR" }> { - let link = await generatePasswordResetLink(userId, tenantId, userContext); + let link = await createResetPasswordLink(userId, tenantId, userContext); if (link.status === "UNKNOWN_USER_ID_ERROR") { return link; } @@ -161,8 +161,8 @@ export let updateEmailOrPassword = Wrapper.updateEmailOrPassword; export type { RecipeInterface, User, APIOptions, APIInterface }; -export let generatePasswordResetLink = Wrapper.generatePasswordResetLink; +export let createResetPasswordLink = Wrapper.createResetPasswordLink; -export let sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; +export let sendResetPasswordEmail = Wrapper.sendResetPasswordEmail; export let sendEmail = Wrapper.sendEmail; diff --git a/lib/ts/recipe/thirdpartyemailpassword/index.ts b/lib/ts/recipe/thirdpartyemailpassword/index.ts index ed412362b..0e7b9552a 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/index.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/index.ts @@ -130,7 +130,7 @@ export default class Wrapper { }); } - static async generatePasswordResetLink( + static async createResetPasswordLink( userId: string, tenantId?: string, userContext?: any @@ -152,12 +152,12 @@ export default class Wrapper { }; } - static async sendPasswordResetEmail( + static async sendResetPasswordEmail( userId: string, tenantId?: string, userContext?: any ): Promise<{ status: "OK" | "UNKNOWN_USER_ID_ERROR" }> { - let link = await generatePasswordResetLink(userId, tenantId, userContext); + let link = await createResetPasswordLink(userId, tenantId, userContext); if (link.status === "UNKNOWN_USER_ID_ERROR") { return link; } @@ -209,8 +209,8 @@ export let updateEmailOrPassword = Wrapper.updateEmailOrPassword; export type { RecipeInterface, TypeProvider, User, APIInterface, EmailPasswordAPIOptions, ThirdPartyAPIOptions }; -export let generatePasswordResetLink = Wrapper.generatePasswordResetLink; +export let createResetPasswordLink = Wrapper.createResetPasswordLink; -export let sendPasswordResetEmail = Wrapper.sendPasswordResetEmail; +export let sendResetPasswordEmail = Wrapper.sendResetPasswordEmail; export let sendEmail = Wrapper.sendEmail; From 3f1e0ce9ab34fbbaea7ba346f4b4d84a6a37fbf9 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 6 Jul 2023 17:56:48 +0530 Subject: [PATCH 04/14] fix: tenantId in types --- lib/ts/recipe/emailpassword/types.ts | 7 +++--- lib/ts/recipe/emailverification/types.ts | 2 +- lib/ts/recipe/openid/types.ts | 1 + lib/ts/recipe/passwordless/types.ts | 24 +++++++++++-------- lib/ts/recipe/session/types.ts | 3 +++ lib/ts/recipe/thirdparty/types.ts | 3 ++- .../recipe/thirdpartyemailpassword/types.ts | 1 + lib/ts/recipe/thirdpartypasswordless/types.ts | 22 ++++++++++------- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index 04d26fa56..189dab2d1 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -42,7 +42,7 @@ export type TypeNormalisedInput = { export type TypeInputFormField = { id: string; - validate?: (value: any) => Promise; + validate?: (value: any, tenantId: string) => Promise; optional?: boolean; }; @@ -54,7 +54,7 @@ export type TypeInputSignUp = { export type NormalisedFormField = { id: string; - validate: (value: any) => Promise; + validate: (value: any, tenantId: string) => Promise; optional: boolean; }; @@ -70,7 +70,7 @@ export type TypeInputResetPasswordUsingTokenFeature = { /** * @deprecated Please use emailDelivery config instead */ - createAndSendCustomEmail?: (user: User, passwordResetURLWithToken: string, userContext: any) => Promise; + createAndSendCustomEmail?: (user: User, passwordResetURLWithToken: string, tenantId: string, userContext: any) => Promise; }; export type TypeNormalisedInputResetPasswordUsingTokenFeature = { @@ -146,6 +146,7 @@ export type RecipeInterface = { password?: string; userContext: any; applyPasswordPolicy?: boolean; + tenantId: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; diff --git a/lib/ts/recipe/emailverification/types.ts b/lib/ts/recipe/emailverification/types.ts index 33331bf31..d65368a7b 100644 --- a/lib/ts/recipe/emailverification/types.ts +++ b/lib/ts/recipe/emailverification/types.ts @@ -39,7 +39,7 @@ export type TypeInput = { /** * @deprecated Please use emailDelivery config instead */ - createAndSendCustomEmail?: (user: User, emailVerificationURLWithToken: string, userContext: any) => Promise; + createAndSendCustomEmail?: (user: User, emailVerificationURLWithToken: string, tenantId: string, userContext: any) => Promise; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/ts/recipe/openid/types.ts b/lib/ts/recipe/openid/types.ts index b3ade8a79..978b340f1 100644 --- a/lib/ts/recipe/openid/types.ts +++ b/lib/ts/recipe/openid/types.ts @@ -100,6 +100,7 @@ export type RecipeInterface = { payload?: any; validitySeconds?: number; useStaticSigningKey?: boolean; + tenantId: string; userContext: any; }): Promise< | { diff --git a/lib/ts/recipe/passwordless/types.ts b/lib/ts/recipe/passwordless/types.ts index 918f9a063..04c2037a0 100644 --- a/lib/ts/recipe/passwordless/types.ts +++ b/lib/ts/recipe/passwordless/types.ts @@ -41,7 +41,7 @@ export type User = { export type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -59,12 +59,13 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -82,12 +83,13 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -105,9 +107,10 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -125,6 +128,7 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } @@ -136,7 +140,7 @@ export type TypeInput = ( // Override this to override how user input codes are generated // By default (=undefined) it is done in the Core - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; override?: { functions?: ( @@ -150,24 +154,24 @@ export type TypeInput = ( export type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber: (phoneNumber: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL"; - validateEmailAddress: (email: string) => Promise | string | undefined; + validateEmailAddress: (email: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress: (email: string) => Promise | string | undefined; + validateEmailAddress: (email: string, tenantId: string) => Promise | string | undefined; - validatePhoneNumber: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber: (phoneNumber: string, tenantId: string) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; // Override this to override how user input codes are generated // By default (=undefined) it is done in the Core - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; getSmsDeliveryConfig: () => SmsDeliveryTypeInputWithService; getEmailDeliveryConfig: () => EmailDeliveryTypeInputWithService; diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index 4c00eeac5..c8435c40b 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -69,6 +69,7 @@ export type TypeInput = { getTokenTransferMethod?: (input: { req: BaseRequest; forCreateNewSession: boolean; + tenantId: string; userContext: any; }) => TokenTransferMethod | "any"; @@ -118,6 +119,7 @@ export type TypeNormalisedInput = { getTokenTransferMethod: (input: { req: BaseRequest; forCreateNewSession: boolean; + tenantId: string; userContext: any; }) => TokenTransferMethod | "any"; @@ -182,6 +184,7 @@ export interface VerifySessionOptions { overrideGlobalClaimValidators?: ( globalClaimValidators: SessionClaimValidator[], session: SessionContainerInterface, + tenantId: string, userContext: any ) => Promise | SessionClaimValidator[]; } diff --git a/lib/ts/recipe/thirdparty/types.ts b/lib/ts/recipe/thirdparty/types.ts index 4f4ac23f5..c8fd06400 100644 --- a/lib/ts/recipe/thirdparty/types.ts +++ b/lib/ts/recipe/thirdparty/types.ts @@ -64,10 +64,11 @@ type CommonProviderConfig = { validateIdTokenPayload?: (input: { idTokenPayload: { [key: string]: any }; clientConfig: ProviderConfigForClientType; + tenantId: string; userContext: any; }) => Promise; requireEmail?: boolean; - generateFakeEmail?: (input: { thirdPartyUserId: string; userContext: any }) => Promise; + generateFakeEmail?: (input: { thirdPartyUserId: string; tenantId: string; userContext: any }) => Promise; }; export type ProviderConfigForClientType = ProviderClientConfig & CommonProviderConfig; diff --git a/lib/ts/recipe/thirdpartyemailpassword/types.ts b/lib/ts/recipe/thirdpartyemailpassword/types.ts index c03c05861..4ca16bd48 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/types.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/types.ts @@ -129,6 +129,7 @@ export type RecipeInterface = { fromIdTokenPayload?: { [key: string]: any }; fromUserInfoAPI?: { [key: string]: any }; }; + tenantId: string; userContext: any; }): Promise<{ status: "OK"; diff --git a/lib/ts/recipe/thirdpartypasswordless/types.ts b/lib/ts/recipe/thirdpartypasswordless/types.ts index 2fba9b2a4..a0b3734ed 100644 --- a/lib/ts/recipe/thirdpartypasswordless/types.ts +++ b/lib/ts/recipe/thirdpartypasswordless/types.ts @@ -63,7 +63,7 @@ export type User = ( export type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -81,12 +81,13 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -104,12 +105,13 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -127,9 +129,10 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -147,6 +150,7 @@ export type TypeInput = ( // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } @@ -175,23 +179,23 @@ export type TypeInput = ( export type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; // Override this to override how user input codes are generated // By default (=undefined) it is done in the Core - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; providers: ProviderInput[]; getEmailDeliveryConfig: ( recipeImpl: RecipeInterface, From 5f077e913136d4a09be9c4f123fb71a910ec0c09 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Thu, 6 Jul 2023 18:00:26 +0530 Subject: [PATCH 05/14] fix: tenantId in types --- lib/ts/recipe/emailpassword/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index 189dab2d1..fe9f15172 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -146,7 +146,6 @@ export type RecipeInterface = { password?: string; userContext: any; applyPasswordPolicy?: boolean; - tenantId: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; From c95d8efc9f6796a01d6a07b00f4ac7f4e09aa8b9 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 7 Jul 2023 16:54:08 +0530 Subject: [PATCH 06/14] fix: impl --- .../api/userdetails/userPasswordPut.js | 4 +- .../dashboard/api/userdetails/userPut.d.ts | 2 +- .../dashboard/api/userdetails/userPut.js | 20 ++-- .../api/generatePasswordResetToken.js | 3 +- .../recipe/emailpassword/api/passwordReset.js | 3 +- lib/build/recipe/emailpassword/api/signin.js | 3 +- lib/build/recipe/emailpassword/api/signup.js | 3 +- lib/build/recipe/emailpassword/api/utils.d.ts | 3 +- lib/build/recipe/emailpassword/api/utils.js | 8 +- .../emailpassword/recipeImplementation.js | 7 +- lib/build/recipe/emailpassword/types.d.ts | 11 +- lib/build/recipe/emailpassword/utils.js | 7 +- lib/build/recipe/emailverification/types.d.ts | 4 - lib/build/recipe/emailverification/utils.js | 6 +- .../recipe/passwordless/api/createCode.js | 4 +- .../recipe/passwordless/api/implementation.js | 12 ++- .../services/backwardCompatibility/index.d.ts | 14 +-- .../services/backwardCompatibility/index.js | 11 +- lib/build/recipe/passwordless/recipe.js | 2 +- .../services/backwardCompatibility/index.d.ts | 14 +-- .../services/backwardCompatibility/index.js | 9 +- lib/build/recipe/passwordless/types.d.ts | 84 ++++----------- lib/build/recipe/passwordless/utils.js | 7 +- .../recipe/thirdparty/api/implementation.js | 1 + lib/build/recipe/thirdparty/types.d.ts | 2 +- .../recipe/thirdpartyemailpassword/recipe.js | 1 - .../recipe/thirdpartyemailpassword/types.d.ts | 4 +- .../recipe/thirdpartyemailpassword/utils.js | 9 +- .../services/backwardCompatibility/index.d.ts | 16 +-- .../services/backwardCompatibility/index.js | 9 +- .../services/backwardCompatibility/index.d.ts | 16 +-- .../services/backwardCompatibility/index.js | 9 +- .../recipe/thirdpartypasswordless/types.d.ts | 34 ++++-- .../recipe/thirdpartypasswordless/utils.js | 18 +--- .../api/userdetails/userPasswordPut.ts | 4 +- .../dashboard/api/userdetails/userPut.ts | 18 ++-- .../api/generatePasswordResetToken.ts | 3 +- .../recipe/emailpassword/api/passwordReset.ts | 3 +- lib/ts/recipe/emailpassword/api/signin.ts | 3 +- lib/ts/recipe/emailpassword/api/signup.ts | 3 +- lib/ts/recipe/emailpassword/api/utils.ts | 10 +- .../emailpassword/recipeImplementation.ts | 8 +- lib/ts/recipe/emailpassword/types.ts | 8 -- lib/ts/recipe/emailpassword/utils.ts | 7 +- lib/ts/recipe/emailverification/types.ts | 4 - lib/ts/recipe/emailverification/utils.ts | 6 +- lib/ts/recipe/openid/types.ts | 1 - lib/ts/recipe/passwordless/api/createCode.ts | 4 +- .../recipe/passwordless/api/implementation.ts | 12 ++- .../services/backwardCompatibility/index.ts | 29 ++--- lib/ts/recipe/passwordless/recipe.ts | 2 +- .../services/backwardCompatibility/index.ts | 27 ++--- lib/ts/recipe/passwordless/types.ts | 101 +++--------------- lib/ts/recipe/passwordless/utils.ts | 7 +- lib/ts/recipe/session/types.ts | 3 - .../recipe/thirdparty/api/implementation.ts | 1 + lib/ts/recipe/thirdparty/types.ts | 1 - .../recipe/thirdpartyemailpassword/recipe.ts | 1 - .../recipe/thirdpartyemailpassword/types.ts | 3 - .../recipe/thirdpartyemailpassword/utils.ts | 10 +- .../services/backwardCompatibility/index.ts | 25 +---- .../services/backwardCompatibility/index.ts | 25 +---- lib/ts/recipe/thirdpartypasswordless/types.ts | 20 +++- lib/ts/recipe/thirdpartypasswordless/utils.ts | 10 +- 64 files changed, 227 insertions(+), 492 deletions(-) diff --git a/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js b/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js index d4fed4a91..136b55cf1 100644 --- a/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js +++ b/lib/build/recipe/dashboard/api/userdetails/userPasswordPut.js @@ -79,7 +79,7 @@ const userPasswordPut = (_, tenantId, options, userContext) => let passwordFormFields = recipe_1.default .getInstanceOrThrowError() .config.signUpFeature.formFields.filter((field) => field.id === constants_1.FORM_FIELD_PASSWORD_ID); - let passwordValidationError = yield passwordFormFields[0].validate(newPassword); + let passwordValidationError = yield passwordFormFields[0].validate(newPassword, tenantId); if (passwordValidationError !== undefined) { return { status: "INVALID_PASSWORD_ERROR", @@ -111,7 +111,7 @@ const userPasswordPut = (_, tenantId, options, userContext) => let passwordFormFields = recipe_2.default .getInstanceOrThrowError() .config.signUpFeature.formFields.filter((field) => field.id === constants_1.FORM_FIELD_PASSWORD_ID); - let passwordValidationError = yield passwordFormFields[0].validate(newPassword); + let passwordValidationError = yield passwordFormFields[0].validate(newPassword, tenantId); if (passwordValidationError !== undefined) { return { status: "INVALID_PASSWORD_ERROR", diff --git a/lib/build/recipe/dashboard/api/userdetails/userPut.d.ts b/lib/build/recipe/dashboard/api/userdetails/userPut.d.ts index 08684b279..6bc884816 100644 --- a/lib/build/recipe/dashboard/api/userdetails/userPut.d.ts +++ b/lib/build/recipe/dashboard/api/userdetails/userPut.d.ts @@ -20,7 +20,7 @@ declare type Response = }; export declare const userPut: ( _: APIInterface, - ___: string, + tenantId: string, options: APIOptions, userContext: any ) => Promise; diff --git a/lib/build/recipe/dashboard/api/userdetails/userPut.js b/lib/build/recipe/dashboard/api/userdetails/userPut.js index cb628ea4d..af1a8aaae 100644 --- a/lib/build/recipe/dashboard/api/userdetails/userPut.js +++ b/lib/build/recipe/dashboard/api/userdetails/userPut.js @@ -51,13 +51,13 @@ const recipe_5 = __importDefault(require("../../../usermetadata/recipe")); const usermetadata_1 = __importDefault(require("../../../usermetadata")); const constants_1 = require("../../../emailpassword/constants"); const utils_2 = require("../../../passwordless/utils"); -const updateEmailForRecipeId = (recipeId, userId, email, userContext) => +const updateEmailForRecipeId = (recipeId, userId, email, tenantId, userContext) => __awaiter(void 0, void 0, void 0, function* () { if (recipeId === "emailpassword") { let emailFormFields = recipe_1.default .getInstanceOrThrowError() .config.signUpFeature.formFields.filter((field) => field.id === constants_1.FORM_FIELD_EMAIL_ID); - let validationError = yield emailFormFields[0].validate(email); + let validationError = yield emailFormFields[0].validate(email, tenantId); if (validationError !== undefined) { return { status: "INVALID_EMAIL_ERROR", @@ -82,7 +82,7 @@ const updateEmailForRecipeId = (recipeId, userId, email, userContext) => let emailFormFields = recipe_2.default .getInstanceOrThrowError() .config.signUpFeature.formFields.filter((field) => field.id === constants_1.FORM_FIELD_EMAIL_ID); - let validationError = yield emailFormFields[0].validate(email); + let validationError = yield emailFormFields[0].validate(email, tenantId); if (validationError !== undefined) { return { status: "INVALID_EMAIL_ERROR", @@ -117,7 +117,7 @@ const updateEmailForRecipeId = (recipeId, userId, email, userContext) => validationError = validationResult; } } else { - const validationResult = yield passwordlessConfig.validateEmailAddress(email); + const validationResult = yield passwordlessConfig.validateEmailAddress(email, tenantId); if (validationResult !== undefined) { isValidEmail = false; validationError = validationResult; @@ -157,7 +157,7 @@ const updateEmailForRecipeId = (recipeId, userId, email, userContext) => validationError = validationResult; } } else { - const validationResult = yield passwordlessConfig.validateEmailAddress(email); + const validationResult = yield passwordlessConfig.validateEmailAddress(email, tenantId); if (validationResult !== undefined) { isValidEmail = false; validationError = validationResult; @@ -191,7 +191,7 @@ const updateEmailForRecipeId = (recipeId, userId, email, userContext) => */ throw new Error("Should never come here"); }); -const updatePhoneForRecipeId = (recipeId, userId, phone, userContext) => +const updatePhoneForRecipeId = (recipeId, userId, phone, tenantId, userContext) => __awaiter(void 0, void 0, void 0, function* () { if (recipeId === "passwordless") { let isValidPhone = true; @@ -204,7 +204,7 @@ const updatePhoneForRecipeId = (recipeId, userId, phone, userContext) => validationError = validationResult; } } else { - const validationResult = yield passwordlessConfig.validatePhoneNumber(phone); + const validationResult = yield passwordlessConfig.validatePhoneNumber(phone, tenantId); if (validationResult !== undefined) { isValidPhone = false; validationError = validationResult; @@ -244,7 +244,7 @@ const updatePhoneForRecipeId = (recipeId, userId, phone, userContext) => validationError = validationResult; } } else { - const validationResult = yield passwordlessConfig.validatePhoneNumber(phone); + const validationResult = yield passwordlessConfig.validatePhoneNumber(phone, tenantId); if (validationResult !== undefined) { isValidPhone = false; validationError = validationResult; @@ -278,7 +278,7 @@ const updatePhoneForRecipeId = (recipeId, userId, phone, userContext) => */ throw new Error("Should never come here"); }); -const userPut = (_, ___, options, userContext) => +const userPut = (_, tenantId, options, userContext) => __awaiter(void 0, void 0, void 0, function* () { const requestBody = yield options.req.getJSONBody(); const userId = requestBody.userId; @@ -357,6 +357,7 @@ const userPut = (_, ___, options, userContext) => userResponse.recipe, userId, email.trim(), + tenantId, userContext ); if (emailUpdateResponse.status !== "OK") { @@ -368,6 +369,7 @@ const userPut = (_, ___, options, userContext) => userResponse.recipe, userId, phone.trim(), + tenantId, userContext ); if (phoneUpdateResponse.status !== "OK") { diff --git a/lib/build/recipe/emailpassword/api/generatePasswordResetToken.js b/lib/build/recipe/emailpassword/api/generatePasswordResetToken.js index bd2cbb149..90c591fa1 100644 --- a/lib/build/recipe/emailpassword/api/generatePasswordResetToken.js +++ b/lib/build/recipe/emailpassword/api/generatePasswordResetToken.js @@ -56,7 +56,8 @@ function generatePasswordResetToken(apiImplementation, tenantId, options, userCo // step 1 let formFields = yield utils_2.validateFormFieldsOrThrowError( options.config.resetPasswordUsingTokenFeature.formFieldsForGenerateTokenForm, - (yield options.req.getJSONBody()).formFields + (yield options.req.getJSONBody()).formFields, + tenantId ); let result = yield apiImplementation.generatePasswordResetTokenPOST({ formFields, diff --git a/lib/build/recipe/emailpassword/api/passwordReset.js b/lib/build/recipe/emailpassword/api/passwordReset.js index 2170f7f03..9fc50b87b 100644 --- a/lib/build/recipe/emailpassword/api/passwordReset.js +++ b/lib/build/recipe/emailpassword/api/passwordReset.js @@ -62,7 +62,8 @@ function passwordReset(apiImplementation, tenantId, options, userContext) { // step 1 let formFields = yield utils_2.validateFormFieldsOrThrowError( options.config.resetPasswordUsingTokenFeature.formFieldsForPasswordResetForm, - (yield options.req.getJSONBody()).formFields + (yield options.req.getJSONBody()).formFields, + tenantId ); let token = (yield options.req.getJSONBody()).token; if (token === undefined) { diff --git a/lib/build/recipe/emailpassword/api/signin.js b/lib/build/recipe/emailpassword/api/signin.js index dd25133eb..0351b9064 100644 --- a/lib/build/recipe/emailpassword/api/signin.js +++ b/lib/build/recipe/emailpassword/api/signin.js @@ -56,7 +56,8 @@ function signInAPI(apiImplementation, tenantId, options, userContext) { // step 1 let formFields = yield utils_2.validateFormFieldsOrThrowError( options.config.signInFeature.formFields, - (yield options.req.getJSONBody()).formFields + (yield options.req.getJSONBody()).formFields, + tenantId ); let result = yield apiImplementation.signInPOST({ formFields, diff --git a/lib/build/recipe/emailpassword/api/signup.js b/lib/build/recipe/emailpassword/api/signup.js index b70407e07..fa66ca4c9 100644 --- a/lib/build/recipe/emailpassword/api/signup.js +++ b/lib/build/recipe/emailpassword/api/signup.js @@ -62,7 +62,8 @@ function signUpAPI(apiImplementation, tenantId, options, userContext) { // step 1 let formFields = yield utils_2.validateFormFieldsOrThrowError( options.config.signUpFeature.formFields, - (yield options.req.getJSONBody()).formFields + (yield options.req.getJSONBody()).formFields, + tenantId ); let result = yield apiImplementation.signUpPOST({ formFields, diff --git a/lib/build/recipe/emailpassword/api/utils.d.ts b/lib/build/recipe/emailpassword/api/utils.d.ts index 5579f71cc..998bf0c28 100644 --- a/lib/build/recipe/emailpassword/api/utils.d.ts +++ b/lib/build/recipe/emailpassword/api/utils.d.ts @@ -2,7 +2,8 @@ import { NormalisedFormField } from "../types"; export declare function validateFormFieldsOrThrowError( configFormFields: NormalisedFormField[], - formFieldsRaw: any + formFieldsRaw: any, + tenantId: string ): Promise< { id: string; diff --git a/lib/build/recipe/emailpassword/api/utils.js b/lib/build/recipe/emailpassword/api/utils.js index bbf03c787..e8e5a8417 100644 --- a/lib/build/recipe/emailpassword/api/utils.js +++ b/lib/build/recipe/emailpassword/api/utils.js @@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateFormFieldsOrThrowError = void 0; const error_1 = __importDefault(require("../error")); const constants_1 = require("../constants"); -function validateFormFieldsOrThrowError(configFormFields, formFieldsRaw) { +function validateFormFieldsOrThrowError(configFormFields, formFieldsRaw, tenantId) { return __awaiter(this, void 0, void 0, function* () { // first we check syntax ---------------------------- if (formFieldsRaw === undefined) { @@ -67,7 +67,7 @@ function validateFormFieldsOrThrowError(configFormFields, formFieldsRaw) { return field; }); // then run validators through them----------------------- - yield validateFormOrThrowError(formFields, configFormFields); + yield validateFormOrThrowError(formFields, configFormFields, tenantId); return formFields; }); } @@ -80,7 +80,7 @@ function newBadRequestError(message) { } // We check that the number of fields in input and config form field is the same. // We check that each item in the config form field is also present in the input form field -function validateFormOrThrowError(inputs, configFormFields) { +function validateFormOrThrowError(inputs, configFormFields, tenantId) { return __awaiter(this, void 0, void 0, function* () { let validationErrors = []; if (configFormFields.length !== inputs.length) { @@ -99,7 +99,7 @@ function validateFormOrThrowError(inputs, configFormFields) { }); } else { // Otherwise, use validate function. - const error = yield field.validate(input.value); + const error = yield field.validate(input.value, tenantId); // If error, add it. if (error !== undefined) { validationErrors.push({ diff --git a/lib/build/recipe/emailpassword/recipeImplementation.js b/lib/build/recipe/emailpassword/recipeImplementation.js index a4170a97f..70a277b2b 100644 --- a/lib/build/recipe/emailpassword/recipeImplementation.js +++ b/lib/build/recipe/emailpassword/recipeImplementation.js @@ -159,7 +159,12 @@ function getRecipeInterface(querier, getEmailPasswordConfig) { const passwordField = formFields.filter( (el) => el.id === constants_1.FORM_FIELD_PASSWORD_ID )[0]; - const error = yield passwordField.validate(input.password); + const error = yield passwordField.validate( + input.password, + input.tenantIdForPasswordPolicy === undefined + ? constants_2.DEFAULT_TENANT_ID + : input.tenantIdForPasswordPolicy + ); if (error !== undefined) { return { status: "PASSWORD_POLICY_VIOLATED_ERROR", diff --git a/lib/build/recipe/emailpassword/types.d.ts b/lib/build/recipe/emailpassword/types.d.ts index ab3674b65..8ec43989d 100644 --- a/lib/build/recipe/emailpassword/types.d.ts +++ b/lib/build/recipe/emailpassword/types.d.ts @@ -26,7 +26,7 @@ export declare type TypeNormalisedInput = { }; export declare type TypeInputFormField = { id: string; - validate?: (value: any) => Promise; + validate?: (value: any, tenantId: string) => Promise; optional?: boolean; }; export declare type TypeFormField = { @@ -38,7 +38,7 @@ export declare type TypeInputSignUp = { }; export declare type NormalisedFormField = { id: string; - validate: (value: any) => Promise; + validate: (value: any, tenantId: string) => Promise; optional: boolean; }; export declare type TypeNormalisedInputSignUp = { @@ -47,12 +47,6 @@ export declare type TypeNormalisedInputSignUp = { export declare type TypeNormalisedInputSignIn = { formFields: NormalisedFormField[]; }; -export declare type TypeInputResetPasswordUsingTokenFeature = { - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: (user: User, passwordResetURLWithToken: string, userContext: any) => Promise; -}; export declare type TypeNormalisedInputResetPasswordUsingTokenFeature = { formFieldsForGenerateTokenForm: NormalisedFormField[]; formFieldsForPasswordResetForm: NormalisedFormField[]; @@ -66,7 +60,6 @@ export declare type User = { export declare type TypeInput = { signUpFeature?: TypeInputSignUp; emailDelivery?: EmailDeliveryTypeInput; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/build/recipe/emailpassword/utils.js b/lib/build/recipe/emailpassword/utils.js index 064ecd8ea..86e2daa88 100644 --- a/lib/build/recipe/emailpassword/utils.js +++ b/lib/build/recipe/emailpassword/utils.js @@ -82,12 +82,7 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { * createAndSendCustomEmail implementation which calls our supertokens API */ if (emailService === undefined) { - emailService = new backwardCompatibility_1.default( - recipeImpl, - appInfo, - isInServerlessEnv, - config === null || config === void 0 ? void 0 : config.resetPasswordUsingTokenFeature - ); + emailService = new backwardCompatibility_1.default(recipeImpl, appInfo, isInServerlessEnv); } return Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.emailDelivery), { /** diff --git a/lib/build/recipe/emailverification/types.d.ts b/lib/build/recipe/emailverification/types.d.ts index 42733fe7c..0a72560af 100644 --- a/lib/build/recipe/emailverification/types.d.ts +++ b/lib/build/recipe/emailverification/types.d.ts @@ -23,10 +23,6 @@ export declare type TypeInput = { status: "EMAIL_DOES_NOT_EXIST_ERROR" | "UNKNOWN_USER_ID_ERROR"; } >; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: (user: User, emailVerificationURLWithToken: string, userContext: any) => Promise; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/build/recipe/emailverification/utils.js b/lib/build/recipe/emailverification/utils.js index 39cbd35eb..370465974 100644 --- a/lib/build/recipe/emailverification/utils.js +++ b/lib/build/recipe/emailverification/utils.js @@ -40,11 +40,7 @@ function validateAndNormaliseUserInput(_, appInfo, config) { * createAndSendCustomEmail implementation which calls our supertokens API */ if (emailService === undefined) { - emailService = new backwardCompatibility_1.default( - appInfo, - isInServerlessEnv, - config.createAndSendCustomEmail - ); + emailService = new backwardCompatibility_1.default(appInfo, isInServerlessEnv); } return Object.assign(Object.assign({}, config.emailDelivery), { /** diff --git a/lib/build/recipe/passwordless/api/createCode.js b/lib/build/recipe/passwordless/api/createCode.js index 17dd34bf3..587bb43fe 100644 --- a/lib/build/recipe/passwordless/api/createCode.js +++ b/lib/build/recipe/passwordless/api/createCode.js @@ -85,7 +85,7 @@ function createCode(apiImplementation, tenantId, options, userContext) { (options.config.contactMethod === "EMAIL" || options.config.contactMethod === "EMAIL_OR_PHONE") ) { email = email.trim(); - const validateError = yield options.config.validateEmailAddress(email); + const validateError = yield options.config.validateEmailAddress(email, tenantId); if (validateError !== undefined) { utils_1.send200Response(options.res, { status: "GENERAL_ERROR", @@ -98,7 +98,7 @@ function createCode(apiImplementation, tenantId, options, userContext) { phoneNumber !== undefined && (options.config.contactMethod === "PHONE" || options.config.contactMethod === "EMAIL_OR_PHONE") ) { - const validateError = yield options.config.validatePhoneNumber(phoneNumber); + const validateError = yield options.config.validatePhoneNumber(phoneNumber, tenantId); if (validateError !== undefined) { utils_1.send200Response(options.res, { status: "GENERAL_ERROR", diff --git a/lib/build/recipe/passwordless/api/implementation.js b/lib/build/recipe/passwordless/api/implementation.js index 42652a59f..c555e612d 100644 --- a/lib/build/recipe/passwordless/api/implementation.js +++ b/lib/build/recipe/passwordless/api/implementation.js @@ -110,7 +110,10 @@ function getAPIImplementation() { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : yield input.options.config.getCustomUserInputCode(input.userContext), + : yield input.options.config.getCustomUserInputCode( + input.tenantId, + input.userContext + ), tenantId: input.tenantId, } : { @@ -119,7 +122,10 @@ function getAPIImplementation() { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : yield input.options.config.getCustomUserInputCode(input.userContext), + : yield input.options.config.getCustomUserInputCode( + input.tenantId, + input.userContext + ), tenantId: input.tenantId, } ); @@ -238,7 +244,7 @@ function getAPIImplementation() { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : yield input.options.config.getCustomUserInputCode(input.userContext), + : yield input.options.config.getCustomUserInputCode(input.tenantId, input.userContext), tenantId: input.tenantId, }); if (response.status === "USER_INPUT_CODE_ALREADY_USED_ERROR") { diff --git a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts index 2f0015dda..f88a3bbe6 100644 --- a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts @@ -5,19 +5,7 @@ import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements EmailDeliveryInterface { private createAndSendCustomEmail; - constructor( - appInfo: NormalisedAppinfo, - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise - ); + constructor(appInfo: NormalisedAppinfo); sendEmail: ( input: TypePasswordlessEmailDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js index 241629b1a..ca42ebd69 100644 --- a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js @@ -38,8 +38,9 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const logger_1 = require("../../../../../logger"); +const constants_1 = require("../../../../multitenancy/constants"); function defaultCreateAndSendCustomEmail(appInfo) { - return (input, _) => + return (input, _, __) => __awaiter(this, void 0, void 0, function* () { if (process.env.TEST_MODE === "testing") { return; @@ -101,7 +102,7 @@ function defaultCreateAndSendCustomEmail(appInfo) { }); } class BackwardCompatibilityService { - constructor(appInfo, createAndSendCustomEmail) { + constructor(appInfo) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { yield this.createAndSendCustomEmail( @@ -112,13 +113,11 @@ class BackwardCompatibilityService { preAuthSessionId: input.preAuthSessionId, codeLifetime: input.codeLifetime, }, + input.tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : input.tenantId, input.userContext ); }); - this.createAndSendCustomEmail = - createAndSendCustomEmail === undefined - ? defaultCreateAndSendCustomEmail(appInfo) - : createAndSendCustomEmail; + this.createAndSendCustomEmail = defaultCreateAndSendCustomEmail(appInfo); } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/passwordless/recipe.js b/lib/build/recipe/passwordless/recipe.js index 24813943b..fff815b69 100644 --- a/lib/build/recipe/passwordless/recipe.js +++ b/lib/build/recipe/passwordless/recipe.js @@ -146,7 +146,7 @@ class Recipe extends recipeModule_1.default { __awaiter(this, void 0, void 0, function* () { let userInputCode = this.config.getCustomUserInputCode !== undefined - ? yield this.config.getCustomUserInputCode(input.userContext) + ? yield this.config.getCustomUserInputCode(input.tenantId, input.userContext) : undefined; const codeInfo = yield this.recipeInterfaceImpl.createCode( "email" in input diff --git a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts index d1477c878..cd1b66f81 100644 --- a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts @@ -4,19 +4,7 @@ import { SmsDeliveryInterface } from "../../../../../ingredients/smsdelivery/typ import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements SmsDeliveryInterface { private createAndSendCustomSms; - constructor( - appInfo: NormalisedAppinfo, - createAndSendCustomSms?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise - ); + constructor(appInfo: NormalisedAppinfo); sendSms: ( input: TypePasswordlessSmsDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js index 887b67227..267628062 100644 --- a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js @@ -40,8 +40,9 @@ const axios_1 = __importDefault(require("axios")); const supertokens_1 = require("../../../../../ingredients/smsdelivery/services/supertokens"); const supertokens_2 = __importDefault(require("../../../../../supertokens")); const logger_1 = require("../../../../../logger"); +const constants_1 = require("../../../../multitenancy/constants"); function defaultCreateAndSendCustomSms(_) { - return (input, _) => + return (input, _, __) => __awaiter(this, void 0, void 0, function* () { let supertokens = supertokens_2.default.getInstanceOrThrowError(); let appName = supertokens.appInfo.appName; @@ -127,7 +128,7 @@ function defaultCreateAndSendCustomSms(_) { }); } class BackwardCompatibilityService { - constructor(appInfo, createAndSendCustomSms) { + constructor(appInfo) { this.sendSms = (input) => __awaiter(this, void 0, void 0, function* () { yield this.createAndSendCustomSms( @@ -138,11 +139,11 @@ class BackwardCompatibilityService { preAuthSessionId: input.preAuthSessionId, codeLifetime: input.codeLifetime, }, + input.tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : input.tenantId, input.userContext ); }); - this.createAndSendCustomSms = - createAndSendCustomSms === undefined ? defaultCreateAndSendCustomSms(appInfo) : createAndSendCustomSms; + this.createAndSendCustomSms = defaultCreateAndSendCustomSms(appInfo); } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/passwordless/types.d.ts b/lib/build/recipe/passwordless/types.d.ts index a126017f2..5e0940de8 100644 --- a/lib/build/recipe/passwordless/types.d.ts +++ b/lib/build/recipe/passwordless/types.d.ts @@ -23,74 +23,28 @@ export declare type User = { export declare type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; emailDelivery?: EmailDeliveryTypeInput; smsDelivery?: SmsDeliveryTypeInput; - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; override?: { functions?: ( originalImplementation: RecipeInterface, @@ -102,20 +56,26 @@ export declare type TypeInput = ( export declare type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; - validateEmailAddress: (email: string) => Promise | string | undefined; + validateEmailAddress: (email: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress: (email: string) => Promise | string | undefined; - validatePhoneNumber: (phoneNumber: string) => Promise | string | undefined; + validateEmailAddress: (email: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; getSmsDeliveryConfig: () => SmsDeliveryTypeInputWithService; getEmailDeliveryConfig: () => EmailDeliveryTypeInputWithService; override: { diff --git a/lib/build/recipe/passwordless/utils.js b/lib/build/recipe/passwordless/utils.js index 2bbe5e2e2..5fe99b3fc 100644 --- a/lib/build/recipe/passwordless/utils.js +++ b/lib/build/recipe/passwordless/utils.js @@ -44,7 +44,6 @@ function validateAndNormaliseUserInput(_, appInfo, config) { function getEmailDeliveryConfig() { var _a; let emailService = (_a = config.emailDelivery) === null || _a === void 0 ? void 0 : _a.service; - let createAndSendCustomEmail = config.contactMethod === "PHONE" ? undefined : config.createAndSendCustomEmail; /** * following code is for backward compatibility. * if user has not passed emailDelivery config, we @@ -53,7 +52,7 @@ function validateAndNormaliseUserInput(_, appInfo, config) { * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new backwardCompatibility_1.default(appInfo, createAndSendCustomEmail); + emailService = new backwardCompatibility_1.default(appInfo); } let emailDelivery = Object.assign(Object.assign({}, config.emailDelivery), { /** @@ -74,8 +73,6 @@ function validateAndNormaliseUserInput(_, appInfo, config) { function getSmsDeliveryConfig() { var _a; let smsService = (_a = config.smsDelivery) === null || _a === void 0 ? void 0 : _a.service; - let createAndSendCustomTextMessage = - config.contactMethod === "EMAIL" ? undefined : config.createAndSendCustomTextMessage; /** * following code is for backward compatibility. * if user has not passed emailDelivery config, we @@ -84,7 +81,7 @@ function validateAndNormaliseUserInput(_, appInfo, config) { * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new backwardCompatibility_2.default(appInfo, createAndSendCustomTextMessage); + smsService = new backwardCompatibility_2.default(appInfo); } let smsDelivery = Object.assign(Object.assign({}, config.smsDelivery), { /** diff --git a/lib/build/recipe/thirdparty/api/implementation.js b/lib/build/recipe/thirdparty/api/implementation.js index a53e18e75..6548e6d2c 100644 --- a/lib/build/recipe/thirdparty/api/implementation.js +++ b/lib/build/recipe/thirdparty/api/implementation.js @@ -68,6 +68,7 @@ function getAPIInterface() { userInfo.email = { id: yield provider.config.generateFakeEmail({ thirdPartyUserId: userInfo.thirdPartyUserId, + tenantId, userContext, }), isVerified: true, diff --git a/lib/build/recipe/thirdparty/types.d.ts b/lib/build/recipe/thirdparty/types.d.ts index 7913aa7cd..cbda028bc 100644 --- a/lib/build/recipe/thirdparty/types.d.ts +++ b/lib/build/recipe/thirdparty/types.d.ts @@ -70,7 +70,7 @@ declare type CommonProviderConfig = { userContext: any; }) => Promise; requireEmail?: boolean; - generateFakeEmail?: (input: { thirdPartyUserId: string; userContext: any }) => Promise; + generateFakeEmail?: (input: { thirdPartyUserId: string; tenantId: string; userContext: any }) => Promise; }; export declare type ProviderConfigForClientType = ProviderClientConfig & CommonProviderConfig; export declare type TypeProvider = { diff --git a/lib/build/recipe/thirdpartyemailpassword/recipe.js b/lib/build/recipe/thirdpartyemailpassword/recipe.js index 9c7d03111..5cd5ea2ef 100644 --- a/lib/build/recipe/thirdpartyemailpassword/recipe.js +++ b/lib/build/recipe/thirdpartyemailpassword/recipe.js @@ -189,7 +189,6 @@ class Recipe extends recipeModule_1.default { signUpFeature: { formFields: this.config.signUpFeature.formFields, }, - resetPasswordUsingTokenFeature: this.config.resetPasswordUsingTokenFeature, }, { emailDelivery: this.emailDelivery, diff --git a/lib/build/recipe/thirdpartyemailpassword/types.d.ts b/lib/build/recipe/thirdpartyemailpassword/types.d.ts index a86e73a63..48df0bb9b 100644 --- a/lib/build/recipe/thirdpartyemailpassword/types.d.ts +++ b/lib/build/recipe/thirdpartyemailpassword/types.d.ts @@ -11,7 +11,6 @@ import { NormalisedFormField, TypeFormField, TypeInputFormField, - TypeInputResetPasswordUsingTokenFeature, APIOptions as EmailPasswordAPIOptionsOriginal, TypeEmailPasswordEmailDeliveryInput, RecipeInterface as EPRecipeInterface, @@ -54,7 +53,6 @@ export declare type TypeInput = { signUpFeature?: TypeInputSignUp; providers?: ProviderInput[]; emailDelivery?: EmailDeliveryTypeInput; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override?: { functions?: ( originalImplementation: RecipeInterface, @@ -70,7 +68,6 @@ export declare type TypeNormalisedInput = { emailPasswordRecipeImpl: EPRecipeInterface, isInServerlessEnv: boolean ) => EmailDeliveryTypeInputWithService; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override: { functions: ( originalImplementation: RecipeInterface, @@ -113,6 +110,7 @@ export declare type RecipeInterface = { [key: string]: any; }; }; + tenantId: string; userContext: any; }): Promise<{ status: "OK"; diff --git a/lib/build/recipe/thirdpartyemailpassword/utils.js b/lib/build/recipe/thirdpartyemailpassword/utils.js index daa8a505c..9b36d7936 100644 --- a/lib/build/recipe/thirdpartyemailpassword/utils.js +++ b/lib/build/recipe/thirdpartyemailpassword/utils.js @@ -28,7 +28,6 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { appInfo, config === undefined ? undefined : config.signUpFeature ); - let resetPasswordUsingTokenFeature = config === undefined ? undefined : config.resetPasswordUsingTokenFeature; let providers = config === undefined || config.providers === undefined ? [] : config.providers; let override = Object.assign( { @@ -51,12 +50,7 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new backwardCompatibility_1.default( - emailPasswordRecipeImpl, - appInfo, - isInServerlessEnv, - config === null || config === void 0 ? void 0 : config.resetPasswordUsingTokenFeature - ); + emailService = new backwardCompatibility_1.default(emailPasswordRecipeImpl, appInfo, isInServerlessEnv); } return Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.emailDelivery), { /** @@ -78,7 +72,6 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { getEmailDeliveryConfig, signUpFeature, providers, - resetPasswordUsingTokenFeature, }; } exports.validateAndNormaliseUserInput = validateAndNormaliseUserInput; diff --git a/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.d.ts index 3e90372c3..29bbefd07 100644 --- a/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.d.ts @@ -5,21 +5,7 @@ import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery export default class BackwardCompatibilityService implements EmailDeliveryInterface { private passwordlessBackwardCompatibilityService; - constructor( - appInfo: NormalisedAppinfo, - passwordlessFeature?: { - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; - } - ); + constructor(appInfo: NormalisedAppinfo); sendEmail: ( input: TypeThirdPartyPasswordlessEmailDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.js index d61010ab5..8bf949cdb 100644 --- a/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.js @@ -40,18 +40,13 @@ const backwardCompatibility_1 = __importDefault( require("../../../../passwordless/emaildelivery/services/backwardCompatibility") ); class BackwardCompatibilityService { - constructor(appInfo, passwordlessFeature) { + constructor(appInfo) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { yield this.passwordlessBackwardCompatibilityService.sendEmail(input); }); { - this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default( - appInfo, - passwordlessFeature === null || passwordlessFeature === void 0 - ? void 0 - : passwordlessFeature.createAndSendCustomEmail - ); + this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default(appInfo); } } } diff --git a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts index 9e1f9745a..933ac145f 100644 --- a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts @@ -5,21 +5,7 @@ import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements SmsDeliveryInterface { private passwordlessBackwardCompatibilityService; - constructor( - appInfo: NormalisedAppinfo, - passwordlessFeature?: { - createAndSendCustomTextMessage?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - userContext: any - ) => Promise; - } - ); + constructor(appInfo: NormalisedAppinfo); sendSms: ( input: TypeThirdPartyPasswordlessSmsDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js index 6fb2a2e25..fe145fa16 100644 --- a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js @@ -40,17 +40,12 @@ const backwardCompatibility_1 = __importDefault( require("../../../../passwordless/smsdelivery/services/backwardCompatibility") ); class BackwardCompatibilityService { - constructor(appInfo, passwordlessFeature) { + constructor(appInfo) { this.sendSms = (input) => __awaiter(this, void 0, void 0, function* () { yield this.passwordlessBackwardCompatibilityService.sendSms(input); }); - this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default( - appInfo, - passwordlessFeature === null || passwordlessFeature === void 0 - ? void 0 - : passwordlessFeature.createAndSendCustomTextMessage - ); + this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default(appInfo); } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/thirdpartypasswordless/types.d.ts b/lib/build/recipe/thirdpartypasswordless/types.d.ts index 177e05efd..24f1790f1 100644 --- a/lib/build/recipe/thirdpartypasswordless/types.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/types.d.ts @@ -45,7 +45,10 @@ export declare type User = ( export declare type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; /** * @deprecated Please use smsDelivery config instead */ @@ -57,12 +60,13 @@ export declare type TypeInput = ( codeLifetime: number; preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; /** * @deprecated Please use emailDelivery config instead */ @@ -74,12 +78,13 @@ export declare type TypeInput = ( codeLifetime: number; preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; /** * @deprecated Please use emailDelivery config instead */ @@ -91,9 +96,13 @@ export declare type TypeInput = ( codeLifetime: number; preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; /** * @deprecated Please use smsDelivery config instead */ @@ -105,6 +114,7 @@ export declare type TypeInput = ( codeLifetime: number; preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; } @@ -129,20 +139,26 @@ export declare type TypeInput = ( export declare type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; - validateEmailAddress?: (email: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; } | { contactMethod: "EMAIL_OR_PHONE"; - validateEmailAddress?: (email: string) => Promise | string | undefined; - validatePhoneNumber?: (phoneNumber: string) => Promise | string | undefined; + validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; - getCustomUserInputCode?: (userContext: any) => Promise | string; + getCustomUserInputCode?: (tenantId: string, userContext: any) => Promise | string; providers: ProviderInput[]; getEmailDeliveryConfig: ( recipeImpl: RecipeInterface, diff --git a/lib/build/recipe/thirdpartypasswordless/utils.js b/lib/build/recipe/thirdpartypasswordless/utils.js index ffdfd159c..62bb457ac 100644 --- a/lib/build/recipe/thirdpartypasswordless/utils.js +++ b/lib/build/recipe/thirdpartypasswordless/utils.js @@ -45,14 +45,7 @@ function validateAndNormaliseUserInput(appInfo, config) { * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new backwardCompatibility_1.default(appInfo, { - createAndSendCustomEmail: - (config === null || config === void 0 ? void 0 : config.contactMethod) !== "PHONE" - ? config === null || config === void 0 - ? void 0 - : config.createAndSendCustomEmail - : undefined, - }); + emailService = new backwardCompatibility_1.default(appInfo); } return Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.emailDelivery), { /** @@ -83,14 +76,7 @@ function validateAndNormaliseUserInput(appInfo, config) { * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new backwardCompatibility_2.default(appInfo, { - createAndSendCustomTextMessage: - (config === null || config === void 0 ? void 0 : config.contactMethod) !== "EMAIL" - ? config === null || config === void 0 - ? void 0 - : config.createAndSendCustomTextMessage - : undefined, - }); + smsService = new backwardCompatibility_2.default(appInfo); } return Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.smsDelivery), { /** diff --git a/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts b/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts index f4023aef5..dc37669ba 100644 --- a/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts +++ b/lib/ts/recipe/dashboard/api/userdetails/userPasswordPut.ts @@ -63,7 +63,7 @@ export const userPasswordPut = async ( (field) => field.id === FORM_FIELD_PASSWORD_ID ); - let passwordValidationError = await passwordFormFields[0].validate(newPassword); + let passwordValidationError = await passwordFormFields[0].validate(newPassword, tenantId); if (passwordValidationError !== undefined) { return { @@ -99,7 +99,7 @@ export const userPasswordPut = async ( (field) => field.id === FORM_FIELD_PASSWORD_ID ); - let passwordValidationError = await passwordFormFields[0].validate(newPassword); + let passwordValidationError = await passwordFormFields[0].validate(newPassword, tenantId); if (passwordValidationError !== undefined) { return { diff --git a/lib/ts/recipe/dashboard/api/userdetails/userPut.ts b/lib/ts/recipe/dashboard/api/userdetails/userPut.ts index aa16f4980..a67f97322 100644 --- a/lib/ts/recipe/dashboard/api/userdetails/userPut.ts +++ b/lib/ts/recipe/dashboard/api/userdetails/userPut.ts @@ -37,6 +37,7 @@ const updateEmailForRecipeId = async ( recipeId: "emailpassword" | "thirdparty" | "passwordless" | "thirdpartyemailpassword" | "thirdpartypasswordless", userId: string, email: string, + tenantId: string, userContext: any ): Promise< | { @@ -55,7 +56,7 @@ const updateEmailForRecipeId = async ( (field) => field.id === FORM_FIELD_EMAIL_ID ); - let validationError = await emailFormFields[0].validate(email); + let validationError = await emailFormFields[0].validate(email, tenantId); if (validationError !== undefined) { return { @@ -86,7 +87,7 @@ const updateEmailForRecipeId = async ( (field) => field.id === FORM_FIELD_EMAIL_ID ); - let validationError = await emailFormFields[0].validate(email); + let validationError = await emailFormFields[0].validate(email, tenantId); if (validationError !== undefined) { return { @@ -130,7 +131,7 @@ const updateEmailForRecipeId = async ( validationError = validationResult; } } else { - const validationResult = await passwordlessConfig.validateEmailAddress(email); + const validationResult = await passwordlessConfig.validateEmailAddress(email, tenantId); if (validationResult !== undefined) { isValidEmail = false; @@ -180,7 +181,7 @@ const updateEmailForRecipeId = async ( validationError = validationResult; } } else { - const validationResult = await passwordlessConfig.validateEmailAddress(email); + const validationResult = await passwordlessConfig.validateEmailAddress(email, tenantId); if (validationResult !== undefined) { isValidEmail = false; @@ -226,6 +227,7 @@ const updatePhoneForRecipeId = async ( recipeId: "emailpassword" | "thirdparty" | "passwordless" | "thirdpartyemailpassword" | "thirdpartypasswordless", userId: string, phone: string, + tenantId: string, userContext: any ): Promise< | { @@ -253,7 +255,7 @@ const updatePhoneForRecipeId = async ( validationError = validationResult; } } else { - const validationResult = await passwordlessConfig.validatePhoneNumber(phone); + const validationResult = await passwordlessConfig.validatePhoneNumber(phone, tenantId); if (validationResult !== undefined) { isValidPhone = false; @@ -303,7 +305,7 @@ const updatePhoneForRecipeId = async ( validationError = validationResult; } } else { - const validationResult = await passwordlessConfig.validatePhoneNumber(phone); + const validationResult = await passwordlessConfig.validatePhoneNumber(phone, tenantId); if (validationResult !== undefined) { isValidPhone = false; @@ -347,7 +349,7 @@ const updatePhoneForRecipeId = async ( export const userPut = async ( _: APIInterface, - ___: string, + tenantId: string, options: APIOptions, userContext: any ): Promise => { @@ -443,6 +445,7 @@ export const userPut = async ( userResponse.recipe, userId, email.trim(), + tenantId, userContext ); @@ -456,6 +459,7 @@ export const userPut = async ( userResponse.recipe, userId, phone.trim(), + tenantId, userContext ); diff --git a/lib/ts/recipe/emailpassword/api/generatePasswordResetToken.ts b/lib/ts/recipe/emailpassword/api/generatePasswordResetToken.ts index b6eb23a8c..033571770 100644 --- a/lib/ts/recipe/emailpassword/api/generatePasswordResetToken.ts +++ b/lib/ts/recipe/emailpassword/api/generatePasswordResetToken.ts @@ -35,7 +35,8 @@ export default async function generatePasswordResetToken( value: string; }[] = await validateFormFieldsOrThrowError( options.config.resetPasswordUsingTokenFeature.formFieldsForGenerateTokenForm, - (await options.req.getJSONBody()).formFields + (await options.req.getJSONBody()).formFields, + tenantId ); let result = await apiImplementation.generatePasswordResetTokenPOST({ diff --git a/lib/ts/recipe/emailpassword/api/passwordReset.ts b/lib/ts/recipe/emailpassword/api/passwordReset.ts index f16fab61c..8b5303e07 100644 --- a/lib/ts/recipe/emailpassword/api/passwordReset.ts +++ b/lib/ts/recipe/emailpassword/api/passwordReset.ts @@ -36,7 +36,8 @@ export default async function passwordReset( value: string; }[] = await validateFormFieldsOrThrowError( options.config.resetPasswordUsingTokenFeature.formFieldsForPasswordResetForm, - (await options.req.getJSONBody()).formFields + (await options.req.getJSONBody()).formFields, + tenantId ); let token = (await options.req.getJSONBody()).token; diff --git a/lib/ts/recipe/emailpassword/api/signin.ts b/lib/ts/recipe/emailpassword/api/signin.ts index 86d8425ad..75f68878d 100644 --- a/lib/ts/recipe/emailpassword/api/signin.ts +++ b/lib/ts/recipe/emailpassword/api/signin.ts @@ -34,7 +34,8 @@ export default async function signInAPI( value: string; }[] = await validateFormFieldsOrThrowError( options.config.signInFeature.formFields, - (await options.req.getJSONBody()).formFields + (await options.req.getJSONBody()).formFields, + tenantId ); let result = await apiImplementation.signInPOST({ diff --git a/lib/ts/recipe/emailpassword/api/signup.ts b/lib/ts/recipe/emailpassword/api/signup.ts index 02d89d60b..1ae42d9ac 100644 --- a/lib/ts/recipe/emailpassword/api/signup.ts +++ b/lib/ts/recipe/emailpassword/api/signup.ts @@ -36,7 +36,8 @@ export default async function signUpAPI( value: string; }[] = await validateFormFieldsOrThrowError( options.config.signUpFeature.formFields, - (await options.req.getJSONBody()).formFields + (await options.req.getJSONBody()).formFields, + tenantId ); let result = await apiImplementation.signUpPOST({ diff --git a/lib/ts/recipe/emailpassword/api/utils.ts b/lib/ts/recipe/emailpassword/api/utils.ts index aca7cbab8..090180ba6 100644 --- a/lib/ts/recipe/emailpassword/api/utils.ts +++ b/lib/ts/recipe/emailpassword/api/utils.ts @@ -18,7 +18,8 @@ import { FORM_FIELD_EMAIL_ID } from "../constants"; export async function validateFormFieldsOrThrowError( configFormFields: NormalisedFormField[], - formFieldsRaw: any + formFieldsRaw: any, + tenantId: string ): Promise< { id: string; @@ -62,7 +63,7 @@ export async function validateFormFieldsOrThrowError( }); // then run validators through them----------------------- - await validateFormOrThrowError(formFields, configFormFields); + await validateFormOrThrowError(formFields, configFormFields, tenantId); return formFields; } @@ -81,7 +82,8 @@ async function validateFormOrThrowError( id: string; value: string; }[], - configFormFields: NormalisedFormField[] + configFormFields: NormalisedFormField[], + tenantId: string ) { let validationErrors: { id: string; error: string }[] = []; @@ -104,7 +106,7 @@ async function validateFormOrThrowError( }); } else { // Otherwise, use validate function. - const error = await field.validate(input.value); + const error = await field.validate(input.value, tenantId); // If error, add it. if (error !== undefined) { validationErrors.push({ diff --git a/lib/ts/recipe/emailpassword/recipeImplementation.ts b/lib/ts/recipe/emailpassword/recipeImplementation.ts index 658eaadac..d443c1fcd 100644 --- a/lib/ts/recipe/emailpassword/recipeImplementation.ts +++ b/lib/ts/recipe/emailpassword/recipeImplementation.ts @@ -158,6 +158,7 @@ export default function getRecipeInterface( email?: string; password?: string; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy?: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; @@ -168,7 +169,12 @@ export default function getRecipeInterface( let formFields = getEmailPasswordConfig().signUpFeature.formFields; if (input.password !== undefined) { const passwordField = formFields.filter((el) => el.id === FORM_FIELD_PASSWORD_ID)[0]; - const error = await passwordField.validate(input.password); + const error = await passwordField.validate( + input.password, + input.tenantIdForPasswordPolicy === undefined + ? DEFAULT_TENANT_ID + : input.tenantIdForPasswordPolicy + ); if (error !== undefined) { return { status: "PASSWORD_POLICY_VIOLATED_ERROR", diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index fe9f15172..cd79ab47b 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -66,13 +66,6 @@ export type TypeNormalisedInputSignIn = { formFields: NormalisedFormField[]; }; -export type TypeInputResetPasswordUsingTokenFeature = { - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: (user: User, passwordResetURLWithToken: string, tenantId: string, userContext: any) => Promise; -}; - export type TypeNormalisedInputResetPasswordUsingTokenFeature = { formFieldsForGenerateTokenForm: NormalisedFormField[]; formFieldsForPasswordResetForm: NormalisedFormField[]; @@ -88,7 +81,6 @@ export type User = { export type TypeInput = { signUpFeature?: TypeInputSignUp; emailDelivery?: EmailDeliveryTypeInput; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/ts/recipe/emailpassword/utils.ts b/lib/ts/recipe/emailpassword/utils.ts index 0e93633ba..96ae19aac 100644 --- a/lib/ts/recipe/emailpassword/utils.ts +++ b/lib/ts/recipe/emailpassword/utils.ts @@ -60,12 +60,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomEmail implementation which calls our supertokens API */ if (emailService === undefined) { - emailService = new BackwardCompatibilityService( - recipeImpl, - appInfo, - isInServerlessEnv, - config?.resetPasswordUsingTokenFeature - ); + emailService = new BackwardCompatibilityService(recipeImpl, appInfo, isInServerlessEnv); } return { ...config?.emailDelivery, diff --git a/lib/ts/recipe/emailverification/types.ts b/lib/ts/recipe/emailverification/types.ts index d65368a7b..933f5d83f 100644 --- a/lib/ts/recipe/emailverification/types.ts +++ b/lib/ts/recipe/emailverification/types.ts @@ -36,10 +36,6 @@ export type TypeInput = { } | { status: "EMAIL_DOES_NOT_EXIST_ERROR" | "UNKNOWN_USER_ID_ERROR" } >; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: (user: User, emailVerificationURLWithToken: string, tenantId: string, userContext: any) => Promise; override?: { functions?: ( originalImplementation: RecipeInterface, diff --git a/lib/ts/recipe/emailverification/utils.ts b/lib/ts/recipe/emailverification/utils.ts index 8b77b0af5..ee27764ea 100644 --- a/lib/ts/recipe/emailverification/utils.ts +++ b/lib/ts/recipe/emailverification/utils.ts @@ -39,11 +39,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomEmail implementation which calls our supertokens API */ if (emailService === undefined) { - emailService = new BackwardCompatibilityService( - appInfo, - isInServerlessEnv, - config.createAndSendCustomEmail - ); + emailService = new BackwardCompatibilityService(appInfo, isInServerlessEnv); } return { ...config.emailDelivery, diff --git a/lib/ts/recipe/openid/types.ts b/lib/ts/recipe/openid/types.ts index 978b340f1..b3ade8a79 100644 --- a/lib/ts/recipe/openid/types.ts +++ b/lib/ts/recipe/openid/types.ts @@ -100,7 +100,6 @@ export type RecipeInterface = { payload?: any; validitySeconds?: number; useStaticSigningKey?: boolean; - tenantId: string; userContext: any; }): Promise< | { diff --git a/lib/ts/recipe/passwordless/api/createCode.ts b/lib/ts/recipe/passwordless/api/createCode.ts index 6bf47cb0f..bd94a27b9 100644 --- a/lib/ts/recipe/passwordless/api/createCode.ts +++ b/lib/ts/recipe/passwordless/api/createCode.ts @@ -59,7 +59,7 @@ export default async function createCode( (options.config.contactMethod === "EMAIL" || options.config.contactMethod === "EMAIL_OR_PHONE") ) { email = email.trim(); - const validateError = await options.config.validateEmailAddress(email); + const validateError = await options.config.validateEmailAddress(email, tenantId); if (validateError !== undefined) { send200Response(options.res, { status: "GENERAL_ERROR", @@ -73,7 +73,7 @@ export default async function createCode( phoneNumber !== undefined && (options.config.contactMethod === "PHONE" || options.config.contactMethod === "EMAIL_OR_PHONE") ) { - const validateError = await options.config.validatePhoneNumber(phoneNumber); + const validateError = await options.config.validatePhoneNumber(phoneNumber, tenantId); if (validateError !== undefined) { send200Response(options.res, { status: "GENERAL_ERROR", diff --git a/lib/ts/recipe/passwordless/api/implementation.ts b/lib/ts/recipe/passwordless/api/implementation.ts index 089a22002..58eb8f2e7 100644 --- a/lib/ts/recipe/passwordless/api/implementation.ts +++ b/lib/ts/recipe/passwordless/api/implementation.ts @@ -77,7 +77,10 @@ export default function getAPIImplementation(): APIInterface { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : await input.options.config.getCustomUserInputCode(input.userContext), + : await input.options.config.getCustomUserInputCode( + input.tenantId, + input.userContext + ), tenantId: input.tenantId, } : { @@ -86,7 +89,10 @@ export default function getAPIImplementation(): APIInterface { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : await input.options.config.getCustomUserInputCode(input.userContext), + : await input.options.config.getCustomUserInputCode( + input.tenantId, + input.userContext + ), tenantId: input.tenantId, } ); @@ -207,7 +213,7 @@ export default function getAPIImplementation(): APIInterface { userInputCode: input.options.config.getCustomUserInputCode === undefined ? undefined - : await input.options.config.getCustomUserInputCode(input.userContext), + : await input.options.config.getCustomUserInputCode(input.tenantId, input.userContext), tenantId: input.tenantId, }); diff --git a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts index 909f38900..28d81f08e 100644 --- a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts @@ -17,6 +17,7 @@ import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery import axios, { AxiosError } from "axios"; import { NormalisedAppinfo } from "../../../../../types"; import { logDebugMessage } from "../../../../../logger"; +import { DEFAULT_TENANT_ID } from "../../../../multitenancy/constants"; function defaultCreateAndSendCustomEmail(appInfo: NormalisedAppinfo) { return async ( @@ -29,7 +30,8 @@ function defaultCreateAndSendCustomEmail(appInfo: NormalisedAppinfo) { urlWithLinkCode?: string; codeLifetime: number; }, - _: any + _: string, + __: any ): Promise => { if (process.env.TEST_MODE === "testing") { return; @@ -105,30 +107,12 @@ export default class BackwardCompatibilityService // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; - constructor( - appInfo: NormalisedAppinfo, - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - userContext: any - ) => Promise - ) { - this.createAndSendCustomEmail = - createAndSendCustomEmail === undefined - ? defaultCreateAndSendCustomEmail(appInfo) - : createAndSendCustomEmail; + constructor(appInfo: NormalisedAppinfo) { + this.createAndSendCustomEmail = defaultCreateAndSendCustomEmail(appInfo); } sendEmail = async (input: TypePasswordlessEmailDeliveryInput & { userContext: any }) => { @@ -140,6 +124,7 @@ export default class BackwardCompatibilityService preAuthSessionId: input.preAuthSessionId, codeLifetime: input.codeLifetime, }, + input.tenantId === undefined ? DEFAULT_TENANT_ID : input.tenantId, input.userContext ); }; diff --git a/lib/ts/recipe/passwordless/recipe.ts b/lib/ts/recipe/passwordless/recipe.ts index 26e20e5a1..11b75bd97 100644 --- a/lib/ts/recipe/passwordless/recipe.ts +++ b/lib/ts/recipe/passwordless/recipe.ts @@ -231,7 +231,7 @@ export default class Recipe extends RecipeModule { ): Promise => { let userInputCode = this.config.getCustomUserInputCode !== undefined - ? await this.config.getCustomUserInputCode(input.userContext) + ? await this.config.getCustomUserInputCode(input.tenantId, input.userContext) : undefined; const codeInfo = await this.recipeInterfaceImpl.createCode( diff --git a/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts index a140fb03c..af608e4e3 100644 --- a/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts @@ -19,6 +19,7 @@ import axios, { AxiosError } from "axios"; import { SUPERTOKENS_SMS_SERVICE_URL } from "../../../../../ingredients/smsdelivery/services/supertokens"; import Supertokens from "../../../../../supertokens"; import { logDebugMessage } from "../../../../../logger"; +import { DEFAULT_TENANT_ID } from "../../../../multitenancy/constants"; function defaultCreateAndSendCustomSms(_: NormalisedAppinfo) { return async ( @@ -31,7 +32,8 @@ function defaultCreateAndSendCustomSms(_: NormalisedAppinfo) { urlWithLinkCode?: string; codeLifetime: number; }, - _: any + _: string, + __: any ): Promise => { let supertokens = Supertokens.getInstanceOrThrowError(); let appName = supertokens.appInfo.appName; @@ -130,28 +132,12 @@ export default class BackwardCompatibilityService implements SmsDeliveryInterfac // Unlikely, but someone could display this (or a derived thing) to identify the device preAuthSessionId: string; }, + tenantId: string, userContext: any ) => Promise; - constructor( - appInfo: NormalisedAppinfo, - createAndSendCustomSms?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - userContext: any - ) => Promise - ) { - this.createAndSendCustomSms = - createAndSendCustomSms === undefined ? defaultCreateAndSendCustomSms(appInfo) : createAndSendCustomSms; + constructor(appInfo: NormalisedAppinfo) { + this.createAndSendCustomSms = defaultCreateAndSendCustomSms(appInfo); } sendSms = async (input: TypePasswordlessSmsDeliveryInput & { userContext: any }) => { @@ -163,6 +149,7 @@ export default class BackwardCompatibilityService implements SmsDeliveryInterfac preAuthSessionId: input.preAuthSessionId, codeLifetime: input.codeLifetime, }, + input.tenantId === undefined ? DEFAULT_TENANT_ID : input.tenantId, input.userContext ); }; diff --git a/lib/ts/recipe/passwordless/types.ts b/lib/ts/recipe/passwordless/types.ts index 04c2037a0..fb45a21df 100644 --- a/lib/ts/recipe/passwordless/types.ts +++ b/lib/ts/recipe/passwordless/types.ts @@ -41,96 +41,22 @@ export type User = { export type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; @@ -154,7 +80,10 @@ export type TypeInput = ( export type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; @@ -163,8 +92,10 @@ export type TypeNormalisedInput = ( | { contactMethod: "EMAIL_OR_PHONE"; validateEmailAddress: (email: string, tenantId: string) => Promise | string | undefined; - - validatePhoneNumber: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; diff --git a/lib/ts/recipe/passwordless/utils.ts b/lib/ts/recipe/passwordless/utils.ts index 343eed274..223c5ff4b 100644 --- a/lib/ts/recipe/passwordless/utils.ts +++ b/lib/ts/recipe/passwordless/utils.ts @@ -46,7 +46,6 @@ export function validateAndNormaliseUserInput( function getEmailDeliveryConfig() { let emailService = config.emailDelivery?.service; - let createAndSendCustomEmail = config.contactMethod === "PHONE" ? undefined : config.createAndSendCustomEmail; /** * following code is for backward compatibility. * if user has not passed emailDelivery config, we @@ -55,7 +54,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new BackwardCompatibilityEmailService(appInfo, createAndSendCustomEmail); + emailService = new BackwardCompatibilityEmailService(appInfo); } let emailDelivery = { ...config.emailDelivery, @@ -78,8 +77,6 @@ export function validateAndNormaliseUserInput( function getSmsDeliveryConfig() { let smsService = config.smsDelivery?.service; - let createAndSendCustomTextMessage = - config.contactMethod === "EMAIL" ? undefined : config.createAndSendCustomTextMessage; /** * following code is for backward compatibility. * if user has not passed emailDelivery config, we @@ -88,7 +85,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new BackwardCompatibilitySmsService(appInfo, createAndSendCustomTextMessage); + smsService = new BackwardCompatibilitySmsService(appInfo); } let smsDelivery = { ...config.smsDelivery, diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index c8435c40b..4c00eeac5 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -69,7 +69,6 @@ export type TypeInput = { getTokenTransferMethod?: (input: { req: BaseRequest; forCreateNewSession: boolean; - tenantId: string; userContext: any; }) => TokenTransferMethod | "any"; @@ -119,7 +118,6 @@ export type TypeNormalisedInput = { getTokenTransferMethod: (input: { req: BaseRequest; forCreateNewSession: boolean; - tenantId: string; userContext: any; }) => TokenTransferMethod | "any"; @@ -184,7 +182,6 @@ export interface VerifySessionOptions { overrideGlobalClaimValidators?: ( globalClaimValidators: SessionClaimValidator[], session: SessionContainerInterface, - tenantId: string, userContext: any ) => Promise | SessionClaimValidator[]; } diff --git a/lib/ts/recipe/thirdparty/api/implementation.ts b/lib/ts/recipe/thirdparty/api/implementation.ts index 353058182..84d215e6a 100644 --- a/lib/ts/recipe/thirdparty/api/implementation.ts +++ b/lib/ts/recipe/thirdparty/api/implementation.ts @@ -36,6 +36,7 @@ export default function getAPIInterface(): APIInterface { userInfo.email = { id: await provider.config.generateFakeEmail!({ thirdPartyUserId: userInfo.thirdPartyUserId, + tenantId, userContext, }), isVerified: true, diff --git a/lib/ts/recipe/thirdparty/types.ts b/lib/ts/recipe/thirdparty/types.ts index c8fd06400..ac3aa0528 100644 --- a/lib/ts/recipe/thirdparty/types.ts +++ b/lib/ts/recipe/thirdparty/types.ts @@ -64,7 +64,6 @@ type CommonProviderConfig = { validateIdTokenPayload?: (input: { idTokenPayload: { [key: string]: any }; clientConfig: ProviderConfigForClientType; - tenantId: string; userContext: any; }) => Promise; requireEmail?: boolean; diff --git a/lib/ts/recipe/thirdpartyemailpassword/recipe.ts b/lib/ts/recipe/thirdpartyemailpassword/recipe.ts index 65c2947eb..c9706f7c0 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/recipe.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/recipe.ts @@ -121,7 +121,6 @@ export default class Recipe extends RecipeModule { signUpFeature: { formFields: this.config.signUpFeature.formFields, }, - resetPasswordUsingTokenFeature: this.config.resetPasswordUsingTokenFeature, }, { emailDelivery: this.emailDelivery, diff --git a/lib/ts/recipe/thirdpartyemailpassword/types.ts b/lib/ts/recipe/thirdpartyemailpassword/types.ts index 4ca16bd48..988465a44 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/types.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/types.ts @@ -24,7 +24,6 @@ import { NormalisedFormField, TypeFormField, TypeInputFormField, - TypeInputResetPasswordUsingTokenFeature, APIOptions as EmailPasswordAPIOptionsOriginal, TypeEmailPasswordEmailDeliveryInput, RecipeInterface as EPRecipeInterface, @@ -74,7 +73,6 @@ export type TypeInput = { signUpFeature?: TypeInputSignUp; providers?: ProviderInput[]; emailDelivery?: EmailDeliveryTypeInput; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override?: { functions?: ( originalImplementation: RecipeInterface, @@ -91,7 +89,6 @@ export type TypeNormalisedInput = { emailPasswordRecipeImpl: EPRecipeInterface, isInServerlessEnv: boolean ) => EmailDeliveryTypeInputWithService; - resetPasswordUsingTokenFeature?: TypeInputResetPasswordUsingTokenFeature; override: { functions: ( originalImplementation: RecipeInterface, diff --git a/lib/ts/recipe/thirdpartyemailpassword/utils.ts b/lib/ts/recipe/thirdpartyemailpassword/utils.ts index 2c1577768..b27c6239d 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/utils.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/utils.ts @@ -33,8 +33,6 @@ export function validateAndNormaliseUserInput( config === undefined ? undefined : config.signUpFeature ); - let resetPasswordUsingTokenFeature = config === undefined ? undefined : config.resetPasswordUsingTokenFeature; - let providers = config === undefined || config.providers === undefined ? [] : config.providers; let override = { @@ -53,12 +51,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new BackwardCompatibilityService( - emailPasswordRecipeImpl, - appInfo, - isInServerlessEnv, - config?.resetPasswordUsingTokenFeature - ); + emailService = new BackwardCompatibilityService(emailPasswordRecipeImpl, appInfo, isInServerlessEnv); } return { ...config?.emailDelivery, @@ -82,7 +75,6 @@ export function validateAndNormaliseUserInput( getEmailDeliveryConfig, signUpFeature, providers, - resetPasswordUsingTokenFeature, }; } diff --git a/lib/ts/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.ts index 914128178..ff8f183a0 100644 --- a/lib/ts/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/thirdpartypasswordless/emaildelivery/services/backwardCompatibility/index.ts @@ -21,30 +21,9 @@ export default class BackwardCompatibilityService implements EmailDeliveryInterface { private passwordlessBackwardCompatibilityService: PasswordlessBackwardCompatibilityService; - constructor( - appInfo: NormalisedAppinfo, - passwordlessFeature?: { - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - userContext: any - ) => Promise; - } - ) { + constructor(appInfo: NormalisedAppinfo) { { - this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService( - appInfo, - passwordlessFeature?.createAndSendCustomEmail - ); + this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService(appInfo); } } diff --git a/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts index ddffd8a65..c0a8b2e30 100644 --- a/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts @@ -21,29 +21,8 @@ export default class BackwardCompatibilityService implements SmsDeliveryInterface { private passwordlessBackwardCompatibilityService: PasswordlessBackwardCompatibilityService; - constructor( - appInfo: NormalisedAppinfo, - passwordlessFeature?: { - createAndSendCustomTextMessage?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - userContext: any - ) => Promise; - } - ) { - this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService( - appInfo, - passwordlessFeature?.createAndSendCustomTextMessage - ); + constructor(appInfo: NormalisedAppinfo) { + this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService(appInfo); } sendSms = async (input: TypeThirdPartyPasswordlessSmsDeliveryInput & { userContext: any }) => { diff --git a/lib/ts/recipe/thirdpartypasswordless/types.ts b/lib/ts/recipe/thirdpartypasswordless/types.ts index a0b3734ed..0be408b0c 100644 --- a/lib/ts/recipe/thirdpartypasswordless/types.ts +++ b/lib/ts/recipe/thirdpartypasswordless/types.ts @@ -63,7 +63,10 @@ export type User = ( export type TypeInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -132,7 +135,10 @@ export type TypeInput = ( tenantId: string, userContext: any ) => Promise; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; // Override to use custom template/contact method /** @@ -179,7 +185,10 @@ export type TypeInput = ( export type TypeNormalisedInput = ( | { contactMethod: "PHONE"; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } | { contactMethod: "EMAIL"; @@ -188,7 +197,10 @@ export type TypeNormalisedInput = ( | { contactMethod: "EMAIL_OR_PHONE"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - validatePhoneNumber?: (phoneNumber: string, tenantId: string) => Promise | string | undefined; + validatePhoneNumber?: ( + phoneNumber: string, + tenantId: string + ) => Promise | string | undefined; } ) & { flowType: "USER_INPUT_CODE" | "MAGIC_LINK" | "USER_INPUT_CODE_AND_MAGIC_LINK"; diff --git a/lib/ts/recipe/thirdpartypasswordless/utils.ts b/lib/ts/recipe/thirdpartypasswordless/utils.ts index b68a8eef5..820705c22 100644 --- a/lib/ts/recipe/thirdpartypasswordless/utils.ts +++ b/lib/ts/recipe/thirdpartypasswordless/utils.ts @@ -38,10 +38,7 @@ export function validateAndNormaliseUserInput(appInfo: NormalisedAppinfo, config * createAndSendCustomEmail implementation */ if (emailService === undefined) { - emailService = new BackwardCompatibilityEmailService(appInfo, { - createAndSendCustomEmail: - config?.contactMethod !== "PHONE" ? config?.createAndSendCustomEmail : undefined, - }); + emailService = new BackwardCompatibilityEmailService(appInfo); } return { ...config?.emailDelivery, @@ -70,10 +67,7 @@ export function validateAndNormaliseUserInput(appInfo: NormalisedAppinfo, config * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new BackwardCompatibilitySmsService(appInfo, { - createAndSendCustomTextMessage: - config?.contactMethod !== "EMAIL" ? config?.createAndSendCustomTextMessage : undefined, - }); + smsService = new BackwardCompatibilitySmsService(appInfo); } return { ...config?.smsDelivery, From 1a2547f788987a0c3b49158d76b421e471fbd59c Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 7 Jul 2023 17:00:22 +0530 Subject: [PATCH 07/14] fix: impl --- lib/build/recipe/emailpassword/index.d.ts | 1 + lib/build/recipe/emailpassword/index.js | 11 ++++++++--- .../recipe/emailpassword/recipeImplementation.js | 7 +------ lib/build/recipe/emailpassword/types.d.ts | 1 + lib/ts/recipe/emailpassword/index.ts | 3 +++ lib/ts/recipe/emailpassword/recipeImplementation.ts | 9 ++------- lib/ts/recipe/emailpassword/types.ts | 1 + .../emailPasswordRecipeImplementation.ts | 1 + .../recipeImplementation/index.ts | 1 + 9 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/build/recipe/emailpassword/index.d.ts b/lib/build/recipe/emailpassword/index.d.ts index 654045cc6..b230b3a82 100644 --- a/lib/build/recipe/emailpassword/index.d.ts +++ b/lib/build/recipe/emailpassword/index.d.ts @@ -68,6 +68,7 @@ export default class Wrapper { password?: string; userContext?: any; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy?: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; diff --git a/lib/build/recipe/emailpassword/index.js b/lib/build/recipe/emailpassword/index.js index c942897ef..7c31cf370 100644 --- a/lib/build/recipe/emailpassword/index.js +++ b/lib/build/recipe/emailpassword/index.js @@ -101,9 +101,14 @@ class Wrapper { }); } static updateEmailOrPassword(input) { - return recipe_1.default - .getInstanceOrThrowError() - .recipeInterfaceImpl.updateEmailOrPassword(Object.assign({ userContext: {} }, input)); + return recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.updateEmailOrPassword( + Object.assign(Object.assign({ userContext: {} }, input), { + tenantIdForPasswordPolicy: + input.tenantIdForPasswordPolicy === undefined + ? constants_1.DEFAULT_TENANT_ID + : input.tenantIdForPasswordPolicy, + }) + ); } static createResetPasswordLink(userId, tenantId, userContext) { return __awaiter(this, void 0, void 0, function* () { diff --git a/lib/build/recipe/emailpassword/recipeImplementation.js b/lib/build/recipe/emailpassword/recipeImplementation.js index 70a277b2b..5ab61cd8b 100644 --- a/lib/build/recipe/emailpassword/recipeImplementation.js +++ b/lib/build/recipe/emailpassword/recipeImplementation.js @@ -159,12 +159,7 @@ function getRecipeInterface(querier, getEmailPasswordConfig) { const passwordField = formFields.filter( (el) => el.id === constants_1.FORM_FIELD_PASSWORD_ID )[0]; - const error = yield passwordField.validate( - input.password, - input.tenantIdForPasswordPolicy === undefined - ? constants_2.DEFAULT_TENANT_ID - : input.tenantIdForPasswordPolicy - ); + const error = yield passwordField.validate(input.password, input.tenantIdForPasswordPolicy); if (error !== undefined) { return { status: "PASSWORD_POLICY_VIOLATED_ERROR", diff --git a/lib/build/recipe/emailpassword/types.d.ts b/lib/build/recipe/emailpassword/types.d.ts index 8ec43989d..53c0e1bae 100644 --- a/lib/build/recipe/emailpassword/types.d.ts +++ b/lib/build/recipe/emailpassword/types.d.ts @@ -136,6 +136,7 @@ export declare type RecipeInterface = { password?: string; userContext: any; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; diff --git a/lib/ts/recipe/emailpassword/index.ts b/lib/ts/recipe/emailpassword/index.ts index 064cf7afb..ed87edf58 100644 --- a/lib/ts/recipe/emailpassword/index.ts +++ b/lib/ts/recipe/emailpassword/index.ts @@ -80,10 +80,13 @@ export default class Wrapper { password?: string; userContext?: any; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy?: string; }) { return Recipe.getInstanceOrThrowError().recipeInterfaceImpl.updateEmailOrPassword({ userContext: {}, ...input, + tenantIdForPasswordPolicy: + input.tenantIdForPasswordPolicy === undefined ? DEFAULT_TENANT_ID : input.tenantIdForPasswordPolicy, }); } diff --git a/lib/ts/recipe/emailpassword/recipeImplementation.ts b/lib/ts/recipe/emailpassword/recipeImplementation.ts index d443c1fcd..31265e005 100644 --- a/lib/ts/recipe/emailpassword/recipeImplementation.ts +++ b/lib/ts/recipe/emailpassword/recipeImplementation.ts @@ -158,7 +158,7 @@ export default function getRecipeInterface( email?: string; password?: string; applyPasswordPolicy?: boolean; - tenantIdForPasswordPolicy?: string; + tenantIdForPasswordPolicy: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; @@ -169,12 +169,7 @@ export default function getRecipeInterface( let formFields = getEmailPasswordConfig().signUpFeature.formFields; if (input.password !== undefined) { const passwordField = formFields.filter((el) => el.id === FORM_FIELD_PASSWORD_ID)[0]; - const error = await passwordField.validate( - input.password, - input.tenantIdForPasswordPolicy === undefined - ? DEFAULT_TENANT_ID - : input.tenantIdForPasswordPolicy - ); + const error = await passwordField.validate(input.password, input.tenantIdForPasswordPolicy); if (error !== undefined) { return { status: "PASSWORD_POLICY_VIOLATED_ERROR", diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index cd79ab47b..ad678e7f5 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -138,6 +138,7 @@ export type RecipeInterface = { password?: string; userContext: any; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; diff --git a/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/emailPasswordRecipeImplementation.ts b/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/emailPasswordRecipeImplementation.ts index 853e8f7c2..0d2c7a2e3 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/emailPasswordRecipeImplementation.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/emailPasswordRecipeImplementation.ts @@ -67,6 +67,7 @@ export default function getRecipeInterface(recipeInterface: ThirdPartyEmailPassw password?: string; userContext: any; applyPasswordPolicy: boolean; + tenantIdForPasswordPolicy: string; }): Promise< | { status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR"; diff --git a/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/index.ts b/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/index.ts index 4ff5912bc..fe6c22a46 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/index.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/recipeImplementation/index.ts @@ -169,6 +169,7 @@ export default function getRecipeInterface( password?: string; userContext: any; applyPasswordPolicy?: boolean; + tenantIdForPasswordPolicy: string; } ): Promise< | { From b5f2c7793f40e74c8d6c6bb2e43ed30d85c82b89 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 7 Jul 2023 17:55:05 +0530 Subject: [PATCH 08/14] fix: pr comments --- .../services/backwardCompatibility/index.d.ts | 16 +- .../services/backwardCompatibility/index.js | 26 +-- .../emailpassword/passwordResetFunctions.d.ts | 8 +- .../emailpassword/passwordResetFunctions.js | 89 ++++---- lib/build/recipe/emailpassword/utils.js | 6 +- .../emailVerificationFunctions.d.ts | 8 +- .../emailVerificationFunctions.js | 87 ++++--- .../services/backwardCompatibility/index.d.ts | 13 +- .../services/backwardCompatibility/index.js | 20 +- lib/build/recipe/emailverification/utils.js | 6 +- .../services/backwardCompatibility/index.d.ts | 2 +- .../services/backwardCompatibility/index.js | 126 +++++------ .../services/backwardCompatibility/index.d.ts | 4 +- .../services/backwardCompatibility/index.js | 178 +++++++-------- lib/build/recipe/passwordless/utils.js | 8 +- .../services/backwardCompatibility/index.d.ts | 11 +- .../services/backwardCompatibility/index.js | 5 +- .../recipe/thirdpartyemailpassword/utils.js | 6 +- .../services/backwardCompatibility/index.d.ts | 3 +- .../services/backwardCompatibility/index.js | 4 +- .../recipe/thirdpartypasswordless/types.d.ts | 60 ----- .../recipe/thirdpartypasswordless/utils.js | 8 +- .../services/backwardCompatibility/index.ts | 41 +--- .../emailpassword/passwordResetFunctions.ts | 86 +++---- lib/ts/recipe/emailpassword/utils.ts | 6 +- .../emailVerificationFunctions.ts | 84 +++---- .../services/backwardCompatibility/index.ts | 31 +-- lib/ts/recipe/emailverification/utils.ts | 6 +- .../services/backwardCompatibility/index.ts | 160 ++++++------- .../services/backwardCompatibility/index.ts | 213 ++++++++---------- lib/ts/recipe/passwordless/utils.ts | 8 +- .../services/backwardCompatibility/index.ts | 14 +- .../recipe/thirdpartyemailpassword/utils.ts | 6 +- .../services/backwardCompatibility/index.ts | 5 +- lib/ts/recipe/thirdpartypasswordless/types.ts | 84 ------- lib/ts/recipe/thirdpartypasswordless/utils.ts | 8 +- 36 files changed, 559 insertions(+), 887 deletions(-) diff --git a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.d.ts index 77620015d..3f9e44647 100644 --- a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.d.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import { TypeEmailPasswordEmailDeliveryInput, User, RecipeInterface } from "../../../types"; +import { TypeEmailPasswordEmailDeliveryInput, RecipeInterface } from "../../../types"; import { NormalisedAppinfo } from "../../../../../types"; import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery/types"; export default class BackwardCompatibilityService @@ -7,19 +7,7 @@ export default class BackwardCompatibilityService private recipeInterfaceImpl; private isInServerlessEnv; private appInfo; - private resetPasswordUsingTokenFeature; - constructor( - recipeInterfaceImpl: RecipeInterface, - appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - resetPasswordUsingTokenFeature?: { - createAndSendCustomEmail?: ( - user: User, - passwordResetURLWithToken: string, - userContext: any - ) => Promise; - } - ); + constructor(recipeInterfaceImpl: RecipeInterface, appInfo: NormalisedAppinfo, isInServerlessEnv: boolean); sendEmail: ( input: TypeEmailPasswordEmailDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js index 96f394f0d..fcefa7e29 100644 --- a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js @@ -33,7 +33,7 @@ var __awaiter = Object.defineProperty(exports, "__esModule", { value: true }); const passwordResetFunctions_1 = require("../../../passwordResetFunctions"); class BackwardCompatibilityService { - constructor(recipeInterfaceImpl, appInfo, isInServerlessEnv, resetPasswordUsingTokenFeature) { + constructor(recipeInterfaceImpl, appInfo, isInServerlessEnv) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { let user = yield this.recipeInterfaceImpl.getUserById({ @@ -49,15 +49,15 @@ class BackwardCompatibilityService { user.email = input.user.email; try { if (!this.isInServerlessEnv) { - this.resetPasswordUsingTokenFeature - .createAndSendCustomEmail(user, input.passwordResetLink, input.userContext) + passwordResetFunctions_1 + .createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink) .catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - yield this.resetPasswordUsingTokenFeature.createAndSendCustomEmail( + passwordResetFunctions_1.createAndSendEmailUsingSupertokensService( + this.appInfo, user, - input.passwordResetLink, - input.userContext + input.passwordResetLink ); } } catch (_) {} @@ -65,20 +65,6 @@ class BackwardCompatibilityService { this.recipeInterfaceImpl = recipeInterfaceImpl; this.isInServerlessEnv = isInServerlessEnv; this.appInfo = appInfo; - { - let inputCreateAndSendCustomEmail = - resetPasswordUsingTokenFeature === null || resetPasswordUsingTokenFeature === void 0 - ? void 0 - : resetPasswordUsingTokenFeature.createAndSendCustomEmail; - this.resetPasswordUsingTokenFeature = - inputCreateAndSendCustomEmail !== undefined - ? { - createAndSendCustomEmail: inputCreateAndSendCustomEmail, - } - : { - createAndSendCustomEmail: passwordResetFunctions_1.createAndSendCustomEmail(this.appInfo), - }; - } } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/emailpassword/passwordResetFunctions.d.ts b/lib/build/recipe/emailpassword/passwordResetFunctions.d.ts index 56b10c948..38959a2d7 100644 --- a/lib/build/recipe/emailpassword/passwordResetFunctions.d.ts +++ b/lib/build/recipe/emailpassword/passwordResetFunctions.d.ts @@ -1,6 +1,8 @@ // @ts-nocheck import { User } from "./types"; import { NormalisedAppinfo } from "../../types"; -export declare function createAndSendCustomEmail( - appInfo: NormalisedAppinfo -): (user: User, passwordResetURLWithToken: string) => Promise; +export declare function createAndSendEmailUsingSupertokensService( + appInfo: NormalisedAppinfo, + user: User, + passwordResetURLWithToken: string +): Promise; diff --git a/lib/build/recipe/emailpassword/passwordResetFunctions.js b/lib/build/recipe/emailpassword/passwordResetFunctions.js index 535499e39..98f749e5e 100644 --- a/lib/build/recipe/emailpassword/passwordResetFunctions.js +++ b/lib/build/recipe/emailpassword/passwordResetFunctions.js @@ -50,56 +50,55 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.createAndSendCustomEmail = void 0; +exports.createAndSendEmailUsingSupertokensService = void 0; const axios_1 = __importDefault(require("axios")); const logger_1 = require("../../logger"); -function createAndSendCustomEmail(appInfo) { - return (user, passwordResetURLWithToken) => - __awaiter(this, void 0, void 0, function* () { - // related issue: https://github.com/supertokens/supertokens-node/issues/38 - if (process.env.TEST_MODE === "testing") { - return; +function createAndSendEmailUsingSupertokensService(appInfo, user, passwordResetURLWithToken) { + return __awaiter(this, void 0, void 0, function* () { + // related issue: https://github.com/supertokens/supertokens-node/issues/38 + if (process.env.TEST_MODE === "testing") { + return; + } + try { + yield axios_1.default({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/password/reset", + data: { + email: user.email, + appName: appInfo.appName, + passwordResetURL: passwordResetURLWithToken, + }, + headers: { + "api-version": 0, + }, + }); + logger_1.logDebugMessage(`Password reset email sent to ${user.email}`); + } catch (error) { + logger_1.logDebugMessage("Error sending password reset email"); + if (axios_1.default.isAxiosError(error)) { + const err = error; + if (err.response) { + logger_1.logDebugMessage(`Error status: ${err.response.status}`); + logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logger_1.logDebugMessage(`Error: ${err.message}`); + } + } else { + logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - yield axios_1.default({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/password/reset", - data: { + logger_1.logDebugMessage("Logging the input below:"); + logger_1.logDebugMessage( + JSON.stringify( + { email: user.email, appName: appInfo.appName, passwordResetURL: passwordResetURLWithToken, }, - headers: { - "api-version": 0, - }, - }); - logger_1.logDebugMessage(`Password reset email sent to ${user.email}`); - } catch (error) { - logger_1.logDebugMessage("Error sending password reset email"); - if (axios_1.default.isAxiosError(error)) { - const err = error; - if (err.response) { - logger_1.logDebugMessage(`Error status: ${err.response.status}`); - logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logger_1.logDebugMessage(`Error: ${err.message}`); - } - } else { - logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logger_1.logDebugMessage("Logging the input below:"); - logger_1.logDebugMessage( - JSON.stringify( - { - email: user.email, - appName: appInfo.appName, - passwordResetURL: passwordResetURLWithToken, - }, - null, - 2 - ) - ); - } - }); + null, + 2 + ) + ); + } + }); } -exports.createAndSendCustomEmail = createAndSendCustomEmail; +exports.createAndSendEmailUsingSupertokensService = createAndSendEmailUsingSupertokensService; diff --git a/lib/build/recipe/emailpassword/utils.js b/lib/build/recipe/emailpassword/utils.js index 86e2daa88..06e998f29 100644 --- a/lib/build/recipe/emailpassword/utils.js +++ b/lib/build/recipe/emailpassword/utils.js @@ -76,10 +76,8 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { : _a.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation which calls our supertokens API + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { emailService = new backwardCompatibility_1.default(recipeImpl, appInfo, isInServerlessEnv); diff --git a/lib/build/recipe/emailverification/emailVerificationFunctions.d.ts b/lib/build/recipe/emailverification/emailVerificationFunctions.d.ts index f09fbc85b..0dd678d38 100644 --- a/lib/build/recipe/emailverification/emailVerificationFunctions.d.ts +++ b/lib/build/recipe/emailverification/emailVerificationFunctions.d.ts @@ -1,6 +1,8 @@ // @ts-nocheck import { User } from "./types"; import { NormalisedAppinfo } from "../../types"; -export declare function createAndSendCustomEmail( - appInfo: NormalisedAppinfo -): (user: User, emailVerifyURLWithToken: string) => Promise; +export declare function createAndSendEmailUsingSupertokensService( + appInfo: NormalisedAppinfo, + user: User, + emailVerifyURLWithToken: string +): Promise; diff --git a/lib/build/recipe/emailverification/emailVerificationFunctions.js b/lib/build/recipe/emailverification/emailVerificationFunctions.js index 29b7b92a2..b590e17ed 100644 --- a/lib/build/recipe/emailverification/emailVerificationFunctions.js +++ b/lib/build/recipe/emailverification/emailVerificationFunctions.js @@ -50,55 +50,54 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.createAndSendCustomEmail = void 0; +exports.createAndSendEmailUsingSupertokensService = void 0; const axios_1 = __importDefault(require("axios")); const logger_1 = require("../../logger"); -function createAndSendCustomEmail(appInfo) { - return (user, emailVerifyURLWithToken) => - __awaiter(this, void 0, void 0, function* () { - if (process.env.TEST_MODE === "testing") { - return; +function createAndSendEmailUsingSupertokensService(appInfo, user, emailVerifyURLWithToken) { + return __awaiter(this, void 0, void 0, function* () { + if (process.env.TEST_MODE === "testing") { + return; + } + try { + yield axios_1.default({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/email/verify", + data: { + email: user.email, + appName: appInfo.appName, + emailVerifyURL: emailVerifyURLWithToken, + }, + headers: { + "api-version": 0, + }, + }); + logger_1.logDebugMessage(`Email sent to ${user.email}`); + } catch (error) { + logger_1.logDebugMessage("Error sending verification email"); + if (axios_1.default.isAxiosError(error)) { + const err = error; + if (err.response) { + logger_1.logDebugMessage(`Error status: ${err.response.status}`); + logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logger_1.logDebugMessage(`Error: ${err.message}`); + } + } else { + logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - yield axios_1.default({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/email/verify", - data: { + logger_1.logDebugMessage("Logging the input below:"); + logger_1.logDebugMessage( + JSON.stringify( + { email: user.email, appName: appInfo.appName, emailVerifyURL: emailVerifyURLWithToken, }, - headers: { - "api-version": 0, - }, - }); - logger_1.logDebugMessage(`Email sent to ${user.email}`); - } catch (error) { - logger_1.logDebugMessage("Error sending verification email"); - if (axios_1.default.isAxiosError(error)) { - const err = error; - if (err.response) { - logger_1.logDebugMessage(`Error status: ${err.response.status}`); - logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logger_1.logDebugMessage(`Error: ${err.message}`); - } - } else { - logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logger_1.logDebugMessage("Logging the input below:"); - logger_1.logDebugMessage( - JSON.stringify( - { - email: user.email, - appName: appInfo.appName, - emailVerifyURL: emailVerifyURLWithToken, - }, - null, - 2 - ) - ); - } - }); + null, + 2 + ) + ); + } + }); } -exports.createAndSendCustomEmail = createAndSendCustomEmail; +exports.createAndSendEmailUsingSupertokensService = createAndSendEmailUsingSupertokensService; diff --git a/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.d.ts index 6a681f11d..e49c3c040 100644 --- a/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.d.ts @@ -1,21 +1,12 @@ // @ts-nocheck -import { TypeEmailVerificationEmailDeliveryInput, User } from "../../../types"; +import { TypeEmailVerificationEmailDeliveryInput } from "../../../types"; import { NormalisedAppinfo } from "../../../../../types"; import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery/types"; export default class BackwardCompatibilityService implements EmailDeliveryInterface { private appInfo; private isInServerlessEnv; - private createAndSendCustomEmail; - constructor( - appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - createAndSendCustomEmail?: ( - user: User, - emailVerificationURLWithToken: string, - userContext: any - ) => Promise - ); + constructor(appInfo: NormalisedAppinfo, isInServerlessEnv: boolean); sendEmail: ( input: TypeEmailVerificationEmailDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.js index 67e5311b1..7867c3be3 100644 --- a/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.js @@ -33,28 +33,26 @@ var __awaiter = Object.defineProperty(exports, "__esModule", { value: true }); const emailVerificationFunctions_1 = require("../../../emailVerificationFunctions"); class BackwardCompatibilityService { - constructor(appInfo, isInServerlessEnv, createAndSendCustomEmail) { + constructor(appInfo, isInServerlessEnv) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { try { if (!this.isInServerlessEnv) { - this.createAndSendCustomEmail( - input.user, - input.emailVerifyLink, - input.userContext - ).catch((_) => {}); + emailVerificationFunctions_1 + .createAndSendEmailUsingSupertokensService(this.appInfo, input.user, input.emailVerifyLink) + .catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - yield this.createAndSendCustomEmail(input.user, input.emailVerifyLink, input.userContext); + yield emailVerificationFunctions_1.createAndSendEmailUsingSupertokensService( + this.appInfo, + input.user, + input.emailVerifyLink + ); } } catch (_) {} }); this.appInfo = appInfo; this.isInServerlessEnv = isInServerlessEnv; - this.createAndSendCustomEmail = - createAndSendCustomEmail === undefined - ? emailVerificationFunctions_1.createAndSendCustomEmail(this.appInfo) - : createAndSendCustomEmail; } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/emailverification/utils.js b/lib/build/recipe/emailverification/utils.js index 370465974..e1adb446c 100644 --- a/lib/build/recipe/emailverification/utils.js +++ b/lib/build/recipe/emailverification/utils.js @@ -34,10 +34,8 @@ function validateAndNormaliseUserInput(_, appInfo, config) { let emailService = (_a = config.emailDelivery) === null || _a === void 0 ? void 0 : _a.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation which calls our supertokens API + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { emailService = new backwardCompatibility_1.default(appInfo, isInServerlessEnv); diff --git a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts index f88a3bbe6..533582631 100644 --- a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.d.ts @@ -4,7 +4,7 @@ import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements EmailDeliveryInterface { - private createAndSendCustomEmail; + private appInfo; constructor(appInfo: NormalisedAppinfo); sendEmail: ( input: TypePasswordlessEmailDeliveryInput & { diff --git a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js index ca42ebd69..e50e3e150 100644 --- a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js @@ -38,86 +38,80 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const logger_1 = require("../../../../../logger"); -const constants_1 = require("../../../../multitenancy/constants"); -function defaultCreateAndSendCustomEmail(appInfo) { - return (input, _, __) => - __awaiter(this, void 0, void 0, function* () { - if (process.env.TEST_MODE === "testing") { - return; +function defaultCreateAndSendCustomEmail(input) { + return __awaiter(this, void 0, void 0, function* () { + if (process.env.TEST_MODE === "testing") { + return; + } + try { + yield axios_1.default({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/passwordless/login", + data: { + email: input.email, + appName: input.appInfo.appName, + codeLifetime: input.codeLifetime, + urlWithLinkCode: input.urlWithLinkCode, + userInputCode: input.userInputCode, + }, + headers: { + "api-version": 0, + }, + }); + logger_1.logDebugMessage(`Email sent to ${input.email}`); + } catch (error) { + logger_1.logDebugMessage("Error sending passwordless login email"); + if (axios_1.default.isAxiosError(error)) { + const err = error; + if (err.response) { + logger_1.logDebugMessage(`Error status: ${err.response.status}`); + logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logger_1.logDebugMessage(`Error: ${err.message}`); + } + } else { + logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - yield axios_1.default({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/passwordless/login", - data: { + logger_1.logDebugMessage("Logging the input below:"); + logger_1.logDebugMessage( + JSON.stringify( + { email: input.email, - appName: appInfo.appName, + appName: input.appInfo.appName, codeLifetime: input.codeLifetime, urlWithLinkCode: input.urlWithLinkCode, userInputCode: input.userInputCode, }, - headers: { - "api-version": 0, - }, - }); - logger_1.logDebugMessage(`Email sent to ${input.email}`); - } catch (error) { - logger_1.logDebugMessage("Error sending passwordless login email"); - if (axios_1.default.isAxiosError(error)) { - const err = error; - if (err.response) { - logger_1.logDebugMessage(`Error status: ${err.response.status}`); - logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logger_1.logDebugMessage(`Error: ${err.message}`); - } - } else { - logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logger_1.logDebugMessage("Logging the input below:"); - logger_1.logDebugMessage( - JSON.stringify( - { - email: input.email, - appName: appInfo.appName, - codeLifetime: input.codeLifetime, - urlWithLinkCode: input.urlWithLinkCode, - userInputCode: input.userInputCode, - }, - null, - 2 - ) - ); - /** - * if the error is thrown from API, the response object - * will be of type `{err: string}` - */ - if (axios_1.default.isAxiosError(error) && error.response !== undefined) { - if (error.response.data.err !== undefined) { - throw Error(error.response.data.err); - } + null, + 2 + ) + ); + /** + * if the error is thrown from API, the response object + * will be of type `{err: string}` + */ + if (axios_1.default.isAxiosError(error) && error.response !== undefined) { + if (error.response.data.err !== undefined) { + throw Error(error.response.data.err); } - throw error; } - }); + throw error; + } + }); } class BackwardCompatibilityService { constructor(appInfo) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { - yield this.createAndSendCustomEmail( - { - email: input.email, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - preAuthSessionId: input.preAuthSessionId, - codeLifetime: input.codeLifetime, - }, - input.tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : input.tenantId, - input.userContext - ); + yield defaultCreateAndSendCustomEmail({ + appInfo: this.appInfo, + email: input.email, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, + }); }); - this.createAndSendCustomEmail = defaultCreateAndSendCustomEmail(appInfo); + this.appInfo = appInfo; } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts index cd1b66f81..66c9c0498 100644 --- a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.d.ts @@ -1,10 +1,8 @@ // @ts-nocheck import { TypePasswordlessSmsDeliveryInput } from "../../../types"; import { SmsDeliveryInterface } from "../../../../../ingredients/smsdelivery/types"; -import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements SmsDeliveryInterface { - private createAndSendCustomSms; - constructor(appInfo: NormalisedAppinfo); + constructor(); sendSms: ( input: TypePasswordlessSmsDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js index 267628062..99ab642e0 100644 --- a/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.js @@ -40,110 +40,102 @@ const axios_1 = __importDefault(require("axios")); const supertokens_1 = require("../../../../../ingredients/smsdelivery/services/supertokens"); const supertokens_2 = __importDefault(require("../../../../../supertokens")); const logger_1 = require("../../../../../logger"); -const constants_1 = require("../../../../multitenancy/constants"); -function defaultCreateAndSendCustomSms(_) { - return (input, _, __) => - __awaiter(this, void 0, void 0, function* () { - let supertokens = supertokens_2.default.getInstanceOrThrowError(); - let appName = supertokens.appInfo.appName; - try { - yield axios_1.default({ - method: "post", - url: supertokens_1.SUPERTOKENS_SMS_SERVICE_URL, - data: { - smsInput: { - appName, - type: "PASSWORDLESS_LOGIN", - phoneNumber: input.phoneNumber, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - codeLifetime: input.codeLifetime, - }, - }, - headers: { - "api-version": "0", +function createAndSendSmsUsingSupertokensService(input) { + return __awaiter(this, void 0, void 0, function* () { + let supertokens = supertokens_2.default.getInstanceOrThrowError(); + let appName = supertokens.appInfo.appName; + try { + yield axios_1.default({ + method: "post", + url: supertokens_1.SUPERTOKENS_SMS_SERVICE_URL, + data: { + smsInput: { + appName, + type: "PASSWORDLESS_LOGIN", + phoneNumber: input.phoneNumber, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, }, - }); - logger_1.logDebugMessage(`Passwordless login SMS sent to ${input.phoneNumber}`); - return; - } catch (error) { - logger_1.logDebugMessage("Error sending passwordless login SMS"); - if (axios_1.default.isAxiosError(error)) { - const err = error; - if (err.response) { - logger_1.logDebugMessage(`Error status: ${err.response.status}`); - logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logger_1.logDebugMessage(`Error: ${err.message}`); - } - if (err.response) { - if (err.response.status !== 429) { - /** - * if the error is thrown from API, the response object - * will be of type `{err: string}` - */ - if (err.response.data.err !== undefined) { - throw Error(err.response.data.err); - } else { - throw err; - } + }, + headers: { + "api-version": "0", + }, + }); + logger_1.logDebugMessage(`Passwordless login SMS sent to ${input.phoneNumber}`); + return; + } catch (error) { + logger_1.logDebugMessage("Error sending passwordless login SMS"); + if (axios_1.default.isAxiosError(error)) { + const err = error; + if (err.response) { + logger_1.logDebugMessage(`Error status: ${err.response.status}`); + logger_1.logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logger_1.logDebugMessage(`Error: ${err.message}`); + } + if (err.response) { + if (err.response.status !== 429) { + /** + * if the error is thrown from API, the response object + * will be of type `{err: string}` + */ + if (err.response.data.err !== undefined) { + throw Error(err.response.data.err); + } else { + throw err; } - } else { - throw err; } } else { - logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); - throw error; + throw err; } + } else { + logger_1.logDebugMessage(`Error: ${JSON.stringify(error)}`); + throw error; } - console.log( - "Free daily SMS quota reached. If you want to use SuperTokens to send SMS, please sign up on supertokens.com to get your SMS API key, else you can also define your own method by overriding the service. For now, we are logging it below:" - ); - /** - * if we do console.log(`SMS content: ${input}`); - * Output would be: - * SMS content: [object Object] - */ - /** - * JSON.stringify takes 3 inputs - * - value: usually an object or array, to be converted - * - replacer: An array of strings and numbers that acts - * as an approved list for selecting the object - * properties that will be stringified - * - space: Adds indentation, white space, and line break characters - * to the return-value JSON text to make it easier to read - * - * console.log(JSON.stringify({"a": 1, "b": 2})) - * Output: - * {"a":1,"b":2} - * - * console.log(JSON.stringify({"a": 1, "b": 2}, null, 2)) - * Output: - * { - * "a": 1, - * "b": 2 - * } - */ - console.log(`\nSMS content: ${JSON.stringify(input, null, 2)}`); - }); + } + console.log( + "Free daily SMS quota reached. If you want to use SuperTokens to send SMS, please sign up on supertokens.com to get your SMS API key, else you can also define your own method by overriding the service. For now, we are logging it below:" + ); + /** + * if we do console.log(`SMS content: ${input}`); + * Output would be: + * SMS content: [object Object] + */ + /** + * JSON.stringify takes 3 inputs + * - value: usually an object or array, to be converted + * - replacer: An array of strings and numbers that acts + * as an approved list for selecting the object + * properties that will be stringified + * - space: Adds indentation, white space, and line break characters + * to the return-value JSON text to make it easier to read + * + * console.log(JSON.stringify({"a": 1, "b": 2})) + * Output: + * {"a":1,"b":2} + * + * console.log(JSON.stringify({"a": 1, "b": 2}, null, 2)) + * Output: + * { + * "a": 1, + * "b": 2 + * } + */ + console.log(`\nSMS content: ${JSON.stringify(input, null, 2)}`); + }); } class BackwardCompatibilityService { - constructor(appInfo) { + constructor() { this.sendSms = (input) => __awaiter(this, void 0, void 0, function* () { - yield this.createAndSendCustomSms( - { - phoneNumber: input.phoneNumber, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - preAuthSessionId: input.preAuthSessionId, - codeLifetime: input.codeLifetime, - }, - input.tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : input.tenantId, - input.userContext - ); + yield createAndSendSmsUsingSupertokensService({ + phoneNumber: input.phoneNumber, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, + }); }); - this.createAndSendCustomSms = defaultCreateAndSendCustomSms(appInfo); } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/passwordless/utils.js b/lib/build/recipe/passwordless/utils.js index 5fe99b3fc..ac0f1dedf 100644 --- a/lib/build/recipe/passwordless/utils.js +++ b/lib/build/recipe/passwordless/utils.js @@ -46,10 +46,8 @@ function validateAndNormaliseUserInput(_, appInfo, config) { let emailService = (_a = config.emailDelivery) === null || _a === void 0 ? void 0 : _a.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new backwardCompatibility_1.default(appInfo); @@ -81,7 +79,7 @@ function validateAndNormaliseUserInput(_, appInfo, config) { * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new backwardCompatibility_2.default(appInfo); + smsService = new backwardCompatibility_2.default(); } let smsDelivery = Object.assign(Object.assign({}, config.smsDelivery), { /** diff --git a/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.d.ts index be35a1981..e3b6e87a8 100644 --- a/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.d.ts @@ -1,5 +1,5 @@ // @ts-nocheck -import { TypeThirdPartyEmailPasswordEmailDeliveryInput, User } from "../../../types"; +import { TypeThirdPartyEmailPasswordEmailDeliveryInput } from "../../../types"; import { RecipeInterface as EmailPasswordRecipeInterface } from "../../../../emailpassword"; import { NormalisedAppinfo } from "../../../../../types"; import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery/types"; @@ -9,14 +9,7 @@ export default class BackwardCompatibilityService constructor( emailPasswordRecipeInterfaceImpl: EmailPasswordRecipeInterface, appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - resetPasswordUsingTokenFeature?: { - createAndSendCustomEmail?: ( - user: User, - passwordResetURLWithToken: string, - userContext: any - ) => Promise; - } + isInServerlessEnv: boolean ); sendEmail: ( input: TypeThirdPartyEmailPasswordEmailDeliveryInput & { diff --git a/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.js index c4057c084..ee09e5c75 100644 --- a/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.js @@ -40,7 +40,7 @@ const backwardCompatibility_1 = __importDefault( require("../../../../emailpassword/emaildelivery/services/backwardCompatibility") ); class BackwardCompatibilityService { - constructor(emailPasswordRecipeInterfaceImpl, appInfo, isInServerlessEnv, resetPasswordUsingTokenFeature) { + constructor(emailPasswordRecipeInterfaceImpl, appInfo, isInServerlessEnv) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { yield this.emailPasswordBackwardCompatibilityService.sendEmail(input); @@ -49,8 +49,7 @@ class BackwardCompatibilityService { this.emailPasswordBackwardCompatibilityService = new backwardCompatibility_1.default( emailPasswordRecipeInterfaceImpl, appInfo, - isInServerlessEnv, - resetPasswordUsingTokenFeature + isInServerlessEnv ); } } diff --git a/lib/build/recipe/thirdpartyemailpassword/utils.js b/lib/build/recipe/thirdpartyemailpassword/utils.js index 9b36d7936..797bd9b35 100644 --- a/lib/build/recipe/thirdpartyemailpassword/utils.js +++ b/lib/build/recipe/thirdpartyemailpassword/utils.js @@ -44,10 +44,8 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { : _a.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new backwardCompatibility_1.default(emailPasswordRecipeImpl, appInfo, isInServerlessEnv); diff --git a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts index 933ac145f..275e3e17f 100644 --- a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.d.ts @@ -1,11 +1,10 @@ // @ts-nocheck import { TypeThirdPartyPasswordlessSmsDeliveryInput } from "../../../types"; import { SmsDeliveryInterface } from "../../../../../ingredients/smsdelivery/types"; -import { NormalisedAppinfo } from "../../../../../types"; export default class BackwardCompatibilityService implements SmsDeliveryInterface { private passwordlessBackwardCompatibilityService; - constructor(appInfo: NormalisedAppinfo); + constructor(); sendSms: ( input: TypeThirdPartyPasswordlessSmsDeliveryInput & { userContext: any; diff --git a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js index fe145fa16..617e5be76 100644 --- a/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.js @@ -40,12 +40,12 @@ const backwardCompatibility_1 = __importDefault( require("../../../../passwordless/smsdelivery/services/backwardCompatibility") ); class BackwardCompatibilityService { - constructor(appInfo) { + constructor() { this.sendSms = (input) => __awaiter(this, void 0, void 0, function* () { yield this.passwordlessBackwardCompatibilityService.sendSms(input); }); - this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default(appInfo); + this.passwordlessBackwardCompatibilityService = new backwardCompatibility_1.default(); } } exports.default = BackwardCompatibilityService; diff --git a/lib/build/recipe/thirdpartypasswordless/types.d.ts b/lib/build/recipe/thirdpartypasswordless/types.d.ts index 24f1790f1..fec3217a3 100644 --- a/lib/build/recipe/thirdpartypasswordless/types.d.ts +++ b/lib/build/recipe/thirdpartypasswordless/types.d.ts @@ -49,74 +49,14 @@ export declare type TypeInput = ( phoneNumber: string, tenantId: string ) => Promise | string | undefined; - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } | { contactMethod: "EMAIL"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - email: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; - validatePhoneNumber?: ( - phoneNumber: string, - tenantId: string - ) => Promise | string | undefined; - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - phoneNumber: string; - userInputCode?: string; - urlWithLinkCode?: string; - codeLifetime: number; - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } ) & { /** diff --git a/lib/build/recipe/thirdpartypasswordless/utils.js b/lib/build/recipe/thirdpartypasswordless/utils.js index 62bb457ac..fea21a20f 100644 --- a/lib/build/recipe/thirdpartypasswordless/utils.js +++ b/lib/build/recipe/thirdpartypasswordless/utils.js @@ -39,10 +39,8 @@ function validateAndNormaliseUserInput(appInfo, config) { : _a.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new backwardCompatibility_1.default(appInfo); @@ -76,7 +74,7 @@ function validateAndNormaliseUserInput(appInfo, config) { * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new backwardCompatibility_2.default(appInfo); + smsService = new backwardCompatibility_2.default(); } return Object.assign(Object.assign({}, config === null || config === void 0 ? void 0 : config.smsDelivery), { /** diff --git a/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts index 6bdeaa072..c841a0443 100644 --- a/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts @@ -12,8 +12,8 @@ * License for the specific language governing permissions and limitations * under the License. */ -import { TypeEmailPasswordEmailDeliveryInput, User, RecipeInterface } from "../../../types"; -import { createAndSendCustomEmail as defaultCreateAndSendCustomEmail } from "../../../passwordResetFunctions"; +import { TypeEmailPasswordEmailDeliveryInput, RecipeInterface } from "../../../types"; +import { createAndSendEmailUsingSupertokensService } from "../../../passwordResetFunctions"; import { NormalisedAppinfo } from "../../../../../types"; import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery/types"; @@ -22,36 +22,11 @@ export default class BackwardCompatibilityService private recipeInterfaceImpl: RecipeInterface; private isInServerlessEnv: boolean; private appInfo: NormalisedAppinfo; - private resetPasswordUsingTokenFeature: { - createAndSendCustomEmail: (user: User, passwordResetURLWithToken: string, userContext: any) => Promise; - }; - constructor( - recipeInterfaceImpl: RecipeInterface, - appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - resetPasswordUsingTokenFeature?: { - createAndSendCustomEmail?: ( - user: User, - passwordResetURLWithToken: string, - userContext: any - ) => Promise; - } - ) { + constructor(recipeInterfaceImpl: RecipeInterface, appInfo: NormalisedAppinfo, isInServerlessEnv: boolean) { this.recipeInterfaceImpl = recipeInterfaceImpl; this.isInServerlessEnv = isInServerlessEnv; this.appInfo = appInfo; - { - let inputCreateAndSendCustomEmail = resetPasswordUsingTokenFeature?.createAndSendCustomEmail; - this.resetPasswordUsingTokenFeature = - inputCreateAndSendCustomEmail !== undefined - ? { - createAndSendCustomEmail: inputCreateAndSendCustomEmail, - } - : { - createAndSendCustomEmail: defaultCreateAndSendCustomEmail(this.appInfo), - }; - } } sendEmail = async (input: TypeEmailPasswordEmailDeliveryInput & { userContext: any }) => { @@ -68,16 +43,10 @@ export default class BackwardCompatibilityService user.email = input.user.email; try { if (!this.isInServerlessEnv) { - this.resetPasswordUsingTokenFeature - .createAndSendCustomEmail(user, input.passwordResetLink, input.userContext) - .catch((_) => {}); + createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink).catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - await this.resetPasswordUsingTokenFeature.createAndSendCustomEmail( - user, - input.passwordResetLink, - input.userContext - ); + createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink); } } catch (_) {} }; diff --git a/lib/ts/recipe/emailpassword/passwordResetFunctions.ts b/lib/ts/recipe/emailpassword/passwordResetFunctions.ts index d5671a545..c0a4a1ebe 100644 --- a/lib/ts/recipe/emailpassword/passwordResetFunctions.ts +++ b/lib/ts/recipe/emailpassword/passwordResetFunctions.ts @@ -18,51 +18,53 @@ import { NormalisedAppinfo } from "../../types"; import axios, { AxiosError } from "axios"; import { logDebugMessage } from "../../logger"; -export function createAndSendCustomEmail(appInfo: NormalisedAppinfo) { - return async (user: User, passwordResetURLWithToken: string) => { - // related issue: https://github.com/supertokens/supertokens-node/issues/38 - if (process.env.TEST_MODE === "testing") { - return; +export async function createAndSendEmailUsingSupertokensService( + appInfo: NormalisedAppinfo, + user: User, + passwordResetURLWithToken: string +) { + // related issue: https://github.com/supertokens/supertokens-node/issues/38 + if (process.env.TEST_MODE === "testing") { + return; + } + try { + await axios({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/password/reset", + data: { + email: user.email, + appName: appInfo.appName, + passwordResetURL: passwordResetURLWithToken, + }, + headers: { + "api-version": 0, + }, + }); + logDebugMessage(`Password reset email sent to ${user.email}`); + } catch (error) { + logDebugMessage("Error sending password reset email"); + if (axios.isAxiosError(error)) { + const err = error as AxiosError; + if (err.response) { + logDebugMessage(`Error status: ${err.response.status}`); + logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logDebugMessage(`Error: ${err.message}`); + } + } else { + logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - await axios({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/password/reset", - data: { + logDebugMessage("Logging the input below:"); + logDebugMessage( + JSON.stringify( + { email: user.email, appName: appInfo.appName, passwordResetURL: passwordResetURLWithToken, }, - headers: { - "api-version": 0, - }, - }); - logDebugMessage(`Password reset email sent to ${user.email}`); - } catch (error) { - logDebugMessage("Error sending password reset email"); - if (axios.isAxiosError(error)) { - const err = error as AxiosError; - if (err.response) { - logDebugMessage(`Error status: ${err.response.status}`); - logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logDebugMessage(`Error: ${err.message}`); - } - } else { - logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logDebugMessage("Logging the input below:"); - logDebugMessage( - JSON.stringify( - { - email: user.email, - appName: appInfo.appName, - passwordResetURL: passwordResetURLWithToken, - }, - null, - 2 - ) - ); - } - }; + null, + 2 + ) + ); + } } diff --git a/lib/ts/recipe/emailpassword/utils.ts b/lib/ts/recipe/emailpassword/utils.ts index 96ae19aac..3bee9fa0c 100644 --- a/lib/ts/recipe/emailpassword/utils.ts +++ b/lib/ts/recipe/emailpassword/utils.ts @@ -54,10 +54,8 @@ export function validateAndNormaliseUserInput( let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation which calls our supertokens API + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { emailService = new BackwardCompatibilityService(recipeImpl, appInfo, isInServerlessEnv); diff --git a/lib/ts/recipe/emailverification/emailVerificationFunctions.ts b/lib/ts/recipe/emailverification/emailVerificationFunctions.ts index edc069713..103cd68dd 100644 --- a/lib/ts/recipe/emailverification/emailVerificationFunctions.ts +++ b/lib/ts/recipe/emailverification/emailVerificationFunctions.ts @@ -18,50 +18,52 @@ import { NormalisedAppinfo } from "../../types"; import axios, { AxiosError } from "axios"; import { logDebugMessage } from "../../logger"; -export function createAndSendCustomEmail(appInfo: NormalisedAppinfo) { - return async (user: User, emailVerifyURLWithToken: string) => { - if (process.env.TEST_MODE === "testing") { - return; +export async function createAndSendEmailUsingSupertokensService( + appInfo: NormalisedAppinfo, + user: User, + emailVerifyURLWithToken: string +) { + if (process.env.TEST_MODE === "testing") { + return; + } + try { + await axios({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/email/verify", + data: { + email: user.email, + appName: appInfo.appName, + emailVerifyURL: emailVerifyURLWithToken, + }, + headers: { + "api-version": 0, + }, + }); + logDebugMessage(`Email sent to ${user.email}`); + } catch (error) { + logDebugMessage("Error sending verification email"); + if (axios.isAxiosError(error)) { + const err = error as AxiosError; + if (err.response) { + logDebugMessage(`Error status: ${err.response.status}`); + logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logDebugMessage(`Error: ${err.message}`); + } + } else { + logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - await axios({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/email/verify", - data: { + logDebugMessage("Logging the input below:"); + logDebugMessage( + JSON.stringify( + { email: user.email, appName: appInfo.appName, emailVerifyURL: emailVerifyURLWithToken, }, - headers: { - "api-version": 0, - }, - }); - logDebugMessage(`Email sent to ${user.email}`); - } catch (error) { - logDebugMessage("Error sending verification email"); - if (axios.isAxiosError(error)) { - const err = error as AxiosError; - if (err.response) { - logDebugMessage(`Error status: ${err.response.status}`); - logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logDebugMessage(`Error: ${err.message}`); - } - } else { - logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logDebugMessage("Logging the input below:"); - logDebugMessage( - JSON.stringify( - { - email: user.email, - appName: appInfo.appName, - emailVerifyURL: emailVerifyURLWithToken, - }, - null, - 2 - ) - ); - } - }; + null, + 2 + ) + ); + } } diff --git a/lib/ts/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.ts index c9b55d7aa..7e97fd89f 100644 --- a/lib/ts/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/emailverification/emaildelivery/services/backwardCompatibility/index.ts @@ -12,8 +12,8 @@ * License for the specific language governing permissions and limitations * under the License. */ -import { TypeEmailVerificationEmailDeliveryInput, User } from "../../../types"; -import { createAndSendCustomEmail as defaultCreateAndSendCustomEmail } from "../../../emailVerificationFunctions"; +import { TypeEmailVerificationEmailDeliveryInput } from "../../../types"; +import { createAndSendEmailUsingSupertokensService } from "../../../emailVerificationFunctions"; import { NormalisedAppinfo } from "../../../../../types"; import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery/types"; @@ -21,36 +21,23 @@ export default class BackwardCompatibilityService implements EmailDeliveryInterface { private appInfo: NormalisedAppinfo; private isInServerlessEnv: boolean; - private createAndSendCustomEmail: ( - user: User, - emailVerificationURLWithToken: string, - userContext: any - ) => Promise; - constructor( - appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - createAndSendCustomEmail?: ( - user: User, - emailVerificationURLWithToken: string, - userContext: any - ) => Promise - ) { + constructor(appInfo: NormalisedAppinfo, isInServerlessEnv: boolean) { this.appInfo = appInfo; this.isInServerlessEnv = isInServerlessEnv; - this.createAndSendCustomEmail = - createAndSendCustomEmail === undefined - ? defaultCreateAndSendCustomEmail(this.appInfo) - : createAndSendCustomEmail; } sendEmail = async (input: TypeEmailVerificationEmailDeliveryInput & { userContext: any }) => { try { if (!this.isInServerlessEnv) { - this.createAndSendCustomEmail(input.user, input.emailVerifyLink, input.userContext).catch((_) => {}); + createAndSendEmailUsingSupertokensService( + this.appInfo, + input.user, + input.emailVerifyLink + ).catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - await this.createAndSendCustomEmail(input.user, input.emailVerifyLink, input.userContext); + await createAndSendEmailUsingSupertokensService(this.appInfo, input.user, input.emailVerifyLink); } } catch (_) {} }; diff --git a/lib/ts/recipe/emailverification/utils.ts b/lib/ts/recipe/emailverification/utils.ts index ee27764ea..2758074bd 100644 --- a/lib/ts/recipe/emailverification/utils.ts +++ b/lib/ts/recipe/emailverification/utils.ts @@ -33,10 +33,8 @@ export function validateAndNormaliseUserInput( let emailService = config.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation which calls our supertokens API + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { emailService = new BackwardCompatibilityService(appInfo, isInServerlessEnv); diff --git a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts index 28d81f08e..8dbd998c9 100644 --- a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts @@ -17,115 +17,91 @@ import { EmailDeliveryInterface } from "../../../../../ingredients/emaildelivery import axios, { AxiosError } from "axios"; import { NormalisedAppinfo } from "../../../../../types"; import { logDebugMessage } from "../../../../../logger"; -import { DEFAULT_TENANT_ID } from "../../../../multitenancy/constants"; -function defaultCreateAndSendCustomEmail(appInfo: NormalisedAppinfo) { - return async ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - }, - _: string, - __: any - ): Promise => { - if (process.env.TEST_MODE === "testing") { - return; +async function defaultCreateAndSendCustomEmail(input: { + appInfo: NormalisedAppinfo; + // Where the message should be delivered. + email: string; + // This has to be entered on the starting device to finish sign in/up + userInputCode?: string; + // Full url that the end-user can click to finish sign in/up + urlWithLinkCode?: string; + codeLifetime: number; +}): Promise { + if (process.env.TEST_MODE === "testing") { + return; + } + try { + await axios({ + method: "POST", + url: "https://api.supertokens.io/0/st/auth/passwordless/login", + data: { + email: input.email, + appName: input.appInfo.appName, + codeLifetime: input.codeLifetime, + urlWithLinkCode: input.urlWithLinkCode, + userInputCode: input.userInputCode, + }, + headers: { + "api-version": 0, + }, + }); + logDebugMessage(`Email sent to ${input.email}`); + } catch (error) { + logDebugMessage("Error sending passwordless login email"); + if (axios.isAxiosError(error)) { + const err = error as AxiosError; + if (err.response) { + logDebugMessage(`Error status: ${err.response.status}`); + logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logDebugMessage(`Error: ${err.message}`); + } + } else { + logDebugMessage(`Error: ${JSON.stringify(error)}`); } - try { - await axios({ - method: "POST", - url: "https://api.supertokens.io/0/st/auth/passwordless/login", - data: { + logDebugMessage("Logging the input below:"); + logDebugMessage( + JSON.stringify( + { email: input.email, - appName: appInfo.appName, + appName: input.appInfo.appName, codeLifetime: input.codeLifetime, urlWithLinkCode: input.urlWithLinkCode, userInputCode: input.userInputCode, }, - headers: { - "api-version": 0, - }, - }); - logDebugMessage(`Email sent to ${input.email}`); - } catch (error) { - logDebugMessage("Error sending passwordless login email"); - if (axios.isAxiosError(error)) { - const err = error as AxiosError; - if (err.response) { - logDebugMessage(`Error status: ${err.response.status}`); - logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logDebugMessage(`Error: ${err.message}`); - } - } else { - logDebugMessage(`Error: ${JSON.stringify(error)}`); - } - logDebugMessage("Logging the input below:"); - logDebugMessage( - JSON.stringify( - { - email: input.email, - appName: appInfo.appName, - codeLifetime: input.codeLifetime, - urlWithLinkCode: input.urlWithLinkCode, - userInputCode: input.userInputCode, - }, - null, - 2 - ) - ); - /** - * if the error is thrown from API, the response object - * will be of type `{err: string}` - */ - if (axios.isAxiosError(error) && error.response !== undefined) { - if (error.response.data.err !== undefined) { - throw Error(error.response.data.err); - } + null, + 2 + ) + ); + /** + * if the error is thrown from API, the response object + * will be of type `{err: string}` + */ + if (axios.isAxiosError(error) && error.response !== undefined) { + if (error.response.data.err !== undefined) { + throw Error(error.response.data.err); } - throw error; } - }; + throw error; + } } export default class BackwardCompatibilityService implements EmailDeliveryInterface { - private createAndSendCustomEmail: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; + private appInfo: NormalisedAppinfo; constructor(appInfo: NormalisedAppinfo) { - this.createAndSendCustomEmail = defaultCreateAndSendCustomEmail(appInfo); + this.appInfo = appInfo; } sendEmail = async (input: TypePasswordlessEmailDeliveryInput & { userContext: any }) => { - await this.createAndSendCustomEmail( - { - email: input.email, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - preAuthSessionId: input.preAuthSessionId, - codeLifetime: input.codeLifetime, - }, - input.tenantId === undefined ? DEFAULT_TENANT_ID : input.tenantId, - input.userContext - ); + await defaultCreateAndSendCustomEmail({ + appInfo: this.appInfo, + email: input.email, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, + }); }; } diff --git a/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts index af608e4e3..ee875a388 100644 --- a/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/passwordless/smsdelivery/services/backwardCompatibility/index.ts @@ -14,143 +14,112 @@ */ import { TypePasswordlessSmsDeliveryInput } from "../../../types"; import { SmsDeliveryInterface } from "../../../../../ingredients/smsdelivery/types"; -import { NormalisedAppinfo } from "../../../../../types"; import axios, { AxiosError } from "axios"; import { SUPERTOKENS_SMS_SERVICE_URL } from "../../../../../ingredients/smsdelivery/services/supertokens"; import Supertokens from "../../../../../supertokens"; import { logDebugMessage } from "../../../../../logger"; -import { DEFAULT_TENANT_ID } from "../../../../multitenancy/constants"; -function defaultCreateAndSendCustomSms(_: NormalisedAppinfo) { - return async ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - }, - _: string, - __: any - ): Promise => { - let supertokens = Supertokens.getInstanceOrThrowError(); - let appName = supertokens.appInfo.appName; - try { - await axios({ - method: "post", - url: SUPERTOKENS_SMS_SERVICE_URL, - data: { - smsInput: { - appName, - type: "PASSWORDLESS_LOGIN", - phoneNumber: input.phoneNumber, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - codeLifetime: input.codeLifetime, - }, +async function createAndSendSmsUsingSupertokensService(input: { + // Where the message should be delivered. + phoneNumber: string; + // This has to be entered on the starting device to finish sign in/up + userInputCode?: string; + // Full url that the end-user can click to finish sign in/up + urlWithLinkCode?: string; + codeLifetime: number; +}): Promise { + let supertokens = Supertokens.getInstanceOrThrowError(); + let appName = supertokens.appInfo.appName; + try { + await axios({ + method: "post", + url: SUPERTOKENS_SMS_SERVICE_URL, + data: { + smsInput: { + appName, + type: "PASSWORDLESS_LOGIN", + phoneNumber: input.phoneNumber, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, }, - headers: { - "api-version": "0", - }, - }); - logDebugMessage(`Passwordless login SMS sent to ${input.phoneNumber}`); - return; - } catch (error) { - logDebugMessage("Error sending passwordless login SMS"); - if (axios.isAxiosError(error)) { - const err = error as AxiosError; - if (err.response) { - logDebugMessage(`Error status: ${err.response.status}`); - logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); - } else { - logDebugMessage(`Error: ${err.message}`); - } - if (err.response) { - if (err.response.status !== 429) { - /** - * if the error is thrown from API, the response object - * will be of type `{err: string}` - */ - if (err.response.data.err !== undefined) { - throw Error(err.response.data.err); - } else { - throw err; - } + }, + headers: { + "api-version": "0", + }, + }); + logDebugMessage(`Passwordless login SMS sent to ${input.phoneNumber}`); + return; + } catch (error) { + logDebugMessage("Error sending passwordless login SMS"); + if (axios.isAxiosError(error)) { + const err = error as AxiosError; + if (err.response) { + logDebugMessage(`Error status: ${err.response.status}`); + logDebugMessage(`Error response: ${JSON.stringify(err.response.data)}`); + } else { + logDebugMessage(`Error: ${err.message}`); + } + if (err.response) { + if (err.response.status !== 429) { + /** + * if the error is thrown from API, the response object + * will be of type `{err: string}` + */ + if (err.response.data.err !== undefined) { + throw Error(err.response.data.err); + } else { + throw err; } - } else { - throw err; } } else { - logDebugMessage(`Error: ${JSON.stringify(error)}`); - throw error; + throw err; } + } else { + logDebugMessage(`Error: ${JSON.stringify(error)}`); + throw error; } - console.log( - "Free daily SMS quota reached. If you want to use SuperTokens to send SMS, please sign up on supertokens.com to get your SMS API key, else you can also define your own method by overriding the service. For now, we are logging it below:" - ); - /** - * if we do console.log(`SMS content: ${input}`); - * Output would be: - * SMS content: [object Object] - */ - /** - * JSON.stringify takes 3 inputs - * - value: usually an object or array, to be converted - * - replacer: An array of strings and numbers that acts - * as an approved list for selecting the object - * properties that will be stringified - * - space: Adds indentation, white space, and line break characters - * to the return-value JSON text to make it easier to read - * - * console.log(JSON.stringify({"a": 1, "b": 2})) - * Output: - * {"a":1,"b":2} - * - * console.log(JSON.stringify({"a": 1, "b": 2}, null, 2)) - * Output: - * { - * "a": 1, - * "b": 2 - * } - */ - console.log(`\nSMS content: ${JSON.stringify(input, null, 2)}`); - }; + } + console.log( + "Free daily SMS quota reached. If you want to use SuperTokens to send SMS, please sign up on supertokens.com to get your SMS API key, else you can also define your own method by overriding the service. For now, we are logging it below:" + ); + /** + * if we do console.log(`SMS content: ${input}`); + * Output would be: + * SMS content: [object Object] + */ + /** + * JSON.stringify takes 3 inputs + * - value: usually an object or array, to be converted + * - replacer: An array of strings and numbers that acts + * as an approved list for selecting the object + * properties that will be stringified + * - space: Adds indentation, white space, and line break characters + * to the return-value JSON text to make it easier to read + * + * console.log(JSON.stringify({"a": 1, "b": 2})) + * Output: + * {"a":1,"b":2} + * + * console.log(JSON.stringify({"a": 1, "b": 2}, null, 2)) + * Output: + * { + * "a": 1, + * "b": 2 + * } + */ + console.log(`\nSMS content: ${JSON.stringify(input, null, 2)}`); } export default class BackwardCompatibilityService implements SmsDeliveryInterface { - private createAndSendCustomSms: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; - - constructor(appInfo: NormalisedAppinfo) { - this.createAndSendCustomSms = defaultCreateAndSendCustomSms(appInfo); - } + constructor() {} sendSms = async (input: TypePasswordlessSmsDeliveryInput & { userContext: any }) => { - await this.createAndSendCustomSms( - { - phoneNumber: input.phoneNumber, - userInputCode: input.userInputCode, - urlWithLinkCode: input.urlWithLinkCode, - preAuthSessionId: input.preAuthSessionId, - codeLifetime: input.codeLifetime, - }, - input.tenantId === undefined ? DEFAULT_TENANT_ID : input.tenantId, - input.userContext - ); + await createAndSendSmsUsingSupertokensService({ + phoneNumber: input.phoneNumber, + userInputCode: input.userInputCode, + urlWithLinkCode: input.urlWithLinkCode, + codeLifetime: input.codeLifetime, + }); }; } diff --git a/lib/ts/recipe/passwordless/utils.ts b/lib/ts/recipe/passwordless/utils.ts index 223c5ff4b..78b403997 100644 --- a/lib/ts/recipe/passwordless/utils.ts +++ b/lib/ts/recipe/passwordless/utils.ts @@ -48,10 +48,8 @@ export function validateAndNormaliseUserInput( /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new BackwardCompatibilityEmailService(appInfo); @@ -85,7 +83,7 @@ export function validateAndNormaliseUserInput( * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new BackwardCompatibilitySmsService(appInfo); + smsService = new BackwardCompatibilitySmsService(); } let smsDelivery = { ...config.smsDelivery, diff --git a/lib/ts/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.ts index e6c6f07b1..c585bcb58 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/emaildelivery/services/backwardCompatibility/index.ts @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -import { TypeThirdPartyEmailPasswordEmailDeliveryInput, User } from "../../../types"; +import { TypeThirdPartyEmailPasswordEmailDeliveryInput } from "../../../types"; import { RecipeInterface as EmailPasswordRecipeInterface } from "../../../../emailpassword"; import { NormalisedAppinfo } from "../../../../../types"; import EmailPasswordBackwardCompatibilityService from "../../../../emailpassword/emaildelivery/services/backwardCompatibility"; @@ -25,21 +25,13 @@ export default class BackwardCompatibilityService constructor( emailPasswordRecipeInterfaceImpl: EmailPasswordRecipeInterface, appInfo: NormalisedAppinfo, - isInServerlessEnv: boolean, - resetPasswordUsingTokenFeature?: { - createAndSendCustomEmail?: ( - user: User, - passwordResetURLWithToken: string, - userContext: any - ) => Promise; - } + isInServerlessEnv: boolean ) { { this.emailPasswordBackwardCompatibilityService = new EmailPasswordBackwardCompatibilityService( emailPasswordRecipeInterfaceImpl, appInfo, - isInServerlessEnv, - resetPasswordUsingTokenFeature + isInServerlessEnv ); } } diff --git a/lib/ts/recipe/thirdpartyemailpassword/utils.ts b/lib/ts/recipe/thirdpartyemailpassword/utils.ts index b27c6239d..6e19ec545 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/utils.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/utils.ts @@ -45,10 +45,8 @@ export function validateAndNormaliseUserInput( let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new BackwardCompatibilityService(emailPasswordRecipeImpl, appInfo, isInServerlessEnv); diff --git a/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts index c0a8b2e30..7ccb6646a 100644 --- a/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/thirdpartypasswordless/smsdelivery/services/backwardCompatibility/index.ts @@ -14,15 +14,14 @@ */ import { TypeThirdPartyPasswordlessSmsDeliveryInput } from "../../../types"; import { SmsDeliveryInterface } from "../../../../../ingredients/smsdelivery/types"; -import { NormalisedAppinfo } from "../../../../../types"; import PasswordlessBackwardCompatibilityService from "../../../../passwordless/smsdelivery/services/backwardCompatibility"; export default class BackwardCompatibilityService implements SmsDeliveryInterface { private passwordlessBackwardCompatibilityService: PasswordlessBackwardCompatibilityService; - constructor(appInfo: NormalisedAppinfo) { - this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService(appInfo); + constructor() { + this.passwordlessBackwardCompatibilityService = new PasswordlessBackwardCompatibilityService(); } sendSms = async (input: TypeThirdPartyPasswordlessSmsDeliveryInput & { userContext: any }) => { diff --git a/lib/ts/recipe/thirdpartypasswordless/types.ts b/lib/ts/recipe/thirdpartypasswordless/types.ts index 0be408b0c..2ab87b256 100644 --- a/lib/ts/recipe/thirdpartypasswordless/types.ts +++ b/lib/ts/recipe/thirdpartypasswordless/types.ts @@ -67,98 +67,14 @@ export type TypeInput = ( phoneNumber: string, tenantId: string ) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } | { contactMethod: "EMAIL"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } | { contactMethod: "EMAIL_OR_PHONE"; validateEmailAddress?: (email: string, tenantId: string) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use emailDelivery config instead - */ - createAndSendCustomEmail?: ( - input: { - // Where the message should be delivered. - email: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; - validatePhoneNumber?: ( - phoneNumber: string, - tenantId: string - ) => Promise | string | undefined; - - // Override to use custom template/contact method - /** - * @deprecated Please use smsDelivery config instead - */ - createAndSendCustomTextMessage?: ( - input: { - // Where the message should be delivered. - phoneNumber: string; - // This has to be entered on the starting device to finish sign in/up - userInputCode?: string; - // Full url that the end-user can click to finish sign in/up - urlWithLinkCode?: string; - codeLifetime: number; - // Unlikely, but someone could display this (or a derived thing) to identify the device - preAuthSessionId: string; - }, - tenantId: string, - userContext: any - ) => Promise; } ) & { /** diff --git a/lib/ts/recipe/thirdpartypasswordless/utils.ts b/lib/ts/recipe/thirdpartypasswordless/utils.ts index 820705c22..e0277a13f 100644 --- a/lib/ts/recipe/thirdpartypasswordless/utils.ts +++ b/lib/ts/recipe/thirdpartypasswordless/utils.ts @@ -32,10 +32,8 @@ export function validateAndNormaliseUserInput(appInfo: NormalisedAppinfo, config let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we - * use the createAndSendCustomEmail config. If the user - * has not passed even that config, we use the default - * createAndSendCustomEmail implementation + * if user has not passed emailDelivery config, we use the default + * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { emailService = new BackwardCompatibilityEmailService(appInfo); @@ -67,7 +65,7 @@ export function validateAndNormaliseUserInput(appInfo: NormalisedAppinfo, config * createAndSendCustomTextMessage implementation */ if (smsService === undefined) { - smsService = new BackwardCompatibilitySmsService(appInfo); + smsService = new BackwardCompatibilitySmsService(); } return { ...config?.smsDelivery, From e3ec4b37856b7e5c8b799acf7bfc43dd183a9aa1 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 7 Jul 2023 18:00:42 +0530 Subject: [PATCH 09/14] fix: minor --- .../emaildelivery/services/backwardCompatibility/index.js | 2 +- .../emaildelivery/services/backwardCompatibility/index.js | 4 ++-- .../emaildelivery/services/backwardCompatibility/index.ts | 2 +- .../emaildelivery/services/backwardCompatibility/index.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js index fcefa7e29..6cd37e689 100644 --- a/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.js @@ -54,7 +54,7 @@ class BackwardCompatibilityService { .catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - passwordResetFunctions_1.createAndSendEmailUsingSupertokensService( + yield passwordResetFunctions_1.createAndSendEmailUsingSupertokensService( this.appInfo, user, input.passwordResetLink diff --git a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js index e50e3e150..884d2db11 100644 --- a/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js +++ b/lib/build/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.js @@ -38,7 +38,7 @@ var __importDefault = Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const logger_1 = require("../../../../../logger"); -function defaultCreateAndSendCustomEmail(input) { +function createAndSendEmailUsingSupertokensService(input) { return __awaiter(this, void 0, void 0, function* () { if (process.env.TEST_MODE === "testing") { return; @@ -103,7 +103,7 @@ class BackwardCompatibilityService { constructor(appInfo) { this.sendEmail = (input) => __awaiter(this, void 0, void 0, function* () { - yield defaultCreateAndSendCustomEmail({ + yield createAndSendEmailUsingSupertokensService({ appInfo: this.appInfo, email: input.email, userInputCode: input.userInputCode, diff --git a/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts index c841a0443..ef38911fd 100644 --- a/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/emailpassword/emaildelivery/services/backwardCompatibility/index.ts @@ -46,7 +46,7 @@ export default class BackwardCompatibilityService createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink).catch((_) => {}); } else { // see https://github.com/supertokens/supertokens-node/pull/135 - createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink); + await createAndSendEmailUsingSupertokensService(this.appInfo, user, input.passwordResetLink); } } catch (_) {} }; diff --git a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts index 8dbd998c9..ae3da2c7a 100644 --- a/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts +++ b/lib/ts/recipe/passwordless/emaildelivery/services/backwardCompatibility/index.ts @@ -18,7 +18,7 @@ import axios, { AxiosError } from "axios"; import { NormalisedAppinfo } from "../../../../../types"; import { logDebugMessage } from "../../../../../logger"; -async function defaultCreateAndSendCustomEmail(input: { +async function createAndSendEmailUsingSupertokensService(input: { appInfo: NormalisedAppinfo; // Where the message should be delivered. email: string; @@ -96,7 +96,7 @@ export default class BackwardCompatibilityService } sendEmail = async (input: TypePasswordlessEmailDeliveryInput & { userContext: any }) => { - await defaultCreateAndSendCustomEmail({ + await createAndSendEmailUsingSupertokensService({ appInfo: this.appInfo, email: input.email, userInputCode: input.userInputCode, From bdc06e3252e059acb967b7cc23bd4a82e67be5b8 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 7 Jul 2023 18:09:56 +0530 Subject: [PATCH 10/14] Update lib/ts/recipe/emailpassword/utils.ts --- lib/ts/recipe/emailpassword/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/emailpassword/utils.ts b/lib/ts/recipe/emailpassword/utils.ts index 3bee9fa0c..47c02c934 100644 --- a/lib/ts/recipe/emailpassword/utils.ts +++ b/lib/ts/recipe/emailpassword/utils.ts @@ -54,7 +54,7 @@ export function validateAndNormaliseUserInput( let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we use the default + * if user has not passed emailService config, we use the default * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { From a44150184c4c0143e787411643611f0b6882348a Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 7 Jul 2023 18:10:07 +0530 Subject: [PATCH 11/14] Update lib/ts/recipe/emailverification/utils.ts --- lib/ts/recipe/emailverification/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/emailverification/utils.ts b/lib/ts/recipe/emailverification/utils.ts index 2758074bd..83c4441e9 100644 --- a/lib/ts/recipe/emailverification/utils.ts +++ b/lib/ts/recipe/emailverification/utils.ts @@ -33,7 +33,7 @@ export function validateAndNormaliseUserInput( let emailService = config.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we use the default + * if user has not passed emailService config, we use the default * createAndSendEmailUsingSupertokensService implementation which calls our supertokens API */ if (emailService === undefined) { From 8753ce60d2107054adc8a6bad27d6492f756c0a3 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 7 Jul 2023 18:10:14 +0530 Subject: [PATCH 12/14] Update lib/ts/recipe/passwordless/utils.ts --- lib/ts/recipe/passwordless/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/passwordless/utils.ts b/lib/ts/recipe/passwordless/utils.ts index 78b403997..06dceaa20 100644 --- a/lib/ts/recipe/passwordless/utils.ts +++ b/lib/ts/recipe/passwordless/utils.ts @@ -48,7 +48,7 @@ export function validateAndNormaliseUserInput( /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we use the default + * if user has not passed emailService config, we use the default * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { From 5c7e538ccfbce802ffb502eda4de960afc784305 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 7 Jul 2023 18:10:22 +0530 Subject: [PATCH 13/14] Update lib/ts/recipe/thirdpartyemailpassword/utils.ts --- lib/ts/recipe/thirdpartyemailpassword/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/thirdpartyemailpassword/utils.ts b/lib/ts/recipe/thirdpartyemailpassword/utils.ts index 6e19ec545..d23f86134 100644 --- a/lib/ts/recipe/thirdpartyemailpassword/utils.ts +++ b/lib/ts/recipe/thirdpartyemailpassword/utils.ts @@ -45,7 +45,7 @@ export function validateAndNormaliseUserInput( let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we use the default + * if user has not passed emailService config, we use the default * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) { From 83f3cf790b78fffb7a40c3b8fa1dc16a8c140b87 Mon Sep 17 00:00:00 2001 From: Rishabh Poddar Date: Fri, 7 Jul 2023 18:10:52 +0530 Subject: [PATCH 14/14] Update lib/ts/recipe/thirdpartypasswordless/utils.ts --- lib/ts/recipe/thirdpartypasswordless/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ts/recipe/thirdpartypasswordless/utils.ts b/lib/ts/recipe/thirdpartypasswordless/utils.ts index e0277a13f..50a1d2e9b 100644 --- a/lib/ts/recipe/thirdpartypasswordless/utils.ts +++ b/lib/ts/recipe/thirdpartypasswordless/utils.ts @@ -32,7 +32,7 @@ export function validateAndNormaliseUserInput(appInfo: NormalisedAppinfo, config let emailService = config?.emailDelivery?.service; /** * following code is for backward compatibility. - * if user has not passed emailDelivery config, we use the default + * if user has not passed emailService config, we use the default * createAndSendEmailUsingSupertokensService implementation */ if (emailService === undefined) {