og-route-kit 0.0.0-stage → 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/CHANGELOG.md +43 -0
- package/LICENSE +21 -0
- package/README.md +265 -2
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +195 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/index.d.ts +21 -0
- package/dist/core/index.js +133 -0
- package/dist/core/index.js.map +1 -0
- package/dist/examples/cards/index.d.ts +24 -0
- package/dist/examples/cards/index.js +129 -0
- package/dist/examples/cards/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.d.ts +44 -0
- package/dist/next/index.js +270 -0
- package/dist/next/index.js.map +1 -0
- package/dist/sizes-Bn3i71Bz.d.ts +34 -0
- package/package.json +92 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public release. A narrow toolkit for typed Open Graph image routes in Next.js App Router projects.
|
|
6
|
+
|
|
7
|
+
### Route factory (`og-route-kit/next`)
|
|
8
|
+
|
|
9
|
+
- `createOgRoute` returns an App Router `GET` handler that normalizes query params, renders your TSX card with `next/og`, and returns an `ImageResponse`.
|
|
10
|
+
- Missing required params return `400` with `Cache-Control: no-store`.
|
|
11
|
+
- Image responses default to `DEFAULT_CACHE_CONTROL` (`public, max-age=0, s-maxage=86400, stale-while-revalidate=604800`) and `X-Content-Type-Options: nosniff`; pass `headers` to override.
|
|
12
|
+
|
|
13
|
+
### Param normalization (`og-route-kit/core`)
|
|
14
|
+
|
|
15
|
+
- `normalizeOgParams` applies defaults and fallbacks, required fields, whitespace collapsing, trimming, and deterministic `max` truncation.
|
|
16
|
+
- Fields without a `max` are capped at `DEFAULT_OG_PARAM_MAX` (512) so untrusted query input cannot reach the renderer unbounded.
|
|
17
|
+
- `normalizeText` and `OgParamError` are exported for custom handling.
|
|
18
|
+
|
|
19
|
+
### Metadata helper (`og-route-kit/next`)
|
|
20
|
+
|
|
21
|
+
- `createSocialMetadata` builds Open Graph and Twitter metadata for website and article pages, with matching image lists for both.
|
|
22
|
+
- Optional `includeDefaultImageFallback` lists a committed static image after the generated route image.
|
|
23
|
+
|
|
24
|
+
### Core helpers (`og-route-kit/core`)
|
|
25
|
+
|
|
26
|
+
- `buildOgImageUrl` builds an encoded route URL while preserving existing query params and hash fragments.
|
|
27
|
+
- `OG_IMAGE_SIZES` and `resolveOgImageSize` provide size presets (`og` 1200x630, `twitter` 1200x675, `square` 1200x1200) and custom sizes.
|
|
28
|
+
|
|
29
|
+
### CLI
|
|
30
|
+
|
|
31
|
+
- `og-route-kit check` verifies a running route returns a valid PNG.
|
|
32
|
+
- `og-route-kit export` writes the rendered PNG to disk, for example as a static fallback in `public/`.
|
|
33
|
+
- `og-route-kit preview` prints preview URLs for a route.
|
|
34
|
+
- `check` and `export` reject non-2xx responses, non-PNG content types, corrupt PNG bodies, responses over `--max-bytes` (default `8000000`), and requests over `--timeout` (default `30000` ms).
|
|
35
|
+
|
|
36
|
+
### Example cards (`og-route-kit/examples/cards`)
|
|
37
|
+
|
|
38
|
+
- Product, article, and changelog cards that render through `createOgRoute`, plus a Next App Router example app that serves them.
|
|
39
|
+
|
|
40
|
+
### Requirements
|
|
41
|
+
|
|
42
|
+
- Node.js 20 or newer.
|
|
43
|
+
- Peer dependencies: `next` >= 14.0.0 and `react` >= 18.2.0.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pixelbrew
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,266 @@
|
|
|
1
|
-
#
|
|
1
|
+
# og-route-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/pixelbrew-studio/og-route-kit/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
Typed `next/og` image routes from your own TSX cards, with query-param defaults, metadata helpers, and a CLI to check and export. For Next.js App Router projects. Not a hosted renderer, visual editor, or template marketplace.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i og-route-kit
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`next` (>= 14) and `react` (>= 18.2) are peer dependencies: `npm i next react`. Node.js 20 or newer.
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
// app/api/og/route.tsx
|
|
18
|
+
import { createOgRoute } from "og-route-kit/next";
|
|
19
|
+
import { ProductOgCard } from "@/og/ProductOgCard";
|
|
20
|
+
|
|
21
|
+
export const GET = createOgRoute({
|
|
22
|
+
defaults: { title: "Ship better social cards.", description: "Code-rendered Open Graph images." },
|
|
23
|
+
fields: { title: { max: 140, required: true } },
|
|
24
|
+
render: ProductOgCard,
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// app/pricing/page.tsx (`social` comes from createSocialMetadata, see Usage)
|
|
30
|
+
export const metadata = social.website({
|
|
31
|
+
title: "Pricing", description: "Simple usage-based pricing.", path: "/pricing",
|
|
32
|
+
image: { title: "Usage-based pricing." },
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
[Demo](https://pixelbrew-studio.github.io/og-route-kit/) · [Usage](#usage) · [API](#api) · [CLI](#cli) · [Changelog](CHANGELOG.md)
|
|
37
|
+
|
|
38
|
+
## What you get over calling `next/og` directly
|
|
39
|
+
|
|
40
|
+
| You get | How |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| Typed query params | Per-field `defaults`, `required`, and `max`. Your card receives a typed props object. A missing required param returns `400` with `Cache-Control: no-store`. |
|
|
43
|
+
| Deterministic text cleanup | Whitespace is collapsed and trimmed, and long values are truncated at `max`. Fields without a `max` are still capped at 512 characters. |
|
|
44
|
+
| Cache headers | `public, max-age=0, s-maxage=86400, stale-while-revalidate=604800` plus `X-Content-Type-Options: nosniff` by default. Override with `headers`. |
|
|
45
|
+
| Metadata helper | `createSocialMetadata` emits Open Graph and Twitter metadata from the same inputs, with the same image list for both and an optional static PNG fallback. |
|
|
46
|
+
| CLI | `check`, `export`, and `preview` against a running route. |
|
|
47
|
+
| Example cards | Product, article, and changelog cards, plus a runnable Next example app. |
|
|
48
|
+
| What it does not do | No hosted renderer, no visual editor, and no CSS beyond what Satori (the renderer behind `next/og`) supports. |
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npm i og-route-kit next react
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`og-route-kit` expects Node.js 20 or newer. It supports Next.js 14 and newer, so its engine is intentionally not tightened to the Next.js 16 floor. The included Next.js 16 example requires Node.js 20.9.0 or newer.
|
|
59
|
+
|
|
60
|
+
To install straight from GitHub, pin a commit or tag for reproducible builds. GitHub installs run the package `prepare` script and build `dist` from source during installation:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm i github:pixelbrew-studio/og-route-kit#v0.1.0-dogfood.20260630
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Route
|
|
67
|
+
|
|
68
|
+
Create an App Router route:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// app/api/og/route.tsx
|
|
72
|
+
import { createOgRoute } from "og-route-kit/next";
|
|
73
|
+
|
|
74
|
+
import { ProductOgCard } from "@/og/ProductOgCard";
|
|
75
|
+
|
|
76
|
+
export const runtime = "edge";
|
|
77
|
+
|
|
78
|
+
export const GET = createOgRoute({
|
|
79
|
+
size: "og",
|
|
80
|
+
defaults: {
|
|
81
|
+
eyebrow: "Acme",
|
|
82
|
+
title: "Ship better social cards.",
|
|
83
|
+
description: "Code-rendered Open Graph images for product pages.",
|
|
84
|
+
},
|
|
85
|
+
fields: {
|
|
86
|
+
eyebrow: { max: 80 },
|
|
87
|
+
title: { max: 140, required: true },
|
|
88
|
+
description: { max: 180 },
|
|
89
|
+
},
|
|
90
|
+
render: ProductOgCard,
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The card is a plain component that returns Satori-compatible JSX. The example app has [three complete cards](examples/next-app/og).
|
|
95
|
+
|
|
96
|
+
### Metadata
|
|
97
|
+
|
|
98
|
+
Build metadata once and reuse it:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// lib/social.ts
|
|
102
|
+
import { createSocialMetadata } from "og-route-kit/next";
|
|
103
|
+
|
|
104
|
+
export const social = createSocialMetadata({
|
|
105
|
+
siteUrl: "https://acme.com",
|
|
106
|
+
siteName: "Acme",
|
|
107
|
+
twitter: "@acme",
|
|
108
|
+
imageRoute: "/api/og",
|
|
109
|
+
defaultImage: "/og-image.png",
|
|
110
|
+
includeDefaultImageFallback: true,
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// app/pricing/page.tsx
|
|
116
|
+
import type { Metadata } from "next";
|
|
117
|
+
|
|
118
|
+
import { social } from "@/lib/social";
|
|
119
|
+
|
|
120
|
+
export const metadata: Metadata = social.website({
|
|
121
|
+
title: "Pricing",
|
|
122
|
+
description: "Simple usage-based pricing.",
|
|
123
|
+
path: "/pricing",
|
|
124
|
+
image: {
|
|
125
|
+
eyebrow: "Pricing",
|
|
126
|
+
title: "Usage-based pricing.",
|
|
127
|
+
description: "Start small. Scale when needed.",
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`defaultImage` is used when a page does not pass `image` params. It is not, by itself, a backup for a dynamic route that fails after a page has emitted `/api/og?...`. Set `includeDefaultImageFallback: true` to emit both images when page-specific image params are present: the generated route image first, then `defaultImage` second. Twitter metadata stays a string URL list in the same order.
|
|
133
|
+
|
|
134
|
+
### Static fallback
|
|
135
|
+
|
|
136
|
+
Keep a committed PNG in `public/` and list it as the static fallback. Export it from your own route:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npx og-route-kit export \
|
|
140
|
+
--url "http://localhost:3000/api/og?title=Pixelbrew&description=Landing+page" \
|
|
141
|
+
--out public/og/default.png
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Then point `defaultImage` at it, for example `defaultImage: "/og/default.png"`.
|
|
145
|
+
|
|
146
|
+
## CLI
|
|
147
|
+
|
|
148
|
+
Check a running route:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx og-route-kit check \
|
|
152
|
+
--url "http://localhost:3000/api/og?title=Hello"
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Export a static fallback PNG from a running route:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx og-route-kit export \
|
|
159
|
+
--url "http://localhost:3000/api/og?title=Hello" \
|
|
160
|
+
--out public/og-image.png
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Print preview URLs:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
npx og-route-kit preview --origin http://localhost:3000 --route /api/og
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`check` and `export` reject non-2xx responses, non-PNG content types, corrupt PNG bodies, responses over `--max-bytes` (default `8000000`), and requests that exceed `--timeout` (default `30000` milliseconds).
|
|
170
|
+
|
|
171
|
+
## API
|
|
172
|
+
|
|
173
|
+
### `createOgRoute`
|
|
174
|
+
|
|
175
|
+
Creates a Next App Router `GET` handler that normalizes search params and returns an `ImageResponse`.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { createOgRoute } from "og-route-kit/next";
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Missing required query fields return `400` with `Cache-Control: no-store`. Successful image responses default to `Cache-Control: public, max-age=0, s-maxage=86400, stale-while-revalidate=604800` (exported as `DEFAULT_CACHE_CONTROL`); pass `headers` to override that cache policy for your route.
|
|
182
|
+
|
|
183
|
+
### `createSocialMetadata`
|
|
184
|
+
|
|
185
|
+
Builds Open Graph and Twitter metadata for website and article pages.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { createSocialMetadata } from "og-route-kit/next";
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Metadata inputs (`title`, `description`, `path`, `image`) are treated as trusted page configuration. A `path` or image value that is a full `http(s)` URL is used verbatim, so do not pass raw end-user input into these fields, or `canonical` and `og:url` could point off-origin.
|
|
192
|
+
|
|
193
|
+
`defaultImage` is a default for pages that omit `image`; it does not automatically back up failed dynamic image routes. To list a committed PNG after the dynamic route image, set `includeDefaultImageFallback: true` and keep `defaultImage` pointed at the static asset.
|
|
194
|
+
|
|
195
|
+
### `normalizeOgParams`
|
|
196
|
+
|
|
197
|
+
Framework-independent field normalization:
|
|
198
|
+
|
|
199
|
+
- missing, empty, and whitespace-only values use a field fallback or default
|
|
200
|
+
- whitespace collapses by default
|
|
201
|
+
- strings trim before validation
|
|
202
|
+
- `max` truncates deterministically; fields without a `max` are still capped at `DEFAULT_OG_PARAM_MAX` (512) so untrusted query input cannot reach the renderer unbounded
|
|
203
|
+
- required fields fail clearly when no usable value exists
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { normalizeOgParams } from "og-route-kit/core";
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `buildOgImageUrl`
|
|
210
|
+
|
|
211
|
+
Builds an encoded route URL while preserving existing query params and hash fragments.
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { buildOgImageUrl } from "og-route-kit/core";
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Example cards
|
|
218
|
+
|
|
219
|
+
`ProductCard`, `ArticleCard`, and `ChangelogCard` are exported from `og-route-kit/examples/cards` for trying the route factory without writing a card first.
|
|
220
|
+
|
|
221
|
+
## Example App
|
|
222
|
+
|
|
223
|
+
Build the package and run the example route from a clone of this repository:
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
pnpm install
|
|
227
|
+
pnpm build
|
|
228
|
+
pnpm --filter og-route-kit-next-app-example exec next dev -p 3000
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Open `http://localhost:3000/api/og?title=Hello&description=World`. The route should return a `1200 x 630` PNG.
|
|
232
|
+
|
|
233
|
+
The cards shown in this README and on the [demo page](https://pixelbrew-studio.github.io/og-route-kit/) in [`demo/cards`](demo/cards) are real output of the example routes, exported with `og-route-kit export`.
|
|
234
|
+
|
|
235
|
+
## Development
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
pnpm install
|
|
239
|
+
pnpm run ci
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Useful targeted commands:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
pnpm typecheck
|
|
246
|
+
pnpm test
|
|
247
|
+
pnpm build
|
|
248
|
+
pnpm example:build
|
|
249
|
+
pnpm pack:check
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
For a full local route check, run:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
pnpm verify:local
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
That starts the example app, checks the OG route, exports a test PNG to `.context/og-image-test.png`, and stops the server.
|
|
259
|
+
|
|
260
|
+
## Contributing
|
|
261
|
+
|
|
262
|
+
Read [CONTRIBUTING.md](CONTRIBUTING.md). Keep changes focused on the Next-first route kit workflow.
|
|
263
|
+
|
|
264
|
+
## Release
|
|
265
|
+
|
|
266
|
+
Releases are published from a version tag by [`release.yml`](.github/workflows/release.yml). The checklist lives in [docs/release.md](docs/release.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli/index.ts
|
|
4
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
5
|
+
import { dirname } from "path";
|
|
6
|
+
|
|
7
|
+
// src/cli/fetch-png.ts
|
|
8
|
+
var DEFAULT_MAX_BYTES = 8e6;
|
|
9
|
+
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
10
|
+
var PNG_SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
11
|
+
function assertPngResponseHeaders(response, maxBytes) {
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
|
|
14
|
+
}
|
|
15
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
16
|
+
if (!contentType.toLowerCase().includes("image/png")) {
|
|
17
|
+
throw new Error(`Expected image/png, received ${contentType || "unknown content type"}`);
|
|
18
|
+
}
|
|
19
|
+
const contentLength = Number(response.headers.get("content-length"));
|
|
20
|
+
if (Number.isFinite(contentLength) && contentLength > maxBytes) {
|
|
21
|
+
throw new Error(`Image is ${contentLength} bytes, above max ${maxBytes}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function assertPngSignature(bytes) {
|
|
25
|
+
const matches = bytes.byteLength >= PNG_SIGNATURE.length && PNG_SIGNATURE.every((byte, index) => bytes[index] === byte);
|
|
26
|
+
if (!matches) {
|
|
27
|
+
throw new Error("Response body is not a PNG (missing PNG signature)");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function fetchPng(url, options) {
|
|
31
|
+
const maxBytes = resolvePositiveInteger(options.maxBytes, DEFAULT_MAX_BYTES, "maxBytes");
|
|
32
|
+
const timeoutMs = resolvePositiveInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, "timeoutMs");
|
|
33
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
34
|
+
assertPngResponseHeaders(response, maxBytes);
|
|
35
|
+
const bytes = await readResponseBody(response, maxBytes);
|
|
36
|
+
assertPngSignature(bytes);
|
|
37
|
+
return bytes;
|
|
38
|
+
}
|
|
39
|
+
function resolvePositiveInteger(value, fallback, name) {
|
|
40
|
+
const resolved = value ?? fallback;
|
|
41
|
+
if (!Number.isSafeInteger(resolved) || resolved <= 0) {
|
|
42
|
+
throw new Error(`${name} must be a positive integer`);
|
|
43
|
+
}
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
async function readResponseBody(response, maxBytes) {
|
|
47
|
+
if (!response.body) {
|
|
48
|
+
throw new Error("Response body is empty");
|
|
49
|
+
}
|
|
50
|
+
const reader = response.body.getReader();
|
|
51
|
+
const chunks = [];
|
|
52
|
+
let totalBytes = 0;
|
|
53
|
+
try {
|
|
54
|
+
while (true) {
|
|
55
|
+
const { done, value } = await reader.read();
|
|
56
|
+
if (done) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
totalBytes += value.byteLength;
|
|
60
|
+
if (totalBytes > maxBytes) {
|
|
61
|
+
await reader.cancel();
|
|
62
|
+
throw new Error(`Image is above max ${maxBytes} bytes`);
|
|
63
|
+
}
|
|
64
|
+
chunks.push(value);
|
|
65
|
+
}
|
|
66
|
+
} finally {
|
|
67
|
+
reader.releaseLock();
|
|
68
|
+
}
|
|
69
|
+
const bytes = new Uint8Array(totalBytes);
|
|
70
|
+
let offset = 0;
|
|
71
|
+
for (const chunk of chunks) {
|
|
72
|
+
bytes.set(chunk, offset);
|
|
73
|
+
offset += chunk.byteLength;
|
|
74
|
+
}
|
|
75
|
+
return bytes;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/cli/args.ts
|
|
79
|
+
var PREVIEW_EXAMPLES = [
|
|
80
|
+
["Product", "eyebrow=Product&title=Ship+better+social+cards.&description=Code-rendered+Open+Graph+images."],
|
|
81
|
+
["Article", "eyebrow=Journal&title=Why+coded+OG+routes+beat+exported+PNGs&description=Typed+routes+stay+fresh."],
|
|
82
|
+
["Changelog", "eyebrow=v0.1.0&title=Initial+route+kit+release&description=Params%2C+metadata%2C+export."]
|
|
83
|
+
];
|
|
84
|
+
function parseFlags(values) {
|
|
85
|
+
const flags = {};
|
|
86
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
87
|
+
const token = values[index];
|
|
88
|
+
if (!token?.startsWith("--")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const key = token.slice(2);
|
|
92
|
+
const next = values[index + 1];
|
|
93
|
+
if (next && !next.startsWith("--")) {
|
|
94
|
+
flags[key] = next;
|
|
95
|
+
index += 1;
|
|
96
|
+
} else {
|
|
97
|
+
flags[key] = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return flags;
|
|
101
|
+
}
|
|
102
|
+
function requireString(flags, key) {
|
|
103
|
+
const value = flags[key];
|
|
104
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
105
|
+
throw new Error(`Missing required flag --${key}`);
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
function optionalPositiveInteger(flags, key, fallback) {
|
|
110
|
+
const value = flags[key];
|
|
111
|
+
if (value === void 0) {
|
|
112
|
+
return fallback;
|
|
113
|
+
}
|
|
114
|
+
if (typeof value !== "string") {
|
|
115
|
+
throw new Error(`Flag --${key} requires a positive integer`);
|
|
116
|
+
}
|
|
117
|
+
const parsed = Number(value);
|
|
118
|
+
if (!Number.isSafeInteger(parsed) || parsed <= 0) {
|
|
119
|
+
throw new Error(`Flag --${key} requires a positive integer`);
|
|
120
|
+
}
|
|
121
|
+
return parsed;
|
|
122
|
+
}
|
|
123
|
+
function buildPreviewUrls(flags) {
|
|
124
|
+
const origin = String(flags.origin ?? "http://localhost:3000").replace(/\/+$/, "");
|
|
125
|
+
const route = String(flags.route ?? "/api/og");
|
|
126
|
+
const base = `${origin}${route.startsWith("/") ? route : `/${route}`}`;
|
|
127
|
+
return PREVIEW_EXAMPLES.map(([label, query]) => `${label}: ${base}?${query}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/cli/index.ts
|
|
131
|
+
async function main() {
|
|
132
|
+
const args = process.argv.slice(2);
|
|
133
|
+
const command = args[0] ?? "help";
|
|
134
|
+
const flags = parseFlags(args.slice(1));
|
|
135
|
+
try {
|
|
136
|
+
if (command === "export") {
|
|
137
|
+
await exportImage(flags);
|
|
138
|
+
} else if (command === "check") {
|
|
139
|
+
await checkImage(flags);
|
|
140
|
+
} else if (command === "preview") {
|
|
141
|
+
preview(flags);
|
|
142
|
+
} else {
|
|
143
|
+
help();
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
147
|
+
process.exitCode = 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function exportImage(flags) {
|
|
151
|
+
const url = requireString(flags, "url");
|
|
152
|
+
const out = requireString(flags, "out");
|
|
153
|
+
const maxBytes = optionalPositiveInteger(flags, "max-bytes", DEFAULT_MAX_BYTES);
|
|
154
|
+
const timeoutMs = optionalPositiveInteger(flags, "timeout", DEFAULT_TIMEOUT_MS);
|
|
155
|
+
let bytes;
|
|
156
|
+
try {
|
|
157
|
+
bytes = await fetchPng(url, { maxBytes, timeoutMs });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
throw new Error(`Export failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
160
|
+
}
|
|
161
|
+
await mkdir(dirname(out), { recursive: true });
|
|
162
|
+
await writeFile(out, bytes);
|
|
163
|
+
console.log(`Wrote ${bytes.byteLength} bytes to ${out}`);
|
|
164
|
+
}
|
|
165
|
+
async function checkImage(flags) {
|
|
166
|
+
const url = requireString(flags, "url");
|
|
167
|
+
const maxBytes = optionalPositiveInteger(flags, "max-bytes", DEFAULT_MAX_BYTES);
|
|
168
|
+
const timeoutMs = optionalPositiveInteger(flags, "timeout", DEFAULT_TIMEOUT_MS);
|
|
169
|
+
let bytes;
|
|
170
|
+
try {
|
|
171
|
+
bytes = await fetchPng(url, { maxBytes, timeoutMs });
|
|
172
|
+
} catch (error) {
|
|
173
|
+
throw new Error(`Check failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
174
|
+
}
|
|
175
|
+
console.log(`OK 200 image/png ${bytes.byteLength} bytes`);
|
|
176
|
+
}
|
|
177
|
+
function preview(flags) {
|
|
178
|
+
for (const line of buildPreviewUrls(flags)) {
|
|
179
|
+
console.log(line);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function help() {
|
|
183
|
+
console.log(`og-route-kit
|
|
184
|
+
|
|
185
|
+
Commands:
|
|
186
|
+
export --url <url> --out <path> [--max-bytes <n>] [--timeout <ms>]
|
|
187
|
+
Fetch a PNG route and write it to disk
|
|
188
|
+
check --url <url> [--max-bytes <n>] [--timeout <ms>]
|
|
189
|
+
Verify a PNG route is healthy
|
|
190
|
+
preview [--origin <url>] [--route <path>]
|
|
191
|
+
Print local preview URLs
|
|
192
|
+
`);
|
|
193
|
+
}
|
|
194
|
+
await main();
|
|
195
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/cli/fetch-png.ts","../../src/cli/args.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname } from \"node:path\";\n\nimport { DEFAULT_MAX_BYTES, DEFAULT_TIMEOUT_MS, fetchPng } from \"./fetch-png.js\";\nimport { buildPreviewUrls, optionalPositiveInteger, parseFlags, requireString } from \"./args.js\";\nimport type { Flags } from \"./args.js\";\n\ntype Command = \"export\" | \"check\" | \"preview\" | \"help\";\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n const command = (args[0] ?? \"help\") as Command;\n const flags = parseFlags(args.slice(1));\n\n try {\n if (command === \"export\") {\n await exportImage(flags);\n } else if (command === \"check\") {\n await checkImage(flags);\n } else if (command === \"preview\") {\n preview(flags);\n } else {\n help();\n }\n } catch (error) {\n console.error(error instanceof Error ? error.message : String(error));\n process.exitCode = 1;\n }\n}\n\nasync function exportImage(flags: Flags): Promise<void> {\n const url = requireString(flags, \"url\");\n const out = requireString(flags, \"out\");\n const maxBytes = optionalPositiveInteger(flags, \"max-bytes\", DEFAULT_MAX_BYTES);\n const timeoutMs = optionalPositiveInteger(flags, \"timeout\", DEFAULT_TIMEOUT_MS);\n\n let bytes: Uint8Array;\n\n try {\n bytes = await fetchPng(url, { maxBytes, timeoutMs });\n } catch (error) {\n throw new Error(`Export failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n await mkdir(dirname(out), { recursive: true });\n await writeFile(out, bytes);\n console.log(`Wrote ${bytes.byteLength} bytes to ${out}`);\n}\n\nasync function checkImage(flags: Flags): Promise<void> {\n const url = requireString(flags, \"url\");\n const maxBytes = optionalPositiveInteger(flags, \"max-bytes\", DEFAULT_MAX_BYTES);\n const timeoutMs = optionalPositiveInteger(flags, \"timeout\", DEFAULT_TIMEOUT_MS);\n\n let bytes: Uint8Array;\n\n try {\n bytes = await fetchPng(url, { maxBytes, timeoutMs });\n } catch (error) {\n throw new Error(`Check failed: ${error instanceof Error ? error.message : String(error)}`);\n }\n\n console.log(`OK 200 image/png ${bytes.byteLength} bytes`);\n}\n\nfunction preview(flags: Flags): void {\n for (const line of buildPreviewUrls(flags)) {\n console.log(line);\n }\n}\n\nfunction help(): void {\n console.log(`og-route-kit\n\nCommands:\n export --url <url> --out <path> [--max-bytes <n>] [--timeout <ms>]\n Fetch a PNG route and write it to disk\n check --url <url> [--max-bytes <n>] [--timeout <ms>]\n Verify a PNG route is healthy\n preview [--origin <url>] [--route <path>]\n Print local preview URLs\n`);\n}\n\nawait main();\n","export const DEFAULT_MAX_BYTES = 8_000_000;\nexport const DEFAULT_TIMEOUT_MS = 30_000;\n\nconst PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a] as const;\n\nexport interface FetchPngOptions {\n maxBytes?: number;\n timeoutMs?: number;\n}\n\nexport function assertPngResponseHeaders(response: Response, maxBytes: number): void {\n if (!response.ok) {\n throw new Error(`Request failed: ${response.status} ${response.statusText}`);\n }\n\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n\n if (!contentType.toLowerCase().includes(\"image/png\")) {\n throw new Error(`Expected image/png, received ${contentType || \"unknown content type\"}`);\n }\n\n const contentLength = Number(response.headers.get(\"content-length\"));\n\n if (Number.isFinite(contentLength) && contentLength > maxBytes) {\n throw new Error(`Image is ${contentLength} bytes, above max ${maxBytes}`);\n }\n}\n\nexport function assertPngSignature(bytes: Uint8Array): void {\n const matches =\n bytes.byteLength >= PNG_SIGNATURE.length &&\n PNG_SIGNATURE.every((byte, index) => bytes[index] === byte);\n\n if (!matches) {\n throw new Error(\"Response body is not a PNG (missing PNG signature)\");\n }\n}\n\nexport async function fetchPng(url: string, options: FetchPngOptions): Promise<Uint8Array> {\n const maxBytes = resolvePositiveInteger(options.maxBytes, DEFAULT_MAX_BYTES, \"maxBytes\");\n const timeoutMs = resolvePositiveInteger(options.timeoutMs, DEFAULT_TIMEOUT_MS, \"timeoutMs\");\n\n const response = await fetch(url, { signal: AbortSignal.timeout(timeoutMs) });\n\n assertPngResponseHeaders(response, maxBytes);\n\n const bytes = await readResponseBody(response, maxBytes);\n\n assertPngSignature(bytes);\n\n return bytes;\n}\n\nfunction resolvePositiveInteger(value: number | undefined, fallback: number, name: string): number {\n const resolved = value ?? fallback;\n\n if (!Number.isSafeInteger(resolved) || resolved <= 0) {\n throw new Error(`${name} must be a positive integer`);\n }\n\n return resolved;\n}\n\nasync function readResponseBody(response: Response, maxBytes: number): Promise<Uint8Array> {\n if (!response.body) {\n throw new Error(\"Response body is empty\");\n }\n\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let totalBytes = 0;\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n\n if (done) {\n break;\n }\n\n totalBytes += value.byteLength;\n\n if (totalBytes > maxBytes) {\n await reader.cancel();\n throw new Error(`Image is above max ${maxBytes} bytes`);\n }\n\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n\n const bytes = new Uint8Array(totalBytes);\n let offset = 0;\n\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n\n return bytes;\n}\n","export type Flags = Record<string, string | boolean>;\n\nconst PREVIEW_EXAMPLES: ReadonlyArray<readonly [string, string]> = [\n [\"Product\", \"eyebrow=Product&title=Ship+better+social+cards.&description=Code-rendered+Open+Graph+images.\"],\n [\"Article\", \"eyebrow=Journal&title=Why+coded+OG+routes+beat+exported+PNGs&description=Typed+routes+stay+fresh.\"],\n [\"Changelog\", \"eyebrow=v0.1.0&title=Initial+route+kit+release&description=Params%2C+metadata%2C+export.\"],\n];\n\nexport function parseFlags(values: string[]): Flags {\n const flags: Flags = {};\n\n for (let index = 0; index < values.length; index += 1) {\n const token = values[index];\n\n if (!token?.startsWith(\"--\")) {\n continue;\n }\n\n const key = token.slice(2);\n const next = values[index + 1];\n\n if (next && !next.startsWith(\"--\")) {\n flags[key] = next;\n index += 1;\n } else {\n flags[key] = true;\n }\n }\n\n return flags;\n}\n\nexport function requireString(flags: Flags, key: string): string {\n const value = flags[key];\n\n if (typeof value !== \"string\" || value.length === 0) {\n throw new Error(`Missing required flag --${key}`);\n }\n\n return value;\n}\n\nexport function optionalPositiveInteger(flags: Flags, key: string, fallback: number): number {\n const value = flags[key];\n\n if (value === undefined) {\n return fallback;\n }\n\n if (typeof value !== \"string\") {\n throw new Error(`Flag --${key} requires a positive integer`);\n }\n\n const parsed = Number(value);\n\n if (!Number.isSafeInteger(parsed) || parsed <= 0) {\n throw new Error(`Flag --${key} requires a positive integer`);\n }\n\n return parsed;\n}\n\nexport function buildPreviewUrls(flags: Flags): string[] {\n const origin = String(flags.origin ?? \"http://localhost:3000\").replace(/\\/+$/, \"\");\n const route = String(flags.route ?? \"/api/og\");\n const base = `${origin}${route.startsWith(\"/\") ? route : `/${route}`}`;\n return PREVIEW_EXAMPLES.map(([label, query]) => `${label}: ${base}?${query}`);\n}\n"],"mappings":";;;AACA,SAAS,OAAO,iBAAiB;AACjC,SAAS,eAAe;;;ACFjB,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAElC,IAAM,gBAAgB,CAAC,KAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IAAM,EAAI;AAO9D,SAAS,yBAAyB,UAAoB,UAAwB;AACnF,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI,MAAM,mBAAmB,SAAS,MAAM,IAAI,SAAS,UAAU,EAAE;AAAA,EAC7E;AAEA,QAAM,cAAc,SAAS,QAAQ,IAAI,cAAc,KAAK;AAE5D,MAAI,CAAC,YAAY,YAAY,EAAE,SAAS,WAAW,GAAG;AACpD,UAAM,IAAI,MAAM,gCAAgC,eAAe,s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g as buildOgImageUrl, r as resolveOgImageSize } from '../sizes-Bn3i71Bz.js';
|
|
3
|
+
|
|
4
|
+
type OgSearchParamsInput = URLSearchParams | Iterable<[string, string]> | Record<string, string | string[] | null | undefined>;
|
|
5
|
+
type NormalizeOgParamsOptions<T extends Record<string, string>> = {
|
|
6
|
+
defaults: T;
|
|
7
|
+
fields?: OgFields<T> | undefined;
|
|
8
|
+
};
|
|
9
|
+
declare const DEFAULT_OG_PARAM_MAX = 512;
|
|
10
|
+
declare class OgParamError extends Error {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
declare function normalizeOgParams<T extends Record<string, string>>(input: OgSearchParamsInput, options: NormalizeOgParamsOptions<T>): T;
|
|
14
|
+
|
|
15
|
+
type NormalizeTextOptions = {
|
|
16
|
+
collapseWhitespace?: boolean | undefined;
|
|
17
|
+
max?: number | undefined;
|
|
18
|
+
};
|
|
19
|
+
declare function normalizeText(value: string, options?: NormalizeTextOptions): string;
|
|
20
|
+
|
|
21
|
+
export { DEFAULT_OG_PARAM_MAX, type NormalizeOgParamsOptions, type NormalizeTextOptions, OgFields, OgParamError, type OgSearchParamsInput, normalizeOgParams, normalizeText };
|