@ethersphere/bee-js 4.0.0 → 4.1.0

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 (199) hide show
  1. package/README.md +3 -14
  2. package/dist/cjs/{bee-debug.js → src/bee-debug.js} +31 -8
  3. package/dist/cjs/{bee.js → src/bee.js} +12 -10
  4. package/dist/cjs/{chunk → src/chunk}/bmt.js +0 -0
  5. package/dist/cjs/{chunk → src/chunk}/cac.js +0 -0
  6. package/dist/cjs/{chunk → src/chunk}/serialize.js +0 -0
  7. package/dist/cjs/{chunk → src/chunk}/signer.js +0 -0
  8. package/dist/cjs/{chunk → src/chunk}/soc.js +0 -0
  9. package/dist/cjs/{chunk → src/chunk}/span.js +0 -0
  10. package/dist/cjs/{feed → src/feed}/identifier.js +0 -0
  11. package/dist/cjs/{feed → src/feed}/index.js +0 -0
  12. package/dist/cjs/{feed → src/feed}/json.js +0 -0
  13. package/dist/cjs/{feed → src/feed}/retrievable.js +0 -0
  14. package/dist/cjs/{feed → src/feed}/topic.js +0 -0
  15. package/dist/cjs/{feed → src/feed}/type.js +0 -0
  16. package/dist/cjs/{index.js → src/index.js} +0 -0
  17. package/dist/cjs/{modules → src/modules}/bytes.js +0 -0
  18. package/dist/cjs/{modules → src/modules}/bzz.js +0 -0
  19. package/dist/cjs/{modules → src/modules}/chunk.js +0 -0
  20. package/dist/cjs/{modules → src/modules}/debug/balance.js +0 -0
  21. package/dist/cjs/{modules → src/modules}/debug/chequebook.js +0 -0
  22. package/dist/cjs/{modules → src/modules}/debug/chunk.js +0 -0
  23. package/dist/cjs/{modules → src/modules}/debug/connectivity.js +0 -0
  24. package/dist/cjs/{modules → src/modules}/debug/settlements.js +0 -0
  25. package/dist/cjs/{modules → src/modules}/debug/stamps.js +0 -0
  26. package/dist/cjs/{modules → src/modules}/debug/states.js +18 -1
  27. package/dist/cjs/{modules → src/modules}/debug/status.js +0 -0
  28. package/dist/cjs/{modules → src/modules}/debug/tag.js +0 -0
  29. package/dist/cjs/{modules → src/modules}/debug/transactions.js +0 -0
  30. package/dist/cjs/{modules → src/modules}/feed.js +0 -0
  31. package/dist/cjs/{modules → src/modules}/pinning.js +0 -0
  32. package/dist/cjs/{modules → src/modules}/pss.js +0 -0
  33. package/dist/cjs/{modules → src/modules}/soc.js +0 -0
  34. package/dist/cjs/{modules → src/modules}/status.js +0 -0
  35. package/dist/cjs/{modules → src/modules}/stewardship.js +0 -0
  36. package/dist/cjs/{modules → src/modules}/tag.js +0 -0
  37. package/dist/cjs/{types → src/types}/debug.js +0 -0
  38. package/dist/cjs/{types → src/types}/index.js +0 -0
  39. package/dist/cjs/{types → src/types}/ky-options.js +0 -0
  40. package/dist/cjs/{types → src/types}/ky-universal/common.js +0 -0
  41. package/dist/cjs/{types → src/types}/ky-universal/hooks.js +0 -0
  42. package/dist/cjs/{types → src/types}/ky-universal/retry.js +0 -0
  43. package/dist/cjs/{utils → src/utils}/bytes.js +0 -0
  44. package/dist/cjs/{utils → src/utils}/collection.browser.js +0 -0
  45. package/dist/cjs/{utils → src/utils}/collection.js +0 -0
  46. package/dist/cjs/{utils → src/utils}/collection.node.js +0 -0
  47. package/dist/cjs/{utils → src/utils}/data.browser.js +0 -0
  48. package/dist/cjs/{utils → src/utils}/data.js +0 -0
  49. package/dist/cjs/{utils → src/utils}/error.js +0 -0
  50. package/dist/cjs/{utils → src/utils}/eth.js +0 -0
  51. package/dist/cjs/{utils → src/utils}/expose.js +0 -0
  52. package/dist/cjs/{utils → src/utils}/file.js +0 -0
  53. package/dist/cjs/{utils → src/utils}/hash.js +0 -0
  54. package/dist/cjs/{utils → src/utils}/headers.js +0 -0
  55. package/dist/cjs/{utils → src/utils}/hex.js +0 -0
  56. package/dist/cjs/{utils → src/utils}/http.js +6 -0
  57. package/dist/cjs/{utils → src/utils}/merge.js +0 -0
  58. package/dist/cjs/{utils → src/utils}/pss.js +0 -0
  59. package/dist/cjs/{utils → src/utils}/reference.js +0 -0
  60. package/dist/cjs/{utils → src/utils}/stamps.js +0 -0
  61. package/dist/cjs/{utils → src/utils}/stream.js +0 -0
  62. package/dist/cjs/{utils → src/utils}/tar.js +0 -0
  63. package/dist/cjs/{utils → src/utils}/type.js +66 -2
  64. package/dist/cjs/{utils → src/utils}/uint64.js +0 -0
  65. package/dist/cjs/{utils → src/utils}/url.js +0 -0
  66. package/dist/cjs/test/utils.js +419 -0
  67. package/dist/index.browser.min.js +1 -1
  68. package/dist/index.browser.min.js.map +1 -1
  69. package/dist/mjs/{bee-debug.js → src/bee-debug.js} +40 -10
  70. package/dist/mjs/{bee.js → src/bee.js} +15 -13
  71. package/dist/mjs/{chunk → src/chunk}/bmt.js +0 -0
  72. package/dist/mjs/{chunk → src/chunk}/cac.js +0 -0
  73. package/dist/mjs/{chunk → src/chunk}/serialize.js +0 -0
  74. package/dist/mjs/{chunk → src/chunk}/signer.js +0 -0
  75. package/dist/mjs/{chunk → src/chunk}/soc.js +0 -0
  76. package/dist/mjs/{chunk → src/chunk}/span.js +0 -0
  77. package/dist/mjs/{feed → src/feed}/identifier.js +0 -0
  78. package/dist/mjs/{feed → src/feed}/index.js +0 -0
  79. package/dist/mjs/{feed → src/feed}/json.js +0 -0
  80. package/dist/mjs/{feed → src/feed}/retrievable.js +0 -0
  81. package/dist/mjs/{feed → src/feed}/topic.js +0 -0
  82. package/dist/mjs/{feed → src/feed}/type.js +0 -0
  83. package/dist/mjs/{index.js → src/index.js} +0 -0
  84. package/dist/mjs/{modules → src/modules}/bytes.js +0 -0
  85. package/dist/mjs/{modules → src/modules}/bzz.js +0 -0
  86. package/dist/mjs/{modules → src/modules}/chunk.js +0 -0
  87. package/dist/mjs/{modules → src/modules}/debug/balance.js +0 -0
  88. package/dist/mjs/{modules → src/modules}/debug/chequebook.js +0 -0
  89. package/dist/mjs/{modules → src/modules}/debug/chunk.js +0 -0
  90. package/dist/mjs/{modules → src/modules}/debug/connectivity.js +0 -0
  91. package/dist/mjs/{modules → src/modules}/debug/settlements.js +0 -0
  92. package/dist/mjs/{modules → src/modules}/debug/stamps.js +0 -0
  93. package/dist/mjs/{modules → src/modules}/debug/states.js +17 -0
  94. package/dist/mjs/{modules → src/modules}/debug/status.js +0 -0
  95. package/dist/mjs/{modules → src/modules}/debug/tag.js +0 -0
  96. package/dist/mjs/{modules → src/modules}/debug/transactions.js +0 -0
  97. package/dist/mjs/{modules → src/modules}/feed.js +0 -0
  98. package/dist/mjs/{modules → src/modules}/pinning.js +0 -0
  99. package/dist/mjs/{modules → src/modules}/pss.js +0 -0
  100. package/dist/mjs/{modules → src/modules}/soc.js +0 -0
  101. package/dist/mjs/{modules → src/modules}/status.js +0 -0
  102. package/dist/mjs/{modules → src/modules}/stewardship.js +0 -0
  103. package/dist/mjs/{modules → src/modules}/tag.js +0 -0
  104. package/dist/mjs/{types → src/types}/debug.js +0 -0
  105. package/dist/mjs/{types → src/types}/index.js +0 -0
  106. package/dist/mjs/{types → src/types}/ky-options.js +0 -0
  107. package/dist/mjs/{types → src/types}/ky-universal/common.js +0 -0
  108. package/dist/mjs/{types → src/types}/ky-universal/hooks.js +0 -0
  109. package/dist/mjs/{types → src/types}/ky-universal/retry.js +0 -0
  110. package/dist/mjs/{utils → src/utils}/bytes.js +0 -0
  111. package/dist/mjs/{utils → src/utils}/collection.browser.js +0 -0
  112. package/dist/mjs/{utils → src/utils}/collection.js +0 -0
  113. package/dist/mjs/{utils → src/utils}/collection.node.js +0 -0
  114. package/dist/mjs/{utils → src/utils}/data.browser.js +0 -0
  115. package/dist/mjs/{utils → src/utils}/data.js +0 -0
  116. package/dist/mjs/{utils → src/utils}/error.js +0 -0
  117. package/dist/mjs/{utils → src/utils}/eth.js +0 -0
  118. package/dist/mjs/{utils → src/utils}/expose.js +0 -0
  119. package/dist/mjs/{utils → src/utils}/file.js +0 -0
  120. package/dist/mjs/{utils → src/utils}/hash.js +0 -0
  121. package/dist/mjs/{utils → src/utils}/headers.js +0 -0
  122. package/dist/mjs/{utils → src/utils}/hex.js +0 -0
  123. package/dist/mjs/{utils → src/utils}/http.js +7 -0
  124. package/dist/mjs/{utils → src/utils}/merge.js +0 -0
  125. package/dist/mjs/{utils → src/utils}/pss.js +0 -0
  126. package/dist/mjs/{utils → src/utils}/reference.js +0 -0
  127. package/dist/mjs/{utils → src/utils}/stamps.js +0 -0
  128. package/dist/mjs/{utils → src/utils}/stream.js +0 -0
  129. package/dist/mjs/{utils → src/utils}/tar.js +0 -0
  130. package/dist/mjs/{utils → src/utils}/type.js +72 -2
  131. package/dist/mjs/{utils → src/utils}/uint64.js +0 -0
  132. package/dist/mjs/{utils → src/utils}/url.js +0 -0
  133. package/dist/mjs/test/utils.js +458 -0
  134. package/dist/types/{bee-debug.d.ts → src/bee-debug.d.ts} +8 -1
  135. package/dist/types/{bee.d.ts → src/bee.d.ts} +11 -10
  136. package/dist/types/{chunk → src/chunk}/bmt.d.ts +0 -0
  137. package/dist/types/{chunk → src/chunk}/cac.d.ts +0 -0
  138. package/dist/types/{chunk → src/chunk}/serialize.d.ts +0 -0
  139. package/dist/types/{chunk → src/chunk}/signer.d.ts +0 -0
  140. package/dist/types/{chunk → src/chunk}/soc.d.ts +0 -0
  141. package/dist/types/{chunk → src/chunk}/span.d.ts +0 -0
  142. package/dist/types/{feed → src/feed}/identifier.d.ts +0 -0
  143. package/dist/types/{feed → src/feed}/index.d.ts +0 -0
  144. package/dist/types/{feed → src/feed}/json.d.ts +0 -0
  145. package/dist/types/{feed → src/feed}/retrievable.d.ts +0 -0
  146. package/dist/types/{feed → src/feed}/topic.d.ts +0 -0
  147. package/dist/types/{feed → src/feed}/type.d.ts +0 -0
  148. package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
  149. package/dist/types/{modules → src/modules}/bytes.d.ts +0 -0
  150. package/dist/types/{modules → src/modules}/bzz.d.ts +0 -0
  151. package/dist/types/{modules → src/modules}/chunk.d.ts +0 -0
  152. package/dist/types/{modules → src/modules}/debug/balance.d.ts +0 -0
  153. package/dist/types/{modules → src/modules}/debug/chequebook.d.ts +0 -0
  154. package/dist/types/{modules → src/modules}/debug/chunk.d.ts +0 -0
  155. package/dist/types/{modules → src/modules}/debug/connectivity.d.ts +0 -0
  156. package/dist/types/{modules → src/modules}/debug/settlements.d.ts +0 -0
  157. package/dist/types/{modules → src/modules}/debug/stamps.d.ts +0 -0
  158. package/dist/types/{modules → src/modules}/debug/states.d.ts +7 -1
  159. package/dist/types/{modules → src/modules}/debug/status.d.ts +0 -0
  160. package/dist/types/{modules → src/modules}/debug/tag.d.ts +0 -0
  161. package/dist/types/{modules → src/modules}/debug/transactions.d.ts +0 -0
  162. package/dist/types/{modules → src/modules}/feed.d.ts +0 -0
  163. package/dist/types/{modules → src/modules}/pinning.d.ts +0 -0
  164. package/dist/types/{modules → src/modules}/pss.d.ts +0 -0
  165. package/dist/types/{modules → src/modules}/soc.d.ts +0 -0
  166. package/dist/types/{modules → src/modules}/status.d.ts +0 -0
  167. package/dist/types/{modules → src/modules}/stewardship.d.ts +0 -0
  168. package/dist/types/{modules → src/modules}/tag.d.ts +0 -0
  169. package/dist/types/{types → src/types}/debug.d.ts +18 -0
  170. package/dist/types/{types → src/types}/index.d.ts +23 -1
  171. package/dist/types/{types → src/types}/ky-options.d.ts +0 -0
  172. package/dist/types/{types → src/types}/ky-universal/common.d.ts +0 -0
  173. package/dist/types/{types → src/types}/ky-universal/hooks.d.ts +0 -0
  174. package/dist/types/{types → src/types}/ky-universal/retry.d.ts +0 -0
  175. package/dist/types/{utils → src/utils}/bytes.d.ts +0 -0
  176. package/dist/types/{utils → src/utils}/collection.browser.d.ts +0 -0
  177. package/dist/types/{utils → src/utils}/collection.d.ts +0 -0
  178. package/dist/types/{utils → src/utils}/collection.node.d.ts +0 -0
  179. package/dist/types/{utils → src/utils}/data.browser.d.ts +0 -0
  180. package/dist/types/{utils → src/utils}/data.d.ts +0 -0
  181. package/dist/types/{utils → src/utils}/error.d.ts +0 -0
  182. package/dist/types/{utils → src/utils}/eth.d.ts +0 -0
  183. package/dist/types/{utils → src/utils}/expose.d.ts +0 -0
  184. package/dist/types/{utils → src/utils}/file.d.ts +0 -0
  185. package/dist/types/{utils → src/utils}/hash.d.ts +0 -0
  186. package/dist/types/{utils → src/utils}/headers.d.ts +0 -0
  187. package/dist/types/{utils → src/utils}/hex.d.ts +0 -0
  188. package/dist/types/{utils → src/utils}/http.d.ts +0 -0
  189. package/dist/types/{utils → src/utils}/merge.d.ts +0 -0
  190. package/dist/types/{utils → src/utils}/pss.d.ts +0 -0
  191. package/dist/types/{utils → src/utils}/reference.d.ts +0 -0
  192. package/dist/types/{utils → src/utils}/stamps.d.ts +0 -0
  193. package/dist/types/{utils → src/utils}/stream.d.ts +0 -0
  194. package/dist/types/{utils → src/utils}/tar.d.ts +0 -0
  195. package/dist/types/{utils → src/utils}/type.d.ts +16 -1
  196. package/dist/types/{utils → src/utils}/uint64.d.ts +0 -0
  197. package/dist/types/{utils → src/utils}/url.d.ts +0 -0
  198. package/dist/types/test/utils.d.ts +119 -0
  199. package/package.json +5 -4
@@ -37,13 +37,14 @@ import * as settlements from "./modules/debug/settlements.js";
37
37
  import * as status from "./modules/debug/status.js";
38
38
  import * as transactions from "./modules/debug/transactions.js";
39
39
  import * as states from "./modules/debug/states.js";
40
- import { BeeArgumentError } from "./utils/error.js";
40
+ import { BeeArgumentError, BeeError } from "./utils/error.js";
41
41
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
42
- import { assertAddress, assertBatchId, assertBoolean, assertCashoutOptions, assertNonNegativeInteger, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
42
+ import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
43
43
  import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
44
44
  import * as tag from "./modules/debug/tag.js";
45
45
  import * as stamps from "./modules/debug/stamps.js";
46
46
  import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
47
+ import { sleep } from "../test/utils.js";
47
48
  export class BeeDebug {
48
49
  constructor(url, options) {
49
50
  var _a;
@@ -501,6 +502,19 @@ export class BeeDebug {
501
502
  return states.getChainState(this.getKy(options));
502
503
  });
503
504
  }
505
+ /**
506
+ * Get wallet balances for xDai and BZZ of the Bee node
507
+ *
508
+ * @param options
509
+ */
510
+
511
+
512
+ getWalletBalance(options) {
513
+ return __awaiter(this, void 0, void 0, function* () {
514
+ assertRequestOptions(options);
515
+ return states.getWalletBalance(this.getKy(options));
516
+ });
517
+ }
504
518
  /**
505
519
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
506
520
  *
@@ -522,8 +536,8 @@ export class BeeDebug {
522
536
 
523
537
  createPostageBatch(amount, depth, options) {
524
538
  return __awaiter(this, void 0, void 0, function* () {
525
- assertRequestOptions(options);
526
- assertNonNegativeInteger(amount);
539
+ assertPostageBatchOptions(options);
540
+ assertPositiveInteger(amount);
527
541
  assertNonNegativeInteger(depth);
528
542
 
529
543
  if (depth < STAMPS_DEPTH_MIN) {
@@ -534,15 +548,13 @@ export class BeeDebug {
534
548
  throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
535
549
  }
536
550
 
537
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
538
- assertNonNegativeInteger(options.gasPrice);
539
- }
551
+ const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
540
552
 
541
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
542
- assertBoolean(options.immutableFlag);
553
+ if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
554
+ yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
543
555
  }
544
556
 
545
- return stamps.createPostageBatch(this.getKy(options), amount, depth, options);
557
+ return stamp;
546
558
  });
547
559
  }
548
560
  /**
@@ -703,6 +715,24 @@ export class BeeDebug {
703
715
  });
704
716
  }
705
717
 
718
+ waitForUsablePostageStamp(id, timeout = 120000) {
719
+ return __awaiter(this, void 0, void 0, function* () {
720
+ const TIME_STEP = 1500;
721
+
722
+ for (let time = 0; time < timeout; time += TIME_STEP) {
723
+ const stamp = yield this.getPostageBatch(id);
724
+
725
+ if (stamp.usable) {
726
+ return;
727
+ }
728
+
729
+ yield sleep(TIME_STEP);
730
+ }
731
+
732
+ throw new BeeError('Timeout on waiting for postage stamp to become usable');
733
+ });
734
+ }
735
+
706
736
  getKy(options) {
707
737
  if (!options) {
708
738
  return this.ky;
@@ -50,14 +50,15 @@ import { createFeedManifest } from "./modules/feed.js";
50
50
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
51
51
  import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
52
52
  import { wrapBytesWithHelpers } from "./utils/bytes.js";
53
- import { assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
54
- import { setJsonData, getJsonData } from "./feed/json.js";
55
- import { makeCollectionFromFileList, assertCollection } from "./utils/collection.js";
53
+ import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
54
+ import { getJsonData, setJsonData } from "./feed/json.js";
55
+ import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
56
56
  import { makeCollectionFromFS } from "./utils/collection.node.js";
57
57
  import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
58
58
  import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
59
59
  import { isReadable } from "./utils/stream.js";
60
60
  import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
61
+ import { ReferenceType } from '@ethersphere/swarm-cid';
61
62
  /**
62
63
  * The main component that abstracts operations available on the main Bee API.
63
64
  *
@@ -254,21 +255,21 @@ export class Bee {
254
255
  const fileOptions = Object.assign({
255
256
  contentType
256
257
  }, options);
257
- return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
258
+ return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
258
259
  } else if (isReadable(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
259
260
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
260
261
  const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
261
262
  yield this.updateTag(options.tag, result.reference);
262
- return result;
263
+ return addCidConversionFunction(result, ReferenceType.MANIFEST);
263
264
  } else {
264
- return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
265
+ return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
265
266
  }
266
267
  });
267
268
  }
268
269
  /**
269
270
  * Download single file.
270
271
  *
271
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
272
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
272
273
  * @param path If reference points to manifest, then this parameter defines path to the file
273
274
  * @param options Options that affects the request behavior
274
275
  * @throws TypeError if some of the input parameters is not expected type
@@ -282,14 +283,14 @@ export class Bee {
282
283
  downloadFile(reference, path = '', options) {
283
284
  return __awaiter(this, void 0, void 0, function* () {
284
285
  assertRequestOptions(options);
285
- assertReferenceOrEns(reference);
286
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
286
287
  return bzz.downloadFile(this.getKy(options), reference, path);
287
288
  });
288
289
  }
289
290
  /**
290
291
  * Download single file as a readable stream
291
292
  *
292
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
293
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
293
294
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
294
295
  * @param options Options that affects the request behavior
295
296
  * @throws TypeError if some of the input parameters is not expected type
@@ -303,7 +304,7 @@ export class Bee {
303
304
  downloadReadableFile(reference, path = '', options) {
304
305
  return __awaiter(this, void 0, void 0, function* () {
305
306
  assertRequestOptions(options);
306
- assertReferenceOrEns(reference);
307
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
307
308
  return bzz.downloadFileReadable(this.getKy(options), reference, path);
308
309
  });
309
310
  }
@@ -330,7 +331,7 @@ export class Bee {
330
331
  assertBatchId(postageBatchId);
331
332
  if (options) assertCollectionUploadOptions(options);
332
333
  const data = yield makeCollectionFromFileList(fileList);
333
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
334
+ return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
334
335
  });
335
336
  }
336
337
  /**
@@ -350,7 +351,7 @@ export class Bee {
350
351
  assertBatchId(postageBatchId);
351
352
  assertCollection(collection);
352
353
  if (options) assertCollectionUploadOptions(options);
353
- return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
354
+ return addCidConversionFunction(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), ReferenceType.MANIFEST);
354
355
  });
355
356
  }
356
357
  /**
@@ -376,7 +377,7 @@ export class Bee {
376
377
  assertBatchId(postageBatchId);
377
378
  if (options) assertCollectionUploadOptions(options);
378
379
  const data = yield makeCollectionFromFS(dir);
379
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
380
+ return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
380
381
  });
381
382
  }
382
383
  /**
@@ -832,6 +833,7 @@ export class Bee {
832
833
  *
833
834
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
834
835
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
836
+ * TODO: Once breaking add support for Feed CID
835
837
  */
836
838
 
837
839
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -32,6 +32,7 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
32
32
 
33
33
  import { http } from "../../utils/http.js";
34
34
  const RESERVE_STATE_ENDPOINT = 'reservestate';
35
+ const WALLET_ENDPOINT = 'wallet';
35
36
  const CHAIN_STATE_ENDPOINT = 'chainstate';
36
37
  /**
37
38
  * Get state of reserve
@@ -64,4 +65,20 @@ export function getChainState(ky) {
64
65
  });
65
66
  return response.data;
66
67
  });
68
+ }
69
+ /**
70
+ * Get wallet balances for xDai and BZZ of the node
71
+ *
72
+ * @param ky Ky debug instance
73
+ */
74
+
75
+ export function getWalletBalance(ky) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const response = yield http(ky, {
78
+ method: 'get',
79
+ path: `${WALLET_ENDPOINT}`,
80
+ responseType: 'json'
81
+ });
82
+ return response.data;
83
+ });
67
84
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -191,6 +191,13 @@ export function http(ky, config) {
191
191
  } else if (isHttpRequestError(e)) {
192
192
  throw new BeeRequestError(e.message, config);
193
193
  } else {
194
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
195
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
196
+ // expose the underlying problem.
197
+ if (e.cause) {
198
+ throw new BeeError(e.cause.message);
199
+ }
200
+
194
201
  throw new BeeError(e.message);
195
202
  }
196
203
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,8 +1,9 @@
1
1
  import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
2
- import { BeeArgumentError } from "./error.js";
2
+ import { BeeArgumentError, BeeError } from "./error.js";
3
3
  import { isFile } from "./file.js";
4
4
  import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js";
5
5
  import { isReadable } from "./stream.js";
6
+ import { decodeCid, encodeReference } from '@ethersphere/swarm-cid';
6
7
  export function isUint8Array(obj) {
7
8
  return obj instanceof Uint8Array;
8
9
  }
@@ -51,6 +52,10 @@ export function assertNonNegativeInteger(value, name = 'Value') {
51
52
  assertInteger(value, name);
52
53
  if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
53
54
  }
55
+ export function assertPositiveInteger(value, name = 'Value') {
56
+ assertInteger(value, name);
57
+ if (Number(value) <= 0) throw new BeeArgumentError(`${name} has to be bigger then zero`, value);
58
+ }
54
59
  export function assertReference(value) {
55
60
  try {
56
61
  assertHexString(value, REFERENCE_HEX_LENGTH);
@@ -84,10 +89,24 @@ export function assertReferenceOrEns(value) {
84
89
  * ethswarm.something- - INVALID
85
90
  * ethswarm.-something - INVALID
86
91
  * ethswarm.some-thing - VALID
92
+ *
93
+ * The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
94
+ *
95
+ * This part matches 2-63 character string that does not start or end with -
96
+ * [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
97
+ *
98
+ * For 1 character long string we use the part after |
99
+ * [^-.\/?:\s] <regexp2>
100
+ *
101
+ * This is terminated in a group with . character an repeated at least once
102
+ * (<regexp1>|<regexp2>\.)+
103
+ *
104
+ * This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
105
+ * ^(<regexp1>|<regexp2>\.)+<regexp1>$
87
106
  */
88
107
 
89
108
 
90
- const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
109
+ const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
91
110
  // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
92
111
  // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
93
112
 
@@ -95,6 +114,49 @@ export function assertReferenceOrEns(value) {
95
114
  throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
96
115
  }
97
116
  }
117
+ /**
118
+ * Function that mainly converts Swarm CID into hex encoded Swarm Reference
119
+ *
120
+ * @param value
121
+ * @param expectedCidType
122
+ */
123
+
124
+ export function makeReferenceOrEns(value, expectedCidType) {
125
+ var _a;
126
+
127
+ if (typeof value !== 'string') {
128
+ throw new TypeError('ReferenceCidOrEns has to be a string!');
129
+ }
130
+
131
+ try {
132
+ const result = decodeCid(value);
133
+
134
+ if (result.type !== expectedCidType) {
135
+ throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
136
+ }
137
+
138
+ return result.reference;
139
+ } catch (e) {
140
+ if (e instanceof BeeError) throw e;
141
+ }
142
+
143
+ assertReferenceOrEns(value);
144
+ return value;
145
+ }
146
+ /**
147
+ * Function that adds getter which converts the reference into CID base32 encoded string.
148
+ * @param result
149
+ * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
150
+ */
151
+
152
+ export function addCidConversionFunction(result, cidType) {
153
+ return Object.assign(Object.assign({}, result), {
154
+ get cid() {
155
+ return encodeReference(result.reference, cidType).toString();
156
+ }
157
+
158
+ });
159
+ }
98
160
  export function assertAddress(value) {
99
161
  assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
100
162
  }
@@ -258,6 +320,14 @@ export function assertPostageBatchOptions(value) {
258
320
  if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
259
321
  assertBoolean(options.immutableFlag);
260
322
  }
323
+
324
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
325
+ assertBoolean(options.waitForUsable);
326
+ }
327
+
328
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
329
+ assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
330
+ }
261
331
  }
262
332
  export function assertCashoutOptions(value) {
263
333
  if (value === undefined) {
File without changes
File without changes