Skip to content

Commit 84843a0

Browse files
authored
fix: Update dashboard recipe user Get API (#464)
* 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
1 parent d07f864 commit 84843a0

File tree

11 files changed

+130
-10
lines changed

11 files changed

+130
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [12.1.4] - 2022-12-26
11+
12+
- Updates dashboard version
13+
- Updates user GET API for the dashboard recipe
14+
1015
## [12.1.3] - 2022-12-12
1116

1217
- Updates some dependencies cause of `npm audit`

lib/build/recipe/dashboard/api/userdetails/userGet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ exports.userGet = (_, options) =>
5757
type: error_1.default.BAD_INPUT_ERROR,
5858
});
5959
}
60+
if (!utils_1.isRecipeInitialised(recipeId)) {
61+
return {
62+
status: "RECIPE_NOT_INITIALISED",
63+
};
64+
}
6065
let user = (yield utils_1.getUserForRecipeId(userId, recipeId)).user;
6166
if (user === undefined) {
6267
return {

lib/build/recipe/dashboard/utils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export declare function getUserForRecipeId(
2828
| "thirdpartypasswordless"
2929
| undefined;
3030
}>;
31+
export declare function isRecipeInitialised(recipeId: RecipeIdForUser): boolean;

lib/build/recipe/dashboard/utils.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ const emailpassword_1 = require("../emailpassword");
5555
const thirdparty_1 = require("../thirdparty");
5656
const passwordless_1 = require("../passwordless");
5757
const thirdpartyemailpassword_1 = require("../thirdpartyemailpassword");
58+
const recipe_4 = require("../thirdpartyemailpassword/recipe");
5859
const thirdpartypasswordless_1 = require("../thirdpartypasswordless");
60+
const recipe_5 = require("../thirdpartypasswordless/recipe");
5961
function validateAndNormaliseUserInput(config) {
6062
if (config.apiKey.trim().length === 0) {
6163
throw new Error("apiKey provided to Dashboard recipe cannot be empty");
@@ -228,3 +230,48 @@ function getUserForRecipeId(userId, recipeId) {
228230
});
229231
}
230232
exports.getUserForRecipeId = getUserForRecipeId;
233+
function isRecipeInitialised(recipeId) {
234+
let isRecipeInitialised = false;
235+
if (recipeId === "emailpassword") {
236+
try {
237+
recipe_1.default.getInstanceOrThrowError();
238+
isRecipeInitialised = true;
239+
} catch (_) {}
240+
if (!isRecipeInitialised) {
241+
try {
242+
recipe_4.default.getInstanceOrThrowError();
243+
isRecipeInitialised = true;
244+
} catch (_) {}
245+
}
246+
} else if (recipeId === "passwordless") {
247+
try {
248+
recipe_3.default.getInstanceOrThrowError();
249+
isRecipeInitialised = true;
250+
} catch (_) {}
251+
if (!isRecipeInitialised) {
252+
try {
253+
recipe_5.default.getInstanceOrThrowError();
254+
isRecipeInitialised = true;
255+
} catch (_) {}
256+
}
257+
} else if (recipeId === "thirdparty") {
258+
try {
259+
recipe_2.default.getInstanceOrThrowError();
260+
isRecipeInitialised = true;
261+
} catch (_) {}
262+
if (!isRecipeInitialised) {
263+
try {
264+
recipe_4.default.getInstanceOrThrowError();
265+
isRecipeInitialised = true;
266+
} catch (_) {}
267+
}
268+
if (!isRecipeInitialised) {
269+
try {
270+
recipe_5.default.getInstanceOrThrowError();
271+
isRecipeInitialised = true;
272+
} catch (_) {}
273+
}
274+
}
275+
return isRecipeInitialised;
276+
}
277+
exports.isRecipeInitialised = isRecipeInitialised;

lib/build/version.d.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/version.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/recipe/dashboard/api/userdetails/userGet.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ import {
77
ThirdPartyUser,
88
} from "../../types";
99
import STError from "../../../../error";
10-
import { getUserForRecipeId, isValidRecipeId } from "../../utils";
10+
import { getUserForRecipeId, isRecipeInitialised, isValidRecipeId } from "../../utils";
1111
import UserMetaDataRecipe from "../../../usermetadata/recipe";
1212
import UserMetaData from "../../../usermetadata";
1313

1414
type Response =
1515
| {
1616
status: "NO_USER_FOUND_ERROR";
1717
}
18+
| {
19+
status: "RECIPE_NOT_INITIALISED";
20+
}
1821
| {
1922
status: "OK";
2023
recipeId: "emailpassword";
@@ -56,6 +59,12 @@ export const userGet: APIFunction = async (_: APIInterface, options: APIOptions)
5659
});
5760
}
5861

62+
if (!isRecipeInitialised(recipeId)) {
63+
return {
64+
status: "RECIPE_NOT_INITIALISED",
65+
};
66+
}
67+
5968
let user: EmailPasswordUser | ThirdPartyUser | PasswordlessUser | undefined = (
6069
await getUserForRecipeId(userId, recipeId)
6170
).user;

lib/ts/recipe/dashboard/utils.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ import EmailPassword from "../emailpassword";
4646
import ThirdParty from "../thirdparty";
4747
import Passwordless from "../passwordless";
4848
import ThirdPartyEmailPassword from "../thirdpartyemailpassword";
49+
import ThirdPartyEmailPasswordRecipe from "../thirdpartyemailpassword/recipe";
4950
import ThirdPartyPasswordless from "../thirdpartypasswordless";
51+
import ThirdPartyPasswordlessRecipe from "../thirdpartypasswordless/recipe";
5052

5153
export function validateAndNormaliseUserInput(config: TypeInput): TypeNormalisedInput {
5254
if (config.apiKey.trim().length === 0) {
@@ -288,3 +290,54 @@ export async function getUserForRecipeId(
288290
recipe,
289291
};
290292
}
293+
294+
export function isRecipeInitialised(recipeId: RecipeIdForUser): boolean {
295+
let isRecipeInitialised = false;
296+
297+
if (recipeId === "emailpassword") {
298+
try {
299+
EmailPasswordRecipe.getInstanceOrThrowError();
300+
isRecipeInitialised = true;
301+
} catch (_) {}
302+
303+
if (!isRecipeInitialised) {
304+
try {
305+
ThirdPartyEmailPasswordRecipe.getInstanceOrThrowError();
306+
isRecipeInitialised = true;
307+
} catch (_) {}
308+
}
309+
} else if (recipeId === "passwordless") {
310+
try {
311+
PasswordlessRecipe.getInstanceOrThrowError();
312+
isRecipeInitialised = true;
313+
} catch (_) {}
314+
315+
if (!isRecipeInitialised) {
316+
try {
317+
ThirdPartyPasswordlessRecipe.getInstanceOrThrowError();
318+
isRecipeInitialised = true;
319+
} catch (_) {}
320+
}
321+
} else if (recipeId === "thirdparty") {
322+
try {
323+
ThirdPartyRecipe.getInstanceOrThrowError();
324+
isRecipeInitialised = true;
325+
} catch (_) {}
326+
327+
if (!isRecipeInitialised) {
328+
try {
329+
ThirdPartyEmailPasswordRecipe.getInstanceOrThrowError();
330+
isRecipeInitialised = true;
331+
} catch (_) {}
332+
}
333+
334+
if (!isRecipeInitialised) {
335+
try {
336+
ThirdPartyPasswordlessRecipe.getInstanceOrThrowError();
337+
isRecipeInitialised = true;
338+
} catch (_) {}
339+
}
340+
}
341+
342+
return isRecipeInitialised;
343+
}

lib/ts/version.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
* License for the specific language governing permissions and limitations
1313
* under the License.
1414
*/
15-
export const version = "12.1.3";
15+
export const version = "12.1.4";
1616

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

1919
// Note: The actual script import for dashboard uses v{DASHBOARD_VERSION}
20-
export const dashboardVersion = "0.2";
20+
export const dashboardVersion = "0.3";

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "supertokens-node",
3-
"version": "12.1.3",
3+
"version": "12.1.4",
44
"description": "NodeJS driver for SuperTokens core",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)