brease-client 0.1.0 → 0.2.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 +3 -3
- package/dist/image.cjs +5 -27
- package/dist/image.d.cts +3 -4
- package/dist/image.d.ts +3 -4
- package/dist/image.js +6 -27
- package/dist/index.cjs +6 -6
- package/dist/index.js +6 -6
- package/dist/next.cjs +1 -1
- package/dist/next.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -151,14 +151,14 @@ const props = imageProps(page.content.hero.image, { sizes: '(min-width: 768px) 5
|
|
|
151
151
|
// <img src={props.src} srcSet={props.srcSet} sizes={props.sizes} />
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
-
|
|
154
|
+
Brease files are served as-is from an S3 bucket, which doesn't resize images: the helpers return the URL unchanged with an empty `srcset`. For responsive images, let your framework resize them, e.g. `next/image` with the bucket's host in `images.remotePatterns`.
|
|
155
155
|
|
|
156
156
|
## Without JavaScript
|
|
157
157
|
|
|
158
158
|
Every call is a plain REST request:
|
|
159
159
|
|
|
160
160
|
```sh
|
|
161
|
-
curl -H "Authorization: Bearer $BREASE_TOKEN" "https://api.brease.io/
|
|
161
|
+
curl -H "Authorization: Bearer $BREASE_TOKEN" "https://api.brease.io/content-api/page?slug=about&locale=en"
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
-
Routes: `GET /
|
|
164
|
+
Routes: `GET /content-api/site`, `/content-api/pages?locale=`, `/content-api/page?slug=&locale=`, `/content-api/navigations/:key?locale=`, `/content-api/redirects`, `/content-api/release`.
|
package/dist/image.cjs
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/image.ts
|
|
4
|
-
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
-
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
4
|
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
-
function
|
|
8
|
-
return src
|
|
5
|
+
function imageUrl(src, _opts = {}) {
|
|
6
|
+
return src;
|
|
9
7
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let url;
|
|
13
|
-
try {
|
|
14
|
-
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
-
} catch {
|
|
16
|
-
return src;
|
|
17
|
-
}
|
|
18
|
-
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
-
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
-
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
-
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
-
return url.toString();
|
|
23
|
-
}
|
|
24
|
-
function srcset(src, opts = {}) {
|
|
25
|
-
if (!isSupabaseImage(src)) return "";
|
|
26
|
-
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
8
|
+
function srcset(_src, _opts = {}) {
|
|
9
|
+
return "";
|
|
27
10
|
}
|
|
28
11
|
function imageProps(src, opts = {}) {
|
|
29
|
-
return {
|
|
30
|
-
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
-
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
-
sizes: opts.sizes ?? "100vw"
|
|
33
|
-
};
|
|
12
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw" };
|
|
34
13
|
}
|
|
35
14
|
|
|
36
15
|
exports.DEFAULT_WIDTHS = DEFAULT_WIDTHS;
|
|
37
16
|
exports.imageProps = imageProps;
|
|
38
17
|
exports.imageUrl = imageUrl;
|
|
39
|
-
exports.isSupabaseImage = isSupabaseImage;
|
|
40
18
|
exports.srcset = srcset;
|
package/dist/image.d.cts
CHANGED
|
@@ -6,9 +6,8 @@ type ImageOptions = {
|
|
|
6
6
|
resize?: Resize;
|
|
7
7
|
};
|
|
8
8
|
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
11
|
-
declare function srcset(src: string, opts?: {
|
|
9
|
+
declare function imageUrl(src: string, _opts?: ImageOptions): string;
|
|
10
|
+
declare function srcset(_src: string, _opts?: {
|
|
12
11
|
widths?: number[];
|
|
13
12
|
quality?: number;
|
|
14
13
|
resize?: Resize;
|
|
@@ -25,4 +24,4 @@ declare function imageProps(src: string, opts?: {
|
|
|
25
24
|
sizes: string;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl,
|
|
27
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.d.ts
CHANGED
|
@@ -6,9 +6,8 @@ type ImageOptions = {
|
|
|
6
6
|
resize?: Resize;
|
|
7
7
|
};
|
|
8
8
|
declare const DEFAULT_WIDTHS: number[];
|
|
9
|
-
declare function
|
|
10
|
-
declare function
|
|
11
|
-
declare function srcset(src: string, opts?: {
|
|
9
|
+
declare function imageUrl(src: string, _opts?: ImageOptions): string;
|
|
10
|
+
declare function srcset(_src: string, _opts?: {
|
|
12
11
|
widths?: number[];
|
|
13
12
|
quality?: number;
|
|
14
13
|
resize?: Resize;
|
|
@@ -25,4 +24,4 @@ declare function imageProps(src: string, opts?: {
|
|
|
25
24
|
sizes: string;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
|
-
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl,
|
|
27
|
+
export { DEFAULT_WIDTHS, type ImageOptions, type Resize, imageProps, imageUrl, srcset };
|
package/dist/image.js
CHANGED
|
@@ -1,36 +1,15 @@
|
|
|
1
1
|
import './chunk-PKBMQBKP.js';
|
|
2
2
|
|
|
3
3
|
// src/image.ts
|
|
4
|
-
var OBJECT_PATH = "/storage/v1/object/public/";
|
|
5
|
-
var RENDER_PATH = "/storage/v1/render/image/public/";
|
|
6
4
|
var DEFAULT_WIDTHS = [320, 640, 960, 1280, 1920];
|
|
7
|
-
function
|
|
8
|
-
return src
|
|
5
|
+
function imageUrl(src, _opts = {}) {
|
|
6
|
+
return src;
|
|
9
7
|
}
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
let url;
|
|
13
|
-
try {
|
|
14
|
-
url = new URL(src.replace(OBJECT_PATH, RENDER_PATH));
|
|
15
|
-
} catch {
|
|
16
|
-
return src;
|
|
17
|
-
}
|
|
18
|
-
if (opts.width) url.searchParams.set("width", String(Math.round(opts.width)));
|
|
19
|
-
if (opts.height) url.searchParams.set("height", String(Math.round(opts.height)));
|
|
20
|
-
if (opts.quality) url.searchParams.set("quality", String(opts.quality));
|
|
21
|
-
if (opts.resize) url.searchParams.set("resize", opts.resize);
|
|
22
|
-
return url.toString();
|
|
23
|
-
}
|
|
24
|
-
function srcset(src, opts = {}) {
|
|
25
|
-
if (!isSupabaseImage(src)) return "";
|
|
26
|
-
return (opts.widths ?? DEFAULT_WIDTHS).map((w) => `${imageUrl(src, { width: w, quality: opts.quality, resize: opts.resize })} ${w}w`).join(", ");
|
|
8
|
+
function srcset(_src, _opts = {}) {
|
|
9
|
+
return "";
|
|
27
10
|
}
|
|
28
11
|
function imageProps(src, opts = {}) {
|
|
29
|
-
return {
|
|
30
|
-
src: imageUrl(src, { width: opts.width, height: opts.height, quality: opts.quality }),
|
|
31
|
-
srcSet: srcset(src, { widths: opts.widths, quality: opts.quality }),
|
|
32
|
-
sizes: opts.sizes ?? "100vw"
|
|
33
|
-
};
|
|
12
|
+
return { src: imageUrl(src), srcSet: srcset(), sizes: opts.sizes ?? "100vw" };
|
|
34
13
|
}
|
|
35
14
|
|
|
36
|
-
export { DEFAULT_WIDTHS, imageProps, imageUrl,
|
|
15
|
+
export { DEFAULT_WIDTHS, imageProps, imageUrl, srcset };
|
package/dist/index.cjs
CHANGED
|
@@ -123,26 +123,26 @@ function createBrease(opts = {}) {
|
|
|
123
123
|
}
|
|
124
124
|
const client = {
|
|
125
125
|
getSite() {
|
|
126
|
-
sitePromise ?? (sitePromise = request("/
|
|
126
|
+
sitePromise ?? (sitePromise = request("/content-api/site").catch((err) => {
|
|
127
127
|
sitePromise = void 0;
|
|
128
128
|
throw err;
|
|
129
129
|
}));
|
|
130
130
|
return sitePromise;
|
|
131
131
|
},
|
|
132
132
|
getPage(slug, { locale }) {
|
|
133
|
-
return request("/
|
|
133
|
+
return request("/content-api/page", { slug, locale }, true);
|
|
134
134
|
},
|
|
135
135
|
getPages(o = {}) {
|
|
136
|
-
return request("/
|
|
136
|
+
return request("/content-api/pages", { locale: o.locale });
|
|
137
137
|
},
|
|
138
138
|
getNavigation(key, { locale }) {
|
|
139
|
-
return request(`/
|
|
139
|
+
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
140
140
|
},
|
|
141
141
|
getRedirects() {
|
|
142
|
-
return request("/
|
|
142
|
+
return request("/content-api/redirects");
|
|
143
143
|
},
|
|
144
144
|
getRelease() {
|
|
145
|
-
return request("/
|
|
145
|
+
return request("/content-api/release");
|
|
146
146
|
},
|
|
147
147
|
async resolve(pathname) {
|
|
148
148
|
const site = await client.getSite();
|
package/dist/index.js
CHANGED
|
@@ -113,26 +113,26 @@ function createBrease(opts = {}) {
|
|
|
113
113
|
}
|
|
114
114
|
const client = {
|
|
115
115
|
getSite() {
|
|
116
|
-
sitePromise ?? (sitePromise = request("/
|
|
116
|
+
sitePromise ?? (sitePromise = request("/content-api/site").catch((err) => {
|
|
117
117
|
sitePromise = void 0;
|
|
118
118
|
throw err;
|
|
119
119
|
}));
|
|
120
120
|
return sitePromise;
|
|
121
121
|
},
|
|
122
122
|
getPage(slug, { locale }) {
|
|
123
|
-
return request("/
|
|
123
|
+
return request("/content-api/page", { slug, locale }, true);
|
|
124
124
|
},
|
|
125
125
|
getPages(o = {}) {
|
|
126
|
-
return request("/
|
|
126
|
+
return request("/content-api/pages", { locale: o.locale });
|
|
127
127
|
},
|
|
128
128
|
getNavigation(key, { locale }) {
|
|
129
|
-
return request(`/
|
|
129
|
+
return request(`/content-api/navigations/${encodeURIComponent(key)}`, { locale }, true);
|
|
130
130
|
},
|
|
131
131
|
getRedirects() {
|
|
132
|
-
return request("/
|
|
132
|
+
return request("/content-api/redirects");
|
|
133
133
|
},
|
|
134
134
|
getRelease() {
|
|
135
|
-
return request("/
|
|
135
|
+
return request("/content-api/release");
|
|
136
136
|
},
|
|
137
137
|
async resolve(pathname) {
|
|
138
138
|
const site = await client.getSite();
|
package/dist/next.cjs
CHANGED
|
@@ -37,7 +37,7 @@ function toMetadata(seo, opts = {}) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
function breaseFetch(tags = [], revalidate) {
|
|
40
|
-
return (input, init) => fetch(input, {
|
|
40
|
+
return (input, init) => env("BREASE_PREVIEW") ? fetch(input, { ...init, cache: "no-store" }) : fetch(input, {
|
|
41
41
|
...init,
|
|
42
42
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
43
43
|
});
|
package/dist/next.js
CHANGED
|
@@ -31,7 +31,7 @@ function toMetadata(seo, opts = {}) {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
function breaseFetch(tags = [], revalidate) {
|
|
34
|
-
return (input, init) => fetch(input, {
|
|
34
|
+
return (input, init) => env("BREASE_PREVIEW") ? fetch(input, { ...init, cache: "no-store" }) : fetch(input, {
|
|
35
35
|
...init,
|
|
36
36
|
next: { tags: ["brease", ...tags], ...revalidate !== void 0 ? { revalidate } : {} }
|
|
37
37
|
});
|