Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Enad TypeScript SDK

The @enadhq/enad-ts-sdk TypeScript SDK: a typed GraphQL client for product search, plus clients for the Customers API and the Shopper API.

A TypeScript SDK for interacting with the Enad APIs.

The package has two entry points:

Import What it gives you
@enadhq/enad-ts-sdk/search createSearchClient(): a typed client for the Product Search GraphQL API at https://graphql.enad.io. Use this for product listings, product detail pages, facets, categories, collections, and autocomplete.
@enadhq/enad-ts-sdk CustomerClient for the Customers API, and the deprecated ShopperClient for the Shopper API.

Installation

pnpm add @enadhq/enad-ts-sdk
# or
npm install @enadhq/enad-ts-sdk
# or
yarn add @enadhq/enad-ts-sdk

Search client (GraphQL)

createSearchClient() calls the Product Search GraphQL API. Every request and response is typed from the GraphQL schema, so you get autocompletion on variables and result fields without writing your own types.

import { createSearchClient } from "@enadhq/enad-ts-sdk/search";

export const search = createSearchClient({
  appId: "app-id-UUID",
  marketSlug: "us",
  storeGroupSlug: "store-group-slug",
  locale: "en",
});

The client sends requests to https://graphql.enad.io/{appId}/graphql. marketSlug, storeGroupSlug, and locale are added to every request, so you don’t pass them per call. To override them for a single call, pass them in the second argument.

Option Required Description
appId Yes Your application (tenant) ID.
marketSlug Yes Default market for all requests.
storeGroupSlug Yes Default store group for all requests.
locale Yes Default locale for all requests.
baseUrl No Overrides https://graphql.enad.io/{appId}.
headers No Extra headers, or a function (sync or async) that returns them per request.
fetch No Custom fetch implementation. Defaults to globalThis.fetch.

Usage examples

  1. Product listing (PLP, search results)
const { products, pageInfo } = await search.searchProducts({
  page: 1,
  perPage: 24,
  search: "chair",
});
  1. Product detail page by slug or SKU
const product = await search.getProductBySlug({ slug: "oak-chair" });
const bySku = await search.getProductBySku({ sku: "OAK-CHAIR-1" });

// Include related products (all relation types)
const withRelated = await search.getProductBySlug({
  slug: "oak-chair",
  includeRelatedProducts: true,
});

Both return null when no product matches.

  1. Override the market for a single request
const result = await search.searchProducts(
  { page: 1, perPage: 24 },
  { marketSlug: "se", locale: "sv" },
);

Methods

Method Use it for
searchProducts / searchProductCards Product lists with page, perPage, search, filter, sortBy, and warehouseSlug. searchProductCards returns a lighter selection for grids.
getProductBySlug / getProductBySku A single product when you already know its slug or SKU.
searchFacets Facet counts for filters (brands, categories, price range, stock, series, tags, attributes).
searchCategories, getCategoryById, getCategoryByUri, getCategoryByFullUri Categories.
searchCollections, getCollectionById, getCollectionByUri Collections.
searchBrands, searchSeries, searchVariants, searchRedirects Brands, series, variants, and redirects.
searchCompletions Autocomplete suggestions.
getProductSlugs All product slugs, for example to generate static pages.

Your own queries

The SDK also exports the GraphQL documents it uses (for example SearchProductsDocument) together with their variable and result types. Pass a document to executeWithContext to run it with the client’s market, store group, and locale, or to execute to pass every variable yourself. The result is typed from the document.

import { SearchProductsDocument } from "@enadhq/enad-ts-sdk/search";

const data = await search.executeWithContext(SearchProductsDocument, {
  page: 1,
  perPage: 12,
});
// data.v1Products.products is fully typed

The full schema, with every query, type, and field, is in the Product Search API reference.

Error handling

The search client throws a SearchClientError when a request fails. It does not return [data, error] tuples. error.code is one of HTTP_ERROR, GRAPHQL_ERROR, INVALID_JSON, MISSING_DATA, or CONFIG_ERROR.

import { SearchClientError } from "@enadhq/enad-ts-sdk/search";

try {
  const { products } = await search.searchProducts({ page: 1, perPage: 24 });
} catch (error) {
  if (error instanceof SearchClientError) {
    console.error(error.code, error.status, error.message);
  }
  throw error;
}

Customers API client

CustomerClient calls the Customers API at https://customers.enad.io/api/v1/.

import { CustomerClient } from "@enadhq/enad-ts-sdk";

export const customers = new CustomerClient({
  apiKey: "api-key-123",
  appId: "app-id-UUID",
  groupId: "store-group-slug",
});

Modules:

  • user: Retrieve and manage user information.
  • wishlist: Create, list, update, and share wishlists.
  • cart: List and save carts.
  • organisation: Organisations and their users.
  • attributes: Customer attributes.
  • customerGroups: Customer groups and their prices.

Shopper API client (deprecated)

import { ShopperClient } from "@enadhq/enad-ts-sdk";

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

const [product, error] = await client.products.getBySku("SKU123");

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

EnadClient is an alias of ShopperClient, kept for backwards compatibility.

Modules: products, brands, categories, collections, facets, redirects, series, tags, and variants.

Response format

CustomerClient and ShopperClient methods return a standardized tuple-style response:

type ApiResponse<T> =
  | [data: T, error: null]
  | [data: null, error: ApiError];

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

const [wishlists, error] = await customers.wishlist.listWishlists(authToken);

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

console.log("Wishlists:", wishlists);

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.