admitad-api-client
Version:
A TypeScript/JavaScript client for the Admitad API with built-in authentication and token management
63 lines • 2.53 kB
TypeScript
import type { AdmitadTokenResponse, AdmitadClientConfig, AdmitadScope, AdmitadRequestOptions, AliExpressCommissionResponse, UrlShortenerResponse, DeeplinkGeneratorParams, DeeplinkGeneratorResult } from '../types/admitad';
export declare class AdmitadApiClient {
private config;
private accessToken;
private refreshToken;
private tokenExpiresAt;
private base64Auth;
constructor(config: AdmitadClientConfig);
/**
* Authenticates with Admitad API and obtains access token
* @param scopes - Array of scopes to request access for
* @returns Promise resolving to token response
*/
authenticate(scopes: AdmitadScope[]): Promise<AdmitadTokenResponse>;
/**
* Ensures we have a valid access token, refreshing if necessary
*/
private ensureValidToken;
/**
* Makes an authenticated request to the Admitad API
* @param endpoint - API endpoint (without base URL)
* @param options - Request options
* @returns Promise resolving to response data
*/
request<T = any>(endpoint: string, options?: AdmitadRequestOptions): Promise<T>;
/**
* Gets current access token
*/
getAccessToken(): string | null;
/**
* Gets current refresh token
*/
getRefreshToken(): string | null;
/**
* Checks if current token is valid and not expired
*/
isAuthenticated(): boolean;
/**
* Clears stored authentication data
*/
logout(): void;
/**
* Gets commission rates for AliExpress products
* @param urls - Array of product URLs to check commission rates for
* @returns Promise resolving to commission rates response
*/
getAliExpressCommissionRates(urls: string[]): Promise<AliExpressCommissionResponse>;
/**
* Shortens an Admitad URL using the URL shortener service
* @param link - The Admitad link to shorten (must belong to Admitad's domains)
* @returns Promise resolving to shortened URL response
*/
shortenUrl(link: string): Promise<UrlShortenerResponse>;
/**
* Generates deeplinks for affiliate programs
* @param websiteId - The ad space ID (w_id)
* @param campaignId - The affiliate program ID (c_id)
* @param params - Deeplink generation parameters
* @returns Promise resolving to generated deeplinks
*/
generateDeeplinks(websiteId: string | number, campaignId: string | number, params: DeeplinkGeneratorParams): Promise<DeeplinkGeneratorResult>;
}
//# sourceMappingURL=admitad-client.d.ts.map