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/next.js ADDED
@@ -0,0 +1,98 @@
1
+ import { env } from './chunk-L7GXI4GK.js';
2
+ import './chunk-PKBMQBKP.js';
3
+
4
+ // src/next.ts
5
+ var compact = (obj) => Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== void 0));
6
+ function toMetadata(seo, opts = {}) {
7
+ const languages = { ...seo.alternates };
8
+ if (opts.xDefault) languages["x-default"] = opts.xDefault;
9
+ return compact({
10
+ title: { absolute: seo.title },
11
+ description: seo.description,
12
+ alternates: compact({ canonical: seo.canonical, languages }),
13
+ robots: { index: seo.robots.index, follow: seo.robots.follow },
14
+ openGraph: compact({
15
+ type: seo.openGraph.type,
16
+ title: seo.openGraph.title,
17
+ description: seo.openGraph.description,
18
+ url: seo.openGraph.url,
19
+ siteName: seo.openGraph.siteName,
20
+ images: seo.openGraph.image ? [{ url: seo.openGraph.image }] : void 0
21
+ }),
22
+ twitter: compact({
23
+ card: seo.twitter.card,
24
+ site: seo.twitter.site,
25
+ creator: seo.twitter.creator,
26
+ title: seo.twitter.title,
27
+ description: seo.twitter.description,
28
+ images: seo.twitter.image ? [seo.twitter.image] : void 0
29
+ }),
30
+ icons: seo.favicon ? { icon: seo.favicon } : void 0
31
+ });
32
+ }
33
+ function breaseFetch(tags = [], revalidate) {
34
+ return (input, init) => fetch(input, {
35
+ ...init,
36
+ next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
37
+ });
38
+ }
39
+ var MAX_SKEW_MS = 5 * 6e4;
40
+ function revalidateHandler(secret) {
41
+ return async (req) => {
42
+ const key = secret ?? env("BREASE_REVALIDATE_SECRET");
43
+ if (!key)
44
+ return json(500, { error: { code: "internal", message: "BREASE_REVALIDATE_SECRET is not set" } });
45
+ const raw = await req.text();
46
+ const ok = await verifySignature(
47
+ raw,
48
+ req.headers.get("x-brease-timestamp"),
49
+ req.headers.get("x-brease-signature"),
50
+ key
51
+ );
52
+ if (!ok) return json(401, { error: { code: "unauthorized", message: "Invalid or expired signature" } });
53
+ let body;
54
+ try {
55
+ body = JSON.parse(raw || "{}");
56
+ } catch {
57
+ return json(400, { error: { code: "validation", message: "Body must be JSON" } });
58
+ }
59
+ const paths = new Set(body.paths ?? []);
60
+ for (const url of body.urls ?? []) {
61
+ try {
62
+ paths.add(new URL(url, "http://localhost").pathname);
63
+ } catch {
64
+ }
65
+ }
66
+ const tags = /* @__PURE__ */ new Set(["brease", ...body.tags ?? []]);
67
+ const cache = await import('next/cache');
68
+ for (const path of paths) cache.revalidatePath(path);
69
+ for (const tag of tags) cache.revalidateTag(tag, "max");
70
+ return json(200, { revalidated: true, paths: [...paths], tags: [...tags] });
71
+ };
72
+ }
73
+ async function verifySignature(body, timestamp, signature, secret, now = Date.now()) {
74
+ if (!timestamp || !signature) return false;
75
+ if (!Number.isFinite(Number(timestamp)) || Math.abs(now - Number(timestamp)) > MAX_SKEW_MS) return false;
76
+ const expected = await hmacHex(secret, `${timestamp}.${body}`);
77
+ if (expected.length !== signature.length) return false;
78
+ let diff = 0;
79
+ for (let i = 0; i < expected.length; i++) diff |= expected.charCodeAt(i) ^ signature.charCodeAt(i);
80
+ return diff === 0;
81
+ }
82
+ async function hmacHex(secret, message) {
83
+ const enc = new TextEncoder();
84
+ const key = await crypto.subtle.importKey(
85
+ "raw",
86
+ enc.encode(secret),
87
+ { name: "HMAC", hash: "SHA-256" },
88
+ false,
89
+ ["sign"]
90
+ );
91
+ const sig = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(message)));
92
+ return Array.from(sig, (b) => b.toString(16).padStart(2, "0")).join("");
93
+ }
94
+ function json(status, data) {
95
+ return new Response(JSON.stringify(data), { status, headers: { "content-type": "application/json" } });
96
+ }
97
+
98
+ export { breaseFetch, hmacHex, revalidateHandler, toMetadata, verifySignature };
@@ -0,0 +1,113 @@
1
+ type LocaleStrategy = 'PREFIX_EXCEPT_DEFAULT' | 'PREFIX_ALL' | 'CUSTOM';
2
+ type UrlSettings = {
3
+ locales: string[];
4
+ defaultLocale: string;
5
+ localeStrategy: LocaleStrategy;
6
+ urlTemplate?: string | null;
7
+ };
8
+ type Robots = {
9
+ index?: boolean;
10
+ follow?: boolean;
11
+ };
12
+ type OpenGraph = {
13
+ type?: string;
14
+ title?: string;
15
+ description?: string;
16
+ image?: string;
17
+ };
18
+ type Twitter = {
19
+ card?: 'summary' | 'summary_large_image';
20
+ site?: string;
21
+ creator?: string;
22
+ title?: string;
23
+ description?: string;
24
+ image?: string;
25
+ };
26
+ type PageSeo = {
27
+ title?: string;
28
+ description?: string;
29
+ canonical?: string;
30
+ robots?: Robots;
31
+ openGraph?: OpenGraph;
32
+ twitter?: Twitter;
33
+ structuredData?: Record<string, unknown>[];
34
+ customCode?: string;
35
+ };
36
+ type SiteSeo = PageSeo & {
37
+ titleTemplate?: string;
38
+ siteName?: string;
39
+ defaultImage?: string;
40
+ favicon?: string;
41
+ customHead?: string;
42
+ };
43
+ type ResolvedSeo = {
44
+ title: string;
45
+ description?: string;
46
+ canonical?: string;
47
+ robots: {
48
+ index: boolean;
49
+ follow: boolean;
50
+ };
51
+ openGraph: OpenGraph & {
52
+ url?: string;
53
+ siteName?: string;
54
+ };
55
+ twitter: Twitter;
56
+ structuredData: Record<string, unknown>[];
57
+ alternates: Record<string, string>;
58
+ customHead?: string;
59
+ customCode?: string;
60
+ favicon?: string;
61
+ };
62
+ type Site = {
63
+ name: string;
64
+ locales: string[];
65
+ defaultLocale: string;
66
+ localeStrategy: LocaleStrategy;
67
+ urlTemplate: string | null;
68
+ seo: Record<string, SiteSeo>;
69
+ };
70
+ type Page<T = Record<string, unknown>> = {
71
+ pageId: string;
72
+ name: string;
73
+ locale: string;
74
+ slug: string;
75
+ url: string;
76
+ hidden: boolean;
77
+ content: T;
78
+ seo: PageSeo;
79
+ resolvedSeo: ResolvedSeo;
80
+ alternates: Record<string, string>;
81
+ };
82
+ type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'>;
83
+ type NavigationItem = {
84
+ id: string;
85
+ label: string;
86
+ url: string;
87
+ pageId?: string;
88
+ target?: '_self' | '_blank';
89
+ children: NavigationItem[];
90
+ };
91
+ type Navigation = {
92
+ key: string;
93
+ locale: string;
94
+ items: NavigationItem[];
95
+ };
96
+ type Redirect = {
97
+ source: string;
98
+ destination: string;
99
+ status: 301 | 302 | 307 | 308;
100
+ };
101
+ type Release = {
102
+ id: string;
103
+ number: number;
104
+ commitSha: string;
105
+ liveAt: string | null;
106
+ };
107
+ type SitemapEntry = {
108
+ url: string;
109
+ lastModified?: string;
110
+ alternates: Record<string, string>;
111
+ };
112
+
113
+ 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 };
@@ -0,0 +1,113 @@
1
+ type LocaleStrategy = 'PREFIX_EXCEPT_DEFAULT' | 'PREFIX_ALL' | 'CUSTOM';
2
+ type UrlSettings = {
3
+ locales: string[];
4
+ defaultLocale: string;
5
+ localeStrategy: LocaleStrategy;
6
+ urlTemplate?: string | null;
7
+ };
8
+ type Robots = {
9
+ index?: boolean;
10
+ follow?: boolean;
11
+ };
12
+ type OpenGraph = {
13
+ type?: string;
14
+ title?: string;
15
+ description?: string;
16
+ image?: string;
17
+ };
18
+ type Twitter = {
19
+ card?: 'summary' | 'summary_large_image';
20
+ site?: string;
21
+ creator?: string;
22
+ title?: string;
23
+ description?: string;
24
+ image?: string;
25
+ };
26
+ type PageSeo = {
27
+ title?: string;
28
+ description?: string;
29
+ canonical?: string;
30
+ robots?: Robots;
31
+ openGraph?: OpenGraph;
32
+ twitter?: Twitter;
33
+ structuredData?: Record<string, unknown>[];
34
+ customCode?: string;
35
+ };
36
+ type SiteSeo = PageSeo & {
37
+ titleTemplate?: string;
38
+ siteName?: string;
39
+ defaultImage?: string;
40
+ favicon?: string;
41
+ customHead?: string;
42
+ };
43
+ type ResolvedSeo = {
44
+ title: string;
45
+ description?: string;
46
+ canonical?: string;
47
+ robots: {
48
+ index: boolean;
49
+ follow: boolean;
50
+ };
51
+ openGraph: OpenGraph & {
52
+ url?: string;
53
+ siteName?: string;
54
+ };
55
+ twitter: Twitter;
56
+ structuredData: Record<string, unknown>[];
57
+ alternates: Record<string, string>;
58
+ customHead?: string;
59
+ customCode?: string;
60
+ favicon?: string;
61
+ };
62
+ type Site = {
63
+ name: string;
64
+ locales: string[];
65
+ defaultLocale: string;
66
+ localeStrategy: LocaleStrategy;
67
+ urlTemplate: string | null;
68
+ seo: Record<string, SiteSeo>;
69
+ };
70
+ type Page<T = Record<string, unknown>> = {
71
+ pageId: string;
72
+ name: string;
73
+ locale: string;
74
+ slug: string;
75
+ url: string;
76
+ hidden: boolean;
77
+ content: T;
78
+ seo: PageSeo;
79
+ resolvedSeo: ResolvedSeo;
80
+ alternates: Record<string, string>;
81
+ };
82
+ type PageRef = Pick<Page, 'pageId' | 'locale' | 'slug' | 'url' | 'hidden'>;
83
+ type NavigationItem = {
84
+ id: string;
85
+ label: string;
86
+ url: string;
87
+ pageId?: string;
88
+ target?: '_self' | '_blank';
89
+ children: NavigationItem[];
90
+ };
91
+ type Navigation = {
92
+ key: string;
93
+ locale: string;
94
+ items: NavigationItem[];
95
+ };
96
+ type Redirect = {
97
+ source: string;
98
+ destination: string;
99
+ status: 301 | 302 | 307 | 308;
100
+ };
101
+ type Release = {
102
+ id: string;
103
+ number: number;
104
+ commitSha: string;
105
+ liveAt: string | null;
106
+ };
107
+ type SitemapEntry = {
108
+ url: string;
109
+ lastModified?: string;
110
+ alternates: Record<string, string>;
111
+ };
112
+
113
+ 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 };
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "brease-client",
3
+ "version": "0.1.0",
4
+ "description": "Brease delivery API client for Next.js, Astro and any fetch-capable runtime",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/designatives/brease-client.git"
9
+ },
10
+ "homepage": "https://github.com/designatives/brease-client#readme",
11
+ "bugs": "https://github.com/designatives/brease-client/issues",
12
+ "keywords": [
13
+ "brease",
14
+ "cms",
15
+ "headless",
16
+ "nextjs",
17
+ "astro"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "main": "./dist/index.cjs",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ },
30
+ "./next": {
31
+ "types": "./dist/next.d.ts",
32
+ "import": "./dist/next.js",
33
+ "require": "./dist/next.cjs"
34
+ },
35
+ "./astro": {
36
+ "types": "./dist/astro.d.ts",
37
+ "import": "./dist/astro.js",
38
+ "require": "./dist/astro.cjs"
39
+ },
40
+ "./html": {
41
+ "types": "./dist/html.d.ts",
42
+ "import": "./dist/html.js",
43
+ "require": "./dist/html.cjs"
44
+ },
45
+ "./image": {
46
+ "types": "./dist/image.d.ts",
47
+ "import": "./dist/image.js",
48
+ "require": "./dist/image.cjs"
49
+ }
50
+ },
51
+ "files": [
52
+ "dist",
53
+ "README.md"
54
+ ],
55
+ "engines": {
56
+ "node": ">=18"
57
+ },
58
+ "peerDependencies": {
59
+ "next": ">=14"
60
+ },
61
+ "peerDependenciesMeta": {
62
+ "next": {
63
+ "optional": true
64
+ }
65
+ },
66
+ "devDependencies": {
67
+ "@biomejs/biome": "^2.5.14",
68
+ "@types/node": "^22.20.4",
69
+ "tsup": "^8.5.1",
70
+ "typescript": "^5.9.3",
71
+ "vitest": "^5.0.1"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public",
75
+ "provenance": true
76
+ },
77
+ "scripts": {
78
+ "build": "tsup",
79
+ "dev": "tsup --watch",
80
+ "typecheck": "tsc --noEmit",
81
+ "test": "vitest run",
82
+ "lint": "biome check ."
83
+ }
84
+ }