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
|
@@ -110,7 +110,7 @@ class AuthController extends NativeController {
|
|
|
110
110
|
async createApiKey (request) {
|
|
111
111
|
const expiresIn = request.input.args.expiresIn || -1;
|
|
112
112
|
const refresh = request.getRefresh('wait_for');
|
|
113
|
-
const apiKeyId = request.getId({ ifMissing: '
|
|
113
|
+
const apiKeyId = request.getId({ ifMissing: 'generate' });
|
|
114
114
|
const description = request.getBodyString('description');
|
|
115
115
|
|
|
116
116
|
const user = request.context.user;
|
|
@@ -136,7 +136,7 @@ class SecurityController extends NativeController {
|
|
|
136
136
|
const expiresIn = request.input.args.expiresIn || -1;
|
|
137
137
|
const refresh = request.getRefresh('wait_for');
|
|
138
138
|
const userId = request.getString('userId');
|
|
139
|
-
const apiKeyId = request.getId({ ifMissing: '
|
|
139
|
+
const apiKeyId = request.getId({ ifMissing: 'generate' });
|
|
140
140
|
const description = request.getBodyString('description');
|
|
141
141
|
|
|
142
142
|
const user = await this.ask('core:security:user:get', userId);
|
|
@@ -38,9 +38,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
38
38
|
__setModuleDefault(result, mod);
|
|
39
39
|
return result;
|
|
40
40
|
};
|
|
41
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
-
};
|
|
44
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
42
|
exports.Request = exports.KuzzleRequest = void 0;
|
|
46
43
|
const uuid = __importStar(require("uuid"));
|
|
@@ -49,12 +46,12 @@ const requestInput_1 = require("./requestInput");
|
|
|
49
46
|
const requestResponse_1 = require("./requestResponse");
|
|
50
47
|
const requestContext_1 = require("./requestContext");
|
|
51
48
|
const errors_1 = require("../../kerror/errors");
|
|
52
|
-
const
|
|
49
|
+
const kerror = __importStar(require("../../kerror"));
|
|
53
50
|
const types_1 = require("../../types");
|
|
54
51
|
const assert = __importStar(require("../../util/assertType"));
|
|
55
52
|
const safeObject_1 = require("../../util/safeObject");
|
|
56
53
|
const lodash_1 = require("lodash");
|
|
57
|
-
const assertionError =
|
|
54
|
+
const assertionError = kerror.wrap('api', 'assert');
|
|
58
55
|
// private properties
|
|
59
56
|
// \u200b is a zero width space, used to masquerade console.log output
|
|
60
57
|
const _internalId = 'internalId\u200b';
|
|
@@ -219,7 +216,7 @@ class KuzzleRequest {
|
|
|
219
216
|
throw new errors_1.InternalError('cannot set an error as a request\'s response');
|
|
220
217
|
}
|
|
221
218
|
if (this.context.connection.protocol !== 'http' && result instanceof types_1.HttpStream) {
|
|
222
|
-
throw
|
|
219
|
+
throw kerror.get('api', 'assert', 'forbidden_stream');
|
|
223
220
|
}
|
|
224
221
|
this.status = options.status || 200;
|
|
225
222
|
if (options.headers) {
|
|
@@ -324,7 +321,7 @@ class KuzzleRequest {
|
|
|
324
321
|
getLangParam() {
|
|
325
322
|
const lang = this.getString('lang', 'elasticsearch');
|
|
326
323
|
if (lang !== 'elasticsearch' && lang !== 'koncorde') {
|
|
327
|
-
throw
|
|
324
|
+
throw kerror.get('api', 'assert', 'invalid_argument', 'lang', '"elasticsearch" or "koncorde"');
|
|
328
325
|
}
|
|
329
326
|
return lang;
|
|
330
327
|
}
|
|
@@ -589,6 +586,7 @@ class KuzzleRequest {
|
|
|
589
586
|
*/
|
|
590
587
|
getId(options = { generator: uuid.v4, ifMissing: 'error' }) {
|
|
591
588
|
const id = this.input.args._id;
|
|
589
|
+
options.generator = options.generator || uuid.v4; // Default to uuid v4
|
|
592
590
|
if (!id) {
|
|
593
591
|
if (options.ifMissing === 'generate') {
|
|
594
592
|
return options.generator();
|
package/lib/cluster/state.js
CHANGED
|
@@ -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
|
const koncorde_1 = require("koncorde");
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../kerror"));
|
|
28
44
|
require("../types/Global");
|
|
29
45
|
const koncordeCompat_1 = require("../util/koncordeCompat");
|
|
30
|
-
const errorFatal =
|
|
46
|
+
const errorFatal = kerror.wrap('cluster', 'fatal');
|
|
31
47
|
/**
|
|
32
48
|
* Private class aiming at maintaining both the number of a node's subscriptions
|
|
33
49
|
* to a room, and the node's last message ID to detect desyncs.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EmbeddedSDK } from '../shared/sdk/embeddedSdk';
|
|
2
2
|
import { JSONObject } from '../../../index';
|
|
3
|
-
import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, BackendOpenApi, InternalLogger } from './index';
|
|
3
|
+
import { BackendCluster, BackendConfig, BackendController, BackendHook, BackendImport, BackendPipe, BackendPlugin, BackendStorage, BackendVault, BackendOpenApi, InternalLogger, BackendErrors } from './index';
|
|
4
4
|
export declare class Backend {
|
|
5
5
|
private _kuzzle;
|
|
6
6
|
private _name;
|
|
@@ -117,14 +117,18 @@ export declare class Backend {
|
|
|
117
117
|
* OpenApi manager
|
|
118
118
|
*/
|
|
119
119
|
openApi: BackendOpenApi;
|
|
120
|
+
/**
|
|
121
|
+
* Standard errors
|
|
122
|
+
*/
|
|
123
|
+
errors: BackendErrors;
|
|
120
124
|
/**
|
|
121
125
|
* @deprecated
|
|
122
126
|
*
|
|
127
|
+
* Use the app.import.xxx() feature instead.
|
|
128
|
+
*
|
|
123
129
|
* Support for old features available before Kuzzle as a framework
|
|
124
130
|
* to avoid breaking existing deployments.
|
|
125
131
|
*
|
|
126
|
-
* Do not use this property unless you know exactly what you are doing,
|
|
127
|
-
* this property can be removed in future releases.
|
|
128
132
|
*/
|
|
129
133
|
_support: JSONObject;
|
|
130
134
|
/**
|
|
@@ -46,10 +46,10 @@ exports.Backend = void 0;
|
|
|
46
46
|
const fs_1 = __importDefault(require("fs"));
|
|
47
47
|
const kuzzle_1 = __importDefault(require("../../kuzzle"));
|
|
48
48
|
const embeddedSdk_1 = require("../shared/sdk/embeddedSdk");
|
|
49
|
-
const
|
|
49
|
+
const kerror = __importStar(require("../../kerror"));
|
|
50
50
|
const index_1 = require("./index");
|
|
51
|
-
const assertionError =
|
|
52
|
-
const runtimeError =
|
|
51
|
+
const assertionError = kerror.wrap('plugin', 'assert');
|
|
52
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
53
53
|
let _app = null;
|
|
54
54
|
Reflect.defineProperty(global, 'app', {
|
|
55
55
|
configurable: true,
|
|
@@ -95,11 +95,11 @@ class Backend {
|
|
|
95
95
|
/**
|
|
96
96
|
* @deprecated
|
|
97
97
|
*
|
|
98
|
+
* Use the app.import.xxx() feature instead.
|
|
99
|
+
*
|
|
98
100
|
* Support for old features available before Kuzzle as a framework
|
|
99
101
|
* to avoid breaking existing deployments.
|
|
100
102
|
*
|
|
101
|
-
* Do not use this property unless you know exactly what you are doing,
|
|
102
|
-
* this property can be removed in future releases.
|
|
103
103
|
*/
|
|
104
104
|
this._support = {};
|
|
105
105
|
/**
|
|
@@ -146,7 +146,8 @@ class Backend {
|
|
|
146
146
|
this.log = new index_1.InternalLogger(this);
|
|
147
147
|
this.cluster = new index_1.BackendCluster();
|
|
148
148
|
this.openApi = new index_1.BackendOpenApi(this);
|
|
149
|
-
this.
|
|
149
|
+
this.errors = new index_1.BackendErrors(this);
|
|
150
|
+
this.kerror = kerror;
|
|
150
151
|
try {
|
|
151
152
|
this.commit = this._readCommit();
|
|
152
153
|
}
|
|
@@ -213,13 +214,13 @@ class Backend {
|
|
|
213
214
|
throw runtimeError.get('already_started', 'install');
|
|
214
215
|
}
|
|
215
216
|
if (typeof id !== 'string') {
|
|
216
|
-
throw
|
|
217
|
+
throw kerror.get('validation', 'assert', 'invalid_type', 'id', 'string');
|
|
217
218
|
}
|
|
218
219
|
if (typeof handler !== 'function') {
|
|
219
|
-
throw
|
|
220
|
+
throw kerror.get('validation', 'assert', 'invalid_type', 'handler', 'function');
|
|
220
221
|
}
|
|
221
222
|
if (description && typeof description !== 'string') {
|
|
222
|
-
throw
|
|
223
|
+
throw kerror.get('validation', 'assert', 'invalid_type', 'id', 'string');
|
|
223
224
|
}
|
|
224
225
|
this._installationsWaitingList.push({ description, handler, id });
|
|
225
226
|
}
|
|
@@ -19,16 +19,35 @@
|
|
|
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.BackendConfig = void 0;
|
|
27
46
|
const lodash_1 = __importDefault(require("lodash"));
|
|
28
|
-
const
|
|
47
|
+
const kerror = __importStar(require("../../kerror"));
|
|
29
48
|
const index_1 = require("./index");
|
|
30
49
|
const index_js_1 = require("../../config/index.js");
|
|
31
|
-
const runtimeError =
|
|
50
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
32
51
|
class BackendConfig extends index_1.ApplicationManager {
|
|
33
52
|
constructor(application) {
|
|
34
53
|
super(application);
|
|
@@ -19,16 +19,32 @@
|
|
|
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.BackendController = void 0;
|
|
27
43
|
const inflector_1 = require("../../util/inflector");
|
|
28
|
-
const
|
|
44
|
+
const kerror = __importStar(require("../../kerror"));
|
|
29
45
|
const index_1 = require("./index");
|
|
30
|
-
const assertionError =
|
|
31
|
-
const runtimeError =
|
|
46
|
+
const assertionError = kerror.wrap('plugin', 'assert');
|
|
47
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
32
48
|
class BackendController extends index_1.ApplicationManager {
|
|
33
49
|
/**
|
|
34
50
|
* Registers a new controller.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { KuzzleError } from '../../kerror/errors';
|
|
2
|
+
import { ApplicationManager, Backend } from './index';
|
|
3
|
+
import { CustomErrorDefinition } from '../../types';
|
|
4
|
+
export declare class BackendErrors extends ApplicationManager {
|
|
5
|
+
private domains;
|
|
6
|
+
private subDomains;
|
|
7
|
+
constructor(application: Backend);
|
|
8
|
+
/**
|
|
9
|
+
* Register a new standard KuzzleError
|
|
10
|
+
*
|
|
11
|
+
* @param subDomain Subdomain name
|
|
12
|
+
* @param name Standard error name
|
|
13
|
+
* @param definition Standard error definition
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* app.errors.register('api', 'custom', {
|
|
18
|
+
* class: 'BadRequestError',
|
|
19
|
+
* description: 'This is a custom error from API subdomain',
|
|
20
|
+
* message: 'Custom API error: %s',
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
register(subDomain: string, name: string, definition: CustomErrorDefinition): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get a standardized KuzzleError
|
|
27
|
+
*
|
|
28
|
+
* @param subDomain Subdomain name
|
|
29
|
+
* @param name Standard error name
|
|
30
|
+
* @param placeholders Other placeholder arguments
|
|
31
|
+
*
|
|
32
|
+
* @example throw app.errors.get('api', 'custom', 'Tbilisi');
|
|
33
|
+
*
|
|
34
|
+
* @returns Standardized KuzzleError
|
|
35
|
+
*/
|
|
36
|
+
get(subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
|
|
37
|
+
/**
|
|
38
|
+
* Get a standardized KuzzleError from an existing error to keep the stacktrace
|
|
39
|
+
*
|
|
40
|
+
* @param source Original error
|
|
41
|
+
* @param subDomain Subdomain name
|
|
42
|
+
* @param name Standard error name
|
|
43
|
+
* @param placeholders Other placeholder arguments
|
|
44
|
+
*
|
|
45
|
+
* @returns Standardized KuzzleError
|
|
46
|
+
*/
|
|
47
|
+
getFrom(source: Error, subDomain: string, name: string, ...placeholders: any[]): KuzzleError;
|
|
48
|
+
/**
|
|
49
|
+
* Wrap an error manager on the subDomain
|
|
50
|
+
*
|
|
51
|
+
* @param subDomain Subdomain to wrap to
|
|
52
|
+
*/
|
|
53
|
+
wrap(subDomain: string): {
|
|
54
|
+
get: (error: any, ...placeholders: any[]) => KuzzleError;
|
|
55
|
+
getFrom: (source: any, error: any, ...placeholders: any[]) => KuzzleError;
|
|
56
|
+
reject: (error: any, ...placeholders: any[]) => Promise<any>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2020 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
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
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.BackendErrors = void 0;
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
44
|
+
const index_1 = require("./index");
|
|
45
|
+
class BackendErrors extends index_1.ApplicationManager {
|
|
46
|
+
constructor(application) {
|
|
47
|
+
super(application);
|
|
48
|
+
this.domains = {
|
|
49
|
+
app: {
|
|
50
|
+
code: 9,
|
|
51
|
+
subdomains: {},
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
this.subDomains = 0;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Register a new standard KuzzleError
|
|
58
|
+
*
|
|
59
|
+
* @param subDomain Subdomain name
|
|
60
|
+
* @param name Standard error name
|
|
61
|
+
* @param definition Standard error definition
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```
|
|
65
|
+
* app.errors.register('api', 'custom', {
|
|
66
|
+
* class: 'BadRequestError',
|
|
67
|
+
* description: 'This is a custom error from API subdomain',
|
|
68
|
+
* message: 'Custom API error: %s',
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
register(subDomain, name, definition) {
|
|
73
|
+
if (!this.domains.app.subdomains[subDomain]) {
|
|
74
|
+
this.domains.app.subdomains[subDomain] = {
|
|
75
|
+
code: this.subDomains++,
|
|
76
|
+
errors: {},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
this.domains.app.subdomains[subDomain].errors[name] = {
|
|
80
|
+
code: Object.keys(this.domains.app.subdomains[subDomain].errors).length,
|
|
81
|
+
...definition,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get a standardized KuzzleError
|
|
86
|
+
*
|
|
87
|
+
* @param subDomain Subdomain name
|
|
88
|
+
* @param name Standard error name
|
|
89
|
+
* @param placeholders Other placeholder arguments
|
|
90
|
+
*
|
|
91
|
+
* @example throw app.errors.get('api', 'custom', 'Tbilisi');
|
|
92
|
+
*
|
|
93
|
+
* @returns Standardized KuzzleError
|
|
94
|
+
*/
|
|
95
|
+
get(subDomain, name, ...placeholders) {
|
|
96
|
+
return kerror.rawGet(this.domains, 'app', subDomain, name, ...placeholders);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get a standardized KuzzleError from an existing error to keep the stacktrace
|
|
100
|
+
*
|
|
101
|
+
* @param source Original error
|
|
102
|
+
* @param subDomain Subdomain name
|
|
103
|
+
* @param name Standard error name
|
|
104
|
+
* @param placeholders Other placeholder arguments
|
|
105
|
+
*
|
|
106
|
+
* @returns Standardized KuzzleError
|
|
107
|
+
*/
|
|
108
|
+
getFrom(source, subDomain, name, ...placeholders) {
|
|
109
|
+
return kerror.rawGetFrom(this.domains, source, 'app', subDomain, name, ...placeholders);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Wrap an error manager on the subDomain
|
|
113
|
+
*
|
|
114
|
+
* @param subDomain Subdomain to wrap to
|
|
115
|
+
*/
|
|
116
|
+
wrap(subDomain) {
|
|
117
|
+
return kerror.rawWrap(this.domains, 'app', subDomain);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.BackendErrors = BackendErrors;
|
|
121
|
+
//# sourceMappingURL=backendErrors.js.map
|
|
@@ -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.BackendHook = void 0;
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
28
44
|
const index_1 = require("./index");
|
|
29
|
-
const assertionError =
|
|
30
|
-
const runtimeError =
|
|
45
|
+
const assertionError = kerror.wrap('plugin', 'assert');
|
|
46
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
31
47
|
class BackendHook extends index_1.ApplicationManager {
|
|
32
48
|
/**
|
|
33
49
|
* Registers a new hook on an event
|
|
@@ -19,16 +19,32 @@
|
|
|
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.BackendImport = void 0;
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
28
44
|
const index_1 = require("./index");
|
|
29
45
|
const safeObject_1 = require("../../../lib/util/safeObject");
|
|
30
|
-
const assertionError =
|
|
31
|
-
const runtimeError =
|
|
46
|
+
const assertionError = kerror.wrap('validation', 'assert');
|
|
47
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
32
48
|
class BackendImport extends index_1.ApplicationManager {
|
|
33
49
|
/**
|
|
34
50
|
* Import mappings.
|
|
@@ -27,7 +27,7 @@ class BackendOpenApi extends index_1.ApplicationManager {
|
|
|
27
27
|
super(application);
|
|
28
28
|
/* eslint-disable sort-keys */
|
|
29
29
|
this.definition = {
|
|
30
|
-
|
|
30
|
+
openapi: '3.0.0',
|
|
31
31
|
info: {
|
|
32
32
|
title: `${application.name} API`,
|
|
33
33
|
description: `${application.name} HTTP API definition`,
|
|
@@ -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.BackendPipe = void 0;
|
|
27
|
-
const
|
|
43
|
+
const kerror = __importStar(require("../../kerror"));
|
|
28
44
|
const index_1 = require("./index");
|
|
29
|
-
const assertionError =
|
|
30
|
-
const runtimeError =
|
|
45
|
+
const assertionError = kerror.wrap('plugin', 'assert');
|
|
46
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
31
47
|
class BackendPipe extends index_1.ApplicationManager {
|
|
32
48
|
/**
|
|
33
49
|
* Registers a new pipe on an event
|
|
@@ -19,17 +19,36 @@
|
|
|
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.BackendPlugin = void 0;
|
|
27
46
|
const inflector_1 = require("../../util/inflector");
|
|
28
|
-
const
|
|
47
|
+
const kerror = __importStar(require("../../kerror"));
|
|
29
48
|
const index_1 = require("./index");
|
|
30
49
|
const didYouMean_1 = __importDefault(require("../../util/didYouMean"));
|
|
31
|
-
const assertionError =
|
|
32
|
-
const runtimeError =
|
|
50
|
+
const assertionError = kerror.wrap('plugin', 'assert');
|
|
51
|
+
const runtimeError = kerror.wrap('plugin', 'runtime');
|
|
33
52
|
class BackendPlugin extends index_1.ApplicationManager {
|
|
34
53
|
/**
|
|
35
54
|
* Uses a plugin in this application.
|
|
@@ -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);
|