PERS SDK - v2.3.26 / Exports / PersApiClient
- ensureValidToken
- setEvents
- get
- post
- put
- patch
- delete
- getAuthService
- getConfig
- getOriginalConfig
- setDataSource
- updateDataSource
- setPlatform
- getDataSource
- getPlatform
- validateTracking
• new PersApiClient(httpClient, config): PersApiClient
Creates a new PERS API Client instance
| Name | Type | Description |
|---|---|---|
httpClient | HttpClient | Platform-specific HTTP client implementation |
config | PersConfig | Configuration options for the API client |
▸ ensureValidToken(): Promise<void>
Ensures valid authentication token before making requests
Validates the current token and automatically refreshes if expired or near expiration. Uses a 120-second margin - tokens are refreshed if they expire within 2 minutes.
This method is called automatically before each request but can also be called manually when needed (e.g., app resume from background).
Promise<void>
Promise that resolves when token validation is complete
Throws
Error if token refresh fails
Example
// Validate tokens when app becomes active
await apiClient.ensureValidToken();▸ setEvents(events): void
Set event emitter for error event emission
| Name | Type |
|---|---|
events | PersEventEmitter |
void
▸ get<T>(endpoint, responseType?): Promise<T>
Performs an authenticated GET request
| Name | Description |
|---|---|
T | Expected response type |
| Name | Type | Description |
|---|---|---|
endpoint | string | API endpoint path (without base URL) |
responseType? | "json" | "blob" | "text" | "arraybuffer" | Expected response format |
Promise<T>
Promise resolving to typed response data
Example
const user = await client.get<User>('/users/123');
const csvData = await client.get('/export/data', 'blob');▸ post<T>(endpoint, body?, options?): Promise<T>
Performs an authenticated POST request
| Name |
|---|
T |
| Name | Type |
|---|---|
endpoint | string |
body? | unknown |
options? | Object |
options.bypassAuth? | boolean |
options.isRefreshRequest? | boolean |
Promise<T>
▸ put<T>(endpoint, body?): Promise<T>
Generic PUT request
| Name |
|---|
T |
| Name | Type |
|---|---|
endpoint | string |
body? | unknown |
Promise<T>
▸ patch<T>(endpoint, body?): Promise<T>
| Name |
|---|
T |
| Name | Type |
|---|---|
endpoint | string |
body? | unknown |
Promise<T>
▸ delete<T>(endpoint): Promise<T>
Generic DELETE request
| Name |
|---|
T |
| Name | Type |
|---|---|
endpoint | string |
Promise<T>
▸ getAuthService(): AuthService
- For AuthManager use only
▸ getConfig(): PersConfig & Required<Pick<PersConfig, "environment" | "apiVersion" | "timeout" | "retries">>
Get current configuration (returns merged config)
PersConfig & Required<Pick<PersConfig, "environment" | "apiVersion" | "timeout" | "retries">>
▸ getOriginalConfig(): PersConfig
Get original user configuration
▸ setDataSource(dataSource): void
Set data source tracking info (replaces existing)
| Name | Type |
|---|---|
dataSource | DataSource |
void
▸ updateDataSource(dataSource): void
Update data source tracking info (merges with existing)
| Name | Type |
|---|---|
dataSource | Partial<DataSource> |
void
▸ setPlatform(platform): void
Set platform info for analytics
| Name | Type |
|---|---|
platform | Platform |
void
▸ getDataSource(): undefined | DataSource
Get current data source config
undefined | DataSource
▸ getPlatform(): undefined | Platform
Get current platform info
undefined | Platform
▸ validateTracking(): Object
Validate tracking configuration (for debugging)
Object
| Name | Type |
|---|---|
isValid | boolean |
warnings | string[] |