@mux/ai 0.7.4 → 0.7.6

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.
@@ -1,3 +1,3 @@
1
- export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, b as Hotspot, c as HotspotOptions, d as HotspotResponse, T as ThumbnailOptions, e as TranscriptFetchOptions, f as TranscriptResult, V as VTTCue, g as buildTranscriptUrl, h as chunkByTokens, j as chunkText, k as chunkVTTCues, l as estimateTokenCount, m as extractTextFromVTT, n as extractTimestampedTranscript, o as fetchTranscriptForAsset, p as findCaptionTrack, q as getHeatmapForAsset, r as getHeatmapForPlaybackId, s as getHeatmapForVideo, t as getHotspotsForAsset, u as getHotspotsForPlaybackId, v as getHotspotsForVideo, w as getReadyTextTracks, x as getStoryboardUrl, y as getThumbnailUrls, z as parseVTTCues, A as secondsToTimestamp, B as vttTimestampToSeconds } from '../index-DZlygsvb.js';
2
- import '../types-BQVi_wnh.js';
1
+ export { D as DEFAULT_STORYBOARD_WIDTH, H as HeatmapOptions, a as HeatmapResponse, b as Hotspot, c as HotspotOptions, d as HotspotResponse, T as ThumbnailOptions, e as TranscriptFetchOptions, f as TranscriptResult, V as VTTCue, g as buildTranscriptUrl, h as chunkByTokens, j as chunkText, k as chunkVTTCues, l as estimateTokenCount, m as extractTextFromVTT, n as extractTimestampedTranscript, o as fetchTranscriptForAsset, p as findCaptionTrack, q as getHeatmapForAsset, r as getHeatmapForPlaybackId, s as getHeatmapForVideo, t as getHotspotsForAsset, u as getHotspotsForPlaybackId, v as getHotspotsForVideo, w as getReadyTextTracks, x as getStoryboardUrl, y as getThumbnailUrls, z as parseVTTCues, A as secondsToTimestamp, B as vttTimestampToSeconds } from '../index-Nxf6BaBO.js';
2
+ import '../types-BRbaGW3t.js';
3
3
  import '@mux/mux-node';
@@ -26,6 +26,10 @@ var EnvSchema = z.object({
26
26
  ),
27
27
  MUX_SIGNING_KEY: optionalString("Mux signing key ID for signed playback URLs.", "Used to sign playback URLs"),
28
28
  MUX_PRIVATE_KEY: optionalString("Mux signing private key for signed playback URLs.", "Used to sign playback URLs"),
29
+ MUX_IMAGE_URL_OVERRIDE: optionalString(
30
+ "Override for Mux image base URL (defaults to https://image.mux.com).",
31
+ "Mux image URL override"
32
+ ),
29
33
  // Test-only helpers (used by this repo's integration tests)
30
34
  MUX_TEST_ASSET_ID: optionalString("Mux asset ID used by integration tests.", "Mux test asset id"),
31
35
  MUX_TEST_ASSET_ID_CHAPTERS: optionalString("Mux asset ID used by integration tests for chapters.", "Mux test asset id for chapters"),
@@ -312,12 +316,13 @@ function readString(record, key) {
312
316
  function resolveDirectMuxCredentials(record) {
313
317
  const tokenId = readString(record, "muxTokenId");
314
318
  const tokenSecret = readString(record, "muxTokenSecret");
319
+ const authorizationToken = readString(record, "muxAuthorizationToken");
315
320
  const signingKey = readString(record, "muxSigningKey");
316
321
  const privateKey = readString(record, "muxPrivateKey");
317
- if (!tokenId && !tokenSecret && !signingKey && !privateKey) {
322
+ if (!tokenId && !tokenSecret && !authorizationToken && !signingKey && !privateKey) {
318
323
  return void 0;
319
324
  }
320
- if (!tokenId || !tokenSecret) {
325
+ if ((!tokenId || !tokenSecret) && !authorizationToken) {
321
326
  throw new Error(
322
327
  "Both muxTokenId and muxTokenSecret are required when passing direct Mux workflow credentials."
323
328
  );
@@ -325,6 +330,7 @@ function resolveDirectMuxCredentials(record) {
325
330
  return {
326
331
  tokenId,
327
332
  tokenSecret,
333
+ authorizationToken,
328
334
  signingKey,
329
335
  privateKey
330
336
  };
@@ -335,7 +341,8 @@ function createWorkflowMuxClient(options) {
335
341
  const { default: MuxClient } = await import("@mux/mux-node");
336
342
  return new MuxClient({
337
343
  tokenId: options.tokenId,
338
- tokenSecret: options.tokenSecret
344
+ tokenSecret: options.tokenSecret,
345
+ authorizationToken: options.authorizationToken
339
346
  });
340
347
  },
341
348
  getSigningKey() {
@@ -548,6 +555,44 @@ async function fetchHotspots(identifierType, id, options) {
548
555
  return transformHotspotResponse(response);
549
556
  }
550
557
 
558
+ // src/lib/mux-image-url.ts
559
+ var DEFAULT_MUX_IMAGE_ORIGIN = "https://image.mux.com";
560
+ function normalizeMuxImageOrigin(value) {
561
+ const trimmed = value.trim();
562
+ const candidate = trimmed.includes("://") ? trimmed : `https://${trimmed}`;
563
+ let parsed;
564
+ try {
565
+ parsed = new URL(candidate);
566
+ } catch {
567
+ throw new Error(
568
+ `Invalid MUX_IMAGE_URL_OVERRIDE. Provide a hostname like "image.example.mux.com" (or a URL origin such as "https://image.example.mux.com").`
569
+ );
570
+ }
571
+ if (parsed.username || parsed.password || parsed.search || parsed.hash || parsed.pathname && parsed.pathname !== "/") {
572
+ throw new Error(
573
+ "Invalid MUX_IMAGE_URL_OVERRIDE. Only a hostname/origin is allowed (no credentials, query params, hash fragments, or path)."
574
+ );
575
+ }
576
+ return parsed.origin;
577
+ }
578
+ function getMuxImageOrigin() {
579
+ const override = env_default.MUX_IMAGE_URL_OVERRIDE;
580
+ if (!override) {
581
+ return DEFAULT_MUX_IMAGE_ORIGIN;
582
+ }
583
+ return normalizeMuxImageOrigin(override);
584
+ }
585
+ function getMuxImageBaseUrl(playbackId, assetType) {
586
+ const origin = getMuxImageOrigin();
587
+ return `${origin}/${playbackId}/${assetType}.png`;
588
+ }
589
+ function getMuxStoryboardBaseUrl(playbackId) {
590
+ return getMuxImageBaseUrl(playbackId, "storyboard");
591
+ }
592
+ function getMuxThumbnailBaseUrl(playbackId) {
593
+ return getMuxImageBaseUrl(playbackId, "thumbnail");
594
+ }
595
+
551
596
  // src/lib/url-signing.ts
552
597
  async function createSigningClient(context) {
553
598
  const { default: MuxClient } = await import("@mux/mux-node");
@@ -572,9 +617,9 @@ async function signPlaybackId(playbackId, context, type = "video", params) {
572
617
  params: stringParams
573
618
  });
574
619
  }
575
- async function signUrl(url, playbackId, context, type = "video", params, credentials) {
620
+ async function signUrl(url, playbackId, type = "video", params, credentials) {
576
621
  "use step";
577
- const resolvedContext = context ?? await resolveMuxSigningContext(credentials);
622
+ const resolvedContext = await resolveMuxSigningContext(credentials);
578
623
  if (!resolvedContext) {
579
624
  throw new Error(
580
625
  "Signed playback ID requires signing credentials. Provide muxSigningKey and muxPrivateKey via workflow credentials or set MUX_SIGNING_KEY and MUX_PRIVATE_KEY environment variables."
@@ -589,9 +634,9 @@ async function signUrl(url, playbackId, context, type = "video", params, credent
589
634
  var DEFAULT_STORYBOARD_WIDTH = 640;
590
635
  async function getStoryboardUrl(playbackId, width = DEFAULT_STORYBOARD_WIDTH, shouldSign = false, credentials) {
591
636
  "use step";
592
- const baseUrl = `https://image.mux.com/${playbackId}/storyboard.png`;
637
+ const baseUrl = getMuxStoryboardBaseUrl(playbackId);
593
638
  if (shouldSign) {
594
- return signUrl(baseUrl, playbackId, void 0, "storyboard", { width }, credentials);
639
+ return signUrl(baseUrl, playbackId, "storyboard", { width }, credentials);
595
640
  }
596
641
  return `${baseUrl}?width=${width}`;
597
642
  }
@@ -708,10 +753,10 @@ async function getThumbnailUrls(playbackId, duration, options = {}) {
708
753
  }
709
754
  timestamps = newTimestamps;
710
755
  }
711
- const baseUrl = `https://image.mux.com/${playbackId}/thumbnail.png`;
756
+ const baseUrl = getMuxThumbnailBaseUrl(playbackId);
712
757
  const urlPromises = timestamps.map(async (time) => {
713
758
  if (shouldSign) {
714
- return signUrl(baseUrl, playbackId, void 0, "thumbnail", { time, width }, credentials);
759
+ return signUrl(baseUrl, playbackId, "thumbnail", { time, width }, credentials);
715
760
  }
716
761
  return `${baseUrl}?time=${time}&width=${width}`;
717
762
  });
@@ -840,7 +885,7 @@ async function buildTranscriptUrl(playbackId, trackId, shouldSign = false, crede
840
885
  "use step";
841
886
  const baseUrl = `https://stream.mux.com/${playbackId}/text/${trackId}.vtt`;
842
887
  if (shouldSign) {
843
- return signUrl(baseUrl, playbackId, void 0, "video", void 0, credentials);
888
+ return signUrl(baseUrl, playbackId, "video", void 0, credentials);
844
889
  }
845
890
  return baseUrl;
846
891
  }