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

kiotviet-fnb-sdk

v1.1.0

Published

TypeScript SDK for KiotViet FNB API with full type support and real-time webhook capabilities

Readme

KiotViet FNB SDK

TypeScript/JavaScript SDK for KiotViet FNB API with real-time webhook support.

Installation

npm install kiotviet-fnb-sdk

Quick Start

import { KiotVietClient } from 'kiotviet-fnb-sdk';

const client = new KiotVietClient({
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  retailer: 'your-store-name'
});

API Documentation

Categories

// List categories
const categories = await client.categories.list({
  pageSize: 20,               // Default: 20, max: 100
  hierarchicalData: true,     // Get nested structure
  orderBy: 'name',           // Sort field
  orderDirection: 'Asc'      // Sort direction: 'Asc' or 'Desc'
});

// Get by ID
const category = await client.categories.get(123);

Products

// List products
const products = await client.products.list({
  pageSize: 20,
  includeInventory: true,     // Include stock info
  includePricebook: true,     // Include price book info
  masterUnitId: 123,         // Filter by master unit
  categoryId: 456            // Filter by category
});

// Get by ID
const product = await client.products.get(123);

// Get by code
const product = await client.products.getByCode('PRD001');

// Get by category
const products = await client.products.getByCategory(456);

// Get by master unit
const products = await client.products.getByMasterUnit(789);

Orders

// Create order
const orderId = await client.orders.create({
  branchId: 1,
  customerId: 123,
  orderDetails: [{
    productId: 456,
    quantity: 2,
    price: 100000,
    note: 'Extra spicy',
    rank: 1
  }],
  deliveryDetail: {
    receiver: 'John Doe',
    contactNumber: '0123456789',
    address: '123 Street',
    locationName: 'District 1',
    wardName: 'Ward 1',
    price: 15000,
    status: 3             // 3: Not delivered, 4: Delivering
  }
});

// Get order by UUID
const order = await client.orders.getByUuid(orderId);

Customers

// Create customer
const customer = await client.customers.create({
  code: 'CUST001',
  name: 'John Doe',
  contactNumber: '0123456789',
  email: '[email protected]',
  address: '123 Street'
});

// Update customer
await client.customers.update(customer.id, {
  name: 'John Smith',
  contactNumber: '0123456789'
});

// Get by ID
const customer = await client.customers.get(123);

// Get by code
const customer = await client.customers.getByCode('CUST001');

// List customers
const customers = await client.customers.list({
  pageSize: 20,
  includeTotal: true,       // Include invoices/points total
  orderBy: 'name'
});

// Search customers
const searchResults = await client.customers.search('John');

// Delete customer
await client.customers.delete(123);

Branches

// List all branches
const branches = await client.branches.list({
  pageSize: 20,
  orderBy: 'branchName',
  orderDirection: 'Asc'
});

// Get all branches (without pagination)
const allBranches = await client.branches.getAll();

// Get by ID
const branch = await client.branches.get(1);

// Get by retailer ID
const retailerBranches = await client.branches.getByRetailer(123);

Invoices

// List invoices
const invoices = await client.invoices.list({
  pageSize: 20,
  includePayment: true,
  includeInvoiceDelivery: true,
  branchIds: [1, 2],
  customerIds: [123],
  status: [1, 2],
  SaleChannel: true        // Include sale channel info
});

// Get by ID
const invoice = await client.invoices.get(123);

// Get by code
const invoice = await client.invoices.getByCode('INV001');

// Get by branches
const branchInvoices = await client.invoices.getByBranches([1, 2]);

// Get by customers
const customerInvoices = await client.invoices.getByCustomers([123]);

// Get by customer code
const invoices = await client.invoices.getByCustomerCode('CUST001');

// Get by status
const statusInvoices = await client.invoices.getByStatus([1, 2]);

// Get by order ID
const orderInvoices = await client.invoices.getByOrderId(456);

// Get by date range
const dateInvoices = await client.invoices.getByDateRange(
  '2024-01-01',
  '2024-12-31'
);

Webhooks & Real-time Updates

// Register webhook endpoint
await client.webhooks.register({
  Type: 'product.update',
  Url: 'https://your-webhook.com/endpoint',
  IsActive: true
});

// Connect WebSocket for real-time updates
await client.connectWebSocket({
  onProductUpdate: (products) => {
    console.log('Products updated:', products);
  },
  onCustomerUpdate: (customers) => {
    console.log('Customers updated:', customers);
  },
  onStockUpdate: (stocks) => {
    console.log('Stock levels updated:', stocks);
  },
  onError: (error) => {
    console.error('WebSocket error:', error);
  }
});

// Disconnect WebSocket
client.disconnectWebSocket();

Configuration

interface KiotVietClientConfig {
  // Required
  clientId: string;
  clientSecret: string;
  retailer: string;

  // Optional
  storageType?: 'file' | 'memory';  // Default: 'file'
  websocket?: {
    autoReconnect?: boolean;        // Default: true
    reconnectInterval?: number;     // Default: 5000ms
    maxReconnectAttempts?: number;  // Default: 5
  }
}

Storage Types

  • file: Stores tokens securely in the filesystem (default)
  • memory: Stores tokens in memory (cleared on process restart)

License

MIT