Linkit
SDK Reference

TypeScript SDK

Type-safe TypeScript SDK for the Linkit API — works in Node.js, Deno, and Bun with native fetch, full type inference, and npm distribution.

TypeScript SDK

Package

@linkit/sdk · TypeScript 5+ · Native fetch · Zero dependencies · npm / Bun


Installation

npm install @linkit/sdk
bun add @linkit/sdk
pnpm add @linkit/sdk
yarn add @linkit/sdk

Quick Start

Initialize the Client

import { LinkitClient } from "@linkit/sdk";

const client = LinkitClient.quickSetup("https://linkit.works/api/v1", "your-jwt-token");

Create a SKU with the Fluent Builder

import { SkuCreateBuilder } from "@linkit/sdk";

const sku = await client.skus.create(
  new SkuCreateBuilder()
    .withIvId("SKU-001")
    .inBranch("BR-RYD")
    .forProduct("PROD-001")
    .withPrice(29.99)
    .withQty(500)
    .build()
);

List Products with Filtering

const products = await client.products.list({
  page: 1,
  limit: 25,
  enabled: true,
  search: "widget",
});

for (const product of products.data) {
  console.log(`${product.nameEn} — ${product.averagePrice}`);
}

Dispose

client.dispose();

Configuration

const client = LinkitClient.create({
  baseUrl: "https://linkit.works/api/v1",
  jwtToken: "your-jwt-token",
  timeoutMs: 30_000,
  maxRetries: 3,
  retryBaseDelayMs: 1_000,
  retryMaxDelayMs: 30_000,
  circuitBreakerThreshold: 5,
  circuitBreakerRecoveryMs: 60_000,
  maxConcurrentRequests: 10,
});

Services Reference

ServiceMethodsDescription
client.skuscreate(), getById(), update(), updateStock(), deleteById(), list()Per-branch inventory
client.productscreate(), getById(), update(), deleteById(), list()Product catalog
client.branchescreate(), getById(), update(), deleteById(), list()Physical locations
client.customerscreate(), getById(), update(), deleteById(), list(), createAddress(), createGroup()Customer profiles
client.ordersgetById()Order retrieval
client.brandscreate(), getById(), update(), deleteById()Brand management
client.categoriescreate(), getById(), update(), deleteById()Product categories
client.genericscreate(), getById(), update(), deleteById()Generic entities
client.healthcheck(), ping()System health
client.integrationsgetById(), execute(), enable(), disable()Platform connections

Builders

SkuCreateBuilder

const request = new SkuCreateBuilder()
  .withIvId("SKU-001")
  .inBranch("BR-RYD")
  .forProduct("PROD-001")
  .withBarcode("5901234123457")
  .withPrice(29.99)
  .withQty(500)
  .withAvailable(true)
  .withAmazonSku("AMZ-W001")
  .withNoonNsku("NOON-W001")
  .build(); // throws LinkitValidationError on invalid input

ProductCreateBuilder

const request = new ProductCreateBuilder()
  .withIvId("PROD-001")
  .withNameEn("Premium Widget")
  .withNameAr("ودجت فاخر")
  .withAveragePrice(149.99)
  .withEnabled(true)
  .withBuffer(15)
  .build();

BranchCreateBuilder

const request = new BranchCreateBuilder()
  .withIvId("BR-RYD")
  .withNameEn("Riyadh Main Store")
  .withLocation(24.7136, 46.6753)
  .withStatus("Published")
  .build();

Error Handling

try {
  const sku = await client.skus.getById("nonexistent");
} catch (error) {
  if (error instanceof LinkitNotFoundError) {
    console.log(`Not found: ${error.resourceType}`);
  } else if (error instanceof LinkitRateLimitError) {
    console.log(`Rate limited — retry after ${error.retryAfterMs}ms`);
  } else if (error instanceof LinkitValidationError) {
    for (const ve of error.validationErrors) {
      console.log(`  ${ve.field}: ${ve.message}`);
    }
  } else if (error instanceof LinkitApiError) {
    console.log(`API error ${error.statusCode}: ${error.userFriendlyMessage}`);
  }
}

Exception Hierarchy

Error ClassStatusDescription
LinkitErrorBase error
LinkitInitializationErrorBad configuration
LinkitApiErrorAnyAPI error response
LinkitAuthenticationError401Invalid credentials
LinkitAuthorizationError403Insufficient permissions
LinkitNotFoundError404Resource not found
LinkitValidationError400Validation failed
LinkitConflictError409State conflict
LinkitRateLimitError429Too many requests
LinkitServerError5xxServer error
LinkitSerializationErrorJSON parse failure

Runtime Compatibility

Node.js 18+

Uses native fetch — no polyfill needed on Node 18+.

Deno

Import directly from npm — @linkit/sdk works out of the box.

Bun

Native fetch support. Install with bun add @linkit/sdk.

Browsers

Tree-shakeable ESM bundle. Use with Vite, Webpack, or esbuild.