Skip to main content
Documentation

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)
ts

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.

SectionCovers
AuthuseAuth, useUser, useAuthStatus, useAuthProfileReady, AuthGate, AuthOverlay, signIn, signOut, getAuthToken
RecordsuseQuery, useMutations, RecordProvider, RecordScope, useUsers, useUserLookup
MessaginguseChannels, useMessages, useReactions, useChannelMembers, useReadReceipts, useConversation, useConversations, useCommunities, usePosts
Real-timeusePresence, usePresenceRoom, useYjsText, useYjsField, useCanvas, useGameRoom, useVoiceAgent, useCronMonitor, useJobs
FilesuseR2Files, formatFileSize, isImageFile
Integrationsintegration.post, OAuth helpers, platform-context exports
PaymentsuseSubscription, useCheckout, PricingTable, server helpers
ThemingDeepSpaceThemeProvider, 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'
ts

Worker - deepspace/worker#

Everything you import inside your Cloudflare Worker - DO base classes, schemas, auth verification, AI helpers.

SectionCovers
RoomsRecordRoom, YjsRoom, CanvasRoom, PresenceRoom, CronRoom, GameRoom, JobRoom, enqueueJob, DOManifest
SchemasCollectionSchema, RBAC types, drop-in collections, role constants
Server actionsActionHandler, ActionContext, ActionTools, ActionResult
AIcreateDeepSpaceAI, context compaction, chat history, built-in tools
CronCronTask, CronExecution, buildCronContext
AuthverifyJwt, createDeepSpaceAuth, HMAC primitives
BindingsrunMigrations, meterAi, meterVectorize, meterUsage, manifest types
Proxy helpersapiWorkerFetch, 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, refundInvoice and their error classes - server-side payment gates and operations. See payments reference.

Testing - deepspace/testing#

Multi-user Playwright fixture and 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.

ExportSignatureReturns
detectEnvironment() => Environment'dev' | 'staging' | 'prod' (cached after first call)
getEnvironmentConfig() => EnvironmentConfig{ name, apiUrl, platformWorkerUrl, authUrl, authSignInUrl, authSignUpUrl, mainAppUrl, dashboardUrl }
getApiUrl() => stringPlatform API worker URL for the current environment
getPlatformWorkerUrl() => stringPlatform worker URL for the current environment
getAuthUrl() => stringAuth worker URL for the current environment
isLocalDev() => booleandetectEnvironment() === 'dev'
isProduction() => booleandetectEnvironment() === 'prod'
resetEnvironmentCache() => voidClears the cached detection (useful in tests)
ENVobjectGetter-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)
ts

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.

ExportWhat it is
MSGConstants object of every JSON message type string (e.g. MSG.PUT is 'core.put')
ClientMessageDiscriminated union of every client → server message
ServerMessageDiscriminated union of every server → client message
clientBuildTyped 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),
  })
}
ts

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:

ModuleLocation
deepspacenode_modules/deepspace/dist/index.d.ts
deepspace/schemanode_modules/deepspace/dist/schema.d.ts
deepspace/workernode_modules/deepspace/dist/worker.d.ts
deepspace/servernode_modules/deepspace/dist/server.d.ts
deepspace/testingnode_modules/deepspace/dist/testing.d.ts
deepspace/documentationnode_modules/deepspace/dist/documentation.d.ts
deepspace/documentation/reactnode_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.