@ethersphere/bee-js 5.0.0 → 5.1.1

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 CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  **Warning: This project is in beta state. There might (and most probably will) be changes in the future to its API and working. Also, no guarantees can be made about its stability, efficiency, and security at this stage.**
15
15
 
16
- This project is intended to be used with **Bee version <!-- SUPPORTED_BEE_START -->1.7.0<!-- SUPPORTED_BEE_END -->**. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/bee-js/releases).
16
+ This project is intended to be used with **Bee version <!-- SUPPORTED_BEE_START -->1.10.0<!-- SUPPORTED_BEE_END -->**. Using it with older or newer Bee versions is not recommended and may not work. Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the [releases tab](https://github.com/ethersphere/bee-js/releases).
17
17
 
18
18
  ## Table of Contents
19
19
 
@@ -71,14 +71,15 @@ Loading this module through a script tag will make the `BeeJs` object available
71
71
  ## Usage
72
72
 
73
73
  ```js
74
- import { Bee } from "@ethersphere/bee-js"
74
+ import { Bee, BeeDebug } from '@ethersphere/bee-js'
75
75
 
76
- bee = new Bee("http://localhost:1633")
76
+ const bee = new Bee('http://localhost:1633')
77
+ const beeDebug = new BeeDebug('http://localhost:1635')
77
78
 
78
79
  // Be aware, this creates on-chain transactions that spend Eth and BZZ!
79
- const batchId = await bee.createPostageBatch('100', 17)
80
- const fileHash = await bee.uploadData(batchId, "Bee is awesome!")
81
- const data = await bee.downloadData(fileHash)
80
+ const batchId = await beeDebug.createPostageBatch('2000', 20)
81
+ const { reference } = await bee.uploadData(batchId, 'Bee is awesome!')
82
+ const data = await bee.downloadData(reference)
82
83
 
83
84
  console.log(data.text()) // prints 'Bee is awesome!'
84
85
  ```
@@ -40,6 +40,7 @@ const settlements = __importStar(require("./modules/debug/settlements"));
40
40
  const status = __importStar(require("./modules/debug/status"));
41
41
  const transactions = __importStar(require("./modules/debug/transactions"));
42
42
  const states = __importStar(require("./modules/debug/states"));
43
+ const stake = __importStar(require("./modules/debug/stake"));
43
44
  const error_1 = require("./utils/error");
44
45
  const url_1 = require("./utils/url");
45
46
  const type_1 = require("./utils/type");
@@ -327,6 +328,15 @@ class BeeDebug {
327
328
  return status.getHealth(this.getKy(options));
328
329
  });
329
330
  }
331
+ /**
332
+ * Get readiness of node
333
+ */
334
+ getReadiness(options) {
335
+ return __awaiter(this, void 0, void 0, function* () {
336
+ (0, type_1.assertRequestOptions)(options);
337
+ return status.getReadiness(this.getKy(options));
338
+ });
339
+ }
330
340
  /**
331
341
  * Get mode information of node
332
342
  */
@@ -619,6 +629,32 @@ class BeeDebug {
619
629
  return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
620
630
  });
621
631
  }
632
+ /**
633
+ * Gets the staked amount of BZZ (in PLUR unit) as number string.
634
+ *
635
+ * @param options
636
+ */
637
+ getStake(options) {
638
+ return __awaiter(this, void 0, void 0, function* () {
639
+ (0, type_1.assertRequestOptions)(options);
640
+ return stake.getStake(this.getKy(options));
641
+ });
642
+ }
643
+ /**
644
+ * Deposits given amount of BZZ token (in PLUR unit).
645
+ *
646
+ * Be aware that staked BZZ tokens can **not** be withdrawn.
647
+ *
648
+ * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
649
+ * @param options
650
+ */
651
+ depositStake(amount, options) {
652
+ return __awaiter(this, void 0, void 0, function* () {
653
+ (0, type_1.assertRequestOptions)(options);
654
+ (0, type_1.assertTransactionOptions)(options);
655
+ yield stake.stake(this.getKy(options), amount, options);
656
+ });
657
+ }
622
658
  waitForUsablePostageStamp(id, timeout = 120000) {
623
659
  return __awaiter(this, void 0, void 0, function* () {
624
660
  const TIME_STEP = 1500;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.stake = exports.getStake = void 0;
13
+ const http_1 = require("../../utils/http");
14
+ const STAKE_ENDPOINT = 'stake';
15
+ /**
16
+ * Gets the staked amount
17
+ *
18
+ * @param ky Ky instance for given Bee class instance
19
+ */
20
+ function getStake(ky) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const response = yield (0, http_1.http)(ky, {
23
+ method: 'get',
24
+ responseType: 'json',
25
+ path: `${STAKE_ENDPOINT}`,
26
+ });
27
+ return response.data.stakedAmount.toString();
28
+ });
29
+ }
30
+ exports.getStake = getStake;
31
+ /**
32
+ * Stake given amount of tokens.
33
+ *
34
+ * @param ky
35
+ * @param amount
36
+ * @param options
37
+ */
38
+ function stake(ky, amount, options) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const headers = {};
41
+ if (options === null || options === void 0 ? void 0 : options.gasPrice) {
42
+ headers['gas-price'] = options.gasPrice.toString();
43
+ }
44
+ if (options === null || options === void 0 ? void 0 : options.gasLimit) {
45
+ headers['gas-limit'] = options.gasLimit.toString();
46
+ }
47
+ yield (0, http_1.http)(ky, {
48
+ method: 'post',
49
+ responseType: 'json',
50
+ path: `${STAKE_ENDPOINT}/${amount}`,
51
+ headers,
52
+ });
53
+ });
54
+ }
55
+ exports.stake = stake;
@@ -58,7 +58,20 @@ function getWalletBalance(ky) {
58
58
  path: `${WALLET_ENDPOINT}`,
59
59
  responseType: 'json',
60
60
  });
61
- return response.data;
61
+ return mapWalletProperties(response.data);
62
62
  });
63
63
  }
64
64
  exports.getWalletBalance = getWalletBalance;
65
+ /**
66
+ * TODO: Remove on next break
67
+ * @param data
68
+ */
69
+ function mapWalletProperties(data) {
70
+ return Object.assign({
71
+ // @ts-ignore: Needed for backward compatibility mapping
72
+ bzz: data.bzzBalance,
73
+ // @ts-ignore: Needed for backward compatibility mapping
74
+ xDai: data.nativeTokenBalance,
75
+ // @ts-ignore: Needed for backward compatibility mapping
76
+ contractAddress: data.chequebookContractAddress }, data);
77
+ }
@@ -12,17 +12,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedDebugApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getHealth = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_DEBUG_API_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
15
+ exports.getVersions = exports.isSupportedApiVersion = exports.isSupportedDebugApiVersion = exports.isSupportedMainApiVersion = exports.isSupportedExactVersion = exports.isSupportedVersion = exports.getNodeInfo = exports.getReadiness = exports.getHealth = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_DEBUG_API_VERSION = exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
16
16
  const http_1 = require("../../utils/http");
17
17
  const major_js_1 = __importDefault(require("semver/functions/major.js"));
18
18
  // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
19
19
  // so if you are changing anything about them change the `update_bee` action accordingly!
20
- exports.SUPPORTED_BEE_VERSION_EXACT = '1.7.0-bbf13011';
21
- exports.SUPPORTED_API_VERSION = '3.0.2';
22
- exports.SUPPORTED_DEBUG_API_VERSION = '3.0.2';
20
+ exports.SUPPORTED_BEE_VERSION_EXACT = '1.10.0-904cbb08';
21
+ exports.SUPPORTED_API_VERSION = '4.0.0';
22
+ exports.SUPPORTED_DEBUG_API_VERSION = '4.0.0';
23
23
  exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.substring(0, exports.SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
24
24
  const NODE_INFO_URL = 'node';
25
25
  const HEALTH_URL = 'health';
26
+ const READINESS_URL = 'readiness';
26
27
  /**
27
28
  * Get health of node
28
29
  *
@@ -39,6 +40,26 @@ function getHealth(ky) {
39
40
  });
40
41
  }
41
42
  exports.getHealth = getHealth;
43
+ /**
44
+ * Get readiness of node
45
+ *
46
+ * @param ky Ky debug instance
47
+ */
48
+ function getReadiness(ky) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ try {
51
+ const response = yield (0, http_1.http)(ky, {
52
+ method: 'get',
53
+ path: READINESS_URL,
54
+ });
55
+ return response.status === 200;
56
+ }
57
+ catch (_a) {
58
+ return false;
59
+ }
60
+ });
61
+ }
62
+ exports.getReadiness = getReadiness;
42
63
  /**
43
64
  * Get information about Bee node
44
65
  *
@@ -63,6 +84,7 @@ exports.getNodeInfo = getNodeInfo;
63
84
  * @returns true if the Bee node version is supported
64
85
  * @deprecated Use `isSupportedExactVersion` instead
65
86
  */
87
+ // TODO: Remove on break
66
88
  function isSupportedVersion(ky) {
67
89
  return __awaiter(this, void 0, void 0, function* () {
68
90
  return isSupportedExactVersion(ky);
@@ -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.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.isUint8Array = void 0;
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.isUint8Array = void 0;
4
4
  const types_1 = require("../types");
5
5
  const error_1 = require("./error");
6
6
  const file_1 = require("./file");
@@ -322,20 +322,29 @@ function assertPostageBatchOptions(value) {
322
322
  }
323
323
  }
324
324
  exports.assertPostageBatchOptions = assertPostageBatchOptions;
325
- function assertCashoutOptions(value) {
325
+ function assertTransactionOptions(value, name = 'TransactionOptions') {
326
326
  if (value === undefined) {
327
327
  return;
328
328
  }
329
- assertStrictlyObject(value);
329
+ assertStrictlyObject(value, name);
330
330
  const options = value;
331
- assertRequestOptions(options, 'PostageBatchOptions');
332
331
  if (options === null || options === void 0 ? void 0 : options.gasLimit) {
333
- assertNonNegativeInteger(options.gasLimit);
332
+ assertNonNegativeInteger(options.gasLimit, name);
334
333
  }
335
334
  if (options === null || options === void 0 ? void 0 : options.gasPrice) {
336
- assertNonNegativeInteger(options.gasPrice);
335
+ assertNonNegativeInteger(options.gasPrice, name);
337
336
  }
338
337
  }
338
+ exports.assertTransactionOptions = assertTransactionOptions;
339
+ function assertCashoutOptions(value) {
340
+ if (value === undefined) {
341
+ return;
342
+ }
343
+ assertStrictlyObject(value);
344
+ const options = value;
345
+ assertRequestOptions(options, 'CashoutOptions');
346
+ assertTransactionOptions(options, 'CashoutOptions');
347
+ }
339
348
  exports.assertCashoutOptions = assertCashoutOptions;
340
349
  /**
341
350
  * Check whether the given parameter is valid data to upload