ts-twitch-api 0.1.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.
- package/README.md +91 -0
- package/index.ts +2 -0
- package/package.json +31 -0
- package/twitch-api.generated.ts +12365 -0
- package/twitch-api.ts +6653 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# ts-twitch-api
|
|
2
|
+
|
|
3
|
+
Very simple `TwitchApi` class and TypeScript interfaces for all Twitch API endpoints
|
|
4
|
+
|
|
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
|
+
|
|
13
|
+
## TODO
|
|
14
|
+
|
|
15
|
+
* Pass RequestInit object
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm i ts-twitch-api
|
|
21
|
+
|
|
22
|
+
pnpm i ts-twitch-api
|
|
23
|
+
|
|
24
|
+
yarn add ts-twitch-api
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Types only
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import type {
|
|
33
|
+
UpdateAutoModSettingsParams,
|
|
34
|
+
UpdateAutoModSettingsBody,
|
|
35
|
+
UpdateAutoModSettingsResponse,
|
|
36
|
+
} from 'ts-twitch-api';
|
|
37
|
+
|
|
38
|
+
const updateAutoModSettings = async (
|
|
39
|
+
params: UpdateAutoModSettingsParams,
|
|
40
|
+
body: UpdateAutoModSettingsBody,
|
|
41
|
+
) => {
|
|
42
|
+
const searchParams = new URLSearchParams(params);
|
|
43
|
+
const url = `https://api.twitch.tv/helix/moderation/automod/settings?${searchParams}`;
|
|
44
|
+
const response = await fetch(url, {
|
|
45
|
+
method: 'PUT',
|
|
46
|
+
body: JSON.stringify(body),
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${process.env.ACCESS_TOKEN}`,
|
|
49
|
+
'Client-Id': process.env.CLIENT_ID,
|
|
50
|
+
'Content-Type': 'application/json',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
return response.json() as Promise<UpdateAutoModSettingsResponse>;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `TwitchApi` class
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { TwitchApi } from 'ts-twitch-api';
|
|
61
|
+
|
|
62
|
+
const twitchApi = new TwitchApi({
|
|
63
|
+
accessToken: process.env.ACCESS_TOKEN,
|
|
64
|
+
clientId: process.env.CLIENT_ID,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const response = await twitchApi.chat.updateChatSettings(
|
|
68
|
+
// query params
|
|
69
|
+
{ broadcaster_id: '1', moderator_id: '2' },
|
|
70
|
+
// body
|
|
71
|
+
{ emote_mode: true },
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
if (response.ok) {
|
|
75
|
+
console.log(response.data);
|
|
76
|
+
} else {
|
|
77
|
+
console.error(response.status);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const streams = await twitchApi.streams.getStreams(
|
|
81
|
+
// some endpoints accept multiple ids like this: `id=1234&id=5678`
|
|
82
|
+
{ user_id: ['1', '2'] },
|
|
83
|
+
// override accessToken and/or clientId for different requests
|
|
84
|
+
'<accessToken>',
|
|
85
|
+
'<clientId>',
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (streams.ok) {
|
|
89
|
+
console.log(streams.data);
|
|
90
|
+
}
|
|
91
|
+
```
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts-twitch-api",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Very simple TwitchApi class and TypeScript interfaces for all Twitch API endpoints",
|
|
5
|
+
"author": "DmitryScaletta",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/DmitryScaletta/ts-twitch-api.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/DmitryScaletta/ts-twitch-api/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "index.ts",
|
|
16
|
+
"files": [
|
|
17
|
+
"index.ts",
|
|
18
|
+
"twitch-api.ts",
|
|
19
|
+
"twitch-api.generated.ts"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^20.11.2",
|
|
24
|
+
"tsx": "^4.7.0",
|
|
25
|
+
"typescript": "^5.3.3"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node --import tsx ./scripts/build.ts",
|
|
29
|
+
"gen": "pnpm dlx openapi-typescript https://github.com/DmitryScaletta/twitch-api-swagger/raw/main/openapi.json --output twitch-api.generated.ts"
|
|
30
|
+
}
|
|
31
|
+
}
|