@ethersphere/bee-js 5.1.1 → 5.1.2

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 (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/mjs/bee.js CHANGED
@@ -1,35 +1,3 @@
1
- var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) {
3
- return value instanceof P ? value : new P(function (resolve) {
4
- resolve(value);
5
- });
6
- }
7
-
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) {
10
- try {
11
- step(generator.next(value));
12
- } catch (e) {
13
- reject(e);
14
- }
15
- }
16
-
17
- function rejected(value) {
18
- try {
19
- step(generator["throw"](value));
20
- } catch (e) {
21
- reject(e);
22
- }
23
- }
24
-
25
- function step(result) {
26
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
- }
28
-
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- };
32
-
33
1
  import * as bzz from "./modules/bzz.js";
34
2
  import * as stewardship from "./modules/stewardship.js";
35
3
  import * as tag from "./modules/tag.js";
@@ -55,59 +23,51 @@ import { getJsonData, setJsonData } from "./feed/json.js";
55
23
  import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
56
24
  import { makeCollectionFromFS } from "./utils/collection.node.js";
57
25
  import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
58
- import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
26
+ import { DEFAULT_KY_CONFIG, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
59
27
  import { isReadable } from "./utils/stream.js";
60
28
  import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
61
29
  import { ReferenceType } from '@ethersphere/swarm-cid';
30
+ import { deepMerge } from "./utils/merge.js";
62
31
  /**
63
32
  * The main component that abstracts operations available on the main Bee API.
64
33
  *
65
34
  * Not all methods are always available as it depends in what mode is Bee node launched in.
66
35
  * For example gateway mode and light node mode has only limited set of endpoints enabled.
67
36
  */
68
-
69
37
  export class Bee {
70
38
  /**
71
39
  * @param url URL on which is the main API of Bee node exposed
72
40
  * @param options
73
41
  */
74
42
  constructor(url, options) {
75
- var _a;
76
-
77
- assertBeeUrl(url); // Remove last slash if present, as our endpoint strings starts with `/...`
43
+ assertBeeUrl(url);
44
+ // Remove last slash if present, as our endpoint strings starts with `/...`
78
45
  // which could lead to double slash in URL to which Bee responds with
79
46
  // unnecessary redirects.
80
-
81
47
  this.url = stripLastSlash(url);
82
-
83
- if (options === null || options === void 0 ? void 0 : options.signer) {
48
+ if (options?.signer) {
84
49
  this.signer = makeSigner(options.signer);
85
50
  }
86
-
87
51
  const kyOptions = {
88
52
  prefixUrl: this.url,
89
- timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : false,
90
- retry: options === null || options === void 0 ? void 0 : options.retry,
91
- fetch: options === null || options === void 0 ? void 0 : options.fetch,
53
+ timeout: options?.timeout ?? false,
54
+ retry: options?.retry,
55
+ fetch: options?.fetch,
92
56
  hooks: {
93
57
  beforeRequest: [],
94
58
  afterResponse: []
95
59
  }
96
60
  };
97
-
98
- if (options === null || options === void 0 ? void 0 : options.defaultHeaders) {
61
+ if (options?.defaultHeaders) {
99
62
  kyOptions.headers = options.defaultHeaders;
100
63
  }
101
-
102
- if (options === null || options === void 0 ? void 0 : options.onRequest) {
64
+ if (options?.onRequest) {
103
65
  kyOptions.hooks.beforeRequest.push(wrapRequestClosure(options.onRequest));
104
66
  }
105
-
106
- if (options === null || options === void 0 ? void 0 : options.onResponse) {
67
+ if (options?.onResponse) {
107
68
  kyOptions.hooks.afterResponse.push(wrapResponseClosure(options.onResponse));
108
69
  }
109
-
110
- this.ky = makeDefaultKy(kyOptions);
70
+ this.kyOptions = deepMerge(DEFAULT_KY_CONFIG, kyOptions);
111
71
  }
112
72
  /**
113
73
  * Upload data to a Bee node
@@ -120,15 +80,11 @@ export class Bee {
120
80
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
121
81
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
122
82
  */
123
-
124
-
125
- uploadData(postageBatchId, data, options) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- assertBatchId(postageBatchId);
128
- assertData(data);
129
- if (options) assertUploadOptions(options);
130
- return bytes.upload(this.getKy(options), data, postageBatchId, options);
131
- });
83
+ async uploadData(postageBatchId, data, options) {
84
+ assertBatchId(postageBatchId);
85
+ assertData(data);
86
+ if (options) assertUploadOptions(options);
87
+ return bytes.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
132
88
  }
133
89
  /**
134
90
  * Download data as a byte array
@@ -140,14 +96,10 @@ export class Bee {
140
96
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
141
97
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
142
98
  */
143
-
144
-
145
- downloadData(reference, options) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- assertRequestOptions(options);
148
- assertReferenceOrEns(reference);
149
- return bytes.download(this.getKy(options), reference);
150
- });
99
+ async downloadData(reference, options) {
100
+ assertRequestOptions(options);
101
+ assertReferenceOrEns(reference);
102
+ return bytes.download(this.getKyOptionsForCall(options), reference);
151
103
  }
152
104
  /**
153
105
  * Download data as a Readable stream
@@ -159,14 +111,10 @@ export class Bee {
159
111
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
160
112
  * @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
161
113
  */
162
-
163
-
164
- downloadReadableData(reference, options) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- assertRequestOptions(options);
167
- assertReferenceOrEns(reference);
168
- return bytes.downloadReadable(this.getKy(options), reference);
169
- });
114
+ async downloadReadableData(reference, options) {
115
+ assertRequestOptions(options);
116
+ assertReferenceOrEns(reference);
117
+ return bytes.downloadReadable(this.getKyOptionsForCall(options), reference);
170
118
  }
171
119
  /**
172
120
  * Upload chunk to a Bee node
@@ -179,27 +127,19 @@ export class Bee {
179
127
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
180
128
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
181
129
  */
182
-
183
-
184
- uploadChunk(postageBatchId, data, options) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- assertBatchId(postageBatchId);
187
-
188
- if (!(data instanceof Uint8Array)) {
189
- throw new TypeError('Data has to be Uint8Array instance!');
190
- }
191
-
192
- if (data.length < SPAN_SIZE) {
193
- throw new BeeArgumentError(`Chunk has to have size of at least ${SPAN_SIZE}.`, data);
194
- }
195
-
196
- if (data.length > CHUNK_SIZE + SPAN_SIZE) {
197
- throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
198
- }
199
-
200
- if (options) assertUploadOptions(options);
201
- return chunk.upload(this.getKy(options), data, postageBatchId, options);
202
- });
130
+ async uploadChunk(postageBatchId, data, options) {
131
+ assertBatchId(postageBatchId);
132
+ if (!(data instanceof Uint8Array)) {
133
+ throw new TypeError('Data has to be Uint8Array instance!');
134
+ }
135
+ if (data.length < SPAN_SIZE) {
136
+ throw new BeeArgumentError(`Chunk has to have size of at least ${SPAN_SIZE}.`, data);
137
+ }
138
+ if (data.length > CHUNK_SIZE + SPAN_SIZE) {
139
+ throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
140
+ }
141
+ if (options) assertUploadOptions(options);
142
+ return chunk.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
203
143
  }
204
144
  /**
205
145
  * Download chunk as a byte array
@@ -211,14 +151,10 @@ export class Bee {
211
151
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
212
152
  * @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
213
153
  */
214
-
215
-
216
- downloadChunk(reference, options) {
217
- return __awaiter(this, void 0, void 0, function* () {
218
- assertRequestOptions(options);
219
- assertReferenceOrEns(reference);
220
- return chunk.download(this.getKy(options), reference);
221
- });
154
+ async downloadChunk(reference, options) {
155
+ assertRequestOptions(options);
156
+ assertReferenceOrEns(reference);
157
+ return chunk.download(this.getKyOptionsForCall(options), reference);
222
158
  }
223
159
  /**
224
160
  * Upload single file to a Bee node.
@@ -236,35 +172,30 @@ export class Bee {
236
172
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
237
173
  * @returns reference is a content hash of the file
238
174
  */
239
-
240
-
241
- uploadFile(postageBatchId, data, name, options) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- assertBatchId(postageBatchId);
244
- assertFileData(data);
245
- if (options) assertFileUploadOptions(options);
246
-
247
- if (name && typeof name !== 'string') {
248
- throw new TypeError('name has to be string or undefined!');
249
- }
250
-
251
- if (isFile(data)) {
252
- const fileData = yield fileArrayBuffer(data);
253
- const fileName = name !== null && name !== void 0 ? name : data.name;
254
- const contentType = data.type;
255
- const fileOptions = Object.assign({
256
- contentType
257
- }, options);
258
- return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
259
- } else if (isReadable(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
260
- // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
261
- const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
262
- yield this.updateTag(options.tag, result.reference);
263
- return addCidConversionFunction(result, ReferenceType.MANIFEST);
264
- } else {
265
- return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
266
- }
267
- });
175
+ async uploadFile(postageBatchId, data, name, options) {
176
+ assertBatchId(postageBatchId);
177
+ assertFileData(data);
178
+ if (options) assertFileUploadOptions(options);
179
+ if (name && typeof name !== 'string') {
180
+ throw new TypeError('name has to be string or undefined!');
181
+ }
182
+ if (isFile(data)) {
183
+ const fileData = await fileArrayBuffer(data);
184
+ const fileName = name ?? data.name;
185
+ const contentType = data.type;
186
+ const fileOptions = {
187
+ contentType,
188
+ ...options
189
+ };
190
+ return addCidConversionFunction(await bzz.uploadFile(this.getKyOptionsForCall(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
191
+ } else if (isReadable(data) && options?.tag && !options.size) {
192
+ // 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);
194
+ await this.updateTag(options.tag, result.reference);
195
+ return addCidConversionFunction(result, ReferenceType.MANIFEST);
196
+ } else {
197
+ return addCidConversionFunction(await bzz.uploadFile(this.getKyOptionsForCall(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
198
+ }
268
199
  }
269
200
  /**
270
201
  * Download single file.
@@ -278,14 +209,10 @@ export class Bee {
278
209
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
279
210
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
280
211
  */
281
-
282
-
283
- downloadFile(reference, path = '', options) {
284
- return __awaiter(this, void 0, void 0, function* () {
285
- assertRequestOptions(options);
286
- reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
287
- return bzz.downloadFile(this.getKy(options), reference, path);
288
- });
212
+ async downloadFile(reference, path = '', options) {
213
+ assertRequestOptions(options);
214
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
215
+ return bzz.downloadFile(this.getKyOptionsForCall(options), reference, path);
289
216
  }
290
217
  /**
291
218
  * Download single file as a readable stream
@@ -299,14 +226,10 @@ export class Bee {
299
226
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
300
227
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
301
228
  */
302
-
303
-
304
- downloadReadableFile(reference, path = '', options) {
305
- return __awaiter(this, void 0, void 0, function* () {
306
- assertRequestOptions(options);
307
- reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
308
- return bzz.downloadFileReadable(this.getKy(options), reference, path);
309
- });
229
+ async downloadReadableFile(reference, path = '', options) {
230
+ assertRequestOptions(options);
231
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
232
+ return bzz.downloadFileReadable(this.getKyOptionsForCall(options), reference, path);
310
233
  }
311
234
  /**
312
235
  * Upload collection of files to a Bee node
@@ -324,15 +247,11 @@ export class Bee {
324
247
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
325
248
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
326
249
  */
327
-
328
-
329
- uploadFiles(postageBatchId, fileList, options) {
330
- return __awaiter(this, void 0, void 0, function* () {
331
- assertBatchId(postageBatchId);
332
- if (options) assertCollectionUploadOptions(options);
333
- const data = yield makeCollectionFromFileList(fileList);
334
- return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
335
- });
250
+ async uploadFiles(postageBatchId, fileList, options) {
251
+ assertBatchId(postageBatchId);
252
+ if (options) assertCollectionUploadOptions(options);
253
+ const data = await makeCollectionFromFileList(fileList);
254
+ return addCidConversionFunction(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), ReferenceType.MANIFEST);
336
255
  }
337
256
  /**
338
257
  * Upload Collection that you can assembly yourself.
@@ -344,15 +263,11 @@ export class Bee {
344
263
  * @param collection
345
264
  * @param options Collections and request options
346
265
  */
347
-
348
-
349
- uploadCollection(postageBatchId, collection, options) {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- assertBatchId(postageBatchId);
352
- assertCollection(collection);
353
- if (options) assertCollectionUploadOptions(options);
354
- return addCidConversionFunction(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), ReferenceType.MANIFEST);
355
- });
266
+ async uploadCollection(postageBatchId, collection, options) {
267
+ assertBatchId(postageBatchId);
268
+ assertCollection(collection);
269
+ if (options) assertCollectionUploadOptions(options);
270
+ return addCidConversionFunction(await bzz.uploadCollection(this.kyOptions, collection, postageBatchId, options), ReferenceType.MANIFEST);
356
271
  }
357
272
  /**
358
273
  * Upload collection of files.
@@ -370,40 +285,28 @@ export class Bee {
370
285
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
371
286
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
372
287
  */
373
-
374
-
375
- uploadFilesFromDirectory(postageBatchId, dir, options) {
376
- return __awaiter(this, void 0, void 0, function* () {
377
- assertBatchId(postageBatchId);
378
- if (options) assertCollectionUploadOptions(options);
379
- const data = yield makeCollectionFromFS(dir);
380
- return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
381
- });
288
+ async uploadFilesFromDirectory(postageBatchId, dir, options) {
289
+ assertBatchId(postageBatchId);
290
+ if (options) assertCollectionUploadOptions(options);
291
+ const data = await makeCollectionFromFS(dir);
292
+ return addCidConversionFunction(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), ReferenceType.MANIFEST);
382
293
  }
383
294
  /**
384
295
  * Create a new Tag which is meant for tracking progres of syncing data across network.
385
296
  *
386
- * **Warning! Not allowed when node is in Gateway mode!**
387
- *
388
297
  * @param options Options that affects the request behavior
389
298
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
390
299
  * @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
391
300
  */
392
-
393
-
394
- createTag(options) {
395
- return __awaiter(this, void 0, void 0, function* () {
396
- assertRequestOptions(options);
397
- return tag.createTag(this.getKy(options));
398
- });
301
+ async createTag(options) {
302
+ assertRequestOptions(options);
303
+ return tag.createTag(this.getKyOptionsForCall(options));
399
304
  }
400
305
  /**
401
306
  * Fetches all tags.
402
307
  *
403
308
  * The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
404
309
  *
405
- * **Warning! Not allowed when node is in Gateway mode!**
406
- *
407
310
  * @param options Options that affects the request behavior
408
311
  * @throws TypeError if limit or offset are not numbers or undefined
409
312
  * @throws BeeArgumentError if limit or offset have invalid options
@@ -411,20 +314,14 @@ export class Bee {
411
314
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
412
315
  * @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
413
316
  */
414
-
415
-
416
- getAllTags(options) {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- assertRequestOptions(options);
419
- assertAllTagsOptions(options);
420
- return tag.getAllTags(this.getKy(options), options === null || options === void 0 ? void 0 : options.offset, options === null || options === void 0 ? void 0 : options.limit);
421
- });
317
+ async getAllTags(options) {
318
+ assertRequestOptions(options);
319
+ assertAllTagsOptions(options);
320
+ return tag.getAllTags(this.getKyOptionsForCall(options), options?.offset, options?.limit);
422
321
  }
423
322
  /**
424
323
  * Retrieve tag information from Bee node
425
324
  *
426
- * **Warning! Not allowed when node is in Gateway mode!**
427
- *
428
325
  * @param tagUid UID or tag object to be retrieved
429
326
  * @param options Options that affects the request behavior
430
327
  * @throws TypeError if tagUid is in not correct format
@@ -433,20 +330,14 @@ export class Bee {
433
330
  * @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
434
331
  *
435
332
  */
436
-
437
-
438
- retrieveTag(tagUid, options) {
439
- return __awaiter(this, void 0, void 0, function* () {
440
- assertRequestOptions(options);
441
- tagUid = makeTagUid(tagUid);
442
- return tag.retrieveTag(this.getKy(options), tagUid);
443
- });
333
+ async retrieveTag(tagUid, options) {
334
+ assertRequestOptions(options);
335
+ tagUid = makeTagUid(tagUid);
336
+ return tag.retrieveTag(this.getKyOptionsForCall(options), tagUid);
444
337
  }
445
338
  /**
446
339
  * Delete Tag
447
340
  *
448
- * **Warning! Not allowed when node is in Gateway mode!**
449
- *
450
341
  * @param tagUid UID or tag object to be retrieved
451
342
  * @param options Options that affects the request behavior
452
343
  * @throws TypeError if tagUid is in not correct format
@@ -455,14 +346,10 @@ export class Bee {
455
346
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
456
347
  * @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
457
348
  */
458
-
459
-
460
- deleteTag(tagUid, options) {
461
- return __awaiter(this, void 0, void 0, function* () {
462
- assertRequestOptions(options);
463
- tagUid = makeTagUid(tagUid);
464
- return tag.deleteTag(this.getKy(options), tagUid);
465
- });
349
+ async deleteTag(tagUid, options) {
350
+ assertRequestOptions(options);
351
+ tagUid = makeTagUid(tagUid);
352
+ return tag.deleteTag(this.getKyOptionsForCall(options), tagUid);
466
353
  }
467
354
  /**
468
355
  * Update tag's total chunks count.
@@ -470,8 +357,6 @@ export class Bee {
470
357
  * This is important if you are uploading individual chunks with a tag. Then upon finishing the final root chunk,
471
358
  * you can use this method to update the total chunks count for the tag.
472
359
  *
473
- * **Warning! Not allowed when node is in Gateway mode!**
474
- *
475
360
  * @param tagUid UID or tag object to be retrieved
476
361
  * @param reference The root reference that contains all the chunks to be counted
477
362
  * @param options Options that affects the request behavior
@@ -481,77 +366,53 @@ export class Bee {
481
366
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
482
367
  * @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
483
368
  */
484
-
485
-
486
- updateTag(tagUid, reference, options) {
487
- return __awaiter(this, void 0, void 0, function* () {
488
- assertReference(reference);
489
- assertRequestOptions(options);
490
- tagUid = makeTagUid(tagUid);
491
- return tag.updateTag(this.getKy(options), tagUid, reference);
492
- });
369
+ async updateTag(tagUid, reference, options) {
370
+ assertReference(reference);
371
+ assertRequestOptions(options);
372
+ tagUid = makeTagUid(tagUid);
373
+ return tag.updateTag(this.getKyOptionsForCall(options), tagUid, reference);
493
374
  }
494
375
  /**
495
376
  * Pin local data with given reference
496
377
  *
497
- * **Warning! Not allowed when node is in Gateway mode!**
498
- *
499
378
  * @param reference Data reference
500
379
  * @param options Options that affects the request behavior
501
380
  * @throws TypeError if reference is in not correct format
502
381
  *
503
382
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
504
383
  */
505
-
506
-
507
- pin(reference, options) {
508
- return __awaiter(this, void 0, void 0, function* () {
509
- assertRequestOptions(options);
510
- assertReference(reference);
511
- return pinning.pin(this.getKy(options), reference);
512
- });
384
+ async pin(reference, options) {
385
+ assertRequestOptions(options);
386
+ assertReference(reference);
387
+ return pinning.pin(this.getKyOptionsForCall(options), reference);
513
388
  }
514
389
  /**
515
390
  * Unpin local data with given reference
516
391
  *
517
- * **Warning! Not allowed when node is in Gateway mode!**
518
- *
519
392
  * @param reference Data reference
520
393
  * @param options Options that affects the request behavior
521
394
  * @throws TypeError if reference is in not correct format
522
395
  *
523
396
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
524
397
  */
525
-
526
-
527
- unpin(reference, options) {
528
- return __awaiter(this, void 0, void 0, function* () {
529
- assertRequestOptions(options);
530
- assertReference(reference);
531
- return pinning.unpin(this.getKy(options), reference);
532
- });
398
+ async unpin(reference, options) {
399
+ assertRequestOptions(options);
400
+ assertReference(reference);
401
+ return pinning.unpin(this.getKyOptionsForCall(options), reference);
533
402
  }
534
403
  /**
535
404
  * Get list of all locally pinned references
536
405
  *
537
- * **Warning! Not allowed when node is in Gateway mode!**
538
- *
539
406
  * @param options Options that affects the request behavior
540
407
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
541
408
  */
542
-
543
-
544
- getAllPins(options) {
545
- return __awaiter(this, void 0, void 0, function* () {
546
- assertRequestOptions(options);
547
- return pinning.getAllPins(this.getKy(options));
548
- });
409
+ async getAllPins(options) {
410
+ assertRequestOptions(options);
411
+ return pinning.getAllPins(this.getKyOptionsForCall(options));
549
412
  }
550
413
  /**
551
414
  * Get pinning status of chunk with given reference
552
415
  *
553
- * **Warning! Not allowed when node is in Gateway mode!**
554
- *
555
416
  * @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
556
417
  * @param options Options that affects the request behavior
557
418
  * @throws TypeError if some of the input parameters is not expected type
@@ -559,14 +420,10 @@ export class Bee {
559
420
  *
560
421
  * @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
561
422
  */
562
-
563
-
564
- getPin(reference, options) {
565
- return __awaiter(this, void 0, void 0, function* () {
566
- assertRequestOptions(options);
567
- assertReference(reference);
568
- return pinning.getPin(this.getKy(options), reference);
569
- });
423
+ async getPin(reference, options) {
424
+ assertRequestOptions(options);
425
+ assertReference(reference);
426
+ return pinning.getPin(this.getKyOptionsForCall(options), reference);
570
427
  }
571
428
  /**
572
429
  * Instructs the Bee node to reupload a locally pinned data into the network.
@@ -579,14 +436,10 @@ export class Bee {
579
436
  *
580
437
  * @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
581
438
  */
582
-
583
-
584
- reuploadPinnedData(reference, options) {
585
- return __awaiter(this, void 0, void 0, function* () {
586
- assertRequestOptions(options);
587
- assertReferenceOrEns(reference);
588
- yield stewardship.reupload(this.getKy(options), reference);
589
- });
439
+ async reuploadPinnedData(reference, options) {
440
+ assertRequestOptions(options);
441
+ assertReferenceOrEns(reference);
442
+ await stewardship.reupload(this.getKyOptionsForCall(options), reference);
590
443
  }
591
444
  /**
592
445
  * Checks if content specified by reference is retrievable from the network.
@@ -598,14 +451,10 @@ export class Bee {
598
451
  *
599
452
  * @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
600
453
  */
601
-
602
-
603
- isReferenceRetrievable(reference, options) {
604
- return __awaiter(this, void 0, void 0, function* () {
605
- assertRequestOptions(options);
606
- assertReferenceOrEns(reference);
607
- return stewardship.isRetrievable(this.getKy(options), reference);
608
- });
454
+ async isReferenceRetrievable(reference, options) {
455
+ assertRequestOptions(options);
456
+ assertReferenceOrEns(reference);
457
+ return stewardship.isRetrievable(this.getKyOptionsForCall(options), reference);
609
458
  }
610
459
  /**
611
460
  * Functions that validates if feed is retrievable in the network.
@@ -622,34 +471,26 @@ export class Bee {
622
471
  * @param index
623
472
  * @param options
624
473
  */
625
-
626
-
627
- isFeedRetrievable(type, owner, topic, index, options) {
628
- return __awaiter(this, void 0, void 0, function* () {
629
- const canonicalOwner = makeEthAddress(owner);
630
- const canonicalTopic = makeTopic(topic);
631
-
632
- if (!index) {
633
- try {
634
- yield this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
635
- return true;
636
- } catch (e) {
637
- const err = e; // Only if the error is "not-found" then we return false otherwise we re-throw the error
638
-
639
- if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
640
- return false;
641
- }
642
-
643
- throw e;
474
+ async isFeedRetrievable(type, owner, topic, index, options) {
475
+ const canonicalOwner = makeEthAddress(owner);
476
+ const canonicalTopic = makeTopic(topic);
477
+ if (!index) {
478
+ try {
479
+ await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
480
+ return true;
481
+ } 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) {
485
+ return false;
644
486
  }
487
+ throw e;
645
488
  }
646
-
647
- if (type !== 'sequence') {
648
- throw new BeeError('Only Sequence type of Feeds is supported at the moment');
649
- }
650
-
651
- return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, options);
652
- });
489
+ }
490
+ if (type !== 'sequence') {
491
+ throw new BeeError('Only Sequence type of Feeds is supported at the moment');
492
+ }
493
+ return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, options);
653
494
  }
654
495
  /**
655
496
  * Send data to recipient or target with Postal Service for Swarm.
@@ -659,8 +500,6 @@ export class Bee {
659
500
  * most likely for setting up an encrypted communication
660
501
  * channel by sending an one-off message.
661
502
  *
662
- * **Warning! Not allowed when node is in Gateway mode!**
663
- *
664
503
  * **Warning! If the recipient Bee node is a light node, then he will never receive the message!**
665
504
  * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
666
505
  *
@@ -675,32 +514,24 @@ export class Bee {
675
514
  * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
676
515
  * @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
677
516
  */
678
-
679
-
680
- pssSend(postageBatchId, topic, target, data, recipient, options) {
681
- return __awaiter(this, void 0, void 0, function* () {
682
- assertRequestOptions(options);
683
- assertData(data);
684
- assertBatchId(postageBatchId);
685
- assertAddressPrefix(target);
686
-
687
- if (typeof topic !== 'string') {
688
- throw new TypeError('topic has to be an string!');
689
- }
690
-
691
- if (recipient) {
692
- assertPublicKey(recipient);
693
- return pss.send(this.getKy(options), topic, target, data, postageBatchId, recipient);
694
- } else {
695
- return pss.send(this.getKy(options), topic, target, data, postageBatchId);
696
- }
697
- });
517
+ async pssSend(postageBatchId, topic, target, data, recipient, options) {
518
+ assertRequestOptions(options);
519
+ assertData(data);
520
+ assertBatchId(postageBatchId);
521
+ assertAddressPrefix(target);
522
+ if (typeof topic !== 'string') {
523
+ throw new TypeError('topic has to be an string!');
524
+ }
525
+ if (recipient) {
526
+ assertPublicKey(recipient);
527
+ return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId, recipient);
528
+ } else {
529
+ return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId);
530
+ }
698
531
  }
699
532
  /**
700
533
  * Subscribe to messages for given topic with Postal Service for Swarm
701
534
  *
702
- * **Warning! Not allowed when node is in Gateway mode!**
703
- *
704
535
  * **Warning! If connected Bee node is a light node, then he will never receive any message!**
705
536
  * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
706
537
  *
@@ -712,24 +543,19 @@ export class Bee {
712
543
  * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
713
544
  * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
714
545
  */
715
-
716
-
717
546
  pssSubscribe(topic, handler) {
718
547
  assertPssMessageHandler(handler);
719
-
720
548
  if (typeof topic !== 'string') {
721
549
  throw new TypeError('topic has to be an string!');
722
550
  }
723
-
724
551
  const ws = pss.subscribe(this.url, topic);
725
552
  let cancelled = false;
726
-
727
553
  const cancel = () => {
728
554
  if (cancelled === false) {
729
- cancelled = true; // although the WebSocket API offers a `close` function, it seems that
555
+ cancelled = true;
556
+ // although the WebSocket API offers a `close` function, it seems that
730
557
  // with the library that we are using (isomorphic-ws) it doesn't close
731
558
  // the websocket properly, whereas `terminate` does
732
-
733
559
  if (ws.terminate) ws.terminate();else ws.close(); // standard Websocket in browser does not have terminate function
734
560
  }
735
561
  };
@@ -738,22 +564,19 @@ export class Bee {
738
564
  topic,
739
565
  cancel
740
566
  };
741
-
742
- ws.onmessage = ev => __awaiter(this, void 0, void 0, function* () {
743
- const data = yield prepareWebsocketData(ev.data); // ignore empty messages
744
-
567
+ ws.onmessage = async ev => {
568
+ const data = await prepareWebsocketData(ev.data);
569
+ // ignore empty messages
745
570
  if (data.length > 0) {
746
571
  handler.onMessage(wrapBytesWithHelpers(data), subscription);
747
572
  }
748
- });
749
-
573
+ };
750
574
  ws.onerror = ev => {
751
575
  // ignore errors after subscription was cancelled
752
576
  if (!cancelled) {
753
577
  handler.onError(new BeeError(ev.message), subscription);
754
578
  }
755
579
  };
756
-
757
580
  return subscription;
758
581
  }
759
582
  /**
@@ -769,8 +592,6 @@ export class Bee {
769
592
  * timeout can be provided for the message to arrive or else
770
593
  * an error will be thrown.
771
594
  *
772
- * **Warning! Not allowed when node is in Gateway mode!**
773
- *
774
595
  * **Warning! If connected Bee node is a light node, then he will never receive any message!**
775
596
  * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
776
597
  *
@@ -782,42 +603,35 @@ export class Bee {
782
603
  * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
783
604
  * @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
784
605
  */
785
-
786
-
787
- pssReceive(topic, timeoutMsec = 0) {
788
- return __awaiter(this, void 0, void 0, function* () {
789
- if (typeof topic !== 'string') {
790
- throw new TypeError('topic has to be an string!');
791
- }
792
-
793
- if (typeof timeoutMsec !== 'number') {
794
- throw new TypeError('timeoutMsc parameter has to be a number!');
795
- }
796
-
797
- return new Promise((resolve, reject) => {
798
- let timeout;
799
- const subscription = this.pssSubscribe(topic, {
800
- onError: error => {
801
- clearTimeout(timeout);
802
- subscription.cancel();
803
- reject(error.message);
804
- },
805
- onMessage: message => {
806
- clearTimeout(timeout);
807
- subscription.cancel();
808
- resolve(message);
809
- }
810
- });
811
-
812
- if (timeoutMsec > 0) {
813
- // we need to cast the type because Typescript is getting confused with Node.js'
814
- // alternative type definitions
815
- timeout = setTimeout(() => {
816
- subscription.cancel();
817
- reject(new BeeError('pssReceive timeout'));
818
- }, timeoutMsec);
606
+ async pssReceive(topic, timeoutMsec = 0) {
607
+ if (typeof topic !== 'string') {
608
+ throw new TypeError('topic has to be an string!');
609
+ }
610
+ if (typeof timeoutMsec !== 'number') {
611
+ throw new TypeError('timeoutMsc parameter has to be a number!');
612
+ }
613
+ return new Promise((resolve, reject) => {
614
+ let timeout;
615
+ const subscription = this.pssSubscribe(topic, {
616
+ onError: error => {
617
+ clearTimeout(timeout);
618
+ subscription.cancel();
619
+ reject(error.message);
620
+ },
621
+ onMessage: message => {
622
+ clearTimeout(timeout);
623
+ subscription.cancel();
624
+ resolve(message);
819
625
  }
820
626
  });
627
+ if (timeoutMsec > 0) {
628
+ // we need to cast the type because Typescript is getting confused with Node.js'
629
+ // alternative type definitions
630
+ timeout = setTimeout(() => {
631
+ subscription.cancel();
632
+ reject(new BeeError('pssReceive timeout'));
633
+ }, timeoutMsec);
634
+ }
821
635
  });
822
636
  }
823
637
  /**
@@ -834,22 +648,18 @@ export class Bee {
834
648
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
835
649
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
836
650
  */
837
-
838
-
839
- createFeedManifest(postageBatchId, type, topic, owner, options) {
840
- return __awaiter(this, void 0, void 0, function* () {
841
- assertRequestOptions(options);
842
- assertFeedType(type);
843
- assertBatchId(postageBatchId);
844
- const canonicalTopic = makeTopic(topic);
845
- const canonicalOwner = makeHexEthAddress(owner);
846
- const reference = yield createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, {
847
- type
848
- });
849
- return addCidConversionFunction({
850
- reference
851
- }, ReferenceType.FEED);
651
+ async createFeedManifest(postageBatchId, type, topic, owner, options) {
652
+ assertRequestOptions(options);
653
+ assertFeedType(type);
654
+ assertBatchId(postageBatchId);
655
+ const canonicalTopic = makeTopic(topic);
656
+ const canonicalOwner = makeHexEthAddress(owner);
657
+ const reference = await createFeedManifest(this.getKyOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId, {
658
+ type
852
659
  });
660
+ return addCidConversionFunction({
661
+ reference
662
+ }, ReferenceType.FEED);
853
663
  }
854
664
  /**
855
665
  * Make a new feed reader for downloading feed updates.
@@ -861,14 +671,12 @@ export class Bee {
861
671
  *
862
672
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
863
673
  */
864
-
865
-
866
674
  makeFeedReader(type, topic, owner, options) {
867
675
  assertRequestOptions(options);
868
676
  assertFeedType(type);
869
677
  const canonicalTopic = makeTopic(topic);
870
678
  const canonicalOwner = makeHexEthAddress(owner);
871
- return makeFeedReader(this.getKy(options), type, canonicalTopic, canonicalOwner);
679
+ return makeFeedReader(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalOwner);
872
680
  }
873
681
  /**
874
682
  * Make a new feed writer for updating feeds
@@ -880,14 +688,12 @@ export class Bee {
880
688
  *
881
689
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
882
690
  */
883
-
884
-
885
691
  makeFeedWriter(type, topic, signer, options) {
886
692
  assertRequestOptions(options);
887
693
  assertFeedType(type);
888
694
  const canonicalTopic = makeTopic(topic);
889
695
  const canonicalSigner = this.resolveSigner(signer);
890
- return makeFeedWriter(this.getKy(options), type, canonicalTopic, canonicalSigner);
696
+ return makeFeedWriter(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalSigner);
891
697
  }
892
698
  /**
893
699
  * High-level function that allows you to easily set JSON data to feed.
@@ -907,19 +713,13 @@ export class Bee {
907
713
  *
908
714
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
909
715
  */
910
-
911
-
912
- setJsonFeed(postageBatchId, topic, data, options) {
913
- var _a;
914
-
915
- return __awaiter(this, void 0, void 0, function* () {
916
- assertRequestOptions(options, 'JsonFeedOptions');
917
- assertBatchId(postageBatchId);
918
- const hashedTopic = this.makeFeedTopic(topic);
919
- const feedType = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : DEFAULT_FEED_TYPE;
920
- const writer = this.makeFeedWriter(feedType, hashedTopic, options === null || options === void 0 ? void 0 : options.signer, options);
921
- return setJsonData(this, writer, postageBatchId, data, options);
922
- });
716
+ async setJsonFeed(postageBatchId, topic, data, options) {
717
+ assertRequestOptions(options, 'JsonFeedOptions');
718
+ assertBatchId(postageBatchId);
719
+ const hashedTopic = this.makeFeedTopic(topic);
720
+ 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);
923
723
  }
924
724
  /**
925
725
  * High-level function that allows you to easily get data from feed.
@@ -940,39 +740,29 @@ export class Bee {
940
740
  *
941
741
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
942
742
  */
943
-
944
-
945
- getJsonFeed(topic, options) {
946
- var _a;
947
-
948
- return __awaiter(this, void 0, void 0, function* () {
949
- assertRequestOptions(options, 'JsonFeedOptions');
950
- const hashedTopic = this.makeFeedTopic(topic);
951
- const feedType = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : DEFAULT_FEED_TYPE;
952
-
953
- if ((options === null || options === void 0 ? void 0 : options.signer) && (options === null || options === void 0 ? void 0 : options.address)) {
954
- throw new BeeError('Both options "signer" and "address" can not be specified at one time!');
955
- }
956
-
957
- let address;
958
-
959
- if (options === null || options === void 0 ? void 0 : options.address) {
960
- address = makeEthAddress(options === null || options === void 0 ? void 0 : options.address);
961
- } else {
962
- try {
963
- address = this.resolveSigner(options === null || options === void 0 ? void 0 : options.signer).address;
964
- } catch (e) {
965
- if (e instanceof BeeError) {
966
- throw new BeeError('Either address, signer or default signer has to be specified!');
967
- } else {
968
- throw e;
969
- }
743
+ async getJsonFeed(topic, options) {
744
+ assertRequestOptions(options, 'JsonFeedOptions');
745
+ const hashedTopic = this.makeFeedTopic(topic);
746
+ const feedType = options?.type ?? DEFAULT_FEED_TYPE;
747
+ if (options?.signer && options?.address) {
748
+ throw new BeeError('Both options "signer" and "address" can not be specified at one time!');
749
+ }
750
+ let address;
751
+ if (options?.address) {
752
+ address = makeEthAddress(options?.address);
753
+ } else {
754
+ try {
755
+ address = this.resolveSigner(options?.signer).address;
756
+ } catch (e) {
757
+ if (e instanceof BeeError) {
758
+ throw new BeeError('Either address, signer or default signer has to be specified!');
759
+ } else {
760
+ throw e;
970
761
  }
971
762
  }
972
-
973
- const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
974
- return getJsonData(this, reader);
975
- });
763
+ }
764
+ const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
765
+ return getJsonData(this, reader);
976
766
  }
977
767
  /**
978
768
  * Make a new feed topic from a string
@@ -982,8 +772,6 @@ export class Bee {
982
772
  *
983
773
  * @param topic The input string
984
774
  */
985
-
986
-
987
775
  makeFeedTopic(topic) {
988
776
  return makeTopicFromString(topic);
989
777
  }
@@ -994,14 +782,12 @@ export class Bee {
994
782
  * @param options Options that affects the request behavior
995
783
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
996
784
  */
997
-
998
-
999
785
  makeSOCReader(ownerAddress, options) {
1000
786
  assertRequestOptions(options);
1001
787
  const canonicalOwner = makeEthAddress(ownerAddress);
1002
788
  return {
1003
789
  owner: makeHexEthAddress(canonicalOwner),
1004
- download: downloadSingleOwnerChunk.bind(null, this.getKy(options), canonicalOwner)
790
+ download: downloadSingleOwnerChunk.bind(null, this.getKyOptionsForCall(options), canonicalOwner)
1005
791
  };
1006
792
  }
1007
793
  /**
@@ -1011,14 +797,13 @@ export class Bee {
1011
797
  * @param options Options that affects the request behavior
1012
798
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/dapps-on-swarm/chunk-types#single-owner-chunks)
1013
799
  */
1014
-
1015
-
1016
800
  makeSOCWriter(signer, options) {
1017
801
  assertRequestOptions(options);
1018
802
  const canonicalSigner = this.resolveSigner(signer);
1019
- return Object.assign(Object.assign({}, this.makeSOCReader(canonicalSigner.address, options)), {
1020
- upload: uploadSingleOwnerChunkData.bind(null, this.getKy(options), canonicalSigner)
1021
- });
803
+ return {
804
+ ...this.makeSOCReader(canonicalSigner.address, options),
805
+ upload: uploadSingleOwnerChunkData.bind(null, this.getKyOptionsForCall(options), canonicalSigner)
806
+ };
1022
807
  }
1023
808
  /**
1024
809
  * Ping the Bee node to see if there is a live Bee node on the given URL.
@@ -1026,13 +811,9 @@ export class Bee {
1026
811
  * @param options Options that affects the request behavior
1027
812
  * @throws If connection was not successful throw error
1028
813
  */
1029
-
1030
-
1031
- checkConnection(options) {
1032
- return __awaiter(this, void 0, void 0, function* () {
1033
- assertRequestOptions(options, 'PostageBatchOptions');
1034
- return status.checkConnection(this.getKy(options));
1035
- });
814
+ async checkConnection(options) {
815
+ assertRequestOptions(options, 'PostageBatchOptions');
816
+ return status.checkConnection(this.getKyOptionsForCall(options));
1036
817
  }
1037
818
  /**
1038
819
  * Ping the Bee node to see if there is a live Bee node on the given URL.
@@ -1040,46 +821,30 @@ export class Bee {
1040
821
  * @param options Options that affects the request behavior
1041
822
  * @returns true if successful, false on error
1042
823
  */
1043
-
1044
-
1045
- isConnected(options) {
1046
- return __awaiter(this, void 0, void 0, function* () {
1047
- assertRequestOptions(options, 'PostageBatchOptions');
1048
-
1049
- try {
1050
- yield status.checkConnection(this.getKy(options));
1051
- } catch (e) {
1052
- return false;
1053
- }
1054
-
1055
- return true;
1056
- });
824
+ async isConnected(options) {
825
+ assertRequestOptions(options, 'PostageBatchOptions');
826
+ try {
827
+ await status.checkConnection(this.getKyOptionsForCall(options));
828
+ } catch (e) {
829
+ return false;
830
+ }
831
+ return true;
1057
832
  }
1058
833
  /**
1059
834
  * @param signer
1060
835
  * @private
1061
836
  * @throws BeeError if either no Signer was passed or no default Signer was specified for the instance
1062
837
  */
1063
-
1064
-
1065
838
  resolveSigner(signer) {
1066
839
  if (signer) {
1067
840
  return makeSigner(signer);
1068
841
  }
1069
-
1070
842
  if (this.signer) {
1071
843
  return this.signer;
1072
844
  }
1073
-
1074
845
  throw new BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
1075
846
  }
1076
-
1077
- getKy(options) {
1078
- if (!options) {
1079
- return this.ky;
1080
- }
1081
-
1082
- return this.ky.extend(options);
847
+ getKyOptionsForCall(options) {
848
+ return deepMerge(this.kyOptions, options);
1083
849
  }
1084
-
1085
850
  }