@ethersphere/bee-js 2.1.0 → 3.2.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.
- package/README.md +3 -3
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +5 -1
- package/dist/src/bee.d.ts +23 -46
- package/dist/src/modules/chunk.d.ts +2 -10
- package/dist/src/modules/debug/status.d.ts +10 -4
- package/dist/src/types/debug.d.ts +19 -0
- package/dist/src/types/index.d.ts +31 -2
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/error.d.ts +21 -2
- package/dist/src/utils/expose.d.ts +1 -0
- package/dist/src/utils/http.d.ts +7 -9
- package/dist/src/utils/stamps.d.ts +12 -0
- package/dist/src/utils/type.d.ts +6 -0
- package/package.json +28 -27
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -109
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CHANGELOG.md +0 -520
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -85
- package/src/bee-debug.ts +0 -601
- package/src/bee.ts +0 -1087
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -217
- package/src/feed/json.ts +0 -33
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -70
- package/src/modules/bzz.ts +0 -179
- package/src/modules/chunk.ts +0 -69
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -175
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -96
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -105
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -49
- package/src/modules/soc.ts +0 -40
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -32
- package/src/modules/tag.ts +0 -83
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -561
- package/src/types/ky-universal/common.d.ts +0 -17
- package/src/types/ky-universal/hooks.d.ts +0 -103
- package/src/types/ky-universal/index.d.ts +0 -125
- package/src/types/ky-universal/options.d.ts +0 -235
- package/src/types/ky-universal/response.d.ts +0 -38
- package/src/types/ky-universal/retry.d.ts +0 -39
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -68
- package/src/utils/data.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -48
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/http.ts +0 -141
- package/src/utils/merge.ts +0 -34
- package/src/utils/pss.ts +0 -16
- package/src/utils/stream.ts +0 -146
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -394
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -272
- package/test/integration/bee-class.spec.ts +0 -648
- package/test/integration/bee-debug-class.spec.ts +0 -114
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -265
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/debug/transactions.spec.ts +0 -10
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -105
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/tests-setup.ts +0 -94
- package/test/unit/assertions.ts +0 -460
- package/test/unit/bee-class.spec.ts +0 -976
- package/test/unit/bee-debug-class.spec.ts +0 -435
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -151
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/stream.spec.ts +0 -30
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -426
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- 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, overlay.slice(0, 2), message) // We don't have the `makeTestTarget` utility available in this context
|
|
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
|
-
overlay.slice(0, 2), // We don't have the `makeTestTarget` utility available in this context
|
|
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
|
-
})
|