@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
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Bee-js
2
2
 
3
3
  [![Tests](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml/badge.svg)](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml)
4
- [![Dependency Status](https://david-dm.org/ethersphere/bee-js.svg?style=flat-square)](https://david-dm.org/ethersphere/bee-js)
5
4
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_shield)
6
5
  [![](https://img.shields.io/badge/made%20by-Swarm-blue.svg?style=flat-square)](https://swarm.ethereum.org/)
7
6
  [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
@@ -110,25 +109,15 @@ npm i
110
109
 
111
110
  The tests run in both context: node and dom with Jest.
112
111
 
113
- To run the integration tests, you need to use our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project. Clone the repo, you can use our prebuilt Docker images with setting env. variables like:
114
-
115
- ```bash
116
- export BEE_VERSION="1.0.0-2572fa48"
117
- export BLOCKCHAIN_VERSION="1.2.0"
118
- export BEE_ENV_PREFIX="swarm-test"
119
- export BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory"
120
- ```
121
-
122
- Customize these values based on which Bee version you want to run. After the env. variables are set use the `./scripts/environment.sh` script with `start` parameter.
112
+ To run the integration tests, you need to spin up local Bee cluster using our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project.
113
+ In order to do that you have to have locally Docker running on your machine, but afterwards you can just simply run `npm run bee`, which spins up the
114
+ cluster and display Queen's logs. If you want to exit hit `CTRL+C`.
123
115
 
124
116
  If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and set them under env. variables `BEE_POSTAGE` and `BEE_PEER_POSTAGE`.
125
117
 
126
118
  By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633` and `http://localhost:11633`. These are the default values for the `bee-factory` script.
127
119
  If you want to use custom setup, you can change the behavior of tests to different addresses using environment variables `BEE_API_URL`, `BEE_DEBUG_API_URL`, `BEE_PEER_DEBUG_API_URL` and `BEE_PEER_API_URL`.
128
120
 
129
- In Visual Studio environment, the tests have been set up to run against your local bee node on `http://localhost:1633`
130
- To run Jest tests, choose the `vscode-jest-tests` CI job under the Run tab.
131
-
132
121
  There are also browser tests by Puppeteer, which also provide integrity testing.
133
122
  ```sh
134
123
  npm run test:browser
@@ -43,6 +43,7 @@ const types_1 = require("./types");
43
43
  const tag = __importStar(require("./modules/debug/tag"));
44
44
  const stamps = __importStar(require("./modules/debug/stamps"));
45
45
  const http_1 = require("./utils/http");
46
+ const utils_1 = require("../test/utils");
46
47
  class BeeDebug {
47
48
  constructor(url, options) {
48
49
  var _a;
@@ -431,6 +432,17 @@ class BeeDebug {
431
432
  return states.getChainState(this.getKy(options));
432
433
  });
433
434
  }
435
+ /**
436
+ * Get wallet balances for xDai and BZZ of the Bee node
437
+ *
438
+ * @param options
439
+ */
440
+ getWalletBalance(options) {
441
+ return __awaiter(this, void 0, void 0, function* () {
442
+ (0, type_1.assertRequestOptions)(options);
443
+ return states.getWalletBalance(this.getKy(options));
444
+ });
445
+ }
434
446
  /**
435
447
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
436
448
  *
@@ -450,8 +462,8 @@ class BeeDebug {
450
462
  */
451
463
  createPostageBatch(amount, depth, options) {
452
464
  return __awaiter(this, void 0, void 0, function* () {
453
- (0, type_1.assertRequestOptions)(options);
454
- (0, type_1.assertNonNegativeInteger)(amount);
465
+ (0, type_1.assertPostageBatchOptions)(options);
466
+ (0, type_1.assertPositiveInteger)(amount);
455
467
  (0, type_1.assertNonNegativeInteger)(depth);
456
468
  if (depth < types_1.STAMPS_DEPTH_MIN) {
457
469
  throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
@@ -459,13 +471,11 @@ class BeeDebug {
459
471
  if (depth > types_1.STAMPS_DEPTH_MAX) {
460
472
  throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
461
473
  }
462
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
463
- (0, type_1.assertNonNegativeInteger)(options.gasPrice);
474
+ const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
475
+ if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
476
+ yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
464
477
  }
465
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
466
- (0, type_1.assertBoolean)(options.immutableFlag);
467
- }
468
- return stamps.createPostageBatch(this.getKy(options), amount, depth, options);
478
+ return stamp;
469
479
  });
470
480
  }
471
481
  /**
@@ -605,6 +615,19 @@ class BeeDebug {
605
615
  return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
606
616
  });
607
617
  }
618
+ waitForUsablePostageStamp(id, timeout = 120000) {
619
+ return __awaiter(this, void 0, void 0, function* () {
620
+ const TIME_STEP = 1500;
621
+ for (let time = 0; time < timeout; time += TIME_STEP) {
622
+ const stamp = yield this.getPostageBatch(id);
623
+ if (stamp.usable) {
624
+ return;
625
+ }
626
+ yield (0, utils_1.sleep)(TIME_STEP);
627
+ }
628
+ throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
629
+ });
630
+ }
608
631
  getKy(options) {
609
632
  if (!options) {
610
633
  return this.ky;
@@ -57,6 +57,7 @@ const types_1 = require("./types");
57
57
  const http_1 = require("./utils/http");
58
58
  const stream_1 = require("./utils/stream");
59
59
  const retrievable_1 = require("./feed/retrievable");
60
+ const swarm_cid_1 = require("@ethersphere/swarm-cid");
60
61
  /**
61
62
  * The main component that abstracts operations available on the main Bee API.
62
63
  *
@@ -228,23 +229,23 @@ class Bee {
228
229
  const fileName = name !== null && name !== void 0 ? name : data.name;
229
230
  const contentType = data.type;
230
231
  const fileOptions = Object.assign({ contentType }, options);
231
- return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
232
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), swarm_cid_1.ReferenceType.MANIFEST);
232
233
  }
233
234
  else if ((0, stream_1.isReadable)(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
234
235
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
235
236
  const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
236
237
  yield this.updateTag(options.tag, result.reference);
237
- return result;
238
+ return (0, type_2.addCidConversionFunction)(result, swarm_cid_1.ReferenceType.MANIFEST);
238
239
  }
239
240
  else {
240
- return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
241
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), swarm_cid_1.ReferenceType.MANIFEST);
241
242
  }
242
243
  });
243
244
  }
244
245
  /**
245
246
  * Download single file.
246
247
  *
247
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
248
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
248
249
  * @param path If reference points to manifest, then this parameter defines path to the file
249
250
  * @param options Options that affects the request behavior
250
251
  * @throws TypeError if some of the input parameters is not expected type
@@ -256,14 +257,14 @@ class Bee {
256
257
  downloadFile(reference, path = '', options) {
257
258
  return __awaiter(this, void 0, void 0, function* () {
258
259
  (0, type_2.assertRequestOptions)(options);
259
- (0, type_2.assertReferenceOrEns)(reference);
260
+ reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
260
261
  return bzz.downloadFile(this.getKy(options), reference, path);
261
262
  });
262
263
  }
263
264
  /**
264
265
  * Download single file as a readable stream
265
266
  *
266
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
267
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
267
268
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
268
269
  * @param options Options that affects the request behavior
269
270
  * @throws TypeError if some of the input parameters is not expected type
@@ -275,7 +276,7 @@ class Bee {
275
276
  downloadReadableFile(reference, path = '', options) {
276
277
  return __awaiter(this, void 0, void 0, function* () {
277
278
  (0, type_2.assertRequestOptions)(options);
278
- (0, type_2.assertReferenceOrEns)(reference);
279
+ reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
279
280
  return bzz.downloadFileReadable(this.getKy(options), reference, path);
280
281
  });
281
282
  }
@@ -301,7 +302,7 @@ class Bee {
301
302
  if (options)
302
303
  (0, type_2.assertCollectionUploadOptions)(options);
303
304
  const data = yield (0, collection_1.makeCollectionFromFileList)(fileList);
304
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
305
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
305
306
  });
306
307
  }
307
308
  /**
@@ -320,7 +321,7 @@ class Bee {
320
321
  (0, collection_1.assertCollection)(collection);
321
322
  if (options)
322
323
  (0, type_2.assertCollectionUploadOptions)(options);
323
- return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
324
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
324
325
  });
325
326
  }
326
327
  /**
@@ -345,7 +346,7 @@ class Bee {
345
346
  if (options)
346
347
  (0, type_2.assertCollectionUploadOptions)(options);
347
348
  const data = yield (0, collection_node_1.makeCollectionFromFS)(dir);
348
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
349
+ return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
349
350
  });
350
351
  }
351
352
  /**
@@ -760,6 +761,7 @@ class Bee {
760
761
  *
761
762
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
762
763
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
764
+ * TODO: Once breaking add support for Feed CID
763
765
  */
764
766
  createFeedManifest(postageBatchId, type, topic, owner, options) {
765
767
  return __awaiter(this, void 0, void 0, function* () {
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
@@ -9,9 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getChainState = exports.getReserveState = void 0;
12
+ exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
13
13
  const http_1 = require("../../utils/http");
14
14
  const RESERVE_STATE_ENDPOINT = 'reservestate';
15
+ const WALLET_ENDPOINT = 'wallet';
15
16
  const CHAIN_STATE_ENDPOINT = 'chainstate';
16
17
  /**
17
18
  * Get state of reserve
@@ -45,3 +46,19 @@ function getChainState(ky) {
45
46
  });
46
47
  }
47
48
  exports.getChainState = getChainState;
49
+ /**
50
+ * Get wallet balances for xDai and BZZ of the node
51
+ *
52
+ * @param ky Ky debug instance
53
+ */
54
+ function getWalletBalance(ky) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const response = yield (0, http_1.http)(ky, {
57
+ method: 'get',
58
+ path: `${WALLET_ENDPOINT}`,
59
+ responseType: 'json',
60
+ });
61
+ return response.data;
62
+ });
63
+ }
64
+ exports.getWalletBalance = getWalletBalance;
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
@@ -154,6 +154,12 @@ function http(ky, config) {
154
154
  throw new error_1.BeeRequestError(e.message, config);
155
155
  }
156
156
  else {
157
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
158
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
159
+ // expose the underlying problem.
160
+ if (e.cause) {
161
+ throw new error_1.BeeError(e.cause.message);
162
+ }
157
163
  throw new error_1.BeeError(e.message);
158
164
  }
159
165
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReferenceOrEns = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
3
+ exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
4
4
  const types_1 = require("../types");
5
5
  const error_1 = require("./error");
6
6
  const file_1 = require("./file");
7
7
  const hex_1 = require("./hex");
8
8
  const stream_1 = require("./stream");
9
+ const swarm_cid_1 = require("@ethersphere/swarm-cid");
9
10
  function isUint8Array(obj) {
10
11
  return obj instanceof Uint8Array;
11
12
  }
@@ -68,6 +69,12 @@ function assertNonNegativeInteger(value, name = 'Value') {
68
69
  throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
69
70
  }
70
71
  exports.assertNonNegativeInteger = assertNonNegativeInteger;
72
+ function assertPositiveInteger(value, name = 'Value') {
73
+ assertInteger(value, name);
74
+ if (Number(value) <= 0)
75
+ throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
76
+ }
77
+ exports.assertPositiveInteger = assertPositiveInteger;
71
78
  function assertReference(value) {
72
79
  try {
73
80
  (0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
@@ -102,8 +109,22 @@ function assertReferenceOrEns(value) {
102
109
  * ethswarm.something- - INVALID
103
110
  * ethswarm.-something - INVALID
104
111
  * ethswarm.some-thing - VALID
112
+ *
113
+ * 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
114
+ *
115
+ * This part matches 2-63 character string that does not start or end with -
116
+ * [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
117
+ *
118
+ * For 1 character long string we use the part after |
119
+ * [^-.\/?:\s] <regexp2>
120
+ *
121
+ * This is terminated in a group with . character an repeated at least once
122
+ * (<regexp1>|<regexp2>\.)+
123
+ *
124
+ * This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
125
+ * ^(<regexp1>|<regexp2>\.)+<regexp1>$
105
126
  */
106
- const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/;
127
+ const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
107
128
  // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
108
129
  // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
109
130
  // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
@@ -112,6 +133,43 @@ function assertReferenceOrEns(value) {
112
133
  }
113
134
  }
114
135
  exports.assertReferenceOrEns = assertReferenceOrEns;
136
+ /**
137
+ * Function that mainly converts Swarm CID into hex encoded Swarm Reference
138
+ *
139
+ * @param value
140
+ * @param expectedCidType
141
+ */
142
+ function makeReferenceOrEns(value, expectedCidType) {
143
+ var _a;
144
+ if (typeof value !== 'string') {
145
+ throw new TypeError('ReferenceCidOrEns has to be a string!');
146
+ }
147
+ try {
148
+ const result = (0, swarm_cid_1.decodeCid)(value);
149
+ if (result.type !== expectedCidType) {
150
+ throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
151
+ }
152
+ return result.reference;
153
+ }
154
+ catch (e) {
155
+ if (e instanceof error_1.BeeError)
156
+ throw e;
157
+ }
158
+ assertReferenceOrEns(value);
159
+ return value;
160
+ }
161
+ exports.makeReferenceOrEns = makeReferenceOrEns;
162
+ /**
163
+ * Function that adds getter which converts the reference into CID base32 encoded string.
164
+ * @param result
165
+ * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
166
+ */
167
+ function addCidConversionFunction(result, cidType) {
168
+ return Object.assign(Object.assign({}, result), { get cid() {
169
+ return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
170
+ } });
171
+ }
172
+ exports.addCidConversionFunction = addCidConversionFunction;
115
173
  function assertAddress(value) {
116
174
  (0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
117
175
  }
@@ -256,6 +314,12 @@ function assertPostageBatchOptions(value) {
256
314
  if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
257
315
  assertBoolean(options.immutableFlag);
258
316
  }
317
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
318
+ assertBoolean(options.waitForUsable);
319
+ }
320
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
321
+ assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
322
+ }
259
323
  }
260
324
  exports.assertPostageBatchOptions = assertPostageBatchOptions;
261
325
  function assertCashoutOptions(value) {
File without changes
File without changes