@n1xyz/nord-ts 0.0.1 → 0.0.4

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.
Files changed (237) hide show
  1. package/.eslintrc.js +11 -0
  2. package/README.md +148 -65
  3. package/dist/bridge/NordUser.d.ts +78 -0
  4. package/dist/bridge/NordUser.js +196 -0
  5. package/dist/bridge/client.d.ts +150 -0
  6. package/dist/bridge/client.js +394 -0
  7. package/dist/bridge/const.d.ts +23 -0
  8. package/dist/bridge/const.js +47 -0
  9. package/dist/bridge/index.d.ts +5 -0
  10. package/dist/bridge/index.js +23 -0
  11. package/dist/bridge/types.d.ts +118 -0
  12. package/dist/bridge/types.js +16 -0
  13. package/dist/bridge/utils.d.ts +64 -0
  14. package/dist/bridge/utils.js +131 -0
  15. package/dist/client.d.ts +70 -0
  16. package/dist/client.js +129 -0
  17. package/dist/const.d.ts +2 -5
  18. package/dist/const.js +18 -22
  19. package/dist/constants/endpoints.d.ts +65 -0
  20. package/dist/constants/endpoints.js +68 -0
  21. package/dist/gen/common.d.ts +6 -1
  22. package/dist/gen/common.js +19 -9
  23. package/dist/gen/nord.d.ts +75 -17
  24. package/dist/gen/nord.js +987 -423
  25. package/dist/idl/bridge.d.ts +2 -0
  26. package/dist/idl/bridge.js +703 -0
  27. package/dist/index.d.ts +8 -5
  28. package/dist/index.js +18 -2
  29. package/dist/models/account.d.ts +58 -0
  30. package/dist/models/account.js +6 -0
  31. package/dist/models/index.d.ts +8 -0
  32. package/dist/models/index.js +28 -0
  33. package/dist/models/market.d.ts +137 -0
  34. package/dist/models/market.js +6 -0
  35. package/dist/models/order.d.ts +211 -0
  36. package/dist/models/order.js +6 -0
  37. package/dist/models/token.d.ts +50 -0
  38. package/dist/models/token.js +6 -0
  39. package/dist/nord/Nord.d.ts +222 -49
  40. package/dist/nord/Nord.js +290 -278
  41. package/dist/nord/NordError.d.ts +23 -0
  42. package/dist/nord/NordError.js +48 -0
  43. package/dist/nord/NordImpl.d.ts +6 -2
  44. package/dist/nord/NordImpl.js +21 -1
  45. package/dist/nord/NordUser.d.ts +208 -42
  46. package/dist/nord/NordUser.js +389 -157
  47. package/dist/nord/Subscriber.d.ts +37 -0
  48. package/dist/nord/Subscriber.js +29 -0
  49. package/dist/nord/api/actions.d.ts +101 -0
  50. package/dist/nord/api/actions.js +250 -0
  51. package/dist/nord/api/core.d.ts +49 -0
  52. package/dist/nord/api/core.js +121 -0
  53. package/dist/nord/api/index.d.ts +1 -0
  54. package/dist/nord/api/index.js +17 -0
  55. package/dist/nord/api/market.d.ts +36 -0
  56. package/dist/nord/api/market.js +98 -0
  57. package/dist/nord/api/metrics.d.ts +67 -0
  58. package/dist/nord/api/metrics.js +132 -0
  59. package/dist/nord/api/orderFunctions.d.ts +168 -0
  60. package/dist/nord/api/orderFunctions.js +133 -0
  61. package/dist/nord/api/queries.d.ts +81 -0
  62. package/dist/nord/api/queries.js +187 -0
  63. package/dist/nord/client/Nord.d.ts +335 -0
  64. package/dist/nord/client/Nord.js +532 -0
  65. package/dist/nord/client/NordUser.d.ts +320 -0
  66. package/dist/nord/client/NordUser.js +701 -0
  67. package/dist/nord/core.d.ts +48 -0
  68. package/dist/nord/core.js +97 -0
  69. package/dist/nord/index.d.ts +9 -2
  70. package/dist/nord/index.js +30 -6
  71. package/dist/nord/market.d.ts +36 -0
  72. package/dist/nord/market.js +90 -0
  73. package/dist/nord/metrics.d.ts +67 -0
  74. package/dist/nord/metrics.js +124 -0
  75. package/dist/nord/models/Subscriber.d.ts +37 -0
  76. package/dist/nord/models/Subscriber.js +29 -0
  77. package/dist/nord/queries.d.ts +81 -0
  78. package/dist/nord/queries.js +181 -0
  79. package/dist/nord/types.d.ts +88 -0
  80. package/dist/nord/types.js +2 -0
  81. package/dist/nord/utils/NordError.d.ts +35 -0
  82. package/dist/nord/utils/NordError.js +46 -0
  83. package/dist/nord/websocket.d.ts +49 -0
  84. package/dist/nord/websocket.js +107 -0
  85. package/dist/operations/account.d.ts +58 -0
  86. package/dist/operations/account.js +112 -0
  87. package/dist/operations/market.d.ts +65 -0
  88. package/dist/operations/market.js +131 -0
  89. package/dist/operations/orders.d.ts +57 -0
  90. package/dist/operations/orders.js +129 -0
  91. package/dist/solana/NordUser.d.ts +78 -0
  92. package/dist/solana/NordUser.js +196 -0
  93. package/dist/solana/client.d.ts +139 -0
  94. package/dist/solana/client.js +360 -0
  95. package/dist/solana/const.d.ts +23 -0
  96. package/dist/solana/const.js +47 -0
  97. package/dist/solana/index.d.ts +5 -0
  98. package/dist/solana/index.js +23 -0
  99. package/dist/solana/types.d.ts +118 -0
  100. package/dist/solana/types.js +16 -0
  101. package/dist/solana/utils.d.ts +64 -0
  102. package/dist/solana/utils.js +131 -0
  103. package/dist/types/api.d.ts +152 -0
  104. package/dist/types/api.js +6 -0
  105. package/dist/types/config.d.ts +34 -0
  106. package/dist/types/config.js +6 -0
  107. package/dist/types.d.ts +144 -87
  108. package/dist/types.js +13 -2
  109. package/dist/utils/errors.d.ts +96 -0
  110. package/dist/utils/errors.js +132 -0
  111. package/dist/utils/http.d.ts +35 -0
  112. package/dist/utils/http.js +105 -0
  113. package/dist/utils.d.ts +14 -5
  114. package/dist/utils.js +26 -7
  115. package/dist/websocket/NordWebSocketClient.d.ts +71 -0
  116. package/dist/websocket/NordWebSocketClient.js +343 -0
  117. package/dist/websocket/client.d.ts +93 -0
  118. package/dist/websocket/client.js +222 -0
  119. package/dist/websocket/events.d.ts +19 -0
  120. package/dist/websocket/events.js +2 -0
  121. package/dist/websocket/index.d.ts +2 -0
  122. package/dist/websocket/index.js +5 -0
  123. package/dist/websocket.d.ts +55 -0
  124. package/dist/websocket.js +211 -0
  125. package/docs/assets/navigation.js +1 -1
  126. package/docs/assets/search.js +1 -1
  127. package/docs/classes/Nord.html +2 -15
  128. package/docs/classes/NordUser.html +4 -4
  129. package/docs/enums/FillMode.html +2 -2
  130. package/docs/enums/KeyType.html +2 -2
  131. package/docs/enums/PeakTpsPeriodUnit.html +2 -2
  132. package/docs/enums/Side.html +2 -2
  133. package/docs/functions/assert.html +1 -1
  134. package/docs/functions/bigIntToProtoU128.html +1 -1
  135. package/docs/functions/checkPubKeyLength.html +1 -1
  136. package/docs/functions/checkedFetch.html +1 -1
  137. package/docs/functions/decodeLengthDelimited.html +1 -1
  138. package/docs/functions/encodeLengthDelimited.html +1 -1
  139. package/docs/functions/fillModeToProtoFillMode.html +1 -1
  140. package/docs/functions/findMarket.html +1 -1
  141. package/docs/functions/findToken.html +1 -1
  142. package/docs/functions/makeWalletSignFn.html +1 -1
  143. package/docs/functions/optExpect.html +1 -1
  144. package/docs/functions/optMap.html +1 -1
  145. package/docs/functions/optUnwrap.html +1 -1
  146. package/docs/functions/panic.html +1 -1
  147. package/docs/functions/signAction.html +1 -1
  148. package/docs/functions/toScaledU128.html +1 -1
  149. package/docs/functions/toScaledU64.html +1 -1
  150. package/docs/interfaces/Account.html +2 -2
  151. package/docs/interfaces/ActionInfo.html +2 -2
  152. package/docs/interfaces/ActionQuery.html +2 -2
  153. package/docs/interfaces/ActionResponse.html +2 -2
  154. package/docs/interfaces/ActionsExtendedInfo.html +2 -2
  155. package/docs/interfaces/ActionsQuery.html +2 -2
  156. package/docs/interfaces/ActionsResponse.html +2 -2
  157. package/docs/interfaces/AggregateMetrics.html +2 -2
  158. package/docs/interfaces/BlockQuery.html +2 -2
  159. package/docs/interfaces/BlockResponse.html +2 -2
  160. package/docs/interfaces/BlockSummary.html +2 -2
  161. package/docs/interfaces/BlockSummaryResponse.html +2 -2
  162. package/docs/interfaces/DeltaEvent.html +2 -2
  163. package/docs/interfaces/ERC20TokenInfo.html +2 -2
  164. package/docs/interfaces/Info.html +2 -2
  165. package/docs/interfaces/Market.html +2 -2
  166. package/docs/interfaces/MarketStats.html +2 -2
  167. package/docs/interfaces/MarketsStatsResponse.html +2 -2
  168. package/docs/interfaces/NordConfig.html +2 -2
  169. package/docs/interfaces/Order.html +2 -2
  170. package/docs/interfaces/OrderInfo.html +2 -2
  171. package/docs/interfaces/PerpMarketStats.html +2 -2
  172. package/docs/interfaces/RollmanActionExtendedInfo.html +2 -2
  173. package/docs/interfaces/RollmanActionInfo.html +2 -2
  174. package/docs/interfaces/RollmanActionResponse.html +2 -2
  175. package/docs/interfaces/RollmanActionsResponse.html +2 -2
  176. package/docs/interfaces/RollmanBlockResponse.html +2 -2
  177. package/docs/interfaces/SubscriberConfig.html +2 -2
  178. package/docs/interfaces/Token.html +2 -2
  179. package/docs/interfaces/Trade.html +2 -2
  180. package/docs/interfaces/Trades.html +2 -2
  181. package/docs/modules.html +0 -7
  182. package/docs/types/BigIntValue.html +1 -1
  183. package/docs/variables/DEBUG_KEYS.html +1 -1
  184. package/docs/variables/DEFAULT_FUNDING_AMOUNTS.html +1 -1
  185. package/docs/variables/DEV_CONTRACT_ADDRESS.html +1 -1
  186. package/docs/variables/DEV_TOKEN_INFOS.html +1 -1
  187. package/docs/variables/DEV_URL.html +1 -1
  188. package/docs/variables/ERC20_ABI.html +1 -1
  189. package/docs/variables/EVM_DEV_URL.html +1 -1
  190. package/docs/variables/FAUCET_PRIVATE_ADDRESS.html +1 -1
  191. package/docs/variables/MAX_BUFFER_LEN.html +1 -1
  192. package/docs/variables/NORD_GETTERS_FACET_ABI.html +1 -1
  193. package/docs/variables/NORD_RAMP_FACET_ABI.html +1 -1
  194. package/docs/variables/SESSION_TTL.html +1 -1
  195. package/docs/variables/WEBSERVER_DEV_URL.html +1 -1
  196. package/docs/variables/ZERO_DECIMAL.html +1 -1
  197. package/package.json +10 -12
  198. package/src/bridge/client.ts +487 -0
  199. package/src/bridge/const.ts +53 -0
  200. package/src/bridge/index.ts +7 -0
  201. package/src/bridge/types.ts +127 -0
  202. package/src/bridge/utils.ts +140 -0
  203. package/src/const.ts +20 -25
  204. package/src/gen/common.ts +27 -10
  205. package/src/gen/nord.ts +1044 -483
  206. package/src/idl/bridge.ts +702 -0
  207. package/src/index.ts +24 -5
  208. package/src/nord/{actions.ts → api/actions.ts} +33 -37
  209. package/src/nord/api/core.ts +130 -0
  210. package/src/nord/api/market.ts +125 -0
  211. package/src/nord/api/metrics.ts +154 -0
  212. package/src/nord/api/queries.ts +236 -0
  213. package/src/nord/client/Nord.ts +652 -0
  214. package/src/nord/client/NordUser.ts +1105 -0
  215. package/src/nord/index.ts +16 -2
  216. package/src/nord/models/Subscriber.ts +57 -0
  217. package/src/nord/utils/NordError.ts +72 -0
  218. package/src/types.ts +170 -99
  219. package/src/utils.ts +40 -19
  220. package/src/websocket/NordWebSocketClient.ts +432 -0
  221. package/src/websocket/events.ts +31 -0
  222. package/src/websocket/index.ts +2 -0
  223. package/tests/utils.spec.ts +24 -24
  224. package/docs/classes/Subscriber.html +0 -6
  225. package/docs/functions/createWebSocketSubscription.html +0 -12
  226. package/docs/interfaces/OrderbookOrder.html +0 -6
  227. package/docs/interfaces/OrderbookResponse.html +0 -10
  228. package/docs/interfaces/TradeInfo.html +0 -20
  229. package/docs/interfaces/TradesQueryParams.html +0 -10
  230. package/docs/interfaces/TradesResponse.html +0 -12
  231. package/src/abis/ERC20_ABI.ts +0 -310
  232. package/src/abis/NORD_GETTERS_FACET_ABI.ts +0 -192
  233. package/src/abis/NORD_RAMP_FACET_ABI.ts +0 -141
  234. package/src/abis/index.ts +0 -3
  235. package/src/nord/Nord.ts +0 -504
  236. package/src/nord/NordImpl.ts +0 -8
  237. package/src/nord/NordUser.ts +0 -469
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as proto from "./gen/nord";
1
+ import * as proto from './gen/nord';
2
2
  /**
3
3
  * The peak TPS rate is queried over the specified period.
4
4
  * The period is specified in units of: {hour, day, week, month, year}.
@@ -15,13 +15,24 @@ export declare enum PeakTpsPeriodUnit {
15
15
  Month = "m",
16
16
  Year = "y"
17
17
  }
18
+ /**
19
+ * Configuration options for the Nord client
20
+ */
18
21
  export interface NordConfig {
19
- evmUrl: string;
22
+ /** Base URL for the Nord web server */
20
23
  webServerUrl: string;
21
- contractAddress: string;
22
- tokenInfos: ERC20TokenInfo[];
23
- }
24
- export interface ERC20TokenInfo {
24
+ /** Solana program ID */
25
+ solanaProgramId: string;
26
+ /** Solana cluster URL */
27
+ solanaUrl: string;
28
+ /** Whether to initialize WebSockets on creation, defaults to true */
29
+ initWebSockets?: boolean;
30
+ /** Initial subscriptions for the trades WebSocket (e.g., ["trades@BTCUSDC"]) */
31
+ tradesSubscriptions?: string[];
32
+ /** Initial subscriptions for the deltas WebSocket (e.g., ["deltas@BTCUSDC"]) */
33
+ deltasSubscriptions?: string[];
34
+ }
35
+ export interface TokenInfo {
25
36
  address: string;
26
37
  precision: number;
27
38
  tokenId: number;
@@ -54,17 +65,19 @@ export interface SubscriberConfig {
54
65
  maxBufferLen?: number;
55
66
  }
56
67
  export interface Market {
68
+ marketId: number;
57
69
  symbol: string;
58
- baseTokenId: number;
59
- quoteTokenId: number;
60
70
  priceDecimals: number;
61
71
  sizeDecimals: number;
72
+ baseTokenId: number;
73
+ quoteTokenId: number;
74
+ frozen: boolean;
62
75
  }
63
76
  export interface Token {
77
+ tokenId: number;
64
78
  symbol: string;
65
- ethAddr: string;
66
79
  decimals: number;
67
- tokenId: number;
80
+ mintAddr: string;
68
81
  }
69
82
  export interface Info {
70
83
  markets: Market[];
@@ -74,8 +87,8 @@ export interface DeltaEvent {
74
87
  last_update_id: number;
75
88
  update_id: number;
76
89
  market_symbol: string;
77
- asks: [number, number];
78
- bids: [number, number];
90
+ asks: OrderbookEntry[];
91
+ bids: OrderbookEntry[];
79
92
  }
80
93
  export interface Trade {
81
94
  side: Side;
@@ -92,7 +105,7 @@ export interface Trades {
92
105
  export interface OrderInfo {
93
106
  id: number;
94
107
  reduce_only: boolean;
95
- imit_price: number;
108
+ limit_price: number;
96
109
  size: number;
97
110
  account_id: number;
98
111
  }
@@ -103,7 +116,7 @@ export interface Account {
103
116
  last_update_id: number;
104
117
  update_id: number;
105
118
  account_id: number;
106
- fills: HashMap<FillMode>;
119
+ fills: HashMap<number>;
107
120
  places: HashMap<OrderInfo>;
108
121
  cancels: HashMap<OrderInfo>;
109
122
  balances: HashMap<number>;
@@ -220,79 +233,6 @@ export interface AggregateMetrics {
220
233
  tx_tps_peak: number;
221
234
  request_latency_average: number;
222
235
  }
223
- /**
224
- * Parameters for querying trades
225
- * @field {number} accountId - ID of target account
226
- * @field {string} [since] - Start with this timestamp (RFC3339); defaults to UNIX epoch start
227
- * @field {string} [until] - End with this timestamp (RFC3339); defaults to current date-time
228
- * @field {string} [pageId] - Fetch results starting with this page
229
- */
230
- export interface TradesQueryParams {
231
- accountId: number;
232
- since?: string;
233
- until?: string;
234
- pageId?: string;
235
- }
236
- /**
237
- * Trade information
238
- * @field {string} id - Trade ID
239
- * @field {string} timestamp - Trade timestamp (RFC3339)
240
- * @field {string} symbol - Market symbol
241
- * @field {string} side - Trade side (buy/sell)
242
- * @field {number} price - Trade price
243
- * @field {number} size - Trade size
244
- * @field {number} fee - Trade fee
245
- * @field {string} feeCurrency - Fee currency
246
- * @field {number} orderId - Order ID
247
- */
248
- export interface TradeInfo {
249
- id: string;
250
- timestamp: string;
251
- symbol: string;
252
- side: string;
253
- price: number;
254
- size: number;
255
- fee: number;
256
- feeCurrency: string;
257
- orderId: number;
258
- }
259
- /**
260
- * Response for trades query
261
- * @field {number} accountId - Account ID
262
- * @field {string} since - Start timestamp (RFC3339)
263
- * @field {string} until - End timestamp (RFC3339)
264
- * @field {string} [nextPageId] - ID for the next page of results
265
- * @field {TradeInfo[]} trades - Array of trades
266
- */
267
- export interface TradesResponse {
268
- accountId: number;
269
- since: string;
270
- until: string;
271
- nextPageId?: string;
272
- trades: TradeInfo[];
273
- }
274
- /**
275
- * Order in the orderbook
276
- * @field {number} price - Order price
277
- * @field {number} size - Order size
278
- */
279
- export interface OrderbookOrder {
280
- price: number;
281
- size: number;
282
- }
283
- /**
284
- * Response for orderbook query
285
- * @field {string} symbol - Market symbol
286
- * @field {number} timestamp - Orderbook timestamp
287
- * @field {OrderbookOrder[]} bids - Array of bid orders
288
- * @field {OrderbookOrder[]} asks - Array of ask orders
289
- */
290
- export interface OrderbookResponse {
291
- symbol: string;
292
- timestamp: number;
293
- bids: OrderbookOrder[];
294
- asks: OrderbookOrder[];
295
- }
296
236
  export interface RollmanBlockResponse {
297
237
  block_number: number;
298
238
  actions: RollmanActionInfo[];
@@ -340,4 +280,121 @@ export interface PerpMarketStats {
340
280
  * @throws Will throw an error if provided with an invalid fill mode.
341
281
  */
342
282
  export declare function fillModeToProtoFillMode(x: FillMode): proto.FillMode;
283
+ /**
284
+ * Response for trades query with pagination support
285
+ */
286
+ export interface TradesResponse {
287
+ trades: Trade[];
288
+ accountId: number;
289
+ since?: string;
290
+ until?: string;
291
+ nextPageId?: string;
292
+ }
293
+ /**
294
+ * Query parameters for trades endpoint
295
+ */
296
+ export interface TradesQuery {
297
+ accountId: number;
298
+ since?: string;
299
+ until?: string;
300
+ pageId?: string;
301
+ }
302
+ /**
303
+ * Response for user account IDs query
304
+ */
305
+ export interface UserAccountIdsResponse {
306
+ accountIds: number[];
307
+ }
308
+ /**
309
+ * Query parameters for user account IDs
310
+ */
311
+ export interface UserAccountIdsQuery {
312
+ pubkey: string;
313
+ }
314
+ /**
315
+ * Orderbook entry representing price and size
316
+ */
317
+ export interface OrderbookEntry {
318
+ price: number;
319
+ size: number;
320
+ }
321
+ /**
322
+ * Response for orderbook query
323
+ */
324
+ export interface OrderbookResponse {
325
+ symbol: string;
326
+ asks: OrderbookEntry[];
327
+ bids: OrderbookEntry[];
328
+ timestamp: number;
329
+ }
330
+ /**
331
+ * Query parameters for orderbook
332
+ *
333
+ * Note: While you can provide either symbol or market_id, the API endpoint only accepts market_id.
334
+ * If you provide a symbol, it will be converted to a market_id internally.
335
+ */
336
+ export interface OrderbookQuery {
337
+ symbol?: string;
338
+ market_id?: number;
339
+ }
340
+ /**
341
+ * Response for timestamp query
342
+ */
343
+ export interface TimestampResponse {
344
+ timestamp: number;
345
+ }
346
+ /**
347
+ * Response for action nonce query
348
+ */
349
+ export interface ActionNonceResponse {
350
+ nonce: number;
351
+ }
352
+ /**
353
+ * WebSocket message types
354
+ */
355
+ export declare enum WebSocketMessageType {
356
+ Subscribe = "subscribe",
357
+ Unsubscribe = "unsubscribe",
358
+ TradeUpdate = "trade",
359
+ DeltaUpdate = "delta",
360
+ UserUpdate = "user"
361
+ }
362
+ /**
363
+ * WebSocket subscription request
364
+ */
365
+ export interface WebSocketSubscription {
366
+ type: WebSocketMessageType;
367
+ streams: string[];
368
+ }
369
+ /**
370
+ * WebSocket trade update message
371
+ */
372
+ export interface WebSocketTradeUpdate {
373
+ type: WebSocketMessageType.TradeUpdate;
374
+ symbol: string;
375
+ trades: Trade[];
376
+ timestamp: number;
377
+ }
378
+ /**
379
+ * WebSocket delta update message
380
+ */
381
+ export interface WebSocketDeltaUpdate {
382
+ type: WebSocketMessageType.DeltaUpdate;
383
+ last_update_id: number;
384
+ update_id: number;
385
+ market_symbol: string;
386
+ asks: OrderbookEntry[];
387
+ bids: OrderbookEntry[];
388
+ timestamp: number;
389
+ }
390
+ /**
391
+ * WebSocket user update message
392
+ */
393
+ export interface WebSocketUserUpdate {
394
+ type: WebSocketMessageType.UserUpdate;
395
+ userId: number;
396
+ account: Account;
397
+ timestamp: number;
398
+ }
399
+ export type WebSocketMessage = WebSocketSubscription | WebSocketTradeUpdate | WebSocketDeltaUpdate | WebSocketUserUpdate;
343
400
  export {};
package/dist/types.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
36
+ exports.WebSocketMessageType = exports.FillMode = exports.Side = exports.KeyType = exports.PeakTpsPeriodUnit = void 0;
37
37
  exports.fillModeToProtoFillMode = fillModeToProtoFillMode;
38
38
  const proto = __importStar(require("./gen/nord"));
39
39
  /**
@@ -88,5 +88,16 @@ function fillModeToProtoFillMode(x) {
88
88
  }
89
89
  if (x === FillMode.FillOrKill)
90
90
  return proto.FillMode.FILL_OR_KILL;
91
- throw new Error("Invalid fill mode");
91
+ throw new Error('Invalid fill mode');
92
92
  }
93
+ /**
94
+ * WebSocket message types
95
+ */
96
+ var WebSocketMessageType;
97
+ (function (WebSocketMessageType) {
98
+ WebSocketMessageType["Subscribe"] = "subscribe";
99
+ WebSocketMessageType["Unsubscribe"] = "unsubscribe";
100
+ WebSocketMessageType["TradeUpdate"] = "trade";
101
+ WebSocketMessageType["DeltaUpdate"] = "delta";
102
+ WebSocketMessageType["UserUpdate"] = "user";
103
+ })(WebSocketMessageType || (exports.WebSocketMessageType = WebSocketMessageType = {}));
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Error handling utilities
3
+ * @module utils/errors
4
+ */
5
+ /**
6
+ * Base error class for Nord SDK
7
+ */
8
+ export declare class NordError extends Error {
9
+ /**
10
+ * Original error that caused this error
11
+ */
12
+ readonly cause?: Error;
13
+ /**
14
+ * Error code
15
+ */
16
+ readonly code?: string;
17
+ /**
18
+ * Create a new Nord error
19
+ *
20
+ * @param message - Error message
21
+ * @param options - Error options
22
+ */
23
+ constructor(message: string, options?: {
24
+ cause?: Error;
25
+ code?: string;
26
+ });
27
+ }
28
+ /**
29
+ * Error class for API errors
30
+ */
31
+ export declare class NordApiError extends NordError {
32
+ /**
33
+ * HTTP status code
34
+ */
35
+ readonly statusCode: number;
36
+ /**
37
+ * API endpoint
38
+ */
39
+ readonly endpoint: string;
40
+ /**
41
+ * Create a new API error
42
+ *
43
+ * @param message - Error message
44
+ * @param statusCode - HTTP status code
45
+ * @param endpoint - API endpoint
46
+ * @param cause - Original error
47
+ */
48
+ constructor(message: string, statusCode: number, endpoint: string, cause?: Error);
49
+ }
50
+ /**
51
+ * Error class for validation errors
52
+ */
53
+ export declare class NordValidationError extends NordError {
54
+ /**
55
+ * Field that failed validation
56
+ */
57
+ readonly field: string;
58
+ /**
59
+ * Create a new validation error
60
+ *
61
+ * @param message - Error message
62
+ * @param field - Field that failed validation
63
+ */
64
+ constructor(message: string, field: string);
65
+ }
66
+ /**
67
+ * Error class for WebSocket errors
68
+ */
69
+ export declare class NordWebSocketError extends NordError {
70
+ /**
71
+ * Create a new WebSocket error
72
+ *
73
+ * @param message - Error message
74
+ * @param cause - Original error
75
+ */
76
+ constructor(message: string, cause?: Error);
77
+ }
78
+ /**
79
+ * Error class for authentication errors
80
+ */
81
+ export declare class NordAuthError extends NordError {
82
+ /**
83
+ * Create a new authentication error
84
+ *
85
+ * @param message - Error message
86
+ * @param cause - Original error
87
+ */
88
+ constructor(message: string, cause?: Error);
89
+ }
90
+ /**
91
+ * Format an error for logging
92
+ *
93
+ * @param error - Error to format
94
+ * @returns Formatted error string
95
+ */
96
+ export declare function formatError(error: unknown): string;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ /**
3
+ * Error handling utilities
4
+ * @module utils/errors
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.NordAuthError = exports.NordWebSocketError = exports.NordValidationError = exports.NordApiError = exports.NordError = void 0;
8
+ exports.formatError = formatError;
9
+ /**
10
+ * Base error class for Nord SDK
11
+ */
12
+ class NordError extends Error {
13
+ /**
14
+ * Create a new Nord error
15
+ *
16
+ * @param message - Error message
17
+ * @param options - Error options
18
+ */
19
+ constructor(message, options) {
20
+ super(message);
21
+ this.name = 'NordError';
22
+ if (options?.cause) {
23
+ this.cause = options.cause;
24
+ }
25
+ if (options?.code) {
26
+ this.code = options.code;
27
+ }
28
+ // Ensure prototype chain is properly set up
29
+ Object.setPrototypeOf(this, NordError.prototype);
30
+ }
31
+ }
32
+ exports.NordError = NordError;
33
+ /**
34
+ * Error class for API errors
35
+ */
36
+ class NordApiError extends NordError {
37
+ /**
38
+ * Create a new API error
39
+ *
40
+ * @param message - Error message
41
+ * @param statusCode - HTTP status code
42
+ * @param endpoint - API endpoint
43
+ * @param cause - Original error
44
+ */
45
+ constructor(message, statusCode, endpoint, cause) {
46
+ super(message, { cause });
47
+ this.name = 'NordApiError';
48
+ this.statusCode = statusCode;
49
+ this.endpoint = endpoint;
50
+ // Ensure prototype chain is properly set up
51
+ Object.setPrototypeOf(this, NordApiError.prototype);
52
+ }
53
+ }
54
+ exports.NordApiError = NordApiError;
55
+ /**
56
+ * Error class for validation errors
57
+ */
58
+ class NordValidationError extends NordError {
59
+ /**
60
+ * Create a new validation error
61
+ *
62
+ * @param message - Error message
63
+ * @param field - Field that failed validation
64
+ */
65
+ constructor(message, field) {
66
+ super(message);
67
+ this.name = 'NordValidationError';
68
+ this.field = field;
69
+ // Ensure prototype chain is properly set up
70
+ Object.setPrototypeOf(this, NordValidationError.prototype);
71
+ }
72
+ }
73
+ exports.NordValidationError = NordValidationError;
74
+ /**
75
+ * Error class for WebSocket errors
76
+ */
77
+ class NordWebSocketError extends NordError {
78
+ /**
79
+ * Create a new WebSocket error
80
+ *
81
+ * @param message - Error message
82
+ * @param cause - Original error
83
+ */
84
+ constructor(message, cause) {
85
+ super(message, { cause });
86
+ this.name = 'NordWebSocketError';
87
+ // Ensure prototype chain is properly set up
88
+ Object.setPrototypeOf(this, NordWebSocketError.prototype);
89
+ }
90
+ }
91
+ exports.NordWebSocketError = NordWebSocketError;
92
+ /**
93
+ * Error class for authentication errors
94
+ */
95
+ class NordAuthError extends NordError {
96
+ /**
97
+ * Create a new authentication error
98
+ *
99
+ * @param message - Error message
100
+ * @param cause - Original error
101
+ */
102
+ constructor(message, cause) {
103
+ super(message, { cause });
104
+ this.name = 'NordAuthError';
105
+ // Ensure prototype chain is properly set up
106
+ Object.setPrototypeOf(this, NordAuthError.prototype);
107
+ }
108
+ }
109
+ exports.NordAuthError = NordAuthError;
110
+ /**
111
+ * Format an error for logging
112
+ *
113
+ * @param error - Error to format
114
+ * @returns Formatted error string
115
+ */
116
+ function formatError(error) {
117
+ if (error instanceof NordApiError) {
118
+ return `API Error (${error.statusCode}) for ${error.endpoint}: ${error.message}`;
119
+ }
120
+ else if (error instanceof NordValidationError) {
121
+ return `Validation Error for field '${error.field}': ${error.message}`;
122
+ }
123
+ else if (error instanceof NordError) {
124
+ return `Nord Error: ${error.message}`;
125
+ }
126
+ else if (error instanceof Error) {
127
+ return `Error: ${error.message}`;
128
+ }
129
+ else {
130
+ return `Unknown error: ${String(error)}`;
131
+ }
132
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * HTTP utilities for making API requests
3
+ * @module utils/http
4
+ */
5
+ /**
6
+ * Make a GET request to the API
7
+ *
8
+ * @param baseUrl - Base URL for the API
9
+ * @param endpoint - API endpoint
10
+ * @param headers - Additional headers (optional)
11
+ * @returns Promise resolving to the response data
12
+ * @throws {NordApiError} If the request fails
13
+ */
14
+ export declare function httpGet<T>(baseUrl: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
15
+ /**
16
+ * Make a POST request to the API
17
+ *
18
+ * @param baseUrl - Base URL for the API
19
+ * @param endpoint - API endpoint
20
+ * @param data - Request data
21
+ * @param headers - Additional headers (optional)
22
+ * @returns Promise resolving to the response data
23
+ * @throws {NordApiError} If the request fails
24
+ */
25
+ export declare function httpPost<T>(baseUrl: string, endpoint: string, data: any, headers?: Record<string, string>): Promise<T>;
26
+ /**
27
+ * Make a DELETE request to the API
28
+ *
29
+ * @param baseUrl - Base URL for the API
30
+ * @param endpoint - API endpoint
31
+ * @param headers - Additional headers (optional)
32
+ * @returns Promise resolving to the response data
33
+ * @throws {NordApiError} If the request fails
34
+ */
35
+ export declare function httpDelete<T>(baseUrl: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP utilities for making API requests
4
+ * @module utils/http
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.httpGet = httpGet;
8
+ exports.httpPost = httpPost;
9
+ exports.httpDelete = httpDelete;
10
+ const errors_1 = require("./errors");
11
+ /**
12
+ * Make a GET request to the API
13
+ *
14
+ * @param baseUrl - Base URL for the API
15
+ * @param endpoint - API endpoint
16
+ * @param headers - Additional headers (optional)
17
+ * @returns Promise resolving to the response data
18
+ * @throws {NordApiError} If the request fails
19
+ */
20
+ async function httpGet(baseUrl, endpoint, headers = {}) {
21
+ const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
22
+ try {
23
+ const response = await fetch(url, {
24
+ method: 'GET',
25
+ headers: {
26
+ 'Content-Type': 'application/json',
27
+ ...headers,
28
+ },
29
+ });
30
+ if (!response.ok) {
31
+ throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
32
+ }
33
+ return await response.json();
34
+ }
35
+ catch (error) {
36
+ if (error instanceof errors_1.NordApiError) {
37
+ throw error;
38
+ }
39
+ throw new errors_1.NordApiError(`Failed to make GET request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
40
+ }
41
+ }
42
+ /**
43
+ * Make a POST request to the API
44
+ *
45
+ * @param baseUrl - Base URL for the API
46
+ * @param endpoint - API endpoint
47
+ * @param data - Request data
48
+ * @param headers - Additional headers (optional)
49
+ * @returns Promise resolving to the response data
50
+ * @throws {NordApiError} If the request fails
51
+ */
52
+ async function httpPost(baseUrl, endpoint, data, headers = {}) {
53
+ const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
54
+ try {
55
+ const response = await fetch(url, {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-Type': 'application/json',
59
+ ...headers,
60
+ },
61
+ body: JSON.stringify(data),
62
+ });
63
+ if (!response.ok) {
64
+ throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
65
+ }
66
+ return await response.json();
67
+ }
68
+ catch (error) {
69
+ if (error instanceof errors_1.NordApiError) {
70
+ throw error;
71
+ }
72
+ throw new errors_1.NordApiError(`Failed to make POST request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
73
+ }
74
+ }
75
+ /**
76
+ * Make a DELETE request to the API
77
+ *
78
+ * @param baseUrl - Base URL for the API
79
+ * @param endpoint - API endpoint
80
+ * @param headers - Additional headers (optional)
81
+ * @returns Promise resolving to the response data
82
+ * @throws {NordApiError} If the request fails
83
+ */
84
+ async function httpDelete(baseUrl, endpoint, headers = {}) {
85
+ const url = `${baseUrl}${endpoint.startsWith('/') ? '' : '/'}${endpoint}`;
86
+ try {
87
+ const response = await fetch(url, {
88
+ method: 'DELETE',
89
+ headers: {
90
+ 'Content-Type': 'application/json',
91
+ ...headers,
92
+ },
93
+ });
94
+ if (!response.ok) {
95
+ throw new errors_1.NordApiError(`HTTP error ${response.status}: ${response.statusText}`, response.status, endpoint);
96
+ }
97
+ return await response.json();
98
+ }
99
+ catch (error) {
100
+ if (error instanceof errors_1.NordApiError) {
101
+ throw error;
102
+ }
103
+ throw new errors_1.NordApiError(`Failed to make DELETE request to ${endpoint}: ${error instanceof Error ? error.message : String(error)}`, 500, endpoint, error instanceof Error ? error : undefined);
104
+ }
105
+ }