@nitida/asset-client 0.20.3 → 0.21.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/dist/index.cjs +9 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +67 -5
package/dist/index.d.cts
CHANGED
|
@@ -770,6 +770,15 @@ declare function hlsLadderAlignment(rungs: HlsRung[]): {
|
|
|
770
770
|
*/
|
|
771
771
|
type AssetDTO = {
|
|
772
772
|
id: string;
|
|
773
|
+
/**
|
|
774
|
+
* ⭐ The same value as `id`, under the name the WRITE side uses.
|
|
775
|
+
*
|
|
776
|
+
* `upload()` returns `assetId`; the read endpoints returned only `id`, so
|
|
777
|
+
* what `assets.byHash()` handed back could not be fed to `assets.get()`
|
|
778
|
+
* without renaming a field. Optional here because a DTO produced by an older
|
|
779
|
+
* server will not carry it — read `dto.assetId ?? dto.id`.
|
|
780
|
+
*/
|
|
781
|
+
assetId?: string;
|
|
773
782
|
/** First 16 hex chars of sha256 — used to derive CDN URLs. */
|
|
774
783
|
sha: string;
|
|
775
784
|
kind: "image" | "video" | "document" | "audio" | "other";
|
|
@@ -841,6 +850,13 @@ type OriginalHints = {
|
|
|
841
850
|
oext?: string | null;
|
|
842
851
|
/** Full variant list — carries the stored URL verbatim. Authoritative. */
|
|
843
852
|
variants?: AssetVariant[];
|
|
853
|
+
/**
|
|
854
|
+
* What the asset IS. Optional because these builders accept a minimal
|
|
855
|
+
* `{ sha }`, and absent means "we cannot know" — never "assume the worst".
|
|
856
|
+
* Used to refuse `hls` on something that can never have a ladder; see the
|
|
857
|
+
* `hls` branch of `getAssetUrl`.
|
|
858
|
+
*/
|
|
859
|
+
kind?: AssetDTO["kind"];
|
|
844
860
|
};
|
|
845
861
|
/**
|
|
846
862
|
* Build the public CDN URL for a specific variant of an asset. The variant
|
|
@@ -959,7 +975,9 @@ declare function getPrivateTransformUrl(asset: Pick<AssetDTO, "sha">, opts: Sign
|
|
|
959
975
|
* hasPreset({ presets: "pv" }, "aiproxy"); // → false — video without the AI proxy
|
|
960
976
|
* ```
|
|
961
977
|
*/
|
|
962
|
-
declare function hasPreset(asset:
|
|
978
|
+
declare function hasPreset(asset: {
|
|
979
|
+
presets?: string | null;
|
|
980
|
+
}, preset: VariantPreset): boolean;
|
|
963
981
|
declare function getAssetSrcSet(asset: Pick<AssetDTO, "sha" | "presets"> & VisibilityHint): string;
|
|
964
982
|
/**
|
|
965
983
|
* Compute the dimensions a variant would have given the source asset's
|
package/dist/index.d.ts
CHANGED
|
@@ -770,6 +770,15 @@ declare function hlsLadderAlignment(rungs: HlsRung[]): {
|
|
|
770
770
|
*/
|
|
771
771
|
type AssetDTO = {
|
|
772
772
|
id: string;
|
|
773
|
+
/**
|
|
774
|
+
* ⭐ The same value as `id`, under the name the WRITE side uses.
|
|
775
|
+
*
|
|
776
|
+
* `upload()` returns `assetId`; the read endpoints returned only `id`, so
|
|
777
|
+
* what `assets.byHash()` handed back could not be fed to `assets.get()`
|
|
778
|
+
* without renaming a field. Optional here because a DTO produced by an older
|
|
779
|
+
* server will not carry it — read `dto.assetId ?? dto.id`.
|
|
780
|
+
*/
|
|
781
|
+
assetId?: string;
|
|
773
782
|
/** First 16 hex chars of sha256 — used to derive CDN URLs. */
|
|
774
783
|
sha: string;
|
|
775
784
|
kind: "image" | "video" | "document" | "audio" | "other";
|
|
@@ -841,6 +850,13 @@ type OriginalHints = {
|
|
|
841
850
|
oext?: string | null;
|
|
842
851
|
/** Full variant list — carries the stored URL verbatim. Authoritative. */
|
|
843
852
|
variants?: AssetVariant[];
|
|
853
|
+
/**
|
|
854
|
+
* What the asset IS. Optional because these builders accept a minimal
|
|
855
|
+
* `{ sha }`, and absent means "we cannot know" — never "assume the worst".
|
|
856
|
+
* Used to refuse `hls` on something that can never have a ladder; see the
|
|
857
|
+
* `hls` branch of `getAssetUrl`.
|
|
858
|
+
*/
|
|
859
|
+
kind?: AssetDTO["kind"];
|
|
844
860
|
};
|
|
845
861
|
/**
|
|
846
862
|
* Build the public CDN URL for a specific variant of an asset. The variant
|
|
@@ -959,7 +975,9 @@ declare function getPrivateTransformUrl(asset: Pick<AssetDTO, "sha">, opts: Sign
|
|
|
959
975
|
* hasPreset({ presets: "pv" }, "aiproxy"); // → false — video without the AI proxy
|
|
960
976
|
* ```
|
|
961
977
|
*/
|
|
962
|
-
declare function hasPreset(asset:
|
|
978
|
+
declare function hasPreset(asset: {
|
|
979
|
+
presets?: string | null;
|
|
980
|
+
}, preset: VariantPreset): boolean;
|
|
963
981
|
declare function getAssetSrcSet(asset: Pick<AssetDTO, "sha" | "presets"> & VisibilityHint): string;
|
|
964
982
|
/**
|
|
965
983
|
* Compute the dimensions a variant would have given the source asset's
|
package/dist/index.js
CHANGED
|
@@ -615,6 +615,11 @@ function buildPublicAssetUrl(asset, preset, caller) {
|
|
|
615
615
|
if (preset === "hls") {
|
|
616
616
|
const stored = asset.variants?.find((v) => v.preset === "hls")?.url;
|
|
617
617
|
if (stored) return stored;
|
|
618
|
+
if (asset.kind != null && asset.kind !== "video") {
|
|
619
|
+
throw new Error(
|
|
620
|
+
`${caller}: this asset is \`${asset.kind}\`, and only a video has an HLS ladder. Asking for \`hls\` here would build \`/t/format=hls/<sha>.m3u8\`, which does NOT 404 \u2014 the edge answers 200 with the image bytes under an .m3u8 name, so a player fails with no way to see why. For an image use a size preset (\`${caller}(asset, "md")\`) or a transform (\`getTransformUrl\`); for audio use \`mp3\`.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
618
623
|
return `${cdnBaseUrl}/t/format=hls/${asset.sha}.m3u8`;
|
|
619
624
|
}
|
|
620
625
|
return `${cdnBaseUrl}/${variantPrefix(caller)}${asset.sha}-${PRESET_SHORT[preset]}.${PRESET_EXT[preset]}`;
|
|
@@ -643,11 +648,12 @@ async function getPrivateTransformUrl(asset, opts, signingKey, signOpts) {
|
|
|
643
648
|
);
|
|
644
649
|
}
|
|
645
650
|
function hasPreset(asset, preset) {
|
|
646
|
-
|
|
647
|
-
return
|
|
651
|
+
const presets = asset.presets ?? "";
|
|
652
|
+
if (preset === "mp3") return presets.includes("mp3");
|
|
653
|
+
return stripMultiCharTokens(presets).includes(PRESET_SHORT[preset]);
|
|
648
654
|
}
|
|
649
655
|
function stripMultiCharTokens(presets) {
|
|
650
|
-
return presets.replace(/transform-[0-9a-f]*/g, "").replace(/upscale_[a-z0-9_]*/g, "").replace(/mp3/g, "").replace(/u[2-8]|t[1248ghij]/g, "").replace(/pr/g, "");
|
|
656
|
+
return (presets ?? "").replace(/transform-[0-9a-f]*/g, "").replace(/upscale_[a-z0-9_]*/g, "").replace(/mp3/g, "").replace(/u[2-8]|t[1248ghij]/g, "").replace(/pr/g, "");
|
|
651
657
|
}
|
|
652
658
|
var IMAGE_PRESETS = ["thumb", "sm", "md", "lg", "xl"];
|
|
653
659
|
function getAssetSrcSet(asset) {
|