npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sdkwork-commons-typescript

v1.0.8

Published

Common TypeScript library for SDK work

Readme

SDKWORK TypeScript Commons

A comprehensive TypeScript library for building SDKs with common utilities and base classes.

Overview

This library provides a foundation for building consistent and robust SDKs in TypeScript. It includes base classes, HTTP utilities, type definitions, and examples to help you quickly create your own SDKs.

Features

  • Base SDK Classes: Foundation classes for building consistent SDKs
  • HTTP Client: Configurable HTTP client with retry logic and middleware support
  • Type Safety: Comprehensive TypeScript type definitions
  • Extensible Design: Hook system for customizing request behavior
  • Promise Wrapper: Enhanced promise handling with additional utility methods

Project Structure

src/
├── core/              # Core SDK classes
│   ├── BaseSdkApi.ts  # Base API class
│   └── index.ts       # Core module exports
├── http/              # HTTP-related functionality
│   ├── BaseSdkClient.ts  # Base SDK client with HTTP methods
│   ├── HttpTool.ts       # HTTP utility functions
│   └── index.ts          # HTTP module exports
├── types/             # Type definitions
│   └── index.ts       # All type definitions
├── examples/          # Example implementations
│   ├── ExampleApi.ts  # Example API implementation
│   ├── enhanced-usage-example.ts  # Enhanced usage examples
│   ├── usage-example.ts           # Basic usage examples
│   └── index.ts       # Examples module exports
└── index.ts           # Main entry point

Installation

npm install

Building

npm run build

This will compile the TypeScript code into JavaScript in the dist/ directory.

Usage

Basic Client Setup

import { BaseSdkClient } from 'sdkwork-typescript-commons';

const client = new BaseSdkClient({
  baseUrl: 'https://api.example.com',
  apiKey: 'your-api-key',
  timeout: 5000
});

Making Requests

The client provides convenient methods for all HTTP verbs:

// GET request
const users = await client.get('/users');

// POST request
const newUser = await client.post('/users', {
  body: JSON.stringify({ name: 'John Doe' })
});

// PUT request
const updatedUser = await client.put('/users/1', {
  body: JSON.stringify({ name: 'Jane Doe' })
});

// DELETE request
await client.delete('/users/1');

Advanced Usage with Hooks

Extend the BaseSdkClient to add custom behavior:

class CustomSdkClient extends BaseSdkClient {
  protected async prepareOptions(options) {
    // Add custom headers
    options.headers = {
      ...options.headers,
      'X-Custom-Header': 'custom-value'
    };
  }

  protected async prepareRequest(request, { url, options }) {
    // Log requests
    console.log(`Making ${options.method} request to ${url}`);
  }
}

API

BaseSdkClient

The main client class with the following methods:

  • get(path, opts?) - Make a GET request
  • post(path, opts?) - Make a POST request
  • put(path, opts?) - Make a PUT request
  • patch(path, opts?) - Make a PATCH request
  • delete(path, opts?) - Make a DELETE request
  • request(options, remainingRetries?) - Generic request method
  • sendRequest(requestOptions) - Send a request with full options

Hooks

  • prepareOptions(options) - Called before each request to modify options
  • prepareRequest(request, { url, options }) - Called before each request to modify the RequestInit object

Types

The library provides comprehensive type definitions:

  • SdkClientOptions - Client configuration options
  • SdkRequestOptions - Request configuration options
  • SdkResponse<T> - Response structure
  • HTTPMethod - Type for HTTP methods
  • FinalRequestOptions - Internal request options
  • APIPromise<T> - Enhanced promise with additional methods

Examples

See the examples directory for detailed usage examples:

  1. Basic Usage
  2. Enhanced Usage with Hooks
  3. Custom API Implementation

Development

Prerequisites

  • Node.js (v12 or higher)
  • npm or yarn

Setup

  1. Clone the repository
  2. Install dependencies:
    npm install

Building

npm run build

Publishing

To publish the package to npm registry, use the following command:

npm publish --registry=https://registry.npmjs.org/

This ensures the package is published to the official npm registry, even if you have configured a different default registry.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

License

MIT