01 Software

Client

Browser and Server client setup guide

Client

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

BrowserClient

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

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

export const client = createBrowserClient({
  clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_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({
  clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY!,
  secretKey: process.env.SOFTWARE_SECRET_KEY!,
})

The secretKey must never be exposed to the browser!

In addition to all BrowserClient 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 = createBrowserClient({
  clientKey: string,           // Required: API client key
  environment?: Environment,   // 'local' | 'production' (default: 'production')
  baseUrl?: string,            // API URL override (default: https://api.01.software)
  customer?: {                 // Customer authentication
    token?: string,            // Initial token (e.g. from localStorage)
    onTokenChange?: (token: string | null) => void,  // Persist on login/logout
  },
})

Priority: baseUrl > environment variable (SOFTWARE_API_URL) > environment > production

On this page