@ethersphere/bee-js 12.3.2-upcoming.116 → 13.0.0-upcoming.gc013bdf
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/api/balance.js +24 -0
- package/dist/cjs/api/batches.js +26 -0
- package/dist/cjs/{modules → api}/bytes.js +4 -29
- package/dist/cjs/{modules → api}/bzz.js +6 -34
- package/dist/cjs/{modules/debug → api}/chequebook.js +48 -87
- package/dist/cjs/api/chunk.js +43 -0
- package/dist/cjs/api/connectivity.js +86 -0
- package/dist/cjs/api/consumed.js +24 -0
- package/dist/cjs/{modules → api}/envelope.js +3 -2
- package/dist/cjs/api/feed.js +55 -0
- package/dist/cjs/api/grantee.js +62 -0
- package/dist/cjs/{modules/pinning.js → api/pin.js} +13 -34
- package/dist/cjs/api/pss.js +19 -0
- package/dist/cjs/api/redistributionstate.js +17 -0
- package/dist/cjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/cjs/api/soc.js +34 -0
- package/dist/cjs/{modules/debug → api}/stake.js +15 -43
- package/dist/cjs/{modules/debug/stamps.js → api/stamp.js} +41 -57
- package/dist/cjs/api/status.js +67 -0
- package/dist/cjs/{modules → api}/stewardship.js +1 -6
- package/dist/cjs/api/tag.js +51 -0
- package/dist/cjs/{modules/debug/transactions.js → api/transaction.js} +10 -31
- package/dist/cjs/{modules/debug/states.js → api/wallet.js} +4 -36
- package/dist/cjs/bee.js +115 -1978
- package/dist/cjs/chunk/soc.js +23 -65
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +20 -22
- package/dist/cjs/feed/retrievable.js +3 -3
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +99 -335
- package/dist/cjs/modules/balance.js +86 -0
- package/dist/cjs/modules/cheque.js +92 -0
- package/dist/cjs/modules/chequebook.js +90 -0
- package/dist/cjs/modules/chunk.js +87 -53
- package/dist/cjs/modules/collection.js +145 -0
- package/dist/cjs/modules/connectivity.js +141 -0
- package/dist/cjs/modules/context.js +2 -0
- package/dist/cjs/modules/data.js +119 -0
- package/dist/cjs/modules/feed.js +94 -70
- package/dist/cjs/modules/file.js +113 -0
- package/dist/cjs/modules/grantee.js +86 -55
- package/dist/cjs/modules/messaging.js +248 -0
- package/dist/cjs/modules/pin.js +100 -0
- package/dist/cjs/modules/settlement.js +67 -0
- package/dist/cjs/modules/soc.js +39 -36
- package/dist/cjs/modules/stake.js +110 -0
- package/dist/cjs/modules/stamp.js +199 -0
- package/dist/cjs/modules/status.js +128 -20
- package/dist/cjs/modules/storage.js +191 -0
- package/dist/cjs/modules/tag.js +97 -71
- package/dist/cjs/modules/transaction.js +92 -0
- package/dist/cjs/modules/wallet.js +82 -0
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/balance.js +20 -0
- package/dist/mjs/api/batches.js +22 -0
- package/dist/mjs/{modules → api}/bytes.js +2 -27
- package/dist/mjs/{modules → api}/bzz.js +2 -30
- package/dist/mjs/{modules/debug → api}/chequebook.js +50 -89
- package/dist/mjs/api/chunk.js +37 -0
- package/dist/mjs/api/connectivity.js +76 -0
- package/dist/mjs/api/consumed.js +20 -0
- package/dist/mjs/{modules → api}/envelope.js +3 -2
- package/dist/mjs/api/feed.js +52 -0
- package/dist/mjs/api/grantee.js +59 -0
- package/dist/mjs/{modules/pinning.js → api/pin.js} +14 -35
- package/dist/mjs/api/pss.js +18 -0
- package/dist/mjs/api/redistributionstate.js +14 -0
- package/dist/mjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/mjs/api/soc.js +31 -0
- package/dist/mjs/{modules/debug → api}/stake.js +14 -41
- package/dist/mjs/{modules/debug/stamps.js → api/stamp.js} +37 -51
- package/dist/mjs/api/status.js +59 -0
- package/dist/mjs/{modules → api}/stewardship.js +1 -6
- package/dist/mjs/api/tag.js +49 -0
- package/dist/mjs/api/transaction.js +41 -0
- package/dist/mjs/api/wallet.js +38 -0
- package/dist/mjs/bee.js +115 -1965
- package/dist/mjs/chunk/soc.js +13 -51
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +9 -11
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +97 -341
- package/dist/mjs/modules/balance.js +49 -0
- package/dist/mjs/modules/cheque.js +55 -0
- package/dist/mjs/modules/chequebook.js +65 -0
- package/dist/mjs/modules/chunk.js +52 -49
- package/dist/mjs/modules/collection.js +108 -0
- package/dist/mjs/modules/connectivity.js +102 -0
- package/dist/mjs/modules/context.js +1 -0
- package/dist/mjs/modules/data.js +82 -0
- package/dist/mjs/modules/feed.js +89 -67
- package/dist/mjs/modules/file.js +78 -0
- package/dist/mjs/modules/grantee.js +52 -55
- package/dist/mjs/modules/messaging.js +213 -0
- package/dist/mjs/modules/pin.js +63 -0
- package/dist/mjs/modules/settlement.js +30 -0
- package/dist/mjs/modules/soc.js +36 -34
- package/dist/mjs/modules/stake.js +76 -0
- package/dist/mjs/modules/stamp.js +170 -0
- package/dist/mjs/modules/status.js +98 -18
- package/dist/mjs/modules/storage.js +185 -0
- package/dist/mjs/modules/tag.js +61 -68
- package/dist/mjs/modules/transaction.js +58 -0
- package/dist/mjs/modules/wallet.js +45 -0
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/types/api/balance.d.ts +7 -0
- package/dist/types/api/batches.d.ts +7 -0
- package/dist/types/api/bytes.d.ts +11 -0
- package/dist/types/api/bzz.d.ts +12 -0
- package/dist/types/api/chequebook.d.ts +21 -0
- package/dist/types/api/chunk.d.ts +7 -0
- package/dist/types/api/connectivity.d.ts +22 -0
- package/dist/types/api/consumed.d.ts +7 -0
- package/dist/types/{modules → api}/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +40 -0
- package/dist/types/api/grantee.d.ts +11 -0
- package/dist/types/api/pin.d.ts +10 -0
- package/dist/types/api/pss.d.ts +6 -0
- package/dist/types/api/redistributionstate.d.ts +5 -0
- package/dist/types/api/settlement.d.ts +7 -0
- package/dist/types/api/soc.d.ts +6 -0
- package/dist/types/api/stake.d.ts +11 -0
- package/dist/types/api/stamp.d.ts +12 -0
- package/dist/types/api/status.d.ts +11 -0
- package/dist/types/api/stewardship.d.ts +7 -0
- package/dist/types/api/tag.d.ts +12 -0
- package/dist/types/api/transaction.d.ts +9 -0
- package/dist/types/api/wallet.d.ts +9 -0
- package/dist/types/bee.d.ts +71 -1199
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +2 -4
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +25 -34
- package/dist/types/modules/balance.d.ts +38 -0
- package/dist/types/modules/cheque.d.ts +40 -0
- package/dist/types/modules/chequebook.d.ts +41 -0
- package/dist/types/modules/chunk.d.ts +30 -20
- package/dist/types/modules/collection.d.ts +77 -0
- package/dist/types/modules/connectivity.d.ts +74 -0
- package/dist/types/modules/context.d.ts +24 -0
- package/dist/types/modules/data.d.ts +55 -0
- package/dist/types/modules/feed.d.ts +47 -49
- package/dist/types/modules/file.d.ts +43 -0
- package/dist/types/modules/grantee.d.ts +40 -8
- package/dist/types/modules/messaging.d.ts +79 -0
- package/dist/types/modules/pin.d.ts +47 -0
- package/dist/types/modules/settlement.d.ts +25 -0
- package/dist/types/modules/soc.d.ts +23 -11
- package/dist/types/modules/stake.d.ts +55 -0
- package/dist/types/modules/stamp.d.ts +96 -0
- package/dist/types/modules/status.d.ts +66 -5
- package/dist/types/modules/storage.d.ts +107 -0
- package/dist/types/modules/tag.d.ts +44 -33
- package/dist/types/modules/transaction.d.ts +42 -0
- package/dist/types/modules/wallet.d.ts +35 -0
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +3 -12
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/package.json +4 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/modules/debug/balance.js +0 -60
- package/dist/cjs/modules/debug/connectivity.js +0 -54
- package/dist/cjs/modules/debug/status.js +0 -104
- package/dist/cjs/modules/gsoc.js +0 -23
- package/dist/cjs/modules/pss.js +0 -48
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/modules/debug/balance.js +0 -54
- package/dist/mjs/modules/debug/connectivity.js +0 -46
- package/dist/mjs/modules/debug/states.js +0 -68
- package/dist/mjs/modules/debug/status.js +0 -99
- package/dist/mjs/modules/debug/transactions.js +0 -62
- package/dist/mjs/modules/gsoc.js +0 -16
- package/dist/mjs/modules/pss.js +0 -43
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/modules/bytes.d.ts +0 -35
- package/dist/types/modules/bzz.d.ts +0 -40
- package/dist/types/modules/debug/balance.d.ts +0 -28
- package/dist/types/modules/debug/chequebook.d.ts +0 -60
- package/dist/types/modules/debug/connectivity.d.ts +0 -9
- package/dist/types/modules/debug/settlements.d.ts +0 -15
- package/dist/types/modules/debug/stake.d.ts +0 -30
- package/dist/types/modules/debug/stamps.d.ts +0 -11
- package/dist/types/modules/debug/states.d.ts +0 -23
- package/dist/types/modules/debug/status.d.ts +0 -46
- package/dist/types/modules/debug/transactions.d.ts +0 -30
- package/dist/types/modules/gsoc.d.ts +0 -6
- package/dist/types/modules/pinning.d.ts +0 -30
- package/dist/types/modules/pss.d.ts +0 -22
- package/dist/types/modules/stewardship.d.ts +0 -10
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
- /package/dist/cjs/{modules → api}/rchash.js +0 -0
- /package/dist/mjs/{modules → api}/rchash.js +0 -0
- /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
|
+
}
|
|
@@ -4,22 +4,16 @@ exports.upload = upload;
|
|
|
4
4
|
exports.head = head;
|
|
5
5
|
exports.download = download;
|
|
6
6
|
exports.downloadReadable = downloadReadable;
|
|
7
|
+
const swarm_core_1 = require("swarm-core");
|
|
7
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
9
|
const upload_1 = require("../types/schema/upload");
|
|
9
|
-
const bytes_1 = require("../utils/bytes");
|
|
10
10
|
const headers_1 = require("../utils/headers");
|
|
11
11
|
const http_1 = require("../utils/http");
|
|
12
12
|
const schema_1 = require("../utils/schema");
|
|
13
13
|
const type_1 = require("../utils/type");
|
|
14
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
15
14
|
const endpoint = 'bytes';
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
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
|
|
16
|
+
* Raw HTTP calls for the `/bytes` endpoint.
|
|
23
17
|
*/
|
|
24
18
|
async function upload(requestOptions, data, postageBatchId, options) {
|
|
25
19
|
const response = await (0, http_1.http)(requestOptions, {
|
|
@@ -37,18 +31,11 @@ async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
37
31
|
reference: body.reference,
|
|
38
32
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
39
33
|
historyAddress: response.headers['swarm-act-history-address']
|
|
40
|
-
? cafe_utility_1.Optional.of(new
|
|
34
|
+
? cafe_utility_1.Optional.of(new swarm_core_1.Reference(response.headers['swarm-act-history-address']))
|
|
41
35
|
: cafe_utility_1.Optional.empty(),
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Requests content length for a reference
|
|
46
|
-
*
|
|
47
|
-
* @param requestOptions Options for making requests
|
|
48
|
-
* @param hash Bee content reference
|
|
49
|
-
*/
|
|
50
38
|
async function head(requestOptions, reference) {
|
|
51
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
52
39
|
const response = await (0, http_1.http)(requestOptions, {
|
|
53
40
|
url: `${endpoint}/${reference}`,
|
|
54
41
|
method: 'head',
|
|
@@ -58,12 +45,6 @@ async function head(requestOptions, reference) {
|
|
|
58
45
|
contentLength: parseInt(response.headers['content-length']),
|
|
59
46
|
};
|
|
60
47
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Download data as a byte array
|
|
63
|
-
*
|
|
64
|
-
* @param requestOptions Options for making requests
|
|
65
|
-
* @param hash Bee content reference
|
|
66
|
-
*/
|
|
67
48
|
async function download(requestOptions, resource, options) {
|
|
68
49
|
if (options) {
|
|
69
50
|
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
@@ -73,14 +54,8 @@ async function download(requestOptions, resource, options) {
|
|
|
73
54
|
url: `${endpoint}/${resource}`,
|
|
74
55
|
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
75
56
|
});
|
|
76
|
-
return new
|
|
57
|
+
return new swarm_core_1.Bytes(response.data);
|
|
77
58
|
}
|
|
78
|
-
/**
|
|
79
|
-
* Download data as a readable stream
|
|
80
|
-
*
|
|
81
|
-
* @param requestOptions Options for making requests
|
|
82
|
-
* @param hash Bee content reference
|
|
83
|
-
*/
|
|
84
59
|
async function downloadReadable(requestOptions, resource, options) {
|
|
85
60
|
if (options) {
|
|
86
61
|
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
@@ -4,24 +4,17 @@ exports.uploadFile = uploadFile;
|
|
|
4
4
|
exports.downloadFile = downloadFile;
|
|
5
5
|
exports.downloadFileReadable = downloadFileReadable;
|
|
6
6
|
exports.uploadCollection = uploadCollection;
|
|
7
|
+
const swarm_core_1 = require("swarm-core");
|
|
7
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
9
|
const upload_1 = require("../types/schema/upload");
|
|
9
|
-
const bytes_1 = require("../utils/bytes");
|
|
10
10
|
const collection_1 = require("../utils/collection");
|
|
11
11
|
const headers_1 = require("../utils/headers");
|
|
12
12
|
const http_1 = require("../utils/http");
|
|
13
13
|
const tar_uploader_1 = require("../utils/tar-uploader");
|
|
14
14
|
const type_1 = require("../utils/type");
|
|
15
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
16
15
|
const bzzEndpoint = 'bzz';
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
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
|
|
17
|
+
* Raw HTTP calls for the `/bzz` endpoint.
|
|
25
18
|
*/
|
|
26
19
|
async function uploadFile(requestOptions, data, postageBatchId, name, options) {
|
|
27
20
|
if ((0, type_1.isReadable)(data) && !options?.contentType) {
|
|
@@ -43,17 +36,10 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
|
|
|
43
36
|
reference: body.reference,
|
|
44
37
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
45
38
|
historyAddress: response.headers['swarm-act-history-address']
|
|
46
|
-
? cafe_utility_1.Optional.of(new
|
|
39
|
+
? cafe_utility_1.Optional.of(new swarm_core_1.Reference(response.headers['swarm-act-history-address']))
|
|
47
40
|
: cafe_utility_1.Optional.empty(),
|
|
48
41
|
};
|
|
49
42
|
}
|
|
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
43
|
async function downloadFile(requestOptions, resource, path = '', options) {
|
|
58
44
|
const response = await (0, http_1.http)(requestOptions, {
|
|
59
45
|
method: 'GET',
|
|
@@ -63,19 +49,12 @@ async function downloadFile(requestOptions, resource, path = '', options) {
|
|
|
63
49
|
});
|
|
64
50
|
const file = {
|
|
65
51
|
...(0, headers_1.readFileHeaders)(response.headers),
|
|
66
|
-
data: new
|
|
52
|
+
data: new swarm_core_1.Bytes(response.data),
|
|
67
53
|
};
|
|
68
54
|
return file;
|
|
69
55
|
}
|
|
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
56
|
async function downloadFileReadable(requestOptions, reference, path = '', options) {
|
|
78
|
-
reference = new
|
|
57
|
+
reference = new swarm_core_1.Reference(reference);
|
|
79
58
|
const response = await (0, http_1.http)(requestOptions, {
|
|
80
59
|
method: 'GET',
|
|
81
60
|
responseType: 'stream',
|
|
@@ -90,13 +69,6 @@ async function downloadFileReadable(requestOptions, reference, path = '', option
|
|
|
90
69
|
}
|
|
91
70
|
/*******************************************************************************************************************/
|
|
92
71
|
// 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
72
|
async function uploadCollection(requestOptions, collection, postageBatchId, options) {
|
|
101
73
|
(0, collection_1.assertCollection)(collection);
|
|
102
74
|
const response = await (0, tar_uploader_1.uploadTar)(requestOptions, collection, postageBatchId, options);
|
|
@@ -105,7 +77,7 @@ async function uploadCollection(requestOptions, collection, postageBatchId, opti
|
|
|
105
77
|
reference: body.reference,
|
|
106
78
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
107
79
|
historyAddress: response.headers['swarm-act-history-address']
|
|
108
|
-
? cafe_utility_1.Optional.of(new
|
|
80
|
+
? cafe_utility_1.Optional.of(new swarm_core_1.Reference(response.headers['swarm-act-history-address']))
|
|
109
81
|
: cafe_utility_1.Optional.empty(),
|
|
110
82
|
};
|
|
111
83
|
}
|
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
|
29
|
+
url: `${chequebookEndpoint}/balance`,
|
|
35
30
|
responseType: 'json',
|
|
36
31
|
});
|
|
37
32
|
return chequebook_1.GetChequebookBalanceResponse.parse(response.data);
|
|
38
33
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
41
|
+
method: 'post',
|
|
42
|
+
url: `${chequebookEndpoint}/deposit`,
|
|
48
43
|
responseType: 'json',
|
|
44
|
+
params: { amount },
|
|
45
|
+
headers,
|
|
49
46
|
});
|
|
50
|
-
return chequebook_1.
|
|
47
|
+
return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
|
|
51
48
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
57
|
+
url: `${chequebookEndpoint}/withdraw`,
|
|
63
58
|
responseType: 'json',
|
|
64
|
-
|
|
59
|
+
params: { amount },
|
|
60
|
+
headers,
|
|
65
61
|
});
|
|
66
62
|
return chequebook_1.TransactionHashResponse.parse(response.data).transactionHash;
|
|
67
63
|
}
|
|
68
|
-
/**
|
|
69
|
-
|
|
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
|
|
67
|
+
url: `${chequebookEndpoint}/cheque`,
|
|
77
68
|
responseType: 'json',
|
|
78
69
|
});
|
|
79
|
-
return chequebook_1.
|
|
70
|
+
return chequebook_1.GetLastChequesResponse.parse(response.data);
|
|
80
71
|
}
|
|
81
|
-
/**
|
|
82
|
-
|
|
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
|
|
75
|
+
url: `${chequebookEndpoint}/cheque/${peer}`,
|
|
89
76
|
responseType: 'json',
|
|
90
77
|
});
|
|
91
|
-
return chequebook_1.
|
|
78
|
+
return chequebook_1.GetLastChequesForPeerResponse.parse(response.data);
|
|
92
79
|
}
|
|
93
|
-
/**
|
|
94
|
-
|
|
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
|
-
|
|
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.
|
|
86
|
+
return chequebook_1.GetLastCashoutActionResponse.parse(response.data);
|
|
114
87
|
}
|
|
115
|
-
/**
|
|
116
|
-
|
|
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
|
|
92
|
+
url: `${chequebookEndpoint}/cashout/${peer}`,
|
|
131
93
|
responseType: 'json',
|
|
132
|
-
|
|
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 swarm_core_1 = require("swarm-core");
|
|
6
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
7
|
+
const upload_1 = require("../types/schema/upload");
|
|
8
|
+
const headers_1 = require("../utils/headers");
|
|
9
|
+
const http_1 = require("../utils/http");
|
|
10
|
+
const type_1 = require("../utils/type");
|
|
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 swarm_core_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 swarm_core_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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.postEnvelope = postEnvelope;
|
|
4
|
+
const swarm_core_1 = require("swarm-core");
|
|
4
5
|
const envelope_1 = require("../types/schema/envelope");
|
|
5
6
|
const http_1 = require("../utils/http");
|
|
6
7
|
const ENVELOPE_ENDPOINT = 'envelope';
|
|
@@ -15,10 +16,10 @@ async function postEnvelope(requestOptions, postageBatchId, reference) {
|
|
|
15
16
|
});
|
|
16
17
|
const body = envelope_1.PostEnvelopeBodyResponse.parse(response.data);
|
|
17
18
|
return {
|
|
18
|
-
issuer: body.issuer,
|
|
19
|
+
issuer: new swarm_core_1.EthAddress(body.issuer),
|
|
19
20
|
index: body.index,
|
|
20
21
|
timestamp: body.timestamp,
|
|
21
|
-
signature: body.signature,
|
|
22
|
+
signature: new swarm_core_1.Signature(body.signature),
|
|
22
23
|
batchId: postageBatchId,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFeedManifest = createFeedManifest;
|
|
4
|
+
exports.fetchLatestFeedUpdate = fetchLatestFeedUpdate;
|
|
5
|
+
exports.probeFeed = probeFeed;
|
|
6
|
+
const swarm_core_1 = require("swarm-core");
|
|
7
|
+
const upload_1 = require("../types/schema/upload");
|
|
8
|
+
const error_1 = require("../utils/error");
|
|
9
|
+
const headers_1 = require("../utils/headers");
|
|
10
|
+
const http_1 = require("../utils/http");
|
|
11
|
+
const feedEndpoint = 'feeds';
|
|
12
|
+
async function createFeedManifest(requestOptions, owner, topic, stamp, options) {
|
|
13
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
14
|
+
method: 'post',
|
|
15
|
+
responseType: 'json',
|
|
16
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
17
|
+
headers: (0, headers_1.prepareRequestHeaders)(stamp, options),
|
|
18
|
+
});
|
|
19
|
+
return upload_1.UploadResultBody.parse(response.data).reference;
|
|
20
|
+
}
|
|
21
|
+
function readFeedUpdateHeaders(headers) {
|
|
22
|
+
const feedIndex = headers['swarm-feed-index'];
|
|
23
|
+
const feedIndexNext = headers['swarm-feed-index-next'];
|
|
24
|
+
if (!feedIndex) {
|
|
25
|
+
throw new error_1.BeeError('Response did not contain expected swarm-feed-index!');
|
|
26
|
+
}
|
|
27
|
+
if (!feedIndexNext) {
|
|
28
|
+
throw new error_1.BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
feedIndex: new swarm_core_1.FeedIndex(feedIndex),
|
|
32
|
+
feedIndexNext: new swarm_core_1.FeedIndex(feedIndexNext),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
|
|
36
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
37
|
+
responseType: 'arraybuffer',
|
|
38
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
39
|
+
params: { ...options },
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
payload: new swarm_core_1.Bytes(response.data),
|
|
43
|
+
...readFeedUpdateHeaders(response.headers),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async function probeFeed(requestOptions, owner, topic) {
|
|
47
|
+
const response = await (0, http_1.http)(requestOptions, {
|
|
48
|
+
responseType: 'arraybuffer',
|
|
49
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
50
|
+
params: {
|
|
51
|
+
'Swarm-Only-Root-Chunk': true,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return readFeedUpdateHeaders(response.headers);
|
|
55
|
+
}
|