@getpaidhq/sdk
Version:
TypeScript SDK for GetPaidHQ API - Comprehensive subscription billing platform
1 lines • 15.2 kB
Source Map (JSON)
{"version":3,"sources":["../src/auth/auth.ts","../src/utils/http-client.ts","../src/client.ts"],"names":["AuthManager","config","requestConfig","apiKey","HttpClient","authManager","axios","axiosRetry","retryCount","error","response","handleApiError","url","data","GetPaidHQClient","httpConfig","CustomersResource","ProductsResource","VariantsResource","PricesResource","SubscriptionsResource","UsageResource","OrganizationsResource","MetersResource","OrdersResource","PaymentsResource","InvoicesResource","DunningResource","WebhooksResource","ReportsResource","SettingsResource","GatewaysResource","SessionsResource","DiscountsResource","PaymentLinksResource","CartsResource","PublicPaymentsResource","_bearerToken"],"mappings":"gUAQO,IAAMA,CAAAA,CAAN,KAAkB,CACf,MAAA,CAER,WAAA,CAAYC,CAAAA,CAAoB,CAC9B,GAAI,CAACA,CAAAA,CAAO,MAAA,EAAU,CAACA,EAAO,QAAA,EAAY,CAACA,CAAAA,CAAO,KAAA,CAChD,MAAM,IAAI,KAAA,CAAM,uDAAuD,CAAA,CAEzE,IAAA,CAAK,MAAA,CAASA,EAChB,CAEA,MAAM,SAAA,CAAUC,CAAAA,CAAgE,CAC9E,OAAKA,CAAAA,CAAc,OAAA,GACjBA,CAAAA,CAAc,OAAA,CAAU,EAAC,CAAA,CAIvB,IAAA,CAAK,MAAA,CAAO,MAAA,CACdA,CAAAA,CAAc,OAAA,CAAQ,WAAW,CAAA,CAAI,IAAA,CAAK,MAAA,CAAO,OACxC,IAAA,CAAK,MAAA,CAAO,QAAA,CACrBA,CAAAA,CAAc,OAAA,CAAQ,aAAA,CAAmB,CAAA,OAAA,EAAU,MAAM,IAAA,CAAK,MAAA,CAAO,QAAA,EAAU,CAAA,CAAA,CACtE,IAAA,CAAK,MAAA,CAAO,KAAA,GAIrBA,EAAc,MAAA,CAAS,CACrB,GAAGA,CAAAA,CAAc,MAAA,CACjB,KAAA,CAAO,IAAA,CAAK,MAAA,CAAO,KACrB,CAAA,C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esContent":["import { AxiosRequestConfig } from 'axios';\n\nexport interface AuthConfig {\n apiKey?: string;\n getToken?: () => Promise<string | null>;\n token?: string;\n}\n\nexport class AuthManager {\n private config: AuthConfig;\n\n constructor(config: AuthConfig) {\n if (!config.apiKey && !config.getToken && !config.token) {\n throw new Error('Either apiKey, bearerToken, or token must be provided');\n }\n this.config = config;\n }\n\n async applyAuth(requestConfig: AxiosRequestConfig): Promise<AxiosRequestConfig> {\n if (!requestConfig.headers) {\n requestConfig.headers = {};\n }\n\n // API Key takes precedence over Bearer token, token is used as query parameter\n if (this.config.apiKey) {\n requestConfig.headers['X-API-Key'] = this.config.apiKey;\n } else if (this.config.getToken) {\n requestConfig.headers['Authorization'] = `Bearer ${await this.config.getToken()}`;\n } else if (this.config.token) {\n // Add token as query parameter for public endpoints\n // Ensure params object exists and merge with any existing params\n // Merge our token with any existing params\n requestConfig.params = {\n ...requestConfig.params,\n token: this.config.token,\n };\n }\n\n return requestConfig;\n }\n\n updateApiKey(apiKey: string): void {\n this.config.apiKey = apiKey;\n }\n\n getAuthType(): 'apiKey' | 'bearer' | 'token' | null {\n if (this.config.apiKey) return 'apiKey';\n if (this.config.getToken) return 'bearer';\n if (this.config.token) return 'token';\n return null;\n }\n}\n","import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';\nimport axiosRetry from 'axios-retry';\nimport { AuthManager } from '../auth/auth';\nimport { handleApiError } from '../errors/errors';\n\nexport interface HttpClientConfig {\n baseURL: string;\n timeout?: number;\n retries?: number;\n retryDelay?: number;\n userAgent?: string;\n}\n\nexport class HttpClient {\n private client: AxiosInstance;\n private authManager: AuthManager;\n\n constructor(config: HttpClientConfig, authManager: AuthManager) {\n this.authManager = authManager;\n\n this.client = axios.create({\n baseURL: config.baseURL,\n timeout: config.timeout || 30000,\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n // Configure retry logic\n axiosRetry(this.client, {\n retries: config.retries || 3,\n retryDelay: (retryCount) => {\n const delay = config.retryDelay || 1000;\n return delay * Math.pow(2, retryCount - 1); // Exponential backoff\n },\n retryCondition: (error) => {\n // Retry on network errors\n return axiosRetry.isNetworkError(error);\n },\n });\n\n // Request interceptor for authentication\n this.client.interceptors.request.use(\n async (config) => {\n const authConfig = await this.authManager.applyAuth(config);\n return authConfig as any;\n },\n (error) => Promise.reject(error),\n );\n\n // Response interceptor for error handling\n this.client.interceptors.response.use(\n (response) => response,\n (error) => handleApiError(error),\n );\n }\n\n async get<T>(url: string, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.get<T>(url, config);\n return response.data;\n }\n\n async post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.post<T>(url, data, config);\n return response.data;\n }\n\n async put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.put<T>(url, data, config);\n return response.data;\n }\n\n async patch<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.patch<T>(url, data, config);\n return response.data;\n }\n\n async delete<T = void>(url: string, config?: AxiosRequestConfig): Promise<T> {\n const response = await this.client.delete<T>(url, config);\n return response.data;\n }\n\n getAxiosInstance(): AxiosInstance {\n return this.client;\n }\n}\n","import { AuthManager } from './auth/auth';\nimport { HttpClient, HttpClientConfig } from './utils/http-client';\n\n// Export HttpClient for advanced use cases\nexport { HttpClient } from './utils/http-client';\nimport {\n CustomersResource,\n ProductsResource,\n VariantsResource,\n PricesResource,\n SubscriptionsResource,\n UsageResource,\n OrganizationsResource,\n MetersResource,\n OrdersResource,\n PaymentsResource,\n InvoicesResource,\n DunningResource,\n WebhooksResource,\n ReportsResource,\n SettingsResource,\n GatewaysResource,\n SessionsResource,\n DiscountsResource,\n PaymentLinksResource,\n CartsResource,\n PublicPaymentsResource,\n} from './resources';\n\nexport interface GetPaidHQClientConfig {\n /**\n * API key for authentication (starts with 'sk_')\n */\n apiKey?: string;\n\n /**\n * Async function that returns bearer token for OAuth authentication\n */\n getToken?: () => Promise<string | null>;\n /**\n * Bearer token for OAuth authentication\n */\n bearerToken?: string;\n\n /**\n * Token for public payment endpoints (used as query parameter)\n */\n token?: string;\n\n /**\n * Base URL for the API\n * @default https://api.getpaidhq.co\n */\n baseURL?: string;\n\n /**\n * Request timeout in milliseconds\n * @default 30000 (30 seconds)\n */\n timeout?: number;\n\n /**\n * Number of retry attempts for failed requests\n * @default 3\n */\n retries?: number;\n\n /**\n * Delay between retries in milliseconds\n * @default 1000 (1 second)\n */\n retryDelay?: number;\n\n /**\n * Custom user agent string\n */\n userAgent?: string;\n}\n\nexport class GetPaidHQClient {\n private authManager: AuthManager;\n public readonly httpClient: HttpClient;\n\n // Resources\n public readonly customers: CustomersResource;\n public readonly products: ProductsResource;\n public readonly variants: VariantsResource;\n public readonly prices: PricesResource;\n public readonly subscriptions: SubscriptionsResource;\n public readonly usage: UsageResource;\n public readonly organizations: OrganizationsResource;\n public readonly meters: MetersResource;\n public readonly orders: OrdersResource;\n public readonly payments: PaymentsResource;\n public readonly invoices: InvoicesResource;\n public readonly dunning: DunningResource;\n public readonly webhooks: WebhooksResource;\n public readonly reports: ReportsResource;\n public readonly settings: SettingsResource;\n public readonly gateways: GatewaysResource;\n public readonly sessions: SessionsResource;\n public readonly discounts: DiscountsResource;\n public readonly paymentLinks: PaymentLinksResource;\n public readonly carts: CartsResource;\n public readonly publicPayments: PublicPaymentsResource;\n\n constructor(config: GetPaidHQClientConfig) {\n // Validate auth config - allow token as standalone auth for public endpoints only\n if (!config.apiKey && !config.getToken && !config.token) {\n throw new Error('Either apiKey, bearerToken, or token must be provided');\n }\n\n // Initialize auth manager\n this.authManager = new AuthManager({\n apiKey: config.apiKey,\n getToken: config.getToken,\n token: config.token,\n });\n\n // Initialize HTTP client\n const httpConfig: HttpClientConfig = {\n baseURL: config.baseURL || 'https://api.getpaidhq.co',\n timeout: config.timeout,\n retries: config.retries,\n retryDelay: config.retryDelay,\n userAgent: config.userAgent,\n };\n\n this.httpClient = new HttpClient(httpConfig, this.authManager);\n\n // Initialize resources\n this.customers = new CustomersResource(this.httpClient);\n this.products = new ProductsResource(this.httpClient);\n this.variants = new VariantsResource(this.httpClient);\n this.prices = new PricesResource(this.httpClient);\n this.subscriptions = new SubscriptionsResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.organizations = new OrganizationsResource(this.httpClient);\n this.meters = new MetersResource(this.httpClient);\n this.orders = new OrdersResource(this.httpClient);\n this.payments = new PaymentsResource(this.httpClient);\n this.invoices = new InvoicesResource(this.httpClient);\n this.dunning = new DunningResource(this.httpClient);\n this.webhooks = new WebhooksResource(this.httpClient);\n this.reports = new ReportsResource(this.httpClient);\n this.settings = new SettingsResource(this.httpClient);\n this.gateways = new GatewaysResource(this.httpClient);\n this.sessions = new SessionsResource(this.httpClient);\n this.discounts = new DiscountsResource(this.httpClient);\n this.paymentLinks = new PaymentLinksResource(this.httpClient);\n this.carts = new CartsResource(this.httpClient);\n this.publicPayments = new PublicPaymentsResource(this.httpClient);\n }\n\n /**\n * Update API key for authentication\n */\n updateApiKey(apiKey: string): void {\n this.authManager.updateApiKey(apiKey);\n }\n\n /**\n * Update bearer token for authentication\n */\n updateBearerToken(_bearerToken: string): void {}\n\n /**\n * Check API health\n */\n async healthCheck(): Promise<{ status: string }> {\n return this.httpClient.get<{ status: string }>('/api/health');\n }\n}\n"]}