kuzzle 2.17.0 → 2.17.1
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/request/kuzzleRequest.js +5 -7
- 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/httpwsProtocol.js +15 -2
- 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/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 +176 -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 +27 -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
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,89 @@
|
|
|
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
|
-
else {
|
|
88
|
-
kerror = new errors[kuzzleError.class](message, id, code);
|
|
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 {
|
|
97
|
+
kerror = new errors[kuzzleError.class](message, id, code);
|
|
98
|
+
}
|
|
99
|
+
if (kuzzleError.class !== 'InternalError') {
|
|
100
|
+
cleanStackTrace(kerror);
|
|
101
|
+
}
|
|
102
|
+
return kerror;
|
|
96
103
|
}
|
|
97
|
-
|
|
104
|
+
exports.rawGet = rawGet;
|
|
98
105
|
/**
|
|
99
106
|
* Removes the first lines of the stacktrace because they are related
|
|
100
107
|
* to internal mechanisms.
|
|
@@ -106,98 +113,124 @@ function get (domain, subdomain, error, ...placeholders) {
|
|
|
106
113
|
* // Line that triggered the error =>
|
|
107
114
|
* at ControllerManager.add (kuzzle/lib/core/backend/backend.ts:226:34)
|
|
108
115
|
*/
|
|
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);
|
|
116
|
+
function cleanStackTrace(error) {
|
|
117
|
+
// Keep the original error message
|
|
118
|
+
const messageLength = error.message.split('\n').length;
|
|
119
|
+
const currentFileName = _getCurrentFileName();
|
|
120
|
+
// we keep the new error instantiation line ("new ...Error (") on purpose:
|
|
121
|
+
// this will allow us to replace it without inserting a new line in the array,
|
|
122
|
+
// saving us from building a new array
|
|
123
|
+
const newStack = error.stack.split('\n')
|
|
124
|
+
.filter((line, index) => {
|
|
125
|
+
if (index < messageLength) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
// filter all lines related to the kerror object
|
|
129
|
+
return !line.includes(currentFileName);
|
|
126
130
|
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
error.stack = newStack.join('\n');
|
|
131
|
+
.map(stackTrace_1.hilightUserCode);
|
|
132
|
+
// insert a deletion message in place of the new error instantiation line
|
|
133
|
+
newStack[messageLength] = ' [...Kuzzle internal calls deleted...]';
|
|
134
|
+
error.stack = newStack.join('\n');
|
|
133
135
|
}
|
|
134
|
-
|
|
135
136
|
/**
|
|
136
137
|
* Returns a promise rejected with the corresponding error
|
|
137
138
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param
|
|
139
|
+
* @param domains - Domains object with subdomains and error names
|
|
140
|
+
* @param domain - Domain (eg: 'external')
|
|
141
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
142
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
143
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
142
144
|
*/
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
+
function rawReject(domains, domain, subdomain, error, ...placeholders) {
|
|
146
|
+
return Promise.reject(rawGet(domains, domain, subdomain, error, ...placeholders));
|
|
145
147
|
}
|
|
146
|
-
|
|
148
|
+
exports.rawReject = rawReject;
|
|
147
149
|
/**
|
|
148
150
|
* Construct and return the corresponding error, with its stack
|
|
149
151
|
* trace derivated from a provided source error
|
|
150
152
|
*
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
155
|
-
* @param
|
|
153
|
+
* @param domains - Domains object with subdomains and error names
|
|
154
|
+
* @param source - Original error
|
|
155
|
+
* @param domain - Domain (eg: 'external')
|
|
156
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
157
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
158
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
156
159
|
*/
|
|
157
|
-
function
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return derivedError;
|
|
160
|
+
function rawGetFrom(domains, source, domain, subdomain, error, ...placeholders) {
|
|
161
|
+
const derivedError = rawGet(domains, domain, subdomain, error, ...placeholders);
|
|
162
|
+
// If a stacktrace is present, we need to modify the first line because it
|
|
163
|
+
// still contains the original error message
|
|
164
|
+
if (derivedError.stack && derivedError.stack.length) {
|
|
165
|
+
const stackArray = source.stack.split('\n');
|
|
166
|
+
stackArray.shift();
|
|
167
|
+
derivedError.stack = [
|
|
168
|
+
`${derivedError.constructor.name}: ${derivedError.message}`,
|
|
169
|
+
...stackArray
|
|
170
|
+
].join('\n');
|
|
171
|
+
}
|
|
172
|
+
return derivedError;
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
+
exports.rawGetFrom = rawGetFrom;
|
|
174
175
|
/**
|
|
175
176
|
* Wrap error functions with the provided domain and subdomain.
|
|
176
177
|
*/
|
|
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
|
-
};
|
|
178
|
+
function rawWrap(domains, domain, subdomain) {
|
|
179
|
+
return {
|
|
180
|
+
get: (error, ...placeholders) => rawGet(domains, domain, subdomain, error, ...placeholders),
|
|
181
|
+
getFrom: (source, error, ...placeholders) => rawGetFrom(domains, source, domain, subdomain, error, ...placeholders),
|
|
182
|
+
reject: (error, ...placeholders) => rawReject(domains, domain, subdomain, error, ...placeholders),
|
|
183
|
+
};
|
|
196
184
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
185
|
+
exports.rawWrap = rawWrap;
|
|
186
|
+
/**
|
|
187
|
+
* Construct and return the corresponding error
|
|
188
|
+
*
|
|
189
|
+
* @param domain - Domain (eg: 'external')
|
|
190
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
191
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
192
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
193
|
+
* @param options - Last param can be additional options { message }
|
|
194
|
+
*/
|
|
195
|
+
function get(domain, subdomain, error, ...placeholders) {
|
|
196
|
+
return rawGet(codes_1.domains, domain, subdomain, error, ...placeholders);
|
|
197
|
+
}
|
|
198
|
+
exports.get = get;
|
|
199
|
+
/**
|
|
200
|
+
* Returns a promise rejected with the corresponding error
|
|
201
|
+
*
|
|
202
|
+
* @param domain - Domain (eg: 'external')
|
|
203
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
204
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
205
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
206
|
+
*/
|
|
207
|
+
function reject(domain, subdomain, error, ...placeholders) {
|
|
208
|
+
return rawReject(codes_1.domains, domain, subdomain, error, ...placeholders);
|
|
209
|
+
}
|
|
210
|
+
exports.reject = reject;
|
|
211
|
+
/**
|
|
212
|
+
* Construct and return the corresponding error, with its stack
|
|
213
|
+
* trace derivated from a provided source error
|
|
214
|
+
*
|
|
215
|
+
* @param source - Original error
|
|
216
|
+
* @param domain - Domain (eg: 'external')
|
|
217
|
+
* @param subdomain - Subdomain (eg: 'elasticsearch')
|
|
218
|
+
* @param error - Error name: (eg: 'index_not_found')
|
|
219
|
+
* @param placeholders - Placeholders value to inject in error message
|
|
220
|
+
*/
|
|
221
|
+
function getFrom(source, domain, subdomain, error, ...placeholders) {
|
|
222
|
+
return rawGetFrom(codes_1.domains, source, domain, subdomain, error, ...placeholders);
|
|
223
|
+
}
|
|
224
|
+
exports.getFrom = getFrom;
|
|
225
|
+
/**
|
|
226
|
+
* Wrap error functions with the provided domain and subdomain.
|
|
227
|
+
*/
|
|
228
|
+
function wrap(domain, subdomain) {
|
|
229
|
+
return {
|
|
230
|
+
get: (error, ...placeholders) => get(domain, subdomain, error, ...placeholders),
|
|
231
|
+
getFrom: (source, error, ...placeholders) => getFrom(source, domain, subdomain, error, ...placeholders),
|
|
232
|
+
reject: (error, ...placeholders) => reject(domain, subdomain, error, ...placeholders),
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
exports.wrap = wrap;
|
|
236
|
+
//# 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;
|
|
@@ -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,7 +46,7 @@ exports.User = void 0;
|
|
|
27
46
|
const rights_1 = __importDefault(require("./rights"));
|
|
28
47
|
const bluebird_1 = __importDefault(require("bluebird"));
|
|
29
48
|
const lodash_1 = __importDefault(require("lodash"));
|
|
30
|
-
const
|
|
49
|
+
const kerror = __importStar(require("../../kerror"));
|
|
31
50
|
/**
|
|
32
51
|
* @class User
|
|
33
52
|
*/
|
|
@@ -41,7 +60,7 @@ class User {
|
|
|
41
60
|
*/
|
|
42
61
|
getProfiles() {
|
|
43
62
|
if (!global.kuzzle) {
|
|
44
|
-
return
|
|
63
|
+
return kerror.reject('security', 'user', 'uninitialized', this._id);
|
|
45
64
|
}
|
|
46
65
|
return global.kuzzle.ask('core:security:profile:mGet', this.profileIds);
|
|
47
66
|
}
|
package/lib/types/Plugin.js
CHANGED
|
@@ -19,12 +19,28 @@
|
|
|
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.Plugin = void 0;
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../kerror"));
|
|
28
44
|
const safeObject_1 = require("../util/safeObject");
|
|
29
45
|
/**
|
|
30
46
|
* Plugins must implements this abstract class.
|
|
@@ -36,7 +52,7 @@ class Plugin {
|
|
|
36
52
|
constructor(manifest) {
|
|
37
53
|
if (!(0, safeObject_1.has)(manifest, 'kuzzleVersion')) {
|
|
38
54
|
// eslint-disable-next-line new-cap
|
|
39
|
-
throw
|
|
55
|
+
throw kerror.get('plugin', 'manifest', 'missing_version');
|
|
40
56
|
}
|
|
41
57
|
this._manifest = manifest;
|
|
42
58
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Available error class
|
|
3
|
+
*/
|
|
4
|
+
export declare type ErrorClassNames = 'BadRequestError' | 'ExternalServiceError' | 'ForbiddenError' | 'GatewayTimeoutError' | 'InternalError' | 'KuzzleError' | 'MultipleErrorsError' | 'NotFoundError' | 'PartialError' | 'PluginImplementationError' | 'ServiceUnavailableError' | 'SizeLimitError' | 'UnauthorizedError' | 'PreconditionError' | 'TooManyRequestsError';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a standardized error definition
|
|
7
|
+
*/
|
|
8
|
+
export declare type ErrorDefinition = CustomErrorDefinition & {
|
|
9
|
+
code: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Represents a custom standardized error definition
|
|
13
|
+
*/
|
|
14
|
+
export declare type CustomErrorDefinition = {
|
|
15
|
+
/**
|
|
16
|
+
* Error description for documentation purpose
|
|
17
|
+
*/
|
|
18
|
+
description: string;
|
|
19
|
+
/**
|
|
20
|
+
* Error message
|
|
21
|
+
*/
|
|
22
|
+
message: string;
|
|
23
|
+
/**
|
|
24
|
+
* Error class
|
|
25
|
+
*/
|
|
26
|
+
class: ErrorClassNames;
|
|
27
|
+
};
|