From d3f428720091cde18885ba7b52cc552d4d7c54cb Mon Sep 17 00:00:00 2001 From: Arthur Belleville Date: Sat, 11 Apr 2026 11:59:27 +0200 Subject: [PATCH] feat(chat-worker): scaffold Cloudflare Worker project Co-Authored-By: Claude Sonnet 4.6 --- apps/chat-worker/package.json | 22 ++++++++++++++++++ apps/chat-worker/src/lib/types.ts | 37 +++++++++++++++++++++++++++++++ apps/chat-worker/tsconfig.json | 15 +++++++++++++ apps/chat-worker/wrangler.toml | 28 +++++++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 apps/chat-worker/package.json create mode 100644 apps/chat-worker/src/lib/types.ts create mode 100644 apps/chat-worker/tsconfig.json create mode 100644 apps/chat-worker/wrangler.toml diff --git a/apps/chat-worker/package.json b/apps/chat-worker/package.json new file mode 100644 index 0000000..9230b22 --- /dev/null +++ b/apps/chat-worker/package.json @@ -0,0 +1,22 @@ +{ + "name": "@xtablo/chat-worker", + "version": "0.0.0", + "private": true, + "type": "module", + "scripts": { + "dev": "wrangler dev", + "deploy": "wrangler deploy", + "deploy:staging": "wrangler deploy --env staging", + "deploy:prod": "wrangler deploy --env production", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "hono": "^4.7.7", + "jose": "^6.0.0" + }, + "devDependencies": { + "@cloudflare/workers-types": "^4.20250410.0", + "typescript": "^5.8.3", + "wrangler": "^4.14.0" + } +} diff --git a/apps/chat-worker/src/lib/types.ts b/apps/chat-worker/src/lib/types.ts new file mode 100644 index 0000000..882f57e --- /dev/null +++ b/apps/chat-worker/src/lib/types.ts @@ -0,0 +1,37 @@ +// WebSocket message types — client to server +export type ClientMessage = + | { type: "message.send"; text: string; clientId: string } + | { type: "typing.start" } + | { type: "typing.stop" } + | { type: "presence.ping" }; + +// WebSocket message types — server to client +export type ServerMessage = + | { type: "message.new"; id: string; userId: string; text: string; createdAt: string; clientId: string } + | { type: "typing"; userId: string; isTyping: boolean } + | { type: "presence.update"; userId: string; status: "online" | "offline" } + | { type: "error"; code: string; message: string }; + +// REST API types +export interface ChatMessage { + id: string; + channel_id: string; + user_id: string; + text: string; + created_at: string; + updated_at: string | null; + deleted_at: string | null; +} + +export interface UnreadCount { + channel_id: string; + unread_count: number; +} + +// Worker environment bindings +export interface Env { + CHAT_ROOM: DurableObjectNamespace; + SUPABASE_URL: string; + SUPABASE_SERVICE_ROLE_KEY: string; + JWT_SECRET: string; +} diff --git a/apps/chat-worker/tsconfig.json b/apps/chat-worker/tsconfig.json new file mode 100644 index 0000000..a4473e3 --- /dev/null +++ b/apps/chat-worker/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ES2022", + "moduleResolution": "bundler", + "lib": ["ES2022"], + "types": ["@cloudflare/workers-types"], + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true, + "outDir": "./dist", + "rootDir": "./src" + }, + "include": ["src"] +} diff --git a/apps/chat-worker/wrangler.toml b/apps/chat-worker/wrangler.toml new file mode 100644 index 0000000..ee06486 --- /dev/null +++ b/apps/chat-worker/wrangler.toml @@ -0,0 +1,28 @@ +name = "xtablo-chat" +main = "src/index.ts" +compatibility_date = "2025-07-09" + +[durable_objects] +bindings = [ + { name = "CHAT_ROOM", class_name = "ChatRoom" } +] + +[[migrations]] +tag = "v1" +new_classes = ["ChatRoom"] + +[observability] +enabled = true + +[vars] +SUPABASE_URL = "https://mhcafqvzbrrwvahpvvzd.supabase.co" + +# Secrets (set via `wrangler secret put`): +# SUPABASE_SERVICE_ROLE_KEY +# JWT_SECRET + +[env.staging] +route = { pattern = "chat-staging.xtablo.com", custom_domain = true } + +[env.production] +route = { pattern = "chat.xtablo.com", custom_domain = true }