@neuroinfoapi-client/core 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 +19 -19
- package/dist/NeuroInfoAPI-Client.d.ts +67 -0
- package/dist/NeuroInfoAPI-Client.js +10 -2
- package/package.json +40 -40
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,19 +1,19 @@
|
|
|
1
|
-
# @neuroinfoapi-client/core
|
|
2
|
-
|
|
3
|
-
Shared HTTP client, API types, utilities and WebSocket protocol logic for NeuroInfoAPI.
|
|
4
|
-
Core has no WebSocket runtime dependency.
|
|
5
|
-
|
|
6
|
-
**You can use this for HTTP only, but please consider using the other packages.**
|
|
7
|
-
|
|
8
|
-
- [@neuroinfoapi-client/native](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/native/README.md): standard WebSocket in browsers and Node.js; ticket auth and JSON heartbeat.
|
|
9
|
-
- [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with `ws`; header auth and protocol heartbeat.
|
|
10
|
-
- [@neuroinfoapi-client/bun](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/bun/README.md): Bun's native WebSocket; header auth and protocol heartbeat.
|
|
11
|
-
|
|
12
|
-
## Documentation
|
|
13
|
-
|
|
14
|
-
- [Clients Repositories](https://github.com/NeuroInfoAPI/NPM-Package/tree/master/packages)
|
|
15
|
-
- [API documentation](https://neuroinfoapi.dev/api/docs)
|
|
16
|
-
|
|
17
|
-
## License
|
|
18
|
-
|
|
19
|
-
MIT
|
|
1
|
+
# @neuroinfoapi-client/core
|
|
2
|
+
|
|
3
|
+
Shared HTTP client, API types, utilities and WebSocket protocol logic for NeuroInfoAPI.
|
|
4
|
+
Core has no WebSocket runtime dependency.
|
|
5
|
+
|
|
6
|
+
**You can use this for HTTP only, but please consider using the other packages.**
|
|
7
|
+
|
|
8
|
+
- [@neuroinfoapi-client/native](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/native/README.md): standard WebSocket in browsers and Node.js; ticket auth and JSON heartbeat.
|
|
9
|
+
- [@neuroinfoapi-client/node](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/node/README.md): Node.js with `ws`; header auth and protocol heartbeat.
|
|
10
|
+
- [@neuroinfoapi-client/bun](https://github.com/NeuroInfoAPI/NPM-Package/blob/master/packages/bun/README.md): Bun's native WebSocket; header auth and protocol heartbeat.
|
|
11
|
+
|
|
12
|
+
## Documentation
|
|
13
|
+
|
|
14
|
+
- [Clients Repositories](https://github.com/NeuroInfoAPI/NPM-Package/tree/master/packages)
|
|
15
|
+
- [API documentation](https://neuroinfoapi.dev/api/docs)
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
MIT
|
|
@@ -137,6 +137,10 @@ export declare class NeuroInfoApiClient {
|
|
|
137
137
|
* @docs https://github.com/Appstun/NeuroInfoAPI-Docs/blob/master/x-feed.md#endpoint
|
|
138
138
|
*/
|
|
139
139
|
getXFeed: (user: XFeedAccount) => Promise<ApiResult<XFeedEntry[]>>;
|
|
140
|
+
/** Fetches the full shop catalog. Requires an API token. Prices optionally use the requested currency. */
|
|
141
|
+
getShopProducts: (currency?: string) => Promise<ApiResult<ShopProduct[]>>;
|
|
142
|
+
/** Fetches a shop product by ID. Requires an API token. Price currencyCode identifies the returned currency. */
|
|
143
|
+
getShopProduct: (id: string, currency?: string) => Promise<ApiResult<ShopProduct>>;
|
|
140
144
|
}
|
|
141
145
|
/**
|
|
142
146
|
* Event-based wrapper for the NeuroInfo API.
|
|
@@ -209,6 +213,7 @@ export declare class NeuroInfoApiEventer {
|
|
|
209
213
|
* REST API before connecting, so the token is never exposed in URL query parameters.
|
|
210
214
|
*/
|
|
211
215
|
export declare abstract class NeuroInfoApiWebsocketClient {
|
|
216
|
+
protected readonly userAgent = "niac_js@{*gets set when build*}";
|
|
212
217
|
protected abstract createWSController(url: string, headers?: Record<string, string>): WSController;
|
|
213
218
|
private connection;
|
|
214
219
|
private readonly auth;
|
|
@@ -484,8 +489,70 @@ export interface WsSubathonGoalUpdateData {
|
|
|
484
489
|
goal: SubathonGoal;
|
|
485
490
|
subcount: number;
|
|
486
491
|
}
|
|
492
|
+
export interface ShopImage {
|
|
493
|
+
url: string;
|
|
494
|
+
altText: string | null;
|
|
495
|
+
width: number;
|
|
496
|
+
height: number;
|
|
497
|
+
}
|
|
498
|
+
export interface ShopMoney {
|
|
499
|
+
amount: string;
|
|
500
|
+
currencyCode: string;
|
|
501
|
+
}
|
|
502
|
+
export interface ShopProduct {
|
|
503
|
+
id: string;
|
|
504
|
+
title: string;
|
|
505
|
+
handle: string;
|
|
506
|
+
url: string;
|
|
507
|
+
description: string;
|
|
508
|
+
descriptionHtml: string;
|
|
509
|
+
vendor: string;
|
|
510
|
+
productType: string;
|
|
511
|
+
tags: string[];
|
|
512
|
+
availableForSale: boolean;
|
|
513
|
+
createdAt: number;
|
|
514
|
+
updatedAt: number;
|
|
515
|
+
publishedAt: number;
|
|
516
|
+
seo: {
|
|
517
|
+
title: string | null;
|
|
518
|
+
description: string | null;
|
|
519
|
+
};
|
|
520
|
+
options: {
|
|
521
|
+
name: string;
|
|
522
|
+
values: string[];
|
|
523
|
+
}[];
|
|
524
|
+
images: ShopImage[];
|
|
525
|
+
variants: {
|
|
526
|
+
id: string;
|
|
527
|
+
title: string;
|
|
528
|
+
sku: string | null;
|
|
529
|
+
availableForSale: boolean;
|
|
530
|
+
price: ShopMoney;
|
|
531
|
+
compareAtPrice: ShopMoney | null;
|
|
532
|
+
selectedOptions: {
|
|
533
|
+
name: string;
|
|
534
|
+
value: string;
|
|
535
|
+
}[];
|
|
536
|
+
image: ShopImage | null;
|
|
537
|
+
}[];
|
|
538
|
+
collections: {
|
|
539
|
+
id: string;
|
|
540
|
+
title: string;
|
|
541
|
+
}[];
|
|
542
|
+
metafields: {
|
|
543
|
+
namespace: string;
|
|
544
|
+
key: string;
|
|
545
|
+
type: string;
|
|
546
|
+
value: string;
|
|
547
|
+
reference: Record<string, unknown> | null;
|
|
548
|
+
}[];
|
|
549
|
+
}
|
|
550
|
+
export interface ShopProductsUpdateData {
|
|
551
|
+
products: ShopProduct[];
|
|
552
|
+
}
|
|
487
553
|
/** Mapping of event types to their data structures. */
|
|
488
554
|
export interface WsEventDataMap {
|
|
555
|
+
shopProductsUpdate: ShopProductsUpdateData;
|
|
489
556
|
blogFeedUpdate: BlogFeedData;
|
|
490
557
|
xFeedNewEntries: XFeedNewEntriesData;
|
|
491
558
|
/** @deprecated Subscribe to xFeedNewEntries instead. */
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const apiVersion = "v2";
|
|
2
|
+
const clientVersion = "2.7.0";
|
|
3
|
+
const userAgent = `niac_js@${clientVersion}`;
|
|
2
4
|
const defaultApiBaseUrl = `neuroinfoapi.dev/api/${apiVersion}`;
|
|
3
5
|
function invokeSafely(callback, ...args) {
|
|
4
6
|
try {
|
|
@@ -43,7 +45,7 @@ async function bootCheck(baseUrlOrApiBase, clientApiVer = apiVersion) {
|
|
|
43
45
|
bootCheckFired = true;
|
|
44
46
|
try {
|
|
45
47
|
const infoUrl = `${baseUrlOrApiBase.replace(/\/api\/v\d+.*$/, "/api")}/info`;
|
|
46
|
-
const resp = await fetch(infoUrl);
|
|
48
|
+
const resp = await fetch(infoUrl, { headers: { "User-Agent": userAgent } });
|
|
47
49
|
if (!resp.ok)
|
|
48
50
|
return;
|
|
49
51
|
const json = await resp.json();
|
|
@@ -85,7 +87,7 @@ export class HttpRequestError extends Error {
|
|
|
85
87
|
export class HttpClient {
|
|
86
88
|
constructor(options = {}) {
|
|
87
89
|
const timeout = options.timeout == null || !Number.isFinite(options.timeout) || options.timeout < 0 ? 10000 : options.timeout;
|
|
88
|
-
this.config = { baseURL: options.baseURL ?? "", timeout, headers: options.headers
|
|
90
|
+
this.config = { baseURL: options.baseURL ?? "", timeout, headers: { "User-Agent": userAgent, ...options.headers } };
|
|
89
91
|
}
|
|
90
92
|
/** @deprecated Use `new HttpClient(options)` instead. */
|
|
91
93
|
static create(options = {}) {
|
|
@@ -251,6 +253,10 @@ export class NeuroInfoApiClient {
|
|
|
251
253
|
* @docs https://github.com/Appstun/NeuroInfoAPI-Docs/blob/master/x-feed.md#endpoint
|
|
252
254
|
*/
|
|
253
255
|
this.getXFeed = (user) => this.request("/x-feed", { user });
|
|
256
|
+
/** Fetches the full shop catalog. Requires an API token. Prices optionally use the requested currency. */
|
|
257
|
+
this.getShopProducts = (currency) => this.request("/shop/products", currency === undefined ? undefined : { currency });
|
|
258
|
+
/** Fetches a shop product by ID. Requires an API token. Price currencyCode identifies the returned currency. */
|
|
259
|
+
this.getShopProduct = (id, currency) => this.request("/shop/product", { id, ...(currency === undefined ? {} : { currency }) });
|
|
254
260
|
const apiUrl = options.apiBaseUrl != null ? createClientUrls(options.apiBaseUrl, options.useTls).api : (options.baseUrl ?? createClientUrls().api);
|
|
255
261
|
this.apiInstance = new HttpClient({
|
|
256
262
|
baseURL: apiUrl,
|
|
@@ -642,6 +648,7 @@ export class NeuroInfoApiWebsocketClient {
|
|
|
642
648
|
* @param options - Optional configuration options
|
|
643
649
|
*/
|
|
644
650
|
constructor(token, options = {}) {
|
|
651
|
+
this.userAgent = userAgent;
|
|
645
652
|
this.connection = null;
|
|
646
653
|
this.listeners = { events: new Map(), system: new Map() };
|
|
647
654
|
this.reconnect = { attempts: 0, timeout: null };
|
|
@@ -1236,6 +1243,7 @@ export var Utils;
|
|
|
1236
1243
|
Utils.hasScheduleImage = hasScheduleImage;
|
|
1237
1244
|
})(Utils || (Utils = {}));
|
|
1238
1245
|
const wsEventTypes = new Set([
|
|
1246
|
+
"shopProductsUpdate",
|
|
1239
1247
|
"blogFeedUpdate",
|
|
1240
1248
|
"xFeedNewEntries",
|
|
1241
1249
|
"xFeedUpdate",
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@neuroinfoapi-client/core",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Shared HTTP client, types and WebSocket protocol logic for NeuroInfoAPI-Client (Bun, Node.js, Native)",
|
|
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 core",
|
|
24
|
-
"deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package core"
|
|
25
|
-
},
|
|
26
|
-
"publishConfig": {
|
|
27
|
-
"access": "public"
|
|
28
|
-
},
|
|
29
|
-
"author": "Appstun",
|
|
30
|
-
"license": "MIT",
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "https://github.com/NeuroInfoAPI/NPM-
|
|
34
|
-
"directory": "packages/core"
|
|
35
|
-
},
|
|
36
|
-
"bugs": {
|
|
37
|
-
"url": "https://github.com/NeuroInfoAPI/NPM-
|
|
38
|
-
},
|
|
39
|
-
"homepage": "https://neuroinfoapi.dev/api/docs"
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@neuroinfoapi-client/core",
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "Shared HTTP client, types and WebSocket protocol logic for NeuroInfoAPI-Client (Bun, Node.js, Native)",
|
|
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 && node ../../scripts/helpers/setClientVersion.mjs",
|
|
22
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
|
+
"publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package core",
|
|
24
|
+
"deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package core"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"author": "Appstun",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/NeuroInfoAPI/NPM-Packages.git",
|
|
34
|
+
"directory": "packages/core"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/NeuroInfoAPI/NPM-Packages/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://neuroinfoapi.dev/api/docs"
|
|
40
|
+
}
|