@ethersphere/bee-js 13.1.1-upcoming.gc4973c3 → 13.2.0-upcoming.g40a63fd

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
@@ -59,6 +59,18 @@ Loading this module through a script tag will make the `BeeJs` object available
59
59
  <script src="https://unpkg.com/@ethersphere/bee-js/dist/index.browser.min.js"></script>
60
60
  ```
61
61
 
62
+ ### Browser apps and CORS
63
+
64
+ From Bee 2.8.3, a node rejects `POST`, `PUT`, `PATCH` and `DELETE` requests from a browser page on another origin with
65
+ `403 Forbidden`, unless that origin is listed in the node's `cors-allowed-origins` option. Uploads, stamp purchases and
66
+ other write calls from a web app therefore need the app's origin in that list:
67
+
68
+ ```sh
69
+ bee start --cors-allowed-origins="https://my-app.example"
70
+ ```
71
+
72
+ Node.js scripts are not affected, because they send no `Origin` header.
73
+
62
74
  ## Overview
63
75
 
64
76
  ### Type interfaces
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRedistributionState = getRedistributionState;
4
+ exports.setRedistributionEnabled = setRedistributionEnabled;
4
5
  const stake_1 = require("../types/schema/stake");
5
6
  const http_1 = require("../utils/http");
6
7
  const redistributionStateEndpoint = 'redistributionstate';
@@ -15,3 +16,12 @@ async function getRedistributionState(requestOptions) {
15
16
  });
16
17
  return stake_1.GetRedistributionStateResponse.parse(response.data);
17
18
  }
19
+ async function setRedistributionEnabled(requestOptions, enabled) {
20
+ const response = await (0, http_1.http)(requestOptions, {
21
+ method: 'patch',
22
+ responseType: 'json',
23
+ url: redistributionStateEndpoint,
24
+ data: { enabled },
25
+ });
26
+ return stake_1.RedistributionToggleResponse.parse(response.data).enabled;
27
+ }
@@ -18,7 +18,7 @@ async function getStake(requestOptions) {
18
18
  responseType: 'json',
19
19
  url: STAKE_ENDPOINT,
20
20
  });
21
- return stake_1.GetStakeResponse.parse(response.data).stakedAmount;
21
+ return stake_1.GetStakeResponse.parse(response.data);
22
22
  }
23
23
  async function getWithdrawableStake(requestOptions) {
24
24
  const response = await (0, http_1.http)(requestOptions, {
@@ -71,7 +71,7 @@ class Chequebook {
71
71
  */
72
72
  async deposit(amount, gasPrice, requestOptions) {
73
73
  const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
74
- const gasPriceString = gasPrice ? (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' }) : undefined;
74
+ const gasPriceString = gasPrice ? (0, type_1.asNumberString)(gasPrice, { min: 0n, name: 'gasPrice' }) : undefined;
75
75
  return api.depositTokens(this.context.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
76
76
  }
77
77
  /**
@@ -83,7 +83,7 @@ class Chequebook {
83
83
  */
84
84
  async withdraw(amount, gasPrice, requestOptions) {
85
85
  const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
86
- const gasPriceString = gasPrice ? (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' }) : undefined;
86
+ const gasPriceString = gasPrice ? (0, type_1.asNumberString)(gasPrice, { min: 0n, name: 'gasPrice' }) : undefined;
87
87
  return api.withdrawTokens(this.context.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
88
88
  }
89
89
  }
@@ -194,13 +194,23 @@ class Messaging {
194
194
  * @param address
195
195
  * @param identifier
196
196
  * @param handler
197
+ * @param options SOC fields to receive and whether to cache the wrapped chunk; requires Bee 2.8.3 or later
197
198
  */
198
- gsocSubscribe(address, identifier, handler) {
199
+ gsocSubscribe(address, identifier, handler, options) {
199
200
  const ethAddress = new core_sdk_1.EthAddress(address);
200
201
  const id = new core_sdk_1.Identifier(identifier);
201
202
  handler = schema_1.GsocMessageHandlerSchema.parse(handler);
203
+ const { fields, cacheWrappedChunk } = schema_1.GsocSubscribeOptionsSchema.parse(options ?? {});
204
+ const params = new URLSearchParams();
205
+ if (fields) {
206
+ params.set('swarm-soc-fields', fields.join(','));
207
+ }
208
+ if (cacheWrappedChunk !== undefined) {
209
+ params.set('swarm-cache-wrapped-chunk', String(cacheWrappedChunk));
210
+ }
202
211
  const socAddress = (0, soc_1.makeSOCAddress)(id, ethAddress);
203
- const ws = this.openWebSocket(`${GSOC_ENDPOINT}/subscribe/${socAddress.toHex()}`);
212
+ const query = params.toString() ? `?${params.toString()}` : '';
213
+ const ws = this.openWebSocket(`${GSOC_ENDPOINT}/subscribe/${socAddress.toHex()}${query}`);
204
214
  const cancel = this.makeCancel(ws);
205
215
  const subscription = { address: ethAddress, cancel };
206
216
  ws.onmessage = async (event) => {
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Stake = void 0;
37
+ const zod_1 = require("zod");
37
38
  const schema_1 = require("../utils/schema");
38
39
  const tokens_1 = require("../utils/tokens");
39
40
  const type_1 = require("../utils/type");
@@ -54,7 +55,13 @@ class Stake {
54
55
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
55
56
  */
56
57
  async get(requestOptions) {
57
- return stakeApi.getStake(this.context.getRequestOptionsForCall(requestOptions));
58
+ const { stakedAmount } = await stakeApi.getStake(this.context.getRequestOptionsForCall(requestOptions));
59
+ return stakedAmount;
60
+ }
61
+ /** Gets the minimum next deposit, or `null` when Bee cannot determine it (e.g. the price oracle is unavailable). */
62
+ async getMinimumDeposit(requestOptions) {
63
+ const { minimumDeposit } = await stakeApi.getStake(this.context.getRequestOptionsForCall(requestOptions));
64
+ return minimumDeposit;
58
65
  }
59
66
  /**
60
67
  * Gets the amount of withdrawable staked BZZ.
@@ -65,7 +72,7 @@ class Stake {
65
72
  return stakeApi.getWithdrawableStake(this.context.getRequestOptionsForCall(requestOptions));
66
73
  }
67
74
  /**
68
- * Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
75
+ * Stakes the given amount of BZZ. Must be at least {@link getMinimumDeposit}, otherwise Bee rejects it with 400.
69
76
  *
70
77
  * Be aware that staked BZZ tokens can **not** be withdrawn.
71
78
  *
@@ -106,5 +113,9 @@ class Stake {
106
113
  async getRedistributionState(requestOptions) {
107
114
  return redistributionApi.getRedistributionState(this.context.getRequestOptionsForCall(requestOptions));
108
115
  }
116
+ /** Enables or disables participation in new redistribution rounds; resets to enabled when the node restarts. */
117
+ async setRedistributionEnabled(enabled, requestOptions) {
118
+ return redistributionApi.setRedistributionEnabled(this.context.getRequestOptionsForCall(requestOptions), zod_1.z.boolean().parse(enabled));
119
+ }
109
120
  }
110
121
  exports.Stake = Stake;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetRedistributionStateResponse = exports.TxHashResponse = exports.GetWithdrawableStakeResponse = exports.GetStakeResponse = void 0;
3
+ exports.RedistributionToggleResponse = exports.GetRedistributionStateResponse = exports.TxHashResponse = exports.GetWithdrawableStakeResponse = exports.GetStakeResponse = void 0;
4
4
  const core_sdk_1 = require("@ethersphere/core-sdk");
5
5
  const zod_1 = require("zod");
6
6
  const tokens_1 = require("../../utils/tokens");
7
7
  const type_1 = require("../../utils/type");
8
8
  exports.GetStakeResponse = zod_1.z.object({
9
9
  stakedAmount: zod_1.z.string().transform(s => tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(s, { name: 'stakedAmount' }))),
10
+ minimumDeposit: zod_1.z
11
+ .string()
12
+ .nullish()
13
+ .transform(s => (s ? tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(s, { name: 'minimumDeposit' })) : null)),
10
14
  });
11
15
  exports.GetWithdrawableStakeResponse = zod_1.z.object({
12
16
  withdrawableAmount: zod_1.z.string().transform(s => tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(s, { name: 'withdrawableAmount' }))),
@@ -30,4 +34,10 @@ exports.GetRedistributionStateResponse = zod_1.z.object({
30
34
  reward: zod_1.z.string().transform(s => tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(s, { name: 'reward' }))),
31
35
  fees: zod_1.z.string().transform(s => tokens_1.DAI.fromWei((0, type_1.asNumberString)(s, { name: 'fees' }))),
32
36
  isHealthy: zod_1.z.boolean(),
37
+ enabled: zod_1.z.boolean(),
38
+ hasCommittedThisRound: zod_1.z.boolean(),
39
+ hasRevealedThisRound: zod_1.z.boolean(),
40
+ });
41
+ exports.RedistributionToggleResponse = zod_1.z.object({
42
+ enabled: zod_1.z.boolean(),
33
43
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AllTagsOptionsSchema = exports.TransactionOptionsSchema = exports.PostageBatchOptionsSchema = exports.GsocMessageHandlerSchema = exports.PssMessageHandlerSchema = exports.TagUidSchema = exports.TagInputSchema = exports.CollectionUploadOptionsSchema = exports.FileUploadOptionsSchema = exports.RedundantUploadOptionsSchema = exports.UploadOptionsSchema = exports.DownloadOptionsSchema = exports.BeeRequestOptionsSchema = exports.HexStringSchema = void 0;
3
+ exports.AllTagsOptionsSchema = exports.TransactionOptionsSchema = exports.PostageBatchOptionsSchema = exports.GsocSubscribeOptionsSchema = exports.GsocMessageHandlerSchema = exports.PssMessageHandlerSchema = exports.TagUidSchema = exports.TagInputSchema = exports.CollectionUploadOptionsSchema = exports.FileUploadOptionsSchema = exports.RedundantUploadOptionsSchema = exports.UploadOptionsSchema = exports.DownloadOptionsSchema = exports.BeeRequestOptionsSchema = exports.HexStringSchema = void 0;
4
4
  const core_sdk_1 = require("@ethersphere/core-sdk");
5
5
  const zod_1 = require("zod");
6
6
  const types_1 = require("../types");
@@ -71,6 +71,13 @@ exports.GsocMessageHandlerSchema = zod_1.z.object({
71
71
  onError: fnField,
72
72
  onClose: fnField,
73
73
  });
74
+ exports.GsocSubscribeOptionsSchema = zod_1.z.object({
75
+ fields: zod_1.z
76
+ .array(zod_1.z.enum(['address', 'recoveredPubKey', 'identifier', 'signature', 'wrappedAddress', 'span', 'payload']))
77
+ .nonempty()
78
+ .optional(),
79
+ cacheWrappedChunk: zod_1.z.boolean().optional(),
80
+ });
74
81
  exports.PostageBatchOptionsSchema = zod_1.z.object({
75
82
  gasPrice: integerStringField.optional(),
76
83
  immutableFlag: zod_1.z.boolean().optional(),
@@ -4,8 +4,8 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
6
6
  /** Exact supported Bee version, including the commit hash suffix. */
7
- exports.SUPPORTED_BEE_VERSION_EXACT = '2.8.1-7cf53193';
7
+ exports.SUPPORTED_BEE_VERSION_EXACT = '2.8.3';
8
8
  /** Supported Bee version without the commit hash suffix. */
9
9
  exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
10
10
  /** Supported Bee API version. */
11
- exports.SUPPORTED_API_VERSION = '8.1.0';
11
+ exports.SUPPORTED_API_VERSION = '8.2.0';