includio-cms 0.15.4 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/DOCS.md +1 -1
  3. package/ROADMAP.md +22 -8
  4. package/dist/admin/components/fields/media-field.svelte +54 -2
  5. package/dist/admin/components/media/file/file-details.svelte +65 -0
  6. package/dist/admin/remote/media.remote.d.ts +1 -0
  7. package/dist/admin/remote/media.remote.js +5 -0
  8. package/dist/cmp/types.d.ts +25 -0
  9. package/dist/cmp/types.js +1 -0
  10. package/dist/core/cms.d.ts +2 -0
  11. package/dist/core/cms.js +2 -0
  12. package/dist/core/server/cmp/getCountryFromHeaders.d.ts +10 -0
  13. package/dist/core/server/cmp/getCountryFromHeaders.js +30 -0
  14. package/dist/core/server/cmp/operations/create.d.ts +17 -0
  15. package/dist/core/server/cmp/operations/create.js +38 -0
  16. package/dist/core/server/cmp/operations/get.d.ts +2 -0
  17. package/dist/core/server/cmp/operations/get.js +8 -0
  18. package/dist/core/server/cmp/operations/list.d.ts +3 -0
  19. package/dist/core/server/cmp/operations/list.js +15 -0
  20. package/dist/core/server/cmp/truncateIpAddress.d.ts +7 -0
  21. package/dist/core/server/cmp/truncateIpAddress.js +57 -0
  22. package/dist/core/server/fields/resolveImageFields.d.ts +5 -0
  23. package/dist/core/server/fields/resolveImageFields.js +9 -1
  24. package/dist/core/server/generator/generator.js +22 -6
  25. package/dist/core/server/media/operations/backgroundMaintenance.js +51 -20
  26. package/dist/core/server/media/operations/findMediaReferences.d.ts +16 -0
  27. package/dist/core/server/media/operations/findMediaReferences.js +60 -0
  28. package/dist/db-postgres/index.js +46 -1
  29. package/dist/db-postgres/schema/consentLog.d.ts +17 -0
  30. package/dist/db-postgres/schema/consentLog.js +4 -1
  31. package/dist/paraglide/messages/_index.d.ts +36 -3
  32. package/dist/paraglide/messages/_index.js +71 -3
  33. package/dist/paraglide/messages/en.d.ts +5 -0
  34. package/dist/paraglide/messages/en.js +14 -0
  35. package/dist/paraglide/messages/pl.d.ts +5 -0
  36. package/dist/paraglide/messages/pl.js +14 -0
  37. package/dist/sveltekit/server/handle.js +1 -1
  38. package/dist/types/adapters/db.d.ts +7 -1
  39. package/dist/types/cms.d.ts +3 -0
  40. package/dist/types/consent.d.ts +11 -0
  41. package/dist/updates/0.15.5/index.d.ts +2 -0
  42. package/dist/updates/0.15.5/index.js +15 -0
  43. package/dist/updates/0.16.0/index.d.ts +2 -0
  44. package/dist/updates/0.16.0/index.js +14 -0
  45. package/dist/updates/index.js +3 -1
  46. package/package.json +1 -1
  47. package/dist/demo/seed.d.ts +0 -1
  48. package/dist/demo/seed.js +0 -117
  49. package/dist/inline-edit-proto/ModeToggle.svelte +0 -36
  50. package/dist/inline-edit-proto/ModeToggle.svelte.d.ts +0 -18
  51. package/dist/inline-edit-proto/blocks/AddBlockButton.svelte +0 -47
  52. package/dist/inline-edit-proto/blocks/AddBlockButton.svelte.d.ts +0 -8
  53. package/dist/inline-edit-proto/blocks/BlockToolbar.svelte +0 -80
  54. package/dist/inline-edit-proto/blocks/BlockToolbar.svelte.d.ts +0 -13
  55. package/dist/inline-edit-proto/blocks/BlockWrapper.svelte +0 -83
  56. package/dist/inline-edit-proto/blocks/BlockWrapper.svelte.d.ts +0 -11
  57. package/dist/inline-edit-proto/context.svelte.d.ts +0 -65
  58. package/dist/inline-edit-proto/context.svelte.js +0 -194
  59. package/dist/inline-edit-proto/hybrid/EditableHybrid.svelte +0 -70
  60. package/dist/inline-edit-proto/hybrid/EditableHybrid.svelte.d.ts +0 -11
  61. package/dist/inline-edit-proto/hybrid/FieldRenderer.svelte +0 -94
  62. package/dist/inline-edit-proto/hybrid/FieldRenderer.svelte.d.ts +0 -11
  63. package/dist/inline-edit-proto/hybrid/HybridEditor.svelte +0 -107
  64. package/dist/inline-edit-proto/hybrid/HybridEditor.svelte.d.ts +0 -7
  65. package/dist/inline-edit-proto/hybrid/SyncPanel.svelte +0 -181
  66. package/dist/inline-edit-proto/hybrid/SyncPanel.svelte.d.ts +0 -3
  67. package/dist/inline-edit-proto/inline/EditableInline.svelte +0 -120
  68. package/dist/inline-edit-proto/inline/EditableInline.svelte.d.ts +0 -11
  69. package/dist/inline-edit-proto/inline/InlineToolbar.svelte +0 -71
  70. package/dist/inline-edit-proto/inline/InlineToolbar.svelte.d.ts +0 -6
  71. package/dist/inline-edit-proto/panel/EditSheet.svelte +0 -130
  72. package/dist/inline-edit-proto/panel/EditSheet.svelte.d.ts +0 -3
  73. package/dist/inline-edit-proto/panel/EditablePanel.svelte +0 -44
  74. package/dist/inline-edit-proto/panel/EditablePanel.svelte.d.ts +0 -9
  75. package/dist/paraglide/messages/hello_world.d.ts +0 -5
  76. package/dist/paraglide/messages/hello_world.js +0 -33
  77. package/dist/paraglide/messages/login_hello.d.ts +0 -16
  78. package/dist/paraglide/messages/login_hello.js +0 -34
  79. package/dist/paraglide/messages/login_please_login.d.ts +0 -16
  80. package/dist/paraglide/messages/login_please_login.js +0 -34
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to includio-cms are documented here.
4
4
  Generated from `src/lib/updates/` — do not edit manually.
5
5
 
6
+ ## 0.16.0 — 2026-04-29
7
+
8
+ Hard reset martwego kodu — start drogi do v1.0.0. Wycięte: prototyp inline-edit, demo seed, demo routes. Zostają: cmp/ (backend działa), mockups/ (designy), isomorphic-dompurify (Faza 5), tippy.js (slash-command).
9
+
10
+ ### Breaking
11
+ - `src/lib/inline-edit-proto/` — usunięty. Prototyp hybrid editor (`HybridEditor`, `EditableInline`, `EditablePanel`, `BlockWrapper`, `ModeToggle` itd.) skasowany w całości. Inline edit zostanie zaprojektowany od zera w v1.x z innym podejściem. Pełen kod zarchiwizowany lokalnie na branchu `archive/inline-edit-proto` (niepublikowany na origin). Projekty importujące cokolwiek z `$lib/inline-edit-proto/*` lub `includio-cms/inline-edit-proto` muszą wyciąć te wywołania — moduł nigdy nie był publikowany w `package.json` exports, więc realnie żadna external integracja się nie zerwie.
12
+ - `src/lib/demo/seed.ts` — usunięte. Funkcja `seedDemoData()` (wpisywanie demo użytkownika `demo@includio.dev`) skasowana. Demo content zostanie zaprojektowany od zera w v1.x.
13
+ - `src/routes/(site)/demo/` i `src/routes/admin/(afterLogin)/demo/` — usunięte. Demo pages (`/demo`, `/demo/inline-edit-test`, `/admin/demo/hybrid-editor`) skasowane razem z modułami. Live preview demo trzeba odbudować od zera.
14
+ - `ROADMAP-EDITOR.md` — usunięty. Plan unified editora (Faza 0.2.0–0.5.0) zarchiwizowany razem z prototypem na branchu `archive/inline-edit-proto`.
15
+
16
+ ### Notes
17
+
18
+ Brak SQL migration. Brak zmian publicznego API w `package.json` exports — `inline-edit-proto`, `demo`, ani `cmp` nigdy nie były tam wymienione, więc `pnpm i` w projekcie konsumującym przejdzie clean. `cmp/` ZOSTAJE: backend CMP (operations, `consent_logs` schema, public `createConsentLog`) i typy publiczne (`ResolvedCmpConfig`, `CmpStrings` w `CMSConfig.cmp`) działają bez zmian. Frontend banner dla CMP wróci jako feature w v1.x. Backlog `ideas/*.md` przeniesiony do `ideas/post-v1/` (lokalnie, katalog w `.gitignore`); `select-field-defaultvalue-bug.md` promowany do ROADMAP jako fix do v1.0. Bundle delta: `dist/` 8.8M → 8.5M (−0.3 MB) — mniej niż meta-plan szacował (−1.5 MB+), bo `inline-edit-proto/` był w `.gitignore` i nigdy nie trafiał do `dist/`. Realny zysk to czystsza struktura repo + zero martwego kodu w gałęzi roboczej.
19
+
20
+ ## 0.15.5 — 2026-04-23
21
+
22
+ Media field recovers from orphan references; delete dialog shows usage breakdown + replace hint. X-Frame-Options relaxed to SAMEORIGIN. Background maintenance no longer duplicates on Vite HMR. Runtime generator no longer triggers an infinite SSR reload loop in dev.
23
+
24
+ ### Added
25
+ - Admin media library: delete dialog (`FileDetails`) teraz pokazuje breakdown użyć pliku per kolekcja/single ("Plik jest używany w: Strony: 1") oraz hint wskazujący na funkcję **Zamień plik** (która zachowuje ID → wszystkie referencje). Dane ładowane asynchronicznie przez nowy remote query `findMediaReferences(id)` uruchamiany w momencie otwarcia dialogu. Scope (MVP): tylko najnowsza wersja per entry; historia poza zakresem. Walker po schematach (`media`, `file`, `seo.ogImage`, `object`, `blocks`, `content` z inline blocks) wyekstrahowany z `resolveImageFields.ts` jako reużywalne `extractMediaIdsFromData(data, fields)`.
26
+
27
+ ### Fixed
28
+ - `media-field.svelte` nie blokuje już edycji entry gdy pole media wskazuje na usunięty plik (orphan reference). Wcześniej render wchodził w `{:else if singleFile}` z `singleFile=null` po nieudanym `getFileById`, co wyrzucało UI do pustego diva bez przycisków Zmień/Usuń — user zablokowany, nie mógł wstawić nowego obrazu. Nowa gałąź `{:else}` renderuje dashed warning placeholder ("Brakujący plik" / "Missing file") z zachowanymi kontrolkami. Analogicznie dla multi-media: per-item fallback pozwala usunąć pojedynczy orphan z tablicy bez czyszczenia pozostałych.
29
+ - `X-Frame-Options` zmieniony z `DENY` na `SAMEORIGIN` w middleware `securityHeaders`. Wcześniej `DENY` blokował nawet same-origin framing, przez co admin CMS nie mógł załadować preview entry w iframe (`previewUrl` w konfiguracji kolekcji/single). Safari egzekwuje to rygorystycznie ("Refused to display ... in a frame because it set X-Frame-Options to DENY"). `SAMEORIGIN` dalej chroni przed clickjackingiem z obcych domen.
30
+ - `startBackgroundMaintenance()` jest teraz idempotentne. Wcześniej każde wywołanie tworzyło nowy `setTimeout`/`setInterval` bez czyszczenia poprzedniego — w `pnpm dev` Vite HMR re-executuje `hooks.server.ts` (i tym samym `initCMS()`) przy każdej zmianie, więc po kilku edycjach działało N równoległych przebiegów maintenance. Stan timerów (`pendingTimeout`, `timer`, `running`, `lastResult`, `nextRunAt`) przeniesiony na `globalThis[Symbol.for("includio.maintenance.state")]`, żeby przeżył re-eval modułu w dev. Dodany guard: gdy timer już zaplanowany, kolejne `start()` loguje `already scheduled, skipping` i wychodzi. `stopBackgroundMaintenance()` teraz czyści również initial 30s `setTimeout`, nie tylko interval. Dodany `import.meta.hot.dispose()` czyszczący timery gdy Vite unlinkuje moduł.
31
+ - `generateRuntime()` (`generator.ts`) nie zapisuje już plików gdy treść się nie zmieniła. Wcześniej każdy wywołanie `includioCMS()` (a więc każdy SSR reload Vite) bezwarunkowo `writeFileSync` na 5 plikach w `src/lib/cms/runtime/` (`api.ts`, `types.ts`, `schemas.ts`, `schema.ts`, `remote.ts`) — co aktualizowało mtime, Vite wykrywał zmianę, robił `(ssr) page reload`, znów wołał `includioCMS()` → znów zapis → nieskończona pętla reload w `pnpm dev`, blokująca pracę. Nowy helper `writeIfChanged(filePath, content)` najpierw czyta plik i zapisuje wyłącznie gdy treść się różni.
32
+
6
33
  ## 0.15.4 — 2026-04-21
7
34
 
8
35
  Forms: auto-scaffolded public submission endpoint + decoupled notification emails from submission success.
package/DOCS.md CHANGED
@@ -1,4 +1,4 @@
1
- # Includio CMS Documentation (v0.15.4)
1
+ # Includio CMS Documentation (v0.16.0)
2
2
 
3
3
  > This file is auto-generated from the docs site. For the latest version, update the package.
4
4
 
package/ROADMAP.md CHANGED
@@ -324,17 +324,31 @@
324
324
  - [x] `[fix]` `[P0]` `createFormSubmission` — split try/catch so SMTP failure no longer returns `false` (endpoint responded 500 even though submission was persisted); notification email is best-effort, logged via `console.error` <!-- files: src/lib/core/server/forms/submissions/operations/create.ts -->
325
325
  - [ ] `[feature]` `[P1]` Built-in `/api/health` + `/api/health/ready` with per-adapter checks (db/files/email/ai) + ręczny SMTP diagnostics panel in maintenance page <!-- files: ideas/health-check-module.md -->
326
326
 
327
- ## 0.16.0 — SEO module
327
+ ## 0.16.0 — Hard reset
328
328
 
329
- - [ ] `[feature]` `[P1]` SERP preview + character limits for title/description <!-- files: src/lib/admin/components/fields/seo-field.svelte -->
330
- - [ ] `[feature]` `[P1]` Global SEO settings
331
- - [ ] `[feature]` `[P1]` Dedicated frontend SEO components <!-- files: src/lib/sveltekit/components/seo.svelte -->
332
- - [ ] `[feature]` `[P2]` Sitemap generation
329
+ > Start drogi do v1.0.0. Decyzje: **[V1-DECISIONS.md](./V1-DECISIONS.md)** | Workflow: **[V1-WORKFLOW.md](./V1-WORKFLOW.md)**
333
330
 
334
- ## 0.17.0 WCAG/ATAG compliance
331
+ - [x] `[breaking]` `[P0]` Wycięty `src/lib/inline-edit-proto/` (kod na lokalnym branchu `archive/inline-edit-proto`) — inline edit od zera w v1.x
332
+ - [x] `[breaking]` `[P0]` Wycięty `src/lib/demo/seed.ts` + demo routes (`/demo/*`, `/admin/demo/*`) — demo content od zera w v1.x
333
+ - [x] `[breaking]` `[P0]` Skasowany `ROADMAP-EDITOR.md` (treść na archive branch)
334
+ - [x] `[chore]` `[P2]` `ideas/*.md` przeniesione do `ideas/post-v1/` (lokalnie, w `.gitignore`); `select-field-defaultvalue-bug` promowany do v1.0 fix
335
+ - [x] `[chore]` `[P2]` `V1-DECISIONS.md` jako referencja decyzji v1 dla każdej kolejnej sesji
335
336
 
336
- - [ ] `[chore]` `[P0]` Full WCAG/ATAG audit
337
- - [ ] `[feature]` `[P0]` Accessibility rework based on audit findings
337
+ ## v1.0.0 Stabilizacja (in progress)
338
+
339
+ > 13 faz w ~16 sesjach, droga 0.16 → 1.0.0. Lean scope: stabilizacja, security, testy, docs, audit + polish shopa. Bez nowych feature'ów.
340
+
341
+ - [ ] `[fix]` `[P1]` Select field — `defaultValue` propagacja do zod schema (full repro: `ideas/post-v1/select-field-defaultvalue-bug.md`); fix planowany w Fazie 12 (RC)
342
+
343
+ ## v1.x — Post-v1.0 deferred
344
+
345
+ - [ ] `[feature]` `[P1]` SEO module — SERP preview, char limits, global settings, frontend components, sitemap (full plan: `ideas/post-v1/seo-aeo-geo-module.md`)
346
+ - [ ] `[feature]` `[P0]` WCAG/ATAG compliance — full audit + accessibility rework
347
+ - [ ] `[feature]` `[P1]` CMP frontend banner — backend już działa (operations, `consent_logs`, `createConsentLog`); brakuje banner UI (`ideas/post-v1/cmp-module.md`)
348
+ - [ ] `[feature]` `[P1]` Health check module — `/api/health` + `/api/health/ready` (`ideas/post-v1/health-check-module.md`)
349
+ - [ ] `[feature]` `[P2]` Cache layer dla `getEntries` / `getEntry` / `countEntries` (`ideas/post-v1/cache-layer.md`)
350
+ - [ ] `[feature]` `[P2]` Configurable sidebar (`ideas/post-v1/configurable-sidebar.md`)
351
+ - [ ] `[feature]` `[P0]` Plugin hooks in CRUD ops + plugin registration API
338
352
 
339
353
  ## Security hardening
340
354
 
@@ -30,6 +30,7 @@
30
30
  a11yMissingAudioDesc: string;
31
31
  a11yMissingBoth: string;
32
32
  a11yHint: string;
33
+ missingFile: string;
33
34
  }
34
35
  > = {
35
36
  pl: {
@@ -41,7 +42,8 @@
41
42
  a11yMissingTranscript: 'Brakuje transkrypcji',
42
43
  a11yMissingAudioDesc: 'Brakuje audiodeskrypcji',
43
44
  a11yMissingBoth: 'Brakuje transkrypcji i audiodeskrypcji',
44
- a11yHint: 'Uzupełnij w bibliotece mediów'
45
+ a11yHint: 'Uzupełnij w bibliotece mediów',
46
+ missingFile: 'Brakujący plik'
45
47
  },
46
48
  en: {
47
49
  selectMedia: 'Select media',
@@ -52,7 +54,8 @@
52
54
  a11yMissingTranscript: 'Transcript missing',
53
55
  a11yMissingAudioDesc: 'Audio description missing',
54
56
  a11yMissingBoth: 'Transcript and audio description missing',
55
- a11yHint: 'Add it in the media library'
57
+ a11yHint: 'Add it in the media library',
58
+ missingFile: 'Missing file'
56
59
  }
57
60
  };
58
61
 
@@ -195,6 +198,17 @@
195
198
  </button>
196
199
  {/snippet}
197
200
 
201
+ {#snippet missingPlaceholder()}
202
+ <div
203
+ class="flex aspect-square w-full flex-col items-center justify-center gap-2 rounded-2xl border-2 border-dashed border-warning/50 bg-warning/5 p-6"
204
+ >
205
+ <div class="rounded-full bg-warning/10 p-3">
206
+ <AlertTriangle class="h-6 w-6 text-warning" />
207
+ </div>
208
+ <span class="text-sm text-warning">{lang[interfaceLanguage.current].missingFile}</span>
209
+ </div>
210
+ {/snippet}
211
+
198
212
  {#snippet mediaActions(onRemove: () => void)}
199
213
  <div class="flex items-center justify-between gap-2 mt-1.5">
200
214
  <Button size="sm" variant="secondary" class="h-8" onclick={openPicker}>
@@ -224,6 +238,9 @@
224
238
  {@render imagePreview(file)}
225
239
  {/if}
226
240
  {@render mediaActions(() => { value = ''; })}
241
+ {:else}
242
+ {@render missingPlaceholder()}
243
+ {@render mediaActions(() => { value = ''; })}
227
244
  {/if}
228
245
  {:else if Array.isArray(value) && value.length > 0}
229
246
  {@const valueArr = value}
@@ -262,7 +279,42 @@
262
279
  {/if}
263
280
  </div>
264
281
  {@render mediaActions(() => { value = field.multiple ? [] : ''; })}
282
+ {:else}
283
+ <div class="relative">
284
+ {@render missingPlaceholder()}
285
+ {#if valueArr.length > 1}
286
+ <div class="absolute inset-x-0 top-1/2 flex -translate-y-1/2 justify-between px-1 pointer-events-none">
287
+ <button
288
+ type="button"
289
+ class="pointer-events-auto flex h-8 w-8 items-center justify-center rounded-full bg-white/80 backdrop-blur shadow-md transition hover:bg-white hover:scale-105 dark:bg-background/80 dark:hover:bg-background"
290
+ onclick={() => { currentIndex = currentIndex > 0 ? currentIndex - 1 : valueArr.length - 1; }}
291
+ >
292
+ <ChevronLeft class="h-5 w-5" />
293
+ </button>
294
+ <button
295
+ type="button"
296
+ class="pointer-events-auto flex h-8 w-8 items-center justify-center rounded-full bg-white/80 backdrop-blur shadow-md transition hover:bg-white hover:scale-105 dark:bg-background/80 dark:hover:bg-background"
297
+ onclick={() => { currentIndex = currentIndex < valueArr.length - 1 ? currentIndex + 1 : 0; }}
298
+ >
299
+ <ChevronRight class="h-5 w-5" />
300
+ </button>
301
+ </div>
302
+ <div class="absolute top-2 right-2 rounded-full bg-plum-darker/60 px-2 py-0.5 text-xs font-medium text-white backdrop-blur">
303
+ {currentIndex + 1} / {valueArr.length}
304
+ </div>
305
+ {/if}
306
+ </div>
307
+ {@render mediaActions(() => {
308
+ if (Array.isArray(value)) {
309
+ const next = value.filter((_, i) => i !== currentIndex);
310
+ value = field.multiple ? next : next[0] ?? '';
311
+ if (currentIndex >= next.length) currentIndex = Math.max(0, next.length - 1);
312
+ }
313
+ })}
265
314
  {/if}
315
+ {:else}
316
+ {@render missingPlaceholder()}
317
+ {@render mediaActions(() => { value = field.multiple ? [] : ''; })}
266
318
  {/if}
267
319
  {/if}
268
320
  </div>
@@ -31,6 +31,19 @@
31
31
  let deleteDialogOpen = $state(false);
32
32
  let videoError = $state(false);
33
33
 
34
+ type ReferenceResult = {
35
+ total: number;
36
+ byCollection: Array<{ collection: string; label: string; count: number; kind: 'collection' | 'single' }>;
37
+ };
38
+
39
+ const referencesQuery = $derived(
40
+ deleteDialogOpen ? remotes.findMediaReferences(file.id) : null
41
+ );
42
+ const referencesLoading = $derived(!!referencesQuery && !referencesQuery.ready);
43
+ const references = $derived(
44
+ referencesQuery && referencesQuery.ready ? (referencesQuery.current as ReferenceResult) : null
45
+ );
46
+
34
47
  $effect(() => {
35
48
  file.url;
36
49
  videoError = false;
@@ -43,6 +56,12 @@
43
56
  deleteConfirmTitle: string;
44
57
  deleteConfirmDesc: string;
45
58
  deleteCancel: string;
59
+ usedInLoading: string;
60
+ usedInTitle: string;
61
+ missingAfterDelete: string;
62
+ replaceHintBefore: string;
63
+ replaceHintCta: string;
64
+ replaceHintAfter: string;
46
65
  fileNameLabel: string;
47
66
  fileUrlLabel: string;
48
67
  fileAltLabel: string;
@@ -81,6 +100,12 @@
81
100
  deleteConfirmTitle: 'Usunąć plik?',
82
101
  deleteConfirmDesc: 'Plik zostanie trwale usunięty.',
83
102
  deleteCancel: 'Anuluj',
103
+ usedInLoading: 'Liczenie użyć…',
104
+ usedInTitle: 'Plik jest używany w:',
105
+ missingAfterDelete: 'Po usunięciu te pola zostaną oznaczone jako brakujące.',
106
+ replaceHintBefore: 'Jeśli chcesz tylko zmienić obraz, użyj funkcji',
107
+ replaceHintCta: 'Zamień plik',
108
+ replaceHintAfter: ' — zachowa wszystkie referencje.',
84
109
  replaceFileLabel: 'Zamień plik',
85
110
  fileNameLabel: 'Nazwa pliku',
86
111
  fileUrlLabel: 'URL',
@@ -118,6 +143,12 @@
118
143
  deleteConfirmTitle: 'Delete file?',
119
144
  deleteConfirmDesc: 'The file will be permanently deleted.',
120
145
  deleteCancel: 'Cancel',
146
+ usedInLoading: 'Counting usages…',
147
+ usedInTitle: 'This file is used in:',
148
+ missingAfterDelete: 'After deletion these fields will be marked as missing.',
149
+ replaceHintBefore: 'If you only want to change the image, use the',
150
+ replaceHintCta: 'Replace file',
151
+ replaceHintAfter: ' action — it keeps all references intact.',
121
152
  fileNameLabel: 'File name',
122
153
  fileUrlLabel: 'URL',
123
154
  fileAltLabel: 'Alt text',
@@ -565,6 +596,40 @@
565
596
  <AlertDialog.Content>
566
597
  <AlertDialog.Title>{lang[interfaceLanguage.current].deleteConfirmTitle}</AlertDialog.Title>
567
598
  <AlertDialog.Description>{lang[interfaceLanguage.current].deleteConfirmDesc}</AlertDialog.Description>
599
+
600
+ {#if referencesLoading}
601
+ <div class="mt-2 flex items-center gap-2 text-sm text-muted-foreground">
602
+ <div class="h-3 w-3 animate-pulse rounded-full bg-muted"></div>
603
+ <span>{lang[interfaceLanguage.current].usedInLoading}</span>
604
+ </div>
605
+ {:else if references && references.total > 0}
606
+ <div class="mt-2 space-y-3 text-sm">
607
+ <div class="rounded-md border border-warning/40 bg-warning/5 p-3">
608
+ <div class="flex items-start gap-2">
609
+ <AlertTriangle class="h-4 w-4 text-warning mt-0.5 shrink-0" />
610
+ <div class="flex-1 min-w-0">
611
+ <p class="font-medium text-foreground">{lang[interfaceLanguage.current].usedInTitle}</p>
612
+ <ul class="mt-1.5 space-y-0.5">
613
+ {#each references.byCollection as ref}
614
+ <li class="text-muted-foreground">
615
+ <span class="font-medium text-foreground">{ref.label}</span>: {ref.count}
616
+ </li>
617
+ {/each}
618
+ </ul>
619
+ <p class="mt-2 text-xs text-muted-foreground">{lang[interfaceLanguage.current].missingAfterDelete}</p>
620
+ </div>
621
+ </div>
622
+ </div>
623
+ <p class="text-xs text-muted-foreground">
624
+ {lang[interfaceLanguage.current].replaceHintBefore}
625
+ <span class="inline-flex items-center gap-1 rounded border border-border bg-muted/50 px-1.5 py-0.5 font-medium text-foreground">
626
+ <Replace class="h-3 w-3" />
627
+ {lang[interfaceLanguage.current].replaceHintCta}
628
+ </span>{lang[interfaceLanguage.current].replaceHintAfter}
629
+ </p>
630
+ </div>
631
+ {/if}
632
+
568
633
  <AlertDialog.Footer>
569
634
  <AlertDialog.Cancel>{lang[interfaceLanguage.current].deleteCancel}</AlertDialog.Cancel>
570
635
  <AlertDialog.Action
@@ -33,6 +33,7 @@ export declare const getMediaTagsWithCounts: import("@sveltejs/kit").RemoteQuery
33
33
  count: number;
34
34
  }[]>;
35
35
  export declare const getFileById: import("@sveltejs/kit").RemoteQueryFunction<string, MediaFile | null>;
36
+ export declare const findMediaReferences: import("@sveltejs/kit").RemoteQueryFunction<string, import("../../core/server/media/operations/findMediaReferences.js").MediaReferenceResult>;
36
37
  export declare const deleteMediaFile: import("@sveltejs/kit").RemoteCommand<string, Promise<void>>;
37
38
  export declare const bulkDeleteMediaFiles: import("@sveltejs/kit").RemoteCommand<{
38
39
  ids: string[];
@@ -2,6 +2,7 @@ import { command, query } from '$app/server';
2
2
  import { setAlt, renameMediaFile as renameMediaFileOperation, updateMediaAccessibility as updateMediaAccessibilityOp } from '../../core/server/media/operations/updateFile.js';
3
3
  import z from 'zod';
4
4
  import { deleteMediaFile as deleteMediaFileFn, bulkDeleteMediaFiles as bulkDeleteMediaFilesFn } from '../../core/server/media/operations/deleteMediaFile.js';
5
+ import { findMediaReferences as findMediaReferencesFn } from '../../core/server/media/operations/findMediaReferences.js';
5
6
  import { getFile, getFiles, countFiles, getMediaTagsWithCounts as getMediaTagsWithCountsFn } from '../../core/server/media/operations/getFiles.js';
6
7
  import { getMediaTags as getMediaTagsFn, createMediaTag as createMediaTagFn, updateMediaTag as updateMediaTagFn, deleteMediaTag as deleteMediaTagFn, setMediaFileTags as setMediaFileTagsFn, bulkSetMediaFileTags as bulkSetMediaFileTagsFn } from '../../core/server/media/operations/tags.js';
7
8
  import { requireAuth } from './middleware/auth.js';
@@ -70,6 +71,10 @@ export const getMediaTagsWithCounts = query(async () => {
70
71
  export const getFileById = query(z.string().uuid(), async (id) => {
71
72
  return getFile(id);
72
73
  });
74
+ export const findMediaReferences = query(z.string().uuid(), async (id) => {
75
+ requireAuth();
76
+ return findMediaReferencesFn(id);
77
+ });
73
78
  export const deleteMediaFile = command(z.string().uuid(), async (id) => {
74
79
  requireAuth();
75
80
  return deleteMediaFileFn(id);
@@ -0,0 +1,25 @@
1
+ export interface ResolvedCmpConfig {
2
+ enabled: boolean;
3
+ version: string;
4
+ policyVersion: string;
5
+ gtmConsentMode: boolean;
6
+ categories: {
7
+ analytics: boolean;
8
+ marketing: boolean;
9
+ preferences: boolean;
10
+ };
11
+ strings: Record<string, CmpStrings>;
12
+ }
13
+ export interface CmpStrings {
14
+ bannerTitle?: string;
15
+ bannerBody?: string;
16
+ acceptAll?: string;
17
+ rejectAll?: string;
18
+ customize?: string;
19
+ settingsTitle?: string;
20
+ save?: string;
21
+ necessary?: string;
22
+ analytics?: string;
23
+ marketing?: string;
24
+ preferences?: string;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -10,6 +10,7 @@ import type { AIAdapter } from '../types/adapters/ai.js';
10
10
  import type { EmailAdapter } from '../types/adapters/email.js';
11
11
  import { betterAuth } from 'better-auth';
12
12
  import type { ResolvedShopConfig } from '../shop/types.js';
13
+ import type { ResolvedCmpConfig } from '../cmp/types.js';
13
14
  export declare class CMS implements ICMS {
14
15
  private config;
15
16
  databaseAdapter: DatabaseAdapter;
@@ -26,6 +27,7 @@ export declare class CMS implements ICMS {
26
27
  typographyConfig: TypographyConfig;
27
28
  sidebarHelp: boolean;
28
29
  shopConfig: ResolvedShopConfig | null;
30
+ cmpConfig: ResolvedCmpConfig | null;
29
31
  plugins: PluginConfig[];
30
32
  customFields: Map<string, CustomFieldDefinition>;
31
33
  apiKeys: ApiKeyConfig[];
package/dist/core/cms.js CHANGED
@@ -20,6 +20,7 @@ export class CMS {
20
20
  typographyConfig;
21
21
  sidebarHelp;
22
22
  shopConfig;
23
+ cmpConfig;
23
24
  plugins = [];
24
25
  customFields = new Map();
25
26
  apiKeys = [];
@@ -34,6 +35,7 @@ export class CMS {
34
35
  this.typographyConfig = config.typography || {};
35
36
  this.sidebarHelp = config.sidebarHelp ?? true;
36
37
  this.shopConfig = config.shop ?? null;
38
+ this.cmpConfig = config.cmp ?? null;
37
39
  this.collections = {};
38
40
  this.singles = {};
39
41
  this.forms = {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Extract 2-letter ISO country code from request headers.
3
+ * Priority:
4
+ * 1. `cf-ipcountry` (Cloudflare)
5
+ * 2. `x-vercel-ip-country` (Vercel)
6
+ * 3. `x-country-code` (generic proxy)
7
+ * 4. Fallback: parse `Accept-Language` region subtag (e.g. `pl-PL` → `PL`)
8
+ * Returns 'XX' when no reliable source available.
9
+ */
10
+ export declare function getCountryFromHeaders(headers: Headers): string;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Extract 2-letter ISO country code from request headers.
3
+ * Priority:
4
+ * 1. `cf-ipcountry` (Cloudflare)
5
+ * 2. `x-vercel-ip-country` (Vercel)
6
+ * 3. `x-country-code` (generic proxy)
7
+ * 4. Fallback: parse `Accept-Language` region subtag (e.g. `pl-PL` → `PL`)
8
+ * Returns 'XX' when no reliable source available.
9
+ */
10
+ export function getCountryFromHeaders(headers) {
11
+ const providerCountry = headers.get('cf-ipcountry') ??
12
+ headers.get('x-vercel-ip-country') ??
13
+ headers.get('x-country-code');
14
+ if (providerCountry) {
15
+ const normalized = providerCountry.trim().toUpperCase();
16
+ if (/^[A-Z]{2}$/.test(normalized))
17
+ return normalized;
18
+ }
19
+ const acceptLanguage = headers.get('accept-language');
20
+ if (acceptLanguage) {
21
+ const first = acceptLanguage.split(',')[0].trim();
22
+ const region = first.split('-')[1] ?? first.split('_')[1];
23
+ if (region) {
24
+ const normalized = region.split(';')[0].trim().toUpperCase();
25
+ if (/^[A-Z]{2}$/.test(normalized))
26
+ return normalized;
27
+ }
28
+ }
29
+ return 'XX';
30
+ }
@@ -0,0 +1,17 @@
1
+ import type { RequestEvent } from '@sveltejs/kit';
2
+ import type { ConsentLogData } from '../../../../types/consent.js';
3
+ export interface CreateCmpConsentLogInput {
4
+ consents: ConsentLogData['consents'];
5
+ consentModeStatus: ConsentLogData['consentModeStatus'];
6
+ parentLogId?: string | null;
7
+ }
8
+ export interface CreateCmpConsentLogResult {
9
+ id: string;
10
+ timestamp: Date;
11
+ }
12
+ /**
13
+ * Creates a consent log from a SvelteKit request event.
14
+ * Extracts IP/UA/URL/language from headers, truncates the IP,
15
+ * pulls cmpVersion/policyVersion from the CMS cmpConfig.
16
+ */
17
+ export declare function createCmpConsentLog(event: RequestEvent, input: CreateCmpConsentLogInput): Promise<CreateCmpConsentLogResult>;
@@ -0,0 +1,38 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ import { getCMS } from '../../../cms.js';
3
+ import { truncateIpAddress } from '../truncateIpAddress.js';
4
+ import { getCountryFromHeaders } from '../getCountryFromHeaders.js';
5
+ /**
6
+ * Creates a consent log from a SvelteKit request event.
7
+ * Extracts IP/UA/URL/language from headers, truncates the IP,
8
+ * pulls cmpVersion/policyVersion from the CMS cmpConfig.
9
+ */
10
+ export async function createCmpConsentLog(event, input) {
11
+ const cms = getCMS();
12
+ if (!cms.cmpConfig) {
13
+ throw new Error('CMP is not configured. Pass `cmp: defineCmp({...})` to your CMS config.');
14
+ }
15
+ const rawIp = event.request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ??
16
+ event.request.headers.get('x-real-ip') ??
17
+ event.getClientAddress();
18
+ const ipAddressTruncated = truncateIpAddress(rawIp);
19
+ const countryCode = getCountryFromHeaders(event.request.headers);
20
+ const language = event.request.headers.get('accept-language')?.split(',')[0]?.trim() ?? 'unknown';
21
+ const userAgent = event.request.headers.get('user-agent') ?? 'unknown';
22
+ const url = event.request.headers.get('referer') ?? event.url.toString();
23
+ const data = {
24
+ id: uuidv4(),
25
+ ipAddressTruncated,
26
+ countryCode,
27
+ language,
28
+ userAgent,
29
+ url,
30
+ consents: input.consents,
31
+ consentModeStatus: input.consentModeStatus,
32
+ cmpVersion: cms.cmpConfig.version,
33
+ policyVersion: cms.cmpConfig.policyVersion,
34
+ parentLogId: input.parentLogId ?? null
35
+ };
36
+ await cms.databaseAdapter.createConsentLog(data);
37
+ return { id: data.id, timestamp: new Date() };
38
+ }
@@ -0,0 +1,2 @@
1
+ import type { ConsentLogRecord } from '../../../../types/consent.js';
2
+ export declare function getConsentLog(id: string): Promise<ConsentLogRecord | null>;
@@ -0,0 +1,8 @@
1
+ import { getCMS } from '../../../cms.js';
2
+ export async function getConsentLog(id) {
3
+ const adapter = getCMS().databaseAdapter;
4
+ if (!adapter.getConsentLog) {
5
+ throw new Error('Database adapter does not implement getConsentLog. Use includio-cms db-postgres ≥ 0.16.0 or implement the method.');
6
+ }
7
+ return adapter.getConsentLog(id);
8
+ }
@@ -0,0 +1,3 @@
1
+ import type { ConsentLogRecord, GetConsentLogsFilters } from '../../../../types/consent.js';
2
+ export declare function getConsentLogs(filters?: GetConsentLogsFilters): Promise<ConsentLogRecord[]>;
3
+ export declare function countConsentLogs(filters?: Omit<GetConsentLogsFilters, 'limit' | 'offset'>): Promise<number>;
@@ -0,0 +1,15 @@
1
+ import { getCMS } from '../../../cms.js';
2
+ export async function getConsentLogs(filters = {}) {
3
+ const adapter = getCMS().databaseAdapter;
4
+ if (!adapter.getConsentLogs) {
5
+ throw new Error('Database adapter does not implement getConsentLogs. Use includio-cms db-postgres ≥ 0.16.0 or implement the method.');
6
+ }
7
+ return adapter.getConsentLogs(filters);
8
+ }
9
+ export async function countConsentLogs(filters = {}) {
10
+ const adapter = getCMS().databaseAdapter;
11
+ if (!adapter.countConsentLogs) {
12
+ throw new Error('Database adapter does not implement countConsentLogs. Use includio-cms db-postgres ≥ 0.16.0 or implement the method.');
13
+ }
14
+ return adapter.countConsentLogs(filters);
15
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * GDPR-compliant IP anonymization.
3
+ * IPv4: zero last octet (e.g. 192.168.1.42 → 192.168.1.0)
4
+ * IPv6: zero last 80 bits / keep /48 prefix (e.g. 2001:db8:abcd:1234::1 → 2001:db8:abcd::)
5
+ * Invalid input → 'unknown'
6
+ */
7
+ export declare function truncateIpAddress(ip: string | null | undefined): string;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * GDPR-compliant IP anonymization.
3
+ * IPv4: zero last octet (e.g. 192.168.1.42 → 192.168.1.0)
4
+ * IPv6: zero last 80 bits / keep /48 prefix (e.g. 2001:db8:abcd:1234::1 → 2001:db8:abcd::)
5
+ * Invalid input → 'unknown'
6
+ */
7
+ export function truncateIpAddress(ip) {
8
+ if (!ip)
9
+ return 'unknown';
10
+ const trimmed = ip.trim();
11
+ if (!trimmed)
12
+ return 'unknown';
13
+ if (trimmed.includes('.') && !trimmed.includes(':')) {
14
+ return truncateIpv4(trimmed);
15
+ }
16
+ if (trimmed.includes(':')) {
17
+ return truncateIpv6(trimmed);
18
+ }
19
+ return 'unknown';
20
+ }
21
+ function truncateIpv4(ip) {
22
+ const parts = ip.split('.');
23
+ if (parts.length !== 4)
24
+ return 'unknown';
25
+ for (let i = 0; i < 4; i++) {
26
+ const n = Number(parts[i]);
27
+ if (!Number.isInteger(n) || n < 0 || n > 255)
28
+ return 'unknown';
29
+ }
30
+ return `${parts[0]}.${parts[1]}.${parts[2]}.0`;
31
+ }
32
+ function truncateIpv6(ip) {
33
+ const stripped = ip.split('%')[0];
34
+ const doubleColon = stripped.indexOf('::');
35
+ let groups;
36
+ if (doubleColon !== -1) {
37
+ const left = stripped.slice(0, doubleColon);
38
+ const right = stripped.slice(doubleColon + 2);
39
+ const leftGroups = left ? left.split(':') : [];
40
+ const rightGroups = right ? right.split(':') : [];
41
+ const missing = 8 - leftGroups.length - rightGroups.length;
42
+ if (missing < 0)
43
+ return 'unknown';
44
+ groups = [...leftGroups, ...Array(missing).fill('0'), ...rightGroups];
45
+ }
46
+ else {
47
+ groups = stripped.split(':');
48
+ }
49
+ if (groups.length !== 8)
50
+ return 'unknown';
51
+ for (const g of groups) {
52
+ if (!/^[0-9a-fA-F]{0,4}$/.test(g))
53
+ return 'unknown';
54
+ }
55
+ const prefix = groups.slice(0, 3).map((g) => g.toLowerCase().replace(/^0+(?=.)/, '') || '0');
56
+ return `${prefix.join(':')}::`;
57
+ }
@@ -1,3 +1,8 @@
1
1
  import type { EntryData, PopulatedEntryData } from '../../../types/entries.js';
2
2
  import type { Field } from '../../../types/fields.js';
3
+ /**
4
+ * Walk entry data according to the field schema and collect all media file UUID references.
5
+ * Covers media/file/seo/object/blocks/content (incl. inline blocks inside content).
6
+ */
7
+ export declare function extractMediaIdsFromData(data: EntryData, fields: Field[]): string[];
3
8
  export declare function resolveMediaFields(data: EntryData, fields: Field[]): Promise<PopulatedEntryData>;
@@ -4,7 +4,11 @@ import { getCMS } from '../../cms.js';
4
4
  import z from 'zod';
5
5
  import { getImageStyles } from './utils/imageStyles.js';
6
6
  import { extractMediaIds as extractMediaIdsFromDoc, walkMediaNodes, walkInlineBlockNodes, cloneDoc } from '../../../admin/components/tiptap/structured-content-utils.js';
7
- export async function resolveMediaFields(data, fields) {
7
+ /**
8
+ * Walk entry data according to the field schema and collect all media file UUID references.
9
+ * Covers media/file/seo/object/blocks/content (incl. inline blocks inside content).
10
+ */
11
+ export function extractMediaIdsFromData(data, fields) {
8
12
  const mediaIds = [];
9
13
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
14
  const collectIds = (value, fields) => {
@@ -71,6 +75,10 @@ export async function resolveMediaFields(data, fields) {
71
75
  }
72
76
  };
73
77
  collectIds(data, fields);
78
+ return mediaIds;
79
+ }
80
+ export async function resolveMediaFields(data, fields) {
81
+ const mediaIds = extractMediaIdsFromData(data, fields);
74
82
  if (mediaIds.length === 0)
75
83
  return data;
76
84
  const media = await getCMS().databaseAdapter.getMediaFiles({