ault-sdk-ts 0.7.1 → 0.7.2
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/README.md +6 -0
- package/dist/core/http.d.ts +8 -0
- package/dist/core/user-agent.d.ts +15 -0
- package/dist/index.cjs +49 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +48 -13
- package/dist/index.js.map +1 -1
- package/dist/ws/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,6 +4,16 @@ var __export = (target, all) => {
|
|
|
4
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
+
// src/core/user-agent.ts
|
|
8
|
+
var SDK_VERSION = "0.7.2";
|
|
9
|
+
var USER_AGENT = `ault-sdk-ts/${SDK_VERSION}`;
|
|
10
|
+
function isServerRuntime() {
|
|
11
|
+
if (typeof document !== "undefined") return false;
|
|
12
|
+
if (typeof globalThis.Deno !== "undefined") return false;
|
|
13
|
+
const versions = globalThis.process?.versions;
|
|
14
|
+
return Boolean(versions?.node || versions?.bun);
|
|
15
|
+
}
|
|
16
|
+
|
|
7
17
|
// src/proto/gen/google/protobuf/duration.ts
|
|
8
18
|
import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
|
|
9
19
|
function createBaseDuration() {
|
|
@@ -207,7 +217,8 @@ var DEFAULT_OPTIONS = {
|
|
|
207
217
|
exponentialBackoff: true,
|
|
208
218
|
retryableMethods: ["GET", "HEAD", "OPTIONS"],
|
|
209
219
|
retryableStatuses: [...DEFAULT_RETRYABLE_STATUSES],
|
|
210
|
-
retryOnTimeout: false
|
|
220
|
+
retryOnTimeout: false,
|
|
221
|
+
userAgent: USER_AGENT
|
|
211
222
|
};
|
|
212
223
|
function ensureFetch(fetchFn) {
|
|
213
224
|
const resolved = fetchFn ?? globalThis.fetch;
|
|
@@ -252,6 +263,21 @@ async function fetchWithTimeout(fetchFn, url, options, timeout) {
|
|
|
252
263
|
removeAbortListener?.();
|
|
253
264
|
}
|
|
254
265
|
}
|
|
266
|
+
function withUserAgent(options, userAgent) {
|
|
267
|
+
if (!isServerRuntime()) return options;
|
|
268
|
+
const entries = [];
|
|
269
|
+
const raw = options.headers;
|
|
270
|
+
if (Array.isArray(raw)) {
|
|
271
|
+
entries.push(...raw.map(([k, v]) => [k, v]));
|
|
272
|
+
} else if (raw && typeof raw.forEach === "function") {
|
|
273
|
+
raw.forEach((value, key) => entries.push([key, value]));
|
|
274
|
+
} else if (raw) {
|
|
275
|
+
entries.push(...Object.entries(raw));
|
|
276
|
+
}
|
|
277
|
+
if (entries.some(([k]) => k.toLowerCase() === "user-agent")) return options;
|
|
278
|
+
entries.push(["user-agent", userAgent]);
|
|
279
|
+
return { ...options, headers: entries };
|
|
280
|
+
}
|
|
255
281
|
function calculateDelay(attempt, baseDelay, exponential) {
|
|
256
282
|
if (exponential) {
|
|
257
283
|
const exponentialDelay = baseDelay * Math.pow(2, attempt);
|
|
@@ -268,11 +294,12 @@ async function fetchWithRetry(url, options = {}, fetchOptions = {}, fetchFn) {
|
|
|
268
294
|
const method = (options.method || "GET").toUpperCase();
|
|
269
295
|
const canRetry = opts.retryableMethods.includes(method);
|
|
270
296
|
const resolvedFetch = ensureFetch(fetchFn);
|
|
297
|
+
const init = withUserAgent(options, opts.userAgent);
|
|
271
298
|
const isAbortError = (error) => error instanceof Error && error.name === "AbortError";
|
|
272
299
|
let lastError = null;
|
|
273
300
|
for (let attempt = 0; attempt <= opts.retries; attempt++) {
|
|
274
301
|
try {
|
|
275
|
-
const response = await fetchWithTimeout(resolvedFetch, url,
|
|
302
|
+
const response = await fetchWithTimeout(resolvedFetch, url, init, opts.timeout);
|
|
276
303
|
if (!response.ok && canRetry && opts.retryableStatuses.includes(response.status) && attempt < opts.retries) {
|
|
277
304
|
const delay = calculateDelay(attempt, opts.retryDelay, opts.exponentialBackoff);
|
|
278
305
|
await sleep(delay);
|
|
@@ -12133,22 +12160,31 @@ function frameMatches(sub, data) {
|
|
|
12133
12160
|
}
|
|
12134
12161
|
}
|
|
12135
12162
|
var isowsModulePromise = null;
|
|
12136
|
-
function wrapCtor(Ctor) {
|
|
12137
|
-
return (url, protocols) =>
|
|
12163
|
+
function wrapCtor(Ctor, userAgent) {
|
|
12164
|
+
return (url, protocols) => {
|
|
12165
|
+
if (protocols !== void 0) return new Ctor(url, protocols);
|
|
12166
|
+
if (isServerRuntime()) {
|
|
12167
|
+
try {
|
|
12168
|
+
return new Ctor(url, { headers: { "User-Agent": userAgent } });
|
|
12169
|
+
} catch {
|
|
12170
|
+
}
|
|
12171
|
+
}
|
|
12172
|
+
return new Ctor(url);
|
|
12173
|
+
};
|
|
12138
12174
|
}
|
|
12139
12175
|
function currentGlobalCtor() {
|
|
12140
12176
|
return typeof globalThis !== "undefined" && typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : null;
|
|
12141
12177
|
}
|
|
12142
|
-
function getDefaultWebSocketFactory() {
|
|
12178
|
+
function getDefaultWebSocketFactory(userAgent) {
|
|
12143
12179
|
const G = currentGlobalCtor();
|
|
12144
|
-
if (G) return wrapCtor(G);
|
|
12180
|
+
if (G) return wrapCtor(G, userAgent);
|
|
12145
12181
|
if (!isowsModulePromise) {
|
|
12146
12182
|
isowsModulePromise = import("isows");
|
|
12147
12183
|
}
|
|
12148
12184
|
return isowsModulePromise.then((mod) => {
|
|
12149
12185
|
const G2 = currentGlobalCtor();
|
|
12150
|
-
if (G2) return wrapCtor(G2);
|
|
12151
|
-
return wrapCtor(mod.WebSocket);
|
|
12186
|
+
if (G2) return wrapCtor(G2, userAgent);
|
|
12187
|
+
return wrapCtor(mod.WebSocket, userAgent);
|
|
12152
12188
|
});
|
|
12153
12189
|
}
|
|
12154
12190
|
var DexWsClient = class {
|
|
@@ -12176,7 +12212,8 @@ var DexWsClient = class {
|
|
|
12176
12212
|
reconnect: opts?.reconnect ?? true,
|
|
12177
12213
|
maxReconnectAttempts: opts?.maxReconnectAttempts ?? Infinity,
|
|
12178
12214
|
reconnectDelay: opts?.reconnectDelay ?? 1e3,
|
|
12179
|
-
maxReconnectDelay: opts?.maxReconnectDelay ?? 3e4
|
|
12215
|
+
maxReconnectDelay: opts?.maxReconnectDelay ?? 3e4,
|
|
12216
|
+
userAgent: opts?.userAgent ?? USER_AGENT
|
|
12180
12217
|
};
|
|
12181
12218
|
this.userFactory = opts?.createWebSocket;
|
|
12182
12219
|
}
|
|
@@ -12394,7 +12431,7 @@ var DexWsClient = class {
|
|
|
12394
12431
|
}
|
|
12395
12432
|
resolveFactory() {
|
|
12396
12433
|
if (this.userFactory) return this.userFactory;
|
|
12397
|
-
return getDefaultWebSocketFactory();
|
|
12434
|
+
return getDefaultWebSocketFactory(this.options.userAgent);
|
|
12398
12435
|
}
|
|
12399
12436
|
handleMessage(raw) {
|
|
12400
12437
|
let msg2;
|
|
@@ -28625,9 +28662,6 @@ var GetUDFTimescaleMarksResponse = zod.array(GetUDFTimescaleMarksResponseItem);
|
|
|
28625
28662
|
function createDexWs(url, options) {
|
|
28626
28663
|
return new DexWsClient(url, options);
|
|
28627
28664
|
}
|
|
28628
|
-
|
|
28629
|
-
// src/index.ts
|
|
28630
|
-
var SDK_VERSION = "0.7.1";
|
|
28631
28665
|
export {
|
|
28632
28666
|
AGENT_DEFAULTS,
|
|
28633
28667
|
AULT_SIGNER_MARKER,
|
|
@@ -28724,6 +28758,7 @@ export {
|
|
|
28724
28758
|
TxError,
|
|
28725
28759
|
TxNotConfirmedError,
|
|
28726
28760
|
TxSimulationError,
|
|
28761
|
+
USER_AGENT,
|
|
28727
28762
|
BondStatus as ValidatorStatus,
|
|
28728
28763
|
WebSocketError,
|
|
28729
28764
|
WithdrawRewardsPartialError,
|