@ethersphere/bee-js 12.2.2 → 12.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/bee.js +56 -23
- package/dist/cjs/chunk/cac.js +4 -2
- package/dist/cjs/feed/index.js +3 -1
- package/dist/cjs/modules/bytes.js +6 -4
- package/dist/cjs/modules/bzz.js +5 -4
- package/dist/cjs/modules/chunk.js +3 -2
- package/dist/cjs/modules/debug/balance.js +5 -29
- package/dist/cjs/modules/debug/chequebook.js +9 -58
- package/dist/cjs/modules/debug/connectivity.js +5 -82
- package/dist/cjs/modules/debug/settlements.js +3 -22
- package/dist/cjs/modules/debug/stake.js +8 -33
- package/dist/cjs/modules/debug/stamps.js +27 -53
- package/dist/cjs/modules/debug/states.js +6 -31
- package/dist/cjs/modules/debug/status.js +7 -39
- package/dist/cjs/modules/debug/transactions.js +5 -26
- package/dist/cjs/modules/envelope.js +6 -6
- package/dist/cjs/modules/feed.js +3 -4
- package/dist/cjs/modules/grantee.js +8 -10
- package/dist/cjs/modules/pinning.js +5 -11
- package/dist/cjs/modules/rchash.js +2 -3
- package/dist/cjs/modules/soc.js +3 -2
- package/dist/cjs/modules/status.js +3 -3
- package/dist/cjs/modules/stewardship.js +2 -3
- package/dist/cjs/modules/tag.js +4 -35
- package/dist/cjs/stamper/stamper.js +2 -1
- package/dist/cjs/types/schema/balance.js +14 -0
- package/dist/cjs/types/schema/chequebook.js +49 -0
- package/dist/cjs/types/schema/connectivity.js +46 -0
- package/dist/cjs/types/schema/envelope.js +11 -0
- package/dist/cjs/types/schema/grantee.js +10 -0
- package/dist/cjs/types/schema/pinning.js +7 -0
- package/dist/cjs/types/schema/rchash.js +7 -0
- package/dist/cjs/types/schema/settlements.js +17 -0
- package/dist/cjs/types/schema/stake.js +33 -0
- package/dist/cjs/types/schema/stamps.js +48 -0
- package/dist/cjs/types/schema/states.js +34 -0
- package/dist/cjs/types/schema/status.js +39 -0
- package/dist/cjs/types/schema/stewardship.js +7 -0
- package/dist/cjs/types/schema/tag.js +20 -0
- package/dist/cjs/types/schema/transactions.js +24 -0
- package/dist/cjs/types/schema/upload.js +8 -0
- package/dist/cjs/utils/bad-ports.js +92 -0
- package/dist/cjs/utils/bytes.js +5 -3
- package/dist/cjs/utils/error.js +1 -0
- package/dist/cjs/utils/headers.js +19 -13
- package/dist/cjs/utils/hex-schema.js +8 -0
- package/dist/cjs/utils/http.js +92 -52
- package/dist/cjs/utils/resource-locator.js +4 -3
- package/dist/cjs/utils/schema.js +88 -0
- package/dist/cjs/utils/stamps.js +2 -1
- package/dist/cjs/utils/type.js +12 -130
- package/dist/cjs/utils/url.js +24 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +59 -30
- package/dist/mjs/chunk/cac.js +5 -3
- package/dist/mjs/feed/index.js +4 -2
- package/dist/mjs/modules/bytes.js +8 -8
- package/dist/mjs/modules/bzz.js +6 -9
- package/dist/mjs/modules/chunk.js +4 -7
- package/dist/mjs/modules/debug/balance.js +5 -61
- package/dist/mjs/modules/debug/chequebook.js +9 -114
- package/dist/mjs/modules/debug/connectivity.js +5 -145
- package/dist/mjs/modules/debug/settlements.js +3 -46
- package/dist/mjs/modules/debug/stake.js +8 -85
- package/dist/mjs/modules/debug/stamps.js +24 -126
- package/dist/mjs/modules/debug/states.js +6 -71
- package/dist/mjs/modules/debug/status.js +7 -93
- package/dist/mjs/modules/debug/transactions.js +5 -60
- package/dist/mjs/modules/envelope.js +6 -20
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/grantee.js +8 -26
- package/dist/mjs/modules/pinning.js +7 -21
- package/dist/mjs/modules/rchash.js +2 -7
- package/dist/mjs/modules/soc.js +4 -5
- package/dist/mjs/modules/status.js +4 -4
- package/dist/mjs/modules/stewardship.js +2 -7
- package/dist/mjs/modules/tag.js +4 -93
- package/dist/mjs/stamper/stamper.js +2 -1
- package/dist/mjs/types/schema/balance.js +13 -0
- package/dist/mjs/types/schema/chequebook.js +53 -0
- package/dist/mjs/types/schema/connectivity.js +41 -0
- package/dist/mjs/types/schema/envelope.js +8 -0
- package/dist/mjs/types/schema/grantee.js +7 -0
- package/dist/mjs/types/schema/pinning.js +4 -0
- package/dist/mjs/types/schema/rchash.js +4 -0
- package/dist/mjs/types/schema/settlements.js +22 -0
- package/dist/mjs/types/schema/stake.js +40 -0
- package/dist/mjs/types/schema/stamps.js +47 -0
- package/dist/mjs/types/schema/states.js +34 -0
- package/dist/mjs/types/schema/status.js +36 -0
- package/dist/mjs/types/schema/stewardship.js +4 -0
- package/dist/mjs/types/schema/tag.js +14 -0
- package/dist/mjs/types/schema/transactions.js +25 -0
- package/dist/mjs/types/schema/upload.js +5 -0
- package/dist/mjs/utils/bad-ports.js +6 -0
- package/dist/mjs/utils/bytes.js +6 -8
- package/dist/mjs/utils/error.js +5 -0
- package/dist/mjs/utils/headers.js +19 -13
- package/dist/mjs/utils/hex-schema.js +2 -0
- package/dist/mjs/utils/http.js +97 -59
- package/dist/mjs/utils/resource-locator.js +4 -3
- package/dist/mjs/utils/schema.js +81 -0
- package/dist/mjs/utils/stamps.js +2 -1
- package/dist/mjs/utils/type.js +13 -233
- package/dist/mjs/utils/url.js +23 -0
- package/dist/types/bee.d.ts +23 -0
- package/dist/types/modules/debug/connectivity.d.ts +2 -2
- package/dist/types/modules/debug/stamps.d.ts +2 -0
- package/dist/types/modules/debug/status.d.ts +2 -2
- package/dist/types/types/debug.d.ts +1 -0
- package/dist/types/types/schema/balance.d.ts +12 -0
- package/dist/types/types/schema/chequebook.d.ts +104 -0
- package/dist/types/types/schema/connectivity.d.ts +49 -0
- package/dist/types/types/schema/envelope.d.ts +7 -0
- package/dist/types/types/schema/grantee.d.ts +7 -0
- package/dist/types/types/schema/pinning.d.ts +4 -0
- package/dist/types/types/schema/rchash.d.ts +4 -0
- package/dist/types/types/schema/settlements.d.ts +16 -0
- package/dist/types/types/schema/stake.d.ts +29 -0
- package/dist/types/types/schema/stamps.d.ts +77 -0
- package/dist/types/types/schema/states.d.ts +26 -0
- package/dist/types/types/schema/status.d.ts +38 -0
- package/dist/types/types/schema/stewardship.d.ts +4 -0
- package/dist/types/types/schema/tag.d.ts +23 -0
- package/dist/types/types/schema/transactions.d.ts +29 -0
- package/dist/types/types/schema/upload.d.ts +5 -0
- package/dist/types/utils/bad-ports.d.ts +6 -0
- package/dist/types/utils/error.d.ts +5 -0
- package/dist/types/utils/hex-schema.d.ts +2 -0
- package/dist/types/utils/http.d.ts +18 -3
- package/dist/types/utils/schema.d.ts +90 -0
- package/dist/types/utils/stamps.d.ts +1 -0
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -16
- package/dist/types/utils/url.d.ts +9 -0
- package/package.json +11 -11
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetAllTagsResponse = exports.TagSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.TagSchema = zod_1.z.object({
|
|
6
|
+
address: zod_1.z
|
|
7
|
+
.string()
|
|
8
|
+
.nullish()
|
|
9
|
+
.transform(v => v ?? ''),
|
|
10
|
+
seen: zod_1.z.number(),
|
|
11
|
+
sent: zod_1.z.number(),
|
|
12
|
+
split: zod_1.z.number(),
|
|
13
|
+
startedAt: zod_1.z.string(),
|
|
14
|
+
stored: zod_1.z.number(),
|
|
15
|
+
synced: zod_1.z.number(),
|
|
16
|
+
uid: zod_1.z.number(),
|
|
17
|
+
});
|
|
18
|
+
exports.GetAllTagsResponse = zod_1.z.object({
|
|
19
|
+
tags: zod_1.z.array(exports.TagSchema),
|
|
20
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionHashResponse = exports.GetTransactionResponse = exports.GetAllTransactionsResponse = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const type_1 = require("../../utils/type");
|
|
6
|
+
const typed_bytes_1 = require("../../utils/typed-bytes");
|
|
7
|
+
const TransactionInfoSchema = zod_1.z.object({
|
|
8
|
+
transactionHash: zod_1.z.string().transform(s => new typed_bytes_1.TransactionId(s)),
|
|
9
|
+
to: zod_1.z.string(),
|
|
10
|
+
nonce: zod_1.z.number(),
|
|
11
|
+
gasPrice: zod_1.z.string().transform(s => (0, type_1.asNumberString)(s, { name: 'gasPrice' })),
|
|
12
|
+
gasLimit: zod_1.z.number(),
|
|
13
|
+
data: zod_1.z.string(),
|
|
14
|
+
created: zod_1.z.string(),
|
|
15
|
+
description: zod_1.z.string(),
|
|
16
|
+
value: zod_1.z.string().transform(s => (0, type_1.asNumberString)(s, { name: 'value' })),
|
|
17
|
+
});
|
|
18
|
+
exports.GetAllTransactionsResponse = zod_1.z.object({
|
|
19
|
+
pendingTransactions: zod_1.z.array(TransactionInfoSchema),
|
|
20
|
+
});
|
|
21
|
+
exports.GetTransactionResponse = TransactionInfoSchema;
|
|
22
|
+
exports.TransactionHashResponse = zod_1.z.object({
|
|
23
|
+
transactionHash: zod_1.z.string().transform(s => new typed_bytes_1.TransactionId(s)),
|
|
24
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UploadResultBody = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const typed_bytes_1 = require("../../utils/typed-bytes");
|
|
6
|
+
exports.UploadResultBody = zod_1.z.object({
|
|
7
|
+
reference: zod_1.z.string().transform(s => new typed_bytes_1.Reference(s)),
|
|
8
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BAD_PORTS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Ports blocked by the WHATWG Fetch spec for HTTP/HTTPS requests.
|
|
6
|
+
*
|
|
7
|
+
* See: https://fetch.spec.whatwg.org/#port-blocking
|
|
8
|
+
*/
|
|
9
|
+
exports.BAD_PORTS = [
|
|
10
|
+
'1',
|
|
11
|
+
'7',
|
|
12
|
+
'9',
|
|
13
|
+
'11',
|
|
14
|
+
'13',
|
|
15
|
+
'15',
|
|
16
|
+
'17',
|
|
17
|
+
'19',
|
|
18
|
+
'20',
|
|
19
|
+
'21',
|
|
20
|
+
'22',
|
|
21
|
+
'23',
|
|
22
|
+
'25',
|
|
23
|
+
'37',
|
|
24
|
+
'42',
|
|
25
|
+
'43',
|
|
26
|
+
'53',
|
|
27
|
+
'69',
|
|
28
|
+
'77',
|
|
29
|
+
'79',
|
|
30
|
+
'87',
|
|
31
|
+
'95',
|
|
32
|
+
'101',
|
|
33
|
+
'102',
|
|
34
|
+
'103',
|
|
35
|
+
'104',
|
|
36
|
+
'109',
|
|
37
|
+
'110',
|
|
38
|
+
'111',
|
|
39
|
+
'113',
|
|
40
|
+
'115',
|
|
41
|
+
'117',
|
|
42
|
+
'119',
|
|
43
|
+
'123',
|
|
44
|
+
'135',
|
|
45
|
+
'137',
|
|
46
|
+
'139',
|
|
47
|
+
'143',
|
|
48
|
+
'161',
|
|
49
|
+
'179',
|
|
50
|
+
'389',
|
|
51
|
+
'427',
|
|
52
|
+
'465',
|
|
53
|
+
'512',
|
|
54
|
+
'513',
|
|
55
|
+
'514',
|
|
56
|
+
'515',
|
|
57
|
+
'526',
|
|
58
|
+
'530',
|
|
59
|
+
'531',
|
|
60
|
+
'532',
|
|
61
|
+
'540',
|
|
62
|
+
'548',
|
|
63
|
+
'554',
|
|
64
|
+
'556',
|
|
65
|
+
'563',
|
|
66
|
+
'587',
|
|
67
|
+
'601',
|
|
68
|
+
'636',
|
|
69
|
+
'989',
|
|
70
|
+
'990',
|
|
71
|
+
'993',
|
|
72
|
+
'995',
|
|
73
|
+
'1719',
|
|
74
|
+
'1720',
|
|
75
|
+
'1723',
|
|
76
|
+
'2049',
|
|
77
|
+
'3659',
|
|
78
|
+
'4045',
|
|
79
|
+
'4190',
|
|
80
|
+
'5060',
|
|
81
|
+
'5061',
|
|
82
|
+
'6000',
|
|
83
|
+
'6566',
|
|
84
|
+
'6665',
|
|
85
|
+
'6666',
|
|
86
|
+
'6667',
|
|
87
|
+
'6668',
|
|
88
|
+
'6669',
|
|
89
|
+
'6679',
|
|
90
|
+
'6697',
|
|
91
|
+
'10080',
|
|
92
|
+
];
|
package/dist/cjs/utils/bytes.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.Bytes = void 0;
|
|
|
7
7
|
exports.parseSizeToBytes = parseSizeToBytes;
|
|
8
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
9
|
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const hex_schema_1 = require("./hex-schema");
|
|
10
12
|
const debug = (0, debug_1.default)('bee-js:bytes');
|
|
11
13
|
const DECODER = new TextDecoder();
|
|
12
14
|
const ENCODER = new TextEncoder();
|
|
@@ -19,7 +21,7 @@ class Bytes {
|
|
|
19
21
|
this.bytes = bytes.bytes;
|
|
20
22
|
}
|
|
21
23
|
else if (typeof bytes === 'string') {
|
|
22
|
-
this.bytes = cafe_utility_1.Binary.hexToUint8Array(
|
|
24
|
+
this.bytes = cafe_utility_1.Binary.hexToUint8Array(hex_schema_1.HexStringSchema.parse(bytes));
|
|
23
25
|
}
|
|
24
26
|
else if (bytes instanceof ArrayBuffer) {
|
|
25
27
|
this.bytes = new Uint8Array(bytes);
|
|
@@ -30,9 +32,9 @@ class Bytes {
|
|
|
30
32
|
else {
|
|
31
33
|
const unknownInput = bytes;
|
|
32
34
|
const toHex = cafe_utility_1.Objects.getDeep(unknownInput, 'toHex');
|
|
33
|
-
if (
|
|
35
|
+
if (zod_1.z.function().safeParse(toHex).success) {
|
|
34
36
|
const hex = toHex.call(unknownInput);
|
|
35
|
-
this.bytes = cafe_utility_1.Binary.hexToUint8Array(
|
|
37
|
+
this.bytes = cafe_utility_1.Binary.hexToUint8Array(hex_schema_1.HexStringSchema.parse(hex));
|
|
36
38
|
}
|
|
37
39
|
else {
|
|
38
40
|
debug('bytes', bytes);
|
package/dist/cjs/utils/error.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readFileHeaders = readFileHeaders;
|
|
4
4
|
exports.prepareRequestHeaders = prepareRequestHeaders;
|
|
5
|
-
const
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
6
|
const error_1 = require("./error");
|
|
7
7
|
const stamps_1 = require("./stamps");
|
|
8
8
|
const typed_bytes_1 = require("./typed-bytes");
|
|
@@ -46,7 +46,7 @@ function prepareRequestHeaders(stamp, nullableOptions) {
|
|
|
46
46
|
if (!nullableOptions) {
|
|
47
47
|
return headers;
|
|
48
48
|
}
|
|
49
|
-
const options =
|
|
49
|
+
const options = nullableOptions;
|
|
50
50
|
if (options.size) {
|
|
51
51
|
headers['content-length'] = String(options.size);
|
|
52
52
|
}
|
|
@@ -56,26 +56,31 @@ function prepareRequestHeaders(stamp, nullableOptions) {
|
|
|
56
56
|
if (options.redundancyLevel) {
|
|
57
57
|
headers['swarm-redundancy-level'] = String(options.redundancyLevel);
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const act = zod_1.z.boolean().safeParse(options.act);
|
|
60
|
+
if (act.success) {
|
|
61
|
+
headers['swarm-act'] = String(act.data);
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const pin = zod_1.z.boolean().safeParse(options.pin);
|
|
64
|
+
if (pin.success) {
|
|
65
|
+
headers['swarm-pin'] = String(pin.data);
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
const encrypt = zod_1.z.boolean().safeParse(options.encrypt);
|
|
68
|
+
if (encrypt.success) {
|
|
69
|
+
headers['swarm-encrypt'] = String(encrypt.data);
|
|
67
70
|
}
|
|
68
71
|
if (options.tag) {
|
|
69
72
|
headers['swarm-tag'] = String(options.tag);
|
|
70
73
|
}
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
const deferred = zod_1.z.boolean().safeParse(options.deferred);
|
|
75
|
+
if (deferred.success) {
|
|
76
|
+
headers['swarm-deferred-upload'] = String(deferred.data);
|
|
73
77
|
}
|
|
74
78
|
if (options.redundancyStrategy) {
|
|
75
79
|
headers['swarm-redundancy-strategy'] = String(options.redundancyStrategy);
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
const fallback = zod_1.z.boolean().safeParse(options.fallback);
|
|
82
|
+
if (fallback.success) {
|
|
83
|
+
headers['swarm-redundancy-fallback-mode'] = String(fallback.data);
|
|
79
84
|
}
|
|
80
85
|
if (options.timeoutMs) {
|
|
81
86
|
headers['swarm-chunk-retrieval-timeout'] = String(options.timeoutMs);
|
|
@@ -107,7 +112,8 @@ function prepareRequestHeaders(stamp, nullableOptions) {
|
|
|
107
112
|
return headers;
|
|
108
113
|
}
|
|
109
114
|
function isEnvelopeWithBatchId(value) {
|
|
110
|
-
|
|
115
|
+
const result = zod_1.z.object({}).safeParse(value);
|
|
116
|
+
if (!result.success) {
|
|
111
117
|
return false;
|
|
112
118
|
}
|
|
113
119
|
const envelope = value;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HexStringSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.HexStringSchema = zod_1.z
|
|
6
|
+
.string()
|
|
7
|
+
.regex(/^(?:0x)?[0-9a-fA-F]*$/i, 'expected hex string')
|
|
8
|
+
.refine(s => s.replace(/^0x/i, '').length % 2 === 0, 'expected even-length hex string');
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -5,29 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DEFAULT_HTTP_CONFIG = void 0;
|
|
7
7
|
exports.http = http;
|
|
8
|
-
|
|
8
|
+
exports.toBeeResponse = toBeeResponse;
|
|
9
9
|
const cafe_utility_1 = require("cafe-utility");
|
|
10
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
11
|
const index_1 = require("../index");
|
|
12
12
|
const debug = (0, debug_1.default)('bee-js:http');
|
|
13
|
-
const { AxiosError } = axios_1.default;
|
|
14
13
|
const MAX_FAILED_ATTEMPTS = 100000;
|
|
15
14
|
const DELAY_FAST = 200;
|
|
16
15
|
const DELAY_SLOW = 1000;
|
|
17
|
-
const
|
|
18
|
-
const ABORT_ERROR_MESSAGE = 'Request aborted';
|
|
16
|
+
const FAST_RETRY_COUNT = 300;
|
|
19
17
|
exports.DEFAULT_HTTP_CONFIG = {
|
|
20
18
|
headers: {
|
|
21
19
|
accept: 'application/json, text/plain, */*',
|
|
22
20
|
},
|
|
23
|
-
maxBodyLength: Infinity,
|
|
24
|
-
maxContentLength: Infinity,
|
|
25
21
|
};
|
|
26
|
-
function throwIfAborted(signal, config, responseData, responseStatus) {
|
|
27
|
-
if (signal?.aborted) {
|
|
28
|
-
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', ABORT_ERROR_MESSAGE, responseData, responseStatus, 'ERR_CANCELED');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
22
|
/**
|
|
32
23
|
* Main function to make HTTP requests.
|
|
33
24
|
* @param options User defined settings
|
|
@@ -37,65 +28,114 @@ async function http(options, config) {
|
|
|
37
28
|
const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
|
|
38
29
|
if (options.signal) {
|
|
39
30
|
requestConfig.signal = options.signal;
|
|
40
|
-
throwIfAborted(options.signal, config);
|
|
41
31
|
}
|
|
42
|
-
|
|
32
|
+
attachBody(requestConfig);
|
|
43
33
|
if (requestConfig.params) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (value === undefined) {
|
|
48
|
-
delete requestConfig.params[key];
|
|
49
|
-
}
|
|
34
|
+
for (const k of Object.keys(requestConfig.params)) {
|
|
35
|
+
if (requestConfig.params[k] === undefined)
|
|
36
|
+
delete requestConfig.params[k];
|
|
50
37
|
}
|
|
51
38
|
}
|
|
39
|
+
const url = buildUrl(requestConfig);
|
|
40
|
+
const method = (requestConfig.method || 'GET').toUpperCase();
|
|
41
|
+
requestConfig.method = method;
|
|
42
|
+
options.onRequest?.({
|
|
43
|
+
method,
|
|
44
|
+
url: cafe_utility_1.Strings.joinUrl([requestConfig.baseURL ?? '', requestConfig.url ?? '']),
|
|
45
|
+
headers: { ...requestConfig.headers },
|
|
46
|
+
params: requestConfig.params,
|
|
47
|
+
});
|
|
52
48
|
let failedAttempts = 0;
|
|
53
49
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
54
|
-
throwIfAborted(options.signal, config);
|
|
55
50
|
try {
|
|
56
|
-
debug(`${
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const response = await (0, axios_1.default)(requestConfig);
|
|
62
|
-
return response;
|
|
51
|
+
debug(`${method} ${url}`, { headers: requestConfig.headers, params: requestConfig.params });
|
|
52
|
+
const res = await fetch(url, requestConfig);
|
|
53
|
+
if (!res.ok)
|
|
54
|
+
await throwHttpError(method, url, res, requestConfig.responseType);
|
|
55
|
+
return toBeeResponse(res, requestConfig.responseType);
|
|
63
56
|
}
|
|
64
57
|
catch (e) {
|
|
65
|
-
if (e instanceof
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
await cafe_utility_1.System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.response?.statusText);
|
|
75
|
-
}
|
|
58
|
+
if (e instanceof index_1.BeeResponseError)
|
|
59
|
+
throw e;
|
|
60
|
+
const err = e;
|
|
61
|
+
if (err.name === 'TimeoutError' && options.endlesslyRetry) {
|
|
62
|
+
failedAttempts++;
|
|
63
|
+
await cafe_utility_1.System.sleepMillis(failedAttempts < FAST_RETRY_COUNT ? DELAY_FAST : DELAY_SLOW);
|
|
76
64
|
}
|
|
77
65
|
else {
|
|
78
|
-
throw
|
|
66
|
+
throw toBeeError(err, method, url);
|
|
79
67
|
}
|
|
80
68
|
}
|
|
81
69
|
}
|
|
82
70
|
throw Error('Max number of failed attempts reached');
|
|
83
71
|
}
|
|
84
|
-
function
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
72
|
+
function attachBody(config) {
|
|
73
|
+
if (config.data === undefined)
|
|
74
|
+
return;
|
|
75
|
+
const data = config.data;
|
|
76
|
+
const isJsonShape = (data !== null && typeof data === 'object' && data.constructor === Object) || Array.isArray(data);
|
|
77
|
+
if (isJsonShape) {
|
|
78
|
+
config.body = JSON.stringify(data);
|
|
79
|
+
config.headers = { 'content-type': 'application/json', ...config.headers };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
config.body = data;
|
|
83
|
+
config.duplex = 'half';
|
|
84
|
+
const ct = data instanceof Blob && data.type ? data.type : 'application/octet-stream';
|
|
85
|
+
config.headers = { 'content-type': ct, ...config.headers };
|
|
92
86
|
}
|
|
93
87
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
async function throwHttpError(method, url, res, responseType) {
|
|
89
|
+
const errBody = await toBeeResponse(res, responseType).catch(() => ({ data: undefined }));
|
|
90
|
+
const bodyMsg = typeof errBody.data === 'string' ? errBody.data : JSON.stringify(errBody.data);
|
|
91
|
+
const message = bodyMsg && bodyMsg !== 'undefined' ? `${res.statusText}: ${bodyMsg}` : res.statusText;
|
|
92
|
+
throw new index_1.BeeResponseError(method, url, message, errBody.data, res.status, res.statusText);
|
|
93
|
+
}
|
|
94
|
+
function toBeeError(err, method, url) {
|
|
95
|
+
if (err.name === 'AbortError') {
|
|
96
|
+
return new index_1.BeeResponseError(method, url, 'Request aborted', undefined, undefined, 'ERR_CANCELED');
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const cause = err.cause;
|
|
99
|
+
const message = cause?.message ? `${err.message}: ${cause.message}` : err.message;
|
|
100
|
+
return new index_1.BeeResponseError(method, url, message);
|
|
101
|
+
}
|
|
102
|
+
async function toBeeResponse(res, responseType = 'json') {
|
|
103
|
+
let data;
|
|
104
|
+
switch (responseType) {
|
|
105
|
+
case 'arraybuffer':
|
|
106
|
+
data = await res.arrayBuffer();
|
|
107
|
+
break;
|
|
108
|
+
case 'text':
|
|
109
|
+
data = await res.text();
|
|
110
|
+
break;
|
|
111
|
+
case 'blob':
|
|
112
|
+
data = await res.blob();
|
|
113
|
+
break;
|
|
114
|
+
case 'stream':
|
|
115
|
+
data = res.body;
|
|
116
|
+
break;
|
|
117
|
+
case 'json':
|
|
118
|
+
default: {
|
|
119
|
+
const text = await res.text();
|
|
120
|
+
data = text ? JSON.parse(text) : null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
data: data,
|
|
125
|
+
status: res.status,
|
|
126
|
+
statusText: res.statusText,
|
|
127
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
128
|
+
raw: res,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function buildUrl(config) {
|
|
132
|
+
let url = cafe_utility_1.Strings.joinUrl([config.baseURL ?? '', config.url ?? '']);
|
|
133
|
+
if (config.params) {
|
|
134
|
+
const qs = new URLSearchParams(Object.entries(config.params)
|
|
135
|
+
.filter(([, v]) => v !== undefined)
|
|
136
|
+
.map(([k, v]) => [k, String(v)])).toString();
|
|
137
|
+
if (qs)
|
|
138
|
+
url += `?${qs}`;
|
|
100
139
|
}
|
|
140
|
+
return url;
|
|
101
141
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResourceLocator = void 0;
|
|
4
|
-
const
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
5
|
const typed_bytes_1 = require("./typed-bytes");
|
|
6
6
|
class ResourceLocator {
|
|
7
7
|
constructor(raw) {
|
|
8
8
|
this.raw = raw;
|
|
9
9
|
}
|
|
10
10
|
toString() {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const asString = zod_1.z.string().safeParse(this.raw);
|
|
12
|
+
if (asString.success && asString.data.includes('.eth')) {
|
|
13
|
+
return asString.data;
|
|
13
14
|
}
|
|
14
15
|
return new typed_bytes_1.Reference(this.raw).toHex();
|
|
15
16
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllTagsOptionsSchema = exports.TransactionOptionsSchema = exports.PostageBatchOptionsSchema = exports.GsocMessageHandlerSchema = exports.PssMessageHandlerSchema = exports.TagUidSchema = exports.TagInputSchema = exports.CollectionUploadOptionsSchema = exports.FileUploadOptionsSchema = exports.RedundantUploadOptionsSchema = exports.UploadOptionsSchema = exports.DownloadOptionsSchema = exports.BeeRequestOptionsSchema = exports.HexStringSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
7
|
+
var hex_schema_1 = require("./hex-schema");
|
|
8
|
+
Object.defineProperty(exports, "HexStringSchema", { enumerable: true, get: function () { return hex_schema_1.HexStringSchema; } });
|
|
9
|
+
const fnField = zod_1.z.any().refine(v => zod_1.z.function().safeParse(v).success, 'expected a function');
|
|
10
|
+
const integerStringField = zod_1.z.any().transform((v) => {
|
|
11
|
+
if (zod_1.z.bigint().safeParse(v).success)
|
|
12
|
+
v = String(v);
|
|
13
|
+
return zod_1.z
|
|
14
|
+
.string()
|
|
15
|
+
.regex(/^-?\d+$/, 'expected integer string')
|
|
16
|
+
.parse(v);
|
|
17
|
+
});
|
|
18
|
+
const nonNegativeIntegerStringField = zod_1.z.any().transform((v) => {
|
|
19
|
+
if (zod_1.z.bigint().safeParse(v).success)
|
|
20
|
+
v = String(v);
|
|
21
|
+
return zod_1.z.string().regex(/^\d+$/, 'expected non-negative integer string').parse(v);
|
|
22
|
+
});
|
|
23
|
+
exports.BeeRequestOptionsSchema = zod_1.z.object({
|
|
24
|
+
baseURL: zod_1.z.string().optional(),
|
|
25
|
+
timeout: zod_1.z.number().int().min(0).optional(),
|
|
26
|
+
headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
27
|
+
onRequest: fnField.optional(),
|
|
28
|
+
httpAgent: zod_1.z.unknown().optional(),
|
|
29
|
+
httpsAgent: zod_1.z.unknown().optional(),
|
|
30
|
+
endlesslyRetry: zod_1.z.boolean().optional(),
|
|
31
|
+
signal: zod_1.z.any().optional(),
|
|
32
|
+
});
|
|
33
|
+
exports.DownloadOptionsSchema = zod_1.z.object({
|
|
34
|
+
redundancyStrategy: zod_1.z.number().int().optional(),
|
|
35
|
+
fallback: zod_1.z.boolean().optional(),
|
|
36
|
+
timeoutMs: zod_1.z.number().int().min(0).optional(),
|
|
37
|
+
actPublisher: zod_1.z.optional(zod_1.z.any().transform((v) => new typed_bytes_1.PublicKey(v))),
|
|
38
|
+
actHistoryAddress: zod_1.z.optional(zod_1.z.any().transform((v) => new typed_bytes_1.Reference(v))),
|
|
39
|
+
actTimestamp: zod_1.z.coerce.number().optional(),
|
|
40
|
+
});
|
|
41
|
+
exports.UploadOptionsSchema = zod_1.z.object({
|
|
42
|
+
act: zod_1.z.boolean().optional(),
|
|
43
|
+
actHistoryAddress: zod_1.z.optional(zod_1.z.any().transform((v) => new typed_bytes_1.Reference(v))),
|
|
44
|
+
deferred: zod_1.z.boolean().optional(),
|
|
45
|
+
encrypt: zod_1.z.boolean().optional(),
|
|
46
|
+
pin: zod_1.z.boolean().optional(),
|
|
47
|
+
tag: zod_1.z.number().int().min(0).optional(),
|
|
48
|
+
});
|
|
49
|
+
exports.RedundantUploadOptionsSchema = exports.UploadOptionsSchema.extend({
|
|
50
|
+
redundancyLevel: zod_1.z.number().int().min(0).optional(),
|
|
51
|
+
});
|
|
52
|
+
exports.FileUploadOptionsSchema = exports.UploadOptionsSchema.extend({
|
|
53
|
+
size: zod_1.z.number().int().min(0).optional(),
|
|
54
|
+
contentType: zod_1.z.string().optional(),
|
|
55
|
+
redundancyLevel: zod_1.z.number().int().min(0).optional(),
|
|
56
|
+
});
|
|
57
|
+
exports.CollectionUploadOptionsSchema = exports.UploadOptionsSchema.extend({
|
|
58
|
+
errorDocument: zod_1.z.string().optional(),
|
|
59
|
+
indexDocument: zod_1.z.string().optional(),
|
|
60
|
+
redundancyLevel: zod_1.z.number().int().min(0).optional(),
|
|
61
|
+
});
|
|
62
|
+
exports.TagInputSchema = zod_1.z.object({ uid: zod_1.z.number().int() });
|
|
63
|
+
exports.TagUidSchema = zod_1.z.coerce.number().min(0);
|
|
64
|
+
exports.PssMessageHandlerSchema = zod_1.z.object({
|
|
65
|
+
onMessage: fnField,
|
|
66
|
+
onError: fnField,
|
|
67
|
+
onClose: fnField,
|
|
68
|
+
});
|
|
69
|
+
exports.GsocMessageHandlerSchema = zod_1.z.object({
|
|
70
|
+
onMessage: fnField,
|
|
71
|
+
onError: fnField,
|
|
72
|
+
onClose: fnField,
|
|
73
|
+
});
|
|
74
|
+
exports.PostageBatchOptionsSchema = zod_1.z.object({
|
|
75
|
+
gasPrice: integerStringField.optional(),
|
|
76
|
+
immutableFlag: zod_1.z.boolean().optional(),
|
|
77
|
+
label: zod_1.z.string().optional(),
|
|
78
|
+
waitForUsable: zod_1.z.boolean().optional(),
|
|
79
|
+
waitForUsableTimeout: zod_1.z.number().int().min(0).optional(),
|
|
80
|
+
});
|
|
81
|
+
exports.TransactionOptionsSchema = zod_1.z.object({
|
|
82
|
+
gasLimit: nonNegativeIntegerStringField.optional(),
|
|
83
|
+
gasPrice: nonNegativeIntegerStringField.optional(),
|
|
84
|
+
});
|
|
85
|
+
exports.AllTagsOptionsSchema = zod_1.z.object({
|
|
86
|
+
limit: zod_1.z.number().int().min(types_1.TAGS_LIMIT_MIN).max(types_1.TAGS_LIMIT_MAX).optional(),
|
|
87
|
+
offset: zod_1.z.number().int().min(0).optional(),
|
|
88
|
+
});
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -177,10 +177,10 @@ function marshalStamp(signature, batchId, timestamp, index) {
|
|
|
177
177
|
return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
|
|
178
178
|
}
|
|
179
179
|
function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
180
|
-
const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
|
|
181
180
|
const batchTTL = (0, workaround_1.normalizeBatchTTL)(raw.batchTTL);
|
|
182
181
|
const duration = duration_1.Duration.fromSeconds(batchTTL);
|
|
183
182
|
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, erasureCodeLevel);
|
|
183
|
+
const usage = raw.utilizationRatio ?? getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
|
|
184
184
|
return {
|
|
185
185
|
batchID: new typed_bytes_1.BatchId(raw.batchID),
|
|
186
186
|
utilization: raw.utilization,
|
|
@@ -211,6 +211,7 @@ function unmapPostageBatch(batch) {
|
|
|
211
211
|
return {
|
|
212
212
|
batchID: batch.batchID.toHex(),
|
|
213
213
|
utilization: batch.utilization,
|
|
214
|
+
utilizationRatio: batch.usage,
|
|
214
215
|
usable: batch.usable,
|
|
215
216
|
label: batch.label,
|
|
216
217
|
depth: batch.depth,
|