@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.
- package/LICENSE +21 -21
- package/README.md +293 -290
- package/dist/index.js +1 -1
- 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
|
-
- `
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
console.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
eventer.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
wsClient
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
- `
|
|
237
|
-
- `
|
|
238
|
-
- `
|
|
239
|
-
- `
|
|
240
|
-
- `
|
|
241
|
-
- `
|
|
242
|
-
- `
|
|
243
|
-
- `
|
|
244
|
-
- `
|
|
245
|
-
- `
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
//
|
|
265
|
-
wsClient.
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
wsClient.
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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.
|
|
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-
|
|
38
|
-
},
|
|
39
|
-
"repository": {
|
|
40
|
-
"type": "git",
|
|
41
|
-
"url": "https://github.com/NeuroInfoAPI/NPM-
|
|
42
|
-
"directory": "packages/bun"
|
|
43
|
-
},
|
|
44
|
-
"homepage": "https://neuroinfoapi.dev/api/docs",
|
|
45
|
-
"dependencies": {
|
|
46
|
-
"@neuroinfoapi-client/core": "2.
|
|
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
|
+
}
|