Expose getHistoryBySku as GET /article/:sku/history, and document mutation-emitted company signals via GET /events.
6.3 KiB
6.3 KiB
Dash API
http://localhost:4208/api
CORS & cookies
All browser requests that need auth must send cookies:
fetch('http://localhost:4208/api/auth/me', {
credentials: 'include',
});
Sessions use an HTTP-only token cookie (Secure, SameSite=Strict, 24h). The browser must talk to the API over HTTPS for login to work — Secure cookies are not sent on plain HTTP.
Auth flow
- Call
GET /auth/meto getgoogleClientId(included in 200 and 401 responses). - Sign in with Google on the frontend (Google Identity Services / One Tap).
- POST the Google ID token to
POST /auth/login. - The API sets the session cookie.
- Call protected routes with
credentials: 'include'. The cookie is refreshed automatically when it has less than 2 hours left.
Routes
Generated from @openapi annotations in src/api/routes/. Source of truth is the code; regenerate with npm run docs:api.
Machine-readable spec: openapi.json.
Signals (SSE)
Clients subscribe via GET /events (text/event-stream). After a successful mutation, the API emits a named SSE event (signal) to subscribers of the same selected company.
| Signal | Emitted by |
|---|---|
article-<sku> |
PUT /article/{sku}/brand, PUT /article/{sku}/categories, PUT /article/{sku}/eans, POST /article/{sku}/image, DELETE /article/{sku}/image/{fullHash}, PUT /article/{sku}/images/order, PUT /article/{sku}/prices, PUT /article/{sku}/weight |
articles |
POST /article, DELETE /article/{sku}, PATCH /article/{sku} |
category |
POST /category, PUT /category/order, DELETE /category/{id}, PATCH /category/{id}, DELETE /category/{id}/image, POST /category/{id}/image |
DESIGN
- for every route we have a file in /src/api/routes
- that should loosly bound to services in /src/services
- for every service we have a CLI tester in /scripts/
- all DB SQL code shall be in /src/db
- with mssql staements in /src/db/mssql/
- API docs:
@openapiJSDoc on handlers →npm run docs:api→docs/api/