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

@flinkk/inventory-api

v1.0.2

Published

Lightweight TypeScript wrapper for Flinkk's external inventory service

Readme

📦 Flinkk Inventory Library

A lightweight and modular TypeScript wrapper for interacting with Flinkk's external inventory service. This library enables client modules (like Admin Center) to securely configure and communicate with inventory endpoints by passing configuration directly at runtime — no environment variables are used.

🎯 Features

  • 🔗 Centralized SDK: Consistent API layer for inventory service operations
  • 🔐 Explicit Auth: Runtime configuration with no reliance on environment variables
  • ⚙️ Configurable: Caller must pass both apiUrl and token explicitly when instantiating
  • 🔁 Extensible: Designed for future support of inventory operations like stock updates, product sync
  • 📝 Type-Safe: Full TypeScript support with comprehensive type definitions
  • 🛡️ Robust Error Handling: Descriptive error messages and graceful failure handling

📦 Installation

Since this is an internal library, import it directly from the libs directory:

import { FlinkkInventoryAPI } from "@flinkk/inventory-api";

🚀 Quick Start

Basic Usage

import { FlinkkInventoryAPI } from "@flinkk/inventory-api";

// Create an instance with explicit configuration
const api = new FlinkkInventoryAPI({
  apiUrl: "https://inventory.example.com",
  token: "your-access-token",
});

// Verify the connection
try {
  const result = await api.verifyConnection();
} catch (error) {
  console.error("Connection failed:", error.message);
}

Using the Factory Function

import { createFlinkkInventoryAPI } from "@flinkk/inventory-api";

const api = createFlinkkInventoryAPI({
  apiUrl: "https://inventory.myapp.com",
  token: "abc123",
});

await api.verifyConnection();

📚 API Reference

Constructor

new FlinkkInventoryAPI(config)

Creates a new instance of the Flinkk Inventory API client.

Parameters:

  • config (FlinkkInventoryAPIConfig): Configuration object
    • apiUrl (string, required): Base URL of the inventory service
    • token (string, required): Authentication token

Throws:

  • Error if apiUrl is not provided
  • Error if token is not provided

Methods

verifyConnection(): Promise<VerifyConnectionResponse>

Verifies the connection to the inventory service by making a GET request to /api/inventory/verify.

Returns:

  • Promise<VerifyConnectionResponse>: Connection status and details

Example:

const result = await api.verifyConnection();
// {
//   status: "connected",
//   message: "Connection verified successfully",
//   timestamp: "2024-01-15T10:30:00Z",
//   version: "1.2.3"
// }

🔧 Configuration

FlinkkInventoryAPIConfig

interface FlinkkInventoryAPIConfig {
  apiUrl: string; // Base URL of the inventory service
  token: string; // Authentication token
}

Response Types

APIResponse

interface APIResponse<T = any> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
}

VerifyConnectionResponse

interface VerifyConnectionResponse {
  status: "connected" | "disconnected";
  message: string;
  timestamp: string;
  version?: string;
}

🧪 Usage Examples

In React Components

import { useState, useEffect } from 'react';
import { FlinkkInventoryAPI } from '@flinkk/inventory-api';

function InventorySettings() {
  const [connectionStatus, setConnectionStatus] = useState<string>('checking');

  useEffect(() => {
    const checkConnection = async () => {
      try {
        const api = new FlinkkInventoryAPI({
          apiUrl: formData.inventoryUrl,
          token: formData.apiToken
        });

        const result = await api.verifyConnection();
        setConnectionStatus(result.status);
      } catch (error) {
        setConnectionStatus('error');
        console.error('Connection check failed:', error);
      }
    };

    checkConnection();
  }, [formData]);

  return (
    <div>
      <p>Connection Status: {connectionStatus}</p>
    </div>
  );
}

In Server-Side Functions

import { FlinkkInventoryAPI } from "@flinkk/inventory-api";

export async function validateInventoryConfig(apiUrl: string, token: string) {
  const api = new FlinkkInventoryAPI({ apiUrl, token });

  try {
    const result = await api.verifyConnection();
    return { valid: true, details: result };
  } catch (error) {
    return { valid: false, error: error.message };
  }
}

With React Query

import { useQuery } from "@tanstack/react-query";
import { FlinkkInventoryAPI } from "@flinkk/inventory-api";

function useInventoryConnection(apiUrl: string, token: string) {
  return useQuery({
    queryKey: ["inventory-connection", apiUrl, token],
    queryFn: async () => {
      const api = new FlinkkInventoryAPI({ apiUrl, token });
      return api.verifyConnection();
    },
    enabled: !!(apiUrl && token),
    retry: 2,
  });
}

🚨 Error Handling

The library provides descriptive error messages for common scenarios:

try {
  const api = new FlinkkInventoryAPI({
    apiUrl: "", // Empty URL
    token: "valid-token",
  });
} catch (error) {
  console.error(error.message); // "FlinkkInventoryAPI: apiUrl is required"
}

try {
  const api = new FlinkkInventoryAPI({
    apiUrl: "https://api.example.com",
    token: "invalid-token",
  });
  await api.verifyConnection();
} catch (error) {
  console.error(error.message); // "Inventory API error: 401 Unauthorized - Invalid token"
}

🔮 Future Enhancements

The library is designed to be extensible. Planned future methods include:

  • syncStock(stockData) - Push stock levels per SKU
  • getAvailability(productIds) - Pull availability by product/service
  • listProducts() - Get product catalog
  • bulkUpdateInventory() - Batch inventory updates

🧪 Testing

To test the library in your application:

  1. Unit Tests: Test instantiation and error handling
  2. Integration Tests: Test with actual inventory service endpoints
  3. Mock Tests: Use with React Query or other data fetching libraries

Example test:

describe("FlinkkInventoryAPI", () => {
  it("should throw error when apiUrl is missing", () => {
    expect(() => {
      new FlinkkInventoryAPI({ apiUrl: "", token: "test" });
    }).toThrow("FlinkkInventoryAPI: apiUrl is required");
  });
});

📄 License

Internal Flinkk library - ISC License