supertokens-node
Advanced tools
Comparing version 17.0.1 to 17.0.2
// @ts-nocheck | ||
import { APIInterface, APIOptions } from "../types"; | ||
import { TypeNormalisedInput } from "../../passwordless/types"; | ||
import { UserContext } from "../../../types"; | ||
declare type PasswordlessContactMethod = TypeNormalisedInput["contactMethod"]; | ||
declare type TenantLoginMethodType = { | ||
tenantId: string; | ||
emailPassword: { | ||
enabled: boolean; | ||
}; | ||
thirdPartyEmailPasssword: { | ||
enabled: boolean; | ||
}; | ||
passwordless: { | ||
enabled: boolean; | ||
contactMethod?: PasswordlessContactMethod; | ||
}; | ||
thirdPartyPasswordless: { | ||
enabled: boolean; | ||
contactMethod?: PasswordlessContactMethod; | ||
}; | ||
thirdParty: { | ||
enabled: boolean; | ||
}; | ||
firstFactors: string[]; | ||
}; | ||
@@ -26,0 +8,0 @@ export declare type Response = { |
@@ -10,3 +10,2 @@ "use strict"; | ||
const utils_1 = require("../../multitenancy/utils"); | ||
const multifactorauth_1 = require("../../multifactorauth"); | ||
async function getTenantLoginMethodsInfo(_, __, ___, userContext) { | ||
@@ -19,13 +18,7 @@ const tenantsRes = await recipe_1.default.getInstanceOrThrowError().recipeInterfaceImpl.listAllTenants({ | ||
const currentTenant = tenantsRes.tenants[i]; | ||
const normalisedTenantLoginMethodsInfo = await normaliseTenantLoginMethodsWithInitConfig( | ||
{ | ||
tenantId: currentTenant.tenantId, | ||
emailPassword: currentTenant.emailPassword, | ||
passwordless: currentTenant.passwordless, | ||
thirdParty: currentTenant.thirdParty, | ||
firstFactors: currentTenant.firstFactors, | ||
}, | ||
userContext | ||
); | ||
finalTenants.push(normalisedTenantLoginMethodsInfo); | ||
const loginMethods = normaliseTenantLoginMethodsWithInitConfig(currentTenant); | ||
finalTenants.push({ | ||
tenantId: currentTenant.tenantId, | ||
firstFactors: loginMethods, | ||
}); | ||
} | ||
@@ -38,21 +31,3 @@ return { | ||
exports.default = getTenantLoginMethodsInfo; | ||
async function normaliseTenantLoginMethodsWithInitConfig(tenantDetailsFromCore, userContext) { | ||
const normalisedTenantLoginMethodsInfo = { | ||
tenantId: tenantDetailsFromCore.tenantId, | ||
emailPassword: { | ||
enabled: false, | ||
}, | ||
thirdPartyEmailPasssword: { | ||
enabled: false, | ||
}, | ||
passwordless: { | ||
enabled: false, | ||
}, | ||
thirdPartyPasswordless: { | ||
enabled: false, | ||
}, | ||
thirdParty: { | ||
enabled: false, | ||
}, | ||
}; | ||
function normaliseTenantLoginMethodsWithInitConfig(tenantDetailsFromCore) { | ||
let firstFactors; | ||
@@ -75,35 +50,14 @@ let mtInstance = recipe_1.default.getInstanceOrThrowError(); | ||
for (const factorId of firstFactors) { | ||
let validRes = await utils_1.isValidFirstFactor(tenantDetailsFromCore.tenantId, factorId, userContext); | ||
if (validRes.status === "OK") { | ||
if ( | ||
utils_1.isFactorConfiguredForTenant({ | ||
tenantConfig: tenantDetailsFromCore, | ||
allAvailableFirstFactors: mtInstance.allAvailableFirstFactors, | ||
firstFactors: firstFactors, | ||
factorId, | ||
}) | ||
) { | ||
validFirstFactors.push(factorId); | ||
} | ||
if (validRes.status === "TENANT_NOT_FOUND_ERROR") { | ||
throw new Error("Tenant not found"); | ||
} | ||
} | ||
if (validFirstFactors.includes(multifactorauth_1.FactorIds.EMAILPASSWORD)) { | ||
normalisedTenantLoginMethodsInfo.emailPassword.enabled = true; | ||
} | ||
if (validFirstFactors.includes(multifactorauth_1.FactorIds.THIRDPARTY)) { | ||
normalisedTenantLoginMethodsInfo.thirdParty.enabled = true; | ||
} | ||
const pwlessEmailEnabled = | ||
validFirstFactors.includes(multifactorauth_1.FactorIds.OTP_EMAIL) || | ||
validFirstFactors.includes(multifactorauth_1.FactorIds.LINK_EMAIL); | ||
const pwlessPhoneEnabled = | ||
validFirstFactors.includes(multifactorauth_1.FactorIds.OTP_PHONE) || | ||
validFirstFactors.includes(multifactorauth_1.FactorIds.LINK_PHONE); | ||
if (pwlessEmailEnabled) { | ||
if (pwlessPhoneEnabled) { | ||
normalisedTenantLoginMethodsInfo.passwordless.enabled = true; | ||
normalisedTenantLoginMethodsInfo.passwordless.contactMethod = "EMAIL_OR_PHONE"; | ||
} else { | ||
normalisedTenantLoginMethodsInfo.passwordless.enabled = true; | ||
normalisedTenantLoginMethodsInfo.passwordless.contactMethod = "EMAIL"; | ||
} | ||
} else if (pwlessPhoneEnabled) { | ||
normalisedTenantLoginMethodsInfo.passwordless.enabled = true; | ||
normalisedTenantLoginMethodsInfo.passwordless.contactMethod = "PHONE"; | ||
} | ||
return normalisedTenantLoginMethodsInfo; | ||
return validFirstFactors; | ||
} |
@@ -16,3 +16,2 @@ // @ts-nocheck | ||
export declare const DASHBOARD_ANALYTICS_API = "/api/analytics"; | ||
export declare const TENANTS_LIST_API = "/api/tenants/list"; | ||
export declare const USERROLES_LIST_API = "/api/userroles/roles"; | ||
@@ -19,0 +18,0 @@ export declare const USERROLES_ROLE_API = "/api/userroles/role"; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.UNLINK_USER = exports.USERROLES_USER_API = exports.LIST_TENANT_LOGIN_METHODS = exports.CREATE_PASSWORDLESS_USER = exports.CREATE_EMAIL_PASSWORD_USER = exports.USERROLES_REMOVE_PERMISSIONS_API = exports.USERROLES_PERMISSIONS_API = exports.USERROLES_ROLE_API = exports.USERROLES_LIST_API = exports.TENANTS_LIST_API = exports.DASHBOARD_ANALYTICS_API = exports.SEARCH_TAGS_API = exports.USER_EMAIL_VERIFY_TOKEN_API = exports.USER_PASSWORD_API = exports.USER_SESSIONS_API = exports.USER_METADATA_API = exports.USER_EMAIL_VERIFY_API = exports.USER_API = exports.USERS_COUNT_API = exports.USERS_LIST_GET_API = exports.VALIDATE_KEY_API = exports.SIGN_OUT_API = exports.SIGN_IN_API = exports.DASHBOARD_API = void 0; | ||
exports.UNLINK_USER = exports.USERROLES_USER_API = exports.LIST_TENANT_LOGIN_METHODS = exports.CREATE_PASSWORDLESS_USER = exports.CREATE_EMAIL_PASSWORD_USER = exports.USERROLES_REMOVE_PERMISSIONS_API = exports.USERROLES_PERMISSIONS_API = exports.USERROLES_ROLE_API = exports.USERROLES_LIST_API = exports.DASHBOARD_ANALYTICS_API = exports.SEARCH_TAGS_API = exports.USER_EMAIL_VERIFY_TOKEN_API = exports.USER_PASSWORD_API = exports.USER_SESSIONS_API = exports.USER_METADATA_API = exports.USER_EMAIL_VERIFY_API = exports.USER_API = exports.USERS_COUNT_API = exports.USERS_LIST_GET_API = exports.VALIDATE_KEY_API = exports.SIGN_OUT_API = exports.SIGN_IN_API = exports.DASHBOARD_API = void 0; | ||
exports.DASHBOARD_API = "/dashboard"; | ||
@@ -33,3 +33,2 @@ exports.SIGN_IN_API = "/api/signin"; | ||
exports.DASHBOARD_ANALYTICS_API = "/api/analytics"; | ||
exports.TENANTS_LIST_API = "/api/tenants/list"; | ||
exports.USERROLES_LIST_API = "/api/userroles/roles"; | ||
@@ -36,0 +35,0 @@ exports.USERROLES_ROLE_API = "/api/userroles/role"; |
@@ -50,3 +50,2 @@ "use strict"; | ||
const analytics_1 = __importDefault(require("./api/analytics")); | ||
const listTenants_1 = __importDefault(require("./api/listTenants")); | ||
const userUnlinkGet_1 = require("./api/userdetails/userUnlinkGet"); | ||
@@ -237,10 +236,2 @@ const getAllRoles_1 = __importDefault(require("./api/userroles/roles/getAllRoles")); | ||
{ | ||
id: constants_1.TENANTS_LIST_API, | ||
pathWithoutApiBasePath: new normalisedURLPath_1.default( | ||
utils_1.getApiPathWithDashboardBase(constants_1.TENANTS_LIST_API) | ||
), | ||
disabled: false, | ||
method: "get", | ||
}, | ||
{ | ||
id: constants_1.UNLINK_USER, | ||
@@ -418,4 +409,2 @@ pathWithoutApiBasePath: new normalisedURLPath_1.default( | ||
apiFunction = analytics_1.default; | ||
} else if (id === constants_1.TENANTS_LIST_API) { | ||
apiFunction = listTenants_1.default; | ||
} else if (id === constants_1.UNLINK_USER) { | ||
@@ -422,0 +411,0 @@ apiFunction = userUnlinkGet_1.userUnlink; |
// @ts-nocheck | ||
import { TypeInput, TypeNormalisedInput } from "./types"; | ||
import { TypeInput, TypeNormalisedInput, TenantConfig } from "./types"; | ||
import { UserContext } from "../../types"; | ||
@@ -20,1 +20,12 @@ export declare function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalisedInput; | ||
>; | ||
export declare function isFactorConfiguredForTenant({ | ||
tenantConfig, | ||
allAvailableFirstFactors, | ||
firstFactors, | ||
factorId, | ||
}: { | ||
tenantConfig: TenantConfig; | ||
allAvailableFirstFactors: string[]; | ||
firstFactors: string[]; | ||
factorId: string; | ||
}): boolean; |
@@ -33,3 +33,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidFirstFactor = exports.validateAndNormaliseUserInput = void 0; | ||
exports.isFactorConfiguredForTenant = exports.isValidFirstFactor = exports.validateAndNormaliseUserInput = void 0; | ||
const recipe_1 = __importDefault(require("./recipe")); | ||
@@ -86,8 +86,26 @@ const logger_1 = require("../../logger"); | ||
} | ||
if ( | ||
isFactorConfiguredForTenant({ | ||
tenantConfig, | ||
allAvailableFirstFactors: mtRecipe.allAvailableFirstFactors, | ||
firstFactors: configuredFirstFactors, | ||
factorId, | ||
}) | ||
) { | ||
return { | ||
status: "OK", | ||
}; | ||
} | ||
return { | ||
status: "INVALID_FIRST_FACTOR_ERROR", | ||
}; | ||
}; | ||
exports.isValidFirstFactor = isValidFirstFactor; | ||
function isFactorConfiguredForTenant({ tenantConfig, allAvailableFirstFactors, firstFactors, factorId }) { | ||
// Here we filter the array so that we only have: | ||
// 1. Factors that other recipes have marked as available | ||
// 2. Custom factors (not in the built-in FactorIds list) | ||
configuredFirstFactors = configuredFirstFactors.filter( | ||
let configuredFirstFactors = firstFactors.filter( | ||
(factorId) => | ||
mtRecipe.allAvailableFirstFactors.includes(factorId) || !Object.values(types_1.FactorIds).includes(factorId) | ||
allAvailableFirstFactors.includes(factorId) || !Object.values(types_1.FactorIds).includes(factorId) | ||
); | ||
@@ -114,11 +132,4 @@ // Filter based on enabled recipes in the core | ||
} | ||
if (configuredFirstFactors.includes(factorId)) { | ||
return { | ||
status: "OK", | ||
}; | ||
} | ||
return { | ||
status: "INVALID_FIRST_FACTOR_ERROR", | ||
}; | ||
}; | ||
exports.isValidFirstFactor = isValidFirstFactor; | ||
return configuredFirstFactors.includes(factorId); | ||
} | ||
exports.isFactorConfiguredForTenant = isFactorConfiguredForTenant; |
// @ts-nocheck | ||
export declare const version = "17.0.1"; | ||
export declare const version = "17.0.2"; | ||
export declare const cdiSupported: string[]; | ||
export declare const dashboardVersion = "0.10"; | ||
export declare const dashboardVersion = "0.11"; |
@@ -18,5 +18,5 @@ "use strict"; | ||
*/ | ||
exports.version = "17.0.1"; | ||
exports.version = "17.0.2"; | ||
exports.cdiSupported = ["5.0"]; | ||
// Note: The actual script import for dashboard uses v{DASHBOARD_VERSION} | ||
exports.dashboardVersion = "0.10"; | ||
exports.dashboardVersion = "0.11"; |
{ | ||
"name": "supertokens-node", | ||
"version": "17.0.1", | ||
"version": "17.0.2", | ||
"description": "NodeJS driver for SuperTokens core", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
2065410
720
45154