diff --git a/src/common/TagoIOModule.ts b/src/common/TagoIOModule.ts index c55be321..46ba3ef5 100644 --- a/src/common/TagoIOModule.ts +++ b/src/common/TagoIOModule.ts @@ -1,12 +1,12 @@ import { AxiosRequestConfig, Method } from "axios"; import qs from "qs"; import apiRequest from "../infrastructure/apiRequest"; -import regions, { Regions } from "../regions"; +import regions, { Regions, RegionsObj } from "../regions"; import { RefType, GenericID } from "./common.types"; interface GenericModuleParams { token?: string; - region?: Regions; + region?: Regions | RegionsObj; // options?: Object; } @@ -113,7 +113,10 @@ abstract class TagoIOModule { return result as Promise; } - protected static async doRequestAnonymous(requestObj: doRequestParams, region?: Regions): Promise { + protected static async doRequestAnonymous( + requestObj: doRequestParams, + region?: Regions | RegionsObj + ): Promise { const apiURI = regions(region)?.api; if (!apiURI) { throw new Error("Invalid region"); diff --git a/src/infrastructure/envParams.json b/src/infrastructure/envParams.json index a578506c..e37fad6b 100644 --- a/src/infrastructure/envParams.json +++ b/src/infrastructure/envParams.json @@ -1 +1 @@ -{"version": "11.3.2"} \ No newline at end of file +{"version": "11.3.2"} diff --git a/src/modules/Dictionary/dictionary.types.ts b/src/modules/Dictionary/dictionary.types.ts index c30eac77..3a908849 100644 --- a/src/modules/Dictionary/dictionary.types.ts +++ b/src/modules/Dictionary/dictionary.types.ts @@ -1,16 +1,16 @@ import { GenericModuleParams } from "../../common/TagoIOModule"; -import { Regions } from "../../regions"; +import { Regions, RegionsObj } from "../../regions"; interface IDictionaryModuleParams extends GenericModuleParams { token: string; - region?: Regions; + region?: Regions | RegionsObj; language?: string; options?: object; } interface IDictionaryModuleParamsAnonymous extends GenericModuleParams { runURL: string; - region?: Regions; + region?: Regions | RegionsObj; language?: string; options?: object; } diff --git a/src/modules/RunUser/RunUser.ts b/src/modules/RunUser/RunUser.ts index 0de88a32..c4faa24b 100644 --- a/src/modules/RunUser/RunUser.ts +++ b/src/modules/RunUser/RunUser.ts @@ -1,6 +1,6 @@ import { GenericID, GenericToken } from "../../common/common.types"; import TagoIOModule, { doRequestParams, GenericModuleParams } from "../../common/TagoIOModule"; -import { Regions } from "../../regions"; +import { Regions, RegionsObj } from "../../regions"; import { NotificationInfo, NotificationQuery } from "../Resources/notifications.types"; import { OTPType } from "../Resources/account.types"; import dateParser from "../Utils/dateParser"; @@ -40,7 +40,7 @@ class RunUser extends TagoIOModule { public static async create( tagoIORunURL: string, newUserObj: RunUserCreateInfo, - region?: Regions + region?: Regions | RegionsObj ): Promise { const params: doRequestParams = { path: `/run/${tagoIORunURL}/signup`, @@ -90,7 +90,7 @@ class RunUser extends TagoIOModule { public static async login( tagoIORunURL: string, credentialsObj: RunUserLogin, - region?: Regions + region?: Regions | RegionsObj ): Promise { const params: doRequestParams = { path: `/run/${tagoIORunURL}/login`, @@ -128,7 +128,11 @@ class RunUser extends TagoIOModule { * @param email Run user email to recover the password * @param region TagoIO Region Server [default usa-1] */ - public static async passwordRecover(tagoIORunURL: string, email: string, region?: Regions): Promise { + public static async passwordRecover( + tagoIORunURL: string, + email: string, + region?: Regions | RegionsObj + ): Promise { const params: doRequestParams = { path: `/run/${tagoIORunURL}/passwordreset/${email}`, method: "GET", @@ -264,13 +268,17 @@ class RunUser extends TagoIOModule { public static async requestLoginPINCode( tagoIORunURL: string, credentials: RunUserCredentials, - typeOTP: OTPType + typeOTP: OTPType, + region?: Regions | RegionsObj ): Promise { - const result = await this.doRequestAnonymous({ - path: `/run/${tagoIORunURL}/login/otp`, - method: "POST", - body: { ...credentials, otp_type: typeOTP }, - }); + const result = await this.doRequestAnonymous( + { + path: `/run/${tagoIORunURL}/login/otp`, + method: "POST", + body: { ...credentials, otp_type: typeOTP }, + }, + region + ); return result; } diff --git a/src/regions.ts b/src/regions.ts index d992f74a..e0765e18 100644 --- a/src/regions.ts +++ b/src/regions.ts @@ -27,8 +27,9 @@ const regionsDefinition = { * @internal * @param region Region */ -function getConnectionURI(region?: Regions): RegionsObj { - const value = regionsDefinition[region]; +function getConnectionURI(region?: Regions | RegionsObj): RegionsObj { + const value = + typeof region === "string" ? regionsDefinition[region] : typeof region === "object" ? region : undefined; if (value) { return value; @@ -61,4 +62,4 @@ function getConnectionURI(region?: Regions): RegionsObj { type Regions = "usa-1" | "env"; export default getConnectionURI; -export { Regions }; +export { Regions, RegionsObj };