@nitida/asset-client 0.16.0 → 0.16.2

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/src/transform.ts CHANGED
@@ -2,10 +2,9 @@
2
2
  * On-the-fly transform URL builder.
3
3
  *
4
4
  * Mirrors the server's DSL canonicalizer byte-for-byte so a URL generated
5
- * here hashes to the same R2 cache key as the server's canonical form.
5
+ * here hashes to the same cache key as the server's canonical form.
6
6
  *
7
- * Canonicalization rules (keep in sync with
8
- * `apps/asset-manager/src/features/assets/transform.dsl.ts`):
7
+ * Canonicalization rules (kept in sync with the server):
9
8
  * - Drop entries whose value is `undefined`
10
9
  * - Sort keys alphabetically
11
10
  * - Numbers rendered without leading zeros or trailing dots
@@ -23,7 +22,7 @@ import type { AssetDTO } from "./index";
23
22
  import { getCdnBase } from "./index";
24
23
 
25
24
  /**
26
- * Widths the CDN edge whitelists (DoS guard — see `apps/cdn-proxy` WHITELIST_WIDTHS).
25
+ * Widths the CDN edge whitelists (DoS guard).
27
26
  * Requesting any OTHER width returns HTTP 400 at the edge (unsigned URLs). These are the
28
27
  * 1× base ladder values; DPR ×2/×3 multiples are applied + whitelisted server-side. Import
29
28
  * this instead of hardcoding magic widths so an unsupported size is caught in review/IDE.
@@ -77,9 +76,9 @@ export type TransformOptions = {
77
76
  height?: number;
78
77
  /** Resize fit mode. Default `cover` server-side. */
79
78
  fit?: TransformFit;
80
- /** Crop gravity. `auto` uses sharp's `attention` strategy. */
79
+ /** Crop gravity. `auto` picks the region with the most visual salience. */
81
80
  gravity?: TransformGravity;
82
- /** Output format. `auto` → policy decides (see asset-manager bench). */
81
+ /** Output format. `auto` → the platform's policy decides. */
83
82
  format?: TransformFormat;
84
83
  /** Output quality. `auto` → format-specific default. */
85
84
  quality?: "auto" | number;
@@ -90,16 +89,15 @@ export type TransformOptions = {
90
89
  *
91
90
  * - `removebg`: remove the background; output is a transparent PNG
92
91
  * of the foreground subject. Forces `format=png` regardless of
93
- * other format hints. Runs U²-Net ONNX locally (or BRIA via
94
- * Replicate when `BG_REMOVAL_BACKEND=replicate`). Single cache
95
- * miss per (sha, dsl) tuple; subsequent identical DSLs serve
96
- * from R2 — no inference, no per-image cost.
92
+ * other format hints. A single cache miss per (sha, dsl) tuple;
93
+ * subsequent identical DSLs serve from cache — no inference, no
94
+ * per-image cost.
97
95
  *
98
- * - `genfill`: aspect-extension outpaint via Flux-Fill Pro on
99
- * Replicate. Requires BOTH `width` and `height` — the server
96
+ * - `genfill`: aspect-extension outpaint. Requires BOTH `width`
97
+ * and `height` — the server
100
98
  * fits the source centered into the target canvas and outpaints
101
99
  * the gutters. Output is PNG (forced) at exactly target dims.
102
- * ~$0.05/image first time; same R2 cache as removebg after.
100
+ * ~$0.05/image first time; same cache as removebg after.
103
101
  * Primary use case: building OG cards (1200×630) from portrait
104
102
  * listing photos without awkward edge mirroring.
105
103
  */
@@ -121,7 +119,7 @@ export type TransformOptions = {
121
119
  * the escape hatch for SIGNED URLs that need an off-ladder custom width.
122
120
  *
123
121
  * The edge whitelist only rejects off-ladder widths on UNSIGNED URLs; a valid
124
- * `?sig=` earns the whitelist bypass at the worker (the asset-manager still
122
+ * `?sig=` earns the whitelist bypass at the edge (the server still
125
123
  * does the real HMAC check). So a custom width is ONLY safe when the URL is
126
124
  * signed — hence this type is accepted exclusively by the signing helpers
127
125
  * ({@link getSignedTransformUrl} / `aq.transform(asset, opts, { sign: true })`),
@@ -181,10 +179,10 @@ export function serializeTransform(opts: SignedTransformOptions): string {
181
179
  function extForOptions(opts: SignedTransformOptions): string {
182
180
  // effect=removebg forces PNG output server-side (needs alpha).
183
181
  if (opts.effect === "removebg") return "png";
184
- // effect=genfill defaults to WebP (12× lighter than the raw Flux-Fill
182
+ // effect=genfill defaults to WebP (12× lighter than the raw generated
185
183
  // PNG output with no visible loss at q=85). Explicit `format=png`
186
184
  // opts back into lossless for print / marketing fold-outs. The server
187
- // re-encodes Flux's PNG → target format before R2 cache.
185
+ // re-encodes the generated PNG → target format before caching.
188
186
  if (opts.effect === "genfill") {
189
187
  switch (opts.format) {
190
188
  case "png":
@@ -222,8 +220,8 @@ function extForOptions(opts: SignedTransformOptions): string {
222
220
  * Build a transform URL for a VIDEO asset. Same DSL shape as image
223
221
  * transforms; the server branches on the asset's `kind` column. Video
224
222
  * URLs use `.mp4` (default) or `.webm` extension and on cache miss the
225
- * server returns 202 Accepted while a Cloud Run Job encodes the clip;
226
- * subsequent GETs return 302 to the cached R2 object.
223
+ * server returns 202 Accepted while a background job encodes the clip;
224
+ * subsequent GETs return 302 to the cached object.
227
225
  *
228
226
  * <video src={aq.transformVideo(asset, { width: 1080, height: 1920 })}
229
227
  * autoPlay muted loop playsInline />
@@ -271,8 +269,8 @@ export function getVideoTransformUrl(
271
269
  * }
272
270
  * ```
273
271
  *
274
- * On first request the server returns 202 Accepted while a Cloud Run
275
- * Job transcodes the ladder (typically 1-3 min for a 90 s source);
272
+ * On first request the server returns 202 Accepted while a background
273
+ * job transcodes the ladder (typically 1-3 min for a 90 s source);
276
274
  * subsequent requests get 302 to the cached master.m3u8. Keep the
277
275
  * progressive MP4 as a fallback source for that window.
278
276
  *