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