feat(chat-worker): scaffold Cloudflare Worker project

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Arthur Belleville 2026-04-11 11:59:27 +02:00
parent a9dc771ffb
commit d3f4287200
No known key found for this signature in database
4 changed files with 102 additions and 0 deletions

View file

@ -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"
}
}

View file

@ -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;
}

View file

@ -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"]
}

View file

@ -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 }