Skip to content

Commit

Permalink
End UM beta (#238)
Browse files Browse the repository at this point in the history
* User Management support (#212)

* Add Beta SDKs section in README.md (#213)

* Add Beta SDKs section in README.md

* Nit/typo

* Nit in section about Beta releases in the README.md (#214)

* Nit in section about Beta releases in the README.md

* Improvement to README.md

* Update README.md

* User Management support

* Update version (#215)

* Add Beta SDKs section in README.md (#213)

* Add Beta SDKs section in README.md

* Nit/typo

* Nit in section about Beta releases in the README.md (#214)

* Nit in section about Beta releases in the README.md

* Improvement to README.md

* Update README.md

* Update version

* Fix release script (Beta branch) (#217)

* Add Beta SDKs section in README.md (#213)

* Add Beta SDKs section in README.md

* Nit/typo

* Nit in section about Beta releases in the README.md (#214)

* Nit in section about Beta releases in the README.md

* Improvement to README.md

* Update README.md

* Fix typo in release script

* Add organization membership events (#218)

Add organization membership events.

* Update beta version (#219)

* Add events and API changes for invitations and Magic Auth (#221)

* Add events and API changes for invitations and Magic Auth

* Fix failing test

* Rename event data

* v3.1.0-beta.user-management3 (#222)

* Add organization membership deactivate and reactivate API methods. (#226)

* Bump to version 3.1.0-beta.user-management4. (#227)

* Add methods and events for email verification and password reset (#228)

* v3.1.0-beta.user-management5 (#229)

* Add find invitation by token method (#230)

* Fix list endpoints (#236)

* Now correctly parsing data as params for GET requests

* Value has to be a string

* lol linting

* 3.1.0-beta.user-management6 (#233)

* `invitationCode` should be `invitationToken` (#237)

---------

Co-authored-by: amadeo <165715960+amadeo-workos@users.noreply.github.com>
Co-authored-by: Matt Dzwonczyk <9063128+mattgd@users.noreply.github.com>
Co-authored-by: Blair Lunceford <74257063+blairlunceford@users.noreply.github.com>
Co-authored-by: Michael Hadley <m@mthadley.com>
  • Loading branch information
5 people committed Jul 19, 2024
1 parent 6b236ee commit 183792d
Show file tree
Hide file tree
Showing 93 changed files with 5,483 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# Ignore IntelliJ projects
.idea
.settings/org.eclipse.jdt.core.prefs

# Ignore Eclipse projects
.project
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ WorkOS workos = new WorkOS("WORKOS_API_KEY");
// workos.passwordless
// workos.portal
// workos.sso
// workos.userManagement
// workos.webhooks
```

Expand All @@ -79,5 +80,6 @@ can move to using the stable version.

- [Single Sign-On Guide](https://workos.com/docs/sso/guide)
- [Directory Sync Guide](https://workos.com/docs/directory-sync/guide)
- [User Management](https://workos.com/docs/user-management/guide)
- [Admin Portal Guide](https://workos.com/docs/admin-portal/guide)
- [Magic Link Guide](https://workos.com/docs/magic-link/guide)
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import java.io.FileOutputStream
import java.util.Properties

group = "com.workos"
version = "3.1.0"
version = "4.0.0"

if (!project.hasProperty("release")) {
version = "$version-SNAPSHOT"
Expand Down Expand Up @@ -40,6 +40,8 @@ dependencies {

implementation("com.github.kittinunf.fuel:fuel:2.3.1")

implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.0")

testImplementation("org.jetbrains.kotlin:kotlin-test")

testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/com/workos/WorkOS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.workos.organizations.OrganizationsApi
import com.workos.passwordless.PasswordlessApi
import com.workos.portal.PortalApi
import com.workos.sso.SsoApi
import com.workos.usermanagement.UserManagementApi
import com.workos.webhooks.WebhooksApi
import org.apache.http.client.utils.URIBuilder
import java.lang.IllegalArgumentException
Expand Down Expand Up @@ -95,6 +96,12 @@ class WorkOS(
@JvmField
val mfa = MfaApi(this)

/**
* Module for interacting with the User Management API.
*/
@JvmField
val userManagement = UserManagementApi(this)

/**
* Module for interacting with the Webhooks API.
*/
Expand Down Expand Up @@ -255,17 +262,21 @@ class WorkOS(
val responseData = mapper.readValue(payload, BadRequestExceptionResponse::class.java)
throw BadRequestException(responseData.message, responseData.code, responseData.errors, requestId)
}

401 -> {
val responseData = mapper.readValue(payload, GenericErrorResponse::class.java)
throw UnauthorizedException(responseData.message, requestId)
}

404 -> {
throw NotFoundException(response.url.path, requestId)
}

422 -> {
val unprocessableEntityException = mapper.readValue(payload, UnprocessableEntityExceptionResponse::class.java)
throw UnprocessableEntityException(unprocessableEntityException.message, unprocessableEntityException.code, unprocessableEntityException.errors, requestId)
}

else -> {
val responseData = mapper.readValue(payload, GenericErrorResponse::class.java)
throw GenericServerException(responseData.message, status, requestId)
Expand Down
50 changes: 32 additions & 18 deletions src/main/kotlin/com/workos/common/http/RequestConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.workos.common.http

import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.memberProperties

/**
* Configuration for HTTP Requests.
*
Expand All @@ -12,44 +16,54 @@ class RequestConfig(
val headers: Map<String, String>? = null,
val data: Any? = null
) {
/**
* @suppress
*/
/** @suppress */
companion object {
@JvmStatic
fun builder(): RequestConfigBuilder {
return RequestConfigBuilder()
}

/** Helper method for converting data into params. */
infix fun <T : Any> toMap(obj: T): Map<String, Any?> {
val params =
(obj::class as KClass<T>).memberProperties.associate { prop: KProperty1<T, *> ->
prop.name.toSnakeCase() to
prop.get(obj)?.let { value ->
if (value::class.isData) {
toMap(value)
} else {
value.toString()
}
}
}

return params.filterValues { it != null }
}

/** Convert camel case to snake case. */
fun String.toSnakeCase() = replace(humps, "_").lowercase()

private val humps = "(?<=.)(?=\\p{Upper})".toRegex()
}

/**
* Builder class for creating [RequestConfig].
*/
/** Builder class for creating [RequestConfig]. */
class RequestConfigBuilder {
private var params: Map<String, String> = emptyMap()

private var headers: Map<String, String> = emptyMap()

private var data: Any? = null

/**
* Set the request parameters.
*/
/** Set the request parameters. */
fun params(value: Map<String, String>) = apply { params = value }

/**
* Set the request headers.
*/
/** Set the request headers. */
fun headers(value: Map<String, String?>) = apply { headers = value as Map<String, String> }

/**
* Set the request body.
*/
/** Set the request body. */
fun data(value: Any) = apply { data = value }

/**
* Creates an instance of [RequestConfig] with the given params.
*/
/** Creates an instance of [RequestConfig] with the given params. */
fun build(): RequestConfig {
return RequestConfig(params, headers, data)
}
Expand Down
Loading

0 comments on commit 183792d

Please sign in to comment.