@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.
Files changed (137) hide show
  1. package/dist/cjs/bee.js +56 -23
  2. package/dist/cjs/chunk/cac.js +4 -2
  3. package/dist/cjs/feed/index.js +3 -1
  4. package/dist/cjs/modules/bytes.js +6 -4
  5. package/dist/cjs/modules/bzz.js +5 -4
  6. package/dist/cjs/modules/chunk.js +3 -2
  7. package/dist/cjs/modules/debug/balance.js +5 -29
  8. package/dist/cjs/modules/debug/chequebook.js +9 -58
  9. package/dist/cjs/modules/debug/connectivity.js +5 -82
  10. package/dist/cjs/modules/debug/settlements.js +3 -22
  11. package/dist/cjs/modules/debug/stake.js +8 -33
  12. package/dist/cjs/modules/debug/stamps.js +27 -53
  13. package/dist/cjs/modules/debug/states.js +6 -31
  14. package/dist/cjs/modules/debug/status.js +5 -37
  15. package/dist/cjs/modules/debug/transactions.js +5 -26
  16. package/dist/cjs/modules/envelope.js +6 -6
  17. package/dist/cjs/modules/feed.js +3 -4
  18. package/dist/cjs/modules/grantee.js +8 -10
  19. package/dist/cjs/modules/pinning.js +5 -11
  20. package/dist/cjs/modules/rchash.js +2 -3
  21. package/dist/cjs/modules/soc.js +3 -2
  22. package/dist/cjs/modules/status.js +3 -3
  23. package/dist/cjs/modules/stewardship.js +2 -3
  24. package/dist/cjs/modules/tag.js +4 -35
  25. package/dist/cjs/stamper/stamper.js +2 -1
  26. package/dist/cjs/types/schema/balance.js +14 -0
  27. package/dist/cjs/types/schema/chequebook.js +49 -0
  28. package/dist/cjs/types/schema/connectivity.js +46 -0
  29. package/dist/cjs/types/schema/envelope.js +11 -0
  30. package/dist/cjs/types/schema/grantee.js +10 -0
  31. package/dist/cjs/types/schema/pinning.js +7 -0
  32. package/dist/cjs/types/schema/rchash.js +7 -0
  33. package/dist/cjs/types/schema/settlements.js +17 -0
  34. package/dist/cjs/types/schema/stake.js +33 -0
  35. package/dist/cjs/types/schema/stamps.js +48 -0
  36. package/dist/cjs/types/schema/states.js +34 -0
  37. package/dist/cjs/types/schema/status.js +39 -0
  38. package/dist/cjs/types/schema/stewardship.js +7 -0
  39. package/dist/cjs/types/schema/tag.js +20 -0
  40. package/dist/cjs/types/schema/transactions.js +24 -0
  41. package/dist/cjs/types/schema/upload.js +8 -0
  42. package/dist/cjs/utils/bad-ports.js +92 -0
  43. package/dist/cjs/utils/bytes.js +5 -3
  44. package/dist/cjs/utils/error.js +1 -0
  45. package/dist/cjs/utils/headers.js +19 -13
  46. package/dist/cjs/utils/hex-schema.js +8 -0
  47. package/dist/cjs/utils/http.js +92 -52
  48. package/dist/cjs/utils/resource-locator.js +4 -3
  49. package/dist/cjs/utils/schema.js +88 -0
  50. package/dist/cjs/utils/stamps.js +2 -1
  51. package/dist/cjs/utils/type.js +12 -130
  52. package/dist/cjs/utils/url.js +24 -0
  53. package/dist/index.browser.min.js +1 -1
  54. package/dist/index.browser.min.js.map +1 -1
  55. package/dist/mjs/bee.js +59 -30
  56. package/dist/mjs/chunk/cac.js +5 -3
  57. package/dist/mjs/feed/index.js +4 -2
  58. package/dist/mjs/modules/bytes.js +8 -8
  59. package/dist/mjs/modules/bzz.js +6 -9
  60. package/dist/mjs/modules/chunk.js +4 -7
  61. package/dist/mjs/modules/debug/balance.js +5 -61
  62. package/dist/mjs/modules/debug/chequebook.js +9 -114
  63. package/dist/mjs/modules/debug/connectivity.js +5 -145
  64. package/dist/mjs/modules/debug/settlements.js +3 -46
  65. package/dist/mjs/modules/debug/stake.js +8 -85
  66. package/dist/mjs/modules/debug/stamps.js +24 -126
  67. package/dist/mjs/modules/debug/states.js +6 -71
  68. package/dist/mjs/modules/debug/status.js +5 -91
  69. package/dist/mjs/modules/debug/transactions.js +5 -60
  70. package/dist/mjs/modules/envelope.js +6 -20
  71. package/dist/mjs/modules/feed.js +6 -7
  72. package/dist/mjs/modules/grantee.js +8 -26
  73. package/dist/mjs/modules/pinning.js +7 -21
  74. package/dist/mjs/modules/rchash.js +2 -7
  75. package/dist/mjs/modules/soc.js +4 -5
  76. package/dist/mjs/modules/status.js +4 -4
  77. package/dist/mjs/modules/stewardship.js +2 -7
  78. package/dist/mjs/modules/tag.js +4 -93
  79. package/dist/mjs/stamper/stamper.js +2 -1
  80. package/dist/mjs/types/schema/balance.js +13 -0
  81. package/dist/mjs/types/schema/chequebook.js +53 -0
  82. package/dist/mjs/types/schema/connectivity.js +41 -0
  83. package/dist/mjs/types/schema/envelope.js +8 -0
  84. package/dist/mjs/types/schema/grantee.js +7 -0
  85. package/dist/mjs/types/schema/pinning.js +4 -0
  86. package/dist/mjs/types/schema/rchash.js +4 -0
  87. package/dist/mjs/types/schema/settlements.js +22 -0
  88. package/dist/mjs/types/schema/stake.js +40 -0
  89. package/dist/mjs/types/schema/stamps.js +47 -0
  90. package/dist/mjs/types/schema/states.js +34 -0
  91. package/dist/mjs/types/schema/status.js +36 -0
  92. package/dist/mjs/types/schema/stewardship.js +4 -0
  93. package/dist/mjs/types/schema/tag.js +14 -0
  94. package/dist/mjs/types/schema/transactions.js +25 -0
  95. package/dist/mjs/types/schema/upload.js +5 -0
  96. package/dist/mjs/utils/bad-ports.js +6 -0
  97. package/dist/mjs/utils/bytes.js +6 -8
  98. package/dist/mjs/utils/error.js +5 -0
  99. package/dist/mjs/utils/headers.js +19 -13
  100. package/dist/mjs/utils/hex-schema.js +2 -0
  101. package/dist/mjs/utils/http.js +97 -59
  102. package/dist/mjs/utils/resource-locator.js +4 -3
  103. package/dist/mjs/utils/schema.js +81 -0
  104. package/dist/mjs/utils/stamps.js +2 -1
  105. package/dist/mjs/utils/type.js +13 -233
  106. package/dist/mjs/utils/url.js +23 -0
  107. package/dist/types/bee.d.ts +23 -0
  108. package/dist/types/modules/debug/connectivity.d.ts +2 -2
  109. package/dist/types/modules/debug/stamps.d.ts +2 -0
  110. package/dist/types/types/debug.d.ts +1 -0
  111. package/dist/types/types/schema/balance.d.ts +12 -0
  112. package/dist/types/types/schema/chequebook.d.ts +104 -0
  113. package/dist/types/types/schema/connectivity.d.ts +49 -0
  114. package/dist/types/types/schema/envelope.d.ts +7 -0
  115. package/dist/types/types/schema/grantee.d.ts +7 -0
  116. package/dist/types/types/schema/pinning.d.ts +4 -0
  117. package/dist/types/types/schema/rchash.d.ts +4 -0
  118. package/dist/types/types/schema/settlements.d.ts +16 -0
  119. package/dist/types/types/schema/stake.d.ts +29 -0
  120. package/dist/types/types/schema/stamps.d.ts +77 -0
  121. package/dist/types/types/schema/states.d.ts +26 -0
  122. package/dist/types/types/schema/status.d.ts +38 -0
  123. package/dist/types/types/schema/stewardship.d.ts +4 -0
  124. package/dist/types/types/schema/tag.d.ts +23 -0
  125. package/dist/types/types/schema/transactions.d.ts +29 -0
  126. package/dist/types/types/schema/upload.d.ts +5 -0
  127. package/dist/types/utils/bad-ports.d.ts +6 -0
  128. package/dist/types/utils/error.d.ts +5 -0
  129. package/dist/types/utils/hex-schema.d.ts +2 -0
  130. package/dist/types/utils/http.d.ts +18 -3
  131. package/dist/types/utils/schema.d.ts +90 -0
  132. package/dist/types/utils/stamps.d.ts +1 -0
  133. package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
  134. package/dist/types/utils/tar-uploader.d.ts +1 -1
  135. package/dist/types/utils/type.d.ts +1 -16
  136. package/dist/types/utils/url.d.ts +9 -0
  137. package/package.json +9 -9
@@ -1,8 +1,6 @@
1
- import { Types } from 'cafe-utility';
1
+ import { BatchIdResponse, GetAllPostageBatchesResponse, GetGlobalPostageBatchesResponse, GetGlobalPostageBatchResponse, GetPostageBatchBucketsResponse, GetPostageBatchResponse } from "../../types/schema/stamps.js";
2
2
  import { http } from "../../utils/http.js";
3
3
  import { mapPostageBatch } from "../../utils/stamps.js";
4
- import { asNumberString } from "../../utils/type.js";
5
- import { BatchId, EthAddress } from "../../utils/typed-bytes.js";
6
4
  const STAMPS_ENDPOINT = 'stamps';
7
5
  const BATCHES_ENDPOINT = 'batches';
8
6
  export async function getGlobalPostageBatches(requestOptions) {
@@ -11,40 +9,15 @@ export async function getGlobalPostageBatches(requestOptions) {
11
9
  url: `${BATCHES_ENDPOINT}`,
12
10
  responseType: 'json'
13
11
  });
14
- const body = Types.asObject(response.data, {
15
- name: 'response.data'
12
+ return GetGlobalPostageBatchesResponse.parse(response.data).batches;
13
+ }
14
+ export async function getGlobalPostageBatch(requestOptions, postageBatchId) {
15
+ const response = await http(requestOptions, {
16
+ method: 'get',
17
+ url: `${BATCHES_ENDPOINT}/${postageBatchId}`,
18
+ responseType: 'json'
16
19
  });
17
- const batches = Types.asArray(body.batches, {
18
- name: 'batches'
19
- }).map(x => Types.asObject(x, {
20
- name: 'batch'
21
- }));
22
- return batches.map(x => ({
23
- batchID: new BatchId(Types.asString(x.batchID, {
24
- name: 'batchID'
25
- })),
26
- batchTTL: Types.asNumber(x.batchTTL, {
27
- name: 'batchTTL'
28
- }),
29
- bucketDepth: Types.asNumber(x.bucketDepth, {
30
- name: 'bucketDepth'
31
- }),
32
- depth: Types.asNumber(x.depth, {
33
- name: 'depth'
34
- }),
35
- immutable: Types.asBoolean(x.immutable, {
36
- name: 'immutable'
37
- }),
38
- owner: new EthAddress(Types.asString(x.owner, {
39
- name: 'owner'
40
- })),
41
- start: Types.asNumber(x.start, {
42
- name: 'start'
43
- }),
44
- value: asNumberString(x.value, {
45
- name: 'value'
46
- })
47
- }));
20
+ return GetGlobalPostageBatchResponse.parse(response.data);
48
21
  }
49
22
  export async function getAllPostageBatches(requestOptions) {
50
23
  const response = await http(requestOptions, {
@@ -52,15 +25,7 @@ export async function getAllPostageBatches(requestOptions) {
52
25
  url: `${STAMPS_ENDPOINT}`,
53
26
  responseType: 'json'
54
27
  });
55
- const body = Types.asObject(response.data, {
56
- name: 'response.data'
57
- });
58
- const stamps = Types.asArray(body.stamps, {
59
- name: 'stamps'
60
- }).map(x => Types.asObject(x, {
61
- name: 'stamp'
62
- }));
63
- return stamps.map(x => mapPostageBatch(validateRawPostageBatch(x)));
28
+ return GetAllPostageBatchesResponse.parse(response.data).stamps.map(x => mapPostageBatch(x));
64
29
  }
65
30
  export async function getPostageBatch(requestOptions, postageBatchId, encryption, erasureCodeLevel) {
66
31
  const response = await http(requestOptions, {
@@ -68,10 +33,7 @@ export async function getPostageBatch(requestOptions, postageBatchId, encryption
68
33
  url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
69
34
  responseType: 'json'
70
35
  });
71
- const body = Types.asObject(response.data, {
72
- name: 'response.data'
73
- });
74
- return mapPostageBatch(validateRawPostageBatch(body), encryption, erasureCodeLevel);
36
+ return mapPostageBatch(GetPostageBatchResponse.parse(response.data), encryption, erasureCodeLevel);
75
37
  }
76
38
  export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
77
39
  const response = await http(requestOptions, {
@@ -79,32 +41,7 @@ export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
79
41
  url: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
80
42
  responseType: 'json'
81
43
  });
82
- const body = Types.asObject(response.data, {
83
- name: 'response.data'
84
- });
85
- return {
86
- depth: Types.asNumber(body.depth, {
87
- name: 'depth'
88
- }),
89
- bucketDepth: Types.asNumber(body.bucketDepth, {
90
- name: 'bucketDepth'
91
- }),
92
- bucketUpperBound: Types.asNumber(body.bucketUpperBound, {
93
- name: 'bucketUpperBound'
94
- }),
95
- buckets: Types.asArray(body.buckets, {
96
- name: 'buckets'
97
- }).map(x => Types.asObject(x, {
98
- name: 'bucket'
99
- })).map(x => ({
100
- bucketID: Types.asNumber(x.bucketID, {
101
- name: 'bucketID'
102
- }),
103
- collisions: Types.asNumber(x.collisions, {
104
- name: 'collisions'
105
- })
106
- }))
107
- };
44
+ return GetPostageBatchBucketsResponse.parse(response.data);
108
45
  }
109
46
  export async function createPostageBatch(requestOptions, amount, depth, options) {
110
47
  const headers = {};
@@ -123,12 +60,17 @@ export async function createPostageBatch(requestOptions, amount, depth, options)
123
60
  },
124
61
  headers
125
62
  });
126
- const body = Types.asObject(response.data, {
127
- name: 'response.data'
63
+ return BatchIdResponse.parse(response.data).batchID;
64
+ }
65
+ export async function updatePostageBatchLabel(requestOptions, id, label) {
66
+ await http(requestOptions, {
67
+ method: 'patch',
68
+ url: `${STAMPS_ENDPOINT}/${id}`,
69
+ responseType: 'json',
70
+ data: {
71
+ label
72
+ }
128
73
  });
129
- return new BatchId(Types.asString(body.batchID, {
130
- name: 'batchID'
131
- }));
132
74
  }
133
75
  export async function topUpBatch(requestOptions, id, amount) {
134
76
  const response = await http(requestOptions, {
@@ -136,12 +78,7 @@ export async function topUpBatch(requestOptions, id, amount) {
136
78
  url: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
137
79
  responseType: 'json'
138
80
  });
139
- const body = Types.asObject(response.data, {
140
- name: 'response.data'
141
- });
142
- return new BatchId(Types.asString(body.batchID, {
143
- name: 'batchID'
144
- }));
81
+ return BatchIdResponse.parse(response.data).batchID;
145
82
  }
146
83
  export async function diluteBatch(requestOptions, id, depth) {
147
84
  const response = await http(requestOptions, {
@@ -149,44 +86,5 @@ export async function diluteBatch(requestOptions, id, depth) {
149
86
  url: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
150
87
  responseType: 'json'
151
88
  });
152
- const body = Types.asObject(response.data, {
153
- name: 'response.data'
154
- });
155
- return new BatchId(Types.asString(body.batchID, {
156
- name: 'batchID'
157
- }));
158
- }
159
- function validateRawPostageBatch(raw) {
160
- return {
161
- amount: asNumberString(raw.amount, {
162
- name: 'amount'
163
- }),
164
- batchID: Types.asString(raw.batchID, {
165
- name: 'batchID'
166
- }),
167
- batchTTL: Types.asNumber(raw.batchTTL, {
168
- name: 'batchTTL'
169
- }),
170
- bucketDepth: Types.asNumber(raw.bucketDepth, {
171
- name: 'bucketDepth'
172
- }),
173
- blockNumber: Types.asNumber(raw.blockNumber, {
174
- name: 'blockNumber'
175
- }),
176
- depth: Types.asNumber(raw.depth, {
177
- name: 'depth'
178
- }),
179
- immutableFlag: Types.asBoolean(raw.immutableFlag, {
180
- name: 'immutableFlag'
181
- }),
182
- label: Types.asEmptiableString(raw.label, {
183
- name: 'label'
184
- }),
185
- usable: Types.asBoolean(raw.usable, {
186
- name: 'usable'
187
- }),
188
- utilization: Types.asNumber(raw.utilization, {
189
- name: 'utilization'
190
- })
191
- };
89
+ return BatchIdResponse.parse(response.data).batchID;
192
90
  }
@@ -1,9 +1,5 @@
1
- import { Types } from 'cafe-utility';
1
+ import { GetChainStateResponse, GetReserveStateResponse, GetWalletBalanceResponse, WithdrawResponse } from "../../types/schema/states.js";
2
2
  import { http } from "../../utils/http.js";
3
- import { BZZ, DAI } from "../../utils/tokens.js";
4
- import { asNumberString } from "../../utils/type.js";
5
- import { TransactionId } from "../../utils/typed-bytes.js";
6
- import { normalizeCurrentPrice } from "../../utils/workaround.js";
7
3
  const RESERVE_STATE_ENDPOINT = 'reservestate';
8
4
  const WALLET_ENDPOINT = 'wallet';
9
5
  const CHAIN_STATE_ENDPOINT = 'chainstate';
@@ -18,23 +14,7 @@ export async function getReserveState(requestOptions) {
18
14
  url: `${RESERVE_STATE_ENDPOINT}`,
19
15
  responseType: 'json'
20
16
  });
21
- const body = Types.asObject(response.data, {
22
- name: 'response.data'
23
- });
24
- return {
25
- commitment: Types.asNumber(body.commitment, {
26
- name: 'commitment'
27
- }),
28
- radius: Types.asNumber(body.radius, {
29
- name: 'radius'
30
- }),
31
- storageRadius: Types.asNumber(body.storageRadius, {
32
- name: 'storageRadius'
33
- }),
34
- reserveCapacityDoubling: Types.asNumber(body.reserveCapacityDoubling, {
35
- name: 'reserveCapacityDoubling'
36
- })
37
- };
17
+ return GetReserveStateResponse.parse(response.data);
38
18
  }
39
19
  /**
40
20
  * Get state of reserve
@@ -47,23 +27,7 @@ export async function getChainState(requestOptions) {
47
27
  url: `${CHAIN_STATE_ENDPOINT}`,
48
28
  responseType: 'json'
49
29
  });
50
- const body = Types.asObject(response.data, {
51
- name: 'response.data'
52
- });
53
- return {
54
- block: Types.asNumber(body.block, {
55
- name: 'block'
56
- }),
57
- chainTip: Types.asNumber(body.chainTip, {
58
- name: 'chainTip'
59
- }),
60
- totalAmount: asNumberString(body.totalAmount, {
61
- name: 'totalAmount'
62
- }),
63
- currentPrice: normalizeCurrentPrice(Types.asNumber(body.currentPrice, {
64
- name: 'currentPrice'
65
- }))
66
- };
30
+ return GetChainStateResponse.parse(response.data);
67
31
  }
68
32
  /**
69
33
  * Get wallet balances for xDai and BZZ of the node
@@ -76,26 +40,7 @@ export async function getWalletBalance(requestOptions) {
76
40
  url: `${WALLET_ENDPOINT}`,
77
41
  responseType: 'json'
78
42
  });
79
- const body = Types.asObject(response.data, {
80
- name: 'response.data'
81
- });
82
- return {
83
- bzzBalance: BZZ.fromPLUR(asNumberString(body.bzzBalance, {
84
- name: 'bzzBalance'
85
- })),
86
- nativeTokenBalance: DAI.fromWei(asNumberString(body.nativeTokenBalance, {
87
- name: 'nativeTokenBalance'
88
- })),
89
- chainID: Types.asNumber(body.chainID, {
90
- name: 'chainID'
91
- }),
92
- chequebookContractAddress: Types.asString(body.chequebookContractAddress, {
93
- name: 'chequebookContractAddress'
94
- }),
95
- walletAddress: Types.asString(body.walletAddress, {
96
- name: 'walletAddress'
97
- })
98
- };
43
+ return GetWalletBalanceResponse.parse(response.data);
99
44
  }
100
45
  export async function withdrawBZZ(requestOptions, amount, address) {
101
46
  const response = await http(requestOptions, {
@@ -107,12 +52,7 @@ export async function withdrawBZZ(requestOptions, amount, address) {
107
52
  address: address.toHex()
108
53
  }
109
54
  });
110
- const body = Types.asObject(response.data, {
111
- name: 'response.data'
112
- });
113
- return new TransactionId(Types.asString(body.transactionHash, {
114
- name: 'transactionHash'
115
- }));
55
+ return WithdrawResponse.parse(response.data).transactionHash;
116
56
  }
117
57
  export async function withdrawDAI(requestOptions, amount, address) {
118
58
  const response = await http(requestOptions, {
@@ -124,10 +64,5 @@ export async function withdrawDAI(requestOptions, amount, address) {
124
64
  address: address.toHex()
125
65
  }
126
66
  });
127
- const body = Types.asObject(response.data, {
128
- name: 'response.data'
129
- });
130
- return new TransactionId(Types.asString(body.transactionHash, {
131
- name: 'transactionHash'
132
- }));
67
+ return WithdrawResponse.parse(response.data).transactionHash;
133
68
  }
@@ -1,6 +1,5 @@
1
- import { Types } from 'cafe-utility';
2
1
  import getMajorSemver from 'semver/functions/major.js';
3
- import { toBeeMode } from "../../types/debug.js";
2
+ import { GetDebugStatusResponse, GetHealthResponse, GetNodeInfoResponse, GetReadinessResponse } from "../../types/schema/status.js";
4
3
  import { http } from "../../utils/http.js";
5
4
  export const SUPPORTED_BEE_VERSION_EXACT = '2.7.0-6ddf9b45';
6
5
  export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
@@ -15,53 +14,7 @@ export async function getDebugStatus(requestOptions) {
15
14
  url: STATUS_URL,
16
15
  responseType: 'json'
17
16
  });
18
- const body = Types.asObject(response.data, {
19
- name: 'response.data'
20
- });
21
- return {
22
- overlay: Types.asString(body.overlay, {
23
- name: 'overlay'
24
- }),
25
- proximity: Types.asNumber(body.proximity, {
26
- name: 'proximity'
27
- }),
28
- beeMode: toBeeMode(Types.asString(body.beeMode, {
29
- name: 'beeMode'
30
- })),
31
- reserveSize: Types.asNumber(body.reserveSize, {
32
- name: 'reserveSize'
33
- }),
34
- reserveSizeWithinRadius: Types.asNumber(body.reserveSizeWithinRadius, {
35
- name: 'reserveSizeWithinRadius'
36
- }),
37
- pullsyncRate: Types.asNumber(body.pullsyncRate, {
38
- name: 'pullsyncRate'
39
- }),
40
- storageRadius: Types.asNumber(body.storageRadius, {
41
- name: 'storageRadius'
42
- }),
43
- connectedPeers: Types.asNumber(body.connectedPeers, {
44
- name: 'connectedPeers'
45
- }),
46
- neighborhoodSize: Types.asNumber(body.neighborhoodSize, {
47
- name: 'neighborhoodSize'
48
- }),
49
- batchCommitment: Types.asNumber(body.batchCommitment, {
50
- name: 'batchCommitment'
51
- }),
52
- isReachable: Types.asBoolean(body.isReachable, {
53
- name: 'isReachable'
54
- }),
55
- lastSyncedBlock: Types.asNumber(body.lastSyncedBlock, {
56
- name: 'lastSyncedBlock'
57
- }),
58
- committedDepth: Types.asNumber(body.committedDepth, {
59
- name: 'committedDepth'
60
- }),
61
- isWarmingUp: Types.asBoolean(body.isWarmingUp, {
62
- name: 'isWarmingUp'
63
- })
64
- };
17
+ return GetDebugStatusResponse.parse(response.data);
65
18
  }
66
19
  /**
67
20
  * Get health of node
@@ -74,20 +27,7 @@ export async function getHealth(requestOptions) {
74
27
  url: HEALTH_URL,
75
28
  responseType: 'json'
76
29
  });
77
- const body = Types.asObject(response.data, {
78
- name: 'response.data'
79
- });
80
- return {
81
- apiVersion: Types.asString(body.apiVersion, {
82
- name: 'apiVersion'
83
- }),
84
- version: Types.asString(body.version, {
85
- name: 'version'
86
- }),
87
- status: Types.asString(body.status, {
88
- name: 'status'
89
- })
90
- };
30
+ return GetHealthResponse.parse(response.data);
91
31
  }
92
32
  /**
93
33
  * Get readiness of node
@@ -99,20 +39,7 @@ export async function getReadiness(requestOptions) {
99
39
  method: 'get',
100
40
  url: READINESS_URL
101
41
  });
102
- const body = Types.asObject(response.data, {
103
- name: 'response.data'
104
- });
105
- return {
106
- apiVersion: Types.asString(body.apiVersion, {
107
- name: 'apiVersion'
108
- }),
109
- version: Types.asString(body.version, {
110
- name: 'version'
111
- }),
112
- status: Types.asString(body.status, {
113
- name: 'status'
114
- })
115
- };
42
+ return GetReadinessResponse.parse(response.data);
116
43
  }
117
44
  /**
118
45
  * Get information about Bee node
@@ -125,20 +52,7 @@ export async function getNodeInfo(requestOptions) {
125
52
  url: NODE_INFO_URL,
126
53
  responseType: 'json'
127
54
  });
128
- const body = Types.asObject(response.data, {
129
- name: 'response.data'
130
- });
131
- return {
132
- beeMode: toBeeMode(Types.asString(body.beeMode, {
133
- name: 'beeMode'
134
- })),
135
- chequebookEnabled: Types.asBoolean(body.chequebookEnabled, {
136
- name: 'chequebookEnabled'
137
- }),
138
- swapEnabled: Types.asBoolean(body.swapEnabled, {
139
- name: 'swapEnabled'
140
- })
141
- };
55
+ return GetNodeInfoResponse.parse(response.data);
142
56
  }
143
57
  /**
144
58
  * Connects to a node and checks if its version matches with the one that bee-js supports.
@@ -1,7 +1,5 @@
1
- import { Types } from 'cafe-utility';
1
+ import { GetAllTransactionsResponse, GetTransactionResponse, TransactionHashResponse } from "../../types/schema/transactions.js";
2
2
  import { http } from "../../utils/http.js";
3
- import { asNumberString } from "../../utils/type.js";
4
- import { TransactionId } from "../../utils/typed-bytes.js";
5
3
  const transactionsEndpoint = 'transactions';
6
4
  /**
7
5
  * Get list of all pending transactions
@@ -13,13 +11,7 @@ export async function getAllTransactions(requestOptions) {
13
11
  url: transactionsEndpoint,
14
12
  responseType: 'json'
15
13
  });
16
- const body = Types.asObject(response.data, {
17
- name: 'response.data'
18
- });
19
- const pendingTransactions = Types.asArray(body.pendingTransactions, {
20
- name: 'pendingTransactions'
21
- });
22
- return pendingTransactions.map(toTransaction);
14
+ return GetAllTransactionsResponse.parse(response.data).pendingTransactions;
23
15
  }
24
16
  /**
25
17
  * Get information for specific pending transactions
@@ -32,44 +24,7 @@ export async function getTransaction(requestOptions, transactionHash) {
32
24
  url: `${transactionsEndpoint}/${transactionHash}`,
33
25
  responseType: 'json'
34
26
  });
35
- const body = Types.asObject(response.data, {
36
- name: 'response.data'
37
- });
38
- return toTransaction(body);
39
- }
40
- function toTransaction(value) {
41
- const object = Types.asObject(value, {
42
- name: 'transaction'
43
- });
44
- return {
45
- transactionHash: new TransactionId(Types.asString(object.transactionHash, {
46
- name: 'transactionHash'
47
- })),
48
- to: Types.asString(object.to, {
49
- name: 'to'
50
- }),
51
- nonce: Types.asNumber(object.nonce, {
52
- name: 'nonce'
53
- }),
54
- gasPrice: asNumberString(object.gasPrice, {
55
- name: 'gasPrice'
56
- }),
57
- gasLimit: Types.asNumber(object.gasLimit, {
58
- name: 'gasLimit'
59
- }),
60
- data: Types.asString(object.data, {
61
- name: 'data'
62
- }),
63
- created: Types.asString(object.created, {
64
- name: 'created'
65
- }),
66
- description: Types.asString(object.description, {
67
- name: 'description'
68
- }),
69
- value: asNumberString(object.value, {
70
- name: 'value'
71
- })
72
- };
27
+ return GetTransactionResponse.parse(response.data);
73
28
  }
74
29
  /**
75
30
  * Rebroadcast existing transaction
@@ -83,12 +38,7 @@ export async function rebroadcastTransaction(requestOptions, transactionHash) {
83
38
  url: `${transactionsEndpoint}/${transactionHash}`,
84
39
  responseType: 'json'
85
40
  });
86
- const body = Types.asObject(response.data, {
87
- name: 'response.data'
88
- });
89
- return new TransactionId(Types.asString(body.transactionHash, {
90
- name: 'transactionHash'
91
- }));
41
+ return TransactionHashResponse.parse(response.data).transactionHash;
92
42
  }
93
43
  /**
94
44
  * Cancel existing transaction
@@ -108,10 +58,5 @@ export async function cancelTransaction(requestOptions, transactionHash, gasPric
108
58
  url: `${transactionsEndpoint}/${transactionHash}`,
109
59
  responseType: 'json'
110
60
  });
111
- const body = Types.asObject(response.data, {
112
- name: 'response.data'
113
- });
114
- return new TransactionId(Types.asString(body.transactionHash, {
115
- name: 'transactionHash'
116
- }));
61
+ return TransactionHashResponse.parse(response.data).transactionHash;
117
62
  }
@@ -1,4 +1,4 @@
1
- import { Binary, Types } from 'cafe-utility';
1
+ import { PostEnvelopeBodyResponse } from "../types/schema/envelope.js";
2
2
  import { http } from "../utils/http.js";
3
3
  const ENVELOPE_ENDPOINT = 'envelope';
4
4
  export async function postEnvelope(requestOptions, postageBatchId, reference) {
@@ -10,26 +10,12 @@ export async function postEnvelope(requestOptions, postageBatchId, reference) {
10
10
  'swarm-postage-batch-id': postageBatchId.toHex()
11
11
  }
12
12
  });
13
- const body = Types.asObject(response.data, {
14
- name: 'response.data'
15
- });
13
+ const body = PostEnvelopeBodyResponse.parse(response.data);
16
14
  return {
17
- issuer: Binary.hexToUint8Array(Types.asHexString(body.issuer, {
18
- name: 'issuer',
19
- byteLength: 20
20
- })),
21
- index: Binary.hexToUint8Array(Types.asHexString(body.index, {
22
- name: 'index',
23
- byteLength: 8
24
- })),
25
- timestamp: Binary.hexToUint8Array(Types.asHexString(body.timestamp, {
26
- name: 'timestamp',
27
- byteLength: 8
28
- })),
29
- signature: Binary.hexToUint8Array(Types.asHexString(body.signature, {
30
- name: 'signature',
31
- byteLength: 65
32
- })),
15
+ issuer: body.issuer,
16
+ index: body.index,
17
+ timestamp: body.timestamp,
18
+ signature: body.signature,
33
19
  batchId: postageBatchId
34
20
  };
35
21
  }
@@ -1,9 +1,9 @@
1
- import { Types } from 'cafe-utility';
1
+ import { UploadResultBody } from "../types/schema/upload.js";
2
2
  import { Bytes } from "../utils/bytes.js";
3
3
  import { BeeError } from "../utils/error.js";
4
4
  import { prepareRequestHeaders } from "../utils/headers.js";
5
5
  import { http } from "../utils/http.js";
6
- import { FeedIndex, Reference } from "../utils/typed-bytes.js";
6
+ import { FeedIndex } from "../utils/typed-bytes.js";
7
7
  const feedEndpoint = 'feeds';
8
8
  /**
9
9
  * Create an initial feed root manifest
@@ -21,10 +21,7 @@ export async function createFeedManifest(requestOptions, owner, topic, stamp, op
21
21
  url: `${feedEndpoint}/${owner}/${topic}`,
22
22
  headers: prepareRequestHeaders(stamp, options)
23
23
  });
24
- const body = Types.asObject(response.data, {
25
- name: 'response.data'
26
- });
27
- return new Reference(Types.asHexString(body.reference));
24
+ return UploadResultBody.parse(response.data).reference;
28
25
  }
29
26
  function readFeedUpdateHeaders(headers) {
30
27
  const feedIndex = headers['swarm-feed-index'];
@@ -57,7 +54,9 @@ export async function fetchLatestFeedUpdate(requestOptions, owner, topic, option
57
54
  const response = await http(requestOptions, {
58
55
  responseType: 'arraybuffer',
59
56
  url: `${feedEndpoint}/${owner}/${topic}`,
60
- params: options
57
+ params: {
58
+ ...options
59
+ }
61
60
  });
62
61
  return {
63
62
  payload: new Bytes(response.data),
@@ -1,7 +1,6 @@
1
- import { Types } from 'cafe-utility';
1
+ import { GetGranteesBodyResponse, GranteesResultBodyResponse } from "../types/schema/grantee.js";
2
2
  import { prepareRequestHeaders } from "../utils/headers.js";
3
3
  import { http } from "../utils/http.js";
4
- import { PublicKey, Reference } from "../utils/typed-bytes.js";
5
4
  const granteeEndpoint = 'grantee';
6
5
  export async function getGrantees(reference, requestOptions) {
7
6
  const response = await http(requestOptions, {
@@ -9,15 +8,10 @@ export async function getGrantees(reference, requestOptions) {
9
8
  url: `${granteeEndpoint}/${reference}`,
10
9
  responseType: 'json'
11
10
  });
12
- const body = Types.asArray(response.data, {
13
- name: 'response.data'
14
- }).map(x => new PublicKey(Types.asString(x, {
15
- name: 'grantee'
16
- })));
17
11
  return {
18
12
  status: response.status,
19
13
  statusText: response.statusText,
20
- grantees: body
14
+ grantees: GetGranteesBodyResponse.parse(response.data)
21
15
  };
22
16
  }
23
17
  export async function createGrantees(requestOptions, postageBatchId, grantees) {
@@ -30,18 +24,12 @@ export async function createGrantees(requestOptions, postageBatchId, grantees) {
30
24
  headers: prepareRequestHeaders(postageBatchId),
31
25
  responseType: 'json'
32
26
  });
33
- const body = Types.asObject(response.data, {
34
- name: 'response.data'
35
- });
27
+ const body = GranteesResultBodyResponse.parse(response.data);
36
28
  return {
37
29
  status: response.status,
38
30
  statusText: response.statusText,
39
- ref: new Reference(Types.asString(body.ref, {
40
- name: 'ref'
41
- })),
42
- historyref: new Reference(Types.asString(body.historyref, {
43
- name: 'historyref'
44
- }))
31
+ ref: body.ref,
32
+ historyref: body.historyref
45
33
  };
46
34
  }
47
35
  export async function patchGrantees(postageBatchId, reference, historyRef, grantees, requestOptions) {
@@ -58,17 +46,11 @@ export async function patchGrantees(postageBatchId, reference, historyRef, grant
58
46
  },
59
47
  responseType: 'json'
60
48
  });
61
- const body = Types.asObject(response.data, {
62
- name: 'response.data'
63
- });
49
+ const body = GranteesResultBodyResponse.parse(response.data);
64
50
  return {
65
51
  status: response.status,
66
52
  statusText: response.statusText,
67
- ref: new Reference(Types.asString(body.ref, {
68
- name: 'ref'
69
- })),
70
- historyref: new Reference(Types.asString(body.historyref, {
71
- name: 'historyref'
72
- }))
53
+ ref: body.ref,
54
+ historyref: body.historyref
73
55
  };
74
56
  }