@chemicalluck/recharge-api-node
Version:
ReCharge API Node.js Client
164 lines (141 loc) • 5.41 kB
TypeScript
import { Response, Request } from 'node-fetch';
declare class HTTPResponseError extends Error {
response: Response;
constructor(response: Response);
}
declare class RechargeAPIError extends Error {
constructor(message: string);
}
declare class NotImplementedError extends Error {
constructor(message: string);
}
declare enum RequestMethod {
GET = "GET",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE"
}
declare enum RechargeAPIVersion {
v1 = "2021-01",
v2 = "2021-11"
}
declare class RechargeClient {
private _headers;
private _retries;
private readonly _maxRetries;
private readonly _retryDelay;
constructor(api_key: string);
get retries(): number;
set retries(value: number);
get maxRetries(): number;
get retryDelay(): number;
get headers(): Record<string, string>;
set headers(value: Record<string, string>);
_setVersion(value: RechargeAPIVersion): void;
private _retry;
private _delay;
private _constructURL;
private _constructRequestOptions;
_request(method: RequestMethod, url: string, query?: Record<string, string>, json?: unknown): Promise<Response>;
_send(request: Request): Promise<Response>;
_extractData<T>(response: Response): Promise<T>;
_getNextPageV1(response: Response): string | undefined;
_getNextPageV2(_response: Response): string | undefined;
_getNextPage(response: Response, version: RechargeAPIVersion): string | undefined;
paginate<T>(url: string, version: RechargeAPIVersion, query?: Record<string, string>): Promise<T[]>;
get<T>(url: string, version: RechargeAPIVersion, query?: Record<string, string>): Promise<T>;
post<T>(url: string, version: RechargeAPIVersion, json?: unknown): Promise<T>;
put<T>(url: string, version: RechargeAPIVersion, json?: unknown): Promise<T>;
delete<T>(url: string, version: RechargeAPIVersion, json?: unknown): Promise<T>;
}
declare abstract class RechargeResource {
protected readonly base_url: string;
protected resource: string | null;
protected recharge_version: RechargeAPIVersion;
protected client: RechargeClient;
protected constructor(client: RechargeClient);
protected get url(): string;
protected _get<T>(url: string, query?: Record<string, string>): Promise<T>;
protected _post<T>(url: string, body?: unknown): Promise<T>;
protected _put<T>(url: string, body?: unknown): Promise<T>;
protected _delete<T>(url: string, body?: unknown): Promise<T>;
protected _paginate<T>(url: string, query?: Record<string, string>): Promise<T[]>;
}
declare class AddressResource extends RechargeResource {
constructor(client: RechargeClient);
create(customerId: number, body: object): Promise<any>;
get(addressId: number): Promise<any>;
update(addressId: number, body: object): Promise<any>;
delete(addressId: number): Promise<any>;
list(customerId: number, query?: Record<string, string>): Promise<any>;
count(query?: Record<string, string>): Promise<any>;
validate(body: unknown): Promise<any>;
applyDiscount(addressId: number, body: unknown): Promise<any>;
removeDiscount(addressId: number): Promise<any>;
}
declare class ChargeResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class CheckoutResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class CustomerResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class OrderResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class SubscriptionResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class OnetimeResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class DiscountResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class WebhookResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class MetafieldResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class ShopResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class ProductResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class AsyncBatchResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class NotificationResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class TokenResource extends RechargeResource {
constructor(client: RechargeClient);
}
declare class RechargeV1 {
address: AddressResource;
charge: ChargeResource;
checkout: CheckoutResource;
customer: CustomerResource;
order: OrderResource;
subscription: SubscriptionResource;
onetime: OnetimeResource;
discount: DiscountResource;
webhook: WebhookResource;
metafield: MetafieldResource;
shop: ShopResource;
product: ProductResource;
asyncBatch: AsyncBatchResource;
notification: NotificationResource;
token: TokenResource;
constructor(client: RechargeClient);
}
declare class Recharge {
private client;
v1: RechargeV1;
constructor(api_key: string, client?: RechargeClient);
}
export { HTTPResponseError, NotImplementedError, Recharge, RechargeAPIError, RechargeAPIVersion, RequestMethod };