Skip to content
Last updated

PERS SDK - v2.3.26 / Exports / PersApiClient

Class: PersApiClient

Table of contents

Constructors

Methods

Constructors

constructor

new PersApiClient(httpClient, config): PersApiClient

Creates a new PERS API Client instance

Parameters

NameTypeDescription
httpClientHttpClientPlatform-specific HTTP client implementation
configPersConfigConfiguration options for the API client

Returns

PersApiClient

Defined in

core/pers-api-client.ts:58

Methods

ensureValidToken

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).

Returns

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();

Defined in

core/pers-api-client.ts:134


setEvents

setEvents(events): void

Set event emitter for error event emission

Parameters

NameType
eventsPersEventEmitter

Returns

void

Defined in

core/pers-api-client.ts:331


get

get<T>(endpoint, responseType?): Promise<T>

Performs an authenticated GET request

Type parameters

NameDescription
TExpected response type

Parameters

NameTypeDescription
endpointstringAPI endpoint path (without base URL)
responseType?"json" | "blob" | "text" | "arraybuffer"Expected response format

Returns

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');

Defined in

core/pers-api-client.ts:349


post

post<T>(endpoint, body?, options?): Promise<T>

Performs an authenticated POST request

Type parameters

Name
T

Parameters

NameType
endpointstring
body?unknown
options?Object
options.bypassAuth?boolean
options.isRefreshRequest?boolean

Returns

Promise<T>

Defined in

core/pers-api-client.ts:356


put

put<T>(endpoint, body?): Promise<T>

Generic PUT request

Type parameters

Name
T

Parameters

NameType
endpointstring
body?unknown

Returns

Promise<T>

Defined in

core/pers-api-client.ts:363


patch

patch<T>(endpoint, body?): Promise<T>

Type parameters

Name
T

Parameters

NameType
endpointstring
body?unknown

Returns

Promise<T>

Defined in

core/pers-api-client.ts:368


delete

delete<T>(endpoint): Promise<T>

Generic DELETE request

Type parameters

Name
T

Parameters

NameType
endpointstring

Returns

Promise<T>

Defined in

core/pers-api-client.ts:374


getAuthService

getAuthService(): AuthService

  • For AuthManager use only

Returns

AuthService

Defined in

core/pers-api-client.ts:446


getConfig

getConfig(): PersConfig & Required<Pick<PersConfig, "environment" | "apiVersion" | "timeout" | "retries">>

Get current configuration (returns merged config)

Returns

PersConfig & Required<Pick<PersConfig, "environment" | "apiVersion" | "timeout" | "retries">>

Defined in

core/pers-api-client.ts:453


getOriginalConfig

getOriginalConfig(): PersConfig

Get original user configuration

Returns

PersConfig

Defined in

core/pers-api-client.ts:460


setDataSource

setDataSource(dataSource): void

Set data source tracking info (replaces existing)

Parameters

NameType
dataSourceDataSource

Returns

void

Defined in

core/pers-api-client.ts:469


updateDataSource

updateDataSource(dataSource): void

Update data source tracking info (merges with existing)

Parameters

NameType
dataSourcePartial<DataSource>

Returns

void

Defined in

core/pers-api-client.ts:474


setPlatform

setPlatform(platform): void

Set platform info for analytics

Parameters

NameType
platformPlatform

Returns

void

Defined in

core/pers-api-client.ts:479


getDataSource

getDataSource(): undefined | DataSource

Get current data source config

Returns

undefined | DataSource

Defined in

core/pers-api-client.ts:484


getPlatform

getPlatform(): undefined | Platform

Get current platform info

Returns

undefined | Platform

Defined in

core/pers-api-client.ts:489


validateTracking

validateTracking(): Object

Validate tracking configuration (for debugging)

Returns

Object

NameType
isValidboolean
warningsstring[]

Defined in

core/pers-api-client.ts:494