You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+214-2Lines changed: 214 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,9 @@
4
4
5
5
This library provides convenient access to the Mux REST API from server-side TypeScript or JavaScript.
6
6
7
+
> [!NOTE]
8
+
> In February 2024 this SDK was updated to Version 8.0. For upgrading to 8.x see [UPGRADE_8.x.md](https://github.com/muxinc/mux-node-sdk/blob/master/UPGRADE_8.x.md)
9
+
7
10
The REST API documentation can be found on [docs.mux.com](https://docs.mux.com). The full API of this library can be found in [api.md](api.md).
8
11
9
12
## Installation
@@ -63,6 +66,215 @@ main();
63
66
64
67
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
To simplify this use-case, you can provide multiple types to `signPlaybackId` to recieve multiple tokens. These tokens are provided in a format that Mux Player can take as props:
If you would like to provide params to a single token (e.g., if you would like to have a thumbnail `time`), you can provide `[type, typeParams]` instead of `type`:
Verifying Webhook Signatures is _optional but encouraged_. Learn more in our [Webhook Security Guide](https://docs.mux.com/docs/webhook-security)
214
+
215
+
```js
216
+
/*
217
+
If the header is valid, this function will not throw an error and will not return a value.
218
+
If the header is invalid, this function will throw one of the following errors:
219
+
- new Error(
220
+
"The webhook secret must either be set using the env var, MUX_WEBHOOK_SECRET, on the client class, Mux({ webhookSecret: '123' }), or passed to this function",
221
+
);
222
+
- new Error('Could not find a mux-signature header');
223
+
- new Error(
224
+
'Webhook body must be passed as the raw JSON string sent from the server (do not parse it first).',
225
+
);
226
+
- new Error('Unable to extract timestamp and signatures from header')
227
+
- new Error('No v1 signatures found');
228
+
- new Error('No signatures found matching the expected signature for payload.')
229
+
- new Error('Webhook timestamp is too old')
230
+
*/
231
+
232
+
/*
233
+
`body` is the raw request body. It should be a string representation of a JSON object.
234
+
`headers` is the value in request.headers
235
+
`secret` is the signing secret for this configured webhook. You can find that in your webhooks dashboard
236
+
(note that this secret is different than your API Secret Key)
Note that when passing in the payload (body) you want to pass in the raw un-parsed request body, not the parsed JSON. Here's an example if you are using express.
243
+
244
+
```js
245
+
constMux=require('@mux/mux-node');
246
+
constmux=newMux();
247
+
constexpress=require('express');
248
+
constbodyParser=require('body-parser');
249
+
250
+
/**
251
+
* You'll need to make sure this is externally accessible. ngrok (https://ngrok.com/)
If you're coming a version of this SDK before 8.0 then a lot has changed.
4
+
5
+
For context & background see the [announcement issue](https://github.com/muxinc/mux-node-sdk/issues/327).
6
+
7
+
## Codemod
8
+
9
+
There is a codemod script you can run which will modify the old function calls to the new 8.0 syntax:
10
+
11
+
```
12
+
npx @getgrit/launcher apply mux_v8
13
+
```
14
+
15
+
This will edit the files in your project in a way that converts your existing code to the new v8 syntax. The codemod script is working well for us, but you should still verify your code changes and make sure it works as expected before deploying the new code to production.
16
+
17
+
This codemod script was tested and run against code running 7.x versions of the SDK. If you're on a version before 7.x you can still run it, but it might not work as reliably and if you're running into issues you may want to upgrade to 7.3.5 before running the codemod.
18
+
19
+
## Documentation
20
+
21
+
The current [README](https://github.com/muxinc/mux-node-sdk/blob/master/README.md) has everything else to get started with version 8.
22
+
23
+
You also may want to look at [api.md](https://github.com/muxinc/mux-node-sdk/blob/master/api.md) for a full API reference.
0 commit comments