> ## Documentation Index
> Fetch the complete documentation index at: https://docs.enad.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Enad TypeScript SDK

A TypeScript SDK for interacting with the **Enad API**.\
Provides a clean, type-safe interface with all responses standardized to `[data, error]`.

***

## Installation

```bash theme={null}
pnpm add @enadhq/enad-ts-sdk
# or
npm install @enadhq/enad-ts-sdk
# or 
yarn add @enadhq/enad-ts-sdk
```

```typescript theme={null}
import { ShopperClient } from "@enadhq/enad-ts-sdk";

// Minimum configuration
export const client = new ShopperClient({
    apiKey: "api-key-123",
    appId: "app-id-UUID",
    groupId: "store-group-slug",
    defaultLocale: "en", // Optional. Recommended to add a defaultLocale
    defaultMarket: "us", // Optional. Recommended to add a defaultMarket
})

```

## Usage examples

1. Fetch a single product by SKU

```typescript theme={null}
const [product, error] = await client.products.getBySku("SKU123");

if (error) {
  console.error("Failed to fetch product:", res.error.message);
} else {
  console.log("Product id:", product.id);
}
```

2. Fetch multiple products by SKUs

```typescript theme={null}
const [skus, error] = await client.products.getBySkus(["SKU123", "SKU456"]);

if (error) {
  console.error("Failed to fetch products:", error.message);
} else {
  console.log("skus:", skus);
}
```

3. Get category by slug

```typescript theme={null}
const [result, error] = await client.categories.getBySlug("laptops", { per_page: 10, include_child_category_products: true});

if (error) {
  console.error("Failed to fetch category:", error.message);
} else {
  console.log("result:", result);
}
```

## Clients

There is clients available:

* `ShopperClient`: Deprecated. We will not add new features to the Shopper API; only bug fixes and security fixes will be made. Use [https://graphql.enad.io](https://graphql.enad.io) instead. See [Product search](/docs/product-search).
* `CustomerClient`: For customer specific operations like getting user details, whishlist etc.

```typescript theme={null}
import { ShopperClient } from "@enadhq/enad-ts-sdk";
import { CustomerClient } from "@enadhq/enad-ts-sdk";
```

## Modules

### ShopperClient

The SDK is organized into modules that group related functionality. Each module exposes methods for interacting with specific parts of the Enad API.

* `products`: Methods for fetching and searching products.
* `brands`: Methods for fetching brand information.
* `categories`: Methods for fetching product categories.
* `collections`: Methods for fetching product collections.
* `facets`: Methods for working with product facets.
* `redirects`: Methods for handling URL redirects.
* `series`: Methods for fetching product series.
* `tags`: Methods for fetching product tags.
* `variants`: Methods for fetching product variants.

### CustomerClient

* `user`: Methods for retrieving and managing user information.

## Response Format

All SDK methods return a standardized tuple-style response, making it simple and predictable to handle results:

```ts theme={null}
type ApiResponse<T> =
  | [data: T, error: null]
  | [data: null, error: ApiError];
```

This design allows for easy destructuring and explicit naming, for example:

```ts theme={null}
const [tags, error] = await client.tags.getAll();

if (error) {
  console.error("Failed to fetch product:", error.message);
  return;
}

console.log("Product:", data);
```

Because of the response contract:

* data is guaranteed to be defined if error is null.
* error is guaranteed to be defined if data is null.

This means you can safely use one or the other without additional null checks, and you don’t need try/catch blocks for simple error handling.
