supertokens-web-js
Version:
SuperTokens SDK for vanilla JS for all recipes
160 lines (159 loc) • 6.5 kB
JavaScript
;
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
var __assign =
(this && this.__assign) ||
function () {
__assign =
Object.assign ||
function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.listDevices =
exports.removeDevice =
exports.verifyDevice =
exports.verifyCode =
exports.createDevice =
exports.init =
void 0;
var utils_1 = require("../../utils");
var recipe_1 = require("./recipe");
var RecipeWrapper = /** @class */ (function () {
function RecipeWrapper() {}
RecipeWrapper.init = function (config) {
return recipe_1.default.init(config);
};
/**
* Creates a new unverified device.
*
* @param deviceName (OPTIONAL) A display name for the device
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}
*
* @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks)
*
* @returns `{ status: "OK", ...}` if successful along a description of the created device (secret, etc.)
*/
RecipeWrapper.createDevice = function (input) {
return recipe_1.default.getInstanceOrThrow().recipeImplementation.createDevice(
__assign(__assign({}, input), {
userContext: (0, utils_1.getNormalisedUserContext)(
input === null || input === void 0 ? void 0 : input.userContext
),
})
);
};
/**
* Verifies that the totp code belongs to a verified device of the current user
*
* @param totp The TOTP code
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}
*
* @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks)
*
* @returns `{ status: "OK", ...}` if successful
*/
RecipeWrapper.verifyCode = function (input) {
return recipe_1.default.getInstanceOrThrow().recipeImplementation.verifyCode(
__assign(__assign({}, input), {
userContext: (0, utils_1.getNormalisedUserContext)(
input === null || input === void 0 ? void 0 : input.userContext
),
})
);
};
/**
* Verifies the totp device for the current user
*
* @param deviceName The name of the device we are verifying
*
* @param totp The TOTP code
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}
*
* @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks)
*
* @returns `{ status: "OK", ...}` if successful
*/
RecipeWrapper.verifyDevice = function (input) {
return recipe_1.default.getInstanceOrThrow().recipeImplementation.verifyDevice(
__assign(__assign({}, input), {
userContext: (0, utils_1.getNormalisedUserContext)(
input === null || input === void 0 ? void 0 : input.userContext
),
})
);
};
/**
* Removes a TOTP device
*
* @param deviceName The name of the device we are verifying
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}
*
* @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks)
*
* @returns `{ status: "OK", ...}` if successful
*/
RecipeWrapper.removeDevice = function (input) {
return recipe_1.default.getInstanceOrThrow().recipeImplementation.removeDevice(
__assign(__assign({}, input), {
userContext: (0, utils_1.getNormalisedUserContext)(
input === null || input === void 0 ? void 0 : input.userContext
),
})
);
};
/**
* Lists all TOTP devices of the current user
*
* @param userContext (OPTIONAL) Refer to {@link https://supertokens.com/docs/emailpassword/advanced-customizations/user-context the documentation}
*
* @param options (OPTIONAL) Use this to configure additional properties (for example pre api hooks)
*
* @returns `{ status: "OK", ...}` if successful with a list of devices in the `devices` prop
*/
RecipeWrapper.listDevices = function (input) {
return recipe_1.default.getInstanceOrThrow().recipeImplementation.listDevices(
__assign(__assign({}, input), {
userContext: (0, utils_1.getNormalisedUserContext)(
input === null || input === void 0 ? void 0 : input.userContext
),
})
);
};
return RecipeWrapper;
})();
exports.default = RecipeWrapper;
var init = RecipeWrapper.init;
exports.init = init;
var createDevice = RecipeWrapper.createDevice;
exports.createDevice = createDevice;
var verifyCode = RecipeWrapper.verifyCode;
exports.verifyCode = verifyCode;
var verifyDevice = RecipeWrapper.verifyDevice;
exports.verifyDevice = verifyDevice;
var removeDevice = RecipeWrapper.removeDevice;
exports.removeDevice = removeDevice;
var listDevices = RecipeWrapper.listDevices;
exports.listDevices = listDevices;