@ix-xs/twitch.api 2.0.1 → 2.0.3

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 CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to `@ix-xs/twitch.api` are documented here. This project
4
4
  adheres to [Semantic Versioning](https://semver.org).
5
5
 
6
+ ## 2.0.3
7
+
8
+ ### Documentation
9
+
10
+ - The README, which is also the npm page, now links to the documentation
11
+ site (in English and in French), to the reference and to the repository.
12
+ No change to the code.
13
+
14
+ ## 2.0.2
15
+
16
+ ### Fixed
17
+
18
+ - `twitch.rateLimitOf()` returned `undefined` on a client with little traffic.
19
+ Twitch reports a reset time that is already reached when the bucket is
20
+ nearly full, and the client took that for a finished window. It now reports
21
+ the bucket as full once its reset time has passed.
22
+
6
23
  ## 2.0.1
7
24
 
8
25
  ### Changed
package/README.md CHANGED
@@ -11,8 +11,15 @@ _Every Helix endpoint. Every EventSub event. Fully typed. Zero dependencies._
11
11
  [![CI](https://img.shields.io/github/actions/workflow/status/ix-xs/twitch.api/ci.yml?branch=main&label=CI&logo=github)](https://github.com/ix-xs/twitch.api/actions)
12
12
  [![node](https://img.shields.io/badge/node-%3E%3D22-brightgreen?logo=node.js&logoColor=white)](https://nodejs.org)
13
13
  [![types](https://img.shields.io/badge/types-included-3178c6?logo=typescript&logoColor=white)](#)
14
- [![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](./package.json)
15
- [![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
14
+ [![dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)](https://github.com/ix-xs/twitch.api/blob/main/package.json)
15
+ [![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/ix-xs/twitch.api/blob/main/LICENSE)
16
+
17
+ **[Documentation](https://ix-xs.github.io/twitch.api/)** ·
18
+ [Quick start](https://ix-xs.github.io/twitch.api/quick-start/) ·
19
+ [API reference](https://ix-xs.github.io/twitch.api/reference/overview/) ·
20
+ [Recipes](https://ix-xs.github.io/twitch.api/recipes/chat-bot/) ·
21
+ [Troubleshooting](https://ix-xs.github.io/twitch.api/help/troubleshooting/) ·
22
+ [GitHub](https://github.com/ix-xs/twitch.api)
16
23
 
17
24
  </div>
18
25
 
@@ -38,6 +45,8 @@ for await (const stream of twitch.streams.get({ language: "fr" })) {
38
45
 
39
46
  No token to fetch, no header to set, no cursor to carry around, no `429` to catch. You call a method, you get typed data.
40
47
 
48
+ This page is the short tour. The [documentation site](https://ix-xs.github.io/twitch.api/) has the guides, complete programs to copy and the reference of every method and event type, in English and [in French](https://ix-xs.github.io/twitch.api/fr/).
49
+
41
50
  ## What you get
42
51
 
43
52
  | | |
@@ -471,11 +480,11 @@ const twitch = new Twitch({ clientId, clientSecret, baseUrl: "http://localhost:8
471
480
  | `twitch.whispers` | Whispers |
472
481
  | `twitch.auth` | Tokens and OAuth flows |
473
482
 
474
- Every method has an example and a link to the official reference in its documentation: hover it in your editor.
483
+ Every method has an example and a link to the official reference in its documentation: hover it in your editor. The [reference](https://ix-xs.github.io/twitch.api/reference/overview/) lists them all, with their parameters, what they return and the token they need, and the [event types](https://ix-xs.github.io/twitch.api/reference/event-types/) page does the same for EventSub.
475
484
 
476
485
  ## Coming from version 1
477
486
 
478
- Version 2 is a rewrite. The main differences:
487
+ Version 2 is a rewrite. The [migration page](https://ix-xs.github.io/twitch.api/help/migrating-from-v1/) has the details and a before and after example. The main differences:
479
488
 
480
489
  - The client is a named export and takes `clientId` / `clientSecret`: `new Twitch({ clientId, clientSecret })`.
481
490
  - No `initialize()`. Tokens are fetched when needed, and nothing is written to `node_modules` anymore.
@@ -499,6 +508,13 @@ Version 2 is a rewrite. The main differences:
499
508
  | `client.getGames(names)` | `twitch.games.get({ name })` |
500
509
  | `client.getVideos(login)` | `twitch.videos.get({ user_id })` |
501
510
 
511
+ ## Links
512
+
513
+ - [Documentation](https://ix-xs.github.io/twitch.api/), also [in French](https://ix-xs.github.io/twitch.api/fr/)
514
+ - [Source code and issues](https://github.com/ix-xs/twitch.api) on GitHub
515
+ - [Changelog](https://github.com/ix-xs/twitch.api/blob/main/CHANGELOG.md)
516
+ - [Package](https://www.npmjs.com/package/@ix-xs/twitch.api) on npm
517
+
502
518
  ## License
503
519
 
504
- [MIT](./LICENSE)
520
+ [MIT](https://github.com/ix-xs/twitch.api/blob/main/LICENSE)
package/dist/index.cjs CHANGED
@@ -3104,7 +3104,8 @@ var RateLimiter = class {
3104
3104
  if (!state) return 0;
3105
3105
  const now = Date.now();
3106
3106
  if (now >= state.resetAt) {
3107
- this.#buckets.delete(bucket);
3107
+ if (state.limit === 0) this.#buckets.delete(bucket);
3108
+ else state.remaining = state.limit;
3108
3109
  return 0;
3109
3110
  }
3110
3111
  if (state.remaining > 0) {
@@ -3638,7 +3639,8 @@ var Twitch = class _Twitch {
3638
3639
  }
3639
3640
  rateLimitOf(userId) {
3640
3641
  const state = this.#shared.limiter.get(userId ? `user:${userId}` : "app");
3641
- return state && state.resetAt > Date.now() ? { ...state } : void 0;
3642
+ if (!state || state.limit === 0) return void 0;
3643
+ return state.resetAt > Date.now() ? { ...state } : { ...state, remaining: state.limit };
3642
3644
  }
3643
3645
  close() {
3644
3646
  this.#shared.auth.close();
package/dist/index.d.cts CHANGED
@@ -11218,6 +11218,10 @@ declare class Twitch {
11218
11218
  /**
11219
11219
  * What is known about a rate limit bucket: the app token's by default, a
11220
11220
  * user's when you pass their ID. `undefined` until Twitch has reported it.
11221
+ *
11222
+ * `resetAt` is when the bucket is full again. Twitch refills it as time
11223
+ * passes, so with little traffic that moment is always close: once it has
11224
+ * passed, the bucket is reported full.
11221
11225
  */
11222
11226
  rateLimitOf(userId?: string): {
11223
11227
  limit: number;
package/dist/index.d.ts CHANGED
@@ -11218,6 +11218,10 @@ declare class Twitch {
11218
11218
  /**
11219
11219
  * What is known about a rate limit bucket: the app token's by default, a
11220
11220
  * user's when you pass their ID. `undefined` until Twitch has reported it.
11221
+ *
11222
+ * `resetAt` is when the bucket is full again. Twitch refills it as time
11223
+ * passes, so with little traffic that moment is always close: once it has
11224
+ * passed, the bucket is reported full.
11221
11225
  */
11222
11226
  rateLimitOf(userId?: string): {
11223
11227
  limit: number;
package/dist/index.js CHANGED
@@ -3102,7 +3102,8 @@ var RateLimiter = class {
3102
3102
  if (!state) return 0;
3103
3103
  const now = Date.now();
3104
3104
  if (now >= state.resetAt) {
3105
- this.#buckets.delete(bucket);
3105
+ if (state.limit === 0) this.#buckets.delete(bucket);
3106
+ else state.remaining = state.limit;
3106
3107
  return 0;
3107
3108
  }
3108
3109
  if (state.remaining > 0) {
@@ -3636,7 +3637,8 @@ var Twitch = class _Twitch {
3636
3637
  }
3637
3638
  rateLimitOf(userId) {
3638
3639
  const state = this.#shared.limiter.get(userId ? `user:${userId}` : "app");
3639
- return state && state.resetAt > Date.now() ? { ...state } : void 0;
3640
+ if (!state || state.limit === 0) return void 0;
3641
+ return state.resetAt > Date.now() ? { ...state } : { ...state, remaining: state.limit };
3640
3642
  }
3641
3643
  close() {
3642
3644
  this.#shared.auth.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ix-xs/twitch.api",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "The whole Twitch API, typed. A zero-dependency client for JavaScript and TypeScript: all 149 Helix endpoints and 83 EventSub events, with tokens, rate limits, pagination and reconnects handled for you.",
5
5
  "keywords": [
6
6
  "twitch",