brease-client 0.7.1 → 0.8.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 +75 -27
- package/dist/astro.d.cts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/{chunk-GJ3SOWDB.js → chunk-SO4BD4ME.js} +129 -3
- package/dist/html.d.cts +1 -1
- package/dist/html.d.ts +1 -1
- package/dist/image.cjs +8 -2
- package/dist/image.d.cts +6 -1
- package/dist/image.d.ts +6 -1
- package/dist/image.js +8 -2
- package/dist/index.cjs +135 -2
- package/dist/index.d.cts +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +1 -1
- package/dist/next.cjs +67 -49
- package/dist/next.d.cts +3 -4
- package/dist/next.d.ts +3 -4
- package/dist/next.js +9 -49
- package/dist/{types-ecfDXrLa.d.cts → types-DeS_3KtO.d.cts} +29 -3
- package/dist/{types-ecfDXrLa.d.ts → types-DeS_3KtO.d.ts} +29 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Typed client for the Brease delivery API. Zero runtime dependencies, ESM + CJS,
|
|
|
6
6
|
pnpm add brease-client
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
Set
|
|
9
|
+
Set these environment variables (Brease writes them into your Vercel project at onboarding):
|
|
10
10
|
|
|
11
11
|
| Variable | Purpose |
|
|
12
12
|
| --- | --- |
|
|
@@ -26,22 +26,23 @@ const brease = createBrease({
|
|
|
26
26
|
fetch // optional custom fetch, e.g. to add framework cache options
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
await brease.getSite() // name, locales, defaultLocale, localeStrategy, global SEO
|
|
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 }]
|
|
31
|
+
await brease.getPages({ locale: 'en' }) // [{ pageId, locale, slug, url, hidden, name, index, parentId, order }]
|
|
32
32
|
await brease.getNavigation('main', { locale: 'en' }) // { key, locale, items } | null
|
|
33
|
-
await brease.getRedirects() // [{ source, destination, status }]
|
|
33
|
+
await brease.getRedirects() // [{ source, destination, status }], cached for a minute
|
|
34
34
|
await brease.resolve('/en/about') // { slug: 'about', locale: 'en' } | null
|
|
35
35
|
await brease.route(['en', 'about']) // the same from catch-all path segments; null for shared "_" pages
|
|
36
36
|
await brease.routes() // [{ path: ['en', 'about'] }, …]: static params for every published page
|
|
37
37
|
await brease.localeContext(['en', 'about']) // { locale, settings, alternates, homes } for BreaseLocaleProvider
|
|
38
|
-
await brease.sitemap(
|
|
38
|
+
await brease.sitemap(site.url) // [{ url, alternates }]: pages search may show
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
- `null` means 404. Every other failure throws a `BreaseError` with `status`, `code`, `requestId` and `details`.
|
|
42
42
|
- 429 and 5xx responses (and network errors) are retried twice with backoff; `Retry-After` is honoured.
|
|
43
43
|
- 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
|
-
- `sitemap()` has no `lastModified`: releases are immutable snapshots and do not track per-page edit times.
|
|
44
|
+
- `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.
|
|
45
|
+
- `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.
|
|
45
46
|
- `getSite()` is cached for a minute, so a locale added in Brease is served without a restart.
|
|
46
47
|
- `buildPath(settings, slug, locale)` and `resolvePath(settings, pathname)` are exported for routing code that already has the site settings.
|
|
47
48
|
|
|
@@ -72,8 +73,7 @@ async function load(params: Props['params']) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
export async function generateStaticParams() {
|
|
75
|
-
|
|
76
|
-
return pages.filter((p) => !p.hidden).map((p) => ({ slug: p.url.split('/').filter(Boolean) }))
|
|
76
|
+
return (await brease.routes()).map((r) => ({ slug: r.path })) // published pages, without site-wide "_" pages
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export async function generateMetadata({ params }: Props) {
|
|
@@ -88,29 +88,46 @@ export default async function Page({ params }: Props) {
|
|
|
88
88
|
}
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
+
`page.resolvedSeo` is final: the title already has the site's title template applied (unless the page chose to show
|
|
92
|
+
its title as written), and every field falls back to the site's defaults. Render it as is; don't add your own
|
|
93
|
+
template or a home-page exception in code.
|
|
94
|
+
|
|
91
95
|
```ts
|
|
92
|
-
// app/api/revalidate/route.ts
|
|
96
|
+
// app/api/brease/revalidate/route.ts: the path Brease calls after a content release
|
|
93
97
|
import { revalidateHandler } from 'brease-client/next'
|
|
94
98
|
|
|
95
|
-
export const POST = revalidateHandler() // uses BREASE_REVALIDATE_SECRET
|
|
99
|
+
export const POST = revalidateHandler() // uses BREASE_REVALIDATE_SECRET; refreshes at once
|
|
96
100
|
```
|
|
97
101
|
|
|
102
|
+
Other frameworks: `verifyRevalidate(request, secret)` (root export) checks the signature and returns the paths and
|
|
103
|
+
cache tags to refresh, or why not (401 for a bad signature, 400 for a bad body).
|
|
104
|
+
|
|
105
|
+
Redirects managed in Brease apply per request, so a new one works as soon as it's published (within a minute), with
|
|
106
|
+
no rebuild:
|
|
107
|
+
|
|
98
108
|
```ts
|
|
99
|
-
//
|
|
100
|
-
import {
|
|
109
|
+
// proxy.ts (middleware.ts before Next 16)
|
|
110
|
+
import { type NextRequest, NextResponse } from 'next/server'
|
|
111
|
+
import { matchRedirect } from 'brease-client'
|
|
112
|
+
import { brease } from '@/lib/brease'
|
|
101
113
|
|
|
102
|
-
export
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return redirects.map((r) => ({ source: r.source, destination: r.destination, permanent: r.status === 301 || r.status === 308 }))
|
|
106
|
-
}
|
|
114
|
+
export async function proxy(req: NextRequest) {
|
|
115
|
+
const hit = matchRedirect(await brease.getRedirects().catch(() => []), req.nextUrl.pathname)
|
|
116
|
+
return hit ? NextResponse.redirect(new URL(hit.destination, req.url), hit.status) : NextResponse.next()
|
|
107
117
|
}
|
|
118
|
+
|
|
119
|
+
export const config = { matcher: ['/((?!_next|api|.*\\..*).*)'] }
|
|
108
120
|
```
|
|
109
121
|
|
|
122
|
+
Sources may use parameters as in Next's redirects (`/blog/:slug`, `/docs/:rest*`). `breaseRedirects()` (from
|
|
123
|
+
`brease-client/next`, for `next.config`) still works, but only reads redirects at build time.
|
|
124
|
+
|
|
110
125
|
### Structured data (JSON-LD)
|
|
111
126
|
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
Structured data is content: the page's own entries (its SEO in Brease) and the site's (site SEO) come together in
|
|
128
|
+
`page.resolvedSeo.structuredData`. `toMetadata` can't output scripts, so render them with `jsonLd` (framework-free,
|
|
129
|
+
from the root export) on every page; each item's `json` is escaped for use inside a script tag. Entities your code
|
|
130
|
+
already emits shouldn't be added in Brease too.
|
|
114
131
|
|
|
115
132
|
```tsx
|
|
116
133
|
import { jsonLd } from 'brease-client'
|
|
@@ -122,6 +139,23 @@ import { jsonLd } from 'brease-client'
|
|
|
122
139
|
|
|
123
140
|
`headTags` (HTML) and `breaseHead` (Astro) already include it; `jsonLdHtml(seo)` gives only the scripts.
|
|
124
141
|
|
|
142
|
+
### Custom code
|
|
143
|
+
|
|
144
|
+
Site-wide head code and a page's own code (both from SEO settings in Brease) run on the live site only when the site
|
|
145
|
+
renders them. `toMetadata` can't, so render `customTags(page.resolvedSeo)` (root export) as real elements:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
import { customTags } from 'brease-client'
|
|
149
|
+
|
|
150
|
+
{customTags(page.resolvedSeo).map(({ tag: Tag, attrs, content }, i) => {
|
|
151
|
+
const props = Object.fromEntries(Object.entries(attrs).map(([k, v]) => [k, v === '' ? true : v]))
|
|
152
|
+
return content ? <Tag key={i} {...props} dangerouslySetInnerHTML={{ __html: content }} /> : <Tag key={i} {...props} />
|
|
153
|
+
})}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Only `script`, `style`, `meta`, `link` and `noscript` tags are kept. `headTags` (HTML) and `breaseHead` (Astro)
|
|
157
|
+
include the code already.
|
|
158
|
+
|
|
125
159
|
### Google Analytics (GA4)
|
|
126
160
|
|
|
127
161
|
When GA4 is linked in Brease (Connections → Google) with "Add the tag to the site" on, the site response carries
|
|
@@ -244,7 +278,7 @@ A locale switcher is then a few lines in any framework: a list of `<a href={l.hr
|
|
|
244
278
|
- Everything that read a fixed locale (`getPage(…, { locale: 'hu' })`, `getNavigation`, `site.seo.hu`) takes it from the route instead.
|
|
245
279
|
- Links inside content are already locale URLs. Build other internal links with `localeHref(settings, slug, locale)`.
|
|
246
280
|
- Text written into components (button labels, captions) stays as it is; moving it into Brease content is a separate change.
|
|
247
|
-
- `
|
|
281
|
+
- `proxy.ts`: `matchRedirect(await brease.getRedirects(), pathname)` applies the redirects managed in Brease per request (see above).
|
|
248
282
|
|
|
249
283
|
### Revalidation signature
|
|
250
284
|
|
|
@@ -289,13 +323,17 @@ const html = `<head>${headTags(page.resolvedSeo, { xDefault: 'https://example.co
|
|
|
289
323
|
|
|
290
324
|
The Brease editor's Edit tool finds content through `data-brease` attributes:
|
|
291
325
|
|
|
292
|
-
- `data-brease=
|
|
293
|
-
- `data-brease=
|
|
294
|
-
- `data-brease
|
|
326
|
+
- `data-brease={fieldPath('hero.title')}` on an element that renders a field of the page being shown (a path into `page.content`, e.g. `hero.title` or `sections.2.items.0.label`)
|
|
327
|
+
- `data-brease={fieldPath('footer.copyright', global.pageId)}` for a field of another page, such as site-wide content (`_global`): the path is prefixed with that page's id (`<pageId>:footer.copyright`). Take the id from the page you fetched, never a fixed one.
|
|
328
|
+
- `data-brease={navPath('footer')}` (`nav:footer`) on the element that wraps a navigation menu; clicking it opens that navigation's editor
|
|
329
|
+
- `data-brease-block`: a section root carries its section type (`{section.type}`); other blocks (header, footer, a hero outside the sections list) carry their component name. A hint for the AI.
|
|
295
330
|
- `data-brease-sections="sections"` and `data-brease-section="<id>"`: the section list and its sections (see Sections)
|
|
296
331
|
|
|
297
332
|
```tsx
|
|
298
|
-
|
|
333
|
+
import { fieldPath, navPath } from 'brease-client'
|
|
334
|
+
|
|
335
|
+
<nav data-brease={navPath('footer')}>{footer.items.map(/* … */)}</nav>
|
|
336
|
+
<p data-brease={fieldPath('footer.copyright', global.pageId)}>{global.content.footer.copyright}</p>
|
|
299
337
|
```
|
|
300
338
|
|
|
301
339
|
## Sections
|
|
@@ -311,7 +349,7 @@ src/brease/sections/ (or brease/sections/)
|
|
|
311
349
|
```
|
|
312
350
|
|
|
313
351
|
- 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.
|
|
314
|
-
- `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 }
|
|
352
|
+
- `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, width?, height? }` (`BreaseImage`), links `{ label, href }` (`BreaseLink`; an internal link also carries the page's `pageId`, and the delivery API sets its `href` for the requested locale), rich text `{ "type": "string", "format": "html" }`.
|
|
315
353
|
- `"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>`).
|
|
316
354
|
- 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>"`.
|
|
317
355
|
|
|
@@ -338,10 +376,20 @@ export function Sections({ sections }: { sections: BreaseSection[] }) {
|
|
|
338
376
|
import { imageProps, srcset } from 'brease-client/image'
|
|
339
377
|
|
|
340
378
|
const props = imageProps(page.content.hero.image, { sizes: '(min-width: 768px) 50vw, 100vw' })
|
|
341
|
-
// <img src={props.src} srcSet={props.srcSet} sizes={props.sizes} />
|
|
379
|
+
// <img src={props.src} srcSet={props.srcSet} sizes={props.sizes} alt={props.alt} width={props.width} height={props.height} />
|
|
342
380
|
```
|
|
343
381
|
|
|
344
|
-
|
|
382
|
+
An image field is `{ assetId, url, alt, width?, height? }` (`BreaseImage`); `imageProps` takes the field or a plain
|
|
383
|
+
URL. Brease files are served as-is from storage, which doesn't resize images: the helpers return the URL unchanged
|
|
384
|
+
with an empty `srcset`. For responsive images, let your framework resize them, e.g. `next/image` with the host of
|
|
385
|
+
your Brease image URLs in `images.remotePatterns`.
|
|
386
|
+
|
|
387
|
+
## Content links
|
|
388
|
+
|
|
389
|
+
Link fields are `{ label, href }`. A link to another page of the site also carries that page's `pageId`, and the
|
|
390
|
+
delivery API sets `href` to the page's URL in the locale you asked for, so renaming or moving a page never breaks a
|
|
391
|
+
link and every locale links to its own version. External links are only the `href`. Rich text links to pages carry
|
|
392
|
+
`data-brease-page="<pageId>"`, and their `href` is filled in the same way.
|
|
345
393
|
|
|
346
394
|
## Without JavaScript
|
|
347
395
|
|
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-
|
|
3
|
+
import { R as ResolvedSeo } from './types-DeS_3KtO.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-
|
|
3
|
+
import { R as ResolvedSeo } from './types-DeS_3KtO.js';
|
|
4
4
|
|
|
5
5
|
declare function breaseHead(seo: ResolvedSeo, opts?: HeadOptions): string;
|
|
6
6
|
|
|
@@ -96,6 +96,29 @@ function grantAnalytics(granted = true) {
|
|
|
96
96
|
gtag?.("consent", "update", { analytics_storage: granted ? "granted" : "denied" });
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// src/custom-code.ts
|
|
100
|
+
function customTags(seo) {
|
|
101
|
+
return [seo.customHead, seo.customCode].flatMap((html) => html ? parseTags(html) : []);
|
|
102
|
+
}
|
|
103
|
+
function parseTags(html) {
|
|
104
|
+
const out = [];
|
|
105
|
+
const re = /<(script|style|noscript)\b([^>]*)>([\s\S]*?)<\/\1\s*>|<(meta|link)\b([^>]*?)\/?>/gi;
|
|
106
|
+
for (const m of html.matchAll(re)) {
|
|
107
|
+
if (m[1]) {
|
|
108
|
+
const tag = m[1].toLowerCase();
|
|
109
|
+
out.push({ tag, attrs: attrsOf(m[2] ?? ""), ...m[3]?.trim() ? { content: m[3] } : {} });
|
|
110
|
+
} else if (m[4])
|
|
111
|
+
out.push({ tag: m[4].toLowerCase(), attrs: attrsOf(m[5] ?? "") });
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
function attrsOf(source) {
|
|
116
|
+
const attrs = {};
|
|
117
|
+
for (const m of source.matchAll(/([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g))
|
|
118
|
+
attrs[m[1].toLowerCase()] = m[2] ?? m[3] ?? m[4] ?? "";
|
|
119
|
+
return attrs;
|
|
120
|
+
}
|
|
121
|
+
|
|
99
122
|
// src/locales.ts
|
|
100
123
|
function localeLinks(context) {
|
|
101
124
|
const { settings, alternates, homes, locale: current } = context;
|
|
@@ -114,6 +137,98 @@ function nativeName(locale) {
|
|
|
114
137
|
}
|
|
115
138
|
var localeHref = (settings, slug, locale) => buildPath(settings, slug, locale);
|
|
116
139
|
|
|
140
|
+
// src/markers.ts
|
|
141
|
+
function fieldPath(path, pageId) {
|
|
142
|
+
return pageId ? `${pageId}:${path}` : path;
|
|
143
|
+
}
|
|
144
|
+
function navPath(key) {
|
|
145
|
+
return `nav:${key}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/redirects.ts
|
|
149
|
+
function matchRedirect(redirects, pathname) {
|
|
150
|
+
const path = normalize(pathname);
|
|
151
|
+
for (const r of redirects) {
|
|
152
|
+
const params = matchSource(normalize(r.source), path);
|
|
153
|
+
if (!params) continue;
|
|
154
|
+
const destination = r.destination.replace(
|
|
155
|
+
/:([A-Za-z_][A-Za-z0-9_]*)\*?/g,
|
|
156
|
+
(whole, name) => name in params ? params[name] : whole
|
|
157
|
+
);
|
|
158
|
+
if (normalize(destination) === path) continue;
|
|
159
|
+
return { destination, status: r.status };
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
var normalize = (p) => (p.length > 1 ? p.replace(/\/+$/, "") : p) || "/";
|
|
164
|
+
function matchSource(source, path) {
|
|
165
|
+
const want = source.split("/").filter(Boolean);
|
|
166
|
+
const have = path.split("/").filter(Boolean);
|
|
167
|
+
const params = {};
|
|
168
|
+
for (let i = 0; i < want.length; i++) {
|
|
169
|
+
const seg = want[i];
|
|
170
|
+
const rest = /^:([A-Za-z_][A-Za-z0-9_]*)\*$/.exec(seg);
|
|
171
|
+
if (rest) {
|
|
172
|
+
params[rest[1]] = have.slice(i).join("/");
|
|
173
|
+
return params;
|
|
174
|
+
}
|
|
175
|
+
const value = have[i];
|
|
176
|
+
if (value === void 0) return null;
|
|
177
|
+
const param = /^:([A-Za-z_][A-Za-z0-9_]*)$/.exec(seg);
|
|
178
|
+
if (param) params[param[1]] = value;
|
|
179
|
+
else if (decodeURIComponent(value) !== decodeURIComponent(seg)) return null;
|
|
180
|
+
}
|
|
181
|
+
return want.length === have.length ? params : null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/signature.ts
|
|
185
|
+
var MAX_SKEW_MS = 5 * 6e4;
|
|
186
|
+
async function hmacHex(secret, message) {
|
|
187
|
+
const enc = new TextEncoder();
|
|
188
|
+
const key = await crypto.subtle.importKey(
|
|
189
|
+
"raw",
|
|
190
|
+
enc.encode(secret),
|
|
191
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
192
|
+
false,
|
|
193
|
+
["sign"]
|
|
194
|
+
);
|
|
195
|
+
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
|
|
196
|
+
return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
197
|
+
}
|
|
198
|
+
async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
|
|
199
|
+
if (!timestamp || !signature) return false;
|
|
200
|
+
if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
|
|
201
|
+
const expected = await hmacHex(secret, `${timestamp}.${body}`);
|
|
202
|
+
if (expected.length !== signature.length) return false;
|
|
203
|
+
let diff = 0;
|
|
204
|
+
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
205
|
+
return diff === 0;
|
|
206
|
+
}
|
|
207
|
+
async function verifyRevalidate(req, secret) {
|
|
208
|
+
const raw = await req.text();
|
|
209
|
+
const ok = await verifySignature(
|
|
210
|
+
raw,
|
|
211
|
+
req.headers.get("x-brease-timestamp"),
|
|
212
|
+
req.headers.get("x-brease-signature"),
|
|
213
|
+
secret
|
|
214
|
+
);
|
|
215
|
+
if (!ok) return { ok: false, reason: "signature" };
|
|
216
|
+
let body;
|
|
217
|
+
try {
|
|
218
|
+
body = JSON.parse(raw || "{}");
|
|
219
|
+
} catch {
|
|
220
|
+
return { ok: false, reason: "body" };
|
|
221
|
+
}
|
|
222
|
+
const paths = new Set(body.paths ?? []);
|
|
223
|
+
for (const url of body.urls ?? []) {
|
|
224
|
+
try {
|
|
225
|
+
paths.add(new URL(url, "http://localhost").pathname);
|
|
226
|
+
} catch {
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return { ok: true, paths: [...paths], tags: ["brease", ...body.tags ?? []], body };
|
|
230
|
+
}
|
|
231
|
+
|
|
117
232
|
// src/index.ts
|
|
118
233
|
var RETRY_AFTER_CAP_MS = 1e4;
|
|
119
234
|
var SITE_TTL_MS = 6e4;
|
|
@@ -125,6 +240,7 @@ function createBrease(opts = {}) {
|
|
|
125
240
|
const baseMs = opts.retryBaseMs ?? 300;
|
|
126
241
|
const doFetch = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
127
242
|
let site;
|
|
243
|
+
let redirects;
|
|
128
244
|
async function request(path, query = {}, nullOn404 = false) {
|
|
129
245
|
const token = opts.token ?? env("BREASE_TOKEN");
|
|
130
246
|
if (!token)
|
|
@@ -179,8 +295,16 @@ function createBrease(opts = {}) {
|
|
|
179
295
|
getNavigation(key, { locale }) {
|
|
180
296
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
181
297
|
},
|
|
298
|
+
// Cached for a minute, like the site: a proxy applies redirects per request (matchRedirect).
|
|
182
299
|
getRedirects() {
|
|
183
|
-
|
|
300
|
+
if (!redirects || Date.now() - redirects.at > SITE_TTL_MS) {
|
|
301
|
+
const promise = request("/content-api/redirects").catch((err) => {
|
|
302
|
+
if (redirects?.promise === promise) redirects = void 0;
|
|
303
|
+
throw err;
|
|
304
|
+
});
|
|
305
|
+
redirects = { promise, at: Date.now() };
|
|
306
|
+
}
|
|
307
|
+
return redirects.promise;
|
|
184
308
|
},
|
|
185
309
|
getRelease() {
|
|
186
310
|
return request("/content-api/release");
|
|
@@ -222,7 +346,9 @@ function createBrease(opts = {}) {
|
|
|
222
346
|
},
|
|
223
347
|
async sitemap(baseUrl) {
|
|
224
348
|
const base = baseUrl.replace(/\/+$/, "");
|
|
225
|
-
const refs = (await client.getPages()).filter(
|
|
349
|
+
const refs = (await client.getPages()).filter(
|
|
350
|
+
(r) => !r.hidden && r.index !== false && !r.slug.split("/").some((part) => part.startsWith("_"))
|
|
351
|
+
);
|
|
226
352
|
const byPage = /* @__PURE__ */ new Map();
|
|
227
353
|
for (const ref of refs) {
|
|
228
354
|
const alternates = byPage.get(ref.pageId) ?? {};
|
|
@@ -242,4 +368,4 @@ function pathOf(url) {
|
|
|
242
368
|
}
|
|
243
369
|
}
|
|
244
370
|
|
|
245
|
-
export { BreaseError, buildPath, createBrease, env, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath };
|
|
371
|
+
export { BreaseError, buildPath, createBrease, customTags, env, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature };
|
package/dist/html.d.cts
CHANGED
package/dist/html.d.ts
CHANGED
package/dist/image.cjs
CHANGED
|
@@ -8,8 +8,14 @@ function imageUrl(src, _opts = {}) {
|
|
|
8
8
|
function srcset(_src, _opts = {}) {
|
|
9
9
|
return "";
|
|
10
10
|
}
|
|
11
|
-
function imageProps(
|
|
12
|
-
|
|
11
|
+
function imageProps(image, opts = {}) {
|
|
12
|
+
const src = typeof image === "string" ? image : image.url;
|
|
13
|
+
const extra = typeof image === "string" ? {} : {
|
|
14
|
+
...image.alt !== void 0 ? { alt: image.alt } : {},
|
|
15
|
+
...image.width ? { width: image.width } : {},
|
|
16
|
+
...image.height ? { height: image.height } : {}
|
|
17
|
+
};
|
|
18
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw", ...extra };
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
exports.DEFAULT_WIDTHS = DEFAULT_WIDTHS;
|
package/dist/image.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { B as BreaseImage } from './types-DeS_3KtO.cjs';
|
|
2
|
+
|
|
1
3
|
type Resize = 'cover' | 'contain' | 'fill';
|
|
2
4
|
type ImageOptions = {
|
|
3
5
|
width?: number;
|
|
@@ -12,7 +14,7 @@ declare function srcset(_src: string, _opts?: {
|
|
|
12
14
|
quality?: number;
|
|
13
15
|
resize?: Resize;
|
|
14
16
|
}): string;
|
|
15
|
-
declare function imageProps(
|
|
17
|
+
declare function imageProps(image: string | BreaseImage, opts?: {
|
|
16
18
|
sizes?: string;
|
|
17
19
|
widths?: number[];
|
|
18
20
|
width?: number;
|
|
@@ -22,6 +24,9 @@ declare function imageProps(src: string, opts?: {
|
|
|
22
24
|
src: string;
|
|
23
25
|
srcSet: string;
|
|
24
26
|
sizes: string;
|
|
27
|
+
alt?: string;
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { B as BreaseImage } from './types-DeS_3KtO.js';
|
|
2
|
+
|
|
1
3
|
type Resize = 'cover' | 'contain' | 'fill';
|
|
2
4
|
type ImageOptions = {
|
|
3
5
|
width?: number;
|
|
@@ -12,7 +14,7 @@ declare function srcset(_src: string, _opts?: {
|
|
|
12
14
|
quality?: number;
|
|
13
15
|
resize?: Resize;
|
|
14
16
|
}): string;
|
|
15
|
-
declare function imageProps(
|
|
17
|
+
declare function imageProps(image: string | BreaseImage, opts?: {
|
|
16
18
|
sizes?: string;
|
|
17
19
|
widths?: number[];
|
|
18
20
|
width?: number;
|
|
@@ -22,6 +24,9 @@ declare function imageProps(src: string, opts?: {
|
|
|
22
24
|
src: string;
|
|
23
25
|
srcSet: string;
|
|
24
26
|
sizes: string;
|
|
27
|
+
alt?: string;
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
25
30
|
};
|
|
26
31
|
|
|
27
32
|
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.js
CHANGED
|
@@ -8,8 +8,14 @@ function imageUrl(src, _opts = {}) {
|
|
|
8
8
|
function srcset(_src, _opts = {}) {
|
|
9
9
|
return "";
|
|
10
10
|
}
|
|
11
|
-
function imageProps(
|
|
12
|
-
|
|
11
|
+
function imageProps(image, opts = {}) {
|
|
12
|
+
const src = typeof image === "string" ? image : image.url;
|
|
13
|
+
const extra = typeof image === "string" ? {} : {
|
|
14
|
+
...image.alt !== void 0 ? { alt: image.alt } : {},
|
|
15
|
+
...image.width ? { width: image.width } : {},
|
|
16
|
+
...image.height ? { height: image.height } : {}
|
|
17
|
+
};
|
|
18
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw", ...extra };
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export { DEFAULT_WIDTHS, imageProps, imageUrl, srcset };
|
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,29 @@ function grantAnalytics(granted = true) {
|
|
|
100
100
|
gtag?.("consent", "update", { analytics_storage: granted ? "granted" : "denied" });
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
// src/custom-code.ts
|
|
104
|
+
function customTags(seo) {
|
|
105
|
+
return [seo.customHead, seo.customCode].flatMap((html) => html ? parseTags(html) : []);
|
|
106
|
+
}
|
|
107
|
+
function parseTags(html) {
|
|
108
|
+
const out = [];
|
|
109
|
+
const re = /<(script|style|noscript)\b([^>]*)>([\s\S]*?)<\/\1\s*>|<(meta|link)\b([^>]*?)\/?>/gi;
|
|
110
|
+
for (const m of html.matchAll(re)) {
|
|
111
|
+
if (m[1]) {
|
|
112
|
+
const tag = m[1].toLowerCase();
|
|
113
|
+
out.push({ tag, attrs: attrsOf(m[2] ?? ""), ...m[3]?.trim() ? { content: m[3] } : {} });
|
|
114
|
+
} else if (m[4])
|
|
115
|
+
out.push({ tag: m[4].toLowerCase(), attrs: attrsOf(m[5] ?? "") });
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
function attrsOf(source) {
|
|
120
|
+
const attrs = {};
|
|
121
|
+
for (const m of source.matchAll(/([^\s"'=<>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g))
|
|
122
|
+
attrs[m[1].toLowerCase()] = m[2] ?? m[3] ?? m[4] ?? "";
|
|
123
|
+
return attrs;
|
|
124
|
+
}
|
|
125
|
+
|
|
103
126
|
// src/locales.ts
|
|
104
127
|
function localeLinks(context) {
|
|
105
128
|
const { settings, alternates, homes, locale: current } = context;
|
|
@@ -118,6 +141,50 @@ function nativeName(locale) {
|
|
|
118
141
|
}
|
|
119
142
|
var localeHref = (settings, slug, locale) => buildPath(settings, slug, locale);
|
|
120
143
|
|
|
144
|
+
// src/markers.ts
|
|
145
|
+
function fieldPath(path, pageId) {
|
|
146
|
+
return pageId ? `${pageId}:${path}` : path;
|
|
147
|
+
}
|
|
148
|
+
function navPath(key) {
|
|
149
|
+
return `nav:${key}`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/redirects.ts
|
|
153
|
+
function matchRedirect(redirects, pathname) {
|
|
154
|
+
const path = normalize(pathname);
|
|
155
|
+
for (const r of redirects) {
|
|
156
|
+
const params = matchSource(normalize(r.source), path);
|
|
157
|
+
if (!params) continue;
|
|
158
|
+
const destination = r.destination.replace(
|
|
159
|
+
/:([A-Za-z_][A-Za-z0-9_]*)\*?/g,
|
|
160
|
+
(whole, name) => name in params ? params[name] : whole
|
|
161
|
+
);
|
|
162
|
+
if (normalize(destination) === path) continue;
|
|
163
|
+
return { destination, status: r.status };
|
|
164
|
+
}
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
var normalize = (p) => (p.length > 1 ? p.replace(/\/+$/, "") : p) || "/";
|
|
168
|
+
function matchSource(source, path) {
|
|
169
|
+
const want = source.split("/").filter(Boolean);
|
|
170
|
+
const have = path.split("/").filter(Boolean);
|
|
171
|
+
const params = {};
|
|
172
|
+
for (let i = 0; i < want.length; i++) {
|
|
173
|
+
const seg = want[i];
|
|
174
|
+
const rest = /^:([A-Za-z_][A-Za-z0-9_]*)\*$/.exec(seg);
|
|
175
|
+
if (rest) {
|
|
176
|
+
params[rest[1]] = have.slice(i).join("/");
|
|
177
|
+
return params;
|
|
178
|
+
}
|
|
179
|
+
const value = have[i];
|
|
180
|
+
if (value === void 0) return null;
|
|
181
|
+
const param = /^:([A-Za-z_][A-Za-z0-9_]*)$/.exec(seg);
|
|
182
|
+
if (param) params[param[1]] = value;
|
|
183
|
+
else if (decodeURIComponent(value) !== decodeURIComponent(seg)) return null;
|
|
184
|
+
}
|
|
185
|
+
return want.length === have.length ? params : null;
|
|
186
|
+
}
|
|
187
|
+
|
|
121
188
|
// src/sections.ts
|
|
122
189
|
var sectionsAttrs = { "data-brease-sections": "sections" };
|
|
123
190
|
function sectionAttrs(section) {
|
|
@@ -196,6 +263,54 @@ function checkSections(files, pages = {}) {
|
|
|
196
263
|
return warnings;
|
|
197
264
|
}
|
|
198
265
|
|
|
266
|
+
// src/signature.ts
|
|
267
|
+
var MAX_SKEW_MS = 5 * 6e4;
|
|
268
|
+
async function hmacHex(secret, message) {
|
|
269
|
+
const enc = new TextEncoder();
|
|
270
|
+
const key = await crypto.subtle.importKey(
|
|
271
|
+
"raw",
|
|
272
|
+
enc.encode(secret),
|
|
273
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
274
|
+
false,
|
|
275
|
+
["sign"]
|
|
276
|
+
);
|
|
277
|
+
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
|
|
278
|
+
return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
279
|
+
}
|
|
280
|
+
async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
|
|
281
|
+
if (!timestamp || !signature) return false;
|
|
282
|
+
if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
|
|
283
|
+
const expected = await hmacHex(secret, `${timestamp}.${body}`);
|
|
284
|
+
if (expected.length !== signature.length) return false;
|
|
285
|
+
let diff = 0;
|
|
286
|
+
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
287
|
+
return diff === 0;
|
|
288
|
+
}
|
|
289
|
+
async function verifyRevalidate(req, secret) {
|
|
290
|
+
const raw = await req.text();
|
|
291
|
+
const ok = await verifySignature(
|
|
292
|
+
raw,
|
|
293
|
+
req.headers.get("x-brease-timestamp"),
|
|
294
|
+
req.headers.get("x-brease-signature"),
|
|
295
|
+
secret
|
|
296
|
+
);
|
|
297
|
+
if (!ok) return { ok: false, reason: "signature" };
|
|
298
|
+
let body;
|
|
299
|
+
try {
|
|
300
|
+
body = JSON.parse(raw || "{}");
|
|
301
|
+
} catch {
|
|
302
|
+
return { ok: false, reason: "body" };
|
|
303
|
+
}
|
|
304
|
+
const paths = new Set(body.paths ?? []);
|
|
305
|
+
for (const url of body.urls ?? []) {
|
|
306
|
+
try {
|
|
307
|
+
paths.add(new URL(url, "http://localhost").pathname);
|
|
308
|
+
} catch {
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return { ok: true, paths: [...paths], tags: ["brease", ...body.tags ?? []], body };
|
|
312
|
+
}
|
|
313
|
+
|
|
199
314
|
// src/structured-data.ts
|
|
200
315
|
var jsonLdText = (data) => JSON.stringify(data).replace(/</g, "\\u003c");
|
|
201
316
|
function jsonLd(seo) {
|
|
@@ -216,6 +331,7 @@ function createBrease(opts = {}) {
|
|
|
216
331
|
const baseMs = opts.retryBaseMs ?? 300;
|
|
217
332
|
const doFetch = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
218
333
|
let site;
|
|
334
|
+
let redirects;
|
|
219
335
|
async function request(path, query = {}, nullOn404 = false) {
|
|
220
336
|
const token = opts.token ?? env("BREASE_TOKEN");
|
|
221
337
|
if (!token)
|
|
@@ -270,8 +386,16 @@ function createBrease(opts = {}) {
|
|
|
270
386
|
getNavigation(key, { locale }) {
|
|
271
387
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
272
388
|
},
|
|
389
|
+
// Cached for a minute, like the site: a proxy applies redirects per request (matchRedirect).
|
|
273
390
|
getRedirects() {
|
|
274
|
-
|
|
391
|
+
if (!redirects || Date.now() - redirects.at > SITE_TTL_MS) {
|
|
392
|
+
const promise = request("/content-api/redirects").catch((err) => {
|
|
393
|
+
if (redirects?.promise === promise) redirects = void 0;
|
|
394
|
+
throw err;
|
|
395
|
+
});
|
|
396
|
+
redirects = { promise, at: Date.now() };
|
|
397
|
+
}
|
|
398
|
+
return redirects.promise;
|
|
275
399
|
},
|
|
276
400
|
getRelease() {
|
|
277
401
|
return request("/content-api/release");
|
|
@@ -313,7 +437,9 @@ function createBrease(opts = {}) {
|
|
|
313
437
|
},
|
|
314
438
|
async sitemap(baseUrl) {
|
|
315
439
|
const base = baseUrl.replace(/\/+$/, "");
|
|
316
|
-
const refs = (await client.getPages()).filter(
|
|
440
|
+
const refs = (await client.getPages()).filter(
|
|
441
|
+
(r) => !r.hidden && r.index !== false && !r.slug.split("/").some((part) => part.startsWith("_"))
|
|
442
|
+
);
|
|
317
443
|
const byPage = /* @__PURE__ */ new Map();
|
|
318
444
|
for (const ref of refs) {
|
|
319
445
|
const alternates = byPage.get(ref.pageId) ?? {};
|
|
@@ -337,15 +463,22 @@ exports.BreaseError = BreaseError;
|
|
|
337
463
|
exports.buildPath = buildPath;
|
|
338
464
|
exports.checkSections = checkSections;
|
|
339
465
|
exports.createBrease = createBrease;
|
|
466
|
+
exports.customTags = customTags;
|
|
467
|
+
exports.fieldPath = fieldPath;
|
|
340
468
|
exports.ga4Html = ga4Html;
|
|
341
469
|
exports.ga4Tag = ga4Tag;
|
|
342
470
|
exports.grantAnalytics = grantAnalytics;
|
|
471
|
+
exports.hmacHex = hmacHex;
|
|
343
472
|
exports.jsonLd = jsonLd;
|
|
344
473
|
exports.jsonLdHtml = jsonLdHtml;
|
|
345
474
|
exports.localeHref = localeHref;
|
|
346
475
|
exports.localeLinks = localeLinks;
|
|
476
|
+
exports.matchRedirect = matchRedirect;
|
|
347
477
|
exports.nativeName = nativeName;
|
|
478
|
+
exports.navPath = navPath;
|
|
348
479
|
exports.normalizeSlug = normalizeSlug;
|
|
349
480
|
exports.resolvePath = resolvePath;
|
|
350
481
|
exports.sectionAttrs = sectionAttrs;
|
|
351
482
|
exports.sectionsAttrs = sectionsAttrs;
|
|
483
|
+
exports.verifyRevalidate = verifyRevalidate;
|
|
484
|
+
exports.verifySignature = verifySignature;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Site, U as UrlSettings,
|
|
2
|
-
export { L as LocaleStrategy,
|
|
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';
|
|
3
3
|
|
|
4
4
|
type Ga4Tag = {
|
|
5
5
|
id: string;
|
|
@@ -10,6 +10,13 @@ declare function ga4Tag(site: Pick<Site, 'analytics'>): Ga4Tag | null;
|
|
|
10
10
|
declare function ga4Html(site: Pick<Site, 'analytics'>): string;
|
|
11
11
|
declare function grantAnalytics(granted?: boolean): void;
|
|
12
12
|
|
|
13
|
+
type CustomTag = {
|
|
14
|
+
tag: 'script' | 'style' | 'meta' | 'link' | 'noscript';
|
|
15
|
+
attrs: Record<string, string>;
|
|
16
|
+
content?: string;
|
|
17
|
+
};
|
|
18
|
+
declare function customTags(seo: Pick<ResolvedSeo, 'customHead' | 'customCode'>): CustomTag[];
|
|
19
|
+
|
|
13
20
|
declare class BreaseError extends Error {
|
|
14
21
|
code: string;
|
|
15
22
|
status: number;
|
|
@@ -30,6 +37,14 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
|
|
|
30
37
|
declare function nativeName(locale: string): string;
|
|
31
38
|
declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
|
|
32
39
|
|
|
40
|
+
declare function fieldPath(path: string, pageId?: string): string;
|
|
41
|
+
declare function navPath(key: string): string;
|
|
42
|
+
|
|
43
|
+
declare function matchRedirect(redirects: Redirect[], pathname: string): {
|
|
44
|
+
destination: string;
|
|
45
|
+
status: Redirect['status'];
|
|
46
|
+
} | null;
|
|
47
|
+
|
|
33
48
|
type BreaseSection<T = Record<string, unknown>> = {
|
|
34
49
|
id: string;
|
|
35
50
|
type: string;
|
|
@@ -49,6 +64,31 @@ type PageLocales = Record<string, Record<string, {
|
|
|
49
64
|
}>>;
|
|
50
65
|
declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
|
|
51
66
|
|
|
67
|
+
type RevalidateBody = {
|
|
68
|
+
urls?: string[];
|
|
69
|
+
paths?: string[];
|
|
70
|
+
tags?: string[];
|
|
71
|
+
releaseId?: string;
|
|
72
|
+
siteId?: string;
|
|
73
|
+
};
|
|
74
|
+
declare function hmacHex(secret: string, message: string): Promise<string>;
|
|
75
|
+
declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
|
|
76
|
+
type RevalidateTarget = {
|
|
77
|
+
ok: true;
|
|
78
|
+
paths: string[];
|
|
79
|
+
tags: string[];
|
|
80
|
+
body: RevalidateBody;
|
|
81
|
+
} | {
|
|
82
|
+
ok: false;
|
|
83
|
+
reason: 'signature' | 'body';
|
|
84
|
+
};
|
|
85
|
+
declare function verifyRevalidate(req: {
|
|
86
|
+
text(): Promise<string>;
|
|
87
|
+
headers: {
|
|
88
|
+
get(name: string): string | null;
|
|
89
|
+
};
|
|
90
|
+
}, secret: string): Promise<RevalidateTarget>;
|
|
91
|
+
|
|
52
92
|
type JsonLd = {
|
|
53
93
|
data: Record<string, unknown>;
|
|
54
94
|
json: string;
|
|
@@ -106,4 +146,4 @@ interface Brease {
|
|
|
106
146
|
}
|
|
107
147
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
108
148
|
|
|
109
|
-
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, ga4Html, ga4Tag, grantAnalytics, jsonLd, jsonLdHtml, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Site, U as UrlSettings,
|
|
2
|
-
export { L as LocaleStrategy,
|
|
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';
|
|
3
3
|
|
|
4
4
|
type Ga4Tag = {
|
|
5
5
|
id: string;
|
|
@@ -10,6 +10,13 @@ declare function ga4Tag(site: Pick<Site, 'analytics'>): Ga4Tag | null;
|
|
|
10
10
|
declare function ga4Html(site: Pick<Site, 'analytics'>): string;
|
|
11
11
|
declare function grantAnalytics(granted?: boolean): void;
|
|
12
12
|
|
|
13
|
+
type CustomTag = {
|
|
14
|
+
tag: 'script' | 'style' | 'meta' | 'link' | 'noscript';
|
|
15
|
+
attrs: Record<string, string>;
|
|
16
|
+
content?: string;
|
|
17
|
+
};
|
|
18
|
+
declare function customTags(seo: Pick<ResolvedSeo, 'customHead' | 'customCode'>): CustomTag[];
|
|
19
|
+
|
|
13
20
|
declare class BreaseError extends Error {
|
|
14
21
|
code: string;
|
|
15
22
|
status: number;
|
|
@@ -30,6 +37,14 @@ declare function localeLinks(context: LocaleContext): LocaleLink[];
|
|
|
30
37
|
declare function nativeName(locale: string): string;
|
|
31
38
|
declare const localeHref: (settings: UrlSettings, slug: string, locale: string) => string;
|
|
32
39
|
|
|
40
|
+
declare function fieldPath(path: string, pageId?: string): string;
|
|
41
|
+
declare function navPath(key: string): string;
|
|
42
|
+
|
|
43
|
+
declare function matchRedirect(redirects: Redirect[], pathname: string): {
|
|
44
|
+
destination: string;
|
|
45
|
+
status: Redirect['status'];
|
|
46
|
+
} | null;
|
|
47
|
+
|
|
33
48
|
type BreaseSection<T = Record<string, unknown>> = {
|
|
34
49
|
id: string;
|
|
35
50
|
type: string;
|
|
@@ -49,6 +64,31 @@ type PageLocales = Record<string, Record<string, {
|
|
|
49
64
|
}>>;
|
|
50
65
|
declare function checkSections(files: Record<string, string>, pages?: PageLocales): string[];
|
|
51
66
|
|
|
67
|
+
type RevalidateBody = {
|
|
68
|
+
urls?: string[];
|
|
69
|
+
paths?: string[];
|
|
70
|
+
tags?: string[];
|
|
71
|
+
releaseId?: string;
|
|
72
|
+
siteId?: string;
|
|
73
|
+
};
|
|
74
|
+
declare function hmacHex(secret: string, message: string): Promise<string>;
|
|
75
|
+
declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
|
|
76
|
+
type RevalidateTarget = {
|
|
77
|
+
ok: true;
|
|
78
|
+
paths: string[];
|
|
79
|
+
tags: string[];
|
|
80
|
+
body: RevalidateBody;
|
|
81
|
+
} | {
|
|
82
|
+
ok: false;
|
|
83
|
+
reason: 'signature' | 'body';
|
|
84
|
+
};
|
|
85
|
+
declare function verifyRevalidate(req: {
|
|
86
|
+
text(): Promise<string>;
|
|
87
|
+
headers: {
|
|
88
|
+
get(name: string): string | null;
|
|
89
|
+
};
|
|
90
|
+
}, secret: string): Promise<RevalidateTarget>;
|
|
91
|
+
|
|
52
92
|
type JsonLd = {
|
|
53
93
|
data: Record<string, unknown>;
|
|
54
94
|
json: string;
|
|
@@ -106,4 +146,4 @@ interface Brease {
|
|
|
106
146
|
}
|
|
107
147
|
declare function createBrease(opts?: BreaseOptions): Brease;
|
|
108
148
|
|
|
109
|
-
export { type Brease, BreaseError, type BreaseOptions, type BreaseSection, type Ga4Tag, type JsonLd, type LocaleContext, type LocaleLink, Navigation, Page, PageRef, Redirect, Release, ResolvedSeo, Site, SitemapEntry, UrlSettings, buildPath, checkSections, createBrease, ga4Html, ga4Tag, grantAnalytics, jsonLd, jsonLdHtml, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath, sectionAttrs, sectionsAttrs };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { BreaseError, buildPath, createBrease, ga4Html, ga4Tag, grantAnalytics, localeHref, localeLinks, nativeName, normalizeSlug, resolvePath } from './chunk-
|
|
1
|
+
export { BreaseError, buildPath, createBrease, customTags, fieldPath, ga4Html, ga4Tag, grantAnalytics, hmacHex, localeHref, localeLinks, matchRedirect, nativeName, navPath, normalizeSlug, resolvePath, verifyRevalidate, verifySignature } from './chunk-SO4BD4ME.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
|
@@ -67,6 +67,54 @@ function resolvePath(settings, pathname) {
|
|
|
67
67
|
return { slug: clean, locale: settings.defaultLocale };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// src/signature.ts
|
|
71
|
+
var MAX_SKEW_MS = 5 * 6e4;
|
|
72
|
+
async function hmacHex(secret, message) {
|
|
73
|
+
const enc = new TextEncoder();
|
|
74
|
+
const key = await crypto.subtle.importKey(
|
|
75
|
+
"raw",
|
|
76
|
+
enc.encode(secret),
|
|
77
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
78
|
+
false,
|
|
79
|
+
["sign"]
|
|
80
|
+
);
|
|
81
|
+
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
|
|
82
|
+
return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
83
|
+
}
|
|
84
|
+
async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
|
|
85
|
+
if (!timestamp || !signature) return false;
|
|
86
|
+
if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
|
|
87
|
+
const expected = await hmacHex(secret, `${timestamp}.${body}`);
|
|
88
|
+
if (expected.length !== signature.length) return false;
|
|
89
|
+
let diff = 0;
|
|
90
|
+
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
91
|
+
return diff === 0;
|
|
92
|
+
}
|
|
93
|
+
async function verifyRevalidate(req, secret) {
|
|
94
|
+
const raw = await req.text();
|
|
95
|
+
const ok = await verifySignature(
|
|
96
|
+
raw,
|
|
97
|
+
req.headers.get("x-brease-timestamp"),
|
|
98
|
+
req.headers.get("x-brease-signature"),
|
|
99
|
+
secret
|
|
100
|
+
);
|
|
101
|
+
if (!ok) return { ok: false, reason: "signature" };
|
|
102
|
+
let body;
|
|
103
|
+
try {
|
|
104
|
+
body = JSON.parse(raw || "{}");
|
|
105
|
+
} catch {
|
|
106
|
+
return { ok: false, reason: "body" };
|
|
107
|
+
}
|
|
108
|
+
const paths = new Set(body.paths ?? []);
|
|
109
|
+
for (const url of body.urls ?? []) {
|
|
110
|
+
try {
|
|
111
|
+
paths.add(new URL(url, "http://localhost").pathname);
|
|
112
|
+
} catch {
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { ok: true, paths: [...paths], tags: ["brease", ...body.tags ?? []], body };
|
|
116
|
+
}
|
|
117
|
+
|
|
70
118
|
// src/index.ts
|
|
71
119
|
var RETRY_AFTER_CAP_MS = 1e4;
|
|
72
120
|
var SITE_TTL_MS = 6e4;
|
|
@@ -78,6 +126,7 @@ function createBrease(opts = {}) {
|
|
|
78
126
|
const baseMs = opts.retryBaseMs ?? 300;
|
|
79
127
|
const doFetch = opts.fetch ?? ((input, init) => fetch(input, init));
|
|
80
128
|
let site;
|
|
129
|
+
let redirects;
|
|
81
130
|
async function request(path, query = {}, nullOn404 = false) {
|
|
82
131
|
const token = opts.token ?? env("BREASE_TOKEN");
|
|
83
132
|
if (!token)
|
|
@@ -132,8 +181,16 @@ function createBrease(opts = {}) {
|
|
|
132
181
|
getNavigation(key, { locale }) {
|
|
133
182
|
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
134
183
|
},
|
|
184
|
+
// Cached for a minute, like the site: a proxy applies redirects per request (matchRedirect).
|
|
135
185
|
getRedirects() {
|
|
136
|
-
|
|
186
|
+
if (!redirects || Date.now() - redirects.at > SITE_TTL_MS) {
|
|
187
|
+
const promise = request("/content-api/redirects").catch((err) => {
|
|
188
|
+
if (redirects?.promise === promise) redirects = void 0;
|
|
189
|
+
throw err;
|
|
190
|
+
});
|
|
191
|
+
redirects = { promise, at: Date.now() };
|
|
192
|
+
}
|
|
193
|
+
return redirects.promise;
|
|
137
194
|
},
|
|
138
195
|
getRelease() {
|
|
139
196
|
return request("/content-api/release");
|
|
@@ -175,7 +232,9 @@ function createBrease(opts = {}) {
|
|
|
175
232
|
},
|
|
176
233
|
async sitemap(baseUrl) {
|
|
177
234
|
const base = baseUrl.replace(/\/+$/, "");
|
|
178
|
-
const refs = (await client.getPages()).filter(
|
|
235
|
+
const refs = (await client.getPages()).filter(
|
|
236
|
+
(r) => !r.hidden && r.index !== false && !r.slug.split("/").some((part) => part.startsWith("_"))
|
|
237
|
+
);
|
|
179
238
|
const byPage = /* @__PURE__ */ new Map();
|
|
180
239
|
for (const ref of refs) {
|
|
181
240
|
const alternates = byPage.get(ref.pageId) ?? {};
|
|
@@ -230,61 +289,20 @@ function breaseFetch(tags = [], revalidate) {
|
|
|
230
289
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
231
290
|
});
|
|
232
291
|
}
|
|
233
|
-
var MAX_SKEW_MS = 5 * 6e4;
|
|
234
292
|
function revalidateHandler(secret) {
|
|
235
293
|
return async (req) => {
|
|
236
294
|
const key = secret ?? env("BREASE_REVALIDATE_SECRET");
|
|
237
295
|
if (!key)
|
|
238
296
|
return json(500, { error: { code: "internal", message: "BREASE_REVALIDATE_SECRET is not set" } });
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
req.headers.get("x-brease-timestamp"),
|
|
243
|
-
req.headers.get("x-brease-signature"),
|
|
244
|
-
key
|
|
245
|
-
);
|
|
246
|
-
if (!ok) return json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
|
|
247
|
-
let body;
|
|
248
|
-
try {
|
|
249
|
-
body = JSON.parse(raw || "{}");
|
|
250
|
-
} catch {
|
|
251
|
-
return json(400, { error: { code: "validation", message: "Body must be JSON" } });
|
|
252
|
-
}
|
|
253
|
-
const paths = new Set(body.paths ?? []);
|
|
254
|
-
for (const url of body.urls ?? []) {
|
|
255
|
-
try {
|
|
256
|
-
paths.add(new URL(url, "http://localhost").pathname);
|
|
257
|
-
} catch {
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const tags = /* @__PURE__ */ new Set(["brease", ...body.tags ?? []]);
|
|
297
|
+
const target = await verifyRevalidate(req, key);
|
|
298
|
+
if (!target.ok)
|
|
299
|
+
return target.reason === "body" ? json(400, { error: { code: "validation", message: "Body must be JSON" } }) : json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
|
|
261
300
|
const cache = await import('next/cache');
|
|
262
|
-
for (const path of paths) cache.revalidatePath(path);
|
|
263
|
-
for (const tag of tags) cache.revalidateTag(tag,
|
|
264
|
-
return json(200, { revalidated: true, paths:
|
|
301
|
+
for (const path of target.paths) cache.revalidatePath(path);
|
|
302
|
+
for (const tag of target.tags) cache.revalidateTag(tag, { expire: 0 });
|
|
303
|
+
return json(200, { revalidated: true, paths: target.paths, tags: target.tags });
|
|
265
304
|
};
|
|
266
305
|
}
|
|
267
|
-
async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
|
|
268
|
-
if (!timestamp || !signature) return false;
|
|
269
|
-
if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
|
|
270
|
-
const expected = await hmacHex(secret, `${timestamp}.${body}`);
|
|
271
|
-
if (expected.length !== signature.length) return false;
|
|
272
|
-
let diff = 0;
|
|
273
|
-
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
274
|
-
return diff === 0;
|
|
275
|
-
}
|
|
276
|
-
async function hmacHex(secret, message) {
|
|
277
|
-
const enc = new TextEncoder();
|
|
278
|
-
const key = await crypto.subtle.importKey(
|
|
279
|
-
"raw",
|
|
280
|
-
enc.encode(secret),
|
|
281
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
282
|
-
false,
|
|
283
|
-
["sign"]
|
|
284
|
-
);
|
|
285
|
-
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
|
|
286
|
-
return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
287
|
-
}
|
|
288
306
|
function json(status, data) {
|
|
289
307
|
return new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
|
|
290
308
|
}
|
package/dist/next.d.cts
CHANGED
|
@@ -1,5 +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
4
|
|
|
4
5
|
type BreaseMetadata = {
|
|
5
6
|
title: {
|
|
@@ -42,12 +43,10 @@ declare function toMetadata(seo: ResolvedSeo, opts?: {
|
|
|
42
43
|
}): BreaseMetadata;
|
|
43
44
|
declare function breaseFetch(tags?: string[], revalidate?: number | false): typeof fetch;
|
|
44
45
|
declare function revalidateHandler(secret?: string): (req: Request) => Promise<Response>;
|
|
45
|
-
declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
|
|
46
|
-
declare function hmacHex(secret: string, message: string): Promise<string>;
|
|
47
46
|
declare function breaseRedirects(client?: Pick<Brease, 'getRedirects'>): () => Promise<{
|
|
48
47
|
source: string;
|
|
49
48
|
destination: string;
|
|
50
49
|
statusCode: 301 | 302 | 307 | 308;
|
|
51
50
|
}[]>;
|
|
52
51
|
|
|
53
|
-
export { type BreaseMetadata, breaseFetch, breaseRedirects,
|
|
52
|
+
export { type BreaseMetadata, breaseFetch, breaseRedirects, revalidateHandler, toMetadata };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,5 +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
4
|
|
|
4
5
|
type BreaseMetadata = {
|
|
5
6
|
title: {
|
|
@@ -42,12 +43,10 @@ declare function toMetadata(seo: ResolvedSeo, opts?: {
|
|
|
42
43
|
}): BreaseMetadata;
|
|
43
44
|
declare function breaseFetch(tags?: string[], revalidate?: number | false): typeof fetch;
|
|
44
45
|
declare function revalidateHandler(secret?: string): (req: Request) => Promise<Response>;
|
|
45
|
-
declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
|
|
46
|
-
declare function hmacHex(secret: string, message: string): Promise<string>;
|
|
47
46
|
declare function breaseRedirects(client?: Pick<Brease, 'getRedirects'>): () => Promise<{
|
|
48
47
|
source: string;
|
|
49
48
|
destination: string;
|
|
50
49
|
statusCode: 301 | 302 | 307 | 308;
|
|
51
50
|
}[]>;
|
|
52
51
|
|
|
53
|
-
export { type BreaseMetadata, breaseFetch, breaseRedirects,
|
|
52
|
+
export { type BreaseMetadata, breaseFetch, breaseRedirects, revalidateHandler, toMetadata };
|
package/dist/next.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { env, createBrease } from './chunk-
|
|
1
|
+
import { env, verifyRevalidate, createBrease } from './chunk-SO4BD4ME.js';
|
|
2
|
+
export { hmacHex, verifySignature } from './chunk-SO4BD4ME.js';
|
|
2
3
|
import './chunk-CQZLTZGN.js';
|
|
3
4
|
import './chunk-N3QOL5EU.js';
|
|
4
5
|
import './chunk-PKBMQBKP.js';
|
|
@@ -38,61 +39,20 @@ function breaseFetch(tags = [], revalidate) {
|
|
|
38
39
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
|
-
var MAX_SKEW_MS = 5 * 6e4;
|
|
42
42
|
function revalidateHandler(secret) {
|
|
43
43
|
return async (req) => {
|
|
44
44
|
const key = secret ?? env("BREASE_REVALIDATE_SECRET");
|
|
45
45
|
if (!key)
|
|
46
46
|
return json(500, { error: { code: "internal", message: "BREASE_REVALIDATE_SECRET is not set" } });
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
req.headers.get("x-brease-timestamp"),
|
|
51
|
-
req.headers.get("x-brease-signature"),
|
|
52
|
-
key
|
|
53
|
-
);
|
|
54
|
-
if (!ok) return json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
|
|
55
|
-
let body;
|
|
56
|
-
try {
|
|
57
|
-
body = JSON.parse(raw || "{}");
|
|
58
|
-
} catch {
|
|
59
|
-
return json(400, { error: { code: "validation", message: "Body must be JSON" } });
|
|
60
|
-
}
|
|
61
|
-
const paths = new Set(body.paths ?? []);
|
|
62
|
-
for (const url of body.urls ?? []) {
|
|
63
|
-
try {
|
|
64
|
-
paths.add(new URL(url, "http://localhost").pathname);
|
|
65
|
-
} catch {
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const tags = /* @__PURE__ */ new Set(["brease", ...body.tags ?? []]);
|
|
47
|
+
const target = await verifyRevalidate(req, key);
|
|
48
|
+
if (!target.ok)
|
|
49
|
+
return target.reason === "body" ? json(400, { error: { code: "validation", message: "Body must be JSON" } }) : json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
|
|
69
50
|
const cache = await import('next/cache');
|
|
70
|
-
for (const path of paths) cache.revalidatePath(path);
|
|
71
|
-
for (const tag of tags) cache.revalidateTag(tag,
|
|
72
|
-
return json(200, { revalidated: true, paths:
|
|
51
|
+
for (const path of target.paths) cache.revalidatePath(path);
|
|
52
|
+
for (const tag of target.tags) cache.revalidateTag(tag, { expire: 0 });
|
|
53
|
+
return json(200, { revalidated: true, paths: target.paths, tags: target.tags });
|
|
73
54
|
};
|
|
74
55
|
}
|
|
75
|
-
async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
|
|
76
|
-
if (!timestamp || !signature) return false;
|
|
77
|
-
if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
|
|
78
|
-
const expected = await hmacHex(secret, `${timestamp}.${body}`);
|
|
79
|
-
if (expected.length !== signature.length) return false;
|
|
80
|
-
let diff = 0;
|
|
81
|
-
for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
|
|
82
|
-
return diff === 0;
|
|
83
|
-
}
|
|
84
|
-
async function hmacHex(secret, message) {
|
|
85
|
-
const enc = new TextEncoder();
|
|
86
|
-
const key = await crypto.subtle.importKey(
|
|
87
|
-
"raw",
|
|
88
|
-
enc.encode(secret),
|
|
89
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
90
|
-
false,
|
|
91
|
-
["sign"]
|
|
92
|
-
);
|
|
93
|
-
const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
|
|
94
|
-
return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
95
|
-
}
|
|
96
56
|
function json(status, data) {
|
|
97
57
|
return new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
|
|
98
58
|
}
|
|
@@ -108,4 +68,4 @@ function breaseRedirects(client = createBrease()) {
|
|
|
108
68
|
};
|
|
109
69
|
}
|
|
110
70
|
|
|
111
|
-
export { breaseFetch, breaseRedirects,
|
|
71
|
+
export { breaseFetch, breaseRedirects, revalidateHandler, toMetadata };
|
|
@@ -25,6 +25,7 @@ type Twitter = {
|
|
|
25
25
|
};
|
|
26
26
|
type PageSeo = {
|
|
27
27
|
title?: string;
|
|
28
|
+
useTitleTemplate?: boolean;
|
|
28
29
|
description?: string;
|
|
29
30
|
canonical?: string;
|
|
30
31
|
robots?: Robots;
|
|
@@ -33,12 +34,18 @@ type PageSeo = {
|
|
|
33
34
|
structuredData?: Record<string, unknown>[];
|
|
34
35
|
customCode?: string;
|
|
35
36
|
};
|
|
36
|
-
type SiteSeo =
|
|
37
|
+
type SiteSeo = {
|
|
37
38
|
titleTemplate?: string;
|
|
38
39
|
siteName?: string;
|
|
40
|
+
description?: string;
|
|
39
41
|
defaultImage?: string;
|
|
40
42
|
favicon?: string;
|
|
43
|
+
robots?: Robots;
|
|
44
|
+
openGraph?: Pick<OpenGraph, 'type' | 'image'>;
|
|
45
|
+
twitter?: Pick<Twitter, 'card' | 'site' | 'creator'>;
|
|
46
|
+
structuredData?: Record<string, unknown>[];
|
|
41
47
|
customHead?: string;
|
|
48
|
+
customCode?: string;
|
|
42
49
|
};
|
|
43
50
|
type ResolvedSeo = {
|
|
44
51
|
title: string;
|
|
@@ -69,6 +76,20 @@ type Site = {
|
|
|
69
76
|
analytics?: {
|
|
70
77
|
ga4: string;
|
|
71
78
|
} | null;
|
|
79
|
+
url?: string | null;
|
|
80
|
+
};
|
|
81
|
+
type BreaseImage = {
|
|
82
|
+
assetId: string;
|
|
83
|
+
url: string;
|
|
84
|
+
alt?: string;
|
|
85
|
+
width?: number;
|
|
86
|
+
height?: number;
|
|
87
|
+
};
|
|
88
|
+
type BreaseLink = {
|
|
89
|
+
label?: string;
|
|
90
|
+
href: string;
|
|
91
|
+
pageId?: string;
|
|
92
|
+
target?: '_self' | '_blank';
|
|
72
93
|
};
|
|
73
94
|
type Page<T = Record<string, unknown>> = {
|
|
74
95
|
pageId: string;
|
|
@@ -82,7 +103,12 @@ type Page<T = Record<string, unknown>> = {
|
|
|
82
103
|
resolvedSeo: ResolvedSeo;
|
|
83
104
|
alternates: Record<string, string>;
|
|
84
105
|
};
|
|
85
|
-
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'
|
|
106
|
+
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
107
|
+
name?: string;
|
|
108
|
+
index?: boolean;
|
|
109
|
+
parentId?: string | null;
|
|
110
|
+
order?: number;
|
|
111
|
+
};
|
|
86
112
|
type NavigationItem = {
|
|
87
113
|
id: string;
|
|
88
114
|
label: string;
|
|
@@ -113,4 +139,4 @@ type SitemapEntry = {
|
|
|
113
139
|
alternates: Record<string, string>;
|
|
114
140
|
};
|
|
115
141
|
|
|
116
|
-
export type { LocaleStrategy as L, Navigation as N, OpenGraph as O, Page as P, ResolvedSeo as R, Site as S, Twitter as T, UrlSettings as U,
|
|
142
|
+
export type { BreaseImage as B, LocaleStrategy as L, Navigation as N, OpenGraph as O, Page as P, ResolvedSeo as R, Site as S, Twitter as T, UrlSettings as U, Redirect as a, PageRef as b, Release as c, SitemapEntry as d, BreaseLink as e, NavigationItem as f, PageSeo as g, Robots as h, SiteSeo as i };
|
|
@@ -25,6 +25,7 @@ type Twitter = {
|
|
|
25
25
|
};
|
|
26
26
|
type PageSeo = {
|
|
27
27
|
title?: string;
|
|
28
|
+
useTitleTemplate?: boolean;
|
|
28
29
|
description?: string;
|
|
29
30
|
canonical?: string;
|
|
30
31
|
robots?: Robots;
|
|
@@ -33,12 +34,18 @@ type PageSeo = {
|
|
|
33
34
|
structuredData?: Record<string, unknown>[];
|
|
34
35
|
customCode?: string;
|
|
35
36
|
};
|
|
36
|
-
type SiteSeo =
|
|
37
|
+
type SiteSeo = {
|
|
37
38
|
titleTemplate?: string;
|
|
38
39
|
siteName?: string;
|
|
40
|
+
description?: string;
|
|
39
41
|
defaultImage?: string;
|
|
40
42
|
favicon?: string;
|
|
43
|
+
robots?: Robots;
|
|
44
|
+
openGraph?: Pick<OpenGraph, 'type' | 'image'>;
|
|
45
|
+
twitter?: Pick<Twitter, 'card' | 'site' | 'creator'>;
|
|
46
|
+
structuredData?: Record<string, unknown>[];
|
|
41
47
|
customHead?: string;
|
|
48
|
+
customCode?: string;
|
|
42
49
|
};
|
|
43
50
|
type ResolvedSeo = {
|
|
44
51
|
title: string;
|
|
@@ -69,6 +76,20 @@ type Site = {
|
|
|
69
76
|
analytics?: {
|
|
70
77
|
ga4: string;
|
|
71
78
|
} | null;
|
|
79
|
+
url?: string | null;
|
|
80
|
+
};
|
|
81
|
+
type BreaseImage = {
|
|
82
|
+
assetId: string;
|
|
83
|
+
url: string;
|
|
84
|
+
alt?: string;
|
|
85
|
+
width?: number;
|
|
86
|
+
height?: number;
|
|
87
|
+
};
|
|
88
|
+
type BreaseLink = {
|
|
89
|
+
label?: string;
|
|
90
|
+
href: string;
|
|
91
|
+
pageId?: string;
|
|
92
|
+
target?: '_self' | '_blank';
|
|
72
93
|
};
|
|
73
94
|
type Page<T = Record<string, unknown>> = {
|
|
74
95
|
pageId: string;
|
|
@@ -82,7 +103,12 @@ type Page<T = Record<string, unknown>> = {
|
|
|
82
103
|
resolvedSeo: ResolvedSeo;
|
|
83
104
|
alternates: Record<string, string>;
|
|
84
105
|
};
|
|
85
|
-
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'
|
|
106
|
+
type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
|
|
107
|
+
name?: string;
|
|
108
|
+
index?: boolean;
|
|
109
|
+
parentId?: string | null;
|
|
110
|
+
order?: number;
|
|
111
|
+
};
|
|
86
112
|
type NavigationItem = {
|
|
87
113
|
id: string;
|
|
88
114
|
label: string;
|
|
@@ -113,4 +139,4 @@ type SitemapEntry = {
|
|
|
113
139
|
alternates: Record<string, string>;
|
|
114
140
|
};
|
|
115
141
|
|
|
116
|
-
export type { LocaleStrategy as L, Navigation as N, OpenGraph as O, Page as P, ResolvedSeo as R, Site as S, Twitter as T, UrlSettings as U,
|
|
142
|
+
export type { BreaseImage as B, LocaleStrategy as L, Navigation as N, OpenGraph as O, Page as P, ResolvedSeo as R, Site as S, Twitter as T, UrlSettings as U, Redirect as a, PageRef as b, Release as c, SitemapEntry as d, BreaseLink as e, NavigationItem as f, PageSeo as g, Robots as h, SiteSeo as i };
|