@ethersphere/bee-js 8.0.2 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee.js +50 -22
- package/dist/cjs/chunk/soc.js +4 -6
- package/dist/cjs/feed/json.js +1 -1
- package/dist/cjs/feed/retrievable.js +1 -1
- package/dist/cjs/modules/bytes.js +18 -1
- package/dist/cjs/modules/chunk.js +4 -4
- package/dist/cjs/modules/debug/status.js +3 -4
- package/dist/cjs/modules/envelope.js +23 -0
- package/dist/cjs/modules/feed.js +2 -2
- package/dist/cjs/modules/pinning.js +1 -1
- package/dist/cjs/modules/soc.js +2 -2
- package/dist/cjs/utils/error.js +4 -1
- package/dist/cjs/utils/expose.js +3 -1
- package/dist/cjs/utils/file.js +2 -2
- package/dist/cjs/utils/headers.js +11 -6
- package/dist/cjs/utils/http.js +1 -1
- package/dist/cjs/utils/stamps.js +22 -1
- package/dist/cjs/utils/type.js +1 -8
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +54 -22
- package/dist/mjs/chunk/soc.js +4 -6
- package/dist/mjs/feed/json.js +3 -1
- package/dist/mjs/feed/retrievable.js +1 -1
- package/dist/mjs/modules/bytes.js +16 -0
- package/dist/mjs/modules/chunk.js +4 -4
- package/dist/mjs/modules/debug/status.js +2 -3
- package/dist/mjs/modules/envelope.js +33 -0
- package/dist/mjs/modules/feed.js +2 -2
- package/dist/mjs/modules/pinning.js +1 -1
- package/dist/mjs/modules/soc.js +2 -2
- package/dist/mjs/utils/error.js +4 -1
- package/dist/mjs/utils/expose.js +3 -1
- package/dist/mjs/utils/file.js +2 -2
- package/dist/mjs/utils/headers.js +10 -6
- package/dist/mjs/utils/http.js +1 -1
- package/dist/mjs/utils/stamps.js +19 -0
- package/dist/mjs/utils/type.js +0 -6
- package/dist/types/bee.d.ts +14 -7
- package/dist/types/chunk/soc.d.ts +2 -2
- package/dist/types/modules/bytes.d.ts +8 -1
- package/dist/types/modules/chunk.d.ts +3 -3
- package/dist/types/modules/debug/status.d.ts +2 -3
- package/dist/types/modules/envelope.d.ts +2 -0
- package/dist/types/modules/feed.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/types/index.d.ts +10 -2
- package/dist/types/utils/error.d.ts +4 -1
- package/dist/types/utils/expose.d.ts +6 -3
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +3 -1
- package/dist/types/utils/type.d.ts +0 -1
- package/package.json +13 -16
package/dist/cjs/bee.js
CHANGED
|
@@ -46,6 +46,7 @@ const states = __importStar(require("./modules/debug/states"));
|
|
|
46
46
|
const debugStatus = __importStar(require("./modules/debug/status"));
|
|
47
47
|
const debugTag = __importStar(require("./modules/debug/tag"));
|
|
48
48
|
const transactions = __importStar(require("./modules/debug/transactions"));
|
|
49
|
+
const envelope_1 = require("./modules/envelope");
|
|
49
50
|
const feed_2 = require("./modules/feed");
|
|
50
51
|
const grantee = __importStar(require("./modules/grantee"));
|
|
51
52
|
const pinning = __importStar(require("./modules/pinning"));
|
|
@@ -104,10 +105,22 @@ class Bee {
|
|
|
104
105
|
async uploadData(postageBatchId, data, options, requestOptions) {
|
|
105
106
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
106
107
|
(0, type_2.assertData)(data);
|
|
107
|
-
|
|
108
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
109
|
+
if (options) {
|
|
108
110
|
(0, type_2.assertUploadOptions)(options);
|
|
111
|
+
}
|
|
109
112
|
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
110
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Requests content length for a `/bytes` reference
|
|
116
|
+
*
|
|
117
|
+
* @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
|
|
118
|
+
*/
|
|
119
|
+
async probeData(reference, options) {
|
|
120
|
+
(0, type_2.assertRequestOptions)(options);
|
|
121
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
122
|
+
return bytes.head(this.getRequestOptionsForCall(options), reference);
|
|
123
|
+
}
|
|
111
124
|
/**
|
|
112
125
|
* Download data as a byte array
|
|
113
126
|
*
|
|
@@ -149,8 +162,8 @@ class Bee {
|
|
|
149
162
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
150
163
|
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
151
164
|
*/
|
|
152
|
-
async uploadChunk(
|
|
153
|
-
(0, type_2.
|
|
165
|
+
async uploadChunk(stamp, data, options, requestOptions) {
|
|
166
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
154
167
|
if (!(data instanceof Uint8Array)) {
|
|
155
168
|
throw new TypeError('Data has to be Uint8Array instance!');
|
|
156
169
|
}
|
|
@@ -160,9 +173,10 @@ class Bee {
|
|
|
160
173
|
if (data.length > types_1.CHUNK_SIZE + types_1.SPAN_SIZE) {
|
|
161
174
|
throw new error_1.BeeArgumentError(`Chunk has to have size of at most ${types_1.CHUNK_SIZE}.`, data);
|
|
162
175
|
}
|
|
163
|
-
if (options)
|
|
176
|
+
if (options) {
|
|
164
177
|
(0, type_2.assertUploadOptions)(options);
|
|
165
|
-
|
|
178
|
+
}
|
|
179
|
+
return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
|
|
166
180
|
}
|
|
167
181
|
/**
|
|
168
182
|
* Download chunk as a byte array
|
|
@@ -190,6 +204,7 @@ class Bee {
|
|
|
190
204
|
* @returns A promise that resolves to a `GranteesResult` object.
|
|
191
205
|
*/
|
|
192
206
|
async createGrantees(postageBatchId, grantees, requestOptions) {
|
|
207
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
193
208
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
194
209
|
return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
|
|
195
210
|
}
|
|
@@ -201,6 +216,7 @@ class Bee {
|
|
|
201
216
|
* @returns A promise that resolves to a `GetGranteesResult` object.
|
|
202
217
|
*/
|
|
203
218
|
async getGrantees(reference, requestOptions) {
|
|
219
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
204
220
|
return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
|
|
205
221
|
}
|
|
206
222
|
/**
|
|
@@ -214,6 +230,7 @@ class Bee {
|
|
|
214
230
|
* @returns A Promise that resolves to to a `GranteesResult` object.
|
|
215
231
|
*/
|
|
216
232
|
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
|
|
233
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
217
234
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
218
235
|
return grantee.patchGrantees(postageBatchId, reference, history, { add: grantees.add || [], revoke: grantees.revoke || [] }, this.getRequestOptionsForCall(requestOptions));
|
|
219
236
|
}
|
|
@@ -234,10 +251,12 @@ class Bee {
|
|
|
234
251
|
* @returns reference is a content hash of the file
|
|
235
252
|
*/
|
|
236
253
|
async uploadFile(postageBatchId, data, name, options, requestOptions) {
|
|
254
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
237
255
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
238
256
|
(0, type_2.assertFileData)(data);
|
|
239
|
-
if (options)
|
|
257
|
+
if (options) {
|
|
240
258
|
(0, type_2.assertFileUploadOptions)(options);
|
|
259
|
+
}
|
|
241
260
|
if (name && typeof name !== 'string') {
|
|
242
261
|
throw new TypeError('name has to be string or undefined!');
|
|
243
262
|
}
|
|
@@ -309,9 +328,11 @@ class Bee {
|
|
|
309
328
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
310
329
|
*/
|
|
311
330
|
async uploadFiles(postageBatchId, fileList, options, requestOptions) {
|
|
331
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
312
332
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
313
|
-
if (options)
|
|
333
|
+
if (options) {
|
|
314
334
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
335
|
+
}
|
|
315
336
|
const data = await (0, collection_1.makeCollectionFromFileList)(fileList);
|
|
316
337
|
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
317
338
|
}
|
|
@@ -325,12 +346,13 @@ class Bee {
|
|
|
325
346
|
* @param collection
|
|
326
347
|
* @param options Collections and request options
|
|
327
348
|
*/
|
|
328
|
-
async uploadCollection(postageBatchId, collection, options) {
|
|
349
|
+
async uploadCollection(postageBatchId, collection, options, requestOptions) {
|
|
350
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
329
351
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
330
352
|
(0, collection_1.assertCollection)(collection);
|
|
331
353
|
if (options)
|
|
332
354
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
333
|
-
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.requestOptions, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
355
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getRequestOptionsForCall(this.requestOptions), collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
334
356
|
}
|
|
335
357
|
/**
|
|
336
358
|
* Upload collection of files.
|
|
@@ -350,6 +372,7 @@ class Bee {
|
|
|
350
372
|
*/
|
|
351
373
|
async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
|
|
352
374
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
375
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
353
376
|
if (options)
|
|
354
377
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
355
378
|
const data = await (0, collection_node_1.makeCollectionFromFS)(dir);
|
|
@@ -378,10 +401,10 @@ class Bee {
|
|
|
378
401
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
379
402
|
* @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
|
|
380
403
|
*/
|
|
381
|
-
async getAllTags(options) {
|
|
382
|
-
(0, type_2.assertRequestOptions)(
|
|
404
|
+
async getAllTags(options, requestOptions) {
|
|
405
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
383
406
|
(0, type_2.assertAllTagsOptions)(options);
|
|
384
|
-
return tag.getAllTags(this.getRequestOptionsForCall(
|
|
407
|
+
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
|
|
385
408
|
}
|
|
386
409
|
/**
|
|
387
410
|
* Retrieve tag information from Bee node
|
|
@@ -544,7 +567,7 @@ class Bee {
|
|
|
544
567
|
return true;
|
|
545
568
|
}
|
|
546
569
|
catch (e) {
|
|
547
|
-
if (e?.
|
|
570
|
+
if (e?.status === 404 || e?.status === 500) {
|
|
548
571
|
return false;
|
|
549
572
|
}
|
|
550
573
|
throw e;
|
|
@@ -714,13 +737,12 @@ class Bee {
|
|
|
714
737
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
715
738
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
716
739
|
*/
|
|
717
|
-
async createFeedManifest(
|
|
740
|
+
async createFeedManifest(stamp, type, topic, owner, options) {
|
|
718
741
|
(0, type_2.assertRequestOptions)(options);
|
|
719
742
|
(0, type_1.assertFeedType)(type);
|
|
720
|
-
(0, type_2.assertBatchId)(postageBatchId);
|
|
721
743
|
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
722
744
|
const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
|
|
723
|
-
const reference = await (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic,
|
|
745
|
+
const reference = await (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, stamp);
|
|
724
746
|
return (0, type_2.addCidConversionFunction)({ reference }, swarm_cid_1.ReferenceType.FEED);
|
|
725
747
|
}
|
|
726
748
|
/**
|
|
@@ -776,7 +798,7 @@ class Bee {
|
|
|
776
798
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
777
799
|
*/
|
|
778
800
|
async setJsonFeed(postageBatchId, topic, data, options, requestOptions) {
|
|
779
|
-
(0, type_2.assertRequestOptions)(
|
|
801
|
+
(0, type_2.assertRequestOptions)(requestOptions, 'JsonFeedOptions');
|
|
780
802
|
(0, type_2.assertBatchId)(postageBatchId);
|
|
781
803
|
const hashedTopic = this.makeFeedTopic(topic);
|
|
782
804
|
const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
|
|
@@ -802,8 +824,8 @@ class Bee {
|
|
|
802
824
|
*
|
|
803
825
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
804
826
|
*/
|
|
805
|
-
async getJsonFeed(topic, options) {
|
|
806
|
-
(0, type_2.assertRequestOptions)(
|
|
827
|
+
async getJsonFeed(topic, options, requestOptions) {
|
|
828
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
807
829
|
const hashedTopic = this.makeFeedTopic(topic);
|
|
808
830
|
const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
|
|
809
831
|
if (options?.signer && options?.address) {
|
|
@@ -826,7 +848,7 @@ class Bee {
|
|
|
826
848
|
}
|
|
827
849
|
}
|
|
828
850
|
}
|
|
829
|
-
const reader = this.makeFeedReader(feedType, hashedTopic, address,
|
|
851
|
+
const reader = this.makeFeedReader(feedType, hashedTopic, address, requestOptions);
|
|
830
852
|
return (0, json_1.getJsonData)(this, reader);
|
|
831
853
|
}
|
|
832
854
|
/**
|
|
@@ -870,6 +892,10 @@ class Bee {
|
|
|
870
892
|
upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner),
|
|
871
893
|
};
|
|
872
894
|
}
|
|
895
|
+
async createEnvelope(postageBatchId, reference, options) {
|
|
896
|
+
(0, type_2.assertRequestOptions)(options);
|
|
897
|
+
return (0, envelope_1.postEnvelope)(this.getRequestOptionsForCall(options), postageBatchId, reference);
|
|
898
|
+
}
|
|
873
899
|
/**
|
|
874
900
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
875
901
|
*
|
|
@@ -1044,6 +1070,7 @@ class Bee {
|
|
|
1044
1070
|
async cashoutLastCheque(address, options, requestOptions) {
|
|
1045
1071
|
(0, type_2.assertCashoutOptions)(options);
|
|
1046
1072
|
(0, type_2.assertAddress)(address);
|
|
1073
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
1047
1074
|
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
1048
1075
|
}
|
|
1049
1076
|
/**
|
|
@@ -1226,6 +1253,7 @@ class Bee {
|
|
|
1226
1253
|
(0, type_2.assertPostageBatchOptions)(options);
|
|
1227
1254
|
(0, type_2.assertPositiveInteger)(amount);
|
|
1228
1255
|
(0, type_2.assertNonNegativeInteger)(depth);
|
|
1256
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
1229
1257
|
if (depth < types_1.STAMPS_DEPTH_MIN) {
|
|
1230
1258
|
throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
|
|
1231
1259
|
}
|
|
@@ -1385,8 +1413,8 @@ class Bee {
|
|
|
1385
1413
|
* @param options
|
|
1386
1414
|
*/
|
|
1387
1415
|
async depositStake(amount, options, requestOptions) {
|
|
1388
|
-
(0, type_2.assertRequestOptions)(options);
|
|
1389
1416
|
(0, type_2.assertTransactionOptions)(options);
|
|
1417
|
+
(0, type_2.assertRequestOptions)(requestOptions);
|
|
1390
1418
|
await stake.stake(this.getRequestOptionsForCall(requestOptions), amount, options);
|
|
1391
1419
|
}
|
|
1392
1420
|
/**
|
|
@@ -1424,7 +1452,7 @@ class Bee {
|
|
|
1424
1452
|
if (this.signer) {
|
|
1425
1453
|
return this.signer;
|
|
1426
1454
|
}
|
|
1427
|
-
throw new
|
|
1455
|
+
throw new TypeError('You have to pass Signer as property to either the method call or constructor! Non found.');
|
|
1428
1456
|
}
|
|
1429
1457
|
getRequestOptionsForCall(options) {
|
|
1430
1458
|
return options ? cafe_utility_1.Objects.deepMerge2(this.requestOptions, options) : this.requestOptions;
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -31,7 +31,6 @@ const bytes_1 = require("../utils/bytes");
|
|
|
31
31
|
const error_1 = require("../utils/error");
|
|
32
32
|
const hash_1 = require("../utils/hash");
|
|
33
33
|
const hex_1 = require("../utils/hex");
|
|
34
|
-
const type_1 = require("../utils/type");
|
|
35
34
|
const bmt_1 = require("./bmt");
|
|
36
35
|
const cac_1 = require("./cac");
|
|
37
36
|
const signer_1 = require("./signer");
|
|
@@ -119,12 +118,12 @@ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
|
|
|
119
118
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
120
119
|
* @param options Upload options
|
|
121
120
|
*/
|
|
122
|
-
async function uploadSingleOwnerChunk(requestOptions, chunk,
|
|
121
|
+
async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
|
|
123
122
|
const owner = (0, hex_1.bytesToHex)(chunk.owner());
|
|
124
123
|
const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
|
|
125
124
|
const signature = (0, hex_1.bytesToHex)(chunk.signature());
|
|
126
125
|
const data = cafe_utility_1.Binary.concatBytes(chunk.span(), chunk.payload());
|
|
127
|
-
return socAPI.upload(requestOptions, owner, identifier, signature, data,
|
|
126
|
+
return socAPI.upload(requestOptions, owner, identifier, signature, data, stamp, options);
|
|
128
127
|
}
|
|
129
128
|
exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
|
|
130
129
|
/**
|
|
@@ -137,11 +136,10 @@ exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
|
|
|
137
136
|
* @param data The chunk data
|
|
138
137
|
* @param options
|
|
139
138
|
*/
|
|
140
|
-
async function uploadSingleOwnerChunkData(requestOptions, signer,
|
|
141
|
-
(0, type_1.assertAddress)(postageBatchId);
|
|
139
|
+
async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identifier, data, options) {
|
|
142
140
|
const cac = (0, cac_1.makeContentAddressedChunk)(data);
|
|
143
141
|
const soc = await makeSingleOwnerChunk(cac, identifier, signer);
|
|
144
|
-
return uploadSingleOwnerChunk(requestOptions, soc,
|
|
142
|
+
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
145
143
|
}
|
|
146
144
|
exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
|
147
145
|
/**
|
package/dist/cjs/feed/json.js
CHANGED
|
@@ -23,6 +23,6 @@ exports.getJsonData = getJsonData;
|
|
|
23
23
|
async function setJsonData(bee, writer, postageBatchId, data, options, requestOptions) {
|
|
24
24
|
const serializedData = serializeJson(data);
|
|
25
25
|
const { reference } = await bee.uploadData(postageBatchId, serializedData, options, requestOptions);
|
|
26
|
-
return writer.upload(postageBatchId, reference);
|
|
26
|
+
return writer.upload(postageBatchId, reference, { pin: options?.pin });
|
|
27
27
|
}
|
|
28
28
|
exports.setJsonData = setJsonData;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.downloadReadable = exports.download = exports.upload = void 0;
|
|
3
|
+
exports.downloadReadable = exports.download = exports.head = exports.upload = void 0;
|
|
4
4
|
const bytes_1 = require("../utils/bytes");
|
|
5
5
|
const headers_1 = require("../utils/headers");
|
|
6
6
|
const http_1 = require("../utils/http");
|
|
@@ -32,6 +32,23 @@ async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
exports.upload = upload;
|
|
35
|
+
/**
|
|
36
|
+
* Requests content length for a reference
|
|
37
|
+
*
|
|
38
|
+
* @param requestOptions Options for making requests
|
|
39
|
+
* @param hash Bee content reference
|
|
40
|
+
*/
|
|
41
|
+
async function head(requestOptions, hash) {
|
|
42
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
43
|
+
url: `${endpoint}/${hash}`,
|
|
44
|
+
method: 'head',
|
|
45
|
+
responseType: 'json',
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
contentLength: parseInt(response.headers['content-length']),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
exports.head = head;
|
|
35
52
|
/**
|
|
36
53
|
* Download data as a byte array
|
|
37
54
|
*
|
|
@@ -14,18 +14,18 @@ const endpoint = 'chunks';
|
|
|
14
14
|
* Upload expects the chuck data to be set accordingly.
|
|
15
15
|
*
|
|
16
16
|
* @param requestOptions Options for making requests
|
|
17
|
-
* @param data
|
|
18
|
-
* @param
|
|
17
|
+
* @param data Chunk data to be uploaded
|
|
18
|
+
* @param stamp BatchId or marshaled stamp to be used for the upload
|
|
19
19
|
* @param options Additional options like tag, encryption, pinning
|
|
20
20
|
*/
|
|
21
|
-
async function upload(requestOptions, data,
|
|
21
|
+
async function upload(requestOptions, data, stamp, options) {
|
|
22
22
|
const response = await (0, http_1.http)(requestOptions, {
|
|
23
23
|
method: 'post',
|
|
24
24
|
url: `${endpoint}`,
|
|
25
25
|
data,
|
|
26
26
|
headers: {
|
|
27
27
|
'content-type': 'application/octet-stream',
|
|
28
|
-
...(0, headers_1.extractUploadHeaders)(
|
|
28
|
+
...(0, headers_1.extractUploadHeaders)(stamp, options),
|
|
29
29
|
},
|
|
30
30
|
responseType: 'json',
|
|
31
31
|
});
|
|
@@ -3,14 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.getDebugStatus = exports.SUPPORTED_BEE_VERSION = exports.
|
|
6
|
+
exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.getDebugStatus = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
|
|
7
7
|
const major_js_1 = __importDefault(require("semver/functions/major.js"));
|
|
8
8
|
const http_1 = require("../../utils/http");
|
|
9
9
|
// Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
10
10
|
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
11
|
-
exports.SUPPORTED_BEE_VERSION_EXACT = '
|
|
12
|
-
exports.SUPPORTED_API_VERSION = '
|
|
13
|
-
exports.SUPPORTED_DEBUG_API_VERSION = '4.0.0';
|
|
11
|
+
exports.SUPPORTED_BEE_VERSION_EXACT = '2.2.0-06a0aca7';
|
|
12
|
+
exports.SUPPORTED_API_VERSION = '7.1.0';
|
|
14
13
|
exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
|
|
15
14
|
const NODE_INFO_URL = 'node';
|
|
16
15
|
const STATUS_URL = 'status';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postEnvelope = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const http_1 = require("../utils/http");
|
|
6
|
+
const ENVELOPE_ENDPOINT = 'envelope';
|
|
7
|
+
async function postEnvelope(requestOptions, postageBatchId, reference) {
|
|
8
|
+
const { data } = await (0, http_1.http)(requestOptions, {
|
|
9
|
+
method: 'post',
|
|
10
|
+
responseType: 'json',
|
|
11
|
+
url: `${ENVELOPE_ENDPOINT}/${reference}`,
|
|
12
|
+
headers: {
|
|
13
|
+
'swarm-postage-batch-id': postageBatchId,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
issuer: cafe_utility_1.Binary.hexToUint8Array(cafe_utility_1.Types.asHexString(data.issuer, { name: 'issuer', byteLength: 20 })),
|
|
18
|
+
index: cafe_utility_1.Binary.hexToUint8Array(cafe_utility_1.Types.asHexString(data.index, { name: 'index', byteLength: 8 })),
|
|
19
|
+
timestamp: cafe_utility_1.Binary.hexToUint8Array(cafe_utility_1.Types.asHexString(data.timestamp, { name: 'timestamp', byteLength: 8 })),
|
|
20
|
+
signature: cafe_utility_1.Binary.hexToUint8Array(cafe_utility_1.Types.asHexString(data.signature, { name: 'signature', byteLength: 65 })),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.postEnvelope = postEnvelope;
|
package/dist/cjs/modules/feed.js
CHANGED
|
@@ -14,12 +14,12 @@ const feedEndpoint = 'feeds';
|
|
|
14
14
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
15
15
|
* @param options Additional options, like type (default: 'sequence')
|
|
16
16
|
*/
|
|
17
|
-
async function createFeedManifest(requestOptions, owner, topic,
|
|
17
|
+
async function createFeedManifest(requestOptions, owner, topic, stamp) {
|
|
18
18
|
const response = await (0, http_1.http)(requestOptions, {
|
|
19
19
|
method: 'post',
|
|
20
20
|
responseType: 'json',
|
|
21
21
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
22
|
-
headers: (0, headers_1.extractUploadHeaders)(
|
|
22
|
+
headers: (0, headers_1.extractUploadHeaders)(stamp),
|
|
23
23
|
});
|
|
24
24
|
return response.data.reference;
|
|
25
25
|
}
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -16,14 +16,14 @@ const socEndpoint = 'soc';
|
|
|
16
16
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
17
17
|
* @param options Additional options like tag, encryption, pinning
|
|
18
18
|
*/
|
|
19
|
-
async function upload(requestOptions, owner, identifier, signature, data,
|
|
19
|
+
async function upload(requestOptions, owner, identifier, signature, data, stamp, options) {
|
|
20
20
|
const response = await (0, http_1.http)(requestOptions, {
|
|
21
21
|
method: 'post',
|
|
22
22
|
url: `${socEndpoint}/${owner}/${identifier}`,
|
|
23
23
|
data,
|
|
24
24
|
headers: {
|
|
25
25
|
'content-type': 'application/octet-stream',
|
|
26
|
-
...(0, headers_1.extractUploadHeaders)(
|
|
26
|
+
...(0, headers_1.extractUploadHeaders)(stamp, options),
|
|
27
27
|
},
|
|
28
28
|
responseType: 'json',
|
|
29
29
|
params: { sig: signature },
|
package/dist/cjs/utils/error.js
CHANGED
|
@@ -15,8 +15,11 @@ class BeeArgumentError extends BeeError {
|
|
|
15
15
|
}
|
|
16
16
|
exports.BeeArgumentError = BeeArgumentError;
|
|
17
17
|
class BeeResponseError extends BeeError {
|
|
18
|
-
constructor(message, status, statusText) {
|
|
18
|
+
constructor(method, url, message, responseBody, status, statusText) {
|
|
19
19
|
super(message);
|
|
20
|
+
this.method = method;
|
|
21
|
+
this.url = url;
|
|
22
|
+
this.responseBody = responseBody;
|
|
20
23
|
this.status = status;
|
|
21
24
|
this.statusText = statusText;
|
|
22
25
|
}
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.capitalizeAddressERC55 = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
3
|
+
exports.NULL_TOPIC = exports.NULL_STAMP = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.capitalizeAddressERC55 = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
6
|
var collection_node_1 = require("./collection.node");
|
|
@@ -47,3 +47,5 @@ var redundancy_1 = require("./redundancy");
|
|
|
47
47
|
Object.defineProperty(exports, "approximateOverheadForRedundancyLevel", { enumerable: true, get: function () { return redundancy_1.approximateOverheadForRedundancyLevel; } });
|
|
48
48
|
Object.defineProperty(exports, "getRedundancyStat", { enumerable: true, get: function () { return redundancy_1.getRedundancyStat; } });
|
|
49
49
|
Object.defineProperty(exports, "getRedundancyStats", { enumerable: true, get: function () { return redundancy_1.getRedundancyStats; } });
|
|
50
|
+
exports.NULL_STAMP = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
51
|
+
exports.NULL_TOPIC = '0000000000000000000000000000000000000000000000000000000000000000';
|
package/dist/cjs/utils/file.js
CHANGED
|
@@ -8,8 +8,8 @@ exports.fileArrayBuffer = exports.isFile = void 0;
|
|
|
8
8
|
*/
|
|
9
9
|
function isFile(file) {
|
|
10
10
|
// browser
|
|
11
|
-
if (typeof File === 'function') {
|
|
12
|
-
return
|
|
11
|
+
if (typeof File === 'function' && file instanceof File) {
|
|
12
|
+
return true;
|
|
13
13
|
}
|
|
14
14
|
// node.js
|
|
15
15
|
const f = file;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractDownloadHeaders = exports.extractRedundantUploadHeaders = exports.extractUploadHeaders = exports.readFileHeaders = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
4
5
|
const error_1 = require("./error");
|
|
5
6
|
/**
|
|
6
7
|
* Read the filename from the content-disposition header
|
|
@@ -39,13 +40,17 @@ function readFileHeaders(headers) {
|
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
exports.readFileHeaders = readFileHeaders;
|
|
42
|
-
function extractUploadHeaders(
|
|
43
|
-
if (!
|
|
44
|
-
throw new error_1.BeeError('
|
|
43
|
+
function extractUploadHeaders(stamp, options) {
|
|
44
|
+
if (!stamp) {
|
|
45
|
+
throw new error_1.BeeError('Stamp has to be specified!');
|
|
46
|
+
}
|
|
47
|
+
const headers = {};
|
|
48
|
+
if (stamp instanceof Uint8Array) {
|
|
49
|
+
headers['swarm-postage-stamp'] = cafe_utility_1.Binary.uint8ArrayToHex(stamp);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
headers['swarm-postage-batch-id'] = stamp;
|
|
45
53
|
}
|
|
46
|
-
const headers = {
|
|
47
|
-
'swarm-postage-batch-id': postageBatchId,
|
|
48
|
-
};
|
|
49
54
|
if (options?.act) {
|
|
50
55
|
headers['swarm-act'] = String(options.act);
|
|
51
56
|
}
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -35,7 +35,7 @@ async function http(options, config) {
|
|
|
35
35
|
}
|
|
36
36
|
catch (e) {
|
|
37
37
|
if (e instanceof AxiosError) {
|
|
38
|
-
throw new index_1.BeeResponseError(e.message, e.status, e.code);
|
|
38
|
+
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code);
|
|
39
39
|
}
|
|
40
40
|
throw e;
|
|
41
41
|
}
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
|
|
3
|
+
exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
4
5
|
/**
|
|
5
6
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
6
7
|
*
|
|
@@ -112,3 +113,23 @@ function getDepthForCapacity(gigabytes) {
|
|
|
112
113
|
return gigabytes <= 1 ? 18 : Math.ceil(Math.log2(Math.ceil(gigabytes)) + 18);
|
|
113
114
|
}
|
|
114
115
|
exports.getDepthForCapacity = getDepthForCapacity;
|
|
116
|
+
function convertEnvelopeToMarshaledStamp(batchID, envelope) {
|
|
117
|
+
return marshalStamp(envelope.signature, cafe_utility_1.Binary.hexToUint8Array(batchID), envelope.timestamp, envelope.index);
|
|
118
|
+
}
|
|
119
|
+
exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
|
|
120
|
+
function marshalStamp(signature, batchID, timestamp, index) {
|
|
121
|
+
if (signature.length !== 65) {
|
|
122
|
+
throw Error('invalid signature length');
|
|
123
|
+
}
|
|
124
|
+
if (batchID.length !== 32) {
|
|
125
|
+
throw Error('invalid batch ID length');
|
|
126
|
+
}
|
|
127
|
+
if (timestamp.length !== 8) {
|
|
128
|
+
throw Error('invalid timestamp length');
|
|
129
|
+
}
|
|
130
|
+
if (index.length !== 8) {
|
|
131
|
+
throw Error('invalid index length');
|
|
132
|
+
}
|
|
133
|
+
return cafe_utility_1.Binary.concatBytes(batchID, index, timestamp, signature);
|
|
134
|
+
}
|
|
135
|
+
exports.marshalStamp = marshalStamp;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.
|
|
3
|
+
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isReadable = void 0;
|
|
4
4
|
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
5
5
|
const stream_1 = require("stream");
|
|
6
6
|
const types_1 = require("../types");
|
|
@@ -11,10 +11,6 @@ function isReadable(obj) {
|
|
|
11
11
|
return typeof stream_1.Readable !== 'undefined' && obj instanceof stream_1.Readable;
|
|
12
12
|
}
|
|
13
13
|
exports.isReadable = isReadable;
|
|
14
|
-
function isUint8Array(obj) {
|
|
15
|
-
return obj instanceof Uint8Array;
|
|
16
|
-
}
|
|
17
|
-
exports.isUint8Array = isUint8Array;
|
|
18
14
|
function isInteger(value) {
|
|
19
15
|
return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
|
|
20
16
|
(typeof value === 'number' &&
|
|
@@ -182,9 +178,6 @@ function assertRequestOptions(value, name = 'RequestOptions') {
|
|
|
182
178
|
throw new TypeError(`${name} has to be an object!`);
|
|
183
179
|
}
|
|
184
180
|
const options = value;
|
|
185
|
-
if (options.retry) {
|
|
186
|
-
assertNonNegativeInteger(options.retry, `${name}.retry`);
|
|
187
|
-
}
|
|
188
181
|
if (options.timeout) {
|
|
189
182
|
assertNonNegativeInteger(options.timeout, `${name}.timeout`);
|
|
190
183
|
}
|