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/README.md +92 -27
- package/dist/astro.d.cts +1 -1
- package/dist/astro.d.ts +1 -1
- package/dist/{chunk-GJ3SOWDB.js → chunk-MWTYINWA.js} +142 -4
- 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 +149 -3
- package/dist/index.d.cts +47 -3
- package/dist/index.d.ts +47 -3
- package/dist/index.js +1 -1
- package/dist/next.cjs +73 -50
- 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-D5mwpqAP.d.cts} +31 -3
- package/dist/{types-ecfDXrLa.d.ts → types-D5mwpqAP.d.ts} +31 -3
- package/package.json +1 -1
package/dist/next.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { env, createBrease } from './chunk-
|
|
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
|
|
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,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,
|
|
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 =
|
|
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,
|
|
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 };
|