Skip to content

Commit

Permalink
fix: fixes and error handling changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamassoltesz committed Nov 22, 2024
1 parent 714e4c7 commit 8f6ba14
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/supertokens/pluginInterface/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface Storage {
Expand Down Expand Up @@ -80,6 +81,9 @@ void setKeyValue(TenantIdentifier tenantIdentifier, String key, KeyValueInfo inf
boolean isUserIdBeingUsedInNonAuthRecipe(AppIdentifier appIdentifier, String className, String userId)
throws StorageQueryException;

Map<String, List<String>> findNonAuthRecipesWhereForUserIdsUsed(AppIdentifier appIdentifier, List<String> userIds)
throws StorageQueryException;

// to be used for testing purposes only. This function will add dummy data to non-auth tables.
void addInfoToNonAuthRecipesBasedOnUserId(TenantIdentifier tenantIdentifier, String className, String userId)
throws StorageQueryException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.List;

public interface AuthRecipeStorage extends Storage {

Expand All @@ -45,6 +46,8 @@ AuthRecipeUserInfo[] getUsers(TenantIdentifier tenantIdentifier, @Nonnull Intege

boolean doesUserIdExist(TenantIdentifier tenantIdentifierIdentifier, String userId) throws StorageQueryException;

List<String> findExistingUserIds(AppIdentifier appIdentifier, List<String> userIds) throws StorageQueryException;

AuthRecipeUserInfo getPrimaryUserById(AppIdentifier appIdentifier, String userId) throws StorageQueryException;

String getPrimaryUserIdStrForUserId(AppIdentifier appIdentifier, String userId) throws StorageQueryException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ AuthRecipeUserInfo[] listPrimaryUsersByEmail_Transaction(AppIdentifier appIdenti
String email)
throws StorageQueryException;

//helper method for bulk import
AuthRecipeUserInfo[] listPrimaryUsersByMultipleEmailsOrPhoneNumbersOrThirdparty_Transaction(AppIdentifier appIdentifier,
TransactionConnection con,
List<String> emails, List<String> phones,
Map<String, String> thirdpartyIdToThirdpartyUserId)
throws StorageQueryException;

// locks only passwordless table
AuthRecipeUserInfo[] listPrimaryUsersByPhoneNumber_Transaction(AppIdentifier appIdentifier,
TransactionConnection con, String phoneNumber)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024, 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.
*/

package io.supertokens.pluginInterface.bulkimport.exceptions;

import java.util.Map;

//In case of batch inserting when one
public class BulkImportBatchInsertException extends Exception {
public Map<String, Exception> exceptionByUserId;

public BulkImportBatchInsertException(String message, Map<String, Exception> exceptionByPosition) {
super(message);
this.exceptionByUserId = exceptionByPosition;
}

public BulkImportBatchInsertException(String message, Throwable cause,
Map<String, Exception> exceptionByPosition) {
super(message, cause);
this.exceptionByUserId = exceptionByPosition;
}

public BulkImportBatchInsertException(Throwable cause, Map<String, Exception> exceptionByPosition) {
super(cause);
this.exceptionByUserId = exceptionByPosition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@

package io.supertokens.pluginInterface.bulkimport.sqlStorage;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import io.supertokens.pluginInterface.bulkimport.BulkImportStorage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;

public interface BulkImportSQLStorage extends BulkImportStorage, SQLStorage {

/**
* Update the status of the users in the bulk_import_users table
*/
void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier,
TransactionConnection con, @Nonnull String bulkImportUserId, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException;

void updateMultipleBulkImportUsersStatusToError_Transaction(AppIdentifier appIdentifier,
TransactionConnection con, @Nonnull Map<String, String> bulkImportUserIdToErrorMessage) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateUserIdException;
import io.supertokens.pluginInterface.emailpassword.exceptions.UnknownUserIdException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;

import java.util.List;

public interface EmailPasswordStorage extends AuthRecipeStorage {

// we pass tenantIdentifier here cause this also adds to the userId <-> tenantId mapping
Expand All @@ -38,10 +35,6 @@ AuthRecipeUserInfo signUp(TenantIdentifier tenantIdentifier, String id, String e
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException;

void signUpMultiple(List<EmailPasswordImportUser> users)
throws StorageQueryException, DuplicateUserIdException, DuplicateEmailException,
TenantOrAppNotFoundException, StorageTransactionLogicException;

// password reset stuff is app wide cause changing the password for a user affects all the tenants
// across which it's shared.
void addPasswordResetToken(AppIdentifier appIdentifier, PasswordResetTokenInfo passwordResetTokenInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package io.supertokens.pluginInterface.emailpassword.sqlStorage;

import io.supertokens.pluginInterface.emailpassword.EmailPasswordImportUser;
import io.supertokens.pluginInterface.emailpassword.EmailPasswordStorage;
import io.supertokens.pluginInterface.emailpassword.PasswordResetTokenInfo;
import io.supertokens.pluginInterface.emailpassword.exceptions.DuplicateEmailException;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;

import java.util.List;

public interface EmailPasswordSQLStorage extends EmailPasswordStorage, SQLStorage {

// all password reset related stuff is app wide cause the same user ID can be shared across tenants,
Expand All @@ -49,4 +53,7 @@ void updateUsersEmail_Transaction(AppIdentifier appIdentifier, TransactionConnec
void deleteEmailPasswordUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean deleteUserIdMappingToo)
throws StorageQueryException;

void signUpMultipleViaBulkImport_Transaction(TransactionConnection connection, List<EmailPasswordImportUser> users)
throws StorageQueryException, StorageTransactionLogicException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage;

import java.util.Map;

public interface EmailVerificationStorage extends NonAuthRecipeStorage {

void addEmailVerificationToken(TenantIdentifier tenantIdentifier, EmailVerificationTokenInfo emailVerificationInfo)
Expand All @@ -49,4 +51,7 @@ EmailVerificationTokenInfo[] getAllEmailVerificationTokenInfoForUser(TenantIdent

void updateIsEmailVerifiedToExternalUserId(AppIdentifier appIdentifier, String supertokensUserId,
String externalUserId) throws StorageQueryException;

void updateMultipleIsEmailVerifiedToExternalUserIds(AppIdentifier appIdentifier,
Map<String, String> supertokensUserIdToExternalUserId) throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.passwordless.PasswordlessCode;
import io.supertokens.pluginInterface.passwordless.PasswordlessDevice;
import io.supertokens.pluginInterface.passwordless.PasswordlessImportUser;
Expand All @@ -31,7 +32,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;

public interface PasswordlessSQLStorage extends PasswordlessStorage, SQLStorage {
PasswordlessDevice getDevice_Transaction(TenantIdentifier tenantIdentifier, TransactionConnection con,
Expand Down Expand Up @@ -88,6 +89,6 @@ void deletePasswordlessUser_Transaction(TransactionConnection con, AppIdentifier
boolean deleteUserIdMappingToo)
throws StorageQueryException;

void importPasswordlessUsers_Transaction(TransactionConnection con, Collection<PasswordlessImportUser> users)
throws StorageQueryException;
void importPasswordlessUsers_Transaction(TransactionConnection con, List<PasswordlessImportUser> users)
throws StorageQueryException, TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;

import java.sql.SQLException;

public interface SQLStorage extends Storage {
<T> T startTransaction(TransactionLogic<T> logic, TransactionIsolationLevel isolationLevel)
throws StorageQueryException, StorageTransactionLogicException;
Expand All @@ -40,7 +42,8 @@ KeyValueInfo getKeyValue_Transaction(TenantIdentifier tenantIdentifier, Transact

interface TransactionLogic<T> {
T mainLogicAndCommit(TransactionConnection con)
throws StorageQueryException, StorageTransactionLogicException, TenantOrAppNotFoundException;
throws StorageQueryException, StorageTransactionLogicException, TenantOrAppNotFoundException,
SQLException;
}

public enum TransactionIsolationLevel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package io.supertokens.pluginInterface.thirdparty.sqlStorage;

import io.supertokens.pluginInterface.exceptions.StorageQueryException;
import io.supertokens.pluginInterface.exceptions.StorageTransactionLogicException;
import io.supertokens.pluginInterface.multitenancy.AppIdentifier;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.sqlStorage.SQLStorage;
import io.supertokens.pluginInterface.sqlStorage.TransactionConnection;
import io.supertokens.pluginInterface.thirdparty.ThirdPartyImportUser;
import io.supertokens.pluginInterface.thirdparty.ThirdPartyStorage;

import java.util.Collection;
import java.util.List;

public interface ThirdPartySQLStorage extends ThirdPartyStorage, SQLStorage {

Expand All @@ -35,6 +37,6 @@ void deleteThirdPartyUser_Transaction(TransactionConnection con, AppIdentifier a
boolean deleteUserIdMappingToo)
throws StorageQueryException;

void importThirdPartyUsers_Transaction(TransactionConnection con, Collection<ThirdPartyImportUser> usersToImport)
throws StorageQueryException;
void importThirdPartyUsers_Transaction(TransactionConnection con, List<ThirdPartyImportUser> usersToImport)
throws StorageQueryException, StorageTransactionLogicException, TenantOrAppNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public interface UserIdMappingStorage extends Storage {

Expand All @@ -35,6 +36,10 @@ void createUserIdMapping(AppIdentifier appIdentifier, String superTokensUserId,
@Nullable String externalUserIdInfo)
throws StorageQueryException, UnknownSuperTokensUserIdException, UserIdMappingAlreadyExistsException;

// support method for bulk migration
void createBulkUserIdMapping(AppIdentifier appIdentifier, Map<String,String> superTokensUserIdToExternalUserId)
throws StorageQueryException;

boolean deleteUserIdMapping(AppIdentifier appIdentifier, String userId, boolean isSuperTokensUserId)
throws StorageQueryException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@
import io.supertokens.pluginInterface.useridmapping.UserIdMapping;
import io.supertokens.pluginInterface.useridmapping.UserIdMappingStorage;

import java.util.List;

public interface UserIdMappingSQLStorage extends UserIdMappingStorage, SQLStorage {
UserIdMapping getUserIdMapping_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId,
boolean isSuperTokensUserId)
throws StorageQueryException;

UserIdMapping[] getUserIdMapping_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

List<UserIdMapping> getMultipleUserIdMapping_Transaction(TransactionConnection connection, AppIdentifier appIdentifier,
List<String> userIds, boolean isSupertokensIds)
throws StorageQueryException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.supertokens.pluginInterface.userroles.UserRolesStorage;
import io.supertokens.pluginInterface.userroles.exception.UnknownRoleException;

import java.util.List;
import java.util.Map;

public interface UserRolesSQLStorage extends UserRolesStorage, SQLStorage {
Expand Down Expand Up @@ -56,6 +57,9 @@ int deleteAllPermissionsForRole_Transaction(AppIdentifier appIdentifier, Transac
boolean doesRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnection con, String role)
throws StorageQueryException;

List<Boolean> doesMultipleRoleExist_Transaction(AppIdentifier appIdentifier, TransactionConnection con, List<String> roles)
throws StorageQueryException;

void deleteAllRolesForUser_Transaction(TransactionConnection con, AppIdentifier appIdentifier, String userId)
throws StorageQueryException;

Expand Down

0 comments on commit 8f6ba14

Please sign in to comment.