Skip to content

MakeWorkerOptions

MakeWorkerOptions<TEnv, TSyncPayload> = object

Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:32

Options accepted by makeWorker. The Durable Object binding has to be supplied explicitly so we never fall back to deprecated defaults when Cloudflare config changes.

TEnv extends Env = Env

TSyncPayload = Schema.JsonValue

optional enableCORS: boolean

Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:62

false

syncBackendBinding: HelperTypes.ExtractDurableObjectKeys<TEnv>

Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:36

Binding name of the sync Durable Object declared in wrangler config.


optional syncPayloadSchema: Schema.Schema<TSyncPayload>

Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:41

Optionally pass a schema to decode the client-provided payload into a typed object before calling validatePayload. If omitted, the raw JSON value is forwarded.


optional validatePayload: (payload, context) => void | Promise<void>

Defined in: packages/@livestore/sync-cf/src/cf-worker/worker.ts:60

Validates the (optionally decoded) payload during WebSocket connection establishment. If syncPayloadSchema is provided, payload will be of the schema’s inferred type.

The context includes request headers for cookie-based or header-based authentication.

TSyncPayload

ValidatePayloadContext

void | Promise<void>

validatePayload: async (payload, { storeId, headers }) => {
const cookie = headers.get('cookie')
const session = await validateSessionFromCookie(cookie)
if (!session) throw new Error('Unauthorized')
}

Note: This runs only at connection time, not for individual push events. For push event validation, use the onPush callback in the Durable Object.