All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.stytch.java.b2b.api.organizationsmembers.OrganizationsMembers.kt Maven / Gradle / Ivy

package com.stytch.java.b2b.api.organizationsmembers

// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.stytch.java.b2b.api.organizationsmembersoauthproviders.OAuthProviders
import com.stytch.java.b2b.api.organizationsmembersoauthproviders.OAuthProvidersImpl
import com.stytch.java.b2b.models.organizationsmembers.CreateRequest
import com.stytch.java.b2b.models.organizationsmembers.CreateRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.CreateResponse
import com.stytch.java.b2b.models.organizationsmembers.DangerouslyGetRequest
import com.stytch.java.b2b.models.organizationsmembers.DeleteMFAPhoneNumberRequest
import com.stytch.java.b2b.models.organizationsmembers.DeleteMFAPhoneNumberRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.DeleteMFAPhoneNumberResponse
import com.stytch.java.b2b.models.organizationsmembers.DeletePasswordRequest
import com.stytch.java.b2b.models.organizationsmembers.DeletePasswordRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.DeletePasswordResponse
import com.stytch.java.b2b.models.organizationsmembers.DeleteRequest
import com.stytch.java.b2b.models.organizationsmembers.DeleteRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.DeleteResponse
import com.stytch.java.b2b.models.organizationsmembers.DeleteTOTPRequest
import com.stytch.java.b2b.models.organizationsmembers.DeleteTOTPRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.DeleteTOTPResponse
import com.stytch.java.b2b.models.organizationsmembers.GetRequest
import com.stytch.java.b2b.models.organizationsmembers.GetResponse
import com.stytch.java.b2b.models.organizationsmembers.ReactivateRequest
import com.stytch.java.b2b.models.organizationsmembers.ReactivateRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.ReactivateResponse
import com.stytch.java.b2b.models.organizationsmembers.SearchRequest
import com.stytch.java.b2b.models.organizationsmembers.SearchRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.SearchResponse
import com.stytch.java.b2b.models.organizationsmembers.UnlinkRetiredEmailRequest
import com.stytch.java.b2b.models.organizationsmembers.UnlinkRetiredEmailRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.UnlinkRetiredEmailResponse
import com.stytch.java.b2b.models.organizationsmembers.UpdateRequest
import com.stytch.java.b2b.models.organizationsmembers.UpdateRequestOptions
import com.stytch.java.b2b.models.organizationsmembers.UpdateResponse
import com.stytch.java.common.InstantAdapter
import com.stytch.java.common.StytchResult
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.CompletableFuture

public interface Members {
    public val oauthProviders: OAuthProviders

    /**
     * Updates a specified by `organization_id` and `member_id`.
     */
    public suspend fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
    ): StytchResult

    /**
     * Updates a specified by `organization_id` and `member_id`.
     */
    public fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Updates a specified by `organization_id` and `member_id`.
     */
    public fun updateCompletable(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Deletes a specified by `organization_id` and `member_id`.
     */
    public suspend fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
    ): StytchResult

    /**
     * Deletes a specified by `organization_id` and `member_id`.
     */
    public fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Deletes a specified by `organization_id` and `member_id`.
     */
    public fun deleteCompletable(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Reactivates a deleted's status and its associated email status (if applicable) to active, specified by
     * `organization_id` and `member_id`.
     */
    public suspend fun reactivate(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions? = null,
    ): StytchResult

    /**
     * Reactivates a deleted's status and its associated email status (if applicable) to active, specified by
     * `organization_id` and `member_id`.
     */
    public fun reactivate(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Reactivates a deleted's status and its associated email status (if applicable) to active, specified by
     * `organization_id` and `member_id`.
     */
    public fun reactivateCompletable(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Delete a's MFA phone number.
     *
     * To change a Member's phone number, you must first call this endpoint to delete the existing phone number.
     *
     * Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is
     * deleted, and MFA will not be enforced until the Member logs in again.
     * If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter
     * a new phone number
     * and calling the [OTP SMS send](https://stytch.com/docs/b2b/api/otp-sms-send) endpoint, then calling the
     * [OTP SMS Authenticate](https://stytch.com/docs/b2b/api/authenticate-otp-sms) endpoint.
     */
    public suspend fun deleteMFAPhoneNumber(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions? = null,
    ): StytchResult

    /**
     * Delete a's MFA phone number.
     *
     * To change a Member's phone number, you must first call this endpoint to delete the existing phone number.
     *
     * Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is
     * deleted, and MFA will not be enforced until the Member logs in again.
     * If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter
     * a new phone number
     * and calling the [OTP SMS send](https://stytch.com/docs/b2b/api/otp-sms-send) endpoint, then calling the
     * [OTP SMS Authenticate](https://stytch.com/docs/b2b/api/authenticate-otp-sms) endpoint.
     */
    public fun deleteMFAPhoneNumber(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a's MFA phone number.
     *
     * To change a Member's phone number, you must first call this endpoint to delete the existing phone number.
     *
     * Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is
     * deleted, and MFA will not be enforced until the Member logs in again.
     * If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter
     * a new phone number
     * and calling the [OTP SMS send](https://stytch.com/docs/b2b/api/otp-sms-send) endpoint, then calling the
     * [OTP SMS Authenticate](https://stytch.com/docs/b2b/api/authenticate-otp-sms) endpoint.
     */
    public fun deleteMFAPhoneNumberCompletable(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Delete a Member's MFA TOTP registration.
     *
     * To mint a new registration for a Member, you must first call this endpoint to delete the existing registration.
     *
     * Existing Member Sessions that include the TOTP authentication factor will not be revoked if the registration is
     * deleted, and MFA will not be enforced until the Member logs in again.
     */
    public suspend fun deleteTOTP(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions? = null,
    ): StytchResult

    /**
     * Delete a Member's MFA TOTP registration.
     *
     * To mint a new registration for a Member, you must first call this endpoint to delete the existing registration.
     *
     * Existing Member Sessions that include the TOTP authentication factor will not be revoked if the registration is
     * deleted, and MFA will not be enforced until the Member logs in again.
     */
    public fun deleteTOTP(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a Member's MFA TOTP registration.
     *
     * To mint a new registration for a Member, you must first call this endpoint to delete the existing registration.
     *
     * Existing Member Sessions that include the TOTP authentication factor will not be revoked if the registration is
     * deleted, and MFA will not be enforced until the Member logs in again.
     */
    public fun deleteTOTPCompletable(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting
     * an empty `query` returns all non-deleted Members within the specified Organizations.
     *
     * *All fuzzy search filters require a minimum of three characters.
     */
    public suspend fun search(
        data: SearchRequest,
        methodOptions: SearchRequestOptions? = null,
    ): StytchResult

    /**
     * Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting
     * an empty `query` returns all non-deleted Members within the specified Organizations.
     *
     * *All fuzzy search filters require a minimum of three characters.
     */
    public fun search(
        data: SearchRequest,
        methodOptions: SearchRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting
     * an empty `query` returns all non-deleted Members within the specified Organizations.
     *
     * *All fuzzy search filters require a minimum of three characters.
     */
    public fun searchCompletable(
        data: SearchRequest,
        methodOptions: SearchRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Delete a's password.
     */
    public suspend fun deletePassword(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions? = null,
    ): StytchResult

    /**
     * Delete a's password.
     */
    public fun deletePassword(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a's password.
     */
    public fun deletePasswordCompletable(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Get a Member by `member_id`. This endpoint does not require an `organization_id`, enabling you to get members across
     * organizations. This is a dangerous operation. Incorrect use may open you up to indirect object reference (IDOR)
     * attacks. We recommend using the [Get Member](https://stytch.com/docs/b2b/api/get-member) API instead.
     */
    public suspend fun dangerouslyGet(data: DangerouslyGetRequest): StytchResult

    /**
     * Get a Member by `member_id`. This endpoint does not require an `organization_id`, enabling you to get members across
     * organizations. This is a dangerous operation. Incorrect use may open you up to indirect object reference (IDOR)
     * attacks. We recommend using the [Get Member](https://stytch.com/docs/b2b/api/get-member) API instead.
     */
    public fun dangerouslyGet(
        data: DangerouslyGetRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Get a Member by `member_id`. This endpoint does not require an `organization_id`, enabling you to get members across
     * organizations. This is a dangerous operation. Incorrect use may open you up to indirect object reference (IDOR)
     * attacks. We recommend using the [Get Member](https://stytch.com/docs/b2b/api/get-member) API instead.
     */
    public fun dangerouslyGetCompletable(data: DangerouslyGetRequest): CompletableFuture>

    /**
     * Unlinks a retired email address from a specified by their `organization_id` and `member_id`. The email address
     * to be retired can be identified in the request body by either its `email_id`, its `email_address`, or both. If using
     * both identifiers they must refer to the same email.
     *
     * A previously active email address can be marked as retired in one of two ways:
     *
     * - It's replaced with a new primary email address during an explicit Member update.
     * - A new email address is surfaced by an OAuth, SAML or OIDC provider. In this case the new email address becomes the
     *   Member's primary email address and the old primary email address is retired.
     *
     * A retired email address cannot be used by other Members in the same Organization. However, unlinking retired email
     * addresses allows them to be subsequently re-used by other Organization Members. Retired email addresses can be viewed
     * on the [Member object](https://stytch.com/docs/b2b/api/member-object).
     *  %}
     */
    public suspend fun unlinkRetiredEmail(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions? = null,
    ): StytchResult

    /**
     * Unlinks a retired email address from a specified by their `organization_id` and `member_id`. The email address
     * to be retired can be identified in the request body by either its `email_id`, its `email_address`, or both. If using
     * both identifiers they must refer to the same email.
     *
     * A previously active email address can be marked as retired in one of two ways:
     *
     * - It's replaced with a new primary email address during an explicit Member update.
     * - A new email address is surfaced by an OAuth, SAML or OIDC provider. In this case the new email address becomes the
     *   Member's primary email address and the old primary email address is retired.
     *
     * A retired email address cannot be used by other Members in the same Organization. However, unlinking retired email
     * addresses allows them to be subsequently re-used by other Organization Members. Retired email addresses can be viewed
     * on the [Member object](https://stytch.com/docs/b2b/api/member-object).
     *  %}
     */
    public fun unlinkRetiredEmail(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Unlinks a retired email address from a specified by their `organization_id` and `member_id`. The email address
     * to be retired can be identified in the request body by either its `email_id`, its `email_address`, or both. If using
     * both identifiers they must refer to the same email.
     *
     * A previously active email address can be marked as retired in one of two ways:
     *
     * - It's replaced with a new primary email address during an explicit Member update.
     * - A new email address is surfaced by an OAuth, SAML or OIDC provider. In this case the new email address becomes the
     *   Member's primary email address and the old primary email address is retired.
     *
     * A retired email address cannot be used by other Members in the same Organization. However, unlinking retired email
     * addresses allows them to be subsequently re-used by other Organization Members. Retired email addresses can be viewed
     * on the [Member object](https://stytch.com/docs/b2b/api/member-object).
     *  %}
     */
    public fun unlinkRetiredEmailCompletable(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Creates a. An `organization_id` and `email_address` are required.
     */
    public suspend fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
    ): StytchResult

    /**
     * Creates a. An `organization_id` and `email_address` are required.
     */
    public fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Creates a. An `organization_id` and `email_address` are required.
     */
    public fun createCompletable(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Get a Member by `member_id` or `email_address`.
     */
    public suspend fun get(data: GetRequest): StytchResult

    /**
     * Get a Member by `member_id` or `email_address`.
     */
    public fun get(
        data: GetRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Get a Member by `member_id` or `email_address`.
     */
    public fun getCompletable(data: GetRequest): CompletableFuture>
}

internal class MembersImpl(
    private val httpClient: HttpClient,
    private val coroutineScope: CoroutineScope,
) : Members {
    private val moshi = Moshi.Builder().add(InstantAdapter()).build()

    override val oauthProviders: OAuthProviders = OAuthProvidersImpl(httpClient, coroutineScope)

    override suspend fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(UpdateRequest::class.java).toJson(data)
            httpClient.put("/v1/b2b/organizations/${data.organizationId}/members/${data.memberId}", asJson, headers)
        }

    override fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(update(data, methodOptions))
        }
    }

    override fun updateCompletable(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            update(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            httpClient.delete("/v1/b2b/organizations/${data.organizationId}/members/${data.memberId}", headers)
        }

    override fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(delete(data, methodOptions))
        }
    }

    override fun deleteCompletable(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            delete(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun reactivate(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(ReactivateRequest::class.java).toJson(data)
            httpClient.put("/v1/b2b/organizations/${data.organizationId}/members/${data.memberId}/reactivate", asJson, headers)
        }

    override fun reactivate(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(reactivate(data, methodOptions))
        }
    }

    override fun reactivateCompletable(
        data: ReactivateRequest,
        methodOptions: ReactivateRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            reactivate(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun deleteMFAPhoneNumber(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            httpClient.delete("/v1/b2b/organizations/${data.organizationId}/members/mfa_phone_numbers/${data.memberId}", headers)
        }

    override fun deleteMFAPhoneNumber(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(deleteMFAPhoneNumber(data, methodOptions))
        }
    }

    override fun deleteMFAPhoneNumberCompletable(
        data: DeleteMFAPhoneNumberRequest,
        methodOptions: DeleteMFAPhoneNumberRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteMFAPhoneNumber(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun deleteTOTP(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            httpClient.delete("/v1/b2b/organizations/${data.organizationId}/members/${data.memberId}/totp", headers)
        }

    override fun deleteTOTP(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(deleteTOTP(data, methodOptions))
        }
    }

    override fun deleteTOTPCompletable(
        data: DeleteTOTPRequest,
        methodOptions: DeleteTOTPRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteTOTP(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun search(
        data: SearchRequest,
        methodOptions: SearchRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(SearchRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/organizations/members/search", asJson, headers)
        }

    override fun search(
        data: SearchRequest,
        methodOptions: SearchRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(search(data, methodOptions))
        }
    }

    override fun searchCompletable(
        data: SearchRequest,
        methodOptions: SearchRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            search(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun deletePassword(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            httpClient.delete("/v1/b2b/organizations/${data.organizationId}/members/passwords/${data.memberPasswordId}", headers)
        }

    override fun deletePassword(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(deletePassword(data, methodOptions))
        }
    }

    override fun deletePasswordCompletable(
        data: DeletePasswordRequest,
        methodOptions: DeletePasswordRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            deletePassword(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun dangerouslyGet(data: DangerouslyGetRequest): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()

            val asJson = moshi.adapter(DangerouslyGetRequest::class.java).toJson(data)
            val type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java)
            val adapter: JsonAdapter> = moshi.adapter(type)
            val asMap = adapter.fromJson(asJson) ?: emptyMap()
            httpClient.get("/v1/b2b/organizations/members/dangerously_get/${data.memberId}", asMap, headers)
        }

    override fun dangerouslyGet(
        data: DangerouslyGetRequest,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(dangerouslyGet(data))
        }
    }

    override fun dangerouslyGetCompletable(data: DangerouslyGetRequest): CompletableFuture> =
        coroutineScope.async {
            dangerouslyGet(data)
        }.asCompletableFuture()

    override suspend fun unlinkRetiredEmail(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(UnlinkRetiredEmailRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/organizations/${data.organizationId}/members/${data.memberId}/unlink_retired_email", asJson, headers)
        }

    override fun unlinkRetiredEmail(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(unlinkRetiredEmail(data, methodOptions))
        }
    }

    override fun unlinkRetiredEmailCompletable(
        data: UnlinkRetiredEmailRequest,
        methodOptions: UnlinkRetiredEmailRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            unlinkRetiredEmail(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(CreateRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/organizations/${data.organizationId}/members", asJson, headers)
        }

    override fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(create(data, methodOptions))
        }
    }

    override fun createCompletable(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            create(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun get(data: GetRequest): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()

            val asJson = moshi.adapter(GetRequest::class.java).toJson(data)
            val type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java)
            val adapter: JsonAdapter> = moshi.adapter(type)
            val asMap = adapter.fromJson(asJson) ?: emptyMap()
            httpClient.get("/v1/b2b/organizations/${data.organizationId}/member", asMap, headers)
        }

    override fun get(
        data: GetRequest,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(get(data))
        }
    }

    override fun getCompletable(data: GetRequest): CompletableFuture> =
        coroutineScope.async {
            get(data)
        }.asCompletableFuture()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy