@streamr/node 100.0.0-rc.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/LICENSE +78 -0
- package/README.md +54 -0
- package/bin/broker.ts +36 -0
- package/bin/config-wizard.js +4 -0
- package/bin/config-wizard.ts +17 -0
- package/bin/delete-expired-data.ts +41 -0
- package/bin/entry-point.ts +27 -0
- package/configs/development-1.env.json +68 -0
- package/configs/development-2.env.json +53 -0
- package/configs/development-3.env.json +53 -0
- package/configs/development-prod-resend.env.json +21 -0
- package/configs/docker-1.env.json +72 -0
- package/configs/docker-2.env.json +58 -0
- package/configs/docker-3.env.json +58 -0
- package/configuration.md +38 -0
- package/dist/bin/broker.d.ts +2 -0
- package/dist/bin/broker.js +42 -0
- package/dist/bin/broker.js.map +1 -0
- package/dist/bin/config-wizard.d.ts +2 -0
- package/dist/bin/config-wizard.js +22 -0
- package/dist/bin/config-wizard.js.map +1 -0
- package/dist/bin/delete-expired-data.d.ts +2 -0
- package/dist/bin/delete-expired-data.js +44 -0
- package/dist/bin/delete-expired-data.js.map +1 -0
- package/dist/bin/entry-point.d.ts +2 -0
- package/dist/bin/entry-point.js +28 -0
- package/dist/bin/entry-point.js.map +1 -0
- package/dist/package.json +78 -0
- package/dist/src/Plugin.d.ts +33 -0
- package/dist/src/Plugin.js +43 -0
- package/dist/src/Plugin.js.map +1 -0
- package/dist/src/apiAuthentication.d.ts +4 -0
- package/dist/src/apiAuthentication.js +16 -0
- package/dist/src/apiAuthentication.js.map +1 -0
- package/dist/src/broker.d.ts +8 -0
- package/dist/src/broker.js +69 -0
- package/dist/src/broker.js.map +1 -0
- package/dist/src/config/ConfigWizard.d.ts +5 -0
- package/dist/src/config/ConfigWizard.js +466 -0
- package/dist/src/config/ConfigWizard.js.map +1 -0
- package/dist/src/config/config.d.ts +26 -0
- package/dist/src/config/config.js +92 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.schema.json +86 -0
- package/dist/src/config/definitions.schema.json +35 -0
- package/dist/src/config/migration.d.ts +6 -0
- package/dist/src/config/migration.js +210 -0
- package/dist/src/config/migration.js.map +1 -0
- package/dist/src/config/validateConfig.d.ts +4 -0
- package/dist/src/config/validateConfig.js +40 -0
- package/dist/src/config/validateConfig.js.map +1 -0
- package/dist/src/exports.d.ts +3 -0
- package/dist/src/exports.js +6 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/PayloadFormat.d.ts +19 -0
- package/dist/src/helpers/PayloadFormat.js +85 -0
- package/dist/src/helpers/PayloadFormat.js.map +1 -0
- package/dist/src/helpers/applyPluginClientConfigs.d.ts +3 -0
- package/dist/src/helpers/applyPluginClientConfigs.js +29 -0
- package/dist/src/helpers/applyPluginClientConfigs.js.map +1 -0
- package/dist/src/helpers/fetchOrThrow.d.ts +2 -0
- package/dist/src/helpers/fetchOrThrow.js +20 -0
- package/dist/src/helpers/fetchOrThrow.js.map +1 -0
- package/dist/src/helpers/generateMnemonicFromAddress.d.ts +5 -0
- package/dist/src/helpers/generateMnemonicFromAddress.js +16 -0
- package/dist/src/helpers/generateMnemonicFromAddress.js.map +1 -0
- package/dist/src/helpers/multiply.d.ts +1 -0
- package/dist/src/helpers/multiply.js +10 -0
- package/dist/src/helpers/multiply.js.map +1 -0
- package/dist/src/helpers/parser.d.ts +9 -0
- package/dist/src/helpers/parser.js +62 -0
- package/dist/src/helpers/parser.js.map +1 -0
- package/dist/src/helpers/partitions.d.ts +8 -0
- package/dist/src/helpers/partitions.js +32 -0
- package/dist/src/helpers/partitions.js.map +1 -0
- package/dist/src/helpers/weightedSample.d.ts +16 -0
- package/dist/src/helpers/weightedSample.js +35 -0
- package/dist/src/helpers/weightedSample.js.map +1 -0
- package/dist/src/httpServer.d.ts +16 -0
- package/dist/src/httpServer.js +71 -0
- package/dist/src/httpServer.js.map +1 -0
- package/dist/src/pluginRegistry.d.ts +3 -0
- package/dist/src/pluginRegistry.js +35 -0
- package/dist/src/pluginRegistry.js.map +1 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.d.ts +12 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js +36 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js.map +1 -0
- package/dist/src/plugins/consoleMetrics/config.schema.json +18 -0
- package/dist/src/plugins/http/HttpPlugin.d.ts +8 -0
- package/dist/src/plugins/http/HttpPlugin.js +23 -0
- package/dist/src/plugins/http/HttpPlugin.js.map +1 -0
- package/dist/src/plugins/http/config.schema.json +12 -0
- package/dist/src/plugins/http/publishEndpoint.d.ts +3 -0
- package/dist/src/plugins/http/publishEndpoint.js +72 -0
- package/dist/src/plugins/http/publishEndpoint.js.map +1 -0
- package/dist/src/plugins/info/InfoPlugin.d.ts +9 -0
- package/dist/src/plugins/info/InfoPlugin.js +31 -0
- package/dist/src/plugins/info/InfoPlugin.js.map +1 -0
- package/dist/src/plugins/info/config.schema.json +12 -0
- package/dist/src/plugins/mqtt/Bridge.d.ts +40 -0
- package/dist/src/plugins/mqtt/Bridge.js +136 -0
- package/dist/src/plugins/mqtt/Bridge.js.map +1 -0
- package/dist/src/plugins/mqtt/MqttPlugin.d.ts +14 -0
- package/dist/src/plugins/mqtt/MqttPlugin.js +30 -0
- package/dist/src/plugins/mqtt/MqttPlugin.js.map +1 -0
- package/dist/src/plugins/mqtt/MqttServer.d.ts +22 -0
- package/dist/src/plugins/mqtt/MqttServer.js +109 -0
- package/dist/src/plugins/mqtt/MqttServer.js.map +1 -0
- package/dist/src/plugins/mqtt/config.schema.json +26 -0
- package/dist/src/plugins/operator/ConsistentHashRing.d.ts +20 -0
- package/dist/src/plugins/operator/ConsistentHashRing.js +64 -0
- package/dist/src/plugins/operator/ConsistentHashRing.js.map +1 -0
- package/dist/src/plugins/operator/ContractFacade.d.ts +80 -0
- package/dist/src/plugins/operator/ContractFacade.js +364 -0
- package/dist/src/plugins/operator/ContractFacade.js.map +1 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.d.ts +23 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.js +75 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.js.map +1 -0
- package/dist/src/plugins/operator/MaintainTopologyService.d.ts +11 -0
- package/dist/src/plugins/operator/MaintainTopologyService.js +57 -0
- package/dist/src/plugins/operator/MaintainTopologyService.js.map +1 -0
- package/dist/src/plugins/operator/OperatorFleetState.d.ts +33 -0
- package/dist/src/plugins/operator/OperatorFleetState.js +112 -0
- package/dist/src/plugins/operator/OperatorFleetState.js.map +1 -0
- package/dist/src/plugins/operator/OperatorPlugin.d.ts +50 -0
- package/dist/src/plugins/operator/OperatorPlugin.js +159 -0
- package/dist/src/plugins/operator/OperatorPlugin.js.map +1 -0
- package/dist/src/plugins/operator/StreamPartAssignments.d.ts +28 -0
- package/dist/src/plugins/operator/StreamPartAssignments.js +104 -0
- package/dist/src/plugins/operator/StreamPartAssignments.js.map +1 -0
- package/dist/src/plugins/operator/announceNodeToContract.d.ts +3 -0
- package/dist/src/plugins/operator/announceNodeToContract.js +39 -0
- package/dist/src/plugins/operator/announceNodeToContract.js.map +1 -0
- package/dist/src/plugins/operator/announceNodeToStream.d.ts +3 -0
- package/dist/src/plugins/operator/announceNodeToStream.js +25 -0
- package/dist/src/plugins/operator/announceNodeToStream.js.map +1 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.d.ts +2 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.js +21 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.js.map +1 -0
- package/dist/src/plugins/operator/closeExpiredFlags.d.ts +3 -0
- package/dist/src/plugins/operator/closeExpiredFlags.js +24 -0
- package/dist/src/plugins/operator/closeExpiredFlags.js.map +1 -0
- package/dist/src/plugins/operator/config.schema.json +152 -0
- package/dist/src/plugins/operator/createIsLeaderFn.d.ts +4 -0
- package/dist/src/plugins/operator/createIsLeaderFn.js +14 -0
- package/dist/src/plugins/operator/createIsLeaderFn.js.map +1 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.d.ts +2 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.js +43 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.js.map +1 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.d.ts +3 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.js +9 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.js.map +1 -0
- package/dist/src/plugins/operator/heartbeatUtils.d.ts +67 -0
- package/dist/src/plugins/operator/heartbeatUtils.js +26 -0
- package/dist/src/plugins/operator/heartbeatUtils.js.map +1 -0
- package/dist/src/plugins/operator/inspectOverTime.d.ts +22 -0
- package/dist/src/plugins/operator/inspectOverTime.js +146 -0
- package/dist/src/plugins/operator/inspectOverTime.js.map +1 -0
- package/dist/src/plugins/operator/inspectRandomNode.d.ts +8 -0
- package/dist/src/plugins/operator/inspectRandomNode.js +44 -0
- package/dist/src/plugins/operator/inspectRandomNode.js.map +1 -0
- package/dist/src/plugins/operator/inspectionUtils.d.ts +23 -0
- package/dist/src/plugins/operator/inspectionUtils.js +120 -0
- package/dist/src/plugins/operator/inspectionUtils.js.map +1 -0
- package/dist/src/plugins/operator/maintainOperatorValue.d.ts +2 -0
- package/dist/src/plugins/operator/maintainOperatorValue.js +21 -0
- package/dist/src/plugins/operator/maintainOperatorValue.js.map +1 -0
- package/dist/src/plugins/operator/reviewSuspectNode.d.ts +24 -0
- package/dist/src/plugins/operator/reviewSuspectNode.js +56 -0
- package/dist/src/plugins/operator/reviewSuspectNode.js.map +1 -0
- package/dist/src/plugins/storage/Batch.d.ts +51 -0
- package/dist/src/plugins/storage/Batch.js +121 -0
- package/dist/src/plugins/storage/Batch.js.map +1 -0
- package/dist/src/plugins/storage/BatchManager.d.ts +27 -0
- package/dist/src/plugins/storage/BatchManager.js +117 -0
- package/dist/src/plugins/storage/BatchManager.js.map +1 -0
- package/dist/src/plugins/storage/Bucket.d.ts +23 -0
- package/dist/src/plugins/storage/Bucket.js +90 -0
- package/dist/src/plugins/storage/Bucket.js.map +1 -0
- package/dist/src/plugins/storage/BucketManager.d.ts +56 -0
- package/dist/src/plugins/storage/BucketManager.js +306 -0
- package/dist/src/plugins/storage/BucketManager.js.map +1 -0
- package/dist/src/plugins/storage/DataQueryFormat.d.ts +10 -0
- package/dist/src/plugins/storage/DataQueryFormat.js +51 -0
- package/dist/src/plugins/storage/DataQueryFormat.js.map +1 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.d.ts +28 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.js +155 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.js.map +1 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.d.ts +33 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.js +102 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.js.map +1 -0
- package/dist/src/plugins/storage/Storage.d.ts +47 -0
- package/dist/src/plugins/storage/Storage.js +459 -0
- package/dist/src/plugins/storage/Storage.js.map +1 -0
- package/dist/src/plugins/storage/StorageConfig.d.ts +43 -0
- package/dist/src/plugins/storage/StorageConfig.js +83 -0
- package/dist/src/plugins/storage/StorageConfig.js.map +1 -0
- package/dist/src/plugins/storage/StorageEventListener.d.ts +17 -0
- package/dist/src/plugins/storage/StorageEventListener.js +46 -0
- package/dist/src/plugins/storage/StorageEventListener.js.map +1 -0
- package/dist/src/plugins/storage/StoragePlugin.d.ts +32 -0
- package/dist/src/plugins/storage/StoragePlugin.js +103 -0
- package/dist/src/plugins/storage/StoragePlugin.js.map +1 -0
- package/dist/src/plugins/storage/StoragePoller.d.ts +15 -0
- package/dist/src/plugins/storage/StoragePoller.js +47 -0
- package/dist/src/plugins/storage/StoragePoller.js.map +1 -0
- package/dist/src/plugins/storage/config.schema.json +88 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.d.ts +3 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.js +35 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.js.map +1 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.d.ts +6 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.js +181 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.js.map +1 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.d.ts +3 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.js +31 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.js.map +1 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.d.ts +16 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.js +22 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.js.map +1 -0
- package/dist/src/plugins/subscriber/config.schema.json +31 -0
- package/dist/src/plugins/websocket/Connection.d.ts +9 -0
- package/dist/src/plugins/websocket/Connection.js +45 -0
- package/dist/src/plugins/websocket/Connection.js.map +1 -0
- package/dist/src/plugins/websocket/PublishConnection.d.ts +12 -0
- package/dist/src/plugins/websocket/PublishConnection.js +46 -0
- package/dist/src/plugins/websocket/PublishConnection.js.map +1 -0
- package/dist/src/plugins/websocket/SubscribeConnection.d.ts +13 -0
- package/dist/src/plugins/websocket/SubscribeConnection.js +50 -0
- package/dist/src/plugins/websocket/SubscribeConnection.js.map +1 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.d.ts +19 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.js +26 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.js.map +1 -0
- package/dist/src/plugins/websocket/WebsocketServer.d.ts +16 -0
- package/dist/src/plugins/websocket/WebsocketServer.js +132 -0
- package/dist/src/plugins/websocket/WebsocketServer.js.map +1 -0
- package/dist/src/plugins/websocket/config.schema.json +51 -0
- package/package.json +78 -0
- package/plugins.md +318 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "config.schema.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"description": "Broker configuration format",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"client": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"description": "Client configuration",
|
|
14
|
+
"additionalProperties": true,
|
|
15
|
+
"properties": {
|
|
16
|
+
"auth": {
|
|
17
|
+
"anyOf": [
|
|
18
|
+
{
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": {
|
|
21
|
+
"privateKey": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"pattern": "^(0x)?[a-fA-F0-9]{64}$"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["privateKey"]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"type": "object",
|
|
30
|
+
"properties": {
|
|
31
|
+
"ethereum": {
|
|
32
|
+
"type": "object"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"required": ["ethereum"]
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"default": {}
|
|
41
|
+
},
|
|
42
|
+
"plugins": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"description": "Plugin configurations",
|
|
45
|
+
"additionalProperties": true,
|
|
46
|
+
"default": {}
|
|
47
|
+
},
|
|
48
|
+
"httpServer": {
|
|
49
|
+
"type": [
|
|
50
|
+
"object"
|
|
51
|
+
],
|
|
52
|
+
"description": "HTTP server configuration",
|
|
53
|
+
"default": {},
|
|
54
|
+
"additionalProperties": false,
|
|
55
|
+
"properties": {
|
|
56
|
+
"port": {
|
|
57
|
+
"$ref": "definitions.schema.json#/definitions/port",
|
|
58
|
+
"description": "Port to start HTTP server on",
|
|
59
|
+
"default": 7171
|
|
60
|
+
},
|
|
61
|
+
"sslCertificate": {
|
|
62
|
+
"description": "Files to use for SSL",
|
|
63
|
+
"type": "object",
|
|
64
|
+
"required": [
|
|
65
|
+
"certFileName",
|
|
66
|
+
"privateKeyFileName"
|
|
67
|
+
],
|
|
68
|
+
"additionalProperties": false,
|
|
69
|
+
"properties": {
|
|
70
|
+
"certFileName": {
|
|
71
|
+
"type": "string",
|
|
72
|
+
"description": "Path of certificate file"
|
|
73
|
+
},
|
|
74
|
+
"privateKeyFileName": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"description": "Path of private key file"
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"apiAuthentication": {
|
|
83
|
+
"$ref": "definitions.schema.json#/definitions/apiAuthentication"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "definitions.schema.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"definitions": {
|
|
5
|
+
"port": {
|
|
6
|
+
"type": "number",
|
|
7
|
+
"minimum": 0,
|
|
8
|
+
"maximum": 65353
|
|
9
|
+
},
|
|
10
|
+
"apiAuthentication": {
|
|
11
|
+
"type": "object",
|
|
12
|
+
"description": "Plugins should restrict the API access: if an endpoint requires authentication, the user must provide one of the API keys e.g. in a request header",
|
|
13
|
+
"required": [
|
|
14
|
+
"keys"
|
|
15
|
+
],
|
|
16
|
+
"additionalProperties": false,
|
|
17
|
+
"properties": {
|
|
18
|
+
"keys": {
|
|
19
|
+
"type": "array",
|
|
20
|
+
"items": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"apiAuthenticationOverride": {
|
|
27
|
+
"description": "Override global API keys",
|
|
28
|
+
"anyOf": [{
|
|
29
|
+
"$ref": "definitions.schema.json#/definitions/apiAuthentication"
|
|
30
|
+
}, {
|
|
31
|
+
"type": "null"
|
|
32
|
+
}]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ConfigFile } from './config';
|
|
2
|
+
export declare const CURRENT_CONFIGURATION_VERSION = 3;
|
|
3
|
+
export declare const formSchemaUrl: (version: number) => string;
|
|
4
|
+
export declare const needsMigration: (config: any) => boolean;
|
|
5
|
+
export declare const createMigratedConfig: (source: any) => ConfigFile | never;
|
|
6
|
+
export declare const readConfigAndMigrateIfNeeded: (fileName: string | undefined) => ConfigFile | never;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readConfigAndMigrateIfNeeded = exports.createMigratedConfig = exports.needsMigration = exports.formSchemaUrl = exports.CURRENT_CONFIGURATION_VERSION = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
exports.CURRENT_CONFIGURATION_VERSION = 3;
|
|
12
|
+
const formSchemaUrl = (version) => {
|
|
13
|
+
return `https://schema.streamr.network/config-v${version}.schema.json`;
|
|
14
|
+
};
|
|
15
|
+
exports.formSchemaUrl = formSchemaUrl;
|
|
16
|
+
const getVersion = (config) => {
|
|
17
|
+
const PATTERN = /config-v([0-9]+).schema.json$/;
|
|
18
|
+
const schemaUrl = config.$schema;
|
|
19
|
+
if (schemaUrl !== undefined) {
|
|
20
|
+
const match = PATTERN.exec(schemaUrl);
|
|
21
|
+
if (match !== null) {
|
|
22
|
+
return Number(match[1]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
28
|
+
const needsMigration = (config) => {
|
|
29
|
+
return (getVersion(config) !== undefined) && (getVersion(config) !== exports.CURRENT_CONFIGURATION_VERSION);
|
|
30
|
+
};
|
|
31
|
+
exports.needsMigration = needsMigration;
|
|
32
|
+
const convertV1ToV2 = (source) => {
|
|
33
|
+
const TARGET_VERSION = 2;
|
|
34
|
+
const target = (0, cloneDeep_1.default)(source);
|
|
35
|
+
target.$schema = (0, exports.formSchemaUrl)(TARGET_VERSION);
|
|
36
|
+
const consoleAndPM2IntervalInSeconds = source.plugins.metrics?.consoleAndPM2IntervalInSeconds;
|
|
37
|
+
if ((consoleAndPM2IntervalInSeconds !== undefined) && (consoleAndPM2IntervalInSeconds !== 0)) {
|
|
38
|
+
target.plugins.consoleMetrics = {
|
|
39
|
+
interval: consoleAndPM2IntervalInSeconds
|
|
40
|
+
};
|
|
41
|
+
delete target.plugins.metrics.consoleAndPM2IntervalInSeconds;
|
|
42
|
+
}
|
|
43
|
+
const isMetricsPluginEnabled = (source.plugins.metrics !== undefined) && (source.plugins.metrics.nodeMetrics !== null);
|
|
44
|
+
if (isMetricsPluginEnabled) {
|
|
45
|
+
const streamIdPrefix = source.plugins.metrics.nodeMetrics?.streamIdPrefix;
|
|
46
|
+
if (streamIdPrefix !== undefined) {
|
|
47
|
+
target.client.metrics = {
|
|
48
|
+
periods: [
|
|
49
|
+
{
|
|
50
|
+
duration: 60000,
|
|
51
|
+
streamId: `${streamIdPrefix}/min`
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
duration: 3600000,
|
|
55
|
+
streamId: `${streamIdPrefix}/hour`
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
duration: 86400000,
|
|
59
|
+
streamId: `${streamIdPrefix}/day`
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
target.client.metrics = false;
|
|
67
|
+
}
|
|
68
|
+
delete target.plugins.metrics;
|
|
69
|
+
if (target.client?.network?.name !== undefined) {
|
|
70
|
+
delete target.client.network.name;
|
|
71
|
+
}
|
|
72
|
+
if (source.plugins.publishHttp !== undefined) {
|
|
73
|
+
target.plugins.http = source.plugins.publishHttp;
|
|
74
|
+
delete target.plugins.publishHttp;
|
|
75
|
+
}
|
|
76
|
+
const deleteNullProperties = (obj, excludeKeys = []) => {
|
|
77
|
+
const keys = Object.keys(obj);
|
|
78
|
+
for (const key of keys) {
|
|
79
|
+
if ((obj[key] === null) && (!excludeKeys.includes(key))) {
|
|
80
|
+
delete obj[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
deleteNullProperties(target);
|
|
85
|
+
if (target.httpServer !== undefined) {
|
|
86
|
+
deleteNullProperties(target.httpServer);
|
|
87
|
+
}
|
|
88
|
+
if (target.plugins.brubeckMiner !== undefined) {
|
|
89
|
+
deleteNullProperties(target.plugins.brubeckMiner, ['stunServerHost']);
|
|
90
|
+
}
|
|
91
|
+
if (target.plugins.mqtt !== undefined) {
|
|
92
|
+
deleteNullProperties(target.plugins.mqtt);
|
|
93
|
+
}
|
|
94
|
+
if (target.plugins.storage !== undefined) {
|
|
95
|
+
deleteNullProperties(target.plugins.storage.cluster);
|
|
96
|
+
}
|
|
97
|
+
if (target.plugins.websocket !== undefined) {
|
|
98
|
+
deleteNullProperties(target.plugins.websocket);
|
|
99
|
+
}
|
|
100
|
+
if ((target.httpServer?.certFileName !== undefined) || (target.httpServer?.privateKeyFileName !== undefined)) {
|
|
101
|
+
target.httpServer.sslCertificate = {
|
|
102
|
+
certFileName: target.httpServer.certFileName,
|
|
103
|
+
privateKeyFileName: target.httpServer.privateKeyFileName
|
|
104
|
+
};
|
|
105
|
+
delete target.httpServer.certFileName;
|
|
106
|
+
delete target.httpServer.privateKeyFileName;
|
|
107
|
+
}
|
|
108
|
+
return target;
|
|
109
|
+
};
|
|
110
|
+
const convertV2ToV3 = (source) => {
|
|
111
|
+
const TARGET_VERSION = 3;
|
|
112
|
+
const target = (0, cloneDeep_1.default)(source);
|
|
113
|
+
target.$schema = (0, exports.formSchemaUrl)(TARGET_VERSION);
|
|
114
|
+
return target;
|
|
115
|
+
};
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
117
|
+
const createMigratedConfig = (source) => {
|
|
118
|
+
let config = source;
|
|
119
|
+
do {
|
|
120
|
+
const version = getVersion(config);
|
|
121
|
+
if (version === 1) {
|
|
122
|
+
config = convertV1ToV2(config);
|
|
123
|
+
}
|
|
124
|
+
else if (version === 2) {
|
|
125
|
+
config = convertV2ToV3(config);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error(`Unable to migrate the config: version=${version}`);
|
|
129
|
+
}
|
|
130
|
+
} while ((0, exports.needsMigration)(config));
|
|
131
|
+
return config;
|
|
132
|
+
};
|
|
133
|
+
exports.createMigratedConfig = createMigratedConfig;
|
|
134
|
+
/*
|
|
135
|
+
* Creates a backup file name, derived from the given name. Ensures that no file exist with that name.
|
|
136
|
+
* - foobar.ext.backup
|
|
137
|
+
* - or foobar.ext.backup-123
|
|
138
|
+
*/
|
|
139
|
+
const formBackupFileName = (originalFileName) => {
|
|
140
|
+
const name = `${originalFileName}.backup`;
|
|
141
|
+
if (!fs_1.default.existsSync(name)) {
|
|
142
|
+
return name;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
let suffix = 1;
|
|
146
|
+
// eslint-disable-next-line no-constant-condition
|
|
147
|
+
while (true) {
|
|
148
|
+
const suffixedName = `${name}-${suffix}`;
|
|
149
|
+
if (!fs_1.default.existsSync(suffixedName)) {
|
|
150
|
+
return suffixedName;
|
|
151
|
+
}
|
|
152
|
+
suffix++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const readConfigAndMigrateIfNeeded = (fileName) => {
|
|
157
|
+
let explicitTargetFile = undefined;
|
|
158
|
+
if (fileName === undefined) {
|
|
159
|
+
const defaultTargetFile = (0, config_1.getDefaultFile)();
|
|
160
|
+
const legacyTargetFile = (0, config_1.getLegacyDefaultFile)();
|
|
161
|
+
fileName = [defaultTargetFile, legacyTargetFile].find((file) => fs_1.default.existsSync(file));
|
|
162
|
+
if (fileName === undefined) {
|
|
163
|
+
/*
|
|
164
|
+
* No config file. Some config options are maybe set with enviroment variables
|
|
165
|
+
* (see overrideConfigToEnvVarsIfGiven function), and others just
|
|
166
|
+
* use the default values (see `default` definitions in config.schema.json)
|
|
167
|
+
*/
|
|
168
|
+
return {};
|
|
169
|
+
}
|
|
170
|
+
if (fileName === legacyTargetFile) {
|
|
171
|
+
/*
|
|
172
|
+
* User has not specified the config file location in the command line and we found
|
|
173
|
+
* the file from the legacy default location. We'll write the migrated file to current
|
|
174
|
+
* default location instead of the legacy default location. There is no need to backup
|
|
175
|
+
* the file as we won't overwrite anything.
|
|
176
|
+
*/
|
|
177
|
+
explicitTargetFile = defaultTargetFile;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
let content = JSON.parse(fs_1.default.readFileSync(fileName, 'utf8'));
|
|
181
|
+
if ((0, exports.needsMigration)(content)) {
|
|
182
|
+
if (explicitTargetFile === undefined) {
|
|
183
|
+
const backupFile = formBackupFileName(fileName);
|
|
184
|
+
// eslint-disable-next-line no-console
|
|
185
|
+
console.log(`Migrating config ${fileName}, saving backup to ${backupFile}`);
|
|
186
|
+
fs_1.default.copyFileSync(fileName, backupFile);
|
|
187
|
+
content = (0, exports.createMigratedConfig)(content);
|
|
188
|
+
fs_1.default.writeFileSync(fileName, JSON.stringify(content, undefined, 4));
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const backupFile = formBackupFileName(fileName);
|
|
192
|
+
// eslint-disable-next-line no-console
|
|
193
|
+
console.log(`Migrating config ${fileName} to ${explicitTargetFile} (archiving the original file to ${backupFile})`);
|
|
194
|
+
content = (0, exports.createMigratedConfig)(content);
|
|
195
|
+
const directory = path_1.default.dirname(explicitTargetFile);
|
|
196
|
+
if (!fs_1.default.existsSync(directory)) {
|
|
197
|
+
fs_1.default.mkdirSync(directory, {
|
|
198
|
+
recursive: true
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
fs_1.default.writeFileSync(explicitTargetFile, JSON.stringify(content, undefined, 4));
|
|
202
|
+
// read permissions from the source file and set the same permissions to the target file
|
|
203
|
+
fs_1.default.chmodSync(explicitTargetFile, (fs_1.default.statSync(fileName).mode & parseInt('777', 8)).toString(8));
|
|
204
|
+
fs_1.default.renameSync(fileName, backupFile);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return content;
|
|
208
|
+
};
|
|
209
|
+
exports.readConfigAndMigrateIfNeeded = readConfigAndMigrateIfNeeded;
|
|
210
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/config/migration.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,iEAAwC;AACxC,qCAA2E;AAE9D,QAAA,6BAA6B,GAAG,CAAC,CAAA;AAEvC,MAAM,aAAa,GAAG,CAAC,OAAe,EAAU,EAAE;IACrD,OAAO,0CAA0C,OAAO,cAAc,CAAA;AAC1E,CAAC,CAAA;AAFY,QAAA,aAAa,iBAEzB;AAED,MAAM,UAAU,GAAG,CAAC,MAAW,EAAsB,EAAE;IACnD,MAAM,OAAO,GAAG,+BAA+B,CAAA;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAA;IAChC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACrC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACjB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC3B,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAA;AACpB,CAAC,CAAA;AA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AC,QAAQ,CAAC,CAAA;YAC/C,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,oBAAoB,QAAQ,OAAO,kBAAkB,oCAAoC,UAAU,GAAG,CAAC,CAAA;YACnH,OAAO,GAAG,IAAA,4BAAoB,EAAC,OAAO,CAAC,CAAA;YACvC,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;YAClD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC5B,YAAE,CAAC,SAAS,CAAC,SAAS,EAAE;oBACpB,SAAS,EAAE,IAAI;iBAClB,CAAC,CAAA;YACN,CAAC;YACD,YAAE,CAAC,aAAa,CAAC,kBAAkB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAA;YAC3E,wFAAwF;YACxF,YAAE,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;YAC/F,YAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QACvC,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA;AAnDY,QAAA,4BAA4B,gCAmDxC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Schema } from 'ajv';
|
|
2
|
+
import { StrictConfig } from './config';
|
|
3
|
+
export declare const validateConfig: (data: unknown, schema: Schema, contextName?: string, useDefaults?: boolean) => StrictConfig;
|
|
4
|
+
export declare const isValidConfig: (data: unknown, schema: Schema) => boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidConfig = exports.validateConfig = void 0;
|
|
7
|
+
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
9
|
+
const definitions_schema_json_1 = __importDefault(require("./definitions.schema.json"));
|
|
10
|
+
const validateConfig = (data, schema, contextName, useDefaults = true) => {
|
|
11
|
+
const ajv = new ajv_1.default({
|
|
12
|
+
useDefaults
|
|
13
|
+
});
|
|
14
|
+
(0, ajv_formats_1.default)(ajv);
|
|
15
|
+
ajv.addFormat('ethereum-address', /^0x[a-zA-Z0-9]{40}$/);
|
|
16
|
+
ajv.addSchema(definitions_schema_json_1.default);
|
|
17
|
+
if (!ajv.validate(schema, data)) {
|
|
18
|
+
const prefix = (contextName !== undefined) ? (contextName + ': ') : '';
|
|
19
|
+
throw new Error(prefix + ajv.errors.map((e) => {
|
|
20
|
+
let text = ajv.errorsText([e], { dataVar: '' }).trim();
|
|
21
|
+
if (e.params.additionalProperty) {
|
|
22
|
+
text += ` (${e.params.additionalProperty})`;
|
|
23
|
+
}
|
|
24
|
+
return text;
|
|
25
|
+
}).join('\n'));
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
};
|
|
29
|
+
exports.validateConfig = validateConfig;
|
|
30
|
+
const isValidConfig = (data, schema) => {
|
|
31
|
+
try {
|
|
32
|
+
(0, exports.validateConfig)(data, schema, undefined, false);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
catch (_e) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.isValidConfig = isValidConfig;
|
|
40
|
+
//# sourceMappingURL=validateConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateConfig.js","sourceRoot":"","sources":["../../../src/config/validateConfig.ts"],"names":[],"mappings":";;;;;;AA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,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;QAC9C,OAAO,IAAI,CAAA;IACf,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACV,OAAO,KAAK,CAAA;IAChB,CAAC;AACL,CAAC,CAAA;AAPY,QAAA,aAAa,iBAOzB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBroker = void 0;
|
|
4
|
+
var broker_1 = require("./broker");
|
|
5
|
+
Object.defineProperty(exports, "createBroker", { enumerable: true, get: function () { return broker_1.createBroker; } });
|
|
6
|
+
//# sourceMappingURL=exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAAtC,sGAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MessageMetadata } from '@streamr/sdk';
|
|
2
|
+
export interface PayloadFormat {
|
|
3
|
+
createMessage: (payload: string) => Message | never;
|
|
4
|
+
createPayload: (content: Record<string, unknown>, metadata?: Metadata) => string | never;
|
|
5
|
+
}
|
|
6
|
+
export interface Message {
|
|
7
|
+
content: Record<string, unknown>;
|
|
8
|
+
metadata: Metadata;
|
|
9
|
+
}
|
|
10
|
+
export type Metadata = Partial<Pick<MessageMetadata, 'timestamp' | 'sequenceNumber' | 'publisherId' | 'msgChainId'>>;
|
|
11
|
+
export declare class PlainPayloadFormat implements PayloadFormat {
|
|
12
|
+
createMessage(payload: string): Message | never;
|
|
13
|
+
createPayload(content: Record<string, unknown>): string | never;
|
|
14
|
+
}
|
|
15
|
+
export declare class MetadataPayloadFormat implements PayloadFormat {
|
|
16
|
+
createMessage(payload: string): Message | never;
|
|
17
|
+
createPayload(content: Record<string, unknown>, metadata?: Metadata): string | never;
|
|
18
|
+
}
|
|
19
|
+
export declare const getPayloadFormat: (metadata: boolean) => PayloadFormat;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPayloadFormat = exports.MetadataPayloadFormat = exports.PlainPayloadFormat = void 0;
|
|
4
|
+
const METADATA_FIELDS = ['timestamp', 'sequenceNumber', 'publisherId', 'msgChainId'];
|
|
5
|
+
const pickProperties = (fields, from) => {
|
|
6
|
+
const result = {};
|
|
7
|
+
fields.forEach((field) => result[field] = from[field]);
|
|
8
|
+
return result;
|
|
9
|
+
};
|
|
10
|
+
const isJavascriptObject = (content) => {
|
|
11
|
+
return (content instanceof Object) && (!(content instanceof Array));
|
|
12
|
+
};
|
|
13
|
+
const assertContent = (content) => {
|
|
14
|
+
if ((content === undefined) || (content === null)) {
|
|
15
|
+
throw new Error('Content missing');
|
|
16
|
+
}
|
|
17
|
+
if (!isJavascriptObject(content)) {
|
|
18
|
+
throw new Error('Content is not an object');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const assertMetadata = (metadata) => {
|
|
22
|
+
if (!isJavascriptObject(metadata)) {
|
|
23
|
+
throw new Error('Metadata is not an object');
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const parsePayloadJson = (payload) => {
|
|
27
|
+
if (payload.length === 0) {
|
|
28
|
+
throw new Error('Payload missing');
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(payload);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error(`Payload is not a JSON string: ${e.message}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/* eslint-disable class-methods-use-this */
|
|
38
|
+
class PlainPayloadFormat {
|
|
39
|
+
createMessage(payload) {
|
|
40
|
+
const content = parsePayloadJson(payload);
|
|
41
|
+
assertContent(content);
|
|
42
|
+
return {
|
|
43
|
+
content,
|
|
44
|
+
metadata: {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
createPayload(content) {
|
|
48
|
+
assertContent(content);
|
|
49
|
+
return JSON.stringify(content);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.PlainPayloadFormat = PlainPayloadFormat;
|
|
53
|
+
class MetadataPayloadFormat {
|
|
54
|
+
createMessage(payload) {
|
|
55
|
+
const json = parsePayloadJson(payload);
|
|
56
|
+
const content = json.content;
|
|
57
|
+
assertContent(content);
|
|
58
|
+
let metadata;
|
|
59
|
+
if (json.metadata !== undefined) {
|
|
60
|
+
assertMetadata(json.metadata);
|
|
61
|
+
metadata = pickProperties(METADATA_FIELDS, json.metadata);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
metadata = {};
|
|
65
|
+
}
|
|
66
|
+
return { content, metadata };
|
|
67
|
+
}
|
|
68
|
+
createPayload(content, metadata) {
|
|
69
|
+
assertContent(content);
|
|
70
|
+
const payload = {
|
|
71
|
+
content
|
|
72
|
+
};
|
|
73
|
+
if (metadata !== undefined) {
|
|
74
|
+
assertMetadata(metadata);
|
|
75
|
+
payload.metadata = pickProperties(METADATA_FIELDS, metadata);
|
|
76
|
+
}
|
|
77
|
+
return JSON.stringify(payload);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.MetadataPayloadFormat = MetadataPayloadFormat;
|
|
81
|
+
const getPayloadFormat = (metadata) => {
|
|
82
|
+
return metadata ? new MetadataPayloadFormat() : new PlainPayloadFormat();
|
|
83
|
+
};
|
|
84
|
+
exports.getPayloadFormat = getPayloadFormat;
|
|
85
|
+
//# sourceMappingURL=PayloadFormat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PayloadFormat.js","sourceRoot":"","sources":["../../../src/helpers/PayloadFormat.ts"],"names":[],"mappings":";;;AAcA,MAAM,eAAe,GAAG,CAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,CAAE,CAAA;AAEtF,MAAM,cAAc,GAAG,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AE,QAAmC,CAAC,CAAA;QAC3F,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC;CACJ;AA3BD,sDA2BC;AAEM,MAAM,gBAAgB,GAAG,CAAC,QAAiB,EAAiB,EAAE;IACjE,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,qBAAqB,EAAE,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAAE,CAAA;AAC5E,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.applyPluginClientConfigs = void 0;
|
|
7
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
8
|
+
const has_1 = __importDefault(require("lodash/has"));
|
|
9
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
10
|
+
const isString_1 = __importDefault(require("lodash/isString"));
|
|
11
|
+
const set_1 = __importDefault(require("lodash/set"));
|
|
12
|
+
const applyPluginClientConfigs = (plugins, clientConfig) => {
|
|
13
|
+
for (const plugin of plugins) {
|
|
14
|
+
for (const item of plugin.getClientConfig()) {
|
|
15
|
+
if (!(0, has_1.default)(clientConfig, item.path)) {
|
|
16
|
+
(0, set_1.default)(clientConfig, item.path, item.value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const existingValue = (0, get_1.default)(clientConfig, item.path);
|
|
20
|
+
if (!(0, isEqual_1.default)(item.value, existingValue)) {
|
|
21
|
+
const formattedValue = (0, isString_1.default)(existingValue) ? existingValue : `${JSON.stringify(existingValue)}`;
|
|
22
|
+
throw new Error(`Plugin ${plugin.name} doesn't support client config value "${formattedValue}" in ${item.path}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.applyPluginClientConfigs = applyPluginClientConfigs;
|
|
29
|
+
//# sourceMappingURL=applyPluginClientConfigs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyPluginClientConfigs.js","sourceRoot":"","sources":["../../../src/helpers/applyPluginClientConfigs.ts"],"names":[],"mappings":";;;;;;AAAA,qDAA4B;AAC5B,qDAA4B;AAC5B,6DAAoC;AACpC,+DAAsC;AACtC,qDAA4B;AAIrB,MAAM,wBAAwB,GAAG,CAAC,OAAsB,EAAE,YAAoC,EAAQ,EAAE;IAC3G,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,eAAe,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,IAAA,aAAG,EAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChC,IAAA,aAAG,EAAC,YAAY,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;YAC5C,CAAC;iBAAM,CAAC;gBACJ,MAAM,aAAa,GAAG,IAAA,aAAG,EAAC,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;gBAClD,IAAI,CAAC,IAAA,iBAAO,EAAC,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC;oBACtC,MAAM,cAAc,GAAG,IAAA,kBAAQ,EAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAA;oBACnG,MAAM,IAAI,KAAK,CAAC,UAAU,MAAM,CAAC,IAAI,yCAAyC,cAAc,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;gBACpH,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;AACL,CAAC,CAAA;AAdY,QAAA,wBAAwB,4BAcpC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchOrThrow = void 0;
|
|
7
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
|
+
const utils_1 = require("@streamr/utils");
|
|
9
|
+
const DEFAULT_TIMEOUT = 30 * 1000;
|
|
10
|
+
const fetchOrThrow = async (url, init) => {
|
|
11
|
+
const res = await (0, node_fetch_1.default)(url, (0, utils_1.merge)({ timeout: DEFAULT_TIMEOUT }, init));
|
|
12
|
+
if (res.ok) {
|
|
13
|
+
return res;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw new Error(`request to ${url} failed, response: ${res.status} ${res.statusText}`);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.fetchOrThrow = fetchOrThrow;
|
|
20
|
+
//# sourceMappingURL=fetchOrThrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchOrThrow.js","sourceRoot":"","sources":["../../../src/helpers/fetchOrThrow.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAyD;AACzD,0CAAsC;AAEtC,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAA;AAE1B,MAAM,YAAY,GAAG,KAAK,EAAE,GAAW,EAAE,IAAkB,EAAqB,EAAE;IACrF,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAK,EAAC,GAAG,EAAE,IAAA,aAAK,EAAC,EAAE,OAAO,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;IACvE,IAAI,GAAG,CAAC,EAAE,EAAE,CAAC;QACT,OAAO,GAAG,CAAA;IACd,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CAAC,cAAc,GAAG,sBAAsB,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAA;IAC1F,CAAC;AACL,CAAC,CAAA;AAPY,QAAA,YAAY,gBAOxB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateMnemonicFromAddress = void 0;
|
|
4
|
+
const hdnode_1 = require("@ethersproject/hdnode");
|
|
5
|
+
/**
|
|
6
|
+
* @param address - valid eth address with leading 0x
|
|
7
|
+
*/
|
|
8
|
+
const generateMnemonicFromAddress = (address) => {
|
|
9
|
+
return (0, hdnode_1.entropyToMnemonic)(address)
|
|
10
|
+
.split(' ')
|
|
11
|
+
.slice(0, 3)
|
|
12
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
13
|
+
.join(' ');
|
|
14
|
+
};
|
|
15
|
+
exports.generateMnemonicFromAddress = generateMnemonicFromAddress;
|
|
16
|
+
//# sourceMappingURL=generateMnemonicFromAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateMnemonicFromAddress.js","sourceRoot":"","sources":["../../../src/helpers/generateMnemonicFromAddress.ts"],"names":[],"mappings":";;;AAAA,kDAAyD;AAGzD;;GAEG;AACI,MAAM,2BAA2B,GAAG,CAAC,OAAwB,EAAU,EAAE;IAC5E,OAAO,IAAA,0BAAiB,EAAC,OAAO,CAAC;SAC5B,KAAK,CAAC,GAAG,CAAC;SACV,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC3D,IAAI,CAAC,GAAG,CAAC,CAAA;AAClB,CAAC,CAAA;AANY,QAAA,2BAA2B,+BAMvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const multiply: (val1: bigint, val2: number) => bigint;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.multiply = void 0;
|
|
4
|
+
// this precision is big enough as we typically handle bigints which are in weis (the smallest denomination of Ethereum)
|
|
5
|
+
const PRECISION = 1e18;
|
|
6
|
+
const multiply = (val1, val2) => {
|
|
7
|
+
return val1 * BigInt(PRECISION * val2) / BigInt(PRECISION);
|
|
8
|
+
};
|
|
9
|
+
exports.multiply = multiply;
|
|
10
|
+
//# sourceMappingURL=multiply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiply.js","sourceRoot":"","sources":["../../../src/helpers/multiply.ts"],"names":[],"mappings":";;;AAAA,wHAAwH;AACxH,MAAM,SAAS,GAAG,IAAI,CAAA;AAEf,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE;IAC3D,OAAO,IAAI,GAAG,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAC9D,CAAC,CAAA;AAFY,QAAA,QAAQ,YAEpB"}
|