kuzzle 2.19.10 → 2.19.12
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/lib/core/network/protocols/httpwsProtocol.js +30 -7
- package/lib/service/storage/elasticsearch.js +16 -0
- package/lib/types/ClientConnection.d.ts +7 -0
- package/lib/types/ClientConnection.js +3 -0
- package/lib/types/HttpMessage.d.ts +12 -0
- package/lib/types/HttpMessage.js +3 -0
- package/lib/types/ProfileDefinition.d.ts +1 -1
- package/lib/types/events/EventProtocol.d.ts +32 -0
- package/lib/types/events/EventProtocol.js +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/package.json +1 -1
|
@@ -324,7 +324,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
324
324
|
this.socketByConnectionId.delete(connection.id);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
wsOnMessageHandler(socket, data) {
|
|
327
|
+
async wsOnMessageHandler(socket, data) {
|
|
328
328
|
if (!data || data.byteLength === 0) {
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
@@ -347,12 +347,20 @@ class HttpWsProtocol extends Protocol {
|
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
let parsed;
|
|
350
|
-
|
|
350
|
+
let message = Buffer.from(data).toString();
|
|
351
351
|
|
|
352
352
|
debugWS("[%s] client message: %s", connection.id, message);
|
|
353
353
|
|
|
354
|
+
({ payload: message } = await global.kuzzle.pipe(
|
|
355
|
+
"protocol:websocket:beforeParsingPayload",
|
|
356
|
+
{ connection, payload: message }
|
|
357
|
+
));
|
|
358
|
+
|
|
354
359
|
try {
|
|
355
|
-
parsed =
|
|
360
|
+
({ payload: parsed } = await global.kuzzle.pipe(
|
|
361
|
+
"protocol:websocket:afterParsingPayload",
|
|
362
|
+
{ connection, payload: JSON.parse(message) }
|
|
363
|
+
));
|
|
356
364
|
} catch (e) {
|
|
357
365
|
/*
|
|
358
366
|
we cannot add a "room" information since we need to extract
|
|
@@ -552,14 +560,25 @@ class HttpWsProtocol extends Protocol {
|
|
|
552
560
|
return;
|
|
553
561
|
}
|
|
554
562
|
|
|
555
|
-
|
|
563
|
+
let resolve;
|
|
564
|
+
let promise = new Promise((res) => (resolve = res));
|
|
565
|
+
|
|
566
|
+
this.httpUncompress(message, payload, async (err, inflated) => {
|
|
556
567
|
if (err) {
|
|
557
568
|
cb(err);
|
|
569
|
+
resolve();
|
|
558
570
|
return;
|
|
559
571
|
}
|
|
560
572
|
|
|
561
|
-
|
|
573
|
+
const { payload: newPayload } = await global.kuzzle.pipe(
|
|
574
|
+
"protocol:http:beforeParsingPayload",
|
|
575
|
+
{ message, payload: inflated }
|
|
576
|
+
);
|
|
577
|
+
await this.httpParseContent(message, newPayload, cb);
|
|
578
|
+
resolve();
|
|
562
579
|
});
|
|
580
|
+
|
|
581
|
+
return promise;
|
|
563
582
|
});
|
|
564
583
|
|
|
565
584
|
// Beware: the "response" object might be invalidated at any point of time,
|
|
@@ -569,7 +588,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
569
588
|
});
|
|
570
589
|
}
|
|
571
590
|
|
|
572
|
-
httpParseContent(message, content, cb) {
|
|
591
|
+
async httpParseContent(message, content, cb) {
|
|
573
592
|
const type = message.headers["content-type"] || "";
|
|
574
593
|
|
|
575
594
|
if (type.includes("multipart/form-data")) {
|
|
@@ -601,7 +620,11 @@ class HttpWsProtocol extends Protocol {
|
|
|
601
620
|
message.content = querystring.parse(content.toString());
|
|
602
621
|
} else {
|
|
603
622
|
try {
|
|
604
|
-
|
|
623
|
+
const { payload } = await global.kuzzle.pipe(
|
|
624
|
+
"protocol:http:afterParsingPayload",
|
|
625
|
+
{ message, payload: JSON.parse(content.toString()) }
|
|
626
|
+
);
|
|
627
|
+
message.content = payload;
|
|
605
628
|
} catch (e) {
|
|
606
629
|
cb(
|
|
607
630
|
kerrorHTTP.get("body_parse_failed", content.toString().slice(0, 50))
|
|
@@ -1961,6 +1961,12 @@ class ElasticSearch extends Service {
|
|
|
1961
1961
|
try {
|
|
1962
1962
|
await this._client.indices.delete(esRequest);
|
|
1963
1963
|
|
|
1964
|
+
if (await this._checkIfAliasExists(this._getAlias(index, collection))) {
|
|
1965
|
+
await this._client.indices.deleteAlias({
|
|
1966
|
+
name: this._getAlias(index, collection),
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1964
1970
|
await this._createHiddenCollection(index);
|
|
1965
1971
|
} catch (e) {
|
|
1966
1972
|
throw this._esWrapper.formatESError(e);
|
|
@@ -2917,6 +2923,16 @@ class ElasticSearch extends Service {
|
|
|
2917
2923
|
return `${ALIAS_PREFIX}${this._indexPrefix}${index}${NAME_SEPARATOR}${collection}`;
|
|
2918
2924
|
}
|
|
2919
2925
|
|
|
2926
|
+
/**
|
|
2927
|
+
* Given an alias name, returns the associated index name.
|
|
2928
|
+
*/
|
|
2929
|
+
async _checkIfAliasExists(aliasName) {
|
|
2930
|
+
const { body } = await this._client.indices.existsAlias({
|
|
2931
|
+
name: aliasName,
|
|
2932
|
+
});
|
|
2933
|
+
return body;
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2920
2936
|
/**
|
|
2921
2937
|
* Given index + collection, returns the associated indice name.
|
|
2922
2938
|
* Use this function if ES does not accept aliases in the request. Otherwise use `_getAlias`.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { JSONObject } from "../..";
|
|
2
|
+
import { ClientConnection } from "./ClientConnection";
|
|
3
|
+
export interface HttpMessage {
|
|
4
|
+
connection: ClientConnection;
|
|
5
|
+
content: JSONObject;
|
|
6
|
+
ips: string[];
|
|
7
|
+
query: string;
|
|
8
|
+
path: string;
|
|
9
|
+
method: string;
|
|
10
|
+
headers: JSONObject;
|
|
11
|
+
requestId: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { JSONObject, PipeEventHandler } from "../../../";
|
|
3
|
+
import { ClientConnection } from "../ClientConnection";
|
|
4
|
+
import { HttpMessage } from "../HttpMessage";
|
|
5
|
+
export type EventHTTPBeforeParsingPayload = {
|
|
6
|
+
name: `protocol:http:beforeParsingPayload`;
|
|
7
|
+
args: [{
|
|
8
|
+
message: HttpMessage;
|
|
9
|
+
payload: Buffer;
|
|
10
|
+
}];
|
|
11
|
+
} & PipeEventHandler;
|
|
12
|
+
export type EventHTTPAfterParsingPayload = {
|
|
13
|
+
name: `protocol:http:afterParsingPayload`;
|
|
14
|
+
args: [{
|
|
15
|
+
message: HttpMessage;
|
|
16
|
+
payload: JSONObject;
|
|
17
|
+
}];
|
|
18
|
+
} & PipeEventHandler;
|
|
19
|
+
export type EventWebsocketBeforeParsingPayload = {
|
|
20
|
+
name: `protocol:websocket:beforeParsingPayload`;
|
|
21
|
+
args: [{
|
|
22
|
+
connection: ClientConnection;
|
|
23
|
+
payload: Buffer;
|
|
24
|
+
}];
|
|
25
|
+
} & PipeEventHandler;
|
|
26
|
+
export type EventWebsocketAfterParsingPayload = {
|
|
27
|
+
name: `protocol:websocket:afterParsingPayload`;
|
|
28
|
+
args: [{
|
|
29
|
+
connection: ClientConnection;
|
|
30
|
+
payload: JSONObject;
|
|
31
|
+
}];
|
|
32
|
+
} & PipeEventHandler;
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -72,4 +72,5 @@ __exportStar(require("./OpenApiDefinition"), exports);
|
|
|
72
72
|
__exportStar(require("./errors/ErrorDefinition"), exports);
|
|
73
73
|
__exportStar(require("./errors/ErrorDomains"), exports);
|
|
74
74
|
__exportStar(require("./events/EventGenericDocument"), exports);
|
|
75
|
+
__exportStar(require("./events/EventProtocol"), exports);
|
|
75
76
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kuzzle",
|
|
3
3
|
"author": "The Kuzzle Team <support@kuzzle.io>",
|
|
4
|
-
"version": "2.19.
|
|
4
|
+
"version": "2.19.12",
|
|
5
5
|
"description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
|
|
6
6
|
"bin": "bin/start-kuzzle-server",
|
|
7
7
|
"scripts": {
|