@neuroinfoapi-client/node 0.0.0-stage → 2.6.1

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 ADDED
@@ -0,0 +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.
package/README.md CHANGED
@@ -1,3 +1,288 @@
1
- # Temporary Holding Version
1
+ # @neuroinfoapi-client/node
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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/bun](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/bun/README.md): Bun's native WebSocket, 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
+ - WebSocket in Node.js using the `ws` npm package, 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/node
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```ts
31
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/node";
32
+
33
+ // Optional token can be passed directly in the constructor
34
+ const client = new NeuroInfoApiClient("your-api-token-here");
35
+
36
+ const { data, error } = await client.getCurrentStream();
37
+
38
+ if (error) {
39
+ console.error(`Error ${error.code}: ${error.message}`);
40
+ } else {
41
+ console.log(data);
42
+ }
43
+ ```
44
+
45
+ ## Client Configuration
46
+
47
+ Constructor signature:
48
+
49
+ ```ts
50
+ new NeuroInfoApiClient(token?: string, options?: NeuroInfoApiClientOptions)
51
+ ```
52
+
53
+ `NeuroInfoApiClientOptions` supports:
54
+
55
+ | Option | Default | Description |
56
+ | ------------------ | ------------------------- | ---------------------------------------- |
57
+ | `apiBaseUrl` | `neuroinfoapi.dev/api/v2` | API host and path without a protocol |
58
+ | `useTls` | `true` | Use HTTPS when `true`, HTTP when `false` |
59
+ | `requestTimeoutMs` | `10000` | HTTP request timeout in milliseconds |
60
+
61
+ The legacy `baseUrl` option is deprecated and will be removed in a future major version.
62
+
63
+ Examples:
64
+
65
+ ```ts
66
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/node";
67
+
68
+ // 1) No token in constructor (set later)
69
+ const clientA = new NeuroInfoApiClient();
70
+ clientA.setApiToken("your-api-token-here");
71
+
72
+ // 2) Token in constructor
73
+ const clientB = new NeuroInfoApiClient("your-api-token-here");
74
+
75
+ // 3) for testing with Mock-TesServer (https://github.com/NeuroInfoAPI/Mock-TestServer)
76
+ const clientC = new NeuroInfoApiClient(undefined, {
77
+ apiBaseUrl: "localhost:8787/api/v2",
78
+ useTls: false,
79
+ requestTimeoutMs: 15000,
80
+ });
81
+ ```
82
+
83
+ ## Node.js Usage
84
+
85
+ ```ts
86
+ import { NeuroInfoApiClient, NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/node";
87
+
88
+ const client = new NeuroInfoApiClient();
89
+ client.setApiToken("your-api-token-here");
90
+
91
+ // Sends Authorization: Bearer during the handshake by default
92
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
93
+ await wsClient.connect();
94
+ ```
95
+
96
+ This package defaults to `authMethod: "header"` in Node.js. Set `authMethod: "ticket"` to obtain a one-time ticket through HTTP before connecting. For browser usage, use `@neuroinfoapi-client/native`.
97
+
98
+ ## Error Handling
99
+
100
+ All HTTP API request methods return a result object with either `data` or `error`:
101
+
102
+ ```ts
103
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/node";
104
+
105
+ const client = new NeuroInfoApiClient("your-api-token-here");
106
+ const { data, error } = await client.getCurrentStream();
107
+
108
+ if (error) {
109
+ // error is NeuroApiError with code, message, and optional status
110
+ console.log(`Error ${error.code}: ${error.message}`);
111
+ } else if (data.isLive) {
112
+ console.log(data.title);
113
+ } else {
114
+ console.log("Stream is offline");
115
+ }
116
+ ```
117
+
118
+ ## HTTP API Methods
119
+
120
+ All methods below return `Promise<ApiResult<T>>`:
121
+
122
+ - `getCurrentStream()` — current Twitch stream state
123
+ - `getAllVods()` — all Twitch VODs
124
+ - `getVod(id)` — a VOD by stream ID
125
+ - `getSchedule(week, year?)` — schedule for a specific week and optional year
126
+ - `getLatestSchedule()` — latest schedule
127
+ - `getScheduleWeeks()` — available schedule weeks grouped by year
128
+ - `getDevstreamTimes()` — devstream schedule timestamps
129
+ - `getScheduleSearch(query, options?)` — search schedules with filters and cursor pagination
130
+ - `getCurrentSubathons()` — currently active subathons
131
+ - `getSubathon(year)` — subathon data for a year
132
+ - `getSubathonYears()` — available subathon years
133
+ - `getBlogFeed(raw?)` — Neuro-sama blog feed; requires an API token
134
+ - `getXFeed(user)` — cached X feed for `NeurosamaAI`, `EvilNeuroAI`, or `Vedal987`; requires an API token
135
+
136
+ ## Schedule Search Pagination
137
+
138
+ Use `getScheduleSearch` and continue with `nextCursor`.
139
+ Optional filter: `type` (`normal`, `offline`, `canceled`, `TBD`, `unknown`).
140
+
141
+ `/schedule/search` has rate limits (`6 requests/minute` and `2 requests/10 seconds` per token), so avoid tight loops.
142
+
143
+ ```ts
144
+ import { NeuroInfoApiClient } from "@neuroinfoapi-client/node";
145
+
146
+ const client = new NeuroInfoApiClient("your-api-token-here");
147
+ const firstPage = await client.getScheduleSearch("karaoke", { limit: 5, sort: "desc", type: "normal" });
148
+ if (firstPage.error) {
149
+ console.error(firstPage.error.code, firstPage.error.message);
150
+ } else {
151
+ console.log("matches:", firstPage.data.results.length);
152
+
153
+ if (firstPage.data.nextCursor) {
154
+ const secondPage = await client.getScheduleSearch("karaoke", {
155
+ limit: 5,
156
+ sort: "desc",
157
+ cursor: firstPage.data.nextCursor,
158
+ });
159
+ console.log("next page:", secondPage.data?.results.length ?? 0);
160
+ }
161
+ }
162
+ ```
163
+
164
+ ## Event System (Deprecated)
165
+
166
+ `NeuroInfoApiEventer` is deprecated in favor of `NeuroInfoApiWebsocketClient`.
167
+
168
+ ```ts
169
+ import { NeuroInfoApiEventer } from "@neuroinfoapi-client/node";
170
+
171
+ const eventer = new NeuroInfoApiEventer();
172
+ eventer.setApiToken("your-api-token-here");
173
+
174
+ eventer.on("streamOnline", (stream) => {
175
+ console.log(`${stream.title} is now live!`);
176
+ });
177
+
178
+ eventer.on(
179
+ "scheduleUpdate",
180
+ (schedule) => console.log(`New schedule for week ${schedule.week}`),
181
+ (error) => console.log(`Failed to fetch schedule: ${error.code}`),
182
+ );
183
+
184
+ // Default: 60s, minimum: 10s
185
+ eventer.fetchInterval = 30000;
186
+ eventer.startEventLoop();
187
+ ```
188
+
189
+ Available events: `streamOnline`, `streamOffline`, `streamUpdate`, `scheduleUpdate`, `subathonUpdate`, `subathonGoalUpdate`
190
+
191
+ ## WebSocket Client
192
+
193
+ `heartbeatMonitoring` defaults to `true` and can also be changed on the client
194
+ instance. Set it to `false` to disable heartbeat timeout monitoring; Native also
195
+ stops its automatic JSON pings. Protocol pong replies and incoming `_pong`
196
+ notifications remain active.
197
+
198
+ Constructor signature:
199
+
200
+ ```ts
201
+ new NeuroInfoApiWebsocketClient(token: string, options?: NeuroInfoApiWebsocketClientOptions)
202
+ ```
203
+
204
+ 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.
205
+
206
+ ```ts
207
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/node";
208
+
209
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
210
+
211
+ wsClient.on("_connected", (sessionId) => {
212
+ console.log("Connected with session:", sessionId);
213
+ });
214
+
215
+ wsClient.on("_eventAdded", (eventType) => {
216
+ console.log("Subscribed:", eventType);
217
+ });
218
+
219
+ wsClient.on("_eventRemoved", (eventType) => {
220
+ console.log("Unsubscribed:", eventType);
221
+ });
222
+
223
+ wsClient.on("streamOnline", (stream) => {
224
+ console.log("Stream online:", stream.title);
225
+ });
226
+
227
+ await wsClient.connect();
228
+ ```
229
+
230
+ Available WebSocket events:
231
+
232
+ - `streamOnline`
233
+ - `streamOffline`
234
+ - `streamUpdate`
235
+ - `secretneuroaccountOnline`
236
+ - `streamRaidIncoming`
237
+ - `streamRaidOutgoing`
238
+ - `scheduleUpdate`
239
+ - `subathonUpdate`
240
+ - `subathonGoalUpdate`
241
+ - `blogFeedUpdate`
242
+ - `xFeedNewEntries`
243
+ - `xFeedUpdate` (deprecated alias for `xFeedNewEntries`)
244
+
245
+ **Heartbeat:** The server must send WebSocket protocol ping frames. `ws` 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.
246
+
247
+ ## Unsubscribe and clean up
248
+
249
+ Using the connected `wsClient` from the WebSocket example:
250
+
251
+ ```ts
252
+ const unsubscribe = wsClient.on("streamUpdate", (stream) => {
253
+ console.log("Updated stream:", stream.title);
254
+ });
255
+
256
+ // Later, remove this listener.
257
+ unsubscribe();
258
+
259
+ // Disconnect intentionally; listeners are retained for a later connect().
260
+ wsClient.disconnect();
261
+
262
+ // When finished, remove every listener and disconnect.
263
+ wsClient.destroy();
264
+ ```
265
+
266
+ `connect()` returns a promise that can reject. Handle connection failures with `try`/`catch`, and register an `_error` listener for errors after connecting:
267
+
268
+ ```ts
269
+ import { NeuroInfoApiWebsocketClient } from "@neuroinfoapi-client/node";
270
+
271
+ const wsClient = new NeuroInfoApiWebsocketClient("your-api-token-here");
272
+ wsClient.on("_error", (error) => console.error("WebSocket error:", error));
273
+
274
+ try {
275
+ await wsClient.connect();
276
+ } catch (error) {
277
+ console.error("Connection failed:", error);
278
+ wsClient.destroy();
279
+ }
280
+ ```
281
+
282
+ ## Documentation
283
+
284
+ - [API documentation](https://neuroinfoapi.dev/api/docs)
285
+
286
+ ## License
287
+
288
+ MIT
@@ -0,0 +1,13 @@
1
+ import type { WSController as SharedWSController } from "@neuroinfoapi-client/core";
2
+ export declare class WSController implements SharedWSController {
3
+ readonly heartbeatMode = "server-ping";
4
+ onPing: (() => void) | null;
5
+ private readonly socket;
6
+ constructor(url: string, headers?: Record<string, string>);
7
+ get readyState(): SharedWSController["readyState"];
8
+ send(data: Parameters<SharedWSController["send"]>[0]): void;
9
+ close(code?: number, reason?: string): void;
10
+ terminate(_code: number, _reason: string): void;
11
+ addEventListener: SharedWSController["addEventListener"];
12
+ removeEventListener: SharedWSController["removeEventListener"];
13
+ }
@@ -0,0 +1,24 @@
1
+ import WebSocket from "ws";
2
+ export class WSController {
3
+ constructor(url, headers) {
4
+ this.heartbeatMode = "server-ping";
5
+ this.onPing = null;
6
+ // ws's EventTarget adapter converts text frames and close reasons to strings
7
+ // and preserves listener identities (including once and handleEvent objects).
8
+ this.addEventListener = (type, listener, options) => {
9
+ this.socket.addEventListener(type, listener, options);
10
+ };
11
+ this.removeEventListener = (type, listener) => {
12
+ this.socket.removeEventListener(type, listener);
13
+ };
14
+ this.socket = new WebSocket(url, { headers });
15
+ // ws automatically answers protocol pings with matching pong frames.
16
+ this.socket.on("ping", () => this.onPing?.());
17
+ // An aborted handshake can emit error after the shared client removes listeners.
18
+ this.socket.on("error", () => { });
19
+ }
20
+ get readyState() { return this.socket.readyState; }
21
+ send(data) { this.socket.send(data); }
22
+ close(code, reason) { this.socket.close(code, reason); }
23
+ terminate(_code, _reason) { this.socket.terminate(); }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { NeuroInfoApiWebsocketClient as SharedWebsocketClient } from "@neuroinfoapi-client/core";
2
+ import type { WSController as SharedWSController, NeuroInfoApiWebsocketClientOptions } from "@neuroinfoapi-client/core";
3
+ export * from "@neuroinfoapi-client/core";
4
+ export declare class NeuroInfoApiWebsocketClient extends SharedWebsocketClient {
5
+ constructor(token: string, options?: NeuroInfoApiWebsocketClientOptions);
6
+ /** Native-only timing option. Ignored here; server-ping monitoring uses a fixed 90-second timeout. */
7
+ get heartbeatIntervalMs(): number;
8
+ set heartbeatIntervalMs(_value: number);
9
+ /** Native-only timing option. Ignored here, including assignments after connecting. */
10
+ get heartbeatTimeoutMs(): number;
11
+ set heartbeatTimeoutMs(_value: number);
12
+ protected createWSController(url: string, headers?: Record<string, string>): SharedWSController;
13
+ }
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import { NeuroInfoApiWebsocketClient as SharedWebsocketClient } from "@neuroinfoapi-client/core";
2
+ import { WSController } from "./WSController.js";
3
+ export * from "@neuroinfoapi-client/core";
4
+ export class NeuroInfoApiWebsocketClient extends SharedWebsocketClient {
5
+ constructor(token, options = {}) {
6
+ super(token, {
7
+ ...options,
8
+ authMethod: options.authMethod ?? "header",
9
+ });
10
+ }
11
+ /** Native-only timing option. Ignored here; server-ping monitoring uses a fixed 90-second timeout. */
12
+ get heartbeatIntervalMs() { return 60000; }
13
+ set heartbeatIntervalMs(_value) { }
14
+ /** Native-only timing option. Ignored here, including assignments after connecting. */
15
+ get heartbeatTimeoutMs() { return 30000; }
16
+ set heartbeatTimeoutMs(_value) { }
17
+ createWSController(url, headers) {
18
+ return new WSController(url, { "User-Agent": this.userAgent, ...headers });
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,56 @@
1
1
  {
2
2
  "name": "@neuroinfoapi-client/node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.6.1",
4
+ "description": "A client for interacting with the NeuroInfoAPI (Node.js 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 node",
24
+ "deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package node"
25
+ },
26
+ "keywords": [
27
+ "node",
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/node"
43
+ },
44
+ "homepage": "https://neuroinfoapi.dev/api/docs",
45
+ "dependencies": {
46
+ "@neuroinfoapi-client/core": "2.6.1",
47
+ "ws": "^8.22.1"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^26.6.6",
51
+ "@types/ws": "^8.18.2"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }