ts-twitch-api 0.2.8 → 0.3.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/README.md +18 -18
- package/dist/index.cjs +6694 -6297
- package/dist/index.d.cts +19641 -18459
- package/dist/index.d.mts +19881 -0
- package/dist/index.mjs +6696 -0
- package/package.json +26 -19
- package/dist/index.d.ts +0 -18699
- package/dist/index.js +0 -6273
package/README.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Very simple `TwitchApi` class and TypeScript interfaces for all Twitch API endpoints
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
- Auto-generated from [twitch-api-swagger](https://github.com/DmitryScaletta/twitch-api-swagger)
|
|
6
|
+
- Uses `fetch` under the hood
|
|
7
|
+
- Includes types for all endpoints
|
|
8
|
+
- _Request Query Parameters_
|
|
9
|
+
- _Request Body_
|
|
10
|
+
- _Response Body_
|
|
11
|
+
- Includes descriptions for the fields
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
UpdateAutoModSettingsParams,
|
|
30
30
|
UpdateAutoModSettingsBody,
|
|
31
31
|
UpdateAutoModSettingsResponse,
|
|
32
|
-
} from
|
|
32
|
+
} from "ts-twitch-api";
|
|
33
33
|
|
|
34
34
|
const updateAutoModSettings = async (
|
|
35
35
|
params: UpdateAutoModSettingsParams,
|
|
@@ -38,22 +38,22 @@ const updateAutoModSettings = async (
|
|
|
38
38
|
const searchParams = new URLSearchParams(params);
|
|
39
39
|
const url = `https://api.twitch.tv/helix/moderation/automod/settings?${searchParams}`;
|
|
40
40
|
const response = await fetch(url, {
|
|
41
|
-
method:
|
|
41
|
+
method: "PUT",
|
|
42
42
|
body: JSON.stringify(body),
|
|
43
43
|
headers: {
|
|
44
44
|
Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
"Client-Id": process.env.CLIENT_ID,
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
return response.json() as Promise<UpdateAutoModSettingsResponse>;
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
### `TwitchApi` class
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
-
import { TwitchApi } from
|
|
56
|
+
import { TwitchApi } from "ts-twitch-api";
|
|
57
57
|
|
|
58
58
|
const twitchApi = new TwitchApi({
|
|
59
59
|
accessToken: process.env.ACCESS_TOKEN,
|
|
@@ -62,7 +62,7 @@ const twitchApi = new TwitchApi({
|
|
|
62
62
|
|
|
63
63
|
const response = await twitchApi.chat.updateChatSettings(
|
|
64
64
|
// query params
|
|
65
|
-
{ broadcaster_id:
|
|
65
|
+
{ broadcaster_id: "1", moderator_id: "2" },
|
|
66
66
|
// body
|
|
67
67
|
{ emote_mode: true },
|
|
68
68
|
);
|
|
@@ -75,11 +75,11 @@ if (response.ok) {
|
|
|
75
75
|
|
|
76
76
|
const streams = await twitchApi.streams.getStreams(
|
|
77
77
|
// some endpoints accept multiple ids like this: `id=1234&id=5678`
|
|
78
|
-
{ user_id: [
|
|
78
|
+
{ user_id: ["1", "2"] },
|
|
79
79
|
// override accessToken and/or clientId for different requests
|
|
80
80
|
{
|
|
81
|
-
accessToken:
|
|
82
|
-
clientId:
|
|
81
|
+
accessToken: "<accessToken>",
|
|
82
|
+
clientId: "<clientId>",
|
|
83
83
|
},
|
|
84
84
|
);
|
|
85
85
|
|
|
@@ -90,7 +90,7 @@ if (streams.ok) {
|
|
|
90
90
|
// pass fetch options via RequestInit object
|
|
91
91
|
const ac = new AbortController();
|
|
92
92
|
const users = twitchApi.users.getUsers(
|
|
93
|
-
{ id: [
|
|
93
|
+
{ id: ["1", "2"] },
|
|
94
94
|
{ requestInit: { signal: ac.signal } },
|
|
95
95
|
);
|
|
96
96
|
|