brease-client 0.8.0 → 0.8.2

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
@@ -28,7 +28,8 @@ const brease = createBrease({
28
28
 
29
29
  await brease.getSite() // name, url (the public address), locales, defaultLocale, localeStrategy, global SEO, analytics
30
30
  await brease.getPage<Home>('', { locale: 'en' }) // Page<Home> | null ('' is the home page)
31
- await brease.getPages({ locale: 'en' }) // [{ pageId, locale, slug, url, hidden, name, index, parentId, order }]
31
+ await brease.getPages({ locale: 'en' }) // [{ pageId, locale, slug, url, hidden, name, index, parentId, order, template }]
32
+ await brease.getPages({ locale: 'en', parentId: news.pageId, withContent: true }) // a news list, with each page's content
32
33
  await brease.getNavigation('main', { locale: 'en' }) // { key, locale, items } | null
33
34
  await brease.getRedirects() // [{ source, destination, status }], cached for a minute
34
35
  await brease.resolve('/en/about') // { slug: 'about', locale: 'en' } | null
@@ -42,6 +43,9 @@ await brease.sitemap(site.url) // [{ url, alternates }]: pages search may show
42
43
  - 429 and 5xx responses (and network errors) are retried twice with backoff; `Retry-After` is honoured.
43
44
  - Commit pinning: the `x-brease-commit` header is sent from `VERCEL_GIT_COMMIT_SHA`, so every deployment reads the content release that was built and tested with its code.
44
45
  - `sitemap()` lists only pages search may show: not hidden, not kept out of search (`index: false`, the page's "Show in search results" switch), and no site-wide `_` pages. It has no `lastModified`: releases are immutable snapshots and do not track per-page edit times.
46
+ - `getPages({ parentId, template, withContent })` narrows the list to a page's children or one template, and with
47
+ `withContent` adds each page's content (one locale, hidden pages left out, up to 100 pages): build news, team or
48
+ job lists from it instead of fetching every page.
45
49
  - `site.url` is the site's public address (its primary domain), the one Brease uses in canonical URLs and hreflang; use it for the sitemap and `metadataBase` rather than an env variable of your own.
46
50
  - `getSite()` is cached for a minute, so a locale added in Brease is served without a restart.
47
51
  - `buildPath(settings, slug, locale)` and `resolvePath(settings, pathname)` are exported for routing code that already has the site settings.
@@ -122,6 +126,21 @@ export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] }
122
126
  Sources may use parameters as in Next's redirects (`/blog/:slug`, `/docs/:rest*`). `breaseRedirects()` (from
123
127
  `brease-client/next`, for `next.config`) still works, but only reads redirects at build time.
124
128
 
129
+ `route()` also resolves other forms of a page's URL (`/en/about` where English has no prefix, `/about` where every
130
+ locale is prefixed); `resolvedSeo.canonical` points search engines at the real one. To redirect those forms too,
131
+ add this to the same proxy, before `NextResponse.next()`. Keep it in the `try`: when Brease can't be reached, the
132
+ request goes on to the page instead of failing.
133
+
134
+ ```ts
135
+ import { canonicalPath } from 'brease-client'
136
+
137
+ try {
138
+ const canonical = canonicalPath(await brease.getSite(), req.nextUrl.pathname)
139
+ if (canonical && (await brease.getPages()).some((p) => p.url === canonical))
140
+ return NextResponse.redirect(new URL(canonical + req.nextUrl.search, req.url), 308)
141
+ } catch {}
142
+ ```
143
+
125
144
  ### Structured data (JSON-LD)
126
145
 
127
146
  Structured data is content: the page's own entries (its SEO in Brease) and the site's (site SEO) come together in
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-DeS_3KtO.cjs';
3
+ import { R as ResolvedSeo } from './types-D5mwpqAP.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-DeS_3KtO.js';
3
+ import { R as ResolvedSeo } from './types-D5mwpqAP.js';
4
4
 
5
5
  declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
6
6
 
@@ -72,6 +72,13 @@ function resolvePath(settings, pathname) {
72
72
  }
73
73
  return { slug: clean, locale: settings.defaultLocale };
74
74
  }
75
+ function canonicalPath(settings, pathname) {
76
+ const path = pathname.split(/[?#]/)[0] ?? "";
77
+ const { slug, locale } = resolvePath(settings, path);
78
+ const canonical = buildPath(settings, slug, locale);
79
+ const trim = (p) => p.length > 1 ? p.replace(/\/+$/, "") : p;
80
+ return trim(decodeURIComponent(path)) === trim(canonical) ? null : canonical;
81
+ }
75
82
 
76
83
  // src/analytics.ts
77
84
  var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
@@ -290,7 +297,12 @@ function createBrease(opts = {}) {
290
297
  return request("/content-api/page", { slug, locale }, true);
291
298
  },
292
299
  getPages(o = {}) {
293
- return request("/content-api/pages", { locale: o.locale });
300
+ return request("/content-api/pages", {
301
+ locale: o.locale,
302
+ parentId: o.parentId,
303
+ template: o.template,
304
+ withContent: o.withContent ? "1" : void 0
305
+ });
294
306
  },
295
307
  getNavigation(key, { locale }) {
296
308
  return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
@@ -368,4 +380,4 @@ function pathOf(url) {
368
380
  }
369
381
  }
370
382
 
371
- export { BreaseError, buildPath, createBrease, customTags, env, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature };
383
+ export { BreaseError, buildPath, canonicalPath, createBrease, customTags, env, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature };
package/dist/html.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { R as ResolvedSeo } from './types-DeS_3KtO.cjs';
1
+ import { R as ResolvedSeo } from './types-D5mwpqAP.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-DeS_3KtO.js';
1
+ import { R as ResolvedSeo } from './types-D5mwpqAP.js';
2
2
 
3
3
  type HeadOptions = {
4
4
  xDefault?: string;
package/dist/image.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as BreaseImage } from './types-DeS_3KtO.cjs';
1
+ import { B as BreaseImage } from './types-D5mwpqAP.cjs';
2
2
 
3
3
  type Resize = 'cover' | 'contain' | 'fill';
4
4
  type ImageOptions = {
package/dist/image.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { B as BreaseImage } from './types-DeS_3KtO.js';
1
+ import { B as BreaseImage } from './types-D5mwpqAP.js';
2
2
 
3
3
  type Resize = 'cover' | 'contain' | 'fill';
4
4
  type ImageOptions = {
package/dist/index.cjs CHANGED
@@ -76,6 +76,13 @@ function resolvePath(settings, pathname) {
76
76
  }
77
77
  return { slug: clean, locale: settings.defaultLocale };
78
78
  }
79
+ function canonicalPath(settings, pathname) {
80
+ const path = pathname.split(/[?#]/)[0] ?? "";
81
+ const { slug, locale } = resolvePath(settings, path);
82
+ const canonical = buildPath(settings, slug, locale);
83
+ const trim = (p) => p.length > 1 ? p.replace(/\/+$/, "") : p;
84
+ return trim(decodeURIComponent(path)) === trim(canonical) ? null : canonical;
85
+ }
79
86
 
80
87
  // src/analytics.ts
81
88
  var MEASUREMENT_ID = /^G-[A-Z0-9]+$/;
@@ -381,7 +388,12 @@ function createBrease(opts = {}) {
381
388
  return request("/content-api/page", { slug, locale }, true);
382
389
  },
383
390
  getPages(o = {}) {
384
- return request("/content-api/pages", { locale: o.locale });
391
+ return request("/content-api/pages", {
392
+ locale: o.locale,
393
+ parentId: o.parentId,
394
+ template: o.template,
395
+ withContent: o.withContent ? "1" : void 0
396
+ });
385
397
  },
386
398
  getNavigation(key, { locale }) {
387
399
  return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
@@ -461,6 +473,7 @@ function pathOf(url) {
461
473
 
462
474
  exports.BreaseError = BreaseError;
463
475
  exports.buildPath = buildPath;
476
+ exports.canonicalPath = canonicalPath;
464
477
  exports.checkSections = checkSections;
465
478
  exports.createBrease = createBrease;
466
479
  exports.customTags = customTags;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-DeS_3KtO.cjs';
2
- export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-DeS_3KtO.cjs';
1
+ import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-D5mwpqAP.cjs';
2
+ export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-D5mwpqAP.cjs';
3
3
 
4
4
  type Ga4Tag = {
5
5
  id: string;
@@ -102,6 +102,7 @@ declare function resolvePath(settings: UrlSettings, pathname: string): {
102
102
  slug: string;
103
103
  locale: string;
104
104
  };
105
+ declare function canonicalPath(settings: UrlSettings, pathname: string): string | null;
105
106
 
106
107
  type LocaleContext = {
107
108
  locale: string;
@@ -122,9 +123,12 @@ interface Brease {
122
123
  getPage<T = Record<string, unknown>>(slug: string, opts: {
123
124
  locale: string;
124
125
  }): Promise<Page<T> | null>;
125
- getPages(opts?: {
126
+ getPages<T = Record<string, unknown>>(opts?: {
126
127
  locale?: string;
127
- }): Promise<PageRef[]>;
128
+ parentId?: string;
129
+ template?: string;
130
+ withContent?: boolean;
131
+ }): Promise<PageRef<T>[]>;
128
132
  getNavigation(key: string, opts: {
129
133
  locale: string;
130
134
  }): Promise<Navigation | null>;
@@ -146,4 +150,4 @@ interface Brease {
146
150
  }
147
151
  declare function createBrease(opts?: BreaseOptions): Brease;
148
152
 
149
- export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
153
+ export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, canonicalPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-DeS_3KtO.js';
2
- export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-DeS_3KtO.js';
1
+ import { S as Site, R as ResolvedSeo, U as UrlSettings, a as Redirect, P as Page, b as PageRef, N as Navigation, c as Release, d as SitemapEntry } from './types-D5mwpqAP.js';
2
+ export { B as BreaseImage, e as BreaseLink, L as LocaleStrategy, f as NavigationItem, O as OpenGraph, g as PageSeo, h as Robots, i as SiteSeo, T as Twitter } from './types-D5mwpqAP.js';
3
3
 
4
4
  type Ga4Tag = {
5
5
  id: string;
@@ -102,6 +102,7 @@ declare function resolvePath(settings: UrlSettings, pathname: string): {
102
102
  slug: string;
103
103
  locale: string;
104
104
  };
105
+ declare function canonicalPath(settings: UrlSettings, pathname: string): string | null;
105
106
 
106
107
  type LocaleContext = {
107
108
  locale: string;
@@ -122,9 +123,12 @@ interface Brease {
122
123
  getPage<T = Record<string, unknown>>(slug: string, opts: {
123
124
  locale: string;
124
125
  }): Promise<Page<T> | null>;
125
- getPages(opts?: {
126
+ getPages<T = Record<string, unknown>>(opts?: {
126
127
  locale?: string;
127
- }): Promise<PageRef[]>;
128
+ parentId?: string;
129
+ template?: string;
130
+ withContent?: boolean;
131
+ }): Promise<PageRef<T>[]>;
128
132
  getNavigation(key: string, opts: {
129
133
  locale: string;
130
134
  }): Promise<Navigation | null>;
@@ -146,4 +150,4 @@ interface Brease {
146
150
  }
147
151
  declare function createBrease(opts?: BreaseOptions): Brease;
148
152
 
149
- export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
153
+ export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type CustomTag, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, type RevalidateBody, type RevalidateTarget, Site, SitemapEntry, UrlSettings, buildPath, canonicalPath, checkSections, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, jsonLd, jsonLdHtml, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs, verifyRevalidate, verifySignature };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { BreaseError, buildPath, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature } from './chunk-SO4BD4ME.js';
1
+ export { BreaseError, buildPath, canonicalPath, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature } from './chunk-MWTYINWA.js';
2
2
  export { checkSections, sectionAttrs, sectionsAttrs } from './chunk-CQZLTZGN.js';
3
3
  export { jsonLd, jsonLdHtml } from './chunk-N3QOL5EU.js';
4
4
  import './chunk-PKBMQBKP.js';
package/dist/next.cjs CHANGED
@@ -176,7 +176,12 @@ function createBrease(opts = {}) {
176
176
  return request("/content-api/page", { slug, locale }, true);
177
177
  },
178
178
  getPages(o = {}) {
179
- return request("/content-api/pages", { locale: o.locale });
179
+ return request("/content-api/pages", {
180
+ locale: o.locale,
181
+ parentId: o.parentId,
182
+ template: o.template,
183
+ withContent: o.withContent ? "1" : void 0
184
+ });
180
185
  },
181
186
  getNavigation(key, { locale }) {
182
187
  return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
package/dist/next.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Brease } from './index.cjs';
2
2
  export { hmacHex, verifySignature } from './index.cjs';
3
- import { R as ResolvedSeo } from './types-DeS_3KtO.cjs';
3
+ import { R as ResolvedSeo } from './types-D5mwpqAP.cjs';
4
4
 
5
5
  type BreaseMetadata = {
6
6
  title: {
package/dist/next.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Brease } from './index.js';
2
2
  export { hmacHex, verifySignature } from './index.js';
3
- import { R as ResolvedSeo } from './types-DeS_3KtO.js';
3
+ import { R as ResolvedSeo } from './types-D5mwpqAP.js';
4
4
 
5
5
  type BreaseMetadata = {
6
6
  title: {
package/dist/next.js CHANGED
@@ -1,5 +1,5 @@
1
- import { env, verifyRevalidate, createBrease } from './chunk-SO4BD4ME.js';
2
- export { hmacHex, verifySignature } from './chunk-SO4BD4ME.js';
1
+ import { env, verifyRevalidate, createBrease } from './chunk-MWTYINWA.js';
2
+ export { hmacHex, verifySignature } from './chunk-MWTYINWA.js';
3
3
  import './chunk-CQZLTZGN.js';
4
4
  import './chunk-N3QOL5EU.js';
5
5
  import './chunk-PKBMQBKP.js';
@@ -103,11 +103,13 @@ type Page<T = Record<string, unknown>> = {
103
103
  resolvedSeo: ResolvedSeo;
104
104
  alternates: Record<string, string>;
105
105
  };
106
- type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
106
+ type PageRef<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
107
107
  name?: string;
108
108
  index?: boolean;
109
109
  parentId?: string | null;
110
110
  order?: number;
111
+ template?: string | null;
112
+ content?: T;
111
113
  };
112
114
  type NavigationItem = {
113
115
  id: string;
@@ -103,11 +103,13 @@ type Page<T = Record<string, unknown>> = {
103
103
  resolvedSeo: ResolvedSeo;
104
104
  alternates: Record<string, string>;
105
105
  };
106
- type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
106
+ type PageRef<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
107
107
  name?: string;
108
108
  index?: boolean;
109
109
  parentId?: string | null;
110
110
  order?: number;
111
+ template?: string | null;
112
+ content?: T;
111
113
  };
112
114
  type NavigationItem = {
113
115
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brease-client",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Brease delivery API client for Next.js, Astro and any fetch-capable runtime",
5
5
  "license": "MIT",
6
6
  "repository": {