diff --git a/CLAUDE.md b/CLAUDE.md index cb86bf3..1020b68 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -164,6 +164,8 @@ await this.fileHarborService.uploadImageIfProvided(file, 'article', externalId, Supported types: JPEG, PNG, GIF, WebP (max 10 MB). `deleteImageSafely()` silently ignores 404s. +HTTP goes through `FileHarborClient` (`@heyatom/client/fileharbor`), one per call since the config is per tenant (not the global Nest module); FileHarbor answers `{ data }`, read `.data`. Validation, endpoint check, id extraction and "404 = already deleted" stay in `FileHarborService`. The client gets `fileHarborFetch`: no redirects (`redirect: 'manual'`, so the tenant key never follows a `Location`) and 1 MB max response body. + ### Scheduled Jobs | Job | Schedule | Purpose | @@ -185,7 +187,7 @@ Validation runs at startup via Joi (`src/configs/config.validation.ts`) — the Key runtime settings — the HTTP runtime is `@heyatom/nest-common` (platform standard `../docs/standards/api.md`); don't re-add local copies: - Bootstrap: `setupHttpApp` in `main.ts` — shutdown hooks, `trust proxy` = `TRUST_PROXY_HOPS`, helmet, CORS allowlist `CORS_ORIGINS` (`X-API-Key`/`X-User-Id` deliberately **not** in `allowedHeaders`), JSON 1mb, global `ValidationPipe` (`whitelist`, `forbidNonWhitelisted`, `transform`). The urlencoded limit (256kb) is set right after it. Old `CORS_ORIGIN` / `TRUST_PROXY=true` are still read as defaults. - Errors: `AllExceptionsFilter` (`APP_FILTER`) → `{ statusCode, code, message, errors?, requestId }`. Domain errors declare an `UPPER_SNAKE` `code` (`throw new ConflictException({ code: 'SLUG_TAKEN', message })`); consumers branch on `code`, never on `message`. P2002 → 409, P2003 → 409, P2025 → 404 globally; anything non-HTTP → generic 500. -- **No `TransformInterceptor`**: responses are raw resources (no `{ data }` envelope) until the coordinated phase-3 migration with heyatom-client, dbdbuilds-api and Meridian. +- **Envelope**: global `TransformInterceptor` (`APP_INTERCEPTOR`) wraps every 2xx JSON body in `{ data }`; a `paginate()` page passes through as `{ data, meta }` (recognized by its marker: rebuild a mapped page with `markPaginated`, never a bare spread). No `@NoTransform()` endpoint today. Document with `ApiOkData` / `ApiCreatedData` / `ApiPaginatedResponse`, never `@ApiOkResponse({ type })` (that documents the bare DTO). 204s have no body. - Logging: `loggerParams` (nestjs-pino), server-generated `X-Request-Id` on every response, `ip` kept on the request line; `LOG_LEVEL` default info in production, debug elsewhere. - API docs: `GET /docs` only with `ENABLE_SWAGGER` (unset = on only for an explicit `NODE_ENV` development/test). `SWAGGER_OPTIONS` (`src/common/swagger.ts`) is shared with `pnpm openapi:dump`. - Pagination: `PageParams` / `paginate()` / `ApiPaginatedResponse` from the package. diff --git a/app_logo.png b/app_logo.png index 0d48847..4d7d7bc 100644 Binary files a/app_logo.png and b/app_logo.png differ diff --git a/docs/brand/README.md b/docs/brand/README.md new file mode 100644 index 0000000..2205b0f --- /dev/null +++ b/docs/brand/README.md @@ -0,0 +1,92 @@ +# Articuno — logo e uso + +## 1. Il logo + +- **Idea**: un **pennino** con la punta in alto, e il pennino è una **A**. Il taglio e il foro di + sfiato sono la controforma della A, i piedi aperti sono le sue gambe. Articuno è dove si scrive: + articoli, traduzioni, commenti. +- **Versioni**: lockup orizzontale (simbolo + wordmark) · simbolo · simbolo *small* (≤ 48 px: + taglio più largo, controforma e piedi più grandi, riempie il canvas). +- **Costruzione**: canvas 256. Punta a y 32, fianchi a 60° fino alle spalle (y 156, larghezza + 143), poi la vita rientra a 15° fino alla base (y 216, larghezza 111). Controforma: triangolo a + 60° (punta y 100, base y 146), lati paralleli ai fianchi, quindi le gambe hanno spessore + costante. Taglio largo 8, dalla punta fino alla controforma, senza gradino. Piedi: tetto a 30° + (come le pieghe di Herald), largo 36, fianchi interni a 15°, paralleli alla vita. Il simbolo è + centrato sul canvas e alzato di 2 (centro ottico). +- **Wordmark**: Inter Bold (SIL OFL), tracciato in path, cap height 120, tracking −3, a 48 dal + simbolo e centrato in altezza su di esso, come Herald. Non ribattere il nome con un font. +- **Scartati**: il vecchio logo con le righe nella A (Barlow Condensed) e gli altri concept + esplorati: pilcrow-uccello, pergamena, A ad ala, A a righe, piuma. + +## 2. File + +| File | Uso | +|---|---| +| `articuno-lockup.svg` · `-black` · `-white` · `-orange` · `-orange-dark` | README, documentazione, intestazioni | +| `articuno-symbol.svg` · `-black` · `-white` · `-orange` · `-orange-dark` | simbolo ≥ 48 px | +| `articuno-symbol-small.svg` · `-white` · `-orange` | simbolo 16–48 px (favicon, tab, box Meridian) | +| `articuno-symbol-square.svg` | avatar/social: simbolo all'80 % su 256 | +| `articuno-symbol-app-icon.svg` | tile 22 % di raggio, arancio, simbolo inchiostro | +| `articuno-symbol-favicon.svg` | favicon vettoriale (taglio small): nero su chiaro, bianco su scuro (`prefers-color-scheme`) | +| `articuno-stream-deck-orange.svg` · `-dark` · `stream-deck/` | tasto Stream Deck: full bleed 288, simbolo al 60 %; PNG 288 e 144 in `stream-deck/` | +| `png/` | lockup nero e arancio a 1000 px, simboli a 512 px, trasparenti | +| `web/` | `favicon.ico` (16/32/48) e `favicon-*.png` dal tile con il taglio small, `apple-touch-icon.png` (full bleed), `icon-192/512.png` | +| `../../app_logo.png` | lockup bianco su trasparente per il README | +| `generate.py` | rigenera tutto: `uv run --no-project --with fonttools --with skia-pathops --with resvg-py python generate.py .` (font da `google/fonts`, `ofl/inter`; serve `magick` per il `.ico`) | + +Si modifica `generate.py`, non gli SVG a mano: pennino, controforma e piedi sono definiti una volta +sola lì. + +Gli SVG attuali sono generati con Inter 3.018 (variabile `wght`, senza asse `opsz`). Con l'Inter 4 +di `google/fonts` lo script istanzia `opsz 32` come Herald: rigenerare con quello per avere lo +stesso disegno delle lettere. + +`` per le icone web: + +```html + + + +``` + +## 3. Spazio e dimensioni minime + +- **Spazio libero**: tutt'intorno almeno l'altezza della controforma (46 su 256, ≈ 18 % del + simbolo). Scala con il logo. +- **Minimi**: lockup 200 px di larghezza (il simbolo resta ≥ 48 px) · simbolo 48 px (sotto, il + taglio da 8 si chiude) · sotto 48 px il taglio *small* (16 px è il minimo: si leggono la A e il + pennino, il taglio diventa una riga di un pixel). + +## 4. Colore + +| Nome | HEX | RGB | Uso | +|---|---|---|---| +| Arancio | `#E27A43` | 226 122 67 | accento Articuno in Meridian (`[data-svc="articuno"]`), marchio su scuro, tile app e Stream Deck | +| Arancio scuro | `#BE551D` | 190 85 29 | marchio su fondi chiari (4,66:1 su bianco, AA) | +| Inchiostro | `#111111` | 17 17 17 | nero, e il marchio sul tile arancio | +| Bianco | `#FFFFFF` | | su scuro | + +Abbinamenti approvati: nero su bianco · arancio scuro su chiaro · inchiostro su arancio (6,4:1) · +arancio su scuro (`#272B33` 4,8:1, `#0d1117` 6,4:1). Un solo colore per volta: mai gradienti, +ombre, contorni. L'arancio `#E27A43` su bianco (2,96:1) non va: su chiaro si usa l'arancio scuro. +Il bianco sull'arancio (2,96:1) non va: sul tile il pennino è in inchiostro, come scrive. + +**Box servizio in Meridian** (`ShellServiceCard`, 44 px): resta il box `.svc-logo--articuno` +(`rgba(226,122,67,0.18)`, bordo `rgba(226,122,67,0.34)`, colore `#E27A43`), simbolo *small* a +22 px come Herald (`meridian/app/components/shell/ArticunoGlyph.vue`, path copiato da +`articuno-symbol-small.svg`). + +## 5. Non fare + +Non deformare · non ruotare · non chiudere il taglio o staccarlo dalla controforma · non chiudere i +piedi (senza gambe il pennino diventa una casetta) · non rimettere le righe nella A · non +ridisporre simbolo e wordmark · non usare il simbolo *small* sopra 48 px · non ricolorare fuori +palette · non mettere su sfondi mossi senza il tile. + +## 6. Verifiche fatte + +Scala 16–512 px, favicon 16/32/48, nero su bianco, arancio su `#272B33`, arancio scuro su bianco, +tile app e Stream Deck, glyph a 22 px nel box Meridian accanto a quello di Herald, `svg_audit` (un +colore, niente testo vivo, margini simmetrici). Concept confrontati: pilcrow-uccello, pergamena +con la A, A ad ala, A a righe (gamba o intera), piuma. Nessuna ricerca di marchio: prima di un uso +pubblico fuori HeyAtom, verificare. diff --git a/docs/brand/articuno-lockup-black.svg b/docs/brand/articuno-lockup-black.svg new file mode 100644 index 0000000..9158c2e --- /dev/null +++ b/docs/brand/articuno-lockup-black.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-lockup-orange-dark.svg b/docs/brand/articuno-lockup-orange-dark.svg new file mode 100644 index 0000000..80be185 --- /dev/null +++ b/docs/brand/articuno-lockup-orange-dark.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-lockup-orange.svg b/docs/brand/articuno-lockup-orange.svg new file mode 100644 index 0000000..6924c8d --- /dev/null +++ b/docs/brand/articuno-lockup-orange.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-lockup-white.svg b/docs/brand/articuno-lockup-white.svg new file mode 100644 index 0000000..d9dfdc6 --- /dev/null +++ b/docs/brand/articuno-lockup-white.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-lockup.svg b/docs/brand/articuno-lockup.svg new file mode 100644 index 0000000..8f7da45 --- /dev/null +++ b/docs/brand/articuno-lockup.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-stream-deck-dark.svg b/docs/brand/articuno-stream-deck-dark.svg new file mode 100644 index 0000000..61bdf88 --- /dev/null +++ b/docs/brand/articuno-stream-deck-dark.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-stream-deck-orange.svg b/docs/brand/articuno-stream-deck-orange.svg new file mode 100644 index 0000000..d6cd608 --- /dev/null +++ b/docs/brand/articuno-stream-deck-orange.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-app-icon.svg b/docs/brand/articuno-symbol-app-icon.svg new file mode 100644 index 0000000..c0f52b5 --- /dev/null +++ b/docs/brand/articuno-symbol-app-icon.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-black.svg b/docs/brand/articuno-symbol-black.svg new file mode 100644 index 0000000..a06817c --- /dev/null +++ b/docs/brand/articuno-symbol-black.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-favicon.svg b/docs/brand/articuno-symbol-favicon.svg new file mode 100644 index 0000000..0480d5c --- /dev/null +++ b/docs/brand/articuno-symbol-favicon.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-orange-dark.svg b/docs/brand/articuno-symbol-orange-dark.svg new file mode 100644 index 0000000..01e6e62 --- /dev/null +++ b/docs/brand/articuno-symbol-orange-dark.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-orange.svg b/docs/brand/articuno-symbol-orange.svg new file mode 100644 index 0000000..171054a --- /dev/null +++ b/docs/brand/articuno-symbol-orange.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-small-orange.svg b/docs/brand/articuno-symbol-small-orange.svg new file mode 100644 index 0000000..75060a8 --- /dev/null +++ b/docs/brand/articuno-symbol-small-orange.svg @@ -0,0 +1 @@ +Articuno (small sizes) diff --git a/docs/brand/articuno-symbol-small-white.svg b/docs/brand/articuno-symbol-small-white.svg new file mode 100644 index 0000000..d86123c --- /dev/null +++ b/docs/brand/articuno-symbol-small-white.svg @@ -0,0 +1 @@ +Articuno (small sizes) diff --git a/docs/brand/articuno-symbol-small.svg b/docs/brand/articuno-symbol-small.svg new file mode 100644 index 0000000..f94d5a1 --- /dev/null +++ b/docs/brand/articuno-symbol-small.svg @@ -0,0 +1 @@ +Articuno (small sizes) diff --git a/docs/brand/articuno-symbol-square.svg b/docs/brand/articuno-symbol-square.svg new file mode 100644 index 0000000..6a7c032 --- /dev/null +++ b/docs/brand/articuno-symbol-square.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol-white.svg b/docs/brand/articuno-symbol-white.svg new file mode 100644 index 0000000..c877e42 --- /dev/null +++ b/docs/brand/articuno-symbol-white.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/articuno-symbol.svg b/docs/brand/articuno-symbol.svg new file mode 100644 index 0000000..07499dc --- /dev/null +++ b/docs/brand/articuno-symbol.svg @@ -0,0 +1 @@ +Articuno diff --git a/docs/brand/generate.py b/docs/brand/generate.py new file mode 100644 index 0000000..c1bfce6 --- /dev/null +++ b/docs/brand/generate.py @@ -0,0 +1,174 @@ +"""Articuno brand kit generator. + +Usage: uv run --no-project --with fonttools --with skia-pathops --with resvg-py \ + python generate.py +Font: Inter (SIL OFL), google/fonts ofl/inter. Variable fonts are instanced at wght 700 +(and opsz 32 when the axis exists, as Herald). Needs `magick` for favicon.ico. +""" +import os, sys, subprocess +import pathops, resvg_py +from fontTools.ttLib import TTFont +from fontTools.varLib import instancer +from fontTools.pens.svgPathPen import SVGPathPen +from fontTools.pens.transformPen import TransformPen +from fontTools.svgLib.path import parse_path + +FONT, OUT = sys.argv[1], sys.argv[2] +for sub in ("", "png", "web", "stream-deck"): + os.makedirs(os.path.join(OUT, sub), exist_ok=True) + +INK, WHITE = "#111111", "#ffffff" +ORANGE = "#E27A43" # Meridian accent [data-svc="articuno"]: mark on dark, tile +ORANGE_DARK = "#BE551D" # mark on light grounds (4.66:1 on white) +DARK = "#0d1117" + +# ── Geometry helpers (pathops = Skia boolean ops) ─────────────────────── +def P(d): + p = pathops.Path() + parse_path(d, p.getPen()) + return p + +U, D = pathops.PathOp.UNION, pathops.PathOp.DIFFERENCE +op = pathops.op + +def poly(*pts): + return P("M" + "L".join(f"{x:.3f} {y:.3f}" for x, y in pts) + "Z") + +def xf(path, m): + out = pathops.Path() + path.draw(TransformPen(out.getPen(), m)) + return out + +def d(path): + pen = SVGPathPen(None, ntos=lambda v: f"{v:.2f}".rstrip("0").rstrip(".")) + path.draw(pen) + return pen.getCommands() + +T60, T30, T15 = 1.73205, 0.57735, 0.26795 # tan 60°, 30°, 15° + +# ── Symbol: a pen nib pointing up; slit + breather hole are the A's counter ── +# Outer point and counter are 60° triangles (parallel sides → even legs); the waist +# tapers in at 15° to the base like a real nib; the feet open under a 30° roof and +# splay at 15° (parallel to the waist, so the legs keep an even width) +# (the crossbar is the band between counter and roof). +def nib(small=False): + apex, shoulder, base = 32, 156, 216 + if small: # ≤ 48 px: wider slit, bigger counter, wider feet + c_apex, c_base, slit, feet, roof = 96, 146, 12, 22, 196 + else: + c_apex, c_base, slit, feet, roof = 100, 146, 8, 18, 196 + xs = (shoulder - apex) / T60 + waist = xs - (base - shoulder) * T15 + body = poly((128, apex), (128 + xs, shoulder), (128 + waist, base), + (128 - waist, base), (128 - xs, shoulder)) + ch = (c_base - c_apex) / T60 + counter = poly((128, c_apex), (128 + ch, c_base), (128 - ch, c_base)) + cut = poly((128 - slit / 2, apex - 10), (128 + slit / 2, apex - 10), + (128 + slit / 2, c_apex + slit * T60), (128 - slit / 2, c_apex + slit * T60)) # runs into the counter: no ledge + spread = feet + (base + 10 - roof) * T15 # inner leg edges splay at 15°, parallel to the waist + foot = poly((128 - spread, base + 10), (128 - feet, roof), (128, roof - feet * T30), + (128 + feet, roof), (128 + spread, base + 10)) + m = body + for q in (counter, cut, foot): + m = op(m, q, D) + x0, y0, x1, y1 = m.bounds + if small: # fill the canvas: the larger side to 216 + s = 216 / max(x1 - x0, y1 - y0) + m = xf(m, (s, 0, 0, s, 0, 0)) + x0, y0, x1, y1 = m.bounds + return xf(m, (1, 0, 0, 1, 128 - (x0 + x1) / 2, 126 - (y0 + y1) / 2)) # lifted 2 (optical centre) + +def symbol(color, small=False): + return f'' + +# ── Wordmark: Inter Bold in paths, cap height 120, tracking −3 (as Herald) ── +vf = TTFont(FONT) +if "fvar" in vf: + axes = {a.axisTag: a for a in vf["fvar"].axes} + loc = {t: (700 if t == "wght" else 32 if t == "opsz" else a.defaultValue) for t, a in axes.items()} + font = instancer.instantiateVariableFont(vf, loc) +else: + font = vf +gs, cmap = font.getGlyphSet(), font.getBestCmap() +K = 120 / font["OS/2"].sCapHeight + +def wordmark(x, baseline): + out = pathops.Path() + for ch in "Articuno": + g = pathops.Path() + gs[cmap[ord(ch)]].draw(TransformPen(g.getPen(gs), (K, 0, 0, -K, x, baseline))) + out = op(out, g, U) + x += gs[cmap[ord(ch)]].width * K - 3 + return out + +SYM = nib() +_, sy0, sx1, sy1 = SYM.bounds +LOCK = op(SYM, wordmark(sx1 + 48, (sy0 + sy1) / 2 + 60), U) # cap centred on the mark +LX0, LY0, LX1, LY1 = LOCK.bounds +PAD = 40 +LVB = f"0 0 {LX1 - LX0 + 2 * PAD:.0f} {LY1 - LY0 + 2 * PAD:.0f}" + +def lockup(color): + return (f'') + +def svg(vb, body, title="Articuno"): + w, h = vb.split()[2:] + return (f'' + f'{title}{body}\n') + +def tile(size, rx, inset, bg, color, small=False): + s = (size - 2 * inset) / 256 + return (f'' + f'{symbol(color, small)}') + +SMALL = "Articuno (small sizes)" +files = { + "articuno-lockup.svg": svg(LVB, lockup(INK)), + "articuno-lockup-black.svg": svg(LVB, lockup("#000000")), + "articuno-lockup-white.svg": svg(LVB, lockup(WHITE)), + "articuno-lockup-orange.svg": svg(LVB, lockup(ORANGE)), + "articuno-lockup-orange-dark.svg": svg(LVB, lockup(ORANGE_DARK)), + "articuno-symbol.svg": svg("0 0 256 256", symbol(INK)), + "articuno-symbol-black.svg": svg("0 0 256 256", symbol("#000000")), + "articuno-symbol-white.svg": svg("0 0 256 256", symbol(WHITE)), + "articuno-symbol-orange.svg": svg("0 0 256 256", symbol(ORANGE)), + "articuno-symbol-orange-dark.svg": svg("0 0 256 256", symbol(ORANGE_DARK)), + "articuno-symbol-small.svg": svg("0 0 256 256", symbol(INK, True), SMALL), + "articuno-symbol-small-white.svg": svg("0 0 256 256", symbol(WHITE, True), SMALL), + "articuno-symbol-small-orange.svg": svg("0 0 256 256", symbol(ORANGE, True), SMALL), + "articuno-symbol-square.svg": svg("0 0 256 256", f'{symbol(INK)}'), + # ink on orange: the nib writes in ink (white on orange is only 2.96:1) + "articuno-symbol-app-icon.svg": svg("0 0 256 256", tile(256, ' rx="57.6"', 44, ORANGE, INK)), + # adapts to the tab bar: ink on light, white on dark + "articuno-symbol-favicon.svg": svg("16 16 224 224", + '' + f'{symbol("currentColor", True)}'), + "articuno-stream-deck-orange.svg": svg("0 0 288 288", tile(288, "", 58, ORANGE, INK)), + "articuno-stream-deck-dark.svg": svg("0 0 288 288", tile(288, "", 58, DARK, ORANGE)), +} +for name, content in files.items(): + open(os.path.join(OUT, name), "w").write(content) + +def png(src_svg, dst, width): + open(os.path.join(OUT, dst), "wb").write(bytes(resvg_py.svg_to_bytes(svg_string=src_svg, width=width))) + +png(files["articuno-lockup-black.svg"], "png/articuno-lockup-black.png", 1000) +png(files["articuno-lockup-orange.svg"], "png/articuno-lockup-orange.png", 1000) +png(files["articuno-lockup-white.svg"], "../../app_logo.png", 1000) +for v in ("black", "white", "orange"): + png(files[f"articuno-symbol-{v}.svg"], f"png/articuno-symbol-{v}.png", 512) +small_icon = svg("0 0 256 256", tile(256, ' rx="57.6"', 20, ORANGE, INK, True)) # ≤48 px: small cut, bigger in the tile +for n in (16, 32, 48): + png(small_icon, f"web/favicon-{n}.png", n) +icon = files["articuno-symbol-app-icon.svg"] +for n in (192, 512): + png(icon, f"web/icon-{n}.png", n) +png(icon.replace(' rx="57.6"', ""), "web/apple-touch-icon.png", 180) # Apple masks the corners itself +for v in ("orange", "dark"): + for n in (288, 144): + png(files[f"articuno-stream-deck-{v}.svg"], f"stream-deck/articuno-{v}-{n}.png", n) +w = os.path.join(OUT, "web") +subprocess.run(["magick", f"{w}/favicon-16.png", f"{w}/favicon-32.png", f"{w}/favicon-48.png", f"{w}/favicon.ico"], check=True) +print("lockup viewBox", LVB) +print("small path", d(nib(True))) diff --git a/docs/brand/png/articuno-lockup-black.png b/docs/brand/png/articuno-lockup-black.png new file mode 100644 index 0000000..b124a35 Binary files /dev/null and b/docs/brand/png/articuno-lockup-black.png differ diff --git a/docs/brand/png/articuno-lockup-orange.png b/docs/brand/png/articuno-lockup-orange.png new file mode 100644 index 0000000..165449d Binary files /dev/null and b/docs/brand/png/articuno-lockup-orange.png differ diff --git a/docs/brand/png/articuno-symbol-black.png b/docs/brand/png/articuno-symbol-black.png new file mode 100644 index 0000000..973194e Binary files /dev/null and b/docs/brand/png/articuno-symbol-black.png differ diff --git a/docs/brand/png/articuno-symbol-orange.png b/docs/brand/png/articuno-symbol-orange.png new file mode 100644 index 0000000..1d0d5b8 Binary files /dev/null and b/docs/brand/png/articuno-symbol-orange.png differ diff --git a/docs/brand/png/articuno-symbol-white.png b/docs/brand/png/articuno-symbol-white.png new file mode 100644 index 0000000..59f3ac7 Binary files /dev/null and b/docs/brand/png/articuno-symbol-white.png differ diff --git a/docs/brand/stream-deck/articuno-dark-144.png b/docs/brand/stream-deck/articuno-dark-144.png new file mode 100644 index 0000000..0667c24 Binary files /dev/null and b/docs/brand/stream-deck/articuno-dark-144.png differ diff --git a/docs/brand/stream-deck/articuno-dark-288.png b/docs/brand/stream-deck/articuno-dark-288.png new file mode 100644 index 0000000..71a9d3d Binary files /dev/null and b/docs/brand/stream-deck/articuno-dark-288.png differ diff --git a/docs/brand/stream-deck/articuno-orange-144.png b/docs/brand/stream-deck/articuno-orange-144.png new file mode 100644 index 0000000..b429773 Binary files /dev/null and b/docs/brand/stream-deck/articuno-orange-144.png differ diff --git a/docs/brand/stream-deck/articuno-orange-288.png b/docs/brand/stream-deck/articuno-orange-288.png new file mode 100644 index 0000000..0236424 Binary files /dev/null and b/docs/brand/stream-deck/articuno-orange-288.png differ diff --git a/docs/brand/web/apple-touch-icon.png b/docs/brand/web/apple-touch-icon.png new file mode 100644 index 0000000..d8dd1a8 Binary files /dev/null and b/docs/brand/web/apple-touch-icon.png differ diff --git a/docs/brand/web/favicon-16.png b/docs/brand/web/favicon-16.png new file mode 100644 index 0000000..6599297 Binary files /dev/null and b/docs/brand/web/favicon-16.png differ diff --git a/docs/brand/web/favicon-32.png b/docs/brand/web/favicon-32.png new file mode 100644 index 0000000..fc80c5e Binary files /dev/null and b/docs/brand/web/favicon-32.png differ diff --git a/docs/brand/web/favicon-48.png b/docs/brand/web/favicon-48.png new file mode 100644 index 0000000..33af0fb Binary files /dev/null and b/docs/brand/web/favicon-48.png differ diff --git a/docs/brand/web/favicon.ico b/docs/brand/web/favicon.ico new file mode 100644 index 0000000..fb5763a Binary files /dev/null and b/docs/brand/web/favicon.ico differ diff --git a/docs/brand/web/icon-192.png b/docs/brand/web/icon-192.png new file mode 100644 index 0000000..8f38309 Binary files /dev/null and b/docs/brand/web/icon-192.png differ diff --git a/docs/brand/web/icon-512.png b/docs/brand/web/icon-512.png new file mode 100644 index 0000000..a694880 Binary files /dev/null and b/docs/brand/web/icon-512.png differ diff --git a/openapi.json b/openapi.json index ce57947..cafe409 100644 --- a/openapi.json +++ b/openapi.json @@ -22,7 +22,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -219,7 +227,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -274,7 +290,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -357,7 +381,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/BannedWordDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/BannedWordDto" + } + } } } } @@ -528,7 +560,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -587,9 +627,17 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ArticleTranslationSummaryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ArticleTranslationSummaryDto" + } + } } } } @@ -655,7 +703,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -718,7 +774,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -829,7 +893,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/BookmarkToggleResultDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/BookmarkToggleResultDto" + } + } } } } @@ -963,7 +1035,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } } } } @@ -1077,7 +1157,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } } } } @@ -1132,7 +1220,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } } } } @@ -1217,7 +1313,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CommentDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CommentDto" + } + } } } } @@ -1346,7 +1450,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CommentDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CommentDto" + } + } } } } @@ -1389,7 +1501,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CommentDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CommentDto" + } + } } } } @@ -1462,7 +1582,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/LikeToggleResultDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/LikeToggleResultDto" + } + } } } } @@ -1527,7 +1655,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleInteractionStatusDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleInteractionStatusDto" + } + } } } } @@ -1615,7 +1751,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ReportDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ReportDto" + } + } } } } @@ -1807,7 +1951,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ReportDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ReportDto" + } + } } } } @@ -1854,7 +2006,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -1978,7 +2138,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -2033,7 +2201,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -2119,7 +2295,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/UserDto" + } + } } } } @@ -2192,7 +2376,9 @@ "application/json": { "schema": { "example": { - "status": "ok" + "data": { + "status": "ok" + } } } } @@ -2379,7 +2565,16 @@ "post": { "description": "Creates a new article for the session tenant. Accepts either `application/json` (plain body) or `multipart/form-data` (JSON in the `data` field + optional `coverImage` file). Uploaded images are stored in the tenant's FileHarbor instance (JPEG/PNG/GIF/WebP, max 10 MB).", "operationId": "AdminArticlesController_create", - "parameters": [], + "parameters": [ + { + "name": "content-type", + "required": true, + "in": "header", + "schema": { + "type": "string" + } + } + ], "requestBody": { "required": true, "description": "Article data. When using multipart/form-data, serialize the article JSON in the `data` field and optionally attach a `coverImage` file.", @@ -2426,7 +2621,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -2634,7 +2837,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -2671,6 +2882,14 @@ "example": "123e4567-e89b-12d3-a456-426614174000", "type": "string" } + }, + { + "name": "content-type", + "required": true, + "in": "header", + "schema": { + "type": "string" + } } ], "requestBody": { @@ -2719,7 +2938,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleDto" + } + } } } } @@ -2813,7 +3040,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -2862,9 +3097,17 @@ "content": { "application/json": { "schema": { - "type": "array", - "items": { - "$ref": "#/components/schemas/ArticleTranslationSummaryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/ArticleTranslationSummaryDto" + } + } } } } @@ -2920,7 +3163,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -2983,7 +3234,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ArticleTranslationDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ArticleTranslationDto" + } + } } } } @@ -3075,7 +3334,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -3182,7 +3449,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -3227,7 +3502,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/TagDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/TagDto" + } + } } } } @@ -3291,9 +3574,17 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" - } - } + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } + } + } } } }, @@ -3388,7 +3679,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } } } } @@ -3433,7 +3732,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CategoryDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CategoryDto" + } + } } } } @@ -3498,7 +3805,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/BannedWordDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/BannedWordDto" + } + } } } } @@ -3655,7 +3970,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ReportDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ReportDto" + } + } } } } @@ -3837,7 +4160,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ReportDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ReportDto" + } + } } } } @@ -3892,7 +4223,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ReportDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/ReportDto" + } + } } } } @@ -4068,7 +4407,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AuditLogDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/AuditLogDto" + } + } } } } @@ -4232,7 +4579,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserListItemDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/UserListItemDto" + } + } } } } @@ -4323,7 +4678,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserListItemDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/UserListItemDto" + } + } } } } @@ -4462,7 +4825,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CommentDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CommentDto" + } + } } } } @@ -4516,7 +4887,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/CommentDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/CommentDto" + } + } } } } @@ -4686,7 +5065,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/WebhookEventDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/WebhookEventDto" + } + } } } } @@ -4730,7 +5117,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/WebhookEventDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/WebhookEventDto" + } + } } } } @@ -4770,7 +5165,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/WebhookResendAllResultDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/WebhookResendAllResultDto" + } + } } } } @@ -4813,7 +5216,15 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/DashboardStatsDto" + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "$ref": "#/components/schemas/DashboardStatsDto" + } + } } } } @@ -4860,93 +5271,6 @@ } }, "schemas": { - "CreateArticleTranslationDto": { - "type": "object", - "properties": { - "languageCode": { - "type": "string", - "description": "BCP 47 language code for this translation (e.g. \"en\", \"it\", \"fr\").", - "example": "en" - }, - "title": { - "type": "string", - "description": "Localized title of the article.", - "example": "Getting Started with NestJS" - }, - "content": { - "type": "string", - "description": "Full HTML/Markdown body of the article.", - "example": "

NestJS is a progressive Node.js framework...

" - }, - "excerpt": { - "type": "string", - "description": "Short plain-text summary shown in listing pages and previews.", - "example": "A step-by-step guide to building your first NestJS application." - }, - "metaTitle": { - "type": "string", - "description": "SEO meta title. Defaults to the article title when omitted.", - "example": "Getting Started with NestJS | My Blog" - }, - "metaDescription": { - "type": "string", - "description": "SEO meta description shown in search engine result pages.", - "example": "Learn how to set up your first NestJS project from scratch." - } - }, - "required": [ - "languageCode", - "title", - "content", - "excerpt" - ] - }, - "PublicCreateArticleDto": { - "type": "object", - "properties": { - "coverImage": { - "type": "string", - "description": "URL of the article cover image. When creating via multipart/form-data, upload the file in the `coverImage` field instead.", - "example": "https://cdn.example.com/articles/my-article-cover.jpg" - }, - "featured": { - "type": "boolean", - "description": "Whether the article should appear in featured/highlighted sections.", - "example": false - }, - "authorId": { - "type": "string", - "description": "UUID of the user (author) to associate with the article. Defaults to the authenticated user when omitted.", - "example": "123e4567-e89b-12d3-a456-426614174000" - }, - "categoryId": { - "type": "string", - "description": "UUID of the category the article belongs to.", - "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" - }, - "tagIds": { - "description": "List of tag UUIDs to attach to the article.", - "example": [ - "tag-uuid-1", - "tag-uuid-2" - ], - "type": "array", - "items": { - "type": "string" - } - }, - "translations": { - "description": "One or more translation objects to create alongside the article. At least one translation (with the default language) is recommended.", - "type": "array", - "items": { - "$ref": "#/components/schemas/CreateArticleTranslationDto" - } - } - }, - "required": [ - "categoryId" - ] - }, "ContentStatus": { "type": "string", "enum": [ @@ -5229,37 +5553,124 @@ "translations" ] }, - "PageMetaDto": { + "CreateArticleTranslationDto": { "type": "object", "properties": { - "total": { - "type": "number" + "languageCode": { + "type": "string", + "description": "BCP 47 language code for this translation (e.g. \"en\", \"it\", \"fr\").", + "example": "en" }, - "page": { - "type": "number" + "title": { + "type": "string", + "description": "Localized title of the article.", + "example": "Getting Started with NestJS" }, - "limit": { - "type": "number" + "content": { + "type": "string", + "description": "Full HTML/Markdown body of the article.", + "example": "

NestJS is a progressive Node.js framework...

" }, - "totalPages": { - "type": "number" + "excerpt": { + "type": "string", + "description": "Short plain-text summary shown in listing pages and previews.", + "example": "A step-by-step guide to building your first NestJS application." + }, + "metaTitle": { + "type": "string", + "description": "SEO meta title. Defaults to the article title when omitted.", + "example": "Getting Started with NestJS | My Blog" + }, + "metaDescription": { + "type": "string", + "description": "SEO meta description shown in search engine result pages.", + "example": "Learn how to set up your first NestJS project from scratch." } }, "required": [ - "total", - "page", - "limit", - "totalPages" + "languageCode", + "title", + "content", + "excerpt" ] }, - "ArticleTranslationSummaryDto": { + "PublicCreateArticleDto": { "type": "object", "properties": { - "id": { - "type": "string" - }, - "title": { - "type": "string" + "coverImage": { + "type": "string", + "description": "URL of the article cover image. When creating via multipart/form-data, upload the file in the `coverImage` field instead.", + "example": "https://cdn.example.com/articles/my-article-cover.jpg" + }, + "featured": { + "type": "boolean", + "description": "Whether the article should appear in featured/highlighted sections.", + "example": false + }, + "authorId": { + "type": "string", + "description": "UUID of the user (author) to associate with the article. Defaults to the authenticated user when omitted.", + "example": "123e4567-e89b-12d3-a456-426614174000" + }, + "categoryId": { + "type": "string", + "description": "UUID of the category the article belongs to.", + "example": "a1b2c3d4-e5f6-7890-abcd-ef1234567890" + }, + "tagIds": { + "description": "List of tag UUIDs to attach to the article.", + "example": [ + "tag-uuid-1", + "tag-uuid-2" + ], + "type": "array", + "items": { + "type": "string" + } + }, + "translations": { + "description": "One or more translation objects to create alongside the article. At least one translation (with the default language) is recommended.", + "type": "array", + "items": { + "$ref": "#/components/schemas/CreateArticleTranslationDto" + } + } + }, + "required": [ + "categoryId" + ] + }, + "PageMetaDto": { + "type": "object", + "properties": { + "total": { + "type": "number" + }, + "page": { + "type": "number" + }, + "limit": { + "type": "number" + }, + "totalPages": { + "type": "number" + } + }, + "required": [ + "total", + "page", + "limit", + "totalPages" + ] + }, + "ArticleTranslationSummaryDto": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "title": { + "type": "string" }, "slug": { "type": "string" @@ -5425,21 +5836,6 @@ } } }, - "CreateBannedWordDto": { - "type": "object", - "properties": { - "word": { - "type": "string", - "description": "The word to add to the banned word list (2–50 characters)", - "example": "spam", - "minLength": 2, - "maxLength": 50 - } - }, - "required": [ - "word" - ] - }, "BannedWordDto": { "type": "object", "properties": { @@ -5465,6 +5861,21 @@ "tenantId" ] }, + "CreateBannedWordDto": { + "type": "object", + "properties": { + "word": { + "type": "string", + "description": "The word to add to the banned word list (2–50 characters)", + "example": "spam", + "minLength": 2, + "maxLength": 50 + } + }, + "required": [ + "word" + ] + }, "UpdateArticleTranslationDto": { "type": "object", "properties": { @@ -5629,29 +6040,6 @@ "article" ] }, - "CreateCategoryDto": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Display name of the category. The slug will be auto-generated from this value.", - "example": "Science" - }, - "description": { - "type": "string", - "description": "Optional human-readable description of the category.", - "example": "Articles about science and research." - }, - "color": { - "type": "string", - "description": "Optional hex colour associated with the category for UI display.", - "example": "#3B82F6" - } - }, - "required": [ - "name" - ] - }, "CategoryDto": { "type": "object", "properties": { @@ -5701,6 +6089,29 @@ "updatedAt" ] }, + "CreateCategoryDto": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Display name of the category. The slug will be auto-generated from this value.", + "example": "Science" + }, + "description": { + "type": "string", + "description": "Optional human-readable description of the category.", + "example": "Articles about science and research." + }, + "color": { + "type": "string", + "description": "Optional hex colour associated with the category for UI display.", + "example": "#3B82F6" + } + }, + "required": [ + "name" + ] + }, "CategoryListItemDto": { "type": "object", "properties": { @@ -5776,29 +6187,6 @@ } } }, - "CreateCommentDto": { - "type": "object", - "properties": { - "articleId": { - "type": "string", - "description": "UUID of the article being commented on" - }, - "content": { - "type": "string", - "description": "Comment text, plain text (tags are stripped)", - "maxLength": 5000 - }, - "authorExternalId": { - "type": "string", - "description": "External ID of the author (from your identity provider)" - } - }, - "required": [ - "articleId", - "content", - "authorExternalId" - ] - }, "UserDto": { "type": "object", "properties": { @@ -5914,6 +6302,29 @@ "author" ] }, + "CreateCommentDto": { + "type": "object", + "properties": { + "articleId": { + "type": "string", + "description": "UUID of the article being commented on" + }, + "content": { + "type": "string", + "description": "Comment text, plain text (tags are stripped)", + "maxLength": 5000 + }, + "authorExternalId": { + "type": "string", + "description": "External ID of the author (from your identity provider)" + } + }, + "required": [ + "articleId", + "content", + "authorExternalId" + ] + }, "CommentTenantSummaryDto": { "type": "object", "properties": { @@ -6114,47 +6525,6 @@ "bookmarked" ] }, - "CreateReportDto": { - "type": "object", - "properties": { - "targetType": { - "type": "string", - "description": "Type of the reported target", - "enum": [ - "ARTICLE", - "COMMENT", - "USER" - ], - "example": "COMMENT" - }, - "targetId": { - "type": "string", - "description": "UUID of the reported target (article, comment or user)", - "example": "123e4567-e89b-12d3-a456-426614174000" - }, - "reason": { - "type": "string", - "description": "Short reason for the report", - "example": "Spam" - }, - "description": { - "type": "string", - "description": "Optional additional details about the report", - "example": "This comment contains repeated promotional links." - }, - "reporterId": { - "type": "string", - "description": "External ID of the user submitting the report", - "example": "user_abc123" - } - }, - "required": [ - "targetType", - "targetId", - "reason", - "reporterId" - ] - }, "ReportStatus": { "type": "string", "enum": [ @@ -6333,6 +6703,47 @@ "target" ] }, + "CreateReportDto": { + "type": "object", + "properties": { + "targetType": { + "type": "string", + "description": "Type of the reported target", + "enum": [ + "ARTICLE", + "COMMENT", + "USER" + ], + "example": "COMMENT" + }, + "targetId": { + "type": "string", + "description": "UUID of the reported target (article, comment or user)", + "example": "123e4567-e89b-12d3-a456-426614174000" + }, + "reason": { + "type": "string", + "description": "Short reason for the report", + "example": "Spam" + }, + "description": { + "type": "string", + "description": "Optional additional details about the report", + "example": "This comment contains repeated promotional links." + }, + "reporterId": { + "type": "string", + "description": "External ID of the user submitting the report", + "example": "user_abc123" + } + }, + "required": [ + "targetType", + "targetId", + "reason", + "reporterId" + ] + }, "UpdateReportStatusDto": { "type": "object", "properties": { @@ -6363,19 +6774,6 @@ "moderatorId" ] }, - "CreateTagDto": { - "type": "object", - "properties": { - "name": { - "type": "string", - "description": "Display name of the tag. The slug will be auto-generated from this value.", - "example": "Technology" - } - }, - "required": [ - "name" - ] - }, "TenantDto": { "type": "object", "properties": { @@ -6495,6 +6893,19 @@ "updatedAt" ] }, + "CreateTagDto": { + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Display name of the tag. The slug will be auto-generated from this value.", + "example": "Technology" + } + }, + "required": [ + "name" + ] + }, "UpdateTagDto": { "type": "object", "properties": { diff --git a/package.json b/package.json index 722c5dd..bb2acf4 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ }, "dependencies": { "@heyatom/bastion-client": "^0.9.0", - "@heyatom/nest-common": "^0.3.0", - "@nestjs/axios": "^4.0.1", + "@heyatom/client": "^1.0.0", + "@heyatom/nest-common": "^0.4.0", "@nestjs/common": "^11.2.7", "@nestjs/config": "^4.0.4", "@nestjs/core": "^11.2.7", @@ -37,12 +37,10 @@ "@prisma/adapter-pg": "^7.10.0", "@prisma/client": "^7.10.0", "@prometheus-io/client": "^0.16.1", - "axios": "^1.20.0", "class-transformer": "^0.5.1", "class-validator": "^0.15.1", "date-fns": "^4.4.0", "entities": "^7.0.1", - "form-data": "^4.0.6", "helmet": "^8.3.0", "joi": "^18.2.9", "multer": "^2.5.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68f0fa4..5aeed8f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,12 +14,12 @@ importers: '@heyatom/bastion-client': specifier: ^0.9.0 version: 0.9.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@heyatom/client': + specifier: ^1.0.0 + version: 1.0.0(@heyatom/bastion-client@0.9.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)) '@heyatom/nest-common': - specifier: ^0.3.0 - version: 0.3.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(@nestjs/platform-express@11.2.7)(@nestjs/swagger@11.4.7(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2))(@prometheus-io/client@0.16.1)(class-transformer@0.5.1)(class-validator@0.15.1)(helmet@8.3.0)(nestjs-pino@4.6.1(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(pino-http@11.0.0)(pino@10.4.0)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2) - '@nestjs/axios': - specifier: ^4.0.1 - version: 4.0.1(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(axios@1.20.0)(rxjs@7.8.2) + specifier: ^0.4.0 + version: 0.4.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(@nestjs/platform-express@11.2.7)(@nestjs/swagger@11.4.7(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2))(@prometheus-io/client@0.16.1)(class-transformer@0.5.1)(class-validator@0.15.1)(helmet@8.3.0)(nestjs-pino@4.6.1(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(pino-http@11.0.0)(pino@10.4.0)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2) '@nestjs/common': specifier: ^11.2.7 version: 11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) @@ -53,9 +53,6 @@ importers: '@prometheus-io/client': specifier: ^0.16.1 version: 0.16.1 - axios: - specifier: ^1.20.0 - version: 1.20.0 class-transformer: specifier: ^0.5.1 version: 0.5.1 @@ -68,9 +65,6 @@ importers: entities: specifier: ^7.0.1 version: 7.0.1 - form-data: - specifier: ^4.0.6 - version: 4.0.6 helmet: specifier: ^8.3.0 version: 8.3.0 @@ -474,8 +468,20 @@ packages: rxjs: optional: true - '@heyatom/nest-common@0.3.0': - resolution: {integrity: sha512-lw8dmbiw02ObKDOzoRK/NT0xQ6+Yw7f91heBvw+QuhoM+fjy0RMZaZSMuCi8z+bLMaRhlpiyUj8aOMBIvSQnSQ==} + '@heyatom/client@1.0.0': + resolution: {integrity: sha512-hUnhwA3iNXBDC27HSOZvqgcor2SxRYUkDK5QO5uiISnZGmImLkSRk/hjqHMFgzCcgNBkwuAtT49oMgRuNGFuOQ==} + engines: {node: '>=20.19'} + peerDependencies: + '@heyatom/bastion-client': '>=0.3.0' + '@nestjs/common': ^11.0.0 + peerDependenciesMeta: + '@heyatom/bastion-client': + optional: true + '@nestjs/common': + optional: true + + '@heyatom/nest-common@0.4.0': + resolution: {integrity: sha512-HgrGbdy9zLI6zvYxOUnKw/K1EWrl5GNHBrX9Lrc1PtdYbUyHF80qK5Ic4iVoAEL4yTysLWmr4Z7rG2HGqOB+mA==} engines: {node: '>=20.19'} peerDependencies: '@nestjs/common': ^11.0.0 @@ -4791,7 +4797,12 @@ snapshots: reflect-metadata: 0.2.2 rxjs: 7.8.2 - '@heyatom/nest-common@0.3.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(@nestjs/platform-express@11.2.7)(@nestjs/swagger@11.4.7(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2))(@prometheus-io/client@0.16.1)(class-transformer@0.5.1)(class-validator@0.15.1)(helmet@8.3.0)(nestjs-pino@4.6.1(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(pino-http@11.0.0)(pino@10.4.0)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2)': + '@heyatom/client@1.0.0(@heyatom/bastion-client@0.9.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))': + optionalDependencies: + '@heyatom/bastion-client': 0.9.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(reflect-metadata@0.2.2)(rxjs@7.8.2) + '@nestjs/common': 11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) + + '@heyatom/nest-common@0.4.0(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(@nestjs/platform-express@11.2.7)(@nestjs/swagger@11.4.7(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.2.7)(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2))(@prometheus-io/client@0.16.1)(class-transformer@0.5.1)(class-validator@0.15.1)(helmet@8.3.0)(nestjs-pino@4.6.1(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(pino-http@11.0.0)(pino@10.4.0)(rxjs@7.8.2))(reflect-metadata@0.2.2)(rxjs@7.8.2)': dependencies: '@nestjs/common': 11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) '@nestjs/core': 11.2.7(@nestjs/common@11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.2.7)(reflect-metadata@0.2.2)(rxjs@7.8.2) @@ -5244,6 +5255,7 @@ snapshots: '@nestjs/common': 11.2.7(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2) axios: 1.20.0 rxjs: 7.8.2 + optional: true '@nestjs/cli@11.0.24(@swc/cli@0.6.0(@swc/core@1.16.13)(chokidar@4.0.3))(@swc/core@1.16.13)(@types/node@22.20.5)(prettier@3.9.9)': dependencies: @@ -6300,6 +6312,7 @@ snapshots: debug: 4.4.3 transitivePeerDependencies: - supports-color + optional: true ajv-formats@3.0.1(ajv@8.18.0): optionalDependencies: @@ -6381,7 +6394,8 @@ snapshots: array-union@2.1.0: {} - asynckit@0.4.0: {} + asynckit@0.4.0: + optional: true atomic-sleep@1.0.0: {} @@ -6396,6 +6410,7 @@ snapshots: transitivePeerDependencies: - debug - supports-color + optional: true b4a@1.9.0: optional: true @@ -6727,6 +6742,7 @@ snapshots: combined-stream@1.0.8: dependencies: delayed-stream: 1.0.0 + optional: true commander@2.20.3: {} @@ -6897,7 +6913,8 @@ snapshots: dependencies: robust-predicates: 3.0.3 - delayed-stream@1.0.0: {} + delayed-stream@1.0.0: + optional: true denque@2.1.0: {} @@ -7003,6 +7020,7 @@ snapshots: get-intrinsic: 1.3.0 has-tostringtag: 1.0.2 hasown: 2.0.4 + optional: true escalade@3.2.0: {} @@ -7308,7 +7326,8 @@ snapshots: flatted@3.4.4: {} - follow-redirects@1.16.1: {} + follow-redirects@1.16.1: + optional: true foreground-child@3.3.1: dependencies: @@ -7342,6 +7361,7 @@ snapshots: es-set-tostringtag: 2.1.0 hasown: 2.0.4 mime-types: 2.1.35 + optional: true forwarded@0.2.0: {} @@ -7477,6 +7497,7 @@ snapshots: has-tostringtag@1.0.2: dependencies: has-symbols: 1.1.0 + optional: true hasown@2.0.4: dependencies: @@ -7518,6 +7539,7 @@ snapshots: debug: 4.4.3 transitivePeerDependencies: - supports-color + optional: true human-signals@2.1.0: {} @@ -8484,7 +8506,8 @@ snapshots: forwarded: 0.2.0 ipaddr.js: 1.9.1 - proxy-from-env@2.1.0: {} + proxy-from-env@2.1.0: + optional: true pump@3.0.4: dependencies: diff --git a/src/modules/admin/controllers/admin-articles.controller.ts b/src/modules/admin/controllers/admin-articles.controller.ts index a22cfd9..10d0681 100644 --- a/src/modules/admin/controllers/admin-articles.controller.ts +++ b/src/modules/admin/controllers/admin-articles.controller.ts @@ -53,7 +53,11 @@ import { ArticleFiltersQueryDto, adminArticleOrderBy, } from '@/modules/articles/dto/article-filters-query.dto'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { FileHarborService } from '@/modules/fileharbor/fileharbor.service'; import { FileHarborConfig } from '@/modules/fileharbor/interfaces/fileharbor-config.interface'; import { PrismaService } from '@/modules/prisma/prisma.service'; @@ -255,11 +259,7 @@ export class AdminArticlesController { }, }, }) - @ApiResponse({ - status: 201, - description: 'Article created successfully.', - type: ArticleDto, - }) + @ApiCreatedData(ArticleDto, 'Article created successfully.') @ApiResponse({ status: 400, description: @@ -352,7 +352,7 @@ export class AdminArticlesController { description: 'UUID of the article, or a translation slug', example: 'getting-started-with-nestjs', }) - @ApiResponse({ status: 200, description: 'Article found.', type: ArticleDto }) + @ApiOkData(ArticleDto, 'Article found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -408,11 +408,7 @@ export class AdminArticlesController { }, }, }) - @ApiResponse({ - status: 200, - description: 'Article updated successfully.', - type: ArticleDto, - }) + @ApiOkData(ArticleDto, 'Article updated successfully.') @ApiResponse({ status: 400, description: @@ -575,11 +571,7 @@ export class AdminArticlesController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: CreateArticleTranslationDto }) - @ApiResponse({ - status: 201, - description: 'Translation created successfully.', - type: ArticleTranslationDto, - }) + @ApiCreatedData(ArticleTranslationDto, 'Translation created successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -629,11 +621,7 @@ export class AdminArticlesController { description: 'UUID of the article', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 200, - description: 'List of translations.', - type: [ArticleTranslationSummaryDto], - }) + @ApiOkData([ArticleTranslationSummaryDto], 'List of translations.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -662,11 +650,7 @@ export class AdminArticlesController { description: 'BCP 47 language code', example: 'en', }) - @ApiResponse({ - status: 200, - description: 'Translation found.', - type: ArticleTranslationDto, - }) + @ApiOkData(ArticleTranslationDto, 'Translation found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -700,11 +684,7 @@ export class AdminArticlesController { example: 'en', }) @ApiBody({ type: AdminUpdateArticleTranslationDto }) - @ApiResponse({ - status: 200, - description: 'Translation updated successfully.', - type: ArticleTranslationDto, - }) + @ApiOkData(ArticleTranslationDto, 'Translation updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/admin/controllers/admin-audits.controller.ts b/src/modules/admin/controllers/admin-audits.controller.ts index 3179560..1c024ba 100644 --- a/src/modules/admin/controllers/admin-audits.controller.ts +++ b/src/modules/admin/controllers/admin-audits.controller.ts @@ -16,7 +16,7 @@ import { } from '@/modules/bastion/decorators/roles.decorator'; import { GetSession } from '@/modules/bastion/decorators/get-session.decorator'; import { AuditListQueryDto } from '@/modules/audits/dto/audit-list-query.dto'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { ApiPaginatedResponse, ApiOkData } from '@heyatom/nest-common'; import { AuditLogDto } from '@/modules/audits/dto/audit-log.dto'; @ApiTags('Admin / Audits') @@ -56,11 +56,7 @@ export class AdminAuditsController { description: 'UUID of the audit log entry', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 200, - description: 'Audit log entry found.', - type: AuditLogDto, - }) + @ApiOkData(AuditLogDto, 'Audit log entry found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', diff --git a/src/modules/admin/controllers/admin-banned-words.controller.ts b/src/modules/admin/controllers/admin-banned-words.controller.ts index 159b0b9..45948cc 100644 --- a/src/modules/admin/controllers/admin-banned-words.controller.ts +++ b/src/modules/admin/controllers/admin-banned-words.controller.ts @@ -30,7 +30,11 @@ import { import { GetSession } from '@/modules/bastion/decorators/get-session.decorator'; import { CreateBannedWordDto } from '@/modules/banned-words/dto/create-banned-word.dto'; import { BannedWordListQueryDto } from '@/modules/banned-words/dto/banned-word-list-query.dto'; -import { PaginatedResult, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PaginatedResult, + ApiPaginatedResponse, + ApiCreatedData, +} from '@heyatom/nest-common'; import { BannedWordDto } from '@/modules/banned-words/dto/banned-word.dto'; @ApiTags('Admin / Banned Words') @@ -48,11 +52,7 @@ export class AdminBannedWordsController { "Adds a new word to the tenant's banned word list. The word must be between 2 and 50 characters.", }) @ApiBody({ type: CreateBannedWordDto }) - @ApiResponse({ - status: 201, - description: 'Banned word added successfully.', - type: BannedWordDto, - }) + @ApiCreatedData(BannedWordDto, 'Banned word added successfully.') @ApiResponse({ status: 400, description: 'Validation error – word is missing or out of length bounds.', diff --git a/src/modules/admin/controllers/admin-categories.controller.ts b/src/modules/admin/controllers/admin-categories.controller.ts index db432a4..072d508 100644 --- a/src/modules/admin/controllers/admin-categories.controller.ts +++ b/src/modules/admin/controllers/admin-categories.controller.ts @@ -29,12 +29,15 @@ import { CategoryDto, CategoryListItemDto, } from '@/modules/categories/dto/category.dto'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; -import { ApiCreatedResponse, ApiOkResponse } from '@nestjs/swagger'; @ApiTags('Admin / Categories') @ApiBearerAuth() @@ -49,7 +52,7 @@ export class AdminCategoriesController { ) {} @Post() - @ApiCreatedResponse({ type: CategoryDto }) + @ApiCreatedData(CategoryDto) async create( @GetSession() session: AdminSession, @Body() dto: CreateCategoryDto, @@ -80,7 +83,7 @@ export class AdminCategoriesController { } @Get(':id') - @ApiOkResponse({ type: CategoryDto }) + @ApiOkData(CategoryDto) findOne( @GetSession() session: AdminSession, @Param() params: CategoryParamsDto, @@ -89,7 +92,7 @@ export class AdminCategoriesController { } @Patch(':id') - @ApiOkResponse({ type: CategoryDto }) + @ApiOkData(CategoryDto) async update( @GetSession() session: AdminSession, @Param() params: CategoryParamsDto, diff --git a/src/modules/admin/controllers/admin-comments.controller.ts b/src/modules/admin/controllers/admin-comments.controller.ts index 627c424..c28cfc4 100644 --- a/src/modules/admin/controllers/admin-comments.controller.ts +++ b/src/modules/admin/controllers/admin-comments.controller.ts @@ -33,7 +33,7 @@ import { CommentFiltersQueryDto } from '@/modules/comments/dto/comment-filters-q import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { ApiPaginatedResponse, ApiOkData } from '@heyatom/nest-common'; import { CommentDto, CommentListItemDto, @@ -83,7 +83,7 @@ export class AdminCommentsController { description: 'UUID of the comment', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ status: 200, description: 'Comment found.', type: CommentDto }) + @ApiOkData(CommentDto, 'Comment found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -108,11 +108,7 @@ export class AdminCommentsController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: UpdateCommentDto }) - @ApiResponse({ - status: 200, - description: 'Comment updated successfully.', - type: CommentDto, - }) + @ApiOkData(CommentDto, 'Comment updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/admin/controllers/admin-reports.controller.ts b/src/modules/admin/controllers/admin-reports.controller.ts index ab480b5..6292fa0 100644 --- a/src/modules/admin/controllers/admin-reports.controller.ts +++ b/src/modules/admin/controllers/admin-reports.controller.ts @@ -32,7 +32,11 @@ import { ReportParamsDto } from '@/modules/reports/dto/report-params.dto'; import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { ReportDto } from '@/modules/reports/dto/report-response.dto'; @ApiTags('Admin / Reports') @@ -55,11 +59,7 @@ export class AdminReportsController { "`reporterId` is automatically set to the session user's external ID.", }) @ApiBody({ type: AdminCreateReportDto }) - @ApiResponse({ - status: 201, - description: 'Report submitted successfully.', - type: ReportDto, - }) + @ApiCreatedData(ReportDto, 'Report submitted successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -121,7 +121,7 @@ export class AdminReportsController { description: 'UUID of the report', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ status: 200, description: 'Report found.', type: ReportDto }) + @ApiOkData(ReportDto, 'Report found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -146,11 +146,7 @@ export class AdminReportsController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: AdminUpdateReportDto }) - @ApiResponse({ - status: 200, - description: 'Report status updated successfully.', - type: ReportDto, - }) + @ApiOkData(ReportDto, 'Report status updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/admin/controllers/admin-stats.controller.ts b/src/modules/admin/controllers/admin-stats.controller.ts index d5aa3d8..84d664d 100644 --- a/src/modules/admin/controllers/admin-stats.controller.ts +++ b/src/modules/admin/controllers/admin-stats.controller.ts @@ -9,7 +9,8 @@ import { Roles, } from '@/modules/bastion/decorators/roles.decorator'; import { GetSession } from '@/modules/bastion/decorators/get-session.decorator'; -import { ApiTags, ApiBearerAuth, ApiOkResponse } from '@nestjs/swagger'; +import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; +import { ApiOkData } from '@heyatom/nest-common'; import { DashboardStatsDto } from '@/modules/analytics/dto/dashboard-stats.dto'; import { DashboardStatsQueryDto } from '@/modules/analytics/dto/dashboard-stats-query.dto'; @@ -22,7 +23,7 @@ export class AdminStatsController { constructor(private readonly analyticsService: AnalyticsService) {} @Get('dashboard') - @ApiOkResponse({ type: DashboardStatsDto }) + @ApiOkData(DashboardStatsDto) getDashboard( @GetSession() session: AdminSession, @Query() query: DashboardStatsQueryDto, diff --git a/src/modules/admin/controllers/admin-tags.controller.ts b/src/modules/admin/controllers/admin-tags.controller.ts index 76ba4b8..9a15a45 100644 --- a/src/modules/admin/controllers/admin-tags.controller.ts +++ b/src/modules/admin/controllers/admin-tags.controller.ts @@ -26,13 +26,17 @@ import { CreateTagDto } from '@/modules/tags/dto/create-tag.dto'; import { AdminUpdateTagDto } from '@/modules/tags/dto/update-tag.dto'; import { TagParamsDto } from '@/modules/tags/dto/tag-params.dto'; import { TagsListQuery } from '@/modules/tags/queries/tags.query'; -import { PaginatedResult, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PaginatedResult, + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { TagDto } from '@/modules/tags/dto/tags.dto'; import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; -import { ApiCreatedResponse, ApiOkResponse } from '@nestjs/swagger'; @ApiTags('Admin / Tags') @ApiBearerAuth() @@ -47,7 +51,7 @@ export class AdminTagsController { ) {} @Post() - @ApiCreatedResponse({ type: TagDto }) + @ApiCreatedData(TagDto) async create(@GetSession() session: AdminSession, @Body() dto: CreateTagDto) { const tag = await this.tagsService.create(session.tenantId, dto); @@ -75,13 +79,13 @@ export class AdminTagsController { } @Get(':id') - @ApiOkResponse({ type: TagDto }) + @ApiOkData(TagDto) findOne(@GetSession() session: AdminSession, @Param() params: TagParamsDto) { return this.tagsService.findOne(session.tenantId, params.id); } @Patch(':id') - @ApiOkResponse({ type: TagDto }) + @ApiOkData(TagDto) async update( @GetSession() session: AdminSession, @Param() params: TagParamsDto, diff --git a/src/modules/admin/controllers/admin-users.controller.ts b/src/modules/admin/controllers/admin-users.controller.ts index 056465f..cb6593c 100644 --- a/src/modules/admin/controllers/admin-users.controller.ts +++ b/src/modules/admin/controllers/admin-users.controller.ts @@ -30,7 +30,11 @@ import { UserListQueryDto } from '@/modules/users/dto/user-list-query.dto'; import { UserListItemDto } from '@/modules/users/dto/user-list-item.dto'; import { UserParamsDto } from '@/modules/users/dto/user-params.dto'; import { UpdateUserStatusDto } from '@/modules/users/dto/update-user-status.dto'; -import { PaginatedResult, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PaginatedResult, + ApiPaginatedResponse, + ApiOkData, +} from '@heyatom/nest-common'; import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; @@ -74,11 +78,7 @@ export class AdminUsersController { description: 'Internal UUID of the user', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 200, - description: 'User found.', - type: UserListItemDto, - }) + @ApiOkData(UserListItemDto, 'User found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -98,11 +98,7 @@ export class AdminUsersController { 'Changes the moderation status of a user (ACTIVE, BANNED, SHADOW_BANNED).', }) @ApiParam({ name: 'id', description: 'Internal UUID of the user' }) - @ApiResponse({ - status: 200, - description: 'User status updated.', - type: UserListItemDto, - }) + @ApiOkData(UserListItemDto, 'User status updated.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', diff --git a/src/modules/admin/controllers/admin-webhooks.controller.spec.ts b/src/modules/admin/controllers/admin-webhooks.controller.spec.ts new file mode 100644 index 0000000..5105781 --- /dev/null +++ b/src/modules/admin/controllers/admin-webhooks.controller.spec.ts @@ -0,0 +1,23 @@ +import { isPaginated, paginate } from '@heyatom/nest-common'; +import { AdminWebhooksController } from './admin-webhooks.controller'; +import { DEAD_LETTER_DATE } from '@/modules/webhook/webhook.constants'; + +describe('AdminWebhooksController', () => { + it('findAll keeps the page marker, so TransformInterceptor does not wrap it twice', async () => { + const row = { id: 'e1', sentAt: null, nextRetryAt: DEAD_LETTER_DATE }; + const service = { + findAll: jest + .fn() + .mockResolvedValue(paginate([row], 1, { page: 1, limit: 20 })), + }; + const controller = new AdminWebhooksController(service as any); + + const page = await controller.findAll({ tenantId: 't1' } as any, {} as any); + + expect(isPaginated(page)).toBe(true); + expect(page.data).toEqual([ + { ...row, nextRetryAt: null, deadLettered: true }, + ]); + expect(page.meta).toEqual({ total: 1, page: 1, limit: 20, totalPages: 1 }); + }); +}); diff --git a/src/modules/admin/controllers/admin-webhooks.controller.ts b/src/modules/admin/controllers/admin-webhooks.controller.ts index a23def8..35dc40f 100644 --- a/src/modules/admin/controllers/admin-webhooks.controller.ts +++ b/src/modules/admin/controllers/admin-webhooks.controller.ts @@ -27,7 +27,11 @@ import { WebhookEventListQueryDto } from '@/modules/webhook/dto/webhook-event-li import { WebhookEventParamsDto } from '@/modules/webhook/dto/webhook-event-params.dto'; import { WebhooksService } from '@/modules/webhook/webhooks.service'; import { toWebhookEventView } from '@/modules/webhook/webhook.constants'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiOkData, + markPaginated, +} from '@heyatom/nest-common'; import { WebhookEventDto, WebhookResendAllResultDto, @@ -60,7 +64,9 @@ export class AdminWebhooksController { session.tenantId, query, ); - return { ...page, data: page.data.map(toWebhookEventView) }; + // markPaginated: the spread drops paginate()'s marker, and TransformInterceptor would + // wrap the page again. + return markPaginated({ ...page, data: page.data.map(toWebhookEventView) }); } @Get(':id') @@ -70,11 +76,7 @@ export class AdminWebhooksController { 'Returns the full detail of a single webhook event (payload, attempts, sentAt, lastError, nextRetryAt).', }) @ApiParam({ name: 'id', description: 'Internal UUID of the webhook event' }) - @ApiResponse({ - status: 200, - description: 'Webhook event found.', - type: WebhookEventDto, - }) + @ApiOkData(WebhookEventDto, 'Webhook event found.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', @@ -97,11 +99,7 @@ export class AdminWebhooksController { 'Resets attempts to 0 and clears nextRetryAt / lastError for the given event so that the delivery cron picks it up on the next cycle. Returns 400 if the event was already delivered successfully.', }) @ApiParam({ name: 'id', description: 'Internal UUID of the webhook event' }) - @ApiResponse({ - status: 200, - description: 'Webhook event reset — will be retried shortly.', - type: WebhookEventDto, - }) + @ApiOkData(WebhookEventDto, 'Webhook event reset — will be retried shortly.') @ApiResponse({ status: 400, description: 'Event already delivered — resend not needed.', @@ -131,11 +129,7 @@ export class AdminWebhooksController { description: 'Resets attempts, nextRetryAt and lastError to 0 / null for every undelivered event belonging to the current tenant, except events a worker is delivering right now. Use this after a temporary outage of the receiving system to trigger re-delivery of the entire backlog.', }) - @ApiResponse({ - status: 200, - description: 'Number of events reset.', - type: WebhookResendAllResultDto, - }) + @ApiOkData(WebhookResendAllResultDto, 'Number of events reset.') @ApiResponse({ status: 401, description: 'Not authenticated – missing or expired session.', diff --git a/src/modules/app/app.module.ts b/src/modules/app/app.module.ts index d12ba3b..b7ddbb4 100644 --- a/src/modules/app/app.module.ts +++ b/src/modules/app/app.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { APP_FILTER } from '@nestjs/core'; +import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { ThrottlerModule } from '@nestjs/throttler'; import { ScheduleModule } from '@nestjs/schedule'; @@ -29,6 +29,7 @@ import { AllExceptionsFilter, loggerParams, minimalRequestSerializer, + TransformInterceptor, } from '@heyatom/nest-common'; /** Comma-separated env list → array; undefined keeps the package default. */ @@ -130,8 +131,9 @@ const splitList = (raw?: string): string[] | undefined => AnalyticsModule, WebhooksModule, ], - // No TransformInterceptor: the public contract returns raw resources until - // the coordinated envelope migration (api standards plan, phase 3). - providers: [{ provide: APP_FILTER, useClass: AllExceptionsFilter }], + providers: [ + { provide: APP_FILTER, useClass: AllExceptionsFilter }, + { provide: APP_INTERCEPTOR, useClass: TransformInterceptor }, + ], }) export class AppModule {} diff --git a/src/modules/article-translations/article-translations.controller.ts b/src/modules/article-translations/article-translations.controller.ts index eab4083..ba3e1b4 100644 --- a/src/modules/article-translations/article-translations.controller.ts +++ b/src/modules/article-translations/article-translations.controller.ts @@ -19,6 +19,7 @@ import { ApiParam, ApiBody, } from '@nestjs/swagger'; +import { ApiCreatedData, ApiOkData } from '@heyatom/nest-common'; import { ArticleTranslationsService } from '@/modules/article-translations/article-translations.service'; import { TenantGuard } from '@/modules/tenants/guards/tenant.guard'; import { GetTenant } from '@/modules/tenants/decorators/get-tenant.decorator'; @@ -54,11 +55,7 @@ export class ArticleTranslationsController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: CreateArticleTranslationDto }) - @ApiResponse({ - status: 201, - description: 'Translation created successfully.', - type: ArticleTranslationDto, - }) + @ApiCreatedData(ArticleTranslationDto, 'Translation created successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -89,11 +86,7 @@ export class ArticleTranslationsController { description: 'UUID of the article', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 200, - description: 'List of translations.', - type: [ArticleTranslationSummaryDto], - }) + @ApiOkData([ArticleTranslationSummaryDto], 'List of translations.') @ApiResponse({ status: 401, description: 'Missing or invalid API key.' }) @ApiResponse({ status: 404, description: 'Article not found.' }) findAll( @@ -125,11 +118,7 @@ export class ArticleTranslationsController { description: 'BCP 47 language code', example: 'en', }) - @ApiResponse({ - status: 200, - description: 'Translation found.', - type: ArticleTranslationDto, - }) + @ApiOkData(ArticleTranslationDto, 'Translation found.') @ApiResponse({ status: 401, description: 'Missing or invalid API key.' }) @ApiResponse({ status: 404, description: 'Translation not found.' }) findOne( @@ -162,11 +151,7 @@ export class ArticleTranslationsController { example: 'en', }) @ApiBody({ type: UpdateArticleTranslationDto }) - @ApiResponse({ - status: 200, - description: 'Translation updated successfully.', - type: ArticleTranslationDto, - }) + @ApiOkData(ArticleTranslationDto, 'Translation updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/articles/articles.controller.ts b/src/modules/articles/articles.controller.ts index f62b025..9bcc1d3 100644 --- a/src/modules/articles/articles.controller.ts +++ b/src/modules/articles/articles.controller.ts @@ -30,7 +30,11 @@ import { } from '@/modules/articles/dto/article-params.dto'; import { PublicArticleFiltersQueryDto } from '@/modules/articles/dto/article-filters-query.dto'; import { ArticleShowQueryDto } from '@/modules/articles/dto/article-show-query.dto'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { ArticleDto, ArticleListItemDto, @@ -52,11 +56,7 @@ export class ArticlesController { 'Content is automatically checked for banned words; matching content will be created with a HIDDEN status.', }) @ApiBody({ type: PublicCreateArticleDto }) - @ApiResponse({ - status: 201, - description: 'Article created successfully.', - type: ArticleDto, - }) + @ApiCreatedData(ArticleDto, 'Article created successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -102,7 +102,7 @@ export class ArticlesController { description: 'URL-friendly slug of the article', example: 'getting-started-with-nestjs', }) - @ApiResponse({ status: 200, description: 'Article found.', type: ArticleDto }) + @ApiOkData(ArticleDto, 'Article found.') @ApiResponse({ status: 401, description: 'Missing or invalid API key.' }) @ApiResponse({ status: 404, @@ -134,11 +134,7 @@ export class ArticlesController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: PublicUpdateArticleDto }) - @ApiResponse({ - status: 200, - description: 'Article updated successfully.', - type: ArticleDto, - }) + @ApiOkData(ArticleDto, 'Article updated successfully.') @ApiResponse({ status: 400, description: 'Validation error or invalid status transition.', diff --git a/src/modules/banned-words/banned-words.controller.ts b/src/modules/banned-words/banned-words.controller.ts index ee2275e..ac01f29 100644 --- a/src/modules/banned-words/banned-words.controller.ts +++ b/src/modules/banned-words/banned-words.controller.ts @@ -24,7 +24,11 @@ import { CreateBannedWordDto } from './dto/create-banned-word.dto'; import { TenantGuard } from '@/modules/tenants/guards/tenant.guard'; import { GetTenant } from '@/modules/tenants/decorators/get-tenant.decorator'; import { BannedWordListQueryDto } from './dto/banned-word-list-query.dto'; -import { PaginatedResult, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PaginatedResult, + ApiPaginatedResponse, + ApiCreatedData, +} from '@heyatom/nest-common'; import { BannedWordDto } from './dto/banned-word.dto'; @ApiTags('Banned Words') @@ -42,11 +46,7 @@ export class BannedWordsController { 'Any content containing this word will be automatically hidden during creation or moderation checks.', }) @ApiBody({ type: CreateBannedWordDto }) - @ApiResponse({ - status: 201, - description: 'Banned word added successfully.', - type: BannedWordDto, - }) + @ApiCreatedData(BannedWordDto, 'Banned word added successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/bookmarks/bookmarks.controller.ts b/src/modules/bookmarks/bookmarks.controller.ts index 2597362..4665ec9 100644 --- a/src/modules/bookmarks/bookmarks.controller.ts +++ b/src/modules/bookmarks/bookmarks.controller.ts @@ -20,7 +20,11 @@ import { TenantGuard } from '@/modules/tenants/guards/tenant.guard'; import { GetTenant } from '@/modules/tenants/decorators/get-tenant.decorator'; import { BookmarksService } from '@/modules/bookmarks/bookmarks.service'; import { BookmarkParamsDto } from '@/modules/bookmarks/dto/bookmark-params.dto'; -import { PageParams, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PageParams, + ApiPaginatedResponse, + ApiCreatedData, +} from '@heyatom/nest-common'; import { BookmarkListItemDto, BookmarkToggleResultDto, @@ -60,11 +64,7 @@ export class BookmarksController { description: 'UUID of the article to bookmark/unbookmark', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 201, - description: 'Bookmark toggled successfully.', - type: BookmarkToggleResultDto, - }) + @ApiCreatedData(BookmarkToggleResultDto, 'Bookmark toggled successfully.') @ApiResponse({ status: 400, description: 'Missing X-User-Id header or invalid articleId.', diff --git a/src/modules/categories/categories.controller.ts b/src/modules/categories/categories.controller.ts index b039bcf..748804a 100644 --- a/src/modules/categories/categories.controller.ts +++ b/src/modules/categories/categories.controller.ts @@ -31,7 +31,11 @@ import { CategoryDto, CategoryListItemDto, } from '@/modules/categories/dto/category.dto'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; @ApiTags('Categories') @ApiSecurity('api-key') @@ -47,11 +51,7 @@ export class CategoriesController { 'Creates a new category for the current tenant. The slug is auto-generated from the name.', }) @ApiBody({ type: CreateCategoryDto }) - @ApiResponse({ - status: 201, - description: 'Category created successfully.', - type: CategoryDto, - }) + @ApiCreatedData(CategoryDto, 'Category created successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -88,11 +88,7 @@ export class CategoriesController { description: 'URL-friendly slug of the category (e.g. "science")', example: 'science', }) - @ApiResponse({ - status: 200, - description: 'Category found.', - type: CategoryDto, - }) + @ApiOkData(CategoryDto, 'Category found.') @ApiResponse({ status: 401, description: 'Missing or invalid API key.' }) @ApiResponse({ status: 404, description: 'Category not found.' }) findOne(@GetTenant() tenant: any, @Param() params: CategorySlugParamsDto) { @@ -111,11 +107,7 @@ export class CategoriesController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: UpdateCategoryDto }) - @ApiResponse({ - status: 200, - description: 'Category updated successfully.', - type: CategoryDto, - }) + @ApiOkData(CategoryDto, 'Category updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/comments/comments.controller.ts b/src/modules/comments/comments.controller.ts index 7d11909..c9aa0ba 100644 --- a/src/modules/comments/comments.controller.ts +++ b/src/modules/comments/comments.controller.ts @@ -23,13 +23,12 @@ import { UserRole } from '@prisma/client'; import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType } from '@prisma/client'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; import { - ApiCreatedResponse, - ApiHeader, - ApiNotFoundResponse, - ApiOkResponse, -} from '@nestjs/swagger'; + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; +import { ApiHeader, ApiNotFoundResponse } from '@nestjs/swagger'; import { CommentDto, CommentListItemDto, @@ -45,7 +44,7 @@ export class CommentsController { ) {} @Post() - @ApiCreatedResponse({ type: CommentDto }) + @ApiCreatedData(CommentDto) @ApiNotFoundResponse({ description: 'Article not found or not PUBLISHED.' }) async create(@GetTenant() tenant: any, @Body() dto: CreateCommentDto) { const comment = await this.commentsService.create(tenant.id, dto); @@ -76,10 +75,7 @@ export class CommentsController { } @Get(':id') - @ApiOkResponse({ - type: CommentDto, - description: 'content is null while the comment is not VISIBLE', - }) + @ApiOkData(CommentDto, 'content is null while the comment is not VISIBLE') @ApiHeader({ name: 'X-User-Id', required: false, @@ -105,7 +101,7 @@ export class CommentsController { } @Patch(':id') - @ApiOkResponse({ type: CommentDto }) + @ApiOkData(CommentDto) async update( @GetTenant() tenant: any, @Param() params: CommentParamsDto, diff --git a/src/modules/fileharbor/dto/file-harbor.dto.ts b/src/modules/fileharbor/dto/file-harbor.dto.ts deleted file mode 100644 index c36fb8d..0000000 --- a/src/modules/fileharbor/dto/file-harbor.dto.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Base DTO with common fields for both Images and Avatars - */ -abstract class FileHarborBaseDto { - id: string; - userId?: string; - format: string; - width?: number; - height?: number; - size: number; - mimeType: string; - isOptimized: boolean; - views: number; - downloads: number; - createdAt: string | Date; - url: string; - thumbnailUrl?: string; - fullPath: string; -} - -/** - * DTO for /images endpoint response - */ -export class FileHarborImageDto extends FileHarborBaseDto { - user?: string; - client?: string; - originalName?: string; - isPrivate?: boolean; - tags?: string[]; - description?: string; -} diff --git a/src/modules/fileharbor/fileharbor.module.ts b/src/modules/fileharbor/fileharbor.module.ts index 4b31377..d8678c1 100644 --- a/src/modules/fileharbor/fileharbor.module.ts +++ b/src/modules/fileharbor/fileharbor.module.ts @@ -1,19 +1,7 @@ import { Module } from '@nestjs/common'; import { FileHarborService } from './fileharbor.service'; -import { HttpModule } from '@nestjs/axios'; - -// Defaults for every FileHarbor call (per-call timeouts override): never -// follow redirects with the tenant API key, bound responses and uploads. -export const FILEHARBOR_HTTP_OPTIONS = { - timeout: 15_000, - maxRedirects: 0, - maxContentLength: 1024 * 1024, - maxBodyLength: FileHarborService.MAX_IMAGE_SIZE + 1024 * 1024, -}; @Module({ - controllers: [], - imports: [HttpModule.register(FILEHARBOR_HTTP_OPTIONS)], providers: [FileHarborService], exports: [FileHarborService], }) diff --git a/src/modules/fileharbor/fileharbor.service.spec.ts b/src/modules/fileharbor/fileharbor.service.spec.ts index 6ecfea9..8003d83 100644 --- a/src/modules/fileharbor/fileharbor.service.spec.ts +++ b/src/modules/fileharbor/fileharbor.service.spec.ts @@ -1,5 +1,10 @@ -import { of } from 'rxjs'; -import { FileHarborService } from './fileharbor.service'; +import { createServer, RequestListener, Server } from 'node:http'; +import { AddressInfo } from 'node:net'; +import { + FileHarborService, + FILEHARBOR_MAX_RESPONSE_BYTES, + fileHarborFetch, +} from './fileharbor.service'; const config = { endpoint: 'https://cdn.example.com/v2', apiKey: 'k' }; @@ -18,32 +23,134 @@ describe('FileHarborService.isUnderEndpoint', () => { }); }); -describe('FileHarborService.deleteImageSafely', () => { - const http = { delete: jest.fn() }; - const service = new FileHarborService(http as any); +describe('FileHarborService', () => { + const service = new FileHarborService(); + let fetchMock: jest.SpyInstance; beforeEach(() => { - jest.resetAllMocks(); - http.delete.mockReturnValue(of({ data: {} })); + fetchMock = jest + .spyOn(global, 'fetch') + .mockImplementation(async () => new Response(null, { status: 204 })); }); - it('refuses to delete a URL outside the tenant endpoint', async () => { - await expect( - service.deleteImageSafely( - 'https://attacker.example/images/0123456789abcdef', + afterEach(() => fetchMock.mockRestore()); + + const call = () => { + const [url, init] = fetchMock.mock.calls[0]; + return { url: String(url), init: init as RequestInit }; + }; + + describe('deleteImageSafely', () => { + it('refuses to delete a URL outside the tenant endpoint', async () => { + await expect( + service.deleteImageSafely( + 'https://attacker.example/images/0123456789abcdef', + config, + ), + ).resolves.toBe(false); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('encodes the file id into the DELETE path, with the tenant key, no redirects', async () => { + await service.deleteImageSafely( + 'https://cdn.example.com/v2/images/0123456789ab%2F..%2Fadmin', config, - ), - ).resolves.toBe(false); - expect(http.delete).not.toHaveBeenCalled(); + ); + const { url, init } = call(); + expect(url).toBe( + 'https://cdn.example.com/v2/images/0123456789ab%252F..%252Fadmin', + ); + expect(init.method).toBe('DELETE'); + expect(init.redirect).toBe('manual'); + expect((init.headers as Record)['X-API-Key']).toBe('k'); + }); + + it('treats a 404 as already deleted', async () => { + fetchMock.mockImplementation( + async () => + new Response(JSON.stringify({ code: 'NOT_FOUND' }), { status: 404 }), + ); + await expect( + service.deleteImageSafely( + 'https://cdn.example.com/v2/images/0123456789abcdef', + config, + ), + ).resolves.toBe(true); + }); }); - it('encodes the file id into the DELETE path', async () => { - await service.deleteImageSafely( - 'https://cdn.example.com/v2/images/0123456789ab%2F..%2Fadmin', - config, - ); - expect(http.delete.mock.calls[0][0]).toBe( - 'https://cdn.example.com/v2/images/0123456789ab%252F..%252Fadmin', - ); + describe('uploadImageIfProvided', () => { + const file = { + buffer: Buffer.from('img'), + originalname: 'a.png', + mimetype: 'image/png', + size: 3, + } as Express.Multer.File; + + it('posts the file as the external user and returns the enveloped fullPath', async () => { + fetchMock.mockImplementation( + async () => + new Response( + JSON.stringify({ data: { fullPath: 'https://cdn/x.png' } }), + { status: 201 }, + ), + ); + await expect( + service.uploadImageIfProvided(file, 'article', 'u1', config), + ).resolves.toBe('https://cdn/x.png'); + + const { url, init } = call(); + expect(url).toBe('https://cdn.example.com/v2/images'); + expect((init.headers as Record)['X-User-Id']).toBe('u1'); + expect((init.body as FormData).get('description')).toBe('article Image'); + }); + + it('fails when FileHarbor returns no URL', async () => { + fetchMock.mockImplementation( + async () => new Response(JSON.stringify({ data: {} }), { status: 201 }), + ); + await expect( + service.uploadImageIfProvided(file, 'article', 'u1', config), + ).rejects.toThrow(/no URL returned/); + }); + }); +}); + +describe('fileHarborFetch', () => { + const listen = (handler: RequestListener) => + new Promise((resolve) => { + const server = createServer(handler); + server.listen(0, '127.0.0.1', () => resolve(server)); + }); + const urlOf = (s: Server) => + `http://127.0.0.1:${(s.address() as AddressInfo).port}`; + + let target: Server; + let redirector: Server; + let targetHits = 0; + + beforeAll(async () => { + target = await listen((_req, res) => { + targetHits++; + res.end('x'.repeat(FILEHARBOR_MAX_RESPONSE_BYTES + 1)); + }); + redirector = await listen((_req, res) => { + res.writeHead(307, { location: `${urlOf(target)}/internal` }).end(); + }); + }); + + afterAll(() => { + target.close(); + redirector.close(); + }); + + it('does not follow redirects', async () => { + const res = await fileHarborFetch(urlOf(redirector), { method: 'POST' }); + expect(res.status).toBe(307); + expect(targetHits).toBe(0); + }); + + it('caps the response size', async () => { + await expect(fileHarborFetch(urlOf(target))).rejects.toThrow(/bytes/); }); }); diff --git a/src/modules/fileharbor/fileharbor.service.ts b/src/modules/fileharbor/fileharbor.service.ts index b28d5ab..126b628 100644 --- a/src/modules/fileharbor/fileharbor.service.ts +++ b/src/modules/fileharbor/fileharbor.service.ts @@ -4,13 +4,49 @@ import { InternalServerErrorException, Logger, } from '@nestjs/common'; -import { HttpService } from '@nestjs/axios'; -import * as FormData from 'form-data'; -import { firstValueFrom } from 'rxjs'; -import { FileHarborImageDto } from './dto/file-harbor.dto'; +import { + apiKeyAuth, + FileHarborClient, + HeyAtomHttpError, + type ImageResponseDto, +} from '@heyatom/client/fileharbor'; import { ImageCleanupOptions } from './interfaces/cleanup-options.interface'; import { FileHarborConfig } from './interfaces/fileharbor-config.interface'; +/** FileHarbor answers are small JSON documents. */ +export const FILEHARBOR_MAX_RESPONSE_BYTES = 1024 * 1024; + +/** + * `fetch` for the tenant's FileHarbor: never follows a redirect (it would carry + * the tenant API key to wherever the `Location` points; a 3xx comes back as an + * error status) and refuses bodies over `FILEHARBOR_MAX_RESPONSE_BYTES`. + */ +export const fileHarborFetch: typeof fetch = async (input, init) => { + const res = await fetch(input, { ...init, redirect: 'manual' }); + if (!res.body) return res; + + const reader = res.body.getReader(); + const chunks: Uint8Array[] = []; + let size = 0; + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + size += value.byteLength; + if (size > FILEHARBOR_MAX_RESPONSE_BYTES) { + await reader.cancel(); + throw new Error( + `FileHarbor response over ${FILEHARBOR_MAX_RESPONSE_BYTES} bytes`, + ); + } + chunks.push(value); + } + return new Response(size ? Buffer.concat(chunks) : null, { + status: res.status, + statusText: res.statusText, + headers: res.headers, + }); +}; + @Injectable() export class FileHarborService { private readonly logger = new Logger(FileHarborService.name); @@ -28,7 +64,15 @@ export class FileHarborService { private static readonly UPLOAD_TIMEOUT = 30000; // 30 seconds private static readonly DELETE_TIMEOUT = 15000; // 15 seconds - constructor(private readonly httpService: HttpService) {} + /** One client per call: endpoint and API key are per tenant. */ + private client(config: FileHarborConfig): FileHarborClient { + return new FileHarborClient({ + baseUrl: config.endpoint, + auth: apiKeyAuth(config.apiKey), + timeoutMs: FileHarborService.DELETE_TIMEOUT, + fetch: fileHarborFetch, + }); + } /** * Safely delete a single image @@ -115,40 +159,31 @@ export class FileHarborService { description = 'Imported image', externalId: string, config: FileHarborConfig, - ): Promise { + ): Promise { this.validateImageFile(file); try { - const form = this.createFormData(file, { - description, - creatorId: externalId, - }); - - const response = await firstValueFrom( - this.httpService.post( - `${config.endpoint}/images`, - form, - { - headers: { - ...form.getHeaders(), - 'X-API-Key': config.apiKey, - }, - timeout: FileHarborService.UPLOAD_TIMEOUT, - }, - ), + const { data: image } = await this.client(config).uploadImage( + { + data: file.buffer, + filename: file.originalname, + contentType: file.mimetype, + }, + { description }, + { userId: externalId, timeoutMs: FileHarborService.UPLOAD_TIMEOUT }, ); - if (!response.data?.fullPath) { + if (!image?.fullPath) { throw new Error('Upload succeeded but no URL returned'); } - this.logger.log(`Image uploaded: ${response.data.fullPath}`); - return response.data; + this.logger.log(`Image uploaded: ${image.fullPath}`); + return image; } catch (error) { // Status and a slice of the body tell FileHarbor errors apart from a proxy in front of it - const body = error.response?.data; + const body = error instanceof HeyAtomHttpError ? error.body : undefined; this.logger.error( - `Upload failed: ${error.message} (${config.endpoint}/images, status ${error.response?.status ?? 'n/a'}, body ${String(typeof body === 'string' ? body : JSON.stringify(body)).slice(0, 500)})`, + `Upload failed: ${error.message} (${config.endpoint}/images, status ${error instanceof HeyAtomHttpError ? error.status : 'n/a'}, body ${String(typeof body === 'string' ? body : JSON.stringify(body)).slice(0, 500)})`, error.stack, ); throw new InternalServerErrorException(`Upload failed: ${error.message}`); @@ -181,25 +216,15 @@ export class FileHarborService { } try { - const response = await firstValueFrom( - this.httpService.delete( - `${config.endpoint}/images/${encodeURIComponent(fileId)}`, - { - headers: { - 'X-API-Key': config.apiKey, - }, - timeout: FileHarborService.DELETE_TIMEOUT, - }, - ), - ); + const response = await this.client(config).deleteImage(fileId); this.logger.log(`Image deleted: ${fileId}`); - return response.data; + return response; } catch (error) { this.logger.error(`Delete failed for ${fileId}: ${error.message}`); // Don't throw for 404 errors (file already deleted) - if (error.response?.status === 404) { + if (error instanceof HeyAtomHttpError && error.status === 404) { this.logger.warn(`File already deleted: ${fileId}`); return { id: fileId, status: 'already_deleted' }; } @@ -245,26 +270,6 @@ export class FileHarborService { } } - /** - * Create FormData object from file and additional fields - */ - private createFormData( - file: Express.Multer.File, - additionalFields: Record, - ): FormData { - const form = new FormData(); - form.append('file', file.buffer, { - filename: file.originalname, - contentType: file.mimetype, - }); - - Object.entries(additionalFields).forEach(([key, value]) => { - form.append(key, value); - }); - - return form; - } - /** * Extract file ID from URL using multiple strategies */ diff --git a/src/modules/health/health.controller.ts b/src/modules/health/health.controller.ts index bb48ff6..b4b95ff 100644 --- a/src/modules/health/health.controller.ts +++ b/src/modules/health/health.controller.ts @@ -29,7 +29,7 @@ export class HealthController { description: 'Always returns 200. Used by container orchestrators to check if the process is alive.', }) - @ApiOkResponse({ schema: { example: { status: 'ok' } } }) + @ApiOkResponse({ schema: { example: { data: { status: 'ok' } } } }) live() { return { status: 'ok' }; } diff --git a/src/modules/interactions/interactions.controller.ts b/src/modules/interactions/interactions.controller.ts index 5fc5598..aefee25 100644 --- a/src/modules/interactions/interactions.controller.ts +++ b/src/modules/interactions/interactions.controller.ts @@ -17,6 +17,7 @@ import { ApiParam, ApiHeader, } from '@nestjs/swagger'; +import { ApiCreatedData, ApiOkData } from '@heyatom/nest-common'; import { TenantGuard } from '@/modules/tenants/guards/tenant.guard'; import { GetTenant } from '@/modules/tenants/decorators/get-tenant.decorator'; import { InteractionsService } from '@/modules/interactions/interactions.service'; @@ -62,11 +63,7 @@ export class InteractionsController { description: 'UUID of the article to like/unlike', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 201, - description: 'Like toggled successfully.', - type: LikeToggleResultDto, - }) + @ApiCreatedData(LikeToggleResultDto, 'Like toggled successfully.') @ApiResponse({ status: 400, description: 'Missing X-User-Id header or invalid articleId.', @@ -100,11 +97,10 @@ export class InteractionsController { description: 'UUID of the article to check', example: '123e4567-e89b-12d3-a456-426614174000', }) - @ApiResponse({ - status: 200, - description: 'Interaction status returned successfully.', - type: ArticleInteractionStatusDto, - }) + @ApiOkData( + ArticleInteractionStatusDto, + 'Interaction status returned successfully.', + ) @ApiResponse({ status: 400, description: 'Missing X-User-Id header or invalid articleId.', diff --git a/src/modules/reports/reports.controller.ts b/src/modules/reports/reports.controller.ts index 82abcb2..901a5c3 100644 --- a/src/modules/reports/reports.controller.ts +++ b/src/modules/reports/reports.controller.ts @@ -25,7 +25,11 @@ import { ReportListQueryDto } from '@/modules/reports/dto/report-list-query.dto' import { AuditLoggerService } from '@/modules/audits/audit-logger.service'; import { PrismaService } from '@/modules/prisma/prisma.service'; import { AuditAction, AuditResourceType, UserRole } from '@prisma/client'; -import { ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { ReportDto } from '@/modules/reports/dto/report-response.dto'; @ApiTags('Reports') @@ -46,11 +50,7 @@ export class ReportsController { 'Creates a new report for a user, article, or comment. When the report threshold is reached the target is auto-moderated.', }) @ApiBody({ type: CreateReportDto }) - @ApiResponse({ - status: 201, - description: 'Report submitted successfully.', - type: ReportDto, - }) + @ApiCreatedData(ReportDto, 'Report submitted successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -97,11 +97,7 @@ export class ReportsController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: UpdateReportStatusDto }) - @ApiResponse({ - status: 200, - description: 'Report status updated successfully.', - type: ReportDto, - }) + @ApiOkData(ReportDto, 'Report status updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/tags/tags.controller.ts b/src/modules/tags/tags.controller.ts index a56fd64..7c92376 100644 --- a/src/modules/tags/tags.controller.ts +++ b/src/modules/tags/tags.controller.ts @@ -28,7 +28,12 @@ import { UpdateTagDto } from '@/modules/tags/dto/update-tag.dto'; import { TagParamsDto } from '@/modules/tags/dto/tag-params.dto'; import { TagSlugParamsDto } from '@/modules/tags/dto/tag-slug-params.dto'; import { TagsListQuery } from '@/modules/tags/queries/tags.query'; -import { PaginatedResult, ApiPaginatedResponse } from '@heyatom/nest-common'; +import { + PaginatedResult, + ApiPaginatedResponse, + ApiCreatedData, + ApiOkData, +} from '@heyatom/nest-common'; import { TagDto } from '@/modules/tags/dto/tags.dto'; @ApiTags('Tags') @@ -45,11 +50,7 @@ export class TagsController { 'Creates a new tag for the current tenant. The slug is auto-generated from the name.', }) @ApiBody({ type: CreateTagDto }) - @ApiResponse({ - status: 201, - description: 'Tag created successfully.', - type: TagDto, - }) + @ApiCreatedData(TagDto, 'Tag created successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', @@ -88,7 +89,7 @@ export class TagsController { description: 'URL-friendly slug of the tag (e.g. "technology")', example: 'technology', }) - @ApiResponse({ status: 200, description: 'Tag found.', type: TagDto }) + @ApiOkData(TagDto, 'Tag found.') @ApiResponse({ status: 401, description: 'Missing or invalid API key.' }) @ApiResponse({ status: 404, description: 'Tag not found.' }) findOne(@GetTenant() tenant: any, @Param() params: TagSlugParamsDto) { @@ -107,11 +108,7 @@ export class TagsController { example: '123e4567-e89b-12d3-a456-426614174000', }) @ApiBody({ type: UpdateTagDto }) - @ApiResponse({ - status: 200, - description: 'Tag updated successfully.', - type: TagDto, - }) + @ApiOkData(TagDto, 'Tag updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/users/users.controller.ts b/src/modules/users/users.controller.ts index 1f186ca..a758e68 100644 --- a/src/modules/users/users.controller.ts +++ b/src/modules/users/users.controller.ts @@ -16,6 +16,7 @@ import { ApiParam, ApiBody, } from '@nestjs/swagger'; +import { ApiCreatedData } from '@heyatom/nest-common'; import { UsersService } from '@/modules/users/users.service'; import { TenantGuard } from '@/modules/tenants/guards/tenant.guard'; import { GetTenant } from '@/modules/tenants/decorators/get-tenant.decorator'; @@ -37,11 +38,7 @@ export class UsersController { 'Creates or updates a user record for the current tenant based on their external ID. Use this endpoint to keep the CMS user data in sync with your identity provider.', }) @ApiBody({ type: UpsertUserDto }) - @ApiResponse({ - status: 201, - description: 'User created or updated successfully.', - type: UserDto, - }) + @ApiCreatedData(UserDto, 'User created or updated successfully.') @ApiResponse({ status: 400, description: 'Validation error – invalid request body.', diff --git a/src/modules/webhook/webhook-http.spec.ts b/src/modules/webhook/webhook-http.spec.ts deleted file mode 100644 index 4eb2381..0000000 --- a/src/modules/webhook/webhook-http.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { createServer, RequestListener, Server } from 'node:http'; -import { AddressInfo } from 'node:net'; -import { Test } from '@nestjs/testing'; -import { HttpModule, HttpService } from '@nestjs/axios'; -import { lastValueFrom } from 'rxjs'; -import { FILEHARBOR_HTTP_OPTIONS } from '@/modules/fileharbor/fileharbor.module'; - -const listen = (handler: RequestListener) => - new Promise((resolve) => { - const server = createServer(handler); - server.listen(0, '127.0.0.1', () => resolve(server)); - }); -const urlOf = (s: Server) => - `http://127.0.0.1:${(s.address() as AddressInfo).port}`; - -describe.each([['fileharbor', FILEHARBOR_HTTP_OPTIONS]])( - '%s HTTP client', - (_name, options) => { - let http: HttpService; - let target: Server; - let redirector: Server; - let targetHits = 0; - - beforeAll(async () => { - const mod = await Test.createTestingModule({ - imports: [HttpModule.register(options)], - }).compile(); - http = mod.get(HttpService); - target = await listen((_req, res) => { - targetHits++; - res.end('x'.repeat(2 * 1024 * 1024)); - }); - redirector = await listen((_req, res) => { - res.writeHead(307, { location: `${urlOf(target)}/internal` }).end(); - }); - }); - - afterAll(() => { - target.close(); - redirector.close(); - }); - - it('does not follow redirects', async () => { - await expect( - lastValueFrom(http.post(urlOf(redirector), {})), - ).rejects.toMatchObject({ response: { status: 307 } }); - expect(targetHits).toBe(0); - }); - - it('caps the response size', async () => { - await expect(lastValueFrom(http.get(urlOf(target)))).rejects.toThrow( - /maxContentLength/, - ); - }); - - it('has a timeout', () => { - expect(http.axiosRef.defaults.timeout).toBeGreaterThan(0); - }); - }, -);