From 6a2450af1a809c1a47ec3f67b1f89f3c3b3d3c40 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 11:27:49 +0530 Subject: [PATCH 01/12] Add API type definition for updating user details (name) --- lib/build/recipe/usermetadata/types.d.ts | 25 ++++++++++++++++++++++-- lib/ts/recipe/usermetadata/types.ts | 25 ++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/build/recipe/usermetadata/types.d.ts b/lib/build/recipe/usermetadata/types.d.ts index 8dd434ac7..ee92a6ed9 100644 --- a/lib/build/recipe/usermetadata/types.d.ts +++ b/lib/build/recipe/usermetadata/types.d.ts @@ -1,6 +1,7 @@ // @ts-nocheck import OverrideableBuilder from "supertokens-js-override"; -import { JSONObject, UserContext } from "../../types"; +import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; +import { SessionContainerInterface } from "../session/types"; export declare type TypeInput = { override?: { functions?: ( @@ -19,7 +20,27 @@ export declare type TypeNormalisedInput = { apis: (originalImplementation: APIInterface, builder?: OverrideableBuilder) => APIInterface; }; }; -export declare type APIInterface = {}; +export declare type APIInterface = { + updateUserDetailsPOST?: (input: { + session: SessionContainerInterface; + details: { + name?: string; + }; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + details: { + name: string | undefined; + }; + } + | { + status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; +}; export declare type RecipeInterface = { getUserMetadata: (input: { userId: string; diff --git a/lib/ts/recipe/usermetadata/types.ts b/lib/ts/recipe/usermetadata/types.ts index 590267b4f..9067b0e23 100644 --- a/lib/ts/recipe/usermetadata/types.ts +++ b/lib/ts/recipe/usermetadata/types.ts @@ -14,7 +14,8 @@ */ import OverrideableBuilder from "supertokens-js-override"; -import { JSONObject, UserContext } from "../../types"; +import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; +import { SessionContainerInterface } from "../session/types"; export type TypeInput = { override?: { @@ -36,7 +37,27 @@ export type TypeNormalisedInput = { }; }; -export type APIInterface = {}; +export type APIInterface = { + updateUserDetailsPOST?: (input: { + session: SessionContainerInterface; + details: { + name?: string; + }; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + details: { + name: string | undefined; + }; + } + | { + status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >; +}; export type RecipeInterface = { getUserMetadata: (input: { From 224c0d21806c23594174f39d8024dd00eee88160 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 12:20:33 +0530 Subject: [PATCH 02/12] Add API type definitions for phone/email related user details --- lib/build/recipe/usermetadata/types.d.ts | 136 +++++++++++++++++++++ lib/ts/recipe/usermetadata/types.ts | 145 +++++++++++++++++++++++ 2 files changed, 281 insertions(+) diff --git a/lib/build/recipe/usermetadata/types.d.ts b/lib/build/recipe/usermetadata/types.d.ts index ee92a6ed9..de81c77ce 100644 --- a/lib/build/recipe/usermetadata/types.d.ts +++ b/lib/build/recipe/usermetadata/types.d.ts @@ -1,4 +1,5 @@ // @ts-nocheck +import { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; import { SessionContainerInterface } from "../session/types"; @@ -20,12 +21,21 @@ export declare type TypeNormalisedInput = { apis: (originalImplementation: APIInterface, builder?: OverrideableBuilder) => APIInterface; }; }; +export declare type APIOptions = { + recipeImplementation: RecipeInterface; + config: TypeNormalisedInput; + recipeId: string; + isInServerlessEnv: boolean; + req: BaseRequest; + res: BaseResponse; +}; export declare type APIInterface = { updateUserDetailsPOST?: (input: { session: SessionContainerInterface; details: { name?: string; }; + options: APIOptions; userContext: UserContext; }) => Promise< | { @@ -40,6 +50,132 @@ export declare type APIInterface = { } | GeneralErrorResponse >; + userEmailsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + emails: Array<{ + id: string; + isVerified: boolean; + isPrimary: boolean; + }>; + } + | GeneralErrorResponse + >; + addEmailForUserPOST?: (input: { + email: { + id: string; + isVerified?: boolean; + isPrimary?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; + reason: string; + } + | GeneralErrorResponse + >; + updateEmailForUserPATCH?: (input: { + emailId: string; + details: { + isVerified?: boolean; + isPrimary?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; + reason: string; + } + | GeneralErrorResponse + >; + removeEmailForUserDELETE?: ( + emailId: string, + session: SessionContainerInterface, + options: APIOptions, + userContext: UserContext + ) => Promise< + | { + status: "OK"; + email: { + id: string; + isVerified: boolean; + isPrimary: boolean; + }; + } + | { + status: "AT_LEAST_ONE_VERIFIED_EMAIL_IS_REQUIRED"; + reason: string; + } + | GeneralErrorResponse + >; + userPhoneNumbersGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + phones: Array<{ + number: string; + isVerified: boolean; + }>; + } + | GeneralErrorResponse + >; + addPhoneNumberForUserPOST?: (input: { + phone: { + number: string; + isVerified?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + updatePhoneNumberForUserPATCH?: (input: { + phoneNumber: string; + details: { + isVerified?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + removePhoneNumberForUserDELETE?: ( + phoneNumber: string, + session: SessionContainerInterface, + options: APIOptions, + userContext: UserContext + ) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; }; export declare type RecipeInterface = { getUserMetadata: (input: { diff --git a/lib/ts/recipe/usermetadata/types.ts b/lib/ts/recipe/usermetadata/types.ts index 9067b0e23..77ac1b7aa 100644 --- a/lib/ts/recipe/usermetadata/types.ts +++ b/lib/ts/recipe/usermetadata/types.ts @@ -13,6 +13,7 @@ * under the License. */ +import { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; import { SessionContainerInterface } from "../session/types"; @@ -37,12 +38,22 @@ export type TypeNormalisedInput = { }; }; +export type APIOptions = { + recipeImplementation: RecipeInterface; + config: TypeNormalisedInput; + recipeId: string; + isInServerlessEnv: boolean; + req: BaseRequest; + res: BaseResponse; +}; + export type APIInterface = { updateUserDetailsPOST?: (input: { session: SessionContainerInterface; details: { name?: string; }; + options: APIOptions; userContext: UserContext; }) => Promise< | { @@ -57,6 +68,140 @@ export type APIInterface = { } | GeneralErrorResponse >; + + userEmailsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + emails: Array<{ + id: string; + isVerified: boolean; + isPrimary: boolean; + }>; + } + | GeneralErrorResponse + >; + + addEmailForUserPOST?: (input: { + email: { + id: string; + isVerified?: boolean; + isPrimary?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; + reason: string; + } + | GeneralErrorResponse + >; + + updateEmailForUserPATCH?: (input: { + emailId: string; + details: { + isVerified?: boolean; + isPrimary?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; + reason: string; + } + | GeneralErrorResponse + >; + + removeEmailForUserDELETE?: ( + emailId: string, + session: SessionContainerInterface, + options: APIOptions, + userContext: UserContext + ) => Promise< + | { + status: "OK"; + email: { + id: string; + isVerified: boolean; + isPrimary: boolean; + }; + } + | { + status: "AT_LEAST_ONE_VERIFIED_EMAIL_IS_REQUIRED"; + reason: string; + } + | GeneralErrorResponse + >; + + userPhoneNumbersGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + phones: Array<{ + number: string; + isVerified: boolean; + }>; + } + | GeneralErrorResponse + >; + + addPhoneNumberForUserPOST?: (input: { + phone: { + number: string; + isVerified?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + + updatePhoneNumberForUserPATCH?: (input: { + phoneNumber: string; + details: { + isVerified?: boolean; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + + removePhoneNumberForUserDELETE?: ( + phoneNumber: string, + session: SessionContainerInterface, + options: APIOptions, + userContext: UserContext + ) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; }; export type RecipeInterface = { From c5c4a8891acae15db226b51eeedb7125e451d5b0 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 12:33:37 +0530 Subject: [PATCH 03/12] Add API type definitions for getting connected accounts and removing them --- lib/build/recipe/thirdparty/types.d.ts | 23 +++++++++++++++++++++++ lib/ts/recipe/thirdparty/types.ts | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/lib/build/recipe/thirdparty/types.d.ts b/lib/build/recipe/thirdparty/types.d.ts index 8d0198e3b..56436c3a2 100644 --- a/lib/build/recipe/thirdparty/types.d.ts +++ b/lib/build/recipe/thirdparty/types.d.ts @@ -330,5 +330,28 @@ export declare type APIInterface = { options: APIOptions; userContext: UserContext; }) => Promise); + connectedAccountsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + }) => Promise< + | { + status: "OK"; + accounts: { + id: string; + userId: string; + }[]; + } + | GeneralErrorResponse + >; + removeAccountDELETE?: (input: { + session: SessionContainerInterface; + options: APIOptions; + }) => Promise< + | { + status: "OK"; + wasDeleted: boolean; + } + | GeneralErrorResponse + >; }; export {}; diff --git a/lib/ts/recipe/thirdparty/types.ts b/lib/ts/recipe/thirdparty/types.ts index 71e9847d3..f1b91f6cd 100644 --- a/lib/ts/recipe/thirdparty/types.ts +++ b/lib/ts/recipe/thirdparty/types.ts @@ -316,4 +316,29 @@ export type APIInterface = { options: APIOptions; userContext: UserContext; }) => Promise); + + connectedAccountsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + }) => Promise< + | { + status: "OK"; + accounts: { + id: string; + userId: string; + }[]; + } + | GeneralErrorResponse + >; + + removeAccountDELETE?: (input: { + session: SessionContainerInterface; + options: APIOptions; + }) => Promise< + | { + status: "OK"; + wasDeleted: boolean; + } + | GeneralErrorResponse + >; }; From 3f4d86d68722e63e090083e9ee5558080525a8a7 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 12:44:18 +0530 Subject: [PATCH 04/12] Add password related API type definitions --- lib/build/recipe/emailpassword/types.d.ts | 35 +++++++++++++++++++++++ lib/build/recipe/thirdparty/types.d.ts | 1 + lib/ts/recipe/emailpassword/types.ts | 34 ++++++++++++++++++++++ lib/ts/recipe/thirdparty/types.ts | 1 + 4 files changed, 71 insertions(+) diff --git a/lib/build/recipe/emailpassword/types.d.ts b/lib/build/recipe/emailpassword/types.d.ts index fa3eb1408..94d655389 100644 --- a/lib/build/recipe/emailpassword/types.d.ts +++ b/lib/build/recipe/emailpassword/types.d.ts @@ -322,6 +322,41 @@ export declare type APIInterface = { } | GeneralErrorResponse >); + passwordStateGET?: (input: { + email: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >; + updatePasswordPOST?: (input: { + details: { + email: string; + newPassword: string; + oldPassword?: string; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "OLD_PASSWORD_IS_REQUIRED_FOR_VERIFICATION"; + reason: string; + } + | { + status: "PASSWORD_POLICY_VIOLATED_ERROR"; + failureReason: string; + } + | GeneralErrorResponse + >; }; export declare type TypeEmailPasswordPasswordResetEmailDeliveryInput = { type: "PASSWORD_RESET"; diff --git a/lib/build/recipe/thirdparty/types.d.ts b/lib/build/recipe/thirdparty/types.d.ts index 56436c3a2..2e38a977d 100644 --- a/lib/build/recipe/thirdparty/types.d.ts +++ b/lib/build/recipe/thirdparty/types.d.ts @@ -344,6 +344,7 @@ export declare type APIInterface = { | GeneralErrorResponse >; removeAccountDELETE?: (input: { + id: string; session: SessionContainerInterface; options: APIOptions; }) => Promise< diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index 0fdfbe088..39ad2dfe6 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -325,6 +325,40 @@ export type APIInterface = { } | GeneralErrorResponse >); + + passwordStateGET?: (input: { + email: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + exists: boolean; + } + | GeneralErrorResponse + >; + + updatePasswordPOST?: (input: { + details: { + email: string; + newPassword: string; + oldPassword?: string; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "OLD_PASSWORD_IS_REQUIRED_FOR_VERIFICATION"; + reason: string; + } + | { status: "PASSWORD_POLICY_VIOLATED_ERROR"; failureReason: string } + | GeneralErrorResponse + >; }; export type TypeEmailPasswordPasswordResetEmailDeliveryInput = { diff --git a/lib/ts/recipe/thirdparty/types.ts b/lib/ts/recipe/thirdparty/types.ts index f1b91f6cd..62ea24b1a 100644 --- a/lib/ts/recipe/thirdparty/types.ts +++ b/lib/ts/recipe/thirdparty/types.ts @@ -332,6 +332,7 @@ export type APIInterface = { >; removeAccountDELETE?: (input: { + id: string; session: SessionContainerInterface; options: APIOptions; }) => Promise< From ab7ea52d428d7de7917ccd36e559ebe221fc33fa Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 12:53:44 +0530 Subject: [PATCH 05/12] Add API type definitions for session related functions --- lib/build/recipe/session/types.d.ts | 34 ++++++++++++++++++++++++++ lib/ts/recipe/session/types.ts | 37 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/lib/build/recipe/session/types.d.ts b/lib/build/recipe/session/types.d.ts index b573925ed..89950bfa8 100644 --- a/lib/build/recipe/session/types.d.ts +++ b/lib/build/recipe/session/types.d.ts @@ -323,6 +323,40 @@ export declare type APIInterface = { } | GeneralErrorResponse >); + allSessionsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessions: SessionInformation[]; + } + | GeneralErrorResponse + >; + revokeAllSessionsPOST?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessionRemoveCount: number; + } + | GeneralErrorResponse + >; + revokeSessionPOST?: (input: { + sessionHandle: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + wasRemoved: boolean; + } + | GeneralErrorResponse + >; verifySession(input: { verifySessionOptions: VerifySessionOptions | undefined; options: APIOptions; diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index accd318bc..9cfc67459 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -394,6 +394,43 @@ export type APIInterface = { | GeneralErrorResponse >); + allSessionsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessions: SessionInformation[]; + } + | GeneralErrorResponse + >; + + revokeAllSessionsPOST?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessionRemoveCount: number; + } + | GeneralErrorResponse + >; + + revokeSessionPOST?: (input: { + sessionHandle: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + wasRemoved: boolean; + } + | GeneralErrorResponse + >; + verifySession(input: { verifySessionOptions: VerifySessionOptions | undefined; options: APIOptions; From 1aeb9fec863f6a070eba119b130420352c60a143 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 13:09:09 +0530 Subject: [PATCH 06/12] Add multifactor related API type definitions --- lib/build/recipe/multifactorauth/types.d.ts | 55 +++++++++++++++++++ lib/ts/recipe/multifactorauth/types.ts | 59 +++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/lib/build/recipe/multifactorauth/types.d.ts b/lib/build/recipe/multifactorauth/types.d.ts index 53f7ac093..c492a2946 100644 --- a/lib/build/recipe/multifactorauth/types.d.ts +++ b/lib/build/recipe/multifactorauth/types.d.ts @@ -106,6 +106,61 @@ export declare type APIInterface = { } | GeneralErrorResponse >); + factorsSetupForUserGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + factors: { + id: string; + details: JSONObject; + }[]; + backupCodes: string[] | undefined; + } + | GeneralErrorResponse + >; + addFactorForUserPOST?: (input: { + factor: { + id: string; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + backupCodes: string[]; + } + | GeneralErrorResponse + >; + deleteFactorForUserDELETE?: (input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + regenerateBackupCodesPOST?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + backupCodes: string[]; + } + | { + status: "NO_FACTORS_ARE_SETUP"; + reason: string; + } + | GeneralErrorResponse + >; }; export declare type GetFactorsSetupForUserFromOtherRecipesFunc = ( user: User, diff --git a/lib/ts/recipe/multifactorauth/types.ts b/lib/ts/recipe/multifactorauth/types.ts index a7e340662..3f68a5ec7 100644 --- a/lib/ts/recipe/multifactorauth/types.ts +++ b/lib/ts/recipe/multifactorauth/types.ts @@ -135,6 +135,65 @@ export type APIInterface = { } | GeneralErrorResponse >); + + factorsSetupForUserGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + factors: { + id: string; + details: JSONObject; + }[]; + backupCodes: string[] | undefined; + } + | GeneralErrorResponse + >; + + addFactorForUserPOST?: (input: { + factor: { + id: string; + }; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + backupCodes: string[]; + } + | GeneralErrorResponse + >; + + deleteFactorForUserDELETE?: (input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >; + + regenerateBackupCodesPOST?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + backupCodes: string[]; + } + | { + status: "NO_FACTORS_ARE_SETUP"; + reason: string; + } + | GeneralErrorResponse + >; }; export type GetFactorsSetupForUserFromOtherRecipesFunc = (user: User, userContext: UserContext) => Promise; From 24cd569c5bbf0f0d5fec5bc15ced9eb1f349b8f2 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 13:13:04 +0530 Subject: [PATCH 07/12] Rename interface function name for regenerating backup codes --- lib/build/recipe/multifactorauth/types.d.ts | 2 +- lib/ts/recipe/multifactorauth/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/build/recipe/multifactorauth/types.d.ts b/lib/build/recipe/multifactorauth/types.d.ts index c492a2946..25915804b 100644 --- a/lib/build/recipe/multifactorauth/types.d.ts +++ b/lib/build/recipe/multifactorauth/types.d.ts @@ -146,7 +146,7 @@ export declare type APIInterface = { } | GeneralErrorResponse >; - regenerateBackupCodesPOST?: (input: { + generateBackupCodesPOST?: (input: { session: SessionContainerInterface; options: APIOptions; userContext: UserContext; diff --git a/lib/ts/recipe/multifactorauth/types.ts b/lib/ts/recipe/multifactorauth/types.ts index 3f68a5ec7..1b2312bbc 100644 --- a/lib/ts/recipe/multifactorauth/types.ts +++ b/lib/ts/recipe/multifactorauth/types.ts @@ -179,7 +179,7 @@ export type APIInterface = { | GeneralErrorResponse >; - regenerateBackupCodesPOST?: (input: { + generateBackupCodesPOST?: (input: { session: SessionContainerInterface; options: APIOptions; userContext: UserContext; From 0f982c85364badb8174d1e5b1fd8fadda49d5627 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Fri, 11 Oct 2024 13:30:50 +0530 Subject: [PATCH 08/12] Add user details get interface definition --- lib/build/recipe/usermetadata/types.d.ts | 13 +++++++++++++ lib/ts/recipe/usermetadata/types.ts | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/build/recipe/usermetadata/types.d.ts b/lib/build/recipe/usermetadata/types.d.ts index de81c77ce..b0475c1dc 100644 --- a/lib/build/recipe/usermetadata/types.d.ts +++ b/lib/build/recipe/usermetadata/types.d.ts @@ -30,6 +30,19 @@ export declare type APIOptions = { res: BaseResponse; }; export declare type APIInterface = { + userDetailsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + details: { + name?: string; + }; + } + | GeneralErrorResponse + >; updateUserDetailsPOST?: (input: { session: SessionContainerInterface; details: { diff --git a/lib/ts/recipe/usermetadata/types.ts b/lib/ts/recipe/usermetadata/types.ts index 77ac1b7aa..2ca2ffbcb 100644 --- a/lib/ts/recipe/usermetadata/types.ts +++ b/lib/ts/recipe/usermetadata/types.ts @@ -48,6 +48,20 @@ export type APIOptions = { }; export type APIInterface = { + userDetailsGET?: (input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + details: { + name?: string; + }; + } + | GeneralErrorResponse + >; + updateUserDetailsPOST?: (input: { session: SessionContainerInterface; details: { From b70a8ab6a1933534b133a4d1899c7628fe86b697 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 14 Oct 2024 15:17:35 +0530 Subject: [PATCH 09/12] Update type definitions based on requested/discussed changes --- lib/build/recipe/accountlinking/types.d.ts | 71 ++++++++++++++++- .../emailpassword/api/implementation.js | 2 + lib/build/recipe/emailpassword/types.d.ts | 78 ++++++++++--------- .../recipe/session/api/implementation.js | 2 + lib/build/recipe/session/types.d.ts | 60 +++++++------- lib/build/recipe/thirdparty/types.d.ts | 24 ------ lib/ts/recipe/accountlinking/types.ts | 73 ++++++++++++++++- .../emailpassword/api/implementation.ts | 3 + lib/ts/recipe/emailpassword/types.ts | 64 +++++++-------- lib/ts/recipe/session/api/implementation.ts | 3 + lib/ts/recipe/session/types.ts | 61 +++++++-------- lib/ts/recipe/thirdparty/types.ts | 26 ------- 12 files changed, 279 insertions(+), 188 deletions(-) diff --git a/lib/build/recipe/accountlinking/types.d.ts b/lib/build/recipe/accountlinking/types.d.ts index 3530940ee..44ad3929f 100644 --- a/lib/build/recipe/accountlinking/types.d.ts +++ b/lib/build/recipe/accountlinking/types.d.ts @@ -1,6 +1,7 @@ // @ts-nocheck +import type { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; -import type { User, UserContext } from "../../types"; +import type { GeneralErrorResponse, NormalisedAppinfo, User, UserContext } from "../../types"; import RecipeUserId from "../../recipeUserId"; import { SessionContainerInterface } from "../session/types"; export declare type TypeInput = { @@ -175,6 +176,74 @@ export declare type RecipeInterface = { status: "OK"; }>; }; +export declare type APIOptions = { + recipeImplementation: RecipeInterface; + appInfo: NormalisedAppinfo; + config: TypeNormalisedInput; + recipeId: string; + isInServerlessEnv: boolean; + req: BaseRequest; + res: BaseResponse; +}; +export declare type APIInterface = { + userDetailsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + >); + userEnabledDetailsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + enabledRecipes: string[]; + shouldDoAutomaticAccountLinking: boolean; + } + | GeneralErrorResponse + >); + loginMethodDELETE: + | undefined + | ((input: { + recipeId: string; + recipeUserId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); + updateUserDetailsPOST: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; + reason: string; + } + | GeneralErrorResponse + >); +}; export declare type AccountInfo = { email?: string; phoneNumber?: string; diff --git a/lib/build/recipe/emailpassword/api/implementation.js b/lib/build/recipe/emailpassword/api/implementation.js index 6619c14cf..6eea377fe 100644 --- a/lib/build/recipe/emailpassword/api/implementation.js +++ b/lib/build/recipe/emailpassword/api/implementation.js @@ -775,6 +775,8 @@ function getAPIImplementation() { user: postAuthChecks.user, }; }, + updatePasswordPOST: undefined, + changeEmailPOST: undefined, }; } exports.default = getAPIImplementation; diff --git a/lib/build/recipe/emailpassword/types.d.ts b/lib/build/recipe/emailpassword/types.d.ts index 94d655389..9757645b2 100644 --- a/lib/build/recipe/emailpassword/types.d.ts +++ b/lib/build/recipe/emailpassword/types.d.ts @@ -322,41 +322,49 @@ export declare type APIInterface = { } | GeneralErrorResponse >); - passwordStateGET?: (input: { - email: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - exists: boolean; - } - | GeneralErrorResponse - >; - updatePasswordPOST?: (input: { - details: { - email: string; - newPassword: string; - oldPassword?: string; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "OLD_PASSWORD_IS_REQUIRED_FOR_VERIFICATION"; - reason: string; - } - | { - status: "PASSWORD_POLICY_VIOLATED_ERROR"; - failureReason: string; - } - | GeneralErrorResponse - >; + updatePasswordPOST: + | undefined + | ((input: { + newPassword: string; + oldPassword: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "WRONG_CREDENTIALS_ERROR"; + } + | { + status: "PASSWORD_POLICY_VIOLATED_ERROR"; + failureReason: string; + } + | GeneralErrorResponse + >); + changeEmailPOST: + | undefined + | ((input: { + email: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { + status: "EMAIL_VERIFICATION_SENT"; + } + | { + status: "EMAIL_ALREADY_EXISTS_ERROR"; + } + | { + status: "EMAIL_CHANGE_NOT_ALLOWED_ERROR"; + } + | GeneralErrorResponse + >); }; export declare type TypeEmailPasswordPasswordResetEmailDeliveryInput = { type: "PASSWORD_RESET"; diff --git a/lib/build/recipe/session/api/implementation.js b/lib/build/recipe/session/api/implementation.js index d079f77e9..b03e57366 100644 --- a/lib/build/recipe/session/api/implementation.js +++ b/lib/build/recipe/session/api/implementation.js @@ -51,6 +51,8 @@ function getAPIInterface() { status: "OK", }; }, + allSessionsGET: undefined, + revokeSessionPOST: undefined, }; } exports.default = getAPIInterface; diff --git a/lib/build/recipe/session/types.d.ts b/lib/build/recipe/session/types.d.ts index 89950bfa8..ffd51104d 100644 --- a/lib/build/recipe/session/types.d.ts +++ b/lib/build/recipe/session/types.d.ts @@ -323,40 +323,32 @@ export declare type APIInterface = { } | GeneralErrorResponse >); - allSessionsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - sessions: SessionInformation[]; - } - | GeneralErrorResponse - >; - revokeAllSessionsPOST?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - sessionRemoveCount: number; - } - | GeneralErrorResponse - >; - revokeSessionPOST?: (input: { - sessionHandle: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - wasRemoved: boolean; - } - | GeneralErrorResponse - >; + allSessionsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessions: SessionInformation[]; + } + | GeneralErrorResponse + >); + revokeSessionPOST: + | undefined + | ((input: { + sessionHandle: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); verifySession(input: { verifySessionOptions: VerifySessionOptions | undefined; options: APIOptions; diff --git a/lib/build/recipe/thirdparty/types.d.ts b/lib/build/recipe/thirdparty/types.d.ts index 2e38a977d..8d0198e3b 100644 --- a/lib/build/recipe/thirdparty/types.d.ts +++ b/lib/build/recipe/thirdparty/types.d.ts @@ -330,29 +330,5 @@ export declare type APIInterface = { options: APIOptions; userContext: UserContext; }) => Promise); - connectedAccountsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - }) => Promise< - | { - status: "OK"; - accounts: { - id: string; - userId: string; - }[]; - } - | GeneralErrorResponse - >; - removeAccountDELETE?: (input: { - id: string; - session: SessionContainerInterface; - options: APIOptions; - }) => Promise< - | { - status: "OK"; - wasDeleted: boolean; - } - | GeneralErrorResponse - >; }; export {}; diff --git a/lib/ts/recipe/accountlinking/types.ts b/lib/ts/recipe/accountlinking/types.ts index 83aec5230..0867494d3 100644 --- a/lib/ts/recipe/accountlinking/types.ts +++ b/lib/ts/recipe/accountlinking/types.ts @@ -13,8 +13,9 @@ * under the License. */ +import type { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; -import type { User, UserContext } from "../../types"; +import type { GeneralErrorResponse, NormalisedAppinfo, User, UserContext } from "../../types"; import RecipeUserId from "../../recipeUserId"; import { SessionContainerInterface } from "../session/types"; @@ -185,6 +186,76 @@ export type RecipeInterface = { }) => Promise<{ status: "OK" }>; }; +export type APIOptions = { + recipeImplementation: RecipeInterface; + appInfo: NormalisedAppinfo; + config: TypeNormalisedInput; + recipeId: string; + isInServerlessEnv: boolean; + req: BaseRequest; + res: BaseResponse; +}; + +export type APIInterface = { + userDetailsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + user: User; + } + | GeneralErrorResponse + >); + + userEnabledDetailsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + enabledRecipes: string[]; + shouldDoAutomaticAccountLinking: boolean; + } + | GeneralErrorResponse + >); + + loginMethodDELETE: + | undefined + | ((input: { + recipeId: string; + recipeUserId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); + + updateUserDetailsPOST: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; reason: string } + | GeneralErrorResponse + >); +}; + export type AccountInfo = { email?: string; phoneNumber?: string; diff --git a/lib/ts/recipe/emailpassword/api/implementation.ts b/lib/ts/recipe/emailpassword/api/implementation.ts index 635ff2bd6..1eb46e992 100644 --- a/lib/ts/recipe/emailpassword/api/implementation.ts +++ b/lib/ts/recipe/emailpassword/api/implementation.ts @@ -926,5 +926,8 @@ export default function getAPIImplementation(): APIInterface { user: postAuthChecks.user, }; }, + + updatePasswordPOST: undefined, + changeEmailPOST: undefined, }; } diff --git a/lib/ts/recipe/emailpassword/types.ts b/lib/ts/recipe/emailpassword/types.ts index 39ad2dfe6..fc780ea15 100644 --- a/lib/ts/recipe/emailpassword/types.ts +++ b/lib/ts/recipe/emailpassword/types.ts @@ -326,39 +326,39 @@ export type APIInterface = { | GeneralErrorResponse >); - passwordStateGET?: (input: { - email: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - exists: boolean; - } - | GeneralErrorResponse - >; + updatePasswordPOST: + | undefined + | ((input: { + newPassword: string; + oldPassword: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { status: "WRONG_CREDENTIALS_ERROR" } + | { status: "PASSWORD_POLICY_VIOLATED_ERROR"; failureReason: string } + | GeneralErrorResponse + >); - updatePasswordPOST?: (input: { - details: { - email: string; - newPassword: string; - oldPassword?: string; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "OLD_PASSWORD_IS_REQUIRED_FOR_VERIFICATION"; - reason: string; - } - | { status: "PASSWORD_POLICY_VIOLATED_ERROR"; failureReason: string } - | GeneralErrorResponse - >; + changeEmailPOST: + | undefined + | ((input: { + email: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | { status: "EMAIL_VERIFICATION_SENT" } + | { status: "EMAIL_ALREADY_EXISTS_ERROR" } + | { status: "EMAIL_CHANGE_NOT_ALLOWED_ERROR" } + | GeneralErrorResponse + >); }; export type TypeEmailPasswordPasswordResetEmailDeliveryInput = { diff --git a/lib/ts/recipe/session/api/implementation.ts b/lib/ts/recipe/session/api/implementation.ts index e6b799e9d..084e722a7 100644 --- a/lib/ts/recipe/session/api/implementation.ts +++ b/lib/ts/recipe/session/api/implementation.ts @@ -80,5 +80,8 @@ export default function getAPIInterface(): APIInterface { status: "OK", }; }, + + allSessionsGET: undefined, + revokeSessionPOST: undefined, }; } diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index 9cfc67459..253aee8cb 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -394,42 +394,33 @@ export type APIInterface = { | GeneralErrorResponse >); - allSessionsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - sessions: SessionInformation[]; - } - | GeneralErrorResponse - >; - - revokeAllSessionsPOST?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - sessionRemoveCount: number; - } - | GeneralErrorResponse - >; + allSessionsGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + sessions: SessionInformation[]; + } + | GeneralErrorResponse + >); - revokeSessionPOST?: (input: { - sessionHandle: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - wasRemoved: boolean; - } - | GeneralErrorResponse - >; + revokeSessionPOST: + | undefined + | ((input: { + sessionHandle: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); verifySession(input: { verifySessionOptions: VerifySessionOptions | undefined; diff --git a/lib/ts/recipe/thirdparty/types.ts b/lib/ts/recipe/thirdparty/types.ts index 62ea24b1a..71e9847d3 100644 --- a/lib/ts/recipe/thirdparty/types.ts +++ b/lib/ts/recipe/thirdparty/types.ts @@ -316,30 +316,4 @@ export type APIInterface = { options: APIOptions; userContext: UserContext; }) => Promise); - - connectedAccountsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - }) => Promise< - | { - status: "OK"; - accounts: { - id: string; - userId: string; - }[]; - } - | GeneralErrorResponse - >; - - removeAccountDELETE?: (input: { - id: string; - session: SessionContainerInterface; - options: APIOptions; - }) => Promise< - | { - status: "OK"; - wasDeleted: boolean; - } - | GeneralErrorResponse - >; }; From 81cb0c3c7f1c8c725efef88a42de21103bc3285a Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 14 Oct 2024 15:19:42 +0530 Subject: [PATCH 10/12] Update user details update endpoint to accept inputs --- lib/build/recipe/accountlinking/types.d.ts | 2 ++ lib/ts/recipe/accountlinking/types.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/build/recipe/accountlinking/types.d.ts b/lib/build/recipe/accountlinking/types.d.ts index 44ad3929f..ba31192a2 100644 --- a/lib/build/recipe/accountlinking/types.d.ts +++ b/lib/build/recipe/accountlinking/types.d.ts @@ -230,6 +230,8 @@ export declare type APIInterface = { updateUserDetailsPOST: | undefined | ((input: { + firstName: string; + lastName: string; session: SessionContainerInterface; options: APIOptions; userContext: UserContext; diff --git a/lib/ts/recipe/accountlinking/types.ts b/lib/ts/recipe/accountlinking/types.ts index 0867494d3..298587c5c 100644 --- a/lib/ts/recipe/accountlinking/types.ts +++ b/lib/ts/recipe/accountlinking/types.ts @@ -244,6 +244,8 @@ export type APIInterface = { updateUserDetailsPOST: | undefined | ((input: { + firstName: string; + lastName: string; session: SessionContainerInterface; options: APIOptions; userContext: UserContext; From 848c8a8ba95626ea007301334b124cffd510d883 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 14 Oct 2024 15:21:53 +0530 Subject: [PATCH 11/12] Remove all changes in user metadata --- lib/build/recipe/usermetadata/types.d.ts | 174 +-------------------- lib/ts/recipe/usermetadata/types.ts | 184 +---------------------- 2 files changed, 4 insertions(+), 354 deletions(-) diff --git a/lib/build/recipe/usermetadata/types.d.ts b/lib/build/recipe/usermetadata/types.d.ts index b0475c1dc..8dd434ac7 100644 --- a/lib/build/recipe/usermetadata/types.d.ts +++ b/lib/build/recipe/usermetadata/types.d.ts @@ -1,8 +1,6 @@ // @ts-nocheck -import { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; -import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; -import { SessionContainerInterface } from "../session/types"; +import { JSONObject, UserContext } from "../../types"; export declare type TypeInput = { override?: { functions?: ( @@ -21,175 +19,7 @@ export declare type TypeNormalisedInput = { apis: (originalImplementation: APIInterface, builder?: OverrideableBuilder) => APIInterface; }; }; -export declare type APIOptions = { - recipeImplementation: RecipeInterface; - config: TypeNormalisedInput; - recipeId: string; - isInServerlessEnv: boolean; - req: BaseRequest; - res: BaseResponse; -}; -export declare type APIInterface = { - userDetailsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - details: { - name?: string; - }; - } - | GeneralErrorResponse - >; - updateUserDetailsPOST?: (input: { - session: SessionContainerInterface; - details: { - name?: string; - }; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - details: { - name: string | undefined; - }; - } - | { - status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; - reason: string; - } - | GeneralErrorResponse - >; - userEmailsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - emails: Array<{ - id: string; - isVerified: boolean; - isPrimary: boolean; - }>; - } - | GeneralErrorResponse - >; - addEmailForUserPOST?: (input: { - email: { - id: string; - isVerified?: boolean; - isPrimary?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; - reason: string; - } - | GeneralErrorResponse - >; - updateEmailForUserPATCH?: (input: { - emailId: string; - details: { - isVerified?: boolean; - isPrimary?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; - reason: string; - } - | GeneralErrorResponse - >; - removeEmailForUserDELETE?: ( - emailId: string, - session: SessionContainerInterface, - options: APIOptions, - userContext: UserContext - ) => Promise< - | { - status: "OK"; - email: { - id: string; - isVerified: boolean; - isPrimary: boolean; - }; - } - | { - status: "AT_LEAST_ONE_VERIFIED_EMAIL_IS_REQUIRED"; - reason: string; - } - | GeneralErrorResponse - >; - userPhoneNumbersGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - phones: Array<{ - number: string; - isVerified: boolean; - }>; - } - | GeneralErrorResponse - >; - addPhoneNumberForUserPOST?: (input: { - phone: { - number: string; - isVerified?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - updatePhoneNumberForUserPATCH?: (input: { - phoneNumber: string; - details: { - isVerified?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - removePhoneNumberForUserDELETE?: ( - phoneNumber: string, - session: SessionContainerInterface, - options: APIOptions, - userContext: UserContext - ) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; -}; +export declare type APIInterface = {}; export declare type RecipeInterface = { getUserMetadata: (input: { userId: string; diff --git a/lib/ts/recipe/usermetadata/types.ts b/lib/ts/recipe/usermetadata/types.ts index 2ca2ffbcb..590267b4f 100644 --- a/lib/ts/recipe/usermetadata/types.ts +++ b/lib/ts/recipe/usermetadata/types.ts @@ -13,10 +13,8 @@ * under the License. */ -import { BaseRequest, BaseResponse } from "../../framework"; import OverrideableBuilder from "supertokens-js-override"; -import { GeneralErrorResponse, JSONObject, UserContext } from "../../types"; -import { SessionContainerInterface } from "../session/types"; +import { JSONObject, UserContext } from "../../types"; export type TypeInput = { override?: { @@ -38,185 +36,7 @@ export type TypeNormalisedInput = { }; }; -export type APIOptions = { - recipeImplementation: RecipeInterface; - config: TypeNormalisedInput; - recipeId: string; - isInServerlessEnv: boolean; - req: BaseRequest; - res: BaseResponse; -}; - -export type APIInterface = { - userDetailsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - details: { - name?: string; - }; - } - | GeneralErrorResponse - >; - - updateUserDetailsPOST?: (input: { - session: SessionContainerInterface; - details: { - name?: string; - }; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - details: { - name: string | undefined; - }; - } - | { - status: "USER_DETAILS_UPDATE_NOT_ALLOWED"; - reason: string; - } - | GeneralErrorResponse - >; - - userEmailsGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - emails: Array<{ - id: string; - isVerified: boolean; - isPrimary: boolean; - }>; - } - | GeneralErrorResponse - >; - - addEmailForUserPOST?: (input: { - email: { - id: string; - isVerified?: boolean; - isPrimary?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; - reason: string; - } - | GeneralErrorResponse - >; - - updateEmailForUserPATCH?: (input: { - emailId: string; - details: { - isVerified?: boolean; - isPrimary?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | { - status: "UNVERIFIED_EMAIL_CANNOT_BE_PRIMARY"; - reason: string; - } - | GeneralErrorResponse - >; - - removeEmailForUserDELETE?: ( - emailId: string, - session: SessionContainerInterface, - options: APIOptions, - userContext: UserContext - ) => Promise< - | { - status: "OK"; - email: { - id: string; - isVerified: boolean; - isPrimary: boolean; - }; - } - | { - status: "AT_LEAST_ONE_VERIFIED_EMAIL_IS_REQUIRED"; - reason: string; - } - | GeneralErrorResponse - >; - - userPhoneNumbersGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - phones: Array<{ - number: string; - isVerified: boolean; - }>; - } - | GeneralErrorResponse - >; - - addPhoneNumberForUserPOST?: (input: { - phone: { - number: string; - isVerified?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - - updatePhoneNumberForUserPATCH?: (input: { - phoneNumber: string; - details: { - isVerified?: boolean; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - - removePhoneNumberForUserDELETE?: ( - phoneNumber: string, - session: SessionContainerInterface, - options: APIOptions, - userContext: UserContext - ) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; -}; +export type APIInterface = {}; export type RecipeInterface = { getUserMetadata: (input: { From ed648edf28866a0588f99dea7956f406d7e4fdcd Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Mon, 14 Oct 2024 15:27:52 +0530 Subject: [PATCH 12/12] Update multifactorauth endpoints --- .../multifactorauth/api/implementation.js | 3 + lib/build/recipe/multifactorauth/types.d.ts | 94 ++++++++---------- .../multifactorauth/api/implementation.ts | 3 + lib/ts/recipe/multifactorauth/types.ts | 99 ++++++++----------- 4 files changed, 86 insertions(+), 113 deletions(-) diff --git a/lib/build/recipe/multifactorauth/api/implementation.js b/lib/build/recipe/multifactorauth/api/implementation.js index 954ae11bd..9dea130f2 100644 --- a/lib/build/recipe/multifactorauth/api/implementation.js +++ b/lib/build/recipe/multifactorauth/api/implementation.js @@ -120,6 +120,9 @@ function getAPIInterface() { phoneNumbers: getPhoneNumbersForFactorsResult.factorIdToPhoneNumberMap, }; }, + factorsForUserGET: undefined, + addFactorForUserPOST: undefined, + deleteFactorForUserDELETE: undefined, }; } exports.default = getAPIInterface; diff --git a/lib/build/recipe/multifactorauth/types.d.ts b/lib/build/recipe/multifactorauth/types.d.ts index 25915804b..ca2452da3 100644 --- a/lib/build/recipe/multifactorauth/types.d.ts +++ b/lib/build/recipe/multifactorauth/types.d.ts @@ -106,61 +106,45 @@ export declare type APIInterface = { } | GeneralErrorResponse >); - factorsSetupForUserGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - factors: { - id: string; - details: JSONObject; - }[]; - backupCodes: string[] | undefined; - } - | GeneralErrorResponse - >; - addFactorForUserPOST?: (input: { - factor: { - id: string; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - backupCodes: string[]; - } - | GeneralErrorResponse - >; - deleteFactorForUserDELETE?: (input: { - factorId: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - generateBackupCodesPOST?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - backupCodes: string[]; - } - | { - status: "NO_FACTORS_ARE_SETUP"; - reason: string; - } - | GeneralErrorResponse - >; + factorsForUserGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + factors: string[]; + } + | GeneralErrorResponse + >); + addFactorForUserPOST: + | undefined + | ((input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); + deleteFactorForUserDELETE: + | undefined + | ((input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); }; export declare type GetFactorsSetupForUserFromOtherRecipesFunc = ( user: User, diff --git a/lib/ts/recipe/multifactorauth/api/implementation.ts b/lib/ts/recipe/multifactorauth/api/implementation.ts index c0c8ced7e..d5f22266e 100644 --- a/lib/ts/recipe/multifactorauth/api/implementation.ts +++ b/lib/ts/recipe/multifactorauth/api/implementation.ts @@ -125,5 +125,8 @@ export default function getAPIInterface(): APIInterface { phoneNumbers: getPhoneNumbersForFactorsResult.factorIdToPhoneNumberMap, }; }, + factorsForUserGET: undefined, + addFactorForUserPOST: undefined, + deleteFactorForUserDELETE: undefined, }; } diff --git a/lib/ts/recipe/multifactorauth/types.ts b/lib/ts/recipe/multifactorauth/types.ts index 1b2312bbc..d47cd7b10 100644 --- a/lib/ts/recipe/multifactorauth/types.ts +++ b/lib/ts/recipe/multifactorauth/types.ts @@ -136,64 +136,47 @@ export type APIInterface = { | GeneralErrorResponse >); - factorsSetupForUserGET?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - factors: { - id: string; - details: JSONObject; - }[]; - backupCodes: string[] | undefined; - } - | GeneralErrorResponse - >; - - addFactorForUserPOST?: (input: { - factor: { - id: string; - }; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - backupCodes: string[]; - } - | GeneralErrorResponse - >; - - deleteFactorForUserDELETE?: (input: { - factorId: string; - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - } - | GeneralErrorResponse - >; - - generateBackupCodesPOST?: (input: { - session: SessionContainerInterface; - options: APIOptions; - userContext: UserContext; - }) => Promise< - | { - status: "OK"; - backupCodes: string[]; - } - | { - status: "NO_FACTORS_ARE_SETUP"; - reason: string; - } - | GeneralErrorResponse - >; + factorsForUserGET: + | undefined + | ((input: { + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + factors: string[]; + } + | GeneralErrorResponse + >); + + addFactorForUserPOST: + | undefined + | ((input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); + + deleteFactorForUserDELETE: + | undefined + | ((input: { + factorId: string; + session: SessionContainerInterface; + options: APIOptions; + userContext: UserContext; + }) => Promise< + | { + status: "OK"; + } + | GeneralErrorResponse + >); }; export type GetFactorsSetupForUserFromOtherRecipesFunc = (user: User, userContext: UserContext) => Promise;