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

com.stytch.java.consumer.api.users.Users.kt Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package com.stytch.java.consumer.api.users

// !!!
// 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.common.InstantAdapter
import com.stytch.java.common.StytchResult
import com.stytch.java.consumer.models.users.CreateRequest
import com.stytch.java.consumer.models.users.CreateResponse
import com.stytch.java.consumer.models.users.DeleteBiometricRegistrationRequest
import com.stytch.java.consumer.models.users.DeleteBiometricRegistrationResponse
import com.stytch.java.consumer.models.users.DeleteCryptoWalletRequest
import com.stytch.java.consumer.models.users.DeleteCryptoWalletResponse
import com.stytch.java.consumer.models.users.DeleteEmailRequest
import com.stytch.java.consumer.models.users.DeleteEmailResponse
import com.stytch.java.consumer.models.users.DeleteOAuthRegistrationRequest
import com.stytch.java.consumer.models.users.DeleteOAuthRegistrationResponse
import com.stytch.java.consumer.models.users.DeletePasswordRequest
import com.stytch.java.consumer.models.users.DeletePasswordResponse
import com.stytch.java.consumer.models.users.DeletePhoneNumberRequest
import com.stytch.java.consumer.models.users.DeletePhoneNumberResponse
import com.stytch.java.consumer.models.users.DeleteRequest
import com.stytch.java.consumer.models.users.DeleteResponse
import com.stytch.java.consumer.models.users.DeleteTOTPRequest
import com.stytch.java.consumer.models.users.DeleteTOTPResponse
import com.stytch.java.consumer.models.users.DeleteWebAuthnRegistrationRequest
import com.stytch.java.consumer.models.users.DeleteWebAuthnRegistrationResponse
import com.stytch.java.consumer.models.users.ExchangePrimaryFactorRequest
import com.stytch.java.consumer.models.users.ExchangePrimaryFactorResponse
import com.stytch.java.consumer.models.users.GetRequest
import com.stytch.java.consumer.models.users.GetResponse
import com.stytch.java.consumer.models.users.SearchRequest
import com.stytch.java.consumer.models.users.SearchResponse
import com.stytch.java.consumer.models.users.UpdateRequest
import com.stytch.java.consumer.models.users.UpdateResponse
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 Users {
    /**
     * Add a User to Stytch. A `user_id` is returned in the response that can then be used to perform other operations within
     * Stytch. An `email` or a `phone_number` is required.
     */
    public suspend fun create(data: CreateRequest): StytchResult

    /**
     * Add a User to Stytch. A `user_id` is returned in the response that can then be used to perform other operations within
     * Stytch. An `email` or a `phone_number` is required.
     */
    public fun create(
        data: CreateRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Add a User to Stytch. A `user_id` is returned in the response that can then be used to perform other operations within
     * Stytch. An `email` or a `phone_number` is required.
     */
    public fun createCompletable(data: CreateRequest): CompletableFuture>

    /**
     * Get information about a specific User.
     */
    public suspend fun get(data: GetRequest): StytchResult

    /**
     * Get information about a specific User.
     */
    public fun get(
        data: GetRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Get information about a specific User.
     */
    public fun getCompletable(data: GetRequest): CompletableFuture>

    /**
     * Search for Users within your Stytch Project. Submit an empty `query` in the request to return all Users.
     */
    public suspend fun search(data: SearchRequest): StytchResult

    /**
     * Search for Users within your Stytch Project. Submit an empty `query` in the request to return all Users.
     */
    public fun search(
        data: SearchRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Search for Users within your Stytch Project. Submit an empty `query` in the request to return all Users.
     */
    public fun searchCompletable(data: SearchRequest): CompletableFuture>

    /**
     * Update a User's attributes.
     *
     * **Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or
     * phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the
     * existing User's `user_id` while calling the `/send` endpoint, the new, unverified email address or phone number will be
     * added to the existing User object. If the user successfully authenticates within 5 minutes of the `/send` request, the
     * new email address or phone number will be marked as verified and remain permanently on the existing Stytch User.
     * Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will
     * create a new User. We require this process to guard against an account takeover vulnerability.
     */
    public suspend fun update(data: UpdateRequest): StytchResult

    /**
     * Update a User's attributes.
     *
     * **Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or
     * phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the
     * existing User's `user_id` while calling the `/send` endpoint, the new, unverified email address or phone number will be
     * added to the existing User object. If the user successfully authenticates within 5 minutes of the `/send` request, the
     * new email address or phone number will be marked as verified and remain permanently on the existing Stytch User.
     * Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will
     * create a new User. We require this process to guard against an account takeover vulnerability.
     */
    public fun update(
        data: UpdateRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Update a User's attributes.
     *
     * **Note:** In order to add a new email address or phone number to an existing User object, pass the new email address or
     * phone number into the respective `/send` endpoint for the authentication method of your choice. If you specify the
     * existing User's `user_id` while calling the `/send` endpoint, the new, unverified email address or phone number will be
     * added to the existing User object. If the user successfully authenticates within 5 minutes of the `/send` request, the
     * new email address or phone number will be marked as verified and remain permanently on the existing Stytch User.
     * Otherwise, it will be removed from the User object, and any subsequent login requests using that phone number will
     * create a new User. We require this process to guard against an account takeover vulnerability.
     */
    public fun updateCompletable(data: UpdateRequest): CompletableFuture>

    /**
     * Exchange a user's email address or phone number for another.
     *
     * Must pass either an `email_address` or a `phone_number`.
     *
     * This endpoint only works if the user has exactly one factor. You are able to exchange the type of factor for another as
     * well, i.e. exchange an `email_address` for a `phone_number`.
     *
     * Use this endpoint with caution as it performs an admin level action.
     */
    public suspend fun exchangePrimaryFactor(data: ExchangePrimaryFactorRequest): StytchResult

    /**
     * Exchange a user's email address or phone number for another.
     *
     * Must pass either an `email_address` or a `phone_number`.
     *
     * This endpoint only works if the user has exactly one factor. You are able to exchange the type of factor for another as
     * well, i.e. exchange an `email_address` for a `phone_number`.
     *
     * Use this endpoint with caution as it performs an admin level action.
     */
    public fun exchangePrimaryFactor(
        data: ExchangePrimaryFactorRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Exchange a user's email address or phone number for another.
     *
     * Must pass either an `email_address` or a `phone_number`.
     *
     * This endpoint only works if the user has exactly one factor. You are able to exchange the type of factor for another as
     * well, i.e. exchange an `email_address` for a `phone_number`.
     *
     * Use this endpoint with caution as it performs an admin level action.
     */
    public fun exchangePrimaryFactorCompletable(
        data: ExchangePrimaryFactorRequest,
    ): CompletableFuture>

    /**
     * Delete a User from Stytch.
     */
    public suspend fun delete(data: DeleteRequest): StytchResult

    /**
     * Delete a User from Stytch.
     */
    public fun delete(
        data: DeleteRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a User from Stytch.
     */
    public fun deleteCompletable(data: DeleteRequest): CompletableFuture>

    /**
     * Delete an email from a User.
     */
    public suspend fun deleteEmail(data: DeleteEmailRequest): StytchResult

    /**
     * Delete an email from a User.
     */
    public fun deleteEmail(
        data: DeleteEmailRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete an email from a User.
     */
    public fun deleteEmailCompletable(data: DeleteEmailRequest): CompletableFuture>

    /**
     * Delete a phone number from a User.
     */
    public suspend fun deletePhoneNumber(data: DeletePhoneNumberRequest): StytchResult

    /**
     * Delete a phone number from a User.
     */
    public fun deletePhoneNumber(
        data: DeletePhoneNumberRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a phone number from a User.
     */
    public fun deletePhoneNumberCompletable(data: DeletePhoneNumberRequest): CompletableFuture>

    /**
     * Delete a WebAuthn registration from a User.
     */
    public suspend fun deleteWebAuthnRegistration(
        data: DeleteWebAuthnRegistrationRequest,
    ): StytchResult

    /**
     * Delete a WebAuthn registration from a User.
     */
    public fun deleteWebAuthnRegistration(
        data: DeleteWebAuthnRegistrationRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a WebAuthn registration from a User.
     */
    public fun deleteWebAuthnRegistrationCompletable(
        data: DeleteWebAuthnRegistrationRequest,
    ): CompletableFuture>

    /**
     * Delete a biometric registration from a User.
     */
    public suspend fun deleteBiometricRegistration(
        data: DeleteBiometricRegistrationRequest,
    ): StytchResult

    /**
     * Delete a biometric registration from a User.
     */
    public fun deleteBiometricRegistration(
        data: DeleteBiometricRegistrationRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a biometric registration from a User.
     */
    public fun deleteBiometricRegistrationCompletable(
        data: DeleteBiometricRegistrationRequest,
    ): CompletableFuture>

    /**
     * Delete a TOTP from a User.
     */
    public suspend fun deleteTOTP(data: DeleteTOTPRequest): StytchResult

    /**
     * Delete a TOTP from a User.
     */
    public fun deleteTOTP(
        data: DeleteTOTPRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a TOTP from a User.
     */
    public fun deleteTOTPCompletable(data: DeleteTOTPRequest): CompletableFuture>

    /**
     * Delete a crypto wallet from a User.
     */
    public suspend fun deleteCryptoWallet(data: DeleteCryptoWalletRequest): StytchResult

    /**
     * Delete a crypto wallet from a User.
     */
    public fun deleteCryptoWallet(
        data: DeleteCryptoWalletRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a crypto wallet from a User.
     */
    public fun deleteCryptoWalletCompletable(data: DeleteCryptoWalletRequest): CompletableFuture>

    /**
     * Delete a password from a User.
     */
    public suspend fun deletePassword(data: DeletePasswordRequest): StytchResult

    /**
     * Delete a password from a User.
     */
    public fun deletePassword(
        data: DeletePasswordRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete a password from a User.
     */
    public fun deletePasswordCompletable(data: DeletePasswordRequest): CompletableFuture>

    /**
     * Delete an OAuth registration from a User.
     */
    public suspend fun deleteOAuthRegistration(data: DeleteOAuthRegistrationRequest): StytchResult

    /**
     * Delete an OAuth registration from a User.
     */
    public fun deleteOAuthRegistration(
        data: DeleteOAuthRegistrationRequest,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Delete an OAuth registration from a User.
     */
    public fun deleteOAuthRegistrationCompletable(
        data: DeleteOAuthRegistrationRequest,
    ): CompletableFuture>
}

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

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

            val asJson = moshi.adapter(CreateRequest::class.java).toJson(data)
            httpClient.post("/v1/users", asJson, headers)
        }

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

    override fun createCompletable(data: CreateRequest): CompletableFuture> =
        coroutineScope.async {
            create(data)
        }.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/users/${data.userId}", 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()

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

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

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

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

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

            val asJson = moshi.adapter(UpdateRequest::class.java).toJson(data)
            httpClient.put("/v1/users/${data.userId}", asJson, headers)
        }

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

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

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

            val asJson = moshi.adapter(ExchangePrimaryFactorRequest::class.java).toJson(data)
            httpClient.put("/v1/users/${data.userId}/exchange_primary_factor", asJson, headers)
        }

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

    override fun exchangePrimaryFactorCompletable(
        data: ExchangePrimaryFactorRequest,
    ): CompletableFuture> =
        coroutineScope.async {
            exchangePrimaryFactor(data)
        }.asCompletableFuture()

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

            httpClient.delete("/v1/users/${data.userId}", headers)
        }

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

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

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

            httpClient.delete("/v1/users/emails/${data.emailId}", headers)
        }

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

    override fun deleteEmailCompletable(data: DeleteEmailRequest): CompletableFuture> =
        coroutineScope.async {
            deleteEmail(data)
        }.asCompletableFuture()

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

            httpClient.delete("/v1/users/phone_numbers/${data.phoneId}", headers)
        }

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

    override fun deletePhoneNumberCompletable(data: DeletePhoneNumberRequest): CompletableFuture> =
        coroutineScope.async {
            deletePhoneNumber(data)
        }.asCompletableFuture()

    override suspend fun deleteWebAuthnRegistration(
        data: DeleteWebAuthnRegistrationRequest,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()

            httpClient.delete("/v1/users/webauthn_registrations/${data.webauthnRegistrationId}", headers)
        }

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

    override fun deleteWebAuthnRegistrationCompletable(
        data: DeleteWebAuthnRegistrationRequest,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteWebAuthnRegistration(data)
        }.asCompletableFuture()

    override suspend fun deleteBiometricRegistration(
        data: DeleteBiometricRegistrationRequest,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()

            httpClient.delete("/v1/users/biometric_registrations/${data.biometricRegistrationId}", headers)
        }

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

    override fun deleteBiometricRegistrationCompletable(
        data: DeleteBiometricRegistrationRequest,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteBiometricRegistration(data)
        }.asCompletableFuture()

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

            httpClient.delete("/v1/users/totps/${data.totpId}", headers)
        }

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

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

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

            httpClient.delete("/v1/users/crypto_wallets/${data.cryptoWalletId}", headers)
        }

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

    override fun deleteCryptoWalletCompletable(
        data: DeleteCryptoWalletRequest,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteCryptoWallet(data)
        }.asCompletableFuture()

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

            httpClient.delete("/v1/users/passwords/${data.passwordId}", headers)
        }

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

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

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

            httpClient.delete("/v1/users/oauth/${data.oauthUserRegistrationId}", headers)
        }

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

    override fun deleteOAuthRegistrationCompletable(
        data: DeleteOAuthRegistrationRequest,
    ): CompletableFuture> =
        coroutineScope.async {
            deleteOAuthRegistration(data)
        }.asCompletableFuture()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy