$ show stripe/stripe-node
stripe-node is the official Stripe API client library for Node.js and JavaScript runtimes. It provides a comprehensive, typed interface to the entire Stripe REST API (both V1 and V2), covering payments, billing, Connect, Treasury, Issuing, Terminal, and more. The library is auto-generated from Stripe's OpenAPI spec, ensuring tight alignment with the API surface. It supports multiple JavaScript runtimes (Node.js, Deno, Cloudflare Workers, browsers) via platform abstraction layers for HTTP, crypto, and event emission. Key architectural features include a pluggable HTTP client hierarchy (Node native, Fetch, custom endpoints), runtime type coercion for V2 decimal and int64 fields, robust error generation with typed error classes, automatic pagination with async iterators, and webhook signature verification. The codebase is well-tested with unit and integration tests across runtimes, and follows semantic versioning. While the vast majority of resource files are generated boilerplate, the core infrastructure (request sender, platform functions, crypto providers, auto-pagination) demonstrates solid engineering craftsmanship and is designed for extensibility.
The LLM identified 6 files worth highlighting for reuse:
A standalone, well-tested arbitrary-precision decimal class backed by BigInt. Supports all basic arithmetic operations, rounding (half-up, half-even, etc.), comparison, and serialization. Designed for monetary amounts, it handles edge cases like negative zero and exponential notation. It has zero internal dependencies and can be extracted into any project needing safe decimal math.
Provides async iteration over paginated API results, supporting V1 cursor-based lists, V1 search, and V2 next-page-URL pagination. Exposes `autoPagingEach` (callback-based), `autoPagingToArray`, and `Symbol.asyncIterator`. The implementation is generic and self-contained (only depends on a `request` function), making it reusable in any API client needing automatic pagination.
Implements Stripe webhook event construction and signature verification using HMAC-SHA256. Provides both sync and async variants (`constructEvent`, `constructEventAsync`), along with test header generation. The logic is self-contained and relies only on the crypto provider abstraction, making it extractable for any service needing to verify webhook payloads.
Defines an abstract `CryptoProvider` class with methods for HMAC computation, secure comparison, and random byte generation. Implementations exist for Node.js (`NodeCryptoProvider`) and Web Crypto (`SubtleCryptoProvider`). This pattern enables runtime-agnostic cryptographic operations and is reusable as a clean interface for pluggable crypto backends.
Base abstract class for HTTP clients, defining methods for `makeRequest`, `makeRequestWithStreaming`, and error handling. Concrete implementations (`NodeHttpClient`, `FetchHttpClient`, `EndpointFetchHttpClient`) demonstrate how to abstract over different transport layers. The interface is clean and could be reused in any multi-runtime HTTP client library.
Abstracts platform-specific functionality: HTTP client creation, crypto provider, UUID generation, secure string comparison, telemetry ID, and environment detection. Each runtime (Node, Web, Extensibility) provides a concrete subclass. The singleton pattern (`getPlatformFunctions`) and clean interface make it a reusable foundation for cross-runtime libraries.