u
This commit is contained in:
@@ -345,6 +345,7 @@ Clients subscribe via [`GET /events`](routes/events.md) (`text/event-stream`). A
|
||||
| `shipping` | `POST /stock/ship` |
|
||||
| `stock` | `DELETE /shipment/{id}`, `POST /stock/accept`, `POST /stock/adjust`, `POST /stock/ship` |
|
||||
| `subagentschedule` | `POST /subagentschedule`, `DELETE /subagentschedule/{id}`, `PUT /subagentschedule/{id}` |
|
||||
| `user` | `PUT /auth/selected-company`, `POST /company`, `DELETE /company/{id}` |
|
||||
| `vfs` | `POST /vfs/applets/restore`, `POST /vfs/mkdir`, `POST /vfs/rename`, `POST /vfs/skills/restore`, `POST /vfs/upload`, `DELETE /vfs/{*path}`, `POST /vfs/{*path}`, `PUT /vfs/{*path}` |
|
||||
| `warehouse` | `POST /warehouse`, `PUT /warehouse/order`, `DELETE /warehouse/{id}`, `PUT /warehouse/{id}` |
|
||||
|
||||
|
||||
@@ -478,6 +478,7 @@ _none_
|
||||
- Returns: `200 SSE`
|
||||
|
||||
- Events:
|
||||
- `user`: `{ selectedCompanyId }`
|
||||
- `company`: `{ companyId }`
|
||||
- `category`: `{}`
|
||||
- `articles`: `{}`
|
||||
|
||||
@@ -20,7 +20,7 @@ Sets the authenticated user's selected company.
|
||||
|
||||
## Signals
|
||||
|
||||
On success, emits SSE signal: `company` (see [`GET /events`](../events.md)).
|
||||
On success, emits SSE signals: `user`, `company` (see [`GET /events`](../events.md)).
|
||||
|
||||
## Response `200`
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ Creates a company and selects it for the current user.
|
||||
|
||||
## Signals
|
||||
|
||||
On success, emits SSE signal: `company` (see [`GET /events`](../events.md)).
|
||||
On success, emits SSE signals: `user`, `company` (see [`GET /events`](../events.md)).
|
||||
|
||||
## Response `201`
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Deletes a company.
|
||||
|
||||
## Signals
|
||||
|
||||
On success, emits SSE signal: `company` (see [`GET /events`](../events.md)).
|
||||
On success, emits SSE signals: `user`, `company` (see [`GET /events`](../events.md)).
|
||||
|
||||
## Response `204`
|
||||
|
||||
|
||||
@@ -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