Add article history by SKU and SSE update signals for live clients.

Expose getHistoryBySku as GET /article/:sku/history, and document mutation-emitted company signals via GET /events.
This commit is contained in:
seb
2026-08-05 09:54:56 +02:00
parent 4a9403bfd1
commit 782c49a680
28 changed files with 757 additions and 2 deletions

View File

@@ -20,6 +20,10 @@ Auth like GET by SKU.
Raw binary (`image/avif`).
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `201`
Image stored and linked

View File

@@ -15,6 +15,10 @@ Creates an article under an authorized category (`parentId`).
}
```
## Signals
On success, emits SSE signal: `articles` (see [`GET /events`](../events.md)).
## Response `201`
Created

View File

@@ -13,6 +13,10 @@ Removes `articlepic` and the `pic` row for this article (`fullHash`). Auth like
| `sku` | yes | string | |
| `fullHash` | yes | string | |
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `204`
Deleted

View File

@@ -15,6 +15,10 @@ Auth like GET by SKU.
|-------|----------|------|-------------|
| `sku` | yes | string | Article SKU |
## Signals
On success, emits SSE signal: `articles` (see [`GET /events`](../events.md)).
## Response `204`
Deleted

View File

@@ -0,0 +1,49 @@
# `GET /article/{sku}/history`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Get article history by SKU
Returns `articlehistory` rows for the article, newest first (`date` DESC, `id` DESC).
Auth like GET by SKU.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `sku` | yes | string | Article SKU |
## Response `200`
Article history (newest first)
```json
{
"history": [
{
"id": 42,
"date": "2026-08-05T07:15:00.000Z",
"text": "Name geändert von \"Tee\" auf \"Grüner Tee\"\nEinheit geändert von \"500g\" auf \"1kg\""
},
{
"id": 41,
"date": "2026-08-01T09:00:00.000Z",
"text": "Name geändert von \"\" auf \"Tee\""
}
]
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Missing sku — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Article not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -25,6 +25,10 @@ Sets `articlepic.sort` to `0..n-1` in the given order.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
New order

View File

@@ -22,6 +22,10 @@ Pass `null` to clear the brand. Returns the same shape as GET by SKU.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -26,6 +26,10 @@ article from all categories. Returns the same shape as GET by SKU.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -24,6 +24,10 @@ empty array clears all EANs. Returns the same shape as GET by SKU.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -33,6 +33,10 @@ Empty `prices` clears all POS prices. Returns the same shape as GET by SKU.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -22,6 +22,10 @@ Returns the same shape as GET by SKU.
}
```
## Signals
On success, emits SSE signal: `article-<sku>` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -23,6 +23,10 @@ Patches article fields. At least one of `name`, `unitamount`, `unitSi` required.
}
```
## Signals
On success, emits SSE signal: `articles` (see [`GET /events`](../events.md)).
## Response `200`
Updated article detail

View File

@@ -20,6 +20,10 @@ Auth like GET /category/tree — user must be authorized for the category's comp
Raw binary (`image/avif`).
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `201`
Image stored and linked

View File

@@ -15,6 +15,10 @@ Creates a category under an authorized parent.
}
```
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `201`
Created

View File

@@ -14,6 +14,10 @@ Auth like GET /category/tree — user must be authorized for the category's comp
|-------|----------|------|-------------|
| `id` | yes | integer | Category id |
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `200`
Image removed

View File

@@ -12,6 +12,10 @@ Deletes a category the user is authorized for (not the company root).
|-------|----------|------|-------------|
| `id` | yes | integer | Category id |
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `204`
Deleted

View File

@@ -24,6 +24,10 @@ to its index `0..n-1` in one transaction.
}
```
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `200`
New sibling order

View File

@@ -24,6 +24,10 @@ Either `name` or `parentId` (or both) is required.
}
```
## Signals
On success, emits SSE signal: `category` (see [`GET /events`](../events.md)).
## Response `200`
Updated category (renamed and/or moved)

53
docs/api/routes/events.md Normal file
View File

@@ -0,0 +1,53 @@
# `GET /events`
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).
Use `EventSource` with credentials so the session cookie is sent:
```js
const es = new EventSource('https://…/api/events', { withCredentials: true });
es.addEventListener('category', () => { refetchCategoryTree(); });
es.addEventListener('articles', () => { refetchArticleIndex(); });
es.addEventListener('article-42000045', () => { refetchArticle('42000045'); });
```
Keep-alive comments (`: keepalive`) are sent roughly every 25s.
Reconnect after changing the selected company (the stream is bound
to the company at connect time).
## Signals
| Signal | Emitted after successful |
|--------|--------------------------|
| `category` | `POST /category`, `PATCH /category/{id}`, `PUT /category/order`, `DELETE /category/{id}`, `POST /category/{id}/image`, `DELETE /category/{id}/image` |
| `articles` | `POST /article`, `PATCH /article/{sku}`, `DELETE /article/{sku}` |
| `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}` |
Signals are only sent when the mutation actually succeeds (2xx).
Failed or no-op validation errors do not emit. The `article-<sku>`
event name uses the concrete SKU (e.g. `article-42000045`).
## Response `200`
SSE stream (`text/event-stream`). Each signal is an SSE event
whose name is the signal id and whose data is `{}`.
## Errors
| Status | Description |
|--------|-------------|
| 400 | No company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._