Skip to content

Tree-shaking and minimal bundles

The SDK is split into one module per API resource, each independently importable via a subpath, instead of one monolithic client class. This matters even outside the browser — a serverless function's cold-start time depends on how much code it has to load, so a smaller bundle is a real win on the server too, not just for front-end bundle size.

Full client (convenience)

ts
import { createClient } from '@klappay/node'

const klap = createClient({ baseUrl: '...', apiKey: '...' })
klap.charges.create(...)
klap.webhooks.create(...)

Pulls in every resource module, regardless of which ones you actually call.

Minimal (only what you use)

ts
import { createChargesClient } from '@klappay/node/charges'

const charges = createChargesClient({ baseUrl: '...', apiKey: '...' })
charges.create(...)

A bundler never even sees the webhooks/metrics/etc. modules in this case — they're not in the import graph at all, which doesn't depend on the bundler being smart enough to eliminate unused code from a bigger object (dead-code elimination on object properties isn't reliably supported everywhere; simply not importing the module in the first place always works).

Available subpaths

SubpathExports
@klappay/node/chargescreateChargesClient
@klappay/node/webhookscreateWebhooksClient, verifyWebhookSignature, constructWebhookEvent
@klappay/node/metricscreateMetricsClient
@klappay/node/sandboxcreateSandboxClient
@klappay/node/distributionscreateDistributionsClient
@klappay/node/networkscreateNetworksClient
@klappay/node/recipientscreateRecipientsClient

Each create*Client(config) takes the same config shape createClient() does ({ baseUrl, apiKey?, debug?, timeoutMs? }) — you're just constructing one resource directly instead of the full composed client.

Verifying a webhook without any client at all

verifyWebhookSignature/constructWebhookEvent (from @klappay/node/webhooks) don't need a configured client — they're plain functions. If all you need is webhook signature verification, you don't need to construct a client at all:

ts
import { verifyWebhookSignature } from '@klappay/node/webhooks'

const isValid = verifyWebhookSignature(rawBody, signatureHeader, secret)

Docs live in ./docs — the source of truth for both the package and this site.