brease-client 0.7.1 → 0.8.1

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/dist/next.js CHANGED
@@ -1,4 +1,5 @@
1
- import { env, createBrease } from './chunk-GJ3SOWDB.js';
1
+ import { env, verifyRevalidate, createBrease } from './chunk-MWTYINWA.js';
2
+ export { hmacHex, verifySignature } from './chunk-MWTYINWA.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 raw = await req.text();
48
- const ok = await verifySignature(
49
- raw,
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, "max");
72
- return json(200, { revalidated: true, paths: [...paths], tags: [...tags] });
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, hmacHex, revalidateHandler, toMetadata, verifySignature };
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 = PageSeo & {
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,14 @@ 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<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
107
+ name?: string;
108
+ index?: boolean;
109
+ parentId?: string | null;
110
+ order?: number;
111
+ template?: string | null;
112
+ content?: T;
113
+ };
86
114
  type NavigationItem = {
87
115
  id: string;
88
116
  label: string;
@@ -113,4 +141,4 @@ type SitemapEntry = {
113
141
  alternates: Record<string, string>;
114
142
  };
115
143
 
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, PageRef as a, Redirect as b, Release as c, SitemapEntry as d, NavigationItem as e, PageSeo as f, Robots as g, SiteSeo as h };
144
+ 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 = PageSeo & {
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,14 @@ 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<T = Record<string, unknown>> = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'> & {
107
+ name?: string;
108
+ index?: boolean;
109
+ parentId?: string | null;
110
+ order?: number;
111
+ template?: string | null;
112
+ content?: T;
113
+ };
86
114
  type NavigationItem = {
87
115
  id: string;
88
116
  label: string;
@@ -113,4 +141,4 @@ type SitemapEntry = {
113
141
  alternates: Record<string, string>;
114
142
  };
115
143
 
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, PageRef as a, Redirect as b, Release as c, SitemapEntry as d, NavigationItem as e, PageSeo as f, Robots as g, SiteSeo as h };
144
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brease-client",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
4
  "description": "Brease delivery API client for Next.js, Astro and any fetch-capable runtime",
5
5
  "license": "MIT",
6
6
  "repository": {