@ix-xs/twitch.api 1.0.5 → 2.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@ix-xs/twitch.api` are documented here. This project
4
+ adheres to [Semantic Versioning](https://semver.org).
5
+
6
+ ## 2.0.0
7
+
8
+ A rewrite from scratch, in TypeScript. Version 1 covered 12 endpoints with an
9
+ app token. Version 2 covers the whole Twitch API, user tokens and EventSub.
10
+
11
+ ### Breaking
12
+
13
+ - The client is the named export `Twitch` and takes `clientId` and
14
+ `clientSecret`. Version 1 documented those names but read `client_id` and
15
+ `client_secret`.
16
+ - `initialize()` is gone. Tokens are requested when a call needs them.
17
+ - Methods throw typed errors (`TwitchApiError`, `TwitchAuthError`...) instead
18
+ of returning `{ ok, result }`.
19
+ - Methods are grouped (`twitch.users.get`, `twitch.streams.get`...) and take
20
+ IDs, like the Twitch API. The README has the full mapping from version 1.
21
+ - Node.js 22 or later is required.
22
+
23
+ ### Added
24
+
25
+ - **Every Helix endpoint**: 149 endpoints in 30 groups, with typed parameters
26
+ and responses, an example and a link to the official reference on each method.
27
+ - **Every EventSub subscription type**: 83 typed conditions and events, with
28
+ discriminated unions for the events that come in several shapes
29
+ (`channel.chat.notification`, `channel.moderate`, `channel.bits.use`...).
30
+ - **EventSub listeners** for WebSocket, webhooks and conduits behind one typed
31
+ `on()`: automatic reconnection and resubscription, Twitch's reconnect
32
+ handover, keepalive watchdog, signature verification, replay and duplicate
33
+ protection. Webhooks plug into Fetch API runtimes and Node.js servers.
34
+ - **User tokens**: authorization code flow, device code flow, automatic
35
+ refresh, hourly validation, revocation, and a pluggable `TokenStore`
36
+ (`FileTokenStore` in `@ix-xs/twitch.api/node`).
37
+ - **Automatic choice of token**: each endpoint knows whether it needs the app
38
+ token or a user's, and whose. The acting user (`moderator_id`,
39
+ `broadcaster_id`, `sender_id`...) defaults to the owner of the token. `{ as }`
40
+ and `twitch.as()` choose a user explicitly, and `"app"` asks for the app
41
+ token.
42
+ - **Scope checks before the request**, with the missing scope in the error.
43
+ - **Pagination helpers**: `await` for a page, `for await` for every item,
44
+ `all()`, `take()`, `first()`, `total()`.
45
+ - **Batching**: ID lists longer than Twitch's cap are split and fetched in
46
+ parallel, and single lookups made at the same moment are merged into one
47
+ request.
48
+ - **Rate limit handling**: per token buckets followed from the response
49
+ headers, waiting instead of failing, retries with backoff for what is safe
50
+ to retry, timeouts and `AbortSignal` support.
51
+ - **Typed errors**: `TwitchApiError`, `TwitchRateLimitError`,
52
+ `TwitchAuthError`, `TwitchScopeError`, `TwitchTimeoutError`,
53
+ `TwitchNetworkError` and `TwitchEventSubError`, all extending `TwitchError`.
54
+ - `twitch.request()` and `twitch.paginate()` for endpoints newer than the
55
+ library, and `request`, `response`, `rateLimit`, `tokenRefresh` and
56
+ `tokenInvalid` events.
57
+ - ESM and CommonJS builds with type declarations for both.
58
+
59
+ ### Fixed
60
+
61
+ - The token is no longer written inside `node_modules`, which broke on
62
+ read-only file systems, with pnpm, in monorepos and on every reinstall.
63
+ - The client secret is sent in the request body, not in the URL.
64
+ - Query values are URL encoded.
65
+ - The validation timer no longer keeps the process alive.
66
+
67
+ ### Removed
68
+
69
+ - Dependencies: there are none.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ix-xs.dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.