brease-client 0.1.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/dist/index.cjs ADDED
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+
7
+ // src/env.ts
8
+ function env(name) {
9
+ const proc = globalThis.process;
10
+ const value = proc?.env?.[name];
11
+ return value === "" ? void 0 : value;
12
+ }
13
+
14
+ // src/errors.ts
15
+ var BreaseError = class _BreaseError extends Error {
16
+ constructor(code, message, status, requestId, details) {
17
+ super(message);
18
+ __publicField(this, "code", code);
19
+ __publicField(this, "status", status);
20
+ __publicField(this, "requestId", requestId);
21
+ __publicField(this, "details", details);
22
+ __publicField(this, "name", "BreaseError");
23
+ }
24
+ static async fromResponse(res) {
25
+ const requestId = res.headers.get("x-request-id") ?? res.headers.get("x-vercel-id") ?? void 0;
26
+ let code = res.status === 429 ? "rate_limited" : res.status >= 500 ? "upstream" : "http_error";
27
+ let message = `Brease API responded ${res.status}`;
28
+ let details;
29
+ try {
30
+ const body = await res.json();
31
+ if (body?.error) {
32
+ code = body.error.code ?? code;
33
+ message = body.error.message ?? message;
34
+ details = body.error.details;
35
+ }
36
+ } catch {
37
+ }
38
+ return new _BreaseError(code, message, res.status, requestId ?? void 0, details);
39
+ }
40
+ };
41
+
42
+ // src/urls.ts
43
+ function normalizeSlug(input) {
44
+ return input.trim().replace(/^\/+|\/+$/g, "").replace(/\/{2,}/g, "/");
45
+ }
46
+ function buildPath(settings, slug, locale) {
47
+ const clean = normalizeSlug(slug);
48
+ if (settings.localeStrategy === "CUSTOM" && settings.urlTemplate) {
49
+ const path = settings.urlTemplate.replace("{locale}", locale).replace("{slug}", clean);
50
+ return `/${normalizeSlug(path)}`;
51
+ }
52
+ const prefixed = settings.localeStrategy === "PREFIX_ALL" || locale !== settings.defaultLocale;
53
+ const parts = [prefixed ? locale : "", clean].filter(Boolean);
54
+ return `/${parts.join("/")}`;
55
+ }
56
+ function resolvePath(settings, pathname) {
57
+ const clean = normalizeSlug(decodeURIComponent(pathname.split(/[?#]/)[0] ?? ""));
58
+ if (settings.localeStrategy === "CUSTOM" && settings.urlTemplate) {
59
+ const pattern = normalizeSlug(settings.urlTemplate).split(/(\{locale\}|\{slug\})/).map((part) => {
60
+ if (part === "{locale}") return "(?<locale>[^/]+)";
61
+ if (part === "{slug}") return "(?<slug>.*)";
62
+ return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
63
+ }).join("");
64
+ const match = new RegExp(`^${pattern}$`).exec(clean);
65
+ if (match?.groups) {
66
+ return {
67
+ slug: normalizeSlug(match.groups.slug ?? ""),
68
+ locale: match.groups.locale ?? settings.defaultLocale
69
+ };
70
+ }
71
+ return { slug: clean, locale: settings.defaultLocale };
72
+ }
73
+ const [first, ...rest] = clean.split("/");
74
+ if (first && settings.locales.includes(first)) {
75
+ return { slug: rest.join("/"), locale: first };
76
+ }
77
+ return { slug: clean, locale: settings.defaultLocale };
78
+ }
79
+
80
+ // src/index.ts
81
+ var RETRY_AFTER_CAP_MS = 1e4;
82
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
83
+ function createBrease(opts = {}) {
84
+ const apiUrl = (opts.apiUrl ?? env("BREASE_API_URL") ?? "https://api.brease.io").replace(/\/+$/, "");
85
+ const commit = opts.commit === false ? void 0 : opts.commit ?? env("VERCEL_GIT_COMMIT_SHA");
86
+ const retries = opts.retries ?? 2;
87
+ const baseMs = opts.retryBaseMs ?? 300;
88
+ const doFetch = opts.fetch ?? ((input, init) => fetch(input, init));
89
+ let sitePromise;
90
+ async function request(path, query = {}, nullOn404 = false) {
91
+ const token = opts.token ?? env("BREASE_TOKEN");
92
+ if (!token)
93
+ throw new BreaseError("unauthorized", "No Brease token: pass { token } or set BREASE_TOKEN", 401);
94
+ const params = new URLSearchParams();
95
+ for (const [k, v] of Object.entries(query)) if (v !== void 0) params.set(k, v);
96
+ const qs = params.toString();
97
+ const url = `${apiUrl}${path}${qs ? `?${qs}` : ""}`;
98
+ const headers = { authorization: `Bearer ${token}`, accept: "application/json" };
99
+ if (commit) headers["x-brease-commit"] = commit;
100
+ for (let attempt = 0; ; attempt++) {
101
+ let res;
102
+ try {
103
+ res = await doFetch(url, { method: "GET", headers });
104
+ } catch (err) {
105
+ if (attempt < retries) {
106
+ await sleep(backoff(attempt));
107
+ continue;
108
+ }
109
+ throw new BreaseError("network", `Request to ${url} failed: ${err.message}`, 0);
110
+ }
111
+ if (res.ok) return await res.json();
112
+ if (res.status === 404 && nullOn404) return null;
113
+ if ((res.status === 429 || res.status >= 500) && attempt < retries) {
114
+ const after = Number(res.headers.get("retry-after"));
115
+ await sleep(after > 0 ? Math.min(after * 1e3, RETRY_AFTER_CAP_MS) : backoff(attempt));
116
+ continue;
117
+ }
118
+ throw await BreaseError.fromResponse(res);
119
+ }
120
+ }
121
+ function backoff(attempt) {
122
+ return baseMs * 2 ** attempt + Math.random() * baseMs;
123
+ }
124
+ const client = {
125
+ getSite() {
126
+ sitePromise ?? (sitePromise = request("/v1/site").catch((err) => {
127
+ sitePromise = void 0;
128
+ throw err;
129
+ }));
130
+ return sitePromise;
131
+ },
132
+ getPage(slug, { locale }) {
133
+ return request("/v1/page", { slug, locale }, true);
134
+ },
135
+ getPages(o = {}) {
136
+ return request("/v1/pages", { locale: o.locale });
137
+ },
138
+ getNavigation(key, { locale }) {
139
+ return request(`/v1/navigations/${encodeURIComponent(key)}`, { locale }, true);
140
+ },
141
+ getRedirects() {
142
+ return request("/v1/redirects");
143
+ },
144
+ getRelease() {
145
+ return request("/v1/release");
146
+ },
147
+ async resolve(pathname) {
148
+ const site = await client.getSite();
149
+ const result = resolvePath(site, pathname);
150
+ return site.locales.includes(result.locale) ? result : null;
151
+ },
152
+ async sitemap(baseUrl) {
153
+ const base = baseUrl.replace(/\/+$/, "");
154
+ const refs = (await client.getPages()).filter((r) => !r.hidden);
155
+ const byPage = /* @__PURE__ */ new Map();
156
+ for (const ref of refs) {
157
+ const alternates = byPage.get(ref.pageId) ?? {};
158
+ alternates[ref.locale] = `${base}${ref.url}`;
159
+ byPage.set(ref.pageId, alternates);
160
+ }
161
+ return refs.map((ref) => ({ url: `${base}${ref.url}`, alternates: byPage.get(ref.pageId) ?? {} }));
162
+ }
163
+ };
164
+ return client;
165
+ }
166
+
167
+ exports.BreaseError = BreaseError;
168
+ exports.buildPath = buildPath;
169
+ exports.createBrease = createBrease;
170
+ exports.normalizeSlug = normalizeSlug;
171
+ exports.resolvePath = resolvePath;
@@ -0,0 +1,50 @@
1
+ import { U as UrlSettings, S as Site, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-V0ELFvwy.cjs';
2
+ export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-V0ELFvwy.cjs';
3
+
4
+ declare class BreaseError extends Error {
5
+ code: string;
6
+ status: number;
7
+ requestId?: string | undefined;
8
+ details?: unknown | undefined;
9
+ name: string;
10
+ constructor(code: string, message: string, status: number, requestId?: string | undefined, details?: unknown | undefined);
11
+ static fromResponse(res: Response): Promise<BreaseError>;
12
+ }
13
+
14
+ declare function normalizeSlug(input: string): string;
15
+ declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
16
+ declare function resolvePath(settings: UrlSettings, pathname: string): {
17
+ slug: string;
18
+ locale: string;
19
+ };
20
+
21
+ type BreaseOptions = {
22
+ token?: string;
23
+ apiUrl?: string;
24
+ commit?: string | false;
25
+ fetch?: typeof fetch;
26
+ retries?: number;
27
+ retryBaseMs?: number;
28
+ };
29
+ interface Brease {
30
+ getSite(): Promise<Site>;
31
+ getPage<T = Record<string, unknown>>(slug: string, opts: {
32
+ locale: string;
33
+ }): Promise<Page<T> | null>;
34
+ getPages(opts?: {
35
+ locale?: string;
36
+ }): Promise<PageRef[]>;
37
+ getNavigation(key: string, opts: {
38
+ locale: string;
39
+ }): Promise<Navigation | null>;
40
+ getRedirects(): Promise<Redirect[]>;
41
+ getRelease(): Promise<Release>;
42
+ resolve(pathname: string): Promise<{
43
+ slug: string;
44
+ locale: string;
45
+ } | null>;
46
+ sitemap(baseUrl: string): Promise<SitemapEntry[]>;
47
+ }
48
+ declare function createBrease(opts?: BreaseOptions): Brease;
49
+
50
+ export { type Brease, BreaseError, type BreaseOptions, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, normalizeSlug, resolvePath };
@@ -0,0 +1,50 @@
1
+ import { U as UrlSettings, S as Site, P as Page, a as PageRef, N as Navigation, b as Redirect, c as Release, d as SitemapEntry } from './types-V0ELFvwy.js';
2
+ export { L as LocaleStrategy, e as NavigationItem, O as OpenGraph, f as PageSeo, R as ResolvedSeo, g as Robots, h as SiteSeo, T as Twitter } from './types-V0ELFvwy.js';
3
+
4
+ declare class BreaseError extends Error {
5
+ code: string;
6
+ status: number;
7
+ requestId?: string | undefined;
8
+ details?: unknown | undefined;
9
+ name: string;
10
+ constructor(code: string, message: string, status: number, requestId?: string | undefined, details?: unknown | undefined);
11
+ static fromResponse(res: Response): Promise<BreaseError>;
12
+ }
13
+
14
+ declare function normalizeSlug(input: string): string;
15
+ declare function buildPath(settings: UrlSettings, slug: string, locale: string): string;
16
+ declare function resolvePath(settings: UrlSettings, pathname: string): {
17
+ slug: string;
18
+ locale: string;
19
+ };
20
+
21
+ type BreaseOptions = {
22
+ token?: string;
23
+ apiUrl?: string;
24
+ commit?: string | false;
25
+ fetch?: typeof fetch;
26
+ retries?: number;
27
+ retryBaseMs?: number;
28
+ };
29
+ interface Brease {
30
+ getSite(): Promise<Site>;
31
+ getPage<T = Record<string, unknown>>(slug: string, opts: {
32
+ locale: string;
33
+ }): Promise<Page<T> | null>;
34
+ getPages(opts?: {
35
+ locale?: string;
36
+ }): Promise<PageRef[]>;
37
+ getNavigation(key: string, opts: {
38
+ locale: string;
39
+ }): Promise<Navigation | null>;
40
+ getRedirects(): Promise<Redirect[]>;
41
+ getRelease(): Promise<Release>;
42
+ resolve(pathname: string): Promise<{
43
+ slug: string;
44
+ locale: string;
45
+ } | null>;
46
+ sitemap(baseUrl: string): Promise<SitemapEntry[]>;
47
+ }
48
+ declare function createBrease(opts?: BreaseOptions): Brease;
49
+
50
+ export { type Brease, BreaseError, type BreaseOptions, Navigation, Page, PageRef, Redirect, Release, Site, SitemapEntry, UrlSettings, buildPath, createBrease, normalizeSlug, resolvePath };
package/dist/index.js ADDED
@@ -0,0 +1,157 @@
1
+ import { env } from './chunk-L7GXI4GK.js';
2
+ import { __publicField } from './chunk-PKBMQBKP.js';
3
+
4
+ // src/errors.ts
5
+ var BreaseError = class _BreaseError extends Error {
6
+ constructor(code, message, status, requestId, details) {
7
+ super(message);
8
+ __publicField(this, "code", code);
9
+ __publicField(this, "status", status);
10
+ __publicField(this, "requestId", requestId);
11
+ __publicField(this, "details", details);
12
+ __publicField(this, "name", "BreaseError");
13
+ }
14
+ static async fromResponse(res) {
15
+ const requestId = res.headers.get("x-request-id") ?? res.headers.get("x-vercel-id") ?? void 0;
16
+ let code = res.status === 429 ? "rate_limited" : res.status >= 500 ? "upstream" : "http_error";
17
+ let message = `Brease API responded ${res.status}`;
18
+ let details;
19
+ try {
20
+ const body = await res.json();
21
+ if (body?.error) {
22
+ code = body.error.code ?? code;
23
+ message = body.error.message ?? message;
24
+ details = body.error.details;
25
+ }
26
+ } catch {
27
+ }
28
+ return new _BreaseError(code, message, res.status, requestId ?? void 0, details);
29
+ }
30
+ };
31
+
32
+ // src/urls.ts
33
+ function normalizeSlug(input) {
34
+ return input.trim().replace(/^\/+|\/+$/g, "").replace(/\/{2,}/g, "/");
35
+ }
36
+ function buildPath(settings, slug, locale) {
37
+ const clean = normalizeSlug(slug);
38
+ if (settings.localeStrategy === "CUSTOM" && settings.urlTemplate) {
39
+ const path = settings.urlTemplate.replace("{locale}", locale).replace("{slug}", clean);
40
+ return `/${normalizeSlug(path)}`;
41
+ }
42
+ const prefixed = settings.localeStrategy === "PREFIX_ALL" || locale !== settings.defaultLocale;
43
+ const parts = [prefixed ? locale : "", clean].filter(Boolean);
44
+ return `/${parts.join("/")}`;
45
+ }
46
+ function resolvePath(settings, pathname) {
47
+ const clean = normalizeSlug(decodeURIComponent(pathname.split(/[?#]/)[0] ?? ""));
48
+ if (settings.localeStrategy === "CUSTOM" && settings.urlTemplate) {
49
+ const pattern = normalizeSlug(settings.urlTemplate).split(/(\{locale\}|\{slug\})/).map((part) => {
50
+ if (part === "{locale}") return "(?<locale>[^/]+)";
51
+ if (part === "{slug}") return "(?<slug>.*)";
52
+ return part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
+ }).join("");
54
+ const match = new RegExp(`^${pattern}$`).exec(clean);
55
+ if (match?.groups) {
56
+ return {
57
+ slug: normalizeSlug(match.groups.slug ?? ""),
58
+ locale: match.groups.locale ?? settings.defaultLocale
59
+ };
60
+ }
61
+ return { slug: clean, locale: settings.defaultLocale };
62
+ }
63
+ const [first, ...rest] = clean.split("/");
64
+ if (first && settings.locales.includes(first)) {
65
+ return { slug: rest.join("/"), locale: first };
66
+ }
67
+ return { slug: clean, locale: settings.defaultLocale };
68
+ }
69
+
70
+ // src/index.ts
71
+ var RETRY_AFTER_CAP_MS = 1e4;
72
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
73
+ function createBrease(opts = {}) {
74
+ const apiUrl = (opts.apiUrl ?? env("BREASE_API_URL") ?? "https://api.brease.io").replace(/\/+$/, "");
75
+ const commit = opts.commit === false ? void 0 : opts.commit ?? env("VERCEL_GIT_COMMIT_SHA");
76
+ const retries = opts.retries ?? 2;
77
+ const baseMs = opts.retryBaseMs ?? 300;
78
+ const doFetch = opts.fetch ?? ((input, init) => fetch(input, init));
79
+ let sitePromise;
80
+ async function request(path, query = {}, nullOn404 = false) {
81
+ const token = opts.token ?? env("BREASE_TOKEN");
82
+ if (!token)
83
+ throw new BreaseError("unauthorized", "No Brease token: pass { token } or set BREASE_TOKEN", 401);
84
+ const params = new URLSearchParams();
85
+ for (const [k, v] of Object.entries(query)) if (v !== void 0) params.set(k, v);
86
+ const qs = params.toString();
87
+ const url = `${apiUrl}${path}${qs ? `?${qs}` : ""}`;
88
+ const headers = { authorization: `Bearer ${token}`, accept: "application/json" };
89
+ if (commit) headers["x-brease-commit"] = commit;
90
+ for (let attempt = 0; ; attempt++) {
91
+ let res;
92
+ try {
93
+ res = await doFetch(url, { method: "GET", headers });
94
+ } catch (err) {
95
+ if (attempt < retries) {
96
+ await sleep(backoff(attempt));
97
+ continue;
98
+ }
99
+ throw new BreaseError("network", `Request to ${url} failed: ${err.message}`, 0);
100
+ }
101
+ if (res.ok) return await res.json();
102
+ if (res.status === 404 && nullOn404) return null;
103
+ if ((res.status === 429 || res.status >= 500) && attempt < retries) {
104
+ const after = Number(res.headers.get("retry-after"));
105
+ await sleep(after > 0 ? Math.min(after * 1e3, RETRY_AFTER_CAP_MS) : backoff(attempt));
106
+ continue;
107
+ }
108
+ throw await BreaseError.fromResponse(res);
109
+ }
110
+ }
111
+ function backoff(attempt) {
112
+ return baseMs * 2 ** attempt + Math.random() * baseMs;
113
+ }
114
+ const client = {
115
+ getSite() {
116
+ sitePromise ?? (sitePromise = request("/v1/site").catch((err) => {
117
+ sitePromise = void 0;
118
+ throw err;
119
+ }));
120
+ return sitePromise;
121
+ },
122
+ getPage(slug, { locale }) {
123
+ return request("/v1/page", { slug, locale }, true);
124
+ },
125
+ getPages(o = {}) {
126
+ return request("/v1/pages", { locale: o.locale });
127
+ },
128
+ getNavigation(key, { locale }) {
129
+ return request(`/v1/navigations/${encodeURIComponent(key)}`, { locale }, true);
130
+ },
131
+ getRedirects() {
132
+ return request("/v1/redirects");
133
+ },
134
+ getRelease() {
135
+ return request("/v1/release");
136
+ },
137
+ async resolve(pathname) {
138
+ const site = await client.getSite();
139
+ const result = resolvePath(site, pathname);
140
+ return site.locales.includes(result.locale) ? result : null;
141
+ },
142
+ async sitemap(baseUrl) {
143
+ const base = baseUrl.replace(/\/+$/, "");
144
+ const refs = (await client.getPages()).filter((r) => !r.hidden);
145
+ const byPage = /* @__PURE__ */ new Map();
146
+ for (const ref of refs) {
147
+ const alternates = byPage.get(ref.pageId) ?? {};
148
+ alternates[ref.locale] = `${base}${ref.url}`;
149
+ byPage.set(ref.pageId, alternates);
150
+ }
151
+ return refs.map((ref) => ({ url: `${base}${ref.url}`, alternates: byPage.get(ref.pageId) ?? {} }));
152
+ }
153
+ };
154
+ return client;
155
+ }
156
+
157
+ export { BreaseError, buildPath, createBrease, normalizeSlug, resolvePath };
package/dist/next.cjs ADDED
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ // src/env.ts
4
+ function env(name) {
5
+ const proc = globalThis.process;
6
+ const value = proc?.env?.[name];
7
+ return value === "" ? void 0 : value;
8
+ }
9
+
10
+ // src/next.ts
11
+ var compact = (obj) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
12
+ function toMetadata(seo, opts = {}) {
13
+ const languages = { ...seo.alternates };
14
+ if (opts.xDefault) languages["x-default"] = opts.xDefault;
15
+ return compact({
16
+ title: { absolute: seo.title },
17
+ description: seo.description,
18
+ alternates: compact({ canonical: seo.canonical, languages }),
19
+ robots: { index: seo.robots.index, follow: seo.robots.follow },
20
+ openGraph: compact({
21
+ type: seo.openGraph.type,
22
+ title: seo.openGraph.title,
23
+ description: seo.openGraph.description,
24
+ url: seo.openGraph.url,
25
+ siteName: seo.openGraph.siteName,
26
+ images: seo.openGraph.image ? [{ url: seo.openGraph.image }] : void 0
27
+ }),
28
+ twitter: compact({
29
+ card: seo.twitter.card,
30
+ site: seo.twitter.site,
31
+ creator: seo.twitter.creator,
32
+ title: seo.twitter.title,
33
+ description: seo.twitter.description,
34
+ images: seo.twitter.image ? [seo.twitter.image] : void 0
35
+ }),
36
+ icons: seo.favicon ? { icon: seo.favicon } : void 0
37
+ });
38
+ }
39
+ function breaseFetch(tags = [], revalidate) {
40
+ return (input, init) => fetch(input, {
41
+ ...init,
42
+ next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
43
+ });
44
+ }
45
+ var MAX_SKEW_MS = 5 * 6e4;
46
+ function revalidateHandler(secret) {
47
+ return async (req) => {
48
+ const key = secret ?? env("BREASE_REVALIDATE_SECRET");
49
+ if (!key)
50
+ return json(500, { error: { code: "internal", message: "BREASE_REVALIDATE_SECRET is not set" } });
51
+ const raw = await req.text();
52
+ const ok = await verifySignature(
53
+ raw,
54
+ req.headers.get("x-brease-timestamp"),
55
+ req.headers.get("x-brease-signature"),
56
+ key
57
+ );
58
+ if (!ok) return json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
59
+ let body;
60
+ try {
61
+ body = JSON.parse(raw || "{}");
62
+ } catch {
63
+ return json(400, { error: { code: "validation", message: "Body must be JSON" } });
64
+ }
65
+ const paths = new Set(body.paths ?? []);
66
+ for (const url of body.urls ?? []) {
67
+ try {
68
+ paths.add(new URL(url, "http://localhost").pathname);
69
+ } catch {
70
+ }
71
+ }
72
+ const tags = /* @__PURE__ */ new Set(["brease", ...body.tags ?? []]);
73
+ const cache = await import('next/cache');
74
+ for (const path of paths) cache.revalidatePath(path);
75
+ for (const tag of tags) cache.revalidateTag(tag, "max");
76
+ return json(200, { revalidated: true, paths: [...paths], tags: [...tags] });
77
+ };
78
+ }
79
+ async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
80
+ if (!timestamp || !signature) return false;
81
+ if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
82
+ const expected = await hmacHex(secret, `${timestamp}.${body}`);
83
+ if (expected.length !== signature.length) return false;
84
+ let diff = 0;
85
+ for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
86
+ return diff === 0;
87
+ }
88
+ async function hmacHex(secret, message) {
89
+ const enc = new TextEncoder();
90
+ const key = await crypto.subtle.importKey(
91
+ "raw",
92
+ enc.encode(secret),
93
+ { name: "HMAC", hash: "SHA-256" },
94
+ false,
95
+ ["sign"]
96
+ );
97
+ const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
98
+ return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
99
+ }
100
+ function json(status, data) {
101
+ return new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
102
+ }
103
+
104
+ exports.breaseFetch = breaseFetch;
105
+ exports.hmacHex = hmacHex;
106
+ exports.revalidateHandler = revalidateHandler;
107
+ exports.toMetadata = toMetadata;
108
+ exports.verifySignature = verifySignature;
@@ -0,0 +1,47 @@
1
+ import { R as ResolvedSeo } from './types-V0ELFvwy.cjs';
2
+
3
+ type BreaseMetadata = {
4
+ title: {
5
+ absolute: string;
6
+ };
7
+ description?: string;
8
+ alternates: {
9
+ canonical?: string;
10
+ languages: Record<string, string>;
11
+ };
12
+ robots: {
13
+ index: boolean;
14
+ follow: boolean;
15
+ };
16
+ openGraph: {
17
+ type?: string;
18
+ title?: string;
19
+ description?: string;
20
+ url?: string;
21
+ siteName?: string;
22
+ images?: {
23
+ url: string;
24
+ }[];
25
+ };
26
+ twitter: {
27
+ card?: 'summary' | 'summary_large_image';
28
+ site?: string;
29
+ creator?: string;
30
+ title?: string;
31
+ description?: string;
32
+ images?: string[];
33
+ };
34
+ icons?: {
35
+ icon: string;
36
+ };
37
+ other?: Record<string, string>;
38
+ };
39
+ declare function toMetadata(seo: ResolvedSeo, opts?: {
40
+ xDefault?: string;
41
+ }): BreaseMetadata;
42
+ declare function breaseFetch(tags?: string[], revalidate?: number | false): typeof fetch;
43
+ declare function revalidateHandler(secret?: string): (req: Request) => Promise<Response>;
44
+ declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
45
+ declare function hmacHex(secret: string, message: string): Promise<string>;
46
+
47
+ export { type BreaseMetadata, breaseFetch, hmacHex, revalidateHandler, toMetadata, verifySignature };
package/dist/next.d.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { R as ResolvedSeo } from './types-V0ELFvwy.js';
2
+
3
+ type BreaseMetadata = {
4
+ title: {
5
+ absolute: string;
6
+ };
7
+ description?: string;
8
+ alternates: {
9
+ canonical?: string;
10
+ languages: Record<string, string>;
11
+ };
12
+ robots: {
13
+ index: boolean;
14
+ follow: boolean;
15
+ };
16
+ openGraph: {
17
+ type?: string;
18
+ title?: string;
19
+ description?: string;
20
+ url?: string;
21
+ siteName?: string;
22
+ images?: {
23
+ url: string;
24
+ }[];
25
+ };
26
+ twitter: {
27
+ card?: 'summary' | 'summary_large_image';
28
+ site?: string;
29
+ creator?: string;
30
+ title?: string;
31
+ description?: string;
32
+ images?: string[];
33
+ };
34
+ icons?: {
35
+ icon: string;
36
+ };
37
+ other?: Record<string, string>;
38
+ };
39
+ declare function toMetadata(seo: ResolvedSeo, opts?: {
40
+ xDefault?: string;
41
+ }): BreaseMetadata;
42
+ declare function breaseFetch(tags?: string[], revalidate?: number | false): typeof fetch;
43
+ declare function revalidateHandler(secret?: string): (req: Request) => Promise<Response>;
44
+ declare function verifySignature(body: string, timestamp: string | null, signature: string | null, secret: string, now?: number): Promise<boolean>;
45
+ declare function hmacHex(secret: string, message: string): Promise<string>;
46
+
47
+ export { type BreaseMetadata, breaseFetch, hmacHex, revalidateHandler, toMetadata, verifySignature };