Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add interfaces and types for bulk import #138

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void addBulkImportUsers(AppIdentifier appIdentifier, List<BulkImportUser> users)
/**
* Get users from the bulk_import_users table
*/
List<BulkImportUserInfo> getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status,
List<BulkImportUser> getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status,
@Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BulkImportUserStatus;

public class BulkImportUser {
public String id;
public String externalUserId;
Expand All @@ -29,7 +31,13 @@ public class BulkImportUser {
public List<TotpDevice> totpDevices;
public List<LoginMethod> loginMethods;

public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<String> userRoles, List<TotpDevice> totpDevices, List<LoginMethod> loginMethods) {
// Following fields come from the DB Record.
public BulkImportUserStatus status;
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
public Long createdAt;
public Long updatedAt;

public BulkImportUser(String id, String externalUserId, JsonObject userMetadata, List<String> userRoles,
List<TotpDevice> totpDevices, List<LoginMethod> loginMethods) {
this.id = id;
this.externalUserId = externalUserId;
this.userMetadata = userMetadata;
Expand All @@ -38,17 +46,25 @@ public BulkImportUser(String id, String externalUserId, JsonObject userMetadata,
this.loginMethods = loginMethods;
}

public String toString() {
Gson gson = new Gson();
JsonObject json = new JsonObject();
public static BulkImportUser fromJson(JsonObject jsonObject) {
return new Gson().fromJson(jsonObject, BulkImportUser.class);
}
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved

json.addProperty("externalUserId", externalUserId);
json.add("userMetadata", userMetadata);
json.add("roles", gson.toJsonTree(userRoles));
json.add("totp", gson.toJsonTree(totpDevices));
json.add("loginMethods", gson.toJsonTree(loginMethods));
public String toString() {
return new Gson().toJson(this);
}
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved

return json.toString();
// This method returns a JSON object string representation, excluding 'status', 'createdAt', and 'updatedAt'. Useful for test comparisons.
public String toRawData() {
rishabhpoddar marked this conversation as resolved.
Show resolved Hide resolved
JsonObject jsonObject = new Gson().fromJson(this.toString(), JsonObject.class);
jsonObject.remove("status");
jsonObject.remove("createdAt");
jsonObject.remove("updatedAt");
return jsonObject.toString();
}

public JsonObject toJsonObject() {
return new Gson().fromJson(this.toString(), JsonObject.class);
}

public static class TotpDevice {
Expand All @@ -71,54 +87,27 @@ public static class LoginMethod {
public boolean isPrimary;
public long timeJoinedInMSSinceEpoch;
public String recipeId;

public EmailPasswordLoginMethod emailPasswordLoginMethod;
public ThirdPartyLoginMethod thirdPartyLoginMethod;
public PasswordlessLoginMethod passwordlessLoginMethod;

public LoginMethod(String tenantId, String recipeId, boolean isVerified, boolean isPrimary, long timeJoinedInMSSinceEpoch, EmailPasswordLoginMethod emailPasswordLoginMethod, ThirdPartyLoginMethod thirdPartyLoginMethod, PasswordlessLoginMethod passwordlessLoginMethod) {
public String email;
public String passwordHash;
public String hashingAlgorithm;
public String thirdPartyId;
public String thirdPartyUserId;
public String phoneNumber;

public LoginMethod(String tenantId, String recipeId, boolean isVerified, boolean isPrimary,
long timeJoinedInMSSinceEpoch, String email, String passwordHash, String hashingAlgorithm,
String thirdPartyId, String thirdPartyUserId, String phoneNumber) {
this.tenantId = tenantId;
this.recipeId = recipeId;
this.isVerified = isVerified;
this.isPrimary = isPrimary;
this.timeJoinedInMSSinceEpoch = timeJoinedInMSSinceEpoch;
this.emailPasswordLoginMethod = emailPasswordLoginMethod;
this.thirdPartyLoginMethod = thirdPartyLoginMethod;
this.passwordlessLoginMethod = passwordlessLoginMethod;
}

public static class EmailPasswordLoginMethod {
public String email;
public String passwordHash;
public String hashingAlgorithm;

public EmailPasswordLoginMethod(String email, String passwordHash, String hashingAlgorithm) {
this.email = email;
this.passwordHash = passwordHash;
this.hashingAlgorithm = hashingAlgorithm;
}
}

public static class ThirdPartyLoginMethod {
public String email;
public String thirdPartyId;
public String thirdPartyUserId;

public ThirdPartyLoginMethod(String email, String thirdPartyId, String thirdPartyUserId) {
this.email = email;
this.thirdPartyId = thirdPartyId;
this.thirdPartyUserId = thirdPartyUserId;
}
}

public static class PasswordlessLoginMethod {
public String email;
public String phoneNumber;

public PasswordlessLoginMethod(String email, String phoneNumber) {
this.email = email;
this.phoneNumber = phoneNumber;
}
this.email = email;
this.passwordHash = passwordHash;
this.hashingAlgorithm = hashingAlgorithm;
this.thirdPartyId = thirdPartyId;
this.thirdPartyUserId = thirdPartyUserId;
this.phoneNumber = phoneNumber;
}
}
}

This file was deleted.

Loading