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/sdkbun add @linkit/sdkpnpm add @linkit/sdkyarn add @linkit/sdkQuick 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
| Service | Methods | Description |
|---|---|---|
client.skus | create(), getById(), update(), updateStock(), deleteById(), list() | Per-branch inventory |
client.products | create(), getById(), update(), deleteById(), list() | Product catalog |
client.branches | create(), getById(), update(), deleteById(), list() | Physical locations |
client.customers | create(), getById(), update(), deleteById(), list(), createAddress(), createGroup() | Customer profiles |
client.orders | getById() | Order retrieval |
client.brands | create(), getById(), update(), deleteById() | Brand management |
client.categories | create(), getById(), update(), deleteById() | Product categories |
client.generics | create(), getById(), update(), deleteById() | Generic entities |
client.health | check(), ping() | System health |
client.integrations | getById(), 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 inputProductCreateBuilder
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 Class | Status | Description |
|---|---|---|
LinkitError | — | Base error |
LinkitInitializationError | — | Bad configuration |
LinkitApiError | Any | API error response |
LinkitAuthenticationError | 401 | Invalid credentials |
LinkitAuthorizationError | 403 | Insufficient permissions |
LinkitNotFoundError | 404 | Resource not found |
LinkitValidationError | 400 | Validation failed |
LinkitConflictError | 409 | State conflict |
LinkitRateLimitError | 429 | Too many requests |
LinkitServerError | 5xx | Server error |
LinkitSerializationError | — | JSON 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.