|
|
|
|
@@ -4,32 +4,35 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
|
|
|
|
|
|
|
|
|
|
Subscribe to update signals (SSE)
|
|
|
|
|
|
|
|
|
|
Opens a Server-Sent Events stream for the authenticated user's
|
|
|
|
|
**selected company**. Clients receive named signals when another
|
|
|
|
|
request successfully mutates shared data for that company
|
|
|
|
|
(including the same browser's other tabs).
|
|
|
|
|
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.
|
|
|
|
|
Clients also receive named signals when another request successfully
|
|
|
|
|
mutates shared data for the active company (including the same
|
|
|
|
|
browser's other tabs).
|
|
|
|
|
|
|
|
|
|
Use `EventSource` with credentials so the session cookie is sent:
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const es = new EventSource('https://…/api/events', { withCredentials: true });
|
|
|
|
|
es.addEventListener('company', () => { refetchCompany(); });
|
|
|
|
|
es.addEventListener('category', () => { refetchCategoryTree(); });
|
|
|
|
|
es.addEventListener('articles', () => { refetchArticleIndex(); });
|
|
|
|
|
es.addEventListener('article-42000045', () => { refetchArticle('42000045'); });
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Keep-alive comments (`: heartbeat`) are sent roughly every 20s.
|
|
|
|
|
Reconnect after changing the selected company (the stream is bound
|
|
|
|
|
to the company at connect time).
|
|
|
|
|
|
|
|
|
|
## Signals
|
|
|
|
|
|
|
|
|
|
Every SSE event uses the event name as the signal id; payloads are
|
|
|
|
|
JSON and most events send an empty object `{}`. Only `brand` emits a
|
|
|
|
|
richer payload.
|
|
|
|
|
JSON and most events send an empty object `{}`. `company` emits
|
|
|
|
|
`{ companyId }` and `brand` emits `{ sender, brandId }`.
|
|
|
|
|
|
|
|
|
|
| Signal | Payload | Emitted after successful |
|
|
|
|
|
|--------|---------|--------------------------|
|
|
|
|
|
| `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 |
|
|
|
|
|
| `article-<sku>` | `{}` | `PUT /article/{sku}/weight`, `PUT /article/{sku}/prices`, `PUT /article/{sku}/eans`, `PUT /article/{sku}/categories`, `PUT /article/{sku}/brand`, `PUT /article/{sku}/images/order`, `POST /article/{sku}/image`, `DELETE /article/{sku}/image/{fullHash}`, supplier/article-property mutations affecting the article |
|
|
|
|
|
@@ -60,14 +63,14 @@ 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;
|
|
|
|
|
`brand` sends `{ "sender": "<x-client-id>", "brandId": 12 }`.
|
|
|
|
|
`company` sends `{ "companyId": 1 }` and `brand` sends
|
|
|
|
|
`{ "sender": "<x-client-id>", "brandId": 12 }`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Errors
|
|
|
|
|
|
|
|
|
|
| Status | Description |
|
|
|
|
|
|--------|-------------|
|
|
|
|
|
| 400 | No company selected — `{"error":"…"}` |
|
|
|
|
|
| 401 | Unauthorized — `{"error":"…"}` |
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|