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
@@ -46,12 +46,19 @@ import {
46
46
  } from "./jsonrpc/jsonrpc.enums.browser.js";
47
47
  import { BaseClient } from "./base-client.browser.js";
48
48
  import { WapiClientType } from "../index.browser.js";
49
+ import { ConfigError } from "../lib/errors.browser.js";
49
50
  import { getRandomHex } from "../lib/utils.browser.js";
50
- function createHttpClient(opts) {
51
- const initialConnection = createConnection(opts);
52
- return new HttpClient(initialConnection, opts);
51
+ function createHttpClient(opts, config) {
52
+ const initialConnection = createConnection(opts, {
53
+ timeout: config == null ? void 0 : config.connectingTimeout
54
+ });
55
+ return new HttpClient(
56
+ initialConnection,
57
+ opts
58
+ /* config */
59
+ );
53
60
  }
54
- function createConnection(opts) {
61
+ function createConnection(opts, connectionConfig) {
55
62
  const url = opts.host.replace(/^wss:/, "https:");
56
63
  const REQ_HEADER_ID = "x-wapi-req-id";
57
64
  function onmessage(body) {
@@ -76,23 +83,40 @@ function createConnection(opts) {
76
83
  });
77
84
  }
78
85
  const connectId = getRandomHex();
79
- const $connect = fetch(`${url}/api`, {
80
- method: "POST",
81
- headers: {
82
- Authorization: `Bearer ${opts.jwt}`,
83
- [REQ_HEADER_ID]: connectId
84
- },
85
- body: JSON.stringify({
86
- jsonrpc: JSONRPC.version,
87
- method: "authenticationCheck",
88
- params: {},
89
- id: connectId
90
- })
91
- }).then((res) => res.json()).then((res) => {
92
- if (res.error) {
93
- throw new Error(res.error.message);
94
- }
95
- return;
86
+ const $connect = new Promise((resolve, reject) => {
87
+ const controller = new AbortController();
88
+ debugLog(
89
+ `createConnection(sending http auth request${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
90
+ );
91
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
92
+ controller.abort();
93
+ reject(
94
+ new ConfigError("CONNECTION_TIMEOUT", {
95
+ timeout: connectionConfig.timeout
96
+ })
97
+ );
98
+ }, connectionConfig.timeout) : void 0;
99
+ fetch(`${url}/api`, {
100
+ method: "POST",
101
+ headers: {
102
+ Authorization: `Bearer ${opts.jwt}`,
103
+ [REQ_HEADER_ID]: connectId
104
+ },
105
+ body: JSON.stringify({
106
+ jsonrpc: JSONRPC.version,
107
+ method: "authenticationCheck",
108
+ params: {},
109
+ id: connectId
110
+ }),
111
+ signal: controller.signal
112
+ }).then((res) => res.json()).then((res) => {
113
+ clearTimeout(connectingTimeout);
114
+ if (res.error) {
115
+ throw new Error(res.error.message);
116
+ }
117
+ resolve(void 0);
118
+ return;
119
+ }).catch(reject);
96
120
  });
97
121
  return {
98
122
  send,
@@ -101,6 +125,8 @@ function createConnection(opts) {
101
125
  };
102
126
  }
103
127
  var HttpClient = class extends BaseClient {
128
+ // private _opts: WapiHttpConnectionOptions;
129
+ // private _connectionConfig: ConnectionConfig | undefined;
104
130
  constructor(connection, opts) {
105
131
  super(connection, WapiClientType.https, connection.$connect);
106
132
  this.host = opts.host;
@@ -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;
@@ -1,4 +1,4 @@
1
- import { WapiHttpConnectionOptions } from './index';
1
+ import { ConnectionConfig, WapiHttpConnectionOptions } from './index';
2
2
  import { JSONRPCRequest, JSONRPCResponse } from './jsonrpc/jsonrpc.enums';
3
3
  import { BaseClient } from './base-client';
4
4
  export interface HttpConnectionClient {
@@ -6,7 +6,7 @@ export interface HttpConnectionClient {
6
6
  onmessage: (response: JSONRPCResponse) => void;
7
7
  $connect: Promise<undefined>;
8
8
  }
9
- export declare function createHttpClient(opts: WapiHttpConnectionOptions): HttpClient;
9
+ export declare function createHttpClient(opts: WapiHttpConnectionOptions, config?: ConnectionConfig): HttpClient;
10
10
  export declare class HttpClient extends BaseClient {
11
11
  protected _connection: HttpConnectionClient;
12
12
  constructor(connection: HttpConnectionClient, opts: WapiHttpConnectionOptions);
@@ -46,12 +46,19 @@ import {
46
46
  } from "./jsonrpc/jsonrpc.enums";
47
47
  import { BaseClient } from "./base-client";
48
48
  import { WapiClientType } from "../index";
49
+ import { ConfigError } from "../lib/errors";
49
50
  import { getRandomHex } from "../lib/utils";
50
- function createHttpClient(opts) {
51
- const initialConnection = createConnection(opts);
52
- return new HttpClient(initialConnection, opts);
51
+ function createHttpClient(opts, config) {
52
+ const initialConnection = createConnection(opts, {
53
+ timeout: config == null ? void 0 : config.connectingTimeout
54
+ });
55
+ return new HttpClient(
56
+ initialConnection,
57
+ opts
58
+ /* config */
59
+ );
53
60
  }
54
- function createConnection(opts) {
61
+ function createConnection(opts, connectionConfig) {
55
62
  const url = opts.host.replace(/^wss:/, "https:");
56
63
  const REQ_HEADER_ID = "x-wapi-req-id";
57
64
  function onmessage(body) {
@@ -76,23 +83,40 @@ function createConnection(opts) {
76
83
  });
77
84
  }
78
85
  const connectId = getRandomHex();
79
- const $connect = fetch(`${url}/api`, {
80
- method: "POST",
81
- headers: {
82
- Authorization: `Bearer ${opts.jwt}`,
83
- [REQ_HEADER_ID]: connectId
84
- },
85
- body: JSON.stringify({
86
- jsonrpc: JSONRPC.version,
87
- method: "authenticationCheck",
88
- params: {},
89
- id: connectId
90
- })
91
- }).then((res) => res.json()).then((res) => {
92
- if (res.error) {
93
- throw new Error(res.error.message);
94
- }
95
- return;
86
+ const $connect = new Promise((resolve, reject) => {
87
+ const controller = new AbortController();
88
+ debugLog(
89
+ `createConnection(sending http auth request${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
90
+ );
91
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
92
+ controller.abort();
93
+ reject(
94
+ new ConfigError("CONNECTION_TIMEOUT", {
95
+ timeout: connectionConfig.timeout
96
+ })
97
+ );
98
+ }, connectionConfig.timeout) : void 0;
99
+ fetch(`${url}/api`, {
100
+ method: "POST",
101
+ headers: {
102
+ Authorization: `Bearer ${opts.jwt}`,
103
+ [REQ_HEADER_ID]: connectId
104
+ },
105
+ body: JSON.stringify({
106
+ jsonrpc: JSONRPC.version,
107
+ method: "authenticationCheck",
108
+ params: {},
109
+ id: connectId
110
+ }),
111
+ signal: controller.signal
112
+ }).then((res) => res.json()).then((res) => {
113
+ clearTimeout(connectingTimeout);
114
+ if (res.error) {
115
+ throw new Error(res.error.message);
116
+ }
117
+ resolve(void 0);
118
+ return;
119
+ }).catch(reject);
96
120
  });
97
121
  return {
98
122
  send,
@@ -101,6 +125,8 @@ function createConnection(opts) {
101
125
  };
102
126
  }
103
127
  var HttpClient = class extends BaseClient {
128
+ // private _opts: WapiHttpConnectionOptions;
129
+ // private _connectionConfig: ConnectionConfig | undefined;
104
130
  constructor(connection, opts) {
105
131
  super(connection, WapiClientType.https, connection.$connect);
106
132
  this.host = opts.host;
@@ -14,6 +14,10 @@ export interface WapiHttpConnectionOptions {
14
14
  host: string;
15
15
  jwt: string;
16
16
  }
17
+ export interface ConnectionConfig {
18
+ connectingTimeout?: number;
19
+ reconnectingTimeout?: number;
20
+ }
17
21
  export { BaseClient, WsClient, HttpClient, createWsClient, createHttpClient };
18
22
  import JSONRPCRequestSchema from './jsonrpc/jsonrpc.request.schema.json';
19
23
  import JSONRPCResponseSchema from './jsonrpc/jsonrpc.response.schema.json';
@@ -56,11 +56,13 @@ var import_connection = require('./connection/connection.enums.cjs');
56
56
  var import__ = require('../index.cjs');
57
57
  var _a;
58
58
  var CLIENT_VERSION = (_a = window.WAPI_VERSION) != null ? _a : "";
59
- function createWsClient(opts) {
60
- const initialConnection = createConnection(opts);
61
- return new WsClient(initialConnection, opts);
59
+ function createWsClient(opts, config) {
60
+ const initialConnection = createConnection(opts, {
61
+ timeout: config == null ? void 0 : config.connectingTimeout
62
+ });
63
+ return new WsClient(initialConnection, opts, config);
62
64
  }
63
- function createConnection(opts) {
65
+ function createConnection(opts, connectionConfig) {
64
66
  var _a2;
65
67
  const config = Object.assign(
66
68
  {
@@ -109,10 +111,21 @@ function createConnection(opts) {
109
111
  }
110
112
  clean();
111
113
  }
114
+ (0, import_debug.debugLog)(
115
+ `createConnection>(message:setting up ws connection${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
116
+ );
117
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
118
+ clean(
119
+ new import_errors.ConfigError("CONNECTION_TIMEOUT", {
120
+ timeout: connectionConfig.timeout
121
+ })
122
+ );
123
+ }, connectionConfig.timeout) : void 0;
112
124
  function clean(err) {
113
125
  if (isCleaned) {
114
126
  return;
115
127
  }
128
+ clearTimeout(connectingTimeout);
116
129
  delete ws.onmessage;
117
130
  delete ws.onerror;
118
131
  delete ws.onclose;
@@ -134,11 +147,12 @@ function createConnection(opts) {
134
147
  };
135
148
  }
136
149
  var WsClient = class extends import_base_client.BaseClient {
137
- constructor(initial, config) {
150
+ constructor(initial, opts, config) {
138
151
  super(initial.ws, import__.WapiClientType.ws, initial.$connect);
139
152
  this._tryToReconnect = true;
140
- this._config = config;
141
- this.host = config.host;
153
+ this._opts = opts;
154
+ this._connectionConfig = config;
155
+ this.host = opts.host;
142
156
  this.$connect.then((_id) => {
143
157
  this.socId = _id;
144
158
  return this._ready();
@@ -197,12 +211,14 @@ var WsClient = class extends import_base_client.BaseClient {
197
211
  nrOfAttempts != null ? nrOfAttempts : nrOfAttempts = window.WAPI_RECONNECT_ATTEMPTS && parseInt(window.WAPI_RECONNECT_ATTEMPTS) || 10;
198
212
  const maxWaitTime = window.WAPI_MAX_RECONNECT_WAIT && parseInt(window.WAPI_MAX_RECONNECT_WAIT) || 1e4;
199
213
  this.$connect = (() => __async(this, null, function* () {
200
- var _a2, _b;
214
+ var _a2, _b, _c;
201
215
  let _id;
202
216
  for (let i = 0; i < nrOfAttempts + 1; i++) {
203
217
  try {
204
218
  (0, import_debug.debugLog)("Trying to connect, attempt:", i);
205
- const { ws, $connect } = createConnection(this._config);
219
+ const { ws, $connect } = createConnection(this._opts, {
220
+ timeout: (_a2 = this._connectionConfig) == null ? void 0 : _a2.reconnectingTimeout
221
+ });
206
222
  _id = yield $connect;
207
223
  this.socId = _id;
208
224
  this._connection = ws;
@@ -213,7 +229,7 @@ var WsClient = class extends import_base_client.BaseClient {
213
229
  const outOfAttempts = i > nrOfAttempts - 1;
214
230
  if (isAuthError || outOfAttempts) {
215
231
  this._setErrored(err);
216
- (_b = (_a2 = this.hooks).reconnectError) == null ? void 0 : _b.call(_a2, err);
232
+ (_c = (_b = this.hooks).reconnectError) == null ? void 0 : _c.call(_b, err);
217
233
  break;
218
234
  }
219
235
  yield (0, import_utils.wait)(Math.min(Math.pow(1.5, i) * 1e3, maxWaitTime));
@@ -24,7 +24,7 @@ var browser_default = WebSocket;
24
24
 
25
25
  // src/api/ws-client.ts
26
26
  import { debugLog } from "../lib/debug.browser.js";
27
- import { AuthenticationError, ERROR_GROUPS } from "../lib/errors.browser.js";
27
+ import { AuthenticationError, ConfigError, ERROR_GROUPS } from "../lib/errors.browser.js";
28
28
  import { getConnectionParams, wait } from "../lib/utils.browser.js";
29
29
  import { BaseClient } from "./base-client.browser.js";
30
30
  import {
@@ -34,11 +34,13 @@ import {
34
34
  import { WapiClientType } from "../index.browser.js";
35
35
  var _a;
36
36
  var CLIENT_VERSION = (_a = window.WAPI_VERSION) != null ? _a : "";
37
- function createWsClient(opts) {
38
- const initialConnection = createConnection(opts);
39
- return new WsClient(initialConnection, opts);
37
+ function createWsClient(opts, config) {
38
+ const initialConnection = createConnection(opts, {
39
+ timeout: config == null ? void 0 : config.connectingTimeout
40
+ });
41
+ return new WsClient(initialConnection, opts, config);
40
42
  }
41
- function createConnection(opts) {
43
+ function createConnection(opts, connectionConfig) {
42
44
  var _a2;
43
45
  const config = Object.assign(
44
46
  {
@@ -87,10 +89,21 @@ function createConnection(opts) {
87
89
  }
88
90
  clean();
89
91
  }
92
+ debugLog(
93
+ `createConnection>(message:setting up ws connection${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
94
+ );
95
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
96
+ clean(
97
+ new ConfigError("CONNECTION_TIMEOUT", {
98
+ timeout: connectionConfig.timeout
99
+ })
100
+ );
101
+ }, connectionConfig.timeout) : void 0;
90
102
  function clean(err) {
91
103
  if (isCleaned) {
92
104
  return;
93
105
  }
106
+ clearTimeout(connectingTimeout);
94
107
  delete ws.onmessage;
95
108
  delete ws.onerror;
96
109
  delete ws.onclose;
@@ -112,11 +125,12 @@ function createConnection(opts) {
112
125
  };
113
126
  }
114
127
  var WsClient = class extends BaseClient {
115
- constructor(initial, config) {
128
+ constructor(initial, opts, config) {
116
129
  super(initial.ws, WapiClientType.ws, initial.$connect);
117
130
  this._tryToReconnect = true;
118
- this._config = config;
119
- this.host = config.host;
131
+ this._opts = opts;
132
+ this._connectionConfig = config;
133
+ this.host = opts.host;
120
134
  this.$connect.then((_id) => {
121
135
  this.socId = _id;
122
136
  return this._ready();
@@ -175,12 +189,14 @@ var WsClient = class extends BaseClient {
175
189
  nrOfAttempts != null ? nrOfAttempts : nrOfAttempts = window.WAPI_RECONNECT_ATTEMPTS && parseInt(window.WAPI_RECONNECT_ATTEMPTS) || 10;
176
190
  const maxWaitTime = window.WAPI_MAX_RECONNECT_WAIT && parseInt(window.WAPI_MAX_RECONNECT_WAIT) || 1e4;
177
191
  this.$connect = (() => __async(this, null, function* () {
178
- var _a2, _b;
192
+ var _a2, _b, _c;
179
193
  let _id;
180
194
  for (let i = 0; i < nrOfAttempts + 1; i++) {
181
195
  try {
182
196
  debugLog("Trying to connect, attempt:", i);
183
- const { ws, $connect } = createConnection(this._config);
197
+ const { ws, $connect } = createConnection(this._opts, {
198
+ timeout: (_a2 = this._connectionConfig) == null ? void 0 : _a2.reconnectingTimeout
199
+ });
184
200
  _id = yield $connect;
185
201
  this.socId = _id;
186
202
  this._connection = ws;
@@ -191,7 +207,7 @@ var WsClient = class extends BaseClient {
191
207
  const outOfAttempts = i > nrOfAttempts - 1;
192
208
  if (isAuthError || outOfAttempts) {
193
209
  this._setErrored(err);
194
- (_b = (_a2 = this.hooks).reconnectError) == null ? void 0 : _b.call(_a2, err);
210
+ (_c = (_b = this.hooks).reconnectError) == null ? void 0 : _c.call(_b, err);
195
211
  break;
196
212
  }
197
213
  yield wait(Math.min(Math.pow(1.5, i) * 1e3, maxWaitTime));
@@ -61,12 +61,14 @@ var import_base_client = require('./base-client.cjs');
61
61
  var import_connection = require('./connection/connection.enums.cjs');
62
62
  var import__ = require('../index.cjs');
63
63
  var _a;
64
- var CLIENT_VERSION = (_a = '0.10.2') != null ? _a : "";
65
- function createWsClient(opts) {
66
- const initialConnection = createConnection(opts);
67
- return new WsClient(initialConnection, opts);
64
+ var CLIENT_VERSION = (_a = '0.10.6') != null ? _a : "";
65
+ function createWsClient(opts, config) {
66
+ const initialConnection = createConnection(opts, {
67
+ timeout: config == null ? void 0 : config.connectingTimeout
68
+ });
69
+ return new WsClient(initialConnection, opts, config);
68
70
  }
69
- function createConnection(opts) {
71
+ function createConnection(opts, connectionConfig) {
70
72
  var _a2;
71
73
  const config = Object.assign(
72
74
  {
@@ -115,10 +117,21 @@ function createConnection(opts) {
115
117
  }
116
118
  clean();
117
119
  }
120
+ (0, import_debug.debugLog)(
121
+ `createConnection>(message:setting up ws connection${(connectionConfig == null ? void 0 : connectionConfig.timeout) ? " with timeout " + connectionConfig.timeout : ""})`
122
+ );
123
+ const connectingTimeout = (connectionConfig == null ? void 0 : connectionConfig.timeout) ? setTimeout(() => {
124
+ clean(
125
+ new import_errors.ConfigError("CONNECTION_TIMEOUT", {
126
+ timeout: connectionConfig.timeout
127
+ })
128
+ );
129
+ }, connectionConfig.timeout) : void 0;
118
130
  function clean(err) {
119
131
  if (isCleaned) {
120
132
  return;
121
133
  }
134
+ clearTimeout(connectingTimeout);
122
135
  delete ws.onmessage;
123
136
  delete ws.onerror;
124
137
  delete ws.onclose;
@@ -140,11 +153,12 @@ function createConnection(opts) {
140
153
  };
141
154
  }
142
155
  var WsClient = class extends import_base_client.BaseClient {
143
- constructor(initial, config) {
156
+ constructor(initial, opts, config) {
144
157
  super(initial.ws, import__.WapiClientType.ws, initial.$connect);
145
158
  this._tryToReconnect = true;
146
- this._config = config;
147
- this.host = config.host;
159
+ this._opts = opts;
160
+ this._connectionConfig = config;
161
+ this.host = opts.host;
148
162
  this.$connect.then((_id) => {
149
163
  this.socId = _id;
150
164
  return this._ready();
@@ -203,12 +217,14 @@ var WsClient = class extends import_base_client.BaseClient {
203
217
  nrOfAttempts != null ? nrOfAttempts : nrOfAttempts = process.env.WAPI_RECONNECT_ATTEMPTS && parseInt(process.env.WAPI_RECONNECT_ATTEMPTS) || 10;
204
218
  const maxWaitTime = process.env.WAPI_MAX_RECONNECT_WAIT && parseInt(process.env.WAPI_MAX_RECONNECT_WAIT) || 1e4;
205
219
  this.$connect = (() => __async(this, null, function* () {
206
- var _a2, _b;
220
+ var _a2, _b, _c;
207
221
  let _id;
208
222
  for (let i = 0; i < nrOfAttempts + 1; i++) {
209
223
  try {
210
224
  (0, import_debug.debugLog)("Trying to connect, attempt:", i);
211
- const { ws, $connect } = createConnection(this._config);
225
+ const { ws, $connect } = createConnection(this._opts, {
226
+ timeout: (_a2 = this._connectionConfig) == null ? void 0 : _a2.reconnectingTimeout
227
+ });
212
228
  _id = yield $connect;
213
229
  this.socId = _id;
214
230
  this._connection = ws;
@@ -219,7 +235,7 @@ var WsClient = class extends import_base_client.BaseClient {
219
235
  const outOfAttempts = i > nrOfAttempts - 1;
220
236
  if (isAuthError || outOfAttempts) {
221
237
  this._setErrored(err);
222
- (_b = (_a2 = this.hooks).reconnectError) == null ? void 0 : _b.call(_a2, err);
238
+ (_c = (_b = this.hooks).reconnectError) == null ? void 0 : _c.call(_b, err);
223
239
  break;
224
240
  }
225
241
  yield (0, import_utils.wait)(Math.min(Math.pow(1.5, i) * 1e3, maxWaitTime));
@@ -2,8 +2,8 @@ import WebSocket from 'modern-isomorphic-ws';
2
2
  import { AuthenticationError } from '../lib/errors';
3
3
  import { BaseClient, ISocketId } from './base-client';
4
4
  import { JSONRPCRequest, JSONRPCResponse } from './jsonrpc/jsonrpc.enums';
5
- import { WapiConnectionOptions } from './index';
6
- export declare function createWsClient(opts: WapiConnectionOptions): WsClient;
5
+ import { ConnectionConfig, WapiConnectionOptions } from './index';
6
+ export declare function createWsClient(opts: WapiConnectionOptions, config?: ConnectionConfig): WsClient;
7
7
  interface ConnectionWPromise {
8
8
  ws: WebSocket;
9
9
  $connect: Promise<ISocketId>;
@@ -14,10 +14,11 @@ export interface EWapiConnectionOptions extends WapiConnectionOptions {
14
14
  }
15
15
  export declare class WsClient extends BaseClient {
16
16
  private _pingTimeout;
17
- private _config;
17
+ private _opts;
18
+ private _connectionConfig;
18
19
  private _tryToReconnect;
19
20
  protected _connection: WebSocket;
20
- constructor(initial: ConnectionWPromise, config: WapiConnectionOptions);
21
+ constructor(initial: ConnectionWPromise, opts: WapiConnectionOptions, config?: ConnectionConfig);
21
22
  protected _setErrored(err: Error | AuthenticationError): void;
22
23
  private _ready;
23
24
  protected _reconnect(nrOfAttempts?: number | undefined): void;