@ethersphere/bee-js 12.2.2 → 12.3.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 +56 -23
- package/dist/cjs/chunk/cac.js +4 -2
- package/dist/cjs/feed/index.js +3 -1
- package/dist/cjs/modules/bytes.js +6 -4
- package/dist/cjs/modules/bzz.js +5 -4
- package/dist/cjs/modules/chunk.js +3 -2
- package/dist/cjs/modules/debug/balance.js +5 -29
- package/dist/cjs/modules/debug/chequebook.js +9 -58
- package/dist/cjs/modules/debug/connectivity.js +5 -82
- package/dist/cjs/modules/debug/settlements.js +3 -22
- package/dist/cjs/modules/debug/stake.js +8 -33
- package/dist/cjs/modules/debug/stamps.js +27 -53
- package/dist/cjs/modules/debug/states.js +6 -31
- package/dist/cjs/modules/debug/status.js +5 -37
- package/dist/cjs/modules/debug/transactions.js +5 -26
- package/dist/cjs/modules/envelope.js +6 -6
- package/dist/cjs/modules/feed.js +3 -4
- package/dist/cjs/modules/grantee.js +8 -10
- package/dist/cjs/modules/pinning.js +5 -11
- package/dist/cjs/modules/rchash.js +2 -3
- package/dist/cjs/modules/soc.js +3 -2
- package/dist/cjs/modules/status.js +3 -3
- package/dist/cjs/modules/stewardship.js +2 -3
- package/dist/cjs/modules/tag.js +4 -35
- package/dist/cjs/stamper/stamper.js +2 -1
- package/dist/cjs/types/schema/balance.js +14 -0
- package/dist/cjs/types/schema/chequebook.js +49 -0
- package/dist/cjs/types/schema/connectivity.js +46 -0
- package/dist/cjs/types/schema/envelope.js +11 -0
- package/dist/cjs/types/schema/grantee.js +10 -0
- package/dist/cjs/types/schema/pinning.js +7 -0
- package/dist/cjs/types/schema/rchash.js +7 -0
- package/dist/cjs/types/schema/settlements.js +17 -0
- package/dist/cjs/types/schema/stake.js +33 -0
- package/dist/cjs/types/schema/stamps.js +48 -0
- package/dist/cjs/types/schema/states.js +34 -0
- package/dist/cjs/types/schema/status.js +39 -0
- package/dist/cjs/types/schema/stewardship.js +7 -0
- package/dist/cjs/types/schema/tag.js +20 -0
- package/dist/cjs/types/schema/transactions.js +24 -0
- package/dist/cjs/types/schema/upload.js +8 -0
- package/dist/cjs/utils/bad-ports.js +92 -0
- package/dist/cjs/utils/bytes.js +5 -3
- package/dist/cjs/utils/error.js +1 -0
- package/dist/cjs/utils/headers.js +19 -13
- package/dist/cjs/utils/hex-schema.js +8 -0
- package/dist/cjs/utils/http.js +92 -52
- package/dist/cjs/utils/resource-locator.js +4 -3
- package/dist/cjs/utils/schema.js +88 -0
- package/dist/cjs/utils/stamps.js +2 -1
- package/dist/cjs/utils/type.js +12 -130
- package/dist/cjs/utils/url.js +24 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +59 -30
- package/dist/mjs/chunk/cac.js +5 -3
- package/dist/mjs/feed/index.js +4 -2
- package/dist/mjs/modules/bytes.js +8 -8
- package/dist/mjs/modules/bzz.js +6 -9
- package/dist/mjs/modules/chunk.js +4 -7
- package/dist/mjs/modules/debug/balance.js +5 -61
- package/dist/mjs/modules/debug/chequebook.js +9 -114
- package/dist/mjs/modules/debug/connectivity.js +5 -145
- package/dist/mjs/modules/debug/settlements.js +3 -46
- package/dist/mjs/modules/debug/stake.js +8 -85
- package/dist/mjs/modules/debug/stamps.js +24 -126
- package/dist/mjs/modules/debug/states.js +6 -71
- package/dist/mjs/modules/debug/status.js +5 -91
- package/dist/mjs/modules/debug/transactions.js +5 -60
- package/dist/mjs/modules/envelope.js +6 -20
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/grantee.js +8 -26
- package/dist/mjs/modules/pinning.js +7 -21
- package/dist/mjs/modules/rchash.js +2 -7
- package/dist/mjs/modules/soc.js +4 -5
- package/dist/mjs/modules/status.js +4 -4
- package/dist/mjs/modules/stewardship.js +2 -7
- package/dist/mjs/modules/tag.js +4 -93
- package/dist/mjs/stamper/stamper.js +2 -1
- package/dist/mjs/types/schema/balance.js +13 -0
- package/dist/mjs/types/schema/chequebook.js +53 -0
- package/dist/mjs/types/schema/connectivity.js +41 -0
- package/dist/mjs/types/schema/envelope.js +8 -0
- package/dist/mjs/types/schema/grantee.js +7 -0
- package/dist/mjs/types/schema/pinning.js +4 -0
- package/dist/mjs/types/schema/rchash.js +4 -0
- package/dist/mjs/types/schema/settlements.js +22 -0
- package/dist/mjs/types/schema/stake.js +40 -0
- package/dist/mjs/types/schema/stamps.js +47 -0
- package/dist/mjs/types/schema/states.js +34 -0
- package/dist/mjs/types/schema/status.js +36 -0
- package/dist/mjs/types/schema/stewardship.js +4 -0
- package/dist/mjs/types/schema/tag.js +14 -0
- package/dist/mjs/types/schema/transactions.js +25 -0
- package/dist/mjs/types/schema/upload.js +5 -0
- package/dist/mjs/utils/bad-ports.js +6 -0
- package/dist/mjs/utils/bytes.js +6 -8
- package/dist/mjs/utils/error.js +5 -0
- package/dist/mjs/utils/headers.js +19 -13
- package/dist/mjs/utils/hex-schema.js +2 -0
- package/dist/mjs/utils/http.js +97 -59
- package/dist/mjs/utils/resource-locator.js +4 -3
- package/dist/mjs/utils/schema.js +81 -0
- package/dist/mjs/utils/stamps.js +2 -1
- package/dist/mjs/utils/type.js +13 -233
- package/dist/mjs/utils/url.js +23 -0
- package/dist/types/bee.d.ts +23 -0
- package/dist/types/modules/debug/connectivity.d.ts +2 -2
- package/dist/types/modules/debug/stamps.d.ts +2 -0
- package/dist/types/types/debug.d.ts +1 -0
- package/dist/types/types/schema/balance.d.ts +12 -0
- package/dist/types/types/schema/chequebook.d.ts +104 -0
- package/dist/types/types/schema/connectivity.d.ts +49 -0
- package/dist/types/types/schema/envelope.d.ts +7 -0
- package/dist/types/types/schema/grantee.d.ts +7 -0
- package/dist/types/types/schema/pinning.d.ts +4 -0
- package/dist/types/types/schema/rchash.d.ts +4 -0
- package/dist/types/types/schema/settlements.d.ts +16 -0
- package/dist/types/types/schema/stake.d.ts +29 -0
- package/dist/types/types/schema/stamps.d.ts +77 -0
- package/dist/types/types/schema/states.d.ts +26 -0
- package/dist/types/types/schema/status.d.ts +38 -0
- package/dist/types/types/schema/stewardship.d.ts +4 -0
- package/dist/types/types/schema/tag.d.ts +23 -0
- package/dist/types/types/schema/transactions.d.ts +29 -0
- package/dist/types/types/schema/upload.d.ts +5 -0
- package/dist/types/utils/bad-ports.d.ts +6 -0
- package/dist/types/utils/error.d.ts +5 -0
- package/dist/types/utils/hex-schema.d.ts +2 -0
- package/dist/types/utils/http.d.ts +18 -3
- package/dist/types/utils/schema.d.ts +90 -0
- package/dist/types/utils/stamps.d.ts +1 -0
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -16
- package/dist/types/utils/url.d.ts +9 -0
- package/package.json +9 -9
package/dist/mjs/bee.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Binary, Objects, System
|
|
1
|
+
import { Binary, Objects, System } from 'cafe-utility';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { makeContentAddressedChunk, unmarshalContentAddressedChunk } from "./chunk/cac.js";
|
|
3
4
|
import { downloadSingleOwnerChunk, makeSOCAddress, makeSingleOwnerChunk, unmarshalSingleOwnerChunk, uploadSingleOwnerChunkData } from "./chunk/soc.js";
|
|
4
5
|
import { makeFeedReader, makeFeedWriter } from "./feed/index.js";
|
|
@@ -34,9 +35,10 @@ import { prepareWebsocketData } from "./utils/data.js";
|
|
|
34
35
|
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
35
36
|
import { fileArrayBuffer, isFile } from "./utils/file.js";
|
|
36
37
|
import { ResourceLocator } from "./utils/resource-locator.js";
|
|
38
|
+
import { AllTagsOptionsSchema, BeeRequestOptionsSchema, CollectionUploadOptionsSchema, DownloadOptionsSchema, FileUploadOptionsSchema, GsocMessageHandlerSchema, PostageBatchOptionsSchema, PssMessageHandlerSchema, RedundantUploadOptionsSchema, TransactionOptionsSchema, UploadOptionsSchema } from "./utils/schema.js";
|
|
37
39
|
import { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration } from "./utils/stamps.js";
|
|
38
40
|
import { BZZ, DAI } from "./utils/tokens.js";
|
|
39
|
-
import { asNumberString, assertData, assertFileData, makeTagUid
|
|
41
|
+
import { asNumberString, assertData, assertFileData, makeTagUid } from "./utils/type.js";
|
|
40
42
|
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Signature, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
41
43
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
42
44
|
/**
|
|
@@ -90,7 +92,7 @@ export class Bee {
|
|
|
90
92
|
postageBatchId = new BatchId(postageBatchId);
|
|
91
93
|
assertData(data);
|
|
92
94
|
if (options) {
|
|
93
|
-
options =
|
|
95
|
+
options = RedundantUploadOptionsSchema.parse(options);
|
|
94
96
|
}
|
|
95
97
|
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
96
98
|
}
|
|
@@ -126,7 +128,7 @@ export class Bee {
|
|
|
126
128
|
*/
|
|
127
129
|
async downloadData(resource, options, requestOptions) {
|
|
128
130
|
if (options) {
|
|
129
|
-
options =
|
|
131
|
+
options = DownloadOptionsSchema.parse(options);
|
|
130
132
|
}
|
|
131
133
|
return bytes.download(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
132
134
|
}
|
|
@@ -148,7 +150,7 @@ export class Bee {
|
|
|
148
150
|
*/
|
|
149
151
|
async downloadReadableData(resource, options, requestOptions) {
|
|
150
152
|
if (options) {
|
|
151
|
-
options =
|
|
153
|
+
options = DownloadOptionsSchema.parse(options);
|
|
152
154
|
}
|
|
153
155
|
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
154
156
|
}
|
|
@@ -170,7 +172,7 @@ export class Bee {
|
|
|
170
172
|
const isSOC = 'identifier' in data && 'signature' in data && 'owner' in data;
|
|
171
173
|
data = data instanceof Uint8Array ? data : data.data;
|
|
172
174
|
if (options) {
|
|
173
|
-
options =
|
|
175
|
+
options = UploadOptionsSchema.parse(options);
|
|
174
176
|
}
|
|
175
177
|
if (data.length < Span.LENGTH) {
|
|
176
178
|
throw new BeeArgumentError(`Chunk has to have size of at least ${Span.LENGTH}.`, data);
|
|
@@ -201,7 +203,7 @@ export class Bee {
|
|
|
201
203
|
async downloadChunk(reference, options, requestOptions) {
|
|
202
204
|
reference = new Reference(reference);
|
|
203
205
|
if (options) {
|
|
204
|
-
options =
|
|
206
|
+
options = DownloadOptionsSchema.parse(options);
|
|
205
207
|
}
|
|
206
208
|
return chunk.download(this.getRequestOptionsForCall(requestOptions), reference, options);
|
|
207
209
|
}
|
|
@@ -274,7 +276,7 @@ export class Bee {
|
|
|
274
276
|
postageBatchId = new BatchId(postageBatchId);
|
|
275
277
|
assertFileData(data);
|
|
276
278
|
if (options) {
|
|
277
|
-
options =
|
|
279
|
+
options = FileUploadOptionsSchema.parse(options);
|
|
278
280
|
}
|
|
279
281
|
if (name && typeof name !== 'string') {
|
|
280
282
|
throw new TypeError('name has to be string or undefined!');
|
|
@@ -284,8 +286,8 @@ export class Bee {
|
|
|
284
286
|
const fileName = name ?? data.name;
|
|
285
287
|
const contentType = data.type;
|
|
286
288
|
const fileOptions = {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
...options,
|
|
290
|
+
contentType
|
|
289
291
|
};
|
|
290
292
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
291
293
|
} else {
|
|
@@ -305,7 +307,7 @@ export class Bee {
|
|
|
305
307
|
*/
|
|
306
308
|
async downloadFile(resource, path = '', options, requestOptions) {
|
|
307
309
|
if (options) {
|
|
308
|
-
options =
|
|
310
|
+
options = DownloadOptionsSchema.parse(options);
|
|
309
311
|
}
|
|
310
312
|
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), path, options);
|
|
311
313
|
}
|
|
@@ -323,7 +325,7 @@ export class Bee {
|
|
|
323
325
|
async downloadReadableFile(reference, path = '', options, requestOptions) {
|
|
324
326
|
reference = new Reference(reference);
|
|
325
327
|
if (options) {
|
|
326
|
-
options =
|
|
328
|
+
options = DownloadOptionsSchema.parse(options);
|
|
327
329
|
}
|
|
328
330
|
return bzz.downloadFileReadable(this.getRequestOptionsForCall(requestOptions), reference, path, options);
|
|
329
331
|
}
|
|
@@ -347,7 +349,7 @@ export class Bee {
|
|
|
347
349
|
async uploadFiles(postageBatchId, fileList, options, requestOptions) {
|
|
348
350
|
postageBatchId = new BatchId(postageBatchId);
|
|
349
351
|
if (options) {
|
|
350
|
-
options =
|
|
352
|
+
options = CollectionUploadOptionsSchema.parse(options);
|
|
351
353
|
}
|
|
352
354
|
const data = makeCollectionFromFileList(fileList);
|
|
353
355
|
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
@@ -421,7 +423,7 @@ export class Bee {
|
|
|
421
423
|
postageBatchId = new BatchId(postageBatchId);
|
|
422
424
|
assertCollection(collection);
|
|
423
425
|
if (options) {
|
|
424
|
-
options =
|
|
426
|
+
options = CollectionUploadOptionsSchema.parse(options);
|
|
425
427
|
}
|
|
426
428
|
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), collection, postageBatchId, options);
|
|
427
429
|
}
|
|
@@ -444,7 +446,7 @@ export class Bee {
|
|
|
444
446
|
async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
|
|
445
447
|
postageBatchId = new BatchId(postageBatchId);
|
|
446
448
|
if (options) {
|
|
447
|
-
options =
|
|
449
|
+
options = CollectionUploadOptionsSchema.parse(options);
|
|
448
450
|
}
|
|
449
451
|
const data = await makeCollectionFromFS(dir);
|
|
450
452
|
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
@@ -473,7 +475,7 @@ export class Bee {
|
|
|
473
475
|
*/
|
|
474
476
|
async getAllTags(options, requestOptions) {
|
|
475
477
|
if (options) {
|
|
476
|
-
options =
|
|
478
|
+
options = AllTagsOptionsSchema.parse(options);
|
|
477
479
|
}
|
|
478
480
|
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
|
|
479
481
|
}
|
|
@@ -614,7 +616,7 @@ export class Bee {
|
|
|
614
616
|
owner = new EthAddress(owner);
|
|
615
617
|
topic = new Topic(topic);
|
|
616
618
|
if (options) {
|
|
617
|
-
options =
|
|
619
|
+
options = DownloadOptionsSchema.parse(options);
|
|
618
620
|
}
|
|
619
621
|
if (!index) {
|
|
620
622
|
try {
|
|
@@ -674,7 +676,7 @@ export class Bee {
|
|
|
674
676
|
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
675
677
|
*/
|
|
676
678
|
pssSubscribe(topic, handler) {
|
|
677
|
-
handler =
|
|
679
|
+
handler = PssMessageHandlerSchema.parse(handler);
|
|
678
680
|
const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
|
|
679
681
|
let cancelled = false;
|
|
680
682
|
const cancel = () => {
|
|
@@ -851,7 +853,7 @@ export class Bee {
|
|
|
851
853
|
gsocSubscribe(address, identifier, handler) {
|
|
852
854
|
address = new EthAddress(address);
|
|
853
855
|
identifier = new Identifier(identifier);
|
|
854
|
-
handler =
|
|
856
|
+
handler = GsocMessageHandlerSchema.parse(handler);
|
|
855
857
|
const socAddress = makeSOCAddress(identifier, address);
|
|
856
858
|
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
857
859
|
let cancelled = false;
|
|
@@ -904,7 +906,7 @@ export class Bee {
|
|
|
904
906
|
topic = new Topic(topic);
|
|
905
907
|
owner = new EthAddress(owner);
|
|
906
908
|
if (options) {
|
|
907
|
-
options =
|
|
909
|
+
options = UploadOptionsSchema.parse(options);
|
|
908
910
|
}
|
|
909
911
|
return createFeedManifest(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
|
|
910
912
|
}
|
|
@@ -1273,7 +1275,7 @@ export class Bee {
|
|
|
1273
1275
|
async cashoutLastCheque(address, options, requestOptions) {
|
|
1274
1276
|
address = new PeerAddress(address);
|
|
1275
1277
|
if (options) {
|
|
1276
|
-
|
|
1278
|
+
options = TransactionOptionsSchema.parse(options);
|
|
1277
1279
|
}
|
|
1278
1280
|
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
1279
1281
|
}
|
|
@@ -1502,7 +1504,7 @@ export class Bee {
|
|
|
1502
1504
|
name: 'amount'
|
|
1503
1505
|
});
|
|
1504
1506
|
if (options) {
|
|
1505
|
-
options =
|
|
1507
|
+
options = PostageBatchOptionsSchema.parse(options);
|
|
1506
1508
|
}
|
|
1507
1509
|
if (depth < STAMPS_DEPTH_MIN || depth > STAMPS_DEPTH_MAX) {
|
|
1508
1510
|
throw new BeeArgumentError(`Depth has to be between ${STAMPS_DEPTH_MIN}..${STAMPS_DEPTH_MAX}`, depth);
|
|
@@ -1540,7 +1542,7 @@ export class Bee {
|
|
|
1540
1542
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1541
1543
|
const depth = getDepthForSize(size, encryption, erasureCodeLevel);
|
|
1542
1544
|
if (options) {
|
|
1543
|
-
options =
|
|
1545
|
+
options = PostageBatchOptionsSchema.parse(options);
|
|
1544
1546
|
}
|
|
1545
1547
|
return this.createPostageBatch(amount, depth, options, requestOptions);
|
|
1546
1548
|
}
|
|
@@ -1736,6 +1738,27 @@ export class Bee {
|
|
|
1736
1738
|
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1737
1739
|
return getStampCost(batch.depth, amount);
|
|
1738
1740
|
}
|
|
1741
|
+
/**
|
|
1742
|
+
* Updates the label of a certain postage batch.
|
|
1743
|
+
*
|
|
1744
|
+
* @param postageBatchId Batch ID of the postage batch to update.
|
|
1745
|
+
* @param label New label for the postage batch.
|
|
1746
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1747
|
+
*/
|
|
1748
|
+
async updatePostageBatchLabel(postageBatchId, label, requestOptions) {
|
|
1749
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1750
|
+
return stamps.updatePostageBatchLabel(this.getRequestOptionsForCall(requestOptions), postageBatchId, label);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Renames a storage. This is a convenience method that calls {@link updatePostageBatchLabel}.
|
|
1754
|
+
*
|
|
1755
|
+
* @param postageBatchId Batch ID of the postage batch to update.
|
|
1756
|
+
* @param newName New name for the storage.
|
|
1757
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1758
|
+
*/
|
|
1759
|
+
async renameStorage(postageBatchId, newLabel, requestOptions) {
|
|
1760
|
+
return this.updatePostageBatchLabel(postageBatchId, newLabel, requestOptions);
|
|
1761
|
+
}
|
|
1739
1762
|
/**
|
|
1740
1763
|
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1741
1764
|
*
|
|
@@ -1812,11 +1835,7 @@ export class Bee {
|
|
|
1812
1835
|
*/
|
|
1813
1836
|
async diluteBatch(postageBatchId, depth, requestOptions) {
|
|
1814
1837
|
postageBatchId = new BatchId(postageBatchId);
|
|
1815
|
-
depth =
|
|
1816
|
-
name: 'depth',
|
|
1817
|
-
min: 18,
|
|
1818
|
-
max: 255
|
|
1819
|
-
});
|
|
1838
|
+
depth = z.number().int().min(18).max(255).parse(depth);
|
|
1820
1839
|
return stamps.diluteBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, depth);
|
|
1821
1840
|
}
|
|
1822
1841
|
/**
|
|
@@ -1834,6 +1853,16 @@ export class Bee {
|
|
|
1834
1853
|
postageBatchId = new BatchId(postageBatchId);
|
|
1835
1854
|
return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, encryption, erasureCodeLevel);
|
|
1836
1855
|
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Returns details for specific globally available postage batch.
|
|
1858
|
+
*
|
|
1859
|
+
* @param postageBatchId Batch ID
|
|
1860
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1861
|
+
*/
|
|
1862
|
+
async getGlobalPostageBatch(postageBatchId, requestOptions) {
|
|
1863
|
+
postageBatchId = new BatchId(postageBatchId);
|
|
1864
|
+
return stamps.getGlobalPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId);
|
|
1865
|
+
}
|
|
1837
1866
|
/**
|
|
1838
1867
|
* Return detailed information related to buckets for specific postage batch.
|
|
1839
1868
|
*
|
|
@@ -1987,7 +2016,7 @@ export class Bee {
|
|
|
1987
2016
|
name: 'amount'
|
|
1988
2017
|
});
|
|
1989
2018
|
if (options) {
|
|
1990
|
-
options =
|
|
2019
|
+
options = TransactionOptionsSchema.parse(options);
|
|
1991
2020
|
}
|
|
1992
2021
|
return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
|
|
1993
2022
|
}
|
|
@@ -2018,7 +2047,7 @@ export class Bee {
|
|
|
2018
2047
|
}
|
|
2019
2048
|
getRequestOptionsForCall(requestOptions) {
|
|
2020
2049
|
if (requestOptions) {
|
|
2021
|
-
requestOptions =
|
|
2050
|
+
requestOptions = BeeRequestOptionsSchema.parse(requestOptions);
|
|
2022
2051
|
}
|
|
2023
2052
|
return requestOptions ? Objects.deepMerge2(this.requestOptions, requestOptions) : this.requestOptions;
|
|
2024
2053
|
}
|
package/dist/mjs/chunk/cac.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Binary
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { Bytes } from "../utils/bytes.js";
|
|
3
4
|
import { Span } from "../utils/typed-bytes.js";
|
|
4
5
|
import { calculateChunkAddress } from "./bmt.js";
|
|
@@ -10,8 +11,9 @@ export function unmarshalContentAddressedChunk(data) {
|
|
|
10
11
|
return makeContentAddressedChunk(data.toUint8Array().slice(Span.LENGTH), Span.fromSlice(data.toUint8Array(), 0));
|
|
11
12
|
}
|
|
12
13
|
export function makeContentAddressedChunk(rawPayload, span) {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const asString = z.string().safeParse(rawPayload);
|
|
15
|
+
if (asString.success) {
|
|
16
|
+
rawPayload = Bytes.fromUtf8(asString.data);
|
|
15
17
|
}
|
|
16
18
|
if (rawPayload.length < MIN_PAYLOAD_SIZE || rawPayload.length > MAX_PAYLOAD_SIZE) {
|
|
17
19
|
throw new RangeError(`payload size ${rawPayload.length} exceeds limits [${MIN_PAYLOAD_SIZE}, ${MAX_PAYLOAD_SIZE}]`);
|
package/dist/mjs/feed/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Binary, Optional
|
|
1
|
+
import { Binary, Optional } from 'cafe-utility';
|
|
2
|
+
import { z } from 'zod';
|
|
2
3
|
import { makeContentAddressedChunk, unmarshalContentAddressedChunk } from "../chunk/cac.js";
|
|
3
4
|
import { unmarshalSingleOwnerChunk, uploadSingleOwnerChunkData, uploadSingleOwnerChunkWithWrappedChunk } from "../chunk/soc.js";
|
|
4
5
|
import * as bytes from "../modules/bytes.js";
|
|
@@ -43,7 +44,8 @@ export async function updateFeedWithPayload(requestOptions, signer, topic, data,
|
|
|
43
44
|
const rootChunk = unmarshalContentAddressedChunk(await chunkAPI.download(requestOptions, uploadResult.reference));
|
|
44
45
|
return uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, postageBatchId, identifier, rootChunk, options);
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
const dataString = z.string().safeParse(data);
|
|
48
|
+
return uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, dataString.success ? Bytes.fromUtf8(dataString.data).toUint8Array() : data, options);
|
|
47
49
|
}
|
|
48
50
|
export function getFeedUpdateChunkReference(owner, topic, index) {
|
|
49
51
|
const identifier = makeFeedIdentifier(topic, index);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Optional
|
|
1
|
+
import { Optional } from 'cafe-utility';
|
|
2
|
+
import { UploadResultBody } from "../types/schema/upload.js";
|
|
2
3
|
import { Bytes } from "../utils/bytes.js";
|
|
3
4
|
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
4
5
|
import { http } from "../utils/http.js";
|
|
5
|
-
import {
|
|
6
|
+
import { DownloadOptionsSchema } from "../utils/schema.js";
|
|
7
|
+
import { makeTagUid } from "../utils/type.js";
|
|
6
8
|
import { Reference } from "../utils/typed-bytes.js";
|
|
7
9
|
const endpoint = 'bytes';
|
|
8
10
|
/**
|
|
@@ -24,11 +26,9 @@ export async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
24
26
|
...prepareRequestHeaders(postageBatchId, options)
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
|
-
const body =
|
|
28
|
-
name: 'response.data'
|
|
29
|
-
});
|
|
29
|
+
const body = UploadResultBody.parse(response.data);
|
|
30
30
|
return {
|
|
31
|
-
reference:
|
|
31
|
+
reference: body.reference,
|
|
32
32
|
tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined,
|
|
33
33
|
historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty()
|
|
34
34
|
};
|
|
@@ -58,7 +58,7 @@ export async function head(requestOptions, reference) {
|
|
|
58
58
|
*/
|
|
59
59
|
export async function download(requestOptions, resource, options) {
|
|
60
60
|
if (options) {
|
|
61
|
-
options =
|
|
61
|
+
options = DownloadOptionsSchema.parse(options);
|
|
62
62
|
}
|
|
63
63
|
const response = await http(requestOptions, {
|
|
64
64
|
responseType: 'arraybuffer',
|
|
@@ -75,7 +75,7 @@ export async function download(requestOptions, resource, options) {
|
|
|
75
75
|
*/
|
|
76
76
|
export async function downloadReadable(requestOptions, resource, options) {
|
|
77
77
|
if (options) {
|
|
78
|
-
options =
|
|
78
|
+
options = DownloadOptionsSchema.parse(options);
|
|
79
79
|
}
|
|
80
80
|
const response = await http(requestOptions, {
|
|
81
81
|
responseType: 'stream',
|
package/dist/mjs/modules/bzz.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Optional
|
|
1
|
+
import { Optional } from 'cafe-utility';
|
|
2
|
+
import { UploadResultBody } from "../types/schema/upload.js";
|
|
2
3
|
import { Bytes } from "../utils/bytes.js";
|
|
3
4
|
import { assertCollection } from "../utils/collection.js";
|
|
4
5
|
import { prepareRequestHeaders, readFileHeaders } from "../utils/headers.js";
|
|
@@ -33,11 +34,9 @@ export async function uploadFile(requestOptions, data, postageBatchId, name, opt
|
|
|
33
34
|
},
|
|
34
35
|
responseType: 'json'
|
|
35
36
|
});
|
|
36
|
-
const body =
|
|
37
|
-
name: 'response.data'
|
|
38
|
-
});
|
|
37
|
+
const body = UploadResultBody.parse(response.data);
|
|
39
38
|
return {
|
|
40
|
-
reference:
|
|
39
|
+
reference: body.reference,
|
|
41
40
|
tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined,
|
|
42
41
|
historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty()
|
|
43
42
|
};
|
|
@@ -95,11 +94,9 @@ export async function downloadFileReadable(requestOptions, reference, path = '',
|
|
|
95
94
|
export async function uploadCollection(requestOptions, collection, postageBatchId, options) {
|
|
96
95
|
assertCollection(collection);
|
|
97
96
|
const response = await uploadTar(requestOptions, collection, postageBatchId, options);
|
|
98
|
-
const body =
|
|
99
|
-
name: 'response.data'
|
|
100
|
-
});
|
|
97
|
+
const body = UploadResultBody.parse(response.data);
|
|
101
98
|
return {
|
|
102
|
-
reference:
|
|
99
|
+
reference: body.reference,
|
|
103
100
|
tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined,
|
|
104
101
|
historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty()
|
|
105
102
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Optional
|
|
1
|
+
import { Optional } from 'cafe-utility';
|
|
2
|
+
import { UploadResultBody } from "../types/schema/upload.js";
|
|
2
3
|
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
3
4
|
import { http } from "../utils/http.js";
|
|
4
5
|
import { makeTagUid } from "../utils/type.js";
|
|
@@ -27,13 +28,9 @@ export async function upload(requestOptions, data, stamp, options) {
|
|
|
27
28
|
},
|
|
28
29
|
responseType: 'json'
|
|
29
30
|
});
|
|
30
|
-
const body =
|
|
31
|
-
name: 'response.data'
|
|
32
|
-
});
|
|
31
|
+
const body = UploadResultBody.parse(response.data);
|
|
33
32
|
return {
|
|
34
|
-
reference:
|
|
35
|
-
name: 'reference'
|
|
36
|
-
})),
|
|
33
|
+
reference: body.reference,
|
|
37
34
|
tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined,
|
|
38
35
|
historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty()
|
|
39
36
|
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetAllBalancesResponse, GetPeerBalanceResponse } from "../../types/schema/balance.js";
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
-
import { BZZ } from "../../utils/tokens.js";
|
|
4
|
-
import { asNumberString } from "../../utils/type.js";
|
|
5
3
|
const balancesEndpoint = 'balances';
|
|
6
4
|
const consumedEndpoint = 'consumed';
|
|
7
5
|
/**
|
|
@@ -14,24 +12,7 @@ export async function getAllBalances(requestOptions) {
|
|
|
14
12
|
url: balancesEndpoint,
|
|
15
13
|
responseType: 'json'
|
|
16
14
|
});
|
|
17
|
-
|
|
18
|
-
name: 'response.data'
|
|
19
|
-
});
|
|
20
|
-
const balances = Types.asArray(body.balances, {
|
|
21
|
-
name: 'balances'
|
|
22
|
-
}).map(x => Types.asObject(x, {
|
|
23
|
-
name: 'balance'
|
|
24
|
-
}));
|
|
25
|
-
return {
|
|
26
|
-
balances: balances.map(x => ({
|
|
27
|
-
peer: Types.asString(x.peer, {
|
|
28
|
-
name: 'peer'
|
|
29
|
-
}),
|
|
30
|
-
balance: BZZ.fromPLUR(asNumberString(x.balance, {
|
|
31
|
-
name: 'balance'
|
|
32
|
-
}))
|
|
33
|
-
}))
|
|
34
|
-
};
|
|
15
|
+
return GetAllBalancesResponse.parse(response.data);
|
|
35
16
|
}
|
|
36
17
|
/**
|
|
37
18
|
* Get the balances with a specific peer including prepaid services
|
|
@@ -44,17 +25,7 @@ export async function getPeerBalance(requestOptions, address) {
|
|
|
44
25
|
url: `${balancesEndpoint}/${address}`,
|
|
45
26
|
responseType: 'json'
|
|
46
27
|
});
|
|
47
|
-
|
|
48
|
-
name: 'response.data'
|
|
49
|
-
});
|
|
50
|
-
return {
|
|
51
|
-
peer: Types.asString(body.peer, {
|
|
52
|
-
name: 'peer'
|
|
53
|
-
}),
|
|
54
|
-
balance: BZZ.fromPLUR(asNumberString(body.balance, {
|
|
55
|
-
name: 'balance'
|
|
56
|
-
}))
|
|
57
|
-
};
|
|
28
|
+
return GetPeerBalanceResponse.parse(response.data);
|
|
58
29
|
}
|
|
59
30
|
/**
|
|
60
31
|
* Get the past due consumption balances with all known peers
|
|
@@ -66,24 +37,7 @@ export async function getPastDueConsumptionBalances(requestOptions) {
|
|
|
66
37
|
url: consumedEndpoint,
|
|
67
38
|
responseType: 'json'
|
|
68
39
|
});
|
|
69
|
-
|
|
70
|
-
name: 'response.data'
|
|
71
|
-
});
|
|
72
|
-
const balances = Types.asArray(body.balances, {
|
|
73
|
-
name: 'balances'
|
|
74
|
-
}).map(x => Types.asObject(x, {
|
|
75
|
-
name: 'balance'
|
|
76
|
-
}));
|
|
77
|
-
return {
|
|
78
|
-
balances: balances.map(x => ({
|
|
79
|
-
peer: Types.asString(x.peer, {
|
|
80
|
-
name: 'peer'
|
|
81
|
-
}),
|
|
82
|
-
balance: BZZ.fromPLUR(asNumberString(x.balance, {
|
|
83
|
-
name: 'balance'
|
|
84
|
-
}))
|
|
85
|
-
}))
|
|
86
|
-
};
|
|
40
|
+
return GetAllBalancesResponse.parse(response.data);
|
|
87
41
|
}
|
|
88
42
|
/**
|
|
89
43
|
* Get the past due consumption balance with a specific peer
|
|
@@ -96,15 +50,5 @@ export async function getPastDueConsumptionPeerBalance(requestOptions, address)
|
|
|
96
50
|
url: `${consumedEndpoint}/${address}`,
|
|
97
51
|
responseType: 'json'
|
|
98
52
|
});
|
|
99
|
-
|
|
100
|
-
name: 'response.data'
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
peer: Types.asString(body.peer, {
|
|
104
|
-
name: 'peer'
|
|
105
|
-
}),
|
|
106
|
-
balance: BZZ.fromPLUR(asNumberString(body.balance, {
|
|
107
|
-
name: 'balance'
|
|
108
|
-
}))
|
|
109
|
-
};
|
|
53
|
+
return GetPeerBalanceResponse.parse(response.data);
|
|
110
54
|
}
|