Skip to content

Commit

Permalink
fix: Update dashboard recipe user Get API (#464)
Browse files Browse the repository at this point in the history
* Add recipe not initialised status to dashboard user get API

* Update package version and CHANGELOG

* Update package version and CHANGELOG

* Changes based on PR review

* Changes based on PR review
  • Loading branch information
nkshah2 authored Dec 26, 2022
1 parent d07f864 commit 84843a0
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [12.1.4] - 2022-12-26

- Updates dashboard version
- Updates user GET API for the dashboard recipe

## [12.1.3] - 2022-12-12

- Updates some dependencies cause of `npm audit`
Expand Down
5 changes: 5 additions & 0 deletions lib/build/recipe/dashboard/api/userdetails/userGet.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ exports.userGet = (_, options) =>
type: error_1.default.BAD_INPUT_ERROR,
});
}
if (!utils_1.isRecipeInitialised(recipeId)) {
return {
status: "RECIPE_NOT_INITIALISED",
};
}
let user = (yield utils_1.getUserForRecipeId(userId, recipeId)).user;
if (user === undefined) {
return {
Expand Down
1 change: 1 addition & 0 deletions lib/build/recipe/dashboard/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export declare function getUserForRecipeId(
| "thirdpartypasswordless"
| undefined;
}>;
export declare function isRecipeInitialised(recipeId: RecipeIdForUser): boolean;
47 changes: 47 additions & 0 deletions lib/build/recipe/dashboard/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const emailpassword_1 = require("../emailpassword");
const thirdparty_1 = require("../thirdparty");
const passwordless_1 = require("../passwordless");
const thirdpartyemailpassword_1 = require("../thirdpartyemailpassword");
const recipe_4 = require("../thirdpartyemailpassword/recipe");
const thirdpartypasswordless_1 = require("../thirdpartypasswordless");
const recipe_5 = require("../thirdpartypasswordless/recipe");
function validateAndNormaliseUserInput(config) {
if (config.apiKey.trim().length === 0) {
throw new Error("apiKey provided to Dashboard recipe cannot be empty");
Expand Down Expand Up @@ -228,3 +230,48 @@ function getUserForRecipeId(userId, recipeId) {
});
}
exports.getUserForRecipeId = getUserForRecipeId;
function isRecipeInitialised(recipeId) {
let isRecipeInitialised = false;
if (recipeId === "emailpassword") {
try {
recipe_1.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
if (!isRecipeInitialised) {
try {
recipe_4.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
} else if (recipeId === "passwordless") {
try {
recipe_3.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
if (!isRecipeInitialised) {
try {
recipe_5.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
} else if (recipeId === "thirdparty") {
try {
recipe_2.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
if (!isRecipeInitialised) {
try {
recipe_4.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
if (!isRecipeInitialised) {
try {
recipe_5.default.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
}
return isRecipeInitialised;
}
exports.isRecipeInitialised = isRecipeInitialised;
4 changes: 2 additions & 2 deletions lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion lib/ts/recipe/dashboard/api/userdetails/userGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import {
ThirdPartyUser,
} from "../../types";
import STError from "../../../../error";
import { getUserForRecipeId, isValidRecipeId } from "../../utils";
import { getUserForRecipeId, isRecipeInitialised, isValidRecipeId } from "../../utils";
import UserMetaDataRecipe from "../../../usermetadata/recipe";
import UserMetaData from "../../../usermetadata";

type Response =
| {
status: "NO_USER_FOUND_ERROR";
}
| {
status: "RECIPE_NOT_INITIALISED";
}
| {
status: "OK";
recipeId: "emailpassword";
Expand Down Expand Up @@ -56,6 +59,12 @@ export const userGet: APIFunction = async (_: APIInterface, options: APIOptions)
});
}

if (!isRecipeInitialised(recipeId)) {
return {
status: "RECIPE_NOT_INITIALISED",
};
}

let user: EmailPasswordUser | ThirdPartyUser | PasswordlessUser | undefined = (
await getUserForRecipeId(userId, recipeId)
).user;
Expand Down
53 changes: 53 additions & 0 deletions lib/ts/recipe/dashboard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import EmailPassword from "../emailpassword";
import ThirdParty from "../thirdparty";
import Passwordless from "../passwordless";
import ThirdPartyEmailPassword from "../thirdpartyemailpassword";
import ThirdPartyEmailPasswordRecipe from "../thirdpartyemailpassword/recipe";
import ThirdPartyPasswordless from "../thirdpartypasswordless";
import ThirdPartyPasswordlessRecipe from "../thirdpartypasswordless/recipe";

export function validateAndNormaliseUserInput(config: TypeInput): TypeNormalisedInput {
if (config.apiKey.trim().length === 0) {
Expand Down Expand Up @@ -288,3 +290,54 @@ export async function getUserForRecipeId(
recipe,
};
}

export function isRecipeInitialised(recipeId: RecipeIdForUser): boolean {
let isRecipeInitialised = false;

if (recipeId === "emailpassword") {
try {
EmailPasswordRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}

if (!isRecipeInitialised) {
try {
ThirdPartyEmailPasswordRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
} else if (recipeId === "passwordless") {
try {
PasswordlessRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}

if (!isRecipeInitialised) {
try {
ThirdPartyPasswordlessRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
} else if (recipeId === "thirdparty") {
try {
ThirdPartyRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}

if (!isRecipeInitialised) {
try {
ThirdPartyEmailPasswordRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}

if (!isRecipeInitialised) {
try {
ThirdPartyPasswordlessRecipe.getInstanceOrThrowError();
isRecipeInitialised = true;
} catch (_) {}
}
}

return isRecipeInitialised;
}
4 changes: 2 additions & 2 deletions lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "12.1.3";
export const version = "12.1.4";

export const cdiSupported = ["2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15"];

// Note: The actual script import for dashboard uses v{DASHBOARD_VERSION}
export const dashboardVersion = "0.2";
export const dashboardVersion = "0.3";
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "12.1.3",
"version": "12.1.4",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 84843a0

Please sign in to comment.