@asyncapi/cli 3.2.0 → 3.4.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/assets/create-template/templates/default/package-lock.json +4 -3
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +89 -0
- package/lib/apps/api/configs/development.json +16 -0
- package/lib/apps/api/configs/production.json +16 -0
- package/lib/apps/api/configs/test.json +16 -0
- package/lib/apps/api/constants.d.ts +1 -0
- package/lib/apps/api/constants.js +4 -0
- package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
- package/lib/apps/api/controllers/bundle.controller.js +44 -0
- package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
- package/lib/apps/api/controllers/convert.controller.js +69 -0
- package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
- package/lib/apps/api/controllers/diff.controller.js +42 -0
- package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
- package/lib/apps/api/controllers/docs.controller.js +24 -0
- package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
- package/lib/apps/api/controllers/generate.controller.js +176 -0
- package/lib/apps/api/controllers/help.controller.d.ts +6 -0
- package/lib/apps/api/controllers/help.controller.js +101 -0
- package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
- package/lib/apps/api/controllers/parse.controller.js +35 -0
- package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
- package/lib/apps/api/controllers/validate.controller.js +50 -0
- package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
- package/lib/apps/api/exceptions/problem.exception.js +10 -0
- package/lib/apps/api/index.d.ts +9 -0
- package/lib/apps/api/index.js +21 -0
- package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
- package/lib/apps/api/middlewares/problem.middleware.js +27 -0
- package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
- package/lib/apps/api/middlewares/validation.middleware.js +236 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/{commands → apps/cli/commands}/bundle.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/bundle.js +3 -3
- package/lib/{commands → apps/cli/commands}/config/analytics.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/analytics.js +4 -3
- package/lib/{commands → apps/cli/commands}/config/context/add.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/add.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/current.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/current.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/edit.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/edit.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.js +7 -4
- package/lib/{commands → apps/cli/commands}/config/context/list.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/list.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/remove.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/remove.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/context/use.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/use.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.js +2 -2
- package/lib/{commands → apps/cli/commands}/convert.d.ts +2 -7
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/{commands → apps/cli/commands}/diff.d.ts +11 -2
- package/lib/{commands → apps/cli/commands}/diff.js +85 -31
- package/lib/{commands → apps/cli/commands}/format.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/format.js +4 -4
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.d.ts +4 -5
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.js +89 -122
- package/lib/{commands → apps/cli/commands}/generate/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/generate/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/generate/models.d.ts +6 -1
- package/lib/{commands → apps/cli/commands}/generate/models.js +48 -9
- package/lib/{commands → apps/cli/commands}/new/file.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/file.js +11 -8
- package/lib/{commands → apps/cli/commands}/new/glee.d.ts +2 -2
- package/lib/{commands → apps/cli/commands}/new/glee.js +4 -4
- package/lib/{commands → apps/cli/commands}/new/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.js +10 -8
- package/lib/{commands → apps/cli/commands}/optimize.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/optimize.js +71 -30
- package/lib/{commands → apps/cli/commands}/pretty.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/pretty.js +8 -5
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/{commands → apps/cli/commands}/start/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.js +9 -6
- package/lib/{commands → apps/cli/commands}/start/studio.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/studio.js +10 -7
- package/lib/{commands → apps/cli/commands}/validate.d.ts +4 -2
- package/lib/apps/cli/commands/validate.js +94 -0
- package/lib/{core → apps/cli/internal}/base.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/base.js +12 -4
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/{core → apps/cli/internal}/flags/config/context.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/convert.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/diff.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/diff.flags.js +3 -3
- package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.js +12 -12
- package/lib/{core → apps/cli/internal}/flags/generate/models.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/flags/global.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/new/file.flags.js +7 -2
- package/lib/{core → apps/cli/internal}/flags/optimize.flags.js +24 -4
- package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
- package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
- package/lib/{core → apps/cli/internal}/flags/proxy.flags.js +3 -3
- package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
- package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +31 -0
- package/lib/{core → apps/cli/internal}/flags/start/studio.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/validate.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/validate.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/globals.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/globals.js +2 -4
- package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.js +14 -4
- package/lib/{core → domains}/models/Context.js +1 -1
- package/lib/{core → domains}/models/Preview.js +35 -19
- package/lib/{core → domains}/models/SpecificationFile.d.ts +2 -2
- package/lib/{core → domains}/models/SpecificationFile.js +8 -5
- package/lib/{core → domains}/models/Studio.js +4 -4
- package/lib/domains/services/archiver.service.d.ts +17 -0
- package/lib/domains/services/archiver.service.js +53 -0
- package/lib/domains/services/base.service.d.ts +6 -0
- package/lib/domains/services/base.service.js +26 -0
- package/lib/domains/services/convert.service.d.ts +12 -0
- package/lib/domains/services/convert.service.js +65 -0
- package/lib/domains/services/generator.service.d.ts +15 -0
- package/lib/domains/services/generator.service.js +95 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +288 -0
- package/lib/{core/errors → errors}/specification-file.js +1 -1
- package/lib/{core/errors → errors}/validation-error.js +6 -5
- package/lib/interfaces/index.d.ts +87 -0
- package/lib/interfaces/index.js +7 -0
- package/lib/utils/ajv.d.ts +2 -0
- package/lib/utils/ajv.js +18 -0
- package/lib/utils/app-openapi.d.ts +4 -0
- package/lib/utils/app-openapi.js +28 -0
- package/lib/{core/utils/generator.js → utils/fileWatcher.js} +8 -2
- package/lib/utils/logger.d.ts +6 -0
- package/lib/utils/logger.js +33 -0
- package/lib/utils/retrieve-language.d.ts +1 -0
- package/lib/utils/retrieve-language.js +9 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +25 -0
- package/oclif.manifest.json +109 -1
- package/package.json +37 -10
- package/scripts/releasePackagesRename.js +16 -8
- package/lib/commands/convert.js +0 -132
- package/lib/commands/validate.js +0 -47
- package/lib/core/flags/bundle.flags.js +0 -14
- package/lib/core/flags/config/analytics.flags.js +0 -13
- package/lib/core/flags/start/preview.flags.js +0 -15
- package/lib/core/parser.d.ts +0 -35
- package/lib/core/parser.js +0 -230
- /package/lib/{core → apps/cli/internal}/flags/bundle.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/analytics.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/context.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/convert.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/models.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/global.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/file.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/optimize.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/proxy.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/preview.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/studio.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.d.ts +0 -0
- /package/lib/{core → domains}/models/Context.d.ts +0 -0
- /package/lib/{core → domains}/models/Preview.d.ts +0 -0
- /package/lib/{core → domains}/models/Studio.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.js +0 -0
- /package/lib/{core/errors → errors}/diff-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/diff-error.js +0 -0
- /package/lib/{core/errors → errors}/generator-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/generator-error.js +0 -0
- /package/lib/{core/errors → errors}/specification-file.d.ts +0 -0
- /package/lib/{core/errors → errors}/validation-error.d.ts +0 -0
- /package/lib/{core/utils/generator.d.ts → utils/fileWatcher.d.ts} +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.d.ts +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.js +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HelpController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const problem_exception_1 = require("../exceptions/problem.exception");
|
|
7
|
+
const app_openapi_1 = require("../../../utils/app-openapi");
|
|
8
|
+
const getCommandsFromRequest = (req) => {
|
|
9
|
+
return req.params.command
|
|
10
|
+
? req.params.command.split('/').filter((cmd) => cmd.trim())
|
|
11
|
+
: [];
|
|
12
|
+
};
|
|
13
|
+
const isKeyValid = (key, obj) => {
|
|
14
|
+
return Object.keys(obj).includes(key);
|
|
15
|
+
};
|
|
16
|
+
const getPathKeysMatchingCommands = (commands, pathKeys) => {
|
|
17
|
+
if (!Array.isArray(pathKeys) ||
|
|
18
|
+
!pathKeys.every((key) => typeof key === 'string')) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return pathKeys.find((pathKey) => {
|
|
22
|
+
const pathParts = pathKey.split('/').filter((part) => part !== '');
|
|
23
|
+
return pathParts.every((pathPart, i) => {
|
|
24
|
+
const command = commands[Number(i)];
|
|
25
|
+
return pathPart === command || pathPart.startsWith('{');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const getFullRequestBodySpec = (operationDetails) => {
|
|
30
|
+
return isKeyValid('requestBody', operationDetails)
|
|
31
|
+
? operationDetails.requestBody.content['application/json'].schema
|
|
32
|
+
: null;
|
|
33
|
+
};
|
|
34
|
+
const buildResponseObject = (matchedPathKey, method, operationDetails, requestBodySchema) => {
|
|
35
|
+
return {
|
|
36
|
+
command: matchedPathKey,
|
|
37
|
+
method: method.toUpperCase(),
|
|
38
|
+
summary: operationDetails.summary || '',
|
|
39
|
+
requestBody: requestBodySchema,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
class HelpController {
|
|
43
|
+
constructor() {
|
|
44
|
+
this.basepath = '/help';
|
|
45
|
+
}
|
|
46
|
+
boot() {
|
|
47
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const router = (0, express_1.Router)();
|
|
49
|
+
router.get('/help/:command*?', (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const commands = getCommandsFromRequest(req);
|
|
51
|
+
let openapiSpec;
|
|
52
|
+
try {
|
|
53
|
+
openapiSpec = yield (0, app_openapi_1.getAppOpenAPI)();
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return next(err);
|
|
57
|
+
}
|
|
58
|
+
if (commands.length === 0) {
|
|
59
|
+
const routes = isKeyValid('paths', openapiSpec)
|
|
60
|
+
? Object.keys(openapiSpec.paths).map((path) => ({
|
|
61
|
+
command: path.replace(/^\//, ''),
|
|
62
|
+
url: `${this.basepath}${path}`,
|
|
63
|
+
}))
|
|
64
|
+
: [];
|
|
65
|
+
return res.json(routes);
|
|
66
|
+
}
|
|
67
|
+
const pathKeys = isKeyValid('paths', openapiSpec)
|
|
68
|
+
? Object.keys(openapiSpec.paths)
|
|
69
|
+
: [];
|
|
70
|
+
const matchedPathKey = getPathKeysMatchingCommands(commands, pathKeys);
|
|
71
|
+
if (!matchedPathKey) {
|
|
72
|
+
return next(new problem_exception_1.ProblemException({
|
|
73
|
+
type: 'invalid-asyncapi-command',
|
|
74
|
+
title: 'Invalid AsyncAPI Command',
|
|
75
|
+
status: 404,
|
|
76
|
+
detail: 'The given AsyncAPI command is not valid.',
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
const pathInfo = isKeyValid(matchedPathKey, openapiSpec.paths)
|
|
80
|
+
? openapiSpec.paths[String(matchedPathKey)]
|
|
81
|
+
: undefined;
|
|
82
|
+
const method = commands.length > 1 ? 'get' : 'post';
|
|
83
|
+
const operationDetails = isKeyValid(method, pathInfo)
|
|
84
|
+
? pathInfo[String(method)]
|
|
85
|
+
: undefined;
|
|
86
|
+
if (!operationDetails) {
|
|
87
|
+
return next(new problem_exception_1.ProblemException({
|
|
88
|
+
type: 'invalid-asyncapi-command',
|
|
89
|
+
title: 'Invalid AsyncAPI Command',
|
|
90
|
+
status: 404,
|
|
91
|
+
detail: 'The given AsyncAPI command is not valid.',
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
const requestBodySchema = getFullRequestBodySpec(operationDetails);
|
|
95
|
+
return res.json(buildResponseObject(matchedPathKey, method, operationDetails, requestBodySchema));
|
|
96
|
+
}));
|
|
97
|
+
return router;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.HelpController = HelpController;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { Controller } from '../../../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Controller which exposes the Parser functionality, to parse the AsyncAPI document.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ParseController implements Controller {
|
|
7
|
+
basepath: string;
|
|
8
|
+
private parse;
|
|
9
|
+
boot(): Promise<Router>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const validation_middleware_1 = require("../middlewares/validation.middleware");
|
|
7
|
+
/**
|
|
8
|
+
* Controller which exposes the Parser functionality, to parse the AsyncAPI document.
|
|
9
|
+
*/
|
|
10
|
+
class ParseController {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.basepath = '/parse';
|
|
13
|
+
}
|
|
14
|
+
parse(req, res) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a;
|
|
17
|
+
const stringified = JSON.stringify((_a = req.asyncapi) === null || _a === void 0 ? void 0 : _a.parsedDocument);
|
|
18
|
+
res.status(200).json({
|
|
19
|
+
parsed: stringified,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
boot() {
|
|
24
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const router = (0, express_1.Router)();
|
|
26
|
+
router.post(`${this.basepath}`, yield (0, validation_middleware_1.validationMiddleware)({
|
|
27
|
+
path: this.basepath,
|
|
28
|
+
method: 'post',
|
|
29
|
+
documents: ['asyncapi'],
|
|
30
|
+
}), this.parse.bind(this));
|
|
31
|
+
return router;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ParseController = ParseController;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
import { Controller } from '../../../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Controller which exposes the Parser functionality, to validate the AsyncAPI document.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ValidateController implements Controller {
|
|
7
|
+
basepath: string;
|
|
8
|
+
private validate;
|
|
9
|
+
boot(): Promise<Router>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidateController = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const express_1 = require("express");
|
|
6
|
+
const validation_middleware_1 = require("../middlewares/validation.middleware");
|
|
7
|
+
/**
|
|
8
|
+
* Controller which exposes the Parser functionality, to validate the AsyncAPI document.
|
|
9
|
+
*/
|
|
10
|
+
class ValidateController {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.basepath = '/validate';
|
|
13
|
+
}
|
|
14
|
+
validate(req, res) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
17
|
+
if ((_b = (_a = req.asyncapi) === null || _a === void 0 ? void 0 : _a.parsedDocuments) === null || _b === void 0 ? void 0 : _b.length) {
|
|
18
|
+
const results = ((_c = req.asyncapi.validationResults) === null || _c === void 0 ? void 0 : _c.map((result) => ({
|
|
19
|
+
status: result.status,
|
|
20
|
+
asyncapi: result.document,
|
|
21
|
+
diagnostics: result.diagnostics,
|
|
22
|
+
score: result.score,
|
|
23
|
+
}))) || [];
|
|
24
|
+
res.status(200).json({
|
|
25
|
+
results,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
res.status(200).json({
|
|
30
|
+
status: (_e = (_d = req.asyncapi) === null || _d === void 0 ? void 0 : _d.validationResult) === null || _e === void 0 ? void 0 : _e.status,
|
|
31
|
+
asyncapi: (_g = (_f = req.asyncapi) === null || _f === void 0 ? void 0 : _f.validationResult) === null || _g === void 0 ? void 0 : _g.document,
|
|
32
|
+
diagnostics: (_j = (_h = req.asyncapi) === null || _h === void 0 ? void 0 : _h.validationResult) === null || _j === void 0 ? void 0 : _j.diagnostics,
|
|
33
|
+
score: (_l = (_k = req.asyncapi) === null || _k === void 0 ? void 0 : _k.validationResult) === null || _l === void 0 ? void 0 : _l.score,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
boot() {
|
|
39
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const router = (0, express_1.Router)();
|
|
41
|
+
router.post(`${this.basepath}`, yield (0, validation_middleware_1.validationMiddleware)({
|
|
42
|
+
path: this.basepath,
|
|
43
|
+
method: 'post',
|
|
44
|
+
documents: ['asyncapi'],
|
|
45
|
+
}), this.validate.bind(this));
|
|
46
|
+
return router;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ValidateController = ValidateController;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ProblemExceptionProps {
|
|
2
|
+
status: number;
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}
|
|
5
|
+
declare const ProblemException_base: {
|
|
6
|
+
new (problem: import("@asyncapi/problem").ProblemBase & ProblemExceptionProps, options?: import("@asyncapi/problem").ProblemOptions): import("@asyncapi/problem").Problem<ProblemExceptionProps>;
|
|
7
|
+
createType(type: string): string;
|
|
8
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
9
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
10
|
+
stackTraceLimit: number;
|
|
11
|
+
};
|
|
12
|
+
export declare class ProblemException extends ProblemException_base {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProblemException = void 0;
|
|
4
|
+
const problem_1 = require("@asyncapi/problem");
|
|
5
|
+
const typePrefix = 'https://api.asyncapi.com/problem';
|
|
6
|
+
class ProblemException extends (0, problem_1.ProblemMixin)({
|
|
7
|
+
typePrefix,
|
|
8
|
+
}) {
|
|
9
|
+
}
|
|
10
|
+
exports.ProblemException = ProblemException;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidateController } from './controllers/validate.controller';
|
|
2
|
+
import { ParseController } from './controllers/parse.controller';
|
|
3
|
+
import { GenerateController } from './controllers/generate.controller';
|
|
4
|
+
import { ConvertController } from './controllers/convert.controller';
|
|
5
|
+
import { BundleController } from './controllers/bundle.controller';
|
|
6
|
+
import { DiffController } from './controllers/diff.controller';
|
|
7
|
+
import { DocsController } from './controllers/docs.controller';
|
|
8
|
+
import { HelpController } from './controllers/help.controller';
|
|
9
|
+
export declare const CONTROLLERS: (ValidateController | ParseController | GenerateController | ConvertController | BundleController | DiffController | DocsController | HelpController)[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTROLLERS = void 0;
|
|
4
|
+
const validate_controller_1 = require("./controllers/validate.controller");
|
|
5
|
+
const parse_controller_1 = require("./controllers/parse.controller");
|
|
6
|
+
const generate_controller_1 = require("./controllers/generate.controller");
|
|
7
|
+
const convert_controller_1 = require("./controllers/convert.controller");
|
|
8
|
+
const bundle_controller_1 = require("./controllers/bundle.controller");
|
|
9
|
+
const diff_controller_1 = require("./controllers/diff.controller");
|
|
10
|
+
const docs_controller_1 = require("./controllers/docs.controller");
|
|
11
|
+
const help_controller_1 = require("./controllers/help.controller");
|
|
12
|
+
exports.CONTROLLERS = [
|
|
13
|
+
new validate_controller_1.ValidateController(),
|
|
14
|
+
new parse_controller_1.ParseController(),
|
|
15
|
+
new generate_controller_1.GenerateController(),
|
|
16
|
+
new convert_controller_1.ConvertController(),
|
|
17
|
+
new bundle_controller_1.BundleController(),
|
|
18
|
+
new diff_controller_1.DiffController(),
|
|
19
|
+
new docs_controller_1.DocsController(),
|
|
20
|
+
new help_controller_1.HelpController(),
|
|
21
|
+
];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from 'express';
|
|
2
|
+
import { ProblemException } from '../exceptions/problem.exception';
|
|
3
|
+
/**
|
|
4
|
+
* Catch problem exception, log it and serialize error to human readable form.
|
|
5
|
+
*/
|
|
6
|
+
export declare function problemMiddleware(error: ProblemException, req: Request, res: Response, next: NextFunction): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.problemMiddleware = problemMiddleware;
|
|
4
|
+
const logger_1 = require("../../../utils/logger");
|
|
5
|
+
/**
|
|
6
|
+
* Catch problem exception, log it and serialize error to human readable form.
|
|
7
|
+
*/
|
|
8
|
+
function problemMiddleware(error, req, res, next) {
|
|
9
|
+
if (res.headersSent) {
|
|
10
|
+
return next(error);
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const problemShape = error.get();
|
|
14
|
+
const status = (problemShape.status = problemShape.status || 500);
|
|
15
|
+
problemShape.title = problemShape.title || 'Internal server error';
|
|
16
|
+
logger_1.logger.error(`[${req.method}] ${req.path} >> Status:: ${status}, Type:: ${problemShape.type.replace('https://api.asyncapi.com/problem/', '')}, Title:: ${problemShape.title}, Detail:: ${problemShape.detail}`);
|
|
17
|
+
const isError = status >= 500;
|
|
18
|
+
const problem = error.toObject({
|
|
19
|
+
includeStack: isError,
|
|
20
|
+
includeCause: isError,
|
|
21
|
+
});
|
|
22
|
+
res.status(status).json(problem);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
next(err);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
|
2
|
+
export interface ValidationMiddlewareOptions {
|
|
3
|
+
path: string;
|
|
4
|
+
method: 'all' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
5
|
+
documents?: Array<string>;
|
|
6
|
+
version?: 'v1';
|
|
7
|
+
condition?: (req: Request) => boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validate RequestBody and sent AsyncAPI document(s) for given path and method based on the OpenAPI Document.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validationMiddleware(options: ValidationMiddlewareOptions): Promise<(req: Request, res: Response, next: NextFunction) => Promise<void>>;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validationMiddleware = validationMiddleware;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const problem_exception_1 = require("../exceptions/problem.exception");
|
|
6
|
+
const ajv_1 = require("../../../utils/ajv");
|
|
7
|
+
const app_openapi_1 = require("../../../utils/app-openapi");
|
|
8
|
+
const validation_service_1 = require("../../../domains/services/validation.service");
|
|
9
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
10
|
+
const ajvInstance = (0, ajv_1.createAjvInstance)();
|
|
11
|
+
/**
|
|
12
|
+
* Create AJV's validator function for given path in the OpenAPI document.
|
|
13
|
+
*/
|
|
14
|
+
function compileAjv(options) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const appOpenAPI = yield (0, app_openapi_1.getAppOpenAPI)();
|
|
17
|
+
const paths = appOpenAPI.paths || {};
|
|
18
|
+
const pathName = options.path;
|
|
19
|
+
const path = paths[String(pathName)];
|
|
20
|
+
if (!path) {
|
|
21
|
+
throw new Error(`Path "${pathName}" doesn't exist in the OpenAPI document.`);
|
|
22
|
+
}
|
|
23
|
+
const methodName = options.method;
|
|
24
|
+
const method = path[String(methodName)];
|
|
25
|
+
if (!method) {
|
|
26
|
+
throw new Error(`Method "${methodName}" for "${pathName}" path doesn't exist in the OpenAPI document.`);
|
|
27
|
+
}
|
|
28
|
+
const requestBody = method.requestBody;
|
|
29
|
+
if (!requestBody) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let schema = requestBody.content['application/json'].schema;
|
|
33
|
+
if (!schema) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
schema = Object.assign({}, schema);
|
|
37
|
+
schema['$schema'] = 'http://json-schema.org/draft-07/schema';
|
|
38
|
+
if (options.documents && schema.properties) {
|
|
39
|
+
schema.properties = Object.assign({}, schema.properties);
|
|
40
|
+
for (const field of options.documents) {
|
|
41
|
+
if (schema.properties[String(field)].items) {
|
|
42
|
+
schema.properties[String(field)] = Object.assign({}, schema.properties[String(field)]);
|
|
43
|
+
schema.properties[String(field)].items = true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
schema.properties[String(field)] = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return ajvInstance.compile(schema);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function validateRequestBody(validate, body) {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const valid = validate(body);
|
|
56
|
+
const errors = validate.errors && [...validate.errors];
|
|
57
|
+
if (valid === false) {
|
|
58
|
+
throw new problem_exception_1.ProblemException({
|
|
59
|
+
type: 'invalid-request-body',
|
|
60
|
+
title: 'Invalid Request Body',
|
|
61
|
+
status: 422,
|
|
62
|
+
validationErrors: errors,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function validateSingleDocument(asyncapi, path, validationService) {
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (typeof asyncapi === 'object') {
|
|
70
|
+
asyncapi = JSON.stringify(asyncapi);
|
|
71
|
+
}
|
|
72
|
+
const specFile = new SpecificationFile_1.Specification(asyncapi, { fileURL: path });
|
|
73
|
+
return validationService
|
|
74
|
+
.validateDocument(specFile, {
|
|
75
|
+
'fail-severity': 'error',
|
|
76
|
+
suppressAllWarnings: false,
|
|
77
|
+
})
|
|
78
|
+
.then((result) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
if (!result.success || ((_a = result.data) === null || _a === void 0 ? void 0 : _a.status) !== 'valid') {
|
|
81
|
+
throw new problem_exception_1.ProblemException({
|
|
82
|
+
type: 'invalid-asyncapi-document',
|
|
83
|
+
title: 'Invalid AsyncAPI Document',
|
|
84
|
+
status: 422,
|
|
85
|
+
detail: result.error || 'The provided AsyncAPI document is invalid.',
|
|
86
|
+
diagnostics: result.diagnostics || ((_b = result.data) === null || _b === void 0 ? void 0 : _b.diagnostics),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return result.data;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function validateListDocuments(asyncapis, path, validationService) {
|
|
94
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const validationResults = [];
|
|
96
|
+
for (const asyncapi of asyncapis) {
|
|
97
|
+
const parsed = yield validateSingleDocument(asyncapi, path, validationService);
|
|
98
|
+
if (parsed) {
|
|
99
|
+
validationResults.push(parsed);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new problem_exception_1.ProblemException({
|
|
103
|
+
type: 'invalid-asyncapi-document',
|
|
104
|
+
title: 'Invalid AsyncAPI Document',
|
|
105
|
+
status: 422,
|
|
106
|
+
detail: 'One or more provided AsyncAPI documents are invalid.',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return validationResults;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validate RequestBody and sent AsyncAPI document(s) for given path and method based on the OpenAPI Document.
|
|
115
|
+
*/
|
|
116
|
+
function validationMiddleware(options) {
|
|
117
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
options.version = options.version || 'v1';
|
|
119
|
+
const validate = yield compileAjv(options);
|
|
120
|
+
const documents = options.documents || [];
|
|
121
|
+
return (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
var _a;
|
|
123
|
+
// Check if the condition is met
|
|
124
|
+
if (options.condition && !options.condition(req)) {
|
|
125
|
+
return next();
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
if (!validate) {
|
|
129
|
+
throw new problem_exception_1.ProblemException({
|
|
130
|
+
type: 'invalid-request-body',
|
|
131
|
+
title: 'Invalid Request Body',
|
|
132
|
+
status: 422,
|
|
133
|
+
detail: `Request body validation is not supported for "${options.path}" path with "${options.method}" method.`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
yield validateRequestBody(validate, req.body);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof problem_exception_1.ProblemException) {
|
|
140
|
+
return next(error);
|
|
141
|
+
}
|
|
142
|
+
// Handle unexpected errors
|
|
143
|
+
return next(new problem_exception_1.ProblemException({
|
|
144
|
+
type: 'internal-server-error',
|
|
145
|
+
title: 'Internal Server Error',
|
|
146
|
+
status: 500,
|
|
147
|
+
detail: `An unexpected error occurred during request validation: ${(_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error'}`,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
const parserConfig = {
|
|
151
|
+
__unstable: {
|
|
152
|
+
resolver: {
|
|
153
|
+
resolvers: [
|
|
154
|
+
// @TODO: Add Cookie Based Resolvers after migration and understanding some
|
|
155
|
+
// details about how to use them in the new parser-js version.
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
const validationService = new validation_service_1.ValidationService(parserConfig);
|
|
161
|
+
const resolveURL = req.header('x-asyncapi-resolve-url') ||
|
|
162
|
+
req.header('referer') ||
|
|
163
|
+
req.header('origin') ||
|
|
164
|
+
'';
|
|
165
|
+
try {
|
|
166
|
+
req.asyncapi = req.asyncapi || {};
|
|
167
|
+
for (const field of documents) {
|
|
168
|
+
const body = req.body[String(field)];
|
|
169
|
+
if (Array.isArray(body)) {
|
|
170
|
+
const results = yield validateListDocuments(body, resolveURL, validationService);
|
|
171
|
+
const parsedDocuments = results.map((result) => result.document);
|
|
172
|
+
req.asyncapi.parsedDocuments = parsedDocuments;
|
|
173
|
+
req.asyncapi.validationResults = results;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const result = yield validateSingleDocument(body, resolveURL, validationService);
|
|
177
|
+
req.asyncapi.parsedDocument = result === null || result === void 0 ? void 0 : result.document;
|
|
178
|
+
req.asyncapi.validationResult = result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
next();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
return next(err);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const TYPES_400 = [
|
|
190
|
+
'null-or-falsey-document',
|
|
191
|
+
'impossible-to-convert-to-json',
|
|
192
|
+
'invalid-document-type',
|
|
193
|
+
'invalid-json',
|
|
194
|
+
'invalid-yaml',
|
|
195
|
+
];
|
|
196
|
+
/**
|
|
197
|
+
* Some error types have to be treated as 400 HTTP Status Code, another as 422.
|
|
198
|
+
*/
|
|
199
|
+
function retrieveStatusCode(type) {
|
|
200
|
+
if (TYPES_400.includes(type)) {
|
|
201
|
+
return 400;
|
|
202
|
+
}
|
|
203
|
+
return 422;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Merges fields from ParserError to ProblemException.
|
|
207
|
+
*/
|
|
208
|
+
function mergeParserError(error, parserError) {
|
|
209
|
+
if (parserError.detail) {
|
|
210
|
+
error.set('detail', parserError.detail);
|
|
211
|
+
}
|
|
212
|
+
if (parserError.validationErrors) {
|
|
213
|
+
error.set('validationErrors', parserError.validationErrors);
|
|
214
|
+
}
|
|
215
|
+
if (parserError.parsedJSON) {
|
|
216
|
+
error.set('parsedJSON', parserError.parsedJSON);
|
|
217
|
+
}
|
|
218
|
+
if (parserError.location) {
|
|
219
|
+
error.set('location', parserError.location);
|
|
220
|
+
}
|
|
221
|
+
if (parserError.refs) {
|
|
222
|
+
error.set('refs', parserError.refs);
|
|
223
|
+
}
|
|
224
|
+
return error;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
227
|
+
function tryConvertToProblemException(err) {
|
|
228
|
+
const typeName = err.type.replace('https://github.com/asyncapi/parser-js/', '');
|
|
229
|
+
const error = new problem_exception_1.ProblemException({
|
|
230
|
+
type: typeName,
|
|
231
|
+
title: err.title,
|
|
232
|
+
status: retrieveStatusCode(typeName),
|
|
233
|
+
});
|
|
234
|
+
mergeParserError(error, err);
|
|
235
|
+
return error;
|
|
236
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// include configs in the `dist` folder
|
|
5
|
+
require("./configs/production.json");
|
|
6
|
+
require("./configs/development.json");
|
|
7
|
+
require("./configs/test.json");
|
|
8
|
+
// for `config` module
|
|
9
|
+
process.env['NODE_CONFIG_DIR'] = `${__dirname}/configs`;
|
|
10
|
+
const app_1 = require("./app");
|
|
11
|
+
const _1 = require(".");
|
|
12
|
+
function main() {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const app = new app_1.App(_1.CONTROLLERS);
|
|
15
|
+
yield app.init();
|
|
16
|
+
app.listen();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
main();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
5
5
|
const bundler_1 = tslib_1.__importDefault(require("@asyncapi/bundler"));
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
-
const SpecificationFile_1 = require("
|
|
9
|
-
const bundle_flags_1 = require("../
|
|
8
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
9
|
+
const bundle_flags_1 = require("../internal/flags/bundle.flags");
|
|
10
10
|
const { writeFile } = fs_1.promises;
|
|
11
11
|
class Bundle extends base_1.default {
|
|
12
12
|
run() {
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const os_1 = require("os");
|
|
8
|
-
const analytics_flags_1 = require("../../
|
|
8
|
+
const analytics_flags_1 = require("../../internal/flags/config/analytics.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
const { readFile, writeFile } = fs_1.promises;
|
|
11
11
|
class Analytics extends base_1.default {
|
|
12
12
|
run() {
|
|
13
13
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const { flags } = yield this.parse(Analytics);
|
|
15
|
-
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
15
|
+
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
16
|
+
(0, path_1.join)((0, os_1.homedir)(), '.asyncapi-analytics');
|
|
16
17
|
try {
|
|
17
18
|
const analyticsConfigFileContent = JSON.parse(yield readFile((0, path_1.resolve)(analyticsConfigFile), { encoding: 'utf8' }));
|
|
18
19
|
if (flags.disable) {
|