UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) 8.1 kB
"use strict";var t,e=require("ofetch");class s extends Error{toString(){return`${this.type}${this.privyErrorCode?`-${this.privyErrorCode}`:""}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}constructor(t,e,s){super(t),e instanceof Error&&(this.cause=e),this.privyErrorCode=s}}class a extends s{constructor(t,e,s,a,r,i){super(s,a,r),this.type=t,this.status=e,this.data=i}}class r extends s{constructor(t,e,s){super(t,e,s),this.type="client_error"}}const i=t=>t instanceof s?t:t instanceof Error?new r(t.message,t):new r(`Internal error: ${t}`);var n=((t={}).OAUTH_ACCOUNT_SUSPENDED="oauth_account_suspended",t.MISSING_OR_INVALID_PRIVY_APP_ID="missing_or_invalid_privy_app_id",t.MISSING_OR_INVALID_PRIVY_ACCOUNT_ID="missing_or_invalid_privy_account_id",t.MISSING_OR_INVALID_TOKEN="missing_or_invalid_token",t.INVALID_DATA="invalid_data",t.INVALID_CAPTCHA="invalid_captcha",t.LINKED_TO_ANOTHER_USER="linked_to_another_user",t.CANNOT_LINK_MORE_OF_TYPE="cannot_link_more_of_type",t.FAILED_TO_LINK_ACCOUNT="failed_to_link_account",t.FAILED_TO_UPDATE_ACCOUNT="failed_to_update_account",t.USER_EXITED_UPDATE_FLOW="exited_update_flow",t.ALLOWLIST_REJECTED="allowlist_rejected",t.OAUTH_USER_DENIED="oauth_user_denied",t.OAUTH_UNEXPECTED="oauth_unexpected",t.UNKNOWN_AUTH_ERROR="unknown_auth_error",t.USER_EXITED_AUTH_FLOW="exited_auth_flow",t.USER_EXITED_LINK_FLOW="exited_link_flow",t.USER_EXITED_SET_PASSWORD_FLOW="user_exited_set_password_flow",t.MUST_BE_AUTHENTICATED="must_be_authenticated",t.UNKNOWN_CONNECT_WALLET_ERROR="unknown_connect_wallet_error",t.GENERIC_CONNECT_WALLET_ERROR="generic_connect_wallet_error",t.CLIENT_REQUEST_TIMEOUT="client_request_timeout",t.INVALID_CREDENTIALS="invalid_credentials",t.MISSING_MFA_CREDENTIALS="missing_or_invalid_mfa",t.UNKNOWN_MFA_ERROR="unknown_mfa_error",t.EMBEDDED_WALLET_ALREADY_EXISTS="embedded_wallet_already_exists",t.EMBEDDED_WALLET_NOT_FOUND="embedded_wallet_not_found",t.EMBEDDED_WALLET_CREATE_ERROR="embedded_wallet_create_error",t.UNKNOWN_EMBEDDED_WALLET_ERROR="unknown_embedded_wallet_error",t.EMBEDDED_WALLET_PASSWORD_UNCONFIRMED="embedded_wallet_password_unconfirmed",t.EMBEDDED_WALLET_PASSWORD_ALREADY_EXISTS="embedded_wallet_password_already_exists",t.EMBEDDED_WALLET_RECOVERY_ALREADY_EXISTS="embedded_wallet_recovery_already_exists",t.TRANSACTION_FAILURE="transaction_failure",t.UNSUPPORTED_CHAIN_ID="unsupported_chain_id",t.NOT_SUPPORTED="not_supported",t.CAPTCHA_TIMEOUT="captcha_timeout",t.INVALID_MESSAGE="invalid_message",t.UNABLE_TO_SIGN="unable_to_sign",t.CAPTCHA_FAILURE="captcha_failure",t.CAPTCHA_DISABLED="captcha_disabled",t.SESSION_STORAGE_UNAVAILABLE="session_storage_unavailable",t.TOO_MANY_REQUESTS="too_many_requests",t.USER_LIMIT_REACHED="max_accounts_reached",t.DISALLOWED_LOGIN_METHOD="disallowed_login_method",t.DISALLOWED_PLUS_EMAIL="disallowed_plus_email",t.PASSKEY_NOT_ALLOWED="passkey_not_allowed",t.USER_DOES_NOT_EXIST="user_does_not_exist",t.INSUFFICIENT_BALANCE="insufficient_balance",t.ACCOUNT_TRANSFER_REQUIRED="account_transfer_required",t.BUFFER_NOT_DEFINED="buffer_not_defined",t.UNSUPPORTED_WALLET_TYPE="unsupported_wallet_type",t);exports.PrivyApiError=a,exports.PrivyClientError=r,exports.PrivyConnectorError=class extends s{constructor(t,e,s){super(t,e,s),this.type="connector_error"}},exports.PrivyEmbeddedWalletError=class extends r{constructor(t="Embedded wallet error",e){super(t,e,"unknown_embedded_wallet_error")}},exports.PrivyError=s,exports.PrivyErrorCode=n,exports.PrivyNotReadyError=class extends r{constructor(){super("Method called before `ready`. Ensure you wait until `ready` is true before calling.")}},exports.PrivyTimeoutError=class extends r{constructor(){super("Request timed out",void 0,"client_request_timeout")}},exports.PrivyUnauthenticatedError=class extends r{constructor(t="User must be authenticated"){super(t,void 0,"must_be_authenticated")}},exports.PrivyUserLimitReachedError=class extends r{constructor(t){super("This application is in development mode and must be upgraded to production to log in new users.",t,"max_accounts_reached")}},exports.acceptTermsPath="/api/v1/users/me/accept_terms",exports.analyticsEventsPath="/api/v1/analytics_events",exports.authenticateFarcasterV2Path="api/v2/farcaster/authenticate",exports.coinbaseOnRampInitPath="/api/v1/funding/coinbase_on_ramp/init",exports.coinbaseOnRampStatusPath="/api/v1/funding/coinbase_on_ramp/status",exports.customJwtAccountAuthenticatePath="/api/v1/custom_jwt_account/authenticate",exports.customJwtAccountLinkPath="/api/v1/custom_jwt_account/link",exports.delegatedActionsRevokePath="/api/v1/wallets/revoke",exports.farcasterAuthenticatePath="/api/v1/farcaster/authenticate",exports.farcasterInitPath="/api/v1/farcaster/init",exports.farcasterLinkPath="/api/v1/farcaster/link",exports.farcasterStatusPath="/api/v1/farcaster/status",exports.formatApiError=t=>{if(t instanceof s)return t;if(!(t instanceof e.FetchError))return i(t);if(!t.response)return new a("api_error",null,t.message,t);let{type:r,message:n,error:o,code:_}=t.data;return new a(r||"ApiError",t.response.status,n||o,t,_,t.data)},exports.formatPrivyError=i,exports.guestAccountAuthenticatePath="/api/v1/guest/authenticate",exports.initFarcasterV2Path="api/v2/farcaster/init",exports.mfaPasskeyInitPath="/api/v1/mfa/passkeys/init",exports.mfaPasswordlessSmsInitPath="/api/v1/mfa/passwordless_sms/init",exports.moonpayPluginOnRampPath="/api/v1/plugins/moonpay_on_ramp/sign",exports.oAuthAuthenticatePath="/api/v1/oauth/authenticate",exports.oAuthInitPath="/api/v1/oauth/init",exports.oAuthLinkPath="/api/v1/oauth/link",exports.passkeyAuthenticatePath="/api/v1/passkeys/authenticate",exports.passkeyInitAuthenticatePath="/api/v1/passkeys/authenticate/init",exports.passkeyInitLinkPath="/api/v1/passkeys/link/init",exports.passkeyInitRegisterPath="/api/v1/passkeys/register/init",exports.passkeyLinkPath="/api/v1/passkeys/link",exports.passkeyRegisterPath="/api/v1/passkeys/register",exports.passwordlessAuthenticatePath="/api/v1/passwordless/authenticate",exports.passwordlessInitPath="/api/v1/passwordless/init",exports.passwordlessLinkPath="/api/v1/passwordless/link",exports.passwordlessSmsAuthenticatePath="/api/v1/passwordless_sms/authenticate",exports.passwordlessSmsInitPath="/api/v1/passwordless_sms/init",exports.passwordlessSmsLinkPath="/api/v1/passwordless_sms/link",exports.recoveryOAuthAuthenticatePath="/api/v1/recovery/oauth/authenticate",exports.recoveryOAuthInitICloudPath="/api/v1/recovery/oauth/init_icloud",exports.recoveryOAuthInitPath="/api/v1/recovery/oauth/init",exports.sessionsLogoutPath="/api/v1/sessions/logout",exports.sessionsRefreshPath="/api/v1/sessions",exports.siweAuthenticatePath="/api/v1/siwe/authenticate",exports.siweInitPath="/api/v1/siwe/init",exports.siweLinkPath="/api/v1/siwe/link",exports.siwsAuthenticatePath="/api/v1/siws/authenticate",exports.siwsInitPath="/api/v1/siws/init",exports.siwsLinkPath="/api/v1/siws/link",exports.siwsTransferPath="/api/v1/siws/transfer",exports.siwsUnlinkWalletPath="/api/v1/siws/unlink",exports.smartWalletLinkPath="/api/v1/siwe/link_smart_wallet",exports.telegramAccountAuthenticatePath="/api/v1/telegram/authenticate",exports.telegramAccountLinkPath="/api/v1/telegram/link",exports.telegramAccountTransferPath="/api/v1/telegram/transfer",exports.telegramAccountUnlinkPath="/api/v1/telegram/unlink",exports.transactionScanningPath="/api/v1/scan/transaction",exports.transferEmailPath="/api/v1/passwordless/transfer",exports.transferFarcasterPath="/api/v1/farcaster/transfer",exports.transferOAuthPath="/api/v1/oauth/transfer",exports.transferPhonePath="/api/v1/passwordless_sms/transfer",exports.transferWalletPath="/api/v1/siwe/transfer",exports.unlinkEmailPath="/api/v1/passwordless/unlink",exports.unlinkFarcasterPath="/api/v1/farcaster/unlink",exports.unlinkOAuthPath="/api/v1/oauth/unlink",exports.unlinkPhonePath="/api/v1/passwordless_sms/unlink",exports.unlinkWalletPath="/api/v1/siwe/unlink",exports.updateEmailPath="/api/v1/passwordless/update",exports.updatePhonePath="/api/v1/passwordless_sms/update",exports.usersMePath="/api/v1/users/me";