@mux/ai 0.44.0 → 0.45.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.
@@ -33,12 +33,16 @@ var EnvSchema = z.object({
33
33
  ),
34
34
  MUX_SIGNING_KEY: optionalString("Mux signing key ID for signed playback URLs.", "Used to sign playback URLs"),
35
35
  MUX_PRIVATE_KEY: optionalString("Mux signing private key for signed playback URLs.", "Used to sign playback URLs"),
36
+ MUX_CUSTOM_DOMAIN: optionalString(
37
+ "Mux domain for image.* and stream.* playback URLs, e.g. staging.mux.com or a custom domain (defaults to mux.com).",
38
+ "Mux custom domain"
39
+ ),
36
40
  MUX_IMAGE_URL_OVERRIDE: optionalString(
37
- "Override for Mux image base URL (defaults to https://image.mux.com).",
41
+ "Deprecated: use MUX_CUSTOM_DOMAIN. Override for Mux image base URL (defaults to https://image.mux.com).",
38
42
  "Mux image URL override"
39
43
  ),
40
44
  MUX_STREAM_URL_OVERRIDE: optionalString(
41
- "Override for Mux stream base URL (defaults to https://stream.mux.com).",
45
+ "Deprecated: use MUX_CUSTOM_DOMAIN. Override for Mux stream base URL (defaults to https://stream.mux.com).",
42
46
  "Mux stream URL override"
43
47
  ),
44
48
  MUX_BASE_URL: optionalString(
@@ -157,7 +161,18 @@ function parseEnv() {
157
161
  }
158
162
  return parsedEnv.data;
159
163
  }
164
+ var hasWarnedAboutDeprecatedUrlOverrides = false;
165
+ function warnOnDeprecatedUrlOverrides(parsed) {
166
+ if (hasWarnedAboutDeprecatedUrlOverrides || !parsed.MUX_IMAGE_URL_OVERRIDE && !parsed.MUX_STREAM_URL_OVERRIDE) {
167
+ return;
168
+ }
169
+ hasWarnedAboutDeprecatedUrlOverrides = true;
170
+ console.warn(
171
+ "MUX_IMAGE_URL_OVERRIDE and MUX_STREAM_URL_OVERRIDE are deprecated and will be removed in a future release. Set MUX_CUSTOM_DOMAIN instead (e.g. MUX_CUSTOM_DOMAIN=staging.mux.com for image.staging.mux.com and stream.staging.mux.com)."
172
+ );
173
+ }
160
174
  var env = parseEnv();
175
+ warnOnDeprecatedUrlOverrides(env);
161
176
  var env_default = env;
162
177
 
163
178
  // src/lib/prompt-fragments.ts
@@ -1824,8 +1839,7 @@ function timeRangesOverlap(firstStart, firstEnd, second) {
1824
1839
  }
1825
1840
 
1826
1841
  // src/lib/mux-url.ts
1827
- var DEFAULT_MUX_IMAGE_ORIGIN = "https://image.mux.com";
1828
- var DEFAULT_MUX_STREAM_ORIGIN = "https://stream.mux.com";
1842
+ var DEFAULT_MUX_DOMAIN = "mux.com";
1829
1843
  function normalizeOrigin(value, envVarName) {
1830
1844
  const trimmed = value.trim();
1831
1845
  const candidate = trimmed.includes("://") ? trimmed : `https://${trimmed}`;
@@ -1845,29 +1859,56 @@ function normalizeOrigin(value, envVarName) {
1845
1859
  }
1846
1860
  return parsed.origin;
1847
1861
  }
1848
- function getMuxImageOrigin() {
1849
- const override = env_default.MUX_IMAGE_URL_OVERRIDE;
1850
- if (!override) {
1851
- return DEFAULT_MUX_IMAGE_ORIGIN;
1862
+ function buildPlaybackOrigin(service, customDomain, source) {
1863
+ const invalidDomainError = new Error(
1864
+ `Invalid ${source}. Provide a bare hostname (e.g. "media.example.com") with no scheme, port, credentials, query params, hash fragments, or path.`
1865
+ );
1866
+ const trimmed = customDomain.trim();
1867
+ if (!trimmed) {
1868
+ throw invalidDomainError;
1869
+ }
1870
+ let parsed;
1871
+ try {
1872
+ parsed = new URL(`https://${service}.${trimmed}`);
1873
+ } catch {
1874
+ throw invalidDomainError;
1875
+ }
1876
+ if (parsed.port || parsed.username || parsed.password || parsed.search || parsed.hash || parsed.pathname !== "/") {
1877
+ throw invalidDomainError;
1852
1878
  }
1853
- return normalizeOrigin(override, "MUX_IMAGE_URL_OVERRIDE");
1879
+ return parsed.origin;
1854
1880
  }
1855
- function getMuxStreamOrigin() {
1856
- const override = env_default.MUX_STREAM_URL_OVERRIDE;
1857
- if (!override) {
1858
- return DEFAULT_MUX_STREAM_ORIGIN;
1881
+ async function resolveMuxPlaybackOrigin(service, credentials) {
1882
+ "use step";
1883
+ const { muxCustomDomain } = await resolveWorkflowCredentials(credentials);
1884
+ if (muxCustomDomain) {
1885
+ return buildPlaybackOrigin(service, muxCustomDomain, "muxCustomDomain");
1859
1886
  }
1860
- return normalizeOrigin(override, "MUX_STREAM_URL_OVERRIDE");
1887
+ const legacyOverrideEnvVarName = service === "image" ? "MUX_IMAGE_URL_OVERRIDE" : "MUX_STREAM_URL_OVERRIDE";
1888
+ const legacyOverride = env_default[legacyOverrideEnvVarName];
1889
+ if (legacyOverride) {
1890
+ return normalizeOrigin(legacyOverride, legacyOverrideEnvVarName);
1891
+ }
1892
+ if (env_default.MUX_CUSTOM_DOMAIN) {
1893
+ return buildPlaybackOrigin(service, env_default.MUX_CUSTOM_DOMAIN, "MUX_CUSTOM_DOMAIN");
1894
+ }
1895
+ return buildPlaybackOrigin(service, DEFAULT_MUX_DOMAIN, "custom domain");
1896
+ }
1897
+ async function getMuxImageOrigin(credentials) {
1898
+ return resolveMuxPlaybackOrigin("image", credentials);
1899
+ }
1900
+ async function getMuxStreamOrigin(credentials) {
1901
+ return resolveMuxPlaybackOrigin("stream", credentials);
1861
1902
  }
1862
- function getMuxImageBaseUrl(playbackId, assetType) {
1863
- const origin = getMuxImageOrigin();
1903
+ async function getMuxImageBaseUrl(playbackId, assetType, credentials) {
1904
+ const origin = await getMuxImageOrigin(credentials);
1864
1905
  return `${origin}/${playbackId}/${assetType}.png`;
1865
1906
  }
1866
- function getMuxStoryboardBaseUrl(playbackId) {
1867
- return getMuxImageBaseUrl(playbackId, "storyboard");
1907
+ async function getMuxStoryboardBaseUrl(playbackId, credentials) {
1908
+ return getMuxImageBaseUrl(playbackId, "storyboard", credentials);
1868
1909
  }
1869
- function getMuxThumbnailBaseUrl(playbackId) {
1870
- return getMuxImageBaseUrl(playbackId, "thumbnail");
1910
+ async function getMuxThumbnailBaseUrl(playbackId, credentials) {
1911
+ return getMuxImageBaseUrl(playbackId, "thumbnail", credentials);
1871
1912
  }
1872
1913
 
1873
1914
  // src/lib/url-signing.ts
@@ -1911,7 +1952,7 @@ async function signUrl(url, playbackId, type = "video", params, credentials) {
1911
1952
  var DEFAULT_STORYBOARD_WIDTH = 640;
1912
1953
  async function getStoryboardUrl(playbackId, width = DEFAULT_STORYBOARD_WIDTH, shouldSign = false, credentials, scope) {
1913
1954
  "use step";
1914
- const baseUrl = getMuxStoryboardBaseUrl(playbackId);
1955
+ const baseUrl = await getMuxStoryboardBaseUrl(playbackId, credentials);
1915
1956
  const params = { width };
1916
1957
  if (scope?.startTime !== void 0) {
1917
1958
  params.asset_start_time = scope.startTime;
@@ -2473,7 +2514,7 @@ function concatenateVttSegments(segments, preamble = "WEBVTT") {
2473
2514
  }
2474
2515
  async function buildTranscriptUrl(playbackId, trackId, shouldSign = false, credentials) {
2475
2516
  "use step";
2476
- const baseUrl = `${getMuxStreamOrigin()}/${playbackId}/text/${trackId}.vtt`;
2517
+ const baseUrl = `${await getMuxStreamOrigin(credentials)}/${playbackId}/text/${trackId}.vtt`;
2477
2518
  if (shouldSign) {
2478
2519
  return signUrl(baseUrl, playbackId, "video", void 0, credentials);
2479
2520
  }
@@ -5722,7 +5763,7 @@ function mapShotsToHotspots(shots, hotspots) {
5722
5763
  }
5723
5764
  async function getThumbnailUrlsForHotspots(playbackId, hotspots, options = {}) {
5724
5765
  const { width = 640, shouldSign = false, credentials } = options;
5725
- const baseUrl = getMuxThumbnailBaseUrl(playbackId);
5766
+ const baseUrl = await getMuxThumbnailBaseUrl(playbackId, credentials);
5726
5767
  const urlPromises = hotspots.map(async (h) => {
5727
5768
  const time = Math.floor(h.startMs / 1e3);
5728
5769
  if (shouldSign) {
@@ -6823,7 +6864,7 @@ async function getThumbnailUrls(playbackId, duration, options = {}) {
6823
6864
  }
6824
6865
  timestamps = newTimestamps;
6825
6866
  }
6826
- const baseUrl = getMuxThumbnailBaseUrl(playbackId);
6867
+ const baseUrl = await getMuxThumbnailBaseUrl(playbackId, credentials);
6827
6868
  const urlPromises = timestamps.map(async (time) => {
6828
6869
  const url = shouldSign ? await signUrl(baseUrl, playbackId, "thumbnail", { time, width }, credentials) : `${baseUrl}?time=${time}&width=${width}`;
6829
6870
  return { url, time };
@@ -7287,7 +7328,7 @@ function filterTimestampsWithinExclusiveScope(timestampsMs, scope) {
7287
7328
  async function getThumbnailUrlsFromTimestamps(playbackId, timestampsMs, options) {
7288
7329
  "use step";
7289
7330
  const { width, shouldSign, credentials } = options;
7290
- const baseUrl = getMuxThumbnailBaseUrl(playbackId);
7331
+ const baseUrl = await getMuxThumbnailBaseUrl(playbackId, credentials);
7291
7332
  const times = [...new Set(timestampsMs.map(toThumbnailTimeSeconds))];
7292
7333
  const urlPromises = times.map(async (time) => {
7293
7334
  const url = shouldSign ? await signUrl(baseUrl, playbackId, "thumbnail", { time, width }, credentials) : `${baseUrl}?time=${time}&width=${width}`;
@@ -8471,7 +8512,7 @@ async function translateAudio(assetId, toLanguageCode, options = {}) {
8471
8512
  { type: "validation_error" }
8472
8513
  );
8473
8514
  }
8474
- let audioUrl = `${getMuxStreamOrigin()}/${playbackId}/audio.m4a`;
8515
+ let audioUrl = `${await getMuxStreamOrigin(credentials)}/${playbackId}/audio.m4a`;
8475
8516
  if (policy === "signed") {
8476
8517
  audioUrl = await signUrl(audioUrl, playbackId, "video", void 0, credentials);
8477
8518
  }