@ethersphere/bee-js 9.7.0 → 9.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee.js +2 -1
- package/dist/cjs/manifest/manifest.js +17 -0
- package/dist/cjs/utils/chunk-stream.js +15 -3
- package/dist/cjs/utils/http.js +7 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +2 -1
- package/dist/mjs/manifest/manifest.js +17 -0
- package/dist/mjs/utils/chunk-stream.js +14 -3
- package/dist/mjs/utils/http.js +9 -1
- package/dist/types/bee.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/package.json +5 -3
package/dist/cjs/bee.js
CHANGED
|
@@ -722,7 +722,8 @@ class Bee {
|
|
|
722
722
|
for (let i = 0n; i < 0xffffn; i++) {
|
|
723
723
|
const signer = new typed_bytes_1.PrivateKey(cafe_utility_1.Binary.numberToUint256(start + i, 'BE'));
|
|
724
724
|
const socAddress = (0, soc_1.makeSOCAddress)(identifier, signer.publicKey().address());
|
|
725
|
-
|
|
725
|
+
// TODO: test the significance of the hardcoded 256
|
|
726
|
+
const actualProximity = 256 - cafe_utility_1.Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array());
|
|
726
727
|
if (actualProximity <= 256 - proximity) {
|
|
727
728
|
return signer;
|
|
728
729
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.MantarayNode = exports.Fork = void 0;
|
|
4
7
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
5
9
|
const __1 = require("..");
|
|
6
10
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
11
|
+
const debug = (0, debug_1.default)('bee-js:manifest');
|
|
7
12
|
const ENCODER = new TextEncoder();
|
|
8
13
|
const DECODER = new TextDecoder();
|
|
9
14
|
const TYPE_VALUE = 2;
|
|
@@ -61,6 +66,11 @@ class Fork {
|
|
|
61
66
|
data.push(new Uint8Array(30 - this.prefix.length));
|
|
62
67
|
}
|
|
63
68
|
data.push(this.node.selfAddress);
|
|
69
|
+
debug('marshalling fork', {
|
|
70
|
+
prefixLength: this.prefix.length,
|
|
71
|
+
prefix: DECODER.decode(this.prefix),
|
|
72
|
+
address: cafe_utility_1.Binary.uint8ArrayToHex(this.node.selfAddress),
|
|
73
|
+
});
|
|
64
74
|
if (this.node.metadata) {
|
|
65
75
|
const metadataBytes = cafe_utility_1.Binary.padEndToMultiple(new Uint8Array([0x00, 0x00, ...ENCODER.encode(JSON.stringify(this.node.metadata))]), 32, 0x0a);
|
|
66
76
|
const metadataLengthBytes = cafe_utility_1.Binary.numberToUint16(metadataBytes.length - 2, 'BE');
|
|
@@ -75,6 +85,12 @@ class Fork {
|
|
|
75
85
|
const prefix = reader.read(prefixLength);
|
|
76
86
|
reader.read(30 - prefixLength);
|
|
77
87
|
const selfAddress = reader.read(addressLength);
|
|
88
|
+
debug('unmarshalling fork', {
|
|
89
|
+
prefixLength,
|
|
90
|
+
prefix: DECODER.decode(prefix),
|
|
91
|
+
addressLength,
|
|
92
|
+
address: cafe_utility_1.Binary.uint8ArrayToHex(selfAddress),
|
|
93
|
+
});
|
|
78
94
|
let metadata = undefined;
|
|
79
95
|
if (isType(type, TYPE_WITH_METADATA)) {
|
|
80
96
|
const metadataLength = cafe_utility_1.Binary.uint16ToNumber(reader.read(2), 'BE');
|
|
@@ -227,6 +243,7 @@ class MantarayNode {
|
|
|
227
243
|
addFork(path, reference, metadata) {
|
|
228
244
|
this.selfAddress = null;
|
|
229
245
|
path = path instanceof Uint8Array ? path : ENCODER.encode(path);
|
|
246
|
+
debug('adding fork', { path: DECODER.decode(path), reference: new typed_bytes_1.Reference(reference).represent() });
|
|
230
247
|
// TODO: this should not be ignored
|
|
231
248
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
232
249
|
let tip = this;
|
|
@@ -40,6 +40,7 @@ async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, optio
|
|
|
40
40
|
for (const file of files) {
|
|
41
41
|
total += (0, chunk_size_1.totalChunks)(file.size);
|
|
42
42
|
}
|
|
43
|
+
let hasIndexHtml = false;
|
|
43
44
|
async function onChunk(chunk) {
|
|
44
45
|
await queue.enqueue(async () => {
|
|
45
46
|
await bee.uploadChunk(postageBatchId, chunk.build(), options, requestOptions);
|
|
@@ -64,11 +65,22 @@ async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, optio
|
|
|
64
65
|
Filename: filename,
|
|
65
66
|
});
|
|
66
67
|
if (file.path === 'index.html') {
|
|
67
|
-
|
|
68
|
-
'website-index-document': 'index.html',
|
|
69
|
-
});
|
|
68
|
+
hasIndexHtml = true;
|
|
70
69
|
}
|
|
71
70
|
}
|
|
71
|
+
if (hasIndexHtml || options?.indexDocument || options?.errorDocument) {
|
|
72
|
+
const metadata = {};
|
|
73
|
+
if (options?.indexDocument) {
|
|
74
|
+
metadata['website-index-document'] = options.indexDocument;
|
|
75
|
+
}
|
|
76
|
+
else if (hasIndexHtml) {
|
|
77
|
+
metadata['website-index-document'] = 'index.html';
|
|
78
|
+
}
|
|
79
|
+
if (options?.errorDocument) {
|
|
80
|
+
metadata['website-error-document'] = options.errorDocument;
|
|
81
|
+
}
|
|
82
|
+
mantaray.addFork('/', __1.NULL_ADDRESS, metadata);
|
|
83
|
+
}
|
|
72
84
|
return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
73
85
|
}
|
|
74
86
|
exports.streamDirectory = streamDirectory;
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.http = exports.DEFAULT_HTTP_CONFIG = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
10
|
const index_1 = require("../index");
|
|
11
|
+
const debug = (0, debug_1.default)('bee-js:http');
|
|
10
12
|
const { AxiosError } = axios_1.default;
|
|
11
13
|
const MAX_FAILED_ATTEMPTS = 100000;
|
|
12
14
|
const DELAY_FAST = 200;
|
|
@@ -41,6 +43,10 @@ async function http(options, config) {
|
|
|
41
43
|
let failedAttempts = 0;
|
|
42
44
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
43
45
|
try {
|
|
46
|
+
debug(`${requestConfig.method || 'get'} ${cafe_utility_1.Strings.joinUrl([
|
|
47
|
+
requestConfig.baseURL,
|
|
48
|
+
requestConfig.url,
|
|
49
|
+
])}`, { headers: { ...requestConfig.headers }, params: requestConfig.params });
|
|
44
50
|
maybeRunOnRequestHook(options, requestConfig);
|
|
45
51
|
const response = await (0, axios_1.default)(requestConfig);
|
|
46
52
|
return response;
|
|
@@ -67,7 +73,7 @@ function maybeRunOnRequestHook(options, requestConfig) {
|
|
|
67
73
|
if (options.onRequest) {
|
|
68
74
|
options.onRequest({
|
|
69
75
|
method: requestConfig.method || 'GET',
|
|
70
|
-
url: cafe_utility_1.Strings.joinUrl(requestConfig.baseURL, requestConfig.url),
|
|
76
|
+
url: cafe_utility_1.Strings.joinUrl([requestConfig.baseURL, requestConfig.url]),
|
|
71
77
|
headers: { ...requestConfig.headers },
|
|
72
78
|
params: requestConfig.params,
|
|
73
79
|
});
|