wapi-client 0.10.2 → 0.10.6

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 (61) hide show
  1. package/dist/api/base-client.browser.cjs +27 -8
  2. package/dist/api/base-client.browser.js +28 -9
  3. package/dist/api/base-client.cjs +27 -8
  4. package/dist/api/base-client.d.ts +6 -2
  5. package/dist/api/base-client.js +28 -9
  6. package/dist/api/http-client.browser.cjs +47 -21
  7. package/dist/api/http-client.browser.js +47 -21
  8. package/dist/api/http-client.cjs +47 -21
  9. package/dist/api/http-client.d.ts +2 -2
  10. package/dist/api/http-client.js +47 -21
  11. package/dist/api/index.d.ts +4 -0
  12. package/dist/api/ws-client.browser.cjs +26 -10
  13. package/dist/api/ws-client.browser.js +27 -11
  14. package/dist/api/ws-client.cjs +27 -11
  15. package/dist/api/ws-client.d.ts +5 -4
  16. package/dist/api/ws-client.js +28 -12
  17. package/dist/client.browser.cjs +90 -17
  18. package/dist/client.browser.js +91 -18
  19. package/dist/client.cjs +91 -18
  20. package/dist/client.d.ts +53 -5
  21. package/dist/client.js +92 -19
  22. package/dist/fns/list-exports/list-exports.browser.cjs +4 -7
  23. package/dist/fns/list-exports/list-exports.browser.js +9 -8
  24. package/dist/fns/list-exports/list-exports.cjs +4 -7
  25. package/dist/fns/list-exports/list-exports.enums.d.ts +9 -4
  26. package/dist/fns/list-exports/list-exports.js +9 -8
  27. package/dist/fns/list-exports/list-exports.schema.input.json +20 -2
  28. package/dist/fns/update-transfer/update-transfer.browser.cjs +2 -1
  29. package/dist/fns/update-transfer/update-transfer.browser.js +2 -1
  30. package/dist/fns/update-transfer/update-transfer.cjs +2 -1
  31. package/dist/fns/update-transfer/update-transfer.enums.d.ts +6 -0
  32. package/dist/fns/update-transfer/update-transfer.js +2 -1
  33. package/dist/fns/update-transfer/update-transfer.schema.input.json +3 -0
  34. package/dist/index.browser.cjs +3 -0
  35. package/dist/index.browser.js +3 -0
  36. package/dist/index.cjs +3 -0
  37. package/dist/index.d.ts +23 -5
  38. package/dist/index.js +3 -0
  39. package/dist/lib/errors.browser.cjs +21 -1
  40. package/dist/lib/errors.browser.js +21 -1
  41. package/dist/lib/errors.cjs +21 -1
  42. package/dist/lib/errors.d.ts +180 -109
  43. package/dist/lib/errors.js +21 -1
  44. package/dist/lib/utils.browser.cjs +24 -0
  45. package/dist/lib/utils.browser.js +24 -0
  46. package/dist/lib/utils.cjs +27 -0
  47. package/dist/lib/utils.d.ts +6 -0
  48. package/dist/lib/utils.js +24 -0
  49. package/dist/lib/validator.browser.cjs +3 -0
  50. package/dist/lib/validator.browser.js +4 -1
  51. package/dist/lib/validator.cjs +3 -0
  52. package/dist/lib/validator.js +4 -1
  53. package/dist/txs/get-export/get-export.enums.d.ts +2 -1
  54. package/dist/txs/get-export/get-export.schema.output.json +13 -2
  55. package/dist/txs/list-export-many/list-export-many.enums.d.ts +5 -5
  56. package/dist/txs/list-export-many/list-export-many.schema.input.json +5 -4
  57. package/dist/txs/update-transfer/update-transfer.schema.input.json +0 -4
  58. package/dist/types/index.d.ts +301 -137
  59. package/dist/wapi-client-web.iife.js +6 -6
  60. package/dist/wapi-client.iife.js +6 -6
  61. package/package.json +1 -1
@@ -83,7 +83,7 @@ var BaseClient = class {
83
83
  );
84
84
  this._requests = /* @__PURE__ */ new Map();
85
85
  this._error = false;
86
- this._sending = /* @__PURE__ */ new Set();
86
+ this._sending = /* @__PURE__ */ new Map();
87
87
  this.type = connectionType;
88
88
  this._connection = connection;
89
89
  this.connectionType = connectionType;
@@ -135,7 +135,7 @@ var BaseClient = class {
135
135
  this.socId = void 0;
136
136
  }
137
137
  _handleMessage(incoming) {
138
- var _a, _b, _c;
138
+ var _a, _b, _c, _d;
139
139
  if (this.hooks.message) {
140
140
  this.hooks.message(incoming);
141
141
  }
@@ -161,6 +161,7 @@ var BaseClient = class {
161
161
  return;
162
162
  }
163
163
  if (responseMessage.result === import_jsonrpc.JSONRPC.acknowledgement) {
164
+ clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
164
165
  this._sending.delete(responseMessage.id);
165
166
  return;
166
167
  }
@@ -178,16 +179,16 @@ var BaseClient = class {
178
179
  requestInfo.error(responseMessage.error);
179
180
  }
180
181
  const message = responseMessage;
181
- if (((_a = message.result) == null ? void 0 : _a.type) === import_jsonrpc.JSONRPC.streamPause && "pause" in requestInfo) {
182
+ if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc.JSONRPC.streamPause && "pause" in requestInfo) {
182
183
  requestInfo.pause();
183
184
  return;
184
185
  }
185
- if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc.JSONRPC.streamResume && "resume" in requestInfo) {
186
+ if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc.JSONRPC.streamResume && "resume" in requestInfo) {
186
187
  requestInfo.resume();
187
188
  return;
188
189
  }
189
190
  const { stream, start } = requestInfo;
190
- if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc.JSONRPC.streamChunk) {
191
+ if (((_d = message.result) == null ? void 0 : _d.type) === import_jsonrpc.JSONRPC.streamChunk) {
191
192
  stream.push(message.result);
192
193
  return;
193
194
  }
@@ -212,6 +213,19 @@ var BaseClient = class {
212
213
  }
213
214
  return this._sendRaw(name, inputCopy);
214
215
  }
216
+ _setSending(jsonRpcMessage, stream) {
217
+ this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
218
+ timeout: setTimeout(() => {
219
+ this._sending.delete(jsonRpcMessage.id);
220
+ stream.push({
221
+ error: new import_errors.ConfigError("SENDING_TIMEOUT", {
222
+ timeout: this.sendingTimeout
223
+ }).toJSON()
224
+ });
225
+ this._requests.delete(jsonRpcMessage.id);
226
+ }, this.sendingTimeout)
227
+ }));
228
+ }
215
229
  _sendRaw(method, params) {
216
230
  const jsonRpcMessage = {
217
231
  jsonrpc: import_jsonrpc.JSONRPC.version,
@@ -236,7 +250,7 @@ var BaseClient = class {
236
250
  stream,
237
251
  start: Date.now()
238
252
  });
239
- this._sending.add(jsonRpcMessage.id);
253
+ this._setSending(jsonRpcMessage, stream);
240
254
  this._send(jsonRpcMessage);
241
255
  }));
242
256
  }
@@ -245,6 +259,7 @@ var BaseClient = class {
245
259
  const streamId = (0, import_utils.getRandomHex)();
246
260
  let _error;
247
261
  const sendToStream = ({
262
+ stream,
248
263
  method,
249
264
  params
250
265
  }) => {
@@ -259,7 +274,7 @@ var BaseClient = class {
259
274
  }, params),
260
275
  id: (0, import_utils.getRandomHex)()
261
276
  };
262
- this._sending.add(streamMessage.id);
277
+ this._setSending(streamMessage, stream);
263
278
  this._send(streamMessage);
264
279
  };
265
280
  const sendErrorToStream = (stream, error) => {
@@ -267,6 +282,7 @@ var BaseClient = class {
267
282
  return;
268
283
  }
269
284
  sendToStream({
285
+ stream,
270
286
  method: "streamError",
271
287
  params: {
272
288
  error
@@ -343,6 +359,7 @@ var BaseClient = class {
343
359
  return;
344
360
  }
345
361
  sendToStream({
362
+ stream,
346
363
  method: "streamData",
347
364
  params: {
348
365
  data: chunk
@@ -357,6 +374,7 @@ var BaseClient = class {
357
374
  timeout = null;
358
375
  }
359
376
  sendToStream({
377
+ stream,
360
378
  method: "streamError",
361
379
  params: {
362
380
  error
@@ -374,13 +392,14 @@ var BaseClient = class {
374
392
  timeout = null;
375
393
  }
376
394
  sendToStream({
395
+ stream,
377
396
  method: "streamEnd",
378
397
  params: {}
379
398
  });
380
399
  });
381
400
  }
382
401
  });
383
- this._sending.add(streamStartMessage.id);
402
+ this._setSending(streamStartMessage, stream);
384
403
  this._send(streamStartMessage);
385
404
  }), inputStream);
386
405
  }
@@ -37,7 +37,7 @@ var __async = (__this, __arguments, generator) => {
37
37
 
38
38
  // src/api/base-client.ts
39
39
  import { debugLog } from "../lib/debug.browser.js";
40
- import { StreamError, ValidationError } from "../lib/errors.browser.js";
40
+ import { ConfigError, StreamError, ValidationError } from "../lib/errors.browser.js";
41
41
  import { StreamPromise } from "../lib/stream-promise.browser.js";
42
42
  import { StreamPromiseInput } from "../lib/stream-promise-input.browser.js";
43
43
  import {
@@ -70,7 +70,7 @@ var BaseClient = class {
70
70
  );
71
71
  this._requests = /* @__PURE__ */ new Map();
72
72
  this._error = false;
73
- this._sending = /* @__PURE__ */ new Set();
73
+ this._sending = /* @__PURE__ */ new Map();
74
74
  this.type = connectionType;
75
75
  this._connection = connection;
76
76
  this.connectionType = connectionType;
@@ -122,7 +122,7 @@ var BaseClient = class {
122
122
  this.socId = void 0;
123
123
  }
124
124
  _handleMessage(incoming) {
125
- var _a, _b, _c;
125
+ var _a, _b, _c, _d;
126
126
  if (this.hooks.message) {
127
127
  this.hooks.message(incoming);
128
128
  }
@@ -148,6 +148,7 @@ var BaseClient = class {
148
148
  return;
149
149
  }
150
150
  if (responseMessage.result === JSONRPC.acknowledgement) {
151
+ clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
151
152
  this._sending.delete(responseMessage.id);
152
153
  return;
153
154
  }
@@ -165,16 +166,16 @@ var BaseClient = class {
165
166
  requestInfo.error(responseMessage.error);
166
167
  }
167
168
  const message = responseMessage;
168
- if (((_a = message.result) == null ? void 0 : _a.type) === JSONRPC.streamPause && "pause" in requestInfo) {
169
+ if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamPause && "pause" in requestInfo) {
169
170
  requestInfo.pause();
170
171
  return;
171
172
  }
172
- if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamResume && "resume" in requestInfo) {
173
+ if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamResume && "resume" in requestInfo) {
173
174
  requestInfo.resume();
174
175
  return;
175
176
  }
176
177
  const { stream, start } = requestInfo;
177
- if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamChunk) {
178
+ if (((_d = message.result) == null ? void 0 : _d.type) === JSONRPC.streamChunk) {
178
179
  stream.push(message.result);
179
180
  return;
180
181
  }
@@ -199,6 +200,19 @@ var BaseClient = class {
199
200
  }
200
201
  return this._sendRaw(name, inputCopy);
201
202
  }
203
+ _setSending(jsonRpcMessage, stream) {
204
+ this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
205
+ timeout: setTimeout(() => {
206
+ this._sending.delete(jsonRpcMessage.id);
207
+ stream.push({
208
+ error: new ConfigError("SENDING_TIMEOUT", {
209
+ timeout: this.sendingTimeout
210
+ }).toJSON()
211
+ });
212
+ this._requests.delete(jsonRpcMessage.id);
213
+ }, this.sendingTimeout)
214
+ }));
215
+ }
202
216
  _sendRaw(method, params) {
203
217
  const jsonRpcMessage = {
204
218
  jsonrpc: JSONRPC.version,
@@ -223,7 +237,7 @@ var BaseClient = class {
223
237
  stream,
224
238
  start: Date.now()
225
239
  });
226
- this._sending.add(jsonRpcMessage.id);
240
+ this._setSending(jsonRpcMessage, stream);
227
241
  this._send(jsonRpcMessage);
228
242
  }));
229
243
  }
@@ -232,6 +246,7 @@ var BaseClient = class {
232
246
  const streamId = getRandomHex();
233
247
  let _error;
234
248
  const sendToStream = ({
249
+ stream,
235
250
  method,
236
251
  params
237
252
  }) => {
@@ -246,7 +261,7 @@ var BaseClient = class {
246
261
  }, params),
247
262
  id: getRandomHex()
248
263
  };
249
- this._sending.add(streamMessage.id);
264
+ this._setSending(streamMessage, stream);
250
265
  this._send(streamMessage);
251
266
  };
252
267
  const sendErrorToStream = (stream, error) => {
@@ -254,6 +269,7 @@ var BaseClient = class {
254
269
  return;
255
270
  }
256
271
  sendToStream({
272
+ stream,
257
273
  method: "streamError",
258
274
  params: {
259
275
  error
@@ -330,6 +346,7 @@ var BaseClient = class {
330
346
  return;
331
347
  }
332
348
  sendToStream({
349
+ stream,
333
350
  method: "streamData",
334
351
  params: {
335
352
  data: chunk
@@ -344,6 +361,7 @@ var BaseClient = class {
344
361
  timeout = null;
345
362
  }
346
363
  sendToStream({
364
+ stream,
347
365
  method: "streamError",
348
366
  params: {
349
367
  error
@@ -361,13 +379,14 @@ var BaseClient = class {
361
379
  timeout = null;
362
380
  }
363
381
  sendToStream({
382
+ stream,
364
383
  method: "streamEnd",
365
384
  params: {}
366
385
  });
367
386
  });
368
387
  }
369
388
  });
370
- this._sending.add(streamStartMessage.id);
389
+ this._setSending(streamStartMessage, stream);
371
390
  this._send(streamStartMessage);
372
391
  }), inputStream);
373
392
  }
@@ -83,7 +83,7 @@ var BaseClient = class {
83
83
  );
84
84
  this._requests = /* @__PURE__ */ new Map();
85
85
  this._error = false;
86
- this._sending = /* @__PURE__ */ new Set();
86
+ this._sending = /* @__PURE__ */ new Map();
87
87
  this.type = connectionType;
88
88
  this._connection = connection;
89
89
  this.connectionType = connectionType;
@@ -135,7 +135,7 @@ var BaseClient = class {
135
135
  this.socId = void 0;
136
136
  }
137
137
  _handleMessage(incoming) {
138
- var _a, _b, _c;
138
+ var _a, _b, _c, _d;
139
139
  if (this.hooks.message) {
140
140
  this.hooks.message(incoming);
141
141
  }
@@ -161,6 +161,7 @@ var BaseClient = class {
161
161
  return;
162
162
  }
163
163
  if (responseMessage.result === import_jsonrpc.JSONRPC.acknowledgement) {
164
+ clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
164
165
  this._sending.delete(responseMessage.id);
165
166
  return;
166
167
  }
@@ -178,16 +179,16 @@ var BaseClient = class {
178
179
  requestInfo.error(responseMessage.error);
179
180
  }
180
181
  const message = responseMessage;
181
- if (((_a = message.result) == null ? void 0 : _a.type) === import_jsonrpc.JSONRPC.streamPause && "pause" in requestInfo) {
182
+ if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc.JSONRPC.streamPause && "pause" in requestInfo) {
182
183
  requestInfo.pause();
183
184
  return;
184
185
  }
185
- if (((_b = message.result) == null ? void 0 : _b.type) === import_jsonrpc.JSONRPC.streamResume && "resume" in requestInfo) {
186
+ if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc.JSONRPC.streamResume && "resume" in requestInfo) {
186
187
  requestInfo.resume();
187
188
  return;
188
189
  }
189
190
  const { stream, start } = requestInfo;
190
- if (((_c = message.result) == null ? void 0 : _c.type) === import_jsonrpc.JSONRPC.streamChunk) {
191
+ if (((_d = message.result) == null ? void 0 : _d.type) === import_jsonrpc.JSONRPC.streamChunk) {
191
192
  stream.push(message.result);
192
193
  return;
193
194
  }
@@ -212,6 +213,19 @@ var BaseClient = class {
212
213
  }
213
214
  return this._sendRaw(name, inputCopy);
214
215
  }
216
+ _setSending(jsonRpcMessage, stream) {
217
+ this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
218
+ timeout: setTimeout(() => {
219
+ this._sending.delete(jsonRpcMessage.id);
220
+ stream.push({
221
+ error: new import_errors.ConfigError("SENDING_TIMEOUT", {
222
+ timeout: this.sendingTimeout
223
+ }).toJSON()
224
+ });
225
+ this._requests.delete(jsonRpcMessage.id);
226
+ }, this.sendingTimeout)
227
+ }));
228
+ }
215
229
  _sendRaw(method, params) {
216
230
  const jsonRpcMessage = {
217
231
  jsonrpc: import_jsonrpc.JSONRPC.version,
@@ -236,7 +250,7 @@ var BaseClient = class {
236
250
  stream,
237
251
  start: Date.now()
238
252
  });
239
- this._sending.add(jsonRpcMessage.id);
253
+ this._setSending(jsonRpcMessage, stream);
240
254
  this._send(jsonRpcMessage);
241
255
  }));
242
256
  }
@@ -245,6 +259,7 @@ var BaseClient = class {
245
259
  const streamId = (0, import_utils.getRandomHex)();
246
260
  let _error;
247
261
  const sendToStream = ({
262
+ stream,
248
263
  method,
249
264
  params
250
265
  }) => {
@@ -259,7 +274,7 @@ var BaseClient = class {
259
274
  }, params),
260
275
  id: (0, import_utils.getRandomHex)()
261
276
  };
262
- this._sending.add(streamMessage.id);
277
+ this._setSending(streamMessage, stream);
263
278
  this._send(streamMessage);
264
279
  };
265
280
  const sendErrorToStream = (stream, error) => {
@@ -267,6 +282,7 @@ var BaseClient = class {
267
282
  return;
268
283
  }
269
284
  sendToStream({
285
+ stream,
270
286
  method: "streamError",
271
287
  params: {
272
288
  error
@@ -343,6 +359,7 @@ var BaseClient = class {
343
359
  return;
344
360
  }
345
361
  sendToStream({
362
+ stream,
346
363
  method: "streamData",
347
364
  params: {
348
365
  data: chunk
@@ -357,6 +374,7 @@ var BaseClient = class {
357
374
  timeout = null;
358
375
  }
359
376
  sendToStream({
377
+ stream,
360
378
  method: "streamError",
361
379
  params: {
362
380
  error
@@ -374,13 +392,14 @@ var BaseClient = class {
374
392
  timeout = null;
375
393
  }
376
394
  sendToStream({
395
+ stream,
377
396
  method: "streamEnd",
378
397
  params: {}
379
398
  });
380
399
  });
381
400
  }
382
401
  });
383
- this._sending.add(streamStartMessage.id);
402
+ this._setSending(streamStartMessage, stream);
384
403
  this._send(streamStartMessage);
385
404
  }), inputStream);
386
405
  }
@@ -70,14 +70,17 @@ export declare class BaseClient {
70
70
  protected _connection: WebSocket | HttpConnectionClient;
71
71
  $connect: Promise<ISocketId> | Promise<undefined> | undefined;
72
72
  connectionType: WapiClientType;
73
- host: string;
74
73
  protected jwt: string;
74
+ host: string;
75
75
  isConnected: boolean;
76
76
  socId: undefined | string;
77
77
  hooks: ClientHooks;
78
78
  private _requests;
79
79
  private _error;
80
- protected _sending: Set<string | number>;
80
+ protected _sending: Map<string | number, {
81
+ timeout?: ReturnType<typeof setTimeout>;
82
+ }>;
83
+ sendingTimeout: number | undefined;
81
84
  constructor(connection: WebSocket | HttpConnectionClient, connectionType: WapiClientType, $connect?: Promise<ISocketId>);
82
85
  protected _setConnected(value: boolean): void;
83
86
  protected _setErrored(err: Error): void;
@@ -88,6 +91,7 @@ export declare class BaseClient {
88
91
  protected _connectionLost(): void;
89
92
  protected _handleMessage(incoming: JSONRPCResponse | JSONRPCRequest): void;
90
93
  private _sendTransaction;
94
+ private _setSending;
91
95
  _sendRaw<Input, Output>(method: string, params: Input): StreamPromise<Output>;
92
96
  private _streamTransaction;
93
97
  /**
@@ -37,7 +37,7 @@ var __async = (__this, __arguments, generator) => {
37
37
 
38
38
  // src/api/base-client.ts
39
39
  import { debugLog } from "../lib/debug";
40
- import { StreamError, ValidationError } from "../lib/errors";
40
+ import { ConfigError, StreamError, ValidationError } from "../lib/errors";
41
41
  import { StreamPromise } from "../lib/stream-promise";
42
42
  import { StreamPromiseInput } from "../lib/stream-promise-input";
43
43
  import {
@@ -70,7 +70,7 @@ var BaseClient = class {
70
70
  );
71
71
  this._requests = /* @__PURE__ */ new Map();
72
72
  this._error = false;
73
- this._sending = /* @__PURE__ */ new Set();
73
+ this._sending = /* @__PURE__ */ new Map();
74
74
  this.type = connectionType;
75
75
  this._connection = connection;
76
76
  this.connectionType = connectionType;
@@ -122,7 +122,7 @@ var BaseClient = class {
122
122
  this.socId = void 0;
123
123
  }
124
124
  _handleMessage(incoming) {
125
- var _a, _b, _c;
125
+ var _a, _b, _c, _d;
126
126
  if (this.hooks.message) {
127
127
  this.hooks.message(incoming);
128
128
  }
@@ -148,6 +148,7 @@ var BaseClient = class {
148
148
  return;
149
149
  }
150
150
  if (responseMessage.result === JSONRPC.acknowledgement) {
151
+ clearTimeout((_a = this._sending.get(responseMessage.id)) == null ? void 0 : _a.timeout);
151
152
  this._sending.delete(responseMessage.id);
152
153
  return;
153
154
  }
@@ -165,16 +166,16 @@ var BaseClient = class {
165
166
  requestInfo.error(responseMessage.error);
166
167
  }
167
168
  const message = responseMessage;
168
- if (((_a = message.result) == null ? void 0 : _a.type) === JSONRPC.streamPause && "pause" in requestInfo) {
169
+ if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamPause && "pause" in requestInfo) {
169
170
  requestInfo.pause();
170
171
  return;
171
172
  }
172
- if (((_b = message.result) == null ? void 0 : _b.type) === JSONRPC.streamResume && "resume" in requestInfo) {
173
+ if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamResume && "resume" in requestInfo) {
173
174
  requestInfo.resume();
174
175
  return;
175
176
  }
176
177
  const { stream, start } = requestInfo;
177
- if (((_c = message.result) == null ? void 0 : _c.type) === JSONRPC.streamChunk) {
178
+ if (((_d = message.result) == null ? void 0 : _d.type) === JSONRPC.streamChunk) {
178
179
  stream.push(message.result);
179
180
  return;
180
181
  }
@@ -199,6 +200,19 @@ var BaseClient = class {
199
200
  }
200
201
  return this._sendRaw(name, inputCopy);
201
202
  }
203
+ _setSending(jsonRpcMessage, stream) {
204
+ this._sending.set(jsonRpcMessage.id, __spreadValues({}, this.sendingTimeout && {
205
+ timeout: setTimeout(() => {
206
+ this._sending.delete(jsonRpcMessage.id);
207
+ stream.push({
208
+ error: new ConfigError("SENDING_TIMEOUT", {
209
+ timeout: this.sendingTimeout
210
+ }).toJSON()
211
+ });
212
+ this._requests.delete(jsonRpcMessage.id);
213
+ }, this.sendingTimeout)
214
+ }));
215
+ }
202
216
  _sendRaw(method, params) {
203
217
  const jsonRpcMessage = {
204
218
  jsonrpc: JSONRPC.version,
@@ -223,7 +237,7 @@ var BaseClient = class {
223
237
  stream,
224
238
  start: Date.now()
225
239
  });
226
- this._sending.add(jsonRpcMessage.id);
240
+ this._setSending(jsonRpcMessage, stream);
227
241
  this._send(jsonRpcMessage);
228
242
  }));
229
243
  }
@@ -232,6 +246,7 @@ var BaseClient = class {
232
246
  const streamId = getRandomHex();
233
247
  let _error;
234
248
  const sendToStream = ({
249
+ stream,
235
250
  method,
236
251
  params
237
252
  }) => {
@@ -246,7 +261,7 @@ var BaseClient = class {
246
261
  }, params),
247
262
  id: getRandomHex()
248
263
  };
249
- this._sending.add(streamMessage.id);
264
+ this._setSending(streamMessage, stream);
250
265
  this._send(streamMessage);
251
266
  };
252
267
  const sendErrorToStream = (stream, error) => {
@@ -254,6 +269,7 @@ var BaseClient = class {
254
269
  return;
255
270
  }
256
271
  sendToStream({
272
+ stream,
257
273
  method: "streamError",
258
274
  params: {
259
275
  error
@@ -330,6 +346,7 @@ var BaseClient = class {
330
346
  return;
331
347
  }
332
348
  sendToStream({
349
+ stream,
333
350
  method: "streamData",
334
351
  params: {
335
352
  data: chunk
@@ -344,6 +361,7 @@ var BaseClient = class {
344
361
  timeout = null;
345
362
  }
346
363
  sendToStream({
364
+ stream,
347
365
  method: "streamError",
348
366
  params: {
349
367
  error
@@ -361,13 +379,14 @@ var BaseClient = class {
361
379
  timeout = null;
362
380
  }
363
381
  sendToStream({
382
+ stream,
364
383
  method: "streamEnd",
365
384
  params: {}
366
385
  });
367
386
  });
368
387
  }
369
388
  });
370
- this._sending.add(streamStartMessage.id);
389
+ this._setSending(streamStartMessage, stream);
371
390
  this._send(streamStartMessage);
372
391
  }), inputStream);
373
392
  }
@@ -65,12 +65,19 @@ var import_debug = require('../lib/debug.cjs');
65
65
  var import_jsonrpc = require('./jsonrpc/jsonrpc.enums.cjs');
66
66
  var import_base_client = require('./base-client.cjs');
67
67
  var import__ = require('../index.cjs');
68
+ var import_errors = require('../lib/errors.cjs');
68
69
  var import_utils = require('../lib/utils.cjs');
69
- function createHttpClient(opts) {
70
- const initialConnection = createConnection(opts);
71
- return new HttpClient(initialConnection, opts);
70
+ function createHttpClient(opts, config) {
71
+ const initialConnection = createConnection(opts, {
72
+ timeout: config == null ? void 0 : config.connectingTimeout
73
+ });
74
+ return new HttpClient(
75
+ initialConnection,
76
+ opts
77
+ /* config */
78
+ );
72
79
  }
73
- function createConnection(opts) {
80
+ function createConnection(opts, connectionConfig) {
74
81
  const url = opts.host.replace(/^wss:/, "https:");
75
82
  const REQ_HEADER_ID = "x-wapi-req-id";
76
83
  function onmessage(body) {
@@ -95,23 +102,40 @@ function createConnection(opts) {
95
102
  });
96
103
  }
97
104
  const connectId = (0, import_utils.getRandomHex)();
98
- const $connect = (0, import_fetch.fetch)(`${url}/api`, {
99
- method: "POST",
100
- headers: {
101
- Authorization: `Bearer ${opts.jwt}`,
102
- [REQ_HEADER_ID]: connectId
103
- },
104
- body: JSON.stringify({
105
- jsonrpc: import_jsonrpc.JSONRPC.version,
106
- method: "authenticationCheck",
107
- params: {},
108
- id: connectId
109
- })
110
- }).then((res) => res.json()).then((res) => {
111
- if (res.error) {
112
- throw new Error(res.error.message);
113
- }
114
- return;
105
+ const $connect = new Promise((resolve, reject) => {
106
+ const controller = new AbortController();
107
+ (0, import_debug.debugLog)(
108
+ `createConnection(sending http auth request${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
109
+ );
110
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
111
+ controller.abort();
112
+ reject(
113
+ new import_errors.ConfigError("CONNECTION_TIMEOUT", {
114
+ timeout: connectionConfig.timeout
115
+ })
116
+ );
117
+ }, connectionConfig.timeout) : void 0;
118
+ (0, import_fetch.fetch)(`${url}/api`, {
119
+ method: "POST",
120
+ headers: {
121
+ Authorization: `Bearer ${opts.jwt}`,
122
+ [REQ_HEADER_ID]: connectId
123
+ },
124
+ body: JSON.stringify({
125
+ jsonrpc: import_jsonrpc.JSONRPC.version,
126
+ method: "authenticationCheck",
127
+ params: {},
128
+ id: connectId
129
+ }),
130
+ signal: controller.signal
131
+ }).then((res) => res.json()).then((res) => {
132
+ clearTimeout(connectingTimeout);
133
+ if (res.error) {
134
+ throw new Error(res.error.message);
135
+ }
136
+ resolve(void 0);
137
+ return;
138
+ }).catch(reject);
115
139
  });
116
140
  return {
117
141
  send,
@@ -120,6 +144,8 @@ function createConnection(opts) {
120
144
  };
121
145
  }
122
146
  var HttpClient = class extends import_base_client.BaseClient {
147
+ // private _opts: WapiHttpConnectionOptions;
148
+ // private _connectionConfig: ConnectionConfig | undefined;
123
149
  constructor(connection, opts) {
124
150
  super(connection, import__.WapiClientType.https, connection.$connect);
125
151
  this.host = opts.host;