TypeScript SDK (@xclade/sdk)
Zero-dependency pure GraphQL TypeScript SDK v2 for Storefront (/graphql) and Merchant Admin (/admin/graphql)
@xclade/sdk (v2.0)
@xclade/sdk is xclade's official, zero-dependency pure GraphQL TypeScript SDK. It ships both ESM and CJS builds and covers both GraphQL surfaces:
sdk.store.*&sdk.client.queryStore(...)→ Storefront & B2B Buyer GraphQL (POST /graphql)sdk.graphql.*,sdk.auth.*,sdk.admin.*&sdk.client.queryAdmin(...)→ Merchant Admin GraphQL (POST /admin/graphql)
Installation
pnpm add @xclade/sdk
# or
npm install @xclade/sdkStorefront & B2B Setup
import { createXcladeSDK } from '@xclade/sdk';
export const xclade = createXcladeSDK({
baseUrl: process.env.NEXT_PUBLIC_XCLADE_API_URL!, // https://{shortId}.api.myxclade.com
publishableKey: process.env.NEXT_PUBLIC_XCLADE_PUBLISHABLE_KEY!, // pk_live_...
});Catalog & Contextual Pricing
// List products with USD contextual pricing
const { products, count } = await xclade.store.listProducts({
limit: 20,
offset: 0,
currency_code: 'usd',
});
// Fetch product by URL handle
const product = await xclade.store.getProduct({
handle: 'apex-pro-kit',
currency_code: 'usd',
});
// Search variants directly by SKU (great for B2B quick-order matrices)
const variants = await xclade.store.listProductVariants({
q: 'SKU-100',
pricing_context: { currency_code: 'usd' },
});Cart, Promotions & Checkout
const cart = await xclade.store.createCart({
region_id: 'reg_01...',
email: 'buyer@company.com',
});
await xclade.store.addCartLineItems(cart.id, [
{ variant_id: 'variant_01...', quantity: 2 },
]);
await xclade.store.addCartPromotions(cart.id, 'SAVE15');
const options = await xclade.store.listShippingOptions(cart.id);
await xclade.store.addCartShippingMethod(cart.id, options.shipping_options[0].id);
const collection = await xclade.store.createPaymentCollection(cart.id);
await xclade.store.initializePaymentSession(collection.id, 'pp_stripe_stripe');
const order = await xclade.store.completeCart(cart.id);Customer Auth & B2B Wholesale
// Email + password login (stores customer JWT automatically in browser storage)
const auth = await xclade.store.customerLogin('buyer@company.com', 'secret');
const me = await xclade.store.customerMe();
// B2B Company, Employees, Quotes & Approvals
const company = await xclade.store.myCompany();
const quote = await xclade.store.requestQuote(cart.id);
await xclade.store.createQuoteMessage({
quote_id: quote.id,
text: 'Can we lock Net-30 pricing on 50 units?',
});
await xclade.store.acceptQuote(quote.id);
// Submit cart for Company Admin / Sales Manager sign-off
await xclade.store.createCartApprovals(cart.id);
await xclade.store.updateApproval('appr_01...', 'approved');Raw Storefront GraphQL
Need custom field selection or fragments? Execute raw GraphQL directly through the same authenticated client:
const data = await xclade.store.query<{ siteSettings: { store_name: string } }>(
`query SiteHeader {
siteSettings {
store_name
navigation_menus { id name items { label url } }
}
}`,
);Merchant Admin Setup
import XcladeSDK, { getStoredAdminJwt, setStoredAdminJwt } from '@xclade/sdk';
export const adminSdk = new XcladeSDK({
baseUrl: 'https://{shortId}.api.myxclade.com',
jwtStorageKey: 'xclade_admin_jwt',
auth: {
type: 'session',
jwtTokenStorageKey: 'xclade_admin_jwt',
},
});
const me = await adminSdk.graphql.me();
const { products, count } = await adminSdk.graphql.listProducts({ limit: 20, offset: 0 });
const overview = await adminSdk.graphql.analyticsOverview({ currency_code: 'usd' });Locale Management
Switch translation locales dynamically—automatically attaches X-Xclade-Locale to subsequent requests:
xclade.setLocale('fr-FR');
const localizedCatalog = await xclade.store.listProducts({ limit: 12, currency_code: 'eur' });Error Handling
All GraphQL and transport errors surface via typed XcladeError / FetchError instances:
import { XcladeError, FetchError, mapGraphQLCodeToHttpStatus } from '@xclade/sdk';
try {
await xclade.store.completeCart(cartId);
} catch (err) {
if (err instanceof XcladeError) {
console.error(err.code, err.message, err.field);
if (err.code === 'IDRABBIT_VERIFICATION_REQUIRED') {
// Redirect customer to ID Rabbit age/ID verification session
}
} else if (err instanceof FetchError) {
console.error('HTTP status:', err.status, err.message);
}
}