UNPKG

@hyperse/paypal-node-sdk

Version:

NodeJS SDK for PayPal Checkout APIs

46 lines (45 loc) 1.81 kB
import { type HttpRequest } from '@paypal/paypalhttp'; import { type AccessToken } from './AccessToken.js'; import { type PayPalEnvironment } from './PayPalEnvironment.js'; /** * Stores token, token status and a request queue for every client * Documentation * * @see {@link https://github.com/hyperse-io/paypal-node-sdk/tree/main/src/core/TokenCache.ts} */ export declare class TokenCache { private _token; private _locked; private _requests; private _emitter; static cacheForEnvironment(environment: PayPalEnvironment, refreshToken?: string): TokenCache; constructor(); /** * Gets the current token for the client * @return {AccessToken|null} - The current token or null if there is none */ getToken(): AccessToken | null; /** * Sets the token for the current client also setting its status to absent or valid if the token exist or not * @param {AccessToken|null} token - The current token for the client or null to remove it * @return {void} */ setToken(token: AccessToken | null): void; lock(): void; unlock(): void; isLocked(): boolean; isValid(): boolean; isPresent(): boolean; /** * Add a request to the queue and wait for the notify method to signal error or completion * @param {Object} request - The request to be queued * @return {Promise} - A promise that will resolve or rejects when the notify method is called * */ wait(request: HttpRequest): Promise<unknown>; /** * Flush the request queue resolving every call in the order they were added or rejects all calls if an error is provided * @param {Array} [err] - An optional error that rejects all requests instead of resolving them * @return {void} - void */ notify(err?: any): void; }