@ethersphere/bee-js 5.1.1 → 5.1.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.
Files changed (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  exports.BeeDebug = void 0;
36
27
  const connectivity = __importStar(require("./modules/debug/connectivity"));
@@ -49,9 +40,9 @@ const tag = __importStar(require("./modules/debug/tag"));
49
40
  const stamps = __importStar(require("./modules/debug/stamps"));
50
41
  const http_1 = require("./utils/http");
51
42
  const sleep_1 = require("./utils/sleep");
43
+ const merge_1 = require("./utils/merge");
52
44
  class BeeDebug {
53
45
  constructor(url, options) {
54
- var _a;
55
46
  (0, url_1.assertBeeUrl)(url);
56
47
  // Remove last slash if present, as our endpoint strings starts with `/...`
57
48
  // which could lead to double slash in URL to which Bee responds with
@@ -59,36 +50,32 @@ class BeeDebug {
59
50
  this.url = (0, url_1.stripLastSlash)(url);
60
51
  const kyOptions = {
61
52
  prefixUrl: this.url,
62
- timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : false,
63
- retry: options === null || options === void 0 ? void 0 : options.retry,
64
- fetch: options === null || options === void 0 ? void 0 : options.fetch,
53
+ timeout: options?.timeout ?? false,
54
+ retry: options?.retry,
55
+ fetch: options?.fetch,
65
56
  hooks: {
66
57
  beforeRequest: [],
67
58
  afterResponse: [],
68
59
  },
69
60
  };
70
- if (options === null || options === void 0 ? void 0 : options.defaultHeaders) {
61
+ if (options?.defaultHeaders) {
71
62
  kyOptions.headers = options.defaultHeaders;
72
63
  }
73
- if (options === null || options === void 0 ? void 0 : options.onRequest) {
64
+ if (options?.onRequest) {
74
65
  kyOptions.hooks.beforeRequest.push((0, http_1.wrapRequestClosure)(options.onRequest));
75
66
  }
76
- if (options === null || options === void 0 ? void 0 : options.onResponse) {
67
+ if (options?.onResponse) {
77
68
  kyOptions.hooks.afterResponse.push((0, http_1.wrapResponseClosure)(options.onResponse));
78
69
  }
79
- this.ky = (0, http_1.makeDefaultKy)(kyOptions);
70
+ this.kyOptions = (0, merge_1.deepMerge)(http_1.DEFAULT_KY_CONFIG, kyOptions);
80
71
  }
81
- getNodeAddresses(options) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- (0, type_1.assertRequestOptions)(options);
84
- return connectivity.getNodeAddresses(this.getKy(options));
85
- });
72
+ async getNodeAddresses(options) {
73
+ (0, type_1.assertRequestOptions)(options);
74
+ return connectivity.getNodeAddresses(this.getKyOptionsForCall(options));
86
75
  }
87
- getBlocklist(options) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- (0, type_1.assertRequestOptions)(options);
90
- return connectivity.getBlocklist(this.getKy(options));
91
- });
76
+ async getBlocklist(options) {
77
+ (0, type_1.assertRequestOptions)(options);
78
+ return connectivity.getBlocklist(this.getKyOptionsForCall(options));
92
79
  }
93
80
  /**
94
81
  * Retrieve tag extended information from Bee node
@@ -100,49 +87,39 @@ class BeeDebug {
100
87
  * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
101
88
  *
102
89
  */
103
- retrieveExtendedTag(tagUid, options) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- (0, type_1.assertRequestOptions)(options);
106
- if ((0, type_1.isTag)(tagUid)) {
107
- tagUid = tagUid.uid;
108
- }
109
- else if (typeof tagUid === 'number') {
110
- (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
111
- }
112
- else {
113
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
114
- }
115
- return tag.retrieveExtendedTag(this.getKy(options), tagUid);
116
- });
90
+ async retrieveExtendedTag(tagUid, options) {
91
+ (0, type_1.assertRequestOptions)(options);
92
+ if ((0, type_1.isTag)(tagUid)) {
93
+ tagUid = tagUid.uid;
94
+ }
95
+ else if (typeof tagUid === 'number') {
96
+ (0, type_1.assertNonNegativeInteger)(tagUid, 'UID');
97
+ }
98
+ else {
99
+ throw new TypeError('tagUid has to be either Tag or a number (UID)!');
100
+ }
101
+ return tag.retrieveExtendedTag(this.getKyOptionsForCall(options), tagUid);
117
102
  }
118
103
  /**
119
104
  * Get list of peers for this node
120
105
  */
121
- getPeers(options) {
122
- return __awaiter(this, void 0, void 0, function* () {
123
- (0, type_1.assertRequestOptions)(options);
124
- return connectivity.getPeers(this.getKy(options));
125
- });
126
- }
127
- removePeer(peer, options) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- (0, type_1.assertRequestOptions)(options);
130
- (0, type_1.assertAddress)(peer);
131
- return connectivity.removePeer(this.getKy(options), peer);
132
- });
133
- }
134
- getTopology(options) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- (0, type_1.assertRequestOptions)(options);
137
- return connectivity.getTopology(this.getKy(options));
138
- });
139
- }
140
- pingPeer(peer, options) {
141
- return __awaiter(this, void 0, void 0, function* () {
142
- (0, type_1.assertRequestOptions)(options);
143
- (0, type_1.assertAddress)(peer);
144
- return connectivity.pingPeer(this.getKy(options), peer);
145
- });
106
+ async getPeers(options) {
107
+ (0, type_1.assertRequestOptions)(options);
108
+ return connectivity.getPeers(this.getKyOptionsForCall(options));
109
+ }
110
+ async removePeer(peer, options) {
111
+ (0, type_1.assertRequestOptions)(options);
112
+ (0, type_1.assertAddress)(peer);
113
+ return connectivity.removePeer(this.getKyOptionsForCall(options), peer);
114
+ }
115
+ async getTopology(options) {
116
+ (0, type_1.assertRequestOptions)(options);
117
+ return connectivity.getTopology(this.getKyOptionsForCall(options));
118
+ }
119
+ async pingPeer(peer, options) {
120
+ (0, type_1.assertRequestOptions)(options);
121
+ (0, type_1.assertAddress)(peer);
122
+ return connectivity.pingPeer(this.getKyOptionsForCall(options), peer);
146
123
  }
147
124
  /*
148
125
  * Balance endpoints
@@ -150,44 +127,36 @@ class BeeDebug {
150
127
  /**
151
128
  * Get the balances with all known peers including prepaid services
152
129
  */
153
- getAllBalances(options) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- (0, type_1.assertRequestOptions)(options);
156
- return balance.getAllBalances(this.getKy(options));
157
- });
130
+ async getAllBalances(options) {
131
+ (0, type_1.assertRequestOptions)(options);
132
+ return balance.getAllBalances(this.getKyOptionsForCall(options));
158
133
  }
159
134
  /**
160
135
  * Get the balances with a specific peer including prepaid services
161
136
  *
162
137
  * @param address Swarm address of peer
163
138
  */
164
- getPeerBalance(address, options) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- (0, type_1.assertRequestOptions)(options);
167
- (0, type_1.assertAddress)(address);
168
- return balance.getPeerBalance(this.getKy(options), address);
169
- });
139
+ async getPeerBalance(address, options) {
140
+ (0, type_1.assertRequestOptions)(options);
141
+ (0, type_1.assertAddress)(address);
142
+ return balance.getPeerBalance(this.getKyOptionsForCall(options), address);
170
143
  }
171
144
  /**
172
145
  * Get the past due consumption balances with all known peers
173
146
  */
174
- getPastDueConsumptionBalances(options) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- (0, type_1.assertRequestOptions)(options);
177
- return balance.getPastDueConsumptionBalances(this.getKy(options));
178
- });
147
+ async getPastDueConsumptionBalances(options) {
148
+ (0, type_1.assertRequestOptions)(options);
149
+ return balance.getPastDueConsumptionBalances(this.getKyOptionsForCall(options));
179
150
  }
180
151
  /**
181
152
  * Get the past due consumption balance with a specific peer
182
153
  *
183
154
  * @param address Swarm address of peer
184
155
  */
185
- getPastDueConsumptionPeerBalance(address, options) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- (0, type_1.assertRequestOptions)(options);
188
- (0, type_1.assertAddress)(address);
189
- return balance.getPastDueConsumptionPeerBalance(this.getKy(options), address);
190
- });
156
+ async getPastDueConsumptionPeerBalance(address, options) {
157
+ (0, type_1.assertRequestOptions)(options);
158
+ (0, type_1.assertAddress)(address);
159
+ return balance.getPastDueConsumptionPeerBalance(this.getKyOptionsForCall(options), address);
191
160
  }
192
161
  /*
193
162
  * Chequebook endpoints
@@ -198,53 +167,43 @@ class BeeDebug {
198
167
  * **Warning:** The address is returned with 0x prefix unlike all other calls.
199
168
  * https://github.com/ethersphere/bee/issues/1443
200
169
  */
201
- getChequebookAddress(options) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- (0, type_1.assertRequestOptions)(options);
204
- return chequebook.getChequebookAddress(this.getKy(options));
205
- });
170
+ async getChequebookAddress(options) {
171
+ (0, type_1.assertRequestOptions)(options);
172
+ return chequebook.getChequebookAddress(this.getKyOptionsForCall(options));
206
173
  }
207
174
  /**
208
175
  * Get the balance of the chequebook
209
176
  */
210
- getChequebookBalance(options) {
211
- return __awaiter(this, void 0, void 0, function* () {
212
- (0, type_1.assertRequestOptions)(options);
213
- return chequebook.getChequebookBalance(this.getKy(options));
214
- });
177
+ async getChequebookBalance(options) {
178
+ (0, type_1.assertRequestOptions)(options);
179
+ return chequebook.getChequebookBalance(this.getKyOptionsForCall(options));
215
180
  }
216
181
  /**
217
182
  * Get last cheques for all peers
218
183
  */
219
- getLastCheques(options) {
220
- return __awaiter(this, void 0, void 0, function* () {
221
- (0, type_1.assertRequestOptions)(options);
222
- return chequebook.getLastCheques(this.getKy(options));
223
- });
184
+ async getLastCheques(options) {
185
+ (0, type_1.assertRequestOptions)(options);
186
+ return chequebook.getLastCheques(this.getKyOptionsForCall(options));
224
187
  }
225
188
  /**
226
189
  * Get last cheques for the peer
227
190
  *
228
191
  * @param address Swarm address of peer
229
192
  */
230
- getLastChequesForPeer(address, options) {
231
- return __awaiter(this, void 0, void 0, function* () {
232
- (0, type_1.assertRequestOptions)(options);
233
- (0, type_1.assertAddress)(address);
234
- return chequebook.getLastChequesForPeer(this.getKy(options), address);
235
- });
193
+ async getLastChequesForPeer(address, options) {
194
+ (0, type_1.assertRequestOptions)(options);
195
+ (0, type_1.assertAddress)(address);
196
+ return chequebook.getLastChequesForPeer(this.getKyOptionsForCall(options), address);
236
197
  }
237
198
  /**
238
199
  * Get last cashout action for the peer
239
200
  *
240
201
  * @param address Swarm address of peer
241
202
  */
242
- getLastCashoutAction(address, options) {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- (0, type_1.assertRequestOptions)(options);
245
- (0, type_1.assertAddress)(address);
246
- return chequebook.getLastCashoutAction(this.getKy(options), address);
247
- });
203
+ async getLastCashoutAction(address, options) {
204
+ (0, type_1.assertRequestOptions)(options);
205
+ (0, type_1.assertAddress)(address);
206
+ return chequebook.getLastCashoutAction(this.getKyOptionsForCall(options), address);
248
207
  }
249
208
  /**
250
209
  * Cashout the last cheque for the peer
@@ -254,12 +213,10 @@ class BeeDebug {
254
213
  * @param options.gasPrice Gas price for the cashout transaction in WEI
255
214
  * @param options.gasLimit Gas limit for the cashout transaction in WEI
256
215
  */
257
- cashoutLastCheque(address, options) {
258
- return __awaiter(this, void 0, void 0, function* () {
259
- (0, type_1.assertCashoutOptions)(options);
260
- (0, type_1.assertAddress)(address);
261
- return chequebook.cashoutLastCheque(this.getKy(options), address, options);
262
- });
216
+ async cashoutLastCheque(address, options) {
217
+ (0, type_1.assertCashoutOptions)(options);
218
+ (0, type_1.assertAddress)(address);
219
+ return chequebook.cashoutLastCheque(this.getKyOptionsForCall(options), address, options);
263
220
  }
264
221
  /**
265
222
  * Deposit tokens from overlay address into chequebook
@@ -268,15 +225,13 @@ class BeeDebug {
268
225
  * @param gasPrice Gas Price in WEI for the transaction call
269
226
  * @return string Hash of the transaction
270
227
  */
271
- depositTokens(amount, gasPrice, options) {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- (0, type_1.assertRequestOptions)(options);
274
- (0, type_1.assertNonNegativeInteger)(amount);
275
- if (gasPrice) {
276
- (0, type_1.assertNonNegativeInteger)(gasPrice);
277
- }
278
- return chequebook.depositTokens(this.getKy(options), amount, gasPrice);
279
- });
228
+ async depositTokens(amount, gasPrice, options) {
229
+ (0, type_1.assertRequestOptions)(options);
230
+ (0, type_1.assertNonNegativeInteger)(amount);
231
+ if (gasPrice) {
232
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
233
+ }
234
+ return chequebook.depositTokens(this.getKyOptionsForCall(options), amount, gasPrice);
280
235
  }
281
236
  /**
282
237
  * Withdraw tokens from the chequebook to the overlay address
@@ -285,15 +240,13 @@ class BeeDebug {
285
240
  * @param gasPrice Gas Price in WEI for the transaction call
286
241
  * @return string Hash of the transaction
287
242
  */
288
- withdrawTokens(amount, gasPrice, options) {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- (0, type_1.assertRequestOptions)(options);
291
- (0, type_1.assertNonNegativeInteger)(amount);
292
- if (gasPrice) {
293
- (0, type_1.assertNonNegativeInteger)(gasPrice);
294
- }
295
- return chequebook.withdrawTokens(this.getKy(options), amount, gasPrice);
296
- });
243
+ async withdrawTokens(amount, gasPrice, options) {
244
+ (0, type_1.assertRequestOptions)(options);
245
+ (0, type_1.assertNonNegativeInteger)(amount);
246
+ if (gasPrice) {
247
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
248
+ }
249
+ return chequebook.withdrawTokens(this.getKyOptionsForCall(options), amount, gasPrice);
297
250
  }
298
251
  /*
299
252
  * Settlements endpoint
@@ -303,48 +256,38 @@ class BeeDebug {
303
256
  *
304
257
  * @param address Swarm address of peer
305
258
  */
306
- getSettlements(address, options) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- (0, type_1.assertRequestOptions)(options);
309
- (0, type_1.assertAddress)(address);
310
- return settlements.getSettlements(this.getKy(options), address);
311
- });
259
+ async getSettlements(address, options) {
260
+ (0, type_1.assertRequestOptions)(options);
261
+ (0, type_1.assertAddress)(address);
262
+ return settlements.getSettlements(this.getKyOptionsForCall(options), address);
312
263
  }
313
264
  /**
314
265
  * Get settlements with all known peers and total amount sent or received
315
266
  */
316
- getAllSettlements(options) {
317
- return __awaiter(this, void 0, void 0, function* () {
318
- (0, type_1.assertRequestOptions)(options);
319
- return settlements.getAllSettlements(this.getKy(options));
320
- });
267
+ async getAllSettlements(options) {
268
+ (0, type_1.assertRequestOptions)(options);
269
+ return settlements.getAllSettlements(this.getKyOptionsForCall(options));
321
270
  }
322
271
  /**
323
272
  * Get health of node
324
273
  */
325
- getHealth(options) {
326
- return __awaiter(this, void 0, void 0, function* () {
327
- (0, type_1.assertRequestOptions)(options);
328
- return status.getHealth(this.getKy(options));
329
- });
274
+ async getHealth(options) {
275
+ (0, type_1.assertRequestOptions)(options);
276
+ return status.getHealth(this.getKyOptionsForCall(options));
330
277
  }
331
278
  /**
332
279
  * Get readiness of node
333
280
  */
334
- getReadiness(options) {
335
- return __awaiter(this, void 0, void 0, function* () {
336
- (0, type_1.assertRequestOptions)(options);
337
- return status.getReadiness(this.getKy(options));
338
- });
281
+ async getReadiness(options) {
282
+ (0, type_1.assertRequestOptions)(options);
283
+ return status.getReadiness(this.getKyOptionsForCall(options));
339
284
  }
340
285
  /**
341
286
  * Get mode information of node
342
287
  */
343
- getNodeInfo(options) {
344
- return __awaiter(this, void 0, void 0, function* () {
345
- (0, type_1.assertRequestOptions)(options);
346
- return status.getNodeInfo(this.getKy(options));
347
- });
288
+ async getNodeInfo(options) {
289
+ (0, type_1.assertRequestOptions)(options);
290
+ return status.getNodeInfo(this.getKyOptionsForCall(options));
348
291
  }
349
292
  /**
350
293
  * Connnects to a node and checks if it is a supported Bee version by the bee-js
@@ -352,11 +295,9 @@ class BeeDebug {
352
295
  * @returns true if the Bee node version is supported
353
296
  * @deprecated Use `BeeDebug.isSupportedExactVersion()` instead
354
297
  */
355
- isSupportedVersion(options) {
356
- return __awaiter(this, void 0, void 0, function* () {
357
- (0, type_1.assertRequestOptions)(options);
358
- return status.isSupportedVersion(this.getKy(options));
359
- });
298
+ async isSupportedVersion(options) {
299
+ (0, type_1.assertRequestOptions)(options);
300
+ return status.isSupportedVersion(this.getKyOptionsForCall(options));
360
301
  }
361
302
  /**
362
303
  * Connects to a node and checks if its version matches with the one that bee-js supports.
@@ -368,11 +309,9 @@ class BeeDebug {
368
309
  *
369
310
  * @param options
370
311
  */
371
- isSupportedExactVersion(options) {
372
- return __awaiter(this, void 0, void 0, function* () {
373
- (0, type_1.assertRequestOptions)(options);
374
- return status.isSupportedExactVersion(this.getKy(options));
375
- });
312
+ async isSupportedExactVersion(options) {
313
+ (0, type_1.assertRequestOptions)(options);
314
+ return status.isSupportedExactVersion(this.getKyOptionsForCall(options));
376
315
  }
377
316
  /**
378
317
  * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
@@ -382,11 +321,9 @@ class BeeDebug {
382
321
  *
383
322
  * @param options
384
323
  */
385
- isSupportedMainApiVersion(options) {
386
- return __awaiter(this, void 0, void 0, function* () {
387
- (0, type_1.assertRequestOptions)(options);
388
- return status.isSupportedMainApiVersion(this.getKy(options));
389
- });
324
+ async isSupportedMainApiVersion(options) {
325
+ (0, type_1.assertRequestOptions)(options);
326
+ return status.isSupportedMainApiVersion(this.getKyOptionsForCall(options));
390
327
  }
391
328
  /**
392
329
  * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
@@ -396,11 +333,9 @@ class BeeDebug {
396
333
  *
397
334
  * @param options
398
335
  */
399
- isSupportedDebugApiVersion(options) {
400
- return __awaiter(this, void 0, void 0, function* () {
401
- (0, type_1.assertRequestOptions)(options);
402
- return status.isSupportedDebugApiVersion(this.getKy(options));
403
- });
336
+ async isSupportedDebugApiVersion(options) {
337
+ (0, type_1.assertRequestOptions)(options);
338
+ return status.isSupportedDebugApiVersion(this.getKyOptionsForCall(options));
404
339
  }
405
340
  /**
406
341
  *
@@ -410,11 +345,9 @@ class BeeDebug {
410
345
  *
411
346
  * @param options
412
347
  */
413
- isSupportedApiVersion(options) {
414
- return __awaiter(this, void 0, void 0, function* () {
415
- (0, type_1.assertRequestOptions)(options);
416
- return status.isSupportedDebugApiVersion(this.getKy(options));
417
- });
348
+ async isSupportedApiVersion(options) {
349
+ (0, type_1.assertRequestOptions)(options);
350
+ return status.isSupportedDebugApiVersion(this.getKyOptionsForCall(options));
418
351
  }
419
352
  /**
420
353
  * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
@@ -422,40 +355,32 @@ class BeeDebug {
422
355
  *
423
356
  * @param options
424
357
  */
425
- getVersions(options) {
426
- return __awaiter(this, void 0, void 0, function* () {
427
- (0, type_1.assertRequestOptions)(options);
428
- return status.getVersions(this.getKy(options));
429
- });
358
+ async getVersions(options) {
359
+ (0, type_1.assertRequestOptions)(options);
360
+ return status.getVersions(this.getKyOptionsForCall(options));
430
361
  }
431
362
  /**
432
363
  * Get reserve state
433
364
  */
434
- getReserveState(options) {
435
- return __awaiter(this, void 0, void 0, function* () {
436
- (0, type_1.assertRequestOptions)(options);
437
- return states.getReserveState(this.getKy(options));
438
- });
365
+ async getReserveState(options) {
366
+ (0, type_1.assertRequestOptions)(options);
367
+ return states.getReserveState(this.getKyOptionsForCall(options));
439
368
  }
440
369
  /**
441
370
  * Get chain state
442
371
  */
443
- getChainState(options) {
444
- return __awaiter(this, void 0, void 0, function* () {
445
- (0, type_1.assertRequestOptions)(options);
446
- return states.getChainState(this.getKy(options));
447
- });
372
+ async getChainState(options) {
373
+ (0, type_1.assertRequestOptions)(options);
374
+ return states.getChainState(this.getKyOptionsForCall(options));
448
375
  }
449
376
  /**
450
377
  * Get wallet balances for xDai and BZZ of the Bee node
451
378
  *
452
379
  * @param options
453
380
  */
454
- getWalletBalance(options) {
455
- return __awaiter(this, void 0, void 0, function* () {
456
- (0, type_1.assertRequestOptions)(options);
457
- return states.getWalletBalance(this.getKy(options));
458
- });
381
+ async getWalletBalance(options) {
382
+ (0, type_1.assertRequestOptions)(options);
383
+ return states.getWalletBalance(this.getKyOptionsForCall(options));
459
384
  }
460
385
  /**
461
386
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
@@ -474,23 +399,21 @@ class BeeDebug {
474
399
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
475
400
  * @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
476
401
  */
477
- createPostageBatch(amount, depth, options) {
478
- return __awaiter(this, void 0, void 0, function* () {
479
- (0, type_1.assertPostageBatchOptions)(options);
480
- (0, type_1.assertPositiveInteger)(amount);
481
- (0, type_1.assertNonNegativeInteger)(depth);
482
- if (depth < types_1.STAMPS_DEPTH_MIN) {
483
- throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
484
- }
485
- if (depth > types_1.STAMPS_DEPTH_MAX) {
486
- throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
487
- }
488
- const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
489
- if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== false) {
490
- yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
491
- }
492
- return stamp;
493
- });
402
+ async createPostageBatch(amount, depth, options) {
403
+ (0, type_1.assertPostageBatchOptions)(options);
404
+ (0, type_1.assertPositiveInteger)(amount);
405
+ (0, type_1.assertNonNegativeInteger)(depth);
406
+ if (depth < types_1.STAMPS_DEPTH_MIN) {
407
+ throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
408
+ }
409
+ if (depth > types_1.STAMPS_DEPTH_MAX) {
410
+ throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
411
+ }
412
+ const stamp = await stamps.createPostageBatch(this.getKyOptionsForCall(options), amount, depth, options);
413
+ if (options?.waitForUsable !== false) {
414
+ await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
415
+ }
416
+ return stamp;
494
417
  }
495
418
  /**
496
419
  * Topup a fresh amount of BZZ to given Postage Batch.
@@ -507,13 +430,11 @@ class BeeDebug {
507
430
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
508
431
  * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
509
432
  */
510
- topUpBatch(postageBatchId, amount, options) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- (0, type_1.assertRequestOptions)(options);
513
- (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
514
- (0, type_1.assertBatchId)(postageBatchId);
515
- yield stamps.topUpBatch(this.getKy(options), postageBatchId, amount);
516
- });
433
+ async topUpBatch(postageBatchId, amount, options) {
434
+ (0, type_1.assertRequestOptions)(options);
435
+ (0, type_1.assertNonNegativeInteger)(amount, 'Amount');
436
+ (0, type_1.assertBatchId)(postageBatchId);
437
+ await stamps.topUpBatch(this.getKyOptionsForCall(options), postageBatchId, amount);
517
438
  }
518
439
  /**
519
440
  * Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
@@ -531,13 +452,11 @@ class BeeDebug {
531
452
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
532
453
  * @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
533
454
  */
534
- diluteBatch(postageBatchId, depth, options) {
535
- return __awaiter(this, void 0, void 0, function* () {
536
- (0, type_1.assertRequestOptions)(options);
537
- (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
538
- (0, type_1.assertBatchId)(postageBatchId);
539
- yield stamps.diluteBatch(this.getKy(options), postageBatchId, depth);
540
- });
455
+ async diluteBatch(postageBatchId, depth, options) {
456
+ (0, type_1.assertRequestOptions)(options);
457
+ (0, type_1.assertNonNegativeInteger)(depth, 'Depth');
458
+ (0, type_1.assertBatchId)(postageBatchId);
459
+ await stamps.diluteBatch(this.getKyOptionsForCall(options), postageBatchId, depth);
541
460
  }
542
461
  /**
543
462
  * Return details for specific postage batch.
@@ -547,12 +466,10 @@ class BeeDebug {
547
466
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
548
467
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
549
468
  */
550
- getPostageBatch(postageBatchId, options) {
551
- return __awaiter(this, void 0, void 0, function* () {
552
- (0, type_1.assertRequestOptions)(options);
553
- (0, type_1.assertBatchId)(postageBatchId);
554
- return stamps.getPostageBatch(this.getKy(options), postageBatchId);
555
- });
469
+ async getPostageBatch(postageBatchId, options) {
470
+ (0, type_1.assertRequestOptions)(options);
471
+ (0, type_1.assertBatchId)(postageBatchId);
472
+ return stamps.getPostageBatch(this.getKyOptionsForCall(options), postageBatchId);
556
473
  }
557
474
  /**
558
475
  * Return detailed information related to buckets for specific postage batch.
@@ -562,12 +479,10 @@ class BeeDebug {
562
479
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
563
480
  * @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
564
481
  */
565
- getPostageBatchBuckets(postageBatchId, options) {
566
- return __awaiter(this, void 0, void 0, function* () {
567
- (0, type_1.assertRequestOptions)(options);
568
- (0, type_1.assertBatchId)(postageBatchId);
569
- return stamps.getPostageBatchBuckets(this.getKy(options), postageBatchId);
570
- });
482
+ async getPostageBatchBuckets(postageBatchId, options) {
483
+ (0, type_1.assertRequestOptions)(options);
484
+ (0, type_1.assertBatchId)(postageBatchId);
485
+ return stamps.getPostageBatchBuckets(this.getKyOptionsForCall(options), postageBatchId);
571
486
  }
572
487
  /**
573
488
  * Return all postage batches that has the node available.
@@ -575,31 +490,25 @@ class BeeDebug {
575
490
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
576
491
  * @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
577
492
  */
578
- getAllPostageBatch(options) {
579
- return __awaiter(this, void 0, void 0, function* () {
580
- (0, type_1.assertRequestOptions)(options);
581
- return stamps.getAllPostageBatches(this.getKy(options));
582
- });
493
+ async getAllPostageBatch(options) {
494
+ (0, type_1.assertRequestOptions)(options);
495
+ return stamps.getAllPostageBatches(this.getKyOptionsForCall(options));
583
496
  }
584
497
  /**
585
498
  * Return lists of all current pending transactions that the Bee made
586
499
  */
587
- getAllPendingTransactions(options) {
588
- return __awaiter(this, void 0, void 0, function* () {
589
- (0, type_1.assertRequestOptions)(options);
590
- return transactions.getAllTransactions(this.getKy(options));
591
- });
500
+ async getAllPendingTransactions(options) {
501
+ (0, type_1.assertRequestOptions)(options);
502
+ return transactions.getAllTransactions(this.getKyOptionsForCall(options));
592
503
  }
593
504
  /**
594
505
  * Return transaction information for specific transaction
595
506
  * @param transactionHash
596
507
  */
597
- getPendingTransaction(transactionHash, options) {
598
- return __awaiter(this, void 0, void 0, function* () {
599
- (0, type_1.assertRequestOptions)(options);
600
- (0, type_1.assertTransactionHash)(transactionHash);
601
- return transactions.getTransaction(this.getKy(options), transactionHash);
602
- });
508
+ async getPendingTransaction(transactionHash, options) {
509
+ (0, type_1.assertRequestOptions)(options);
510
+ (0, type_1.assertTransactionHash)(transactionHash);
511
+ return transactions.getTransaction(this.getKyOptionsForCall(options), transactionHash);
603
512
  }
604
513
  /**
605
514
  * Rebroadcast already created transaction.
@@ -607,38 +516,32 @@ class BeeDebug {
607
516
  *
608
517
  * @param transactionHash
609
518
  */
610
- rebroadcastPendingTransaction(transactionHash, options) {
611
- return __awaiter(this, void 0, void 0, function* () {
612
- (0, type_1.assertRequestOptions)(options);
613
- (0, type_1.assertTransactionHash)(transactionHash);
614
- return transactions.rebroadcastTransaction(this.getKy(options), transactionHash);
615
- });
519
+ async rebroadcastPendingTransaction(transactionHash, options) {
520
+ (0, type_1.assertRequestOptions)(options);
521
+ (0, type_1.assertTransactionHash)(transactionHash);
522
+ return transactions.rebroadcastTransaction(this.getKyOptionsForCall(options), transactionHash);
616
523
  }
617
524
  /**
618
525
  * Cancel currently pending transaction
619
526
  * @param transactionHash
620
527
  * @param gasPrice
621
528
  */
622
- cancelPendingTransaction(transactionHash, gasPrice, options) {
623
- return __awaiter(this, void 0, void 0, function* () {
624
- (0, type_1.assertRequestOptions)(options);
625
- (0, type_1.assertTransactionHash)(transactionHash);
626
- if (gasPrice) {
627
- (0, type_1.assertNonNegativeInteger)(gasPrice);
628
- }
629
- return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
630
- });
529
+ async cancelPendingTransaction(transactionHash, gasPrice, options) {
530
+ (0, type_1.assertRequestOptions)(options);
531
+ (0, type_1.assertTransactionHash)(transactionHash);
532
+ if (gasPrice) {
533
+ (0, type_1.assertNonNegativeInteger)(gasPrice);
534
+ }
535
+ return transactions.cancelTransaction(this.getKyOptionsForCall(options), transactionHash, gasPrice);
631
536
  }
632
537
  /**
633
538
  * Gets the staked amount of BZZ (in PLUR unit) as number string.
634
539
  *
635
540
  * @param options
636
541
  */
637
- getStake(options) {
638
- return __awaiter(this, void 0, void 0, function* () {
639
- (0, type_1.assertRequestOptions)(options);
640
- return stake.getStake(this.getKy(options));
641
- });
542
+ async getStake(options) {
543
+ (0, type_1.assertRequestOptions)(options);
544
+ return stake.getStake(this.getKyOptionsForCall(options));
642
545
  }
643
546
  /**
644
547
  * Deposits given amount of BZZ token (in PLUR unit).
@@ -648,31 +551,24 @@ class BeeDebug {
648
551
  * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
649
552
  * @param options
650
553
  */
651
- depositStake(amount, options) {
652
- return __awaiter(this, void 0, void 0, function* () {
653
- (0, type_1.assertRequestOptions)(options);
654
- (0, type_1.assertTransactionOptions)(options);
655
- yield stake.stake(this.getKy(options), amount, options);
656
- });
657
- }
658
- waitForUsablePostageStamp(id, timeout = 120000) {
659
- return __awaiter(this, void 0, void 0, function* () {
660
- const TIME_STEP = 1500;
661
- for (let time = 0; time < timeout; time += TIME_STEP) {
662
- const stamp = yield this.getPostageBatch(id);
663
- if (stamp.usable) {
664
- return;
665
- }
666
- yield (0, sleep_1.sleep)(TIME_STEP);
554
+ async depositStake(amount, options) {
555
+ (0, type_1.assertRequestOptions)(options);
556
+ (0, type_1.assertTransactionOptions)(options);
557
+ await stake.stake(this.getKyOptionsForCall(options), amount, options);
558
+ }
559
+ async waitForUsablePostageStamp(id, timeout = 120000) {
560
+ const TIME_STEP = 1500;
561
+ for (let time = 0; time < timeout; time += TIME_STEP) {
562
+ const stamp = await this.getPostageBatch(id);
563
+ if (stamp.usable) {
564
+ return;
667
565
  }
668
- throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
669
- });
670
- }
671
- getKy(options) {
672
- if (!options) {
673
- return this.ky;
566
+ await (0, sleep_1.sleep)(TIME_STEP);
674
567
  }
675
- return this.ky.extend(options);
568
+ throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
569
+ }
570
+ getKyOptionsForCall(options) {
571
+ return (0, merge_1.deepMerge)(this.kyOptions, options);
676
572
  }
677
573
  }
678
574
  exports.BeeDebug = BeeDebug;