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
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as errors from './errors';
|
|
2
|
+
import { KuzzleError } from './errors';
|
|
3
|
+
import { ErrorDomains } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Construct and return the corresponding error
|
|
6
|
+
*
|
|
7
|
+
* @param domains - Domains object with subDomains and error names
|
|
8
|
+
* @param domain - Domain (eg: 'external')
|
|
9
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
10
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
11
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
12
|
+
* @param options - Last param can be additional options { message }
|
|
13
|
+
*/
|
|
14
|
+
export declare function rawGet(domains: ErrorDomains, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
|
|
15
|
+
/**
|
|
16
|
+
* Returns a promise rejected with the corresponding error
|
|
17
|
+
*
|
|
18
|
+
* @param domains - Domains object with subDomains and error names
|
|
19
|
+
* @param domain - Domain (eg: 'external')
|
|
20
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
21
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
22
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
23
|
+
*/
|
|
24
|
+
export declare function rawReject(domains: ErrorDomains, domain: string, subdomain: string, error: string, ...placeholders: any[]): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Construct and return the corresponding error, with its stack
|
|
27
|
+
* trace derivated from a provided source error
|
|
28
|
+
*
|
|
29
|
+
* @param domains - Domains object with subDomains and error names
|
|
30
|
+
* @param source - Original error
|
|
31
|
+
* @param domain - Domain (eg: 'external')
|
|
32
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
33
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
34
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
35
|
+
*/
|
|
36
|
+
export declare function rawGetFrom(domains: ErrorDomains, source: Error, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
|
|
37
|
+
/**
|
|
38
|
+
* Wrap error functions with the provided domain and subdomain.
|
|
39
|
+
*/
|
|
40
|
+
export declare function rawWrap(domains: ErrorDomains, domain: string, subdomain: string): {
|
|
41
|
+
get: (error: any, ...placeholders: any[]) => errors.KuzzleError;
|
|
42
|
+
getFrom: (source: any, error: any, ...placeholders: any[]) => errors.KuzzleError;
|
|
43
|
+
reject: (error: any, ...placeholders: any[]) => Promise<any>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Construct and return the corresponding error
|
|
47
|
+
*
|
|
48
|
+
* @param domain - Domain (eg: 'external')
|
|
49
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
50
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
51
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
52
|
+
* @param options - Last param can be additional options { message }
|
|
53
|
+
*/
|
|
54
|
+
export declare function get(domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
|
|
55
|
+
/**
|
|
56
|
+
* Returns a promise rejected with the corresponding error
|
|
57
|
+
*
|
|
58
|
+
* @param domain - Domain (eg: 'external')
|
|
59
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
60
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
61
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
62
|
+
*/
|
|
63
|
+
export declare function reject(domain: string, subdomain: string, error: string, ...placeholders: any[]): Promise<any>;
|
|
64
|
+
/**
|
|
65
|
+
* Construct and return the corresponding error, with its stack
|
|
66
|
+
* trace derivated from a provided source error
|
|
67
|
+
*
|
|
68
|
+
* @param source - Original error
|
|
69
|
+
* @param domain - Domain (eg: 'external')
|
|
70
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
71
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
72
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
73
|
+
*/
|
|
74
|
+
export declare function getFrom(source: Error, domain: string, subdomain: string, error: string, ...placeholders: any[]): KuzzleError;
|
|
75
|
+
/**
|
|
76
|
+
* Wrap error functions with the provided domain and subdomain.
|
|
77
|
+
*/
|
|
78
|
+
export declare function wrap(domain: string, subdomain: string): {
|
|
79
|
+
get: (error: any, ...placeholders: any[]) => errors.KuzzleError;
|
|
80
|
+
getFrom: (source: any, error: any, ...placeholders: any[]) => errors.KuzzleError;
|
|
81
|
+
reject: (error: any, ...placeholders: any[]) => Promise<any>;
|
|
82
|
+
};
|
package/lib/kerror/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*
|
|
2
3
|
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
4
|
* to power modern apps
|
|
@@ -18,83 +19,93 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
};
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.wrap = exports.getFrom = exports.reject = exports.get = exports.rawWrap = exports.rawGetFrom = exports.rawReject = exports.rawGet = void 0;
|
|
46
|
+
const util_1 = require("util");
|
|
47
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
48
|
+
const codes_1 = require("./codes");
|
|
49
|
+
const errors = __importStar(require("./errors"));
|
|
50
|
+
const stackTrace_1 = require("../util/stackTrace");
|
|
33
51
|
/**
|
|
34
52
|
* Gets this file name in the exact same format than the one printed in the
|
|
35
53
|
* stacktraces (used to clean kerror lines from stacktraces)
|
|
36
54
|
*/
|
|
37
55
|
let _currentFileName = null;
|
|
38
|
-
function _getCurrentFileName
|
|
39
|
-
|
|
56
|
+
function _getCurrentFileName() {
|
|
57
|
+
if (_currentFileName !== null) {
|
|
58
|
+
return _currentFileName;
|
|
59
|
+
}
|
|
60
|
+
_currentFileName = module.filename.substr(process.cwd().length + 1);
|
|
40
61
|
return _currentFileName;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_currentFileName = module.filename.substr(process.cwd().length + 1);
|
|
44
|
-
|
|
45
|
-
return _currentFileName;
|
|
46
62
|
}
|
|
47
|
-
|
|
48
63
|
/**
|
|
49
64
|
* Construct and return the corresponding error
|
|
50
65
|
*
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
66
|
+
* @param domains - Domains object with subDomains and error names
|
|
67
|
+
* @param domain - Domain (eg: 'external')
|
|
68
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
69
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
70
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
71
|
+
* @param options - Last param can be additional options { message }
|
|
56
72
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (error.name !== 'InternalError') {
|
|
92
|
-
cleanStackTrace(kerror);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return kerror;
|
|
73
|
+
function rawGet(domains, domain, subdomain, error, ...placeholders) {
|
|
74
|
+
let options = {};
|
|
75
|
+
// extract options object from the placeholders
|
|
76
|
+
if (lodash_1.default.isPlainObject(placeholders[placeholders.length - 1])) {
|
|
77
|
+
options = placeholders.pop();
|
|
78
|
+
}
|
|
79
|
+
const kuzzleError = lodash_1.default.get(domains, `${domain}.subDomains.${subdomain}.errors.${error}`);
|
|
80
|
+
if (!kuzzleError) {
|
|
81
|
+
return get('core', 'fatal', 'unexpected_error', `${domain}.${subdomain}.${error}`);
|
|
82
|
+
}
|
|
83
|
+
let body = null;
|
|
84
|
+
if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
|
|
85
|
+
body = placeholders.splice(-1)[0];
|
|
86
|
+
}
|
|
87
|
+
const message = options.message || (0, util_1.format)(kuzzleError.message, ...placeholders);
|
|
88
|
+
const id = `${domain}.${subdomain}.${error}`;
|
|
89
|
+
const code = domains[domain].code << 24
|
|
90
|
+
| domains[domain].subDomains[subdomain].code << 16
|
|
91
|
+
| domains[domain].subDomains[subdomain].errors[error].code;
|
|
92
|
+
let kerror;
|
|
93
|
+
if (kuzzleError.class === 'PartialError' || kuzzleError.class === 'MultipleErrorsError') {
|
|
94
|
+
kerror = new errors[kuzzleError.class](message, body, id, code);
|
|
95
|
+
}
|
|
96
|
+
else if (kuzzleError.class === 'KuzzleError') {
|
|
97
|
+
const status = kuzzleError.status || 500;
|
|
98
|
+
kerror = new errors.KuzzleError(message, status, id, code);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
kerror = new errors[kuzzleError.class](message, id, code);
|
|
102
|
+
}
|
|
103
|
+
if (kuzzleError.class !== 'InternalError') {
|
|
104
|
+
cleanStackTrace(kerror);
|
|
105
|
+
}
|
|
106
|
+
return kerror;
|
|
96
107
|
}
|
|
97
|
-
|
|
108
|
+
exports.rawGet = rawGet;
|
|
98
109
|
/**
|
|
99
110
|
* Removes the first lines of the stacktrace because they are related
|
|
100
111
|
* to internal mechanisms.
|
|
@@ -106,98 +117,124 @@ function get (domain, subdomain, error, ...placeholders) {
|
|
|
106
117
|
* // Line that triggered the error =>
|
|
107
118
|
* at ControllerManager.add (kuzzle/lib/core/backend/backend.ts:226:34)
|
|
108
119
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// filter all lines related to the kerror object
|
|
125
|
-
return ! line.includes(currentFileName);
|
|
120
|
+
function cleanStackTrace(error) {
|
|
121
|
+
// Keep the original error message
|
|
122
|
+
const messageLength = error.message.split('\n').length;
|
|
123
|
+
const currentFileName = _getCurrentFileName();
|
|
124
|
+
// we keep the new error instantiation line ("new ...Error (") on purpose:
|
|
125
|
+
// this will allow us to replace it without inserting a new line in the array,
|
|
126
|
+
// saving us from building a new array
|
|
127
|
+
const newStack = error.stack.split('\n')
|
|
128
|
+
.filter((line, index) => {
|
|
129
|
+
if (index < messageLength) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
// filter all lines related to the kerror object
|
|
133
|
+
return !line.includes(currentFileName);
|
|
126
134
|
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
error.stack = newStack.join('\n');
|
|
135
|
+
.map(stackTrace_1.hilightUserCode);
|
|
136
|
+
// insert a deletion message in place of the new error instantiation line
|
|
137
|
+
newStack[messageLength] = ' [...Kuzzle internal calls deleted...]';
|
|
138
|
+
error.stack = newStack.join('\n');
|
|
133
139
|
}
|
|
134
|
-
|
|
135
140
|
/**
|
|
136
141
|
* Returns a promise rejected with the corresponding error
|
|
137
142
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param
|
|
143
|
+
* @param domains - Domains object with subDomains and error names
|
|
144
|
+
* @param domain - Domain (eg: 'external')
|
|
145
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
146
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
147
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
142
148
|
*/
|
|
143
|
-
function
|
|
144
|
-
|
|
149
|
+
function rawReject(domains, domain, subdomain, error, ...placeholders) {
|
|
150
|
+
return Promise.reject(rawGet(domains, domain, subdomain, error, ...placeholders));
|
|
145
151
|
}
|
|
146
|
-
|
|
152
|
+
exports.rawReject = rawReject;
|
|
147
153
|
/**
|
|
148
154
|
* Construct and return the corresponding error, with its stack
|
|
149
155
|
* trace derivated from a provided source error
|
|
150
156
|
*
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
157
|
+
* @param domains - Domains object with subDomains and error names
|
|
158
|
+
* @param source - Original error
|
|
159
|
+
* @param domain - Domain (eg: 'external')
|
|
160
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
161
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
162
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
156
163
|
*/
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return derivedError;
|
|
164
|
+
function rawGetFrom(domains, source, domain, subdomain, error, ...placeholders) {
|
|
165
|
+
const derivedError = rawGet(domains, domain, subdomain, error, ...placeholders);
|
|
166
|
+
// If a stacktrace is present, we need to modify the first line because it
|
|
167
|
+
// still contains the original error message
|
|
168
|
+
if (derivedError.stack && derivedError.stack.length) {
|
|
169
|
+
const stackArray = source.stack.split('\n');
|
|
170
|
+
stackArray.shift();
|
|
171
|
+
derivedError.stack = [
|
|
172
|
+
`${derivedError.constructor.name}: ${derivedError.message}`,
|
|
173
|
+
...stackArray
|
|
174
|
+
].join('\n');
|
|
175
|
+
}
|
|
176
|
+
return derivedError;
|
|
172
177
|
}
|
|
173
|
-
|
|
178
|
+
exports.rawGetFrom = rawGetFrom;
|
|
174
179
|
/**
|
|
175
180
|
* Wrap error functions with the provided domain and subdomain.
|
|
176
181
|
*/
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
...placeholders),
|
|
184
|
-
getFrom: (source, error, ...placeholders) => getFrom(
|
|
185
|
-
source,
|
|
186
|
-
domain,
|
|
187
|
-
subdomain,
|
|
188
|
-
error,
|
|
189
|
-
...placeholders),
|
|
190
|
-
reject: (error, ...placeholders) => reject(
|
|
191
|
-
domain,
|
|
192
|
-
subdomain,
|
|
193
|
-
error,
|
|
194
|
-
...placeholders),
|
|
195
|
-
};
|
|
182
|
+
function rawWrap(domains, domain, subdomain) {
|
|
183
|
+
return {
|
|
184
|
+
get: (error, ...placeholders) => rawGet(domains, domain, subdomain, error, ...placeholders),
|
|
185
|
+
getFrom: (source, error, ...placeholders) => rawGetFrom(domains, source, domain, subdomain, error, ...placeholders),
|
|
186
|
+
reject: (error, ...placeholders) => rawReject(domains, domain, subdomain, error, ...placeholders),
|
|
187
|
+
};
|
|
196
188
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
189
|
+
exports.rawWrap = rawWrap;
|
|
190
|
+
/**
|
|
191
|
+
* Construct and return the corresponding error
|
|
192
|
+
*
|
|
193
|
+
* @param domain - Domain (eg: 'external')
|
|
194
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
195
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
196
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
197
|
+
* @param options - Last param can be additional options { message }
|
|
198
|
+
*/
|
|
199
|
+
function get(domain, subdomain, error, ...placeholders) {
|
|
200
|
+
return rawGet(codes_1.domains, domain, subdomain, error, ...placeholders);
|
|
201
|
+
}
|
|
202
|
+
exports.get = get;
|
|
203
|
+
/**
|
|
204
|
+
* Returns a promise rejected with the corresponding error
|
|
205
|
+
*
|
|
206
|
+
* @param domain - Domain (eg: 'external')
|
|
207
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
208
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
209
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
210
|
+
*/
|
|
211
|
+
function reject(domain, subdomain, error, ...placeholders) {
|
|
212
|
+
return rawReject(codes_1.domains, domain, subdomain, error, ...placeholders);
|
|
213
|
+
}
|
|
214
|
+
exports.reject = reject;
|
|
215
|
+
/**
|
|
216
|
+
* Construct and return the corresponding error, with its stack
|
|
217
|
+
* trace derivated from a provided source error
|
|
218
|
+
*
|
|
219
|
+
* @param source - Original error
|
|
220
|
+
* @param domain - Domain (eg: 'external')
|
|
221
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
222
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
223
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
224
|
+
*/
|
|
225
|
+
function getFrom(source, domain, subdomain, error, ...placeholders) {
|
|
226
|
+
return rawGetFrom(codes_1.domains, source, domain, subdomain, error, ...placeholders);
|
|
227
|
+
}
|
|
228
|
+
exports.getFrom = getFrom;
|
|
229
|
+
/**
|
|
230
|
+
* Wrap error functions with the provided domain and subdomain.
|
|
231
|
+
*/
|
|
232
|
+
function wrap(domain, subdomain) {
|
|
233
|
+
return {
|
|
234
|
+
get: (error, ...placeholders) => get(domain, subdomain, error, ...placeholders),
|
|
235
|
+
getFrom: (source, error, ...placeholders) => getFrom(source, domain, subdomain, error, ...placeholders),
|
|
236
|
+
reject: (error, ...placeholders) => reject(domain, subdomain, error, ...placeholders),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
exports.wrap = wrap;
|
|
240
|
+
//# sourceMappingURL=index.js.map
|
package/lib/kuzzle/kuzzle.js
CHANGED
|
@@ -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
|
};
|
|
@@ -45,7 +64,7 @@ const vault_1 = __importDefault(require("./vault"));
|
|
|
45
64
|
const dumpGenerator_1 = __importDefault(require("./dumpGenerator"));
|
|
46
65
|
const asyncStore_1 = __importDefault(require("../util/asyncStore"));
|
|
47
66
|
const mutex_1 = require("../util/mutex");
|
|
48
|
-
const
|
|
67
|
+
const kerror = __importStar(require("../kerror"));
|
|
49
68
|
const internalIndexHandler_1 = __importDefault(require("./internalIndexHandler"));
|
|
50
69
|
const cacheEngine_1 = __importDefault(require("../core/cache/cacheEngine"));
|
|
51
70
|
const storageEngine_1 = __importDefault(require("../core/storage/storageEngine"));
|
|
@@ -224,7 +243,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
224
243
|
await installation.handler();
|
|
225
244
|
}
|
|
226
245
|
catch (error) {
|
|
227
|
-
throw
|
|
246
|
+
throw kerror.get('plugin', 'runtime', 'unexpected_installation_error', installation.id, error);
|
|
228
247
|
}
|
|
229
248
|
await this.ask('core:storage:private:document:create', 'kuzzle', 'installations', {
|
|
230
249
|
description: installation.description,
|
|
@@ -266,7 +285,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
266
285
|
const toImport = config.toImport;
|
|
267
286
|
const toSupport = config.toSupport;
|
|
268
287
|
if (!lodash_1.default.isEmpty(toSupport.mappings) && !lodash_1.default.isEmpty(toImport.mappings)) {
|
|
269
|
-
throw
|
|
288
|
+
throw kerror.get('plugin', 'runtime', 'incompatible', '_support.mappings', 'import.mappings');
|
|
270
289
|
}
|
|
271
290
|
else if (!lodash_1.default.isEmpty(toSupport.mappings)) {
|
|
272
291
|
await this.ask('core:storage:public:mappings:import', toSupport.mappings, {
|
|
@@ -318,7 +337,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
318
337
|
&& lodash_1.default.isEmpty(toSupport.securities.roles)
|
|
319
338
|
&& lodash_1.default.isEmpty(toSupport.securities.users));
|
|
320
339
|
if (isPermissionsToSupport && isPermissionsToImport) {
|
|
321
|
-
throw
|
|
340
|
+
throw kerror.get('plugin', 'runtime', 'incompatible', '_support.securities', 'import profiles roles or users');
|
|
322
341
|
}
|
|
323
342
|
else if (isPermissionsToSupport) {
|
|
324
343
|
await this.ask('core:security:load', toSupport.securities, {
|
|
@@ -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.Profile = void 0;
|
|
|
27
46
|
const lodash_1 = __importDefault(require("lodash"));
|
|
28
47
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
29
48
|
const rights_1 = __importDefault(require("./rights"));
|
|
30
|
-
const
|
|
49
|
+
const kerror = __importStar(require("../../kerror"));
|
|
31
50
|
const safeObject_1 = require("../../util/safeObject");
|
|
32
|
-
const assertionError =
|
|
51
|
+
const assertionError = kerror.wrap('api', 'assert');
|
|
33
52
|
/**
|
|
34
53
|
* @class Profile
|
|
35
54
|
*/
|
|
@@ -47,7 +66,7 @@ class Profile {
|
|
|
47
66
|
*/
|
|
48
67
|
async getPolicies() {
|
|
49
68
|
if (!global.kuzzle) {
|
|
50
|
-
throw
|
|
69
|
+
throw kerror.get('security', 'profile', 'uninitialized', this._id);
|
|
51
70
|
}
|
|
52
71
|
return bluebird_1.default.map(this.optimizedPolicies, async ({ restrictedTo, roleId }) => {
|
|
53
72
|
const role = await global.kuzzle.ask('core:security:role:get', roleId);
|
|
@@ -121,7 +140,7 @@ class Profile {
|
|
|
121
140
|
if (strict) {
|
|
122
141
|
const indexExists = await global.kuzzle.ask('core:storage:public:index:exist', restriction.index);
|
|
123
142
|
if (!indexExists) {
|
|
124
|
-
throw
|
|
143
|
+
throw kerror.get('services', 'storage', 'unknown_index', restriction.index);
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
146
|
if (restriction.collections !== undefined
|
|
@@ -138,7 +157,7 @@ class Profile {
|
|
|
138
157
|
}
|
|
139
158
|
}
|
|
140
159
|
if (invalidCollections.length > 0) {
|
|
141
|
-
throw
|
|
160
|
+
throw kerror.get('services', 'storage', 'unknown_collection', restriction.index, invalidCollections);
|
|
142
161
|
}
|
|
143
162
|
}
|
|
144
163
|
}
|
|
@@ -19,15 +19,31 @@
|
|
|
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.Role = void 0;
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
28
44
|
const safeObject_1 = require("../../util/safeObject");
|
|
29
45
|
const array_1 = require("../../util/array");
|
|
30
|
-
const assertionError =
|
|
46
|
+
const assertionError = kerror.wrap('api', 'assert');
|
|
31
47
|
/**
|
|
32
48
|
* @class Role
|
|
33
49
|
*/
|
|
@@ -41,7 +57,7 @@ class Role {
|
|
|
41
57
|
*/
|
|
42
58
|
isActionAllowed(request) {
|
|
43
59
|
if (!global.kuzzle) {
|
|
44
|
-
throw
|
|
60
|
+
throw kerror.get('security', 'role', 'uninitialized', this._id);
|
|
45
61
|
}
|
|
46
62
|
if (this.controllers === undefined || this.controllers === null) {
|
|
47
63
|
return false;
|