PERS SDK - v2.3.26 / Exports / PersConfig
PERS SDK Configuration
Example
// Production setup
const config: PersConfig = {
environment: 'production',
apiProjectKey: 'your-project-key',
};
// Custom API URL (for development/testing)
const devConfig: PersConfig = {
customApiUrl: 'https://my-local-api.ngrok.io/v2',
apiProjectKey: 'your-project-key',
};- environment
- customApiUrl
- apiProjectKey
- apiVersion
- timeout
- retries
- authType
- authStorage
- dpop
- authProvider
- tokenRefreshMargin
- backgroundRefreshThreshold
- captureWalletEvents
- walletEventsWsUrl
- autoRestoreSession
- dataSource
- platform
- apiRoot
• Optional environment: PersEnvironment
Target environment - 'staging' or 'production' (default: 'production')
• Optional customApiUrl: string
Custom API URL - overrides environment setting. Use this for local development or custom deployments.
• Optional apiProjectKey: string
Project key for API authentication
• Optional apiVersion: "v2"
API version to use (default: 'v2')
• Optional timeout: number
Request timeout in milliseconds (default: 30000)
• Optional retries: number
Number of retry attempts (default: 3)
• Optional authType: AccountOwnerType
Authentication type for auto-created provider (default: AccountOwnerType.USER)
• Optional authStorage: TokenStorage
Custom token storage for auto-created provider
Recommendation
Use new IndexedDBTokenStorage() for better security/performance
• Optional dpop: Object
DPoP (Demonstrating Proof-of-Possession) Configuration for auto-created provider
| Name | Type | Description |
|---|---|---|
enabled? | boolean | Enable DPoP (default: true) |
cryptoProvider? | DPoPCryptoProvider | Custom Crypto Provider (optional) |
• Optional authProvider: PersAuthProvider
Authentication provider instance (overrides authType if provided)
• Optional tokenRefreshMargin: number
Seconds before expiry to refresh token proactively (default: 60)
• Optional backgroundRefreshThreshold: number
Seconds threshold for background vs blocking refresh (default: 30)
• Optional captureWalletEvents: boolean
Enable real-time wallet events (default: true)
When enabled, SDK auto-connects to wallet events after authentication. Events are streamed through sdk.events and sdk.walletEvents.
• Optional walletEventsWsUrl: string
Custom wallet events WebSocket URL - overrides environment default. Default: wss://events.pers.ninja (production) or wss://dev.events.pers.ninja (staging)
• Optional autoRestoreSession: boolean
Automatically restore session from stored tokens on SDK initialization (default: true)
When enabled, SDK checks for valid stored tokens during construction and automatically restores the user session. This eliminates the need to manually call restoreSession() and prevents "logged out" flash on app start.
The restoration runs asynchronously and emits 'session_restored' event on success.
Set to false if you need manual control over session restoration timing.
• Optional dataSource: DataSource
Default data source for analytics tracking.
Sets tracking headers on all API requests for attribution:
x-source-channel: Primary ingestion channel (web, mobile, api, etc.)x-source-medium: Marketing medium (email, referral, organic, etc.)x-source-campaign: Campaign identifier for trackingx-source: Traffic source reference
Example
// Simple channel tracking
const config: PersConfig = {
dataSource: { channel: 'mobile' }
};
// Full attribution tracking
const config: PersConfig = {
dataSource: {
channel: 'web',
medium: 'email',
campaign: 'summer_promo_2026',
source: 'mailchimp'
}
};• Optional platform: Platform
Platform information for analytics.
Sent as JSON in x-platform header for device/browser analytics:
- Native: os, osVersion, app, appVersion, deviceType
- Web: os, browser, browserVersion, deviceType
Example
// Native app
const config: PersConfig = {
platform: {
os: 'iOS',
osVersion: '17.4',
app: 'MyApp',
appVersion: '2.3.1',
deviceType: 'phone'
}
};• Optional Readonly apiRoot: string
Internal - API root URL constructed automatically