From c72528fbce68c87758dc4010818d94b4873cf770 Mon Sep 17 00:00:00 2001 From: Sattvik Chakravarthy Date: Fri, 10 Nov 2023 16:48:23 +0530 Subject: [PATCH] fix: update types --- lib/build/recipe/totp/api/createDevice.js | 10 ---------- lib/build/recipe/totp/api/implementation.js | 4 +--- lib/build/recipe/totp/recipe.js | 2 +- lib/build/recipe/totp/recipeImplementation.d.ts | 3 ++- lib/build/recipe/totp/recipeImplementation.js | 5 ++++- lib/build/recipe/totp/types.d.ts | 6 ++++-- lib/build/recipe/totp/utils.js | 9 +++++++++ lib/ts/recipe/totp/api/createDevice.ts | 12 ------------ lib/ts/recipe/totp/api/implementation.ts | 4 +--- lib/ts/recipe/totp/recipe.ts | 4 +++- lib/ts/recipe/totp/recipeImplementation.ts | 6 +++++- lib/ts/recipe/totp/types.ts | 8 ++++++-- lib/ts/recipe/totp/utils.ts | 3 +++ 13 files changed, 39 insertions(+), 37 deletions(-) diff --git a/lib/build/recipe/totp/api/createDevice.js b/lib/build/recipe/totp/api/createDevice.js index 07b85bfe7..99f13a18e 100644 --- a/lib/build/recipe/totp/api/createDevice.js +++ b/lib/build/recipe/totp/api/createDevice.js @@ -33,21 +33,11 @@ async function createDeviceAPI(apiImplementation, options, userContext) { ); const bodyParams = await options.req.getJSONBody(); const deviceName = bodyParams.deviceName; - const period = bodyParams.period; - const skew = bodyParams.skew; if (deviceName !== undefined && typeof deviceName !== "string") { throw new Error("deviceName must be a string"); } - if (period !== undefined && typeof period !== "number") { - throw new Error("period must be a number"); - } - if (skew !== undefined && typeof skew !== "number") { - throw new Error("skew must be a number"); - } let response = await apiImplementation.createDevicePOST({ deviceName, - period, - skew, options, session, userContext, diff --git a/lib/build/recipe/totp/api/implementation.js b/lib/build/recipe/totp/api/implementation.js index d9a14ab29..432bcb277 100644 --- a/lib/build/recipe/totp/api/implementation.js +++ b/lib/build/recipe/totp/api/implementation.js @@ -2,13 +2,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); function getAPIInterface() { return { - createDevicePOST: async function ({ deviceName, period, skew, options, session, userContext }) { + createDevicePOST: async function ({ deviceName, options, session, userContext }) { const userId = session.getUserId(); return await options.recipeImplementation.createDevice({ userId, deviceName: deviceName, - period: period, - skew: skew, userContext: userContext, }); }, diff --git a/lib/build/recipe/totp/recipe.js b/lib/build/recipe/totp/recipe.js index adb50a3ff..52b424b3c 100644 --- a/lib/build/recipe/totp/recipe.js +++ b/lib/build/recipe/totp/recipe.js @@ -88,7 +88,7 @@ class Recipe extends recipeModule_1.default { this.isInServerlessEnv = isInServerlessEnv; { let builder = new supertokens_js_override_1.default( - recipeImplementation_1.default(querier_1.Querier.getNewInstanceOrThrowError(recipeId)) + recipeImplementation_1.default(querier_1.Querier.getNewInstanceOrThrowError(recipeId), this.config) ); this.recipeInterfaceImpl = builder.override(this.config.override.functions).build(); } diff --git a/lib/build/recipe/totp/recipeImplementation.d.ts b/lib/build/recipe/totp/recipeImplementation.d.ts index 6a2182ed3..05e5cc9ef 100644 --- a/lib/build/recipe/totp/recipeImplementation.d.ts +++ b/lib/build/recipe/totp/recipeImplementation.d.ts @@ -1,4 +1,5 @@ // @ts-nocheck import { RecipeInterface } from "./"; import { Querier } from "../../querier"; -export default function getRecipeInterface(querier: Querier): RecipeInterface; +import { TypeNormalisedInput } from "./types"; +export default function getRecipeInterface(querier: Querier, config: TypeNormalisedInput): RecipeInterface; diff --git a/lib/build/recipe/totp/recipeImplementation.js b/lib/build/recipe/totp/recipeImplementation.js index c43a1eff1..8647eb6a9 100644 --- a/lib/build/recipe/totp/recipeImplementation.js +++ b/lib/build/recipe/totp/recipeImplementation.js @@ -6,12 +6,15 @@ var __importDefault = }; Object.defineProperty(exports, "__esModule", { value: true }); const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath")); -function getRecipeInterface(querier) { +function getRecipeInterface(querier, config) { return { createDevice: async (input) => { + var _a, _b; return await querier.sendPostRequest(new normalisedURLPath_1.default("/recipe/totp/device"), { userId: input.userId, deviceName: input.deviceName, + skew: (_a = input.skew) !== null && _a !== void 0 ? _a : config.defaultSkew, + period: (_b = input.period) !== null && _b !== void 0 ? _b : config.defaultPeriod, userContext: input.userContext, }); }, diff --git a/lib/build/recipe/totp/types.d.ts b/lib/build/recipe/totp/types.d.ts index 0c4a457d8..8f556907e 100644 --- a/lib/build/recipe/totp/types.d.ts +++ b/lib/build/recipe/totp/types.d.ts @@ -4,6 +4,8 @@ import OverrideableBuilder from "supertokens-js-override"; import { GeneralErrorResponse } from "../../types"; import { SessionContainerInterface } from "../session/types"; export declare type TypeInput = { + defaultSkew?: number; + defaultPeriod?: number; override?: { functions?: ( originalImplementation: RecipeInterface, @@ -13,6 +15,8 @@ export declare type TypeInput = { }; }; export declare type TypeNormalisedInput = { + defaultSkew: number; + defaultPeriod: number; override: { functions: ( originalImplementation: RecipeInterface, @@ -107,8 +111,6 @@ export declare type APIOptions = { export declare type APIInterface = { createDevicePOST: (input: { deviceName?: string; - period?: number; - skew?: number; options: APIOptions; session: SessionContainerInterface; userContext: any; diff --git a/lib/build/recipe/totp/utils.js b/lib/build/recipe/totp/utils.js index c28798ae0..fc788b4a4 100644 --- a/lib/build/recipe/totp/utils.js +++ b/lib/build/recipe/totp/utils.js @@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAndNormaliseUserInput = void 0; function validateAndNormaliseUserInput(config) { + var _a, _b; let override = Object.assign( { functions: (originalImplementation) => originalImplementation, @@ -24,6 +25,14 @@ function validateAndNormaliseUserInput(config) { config === null || config === void 0 ? void 0 : config.override ); return { + defaultSkew: + (_a = config === null || config === void 0 ? void 0 : config.defaultSkew) !== null && _a !== void 0 + ? _a + : 1, + defaultPeriod: + (_b = config === null || config === void 0 ? void 0 : config.defaultPeriod) !== null && _b !== void 0 + ? _b + : 30, override, }; } diff --git a/lib/ts/recipe/totp/api/createDevice.ts b/lib/ts/recipe/totp/api/createDevice.ts index b9da490e1..145828885 100644 --- a/lib/ts/recipe/totp/api/createDevice.ts +++ b/lib/ts/recipe/totp/api/createDevice.ts @@ -35,25 +35,13 @@ export default async function createDeviceAPI( const bodyParams = await options.req.getJSONBody(); const deviceName = bodyParams.deviceName; - const period = bodyParams.period; - const skew = bodyParams.skew; if (deviceName !== undefined && typeof deviceName !== "string") { throw new Error("deviceName must be a string"); } - if (period !== undefined && typeof period !== "number") { - throw new Error("period must be a number"); - } - - if (skew !== undefined && typeof skew !== "number") { - throw new Error("skew must be a number"); - } - let response = await apiImplementation.createDevicePOST({ deviceName, - period, - skew, options, session, userContext, diff --git a/lib/ts/recipe/totp/api/implementation.ts b/lib/ts/recipe/totp/api/implementation.ts index 48dc404b4..17dc7bdab 100644 --- a/lib/ts/recipe/totp/api/implementation.ts +++ b/lib/ts/recipe/totp/api/implementation.ts @@ -2,14 +2,12 @@ import { APIInterface } from "../"; export default function getAPIInterface(): APIInterface { return { - createDevicePOST: async function ({ deviceName, period, skew, options, session, userContext }) { + createDevicePOST: async function ({ deviceName, options, session, userContext }) { const userId = session.getUserId(); return await options.recipeImplementation.createDevice({ userId, deviceName: deviceName, - period: period, - skew: skew, userContext: userContext, }); }, diff --git a/lib/ts/recipe/totp/recipe.ts b/lib/ts/recipe/totp/recipe.ts index 6fa144343..d0a937012 100644 --- a/lib/ts/recipe/totp/recipe.ts +++ b/lib/ts/recipe/totp/recipe.ts @@ -48,7 +48,9 @@ export default class Recipe extends RecipeModule { this.isInServerlessEnv = isInServerlessEnv; { - let builder = new OverrideableBuilder(RecipeImplementation(Querier.getNewInstanceOrThrowError(recipeId))); + let builder = new OverrideableBuilder( + RecipeImplementation(Querier.getNewInstanceOrThrowError(recipeId), this.config) + ); this.recipeInterfaceImpl = builder.override(this.config.override.functions).build(); } diff --git a/lib/ts/recipe/totp/recipeImplementation.ts b/lib/ts/recipe/totp/recipeImplementation.ts index 6b62feebd..0701368dd 100644 --- a/lib/ts/recipe/totp/recipeImplementation.ts +++ b/lib/ts/recipe/totp/recipeImplementation.ts @@ -1,8 +1,9 @@ import { RecipeInterface } from "./"; import { Querier } from "../../querier"; import NormalisedURLPath from "../../normalisedURLPath"; +import { TypeNormalisedInput } from "./types"; -export default function getRecipeInterface(querier: Querier): RecipeInterface { +export default function getRecipeInterface(querier: Querier, config: TypeNormalisedInput): RecipeInterface { return { createDevice: async (input: { userId: string; @@ -14,9 +15,12 @@ export default function getRecipeInterface(querier: Querier): RecipeInterface { return await querier.sendPostRequest(new NormalisedURLPath("/recipe/totp/device"), { userId: input.userId, deviceName: input.deviceName, + skew: input.skew ?? config.defaultSkew, + period: input.period ?? config.defaultPeriod, userContext: input.userContext, }); }, + updateDevice: (input: { userId: string; existingDeviceName: string; diff --git a/lib/ts/recipe/totp/types.ts b/lib/ts/recipe/totp/types.ts index 85442c163..52fb933d0 100644 --- a/lib/ts/recipe/totp/types.ts +++ b/lib/ts/recipe/totp/types.ts @@ -19,6 +19,9 @@ import { GeneralErrorResponse } from "../../types"; import { SessionContainerInterface } from "../session/types"; export type TypeInput = { + defaultSkew?: number; + defaultPeriod?: number; + override?: { functions?: ( originalImplementation: RecipeInterface, @@ -29,6 +32,9 @@ export type TypeInput = { }; export type TypeNormalisedInput = { + defaultSkew: number; + defaultPeriod: number; + override: { functions: ( originalImplementation: RecipeInterface, @@ -126,8 +132,6 @@ export type APIOptions = { export type APIInterface = { createDevicePOST: (input: { deviceName?: string; - period?: number; - skew?: number; options: APIOptions; session: SessionContainerInterface; userContext: any; diff --git a/lib/ts/recipe/totp/utils.ts b/lib/ts/recipe/totp/utils.ts index 5a0c3ef13..132f068e0 100644 --- a/lib/ts/recipe/totp/utils.ts +++ b/lib/ts/recipe/totp/utils.ts @@ -23,6 +23,9 @@ export function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalise }; return { + defaultSkew: config?.defaultSkew ?? 1, + defaultPeriod: config?.defaultPeriod ?? 30, + override, }; }