Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
59 changes: 55 additions & 4 deletions src/main/kotlin/com/workos/organizations/OrganizationsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class OrganizationsApi(private val workos: WorkOS) {
* @param allowProfilesOutsideOrganization Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization's User Email Domains.
* @param domainData A list of data for the domains of the organization.
* @param domains A list of domains for the organization.
* @param externalId The external identifier of the organization.
* @param metadata Object containing metadata key/value pairs associated with the organization.
*/
@JsonInclude(Include.NON_NULL)
class CreateOrganizationOptions @JvmOverloads constructor(
Expand All @@ -36,7 +38,13 @@ class OrganizationsApi(private val workos: WorkOS) {
val domainData: List<OrganizationDomainDataOptions>? = null,

@Deprecated("Use domainData instead.")
val domains: List<String>? = null
val domains: List<String>? = null,

@JsonProperty("external_id")
val externalId: String? = null,

@JsonProperty("metadata")
val metadata: Map<String, String>? = null
) {
/**
* Builder class for creating [CreateOrganizationOptions].
Expand All @@ -50,6 +58,10 @@ class OrganizationsApi(private val workos: WorkOS) {

private var domains: List<String>? = null

private var externalId: String? = null

private var metadata: Map<String, String>? = null

/**
* Sets the name of the organization.
*/
Expand All @@ -72,11 +84,21 @@ class OrganizationsApi(private val workos: WorkOS) {
@Deprecated("Use domainData instead.")
fun domains(value: List<String>) = apply { domains = value }

/**
* Sets the external identifier of the organization.
*/
fun externalId(value: String) = apply { externalId = value }

/**
* Sets the metadata for the organization.
*/
fun metadata(value: Map<String, String>) = apply { metadata = value }

/**
* Creates an instance of [CreateOrganizationOptions] with the given params.
*/
fun build(): CreateOrganizationOptions {
return CreateOrganizationOptions(name, allowProfilesOutsideOrganization, domainData, domains)
return CreateOrganizationOptions(name, allowProfilesOutsideOrganization, domainData, domains, externalId, metadata)
}
}

Expand Down Expand Up @@ -158,6 +180,13 @@ class OrganizationsApi(private val workos: WorkOS) {
return workos.get("/organizations/$id", Organization::class.java)
}

/**
* Fetches a single organization by external ID.
*/
fun getOrganizationByExternalId(externalId: String): Organization {
return workos.get("/organizations/external_id/$externalId", Organization::class.java)
}

/**
* Parameters for [listOrganizations] method.
* Use `ListOrganizationsOptions.builder()` to create a new builder instance.
Expand Down Expand Up @@ -220,6 +249,8 @@ class OrganizationsApi(private val workos: WorkOS) {
* @param allowProfilesOutsideOrganization Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization's User Email Domains.
* @param domainData A list of data for the domains of the organization.
* @param domains A list of domains for the organization.
* @param externalId The external identifier of the organization.
* @param metadata Object containing metadata key/value pairs associated with the organization.
*/
@JsonInclude(Include.NON_NULL)
class UpdateOrganizationOptions @JvmOverloads constructor(
Expand All @@ -232,7 +263,13 @@ class OrganizationsApi(private val workos: WorkOS) {
val domainData: List<OrganizationDomainDataOptions>? = null,

@Deprecated("Use domainData instead.")
val domains: List<String>? = null
val domains: List<String>? = null,

@JsonProperty("external_id")
val externalId: String? = null,

@JsonProperty("metadata")
val metadata: Map<String, String>? = null
) {
/**
* Builder class for [UpdateOrganizationOptions].
Expand All @@ -246,6 +283,10 @@ class OrganizationsApi(private val workos: WorkOS) {

private var domains: List<String>? = null

private var externalId: String? = null

private var metadata: Map<String, String>? = null

/**
* Sets the name of the organization.
*/
Expand All @@ -268,11 +309,21 @@ class OrganizationsApi(private val workos: WorkOS) {
@Deprecated("Use domainData instead.")
fun domains(value: List<String>) = apply { domains = value }

/**
* Sets the external identifier of the organization.
*/
fun externalId(value: String) = apply { externalId = value }

/**
* Sets the metadata for the organization.
*/
fun metadata(value: Map<String, String>) = apply { metadata = value }

/**
* Creates an instance of [UpdateOrganizationOptions].
*/
fun build(): UpdateOrganizationOptions {
return UpdateOrganizationOptions(name, allowProfilesOutsideOrganization, domainData, domains)
return UpdateOrganizationOptions(name, allowProfilesOutsideOrganization, domainData, domains, externalId, metadata)
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/workos/organizations/models/Organization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.fasterxml.jackson.annotation.JsonProperty
* @param obj The unique object identifier type of the record.
* @param id The unique identifier for the Organization.
* @param name The name of the Organization.
* @param externalId The external ID of the Organization.
* @param metadata A JSON object containing additional information about the organization.
* @param allowProfilesOutsideOrganization Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization's User Email Domains.
* @param domains List of [OrganizationDomain]s.
* @param createdAt The timestamp of when the Organization was created.
Expand All @@ -27,6 +29,14 @@ data class Organization
@JvmField
val name: String,

@JvmField
@JsonProperty("external_id")
val externalId: String? = null,

@JvmField
@JsonProperty("metadata")
val metadata: Map<String, String>? = null,

@JvmField
@JsonProperty("allow_profiles_outside_organization")
val allowProfilesOutsideOrganization: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class UserManagementApi(private val workos: WorkOS) {
return workos.get("/user_management/users/$userId", User::class.java)
}

/** Get the details of an existing user by external ID. */
fun getUserByExternalId(externalId: String): User {
return workos.get("/user_management/users/external_id/$externalId", User::class.java)
}

/** Get a list of all the existing users matching the criteria specified. */
fun listUsers(options: ListUsersOptions? = null): Users {
val params: Map<String, String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import com.workos.usermanagement.types.PasswordHashTypeEnumType
* @param passwordHashType The algorithm originally used to hash the password, used when providing a password_hash.
* @param firstName The first name of the user.
* @param lastName The last name of the user.
* @param emailVerified Whether the user’s email address was previously verified.
* @param emailVerified Whether the user's email address was previously verified.
* @param externalId The external identifier of the user.
* @param metadata Object containing metadata key/value pairs associated with the user.
*/
class CreateUserOptionsBuilder @JvmOverloads constructor(
val email: String,
Expand All @@ -22,6 +24,8 @@ class CreateUserOptionsBuilder @JvmOverloads constructor(
override var firstName: String? = null,
override var lastName: String? = null,
override var emailVerified: Boolean? = null,
var externalId: String? = null,
var metadata: Map<String, String>? = null
) : AbstractUserOptionsBuilder<CreateUserOptions>(
password,
passwordHash,
Expand All @@ -30,6 +34,16 @@ class CreateUserOptionsBuilder @JvmOverloads constructor(
lastName,
emailVerified
) {
/**
* Sets the external identifier of the user.
*/
fun externalId(value: String) = apply { externalId = value }

/**
* Sets the metadata for the user.
*/
fun metadata(value: Map<String, String>) = apply { metadata = value }

/**
* Generates the CreateUserOptions object.
*/
Expand All @@ -42,6 +56,8 @@ class CreateUserOptionsBuilder @JvmOverloads constructor(
firstName = this.firstName,
lastName = this.lastName,
emailVerified = this.emailVerified,
externalId = this.externalId,
metadata = this.metadata
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import com.workos.usermanagement.types.UpdateUserOptions
* @param email The email address of the user.
* @param firstName The first name of the user.
* @param lastName The last name of the user.
* @param emailVerified Whether the users email address was previously verified.
* @param emailVerified Whether the user's email address was previously verified.
* @param password The password to set for the user.
* @param passwordHash The hashed password to set for the user. Mutually exclusive with password.
* @param passwordHashType The algorithm originally used to hash the password, used when providing a password_hash.
* @param externalId The external identifier of the user.
* @param metadata Object containing metadata key/value pairs associated with the user.
*/
class UpdateUserOptionsBuilder @JvmOverloads constructor(
val id: String,
Expand All @@ -24,6 +26,8 @@ class UpdateUserOptionsBuilder @JvmOverloads constructor(
override var password: String? = null,
override var passwordHash: String? = null,
override var passwordHashType: PasswordHashTypeEnumType? = null,
var externalId: String? = null,
var metadata: Map<String, String>? = null
) : AbstractUserOptionsBuilder<UpdateUserOptions>(
password,
passwordHash,
Expand All @@ -45,6 +49,8 @@ class UpdateUserOptionsBuilder @JvmOverloads constructor(
password = this.password,
passwordHash = this.passwordHash,
passwordHashType = this.passwordHashType,
externalId = this.externalId,
metadata = this.metadata
)
}

Expand All @@ -53,6 +59,16 @@ class UpdateUserOptionsBuilder @JvmOverloads constructor(
*/
fun email(value: String) = apply { email = value }

/**
* Sets the external identifier of the user.
*/
fun externalId(value: String) = apply { externalId = value }

/**
* Sets the metadata for the user.
*/
fun metadata(value: Map<String, String>) = apply { metadata = value }

/**
* @suppress
*/
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/com/workos/usermanagement/models/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import com.fasterxml.jackson.annotation.JsonProperty
* @param email The email address of the user.
* @param firstName The first name of the user.
* @param lastName The last name of the user.
* @param emailVerified Whether the user’s email has been verified.
* @param externalId The external ID of the user.
* @param metadata A JSON object containing additional information about the user.
* @param emailVerified Whether the user's email has been verified.
* @param profilePictureUrl A URL reference to an image representing the user.
* @param lastSignInAt The timestamp when the user last signed in.
* @param createdAt The timestamp when the user was created.
Expand All @@ -29,6 +31,12 @@ data class User @JsonCreator constructor(
@JsonProperty("last_name")
val lastName: String? = null,

@JsonProperty("external_id")
val externalId: String? = null,

@JsonProperty("metadata")
val metadata: Map<String, String>? = null,

@JsonProperty("email_verified")
val emailVerified: Boolean,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,24 @@ class CreateUserOptions @JvmOverloads constructor(
val lastName: String? = null,

/**
* Whether the users email address was previously verified.
* Whether the user's email address was previously verified.
*
* You should normally use the email verification flow to verify a users email address. However, if the users email was previously verified, or is being migrated from an existing user store, this can be set to true to mark it as already verified.
* You should normally use the email verification flow to verify a user's email address. However, if the user's email was previously verified, or is being migrated from an existing user store, this can be set to true to mark it as already verified.
*/
@JsonProperty("email_verified")
val emailVerified: Boolean? = null
val emailVerified: Boolean? = null,

/**
* The external identifier of the user.
*/
@JsonProperty("external_id")
val externalId: String? = null,

/**
* Object containing metadata key/value pairs associated with the user.
*/
@JsonProperty("metadata")
val metadata: Map<String, String>? = null
) {
init {
require(email.isNotBlank()) { "Email is required" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ class UpdateUserOptions @JvmOverloads constructor(
* The algorithm originally used to hash the password, used when providing a password_hash.
*/
@JsonProperty("password_hash_type")
val passwordHashType: PasswordHashTypeEnumType? = null
val passwordHashType: PasswordHashTypeEnumType? = null,

/**
* The external identifier of the user.
*/
@JsonProperty("external_id")
val externalId: String? = null,

/**
* Object containing metadata key/value pairs associated with the user.
*/
@JsonProperty("metadata")
val metadata: Map<String, String>? = null
) {
init {
require(id.isNotBlank()) { "User id is required" }
Expand Down
Loading