Skip to content

Commit

Permalink
fix: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Nov 10, 2023
1 parent 84f0d27 commit c72528f
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 37 deletions.
10 changes: 0 additions & 10 deletions lib/build/recipe/totp/api/createDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/build/recipe/totp/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/totp/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/build/recipe/totp/recipeImplementation.d.ts
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 4 additions & 1 deletion lib/build/recipe/totp/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},
Expand Down
6 changes: 4 additions & 2 deletions lib/build/recipe/totp/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,6 +15,8 @@ export declare type TypeInput = {
};
};
export declare type TypeNormalisedInput = {
defaultSkew: number;
defaultPeriod: number;
override: {
functions: (
originalImplementation: RecipeInterface,
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions lib/build/recipe/totp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
}
Expand Down
12 changes: 0 additions & 12 deletions lib/ts/recipe/totp/api/createDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions lib/ts/recipe/totp/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},
Expand Down
4 changes: 3 additions & 1 deletion lib/ts/recipe/totp/recipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 5 additions & 1 deletion lib/ts/recipe/totp/recipeImplementation.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions lib/ts/recipe/totp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { GeneralErrorResponse } from "../../types";
import { SessionContainerInterface } from "../session/types";

export type TypeInput = {
defaultSkew?: number;
defaultPeriod?: number;

override?: {
functions?: (
originalImplementation: RecipeInterface,
Expand All @@ -29,6 +32,9 @@ export type TypeInput = {
};

export type TypeNormalisedInput = {
defaultSkew: number;
defaultPeriod: number;

override: {
functions: (
originalImplementation: RecipeInterface,
Expand Down Expand Up @@ -126,8 +132,6 @@ export type APIOptions = {
export type APIInterface = {
createDevicePOST: (input: {
deviceName?: string;
period?: number;
skew?: number;
options: APIOptions;
session: SessionContainerInterface;
userContext: any;
Expand Down
3 changes: 3 additions & 0 deletions lib/ts/recipe/totp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function validateAndNormaliseUserInput(config?: TypeInput): TypeNormalise
};

return {
defaultSkew: config?.defaultSkew ?? 1,
defaultPeriod: config?.defaultPeriod ?? 30,

override,
};
}

0 comments on commit c72528f

Please sign in to comment.