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.
- package/LICENSE +21 -0
- package/README.md +289 -2
- package/dist/access.d.ts +35 -0
- package/dist/access.js +53 -0
- package/dist/access.js.map +1 -0
- package/dist/bin/args.d.ts +37 -0
- package/dist/bin/args.js +157 -0
- package/dist/bin/args.js.map +1 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +25 -0
- package/dist/bin/cli.js.map +1 -0
- package/dist/bin/fake.d.ts +2 -0
- package/dist/bin/fake.js +14 -0
- package/dist/bin/fake.js.map +1 -0
- package/dist/bin/migrate.d.ts +5 -0
- package/dist/bin/migrate.js +47 -0
- package/dist/bin/migrate.js.map +1 -0
- package/dist/bin/runFake.d.ts +2 -0
- package/dist/bin/runFake.js +24 -0
- package/dist/bin/runFake.js.map +1 -0
- package/dist/bin/webhooks.d.ts +15 -0
- package/dist/bin/webhooks.js +149 -0
- package/dist/bin/webhooks.js.map +1 -0
- package/dist/blocks.d.ts +42 -0
- package/dist/blocks.js +150 -0
- package/dist/blocks.js.map +1 -0
- package/dist/collection.d.ts +10 -0
- package/dist/collection.js +697 -0
- package/dist/collection.js.map +1 -0
- package/dist/components/BulkUploader.d.ts +16 -0
- package/dist/components/BulkUploader.js +226 -0
- package/dist/components/BulkUploader.js.map +1 -0
- package/dist/components/CaptionsManager.d.ts +9 -0
- package/dist/components/CaptionsManager.js +174 -0
- package/dist/components/CaptionsManager.js.map +1 -0
- package/dist/components/DownloadsPanel.d.ts +9 -0
- package/dist/components/DownloadsPanel.js +147 -0
- package/dist/components/DownloadsPanel.js.map +1 -0
- package/dist/components/ListUploader.d.ts +11 -0
- package/dist/components/ListUploader.js +138 -0
- package/dist/components/ListUploader.js.map +1 -0
- package/dist/components/ThumbnailCell.d.ts +5 -0
- package/dist/components/ThumbnailCell.js +28 -0
- package/dist/components/ThumbnailCell.js.map +1 -0
- package/dist/components/Uploader.d.ts +22 -0
- package/dist/components/Uploader.js +171 -0
- package/dist/components/Uploader.js.map +1 -0
- package/dist/components/VideoBlockLabel.d.ts +11 -0
- package/dist/components/VideoBlockLabel.js +86 -0
- package/dist/components/VideoBlockLabel.js.map +1 -0
- package/dist/components/VideoField.d.ts +17 -0
- package/dist/components/VideoField.js +422 -0
- package/dist/components/VideoField.js.map +1 -0
- package/dist/components/VideoRelationshipField.d.ts +16 -0
- package/dist/components/VideoRelationshipField.js +106 -0
- package/dist/components/VideoRelationshipField.js.map +1 -0
- package/dist/components/WebhookStatusPanel.d.ts +6 -0
- package/dist/components/WebhookStatusPanel.js +143 -0
- package/dist/components/WebhookStatusPanel.js.map +1 -0
- package/dist/components/api.d.ts +52 -0
- package/dist/components/api.js +76 -0
- package/dist/components/api.js.map +1 -0
- package/dist/components/chunkedUpload.d.ts +28 -0
- package/dist/components/chunkedUpload.js +49 -0
- package/dist/components/chunkedUpload.js.map +1 -0
- package/dist/components/styles.d.ts +95 -0
- package/dist/components/styles.js +148 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/components/uploadFile.d.ts +30 -0
- package/dist/components/uploadFile.js +140 -0
- package/dist/components/uploadFile.js.map +1 -0
- package/dist/components/usePluginApi.d.ts +46 -0
- package/dist/components/usePluginApi.js +21 -0
- package/dist/components/usePluginApi.js.map +1 -0
- package/dist/components/useUploadQueue.d.ts +35 -0
- package/dist/components/useUploadQueue.js +135 -0
- package/dist/components/useUploadQueue.js.map +1 -0
- package/dist/components/useVideoUpload.d.ts +33 -0
- package/dist/components/useVideoUpload.js +87 -0
- package/dist/components/useVideoUpload.js.map +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +29 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/provider.d.ts +347 -0
- package/dist/core/provider.js +13 -0
- package/dist/core/provider.js.map +1 -0
- package/dist/core/registry.d.ts +17 -0
- package/dist/core/registry.js +110 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/status.d.ts +15 -0
- package/dist/core/status.js +29 -0
- package/dist/core/status.js.map +1 -0
- package/dist/endpoints/index.d.ts +3 -0
- package/dist/endpoints/index.js +500 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/env.d.ts +40 -0
- package/dist/env.js +105 -0
- package/dist/env.js.map +1 -0
- package/dist/exports/bunny.d.ts +16 -0
- package/dist/exports/bunny.js +13 -0
- package/dist/exports/bunny.js.map +1 -0
- package/dist/exports/client.d.ts +22 -0
- package/dist/exports/client.js +18 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/cloudflare.d.ts +18 -0
- package/dist/exports/cloudflare.js +15 -0
- package/dist/exports/cloudflare.js.map +1 -0
- package/dist/exports/mux.d.ts +18 -0
- package/dist/exports/mux.js +15 -0
- package/dist/exports/mux.js.map +1 -0
- package/dist/exports/react.d.ts +25 -0
- package/dist/exports/react.js +18 -0
- package/dist/exports/react.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/testing.d.ts +13 -0
- package/dist/exports/testing.js +9 -0
- package/dist/exports/testing.js.map +1 -0
- package/dist/fields.d.ts +22 -0
- package/dist/fields.js +73 -0
- package/dist/fields.js.map +1 -0
- package/dist/frontend/ClientVideo.d.ts +14 -0
- package/dist/frontend/ClientVideo.js +43 -0
- package/dist/frontend/ClientVideo.js.map +1 -0
- package/dist/frontend/Video.d.ts +32 -0
- package/dist/frontend/Video.js +73 -0
- package/dist/frontend/Video.js.map +1 -0
- package/dist/frontend/VideoIframe.d.ts +35 -0
- package/dist/frontend/VideoIframe.js +60 -0
- package/dist/frontend/VideoIframe.js.map +1 -0
- package/dist/frontend/VideoUploader.d.ts +65 -0
- package/dist/frontend/VideoUploader.js +260 -0
- package/dist/frontend/VideoUploader.js.map +1 -0
- package/dist/frontend/constants.d.ts +10 -0
- package/dist/frontend/constants.js +10 -0
- package/dist/frontend/constants.js.map +1 -0
- package/dist/frontend/converters.d.ts +25 -0
- package/dist/frontend/converters.js +24 -0
- package/dist/frontend/converters.js.map +1 -0
- package/dist/frontend/source.d.ts +80 -0
- package/dist/frontend/source.js +159 -0
- package/dist/frontend/source.js.map +1 -0
- package/dist/frontend/useVideoSource.d.ts +27 -0
- package/dist/frontend/useVideoSource.js +108 -0
- package/dist/frontend/useVideoSource.js.map +1 -0
- package/dist/frontend/useVideoStatus.d.ts +26 -0
- package/dist/frontend/useVideoStatus.js +68 -0
- package/dist/frontend/useVideoStatus.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/migrate/cfStream.d.ts +108 -0
- package/dist/migrate/cfStream.js +418 -0
- package/dist/migrate/cfStream.js.map +1 -0
- package/dist/options.d.ts +9 -0
- package/dist/options.js +153 -0
- package/dist/options.js.map +1 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +177 -0
- package/dist/plugin.js.map +1 -0
- package/dist/providers/bunny/client.d.ts +78 -0
- package/dist/providers/bunny/client.js +231 -0
- package/dist/providers/bunny/client.js.map +1 -0
- package/dist/providers/bunny/env.d.ts +18 -0
- package/dist/providers/bunny/env.js +31 -0
- package/dist/providers/bunny/env.js.map +1 -0
- package/dist/providers/bunny/mapping.d.ts +39 -0
- package/dist/providers/bunny/mapping.js +123 -0
- package/dist/providers/bunny/mapping.js.map +1 -0
- package/dist/providers/bunny/options.d.ts +92 -0
- package/dist/providers/bunny/options.js +85 -0
- package/dist/providers/bunny/options.js.map +1 -0
- package/dist/providers/bunny/provider.d.ts +70 -0
- package/dist/providers/bunny/provider.js +480 -0
- package/dist/providers/bunny/provider.js.map +1 -0
- package/dist/providers/bunny/signing.d.ts +61 -0
- package/dist/providers/bunny/signing.js +144 -0
- package/dist/providers/bunny/signing.js.map +1 -0
- package/dist/providers/bunny/types.d.ts +153 -0
- package/dist/providers/bunny/types.js +64 -0
- package/dist/providers/bunny/types.js.map +1 -0
- package/dist/providers/bunny/urls.d.ts +49 -0
- package/dist/providers/bunny/urls.js +70 -0
- package/dist/providers/bunny/urls.js.map +1 -0
- package/dist/providers/bunny/webhook.d.ts +32 -0
- package/dist/providers/bunny/webhook.js +75 -0
- package/dist/providers/bunny/webhook.js.map +1 -0
- package/dist/providers/cloudflare/client.d.ts +93 -0
- package/dist/providers/cloudflare/client.js +436 -0
- package/dist/providers/cloudflare/client.js.map +1 -0
- package/dist/providers/cloudflare/env.d.ts +22 -0
- package/dist/providers/cloudflare/env.js +57 -0
- package/dist/providers/cloudflare/env.js.map +1 -0
- package/dist/providers/cloudflare/mapping.d.ts +15 -0
- package/dist/providers/cloudflare/mapping.js +95 -0
- package/dist/providers/cloudflare/mapping.js.map +1 -0
- package/dist/providers/cloudflare/options.d.ts +104 -0
- package/dist/providers/cloudflare/options.js +91 -0
- package/dist/providers/cloudflare/options.js.map +1 -0
- package/dist/providers/cloudflare/provider.d.ts +63 -0
- package/dist/providers/cloudflare/provider.js +445 -0
- package/dist/providers/cloudflare/provider.js.map +1 -0
- package/dist/providers/cloudflare/signing.d.ts +41 -0
- package/dist/providers/cloudflare/signing.js +97 -0
- package/dist/providers/cloudflare/signing.js.map +1 -0
- package/dist/providers/cloudflare/tus.d.ts +24 -0
- package/dist/providers/cloudflare/tus.js +55 -0
- package/dist/providers/cloudflare/tus.js.map +1 -0
- package/dist/providers/cloudflare/types.d.ts +156 -0
- package/dist/providers/cloudflare/types.js +14 -0
- package/dist/providers/cloudflare/types.js.map +1 -0
- package/dist/providers/cloudflare/urls.d.ts +55 -0
- package/dist/providers/cloudflare/urls.js +87 -0
- package/dist/providers/cloudflare/urls.js.map +1 -0
- package/dist/providers/cloudflare/webhook.d.ts +36 -0
- package/dist/providers/cloudflare/webhook.js +83 -0
- package/dist/providers/cloudflare/webhook.js.map +1 -0
- package/dist/providers/mux/client.d.ts +82 -0
- package/dist/providers/mux/client.js +283 -0
- package/dist/providers/mux/client.js.map +1 -0
- package/dist/providers/mux/env.d.ts +21 -0
- package/dist/providers/mux/env.js +61 -0
- package/dist/providers/mux/env.js.map +1 -0
- package/dist/providers/mux/mapping.d.ts +38 -0
- package/dist/providers/mux/mapping.js +111 -0
- package/dist/providers/mux/mapping.js.map +1 -0
- package/dist/providers/mux/options.d.ts +96 -0
- package/dist/providers/mux/options.js +83 -0
- package/dist/providers/mux/options.js.map +1 -0
- package/dist/providers/mux/provider.d.ts +63 -0
- package/dist/providers/mux/provider.js +555 -0
- package/dist/providers/mux/provider.js.map +1 -0
- package/dist/providers/mux/signing.d.ts +45 -0
- package/dist/providers/mux/signing.js +84 -0
- package/dist/providers/mux/signing.js.map +1 -0
- package/dist/providers/mux/types.d.ts +173 -0
- package/dist/providers/mux/types.js +42 -0
- package/dist/providers/mux/types.js.map +1 -0
- package/dist/providers/mux/urls.d.ts +58 -0
- package/dist/providers/mux/urls.js +59 -0
- package/dist/providers/mux/urls.js.map +1 -0
- package/dist/providers/mux/webhook.d.ts +38 -0
- package/dist/providers/mux/webhook.js +115 -0
- package/dist/providers/mux/webhook.js.map +1 -0
- package/dist/service.d.ts +193 -0
- package/dist/service.js +967 -0
- package/dist/service.js.map +1 -0
- package/dist/testing/bunny.d.ts +113 -0
- package/dist/testing/bunny.js +776 -0
- package/dist/testing/bunny.js.map +1 -0
- package/dist/testing/cloudflare.d.ts +101 -0
- package/dist/testing/cloudflare.js +913 -0
- package/dist/testing/cloudflare.js.map +1 -0
- package/dist/testing/index.d.ts +45 -0
- package/dist/testing/index.js +42 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/mux.d.ts +139 -0
- package/dist/testing/mux.js +1053 -0
- package/dist/testing/mux.js.map +1 -0
- package/dist/testing/types.d.ts +90 -0
- package/dist/testing/types.js +9 -0
- package/dist/testing/types.js.map +1 -0
- package/dist/types.d.ts +404 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/access.d.ts +22 -0
- package/dist/utils/access.js +66 -0
- package/dist/utils/access.js.map +1 -0
- package/dist/utils/localReq.d.ts +11 -0
- package/dist/utils/localReq.js +23 -0
- package/dist/utils/localReq.js.map +1 -0
- package/dist/utils/request.d.ts +12 -0
- package/dist/utils/request.js +55 -0
- package/dist/utils/request.js.map +1 -0
- package/dist/utils/version.d.ts +5 -0
- package/dist/utils/version.js +7 -0
- package/dist/utils/version.js.map +1 -0
- package/package.json +175 -4
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type KeyObject } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Token audiences (`aud`). A signed playback id needs one token per kind of request.
|
|
4
|
+
* @see https://www.mux.com/docs/guides/secure-video-playback
|
|
5
|
+
*/
|
|
6
|
+
export declare const MUX_AUDIENCES: {
|
|
7
|
+
/** Animated GIF / WebP (`image.mux.com/{id}/animated.gif`). */
|
|
8
|
+
readonly gif: "g";
|
|
9
|
+
/** Timeline hover previews (`image.mux.com/{id}/storyboard.vtt`). */
|
|
10
|
+
readonly storyboard: "s";
|
|
11
|
+
/** Thumbnails (`image.mux.com/{id}/thumbnail.jpg`). */
|
|
12
|
+
readonly thumbnail: "t";
|
|
13
|
+
/** The stream (`stream.mux.com/{id}.m3u8`), its captions and static renditions (MP4). */
|
|
14
|
+
readonly video: "v";
|
|
15
|
+
};
|
|
16
|
+
export type MuxAudience = keyof typeof MUX_AUDIENCES;
|
|
17
|
+
export type MuxSigningKeyInput = {
|
|
18
|
+
/** Signing key id (`MUX_SIGNING_KEY_ID`). */
|
|
19
|
+
keyId: string;
|
|
20
|
+
/** The private key: base64-encoded PEM as returned by Mux (`MUX_SIGNING_KEY_PRIVATE`), or a raw PEM. */
|
|
21
|
+
privateKey: string;
|
|
22
|
+
};
|
|
23
|
+
export type SignMuxTokenArgs = {
|
|
24
|
+
/** Extra claims, e.g. thumbnail options (`time`, `width`…) or `playback_restriction_id`. */
|
|
25
|
+
claims?: Record<string, number | string>;
|
|
26
|
+
/** Seconds until the token expires. Default 3600. */
|
|
27
|
+
expiresIn?: number;
|
|
28
|
+
/** Override "now" (unix seconds), mainly for tests. */
|
|
29
|
+
now?: number;
|
|
30
|
+
/** The signed playback id. */
|
|
31
|
+
playbackId: string;
|
|
32
|
+
type: MuxAudience;
|
|
33
|
+
} & MuxSigningKeyInput;
|
|
34
|
+
/** Parses a Mux signing key: base64-encoded PEM (as Mux returns it) or PEM, PKCS#1 or PKCS#8. */
|
|
35
|
+
export declare const parseMuxSigningKey: (privateKey: string) => KeyObject;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a Mux playback token (RS256 JWT) for one audience. Image options for signed thumbnails and
|
|
38
|
+
* GIFs (`time`, `width`, `height`, `fit_mode`…) must be passed in `claims`, not in the URL.
|
|
39
|
+
*/
|
|
40
|
+
export declare const signMuxToken: (args: SignMuxTokenArgs) => string;
|
|
41
|
+
/** Decodes (without verifying) a JWT's header and payload. */
|
|
42
|
+
export declare const decodeMuxToken: (token: string) => {
|
|
43
|
+
header: Record<string, unknown>;
|
|
44
|
+
payload: Record<string, unknown>;
|
|
45
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createPrivateKey, createSign } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Token audiences (`aud`). A signed playback id needs one token per kind of request.
|
|
4
|
+
* @see https://www.mux.com/docs/guides/secure-video-playback
|
|
5
|
+
*/ export const MUX_AUDIENCES = {
|
|
6
|
+
/** Animated GIF / WebP (`image.mux.com/{id}/animated.gif`). */ gif: 'g',
|
|
7
|
+
/** Timeline hover previews (`image.mux.com/{id}/storyboard.vtt`). */ storyboard: 's',
|
|
8
|
+
/** Thumbnails (`image.mux.com/{id}/thumbnail.jpg`). */ thumbnail: 't',
|
|
9
|
+
/** The stream (`stream.mux.com/{id}.m3u8`), its captions and static renditions (MP4). */ video: 'v'
|
|
10
|
+
};
|
|
11
|
+
const base64url = (input)=>Buffer.from(input).toString('base64url');
|
|
12
|
+
const keyCache = new Map();
|
|
13
|
+
/** Parses a Mux signing key: base64-encoded PEM (as Mux returns it) or PEM, PKCS#1 or PKCS#8. */ export const parseMuxSigningKey = (privateKey)=>{
|
|
14
|
+
const cached = keyCache.get(privateKey);
|
|
15
|
+
if (cached) {
|
|
16
|
+
return cached;
|
|
17
|
+
}
|
|
18
|
+
let pem = privateKey.trim();
|
|
19
|
+
if (!pem.includes('-----BEGIN')) {
|
|
20
|
+
pem = Buffer.from(pem, 'base64').toString('utf8').trim();
|
|
21
|
+
}
|
|
22
|
+
// PEMs pasted into env files often carry literal "\n" sequences.
|
|
23
|
+
pem = pem.replace(/\\n/g, '\n');
|
|
24
|
+
if (!pem.includes('-----BEGIN')) {
|
|
25
|
+
throw new Error('A Mux signing key must be a PEM private key, or the base64-encoded PEM that Mux returns.');
|
|
26
|
+
}
|
|
27
|
+
const key = createPrivateKey({
|
|
28
|
+
format: 'pem',
|
|
29
|
+
key: pem
|
|
30
|
+
});
|
|
31
|
+
if (key.asymmetricKeyType !== 'rsa') {
|
|
32
|
+
throw new Error(`Mux signing keys must be RSA keys (got ${key.asymmetricKeyType}).`);
|
|
33
|
+
}
|
|
34
|
+
keyCache.set(privateKey, key);
|
|
35
|
+
return key;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Creates a Mux playback token (RS256 JWT) for one audience. Image options for signed thumbnails and
|
|
39
|
+
* GIFs (`time`, `width`, `height`, `fit_mode`…) must be passed in `claims`, not in the URL.
|
|
40
|
+
*/ export const signMuxToken = (args)=>{
|
|
41
|
+
const { claims, expiresIn = 3600, keyId, playbackId, type } = args;
|
|
42
|
+
if (!playbackId) {
|
|
43
|
+
throw new Error('signMuxToken: playbackId is required');
|
|
44
|
+
}
|
|
45
|
+
if (!keyId) {
|
|
46
|
+
throw new Error('signMuxToken: keyId is required');
|
|
47
|
+
}
|
|
48
|
+
const aud = MUX_AUDIENCES[type];
|
|
49
|
+
if (!aud) {
|
|
50
|
+
throw new Error(`signMuxToken: unknown token type "${String(type)}"`);
|
|
51
|
+
}
|
|
52
|
+
if (!(expiresIn > 0)) {
|
|
53
|
+
throw new Error('signMuxToken: expiresIn must be a positive number of seconds');
|
|
54
|
+
}
|
|
55
|
+
const now = Math.floor(args.now ?? Date.now() / 1000);
|
|
56
|
+
const header = {
|
|
57
|
+
alg: 'RS256',
|
|
58
|
+
kid: keyId,
|
|
59
|
+
typ: 'JWT'
|
|
60
|
+
};
|
|
61
|
+
// Extra claims first, so they can never override the standard ones.
|
|
62
|
+
const payload = {
|
|
63
|
+
...claims,
|
|
64
|
+
aud,
|
|
65
|
+
exp: now + Math.floor(expiresIn),
|
|
66
|
+
kid: keyId,
|
|
67
|
+
sub: playbackId
|
|
68
|
+
};
|
|
69
|
+
const signingInput = `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(payload))}`;
|
|
70
|
+
const signature = createSign('RSA-SHA256').update(signingInput).sign(parseMuxSigningKey(args.privateKey));
|
|
71
|
+
return `${signingInput}.${base64url(signature)}`;
|
|
72
|
+
};
|
|
73
|
+
/** Decodes (without verifying) a JWT's header and payload. */ export const decodeMuxToken = (token)=>{
|
|
74
|
+
const [h, p] = token.split('.');
|
|
75
|
+
if (!h || !p) {
|
|
76
|
+
throw new Error('Malformed token');
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
header: JSON.parse(Buffer.from(h, 'base64url').toString('utf8')),
|
|
80
|
+
payload: JSON.parse(Buffer.from(p, 'base64url').toString('utf8'))
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/mux/signing.ts"],"sourcesContent":["import { createPrivateKey, createSign, type KeyObject } from 'node:crypto'\n\n/**\n * Token audiences (`aud`). A signed playback id needs one token per kind of request.\n * @see https://www.mux.com/docs/guides/secure-video-playback\n */\nexport const MUX_AUDIENCES = {\n /** Animated GIF / WebP (`image.mux.com/{id}/animated.gif`). */\n gif: 'g',\n /** Timeline hover previews (`image.mux.com/{id}/storyboard.vtt`). */\n storyboard: 's',\n /** Thumbnails (`image.mux.com/{id}/thumbnail.jpg`). */\n thumbnail: 't',\n /** The stream (`stream.mux.com/{id}.m3u8`), its captions and static renditions (MP4). */\n video: 'v',\n} as const\n\nexport type MuxAudience = keyof typeof MUX_AUDIENCES\n\nexport type MuxSigningKeyInput = {\n /** Signing key id (`MUX_SIGNING_KEY_ID`). */\n keyId: string\n /** The private key: base64-encoded PEM as returned by Mux (`MUX_SIGNING_KEY_PRIVATE`), or a raw PEM. */\n privateKey: string\n}\n\nexport type SignMuxTokenArgs = {\n /** Extra claims, e.g. thumbnail options (`time`, `width`…) or `playback_restriction_id`. */\n claims?: Record<string, number | string>\n /** Seconds until the token expires. Default 3600. */\n expiresIn?: number\n /** Override \"now\" (unix seconds), mainly for tests. */\n now?: number\n /** The signed playback id. */\n playbackId: string\n type: MuxAudience\n} & MuxSigningKeyInput\n\nconst base64url = (input: Buffer | string): string => Buffer.from(input).toString('base64url')\n\nconst keyCache = new Map<string, KeyObject>()\n\n/** Parses a Mux signing key: base64-encoded PEM (as Mux returns it) or PEM, PKCS#1 or PKCS#8. */\nexport const parseMuxSigningKey = (privateKey: string): KeyObject => {\n const cached = keyCache.get(privateKey)\n if (cached) {\n return cached\n }\n let pem = privateKey.trim()\n if (!pem.includes('-----BEGIN')) {\n pem = Buffer.from(pem, 'base64').toString('utf8').trim()\n }\n // PEMs pasted into env files often carry literal \"\\n\" sequences.\n pem = pem.replace(/\\\\n/g, '\\n')\n if (!pem.includes('-----BEGIN')) {\n throw new Error('A Mux signing key must be a PEM private key, or the base64-encoded PEM that Mux returns.')\n }\n const key = createPrivateKey({ format: 'pem', key: pem })\n if (key.asymmetricKeyType !== 'rsa') {\n throw new Error(`Mux signing keys must be RSA keys (got ${key.asymmetricKeyType}).`)\n }\n keyCache.set(privateKey, key)\n return key\n}\n\n/**\n * Creates a Mux playback token (RS256 JWT) for one audience. Image options for signed thumbnails and\n * GIFs (`time`, `width`, `height`, `fit_mode`…) must be passed in `claims`, not in the URL.\n */\nexport const signMuxToken = (args: SignMuxTokenArgs): string => {\n const { claims, expiresIn = 3600, keyId, playbackId, type } = args\n if (!playbackId) {\n throw new Error('signMuxToken: playbackId is required')\n }\n if (!keyId) {\n throw new Error('signMuxToken: keyId is required')\n }\n const aud = MUX_AUDIENCES[type]\n if (!aud) {\n throw new Error(`signMuxToken: unknown token type \"${String(type)}\"`)\n }\n if (!(expiresIn > 0)) {\n throw new Error('signMuxToken: expiresIn must be a positive number of seconds')\n }\n const now = Math.floor(args.now ?? Date.now() / 1000)\n const header = { alg: 'RS256', kid: keyId, typ: 'JWT' }\n // Extra claims first, so they can never override the standard ones.\n const payload = { ...claims, aud, exp: now + Math.floor(expiresIn), kid: keyId, sub: playbackId }\n const signingInput = `${base64url(JSON.stringify(header))}.${base64url(JSON.stringify(payload))}`\n const signature = createSign('RSA-SHA256').update(signingInput).sign(parseMuxSigningKey(args.privateKey))\n return `${signingInput}.${base64url(signature)}`\n}\n\n/** Decodes (without verifying) a JWT's header and payload. */\nexport const decodeMuxToken = (token: string): { header: Record<string, unknown>; payload: Record<string, unknown> } => {\n const [h, p] = token.split('.')\n if (!h || !p) {\n throw new Error('Malformed token')\n }\n return {\n header: JSON.parse(Buffer.from(h, 'base64url').toString('utf8')) as Record<string, unknown>,\n payload: JSON.parse(Buffer.from(p, 'base64url').toString('utf8')) as Record<string, unknown>,\n }\n}\n"],"names":["createPrivateKey","createSign","MUX_AUDIENCES","gif","storyboard","thumbnail","video","base64url","input","Buffer","from","toString","keyCache","Map","parseMuxSigningKey","privateKey","cached","get","pem","trim","includes","replace","Error","key","format","asymmetricKeyType","set","signMuxToken","args","claims","expiresIn","keyId","playbackId","type","aud","String","now","Math","floor","Date","header","alg","kid","typ","payload","exp","sub","signingInput","JSON","stringify","signature","update","sign","decodeMuxToken","token","h","p","split","parse"],"mappings":"AAAA,SAASA,gBAAgB,EAAEC,UAAU,QAAwB,cAAa;AAE1E;;;CAGC,GACD,OAAO,MAAMC,gBAAgB;IAC3B,6DAA6D,GAC7DC,KAAK;IACL,mEAAmE,GACnEC,YAAY;IACZ,qDAAqD,GACrDC,WAAW;IACX,uFAAuF,GACvFC,OAAO;AACT,EAAU;AAuBV,MAAMC,YAAY,CAACC,QAAmCC,OAAOC,IAAI,CAACF,OAAOG,QAAQ,CAAC;AAElF,MAAMC,WAAW,IAAIC;AAErB,+FAA+F,GAC/F,OAAO,MAAMC,qBAAqB,CAACC;IACjC,MAAMC,SAASJ,SAASK,GAAG,CAACF;IAC5B,IAAIC,QAAQ;QACV,OAAOA;IACT;IACA,IAAIE,MAAMH,WAAWI,IAAI;IACzB,IAAI,CAACD,IAAIE,QAAQ,CAAC,eAAe;QAC/BF,MAAMT,OAAOC,IAAI,CAACQ,KAAK,UAAUP,QAAQ,CAAC,QAAQQ,IAAI;IACxD;IACA,iEAAiE;IACjED,MAAMA,IAAIG,OAAO,CAAC,QAAQ;IAC1B,IAAI,CAACH,IAAIE,QAAQ,CAAC,eAAe;QAC/B,MAAM,IAAIE,MAAM;IAClB;IACA,MAAMC,MAAMvB,iBAAiB;QAAEwB,QAAQ;QAAOD,KAAKL;IAAI;IACvD,IAAIK,IAAIE,iBAAiB,KAAK,OAAO;QACnC,MAAM,IAAIH,MAAM,CAAC,uCAAuC,EAAEC,IAAIE,iBAAiB,CAAC,EAAE,CAAC;IACrF;IACAb,SAASc,GAAG,CAACX,YAAYQ;IACzB,OAAOA;AACT,EAAC;AAED;;;CAGC,GACD,OAAO,MAAMI,eAAe,CAACC;IAC3B,MAAM,EAAEC,MAAM,EAAEC,YAAY,IAAI,EAAEC,KAAK,EAAEC,UAAU,EAAEC,IAAI,EAAE,GAAGL;IAC9D,IAAI,CAACI,YAAY;QACf,MAAM,IAAIV,MAAM;IAClB;IACA,IAAI,CAACS,OAAO;QACV,MAAM,IAAIT,MAAM;IAClB;IACA,MAAMY,MAAMhC,aAAa,CAAC+B,KAAK;IAC/B,IAAI,CAACC,KAAK;QACR,MAAM,IAAIZ,MAAM,CAAC,kCAAkC,EAAEa,OAAOF,MAAM,CAAC,CAAC;IACtE;IACA,IAAI,CAAEH,CAAAA,YAAY,CAAA,GAAI;QACpB,MAAM,IAAIR,MAAM;IAClB;IACA,MAAMc,MAAMC,KAAKC,KAAK,CAACV,KAAKQ,GAAG,IAAIG,KAAKH,GAAG,KAAK;IAChD,MAAMI,SAAS;QAAEC,KAAK;QAASC,KAAKX;QAAOY,KAAK;IAAM;IACtD,oEAAoE;IACpE,MAAMC,UAAU;QAAE,GAAGf,MAAM;QAAEK;QAAKW,KAAKT,MAAMC,KAAKC,KAAK,CAACR;QAAYY,KAAKX;QAAOe,KAAKd;IAAW;IAChG,MAAMe,eAAe,GAAGxC,UAAUyC,KAAKC,SAAS,CAACT,SAAS,CAAC,EAAEjC,UAAUyC,KAAKC,SAAS,CAACL,WAAW;IACjG,MAAMM,YAAYjD,WAAW,cAAckD,MAAM,CAACJ,cAAcK,IAAI,CAACtC,mBAAmBc,KAAKb,UAAU;IACvG,OAAO,GAAGgC,aAAa,CAAC,EAAExC,UAAU2C,YAAY;AAClD,EAAC;AAED,4DAA4D,GAC5D,OAAO,MAAMG,iBAAiB,CAACC;IAC7B,MAAM,CAACC,GAAGC,EAAE,GAAGF,MAAMG,KAAK,CAAC;IAC3B,IAAI,CAACF,KAAK,CAACC,GAAG;QACZ,MAAM,IAAIlC,MAAM;IAClB;IACA,OAAO;QACLkB,QAAQQ,KAAKU,KAAK,CAACjD,OAAOC,IAAI,CAAC6C,GAAG,aAAa5C,QAAQ,CAAC;QACxDiC,SAASI,KAAKU,KAAK,CAACjD,OAAOC,IAAI,CAAC8C,GAAG,aAAa7C,QAAQ,CAAC;IAC3D;AACF,EAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of the Mux Video REST API this plugin uses, written by hand from the OpenAPI spec
|
|
3
|
+
* (https://www.mux.com/api-spec.json). `sdk-compat.ts` checks them against the official `@mux/ts` types.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MUX_ASSET_STATUSES: readonly ["preparing", "ready", "errored"];
|
|
6
|
+
export type MuxAssetStatus = (typeof MUX_ASSET_STATUSES)[number];
|
|
7
|
+
export declare const MUX_UPLOAD_STATUSES: readonly ["waiting", "asset_created", "errored", "cancelled", "timed_out"];
|
|
8
|
+
export type MuxUploadStatus = (typeof MUX_UPLOAD_STATUSES)[number];
|
|
9
|
+
export type MuxPlaybackPolicy = 'drm' | 'public' | 'signed';
|
|
10
|
+
export type MuxPlaybackId = {
|
|
11
|
+
id: string;
|
|
12
|
+
policy: MuxPlaybackPolicy;
|
|
13
|
+
};
|
|
14
|
+
export type MuxTrackStatus = 'deleted' | 'errored' | 'preparing' | 'ready' | 'skipped';
|
|
15
|
+
export type MuxTrack = {
|
|
16
|
+
closed_captions?: boolean;
|
|
17
|
+
duration?: number;
|
|
18
|
+
id: string;
|
|
19
|
+
language_code?: string;
|
|
20
|
+
max_frame_rate?: number;
|
|
21
|
+
max_height?: number;
|
|
22
|
+
max_width?: number;
|
|
23
|
+
name?: string;
|
|
24
|
+
passthrough?: string;
|
|
25
|
+
primary?: boolean;
|
|
26
|
+
status?: MuxTrackStatus;
|
|
27
|
+
text_source?: 'embedded' | 'generated_live' | 'generated_live_final' | 'generated_vod' | 'uploaded';
|
|
28
|
+
text_type?: 'chapters' | 'subtitles';
|
|
29
|
+
type: 'audio' | 'text' | 'video';
|
|
30
|
+
};
|
|
31
|
+
export type MuxStaticRenditionResolution = '1080p' | '1440p' | '2160p' | '270p' | '360p' | '480p' | '540p' | '720p' | 'audio-only' | 'highest';
|
|
32
|
+
export type MuxStaticRendition = {
|
|
33
|
+
ext?: 'm4a' | 'mp4';
|
|
34
|
+
filesize?: string;
|
|
35
|
+
id?: string;
|
|
36
|
+
name?: `${Exclude<MuxStaticRenditionResolution, 'audio-only'> | 'capped-1080p' | 'high' | 'low' | 'medium'}.mp4` | 'audio.m4a';
|
|
37
|
+
passthrough?: string;
|
|
38
|
+
resolution?: MuxStaticRenditionResolution;
|
|
39
|
+
status?: 'errored' | 'preparing' | 'ready' | 'skipped';
|
|
40
|
+
type?: 'advanced' | 'standard';
|
|
41
|
+
};
|
|
42
|
+
export type MuxAssetMeta = {
|
|
43
|
+
creator_id?: string;
|
|
44
|
+
external_id?: string;
|
|
45
|
+
title?: string;
|
|
46
|
+
};
|
|
47
|
+
export type MuxAssetProgress = {
|
|
48
|
+
progress: number;
|
|
49
|
+
state: 'completed' | 'errored' | 'ingesting' | 'live' | 'optimizing' | 'transcoding';
|
|
50
|
+
};
|
|
51
|
+
export type MuxAsset = {
|
|
52
|
+
aspect_ratio?: string;
|
|
53
|
+
/** Unix seconds, as a string. */
|
|
54
|
+
created_at?: string;
|
|
55
|
+
duration?: number;
|
|
56
|
+
errors?: {
|
|
57
|
+
messages?: string[];
|
|
58
|
+
type?: string;
|
|
59
|
+
};
|
|
60
|
+
id: string;
|
|
61
|
+
is_live?: boolean;
|
|
62
|
+
max_resolution_tier?: '1080p' | '1440p' | '2160p';
|
|
63
|
+
max_stored_resolution?: 'Audio only' | 'FHD' | 'HD' | 'SD' | 'UHD';
|
|
64
|
+
meta?: MuxAssetMeta;
|
|
65
|
+
passthrough?: string;
|
|
66
|
+
playback_ids?: MuxPlaybackId[];
|
|
67
|
+
progress?: MuxAssetProgress;
|
|
68
|
+
resolution_tier?: '1080p' | '1440p' | '2160p' | '720p' | 'audio-only';
|
|
69
|
+
static_renditions?: {
|
|
70
|
+
files?: MuxStaticRendition[];
|
|
71
|
+
status?: string;
|
|
72
|
+
};
|
|
73
|
+
status: MuxAssetStatus;
|
|
74
|
+
test?: boolean;
|
|
75
|
+
thumbnail_time?: number;
|
|
76
|
+
tracks?: MuxTrack[];
|
|
77
|
+
upload_id?: string;
|
|
78
|
+
video_quality?: 'basic' | 'plus' | 'premium';
|
|
79
|
+
};
|
|
80
|
+
export type MuxUpload = {
|
|
81
|
+
asset_id?: string;
|
|
82
|
+
cors_origin?: string;
|
|
83
|
+
error?: {
|
|
84
|
+
message?: string;
|
|
85
|
+
type?: string;
|
|
86
|
+
};
|
|
87
|
+
id: string;
|
|
88
|
+
new_asset_settings?: MuxNewAssetSettings;
|
|
89
|
+
status: MuxUploadStatus;
|
|
90
|
+
test?: boolean;
|
|
91
|
+
timeout?: number;
|
|
92
|
+
/** The one-time URL the file is PUT to. */
|
|
93
|
+
url?: string;
|
|
94
|
+
};
|
|
95
|
+
/** Settings shared by `POST /video/v1/assets` and an upload's `new_asset_settings`. */
|
|
96
|
+
export type MuxNewAssetSettings = {
|
|
97
|
+
inputs?: {
|
|
98
|
+
generated_subtitles?: {
|
|
99
|
+
language_code: string;
|
|
100
|
+
name?: string;
|
|
101
|
+
}[];
|
|
102
|
+
url?: string;
|
|
103
|
+
}[];
|
|
104
|
+
max_resolution_tier?: '1080p' | '1440p' | '2160p';
|
|
105
|
+
meta?: MuxAssetMeta;
|
|
106
|
+
passthrough?: string;
|
|
107
|
+
playback_policies?: MuxPlaybackPolicy[];
|
|
108
|
+
static_renditions?: {
|
|
109
|
+
resolution: MuxStaticRenditionResolution;
|
|
110
|
+
}[];
|
|
111
|
+
test?: boolean;
|
|
112
|
+
video_quality?: 'basic' | 'plus' | 'premium';
|
|
113
|
+
};
|
|
114
|
+
export type MuxCreateUploadRequest = {
|
|
115
|
+
cors_origin: string;
|
|
116
|
+
new_asset_settings: MuxNewAssetSettings;
|
|
117
|
+
test?: boolean;
|
|
118
|
+
timeout?: number;
|
|
119
|
+
};
|
|
120
|
+
export type MuxCreateAssetRequest = MuxNewAssetSettings & {
|
|
121
|
+
inputs: {
|
|
122
|
+
url: string;
|
|
123
|
+
}[];
|
|
124
|
+
};
|
|
125
|
+
export type MuxUpdateAssetRequest = {
|
|
126
|
+
meta?: MuxAssetMeta;
|
|
127
|
+
passthrough?: string;
|
|
128
|
+
thumbnail_time?: number;
|
|
129
|
+
};
|
|
130
|
+
export type MuxCreateTrackRequest = {
|
|
131
|
+
closed_captions?: boolean;
|
|
132
|
+
language_code: string;
|
|
133
|
+
name?: string;
|
|
134
|
+
passthrough?: string;
|
|
135
|
+
text_type: 'subtitles';
|
|
136
|
+
type: 'text';
|
|
137
|
+
url: string;
|
|
138
|
+
};
|
|
139
|
+
export type MuxSigningKey = {
|
|
140
|
+
/** Unix seconds, as a string. */
|
|
141
|
+
created_at: string;
|
|
142
|
+
id: string;
|
|
143
|
+
/** Base64-encoded PEM. Only returned once, when the key is created. */
|
|
144
|
+
private_key?: string;
|
|
145
|
+
};
|
|
146
|
+
export type MuxListAssetsQuery = {
|
|
147
|
+
cursor?: string;
|
|
148
|
+
limit?: number;
|
|
149
|
+
page?: number;
|
|
150
|
+
upload_id?: string;
|
|
151
|
+
};
|
|
152
|
+
export type MuxListAssetsResponse = {
|
|
153
|
+
data: MuxAsset[];
|
|
154
|
+
next_cursor?: null | string;
|
|
155
|
+
};
|
|
156
|
+
/** A webhook notification. `data` is an asset, an upload, a track or a static rendition, by `type`. */
|
|
157
|
+
export type MuxWebhookEvent = {
|
|
158
|
+
attempts?: unknown[];
|
|
159
|
+
created_at?: string;
|
|
160
|
+
data: Record<string, unknown>;
|
|
161
|
+
environment?: {
|
|
162
|
+
id?: string;
|
|
163
|
+
name?: string;
|
|
164
|
+
};
|
|
165
|
+
id: string;
|
|
166
|
+
object?: {
|
|
167
|
+
id: string;
|
|
168
|
+
type: string;
|
|
169
|
+
};
|
|
170
|
+
type: string;
|
|
171
|
+
};
|
|
172
|
+
/** Languages Mux generates captions for, from https://www.mux.com/docs/guides/add-autogenerated-captions-and-use-transcripts. */
|
|
173
|
+
export declare const MUX_GENERATED_CAPTION_LANGUAGES: readonly ["en", "es", "it", "pt", "de", "fr", "pl", "ru", "nl", "ca", "tr", "sv", "uk", "no", "fi", "sk", "el", "cs", "hr", "da", "ro", "bg", "auto"];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parts of the Mux Video REST API this plugin uses, written by hand from the OpenAPI spec
|
|
3
|
+
* (https://www.mux.com/api-spec.json). `sdk-compat.ts` checks them against the official `@mux/ts` types.
|
|
4
|
+
*/ export const MUX_ASSET_STATUSES = [
|
|
5
|
+
'preparing',
|
|
6
|
+
'ready',
|
|
7
|
+
'errored'
|
|
8
|
+
];
|
|
9
|
+
export const MUX_UPLOAD_STATUSES = [
|
|
10
|
+
'waiting',
|
|
11
|
+
'asset_created',
|
|
12
|
+
'errored',
|
|
13
|
+
'cancelled',
|
|
14
|
+
'timed_out'
|
|
15
|
+
];
|
|
16
|
+
/** Languages Mux generates captions for, from https://www.mux.com/docs/guides/add-autogenerated-captions-and-use-transcripts. */ export const MUX_GENERATED_CAPTION_LANGUAGES = [
|
|
17
|
+
'en',
|
|
18
|
+
'es',
|
|
19
|
+
'it',
|
|
20
|
+
'pt',
|
|
21
|
+
'de',
|
|
22
|
+
'fr',
|
|
23
|
+
'pl',
|
|
24
|
+
'ru',
|
|
25
|
+
'nl',
|
|
26
|
+
'ca',
|
|
27
|
+
'tr',
|
|
28
|
+
'sv',
|
|
29
|
+
'uk',
|
|
30
|
+
'no',
|
|
31
|
+
'fi',
|
|
32
|
+
'sk',
|
|
33
|
+
'el',
|
|
34
|
+
'cs',
|
|
35
|
+
'hr',
|
|
36
|
+
'da',
|
|
37
|
+
'ro',
|
|
38
|
+
'bg',
|
|
39
|
+
'auto'
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/mux/types.ts"],"sourcesContent":["/**\n * The parts of the Mux Video REST API this plugin uses, written by hand from the OpenAPI spec\n * (https://www.mux.com/api-spec.json). `sdk-compat.ts` checks them against the official `@mux/ts` types.\n */\n\nexport const MUX_ASSET_STATUSES = ['preparing', 'ready', 'errored'] as const\nexport type MuxAssetStatus = (typeof MUX_ASSET_STATUSES)[number]\n\nexport const MUX_UPLOAD_STATUSES = ['waiting', 'asset_created', 'errored', 'cancelled', 'timed_out'] as const\nexport type MuxUploadStatus = (typeof MUX_UPLOAD_STATUSES)[number]\n\nexport type MuxPlaybackPolicy = 'drm' | 'public' | 'signed'\n\nexport type MuxPlaybackId = {\n id: string\n policy: MuxPlaybackPolicy\n}\n\nexport type MuxTrackStatus = 'deleted' | 'errored' | 'preparing' | 'ready' | 'skipped'\n\nexport type MuxTrack = {\n closed_captions?: boolean\n duration?: number\n id: string\n language_code?: string\n max_frame_rate?: number\n max_height?: number\n max_width?: number\n name?: string\n passthrough?: string\n primary?: boolean\n status?: MuxTrackStatus\n text_source?: 'embedded' | 'generated_live' | 'generated_live_final' | 'generated_vod' | 'uploaded'\n text_type?: 'chapters' | 'subtitles'\n type: 'audio' | 'text' | 'video'\n}\n\nexport type MuxStaticRenditionResolution =\n | '1080p'\n | '1440p'\n | '2160p'\n | '270p'\n | '360p'\n | '480p'\n | '540p'\n | '720p'\n | 'audio-only'\n | 'highest'\n\nexport type MuxStaticRendition = {\n ext?: 'm4a' | 'mp4'\n filesize?: string\n id?: string\n name?: `${Exclude<MuxStaticRenditionResolution, 'audio-only'> | 'capped-1080p' | 'high' | 'low' | 'medium'}.mp4` | 'audio.m4a'\n passthrough?: string\n resolution?: MuxStaticRenditionResolution\n status?: 'errored' | 'preparing' | 'ready' | 'skipped'\n type?: 'advanced' | 'standard'\n}\n\nexport type MuxAssetMeta = {\n creator_id?: string\n external_id?: string\n title?: string\n}\n\nexport type MuxAssetProgress = {\n progress: number\n state: 'completed' | 'errored' | 'ingesting' | 'live' | 'optimizing' | 'transcoding'\n}\n\nexport type MuxAsset = {\n aspect_ratio?: string\n /** Unix seconds, as a string. */\n created_at?: string\n duration?: number\n errors?: { messages?: string[]; type?: string }\n id: string\n is_live?: boolean\n max_resolution_tier?: '1080p' | '1440p' | '2160p'\n max_stored_resolution?: 'Audio only' | 'FHD' | 'HD' | 'SD' | 'UHD'\n meta?: MuxAssetMeta\n passthrough?: string\n playback_ids?: MuxPlaybackId[]\n progress?: MuxAssetProgress\n resolution_tier?: '1080p' | '1440p' | '2160p' | '720p' | 'audio-only'\n static_renditions?: { files?: MuxStaticRendition[]; status?: string }\n status: MuxAssetStatus\n test?: boolean\n thumbnail_time?: number\n tracks?: MuxTrack[]\n upload_id?: string\n video_quality?: 'basic' | 'plus' | 'premium'\n}\n\nexport type MuxUpload = {\n asset_id?: string\n cors_origin?: string\n error?: { message?: string; type?: string }\n id: string\n new_asset_settings?: MuxNewAssetSettings\n status: MuxUploadStatus\n test?: boolean\n timeout?: number\n /** The one-time URL the file is PUT to. */\n url?: string\n}\n\n/** Settings shared by `POST /video/v1/assets` and an upload's `new_asset_settings`. */\nexport type MuxNewAssetSettings = {\n inputs?: { generated_subtitles?: { language_code: string; name?: string }[]; url?: string }[]\n max_resolution_tier?: '1080p' | '1440p' | '2160p'\n meta?: MuxAssetMeta\n passthrough?: string\n playback_policies?: MuxPlaybackPolicy[]\n static_renditions?: { resolution: MuxStaticRenditionResolution }[]\n test?: boolean\n video_quality?: 'basic' | 'plus' | 'premium'\n}\n\nexport type MuxCreateUploadRequest = {\n cors_origin: string\n new_asset_settings: MuxNewAssetSettings\n test?: boolean\n timeout?: number\n}\n\nexport type MuxCreateAssetRequest = MuxNewAssetSettings & { inputs: { url: string }[] }\n\nexport type MuxUpdateAssetRequest = {\n meta?: MuxAssetMeta\n passthrough?: string\n thumbnail_time?: number\n}\n\nexport type MuxCreateTrackRequest = {\n closed_captions?: boolean\n language_code: string\n name?: string\n passthrough?: string\n text_type: 'subtitles'\n type: 'text'\n url: string\n}\n\nexport type MuxSigningKey = {\n /** Unix seconds, as a string. */\n created_at: string\n id: string\n /** Base64-encoded PEM. Only returned once, when the key is created. */\n private_key?: string\n}\n\nexport type MuxListAssetsQuery = {\n cursor?: string\n limit?: number\n page?: number\n upload_id?: string\n}\n\nexport type MuxListAssetsResponse = {\n data: MuxAsset[]\n next_cursor?: null | string\n}\n\n/** A webhook notification. `data` is an asset, an upload, a track or a static rendition, by `type`. */\nexport type MuxWebhookEvent = {\n attempts?: unknown[]\n created_at?: string\n data: Record<string, unknown>\n environment?: { id?: string; name?: string }\n id: string\n object?: { id: string; type: string }\n type: string\n}\n\n/** Languages Mux generates captions for, from https://www.mux.com/docs/guides/add-autogenerated-captions-and-use-transcripts. */\nexport const MUX_GENERATED_CAPTION_LANGUAGES = [\n 'en',\n 'es',\n 'it',\n 'pt',\n 'de',\n 'fr',\n 'pl',\n 'ru',\n 'nl',\n 'ca',\n 'tr',\n 'sv',\n 'uk',\n 'no',\n 'fi',\n 'sk',\n 'el',\n 'cs',\n 'hr',\n 'da',\n 'ro',\n 'bg',\n 'auto',\n] as const\n"],"names":["MUX_ASSET_STATUSES","MUX_UPLOAD_STATUSES","MUX_GENERATED_CAPTION_LANGUAGES"],"mappings":"AAAA;;;CAGC,GAED,OAAO,MAAMA,qBAAqB;IAAC;IAAa;IAAS;CAAU,CAAS;AAG5E,OAAO,MAAMC,sBAAsB;IAAC;IAAW;IAAiB;IAAW;IAAa;CAAY,CAAS;AAwK7G,+HAA+H,GAC/H,OAAO,MAAMC,kCAAkC;IAC7C;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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mux delivery URLs. Pure functions: tokens are passed in, never created here.
|
|
3
|
+
* @see https://www.mux.com/docs/guides/get-images-from-a-video
|
|
4
|
+
* @see https://www.mux.com/docs/guides/player-mux-com
|
|
5
|
+
*/
|
|
6
|
+
export type MuxDeliveryBaseUrls = {
|
|
7
|
+
/** Default `https://image.mux.com`. */
|
|
8
|
+
image: string;
|
|
9
|
+
/** Default `https://player.mux.com`. */
|
|
10
|
+
player: string;
|
|
11
|
+
/** Default `https://stream.mux.com`. */
|
|
12
|
+
stream: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const MUX_DELIVERY_BASE_URLS: MuxDeliveryBaseUrls;
|
|
15
|
+
/** Thumbnail options. For public playback ids they go in the URL, for signed ones in the `t` token. */
|
|
16
|
+
export type MuxThumbnailOptions = {
|
|
17
|
+
fit_mode?: 'crop' | 'pad' | 'preserve' | 'smartcrop' | 'stretch';
|
|
18
|
+
height?: number;
|
|
19
|
+
/** Seconds. Default: the asset's `thumbnail_time`, else the middle of the video. */
|
|
20
|
+
time?: number;
|
|
21
|
+
width?: number;
|
|
22
|
+
};
|
|
23
|
+
/** Animated preview options (max 10 seconds, max 640px). */
|
|
24
|
+
export type MuxAnimatedOptions = {
|
|
25
|
+
end?: number;
|
|
26
|
+
fps?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
start?: number;
|
|
29
|
+
width?: number;
|
|
30
|
+
};
|
|
31
|
+
/** Tokens for a signed playback id, one per audience. */
|
|
32
|
+
export type MuxPlaybackTokens = {
|
|
33
|
+
gif: string;
|
|
34
|
+
storyboard: string;
|
|
35
|
+
thumbnail: string;
|
|
36
|
+
video: string;
|
|
37
|
+
};
|
|
38
|
+
export type MuxPlaybackUrlOptions = {
|
|
39
|
+
animated?: MuxAnimatedOptions;
|
|
40
|
+
bases?: Partial<MuxDeliveryBaseUrls>;
|
|
41
|
+
/** Include `downloadMp4` (`highest.mp4`). */
|
|
42
|
+
mp4?: boolean;
|
|
43
|
+
thumbnail?: MuxThumbnailOptions;
|
|
44
|
+
/** Signed playback: one token per audience. Image options then live in the tokens, not the URLs. */
|
|
45
|
+
tokens?: MuxPlaybackTokens;
|
|
46
|
+
};
|
|
47
|
+
/** Builds HLS, poster, animated, iframe and (optionally) MP4 URLs for a playback id. */
|
|
48
|
+
export declare const buildMuxPlaybackUrls: (playbackId: string, options?: MuxPlaybackUrlOptions) => {
|
|
49
|
+
animated: string;
|
|
50
|
+
downloadMp4?: string;
|
|
51
|
+
hls: string;
|
|
52
|
+
iframe: string;
|
|
53
|
+
storyboard: string;
|
|
54
|
+
thumbnail: string;
|
|
55
|
+
watch: string;
|
|
56
|
+
};
|
|
57
|
+
/** URL of a static rendition file (`highest.mp4`, `audio.m4a`) for a public playback id. */
|
|
58
|
+
export declare const muxStaticRenditionUrl: (playbackId: string, file: string, streamBase?: string, token?: string) => string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mux delivery URLs. Pure functions: tokens are passed in, never created here.
|
|
3
|
+
* @see https://www.mux.com/docs/guides/get-images-from-a-video
|
|
4
|
+
* @see https://www.mux.com/docs/guides/player-mux-com
|
|
5
|
+
*/ export const MUX_DELIVERY_BASE_URLS = {
|
|
6
|
+
image: 'https://image.mux.com',
|
|
7
|
+
player: 'https://player.mux.com',
|
|
8
|
+
stream: 'https://stream.mux.com'
|
|
9
|
+
};
|
|
10
|
+
const withQuery = (url, params)=>{
|
|
11
|
+
const entries = Object.entries(params).filter((e)=>e[1] !== undefined && e[1] !== '');
|
|
12
|
+
if (!entries.length) {
|
|
13
|
+
return url;
|
|
14
|
+
}
|
|
15
|
+
const query = new URLSearchParams(entries.map(([k, v])=>[
|
|
16
|
+
k,
|
|
17
|
+
String(v)
|
|
18
|
+
]));
|
|
19
|
+
return `${url}?${query.toString()}`;
|
|
20
|
+
};
|
|
21
|
+
const enc = encodeURIComponent;
|
|
22
|
+
/** Builds HLS, poster, animated, iframe and (optionally) MP4 URLs for a playback id. */ export const buildMuxPlaybackUrls = (playbackId, options = {})=>{
|
|
23
|
+
const bases = {
|
|
24
|
+
...MUX_DELIVERY_BASE_URLS,
|
|
25
|
+
...options.bases
|
|
26
|
+
};
|
|
27
|
+
const pid = enc(playbackId);
|
|
28
|
+
const tokens = options.tokens;
|
|
29
|
+
const imageParams = (params, token)=>token ? {
|
|
30
|
+
token
|
|
31
|
+
} : params ?? {};
|
|
32
|
+
const playerParams = tokens ? {
|
|
33
|
+
'playback-token': tokens.video,
|
|
34
|
+
'storyboard-token': tokens.storyboard,
|
|
35
|
+
'thumbnail-token': tokens.thumbnail
|
|
36
|
+
} : {};
|
|
37
|
+
return {
|
|
38
|
+
animated: withQuery(`${bases.image}/${pid}/animated.gif`, imageParams(options.animated, tokens?.gif)),
|
|
39
|
+
...options.mp4 ? {
|
|
40
|
+
downloadMp4: withQuery(`${bases.stream}/${pid}/highest.mp4`, {
|
|
41
|
+
token: tokens?.video
|
|
42
|
+
})
|
|
43
|
+
} : {},
|
|
44
|
+
hls: withQuery(`${bases.stream}/${pid}.m3u8`, {
|
|
45
|
+
token: tokens?.video
|
|
46
|
+
}),
|
|
47
|
+
iframe: withQuery(`${bases.player}/${pid}`, playerParams),
|
|
48
|
+
storyboard: withQuery(`${bases.image}/${pid}/storyboard.vtt`, {
|
|
49
|
+
token: tokens?.storyboard
|
|
50
|
+
}),
|
|
51
|
+
thumbnail: withQuery(`${bases.image}/${pid}/thumbnail.jpg`, imageParams(options.thumbnail, tokens?.thumbnail)),
|
|
52
|
+
watch: withQuery(`${bases.player}/watch/${pid}`, playerParams)
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** URL of a static rendition file (`highest.mp4`, `audio.m4a`) for a public playback id. */ export const muxStaticRenditionUrl = (playbackId, file, streamBase = MUX_DELIVERY_BASE_URLS.stream, token)=>withQuery(`${streamBase}/${enc(playbackId)}/${file}`, {
|
|
56
|
+
token
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=urls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/mux/urls.ts"],"sourcesContent":["/**\n * Mux delivery URLs. Pure functions: tokens are passed in, never created here.\n * @see https://www.mux.com/docs/guides/get-images-from-a-video\n * @see https://www.mux.com/docs/guides/player-mux-com\n */\n\nexport type MuxDeliveryBaseUrls = {\n /** Default `https://image.mux.com`. */\n image: string\n /** Default `https://player.mux.com`. */\n player: string\n /** Default `https://stream.mux.com`. */\n stream: string\n}\n\nexport const MUX_DELIVERY_BASE_URLS: MuxDeliveryBaseUrls = {\n image: 'https://image.mux.com',\n player: 'https://player.mux.com',\n stream: 'https://stream.mux.com',\n}\n\n/** Thumbnail options. For public playback ids they go in the URL, for signed ones in the `t` token. */\nexport type MuxThumbnailOptions = {\n fit_mode?: 'crop' | 'pad' | 'preserve' | 'smartcrop' | 'stretch'\n height?: number\n /** Seconds. Default: the asset's `thumbnail_time`, else the middle of the video. */\n time?: number\n width?: number\n}\n\n/** Animated preview options (max 10 seconds, max 640px). */\nexport type MuxAnimatedOptions = {\n end?: number\n fps?: number\n height?: number\n start?: number\n width?: number\n}\n\n/** Tokens for a signed playback id, one per audience. */\nexport type MuxPlaybackTokens = {\n gif: string\n storyboard: string\n thumbnail: string\n video: string\n}\n\nconst withQuery = (url: string, params: Record<string, number | string | undefined>): string => {\n const entries = Object.entries(params).filter((e): e is [string, number | string] => e[1] !== undefined && e[1] !== '')\n if (!entries.length) {\n return url\n }\n const query = new URLSearchParams(entries.map(([k, v]) => [k, String(v)]))\n return `${url}?${query.toString()}`\n}\n\nconst enc = encodeURIComponent\n\nexport type MuxPlaybackUrlOptions = {\n animated?: MuxAnimatedOptions\n bases?: Partial<MuxDeliveryBaseUrls>\n /** Include `downloadMp4` (`highest.mp4`). */\n mp4?: boolean\n thumbnail?: MuxThumbnailOptions\n /** Signed playback: one token per audience. Image options then live in the tokens, not the URLs. */\n tokens?: MuxPlaybackTokens\n}\n\n/** Builds HLS, poster, animated, iframe and (optionally) MP4 URLs for a playback id. */\nexport const buildMuxPlaybackUrls = (\n playbackId: string,\n options: MuxPlaybackUrlOptions = {},\n): { animated: string; downloadMp4?: string; hls: string; iframe: string; storyboard: string; thumbnail: string; watch: string } => {\n const bases = { ...MUX_DELIVERY_BASE_URLS, ...options.bases }\n const pid = enc(playbackId)\n const tokens = options.tokens\n const imageParams = (params: Record<string, number | string | undefined> | undefined, token: string | undefined) =>\n token ? { token } : (params ?? {})\n const playerParams = tokens\n ? { 'playback-token': tokens.video, 'storyboard-token': tokens.storyboard, 'thumbnail-token': tokens.thumbnail }\n : {}\n return {\n animated: withQuery(`${bases.image}/${pid}/animated.gif`, imageParams(options.animated, tokens?.gif)),\n ...(options.mp4 ? { downloadMp4: withQuery(`${bases.stream}/${pid}/highest.mp4`, { token: tokens?.video }) } : {}),\n hls: withQuery(`${bases.stream}/${pid}.m3u8`, { token: tokens?.video }),\n iframe: withQuery(`${bases.player}/${pid}`, playerParams),\n storyboard: withQuery(`${bases.image}/${pid}/storyboard.vtt`, { token: tokens?.storyboard }),\n thumbnail: withQuery(`${bases.image}/${pid}/thumbnail.jpg`, imageParams(options.thumbnail, tokens?.thumbnail)),\n watch: withQuery(`${bases.player}/watch/${pid}`, playerParams),\n }\n}\n\n/** URL of a static rendition file (`highest.mp4`, `audio.m4a`) for a public playback id. */\nexport const muxStaticRenditionUrl = (playbackId: string, file: string, streamBase = MUX_DELIVERY_BASE_URLS.stream, token?: string): string =>\n withQuery(`${streamBase}/${enc(playbackId)}/${file}`, { token })\n"],"names":["MUX_DELIVERY_BASE_URLS","image","player","stream","withQuery","url","params","entries","Object","filter","e","undefined","length","query","URLSearchParams","map","k","v","String","toString","enc","encodeURIComponent","buildMuxPlaybackUrls","playbackId","options","bases","pid","tokens","imageParams","token","playerParams","video","storyboard","thumbnail","animated","gif","mp4","downloadMp4","hls","iframe","watch","muxStaticRenditionUrl","file","streamBase"],"mappings":"AAAA;;;;CAIC,GAWD,OAAO,MAAMA,yBAA8C;IACzDC,OAAO;IACPC,QAAQ;IACRC,QAAQ;AACV,EAAC;AA4BD,MAAMC,YAAY,CAACC,KAAaC;IAC9B,MAAMC,UAAUC,OAAOD,OAAO,CAACD,QAAQG,MAAM,CAAC,CAACC,IAAsCA,CAAC,CAAC,EAAE,KAAKC,aAAaD,CAAC,CAAC,EAAE,KAAK;IACpH,IAAI,CAACH,QAAQK,MAAM,EAAE;QACnB,OAAOP;IACT;IACA,MAAMQ,QAAQ,IAAIC,gBAAgBP,QAAQQ,GAAG,CAAC,CAAC,CAACC,GAAGC,EAAE,GAAK;YAACD;YAAGE,OAAOD;SAAG;IACxE,OAAO,GAAGZ,IAAI,CAAC,EAAEQ,MAAMM,QAAQ,IAAI;AACrC;AAEA,MAAMC,MAAMC;AAYZ,sFAAsF,GACtF,OAAO,MAAMC,uBAAuB,CAClCC,YACAC,UAAiC,CAAC,CAAC;IAEnC,MAAMC,QAAQ;QAAE,GAAGzB,sBAAsB;QAAE,GAAGwB,QAAQC,KAAK;IAAC;IAC5D,MAAMC,MAAMN,IAAIG;IAChB,MAAMI,SAASH,QAAQG,MAAM;IAC7B,MAAMC,cAAc,CAACtB,QAAiEuB,QACpFA,QAAQ;YAAEA;QAAM,IAAKvB,UAAU,CAAC;IAClC,MAAMwB,eAAeH,SACjB;QAAE,kBAAkBA,OAAOI,KAAK;QAAE,oBAAoBJ,OAAOK,UAAU;QAAE,mBAAmBL,OAAOM,SAAS;IAAC,IAC7G,CAAC;IACL,OAAO;QACLC,UAAU9B,UAAU,GAAGqB,MAAMxB,KAAK,CAAC,CAAC,EAAEyB,IAAI,aAAa,CAAC,EAAEE,YAAYJ,QAAQU,QAAQ,EAAEP,QAAQQ;QAChG,GAAIX,QAAQY,GAAG,GAAG;YAAEC,aAAajC,UAAU,GAAGqB,MAAMtB,MAAM,CAAC,CAAC,EAAEuB,IAAI,YAAY,CAAC,EAAE;gBAAEG,OAAOF,QAAQI;YAAM;QAAG,IAAI,CAAC,CAAC;QACjHO,KAAKlC,UAAU,GAAGqB,MAAMtB,MAAM,CAAC,CAAC,EAAEuB,IAAI,KAAK,CAAC,EAAE;YAAEG,OAAOF,QAAQI;QAAM;QACrEQ,QAAQnC,UAAU,GAAGqB,MAAMvB,MAAM,CAAC,CAAC,EAAEwB,KAAK,EAAEI;QAC5CE,YAAY5B,UAAU,GAAGqB,MAAMxB,KAAK,CAAC,CAAC,EAAEyB,IAAI,eAAe,CAAC,EAAE;YAAEG,OAAOF,QAAQK;QAAW;QAC1FC,WAAW7B,UAAU,GAAGqB,MAAMxB,KAAK,CAAC,CAAC,EAAEyB,IAAI,cAAc,CAAC,EAAEE,YAAYJ,QAAQS,SAAS,EAAEN,QAAQM;QACnGO,OAAOpC,UAAU,GAAGqB,MAAMvB,MAAM,CAAC,OAAO,EAAEwB,KAAK,EAAEI;IACnD;AACF,EAAC;AAED,0FAA0F,GAC1F,OAAO,MAAMW,wBAAwB,CAAClB,YAAoBmB,MAAcC,aAAa3C,uBAAuBG,MAAM,EAAE0B,QAClHzB,UAAU,GAAGuC,WAAW,CAAC,EAAEvB,IAAIG,YAAY,CAAC,EAAEmB,MAAM,EAAE;QAAEb;IAAM,GAAE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ProviderRef } from '../../core/provider.js';
|
|
2
|
+
import type { MuxWebhookEvent } from './types.js';
|
|
3
|
+
export declare const MUX_SIGNATURE_HEADER = "mux-signature";
|
|
4
|
+
export type MuxWebhookVerificationResult = {
|
|
5
|
+
ok: false;
|
|
6
|
+
reason: 'invalid_signature' | 'malformed_header' | 'missing_header' | 'stale';
|
|
7
|
+
} | {
|
|
8
|
+
ok: true;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
};
|
|
11
|
+
/** Parses `t=1565220904,v1=20c75c…[,v1=…]` into its timestamp and `v1` signatures. */
|
|
12
|
+
export declare const parseMuxSignatureHeader: (header: string) => {
|
|
13
|
+
signatures: string[];
|
|
14
|
+
timestamp: number;
|
|
15
|
+
} | null;
|
|
16
|
+
/** The hex HMAC-SHA256 Mux sends as `v1`: keyed with the webhook secret, over `${t}.${rawBody}`. */
|
|
17
|
+
export declare const computeMuxSignature: (secret: string, timestamp: number | string, rawBody: string) => string;
|
|
18
|
+
/** Builds a valid `Mux-Signature` header value (tests and local tooling). */
|
|
19
|
+
export declare const createMuxSignatureHeader: (secret: string, rawBody: string, timestamp?: number) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Verifies a Mux webhook request.
|
|
22
|
+
* @param rawBody the exact request body: do not re-serialise parsed JSON.
|
|
23
|
+
* @param toleranceSeconds reject timestamps further than this from now (0 disables the check). Default 300, like Mux's SDKs.
|
|
24
|
+
* @see https://www.mux.com/docs/core/verify-webhook-signatures
|
|
25
|
+
*/
|
|
26
|
+
export declare const verifyMuxWebhookSignature: ({ header, now, rawBody, secret, toleranceSeconds, }: {
|
|
27
|
+
header: null | string | undefined;
|
|
28
|
+
now?: number;
|
|
29
|
+
rawBody: string;
|
|
30
|
+
secret: string;
|
|
31
|
+
toleranceSeconds?: number;
|
|
32
|
+
}) => MuxWebhookVerificationResult;
|
|
33
|
+
/**
|
|
34
|
+
* The asset (or pending upload) a Mux notification is about, or `null` for events the plugin ignores
|
|
35
|
+
* (live streams, deleted assets…). Asset state is never taken from the payload: Mux may deliver events
|
|
36
|
+
* twice or out of order, so the core re-reads the asset (`getAsset`) instead.
|
|
37
|
+
*/
|
|
38
|
+
export declare const muxEventRef: (event: MuxWebhookEvent) => null | ProviderRef;
|