@ethersphere/bee-js 2.0.0 → 3.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 (159) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +2 -2
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.map +1 -1
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/src/bee-debug.d.ts +38 -6
  8. package/dist/src/bee.d.ts +34 -46
  9. package/dist/src/modules/chunk.d.ts +2 -10
  10. package/dist/src/modules/debug/stamps.d.ts +2 -0
  11. package/dist/src/modules/debug/status.d.ts +10 -4
  12. package/dist/src/modules/stewardship.d.ts +1 -0
  13. package/dist/src/types/debug.d.ts +11 -0
  14. package/dist/src/types/index.d.ts +6 -7
  15. package/dist/src/utils/bytes.d.ts +1 -1
  16. package/dist/src/utils/expose.d.ts +1 -0
  17. package/dist/src/utils/stamps.d.ts +12 -0
  18. package/package.json +10 -8
  19. package/.babelrc.js +0 -33
  20. package/.depcheckrc.json +0 -27
  21. package/.editorconfig +0 -6
  22. package/.eslintignore +0 -1
  23. package/.eslintrc.js +0 -109
  24. package/.gitattributes +0 -1
  25. package/.github/config.yaml +0 -23
  26. package/.github/workflows/check.yaml +0 -57
  27. package/.github/workflows/publish_npmjs.yaml +0 -20
  28. package/.github/workflows/release_github.yaml +0 -20
  29. package/.github/workflows/tests.yaml +0 -128
  30. package/.huskyrc +0 -5
  31. package/.prettierrc +0 -13
  32. package/.vscode/launch.json +0 -49
  33. package/.vscode/settings.json +0 -39
  34. package/CODEOWNERS +0 -1
  35. package/CODE_OF_CONDUCT.md +0 -76
  36. package/commitlint.config.js +0 -3
  37. package/dist/src/modules/stamps.d.ts +0 -4
  38. package/jest-puppeteer.config.js +0 -5
  39. package/jest.config.ts +0 -85
  40. package/src/bee-debug.ts +0 -559
  41. package/src/bee.ts +0 -1070
  42. package/src/chunk/bmt.ts +0 -55
  43. package/src/chunk/cac.ts +0 -79
  44. package/src/chunk/serialize.ts +0 -16
  45. package/src/chunk/signer.ts +0 -141
  46. package/src/chunk/soc.ts +0 -190
  47. package/src/chunk/span.ts +0 -33
  48. package/src/feed/index.ts +0 -217
  49. package/src/feed/json.ts +0 -33
  50. package/src/feed/topic.ts +0 -23
  51. package/src/feed/type.ts +0 -12
  52. package/src/index.ts +0 -24
  53. package/src/modules/bytes.ts +0 -70
  54. package/src/modules/bzz.ts +0 -179
  55. package/src/modules/chunk.ts +0 -69
  56. package/src/modules/debug/balance.ts +0 -63
  57. package/src/modules/debug/chequebook.ts +0 -175
  58. package/src/modules/debug/chunk.ts +0 -39
  59. package/src/modules/debug/connectivity.ts +0 -61
  60. package/src/modules/debug/settlements.ts +0 -33
  61. package/src/modules/debug/stamps.ts +0 -76
  62. package/src/modules/debug/states.ts +0 -35
  63. package/src/modules/debug/status.ts +0 -35
  64. package/src/modules/debug/tag.ts +0 -19
  65. package/src/modules/debug/transactions.ts +0 -79
  66. package/src/modules/feed.ts +0 -105
  67. package/src/modules/pinning.ts +0 -74
  68. package/src/modules/pss.ts +0 -49
  69. package/src/modules/soc.ts +0 -40
  70. package/src/modules/stamps.ts +0 -59
  71. package/src/modules/status.ts +0 -13
  72. package/src/modules/stewardship.ts +0 -18
  73. package/src/modules/tag.ts +0 -83
  74. package/src/types/debug.ts +0 -204
  75. package/src/types/index.ts +0 -566
  76. package/src/types/ky-universal/common.d.ts +0 -17
  77. package/src/types/ky-universal/hooks.d.ts +0 -103
  78. package/src/types/ky-universal/index.d.ts +0 -125
  79. package/src/types/ky-universal/options.d.ts +0 -235
  80. package/src/types/ky-universal/response.d.ts +0 -38
  81. package/src/types/ky-universal/retry.d.ts +0 -39
  82. package/src/types/tar-js.d.ts +0 -1
  83. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  84. package/src/utils/bytes.ts +0 -144
  85. package/src/utils/collection.ts +0 -151
  86. package/src/utils/data.browser.ts +0 -68
  87. package/src/utils/data.ts +0 -48
  88. package/src/utils/error.ts +0 -23
  89. package/src/utils/eth.ts +0 -229
  90. package/src/utils/expose.ts +0 -48
  91. package/src/utils/file.ts +0 -40
  92. package/src/utils/hash.ts +0 -16
  93. package/src/utils/headers.ts +0 -63
  94. package/src/utils/hex.ts +0 -186
  95. package/src/utils/http.ts +0 -141
  96. package/src/utils/merge.ts +0 -34
  97. package/src/utils/pss.ts +0 -16
  98. package/src/utils/stream.ts +0 -146
  99. package/src/utils/tar.ts +0 -30
  100. package/src/utils/type.ts +0 -394
  101. package/src/utils/uint64.ts +0 -31
  102. package/src/utils/url.ts +0 -52
  103. package/test/bee.sh +0 -187
  104. package/test/data/1.txt +0 -1
  105. package/test/data/2.txt +0 -0
  106. package/test/data/empty +0 -0
  107. package/test/data/sub/3.txt +0 -1
  108. package/test/data/sub//303/251 +0 -0
  109. package/test/data/sub//360/237/230/216 +0 -0
  110. package/test/integration/bee-class.browser.spec.ts +0 -272
  111. package/test/integration/bee-class.spec.ts +0 -631
  112. package/test/integration/bee-debug-class.spec.ts +0 -85
  113. package/test/integration/chunk/bmt.spec.ts +0 -33
  114. package/test/integration/chunk/cac.spec.ts +0 -27
  115. package/test/integration/chunk/soc.spec.ts +0 -38
  116. package/test/integration/feed/index.spec.ts +0 -84
  117. package/test/integration/modules/bytes.spec.ts +0 -23
  118. package/test/integration/modules/bzz.spec.ts +0 -265
  119. package/test/integration/modules/chunk.spec.ts +0 -29
  120. package/test/integration/modules/debug/balance.spec.ts +0 -70
  121. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  122. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  123. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  124. package/test/integration/modules/debug/states.spec.ts +0 -34
  125. package/test/integration/modules/debug/status.spec.ts +0 -65
  126. package/test/integration/modules/debug/tag.spec.ts +0 -27
  127. package/test/integration/modules/debug/transactions.spec.ts +0 -10
  128. package/test/integration/modules/feed.spec.ts +0 -61
  129. package/test/integration/modules/pinning.spec.ts +0 -155
  130. package/test/integration/modules/pss.spec.ts +0 -97
  131. package/test/integration/modules/status.spec.ts +0 -10
  132. package/test/integration/modules/stewardship.spec.ts +0 -32
  133. package/test/integration/modules/tag.spec.ts +0 -51
  134. package/test/test-type-sequencer.js +0 -36
  135. package/test/testpage/testpage.html +0 -20
  136. package/test/tests-setup.ts +0 -94
  137. package/test/unit/assertions.ts +0 -460
  138. package/test/unit/bee-class.spec.ts +0 -976
  139. package/test/unit/bee-debug-class.spec.ts +0 -435
  140. package/test/unit/chunk/bmt.spec.ts +0 -16
  141. package/test/unit/chunk/cac.spec.ts +0 -29
  142. package/test/unit/chunk/serialize.spec.ts +0 -24
  143. package/test/unit/chunk/signer.spec.ts +0 -140
  144. package/test/unit/chunk/soc.spec.ts +0 -25
  145. package/test/unit/chunk/span.spec.ts +0 -38
  146. package/test/unit/feed/json.spec.ts +0 -73
  147. package/test/unit/nock.ts +0 -151
  148. package/test/unit/utils/bytes.spec.ts +0 -32
  149. package/test/unit/utils/collection.spec.ts +0 -22
  150. package/test/unit/utils/eth.spec.ts +0 -224
  151. package/test/unit/utils/hex.spec.ts +0 -115
  152. package/test/unit/utils/stream.spec.ts +0 -30
  153. package/test/unit/utils/type.spec.ts +0 -32
  154. package/test/unit/utils/uint64.spec.ts +0 -102
  155. package/test/utils.ts +0 -328
  156. package/tsconfig.json +0 -18
  157. package/tsconfig.test.json +0 -11
  158. package/typedoc.json +0 -7
  159. package/webpack.config.ts +0 -141
@@ -1,272 +0,0 @@
1
- import { join } from 'path'
2
- import {
3
- beeDebugUrl,
4
- beeKy,
5
- beePeerDebugUrl,
6
- beePeerUrl,
7
- beeUrl,
8
- commonMatchers,
9
- getPostageBatch,
10
- PSS_TIMEOUT,
11
- } from '../utils'
12
- import '../../src'
13
- import type { Address, Reference } from '../../src/types'
14
- import * as bzz from '../../src/modules/bzz'
15
-
16
- commonMatchers()
17
-
18
- describe('Bee class - in browser', () => {
19
- const BEE_URL = beeUrl()
20
- const BEE_DEBUG_URL = beeDebugUrl()
21
- const BEE_PEER_URL = beePeerUrl()
22
- let batchId: Address, batchIdPeer: Address
23
-
24
- beforeAll(async () => {
25
- await jestPuppeteer.resetPage()
26
- const testPage = join(__dirname, '..', 'testpage', 'testpage.html')
27
- await page.goto(`file://${testPage}`)
28
-
29
- batchId = await getPostageBatch()
30
- batchIdPeer = await getPostageBatch(beePeerDebugUrl())
31
- })
32
-
33
- it('should create a new Bee instance in browser', async () => {
34
- const beeUrl = await page.evaluate(BEE_URL => {
35
- return new window.BeeJs.Bee(BEE_URL).url
36
- }, BEE_URL)
37
-
38
- expect(beeUrl).toBe(BEE_URL)
39
- })
40
-
41
- function testUrl(url: unknown): void {
42
- it(`should not accept invalid url '${url}'`, async () => {
43
- await page.evaluate(url => {
44
- try {
45
- new window.BeeJs.Bee(url as string)
46
- fail('Bee constructor should have thrown error.')
47
- } catch (e) {
48
- if (e instanceof window.BeeJs.BeeArgumentError) {
49
- // We don't have `expect()` available in browser context
50
- if (e.value !== url) {
51
- throw new Error('Error value does not match the URL!')
52
- }
53
-
54
- return
55
- }
56
-
57
- throw e
58
- }
59
- }, url as string)
60
- })
61
- }
62
-
63
- testUrl('')
64
- testUrl(null)
65
- testUrl(undefined)
66
- testUrl(1)
67
- testUrl('some-invalid-url')
68
- testUrl('invalid:protocol')
69
- // eslint-disable-next-line no-script-url
70
- testUrl('javascript:console.log()')
71
- testUrl('ws://localhost:1633')
72
-
73
- it('should pin and unpin collection', async () => {
74
- const fileHash = await page.evaluate(
75
- async (BEE_URL, batchId) => {
76
- const bee = new window.BeeJs.Bee(BEE_URL)
77
- const files: File[] = [new File(['hello'], 'hello')]
78
-
79
- return (await bee.uploadFiles(batchId, files)).reference
80
- },
81
- BEE_URL,
82
- batchId,
83
- )
84
- expect(fileHash).toBeHashReference()
85
- //pinning
86
- await page.evaluate(
87
- async (BEE_URL, fileHash) => {
88
- const bee = new window.BeeJs.Bee(BEE_URL)
89
-
90
- return await bee.pin(fileHash)
91
- },
92
- BEE_URL,
93
- fileHash,
94
- )
95
-
96
- //unpinning
97
- await page.evaluate(
98
- async (BEE_URL, fileHash) => {
99
- const bee = new window.BeeJs.Bee(BEE_URL)
100
-
101
- return await bee.unpin(fileHash)
102
- },
103
- BEE_URL,
104
- fileHash,
105
- )
106
- })
107
-
108
- describe('streams', () => {
109
- it('should upload file with stream', async () => {
110
- const ref = (await page.evaluate(
111
- async (BEE_URL, batchId) => {
112
- // @ts-ignore: This is evaluated in browser context - no TS support
113
- function createReadableStream(iterable) {
114
- const iter = iterable[Symbol.iterator]()
115
-
116
- return new ReadableStream({
117
- async pull(controller) {
118
- const result = iter.next()
119
-
120
- if (result.done) {
121
- controller.close()
122
-
123
- return
124
- }
125
-
126
- controller.enqueue(result.value)
127
- },
128
- })
129
- }
130
-
131
- const bee = new window.BeeJs.Bee(BEE_URL)
132
- const filename = 'hello.txt'
133
- const readable = createReadableStream([
134
- new TextEncoder().encode('hello '),
135
- new TextEncoder().encode('another world'),
136
- ])
137
-
138
- const reference = await bee.uploadFile(batchId, readable, filename, {
139
- contentType: 'text/plain',
140
- })
141
-
142
- return reference.reference
143
- },
144
- BEE_URL,
145
- batchId,
146
- )) as Reference
147
-
148
- const file = await bzz.downloadFile(beeKy(), ref)
149
-
150
- expect(file.name).toEqual('hello.txt')
151
- expect(file.data.text()).toEqual('hello another world')
152
- })
153
-
154
- it('should download file with stream', async () => {
155
- const result = await bzz.uploadFile(beeKy(), 'hello awesome world', batchId)
156
-
157
- const content = (await page.evaluate(
158
- async (BEE_URL, reference) => {
159
- const bee = new window.BeeJs.Bee(BEE_URL)
160
- const readable = await bee.downloadReadableFile(reference)
161
-
162
- const reader = readable.data.getReader()
163
- const buffers = []
164
-
165
- let done, value
166
- do {
167
- ;({ done, value } = await reader.read())
168
-
169
- if (!done) {
170
- buffers.push(value)
171
- }
172
- } while (!done)
173
-
174
- // @ts-ignore: Browser context - no TS
175
- const blob = new Blob(buffers, { type: 'application/octet-stream' })
176
-
177
- return new TextDecoder().decode(await blob.arrayBuffer())
178
- },
179
- BEE_URL,
180
- result.reference,
181
- )) as string
182
-
183
- expect(content).toEqual('hello awesome world')
184
- })
185
- })
186
-
187
- describe('pss', () => {
188
- it(
189
- 'should send and receive pss message',
190
- done => {
191
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
192
- ;(async () => {
193
- const message = '1234'
194
-
195
- const result = await page.evaluate(
196
- async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
197
- const topic = 'browser-bee-class-topic1'
198
-
199
- const bee = new window.BeeJs.Bee(BEE_URL)
200
- const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
201
-
202
- const { overlay } = await beeDebug.getNodeAddresses()
203
- const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
204
-
205
- const receive = bee.pssReceive(topic)
206
- await beePeer.pssSend(batchIdPeer, topic, window.BeeJs.Utils.makeMaxTarget(overlay), message)
207
-
208
- const msg = await receive
209
-
210
- // Need to pass it back as string
211
- return new TextDecoder('utf-8').decode(new Uint8Array(msg))
212
- },
213
- BEE_URL,
214
- BEE_DEBUG_URL,
215
- BEE_PEER_URL,
216
- message,
217
- batchIdPeer,
218
- )
219
-
220
- expect(result).toEqual(message)
221
- done()
222
- })()
223
- },
224
- PSS_TIMEOUT,
225
- )
226
-
227
- it(
228
- 'should send and receive pss message encrypted with PSS key',
229
- done => {
230
- // Jest does not allow use `done` and return Promise so this wrapper work arounds that.
231
- ;(async () => {
232
- const message = '1234'
233
-
234
- const result = await page.evaluate(
235
- async (BEE_URL, BEE_DEBUG_URL, BEE_PEER_URL, message, batchIdPeer) => {
236
- const topic = 'browser-bee-class-topic2'
237
-
238
- const bee = new window.BeeJs.Bee(BEE_URL)
239
- const beeDebug = new window.BeeJs.BeeDebug(BEE_DEBUG_URL)
240
-
241
- const { overlay, pssPublicKey } = await beeDebug.getNodeAddresses()
242
- const beePeer = new window.BeeJs.Bee(BEE_PEER_URL)
243
-
244
- const receive = bee.pssReceive(topic)
245
- await beePeer.pssSend(
246
- batchIdPeer,
247
- topic,
248
- window.BeeJs.Utils.makeMaxTarget(overlay),
249
- message,
250
- pssPublicKey,
251
- )
252
-
253
- const msg = await receive
254
-
255
- // Need to pass it back as string
256
- return new TextDecoder('utf-8').decode(new Uint8Array(msg))
257
- },
258
- BEE_URL,
259
- BEE_DEBUG_URL,
260
- BEE_PEER_URL,
261
- message,
262
- batchIdPeer,
263
- )
264
-
265
- expect(result).toEqual(message)
266
- done()
267
- })()
268
- },
269
- PSS_TIMEOUT,
270
- )
271
- })
272
- })