@ethersphere/bee-js 5.1.1 → 5.1.2
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/README.md +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/utils/eth.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -106,7 +97,6 @@ exports.isHexEthAddress = isHexEthAddress;
|
|
|
106
97
|
* @return little-endian encoded hexstring
|
|
107
98
|
*/
|
|
108
99
|
function toLittleEndian(bigEndian, pad = 2) {
|
|
109
|
-
var _a;
|
|
110
100
|
if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
|
|
111
101
|
throw new TypeError('minimal padding for conversion needs to be positive even integer');
|
|
112
102
|
}
|
|
@@ -122,7 +112,7 @@ function toLittleEndian(bigEndian, pad = 2) {
|
|
|
122
112
|
if (hexRep.length % 2 !== 0)
|
|
123
113
|
hexRep = hexRep.padStart(hexRep.length + 1, '0');
|
|
124
114
|
// Match all two pairs in the hexstring, reverse the pairs and join it again
|
|
125
|
-
const littleEndian =
|
|
115
|
+
const littleEndian = hexRep.match(/../g)?.reverse().join('');
|
|
126
116
|
if (littleEndian)
|
|
127
117
|
return littleEndian;
|
|
128
118
|
throw new Error('failed to convert');
|
|
@@ -175,37 +165,35 @@ exports.ethToSwarmAddress = ethToSwarmAddress;
|
|
|
175
165
|
* @param provider Injected web3 provider like window.ethereum or other compatible with EIP-1193
|
|
176
166
|
* @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
|
|
177
167
|
*/
|
|
178
|
-
function makeEthereumWalletSigner(provider, ethAddress) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
};
|
|
209
|
-
});
|
|
168
|
+
async function makeEthereumWalletSigner(provider, ethAddress) {
|
|
169
|
+
let executorFnc;
|
|
170
|
+
if (typeof provider !== 'object' || provider === null) {
|
|
171
|
+
throw new TypeError('We need JsonRPC provider object!');
|
|
172
|
+
}
|
|
173
|
+
if (provider.request) {
|
|
174
|
+
executorFnc = provider.request;
|
|
175
|
+
}
|
|
176
|
+
else if (provider.sendAsync) {
|
|
177
|
+
executorFnc = provider.sendAsync;
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
throw new Error('Incompatible interface of given provider!');
|
|
181
|
+
}
|
|
182
|
+
if (!ethAddress) {
|
|
183
|
+
ethAddress = (await executorFnc({ method: 'eth_requestAccounts' }))[0];
|
|
184
|
+
}
|
|
185
|
+
const bytesEthAddress = makeEthAddress(ethAddress);
|
|
186
|
+
const hexEthAddress = makeHexEthAddress(ethAddress);
|
|
187
|
+
return {
|
|
188
|
+
address: bytesEthAddress,
|
|
189
|
+
sign: async (data) => {
|
|
190
|
+
const result = await executorFnc({
|
|
191
|
+
jsonrpc: '2.0',
|
|
192
|
+
method: 'personal_sign',
|
|
193
|
+
params: ['0x' + data.hex(), '0x' + hexEthAddress],
|
|
194
|
+
});
|
|
195
|
+
return result;
|
|
196
|
+
},
|
|
197
|
+
};
|
|
210
198
|
}
|
|
211
199
|
exports.makeEthereumWalletSigner = makeEthereumWalletSigner;
|
package/dist/cjs/utils/file.js
CHANGED
|
@@ -4,15 +4,6 @@
|
|
|
4
4
|
*
|
|
5
5
|
* https://developer.mozilla.org/en-US/docs/Web/API/File
|
|
6
6
|
*/
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
8
|
exports.fileArrayBuffer = exports.isFile = void 0;
|
|
18
9
|
function isFile(file) {
|
|
@@ -33,17 +24,15 @@ exports.isFile = isFile;
|
|
|
33
24
|
*
|
|
34
25
|
* @param file A File object
|
|
35
26
|
*/
|
|
36
|
-
function fileArrayBuffer(file) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fr.readAsArrayBuffer(file);
|
|
46
|
-
});
|
|
27
|
+
async function fileArrayBuffer(file) {
|
|
28
|
+
if (file.arrayBuffer) {
|
|
29
|
+
return file.arrayBuffer();
|
|
30
|
+
}
|
|
31
|
+
// workaround for Safari where arrayBuffer is not supported on Files
|
|
32
|
+
return new Promise(resolve => {
|
|
33
|
+
const fr = new FileReader();
|
|
34
|
+
fr.onload = () => resolve(fr.result);
|
|
35
|
+
fr.readAsArrayBuffer(file);
|
|
47
36
|
});
|
|
48
37
|
}
|
|
49
38
|
exports.fileArrayBuffer = fileArrayBuffer;
|
|
@@ -46,13 +46,13 @@ function extractUploadHeaders(postageBatchId, options) {
|
|
|
46
46
|
const headers = {
|
|
47
47
|
'swarm-postage-batch-id': postageBatchId,
|
|
48
48
|
};
|
|
49
|
-
if (options
|
|
49
|
+
if (options?.pin)
|
|
50
50
|
headers['swarm-pin'] = String(options.pin);
|
|
51
|
-
if (options
|
|
51
|
+
if (options?.encrypt)
|
|
52
52
|
headers['swarm-encrypt'] = String(options.encrypt);
|
|
53
|
-
if (options
|
|
53
|
+
if (options?.tag)
|
|
54
54
|
headers['swarm-tag'] = String(options.tag);
|
|
55
|
-
if (typeof
|
|
55
|
+
if (typeof options?.deferred === 'boolean')
|
|
56
56
|
headers['swarm-deferred-upload'] = options.deferred.toString();
|
|
57
57
|
return headers;
|
|
58
58
|
}
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
3
|
+
exports.http = exports.filterHeaders = exports.wrapResponseClosure = exports.wrapRequestClosure = exports.DEFAULT_KY_CONFIG = void 0;
|
|
27
4
|
const error_1 = require("./error");
|
|
28
|
-
const ky_universal_1 = __importDefault(require("ky-universal"));
|
|
29
5
|
const stream_1 = require("./stream");
|
|
30
|
-
const merge_1 = require("./merge");
|
|
31
6
|
const type_1 = require("./type");
|
|
32
|
-
const
|
|
7
|
+
const merge_1 = require("./merge");
|
|
8
|
+
exports.DEFAULT_KY_CONFIG = {
|
|
33
9
|
headers: {
|
|
34
10
|
accept: 'application/json, text/plain, */*',
|
|
35
11
|
'user-agent': `bee-js`,
|
|
@@ -55,20 +31,20 @@ function wrapRequest(request) {
|
|
|
55
31
|
};
|
|
56
32
|
}
|
|
57
33
|
function wrapRequestClosure(cb) {
|
|
58
|
-
return (request) =>
|
|
59
|
-
|
|
60
|
-
}
|
|
34
|
+
return async (request) => {
|
|
35
|
+
await cb(wrapRequest(request));
|
|
36
|
+
};
|
|
61
37
|
}
|
|
62
38
|
exports.wrapRequestClosure = wrapRequestClosure;
|
|
63
39
|
function wrapResponseClosure(cb) {
|
|
64
|
-
return (request, options, response) =>
|
|
65
|
-
|
|
40
|
+
return async (request, options, response) => {
|
|
41
|
+
await cb({
|
|
66
42
|
headers: headersToObject(response.headers),
|
|
67
43
|
status: response.status,
|
|
68
44
|
statusText: response.statusText,
|
|
69
45
|
request: wrapRequest(request),
|
|
70
46
|
});
|
|
71
|
-
}
|
|
47
|
+
};
|
|
72
48
|
}
|
|
73
49
|
exports.wrapResponseClosure = wrapResponseClosure;
|
|
74
50
|
/**
|
|
@@ -97,76 +73,85 @@ function filterHeaders(obj) {
|
|
|
97
73
|
exports.filterHeaders = filterHeaders;
|
|
98
74
|
/**
|
|
99
75
|
* Main utility function to make HTTP requests.
|
|
100
|
-
* @param
|
|
76
|
+
* @param kyOptions
|
|
101
77
|
* @param config
|
|
102
78
|
*/
|
|
103
|
-
function http(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case 'arraybuffer':
|
|
116
|
-
response.data = (yield response.arrayBuffer());
|
|
117
|
-
break;
|
|
118
|
-
case 'json':
|
|
119
|
-
try {
|
|
120
|
-
response.data = (yield response.json());
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
throw new error_1.BeeNotAJsonError();
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
default:
|
|
127
|
-
break; // If responseType is not set, then no data are expected
|
|
128
|
-
}
|
|
129
|
-
return response;
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
// Passthrough thrown errors
|
|
133
|
-
if (e instanceof error_1.BeeNotAJsonError) {
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
if (isHttpError(e)) {
|
|
137
|
-
let message;
|
|
138
|
-
// We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
|
|
139
|
-
// to the user in the BeeResponseError, for further analysis.
|
|
140
|
-
const body = yield e.response.text();
|
|
141
|
-
try {
|
|
142
|
-
// The response can be Bee's JSON with structure `{code, message}` lets try to parse it
|
|
143
|
-
message = JSON.parse(body).message;
|
|
79
|
+
async function http(kyOptions, config) {
|
|
80
|
+
try {
|
|
81
|
+
const ky = await getKy();
|
|
82
|
+
const { path, responseType, ...kyConfig } = (0, merge_1.deepMerge)(kyOptions, config);
|
|
83
|
+
const response = (await ky(path, {
|
|
84
|
+
...kyConfig,
|
|
85
|
+
searchParams: filterHeaders(kyConfig.searchParams),
|
|
86
|
+
}));
|
|
87
|
+
switch (responseType) {
|
|
88
|
+
case 'stream':
|
|
89
|
+
if (!response.body) {
|
|
90
|
+
throw new error_1.BeeError('Response was expected to get data but did not get any!');
|
|
144
91
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
92
|
+
response.parsedData = (0, stream_1.normalizeToReadableStream)(response.body);
|
|
93
|
+
break;
|
|
94
|
+
case 'arraybuffer':
|
|
95
|
+
response.parsedData = (await response.arrayBuffer());
|
|
96
|
+
break;
|
|
97
|
+
case 'json':
|
|
98
|
+
try {
|
|
99
|
+
response.parsedData = (await response.json());
|
|
148
100
|
}
|
|
149
|
-
|
|
150
|
-
throw new error_1.
|
|
101
|
+
catch (e) {
|
|
102
|
+
throw new error_1.BeeNotAJsonError();
|
|
151
103
|
}
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
break; // If responseType is not set, then no data are expected
|
|
107
|
+
}
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
// Passthrough thrown errors
|
|
112
|
+
if (e instanceof error_1.BeeNotAJsonError) {
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
if (isHttpError(e)) {
|
|
116
|
+
let message;
|
|
117
|
+
// We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
|
|
118
|
+
// to the user in the BeeResponseError, for further analysis.
|
|
119
|
+
const body = await e.response.text();
|
|
120
|
+
try {
|
|
121
|
+
// The response can be Bee's JSON with structure `{code, message}` lets try to parse it
|
|
122
|
+
message = JSON.parse(body).message;
|
|
152
123
|
}
|
|
153
|
-
|
|
154
|
-
|
|
124
|
+
catch (e) { }
|
|
125
|
+
if (message) {
|
|
126
|
+
throw new error_1.BeeResponseError(e.response.status, e.response, body, config, `${e.response.statusText}: ${message}`);
|
|
155
127
|
}
|
|
156
128
|
else {
|
|
157
|
-
|
|
158
|
-
// message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
|
|
159
|
-
// expose the underlying problem.
|
|
160
|
-
if (e.cause) {
|
|
161
|
-
throw new error_1.BeeError(e.cause.message);
|
|
162
|
-
}
|
|
163
|
-
throw new error_1.BeeError(e.message);
|
|
129
|
+
throw new error_1.BeeResponseError(e.response.status, e.response, body, config, e.response.statusText);
|
|
164
130
|
}
|
|
165
131
|
}
|
|
166
|
-
|
|
132
|
+
else if (isHttpRequestError(e)) {
|
|
133
|
+
throw new error_1.BeeRequestError(e.message, config);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
// Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
|
|
137
|
+
// message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
|
|
138
|
+
// expose the underlying problem.
|
|
139
|
+
if (e.cause) {
|
|
140
|
+
throw new error_1.BeeError(e.cause.message);
|
|
141
|
+
}
|
|
142
|
+
throw new error_1.BeeError(e.message);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
167
145
|
}
|
|
168
146
|
exports.http = http;
|
|
169
|
-
|
|
170
|
-
|
|
147
|
+
let ky;
|
|
148
|
+
async function getKy() {
|
|
149
|
+
if (ky) {
|
|
150
|
+
return ky;
|
|
151
|
+
}
|
|
152
|
+
ky = (await import('ky-universal')).default;
|
|
153
|
+
if (!ky) {
|
|
154
|
+
throw new Error('Ky was not found while it should have been!');
|
|
155
|
+
}
|
|
156
|
+
return ky;
|
|
171
157
|
}
|
|
172
|
-
exports.makeDefaultKy = makeDefaultKy;
|
package/dist/cjs/utils/merge.js
CHANGED
|
@@ -25,7 +25,7 @@ function deepMerge(...sources) {
|
|
|
25
25
|
if ((0, type_1.isObject)(value) && key in returnValue) {
|
|
26
26
|
value = deepMerge(returnValue[key], value);
|
|
27
27
|
}
|
|
28
|
-
returnValue =
|
|
28
|
+
returnValue = { ...returnValue, [key]: value };
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
package/dist/cjs/utils/sleep.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.sleep = void 0;
|
|
13
4
|
/**
|
|
@@ -15,9 +6,7 @@ exports.sleep = void 0;
|
|
|
15
6
|
*
|
|
16
7
|
* @param ms Number of miliseconds to sleep
|
|
17
8
|
*/
|
|
18
|
-
function sleep(ms) {
|
|
19
|
-
return
|
|
20
|
-
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
21
|
-
});
|
|
9
|
+
async function sleep(ms) {
|
|
10
|
+
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
22
11
|
}
|
|
23
12
|
exports.sleep = sleep;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -140,14 +140,13 @@ exports.assertReferenceOrEns = assertReferenceOrEns;
|
|
|
140
140
|
* @param expectedCidType
|
|
141
141
|
*/
|
|
142
142
|
function makeReferenceOrEns(value, expectedCidType) {
|
|
143
|
-
var _a;
|
|
144
143
|
if (typeof value !== 'string') {
|
|
145
144
|
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
146
145
|
}
|
|
147
146
|
try {
|
|
148
147
|
const result = (0, swarm_cid_1.decodeCid)(value);
|
|
149
148
|
if (result.type !== expectedCidType) {
|
|
150
|
-
throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${
|
|
149
|
+
throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
|
|
151
150
|
}
|
|
152
151
|
return result.reference;
|
|
153
152
|
}
|
|
@@ -165,9 +164,12 @@ exports.makeReferenceOrEns = makeReferenceOrEns;
|
|
|
165
164
|
* @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
|
|
166
165
|
*/
|
|
167
166
|
function addCidConversionFunction(result, cidType) {
|
|
168
|
-
return
|
|
167
|
+
return {
|
|
168
|
+
...result,
|
|
169
|
+
cid() {
|
|
169
170
|
return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
|
|
170
|
-
}
|
|
171
|
+
},
|
|
172
|
+
};
|
|
171
173
|
}
|
|
172
174
|
exports.addCidConversionFunction = addCidConversionFunction;
|
|
173
175
|
function assertAddress(value) {
|
|
@@ -308,16 +310,16 @@ function assertPostageBatchOptions(value) {
|
|
|
308
310
|
assertStrictlyObject(value);
|
|
309
311
|
const options = value;
|
|
310
312
|
assertRequestOptions(options, 'PostageBatchOptions');
|
|
311
|
-
if (options
|
|
313
|
+
if (options?.gasPrice) {
|
|
312
314
|
assertNonNegativeInteger(options.gasPrice);
|
|
313
315
|
}
|
|
314
|
-
if (
|
|
316
|
+
if (options?.immutableFlag !== undefined) {
|
|
315
317
|
assertBoolean(options.immutableFlag);
|
|
316
318
|
}
|
|
317
|
-
if (
|
|
319
|
+
if (options?.waitForUsable !== undefined) {
|
|
318
320
|
assertBoolean(options.waitForUsable);
|
|
319
321
|
}
|
|
320
|
-
if (
|
|
322
|
+
if (options?.waitForUsableTimeout !== undefined) {
|
|
321
323
|
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
322
324
|
}
|
|
323
325
|
}
|
|
@@ -328,10 +330,10 @@ function assertTransactionOptions(value, name = 'TransactionOptions') {
|
|
|
328
330
|
}
|
|
329
331
|
assertStrictlyObject(value, name);
|
|
330
332
|
const options = value;
|
|
331
|
-
if (options
|
|
333
|
+
if (options?.gasLimit) {
|
|
332
334
|
assertNonNegativeInteger(options.gasLimit, name);
|
|
333
335
|
}
|
|
334
|
-
if (options
|
|
336
|
+
if (options?.gasPrice) {
|
|
335
337
|
assertNonNegativeInteger(options.gasPrice, name);
|
|
336
338
|
}
|
|
337
339
|
}
|
|
@@ -378,7 +380,7 @@ function assertAllTagsOptions(entry) {
|
|
|
378
380
|
}
|
|
379
381
|
assertRequestOptions(entry, 'AllTagsOptions');
|
|
380
382
|
const options = entry;
|
|
381
|
-
if (
|
|
383
|
+
if (options?.limit !== undefined) {
|
|
382
384
|
if (typeof options.limit !== 'number') {
|
|
383
385
|
throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
|
|
384
386
|
}
|
|
@@ -389,7 +391,7 @@ function assertAllTagsOptions(entry) {
|
|
|
389
391
|
throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
|
|
390
392
|
}
|
|
391
393
|
}
|
|
392
|
-
if (
|
|
394
|
+
if (options?.offset !== undefined) {
|
|
393
395
|
assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
|
|
394
396
|
}
|
|
395
397
|
}
|