@ethersphere/bee-js 5.2.0 → 6.0.0-pre.1

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 (111) hide show
  1. package/dist/cjs/bee-debug.js +58 -72
  2. package/dist/cjs/bee.js +71 -86
  3. package/dist/cjs/chunk/soc.js +14 -14
  4. package/dist/cjs/feed/index.js +20 -21
  5. package/dist/cjs/feed/json.js +2 -2
  6. package/dist/cjs/feed/retrievable.js +7 -8
  7. package/dist/cjs/index.js +7 -7
  8. package/dist/cjs/modules/bytes.js +15 -15
  9. package/dist/cjs/modules/bzz.js +24 -25
  10. package/dist/cjs/modules/chunk.js +10 -10
  11. package/dist/cjs/modules/debug/balance.js +16 -16
  12. package/dist/cjs/modules/debug/chequebook.js +34 -34
  13. package/dist/cjs/modules/debug/chunk.js +8 -8
  14. package/dist/cjs/modules/debug/connectivity.js +24 -24
  15. package/dist/cjs/modules/debug/settlements.js +8 -8
  16. package/dist/cjs/modules/debug/stake.js +11 -11
  17. package/dist/cjs/modules/debug/stamps.js +25 -25
  18. package/dist/cjs/modules/debug/states.js +12 -12
  19. package/dist/cjs/modules/debug/status.js +24 -24
  20. package/dist/cjs/modules/debug/tag.js +4 -4
  21. package/dist/cjs/modules/debug/transactions.js +16 -16
  22. package/dist/cjs/modules/feed.js +14 -14
  23. package/dist/cjs/modules/pinning.js +14 -14
  24. package/dist/cjs/modules/pss.js +6 -6
  25. package/dist/cjs/modules/soc.js +6 -6
  26. package/dist/cjs/modules/status.js +3 -3
  27. package/dist/cjs/modules/stewardship.js +7 -7
  28. package/dist/cjs/modules/tag.js +20 -20
  29. package/dist/cjs/utils/error.js +1 -35
  30. package/dist/cjs/utils/headers.js +3 -3
  31. package/dist/cjs/utils/http.js +14 -141
  32. package/dist/cjs/utils/type.js +1 -4
  33. package/dist/index.browser.min.js +1 -1
  34. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  35. package/dist/index.browser.min.js.map +1 -1
  36. package/dist/mjs/bee-debug.js +59 -73
  37. package/dist/mjs/bee.js +72 -87
  38. package/dist/mjs/chunk/soc.js +14 -14
  39. package/dist/mjs/feed/index.js +20 -21
  40. package/dist/mjs/feed/json.js +2 -2
  41. package/dist/mjs/feed/retrievable.js +7 -8
  42. package/dist/mjs/index.js +2 -2
  43. package/dist/mjs/modules/bytes.js +15 -15
  44. package/dist/mjs/modules/bzz.js +24 -25
  45. package/dist/mjs/modules/chunk.js +10 -10
  46. package/dist/mjs/modules/debug/balance.js +16 -16
  47. package/dist/mjs/modules/debug/chequebook.js +34 -34
  48. package/dist/mjs/modules/debug/chunk.js +8 -8
  49. package/dist/mjs/modules/debug/connectivity.js +24 -24
  50. package/dist/mjs/modules/debug/settlements.js +8 -8
  51. package/dist/mjs/modules/debug/stake.js +11 -11
  52. package/dist/mjs/modules/debug/stamps.js +25 -25
  53. package/dist/mjs/modules/debug/states.js +12 -12
  54. package/dist/mjs/modules/debug/status.js +24 -25
  55. package/dist/mjs/modules/debug/tag.js +4 -4
  56. package/dist/mjs/modules/debug/transactions.js +16 -16
  57. package/dist/mjs/modules/feed.js +14 -14
  58. package/dist/mjs/modules/pinning.js +14 -14
  59. package/dist/mjs/modules/pss.js +6 -6
  60. package/dist/mjs/modules/soc.js +6 -6
  61. package/dist/mjs/modules/status.js +3 -3
  62. package/dist/mjs/modules/stewardship.js +7 -7
  63. package/dist/mjs/modules/tag.js +20 -20
  64. package/dist/mjs/utils/error.js +0 -31
  65. package/dist/mjs/utils/headers.js +3 -3
  66. package/dist/mjs/utils/http.js +10 -138
  67. package/dist/mjs/utils/type.js +2 -5
  68. package/dist/types/bee-debug.d.ts +50 -50
  69. package/dist/types/bee.d.ts +34 -34
  70. package/dist/types/chunk/soc.d.ts +5 -6
  71. package/dist/types/feed/index.d.ts +7 -8
  72. package/dist/types/feed/json.d.ts +2 -2
  73. package/dist/types/feed/retrievable.d.ts +2 -2
  74. package/dist/types/index.d.ts +2 -4
  75. package/dist/types/modules/bytes.d.ts +4 -5
  76. package/dist/types/modules/bzz.d.ts +5 -6
  77. package/dist/types/modules/chunk.d.ts +3 -4
  78. package/dist/types/modules/debug/balance.d.ts +5 -6
  79. package/dist/types/modules/debug/chequebook.d.ts +9 -10
  80. package/dist/types/modules/debug/chunk.d.ts +3 -4
  81. package/dist/types/modules/debug/connectivity.d.ts +7 -8
  82. package/dist/types/modules/debug/settlements.d.ts +3 -4
  83. package/dist/types/modules/debug/stake.d.ts +4 -5
  84. package/dist/types/modules/debug/stamps.d.ts +7 -8
  85. package/dist/types/modules/debug/states.d.ts +4 -5
  86. package/dist/types/modules/debug/status.d.ts +10 -10
  87. package/dist/types/modules/debug/tag.d.ts +2 -3
  88. package/dist/types/modules/debug/transactions.d.ts +5 -6
  89. package/dist/types/modules/feed.d.ts +3 -4
  90. package/dist/types/modules/pinning.d.ts +5 -6
  91. package/dist/types/modules/pss.d.ts +2 -3
  92. package/dist/types/modules/soc.d.ts +2 -3
  93. package/dist/types/modules/status.d.ts +2 -2
  94. package/dist/types/modules/stewardship.d.ts +3 -4
  95. package/dist/types/modules/tag.d.ts +6 -7
  96. package/dist/types/types/debug.d.ts +2 -2
  97. package/dist/types/types/index.d.ts +12 -51
  98. package/dist/types/utils/error.d.ts +0 -26
  99. package/dist/types/utils/headers.d.ts +1 -1
  100. package/dist/types/utils/http.d.ts +12 -21
  101. package/dist/types/utils/type.d.ts +2 -2
  102. package/package.json +4 -4
  103. package/dist/223.index.browser.min.js +0 -3
  104. package/dist/223.index.browser.min.js.LICENSE.txt +0 -1
  105. package/dist/223.index.browser.min.js.map +0 -1
  106. package/dist/cjs/utils/merge.js +0 -34
  107. package/dist/cjs/utils/sleep.js +0 -12
  108. package/dist/mjs/utils/merge.js +0 -32
  109. package/dist/mjs/utils/sleep.js +0 -8
  110. package/dist/types/utils/merge.d.ts +0 -8
  111. package/dist/types/utils/sleep.d.ts +0 -6
package/dist/mjs/bee.js CHANGED
@@ -1,33 +1,32 @@
1
- import * as bzz from "./modules/bzz.js";
2
- import * as stewardship from "./modules/stewardship.js";
3
- import * as tag from "./modules/tag.js";
4
- import * as pinning from "./modules/pinning.js";
5
- import * as bytes from "./modules/bytes.js";
6
- import * as chunk from "./modules/chunk.js";
7
- import * as pss from "./modules/pss.js";
8
- import * as status from "./modules/status.js";
9
- import { BeeArgumentError, BeeError } from "./utils/error.js";
10
- import { prepareWebsocketData } from "./utils/data.js";
11
- import { fileArrayBuffer, isFile } from "./utils/file.js";
12
- import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
1
+ import { ReferenceType } from '@ethersphere/swarm-cid';
2
+ import { Objects } from 'cafe-utility';
13
3
  import { makeSigner } from "./chunk/signer.js";
14
- import { assertFeedType, DEFAULT_FEED_TYPE } from "./feed/type.js";
15
4
  import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
5
+ import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
6
+ import { getJsonData, setJsonData } from "./feed/json.js";
7
+ import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
16
8
  import { makeTopic, makeTopicFromString } from "./feed/topic.js";
9
+ import { assertFeedType, DEFAULT_FEED_TYPE } from "./feed/type.js";
10
+ import * as bytes from "./modules/bytes.js";
11
+ import * as bzz from "./modules/bzz.js";
12
+ import * as chunk from "./modules/chunk.js";
17
13
  import { createFeedManifest } from "./modules/feed.js";
18
- import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
19
- import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
14
+ import * as pinning from "./modules/pinning.js";
15
+ import * as pss from "./modules/pss.js";
16
+ import * as status from "./modules/status.js";
17
+ import * as stewardship from "./modules/stewardship.js";
18
+ import * as tag from "./modules/tag.js";
19
+ import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
20
20
  import { wrapBytesWithHelpers } from "./utils/bytes.js";
21
- import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
22
- import { getJsonData, setJsonData } from "./feed/json.js";
23
21
  import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
24
22
  import { makeCollectionFromFS } from "./utils/collection.node.js";
25
- import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
26
- import { DEFAULT_KY_CONFIG, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
23
+ import { prepareWebsocketData } from "./utils/data.js";
24
+ import { BeeArgumentError, BeeError } from "./utils/error.js";
25
+ import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
26
+ import { fileArrayBuffer, isFile } from "./utils/file.js";
27
27
  import { isReadable } from "./utils/stream.js";
28
- import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
29
- import { ReferenceType } from '@ethersphere/swarm-cid';
30
- import { deepMerge } from "./utils/merge.js";
28
+ import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
29
+ import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
31
30
  /**
32
31
  * The main component that abstracts operations available on the main Bee API.
33
32
  *
@@ -48,26 +47,14 @@ export class Bee {
48
47
  if (options?.signer) {
49
48
  this.signer = makeSigner(options.signer);
50
49
  }
51
- const kyOptions = {
52
- prefixUrl: this.url,
53
- timeout: options?.timeout ?? false,
54
- retry: options?.retry,
55
- fetch: options?.fetch,
56
- hooks: {
57
- beforeRequest: [],
58
- afterResponse: []
59
- }
50
+ const requestOptions = {
51
+ baseURL: this.url,
52
+ timeout: options?.timeout ?? false
60
53
  };
61
- if (options?.defaultHeaders) {
62
- kyOptions.headers = options.defaultHeaders;
63
- }
64
- if (options?.onRequest) {
65
- kyOptions.hooks.beforeRequest.push(wrapRequestClosure(options.onRequest));
66
- }
67
- if (options?.onResponse) {
68
- kyOptions.hooks.afterResponse.push(wrapResponseClosure(options.onResponse));
54
+ if (options?.headers) {
55
+ requestOptions.headers = options.headers;
69
56
  }
70
- this.kyOptions = deepMerge(DEFAULT_KY_CONFIG, kyOptions);
57
+ this.requestOptions = requestOptions;
71
58
  }
72
59
  /**
73
60
  * Upload data to a Bee node
@@ -80,11 +67,11 @@ export class Bee {
80
67
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
81
68
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
82
69
  */
83
- async uploadData(postageBatchId, data, options) {
70
+ async uploadData(postageBatchId, data, options, requestOptions) {
84
71
  assertBatchId(postageBatchId);
85
72
  assertData(data);
86
73
  if (options) assertUploadOptions(options);
87
- return bytes.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
74
+ return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
88
75
  }
89
76
  /**
90
77
  * Download data as a byte array
@@ -99,7 +86,7 @@ export class Bee {
99
86
  async downloadData(reference, options) {
100
87
  assertRequestOptions(options);
101
88
  assertReferenceOrEns(reference);
102
- return bytes.download(this.getKyOptionsForCall(options), reference);
89
+ return bytes.download(this.getRequestOptionsForCall(options), reference);
103
90
  }
104
91
  /**
105
92
  * Download data as a Readable stream
@@ -114,7 +101,7 @@ export class Bee {
114
101
  async downloadReadableData(reference, options) {
115
102
  assertRequestOptions(options);
116
103
  assertReferenceOrEns(reference);
117
- return bytes.downloadReadable(this.getKyOptionsForCall(options), reference);
104
+ return bytes.downloadReadable(this.getRequestOptionsForCall(options), reference);
118
105
  }
119
106
  /**
120
107
  * Upload chunk to a Bee node
@@ -127,7 +114,7 @@ export class Bee {
127
114
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
128
115
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
129
116
  */
130
- async uploadChunk(postageBatchId, data, options) {
117
+ async uploadChunk(postageBatchId, data, options, requestOptions) {
131
118
  assertBatchId(postageBatchId);
132
119
  if (!(data instanceof Uint8Array)) {
133
120
  throw new TypeError('Data has to be Uint8Array instance!');
@@ -139,7 +126,7 @@ export class Bee {
139
126
  throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
140
127
  }
141
128
  if (options) assertUploadOptions(options);
142
- return chunk.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
129
+ return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
143
130
  }
144
131
  /**
145
132
  * Download chunk as a byte array
@@ -154,7 +141,7 @@ export class Bee {
154
141
  async downloadChunk(reference, options) {
155
142
  assertRequestOptions(options);
156
143
  assertReferenceOrEns(reference);
157
- return chunk.download(this.getKyOptionsForCall(options), reference);
144
+ return chunk.download(this.getRequestOptionsForCall(options), reference);
158
145
  }
159
146
  /**
160
147
  * Upload single file to a Bee node.
@@ -172,7 +159,7 @@ export class Bee {
172
159
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
173
160
  * @returns reference is a content hash of the file
174
161
  */
175
- async uploadFile(postageBatchId, data, name, options) {
162
+ async uploadFile(postageBatchId, data, name, options, requestOptions) {
176
163
  assertBatchId(postageBatchId);
177
164
  assertFileData(data);
178
165
  if (options) assertFileUploadOptions(options);
@@ -187,14 +174,14 @@ export class Bee {
187
174
  contentType,
188
175
  ...options
189
176
  };
190
- return addCidConversionFunction(await bzz.uploadFile(this.getKyOptionsForCall(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
177
+ return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
191
178
  } else if (isReadable(data) && options?.tag && !options.size) {
192
179
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
193
- const result = await bzz.uploadFile(this.getKyOptionsForCall(options), data, postageBatchId, name, options);
180
+ const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
194
181
  await this.updateTag(options.tag, result.reference);
195
182
  return addCidConversionFunction(result, ReferenceType.MANIFEST);
196
183
  } else {
197
- return addCidConversionFunction(await bzz.uploadFile(this.getKyOptionsForCall(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
184
+ return addCidConversionFunction(await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options), ReferenceType.MANIFEST);
198
185
  }
199
186
  }
200
187
  /**
@@ -212,7 +199,7 @@ export class Bee {
212
199
  async downloadFile(reference, path = '', options) {
213
200
  assertRequestOptions(options);
214
201
  reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
215
- return bzz.downloadFile(this.getKyOptionsForCall(options), reference, path);
202
+ return bzz.downloadFile(this.getRequestOptionsForCall(options), reference, path);
216
203
  }
217
204
  /**
218
205
  * Download single file as a readable stream
@@ -229,7 +216,7 @@ export class Bee {
229
216
  async downloadReadableFile(reference, path = '', options) {
230
217
  assertRequestOptions(options);
231
218
  reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
232
- return bzz.downloadFileReadable(this.getKyOptionsForCall(options), reference, path);
219
+ return bzz.downloadFileReadable(this.getRequestOptionsForCall(options), reference, path);
233
220
  }
234
221
  /**
235
222
  * Upload collection of files to a Bee node
@@ -247,11 +234,11 @@ export class Bee {
247
234
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
248
235
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
249
236
  */
250
- async uploadFiles(postageBatchId, fileList, options) {
237
+ async uploadFiles(postageBatchId, fileList, options, requestOptions) {
251
238
  assertBatchId(postageBatchId);
252
239
  if (options) assertCollectionUploadOptions(options);
253
240
  const data = await makeCollectionFromFileList(fileList);
254
- return addCidConversionFunction(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), ReferenceType.MANIFEST);
241
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
255
242
  }
256
243
  /**
257
244
  * Upload Collection that you can assembly yourself.
@@ -267,7 +254,7 @@ export class Bee {
267
254
  assertBatchId(postageBatchId);
268
255
  assertCollection(collection);
269
256
  if (options) assertCollectionUploadOptions(options);
270
- return addCidConversionFunction(await bzz.uploadCollection(this.kyOptions, collection, postageBatchId, options), ReferenceType.MANIFEST);
257
+ return addCidConversionFunction(await bzz.uploadCollection(this.requestOptions, collection, postageBatchId, options), ReferenceType.MANIFEST);
271
258
  }
272
259
  /**
273
260
  * Upload collection of files.
@@ -285,11 +272,11 @@ export class Bee {
285
272
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
286
273
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
287
274
  */
288
- async uploadFilesFromDirectory(postageBatchId, dir, options) {
275
+ async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
289
276
  assertBatchId(postageBatchId);
290
277
  if (options) assertCollectionUploadOptions(options);
291
278
  const data = await makeCollectionFromFS(dir);
292
- return addCidConversionFunction(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), ReferenceType.MANIFEST);
279
+ return addCidConversionFunction(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), ReferenceType.MANIFEST);
293
280
  }
294
281
  /**
295
282
  * Create a new Tag which is meant for tracking progres of syncing data across network.
@@ -300,7 +287,7 @@ export class Bee {
300
287
  */
301
288
  async createTag(options) {
302
289
  assertRequestOptions(options);
303
- return tag.createTag(this.getKyOptionsForCall(options));
290
+ return tag.createTag(this.getRequestOptionsForCall(options));
304
291
  }
305
292
  /**
306
293
  * Fetches all tags.
@@ -317,7 +304,7 @@ export class Bee {
317
304
  async getAllTags(options) {
318
305
  assertRequestOptions(options);
319
306
  assertAllTagsOptions(options);
320
- return tag.getAllTags(this.getKyOptionsForCall(options), options?.offset, options?.limit);
307
+ return tag.getAllTags(this.getRequestOptionsForCall(options), options?.offset, options?.limit);
321
308
  }
322
309
  /**
323
310
  * Retrieve tag information from Bee node
@@ -333,7 +320,7 @@ export class Bee {
333
320
  async retrieveTag(tagUid, options) {
334
321
  assertRequestOptions(options);
335
322
  tagUid = makeTagUid(tagUid);
336
- return tag.retrieveTag(this.getKyOptionsForCall(options), tagUid);
323
+ return tag.retrieveTag(this.getRequestOptionsForCall(options), tagUid);
337
324
  }
338
325
  /**
339
326
  * Delete Tag
@@ -349,7 +336,7 @@ export class Bee {
349
336
  async deleteTag(tagUid, options) {
350
337
  assertRequestOptions(options);
351
338
  tagUid = makeTagUid(tagUid);
352
- return tag.deleteTag(this.getKyOptionsForCall(options), tagUid);
339
+ return tag.deleteTag(this.getRequestOptionsForCall(options), tagUid);
353
340
  }
354
341
  /**
355
342
  * Update tag's total chunks count.
@@ -370,7 +357,7 @@ export class Bee {
370
357
  assertReference(reference);
371
358
  assertRequestOptions(options);
372
359
  tagUid = makeTagUid(tagUid);
373
- return tag.updateTag(this.getKyOptionsForCall(options), tagUid, reference);
360
+ return tag.updateTag(this.getRequestOptionsForCall(options), tagUid, reference);
374
361
  }
375
362
  /**
376
363
  * Pin local data with given reference
@@ -384,7 +371,7 @@ export class Bee {
384
371
  async pin(reference, options) {
385
372
  assertRequestOptions(options);
386
373
  assertReference(reference);
387
- return pinning.pin(this.getKyOptionsForCall(options), reference);
374
+ return pinning.pin(this.getRequestOptionsForCall(options), reference);
388
375
  }
389
376
  /**
390
377
  * Unpin local data with given reference
@@ -398,7 +385,7 @@ export class Bee {
398
385
  async unpin(reference, options) {
399
386
  assertRequestOptions(options);
400
387
  assertReference(reference);
401
- return pinning.unpin(this.getKyOptionsForCall(options), reference);
388
+ return pinning.unpin(this.getRequestOptionsForCall(options), reference);
402
389
  }
403
390
  /**
404
391
  * Get list of all locally pinned references
@@ -408,7 +395,7 @@ export class Bee {
408
395
  */
409
396
  async getAllPins(options) {
410
397
  assertRequestOptions(options);
411
- return pinning.getAllPins(this.getKyOptionsForCall(options));
398
+ return pinning.getAllPins(this.getRequestOptionsForCall(options));
412
399
  }
413
400
  /**
414
401
  * Get pinning status of chunk with given reference
@@ -423,7 +410,7 @@ export class Bee {
423
410
  async getPin(reference, options) {
424
411
  assertRequestOptions(options);
425
412
  assertReference(reference);
426
- return pinning.getPin(this.getKyOptionsForCall(options), reference);
413
+ return pinning.getPin(this.getRequestOptionsForCall(options), reference);
427
414
  }
428
415
  /**
429
416
  * Instructs the Bee node to reupload a locally pinned data into the network.
@@ -439,7 +426,7 @@ export class Bee {
439
426
  async reuploadPinnedData(reference, options) {
440
427
  assertRequestOptions(options);
441
428
  assertReferenceOrEns(reference);
442
- await stewardship.reupload(this.getKyOptionsForCall(options), reference);
429
+ await stewardship.reupload(this.getRequestOptionsForCall(options), reference);
443
430
  }
444
431
  /**
445
432
  * Checks if content specified by reference is retrievable from the network.
@@ -454,7 +441,7 @@ export class Bee {
454
441
  async isReferenceRetrievable(reference, options) {
455
442
  assertRequestOptions(options);
456
443
  assertReferenceOrEns(reference);
457
- return stewardship.isRetrievable(this.getKyOptionsForCall(options), reference);
444
+ return stewardship.isRetrievable(this.getRequestOptionsForCall(options), reference);
458
445
  }
459
446
  /**
460
447
  * Functions that validates if feed is retrievable in the network.
@@ -479,9 +466,7 @@ export class Bee {
479
466
  await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
480
467
  return true;
481
468
  } catch (e) {
482
- const err = e;
483
- // Only if the error is "not-found" then we return false otherwise we re-throw the error
484
- if (err?.status === 404) {
469
+ if (e?.response?.status === 404) {
485
470
  return false;
486
471
  }
487
472
  throw e;
@@ -490,7 +475,7 @@ export class Bee {
490
475
  if (type !== 'sequence') {
491
476
  throw new BeeError('Only Sequence type of Feeds is supported at the moment');
492
477
  }
493
- return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, options);
478
+ return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, this.getRequestOptionsForCall(options));
494
479
  }
495
480
  /**
496
481
  * Send data to recipient or target with Postal Service for Swarm.
@@ -524,9 +509,9 @@ export class Bee {
524
509
  }
525
510
  if (recipient) {
526
511
  assertPublicKey(recipient);
527
- return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId, recipient);
512
+ return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId, recipient);
528
513
  } else {
529
- return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId);
514
+ return pss.send(this.getRequestOptionsForCall(options), topic, target, data, postageBatchId);
530
515
  }
531
516
  }
532
517
  /**
@@ -654,7 +639,7 @@ export class Bee {
654
639
  assertBatchId(postageBatchId);
655
640
  const canonicalTopic = makeTopic(topic);
656
641
  const canonicalOwner = makeHexEthAddress(owner);
657
- const reference = await createFeedManifest(this.getKyOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId, {
642
+ const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId, {
658
643
  type
659
644
  });
660
645
  return addCidConversionFunction({
@@ -676,7 +661,7 @@ export class Bee {
676
661
  assertFeedType(type);
677
662
  const canonicalTopic = makeTopic(topic);
678
663
  const canonicalOwner = makeHexEthAddress(owner);
679
- return makeFeedReader(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalOwner);
664
+ return makeFeedReader(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalOwner);
680
665
  }
681
666
  /**
682
667
  * Make a new feed writer for updating feeds
@@ -693,7 +678,7 @@ export class Bee {
693
678
  assertFeedType(type);
694
679
  const canonicalTopic = makeTopic(topic);
695
680
  const canonicalSigner = this.resolveSigner(signer);
696
- return makeFeedWriter(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalSigner);
681
+ return makeFeedWriter(this.getRequestOptionsForCall(options), type, canonicalTopic, canonicalSigner);
697
682
  }
698
683
  /**
699
684
  * High-level function that allows you to easily set JSON data to feed.
@@ -713,13 +698,13 @@ export class Bee {
713
698
  *
714
699
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
715
700
  */
716
- async setJsonFeed(postageBatchId, topic, data, options) {
701
+ async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
717
702
  assertRequestOptions(options, 'JsonFeedOptions');
718
703
  assertBatchId(postageBatchId);
719
704
  const hashedTopic = this.makeFeedTopic(topic);
720
705
  const feedType = options?.type ?? DEFAULT_FEED_TYPE;
721
- const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, options);
722
- return setJsonData(this, writer, postageBatchId, data, options);
706
+ const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, requestOptions);
707
+ return setJsonData(this, writer, postageBatchId, data, options, requestOptions);
723
708
  }
724
709
  /**
725
710
  * High-level function that allows you to easily get data from feed.
@@ -787,7 +772,7 @@ export class Bee {
787
772
  const canonicalOwner = makeEthAddress(ownerAddress);
788
773
  return {
789
774
  owner: makeHexEthAddress(canonicalOwner),
790
- download: downloadSingleOwnerChunk.bind(null, this.getKyOptionsForCall(options), canonicalOwner)
775
+ download: downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(options), canonicalOwner)
791
776
  };
792
777
  }
793
778
  /**
@@ -802,7 +787,7 @@ export class Bee {
802
787
  const canonicalSigner = this.resolveSigner(signer);
803
788
  return {
804
789
  ...this.makeSOCReader(canonicalSigner.address, options),
805
- upload: uploadSingleOwnerChunkData.bind(null, this.getKyOptionsForCall(options), canonicalSigner)
790
+ upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner)
806
791
  };
807
792
  }
808
793
  /**
@@ -813,7 +798,7 @@ export class Bee {
813
798
  */
814
799
  async checkConnection(options) {
815
800
  assertRequestOptions(options, 'PostageBatchOptions');
816
- return status.checkConnection(this.getKyOptionsForCall(options));
801
+ return status.checkConnection(this.getRequestOptionsForCall(options));
817
802
  }
818
803
  /**
819
804
  * Ping the Bee node to see if there is a live Bee node on the given URL.
@@ -824,7 +809,7 @@ export class Bee {
824
809
  async isConnected(options) {
825
810
  assertRequestOptions(options, 'PostageBatchOptions');
826
811
  try {
827
- await status.checkConnection(this.getKyOptionsForCall(options));
812
+ await status.checkConnection(this.getRequestOptionsForCall(options));
828
813
  } catch (e) {
829
814
  return false;
830
815
  }
@@ -844,7 +829,7 @@ export class Bee {
844
829
  }
845
830
  throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
846
831
  }
847
- getKyOptionsForCall(options) {
848
- return deepMerge(this.kyOptions, options);
832
+ getRequestOptionsForCall(options) {
833
+ return options ? Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
849
834
  }
850
835
  }
@@ -1,15 +1,15 @@
1
+ import * as chunkAPI from "../modules/chunk.js";
2
+ import * as socAPI from "../modules/soc.js";
1
3
  import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
2
- import { bmtHash } from "./bmt.js";
3
- import { recoverAddress, sign } from "./signer.js";
4
- import { keccak256Hash } from "../utils/hash.js";
5
- import { SPAN_SIZE } from "./span.js";
6
- import { serializeBytes } from "./serialize.js";
7
4
  import { BeeError } from "../utils/error.js";
8
- import { makeContentAddressedChunk, MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE, assertValidChunkData } from "./cac.js";
5
+ import { keccak256Hash } from "../utils/hash.js";
9
6
  import { bytesToHex } from "../utils/hex.js";
10
- import * as socAPI from "../modules/soc.js";
11
- import * as chunkAPI from "../modules/chunk.js";
12
7
  import { assertAddress } from "../utils/type.js";
8
+ import { bmtHash } from "./bmt.js";
9
+ import { assertValidChunkData, makeContentAddressedChunk, MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE } from "./cac.js";
10
+ import { serializeBytes } from "./serialize.js";
11
+ import { recoverAddress, sign } from "./signer.js";
12
+ import { SPAN_SIZE } from "./span.js";
13
13
  const IDENTIFIER_SIZE = 32;
14
14
  const SIGNATURE_SIZE = 65;
15
15
  const SOC_IDENTIFIER_OFFSET = 0;
@@ -90,12 +90,12 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
90
90
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
91
91
  * @param options Upload options
92
92
  */
93
- export async function uploadSingleOwnerChunk(kyOptions, chunk, postageBatchId, options) {
93
+ export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatchId, options) {
94
94
  const owner = bytesToHex(chunk.owner());
95
95
  const identifier = bytesToHex(chunk.identifier());
96
96
  const signature = bytesToHex(chunk.signature());
97
97
  const data = serializeBytes(chunk.span(), chunk.payload());
98
- return socAPI.upload(kyOptions, owner, identifier, signature, data, postageBatchId, options);
98
+ return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
99
99
  }
100
100
  /**
101
101
  * Helper function to create and upload SOC.
@@ -107,11 +107,11 @@ export async function uploadSingleOwnerChunk(kyOptions, chunk, postageBatchId, o
107
107
  * @param data The chunk data
108
108
  * @param options
109
109
  */
110
- export async function uploadSingleOwnerChunkData(kyOptions, signer, postageBatchId, identifier, data, options) {
110
+ export async function uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, data, options) {
111
111
  assertAddress(postageBatchId);
112
112
  const cac = makeContentAddressedChunk(data);
113
113
  const soc = await makeSingleOwnerChunk(cac, identifier, signer);
114
- return uploadSingleOwnerChunk(kyOptions, soc, postageBatchId, options);
114
+ return uploadSingleOwnerChunk(requestOptions, soc, postageBatchId, options);
115
115
  }
116
116
  /**
117
117
  * Helper function to download SOC.
@@ -120,8 +120,8 @@ export async function uploadSingleOwnerChunkData(kyOptions, signer, postageBatch
120
120
  * @param ownerAddress The singer interface for signing the chunk
121
121
  * @param identifier The identifier of the chunk
122
122
  */
123
- export async function downloadSingleOwnerChunk(kyOptions, ownerAddress, identifier) {
123
+ export async function downloadSingleOwnerChunk(requestOptions, ownerAddress, identifier) {
124
124
  const address = makeSOCAddress(identifier, ownerAddress);
125
- const data = await chunkAPI.download(kyOptions, bytesToHex(address));
125
+ const data = await chunkAPI.download(requestOptions, bytesToHex(address));
126
126
  return makeSingleOwnerChunkFromData(data, address);
127
127
  }
@@ -1,48 +1,47 @@
1
- import { keccak256Hash } from "../utils/hash.js";
2
1
  import { serializeBytes } from "../chunk/serialize.js";
3
- import { fetchLatestFeedUpdate } from "../modules/feed.js";
4
2
  import { makeSingleOwnerChunkFromData, uploadSingleOwnerChunkData } from "../chunk/soc.js";
3
+ import * as chunkAPI from "../modules/chunk.js";
4
+ import { fetchLatestFeedUpdate } from "../modules/feed.js";
5
5
  import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
6
6
  import { bytesAtOffset, makeBytes } from "../utils/bytes.js";
7
- import { BeeResponseError } from "../utils/error.js";
8
- import { bytesToHex, hexToBytes, makeHexString } from "../utils/hex.js";
9
- import { readUint64BigEndian, writeUint64BigEndian } from "../utils/uint64.js";
10
- import * as chunkAPI from "../modules/chunk.js";
11
7
  import { makeHexEthAddress } from "../utils/eth.js";
8
+ import { keccak256Hash } from "../utils/hash.js";
9
+ import { bytesToHex, hexToBytes, makeHexString } from "../utils/hex.js";
10
+ import { makeBytesReference } from "../utils/reference.js";
12
11
  import { assertAddress } from "../utils/type.js";
12
+ import { readUint64BigEndian, writeUint64BigEndian } from "../utils/uint64.js";
13
13
  import { makeFeedIdentifier } from "./identifier.js";
14
- import { makeBytesReference } from "../utils/reference.js";
15
14
  const TIMESTAMP_PAYLOAD_OFFSET = 0;
16
15
  const TIMESTAMP_PAYLOAD_SIZE = 8;
17
16
  const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
18
- export async function findNextIndex(kyOptions, owner, topic, options) {
17
+ export async function findNextIndex(requestOptions, owner, topic, options) {
19
18
  try {
20
- const feedUpdate = await fetchLatestFeedUpdate(kyOptions, owner, topic, options);
19
+ const feedUpdate = await fetchLatestFeedUpdate(requestOptions, owner, topic, options);
21
20
  return makeHexString(feedUpdate.feedIndexNext, FEED_INDEX_HEX_LENGTH);
22
21
  } catch (e) {
23
- if (e instanceof BeeResponseError && e.status === 404) {
22
+ if (e?.response?.status === 404) {
24
23
  return bytesToHex(makeBytes(8));
25
24
  }
26
25
  throw e;
27
26
  }
28
27
  }
29
- export async function updateFeed(kyOptions, signer, topic, reference, postageBatchId, options, index = 'latest') {
28
+ export async function updateFeed(requestOptions, signer, topic, reference, postageBatchId, options, index = 'latest') {
30
29
  const ownerHex = makeHexEthAddress(signer.address);
31
- const nextIndex = index === 'latest' ? await findNextIndex(kyOptions, ownerHex, topic, options) : index;
30
+ const nextIndex = index === 'latest' ? await findNextIndex(requestOptions, ownerHex, topic, options) : index;
32
31
  const identifier = makeFeedIdentifier(topic, nextIndex);
33
32
  const at = options?.at ?? Date.now() / 1000.0;
34
33
  const timestamp = writeUint64BigEndian(at);
35
34
  const payloadBytes = serializeBytes(timestamp, reference);
36
- return uploadSingleOwnerChunkData(kyOptions, signer, postageBatchId, identifier, payloadBytes, options);
35
+ return uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, payloadBytes, options);
37
36
  }
38
37
  export function getFeedUpdateChunkReference(owner, topic, index) {
39
38
  const identifier = makeFeedIdentifier(topic, index);
40
39
  return keccak256Hash(identifier, owner);
41
40
  }
42
- export async function downloadFeedUpdate(kyOptions, owner, topic, index) {
41
+ export async function downloadFeedUpdate(requestOptions, owner, topic, index) {
43
42
  const address = getFeedUpdateChunkReference(owner, topic, index);
44
43
  const addressHex = bytesToHex(address);
45
- const data = await chunkAPI.download(kyOptions, addressHex);
44
+ const data = await chunkAPI.download(requestOptions, addressHex);
46
45
  const soc = makeSingleOwnerChunkFromData(data, address);
47
46
  const payload = soc.payload();
48
47
  const timestampBytes = bytesAtOffset(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
@@ -53,19 +52,19 @@ export async function downloadFeedUpdate(kyOptions, owner, topic, index) {
53
52
  reference
54
53
  };
55
54
  }
56
- export function makeFeedReader(kyOptions, type, topic, owner) {
55
+ export function makeFeedReader(requestOptions, type, topic, owner) {
57
56
  return {
58
57
  type,
59
58
  owner,
60
59
  topic,
61
60
  async download(options) {
62
61
  if (!options?.index) {
63
- return fetchLatestFeedUpdate(kyOptions, owner, topic, {
62
+ return fetchLatestFeedUpdate(requestOptions, owner, topic, {
64
63
  ...options,
65
64
  type
66
65
  });
67
66
  }
68
- const update = await downloadFeedUpdate(kyOptions, hexToBytes(owner), topic, options.index);
67
+ const update = await downloadFeedUpdate(requestOptions, hexToBytes(owner), topic, options.index);
69
68
  return {
70
69
  reference: bytesToHex(update.reference),
71
70
  feedIndex: options.index,
@@ -74,17 +73,17 @@ export function makeFeedReader(kyOptions, type, topic, owner) {
74
73
  }
75
74
  };
76
75
  }
77
- export function makeFeedWriter(kyOptions, type, topic, signer) {
76
+ export function makeFeedWriter(requestOptions, type, topic, signer) {
78
77
  const upload = async (postageBatchId, reference, options) => {
79
78
  assertAddress(postageBatchId);
80
79
  const canonicalReference = makeBytesReference(reference);
81
- return updateFeed(kyOptions, signer, topic, canonicalReference, postageBatchId, {
80
+ return updateFeed(requestOptions, signer, topic, canonicalReference, postageBatchId, {
82
81
  ...options,
83
82
  type
84
83
  });
85
84
  };
86
85
  return {
87
- ...makeFeedReader(kyOptions, type, topic, makeHexEthAddress(signer.address)),
86
+ ...makeFeedReader(requestOptions, type, topic, makeHexEthAddress(signer.address)),
88
87
  upload
89
88
  };
90
89
  }
@@ -15,10 +15,10 @@ export async function getJsonData(bee, reader) {
15
15
  const retrievedData = await bee.downloadData(feedUpdate.reference);
16
16
  return retrievedData.json();
17
17
  }
18
- export async function setJsonData(bee, writer, postageBatchId, data, options) {
18
+ export async function setJsonData(bee, writer, postageBatchId, data, options, requestOptions) {
19
19
  const serializedData = serializeJson(data);
20
20
  const {
21
21
  reference
22
- } = await bee.uploadData(postageBatchId, serializedData, options);
22
+ } = await bee.uploadData(postageBatchId, serializedData, options, requestOptions);
23
23
  return writer.upload(postageBatchId, reference);
24
24
  }
@@ -1,6 +1,6 @@
1
- import { getFeedUpdateChunkReference } from "./index.js";
2
- import { readUint64BigEndian } from "../utils/uint64.js";
3
1
  import { bytesToHex } from "../utils/hex.js";
2
+ import { readUint64BigEndian } from "../utils/uint64.js";
3
+ import { getFeedUpdateChunkReference } from "./index.js";
4
4
  function makeNumericIndex(index) {
5
5
  if (index instanceof Uint8Array) {
6
6
  return readUint64BigEndian(index);
@@ -21,13 +21,12 @@ function makeNumericIndex(index) {
21
21
  * @param ref
22
22
  * @param options
23
23
  */
24
- async function isChunkRetrievable(bee, ref, options) {
24
+ async function isChunkRetrievable(bee, ref, requestOptions) {
25
25
  try {
26
- await bee.downloadChunk(ref, options);
26
+ await bee.downloadChunk(ref, requestOptions);
27
27
  return true;
28
28
  } catch (e) {
29
- const err = e;
30
- if (err.status === 404) {
29
+ if (e?.response?.status === 404) {
31
30
  return false;
32
31
  }
33
32
  throw e;
@@ -48,7 +47,7 @@ function getAllSequenceUpdateReferences(owner, topic, index) {
48
47
  }
49
48
  return updateReferences;
50
49
  }
51
- export async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
52
- const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async ref => isChunkRetrievable(bee, ref, options));
50
+ export async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, requestOptions) {
51
+ const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async ref => isChunkRetrievable(bee, ref, requestOptions));
53
52
  return (await Promise.all(chunkRetrievablePromises)).every(result => result);
54
53
  }