@ethersphere/bee-js 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chunk/bmt.js +7 -2
- package/dist/cjs/chunk/signer.js +9 -4
- package/dist/cjs/modules/debug/status.js +5 -5
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/eth.js +8 -3
- package/dist/cjs/utils/hash.js +7 -2
- package/dist/cjs/utils/stream.js +14 -5
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +52 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/mjs/bee-debug.js +608 -508
- package/dist/mjs/bee.js +935 -836
- package/dist/mjs/chunk/bmt.js +34 -24
- package/dist/mjs/chunk/cac.js +24 -22
- package/dist/mjs/chunk/serialize.js +9 -9
- package/dist/mjs/chunk/signer.js +92 -73
- package/dist/mjs/chunk/soc.js +78 -66
- package/dist/mjs/chunk/span.js +19 -16
- package/dist/mjs/feed/index.js +110 -101
- package/dist/mjs/feed/json.js +21 -17
- package/dist/mjs/feed/topic.js +18 -17
- package/dist/mjs/feed/type.js +5 -5
- package/dist/mjs/index.js +7 -7
- package/dist/mjs/modules/bytes.js +33 -30
- package/dist/mjs/modules/bzz.js +80 -77
- package/dist/mjs/modules/chunk.js +22 -20
- package/dist/mjs/modules/debug/balance.js +26 -22
- package/dist/mjs/modules/debug/chequebook.js +84 -65
- package/dist/mjs/modules/debug/chunk.js +15 -13
- package/dist/mjs/modules/debug/connectivity.js +34 -34
- package/dist/mjs/modules/debug/settlements.js +14 -12
- package/dist/mjs/modules/debug/stamps.js +52 -47
- package/dist/mjs/modules/debug/states.js +16 -14
- package/dist/mjs/modules/debug/status.js +55 -35
- package/dist/mjs/modules/debug/tag.js +8 -7
- package/dist/mjs/modules/debug/transactions.js +31 -25
- package/dist/mjs/modules/feed.js +39 -33
- package/dist/mjs/modules/pinning.js +34 -28
- package/dist/mjs/modules/pss.js +18 -14
- package/dist/mjs/modules/soc.js +18 -15
- package/dist/mjs/modules/status.js +6 -5
- package/dist/mjs/modules/stewardship.js +13 -12
- package/dist/mjs/modules/tag.js +38 -30
- package/dist/mjs/package.json +1 -0
- package/dist/mjs/types/debug.js +5 -4
- package/dist/mjs/types/index.js +6 -2
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +32 -26
- package/dist/mjs/utils/collection.browser.js +4 -3
- package/dist/mjs/utils/collection.js +47 -35
- package/dist/mjs/utils/collection.node.js +53 -42
- package/dist/mjs/utils/data.browser.js +64 -48
- package/dist/mjs/utils/data.js +29 -25
- package/dist/mjs/utils/error.js +47 -39
- package/dist/mjs/utils/eth.js +119 -104
- package/dist/mjs/utils/expose.js +9 -9
- package/dist/mjs/utils/file.js +22 -19
- package/dist/mjs/utils/hash.js +10 -5
- package/dist/mjs/utils/headers.js +43 -39
- package/dist/mjs/utils/hex.js +78 -63
- package/dist/mjs/utils/http.js +119 -100
- package/dist/mjs/utils/merge.js +26 -20
- package/dist/mjs/utils/pss.js +8 -6
- package/dist/mjs/utils/stamps.js +7 -3
- package/dist/mjs/utils/stream.js +107 -82
- package/dist/mjs/utils/tar.js +17 -14
- package/dist/mjs/utils/type.js +249 -209
- package/dist/mjs/utils/uint64.js +16 -16
- package/dist/mjs/utils/url.js +32 -25
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/types/utils/stream.d.ts +11 -8
- package/package.json +9 -6
- package/dist/index.js +0 -28326
- package/dist/index.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
3
3
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
4
4
|
/**
|
|
@@ -6,24 +6,26 @@ const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
|
6
6
|
*
|
|
7
7
|
* @param ky Ky debug instance
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export async function getReserveState(ky) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const response = await http(ky, {
|
|
12
|
+
method: 'get',
|
|
13
|
+
path: `${RESERVE_STATE_ENDPOINT}`,
|
|
14
|
+
responseType: 'json'
|
|
15
|
+
});
|
|
16
|
+
return response.data;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Get state of reserve
|
|
19
20
|
*
|
|
20
21
|
* @param ky Ky debug instance
|
|
21
22
|
*/
|
|
23
|
+
|
|
22
24
|
export async function getChainState(ky) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
25
|
+
const response = await http(ky, {
|
|
26
|
+
method: 'get',
|
|
27
|
+
path: `${CHAIN_STATE_ENDPOINT}`,
|
|
28
|
+
responseType: 'json'
|
|
29
|
+
});
|
|
30
|
+
return response.data;
|
|
31
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { http } from
|
|
2
|
-
import getMajorSemver from 'semver/functions/major';
|
|
3
|
-
// Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
|
+
import getMajorSemver from 'semver/functions/major.js'; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
4
3
|
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
4
|
+
|
|
5
5
|
export const SUPPORTED_BEE_VERSION_EXACT = '1.4.3-1213e063';
|
|
6
6
|
export const SUPPORTED_API_VERSION = '2.0.0';
|
|
7
7
|
export const SUPPORTED_DEBUG_API_VERSION = '1.2.1';
|
|
@@ -13,26 +13,28 @@ const HEALTH_URL = 'health';
|
|
|
13
13
|
*
|
|
14
14
|
* @param ky Ky debug instance
|
|
15
15
|
*/
|
|
16
|
+
|
|
16
17
|
export async function getHealth(ky) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const response = await http(ky, {
|
|
19
|
+
method: 'get',
|
|
20
|
+
path: HEALTH_URL,
|
|
21
|
+
responseType: 'json'
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
26
|
* Get information about Bee node
|
|
26
27
|
*
|
|
27
28
|
* @param ky Ky debug instance
|
|
28
29
|
*/
|
|
30
|
+
|
|
29
31
|
export async function getNodeInfo(ky) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
const response = await http(ky, {
|
|
33
|
+
method: 'get',
|
|
34
|
+
path: NODE_INFO_URL,
|
|
35
|
+
responseType: 'json'
|
|
36
|
+
});
|
|
37
|
+
return response.data;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Connects to a node and checks if it is a supported Bee version by the bee-js
|
|
@@ -42,8 +44,9 @@ export async function getNodeInfo(ky) {
|
|
|
42
44
|
* @returns true if the Bee node version is supported
|
|
43
45
|
* @deprecated Use `isSupportedExactVersion` instead
|
|
44
46
|
*/
|
|
47
|
+
|
|
45
48
|
export async function isSupportedVersion(ky) {
|
|
46
|
-
|
|
49
|
+
return isSupportedExactVersion(ky);
|
|
47
50
|
}
|
|
48
51
|
/**
|
|
49
52
|
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
@@ -55,9 +58,12 @@ export async function isSupportedVersion(ky) {
|
|
|
55
58
|
*
|
|
56
59
|
* @param ky
|
|
57
60
|
*/
|
|
61
|
+
|
|
58
62
|
export async function isSupportedExactVersion(ky) {
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
const {
|
|
64
|
+
version
|
|
65
|
+
} = await getHealth(ky);
|
|
66
|
+
return version === SUPPORTED_BEE_VERSION_EXACT;
|
|
61
67
|
}
|
|
62
68
|
/**
|
|
63
69
|
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
@@ -67,9 +73,12 @@ export async function isSupportedExactVersion(ky) {
|
|
|
67
73
|
*
|
|
68
74
|
* @param ky
|
|
69
75
|
*/
|
|
76
|
+
|
|
70
77
|
export async function isSupportedMainApiVersion(ky) {
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
const {
|
|
79
|
+
apiVersion
|
|
80
|
+
} = await getHealth(ky);
|
|
81
|
+
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION);
|
|
73
82
|
}
|
|
74
83
|
/**
|
|
75
84
|
* Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
|
|
@@ -79,9 +88,12 @@ export async function isSupportedMainApiVersion(ky) {
|
|
|
79
88
|
*
|
|
80
89
|
* @param ky
|
|
81
90
|
*/
|
|
91
|
+
|
|
82
92
|
export async function isSupportedDebugApiVersion(ky) {
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
const {
|
|
94
|
+
debugApiVersion
|
|
95
|
+
} = await getHealth(ky);
|
|
96
|
+
return getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
85
97
|
}
|
|
86
98
|
/**
|
|
87
99
|
* Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
|
|
@@ -90,10 +102,13 @@ export async function isSupportedDebugApiVersion(ky) {
|
|
|
90
102
|
*
|
|
91
103
|
* @param ky
|
|
92
104
|
*/
|
|
105
|
+
|
|
93
106
|
export async function isSupportedApiVersion(ky) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
const {
|
|
108
|
+
apiVersion,
|
|
109
|
+
debugApiVersion
|
|
110
|
+
} = await getHealth(ky);
|
|
111
|
+
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) && getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
97
112
|
}
|
|
98
113
|
/**
|
|
99
114
|
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
@@ -101,14 +116,19 @@ export async function isSupportedApiVersion(ky) {
|
|
|
101
116
|
*
|
|
102
117
|
* @param ky
|
|
103
118
|
*/
|
|
119
|
+
|
|
104
120
|
export async function getVersions(ky) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
121
|
+
const {
|
|
122
|
+
version,
|
|
123
|
+
apiVersion,
|
|
124
|
+
debugApiVersion
|
|
125
|
+
} = await getHealth(ky);
|
|
126
|
+
return {
|
|
127
|
+
supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT,
|
|
128
|
+
supportedBeeApiVersion: SUPPORTED_API_VERSION,
|
|
129
|
+
supportedBeeDebugApiVersion: SUPPORTED_DEBUG_API_VERSION,
|
|
130
|
+
beeVersion: version,
|
|
131
|
+
beeApiVersion: apiVersion,
|
|
132
|
+
beeDebugApiVersion: debugApiVersion
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const endpoint = 'tags';
|
|
3
3
|
/**
|
|
4
4
|
* Retrieve tag with extended information from Bee node
|
|
@@ -6,10 +6,11 @@ const endpoint = 'tags';
|
|
|
6
6
|
* @param ky Ky debug instance
|
|
7
7
|
* @param uid UID of tag to be retrieved
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export async function retrieveExtendedTag(ky, uid) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
11
|
+
const response = await http(ky, {
|
|
12
|
+
path: `${endpoint}/${uid}`,
|
|
13
|
+
responseType: 'json'
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
16
|
+
}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const transactionsEndpoint = 'transactions';
|
|
3
3
|
/**
|
|
4
4
|
* Get list of all pending transactions
|
|
5
5
|
*
|
|
6
6
|
* @param ky Debug Ky instance
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
export async function getAllTransactions(ky) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const response = await http(ky, {
|
|
11
|
+
path: transactionsEndpoint,
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data.pendingTransactions;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Get information for specific pending transactions
|
|
@@ -18,12 +19,13 @@ export async function getAllTransactions(ky) {
|
|
|
18
19
|
* @param ky Debug Ky instance
|
|
19
20
|
* @param transactionHash Hash of the transaction
|
|
20
21
|
*/
|
|
22
|
+
|
|
21
23
|
export async function getTransaction(ky, transactionHash) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const response = await http(ky, {
|
|
25
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
26
|
+
responseType: 'json'
|
|
27
|
+
});
|
|
28
|
+
return response.data;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
29
31
|
* Rebroadcast existing transaction
|
|
@@ -31,13 +33,14 @@ export async function getTransaction(ky, transactionHash) {
|
|
|
31
33
|
* @param ky Debug Ky instance
|
|
32
34
|
* @param transactionHash Hash of the transaction
|
|
33
35
|
*/
|
|
36
|
+
|
|
34
37
|
export async function rebroadcastTransaction(ky, transactionHash) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const response = await http(ky, {
|
|
39
|
+
method: 'post',
|
|
40
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
41
|
+
responseType: 'json'
|
|
42
|
+
});
|
|
43
|
+
return response.data.transactionHash;
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Cancel existing transaction
|
|
@@ -46,12 +49,15 @@ export async function rebroadcastTransaction(ky, transactionHash) {
|
|
|
46
49
|
* @param transactionHash Hash of the transaction
|
|
47
50
|
* @param gasPrice Optional gas price
|
|
48
51
|
*/
|
|
52
|
+
|
|
49
53
|
export async function cancelTransaction(ky, transactionHash, gasPrice) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
}
|
|
54
|
+
const response = await http(ky, {
|
|
55
|
+
method: 'delete',
|
|
56
|
+
headers: {
|
|
57
|
+
'gas-price': gasPrice
|
|
58
|
+
},
|
|
59
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
60
|
+
responseType: 'json'
|
|
61
|
+
});
|
|
62
|
+
return response.data.transactionHash;
|
|
63
|
+
}
|
package/dist/mjs/modules/feed.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { filterHeaders, http } from
|
|
2
|
-
import { extractUploadHeaders } from
|
|
3
|
-
import { BeeError } from
|
|
1
|
+
import { filterHeaders, http } from "../utils/http.js";
|
|
2
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
3
|
+
import { BeeError } from "../utils/error.js";
|
|
4
4
|
const feedEndpoint = 'feeds';
|
|
5
5
|
/**
|
|
6
6
|
* Create an initial feed root manifest
|
|
@@ -11,29 +11,34 @@ const feedEndpoint = 'feeds';
|
|
|
11
11
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
12
12
|
* @param options Additional options, like type (default: 'sequence')
|
|
13
13
|
*/
|
|
14
|
+
|
|
14
15
|
export async function createFeedManifest(ky, owner, topic, postageBatchId, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const response = await http(ky, {
|
|
17
|
+
method: 'post',
|
|
18
|
+
responseType: 'json',
|
|
19
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
20
|
+
searchParams: filterHeaders(options),
|
|
21
|
+
headers: extractUploadHeaders(postageBatchId)
|
|
22
|
+
});
|
|
23
|
+
return response.data.reference;
|
|
23
24
|
}
|
|
25
|
+
|
|
24
26
|
function readFeedUpdateHeaders(headers) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
const feedIndex = headers.get('swarm-feed-index');
|
|
28
|
+
const feedIndexNext = headers.get('swarm-feed-index-next');
|
|
29
|
+
|
|
30
|
+
if (!feedIndex) {
|
|
31
|
+
throw new BeeError('Response did not contain expected swarm-feed-index!');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!feedIndexNext) {
|
|
35
|
+
throw new BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
feedIndex,
|
|
40
|
+
feedIndexNext
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
43
|
/**
|
|
39
44
|
* Find and retrieve feed update
|
|
@@ -48,14 +53,15 @@ function readFeedUpdateHeaders(headers) {
|
|
|
48
53
|
* @param topic Topic in hex
|
|
49
54
|
* @param options Additional options, like index, at, type
|
|
50
55
|
*/
|
|
56
|
+
|
|
57
|
+
|
|
51
58
|
export async function fetchFeedUpdate(ky, owner, topic, options) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
59
|
+
const response = await http(ky, {
|
|
60
|
+
responseType: 'json',
|
|
61
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
62
|
+
searchParams: filterHeaders(options)
|
|
63
|
+
});
|
|
64
|
+
return { ...response.data,
|
|
65
|
+
...readFeedUpdateHeaders(response.headers)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
2
|
const PINNING_ENDPOINT = 'pins';
|
|
3
3
|
/**
|
|
4
4
|
* Pin data with given reference
|
|
@@ -6,12 +6,13 @@ const PINNING_ENDPOINT = 'pins';
|
|
|
6
6
|
* @param ky Ky instance for given Bee class instance
|
|
7
7
|
* @param reference Bee data reference
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export async function pin(ky, reference) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
await http(ky, {
|
|
12
|
+
method: 'post',
|
|
13
|
+
responseType: 'json',
|
|
14
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
15
|
+
});
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Unpin data with given reference
|
|
@@ -19,12 +20,13 @@ export async function pin(ky, reference) {
|
|
|
19
20
|
* @param ky Ky instance for given Bee class instance
|
|
20
21
|
* @param reference Bee data reference
|
|
21
22
|
*/
|
|
23
|
+
|
|
22
24
|
export async function unpin(ky, reference) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
await http(ky, {
|
|
26
|
+
method: 'delete',
|
|
27
|
+
responseType: 'json',
|
|
28
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Get pin status for specific address.
|
|
@@ -33,28 +35,32 @@ export async function unpin(ky, reference) {
|
|
|
33
35
|
* @param reference
|
|
34
36
|
* @throws Error if given address is not pinned
|
|
35
37
|
*/
|
|
38
|
+
|
|
36
39
|
export async function getPin(ky, reference) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const response = await http(ky, {
|
|
41
|
+
method: 'get',
|
|
42
|
+
responseType: 'json',
|
|
43
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
44
|
+
});
|
|
45
|
+
return response.data;
|
|
43
46
|
}
|
|
44
47
|
/**
|
|
45
48
|
* Get list of all pins
|
|
46
49
|
*
|
|
47
50
|
* @param ky Ky instance
|
|
48
51
|
*/
|
|
52
|
+
|
|
49
53
|
export async function getAllPins(ky) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
const response = await http(ky, {
|
|
55
|
+
method: 'get',
|
|
56
|
+
responseType: 'json',
|
|
57
|
+
path: `${PINNING_ENDPOINT}`
|
|
58
|
+
});
|
|
59
|
+
const result = response.data.references;
|
|
60
|
+
|
|
61
|
+
if (result === null) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
}
|
package/dist/mjs/modules/pss.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import { prepareData } from
|
|
3
|
-
import { http } from
|
|
4
|
-
import { extractUploadHeaders } from
|
|
2
|
+
import { prepareData } from "../utils/data.js";
|
|
3
|
+
import { http } from "../utils/http.js";
|
|
4
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
5
5
|
const endpoint = 'pss';
|
|
6
6
|
/**
|
|
7
7
|
* Send to recipient or target with Postal Service for Swarm
|
|
@@ -14,15 +14,18 @@ const endpoint = 'pss';
|
|
|
14
14
|
* @param recipient Recipient public key
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
export async function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
19
|
+
await http(ky, {
|
|
20
|
+
method: 'post',
|
|
21
|
+
path: `${endpoint}/send/${topic}/${target}`,
|
|
22
|
+
body: await prepareData(data),
|
|
23
|
+
responseType: 'json',
|
|
24
|
+
searchParams: {
|
|
25
|
+
recipient
|
|
26
|
+
},
|
|
27
|
+
headers: extractUploadHeaders(postageBatchId)
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Subscribe for messages on the given topic
|
|
@@ -30,7 +33,8 @@ export async function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
|
30
33
|
* @param url Bee node URL
|
|
31
34
|
* @param topic Topic name
|
|
32
35
|
*/
|
|
36
|
+
|
|
33
37
|
export function subscribe(url, topic) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
39
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic}`);
|
|
40
|
+
}
|
package/dist/mjs/modules/soc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { extractUploadHeaders } from
|
|
2
|
-
import { http } from
|
|
1
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
2
|
+
import { http } from "../utils/http.js";
|
|
3
3
|
const socEndpoint = 'soc';
|
|
4
4
|
/**
|
|
5
5
|
* Upload single owner chunk (SOC) to a Bee node
|
|
@@ -12,17 +12,20 @@ const socEndpoint = 'soc';
|
|
|
12
12
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
13
13
|
* @param options Additional options like tag, encryption, pinning
|
|
14
14
|
*/
|
|
15
|
+
|
|
15
16
|
export async function upload(ky, owner, identifier, signature, data, postageBatchId, options) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
17
|
+
const response = await http(ky, {
|
|
18
|
+
method: 'post',
|
|
19
|
+
path: `${socEndpoint}/${owner}/${identifier}`,
|
|
20
|
+
body: data,
|
|
21
|
+
headers: {
|
|
22
|
+
'content-type': 'application/octet-stream',
|
|
23
|
+
...extractUploadHeaders(postageBatchId, options)
|
|
24
|
+
},
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
searchParams: {
|
|
27
|
+
sig: signature
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return response.data.reference;
|
|
31
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
2
|
/**
|
|
3
3
|
* Ping the base bee URL. If connection was not successful throw error
|
|
4
4
|
*
|
|
5
5
|
* @param ky Ky instance for given Bee class instance
|
|
6
6
|
*/
|
|
7
|
+
|
|
7
8
|
export async function checkConnection(ky) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
await http(ky, {
|
|
10
|
+
path: ''
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
2
|
const stewardshipEndpoint = 'stewardship';
|
|
3
3
|
/**
|
|
4
4
|
* Reupload locally pinned data
|
|
@@ -7,17 +7,18 @@ const stewardshipEndpoint = 'stewardship';
|
|
|
7
7
|
* @param options
|
|
8
8
|
* @throws BeeResponseError if not locally pinned or invalid data
|
|
9
9
|
*/
|
|
10
|
+
|
|
10
11
|
export async function reupload(ky, reference) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
await http(ky, {
|
|
13
|
+
method: 'put',
|
|
14
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
15
|
+
});
|
|
15
16
|
}
|
|
16
17
|
export async function isRetrievable(ky, reference) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
18
|
+
const response = await http(ky, {
|
|
19
|
+
method: 'get',
|
|
20
|
+
responseType: 'json',
|
|
21
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
22
|
+
});
|
|
23
|
+
return response.data.isRetrievable;
|
|
24
|
+
}
|