Skip to main content

API Reference

Complete reference for everything exported by @nexla/react-sdk.


NexlaConnectProvider

The root provider. Must wrap all SDK hooks and components. Handles authentication, credential fetching, and end-user scoping.

import { NexlaConnectProvider } from '@nexla/react-sdk';

<NexlaConnectProvider
serviceKey="YOUR_SERVICE_KEY"
connectors={['CONNECTOR_KEY_1', 'CONNECTOR_KEY_2']}
applicationId="YOUR_APPLICATION_ID"
endUserId="YOUR_END_USER_ID"
>
{/* your app */}
</NexlaConnectProvider>
PropTypeRequiredDescription
serviceKeystringYesService key from your SDK Application
connectorsstring[]YesConnector keys to enable
applicationIdstringYesID of your registered SDK application. Validated against the service key at startup — throws APPLICATION_MISMATCH on mismatch.
endUserIdstringYesYour end user's ID (any stable string up to 128 chars). Stamped on new credentials; used to filter the credential list so each user sees only their own.
apiBaseUrlstringNexla Admin API base URL. Default: https://dataops.nexla.io/admin-api
onConnect(credential: Credential) => voidCalled after a credential is successfully created
onError(error: NexlaConnectError) => voidCalled on any SDK error
themeThemeConfigColor scheme and primary color override
localestringBCP 47 locale tag (e.g. 'en-US')
childrenReact.ReactNodeYes

NexlaThemeProvider

Injects CSS variables for all styled components. Must be inside NexlaConnectProvider. Only needed when using styled components.

import { NexlaThemeProvider } from '@nexla/react-sdk';

<NexlaThemeProvider mode="light">
{/* styled components */}
</NexlaThemeProvider>
PropTypeDefaultDescription
mode'light' | 'dark''light'Color scheme
childrenReact.ReactNode

Hooks

useNexlaConnect()

Returns the full context state and all available actions.

const ctx = useNexlaConnect();

State

PropertyTypeDescription
credentialsCredential[]Connected credentials for enabled connectors, scoped to applicationId and endUserId
connectorsConnector[]Connector metadata for all enabled connectors
loadingbooleantrue during initial fetch (session exchange + credentials + connectors)
errorNexlaConnectError | nullLast error (load, connect, or auth)
connectingConnectorstring | nullConnector key currently mid-OAuth, or null
configNexlaConnectConfigRead-only provider config snapshot

Actions

MethodSignatureDescription
connect(connectorKey: string) => Promise<Credential>Launch OAuth popup for a connector. Resolves with the created Credential.
disconnect(credentialId: number) => Promise<void>Delete a credential by ID
createCredential(body: unknown) => Promise<Credential>Create a credential via raw API body. Automatically stamps endUserId.
updateCredential(id: number, body: unknown) => Promise<Credential>Update an existing credential
refreshCredentials() => Promise<void>Re-fetch all credentials from the API
probeCredential(id: number) => Promise<ProbeResult>Test whether a credential's connection is still valid
fetchConnectorDetail(connectorKey: string) => Promise<Connector | null>Fetch the full expanded connector record
fetchConnectorAuthFields(connectorKey: string) => Promise<ConnectorAuthField[]>Fetch auth form fields for a connector
fetchCredentialDetail(id: number) => Promise<Credential>Fetch a single credential with config expanded
interface ProbeResult {
isValid: boolean;
message?: string;
}

useCredentials(connectorKey?)

Convenience hook for reading credentials, optionally filtered by connector.

const { credentials, loading, error, refresh } = useCredentials();
const { credentials: filtered } = useCredentials('CONNECTOR_KEY');
PropertyTypeDescription
credentialsCredential[]Credentials, filtered to connectorKey if provided
loadingbooleantrue during initial load
errorNexlaConnectError | nullLast fetch error
refresh() => Promise<void>Re-fetch from API

useConnectorForm(connectorKey)

Headless hook for building custom credential forms. Manages fields, values, validation, OAuth, and submission.

const form = useConnectorForm('CONNECTOR_KEY');

Loading & errors

PropertyTypeDescription
loadingbooleantrue while connector fields are being fetched
errorNexlaConnectError | nullLoad or submit error

Auth templates — connectors with multiple auth methods (e.g. "OAuth" and "API Key"):

PropertyTypeDescription
authTemplatesAuthTemplate[]Available auth methods
selectedTemplateIdnumber | nullCurrently selected template ID
setTemplate(id: number) => voidSwitch auth method and reset form

Form fields

PropertyTypeDescription
fieldsConnectorSpecAuthField[]Visible, renderable fields (pre-filtered: hidden, OAuth-internal, and button fields excluded)
allFieldsConnectorSpecAuthField[]All fields including hidden/internal
valuesRecord<string, unknown>Current form values
setValue(name: string, value: unknown) => voidUpdate a field value. Automatically applies conditional-default side effects.
errorsRecord<string, string>Validation error messages keyed by field name
validate() => booleanValidate all visible required fields. Populates errors. Returns true if valid.

Credential state

PropertyTypeDescription
existingCredentialCredential | undefinedExisting credential for this connector (current user), or undefined if creating new

OAuth

PropertyTypeDescription
isOAuthbooleantrue if the current connector/template uses OAuth
authorizingbooleantrue while OAuth popup is open
isAuthorizedbooleantrue after successful authorize()
oauthErrorstring | nullError message from the last authorize() attempt
authorize() => Promise<void>Open the OAuth popup. On success, sets isAuthorized = true and stores the payload for submit().

Submission

PropertyTypeDescription
submit() => Promise<Credential>Create or update the credential. Calls updateCredential when existingCredential exists, createCredential otherwise. For OAuth connectors, uses the payload from authorize().
reset() => voidClear all form values, errors, and OAuth state

useNexlaSnackbar()

Convenience hook that manages toast notification state and provides pre-built handlers for SDK callbacks.

const snackbar = useNexlaSnackbar();
PropertyTypeDescription
snackbarPropsNexlaSnackbarPropsSpread onto <NexlaSnackbar> — contains open, type, message, onClose
show(message: string, type?: 'success' | 'error' | 'warning') => voidProgrammatically show a toast
hide() => voidDismiss the current toast
onConnect(credential: Credential) => voidPass to NexlaConnectProvider.onConnect — shows success toast
onError(error: NexlaConnectError) => voidPass to NexlaConnectProvider.onError — shows error toast
onProbeError(credential: Credential, message: string | null) => voidPass to NexlaConnectModal.onProbeError — shows warning toast

Styled Components

NexlaConnectButton

Button that opens a credential modal for a specific connector. Automatically displays the connector's logo and name.

PropTypeDescription
connectorstringConnector key (required)
onBeforeConnect() => boolean | voidReturn false to cancel
disabledbooleanDisables the button
childrenReact.ReactNodeCustom label (default: "Connect {display_name}")

Also accepts all standard <button> HTML attributes except onClick.

NexlaConnectModal

Credential creation and edit dialog. Detects existing credentials automatically and switches to edit/update mode.

PropTypeDescription
openbooleanControls dialog visibility
connectorstringConnector key
onClose() => voidCalled when the dialog is dismissed. Not called during active OAuth or when an authorized payload is pending save.
onSuccess(credential: Credential) => voidCalled after credential creation or update
onProbeError(credential: Credential, message: string | null) => voidCalled if the post-connect probe returns isValid: false

NexlaConnectorCard

Card component for displaying a connector in a grid or list layout. Auto-detects connected state from the credential list.

PropTypeDefaultDescription
connectorConnectorConnector object (required)
isConnectedbooleanAuto-detectedOverride connected state display
isComingSoonbooleanfalseDisables the card and reduces opacity
viewMode'grid' | 'list''grid'Layout style
onClick(connector: Connector) => voidClick handler

NexlaSnackbar

Toast notification component built on Radix UI Toast.

PropTypeDefaultDescription
openbooleanControls visibility
type'success' | 'error' | 'warning''success'Toast style
messagestringContent
onClose() => voidDismiss handler
autoHideDurationnumber5000Auto-dismiss delay in ms. Set to 0 to disable.

Types

Credential

interface Credential {
id: number;
name: string;
description: string | null;
owner: { id: number; full_name: string; email: string } | number;
org: { id: number; name: string } | number;
credentials_type: string;
credentials_version: string;
managed?: boolean;
connector: {
id: number;
type: string;
connection_type: string;
name: string;
description: string;
nexset_api_compatible: boolean;
};
access_roles: string[];
verified_status: string | null;
verified_at: string | null;
created_at: string;
updated_at: string;
copied_from_id: number | null;
vendor?: {
id: number;
name: string;
display_name: string;
connection_type: string;
connector_id: number;
connector_name: string;
auth_templates: AuthTemplate[];
};
tags?: string[];
credentials_non_secure_data?: Record<string, unknown>;
template_config?: Record<string, unknown>;
}

Connector

interface Connector {
id: number;
name: string;
display_name: string;
connection_type: string;
description: string;
logo: string;
small_logo: string;
nexset_api_compatible: boolean;
auth_templates: AuthTemplate[];
config: ConnectorConfig;
}

AuthTemplate

interface AuthTemplate {
id: number;
name: string;
display_name?: string;
description: string;
credentials_type?: string;
config?: Record<string, unknown>;
auth_parameters?: (number | ConnectorAuthParameter)[];
}

ConnectorAuthField

interface ConnectorAuthField {
name: string;
display_name: string;
type: string; // 'string' | 'password' | 'select' | 'boolean' | ...
required?: boolean;
default?: unknown;
description?: string;
placeholder?: string;
values?: { label: string; value: string }[]; // Options for select fields
group?: string; // Groups fields under collapsible sections
isHiddenField?: boolean; // Internal fields — never render
dependsOn?: unknown; // Conditional visibility — SDK evaluates automatically
}

NexlaConnectError

class NexlaConnectError extends Error {
readonly code: string; // SCREAMING_SNAKE_CASE error code
readonly connector?: string; // Set if error occurred during connect()
}

Error codes: POPUP_BLOCKED, OAUTH_CANCELLED, OAUTH_TIMEOUT, OAUTH_ERROR, MISSING_PROVIDER, API_ERROR, RATE_LIMITED, REQUEST_TIMEOUT, APPLICATION_MISMATCH, CONNECTOR_NOT_FOUND. See Troubleshooting for resolution guidance.

NexlaConnectConfig

Read-only provider config snapshot, accessible via useNexlaConnect().config.

interface NexlaConnectConfig {
apiBaseUrl: string;
connectors: string[];
applicationId: string;
endUserId: string;
theme?: ThemeConfig;
locale?: string;
}

ThemeConfig

interface ThemeConfig {
mode?: 'light' | 'dark';
primaryColor?: string; // CSS color string
}

Theme Utilities

CSS Variables

NexlaThemeProvider injects CSS variables you can use in your own styles:

VariableDescription
--nx-primaryBrand color (default: #5B4CF5)
--nx-bgPage background
--nx-surfaceCard / modal background
--nx-borderBorder color
--nx-textPrimary text
--nx-text-secondarySecondary text
--nx-errorError red
--nx-success-bgSuccess green background

getNexlaTheme(mode)

Returns a typed JS object of theme values for inline styles.

import { getNexlaTheme } from '@nexla/react-sdk';

const theme = getNexlaTheme('light');
// theme.textPrimary, theme.border, theme.primary, theme.bg, ...

nexlaTheme / nexlaDarkTheme

CSS variable maps for light and dark modes:

import { nexlaTheme, nexlaDarkTheme } from '@nexla/react-sdk';
// Record<string, string> — CSS variable name → value