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,404 @@
1
+ import type { VideoBlockArgs } from './blocks.js';
2
+ import type { CollectionConfig, PayloadRequest, TaskConfig } from 'payload';
3
+ import type { DirectUpload, PlaybackUrls, VideoProvider, WebhookSetup } from './core/provider.js';
4
+ import type { VideoStatus } from './core/status.js';
5
+ /** The shape of a video document stored by the plugin. */
6
+ export type VideoDoc = {
7
+ allowedOrigins?: null | string[];
8
+ /** Provider id and asset id joined (`cloudflare:abc…`); unique, maintained by the plugin. */
9
+ assetKey?: null | string;
10
+ /** The provider's asset id (Cloudflare uid, Mux asset id, Bunny guid). */
11
+ assetId?: null | string;
12
+ captions?: null | {
13
+ generated?: boolean | null;
14
+ id?: null | string;
15
+ label?: null | string;
16
+ language: string;
17
+ status?: null | string;
18
+ }[];
19
+ createdAt?: string;
20
+ creator?: null | string;
21
+ downloads?: null | {
22
+ audio?: null | string;
23
+ audioPercent?: null | number;
24
+ mp4?: null | string;
25
+ mp4Percent?: null | number;
26
+ };
27
+ duration?: null | number;
28
+ error?: null | {
29
+ code?: null | string;
30
+ message?: null | string;
31
+ };
32
+ height?: null | number;
33
+ id: number | string;
34
+ lastSyncedAt?: null | string;
35
+ meta?: null | Record<string, unknown>;
36
+ /** Review state, when `moderation` is on. */
37
+ moderation?: null | VideoModerationStatus;
38
+ /** The user who uploaded the video, when `ownership` is on (an id, or the user when populated). */
39
+ owner?: null | number | string | {
40
+ id: number | string;
41
+ };
42
+ /** Virtual: playback URLs, populated on read. */
43
+ playback?: null | VideoPlayback;
44
+ /** Playback id, for providers that separate it from the asset id (Mux). */
45
+ playbackId?: null | string;
46
+ /** Encoding progress 0–100, when the provider reports it. */
47
+ progress?: null | number;
48
+ /** Id of the provider that stores the video, e.g. `cloudflare`. */
49
+ provider?: null | string;
50
+ /** The provider's raw payload from the last sync (hidden). */
51
+ providerData?: null | Record<string, unknown>;
52
+ readyAt?: null | string;
53
+ readyToStream?: boolean | null;
54
+ /** Previous asset, kept until a replacement upload is ready. */
55
+ replacedAssetId?: null | string;
56
+ /** Playback requires a signed token. */
57
+ signedPlayback?: boolean | null;
58
+ size?: null | number;
59
+ status?: null | VideoStatus;
60
+ /** Poster frame position in seconds. */
61
+ thumbnailTime?: null | number;
62
+ title?: null | string;
63
+ updatedAt?: string;
64
+ uploadedAt?: null | string;
65
+ /** Pending upload id, for providers that create the asset in a second step (Mux). */
66
+ uploadId?: null | string;
67
+ width?: null | number;
68
+ };
69
+ export type VideoAccessArgs = {
70
+ /** The video document, when the operation targets an existing video. */
71
+ doc?: VideoDoc;
72
+ req: PayloadRequest;
73
+ };
74
+ /** Extra access check layered on top of the collection's own access control. */
75
+ export type VideoAccess = (args: VideoAccessArgs) => boolean | Promise<boolean>;
76
+ export type VideoModerationStatus = 'approved' | 'pending' | 'rejected';
77
+ /** Arguments of the lifecycle hooks (`hooks` option). */
78
+ export type VideoStatusChangeArgs = {
79
+ doc: VideoDoc;
80
+ /** The document before the change; undefined when it was just created. */
81
+ previousDoc?: VideoDoc;
82
+ /** null when the document was just created. */
83
+ previousStatus: null | VideoStatus;
84
+ req: PayloadRequest;
85
+ status: VideoStatus;
86
+ };
87
+ export type VideoLifecycleHook = (args: VideoStatusChangeArgs) => Promise<void> | void;
88
+ /** What `upload.validate` is asked about. Exactly one of `size` (browser upload) or `url` (import) is set. */
89
+ export type VideoUploadCheck = {
90
+ /** The document being replaced, if any. */
91
+ doc?: VideoDoc;
92
+ filename?: string;
93
+ provider: string;
94
+ req: PayloadRequest;
95
+ size?: number;
96
+ /** MIME type reported by the browser, when known. */
97
+ type?: string;
98
+ url?: string;
99
+ };
100
+ /** The settings of `ownership`, resolved. */
101
+ export type ResolvedOwnership = {
102
+ /** Who may change a video's owner. Server code without a user always may. */
103
+ canAssign: (args: {
104
+ req: PayloadRequest;
105
+ }) => boolean | Promise<boolean>;
106
+ field: string;
107
+ /** The auth collection owners belong to. */
108
+ relationTo: string;
109
+ };
110
+ /** The settings of `moderation`, resolved. */
111
+ export type ResolvedModeration = {
112
+ /** Who may approve or reject videos. Server code without a user always may. */
113
+ canModerate: (args: {
114
+ req: PayloadRequest;
115
+ }) => boolean | Promise<boolean>;
116
+ /** The status of a new video. */
117
+ defaultStatus: (args: {
118
+ canModerate: boolean;
119
+ req: PayloadRequest;
120
+ }) => Promise<VideoModerationStatus> | VideoModerationStatus;
121
+ field: string;
122
+ };
123
+ export type VideoPluginOptions = {
124
+ /**
125
+ * Extra access checks. Collection access (read/create/update/delete) is always enforced first;
126
+ * these let you restrict plugin-specific actions further.
127
+ */
128
+ access?: {
129
+ /** Manage captions / downloads / sync. Default: collection `update` access. */
130
+ manage?: VideoAccess;
131
+ /**
132
+ * Who may receive playback URLs (including signed tokens) via the playback endpoint.
133
+ * Default: anyone with collection `read` access to the video.
134
+ */
135
+ playback?: VideoAccess;
136
+ /** Create uploads / imports. Default: collection `create` access (or `update` when replacing). */
137
+ upload?: VideoAccess;
138
+ };
139
+ /** Collection customisation. */
140
+ collection?: {
141
+ /**
142
+ * Access control for the videos collection, passed straight to Payload. Unset operations use
143
+ * Payload's defaults (logged-in users only). For example, to show videos to visitors of a public
144
+ * site: `{ read: () => true }`. Private videos stay protected by `signedPlayback` and
145
+ * `access.playback`.
146
+ */
147
+ access?: CollectionConfig['access'];
148
+ /** Admin group label. Default: none. */
149
+ adminGroup?: string;
150
+ /** Last chance to modify the generated collection config. */
151
+ override?: (collection: CollectionConfig) => CollectionConfig;
152
+ /** Default: `videos` */
153
+ slug?: string;
154
+ };
155
+ /** Provider for new uploads when several are configured. Default: the first one. */
156
+ defaultProvider?: string;
157
+ /**
158
+ * Lifecycle hooks, called after a video's `status` changes, whatever changed it (a webhook, a sync,
159
+ * the sync-pending task or a new upload). They run after the change is saved, inside the same
160
+ * request, so keep them quick or queue a job. Errors are logged and never undo the change.
161
+ */
162
+ hooks?: {
163
+ /** Every status change, including the first status of a new video (`previousStatus: null`). */
164
+ afterStatusChange?: VideoLifecycleHook;
165
+ /** The video failed to upload or process (`status: 'error'`, details in `doc.error`). */
166
+ onError?: VideoLifecycleHook;
167
+ /** The video can be played (`status: 'ready'`). */
168
+ onReady?: VideoLifecycleHook;
169
+ };
170
+ /**
171
+ * Review new videos before they're shown: adds a `moderation` field (`pending`, `approved`,
172
+ * `rejected`). It only records the decision: pair it with read access such as
173
+ * `approvedOrOwner()` to hide unapproved videos. `true` uses the defaults below.
174
+ */
175
+ moderation?: boolean | {
176
+ /** Who may approve or reject. Default: users of the admin user collection (`admin.user`). */
177
+ canModerate?: ResolvedModeration['canModerate'];
178
+ /** Status of new videos. Default: `approved` when the uploader may moderate, otherwise `pending`. */
179
+ defaultStatus?: ResolvedModeration['defaultStatus'];
180
+ /** Field name. Default `moderation`. */
181
+ field?: string;
182
+ };
183
+ /**
184
+ * Record who uploaded each video: adds an `owner` relationship, set from the logged-in user when a
185
+ * video is created and protected from changes by other users. It doesn't restrict anything by
186
+ * itself: use it in access control, e.g. `ownerOr(isAdmin)` from this package. `true` uses the
187
+ * defaults below.
188
+ */
189
+ ownership?: boolean | {
190
+ /** Who may change a video's owner. Default: nobody (server code without a user always may). */
191
+ canAssign?: ResolvedOwnership['canAssign'];
192
+ /** Field name. Default `owner`. */
193
+ field?: string;
194
+ /** The auth collection of the uploaders. Default: the admin user collection (`admin.user`). */
195
+ relationTo?: string;
196
+ };
197
+ /** Delete the provider's asset when its document is deleted. Default: true. */
198
+ deleteFromProvider?: boolean;
199
+ /**
200
+ * Keeps the collection (so your schema/migrations stay stable) but disables endpoints, hooks
201
+ * and admin components. `providers` may be empty.
202
+ */
203
+ disabled?: boolean;
204
+ /** Playback URL generation. */
205
+ playback?: {
206
+ /**
207
+ * Extend signed tokens so they outlast the video: a video of `duration` seconds gets at least
208
+ * `duration × factor + marginSeconds` (still capped at the provider's maximum), so a token never
209
+ * expires while someone is watching. An explicit `expiresIn` passed to `getPlayback()` or the
210
+ * playback endpoint takes precedence. Default `{ factor: 2, marginSeconds: 600 }`; `false` always
211
+ * uses `expiresIn`.
212
+ */
213
+ coverDuration?: {
214
+ factor?: number;
215
+ marginSeconds?: number;
216
+ } | boolean;
217
+ /** Default signed token lifetime in seconds. Default 3600 (Cloudflare's maximum is 86400). */
218
+ expiresIn?: number;
219
+ /**
220
+ * Populate a virtual `playback` field on every read (REST, GraphQL, Local API).
221
+ * Signed videos get a fresh token when the reader passes `access.playback`.
222
+ * Default: true.
223
+ */
224
+ populateOnRead?: boolean;
225
+ /**
226
+ * Visitors can watch the videos embedded in documents they can read (`videoField()`, video blocks,
227
+ * rich text), even when they can't read the videos collection itself. Restricted videos are
228
+ * excluded: signed playback, unapproved ones (with `moderation`), and those `access.playback`
229
+ * denies. Video documents still can't be listed or fetched by id without read access.
230
+ * Default true; `false` makes playback follow the videos collection's read access only.
231
+ */
232
+ embedded?: boolean;
233
+ };
234
+ /** The video providers, e.g. `[cloudflareStream({ … })]`. Required unless `disabled`. */
235
+ providers: VideoProvider[];
236
+ /**
237
+ * Registers a Payload jobs task that refreshes videos that are still processing. Use it when webhooks
238
+ * aren't configured (or as a safety net), so documents reach `ready`/`error` even if nobody has the
239
+ * admin open. Queue it yourself, or pass `cron` (or `schedule`) to run it automatically.
240
+ */
241
+ syncPendingTask?: boolean | {
242
+ /**
243
+ * When `cron` is set, also add a `jobs.autoRun` entry for `queue` so the task runs without any
244
+ * other configuration. Set to `false` if you run jobs yourself (e.g. a worker or `/api/payload-jobs/run`).
245
+ * Default `true`.
246
+ */
247
+ autoRun?: boolean;
248
+ /** Max documents refreshed per run. Default 50. */
249
+ batchSize?: number;
250
+ /**
251
+ * How often to sync, as a cron expression: 5 fields, or 6 with seconds. For example
252
+ * `'* * * * *'` (every minute) or `'*\/5 * * * *'` (every 5 minutes). Env: `VIDEO_SYNC_CRON`.
253
+ */
254
+ cron?: string;
255
+ /** Jobs queue the task is scheduled on. Default `videos`. */
256
+ queue?: string;
257
+ /** Full Payload jobs schedule. Takes precedence over `cron`/`queue`. */
258
+ schedule?: TaskConfig['schedule'];
259
+ /** Task slug. Default `videoSyncPending`. */
260
+ slug?: string;
261
+ };
262
+ /** Defaults for new videos, for every provider. */
263
+ upload?: {
264
+ /**
265
+ * File types browsers may upload through `POST /upload`: MIME types (`video/mp4`), wildcards
266
+ * (`video/*`) or extensions (`.mp4`). Checked against the file name and the type the browser
267
+ * reports. Default: any type (the provider rejects files it can't process).
268
+ */
269
+ allowedTypes?: string[];
270
+ /** `creator` value stored on the video. Default: the uploading user's id. */
271
+ creator?: (req: PayloadRequest) => string | undefined;
272
+ /**
273
+ * Longest video, in seconds, for providers that enforce it at upload (Cloudflare). A request can
274
+ * lower it but not raise it.
275
+ */
276
+ maxDurationSeconds?: number;
277
+ /** Largest file, in bytes, that browsers may upload through `POST /upload`. Default: no limit. */
278
+ maxFileSize?: number;
279
+ /** New videos require signed playback URLs. Default false. */
280
+ signedPlayback?: boolean;
281
+ /** Default poster frame position, in seconds. */
282
+ thumbnailTime?: number;
283
+ /**
284
+ * Your own check before every `POST /upload` and `POST /import`, e.g. a per-user quota. Return
285
+ * `true` to allow it, or a message to refuse it (sent to the browser with status 400).
286
+ */
287
+ validate?: (args: VideoUploadCheck) => Promise<string | true> | string | true;
288
+ };
289
+ /**
290
+ * Register the video block in `config.blocks`, so blocks fields and Lexical can reference it by
291
+ * slug (`videoBlockReferences('video')`, `BlocksFeature({ blocks: ['video'] })`).
292
+ * Not needed when you use `videoBlock()` inline. Default false.
293
+ */
294
+ videoBlock?: boolean | Omit<VideoBlockArgs, 'collectionSlug'>;
295
+ };
296
+ export type ResolvedVideoOptions = {
297
+ access: NonNullable<VideoPluginOptions['access']>;
298
+ collection: VideoPluginOptions['collection'];
299
+ collectionSlug: string;
300
+ defaultProvider?: string;
301
+ deleteFromProvider: boolean;
302
+ hooks: NonNullable<VideoPluginOptions['hooks']>;
303
+ moderation?: ResolvedModeration;
304
+ ownership?: ResolvedOwnership;
305
+ playback: {
306
+ coverDuration: {
307
+ factor: number;
308
+ marginSeconds: number;
309
+ } | false;
310
+ expiresIn: number;
311
+ /** Longest token lifetime every configured provider accepts. */
312
+ maxTokenTtlSeconds: number;
313
+ embedded: boolean;
314
+ populateOnRead: boolean;
315
+ };
316
+ providers: VideoProvider[];
317
+ syncPendingTask?: {
318
+ autoRun: boolean;
319
+ batchSize: number;
320
+ cron?: string;
321
+ queue: string;
322
+ schedule?: TaskConfig['schedule'];
323
+ slug: string;
324
+ };
325
+ upload: {
326
+ allowedTypes?: string[];
327
+ creator?: (req: PayloadRequest) => string | undefined;
328
+ maxDurationSeconds?: number;
329
+ maxFileSize?: number;
330
+ signedPlayback: boolean;
331
+ thumbnailTime?: number;
332
+ validate?: NonNullable<VideoPluginOptions['upload']>['validate'];
333
+ };
334
+ };
335
+ /** Result of the playback endpoint / server API, and the virtual `playback` field. */
336
+ export type VideoPlayback = {
337
+ assetId: string;
338
+ /** ISO timestamp when the signed token expires. */
339
+ expiresAt?: string;
340
+ playbackId?: string;
341
+ provider: string;
342
+ readyToStream: boolean;
343
+ /** True when the URLs below contain a signed token. */
344
+ signed: boolean;
345
+ /** True when the video requires signed playback URLs. */
346
+ signedPlayback: boolean;
347
+ status: null | VideoStatus;
348
+ token?: string;
349
+ /** null when the video requires signed URLs but the reader may not receive a token. */
350
+ urls: null | PlaybackUrls;
351
+ };
352
+ /** Result of `syncPending()` / `POST /sync-pending`. */
353
+ export type SyncPendingResult = {
354
+ /** Documents that were checked against their provider. */
355
+ checked: number;
356
+ /** Documents whose refresh failed (logged; retried on the next run). */
357
+ failed: number;
358
+ /** Documents whose asset no longer exists at the provider (marked as `error`). */
359
+ missing: number;
360
+ };
361
+ /** Result of `adoptExisting()`. */
362
+ export type AdoptExistingResult = {
363
+ /** Documents created for assets that weren't tracked yet. */
364
+ created: number;
365
+ /** Assets that already had a document. */
366
+ skipped: number;
367
+ };
368
+ /** Result of `createUpload()` / `POST /upload`. */
369
+ export type CreateUploadResult = {
370
+ /** The provider's asset id, when it exists already (not for Mux until the upload completes). */
371
+ assetId?: string;
372
+ /** Payload document id. */
373
+ id: number | string;
374
+ provider: string;
375
+ /** Where and how the browser sends the file. */
376
+ upload: DirectUpload;
377
+ };
378
+ /** The latest webhook delivery and rejection a server saw for a provider. */
379
+ export type WebhookHealth = {
380
+ /** The last accepted delivery; `matched` is false when it was about a video this site doesn't track. */
381
+ lastDelivery?: {
382
+ at: string;
383
+ matched: boolean;
384
+ };
385
+ /** The last refused delivery (bad signature, stale or malformed). */
386
+ lastRejection?: {
387
+ at: string;
388
+ reason: string;
389
+ status: number;
390
+ };
391
+ };
392
+ /** Result of `webhookStatus()` / `GET /webhooks`, one entry per provider. */
393
+ export type WebhookStatus = {
394
+ /** A webhook secret is set, so deliveries are verified and applied. */
395
+ configured: boolean;
396
+ label: string;
397
+ provider: string;
398
+ /** How to register the URL and where the secret comes from. */
399
+ setup?: WebhookSetup;
400
+ /** The provider can send webhooks. */
401
+ supported: boolean;
402
+ /** The endpoint to register with the provider (absolute when `serverURL` is set). */
403
+ url: string;
404
+ } & WebhookHealth;
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ /** Result of `webhookStatus()` / `GET /webhooks`, one entry per provider. */ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { VideoBlockArgs } from './blocks.js'\nimport type { CollectionConfig, PayloadRequest, TaskConfig } from 'payload'\n\nimport type { DirectUpload, PlaybackUrls, VideoProvider, WebhookSetup } from './core/provider.js'\nimport type { VideoStatus } from './core/status.js'\n\n/** The shape of a video document stored by the plugin. */\nexport type VideoDoc = {\n allowedOrigins?: null | string[]\n /** Provider id and asset id joined (`cloudflare:abc…`); unique, maintained by the plugin. */\n assetKey?: null | string\n /** The provider's asset id (Cloudflare uid, Mux asset id, Bunny guid). */\n assetId?: null | string\n captions?: null | {\n generated?: boolean | null\n id?: null | string\n label?: null | string\n language: string\n status?: null | string\n }[]\n createdAt?: string\n creator?: null | string\n downloads?: null | {\n audio?: null | string\n audioPercent?: null | number\n mp4?: null | string\n mp4Percent?: null | number\n }\n duration?: null | number\n error?: null | { code?: null | string; message?: null | string }\n height?: null | number\n id: number | string\n lastSyncedAt?: null | string\n meta?: null | Record<string, unknown>\n /** Review state, when `moderation` is on. */\n moderation?: null | VideoModerationStatus\n /** The user who uploaded the video, when `ownership` is on (an id, or the user when populated). */\n owner?: null | number | string | { id: number | string }\n /** Virtual: playback URLs, populated on read. */\n playback?: null | VideoPlayback\n /** Playback id, for providers that separate it from the asset id (Mux). */\n playbackId?: null | string\n /** Encoding progress 0–100, when the provider reports it. */\n progress?: null | number\n /** Id of the provider that stores the video, e.g. `cloudflare`. */\n provider?: null | string\n /** The provider's raw payload from the last sync (hidden). */\n providerData?: null | Record<string, unknown>\n readyAt?: null | string\n readyToStream?: boolean | null\n /** Previous asset, kept until a replacement upload is ready. */\n replacedAssetId?: null | string\n /** Playback requires a signed token. */\n signedPlayback?: boolean | null\n size?: null | number\n status?: null | VideoStatus\n /** Poster frame position in seconds. */\n thumbnailTime?: null | number\n title?: null | string\n updatedAt?: string\n uploadedAt?: null | string\n /** Pending upload id, for providers that create the asset in a second step (Mux). */\n uploadId?: null | string\n width?: null | number\n}\n\nexport type VideoAccessArgs = {\n /** The video document, when the operation targets an existing video. */\n doc?: VideoDoc\n req: PayloadRequest\n}\n\n/** Extra access check layered on top of the collection's own access control. */\nexport type VideoAccess = (args: VideoAccessArgs) => boolean | Promise<boolean>\n\nexport type VideoModerationStatus = 'approved' | 'pending' | 'rejected'\n\n/** Arguments of the lifecycle hooks (`hooks` option). */\nexport type VideoStatusChangeArgs = {\n doc: VideoDoc\n /** The document before the change; undefined when it was just created. */\n previousDoc?: VideoDoc\n /** null when the document was just created. */\n previousStatus: null | VideoStatus\n req: PayloadRequest\n status: VideoStatus\n}\n\nexport type VideoLifecycleHook = (args: VideoStatusChangeArgs) => Promise<void> | void\n\n/** What `upload.validate` is asked about. Exactly one of `size` (browser upload) or `url` (import) is set. */\nexport type VideoUploadCheck = {\n /** The document being replaced, if any. */\n doc?: VideoDoc\n filename?: string\n provider: string\n req: PayloadRequest\n size?: number\n /** MIME type reported by the browser, when known. */\n type?: string\n url?: string\n}\n\n/** The settings of `ownership`, resolved. */\nexport type ResolvedOwnership = {\n /** Who may change a video's owner. Server code without a user always may. */\n canAssign: (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n field: string\n /** The auth collection owners belong to. */\n relationTo: string\n}\n\n/** The settings of `moderation`, resolved. */\nexport type ResolvedModeration = {\n /** Who may approve or reject videos. Server code without a user always may. */\n canModerate: (args: { req: PayloadRequest }) => boolean | Promise<boolean>\n /** The status of a new video. */\n defaultStatus: (args: { canModerate: boolean; req: PayloadRequest }) => Promise<VideoModerationStatus> | VideoModerationStatus\n field: string\n}\n\nexport type VideoPluginOptions = {\n /**\n * Extra access checks. Collection access (read/create/update/delete) is always enforced first;\n * these let you restrict plugin-specific actions further.\n */\n access?: {\n /** Manage captions / downloads / sync. Default: collection `update` access. */\n manage?: VideoAccess\n /**\n * Who may receive playback URLs (including signed tokens) via the playback endpoint.\n * Default: anyone with collection `read` access to the video.\n */\n playback?: VideoAccess\n /** Create uploads / imports. Default: collection `create` access (or `update` when replacing). */\n upload?: VideoAccess\n }\n /** Collection customisation. */\n collection?: {\n /**\n * Access control for the videos collection, passed straight to Payload. Unset operations use\n * Payload's defaults (logged-in users only). For example, to show videos to visitors of a public\n * site: `{ read: () => true }`. Private videos stay protected by `signedPlayback` and\n * `access.playback`.\n */\n access?: CollectionConfig['access']\n /** Admin group label. Default: none. */\n adminGroup?: string\n /** Last chance to modify the generated collection config. */\n override?: (collection: CollectionConfig) => CollectionConfig\n /** Default: `videos` */\n slug?: string\n }\n /** Provider for new uploads when several are configured. Default: the first one. */\n defaultProvider?: string\n /**\n * Lifecycle hooks, called after a video's `status` changes, whatever changed it (a webhook, a sync,\n * the sync-pending task or a new upload). They run after the change is saved, inside the same\n * request, so keep them quick or queue a job. Errors are logged and never undo the change.\n */\n hooks?: {\n /** Every status change, including the first status of a new video (`previousStatus: null`). */\n afterStatusChange?: VideoLifecycleHook\n /** The video failed to upload or process (`status: 'error'`, details in `doc.error`). */\n onError?: VideoLifecycleHook\n /** The video can be played (`status: 'ready'`). */\n onReady?: VideoLifecycleHook\n }\n /**\n * Review new videos before they're shown: adds a `moderation` field (`pending`, `approved`,\n * `rejected`). It only records the decision: pair it with read access such as\n * `approvedOrOwner()` to hide unapproved videos. `true` uses the defaults below.\n */\n moderation?:\n | boolean\n | {\n /** Who may approve or reject. Default: users of the admin user collection (`admin.user`). */\n canModerate?: ResolvedModeration['canModerate']\n /** Status of new videos. Default: `approved` when the uploader may moderate, otherwise `pending`. */\n defaultStatus?: ResolvedModeration['defaultStatus']\n /** Field name. Default `moderation`. */\n field?: string\n }\n /**\n * Record who uploaded each video: adds an `owner` relationship, set from the logged-in user when a\n * video is created and protected from changes by other users. It doesn't restrict anything by\n * itself: use it in access control, e.g. `ownerOr(isAdmin)` from this package. `true` uses the\n * defaults below.\n */\n ownership?:\n | boolean\n | {\n /** Who may change a video's owner. Default: nobody (server code without a user always may). */\n canAssign?: ResolvedOwnership['canAssign']\n /** Field name. Default `owner`. */\n field?: string\n /** The auth collection of the uploaders. Default: the admin user collection (`admin.user`). */\n relationTo?: string\n }\n /** Delete the provider's asset when its document is deleted. Default: true. */\n deleteFromProvider?: boolean\n /**\n * Keeps the collection (so your schema/migrations stay stable) but disables endpoints, hooks\n * and admin components. `providers` may be empty.\n */\n disabled?: boolean\n /** Playback URL generation. */\n playback?: {\n /**\n * Extend signed tokens so they outlast the video: a video of `duration` seconds gets at least\n * `duration × factor + marginSeconds` (still capped at the provider's maximum), so a token never\n * expires while someone is watching. An explicit `expiresIn` passed to `getPlayback()` or the\n * playback endpoint takes precedence. Default `{ factor: 2, marginSeconds: 600 }`; `false` always\n * uses `expiresIn`.\n */\n coverDuration?: { factor?: number; marginSeconds?: number } | boolean\n /** Default signed token lifetime in seconds. Default 3600 (Cloudflare's maximum is 86400). */\n expiresIn?: number\n /**\n * Populate a virtual `playback` field on every read (REST, GraphQL, Local API).\n * Signed videos get a fresh token when the reader passes `access.playback`.\n * Default: true.\n */\n populateOnRead?: boolean\n /**\n * Visitors can watch the videos embedded in documents they can read (`videoField()`, video blocks,\n * rich text), even when they can't read the videos collection itself. Restricted videos are\n * excluded: signed playback, unapproved ones (with `moderation`), and those `access.playback`\n * denies. Video documents still can't be listed or fetched by id without read access.\n * Default true; `false` makes playback follow the videos collection's read access only.\n */\n embedded?: boolean\n }\n /** The video providers, e.g. `[cloudflareStream({ … })]`. Required unless `disabled`. */\n providers: VideoProvider[]\n /**\n * Registers a Payload jobs task that refreshes videos that are still processing. Use it when webhooks\n * aren't configured (or as a safety net), so documents reach `ready`/`error` even if nobody has the\n * admin open. Queue it yourself, or pass `cron` (or `schedule`) to run it automatically.\n */\n syncPendingTask?:\n | boolean\n | {\n /**\n * When `cron` is set, also add a `jobs.autoRun` entry for `queue` so the task runs without any\n * other configuration. Set to `false` if you run jobs yourself (e.g. a worker or `/api/payload-jobs/run`).\n * Default `true`.\n */\n autoRun?: boolean\n /** Max documents refreshed per run. Default 50. */\n batchSize?: number\n /**\n * How often to sync, as a cron expression: 5 fields, or 6 with seconds. For example\n * `'* * * * *'` (every minute) or `'*\\/5 * * * *'` (every 5 minutes). Env: `VIDEO_SYNC_CRON`.\n */\n cron?: string\n /** Jobs queue the task is scheduled on. Default `videos`. */\n queue?: string\n /** Full Payload jobs schedule. Takes precedence over `cron`/`queue`. */\n schedule?: TaskConfig['schedule']\n /** Task slug. Default `videoSyncPending`. */\n slug?: string\n }\n /** Defaults for new videos, for every provider. */\n upload?: {\n /**\n * File types browsers may upload through `POST /upload`: MIME types (`video/mp4`), wildcards\n * (`video/*`) or extensions (`.mp4`). Checked against the file name and the type the browser\n * reports. Default: any type (the provider rejects files it can't process).\n */\n allowedTypes?: string[]\n /** `creator` value stored on the video. Default: the uploading user's id. */\n creator?: (req: PayloadRequest) => string | undefined\n /**\n * Longest video, in seconds, for providers that enforce it at upload (Cloudflare). A request can\n * lower it but not raise it.\n */\n maxDurationSeconds?: number\n /** Largest file, in bytes, that browsers may upload through `POST /upload`. Default: no limit. */\n maxFileSize?: number\n /** New videos require signed playback URLs. Default false. */\n signedPlayback?: boolean\n /** Default poster frame position, in seconds. */\n thumbnailTime?: number\n /**\n * Your own check before every `POST /upload` and `POST /import`, e.g. a per-user quota. Return\n * `true` to allow it, or a message to refuse it (sent to the browser with status 400).\n */\n validate?: (args: VideoUploadCheck) => Promise<string | true> | string | true\n }\n /**\n * Register the video block in `config.blocks`, so blocks fields and Lexical can reference it by\n * slug (`videoBlockReferences('video')`, `BlocksFeature({ blocks: ['video'] })`).\n * Not needed when you use `videoBlock()` inline. Default false.\n */\n videoBlock?: boolean | Omit<VideoBlockArgs, 'collectionSlug'>\n}\n\nexport type ResolvedVideoOptions = {\n access: NonNullable<VideoPluginOptions['access']>\n collection: VideoPluginOptions['collection']\n collectionSlug: string\n defaultProvider?: string\n deleteFromProvider: boolean\n hooks: NonNullable<VideoPluginOptions['hooks']>\n moderation?: ResolvedModeration\n ownership?: ResolvedOwnership\n playback: {\n coverDuration: { factor: number; marginSeconds: number } | false\n expiresIn: number\n /** Longest token lifetime every configured provider accepts. */\n maxTokenTtlSeconds: number\n embedded: boolean\n populateOnRead: boolean\n }\n providers: VideoProvider[]\n syncPendingTask?: {\n autoRun: boolean\n batchSize: number\n cron?: string\n queue: string\n schedule?: TaskConfig['schedule']\n slug: string\n }\n upload: {\n allowedTypes?: string[]\n creator?: (req: PayloadRequest) => string | undefined\n maxDurationSeconds?: number\n maxFileSize?: number\n signedPlayback: boolean\n thumbnailTime?: number\n validate?: NonNullable<VideoPluginOptions['upload']>['validate']\n }\n}\n\n/** Result of the playback endpoint / server API, and the virtual `playback` field. */\nexport type VideoPlayback = {\n assetId: string\n /** ISO timestamp when the signed token expires. */\n expiresAt?: string\n playbackId?: string\n provider: string\n readyToStream: boolean\n /** True when the URLs below contain a signed token. */\n signed: boolean\n /** True when the video requires signed playback URLs. */\n signedPlayback: boolean\n status: null | VideoStatus\n token?: string\n /** null when the video requires signed URLs but the reader may not receive a token. */\n urls: null | PlaybackUrls\n}\n\n/** Result of `syncPending()` / `POST /sync-pending`. */\nexport type SyncPendingResult = {\n /** Documents that were checked against their provider. */\n checked: number\n /** Documents whose refresh failed (logged; retried on the next run). */\n failed: number\n /** Documents whose asset no longer exists at the provider (marked as `error`). */\n missing: number\n}\n\n/** Result of `adoptExisting()`. */\nexport type AdoptExistingResult = {\n /** Documents created for assets that weren't tracked yet. */\n created: number\n /** Assets that already had a document. */\n skipped: number\n}\n\n/** Result of `createUpload()` / `POST /upload`. */\nexport type CreateUploadResult = {\n /** The provider's asset id, when it exists already (not for Mux until the upload completes). */\n assetId?: string\n /** Payload document id. */\n id: number | string\n provider: string\n /** Where and how the browser sends the file. */\n upload: DirectUpload\n}\n\n/** The latest webhook delivery and rejection a server saw for a provider. */\nexport type WebhookHealth = {\n /** The last accepted delivery; `matched` is false when it was about a video this site doesn't track. */\n lastDelivery?: { at: string; matched: boolean }\n /** The last refused delivery (bad signature, stale or malformed). */\n lastRejection?: { at: string; reason: string; status: number }\n}\n\n/** Result of `webhookStatus()` / `GET /webhooks`, one entry per provider. */\nexport type WebhookStatus = {\n /** A webhook secret is set, so deliveries are verified and applied. */\n configured: boolean\n label: string\n provider: string\n /** How to register the URL and where the secret comes from. */\n setup?: WebhookSetup\n /** The provider can send webhooks. */\n supported: boolean\n /** The endpoint to register with the provider (absolute when `serverURL` is set). */\n url: string\n} & WebhookHealth\n"],"names":[],"mappings":"AAsYA,2EAA2E,GAC3E,WAWiB"}
@@ -0,0 +1,22 @@
1
+ import type { PayloadRequest, Where } from 'payload';
2
+ export type CollectionOperation = 'create' | 'delete' | 'read' | 'update';
3
+ /**
4
+ * Raw result of a collection's access function: `true`, `false`, or a where constraint.
5
+ * Without an access function, any logged-in user is allowed (Payload's default).
6
+ */
7
+ export declare const resolveCollectionAccess: ({ collectionSlug, operation, req, }: {
8
+ collectionSlug: string;
9
+ operation: CollectionOperation;
10
+ req: PayloadRequest;
11
+ }) => Promise<boolean | Where>;
12
+ /**
13
+ * Evaluates a collection's access control for an operation, the same way on Payload 3 and 4.
14
+ * Where-query results are resolved against the specific document id.
15
+ */
16
+ export declare const hasCollectionAccess: ({ id, collectionSlug, data, operation, req, }: {
17
+ collectionSlug: string;
18
+ data?: Record<string, unknown>;
19
+ id?: number | string;
20
+ operation: CollectionOperation;
21
+ req: PayloadRequest;
22
+ }) => Promise<boolean>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Raw result of a collection's access function: `true`, `false`, or a where constraint.
3
+ * Without an access function, any logged-in user is allowed (Payload's default).
4
+ */ export const resolveCollectionAccess = async ({ collectionSlug, operation, req })=>{
5
+ const collection = req.payload.collections[collectionSlug];
6
+ if (!collection) {
7
+ throw new Error(`[payload-video-streaming] collection "${collectionSlug}" not found`);
8
+ }
9
+ const accessFn = collection.config.access?.[operation];
10
+ if (!accessFn) {
11
+ return Boolean(req.user);
12
+ }
13
+ const result = await accessFn({
14
+ req
15
+ });
16
+ if (typeof result === 'boolean') {
17
+ return result;
18
+ }
19
+ return result && typeof result === 'object' ? result : false;
20
+ };
21
+ /**
22
+ * Evaluates a collection's access control for an operation, the same way on Payload 3 and 4.
23
+ * Where-query results are resolved against the specific document id.
24
+ */ export const hasCollectionAccess = async ({ id, collectionSlug, data, operation, req })=>{
25
+ const collection = req.payload.collections[collectionSlug];
26
+ if (!collection) {
27
+ throw new Error(`[payload-video-streaming] collection "${collectionSlug}" not found`);
28
+ }
29
+ const accessFn = collection.config.access?.[operation];
30
+ if (!accessFn) {
31
+ return Boolean(req.user);
32
+ }
33
+ const result = await accessFn({
34
+ id,
35
+ data,
36
+ req
37
+ });
38
+ if (typeof result === 'boolean') {
39
+ return result;
40
+ }
41
+ if (!result || typeof result !== 'object') {
42
+ return false;
43
+ }
44
+ if (id === undefined) {
45
+ // A where constraint without a specific document (e.g. create) – treat as allowed.
46
+ return true;
47
+ }
48
+ const { totalDocs } = await req.payload.count({
49
+ collection: collectionSlug,
50
+ overrideAccess: true,
51
+ req,
52
+ where: {
53
+ and: [
54
+ {
55
+ id: {
56
+ equals: id
57
+ }
58
+ },
59
+ result
60
+ ]
61
+ }
62
+ });
63
+ return totalDocs > 0;
64
+ };
65
+
66
+ //# sourceMappingURL=access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/access.ts"],"sourcesContent":["import type { PayloadRequest, Where } from 'payload'\n\nexport type CollectionOperation = 'create' | 'delete' | 'read' | 'update'\n\n/**\n * Raw result of a collection's access function: `true`, `false`, or a where constraint.\n * Without an access function, any logged-in user is allowed (Payload's default).\n */\nexport const resolveCollectionAccess = async ({\n collectionSlug,\n operation,\n req,\n}: {\n collectionSlug: string\n operation: CollectionOperation\n req: PayloadRequest\n}): Promise<boolean | Where> => {\n const collection = req.payload.collections[collectionSlug as keyof typeof req.payload.collections]\n if (!collection) {\n throw new Error(`[payload-video-streaming] collection \"${collectionSlug}\" not found`)\n }\n const accessFn = collection.config.access?.[operation] as\n | ((args: Record<string, unknown>) => boolean | Promise<boolean | Where> | Where)\n | undefined\n if (!accessFn) {\n return Boolean(req.user)\n }\n const result = await accessFn({ req })\n if (typeof result === 'boolean') {\n return result\n }\n return result && typeof result === 'object' ? result : false\n}\n\n/**\n * Evaluates a collection's access control for an operation, the same way on Payload 3 and 4.\n * Where-query results are resolved against the specific document id.\n */\nexport const hasCollectionAccess = async ({\n id,\n collectionSlug,\n data,\n operation,\n req,\n}: {\n collectionSlug: string\n data?: Record<string, unknown>\n id?: number | string\n operation: CollectionOperation\n req: PayloadRequest\n}): Promise<boolean> => {\n const collection = req.payload.collections[collectionSlug as keyof typeof req.payload.collections]\n if (!collection) {\n throw new Error(`[payload-video-streaming] collection \"${collectionSlug}\" not found`)\n }\n const accessFn = collection.config.access?.[operation] as\n | ((args: Record<string, unknown>) => boolean | Promise<boolean | Where> | Where)\n | undefined\n if (!accessFn) {\n return Boolean(req.user)\n }\n const result = await accessFn({ id, data, req })\n if (typeof result === 'boolean') {\n return result\n }\n if (!result || typeof result !== 'object') {\n return false\n }\n if (id === undefined) {\n // A where constraint without a specific document (e.g. create) – treat as allowed.\n return true\n }\n const { totalDocs } = await req.payload.count({\n collection: collectionSlug as never,\n overrideAccess: true,\n req,\n where: { and: [{ id: { equals: id } }, result] },\n })\n return totalDocs > 0\n}\n"],"names":["resolveCollectionAccess","collectionSlug","operation","req","collection","payload","collections","Error","accessFn","config","access","Boolean","user","result","hasCollectionAccess","id","data","undefined","totalDocs","count","overrideAccess","where","and","equals"],"mappings":"AAIA;;;CAGC,GACD,OAAO,MAAMA,0BAA0B,OAAO,EAC5CC,cAAc,EACdC,SAAS,EACTC,GAAG,EAKJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACL,eAAuD;IAClG,IAAI,CAACG,YAAY;QACf,MAAM,IAAIG,MAAM,CAAC,sCAAsC,EAAEN,eAAe,WAAW,CAAC;IACtF;IACA,MAAMO,WAAWJ,WAAWK,MAAM,CAACC,MAAM,EAAE,CAACR,UAAU;IAGtD,IAAI,CAACM,UAAU;QACb,OAAOG,QAAQR,IAAIS,IAAI;IACzB;IACA,MAAMC,SAAS,MAAML,SAAS;QAAEL;IAAI;IACpC,IAAI,OAAOU,WAAW,WAAW;QAC/B,OAAOA;IACT;IACA,OAAOA,UAAU,OAAOA,WAAW,WAAWA,SAAS;AACzD,EAAC;AAED;;;CAGC,GACD,OAAO,MAAMC,sBAAsB,OAAO,EACxCC,EAAE,EACFd,cAAc,EACde,IAAI,EACJd,SAAS,EACTC,GAAG,EAOJ;IACC,MAAMC,aAAaD,IAAIE,OAAO,CAACC,WAAW,CAACL,eAAuD;IAClG,IAAI,CAACG,YAAY;QACf,MAAM,IAAIG,MAAM,CAAC,sCAAsC,EAAEN,eAAe,WAAW,CAAC;IACtF;IACA,MAAMO,WAAWJ,WAAWK,MAAM,CAACC,MAAM,EAAE,CAACR,UAAU;IAGtD,IAAI,CAACM,UAAU;QACb,OAAOG,QAAQR,IAAIS,IAAI;IACzB;IACA,MAAMC,SAAS,MAAML,SAAS;QAAEO;QAAIC;QAAMb;IAAI;IAC9C,IAAI,OAAOU,WAAW,WAAW;QAC/B,OAAOA;IACT;IACA,IAAI,CAACA,UAAU,OAAOA,WAAW,UAAU;QACzC,OAAO;IACT;IACA,IAAIE,OAAOE,WAAW;QACpB,mFAAmF;QACnF,OAAO;IACT;IACA,MAAM,EAAEC,SAAS,EAAE,GAAG,MAAMf,IAAIE,OAAO,CAACc,KAAK,CAAC;QAC5Cf,YAAYH;QACZmB,gBAAgB;QAChBjB;QACAkB,OAAO;YAAEC,KAAK;gBAAC;oBAAEP,IAAI;wBAAEQ,QAAQR;oBAAG;gBAAE;gBAAGF;aAAO;QAAC;IACjD;IACA,OAAOK,YAAY;AACrB,EAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Payload, PayloadRequest } from 'payload';
2
+ /**
3
+ * Creates a server-side (Local API) request on both Payload 3 and Payload 4.
4
+ * - Payload 3: `createLocalReq(options, payload)`
5
+ * - Payload 4: `createPayloadRequest({ payload, ...options })` (in v3 that name builds a request
6
+ * from a web Request, so we must check for `createLocalReq` first).
7
+ */
8
+ export declare const createLocalRequest: (payload: Payload, options?: {
9
+ context?: Record<string, unknown>;
10
+ user?: PayloadRequest["user"];
11
+ }) => Promise<PayloadRequest>;
@@ -0,0 +1,23 @@
1
+ import * as payloadExports from 'payload';
2
+ /**
3
+ * Creates a server-side (Local API) request on both Payload 3 and Payload 4.
4
+ * - Payload 3: `createLocalReq(options, payload)`
5
+ * - Payload 4: `createPayloadRequest({ payload, ...options })` (in v3 that name builds a request
6
+ * from a web Request, so we must check for `createLocalReq` first).
7
+ */ export const createLocalRequest = async (payload, options = {})=>{
8
+ const exportsRecord = payloadExports;
9
+ const v3 = exportsRecord.createLocalReq;
10
+ if (typeof v3 === 'function') {
11
+ return v3(options, payload);
12
+ }
13
+ const v4 = exportsRecord.createPayloadRequest;
14
+ if (typeof v4 === 'function') {
15
+ return v4({
16
+ ...options,
17
+ payload
18
+ });
19
+ }
20
+ throw new Error('[payload-video-streaming] unsupported Payload version: cannot create a local request');
21
+ };
22
+
23
+ //# sourceMappingURL=localReq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/localReq.ts"],"sourcesContent":["import type { Payload, PayloadRequest } from 'payload'\n\nimport * as payloadExports from 'payload'\n\ntype AnyFn = (...args: unknown[]) => Promise<PayloadRequest>\n\n/**\n * Creates a server-side (Local API) request on both Payload 3 and Payload 4.\n * - Payload 3: `createLocalReq(options, payload)`\n * - Payload 4: `createPayloadRequest({ payload, ...options })` (in v3 that name builds a request\n * from a web Request, so we must check for `createLocalReq` first).\n */\nexport const createLocalRequest = async (\n payload: Payload,\n options: { context?: Record<string, unknown>; user?: PayloadRequest['user'] } = {},\n): Promise<PayloadRequest> => {\n const exportsRecord = payloadExports as unknown as Record<string, AnyFn | undefined>\n const v3 = exportsRecord.createLocalReq\n if (typeof v3 === 'function') {\n return v3(options, payload)\n }\n const v4 = exportsRecord.createPayloadRequest\n if (typeof v4 === 'function') {\n return v4({ ...options, payload })\n }\n throw new Error('[payload-video-streaming] unsupported Payload version: cannot create a local request')\n}\n"],"names":["payloadExports","createLocalRequest","payload","options","exportsRecord","v3","createLocalReq","v4","createPayloadRequest","Error"],"mappings":"AAEA,YAAYA,oBAAoB,UAAS;AAIzC;;;;;CAKC,GACD,OAAO,MAAMC,qBAAqB,OAChCC,SACAC,UAAgF,CAAC,CAAC;IAElF,MAAMC,gBAAgBJ;IACtB,MAAMK,KAAKD,cAAcE,cAAc;IACvC,IAAI,OAAOD,OAAO,YAAY;QAC5B,OAAOA,GAAGF,SAASD;IACrB;IACA,MAAMK,KAAKH,cAAcI,oBAAoB;IAC7C,IAAI,OAAOD,OAAO,YAAY;QAC5B,OAAOA,GAAG;YAAE,GAAGJ,OAAO;YAAED;QAAQ;IAClC;IACA,MAAM,IAAIO,MAAM;AAClB,EAAC"}
@@ -0,0 +1,12 @@
1
+ import type { PayloadRequest } from 'payload';
2
+ /**
3
+ * Small helpers that work identically on Payload 3 and Payload 4 endpoint requests.
4
+ */
5
+ export declare const jsonResponse: (body: unknown, init?: ResponseInit) => Response;
6
+ export declare const errorResponse: (status: number, message: string, extra?: Record<string, unknown>) => Response;
7
+ /** Reads the raw request body as text (needed for webhook signature verification). */
8
+ export declare const readRawBody: (req: PayloadRequest) => Promise<string>;
9
+ /** Reads and parses a JSON body, returning `{}` for empty bodies. Throws on invalid JSON. */
10
+ export declare const readJsonBody: <T extends Record<string, unknown>>(req: PayloadRequest) => Promise<Partial<T>>;
11
+ export declare const routeParam: (req: PayloadRequest, name: string) => string | undefined;
12
+ export declare const searchParam: (req: PayloadRequest, name: string) => string | undefined;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Small helpers that work identically on Payload 3 and Payload 4 endpoint requests.
3
+ */ export const jsonResponse = (body, init = {})=>Response.json(body, init);
4
+ export const errorResponse = (status, message, extra = {})=>Response.json({
5
+ errors: [
6
+ {
7
+ message
8
+ }
9
+ ],
10
+ ...extra
11
+ }, {
12
+ status
13
+ });
14
+ /** Reads the raw request body as text (needed for webhook signature verification). */ export const readRawBody = async (req)=>{
15
+ const r = req;
16
+ if (typeof r.text === 'function') {
17
+ return r.text();
18
+ }
19
+ return '';
20
+ };
21
+ /** Reads and parses a JSON body, returning `{}` for empty bodies. Throws on invalid JSON. */ export const readJsonBody = async (req)=>{
22
+ const preParsed = req.data;
23
+ if (preParsed && typeof preParsed === 'object') {
24
+ return preParsed;
25
+ }
26
+ const text = await readRawBody(req);
27
+ if (!text.trim()) {
28
+ return {};
29
+ }
30
+ const parsed = JSON.parse(text);
31
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
32
+ throw new SyntaxError('Expected a JSON object');
33
+ }
34
+ return parsed;
35
+ };
36
+ export const routeParam = (req, name)=>{
37
+ const value = req.routeParams?.[name];
38
+ return typeof value === 'string' && value ? decodeURIComponent(value) : undefined;
39
+ };
40
+ export const searchParam = (req, name)=>{
41
+ const fromSearchParams = req.searchParams?.get(name);
42
+ if (fromSearchParams) {
43
+ return fromSearchParams;
44
+ }
45
+ if (req.url) {
46
+ try {
47
+ return new URL(req.url, 'http://localhost').searchParams.get(name) ?? undefined;
48
+ } catch {
49
+ return undefined;
50
+ }
51
+ }
52
+ return undefined;
53
+ };
54
+
55
+ //# sourceMappingURL=request.js.map