@ethersphere/bee-js 6.9.1 → 7.0.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 (143) hide show
  1. package/README.md +107 -65
  2. package/dist/cjs/bee.js +533 -6
  3. package/dist/cjs/chunk/cac.js +3 -3
  4. package/dist/cjs/chunk/soc.js +5 -5
  5. package/dist/cjs/chunk/span.js +2 -6
  6. package/dist/cjs/feed/identifier.js +2 -2
  7. package/dist/cjs/feed/index.js +5 -6
  8. package/dist/cjs/feed/retrievable.js +2 -2
  9. package/dist/cjs/index.js +1 -3
  10. package/dist/cjs/modules/bytes.js +3 -3
  11. package/dist/cjs/modules/bzz.js +9 -20
  12. package/dist/cjs/modules/chunk.js +2 -2
  13. package/dist/cjs/modules/debug/balance.js +4 -4
  14. package/dist/cjs/modules/debug/chequebook.js +8 -8
  15. package/dist/cjs/modules/debug/chunk.js +2 -19
  16. package/dist/cjs/modules/debug/settlements.js +2 -2
  17. package/dist/cjs/modules/debug/stake.js +3 -3
  18. package/dist/cjs/modules/debug/states.js +4 -19
  19. package/dist/cjs/modules/debug/status.js +15 -32
  20. package/dist/cjs/modules/debug/tag.js +1 -1
  21. package/dist/cjs/modules/debug/transactions.js +4 -4
  22. package/dist/cjs/modules/feed.js +6 -7
  23. package/dist/cjs/modules/pinning.js +4 -4
  24. package/dist/cjs/modules/pss.js +1 -1
  25. package/dist/cjs/modules/soc.js +1 -1
  26. package/dist/cjs/modules/status.js +1 -1
  27. package/dist/cjs/modules/stewardship.js +1 -1
  28. package/dist/cjs/package.json +4 -0
  29. package/dist/cjs/types/index.js +5 -1
  30. package/dist/cjs/utils/collection.js +7 -22
  31. package/dist/cjs/utils/collection.node.js +2 -1
  32. package/dist/cjs/utils/data.browser.js +1 -49
  33. package/dist/cjs/utils/error.js +2 -6
  34. package/dist/cjs/utils/eth.js +1 -1
  35. package/dist/cjs/utils/expose.js +1 -8
  36. package/dist/cjs/utils/file.js +2 -2
  37. package/dist/cjs/utils/http.js +6 -25
  38. package/dist/cjs/utils/tar-uploader.browser.js +26 -0
  39. package/dist/cjs/utils/tar-uploader.js +27 -0
  40. package/dist/cjs/utils/tar-writer.browser.js +17 -0
  41. package/dist/cjs/utils/tar-writer.js +21 -0
  42. package/dist/cjs/utils/tar.browser.js +65 -0
  43. package/dist/cjs/utils/tar.js +47 -21
  44. package/dist/cjs/utils/type.js +7 -3
  45. package/dist/cjs/utils/url.js +1 -6
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +0 -42
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee.js +533 -9
  50. package/dist/mjs/chunk/cac.js +4 -4
  51. package/dist/mjs/chunk/soc.js +6 -6
  52. package/dist/mjs/chunk/span.js +2 -6
  53. package/dist/mjs/feed/identifier.js +2 -2
  54. package/dist/mjs/feed/index.js +5 -9
  55. package/dist/mjs/feed/retrievable.js +2 -2
  56. package/dist/mjs/index.js +1 -2
  57. package/dist/mjs/modules/bytes.js +3 -3
  58. package/dist/mjs/modules/bzz.js +8 -20
  59. package/dist/mjs/modules/chunk.js +2 -2
  60. package/dist/mjs/modules/debug/balance.js +4 -4
  61. package/dist/mjs/modules/debug/chequebook.js +8 -8
  62. package/dist/mjs/modules/debug/chunk.js +1 -17
  63. package/dist/mjs/modules/debug/settlements.js +2 -2
  64. package/dist/mjs/modules/debug/stake.js +3 -3
  65. package/dist/mjs/modules/debug/states.js +4 -19
  66. package/dist/mjs/modules/debug/status.js +15 -34
  67. package/dist/mjs/modules/debug/tag.js +1 -1
  68. package/dist/mjs/modules/debug/transactions.js +4 -4
  69. package/dist/mjs/modules/feed.js +6 -7
  70. package/dist/mjs/modules/pinning.js +4 -4
  71. package/dist/mjs/modules/pss.js +1 -1
  72. package/dist/mjs/modules/soc.js +1 -1
  73. package/dist/mjs/modules/status.js +1 -1
  74. package/dist/mjs/modules/stewardship.js +1 -1
  75. package/dist/mjs/package.json +6 -2
  76. package/dist/mjs/types/index.js +4 -0
  77. package/dist/mjs/utils/collection.js +7 -22
  78. package/dist/mjs/utils/collection.node.js +2 -1
  79. package/dist/mjs/utils/data.browser.js +0 -57
  80. package/dist/mjs/utils/error.js +2 -6
  81. package/dist/mjs/utils/eth.js +1 -1
  82. package/dist/mjs/utils/expose.js +0 -1
  83. package/dist/mjs/utils/http.js +5 -2
  84. package/dist/mjs/utils/tar-uploader.browser.js +22 -0
  85. package/dist/mjs/utils/tar-uploader.js +23 -0
  86. package/dist/mjs/utils/tar-writer.browser.js +12 -0
  87. package/dist/mjs/utils/tar-writer.js +16 -0
  88. package/dist/mjs/utils/tar.browser.js +61 -0
  89. package/dist/mjs/utils/tar.js +45 -16
  90. package/dist/mjs/utils/type.js +4 -1
  91. package/dist/mjs/utils/url.js +1 -6
  92. package/dist/types/bee.d.ts +305 -4
  93. package/dist/types/chunk/soc.d.ts +2 -2
  94. package/dist/types/feed/identifier.d.ts +1 -1
  95. package/dist/types/index.d.ts +1 -3
  96. package/dist/types/modules/bytes.d.ts +3 -3
  97. package/dist/types/modules/bzz.d.ts +14 -6
  98. package/dist/types/modules/chunk.d.ts +2 -2
  99. package/dist/types/modules/debug/balance.d.ts +4 -4
  100. package/dist/types/modules/debug/chequebook.d.ts +8 -8
  101. package/dist/types/modules/debug/chunk.d.ts +1 -10
  102. package/dist/types/modules/debug/settlements.d.ts +2 -2
  103. package/dist/types/modules/debug/stake.d.ts +3 -3
  104. package/dist/types/modules/debug/states.d.ts +3 -3
  105. package/dist/types/modules/debug/status.d.ts +10 -20
  106. package/dist/types/modules/debug/tag.d.ts +1 -1
  107. package/dist/types/modules/debug/transactions.d.ts +4 -4
  108. package/dist/types/modules/feed.d.ts +6 -9
  109. package/dist/types/modules/pinning.d.ts +4 -4
  110. package/dist/types/modules/pss.d.ts +1 -1
  111. package/dist/types/modules/soc.d.ts +1 -1
  112. package/dist/types/modules/status.d.ts +1 -1
  113. package/dist/types/modules/stewardship.d.ts +1 -1
  114. package/dist/types/types/debug.d.ts +0 -3
  115. package/dist/types/types/index.d.ts +9 -17
  116. package/dist/types/utils/collection.browser.d.ts +1 -1
  117. package/dist/types/utils/collection.d.ts +3 -3
  118. package/dist/types/utils/collection.node.d.ts +1 -1
  119. package/dist/types/utils/data.browser.d.ts +0 -7
  120. package/dist/types/utils/data.d.ts +1 -2
  121. package/dist/types/utils/error.d.ts +2 -7
  122. package/dist/types/utils/eth.d.ts +1 -1
  123. package/dist/types/utils/expose.d.ts +0 -1
  124. package/dist/types/utils/tar-uploader.browser.d.ts +4 -0
  125. package/dist/types/utils/tar-uploader.d.ts +4 -0
  126. package/dist/types/utils/tar-writer.browser.d.ts +3 -0
  127. package/dist/types/utils/tar-writer.d.ts +3 -0
  128. package/dist/types/utils/tar.browser.d.ts +9 -0
  129. package/dist/types/utils/tar.d.ts +10 -2
  130. package/dist/types/utils/type.d.ts +4 -1
  131. package/package.json +4 -19
  132. package/dist/cjs/bee-debug.js +0 -590
  133. package/dist/cjs/chunk/serialize.js +0 -19
  134. package/dist/cjs/utils/stream.js +0 -146
  135. package/dist/cjs/utils/uint64.js +0 -29
  136. package/dist/mjs/bee-debug.js +0 -560
  137. package/dist/mjs/chunk/serialize.js +0 -15
  138. package/dist/mjs/utils/stream.js +0 -129
  139. package/dist/mjs/utils/uint64.js +0 -22
  140. package/dist/types/bee-debug.d.ts +0 -323
  141. package/dist/types/chunk/serialize.d.ts +0 -6
  142. package/dist/types/utils/stream.d.ts +0 -40
  143. package/dist/types/utils/uint64.d.ts +0 -4
package/README.md CHANGED
@@ -1,66 +1,47 @@
1
- # Bee-js
1
+ # Bee-JS
2
2
 
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
- [![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)
5
3
  [![](https://img.shields.io/badge/made%20by-Swarm-blue.svg?style=flat-square)](https://swarm.ethereum.org/)
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
  [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
7
6
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
8
- ![](https://img.shields.io/badge/npm-%3E%3D6.9.0-orange.svg?style=flat-square)
9
- ![](https://img.shields.io/badge/Node.js-%3E%3D14.0.0-orange.svg?style=flat-square)
7
+ ![](https://img.shields.io/badge/Node.js-%3E%3D18.0.0-orange.svg?style=flat-square)
10
8
  ![](https://img.shields.io/badge/runs%20in-browser%20%7C%20node%20%7C%20webworker%20%7C%20electron-orange)
11
9
 
12
- > Client library for connecting to Bee decentralised storage
10
+ > JavaScript SDK for connecting to a Bee node in the Swarm decentralised storage.
13
11
 
14
- **Warning: This project is in beta state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.**
12
+ > Supports Node.js 18+, Vite and Webpack.
15
13
 
16
- This project is intended to be used with **Bee version <!-- SUPPORTED_BEE_START -->1.13.0<!-- SUPPORTED_BEE_END -->**. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/bee-js/releases).
14
+ > Write your code in CJS, MJS or TypeScript.
17
15
 
18
- ## Table of Contents
19
-
20
- - [Install](#install)
21
- - [npm](#npm)
22
- - [Use in Node.js](#use-in-nodejs)
23
- - [Use in a browser with browserify, webpack or any other bundler](#use-in-a-browser-with-browserify-webpack-or-any-other-bundler)
24
- - [Use in a browser Using a script tag](#use-in-a-browser-using-a-script-tag)
25
- - [Usage](#usage)
26
- - [API](#api)
27
- - [Contribute](#contribute)
28
- - [Setup](#setup)
29
- - [Test](#test)
30
- - [License](#license)
16
+ > Intended to be used with Bee version 2.1.0.
31
17
 
32
18
  ## Install
33
19
 
34
- ### npm
35
-
36
20
  ```sh
37
- > npm install @ethersphere/bee-js --save
21
+ npm install @ethersphere/bee-js
38
22
  ```
39
23
 
40
- ### yarn
24
+ or
41
25
 
42
26
  ```sh
43
- > yarn add @ethersphere/bee-js
27
+ yarn add @ethersphere/bee-js
44
28
  ```
45
29
 
46
- Be aware, if you are running Yarn v1 and are attempting to install this repo using GitHub URL, this won't unfortunately
47
- work as it does not correctly handle execution of `prepare` script.
30
+ ## Import
48
31
 
49
- ### Use in Node.js
50
-
51
- **We require Node.js's version of at least 12.x**
32
+ ### CJS
52
33
 
53
34
  ```js
54
- var BeeJs = require("@ethersphere/bee-js");
35
+ const { Bee } = require('@ethersphere/bee-js')
55
36
  ```
56
37
 
57
- ### Use in a browser with browserify, webpack or any other bundler
38
+ ### MJS and TypeScript
58
39
 
59
- ```js
60
- var BeeJs = require("@ethersphere/bee-js");
40
+ ```ts
41
+ import { Bee } from '@ethersphere/bee-js'
61
42
  ```
62
43
 
63
- ### Use in a browser Using a script tag
44
+ ### Script tag
64
45
 
65
46
  Loading this module through a script tag will make the `BeeJs` object available in the global namespace.
66
47
 
@@ -70,33 +51,101 @@ Loading this module through a script tag will make the `BeeJs` object available
70
51
 
71
52
  ## Usage
72
53
 
54
+ ### Create or select an existing postage batch
55
+
56
+ Swarm incentivizes nodes in the network to store content, therefor all uploads require a paid
57
+ [postage batch](https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp).
58
+
59
+ ```js
60
+ import { Bee } from '@ethersphere/bee-js'
61
+
62
+ async function getOrCreatePostageBatch() {
63
+ const bee = new Bee('http://localhost:1633')
64
+ let batchId
65
+
66
+ const batches = await bee.getAllPostageBatch()
67
+ const usable = batches.find(x => x.usable)
68
+
69
+ if (usable) {
70
+ batchId = usable.batchID
71
+ } else {
72
+ batchId = await bee.createPostageBatch('500000000', 20)
73
+ }
74
+ }
75
+ ```
76
+
77
+ > The following examples all assume an existing batchId.
78
+
79
+ ### Upload simple data (Browser + Node.js)
80
+
73
81
  ```js
74
- import { Bee, BeeDebug } from '@ethersphere/bee-js'
82
+ import { Bee } from '@ethersphere/bee-js'
75
83
 
76
84
  const bee = new Bee('http://localhost:1633')
77
- const beeDebug = new BeeDebug('http://localhost:1635')
78
85
 
79
- // Be aware, this creates on-chain transactions that spend Eth and BZZ!
80
- const batchId = await bee.createPostageBatch('2000', 20)
81
- const uploadResult = await bee.uploadData(batchId, "Bee is awesome!")
86
+ const uploadResult = await bee.uploadData(batchId, 'Bee is awesome!')
82
87
  const data = await bee.downloadData(uploadResult.reference)
83
88
 
84
89
  console.log(data.text()) // prints 'Bee is awesome!'
85
90
  ```
86
91
 
92
+ ### Upload data from a file input (React)
93
+
94
+ ```js
95
+ import { Bee } from '@ethersphere/bee-js'
96
+
97
+ const bee = new Bee('http://localhost:1633')
98
+ const result = await bee.uploadFile(batchId, file)
99
+ ```
100
+
101
+ ### Upload multiple files or a directory (React)
102
+
103
+ ```js
104
+ import { Bee } from '@ethersphere/bee-js'
105
+
106
+ const bee = new Bee('http://localhost:1633')
107
+ const result = await bee.uploadFiles(batchId, fileList)
108
+ ```
109
+
110
+ ### Upload arbitrary large file (Node.js)
111
+
112
+ ```js
113
+ import { Bee } from '@ethersphere/bee-js'
114
+ import { createReadStream } from 'fs'
115
+
116
+ const bee = new Bee('http://localhost:1633')
117
+ const readable = createReadStream('./path/to/large.bin')
118
+ const uploadResult = await bee.uploadFile(batchId, readable)
119
+ ```
120
+
121
+ ### Upload arbitrary large directories (Node.js)
122
+
123
+ ```js
124
+ import { Bee } from '@ethersphere/bee-js'
125
+ import { createReadStream } from 'fs'
126
+
127
+ const bee = new Bee('http://localhost:1633')
128
+ const uploadResult = await bee.uploadFilesFromDirectory(batchId, './path/to/gallery/')
129
+ ```
130
+
87
131
  [**Check out our examples repo for some more ideas on how to use `bee-js`**](https://github.com/ethersphere/examples-js)
88
132
 
89
133
  ## Documentation
90
134
 
91
- You can find the full documentation [here](https://bee-js.ethswarm.org/docs). The API reference documentation can be found [here](https://bee-js.ethswarm.org/docs/api).
135
+ You can find the full documentation [here](https://bee-js.ethswarm.org/docs). The API reference documentation can be
136
+ found [here](https://bee-js.ethswarm.org/docs/api).
92
137
 
93
138
  ## Contribute
94
139
 
140
+ Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the
141
+ [releases tab](https://github.com/ethersphere/bee-js/releases).
142
+
95
143
  There are some ways you can make this module better:
96
144
 
97
145
  - Consult our [open issues](https://github.com/ethersphere/bee-js/issues) and take on one of them
98
146
  - Help our tests reach 100% coverage!
99
- - Join us in our [Discord chat](https://discord.gg/wdghaQsGq5) in the #develop-on-swarm channel if you have questions or want to give feedback
147
+ - Join us in our [Discord chat](https://discord.gg/wdghaQsGq5) in the #develop-on-swarm channel if you have questions or
148
+ want to give feedback
100
149
 
101
150
  ### Setup
102
151
 
@@ -106,35 +155,32 @@ Install project dependencies with
106
155
  npm i
107
156
  ```
108
157
 
109
- ### Node 18
110
-
111
- Node 18 came with its own fetch's native implementation called Undici. If you want to run bee-js tests under Node 18, then disable
112
- the native's fetch implementation otherwise unit tests will fail as they capture HTTP calls with library called `nock` that does
113
- not support native fetch yet.
114
-
115
- ```
116
- export NODE_OPTIONS='--no-experimental-fetch'
117
- ```
118
-
119
158
  ### Test
120
159
 
121
160
  The tests run in both context: node and dom with Jest.
122
161
 
123
- To run the integration tests, you need to spin up local Bee cluster using our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project.
124
- 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
125
- cluster and display Queen's logs. If you want to exit hit `CTRL+C`.
162
+ To run the integration tests, you need to spin up local Bee cluster using our
163
+ [`fdp-play`](https://github.com/fairDataSociety/fdp-play/) project. In order to do that you have to have locally Docker
164
+ running on your machine, but afterwards you can just simply run `npm run bee`, which spins up the cluster and display
165
+ Queen's logs. If you want to exit hit `CTRL+C`.
126
166
 
127
- 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`.
167
+ If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and
168
+ set them under env. variables `BEE_POSTAGE` and `BEE_PEER_POSTAGE`.
128
169
 
129
- 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.
130
- 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`.
170
+ By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633`
171
+ and `http://localhost:11633`. These are the default values for the `fdp-play` script. If you want to use custom setup,
172
+ you can change the behavior of tests to different addresses using environment variables `BEE_API_URL` and
173
+ `BEE_PEER_API_URL`.
131
174
 
132
175
  There are also browser tests by Puppeteer, which also provide integrity testing.
176
+
133
177
  ```sh
134
178
  npm run test:browser
135
179
  ```
136
- The test HTML file which Puppeteer uses is the [test/testpage/testpage.html](test/testpage/testpage.html).
137
- To open and manually test BeeJS with developer console, it is necessary to build the library first with `npm run compile:browser` (running the browser tests `npm run test:browser` also builds the library).
180
+
181
+ The test HTML file which Puppeteer uses is the [test/testpage/testpage.html](test/testpage/testpage.html). To open and
182
+ manually test BeeJS with developer console, it is necessary to build the library first with `npm run compile:browser`
183
+ (running the browser tests `npm run test:browser` also builds the library).
138
184
 
139
185
  ### Compile code
140
186
 
@@ -146,12 +192,8 @@ or for Browsers
146
192
 
147
193
  `npm run compile:browser`
148
194
 
149
- ## Maintainers
150
-
151
-
152
195
  ## License
153
196
 
154
197
  [BSD-3-Clause](./LICENSE)
155
198
 
156
-
157
199
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_large)