kuzzle 2.17.0 → 2.17.3
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/api/controllers/authController.js +1 -1
- package/lib/api/controllers/securityController.js +1 -1
- package/lib/api/controllers/serverController.js +0 -1
- package/lib/api/funnel.js +4 -0
- package/lib/api/request/kuzzleRequest.js +5 -7
- package/lib/api/request/requestResponse.js +6 -1
- package/lib/cluster/state.js +20 -4
- package/lib/core/backend/backend.d.ts +7 -3
- package/lib/core/backend/backend.js +10 -9
- package/lib/core/backend/backendConfig.js +21 -2
- package/lib/core/backend/backendController.js +21 -5
- package/lib/core/backend/backendErrors.d.ts +58 -0
- package/lib/core/backend/backendErrors.js +121 -0
- package/lib/core/backend/backendHook.js +21 -5
- package/lib/core/backend/backendImport.js +21 -5
- package/lib/core/backend/backendOpenApi.js +1 -1
- package/lib/core/backend/backendPipe.js +21 -5
- package/lib/core/backend/backendPlugin.js +22 -3
- package/lib/core/backend/backendVault.js +21 -2
- package/lib/core/backend/index.d.ts +1 -0
- package/lib/core/backend/index.js +1 -0
- package/lib/core/network/protocols/httpMessage.js +2 -1
- package/lib/core/network/protocols/httpwsProtocol.js +31 -8
- package/lib/core/plugin/pluginContext.js +22 -3
- package/lib/core/realtime/channel.js +20 -4
- package/lib/core/realtime/hotelClerk.js +24 -5
- package/lib/core/security/profileRepository.js +26 -7
- package/lib/core/shared/sdk/embeddedSdk.js +21 -2
- package/lib/core/storage/indexCache.js +20 -4
- package/lib/kerror/codes/0-core.json +1 -1
- package/lib/kerror/codes/1-services.json +1 -1
- package/lib/kerror/codes/2-api.json +1 -1
- package/lib/kerror/codes/3-network.json +1 -1
- package/lib/kerror/codes/4-plugin.json +1 -1
- package/lib/kerror/codes/5-validation.json +1 -1
- package/lib/kerror/codes/6-protocol.json +1 -1
- package/lib/kerror/codes/7-security.json +1 -1
- package/lib/kerror/codes/8-cluster.json +1 -1
- package/lib/kerror/codes/index.js +7 -7
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +3 -3
- package/lib/kerror/index.d.ts +82 -0
- package/lib/kerror/index.js +180 -143
- package/lib/kuzzle/kuzzle.js +23 -4
- package/lib/model/security/profile.js +24 -5
- package/lib/model/security/role.js +21 -5
- package/lib/model/security/user.js +21 -2
- package/lib/types/Plugin.js +20 -4
- package/lib/types/errors/ErrorDefinition.d.ts +33 -0
- package/lib/types/errors/ErrorDefinition.js +3 -0
- package/lib/types/errors/ErrorDomains.d.ts +17 -0
- package/lib/types/errors/ErrorDomains.js +3 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -0
- package/lib/util/dump-collection.js +21 -2
- package/lib/util/mutex.js +21 -2
- package/package-lock.json +4 -4
- package/package.json +1 -1
|
@@ -19,15 +19,34 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
25
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
45
|
exports.BackendVault = void 0;
|
|
27
46
|
const vault_1 = __importDefault(require("../../kuzzle/vault"));
|
|
28
|
-
const
|
|
47
|
+
const kerror = __importStar(require("../../kerror"));
|
|
29
48
|
const index_1 = require("./index");
|
|
30
|
-
const runtimeError =
|
|
49
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
31
50
|
class BackendVault extends index_1.ApplicationManager {
|
|
32
51
|
constructor() {
|
|
33
52
|
super(...arguments);
|
|
@@ -23,4 +23,5 @@ __exportStar(require("./backendStorage"), exports);
|
|
|
23
23
|
__exportStar(require("./backendVault"), exports);
|
|
24
24
|
__exportStar(require("./backendOpenApi"), exports);
|
|
25
25
|
__exportStar(require("./internalLogger"), exports);
|
|
26
|
+
__exportStar(require("./backendErrors"), exports);
|
|
26
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -33,7 +33,6 @@ class HttpMessage {
|
|
|
33
33
|
this.connection = connection;
|
|
34
34
|
this._content = null;
|
|
35
35
|
this.ips = connection.ips;
|
|
36
|
-
this.requestId = connection.id;
|
|
37
36
|
this.query = request.getQuery();
|
|
38
37
|
this.path = request.getUrl();
|
|
39
38
|
|
|
@@ -51,6 +50,8 @@ class HttpMessage {
|
|
|
51
50
|
this.headers = {};
|
|
52
51
|
|
|
53
52
|
request.forEach((name, value) => (this.headers[name] = value));
|
|
53
|
+
|
|
54
|
+
this.requestId = this.headers['x-kuzzle-request-id'] || connection.id;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
set content (value) {
|
|
@@ -77,6 +77,9 @@ const HTTP_ALLOWED_CONTENT_TYPES = [
|
|
|
77
77
|
'application/x-www-form-urlencoded',
|
|
78
78
|
'multipart/form-data',
|
|
79
79
|
];
|
|
80
|
+
const HTTP_SKIPPED_HEADERS = [
|
|
81
|
+
'content-length',
|
|
82
|
+
];
|
|
80
83
|
const HTTP_HEADER_CONNECTION = Buffer.from('Connection');
|
|
81
84
|
const HTTP_HEADER_CONTENT_LENGTH = Buffer.from('Content-Length');
|
|
82
85
|
const HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = Buffer.from('Access-Control-Allow-Origin');
|
|
@@ -85,6 +88,7 @@ const HTTP_HEADER_TRANSFER_ENCODING = Buffer.from('Transfer-Encoding');
|
|
|
85
88
|
const CHUNKED = Buffer.from('chunked');
|
|
86
89
|
const WILDCARD = Buffer.from('*');
|
|
87
90
|
const ORIGIN = Buffer.from('Origin');
|
|
91
|
+
const X_KUZZLE_REQUEST_ID = Buffer.from('X-Kuzzle-Request-Id');
|
|
88
92
|
const CLOSE = Buffer.from('close');
|
|
89
93
|
const CHARSET_REGEX = /charset=([\w-]+)/i;
|
|
90
94
|
|
|
@@ -255,6 +259,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
255
259
|
res.upgrade(
|
|
256
260
|
{
|
|
257
261
|
cookie: req.getHeader('cookie'),
|
|
262
|
+
origin: req.getHeader('origin'),
|
|
258
263
|
},
|
|
259
264
|
req.getHeader('sec-websocket-key'),
|
|
260
265
|
req.getHeader('sec-websocket-protocol'),
|
|
@@ -265,7 +270,14 @@ class HttpWsProtocol extends Protocol {
|
|
|
265
270
|
|
|
266
271
|
wsOnOpenHandler (socket) {
|
|
267
272
|
const ip = Buffer.from(socket.getRemoteAddressAsText()).toString();
|
|
268
|
-
const connection = new ClientConnection(
|
|
273
|
+
const connection = new ClientConnection(
|
|
274
|
+
this.name,
|
|
275
|
+
[ip],
|
|
276
|
+
{
|
|
277
|
+
cookie: socket.cookie,
|
|
278
|
+
origin: socket.origin
|
|
279
|
+
}
|
|
280
|
+
);
|
|
269
281
|
|
|
270
282
|
this.entryPoint.newConnection(connection);
|
|
271
283
|
this.connectionBySocket.set(socket, connection);
|
|
@@ -351,7 +363,7 @@ class HttpWsProtocol extends Protocol {
|
|
|
351
363
|
request = new Request(parsed, { connection });
|
|
352
364
|
}
|
|
353
365
|
catch (e) {
|
|
354
|
-
this.wsSendError(socket, connection, e);
|
|
366
|
+
this.wsSendError(socket, connection, e, parsed.requestId);
|
|
355
367
|
return;
|
|
356
368
|
}
|
|
357
369
|
|
|
@@ -392,9 +404,14 @@ class HttpWsProtocol extends Protocol {
|
|
|
392
404
|
* @param {uWS.WebSocket} socket
|
|
393
405
|
* @param {ClientConnection} connection
|
|
394
406
|
* @param {Error} error
|
|
407
|
+
* @param {String} requestId @optional
|
|
395
408
|
*/
|
|
396
|
-
wsSendError (socket, connection, error) {
|
|
409
|
+
wsSendError (socket, connection, error, requestId) {
|
|
397
410
|
const request = new Request({}, { connection, error });
|
|
411
|
+
|
|
412
|
+
// If a requestId is provided we use it instead of the generated one
|
|
413
|
+
request.id = requestId || request.id;
|
|
414
|
+
|
|
398
415
|
const sanitized = removeErrorStack(request.response.toJSON()).content;
|
|
399
416
|
|
|
400
417
|
this.wsSend(socket, Buffer.from(JSON.stringify(sanitized)));
|
|
@@ -626,15 +643,16 @@ class HttpWsProtocol extends Protocol {
|
|
|
626
643
|
}
|
|
627
644
|
|
|
628
645
|
/**
|
|
629
|
-
*
|
|
630
|
-
* @param {uWS.HttpRequest} request
|
|
631
|
-
* @param {uWS.HttpResponse} response
|
|
632
|
-
* @param {HttpMessage} message
|
|
646
|
+
*
|
|
647
|
+
* @param {uWS.HttpRequest} request
|
|
648
|
+
* @param {uWS.HttpResponse} response
|
|
649
|
+
* @param {HttpMessage} message
|
|
633
650
|
*/
|
|
634
651
|
httpWriteRequestHeaders (request, response, message) {
|
|
635
652
|
response.writeStatus(Buffer.from(request.response.status.toString()));
|
|
636
|
-
|
|
653
|
+
|
|
637
654
|
response.writeHeader(HTTP_HEADER_CONNECTION, CLOSE);
|
|
655
|
+
response.writeHeader(X_KUZZLE_REQUEST_ID, message.requestId);
|
|
638
656
|
|
|
639
657
|
for (const header of this.httpConfig.headers) {
|
|
640
658
|
// If header is missing, add the default one
|
|
@@ -656,6 +674,11 @@ class HttpWsProtocol extends Protocol {
|
|
|
656
674
|
}
|
|
657
675
|
|
|
658
676
|
for (const [key, value] of Object.entries(request.response.headers)) {
|
|
677
|
+
// Skip some headers that are not allowed to be sent or modified
|
|
678
|
+
if (HTTP_SKIPPED_HEADERS.includes(key.toLowerCase())) {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
|
|
659
682
|
response.writeHeader(Buffer.from(key), Buffer.from(value.toString()));
|
|
660
683
|
}
|
|
661
684
|
}
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -33,12 +52,12 @@ const elasticsearch_1 = __importDefault(require("../../service/storage/elasticse
|
|
|
33
52
|
const safeObject_1 = require("../../util/safeObject");
|
|
34
53
|
const promback_1 = __importDefault(require("../../util/promback"));
|
|
35
54
|
const mutex_1 = require("../../util/mutex");
|
|
36
|
-
const
|
|
55
|
+
const kerror = __importStar(require("../../kerror"));
|
|
37
56
|
const storeScopeEnum_1 = __importDefault(require("../storage/storeScopeEnum"));
|
|
38
57
|
const errors_1 = require("../../kerror/errors");
|
|
39
58
|
const index_1 = require("../../../index");
|
|
40
59
|
const backend_1 = require("../backend");
|
|
41
|
-
const contextError =
|
|
60
|
+
const contextError = kerror.wrap('plugin', 'context');
|
|
42
61
|
class PluginContext {
|
|
43
62
|
constructor(pluginName) {
|
|
44
63
|
this.config = JSON.parse(JSON.stringify(global.kuzzle.config));
|
|
@@ -60,7 +79,7 @@ class PluginContext {
|
|
|
60
79
|
TooManyRequestsError: errors_1.TooManyRequestsError,
|
|
61
80
|
UnauthorizedError: errors_1.UnauthorizedError,
|
|
62
81
|
};
|
|
63
|
-
this.kerror =
|
|
82
|
+
this.kerror = kerror.wrap('plugin', pluginName);
|
|
64
83
|
// @deprecated - backward compatibility only
|
|
65
84
|
this.errorsManager = this.kerror;
|
|
66
85
|
/* context.secrets ====================================================== */
|
|
@@ -19,13 +19,29 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
24
40
|
};
|
|
25
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
42
|
exports.Channel = void 0;
|
|
27
|
-
const
|
|
28
|
-
const realtimeError =
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
44
|
+
const realtimeError = kerror.wrap('core', 'realtime');
|
|
29
45
|
/**
|
|
30
46
|
* A channel define how notifications should be send for a particular realtime
|
|
31
47
|
* room.
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -26,14 +45,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
45
|
exports.HotelClerk = void 0;
|
|
27
46
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
28
47
|
const request_1 = require("../../api/request");
|
|
29
|
-
const
|
|
48
|
+
const kerror = __importStar(require("../../kerror"));
|
|
30
49
|
const debug_1 = __importDefault(require("../../util/debug"));
|
|
31
50
|
const koncordeCompat_1 = require("../../util/koncordeCompat");
|
|
32
51
|
const channel_1 = require("./channel");
|
|
33
52
|
const connectionRooms_1 = require("./connectionRooms");
|
|
34
53
|
const room_1 = require("./room");
|
|
35
54
|
const subscription_1 = require("./subscription");
|
|
36
|
-
const realtimeError =
|
|
55
|
+
const realtimeError = kerror.wrap('core', 'realtime');
|
|
37
56
|
const debug = (0, debug_1.default)('kuzzle:realtime:hotelClerk');
|
|
38
57
|
/**
|
|
39
58
|
* The HotelClerk is responsible of keeping the list of rooms and subscriptions
|
|
@@ -168,10 +187,10 @@ class HotelClerk {
|
|
|
168
187
|
async subscribe(request) {
|
|
169
188
|
const { index, collection } = request.input.resource;
|
|
170
189
|
if (!index) {
|
|
171
|
-
return
|
|
190
|
+
return kerror.reject('api', 'assert', 'missing_argument', 'index');
|
|
172
191
|
}
|
|
173
192
|
if (!collection) {
|
|
174
|
-
return
|
|
193
|
+
return kerror.reject('api', 'assert', 'missing_argument', 'collection');
|
|
175
194
|
}
|
|
176
195
|
/*
|
|
177
196
|
* /!\ This check is a duplicate to the one already made by the
|
|
@@ -192,7 +211,7 @@ class HotelClerk {
|
|
|
192
211
|
normalized = this.koncorde.normalize(request.input.body, (0, koncordeCompat_1.toKoncordeIndex)(index, collection));
|
|
193
212
|
}
|
|
194
213
|
catch (e) {
|
|
195
|
-
throw
|
|
214
|
+
throw kerror.get('api', 'assert', 'koncorde_dsl_error', e.message);
|
|
196
215
|
}
|
|
197
216
|
this.createRoom(normalized);
|
|
198
217
|
const { channel, subscribed } = await this.subscribeToRoom(normalized.id, request);
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -28,7 +47,7 @@ const lodash_1 = require("lodash");
|
|
|
28
47
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
29
48
|
const profile_1 = require("../../model/security/profile");
|
|
30
49
|
const repository_1 = __importDefault(require("../shared/repository"));
|
|
31
|
-
const
|
|
50
|
+
const kerror = __importStar(require("../../kerror"));
|
|
32
51
|
const cacheDbEnum_1 = __importDefault(require("../cache/cacheDbEnum"));
|
|
33
52
|
/**
|
|
34
53
|
* @class ProfileRepository
|
|
@@ -159,7 +178,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
159
178
|
async loadProfiles(profileIds = []) {
|
|
160
179
|
const profiles = [];
|
|
161
180
|
if (profileIds.some(p => typeof p !== 'string')) {
|
|
162
|
-
throw
|
|
181
|
+
throw kerror.get('api', 'assert', 'invalid_type', 'profileIds', 'string[]');
|
|
163
182
|
}
|
|
164
183
|
for (const id of profileIds) {
|
|
165
184
|
let profile = this.profiles.get(id);
|
|
@@ -184,7 +203,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
184
203
|
}
|
|
185
204
|
catch (err) {
|
|
186
205
|
if (err.status === 404) {
|
|
187
|
-
throw
|
|
206
|
+
throw kerror.get('security', 'profile', 'not_found', id);
|
|
188
207
|
}
|
|
189
208
|
throw err;
|
|
190
209
|
}
|
|
@@ -283,7 +302,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
283
302
|
*/
|
|
284
303
|
async delete(profile, { refresh = 'false', onAssignedUsers = 'fail', userId = '-1', } = {}) {
|
|
285
304
|
if (['admin', 'default', 'anonymous'].includes(profile._id)) {
|
|
286
|
-
throw
|
|
305
|
+
throw kerror.get('security', 'profile', 'cannot_delete');
|
|
287
306
|
}
|
|
288
307
|
const query = {
|
|
289
308
|
terms: {
|
|
@@ -316,7 +335,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
316
335
|
else {
|
|
317
336
|
const hits = await this.module.user.search({ query }, { from: 0, size: 1 });
|
|
318
337
|
if (hits.total > 0) {
|
|
319
|
-
throw
|
|
338
|
+
throw kerror.get('security', 'profile', 'in_use');
|
|
320
339
|
}
|
|
321
340
|
}
|
|
322
341
|
await this.deleteFromDatabase(profile._id, { refresh });
|
|
@@ -353,7 +372,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
353
372
|
await profile.validateDefinition({ strict });
|
|
354
373
|
if (profile._id === 'anonymous'
|
|
355
374
|
&& policiesRoles.indexOf('anonymous') === -1) {
|
|
356
|
-
throw
|
|
375
|
+
throw kerror.get('security', 'profile', 'missing_anonymous_role');
|
|
357
376
|
}
|
|
358
377
|
profile.optimizedPolicies = undefined; // Remove optimized policies
|
|
359
378
|
await super.persistToDatabase(profile, { method, refresh, retryOnConflict });
|
|
@@ -380,7 +399,7 @@ class ProfileRepository extends repository_1.default {
|
|
|
380
399
|
const roles = await this.module.role.loadRoles(policiesRoles);
|
|
381
400
|
// Fail if not all roles are found
|
|
382
401
|
if (roles.some(r => r === null)) {
|
|
383
|
-
throw
|
|
402
|
+
throw kerror.get('security', 'profile', 'cannot_hydrate');
|
|
384
403
|
}
|
|
385
404
|
return profile;
|
|
386
405
|
}
|
|
@@ -19,6 +19,25 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
22
41
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
43
|
};
|
|
@@ -27,9 +46,9 @@ exports.EmbeddedSDK = void 0;
|
|
|
27
46
|
const kuzzle_sdk_1 = require("kuzzle-sdk");
|
|
28
47
|
const funnelProtocol_1 = __importDefault(require("./funnelProtocol"));
|
|
29
48
|
const safeObject_1 = require("../../../util/safeObject");
|
|
30
|
-
const
|
|
49
|
+
const kerror = __importStar(require("../../../kerror"));
|
|
31
50
|
const impersonatedSdk_1 = __importDefault(require("./impersonatedSdk"));
|
|
32
|
-
const contextError =
|
|
51
|
+
const contextError = kerror.wrap('plugin', 'context');
|
|
33
52
|
/**
|
|
34
53
|
* Kuzzle embedded SDK to make API calls inside applications or plugins.
|
|
35
54
|
*/
|
|
@@ -19,13 +19,29 @@
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
24
40
|
};
|
|
25
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
42
|
exports.IndexCache = void 0;
|
|
27
|
-
const
|
|
28
|
-
const storageError =
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
44
|
+
const storageError = kerror.wrap('services', 'storage');
|
|
29
45
|
class IndexCache {
|
|
30
46
|
constructor() {
|
|
31
47
|
/**
|
|
@@ -97,8 +97,8 @@ function checkErrors (subdomain, domain, options) {
|
|
|
97
97
|
function checkSubdomains (domain, options) {
|
|
98
98
|
const subdomainCodes = new Set();
|
|
99
99
|
|
|
100
|
-
for (const subdomainName of Object.keys(domain.
|
|
101
|
-
const subdomain = domain.
|
|
100
|
+
for (const subdomainName of Object.keys(domain.subDomains)) {
|
|
101
|
+
const subdomain = domain.subDomains[subdomainName];
|
|
102
102
|
|
|
103
103
|
// Subdomain code for plugins is not required and is automatically set to 0
|
|
104
104
|
if (! options.plugin) {
|
|
@@ -158,11 +158,11 @@ function checkDomains (errorCodesFiles, options = { plugin: false }) {
|
|
|
158
158
|
domainCodes.add(domain.code);
|
|
159
159
|
|
|
160
160
|
assert(
|
|
161
|
-
has(domain, '
|
|
162
|
-
`Error configuration file : Missing required '
|
|
161
|
+
has(domain, 'subDomains'),
|
|
162
|
+
`Error configuration file : Missing required 'subDomains' field. (domain: '${domainName}').`);
|
|
163
163
|
assert(
|
|
164
|
-
isPlainObject(domain.
|
|
165
|
-
`Error configuration file : Field '
|
|
164
|
+
isPlainObject(domain.subDomains),
|
|
165
|
+
`Error configuration file : Field 'subDomains' must be an object. (domain: '${domainName}').`);
|
|
166
166
|
|
|
167
167
|
checkSubdomains(domain, options);
|
|
168
168
|
}
|
|
@@ -170,7 +170,7 @@ function checkDomains (errorCodesFiles, options = { plugin: false }) {
|
|
|
170
170
|
|
|
171
171
|
function loadPluginsErrors (pluginManifest, pluginCode) {
|
|
172
172
|
// @todo this should be in its own, independant domain
|
|
173
|
-
domains.plugin.
|
|
173
|
+
domains.plugin.subDomains[pluginManifest.name] = {
|
|
174
174
|
code: pluginCode,
|
|
175
175
|
errors: pluginManifest.errors
|
|
176
176
|
};
|
|
@@ -2,6 +2,6 @@ import { KuzzleError } from './kuzzleError';
|
|
|
2
2
|
export declare class MultipleErrorsError extends KuzzleError {
|
|
3
3
|
errors: Array<KuzzleError>;
|
|
4
4
|
count: number;
|
|
5
|
-
constructor(message: string,
|
|
5
|
+
constructor(message: string, errors?: KuzzleError[], id?: string, code?: number);
|
|
6
6
|
toJSON(): import("kuzzle-sdk").JSONObject;
|
|
7
7
|
}
|
|
@@ -23,10 +23,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
exports.MultipleErrorsError = void 0;
|
|
24
24
|
const kuzzleError_1 = require("./kuzzleError");
|
|
25
25
|
class MultipleErrorsError extends kuzzleError_1.KuzzleError {
|
|
26
|
-
constructor(message,
|
|
26
|
+
constructor(message, errors = [], id, code) {
|
|
27
27
|
super(message, 400, id, code);
|
|
28
|
-
this.errors =
|
|
29
|
-
this.count =
|
|
28
|
+
this.errors = errors;
|
|
29
|
+
this.count = errors.length;
|
|
30
30
|
}
|
|
31
31
|
toJSON() {
|
|
32
32
|
const serialized = super.toJSON();
|