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,144 @@
1
+ /**
2
+ * Bunny signatures, all built with node:crypto:
3
+ * - the tus upload signature (`AuthorizationSignature`)
4
+ * - the embed (iframe) view token
5
+ * - CDN "advanced" token authentication (`HS256-…`), including directory tokens for HLS
6
+ * @see https://bunny.net/docs/stream/tus-resumable-uploads
7
+ * @see https://bunny.net/docs/stream/token-authentication
8
+ * @see https://bunny.net/docs/cdn/security/token-authentication/advanced
9
+ */ import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
10
+ import { isIP } from 'node:net';
11
+ const sha256Hex = (value)=>createHash('sha256').update(value, 'utf8').digest('hex');
12
+ /** `AuthorizationSignature` for a tus upload: hex SHA256 of `libraryId + apiKey + expires + videoId`. */ export const tusUploadSignature = (args)=>sha256Hex(`${args.libraryId}${args.apiKey}${args.expires}${args.videoId}`);
13
+ /** Embed view token: hex SHA256 of `tokenKey + videoId + expires` (the library's token authentication key). */ export const embedViewToken = (args)=>sha256Hex(`${args.tokenKey}${args.videoId}${args.expires}`);
14
+ /** Constant-time comparison of two hex strings (case-insensitive). */ export const hexEquals = (a, b)=>{
15
+ if (!/^[0-9a-f]+$/i.test(a) || !/^[0-9a-f]+$/i.test(b) || a.length !== b.length) {
16
+ return false;
17
+ }
18
+ return timingSafeEqual(Buffer.from(a.toLowerCase(), 'hex'), Buffer.from(b.toLowerCase(), 'hex'));
19
+ };
20
+ /** The IP address as bytes for the CDN token: 4 bytes for IPv4, IPv6 masked to its /64 prefix. */ export const ipToTokenBytes = (ip)=>{
21
+ const family = isIP(ip);
22
+ if (family === 4) {
23
+ return Buffer.from(ip.split('.').map(Number));
24
+ }
25
+ if (family !== 6) {
26
+ throw new Error(`Invalid IP address "${ip}"`);
27
+ }
28
+ let value = ip;
29
+ let v4 = [];
30
+ const lastColon = value.lastIndexOf(':');
31
+ if (value.indexOf('.') > lastColon) {
32
+ v4 = value.slice(lastColon + 1).split('.').map(Number);
33
+ value = `${value.slice(0, lastColon)}:0:0`;
34
+ }
35
+ const [left = '', right] = value.split('::');
36
+ const head = left ? left.split(':') : [];
37
+ const tail = right ? right.split(':') : [];
38
+ const groups = right === undefined ? head : [
39
+ ...head,
40
+ ...Array(8 - head.length - tail.length).fill('0'),
41
+ ...tail
42
+ ];
43
+ const bytes = Buffer.alloc(16);
44
+ groups.forEach((group, i)=>bytes.writeUInt16BE(Number.parseInt(group, 16), i * 2));
45
+ v4.forEach((byte, i)=>bytes[12 + i] = byte);
46
+ bytes.fill(0, 8);
47
+ return bytes;
48
+ };
49
+ /** Computes an advanced CDN token (`HS256-…`) for a URL path. */ export const cdnToken = (key, path, options)=>{
50
+ if (!key) {
51
+ throw new Error('A CDN token authentication key is required');
52
+ }
53
+ const params = {};
54
+ if (options.countriesAllowed) {
55
+ params.token_countries = options.countriesAllowed;
56
+ }
57
+ if (options.countriesBlocked) {
58
+ params.token_countries_blocked = options.countriesBlocked;
59
+ }
60
+ if (options.tokenPath) {
61
+ params.token_path = options.tokenPath;
62
+ }
63
+ // Sorted by code point (the reference implementations agree on this for these keys).
64
+ const sorted = Object.entries(params).sort(([a], [b])=>a < b ? -1 : a > b ? 1 : 0);
65
+ const signingData = sorted.map(([k, v])=>`${k}=${v}`).join('&');
66
+ const ip = options.userIp ? ipToTokenBytes(options.userIp) : Buffer.alloc(0);
67
+ const digest = createHmac('sha256', key).update(options.tokenPath || path).update(String(options.expires)).update(ip).update(signingData).digest('base64url');
68
+ return {
69
+ params: sorted,
70
+ token: `HS256-${options.userIp ? '1-' : ''}${digest}`
71
+ };
72
+ };
73
+ /**
74
+ * Signs a CDN URL with advanced token authentication.
75
+ * - `directory: false`: `…/file?token=HS256-…&expires=…`
76
+ * - `directory: true`: `/bcdn_token=HS256-…&expires=…/file`, so relative URLs inside an HLS playlist
77
+ * (renditions, segments) inherit the token. Pass `tokenPath` to cover the whole directory.
78
+ */ export const signCdnUrl = (url, key, options)=>{
79
+ const parsed = new URL(url);
80
+ if (options.directory && parsed.search) {
81
+ throw new Error('Directory tokens do not support query parameters');
82
+ }
83
+ const { params, token } = cdnToken(key, parsed.pathname, options);
84
+ const tail = params.map(([k, v])=>`&${k}=${encodeURIComponent(v)}`).join('');
85
+ const base = `${parsed.protocol}//${parsed.host}`;
86
+ if (options.directory) {
87
+ return `${base}/bcdn_token=${token}${tail}&expires=${options.expires}${parsed.pathname}`;
88
+ }
89
+ const existing = parsed.search ? `${parsed.search}&` : '?';
90
+ return `${base}${parsed.pathname}${existing}token=${token}${tail}&expires=${options.expires}`;
91
+ };
92
+ /** Splits a path signed in directory form (`/bcdn_token=…&expires=…/rest`) into its token parameters and real path. */ export const parseDirectoryToken = (pathname)=>{
93
+ const match = /^\/(bcdn_token=[^/]*)(\/.*)$/.exec(pathname);
94
+ if (!match) {
95
+ return null;
96
+ }
97
+ return {
98
+ params: new URLSearchParams(match[1]),
99
+ path: match[2]
100
+ };
101
+ };
102
+ /**
103
+ * Verifies an advanced CDN token, as the CDN does (used by the fake; handy for your own tests).
104
+ * `params` are the request's token parameters (query string or directory segment).
105
+ */ export const verifyCdnToken = (key, path, params, { now = Math.floor(Date.now() / 1000), userIp } = {})=>{
106
+ const token = params.get('token') ?? params.get('bcdn_token');
107
+ const expires = Number(params.get('expires'));
108
+ if (!token || !Number.isFinite(expires)) {
109
+ return {
110
+ ok: false,
111
+ reason: 'missing'
112
+ };
113
+ }
114
+ if (expires < now) {
115
+ return {
116
+ ok: false,
117
+ reason: 'expired'
118
+ };
119
+ }
120
+ const tokenPath = params.get('token_path') ?? undefined;
121
+ if (tokenPath && !path.startsWith(tokenPath)) {
122
+ return {
123
+ ok: false,
124
+ reason: 'path'
125
+ };
126
+ }
127
+ const expected = cdnToken(key, path, {
128
+ countriesAllowed: params.get('token_countries') ?? undefined,
129
+ countriesBlocked: params.get('token_countries_blocked') ?? undefined,
130
+ expires,
131
+ tokenPath,
132
+ userIp: token.startsWith('HS256-1-') ? userIp : undefined
133
+ }).token;
134
+ const a = Buffer.from(token);
135
+ const b = Buffer.from(expected);
136
+ return a.length === b.length && timingSafeEqual(a, b) ? {
137
+ ok: true
138
+ } : {
139
+ ok: false,
140
+ reason: 'invalid'
141
+ };
142
+ };
143
+
144
+ //# sourceMappingURL=signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/bunny/signing.ts"],"sourcesContent":["/**\n * Bunny signatures, all built with node:crypto:\n * - the tus upload signature (`AuthorizationSignature`)\n * - the embed (iframe) view token\n * - CDN \"advanced\" token authentication (`HS256-…`), including directory tokens for HLS\n * @see https://bunny.net/docs/stream/tus-resumable-uploads\n * @see https://bunny.net/docs/stream/token-authentication\n * @see https://bunny.net/docs/cdn/security/token-authentication/advanced\n */\nimport { createHash, createHmac, timingSafeEqual } from 'node:crypto'\nimport { isIP } from 'node:net'\n\nconst sha256Hex = (value: string): string => createHash('sha256').update(value, 'utf8').digest('hex')\n\n/** `AuthorizationSignature` for a tus upload: hex SHA256 of `libraryId + apiKey + expires + videoId`. */\nexport const tusUploadSignature = (args: { apiKey: string; expires: number; libraryId: number | string; videoId: string }): string =>\n sha256Hex(`${args.libraryId}${args.apiKey}${args.expires}${args.videoId}`)\n\n/** Embed view token: hex SHA256 of `tokenKey + videoId + expires` (the library's token authentication key). */\nexport const embedViewToken = (args: { expires: number; tokenKey: string; videoId: string }): string =>\n sha256Hex(`${args.tokenKey}${args.videoId}${args.expires}`)\n\n/** Constant-time comparison of two hex strings (case-insensitive). */\nexport const hexEquals = (a: string, b: string): boolean => {\n if (!/^[0-9a-f]+$/i.test(a) || !/^[0-9a-f]+$/i.test(b) || a.length !== b.length) {\n return false\n }\n return timingSafeEqual(Buffer.from(a.toLowerCase(), 'hex'), Buffer.from(b.toLowerCase(), 'hex'))\n}\n\n/** The IP address as bytes for the CDN token: 4 bytes for IPv4, IPv6 masked to its /64 prefix. */\nexport const ipToTokenBytes = (ip: string): Buffer => {\n const family = isIP(ip)\n if (family === 4) {\n return Buffer.from(ip.split('.').map(Number))\n }\n if (family !== 6) {\n throw new Error(`Invalid IP address \"${ip}\"`)\n }\n let value = ip\n let v4: number[] = []\n const lastColon = value.lastIndexOf(':')\n if (value.indexOf('.') > lastColon) {\n v4 = value.slice(lastColon + 1).split('.').map(Number)\n value = `${value.slice(0, lastColon)}:0:0`\n }\n const [left = '', right] = value.split('::')\n const head = left ? left.split(':') : []\n const tail = right ? right.split(':') : []\n const groups = right === undefined ? head : [...head, ...Array<string>(8 - head.length - tail.length).fill('0'), ...tail]\n const bytes = Buffer.alloc(16)\n groups.forEach((group, i) => bytes.writeUInt16BE(Number.parseInt(group, 16), i * 2))\n v4.forEach((byte, i) => (bytes[12 + i] = byte))\n bytes.fill(0, 8)\n return bytes\n}\n\nexport type CdnTokenOptions = {\n /** Comma-separated ISO country codes allowed to use the token. */\n countriesAllowed?: string\n /** Comma-separated ISO country codes blocked from using the token. */\n countriesBlocked?: string\n /** Unix time (seconds) when the token expires. */\n expires: number\n /** Signs a directory: every file whose path starts with this (e.g. `/{guid}/`) is covered. */\n tokenPath?: string\n /** Lock the token to this IP (IPv6 is locked to its /64). */\n userIp?: string\n}\n\n/** Computes an advanced CDN token (`HS256-…`) for a URL path. */\nexport const cdnToken = (key: string, path: string, options: CdnTokenOptions): { params: [string, string][]; token: string } => {\n if (!key) {\n throw new Error('A CDN token authentication key is required')\n }\n const params: Record<string, string> = {}\n if (options.countriesAllowed) {\n params.token_countries = options.countriesAllowed\n }\n if (options.countriesBlocked) {\n params.token_countries_blocked = options.countriesBlocked\n }\n if (options.tokenPath) {\n params.token_path = options.tokenPath\n }\n // Sorted by code point (the reference implementations agree on this for these keys).\n const sorted = Object.entries(params).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))\n const signingData = sorted.map(([k, v]) => `${k}=${v}`).join('&')\n const ip = options.userIp ? ipToTokenBytes(options.userIp) : Buffer.alloc(0)\n const digest = createHmac('sha256', key)\n .update(options.tokenPath || path)\n .update(String(options.expires))\n .update(ip)\n .update(signingData)\n .digest('base64url')\n return { params: sorted, token: `HS256-${options.userIp ? '1-' : ''}${digest}` }\n}\n\n/**\n * Signs a CDN URL with advanced token authentication.\n * - `directory: false`: `…/file?token=HS256-…&expires=…`\n * - `directory: true`: `/bcdn_token=HS256-…&expires=…/file`, so relative URLs inside an HLS playlist\n * (renditions, segments) inherit the token. Pass `tokenPath` to cover the whole directory.\n */\nexport const signCdnUrl = (url: string, key: string, options: { directory?: boolean } & CdnTokenOptions): string => {\n const parsed = new URL(url)\n if (options.directory && parsed.search) {\n throw new Error('Directory tokens do not support query parameters')\n }\n const { params, token } = cdnToken(key, parsed.pathname, options)\n const tail = params.map(([k, v]) => `&${k}=${encodeURIComponent(v)}`).join('')\n const base = `${parsed.protocol}//${parsed.host}`\n if (options.directory) {\n return `${base}/bcdn_token=${token}${tail}&expires=${options.expires}${parsed.pathname}`\n }\n const existing = parsed.search ? `${parsed.search}&` : '?'\n return `${base}${parsed.pathname}${existing}token=${token}${tail}&expires=${options.expires}`\n}\n\n/** Splits a path signed in directory form (`/bcdn_token=…&expires=…/rest`) into its token parameters and real path. */\nexport const parseDirectoryToken = (pathname: string): { params: URLSearchParams; path: string } | null => {\n const match = /^\\/(bcdn_token=[^/]*)(\\/.*)$/.exec(pathname)\n if (!match) {\n return null\n }\n return { params: new URLSearchParams(match[1]!), path: match[2]! }\n}\n\n/**\n * Verifies an advanced CDN token, as the CDN does (used by the fake; handy for your own tests).\n * `params` are the request's token parameters (query string or directory segment).\n */\nexport const verifyCdnToken = (\n key: string,\n path: string,\n params: URLSearchParams,\n { now = Math.floor(Date.now() / 1000), userIp }: { now?: number; userIp?: string } = {},\n): { ok: true } | { ok: false; reason: 'expired' | 'invalid' | 'missing' | 'path' } => {\n const token = params.get('token') ?? params.get('bcdn_token')\n const expires = Number(params.get('expires'))\n if (!token || !Number.isFinite(expires)) {\n return { ok: false, reason: 'missing' }\n }\n if (expires < now) {\n return { ok: false, reason: 'expired' }\n }\n const tokenPath = params.get('token_path') ?? undefined\n if (tokenPath && !path.startsWith(tokenPath)) {\n return { ok: false, reason: 'path' }\n }\n const expected = cdnToken(key, path, {\n countriesAllowed: params.get('token_countries') ?? undefined,\n countriesBlocked: params.get('token_countries_blocked') ?? undefined,\n expires,\n tokenPath,\n userIp: token.startsWith('HS256-1-') ? userIp : undefined,\n }).token\n const a = Buffer.from(token)\n const b = Buffer.from(expected)\n return a.length === b.length && timingSafeEqual(a, b) ? { ok: true } : { ok: false, reason: 'invalid' }\n}\n"],"names":["createHash","createHmac","timingSafeEqual","isIP","sha256Hex","value","update","digest","tusUploadSignature","args","libraryId","apiKey","expires","videoId","embedViewToken","tokenKey","hexEquals","a","b","test","length","Buffer","from","toLowerCase","ipToTokenBytes","ip","family","split","map","Number","Error","v4","lastColon","lastIndexOf","indexOf","slice","left","right","head","tail","groups","undefined","Array","fill","bytes","alloc","forEach","group","i","writeUInt16BE","parseInt","byte","cdnToken","key","path","options","params","countriesAllowed","token_countries","countriesBlocked","token_countries_blocked","tokenPath","token_path","sorted","Object","entries","sort","signingData","k","v","join","userIp","String","token","signCdnUrl","url","parsed","URL","directory","search","pathname","encodeURIComponent","base","protocol","host","existing","parseDirectoryToken","match","exec","URLSearchParams","verifyCdnToken","now","Math","floor","Date","get","isFinite","ok","reason","startsWith","expected"],"mappings":"AAAA;;;;;;;;CAQC,GACD,SAASA,UAAU,EAAEC,UAAU,EAAEC,eAAe,QAAQ,cAAa;AACrE,SAASC,IAAI,QAAQ,WAAU;AAE/B,MAAMC,YAAY,CAACC,QAA0BL,WAAW,UAAUM,MAAM,CAACD,OAAO,QAAQE,MAAM,CAAC;AAE/F,uGAAuG,GACvG,OAAO,MAAMC,qBAAqB,CAACC,OACjCL,UAAU,GAAGK,KAAKC,SAAS,GAAGD,KAAKE,MAAM,GAAGF,KAAKG,OAAO,GAAGH,KAAKI,OAAO,EAAE,EAAC;AAE5E,6GAA6G,GAC7G,OAAO,MAA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1,153 @@
1
+ /**
2
+ * Hand-written types for the parts of the Bunny Stream API the plugin uses. They are checked against
3
+ * the types generated from Bunny's OpenAPI spec (`openapi.ts`, see `sdk-compat.ts`), but are kept
4
+ * separate so the published declarations never depend on the generated file.
5
+ * @see https://video.bunnycdn.com/openapi/bunnynet-video-api.public.json
6
+ */
7
+ /** `status` of a video in the Stream API (`VideoModelStatus`). */
8
+ export declare const BUNNY_VIDEO_STATUS: {
9
+ readonly Created: 0;
10
+ readonly Uploaded: 1;
11
+ readonly Processing: 2;
12
+ readonly Transcoding: 3;
13
+ readonly Finished: 4;
14
+ readonly Error: 5;
15
+ readonly UploadFailed: 6;
16
+ readonly JitSegmenting: 7;
17
+ readonly JitPlaylistsCreated: 8;
18
+ };
19
+ export type BunnyVideoStatus = (typeof BUNNY_VIDEO_STATUS)[keyof typeof BUNNY_VIDEO_STATUS];
20
+ /** `Status` of a webhook notification. These numbers differ from the API's `status`! */
21
+ export declare const BUNNY_WEBHOOK_STATUS: {
22
+ readonly Queued: 0;
23
+ readonly Processing: 1;
24
+ readonly Encoding: 2;
25
+ readonly Finished: 3;
26
+ readonly ResolutionFinished: 4;
27
+ readonly Failed: 5;
28
+ readonly PresignedUploadStarted: 6;
29
+ readonly PresignedUploadFinished: 7;
30
+ readonly PresignedUploadFailed: 8;
31
+ readonly CaptionsGenerated: 9;
32
+ readonly TitleOrDescriptionGenerated: 10;
33
+ readonly CaptionGenerationFailed: 11;
34
+ readonly ChaptersGenerated: 12;
35
+ readonly MomentsGenerated: 13;
36
+ readonly VideoDeleted: 32;
37
+ readonly SmartGenerationFailed: 33;
38
+ };
39
+ export type BunnyWebhookStatus = (typeof BUNNY_WEBHOOK_STATUS)[keyof typeof BUNNY_WEBHOOK_STATUS];
40
+ /** `IssueCodes` of a transcoding message, by number. */
41
+ export declare const BUNNY_ISSUE_CODES: readonly ["Undefined", "StreamLengthsDifference", "TranscodingWarnings", "IncompatibleResolution", "InvalidFramerate", "VideoExceededMaxDuration", "AudioExceededMaxDuration", "OriginalCorrupted", "TranscriptionFailed", "JitIncompatible", "JitFailed", "CaptionGenerationFailed", "UnsupportedFileType", "LiveNoEncoderCapacity", "LiveStreamBlocked", "LiveTooManyIngests", "LiveRegionConflict", "LivePublishAfterEnd", "LiveMediaStalled", "LiveEncoderLost", "LiveFailedOverToBackup", "LiveIngestRejected", "LiveIngestTimeout", "LiveMaxDurationReached", "LiveLibraryDisabled", "LiveDisconnectTimeout"];
42
+ export type BunnyCaption = {
43
+ label?: null | string;
44
+ srclang?: null | string;
45
+ version?: number;
46
+ };
47
+ export type BunnyMetaTag = {
48
+ property?: null | string;
49
+ value?: null | string;
50
+ };
51
+ export type BunnyTranscodingMessage = {
52
+ /** Number from `BUNNY_ISSUE_CODES`. */
53
+ issueCode?: number;
54
+ /** 0 Undefined, 1 Information, 2 Warning, 3 Error. */
55
+ level?: number;
56
+ message?: null | string;
57
+ timeStamp?: string;
58
+ value?: null | string;
59
+ };
60
+ /** A video as returned by `GET /library/{libraryId}/videos/{videoId}` (`VideoModel`, abridged). */
61
+ export type BunnyVideo = {
62
+ /** Comma-separated resolutions that finished encoding, e.g. `360p,720p`. */
63
+ availableResolutions?: null | string;
64
+ averageWatchTime?: number;
65
+ captions?: BunnyCaption[] | null;
66
+ category?: null | string;
67
+ collectionId?: null | string;
68
+ /** ISO date (Bunny may omit the time zone; it is UTC). */
69
+ dateUploaded: string;
70
+ description?: null | string;
71
+ /** Encoding progress, 0–100. */
72
+ encodeProgress: number;
73
+ framerate?: number;
74
+ guid: string;
75
+ /** MP4 fallback files (`play_720p.mp4`…) exist for this video. */
76
+ hasMP4Fallback: boolean;
77
+ height: number;
78
+ isPublic?: boolean;
79
+ jitEncodingEnabled?: boolean | null;
80
+ /** Duration in seconds. */
81
+ length: number;
82
+ metaTags?: BunnyMetaTag[] | null;
83
+ outputCodecs?: string;
84
+ status: BunnyVideoStatus;
85
+ /** Bytes. */
86
+ storageSize: number;
87
+ thumbnailCount?: number;
88
+ /** e.g. `thumbnail.jpg`. */
89
+ thumbnailFileName?: null | string;
90
+ title: string;
91
+ totalWatchTime?: number;
92
+ transcodingMessages?: BunnyTranscodingMessage[] | null;
93
+ videoLibraryId: number;
94
+ views?: number;
95
+ width: number;
96
+ };
97
+ /** `PaginationListOfVideoModel`. */
98
+ export type BunnyVideoList = {
99
+ currentPage?: number;
100
+ items?: BunnyVideo[] | null;
101
+ itemsPerPage?: number;
102
+ totalItems?: number;
103
+ };
104
+ /** `StatusModel`, the body of most write responses and of errors. */
105
+ export type BunnyStatusModel = {
106
+ message?: null | string;
107
+ statusCode?: number;
108
+ success?: boolean;
109
+ };
110
+ export type BunnyCreateVideoRequest = {
111
+ collectionId?: null | string;
112
+ /** Poster position in milliseconds. */
113
+ thumbnailTime?: null | number;
114
+ title: string;
115
+ };
116
+ export type BunnyUpdateVideoRequest = {
117
+ collectionId?: null | string;
118
+ metaTags?: BunnyMetaTag[] | null;
119
+ title?: null | string;
120
+ };
121
+ export type BunnyFetchVideoRequest = {
122
+ headers?: null | Record<string, string>;
123
+ title?: null | string;
124
+ url: string;
125
+ };
126
+ export type BunnyAddCaptionRequest = {
127
+ /** Base64-encoded caption file. */
128
+ captionsFile?: null | string;
129
+ label?: null | string;
130
+ /** Deprecated by Bunny (the path segment wins), still sent for older API versions. */
131
+ srclang?: null | string;
132
+ };
133
+ export type BunnyTranscribeRequest = {
134
+ generateChapters?: boolean | null;
135
+ generateDescription?: boolean | null;
136
+ generateMoments?: boolean | null;
137
+ generateTitle?: boolean | null;
138
+ /** ISO 639-1. Detected automatically when omitted. */
139
+ sourceLanguage?: null | string;
140
+ /** ISO 639-1 codes. */
141
+ targetLanguages?: null | string[];
142
+ };
143
+ /** The JSON body of a Bunny Stream webhook. */
144
+ export type BunnyWebhookPayload = {
145
+ EventId?: string;
146
+ IsLiveStreamWebhook?: boolean;
147
+ Reason?: null | string;
148
+ Status: number;
149
+ /** UTC timestamp of the event. */
150
+ Timestamp?: string;
151
+ VideoGuid: string;
152
+ VideoLibraryId: number | string;
153
+ };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Hand-written types for the parts of the Bunny Stream API the plugin uses. They are checked against
3
+ * the types generated from Bunny's OpenAPI spec (`openapi.ts`, see `sdk-compat.ts`), but are kept
4
+ * separate so the published declarations never depend on the generated file.
5
+ * @see https://video.bunnycdn.com/openapi/bunnynet-video-api.public.json
6
+ */ /** `status` of a video in the Stream API (`VideoModelStatus`). */ export const BUNNY_VIDEO_STATUS = {
7
+ Created: 0,
8
+ Uploaded: 1,
9
+ Processing: 2,
10
+ Transcoding: 3,
11
+ Finished: 4,
12
+ Error: 5,
13
+ UploadFailed: 6,
14
+ JitSegmenting: 7,
15
+ JitPlaylistsCreated: 8
16
+ };
17
+ /** `Status` of a webhook notification. These numbers differ from the API's `status`! */ export const BUNNY_WEBHOOK_STATUS = {
18
+ Queued: 0,
19
+ Processing: 1,
20
+ Encoding: 2,
21
+ Finished: 3,
22
+ ResolutionFinished: 4,
23
+ Failed: 5,
24
+ PresignedUploadStarted: 6,
25
+ PresignedUploadFinished: 7,
26
+ PresignedUploadFailed: 8,
27
+ CaptionsGenerated: 9,
28
+ TitleOrDescriptionGenerated: 10,
29
+ CaptionGenerationFailed: 11,
30
+ ChaptersGenerated: 12,
31
+ MomentsGenerated: 13,
32
+ VideoDeleted: 32,
33
+ SmartGenerationFailed: 33
34
+ };
35
+ /** `IssueCodes` of a transcoding message, by number. */ export const BUNNY_ISSUE_CODES = [
36
+ 'Undefined',
37
+ 'StreamLengthsDifference',
38
+ 'TranscodingWarnings',
39
+ 'IncompatibleResolution',
40
+ 'InvalidFramerate',
41
+ 'VideoExceededMaxDuration',
42
+ 'AudioExceededMaxDuration',
43
+ 'OriginalCorrupted',
44
+ 'TranscriptionFailed',
45
+ 'JitIncompatible',
46
+ 'JitFailed',
47
+ 'CaptionGenerationFailed',
48
+ 'UnsupportedFileType',
49
+ 'LiveNoEncoderCapacity',
50
+ 'LiveStreamBlocked',
51
+ 'LiveTooManyIngests',
52
+ 'LiveRegionConflict',
53
+ 'LivePublishAfterEnd',
54
+ 'LiveMediaStalled',
55
+ 'LiveEncoderLost',
56
+ 'LiveFailedOverToBackup',
57
+ 'LiveIngestRejected',
58
+ 'LiveIngestTimeout',
59
+ 'LiveMaxDurationReached',
60
+ 'LiveLibraryDisabled',
61
+ 'LiveDisconnectTimeout'
62
+ ];
63
+
64
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/bunny/types.ts"],"sourcesContent":["/**\n * Hand-written types for the parts of the Bunny Stream API the plugin uses. They are checked against\n * the types generated from Bunny's OpenAPI spec (`openapi.ts`, see `sdk-compat.ts`), but are kept\n * separate so the published declarations never depend on the generated file.\n * @see https://video.bunnycdn.com/openapi/bunnynet-video-api.public.json\n */\n\n/** `status` of a video in the Stream API (`VideoModelStatus`). */\nexport const BUNNY_VIDEO_STATUS = {\n Created: 0,\n Uploaded: 1,\n Processing: 2,\n Transcoding: 3,\n Finished: 4,\n Error: 5,\n UploadFailed: 6,\n JitSegmenting: 7,\n JitPlaylistsCreated: 8,\n} as const\n\nexport type BunnyVideoStatus = (typeof BUNNY_VIDEO_STATUS)[keyof typeof BUNNY_VIDEO_STATUS]\n\n/** `Status` of a webhook notification. These numbers differ from the API's `status`! */\nexport const BUNNY_WEBHOOK_STATUS = {\n Queued: 0,\n Processing: 1,\n Encoding: 2,\n Finished: 3,\n ResolutionFinished: 4,\n Failed: 5,\n PresignedUploadStarted: 6,\n PresignedUploadFinished: 7,\n PresignedUploadFailed: 8,\n CaptionsGenerated: 9,\n TitleOrDescriptionGenerated: 10,\n CaptionGenerationFailed: 11,\n ChaptersGenerated: 12,\n MomentsGenerated: 13,\n VideoDeleted: 32,\n SmartGenerationFailed: 33,\n} as const\n\nexport type BunnyWebhookStatus = (typeof BUNNY_WEBHOOK_STATUS)[keyof typeof BUNNY_WEBHOOK_STATUS]\n\n/** `IssueCodes` of a transcoding message, by number. */\nexport const BUNNY_ISSUE_CODES = [\n 'Undefined',\n 'StreamLengthsDifference',\n 'TranscodingWarnings',\n 'IncompatibleResolution',\n 'InvalidFramerate',\n 'VideoExceededMaxDuration',\n 'AudioExceededMaxDuration',\n 'OriginalCorrupted',\n 'TranscriptionFailed',\n 'JitIncompatible',\n 'JitFailed',\n 'CaptionGenerationFailed',\n 'UnsupportedFileType',\n 'LiveNoEncoderCapacity',\n 'LiveStreamBlocked',\n 'LiveTooManyIngests',\n 'LiveRegionConflict',\n 'LivePublishAfterEnd',\n 'LiveMediaStalled',\n 'LiveEncoderLost',\n 'LiveFailedOverToBackup',\n 'LiveIngestRejected',\n 'LiveIngestTimeout',\n 'LiveMaxDurationReached',\n 'LiveLibraryDisabled',\n 'LiveDisconnectTimeout',\n] as const\n\nexport type BunnyCaption = {\n label?: null | string\n srclang?: null | string\n version?: number\n}\n\nexport type BunnyMetaTag = { property?: null | string; value?: null | string }\n\nexport type BunnyTranscodingMessage = {\n /** Number from `BUNNY_ISSUE_CODES`. */\n issueCode?: number\n /** 0 Undefined, 1 Information, 2 Warning, 3 Error. */\n level?: number\n message?: null | string\n timeStamp?: string\n value?: null | string\n}\n\n/** A video as returned by `GET /library/{libraryId}/videos/{videoId}` (`VideoModel`, abridged). */\nexport type BunnyVideo = {\n /** Comma-separated resolutions that finished encoding, e.g. `360p,720p`. */\n availableResolutions?: null | string\n averageWatchTime?: number\n captions?: BunnyCaption[] | null\n category?: null | string\n collectionId?: null | string\n /** ISO date (Bunny may omit the time zone; it is UTC). */\n dateUploaded: string\n description?: null | string\n /** Encoding progress, 0–100. */\n encodeProgress: number\n framerate?: number\n guid: string\n /** MP4 fallback files (`play_720p.mp4`…) exist for this video. */\n hasMP4Fallback: boolean\n height: number\n isPublic?: boolean\n jitEncodingEnabled?: boolean | null\n /** Duration in seconds. */\n length: number\n metaTags?: BunnyMetaTag[] | null\n outputCodecs?: string\n status: BunnyVideoStatus\n /** Bytes. */\n storageSize: number\n thumbnailCount?: number\n /** e.g. `thumbnail.jpg`. */\n thumbnailFileName?: null | string\n title: string\n totalWatchTime?: number\n transcodingMessages?: BunnyTranscodingMessage[] | null\n videoLibraryId: number\n views?: number\n width: number\n}\n\n/** `PaginationListOfVideoModel`. */\nexport type BunnyVideoList = {\n currentPage?: number\n items?: BunnyVideo[] | null\n itemsPerPage?: number\n totalItems?: number\n}\n\n/** `StatusModel`, the body of most write responses and of errors. */\nexport type BunnyStatusModel = {\n message?: null | string\n statusCode?: number\n success?: boolean\n}\n\nexport type BunnyCreateVideoRequest = {\n collectionId?: null | string\n /** Poster position in milliseconds. */\n thumbnailTime?: null | number\n title: string\n}\n\nexport type BunnyUpdateVideoRequest = {\n collectionId?: null | string\n metaTags?: BunnyMetaTag[] | null\n title?: null | string\n}\n\nexport type BunnyFetchVideoRequest = {\n headers?: null | Record<string, string>\n title?: null | string\n url: string\n}\n\nexport type BunnyAddCaptionRequest = {\n /** Base64-encoded caption file. */\n captionsFile?: null | string\n label?: null | string\n /** Deprecated by Bunny (the path segment wins), still sent for older API versions. */\n srclang?: null | string\n}\n\nexport type BunnyTranscribeRequest = {\n generateChapters?: boolean | null\n generateDescription?: boolean | null\n generateMoments?: boolean | null\n generateTitle?: boolean | null\n /** ISO 639-1. Detected automatically when omitted. */\n sourceLanguage?: null | string\n /** ISO 639-1 codes. */\n targetLanguages?: null | string[]\n}\n\n/** The JSON body of a Bunny Stream webhook. */\nexport type BunnyWebhookPayload = {\n EventId?: string\n IsLiveStreamWebhook?: boolean\n Reason?: null | string\n Status: number\n /** UTC timestamp of the event. */\n Timestamp?: string\n VideoGuid: string\n VideoLibraryId: number | string\n}\n"],"names":["BUNNY_VIDEO_STATUS","Created","Uploaded","Processing","Transcoding","Finished","Error","UploadFailed","JitSegmenting","JitPlaylistsCreated","BUNNY_WEBHOOK_STATUS","Queued","Encoding","ResolutionFinished","Failed","PresignedUploadStarted","PresignedUploadFinished","PresignedUploadFailed","CaptionsGenerated","TitleOrDescriptionGenerated","CaptionGenerationFailed","ChaptersGenerated","MomentsGenerated","VideoDeleted","SmartGenerationFailed","BUNNY_ISSUE_CODES"],"mappings":"AAAA;;;;;CAKC,GAED,gEAAgE,GAChE,OAAO,MAAMA,qBAAqB;IAChCC,SAAS;IACTC,UAAU;IACVC,YAAY;IACZC,aAAa;IACbC,UAAU;IACVC,OAAO;IACPC,cAAc;IACdC,eAAe;IACfC,qBAAqB;AACvB,EAAU;AAIV,sFAAsF,GACtF,OAAO,MAAMC,uBAAuB;IAClCC,QAAQ;IACRR,YAAY;IACZS,UAAU;IACVP,UAAU;IACVQ,oBAAoB;IACpBC,QAAQ;IACRC,wBAAwB;IACxBC,yBAAyB;IACzBC,uBAAuB;IACvBC,mBAAmB;IACnBC,6BAA6B;IAC7BC,yBAAyB;IACzBC,mBAAmB;IACnBC,kBAAkB;IAClBC,cAAc;IACdC,uBAAuB;AACzB,EAAU;AAIV,sDAAsD,GACtD,OAAO,MAAMC,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS"}
@@ -0,0 +1,49 @@
1
+ export declare const BUNNY_EMBED_BASE_URL = "https://player.mediadelivery.net";
2
+ /** Bunny player (iframe) options. Bunny's player autoplays unless told otherwise. */
3
+ export type BunnyIframeOptions = {
4
+ autoplay?: boolean;
5
+ /** Caption language shown by default, e.g. `en` (auto captions: `en-auto`). */
6
+ captions?: string;
7
+ loop?: boolean;
8
+ muted?: boolean;
9
+ playsinline?: boolean;
10
+ preload?: boolean;
11
+ /** Adds `responsive=true` (seen in Bunny's examples; not in its parameter table). */
12
+ responsive?: boolean;
13
+ /** Start position: seconds, or a Bunny time string such as `1m30s`. */
14
+ startTime?: number | string;
15
+ };
16
+ /** `{cdn}/{guid}/{file}` */
17
+ export declare const cdnFileUrl: (cdnBaseUrl: string, guid: string, file: string) => string;
18
+ export declare const hlsUrl: (cdnBaseUrl: string, guid: string) => string;
19
+ export declare const thumbnailUrl: (cdnBaseUrl: string, guid: string, file?: string) => string;
20
+ export declare const previewUrl: (cdnBaseUrl: string, guid: string, format?: "gif" | "webp") => string;
21
+ export declare const mp4Url: (cdnBaseUrl: string, guid: string, file?: string) => string;
22
+ export declare const captionsUrl: (cdnBaseUrl: string, guid: string, language: string) => string;
23
+ /** Player query parameters. `autoplay` is always explicit. */
24
+ export declare const iframeParams: (options?: BunnyIframeOptions) => Record<string, string>;
25
+ /** The embeddable player, `https://player.mediadelivery.net/embed/{libraryId}/{guid}`, optionally with a view token. */
26
+ export declare const embedUrl: (embedBaseUrl: string, libraryId: number | string, guid: string, options?: BunnyIframeOptions, token?: {
27
+ expires: number;
28
+ token: string;
29
+ }) => string;
30
+ /** Signs the embed URL of a video with the library's embed token key. */
31
+ export declare const signedEmbedUrl: (args: {
32
+ embedBaseUrl: string;
33
+ expires: number;
34
+ libraryId: number | string;
35
+ tokenKey: string;
36
+ videoId: string;
37
+ }, options?: BunnyIframeOptions) => string;
38
+ export type BunnySignedFile = (file: string, options?: {
39
+ directory?: boolean;
40
+ }) => string;
41
+ /**
42
+ * A signer for every file of one video: one CDN token scoped to the video's directory
43
+ * (`token_path=/{guid}/`). HLS uses the path form so segment requests inherit the token.
44
+ */
45
+ export declare const videoFileSigner: (cdnBaseUrl: string, guid: string, args: {
46
+ countries?: string;
47
+ expires: number;
48
+ key: string;
49
+ }) => BunnySignedFile;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Bunny Stream delivery URLs: files on the library's CDN hostname and the embeddable player.
3
+ * @see https://bunny.net/docs/stream/storage-structure
4
+ * @see https://bunny.net/docs/stream/embedding
5
+ */ import { embedViewToken, signCdnUrl } from './signing.js';
6
+ export const BUNNY_EMBED_BASE_URL = 'https://player.mediadelivery.net';
7
+ const assertGuid = (guid)=>{
8
+ if (!guid || /[/?#\s]/.test(guid)) {
9
+ throw new Error(`Invalid Bunny Stream video id: "${guid}"`);
10
+ }
11
+ return encodeURIComponent(guid);
12
+ };
13
+ const base = (cdnBaseUrl)=>cdnBaseUrl.replace(/\/+$/, '');
14
+ /** `{cdn}/{guid}/{file}` */ export const cdnFileUrl = (cdnBaseUrl, guid, file)=>`${base(cdnBaseUrl)}/${assertGuid(guid)}/${file}`;
15
+ export const hlsUrl = (cdnBaseUrl, guid)=>cdnFileUrl(cdnBaseUrl, guid, 'playlist.m3u8');
16
+ export const thumbnailUrl = (cdnBaseUrl, guid, file = 'thumbnail.jpg')=>cdnFileUrl(cdnBaseUrl, guid, file);
17
+ export const previewUrl = (cdnBaseUrl, guid, format = 'webp')=>cdnFileUrl(cdnBaseUrl, guid, `preview.${format}`);
18
+ export const mp4Url = (cdnBaseUrl, guid, file = 'play_720p.mp4')=>cdnFileUrl(cdnBaseUrl, guid, file);
19
+ export const captionsUrl = (cdnBaseUrl, guid, language)=>cdnFileUrl(cdnBaseUrl, guid, `captions/${encodeURIComponent(language)}.vtt`);
20
+ /** Player query parameters. `autoplay` is always explicit. */ export const iframeParams = (options = {})=>{
21
+ const params = {
22
+ autoplay: options.autoplay ? 'true' : 'false'
23
+ };
24
+ const set = (key, value)=>{
25
+ if (value !== undefined && value !== '') {
26
+ params[key] = String(value);
27
+ }
28
+ };
29
+ set('muted', options.muted);
30
+ set('loop', options.loop);
31
+ set('preload', options.preload);
32
+ set('playsinline', options.playsinline);
33
+ set('captions', options.captions);
34
+ set('responsive', options.responsive);
35
+ set('t', typeof options.startTime === 'number' ? `${options.startTime}s` : options.startTime);
36
+ return params;
37
+ };
38
+ /** The embeddable player, `https://player.mediadelivery.net/embed/{libraryId}/{guid}`, optionally with a view token. */ export const embedUrl = (embedBaseUrl, libraryId, guid, options = {}, token)=>{
39
+ const url = new URL(`${base(embedBaseUrl)}/embed/${encodeURIComponent(String(libraryId))}/${assertGuid(guid)}`);
40
+ for (const [key, value] of Object.entries(iframeParams(options))){
41
+ url.searchParams.set(key, value);
42
+ }
43
+ if (token) {
44
+ url.searchParams.set('token', token.token);
45
+ url.searchParams.set('expires', String(token.expires));
46
+ }
47
+ return url.toString();
48
+ };
49
+ /** Signs the embed URL of a video with the library's embed token key. */ export const signedEmbedUrl = (args, options = {})=>embedUrl(args.embedBaseUrl, args.libraryId, args.videoId, options, {
50
+ expires: args.expires,
51
+ token: embedViewToken({
52
+ expires: args.expires,
53
+ tokenKey: args.tokenKey,
54
+ videoId: args.videoId
55
+ })
56
+ });
57
+ /**
58
+ * A signer for every file of one video: one CDN token scoped to the video's directory
59
+ * (`token_path=/{guid}/`). HLS uses the path form so segment requests inherit the token.
60
+ */ export const videoFileSigner = (cdnBaseUrl, guid, args)=>{
61
+ const tokenPath = new URL(`${base(cdnBaseUrl)}/${assertGuid(guid)}/`).pathname;
62
+ return (file, { directory = false } = {})=>signCdnUrl(cdnFileUrl(cdnBaseUrl, guid, file), args.key, {
63
+ countriesAllowed: args.countries,
64
+ directory,
65
+ expires: args.expires,
66
+ tokenPath
67
+ });
68
+ };
69
+
70
+ //# sourceMappingURL=urls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/providers/bunny/urls.ts"],"sourcesContent":["/**\n * Bunny Stream delivery URLs: files on the library's CDN hostname and the embeddable player.\n * @see https://bunny.net/docs/stream/storage-structure\n * @see https://bunny.net/docs/stream/embedding\n */\nimport { embedViewToken, signCdnUrl } from './signing.js'\n\nexport const BUNNY_EMBED_BASE_URL = 'https://player.mediadelivery.net'\n\n/** Bunny player (iframe) options. Bunny's player autoplays unless told otherwise. */\nexport type BunnyIframeOptions = {\n autoplay?: boolean\n /** Caption language shown by default, e.g. `en` (auto captions: `en-auto`). */\n captions?: string\n loop?: boolean\n muted?: boolean\n playsinline?: boolean\n preload?: boolean\n /** Adds `responsive=true` (seen in Bunny's examples; not in its parameter table). */\n responsive?: boolean\n /** Start position: seconds, or a Bunny time string such as `1m30s`. */\n startTime?: number | string\n}\n\nconst assertGuid = (guid: string): string => {\n if (!guid || /[/?#\\s]/.test(guid)) {\n throw new Error(`Invalid Bunny Stream video id: \"${guid}\"`)\n }\n return encodeURIComponent(guid)\n}\n\nconst base = (cdnBaseUrl: string) => cdnBaseUrl.replace(/\\/+$/, '')\n\n/** `{cdn}/{guid}/{file}` */\nexport const cdnFileUrl = (cdnBaseUrl: string, guid: string, file: string): string => `${base(cdnBaseUrl)}/${assertGuid(guid)}/${file}`\n\nexport const hlsUrl = (cdnBaseUrl: string, guid: string): string => cdnFileUrl(cdnBaseUrl, guid, 'playlist.m3u8')\n\nexport const thumbnailUrl = (cdnBaseUrl: string, guid: string, file = 'thumbnail.jpg'): string => cdnFileUrl(cdnBaseUrl, guid, file)\n\nexport const previewUrl = (cdnBaseUrl: string, guid: string, format: 'gif' | 'webp' = 'webp'): string =>\n cdnFileUrl(cdnBaseUrl, guid, `preview.${format}`)\n\nexport const mp4Url = (cdnBaseUrl: string, guid: string, file = 'play_720p.mp4'): string => cdnFileUrl(cdnBaseUrl, guid, file)\n\nexport const captionsUrl = (cdnBaseUrl: string, guid: string, language: string): string =>\n cdnFileUrl(cdnBaseUrl, guid, `captions/${encodeURIComponent(language)}.vtt`)\n\n/** Player query parameters. `autoplay` is always explicit. */\nexport const iframeParams = (options: BunnyIframeOptions = {}): Record<string, string> => {\n const params: Record<string, string> = { autoplay: options.autoplay ? 'true' : 'false' }\n const set = (key: string, value: boolean | number | string | undefined) => {\n if (value !== undefined && value !== '') {\n params[key] = String(value)\n }\n }\n set('muted', options.muted)\n set('loop', options.loop)\n set('preload', options.preload)\n set('playsinline', options.playsinline)\n set('captions', options.captions)\n set('responsive', options.responsive)\n set('t', typeof options.startTime === 'number' ? `${options.startTime}s` : options.startTime)\n return params\n}\n\n/** The embeddable player, `https://player.mediadelivery.net/embed/{libraryId}/{guid}`, optionally with a view token. */\nexport const embedUrl = (\n embedBaseUrl: string,\n libraryId: number | string,\n guid: string,\n options: BunnyIframeOptions = {},\n token?: { expires: number; token: string },\n): string => {\n const url = new URL(`${base(embedBaseUrl)}/embed/${encodeURIComponent(String(libraryId))}/${assertGuid(guid)}`)\n for (const [key, value] of Object.entries(iframeParams(options))) {\n url.searchParams.set(key, value)\n }\n if (token) {\n url.searchParams.set('token', token.token)\n url.searchParams.set('expires', String(token.expires))\n }\n return url.toString()\n}\n\n/** Signs the embed URL of a video with the library's embed token key. */\nexport const signedEmbedUrl = (\n args: { embedBaseUrl: string; expires: number; libraryId: number | string; tokenKey: string; videoId: string },\n options: BunnyIframeOptions = {},\n): string =>\n embedUrl(args.embedBaseUrl, args.libraryId, args.videoId, options, {\n expires: args.expires,\n token: embedViewToken({ expires: args.expires, tokenKey: args.tokenKey, videoId: args.videoId }),\n })\n\nexport type BunnySignedFile = (file: string, options?: { directory?: boolean }) => string\n\n/**\n * A signer for every file of one video: one CDN token scoped to the video's directory\n * (`token_path=/{guid}/`). HLS uses the path form so segment requests inherit the token.\n */\nexport const videoFileSigner = (\n cdnBaseUrl: string,\n guid: string,\n args: { countries?: string; expires: number; key: string },\n): BunnySignedFile => {\n const tokenPath = new URL(`${base(cdnBaseUrl)}/${assertGuid(guid)}/`).pathname\n return (file, { directory = false } = {}) =>\n signCdnUrl(cdnFileUrl(cdnBaseUrl, guid, file), args.key, {\n countriesAllowed: args.countries,\n directory,\n expires: args.expires,\n tokenPath,\n })\n}\n"],"names":["embedViewToken","signCdnUrl","BUNNY_EMBED_BASE_URL","assertGuid","guid","test","Error","encodeURIComponent","base","cdnBaseUrl","replace","cdnFileUrl","file","hlsUrl","thumbnailUrl","previewUrl","format","mp4Url","captionsUrl","language","iframeParams","options","params","autoplay","set","key","value","undefined","String","muted","loop","preload","playsinline","captions","responsive","startTime","embedUrl","embedBaseUrl","libraryId","token","url","URL","Object","entries","searchParams","expires","toString","signedEmbedUrl","args","videoId","tokenKey","videoFileSigner","tokenPath","pathname","directory","countriesAllowed","countries"],"mappings":"AAAA;;;;CAIC,GACD,SAASA,cAAc,EAAEC,UAAU,QAAQ,eAAc;AAEzD,OAAO,MAAMC,uBAAuB,mCAAkC;AAi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KC,YAAY,CAAC,EAAEN,WAAWC,MAAM,CAAC,CAAC,EAAEiD,QAAQ;IAC9E,OAAO,CAACzC,MAAM,EAAE0C,YAAY,KAAK,EAAE,GAAG,CAAC,CAAC,GACtCrD,WAAWU,WAAWF,YAAYL,MAAMQ,OAAOoC,KAAKvB,GAAG,EAAE;YACvD8B,kBAAkBP,KAAKQ,SAAS;YAChCF;YACAT,SAASG,KAAKH,OAAO;YACrBO;QACF;AACJ,EAAC"}
@@ -0,0 +1,32 @@
1
+ import type { BunnyWebhookPayload } from './types.js';
2
+ export declare const BUNNY_SIGNATURE_HEADER = "x-bunnystream-signature";
3
+ export declare const BUNNY_SIGNATURE_VERSION_HEADER = "x-bunnystream-signature-version";
4
+ export declare const BUNNY_SIGNATURE_ALGORITHM_HEADER = "x-bunnystream-signature-algorithm";
5
+ /** Lowercase hex HMAC-SHA256 of the raw body. */
6
+ export declare const computeBunnyWebhookSignature: (secret: string, rawBody: string) => string;
7
+ /** The headers Bunny sends with a webhook. Handy for tests and local tooling. */
8
+ export declare const bunnyWebhookHeaders: (secret: string, rawBody: string) => Record<string, string>;
9
+ export type BunnyWebhookVerification = {
10
+ ok: false;
11
+ reason: 'invalid_signature' | 'missing_header' | 'unsupported_algorithm' | 'unsupported_version';
12
+ } | {
13
+ ok: true;
14
+ };
15
+ type HeaderSource = Headers | Record<string, string | undefined>;
16
+ /**
17
+ * Verifies a Bunny Stream webhook.
18
+ * @param rawBody the exact request body string; do not re-serialise parsed JSON.
19
+ * @param secret the library's Read-Only API key (or the webhook signing secret, if Bunny gave you one).
20
+ */
21
+ export declare const verifyBunnyWebhook: ({ headers, rawBody, secret, }: {
22
+ headers: HeaderSource;
23
+ rawBody: string;
24
+ secret: string;
25
+ }) => BunnyWebhookVerification;
26
+ /** Parses Bunny's UTC timestamps, which may come without a time zone. Returns ms, or null. */
27
+ export declare const parseBunnyDate: (value: null | string | undefined) => null | number;
28
+ /** Normalises a Bunny date to an ISO string (UTC), or null. */
29
+ export declare const bunnyDateToIso: (value: null | string | undefined) => null | string;
30
+ /** Checks the shape of a parsed webhook body. */
31
+ export declare const isBunnyWebhookPayload: (value: unknown) => value is BunnyWebhookPayload;
32
+ export {};