JavaScript/TypeScript backend SDK for building collaboration features with y-sweet.
npm install @y-sweet/sdk
Read the documentation for guides and API references.
Explore our collaborative examples to help you get started.
All examples are open source and live in this repository, within /examples.
Here’s how access control works in y-sweet:
The client token contains all the information needed for the client to connect to a y-sweet document, so the client doesn’t need any configuration. But you do need to tell your server how to talk to y-sweet, by passing a server token.
A server token combines a URL and a secret key. It can be represented either as a JSON object with url
and token
as keys, or as a JSONified string
of the same. This makes it easy to store the server token in a secret store, and pass it to your server code as an environment variable.
import { YDocProvider } from '@y-sweet/react'
import { getOrCreateDocAndToken } from '@y-sweet/sdk'
type HomeProps = {
searchParams: Record<string, string>
}
export default async function Home({ searchParams }: HomeProps) {
// Point to a local or production y-sweet server.
const connectionString = "ys://localhost:8080"
const clientToken = await getOrCreateDocAndToken(connectionString, searchParams.doc)
return (
<YDocProvider clientToken={clientToken} setQueryParam="doc">
// Call your collaborative interface here
</YDocProvider>
)
}