@lunora/bindings 1.0.0-alpha.6 → 1.0.0-alpha.61
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/analytics/index.d.mts +81 -85
- package/dist/analytics/index.d.ts +81 -85
- package/dist/analytics/index.mjs +1 -2
- package/dist/images/index.d.mts +159 -174
- package/dist/images/index.d.ts +159 -174
- package/dist/images/index.mjs +1 -3
- package/dist/kv/index.d.mts +74 -151
- package/dist/kv/index.d.ts +74 -151
- package/dist/kv/index.mjs +1 -2
- package/dist/packem_shared/AnalyticsSqlError-CeQ3A5Eb.mjs +1 -0
- package/dist/packem_shared/R2SqlError-ZHgOWClB.mjs +1 -0
- package/dist/packem_shared/SelectBuilder-DJXNSdqC.mjs +1 -0
- package/dist/packem_shared/SetOperation-kiI5Wnlm.mjs +1 -0
- package/dist/packem_shared/Sql-BfnxRway.mjs +1 -0
- package/dist/packem_shared/WindowExpression-VX7EEV3h.mjs +1 -0
- package/dist/packem_shared/WindowFunction-CL4jYy2l.mjs +1 -0
- package/dist/packem_shared/asc-DP_WFiAE.mjs +1 -0
- package/dist/packem_shared/buildImageDeliveryUrl-Brqs-dcZ.mjs +1 -0
- package/dist/packem_shared/buildSignedImageUrl-BV-iSJKA.mjs +4 -0
- package/dist/packem_shared/cap-error-body-YBKO32BF.mjs +1 -0
- package/dist/packem_shared/concurrent-vRmSvRpF.mjs +1 -0
- package/dist/packem_shared/createAnalytics-BXTNc57d.mjs +1 -0
- package/dist/packem_shared/createContextVectors-BcfM30uc.mjs +6 -0
- package/dist/packem_shared/createImages-D7JExfqF.mjs +1 -0
- package/dist/packem_shared/createKv-mAHanD5g.mjs +1 -0
- package/dist/packem_shared/createKvIntrospector-BpRiFRFQ.mjs +1 -0
- package/dist/packem_shared/createPipelines-CIvqrc7E.mjs +1 -0
- package/dist/packem_shared/createVectorAdminIntrospector-Ct8v6PxJ.mjs +1 -0
- package/dist/packem_shared/createVectors-Dzv0ilKE.mjs +1 -0
- package/dist/pipelines/index.d.mts +24 -24
- package/dist/pipelines/index.d.ts +24 -24
- package/dist/pipelines/index.mjs +1 -1
- package/dist/r2sql/index.d.mts +169 -125
- package/dist/r2sql/index.d.ts +169 -125
- package/dist/r2sql/index.mjs +1 -7
- package/dist/vectors/index.d.mts +187 -134
- package/dist/vectors/index.d.ts +187 -134
- package/dist/vectors/index.mjs +1 -3
- package/package.json +3 -2
- package/dist/packem_shared/AnalyticsSqlError-C2nz3jpH.mjs +0 -41
- package/dist/packem_shared/R2SqlError-Boygg3S0.mjs +0 -65
- package/dist/packem_shared/SelectBuilder-DHaXZwn_.mjs +0 -167
- package/dist/packem_shared/SetOperation-RDHcxccj.mjs +0 -80
- package/dist/packem_shared/Sql-DceGtcUd.mjs +0 -68
- package/dist/packem_shared/WindowExpression-Cg9s2xcr.mjs +0 -44
- package/dist/packem_shared/WindowFunction-DA3pGC3N.mjs +0 -82
- package/dist/packem_shared/asc-Cur-xO8v.mjs +0 -16
- package/dist/packem_shared/buildImageDeliveryUrl-B6_QU91n.mjs +0 -33
- package/dist/packem_shared/buildSignedImageUrl-6iibA9v1.mjs +0 -113
- package/dist/packem_shared/concurrent-Dj5sOibv.mjs +0 -23
- package/dist/packem_shared/createAnalytics-CEEI69o9.mjs +0 -57
- package/dist/packem_shared/createContextVectors-BSizpmu5.mjs +0 -140
- package/dist/packem_shared/createImages-BzRnsz3H.mjs +0 -85
- package/dist/packem_shared/createKv-7lNrS1W2.mjs +0 -143
- package/dist/packem_shared/createKvIntrospector-CrAgQp1w.mjs +0 -77
- package/dist/packem_shared/createPipelines-CfyJ6VGu.mjs +0 -10
- package/dist/packem_shared/createVectorAdminIntrospector-C-qTDWA1.mjs +0 -53
- package/dist/packem_shared/createVectors-DqxgEPQb.mjs +0 -95
package/dist/images/index.d.mts
CHANGED
|
@@ -1,69 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Structural projections of the Cloudflare **Images** binding (`env.IMAGES`).
|
|
3
|
-
*
|
|
4
|
-
* Declared structurally — the same pattern `@lunora/storage` uses for
|
|
5
|
-
* `R2BucketLike` — so a unit test can pass a plain object double and the real
|
|
6
|
-
* `ImagesBinding` from `@cloudflare/workers-types` satisfies the same shape. We
|
|
7
|
-
* project only the slice of the chain we actually call
|
|
8
|
-
* (`input(stream).transform(opts).output(opts)` + `info(stream)`), not the full
|
|
9
|
-
* hosted-images CRUD surface.
|
|
10
|
-
*
|
|
11
|
-
* TODO(workers-types): the
|
|
12
|
-
* /
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
*/
|
|
2
|
+
* Structural projections of the Cloudflare **Images** binding (`env.IMAGES`).
|
|
3
|
+
*
|
|
4
|
+
* Declared structurally — the same pattern `@lunora/storage` uses for
|
|
5
|
+
* `R2BucketLike` — so a unit test can pass a plain object double and the real
|
|
6
|
+
* `ImagesBinding` from `@cloudflare/workers-types` satisfies the same shape. We
|
|
7
|
+
* project only the slice of the chain we actually call
|
|
8
|
+
* (`input(stream).transform(opts).output(opts)` + `info(stream)`), not the full
|
|
9
|
+
* hosted-images CRUD surface.
|
|
10
|
+
*
|
|
11
|
+
* TODO(workers-types): the `aspect-crop` fit mode is modeled here by hand because
|
|
12
|
+
* `@cloudflare/workers-types` still does not type it — checked at the pinned
|
|
13
|
+
* 5.20260811.1, whose `ImageTransform` now carries `fit: "scale-up"` and `upscale`.
|
|
14
|
+
* Re-check on the next bump: once `ImageTransform` also carries
|
|
15
|
+
* `fit: "aspect-crop"`, drop our hand-rolled addition and lean on the upstream type.
|
|
16
|
+
*/
|
|
18
17
|
/**
|
|
19
|
-
* Porter-Duff compositing operation controlling how an overlay is blended onto
|
|
20
|
-
* the image beneath it. Mirrors the binding's `ImageCompositeMode`.
|
|
21
|
-
*
|
|
22
|
-
* - `over` — foreground drawn on top of the backdrop (default).
|
|
23
|
-
* - `in` — foreground shown only where the backdrop is opaque.
|
|
24
|
-
* - `atop` — foreground drawn on top, clipped to the backdrop's shape.
|
|
25
|
-
* - `out` — foreground shown only where the backdrop is transparent.
|
|
26
|
-
* - `xor` — foreground and backdrop visible only where the other is not.
|
|
27
|
-
* - `lighter` — foreground and backdrop channels added (brightening).
|
|
28
|
-
*/
|
|
18
|
+
* Porter-Duff compositing operation controlling how an overlay is blended onto
|
|
19
|
+
* the image beneath it. Mirrors the binding's `ImageCompositeMode`.
|
|
20
|
+
*
|
|
21
|
+
* - `over` — foreground drawn on top of the backdrop (default).
|
|
22
|
+
* - `in` — foreground shown only where the backdrop is opaque.
|
|
23
|
+
* - `atop` — foreground drawn on top, clipped to the backdrop's shape.
|
|
24
|
+
* - `out` — foreground shown only where the backdrop is transparent.
|
|
25
|
+
* - `xor` — foreground and backdrop visible only where the other is not.
|
|
26
|
+
* - `lighter` — foreground and backdrop channels added (brightening).
|
|
27
|
+
*/
|
|
29
28
|
type ImageCompositeMode = "atop" | "in" | "lighter" | "out" | "over" | "xor";
|
|
30
29
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
* `width`/`height` accept either an integer (pixels) or a decimal in `(0, 1]`
|
|
37
|
-
* interpreted as a fraction of the base image's corresponding dimension.
|
|
38
|
-
*/
|
|
39
|
-
interface DrawOverlay {
|
|
40
|
-
/** Offset, in pixels, from the bottom edge. */
|
|
41
|
-
bottom?: number;
|
|
42
|
-
/** Blend mode for compositing this overlay onto the image. Default `over`. */
|
|
43
|
-
composite?: ImageCompositeMode;
|
|
44
|
-
/** Overlay height — pixels (integer) or a `0–1` fraction of the base height. */
|
|
45
|
-
height?: number;
|
|
46
|
-
/** Offset, in pixels, from the left edge. */
|
|
47
|
-
left?: number;
|
|
48
|
-
/** Overlay opacity, `0.0` (transparent) – `1.0` (opaque). */
|
|
49
|
-
opacity?: number;
|
|
50
|
-
/** Tile the overlay across the base image: `true`, or a single axis `"x"`/`"y"`. */
|
|
51
|
-
repeat?: "x" | "y" | boolean;
|
|
52
|
-
/** Offset, in pixels, from the right edge. */
|
|
53
|
-
right?: number;
|
|
54
|
-
/** Offset, in pixels, from the top edge. */
|
|
55
|
-
top?: number;
|
|
56
|
-
/** Absolute URL of the overlay image. */
|
|
57
|
-
url: string;
|
|
58
|
-
/** Overlay width — pixels (integer) or a `0–1` fraction of the base width. */
|
|
59
|
-
width?: number;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Transform parameters threaded into `binding.input(stream).transform(...)`.
|
|
63
|
-
* A structural subset of the real `ImageTransform`; the keys here are the
|
|
64
|
-
* resize/format/optimize knobs apps reach for. Unknown extra keys on the real
|
|
65
|
-
* binding are still accepted because the binding owns the authoritative type.
|
|
66
|
-
*/
|
|
30
|
+
* Transform parameters threaded into `binding.input(stream).transform(...)`.
|
|
31
|
+
* A structural subset of the real `ImageTransform`; the keys here are the
|
|
32
|
+
* resize/format/optimize knobs apps reach for. Unknown extra keys on the real
|
|
33
|
+
* binding are still accepted because the binding owns the authoritative type.
|
|
34
|
+
*/
|
|
67
35
|
interface TransformOptions {
|
|
68
36
|
/** Background color (CSS color) painted under transparent images. */
|
|
69
37
|
background?: string;
|
|
@@ -74,24 +42,17 @@ interface TransformOptions {
|
|
|
74
42
|
/** Contrast multiplier (1 = unchanged). */
|
|
75
43
|
contrast?: number;
|
|
76
44
|
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* - `cover` — fill the box, cropping overflow.
|
|
89
|
-
* - `crop` — shrink-and-crop to fit, but never enlarges.
|
|
90
|
-
* - `aspect-crop` — crop to the target aspect ratio, but never enlarges.
|
|
91
|
-
* - `pad` — fit within the box, padding the remainder with `background`.
|
|
92
|
-
* - `squeeze` — stretch to the exact box, distorting aspect ratio.
|
|
93
|
-
* - `scale-up` — enlarge to show the whole image, but never downscales.
|
|
94
|
-
*/
|
|
45
|
+
* Resize mode. Affects how `width`/`height` are interpreted.
|
|
46
|
+
*
|
|
47
|
+
* - `scale-down` — contain, but never enlarges.
|
|
48
|
+
* - `contain` — fit within the box, preserving aspect ratio.
|
|
49
|
+
* - `cover` — fill the box, cropping overflow.
|
|
50
|
+
* - `crop` — shrink-and-crop to fit, but never enlarges.
|
|
51
|
+
* - `aspect-crop` — crop to the target aspect ratio, but never enlarges.
|
|
52
|
+
* - `pad` — fit within the box, padding the remainder with `background`.
|
|
53
|
+
* - `squeeze` — stretch to the exact box, distorting aspect ratio.
|
|
54
|
+
* - `scale-up` — enlarge to show the whole image, but never downscales.
|
|
55
|
+
*/
|
|
95
56
|
fit?: "aspect-crop" | "contain" | "cover" | "crop" | "pad" | "scale-down" | "scale-up" | "squeeze";
|
|
96
57
|
/** Mirror the image horizontally, vertically, or both. */
|
|
97
58
|
flip?: "h" | "hv" | "v";
|
|
@@ -114,11 +75,11 @@ interface TransformOptions {
|
|
|
114
75
|
/** Sharpen strength (0–10). */
|
|
115
76
|
sharpen?: number;
|
|
116
77
|
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
78
|
+
* Algorithm used when a transform enlarges the image (e.g. `fit: "scale-up"`).
|
|
79
|
+
*
|
|
80
|
+
* - `interpolate` — bicubic interpolation (default), may soften detail.
|
|
81
|
+
* - `generate` — AI upscaling for sharper, more detailed enlargements.
|
|
82
|
+
*/
|
|
122
83
|
upscale?: "generate" | "interpolate";
|
|
123
84
|
/** Target width in pixels (integer). Clamped to the configured ceiling. */
|
|
124
85
|
width?: number;
|
|
@@ -137,10 +98,10 @@ interface OutputOptions {
|
|
|
137
98
|
quality?: number;
|
|
138
99
|
}
|
|
139
100
|
/**
|
|
140
|
-
* The result of `binding.input(...).transform(...).output(...)`. Mirrors the
|
|
141
|
-
* real `ImageTransformationResult` — a `Response`, the content type, and the
|
|
142
|
-
* raw byte stream.
|
|
143
|
-
*/
|
|
101
|
+
* The result of `binding.input(...).transform(...).output(...)`. Mirrors the
|
|
102
|
+
* real `ImageTransformationResult` — a `Response`, the content type, and the
|
|
103
|
+
* raw byte stream.
|
|
104
|
+
*/
|
|
144
105
|
interface ImageTransformationResultLike {
|
|
145
106
|
contentType: () => string;
|
|
146
107
|
image: () => ReadableStream<Uint8Array>;
|
|
@@ -156,11 +117,11 @@ type ImageInfoLike = {
|
|
|
156
117
|
format: string;
|
|
157
118
|
};
|
|
158
119
|
/**
|
|
159
|
-
* Binding-side overlay options for `transformer.draw(image, options)` — the
|
|
160
|
-
* blend/position/opacity knobs.
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*/
|
|
120
|
+
* Binding-side overlay options for `transformer.draw(image, options)` — the
|
|
121
|
+
* blend/position/opacity knobs. There is no `url` (the overlay bytes are passed
|
|
122
|
+
* as the stream) and no `width`/`height` (the overlay is pre-sized via its own
|
|
123
|
+
* transform); mirrors `ImageDrawOptions`.
|
|
124
|
+
*/
|
|
164
125
|
interface ImageDrawOptions {
|
|
165
126
|
/** Offset, in pixels, from the bottom edge. */
|
|
166
127
|
bottom?: number;
|
|
@@ -178,10 +139,10 @@ interface ImageDrawOptions {
|
|
|
178
139
|
top?: number;
|
|
179
140
|
}
|
|
180
141
|
/**
|
|
181
|
-
* One overlay applied through the **binding** path (`Images.transform`'s
|
|
182
|
-
* `overlays` argument). The overlay bytes come from `image` (any {@link ImageInput});
|
|
183
|
-
* an optional `transform` pre-sizes/reformats the overlay before it is drawn.
|
|
184
|
-
*/
|
|
142
|
+
* One overlay applied through the **binding** path (`Images.transform`'s
|
|
143
|
+
* `overlays` argument). The overlay bytes come from `image` (any {@link ImageInput});
|
|
144
|
+
* an optional `transform` pre-sizes/reformats the overlay before it is drawn.
|
|
145
|
+
*/
|
|
185
146
|
interface ImageOverlay extends ImageDrawOptions {
|
|
186
147
|
/** The overlay image bytes — a stream, buffer, `Blob`, or R2 object body. */
|
|
187
148
|
image: ImageInput;
|
|
@@ -195,19 +156,19 @@ interface ImageTransformerLike {
|
|
|
195
156
|
transform: (transform: TransformOptions) => ImageTransformerLike;
|
|
196
157
|
}
|
|
197
158
|
/**
|
|
198
|
-
* Minimal projection of `ImagesBinding`. Declared structurally so unit tests can
|
|
199
|
-
* pass a plain object double; the real `env.IMAGES` binding satisfies the same
|
|
200
|
-
* shape. Only the input/transform/output chain and `info` are projected — the
|
|
201
|
-
* hosted-images CRUD surface is out of scope.
|
|
202
|
-
*/
|
|
159
|
+
* Minimal projection of `ImagesBinding`. Declared structurally so unit tests can
|
|
160
|
+
* pass a plain object double; the real `env.IMAGES` binding satisfies the same
|
|
161
|
+
* shape. Only the input/transform/output chain and `info` are projected — the
|
|
162
|
+
* hosted-images CRUD surface is out of scope.
|
|
163
|
+
*/
|
|
203
164
|
interface ImagesBindingLike {
|
|
204
165
|
info: (stream: ReadableStream<Uint8Array>) => Promise<ImageInfoLike>;
|
|
205
166
|
input: (stream: ReadableStream<Uint8Array>) => ImageTransformerLike;
|
|
206
167
|
}
|
|
207
168
|
/**
|
|
208
|
-
* An R2 object body (as returned by `ctx.storage.download(key)`) — first-class
|
|
209
|
-
* transform input. Only `.body` is read, so a structural projection is enough.
|
|
210
|
-
*/
|
|
169
|
+
* An R2 object body (as returned by `ctx.storage.download(key)`) — first-class
|
|
170
|
+
* transform input. Only `.body` is read, so a structural projection is enough.
|
|
171
|
+
*/
|
|
211
172
|
interface R2ObjectBodyLike {
|
|
212
173
|
body: ReadableStream | null;
|
|
213
174
|
}
|
|
@@ -220,74 +181,89 @@ interface LunoraImagesOptions {
|
|
|
220
181
|
maxDimension?: number;
|
|
221
182
|
}
|
|
222
183
|
/**
|
|
223
|
-
* The action-only Images client wired onto `ctx.images`.
|
|
224
|
-
*
|
|
225
|
-
* The binding-backed `transform`/`info` calls are non-deterministic network /
|
|
226
|
-
* compute I/O, so this lives on **ActionCtx only** — the same seam as `ctx.ai`.
|
|
227
|
-
* The pure URL/signed-URL builders are exported as free functions (see
|
|
228
|
-
* `index.ts`) and are safe to call from any handler.
|
|
229
|
-
*/
|
|
184
|
+
* The action-only Images client wired onto `ctx.images`.
|
|
185
|
+
*
|
|
186
|
+
* The binding-backed `transform`/`info` calls are non-deterministic network /
|
|
187
|
+
* compute I/O, so this lives on **ActionCtx only** — the same seam as `ctx.ai`.
|
|
188
|
+
* The pure URL/signed-URL builders are exported as free functions (see
|
|
189
|
+
* `index.ts`) and are safe to call from any handler.
|
|
190
|
+
*/
|
|
230
191
|
interface Images {
|
|
231
192
|
/**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
193
|
+
* Probe an image for its format and (for raster formats) dimensions + byte
|
|
194
|
+
* size, without running a transform. Wraps `binding.info(...)`.
|
|
195
|
+
*/
|
|
235
196
|
info: (input: ImageInput) => Promise<ImageInfoLike>;
|
|
236
197
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
198
|
+
* Resize / reformat / optimize `input`, returning the transformed result
|
|
199
|
+
* (a `Response`, content type, and byte stream). Accepts a raw stream/buffer,
|
|
200
|
+
* a `Blob`, or an R2 object body straight from `ctx.storage.download(key)`.
|
|
201
|
+
*
|
|
202
|
+
* `transform` dimensions are clamped to the configured ceiling and the output
|
|
203
|
+
* `format` is validated against the allowlist, so a hostile request can't
|
|
204
|
+
* mint a multi-gigapixel canvas or an unexpected content type.
|
|
205
|
+
*
|
|
206
|
+
* `overlays` are composited over the result in order (last on top) via the
|
|
207
|
+
* binding's `draw` step — each overlay's bytes come from its own `image`, with
|
|
208
|
+
* optional per-overlay `transform` (resize/reformat) and blend/position options.
|
|
209
|
+
*/
|
|
249
210
|
transform: (input: ImageInput, transform?: TransformOptions, output?: OutputOptions, overlays?: ImageOverlay[]) => Promise<ImageTransformationResultLike>;
|
|
250
211
|
}
|
|
251
212
|
/**
|
|
252
|
-
* Build the action-only {@link Images} client over a Cloudflare Images binding.
|
|
253
|
-
*
|
|
254
|
-
* ```ts
|
|
255
|
-
* const images = createImages({ binding: env.IMAGES });
|
|
256
|
-
* const result = await images.transform(
|
|
257
|
-
* await ctx.storage.download("uploads/avatar.png"),
|
|
258
|
-
* { width: 256, height: 256, fit: "cover" },
|
|
259
|
-
* { format: "image/webp", quality: 82 },
|
|
260
|
-
* );
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
213
|
+
* Build the action-only {@link Images} client over a Cloudflare Images binding.
|
|
214
|
+
*
|
|
215
|
+
* ```ts
|
|
216
|
+
* const images = createImages({ binding: env.IMAGES });
|
|
217
|
+
* const result = await images.transform(
|
|
218
|
+
* await ctx.storage.download("uploads/avatar.png"),
|
|
219
|
+
* { width: 256, height: 256, fit: "cover" },
|
|
220
|
+
* { format: "image/webp", quality: 82 },
|
|
221
|
+
* );
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
263
224
|
declare const createImages: (options: LunoraImagesOptions) => Images;
|
|
264
225
|
interface ImageDeliveryUrlOptions {
|
|
265
226
|
/** Delivery / transform origin, e.g. `https://cdn.acme.test`. */
|
|
266
227
|
baseUrl: string;
|
|
267
228
|
/**
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
229
|
+
* Hosted-Images image id. When set, the **delivery-variant** form is built
|
|
230
|
+
* (`<baseUrl>/<imageId>/<variant>`) and `transform`/`key` are ignored.
|
|
231
|
+
*/
|
|
271
232
|
imageId?: string;
|
|
272
233
|
/**
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
234
|
+
* Source image — an absolute URL or an origin-relative key. Used by the
|
|
235
|
+
* `/cdn-cgi/image/...` transform form. Ignored when `imageId` is set.
|
|
236
|
+
*/
|
|
276
237
|
key?: string;
|
|
277
|
-
/** Transform options for the `/cdn-cgi/image
|
|
238
|
+
/** Transform options for the `/cdn-cgi/image/<options>/<source>` form. */
|
|
278
239
|
transform?: TransformOptions;
|
|
279
240
|
/** Named delivery variant (e.g. `public`, `thumbnail`). Used with `imageId`; default `public`. */
|
|
280
241
|
variant?: string;
|
|
281
242
|
}
|
|
282
243
|
/**
|
|
283
|
-
* Build a Cloudflare Images delivery / transform URL.
|
|
284
|
-
*
|
|
285
|
-
* - With `imageId`:
|
|
286
|
-
* - With `key`:
|
|
287
|
-
*
|
|
288
|
-
* Pure and deterministic — usable from any handler.
|
|
289
|
-
*/
|
|
244
|
+
* Build a Cloudflare Images delivery / transform URL.
|
|
245
|
+
*
|
|
246
|
+
* - With `imageId`: `<baseUrl>/<imageId>/<variant>` (hosted delivery variant).
|
|
247
|
+
* - With `key`: `<baseUrl>/cdn-cgi/image/<options>/<source>` (URL-based transform).
|
|
248
|
+
*
|
|
249
|
+
* Pure and deterministic — usable from any handler.
|
|
250
|
+
*/
|
|
290
251
|
declare const buildImageDeliveryUrl: (options: ImageDeliveryUrlOptions) => string;
|
|
252
|
+
/**
|
|
253
|
+
* Parse a verified transform string (the `t` query value handed back by
|
|
254
|
+
* {@link verifySignedImageUrl}) back into the {@link TransformOptions} it was
|
|
255
|
+
* serialized from, so the Worker can apply exactly the signed transform via
|
|
256
|
+
* `ctx.images.transform(...)` without hand-writing the inverse encoding.
|
|
257
|
+
*
|
|
258
|
+
* The exact inverse of `serializeTransform` above — the two MUST evolve
|
|
259
|
+
* together (the round-trip test in
|
|
260
|
+
* `__tests__/images/signed-delivery-url.test.ts` pins the pairing). Throws a
|
|
261
|
+
* `TypeError` on an unknown key or an uncoercible value: the input is meant to
|
|
262
|
+
* be a string whose HMAC already verified, so a parse failure means
|
|
263
|
+
* encoder/decoder drift in the library, never user input — fail loud rather
|
|
264
|
+
* than silently un-binding the transform the signature protects.
|
|
265
|
+
*/
|
|
266
|
+
declare const parseSignedTransform: (t: string) => TransformOptions;
|
|
291
267
|
interface SignedImageUrlOptions {
|
|
292
268
|
/** Delivery / Worker origin the signed URL points at (e.g. `https://cdn.acme.test`). */
|
|
293
269
|
baseUrl: string;
|
|
@@ -298,41 +274,50 @@ interface SignedImageUrlOptions {
|
|
|
298
274
|
/** HMAC secret. MUST NOT be shared across tenants. */
|
|
299
275
|
secret: string;
|
|
300
276
|
/**
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
277
|
+
* Transform requested by this URL. Bound into the signature, so a client
|
|
278
|
+
* can't alter the render without invalidating it. The Worker should apply
|
|
279
|
+
* exactly this (verified) transform via `ctx.images.transform(...)`.
|
|
280
|
+
*/
|
|
305
281
|
transform?: TransformOptions;
|
|
306
282
|
}
|
|
307
283
|
/**
|
|
308
|
-
* Mint a Worker-signed image URL: `baseUrl` joined to `key`, plus `exp` (unix
|
|
309
|
-
* seconds), the serialized `t` (transform), and `sig` (base64url HMAC). The
|
|
310
|
-
* canonical binds host + key + expiry + transform.
|
|
311
|
-
*
|
|
312
|
-
* The Worker handling the route should call {@link verifySignedImageUrl} to
|
|
313
|
-
* validate before serving / transforming.
|
|
314
|
-
*/
|
|
284
|
+
* Mint a Worker-signed image URL: `baseUrl` joined to `key`, plus `exp` (unix
|
|
285
|
+
* seconds), the serialized `t` (transform), and `sig` (base64url HMAC). The
|
|
286
|
+
* canonical binds host + key + expiry + transform.
|
|
287
|
+
*
|
|
288
|
+
* The Worker handling the route should call {@link verifySignedImageUrl} to
|
|
289
|
+
* validate before serving / transforming.
|
|
290
|
+
*/
|
|
315
291
|
declare const buildSignedImageUrl: (options: SignedImageUrlOptions) => Promise<string>;
|
|
316
292
|
interface VerifyImageResult {
|
|
317
293
|
/** The verified image key (route pathname). */
|
|
318
294
|
key?: string;
|
|
319
295
|
/**
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
296
|
+
* Internal-only failure reason for server logs/diagnostics. **Do not echo to
|
|
297
|
+
* clients** — a precise reason ("expired" vs "bad_signature") is a signing
|
|
298
|
+
* oracle. Public responses should expose only `valid`.
|
|
299
|
+
*/
|
|
324
300
|
reason?: "bad_signature" | "expired" | "malformed";
|
|
325
301
|
/** The raw, verified transform string (the `t` query value), when present. */
|
|
326
302
|
transform?: string;
|
|
303
|
+
/**
|
|
304
|
+
* The verified transform decoded back into the options object to pass to
|
|
305
|
+
* `ctx.images.transform(...)` — {@link parseSignedTransform} applied to
|
|
306
|
+
* `transform`. Left `undefined` when `transform` is absent, and also when a
|
|
307
|
+
* genuinely signed transform carries a key this build does not know (an
|
|
308
|
+
* old URL minted before a key was renamed): the request stays `valid`, the
|
|
309
|
+
* raw `transform` is still returned, and the caller decides.
|
|
310
|
+
*/
|
|
311
|
+
transformOptions?: TransformOptions;
|
|
327
312
|
valid: boolean;
|
|
328
313
|
}
|
|
329
314
|
/**
|
|
330
|
-
* Verify a {@link buildSignedImageUrl} output. By default the signature is
|
|
331
|
-
* canonicalized against the inbound `url.host`; pass `expectedHost` for a
|
|
332
|
-
* CDN/host-rewrite topology where the Worker sees a different host than the one
|
|
333
|
-
* the URL was minted for.
|
|
334
|
-
*/
|
|
315
|
+
* Verify a {@link buildSignedImageUrl} output. By default the signature is
|
|
316
|
+
* canonicalized against the inbound `url.host`; pass `expectedHost` for a
|
|
317
|
+
* CDN/host-rewrite topology where the Worker sees a different host than the one
|
|
318
|
+
* the URL was minted for.
|
|
319
|
+
*/
|
|
335
320
|
declare const verifySignedImageUrl: (input: string | URL, secret: string, options?: {
|
|
336
321
|
expectedHost?: string;
|
|
337
322
|
}) => Promise<VerifyImageResult>;
|
|
338
|
-
export { type
|
|
323
|
+
export { type ImageCompositeMode, type ImageDeliveryUrlOptions, type ImageDrawOptions, type ImageInfoLike, type ImageInput, type ImageOutputFormat, type ImageOverlay, type ImageTransformationResultLike, type ImageTransformerLike, type Images, type ImagesBindingLike, type LunoraImagesOptions, type OutputOptions, type R2ObjectBodyLike, type SignedImageUrlOptions, type TransformOptions, type VerifyImageResult, buildImageDeliveryUrl, buildSignedImageUrl, createImages, parseSignedTransform, verifySignedImageUrl };
|