Dub
Official TypeScript SDK for the Dub.co link-management and partner-marketing API.
Repository Health
Technical Analysis
Dub (npm package dub) is the official Speakeasy-generated TypeScript SDK for Dub.co, the link-management and partner-marketing platform used to create trackable short links, run affiliate/referral programs, and measure conversions. It wraps the full Dub REST API — links, analytics, domains, partners, discount codes, commissions, payouts, bounties, QR codes, and embeddable analytics tokens — behind a single Dub client with resource-scoped methods like dub.links.create() and dub.track.sale().
The SDK ships typed request/response models validated with Zod, a typed error hierarchy for every HTTP failure mode, configurable retry/backoff, async-iterator pagination, and both a stateful Dub client and tree-shakeable standalone functions for bundlers that care about size. It targets modern JavaScript runtimes — Node.js LTS, Bun, Deno, and evergreen browsers — with dual ESM/CommonJS builds.
What You Get
- A single
Dubclient exposing 16 resource groups (links, analytics, domains, partners, track, commissions, payouts, discount codes, bounties, QR codes, and more) as typed methods - Typed error classes (
DubErrorand its subclasses) carrying HTTP status, headers, and raw response for every failure mode - Built-in retry/backoff, async-iterator pagination, and OAuth2 or API-key authentication handled by the client
- Standalone, tree-shakeable functions in addition to the class-based client, for bundlers optimizing for size
- Dual ESM/CommonJS builds plus a JSR package, tested against Node.js LTS, Bun 1+, and Deno 1.39+
Common Use Cases
- Short-link creation in a SaaS onboarding flow - A developer wires
dub.links.create()into a signup flow to auto-generate branded short links for each new user’s referral page. - Affiliate/partner program automation - A growth engineer uses
dub.partners,dub.discountCodes, anddub.commissionsto programmatically onboard partners, issue discount codes, and reconcile payouts without touching the Dub dashboard. - Server-side conversion tracking - A backend calls
dub.track.lead()anddub.track.sale()after a checkout webhook fires, attributing revenue back to the originating short link. - Embedded analytics dashboards - A product team calls
dub.analytics.retrieve()anddub.embedTokens.referrals()to render click/referral analytics inside their own app via Dub’s embeddable dashboard tokens.
Under The Hood
Architecture
Dub-ts is a Speakeasy-generated SDK organized as a thin composition layer: src/sdk/sdk.ts defines the Dub class, which lazily instantiates one class per API resource (Links, Analytics, Track, Partners, Commissions, Payouts, DiscountCodes, Bounties, QRCodes, EmbedTokens, and others) via getters backed by a shared ClientSDK base (src/lib/sdks.ts). A parallel DubCore class in src/core.ts exposes the same operations as standalone functions in src/funcs/, decoupling API calls from the stateful client for tree-shaking. Cross-cutting concerns — retry/backoff (src/lib/retries.ts), authentication (src/lib/security.ts, src/hooks/auth.ts), request/response hooks (src/hooks/hooks.ts), and base-URL resolution — are isolated in lib/ and hooks/ rather than mixed into resource classes, and src/models/{components,operations,errors} (Zod schemas validated via src/lib/schemas.ts) form the typed contract between functions and callers.
Tech Stack
Written in TypeScript (~5.8), built with tshy for simultaneous ESM/CommonJS output plus a JSR distribution, validated at runtime with zod (supporting both v3 and v4), and using a dedicated jsonpath-rfc9535 dependency for response-path extraction. It relies on the native Fetch API and Web Streams for HTTP and pagination rather than a bundled HTTP client, and is linted with ESLint 9 / typescript-eslint at zero-warning tolerance. Distribution targets Node.js active/LTS releases, Bun 1+, Deno 1.39+, and evergreen browsers.
Code Quality
No test files (*.test.ts or equivalent) are present anywhere in the repository despite vitest being listed as a devDependency, and the CI workflows present (sdk_generation.yaml, sdk_publish.yaml, tagging.yaml) regenerate and publish the SDK rather than run a test suite — test coverage for this generated client is not visible in this repo. Error handling is a strength: every failure surfaces as a typed DubError subclass (BadRequest, Unauthorized, Forbidden, NotFound, Conflict, RateLimitExceeded, InternalServerError, plus connection/timeout error classes) carrying status code, headers, and raw response. Naming is uniformly generated (PascalCase resources/errors, camelCase methods), and nearly every source file (193 of 214) carries JSDoc-style documentation comments generated alongside the types.
API Design
The public API mirrors Dub’s REST resources one-to-one (dub.links.create(), dub.analytics.retrieve(), dub.track.sale()), which keeps method names predictable for anyone who already knows the Dub API. Getting started requires only new Dub({ token }) before calling any method, and every resource ships its own generated README under docs/sdks/ with runnable examples. Async-iterator pagination, injectable custom HTTP clients, and both OAuth2 and API-key auth are supported out of the box. The surface area is broad — 16 resource groups — but that mirrors the breadth of the underlying Dub API rather than a distinctive design choice of the SDK itself.
Used by 4 apps in this directory
Cal.diy
Scheduling
The 100% MIT-licensed, community-driven scheduling platform — self-host your own booking infrastructure with no enterprise strings attached.
Cap
Team Chat · Video Conferencing
Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.
Dub
Marketing · Analytics
The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.
Papermark
Digital Signiture · File Storage
Open-source DocSend alternative with page-by-page analytics, secure data rooms, and custom domains for document sharing.