@upcoming/bee-js 11.1.0 → 12.0.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/mjs/bee.js CHANGED
@@ -34,7 +34,7 @@ import { prepareWebsocketData } from "./utils/data.js";
34
34
  import { BeeArgumentError, BeeError } from "./utils/error.js";
35
35
  import { fileArrayBuffer, isFile } from "./utils/file.js";
36
36
  import { ResourceLocator } from "./utils/resource-locator.js";
37
- import { getAmountForDuration, getDepthForSize, getStampCost } from "./utils/stamps.js";
37
+ import { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration } from "./utils/stamps.js";
38
38
  import { BZZ, DAI } from "./utils/tokens.js";
39
39
  import { asNumberString, assertData, assertFileData, makeTagUid, prepareAllTagsOptions, prepareBeeRequestOptions, prepareCollectionUploadOptions, prepareDownloadOptions, prepareFileUploadOptions, prepareGsocMessageHandler, preparePostageBatchOptions, preparePssMessageHandler, prepareRedundantUploadOptions, prepareTransactionOptions, prepareUploadOptions } from "./utils/type.js";
40
40
  import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Signature, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
@@ -1730,6 +1730,25 @@ export class Bee {
1730
1730
  const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1731
1731
  return getStampCost(batch.depth, amount);
1732
1732
  }
1733
+ /**
1734
+ * Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
1735
+ *
1736
+ * @param postageBatchId
1737
+ * @param bzz The amount of BZZ to spend on the top-up.
1738
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1739
+ * @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
1740
+ */
1741
+ async calculateTopUpForBzz(postageBatchId, bzz, requestOptions) {
1742
+ const batch = await this.getPostageBatch(postageBatchId, requestOptions);
1743
+ const chainState = await this.getChainState(requestOptions);
1744
+ const blockTime = this.network === 'gnosis' ? 5 : 15;
1745
+ const amount = bzz.toPLURBigInt() / 2n ** BigInt(batch.depth);
1746
+ const duration = getStampDuration(amount, chainState.currentPrice, blockTime);
1747
+ return {
1748
+ amount,
1749
+ duration
1750
+ };
1751
+ }
1733
1752
  /**
1734
1753
  * Increases the duration of a postage batch by increasing its amount.
1735
1754
  *
@@ -1154,6 +1154,18 @@ export declare class Bee {
1154
1154
  * @returns
1155
1155
  */
1156
1156
  getDurationExtensionCost(postageBatchId: BatchId | Uint8Array | string, duration: Duration, requestOptions?: BeeRequestOptions): Promise<BZZ>;
1157
+ /**
1158
+ * Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
1159
+ *
1160
+ * @param postageBatchId
1161
+ * @param bzz The amount of BZZ to spend on the top-up.
1162
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1163
+ * @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
1164
+ */
1165
+ calculateTopUpForBzz(postageBatchId: BatchId | Uint8Array | string, bzz: BZZ, requestOptions?: BeeRequestOptions): Promise<{
1166
+ amount: bigint;
1167
+ duration: Duration;
1168
+ }>;
1157
1169
  /**
1158
1170
  * Increases the duration of a postage batch by increasing its amount.
1159
1171
  *
@@ -1,3 +1,3 @@
1
1
  import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
2
  import { BatchId } from './typed-bytes';
3
- export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
3
+ export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any, {}>>;
@@ -1,3 +1,3 @@
1
1
  import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
2
  import { BatchId } from './typed-bytes';
3
- export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
3
+ export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any, {}>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upcoming/bee-js",
3
- "version": "11.1.0",
3
+ "version": "12.0.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -61,7 +61,7 @@
61
61
  "depcheck": "depcheck ."
62
62
  },
63
63
  "dependencies": {
64
- "axios": "^0.30.2",
64
+ "axios": "^1.15.1",
65
65
  "cafe-utility": "^33.6.1",
66
66
  "debug": "^4.4.1",
67
67
  "isomorphic-ws": "^4.0.1",