@quickscores/chat 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -147
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,158 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @quickscores/chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared TypeScript types and Zod schemas for the QuickScores chat API. Use from React Native or web apps that call the chat endpoints.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- **Supabase**: config, migrations, and Edge Functions for chat (DB, RLS, Realtime).
|
|
8
|
-
- **Shared types**: TypeScript types and Zod schemas in `src/types/` for use by RN and web clients.
|
|
9
|
-
|
|
10
|
-
## Prerequisites
|
|
11
|
-
|
|
12
|
-
- [Supabase CLI](https://supabase.com/docs/guides/cli) (`npm i -g supabase` or `npx supabase`)
|
|
13
|
-
- Node.js 20+
|
|
14
|
-
- A [Supabase project](https://supabase.com/dashboard) (for remote; optional for local-only)
|
|
15
|
-
|
|
16
|
-
## Setup
|
|
5
|
+
## Install
|
|
17
6
|
|
|
18
7
|
```bash
|
|
19
|
-
npm install
|
|
8
|
+
npm install @quickscores/chat
|
|
20
9
|
```
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import {
|
|
15
|
+
threadSchema,
|
|
16
|
+
threadKindSchema,
|
|
17
|
+
threadListRowSchema,
|
|
18
|
+
messageSchema,
|
|
19
|
+
type Thread,
|
|
20
|
+
type ThreadKind,
|
|
21
|
+
type ThreadListRow,
|
|
22
|
+
type Message,
|
|
23
|
+
type CreateThreadBody,
|
|
24
|
+
type SendMessageBody,
|
|
25
|
+
type ThreadResponse,
|
|
26
|
+
type MessageResponse,
|
|
27
|
+
type ErrorResponse,
|
|
28
|
+
} from "@quickscores/chat";
|
|
26
29
|
```
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npx supabase link --project-ref <your-project-ref>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Migrations
|
|
35
|
-
|
|
36
|
-
- Create: put SQL in `supabase/migrations/` with timestamped names (e.g. `20240202120000_create_chat_tables.sql`), or use `npm run db:diff` after changing schema locally.
|
|
37
|
-
- Apply locally: `npx supabase db reset` (reset + seed) or run migrations manually.
|
|
38
|
-
- Push to remote: `npm run db:migrate` (or `npx supabase db push`).
|
|
39
|
-
|
|
40
|
-
### Deploy to Supabase
|
|
41
|
-
|
|
42
|
-
1. **Create a project** at [supabase.com/dashboard](https://supabase.com/dashboard) if you don’t have one. Note the **Project ref** (in Settings → General).
|
|
43
|
-
|
|
44
|
-
2. **Link** the repo to that project (one-time):
|
|
45
|
-
```bash
|
|
46
|
-
npx supabase link --project-ref <your-project-ref>
|
|
47
|
-
```
|
|
48
|
-
Use your database password when prompted (from Dashboard → Settings → Database).
|
|
49
|
-
|
|
50
|
-
3. **Push migrations** (schema + RLS):
|
|
51
|
-
```bash
|
|
52
|
-
npm run db:migrate
|
|
53
|
-
```
|
|
54
|
-
or `npx supabase db push`.
|
|
55
|
-
|
|
56
|
-
4. **Deploy Edge Functions** (chat REST API):
|
|
57
|
-
```bash
|
|
58
|
-
npx supabase functions deploy
|
|
59
|
-
```
|
|
60
|
-
This deploys all functions in `supabase/functions/` (e.g. `chat-thread`, `chat-send-message`, `chat-mark-read`). To deploy a single function: `npx supabase functions deploy chat-thread`.
|
|
61
|
-
|
|
62
|
-
5. **Set secrets** (if your functions need them): in Dashboard → Edge Functions → Secrets, or:
|
|
63
|
-
```bash
|
|
64
|
-
npx supabase secrets set SUPABASE_SERVICE_ROLE_KEY=<your-service-role-key>
|
|
65
|
-
```
|
|
66
|
-
The hosted project already has `SUPABASE_URL` and `SUPABASE_SERVICE_ROLE_KEY` set by default for deployed functions; you only need to add custom secrets.
|
|
67
|
-
|
|
68
|
-
Your API base URL will be `https://<project-ref>.supabase.co/functions/v1`. Use that in clients instead of `http://127.0.0.1:54321/functions/v1`.
|
|
69
|
-
|
|
70
|
-
## Scripts
|
|
71
|
-
|
|
72
|
-
| Script | Description |
|
|
73
|
-
|-----------------|--------------------------------------|
|
|
74
|
-
| `npm run db:start` | Start local Supabase stack |
|
|
75
|
-
| `npm run db:stop` | Stop local Supabase |
|
|
76
|
-
| `npm run db:reset` | Reset DB and run migrations + seed |
|
|
77
|
-
| `npm run db:migrate`| Push migrations to linked project |
|
|
78
|
-
| `npm run db:diff` | Generate migration from schema diff |
|
|
79
|
-
| `npm run build` | Build types package to `dist/` (for publish) |
|
|
80
|
-
| `npm run types:check` | TypeScript check (no emit) |
|
|
81
|
-
| `npm run lint` | Prettier check |
|
|
82
|
-
| `npm run lint:fix` | Prettier fix |
|
|
83
|
-
|
|
84
|
-
## Using shared types in the app
|
|
85
|
-
|
|
86
|
-
From the React Native (or web) app:
|
|
87
|
-
|
|
88
|
-
1. **Workspace / link** (if in a monorepo or same parent repo):
|
|
89
|
-
- Add in the app’s `package.json`: `"@quickscores/chat": "file:../chat"` (or your path).
|
|
90
|
-
- In this repo, run `npm run build` so `dist/` is present (the package entry point is the built output).
|
|
91
|
-
- Then: `import { threadSchema, type Thread, type Message, type ThreadListRow } from "@quickscores/chat";`
|
|
92
|
-
- REST request/response types: `CreateThreadBody`, `SendMessageBody`, `ThreadResponse`, `MessageResponse`, `ErrorResponse`, etc. (see `src/types/api.ts`).
|
|
93
|
-
2. **From a registry**: Publish the types package (see below), then add `"@quickscores/chat": "^0.1.0"` and run `npm install`.
|
|
94
|
-
|
|
95
|
-
Types are aligned with the Supabase schema and [docs/api-chat.md](docs/api-chat.md): `Thread` (chat_threads), `Message` (chat_messages), `ThreadListRow` (chat_thread_list view).
|
|
96
|
-
|
|
97
|
-
### Publishing the types package to a registry
|
|
98
|
-
|
|
99
|
-
The entire `src/` tree is built to `dist/` and only `dist/` is published (`"files": ["dist"]`). Supabase config, migrations, Edge Functions, scripts, and docs are not included in the tarball.
|
|
100
|
-
|
|
101
|
-
1. **Build**: `npm run build` (or it runs automatically via `prepublishOnly` when you publish).
|
|
102
|
-
2. **Allow publishing**: In `package.json`, set `"private": false` (or remove the `"private"` field).
|
|
103
|
-
3. **Publish to npm** (see [Publishing to npm](#publishing-to-npm) below).
|
|
104
|
-
|
|
105
|
-
Consumers then install with `"@quickscores/chat": "^0.1.0"` and import as before; they get types and Zod runtime from the published tarball only.
|
|
106
|
-
|
|
107
|
-
#### Publishing to npm
|
|
108
|
-
|
|
109
|
-
1. **Create the scope** (one-time): [npmjs.com/org/create](https://www.npmjs.com/org/create) and create the `quickscores` org (or use an existing org that will own the package).
|
|
110
|
-
|
|
111
|
-
2. **Log in** (if you aren’t already):
|
|
112
|
-
```bash
|
|
113
|
-
npm login
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
3. **Allow publishing**: In `package.json`, set `"private": false` (or remove the `"private"` field).
|
|
117
|
-
|
|
118
|
-
4. **Publish** (build runs automatically via `prepublishOnly`):
|
|
119
|
-
```bash
|
|
120
|
-
npm publish --access public
|
|
121
|
-
```
|
|
122
|
-
Scoped packages (`@quickscores/chat`) are private by default; `--access public` makes them installable by anyone without a paid plan.
|
|
123
|
-
|
|
124
|
-
After that, anyone can run `npm install @quickscores/chat` with no extra config or tokens.
|
|
125
|
-
|
|
126
|
-
## Project layout
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
chat/
|
|
130
|
-
├── supabase/
|
|
131
|
-
│ ├── config.toml # Local Supabase config
|
|
132
|
-
│ ├── migrations/ # SQL migrations (chat tables, RLS)
|
|
133
|
-
│ ├── functions/ # Edge Functions (chat REST API)
|
|
134
|
-
│ └── seed.sql # Optional seed data
|
|
135
|
-
├── src/
|
|
136
|
-
│ └── types/ # Shared TypeScript + Zod (Thread, Message, ThreadListRow, REST API types)
|
|
137
|
-
├── docs/
|
|
138
|
-
│ ├── prd/ # Product requirements
|
|
139
|
-
│ └── api-chat.md # Chat REST API reference
|
|
140
|
-
├── package.json
|
|
141
|
-
├── tsconfig.json
|
|
142
|
-
└── README.md
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Chat REST API
|
|
146
|
-
|
|
147
|
-
We do **not** use Postgres RPCs for chat. The API is implemented as **REST HTTP endpoints** using Supabase Edge Functions: each action (get/create thread, send message, mark read) is a separate Edge Function. Clients use normal HTTP (e.g. `fetch` or `axios`).
|
|
148
|
-
|
|
149
|
-
- **Docs:** [docs/api-chat.md](docs/api-chat.md)
|
|
150
|
-
- **Endpoints:** `POST /functions/v1/chat-thread` (get/create thread), `chat-league-room`, `chat-team-room`, `chat-send-message`, `chat-mark-read`
|
|
151
|
-
- **Auth:** Not enforced yet; use header `X-User-Id` (or body `user_id`) to identify the caller. Add JWT auth later.
|
|
31
|
+
- **Domain types:** `Thread`, `ThreadKind`, `ThreadListRow`, `Message` — use with the matching Zod schemas for validation.
|
|
32
|
+
- **API types:** `CreateThreadBody`, `LeagueRoomBody`, `TeamRoomBody`, `SendMessageBody`, `MarkReadBody`, `ThreadResponse`, `MessageResponse`, `MarkReadResponse`, `ErrorResponse` — for request/response typing.
|
|
152
33
|
|
|
153
|
-
|
|
34
|
+
Types and schemas stay in sync with the chat backend and [API docs](https://github.com/quickscores/App2.0-Chat/blob/main/docs/api-chat.md) in the source repo.
|
|
154
35
|
|
|
155
|
-
##
|
|
36
|
+
## Repository
|
|
156
37
|
|
|
157
|
-
|
|
158
|
-
2. In the RN/app, call the chat endpoints and use types from `@quickscores/chat` (see [docs/api-chat.md](docs/api-chat.md)).
|
|
38
|
+
Source and backend docs: [github.com/quickscores/App2.0-Chat](https://github.com/quickscores/App2.0-Chat). If you’re developing this package or the chat service, see [DEVELOPING.md](https://github.com/quickscores/App2.0-Chat/blob/main/DEVELOPING.md) in the repo.
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quickscores/chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared chat types and Zod schemas for QuickScores (RN, web)",
|
|
6
6
|
"main": "./dist/types/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
|
8
|
-
"files": [
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
9
11
|
"scripts": {
|
|
10
12
|
"build": "tsc -p tsconfig.build.json",
|
|
11
13
|
"prepublishOnly": "npm run build",
|