u
This commit is contained in:
@@ -6,8 +6,9 @@ Subscribe to update signals (SSE)
|
||||
|
||||
Opens a Server-Sent Events stream for the authenticated user.
|
||||
Can be opened before a company is selected (`selectedCompanyId == null`);
|
||||
when a company is selected or changed, the stream receives a `company`
|
||||
event (`{ companyId }`) and updates its company scope in-place.
|
||||
when a company is selected or changed, the stream receives `user`
|
||||
(`{ selectedCompanyId }`) and `company` (`{ companyId }`) events and
|
||||
updates its company scope in-place.
|
||||
Clients also receive named signals when another request successfully
|
||||
mutates shared data for the active company (including the same
|
||||
browser's other tabs).
|
||||
@@ -16,6 +17,7 @@ Use `EventSource` with credentials so the session cookie is sent:
|
||||
|
||||
```js
|
||||
const es = new EventSource('https://…/api/events', { withCredentials: true });
|
||||
es.addEventListener('user', () => { refetchAuthMe(); });
|
||||
es.addEventListener('company', () => { refetchCompany(); });
|
||||
es.addEventListener('category', () => { refetchCategoryTree(); });
|
||||
es.addEventListener('articles', () => { refetchArticleIndex(); });
|
||||
@@ -27,11 +29,13 @@ Keep-alive comments (`: heartbeat`) are sent roughly every 20s.
|
||||
## Signals
|
||||
|
||||
Every SSE event uses the event name as the signal id; payloads are
|
||||
JSON and most events send an empty object `{}`. `company` emits
|
||||
`{ companyId }` and `brand` emits `{ sender, brandId }`.
|
||||
JSON and most events send an empty object `{}`. `user` emits
|
||||
`{ selectedCompanyId }`, `company` emits `{ companyId }`, and `brand`
|
||||
emits `{ sender, brandId }`.
|
||||
|
||||
| Signal | Payload | Emitted after successful |
|
||||
|--------|---------|--------------------------|
|
||||
| `user` | `{ selectedCompanyId }` | `PUT /auth/selected-company`, `POST /company`, `DELETE /company/{id}` |
|
||||
| `company` | `{ companyId }` | `PUT /auth/selected-company`, `POST /company`, `PUT /company/{id}`, `DELETE /company/{id}` |
|
||||
| `category` | `{}` | `POST /category`, `PATCH /category/{id}`, `PUT /category/order`, `DELETE /category/{id}`, `POST /category/{id}/image`, `DELETE /category/{id}/image`, `PUT /category/{id}/property` |
|
||||
| `articles` | `{}` | `POST /article`, `PATCH /article/{sku}`, `DELETE /article/{sku}`, `PUT /article/{sku}/articles`-style list-level changes, `POST /category/{id}/article` and related article-assigning category mutations |
|
||||
@@ -63,7 +67,8 @@ runtime (for example `article-42000045` and `modelconversation-123`).
|
||||
|
||||
SSE stream (`text/event-stream`). Each signal is an SSE event
|
||||
whose name is the signal id. Most signals send `{}` as data;
|
||||
`company` sends `{ "companyId": 1 }` and `brand` sends
|
||||
`user` sends `{ "selectedCompanyId": 1 }`, `company` sends
|
||||
`{ "companyId": 1 }`, and `brand` sends
|
||||
`{ "sender": "<x-client-id>", "brandId": 12 }`.
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user