Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"@hookform/resolvers": "^5.0.1",
"@lighthouse-web3/kavach": "^0.2.1",
"@lighthouse-web3/sdk": "^0.3.7",
"@livestore/adapter-web": "^0.3.1",
"@livestore/livestore": "^0.3.1",
"@livestore/peer-deps": "^0.3.1",
"@livestore/react": "^0.3.1",
"@livestore/sync-cf": "^0.3.1",
"@livestore/adapter-web": "0.4.0-dev.20",
"@livestore/livestore": "0.4.0-dev.20",
"@livestore/peer-deps": "0.4.0-dev.20",
"@livestore/react": "0.4.0-dev.20",
"@livestore/sync-cf": "0.4.0-dev.20",
"@livestore/wa-sqlite": "1.0.5-dev.2",
"@radix-ui/react-avatar": "^1.1.10",
"@radix-ui/react-collapsible": "^1.1.11",
Expand All @@ -41,10 +41,10 @@
"@radix-ui/react-slot": "^1.2.0",
"@radix-ui/react-tabs": "^1.1.9",
"@radix-ui/react-tooltip": "^1.2.4",
"@storacha/client": "^1.6.1",
"@types/react": "^19.1.2",
"@types/react-dom": "^19.1.2",
"@w3ui/react": "^2.5.5",
"@storacha/client": "^1.6.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"jsdom": "^26.1.0",
Expand All @@ -62,30 +62,30 @@
"zod": "^3.24.3"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.6.3",
"vite-tsconfig-paths": "^5.1.4",
"@cloudflare/vite-plugin": "^1.9.0",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@vitejs/plugin-react-swc": "^3.10.2",
"globals": "^16.3.0",
"typescript": "~5.8.3",
"vite": "^7.0.4",
"wrangler": "^4.26.0",
"@biomejs/biome": "1.9.4",
"@livestore/devtools-vite": "^0.3.1",
"@cloudflare/vite-plugin": "^1.9.0",
"@livestore/devtools-vite": "0.4.0-dev.20",
"@tailwindcss/typography": "^0.5.16",
"@tailwindcss/vite": "^4.1.4",
"@testing-library/jest-dom": "^6.6.3",
"@types/node": "^22.15.17",
"@types/react": "^19.1.8",
"@types/react-dom": "^19.1.6",
"@vitejs/plugin-react": "^4.3.4",
"@vitejs/plugin-react-swc": "^3.10.2",
"@vitest/ui": "^2.1.8",
"autoprefixer": "^10.4.20",
"globals": "^16.3.0",
"postcss": "^8.4.49",
"shadcn": "^2.5.0",
"tailwindcss": "^4.1.4",
"tsx": "^4.19.2",
"tw-animate-css": "^1.2.8",
"typescript": "~5.8.3",
"vite": "^7.0.4",
"vite-bundle-analyzer": "^1.1.0",
"vitest": "^2.1.8"
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^2.1.8",
"wrangler": "^4.26.0"
}
}
4 changes: 2 additions & 2 deletions apps/webapp/src/livestore/livestore.worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeWorker } from "@livestore/adapter-web/worker";
import { makeCfSync } from "@livestore/sync-cf";
import { makeWsSync } from "@livestore/sync-cf/client";

import { schema } from "./schema.js";

Expand All @@ -13,7 +13,7 @@ declare global {
makeWorker({
schema,
sync: {
backend: makeCfSync({
backend: makeWsSync({
url: import.meta.env.VITE_LIVESTORE_SYNC_URL || "http://localhost:8787",
}),
initialSyncOptions: { _tag: "Blocking", timeout: 5000 },
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default defineConfig({
"@livestore/react",
"@livestore/adapter-web",
"@livestore/livestore",
"@livestore/sync-cf",
"@livestore/sync-cf/client",
],
"markdown-editor": ["react-markdown"],
"form-vendor": ["react-hook-form", "@hookform/resolvers", "zod"],
Expand Down
36 changes: 0 additions & 36 deletions packages/cf-worker/api/wrangler.toml

This file was deleted.

14 changes: 7 additions & 7 deletions packages/cf-worker/livestore-sidecar/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hono } from 'hono';
import { makeAdapter } from '@livestore/adapter-node';
import { createStorePromise, Store } from '@livestore/livestore';
import { makeCfSync } from '@livestore/sync-cf';
import { makeWsSync } from '@livestore/sync-cf/client';
import { serve } from '@hono/node-server'
import { events, schema, tables } from './schema';

Expand All @@ -23,8 +23,8 @@ class StoreSingleton {

const adapter = makeAdapter({
storage: { type: 'in-memory' }, // Use in-memory storage for containers
sync: {
backend: makeCfSync({
sync: {
backend: makeWsSync({
url: 'https://geist-livestore-sync-worker.debuggingfuturecors.workers.dev',
}),
initialSyncOptions: {
Expand All @@ -42,7 +42,7 @@ class StoreSingleton {

this.store = store;
return store;


}
}
Expand All @@ -55,17 +55,17 @@ app.get('/api/resources/entries', async (c) => {
console.log('Syncing Resources: entires');

try {

const store = await StoreSingleton.getInstance();
const entries = store.query(tables.entries)

return c.json(entries);

} catch (e) {
console.error(e);

return c.text('Error', e.message);

}

});
Expand Down
13 changes: 9 additions & 4 deletions packages/cf-worker/livestore-sync/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "geist-livestore-sync-worker",
"main": "../src/sync-worker.ts",
"compatibility_date": "2025-05-08",
"compatibility_flags": ["nodejs_compat"],
"compatibility_flags": ["nodejs_compat", "enable_request_signal"],

// Secrets configuration
"secrets_store_secrets": [
Expand Down Expand Up @@ -34,17 +34,22 @@
"durable_objects": {
"bindings": [
{
"name": "WEBSOCKET_SERVER",
"class_name": "WebSocketServer"
"name": "SYNC_BACKEND_DO",
"class_name": "SyncBackendDO"
}
]
},

// Migrations
"migrations": [
{
"tag": "v1",
"new_classes": ["WebSocketServer"]
},
{
"tag": "v2",
"deleted_classes": ["WebSocketServer"],
"new_sqlite_classes": ["SyncBackendDO"]
}
],

Expand Down
8 changes: 4 additions & 4 deletions packages/cf-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"lint": "biome check --fix"
},
"dependencies": {
"multiformats": "^13.3.2",
"@cloudflare/vite-plugin": "^1.9.0",
"@geist-filecoin/auth": "workspace:*",
"@geist-filecoin/storage": "workspace:*",
"@livestore/sync-cf": "^0.3.1",
"@livestore/sync-cf": "0.4.0-dev.20",
"@noble/ciphers": "^1.3.0",
"@tsndr/cloudflare-worker-jwt": "^3.2.0",
"itty-durable": "^2.4.1",
"itty-router": "^5.0.18",
"jose": "^6.0.11"
"jose": "^6.0.11",
"multiformats": "^13.3.2"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@cloudflare/workers-types": "^4.20250620.0",
"@cloudflare/containers": "^0.0.19",
"@cloudflare/workers-types": "^4.20250620.0",
"typescript": "^5.8.3",
"vite": "^6.3.4",
"wrangler": "^4.26.0"
Expand Down
16 changes: 9 additions & 7 deletions packages/cf-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ const errorHandler = (error: Error, request: Request) => {
const authMiddleware = async (request: IRequest, env: any) => {
const authHeader = request.headers.get("Authorization");
if (!authHeader || !authHeader.startsWith("Bearer ")) {
return json({ error: "Missing or invalid Authorization header" }, { status: 401 });
return json(
{ error: "Missing or invalid Authorization header" },
{ status: 401 },
);
}

const token = authHeader.substring(7); // Remove "Bearer "
Expand Down Expand Up @@ -245,11 +248,7 @@ export const loadStorachaSecrets = async (env: any) => {
// better off separate 2 requests from very beginning

router.post("/api/auth/ucan", async (request: Request, env: any) => {
const {
agentDid,
spaceId,
tokenType,
} = (await request.json()) as {
const { agentDid, spaceId, tokenType } = (await request.json()) as {
agentDid: `did:${string}`;
spaceId: string;
tokenType: string;
Expand Down Expand Up @@ -540,7 +539,10 @@ router.post("/api/auth/token", async (request: Request, env: any) => {
// In a real app, you'd have user authentication here
const { sub, name, email } = await request.json();
if (!sub || !name || !email) {
return json({ error: "Missing required user information (sub, name, email)" }, { status: 400 });
return json(
{ error: "Missing required user information (sub, name, email)" },
{ status: 400 },
);
}
const payload = {
sub,
Expand Down
33 changes: 19 additions & 14 deletions packages/cf-worker/src/sync-worker.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { type ExecutionContext, WorkerEntrypoint } from "cloudflare:workers";
import {
type Env,
type CfTypes,
makeDurableObject,
makeWorker,
} from "@livestore/sync-cf/cf-worker";

export class WebSocketServer extends makeDurableObject({
// Define the environment type with the sync backend binding
type Env = CfTypes.Env & {
SYNC_BACKEND_DO: CfTypes.DurableObjectNamespace;
};

export class SyncBackendDO extends makeDurableObject({
onPush: async (message) => {
console.log("onPush", message.batch);
},
Expand All @@ -14,26 +19,26 @@ export class WebSocketServer extends makeDurableObject({
},
}) {}

// Note AutoRouter not compatabile
const syncWorker = makeWorker({
validatePayload: (payload: any) => {
if (payload?.authToken !== "insecure-token-change-me") {
// Note AutoRouter not compatible
const syncWorker = makeWorker<Env>({
syncBackendBinding: "SYNC_BACKEND_DO",
validatePayload: (payload: unknown) => {
if (
typeof payload !== "object" ||
payload === null ||
!("authToken" in payload) ||
payload.authToken !== "insecure-token-change-me"
) {
throw new Error("Invalid auth token");
}
},
enableCORS: true,
});

export class WorkerLiveStore extends WorkerEntrypoint {
export class WorkerLiveStore extends WorkerEntrypoint<Env> {
// Currently, entrypoints without a named handler are not supported
async fetch(request: Request) {
return syncWorker.fetch(
request,
// @ts-expect-error
this.env as Env,
// @ts-expect-error
this.ctx as ExecutionContext,
);
return syncWorker.fetch(request, this.env, this.ctx as ExecutionContext);
}
}

Expand Down
Loading
Loading