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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@eldev/business-central-api

v0.5.1

Published

A Dynamics 365 Business Central client for TypeScript

Downloads

238

Readme

Business Central - TS

A modern TypeScript library built for Node.js 24+, Bun, and Deno with Zod integration.

Features

  • 🚀 Modern TypeScript: Uses latest TypeScript features targeting Node.js 24+
  • 🔄 Universal Runtime: Works on Node.js, Bun, and Deno using native fetch
  • Runtime Validation: Powered by Zod for schema validation
  • 🛡️ Type Safety: Full TypeScript support with strict type checking
  • 🔧 Error Handling: Comprehensive error handling with proper error chaining
  • 🧪 Native Testing: Uses Node.js built-in test runner
  • 📦 ESM Only: Modern ES modules with proper exports

Installation

npm install bc-ts
# Peer dependency
npm install zod@^4.0.0

Usage

import { ApiClient, ConfigSchema } from 'your-library-name';
import * as z from 'zod';

// Create and validate configuration
const config = {
  baseUrl: 'https://api.example.com',
  timeout: 5000,
  retries: 2,
};

const client = new ApiClient(config);

// Make requests with proper error handling
const result = await client.get<{ message: string }>('/hello');

if (result.success) {
  console.log(result.data.message);
} else {
  console.error('Request failed:', result.error.message);
  console.error('Error code:', result.error.code);
}

API Reference

ApiClient

Main client class for making HTTP requests.

Constructor

new ApiClient(config: Partial<Config>)

Methods

  • get<T>(endpoint: string): Promise<Result<T>> - GET request
  • post<T>(endpoint: string, data: unknown): Promise<Result<T>> - POST request
  • request<T>(endpoint: string, options?: RequestInit): Promise<Result<T>> - Custom request

Error Handling

The library uses a Result<T, E> pattern for consistent error handling:

type Result<T, E = LibraryError> =
  | { success: true; data: T }
  | { success: false; error: E };

All errors are wrapped in LibraryError which includes:

  • message: Human-readable error description
  • code: Machine-readable error code
  • cause: Original error that caused this error (for error chaining)

Development

Scripts

# Build the library
npm run build

# Run tests
npm run test

# Run tests in watch mode
npm run test:watch

# Development with hot reload
npm run dev

# Lint code
npm run lint
npm run lint:fix

# Type check without emitting
npm run type-check

Requirements

  • Node.js 24+ (for development and runtime)
  • TypeScript 5.6+
  • Zod 4.x (peer dependency)

Architecture Decisions

Error Handling Strategy

The library implements a comprehensive error handling strategy:

  1. Custom Error Classes: LibraryError extends the native Error class with additional context (code, cause)
  2. Error Chaining: Original errors are preserved in the cause property for full traceability
  3. Result Pattern: Uses discriminated unions (Result<T, E>) to force explicit error handling
  4. Retry Logic: Implements exponential backoff with configurable retry limits
  5. Error Classification: Different error codes help identify the error source and appropriate handling

Runtime Validation

Uses Zod for runtime validation because:

  1. Type Safety: Ensures runtime data matches TypeScript types
  2. Clear Error Messages: Provides detailed validation error messages
  3. Schema Evolution: Easy to extend and modify validation rules
  4. Documentation: Schemas serve as living documentation

Universal Runtime Support

The library uses native fetch which is available in:

  • Node.js 18+ (experimental) and 21+ (stable)
  • Bun (native support)
  • Deno (native support)

This eliminates the need for polyfills while maintaining broad compatibility.

License

MIT