Skip to content

Commit

Permalink
adds types for recipe interface
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 8, 2023
1 parent 81b48ca commit e9db988
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
6 changes: 3 additions & 3 deletions recipe/accountlinking/accountlinkingmodels/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ type AccountInfo struct {
supertokens.AccountInfoWithRecipeID
}

type ShouldDoAutomaticAccountLinkingResult struct {
type ShouldDoAutomaticAccountLinkingResponse struct {
ShouldAutomaticallyLink bool
ShouldRequireVerification bool
}

type TypeInput struct {
OnAccountLinked func(user supertokens.User, newAccountUser supertokens.RecipeLevelUser, userContext supertokens.UserContext) error
ShouldDoAutomaticAccountLinking func(newAccountInfo AccountInfo, user *supertokens.User, tenantID string, userContext supertokens.UserContext) (ShouldDoAutomaticAccountLinkingResult, error)
ShouldDoAutomaticAccountLinking func(newAccountInfo AccountInfo, user *supertokens.User, tenantID string, userContext supertokens.UserContext) (ShouldDoAutomaticAccountLinkingResponse, error)
Override *OverrideStruct
}

type TypeNormalisedInput struct {
OnAccountLinked func(user supertokens.User, newAccountUser supertokens.RecipeLevelUser, userContext supertokens.UserContext) error
ShouldDoAutomaticAccountLinking func(newAccountInfo AccountInfo, user *supertokens.User, tenantID string, userContext supertokens.UserContext) (ShouldDoAutomaticAccountLinkingResult, error)
ShouldDoAutomaticAccountLinking func(newAccountInfo AccountInfo, user *supertokens.User, tenantID string, userContext supertokens.UserContext) (ShouldDoAutomaticAccountLinkingResponse, error)
Override OverrideStruct
}

Expand Down
91 changes: 90 additions & 1 deletion recipe/accountlinking/accountlinkingmodels/recipeInterface.go
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 @@ -15,5 +15,94 @@

package accountlinkingmodels

import "github.com/supertokens/supertokens-golang/supertokens"

type UserPaginationResult struct {
Users []supertokens.User
NextPaginationToken *string
}

type CanCreatePrimaryUserResponse struct {
OK *struct {
WasAlreadyAPrimaryUser bool
}
RecipeUserIdAlreadyLinkedWithPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
}

type CreatePrimaryUserResponse struct {
OK *struct {
User supertokens.User
WasAlreadyAPrimaryUser bool
}
RecipeUserIdAlreadyLinkedWithPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
}

type CanLinkAccountResponse struct {
OK *struct {
AccountsAlreadyLinked bool
}
RecipeUserIdAlreadyLinkedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
InputUserIsNotAPrimaryUserError *struct{}
}

type LinkAccountResponse struct {
OK *struct {
AccountsAlreadyLinked bool
User supertokens.User
}
RecipeUserIdAlreadyLinkedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
User supertokens.User
}
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
InputUserIsNotAPrimaryUserError *struct{}
}

type UnlinkAccountsResponse struct {
WasRecipeUserDeleted bool
WasLinked bool
}

type RecipeInterface struct {
GetUsersWithSearchParams *func(tenantID string, timeJoinedOrder string, paginationToken *string, limit *int, includeRecipeIds *[]string, searchParams map[string]string, userContext supertokens.UserContext) (UserPaginationResult, error)

CanCreatePrimaryUser *func(recipeUserId supertokens.RecipeUserID, userContext supertokens.UserContext) (CanCreatePrimaryUserResponse, error)

CreatePrimaryUser *func(recipeUserId supertokens.RecipeUserID, userContext supertokens.UserContext) (CreatePrimaryUserResponse, error)

CanLinkAccounts *func(recipeUserId supertokens.RecipeUserID, primaryUserId string, userContext supertokens.UserContext) (CanLinkAccountResponse, error)

LinkAccounts *func(recipeUserId supertokens.RecipeUserID, primaryUserId string, userContext supertokens.UserContext) (LinkAccountResponse, error)

UnlinkAccounts *func(recipeUserId supertokens.RecipeUserID, userContext supertokens.UserContext) (UnlinkAccountsResponse, error)

GetUser *func(userId string, userContext supertokens.UserContext) (*supertokens.User, error)

ListUsersByAccountInfo *func(tenantID string, accountInfo supertokens.AccountInfo, doUnionOfAccountInfo bool, userContext supertokens.UserContext) ([]supertokens.User, error)

DeleteUser *func(userId string, removeAllLinkedAccounts bool, userContext supertokens.UserContext) error
}
6 changes: 3 additions & 3 deletions supertokens/recipeUserId.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ type RecipeUserID struct {
recipeUserID string
}

func NewRecipeUserID(recipeUserID string) (*RecipeUserID, error) {
func NewRecipeUserID(recipeUserID string) (RecipeUserID, error) {
if recipeUserID == "" {
return nil, errors.New("recipeUserID cannot be empty")
return RecipeUserID{}, errors.New("recipeUserID cannot be empty")
}
return &RecipeUserID{recipeUserID: recipeUserID}, nil
return RecipeUserID{recipeUserID: recipeUserID}, nil
}

func (r *RecipeUserID) GetAsString() string {
Expand Down

0 comments on commit e9db988

Please sign in to comment.