01 Software

Client

Browser and Server client setup guide

Client

The SDK provides two types of clients depending on your environment.

Client

A read-only client for browser environments (Client Components).

lib/client.ts
import { createClient } from '@01.software/sdk'

export const client = createClient({
  publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY!
})
PropertyDescription
from(collection)Returns ReadOnlyQueryBuilder (find, findById, count)
customerCustomer authentication (register, login, me, logout, ...)
cartCart API (addItem, updateItem, removeItem) — requires customer auth
queryReact Query hooks (6 read + 3 mutation + 9 customer + prefetch + cache)
queryClientTanStack QueryClient instance

ServerClient

A client for server environments (Server Components, API Routes, Server Actions).

lib/server-client.ts
import { createServerClient } from '@01.software/sdk'

export const serverClient = createServerClient({
  publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY!,
  secretKey: process.env.SOFTWARE_SECRET_KEY!,
})

The secretKey must never be exposed to the browser!

In addition to all Client properties, it provides:

PropertyDescription
from(collection)Returns CollectionQueryBuilder (read + create, update, remove, updateMany, removeMany)
apiOrders API (9 methods: order, transaction, fulfillment, return)
cartCart API (addItem, updateItem, removeItem)
productProduct API (stockCheck)

Configuration Options

const client = createClient({
  publishableKey: string,      // Required: Publishable Key (pk01_...)
  customer?: {                 // Customer authentication
    persist?: boolean | string, // Auto-persist in localStorage (default key: 'customer-token')
    token?: string,            // Initial token (ignored when persist is set)
    onTokenChange?: (token: string | null) => void,  // Persist callback (ignored when persist is set)
  },
})

The API URL is resolved at build time (api-dev.01.software for @dev releases, api.01.software for stable). To override at runtime, set SOFTWARE_API_URL (server) or NEXT_PUBLIC_SOFTWARE_API_URL (browser).

On this page