Skip to content

Commit

Permalink
feat: Account linking interface update (#463)
Browse files Browse the repository at this point in the history
* recipe interface changes for account linking

* user context update

* types update

* Update lib/ts/recipe/accountlinking/types.ts

Co-authored-by: Rishabh Poddar <rishabh.poddar@gmail.com>

* Update lib/ts/recipe/accountlinking/types.ts

Co-authored-by: Rishabh Poddar <rishabh.poddar@gmail.com>

* Update lib/ts/recipe/accountlinking/types.ts

Co-authored-by: Rishabh Poddar <rishabh.poddar@gmail.com>

Co-authored-by: Rishabh Poddar <rishabh.poddar@gmail.com>
  • Loading branch information
bhumilsarvaiya and rishabhpoddar authored Dec 30, 2022
1 parent 7973b8c commit 1d98e90
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 10 deletions.
28 changes: 28 additions & 0 deletions lib/build/recipe/accountlinking/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ export declare type TypeNormalisedInput = {
};
export declare type APIInterface = {};
export declare type RecipeInterface = {
getRecipeUserIdsForPrimaryUserIds: (input: {
primaryUserIds: string[];
userContext: any;
}) => Promise<{
[primaryUserId: string]: string[];
}>;
getPrimaryUserIdsforRecipeUserIds: (input: {
recipeUserIds: string[];
userContext: any;
}) => Promise<{
[recipeUserId: string]: string | null;
}>;
addNewRecipeUserIdWithoutPrimaryUserId: (input: {
recipeUserId: string;
recipeId: string;
timeJoined: number;
userContext: any;
}) => Promise<void>;
getUsers: (input: {
timeJoinedOrder: "ASC" | "DESC";
limit?: number;
paginationToken?: string;
includeRecipeIds?: string[];
userContext: any;
}) => Promise<{
users: User[];
nextPaginationToken?: string;
}>;
canCreatePrimaryUserId: (input: {
recipeUserId: string;
userContext: any;
Expand Down
41 changes: 40 additions & 1 deletion lib/build/supertokens.js

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

2 changes: 1 addition & 1 deletion lib/ts/recipe/accountlinking/recipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
/* Copyright (c) 2023, 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.
Expand Down
43 changes: 36 additions & 7 deletions lib/ts/recipe/accountlinking/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
/* Copyright (c) 2023, 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.
Expand All @@ -14,7 +14,7 @@
*/

import OverrideableBuilder from "supertokens-js-override";
import { User } from "../../types";
import type { User } from "../../types";
import { SessionContainer } from "../session";

export type TypeInput = {
Expand All @@ -39,7 +39,6 @@ export type TypeInput = {
originalImplementation: RecipeInterface,
builder?: OverrideableBuilder<RecipeInterface>
) => RecipeInterface;
apis?: (originalImplementation: APIInterface, builder?: OverrideableBuilder<APIInterface>) => APIInterface;
};
};

Expand All @@ -65,13 +64,43 @@ export type TypeNormalisedInput = {
originalImplementation: RecipeInterface,
builder?: OverrideableBuilder<RecipeInterface>
) => RecipeInterface;
apis: (originalImplementation: APIInterface, builder?: OverrideableBuilder<APIInterface>) => APIInterface;
};
};

export type APIInterface = {};

export type RecipeInterface = {
getRecipeUserIdsForPrimaryUserIds: (input: {
primaryUserIds: string[];
userContext: any;
}) => Promise<{
[primaryUserId: string]: string[]; // recipeUserIds. If input primary user ID doesn't exists, those ids will not be part of the output set.
}>;
getPrimaryUserIdsforRecipeUserIds: (input: {
recipeUserIds: string[];
userContext: any;
}) => Promise<{
[recipeUserId: string]: string | null; // if recipeUserId doesn't have a primaryUserId, then it will be mapped to `null`. If the input recipeUserId doesn't exist, then it won't be a part of the map
}>;
addNewRecipeUserIdWithoutPrimaryUserId: (input: {
recipeUserId: string;
recipeId: string;
timeJoined: number;
userContext: any;
}) => Promise<{
status: "OK",
createdNewEntry: boolean
} | {
status: "RECIPE_USER_ID_ALREADY_LINKED_WITH_ANOTHER_PRIMARY_USER_ID_ERROR"
}>;
getUsers: (input: {
timeJoinedOrder: "ASC" | "DESC";
limit?: number;
paginationToken?: string;
includeRecipeIds?: string[];
userContext: any;
}) => Promise<{
users: User[];
nextPaginationToken?: string;
}>;
canCreatePrimaryUserId: (input: {
recipeUserId: string;
userContext: any;
Expand Down Expand Up @@ -158,7 +187,7 @@ export type RecipeInterface = {
}>;
};

type RecipeLevelUser = {
export type RecipeLevelUser = {
recipeId: "emailpassword" | "thirdparty" | "passwordless";
id: string; // can be recipeUserId or primaryUserId
timeJoined: number;
Expand Down
41 changes: 40 additions & 1 deletion lib/ts/supertokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,46 @@ export default class SuperTokens {
};

listUsersByAccountInfo = async (_input: { info: AccountInfo }): Promise<User[] | undefined> => {
// TODO
/**
* if input is only email:
* let emailPasswordUser = emailpassword.getUserByEmail(email);
*
* let thirdpartyUsers = thirdparty.getUsersByEmail(email);
*
* let passwordlessUser = passwordless.getUserByEmail(email);
*
* let recipeUsers = [];
*
* if (emailPasswordUser !== undefined) {
* recipeUsers.push(emailPasswordUser);
* }
*
* recipeUsers.push(...thirdpartyUsers);
*
* if (passwordlessUser !== undefined) {
* recipeUsers.push(passwordlessUser);
* }
*
* let recipeUserIds = recipeUsers.map(r => r.id);
*
* let primaryUserIdMapping: {recipeUserId: primaryUserId} = getPrimaryUserIdsforRecipeUserIds(recipeUserIds);
*
* let result: {id: User | User[]} = {};
*
* for (let i = 0; i < recipeUsers.length; i++) {
* if (primaryUserIdMapping[recipeUsers[i].id] === undefined) {
* result[recipeUsers[i].id] = recipeUsers[i];
* } else {
* let pUserId = primaryUserIdMapping[recipeUsers[i].id];
* if (result[pUserId] === undefined) {
* result[pUserId] = [];
* }
* result[pUserId].push(recipeUsers[i]);
* }
* }
*
*
*/
return;
};

Expand Down

0 comments on commit 1d98e90

Please sign in to comment.