UNPKG

@getpaidhq/sdk

Version:

TypeScript SDK for GetPaidHQ API - Comprehensive subscription billing platform

3 lines 3.79 kB
'use strict';var chunkLPX5RYGR_cjs=require('./chunk-LPX5RYGR.cjs'),chunkM7FS46VT_cjs=require('./chunk-M7FS46VT.cjs'),U=require('axios'),D=require('axios-retry');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var U__default=/*#__PURE__*/_interopDefault(U);var D__default=/*#__PURE__*/_interopDefault(D);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=U__default.default.create({baseURL:e.baseURL,timeout:e.timeout||3e4,headers:{"Content-Type":"application/json"}}),D__default.default(this.client,{retries:e.retries||3,retryDelay:t=>(e.retryDelay||1e3)*Math.pow(2,t-1),retryCondition:t=>D__default.default.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=>chunkLPX5RYGR_cjs.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 L=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){if(!e.apiKey&&!e.getToken&&!e.token)throw new Error("Either apiKey, bearerToken, or token must be provided");this.authManager=new n({apiKey:e.apiKey,getToken:e.getToken,token:e.token});let s={baseURL:e.baseURL||"https://api.getpaidhq.co",timeout:e.timeout,retries:e.retries,retryDelay:e.retryDelay,userAgent:e.userAgent};this.httpClient=new i(s,this.authManager),this.customers=new chunkM7FS46VT_cjs.a(this.httpClient),this.products=new chunkM7FS46VT_cjs.b(this.httpClient),this.variants=new chunkM7FS46VT_cjs.c(this.httpClient),this.prices=new chunkM7FS46VT_cjs.d(this.httpClient),this.subscriptions=new chunkM7FS46VT_cjs.e(this.httpClient),this.usage=new chunkM7FS46VT_cjs.f(this.httpClient),this.organizations=new chunkM7FS46VT_cjs.g(this.httpClient),this.meters=new chunkM7FS46VT_cjs.h(this.httpClient),this.orders=new chunkM7FS46VT_cjs.i(this.httpClient),this.payments=new chunkM7FS46VT_cjs.j(this.httpClient),this.invoices=new chunkM7FS46VT_cjs.k(this.httpClient),this.dunning=new chunkM7FS46VT_cjs.l(this.httpClient),this.webhooks=new chunkM7FS46VT_cjs.m(this.httpClient),this.reports=new chunkM7FS46VT_cjs.n(this.httpClient),this.settings=new chunkM7FS46VT_cjs.o(this.httpClient),this.gateways=new chunkM7FS46VT_cjs.p(this.httpClient),this.sessions=new chunkM7FS46VT_cjs.q(this.httpClient),this.discounts=new chunkM7FS46VT_cjs.r(this.httpClient),this.paymentLinks=new chunkM7FS46VT_cjs.s(this.httpClient),this.carts=new chunkM7FS46VT_cjs.t(this.httpClient),this.publicPayments=new chunkM7FS46VT_cjs.u(this.httpClient);}updateApiKey(e){this.authManager.updateApiKey(e);}updateBearerToken(e){}async healthCheck(){return this.httpClient.get("/api/health")}}; exports.a=i;exports.b=L;//# sourceMappingURL=chunk-3AWKVUG7.cjs.map //# sourceMappingURL=chunk-3AWKVUG7.cjs.map