@bygghammar/cms-platform 0.11.0 → 0.12.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 (63) hide show
  1. package/migrations/20260728113741_f9744b19-078b-46e5-b00f-31c84aaf71ab.sql +111 -0
  2. package/migrations/20260728113757_4156a886-21fb-4a1f-9c12-acb7bb145102.sql +5 -0
  3. package/migrations/20260728113823_6e0237e1-99e3-4e1a-8a68-804b7bcdbbb8.sql +1 -0
  4. package/migrations/20260728115305_506d92b4-129f-4d2b-961f-cf76e592677e.sql +92 -0
  5. package/migrations/20260728115320_717d4447-f433-4a1d-89d2-fc8f028d4ac6.sql +1 -0
  6. package/migrations/20260728115347_c77f5a56-19db-4117-bb60-9ad692b817ab.sql +11 -0
  7. package/migrations/20260728132052_b692dcfe-a944-4a19-afd0-187f7600feb8.sql +63 -0
  8. package/migrations/20260728183318_05b05a47-ba05-4a66-ab8f-69f2688fea84.sql +209 -0
  9. package/migrations/20260728193035_84b68d27-c3f3-4516-a3a9-15fc6f476163.sql +17 -0
  10. package/migrations/20260728193707_8438ee2d-d589-4048-86e2-464fd209af80.sql +37 -0
  11. package/migrations/20260729055312_08862d7e-0279-4d4f-8709-a59b9f068c55.sql +5 -0
  12. package/migrations/20260729055348_418b7e36-4877-4304-831f-290ca73e56f3.sql +133 -0
  13. package/migrations/20260729055358_20b467e2-4efd-42c1-bd34-773ed6b77fc5.sql +3 -0
  14. package/migrations/20260729061039_306859eb-a38c-44ef-af1a-6c02a8fd84db.sql +43 -0
  15. package/migrations/20260730065600_54c25861-3355-4600-a72f-3d67b457ecb1.sql +54 -0
  16. package/migrations/20260730071745_d4904314-15ff-4c58-ac66-85e7371e04b5.sql +113 -0
  17. package/migrations/20260730071914_48163aa3-830e-4dcc-bdd4-c35be282ab87.sql +22 -0
  18. package/migrations/20260730085949_bcfc3270-ea80-4617-86a3-2555ed34a280.sql +24 -0
  19. package/migrations/20260730095256_c977c30e-b285-4041-8804-c0bd72b6d9b3.sql +13 -0
  20. package/migrations/20260730100057_e341b887-eb0e-4a74-850e-0ee5ffb70d7a.sql +38 -0
  21. package/migrations/20260730103703_d5c4e1b7-1e2c-4dd0-be4e-185c159ade69.sql +62 -0
  22. package/migrations/20260730105635_3557b7da-919e-48db-8c92-8221d68d3cf9.sql +29 -0
  23. package/migrations/20260730120308_12ff8cfb-43f9-4070-abde-61531ad3b75f.sql +73 -0
  24. package/migrations/20260730125024_1baf8926-12a2-48f4-8edc-7309941309e9.sql +18 -0
  25. package/migrations/20260730173510_feb974d1-510e-4f52-9e20-5fd0582d8952.sql +107 -0
  26. package/migrations/20260730175409_9f60743f-f5e1-418c-a700-c91fb3704db8.sql +9 -0
  27. package/migrations/20260730181224_1c52ff16-c7a2-4ef1-a0a8-e493c2c9106f.sql +7 -0
  28. package/migrations/20260730183129_933adb75-f985-4d82-ad5d-213b69fd42e5.sql +32 -0
  29. package/migrations/20260730183918_7bc7a827-2100-49f1-bc6e-24509249350b.sql +68 -0
  30. package/migrations/20260730202628_7ceade5e-644c-4bc2-91b8-594133329f31.sql +1 -0
  31. package/migrations/20260730211056_57f42049-00b4-473b-a2cd-65a13570b8d2.sql +16 -0
  32. package/migrations/20260730214340_98af2e55-9031-4c11-9659-c47a37a8d6b7.sql +1 -0
  33. package/migrations/20260731091630_8a6f28ce-5833-4901-ab17-27648cef32ec.sql +149 -0
  34. package/migrations/20260731094716_4c68a1df-83ed-4ba8-8019-fa2fe2b9681e.sql +65 -0
  35. package/migrations/20260731191655_fef97c3c-1397-47b4-8b56-afb020298e97.sql +165 -0
  36. package/migrations/20260731192212_95772a2f-19a1-4013-b463-2eb161e96737.sql +135 -0
  37. package/migrations/20260731192815_c490653e-1232-4ad9-a150-3c83d2b90f5e.sql +13 -0
  38. package/migrations/20260731193135_7966e740-5e86-4b14-8e1d-5119069666ba.sql +2 -0
  39. package/migrations/20260731193245_599790d0-ca5e-4b5d-a3e7-d69b2a79e1a3.sql +13 -0
  40. package/migrations/20260731212959_a748cb0d-4dc7-45dc-be90-f6bacbfab26c.sql +9 -0
  41. package/migrations/20260801003057_1195f4c1-fb54-42dc-9718-638a25e6a82e.sql +3 -0
  42. package/migrations/20260801003300_fc591960-cb41-41cf-837d-2eef23b29ca9.sql +40 -0
  43. package/migrations/20260802151445_a56b0023-eaf7-41e2-a7fb-d4beddfc587c.sql +3 -0
  44. package/migrations/20260802202621_d661af8a-8513-4b54-b375-f963ae824c8f.sql +225 -0
  45. package/migrations/20260802202702_c30cd837-744c-4641-85f1-edd3a7ebbcb6.sql +16 -0
  46. package/migrations/20260802202720_4418d18d-c851-42dc-9345-78fc330128ae.sql +2 -0
  47. package/migrations/20260803132514_78ba1f53-c85b-4457-96b1-7d49c5c8b494.sql +34 -0
  48. package/migrations/20260803181201_28c8aa09-baa8-431c-8338-90b1af9c8172.sql +22 -0
  49. package/migrations/20260803201518_6e8a6028-b70f-4a7d-8bc9-95c86304e7ae.sql +12 -0
  50. package/migrations/20260803201535_32a9a213-cb92-4035-b8cd-8211ca34af68.sql +12 -0
  51. package/migrations/20260811103505_29df753d-14fa-4a05-8fea-f4207785fba3.sql +35 -0
  52. package/migrations/20260811112455_217c4028-f587-4c98-9e4f-9e6c452ab761.sql +20 -0
  53. package/migrations/20260811114438_6687d67d-bad3-4803-9638-8b7670d2e5d4.sql +86 -0
  54. package/migrations/20260811130318_7cb95e95-9baa-40af-8f3f-de1d4e09cec4.sql +1 -0
  55. package/migrations/20260811220548_80d99ec2-bd4b-475d-a627-9408bb60ce56.sql +1 -0
  56. package/migrations/20260811222519_6b040f56-4de3-49e0-92e4-d9deec5ead6a.sql +3 -0
  57. package/migrations/20260812000000_seed_voyara_content.sql +390 -0
  58. package/migrations/20260818040722_1bdf1b8f-7fb0-4ae8-8ecf-73f1fadff3c2.sql +2 -0
  59. package/migrations/20260818040808_69a5e832-57e8-4aa7-aff8-7fd7777faa7c.sql +15 -0
  60. package/migrations/20260818040839_e6523163-bbf5-4a39-9233-91759059569a.sql +26 -0
  61. package/package.json +8 -4
  62. package/src/backoffice/media/ReviewImageUpload.tsx +104 -0
  63. package/src/platform/contract.ts +92 -0
@@ -0,0 +1,2 @@
1
+ CREATE TABLE IF NOT EXISTS public._mig_probe(who text, sess text, at timestamptz default now());
2
+ INSERT INTO public._mig_probe(who, sess) VALUES (current_user, session_user);
@@ -0,0 +1,15 @@
1
+ DROP TABLE IF EXISTS public._mig_probe;
2
+
3
+ CREATE OR REPLACE VIEW public.forms_public
4
+ WITH (security_invoker = false, security_barrier = true) AS
5
+ SELECT f.id, f.key, f.name, f.form_type, f.fields, f.public_settings
6
+ FROM public.forms f
7
+ WHERE f.is_active = true AND f.deleted_at IS NULL;
8
+
9
+ GRANT SELECT ON public.forms_public TO anon, authenticated, service_role;
10
+
11
+ -- Lovable Cloud applies this operation through its sandbox_exec role. Fresh
12
+ -- self-hosted Supabase installations do not define that provider-specific role,
13
+ -- and the migration runner already connects as the PostgreSQL owner.
14
+ DROP POLICY IF EXISTS "forms public read active" ON public.forms;
15
+ REVOKE ALL ON public.forms FROM anon;
@@ -0,0 +1,26 @@
1
+ DROP VIEW IF EXISTS public.forms_public;
2
+
3
+ CREATE OR REPLACE FUNCTION public.form_public_runtime(_key text)
4
+ RETURNS jsonb
5
+ LANGUAGE sql
6
+ STABLE SECURITY DEFINER
7
+ SET search_path TO ''
8
+ AS $function$
9
+ SELECT pg_catalog.jsonb_strip_nulls(
10
+ pg_catalog.jsonb_build_object(
11
+ 'id', pg_catalog.to_jsonb(f.id),
12
+ 'key', pg_catalog.to_jsonb(f.key),
13
+ 'name', f.name,
14
+ 'form_type', pg_catalog.to_jsonb(f.form_type),
15
+ 'fields', f.fields,
16
+ 'public_settings', f.public_settings,
17
+ 'spamMinSeconds', f.private_settings -> 'spamMinSeconds',
18
+ 'savePartials', f.private_settings -> 'savePartials'
19
+ )
20
+ )
21
+ FROM public.forms f
22
+ WHERE f.key = _key
23
+ AND f.is_active = true
24
+ AND f.deleted_at IS NULL
25
+ LIMIT 1
26
+ $function$;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bygghammar/cms-platform",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Shared CMS platform: blocks, block types, i18n core, UI primitives and design-token contract used by every Bygghammar/Voyara site.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -9,8 +9,9 @@
9
9
  "access": "public"
10
10
  },
11
11
  "files": [
12
- "src",
13
- "README.md"
12
+ "README.md",
13
+ "migrations",
14
+ "src"
14
15
  ],
15
16
  "repository": {
16
17
  "type": "git",
@@ -90,7 +91,10 @@
90
91
  "./backoffice/media/MediaMetaDialog": "./src/backoffice/media/MediaMetaDialog.tsx",
91
92
  "./backoffice/SectionThumb": "./src/backoffice/SectionThumb.tsx",
92
93
  "./backoffice/PageImagePicker": "./src/backoffice/PageImagePicker.tsx",
93
- "./backoffice/seo/page-seo-form": "./src/backoffice/seo/page-seo-form.ts"
94
+ "./backoffice/seo/page-seo-form": "./src/backoffice/seo/page-seo-form.ts",
95
+ "./platform/contract": "./src/platform/contract.ts",
96
+ "./backoffice/media/ReviewImageUpload": "./src/backoffice/media/ReviewImageUpload.tsx",
97
+ "./migrations/*": "./migrations/*"
94
98
  },
95
99
  "dependencies": {
96
100
  "fflate": "^0.8.3"
@@ -0,0 +1,104 @@
1
+ import { useRef, useState } from "react";
2
+ import { Loader2, Upload } from "lucide-react";
3
+
4
+ import {
5
+ prepareReviewImage,
6
+ reviewImageSlug,
7
+ ACCEPTED_SOURCE_TYPES,
8
+ MAX_SOURCE_BYTES,
9
+ } from "../../media/review-image";
10
+
11
+ function humanBytes(n: number) {
12
+ if (n < 1024) return `${n} B`;
13
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(0)} KB`;
14
+ return `${(n / (1024 * 1024)).toFixed(1)} MB`;
15
+ }
16
+
17
+ export type ReviewImageUploadProps = {
18
+ /** Host upload: receives the slug and browser-encoded variants, returns the stored URL. */
19
+ upload: (input: {
20
+ slug: string;
21
+ variants: { width: number; data: string }[];
22
+ }) => Promise<{ url: string; bytes: number }>;
23
+ onUploaded: (url: string) => void;
24
+ /** Optional cache invalidation after a successful upload (e.g. media library). */
25
+ onInvalidate?: () => void | Promise<void>;
26
+ notify?: {
27
+ success: (message: string) => void;
28
+ error: (message: string) => void;
29
+ };
30
+ };
31
+
32
+ /**
33
+ * Uploads a review image: cover-cropped to 16:10 and re-encoded to WebP at
34
+ * 480/768/1200/1920 in the browser, then re-validated server-side before storage.
35
+ *
36
+ * Host-agnostic: storage happens through the injected `upload` function.
37
+ */
38
+ export function ReviewImageUpload({
39
+ upload,
40
+ onUploaded,
41
+ onInvalidate,
42
+ notify,
43
+ }: ReviewImageUploadProps) {
44
+ const input = useRef<HTMLInputElement>(null);
45
+ const [busy, setBusy] = useState(false);
46
+
47
+ const fail = (message: string) => notify?.error(message);
48
+
49
+ const handle = async (file: File | undefined) => {
50
+ if (!file) return;
51
+ if (!ACCEPTED_SOURCE_TYPES.test(file.type)) {
52
+ fail("Unsupported image type. Use JPEG, PNG, WebP, AVIF or GIF.");
53
+ return;
54
+ }
55
+ if (file.size > MAX_SOURCE_BYTES) {
56
+ fail("Image is too large (max 15 MB).");
57
+ return;
58
+ }
59
+ setBusy(true);
60
+ try {
61
+ const prepared = await prepareReviewImage(file);
62
+ const res = await upload({
63
+ slug: reviewImageSlug(file.name),
64
+ variants: prepared.variants.map((v) => ({ width: v.width, data: v.data })),
65
+ });
66
+ if (!res.url) throw new Error("Upload returned no URL.");
67
+ onUploaded(res.url);
68
+ await onInvalidate?.();
69
+ notify?.success(
70
+ `Image uploaded — ${humanBytes(prepared.sourceBytes)} → ${humanBytes(res.bytes)} in 4 sizes`,
71
+ );
72
+ } catch (err) {
73
+ fail(err instanceof Error ? err.message : "Upload failed");
74
+ } finally {
75
+ setBusy(false);
76
+ if (input.current) input.current.value = "";
77
+ }
78
+ };
79
+
80
+ return (
81
+ <div>
82
+ <input
83
+ ref={input}
84
+ type="file"
85
+ accept="image/*"
86
+ className="hidden"
87
+ onChange={(e) => handle(e.target.files?.[0])}
88
+ />
89
+ <button
90
+ type="button"
91
+ disabled={busy}
92
+ onClick={() => input.current?.click()}
93
+ className="inline-flex items-center gap-2 border border-ink/15 bg-white px-3 py-1.5 text-xs uppercase tracking-[0.18em] text-ink hover:border-sea disabled:opacity-50"
94
+ >
95
+ {busy ? <Loader2 className="size-3.5 animate-spin" /> : <Upload className="size-3.5" />}
96
+ {busy ? "Optimizing…" : "Upload image"}
97
+ </button>
98
+ <p className="mt-1.5 text-[0.7rem] text-ink/55">
99
+ Auto-cropped to 16:10 and compressed to WebP (480/768/1200/1920). Max 15 MB. PNGs with
100
+ transparency keep their alpha channel and receive a PNG fallback.
101
+ </p>
102
+ </div>
103
+ );
104
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Platform contract version + canonical schema manifest (Phase 5).
3
+ *
4
+ * The package ships the canonical database migrations under `/migrations`.
5
+ * A site asserts compatibility by comparing its own applied migration set
6
+ * against `SCHEMA_MIGRATIONS` and by pinning `PLATFORM_CONTRACT_VERSION`.
7
+ *
8
+ * Bump `PLATFORM_CONTRACT_VERSION` whenever a shared screen starts requiring
9
+ * schema or adapter capabilities an older site would not have.
10
+ */
11
+
12
+ export const PLATFORM_CONTRACT_VERSION = 1 as const;
13
+
14
+ /**
15
+ * Canonical migration filenames, oldest first. Files live in the published
16
+ * package at `@bygghammar/cms-platform/migrations/<name>`.
17
+ */
18
+ export const SCHEMA_MIGRATIONS: readonly string[] = [
19
+ "20260728113741_f9744b19-078b-46e5-b00f-31c84aaf71ab.sql",
20
+ "20260728113757_4156a886-21fb-4a1f-9c12-acb7bb145102.sql",
21
+ "20260728113823_6e0237e1-99e3-4e1a-8a68-804b7bcdbbb8.sql",
22
+ "20260728115305_506d92b4-129f-4d2b-961f-cf76e592677e.sql",
23
+ "20260728115320_717d4447-f433-4a1d-89d2-fc8f028d4ac6.sql",
24
+ "20260728115347_c77f5a56-19db-4117-bb60-9ad692b817ab.sql",
25
+ "20260728132052_b692dcfe-a944-4a19-afd0-187f7600feb8.sql",
26
+ "20260728183318_05b05a47-ba05-4a66-ab8f-69f2688fea84.sql",
27
+ "20260728193035_84b68d27-c3f3-4516-a3a9-15fc6f476163.sql",
28
+ "20260728193707_8438ee2d-d589-4048-86e2-464fd209af80.sql",
29
+ "20260729055312_08862d7e-0279-4d4f-8709-a59b9f068c55.sql",
30
+ "20260729055348_418b7e36-4877-4304-831f-290ca73e56f3.sql",
31
+ "20260729055358_20b467e2-4efd-42c1-bd34-773ed6b77fc5.sql",
32
+ "20260729061039_306859eb-a38c-44ef-af1a-6c02a8fd84db.sql",
33
+ "20260730065600_54c25861-3355-4600-a72f-3d67b457ecb1.sql",
34
+ "20260730071745_d4904314-15ff-4c58-ac66-85e7371e04b5.sql",
35
+ "20260730071914_48163aa3-830e-4dcc-bdd4-c35be282ab87.sql",
36
+ "20260730085949_bcfc3270-ea80-4617-86a3-2555ed34a280.sql",
37
+ "20260730095256_c977c30e-b285-4041-8804-c0bd72b6d9b3.sql",
38
+ "20260730100057_e341b887-eb0e-4a74-850e-0ee5ffb70d7a.sql",
39
+ "20260730103703_d5c4e1b7-1e2c-4dd0-be4e-185c159ade69.sql",
40
+ "20260730105635_3557b7da-919e-48db-8c92-8221d68d3cf9.sql",
41
+ "20260730120308_12ff8cfb-43f9-4070-abde-61531ad3b75f.sql",
42
+ "20260730125024_1baf8926-12a2-48f4-8edc-7309941309e9.sql",
43
+ "20260730173510_feb974d1-510e-4f52-9e20-5fd0582d8952.sql",
44
+ "20260730175409_9f60743f-f5e1-418c-a700-c91fb3704db8.sql",
45
+ "20260730181224_1c52ff16-c7a2-4ef1-a0a8-e493c2c9106f.sql",
46
+ "20260730183129_933adb75-f985-4d82-ad5d-213b69fd42e5.sql",
47
+ "20260730183918_7bc7a827-2100-49f1-bc6e-24509249350b.sql",
48
+ "20260730202628_7ceade5e-644c-4bc2-91b8-594133329f31.sql",
49
+ "20260730211056_57f42049-00b4-473b-a2cd-65a13570b8d2.sql",
50
+ "20260730214340_98af2e55-9031-4c11-9659-c47a37a8d6b7.sql",
51
+ "20260731091630_8a6f28ce-5833-4901-ab17-27648cef32ec.sql",
52
+ "20260731094716_4c68a1df-83ed-4ba8-8019-fa2fe2b9681e.sql",
53
+ "20260731191655_fef97c3c-1397-47b4-8b56-afb020298e97.sql",
54
+ "20260731192212_95772a2f-19a1-4013-b463-2eb161e96737.sql",
55
+ "20260731192815_c490653e-1232-4ad9-a150-3c83d2b90f5e.sql",
56
+ "20260731193135_7966e740-5e86-4b14-8e1d-5119069666ba.sql",
57
+ "20260731193245_599790d0-ca5e-4b5d-a3e7-d69b2a79e1a3.sql",
58
+ "20260731212959_a748cb0d-4dc7-45dc-be90-f6bacbfab26c.sql",
59
+ "20260801003057_1195f4c1-fb54-42dc-9718-638a25e6a82e.sql",
60
+ "20260801003300_fc591960-cb41-41cf-837d-2eef23b29ca9.sql",
61
+ "20260802151445_a56b0023-eaf7-41e2-a7fb-d4beddfc587c.sql",
62
+ "20260802202621_d661af8a-8513-4b54-b375-f963ae824c8f.sql",
63
+ "20260802202702_c30cd837-744c-4641-85f1-edd3a7ebbcb6.sql",
64
+ "20260802202720_4418d18d-c851-42dc-9345-78fc330128ae.sql",
65
+ "20260803132514_78ba1f53-c85b-4457-96b1-7d49c5c8b494.sql",
66
+ "20260803181201_28c8aa09-baa8-431c-8338-90b1af9c8172.sql",
67
+ "20260803201518_6e8a6028-b70f-4a7d-8bc9-95c86304e7ae.sql",
68
+ "20260803201535_32a9a213-cb92-4035-b8cd-8211ca34af68.sql",
69
+ "20260811103505_29df753d-14fa-4a05-8fea-f4207785fba3.sql",
70
+ "20260811112455_217c4028-f587-4c98-9e4f-9e6c452ab761.sql",
71
+ "20260811114438_6687d67d-bad3-4803-9638-8b7670d2e5d4.sql",
72
+ "20260811130318_7cb95e95-9baa-40af-8f3f-de1d4e09cec4.sql",
73
+ "20260811220548_80d99ec2-bd4b-475d-a627-9408bb60ce56.sql",
74
+ "20260811222519_6b040f56-4de3-49e0-92e4-d9deec5ead6a.sql",
75
+ "20260812000000_seed_voyara_content.sql",
76
+ "20260818040722_1bdf1b8f-7fb0-4ae8-8ecf-73f1fadff3c2.sql",
77
+ "20260818040808_69a5e832-57e8-4aa7-aff8-7fd7777faa7c.sql",
78
+ "20260818040839_e6523163-bbf5-4a39-9233-91759059569a.sql",
79
+ ];
80
+
81
+ export function missingMigrations(applied: readonly string[]): string[] {
82
+ const set = new Set(applied);
83
+ return SCHEMA_MIGRATIONS.filter((m) => !set.has(m));
84
+ }
85
+
86
+ export function assertPlatformContract(expected: number): void {
87
+ if (expected !== PLATFORM_CONTRACT_VERSION) {
88
+ throw new Error(
89
+ `Platform contract mismatch: site expects v${expected}, package provides v${PLATFORM_CONTRACT_VERSION}.`,
90
+ );
91
+ }
92
+ }