@neuroinfoapi-client/bun 2.6.0 → 2.7.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.
Files changed (4) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +293 -290
  3. package/dist/index.js +1 -1
  4. package/package.json +54 -54
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Appstun
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Appstun
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.
package/README.md CHANGED
@@ -1,290 +1,293 @@
1
- # @neuroinfoapi-client/bun
2
-
3
- A comprehensive TypeScript/JavaScript client that provides full access to NeuroInfoAPI endpoints with proper type definitions.
4
-
5
- ## Other runtime clients
6
-
7
- - [@neuroinfoapi-client/native](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/native/README.md): standard WebSocket in browsers and Node.js, ticket authentication, and JSON heartbeat.
8
- - [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with the `ws` npm package, automatic protocol pongs, and header authentication by default.
9
-
10
- ## Features
11
-
12
- - HTTP access to streams, VODs, schedules, subathons, blog and X feeds
13
- - Full TypeScript support with typed API responses and event payloads
14
- - HTTP Bearer authentication with an optional token in the constructor
15
- - Type-safe HTTP error handling through `{ data, error }`
16
- - Configurable API base URL and HTTP request timeout (10 seconds by default)
17
- - Bun's native WebSocket, with header authentication by default
18
- - Real-time subscriptions with automatic reconnect and subscription recovery
19
- - Automatic protocol pong replies and a 90-second heartbeat timeout by default
20
- - `NeuroInfoApiEventer` for polling-based updates (deprecated)
21
-
22
- ## Installation
23
-
24
- ```bash
25
- npm install @neuroinfoapi-client/bun
26
- # or
27
- bun add @neuroinfoapi-client/bun
28
- ```
29
-
30
- ## Quick Start
31
-
32
- ```ts
33
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
34
-
35
- // Optional token can be passed directly in the constructor
36
- const client = new NeuroInfoApiClient("your-api-token-here");
37
-
38
- const { data, error } = await client.getCurrentStream();
39
-
40
- if (error) {
41
- console.error(`Error ${error.code}: ${error.message}`);
42
- } else {
43
- console.log(data);
44
- }
45
- ```
46
-
47
- ## Client Configuration
48
-
49
- Constructor signature:
50
-
51
- ```ts
52
- new NeuroInfoApiClient(token?: string, options?: NeuroInfoApiClientOptions)
53
- ```
54
-
55
- `NeuroInfoApiClientOptions` supports:
56
-
57
- | Option | Default | Description |
58
- | ------------------ | ------------------------- | ---------------------------------------- |
59
- | `apiBaseUrl` | `neuroinfoapi.dev/api/v2` | API host and path without a protocol |
60
- | `useTls` | `true` | Use HTTPS when `true`, HTTP when `false` |
61
- | `requestTimeoutMs` | `10000` | HTTP request timeout in milliseconds |
62
-
63
- The legacy `baseUrl` option is deprecated and will be removed in a future major version.
64
-
65
- Examples:
66
-
67
- ```ts
68
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
69
-
70
- // 1) No token in constructor (set later)
71
- const clientA = new NeuroInfoApiClient();
72
- clientA.setApiToken("your-api-token-here");
73
-
74
- // 2) Token in constructor
75
- const clientB = new NeuroInfoApiClient("your-api-token-here");
76
-
77
- // 3) for testing with Mock-TesServer (https://github.com/NeuroInfoAPI/Mock-TestServer)
78
- const clientC = new NeuroInfoApiClient(undefined, {
79
- apiBaseUrl: "localhost:8787/api/v2",
80
- useTls: false,
81
- requestTimeoutMs: 15000,
82
- });
83
- ```
84
-
85
- ## Bun Usage
86
-
87
- ```ts
88
- import { NeuroInfoApiClient, NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
89
-
90
- const client = new NeuroInfoApiClient();
91
- client.setApiToken("your-api-token-here");
92
-
93
- // Sends Authorization: Bearer during the handshake by default
94
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
95
- await wsClient.connect();
96
- ```
97
-
98
- This package defaults to `authMethod: "header"` in Bun. Set `authMethod: "ticket"` to obtain a one-time ticket through HTTP before connecting. For browser usage, use `@neuroinfoapi-client/native`.
99
-
100
- ## Error Handling
101
-
102
- All HTTP API request methods return a result object with either `data` or `error`:
103
-
104
- ```ts
105
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
106
-
107
- const client = new NeuroInfoApiClient("your-api-token-here");
108
- const { data, error } = await client.getCurrentStream();
109
-
110
- if (error) {
111
- // error is NeuroApiError with code, message, and optional status
112
- console.log(`Error ${error.code}: ${error.message}`);
113
- } else if (data.isLive) {
114
- console.log(data.title);
115
- } else {
116
- console.log("Stream is offline");
117
- }
118
- ```
119
-
120
- ## HTTP API Methods
121
-
122
- All methods below return `Promise<ApiResult<T>>`:
123
-
124
- - `getCurrentStream()` — current Twitch stream state
125
- - `getAllVods()` — all Twitch VODs
126
- - `getVod(id)` — a VOD by stream ID
127
- - `getSchedule(week, year?)` — schedule for a specific week and optional year
128
- - `getLatestSchedule()` — latest schedule
129
- - `getScheduleWeeks()` — available schedule weeks grouped by year
130
- - `getDevstreamTimes()` — devstream schedule timestamps
131
- - `getScheduleSearch(query, options?)` — search schedules with filters and cursor pagination
132
- - `getCurrentSubathons()` — currently active subathons
133
- - `getSubathon(year)` — subathon data for a year
134
- - `getSubathonYears()` — available subathon years
135
- - `getBlogFeed(raw?)` — Neuro-sama blog feed; requires an API token
136
- - `getXFeed(user)` — cached X feed for `NeurosamaAI`, `EvilNeuroAI`, or `Vedal987`; requires an API token
137
-
138
- ## Schedule Search Pagination
139
-
140
- Use `getScheduleSearch` and continue with `nextCursor`.
141
- Optional filter: `type` (`normal`, `offline`, `canceled`, `TBD`, `unknown`).
142
-
143
- `/schedule/search` has rate limits (`6 requests/minute` and `2 requests/10 seconds` per token), so avoid tight loops.
144
-
145
- ```ts
146
- import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
147
-
148
- const client = new NeuroInfoApiClient("your-api-token-here");
149
- const firstPage = await client.getScheduleSearch("karaoke", { limit: 5, sort: "desc", type: "normal" });
150
- if (firstPage.error) {
151
- console.error(firstPage.error.code, firstPage.error.message);
152
- } else {
153
- console.log("matches:", firstPage.data.results.length);
154
-
155
- if (firstPage.data.nextCursor) {
156
- const secondPage = await client.getScheduleSearch("karaoke", {
157
- limit: 5,
158
- sort: "desc",
159
- cursor: firstPage.data.nextCursor,
160
- });
161
- console.log("next page:", secondPage.data?.results.length ?? 0);
162
- }
163
- }
164
- ```
165
-
166
- ## Event System (Deprecated)
167
-
168
- `NeuroInfoApiEventer` is deprecated in favor of `NeuroInfoApiWebsocketClient`.
169
-
170
- ```ts
171
- import { NeuroInfoApiEventer } from "@neuroinfoapi-client/bun";
172
-
173
- const eventer = new NeuroInfoApiEventer();
174
- eventer.setApiToken("your-api-token-here");
175
-
176
- eventer.on("streamOnline", (stream) => {
177
- console.log(`${stream.title} is now live!`);
178
- });
179
-
180
- eventer.on(
181
- "scheduleUpdate",
182
- (schedule) => console.log(`New schedule for week ${schedule.week}`),
183
- (error) => console.log(`Failed to fetch schedule: ${error.code}`),
184
- );
185
-
186
- // Default: 60s, minimum: 10s
187
- eventer.fetchInterval = 30000;
188
- eventer.startEventLoop();
189
- ```
190
-
191
- Available events: `streamOnline`, `streamOffline`, `streamUpdate`, `scheduleUpdate`, `subathonUpdate`, `subathonGoalUpdate`
192
-
193
- ## WebSocket Client
194
-
195
- `heartbeatMonitoring` defaults to `true` and can also be changed on the client
196
- instance. Set it to `false` to disable heartbeat timeout monitoring; Native also
197
- stops its automatic JSON pings. Protocol pong replies and incoming `_pong`
198
- notifications remain active.
199
-
200
- Constructor signature:
201
-
202
- ```ts
203
- new NeuroInfoApiWebsocketClient(token: string, options?: NeuroInfoApiWebsocketClientOptions)
204
- ```
205
-
206
- The options include `apiBaseUrl`, `useTls`, `websocketUrl`, `authMethod`, `autoReconnect`, `maxReconnectAttempts`, `reconnectBaseDelay`, `heartbeatMonitoring`, `heartbeatIntervalMs`, `heartbeatTimeoutMs`, and `connectTimeoutMs`. The legacy WebSocket `baseUrl` option is deprecated; use `websocketUrl` for a full URL override.
207
-
208
- ```ts
209
- import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
210
-
211
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
212
-
213
- wsClient.on("_connected", (sessionId) => {
214
- console.log("Connected with session:", sessionId);
215
- });
216
-
217
- wsClient.on("_eventAdded", (eventType) => {
218
- console.log("Subscribed:", eventType);
219
- });
220
-
221
- wsClient.on("_eventRemoved", (eventType) => {
222
- console.log("Unsubscribed:", eventType);
223
- });
224
-
225
- wsClient.on("streamOnline", (stream) => {
226
- console.log("Stream online:", stream.title);
227
- });
228
-
229
- await wsClient.connect();
230
- ```
231
-
232
- Available WebSocket events:
233
-
234
- - `streamOnline`
235
- - `streamOffline`
236
- - `streamUpdate`
237
- - `secretneuroaccountOnline`
238
- - `streamRaidIncoming`
239
- - `streamRaidOutgoing`
240
- - `scheduleUpdate`
241
- - `subathonUpdate`
242
- - `subathonGoalUpdate`
243
- - `blogFeedUpdate`
244
- - `xFeedNewEntries`
245
- - `xFeedUpdate` (deprecated alias for `xFeedNewEntries`)
246
-
247
- **Heartbeat:** The server must send WebSocket protocol ping frames. Bun responds automatically with pong; this package sends no JSON heartbeat messages. The client waits a fixed **90 seconds** for the next server ping; each incoming protocol ping restarts that timer. If the ping is missing, the connection is terminated and automatic reconnect runs when enabled. Disable timeout monitoring with `heartbeatMonitoring: false`. `heartbeatIntervalMs` and `heartbeatTimeoutMs` apply only to Native and are ignored here, both in constructor options and when assigned on the client instance. Automatic protocol pongs remain active when `heartbeatMonitoring: false`. Ticket authentication does not change this heartbeat behavior. The `_pong` event reports heartbeat activity: an incoming server protocol ping that the runtime automatically answers, or an incoming JSON pong. It also fires with `heartbeatMonitoring: false`; that option disables timeout monitoring, not protocol replies or event notifications. This event does not confirm that the server received the reply.
248
-
249
- ## Unsubscribe and clean up
250
-
251
- Using the connected `wsClient` from the WebSocket example:
252
-
253
- ```ts
254
- const unsubscribe = wsClient.on("streamUpdate", (stream) => {
255
- console.log("Updated stream:", stream.title);
256
- });
257
-
258
- // Later, remove this listener.
259
- unsubscribe();
260
-
261
- // Disconnect intentionally; listeners are retained for a later connect().
262
- wsClient.disconnect();
263
-
264
- // When finished, remove every listener and disconnect.
265
- wsClient.destroy();
266
- ```
267
-
268
- `connect()` returns a promise that can reject. Handle connection failures with `try`/`catch`, and register an `_error` listener for errors after connecting:
269
-
270
- ```ts
271
- import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
272
-
273
- const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
274
- wsClient.on("_error", (error) => console.error("WebSocket error:", error));
275
-
276
- try {
277
- await wsClient.connect();
278
- } catch (error) {
279
- console.error("Connection failed:", error);
280
- wsClient.destroy();
281
- }
282
- ```
283
-
284
- ## Documentation
285
-
286
- - [API documentation](https://neuroinfoapi.dev/api/docs)
287
-
288
- ## License
289
-
290
- MIT
1
+ # @neuroinfoapi-client/bun
2
+
3
+ A comprehensive TypeScript/JavaScript client that provides full access to NeuroInfoAPI endpoints with proper type definitions.
4
+
5
+ ## Other runtime clients
6
+
7
+ - [@neuroinfoapi-client/native](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/native/README.md): standard WebSocket in browsers and Node.js, ticket authentication, and JSON heartbeat.
8
+ - [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with the `ws` npm package, automatic protocol pongs, and header authentication by default.
9
+
10
+ ## Features
11
+
12
+ - HTTP access to streams, VODs, schedules, subathons, shop products, blog and X feeds
13
+ - Full TypeScript support with typed API responses and event payloads
14
+ - HTTP Bearer authentication with an optional token in the constructor
15
+ - Type-safe HTTP error handling through `{ data, error }`
16
+ - Configurable API base URL and HTTP request timeout (10 seconds by default)
17
+ - Bun's native WebSocket, with header authentication by default
18
+ - Real-time subscriptions with automatic reconnect and subscription recovery
19
+ - Automatic protocol pong replies and a 90-second heartbeat timeout by default
20
+ - `NeuroInfoApiEventer` for polling-based updates (deprecated)
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install @neuroinfoapi-client/bun
26
+ # or
27
+ bun add @neuroinfoapi-client/bun
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```ts
33
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
34
+
35
+ // Optional token can be passed directly in the constructor
36
+ const client = new NeuroInfoApiClient("your-api-token-here");
37
+
38
+ const { data, error } = await client.getCurrentStream();
39
+
40
+ if (error) {
41
+ console.error(`Error ${error.code}: ${error.message}`);
42
+ } else {
43
+ console.log(data);
44
+ }
45
+ ```
46
+
47
+ ## Client Configuration
48
+
49
+ Constructor signature:
50
+
51
+ ```ts
52
+ new NeuroInfoApiClient(token?: string, options?: NeuroInfoApiClientOptions)
53
+ ```
54
+
55
+ `NeuroInfoApiClientOptions` supports:
56
+
57
+ | Option | Default | Description |
58
+ | ------------------ | ------------------------- | ---------------------------------------- |
59
+ | `apiBaseUrl` | `neuroinfoapi.dev/api/v2` | API host and path without a protocol |
60
+ | `useTls` | `true` | Use HTTPS when `true`, HTTP when `false` |
61
+ | `requestTimeoutMs` | `10000` | HTTP request timeout in milliseconds |
62
+
63
+ The legacy `baseUrl` option is deprecated and will be removed in a future major version.
64
+
65
+ Examples:
66
+
67
+ ```ts
68
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
69
+
70
+ // 1) No token in constructor (set later)
71
+ const clientA = new NeuroInfoApiClient();
72
+ clientA.setApiToken("your-api-token-here");
73
+
74
+ // 2) Token in constructor
75
+ const clientB = new NeuroInfoApiClient("your-api-token-here");
76
+
77
+ // 3) for testing with Mock-TesServer (https://github.com/NeuroInfoAPI/Mock-TestServer)
78
+ const clientC = new NeuroInfoApiClient(undefined, {
79
+ apiBaseUrl: "localhost:8787/api/v2",
80
+ useTls: false,
81
+ requestTimeoutMs: 15000,
82
+ });
83
+ ```
84
+
85
+ ## Bun Usage
86
+
87
+ ```ts
88
+ import { NeuroInfoApiClient, NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
89
+
90
+ const client = new NeuroInfoApiClient();
91
+ client.setApiToken("your-api-token-here");
92
+
93
+ // Sends Authorization: Bearer during the handshake by default
94
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
95
+ await wsClient.connect();
96
+ ```
97
+
98
+ This package defaults to `authMethod: "header"` in Bun. Set `authMethod: "ticket"` to obtain a one-time ticket through HTTP before connecting. For browser usage, use `@neuroinfoapi-client/native`.
99
+
100
+ ## Error Handling
101
+
102
+ All HTTP API request methods return a result object with either `data` or `error`:
103
+
104
+ ```ts
105
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
106
+
107
+ const client = new NeuroInfoApiClient("your-api-token-here");
108
+ const { data, error } = await client.getCurrentStream();
109
+
110
+ if (error) {
111
+ // error is NeuroApiError with code, message, and optional status
112
+ console.log(`Error ${error.code}: ${error.message}`);
113
+ } else if (data.isLive) {
114
+ console.log(data.title);
115
+ } else {
116
+ console.log("Stream is offline");
117
+ }
118
+ ```
119
+
120
+ ## HTTP API Methods
121
+
122
+ All methods below return `Promise<ApiResult<T>>`:
123
+
124
+ - `getCurrentStream()` — current Twitch stream state
125
+ - `getAllVods()` — all Twitch VODs
126
+ - `getVod(id)` — a VOD by stream ID
127
+ - `getSchedule(week, year?)` — schedule for a specific week and optional year
128
+ - `getLatestSchedule()` — latest schedule
129
+ - `getScheduleWeeks()` — available schedule weeks grouped by year
130
+ - `getDevstreamTimes()` — devstream schedule timestamps
131
+ - `getScheduleSearch(query, options?)` — search schedules with filters and cursor pagination
132
+ - `getCurrentSubathons()` — currently active subathons
133
+ - `getSubathon(year)` — subathon data for a year
134
+ - `getSubathonYears()` — available subathon years
135
+ - `getBlogFeed(raw?)` — Neuro-sama blog feed; requires an API token
136
+ - `getShopProducts(currency?)` — shop catalog; requires an API token
137
+ - `getShopProduct(id, currency?)` — one shop product; requires an API token
138
+ - `getXFeed(user)` — cached X feed for `NeurosamaAI`, `EvilNeuroAI`, or `Vedal987`; requires an API token
139
+
140
+ ## Schedule Search Pagination
141
+
142
+ Use `getScheduleSearch` and continue with `nextCursor`.
143
+ Optional filter: `type` (`normal`, `offline`, `canceled`, `TBD`, `unknown`).
144
+
145
+ `/schedule/search` has rate limits (`6 requests/minute` and `2 requests/10 seconds` per token), so avoid tight loops.
146
+
147
+ ```ts
148
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/bun";
149
+
150
+ const client = new NeuroInfoApiClient("your-api-token-here");
151
+ const firstPage = await client.getScheduleSearch("karaoke", { limit: 5, sort: "desc", type: "normal" });
152
+ if (firstPage.error) {
153
+ console.error(firstPage.error.code, firstPage.error.message);
154
+ } else {
155
+ console.log("matches:", firstPage.data.results.length);
156
+
157
+ if (firstPage.data.nextCursor) {
158
+ const secondPage = await client.getScheduleSearch("karaoke", {
159
+ limit: 5,
160
+ sort: "desc",
161
+ cursor: firstPage.data.nextCursor,
162
+ });
163
+ console.log("next page:", secondPage.data?.results.length ?? 0);
164
+ }
165
+ }
166
+ ```
167
+
168
+ ## Event System (Deprecated)
169
+
170
+ `NeuroInfoApiEventer` is deprecated in favor of `NeuroInfoApiWebsocketClient`.
171
+
172
+ ```ts
173
+ import { NeuroInfoApiEventer } from "@neuroinfoapi-client/bun";
174
+
175
+ const eventer = new NeuroInfoApiEventer();
176
+ eventer.setApiToken("your-api-token-here");
177
+
178
+ eventer.on("streamOnline", (stream) => {
179
+ console.log(`${stream.title} is now live!`);
180
+ });
181
+
182
+ eventer.on(
183
+ "scheduleUpdate",
184
+ (schedule) => console.log(`New schedule for week ${schedule.week}`),
185
+ (error) => console.log(`Failed to fetch schedule: ${error.code}`),
186
+ );
187
+
188
+ // Default: 60s, minimum: 10s
189
+ eventer.fetchInterval = 30000;
190
+ eventer.startEventLoop();
191
+ ```
192
+
193
+ Available events: `streamOnline`, `streamOffline`, `streamUpdate`, `scheduleUpdate`, `subathonUpdate`, `subathonGoalUpdate`
194
+
195
+ ## WebSocket Client
196
+
197
+ `heartbeatMonitoring` defaults to `true` and can also be changed on the client
198
+ instance. Set it to `false` to disable heartbeat timeout monitoring; Native also
199
+ stops its automatic JSON pings. Protocol pong replies and incoming `_pong`
200
+ notifications remain active.
201
+
202
+ Constructor signature:
203
+
204
+ ```ts
205
+ new NeuroInfoApiWebsocketClient(token: string, options?: NeuroInfoApiWebsocketClientOptions)
206
+ ```
207
+
208
+ The options include `apiBaseUrl`, `useTls`, `websocketUrl`, `authMethod`, `autoReconnect`, `maxReconnectAttempts`, `reconnectBaseDelay`, `heartbeatMonitoring`, `heartbeatIntervalMs`, `heartbeatTimeoutMs`, and `connectTimeoutMs`. The legacy WebSocket `baseUrl` option is deprecated; use `websocketUrl` for a full URL override.
209
+
210
+ ```ts
211
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
212
+
213
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
214
+
215
+ wsClient.on("_connected", (sessionId) => {
216
+ console.log("Connected with session:", sessionId);
217
+ });
218
+
219
+ wsClient.on("_eventAdded", (eventType) => {
220
+ console.log("Subscribed:", eventType);
221
+ });
222
+
223
+ wsClient.on("_eventRemoved", (eventType) => {
224
+ console.log("Unsubscribed:", eventType);
225
+ });
226
+
227
+ wsClient.on("streamOnline", (stream) => {
228
+ console.log("Stream online:", stream.title);
229
+ });
230
+
231
+ await wsClient.connect();
232
+ ```
233
+
234
+ Available WebSocket events:
235
+
236
+ - `streamOnline`
237
+ - `streamOffline`
238
+ - `streamUpdate`
239
+ - `secretneuroaccountOnline`
240
+ - `streamRaidIncoming`
241
+ - `streamRaidOutgoing`
242
+ - `scheduleUpdate`
243
+ - `subathonUpdate`
244
+ - `subathonGoalUpdate`
245
+ - `shopProductsUpdate`
246
+ - `blogFeedUpdate`
247
+ - `xFeedNewEntries`
248
+ - `xFeedUpdate` (deprecated alias for `xFeedNewEntries`)
249
+
250
+ **Heartbeat:** The server must send WebSocket protocol ping frames. Bun responds automatically with pong; this package sends no JSON heartbeat messages. The client waits a fixed **90 seconds** for the next server ping; each incoming protocol ping restarts that timer. If the ping is missing, the connection is terminated and automatic reconnect runs when enabled. Disable timeout monitoring with `heartbeatMonitoring: false`. `heartbeatIntervalMs` and `heartbeatTimeoutMs` apply only to Native and are ignored here, both in constructor options and when assigned on the client instance. Automatic protocol pongs remain active when `heartbeatMonitoring: false`. Ticket authentication does not change this heartbeat behavior. The `_pong` event reports heartbeat activity: an incoming server protocol ping that the runtime automatically answers, or an incoming JSON pong. It also fires with `heartbeatMonitoring: false`; that option disables timeout monitoring, not protocol replies or event notifications. This event does not confirm that the server received the reply.
251
+
252
+ ## Unsubscribe and clean up
253
+
254
+ Using the connected `wsClient` from the WebSocket example:
255
+
256
+ ```ts
257
+ const unsubscribe = wsClient.on("streamUpdate", (stream) => {
258
+ console.log("Updated stream:", stream.title);
259
+ });
260
+
261
+ // Later, remove this listener.
262
+ unsubscribe();
263
+
264
+ // Disconnect intentionally; listeners are retained for a later connect().
265
+ wsClient.disconnect();
266
+
267
+ // When finished, remove every listener and disconnect.
268
+ wsClient.destroy();
269
+ ```
270
+
271
+ `connect()` returns a promise that can reject. Handle connection failures with `try`/`catch`, and register an `_error` listener for errors after connecting:
272
+
273
+ ```ts
274
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/bun";
275
+
276
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
277
+ wsClient.on("_error", (error) => console.error("WebSocket error:", error));
278
+
279
+ try {
280
+ await wsClient.connect();
281
+ } catch (error) {
282
+ console.error("Connection failed:", error);
283
+ wsClient.destroy();
284
+ }
285
+ ```
286
+
287
+ ## Documentation
288
+
289
+ - [API documentation](https://neuroinfoapi.dev/api/docs)
290
+
291
+ ## License
292
+
293
+ MIT
package/dist/index.js CHANGED
@@ -15,6 +15,6 @@ export class NeuroInfoApiWebsocketClient extends SharedWebsocketClient {
15
15
  get heartbeatTimeoutMs() { return 30000; }
16
16
  set heartbeatTimeoutMs(_value) { }
17
17
  createWSController(url, headers) {
18
- return new WSController(url, headers);
18
+ return new WSController(url, { "User-Agent": this.userAgent, ...headers });
19
19
  }
20
20
  }
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "name": "@neuroinfoapi-client/bun",
3
- "version": "2.6.0",
4
- "description": "A client for interacting with the NeuroInfoAPI (Bun edition)",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
12
- }
13
- },
14
- "files": [
15
- "dist/*.js",
16
- "dist/*.d.ts",
17
- "README.md",
18
- "LICENSE"
19
- ],
20
- "scripts": {
21
- "build": "tsc -b",
22
- "typecheck": "tsc -p tsconfig.json --noEmit",
23
- "publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package bun",
24
- "deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package bun"
25
- },
26
- "keywords": [
27
- "bun",
28
- "neuroinfoapi",
29
- "nia",
30
- "vedal987",
31
- "neurosama",
32
- "neuro-sama"
33
- ],
34
- "author": "Appstun",
35
- "license": "MIT",
36
- "bugs": {
37
- "url": "https://github.com/NeuroInfoAPI/NPM-Package/issues"
38
- },
39
- "repository": {
40
- "type": "git",
41
- "url": "https://github.com/NeuroInfoAPI/NPM-Package.git",
42
- "directory": "packages/bun"
43
- },
44
- "homepage": "https://neuroinfoapi.dev/api/docs",
45
- "dependencies": {
46
- "@neuroinfoapi-client/core": "2.6.0"
47
- },
48
- "devDependencies": {
49
- "@types/bun": "^1.4.4"
50
- },
51
- "publishConfig": {
52
- "access": "public"
53
- }
54
- }
1
+ {
2
+ "name": "@neuroinfoapi-client/bun",
3
+ "version": "2.7.0",
4
+ "description": "A client for interacting with the NeuroInfoAPI (Bun edition)",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist/*.js",
16
+ "dist/*.d.ts",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "scripts": {
21
+ "build": "tsc -b",
22
+ "typecheck": "tsc -p tsconfig.json --noEmit",
23
+ "publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package bun",
24
+ "deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package bun"
25
+ },
26
+ "keywords": [
27
+ "bun",
28
+ "neuroinfoapi",
29
+ "nia",
30
+ "vedal987",
31
+ "neurosama",
32
+ "neuro-sama"
33
+ ],
34
+ "author": "Appstun",
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/NeuroInfoAPI/NPM-Packages/issues"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/NeuroInfoAPI/NPM-Packages.git",
42
+ "directory": "packages/bun"
43
+ },
44
+ "homepage": "https://neuroinfoapi.dev/api/docs",
45
+ "dependencies": {
46
+ "@neuroinfoapi-client/core": "2.7.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/bun": "^1.4.4"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }