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
@@ -1,310 +0,0 @@
1
- import {uuid as generateUuid} from '@sanity/uuid'
2
- import {concat, defer, from, type Observable, of, throwError} from 'rxjs'
3
- import {catchError, mergeMap, mergeMapTo, switchMap} from 'rxjs/operators'
4
- import type {SanityClient} from 'sanity'
5
-
6
- import {createUpChunkObservable} from '../clients/upChunkObservable'
7
- import {formatDriveShareLink} from '../util/formatDriveShareLink'
8
- import {PLUGIN_VERSION_QUERY} from '../util/pluginVersion'
9
- import {roundPxString} from '../util/roundPxString'
10
- import type {MuxAsset, MuxNewAssetSettings, WatermarkConfig} from '../util/types'
11
- import {getAsset} from './assets'
12
- import {testSecretsObservable} from './secrets'
13
-
14
- function sanitizeOverlaySettingsInPlace(settings: MuxNewAssetSettings) {
15
- const inputs = settings.input
16
- if (!inputs) return
17
- for (const input of inputs) {
18
- const overlay = (input as {overlay_settings?: Record<string, unknown>}).overlay_settings
19
- if (!overlay) continue
20
-
21
- const hm = roundPxString(overlay.horizontal_margin)
22
- const vm = roundPxString(overlay.vertical_margin)
23
- const w = roundPxString(overlay.width)
24
-
25
- if (hm) overlay.horizontal_margin = hm
26
- if (vm) overlay.vertical_margin = vm
27
- if (w) overlay.width = w
28
- }
29
- }
30
-
31
- function sanitizePxStringsInJson(json: string): string {
32
- return json.replace(/"(-?\d+(?:\.\d+)?)px"/g, (_match, num) => {
33
- const n = Number(num)
34
- if (!Number.isFinite(n)) return _match
35
- let rounded = Math.round(n)
36
- if (rounded === 0) rounded = n < 0 ? -1 : 1
37
- return `"${rounded}px"`
38
- })
39
- }
40
-
41
- export function cancelUpload(client: SanityClient, uuid: string) {
42
- return client.observable.request({
43
- url: `/addons/mux/uploads/${client.config().dataset}/${uuid}`,
44
- withCredentials: true,
45
- method: 'DELETE',
46
- query: PLUGIN_VERSION_QUERY,
47
- })
48
- }
49
-
50
- export function uploadUrl({
51
- url,
52
- settings,
53
- client,
54
- watermark,
55
- }: {
56
- url: string
57
- settings: MuxNewAssetSettings
58
- client: SanityClient
59
- watermark?: WatermarkConfig
60
- }) {
61
- return testUrl(url).pipe(
62
- switchMap((validUrl) => {
63
- return concat(
64
- of({type: 'url' as const, url: validUrl}),
65
- testSecretsObservable(client).pipe(
66
- switchMap((json) => {
67
- if (!json || !json.status) {
68
- return throwError(new Error('Invalid credentials'))
69
- }
70
- const uuid = generateUuid()
71
- const muxBody = settings
72
- if (!muxBody.input) muxBody.input = [{type: 'video'}]
73
- muxBody.input[0].url = validUrl
74
- sanitizeOverlaySettingsInPlace(muxBody)
75
-
76
- const query = {
77
- muxBody: sanitizePxStringsInJson(JSON.stringify(muxBody)),
78
- filename: validUrl.split('/').slice(-1)[0],
79
- }
80
-
81
- const dataset = client.config().dataset
82
- return defer(() =>
83
- client.observable.request({
84
- url: `/addons/mux/assets/${dataset}`,
85
- withCredentials: true,
86
- method: 'POST',
87
- headers: {
88
- 'MUX-Proxy-UUID': uuid,
89
- 'Content-Type': 'application/json',
90
- },
91
- query: {...query, ...PLUGIN_VERSION_QUERY},
92
- })
93
- ).pipe(
94
- mergeMap((result) => {
95
- const asset =
96
- (result && result.results && result.results[0] && result.results[0].document) ||
97
- null
98
-
99
- if (!asset) {
100
- return throwError(new Error('No asset document returned'))
101
- }
102
- return of({type: 'success' as const, id: uuid, asset})
103
- })
104
- )
105
- })
106
- )
107
- )
108
- })
109
- )
110
- }
111
-
112
- export function uploadFile({
113
- settings,
114
- client,
115
- file,
116
- watermark,
117
- }: {
118
- settings: MuxNewAssetSettings
119
- client: SanityClient
120
- file: File
121
- watermark?: WatermarkConfig
122
- }) {
123
- return testFile(file).pipe(
124
- switchMap((fileOptions) => {
125
- return concat(
126
- of({type: 'file' as const, file: fileOptions}),
127
- testSecretsObservable(client).pipe(
128
- switchMap((json) => {
129
- if (!json || !json.status) {
130
- return throwError(() => new Error('Invalid credentials'))
131
- }
132
- const uuid = generateUuid()
133
- const body = settings
134
- sanitizeOverlaySettingsInPlace(body)
135
-
136
- return concat(
137
- of({type: 'uuid' as const, uuid}),
138
- defer(() =>
139
- client.observable.request<{
140
- sanityAssetId: string
141
- upload: {
142
- cors_origin: string
143
- id: string
144
- new_asset_settings: MuxNewAssetSettings
145
- status: 'waiting'
146
- timeout: number
147
- url: string
148
- }
149
- }>({
150
- url: `/addons/mux/uploads/${client.config().dataset}`,
151
- withCredentials: true,
152
- method: 'POST',
153
- headers: {
154
- 'MUX-Proxy-UUID': uuid,
155
- 'Content-Type': 'application/json',
156
- },
157
- body,
158
- query: PLUGIN_VERSION_QUERY,
159
- })
160
- ).pipe(
161
- mergeMap((result) => {
162
- return createUpChunkObservable(uuid, result.upload.url, file).pipe(
163
- // eslint-disable-next-line no-warning-comments
164
- // @TODO type the observable events
165
- // eslint-disable-next-line max-nested-callbacks
166
- mergeMap((event) => {
167
- if (event.type !== 'success') {
168
- return of(event)
169
- }
170
- return from(updateAssetDocumentFromUpload(client, uuid, watermark)).pipe(
171
- // eslint-disable-next-line max-nested-callbacks
172
- mergeMap((doc) => of({...event, asset: doc}))
173
- )
174
- }),
175
- // eslint-disable-next-line max-nested-callbacks
176
- catchError((err) => {
177
- // Delete asset document
178
- return cancelUpload(client, uuid).pipe(mergeMapTo(throwError(err)))
179
- })
180
- )
181
- })
182
- )
183
- )
184
- })
185
- )
186
- )
187
- })
188
- )
189
- }
190
-
191
- type UploadResponse = {
192
- data: {
193
- asset_id: string
194
- cors_origin: string
195
- id: string
196
- new_asset_settings: {
197
- static_renditions?: {resolution: string}[]
198
- passthrough: string
199
- playback_policies: ['public' | 'signed' | 'drm']
200
- }
201
- status: string
202
- timeout: number
203
- }
204
- }
205
- export function getUpload(client: SanityClient, assetId: string) {
206
- const {dataset} = client.config()
207
- return client.request<UploadResponse>({
208
- url: `/addons/mux/uploads/${dataset}/${assetId}`,
209
- withCredentials: true,
210
- method: 'GET',
211
- query: PLUGIN_VERSION_QUERY,
212
- })
213
- }
214
-
215
- function pollUpload(client: SanityClient, uuid: string): Promise<UploadResponse> {
216
- const maxTries = 10
217
- let pollInterval: number
218
- let tries = 0
219
- let assetId: string
220
- let upload: UploadResponse
221
- return new Promise((resolve, reject) => {
222
- pollInterval = (setInterval as typeof window.setInterval)(async () => {
223
- try {
224
- upload = await getUpload(client, uuid)
225
- } catch (err) {
226
- reject(err)
227
- return
228
- }
229
- assetId = upload && upload.data && upload.data.asset_id
230
- if (assetId) {
231
- clearInterval(pollInterval)
232
- resolve(upload)
233
- }
234
- if (tries > maxTries) {
235
- clearInterval(pollInterval)
236
- reject(new Error('Upload did not finish'))
237
- }
238
- tries++
239
- }, 2000)
240
- })
241
- }
242
-
243
- async function updateAssetDocumentFromUpload(
244
- client: SanityClient,
245
- uuid: string,
246
- _watermark?: WatermarkConfig
247
- ) {
248
- let upload: UploadResponse
249
- let asset: {data: MuxAsset}
250
- try {
251
- upload = await pollUpload(client, uuid)
252
- } catch (err) {
253
- return Promise.reject(err)
254
- }
255
- try {
256
- asset = await getAsset(client, upload.data.asset_id)
257
- } catch (err) {
258
- return Promise.reject(err)
259
- }
260
-
261
- const doc = {
262
- _id: uuid,
263
- _type: 'mux.videoAsset',
264
- status: asset.data.status,
265
- data: asset.data,
266
- assetId: asset.data.id,
267
- playbackId: asset.data.playback_ids[0].id,
268
- uploadId: upload.data.id,
269
- }
270
- return client.createOrReplace(doc).then(() => {
271
- return doc
272
- })
273
- }
274
-
275
- export function testFile(file: File) {
276
- if (typeof window !== 'undefined' && file instanceof window.File) {
277
- const fileOptions = optionsFromFile({}, file)
278
- return of(fileOptions)
279
- }
280
- return throwError(new Error('Invalid file'))
281
- }
282
-
283
- export function testUrl(url: string): Observable<string> {
284
- const error = new Error('Invalid URL')
285
- if (typeof url !== 'string') {
286
- return throwError(error)
287
- }
288
- let formattedUrl = url.trim()
289
- formattedUrl = formatDriveShareLink(formattedUrl)
290
- let parsed
291
- try {
292
- parsed = new URL(formattedUrl)
293
- } catch (err) {
294
- return throwError(error)
295
- }
296
- if (parsed && !parsed.protocol.match(/http:|https:/)) {
297
- return throwError(error)
298
- }
299
- return of(formattedUrl)
300
- }
301
-
302
- function optionsFromFile(opts: {preserveFilename?: boolean}, file: File) {
303
- if (typeof window === 'undefined' || !(file instanceof window.File)) {
304
- return undefined
305
- }
306
- return {
307
- name: opts.preserveFilename === false ? undefined : file.name,
308
- type: file.type,
309
- }
310
- }
@@ -1,54 +0,0 @@
1
- import {UpChunk} from '@mux/upchunk'
2
- import {Observable} from 'rxjs'
3
-
4
- export function createUpChunkObservable(uuid: string, uploadUrl: string, source: File) {
5
- return new Observable<
6
- | {type: 'pause' | 'resume'; id: string}
7
- | {type: 'success'; id: string}
8
- | {type: 'progress'; percent: number}
9
- >((subscriber) => {
10
- const upchunk = UpChunk.createUpload({
11
- endpoint: uploadUrl,
12
- file: source,
13
- dynamicChunkSize: true, // changes the chunk size based on network speeds
14
- })
15
-
16
- const successHandler = () => {
17
- subscriber.next({
18
- type: 'success',
19
- id: uuid,
20
- })
21
- subscriber.complete()
22
- }
23
-
24
- const errorHandler = (data: CustomEvent) => subscriber.error(new Error(data.detail.message))
25
-
26
- const progressHandler = (data: CustomEvent) => {
27
- return subscriber.next({type: 'progress', percent: data.detail})
28
- }
29
-
30
- const offlineHandler = () => {
31
- upchunk.pause()
32
- subscriber.next({
33
- type: 'pause',
34
- id: uuid,
35
- })
36
- }
37
-
38
- const onlineHandler = () => {
39
- upchunk.resume()
40
- subscriber.next({
41
- type: 'resume',
42
- id: uuid,
43
- })
44
- }
45
-
46
- upchunk.on('success', successHandler)
47
- upchunk.on('error', errorHandler)
48
- upchunk.on('progress', progressHandler)
49
- upchunk.on('offline', offlineHandler)
50
- upchunk.on('online', onlineHandler)
51
-
52
- return () => upchunk.abort()
53
- })
54
- }