@ethersphere/bee-js 1.2.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/CHANGELOG.md +135 -2
  2. package/README.md +3 -1
  3. package/dist/index.browser.min.js +1 -1
  4. package/dist/index.browser.min.js.LICENSE.txt +51 -0
  5. package/dist/index.browser.min.js.map +1 -1
  6. package/dist/index.min.js +1 -1
  7. package/dist/index.min.js.LICENSE.txt +42 -0
  8. package/dist/index.min.js.map +1 -1
  9. package/dist/src/bee-debug.d.ts +75 -38
  10. package/dist/src/bee.d.ts +88 -82
  11. package/dist/src/chunk/soc.d.ts +6 -6
  12. package/dist/src/feed/index.d.ts +7 -7
  13. package/dist/src/feed/json.d.ts +2 -2
  14. package/dist/src/modules/bytes.d.ts +8 -11
  15. package/dist/src/modules/bzz.d.ts +9 -14
  16. package/dist/src/modules/chunk.d.ts +7 -11
  17. package/dist/src/modules/debug/balance.d.ts +9 -9
  18. package/dist/src/modules/debug/chequebook.d.ts +17 -18
  19. package/dist/src/modules/debug/chunk.d.ts +5 -5
  20. package/dist/src/modules/debug/connectivity.d.ts +7 -7
  21. package/dist/src/modules/debug/settlements.d.ts +5 -5
  22. package/dist/src/modules/debug/stamps.d.ts +7 -5
  23. package/dist/src/modules/debug/states.d.ts +5 -5
  24. package/dist/src/modules/debug/status.d.ts +5 -4
  25. package/dist/src/modules/debug/tag.d.ts +3 -3
  26. package/dist/src/modules/debug/transactions.d.ts +9 -9
  27. package/dist/src/modules/feed.d.ts +5 -5
  28. package/dist/src/modules/pinning.d.ts +9 -9
  29. package/dist/src/modules/pss.d.ts +4 -3
  30. package/dist/src/modules/soc.d.ts +3 -3
  31. package/dist/src/modules/status.d.ts +3 -2
  32. package/dist/src/modules/stewardship.d.ts +4 -4
  33. package/dist/src/modules/tag.d.ts +6 -6
  34. package/dist/src/types/debug.d.ts +4 -2
  35. package/dist/src/types/index.d.ts +71 -19
  36. package/dist/src/utils/bytes.d.ts +1 -1
  37. package/dist/src/utils/data.browser.d.ts +3 -1
  38. package/dist/src/utils/data.d.ts +7 -4
  39. package/dist/src/utils/expose.d.ts +6 -9
  40. package/dist/src/utils/headers.d.ts +3 -3
  41. package/dist/src/utils/http.d.ts +25 -0
  42. package/dist/src/utils/merge.d.ts +8 -0
  43. package/dist/src/utils/pss.d.ts +9 -0
  44. package/dist/src/utils/stream.d.ts +37 -0
  45. package/dist/src/utils/type.d.ts +19 -9
  46. package/package.json +15 -8
  47. package/.babelrc.js +0 -33
  48. package/.depcheckrc.json +0 -27
  49. package/.editorconfig +0 -6
  50. package/.eslintignore +0 -1
  51. package/.eslintrc.js +0 -108
  52. package/.gitattributes +0 -1
  53. package/.github/config.yaml +0 -23
  54. package/.github/workflows/check.yaml +0 -57
  55. package/.github/workflows/publish_npmjs.yaml +0 -20
  56. package/.github/workflows/release_github.yaml +0 -20
  57. package/.github/workflows/tests.yaml +0 -128
  58. package/.huskyrc +0 -5
  59. package/.prettierrc +0 -13
  60. package/.vscode/launch.json +0 -49
  61. package/.vscode/settings.json +0 -39
  62. package/CODEOWNERS +0 -1
  63. package/CODE_OF_CONDUCT.md +0 -76
  64. package/commitlint.config.js +0 -3
  65. package/dist/src/modules/stamps.d.ts +0 -4
  66. package/dist/src/utils/hooks.d.ts +0 -31
  67. package/dist/src/utils/safe-axios.d.ts +0 -8
  68. package/jest-puppeteer.config.js +0 -5
  69. package/jest.config.ts +0 -170
  70. package/src/bee-debug.ts +0 -440
  71. package/src/bee.ts +0 -941
  72. package/src/chunk/bmt.ts +0 -55
  73. package/src/chunk/cac.ts +0 -79
  74. package/src/chunk/serialize.ts +0 -16
  75. package/src/chunk/signer.ts +0 -141
  76. package/src/chunk/soc.ts +0 -190
  77. package/src/chunk/span.ts +0 -33
  78. package/src/feed/index.ts +0 -221
  79. package/src/feed/json.ts +0 -32
  80. package/src/feed/topic.ts +0 -23
  81. package/src/feed/type.ts +0 -12
  82. package/src/index.ts +0 -24
  83. package/src/modules/bytes.ts +0 -75
  84. package/src/modules/bzz.ts +0 -184
  85. package/src/modules/chunk.ts +0 -75
  86. package/src/modules/debug/balance.ts +0 -63
  87. package/src/modules/debug/chequebook.ts +0 -174
  88. package/src/modules/debug/chunk.ts +0 -39
  89. package/src/modules/debug/connectivity.ts +0 -61
  90. package/src/modules/debug/settlements.ts +0 -33
  91. package/src/modules/debug/stamps.ts +0 -69
  92. package/src/modules/debug/states.ts +0 -35
  93. package/src/modules/debug/status.ts +0 -34
  94. package/src/modules/debug/tag.ts +0 -19
  95. package/src/modules/debug/transactions.ts +0 -79
  96. package/src/modules/feed.ts +0 -92
  97. package/src/modules/pinning.ts +0 -74
  98. package/src/modules/pss.ts +0 -48
  99. package/src/modules/soc.ts +0 -41
  100. package/src/modules/stamps.ts +0 -59
  101. package/src/modules/status.ts +0 -13
  102. package/src/modules/stewardship.ts +0 -21
  103. package/src/modules/tag.ts +0 -83
  104. package/src/types/axios/index.d.ts +0 -18
  105. package/src/types/debug.ts +0 -204
  106. package/src/types/index.ts +0 -497
  107. package/src/types/tar-js.d.ts +0 -1
  108. package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
  109. package/src/utils/bytes.ts +0 -144
  110. package/src/utils/collection.ts +0 -151
  111. package/src/utils/data.browser.ts +0 -24
  112. package/src/utils/data.ts +0 -35
  113. package/src/utils/error.ts +0 -23
  114. package/src/utils/eth.ts +0 -229
  115. package/src/utils/expose.ts +0 -10
  116. package/src/utils/file.ts +0 -40
  117. package/src/utils/hash.ts +0 -16
  118. package/src/utils/headers.ts +0 -63
  119. package/src/utils/hex.ts +0 -186
  120. package/src/utils/hooks.ts +0 -89
  121. package/src/utils/safe-axios.ts +0 -98
  122. package/src/utils/tar.ts +0 -30
  123. package/src/utils/type.ts +0 -302
  124. package/src/utils/uint64.ts +0 -31
  125. package/src/utils/url.ts +0 -52
  126. package/test/bee.sh +0 -187
  127. package/test/data/1.txt +0 -1
  128. package/test/data/2.txt +0 -0
  129. package/test/data/empty +0 -0
  130. package/test/data/sub/3.txt +0 -1
  131. package/test/data/sub//303/251 +0 -0
  132. package/test/data/sub//360/237/230/216 +0 -0
  133. package/test/integration/bee-class.browser.spec.ts +0 -215
  134. package/test/integration/bee-class.spec.ts +0 -595
  135. package/test/integration/bee-debug-class.spec.ts +0 -85
  136. package/test/integration/chunk/bmt.spec.ts +0 -33
  137. package/test/integration/chunk/cac.spec.ts +0 -27
  138. package/test/integration/chunk/soc.spec.ts +0 -38
  139. package/test/integration/feed/index.spec.ts +0 -84
  140. package/test/integration/modules/bytes.spec.ts +0 -23
  141. package/test/integration/modules/bzz.spec.ts +0 -270
  142. package/test/integration/modules/chunk.spec.ts +0 -29
  143. package/test/integration/modules/debug/balance.spec.ts +0 -70
  144. package/test/integration/modules/debug/chequebook.spec.ts +0 -64
  145. package/test/integration/modules/debug/connectivity.spec.ts +0 -69
  146. package/test/integration/modules/debug/settlements.spec.ts +0 -34
  147. package/test/integration/modules/debug/states.spec.ts +0 -34
  148. package/test/integration/modules/debug/status.spec.ts +0 -65
  149. package/test/integration/modules/debug/tag.spec.ts +0 -27
  150. package/test/integration/modules/feed.spec.ts +0 -61
  151. package/test/integration/modules/pinning.spec.ts +0 -155
  152. package/test/integration/modules/pss.spec.ts +0 -92
  153. package/test/integration/modules/status.spec.ts +0 -10
  154. package/test/integration/modules/stewardship.spec.ts +0 -32
  155. package/test/integration/modules/tag.spec.ts +0 -51
  156. package/test/test-type-sequencer.js +0 -36
  157. package/test/testpage/testpage.html +0 -20
  158. package/test/unit/assertions.ts +0 -376
  159. package/test/unit/bee-class.spec.ts +0 -685
  160. package/test/unit/bee-debug-class.spec.ts +0 -365
  161. package/test/unit/chunk/bmt.spec.ts +0 -16
  162. package/test/unit/chunk/cac.spec.ts +0 -29
  163. package/test/unit/chunk/serialize.spec.ts +0 -24
  164. package/test/unit/chunk/signer.spec.ts +0 -140
  165. package/test/unit/chunk/soc.spec.ts +0 -25
  166. package/test/unit/chunk/span.spec.ts +0 -38
  167. package/test/unit/feed/json.spec.ts +0 -73
  168. package/test/unit/nock.ts +0 -134
  169. package/test/unit/utils/bytes.spec.ts +0 -32
  170. package/test/unit/utils/collection.spec.ts +0 -22
  171. package/test/unit/utils/eth.spec.ts +0 -224
  172. package/test/unit/utils/hex.spec.ts +0 -115
  173. package/test/unit/utils/hooks.spec.ts +0 -179
  174. package/test/unit/utils/safe-axios.spec.ts +0 -20
  175. package/test/unit/utils/type.spec.ts +0 -32
  176. package/test/unit/utils/uint64.spec.ts +0 -102
  177. package/test/utils.ts +0 -292
  178. package/tsconfig.json +0 -18
  179. package/tsconfig.test.json +0 -11
  180. package/typedoc.json +0 -7
  181. package/webpack.config.ts +0 -141
@@ -1,63 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import { PeerBalance, BalanceResponse } from '../../types'
3
-
4
- const balancesEndpoint = '/balances'
5
- const consumedEndpoint = '/consumed'
6
-
7
- /**
8
- * Get the balances with all known peers including prepaid services
9
- *
10
- * @param url Bee debug url
11
- */
12
- export async function getAllBalances(url: string): Promise<BalanceResponse> {
13
- const response = await safeAxios<BalanceResponse>({
14
- url: url + balancesEndpoint,
15
- responseType: 'json',
16
- })
17
-
18
- return response.data
19
- }
20
-
21
- /**
22
- * Get the balances with a specific peer including prepaid services
23
- *
24
- * @param url Bee debug url
25
- * @param address Swarm address of peer
26
- */
27
- export async function getPeerBalance(url: string, address: string): Promise<PeerBalance> {
28
- const response = await safeAxios<PeerBalance>({
29
- url: url + `${balancesEndpoint}/${address}`,
30
- responseType: 'json',
31
- })
32
-
33
- return response.data
34
- }
35
-
36
- /**
37
- * Get the past due consumption balances with all known peers
38
- *
39
- * @param url Bee debug url
40
- */
41
- export async function getPastDueConsumptionBalances(url: string): Promise<BalanceResponse> {
42
- const response = await safeAxios<BalanceResponse>({
43
- url: url + consumedEndpoint,
44
- responseType: 'json',
45
- })
46
-
47
- return response.data
48
- }
49
-
50
- /**
51
- * Get the past due consumption balance with a specific peer
52
- *
53
- * @param url Bee debug url
54
- * @param address Swarm address of peer
55
- */
56
- export async function getPastDueConsumptionPeerBalance(url: string, address: string): Promise<PeerBalance> {
57
- const response = await safeAxios<PeerBalance>({
58
- url: url + `${consumedEndpoint}/${address}`,
59
- responseType: 'json',
60
- })
61
-
62
- return response.data
63
- }
@@ -1,174 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import type {
3
- ChequebookAddressResponse,
4
- ChequebookBalanceResponse,
5
- LastCashoutActionResponse,
6
- TransactionResponse,
7
- LastChequesForPeerResponse,
8
- LastChequesResponse,
9
- NumberString,
10
- TransactionHash,
11
- } from '../../types'
12
- import { CashoutOptions } from '../../types'
13
-
14
- const chequebookEndpoint = '/chequebook'
15
-
16
- /**
17
- * Get the address of the chequebook contract used
18
- *
19
- * @param url Bee debug url
20
- */
21
- export async function getChequebookAddress(url: string): Promise<ChequebookAddressResponse> {
22
- const response = await safeAxios<ChequebookAddressResponse>({
23
- url: url + chequebookEndpoint + '/address',
24
- responseType: 'json',
25
- })
26
-
27
- return response.data
28
- }
29
-
30
- /**
31
- * Get the balance of the chequebook
32
- *
33
- * @param url Bee debug url
34
- */
35
- export async function getChequebookBalance(url: string): Promise<ChequebookBalanceResponse> {
36
- const response = await safeAxios<ChequebookBalanceResponse>({
37
- url: url + chequebookEndpoint + '/balance',
38
- responseType: 'json',
39
- })
40
-
41
- return response.data
42
- }
43
-
44
- /**
45
- * Get last cashout action for the peer
46
- *
47
- * @param url Bee debug url
48
- * @param peer Swarm address of peer
49
- */
50
- export async function getLastCashoutAction(url: string, peer: string): Promise<LastCashoutActionResponse> {
51
- const response = await safeAxios<LastCashoutActionResponse>({
52
- url: url + chequebookEndpoint + `/cashout/${peer}`,
53
- responseType: 'json',
54
- })
55
-
56
- return response.data
57
- }
58
-
59
- /**
60
- * Cashout the last cheque for the peer
61
- *
62
- * @param url Bee debug url
63
- * @param peer Swarm address of peer
64
- * @param options
65
- */
66
- export async function cashoutLastCheque(url: string, peer: string, options?: CashoutOptions): Promise<TransactionHash> {
67
- const headers: Record<string, string> = {}
68
-
69
- if (options?.gasPrice) {
70
- headers['gas-price'] = options.gasPrice.toString()
71
- }
72
-
73
- if (options?.gasLimit) {
74
- headers['gas-limit'] = options.gasLimit.toString()
75
- }
76
-
77
- const response = await safeAxios<TransactionResponse>({
78
- method: 'post',
79
- url: url + chequebookEndpoint + `/cashout/${peer}`,
80
- responseType: 'json',
81
- headers,
82
- })
83
-
84
- return response.data.transactionHash
85
- }
86
-
87
- /**
88
- * Get last cheques for the peer
89
- *
90
- * @param url Bee debug url
91
- * @param peer Swarm address of peer
92
- */
93
- export async function getLastChequesForPeer(url: string, peer: string): Promise<LastChequesForPeerResponse> {
94
- const response = await safeAxios<LastChequesForPeerResponse>({
95
- url: url + chequebookEndpoint + `/cheque/${peer}`,
96
- responseType: 'json',
97
- })
98
-
99
- return response.data
100
- }
101
-
102
- /**
103
- * Get last cheques for all peers
104
- *
105
- * @param url Bee debug url
106
- */
107
- export async function getLastCheques(url: string): Promise<LastChequesResponse> {
108
- const response = await safeAxios<LastChequesResponse>({
109
- url: url + chequebookEndpoint + '/cheque',
110
- responseType: 'json',
111
- })
112
-
113
- return response.data
114
- }
115
-
116
- /**
117
- * Deposit tokens from overlay address into chequebook
118
- *
119
- * @param url Bee debug url
120
- * @param amount Amount of tokens to deposit
121
- * @param gasPrice Gas Price in WEI for the transaction call
122
- * @return string Hash of the transaction
123
- */
124
- export async function depositTokens(
125
- url: string,
126
- amount: number | NumberString,
127
- gasPrice?: NumberString,
128
- ): Promise<TransactionHash> {
129
- const headers: Record<string, string> = {}
130
-
131
- if (gasPrice) {
132
- headers['gas-price'] = gasPrice.toString()
133
- }
134
-
135
- const response = await safeAxios<TransactionResponse>({
136
- method: 'post',
137
- url: url + chequebookEndpoint + '/deposit',
138
- responseType: 'json',
139
- params: { amount: amount.toString(10) },
140
- headers,
141
- })
142
-
143
- return response.data.transactionHash
144
- }
145
-
146
- /**
147
- * Withdraw tokens from the chequebook to the overlay address
148
- *
149
- * @param url Bee debug url
150
- * @param amount Amount of tokens to withdraw
151
- * @param gasPrice Gas Price in WEI for the transaction call
152
- * @return string Hash of the transaction
153
- */
154
- export async function withdrawTokens(
155
- url: string,
156
- amount: number | NumberString,
157
- gasPrice?: NumberString,
158
- ): Promise<TransactionHash> {
159
- const headers: Record<string, string> = {}
160
-
161
- if (gasPrice) {
162
- headers['gas-price'] = gasPrice.toString()
163
- }
164
-
165
- const response = await safeAxios<TransactionResponse>({
166
- method: 'post',
167
- url: url + chequebookEndpoint + '/withdraw',
168
- responseType: 'json',
169
- params: { amount: amount.toString(10) },
170
- headers,
171
- })
172
-
173
- return response.data.transactionHash
174
- }
@@ -1,39 +0,0 @@
1
- import { BeeGenericResponse } from '../../types'
2
- import { safeAxios } from '../../utils/safe-axios'
3
-
4
- const endpoint = '/chunks'
5
-
6
- /**
7
- * Check if chunk at address exists locally
8
- *
9
- * @param url Bee debug url
10
- * @param address Swarm address of chunk
11
- *
12
- * @returns BeeGenericResponse if chunk is found or throws an exception
13
- */
14
- export async function checkIfChunkExistsLocally(url: string, address: string): Promise<BeeGenericResponse> {
15
- const response = await safeAxios<BeeGenericResponse>({
16
- url: url + endpoint + `/${address}`,
17
- responseType: 'json',
18
- })
19
-
20
- return response.data
21
- }
22
-
23
- /**
24
- * Delete a chunk from local storage
25
- *
26
- * @param url Bee debug url
27
- * @param address Swarm address of chunk
28
- *
29
- * @returns BeeGenericResponse if chunk was deleted or throws an exception
30
- */
31
- export async function deleteChunkFromLocalStorage(url: string, address: string): Promise<BeeGenericResponse> {
32
- const response = await safeAxios<BeeGenericResponse>({
33
- method: 'delete',
34
- url: url + endpoint + `/${address}`,
35
- responseType: 'json',
36
- })
37
-
38
- return response.data
39
- }
@@ -1,61 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import type { NodeAddresses, Peer, PingResponse, RemovePeerResponse, Topology } from '../../types'
3
-
4
- export async function getNodeAddresses(url: string): Promise<NodeAddresses> {
5
- const response = await safeAxios<NodeAddresses>({
6
- url: url + '/addresses',
7
- responseType: 'json',
8
- })
9
-
10
- return response.data
11
- }
12
- interface Peers {
13
- peers: Peer[]
14
- }
15
-
16
- export async function getPeers(url: string): Promise<Peer[]> {
17
- const response = await safeAxios<Peers>({
18
- url: url + '/peers',
19
- responseType: 'json',
20
- })
21
-
22
- return response.data.peers || []
23
- }
24
-
25
- export async function getBlocklist(url: string): Promise<Peer[]> {
26
- const response = await safeAxios<Peers>({
27
- url: url + '/blocklist',
28
- responseType: 'json',
29
- })
30
-
31
- return response.data.peers || []
32
- }
33
-
34
- export async function removePeer(url: string, peer: string): Promise<RemovePeerResponse> {
35
- const response = await safeAxios<RemovePeerResponse>({
36
- url: `${url}/peers/${peer}`,
37
- responseType: 'json',
38
- method: 'DELETE',
39
- })
40
-
41
- return response.data
42
- }
43
-
44
- export async function getTopology(url: string): Promise<Topology> {
45
- const response = await safeAxios<Topology>({
46
- url: `${url}/topology`,
47
- responseType: 'json',
48
- })
49
-
50
- return response.data
51
- }
52
-
53
- export async function pingPeer(url: string, peer: string): Promise<PingResponse> {
54
- const response = await safeAxios<PingResponse>({
55
- url: `${url}/pingpong/${peer}`,
56
- responseType: 'json',
57
- method: 'POST',
58
- })
59
-
60
- return response.data
61
- }
@@ -1,33 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import { Settlements, AllSettlements } from '../../types'
3
-
4
- const settlementsEndpoint = '/settlements'
5
-
6
- /**
7
- * Get amount of sent and received from settlements with a peer
8
- *
9
- * @param url Bee debug url
10
- * @param peer Swarm address of peer
11
- */
12
- export async function getSettlements(url: string, peer: string): Promise<Settlements> {
13
- const response = await safeAxios<Settlements>({
14
- url: url + `${settlementsEndpoint}/${peer}`,
15
- responseType: 'json',
16
- })
17
-
18
- return response.data
19
- }
20
-
21
- /**
22
- * Get settlements with all known peers and total amount sent or received
23
- *
24
- * @param url Bee debug url
25
- */
26
- export async function getAllSettlements(url: string): Promise<AllSettlements> {
27
- const response = await safeAxios<AllSettlements>({
28
- url: url + settlementsEndpoint,
29
- responseType: 'json',
30
- })
31
-
32
- return response.data
33
- }
@@ -1,69 +0,0 @@
1
- import { BatchId, DebugPostageBatch, NumberString, PostageBatchBuckets, PostageBatchOptions } from '../../types'
2
- import { safeAxios } from '../../utils/safe-axios'
3
-
4
- const STAMPS_ENDPOINT = '/stamps'
5
-
6
- interface GetAllStampsResponse {
7
- stamps: DebugPostageBatch[]
8
- }
9
-
10
- interface CreateStampResponse {
11
- batchID: BatchId
12
- }
13
-
14
- export async function getAllPostageBatches(url: string): Promise<DebugPostageBatch[]> {
15
- const response = await safeAxios<GetAllStampsResponse>({
16
- method: 'get',
17
- url: `${url}${STAMPS_ENDPOINT}`,
18
- responseType: 'json',
19
- })
20
-
21
- return response.data.stamps || []
22
- }
23
-
24
- export async function getPostageBatch(url: string, postageBatchId: BatchId): Promise<DebugPostageBatch> {
25
- const response = await safeAxios<DebugPostageBatch>({
26
- method: 'get',
27
- url: `${url}${STAMPS_ENDPOINT}/${postageBatchId}`,
28
- responseType: 'json',
29
- })
30
-
31
- return response.data
32
- }
33
-
34
- export async function getPostageBatchBuckets(url: string, postageBatchId: BatchId): Promise<PostageBatchBuckets> {
35
- const response = await safeAxios<PostageBatchBuckets>({
36
- method: 'get',
37
- url: `${url}${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
38
- responseType: 'json',
39
- })
40
-
41
- return response.data
42
- }
43
-
44
- export async function createPostageBatch(
45
- url: string,
46
- amount: NumberString,
47
- depth: number,
48
- options?: PostageBatchOptions,
49
- ): Promise<BatchId> {
50
- const headers: Record<string, string> = {}
51
-
52
- if (options?.gasPrice) {
53
- headers['gas-price'] = options.gasPrice.toString()
54
- }
55
-
56
- if (options?.immutableFlag !== undefined) {
57
- headers.immutable = String(options.immutableFlag)
58
- }
59
-
60
- const response = await safeAxios<CreateStampResponse>({
61
- method: 'post',
62
- url: `${url}${STAMPS_ENDPOINT}/${amount}/${depth}`,
63
- responseType: 'json',
64
- params: { label: options?.label },
65
- headers,
66
- })
67
-
68
- return response.data.batchID
69
- }
@@ -1,35 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import { ChainState, ReserveState } from '../../types'
3
-
4
- const RESERVE_STATE_ENDPOINT = '/reservestate'
5
- const CHAIN_STATE_ENDPOINT = '/chainstate'
6
-
7
- /**
8
- * Get state of reserve
9
- *
10
- * @param url Bee debug URL
11
- */
12
- export async function getReserveState(url: string): Promise<ReserveState> {
13
- const response = await safeAxios<ReserveState>({
14
- method: 'get',
15
- url: `${url}${RESERVE_STATE_ENDPOINT}`,
16
- responseType: 'json',
17
- })
18
-
19
- return response.data
20
- }
21
-
22
- /**
23
- * Get state of reserve
24
- *
25
- * @param url Bee debug URL
26
- */
27
- export async function getChainState(url: string): Promise<ChainState> {
28
- const response = await safeAxios<ChainState>({
29
- method: 'get',
30
- url: `${url}${CHAIN_STATE_ENDPOINT}`,
31
- responseType: 'json',
32
- })
33
-
34
- return response.data
35
- }
@@ -1,34 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import type { Health } from '../../types/debug'
3
- import { engines } from '../../../package.json'
4
- export const SUPPORTED_BEE_VERSION_EXACT = engines.bee
5
- export const SUPPORTED_BEE_VERSION = engines.bee.substr(0, engines.bee.indexOf('-'))
6
-
7
- /**
8
- * Get health of node
9
- *
10
- * @param url Bee debug URL
11
- */
12
- export async function getHealth(url: string): Promise<Health> | never {
13
- const response = await safeAxios<Health>({
14
- method: 'get',
15
- url: `${url}/health`,
16
- responseType: 'json',
17
- })
18
-
19
- return response.data
20
- }
21
-
22
- /**
23
- * Connnects to a node and checks if it is a supported Bee version by the bee-js
24
- *
25
- * @param url Bee debug URL
26
- *
27
- * @returns true if the Bee node version is supported
28
- */
29
- export async function isSupportedVersion(url: string): Promise<boolean> | never {
30
- const { version } = await getHealth(url)
31
-
32
- // TODO: Remove this workaround when new Bee version is out https://github.com/ethersphere/bee-js/issues/400
33
- return version === SUPPORTED_BEE_VERSION_EXACT || version === '1.1.0-dev'
34
- }
@@ -1,19 +0,0 @@
1
- import { ExtendedTag } from '../../types'
2
- import { safeAxios } from '../../utils/safe-axios'
3
-
4
- const endpoint = '/tags'
5
-
6
- /**
7
- * Retrieve tag with extended information from Bee node
8
- *
9
- * @param url Bee tag URL
10
- * @param uid UID of tag to be retrieved
11
- */
12
- export async function retrieveExtendedTag(url: string, uid: number): Promise<ExtendedTag> {
13
- const response = await safeAxios<ExtendedTag>({
14
- url: `${url}${endpoint}/${uid}`,
15
- responseType: 'json',
16
- })
17
-
18
- return response.data
19
- }
@@ -1,79 +0,0 @@
1
- import { safeAxios } from '../../utils/safe-axios'
2
- import { NumberString, TransactionHash, TransactionInfo } from '../../types'
3
-
4
- const transactionsEndpoint = '/transactions'
5
-
6
- interface PendingTransactionsResponse {
7
- pendingTransactions: TransactionInfo[]
8
- }
9
-
10
- interface TransactionResponse {
11
- transactionHash: TransactionHash
12
- }
13
-
14
- /**
15
- * Get list of all pending transactions
16
- *
17
- * @param url Bee debug url
18
- */
19
- export async function getAllTransactions(url: string): Promise<TransactionInfo[]> {
20
- const response = await safeAxios<PendingTransactionsResponse>({
21
- url: `${url}${transactionsEndpoint}`,
22
- responseType: 'json',
23
- })
24
-
25
- return response.data.pendingTransactions
26
- }
27
-
28
- /**
29
- * Get information for specific pending transactions
30
- *
31
- * @param url Bee debug url
32
- * @param transactionHash Hash of the transaction
33
- */
34
- export async function getTransaction(url: string, transactionHash: TransactionHash): Promise<TransactionInfo> {
35
- const response = await safeAxios<TransactionInfo>({
36
- url: `${url}${transactionsEndpoint}/${transactionHash}`,
37
- responseType: 'json',
38
- })
39
-
40
- return response.data
41
- }
42
-
43
- /**
44
- * Rebroadcast existing transaction
45
- *
46
- * @param url Bee debug url
47
- * @param transactionHash Hash of the transaction
48
- */
49
- export async function rebroadcastTransaction(url: string, transactionHash: TransactionHash): Promise<TransactionHash> {
50
- const response = await safeAxios<TransactionResponse>({
51
- method: 'post',
52
- url: `${url}${transactionsEndpoint}/${transactionHash}`,
53
- responseType: 'json',
54
- })
55
-
56
- return response.data.transactionHash
57
- }
58
-
59
- /**
60
- * Cancel existing transaction
61
- *
62
- * @param url Bee debug url
63
- * @param transactionHash Hash of the transaction
64
- * @param gasPrice Optional gas price
65
- */
66
- export async function cancelTransaction(
67
- url: string,
68
- transactionHash: TransactionHash,
69
- gasPrice?: NumberString,
70
- ): Promise<TransactionHash> {
71
- const response = await safeAxios<TransactionResponse>({
72
- method: 'delete',
73
- headers: { 'gas-price': gasPrice },
74
- url: `${url}${transactionsEndpoint}/${transactionHash}`,
75
- responseType: 'json',
76
- })
77
-
78
- return response.data.transactionHash
79
- }
@@ -1,92 +0,0 @@
1
- import { BatchId, Dictionary, Reference, ReferenceResponse, Topic } from '../types'
2
- import { safeAxios } from '../utils/safe-axios'
3
- import { FeedType } from '../feed/type'
4
- import { HexEthAddress } from '../utils/eth'
5
- import { extractUploadHeaders } from '../utils/headers'
6
-
7
- const feedEndpoint = '/feeds'
8
-
9
- export interface CreateFeedOptions {
10
- type?: FeedType
11
- }
12
-
13
- export interface FeedUpdateOptions {
14
- /**
15
- * Specifies the start date as unix time stamp
16
- */
17
- at?: number
18
- /**
19
- * Can be 'epoch' or 'sequence' (default: 'sequence')
20
- */
21
- type?: FeedType
22
- }
23
-
24
- interface FeedUpdateHeaders {
25
- feedIndex: string
26
- feedIndexNext: string
27
- }
28
- export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHeaders {}
29
-
30
- /**
31
- * Create an initial feed root manifest
32
- *
33
- * @param url Bee URL
34
- * @param owner Owner's ethereum address in hex
35
- * @param topic Topic in hex
36
- * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
37
- * @param options Additional options, like type (default: 'sequence')
38
- */
39
- export async function createFeedManifest(
40
- url: string,
41
- owner: HexEthAddress,
42
- topic: Topic,
43
- postageBatchId: BatchId,
44
- options?: CreateFeedOptions,
45
- ): Promise<Reference> {
46
- const response = await safeAxios<ReferenceResponse>({
47
- method: 'post',
48
- url: `${url}${feedEndpoint}/${owner}/${topic}`,
49
- params: options,
50
- headers: extractUploadHeaders(postageBatchId),
51
- })
52
-
53
- return response.data.reference
54
- }
55
-
56
- function readFeedUpdateHeaders(headers: Dictionary<string>): FeedUpdateHeaders {
57
- return {
58
- feedIndex: headers['swarm-feed-index'],
59
- feedIndexNext: headers['swarm-feed-index-next'],
60
- }
61
- }
62
-
63
- /**
64
- * Find and retrieve feed update
65
- *
66
- * The feed consists of updates. This endpoint looks up an
67
- * update that matches the provided parameters and returns
68
- * the reference it contains along with its index and the
69
- * index of the subsequent update.
70
- *
71
- * @param url Bee URL
72
- * @param owner Owner's ethereum address in hex
73
- * @param topic Topic in hex
74
- * @param options Additional options, like index, at, type
75
- */
76
- export async function fetchFeedUpdate(
77
- url: string,
78
- owner: HexEthAddress,
79
- topic: Topic,
80
- options?: FeedUpdateOptions,
81
- ): Promise<FetchFeedUpdateResponse> {
82
- const response = await safeAxios<ReferenceResponse>({
83
- url: `${url}${feedEndpoint}/${owner}/${topic}`,
84
- params: options,
85
- })
86
- const findFeedUpdateResponse = {
87
- ...response.data,
88
- ...readFeedUpdateHeaders(response.headers),
89
- }
90
-
91
- return findFeedUpdateResponse
92
- }