payload-video-streaming 0.0.0-stage → 0.2.0-beta.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 (252) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +658 -2
  3. package/dist/bin/args.d.ts +24 -0
  4. package/dist/bin/args.js +96 -0
  5. package/dist/bin/args.js.map +1 -0
  6. package/dist/bin/cli.d.ts +2 -0
  7. package/dist/bin/cli.js +17 -0
  8. package/dist/bin/cli.js.map +1 -0
  9. package/dist/bin/fake.d.ts +2 -0
  10. package/dist/bin/fake.js +14 -0
  11. package/dist/bin/fake.js.map +1 -0
  12. package/dist/bin/migrate.d.ts +5 -0
  13. package/dist/bin/migrate.js +47 -0
  14. package/dist/bin/migrate.js.map +1 -0
  15. package/dist/bin/runFake.d.ts +2 -0
  16. package/dist/bin/runFake.js +24 -0
  17. package/dist/bin/runFake.js.map +1 -0
  18. package/dist/blocks.d.ts +42 -0
  19. package/dist/blocks.js +150 -0
  20. package/dist/blocks.js.map +1 -0
  21. package/dist/collection.d.ts +10 -0
  22. package/dist/collection.js +550 -0
  23. package/dist/collection.js.map +1 -0
  24. package/dist/components/CaptionsManager.d.ts +9 -0
  25. package/dist/components/CaptionsManager.js +174 -0
  26. package/dist/components/CaptionsManager.js.map +1 -0
  27. package/dist/components/DownloadsPanel.d.ts +9 -0
  28. package/dist/components/DownloadsPanel.js +147 -0
  29. package/dist/components/DownloadsPanel.js.map +1 -0
  30. package/dist/components/ListUploader.d.ts +11 -0
  31. package/dist/components/ListUploader.js +116 -0
  32. package/dist/components/ListUploader.js.map +1 -0
  33. package/dist/components/ThumbnailCell.d.ts +5 -0
  34. package/dist/components/ThumbnailCell.js +28 -0
  35. package/dist/components/ThumbnailCell.js.map +1 -0
  36. package/dist/components/Uploader.d.ts +17 -0
  37. package/dist/components/Uploader.js +162 -0
  38. package/dist/components/Uploader.js.map +1 -0
  39. package/dist/components/VideoBlockLabel.d.ts +11 -0
  40. package/dist/components/VideoBlockLabel.js +86 -0
  41. package/dist/components/VideoBlockLabel.js.map +1 -0
  42. package/dist/components/VideoField.d.ts +17 -0
  43. package/dist/components/VideoField.js +418 -0
  44. package/dist/components/VideoField.js.map +1 -0
  45. package/dist/components/api.d.ts +46 -0
  46. package/dist/components/api.js +74 -0
  47. package/dist/components/api.js.map +1 -0
  48. package/dist/components/chunkedUpload.d.ts +28 -0
  49. package/dist/components/chunkedUpload.js +49 -0
  50. package/dist/components/chunkedUpload.js.map +1 -0
  51. package/dist/components/styles.d.ts +95 -0
  52. package/dist/components/styles.js +148 -0
  53. package/dist/components/styles.js.map +1 -0
  54. package/dist/components/usePluginApi.d.ts +41 -0
  55. package/dist/components/usePluginApi.js +21 -0
  56. package/dist/components/usePluginApi.js.map +1 -0
  57. package/dist/components/useVideoUpload.d.ts +37 -0
  58. package/dist/components/useVideoUpload.js +181 -0
  59. package/dist/components/useVideoUpload.js.map +1 -0
  60. package/dist/core/errors.d.ts +27 -0
  61. package/dist/core/errors.js +29 -0
  62. package/dist/core/errors.js.map +1 -0
  63. package/dist/core/provider.d.ts +331 -0
  64. package/dist/core/provider.js +13 -0
  65. package/dist/core/provider.js.map +1 -0
  66. package/dist/core/registry.d.ts +17 -0
  67. package/dist/core/registry.js +110 -0
  68. package/dist/core/registry.js.map +1 -0
  69. package/dist/core/status.d.ts +15 -0
  70. package/dist/core/status.js +29 -0
  71. package/dist/core/status.js.map +1 -0
  72. package/dist/endpoints/index.d.ts +3 -0
  73. package/dist/endpoints/index.js +464 -0
  74. package/dist/endpoints/index.js.map +1 -0
  75. package/dist/env.d.ts +40 -0
  76. package/dist/env.js +105 -0
  77. package/dist/env.js.map +1 -0
  78. package/dist/exports/bunny.d.ts +16 -0
  79. package/dist/exports/bunny.js +13 -0
  80. package/dist/exports/bunny.js.map +1 -0
  81. package/dist/exports/client.d.ts +13 -0
  82. package/dist/exports/client.js +13 -0
  83. package/dist/exports/client.js.map +1 -0
  84. package/dist/exports/cloudflare.d.ts +18 -0
  85. package/dist/exports/cloudflare.js +15 -0
  86. package/dist/exports/cloudflare.js.map +1 -0
  87. package/dist/exports/mux.d.ts +18 -0
  88. package/dist/exports/mux.js +15 -0
  89. package/dist/exports/mux.js.map +1 -0
  90. package/dist/exports/react.d.ts +13 -0
  91. package/dist/exports/react.js +11 -0
  92. package/dist/exports/react.js.map +1 -0
  93. package/dist/exports/rsc.d.ts +1 -0
  94. package/dist/exports/rsc.js +4 -0
  95. package/dist/exports/rsc.js.map +1 -0
  96. package/dist/exports/testing.d.ts +13 -0
  97. package/dist/exports/testing.js +9 -0
  98. package/dist/exports/testing.js.map +1 -0
  99. package/dist/fields.d.ts +13 -0
  100. package/dist/fields.js +13 -0
  101. package/dist/fields.js.map +1 -0
  102. package/dist/frontend/ClientVideo.d.ts +14 -0
  103. package/dist/frontend/ClientVideo.js +43 -0
  104. package/dist/frontend/ClientVideo.js.map +1 -0
  105. package/dist/frontend/Video.d.ts +32 -0
  106. package/dist/frontend/Video.js +73 -0
  107. package/dist/frontend/Video.js.map +1 -0
  108. package/dist/frontend/VideoIframe.d.ts +35 -0
  109. package/dist/frontend/VideoIframe.js +60 -0
  110. package/dist/frontend/VideoIframe.js.map +1 -0
  111. package/dist/frontend/constants.d.ts +10 -0
  112. package/dist/frontend/constants.js +10 -0
  113. package/dist/frontend/constants.js.map +1 -0
  114. package/dist/frontend/converters.d.ts +25 -0
  115. package/dist/frontend/converters.js +24 -0
  116. package/dist/frontend/converters.js.map +1 -0
  117. package/dist/frontend/source.d.ts +80 -0
  118. package/dist/frontend/source.js +159 -0
  119. package/dist/frontend/source.js.map +1 -0
  120. package/dist/frontend/useVideoSource.d.ts +27 -0
  121. package/dist/frontend/useVideoSource.js +108 -0
  122. package/dist/frontend/useVideoSource.js.map +1 -0
  123. package/dist/index.d.ts +20 -0
  124. package/dist/index.js +14 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/migrate/cfStream.d.ts +108 -0
  127. package/dist/migrate/cfStream.js +418 -0
  128. package/dist/migrate/cfStream.js.map +1 -0
  129. package/dist/options.d.ts +4 -0
  130. package/dist/options.js +90 -0
  131. package/dist/options.js.map +1 -0
  132. package/dist/plugin.d.ts +9 -0
  133. package/dist/plugin.js +98 -0
  134. package/dist/plugin.js.map +1 -0
  135. package/dist/providers/bunny/client.d.ts +78 -0
  136. package/dist/providers/bunny/client.js +231 -0
  137. package/dist/providers/bunny/client.js.map +1 -0
  138. package/dist/providers/bunny/env.d.ts +18 -0
  139. package/dist/providers/bunny/env.js +31 -0
  140. package/dist/providers/bunny/env.js.map +1 -0
  141. package/dist/providers/bunny/mapping.d.ts +39 -0
  142. package/dist/providers/bunny/mapping.js +123 -0
  143. package/dist/providers/bunny/mapping.js.map +1 -0
  144. package/dist/providers/bunny/options.d.ts +92 -0
  145. package/dist/providers/bunny/options.js +85 -0
  146. package/dist/providers/bunny/options.js.map +1 -0
  147. package/dist/providers/bunny/provider.d.ts +69 -0
  148. package/dist/providers/bunny/provider.js +472 -0
  149. package/dist/providers/bunny/provider.js.map +1 -0
  150. package/dist/providers/bunny/signing.d.ts +61 -0
  151. package/dist/providers/bunny/signing.js +144 -0
  152. package/dist/providers/bunny/signing.js.map +1 -0
  153. package/dist/providers/bunny/types.d.ts +153 -0
  154. package/dist/providers/bunny/types.js +64 -0
  155. package/dist/providers/bunny/types.js.map +1 -0
  156. package/dist/providers/bunny/urls.d.ts +49 -0
  157. package/dist/providers/bunny/urls.js +70 -0
  158. package/dist/providers/bunny/urls.js.map +1 -0
  159. package/dist/providers/bunny/webhook.d.ts +32 -0
  160. package/dist/providers/bunny/webhook.js +75 -0
  161. package/dist/providers/bunny/webhook.js.map +1 -0
  162. package/dist/providers/cloudflare/client.d.ts +93 -0
  163. package/dist/providers/cloudflare/client.js +436 -0
  164. package/dist/providers/cloudflare/client.js.map +1 -0
  165. package/dist/providers/cloudflare/env.d.ts +22 -0
  166. package/dist/providers/cloudflare/env.js +57 -0
  167. package/dist/providers/cloudflare/env.js.map +1 -0
  168. package/dist/providers/cloudflare/mapping.d.ts +15 -0
  169. package/dist/providers/cloudflare/mapping.js +95 -0
  170. package/dist/providers/cloudflare/mapping.js.map +1 -0
  171. package/dist/providers/cloudflare/options.d.ts +104 -0
  172. package/dist/providers/cloudflare/options.js +91 -0
  173. package/dist/providers/cloudflare/options.js.map +1 -0
  174. package/dist/providers/cloudflare/provider.d.ts +62 -0
  175. package/dist/providers/cloudflare/provider.js +434 -0
  176. package/dist/providers/cloudflare/provider.js.map +1 -0
  177. package/dist/providers/cloudflare/signing.d.ts +41 -0
  178. package/dist/providers/cloudflare/signing.js +97 -0
  179. package/dist/providers/cloudflare/signing.js.map +1 -0
  180. package/dist/providers/cloudflare/tus.d.ts +24 -0
  181. package/dist/providers/cloudflare/tus.js +55 -0
  182. package/dist/providers/cloudflare/tus.js.map +1 -0
  183. package/dist/providers/cloudflare/types.d.ts +156 -0
  184. package/dist/providers/cloudflare/types.js +14 -0
  185. package/dist/providers/cloudflare/types.js.map +1 -0
  186. package/dist/providers/cloudflare/urls.d.ts +55 -0
  187. package/dist/providers/cloudflare/urls.js +87 -0
  188. package/dist/providers/cloudflare/urls.js.map +1 -0
  189. package/dist/providers/cloudflare/webhook.d.ts +36 -0
  190. package/dist/providers/cloudflare/webhook.js +83 -0
  191. package/dist/providers/cloudflare/webhook.js.map +1 -0
  192. package/dist/providers/mux/client.d.ts +82 -0
  193. package/dist/providers/mux/client.js +283 -0
  194. package/dist/providers/mux/client.js.map +1 -0
  195. package/dist/providers/mux/env.d.ts +21 -0
  196. package/dist/providers/mux/env.js +61 -0
  197. package/dist/providers/mux/env.js.map +1 -0
  198. package/dist/providers/mux/mapping.d.ts +38 -0
  199. package/dist/providers/mux/mapping.js +111 -0
  200. package/dist/providers/mux/mapping.js.map +1 -0
  201. package/dist/providers/mux/options.d.ts +96 -0
  202. package/dist/providers/mux/options.js +83 -0
  203. package/dist/providers/mux/options.js.map +1 -0
  204. package/dist/providers/mux/provider.d.ts +62 -0
  205. package/dist/providers/mux/provider.js +546 -0
  206. package/dist/providers/mux/provider.js.map +1 -0
  207. package/dist/providers/mux/signing.d.ts +45 -0
  208. package/dist/providers/mux/signing.js +84 -0
  209. package/dist/providers/mux/signing.js.map +1 -0
  210. package/dist/providers/mux/types.d.ts +173 -0
  211. package/dist/providers/mux/types.js +42 -0
  212. package/dist/providers/mux/types.js.map +1 -0
  213. package/dist/providers/mux/urls.d.ts +58 -0
  214. package/dist/providers/mux/urls.js +59 -0
  215. package/dist/providers/mux/urls.js.map +1 -0
  216. package/dist/providers/mux/webhook.d.ts +38 -0
  217. package/dist/providers/mux/webhook.js +115 -0
  218. package/dist/providers/mux/webhook.js.map +1 -0
  219. package/dist/service.d.ts +166 -0
  220. package/dist/service.js +857 -0
  221. package/dist/service.js.map +1 -0
  222. package/dist/testing/bunny.d.ts +113 -0
  223. package/dist/testing/bunny.js +776 -0
  224. package/dist/testing/bunny.js.map +1 -0
  225. package/dist/testing/cloudflare.d.ts +101 -0
  226. package/dist/testing/cloudflare.js +913 -0
  227. package/dist/testing/cloudflare.js.map +1 -0
  228. package/dist/testing/index.d.ts +45 -0
  229. package/dist/testing/index.js +42 -0
  230. package/dist/testing/index.js.map +1 -0
  231. package/dist/testing/mux.d.ts +139 -0
  232. package/dist/testing/mux.js +1053 -0
  233. package/dist/testing/mux.js.map +1 -0
  234. package/dist/testing/types.d.ts +90 -0
  235. package/dist/testing/types.js +9 -0
  236. package/dist/testing/types.js.map +1 -0
  237. package/dist/types.d.ts +250 -0
  238. package/dist/types.js +3 -0
  239. package/dist/types.js.map +1 -0
  240. package/dist/utils/access.d.ts +22 -0
  241. package/dist/utils/access.js +66 -0
  242. package/dist/utils/access.js.map +1 -0
  243. package/dist/utils/localReq.d.ts +11 -0
  244. package/dist/utils/localReq.js +23 -0
  245. package/dist/utils/localReq.js.map +1 -0
  246. package/dist/utils/request.d.ts +12 -0
  247. package/dist/utils/request.js +55 -0
  248. package/dist/utils/request.js.map +1 -0
  249. package/dist/utils/version.d.ts +5 -0
  250. package/dist/utils/version.js +7 -0
  251. package/dist/utils/version.js.map +1 -0
  252. package/package.json +174 -4
@@ -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,331 @@
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
+ /** Present only when webhooks are configured (e.g. a signing secret was given). */
198
+ export type ProviderWebhook = {
199
+ /** Verifies a notification and turns it into events. `rawBody` is the exact request body. */
200
+ handle(input: {
201
+ headers: Headers;
202
+ rawBody: string;
203
+ }): Promise<WebhookResult>;
204
+ };
205
+ /** An extra endpoint, mounted at `/api/<collection>/providers/<provider id><path>`. */
206
+ export type ProviderEndpoint = {
207
+ handler: (req: PayloadRequest) => Promise<Response>;
208
+ method: 'delete' | 'get' | 'patch' | 'post' | 'put';
209
+ path: string;
210
+ };
211
+ export type ProviderCapabilities = {
212
+ /** `listAssets` is implemented, so `adoptExisting()` works. */
213
+ adoptExisting: boolean;
214
+ /** Per-video embed allow-list (`allowedOrigins`). */
215
+ allowedOrigins: boolean;
216
+ /** Caption tracks: WebVTT upload and/or automatic generation. Requires `captions`. */
217
+ captions: false | {
218
+ generate: boolean;
219
+ upload: boolean;
220
+ };
221
+ /** Playback URLs include a DASH manifest. */
222
+ dash: boolean;
223
+ /**
224
+ * MP4 / audio downloads. `video`: enabled per video from the admin (requires `downloads`).
225
+ * `library`: configured provider-wide; the admin only shows the state.
226
+ */
227
+ downloads: false | {
228
+ managed: 'library' | 'video';
229
+ types: readonly DownloadType[];
230
+ };
231
+ /** `importFromUrl` is implemented. */
232
+ importFromUrl: boolean;
233
+ /** The provider reports an encoding percentage while processing. */
234
+ progress: boolean;
235
+ /** `uploadFile` is implemented. */
236
+ serverUpload: boolean;
237
+ /** `video`: per-video toggle. `library`: provider-wide, read-only per video. false: never signed. */
238
+ signedPlayback: 'library' | 'video' | false;
239
+ /** The poster frame can be chosen (`thumbnailTime`). */
240
+ thumbnailTime: boolean;
241
+ /** Protocols `createDirectUpload` may return. */
242
+ uploadProtocols: readonly UploadProtocol[];
243
+ /** The provider can send signed webhooks (configured separately, see `webhook`). */
244
+ webhooks: boolean;
245
+ };
246
+ /** What the core offers a provider when it uploads a caption file. */
247
+ export type CaptionUploadContext = {
248
+ /**
249
+ * Publishes the caption file at a short-lived, signed public URL served by the plugin, for providers
250
+ * that fetch captions from a URL instead of accepting the file (Mux). The URL works without a Payload
251
+ * session until it expires (default one hour), so the provider must be able to reach your server.
252
+ */
253
+ publicUrl(): Promise<string>;
254
+ };
255
+ /** The result of resolving a pending upload (see `VideoProvider.resolveUpload`). */
256
+ export type UploadResolution = {
257
+ /** Set when the upload will never produce an asset (cancelled, expired, failed). */
258
+ error?: {
259
+ code: string;
260
+ message: string;
261
+ };
262
+ } & ProviderRef;
263
+ export interface VideoProvider {
264
+ /** Caption tracks. Present exactly when `capabilities.captions` is set. */
265
+ captions?: {
266
+ generate?(ref: ProviderRef, language: string): Promise<CaptionTrack>;
267
+ list(ref: ProviderRef): Promise<CaptionTrack[]>;
268
+ remove(ref: ProviderRef, language: string): Promise<void>;
269
+ upload?(ref: ProviderRef, language: string, vtt: Blob | string, context: CaptionUploadContext): Promise<CaptionTrack>;
270
+ };
271
+ readonly capabilities: ProviderCapabilities;
272
+ /** Creates an upload the browser sends the file to. */
273
+ createDirectUpload(input: UploadInput): Promise<DirectUpload>;
274
+ /**
275
+ * Deletes an asset. Resolves when it is already gone. Called with only `uploadId` for an upload that
276
+ * never became an asset (two-step providers cancel it; others may ignore it).
277
+ */
278
+ deleteAsset(ref: ProviderRef): Promise<void>;
279
+ /** Downloads. Present exactly when `capabilities.downloads.managed` is `video`. */
280
+ downloads?: {
281
+ create(ref: ProviderRef, type: DownloadType): Promise<Downloads>;
282
+ list(ref: ProviderRef): Promise<Downloads>;
283
+ remove(ref: ProviderRef, type: DownloadType): Promise<void>;
284
+ };
285
+ /** Extra endpoints the provider needs (mounted under `/providers/<id>`). */
286
+ readonly endpoints?: ProviderEndpoint[];
287
+ /** Reads an asset. Resolves `null` when it no longer exists. */
288
+ getAsset(ref: ProviderRef): Promise<NeutralAsset | null>;
289
+ /** Unique id stored on every document, e.g. `cloudflare`. */
290
+ readonly id: string;
291
+ /** Creates an asset from a public URL. Present when `capabilities.importFromUrl`. */
292
+ importFromUrl?(input: ImportInput): Promise<NeutralAsset>;
293
+ /** Human-readable name for the admin, e.g. `Cloudflare Stream`. */
294
+ readonly label: string;
295
+ /** Lists assets page by page (newest first). Present when `capabilities.adoptExisting`. */
296
+ listAssets?(input: {
297
+ creator?: string;
298
+ cursor?: string;
299
+ }): Promise<{
300
+ assets: NeutralAsset[];
301
+ next?: string;
302
+ }>;
303
+ /** Longest signed-token lifetime the provider accepts, in seconds. */
304
+ readonly maxTokenTtlSeconds?: number;
305
+ /** Builds playback URLs, signed when the asset needs it. */
306
+ playback(asset: StoredAsset, options: PlaybackOptions): Promise<PlaybackResult>;
307
+ /**
308
+ * Resolves a pending upload to its asset, when the provider creates assets in a second step (Mux).
309
+ * Resolves without `assetId` while the file hasn't arrived, with `error` when it never will, and
310
+ * `null` when the upload no longer exists.
311
+ */
312
+ resolveUpload?(uploadId: string): Promise<null | UploadResolution>;
313
+ /**
314
+ * Pushes edited settings. `context.duration` is the stored duration, for providers that need it
315
+ * (Cloudflare stores the poster position as a fraction). Resolves `null` when nothing was sent.
316
+ */
317
+ updateAsset(ref: ProviderRef, patch: AssetPatch, context: {
318
+ duration?: null | number;
319
+ }): Promise<NeutralAsset | null>;
320
+ /** Uploads a file from the server. Present when `capabilities.serverUpload`. */
321
+ uploadFile?(input: ServerUploadInput): Promise<NeutralAsset>;
322
+ /** Webhook handling. Present when webhooks are supported *and* configured. */
323
+ readonly webhook?: ProviderWebhook;
324
+ }
325
+ /** What the admin components need to know about a provider. */
326
+ export type ClientProviderInfo = {
327
+ capabilities: ProviderCapabilities;
328
+ id: string;
329
+ label: string;
330
+ };
331
+ 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/** 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}\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,GAiUD,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
+ }
@@ -0,0 +1,110 @@
1
+ import { UnsupportedFeatureError } from './errors.js';
2
+ const PKG = 'payload-video-streaming';
3
+ const fail = (message)=>{
4
+ throw new Error(`[${PKG}] ${message}`);
5
+ };
6
+ /** Checks that a provider's optional methods match the capabilities it declares. */ export const validateProvider = (provider)=>{
7
+ if (!provider || typeof provider !== 'object') {
8
+ fail('every entry in `providers` must be a provider, e.g. `cloudflareStream({ … })`');
9
+ }
10
+ const id = provider.id;
11
+ if (typeof id !== 'string' || !/^[a-z0-9][a-z0-9-_]*$/i.test(id)) {
12
+ fail(`invalid provider id "${String(id)}" (letters, digits, "-" and "_" only)`);
13
+ }
14
+ const caps = provider.capabilities;
15
+ if (!caps || !Array.isArray(caps.uploadProtocols) || caps.uploadProtocols.length === 0) {
16
+ fail(`provider "${id}" must declare at least one upload protocol in \`capabilities.uploadProtocols\``);
17
+ }
18
+ const pairs = [
19
+ [
20
+ 'importFromUrl',
21
+ caps.importFromUrl,
22
+ typeof provider.importFromUrl === 'function'
23
+ ],
24
+ [
25
+ 'serverUpload',
26
+ caps.serverUpload,
27
+ typeof provider.uploadFile === 'function'
28
+ ],
29
+ [
30
+ 'adoptExisting',
31
+ caps.adoptExisting,
32
+ typeof provider.listAssets === 'function'
33
+ ],
34
+ [
35
+ 'captions',
36
+ Boolean(caps.captions),
37
+ Boolean(provider.captions)
38
+ ],
39
+ [
40
+ 'downloads (managed per video)',
41
+ caps.downloads !== false && caps.downloads.managed === 'video',
42
+ Boolean(provider.downloads)
43
+ ]
44
+ ];
45
+ for (const [name, declared, implemented] of pairs){
46
+ if (declared !== implemented) {
47
+ fail(`provider "${id}" ${declared ? 'declares' : 'does not declare'} the ${name} capability but ${implemented ? 'implements' : 'does not implement'} it`);
48
+ }
49
+ }
50
+ if (caps.captions && caps.captions.upload !== (typeof provider.captions?.upload === 'function')) {
51
+ fail(`provider "${id}": \`capabilities.captions.upload\` must match \`captions.upload\``);
52
+ }
53
+ if (caps.captions && caps.captions.generate !== (typeof provider.captions?.generate === 'function')) {
54
+ fail(`provider "${id}": \`capabilities.captions.generate\` must match \`captions.generate\``);
55
+ }
56
+ if (provider.webhook && !caps.webhooks) {
57
+ fail(`provider "${id}" has a webhook handler but does not declare the webhooks capability`);
58
+ }
59
+ };
60
+ /** The configured providers, looked up by id. */ export class ProviderRegistry {
61
+ defaultId;
62
+ byId;
63
+ constructor(providers, defaultProvider){
64
+ this.byId = new Map();
65
+ for (const provider of providers){
66
+ validateProvider(provider);
67
+ if (this.byId.has(provider.id)) {
68
+ fail(`two providers use the id "${provider.id}". Give one of them another \`id\`, e.g. \`cloudflareStream({ id: 'cloudflare-eu', … })\``);
69
+ }
70
+ this.byId.set(provider.id, provider);
71
+ }
72
+ if (defaultProvider !== undefined && !this.byId.has(defaultProvider)) {
73
+ fail(`\`defaultProvider\` is "${defaultProvider}", but no provider with that id is configured (${this.list() || 'none'})`);
74
+ }
75
+ this.defaultId = defaultProvider ?? providers[0]?.id ?? '';
76
+ }
77
+ get all() {
78
+ return [
79
+ ...this.byId.values()
80
+ ];
81
+ }
82
+ get size() {
83
+ return this.byId.size;
84
+ }
85
+ /** The provider for an id (default: `defaultProvider`). Throws a 501-style error when it isn't configured. */ get(id) {
86
+ const key = id || this.defaultId;
87
+ const provider = this.byId.get(key);
88
+ if (!provider) {
89
+ throw Object.assign(new Error(key ? `The video provider "${key}" is not configured. Add it to \`providers\` (configured: ${this.list() || 'none'}).` : 'No video provider is configured.'), {
90
+ status: 501
91
+ });
92
+ }
93
+ return provider;
94
+ }
95
+ has(id) {
96
+ return this.byId.has(id);
97
+ }
98
+ /** Throws UnsupportedFeatureError (HTTP 501) unless `check` passes. */ require(provider, feature, check) {
99
+ if (!check) {
100
+ throw new UnsupportedFeatureError(provider.label || provider.id, feature);
101
+ }
102
+ }
103
+ list() {
104
+ return [
105
+ ...this.byId.keys()
106
+ ].map((k)=>`"${k}"`).join(', ');
107
+ }
108
+ }
109
+
110
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/registry.ts"],"sourcesContent":["import type { VideoProvider } from './provider.js'\n\nimport { UnsupportedFeatureError } from './errors.js'\n\nconst PKG = 'payload-video-streaming'\n\nconst fail = (message: string): never => {\n throw new Error(`[${PKG}] ${message}`)\n}\n\n/** Checks that a provider's optional methods match the capabilities it declares. */\nexport const validateProvider = (provider: VideoProvider): void => {\n if (!provider || typeof provider !== 'object') {\n fail('every entry in `providers` must be a provider, e.g. `cloudflareStream({ … })`')\n }\n const id = provider.id\n if (typeof id !== 'string' || !/^[a-z0-9][a-z0-9-_]*$/i.test(id)) {\n fail(`invalid provider id \"${String(id)}\" (letters, digits, \"-\" and \"_\" only)`)\n }\n const caps = provider.capabilities\n if (!caps || !Array.isArray(caps.uploadProtocols) || caps.uploadProtocols.length === 0) {\n fail(`provider \"${id}\" must declare at least one upload protocol in \\`capabilities.uploadProtocols\\``)\n }\n const pairs: [string, boolean, boolean][] = [\n ['importFromUrl', caps.importFromUrl, typeof provider.importFromUrl === 'function'],\n ['serverUpload', caps.serverUpload, typeof provider.uploadFile === 'function'],\n ['adoptExisting', caps.adoptExisting, typeof provider.listAssets === 'function'],\n ['captions', Boolean(caps.captions), Boolean(provider.captions)],\n ['downloads (managed per video)', caps.downloads !== false && caps.downloads.managed === 'video', Boolean(provider.downloads)],\n ]\n for (const [name, declared, implemented] of pairs) {\n if (declared !== implemented) {\n fail(\n `provider \"${id}\" ${declared ? 'declares' : 'does not declare'} the ${name} capability but ${implemented ? 'implements' : 'does not implement'} it`,\n )\n }\n }\n if (caps.captions && caps.captions.upload !== (typeof provider.captions?.upload === 'function')) {\n fail(`provider \"${id}\": \\`capabilities.captions.upload\\` must match \\`captions.upload\\``)\n }\n if (caps.captions && caps.captions.generate !== (typeof provider.captions?.generate === 'function')) {\n fail(`provider \"${id}\": \\`capabilities.captions.generate\\` must match \\`captions.generate\\``)\n }\n if (provider.webhook && !caps.webhooks) {\n fail(`provider \"${id}\" has a webhook handler but does not declare the webhooks capability`)\n }\n}\n\n/** The configured providers, looked up by id. */\nexport class ProviderRegistry {\n readonly defaultId: string\n private readonly byId: Map<string, VideoProvider>\n\n constructor(providers: VideoProvider[], defaultProvider?: string) {\n this.byId = new Map()\n for (const provider of providers) {\n validateProvider(provider)\n if (this.byId.has(provider.id)) {\n fail(\n `two providers use the id \"${provider.id}\". Give one of them another \\`id\\`, e.g. \\`cloudflareStream({ id: 'cloudflare-eu', … })\\``,\n )\n }\n this.byId.set(provider.id, provider)\n }\n if (defaultProvider !== undefined && !this.byId.has(defaultProvider)) {\n fail(`\\`defaultProvider\\` is \"${defaultProvider}\", but no provider with that id is configured (${this.list() || 'none'})`)\n }\n this.defaultId = defaultProvider ?? providers[0]?.id ?? ''\n }\n\n get all(): VideoProvider[] {\n return [...this.byId.values()]\n }\n\n get size(): number {\n return this.byId.size\n }\n\n /** The provider for an id (default: `defaultProvider`). Throws a 501-style error when it isn't configured. */\n get(id?: null | string): VideoProvider {\n const key = id || this.defaultId\n const provider = this.byId.get(key)\n if (!provider) {\n throw Object.assign(\n new Error(\n key\n ? `The video provider \"${key}\" is not configured. Add it to \\`providers\\` (configured: ${this.list() || 'none'}).`\n : 'No video provider is configured.',\n ),\n { status: 501 },\n )\n }\n return provider\n }\n\n has(id: string): boolean {\n return this.byId.has(id)\n }\n\n /** Throws UnsupportedFeatureError (HTTP 501) unless `check` passes. */\n require(provider: VideoProvider, feature: string, check: boolean): void {\n if (!check) {\n throw new UnsupportedFeatureError(provider.label || provider.id, feature)\n }\n }\n\n private list(): string {\n return [...this.byId.keys()].map((k) => `\"${k}\"`).join(', ')\n }\n}\n"],"names":["UnsupportedFeatureError","PKG","fail","message","Error","validateProvider","provider","id","test","String","caps","capabilities","Array","isArray","uploadProtocols","length","pairs","importFromUrl","serverUpload","uploadFile","adoptExisting","listAssets","Boolean","captions","downloads","managed","name","declared","implemented","upload","generate","webhook","webhooks","ProviderRegistry","defaultId","byId","providers","defaultProvider","Map","has","set","undefined","list","all","values","size","get","key","Object","assign","status","require","feature","check","label","keys","map","k","join"],"mappings":"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"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Provider-neutral processing status of a video. Every provider maps its own states onto these.
3
+ *
4
+ * - `waiting`: the provider is waiting for the upload (the file hasn't arrived yet)
5
+ * - `queued`: received (or being fetched from a URL), waiting to be processed
6
+ * - `processing`: encoding; `progress` holds a percentage when the provider reports one
7
+ * - `ready`: playable
8
+ * - `error`: processing failed (see the document's `error` field)
9
+ */
10
+ export type VideoStatus = 'error' | 'processing' | 'queued' | 'ready' | 'waiting';
11
+ export declare const VIDEO_STATUSES: readonly VideoStatus[];
12
+ export declare const VIDEO_STATUS_LABELS: Record<VideoStatus, string>;
13
+ /** Statuses after which a video no longer changes on its own (the sync job skips them). */
14
+ export declare const SETTLED_STATUSES: readonly VideoStatus[];
15
+ export declare const isVideoStatus: (value: unknown) => value is VideoStatus;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Provider-neutral processing status of a video. Every provider maps its own states onto these.
3
+ *
4
+ * - `waiting`: the provider is waiting for the upload (the file hasn't arrived yet)
5
+ * - `queued`: received (or being fetched from a URL), waiting to be processed
6
+ * - `processing`: encoding; `progress` holds a percentage when the provider reports one
7
+ * - `ready`: playable
8
+ * - `error`: processing failed (see the document's `error` field)
9
+ */ export const VIDEO_STATUSES = [
10
+ 'waiting',
11
+ 'queued',
12
+ 'processing',
13
+ 'ready',
14
+ 'error'
15
+ ];
16
+ export const VIDEO_STATUS_LABELS = {
17
+ error: 'Error',
18
+ processing: 'Processing',
19
+ queued: 'Queued',
20
+ ready: 'Ready',
21
+ waiting: 'Waiting for upload'
22
+ };
23
+ /** Statuses after which a video no longer changes on its own (the sync job skips them). */ export const SETTLED_STATUSES = [
24
+ 'ready',
25
+ 'error'
26
+ ];
27
+ export const isVideoStatus = (value)=>typeof value === 'string' && VIDEO_STATUSES.includes(value);
28
+
29
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/status.ts"],"sourcesContent":["/**\n * Provider-neutral processing status of a video. Every provider maps its own states onto these.\n *\n * - `waiting`: the provider is waiting for the upload (the file hasn't arrived yet)\n * - `queued`: received (or being fetched from a URL), waiting to be processed\n * - `processing`: encoding; `progress` holds a percentage when the provider reports one\n * - `ready`: playable\n * - `error`: processing failed (see the document's `error` field)\n */\nexport type VideoStatus = 'error' | 'processing' | 'queued' | 'ready' | 'waiting'\n\nexport const VIDEO_STATUSES: readonly VideoStatus[] = ['waiting', 'queued', 'processing', 'ready', 'error'] as const\n\nexport const VIDEO_STATUS_LABELS: Record<VideoStatus, string> = {\n error: 'Error',\n processing: 'Processing',\n queued: 'Queued',\n ready: 'Ready',\n waiting: 'Waiting for upload',\n}\n\n/** Statuses after which a video no longer changes on its own (the sync job skips them). */\nexport const SETTLED_STATUSES: readonly VideoStatus[] = ['ready', 'error'] as const\n\nexport const isVideoStatus = (value: unknown): value is VideoStatus =>\n typeof value === 'string' && (VIDEO_STATUSES as readonly string[]).includes(value)\n"],"names":["VIDEO_STATUSES","VIDEO_STATUS_LABELS","error","processing","queued","ready","waiting","SETTLED_STATUSES","isVideoStatus","value","includes"],"mappings":"AAAA;;;;;;;;CAQC,GAGD,OAAO,MAAMA,iBAAyC;IAAC;IAAW;IAAU;IAAc;IAAS;CAAQ,CAAS;AAEpH,OAAO,MAAMC,sBAAmD;IAC9DC,OAAO;IACPC,YAAY;IACZC,QAAQ;IACRC,OAAO;IACPC,SAAS;AACX,EAAC;AAED,yFAAyF,GACzF,OAAO,MAAMC,mBAA2C;IAAC;IAAS;CAAQ,CAAS;AAEnF,OAAO,MAAMC,gBAAgB,CAACC,QAC5B,OAAOA,UAAU,YAAY,AAACT,eAAqCU,QAAQ,CAACD,OAAM"}
@@ -0,0 +1,3 @@
1
+ import type { Endpoint } from 'payload';
2
+ import type { VideoService } from '../service.js';
3
+ export declare const buildEndpoints: (service: VideoService) => Endpoint[];