@getpaidhq/sdk
Version:
TypeScript SDK for GetPaidHQ API - Comprehensive subscription billing platform
3 lines • 3.23 kB
JavaScript
import {h}from'./chunk-OSMPDGGU.js';import {a,b,c,d,e,f,g,h as h$1,i as i$1,j,k,l,m,n as n$1,o,p,q,r,s,t,u}from'./chunk-2ISV2UKC.js';import H from'axios';import L from'axios-retry';var n=class{config;constructor(e){if(!e.apiKey&&!e.getToken&&!e.token)throw new Error("Either apiKey, bearerToken, or token must be provided");this.config=e;}async applyAuth(e){return e.headers||(e.headers={}),this.config.apiKey?e.headers["X-API-Key"]=this.config.apiKey:this.config.getToken?e.headers.Authorization=`Bearer ${await this.config.getToken()}`:this.config.token&&(e.params={...e.params,token:this.config.token}),e}updateApiKey(e){this.config.apiKey=e;}getAuthType(){return this.config.apiKey?"apiKey":this.config.getToken?"bearer":this.config.token?"token":null}};var i=class{client;authManager;constructor(e,s){this.authManager=s,this.client=H.create({baseURL:e.baseURL,timeout:e.timeout||3e4,headers:{"Content-Type":"application/json"}}),L(this.client,{retries:e.retries||3,retryDelay:t=>(e.retryDelay||1e3)*Math.pow(2,t-1),retryCondition:t=>L.isNetworkError(t)}),this.client.interceptors.request.use(async t=>await this.authManager.applyAuth(t),t=>Promise.reject(t)),this.client.interceptors.response.use(t=>t,t=>h(t));}async get(e,s){return (await this.client.get(e,s)).data}async post(e,s,t){return (await this.client.post(e,s,t)).data}async put(e,s,t){return (await this.client.put(e,s,t)).data}async patch(e,s,t){return (await this.client.patch(e,s,t)).data}async delete(e,s){return (await this.client.delete(e,s)).data}getAxiosInstance(){return this.client}};var U=class{authManager;httpClient;customers;products;variants;prices;subscriptions;usage;organizations;meters;orders;payments;invoices;dunning;webhooks;reports;settings;gateways;sessions;discounts;paymentLinks;carts;publicPayments;constructor(e$1){if(!e$1.apiKey&&!e$1.getToken&&!e$1.token)throw new Error("Either apiKey, bearerToken, or token must be provided");this.authManager=new n({apiKey:e$1.apiKey,getToken:e$1.getToken,token:e$1.token});let s$1={baseURL:e$1.baseURL||"https://api.getpaidhq.co",timeout:e$1.timeout,retries:e$1.retries,retryDelay:e$1.retryDelay,userAgent:e$1.userAgent};this.httpClient=new i(s$1,this.authManager),this.customers=new a(this.httpClient),this.products=new b(this.httpClient),this.variants=new c(this.httpClient),this.prices=new d(this.httpClient),this.subscriptions=new e(this.httpClient),this.usage=new f(this.httpClient),this.organizations=new g(this.httpClient),this.meters=new h$1(this.httpClient),this.orders=new i$1(this.httpClient),this.payments=new j(this.httpClient),this.invoices=new k(this.httpClient),this.dunning=new l(this.httpClient),this.webhooks=new m(this.httpClient),this.reports=new n$1(this.httpClient),this.settings=new o(this.httpClient),this.gateways=new p(this.httpClient),this.sessions=new q(this.httpClient),this.discounts=new r(this.httpClient),this.paymentLinks=new s(this.httpClient),this.carts=new t(this.httpClient),this.publicPayments=new u(this.httpClient);}updateApiKey(e){this.authManager.updateApiKey(e);}updateBearerToken(e){}async healthCheck(){return this.httpClient.get("/api/health")}};
export{i as a,U as b};//# sourceMappingURL=chunk-CK4DI7G3.js.map
//# sourceMappingURL=chunk-CK4DI7G3.js.map