Core Types
Core TypeScript types and interfaces used throughout the Bloque SDK.Configuration Types
BloqueSDKConfig
Public configuration object for the Bloque SDK. Used when initializing the SDK.baseUrl or a mode, but not both.
ConfigWithBaseUrl
Use a custom API endpoint:Custom base URL for the SDK. When provided,
mode cannot be specified.Origin identifier for the SDK. Used to scope requests to a specific origin within the Bloque platform.
- Required for
apiKeyauthentication - Optional for
jwtauthentication (resolved duringauthenticate())
Platform where the SDK is executed. Determines the runtime environment and its capabilities.
node(default): backend runtime (Node.js, Bun, Deno). Supports API key authentication.browser: web browser environment. Must use JWT authentication.react-native: React Native environment. Must use JWT authentication.bun: Bun runtime. Supports API key authentication.deno: Deno runtime. Supports API key authentication.
Authentication strategy used by the SDK.
{ type: 'apiKey', apiKey: string }: for backend platforms{ type: 'jwt' }: for frontend platforms
JWT token storage strategy. See TokenStorage for details.
Default timeout for HTTP requests in milliseconds.Default:
30000 (30 seconds)Retry configuration for failed requests. See RetryConfig for details.
ConfigWithMode
Use default production or sandbox endpoints:SDK operation mode:
'production'(default): production environment with live data'sandbox': sandbox environment with mock data for testing
ConfigWithBaseUrl.
Examples
Mode
SDK operation mode.Production environment. Uses live endpoints and real data. This is the default mode.
Sandbox environment. Uses isolated endpoints and mock data for development and testing.
Platform
Runtime platform where the SDK executes.Node.js runtime (backend)Typical use cases:
- APIs
- Backend services
- Server-side workers
Deno runtime (backend)Typical use cases:
- Serverless functions
- Edge-like services
Bun runtime (backend)Typical use cases:
- High-performance backend services
- Local development servers
Browser runtime (frontend)Characteristics:
- No access to private API keys
- Authentication via JWT
- Requests include credentials (
credentials: 'include') to support httpOnly cookies tokenStorageis optional
React Native runtime (mobile)Characteristics:
- No access to private API keys
- Authentication via JWT
tokenStorageis required to provide/store the JWT token
AuthStrategy
Authentication strategy for the SDK.API Key Authentication
Authentication type
Private API key for backend authentication (starts with
sk_)JWT Authentication
Authentication type
TokenStorage
Interface for storing and retrieving JWT tokens in client-side platforms.Retrieves the currently stored JWT token.Returns the JWT token, or
null if no token is stored.Persists a JWT token.WARNING: If using localStorage/sessionStorage, this token will be accessible to any JavaScript code on the page, including malicious scripts.
Clears the stored JWT token.
Security Considerations
httpOnly Cookies (RECOMMENDED)
- Best security practice - not accessible to JavaScript
- Protects against XSS attacks
- Requires server-side cooperation to set cookies
Secure Storage (RECOMMENDED for mobile)
- Use platform-specific secure storage (e.g., Keychain on iOS, Keystore on Android)
- Libraries:
@react-native-async-storage/async-storage,expo-secure-store
Examples
httpOnly Cookies (Recommended):RetryConfig
Configuration for automatic retry behavior.Whether to enable automatic retries.Default:
trueMaximum number of retry attempts.Default:
3Initial delay in milliseconds before the first retry.Subsequent retries use exponential backoff:
delay * (2 ^ attempt).Default: 1000 (1 second)Maximum delay in milliseconds between retries.Prevents exponential backoff from growing too large.Default:
30000 (30 seconds)Retry Scenarios
The SDK automatically retries for:- 429 (Too Many Requests) - respects
Retry-Afterheader - 503 (Service Unavailable)
- Network errors (timeouts, connection failures)
Example
Request Types
RequestOptions
Options for making HTTP requests.HTTP method
API endpoint path (e.g.,
/v1/accounts)Request body (automatically serialized to JSON)
Additional HTTP headers
Request timeout in milliseconds.If not specified, uses the default timeout from SDK config.
Set to 0 to disable timeout for this specific request.Default:
30000 (30 seconds)This interface is primarily for internal use. Most SDK methods accept optional timeout/headers as parameters.
Response Types
BloqueResponse
Standard API response wrapper.Response data (present on success)
Error details (present on failure). See BloqueError.
BloqueError
Error response from the API.Human-readable error message
Error code (e.g., ‘INVALID_ALIAS’, ‘INSUFFICIENT_FUNDS’)
HTTP status code
This is the raw error format from the API. The SDK throws specialized error classes (see Error Classes) instead of returning this interface.