@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.
Files changed (238) hide show
  1. package/LICENSE +78 -0
  2. package/README.md +54 -0
  3. package/bin/broker.ts +36 -0
  4. package/bin/config-wizard.js +4 -0
  5. package/bin/config-wizard.ts +17 -0
  6. package/bin/delete-expired-data.ts +41 -0
  7. package/bin/entry-point.ts +27 -0
  8. package/configs/development-1.env.json +68 -0
  9. package/configs/development-2.env.json +53 -0
  10. package/configs/development-3.env.json +53 -0
  11. package/configs/development-prod-resend.env.json +21 -0
  12. package/configs/docker-1.env.json +72 -0
  13. package/configs/docker-2.env.json +58 -0
  14. package/configs/docker-3.env.json +58 -0
  15. package/configuration.md +38 -0
  16. package/dist/bin/broker.d.ts +2 -0
  17. package/dist/bin/broker.js +42 -0
  18. package/dist/bin/broker.js.map +1 -0
  19. package/dist/bin/config-wizard.d.ts +2 -0
  20. package/dist/bin/config-wizard.js +22 -0
  21. package/dist/bin/config-wizard.js.map +1 -0
  22. package/dist/bin/delete-expired-data.d.ts +2 -0
  23. package/dist/bin/delete-expired-data.js +44 -0
  24. package/dist/bin/delete-expired-data.js.map +1 -0
  25. package/dist/bin/entry-point.d.ts +2 -0
  26. package/dist/bin/entry-point.js +28 -0
  27. package/dist/bin/entry-point.js.map +1 -0
  28. package/dist/package.json +78 -0
  29. package/dist/src/Plugin.d.ts +33 -0
  30. package/dist/src/Plugin.js +43 -0
  31. package/dist/src/Plugin.js.map +1 -0
  32. package/dist/src/apiAuthentication.d.ts +4 -0
  33. package/dist/src/apiAuthentication.js +16 -0
  34. package/dist/src/apiAuthentication.js.map +1 -0
  35. package/dist/src/broker.d.ts +8 -0
  36. package/dist/src/broker.js +69 -0
  37. package/dist/src/broker.js.map +1 -0
  38. package/dist/src/config/ConfigWizard.d.ts +5 -0
  39. package/dist/src/config/ConfigWizard.js +466 -0
  40. package/dist/src/config/ConfigWizard.js.map +1 -0
  41. package/dist/src/config/config.d.ts +26 -0
  42. package/dist/src/config/config.js +92 -0
  43. package/dist/src/config/config.js.map +1 -0
  44. package/dist/src/config/config.schema.json +86 -0
  45. package/dist/src/config/definitions.schema.json +35 -0
  46. package/dist/src/config/migration.d.ts +6 -0
  47. package/dist/src/config/migration.js +210 -0
  48. package/dist/src/config/migration.js.map +1 -0
  49. package/dist/src/config/validateConfig.d.ts +4 -0
  50. package/dist/src/config/validateConfig.js +40 -0
  51. package/dist/src/config/validateConfig.js.map +1 -0
  52. package/dist/src/exports.d.ts +3 -0
  53. package/dist/src/exports.js +6 -0
  54. package/dist/src/exports.js.map +1 -0
  55. package/dist/src/helpers/PayloadFormat.d.ts +19 -0
  56. package/dist/src/helpers/PayloadFormat.js +85 -0
  57. package/dist/src/helpers/PayloadFormat.js.map +1 -0
  58. package/dist/src/helpers/applyPluginClientConfigs.d.ts +3 -0
  59. package/dist/src/helpers/applyPluginClientConfigs.js +29 -0
  60. package/dist/src/helpers/applyPluginClientConfigs.js.map +1 -0
  61. package/dist/src/helpers/fetchOrThrow.d.ts +2 -0
  62. package/dist/src/helpers/fetchOrThrow.js +20 -0
  63. package/dist/src/helpers/fetchOrThrow.js.map +1 -0
  64. package/dist/src/helpers/generateMnemonicFromAddress.d.ts +5 -0
  65. package/dist/src/helpers/generateMnemonicFromAddress.js +16 -0
  66. package/dist/src/helpers/generateMnemonicFromAddress.js.map +1 -0
  67. package/dist/src/helpers/multiply.d.ts +1 -0
  68. package/dist/src/helpers/multiply.js +10 -0
  69. package/dist/src/helpers/multiply.js.map +1 -0
  70. package/dist/src/helpers/parser.d.ts +9 -0
  71. package/dist/src/helpers/parser.js +62 -0
  72. package/dist/src/helpers/parser.js.map +1 -0
  73. package/dist/src/helpers/partitions.d.ts +8 -0
  74. package/dist/src/helpers/partitions.js +32 -0
  75. package/dist/src/helpers/partitions.js.map +1 -0
  76. package/dist/src/helpers/weightedSample.d.ts +16 -0
  77. package/dist/src/helpers/weightedSample.js +35 -0
  78. package/dist/src/helpers/weightedSample.js.map +1 -0
  79. package/dist/src/httpServer.d.ts +16 -0
  80. package/dist/src/httpServer.js +71 -0
  81. package/dist/src/httpServer.js.map +1 -0
  82. package/dist/src/pluginRegistry.d.ts +3 -0
  83. package/dist/src/pluginRegistry.js +35 -0
  84. package/dist/src/pluginRegistry.js.map +1 -0
  85. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.d.ts +12 -0
  86. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js +36 -0
  87. package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js.map +1 -0
  88. package/dist/src/plugins/consoleMetrics/config.schema.json +18 -0
  89. package/dist/src/plugins/http/HttpPlugin.d.ts +8 -0
  90. package/dist/src/plugins/http/HttpPlugin.js +23 -0
  91. package/dist/src/plugins/http/HttpPlugin.js.map +1 -0
  92. package/dist/src/plugins/http/config.schema.json +12 -0
  93. package/dist/src/plugins/http/publishEndpoint.d.ts +3 -0
  94. package/dist/src/plugins/http/publishEndpoint.js +72 -0
  95. package/dist/src/plugins/http/publishEndpoint.js.map +1 -0
  96. package/dist/src/plugins/info/InfoPlugin.d.ts +9 -0
  97. package/dist/src/plugins/info/InfoPlugin.js +31 -0
  98. package/dist/src/plugins/info/InfoPlugin.js.map +1 -0
  99. package/dist/src/plugins/info/config.schema.json +12 -0
  100. package/dist/src/plugins/mqtt/Bridge.d.ts +40 -0
  101. package/dist/src/plugins/mqtt/Bridge.js +136 -0
  102. package/dist/src/plugins/mqtt/Bridge.js.map +1 -0
  103. package/dist/src/plugins/mqtt/MqttPlugin.d.ts +14 -0
  104. package/dist/src/plugins/mqtt/MqttPlugin.js +30 -0
  105. package/dist/src/plugins/mqtt/MqttPlugin.js.map +1 -0
  106. package/dist/src/plugins/mqtt/MqttServer.d.ts +22 -0
  107. package/dist/src/plugins/mqtt/MqttServer.js +109 -0
  108. package/dist/src/plugins/mqtt/MqttServer.js.map +1 -0
  109. package/dist/src/plugins/mqtt/config.schema.json +26 -0
  110. package/dist/src/plugins/operator/ConsistentHashRing.d.ts +20 -0
  111. package/dist/src/plugins/operator/ConsistentHashRing.js +64 -0
  112. package/dist/src/plugins/operator/ConsistentHashRing.js.map +1 -0
  113. package/dist/src/plugins/operator/ContractFacade.d.ts +80 -0
  114. package/dist/src/plugins/operator/ContractFacade.js +364 -0
  115. package/dist/src/plugins/operator/ContractFacade.js.map +1 -0
  116. package/dist/src/plugins/operator/MaintainTopologyHelper.d.ts +23 -0
  117. package/dist/src/plugins/operator/MaintainTopologyHelper.js +75 -0
  118. package/dist/src/plugins/operator/MaintainTopologyHelper.js.map +1 -0
  119. package/dist/src/plugins/operator/MaintainTopologyService.d.ts +11 -0
  120. package/dist/src/plugins/operator/MaintainTopologyService.js +57 -0
  121. package/dist/src/plugins/operator/MaintainTopologyService.js.map +1 -0
  122. package/dist/src/plugins/operator/OperatorFleetState.d.ts +33 -0
  123. package/dist/src/plugins/operator/OperatorFleetState.js +112 -0
  124. package/dist/src/plugins/operator/OperatorFleetState.js.map +1 -0
  125. package/dist/src/plugins/operator/OperatorPlugin.d.ts +50 -0
  126. package/dist/src/plugins/operator/OperatorPlugin.js +159 -0
  127. package/dist/src/plugins/operator/OperatorPlugin.js.map +1 -0
  128. package/dist/src/plugins/operator/StreamPartAssignments.d.ts +28 -0
  129. package/dist/src/plugins/operator/StreamPartAssignments.js +104 -0
  130. package/dist/src/plugins/operator/StreamPartAssignments.js.map +1 -0
  131. package/dist/src/plugins/operator/announceNodeToContract.d.ts +3 -0
  132. package/dist/src/plugins/operator/announceNodeToContract.js +39 -0
  133. package/dist/src/plugins/operator/announceNodeToContract.js.map +1 -0
  134. package/dist/src/plugins/operator/announceNodeToStream.d.ts +3 -0
  135. package/dist/src/plugins/operator/announceNodeToStream.js +25 -0
  136. package/dist/src/plugins/operator/announceNodeToStream.js.map +1 -0
  137. package/dist/src/plugins/operator/checkOperatorValueBreach.d.ts +2 -0
  138. package/dist/src/plugins/operator/checkOperatorValueBreach.js +21 -0
  139. package/dist/src/plugins/operator/checkOperatorValueBreach.js.map +1 -0
  140. package/dist/src/plugins/operator/closeExpiredFlags.d.ts +3 -0
  141. package/dist/src/plugins/operator/closeExpiredFlags.js +24 -0
  142. package/dist/src/plugins/operator/closeExpiredFlags.js.map +1 -0
  143. package/dist/src/plugins/operator/config.schema.json +152 -0
  144. package/dist/src/plugins/operator/createIsLeaderFn.d.ts +4 -0
  145. package/dist/src/plugins/operator/createIsLeaderFn.js +14 -0
  146. package/dist/src/plugins/operator/createIsLeaderFn.js.map +1 -0
  147. package/dist/src/plugins/operator/fetchRedundancyFactor.d.ts +2 -0
  148. package/dist/src/plugins/operator/fetchRedundancyFactor.js +43 -0
  149. package/dist/src/plugins/operator/fetchRedundancyFactor.js.map +1 -0
  150. package/dist/src/plugins/operator/formCoordinationStreamId.d.ts +3 -0
  151. package/dist/src/plugins/operator/formCoordinationStreamId.js +9 -0
  152. package/dist/src/plugins/operator/formCoordinationStreamId.js.map +1 -0
  153. package/dist/src/plugins/operator/heartbeatUtils.d.ts +67 -0
  154. package/dist/src/plugins/operator/heartbeatUtils.js +26 -0
  155. package/dist/src/plugins/operator/heartbeatUtils.js.map +1 -0
  156. package/dist/src/plugins/operator/inspectOverTime.d.ts +22 -0
  157. package/dist/src/plugins/operator/inspectOverTime.js +146 -0
  158. package/dist/src/plugins/operator/inspectOverTime.js.map +1 -0
  159. package/dist/src/plugins/operator/inspectRandomNode.d.ts +8 -0
  160. package/dist/src/plugins/operator/inspectRandomNode.js +44 -0
  161. package/dist/src/plugins/operator/inspectRandomNode.js.map +1 -0
  162. package/dist/src/plugins/operator/inspectionUtils.d.ts +23 -0
  163. package/dist/src/plugins/operator/inspectionUtils.js +120 -0
  164. package/dist/src/plugins/operator/inspectionUtils.js.map +1 -0
  165. package/dist/src/plugins/operator/maintainOperatorValue.d.ts +2 -0
  166. package/dist/src/plugins/operator/maintainOperatorValue.js +21 -0
  167. package/dist/src/plugins/operator/maintainOperatorValue.js.map +1 -0
  168. package/dist/src/plugins/operator/reviewSuspectNode.d.ts +24 -0
  169. package/dist/src/plugins/operator/reviewSuspectNode.js +56 -0
  170. package/dist/src/plugins/operator/reviewSuspectNode.js.map +1 -0
  171. package/dist/src/plugins/storage/Batch.d.ts +51 -0
  172. package/dist/src/plugins/storage/Batch.js +121 -0
  173. package/dist/src/plugins/storage/Batch.js.map +1 -0
  174. package/dist/src/plugins/storage/BatchManager.d.ts +27 -0
  175. package/dist/src/plugins/storage/BatchManager.js +117 -0
  176. package/dist/src/plugins/storage/BatchManager.js.map +1 -0
  177. package/dist/src/plugins/storage/Bucket.d.ts +23 -0
  178. package/dist/src/plugins/storage/Bucket.js +90 -0
  179. package/dist/src/plugins/storage/Bucket.js.map +1 -0
  180. package/dist/src/plugins/storage/BucketManager.d.ts +56 -0
  181. package/dist/src/plugins/storage/BucketManager.js +306 -0
  182. package/dist/src/plugins/storage/BucketManager.js.map +1 -0
  183. package/dist/src/plugins/storage/DataQueryFormat.d.ts +10 -0
  184. package/dist/src/plugins/storage/DataQueryFormat.js +51 -0
  185. package/dist/src/plugins/storage/DataQueryFormat.js.map +1 -0
  186. package/dist/src/plugins/storage/DeleteExpiredCmd.d.ts +28 -0
  187. package/dist/src/plugins/storage/DeleteExpiredCmd.js +155 -0
  188. package/dist/src/plugins/storage/DeleteExpiredCmd.js.map +1 -0
  189. package/dist/src/plugins/storage/SetMembershipSynchronizer.d.ts +33 -0
  190. package/dist/src/plugins/storage/SetMembershipSynchronizer.js +102 -0
  191. package/dist/src/plugins/storage/SetMembershipSynchronizer.js.map +1 -0
  192. package/dist/src/plugins/storage/Storage.d.ts +47 -0
  193. package/dist/src/plugins/storage/Storage.js +459 -0
  194. package/dist/src/plugins/storage/Storage.js.map +1 -0
  195. package/dist/src/plugins/storage/StorageConfig.d.ts +43 -0
  196. package/dist/src/plugins/storage/StorageConfig.js +83 -0
  197. package/dist/src/plugins/storage/StorageConfig.js.map +1 -0
  198. package/dist/src/plugins/storage/StorageEventListener.d.ts +17 -0
  199. package/dist/src/plugins/storage/StorageEventListener.js +46 -0
  200. package/dist/src/plugins/storage/StorageEventListener.js.map +1 -0
  201. package/dist/src/plugins/storage/StoragePlugin.d.ts +32 -0
  202. package/dist/src/plugins/storage/StoragePlugin.js +103 -0
  203. package/dist/src/plugins/storage/StoragePlugin.js.map +1 -0
  204. package/dist/src/plugins/storage/StoragePoller.d.ts +15 -0
  205. package/dist/src/plugins/storage/StoragePoller.js +47 -0
  206. package/dist/src/plugins/storage/StoragePoller.js.map +1 -0
  207. package/dist/src/plugins/storage/config.schema.json +88 -0
  208. package/dist/src/plugins/storage/dataMetadataEndpoint.d.ts +3 -0
  209. package/dist/src/plugins/storage/dataMetadataEndpoint.js +35 -0
  210. package/dist/src/plugins/storage/dataMetadataEndpoint.js.map +1 -0
  211. package/dist/src/plugins/storage/dataQueryEndpoint.d.ts +6 -0
  212. package/dist/src/plugins/storage/dataQueryEndpoint.js +181 -0
  213. package/dist/src/plugins/storage/dataQueryEndpoint.js.map +1 -0
  214. package/dist/src/plugins/storage/storageConfigEndpoint.d.ts +3 -0
  215. package/dist/src/plugins/storage/storageConfigEndpoint.js +31 -0
  216. package/dist/src/plugins/storage/storageConfigEndpoint.js.map +1 -0
  217. package/dist/src/plugins/subscriber/SubscriberPlugin.d.ts +16 -0
  218. package/dist/src/plugins/subscriber/SubscriberPlugin.js +22 -0
  219. package/dist/src/plugins/subscriber/SubscriberPlugin.js.map +1 -0
  220. package/dist/src/plugins/subscriber/config.schema.json +31 -0
  221. package/dist/src/plugins/websocket/Connection.d.ts +9 -0
  222. package/dist/src/plugins/websocket/Connection.js +45 -0
  223. package/dist/src/plugins/websocket/Connection.js.map +1 -0
  224. package/dist/src/plugins/websocket/PublishConnection.d.ts +12 -0
  225. package/dist/src/plugins/websocket/PublishConnection.js +46 -0
  226. package/dist/src/plugins/websocket/PublishConnection.js.map +1 -0
  227. package/dist/src/plugins/websocket/SubscribeConnection.d.ts +13 -0
  228. package/dist/src/plugins/websocket/SubscribeConnection.js +50 -0
  229. package/dist/src/plugins/websocket/SubscribeConnection.js.map +1 -0
  230. package/dist/src/plugins/websocket/WebsocketPlugin.d.ts +19 -0
  231. package/dist/src/plugins/websocket/WebsocketPlugin.js +26 -0
  232. package/dist/src/plugins/websocket/WebsocketPlugin.js.map +1 -0
  233. package/dist/src/plugins/websocket/WebsocketServer.d.ts +16 -0
  234. package/dist/src/plugins/websocket/WebsocketServer.js +132 -0
  235. package/dist/src/plugins/websocket/WebsocketServer.js.map +1 -0
  236. package/dist/src/plugins/websocket/config.schema.json +51 -0
  237. package/package.json +78 -0
  238. package/plugins.md +318 -0
@@ -0,0 +1,9 @@
1
+ import { ParsedQs } from 'qs';
2
+ export declare const parsePositiveInteger: (n: string) => number | never;
3
+ export declare const parseTimestamp: (millisOrString: number | string) => number | never;
4
+ export declare const parseQueryParameter: <T>(name: string, query: ParsedQs, parser: (input: string) => T) => T | undefined;
5
+ export declare const parseQueryParameterArray: <T>(name: string, query: ParsedQs, parser: (input: string) => T) => T[] | undefined;
6
+ export declare const parseQueryAndBase: (str: string) => {
7
+ base: string;
8
+ query: ParsedQs;
9
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseQueryAndBase = exports.parseQueryParameterArray = exports.parseQueryParameter = exports.parseTimestamp = exports.parsePositiveInteger = void 0;
4
+ const qs_1 = require("qs");
5
+ const parsePositiveInteger = (n) => {
6
+ const parsed = parseInt(n);
7
+ if (!Number.isInteger(parsed) || parsed < 0) {
8
+ throw new Error(`${n} is not a valid positive integer`);
9
+ }
10
+ return parsed;
11
+ };
12
+ exports.parsePositiveInteger = parsePositiveInteger;
13
+ const parseTimestamp = (millisOrString) => {
14
+ if (typeof millisOrString === 'number') {
15
+ return millisOrString;
16
+ }
17
+ if (typeof millisOrString === 'string') {
18
+ // Try if this string represents a number
19
+ const timestamp = Number(millisOrString) || Date.parse(millisOrString);
20
+ if (Number.isNaN(timestamp)) {
21
+ throw new Error(`Invalid timestamp: ${millisOrString}`);
22
+ }
23
+ else {
24
+ return timestamp;
25
+ }
26
+ }
27
+ else {
28
+ throw new Error(`Invalid timestamp: ${millisOrString}`);
29
+ }
30
+ };
31
+ exports.parseTimestamp = parseTimestamp;
32
+ const parseQueryParameter = (name, query, parser) => {
33
+ const value = query[name];
34
+ if (value !== undefined) {
35
+ return parser(value);
36
+ }
37
+ else {
38
+ return undefined;
39
+ }
40
+ };
41
+ exports.parseQueryParameter = parseQueryParameter;
42
+ const parseQueryParameterArray = (name, query, parser) => {
43
+ return (0, exports.parseQueryParameter)(name, query, (input) => input.split(',').map((part) => parser(part)));
44
+ };
45
+ exports.parseQueryParameterArray = parseQueryParameterArray;
46
+ const parseQueryAndBase = (str) => {
47
+ const queryParameterStartPos = str.lastIndexOf('?');
48
+ if (queryParameterStartPos !== -1) {
49
+ return {
50
+ base: str.substring(0, queryParameterStartPos),
51
+ query: (0, qs_1.parse)(str.substring(queryParameterStartPos + 1))
52
+ };
53
+ }
54
+ else {
55
+ return {
56
+ base: str,
57
+ query: {}
58
+ };
59
+ }
60
+ };
61
+ exports.parseQueryAndBase = parseQueryAndBase;
62
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/helpers/parser.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AAE7B,MAAM,oBAAoB,GAAG,CAAC,CAAS,EAAkB,EAAE;IAC9D,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAA;IAC3D,CAAC;IACD,OAAO,MAAM,CAAA;AACjB,CAAC,CAAA;AANY,QAAA,oBAAoB,wBAMhC;AAEM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pG,CAAC,CAAA;AAFY,QAAA,wBAAwB,4BAEpC;AAEM,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAqC,EAAE;IAChF,MAAM,sBAAsB,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACnD,IAAI,sBAAsB,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO;YACH,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,sBAAsB,CAAC;YAC9C,KAAK,EAAE,IAAA,UAAK,EAAC,GAAG,CAAC,SAAS,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC;SAC1D,CAAA;IACL,CAAC;SAAM,CAAC;QACJ,OAAO;YACH,IAAI,EAAE,GAAG;YACT,KAAK,EAAE,EAAE;SACZ,CAAA;IACL,CAAC;AACL,CAAC,CAAA;AAbY,QAAA,iBAAiB,qBAa7B"}
@@ -0,0 +1,8 @@
1
+ import { ParsedQs } from 'qs';
2
+ export declare class PublishPartitionDefinition {
3
+ partition?: number;
4
+ partitionKey?: string;
5
+ partitionKeyField?: string;
6
+ }
7
+ export declare const parsePublishPartitionDefinition: (queryParams: ParsedQs) => PublishPartitionDefinition;
8
+ export declare const getPartitionKey: (content: Record<string, unknown>, definition: PublishPartitionDefinition) => string | undefined;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPartitionKey = exports.parsePublishPartitionDefinition = exports.PublishPartitionDefinition = void 0;
4
+ const parser_1 = require("./parser");
5
+ class PublishPartitionDefinition {
6
+ partition;
7
+ partitionKey;
8
+ partitionKeyField;
9
+ }
10
+ exports.PublishPartitionDefinition = PublishPartitionDefinition;
11
+ const parsePublishPartitionDefinition = (queryParams) => {
12
+ const partition = (0, parser_1.parseQueryParameter)('partition', queryParams, parser_1.parsePositiveInteger);
13
+ const partitionKey = queryParams['partitionKey'];
14
+ const partitionKeyField = queryParams['partitionKeyField'];
15
+ const partitionDefinitions = [partition, partitionKey, partitionKeyField].filter((d) => d !== undefined);
16
+ if (partitionDefinitions.length > 1) {
17
+ throw new Error('Invalid combination of "partition", "partitionKey" and "partitionKeyField"');
18
+ }
19
+ return {
20
+ partition,
21
+ partitionKey,
22
+ partitionKeyField
23
+ };
24
+ };
25
+ exports.parsePublishPartitionDefinition = parsePublishPartitionDefinition;
26
+ const getPartitionKey = (content, definition) => {
27
+ return definition.partitionKey ?? (definition.partitionKeyField
28
+ ? content[definition.partitionKeyField]
29
+ : undefined);
30
+ };
31
+ exports.getPartitionKey = getPartitionKey;
32
+ //# sourceMappingURL=partitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partitions.js","sourceRoot":"","sources":["../../../src/helpers/partitions.ts"],"names":[],"mappings":";;;AACA,qCAAoE;AAEpE,MAAa,0BAA0B;IACnC,SAAS,CAAS;IAClB,YAAY,CAAS;IACrB,iBAAiB,CAAS;CAC7B;AAJD,gEAIC;AAEM,MAAM,+BAA+B,GAAG,CAAC,WAAqB,EAA8B,EAAE;IACjG,MAAM,SAAS,GAAG,IAAA,4BAAmB,EAAS,WAAW,EAAE,WAAW,EAAE,6BAAoB,CAAC,CAAA;IAC7F,MAAM,YAAY,GAAG,WAAW,CAAC,cAAc,CAAuB,CAAA;IACtE,MAAM,iBAAiB,GAAG,WAAW,CAAC,mBAAmB,CAAuB,CAAA;IAChF,MAAM,oBAAoB,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAA;IACxG,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAA;IACjG,CAAC;IACD,OAAO;QACH,SAAS;QACT,YAAY;QACZ,iBAAiB;KACpB,CAAA;AACL,CAAC,CAAA;AAbY,QAAA,+BAA+B,mCAa3C;AAEM,MAAM,eAAe,GAAG,CAAC,OAAgC,EAAE,UAAsC,EAAsB,EAAE;IAC5H,OAAO,UAAU,CAAC,YAAY,IAAI,CAC9B,UAAU,CAAC,iBAAiB;QACxB,CAAC,CAAE,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAY;QACnD,CAAC,CAAC,SAAS,CAClB,CAAA;AACL,CAAC,CAAA;AANY,QAAA,eAAe,mBAM3B"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns a random item from the given array, where the weight of each item is
3
+ * determined by the given weight function.
4
+ *
5
+ * @param items The items to sample from
6
+ * @param weight The weight function, should return a positive integer (strictly greater than zero)
7
+ * @param sampleFn The function to use for sampling, defaults to lodash/random
8
+ * @returns The sampled item, or undefined if the array is empty
9
+ *
10
+ */
11
+ export declare function weightedSample<T>(items: T[], weight: (t: T) => number, sampleFn?: {
12
+ (floating?: boolean | undefined): number;
13
+ (max: number, floating?: boolean | undefined): number;
14
+ (min: number, max: number, floating?: boolean | undefined): number;
15
+ (min: number, index: string | number, guard: object): number;
16
+ }): T | undefined;
@@ -0,0 +1,35 @@
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.weightedSample = void 0;
7
+ const random_1 = __importDefault(require("lodash/random"));
8
+ /**
9
+ * Returns a random item from the given array, where the weight of each item is
10
+ * determined by the given weight function.
11
+ *
12
+ * @param items The items to sample from
13
+ * @param weight The weight function, should return a positive integer (strictly greater than zero)
14
+ * @param sampleFn The function to use for sampling, defaults to lodash/random
15
+ * @returns The sampled item, or undefined if the array is empty
16
+ *
17
+ */
18
+ function weightedSample(items, weight, sampleFn = random_1.default) {
19
+ if (items.length === 0) {
20
+ return undefined;
21
+ }
22
+ const cumulativeWeights = [weight(items[0])];
23
+ for (let i = 1; i < items.length; ++i) {
24
+ cumulativeWeights[i] = cumulativeWeights[i - 1] + weight(items[i]);
25
+ }
26
+ const sample = sampleFn(0, cumulativeWeights[cumulativeWeights.length - 1] - 1);
27
+ for (let i = 0; i < cumulativeWeights.length; ++i) {
28
+ if (cumulativeWeights[i] > sample) {
29
+ return items[i];
30
+ }
31
+ }
32
+ throw new Error('assertion failure: should never be here');
33
+ }
34
+ exports.weightedSample = weightedSample;
35
+ //# sourceMappingURL=weightedSample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weightedSample.js","sourceRoot":"","sources":["../../../src/helpers/weightedSample.ts"],"names":[],"mappings":";;;;;;AAAA,2DAAkC;AAElC;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAI,KAAU,EAAE,MAAwB,EAAE,QAAQ,GAAG,gBAAM;IACrF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,SAAS,CAAA;IACpB,CAAC;IAED,MAAM,iBAAiB,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QACpC,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAE/E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAChD,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;QACnB,CAAC;IACL,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;AAC9D,CAAC;AAlBD,wCAkBC"}
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Server as HttpServer } from 'http';
4
+ import https, { Server as HttpsServer } from 'https';
5
+ import { Request, Response, NextFunction, RequestHandler } from 'express';
6
+ import { StrictConfig } from './config/config';
7
+ import { ApiAuthentication } from './apiAuthentication';
8
+ export interface Endpoint {
9
+ path: string;
10
+ method: 'get' | 'post';
11
+ requestHandlers: RequestHandler[];
12
+ apiAuthentication?: ApiAuthentication;
13
+ }
14
+ export declare const createAuthenticatorMiddleware: (apiAuthentication?: ApiAuthentication) => (req: Request, res: Response, next: NextFunction) => void;
15
+ export declare const startServer: (endpoints: Endpoint[], config: StrictConfig['httpServer']) => Promise<HttpServer | https.Server>;
16
+ export declare const stopServer: (httpServer: HttpServer | HttpsServer) => Promise<void>;
@@ -0,0 +1,71 @@
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.stopServer = exports.startServer = exports.createAuthenticatorMiddleware = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const https_1 = __importDefault(require("https"));
9
+ const cors_1 = __importDefault(require("cors"));
10
+ const express_1 = __importDefault(require("express"));
11
+ const utils_1 = require("@streamr/utils");
12
+ const events_1 = require("events");
13
+ const apiAuthentication_1 = require("./apiAuthentication");
14
+ const logger = new utils_1.Logger(module);
15
+ const HTTP_STATUS_UNAUTHORIZED = 401;
16
+ const HTTP_STATUS_FORBIDDEN = 403;
17
+ const getApiKey = (req) => {
18
+ const headerValue = req.headers.authorization;
19
+ const PREFIX = 'bearer ';
20
+ if (headerValue?.toLowerCase().startsWith(PREFIX)) {
21
+ return headerValue.substring(PREFIX.length);
22
+ }
23
+ return undefined;
24
+ };
25
+ const createAuthenticatorMiddleware = (apiAuthentication) => {
26
+ return (req, res, next) => {
27
+ const apiKey = getApiKey(req);
28
+ if ((0, apiAuthentication_1.isValidAuthentication)(apiKey, apiAuthentication)) {
29
+ next();
30
+ }
31
+ else {
32
+ const status = (apiKey === undefined) ? HTTP_STATUS_UNAUTHORIZED : HTTP_STATUS_FORBIDDEN;
33
+ res.sendStatus(status);
34
+ }
35
+ };
36
+ };
37
+ exports.createAuthenticatorMiddleware = createAuthenticatorMiddleware;
38
+ const startServer = async (endpoints, config) => {
39
+ const app = (0, express_1.default)();
40
+ app.use((0, cors_1.default)({
41
+ origin: true, // Access-Control-Allow-Origin: request origin. The default '*' is invalid if credentials included.
42
+ credentials: true // Access-Control-Allow-Credentials: true
43
+ }));
44
+ endpoints.forEach((endpoint) => {
45
+ const handlers = [(0, exports.createAuthenticatorMiddleware)(endpoint.apiAuthentication)].concat(endpoint.requestHandlers);
46
+ app.route(endpoint.path)[endpoint.method](handlers);
47
+ });
48
+ let serverFactory;
49
+ if (config.sslCertificate !== undefined) {
50
+ serverFactory = https_1.default.createServer({
51
+ cert: fs_1.default.readFileSync(config.sslCertificate.certFileName),
52
+ key: fs_1.default.readFileSync(config.sslCertificate.privateKeyFileName)
53
+ }, app);
54
+ }
55
+ else {
56
+ serverFactory = app;
57
+ }
58
+ const server = serverFactory.listen(config.port);
59
+ await (0, events_1.once)(server, 'listening');
60
+ logger.info(`Started HTTP server on port ${config.port}`);
61
+ return server;
62
+ };
63
+ exports.startServer = startServer;
64
+ const stopServer = async (httpServer) => {
65
+ if (httpServer.listening) {
66
+ httpServer.close();
67
+ await (0, events_1.once)(httpServer, 'close');
68
+ }
69
+ };
70
+ exports.stopServer = stopServer;
71
+ //# sourceMappingURL=httpServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpServer.js","sourceRoot":"","sources":["../../src/httpServer.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AAEnB,kDAAoD;AACpD,gDAAuB;AACvB,sDAAkF;AA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EAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;AACL,CAAC,CAAA;AALY,QAAA,UAAU,cAKtB"}
@@ -0,0 +1,3 @@
1
+ import { Plugin } from './Plugin';
2
+ import { StrictConfig } from './config/config';
3
+ export declare const createPlugin: (name: string, brokerConfig: StrictConfig) => Plugin<any> | never;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPlugin = void 0;
4
+ const ConsoleMetricsPlugin_1 = require("./plugins/consoleMetrics/ConsoleMetricsPlugin");
5
+ const HttpPlugin_1 = require("./plugins/http/HttpPlugin");
6
+ const InfoPlugin_1 = require("./plugins/info/InfoPlugin");
7
+ const MqttPlugin_1 = require("./plugins/mqtt/MqttPlugin");
8
+ const OperatorPlugin_1 = require("./plugins/operator/OperatorPlugin");
9
+ const StoragePlugin_1 = require("./plugins/storage/StoragePlugin");
10
+ const SubscriberPlugin_1 = require("./plugins/subscriber/SubscriberPlugin");
11
+ const WebsocketPlugin_1 = require("./plugins/websocket/WebsocketPlugin");
12
+ const createPlugin = (name, brokerConfig) => {
13
+ switch (name) {
14
+ case 'http':
15
+ return new HttpPlugin_1.HttpPlugin(name, brokerConfig);
16
+ case 'consoleMetrics':
17
+ return new ConsoleMetricsPlugin_1.ConsoleMetricsPlugin(name, brokerConfig);
18
+ case 'websocket':
19
+ return new WebsocketPlugin_1.WebsocketPlugin(name, brokerConfig);
20
+ case 'mqtt':
21
+ return new MqttPlugin_1.MqttPlugin(name, brokerConfig);
22
+ case 'storage':
23
+ return new StoragePlugin_1.StoragePlugin(name, brokerConfig);
24
+ case 'operator':
25
+ return new OperatorPlugin_1.OperatorPlugin(name, brokerConfig);
26
+ case 'subscriber':
27
+ return new SubscriberPlugin_1.SubscriberPlugin(name, brokerConfig);
28
+ case 'info':
29
+ return new InfoPlugin_1.InfoPlugin(name, brokerConfig);
30
+ default:
31
+ throw new Error(`Unknown plugin: ${name}`);
32
+ }
33
+ };
34
+ exports.createPlugin = createPlugin;
35
+ //# sourceMappingURL=pluginRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pluginRegistry.js","sourceRoot":"","sources":["../../src/pluginRegistry.ts"],"names":[],"mappings":";;;AAEA,wFAAoF;AACpF,0DAAsD;AACtD,0DAAsD;AACtD,0DAAsD;AACtD,sEAAkE;AAClE,mEAA+D;AAC/D,4EAAwE;AACxE,yEAAqE;AAE9D,MAAM,YAAY,GAAG,CAAC,IAAY,EAAE,YAA0B,EAAuB,EAAE;IAC1F,QAAQ,IAAI,EAAE,CAAC;QACX,KAAK,MAAM;YACP,OAAO,IAAI,uBAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAC7C,KAAK,gBAAgB;YACjB,OAAO,IAAI,2CAAoB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACvD,KAAK,WAAW;YACZ,OAAO,IAAI,iCAAe,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAClD,KAAK,MAAM;YACP,OAAO,IAAI,uBAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAC7C,KAAK,SAAS;YACV,OAAO,IAAI,6BAAa,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAChD,KAAK,UAAU;YACX,OAAO,IAAI,+BAAc,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACjD,KAAK,YAAY;YACb,OAAO,IAAI,mCAAgB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QACnD,KAAK,MAAM;YACP,OAAO,IAAI,uBAAU,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;QAC7C;YACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAA;IAClD,CAAC;AACL,CAAC,CAAA;AArBY,QAAA,YAAY,gBAqBxB"}
@@ -0,0 +1,12 @@
1
+ import { Schema } from 'ajv';
2
+ import { StreamrClient } from '@streamr/sdk';
3
+ import { Plugin } from '../../Plugin';
4
+ export interface ConsoleMetricsPluginConfig {
5
+ interval: number;
6
+ }
7
+ export declare class ConsoleMetricsPlugin extends Plugin<ConsoleMetricsPluginConfig> {
8
+ private readonly abortController;
9
+ start(streamrClient: StreamrClient): Promise<void>;
10
+ stop(): Promise<void>;
11
+ getConfigSchema(): Schema;
12
+ }
@@ -0,0 +1,36 @@
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.ConsoleMetricsPlugin = void 0;
7
+ const utils_1 = require("@streamr/utils");
8
+ const omit_1 = __importDefault(require("lodash/omit"));
9
+ const Plugin_1 = require("../../Plugin");
10
+ const config_schema_json_1 = __importDefault(require("./config.schema.json"));
11
+ const logger = new utils_1.Logger(module);
12
+ function formatNumber(n) {
13
+ return n < 10 ? n.toFixed(1) : String(Math.round(n));
14
+ }
15
+ class ConsoleMetricsPlugin extends Plugin_1.Plugin {
16
+ abortController = new AbortController();
17
+ async start(streamrClient) {
18
+ const metricsContext = (await (streamrClient.getNode())).getMetricsContext();
19
+ metricsContext.createReportProducer((report) => {
20
+ // omit timestamp info as that is printed by the logger
21
+ const data = (0, omit_1.default)(report, 'period');
22
+ // remove quote chars to improve readability
23
+ const output = JSON.stringify(data, undefined, 4).replace(/"/g, '');
24
+ logger.info(`Report\n${output}`);
25
+ }, this.pluginConfig.interval * 1000, this.abortController.signal, formatNumber);
26
+ }
27
+ async stop() {
28
+ this.abortController.abort();
29
+ }
30
+ // eslint-disable-next-line class-methods-use-this
31
+ getConfigSchema() {
32
+ return config_schema_json_1.default;
33
+ }
34
+ }
35
+ exports.ConsoleMetricsPlugin = ConsoleMetricsPlugin;
36
+ //# sourceMappingURL=ConsoleMetricsPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsoleMetricsPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/consoleMetrics/ConsoleMetricsPlug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"}
@@ -0,0 +1,18 @@
1
+ {
2
+ "$id": "config.schema.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "description": "Console metrics plugin configuration",
6
+ "required": [
7
+ "interval"
8
+ ],
9
+ "additionalProperties": false,
10
+ "properties": {
11
+ "interval": {
12
+ "type": "integer",
13
+ "description": "Interval (in seconds) in which to collect and report metrics",
14
+ "minimum": 0,
15
+ "default": 60
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,8 @@
1
+ import { ApiPluginConfig, Plugin } from '../../Plugin';
2
+ import { Schema } from 'ajv';
3
+ import { StreamrClient } from '@streamr/sdk';
4
+ export declare class HttpPlugin extends Plugin<ApiPluginConfig> {
5
+ start(streamrClient: StreamrClient): Promise<void>;
6
+ stop(): Promise<void>;
7
+ getConfigSchema(): Schema;
8
+ }
@@ -0,0 +1,23 @@
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.HttpPlugin = void 0;
7
+ const publishEndpoint_1 = require("./publishEndpoint");
8
+ const Plugin_1 = require("../../Plugin");
9
+ const config_schema_json_1 = __importDefault(require("./config.schema.json"));
10
+ class HttpPlugin extends Plugin_1.Plugin {
11
+ async start(streamrClient) {
12
+ this.addHttpServerEndpoint((0, publishEndpoint_1.createEndpoint)(streamrClient));
13
+ }
14
+ // eslint-disable-next-line class-methods-use-this
15
+ async stop() {
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ getConfigSchema() {
19
+ return config_schema_json_1.default;
20
+ }
21
+ }
22
+ exports.HttpPlugin = HttpPlugin;
23
+ //# sourceMappingURL=HttpPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/http/HttpPlugin.ts"],"names":[],"mappings":";;;;;;AAAA,uDAAkD;AAClD,yCAAsD;AACtD,8EAAuD;AAIvD,MAAa,UAAW,SAAQ,eAAuB;IAEnD,KAAK,CAAC,KAAK,CAAC,aAA4B;QACpC,IAAI,CAAC,qBAAqB,CAAC,IAAA,gCAAc,EAAC,aAAa,CAAC,CAAC,CAAA;IAC7D,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,IAAI;IACV,CAAC;IAED,kDAAkD;IACzC,eAAe;QACpB,OAAO,4BAAoB,CAAA;IAC/B,CAAC;CACJ;AAdD,gCAcC"}
@@ -0,0 +1,12 @@
1
+ {
2
+ "$id": "config.schema.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "description": "HTTP plugin configuration",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "apiAuthentication": {
9
+ "$ref": "definitions.schema.json#/definitions/apiAuthenticationOverride"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import { StreamrClient } from '@streamr/sdk';
2
+ import { HttpServerEndpoint } from '../../Plugin';
3
+ export declare const createEndpoint: (streamrClient: StreamrClient) => HttpServerEndpoint;
@@ -0,0 +1,72 @@
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.createEndpoint = void 0;
7
+ const express_1 = __importDefault(require("express"));
8
+ const utils_1 = require("@streamr/utils");
9
+ const uuid_1 = require("uuid");
10
+ const parser_1 = require("../../helpers/parser");
11
+ const PayloadFormat_1 = require("../../helpers/PayloadFormat");
12
+ const logger = new utils_1.Logger(module);
13
+ const PAYLOAD_FORMAT = new PayloadFormat_1.PlainPayloadFormat();
14
+ const createHandler = (msgChainId, streamrClient) => {
15
+ return async (req, res) => {
16
+ let content;
17
+ let timestamp;
18
+ let partition;
19
+ let partitionKey;
20
+ try {
21
+ content = PAYLOAD_FORMAT.createMessage(req.body.toString()).content;
22
+ timestamp = (0, parser_1.parseQueryParameter)('timestamp', req.query, parser_1.parseTimestamp);
23
+ partition = (0, parser_1.parseQueryParameter)('partition', req.query, parser_1.parsePositiveInteger);
24
+ partitionKey = req.query['partitionKey'];
25
+ }
26
+ catch (e) {
27
+ res.status(400).send({
28
+ error: e.message
29
+ });
30
+ return;
31
+ }
32
+ if ((partition !== undefined) && (partitionKey !== undefined)) {
33
+ res.status(422).send({
34
+ error: 'Invalid combination of "partition" and "partitionKey"'
35
+ });
36
+ return;
37
+ }
38
+ const streamId = req.params.streamId;
39
+ const streamPartDefinition = {
40
+ streamId,
41
+ streamPartition: partition
42
+ };
43
+ try {
44
+ await streamrClient.publish(streamPartDefinition, content, {
45
+ timestamp,
46
+ partitionKey,
47
+ msgChainId
48
+ });
49
+ return res.sendStatus(200);
50
+ }
51
+ catch (err) {
52
+ logger.error('Unable to publish to message', { streamId, err });
53
+ return res.sendStatus(500);
54
+ }
55
+ };
56
+ };
57
+ const createEndpoint = (streamrClient) => {
58
+ const msgChainId = (0, uuid_1.v4)();
59
+ return {
60
+ path: '/streams/:streamId/',
61
+ method: 'post',
62
+ requestHandlers: [
63
+ express_1.default.raw({
64
+ limit: '1024kb',
65
+ type() { return true; },
66
+ }),
67
+ createHandler(msgChainId, streamrClient)
68
+ ]
69
+ };
70
+ };
71
+ exports.createEndpoint = createEndpoint;
72
+ //# sourceMappingURL=publishEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publishEndpoint.js","sourceRoot":"","sources":["../../../../src/plugins/http/publishEndpoint.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAoE;AAEpE,0CAAuC;AACvC,+BAAiC;AACjC,iDAAgG;AAChG,+DAAgE;AAGhE,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AACjC,MAAM,cAAc,GAAG,IAAI,kCAAkB,EAAE,CAAA;AAE/C,MAAM,aAAa,GAAG,CAAC,UAAkB,EAAE,aAA4B,EAAkB,EAAE;IACvF,OAAO,K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QAC9B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAA;YAC/D,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;QAC9B,CAAC;IACL,CAAC,CAAA;AACL,CAAC,CAAA;AAEM,MAAM,cAAc,GAAG,CAAC,aAA4B,EAAsB,EAAE;IAC/E,MAAM,UAAU,GAAG,IAAA,SAAI,GAAE,CAAA;IACzB,OAAO;QACH,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,MAAM;QACd,eAAe,EAAE;YACb,iBAAO,CAAC,GAAG,CAAC;gBACR,KAAK,EAAE,QAAQ;gBACf,IAAI,KAAK,OAAO,IAAI,CAAA,CAAC,CAAC;aACzB,CAAC;YACF,aAAa,CAAC,UAAU,EAAE,aAAa,CAAC;SAC3C;KACJ,CAAA;AACL,CAAC,CAAA;AAbY,QAAA,cAAc,kBAa1B"}
@@ -0,0 +1,9 @@
1
+ import { Schema } from 'ajv';
2
+ import { StreamrClient } from '@streamr/sdk';
3
+ import { ApiPluginConfig, Plugin } from '../../Plugin';
4
+ export declare class InfoPlugin extends Plugin<ApiPluginConfig> {
5
+ start(streamrClient: StreamrClient): Promise<void>;
6
+ private static createEndpoint;
7
+ stop(): Promise<void>;
8
+ getConfigSchema(): Schema;
9
+ }
@@ -0,0 +1,31 @@
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.InfoPlugin = void 0;
7
+ const Plugin_1 = require("../../Plugin");
8
+ const config_schema_json_1 = __importDefault(require("./config.schema.json"));
9
+ class InfoPlugin extends Plugin_1.Plugin {
10
+ async start(streamrClient) {
11
+ this.addHttpServerEndpoint(InfoPlugin.createEndpoint(streamrClient));
12
+ }
13
+ static createEndpoint(streamrClient) {
14
+ return {
15
+ path: '/info',
16
+ method: 'get',
17
+ requestHandlers: [async (_req, res) => {
18
+ res.json(await streamrClient.getDiagnosticInfo());
19
+ }]
20
+ };
21
+ }
22
+ // eslint-disable-next-line class-methods-use-this
23
+ async stop() {
24
+ }
25
+ // eslint-disable-next-line class-methods-use-this
26
+ getConfigSchema() {
27
+ return config_schema_json_1.default;
28
+ }
29
+ }
30
+ exports.InfoPlugin = InfoPlugin;
31
+ //# sourceMappingURL=InfoPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InfoPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/info/InfoPlugin.ts"],"names":[],"mappings":";;;;;;AAGA,yCAA0E;AAC1E,8EAAuD;AAEvD,MAAa,UAAW,SAAQ,eAAuB;IAEnD,KAAK,CAAC,KAAK,CAAC,aAA4B;QACpC,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAA;IACxE,CAAC;IAEO,MAAM,CAAC,cAAc,CAAC,aAA4B;QACtD,OAAO;YACH,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,KAAK;YACb,eAAe,EAAE,CAAC,KAAK,EAAE,IAAa,EAAE,GAAa,EAAE,EAAE;oBACrD,GAAG,CAAC,IAAI,CAAC,MAAM,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAA;gBACrD,CAAC,CAAC;SACL,CAAA;IACL,CAAC;IAED,kDAAkD;IAClD,KAAK,CAAC,IAAI;IACV,CAAC;IAED,kDAAkD;IACzC,eAAe;QACpB,OAAO,4BAAoB,CAAA;IAC/B,CAAC;CACJ;AAxBD,gCAwBC"}
@@ -0,0 +1,12 @@
1
+ {
2
+ "$id": "config.schema.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "description": "Info plugin configuration",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "apiAuthentication": {
9
+ "$ref": "definitions.schema.json#/definitions/apiAuthenticationOverride"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,40 @@
1
+ import { StreamrClient } from '@streamr/sdk';
2
+ import { PayloadFormat } from '../../helpers/PayloadFormat';
3
+ import { MqttServer, MqttServerListener } from './MqttServer';
4
+ export declare class Bridge implements MqttServerListener {
5
+ private readonly streamrClient;
6
+ private readonly mqttServer;
7
+ private readonly payloadFormat;
8
+ private readonly streamIdDomain?;
9
+ private subscriptions;
10
+ private publishMessageChains;
11
+ constructor(streamrClient: StreamrClient, mqttServer: MqttServer, payloadFormat: PayloadFormat, streamIdDomain?: string);
12
+ onMessageReceived(topic: string, payload: string, clientId: string): Promise<void>;
13
+ onSubscribed(topic: string, clientId: string): Promise<void>;
14
+ /**
15
+ *
16
+ * If a stream is subscribed with a MQTT client and also published with same or another
17
+ * MQTT client, the message could be delivered to the subscribed client two
18
+ * ways:
19
+ *
20
+ * 1) automatic mirroring by Aedes (delivers all published messages to all subscribers)
21
+ * 2) via network node: the subscribing MQTT client receives the published message from the
22
+ * network node as it subscribes to the stream (by calling streamrClient.subscribe)
23
+ *
24
+ * The message should be delivered to the subscribed client only once. Theferore we filter
25
+ * out the "via network node" case by checking whether the message is one of the messages
26
+ * which the Bridge published to the network node.
27
+ *
28
+ * Each publishing session of a stream yields to a unique MessageChainKey value. We store that
29
+ * key value when we call streamrClient.publish().
30
+ *
31
+ * Here we simply check if the incoming message belongs to one of the publish chains. If it
32
+ * does, it must have been published by this Bridge.
33
+ */
34
+ private isSelfPublishedMessage;
35
+ onUnsubscribed(topic: string, clientId: string): void;
36
+ private getSubscribeStreamPart;
37
+ private getPublishStreamPart;
38
+ private getStreamId;
39
+ private getSubscription;
40
+ }