kuzzle 2.16.8 → 2.17.0
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/README.md +11 -0
- package/lib/api/controllers/adminController.js +7 -6
- package/lib/api/controllers/authController.js +11 -11
- package/lib/api/controllers/baseController.js +60 -3
- package/lib/api/controllers/clusterController.js +1 -1
- package/lib/api/controllers/collectionController.js +7 -5
- package/lib/api/controllers/documentController.js +130 -17
- package/lib/api/controllers/indexController.js +1 -1
- package/lib/api/controllers/memoryStorageController.js +39 -38
- package/lib/api/controllers/realtimeController.js +1 -1
- package/lib/api/controllers/securityController.js +49 -49
- package/lib/api/controllers/serverController.js +73 -27
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +40 -21
- package/lib/api/httpRoutes.js +9 -4
- package/lib/api/openapi/OpenApiManager.d.ts +11 -0
- package/lib/api/openapi/OpenApiManager.js +96 -0
- package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
- package/lib/api/openapi/{document → components/document}/index.js +7 -2
- package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
- package/lib/api/openapi/components/document/validate.yaml +42 -0
- package/lib/api/openapi/components/index.d.ts +2 -0
- package/lib/api/openapi/components/index.js +18 -0
- package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
- package/lib/api/openapi/index.d.ts +1 -2
- package/lib/api/openapi/index.js +1 -5
- package/lib/api/openapi/openApiGenerator.d.ts +7 -0
- package/lib/api/openapi/openApiGenerator.js +133 -0
- package/lib/api/request/kuzzleRequest.d.ts +11 -11
- package/lib/api/request/kuzzleRequest.js +38 -48
- package/lib/cluster/node.js +9 -9
- package/lib/cluster/publisher.js +1 -1
- package/lib/cluster/subscriber.js +1 -1
- package/lib/cluster/workers/IDCardRenewer.js +13 -4
- package/lib/config/default.config.js +1 -0
- package/lib/config/index.js +6 -6
- package/lib/core/auth/passportResponse.js +6 -6
- package/lib/core/auth/passportWrapper.js +5 -5
- package/lib/core/backend/backend.d.ts +5 -1
- package/lib/core/backend/backend.js +12 -8
- package/lib/core/backend/backendConfig.d.ts +5 -1
- package/lib/core/backend/backendConfig.js +4 -0
- package/lib/core/backend/backendOpenApi.d.ts +9 -0
- package/lib/core/backend/backendOpenApi.js +69 -0
- package/lib/core/backend/index.d.ts +1 -0
- package/lib/core/backend/index.js +1 -0
- package/lib/core/network/accessLogger.js +6 -6
- package/lib/core/network/clientConnection.js +1 -1
- package/lib/core/network/entryPoint.js +5 -5
- package/lib/core/network/httpRouter/index.js +5 -5
- package/lib/core/network/httpRouter/routeHandler.js +3 -3
- package/lib/core/network/httpRouter/routePart.js +5 -5
- package/lib/core/network/protocolManifest.js +1 -1
- package/lib/core/network/protocols/httpMessage.js +2 -2
- package/lib/core/network/protocols/httpwsProtocol.js +207 -46
- package/lib/core/network/protocols/mqttProtocol.js +3 -3
- package/lib/core/network/protocols/protocol.js +3 -3
- package/lib/core/network/router.js +7 -6
- package/lib/core/plugin/plugin.js +38 -64
- package/lib/core/plugin/pluginContext.d.ts +10 -1
- package/lib/core/plugin/pluginContext.js +2 -0
- package/lib/core/plugin/pluginManifest.js +3 -3
- package/lib/core/plugin/pluginRepository.js +5 -5
- package/lib/core/plugin/pluginsManager.js +29 -28
- package/lib/core/realtime/notification/server.js +1 -1
- package/lib/core/realtime/notification/user.js +1 -1
- package/lib/core/realtime/notifier.js +5 -5
- package/lib/core/security/index.js +1 -1
- package/lib/core/security/profileRepository.d.ts +176 -0
- package/lib/core/security/profileRepository.js +426 -443
- package/lib/core/security/roleRepository.js +16 -16
- package/lib/core/security/securityLoader.js +3 -3
- package/lib/core/security/tokenRepository.js +18 -21
- package/lib/core/security/userRepository.js +8 -8
- package/lib/core/shared/abstractManifest.js +4 -4
- package/lib/core/shared/repository.js +6 -6
- package/lib/core/shared/sdk/funnelProtocol.js +1 -1
- package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
- package/lib/core/shared/store.js +30 -23
- package/lib/core/statistics/statistics.js +17 -17
- package/lib/core/storage/clientAdapter.js +45 -10
- package/lib/core/validation/baseType.js +5 -5
- package/lib/core/validation/types/anything.js +1 -1
- package/lib/core/validation/types/boolean.js +2 -2
- package/lib/core/validation/types/date.js +9 -9
- package/lib/core/validation/types/email.js +5 -5
- package/lib/core/validation/types/enum.js +6 -6
- package/lib/core/validation/types/geoPoint.js +2 -2
- package/lib/core/validation/types/geoShape.js +28 -25
- package/lib/core/validation/types/integer.js +4 -4
- package/lib/core/validation/types/ipAddress.js +7 -6
- package/lib/core/validation/types/numeric.js +4 -4
- package/lib/core/validation/types/object.js +5 -5
- package/lib/core/validation/types/string.js +5 -5
- package/lib/core/validation/types/url.js +7 -6
- package/lib/core/validation/validation.js +95 -84
- package/lib/kerror/codes/1-services.json +12 -0
- package/lib/kerror/codes/2-api.json +12 -0
- package/lib/kerror/codes/3-network.json +12 -0
- package/lib/kerror/codes/4-plugin.json +6 -0
- package/lib/kerror/codes/index.js +11 -11
- package/lib/kerror/index.js +1 -1
- package/lib/kuzzle/dumpGenerator.js +3 -3
- package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
- package/lib/kuzzle/event/pipeRunner.js +1 -1
- package/lib/kuzzle/event/waterfall.js +6 -6
- package/lib/kuzzle/kuzzle.js +36 -5
- package/lib/kuzzle/log.js +3 -3
- package/lib/kuzzle/vault.js +3 -3
- package/lib/model/security/profile.d.ts +54 -0
- package/lib/model/security/profile.js +174 -233
- package/lib/model/security/rights.js +1 -1
- package/lib/model/security/role.d.ts +40 -0
- package/lib/model/security/role.js +159 -191
- package/lib/model/security/user.d.ts +29 -0
- package/lib/model/security/user.js +84 -52
- package/lib/model/storage/apiKey.js +2 -2
- package/lib/model/storage/baseModel.js +3 -3
- package/lib/service/cache/redis.js +7 -7
- package/lib/service/storage/elasticsearch.js +152 -90
- package/lib/service/storage/esWrapper.js +2 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/ControllerRights.d.ts +22 -0
- package/lib/types/ControllerRights.js +23 -0
- package/lib/types/HttpStream.d.ts +32 -0
- package/lib/types/HttpStream.js +70 -0
- package/lib/types/OpenApiDefinition.d.ts +43 -0
- package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
- package/lib/types/Policy.d.ts +25 -0
- package/lib/types/Policy.js +23 -0
- package/lib/types/PolicyRestrictions.d.ts +21 -0
- package/lib/types/PolicyRestrictions.js +23 -0
- package/lib/types/Target.d.ts +15 -0
- package/lib/types/Target.js +23 -0
- package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
- package/lib/types/index.d.ts +7 -1
- package/lib/types/index.js +7 -1
- package/lib/util/array.d.ts +11 -0
- package/lib/util/array.js +57 -0
- package/lib/util/assertType.js +6 -6
- package/lib/util/bufferedPassThrough.d.ts +76 -0
- package/lib/util/bufferedPassThrough.js +161 -0
- package/lib/util/deprecate.js +7 -5
- package/lib/util/didYouMean.js +1 -1
- package/lib/util/dump-collection.d.ts +3 -0
- package/lib/util/dump-collection.js +265 -0
- package/lib/util/extractFields.js +2 -2
- package/lib/util/inflector.d.ts +8 -0
- package/lib/util/inflector.js +16 -0
- package/lib/util/requestAssertions.js +7 -7
- package/lib/util/wildcard.js +55 -0
- package/package-lock.json +881 -431
- package/package.json +23 -20
- package/lib/api/openApiGenerator.d.ts +0 -7
- package/lib/api/openApiGenerator.js +0 -197
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
|
|
4
|
-
const readYamlFile_1 = require("
|
|
3
|
+
exports.OpenApiDocumentValidateComponent = exports.OpenApiDocumentValidate = exports.OpenApiDocumentDeleteByQueryComponent = exports.OpenApiDocumentDeleteByQuery = exports.OpenApiDocumentDeleteComponent = exports.OpenApiDocumentDelete = exports.OpenApiDocumentScrollComponent = exports.OpenApiDocumentScroll = exports.OpenApiDocumentUpdateComponent = exports.OpenApiDocumentUpdate = exports.OpenApiDocumentExistsComponent = exports.OpenApiDocumentExists = exports.OpenApiDocumentReplaceComponent = exports.OpenApiDocumentReplace = exports.OpenApiDocumentGetComponent = exports.OpenApiDocumentGet = exports.OpenApiDocumentCreateOrReplaceComponent = exports.OpenApiDocumentCreateOrReplace = exports.OpenApiDocumentCreateComponent = exports.OpenApiDocumentCreate = exports.OpenApiDocumentCountComponent = exports.OpenApiDocumentCount = void 0;
|
|
4
|
+
const readYamlFile_1 = require("../../../../util/readYamlFile");
|
|
5
5
|
// reading the description of the Count action in the controller document.
|
|
6
6
|
// The yaml objects are then stored in the variables below
|
|
7
7
|
const countObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/count.yaml');
|
|
@@ -52,4 +52,9 @@ exports.OpenApiDocumentDeleteComponent = deleteObject.components.schemas;
|
|
|
52
52
|
const deleteByQueryObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/deleteByQuery.yaml');
|
|
53
53
|
exports.OpenApiDocumentDeleteByQuery = deleteByQueryObject.DocumentDeleteByQuery;
|
|
54
54
|
exports.OpenApiDocumentDeleteByQueryComponent = deleteByQueryObject.components.schemas;
|
|
55
|
+
// reading the description of the Validate action in the controller document.
|
|
56
|
+
// The yaml objects are then stored in the variables below
|
|
57
|
+
const validateObject = (0, readYamlFile_1.readYamlFile)(__dirname + '/validate.yaml');
|
|
58
|
+
exports.OpenApiDocumentValidate = validateObject.DocumentValidate;
|
|
59
|
+
exports.OpenApiDocumentValidateComponent = validateObject.components.schemas;
|
|
55
60
|
//# sourceMappingURL=index.js.map
|
|
@@ -35,12 +35,12 @@ DocumentReplace:
|
|
|
35
35
|
description: "Replaces the content of an existing document."
|
|
36
36
|
required: true
|
|
37
37
|
schema:
|
|
38
|
-
$ref: "#/components/
|
|
38
|
+
$ref: "#/components/document/DocumentReplaceRequest"
|
|
39
39
|
responses:
|
|
40
40
|
200:
|
|
41
41
|
description: "Replaces the content of an existing document."
|
|
42
42
|
schema:
|
|
43
|
-
$ref: "#/components/
|
|
43
|
+
$ref: "#/components/document/DocumentReplaceResponse"
|
|
44
44
|
|
|
45
45
|
components:
|
|
46
46
|
schemas:
|
|
@@ -47,12 +47,12 @@ DocumentUpdate:
|
|
|
47
47
|
description: "Updates a document content."
|
|
48
48
|
required: true
|
|
49
49
|
schema:
|
|
50
|
-
$ref: "#/components/
|
|
50
|
+
$ref: "#/components/document/DocumentUpdateRequest"
|
|
51
51
|
responses:
|
|
52
52
|
200:
|
|
53
53
|
description: "Updates a document content."
|
|
54
54
|
schema:
|
|
55
|
-
$ref: "#/components/
|
|
55
|
+
$ref: "#/components/document/DocumentUpdateResponse"
|
|
56
56
|
|
|
57
57
|
components:
|
|
58
58
|
schemas:
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
DocumentValidate:
|
|
2
|
+
summary: "Validates data against existing validation rules."
|
|
3
|
+
tags:
|
|
4
|
+
- document
|
|
5
|
+
parameters:
|
|
6
|
+
- in: path
|
|
7
|
+
name: index
|
|
8
|
+
schema:
|
|
9
|
+
type: string
|
|
10
|
+
- in: path
|
|
11
|
+
name: collection
|
|
12
|
+
schema:
|
|
13
|
+
type: string
|
|
14
|
+
- in: body
|
|
15
|
+
name: "body"
|
|
16
|
+
description: "Document content to check."
|
|
17
|
+
required: true
|
|
18
|
+
schema:
|
|
19
|
+
$ref: "#/components/document/DocumentValidateRequest"
|
|
20
|
+
responses:
|
|
21
|
+
200:
|
|
22
|
+
description: "Returns the document validation status."
|
|
23
|
+
schema:
|
|
24
|
+
$ref: "#/components/document/DocumentValidateResponse"
|
|
25
|
+
|
|
26
|
+
components:
|
|
27
|
+
schemas:
|
|
28
|
+
DocumentValidateRequest:
|
|
29
|
+
allOf:
|
|
30
|
+
- type: "object"
|
|
31
|
+
description: "document content"
|
|
32
|
+
|
|
33
|
+
DocumentValidateResponse:
|
|
34
|
+
allOf:
|
|
35
|
+
- $ref: "#/components/ResponsePayload"
|
|
36
|
+
- type: "object"
|
|
37
|
+
properties:
|
|
38
|
+
result:
|
|
39
|
+
type: "object"
|
|
40
|
+
properties:
|
|
41
|
+
valid:
|
|
42
|
+
type: "boolean"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.OpenApiPayloadsDefinitions = void 0;
|
|
14
|
+
const readYamlFile_1 = require("../../../util/readYamlFile");
|
|
15
|
+
__exportStar(require("./document"), exports);
|
|
16
|
+
// Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
|
|
17
|
+
exports.OpenApiPayloadsDefinitions = (0, readYamlFile_1.readYamlFile)(__dirname + '/payloads.yaml').definitions;
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export declare const OpenApiPayloadsDefinitions: any;
|
|
1
|
+
export * from './OpenApiManager';
|
package/lib/api/openapi/index.js
CHANGED
|
@@ -10,9 +10,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports
|
|
14
|
-
const readYamlFile_1 = require("../../util/readYamlFile");
|
|
15
|
-
__exportStar(require("./document"), exports);
|
|
16
|
-
// Document definitions (reusable object for KuzzleRequest and KuzzleResponse)
|
|
17
|
-
exports.OpenApiPayloadsDefinitions = (0, readYamlFile_1.readYamlFile)(__dirname + '/payloads.yaml').definitions;
|
|
13
|
+
__exportStar(require("./OpenApiManager"), exports);
|
|
18
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateOpenApi = void 0;
|
|
27
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
28
|
+
const inflector_1 = require("../../util/inflector");
|
|
29
|
+
const routeUrlMatch = /:([^/]*)/g;
|
|
30
|
+
/**
|
|
31
|
+
* Generate basic openApi Controller
|
|
32
|
+
*/
|
|
33
|
+
function generateController(route, definition) {
|
|
34
|
+
if (route.controller === undefined) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!lodash_1.default.some(definition.tags, { name: route.controller })) {
|
|
38
|
+
const capitalizedController = inflector_1.Inflector.pascalCase(route.controller);
|
|
39
|
+
definition.tags.push({
|
|
40
|
+
description: `${capitalizedController} Controller`,
|
|
41
|
+
name: route.controller
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (route.openapi.tags === undefined) {
|
|
45
|
+
route.openapi.tags = [];
|
|
46
|
+
}
|
|
47
|
+
if (!route.openapi.tags.includes(route.controller)) {
|
|
48
|
+
route.openapi.tags.push(route.controller);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generate basic openApi Summary
|
|
53
|
+
*/
|
|
54
|
+
function generateSummary(route) {
|
|
55
|
+
if (route.openapi.description === undefined) {
|
|
56
|
+
route.openapi.description = `Controller: ${route.controller}.`;
|
|
57
|
+
}
|
|
58
|
+
if (route.openapi.summary === undefined) {
|
|
59
|
+
route.openapi.summary = `Action: ${route.action}.`;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generate basic openApi Parameters
|
|
64
|
+
*/
|
|
65
|
+
function generateParameters(route) {
|
|
66
|
+
if (route.openapi.parameters === undefined) {
|
|
67
|
+
route.openapi.parameters = [];
|
|
68
|
+
let m = routeUrlMatch.exec(route.path);
|
|
69
|
+
while (m !== null) {
|
|
70
|
+
routeUrlMatch.lastIndex++;
|
|
71
|
+
route.openapi.parameters.push({
|
|
72
|
+
in: 'path',
|
|
73
|
+
name: m[1],
|
|
74
|
+
required: true,
|
|
75
|
+
schema: { type: 'string' }
|
|
76
|
+
});
|
|
77
|
+
m = routeUrlMatch.exec(route.path);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (route.openapi.parameters.length === 0) {
|
|
81
|
+
route.openapi.parameters = undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate basic openApi Response
|
|
86
|
+
*/
|
|
87
|
+
function generateResponse(route) {
|
|
88
|
+
if (route.openapi.responses === undefined) {
|
|
89
|
+
route.openapi.responses = {
|
|
90
|
+
'200': {
|
|
91
|
+
description: 'OK'
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Generates JSON OpenApi object
|
|
98
|
+
*
|
|
99
|
+
* @returns {object} openApi object
|
|
100
|
+
*/
|
|
101
|
+
function generateOpenApi(routes, definition) {
|
|
102
|
+
for (const route of routes) {
|
|
103
|
+
// Make sure route verbs are lowercase
|
|
104
|
+
if (route.verb !== undefined) {
|
|
105
|
+
route.verb = route.verb.toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
// Set :param notation to {param}
|
|
108
|
+
route.formattedPath = route.path.replace(routeUrlMatch, '{$1}');
|
|
109
|
+
if (definition.paths[route.formattedPath] === undefined) {
|
|
110
|
+
definition.paths[route.formattedPath] = {};
|
|
111
|
+
}
|
|
112
|
+
if (definition.paths[route.formattedPath][route.verb] !== undefined) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
// If custom specification, return as it is
|
|
116
|
+
if (route.openapi) {
|
|
117
|
+
generateController(route, definition);
|
|
118
|
+
definition.paths[route.formattedPath][route.verb] = route.openapi;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (route.openapi === undefined) {
|
|
122
|
+
route.openapi = {};
|
|
123
|
+
}
|
|
124
|
+
generateController(route, definition);
|
|
125
|
+
generateSummary(route);
|
|
126
|
+
generateParameters(route);
|
|
127
|
+
generateResponse(route);
|
|
128
|
+
definition.paths[route.formattedPath][route.verb] = route.openapi;
|
|
129
|
+
}
|
|
130
|
+
return definition;
|
|
131
|
+
}
|
|
132
|
+
exports.generateOpenApi = generateOpenApi;
|
|
133
|
+
//# sourceMappingURL=openApiGenerator.js.map
|
|
@@ -161,7 +161,7 @@ export declare class KuzzleRequest {
|
|
|
161
161
|
* value provided
|
|
162
162
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a number
|
|
163
163
|
*/
|
|
164
|
-
getBodyNumber(name: string, def?: number |
|
|
164
|
+
getBodyNumber(name: string, def?: number | undefined): number;
|
|
165
165
|
/**
|
|
166
166
|
* Gets a parameter from a request body and checks that it is a integer
|
|
167
167
|
*
|
|
@@ -174,7 +174,7 @@ export declare class KuzzleRequest {
|
|
|
174
174
|
* value provided
|
|
175
175
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an integer
|
|
176
176
|
*/
|
|
177
|
-
getBodyInteger(name: string, def?: number |
|
|
177
|
+
getBodyInteger(name: string, def?: number | undefined): number;
|
|
178
178
|
/**
|
|
179
179
|
* Gets a parameter from a request body and checks that it is a string
|
|
180
180
|
*
|
|
@@ -187,7 +187,7 @@ export declare class KuzzleRequest {
|
|
|
187
187
|
* value provided
|
|
188
188
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a string
|
|
189
189
|
*/
|
|
190
|
-
getBodyString(name: string, def?: string |
|
|
190
|
+
getBodyString(name: string, def?: string | undefined): string;
|
|
191
191
|
/**
|
|
192
192
|
* Gets a parameter from a request body and checks that it is an array
|
|
193
193
|
*
|
|
@@ -200,7 +200,7 @@ export declare class KuzzleRequest {
|
|
|
200
200
|
* value provided
|
|
201
201
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an array
|
|
202
202
|
*/
|
|
203
|
-
getBodyArray(name: string, def?: [] |
|
|
203
|
+
getBodyArray(name: string, def?: [] | undefined): any[];
|
|
204
204
|
/**
|
|
205
205
|
* Gets a parameter from a request body and checks that it is an object
|
|
206
206
|
*
|
|
@@ -213,7 +213,7 @@ export declare class KuzzleRequest {
|
|
|
213
213
|
* value provided
|
|
214
214
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an object
|
|
215
215
|
*/
|
|
216
|
-
getBodyObject(name: string, def?: JSONObject |
|
|
216
|
+
getBodyObject(name: string, def?: JSONObject | undefined): JSONObject;
|
|
217
217
|
/**
|
|
218
218
|
* Gets a parameter from a request arguments and checks that it is a boolean
|
|
219
219
|
* Contrary to other parameter types, an unset boolean does not trigger an
|
|
@@ -232,7 +232,7 @@ export declare class KuzzleRequest {
|
|
|
232
232
|
* value provided
|
|
233
233
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a number
|
|
234
234
|
*/
|
|
235
|
-
getNumber(name: string, def?: number |
|
|
235
|
+
getNumber(name: string, def?: number | undefined): number;
|
|
236
236
|
/**
|
|
237
237
|
* Gets a parameter from a request arguments and checks that it is an integer
|
|
238
238
|
*
|
|
@@ -243,7 +243,7 @@ export declare class KuzzleRequest {
|
|
|
243
243
|
* value provided
|
|
244
244
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an integer
|
|
245
245
|
*/
|
|
246
|
-
getInteger(name: string, def?: number |
|
|
246
|
+
getInteger(name: string, def?: number | undefined): number;
|
|
247
247
|
/**
|
|
248
248
|
* Gets a parameter from a request arguments and checks that it is a string
|
|
249
249
|
*
|
|
@@ -254,7 +254,7 @@ export declare class KuzzleRequest {
|
|
|
254
254
|
* value provided
|
|
255
255
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a string
|
|
256
256
|
*/
|
|
257
|
-
getString(name: string, def?: string |
|
|
257
|
+
getString(name: string, def?: string | undefined): string;
|
|
258
258
|
/**
|
|
259
259
|
* Gets a parameter from a request arguments and checks that it is an array
|
|
260
260
|
*
|
|
@@ -265,7 +265,7 @@ export declare class KuzzleRequest {
|
|
|
265
265
|
* value provided
|
|
266
266
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an array
|
|
267
267
|
*/
|
|
268
|
-
getArray(name: string, def?: [] |
|
|
268
|
+
getArray(name: string, def?: [] | undefined): any[];
|
|
269
269
|
/**
|
|
270
270
|
* Gets a parameter from a request arguments and checks that it is an object
|
|
271
271
|
*
|
|
@@ -276,7 +276,7 @@ export declare class KuzzleRequest {
|
|
|
276
276
|
* value provided
|
|
277
277
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an object
|
|
278
278
|
*/
|
|
279
|
-
getObject(name: string, def?: JSONObject |
|
|
279
|
+
getObject(name: string, def?: JSONObject | undefined): JSONObject;
|
|
280
280
|
/**
|
|
281
281
|
* Returns the index specified in the request
|
|
282
282
|
*/
|
|
@@ -300,7 +300,7 @@ export declare class KuzzleRequest {
|
|
|
300
300
|
* @throws {api.assert.body_required} If the body is not set and if no default
|
|
301
301
|
* value is provided
|
|
302
302
|
*/
|
|
303
|
-
getBody(def?: JSONObject |
|
|
303
|
+
getBody(def?: JSONObject | undefined): JSONObject;
|
|
304
304
|
/**
|
|
305
305
|
* Returns the `_id` specified in the request.
|
|
306
306
|
*
|
|
@@ -50,8 +50,10 @@ const requestResponse_1 = require("./requestResponse");
|
|
|
50
50
|
const requestContext_1 = require("./requestContext");
|
|
51
51
|
const errors_1 = require("../../kerror/errors");
|
|
52
52
|
const kerror_1 = __importDefault(require("../../kerror"));
|
|
53
|
+
const types_1 = require("../../types");
|
|
53
54
|
const assert = __importStar(require("../../util/assertType"));
|
|
54
55
|
const safeObject_1 = require("../../util/safeObject");
|
|
56
|
+
const lodash_1 = require("lodash");
|
|
55
57
|
const assertionError = kerror_1.default.wrap('api', 'assert');
|
|
56
58
|
// private properties
|
|
57
59
|
// \u200b is a zero width space, used to masquerade console.log output
|
|
@@ -216,6 +218,9 @@ class KuzzleRequest {
|
|
|
216
218
|
if (result instanceof Error) {
|
|
217
219
|
throw new errors_1.InternalError('cannot set an error as a request\'s response');
|
|
218
220
|
}
|
|
221
|
+
if (this.context.connection.protocol !== 'http' && result instanceof types_1.HttpStream) {
|
|
222
|
+
throw kerror_1.default.get('api', 'assert', 'forbidden_stream');
|
|
223
|
+
}
|
|
219
224
|
this.status = options.status || 200;
|
|
220
225
|
if (options.headers) {
|
|
221
226
|
this.response.setHeaders(options.headers);
|
|
@@ -349,10 +354,10 @@ class KuzzleRequest {
|
|
|
349
354
|
* value provided
|
|
350
355
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a number
|
|
351
356
|
*/
|
|
352
|
-
getBodyNumber(name, def =
|
|
357
|
+
getBodyNumber(name, def = undefined) {
|
|
353
358
|
const body = this.input.body;
|
|
354
359
|
if (body === null) {
|
|
355
|
-
if (def !==
|
|
360
|
+
if (def !== undefined) {
|
|
356
361
|
return def;
|
|
357
362
|
}
|
|
358
363
|
throw assertionError.get('body_required');
|
|
@@ -371,10 +376,10 @@ class KuzzleRequest {
|
|
|
371
376
|
* value provided
|
|
372
377
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an integer
|
|
373
378
|
*/
|
|
374
|
-
getBodyInteger(name, def =
|
|
379
|
+
getBodyInteger(name, def = undefined) {
|
|
375
380
|
const body = this.input.body;
|
|
376
381
|
if (body === null) {
|
|
377
|
-
if (def !==
|
|
382
|
+
if (def !== undefined) {
|
|
378
383
|
return def;
|
|
379
384
|
}
|
|
380
385
|
throw assertionError.get('body_required');
|
|
@@ -393,10 +398,10 @@ class KuzzleRequest {
|
|
|
393
398
|
* value provided
|
|
394
399
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a string
|
|
395
400
|
*/
|
|
396
|
-
getBodyString(name, def =
|
|
401
|
+
getBodyString(name, def = undefined) {
|
|
397
402
|
const body = this.input.body;
|
|
398
403
|
if (body === null) {
|
|
399
|
-
if (def !==
|
|
404
|
+
if (def !== undefined) {
|
|
400
405
|
return def;
|
|
401
406
|
}
|
|
402
407
|
throw assertionError.get('body_required');
|
|
@@ -415,10 +420,10 @@ class KuzzleRequest {
|
|
|
415
420
|
* value provided
|
|
416
421
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an array
|
|
417
422
|
*/
|
|
418
|
-
getBodyArray(name, def =
|
|
423
|
+
getBodyArray(name, def = undefined) {
|
|
419
424
|
const body = this.input.body;
|
|
420
425
|
if (body === null) {
|
|
421
|
-
if (def !==
|
|
426
|
+
if (def !== undefined) {
|
|
422
427
|
return def;
|
|
423
428
|
}
|
|
424
429
|
throw assertionError.get('body_required');
|
|
@@ -437,10 +442,10 @@ class KuzzleRequest {
|
|
|
437
442
|
* value provided
|
|
438
443
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an object
|
|
439
444
|
*/
|
|
440
|
-
getBodyObject(name, def =
|
|
445
|
+
getBodyObject(name, def = undefined) {
|
|
441
446
|
const body = this.input.body;
|
|
442
447
|
if (body === null) {
|
|
443
|
-
if (def !==
|
|
448
|
+
if (def !== undefined) {
|
|
444
449
|
return def;
|
|
445
450
|
}
|
|
446
451
|
throw assertionError.get('body_required');
|
|
@@ -467,7 +472,7 @@ class KuzzleRequest {
|
|
|
467
472
|
* value provided
|
|
468
473
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a number
|
|
469
474
|
*/
|
|
470
|
-
getNumber(name, def =
|
|
475
|
+
getNumber(name, def = undefined) {
|
|
471
476
|
return this._getNumber(this.input.args, name, name, def);
|
|
472
477
|
}
|
|
473
478
|
/**
|
|
@@ -480,7 +485,7 @@ class KuzzleRequest {
|
|
|
480
485
|
* value provided
|
|
481
486
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an integer
|
|
482
487
|
*/
|
|
483
|
-
getInteger(name, def =
|
|
488
|
+
getInteger(name, def = undefined) {
|
|
484
489
|
return this._getInteger(this.input.args, name, name, def);
|
|
485
490
|
}
|
|
486
491
|
/**
|
|
@@ -493,7 +498,7 @@ class KuzzleRequest {
|
|
|
493
498
|
* value provided
|
|
494
499
|
* @throws {api.assert.invalid_type} If the fetched parameter is not a string
|
|
495
500
|
*/
|
|
496
|
-
getString(name, def =
|
|
501
|
+
getString(name, def = undefined) {
|
|
497
502
|
return this._getString(this.input.args, name, name, def);
|
|
498
503
|
}
|
|
499
504
|
/**
|
|
@@ -506,7 +511,7 @@ class KuzzleRequest {
|
|
|
506
511
|
* value provided
|
|
507
512
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an array
|
|
508
513
|
*/
|
|
509
|
-
getArray(name, def =
|
|
514
|
+
getArray(name, def = undefined) {
|
|
510
515
|
return this._getArray(this.input.args, name, name, def);
|
|
511
516
|
}
|
|
512
517
|
/**
|
|
@@ -519,7 +524,7 @@ class KuzzleRequest {
|
|
|
519
524
|
* value provided
|
|
520
525
|
* @throws {api.assert.invalid_type} If the fetched parameter is not an object
|
|
521
526
|
*/
|
|
522
|
-
getObject(name, def =
|
|
527
|
+
getObject(name, def = undefined) {
|
|
523
528
|
return this._getObject(this.input.args, name, name, def);
|
|
524
529
|
}
|
|
525
530
|
/**
|
|
@@ -565,9 +570,9 @@ class KuzzleRequest {
|
|
|
565
570
|
* @throws {api.assert.body_required} If the body is not set and if no default
|
|
566
571
|
* value is provided
|
|
567
572
|
*/
|
|
568
|
-
getBody(def =
|
|
573
|
+
getBody(def = undefined) {
|
|
569
574
|
if (this.input.body === null) {
|
|
570
|
-
if (def !==
|
|
575
|
+
if (def !== undefined) {
|
|
571
576
|
return def;
|
|
572
577
|
}
|
|
573
578
|
throw assertionError.get('body_required');
|
|
@@ -685,7 +690,7 @@ class KuzzleRequest {
|
|
|
685
690
|
* @param errorName name to use in error messages
|
|
686
691
|
*/
|
|
687
692
|
_getBoolean(obj, name, errorName) {
|
|
688
|
-
let value = (0,
|
|
693
|
+
let value = (0, lodash_1.get)(obj, name);
|
|
689
694
|
// In HTTP, booleans are flags: if it's in the querystring, it's set,
|
|
690
695
|
// whatever its value.
|
|
691
696
|
// If a user needs to unset the option, they need to remove it from the
|
|
@@ -713,12 +718,9 @@ class KuzzleRequest {
|
|
|
713
718
|
* @param errorName - name to use in error messages
|
|
714
719
|
* @param def default value
|
|
715
720
|
*/
|
|
716
|
-
_getNumber(obj, name, errorName, def =
|
|
717
|
-
let value = (0,
|
|
718
|
-
if (value === undefined
|
|
719
|
-
if (def !== null) {
|
|
720
|
-
return def;
|
|
721
|
-
}
|
|
721
|
+
_getNumber(obj, name, errorName, def = undefined) {
|
|
722
|
+
let value = (0, lodash_1.get)(obj, name, def);
|
|
723
|
+
if (value === undefined) {
|
|
722
724
|
throw assertionError.get('missing_argument', errorName);
|
|
723
725
|
}
|
|
724
726
|
value = Number.parseFloat(value);
|
|
@@ -735,12 +737,9 @@ class KuzzleRequest {
|
|
|
735
737
|
* @param errorName name to use in error messages
|
|
736
738
|
* @param def default value
|
|
737
739
|
*/
|
|
738
|
-
_getInteger(obj, name, errorName, def =
|
|
739
|
-
let value = (0,
|
|
740
|
-
if (value === undefined
|
|
741
|
-
if (def !== null) {
|
|
742
|
-
return def;
|
|
743
|
-
}
|
|
740
|
+
_getInteger(obj, name, errorName, def = undefined) {
|
|
741
|
+
let value = (0, lodash_1.get)(obj, name, def);
|
|
742
|
+
if (value === undefined) {
|
|
744
743
|
throw assertionError.get('missing_argument', errorName);
|
|
745
744
|
}
|
|
746
745
|
value = Number.parseFloat(value);
|
|
@@ -757,12 +756,9 @@ class KuzzleRequest {
|
|
|
757
756
|
* @param errorName name to use in error messages
|
|
758
757
|
* @param def default value
|
|
759
758
|
*/
|
|
760
|
-
_getString(obj, name, errorName, def =
|
|
761
|
-
const value = (0,
|
|
762
|
-
if (value === undefined
|
|
763
|
-
if (def !== null) {
|
|
764
|
-
return def;
|
|
765
|
-
}
|
|
759
|
+
_getString(obj, name, errorName, def = undefined) {
|
|
760
|
+
const value = (0, lodash_1.get)(obj, name, def);
|
|
761
|
+
if (value === undefined) {
|
|
766
762
|
throw assertionError.get('missing_argument', errorName);
|
|
767
763
|
}
|
|
768
764
|
if (typeof value !== 'string') {
|
|
@@ -778,12 +774,9 @@ class KuzzleRequest {
|
|
|
778
774
|
* @param errorName name to use in error messages
|
|
779
775
|
* @param def default value
|
|
780
776
|
*/
|
|
781
|
-
_getArray(obj, name, errorName, def =
|
|
782
|
-
const value = (0,
|
|
783
|
-
if (value === undefined
|
|
784
|
-
if (def !== null) {
|
|
785
|
-
return def;
|
|
786
|
-
}
|
|
777
|
+
_getArray(obj, name, errorName, def = undefined) {
|
|
778
|
+
const value = (0, lodash_1.get)(obj, name, def);
|
|
779
|
+
if (value === undefined) {
|
|
787
780
|
throw assertionError.get('missing_argument', errorName);
|
|
788
781
|
}
|
|
789
782
|
if (!Array.isArray(value)) {
|
|
@@ -799,12 +792,9 @@ class KuzzleRequest {
|
|
|
799
792
|
* @param errorName name to use in error messages
|
|
800
793
|
* @param def default value
|
|
801
794
|
*/
|
|
802
|
-
_getObject(obj, name, errorName, def =
|
|
803
|
-
const value = (0,
|
|
804
|
-
if (value === undefined
|
|
805
|
-
if (def !== null) {
|
|
806
|
-
return def;
|
|
807
|
-
}
|
|
795
|
+
_getObject(obj, name, errorName, def = undefined) {
|
|
796
|
+
const value = (0, lodash_1.get)(obj, name, def);
|
|
797
|
+
if (value === undefined) {
|
|
808
798
|
throw assertionError.get('missing_argument', errorName);
|
|
809
799
|
}
|
|
810
800
|
if (!(0, safeObject_1.isPlainObject)(value)) {
|