@ethersphere/bee-js 12.3.2-upcoming.116 → 13.0.0-upcoming.gcfb9756

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.
Files changed (183) hide show
  1. package/dist/cjs/api/balance.js +24 -0
  2. package/dist/cjs/api/batches.js +26 -0
  3. package/dist/cjs/{modules → api}/bytes.js +1 -25
  4. package/dist/cjs/{modules → api}/bzz.js +1 -28
  5. package/dist/cjs/{modules/debug → api}/chequebook.js +48 -87
  6. package/dist/cjs/api/chunk.js +43 -0
  7. package/dist/cjs/api/connectivity.js +86 -0
  8. package/dist/cjs/api/consumed.js +24 -0
  9. package/dist/cjs/api/feed.js +56 -0
  10. package/dist/cjs/api/grantee.js +62 -0
  11. package/dist/cjs/{modules/pinning.js → api/pin.js} +12 -33
  12. package/dist/cjs/api/pss.js +19 -0
  13. package/dist/cjs/api/redistributionstate.js +17 -0
  14. package/dist/cjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
  15. package/dist/cjs/api/soc.js +34 -0
  16. package/dist/cjs/{modules/debug → api}/stake.js +15 -43
  17. package/dist/cjs/{modules/debug/stamps.js → api/stamp.js} +41 -57
  18. package/dist/cjs/api/status.js +67 -0
  19. package/dist/cjs/{modules → api}/stewardship.js +1 -6
  20. package/dist/cjs/api/tag.js +51 -0
  21. package/dist/cjs/{modules/debug/transactions.js → api/transaction.js} +10 -31
  22. package/dist/cjs/{modules/debug/states.js → api/wallet.js} +4 -36
  23. package/dist/cjs/bee.js +111 -1973
  24. package/dist/cjs/chunk/soc.js +2 -2
  25. package/dist/cjs/feed/index.js +3 -3
  26. package/dist/cjs/feed/retrievable.js +1 -1
  27. package/dist/cjs/manifest/manifest.js +3 -3
  28. package/dist/cjs/modules/balance.js +86 -0
  29. package/dist/cjs/modules/cheque.js +92 -0
  30. package/dist/cjs/modules/chequebook.js +90 -0
  31. package/dist/cjs/modules/chunk.js +86 -52
  32. package/dist/cjs/modules/collection.js +145 -0
  33. package/dist/cjs/modules/connectivity.js +141 -0
  34. package/dist/cjs/modules/context.js +2 -0
  35. package/dist/cjs/modules/data.js +119 -0
  36. package/dist/cjs/modules/feed.js +93 -69
  37. package/dist/cjs/modules/file.js +113 -0
  38. package/dist/cjs/modules/grantee.js +86 -55
  39. package/dist/cjs/modules/messaging.js +250 -0
  40. package/dist/cjs/modules/pin.js +100 -0
  41. package/dist/cjs/modules/settlement.js +67 -0
  42. package/dist/cjs/modules/soc.js +38 -35
  43. package/dist/cjs/modules/stake.js +110 -0
  44. package/dist/cjs/modules/stamp.js +199 -0
  45. package/dist/cjs/modules/status.js +128 -20
  46. package/dist/cjs/modules/storage.js +191 -0
  47. package/dist/cjs/modules/tag.js +97 -71
  48. package/dist/cjs/modules/transaction.js +92 -0
  49. package/dist/cjs/modules/wallet.js +82 -0
  50. package/dist/cjs/utils/chunk-stream.browser.js +1 -1
  51. package/dist/cjs/utils/chunk-stream.js +1 -1
  52. package/dist/index.browser.min.js +1 -1
  53. package/dist/index.browser.min.js.map +1 -1
  54. package/dist/mjs/api/balance.js +20 -0
  55. package/dist/mjs/api/batches.js +22 -0
  56. package/dist/mjs/{modules → api}/bytes.js +1 -25
  57. package/dist/mjs/{modules → api}/bzz.js +1 -28
  58. package/dist/mjs/{modules/debug → api}/chequebook.js +50 -89
  59. package/dist/mjs/api/chunk.js +37 -0
  60. package/dist/mjs/api/connectivity.js +76 -0
  61. package/dist/mjs/api/consumed.js +20 -0
  62. package/dist/mjs/api/feed.js +53 -0
  63. package/dist/mjs/api/grantee.js +59 -0
  64. package/dist/mjs/{modules/pinning.js → api/pin.js} +13 -34
  65. package/dist/mjs/api/pss.js +18 -0
  66. package/dist/mjs/api/redistributionstate.js +14 -0
  67. package/dist/mjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
  68. package/dist/mjs/api/soc.js +31 -0
  69. package/dist/mjs/{modules/debug → api}/stake.js +14 -41
  70. package/dist/mjs/{modules/debug/stamps.js → api/stamp.js} +37 -51
  71. package/dist/mjs/api/status.js +59 -0
  72. package/dist/mjs/{modules → api}/stewardship.js +1 -6
  73. package/dist/mjs/api/tag.js +49 -0
  74. package/dist/mjs/api/transaction.js +41 -0
  75. package/dist/mjs/api/wallet.js +38 -0
  76. package/dist/mjs/bee.js +115 -1964
  77. package/dist/mjs/chunk/soc.js +2 -2
  78. package/dist/mjs/feed/index.js +3 -3
  79. package/dist/mjs/feed/retrievable.js +1 -1
  80. package/dist/mjs/manifest/manifest.js +3 -3
  81. package/dist/mjs/modules/balance.js +49 -0
  82. package/dist/mjs/modules/cheque.js +55 -0
  83. package/dist/mjs/modules/chequebook.js +65 -0
  84. package/dist/mjs/modules/chunk.js +52 -49
  85. package/dist/mjs/modules/collection.js +108 -0
  86. package/dist/mjs/modules/connectivity.js +102 -0
  87. package/dist/mjs/modules/context.js +1 -0
  88. package/dist/mjs/modules/data.js +82 -0
  89. package/dist/mjs/modules/feed.js +89 -67
  90. package/dist/mjs/modules/file.js +78 -0
  91. package/dist/mjs/modules/grantee.js +52 -55
  92. package/dist/mjs/modules/messaging.js +215 -0
  93. package/dist/mjs/modules/pin.js +63 -0
  94. package/dist/mjs/modules/settlement.js +30 -0
  95. package/dist/mjs/modules/soc.js +36 -34
  96. package/dist/mjs/modules/stake.js +76 -0
  97. package/dist/mjs/modules/stamp.js +170 -0
  98. package/dist/mjs/modules/status.js +98 -18
  99. package/dist/mjs/modules/storage.js +185 -0
  100. package/dist/mjs/modules/tag.js +61 -68
  101. package/dist/mjs/modules/transaction.js +58 -0
  102. package/dist/mjs/modules/wallet.js +45 -0
  103. package/dist/mjs/utils/chunk-stream.browser.js +1 -1
  104. package/dist/mjs/utils/chunk-stream.js +1 -1
  105. package/dist/types/api/balance.d.ts +7 -0
  106. package/dist/types/api/batches.d.ts +7 -0
  107. package/dist/types/{modules → api}/bytes.d.ts +2 -25
  108. package/dist/types/{modules → api}/bzz.d.ts +1 -28
  109. package/dist/types/api/chequebook.d.ts +21 -0
  110. package/dist/types/api/chunk.d.ts +7 -0
  111. package/dist/types/api/connectivity.d.ts +22 -0
  112. package/dist/types/api/consumed.d.ts +7 -0
  113. package/dist/types/api/feed.d.ts +41 -0
  114. package/dist/types/api/grantee.d.ts +11 -0
  115. package/dist/types/api/pin.d.ts +10 -0
  116. package/dist/types/api/pss.d.ts +6 -0
  117. package/dist/types/api/redistributionstate.d.ts +5 -0
  118. package/dist/types/api/settlement.d.ts +7 -0
  119. package/dist/types/api/soc.d.ts +6 -0
  120. package/dist/types/api/stake.d.ts +11 -0
  121. package/dist/types/api/stamp.d.ts +12 -0
  122. package/dist/types/api/status.d.ts +11 -0
  123. package/dist/types/{modules → api}/stewardship.d.ts +2 -5
  124. package/dist/types/api/tag.d.ts +12 -0
  125. package/dist/types/api/transaction.d.ts +9 -0
  126. package/dist/types/api/wallet.d.ts +9 -0
  127. package/dist/types/bee.d.ts +71 -1197
  128. package/dist/types/feed/index.d.ts +1 -1
  129. package/dist/types/manifest/manifest.d.ts +1 -1
  130. package/dist/types/modules/balance.d.ts +38 -0
  131. package/dist/types/modules/cheque.d.ts +40 -0
  132. package/dist/types/modules/chequebook.d.ts +41 -0
  133. package/dist/types/modules/chunk.d.ts +30 -19
  134. package/dist/types/modules/collection.d.ts +77 -0
  135. package/dist/types/modules/connectivity.d.ts +74 -0
  136. package/dist/types/modules/context.d.ts +24 -0
  137. package/dist/types/modules/data.d.ts +56 -0
  138. package/dist/types/modules/feed.d.ts +47 -49
  139. package/dist/types/modules/file.d.ts +44 -0
  140. package/dist/types/modules/grantee.d.ts +39 -7
  141. package/dist/types/modules/messaging.d.ts +80 -0
  142. package/dist/types/modules/pin.d.ts +47 -0
  143. package/dist/types/modules/settlement.d.ts +25 -0
  144. package/dist/types/modules/soc.d.ts +23 -11
  145. package/dist/types/modules/stake.d.ts +55 -0
  146. package/dist/types/modules/stamp.d.ts +96 -0
  147. package/dist/types/modules/status.d.ts +66 -5
  148. package/dist/types/modules/storage.d.ts +107 -0
  149. package/dist/types/modules/tag.d.ts +43 -32
  150. package/dist/types/modules/transaction.d.ts +42 -0
  151. package/dist/types/modules/wallet.d.ts +35 -0
  152. package/dist/types/types/index.d.ts +1 -1
  153. package/package.json +3 -2
  154. package/dist/cjs/modules/debug/balance.js +0 -60
  155. package/dist/cjs/modules/debug/connectivity.js +0 -54
  156. package/dist/cjs/modules/debug/status.js +0 -104
  157. package/dist/cjs/modules/gsoc.js +0 -23
  158. package/dist/cjs/modules/pss.js +0 -48
  159. package/dist/mjs/modules/debug/balance.js +0 -54
  160. package/dist/mjs/modules/debug/connectivity.js +0 -46
  161. package/dist/mjs/modules/debug/states.js +0 -68
  162. package/dist/mjs/modules/debug/status.js +0 -99
  163. package/dist/mjs/modules/debug/transactions.js +0 -62
  164. package/dist/mjs/modules/gsoc.js +0 -16
  165. package/dist/mjs/modules/pss.js +0 -43
  166. package/dist/types/modules/debug/balance.d.ts +0 -28
  167. package/dist/types/modules/debug/chequebook.d.ts +0 -60
  168. package/dist/types/modules/debug/connectivity.d.ts +0 -9
  169. package/dist/types/modules/debug/settlements.d.ts +0 -15
  170. package/dist/types/modules/debug/stake.d.ts +0 -30
  171. package/dist/types/modules/debug/stamps.d.ts +0 -11
  172. package/dist/types/modules/debug/states.d.ts +0 -23
  173. package/dist/types/modules/debug/status.d.ts +0 -46
  174. package/dist/types/modules/debug/transactions.d.ts +0 -30
  175. package/dist/types/modules/gsoc.d.ts +0 -6
  176. package/dist/types/modules/pinning.d.ts +0 -30
  177. package/dist/types/modules/pss.d.ts +0 -22
  178. /package/dist/cjs/{modules → api}/envelope.js +0 -0
  179. /package/dist/cjs/{modules → api}/rchash.js +0 -0
  180. /package/dist/mjs/{modules → api}/envelope.js +0 -0
  181. /package/dist/mjs/{modules → api}/rchash.js +0 -0
  182. /package/dist/types/{modules → api}/envelope.d.ts +0 -0
  183. /package/dist/types/{modules → api}/rchash.d.ts +0 -0
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBalances = getBalances;
4
+ exports.getPeerBalance = getPeerBalance;
5
+ const balance_1 = require("../types/schema/balance");
6
+ const http_1 = require("../utils/http");
7
+ const balancesEndpoint = 'balances';
8
+ /**
9
+ * Raw HTTP calls for the `/balances` endpoint.
10
+ */
11
+ async function getBalances(requestOptions) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ url: balancesEndpoint,
14
+ responseType: 'json',
15
+ });
16
+ return balance_1.GetAllBalancesResponse.parse(response.data);
17
+ }
18
+ async function getPeerBalance(requestOptions, peer) {
19
+ const response = await (0, http_1.http)(requestOptions, {
20
+ url: `${balancesEndpoint}/${peer}`,
21
+ responseType: 'json',
22
+ });
23
+ return balance_1.GetPeerBalanceResponse.parse(response.data);
24
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getGlobalPostageBatch = getGlobalPostageBatch;
4
+ exports.getAllGlobalPostageBatches = getAllGlobalPostageBatches;
5
+ const stamps_1 = require("../types/schema/stamps");
6
+ const http_1 = require("../utils/http");
7
+ const batchesEndpoint = 'batches';
8
+ /**
9
+ * Raw HTTP calls for the `/batches` endpoint.
10
+ */
11
+ async function getGlobalPostageBatch(requestOptions, id) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ method: 'get',
14
+ url: `${batchesEndpoint}/${id}`,
15
+ responseType: 'json',
16
+ });
17
+ return stamps_1.GetGlobalPostageBatchResponse.parse(response.data);
18
+ }
19
+ async function getAllGlobalPostageBatches(requestOptions) {
20
+ const response = await (0, http_1.http)(requestOptions, {
21
+ method: 'get',
22
+ url: batchesEndpoint,
23
+ responseType: 'json',
24
+ });
25
+ return stamps_1.GetGlobalPostageBatchesResponse.parse(response.data).batches;
26
+ }
@@ -14,12 +14,7 @@ const type_1 = require("../utils/type");
14
14
  const typed_bytes_1 = require("../utils/typed-bytes");
15
15
  const endpoint = 'bytes';
16
16
  /**
17
- * Upload data to a Bee node
18
- *
19
- * @param requestOptions Options for making requests
20
- * @param data Data to be uploaded
21
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
22
- * @param options Additional options like tag, encryption, pinning
17
+ * Raw HTTP calls for the `/bytes` endpoint.
23
18
  */
24
19
  async function upload(requestOptions, data, postageBatchId, options) {
25
20
  const response = await (0, http_1.http)(requestOptions, {
@@ -41,14 +36,7 @@ async function upload(requestOptions, data, postageBatchId, options) {
41
36
  : cafe_utility_1.Optional.empty(),
42
37
  };
43
38
  }
44
- /**
45
- * Requests content length for a reference
46
- *
47
- * @param requestOptions Options for making requests
48
- * @param hash Bee content reference
49
- */
50
39
  async function head(requestOptions, reference) {
51
- reference = new typed_bytes_1.Reference(reference);
52
40
  const response = await (0, http_1.http)(requestOptions, {
53
41
  url: `${endpoint}/${reference}`,
54
42
  method: 'head',
@@ -58,12 +46,6 @@ async function head(requestOptions, reference) {
58
46
  contentLength: parseInt(response.headers['content-length']),
59
47
  };
60
48
  }
61
- /**
62
- * Download data as a byte array
63
- *
64
- * @param requestOptions Options for making requests
65
- * @param hash Bee content reference
66
- */
67
49
  async function download(requestOptions, resource, options) {
68
50
  if (options) {
69
51
  options = schema_1.DownloadOptionsSchema.parse(options);
@@ -75,12 +57,6 @@ async function download(requestOptions, resource, options) {
75
57
  });
76
58
  return new bytes_1.Bytes(response.data);
77
59
  }
78
- /**
79
- * Download data as a readable stream
80
- *
81
- * @param requestOptions Options for making requests
82
- * @param hash Bee content reference
83
- */
84
60
  async function downloadReadable(requestOptions, resource, options) {
85
61
  if (options) {
86
62
  options = schema_1.DownloadOptionsSchema.parse(options);
@@ -15,13 +15,7 @@ const type_1 = require("../utils/type");
15
15
  const typed_bytes_1 = require("../utils/typed-bytes");
16
16
  const bzzEndpoint = 'bzz';
17
17
  /**
18
- * Upload single file
19
- *
20
- * @param requestOptions Options for making requests
21
- * @param data Files data
22
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
23
- * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
24
- * @param options
18
+ * Raw HTTP calls for the `/bzz` endpoint.
25
19
  */
26
20
  async function uploadFile(requestOptions, data, postageBatchId, name, options) {
27
21
  if ((0, type_1.isReadable)(data) && !options?.contentType) {
@@ -47,13 +41,6 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
47
41
  : cafe_utility_1.Optional.empty(),
48
42
  };
49
43
  }
50
- /**
51
- * Download single file as a buffer
52
- *
53
- * @param requestOptions Options for making requests
54
- * @param hash Bee file or collection hash
55
- * @param path If hash is collection then this defines path to a single file in the collection
56
- */
57
44
  async function downloadFile(requestOptions, resource, path = '', options) {
58
45
  const response = await (0, http_1.http)(requestOptions, {
59
46
  method: 'GET',
@@ -67,13 +54,6 @@ async function downloadFile(requestOptions, resource, path = '', options) {
67
54
  };
68
55
  return file;
69
56
  }
70
- /**
71
- * Download single file as a readable stream
72
- *
73
- * @param requestOptions Options for making requests
74
- * @param hash Bee file or collection hash
75
- * @param path If hash is collection then this defines path to a single file in the collection
76
- */
77
57
  async function downloadFileReadable(requestOptions, reference, path = '', options) {
78
58
  reference = new typed_bytes_1.Reference(reference);
79
59
  const response = await (0, http_1.http)(requestOptions, {
@@ -90,13 +70,6 @@ async function downloadFileReadable(requestOptions, reference, path = '', option
90
70
  }
91
71
  /*******************************************************************************************************************/
92
72
  // Collections
93
- /**
94
- * Upload collection
95
- * @param requestOptions Options for making requests
96
- * @param collection Collection of Uint8Array buffers to upload
97
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
98
- * @param options
99
- */
100
73
  async function uploadCollection(requestOptions, collection, postageBatchId, options) {
101
74
  (0, collection_1.assertCollection)(collection);
102
75
  const response = await (0, tar_uploader_1.uploadTar)(requestOptions, collection, postageBatchId, options);
@@ -2,135 +2,96 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getChequebookAddress = getChequebookAddress;
4
4
  exports.getChequebookBalance = getChequebookBalance;
5
- exports.getLastCashoutAction = getLastCashoutAction;
6
- exports.cashoutLastCheque = cashoutLastCheque;
7
- exports.getLastChequesForPeer = getLastChequesForPeer;
8
- exports.getLastCheques = getLastCheques;
9
5
  exports.depositTokens = depositTokens;
10
6
  exports.withdrawTokens = withdrawTokens;
11
- const chequebook_1 = require("../../types/schema/chequebook");
12
- const headers_1 = require("../../utils/headers");
13
- const http_1 = require("../../utils/http");
7
+ exports.getLastCheques = getLastCheques;
8
+ exports.getLastChequesForPeer = getLastChequesForPeer;
9
+ exports.getLastCashoutAction = getLastCashoutAction;
10
+ exports.cashoutLastCheque = cashoutLastCheque;
11
+ const chequebook_1 = require("../types/schema/chequebook");
12
+ const headers_1 = require("../utils/headers");
13
+ const http_1 = require("../utils/http");
14
14
  const chequebookEndpoint = 'chequebook';
15
15
  /**
16
- * Get the address of the chequebook contract used
17
- *
18
- * @param requestOptions Options for making requests
16
+ * Raw HTTP calls for the `/chequebook` endpoint (chequebook + cheque operations).
19
17
  */
18
+ /** Gets the address of the deployed chequebook. */
20
19
  async function getChequebookAddress(requestOptions) {
21
20
  const response = await (0, http_1.http)(requestOptions, {
22
- url: chequebookEndpoint + '/address',
21
+ url: `${chequebookEndpoint}/address`,
23
22
  responseType: 'json',
24
23
  });
25
24
  return chequebook_1.GetChequebookAddressResponse.parse(response.data);
26
25
  }
27
- /**
28
- * Get the balance of the chequebook
29
- *
30
- * @param requestOptions Options for making requests
31
- */
26
+ /** Gets the balance of the chequebook. */
32
27
  async function getChequebookBalance(requestOptions) {
33
28
  const response = await (0, http_1.http)(requestOptions, {
34
- url: chequebookEndpoint + '/balance',
29
+ url: `${chequebookEndpoint}/balance`,
35
30
  responseType: 'json',
36
31
  });
37
32
  return chequebook_1.GetChequebookBalanceResponse.parse(response.data);
38
33
  }
39
- /**
40
- * Get last cashout action for the peer
41
- *
42
- * @param requestOptions Options for making requests
43
- * @param peer Swarm address of peer
44
- */
45
- async function getLastCashoutAction(requestOptions, peer) {
34
+ /** Deposits tokens from the node wallet into the chequebook. */
35
+ async function depositTokens(requestOptions, amount, gasPrice) {
36
+ const headers = {};
37
+ if (gasPrice) {
38
+ headers['gas-price'] = gasPrice;
39
+ }
46
40
  const response = await (0, http_1.http)(requestOptions, {
47
- url: chequebookEndpoint + `/cashout/${peer}`,
41
+ method: 'post',
42
+ url: `${chequebookEndpoint}/deposit`,
48
43
  responseType: 'json',
44
+ params: { amount },
45
+ headers,
49
46
  });
50
- return chequebook_1.GetLastCashoutActionResponse.parse(response.data);
47
+ return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
51
48
  }
52
- /**
53
- * Cashout the last cheque for the peer
54
- *
55
- * @param requestOptions Options for making requests
56
- * @param peer Swarm address of peer
57
- * @param options
58
- */
59
- async function cashoutLastCheque(requestOptions, peer, options) {
49
+ /** Withdraws tokens from the chequebook to the node wallet. */
50
+ async function withdrawTokens(requestOptions, amount, gasPrice) {
51
+ const headers = {};
52
+ if (gasPrice) {
53
+ headers['gas-price'] = gasPrice;
54
+ }
60
55
  const response = await (0, http_1.http)(requestOptions, {
61
56
  method: 'post',
62
- url: chequebookEndpoint + `/cashout/${peer}`,
57
+ url: `${chequebookEndpoint}/withdraw`,
63
58
  responseType: 'json',
64
- headers: (0, headers_1.prepareRequestHeaders)(null, options),
59
+ params: { amount },
60
+ headers,
65
61
  });
66
62
  return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
67
63
  }
68
- /**
69
- * Get last cheques for the peer
70
- *
71
- * @param requestOptions Options for making requests
72
- * @param peer Swarm address of peer
73
- */
74
- async function getLastChequesForPeer(requestOptions, peer) {
64
+ /** Gets the last cheques for all peers. */
65
+ async function getLastCheques(requestOptions) {
75
66
  const response = await (0, http_1.http)(requestOptions, {
76
- url: chequebookEndpoint + `/cheque/${peer}`,
67
+ url: `${chequebookEndpoint}/cheque`,
77
68
  responseType: 'json',
78
69
  });
79
- return chequebook_1.GetLastChequesForPeerResponse.parse(response.data);
70
+ return chequebook_1.GetLastChequesResponse.parse(response.data);
80
71
  }
81
- /**
82
- * Get last cheques for all peers
83
- *
84
- * @param requestOptions Options for making requests
85
- */
86
- async function getLastCheques(requestOptions) {
72
+ /** Gets the last cheques for a specific peer. */
73
+ async function getLastChequesForPeer(requestOptions, peer) {
87
74
  const response = await (0, http_1.http)(requestOptions, {
88
- url: chequebookEndpoint + '/cheque',
75
+ url: `${chequebookEndpoint}/cheque/${peer}`,
89
76
  responseType: 'json',
90
77
  });
91
- return chequebook_1.GetLastChequesResponse.parse(response.data);
78
+ return chequebook_1.GetLastChequesForPeerResponse.parse(response.data);
92
79
  }
93
- /**
94
- * Deposit tokens from overlay address into chequebook
95
- *
96
- * @param requestOptions Options for making requests
97
- * @param amount Amount of tokens to deposit
98
- * @param gasPrice Gas Price in WEI for the transaction call
99
- * @return string Hash of the transaction
100
- */
101
- async function depositTokens(requestOptions, amount, gasPrice) {
102
- const headers = {};
103
- if (gasPrice) {
104
- headers['gas-price'] = gasPrice.toString();
105
- }
80
+ /** Gets the last cashout action for a specific peer. */
81
+ async function getLastCashoutAction(requestOptions, peer) {
106
82
  const response = await (0, http_1.http)(requestOptions, {
107
- method: 'post',
108
- url: chequebookEndpoint + '/deposit',
83
+ url: `${chequebookEndpoint}/cashout/${peer}`,
109
84
  responseType: 'json',
110
- params: { amount: amount.toString(10) },
111
- headers,
112
85
  });
113
- return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
86
+ return chequebook_1.GetLastCashoutActionResponse.parse(response.data);
114
87
  }
115
- /**
116
- * Withdraw tokens from the chequebook to the overlay address
117
- *
118
- * @param requestOptions Options for making requests
119
- * @param amount Amount of tokens to withdraw
120
- * @param gasPrice Gas Price in WEI for the transaction call
121
- * @return string Hash of the transaction
122
- */
123
- async function withdrawTokens(requestOptions, amount, gasPrice) {
124
- const headers = {};
125
- if (gasPrice) {
126
- headers['gas-price'] = gasPrice.toString();
127
- }
88
+ /** Cashes out the last cheque for a specific peer. */
89
+ async function cashoutLastCheque(requestOptions, peer, options) {
128
90
  const response = await (0, http_1.http)(requestOptions, {
129
91
  method: 'post',
130
- url: chequebookEndpoint + '/withdraw',
92
+ url: `${chequebookEndpoint}/cashout/${peer}`,
131
93
  responseType: 'json',
132
- params: { amount: amount.toString(10) },
133
- headers,
94
+ headers: (0, headers_1.prepareRequestHeaders)(null, options),
134
95
  });
135
96
  return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
136
97
  }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upload = upload;
4
+ exports.download = download;
5
+ const cafe_utility_1 = require("cafe-utility");
6
+ const upload_1 = require("../types/schema/upload");
7
+ const headers_1 = require("../utils/headers");
8
+ const http_1 = require("../utils/http");
9
+ const type_1 = require("../utils/type");
10
+ const typed_bytes_1 = require("../utils/typed-bytes");
11
+ const endpoint = 'chunks';
12
+ /**
13
+ * Raw HTTP calls for the `/chunks` endpoint.
14
+ */
15
+ async function upload(requestOptions, data, stamp, options) {
16
+ const response = await (0, http_1.http)(requestOptions, {
17
+ method: 'post',
18
+ url: `${endpoint}`,
19
+ data,
20
+ headers: {
21
+ 'content-type': 'application/octet-stream',
22
+ ...(0, headers_1.prepareRequestHeaders)(stamp, options),
23
+ },
24
+ responseType: 'json',
25
+ });
26
+ const body = upload_1.UploadResultBody.parse(response.data);
27
+ return {
28
+ reference: body.reference,
29
+ tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
30
+ historyAddress: response.headers['swarm-act-history-address']
31
+ ? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
32
+ : cafe_utility_1.Optional.empty(),
33
+ };
34
+ }
35
+ async function download(requestOptions, reference, options) {
36
+ reference = new typed_bytes_1.Reference(reference);
37
+ const response = await (0, http_1.http)(requestOptions, {
38
+ responseType: 'arraybuffer',
39
+ url: `${endpoint}/${reference}`,
40
+ headers: (0, headers_1.prepareRequestHeaders)(null, options),
41
+ });
42
+ return new Uint8Array(response.data);
43
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkConnection = checkConnection;
4
+ exports.isGateway = isGateway;
5
+ exports.getNodeAddresses = getNodeAddresses;
6
+ exports.getBlocklist = getBlocklist;
7
+ exports.getPeers = getPeers;
8
+ exports.removePeer = removePeer;
9
+ exports.getTopology = getTopology;
10
+ exports.ping = ping;
11
+ const connectivity_1 = require("../types/schema/connectivity");
12
+ const status_1 = require("../types/schema/status");
13
+ const http_1 = require("../utils/http");
14
+ const addressesEndpoint = 'addresses';
15
+ const blocklistEndpoint = 'blocklist';
16
+ const peersEndpoint = 'peers';
17
+ const topologyEndpoint = 'topology';
18
+ const pingpongEndpoint = 'pingpong';
19
+ const gatewayEndpoint = '/gateway';
20
+ /**
21
+ * Raw HTTP calls for the connectivity endpoints (`/addresses`, `/peers`, `/topology`, `/blocklist`, `/pingpong`, etc.).
22
+ */
23
+ /** Pings the Bee node to see if there is a live Bee node on the given URL. */
24
+ async function checkConnection(requestOptions) {
25
+ await (0, http_1.http)(requestOptions, {
26
+ url: '',
27
+ responseType: 'text',
28
+ });
29
+ }
30
+ /** Checks the `/gateway` endpoint to see if the remote API is a gateway. */
31
+ async function isGateway(requestOptions) {
32
+ const response = await (0, http_1.http)(requestOptions, {
33
+ url: gatewayEndpoint,
34
+ });
35
+ return status_1.IsGatewayResponse.parse(response.data).gateway;
36
+ }
37
+ /** Fetches the overlay, underlay, Ethereum, and other addresses of the Bee node. */
38
+ async function getNodeAddresses(requestOptions) {
39
+ const response = await (0, http_1.http)(requestOptions, {
40
+ url: addressesEndpoint,
41
+ responseType: 'json',
42
+ });
43
+ return connectivity_1.GetNodeAddressesResponse.parse(response.data);
44
+ }
45
+ /** Fetches the list of blocked peers for this node. */
46
+ async function getBlocklist(requestOptions) {
47
+ const response = await (0, http_1.http)(requestOptions, {
48
+ url: blocklistEndpoint,
49
+ responseType: 'json',
50
+ });
51
+ return connectivity_1.GetBlocklistResponse.parse(response.data).peers;
52
+ }
53
+ /** Gets list of peers for this node. */
54
+ async function getPeers(requestOptions) {
55
+ const response = await (0, http_1.http)(requestOptions, {
56
+ url: peersEndpoint,
57
+ responseType: 'json',
58
+ });
59
+ return connectivity_1.GetPeersResponse.parse(response.data).peers;
60
+ }
61
+ /** Disconnects from a specific peer. */
62
+ async function removePeer(requestOptions, peer) {
63
+ const response = await (0, http_1.http)(requestOptions, {
64
+ url: `${peersEndpoint}/${peer}`,
65
+ responseType: 'json',
66
+ method: 'DELETE',
67
+ });
68
+ return response.data;
69
+ }
70
+ /** Fetches topology and connectivity information of the Bee node. */
71
+ async function getTopology(requestOptions) {
72
+ const response = await (0, http_1.http)(requestOptions, {
73
+ url: topologyEndpoint,
74
+ responseType: 'json',
75
+ });
76
+ return connectivity_1.GetTopologyResponse.parse(response.data);
77
+ }
78
+ /** Pings a specific peer to check its availability. */
79
+ async function ping(requestOptions, peer) {
80
+ const response = await (0, http_1.http)(requestOptions, {
81
+ url: `${pingpongEndpoint}/${peer}`,
82
+ responseType: 'json',
83
+ method: 'POST',
84
+ });
85
+ return response.data;
86
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
4
+ exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
5
+ const balance_1 = require("../types/schema/balance");
6
+ const http_1 = require("../utils/http");
7
+ const consumedEndpoint = 'consumed';
8
+ /**
9
+ * Raw HTTP calls for the `/consumed` endpoint.
10
+ */
11
+ async function getPastDueConsumptionBalances(requestOptions) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ url: consumedEndpoint,
14
+ responseType: 'json',
15
+ });
16
+ return balance_1.GetAllBalancesResponse.parse(response.data);
17
+ }
18
+ async function getPastDueConsumptionPeerBalance(requestOptions, peer) {
19
+ const response = await (0, http_1.http)(requestOptions, {
20
+ url: `${consumedEndpoint}/${peer}`,
21
+ responseType: 'json',
22
+ });
23
+ return balance_1.GetPeerBalanceResponse.parse(response.data);
24
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFeedManifest = createFeedManifest;
4
+ exports.fetchLatestFeedUpdate = fetchLatestFeedUpdate;
5
+ exports.probeFeed = probeFeed;
6
+ const upload_1 = require("../types/schema/upload");
7
+ const bytes_1 = require("../utils/bytes");
8
+ const error_1 = require("../utils/error");
9
+ const headers_1 = require("../utils/headers");
10
+ const http_1 = require("../utils/http");
11
+ const typed_bytes_1 = require("../utils/typed-bytes");
12
+ const feedEndpoint = 'feeds';
13
+ async function createFeedManifest(requestOptions, owner, topic, stamp, options) {
14
+ const response = await (0, http_1.http)(requestOptions, {
15
+ method: 'post',
16
+ responseType: 'json',
17
+ url: `${feedEndpoint}/${owner}/${topic}`,
18
+ headers: (0, headers_1.prepareRequestHeaders)(stamp, options),
19
+ });
20
+ return upload_1.UploadResultBody.parse(response.data).reference;
21
+ }
22
+ function readFeedUpdateHeaders(headers) {
23
+ const feedIndex = headers['swarm-feed-index'];
24
+ const feedIndexNext = headers['swarm-feed-index-next'];
25
+ if (!feedIndex) {
26
+ throw new error_1.BeeError('Response did not contain expected swarm-feed-index!');
27
+ }
28
+ if (!feedIndexNext) {
29
+ throw new error_1.BeeError('Response did not contain expected swarm-feed-index-next!');
30
+ }
31
+ return {
32
+ feedIndex: new typed_bytes_1.FeedIndex(feedIndex),
33
+ feedIndexNext: new typed_bytes_1.FeedIndex(feedIndexNext),
34
+ };
35
+ }
36
+ async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
37
+ const response = await (0, http_1.http)(requestOptions, {
38
+ responseType: 'arraybuffer',
39
+ url: `${feedEndpoint}/${owner}/${topic}`,
40
+ params: { ...options },
41
+ });
42
+ return {
43
+ payload: new bytes_1.Bytes(response.data),
44
+ ...readFeedUpdateHeaders(response.headers),
45
+ };
46
+ }
47
+ async function probeFeed(requestOptions, owner, topic) {
48
+ const response = await (0, http_1.http)(requestOptions, {
49
+ responseType: 'arraybuffer',
50
+ url: `${feedEndpoint}/${owner}/${topic}`,
51
+ params: {
52
+ 'Swarm-Only-Root-Chunk': true,
53
+ },
54
+ });
55
+ return readFeedUpdateHeaders(response.headers);
56
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createGrantees = createGrantees;
4
+ exports.getGrantees = getGrantees;
5
+ exports.patchGrantees = patchGrantees;
6
+ const grantee_1 = require("../types/schema/grantee");
7
+ const headers_1 = require("../utils/headers");
8
+ const http_1 = require("../utils/http");
9
+ const granteeEndpoint = 'grantee';
10
+ /** Creates grantees for a postage batch. */
11
+ async function createGrantees(requestOptions, batchId, publicKeys) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ method: 'post',
14
+ url: granteeEndpoint,
15
+ data: { grantees: publicKeys.map(x => x.toCompressedHex()) },
16
+ headers: (0, headers_1.prepareRequestHeaders)(batchId),
17
+ responseType: 'json',
18
+ });
19
+ const body = grantee_1.GranteesResultBodyResponse.parse(response.data);
20
+ return {
21
+ status: response.status,
22
+ statusText: response.statusText,
23
+ ref: body.ref,
24
+ historyref: body.historyref,
25
+ };
26
+ }
27
+ /** Retrieves the grantees for a given reference. */
28
+ async function getGrantees(requestOptions, reference) {
29
+ const response = await (0, http_1.http)(requestOptions, {
30
+ method: 'get',
31
+ url: `${granteeEndpoint}/${reference}`,
32
+ responseType: 'json',
33
+ });
34
+ return {
35
+ status: response.status,
36
+ statusText: response.statusText,
37
+ grantees: grantee_1.GetGranteesBodyResponse.parse(response.data),
38
+ };
39
+ }
40
+ /** Updates the grantees of a specific reference and history. */
41
+ async function patchGrantees(requestOptions, batchId, reference, history, publicKeys) {
42
+ const response = await (0, http_1.http)(requestOptions, {
43
+ method: 'patch',
44
+ url: `${granteeEndpoint}/${reference}`,
45
+ data: {
46
+ add: publicKeys.add.map(x => x.toCompressedHex()),
47
+ revoke: publicKeys.revoke.map(x => x.toCompressedHex()),
48
+ },
49
+ headers: {
50
+ ...(0, headers_1.prepareRequestHeaders)(batchId),
51
+ 'swarm-act-history-address': history.toHex(),
52
+ },
53
+ responseType: 'json',
54
+ });
55
+ const body = grantee_1.GranteesResultBodyResponse.parse(response.data);
56
+ return {
57
+ status: response.status,
58
+ statusText: response.statusText,
59
+ ref: body.ref,
60
+ historyref: body.historyref,
61
+ };
62
+ }