@streamsdk/typescript
v1.0.4
Published
Official Node.js/TypeScript SDK for Stream API - Complete payment processing with consumers, products, subscriptions, invoices, and payment links
Maintainers
Readme
@streamsdk/typescript · Official Stream SDK for TypeScript
Official Node.js/TypeScript SDK for Stream API
📚 Table of Contents
- Overview
- Installation
- Quick Start
- SDK Features
- Usage
- Examples
- Express.js Integration
- API Documentation
- Error Handling
- Contributing
- Support
- License
Overview
The Stream SDK provides a complete TypeScript/JavaScript interface to the Stream payment platform. Process payments, manage subscriptions, create invoices, and handle customer data with full type safety and modern JavaScript features.
Key Features:
- 🔐 Secure API Key authentication
- 👥 Customer (Consumer) management
- 📦 Product catalog management
- 💳 Payment link creation
- 🔄 Subscription handling
- 🧾 Invoice generation
- 🎟️ Coupon & discount management
- 📝 Full TypeScript support
- ⚡ ES Modules and CommonJS compatible
Installation
npm install @streamsdk/typescriptOr install from GitHub:
npm install github:streampayments/streamsdk-typescript#v1.0.0Add to package.json
{
"dependencies": {
"@streamsdk/typescript": "^1.0.0"
}
}Quick Start
import StreamSDK from "@streamsdk/typescript";
// Initialize the SDK
const client = StreamSDK.init(process.env.STREAM_API_KEY!);
// Create a payment link
const result = await client.createSimplePaymentLink({
name: "Monthly Subscription",
amount: 99.99,
consumer: {
email: "[email protected]",
name: "Ahmad Ali",
phone: "+966501234567",
},
product: {
name: "Premium Plan",
price: 99.99,
},
successRedirectUrl: "https://yourapp.com/success",
failureRedirectUrl: "https://yourapp.com/failure",
});
console.log("Payment URL:", result.paymentUrl);SDK Features
Core Capabilities
| Feature | Description | | ------------------ | ------------------------------------------ | | Authentication | API Key and Bearer Token support | | Consumers | Create, update, list, and delete customers | | Products | Manage your product catalog | | Payment Links | Generate secure payment links | | Subscriptions | Handle recurring payments | | Invoices | Create and manage invoices | | Coupons | Discount and promotion management | | Webhooks | Real-time event notifications |
Supported Features
- ✅ Single or multiple products per payment
- ✅ Guest checkout (no consumer required)
- ✅ Smart resource matching (automatic deduplication)
- ✅ SAR currency (default)
- ✅ Custom metadata support
- ✅ Full TypeScript type definitions
- ✅ ESM and CommonJS support
Usage
For detailed usage examples and API documentation, please refer to the API Documentation section below.
Authentication
Initialize the SDK with your API key:
import StreamSDK from "@streamsdk/typescript";
const client = StreamSDK.init(process.env.STREAM_API_KEY!);For more authentication options and detailed examples for each resource, see the documentation links in the Available Resources and Operations section.
Examples
Explore complete TypeScript SDK examples in the examples directory:
- basic.mjs - Basic SDK usage
- comprehensive.mjs - Advanced features
- multiple-products.mjs - Multiple products guide
For Express.js examples, see streamsdk-express
Express.js Integration
For Express.js applications, we provide a separate adapter package with declarative handlers for checkout and webhooks:
API Documentation
Available Resources and Operations
Consumers
- create - Create Consumer
- list - Get All Consumers
- get - Get Consumer
- update - Update Consumer
- delete - Delete Consumer
Coupons
- list - List Coupons
- create - Create Coupon
- update - Update Coupon
- get - Get Coupon
- delete - Delete Coupon
Invoices
PaymentLinks
Payments
Products
- list - List Products
- create - Create Product
- get - Get Product
- update - Update Product
- delete - Delete Product
Subscriptions
- get - Get Subscription
- update - Update Subscription
- list - List Subscriptions
- create - Create Subscription
- cancel - Cancel Subscription
- freeze - Freeze Subscription
- listFreezes - List Subscription Freezes
- updateFreeze - Update Subscription Freeze
Subscriptions.Freeze
- delete - Delete Subscription Freeze
Click on each resource above to see detailed documentation with code examples, parameters, and response types.
Error Handling
The SDK throws errors for failed requests:
try {
const consumer = await client.createConsumer({
name: "Ahmad Ali",
email: "invalid-email",
});
} catch (error) {
console.error("Error creating consumer:", error.message);
console.error("Status:", error.status);
console.error("Response:", error.response);
}Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
# Clone the repository
git clone https://github.com/streampayments/streamsdk-typescript.git
cd streamsdk-typescript
# Install dependencies
npm install
# Build the SDK
npm run build
# Run examples
npm run exampleSupport
Documentation
- API Documentation
- OpenAPI Specification
- Examples
- Express Adapter
- Multiple Products Guide
- Framework Support
Help & Issues
- 📧 Email: [email protected]
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
License
MIT License - see LICENSE for details.
