SDK reference
Every export from the deepspace package, with signatures and examples.
On this page
The deepspace package exposes five main entry points (plus two for the documentation feature). Each section of this reference documents the surface of one entry point, organized by feature.
import { ... } from 'deepspace' // React client SDK
import { ... } from 'deepspace/schema' // Runtime-neutral schemas (browser + worker safe)
import { ... } from 'deepspace/worker' // Cloudflare Worker runtime
import { ... } from 'deepspace/server' // Platform-backed server helpers
import { ... } from 'deepspace/testing' // Playwright fixture (test files only)
Choosing between deepspace/schema and deepspace/worker for schemas: deepspace/schema is the runtime-neutral entry - import from it for any schema (or schema type) that browser or shared code touches, so neither runtime's surface leaks into the other bundle. Reserve deepspace/worker for worker-only helpers (DO classes, auth verification, metering). Every name deepspace/schema exports is also available from deepspace/worker, so worker-only files may keep importing schemas from deepspace/worker.
Client - deepspace#
Everything you import on the frontend - providers, hooks, components, and utility functions.
| Section | Covers |
|---|---|
| Auth | useAuth, useUser, useAuthStatus, useAuthProfileReady, AuthGate, AuthOverlay, signIn, signOut, getAuthToken |
| Records | useQuery, useMutations, RecordProvider, RecordScope, useUsers, useUserLookup |
| Messaging | useChannels, useMessages, useReactions, useChannelMembers, useReadReceipts, useConversation, useConversations, useCommunities, usePosts |
| Real-time | usePresence, usePresenceRoom, useYjsText, useYjsField, useCanvas, useGameRoom, useVoiceAgent, useCronMonitor, useJobs |
| Files | useR2Files, formatFileSize, isImageFile |
| Integrations | integration.post, OAuth helpers, platform-context exports |
| Payments | useSubscription, useCheckout, PricingTable, server helpers |
| Theming | DeepSpaceThemeProvider, applyDeepSpaceTheme, getUserColor |
The client entry also exports the environment helpers and the wire protocol layer documented at the bottom of this page.
Schemas - deepspace/schema#
Runtime-neutral collection declarations - the CollectionSchema / ColumnDefinition / ColumnInterpretation / RolePermissions / PermissionLevel types plus the drop-in schema constants (USERS_COLUMNS, BASE_USERS_SCHEMA, the messaging schemas, AI_CHATS_SCHEMA / AI_MESSAGES_SCHEMA, CONVERSATION_SCHEMAS, DIRECTORY_SCHEMAS, VOTING_SCHEMAS, WORKSPACE_SCHEMAS). See the schemas reference for every shape - the surface is identical, only the import home differs.
// src/schemas/items-schema.ts — imported by both the worker and the browser
import type { CollectionSchema } from 'deepspace/schema'
Worker - deepspace/worker#
Everything you import inside your Cloudflare Worker - DO base classes, schemas, auth verification, AI helpers.
| Section | Covers |
|---|---|
| Rooms | RecordRoom, YjsRoom, CanvasRoom, PresenceRoom, CronRoom, GameRoom, JobRoom, enqueueJob, DOManifest |
| Schemas | CollectionSchema, RBAC types, drop-in collections, role constants |
| Server actions | ActionHandler, ActionContext, ActionTools, ActionResult |
| AI | createDeepSpaceAI, context compaction, chat history, built-in tools |
| Cron | CronTask, CronExecution, buildCronContext |
| Auth | verifyJwt, createDeepSpaceAuth, HMAC primitives |
| Bindings | runMigrations, meterAi, meterVectorize, meterUsage, manifest types |
| Proxy helpers | apiWorkerFetch, platformWorkerFetch, authWorkerFetch |
Server - deepspace/server#
Platform-backed helpers for worker-side code that talks to the DeepSpace platform rather than your own DO:
captureScreenshot- shared Browser Rendering capture. See bindings reference.requireSubscription,getSubscription,cancelSubscription,refundInvoiceand their error classes - server-side payment gates and operations. See payments reference.
Testing - deepspace/testing#
Multi-user Playwright fixture and account helpers.
- Testing reference -
test,expect,users(N),MultiplayerUser, account helpers.
Environment helpers#
Exported from deepspace (and usable in shared code). The SDK detects which environment the code is running in - build-time __DEEPSPACE_ENV__ define, then runtime window.__DEEPSPACE_ENV__, then server-side process.env.DEEPSPACE_ENV, then hostname - and derives the platform service URLs from it.
| Export | Signature | Returns |
|---|---|---|
detectEnvironment | () => Environment | 'dev' | 'staging' | 'prod' (cached after first call) |
getEnvironmentConfig | () => EnvironmentConfig | { name, apiUrl, platformWorkerUrl, authUrl, authSignInUrl, authSignUpUrl, mainAppUrl, dashboardUrl } |
getApiUrl | () => string | Platform API worker URL for the current environment |
getPlatformWorkerUrl | () => string | Platform worker URL for the current environment |
getAuthUrl | () => string | Auth worker URL for the current environment |
isLocalDev | () => boolean | detectEnvironment() === 'dev' |
isProduction | () => boolean | detectEnvironment() === 'prod' |
resetEnvironmentCache | () => void | Clears the cached detection (useful in tests) |
ENV | object | Getter-based convenience: ENV.current, ENV.config, ENV.apiUrl, ENV.platformWorkerUrl, ENV.authUrl, ENV.isLocal, ENV.isProd |
import { getApiUrl, isLocalDev } from 'deepspace'
const res = await fetch(`${getApiUrl()}/api/health`)
if (isLocalDev()) console.debug('api health', res.status)
Wire protocol layer#
For apps that build their own WebSocket client against a DeepSpace DO instead of using the built-in hooks. Exported from both deepspace and deepspace/worker, so a custom hook and a custom room speak the same typed vocabulary.
| Export | What it is |
|---|---|
MSG | Constants object of every JSON message type string (e.g. MSG.PUT is 'core.put') |
ClientMessage | Discriminated union of every client → server message |
ServerMessage | Discriminated union of every server → client message |
clientBuild | Typed builder factories for client → server messages (clientBuild.put(...), clientBuild.subscribe(...), ...) |
dispatch(raw, handlers) | Parses a raw frame (or accepts a parsed object) and routes it by type; returns true if a handler ran |
encode(message) | Serializes a built message for ws.send |
import { MSG, clientBuild, dispatch, encode, type ServerMessage } from 'deepspace'
ws.send(encode(clientBuild.put('notes', noteId, { title: 'Hello' })))
ws.onmessage = (event) => {
dispatch<ServerMessage>(event.data, {
[MSG.RECORD_CHANGE]: (payload) => applyChange(payload),
[MSG.ERROR]: (payload) => console.error(payload.error),
})
}
Most apps should use the records hooks instead - this layer exists for custom clients and custom rooms.
TypeScript signatures#
This reference shows the most common signatures and shapes. For exact type definitions - including generic constraints, optional fields, and discriminated unions - read the bundled .d.ts files:
| Module | Location |
|---|---|
deepspace | node_modules/deepspace/dist/index.d.ts |
deepspace/schema | node_modules/deepspace/dist/schema.d.ts |
deepspace/worker | node_modules/deepspace/dist/worker.d.ts |
deepspace/server | node_modules/deepspace/dist/server.d.ts |
deepspace/testing | node_modules/deepspace/dist/testing.d.ts |
deepspace/documentation | node_modules/deepspace/dist/documentation.d.ts |
deepspace/documentation/react | node_modules/deepspace/dist/documentation-react.d.ts |
deepspace/documentation and deepspace/documentation/react back the documentation feature; apps rarely import them directly.
If a hook or type isn't documented in this reference, it probably exists in the .d.ts. Read the declaration before guessing.