@headroom-cms/api 0.1.2 → 0.1.3
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 +11 -14
- package/blocks/BlockRenderer.astro +3 -3
- package/blocks/Image.astro +3 -3
- package/dist/astro.d.ts +2 -4
- package/dist/astro.js +11 -16
- package/dist/index.cjs +9 -13
- package/dist/index.d.cts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.js +9 -13
- package/dist/react.cjs +6 -6
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install @headroom-cms/api
|
|
|
21
21
|
import { HeadroomClient } from "@headroom-cms/api";
|
|
22
22
|
|
|
23
23
|
const client = new HeadroomClient({
|
|
24
|
-
|
|
24
|
+
url: "https://headroom.example.com",
|
|
25
25
|
site: "mysite.com",
|
|
26
26
|
apiKey: "headroom_xxxxx",
|
|
27
27
|
});
|
|
@@ -35,10 +35,9 @@ const { items } = await client.listContent("posts");
|
|
|
35
35
|
|
|
36
36
|
```ts
|
|
37
37
|
interface HeadroomConfig {
|
|
38
|
-
|
|
38
|
+
url: string; // Headroom CDN URL (used for both API calls and media)
|
|
39
39
|
site: string; // Site host identifier
|
|
40
40
|
apiKey: string; // Public API key
|
|
41
|
-
cdnUrl?: string; // CDN base URL for media
|
|
42
41
|
imageSigningSecret?: string; // HMAC secret for image transforms
|
|
43
42
|
}
|
|
44
43
|
```
|
|
@@ -56,7 +55,7 @@ interface HeadroomConfig {
|
|
|
56
55
|
| `getCollection(name)` | `Collection` | Get collection schema with fields and relationships |
|
|
57
56
|
| `listBlockTypes()` | `BlockTypeListResult` | List block type definitions |
|
|
58
57
|
| `getVersion()` | `number` | Content version (for cache busting) |
|
|
59
|
-
| `mediaUrl(path)` | `string` | Prepend
|
|
58
|
+
| `mediaUrl(path)` | `string` | Prepend base URL to a stored media path |
|
|
60
59
|
| `transformUrl(path, opts?)` | `string` | Build a signed image transform URL |
|
|
61
60
|
|
|
62
61
|
### Query Options for `listContent`
|
|
@@ -121,7 +120,7 @@ const refs = (post._refs || {}) as RefsMap;
|
|
|
121
120
|
| Prop | Type | Description |
|
|
122
121
|
|------|------|-------------|
|
|
123
122
|
| `blocks` | `Block[]` | Block content array |
|
|
124
|
-
| `
|
|
123
|
+
| `baseUrl` | `string?` | Base URL for media (defaults to `HEADROOM_URL` env var) |
|
|
125
124
|
| `refs` | `RefsMap?` | Content reference map for resolving `headroom://` links |
|
|
126
125
|
| `resolveContentLink` | `(ref: PublicContentRef) => string` | Custom URL builder for content links |
|
|
127
126
|
| `transformImage` | `(path: string) => string` | Custom image URL transform (e.g. for responsive images) |
|
|
@@ -141,7 +140,7 @@ function PostBody({ blocks, refs }) {
|
|
|
141
140
|
return (
|
|
142
141
|
<BlockRenderer
|
|
143
142
|
blocks={blocks}
|
|
144
|
-
|
|
143
|
+
baseUrl="https://headroom.example.com"
|
|
145
144
|
refs={refs}
|
|
146
145
|
resolveContentLink={(ref) => `/${ref.collection}/${ref.slug}`}
|
|
147
146
|
/>
|
|
@@ -154,7 +153,7 @@ function PostBody({ blocks, refs }) {
|
|
|
154
153
|
| Prop | Type | Description |
|
|
155
154
|
|------|------|-------------|
|
|
156
155
|
| `blocks` | `Block[]` | Block content array |
|
|
157
|
-
| `
|
|
156
|
+
| `baseUrl` | `string?` | Base URL for media |
|
|
158
157
|
| `refs` | `RefsMap?` | Content reference map |
|
|
159
158
|
| `resolveContentLink` | `(ref: PublicContentRef) => string` | Custom URL builder |
|
|
160
159
|
| `components` | `BlockComponentMap?` | Override or extend block components (see below) |
|
|
@@ -266,20 +265,19 @@ Media paths in content responses (block image URLs, cover images, field values)
|
|
|
266
265
|
|
|
267
266
|
```ts
|
|
268
267
|
const client = new HeadroomClient({
|
|
269
|
-
|
|
268
|
+
url: "https://headroom.example.com",
|
|
270
269
|
site: "mysite.com",
|
|
271
270
|
apiKey: "headroom_xxxxx",
|
|
272
|
-
cdnUrl: "https://d123.cloudfront.net",
|
|
273
271
|
imageSigningSecret: "your-secret",
|
|
274
272
|
});
|
|
275
273
|
|
|
276
|
-
// Full
|
|
274
|
+
// Full URL for the original
|
|
277
275
|
client.mediaUrl(post.coverUrl);
|
|
278
|
-
// → "https://
|
|
276
|
+
// → "https://headroom.example.com/media/mysite.com/01ABC/original.jpg"
|
|
279
277
|
|
|
280
278
|
// Signed transform URL (resized, converted to webp)
|
|
281
279
|
client.transformUrl(post.coverUrl, { width: 800, format: "webp" });
|
|
282
|
-
// → "https://
|
|
280
|
+
// → "https://headroom.example.com/img/mysite.com/01ABC/original.jpg?format=webp&w=800&sig=abc123..."
|
|
283
281
|
```
|
|
284
282
|
|
|
285
283
|
### Transform Options
|
|
@@ -329,10 +327,9 @@ export const collections = {
|
|
|
329
327
|
The loader reads config from environment variables by default:
|
|
330
328
|
|
|
331
329
|
```bash
|
|
332
|
-
|
|
330
|
+
HEADROOM_URL=https://headroom.example.com
|
|
333
331
|
HEADROOM_SITE=mysite.com
|
|
334
332
|
HEADROOM_API_KEY=headroom_xxxxx
|
|
335
|
-
HEADROOM_CDN_URL=https://d123.cloudfront.net # optional
|
|
336
333
|
HEADROOM_IMAGE_SIGNING_SECRET=your-secret # optional
|
|
337
334
|
```
|
|
338
335
|
|
|
@@ -12,14 +12,14 @@ import Fallback from "./Fallback.astro";
|
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
blocks: Block[];
|
|
15
|
-
|
|
15
|
+
baseUrl?: string;
|
|
16
16
|
refs?: RefsMap;
|
|
17
17
|
resolveContentLink?: (ref: PublicContentRef) => string;
|
|
18
18
|
transformImage?: (path: string) => string;
|
|
19
19
|
class?: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const { blocks,
|
|
22
|
+
const { blocks, baseUrl = import.meta.env.HEADROOM_URL, refs, resolveContentLink, transformImage, class: className } = Astro.props;
|
|
23
23
|
|
|
24
24
|
type RenderItem = { listType?: string; block?: Block; items?: Block[] };
|
|
25
25
|
const LIST_TYPE_MAP: Record<string, string> = {
|
|
@@ -53,7 +53,7 @@ for (const block of blocks) {
|
|
|
53
53
|
const block = item.block!;
|
|
54
54
|
if (block.type === "paragraph") return <Paragraph block={block} refs={refs} resolveContentLink={resolveContentLink} />;
|
|
55
55
|
if (block.type === "heading") return <Heading block={block} refs={refs} resolveContentLink={resolveContentLink} />;
|
|
56
|
-
if (block.type === "image") return <Image block={block}
|
|
56
|
+
if (block.type === "image") return <Image block={block} baseUrl={baseUrl} transformImage={transformImage} />;
|
|
57
57
|
if (block.type === "codeBlock") return <CodeBlock block={block} />;
|
|
58
58
|
if (block.type === "table") return <Table block={block} refs={refs} resolveContentLink={resolveContentLink} />;
|
|
59
59
|
return <Fallback block={block} refs={refs} resolveContentLink={resolveContentLink} />;
|
package/blocks/Image.astro
CHANGED
|
@@ -3,11 +3,11 @@ import type { Block } from "../src/types";
|
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
5
|
block: Block;
|
|
6
|
-
|
|
6
|
+
baseUrl?: string;
|
|
7
7
|
transformImage?: (path: string) => string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const { block,
|
|
10
|
+
const { block, baseUrl = import.meta.env.HEADROOM_URL, transformImage } = Astro.props;
|
|
11
11
|
const storedPath = block.props?.url as string | undefined;
|
|
12
12
|
|
|
13
13
|
let src = "";
|
|
@@ -15,7 +15,7 @@ if (storedPath) {
|
|
|
15
15
|
if (transformImage) {
|
|
16
16
|
src = transformImage(storedPath);
|
|
17
17
|
} else {
|
|
18
|
-
src =
|
|
18
|
+
src = baseUrl ? `${baseUrl}${storedPath}` : storedPath;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
package/dist/astro.d.ts
CHANGED
|
@@ -3,14 +3,12 @@ import { ZodTypeAny } from 'astro/zod';
|
|
|
3
3
|
import { AstroIntegration } from 'astro';
|
|
4
4
|
|
|
5
5
|
interface HeadroomConfig {
|
|
6
|
-
/** Base URL of the Headroom
|
|
7
|
-
|
|
6
|
+
/** Base URL of the Headroom CDN (e.g. "https://headroom.example.com"). Used for both API calls and media URLs. */
|
|
7
|
+
url: string;
|
|
8
8
|
/** Site host identifier (e.g. "mysite.com") */
|
|
9
9
|
site: string;
|
|
10
10
|
/** Public API key for X-Headroom-Key header */
|
|
11
11
|
apiKey: string;
|
|
12
|
-
/** CDN base URL for media (e.g. "https://d123.cloudfront.net"). Required for mediaUrl(). */
|
|
13
|
-
cdnUrl?: string;
|
|
14
12
|
/** HMAC secret for signing image transform URLs. Required for transformUrl(). */
|
|
15
13
|
imageSigningSecret?: string;
|
|
16
14
|
}
|
package/dist/astro.js
CHANGED
|
@@ -15,27 +15,24 @@ var HeadroomClient = class {
|
|
|
15
15
|
constructor(config) {
|
|
16
16
|
this.config = {
|
|
17
17
|
...config,
|
|
18
|
-
|
|
19
|
-
cdnUrl: config.cdnUrl?.replace(/\/+$/, "")
|
|
18
|
+
url: config.url.replace(/\/+$/, "")
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
/** Build the full URL for a public API path */
|
|
23
|
-
|
|
24
|
-
return `${this.config.
|
|
22
|
+
apiUrl(path) {
|
|
23
|
+
return `${this.config.url}/v1/${this.config.site}${path}`;
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* Construct a full
|
|
26
|
+
* Construct a full URL from a stored media path.
|
|
28
27
|
* Media paths are stored as `/media/{site}/{mediaId}/original{ext}` in
|
|
29
28
|
* content responses (block props, coverUrl, field values).
|
|
30
29
|
*
|
|
31
30
|
* client.mediaUrl("/media/myblog.com/01ABC/original.jpg")
|
|
32
|
-
* → "https://
|
|
33
|
-
*
|
|
34
|
-
* Returns the path as-is if no cdnUrl is configured (useful for dev).
|
|
31
|
+
* → "https://headroom.example.com/media/myblog.com/01ABC/original.jpg"
|
|
35
32
|
*/
|
|
36
33
|
mediaUrl(path) {
|
|
37
34
|
if (!path) return "";
|
|
38
|
-
return
|
|
35
|
+
return `${this.config.url}${path}`;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* Build a signed image transform URL from a stored media path.
|
|
@@ -65,11 +62,10 @@ var HeadroomClient = class {
|
|
|
65
62
|
const canonical = encoded ? `${imgPath}?${encoded}` : imgPath;
|
|
66
63
|
const mac = createHmac("sha256", this.config.imageSigningSecret).update(canonical).digest("hex").slice(0, 32);
|
|
67
64
|
params.set("sig", mac);
|
|
68
|
-
|
|
69
|
-
return `${cdnBase}${imgPath}?${params.toString()}`;
|
|
65
|
+
return `${this.config.url}${imgPath}?${params.toString()}`;
|
|
70
66
|
}
|
|
71
67
|
async fetch(path, params) {
|
|
72
|
-
const base = this.
|
|
68
|
+
const base = this.apiUrl(path);
|
|
73
69
|
const url = params?.toString() ? `${base}?${params}` : base;
|
|
74
70
|
const res = await fetch(url, {
|
|
75
71
|
headers: { "X-Headroom-Key": this.config.apiKey }
|
|
@@ -88,7 +84,7 @@ var HeadroomClient = class {
|
|
|
88
84
|
return res.json();
|
|
89
85
|
}
|
|
90
86
|
async fetchPost(path, body) {
|
|
91
|
-
const res = await fetch(this.
|
|
87
|
+
const res = await fetch(this.apiUrl(path), {
|
|
92
88
|
method: "POST",
|
|
93
89
|
headers: {
|
|
94
90
|
"X-Headroom-Key": this.config.apiKey,
|
|
@@ -208,10 +204,9 @@ function configFromEnv() {
|
|
|
208
204
|
const dotenv = parseDotenv(resolve(process.cwd(), ".env"));
|
|
209
205
|
const get = (key) => getEnv(key) || dotenv[key];
|
|
210
206
|
return {
|
|
211
|
-
|
|
207
|
+
url: get("HEADROOM_URL") || "http://localhost:3000",
|
|
212
208
|
site: get("HEADROOM_SITE") || "",
|
|
213
209
|
apiKey: get("HEADROOM_API_KEY") || "",
|
|
214
|
-
cdnUrl: get("HEADROOM_CDN_URL") || void 0,
|
|
215
210
|
imageSigningSecret: get("HEADROOM_IMAGE_SIGNING_SECRET") || void 0
|
|
216
211
|
};
|
|
217
212
|
}
|
|
@@ -295,7 +290,7 @@ function headroomDevRefresh(opts) {
|
|
|
295
290
|
const config = opts?.config || configFromEnv();
|
|
296
291
|
const client = new HeadroomClient(config);
|
|
297
292
|
logger.info(
|
|
298
|
-
`Polling ${config.
|
|
293
|
+
`Polling ${config.url}/v1/${config.site}/version every ${interval / 1e3}s`
|
|
299
294
|
);
|
|
300
295
|
let lastVersion = null;
|
|
301
296
|
setInterval(async () => {
|
package/dist/index.cjs
CHANGED
|
@@ -42,27 +42,24 @@ var HeadroomClient = class {
|
|
|
42
42
|
constructor(config) {
|
|
43
43
|
this.config = {
|
|
44
44
|
...config,
|
|
45
|
-
|
|
46
|
-
cdnUrl: config.cdnUrl?.replace(/\/+$/, "")
|
|
45
|
+
url: config.url.replace(/\/+$/, "")
|
|
47
46
|
};
|
|
48
47
|
}
|
|
49
48
|
/** Build the full URL for a public API path */
|
|
50
|
-
|
|
51
|
-
return `${this.config.
|
|
49
|
+
apiUrl(path) {
|
|
50
|
+
return `${this.config.url}/v1/${this.config.site}${path}`;
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
54
|
-
* Construct a full
|
|
53
|
+
* Construct a full URL from a stored media path.
|
|
55
54
|
* Media paths are stored as `/media/{site}/{mediaId}/original{ext}` in
|
|
56
55
|
* content responses (block props, coverUrl, field values).
|
|
57
56
|
*
|
|
58
57
|
* client.mediaUrl("/media/myblog.com/01ABC/original.jpg")
|
|
59
|
-
* → "https://
|
|
60
|
-
*
|
|
61
|
-
* Returns the path as-is if no cdnUrl is configured (useful for dev).
|
|
58
|
+
* → "https://headroom.example.com/media/myblog.com/01ABC/original.jpg"
|
|
62
59
|
*/
|
|
63
60
|
mediaUrl(path) {
|
|
64
61
|
if (!path) return "";
|
|
65
|
-
return
|
|
62
|
+
return `${this.config.url}${path}`;
|
|
66
63
|
}
|
|
67
64
|
/**
|
|
68
65
|
* Build a signed image transform URL from a stored media path.
|
|
@@ -92,11 +89,10 @@ var HeadroomClient = class {
|
|
|
92
89
|
const canonical = encoded ? `${imgPath}?${encoded}` : imgPath;
|
|
93
90
|
const mac = (0, import_node_crypto.createHmac)("sha256", this.config.imageSigningSecret).update(canonical).digest("hex").slice(0, 32);
|
|
94
91
|
params.set("sig", mac);
|
|
95
|
-
|
|
96
|
-
return `${cdnBase}${imgPath}?${params.toString()}`;
|
|
92
|
+
return `${this.config.url}${imgPath}?${params.toString()}`;
|
|
97
93
|
}
|
|
98
94
|
async fetch(path, params) {
|
|
99
|
-
const base = this.
|
|
95
|
+
const base = this.apiUrl(path);
|
|
100
96
|
const url = params?.toString() ? `${base}?${params}` : base;
|
|
101
97
|
const res = await fetch(url, {
|
|
102
98
|
headers: { "X-Headroom-Key": this.config.apiKey }
|
|
@@ -115,7 +111,7 @@ var HeadroomClient = class {
|
|
|
115
111
|
return res.json();
|
|
116
112
|
}
|
|
117
113
|
async fetchPost(path, body) {
|
|
118
|
-
const res = await fetch(this.
|
|
114
|
+
const res = await fetch(this.apiUrl(path), {
|
|
119
115
|
method: "POST",
|
|
120
116
|
headers: {
|
|
121
117
|
"X-Headroom-Key": this.config.apiKey,
|
package/dist/index.d.cts
CHANGED
|
@@ -129,14 +129,12 @@ interface BatchContentResult {
|
|
|
129
129
|
missing: string[];
|
|
130
130
|
}
|
|
131
131
|
interface HeadroomConfig {
|
|
132
|
-
/** Base URL of the Headroom
|
|
133
|
-
|
|
132
|
+
/** Base URL of the Headroom CDN (e.g. "https://headroom.example.com"). Used for both API calls and media URLs. */
|
|
133
|
+
url: string;
|
|
134
134
|
/** Site host identifier (e.g. "mysite.com") */
|
|
135
135
|
site: string;
|
|
136
136
|
/** Public API key for X-Headroom-Key header */
|
|
137
137
|
apiKey: string;
|
|
138
|
-
/** CDN base URL for media (e.g. "https://d123.cloudfront.net"). Required for mediaUrl(). */
|
|
139
|
-
cdnUrl?: string;
|
|
140
138
|
/** HMAC secret for signing image transform URLs. Required for transformUrl(). */
|
|
141
139
|
imageSigningSecret?: string;
|
|
142
140
|
}
|
|
@@ -167,16 +165,14 @@ declare class HeadroomClient {
|
|
|
167
165
|
private config;
|
|
168
166
|
constructor(config: HeadroomConfig);
|
|
169
167
|
/** Build the full URL for a public API path */
|
|
170
|
-
private
|
|
168
|
+
private apiUrl;
|
|
171
169
|
/**
|
|
172
|
-
* Construct a full
|
|
170
|
+
* Construct a full URL from a stored media path.
|
|
173
171
|
* Media paths are stored as `/media/{site}/{mediaId}/original{ext}` in
|
|
174
172
|
* content responses (block props, coverUrl, field values).
|
|
175
173
|
*
|
|
176
174
|
* client.mediaUrl("/media/myblog.com/01ABC/original.jpg")
|
|
177
|
-
* → "https://
|
|
178
|
-
*
|
|
179
|
-
* Returns the path as-is if no cdnUrl is configured (useful for dev).
|
|
175
|
+
* → "https://headroom.example.com/media/myblog.com/01ABC/original.jpg"
|
|
180
176
|
*/
|
|
181
177
|
mediaUrl(path: string | undefined): string;
|
|
182
178
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -129,14 +129,12 @@ interface BatchContentResult {
|
|
|
129
129
|
missing: string[];
|
|
130
130
|
}
|
|
131
131
|
interface HeadroomConfig {
|
|
132
|
-
/** Base URL of the Headroom
|
|
133
|
-
|
|
132
|
+
/** Base URL of the Headroom CDN (e.g. "https://headroom.example.com"). Used for both API calls and media URLs. */
|
|
133
|
+
url: string;
|
|
134
134
|
/** Site host identifier (e.g. "mysite.com") */
|
|
135
135
|
site: string;
|
|
136
136
|
/** Public API key for X-Headroom-Key header */
|
|
137
137
|
apiKey: string;
|
|
138
|
-
/** CDN base URL for media (e.g. "https://d123.cloudfront.net"). Required for mediaUrl(). */
|
|
139
|
-
cdnUrl?: string;
|
|
140
138
|
/** HMAC secret for signing image transform URLs. Required for transformUrl(). */
|
|
141
139
|
imageSigningSecret?: string;
|
|
142
140
|
}
|
|
@@ -167,16 +165,14 @@ declare class HeadroomClient {
|
|
|
167
165
|
private config;
|
|
168
166
|
constructor(config: HeadroomConfig);
|
|
169
167
|
/** Build the full URL for a public API path */
|
|
170
|
-
private
|
|
168
|
+
private apiUrl;
|
|
171
169
|
/**
|
|
172
|
-
* Construct a full
|
|
170
|
+
* Construct a full URL from a stored media path.
|
|
173
171
|
* Media paths are stored as `/media/{site}/{mediaId}/original{ext}` in
|
|
174
172
|
* content responses (block props, coverUrl, field values).
|
|
175
173
|
*
|
|
176
174
|
* client.mediaUrl("/media/myblog.com/01ABC/original.jpg")
|
|
177
|
-
* → "https://
|
|
178
|
-
*
|
|
179
|
-
* Returns the path as-is if no cdnUrl is configured (useful for dev).
|
|
175
|
+
* → "https://headroom.example.com/media/myblog.com/01ABC/original.jpg"
|
|
180
176
|
*/
|
|
181
177
|
mediaUrl(path: string | undefined): string;
|
|
182
178
|
/**
|
package/dist/index.js
CHANGED
|
@@ -15,27 +15,24 @@ var HeadroomClient = class {
|
|
|
15
15
|
constructor(config) {
|
|
16
16
|
this.config = {
|
|
17
17
|
...config,
|
|
18
|
-
|
|
19
|
-
cdnUrl: config.cdnUrl?.replace(/\/+$/, "")
|
|
18
|
+
url: config.url.replace(/\/+$/, "")
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
21
|
/** Build the full URL for a public API path */
|
|
23
|
-
|
|
24
|
-
return `${this.config.
|
|
22
|
+
apiUrl(path) {
|
|
23
|
+
return `${this.config.url}/v1/${this.config.site}${path}`;
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
* Construct a full
|
|
26
|
+
* Construct a full URL from a stored media path.
|
|
28
27
|
* Media paths are stored as `/media/{site}/{mediaId}/original{ext}` in
|
|
29
28
|
* content responses (block props, coverUrl, field values).
|
|
30
29
|
*
|
|
31
30
|
* client.mediaUrl("/media/myblog.com/01ABC/original.jpg")
|
|
32
|
-
* → "https://
|
|
33
|
-
*
|
|
34
|
-
* Returns the path as-is if no cdnUrl is configured (useful for dev).
|
|
31
|
+
* → "https://headroom.example.com/media/myblog.com/01ABC/original.jpg"
|
|
35
32
|
*/
|
|
36
33
|
mediaUrl(path) {
|
|
37
34
|
if (!path) return "";
|
|
38
|
-
return
|
|
35
|
+
return `${this.config.url}${path}`;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* Build a signed image transform URL from a stored media path.
|
|
@@ -65,11 +62,10 @@ var HeadroomClient = class {
|
|
|
65
62
|
const canonical = encoded ? `${imgPath}?${encoded}` : imgPath;
|
|
66
63
|
const mac = createHmac("sha256", this.config.imageSigningSecret).update(canonical).digest("hex").slice(0, 32);
|
|
67
64
|
params.set("sig", mac);
|
|
68
|
-
|
|
69
|
-
return `${cdnBase}${imgPath}?${params.toString()}`;
|
|
65
|
+
return `${this.config.url}${imgPath}?${params.toString()}`;
|
|
70
66
|
}
|
|
71
67
|
async fetch(path, params) {
|
|
72
|
-
const base = this.
|
|
68
|
+
const base = this.apiUrl(path);
|
|
73
69
|
const url = params?.toString() ? `${base}?${params}` : base;
|
|
74
70
|
const res = await fetch(url, {
|
|
75
71
|
headers: { "X-Headroom-Key": this.config.apiKey }
|
|
@@ -88,7 +84,7 @@ var HeadroomClient = class {
|
|
|
88
84
|
return res.json();
|
|
89
85
|
}
|
|
90
86
|
async fetchPost(path, body) {
|
|
91
|
-
const res = await fetch(this.
|
|
87
|
+
const res = await fetch(this.apiUrl(path), {
|
|
92
88
|
method: "POST",
|
|
93
89
|
headers: {
|
|
94
90
|
"X-Headroom-Key": this.config.apiKey,
|
package/dist/react.cjs
CHANGED
|
@@ -120,9 +120,9 @@ function Heading({ block, refs, resolveContentLink }) {
|
|
|
120
120
|
|
|
121
121
|
// src/react/blocks/Image.tsx
|
|
122
122
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
123
|
-
function ImageBlock({ block,
|
|
123
|
+
function ImageBlock({ block, baseUrl }) {
|
|
124
124
|
const storedPath = block.props?.url;
|
|
125
|
-
const src = storedPath ?
|
|
125
|
+
const src = storedPath ? baseUrl ? `${baseUrl}${storedPath}` : storedPath : "";
|
|
126
126
|
const alt = block.props?.alt || "";
|
|
127
127
|
const caption = block.props?.caption || "";
|
|
128
128
|
if (!src) return null;
|
|
@@ -224,7 +224,7 @@ function defaultResolveContentLink(ref) {
|
|
|
224
224
|
function BlockRenderer({
|
|
225
225
|
blocks,
|
|
226
226
|
components,
|
|
227
|
-
|
|
227
|
+
baseUrl,
|
|
228
228
|
refs,
|
|
229
229
|
resolveContentLink,
|
|
230
230
|
fallback,
|
|
@@ -243,7 +243,7 @@ function BlockRenderer({
|
|
|
243
243
|
{
|
|
244
244
|
block: item.items[0],
|
|
245
245
|
items: item.items,
|
|
246
|
-
|
|
246
|
+
baseUrl,
|
|
247
247
|
refs,
|
|
248
248
|
resolveContentLink: resolve,
|
|
249
249
|
components: merged
|
|
@@ -261,7 +261,7 @@ function BlockRenderer({
|
|
|
261
261
|
FallbackComponent,
|
|
262
262
|
{
|
|
263
263
|
block,
|
|
264
|
-
|
|
264
|
+
baseUrl,
|
|
265
265
|
refs,
|
|
266
266
|
resolveContentLink: resolve,
|
|
267
267
|
components: merged
|
|
@@ -275,7 +275,7 @@ function BlockRenderer({
|
|
|
275
275
|
Component,
|
|
276
276
|
{
|
|
277
277
|
block,
|
|
278
|
-
|
|
278
|
+
baseUrl,
|
|
279
279
|
refs,
|
|
280
280
|
resolveContentLink: resolve,
|
|
281
281
|
components: merged
|
package/dist/react.d.cts
CHANGED
|
@@ -58,7 +58,7 @@ declare function Paragraph({ block, refs, resolveContentLink }: BlockComponentPr
|
|
|
58
58
|
|
|
59
59
|
declare function Heading({ block, refs, resolveContentLink }: BlockComponentProps): react_jsx_runtime.JSX.Element;
|
|
60
60
|
|
|
61
|
-
declare function ImageBlock({ block,
|
|
61
|
+
declare function ImageBlock({ block, baseUrl }: BlockComponentProps): react_jsx_runtime.JSX.Element | null;
|
|
62
62
|
|
|
63
63
|
declare function CodeBlock({ block }: BlockComponentProps): react_jsx_runtime.JSX.Element;
|
|
64
64
|
|
|
@@ -75,7 +75,7 @@ declare function Fallback({ block, refs, resolveContentLink }: BlockComponentPro
|
|
|
75
75
|
interface BlockComponentProps {
|
|
76
76
|
block: Block;
|
|
77
77
|
items?: Block[];
|
|
78
|
-
|
|
78
|
+
baseUrl?: string;
|
|
79
79
|
refs?: RefsMap;
|
|
80
80
|
resolveContentLink?: (ref: PublicContentRef) => string;
|
|
81
81
|
components?: BlockComponentMap;
|
|
@@ -87,13 +87,13 @@ declare const defaultBlockComponents: BlockComponentMap;
|
|
|
87
87
|
interface BlockRendererProps {
|
|
88
88
|
blocks: Block[];
|
|
89
89
|
components?: BlockComponentMap;
|
|
90
|
-
|
|
90
|
+
baseUrl?: string;
|
|
91
91
|
refs?: RefsMap;
|
|
92
92
|
resolveContentLink?: (ref: PublicContentRef) => string;
|
|
93
93
|
fallback?: React.ComponentType<BlockComponentProps> | null;
|
|
94
94
|
className?: string;
|
|
95
95
|
}
|
|
96
|
-
declare function BlockRenderer({ blocks, components,
|
|
96
|
+
declare function BlockRenderer({ blocks, components, baseUrl, refs, resolveContentLink, fallback, className, }: BlockRendererProps): react_jsx_runtime.JSX.Element;
|
|
97
97
|
|
|
98
98
|
interface Props {
|
|
99
99
|
content: InlineContent$1[] | undefined | null;
|
package/dist/react.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ declare function Paragraph({ block, refs, resolveContentLink }: BlockComponentPr
|
|
|
58
58
|
|
|
59
59
|
declare function Heading({ block, refs, resolveContentLink }: BlockComponentProps): react_jsx_runtime.JSX.Element;
|
|
60
60
|
|
|
61
|
-
declare function ImageBlock({ block,
|
|
61
|
+
declare function ImageBlock({ block, baseUrl }: BlockComponentProps): react_jsx_runtime.JSX.Element | null;
|
|
62
62
|
|
|
63
63
|
declare function CodeBlock({ block }: BlockComponentProps): react_jsx_runtime.JSX.Element;
|
|
64
64
|
|
|
@@ -75,7 +75,7 @@ declare function Fallback({ block, refs, resolveContentLink }: BlockComponentPro
|
|
|
75
75
|
interface BlockComponentProps {
|
|
76
76
|
block: Block;
|
|
77
77
|
items?: Block[];
|
|
78
|
-
|
|
78
|
+
baseUrl?: string;
|
|
79
79
|
refs?: RefsMap;
|
|
80
80
|
resolveContentLink?: (ref: PublicContentRef) => string;
|
|
81
81
|
components?: BlockComponentMap;
|
|
@@ -87,13 +87,13 @@ declare const defaultBlockComponents: BlockComponentMap;
|
|
|
87
87
|
interface BlockRendererProps {
|
|
88
88
|
blocks: Block[];
|
|
89
89
|
components?: BlockComponentMap;
|
|
90
|
-
|
|
90
|
+
baseUrl?: string;
|
|
91
91
|
refs?: RefsMap;
|
|
92
92
|
resolveContentLink?: (ref: PublicContentRef) => string;
|
|
93
93
|
fallback?: React.ComponentType<BlockComponentProps> | null;
|
|
94
94
|
className?: string;
|
|
95
95
|
}
|
|
96
|
-
declare function BlockRenderer({ blocks, components,
|
|
96
|
+
declare function BlockRenderer({ blocks, components, baseUrl, refs, resolveContentLink, fallback, className, }: BlockRendererProps): react_jsx_runtime.JSX.Element;
|
|
97
97
|
|
|
98
98
|
interface Props {
|
|
99
99
|
content: InlineContent$1[] | undefined | null;
|
package/dist/react.js
CHANGED
|
@@ -73,9 +73,9 @@ function Heading({ block, refs, resolveContentLink }) {
|
|
|
73
73
|
|
|
74
74
|
// src/react/blocks/Image.tsx
|
|
75
75
|
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
76
|
-
function ImageBlock({ block,
|
|
76
|
+
function ImageBlock({ block, baseUrl }) {
|
|
77
77
|
const storedPath = block.props?.url;
|
|
78
|
-
const src = storedPath ?
|
|
78
|
+
const src = storedPath ? baseUrl ? `${baseUrl}${storedPath}` : storedPath : "";
|
|
79
79
|
const alt = block.props?.alt || "";
|
|
80
80
|
const caption = block.props?.caption || "";
|
|
81
81
|
if (!src) return null;
|
|
@@ -177,7 +177,7 @@ function defaultResolveContentLink(ref) {
|
|
|
177
177
|
function BlockRenderer({
|
|
178
178
|
blocks,
|
|
179
179
|
components,
|
|
180
|
-
|
|
180
|
+
baseUrl,
|
|
181
181
|
refs,
|
|
182
182
|
resolveContentLink,
|
|
183
183
|
fallback,
|
|
@@ -196,7 +196,7 @@ function BlockRenderer({
|
|
|
196
196
|
{
|
|
197
197
|
block: item.items[0],
|
|
198
198
|
items: item.items,
|
|
199
|
-
|
|
199
|
+
baseUrl,
|
|
200
200
|
refs,
|
|
201
201
|
resolveContentLink: resolve,
|
|
202
202
|
components: merged
|
|
@@ -214,7 +214,7 @@ function BlockRenderer({
|
|
|
214
214
|
FallbackComponent,
|
|
215
215
|
{
|
|
216
216
|
block,
|
|
217
|
-
|
|
217
|
+
baseUrl,
|
|
218
218
|
refs,
|
|
219
219
|
resolveContentLink: resolve,
|
|
220
220
|
components: merged
|
|
@@ -228,7 +228,7 @@ function BlockRenderer({
|
|
|
228
228
|
Component,
|
|
229
229
|
{
|
|
230
230
|
block,
|
|
231
|
-
|
|
231
|
+
baseUrl,
|
|
232
232
|
refs,
|
|
233
233
|
resolveContentLink: resolve,
|
|
234
234
|
components: merged
|