From fe1a5b18b05e706c5367520ba110e924022c7f6b Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 20 Mar 2024 12:59:36 +0530 Subject: [PATCH 1/6] feat: Add BulkImport APIs and cron --- .../supertokens/pluginInterface/Storage.java | 2 + .../pluginInterface/StorageUtils.java | 9 ++ .../bulkimport/BulkImportStorage.java | 58 ++++++++ .../bulkimport/BulkImportUser.java | 132 ++++++++++++++++++ .../exceptions/DuplicateUserIdException.java | 21 +++ .../sqlStorage/BulkImportSQLStorage.java | 40 ++++++ 6 files changed, 262 insertions(+) create mode 100644 src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java create mode 100644 src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java create mode 100644 src/main/java/io/supertokens/pluginInterface/bulkimport/exceptions/DuplicateUserIdException.java create mode 100644 src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java diff --git a/src/main/java/io/supertokens/pluginInterface/Storage.java b/src/main/java/io/supertokens/pluginInterface/Storage.java index 51e28f57..c17cb931 100644 --- a/src/main/java/io/supertokens/pluginInterface/Storage.java +++ b/src/main/java/io/supertokens/pluginInterface/Storage.java @@ -32,6 +32,8 @@ public interface Storage { // if silent is true, do not log anything out on the console void constructor(String processId, boolean silent, boolean isTesting); + Storage createBulkImportProxyStorageInstance(); + void loadConfig(JsonObject jsonConfig, Set logLevels, TenantIdentifier tenantIdentifier) throws InvalidConfigException; // this returns a unique ID based on the db's connection URI and table prefix such that diff --git a/src/main/java/io/supertokens/pluginInterface/StorageUtils.java b/src/main/java/io/supertokens/pluginInterface/StorageUtils.java index 19bfb89a..9e6b4c99 100644 --- a/src/main/java/io/supertokens/pluginInterface/StorageUtils.java +++ b/src/main/java/io/supertokens/pluginInterface/StorageUtils.java @@ -17,6 +17,7 @@ package io.supertokens.pluginInterface; import io.supertokens.pluginInterface.authRecipe.sqlStorage.AuthRecipeSQLStorage; +import io.supertokens.pluginInterface.bulkimport.sqlStorage.BulkImportSQLStorage; import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage; import io.supertokens.pluginInterface.emailpassword.sqlStorage.EmailPasswordSQLStorage; import io.supertokens.pluginInterface.emailverification.sqlStorage.EmailVerificationSQLStorage; @@ -132,4 +133,12 @@ public static MultitenancyStorage getMultitenancyStorage(Storage storage) { } return (MultitenancyStorage) storage; } + + public static BulkImportSQLStorage getBulkImportStorage(Storage storage) { + if (storage.getType() != STORAGE_TYPE.SQL) { + // we only support SQL for now + throw new UnsupportedOperationException(""); + } + return (BulkImportSQLStorage) storage; + } } diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java new file mode 100644 index 00000000..246fc5ea --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -0,0 +1,58 @@ +/* + * 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; + +import java.util.List; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + + +import io.supertokens.pluginInterface.exceptions.StorageQueryException; +import io.supertokens.pluginInterface.multitenancy.AppIdentifier; +import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; +import io.supertokens.pluginInterface.nonAuthRecipe.NonAuthRecipeStorage; + +public interface BulkImportStorage extends NonAuthRecipeStorage { + /** + * Add users to the bulk_import_users table + */ + void addBulkImportUsers(AppIdentifier appIdentifier, List users) + throws StorageQueryException, + TenantOrAppNotFoundException, + io.supertokens.pluginInterface.bulkimport.exceptions.DuplicateUserIdException; + + /** + * Get users from the bulk_import_users table + */ + List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BULK_IMPORT_USER_STATUS status, + @Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException; + + /** + * Delete users by id from the bulk_import_users table + */ + List deleteBulkImportUsers(AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws StorageQueryException; + + /** + * Returns the users from the bulk_import_users table for processing + */ + List getBulkImportUsersForProcessing(AppIdentifier appIdentifier, @Nonnull Integer limit) throws StorageQueryException; + + public enum BULK_IMPORT_USER_STATUS { + NEW, PROCESSING, FAILED + } +} diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java new file mode 100644 index 00000000..d3f192e0 --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -0,0 +1,132 @@ +/* + * 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; + +import java.util.List; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BULK_IMPORT_USER_STATUS; + +public class BulkImportUser { + public String id; + public String externalUserId; + public JsonObject userMetadata; + public List userRoles; + public List totpDevices; + public List loginMethods; + + // Following fields come from the DB Record. + public BULK_IMPORT_USER_STATUS status; + public String errorMessage; + public Long createdAt; + public Long updatedAt; + + public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List userRoles, + List totpDevices, List loginMethods) { + this.id = id; + this.externalUserId = externalUserId; + this.userMetadata = userMetadata; + this.userRoles = userRoles; + this.totpDevices = totpDevices; + this.loginMethods = loginMethods; + } + + public static BulkImportUser forTesting_fromJson(JsonObject jsonObject) { + return new Gson().fromJson(jsonObject, BulkImportUser.class); + } + + // This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. + // It is used for inserting the user into the database or during testing. + public String toRawDataForDbStorage() { + JsonObject jsonObject = new Gson().fromJson(new Gson().toJson(this), JsonObject.class); + jsonObject.remove("status"); + jsonObject.remove("createdAt"); + jsonObject.remove("updatedAt"); + return jsonObject.toString(); + } + + public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, String errorMessage, long createdAt, long updatedAt) { + BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); + user.id = id; + user.status = status; + user.errorMessage = errorMessage; + user.createdAt = createdAt; + user.updatedAt = updatedAt; + return user; + } + + public JsonObject toJsonObject() { + return new Gson().fromJson(new Gson().toJson(this), JsonObject.class); + } + + public static class UserRole { + public String role; + public List tenantIds; + + public UserRole(String role, List tenantIds) { + this.role = role; + this.tenantIds = tenantIds; + } + } + + public static class TotpDevice { + public String secretKey; + public int period; + public int skew; + public String deviceName; + + public TotpDevice(String secretKey, int period, int skew, String deviceName) { + this.secretKey = secretKey; + this.period = period; + this.skew = skew; + this.deviceName = deviceName; + } + } + + public static class LoginMethod { + public List tenantIds; + public boolean isVerified; + public boolean isPrimary; + public long timeJoinedInMSSinceEpoch; + public String recipeId; + public String email; + public String passwordHash; + public String hashingAlgorithm; + public String thirdPartyId; + public String thirdPartyUserId; + public String phoneNumber; + public String superTokensOrExternalUserId; + + public LoginMethod(List tenantIds, String recipeId, boolean isVerified, boolean isPrimary, + long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm, + String thirdPartyId, String thirdPartyUserId, String phoneNumber) { + this.tenantIds = tenantIds; + this.recipeId = recipeId; + this.isVerified = isVerified; + this.isPrimary = isPrimary; + this.timeJoinedInMSSinceEpoch = timeJoinedInMSSinceEpoch; + this.email = email; + this.passwordHash = passwordHash; + this.hashingAlgorithm = hashingAlgorithm; + this.thirdPartyId = thirdPartyId; + this.thirdPartyUserId = thirdPartyUserId; + this.phoneNumber = phoneNumber; + } + } +} diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/exceptions/DuplicateUserIdException.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/exceptions/DuplicateUserIdException.java new file mode 100644 index 00000000..07070c15 --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/exceptions/DuplicateUserIdException.java @@ -0,0 +1,21 @@ +/* + * 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; + +public class DuplicateUserIdException extends Exception { + private static final long serialVersionUID = 6848053563771647272L; +} diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java new file mode 100644 index 00000000..4196c90e --- /dev/null +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java @@ -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.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; + +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[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException; + + /** + * Delete users by id from the bulk_import_users table + */ + void deleteBulkImportUser_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String bulkImportUserId) throws StorageQueryException; +} From 5bbb2bfefb4260683623b5594dc2364b55e755c8 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Thu, 21 Mar 2024 16:14:53 +0530 Subject: [PATCH 2/6] fix: PR changes --- .../pluginInterface/bulkimport/BulkImportStorage.java | 2 +- .../bulkimport/sqlStorage/BulkImportSQLStorage.java | 2 +- .../pluginInterface/sqlStorage/SQLStorage.java | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index 246fc5ea..15fa89ee 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -50,7 +50,7 @@ List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull In /** * Returns the users from the bulk_import_users table for processing */ - List getBulkImportUsersForProcessing(AppIdentifier appIdentifier, @Nonnull Integer limit) throws StorageQueryException; + List getBulkImportUsersAndChangeStatusToProcessing(AppIdentifier appIdentifier, @Nonnull Integer limit) throws StorageQueryException; public enum BULK_IMPORT_USER_STATUS { NEW, PROCESSING, FAILED diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java index 4196c90e..59212455 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java @@ -31,7 +31,7 @@ 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[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException; + TransactionConnection con, @Nonnull String bulkImportUserId, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException; /** * Delete users by id from the bulk_import_users table diff --git a/src/main/java/io/supertokens/pluginInterface/sqlStorage/SQLStorage.java b/src/main/java/io/supertokens/pluginInterface/sqlStorage/SQLStorage.java index d1351b30..740aa4b2 100644 --- a/src/main/java/io/supertokens/pluginInterface/sqlStorage/SQLStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/sqlStorage/SQLStorage.java @@ -45,4 +45,12 @@ interface TransactionLogic { public enum TransactionIsolationLevel { SERIALIZABLE, REPEATABLE_READ, READ_COMMITTED, READ_UNCOMMITTED, NONE } + + /* BulkImportProxyStorage methods */ + + void closeConnectionForBulkImportProxyStorage() throws StorageQueryException; + + void commitTransactionForBulkImportProxyStorage() throws StorageQueryException; + + void rollbackTransactionForBulkImportProxyStorage() throws StorageQueryException; } From 551df7eaebb9fa0c456feb88e84e49425a2d585f Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Fri, 29 Mar 2024 11:49:19 +0530 Subject: [PATCH 3/6] fix: PR changes --- .../pluginInterface/bulkimport/BulkImportStorage.java | 6 ++++++ .../pluginInterface/bulkimport/BulkImportUser.java | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index 15fa89ee..628b8c7a 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -52,6 +52,12 @@ List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull In */ List getBulkImportUsersAndChangeStatusToProcessing(AppIdentifier appIdentifier, @Nonnull Integer limit) throws StorageQueryException; + + /** + * Update the bulk_import_user's primary_user_id by bulk_import_user_id + */ + void updateBulkImportUserPrimaryUserId(AppIdentifier appIdentifier, @Nonnull String bulkImportUserId, @Nonnull String primaryUserId) throws StorageQueryException; + public enum BULK_IMPORT_USER_STATUS { NEW, PROCESSING, FAILED } diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index d3f192e0..5d929784 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -33,6 +33,7 @@ public class BulkImportUser { // Following fields come from the DB Record. public BULK_IMPORT_USER_STATUS status; + public String primaryUserId; public String errorMessage; public Long createdAt; public Long updatedAt; @@ -61,10 +62,11 @@ public String toRawDataForDbStorage() { return jsonObject.toString(); } - public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, String errorMessage, long createdAt, long updatedAt) { + public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, String primaryUserId, String errorMessage, long createdAt, long updatedAt) { BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); user.id = id; user.status = status; + user.primaryUserId = primaryUserId; user.errorMessage = errorMessage; user.createdAt = createdAt; user.updatedAt = updatedAt; @@ -111,7 +113,12 @@ public static class LoginMethod { public String thirdPartyId; public String thirdPartyUserId; public String phoneNumber; - public String superTokensOrExternalUserId; + public String superTokensUserId; + public String externalUserId; + + public String getSuperTokenOrExternalUserId() { + return this.externalUserId != null ? this.externalUserId : this.superTokensUserId; + } public LoginMethod(List tenantIds, String recipeId, boolean isVerified, boolean isPrimary, long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm, From 288ea58f715d58f22a083429355f32641de594c7 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Tue, 9 Apr 2024 17:59:24 +0530 Subject: [PATCH 4/6] fix: Update version and changelog --- CHANGELOG.md | 12 ++++++++++++ build.gradle | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73efa2e9..9aee0909 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [6.1.0] - 2024-04-10 + +### Added + +- Adds support for Bulk Import +- Adds `BulkImportUser` class to represent a bulk import user +- Adds `BulkImportStorage` interface +- Adds `DuplicateUserIdException` class +- Adds `createBulkImportProxyStorageInstance` method in `Storage` class +- Adds `closeConnectionForBulkImportProxyStorage`, `commitTransactionForBulkImportProxyStorage`, and `rollbackTransactionForBulkImportProxyStorage` method in `SQLStorage` class + + ## [6.0.0] - 2024-03-13 - Replace `TotpNotEnabledException` with `UnknownUserTotpIdException` diff --git a/build.gradle b/build.gradle index 72803d4c..239db1a8 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -version = "6.0.0" +version = "6.0.1" repositories { mavenCentral() From fbce954e30852a5e31d40c42f6a9cc28134e8227 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Thu, 18 Apr 2024 15:56:26 +0530 Subject: [PATCH 5/6] fix: PR changes --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 239db1a8..2158e809 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ plugins { id 'java-library' } -version = "6.0.1" +version = "6.1.0" repositories { mavenCentral() From 02f37da2898dcd954a0ba9c1be19c89295b9accc Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 29 May 2024 12:46:06 +0530 Subject: [PATCH 6/6] fix: PR changes --- .../bulkimport/BulkImportStorage.java | 6 +++++- .../bulkimport/BulkImportUser.java | 16 +++++++++++++--- .../sqlStorage/BulkImportSQLStorage.java | 5 ----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java index 628b8c7a..492d199f 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportStorage.java @@ -21,7 +21,6 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; - import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException; @@ -58,6 +57,11 @@ List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull In */ void updateBulkImportUserPrimaryUserId(AppIdentifier appIdentifier, @Nonnull String bulkImportUserId, @Nonnull String primaryUserId) throws StorageQueryException; + /** + * Returns the count of users from the bulk_import_users table + */ + long getBulkImportUsersCount(AppIdentifier appIdentifier, @Nullable BULK_IMPORT_USER_STATUS status) throws StorageQueryException; + public enum BULK_IMPORT_USER_STATUS { NEW, PROCESSING, FAILED } diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java index 5d929784..dff8ac57 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/BulkImportUser.java @@ -52,8 +52,12 @@ public static BulkImportUser forTesting_fromJson(JsonObject jsonObject) { return new Gson().fromJson(jsonObject, BulkImportUser.class); } - // This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. - // It is used for inserting the user into the database or during testing. + // The bulk_import_users table stores users to be imported via a Cron Job. + // It has a `raw_data` column containing user data in JSON format. + + // The BulkImportUser class represents this `raw_data`, including additional fields like `status`, `createdAt`, and `updatedAt`. + // First, we validate all fields of `raw_data` using the BulkImportUser class, then store this data in the bulk_import_users table. + // This function retrieves the `raw_data` after removing the additional fields. public String toRawDataForDbStorage() { JsonObject jsonObject = new Gson().fromJson(new Gson().toJson(this), JsonObject.class); jsonObject.remove("status"); @@ -62,6 +66,10 @@ public String toRawDataForDbStorage() { return jsonObject.toString(); } + // The bulk_import_users table contains a `raw_data` column with user data in JSON format, along with other columns such as `id`, `status`, `primary_user_id`, and `error_msg` etc. + + // When creating an instance of the BulkImportUser class, the extra fields must be passed separately as they are not part of the `raw_data`. + // This function creates a BulkImportUser instance from a stored bulk_import_user entry. public static BulkImportUser fromRawDataFromDbStorage(String id, String rawData, BULK_IMPORT_USER_STATUS status, String primaryUserId, String errorMessage, long createdAt, long updatedAt) { BulkImportUser user = new Gson().fromJson(rawData, BulkImportUser.class); user.id = id; @@ -110,6 +118,7 @@ public static class LoginMethod { public String email; public String passwordHash; public String hashingAlgorithm; + public String plainTextPassword; public String thirdPartyId; public String thirdPartyUserId; public String phoneNumber; @@ -121,7 +130,7 @@ public String getSuperTokenOrExternalUserId() { } public LoginMethod(List tenantIds, String recipeId, boolean isVerified, boolean isPrimary, - long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm, + long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm, String plainTextPassword, String thirdPartyId, String thirdPartyUserId, String phoneNumber) { this.tenantIds = tenantIds; this.recipeId = recipeId; @@ -131,6 +140,7 @@ public LoginMethod(List tenantIds, String recipeId, boolean isVerified, this.email = email; this.passwordHash = passwordHash; this.hashingAlgorithm = hashingAlgorithm; + this.plainTextPassword = plainTextPassword; this.thirdPartyId = thirdPartyId; this.thirdPartyUserId = thirdPartyUserId; this.phoneNumber = phoneNumber; diff --git a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java index 59212455..a7d1fff3 100644 --- a/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java +++ b/src/main/java/io/supertokens/pluginInterface/bulkimport/sqlStorage/BulkImportSQLStorage.java @@ -32,9 +32,4 @@ public interface BulkImportSQLStorage extends BulkImportStorage, SQLStorage { */ void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String bulkImportUserId, @Nonnull BULK_IMPORT_USER_STATUS status, @Nullable String errorMessage) throws StorageQueryException; - - /** - * Delete users by id from the bulk_import_users table - */ - void deleteBulkImportUser_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String bulkImportUserId) throws StorageQueryException; }