brease-client 0.5.0 → 0.7.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.
package/README.md CHANGED
@@ -107,6 +107,39 @@ export default {
107
107
  }
108
108
  ```
109
109
 
110
+ ### Google Analytics (GA4)
111
+
112
+ When GA4 is linked in Brease (Connections → Google) with "Add the tag to the site" on, the site response carries
113
+ its measurement id. Render it once in the root layout; turning it off in Brease removes it without a deploy.
114
+
115
+ ```tsx
116
+ // app/layout.tsx
117
+ import Script from 'next/script'
118
+ import { ga4Tag } from 'brease-client'
119
+ import { brease } from '@/lib/brease'
120
+
121
+ export default async function RootLayout({ children }: { children: React.ReactNode }) {
122
+ const ga = ga4Tag(await brease.getSite())
123
+ return (
124
+ <html>
125
+ <body>
126
+ {children}
127
+ {ga && (
128
+ <>
129
+ <Script src={ga.src} strategy="afterInteractive" />
130
+ <Script id="brease-ga4" strategy="afterInteractive">{ga.inline}</Script>
131
+ </>
132
+ )}
133
+ </body>
134
+ </html>
135
+ )
136
+ }
137
+ ```
138
+
139
+ Consent mode starts denied: nothing is stored until your cookie banner calls `grantAnalytics()` (and
140
+ `grantAnalytics(false)` when consent is withdrawn). Without a banner, GA4 only receives cookieless pings. For
141
+ Astro or plain HTML, put `ga4Html(site)` in the `<head>`.
142
+
110
143
  ### Recommended structure (optional)
111
144
 
112
145
  Brease works with any routing: `getPage()` and friends don't care how a site is built. This structure is what Brease recommends, and what its editor moves a site towards when the site follows Brease conventions. It makes locales a setting: adding one, or changing how URLs are prefixed, needs no code change.
@@ -243,11 +276,47 @@ The Brease editor's Edit tool finds content through `data-brease` attributes:
243
276
 
244
277
  - `data-brease="hero.title"` on an element that renders a page content field (a path into `page.content`)
245
278
  - `data-brease="nav:footer"` on the element that wraps a navigation menu; clicking it opens that navigation's editor
279
+ - `data-brease-block="<name>"` on a section's root: which component renders it (a hint for the AI)
280
+ - `data-brease-sections="sections"` and `data-brease-section="<id>"`: the section list and its sections (see Sections)
246
281
 
247
282
  ```tsx
248
283
  <nav data-brease="nav:footer">{footer.items.map(/* … */)}</nav>
249
284
  ```
250
285
 
286
+ ## Sections
287
+
288
+ Editors can add, move, duplicate and delete page sections in the Brease editor when a site follows the sections convention:
289
+
290
+ ```
291
+ src/brease/sections/ (or brease/sections/)
292
+ index.tsx type -> component map, renders content.sections in order; unknown types render nothing
293
+ testimonials/
294
+ section.json { "name": "Testimonials", "description": "…", "addable": true, "fields": { JSON Schema } }
295
+ Testimonials.tsx
296
+ ```
297
+
298
+ - A page's sections are one list, `content.sections: [{ id, type, ...fields }]`, with the same ids in the same order in every locale. Fixed parts (a page title, header, footer, site-wide content) stay outside it.
299
+ - `fields` describes the section's fields; Brease builds new sections from it (lorem ipsum, a placeholder image, `default`s, `enum`s' first values, `minItems` list items). Images are `{ assetId, url, alt }`, links `{ label, href }`, rich text `{ "type": "string", "format": "html" }`.
300
+ - `"shared": true` keeps one content for every page that shows the type, on the site-wide page (`_global`) under `content.shared.<type>`; pages list only `{ id, type }` for it, and its markers use the other-page prefix (`<_global pageId>:shared.<type>.<field>`).
301
+ - Markers: the list's element carries `data-brease-sections="sections"`, each section's root `data-brease-section={id}` and `data-brease-block={type}`, fields inside `data-brease="sections.<index>.<field>"`.
302
+
303
+ ```tsx
304
+ import { type BreaseSection, sectionAttrs, sectionsAttrs } from 'brease-client'
305
+
306
+ export function Sections({ sections }: { sections: BreaseSection[] }) {
307
+ return (
308
+ <div {...sectionsAttrs}>
309
+ {sections.map((s, i) => {
310
+ const Component = map[s.type]
311
+ return Component ? <div key={s.id} {...sectionAttrs(s)}><Component section={s} index={i} /></div> : null
312
+ })}
313
+ </div>
314
+ )
315
+ }
316
+ ```
317
+
318
+ `npx brease-client check` warns about folders without a valid `section.json`, types missing from the map file, a missing `data-brease-section`, unknown types in `brease-seed/` or `.brease/` content, and locales whose sections differ. Brease runs the same check before publishing.
319
+
251
320
  ## Images
252
321
 
253
322
  ```ts
package/dist/astro.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HeadOptions } from './html.cjs';
2
2
  export { HeadTag, headTagList, headTags } from './html.cjs';
3
- import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
3
+ import { R as ResolvedSeo } from './types-ecfDXrLa.cjs';
4
4
 
5
5
  declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
6
6
 
package/dist/astro.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HeadOptions } from './html.js';
2
2
  export { HeadTag, headTagList, headTags } from './html.js';
3
- import { R as ResolvedSeo } from './types-V0ELFvwy.js';
3
+ import { R as ResolvedSeo } from './types-ecfDXrLa.js';
4
4
 
5
5
  declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
6
6
 
@@ -73,6 +73,29 @@ function resolvePath(settings, pathname) {
73
73
  return { slug: clean, locale: settings.defaultLocale };
74
74
  }
75
75
 
76
+ // src/analytics.ts
77
+ var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
78
+ function ga4Tag(site) {
79
+ const id = site.analytics?.ga4;
80
+ if (!id || !MEASUREMENT_ID.test(id)) return null;
81
+ const inline = [
82
+ "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}",
83
+ "gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',wait_for_update:500});",
84
+ "gtag('js',new Date());",
85
+ `gtag('config','${id}');`
86
+ ].join("");
87
+ return { id, src: `https://www.googletagmanager.com/gtag/js?id=${id}`, inline };
88
+ }
89
+ function ga4Html(site) {
90
+ const tag = ga4Tag(site);
91
+ return tag ? `<script async src="${tag.src}"></script>
92
+ <script>${tag.inline}</script>` : "";
93
+ }
94
+ function grantAnalytics(granted = true) {
95
+ const gtag = globalThis.gtag;
96
+ gtag?.("consent", "update", { analytics_storage: granted ? "granted" : "denied" });
97
+ }
98
+
76
99
  // src/locales.ts
77
100
  function localeLinks(context) {
78
101
  const { settings, alternates, homes, locale: current } = context;
@@ -219,4 +242,4 @@ function pathOf(url) {
219
242
  }
220
243
  }
221
244
 
222
- export { BreaseError, buildPath, createBrease, env, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
245
+ export { BreaseError, buildPath, createBrease, env, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
@@ -0,0 +1,79 @@
1
+ // src/sections.ts
2
+ var sectionsAttrs = { "data-brease-sections": "sections" };
3
+ function sectionAttrs(section) {
4
+ return { "data-brease-section": section.id, "data-brease-block": section.type };
5
+ }
6
+ var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
7
+ var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
8
+ function checkSections(files, pages = {}) {
9
+ const warnings = [];
10
+ const folder = SECTION_FOLDERS.find((f) => Object.keys(files).some((p) => p.startsWith(`${f}/`)));
11
+ if (!folder) return warnings;
12
+ const inFolder = Object.entries(files).map(([p, text]) => [p.slice(folder.length + 1), text]);
13
+ const types = [
14
+ ...new Set(
15
+ inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
16
+ )
17
+ ];
18
+ const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
19
+ if (!map)
20
+ warnings.push(`${folder} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
21
+ const marked = inFolder.some(
22
+ ([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
23
+ );
24
+ if (!marked)
25
+ warnings.push(
26
+ `No component in ${folder} renders data-brease-section (or sectionAttrs), so editors can't add sections`
27
+ );
28
+ for (const type of types) {
29
+ if (!TYPE_NAME.test(type)) {
30
+ warnings.push(`${folder}/${type}: use lowercase letters, numbers and - in section folder names`);
31
+ continue;
32
+ }
33
+ const json = files[`${folder}/${type}/section.json`];
34
+ if (json === void 0) {
35
+ warnings.push(`${folder}/${type} has no section.json`);
36
+ continue;
37
+ }
38
+ try {
39
+ const meta = JSON.parse(json);
40
+ if (typeof meta.name !== "string" || !meta.name.trim())
41
+ warnings.push(`${folder}/${type}/section.json has no name`);
42
+ if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
43
+ warnings.push(`${folder}/${type}/section.json: fields must be a JSON Schema object`);
44
+ } catch {
45
+ warnings.push(`${folder}/${type}/section.json is not valid JSON`);
46
+ }
47
+ if (map && !map[1].includes(type)) warnings.push(`${type} is in ${folder} but not in its map file`);
48
+ }
49
+ const known = new Set(types);
50
+ for (const [pageId, locales] of Object.entries(pages)) {
51
+ let reference = null;
52
+ for (const [locale, file] of Object.entries(locales)) {
53
+ const list = file.content?.sections;
54
+ if (list === void 0) continue;
55
+ if (!Array.isArray(list)) {
56
+ warnings.push(`${pageId} (${locale}): sections is not a list`);
57
+ continue;
58
+ }
59
+ const ids = /* @__PURE__ */ new Set();
60
+ for (const item of list) {
61
+ if (typeof item?.id !== "string" || typeof item.type !== "string") {
62
+ warnings.push(`${pageId} (${locale}): a section has no id or type`);
63
+ continue;
64
+ }
65
+ if (ids.has(item.id)) warnings.push(`${pageId} (${locale}): section ${item.id} appears twice`);
66
+ ids.add(item.id);
67
+ if (!known.has(item.type))
68
+ warnings.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
69
+ }
70
+ const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
71
+ if (reference === null) reference = shape;
72
+ else if (shape !== reference)
73
+ warnings.push(`${pageId}: the sections in ${locale} differ from the other locales`);
74
+ }
75
+ }
76
+ return warnings;
77
+ }
78
+
79
+ export { SECTION_FOLDERS, checkSections, sectionAttrs, sectionsAttrs };
package/dist/cli.cjs ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var fs = require('fs');
5
+ var path = require('path');
6
+
7
+ // src/sections.ts
8
+ var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
9
+ var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
10
+ function checkSections(files2, pages = {}) {
11
+ const warnings2 = [];
12
+ const folder2 = SECTION_FOLDERS.find((f) => Object.keys(files2).some((p) => p.startsWith(`${f}/`)));
13
+ if (!folder2) return warnings2;
14
+ const inFolder = Object.entries(files2).map(([p, text]) => [p.slice(folder2.length + 1), text]);
15
+ const types = [
16
+ ...new Set(
17
+ inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
18
+ )
19
+ ];
20
+ const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
21
+ if (!map)
22
+ warnings2.push(`${folder2} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
23
+ const marked = inFolder.some(
24
+ ([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
25
+ );
26
+ if (!marked)
27
+ warnings2.push(
28
+ `No component in ${folder2} renders data-brease-section (or sectionAttrs), so editors can't add sections`
29
+ );
30
+ for (const type of types) {
31
+ if (!TYPE_NAME.test(type)) {
32
+ warnings2.push(`${folder2}/${type}: use lowercase letters, numbers and - in section folder names`);
33
+ continue;
34
+ }
35
+ const json = files2[`${folder2}/${type}/section.json`];
36
+ if (json === void 0) {
37
+ warnings2.push(`${folder2}/${type} has no section.json`);
38
+ continue;
39
+ }
40
+ try {
41
+ const meta = JSON.parse(json);
42
+ if (typeof meta.name !== "string" || !meta.name.trim())
43
+ warnings2.push(`${folder2}/${type}/section.json has no name`);
44
+ if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
45
+ warnings2.push(`${folder2}/${type}/section.json: fields must be a JSON Schema object`);
46
+ } catch {
47
+ warnings2.push(`${folder2}/${type}/section.json is not valid JSON`);
48
+ }
49
+ if (map && !map[1].includes(type)) warnings2.push(`${type} is in ${folder2} but not in its map file`);
50
+ }
51
+ const known = new Set(types);
52
+ for (const [pageId, locales] of Object.entries(pages)) {
53
+ let reference = null;
54
+ for (const [locale, file] of Object.entries(locales)) {
55
+ const list = file.content?.sections;
56
+ if (list === void 0) continue;
57
+ if (!Array.isArray(list)) {
58
+ warnings2.push(`${pageId} (${locale}): sections is not a list`);
59
+ continue;
60
+ }
61
+ const ids = /* @__PURE__ */ new Set();
62
+ for (const item of list) {
63
+ if (typeof item?.id !== "string" || typeof item.type !== "string") {
64
+ warnings2.push(`${pageId} (${locale}): a section has no id or type`);
65
+ continue;
66
+ }
67
+ if (ids.has(item.id)) warnings2.push(`${pageId} (${locale}): section ${item.id} appears twice`);
68
+ ids.add(item.id);
69
+ if (!known.has(item.type))
70
+ warnings2.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
71
+ }
72
+ const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
73
+ if (reference === null) reference = shape;
74
+ else if (shape !== reference)
75
+ warnings2.push(`${pageId}: the sections in ${locale} differ from the other locales`);
76
+ }
77
+ }
78
+ return warnings2;
79
+ }
80
+
81
+ // src/cli.ts
82
+ function walk(dir, out = []) {
83
+ for (const name of fs.readdirSync(dir)) {
84
+ if (name === "node_modules") continue;
85
+ const path$1 = path.join(dir, name);
86
+ if (fs.statSync(path$1).isDirectory()) walk(path$1, out);
87
+ else out.push(path$1);
88
+ }
89
+ return out;
90
+ }
91
+ function pagesIn(root) {
92
+ const pages = {};
93
+ const dir = path.join(root, "pages");
94
+ if (!fs.existsSync(dir)) return pages;
95
+ for (const pageId of fs.readdirSync(dir)) {
96
+ for (const file of fs.readdirSync(path.join(dir, pageId))) {
97
+ if (!file.endsWith(".json") || file === "page.json") continue;
98
+ const locales = pages[pageId] ?? {};
99
+ pages[pageId] = locales;
100
+ try {
101
+ locales[file.slice(0, -5)] = JSON.parse(fs.readFileSync(path.join(dir, pageId, file), "utf8"));
102
+ } catch {
103
+ }
104
+ }
105
+ }
106
+ return pages;
107
+ }
108
+ var [command] = process.argv.slice(2);
109
+ if (command !== "check") {
110
+ console.log("Usage: brease-client check");
111
+ process.exit(command ? 1 : 0);
112
+ }
113
+ var cwd = process.cwd();
114
+ var folder = SECTION_FOLDERS.find((f) => fs.existsSync(path.join(cwd, f)));
115
+ if (!folder) {
116
+ console.log("No sections folder (src/brease/sections or brease/sections): nothing to check.");
117
+ process.exit(0);
118
+ }
119
+ var files = Object.fromEntries(
120
+ walk(path.join(cwd, folder)).map((p) => [path.relative(cwd, p).split("\\").join("/"), fs.readFileSync(p, "utf8")])
121
+ );
122
+ var content = ["brease-seed", ".brease"].map((d) => path.join(cwd, d)).find((d) => fs.existsSync(d));
123
+ var warnings = checkSections(files, content ? pagesIn(content) : {});
124
+ for (const w of warnings) console.log(`warning: ${w}`);
125
+ console.log(warnings.length ? `${warnings.length} warning(s)` : "Sections look right.");
126
+ process.exit(warnings.length ? 1 : 0);
package/dist/cli.d.cts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import { SECTION_FOLDERS, checkSections } from './chunk-CQZLTZGN.js';
3
+ import './chunk-PKBMQBKP.js';
4
+ import { existsSync, readFileSync, readdirSync, statSync } from 'fs';
5
+ import { join, relative } from 'path';
6
+
7
+ function walk(dir, out = []) {
8
+ for (const name of readdirSync(dir)) {
9
+ if (name === "node_modules") continue;
10
+ const path = join(dir, name);
11
+ if (statSync(path).isDirectory()) walk(path, out);
12
+ else out.push(path);
13
+ }
14
+ return out;
15
+ }
16
+ function pagesIn(root) {
17
+ const pages = {};
18
+ const dir = join(root, "pages");
19
+ if (!existsSync(dir)) return pages;
20
+ for (const pageId of readdirSync(dir)) {
21
+ for (const file of readdirSync(join(dir, pageId))) {
22
+ if (!file.endsWith(".json") || file === "page.json") continue;
23
+ const locales = pages[pageId] ?? {};
24
+ pages[pageId] = locales;
25
+ try {
26
+ locales[file.slice(0, -5)] = JSON.parse(readFileSync(join(dir, pageId, file), "utf8"));
27
+ } catch {
28
+ }
29
+ }
30
+ }
31
+ return pages;
32
+ }
33
+ var [command] = process.argv.slice(2);
34
+ if (command !== "check") {
35
+ console.log("Usage: brease-client check");
36
+ process.exit(command ? 1 : 0);
37
+ }
38
+ var cwd = process.cwd();
39
+ var folder = SECTION_FOLDERS.find((f) => existsSync(join(cwd, f)));
40
+ if (!folder) {
41
+ console.log("No sections folder (src/brease/sections or brease/sections): nothing to check.");
42
+ process.exit(0);
43
+ }
44
+ var files = Object.fromEntries(
45
+ walk(join(cwd, folder)).map((p) => [relative(cwd, p).split("\\").join("/"), readFileSync(p, "utf8")])
46
+ );
47
+ var content = ["brease-seed", ".brease"].map((d) => join(cwd, d)).find((d) => existsSync(d));
48
+ var warnings = checkSections(files, content ? pagesIn(content) : {});
49
+ for (const w of warnings) console.log(`warning: ${w}`);
50
+ console.log(warnings.length ? `${warnings.length} warning(s)` : "Sections look right.");
51
+ process.exit(warnings.length ? 1 : 0);
package/dist/html.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
1
+ import { R as ResolvedSeo } from './types-ecfDXrLa.cjs';
2
2
 
3
3
  type HeadOptions = {
4
4
  xDefault?: string;
package/dist/html.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedSeo } from './types-V0ELFvwy.js';
1
+ import { R as ResolvedSeo } from './types-ecfDXrLa.js';
2
2
 
3
3
  type HeadOptions = {
4
4
  xDefault?: string;
package/dist/index.cjs CHANGED
@@ -77,6 +77,29 @@ function resolvePath(settings, pathname) {
77
77
  return { slug: clean, locale: settings.defaultLocale };
78
78
  }
79
79
 
80
+ // src/analytics.ts
81
+ var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
82
+ function ga4Tag(site) {
83
+ const id = site.analytics?.ga4;
84
+ if (!id || !MEASUREMENT_ID.test(id)) return null;
85
+ const inline = [
86
+ "window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}",
87
+ "gtag('consent','default',{ad_storage:'denied',ad_user_data:'denied',ad_personalization:'denied',analytics_storage:'denied',wait_for_update:500});",
88
+ "gtag('js',new Date());",
89
+ `gtag('config','${id}');`
90
+ ].join("");
91
+ return { id, src: `https://www.googletagmanager.com/gtag/js?id=${id}`, inline };
92
+ }
93
+ function ga4Html(site) {
94
+ const tag = ga4Tag(site);
95
+ return tag ? `<script async src="${tag.src}"></script>
96
+ <script>${tag.inline}</script>` : "";
97
+ }
98
+ function grantAnalytics(granted = true) {
99
+ const gtag = globalThis.gtag;
100
+ gtag?.("consent", "update", { analytics_storage: granted ? "granted" : "denied" });
101
+ }
102
+
80
103
  // src/locales.ts
81
104
  function localeLinks(context) {
82
105
  const { settings, alternates, homes, locale: current } = context;
@@ -95,6 +118,84 @@ function nativeName(locale) {
95
118
  }
96
119
  var localeHref = (settings, slug, locale) => buildPath(settings, slug, locale);
97
120
 
121
+ // src/sections.ts
122
+ var sectionsAttrs = { "data-brease-sections": "sections" };
123
+ function sectionAttrs(section) {
124
+ return { "data-brease-section": section.id, "data-brease-block": section.type };
125
+ }
126
+ var SECTION_FOLDERS = ["src/brease/sections", "brease/sections"];
127
+ var TYPE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
128
+ function checkSections(files, pages = {}) {
129
+ const warnings = [];
130
+ const folder = SECTION_FOLDERS.find((f) => Object.keys(files).some((p) => p.startsWith(`${f}/`)));
131
+ if (!folder) return warnings;
132
+ const inFolder = Object.entries(files).map(([p, text]) => [p.slice(folder.length + 1), text]);
133
+ const types = [
134
+ ...new Set(
135
+ inFolder.map(([p]) => p.split("/")).filter((s) => s.length > 1).map((s) => s[0])
136
+ )
137
+ ];
138
+ const map = inFolder.find(([p]) => /^index\.[cm]?[jt]sx?$/.test(p));
139
+ if (!map)
140
+ warnings.push(`${folder} has no map file (index.tsx, index.ts or index.js) rendering the section types`);
141
+ const marked = inFolder.some(
142
+ ([, text]) => text.includes("data-brease-section") || text.includes("sectionAttrs(")
143
+ );
144
+ if (!marked)
145
+ warnings.push(
146
+ `No component in ${folder} renders data-brease-section (or sectionAttrs), so editors can't add sections`
147
+ );
148
+ for (const type of types) {
149
+ if (!TYPE_NAME.test(type)) {
150
+ warnings.push(`${folder}/${type}: use lowercase letters, numbers and - in section folder names`);
151
+ continue;
152
+ }
153
+ const json = files[`${folder}/${type}/section.json`];
154
+ if (json === void 0) {
155
+ warnings.push(`${folder}/${type} has no section.json`);
156
+ continue;
157
+ }
158
+ try {
159
+ const meta = JSON.parse(json);
160
+ if (typeof meta.name !== "string" || !meta.name.trim())
161
+ warnings.push(`${folder}/${type}/section.json has no name`);
162
+ if (meta.fields !== void 0 && (typeof meta.fields !== "object" || meta.fields === null))
163
+ warnings.push(`${folder}/${type}/section.json: fields must be a JSON Schema object`);
164
+ } catch {
165
+ warnings.push(`${folder}/${type}/section.json is not valid JSON`);
166
+ }
167
+ if (map && !map[1].includes(type)) warnings.push(`${type} is in ${folder} but not in its map file`);
168
+ }
169
+ const known = new Set(types);
170
+ for (const [pageId, locales] of Object.entries(pages)) {
171
+ let reference = null;
172
+ for (const [locale, file] of Object.entries(locales)) {
173
+ const list = file.content?.sections;
174
+ if (list === void 0) continue;
175
+ if (!Array.isArray(list)) {
176
+ warnings.push(`${pageId} (${locale}): sections is not a list`);
177
+ continue;
178
+ }
179
+ const ids = /* @__PURE__ */ new Set();
180
+ for (const item of list) {
181
+ if (typeof item?.id !== "string" || typeof item.type !== "string") {
182
+ warnings.push(`${pageId} (${locale}): a section has no id or type`);
183
+ continue;
184
+ }
185
+ if (ids.has(item.id)) warnings.push(`${pageId} (${locale}): section ${item.id} appears twice`);
186
+ ids.add(item.id);
187
+ if (!known.has(item.type))
188
+ warnings.push(`${pageId} (${locale}): section type "${item.type}" has no folder`);
189
+ }
190
+ const shape = list.map((s) => `${s?.id}:${s?.type}`).join(",");
191
+ if (reference === null) reference = shape;
192
+ else if (shape !== reference)
193
+ warnings.push(`${pageId}: the sections in ${locale} differ from the other locales`);
194
+ }
195
+ }
196
+ return warnings;
197
+ }
198
+
98
199
  // src/index.ts
99
200
  var RETRY_AFTER_CAP_MS = 1e4;
100
201
  var SITE_TTL_MS = 6e4;
@@ -225,9 +326,15 @@ function pathOf(url) {
225
326
 
226
327
  exports.BreaseError = BreaseError;
227
328
  exports.buildPath = buildPath;
329
+ exports.checkSections = checkSections;
228
330
  exports.createBrease = createBrease;
331
+ exports.ga4Html = ga4Html;
332
+ exports.ga4Tag = ga4Tag;
333
+ exports.grantAnalytics = grantAnalytics;
229
334
  exports.localeHref = localeHref;
230
335
  exports.localeLinks = localeLinks;
231
336
  exports.nativeName = nativeName;
232
337
  exports.normalizeSlug = normalizeSlug;
233
338
  exports.resolvePath = resolvePath;
339
+ exports.sectionAttrs = sectionAttrs;
340
+ exports.sectionsAttrs = sectionsAttrs;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,14 @@
1
- import { U as UrlSettings, S as Site, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-V0ELFvwy.cjs';
2
- export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-V0ELFvwy.cjs';
1
+ import { S as Site, U as UrlSettings, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-ecfDXrLa.cjs';
2
+ export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-ecfDXrLa.cjs';
3
+
4
+ type Ga4Tag = {
5
+ id: string;
6
+ src: string;
7
+ inline: string;
8
+ };
9
+ declare function ga4Tag(site: Pick<Site, 'analytics'>): Ga4Tag | null;
10
+ declare function ga4Html(site: Pick<Site, 'analytics'>): string;
11
+ declare function grantAnalytics(granted?: boolean): void;
3
12
 
4
13
  declare class BreaseError extends Error {
5
14
  code: string;
@@ -21,6 +30,25 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
21
30
  declare function nativeName(locale: string): string;
22
31
  declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
23
32
 
33
+ type BreaseSection<T = Record<string, unknown>> = {
34
+ id: string;
35
+ type: string;
36
+ } & T;
37
+ declare const sectionsAttrs: {
38
+ readonly 'data-brease-sections': "sections";
39
+ };
40
+ declare function sectionAttrs(section: {
41
+ id: string;
42
+ type: string;
43
+ }): {
44
+ 'data-brease-section': string;
45
+ 'data-brease-block': string;
46
+ };
47
+ type PageLocales = Record<string, Record<string, {
48
+ content?: unknown;
49
+ }>>;
50
+ declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
51
+
24
52
  declare function normalizeSlug(input: string): string;
25
53
  declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
26
54
  declare function resolvePath(settings: UrlSettings, pathname: string): {
@@ -71,4 +99,4 @@ interface Brease {
71
99
  }
72
100
  declare function createBrease(opts?: BreaseOptions): Brease;
73
101
 
74
- export { type Brease, BreaseError, type BreaseOptions, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
102
+ export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type Ga4Tag, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,14 @@
1
- import { U as UrlSettings, S as Site, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-V0ELFvwy.js';
2
- export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-V0ELFvwy.js';
1
+ import { S as Site, U as UrlSettings, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-ecfDXrLa.js';
2
+ export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-ecfDXrLa.js';
3
+
4
+ type Ga4Tag = {
5
+ id: string;
6
+ src: string;
7
+ inline: string;
8
+ };
9
+ declare function ga4Tag(site: Pick<Site, 'analytics'>): Ga4Tag | null;
10
+ declare function ga4Html(site: Pick<Site, 'analytics'>): string;
11
+ declare function grantAnalytics(granted?: boolean): void;
3
12
 
4
13
  declare class BreaseError extends Error {
5
14
  code: string;
@@ -21,6 +30,25 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
21
30
  declare function nativeName(locale: string): string;
22
31
  declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
23
32
 
33
+ type BreaseSection<T = Record<string, unknown>> = {
34
+ id: string;
35
+ type: string;
36
+ } & T;
37
+ declare const sectionsAttrs: {
38
+ readonly 'data-brease-sections': "sections";
39
+ };
40
+ declare function sectionAttrs(section: {
41
+ id: string;
42
+ type: string;
43
+ }): {
44
+ 'data-brease-section': string;
45
+ 'data-brease-block': string;
46
+ };
47
+ type PageLocales = Record<string, Record<string, {
48
+ content?: unknown;
49
+ }>>;
50
+ declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
51
+
24
52
  declare function normalizeSlug(input: string): string;
25
53
  declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
26
54
  declare function resolvePath(settings: UrlSettings, pathname: string): {
@@ -71,4 +99,4 @@ interface Brease {
71
99
  }
72
100
  declare function createBrease(opts?: BreaseOptions): Brease;
73
101
 
74
- export { type Brease, BreaseError, type BreaseOptions, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
102
+ export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type Ga4Tag, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export { BreaseError, buildPath, createBrease, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath } from './chunk-ULU4ABCQ.js';
1
+ export { BreaseError, buildPath, createBrease, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath } from './chunk-7BBL2LET.js';
2
+ export { checkSections, sectionAttrs, sectionsAttrs } from './chunk-CQZLTZGN.js';
2
3
  import './chunk-PKBMQBKP.js';
package/dist/next.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Brease } from './index.cjs';
2
- import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
2
+ import { R as ResolvedSeo } from './types-ecfDXrLa.cjs';
3
3
 
4
4
  type BreaseMetadata = {
5
5
  title: {
package/dist/next.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Brease } from './index.js';
2
- import { R as ResolvedSeo } from './types-V0ELFvwy.js';
2
+ import { R as ResolvedSeo } from './types-ecfDXrLa.js';
3
3
 
4
4
  type BreaseMetadata = {
5
5
  title: {
package/dist/next.js CHANGED
@@ -1,4 +1,5 @@
1
- import { env, createBrease } from './chunk-ULU4ABCQ.js';
1
+ import { env, createBrease } from './chunk-7BBL2LET.js';
2
+ import './chunk-CQZLTZGN.js';
2
3
  import './chunk-PKBMQBKP.js';
3
4
 
4
5
  // src/next.ts
@@ -66,6 +66,9 @@ type Site = {
66
66
  localeStrategy: LocaleStrategy;
67
67
  urlTemplate: string | null;
68
68
  seo: Record<string, SiteSeo>;
69
+ analytics?: {
70
+ ga4: string;
71
+ } | null;
69
72
  };
70
73
  type Page<T = Record<string, unknown>> = {
71
74
  pageId: string;
@@ -66,6 +66,9 @@ type Site = {
66
66
  localeStrategy: LocaleStrategy;
67
67
  urlTemplate: string | null;
68
68
  seo: Record<string, SiteSeo>;
69
+ analytics?: {
70
+ ga4: string;
71
+ } | null;
69
72
  };
70
73
  type Page<T = Record<string, unknown>> = {
71
74
  pageId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brease-client",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Brease delivery API client for Next.js, Astro and any fetch-capable runtime",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -74,6 +74,9 @@
74
74
  "access": "public",
75
75
  "provenance": true
76
76
  },
77
+ "bin": {
78
+ "brease-client": "./dist/cli.js"
79
+ },
77
80
  "scripts": {
78
81
  "build": "tsup",
79
82
  "dev": "tsup --watch",