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).
import { createClient } from '@01.software/sdk'
export const client = createClient({
publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY!
})| Property | Description |
|---|---|
from(collection) | Returns ReadOnlyQueryBuilder (find, findById, count) |
customer | Customer authentication (register, login, me, logout, ...) |
cart | Cart API (addItem, updateItem, removeItem) — requires customer auth |
query | React Query hooks (6 read + 3 mutation + 9 customer + prefetch + cache) |
queryClient | TanStack QueryClient instance |
ServerClient
A client for server environments (Server Components, API Routes, Server Actions).
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:
| Property | Description |
|---|---|
from(collection) | Returns CollectionQueryBuilder (read + create, update, remove, updateMany, removeMany) |
api | Orders API (9 methods: order, transaction, fulfillment, return) |
cart | Cart API (addItem, updateItem, removeItem) |
product | Product 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).