0.1.0 • Published 5 months ago

@devdraft/sdk-node v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Devdraft SDK

Official Node.js SDK for the Devdraft API. This SDK provides a developer-friendly interface to interact with Devdraft's services, including payment links, invoices, customer management, and more.

Installation

npm install @devdraft/sdk-node
# or
yarn add @devdraft/sdk-node

Quick Start

import { DevdraftSDK } from '@devdraft/sdk-node';

const sdk = new DevdraftSDK({
  clientKey: 'your_client_key',
  clientSecret: 'your_client_secret',
  // Optional configurations
  baseUrl: 'https://api.devdraft.ai', // Default
  version: 'v0', // Default
  timeout: 30000, // Default: 30 seconds
});

// Create a payment link
const paymentLink = await sdk.paymentLinks.create({
  amount: 100,
  currency: 'usdc',
  customerId: 'cus_abc123',
});

// List invoices
const invoices = await sdk.invoices.list({
  skip: 0,
  take: 10,
});

// Create a webhook
const webhook = await sdk.webhooks.create({
  name: 'Payment Notifications',
  url: 'https://api.example.com/webhooks/payments',
  isActive: true,
  signing_secret: 'whsec_123456789',
  encrypted: false,
});

Features

  • 🔄 Auto-generated from OpenAPI spec
  • 📦 TypeScript support with full type definitions
  • 🔒 Automatic authentication handling
  • 🚀 Axios-based HTTP client
  • ⚡️ Promise-based API
  • 🛡️ Error handling with consistent error format
  • 📝 Comprehensive API documentation

Error Handling

The SDK provides consistent error handling across all API calls:

try {
  const paymentLink = await sdk.paymentLinks.create({
    amount: 100,
    currency: 'usdc',
  });
} catch (error) {
  console.error({
    statusCode: error.statusCode,
    message: error.message,
    error: error.error,
    details: error.details,
  });
}

Available Resources

  • sdk.paymentLinks - Payment link management
  • sdk.invoices - Invoice operations
  • sdk.customers - Customer management
  • sdk.webhooks - Webhook configuration

Configuration

The SDK accepts the following configuration options:

interface DevdraftSDKConfig {
  clientKey: string;      // Required: Your API client key
  clientSecret: string;   // Required: Your API client secret
  baseUrl?: string;       // Optional: API base URL
  version?: string;       // Optional: API version
  timeout?: number;       // Optional: Request timeout in milliseconds
}

Publishing

To publish a new version of the SDK:

  1. Update the version in package.json:

    npm version patch  # for bug fixes
    npm version minor  # for new features
    npm version major  # for breaking changes
  2. Build the package:

    npm run build
  3. Publish to npm:

    npm publish
  4. Create a git tag and push:

    git tag v<version>
    git push origin v<version>

License

MIT

0.1.0

5 months ago

0.2.0

5 months ago