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

ns-inventory-api-types

v1.0.80

Published

Types-only package that re-exports the Hono AppType for RPC clients.

Readme

@ns-inventory/api-types

TypeScript types for NS Inventory Management API, auto-generated from the Hono server's AppType.

Installation

npm install @ns-inventory/api-types hono

Usage

Basic Setup with Hono RPC Client

import { hc } from 'hono/client';
import type { AppType } from '@ns-inventory/api-types';

// Create a typed client
const client = hc<AppType>('http://localhost:3000');

// Now you have full type safety!
const response = await client.api.auth['product-stock'].all.$get();
const data = await response.json(); // Fully typed response

Available Types

import type {
  AppType,
  ApiResponse,
  ProductStock,
  ProductStockWithEmployee,
  Employee,
  WithdrawOrder,
  WithdrawOrderDetails,
  CreateWithdrawOrderRequest,
  UpdateWithdrawOrderRequest,
} from '@ns-inventory/api-types';

Example Usage

Fetching Product Stock

const fetchProductStock = async () => {
  const response = await client.api.auth['product-stock'].all.$get();
  const data: ApiResponse<ProductStock[]> = await response.json();
  
  if (data.success) {
    return data.data; // ProductStock[]
  }
  throw new Error(data.message);
};

Fetching Product Stock with Employee

const fetchProductStockWithEmployee = async () => {
  const response = await client.api.auth['product-stock']['with-employee'].$get();
  const data: ApiResponse<ProductStockWithEmployee[]> = await response.json();
  
  return data.data?.map(item => ({
    productStock: item.product_stock,
    employee: item.employee
  })) || [];
};

Creating a Withdraw Order

const createWithdrawOrder = async (orderData: CreateWithdrawOrderRequest) => {
  const response = await client.api.auth['withdraw-orders'].create.$post({
    json: orderData
  });
  
  const data: ApiResponse<WithdrawOrder> = await response.json();
  
  if (!data.success) {
    throw new Error(data.message);
  }
  
  return data.data;
};

// Usage
const newOrder = await createWithdrawOrder({
  dateWithdraw: '2024-12-20',
  userId: 'user-123',
  numItems: 3,
  isComplete: false
});

Querying with Parameters

const fetchEmployee = async (userId: string) => {
  const response = await client.api.auth.employee.all.$get({
    query: { userId }
  });
  
  const data: ApiResponse<EmployeeWithPermissions[]> = await response.json();
  return data.data;
};

Error Handling

const safeApiCall = async () => {
  try {
    const response = await client.api.auth['product-stock'].all.$get();
    const data = await response.json();
    
    if (!data.success) {
      console.error('API Error:', data.message);
      return null;
    }
    
    return data.data;
  } catch (error) {
    console.error('Network Error:', error);
    return null;
  }
};

With React/Next.js

import { useState, useEffect } from 'react';
import { hc } from 'hono/client';
import type { AppType, ProductStock } from '@ns-inventory/api-types';

const client = hc<AppType>(process.env.NEXT_PUBLIC_API_URL!);

export function useProductStock() {
  const [products, setProducts] = useState<ProductStock[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const fetchProducts = async () => {
      try {
        const response = await client.api.auth['product-stock'].all.$get();
        const data = await response.json();
        
        if (data.success) {
          setProducts(data.data || []);
        } else {
          setError(data.message || 'Failed to fetch products');
        }
      } catch (err) {
        setError('Network error');
      } finally {
        setLoading(false);
      }
    };

    fetchProducts();
  }, []);

  return { products, loading, error };
}

Features

  • Full Type Safety: Every API endpoint is fully typed
  • Auto-generated: Types are automatically extracted from your Hono server
  • IntelliSense: Complete autocompletion in your IDE
  • Request/Response Types: Input and output types for all endpoints
  • Error Handling: Typed error responses
  • Zod Schemas: Validation schemas for client-side validation

Development

This package is automatically generated from the NS Inventory API server. When new routes are added to the server, run:

npm run publish:types

This will automatically:

  1. Extract the latest AppType
  2. Build the types package
  3. Increment the version
  4. Publish to npm

License

MIT