cabalspy-id 0.5.1 → 0.5.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/CHANGELOG.md +146 -112
- package/LICENSE +21 -21
- package/README.md +505 -475
- package/dist/api.cjs +5 -3
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.js +16 -14
- package/dist/chunk-A2ZAFAWC.cjs.map +1 -1
- package/dist/chunk-ABFIPCBY.cjs +109 -0
- package/dist/chunk-ABFIPCBY.cjs.map +1 -0
- package/dist/{chunk-Z3UPDOBY.js → chunk-DBYCRBVS.js} +9 -7
- package/dist/chunk-DBYCRBVS.js.map +1 -0
- package/dist/{chunk-P3MDLWLN.cjs → chunk-PKFIMBPW.cjs} +113 -54
- package/dist/chunk-PKFIMBPW.cjs.map +1 -0
- package/dist/{chunk-L4RHSWOA.cjs → chunk-ULEBNY2A.cjs} +121 -212
- package/dist/chunk-ULEBNY2A.cjs.map +1 -0
- package/dist/{chunk-X3OFGGSE.cjs → chunk-VDFCMYLR.cjs} +50 -48
- package/dist/chunk-VDFCMYLR.cjs.map +1 -0
- package/dist/chunk-VOTYIQAY.js +109 -0
- package/dist/chunk-VOTYIQAY.js.map +1 -0
- package/dist/{chunk-3LKLY5WQ.js → chunk-XLBO2RSL.js} +15 -106
- package/dist/chunk-XLBO2RSL.js.map +1 -0
- package/dist/{chunk-3P7QK2PG.js → chunk-Z23B5TY6.js} +89 -30
- package/dist/chunk-Z23B5TY6.js.map +1 -0
- package/dist/index.cjs +13 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +25 -17
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +55 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +28 -5
- package/dist/react.d.ts +28 -5
- package/dist/react.js +55 -2
- package/dist/react.js.map +1 -1
- package/dist/thesis.cjs +11 -3
- package/dist/thesis.cjs.map +1 -1
- package/dist/thesis.d.cts +42 -11
- package/dist/thesis.d.ts +42 -11
- package/dist/thesis.js +24 -16
- package/dist/{users-BDLkwW1p.d.cts → users-3DAw88_U.d.cts} +4 -4
- package/dist/{users-CDlDRuyv.d.ts → users-B4r33i4O.d.ts} +4 -4
- package/dist/widget.cjs +28 -12
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.d.cts +37 -6
- package/dist/widget.d.ts +37 -6
- package/dist/widget.js +17 -1
- package/dist/widget.js.map +1 -1
- package/package.json +147 -147
- package/dist/chunk-3LKLY5WQ.js.map +0 -1
- package/dist/chunk-3P7QK2PG.js.map +0 -1
- package/dist/chunk-L4RHSWOA.cjs.map +0 -1
- package/dist/chunk-P3MDLWLN.cjs.map +0 -1
- package/dist/chunk-X3OFGGSE.cjs.map +0 -1
- package/dist/chunk-Z3UPDOBY.js.map +0 -1
|
@@ -1,92 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = new.target.name;
|
|
16
|
-
this.status = _nullishCoalesce(opts.status, () => ( 0));
|
|
17
|
-
this.code = _nullishCoalesce(opts.code, () => ( "unknown_error"));
|
|
18
|
-
this.requestId = opts.requestId;
|
|
19
|
-
this.docs = opts.docs;
|
|
20
|
-
this.parameter = opts.parameter;
|
|
21
|
-
this.allowed = opts.allowed;
|
|
22
|
-
this.rateLimit = _nullishCoalesce(opts.rateLimit, () => ( { ...EMPTY_RATE_LIMIT }));
|
|
23
|
-
this.body = opts.body;
|
|
24
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var BadRequestError = class extends CabalSpyIDError {
|
|
28
|
-
};
|
|
29
|
-
var AuthenticationError = class extends CabalSpyIDError {
|
|
30
|
-
};
|
|
31
|
-
var PermissionError = class extends CabalSpyIDError {
|
|
32
|
-
};
|
|
33
|
-
var PlanUserLimitError = (_class = class extends PermissionError {constructor(...args) { super(...args); _class.prototype.__init.call(this); }
|
|
34
|
-
__init() {this.limited = true}
|
|
35
|
-
}, _class);
|
|
36
|
-
var NotFoundError = class extends CabalSpyIDError {
|
|
37
|
-
};
|
|
38
|
-
var RateLimitError = class extends CabalSpyIDError {
|
|
39
|
-
/** Seconds until the next request is allowed, taken from Retry-After. */
|
|
40
|
-
|
|
41
|
-
constructor(message, opts = {}) {
|
|
42
|
-
super(message, opts);
|
|
43
|
-
this.retryAfter = _nullishCoalesce(opts.retryAfter, () => ( null));
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var ServerError = class extends CabalSpyIDError {
|
|
47
|
-
};
|
|
48
|
-
var ConnectionError = class extends CabalSpyIDError {
|
|
49
|
-
};
|
|
50
|
-
var InvalidResponseError = class extends CabalSpyIDError {
|
|
51
|
-
};
|
|
52
|
-
var OAuthError = class extends CabalSpyIDError {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
constructor(error, description, opts = {}) {
|
|
56
|
-
super(description ? `${error}: ${description}` : error, { ...opts, code: error });
|
|
57
|
-
this.error = error;
|
|
58
|
-
this.errorDescription = description;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var TokenVerificationError = class extends CabalSpyIDError {
|
|
62
|
-
};
|
|
63
|
-
var WebhookVerificationError = class extends CabalSpyIDError {
|
|
64
|
-
};
|
|
65
|
-
function errorFromStatus(status, body, rateLimit, retryAfter, fallbackMessage) {
|
|
66
|
-
const opts = {
|
|
67
|
-
status,
|
|
68
|
-
code: _nullishCoalesce(_optionalChain([body, 'optionalAccess', _ => _.code]), () => ( `http_${status}`)),
|
|
69
|
-
requestId: _optionalChain([body, 'optionalAccess', _2 => _2.request_id]),
|
|
70
|
-
docs: _optionalChain([body, 'optionalAccess', _3 => _3.docs]),
|
|
71
|
-
parameter: _optionalChain([body, 'optionalAccess', _4 => _4.parameter]),
|
|
72
|
-
allowed: _optionalChain([body, 'optionalAccess', _5 => _5.allowed]),
|
|
73
|
-
rateLimit,
|
|
74
|
-
body: _nullishCoalesce(body, () => ( void 0))
|
|
75
|
-
};
|
|
76
|
-
const msg = _nullishCoalesce(_optionalChain([body, 'optionalAccess', _6 => _6.message]), () => ( fallbackMessage));
|
|
77
|
-
if (status === 400) return new BadRequestError(msg, opts);
|
|
78
|
-
if (status === 401) return new AuthenticationError(msg, opts);
|
|
79
|
-
if (status === 403) {
|
|
80
|
-
return _optionalChain([body, 'optionalAccess', _7 => _7.code]) === "plan_user_limit" ? new PlanUserLimitError(msg, opts) : new PermissionError(msg, opts);
|
|
81
|
-
}
|
|
82
|
-
if (status === 404) return new NotFoundError(msg, opts);
|
|
83
|
-
if (status === 429) return new RateLimitError(msg, { ...opts, retryAfter });
|
|
84
|
-
if (status >= 500) return new ServerError(msg, opts);
|
|
85
|
-
return new CabalSpyIDError(msg, opts);
|
|
86
|
-
}
|
|
87
|
-
function isRetryable(err) {
|
|
88
|
-
return err instanceof RateLimitError || err instanceof ServerError || err instanceof ConnectionError;
|
|
89
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkABFIPCBYcjs = require('./chunk-ABFIPCBY.cjs');
|
|
90
14
|
|
|
91
15
|
// src/types.ts
|
|
92
16
|
var CHAINS = ["solana", "bnb", "base", "eth", "rh"];
|
|
@@ -114,29 +38,29 @@ var FATAL_CODES = /* @__PURE__ */ new Set([
|
|
|
114
38
|
]);
|
|
115
39
|
function streamError(code, message) {
|
|
116
40
|
const opts = { code };
|
|
117
|
-
if (code === "invalid_parameter" || code === "missing_parameter") return new BadRequestError(message, { ...opts, status: 400 });
|
|
118
|
-
if (code === "too_many_connections") return new RateLimitError(message, { ...opts, status: 429 });
|
|
119
|
-
if (FATAL_CODES.has(code)) return new PermissionError(message, { ...opts, status: 403 });
|
|
120
|
-
return new CabalSpyIDError(message, opts);
|
|
41
|
+
if (code === "invalid_parameter" || code === "missing_parameter") return new (0, _chunkABFIPCBYcjs.BadRequestError)(message, { ...opts, status: 400 });
|
|
42
|
+
if (code === "too_many_connections") return new (0, _chunkABFIPCBYcjs.RateLimitError)(message, { ...opts, status: 429 });
|
|
43
|
+
if (FATAL_CODES.has(code)) return new (0, _chunkABFIPCBYcjs.PermissionError)(message, { ...opts, status: 403 });
|
|
44
|
+
return new (0, _chunkABFIPCBYcjs.CabalSpyIDError)(message, opts);
|
|
121
45
|
}
|
|
122
|
-
var CabalSpyIDStream = (
|
|
123
|
-
constructor(url, apiKey, options = {}) {;
|
|
46
|
+
var CabalSpyIDStream = (_class = class {
|
|
47
|
+
constructor(url, apiKey, options = {}) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);
|
|
124
48
|
this.url = url;
|
|
125
49
|
this.apiKey = apiKey;
|
|
126
50
|
this.options = options;
|
|
127
51
|
const events = _nullishCoalesce(options.events, () => ( ["trades"]));
|
|
128
52
|
if (!events.length || events.some((e) => e !== "trades" && e !== "theses")) {
|
|
129
|
-
throw new BadRequestError("events must contain 'trades' and/or 'theses'", {
|
|
53
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)("events must contain 'trades' and/or 'theses'", {
|
|
130
54
|
code: "invalid_parameter",
|
|
131
55
|
parameter: "events",
|
|
132
56
|
allowed: ["trades", "theses"]
|
|
133
57
|
});
|
|
134
58
|
}
|
|
135
59
|
if (options.mint && !options.blockchain) {
|
|
136
|
-
throw new BadRequestError("mint needs blockchain", { code: "missing_parameter", parameter: "blockchain" });
|
|
60
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)("mint needs blockchain", { code: "missing_parameter", parameter: "blockchain" });
|
|
137
61
|
}
|
|
138
62
|
if (options.blockchain && !CHAINS.includes(options.blockchain)) {
|
|
139
|
-
throw new BadRequestError(`Unknown blockchain '${options.blockchain}'`, {
|
|
63
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`Unknown blockchain '${options.blockchain}'`, {
|
|
140
64
|
code: "invalid_parameter",
|
|
141
65
|
parameter: "blockchain",
|
|
142
66
|
allowed: [...CHAINS]
|
|
@@ -152,17 +76,17 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
152
76
|
|
|
153
77
|
|
|
154
78
|
|
|
155
|
-
|
|
79
|
+
__init() {this.ws = null}
|
|
156
80
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
81
|
+
__init2() {this.handlers = /* @__PURE__ */ new Map()}
|
|
82
|
+
__init3() {this.reconnectAttempt = 0}
|
|
83
|
+
__init4() {this.reconnectTimer = null}
|
|
84
|
+
__init5() {this.watchdog = null}
|
|
85
|
+
__init6() {this.closedByUser = false}
|
|
86
|
+
__init7() {this.fatal = null}
|
|
163
87
|
/** True while the socket is open. */
|
|
164
88
|
get connected() {
|
|
165
|
-
return _optionalChain([this, 'access',
|
|
89
|
+
return _optionalChain([this, 'access', _ => _.ws, 'optionalAccess', _2 => _2.readyState]) === 1;
|
|
166
90
|
}
|
|
167
91
|
/** The stream URL including query parameters, with the key masked. */
|
|
168
92
|
get safeUrl() {
|
|
@@ -187,7 +111,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
187
111
|
return this;
|
|
188
112
|
}
|
|
189
113
|
off(event, handler) {
|
|
190
|
-
_optionalChain([this, 'access',
|
|
114
|
+
_optionalChain([this, 'access', _3 => _3.handlers, 'access', _4 => _4.get, 'call', _5 => _5(event), 'optionalAccess', _6 => _6.delete, 'call', _7 => _7(handler)]);
|
|
191
115
|
return this;
|
|
192
116
|
}
|
|
193
117
|
emit(event, payload) {
|
|
@@ -198,7 +122,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
198
122
|
h(payload);
|
|
199
123
|
} catch (err) {
|
|
200
124
|
if (event !== "error") {
|
|
201
|
-
this.emit("error", err instanceof CabalSpyIDError ? err : new CabalSpyIDError(String(_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
125
|
+
this.emit("error", err instanceof _chunkABFIPCBYcjs.CabalSpyIDError ? err : new (0, _chunkABFIPCBYcjs.CabalSpyIDError)(String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _8 => _8.message]), () => ( err))), { code: "handler_error" }));
|
|
202
126
|
}
|
|
203
127
|
}
|
|
204
128
|
}
|
|
@@ -210,7 +134,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
210
134
|
const WS = _nullishCoalesce(this.options.WebSocketImpl, () => ( globalThis.WebSocket));
|
|
211
135
|
if (!WS) {
|
|
212
136
|
return Promise.reject(
|
|
213
|
-
new ConnectionError("No WebSocket implementation found. On Node < 22, run `npm i ws` and pass { WebSocketImpl: WebSocket }.", {
|
|
137
|
+
new (0, _chunkABFIPCBYcjs.ConnectionError)("No WebSocket implementation found. On Node < 22, run `npm i ws` and pass { WebSocketImpl: WebSocket }.", {
|
|
214
138
|
code: "no_websocket"
|
|
215
139
|
})
|
|
216
140
|
);
|
|
@@ -227,7 +151,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
227
151
|
try {
|
|
228
152
|
ws = new WS(this.buildUrl(this.apiKey));
|
|
229
153
|
} catch (err) {
|
|
230
|
-
settle(new ConnectionError(`Could not open ${this.safeUrl}: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
154
|
+
settle(new (0, _chunkABFIPCBYcjs.ConnectionError)(`Could not open ${this.safeUrl}: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _9 => _9.message]), () => ( err))}`, { code: "ws_error" }));
|
|
231
155
|
return;
|
|
232
156
|
}
|
|
233
157
|
this.ws = ws;
|
|
@@ -282,7 +206,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
282
206
|
};
|
|
283
207
|
ws.onerror = (ev) => {
|
|
284
208
|
if (this.ws !== ws) return;
|
|
285
|
-
const err = new ConnectionError(`WebSocket error on ${this.safeUrl}: ${describeWsEvent(ev)}`, { code: "ws_error" });
|
|
209
|
+
const err = new (0, _chunkABFIPCBYcjs.ConnectionError)(`WebSocket error on ${this.safeUrl}: ${describeWsEvent(ev)}`, { code: "ws_error" });
|
|
286
210
|
this.emit("error", err);
|
|
287
211
|
settle(err);
|
|
288
212
|
};
|
|
@@ -293,7 +217,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
293
217
|
const e = _nullishCoalesce(ev, () => ( {}));
|
|
294
218
|
this.emit("close", { code: e.code, reason: e.reason });
|
|
295
219
|
settle(
|
|
296
|
-
new ConnectionError(`Stream closed before it was ready (code ${_nullishCoalesce(e.code, () => ( "unknown"))}${e.reason ? `, ${e.reason}` : ""})`, {
|
|
220
|
+
new (0, _chunkABFIPCBYcjs.ConnectionError)(`Stream closed before it was ready (code ${_nullishCoalesce(e.code, () => ( "unknown"))}${e.reason ? `, ${e.reason}` : ""})`, {
|
|
297
221
|
code: "ws_closed_early"
|
|
298
222
|
})
|
|
299
223
|
);
|
|
@@ -316,8 +240,8 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
316
240
|
if (!this.opts.heartbeatTimeout) return;
|
|
317
241
|
this.clearWatchdog();
|
|
318
242
|
this.watchdog = setTimeout(() => {
|
|
319
|
-
this.emit("error", new ConnectionError("No heartbeat from the stream; reconnecting", { code: "heartbeat_timeout" }));
|
|
320
|
-
_optionalChain([this, 'access',
|
|
243
|
+
this.emit("error", new (0, _chunkABFIPCBYcjs.ConnectionError)("No heartbeat from the stream; reconnecting", { code: "heartbeat_timeout" }));
|
|
244
|
+
_optionalChain([this, 'access', _10 => _10.ws, 'optionalAccess', _11 => _11.close, 'call', _12 => _12(4e3, "heartbeat timeout")]);
|
|
321
245
|
}, this.opts.heartbeatTimeout);
|
|
322
246
|
}
|
|
323
247
|
clearWatchdog() {
|
|
@@ -330,7 +254,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
330
254
|
* than every 30 s suppresses those heartbeats.
|
|
331
255
|
*/
|
|
332
256
|
ping() {
|
|
333
|
-
if (_optionalChain([this, 'access',
|
|
257
|
+
if (_optionalChain([this, 'access', _13 => _13.ws, 'optionalAccess', _14 => _14.readyState]) === 1) this.ws.send("ping");
|
|
334
258
|
}
|
|
335
259
|
/** Closes the connection and stops reconnecting. */
|
|
336
260
|
close() {
|
|
@@ -340,7 +264,7 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
340
264
|
this.reconnectTimer = null;
|
|
341
265
|
const ws = this.ws;
|
|
342
266
|
this.ws = null;
|
|
343
|
-
_optionalChain([ws, 'optionalAccess',
|
|
267
|
+
_optionalChain([ws, 'optionalAccess', _15 => _15.close, 'call', _16 => _16(1e3, "client closed")]);
|
|
344
268
|
this.emit("close", { code: 1e3, reason: "client closed" });
|
|
345
269
|
}
|
|
346
270
|
/**
|
|
@@ -371,20 +295,20 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
371
295
|
const listeners = names.map((name) => {
|
|
372
296
|
const fn = (data) => {
|
|
373
297
|
queue.push(wrap(name, data));
|
|
374
|
-
_optionalChain([wake, 'optionalCall',
|
|
298
|
+
_optionalChain([wake, 'optionalCall', _17 => _17()]);
|
|
375
299
|
};
|
|
376
300
|
return [name, fn];
|
|
377
301
|
});
|
|
378
302
|
const onError = () => {
|
|
379
303
|
if (this.fatal) {
|
|
380
304
|
failure = this.fatal;
|
|
381
|
-
_optionalChain([wake, 'optionalCall',
|
|
305
|
+
_optionalChain([wake, 'optionalCall', _18 => _18()]);
|
|
382
306
|
}
|
|
383
307
|
};
|
|
384
308
|
const onClose = () => {
|
|
385
309
|
if (this.closedByUser || !this.opts.reconnect) {
|
|
386
310
|
done = true;
|
|
387
|
-
_optionalChain([wake, 'optionalCall',
|
|
311
|
+
_optionalChain([wake, 'optionalCall', _19 => _19()]);
|
|
388
312
|
}
|
|
389
313
|
};
|
|
390
314
|
for (const [name, fn] of listeners) this.on(name, fn);
|
|
@@ -405,11 +329,11 @@ var CabalSpyIDStream = (_class2 = class {
|
|
|
405
329
|
if (ownsConnection && !this.closedByUser) this.close();
|
|
406
330
|
}
|
|
407
331
|
}
|
|
408
|
-
},
|
|
332
|
+
}, _class);
|
|
409
333
|
function describeWsEvent(ev) {
|
|
410
334
|
if (!ev || typeof ev !== "object") return "no detail available";
|
|
411
335
|
const e = ev;
|
|
412
|
-
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'access',
|
|
336
|
+
return _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([e, 'access', _20 => _20.error, 'optionalAccess', _21 => _21.message]), () => ( e.message)), () => ( (_optionalChain([e, 'access', _22 => _22.error, 'optionalAccess', _23 => _23.code]) ? `errno ${e.error.code}` : void 0))), () => ( e.type)), () => ( "no detail available"));
|
|
413
337
|
}
|
|
414
338
|
|
|
415
339
|
// src/thesesStream.ts
|
|
@@ -420,17 +344,17 @@ function keyOf(t) {
|
|
|
420
344
|
return `${t.blockchain}:${mint}`;
|
|
421
345
|
}
|
|
422
346
|
function connectionError(code, message) {
|
|
423
|
-
if (code === "invalid_parameter") return new BadRequestError(message, { code, status: 400 });
|
|
424
|
-
if (code === "too_many_connections") return new RateLimitError(message, { code, status: 429 });
|
|
425
|
-
return new PermissionError(message, { code, status: 403 });
|
|
347
|
+
if (code === "invalid_parameter") return new (0, _chunkABFIPCBYcjs.BadRequestError)(message, { code, status: 400 });
|
|
348
|
+
if (code === "too_many_connections") return new (0, _chunkABFIPCBYcjs.RateLimitError)(message, { code, status: 429 });
|
|
349
|
+
return new (0, _chunkABFIPCBYcjs.PermissionError)(message, { code, status: 403 });
|
|
426
350
|
}
|
|
427
|
-
var ThesesStream = (
|
|
428
|
-
constructor(url, apiKey, options = {}) {;
|
|
351
|
+
var ThesesStream = (_class2 = class {
|
|
352
|
+
constructor(url, apiKey, options = {}) {;_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);_class2.prototype.__init10.call(this);_class2.prototype.__init11.call(this);_class2.prototype.__init12.call(this);_class2.prototype.__init13.call(this);_class2.prototype.__init14.call(this);_class2.prototype.__init15.call(this);_class2.prototype.__init16.call(this);_class2.prototype.__init17.call(this);
|
|
429
353
|
this.url = url;
|
|
430
354
|
this.apiKey = apiKey;
|
|
431
355
|
this.options = options;
|
|
432
356
|
if (options.scope && options.scope !== "global" && options.scope !== "instance") {
|
|
433
|
-
throw new BadRequestError(`Invalid value for 'scope': ${options.scope}`, {
|
|
357
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`Invalid value for 'scope': ${options.scope}`, {
|
|
434
358
|
code: "invalid_parameter",
|
|
435
359
|
parameter: "scope",
|
|
436
360
|
allowed: ["global", "instance"]
|
|
@@ -446,16 +370,16 @@ var ThesesStream = (_class3 = class {
|
|
|
446
370
|
|
|
447
371
|
|
|
448
372
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
373
|
+
__init8() {this.ws = null}
|
|
374
|
+
__init9() {this.handlers = /* @__PURE__ */ new Map()}
|
|
375
|
+
__init10() {this.tokens = /* @__PURE__ */ new Map()}
|
|
376
|
+
__init11() {this.all = false}
|
|
377
|
+
__init12() {this.attempt = 0}
|
|
378
|
+
__init13() {this.closedByUser = false}
|
|
379
|
+
__init14() {this.fatal = null}
|
|
380
|
+
__init15() {this.ready = false}
|
|
381
|
+
__init16() {this.reconnectTimer = null}
|
|
382
|
+
__init17() {this.watchdog = null}
|
|
459
383
|
|
|
460
384
|
buildUrl(key) {
|
|
461
385
|
const sp = new URLSearchParams({ api_key: key });
|
|
@@ -468,7 +392,7 @@ var ThesesStream = (_class3 = class {
|
|
|
468
392
|
return this.buildUrl("***");
|
|
469
393
|
}
|
|
470
394
|
get connected() {
|
|
471
|
-
return _optionalChain([this, 'access',
|
|
395
|
+
return _optionalChain([this, 'access', _24 => _24.ws, 'optionalAccess', _25 => _25.readyState]) === 1 && this.ready;
|
|
472
396
|
}
|
|
473
397
|
/** The tokens currently subscribed (kept across reconnects). */
|
|
474
398
|
get subscriptions() {
|
|
@@ -481,7 +405,7 @@ var ThesesStream = (_class3 = class {
|
|
|
481
405
|
return this;
|
|
482
406
|
}
|
|
483
407
|
off(event, handler) {
|
|
484
|
-
_optionalChain([this, 'access',
|
|
408
|
+
_optionalChain([this, 'access', _26 => _26.handlers, 'access', _27 => _27.get, 'call', _28 => _28(event), 'optionalAccess', _29 => _29.delete, 'call', _30 => _30(handler)]);
|
|
485
409
|
return this;
|
|
486
410
|
}
|
|
487
411
|
emit(event, payload) {
|
|
@@ -489,12 +413,12 @@ var ThesesStream = (_class3 = class {
|
|
|
489
413
|
try {
|
|
490
414
|
h(payload);
|
|
491
415
|
} catch (err) {
|
|
492
|
-
if (event !== "error") this.emit("error", new CabalSpyIDError(String(_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
416
|
+
if (event !== "error") this.emit("error", new (0, _chunkABFIPCBYcjs.CabalSpyIDError)(String(_nullishCoalesce(_optionalChain([err, 'optionalAccess', _31 => _31.message]), () => ( err))), { code: "handler_error" }));
|
|
493
417
|
}
|
|
494
418
|
}
|
|
495
419
|
}
|
|
496
420
|
send(frame) {
|
|
497
|
-
if (_optionalChain([this, 'access',
|
|
421
|
+
if (_optionalChain([this, 'access', _32 => _32.ws, 'optionalAccess', _33 => _33.readyState]) === 1 && this.ready) this.ws.send(JSON.stringify(frame));
|
|
498
422
|
}
|
|
499
423
|
// ── subscriptions ─────────────────────────────────────────────────────────
|
|
500
424
|
/** Adds tokens (at most 200 per connection). Sent now if connected, and after every reconnect. */
|
|
@@ -502,18 +426,18 @@ var ThesesStream = (_class3 = class {
|
|
|
502
426
|
const fresh = [];
|
|
503
427
|
for (const t of tokens) {
|
|
504
428
|
if (!t || !CHAINS.includes(t.blockchain)) {
|
|
505
|
-
throw new BadRequestError(`Unknown blockchain '${_optionalChain([t, 'optionalAccess',
|
|
429
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`Unknown blockchain '${_optionalChain([t, 'optionalAccess', _34 => _34.blockchain])}'`, {
|
|
506
430
|
code: "invalid_parameter",
|
|
507
431
|
parameter: "blockchain",
|
|
508
432
|
allowed: [...CHAINS]
|
|
509
433
|
});
|
|
510
434
|
}
|
|
511
|
-
if (!t.mint) throw new BadRequestError("Parameter 'mint' is required", { code: "missing_parameter", parameter: "mint" });
|
|
435
|
+
if (!t.mint) throw new (0, _chunkABFIPCBYcjs.BadRequestError)("Parameter 'mint' is required", { code: "missing_parameter", parameter: "mint" });
|
|
512
436
|
const k = keyOf(t);
|
|
513
437
|
if (!this.tokens.has(k)) fresh.push({ blockchain: t.blockchain, mint: t.mint.trim() });
|
|
514
438
|
}
|
|
515
439
|
if (this.tokens.size + fresh.length > MAX_THESES_STREAM_TOKENS) {
|
|
516
|
-
throw new BadRequestError(`At most ${MAX_THESES_STREAM_TOKENS} tokens per connection`, {
|
|
440
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`At most ${MAX_THESES_STREAM_TOKENS} tokens per connection`, {
|
|
517
441
|
code: "too_many_tokens",
|
|
518
442
|
parameter: "tokens"
|
|
519
443
|
});
|
|
@@ -554,7 +478,7 @@ var ThesesStream = (_class3 = class {
|
|
|
554
478
|
const WS = _nullishCoalesce(this.options.WebSocketImpl, () => ( globalThis.WebSocket));
|
|
555
479
|
if (!WS) {
|
|
556
480
|
return Promise.reject(
|
|
557
|
-
new ConnectionError("No WebSocket implementation found. On Node < 22, run `npm i ws` and pass { WebSocketImpl: WebSocket }.", {
|
|
481
|
+
new (0, _chunkABFIPCBYcjs.ConnectionError)("No WebSocket implementation found. On Node < 22, run `npm i ws` and pass { WebSocketImpl: WebSocket }.", {
|
|
558
482
|
code: "no_websocket"
|
|
559
483
|
})
|
|
560
484
|
);
|
|
@@ -600,21 +524,21 @@ var ThesesStream = (_class3 = class {
|
|
|
600
524
|
} else if (event === "pong") {
|
|
601
525
|
this.emit("pong", {});
|
|
602
526
|
} else if (event === "error") {
|
|
603
|
-
const code = _nullishCoalesce(_optionalChain([msg, 'access',
|
|
604
|
-
const message = _nullishCoalesce(_optionalChain([msg, 'access',
|
|
527
|
+
const code = _nullishCoalesce(_optionalChain([msg, 'access', _35 => _35.error, 'optionalAccess', _36 => _36.code]), () => ( "stream_error"));
|
|
528
|
+
const message = _nullishCoalesce(_optionalChain([msg, 'access', _37 => _37.error, 'optionalAccess', _38 => _38.message]), () => ( "Stream error"));
|
|
605
529
|
if (!this.ready) {
|
|
606
530
|
const err = connectionError(code, message);
|
|
607
531
|
if (code !== "too_many_connections") this.fatal = err;
|
|
608
532
|
this.emit("error", err);
|
|
609
533
|
settle(err);
|
|
610
534
|
} else {
|
|
611
|
-
this.emit("error", new BadRequestError(message, { code, status: 400 }));
|
|
535
|
+
this.emit("error", new (0, _chunkABFIPCBYcjs.BadRequestError)(message, { code, status: 400 }));
|
|
612
536
|
}
|
|
613
537
|
}
|
|
614
538
|
};
|
|
615
539
|
ws.onerror = () => {
|
|
616
540
|
if (this.ws !== ws) return;
|
|
617
|
-
const err = new ConnectionError(`WebSocket error on ${this.safeUrl}`, { code: "ws_error" });
|
|
541
|
+
const err = new (0, _chunkABFIPCBYcjs.ConnectionError)(`WebSocket error on ${this.safeUrl}`, { code: "ws_error" });
|
|
618
542
|
this.emit("error", err);
|
|
619
543
|
settle(err);
|
|
620
544
|
};
|
|
@@ -625,7 +549,7 @@ var ThesesStream = (_class3 = class {
|
|
|
625
549
|
this.disarm();
|
|
626
550
|
const e = _nullishCoalesce(ev, () => ( {}));
|
|
627
551
|
this.emit("close", { code: e.code, reason: e.reason });
|
|
628
|
-
settle(new ConnectionError(`Theses stream closed before it was ready (code ${_nullishCoalesce(e.code, () => ( "unknown"))})`, { code: "ws_closed_early" }));
|
|
552
|
+
settle(new (0, _chunkABFIPCBYcjs.ConnectionError)(`Theses stream closed before it was ready (code ${_nullishCoalesce(e.code, () => ( "unknown"))})`, { code: "ws_closed_early" }));
|
|
629
553
|
if (!this.closedByUser && !this.fatal && this.opts.reconnect) this.scheduleReconnect();
|
|
630
554
|
};
|
|
631
555
|
});
|
|
@@ -643,8 +567,8 @@ var ThesesStream = (_class3 = class {
|
|
|
643
567
|
if (!this.opts.heartbeatTimeout) return;
|
|
644
568
|
this.disarm();
|
|
645
569
|
this.watchdog = setTimeout(() => {
|
|
646
|
-
this.emit("error", new ConnectionError("No heartbeat from the theses stream; reconnecting", { code: "heartbeat_timeout" }));
|
|
647
|
-
_optionalChain([this, 'access',
|
|
570
|
+
this.emit("error", new (0, _chunkABFIPCBYcjs.ConnectionError)("No heartbeat from the theses stream; reconnecting", { code: "heartbeat_timeout" }));
|
|
571
|
+
_optionalChain([this, 'access', _39 => _39.ws, 'optionalAccess', _40 => _40.close, 'call', _41 => _41(4e3, "heartbeat timeout")]);
|
|
648
572
|
}, this.opts.heartbeatTimeout);
|
|
649
573
|
}
|
|
650
574
|
disarm() {
|
|
@@ -653,7 +577,7 @@ var ThesesStream = (_class3 = class {
|
|
|
653
577
|
}
|
|
654
578
|
/** Sends a ping (answered with `pong`). Pinging more often than every 30 s suppresses heartbeats. */
|
|
655
579
|
ping() {
|
|
656
|
-
if (_optionalChain([this, 'access',
|
|
580
|
+
if (_optionalChain([this, 'access', _42 => _42.ws, 'optionalAccess', _43 => _43.readyState]) === 1) this.ws.send(JSON.stringify({ op: "ping" }));
|
|
657
581
|
}
|
|
658
582
|
/** Closes the socket and stops reconnecting. Subscriptions are kept for a later connect(). */
|
|
659
583
|
close() {
|
|
@@ -664,7 +588,7 @@ var ThesesStream = (_class3 = class {
|
|
|
664
588
|
const ws = this.ws;
|
|
665
589
|
this.ws = null;
|
|
666
590
|
this.ready = false;
|
|
667
|
-
_optionalChain([ws, 'optionalAccess',
|
|
591
|
+
_optionalChain([ws, 'optionalAccess', _44 => _44.close, 'call', _45 => _45(1e3, "client closed")]);
|
|
668
592
|
this.emit("close", { code: 1e3, reason: "client closed" });
|
|
669
593
|
}
|
|
670
594
|
/**
|
|
@@ -679,20 +603,20 @@ var ThesesStream = (_class3 = class {
|
|
|
679
603
|
const listeners = THESIS_EVENT_NAMES.map((name) => {
|
|
680
604
|
const fn = (data) => {
|
|
681
605
|
queue.push({ event: name, data });
|
|
682
|
-
_optionalChain([wake, 'optionalCall',
|
|
606
|
+
_optionalChain([wake, 'optionalCall', _46 => _46()]);
|
|
683
607
|
};
|
|
684
608
|
return [name, fn];
|
|
685
609
|
});
|
|
686
610
|
const onError = () => {
|
|
687
611
|
if (this.fatal) {
|
|
688
612
|
failure = this.fatal;
|
|
689
|
-
_optionalChain([wake, 'optionalCall',
|
|
613
|
+
_optionalChain([wake, 'optionalCall', _47 => _47()]);
|
|
690
614
|
}
|
|
691
615
|
};
|
|
692
616
|
const onClose = () => {
|
|
693
617
|
if (this.closedByUser || !this.opts.reconnect) {
|
|
694
618
|
done = true;
|
|
695
|
-
_optionalChain([wake, 'optionalCall',
|
|
619
|
+
_optionalChain([wake, 'optionalCall', _48 => _48()]);
|
|
696
620
|
}
|
|
697
621
|
};
|
|
698
622
|
for (const [name, fn] of listeners) this.on(name, fn);
|
|
@@ -713,10 +637,10 @@ var ThesesStream = (_class3 = class {
|
|
|
713
637
|
if (owns && !this.closedByUser) this.close();
|
|
714
638
|
}
|
|
715
639
|
}
|
|
716
|
-
},
|
|
640
|
+
}, _class2);
|
|
717
641
|
|
|
718
642
|
// src/util.ts
|
|
719
|
-
var SDK_VERSION = "0.5.
|
|
643
|
+
var SDK_VERSION = "0.5.2";
|
|
720
644
|
var USER_AGENT = `cabalspy-id-sdk/${SDK_VERSION}`;
|
|
721
645
|
var enc = new TextEncoder();
|
|
722
646
|
var dec = new TextDecoder();
|
|
@@ -747,7 +671,7 @@ function base64UrlDecode(text) {
|
|
|
747
671
|
var cryptoPromise = null;
|
|
748
672
|
function getCrypto() {
|
|
749
673
|
const g = globalThis.crypto;
|
|
750
|
-
if (_optionalChain([g, 'optionalAccess',
|
|
674
|
+
if (_optionalChain([g, 'optionalAccess', _49 => _49.subtle])) return Promise.resolve(g);
|
|
751
675
|
if (!cryptoPromise) {
|
|
752
676
|
const mod = "node:crypto";
|
|
753
677
|
cryptoPromise = Promise.resolve().then(() => _interopRequireWildcard(require(
|
|
@@ -777,7 +701,7 @@ function timingSafeEqual(a, b) {
|
|
|
777
701
|
return diff === 0;
|
|
778
702
|
}
|
|
779
703
|
function env(name) {
|
|
780
|
-
return _optionalChain([globalThis, 'access',
|
|
704
|
+
return _optionalChain([globalThis, 'access', _50 => _50.process, 'optionalAccess', _51 => _51.env, 'optionalAccess', _52 => _52[name]]);
|
|
781
705
|
}
|
|
782
706
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
783
707
|
|
|
@@ -801,7 +725,7 @@ function parseNumHeader(h, name) {
|
|
|
801
725
|
return Number.isFinite(n) ? n : null;
|
|
802
726
|
}
|
|
803
727
|
function backoffDelay(attempt, lastError) {
|
|
804
|
-
if (lastError instanceof RateLimitError && lastError.retryAfter != null) {
|
|
728
|
+
if (lastError instanceof _chunkABFIPCBYcjs.RateLimitError && lastError.retryAfter != null) {
|
|
805
729
|
return Math.min(lastError.retryAfter * 1e3, 6e4);
|
|
806
730
|
}
|
|
807
731
|
const base = 500 * 2 ** (attempt - 1);
|
|
@@ -810,7 +734,7 @@ function backoffDelay(attempt, lastError) {
|
|
|
810
734
|
function assertOneOf(value, allowed, parameter) {
|
|
811
735
|
if (value === void 0) return;
|
|
812
736
|
if (!allowed.includes(value)) {
|
|
813
|
-
throw new BadRequestError(`Invalid value for '${parameter}': ${value}`, {
|
|
737
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`Invalid value for '${parameter}': ${value}`, {
|
|
814
738
|
code: "invalid_parameter",
|
|
815
739
|
parameter,
|
|
816
740
|
allowed: [...allowed]
|
|
@@ -819,7 +743,7 @@ function assertOneOf(value, allowed, parameter) {
|
|
|
819
743
|
}
|
|
820
744
|
function assertRequired(value, parameter) {
|
|
821
745
|
if (value === void 0 || value === null || value === "") {
|
|
822
|
-
throw new BadRequestError(`Parameter '${parameter}' is required`, { code: "missing_parameter", parameter });
|
|
746
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)(`Parameter '${parameter}' is required`, { code: "missing_parameter", parameter });
|
|
823
747
|
}
|
|
824
748
|
}
|
|
825
749
|
function assertToken(p) {
|
|
@@ -832,7 +756,7 @@ function assertWallet(p) {
|
|
|
832
756
|
assertOneOf(p.blockchain, CHAINS, "blockchain");
|
|
833
757
|
assertRequired(p.address, "address");
|
|
834
758
|
}
|
|
835
|
-
var CabalSpyID = (
|
|
759
|
+
var CabalSpyID = (_class3 = class {
|
|
836
760
|
|
|
837
761
|
|
|
838
762
|
|
|
@@ -843,8 +767,8 @@ var CabalSpyID = (_class4 = class {
|
|
|
843
767
|
|
|
844
768
|
|
|
845
769
|
/** Rate limit state from the most recent request. */
|
|
846
|
-
|
|
847
|
-
constructor(options = {}) {;
|
|
770
|
+
__init18() {this.lastRateLimit = { ..._chunkABFIPCBYcjs.EMPTY_RATE_LIMIT }}
|
|
771
|
+
constructor(options = {}) {;_class3.prototype.__init18.call(this);
|
|
848
772
|
this.apiKey = _nullishCoalesce(options.apiKey, () => ( (env("CABALSPY_ID_API_KEY") || env("CABALSPY_API_KEY") || "")));
|
|
849
773
|
this.instance = _nullishCoalesce(options.instance, () => ( (env("CABALSPY_ID_INSTANCE") || void 0)));
|
|
850
774
|
this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( (env("CABALSPY_ID_BASE_URL") || DEFAULT_BASE_URL)))).replace(/\/+$/, "");
|
|
@@ -855,7 +779,7 @@ var CabalSpyID = (_class4 = class {
|
|
|
855
779
|
this.extraHeaders = _nullishCoalesce(options.headers, () => ( {}));
|
|
856
780
|
const f = _nullishCoalesce(options.fetch, () => ( globalThis.fetch));
|
|
857
781
|
if (typeof f !== "function") {
|
|
858
|
-
throw new CabalSpyIDError("No fetch implementation available. Use Node 18+ or pass { fetch }.", {
|
|
782
|
+
throw new (0, _chunkABFIPCBYcjs.CabalSpyIDError)("No fetch implementation available. Use Node 18+ or pass { fetch }.", {
|
|
859
783
|
code: "no_fetch"
|
|
860
784
|
});
|
|
861
785
|
}
|
|
@@ -864,7 +788,7 @@ var CabalSpyID = (_class4 = class {
|
|
|
864
788
|
// ── HTTP core ─────────────────────────────────────────────────────────────
|
|
865
789
|
authedQuery(query, auth) {
|
|
866
790
|
if (auth && !this.apiKey) {
|
|
867
|
-
throw new AuthenticationError(
|
|
791
|
+
throw new (0, _chunkABFIPCBYcjs.AuthenticationError)(
|
|
868
792
|
"Missing API key. Pass { apiKey } or set CABALSPY_ID_API_KEY (the CabalSpy API key with CabalSpy ID enabled).",
|
|
869
793
|
{ status: 401, code: "missing_api_key" }
|
|
870
794
|
);
|
|
@@ -917,9 +841,9 @@ var CabalSpyID = (_class4 = class {
|
|
|
917
841
|
});
|
|
918
842
|
text = await res.text();
|
|
919
843
|
} catch (err) {
|
|
920
|
-
const aborted = _optionalChain([err, 'optionalAccess',
|
|
921
|
-
lastError = new ConnectionError(
|
|
922
|
-
aborted ? `Request timed out after ${this.timeout} ms: ${label}` : `Network error: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess',
|
|
844
|
+
const aborted = _optionalChain([err, 'optionalAccess', _53 => _53.name]) === "AbortError";
|
|
845
|
+
lastError = new (0, _chunkABFIPCBYcjs.ConnectionError)(
|
|
846
|
+
aborted ? `Request timed out after ${this.timeout} ms: ${label}` : `Network error: ${_nullishCoalesce(_optionalChain([err, 'optionalAccess', _54 => _54.message]), () => ( String(err)))}`,
|
|
923
847
|
{ code: aborted ? "timeout" : "connection_error" }
|
|
924
848
|
);
|
|
925
849
|
if (method !== "GET") throw lastError;
|
|
@@ -942,10 +866,10 @@ var CabalSpyID = (_class4 = class {
|
|
|
942
866
|
}
|
|
943
867
|
}
|
|
944
868
|
if (!res.ok) {
|
|
945
|
-
const errBody = _nullishCoalesce(_optionalChain([parsed, 'optionalAccess',
|
|
869
|
+
const errBody = _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _55 => _55.error]), () => ( null));
|
|
946
870
|
const retryAfter = parseNumHeader(res.headers, "Retry-After");
|
|
947
|
-
const error = errorFromStatus(res.status, errBody, rateLimit, retryAfter, `HTTP ${res.status} on ${label}`);
|
|
948
|
-
const retryable = method === "GET" ? isRetryable(error) : error instanceof RateLimitError && error.code === "rate_limit_exceeded";
|
|
871
|
+
const error = _chunkABFIPCBYcjs.errorFromStatus.call(void 0, res.status, errBody, rateLimit, retryAfter, `HTTP ${res.status} on ${label}`);
|
|
872
|
+
const retryable = method === "GET" ? _chunkABFIPCBYcjs.isRetryable.call(void 0, error) : error instanceof _chunkABFIPCBYcjs.RateLimitError && error.code === "rate_limit_exceeded";
|
|
949
873
|
if (retryable && attempt < this.maxRetries) {
|
|
950
874
|
lastError = error;
|
|
951
875
|
continue;
|
|
@@ -953,7 +877,7 @@ var CabalSpyID = (_class4 = class {
|
|
|
953
877
|
throw error;
|
|
954
878
|
}
|
|
955
879
|
if (parsed == null || typeof parsed !== "object" || !("data" in parsed)) {
|
|
956
|
-
throw new InvalidResponseError(`Unexpected response shape on ${label}: no data field`, {
|
|
880
|
+
throw new (0, _chunkABFIPCBYcjs.InvalidResponseError)(`Unexpected response shape on ${label}: no data field`, {
|
|
957
881
|
status: res.status,
|
|
958
882
|
code: "invalid_response",
|
|
959
883
|
rateLimit
|
|
@@ -961,7 +885,7 @@ var CabalSpyID = (_class4 = class {
|
|
|
961
885
|
}
|
|
962
886
|
return { ...parsed, rateLimit, status: res.status };
|
|
963
887
|
}
|
|
964
|
-
throw _nullishCoalesce(lastError, () => ( new ConnectionError(`Request failed: ${label}`)));
|
|
888
|
+
throw _nullishCoalesce(lastError, () => ( new (0, _chunkABFIPCBYcjs.ConnectionError)(`Request failed: ${label}`)));
|
|
965
889
|
}
|
|
966
890
|
/**
|
|
967
891
|
* Walks a cursor-paginated route and yields whole pages.
|
|
@@ -975,11 +899,11 @@ var CabalSpyID = (_class4 = class {
|
|
|
975
899
|
const maxPages = _nullishCoalesce(opts.maxPages, () => ( Infinity));
|
|
976
900
|
for (let i = 0; i < maxPages; i++) {
|
|
977
901
|
const page = await fetchPage(cursor);
|
|
978
|
-
const inner = _optionalChain([page, 'access',
|
|
902
|
+
const inner = _optionalChain([page, 'access', _56 => _56.data, 'optionalAccess', _57 => _57.pagination]);
|
|
979
903
|
const pagination = _nullishCoalesce(page.pagination, () => ( inner));
|
|
980
904
|
yield { ...page, pagination };
|
|
981
|
-
const next = _optionalChain([pagination, 'optionalAccess',
|
|
982
|
-
if (!_optionalChain([pagination, 'optionalAccess',
|
|
905
|
+
const next = _optionalChain([pagination, 'optionalAccess', _58 => _58.next_cursor]);
|
|
906
|
+
if (!_optionalChain([pagination, 'optionalAccess', _59 => _59.has_more]) || !next) return;
|
|
983
907
|
cursor = next;
|
|
984
908
|
}
|
|
985
909
|
}
|
|
@@ -1021,13 +945,13 @@ var CabalSpyID = (_class4 = class {
|
|
|
1021
945
|
const p = params;
|
|
1022
946
|
const given = [p.username, p.csid_id, p.address].filter((v) => v !== void 0 && v !== "").length;
|
|
1023
947
|
if (given !== 1) {
|
|
1024
|
-
throw new BadRequestError("Pass exactly one of: username, csid_id, address.", {
|
|
948
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)("Pass exactly one of: username, csid_id, address.", {
|
|
1025
949
|
code: "missing_parameter",
|
|
1026
950
|
parameter: "username|csid_id|address"
|
|
1027
951
|
});
|
|
1028
952
|
}
|
|
1029
953
|
return this.get("/profile", {
|
|
1030
|
-
username: _optionalChain([p, 'access',
|
|
954
|
+
username: _optionalChain([p, 'access', _60 => _60.username, 'optionalAccess', _61 => _61.replace, 'call', _62 => _62(/^@/, "")]),
|
|
1031
955
|
csid_id: p.csid_id,
|
|
1032
956
|
address: p.address,
|
|
1033
957
|
scope: p.scope
|
|
@@ -1156,12 +1080,12 @@ var CabalSpyID = (_class4 = class {
|
|
|
1156
1080
|
async userThesesRaw(params) {
|
|
1157
1081
|
const p = params;
|
|
1158
1082
|
if (!!p.csid_id === !!p.username) {
|
|
1159
|
-
throw new BadRequestError("Pass exactly one of: csid_id, username.", {
|
|
1083
|
+
throw new (0, _chunkABFIPCBYcjs.BadRequestError)("Pass exactly one of: csid_id, username.", {
|
|
1160
1084
|
code: "missing_parameter",
|
|
1161
1085
|
parameter: "csid_id|username"
|
|
1162
1086
|
});
|
|
1163
1087
|
}
|
|
1164
|
-
return this.getRaw("/theses/user", { ...p, username: _optionalChain([p, 'access',
|
|
1088
|
+
return this.getRaw("/theses/user", { ...p, username: _optionalChain([p, 'access', _63 => _63.username, 'optionalAccess', _64 => _64.replace, 'call', _65 => _65(/^@/, "")]) });
|
|
1165
1089
|
}
|
|
1166
1090
|
/**
|
|
1167
1091
|
* GET /v1/theses/eligibility — may this user post (holder, not paused) and
|
|
@@ -1237,7 +1161,7 @@ var CabalSpyID = (_class4 = class {
|
|
|
1237
1161
|
*/
|
|
1238
1162
|
stream(options = {}) {
|
|
1239
1163
|
if (!this.apiKey) {
|
|
1240
|
-
throw new AuthenticationError("The stream needs an API key.", { status: 401, code: "missing_api_key" });
|
|
1164
|
+
throw new (0, _chunkABFIPCBYcjs.AuthenticationError)("The stream needs an API key.", { status: 401, code: "missing_api_key" });
|
|
1241
1165
|
}
|
|
1242
1166
|
return new CabalSpyIDStream(this.streamUrl, this.apiKey, { instance: this.instance, ...options });
|
|
1243
1167
|
}
|
|
@@ -1251,11 +1175,11 @@ var CabalSpyID = (_class4 = class {
|
|
|
1251
1175
|
*/
|
|
1252
1176
|
thesesStream(options = {}) {
|
|
1253
1177
|
if (!this.apiKey) {
|
|
1254
|
-
throw new AuthenticationError("The theses stream needs an API key.", { status: 401, code: "missing_api_key" });
|
|
1178
|
+
throw new (0, _chunkABFIPCBYcjs.AuthenticationError)("The theses stream needs an API key.", { status: 401, code: "missing_api_key" });
|
|
1255
1179
|
}
|
|
1256
1180
|
return new ThesesStream(this.thesesStreamUrl, this.apiKey, { instance: this.instance, ...options });
|
|
1257
1181
|
}
|
|
1258
|
-
},
|
|
1182
|
+
}, _class3);
|
|
1259
1183
|
function stripQuery(path) {
|
|
1260
1184
|
const i = path.indexOf("?");
|
|
1261
1185
|
return i === -1 ? path : path.slice(0, i);
|
|
@@ -1279,7 +1203,7 @@ function secretKey(secret) {
|
|
|
1279
1203
|
try {
|
|
1280
1204
|
return base64ToBytes(secret.startsWith("whsec_") ? secret.slice(6) : secret);
|
|
1281
1205
|
} catch (e5) {
|
|
1282
|
-
throw new WebhookVerificationError("The webhook secret is not valid base64 (expected whsec_\u2026)", { code: "invalid_secret" });
|
|
1206
|
+
throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("The webhook secret is not valid base64 (expected whsec_\u2026)", { code: "invalid_secret" });
|
|
1283
1207
|
}
|
|
1284
1208
|
}
|
|
1285
1209
|
async function hmac(secret, content) {
|
|
@@ -1299,34 +1223,34 @@ async function signWebhook(secret, id, timestamp, payload) {
|
|
|
1299
1223
|
}
|
|
1300
1224
|
async function verifyWebhook(options) {
|
|
1301
1225
|
const { headers, secret } = options;
|
|
1302
|
-
if (!secret) throw new WebhookVerificationError("Missing webhook secret", { code: "invalid_secret" });
|
|
1226
|
+
if (!secret) throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Missing webhook secret", { code: "invalid_secret" });
|
|
1303
1227
|
const id = header(headers, "webhook-id");
|
|
1304
1228
|
const ts = header(headers, "webhook-timestamp");
|
|
1305
1229
|
const sigs = header(headers, "webhook-signature");
|
|
1306
1230
|
if (!id || !ts || !sigs) {
|
|
1307
|
-
throw new WebhookVerificationError("Missing webhook-id, webhook-timestamp or webhook-signature header", {
|
|
1231
|
+
throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Missing webhook-id, webhook-timestamp or webhook-signature header", {
|
|
1308
1232
|
code: "missing_headers"
|
|
1309
1233
|
});
|
|
1310
1234
|
}
|
|
1311
1235
|
const timestamp = Number(ts);
|
|
1312
1236
|
if (!/^\d+$/.test(ts) || !Number.isSafeInteger(timestamp)) {
|
|
1313
|
-
throw new WebhookVerificationError("Invalid webhook-timestamp", { code: "invalid_timestamp" });
|
|
1237
|
+
throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Invalid webhook-timestamp", { code: "invalid_timestamp" });
|
|
1314
1238
|
}
|
|
1315
1239
|
const now = _nullishCoalesce(options.now, () => ( Math.floor(Date.now() / 1e3)));
|
|
1316
1240
|
const tolerance = _nullishCoalesce(options.toleranceSeconds, () => ( 300));
|
|
1317
|
-
if (now - timestamp > tolerance) throw new WebhookVerificationError("Webhook timestamp is too old", { code: "timestamp_too_old" });
|
|
1318
|
-
if (timestamp - now > tolerance) throw new WebhookVerificationError("Webhook timestamp is in the future", { code: "timestamp_too_new" });
|
|
1241
|
+
if (now - timestamp > tolerance) throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Webhook timestamp is too old", { code: "timestamp_too_old" });
|
|
1242
|
+
if (timestamp - now > tolerance) throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Webhook timestamp is in the future", { code: "timestamp_too_new" });
|
|
1319
1243
|
const body = toBytes(options.payload);
|
|
1320
1244
|
const expected = await hmac(secret, signedContent(id, ts, body));
|
|
1321
1245
|
const match = sigs.split(" ").map((s) => s.trim()).filter(Boolean).some((s) => {
|
|
1322
1246
|
const [version, sig] = s.split(",", 2);
|
|
1323
1247
|
return version === "v1" && sig !== void 0 && timingSafeEqual(sig, expected);
|
|
1324
1248
|
});
|
|
1325
|
-
if (!match) throw new WebhookVerificationError("No matching webhook signature", { code: "invalid_signature" });
|
|
1249
|
+
if (!match) throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("No matching webhook signature", { code: "invalid_signature" });
|
|
1326
1250
|
try {
|
|
1327
1251
|
return JSON.parse(fromUtf8(body));
|
|
1328
1252
|
} catch (e6) {
|
|
1329
|
-
throw new WebhookVerificationError("Webhook body is not valid JSON", { code: "invalid_payload" });
|
|
1253
|
+
throw new (0, _chunkABFIPCBYcjs.WebhookVerificationError)("Webhook body is not valid JSON", { code: "invalid_payload" });
|
|
1330
1254
|
}
|
|
1331
1255
|
}
|
|
1332
1256
|
|
|
@@ -1373,20 +1297,5 @@ function hasX(user) {
|
|
|
1373
1297
|
|
|
1374
1298
|
|
|
1375
1299
|
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
exports.EMPTY_RATE_LIMIT = EMPTY_RATE_LIMIT; exports.CabalSpyIDError = CabalSpyIDError; exports.BadRequestError = BadRequestError; exports.AuthenticationError = AuthenticationError; exports.PermissionError = PermissionError; exports.PlanUserLimitError = PlanUserLimitError; exports.NotFoundError = NotFoundError; exports.RateLimitError = RateLimitError; exports.ServerError = ServerError; exports.ConnectionError = ConnectionError; exports.InvalidResponseError = InvalidResponseError; exports.OAuthError = OAuthError; exports.TokenVerificationError = TokenVerificationError; exports.WebhookVerificationError = WebhookVerificationError; exports.errorFromStatus = errorFromStatus; exports.CHAINS = CHAINS; exports.PERIODS = PERIODS; exports.LEADERBOARD_SORTS = LEADERBOARD_SORTS; exports.CURRENCY_BY_CHAIN = CURRENCY_BY_CHAIN; exports.THESIS_EMOJIS = THESIS_EMOJIS; exports.THESIS_REPORT_REASONS = THESIS_REPORT_REASONS; exports.THESIS_MAX_BODY = THESIS_MAX_BODY; exports.CabalSpyIDStream = CabalSpyIDStream; exports.MAX_THESES_STREAM_TOKENS = MAX_THESES_STREAM_TOKENS; exports.ThesesStream = ThesesStream; exports.SDK_VERSION = SDK_VERSION; exports.USER_AGENT = USER_AGENT; exports.utf8 = utf8; exports.fromUtf8 = fromUtf8; exports.base64UrlDecode = base64UrlDecode; exports.getCrypto = getCrypto; exports.randomToken = randomToken; exports.sha256Base64Url = sha256Base64Url; exports.timingSafeEqual = timingSafeEqual; exports.env = env; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_STREAM_URL = DEFAULT_STREAM_URL; exports.DEFAULT_THESES_STREAM_URL = DEFAULT_THESES_STREAM_URL; exports.CabalSpyID = CabalSpyID; exports.signWebhook = signWebhook; exports.verifyWebhook = verifyWebhook; exports.handleKind = handleKind; exports.hasX = hasX;
|
|
1392
|
-
//# sourceMappingURL=chunk-L4RHSWOA.cjs.map
|
|
1300
|
+
exports.CHAINS = CHAINS; exports.PERIODS = PERIODS; exports.LEADERBOARD_SORTS = LEADERBOARD_SORTS; exports.CURRENCY_BY_CHAIN = CURRENCY_BY_CHAIN; exports.THESIS_EMOJIS = THESIS_EMOJIS; exports.THESIS_REPORT_REASONS = THESIS_REPORT_REASONS; exports.THESIS_MAX_BODY = THESIS_MAX_BODY; exports.CabalSpyIDStream = CabalSpyIDStream; exports.MAX_THESES_STREAM_TOKENS = MAX_THESES_STREAM_TOKENS; exports.ThesesStream = ThesesStream; exports.SDK_VERSION = SDK_VERSION; exports.USER_AGENT = USER_AGENT; exports.utf8 = utf8; exports.fromUtf8 = fromUtf8; exports.base64UrlDecode = base64UrlDecode; exports.getCrypto = getCrypto; exports.randomToken = randomToken; exports.sha256Base64Url = sha256Base64Url; exports.timingSafeEqual = timingSafeEqual; exports.env = env; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_STREAM_URL = DEFAULT_STREAM_URL; exports.DEFAULT_THESES_STREAM_URL = DEFAULT_THESES_STREAM_URL; exports.CabalSpyID = CabalSpyID; exports.signWebhook = signWebhook; exports.verifyWebhook = verifyWebhook; exports.handleKind = handleKind; exports.hasX = hasX;
|
|
1301
|
+
//# sourceMappingURL=chunk-ULEBNY2A.cjs.map
|