sanity-plugin-mux-input 3.0.4 → 4.0.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.
Files changed (130) hide show
  1. package/README.md +0 -2
  2. package/dist/index.d.ts +134 -193
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +2893 -4417
  5. package/dist/index.js.map +1 -1
  6. package/package.json +33 -43
  7. package/dist/index.cjs +0 -7270
  8. package/dist/index.cjs.map +0 -1
  9. package/dist/index.d.cts +0 -347
  10. package/sanity.json +0 -8
  11. package/src/_exports/index.ts +0 -73
  12. package/src/actions/assets.ts +0 -152
  13. package/src/actions/secrets.ts +0 -111
  14. package/src/actions/upload.ts +0 -310
  15. package/src/clients/upChunkObservable.ts +0 -54
  16. package/src/components/AddCaptionDialog.tsx +0 -440
  17. package/src/components/CaptionsDialog.tsx +0 -23
  18. package/src/components/ConfigureApi.styled.tsx +0 -19
  19. package/src/components/ConfigureApi.tsx +0 -296
  20. package/src/components/DraggableWatermark.tsx +0 -877
  21. package/src/components/EditCaptionDialog.tsx +0 -510
  22. package/src/components/EditThumbnailDialog.tsx +0 -122
  23. package/src/components/ErrorBoundaryCard.tsx +0 -96
  24. package/src/components/FileInputButton.tsx +0 -54
  25. package/src/components/FileInputMenuItem.styled.tsx +0 -36
  26. package/src/components/FileInputMenuItem.tsx +0 -85
  27. package/src/components/FormField.tsx +0 -38
  28. package/src/components/IconInfo.tsx +0 -22
  29. package/src/components/ImportVideosFromMux.tsx +0 -342
  30. package/src/components/Input.styled.tsx +0 -22
  31. package/src/components/Input.tsx +0 -78
  32. package/src/components/InputBrowser.tsx +0 -41
  33. package/src/components/InputError.tsx +0 -17
  34. package/src/components/MuxLogo.tsx +0 -42
  35. package/src/components/Onboard.tsx +0 -65
  36. package/src/components/PageSelector.tsx +0 -54
  37. package/src/components/Player.styled.tsx +0 -55
  38. package/src/components/Player.tsx +0 -117
  39. package/src/components/PlayerActionsMenu.tsx +0 -190
  40. package/src/components/ResyncMetadata.tsx +0 -280
  41. package/src/components/SelectAsset.tsx +0 -39
  42. package/src/components/SelectSortOptions.tsx +0 -45
  43. package/src/components/SpinnerBox.tsx +0 -16
  44. package/src/components/StudioTool.tsx +0 -24
  45. package/src/components/TextTracksEditor.tsx +0 -117
  46. package/src/components/TextTracksManager.tsx +0 -737
  47. package/src/components/UploadConfiguration.tsx +0 -694
  48. package/src/components/UploadPlaceholder.tsx +0 -88
  49. package/src/components/UploadProgress.tsx +0 -80
  50. package/src/components/Uploader.styled.tsx +0 -66
  51. package/src/components/Uploader.tsx +0 -498
  52. package/src/components/VideoDetails/DeleteDialog.tsx +0 -147
  53. package/src/components/VideoDetails/VideoDetails.tsx +0 -358
  54. package/src/components/VideoDetails/VideoReferences.tsx +0 -63
  55. package/src/components/VideoDetails/useVideoDetails.ts +0 -103
  56. package/src/components/VideoInBrowser.tsx +0 -245
  57. package/src/components/VideoMetadata.tsx +0 -45
  58. package/src/components/VideoPlayer.tsx +0 -235
  59. package/src/components/VideoThumbnail.tsx +0 -138
  60. package/src/components/VideosBrowser.tsx +0 -100
  61. package/src/components/documentPreview/DocumentPreview.tsx +0 -83
  62. package/src/components/documentPreview/DraftStatus.tsx +0 -34
  63. package/src/components/documentPreview/MissingSchemaType.tsx +0 -32
  64. package/src/components/documentPreview/PaneItemPreview.tsx +0 -74
  65. package/src/components/documentPreview/PublishedStatus.tsx +0 -35
  66. package/src/components/documentPreview/TimeAgo.tsx +0 -12
  67. package/src/components/documentPreview/paneItemTypes.ts +0 -7
  68. package/src/components/icons/Audio.tsx +0 -13
  69. package/src/components/icons/Resolution.tsx +0 -12
  70. package/src/components/icons/StopWatch.tsx +0 -20
  71. package/src/components/icons/ToolIcon.tsx +0 -19
  72. package/src/components/uploadConfiguration/PlaybackPolicy.tsx +0 -133
  73. package/src/components/uploadConfiguration/PlaybackPolicyOption.tsx +0 -76
  74. package/src/components/uploadConfiguration/PlaybackPolicyWarning.tsx +0 -29
  75. package/src/components/uploadConfiguration/ResolutionTierSelector.tsx +0 -72
  76. package/src/components/uploadConfiguration/StaticRenditionSelector.tsx +0 -180
  77. package/src/components/withFocusRing/helpers.ts +0 -24
  78. package/src/components/withFocusRing/index.ts +0 -1
  79. package/src/components/withFocusRing/withFocusRing.ts +0 -30
  80. package/src/context/DialogStateContext.tsx +0 -36
  81. package/src/context/DrmPlaybackWarningContext.tsx +0 -93
  82. package/src/hooks/useAccessControl.ts +0 -13
  83. package/src/hooks/useAssetDocumentValues.ts +0 -11
  84. package/src/hooks/useAssets.ts +0 -68
  85. package/src/hooks/useCancelUpload.ts +0 -22
  86. package/src/hooks/useClient.ts +0 -8
  87. package/src/hooks/useDialogState.ts +0 -11
  88. package/src/hooks/useDocReferences.ts +0 -21
  89. package/src/hooks/useFetchFileSize.ts +0 -54
  90. package/src/hooks/useImportMuxAssets.ts +0 -132
  91. package/src/hooks/useInView.ts +0 -42
  92. package/src/hooks/useMediaMetadata.ts +0 -103
  93. package/src/hooks/useMuxAssets.ts +0 -179
  94. package/src/hooks/useMuxPolling.ts +0 -49
  95. package/src/hooks/useResyncAsset.ts +0 -110
  96. package/src/hooks/useResyncMuxMetadata.ts +0 -176
  97. package/src/hooks/useSaveSecrets.ts +0 -78
  98. package/src/hooks/useSecretsDocumentValues.ts +0 -38
  99. package/src/hooks/useSecretsFormState.ts +0 -47
  100. package/src/plugin.tsx +0 -31
  101. package/src/sanity-ui.d.ts +0 -5
  102. package/src/schema.ts +0 -196
  103. package/src/util/addKeysToMuxData.ts +0 -30
  104. package/src/util/areSecretsSignable.ts +0 -5
  105. package/src/util/asserters.ts +0 -36
  106. package/src/util/assetTitlePlaceholder.ts +0 -31
  107. package/src/util/constants.ts +0 -15
  108. package/src/util/convertWatermarkToMux.ts +0 -160
  109. package/src/util/createSearchFilter.ts +0 -76
  110. package/src/util/createUrlParamsObject.ts +0 -29
  111. package/src/util/extractFiles.ts +0 -67
  112. package/src/util/formatBytes.ts +0 -32
  113. package/src/util/formatDriveShareLink.ts +0 -64
  114. package/src/util/formatSeconds.ts +0 -49
  115. package/src/util/generateJwt.ts +0 -57
  116. package/src/util/getAnimatedPosterSrc.ts +0 -26
  117. package/src/util/getPlaybackPolicy.ts +0 -69
  118. package/src/util/getPosterSrc.ts +0 -28
  119. package/src/util/getStoryboardSrc.ts +0 -27
  120. package/src/util/getVideoMetadata.ts +0 -23
  121. package/src/util/getVideoSrc.ts +0 -23
  122. package/src/util/isSigned.ts +0 -20
  123. package/src/util/parsers.ts +0 -5
  124. package/src/util/pluginVersion.ts +0 -1
  125. package/src/util/readSecrets.ts +0 -38
  126. package/src/util/roundPxString.ts +0 -16
  127. package/src/util/textTracks.ts +0 -222
  128. package/src/util/tryWithSuspend.ts +0 -22
  129. package/src/util/types.ts +0 -596
  130. package/v2-incompatible.js +0 -11
package/dist/index.d.cts DELETED
@@ -1,347 +0,0 @@
1
- import type MuxPlayerElement from "@mux/mux-player";
2
- import type { PartialDeep } from "type-fest";
3
- import { Plugin as Plugin_2 } from "sanity";
4
-
5
- export declare const defaultConfig: PluginConfig;
6
-
7
- declare interface MuxAsset {
8
- id: string;
9
- /** In seconds (instead of JS's default milliseconds) */
10
- created_at: string;
11
- status: "preparing" | "ready" | "errored";
12
- duration: number;
13
- max_stored_resolution: "Audio only" | "SD" | "HD" | "FHD" | "UHD";
14
- max_stored_frame_rate: -1 | number;
15
- aspect_ratio: `${number}:${number}`;
16
- playback_ids: MuxPlaybackId[];
17
- tracks: MuxTrack[];
18
- errors?: MuxErrors;
19
- upload_id: string;
20
- is_live?: boolean;
21
- passthrough: string;
22
- live_stream_id?: string;
23
- master?: {
24
- status: "ready" | "preparing" | "errored";
25
- url: string;
26
- };
27
- master_access: "temporary" | "none";
28
- mp4_support: "standard" | "none";
29
- source_asset_id?: string;
30
- normalize_audio?: boolean;
31
- static_renditions?: {
32
- status: "ready" | "preparing" | "disabled" | "errored";
33
- files: {
34
- name: string;
35
- ext: "mp4" | "m4a";
36
- height: number;
37
- width: number;
38
- bitrate: number;
39
- filesize: string;
40
- type: "standard" | "advanced";
41
- status: "ready" | "preparing" | "skipped" | "errored";
42
- resolution_tier?: string;
43
- resolution?: string;
44
- id: string;
45
- passthrough?: string;
46
- }[];
47
- };
48
- recording_times?: {
49
- started_at: string;
50
- duration: number;
51
- type: "content" | "slate";
52
- }[];
53
- non_standard_input_reasons?: {
54
- video_codec?: string;
55
- audio_codec?: string;
56
- video_gop_size?: "high";
57
- video_frame_rate?: string;
58
- video_resolution?: string;
59
- video_bitrate?: "high";
60
- pixel_aspect_ratio?: string;
61
- video_edit_list?: "non-standard";
62
- audio_edit_list?: "non-standard";
63
- unexpected_media_file_parameters?: "non-standard";
64
- test?: boolean;
65
- };
66
- meta?: {
67
- title?: string;
68
- };
69
- }
70
-
71
- declare interface MuxAudioTrack {
72
- type: "audio";
73
- id: string;
74
- duration?: number;
75
- max_channels: number;
76
- max_channel_layout: "stereo" | string;
77
- }
78
-
79
- declare interface MuxErrors {
80
- type: string;
81
- messages: string[];
82
- }
83
-
84
- export declare const muxInput: Plugin_2<void | Partial<PluginConfig>>;
85
-
86
- declare interface MuxInputConfig {
87
- /**
88
- * Enable static renditions by default. Can be overwritten on a per-asset basis.
89
- * Supports:
90
- * - Standard mode: 'highest' (up to 4K MP4) and/or 'audio-only' (M4A)
91
- * - Advanced mode: Specific resolutions ('270p', '360p', '480p', '540p', '720p', '1080p', '1440p', '2160p') and/or 'audio-only'
92
- *
93
- * **Important**: 'highest' cannot be mixed with specific resolutions. If both are provided, only 'highest' will be used.
94
- *
95
- * @see {@link https://docs.mux.com/guides/video/enable-static-mp4-renditions}
96
- * @defaultValue []
97
- */
98
- static_renditions: StaticRenditionResolution[];
99
- /**
100
- * @deprecated Use `static_renditions` instead. This field is kept for backward compatibility.
101
- * Enable static renditions by setting this to 'standard'. Can be overwritten on a per-asset basis.
102
- * Requires `"video_quality": "plus"`
103
- * @see {@link https://docs.mux.com/guides/video/enable-static-mp4-renditions#why-enable-mp4-support}
104
- * @defaultValue 'none'
105
- */
106
- mp4_support: "none" | "standard";
107
- /**
108
- * Max resolution tier can be used to control the maximum resolution_tier your asset is encoded, stored, and streamed at.
109
- * Requires `"video_quality": "plus"`
110
- * @see {@link https://docs.mux.com/guides/stream-videos-in-4k}
111
- * @defaultValue '1080p'
112
- */
113
- max_resolution_tier: "2160p" | "1440p" | "1080p";
114
- /**
115
- * @deprecated Use {@link video_quality}
116
- * <br>
117
- * The encoding tier informs the cost, quality, and available platform features for the asset.
118
- * @see {@link https://docs.mux.com/guides/use-encoding-tiers}
119
- * @defaultValue 'smart'
120
- */
121
- encoding_tier?: "baseline" | "smart";
122
- /**
123
- * The video quality level informs the cost, quality, and available platform features for the asset.
124
- * @see {@link https://www.mux.com/docs/guides/use-video-quality-levels}
125
- * @defaultValue 'plus'
126
- */
127
- video_quality: "basic" | "plus" | "premium";
128
- /**
129
- * Normalize the audio track loudness level.
130
- * @see {@link https://docs.mux.com/guides/adjust-audio-levels#how-to-turn-on-audio-normalization}
131
- * @defaultValue false
132
- */
133
- normalize_audio: boolean;
134
- /**
135
- * Enables signed URLs by default, if you configured them with your API token.
136
- * @see {@link https://docs.mux.com/guides/secure-video-playback}
137
- * @defaultValue false
138
- */
139
- defaultSigned?: boolean;
140
- /**
141
- * Enables public URLs by default.
142
- * @defaultValue true
143
- */
144
- defaultPublic?: boolean;
145
- /**
146
- * Enables DRM Protection by default, if you configured your DRM Configuration Id.
147
- * @see {@link https://www.mux.com/docs/guides/protect-videos-with-drm}
148
- * @defaultValue true
149
- */
150
- defaultDrm?: boolean;
151
- /**
152
- * Auto-generate captions for these languages by default.
153
- * Requires `"video_quality": "plus"`
154
- *
155
- * @see {@link https://docs.mux.com/guides/add-autogenerated-captions-and-use-transcripts}
156
- * @deprecated use `defaultAutogeneratedSubtitleLang` instead. Only a single autogenerated
157
- */
158
- defaultAutogeneratedSubtitleLangs?: SupportedMuxLanguage[];
159
- /**
160
- * Auto-generate captions for this language by default. Users can still
161
- * Requires `"video_quality": "plus"`
162
- *
163
- * @see {@link https://docs.mux.com/guides/add-autogenerated-captions-and-use-transcripts}
164
- */
165
- defaultAutogeneratedSubtitleLang?: SupportedMuxLanguage;
166
- /**
167
- * Whether or not to allow content editors to override asset upload
168
- * configuration settings when uploading a video to Mux.
169
- *
170
- * @see {@link https://docs.mux.com/guides/secure-video-playback}
171
- * @defaultValue false
172
- */
173
- disableUploadConfig?: boolean;
174
- /**
175
- * Whether or not to allow content editors to add text tracks alongside their
176
- * asset when uploading a video to Mux.
177
- *
178
- * @see {@link https://docs.mux.com/guides/secure-video-playback}
179
- * @defaultValue false
180
- */
181
- disableTextTrackConfig?: boolean;
182
- /**
183
- * Whether or not to show the playback warning when trying to watch DRM content for the first time.
184
- *
185
- * @defaultValue false
186
- */
187
- disableDrmPlaybackWarning?: boolean;
188
- /**
189
- * The mime types that are accepted by the input.
190
- *
191
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/accept}
192
- * @defaultValue ['video/*','audio/*']
193
-
194
- */
195
- acceptedMimeTypes?: ("audio/*" | "video/*")[];
196
- /**
197
- * Maximum file size allowed for video uploads in bytes.
198
- * If not specified, no file size validation will be performed.
199
- *
200
- * @example 1024 * 1024 * 1024 // 1 GB
201
- * @defaultValue undefined
202
- */
203
- maxAssetFileSize?: number;
204
- /**
205
- * Maximum video duration allowed in seconds.
206
- * If not specified, no duration validation will be performed.
207
- *
208
- * @example 2 * 60 * 60 // 2 hours
209
- * @defaultValue undefined
210
- */
211
- maxAssetDuration?: number;
212
- /**
213
- * HLS.js configuration options to be passed to the Mux Player.
214
- * These options allow you to customize the underlying HLS.js playback engine behavior.
215
- *
216
- * @see {@link https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning}
217
- * @defaultValue undefined
218
- * @example
219
- * ```ts
220
- * {
221
- * maxBufferLength: 30,
222
- * lowLatencyMode: true,
223
- * capLevelToPlayerSize: true
224
- * }
225
- * ```
226
- */
227
- hlsConfig?: MuxPlayerElement["_hlsConfig"];
228
- }
229
-
230
- declare interface MuxPlaybackId {
231
- id: string;
232
- policy: PlaybackPolicy;
233
- }
234
-
235
- declare interface MuxTextTrack {
236
- type: "text";
237
- id: string;
238
- text_type?: "subtitles";
239
- text_source?:
240
- | "uploaded"
241
- | "embedded"
242
- | "generated_live"
243
- | "generated_live_final"
244
- | "generated_vod";
245
- language_code?: "en" | "en-US" | string;
246
- name?: "English" | string;
247
- closed_captions?: boolean;
248
- passthrough?: string;
249
- status: "preparing" | "ready" | "errored";
250
- error?: {
251
- type: string;
252
- messages?: string[];
253
- };
254
- }
255
-
256
- declare type MuxTrack = MuxVideoTrack | MuxAudioTrack | MuxTextTrack;
257
-
258
- declare interface MuxVideoTrack {
259
- type: "video";
260
- id: string;
261
- max_width: number;
262
- max_height: number;
263
- max_frame_rate: -1 | number;
264
- duration?: number;
265
- }
266
-
267
- declare type PlaybackPolicy = "signed" | "public" | "drm";
268
-
269
- declare interface PluginConfig extends MuxInputConfig {
270
- /**
271
- * How the videos browser should appear as a studio tool in Sanity's top navigation
272
- *
273
- * Pass `false` if you want to disable it.
274
- * @defaultValue {title: 'Videos', icon: VideoIcon}
275
- **/
276
- tool:
277
- | false
278
- | {
279
- title?: string;
280
- icon?: React.ComponentType;
281
- };
282
- /**
283
- * The roles that are allowed to configure the plugin.
284
- *
285
- * If not set, all roles will be allowed to configure the plugin.
286
- * @defaultValue []
287
- */
288
- allowedRolesForConfiguration: string[];
289
- }
290
-
291
- /**
292
- * All static rendition resolution options supported by Mux
293
- */
294
- declare type StaticRenditionResolution =
295
- | "highest"
296
- | "audio-only"
297
- | "270p"
298
- | "360p"
299
- | "480p"
300
- | "540p"
301
- | "720p"
302
- | "1080p"
303
- | "1440p"
304
- | "2160p";
305
-
306
- declare const SUPPORTED_MUX_LANGUAGES_VALUES: (
307
- | "en"
308
- | "es"
309
- | "it"
310
- | "pt"
311
- | "de"
312
- | "fr"
313
- | "pl"
314
- | "ru"
315
- | "nl"
316
- | "ca"
317
- | "tr"
318
- | "sv"
319
- | "uk"
320
- | "no"
321
- | "fi"
322
- | "sk"
323
- | "el"
324
- | "cs"
325
- | "hr"
326
- | "da"
327
- | "ro"
328
- | "bg"
329
- )[];
330
-
331
- declare type SupportedMuxLanguage =
332
- (typeof SUPPORTED_MUX_LANGUAGES_VALUES)[number];
333
-
334
- export declare interface VideoAssetDocument {
335
- _id: string;
336
- _type: "mux.videoAsset";
337
- _createdAt: string;
338
- _updatedAt?: string;
339
- status?: string;
340
- assetId?: string;
341
- playbackId?: string;
342
- filename?: string;
343
- thumbTime?: number;
344
- data?: PartialDeep<MuxAsset>;
345
- }
346
-
347
- export {};
package/sanity.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "parts": [
3
- {
4
- "implements": "part:@sanity/base/sanity-root",
5
- "path": "./v2-incompatible.js"
6
- }
7
- ]
8
- }
@@ -1,73 +0,0 @@
1
- import {definePlugin} from 'sanity'
2
-
3
- import createStudioTool, {DEFAULT_TOOL_CONFIG} from '../components/StudioTool'
4
- import {muxVideoCustomRendering} from '../plugin'
5
- import {muxVideoSchema, schemaTypes} from '../schema'
6
- import type {PluginConfig, StaticRenditionResolution} from '../util/types'
7
- export type {VideoAssetDocument} from '../util/types'
8
-
9
- export const defaultConfig: PluginConfig = {
10
- static_renditions: [],
11
- mp4_support: 'none',
12
- video_quality: 'plus',
13
- max_resolution_tier: '1080p',
14
- normalize_audio: false,
15
- defaultPublic: true,
16
- defaultSigned: false,
17
- defaultDrm: false,
18
- tool: DEFAULT_TOOL_CONFIG,
19
- allowedRolesForConfiguration: [],
20
- acceptedMimeTypes: ['video/*', 'audio/*'],
21
- }
22
-
23
- /**
24
- * Converts legacy mp4_support configuration to static_renditions format
25
- */
26
- function convertLegacyConfig(config: Partial<PluginConfig>): {
27
- static_renditions: StaticRenditionResolution[]
28
- } {
29
- // If static_renditions is already provided, use it
30
- if (config.static_renditions && config.static_renditions.length > 0) {
31
- return {static_renditions: config.static_renditions}
32
- }
33
-
34
- // Convert legacy mp4_support to static_renditions
35
- if (config.mp4_support === 'standard') {
36
- return {static_renditions: ['highest']}
37
- }
38
-
39
- return {static_renditions: []}
40
- }
41
-
42
- export const muxInput = definePlugin<Partial<PluginConfig> | void>((userConfig) => {
43
- // TODO: Remove this on next major version when we end support for encoding_tier
44
- if (typeof userConfig === 'object' && 'encoding_tier' in userConfig) {
45
- const deprecated_encoding_tier = userConfig.encoding_tier
46
- if (!userConfig.video_quality) {
47
- if (deprecated_encoding_tier === 'baseline') {
48
- userConfig.video_quality = 'basic'
49
- }
50
- if (deprecated_encoding_tier === 'smart') {
51
- userConfig.video_quality = 'plus'
52
- }
53
- }
54
- }
55
- const config: PluginConfig = {
56
- ...defaultConfig,
57
- ...(userConfig || {}),
58
- ...convertLegacyConfig(userConfig || {}),
59
- }
60
- return {
61
- name: 'mux-input',
62
- schema: {
63
- types: [
64
- ...schemaTypes,
65
- {
66
- ...muxVideoSchema,
67
- ...muxVideoCustomRendering(config),
68
- },
69
- ],
70
- },
71
- tools: config.tool === false ? undefined : [createStudioTool(config)],
72
- }
73
- })
@@ -1,152 +0,0 @@
1
- import type {SanityClient} from 'sanity'
2
-
3
- import {PLUGIN_VERSION_QUERY} from '../util/pluginVersion'
4
- import type {MuxAsset, VideoAssetDocument} from '../util/types'
5
-
6
- export function deleteAssetOnMux(client: SanityClient, assetId: string) {
7
- const {dataset} = client.config()
8
- return client.request<void>({
9
- url: `/addons/mux/assets/${dataset}/${assetId}`,
10
- withCredentials: true,
11
- method: 'DELETE',
12
- query: PLUGIN_VERSION_QUERY,
13
- })
14
- }
15
-
16
- export async function deleteAsset({
17
- client,
18
- asset,
19
- deleteOnMux,
20
- }: {
21
- client: SanityClient
22
- asset: VideoAssetDocument
23
- deleteOnMux: boolean
24
- }) {
25
- if (!asset?._id) return true
26
-
27
- try {
28
- await client.delete(asset._id)
29
- } catch (error) {
30
- return 'failed-sanity'
31
- }
32
-
33
- if (deleteOnMux && asset?.assetId) {
34
- try {
35
- await deleteAssetOnMux(client, asset.assetId)
36
- } catch (error) {
37
- return 'failed-mux'
38
- }
39
- }
40
-
41
- return true
42
- }
43
-
44
- export function getAsset(client: SanityClient, assetId: string) {
45
- const {dataset} = client.config()
46
- return client.request<{data: MuxAsset}>({
47
- url: `/addons/mux/assets/${dataset}/data/${assetId}`,
48
- withCredentials: true,
49
- method: 'GET',
50
- query: PLUGIN_VERSION_QUERY,
51
- })
52
- }
53
-
54
- export function listAssets(
55
- client: SanityClient,
56
- options: {limit?: number; cursor?: string | null}
57
- ) {
58
- const {dataset} = client.config()
59
- const query: {limit?: string; cursor?: string} = {}
60
-
61
- if (options.limit) {
62
- query.limit = options.limit.toString()
63
- }
64
- if (options.cursor) {
65
- query.cursor = options.cursor
66
- }
67
-
68
- return client.request<{data: MuxAsset[]; next_cursor?: string | null}>({
69
- url: `/addons/mux/assets/${dataset}/data/list`,
70
- withCredentials: true,
71
- method: 'GET',
72
- query: {...query, ...PLUGIN_VERSION_QUERY},
73
- })
74
- }
75
-
76
- /**
77
- * Adds a new text track to an existing asset using a VTT file URL
78
- */
79
- export function addTextTrackFromUrl(
80
- client: SanityClient,
81
- assetId: string,
82
- vttUrl: string,
83
- options: {
84
- language_code: string
85
- name: string
86
- text_type?: 'subtitles'
87
- }
88
- ) {
89
- const {dataset} = client.config()
90
-
91
- return client.request<{data: MuxAsset}>({
92
- url: `/addons/mux/assets/${dataset}/${assetId}/tracks`,
93
- withCredentials: true,
94
- method: 'POST',
95
- body: {
96
- url: vttUrl,
97
- type: 'text',
98
- language_code: options.language_code,
99
- name: options.name,
100
- text_type: options.text_type || 'subtitles',
101
- },
102
- headers: {
103
- 'Content-Type': 'application/json',
104
- },
105
- query: PLUGIN_VERSION_QUERY,
106
- })
107
- }
108
-
109
- /**
110
- * Generates subtitles automatically for an audio track
111
- */
112
- export function generateSubtitles(
113
- client: SanityClient,
114
- assetId: string,
115
- audioTrackId: string,
116
- options: {
117
- language_code: string
118
- name: string
119
- }
120
- ) {
121
- const {dataset} = client.config()
122
- return client.request<{data: MuxAsset}>({
123
- url: `/addons/mux/assets/${dataset}/${assetId}/tracks/${audioTrackId}/generate-subtitles`,
124
- withCredentials: true,
125
- method: 'POST',
126
- body: {
127
- generated_subtitles: [
128
- {
129
- language_code: options.language_code,
130
- name: options.name,
131
- },
132
- ],
133
- },
134
- headers: {
135
- 'Content-Type': 'application/json',
136
- },
137
- query: PLUGIN_VERSION_QUERY,
138
- })
139
- }
140
-
141
- /**
142
- * Deletes a text track from an asset
143
- */
144
- export function deleteTextTrack(client: SanityClient, assetId: string, trackId: string) {
145
- const {dataset} = client.config()
146
- return client.request<{data: MuxAsset}>({
147
- url: `/addons/mux/assets/${dataset}/${assetId}/tracks/${trackId}`,
148
- withCredentials: true,
149
- method: 'DELETE',
150
- query: PLUGIN_VERSION_QUERY,
151
- })
152
- }
@@ -1,111 +0,0 @@
1
- import {defer} from 'rxjs'
2
- import type {SanityClient} from 'sanity'
3
-
4
- import {PLUGIN_VERSION_QUERY} from '../util/pluginVersion'
5
-
6
- interface SecretsDocument {
7
- _id: 'secrets.mux'
8
- _type: 'mux.apiKey'
9
- token: string
10
- secretKey: string
11
- enableSignedUrls: boolean
12
- signingKeyId: string
13
- signingKeyPrivate: string
14
- drmConfigId: string
15
- }
16
- // eslint-disable-next-line max-params
17
- export function saveSecrets(
18
- client: SanityClient,
19
- token: string,
20
- secretKey: string,
21
- enableSignedUrls: boolean,
22
- signingKeyId: string,
23
- signingKeyPrivate: string,
24
- drmConfigId: string
25
- ): Promise<SecretsDocument> {
26
- const doc: SecretsDocument = {
27
- _id: 'secrets.mux',
28
- _type: 'mux.apiKey',
29
- token,
30
- secretKey,
31
- enableSignedUrls,
32
- signingKeyId,
33
- signingKeyPrivate,
34
- drmConfigId,
35
- }
36
- doc.signingKeyId = enableSignedUrls ? signingKeyId : ''
37
- doc.signingKeyPrivate = enableSignedUrls ? signingKeyPrivate : ''
38
-
39
- return client.createOrReplace(doc)
40
- }
41
-
42
- export async function createSigningKeys(client: SanityClient) {
43
- try {
44
- const {dataset} = client.config()
45
- const res = await client.request<{
46
- data: {private_key: string; id: string; created_at: string}
47
- }>({
48
- url: `/addons/mux/signing-keys/${dataset}`,
49
- withCredentials: true,
50
- method: 'POST',
51
- query: PLUGIN_VERSION_QUERY,
52
- })
53
- return res
54
- } catch (error: any) {
55
- console.error('Error creating signing keys', error)
56
- const message =
57
- error.response?.statusCode === 401
58
- ? 'Unauthorized - Failed to create the Signing Key. Please ensure that the token has "System" permissions'
59
- : error.message
60
- throw new Error(message)
61
- }
62
- }
63
-
64
- export function testSecrets(client: SanityClient) {
65
- const {dataset} = client.config()
66
- return client.request<{status: boolean}>({
67
- url: `/addons/mux/secrets/${dataset}/test`,
68
- withCredentials: true,
69
- method: 'GET',
70
- query: PLUGIN_VERSION_QUERY,
71
- })
72
- }
73
-
74
- export async function haveValidSigningKeys(
75
- client: SanityClient,
76
- signingKeyId: string,
77
- signingKeyPrivate: string
78
- ) {
79
- if (!(signingKeyId && signingKeyPrivate)) {
80
- return false
81
- }
82
-
83
- const {dataset} = client.config()
84
- try {
85
- const res = await client.request<{data: {id: string; created_at: string}}>({
86
- url: `/addons/mux/signing-keys/${dataset}/${signingKeyId}`,
87
- withCredentials: true,
88
- method: 'GET',
89
- query: PLUGIN_VERSION_QUERY,
90
- })
91
- //
92
- // if this signing key is valid it will return { data: { id: 'xxxx' } }
93
- //
94
- return !!(res.data && res.data.id)
95
- } catch (e) {
96
- console.error('Error fetching signingKeyId', signingKeyId, 'assuming it is not valid')
97
- return false
98
- }
99
- }
100
-
101
- export function testSecretsObservable(client: SanityClient) {
102
- const {dataset} = client.config()
103
- return defer(() =>
104
- client.observable.request<{status: boolean}>({
105
- url: `/addons/mux/secrets/${dataset}/test`,
106
- withCredentials: true,
107
- method: 'GET',
108
- query: PLUGIN_VERSION_QUERY,
109
- })
110
- )
111
- }