kuzzle 2.27.0 → 2.27.2
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 +12 -6
- package/lib/api/controllers/adminController.js +9 -9
- package/lib/api/controllers/bulkController.js +9 -9
- package/lib/api/controllers/collectionController.js +17 -17
- package/lib/api/controllers/documentController.js +51 -51
- package/lib/api/controllers/indexController.js +4 -4
- package/lib/api/controllers/memoryStorageController.js +11 -11
- package/lib/api/controllers/realtimeController.js +1 -1
- package/lib/api/controllers/securityController.js +67 -70
- package/lib/api/controllers/serverController.js +5 -5
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +43 -43
- package/lib/api/rateLimiter.js +1 -1
- package/lib/cluster/command.js +4 -4
- package/lib/cluster/idCardHandler.js +1 -1
- package/lib/cluster/node.js +55 -55
- package/lib/cluster/subscriber.js +33 -33
- package/lib/cluster/workers/IDCardRenewer.js +4 -4
- package/lib/config/index.js +24 -24
- package/lib/core/auth/passportWrapper.js +6 -6
- package/lib/core/cache/cacheEngine.js +20 -20
- package/lib/core/network/accessLogger.js +15 -15
- package/lib/core/network/entryPoint.js +12 -12
- package/lib/core/network/httpRouter/index.js +4 -4
- package/lib/core/network/httpRouter/routePart.js +2 -2
- package/lib/core/network/protocols/httpwsProtocol.js +60 -53
- package/lib/core/network/protocols/internalProtocol.js +2 -2
- package/lib/core/network/protocols/mqttProtocol.js +9 -9
- package/lib/core/network/protocols/protocol.js +3 -3
- package/lib/core/network/router.js +7 -7
- package/lib/core/plugin/plugin.js +23 -23
- package/lib/core/plugin/pluginManifest.js +1 -1
- package/lib/core/plugin/pluginsManager.js +62 -62
- package/lib/core/realtime/notifier.js +14 -14
- package/lib/core/security/README.md +223 -0
- package/lib/core/security/roleRepository.js +18 -18
- package/lib/core/security/securityLoader.js +7 -7
- package/lib/core/security/userRepository.js +16 -16
- package/lib/core/shared/README.md +3 -0
- package/lib/core/shared/abstractManifest.js +1 -1
- package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
- package/lib/core/shared/store.js +11 -11
- package/lib/core/statistics/statistics.js +15 -15
- package/lib/core/storage/clientAdapter.js +61 -61
- package/lib/core/validation/baseType.js +1 -1
- package/lib/core/validation/types/date.js +1 -1
- package/lib/core/validation/types/enum.js +5 -5
- package/lib/core/validation/types/geoShape.js +13 -13
- package/lib/core/validation/types/numeric.js +2 -2
- package/lib/core/validation/types/string.js +2 -2
- package/lib/core/validation/validation.js +71 -71
- package/lib/kerror/codes/index.js +23 -23
- package/lib/kuzzle/dumpGenerator.js +17 -17
- package/lib/kuzzle/event/kuzzleEventEmitter.js +9 -9
- package/lib/kuzzle/event/pipeRunner.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +8 -8
- package/lib/kuzzle/log.js +2 -2
- package/lib/kuzzle/vault.js +4 -4
- package/lib/model/security/role.js +3 -1
- package/lib/model/security/user.js +3 -1
- package/lib/model/storage/apiKey.js +3 -3
- package/lib/model/storage/baseModel.js +7 -7
- package/lib/service/cache/redis.js +3 -3
- package/lib/service/storage/elasticsearch.js +53 -54
- package/lib/service/storage/esWrapper.js +3 -3
- package/lib/service/storage/queryTranslator.js +2 -2
- package/lib/util/assertType.js +1 -1
- package/lib/util/deprecate.js +3 -3
- package/lib/util/extractFields.js +2 -2
- package/lib/util/wildcard.js +1 -1
- package/package.json +68 -81
|
@@ -66,10 +66,10 @@ const JSON_ENDER = '"}';
|
|
|
66
66
|
// Pre-computed messages & errors
|
|
67
67
|
const WS_FORCED_TERMINATION_CODE = 1011;
|
|
68
68
|
const WS_BACKPRESSURE_MESSAGE = Buffer.from(
|
|
69
|
-
"too much backpressure: client is too slow"
|
|
69
|
+
"too much backpressure: client is too slow",
|
|
70
70
|
);
|
|
71
71
|
const WS_GENERIC_CLOSE_MESSAGE = Buffer.from(
|
|
72
|
-
"Connection closed by remote host"
|
|
72
|
+
"Connection closed by remote host",
|
|
73
73
|
);
|
|
74
74
|
const WS_RATE_LIMIT_EXCEEDED_ERROR = kerrorWS.get("ratelimit_exceeded");
|
|
75
75
|
const HTTP_REQUEST_TOO_LARGE_ERROR = kerrorHTTP.get("request_too_large");
|
|
@@ -84,7 +84,7 @@ const HTTP_ALLOWED_CONTENT_TYPES = [
|
|
|
84
84
|
const HTTP_SKIPPED_HEADERS = ["content-length", "set-cookie"];
|
|
85
85
|
const HTTP_HEADER_CONNECTION = Buffer.from("Connection");
|
|
86
86
|
const HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = Buffer.from(
|
|
87
|
-
"Access-Control-Allow-Origin"
|
|
87
|
+
"Access-Control-Allow-Origin",
|
|
88
88
|
);
|
|
89
89
|
const HTTP_HEADER_SET_COOKIE = Buffer.from("Set-Cookie");
|
|
90
90
|
const HTTP_HEADER_VARY = Buffer.from("Vary");
|
|
@@ -148,7 +148,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
148
148
|
this.server.listen(entrypoint.config.port, (socket) => {
|
|
149
149
|
if (!socket) {
|
|
150
150
|
throw new Error(
|
|
151
|
-
`[http/websocket] fatal: unable to listen to port ${entrypoint.config.port}
|
|
151
|
+
`[http/websocket] fatal: unable to listen to port ${entrypoint.config.port}`,
|
|
152
152
|
);
|
|
153
153
|
}
|
|
154
154
|
});
|
|
@@ -204,7 +204,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
204
204
|
debugWS(
|
|
205
205
|
'Publishing to channel "realtime/%s": %s',
|
|
206
206
|
channel,
|
|
207
|
-
payloadSafeCopy
|
|
207
|
+
payloadSafeCopy,
|
|
208
208
|
);
|
|
209
209
|
this.server.publish(`realtime/${channel}`, payloadSafeCopy, false);
|
|
210
210
|
}
|
|
@@ -236,7 +236,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
236
236
|
debugWS(
|
|
237
237
|
'Subscribing connection ID "%s" to channel "realtime/%s"',
|
|
238
238
|
connectionId,
|
|
239
|
-
channel
|
|
239
|
+
channel,
|
|
240
240
|
);
|
|
241
241
|
socket.subscribe(`realtime/${channel}`);
|
|
242
242
|
}
|
|
@@ -251,7 +251,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
251
251
|
debugWS(
|
|
252
252
|
'Removing connection ID "%s" from channel "realtime/%s"',
|
|
253
253
|
connectionId,
|
|
254
|
-
channel
|
|
254
|
+
channel,
|
|
255
255
|
);
|
|
256
256
|
|
|
257
257
|
socket.unsubscribe(`realtime/${channel}`);
|
|
@@ -268,7 +268,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
268
268
|
|
|
269
269
|
socket.end(
|
|
270
270
|
WS_FORCED_TERMINATION_CODE,
|
|
271
|
-
message ? Buffer.from(message) : WS_GENERIC_CLOSE_MESSAGE
|
|
271
|
+
message ? Buffer.from(message) : WS_GENERIC_CLOSE_MESSAGE,
|
|
272
272
|
);
|
|
273
273
|
}
|
|
274
274
|
|
|
@@ -287,7 +287,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
287
287
|
req.getHeader("sec-websocket-key"),
|
|
288
288
|
req.getHeader("sec-websocket-protocol"),
|
|
289
289
|
req.getHeader("sec-websocket-extensions"),
|
|
290
|
-
context
|
|
290
|
+
context,
|
|
291
291
|
);
|
|
292
292
|
}
|
|
293
293
|
|
|
@@ -297,7 +297,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
297
297
|
this.name,
|
|
298
298
|
[ip],
|
|
299
299
|
socket.headers,
|
|
300
|
-
socket.internal
|
|
300
|
+
socket.internal,
|
|
301
301
|
);
|
|
302
302
|
|
|
303
303
|
this.entryPoint.newConnection(connection);
|
|
@@ -318,7 +318,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
318
318
|
"[%s] received a `close` event (CODE: %d, REASON: %s)",
|
|
319
319
|
connection.id,
|
|
320
320
|
code,
|
|
321
|
-
Buffer.from(message || "").toString()
|
|
321
|
+
Buffer.from(message || "").toString(),
|
|
322
322
|
);
|
|
323
323
|
}
|
|
324
324
|
this.entryPoint.removeConnection(connection.id);
|
|
@@ -356,13 +356,13 @@ class HttpWsProtocol extends Protocol {
|
|
|
356
356
|
|
|
357
357
|
({ payload: message } = await global.kuzzle.pipe(
|
|
358
358
|
"protocol:websocket:beforeParsingPayload",
|
|
359
|
-
{ connection, payload: message }
|
|
359
|
+
{ connection, payload: message },
|
|
360
360
|
));
|
|
361
361
|
|
|
362
362
|
try {
|
|
363
363
|
({ payload: parsed } = await global.kuzzle.pipe(
|
|
364
364
|
"protocol:websocket:afterParsingPayload",
|
|
365
|
-
{ connection, payload: JSON.parse(message) }
|
|
365
|
+
{ connection, payload: JSON.parse(message) },
|
|
366
366
|
));
|
|
367
367
|
} catch (e) {
|
|
368
368
|
/*
|
|
@@ -375,7 +375,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
375
375
|
this.wsSendError(
|
|
376
376
|
socket,
|
|
377
377
|
connection,
|
|
378
|
-
kerrorWS.getFrom(e, "unexpected_error", e.message)
|
|
378
|
+
kerrorWS.getFrom(e, "unexpected_error", e.message),
|
|
379
379
|
);
|
|
380
380
|
return;
|
|
381
381
|
}
|
|
@@ -487,7 +487,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
487
487
|
const connection = new ClientConnection(
|
|
488
488
|
"HTTP/1.1",
|
|
489
489
|
getHttpIps(response, request),
|
|
490
|
-
request.headers
|
|
490
|
+
request.headers,
|
|
491
491
|
);
|
|
492
492
|
const message = new HttpMessage(connection, request);
|
|
493
493
|
|
|
@@ -498,29 +498,36 @@ class HttpWsProtocol extends Protocol {
|
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
|
|
501
|
-
const
|
|
501
|
+
const contentTypeHeader = message.headers["content-type"];
|
|
502
502
|
|
|
503
|
-
if (
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
503
|
+
if (contentTypeHeader) {
|
|
504
|
+
const contentTypeParamIndex = contentTypeHeader.indexOf(";");
|
|
505
|
+
const contentType =
|
|
506
|
+
contentTypeParamIndex !== -1
|
|
507
|
+
? contentTypeHeader.slice(0, contentTypeParamIndex).trim()
|
|
508
|
+
: contentTypeHeader.trim();
|
|
509
|
+
|
|
510
|
+
if (
|
|
511
|
+
!this.httpConfig.opts.allowedContentTypes.some(
|
|
512
|
+
(allowed) => contentType === allowed,
|
|
513
|
+
)
|
|
514
|
+
) {
|
|
515
|
+
this.httpSendError(
|
|
516
|
+
message,
|
|
517
|
+
response,
|
|
518
|
+
kerrorHTTP.get("unsupported_content", contentType),
|
|
519
|
+
);
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
515
522
|
}
|
|
516
523
|
|
|
517
|
-
const encoding = CHARSET_REGEX.exec(
|
|
524
|
+
const encoding = CHARSET_REGEX.exec(contentTypeHeader);
|
|
518
525
|
|
|
519
526
|
if (encoding !== null && encoding[1].toLowerCase() !== "utf-8") {
|
|
520
527
|
this.httpSendError(
|
|
521
528
|
message,
|
|
522
529
|
response,
|
|
523
|
-
kerrorHTTP.get("unsupported_charset", encoding[1].toLowerCase())
|
|
530
|
+
kerrorHTTP.get("unsupported_charset", encoding[1].toLowerCase()),
|
|
524
531
|
);
|
|
525
532
|
return;
|
|
526
533
|
}
|
|
@@ -584,7 +591,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
584
591
|
|
|
585
592
|
const { payload: newPayload } = await global.kuzzle.pipe(
|
|
586
593
|
"protocol:http:beforeParsingPayload",
|
|
587
|
-
{ message, payload: inflated }
|
|
594
|
+
{ message, payload: inflated },
|
|
588
595
|
);
|
|
589
596
|
await this.httpParseContent(message, newPayload, cb);
|
|
590
597
|
resolve();
|
|
@@ -634,12 +641,12 @@ class HttpWsProtocol extends Protocol {
|
|
|
634
641
|
try {
|
|
635
642
|
const { payload } = await global.kuzzle.pipe(
|
|
636
643
|
"protocol:http:afterParsingPayload",
|
|
637
|
-
{ message, payload: JSON.parse(content.toString()) }
|
|
644
|
+
{ message, payload: JSON.parse(content.toString()) },
|
|
638
645
|
);
|
|
639
646
|
message.content = payload;
|
|
640
647
|
} catch (e) {
|
|
641
648
|
cb(
|
|
642
|
-
kerrorHTTP.get("body_parse_failed", content.toString().slice(0, 50))
|
|
649
|
+
kerrorHTTP.get("body_parse_failed", content.toString().slice(0, 50)),
|
|
643
650
|
);
|
|
644
651
|
return;
|
|
645
652
|
}
|
|
@@ -686,7 +693,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
686
693
|
|
|
687
694
|
const [success] = response.tryEnd(
|
|
688
695
|
result.compressed,
|
|
689
|
-
result.compressed.length
|
|
696
|
+
result.compressed.length,
|
|
690
697
|
);
|
|
691
698
|
|
|
692
699
|
if (!success) {
|
|
@@ -694,7 +701,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
694
701
|
const retryData = result.compressed.subarray(offset);
|
|
695
702
|
const [retrySuccess] = response.tryEnd(
|
|
696
703
|
retryData,
|
|
697
|
-
retryData.length
|
|
704
|
+
retryData.length,
|
|
698
705
|
);
|
|
699
706
|
|
|
700
707
|
return retrySuccess;
|
|
@@ -732,7 +739,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
732
739
|
) {
|
|
733
740
|
response.writeHeader(
|
|
734
741
|
HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
|
|
735
|
-
Buffer.from(message.headers.origin)
|
|
742
|
+
Buffer.from(message.headers.origin),
|
|
736
743
|
);
|
|
737
744
|
|
|
738
745
|
response.writeHeader(HTTP_HEADER_VARY, ORIGIN);
|
|
@@ -773,8 +780,8 @@ class HttpWsProtocol extends Protocol {
|
|
|
773
780
|
"network",
|
|
774
781
|
"http",
|
|
775
782
|
"stream_errored",
|
|
776
|
-
httpStream.error.message
|
|
777
|
-
)
|
|
783
|
+
httpStream.error.message,
|
|
784
|
+
),
|
|
778
785
|
);
|
|
779
786
|
return;
|
|
780
787
|
}
|
|
@@ -783,7 +790,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
783
790
|
this.httpSendError(
|
|
784
791
|
message,
|
|
785
792
|
response,
|
|
786
|
-
kerror.get("network", "http", "stream_closed")
|
|
793
|
+
kerror.get("network", "http", "stream_closed"),
|
|
787
794
|
);
|
|
788
795
|
return;
|
|
789
796
|
}
|
|
@@ -800,7 +807,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
800
807
|
// Make a copy of the array buffer
|
|
801
808
|
const arrayBuffer = chunk.buffer.slice(
|
|
802
809
|
chunk.byteOffset,
|
|
803
|
-
chunk.byteOffset + chunk.byteLength
|
|
810
|
+
chunk.byteOffset + chunk.byteLength,
|
|
804
811
|
);
|
|
805
812
|
|
|
806
813
|
const arrayBufferOffset = response.getWriteOffset();
|
|
@@ -815,7 +822,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
815
822
|
if (streamSizeFixed) {
|
|
816
823
|
const [success, done] = response.tryEnd(
|
|
817
824
|
arrayBuffer,
|
|
818
|
-
httpStream.totalBytes
|
|
825
|
+
httpStream.totalBytes,
|
|
819
826
|
);
|
|
820
827
|
backpressure = !success;
|
|
821
828
|
|
|
@@ -847,13 +854,13 @@ class HttpWsProtocol extends Protocol {
|
|
|
847
854
|
|
|
848
855
|
let retryBackpressure = false;
|
|
849
856
|
const remainingChunkData = response.arrayBuffer.slice(
|
|
850
|
-
offset - response.arrayBufferOffset
|
|
857
|
+
offset - response.arrayBufferOffset,
|
|
851
858
|
);
|
|
852
859
|
|
|
853
860
|
if (streamSizeFixed) {
|
|
854
861
|
const [success] = response.tryEnd(
|
|
855
862
|
remainingChunkData,
|
|
856
|
-
httpStream.totalBytes
|
|
863
|
+
httpStream.totalBytes,
|
|
857
864
|
);
|
|
858
865
|
|
|
859
866
|
retryBackpressure = !success;
|
|
@@ -892,7 +899,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
892
899
|
debugHTTP(
|
|
893
900
|
"[%s] httpSendStream: %s",
|
|
894
901
|
httpStream.connection.id,
|
|
895
|
-
err.message
|
|
902
|
+
err.message,
|
|
896
903
|
);
|
|
897
904
|
});
|
|
898
905
|
|
|
@@ -924,7 +931,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
924
931
|
connectionId: message.connection.id,
|
|
925
932
|
error: kerr,
|
|
926
933
|
}),
|
|
927
|
-
message
|
|
934
|
+
message,
|
|
928
935
|
);
|
|
929
936
|
this.entryPoint.removeConnection(message.connection.id);
|
|
930
937
|
|
|
@@ -944,12 +951,12 @@ class HttpWsProtocol extends Protocol {
|
|
|
944
951
|
if (global.kuzzle.config.internal.allowAllOrigins) {
|
|
945
952
|
response.writeHeader(
|
|
946
953
|
HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
|
|
947
|
-
WILDCARD
|
|
954
|
+
WILDCARD,
|
|
948
955
|
);
|
|
949
956
|
} else {
|
|
950
957
|
response.writeHeader(
|
|
951
958
|
HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
|
|
952
|
-
Buffer.from(message.headers.origin)
|
|
959
|
+
Buffer.from(message.headers.origin),
|
|
953
960
|
);
|
|
954
961
|
response.writeHeader(HTTP_HEADER_VARY, ORIGIN);
|
|
955
962
|
}
|
|
@@ -1057,7 +1064,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1057
1064
|
callback({
|
|
1058
1065
|
compressed: !err ? compressed : data,
|
|
1059
1066
|
encoding: !err ? "gzip" : "identity",
|
|
1060
|
-
})
|
|
1067
|
+
}),
|
|
1061
1068
|
);
|
|
1062
1069
|
return;
|
|
1063
1070
|
} else if (algorithm === "deflate") {
|
|
@@ -1065,7 +1072,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1065
1072
|
callback({
|
|
1066
1073
|
compressed: !err ? compressed : data,
|
|
1067
1074
|
encoding: !err ? "deflate" : "identity",
|
|
1068
|
-
})
|
|
1075
|
+
}),
|
|
1069
1076
|
);
|
|
1070
1077
|
return;
|
|
1071
1078
|
}
|
|
@@ -1130,7 +1137,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1130
1137
|
|
|
1131
1138
|
if (cfg === undefined) {
|
|
1132
1139
|
global.kuzzle.log.warn(
|
|
1133
|
-
"[websocket] no configuration found for websocket: disabling it"
|
|
1140
|
+
"[websocket] no configuration found for websocket: disabling it",
|
|
1134
1141
|
);
|
|
1135
1142
|
return { enabled: false };
|
|
1136
1143
|
}
|
|
@@ -1141,7 +1148,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1141
1148
|
if (idleTimeout === 0 || idleTimeout < 1000) {
|
|
1142
1149
|
idleTimeout = DEFAULT_IDLE_TIMEOUT;
|
|
1143
1150
|
global.kuzzle.log.warn(
|
|
1144
|
-
`[websocket] The "idleTimeout" parameter can neither be deactivated or be set with a value lower than 1000. Defaulted to ${DEFAULT_IDLE_TIMEOUT}
|
|
1151
|
+
`[websocket] The "idleTimeout" parameter can neither be deactivated or be set with a value lower than 1000. Defaulted to ${DEFAULT_IDLE_TIMEOUT}.`,
|
|
1145
1152
|
);
|
|
1146
1153
|
}
|
|
1147
1154
|
|
|
@@ -1152,7 +1159,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1152
1159
|
*/
|
|
1153
1160
|
if (cfg.heartbeat) {
|
|
1154
1161
|
global.kuzzle.log.warn(
|
|
1155
|
-
'[websocket] The "heartbeat" parameter has been deprecated and is now ignored. The "idleTimeout" parameter should now be configured instead.'
|
|
1162
|
+
'[websocket] The "heartbeat" parameter has been deprecated and is now ignored. The "idleTimeout" parameter should now be configured instead.',
|
|
1156
1163
|
);
|
|
1157
1164
|
}
|
|
1158
1165
|
|
|
@@ -1174,7 +1181,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
1174
1181
|
|
|
1175
1182
|
if (cfg === undefined) {
|
|
1176
1183
|
global.kuzzle.log.warn(
|
|
1177
|
-
"[http] no configuration found for http: disabling it"
|
|
1184
|
+
"[http] no configuration found for http: disabling it",
|
|
1178
1185
|
);
|
|
1179
1186
|
return { enabled: false };
|
|
1180
1187
|
}
|
|
@@ -25,7 +25,7 @@ const Protocol = require("./protocol");
|
|
|
25
25
|
const ClientConnection = require("../clientConnection");
|
|
26
26
|
|
|
27
27
|
const debug = require("../../../util/debug")(
|
|
28
|
-
"kuzzle:network:protocols:internal"
|
|
28
|
+
"kuzzle:network:protocols:internal",
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -63,7 +63,7 @@ class InternalProtocol extends Protocol {
|
|
|
63
63
|
*/
|
|
64
64
|
global.kuzzle.onAsk(
|
|
65
65
|
"core:network:internal:connectionId:get",
|
|
66
|
-
() => this.connection.id
|
|
66
|
+
() => this.connection.id,
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -73,7 +73,7 @@ class MqttProtocol extends Protocol {
|
|
|
73
73
|
port: 1883,
|
|
74
74
|
},
|
|
75
75
|
},
|
|
76
|
-
this.config
|
|
76
|
+
this.config,
|
|
77
77
|
);
|
|
78
78
|
|
|
79
79
|
/*
|
|
@@ -93,7 +93,7 @@ class MqttProtocol extends Protocol {
|
|
|
93
93
|
this.aedes.on("publish", this.onMessage.bind(this));
|
|
94
94
|
|
|
95
95
|
await new Promise((res) =>
|
|
96
|
-
this.server.listen(this.config.server.port, res)
|
|
96
|
+
this.server.listen(this.config.server.port, res),
|
|
97
97
|
);
|
|
98
98
|
|
|
99
99
|
return true;
|
|
@@ -152,7 +152,7 @@ class MqttProtocol extends Protocol {
|
|
|
152
152
|
const connection = new ClientConnection(
|
|
153
153
|
this.name,
|
|
154
154
|
[client.conn.remoteAddress],
|
|
155
|
-
{}
|
|
155
|
+
{},
|
|
156
156
|
);
|
|
157
157
|
this.entryPoint.newConnection(connection);
|
|
158
158
|
|
|
@@ -198,10 +198,10 @@ class MqttProtocol extends Protocol {
|
|
|
198
198
|
debug(
|
|
199
199
|
"no connection id for client id %s - packet: %o",
|
|
200
200
|
client.id,
|
|
201
|
-
packet
|
|
201
|
+
packet,
|
|
202
202
|
);
|
|
203
203
|
global.kuzzle.log.error(
|
|
204
|
-
`[MQTT] Received a packet from an unregistered client: ${client.id}
|
|
204
|
+
`[MQTT] Received a packet from an unregistered client: ${client.id}`,
|
|
205
205
|
);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
@@ -214,7 +214,7 @@ class MqttProtocol extends Protocol {
|
|
|
214
214
|
const request = new Request(payload, { connection });
|
|
215
215
|
|
|
216
216
|
this.entryPoint.execute(connection, request, (response) =>
|
|
217
|
-
this._respond(client, response)
|
|
217
|
+
this._respond(client, response),
|
|
218
218
|
);
|
|
219
219
|
} catch (error) {
|
|
220
220
|
this._respondError(client, error);
|
|
@@ -238,7 +238,7 @@ class MqttProtocol extends Protocol {
|
|
|
238
238
|
payload: Buffer.from(JSON.stringify(response.content)),
|
|
239
239
|
topic: this.config.responseTopic,
|
|
240
240
|
},
|
|
241
|
-
this.publishCallback
|
|
241
|
+
this.publishCallback,
|
|
242
242
|
);
|
|
243
243
|
}
|
|
244
244
|
|
|
@@ -250,7 +250,7 @@ class MqttProtocol extends Protocol {
|
|
|
250
250
|
{
|
|
251
251
|
connection,
|
|
252
252
|
error: kerror.getFrom(error, "unexpected_error", error.message),
|
|
253
|
-
}
|
|
253
|
+
},
|
|
254
254
|
);
|
|
255
255
|
this._respond(client, removeStacktrace(errReq.response.toJSON()));
|
|
256
256
|
}
|
|
@@ -270,7 +270,7 @@ class MqttProtocol extends Protocol {
|
|
|
270
270
|
callback(
|
|
271
271
|
topic === this.config.requestTopic
|
|
272
272
|
? null
|
|
273
|
-
: new Error("Cannot publish on this topic: unauthorized")
|
|
273
|
+
: new Error("Cannot publish on this topic: unauthorized"),
|
|
274
274
|
);
|
|
275
275
|
}
|
|
276
276
|
}
|
|
@@ -52,7 +52,7 @@ class Protocol {
|
|
|
52
52
|
// name should be passed in the constructor
|
|
53
53
|
assert(
|
|
54
54
|
this.name && !name,
|
|
55
|
-
"A name has been given in the constructor and init method. Passing the name in the init method is deprecated."
|
|
55
|
+
"A name has been given in the constructor and init method. Passing the name in the init method is deprecated.",
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
if (!this.name) {
|
|
@@ -63,7 +63,7 @@ class Protocol {
|
|
|
63
63
|
|
|
64
64
|
assert(
|
|
65
65
|
typeof this.name === "string" && this.name.length > 0,
|
|
66
|
-
'Invalid "name" parameter value: expected a non empty string value'
|
|
66
|
+
'Invalid "name" parameter value: expected a non empty string value',
|
|
67
67
|
);
|
|
68
68
|
|
|
69
69
|
if (entryPoint.config.protocols && entryPoint.config.protocols[this.name]) {
|
|
@@ -72,7 +72,7 @@ class Protocol {
|
|
|
72
72
|
|
|
73
73
|
assert(
|
|
74
74
|
Number.isInteger(this.maxRequestSize),
|
|
75
|
-
'Invalid "maxRequestSize" parameter value: expected a numeric value'
|
|
75
|
+
'Invalid "maxRequestSize" parameter value: expected a numeric value',
|
|
76
76
|
);
|
|
77
77
|
|
|
78
78
|
this.initCalled = true;
|
|
@@ -49,8 +49,8 @@ class Router {
|
|
|
49
49
|
"protocol",
|
|
50
50
|
"runtime",
|
|
51
51
|
"invalid_connection",
|
|
52
|
-
JSON.stringify(requestContext)
|
|
53
|
-
)
|
|
52
|
+
JSON.stringify(requestContext),
|
|
53
|
+
),
|
|
54
54
|
);
|
|
55
55
|
} else {
|
|
56
56
|
this.connections.set(requestContext.connection.id, requestContext);
|
|
@@ -72,8 +72,8 @@ class Router {
|
|
|
72
72
|
"protocol",
|
|
73
73
|
"runtime",
|
|
74
74
|
"invalid_connection",
|
|
75
|
-
JSON.stringify(requestContext.context)
|
|
76
|
-
)
|
|
75
|
+
JSON.stringify(requestContext.context),
|
|
76
|
+
),
|
|
77
77
|
);
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
@@ -84,8 +84,8 @@ class Router {
|
|
|
84
84
|
"protocol",
|
|
85
85
|
"runtime",
|
|
86
86
|
"unknown_connection",
|
|
87
|
-
JSON.stringify(connId)
|
|
88
|
-
)
|
|
87
|
+
JSON.stringify(connId),
|
|
88
|
+
),
|
|
89
89
|
);
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
@@ -130,7 +130,7 @@ class Router {
|
|
|
130
130
|
|
|
131
131
|
const apiRequest = new Request(
|
|
132
132
|
requestPayload,
|
|
133
|
-
request.serialize().options
|
|
133
|
+
request.serialize().options,
|
|
134
134
|
);
|
|
135
135
|
|
|
136
136
|
this._executeFromHttp("post", apiRequest, cb);
|