|
1 |
| -<img src="https://raw.githubusercontent.com/drifting-in-space/y-sweet/main/logo.svg" /> |
| 1 | +<img src="https://raw.githubusercontent.com/jamsocket/y-sweet/main/logo.svg" /> |
2 | 2 |
|
3 |
| -# y-sweet: a Yjs server with persistence and auth |
| 3 | +# Y-Sweet: a Yjs server with persistence and auth |
4 | 4 |
|
5 |
| -[](https://github.com/drifting-in-space/y-sweet) |
| 5 | +[](https://github.com/jamsocket/y-sweet) |
6 | 6 | [](https://discord.gg/N5sEpsuhh9)
|
7 | 7 |
|
8 |
| -**y-sweet** is an open-source server for building realtime applications on top of the [Yjs](https://github.com/yjs/yjs) CRDT library. |
| 8 | +**Y-Sweet** is an open-source server for building realtime applications on top of the [Yjs](https://github.com/yjs/yjs) CRDT library. |
9 | 9 |
|
10 | 10 | ## Features
|
11 | 11 |
|
12 | 12 | - Persists document data to a network filesystem or S3-compatible storage, [inspired by Figma’s infrastructure](https://digest.browsertech.com/archive/browsertech-digest-figma-is-a-file-editor/).
|
13 | 13 | - Scales horizontally with a [session backend](https://jamsocket.com/blog/session-backends) model.
|
14 |
| -- Deploys as a native Linux process, or as a WebAssembly module on Cloudflare's edge. |
| 14 | +- Deploys as a native Linux process. |
15 | 15 | - Provides document-level access control via client tokens.
|
16 | 16 | - Written in Rust with a focus on stability and performance, building on the [blazing fast](https://github.com/dmonad/crdt-benchmarks) [y-crdt](https://github.com/y-crdt/y-crdt/) library.
|
17 | 17 |
|
18 |
| -## y-sweet stack |
| 18 | +## Y-Sweet stack |
19 | 19 |
|
20 |
| -The y-sweet server can be used by any Yjs app, or you can use our opinionated stack to integrate Yjs and y-sweet into a Next.js app. |
| 20 | +The Y-Sweet server can be used by any Yjs app, or you can use our opinionated stack to integrate Yjs and Y-Sweet into a Next.js app. |
21 | 21 |
|
22 | 22 | - `@y-sweet/sdk`, a TypeScript library for interacting with `y-sweet-server` from your application backend.
|
23 |
| -- `@y-sweet/react`, a React hooks library for building Yjs applications. |
24 |
| -- A [debugger](https://y-sweet.cloud/advanced/debugger) for exploring Yjs document and presence state. |
| 23 | +- `@y-sweet/client`, a TypeScript library for syncing documents from a client to a Y-Sweet server. |
| 24 | +- `@y-sweet/react`, a library of React hooks for connecting to a Y-Sweet server and manipulating Yjs docs. |
| 25 | +- A [debugger](https://docs.jamsocket.com/y-sweet/advanced/debugger) for exploring Yjs document and presence state. |
25 | 26 |
|
26 |
| -The goal of the y-sweet stack is to give developers the end-to-end developer ergonomics they would expect from a proprietary state-sync platform, **without the lock-in**. |
| 27 | +The goal of the Y-Sweet stack is to give developers the end-to-end developer ergonomics they would expect from a proprietary state-sync platform, **without the lock-in**. |
27 | 28 |
|
28 |
| -y-sweet is MIT-licensed, and was created by [Jamsocket](https://jamsocket.com). |
| 29 | +Y-Sweet is MIT-licensed, and was created by [Jamsocket](https://jamsocket.com). |
29 | 30 |
|
30 | 31 | ## Docs
|
31 | 32 |
|
32 | 33 | - [API docs](https://docs.y-sweet.dev/index.html)
|
33 | 34 | - [Vanilla JS client](https://docs.y-sweet.dev/modules/_y_sweet_client.html)
|
34 | 35 | - [React hooks](https://docs.y-sweet.dev/modules/_y_sweet_react.html)
|
35 | 36 | - [Document management SDK](https://docs.y-sweet.dev/modules/_y_sweet_sdk.html)
|
36 |
| -- [Y-Sweet Cloud (managed service) docs](https://y-sweet.cloud/quickstart) |
| 37 | +- [Y-Sweet Cloud (managed service) docs](https://docs.jamsocket.com/y-sweet/quickstart) |
37 | 38 | - [Self Hosting](https://github.com/jamsocket/y-sweet/blob/main/docs/running.md)
|
38 | 39 |
|
39 | 40 | ## Examples
|
40 | 41 |
|
41 |
| -Explore our [collaborative examples](https://github.com/drifting-in-space/y-sweet) to help you get started. |
| 42 | +Explore our [collaborative examples](https://github.com/jamsocket/y-sweet) to help you get started. |
42 | 43 |
|
43 |
| -All examples are open source and live in this repository, within [/examples](https://github.com/drifting-in-space/y-sweet/tree/main/examples). |
| 44 | +All examples are open source and live in this repository, within [/examples](https://github.com/jamsocket/y-sweet/tree/main/examples). |
44 | 45 |
|
45 | 46 | ## Usage
|
46 | 47 |
|
47 | 48 | Check the [vanilla js example](/examples/vanilla/) for more details.
|
48 | 49 |
|
49 | 50 | ### On the server
|
50 | 51 | ``` js
|
51 |
| -import { DocumentManager } from '@y-sweet/sdk' |
52 |
| - |
53 |
| -// Pass in a CONNECTION_STRING, which you can get from running npx y-sweet@latest serve locally or from y-sweet cloud |
54 |
| -const manager = new DocumentManager(CONNECTION_STRING) |
55 |
| - |
56 |
| -// Get the client token from the y-sweet server. The client token is like the user's "password" to edit the "myDoc123" doc. |
57 |
| -const clientToken = await manager.getOrCreateDocAndToken('myDoc123') |
| 52 | +import { DocumentManager } from '@y-sweet/sdk'; |
| 53 | + |
| 54 | +// Pass in a CONNECTION_STRING, which you can get from a Y-Sweet service in the Jamsocket dashboard or from running npx y-sweet@latest serve locally |
| 55 | +const manager = new DocumentManager(CONNECTION_STRING); |
| 56 | + |
| 57 | +// create an endpoint that auths your user and returns a Y-Sweet client token |
| 58 | +export async function POST(request) { |
| 59 | + // in a production app, you'd want to authenticate the user |
| 60 | + // and make sure they have access to the given doc |
| 61 | + const body = await request.json(); |
| 62 | + const docId = body.docId; |
| 63 | + const clientToken = await manager.getOrCreateDocAndToken(docId); |
| 64 | + return Response.json(clientToken); |
| 65 | +} |
58 | 66 | ```
|
59 | 67 |
|
60 | 68 | ### On the client
|
61 | 69 | ``` js
|
62 | 70 | import * as Y from 'yjs';
|
63 | 71 | import { createYjsProvider } from '@y-sweet/client';
|
64 | 72 |
|
65 |
| -// Create the yjs doc and link it to the y-sweet server: |
| 73 | +// Create the Yjs doc and link it to the Y-Sweet server: |
66 | 74 | const doc = new Y.Doc();
|
67 |
| -createYjsProvider(doc, clientToken); |
| 75 | +const docId = 'my-doc-id'; |
| 76 | +createYjsProvider(doc, docId, '/api/my-auth-endpoint'); |
68 | 77 |
|
69 |
| -// Now use the doc like a normal yjs doc! |
| 78 | +// Now use the doc like a normal Yjs doc! |
70 | 79 | let mySharedMap = doc.getMap('thing');
|
71 | 80 | mySharedMap.set("foo", 123);
|
72 | 81 |
|
@@ -98,12 +107,12 @@ mySharedMap.observe((event) => {
|
98 | 107 | | npm | `@y-sweet/react` | [](https://www.npmjs.com/package/@y-sweet/react) | `js-pkg/react` |
|
99 | 108 | | pypi | `y-sweet-sdk` | [](https://pypi.org/project/y-sweet-sdk/) | `python/y_sweet_sdk` |
|
100 | 109 |
|
101 |
| -## Y-Sweet Cloud |
| 110 | +## Hosted Y-Sweet on Jamsocket |
102 | 111 |
|
103 |
| -If you were to use the open source y-sweet server alone, you would still have to set up the infrastructure for self hosting it. With Y-Sweet cloud, every document is automatically persisted. You can link your own S3-compatible storage, or just let us take care of the details. |
| 112 | +If you were to use the open source Y-Sweet server alone, you would still have to set up the infrastructure for self hosting it. With [Jamsocket](https://jamsocket.com/y-sweet), Y-Sweet scales effortlessly, and every document is automatically persisted when you link your own S3 storage. |
104 | 113 |
|
105 |
| -You can try a preview for free today by following our [quickstart](https://y-sweet.cloud/quickstart) guide. |
| 114 | +You can try it out for free today by following our [quickstart](https://docs.jamsocket.com/y-sweet/quickstart) guide. |
106 | 115 |
|
107 | 116 | If you are interested in being a build partner for early access to new features, please [reach out ](mailto:[email protected]).
|
108 | 117 |
|
109 |
| -We are committed to growing y-sweet as an open-source-first project, wherever you decide to host it. |
| 118 | +We are committed to growing Y-Sweet as an open-source-first project, wherever you decide to host it. |
0 commit comments