PerspectPerspectDocs
Go to Admin
View as Markdown

perspectapi-ts-sdk

Classes

  • CreditsV2Client

Class: CreditsV2Client

Extends

  • BaseV2Client

Constructors

Constructor

new CreditsV2Client(http, basePath, cache?): CreditsV2Client

Parameters

http

HttpClient

basePath

string

cache?

CacheManager

Returns

CreditsV2Client

Inherited from

BaseV2Client.constructor

Properties

basePath

protected basePath: string

Inherited from

BaseV2Client.basePath

cache?

protected optional cache?: CacheManager

Inherited from

BaseV2Client.cache

http

protected http: HttpClient

Inherited from

BaseV2Client.http

Methods

buildPath()

protected buildPath(endpoint): string

Parameters

endpoint

string

Returns

string

Inherited from

BaseV2Client.buildPath

deleteOne()

protected deleteOne(path): Promise<V2Deleted>

DELETE a resource.

Parameters

path

string

Returns

Promise<V2Deleted>

Inherited from

BaseV2Client.deleteOne

getList()

protected getList<T>(path, params?, cachePolicy?): Promise<V2List<T>>

GET a list of resources with cursor pagination, with optional caching.

Type Parameters

T

T

Parameters

path

string

params?

object

cachePolicy?

CachePolicy

Returns

Promise<V2List<T>>

Inherited from

BaseV2Client.getList

getMyBalance()

getMyBalance(siteName): Promise<V2CreditBalance>

Get the current credit balance for the authenticated user.

Parameters

siteName

string

Returns

Promise<V2CreditBalance>

getMyCredits()

getMyCredits(siteName): Promise<V2CreditBalance>

Get credit balance and transaction history for the authenticated user.

Parameters

siteName

string

Returns

Promise<V2CreditBalance>

getOne()

protected getOne<T>(path, params?, cachePolicy?): Promise<T>

GET a single resource, with optional caching.

Type Parameters

T

T

Parameters

path

string

params?

object

cachePolicy?

CachePolicy

Returns

Promise<T>

Inherited from

BaseV2Client.getOne

getUserBalance()

getUserBalance(siteName, userId): Promise<V2CreditBalance>

Get the credit balance for a specific user (admin).

Parameters

siteName

string

userId

string

Returns

Promise<V2CreditBalance>

grantCredit()

grantCredit(siteName, userId, data): Promise<V2GrantCreditResult>

Grant credit to a specific user (admin).

Parameters

siteName

string

userId

string

data

V2GrantCreditParams

Returns

Promise<V2GrantCreditResult>

invalidateCache()

protected invalidateCache(options): Promise<void>

Invalidate cache entries by keys or tags.

Parameters

options

CacheInvalidateOptions

Returns

Promise<void>

Inherited from

BaseV2Client.invalidateCache

listAutoPaginate()

protected listAutoPaginate<T>(path, params?): AsyncGenerator<T, void, unknown>

Auto-paginating async generator. Yields every item across all pages.

Usage: for await (const item of client.listAutoPaginate(path, params)) { ... }

Type Parameters

T

T extends object

Parameters

path

string

params?

object

Returns

AsyncGenerator<T, void, unknown>

Inherited from

BaseV2Client.listAutoPaginate

patchOne()

protected patchOne<T>(path, body?): Promise<T>

PATCH to update a resource.

Type Parameters

T

T

Parameters

path

string

body?

unknown

Returns

Promise<T>

Inherited from

BaseV2Client.patchOne

post()

protected post<T>(path, body?): Promise<T>

POST to create a resource.

Type Parameters

T

T

Parameters

path

string

body?

unknown

Returns

Promise<T>

Inherited from

BaseV2Client.post

putOne()

protected putOne<T>(path, body?): Promise<T>

PUT to upsert a resource.

Type Parameters

T

T

Parameters

path

string

body?

unknown

Returns

Promise<T>

Inherited from

BaseV2Client.putOne

sitePath()

protected sitePath(siteName, resource, suffix?): string

Parameters

siteName

string

resource

string

suffix?

string = ''

Returns

string

Inherited from

BaseV2Client.sitePath