@neuroinfoapi-client/core 2.6.0 → 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.
|
@@ -209,6 +209,7 @@ export declare class NeuroInfoApiEventer {
|
|
|
209
209
|
* REST API before connecting, so the token is never exposed in URL query parameters.
|
|
210
210
|
*/
|
|
211
211
|
export declare abstract class NeuroInfoApiWebsocketClient {
|
|
212
|
+
protected readonly userAgent = "niac_js@{*gets set when build*}";
|
|
212
213
|
protected abstract createWSController(url: string, headers?: Record<string, string>): WSController;
|
|
213
214
|
private connection;
|
|
214
215
|
private readonly auth;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const apiVersion = "v2";
|
|
2
|
+
const clientVersion = "2.6.1";
|
|
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 = {}) {
|
|
@@ -642,6 +644,7 @@ export class NeuroInfoApiWebsocketClient {
|
|
|
642
644
|
* @param options - Optional configuration options
|
|
643
645
|
*/
|
|
644
646
|
constructor(token, options = {}) {
|
|
647
|
+
this.userAgent = userAgent;
|
|
645
648
|
this.connection = null;
|
|
646
649
|
this.listeners = { events: new Map(), system: new Map() };
|
|
647
650
|
this.reconnect = { attempts: 0, timeout: null };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuroinfoapi-client/core",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "Shared HTTP client, types and WebSocket protocol logic for NeuroInfoAPI-Client (Bun, Node.js, Native)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"LICENSE"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"build": "tsc -b",
|
|
21
|
+
"build": "tsc -b && node ../../scripts/helpers/setClientVersion.mjs",
|
|
22
22
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
23
|
"publishPackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/publishAsk.ps1 -Package core",
|
|
24
24
|
"deprecatePackage": "powershell -NoProfile -ExecutionPolicy Bypass -File ../../scripts/deprecateAsk.ps1 -Package core"
|