payload-video-streaming 0.0.0-stage → 0.2.0-beta.1

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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +289 -2
  3. package/dist/access.d.ts +35 -0
  4. package/dist/access.js +53 -0
  5. package/dist/access.js.map +1 -0
  6. package/dist/bin/args.d.ts +37 -0
  7. package/dist/bin/args.js +157 -0
  8. package/dist/bin/args.js.map +1 -0
  9. package/dist/bin/cli.d.ts +2 -0
  10. package/dist/bin/cli.js +25 -0
  11. package/dist/bin/cli.js.map +1 -0
  12. package/dist/bin/fake.d.ts +2 -0
  13. package/dist/bin/fake.js +14 -0
  14. package/dist/bin/fake.js.map +1 -0
  15. package/dist/bin/migrate.d.ts +5 -0
  16. package/dist/bin/migrate.js +47 -0
  17. package/dist/bin/migrate.js.map +1 -0
  18. package/dist/bin/runFake.d.ts +2 -0
  19. package/dist/bin/runFake.js +24 -0
  20. package/dist/bin/runFake.js.map +1 -0
  21. package/dist/bin/webhooks.d.ts +15 -0
  22. package/dist/bin/webhooks.js +149 -0
  23. package/dist/bin/webhooks.js.map +1 -0
  24. package/dist/blocks.d.ts +42 -0
  25. package/dist/blocks.js +150 -0
  26. package/dist/blocks.js.map +1 -0
  27. package/dist/collection.d.ts +10 -0
  28. package/dist/collection.js +697 -0
  29. package/dist/collection.js.map +1 -0
  30. package/dist/components/BulkUploader.d.ts +16 -0
  31. package/dist/components/BulkUploader.js +226 -0
  32. package/dist/components/BulkUploader.js.map +1 -0
  33. package/dist/components/CaptionsManager.d.ts +9 -0
  34. package/dist/components/CaptionsManager.js +174 -0
  35. package/dist/components/CaptionsManager.js.map +1 -0
  36. package/dist/components/DownloadsPanel.d.ts +9 -0
  37. package/dist/components/DownloadsPanel.js +147 -0
  38. package/dist/components/DownloadsPanel.js.map +1 -0
  39. package/dist/components/ListUploader.d.ts +11 -0
  40. package/dist/components/ListUploader.js +138 -0
  41. package/dist/components/ListUploader.js.map +1 -0
  42. package/dist/components/ThumbnailCell.d.ts +5 -0
  43. package/dist/components/ThumbnailCell.js +28 -0
  44. package/dist/components/ThumbnailCell.js.map +1 -0
  45. package/dist/components/Uploader.d.ts +22 -0
  46. package/dist/components/Uploader.js +171 -0
  47. package/dist/components/Uploader.js.map +1 -0
  48. package/dist/components/VideoBlockLabel.d.ts +11 -0
  49. package/dist/components/VideoBlockLabel.js +86 -0
  50. package/dist/components/VideoBlockLabel.js.map +1 -0
  51. package/dist/components/VideoField.d.ts +17 -0
  52. package/dist/components/VideoField.js +422 -0
  53. package/dist/components/VideoField.js.map +1 -0
  54. package/dist/components/VideoRelationshipField.d.ts +16 -0
  55. package/dist/components/VideoRelationshipField.js +106 -0
  56. package/dist/components/VideoRelationshipField.js.map +1 -0
  57. package/dist/components/WebhookStatusPanel.d.ts +6 -0
  58. package/dist/components/WebhookStatusPanel.js +143 -0
  59. package/dist/components/WebhookStatusPanel.js.map +1 -0
  60. package/dist/components/api.d.ts +52 -0
  61. package/dist/components/api.js +76 -0
  62. package/dist/components/api.js.map +1 -0
  63. package/dist/components/chunkedUpload.d.ts +28 -0
  64. package/dist/components/chunkedUpload.js +49 -0
  65. package/dist/components/chunkedUpload.js.map +1 -0
  66. package/dist/components/styles.d.ts +95 -0
  67. package/dist/components/styles.js +148 -0
  68. package/dist/components/styles.js.map +1 -0
  69. package/dist/components/uploadFile.d.ts +30 -0
  70. package/dist/components/uploadFile.js +140 -0
  71. package/dist/components/uploadFile.js.map +1 -0
  72. package/dist/components/usePluginApi.d.ts +46 -0
  73. package/dist/components/usePluginApi.js +21 -0
  74. package/dist/components/usePluginApi.js.map +1 -0
  75. package/dist/components/useUploadQueue.d.ts +35 -0
  76. package/dist/components/useUploadQueue.js +135 -0
  77. package/dist/components/useUploadQueue.js.map +1 -0
  78. package/dist/components/useVideoUpload.d.ts +33 -0
  79. package/dist/components/useVideoUpload.js +87 -0
  80. package/dist/components/useVideoUpload.js.map +1 -0
  81. package/dist/core/errors.d.ts +27 -0
  82. package/dist/core/errors.js +29 -0
  83. package/dist/core/errors.js.map +1 -0
  84. package/dist/core/provider.d.ts +347 -0
  85. package/dist/core/provider.js +13 -0
  86. package/dist/core/provider.js.map +1 -0
  87. package/dist/core/registry.d.ts +17 -0
  88. package/dist/core/registry.js +110 -0
  89. package/dist/core/registry.js.map +1 -0
  90. package/dist/core/status.d.ts +15 -0
  91. package/dist/core/status.js +29 -0
  92. package/dist/core/status.js.map +1 -0
  93. package/dist/endpoints/index.d.ts +3 -0
  94. package/dist/endpoints/index.js +500 -0
  95. package/dist/endpoints/index.js.map +1 -0
  96. package/dist/env.d.ts +40 -0
  97. package/dist/env.js +105 -0
  98. package/dist/env.js.map +1 -0
  99. package/dist/exports/bunny.d.ts +16 -0
  100. package/dist/exports/bunny.js +13 -0
  101. package/dist/exports/bunny.js.map +1 -0
  102. package/dist/exports/client.d.ts +22 -0
  103. package/dist/exports/client.js +18 -0
  104. package/dist/exports/client.js.map +1 -0
  105. package/dist/exports/cloudflare.d.ts +18 -0
  106. package/dist/exports/cloudflare.js +15 -0
  107. package/dist/exports/cloudflare.js.map +1 -0
  108. package/dist/exports/mux.d.ts +18 -0
  109. package/dist/exports/mux.js +15 -0
  110. package/dist/exports/mux.js.map +1 -0
  111. package/dist/exports/react.d.ts +25 -0
  112. package/dist/exports/react.js +18 -0
  113. package/dist/exports/react.js.map +1 -0
  114. package/dist/exports/rsc.d.ts +1 -0
  115. package/dist/exports/rsc.js +4 -0
  116. package/dist/exports/rsc.js.map +1 -0
  117. package/dist/exports/testing.d.ts +13 -0
  118. package/dist/exports/testing.js +9 -0
  119. package/dist/exports/testing.js.map +1 -0
  120. package/dist/fields.d.ts +22 -0
  121. package/dist/fields.js +73 -0
  122. package/dist/fields.js.map +1 -0
  123. package/dist/frontend/ClientVideo.d.ts +14 -0
  124. package/dist/frontend/ClientVideo.js +43 -0
  125. package/dist/frontend/ClientVideo.js.map +1 -0
  126. package/dist/frontend/Video.d.ts +32 -0
  127. package/dist/frontend/Video.js +73 -0
  128. package/dist/frontend/Video.js.map +1 -0
  129. package/dist/frontend/VideoIframe.d.ts +35 -0
  130. package/dist/frontend/VideoIframe.js +60 -0
  131. package/dist/frontend/VideoIframe.js.map +1 -0
  132. package/dist/frontend/VideoUploader.d.ts +65 -0
  133. package/dist/frontend/VideoUploader.js +260 -0
  134. package/dist/frontend/VideoUploader.js.map +1 -0
  135. package/dist/frontend/constants.d.ts +10 -0
  136. package/dist/frontend/constants.js +10 -0
  137. package/dist/frontend/constants.js.map +1 -0
  138. package/dist/frontend/converters.d.ts +25 -0
  139. package/dist/frontend/converters.js +24 -0
  140. package/dist/frontend/converters.js.map +1 -0
  141. package/dist/frontend/source.d.ts +80 -0
  142. package/dist/frontend/source.js +159 -0
  143. package/dist/frontend/source.js.map +1 -0
  144. package/dist/frontend/useVideoSource.d.ts +27 -0
  145. package/dist/frontend/useVideoSource.js +108 -0
  146. package/dist/frontend/useVideoSource.js.map +1 -0
  147. package/dist/frontend/useVideoStatus.d.ts +26 -0
  148. package/dist/frontend/useVideoStatus.js +68 -0
  149. package/dist/frontend/useVideoStatus.js.map +1 -0
  150. package/dist/index.d.ts +21 -0
  151. package/dist/index.js +15 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/migrate/cfStream.d.ts +108 -0
  154. package/dist/migrate/cfStream.js +418 -0
  155. package/dist/migrate/cfStream.js.map +1 -0
  156. package/dist/options.d.ts +9 -0
  157. package/dist/options.js +153 -0
  158. package/dist/options.js.map +1 -0
  159. package/dist/plugin.d.ts +9 -0
  160. package/dist/plugin.js +177 -0
  161. package/dist/plugin.js.map +1 -0
  162. package/dist/providers/bunny/client.d.ts +78 -0
  163. package/dist/providers/bunny/client.js +231 -0
  164. package/dist/providers/bunny/client.js.map +1 -0
  165. package/dist/providers/bunny/env.d.ts +18 -0
  166. package/dist/providers/bunny/env.js +31 -0
  167. package/dist/providers/bunny/env.js.map +1 -0
  168. package/dist/providers/bunny/mapping.d.ts +39 -0
  169. package/dist/providers/bunny/mapping.js +123 -0
  170. package/dist/providers/bunny/mapping.js.map +1 -0
  171. package/dist/providers/bunny/options.d.ts +92 -0
  172. package/dist/providers/bunny/options.js +85 -0
  173. package/dist/providers/bunny/options.js.map +1 -0
  174. package/dist/providers/bunny/provider.d.ts +70 -0
  175. package/dist/providers/bunny/provider.js +480 -0
  176. package/dist/providers/bunny/provider.js.map +1 -0
  177. package/dist/providers/bunny/signing.d.ts +61 -0
  178. package/dist/providers/bunny/signing.js +144 -0
  179. package/dist/providers/bunny/signing.js.map +1 -0
  180. package/dist/providers/bunny/types.d.ts +153 -0
  181. package/dist/providers/bunny/types.js +64 -0
  182. package/dist/providers/bunny/types.js.map +1 -0
  183. package/dist/providers/bunny/urls.d.ts +49 -0
  184. package/dist/providers/bunny/urls.js +70 -0
  185. package/dist/providers/bunny/urls.js.map +1 -0
  186. package/dist/providers/bunny/webhook.d.ts +32 -0
  187. package/dist/providers/bunny/webhook.js +75 -0
  188. package/dist/providers/bunny/webhook.js.map +1 -0
  189. package/dist/providers/cloudflare/client.d.ts +93 -0
  190. package/dist/providers/cloudflare/client.js +436 -0
  191. package/dist/providers/cloudflare/client.js.map +1 -0
  192. package/dist/providers/cloudflare/env.d.ts +22 -0
  193. package/dist/providers/cloudflare/env.js +57 -0
  194. package/dist/providers/cloudflare/env.js.map +1 -0
  195. package/dist/providers/cloudflare/mapping.d.ts +15 -0
  196. package/dist/providers/cloudflare/mapping.js +95 -0
  197. package/dist/providers/cloudflare/mapping.js.map +1 -0
  198. package/dist/providers/cloudflare/options.d.ts +104 -0
  199. package/dist/providers/cloudflare/options.js +91 -0
  200. package/dist/providers/cloudflare/options.js.map +1 -0
  201. package/dist/providers/cloudflare/provider.d.ts +63 -0
  202. package/dist/providers/cloudflare/provider.js +445 -0
  203. package/dist/providers/cloudflare/provider.js.map +1 -0
  204. package/dist/providers/cloudflare/signing.d.ts +41 -0
  205. package/dist/providers/cloudflare/signing.js +97 -0
  206. package/dist/providers/cloudflare/signing.js.map +1 -0
  207. package/dist/providers/cloudflare/tus.d.ts +24 -0
  208. package/dist/providers/cloudflare/tus.js +55 -0
  209. package/dist/providers/cloudflare/tus.js.map +1 -0
  210. package/dist/providers/cloudflare/types.d.ts +156 -0
  211. package/dist/providers/cloudflare/types.js +14 -0
  212. package/dist/providers/cloudflare/types.js.map +1 -0
  213. package/dist/providers/cloudflare/urls.d.ts +55 -0
  214. package/dist/providers/cloudflare/urls.js +87 -0
  215. package/dist/providers/cloudflare/urls.js.map +1 -0
  216. package/dist/providers/cloudflare/webhook.d.ts +36 -0
  217. package/dist/providers/cloudflare/webhook.js +83 -0
  218. package/dist/providers/cloudflare/webhook.js.map +1 -0
  219. package/dist/providers/mux/client.d.ts +82 -0
  220. package/dist/providers/mux/client.js +283 -0
  221. package/dist/providers/mux/client.js.map +1 -0
  222. package/dist/providers/mux/env.d.ts +21 -0
  223. package/dist/providers/mux/env.js +61 -0
  224. package/dist/providers/mux/env.js.map +1 -0
  225. package/dist/providers/mux/mapping.d.ts +38 -0
  226. package/dist/providers/mux/mapping.js +111 -0
  227. package/dist/providers/mux/mapping.js.map +1 -0
  228. package/dist/providers/mux/options.d.ts +96 -0
  229. package/dist/providers/mux/options.js +83 -0
  230. package/dist/providers/mux/options.js.map +1 -0
  231. package/dist/providers/mux/provider.d.ts +63 -0
  232. package/dist/providers/mux/provider.js +555 -0
  233. package/dist/providers/mux/provider.js.map +1 -0
  234. package/dist/providers/mux/signing.d.ts +45 -0
  235. package/dist/providers/mux/signing.js +84 -0
  236. package/dist/providers/mux/signing.js.map +1 -0
  237. package/dist/providers/mux/types.d.ts +173 -0
  238. package/dist/providers/mux/types.js +42 -0
  239. package/dist/providers/mux/types.js.map +1 -0
  240. package/dist/providers/mux/urls.d.ts +58 -0
  241. package/dist/providers/mux/urls.js +59 -0
  242. package/dist/providers/mux/urls.js.map +1 -0
  243. package/dist/providers/mux/webhook.d.ts +38 -0
  244. package/dist/providers/mux/webhook.js +115 -0
  245. package/dist/providers/mux/webhook.js.map +1 -0
  246. package/dist/service.d.ts +193 -0
  247. package/dist/service.js +967 -0
  248. package/dist/service.js.map +1 -0
  249. package/dist/testing/bunny.d.ts +113 -0
  250. package/dist/testing/bunny.js +776 -0
  251. package/dist/testing/bunny.js.map +1 -0
  252. package/dist/testing/cloudflare.d.ts +101 -0
  253. package/dist/testing/cloudflare.js +913 -0
  254. package/dist/testing/cloudflare.js.map +1 -0
  255. package/dist/testing/index.d.ts +45 -0
  256. package/dist/testing/index.js +42 -0
  257. package/dist/testing/index.js.map +1 -0
  258. package/dist/testing/mux.d.ts +139 -0
  259. package/dist/testing/mux.js +1053 -0
  260. package/dist/testing/mux.js.map +1 -0
  261. package/dist/testing/types.d.ts +90 -0
  262. package/dist/testing/types.js +9 -0
  263. package/dist/testing/types.js.map +1 -0
  264. package/dist/types.d.ts +404 -0
  265. package/dist/types.js +3 -0
  266. package/dist/types.js.map +1 -0
  267. package/dist/utils/access.d.ts +22 -0
  268. package/dist/utils/access.js +66 -0
  269. package/dist/utils/access.js.map +1 -0
  270. package/dist/utils/localReq.d.ts +11 -0
  271. package/dist/utils/localReq.js +23 -0
  272. package/dist/utils/localReq.js.map +1 -0
  273. package/dist/utils/request.d.ts +12 -0
  274. package/dist/utils/request.js +55 -0
  275. package/dist/utils/request.js.map +1 -0
  276. package/dist/utils/version.d.ts +5 -0
  277. package/dist/utils/version.js +7 -0
  278. package/dist/utils/version.js.map +1 -0
  279. package/package.json +175 -4
@@ -0,0 +1,33 @@
1
+ import type { CreateUploadResult } from '../types.js';
2
+ import type { PluginApi } from './api.js';
3
+ import { type VideoUploadOptions } from './uploadFile.js';
4
+ export type UploadState = {
5
+ error: string;
6
+ phase: 'error';
7
+ } | {
8
+ loaded: number;
9
+ paused: boolean;
10
+ phase: 'uploading';
11
+ result: CreateUploadResult;
12
+ total: number;
13
+ } | {
14
+ phase: 'done';
15
+ result: CreateUploadResult;
16
+ } | {
17
+ phase: 'idle';
18
+ } | {
19
+ phase: 'preparing';
20
+ };
21
+ /**
22
+ * Uploads a file directly from the browser to the video provider, with whichever protocol the provider
23
+ * chose: a multipart `post`, resumable `tus` or `put-chunked` (see `uploadVideoFile`), as React state.
24
+ */
25
+ export declare const useVideoUpload: (api: PluginApi) => {
26
+ cancel: () => void;
27
+ canPause: boolean;
28
+ pause: () => void;
29
+ reset: () => void;
30
+ resume: () => void;
31
+ start: (file: File, options?: VideoUploadOptions) => Promise<CreateUploadResult | null>;
32
+ state: UploadState;
33
+ };
@@ -0,0 +1,87 @@
1
+ 'use client';
2
+ import { useCallback, useRef, useState } from 'react';
3
+ import { uploadVideoFile } from './uploadFile.js';
4
+ /**
5
+ * Uploads a file directly from the browser to the video provider, with whichever protocol the provider
6
+ * chose: a multipart `post`, resumable `tus` or `put-chunked` (see `uploadVideoFile`), as React state.
7
+ */ export const useVideoUpload = (api)=>{
8
+ const [state, setState] = useState({
9
+ phase: 'idle'
10
+ });
11
+ const controllerRef = useRef(null);
12
+ const start = useCallback(async (file, options = {})=>{
13
+ setState({
14
+ phase: 'preparing'
15
+ });
16
+ const controller = uploadVideoFile(api, file, options, {
17
+ onCreated: (result)=>setState({
18
+ loaded: 0,
19
+ paused: false,
20
+ phase: 'uploading',
21
+ result,
22
+ total: file.size
23
+ }),
24
+ onProgress: (loaded, total)=>setState((prev)=>prev.phase === 'uploading' ? {
25
+ ...prev,
26
+ loaded,
27
+ total
28
+ } : prev)
29
+ });
30
+ controllerRef.current = controller;
31
+ try {
32
+ const result = await controller.done;
33
+ setState({
34
+ phase: 'done',
35
+ result
36
+ });
37
+ return result;
38
+ } catch (err) {
39
+ setState({
40
+ error: err.message || 'Upload failed',
41
+ phase: 'error'
42
+ });
43
+ return null;
44
+ } finally{
45
+ if (controllerRef.current === controller) {
46
+ controllerRef.current = null;
47
+ }
48
+ }
49
+ }, [
50
+ api
51
+ ]);
52
+ const pause = useCallback(()=>{
53
+ controllerRef.current?.pause();
54
+ setState((prev)=>prev.phase === 'uploading' ? {
55
+ ...prev,
56
+ paused: true
57
+ } : prev);
58
+ }, []);
59
+ const resume = useCallback(()=>{
60
+ controllerRef.current?.resume();
61
+ setState((prev)=>prev.phase === 'uploading' ? {
62
+ ...prev,
63
+ paused: false
64
+ } : prev);
65
+ }, []);
66
+ const cancel = useCallback(()=>{
67
+ controllerRef.current?.cancel();
68
+ setState({
69
+ error: 'Upload cancelled',
70
+ phase: 'error'
71
+ });
72
+ }, []);
73
+ const reset = useCallback(()=>setState({
74
+ phase: 'idle'
75
+ }), []);
76
+ return {
77
+ cancel,
78
+ canPause: Boolean(controllerRef.current?.canPause),
79
+ pause,
80
+ reset,
81
+ resume,
82
+ start,
83
+ state
84
+ };
85
+ };
86
+
87
+ //# sourceMappingURL=useVideoUpload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/useVideoUpload.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useRef, useState } from 'react'\n\nimport type { CreateUploadResult } from '../types.js'\nimport type { PluginApi } from './api.js'\n\nimport { uploadVideoFile, type VideoUploadController, type VideoUploadOptions } from './uploadFile.js'\n\nexport type UploadState =\n | { error: string; phase: 'error' }\n | { loaded: number; paused: boolean; phase: 'uploading'; result: CreateUploadResult; total: number }\n | { phase: 'done'; result: CreateUploadResult }\n | { phase: 'idle' }\n | { phase: 'preparing' }\n\n/**\n * Uploads a file directly from the browser to the video provider, with whichever protocol the provider\n * chose: a multipart `post`, resumable `tus` or `put-chunked` (see `uploadVideoFile`), as React state.\n */\nexport const useVideoUpload = (api: PluginApi) => {\n const [state, setState] = useState<UploadState>({ phase: 'idle' })\n const controllerRef = useRef<null | VideoUploadController>(null)\n\n const start = useCallback(\n async (file: File, options: VideoUploadOptions = {}): Promise<CreateUploadResult | null> => {\n setState({ phase: 'preparing' })\n const controller = uploadVideoFile(api, file, options, {\n onCreated: (result) => setState({ loaded: 0, paused: false, phase: 'uploading', result, total: file.size }),\n onProgress: (loaded, total) => setState((prev) => (prev.phase === 'uploading' ? { ...prev, loaded, total } : prev)),\n })\n controllerRef.current = controller\n try {\n const result = await controller.done\n setState({ phase: 'done', result })\n return result\n } catch (err) {\n setState({ error: (err as Error).message || 'Upload failed', phase: 'error' })\n return null\n } finally {\n if (controllerRef.current === controller) {\n controllerRef.current = null\n }\n }\n },\n [api],\n )\n\n const pause = useCallback(() => {\n controllerRef.current?.pause()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: true } : prev))\n }, [])\n\n const resume = useCallback(() => {\n controllerRef.current?.resume()\n setState((prev) => (prev.phase === 'uploading' ? { ...prev, paused: false } : prev))\n }, [])\n\n const cancel = useCallback(() => {\n controllerRef.current?.cancel()\n setState({ error: 'Upload cancelled', phase: 'error' })\n }, [])\n\n const reset = useCallback(() => setState({ phase: 'idle' }), [])\n\n return { cancel, canPause: Boolean(controllerRef.current?.canPause), pause, reset, resume, start, state }\n}\n"],"names":["useCallback","useRef","useState","uploadVideoFile","useVideoUpload","api","state","setState","phase","controllerRef","start","file","options","controller","onCreated","result","loaded","paused","total","size","onProgress","prev","current","done","err","error","message","pause","resume","cancel","reset","canPause","Boolean"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAKrD,SAASC,eAAe,QAA6D,kBAAiB;AAStG;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,CAACC;IAC7B,MAAM,CAACC,OAAOC,SAAS,GAAGL,SAAsB;QAAEM,OAAO;IAAO;IAChE,MAAMC,gBAAgBR,OAAqC;IAE3D,MAAMS,QAAQV,YACZ,OAAOW,MAAYC,UAA8B,CAAC,CAAC;QACjDL,SAAS;YAAEC,OAAO;QAAY;QAC9B,MAAMK,aAAaV,gBAAgBE,KAAKM,MAAMC,SAAS;YACrDE,WAAW,CAACC,SAAWR,SAAS;oBAAES,QAAQ;oBAAGC,QAAQ;oBAAOT,OAAO;oBAAaO;oBAAQG,OAAOP,KAAKQ,IAAI;gBAAC;YACzGC,YAAY,CAACJ,QAAQE,QAAUX,SAAS,CAACc,OAAUA,KAAKb,KAAK,KAAK,cAAc;wBAAE,GAAGa,IAAI;wBAAEL;wBAAQE;oBAAM,IAAIG;QAC/G;QACAZ,cAAca,OAAO,GAAGT;QACxB,IAAI;YACF,MAAME,SAAS,MAAMF,WAAWU,IAAI;YACpChB,SAAS;gBAAEC,OAAO;gBAAQO;YAAO;YACjC,OAAOA;QACT,EAAE,OAAOS,KAAK;YACZjB,SAAS;gBAAEkB,OAAO,AAACD,IAAcE,OAAO,IAAI;gBAAiBlB,OAAO;YAAQ;YAC5E,OAAO;QACT,SAAU;YACR,IAAIC,cAAca,OAAO,KAAKT,YAAY;gBACxCJ,cAAca,OAAO,GAAG;YAC1B;QACF;IACF,GACA;QAACjB;KAAI;IAGP,MAAMsB,QAAQ3B,YAAY;QACxBS,cAAca,OAAO,EAAEK;QACvBpB,SAAS,CAACc,OAAUA,KAAKb,KAAK,KAAK,cAAc;gBAAE,GAAGa,IAAI;gBAAEJ,QAAQ;YAAK,IAAII;IAC/E,GAAG,EAAE;IAEL,MAAMO,SAAS5B,YAAY;QACzBS,cAAca,OAAO,EAAEM;QACvBrB,SAAS,CAACc,OAAUA,KAAKb,KAAK,KAAK,cAAc;gBAAE,GAAGa,IAAI;gBAAEJ,QAAQ;YAAM,IAAII;IAChF,GAAG,EAAE;IAEL,MAAMQ,SAAS7B,YAAY;QACzBS,cAAca,OAAO,EAAEO;QACvBtB,SAAS;YAAEkB,OAAO;YAAoBjB,OAAO;QAAQ;IACvD,GAAG,EAAE;IAEL,MAAMsB,QAAQ9B,YAAY,IAAMO,SAAS;YAAEC,OAAO;QAAO,IAAI,EAAE;IAE/D,OAAO;QAAEqB;QAAQE,UAAUC,QAAQvB,cAAca,OAAO,EAAES;QAAWJ;QAAOG;QAAOF;QAAQlB;QAAOJ;IAAM;AAC1G,EAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Base class for errors returned by a video provider's API. Endpoints map these to HTTP responses
3
+ * (404 → 404, 429 → 429, anything else → 502) and include `details` as `providerErrors`.
4
+ */
5
+ export declare class ProviderError extends Error {
6
+ /** Provider-specific error details (e.g. Cloudflare's `errors` array). */
7
+ readonly details: unknown[];
8
+ /** Brand checked by `isProviderError` (instanceof breaks when a bundler duplicates this module). */
9
+ readonly isProviderError = true;
10
+ /** Id of the provider that failed, e.g. `cloudflare`. */
11
+ readonly provider: string;
12
+ /** HTTP status from the provider, or 0 when it couldn't be reached. */
13
+ readonly status: number;
14
+ constructor(message: string, options: {
15
+ details?: unknown[];
16
+ provider: string;
17
+ status: number;
18
+ });
19
+ /** True when the provider reports that the resource doesn't exist. */
20
+ get isNotFound(): boolean;
21
+ }
22
+ export declare const isProviderError: (err: unknown) => err is ProviderError;
23
+ /** Thrown by the core when a provider lacks a capability an operation needs (HTTP 501). */
24
+ export declare class UnsupportedFeatureError extends Error {
25
+ readonly status = 501;
26
+ constructor(provider: string, feature: string);
27
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Base class for errors returned by a video provider's API. Endpoints map these to HTTP responses
3
+ * (404 → 404, 429 → 429, anything else → 502) and include `details` as `providerErrors`.
4
+ */ export class ProviderError extends Error {
5
+ /** Provider-specific error details (e.g. Cloudflare's `errors` array). */ details;
6
+ /** Brand checked by `isProviderError` (instanceof breaks when a bundler duplicates this module). */ isProviderError = true;
7
+ /** Id of the provider that failed, e.g. `cloudflare`. */ provider;
8
+ /** HTTP status from the provider, or 0 when it couldn't be reached. */ status;
9
+ constructor(message, options){
10
+ super(message);
11
+ this.name = 'ProviderError';
12
+ this.provider = options.provider;
13
+ this.status = options.status;
14
+ this.details = options.details ?? [];
15
+ }
16
+ /** True when the provider reports that the resource doesn't exist. */ get isNotFound() {
17
+ return this.status === 404;
18
+ }
19
+ }
20
+ export const isProviderError = (err)=>err instanceof ProviderError || typeof err === 'object' && err !== null && err.isProviderError === true;
21
+ /** Thrown by the core when a provider lacks a capability an operation needs (HTTP 501). */ export class UnsupportedFeatureError extends Error {
22
+ status = 501;
23
+ constructor(provider, feature){
24
+ super(`The "${provider}" provider does not support ${feature}.`);
25
+ this.name = 'UnsupportedFeatureError';
26
+ }
27
+ }
28
+
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/errors.ts"],"sourcesContent":["/**\n * Base class for errors returned by a video provider's API. Endpoints map these to HTTP responses\n * (404 → 404, 429 → 429, anything else → 502) and include `details` as `providerErrors`.\n */\nexport class ProviderError extends Error {\n /** Provider-specific error details (e.g. Cloudflare's `errors` array). */\n readonly details: unknown[]\n /** Brand checked by `isProviderError` (instanceof breaks when a bundler duplicates this module). */\n readonly isProviderError = true\n /** Id of the provider that failed, e.g. `cloudflare`. */\n readonly provider: string\n /** HTTP status from the provider, or 0 when it couldn't be reached. */\n readonly status: number\n\n constructor(message: string, options: { details?: unknown[]; provider: string; status: number }) {\n super(message)\n this.name = 'ProviderError'\n this.provider = options.provider\n this.status = options.status\n this.details = options.details ?? []\n }\n\n /** True when the provider reports that the resource doesn't exist. */\n get isNotFound(): boolean {\n return this.status === 404\n }\n}\n\nexport const isProviderError = (err: unknown): err is ProviderError =>\n err instanceof ProviderError || (typeof err === 'object' && err !== null && (err as ProviderError).isProviderError === true)\n\n/** Thrown by the core when a provider lacks a capability an operation needs (HTTP 501). */\nexport class UnsupportedFeatureError extends Error {\n readonly status = 501\n\n constructor(provider: string, feature: string) {\n super(`The \"${provider}\" provider does not support ${feature}.`)\n this.name = 'UnsupportedFeatureError'\n }\n}\n"],"names":["ProviderError","Error","details","isProviderError","provider","status","message","options","name","isNotFound","err","UnsupportedFeatureError","feature"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,sBAAsBC;IACjC,wEAAwE,GACxE,AAASC,QAAkB;IAC3B,kGAAkG,GAClG,AAASC,kBAAkB,KAAI;IAC/B,uDAAuD,GACvD,AAASC,SAAgB;IACzB,qEAAqE,GACrE,AAASC,OAAc;IAEvB,YAAYC,OAAe,EAAEC,OAAkE,CAAE;QAC/F,KAAK,CAACD;QACN,IAAI,CAACE,IAAI,GAAG;QACZ,IAAI,CAACJ,QAAQ,GAAGG,QAAQH,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGE,QAAQF,MAAM;QAC5B,IAAI,CAACH,OAAO,GAAGK,QAAQL,OAAO,IAAI,EAAE;IACtC;IAEA,oEAAoE,GACpE,IAAIO,aAAsB;QACxB,OAAO,IAAI,CAACJ,MAAM,KAAK;IACzB;AACF;AAEA,OAAO,MAAMF,kBAAkB,CAACO,MAC9BA,eAAeV,iBAAkB,OAAOU,QAAQ,YAAYA,QAAQ,QAAQ,AAACA,IAAsBP,eAAe,KAAK,KAAK;AAE9H,yFAAyF,GACzF,OAAO,MAAMQ,gCAAgCV;IAClCI,SAAS,IAAG;IAErB,YAAYD,QAAgB,EAAEQ,OAAe,CAAE;QAC7C,KAAK,CAAC,CAAC,KAAK,EAAER,SAAS,4BAA4B,EAAEQ,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAACJ,IAAI,GAAG;IACd;AACF"}
@@ -0,0 +1,347 @@
1
+ /**
2
+ * The contract between the core plugin and a video provider (Cloudflare Stream, Mux, Bunny Stream…).
3
+ *
4
+ * The core never imports a provider: it calls these methods and reads `capabilities` to decide which
5
+ * admin panels and endpoints exist. Everything here is plain data, so providers can be written and
6
+ * tested without Payload.
7
+ */
8
+ import type { PayloadRequest } from 'payload';
9
+ import type { VideoStatus } from './status.js';
10
+ /** Identifies a provider asset. Mux knows only the upload id until the file has arrived. */
11
+ export type ProviderRef = {
12
+ /** The provider's asset id (Cloudflare uid, Mux asset id, Bunny guid). */
13
+ assetId?: null | string;
14
+ /** Playback id, for providers that separate it from the asset id (Mux). */
15
+ playbackId?: null | string;
16
+ /** Upload id, for providers where an upload becomes an asset in a second step (Mux). */
17
+ uploadId?: null | string;
18
+ };
19
+ export type DownloadType = 'audio' | 'default';
20
+ export type DownloadState = {
21
+ /** Percentage complete while `processing`. */
22
+ percent?: null | number;
23
+ status: 'error' | 'processing' | 'ready';
24
+ url?: null | string;
25
+ };
26
+ export type Downloads = Partial<Record<DownloadType, DownloadState>>;
27
+ export type CaptionTrack = {
28
+ generated?: boolean;
29
+ label?: null | string;
30
+ /** BCP 47 language tag. */
31
+ language: string;
32
+ status?: 'error' | 'processing' | 'ready';
33
+ };
34
+ /** A provider asset in neutral form, as returned by every read. */
35
+ export type NeutralAsset = {
36
+ allowedOrigins?: null | string[];
37
+ assetId: string;
38
+ createdAt?: null | string;
39
+ creator?: null | string;
40
+ /** Seconds. */
41
+ duration?: null | number;
42
+ error?: null | {
43
+ code?: null | string;
44
+ message?: null | string;
45
+ };
46
+ height?: null | number;
47
+ playbackId?: null | string;
48
+ /** Encoding progress 0–100, when the provider reports it. */
49
+ progress?: null | number;
50
+ /** The raw provider payload, stored (hidden) on the document for debugging. */
51
+ providerData?: null | Record<string, unknown>;
52
+ readyAt?: null | string;
53
+ readyToStream: boolean;
54
+ /** Playback requires a signed token. */
55
+ signedPlayback?: boolean;
56
+ /** Bytes. */
57
+ size?: null | number;
58
+ status: VideoStatus;
59
+ /** Poster frame position in seconds. */
60
+ thumbnailTime?: null | number;
61
+ /** The provider-side name of the asset (Cloudflare `meta.name`), used as the title when adopting. */
62
+ title?: null | string;
63
+ uploadedAt?: null | string;
64
+ width?: null | number;
65
+ };
66
+ /** What the core knows about a stored video when it asks a provider for playback URLs. */
67
+ export type StoredAsset = {
68
+ assetId: string;
69
+ downloads?: null | {
70
+ audio?: null | string;
71
+ mp4?: null | string;
72
+ };
73
+ duration?: null | number;
74
+ playbackId?: null | string;
75
+ providerData?: null | Record<string, unknown>;
76
+ signedPlayback: boolean;
77
+ };
78
+ /** Settings shared by every way of creating an asset. */
79
+ export type AssetSettings = {
80
+ /** Embed allow-list. Omit to use the provider's default. */
81
+ allowedOrigins?: string[];
82
+ /** Stored on the asset when the provider supports it (default: the uploading user's id). */
83
+ creator?: string;
84
+ meta?: Record<string, unknown>;
85
+ signedPlayback: boolean;
86
+ /** Poster frame position in seconds, when the provider can apply it at creation. */
87
+ thumbnailTime?: number;
88
+ title: string;
89
+ };
90
+ export type UploadInput = {
91
+ /** The Payload document being replaced, when known. */
92
+ docId?: number | string;
93
+ filename?: string;
94
+ /** Lower the provider's maximum duration for this upload (Cloudflare reserves storage for it). */
95
+ maxDurationSeconds?: number;
96
+ /** The browser's origin, for providers that restrict the upload URL to it (Mux `cors_origin`). */
97
+ origin?: string;
98
+ /** File size in bytes. */
99
+ size: number;
100
+ } & AssetSettings;
101
+ export type ImportInput = {
102
+ /** Public http(s) URL the provider fetches the video from. */
103
+ url: string;
104
+ } & AssetSettings;
105
+ export type ServerUploadInput = {
106
+ file: Blob | Uint8Array;
107
+ filename?: string;
108
+ } & AssetSettings;
109
+ /**
110
+ * How the browser sends the file. The admin uploader (and `useVideoUpload`) supports all three.
111
+ * - `post`: one multipart POST of the file to `url` (field `fieldName`, default `file`)
112
+ * - `tus`: resumable tus upload, either to an upload that already exists (`uploadUrl`) or created by
113
+ * the client at `endpoint` with `headers` and `metadata`
114
+ * - `put-chunked`: sequential `PUT` requests with `Content-Range` headers to `url`
115
+ */
116
+ export type DirectUpload = ({
117
+ chunkMultiple?: number;
118
+ chunkSize: number;
119
+ headers?: Record<string, string>;
120
+ protocol: 'put-chunked';
121
+ url: string;
122
+ } | {
123
+ chunkSize?: number;
124
+ endpoint?: string;
125
+ headers?: Record<string, string>;
126
+ metadata?: Record<string, string>;
127
+ protocol: 'tus';
128
+ uploadUrl?: string;
129
+ } | {
130
+ fieldName?: string;
131
+ protocol: 'post';
132
+ url: string;
133
+ }) & {
134
+ /** The asset (or pending upload) the file belongs to. */
135
+ ref: ProviderRef;
136
+ };
137
+ export type UploadProtocol = DirectUpload['protocol'];
138
+ /** Editable settings pushed to the provider when an editor saves a document. */
139
+ export type AssetPatch = {
140
+ allowedOrigins?: string[];
141
+ meta?: Record<string, unknown>;
142
+ signedPlayback?: boolean;
143
+ thumbnailTime?: number;
144
+ title?: string;
145
+ };
146
+ export type PlaybackOptions = {
147
+ /** Let the provider make network calls to sign (e.g. Cloudflare's /token API). False on reads. */
148
+ allowNetwork: boolean;
149
+ /** Include download permission in the token. */
150
+ downloadable?: boolean;
151
+ /** Signed token lifetime in seconds, already capped at `maxTokenTtlSeconds`. */
152
+ expiresIn: number;
153
+ /** Provider-specific signing options, passed through from `getPlayback()` (e.g. Cloudflare `accessRules`). */
154
+ providerOptions?: Record<string, unknown>;
155
+ /** False when the reader may not receive signed URLs: signed assets then return `urls: null`. */
156
+ sign: boolean;
157
+ };
158
+ export type PlaybackUrls = {
159
+ /** Animated preview (GIF/WebP), when the provider has one. */
160
+ animated?: string;
161
+ /** DASH manifest. Not every provider has one. */
162
+ dash?: string;
163
+ /** MP4 download, when enabled for the video. */
164
+ downloadMp4?: string;
165
+ hls: string;
166
+ /** The provider's embeddable player. */
167
+ iframe: string;
168
+ /** Poster image. */
169
+ thumbnail: string;
170
+ /** The provider's hosted watch page, when it has one. */
171
+ watch?: string;
172
+ };
173
+ export type PlaybackResult = {
174
+ /** ISO timestamp when the signed token expires. */
175
+ expiresAt?: string;
176
+ /** True when the URLs contain a signed token. */
177
+ signed: boolean;
178
+ token?: string;
179
+ /** null when the asset needs a signed token that the provider couldn't (or may not) create. */
180
+ urls: null | PlaybackUrls;
181
+ };
182
+ export type WebhookEvent = {
183
+ /** The asset's current state, when the notification carries it. Otherwise the core fetches it. */
184
+ asset?: NeutralAsset;
185
+ /** Delivery id, used to drop duplicate deliveries. */
186
+ eventId?: string;
187
+ ref: ProviderRef;
188
+ };
189
+ export type WebhookResult = {
190
+ events: WebhookEvent[];
191
+ ok: true;
192
+ } | {
193
+ ok: false;
194
+ reason: string;
195
+ status: 400 | 401;
196
+ };
197
+ /**
198
+ * How to set up a provider's webhook, for the `webhooks` CLI command, the admin's webhook status and
199
+ * error messages. Steps may contain `{url}`, replaced with the endpoint URL to register.
200
+ */
201
+ export type WebhookSetup = {
202
+ /** The URL can be registered through the provider's API (`npx payload-video-streaming webhooks --register`). */
203
+ apiRegistration?: boolean;
204
+ /** Where the secret is configured, e.g. "MUX_WEBHOOK_SECRET (`webhook.secret`)". */
205
+ secret: string;
206
+ /** Where the correct secret value is found, e.g. "the webhook's signing secret in the Mux dashboard". */
207
+ secretLocation: string;
208
+ /** How to register the URL, one step per entry. */
209
+ steps: string[];
210
+ };
211
+ /** Present only when webhooks are configured (e.g. a signing secret was given). */
212
+ export type ProviderWebhook = {
213
+ /** Verifies a notification and turns it into events. `rawBody` is the exact request body. */
214
+ handle(input: {
215
+ headers: Headers;
216
+ rawBody: string;
217
+ }): Promise<WebhookResult>;
218
+ };
219
+ /** An extra endpoint, mounted at `/api/<collection>/providers/<provider id><path>`. */
220
+ export type ProviderEndpoint = {
221
+ handler: (req: PayloadRequest) => Promise<Response>;
222
+ method: 'delete' | 'get' | 'patch' | 'post' | 'put';
223
+ path: string;
224
+ };
225
+ export type ProviderCapabilities = {
226
+ /** `listAssets` is implemented, so `adoptExisting()` works. */
227
+ adoptExisting: boolean;
228
+ /** Per-video embed allow-list (`allowedOrigins`). */
229
+ allowedOrigins: boolean;
230
+ /** Caption tracks: WebVTT upload and/or automatic generation. Requires `captions`. */
231
+ captions: false | {
232
+ generate: boolean;
233
+ upload: boolean;
234
+ };
235
+ /** Playback URLs include a DASH manifest. */
236
+ dash: boolean;
237
+ /**
238
+ * MP4 / audio downloads. `video`: enabled per video from the admin (requires `downloads`).
239
+ * `library`: configured provider-wide; the admin only shows the state.
240
+ */
241
+ downloads: false | {
242
+ managed: 'library' | 'video';
243
+ types: readonly DownloadType[];
244
+ };
245
+ /** `importFromUrl` is implemented. */
246
+ importFromUrl: boolean;
247
+ /** The provider reports an encoding percentage while processing. */
248
+ progress: boolean;
249
+ /** `uploadFile` is implemented. */
250
+ serverUpload: boolean;
251
+ /** `video`: per-video toggle. `library`: provider-wide, read-only per video. false: never signed. */
252
+ signedPlayback: 'library' | 'video' | false;
253
+ /** The poster frame can be chosen (`thumbnailTime`). */
254
+ thumbnailTime: boolean;
255
+ /** Protocols `createDirectUpload` may return. */
256
+ uploadProtocols: readonly UploadProtocol[];
257
+ /** The provider can send signed webhooks (configured separately, see `webhook`). */
258
+ webhooks: boolean;
259
+ };
260
+ /** What the core offers a provider when it uploads a caption file. */
261
+ export type CaptionUploadContext = {
262
+ /**
263
+ * Publishes the caption file at a short-lived, signed public URL served by the plugin, for providers
264
+ * that fetch captions from a URL instead of accepting the file (Mux). The URL works without a Payload
265
+ * session until it expires (default one hour), so the provider must be able to reach your server.
266
+ */
267
+ publicUrl(): Promise<string>;
268
+ };
269
+ /** The result of resolving a pending upload (see `VideoProvider.resolveUpload`). */
270
+ export type UploadResolution = {
271
+ /** Set when the upload will never produce an asset (cancelled, expired, failed). */
272
+ error?: {
273
+ code: string;
274
+ message: string;
275
+ };
276
+ } & ProviderRef;
277
+ export interface VideoProvider {
278
+ /** Caption tracks. Present exactly when `capabilities.captions` is set. */
279
+ captions?: {
280
+ generate?(ref: ProviderRef, language: string): Promise<CaptionTrack>;
281
+ list(ref: ProviderRef): Promise<CaptionTrack[]>;
282
+ remove(ref: ProviderRef, language: string): Promise<void>;
283
+ upload?(ref: ProviderRef, language: string, vtt: Blob | string, context: CaptionUploadContext): Promise<CaptionTrack>;
284
+ };
285
+ readonly capabilities: ProviderCapabilities;
286
+ /** Creates an upload the browser sends the file to. */
287
+ createDirectUpload(input: UploadInput): Promise<DirectUpload>;
288
+ /**
289
+ * Deletes an asset. Resolves when it is already gone. Called with only `uploadId` for an upload that
290
+ * never became an asset (two-step providers cancel it; others may ignore it).
291
+ */
292
+ deleteAsset(ref: ProviderRef): Promise<void>;
293
+ /** Downloads. Present exactly when `capabilities.downloads.managed` is `video`. */
294
+ downloads?: {
295
+ create(ref: ProviderRef, type: DownloadType): Promise<Downloads>;
296
+ list(ref: ProviderRef): Promise<Downloads>;
297
+ remove(ref: ProviderRef, type: DownloadType): Promise<void>;
298
+ };
299
+ /** Extra endpoints the provider needs (mounted under `/providers/<id>`). */
300
+ readonly endpoints?: ProviderEndpoint[];
301
+ /** Reads an asset. Resolves `null` when it no longer exists. */
302
+ getAsset(ref: ProviderRef): Promise<NeutralAsset | null>;
303
+ /** Unique id stored on every document, e.g. `cloudflare`. */
304
+ readonly id: string;
305
+ /** Creates an asset from a public URL. Present when `capabilities.importFromUrl`. */
306
+ importFromUrl?(input: ImportInput): Promise<NeutralAsset>;
307
+ /** Human-readable name for the admin, e.g. `Cloudflare Stream`. */
308
+ readonly label: string;
309
+ /** Lists assets page by page (newest first). Present when `capabilities.adoptExisting`. */
310
+ listAssets?(input: {
311
+ creator?: string;
312
+ cursor?: string;
313
+ }): Promise<{
314
+ assets: NeutralAsset[];
315
+ next?: string;
316
+ }>;
317
+ /** Longest signed-token lifetime the provider accepts, in seconds. */
318
+ readonly maxTokenTtlSeconds?: number;
319
+ /** Builds playback URLs, signed when the asset needs it. */
320
+ playback(asset: StoredAsset, options: PlaybackOptions): Promise<PlaybackResult>;
321
+ /**
322
+ * Resolves a pending upload to its asset, when the provider creates assets in a second step (Mux).
323
+ * Resolves without `assetId` while the file hasn't arrived, with `error` when it never will, and
324
+ * `null` when the upload no longer exists.
325
+ */
326
+ resolveUpload?(uploadId: string): Promise<null | UploadResolution>;
327
+ /**
328
+ * Pushes edited settings. `context.duration` is the stored duration, for providers that need it
329
+ * (Cloudflare stores the poster position as a fraction). Resolves `null` when nothing was sent.
330
+ */
331
+ updateAsset(ref: ProviderRef, patch: AssetPatch, context: {
332
+ duration?: null | number;
333
+ }): Promise<NeutralAsset | null>;
334
+ /** Uploads a file from the server. Present when `capabilities.serverUpload`. */
335
+ uploadFile?(input: ServerUploadInput): Promise<NeutralAsset>;
336
+ /** Webhook handling. Present when webhooks are supported *and* configured. */
337
+ readonly webhook?: ProviderWebhook;
338
+ /** How to set up this provider's webhook (shown by the CLI, the admin and error messages). */
339
+ readonly webhookSetup?: WebhookSetup;
340
+ }
341
+ /** What the admin components need to know about a provider. */
342
+ export type ClientProviderInfo = {
343
+ capabilities: ProviderCapabilities;
344
+ id: string;
345
+ label: string;
346
+ };
347
+ export declare const clientProviderInfo: (provider: VideoProvider) => ClientProviderInfo;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The contract between the core plugin and a video provider (Cloudflare Stream, Mux, Bunny Stream…).
3
+ *
4
+ * The core never imports a provider: it calls these methods and reads `capabilities` to decide which
5
+ * admin panels and endpoints exist. Everything here is plain data, so providers can be written and
6
+ * tested without Payload.
7
+ */ export const clientProviderInfo = (provider)=>({
8
+ capabilities: provider.capabilities,
9
+ id: provider.id,
10
+ label: provider.label
11
+ });
12
+
13
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/provider.ts"],"sourcesContent":["/**\n * The contract between the core plugin and a video provider (Cloudflare Stream, Mux, Bunny Stream…).\n *\n * The core never imports a provider: it calls these methods and reads `capabilities` to decide which\n * admin panels and endpoints exist. Everything here is plain data, so providers can be written and\n * tested without Payload.\n */\nimport type { PayloadRequest } from 'payload'\n\nimport type { VideoStatus } from './status.js'\n\n/** Identifies a provider asset. Mux knows only the upload id until the file has arrived. */\nexport type ProviderRef = {\n /** The provider's asset id (Cloudflare uid, Mux asset id, Bunny guid). */\n assetId?: null | string\n /** Playback id, for providers that separate it from the asset id (Mux). */\n playbackId?: null | string\n /** Upload id, for providers where an upload becomes an asset in a second step (Mux). */\n uploadId?: null | string\n}\n\nexport type DownloadType = 'audio' | 'default'\n\nexport type DownloadState = {\n /** Percentage complete while `processing`. */\n percent?: null | number\n status: 'error' | 'processing' | 'ready'\n url?: null | string\n}\n\nexport type Downloads = Partial<Record<DownloadType, DownloadState>>\n\nexport type CaptionTrack = {\n generated?: boolean\n label?: null | string\n /** BCP 47 language tag. */\n language: string\n status?: 'error' | 'processing' | 'ready'\n}\n\n/** A provider asset in neutral form, as returned by every read. */\nexport type NeutralAsset = {\n allowedOrigins?: null | string[]\n assetId: string\n createdAt?: null | string\n creator?: null | string\n /** Seconds. */\n duration?: null | number\n error?: null | { code?: null | string; message?: null | string }\n height?: null | number\n playbackId?: null | string\n /** Encoding progress 0–100, when the provider reports it. */\n progress?: null | number\n /** The raw provider payload, stored (hidden) on the document for debugging. */\n providerData?: null | Record<string, unknown>\n readyAt?: null | string\n readyToStream: boolean\n /** Playback requires a signed token. */\n signedPlayback?: boolean\n /** Bytes. */\n size?: null | number\n status: VideoStatus\n /** Poster frame position in seconds. */\n thumbnailTime?: null | number\n /** The provider-side name of the asset (Cloudflare `meta.name`), used as the title when adopting. */\n title?: null | string\n uploadedAt?: null | string\n width?: null | number\n}\n\n/** What the core knows about a stored video when it asks a provider for playback URLs. */\nexport type StoredAsset = {\n assetId: string\n downloads?: null | { audio?: null | string; mp4?: null | string }\n duration?: null | number\n playbackId?: null | string\n providerData?: null | Record<string, unknown>\n signedPlayback: boolean\n}\n\n/** Settings shared by every way of creating an asset. */\nexport type AssetSettings = {\n /** Embed allow-list. Omit to use the provider's default. */\n allowedOrigins?: string[]\n /** Stored on the asset when the provider supports it (default: the uploading user's id). */\n creator?: string\n meta?: Record<string, unknown>\n signedPlayback: boolean\n /** Poster frame position in seconds, when the provider can apply it at creation. */\n thumbnailTime?: number\n title: string\n}\n\nexport type UploadInput = {\n /** The Payload document being replaced, when known. */\n docId?: number | string\n filename?: string\n /** Lower the provider's maximum duration for this upload (Cloudflare reserves storage for it). */\n maxDurationSeconds?: number\n /** The browser's origin, for providers that restrict the upload URL to it (Mux `cors_origin`). */\n origin?: string\n /** File size in bytes. */\n size: number\n} & AssetSettings\n\nexport type ImportInput = {\n /** Public http(s) URL the provider fetches the video from. */\n url: string\n} & AssetSettings\n\nexport type ServerUploadInput = {\n file: Blob | Uint8Array\n filename?: string\n} & AssetSettings\n\n/**\n * How the browser sends the file. The admin uploader (and `useVideoUpload`) supports all three.\n * - `post`: one multipart POST of the file to `url` (field `fieldName`, default `file`)\n * - `tus`: resumable tus upload, either to an upload that already exists (`uploadUrl`) or created by\n * the client at `endpoint` with `headers` and `metadata`\n * - `put-chunked`: sequential `PUT` requests with `Content-Range` headers to `url`\n */\nexport type DirectUpload = (\n | {\n chunkMultiple?: number\n chunkSize: number\n headers?: Record<string, string>\n protocol: 'put-chunked'\n url: string\n }\n | {\n chunkSize?: number\n endpoint?: string\n headers?: Record<string, string>\n metadata?: Record<string, string>\n protocol: 'tus'\n uploadUrl?: string\n }\n | { fieldName?: string; protocol: 'post'; url: string }\n) & {\n /** The asset (or pending upload) the file belongs to. */\n ref: ProviderRef\n}\n\nexport type UploadProtocol = DirectUpload['protocol']\n\n/** Editable settings pushed to the provider when an editor saves a document. */\nexport type AssetPatch = {\n allowedOrigins?: string[]\n meta?: Record<string, unknown>\n signedPlayback?: boolean\n thumbnailTime?: number\n title?: string\n}\n\nexport type PlaybackOptions = {\n /** Let the provider make network calls to sign (e.g. Cloudflare's /token API). False on reads. */\n allowNetwork: boolean\n /** Include download permission in the token. */\n downloadable?: boolean\n /** Signed token lifetime in seconds, already capped at `maxTokenTtlSeconds`. */\n expiresIn: number\n /** Provider-specific signing options, passed through from `getPlayback()` (e.g. Cloudflare `accessRules`). */\n providerOptions?: Record<string, unknown>\n /** False when the reader may not receive signed URLs: signed assets then return `urls: null`. */\n sign: boolean\n}\n\nexport type PlaybackUrls = {\n /** Animated preview (GIF/WebP), when the provider has one. */\n animated?: string\n /** DASH manifest. Not every provider has one. */\n dash?: string\n /** MP4 download, when enabled for the video. */\n downloadMp4?: string\n hls: string\n /** The provider's embeddable player. */\n iframe: string\n /** Poster image. */\n thumbnail: string\n /** The provider's hosted watch page, when it has one. */\n watch?: string\n}\n\nexport type PlaybackResult = {\n /** ISO timestamp when the signed token expires. */\n expiresAt?: string\n /** True when the URLs contain a signed token. */\n signed: boolean\n token?: string\n /** null when the asset needs a signed token that the provider couldn't (or may not) create. */\n urls: null | PlaybackUrls\n}\n\nexport type WebhookEvent = {\n /** The asset's current state, when the notification carries it. Otherwise the core fetches it. */\n asset?: NeutralAsset\n /** Delivery id, used to drop duplicate deliveries. */\n eventId?: string\n ref: ProviderRef\n}\n\nexport type WebhookResult =\n | { events: WebhookEvent[]; ok: true }\n | { ok: false; reason: string; status: 400 | 401 }\n\n/**\n * How to set up a provider's webhook, for the `webhooks` CLI command, the admin's webhook status and\n * error messages. Steps may contain `{url}`, replaced with the endpoint URL to register.\n */\nexport type WebhookSetup = {\n /** The URL can be registered through the provider's API (`npx payload-video-streaming webhooks --register`). */\n apiRegistration?: boolean\n /** Where the secret is configured, e.g. \"MUX_WEBHOOK_SECRET (`webhook.secret`)\". */\n secret: string\n /** Where the correct secret value is found, e.g. \"the webhook's signing secret in the Mux dashboard\". */\n secretLocation: string\n /** How to register the URL, one step per entry. */\n steps: string[]\n}\n\n/** Present only when webhooks are configured (e.g. a signing secret was given). */\nexport type ProviderWebhook = {\n /** Verifies a notification and turns it into events. `rawBody` is the exact request body. */\n handle(input: { headers: Headers; rawBody: string }): Promise<WebhookResult>\n}\n\n/** An extra endpoint, mounted at `/api/<collection>/providers/<provider id><path>`. */\nexport type ProviderEndpoint = {\n handler: (req: PayloadRequest) => Promise<Response>\n method: 'delete' | 'get' | 'patch' | 'post' | 'put'\n path: string\n}\n\nexport type ProviderCapabilities = {\n /** `listAssets` is implemented, so `adoptExisting()` works. */\n adoptExisting: boolean\n /** Per-video embed allow-list (`allowedOrigins`). */\n allowedOrigins: boolean\n /** Caption tracks: WebVTT upload and/or automatic generation. Requires `captions`. */\n captions: false | { generate: boolean; upload: boolean }\n /** Playback URLs include a DASH manifest. */\n dash: boolean\n /**\n * MP4 / audio downloads. `video`: enabled per video from the admin (requires `downloads`).\n * `library`: configured provider-wide; the admin only shows the state.\n */\n downloads: false | { managed: 'library' | 'video'; types: readonly DownloadType[] }\n /** `importFromUrl` is implemented. */\n importFromUrl: boolean\n /** The provider reports an encoding percentage while processing. */\n progress: boolean\n /** `uploadFile` is implemented. */\n serverUpload: boolean\n /** `video`: per-video toggle. `library`: provider-wide, read-only per video. false: never signed. */\n signedPlayback: 'library' | 'video' | false\n /** The poster frame can be chosen (`thumbnailTime`). */\n thumbnailTime: boolean\n /** Protocols `createDirectUpload` may return. */\n uploadProtocols: readonly UploadProtocol[]\n /** The provider can send signed webhooks (configured separately, see `webhook`). */\n webhooks: boolean\n}\n\n/** What the core offers a provider when it uploads a caption file. */\nexport type CaptionUploadContext = {\n /**\n * Publishes the caption file at a short-lived, signed public URL served by the plugin, for providers\n * that fetch captions from a URL instead of accepting the file (Mux). The URL works without a Payload\n * session until it expires (default one hour), so the provider must be able to reach your server.\n */\n publicUrl(): Promise<string>\n}\n\n/** The result of resolving a pending upload (see `VideoProvider.resolveUpload`). */\nexport type UploadResolution = {\n /** Set when the upload will never produce an asset (cancelled, expired, failed). */\n error?: { code: string; message: string }\n} & ProviderRef\n\nexport interface VideoProvider {\n /** Caption tracks. Present exactly when `capabilities.captions` is set. */\n captions?: {\n generate?(ref: ProviderRef, language: string): Promise<CaptionTrack>\n list(ref: ProviderRef): Promise<CaptionTrack[]>\n remove(ref: ProviderRef, language: string): Promise<void>\n upload?(ref: ProviderRef, language: string, vtt: Blob | string, context: CaptionUploadContext): Promise<CaptionTrack>\n }\n readonly capabilities: ProviderCapabilities\n /** Creates an upload the browser sends the file to. */\n createDirectUpload(input: UploadInput): Promise<DirectUpload>\n /**\n * Deletes an asset. Resolves when it is already gone. Called with only `uploadId` for an upload that\n * never became an asset (two-step providers cancel it; others may ignore it).\n */\n deleteAsset(ref: ProviderRef): Promise<void>\n /** Downloads. Present exactly when `capabilities.downloads.managed` is `video`. */\n downloads?: {\n create(ref: ProviderRef, type: DownloadType): Promise<Downloads>\n list(ref: ProviderRef): Promise<Downloads>\n remove(ref: ProviderRef, type: DownloadType): Promise<void>\n }\n /** Extra endpoints the provider needs (mounted under `/providers/<id>`). */\n readonly endpoints?: ProviderEndpoint[]\n /** Reads an asset. Resolves `null` when it no longer exists. */\n getAsset(ref: ProviderRef): Promise<NeutralAsset | null>\n /** Unique id stored on every document, e.g. `cloudflare`. */\n readonly id: string\n /** Creates an asset from a public URL. Present when `capabilities.importFromUrl`. */\n importFromUrl?(input: ImportInput): Promise<NeutralAsset>\n /** Human-readable name for the admin, e.g. `Cloudflare Stream`. */\n readonly label: string\n /** Lists assets page by page (newest first). Present when `capabilities.adoptExisting`. */\n listAssets?(input: { creator?: string; cursor?: string }): Promise<{ assets: NeutralAsset[]; next?: string }>\n /** Longest signed-token lifetime the provider accepts, in seconds. */\n readonly maxTokenTtlSeconds?: number\n /** Builds playback URLs, signed when the asset needs it. */\n playback(asset: StoredAsset, options: PlaybackOptions): Promise<PlaybackResult>\n /**\n * Resolves a pending upload to its asset, when the provider creates assets in a second step (Mux).\n * Resolves without `assetId` while the file hasn't arrived, with `error` when it never will, and\n * `null` when the upload no longer exists.\n */\n resolveUpload?(uploadId: string): Promise<null | UploadResolution>\n /**\n * Pushes edited settings. `context.duration` is the stored duration, for providers that need it\n * (Cloudflare stores the poster position as a fraction). Resolves `null` when nothing was sent.\n */\n updateAsset(ref: ProviderRef, patch: AssetPatch, context: { duration?: null | number }): Promise<NeutralAsset | null>\n /** Uploads a file from the server. Present when `capabilities.serverUpload`. */\n uploadFile?(input: ServerUploadInput): Promise<NeutralAsset>\n /** Webhook handling. Present when webhooks are supported *and* configured. */\n readonly webhook?: ProviderWebhook\n /** How to set up this provider's webhook (shown by the CLI, the admin and error messages). */\n readonly webhookSetup?: WebhookSetup\n}\n\n/** What the admin components need to know about a provider. */\nexport type ClientProviderInfo = {\n capabilities: ProviderCapabilities\n id: string\n label: string\n}\n\nexport const clientProviderInfo = (provider: VideoProvider): ClientProviderInfo => ({\n capabilities: provider.capabilities,\n id: provider.id,\n label: provider.label,\n})\n"],"names":["clientProviderInfo","provider","capabilities","id","label"],"mappings":"AAAA;;;;;;CAMC,GAkVD,OAAO,MAAMA,qBAAqB,CAACC,WAAiD,CAAA;QAClFC,cAAcD,SAASC,YAAY;QACnCC,IAAIF,SAASE,EAAE;QACfC,OAAOH,SAASG,KAAK;IACvB,CAAA,EAAE"}
@@ -0,0 +1,17 @@
1
+ import type { VideoProvider } from './provider.js';
2
+ /** Checks that a provider's optional methods match the capabilities it declares. */
3
+ export declare const validateProvider: (provider: VideoProvider) => void;
4
+ /** The configured providers, looked up by id. */
5
+ export declare class ProviderRegistry {
6
+ readonly defaultId: string;
7
+ private readonly byId;
8
+ constructor(providers: VideoProvider[], defaultProvider?: string);
9
+ get all(): VideoProvider[];
10
+ get size(): number;
11
+ /** The provider for an id (default: `defaultProvider`). Throws a 501-style error when it isn't configured. */
12
+ get(id?: null | string): VideoProvider;
13
+ has(id: string): boolean;
14
+ /** Throws UnsupportedFeatureError (HTTP 501) unless `check` passes. */
15
+ require(provider: VideoProvider, feature: string, check: boolean): void;
16
+ private list;
17
+ }