@ethersphere/bee-js 4.0.0 → 4.1.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/README.md +3 -14
- package/dist/cjs/bee-debug.js +31 -8
- package/dist/cjs/bee.js +12 -10
- package/dist/cjs/modules/debug/states.js +18 -1
- package/dist/cjs/utils/http.js +6 -0
- package/dist/cjs/utils/sleep.js +23 -0
- package/dist/cjs/utils/type.js +66 -2
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +40 -10
- package/dist/mjs/bee.js +15 -13
- package/dist/mjs/modules/debug/states.js +17 -0
- package/dist/mjs/utils/http.js +7 -0
- package/dist/mjs/utils/sleep.js +43 -0
- package/dist/mjs/utils/type.js +72 -2
- package/dist/types/bee-debug.d.ts +8 -1
- package/dist/types/bee.d.ts +11 -10
- package/dist/types/modules/debug/states.d.ts +7 -1
- package/dist/types/types/debug.d.ts +18 -0
- package/dist/types/types/index.d.ts +23 -1
- package/dist/types/utils/sleep.d.ts +6 -0
- package/dist/types/utils/type.d.ts +16 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Bee-js
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ethersphere/bee-js/actions/workflows/tests.yaml)
|
|
4
|
-
[](https://david-dm.org/ethersphere/bee-js)
|
|
5
4
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fethersphere%2Fbee-js?ref=badge_shield)
|
|
6
5
|
[](https://swarm.ethereum.org/)
|
|
7
6
|
[](https://github.com/RichardLitt/standard-readme)
|
|
@@ -110,25 +109,15 @@ npm i
|
|
|
110
109
|
|
|
111
110
|
The tests run in both context: node and dom with Jest.
|
|
112
111
|
|
|
113
|
-
To run the integration tests, you need to
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export BEE_VERSION="1.0.0-2572fa48"
|
|
117
|
-
export BLOCKCHAIN_VERSION="1.2.0"
|
|
118
|
-
export BEE_ENV_PREFIX="swarm-test"
|
|
119
|
-
export BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory"
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Customize these values based on which Bee version you want to run. After the env. variables are set use the `./scripts/environment.sh` script with `start` parameter.
|
|
112
|
+
To run the integration tests, you need to spin up local Bee cluster using our [`bee-factory`](https://github.com/ethersphere/bee-factory/) project.
|
|
113
|
+
In order to do that you have to have locally Docker running on your machine, but afterwards you can just simply run `npm run bee`, which spins up the
|
|
114
|
+
cluster and display Queen's logs. If you want to exit hit `CTRL+C`.
|
|
123
115
|
|
|
124
116
|
If you want to skip creation of postage stamps every run of integration tests you can create stamps for both nodes and set them under env. variables `BEE_POSTAGE` and `BEE_PEER_POSTAGE`.
|
|
125
117
|
|
|
126
118
|
By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633` and `http://localhost:11633`. These are the default values for the `bee-factory` script.
|
|
127
119
|
If you want to use custom setup, you can change the behavior of tests to different addresses using environment variables `BEE_API_URL`, `BEE_DEBUG_API_URL`, `BEE_PEER_DEBUG_API_URL` and `BEE_PEER_API_URL`.
|
|
128
120
|
|
|
129
|
-
In Visual Studio environment, the tests have been set up to run against your local bee node on `http://localhost:1633`
|
|
130
|
-
To run Jest tests, choose the `vscode-jest-tests` CI job under the Run tab.
|
|
131
|
-
|
|
132
121
|
There are also browser tests by Puppeteer, which also provide integrity testing.
|
|
133
122
|
```sh
|
|
134
123
|
npm run test:browser
|
package/dist/cjs/bee-debug.js
CHANGED
|
@@ -43,6 +43,7 @@ const types_1 = require("./types");
|
|
|
43
43
|
const tag = __importStar(require("./modules/debug/tag"));
|
|
44
44
|
const stamps = __importStar(require("./modules/debug/stamps"));
|
|
45
45
|
const http_1 = require("./utils/http");
|
|
46
|
+
const sleep_1 = require("./utils/sleep");
|
|
46
47
|
class BeeDebug {
|
|
47
48
|
constructor(url, options) {
|
|
48
49
|
var _a;
|
|
@@ -431,6 +432,17 @@ class BeeDebug {
|
|
|
431
432
|
return states.getChainState(this.getKy(options));
|
|
432
433
|
});
|
|
433
434
|
}
|
|
435
|
+
/**
|
|
436
|
+
* Get wallet balances for xDai and BZZ of the Bee node
|
|
437
|
+
*
|
|
438
|
+
* @param options
|
|
439
|
+
*/
|
|
440
|
+
getWalletBalance(options) {
|
|
441
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
+
(0, type_1.assertRequestOptions)(options);
|
|
443
|
+
return states.getWalletBalance(this.getKy(options));
|
|
444
|
+
});
|
|
445
|
+
}
|
|
434
446
|
/**
|
|
435
447
|
* Creates new postage batch from the funds that the node has available in its Ethereum account.
|
|
436
448
|
*
|
|
@@ -450,8 +462,8 @@ class BeeDebug {
|
|
|
450
462
|
*/
|
|
451
463
|
createPostageBatch(amount, depth, options) {
|
|
452
464
|
return __awaiter(this, void 0, void 0, function* () {
|
|
453
|
-
(0, type_1.
|
|
454
|
-
(0, type_1.
|
|
465
|
+
(0, type_1.assertPostageBatchOptions)(options);
|
|
466
|
+
(0, type_1.assertPositiveInteger)(amount);
|
|
455
467
|
(0, type_1.assertNonNegativeInteger)(depth);
|
|
456
468
|
if (depth < types_1.STAMPS_DEPTH_MIN) {
|
|
457
469
|
throw new error_1.BeeArgumentError(`Depth has to be at least ${types_1.STAMPS_DEPTH_MIN}`, depth);
|
|
@@ -459,13 +471,11 @@ class BeeDebug {
|
|
|
459
471
|
if (depth > types_1.STAMPS_DEPTH_MAX) {
|
|
460
472
|
throw new error_1.BeeArgumentError(`Depth has to be at most ${types_1.STAMPS_DEPTH_MAX}`, depth);
|
|
461
473
|
}
|
|
462
|
-
|
|
463
|
-
|
|
474
|
+
const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
|
|
475
|
+
if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
|
|
476
|
+
yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
|
|
464
477
|
}
|
|
465
|
-
|
|
466
|
-
(0, type_1.assertBoolean)(options.immutableFlag);
|
|
467
|
-
}
|
|
468
|
-
return stamps.createPostageBatch(this.getKy(options), amount, depth, options);
|
|
478
|
+
return stamp;
|
|
469
479
|
});
|
|
470
480
|
}
|
|
471
481
|
/**
|
|
@@ -605,6 +615,19 @@ class BeeDebug {
|
|
|
605
615
|
return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice);
|
|
606
616
|
});
|
|
607
617
|
}
|
|
618
|
+
waitForUsablePostageStamp(id, timeout = 120000) {
|
|
619
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
620
|
+
const TIME_STEP = 1500;
|
|
621
|
+
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
622
|
+
const stamp = yield this.getPostageBatch(id);
|
|
623
|
+
if (stamp.usable) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
yield (0, sleep_1.sleep)(TIME_STEP);
|
|
627
|
+
}
|
|
628
|
+
throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
|
|
629
|
+
});
|
|
630
|
+
}
|
|
608
631
|
getKy(options) {
|
|
609
632
|
if (!options) {
|
|
610
633
|
return this.ky;
|
package/dist/cjs/bee.js
CHANGED
|
@@ -57,6 +57,7 @@ const types_1 = require("./types");
|
|
|
57
57
|
const http_1 = require("./utils/http");
|
|
58
58
|
const stream_1 = require("./utils/stream");
|
|
59
59
|
const retrievable_1 = require("./feed/retrievable");
|
|
60
|
+
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
60
61
|
/**
|
|
61
62
|
* The main component that abstracts operations available on the main Bee API.
|
|
62
63
|
*
|
|
@@ -228,23 +229,23 @@ class Bee {
|
|
|
228
229
|
const fileName = name !== null && name !== void 0 ? name : data.name;
|
|
229
230
|
const contentType = data.type;
|
|
230
231
|
const fileOptions = Object.assign({ contentType }, options);
|
|
231
|
-
return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
|
|
232
|
+
return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), swarm_cid_1.ReferenceType.MANIFEST);
|
|
232
233
|
}
|
|
233
234
|
else if ((0, stream_1.isReadable)(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
|
|
234
235
|
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
235
236
|
const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
236
237
|
yield this.updateTag(options.tag, result.reference);
|
|
237
|
-
return result;
|
|
238
|
+
return (0, type_2.addCidConversionFunction)(result, swarm_cid_1.ReferenceType.MANIFEST);
|
|
238
239
|
}
|
|
239
240
|
else {
|
|
240
|
-
return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
241
|
+
return (0, type_2.addCidConversionFunction)(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
241
242
|
}
|
|
242
243
|
});
|
|
243
244
|
}
|
|
244
245
|
/**
|
|
245
246
|
* Download single file.
|
|
246
247
|
*
|
|
247
|
-
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or
|
|
248
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
248
249
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
249
250
|
* @param options Options that affects the request behavior
|
|
250
251
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -256,14 +257,14 @@ class Bee {
|
|
|
256
257
|
downloadFile(reference, path = '', options) {
|
|
257
258
|
return __awaiter(this, void 0, void 0, function* () {
|
|
258
259
|
(0, type_2.assertRequestOptions)(options);
|
|
259
|
-
(0, type_2.
|
|
260
|
+
reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
|
|
260
261
|
return bzz.downloadFile(this.getKy(options), reference, path);
|
|
261
262
|
});
|
|
262
263
|
}
|
|
263
264
|
/**
|
|
264
265
|
* Download single file as a readable stream
|
|
265
266
|
*
|
|
266
|
-
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or
|
|
267
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
267
268
|
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
268
269
|
* @param options Options that affects the request behavior
|
|
269
270
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -275,7 +276,7 @@ class Bee {
|
|
|
275
276
|
downloadReadableFile(reference, path = '', options) {
|
|
276
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
277
278
|
(0, type_2.assertRequestOptions)(options);
|
|
278
|
-
(0, type_2.
|
|
279
|
+
reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
|
|
279
280
|
return bzz.downloadFileReadable(this.getKy(options), reference, path);
|
|
280
281
|
});
|
|
281
282
|
}
|
|
@@ -301,7 +302,7 @@ class Bee {
|
|
|
301
302
|
if (options)
|
|
302
303
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
303
304
|
const data = yield (0, collection_1.makeCollectionFromFileList)(fileList);
|
|
304
|
-
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
305
|
+
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
308
|
/**
|
|
@@ -320,7 +321,7 @@ class Bee {
|
|
|
320
321
|
(0, collection_1.assertCollection)(collection);
|
|
321
322
|
if (options)
|
|
322
323
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
323
|
-
return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
|
|
324
|
+
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
324
325
|
});
|
|
325
326
|
}
|
|
326
327
|
/**
|
|
@@ -345,7 +346,7 @@ class Bee {
|
|
|
345
346
|
if (options)
|
|
346
347
|
(0, type_2.assertCollectionUploadOptions)(options);
|
|
347
348
|
const data = yield (0, collection_node_1.makeCollectionFromFS)(dir);
|
|
348
|
-
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
349
|
+
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
349
350
|
});
|
|
350
351
|
}
|
|
351
352
|
/**
|
|
@@ -760,6 +761,7 @@ class Bee {
|
|
|
760
761
|
*
|
|
761
762
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
|
|
762
763
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
764
|
+
* TODO: Once breaking add support for Feed CID
|
|
763
765
|
*/
|
|
764
766
|
createFeedManifest(postageBatchId, type, topic, owner, options) {
|
|
765
767
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -9,9 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getChainState = exports.getReserveState = void 0;
|
|
12
|
+
exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
|
|
13
13
|
const http_1 = require("../../utils/http");
|
|
14
14
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
15
|
+
const WALLET_ENDPOINT = 'wallet';
|
|
15
16
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
16
17
|
/**
|
|
17
18
|
* Get state of reserve
|
|
@@ -45,3 +46,19 @@ function getChainState(ky) {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
exports.getChainState = getChainState;
|
|
49
|
+
/**
|
|
50
|
+
* Get wallet balances for xDai and BZZ of the node
|
|
51
|
+
*
|
|
52
|
+
* @param ky Ky debug instance
|
|
53
|
+
*/
|
|
54
|
+
function getWalletBalance(ky) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const response = yield (0, http_1.http)(ky, {
|
|
57
|
+
method: 'get',
|
|
58
|
+
path: `${WALLET_ENDPOINT}`,
|
|
59
|
+
responseType: 'json',
|
|
60
|
+
});
|
|
61
|
+
return response.data;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.getWalletBalance = getWalletBalance;
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -154,6 +154,12 @@ function http(ky, config) {
|
|
|
154
154
|
throw new error_1.BeeRequestError(e.message, config);
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
|
+
// Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
|
|
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
|
+
}
|
|
157
163
|
throw new error_1.BeeError(e.message);
|
|
158
164
|
}
|
|
159
165
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.sleep = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Sleep for N miliseconds
|
|
15
|
+
*
|
|
16
|
+
* @param ms Number of miliseconds to sleep
|
|
17
|
+
*/
|
|
18
|
+
function sleep(ms) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.sleep = sleep;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReferenceOrEns = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
3
|
+
exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
const file_1 = require("./file");
|
|
7
7
|
const hex_1 = require("./hex");
|
|
8
8
|
const stream_1 = require("./stream");
|
|
9
|
+
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
9
10
|
function isUint8Array(obj) {
|
|
10
11
|
return obj instanceof Uint8Array;
|
|
11
12
|
}
|
|
@@ -68,6 +69,12 @@ function assertNonNegativeInteger(value, name = 'Value') {
|
|
|
68
69
|
throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
69
70
|
}
|
|
70
71
|
exports.assertNonNegativeInteger = assertNonNegativeInteger;
|
|
72
|
+
function assertPositiveInteger(value, name = 'Value') {
|
|
73
|
+
assertInteger(value, name);
|
|
74
|
+
if (Number(value) <= 0)
|
|
75
|
+
throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
|
|
76
|
+
}
|
|
77
|
+
exports.assertPositiveInteger = assertPositiveInteger;
|
|
71
78
|
function assertReference(value) {
|
|
72
79
|
try {
|
|
73
80
|
(0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
|
|
@@ -102,8 +109,22 @@ function assertReferenceOrEns(value) {
|
|
|
102
109
|
* ethswarm.something- - INVALID
|
|
103
110
|
* ethswarm.-something - INVALID
|
|
104
111
|
* ethswarm.some-thing - VALID
|
|
112
|
+
*
|
|
113
|
+
* The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
|
|
114
|
+
*
|
|
115
|
+
* This part matches 2-63 character string that does not start or end with -
|
|
116
|
+
* [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
|
|
117
|
+
*
|
|
118
|
+
* For 1 character long string we use the part after |
|
|
119
|
+
* [^-.\/?:\s] <regexp2>
|
|
120
|
+
*
|
|
121
|
+
* This is terminated in a group with . character an repeated at least once
|
|
122
|
+
* (<regexp1>|<regexp2>\.)+
|
|
123
|
+
*
|
|
124
|
+
* This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
|
|
125
|
+
* ^(<regexp1>|<regexp2>\.)+<regexp1>$
|
|
105
126
|
*/
|
|
106
|
-
const DOMAIN_REGEX = /^(?:(
|
|
127
|
+
const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
|
|
107
128
|
// We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
108
129
|
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
109
130
|
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
@@ -112,6 +133,43 @@ function assertReferenceOrEns(value) {
|
|
|
112
133
|
}
|
|
113
134
|
}
|
|
114
135
|
exports.assertReferenceOrEns = assertReferenceOrEns;
|
|
136
|
+
/**
|
|
137
|
+
* Function that mainly converts Swarm CID into hex encoded Swarm Reference
|
|
138
|
+
*
|
|
139
|
+
* @param value
|
|
140
|
+
* @param expectedCidType
|
|
141
|
+
*/
|
|
142
|
+
function makeReferenceOrEns(value, expectedCidType) {
|
|
143
|
+
var _a;
|
|
144
|
+
if (typeof value !== 'string') {
|
|
145
|
+
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const result = (0, swarm_cid_1.decodeCid)(value);
|
|
149
|
+
if (result.type !== expectedCidType) {
|
|
150
|
+
throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
|
|
151
|
+
}
|
|
152
|
+
return result.reference;
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
if (e instanceof error_1.BeeError)
|
|
156
|
+
throw e;
|
|
157
|
+
}
|
|
158
|
+
assertReferenceOrEns(value);
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
exports.makeReferenceOrEns = makeReferenceOrEns;
|
|
162
|
+
/**
|
|
163
|
+
* Function that adds getter which converts the reference into CID base32 encoded string.
|
|
164
|
+
* @param result
|
|
165
|
+
* @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
|
|
166
|
+
*/
|
|
167
|
+
function addCidConversionFunction(result, cidType) {
|
|
168
|
+
return Object.assign(Object.assign({}, result), { get cid() {
|
|
169
|
+
return (0, swarm_cid_1.encodeReference)(result.reference, cidType).toString();
|
|
170
|
+
} });
|
|
171
|
+
}
|
|
172
|
+
exports.addCidConversionFunction = addCidConversionFunction;
|
|
115
173
|
function assertAddress(value) {
|
|
116
174
|
(0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
|
|
117
175
|
}
|
|
@@ -256,6 +314,12 @@ function assertPostageBatchOptions(value) {
|
|
|
256
314
|
if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
|
|
257
315
|
assertBoolean(options.immutableFlag);
|
|
258
316
|
}
|
|
317
|
+
if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
|
|
318
|
+
assertBoolean(options.waitForUsable);
|
|
319
|
+
}
|
|
320
|
+
if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
|
|
321
|
+
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
322
|
+
}
|
|
259
323
|
}
|
|
260
324
|
exports.assertPostageBatchOptions = assertPostageBatchOptions;
|
|
261
325
|
function assertCashoutOptions(value) {
|