@kaapi/kaapi 0.0.2
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/LICENSE +21 -0
- package/README.md +1 -0
- package/lib/app.d.ts +50 -0
- package/lib/app.js +244 -0
- package/lib/app.js.map +1 -0
- package/lib/baseApp.d.ts +23 -0
- package/lib/baseApp.js +23 -0
- package/lib/baseApp.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/services/docs/SwaggerUiGenerator.d.ts +19 -0
- package/lib/services/docs/SwaggerUiGenerator.js +245 -0
- package/lib/services/docs/SwaggerUiGenerator.js.map +1 -0
- package/lib/services/docs/docs.d.ts +41 -0
- package/lib/services/docs/docs.js +77 -0
- package/lib/services/docs/docs.js.map +1 -0
- package/lib/services/docs/generators.d.ts +16 -0
- package/lib/services/docs/generators.js +173 -0
- package/lib/services/docs/generators.js.map +1 -0
- package/lib/services/docs/ui/swagger-ui.d.ts +21 -0
- package/lib/services/docs/ui/swagger-ui.js +321 -0
- package/lib/services/docs/ui/swagger-ui.js.map +1 -0
- package/lib/services/log.d.ts +13 -0
- package/lib/services/log.js +41 -0
- package/lib/services/log.js.map +1 -0
- package/lib/services/messaging.d.ts +17 -0
- package/lib/services/messaging.js +3 -0
- package/lib/services/messaging.js.map +1 -0
- package/package.json +48 -0
- package/types/overrides.d.ts +11 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _SwaggerUiGenerator_swaggerInit;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SwaggerUiGenerator = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
const absolute_path_1 = tslib_1.__importDefault(require("swagger-ui-dist/absolute-path"));
|
|
8
|
+
const favIconHtml = '<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />' +
|
|
9
|
+
'<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />';
|
|
10
|
+
const stringify = function (obj) {
|
|
11
|
+
const placeholder = '____FUNCTIONPLACEHOLDER____';
|
|
12
|
+
const fns = [];
|
|
13
|
+
let json = JSON.stringify(obj, function (_key, value) {
|
|
14
|
+
if (typeof value === 'function') {
|
|
15
|
+
fns.push(value);
|
|
16
|
+
return placeholder;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}, 2);
|
|
20
|
+
json = json.replace(new RegExp('"' + placeholder + '"', 'g'), function () {
|
|
21
|
+
return fns.shift();
|
|
22
|
+
});
|
|
23
|
+
return 'var options = ' + json + ';';
|
|
24
|
+
};
|
|
25
|
+
const htmlTplString = `
|
|
26
|
+
<!-- HTML for static distribution bundle build -->
|
|
27
|
+
<!DOCTYPE html>
|
|
28
|
+
<html lang="en">
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="UTF-8">
|
|
31
|
+
<% robotsMetaString %>
|
|
32
|
+
<title><% title %></title>
|
|
33
|
+
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
|
34
|
+
<% favIconString %>
|
|
35
|
+
<style>
|
|
36
|
+
html
|
|
37
|
+
{
|
|
38
|
+
box-sizing: border-box;
|
|
39
|
+
overflow: -moz-scrollbars-vertical;
|
|
40
|
+
overflow-y: scroll;
|
|
41
|
+
}
|
|
42
|
+
*,
|
|
43
|
+
*:before,
|
|
44
|
+
*:after
|
|
45
|
+
{
|
|
46
|
+
box-sizing: inherit;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
body {
|
|
50
|
+
margin:0;
|
|
51
|
+
background: #fafafa;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
54
|
+
</head>
|
|
55
|
+
|
|
56
|
+
<body>
|
|
57
|
+
|
|
58
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
|
59
|
+
<defs>
|
|
60
|
+
<symbol viewBox="0 0 20 20" id="unlocked">
|
|
61
|
+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
|
62
|
+
</symbol>
|
|
63
|
+
|
|
64
|
+
<symbol viewBox="0 0 20 20" id="locked">
|
|
65
|
+
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
|
66
|
+
</symbol>
|
|
67
|
+
|
|
68
|
+
<symbol viewBox="0 0 20 20" id="close">
|
|
69
|
+
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
|
70
|
+
</symbol>
|
|
71
|
+
|
|
72
|
+
<symbol viewBox="0 0 20 20" id="large-arrow">
|
|
73
|
+
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
|
74
|
+
</symbol>
|
|
75
|
+
|
|
76
|
+
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
|
77
|
+
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
|
78
|
+
</symbol>
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
<symbol viewBox="0 0 24 24" id="jump-to">
|
|
82
|
+
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
|
83
|
+
</symbol>
|
|
84
|
+
|
|
85
|
+
<symbol viewBox="0 0 24 24" id="expand">
|
|
86
|
+
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
|
87
|
+
</symbol>
|
|
88
|
+
|
|
89
|
+
</defs>
|
|
90
|
+
</svg>
|
|
91
|
+
|
|
92
|
+
<div id="swagger-ui"></div>
|
|
93
|
+
|
|
94
|
+
<script src="./swagger-ui-bundle.js"> </script>
|
|
95
|
+
<script src="./swagger-ui-standalone-preset.js"> </script>
|
|
96
|
+
<script src="./swagger-ui-init.js"> </script>
|
|
97
|
+
<% customJs %>
|
|
98
|
+
<% customJsStr %>
|
|
99
|
+
<% customCssUrl %>
|
|
100
|
+
<style>
|
|
101
|
+
<% customCss %>
|
|
102
|
+
</style>
|
|
103
|
+
</body>
|
|
104
|
+
|
|
105
|
+
</html>
|
|
106
|
+
`;
|
|
107
|
+
const jsTplString = `
|
|
108
|
+
window.onload = function() {
|
|
109
|
+
// Build a system
|
|
110
|
+
var url = window.location.search.match(/url=([^&]+)/);
|
|
111
|
+
if (url && url.length > 1) {
|
|
112
|
+
url = decodeURIComponent(url[1]);
|
|
113
|
+
} else {
|
|
114
|
+
url = window.location.origin;
|
|
115
|
+
}
|
|
116
|
+
<% swaggerOptions %>
|
|
117
|
+
url = options.swaggerUrl || url
|
|
118
|
+
var urls = options.swaggerUrls
|
|
119
|
+
var customOptions = options.customOptions
|
|
120
|
+
var spec1 = options.swaggerDoc
|
|
121
|
+
var swaggerOptions = {
|
|
122
|
+
spec: spec1,
|
|
123
|
+
url: url,
|
|
124
|
+
urls: urls,
|
|
125
|
+
dom_id: '#swagger-ui',
|
|
126
|
+
deepLinking: true,
|
|
127
|
+
presets: [
|
|
128
|
+
SwaggerUIBundle.presets.apis,
|
|
129
|
+
SwaggerUIStandalonePreset
|
|
130
|
+
],
|
|
131
|
+
plugins: [
|
|
132
|
+
SwaggerUIBundle.plugins.DownloadUrl
|
|
133
|
+
],
|
|
134
|
+
layout: "StandaloneLayout"
|
|
135
|
+
}
|
|
136
|
+
for (var attrname in customOptions) {
|
|
137
|
+
swaggerOptions[attrname] = customOptions[attrname];
|
|
138
|
+
}
|
|
139
|
+
var ui = SwaggerUIBundle(swaggerOptions)
|
|
140
|
+
|
|
141
|
+
if (customOptions.oauth) {
|
|
142
|
+
ui.initOAuth(customOptions.oauth)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (customOptions.preauthorizeApiKey) {
|
|
146
|
+
const key = customOptions.preauthorizeApiKey.authDefinitionKey;
|
|
147
|
+
const value = customOptions.preauthorizeApiKey.apiKeyValue;
|
|
148
|
+
if (!!key && !!value) {
|
|
149
|
+
const pid = setInterval(() => {
|
|
150
|
+
const authorized = ui.preauthorizeApiKey(key, value);
|
|
151
|
+
if(!!authorized) clearInterval(pid);
|
|
152
|
+
}, 500)
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (customOptions.authAction) {
|
|
158
|
+
ui.authActions.authorize(customOptions.authAction)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
window.ui = ui
|
|
162
|
+
}
|
|
163
|
+
`;
|
|
164
|
+
function toExternalScriptTag(url) {
|
|
165
|
+
return `<script src='${url}'></script>`;
|
|
166
|
+
}
|
|
167
|
+
function toInlineScriptTag(jsCode) {
|
|
168
|
+
return `<script>${jsCode}</script>`;
|
|
169
|
+
}
|
|
170
|
+
function toExternalStylesheetTag(url) {
|
|
171
|
+
return `<link href='${url}' rel='stylesheet'>`;
|
|
172
|
+
}
|
|
173
|
+
function toTags(customCode, toScript) {
|
|
174
|
+
if (typeof customCode === 'string') {
|
|
175
|
+
return toScript(customCode);
|
|
176
|
+
}
|
|
177
|
+
else if (Array.isArray(customCode)) {
|
|
178
|
+
return customCode.map(toScript).join('\n');
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return '';
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
class SwaggerUiGenerator {
|
|
185
|
+
constructor() {
|
|
186
|
+
_SwaggerUiGenerator_swaggerInit.set(this, '');
|
|
187
|
+
}
|
|
188
|
+
get swaggerInit() {
|
|
189
|
+
return tslib_1.__classPrivateFieldGet(this, _SwaggerUiGenerator_swaggerInit, "f");
|
|
190
|
+
}
|
|
191
|
+
getAbsoluteSwaggerFsPath() {
|
|
192
|
+
return (0, absolute_path_1.default)();
|
|
193
|
+
}
|
|
194
|
+
generateHTML(swaggerDoc, opts, options, customCss, customfavIcon, swaggerUrl, customSiteTitle, _htmlTplString, _jsTplString) {
|
|
195
|
+
let isExplorer;
|
|
196
|
+
let customJs;
|
|
197
|
+
let customJsStr;
|
|
198
|
+
let swaggerUrls;
|
|
199
|
+
let customCssUrl;
|
|
200
|
+
let customRobots;
|
|
201
|
+
if (opts && typeof opts === 'object') {
|
|
202
|
+
options = opts.swaggerOptions;
|
|
203
|
+
customCss = opts.customCss;
|
|
204
|
+
customJs = opts.customJs;
|
|
205
|
+
customJsStr = opts.customJsStr;
|
|
206
|
+
customfavIcon = opts.customfavIcon;
|
|
207
|
+
customRobots = opts.customRobots;
|
|
208
|
+
swaggerUrl = opts.swaggerUrl;
|
|
209
|
+
swaggerUrls = opts.swaggerUrls;
|
|
210
|
+
isExplorer = opts.explorer || !!swaggerUrls;
|
|
211
|
+
customSiteTitle = opts.customSiteTitle;
|
|
212
|
+
customCssUrl = opts.customCssUrl;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
//support legacy params based function
|
|
216
|
+
isExplorer = opts;
|
|
217
|
+
}
|
|
218
|
+
options = options || {};
|
|
219
|
+
const explorerString = isExplorer ? '' : '.swagger-ui .topbar .download-url-wrapper { display: none }';
|
|
220
|
+
customCss = explorerString + ' ' + customCss || explorerString;
|
|
221
|
+
customfavIcon = customfavIcon || false;
|
|
222
|
+
customSiteTitle = customSiteTitle || 'Swagger UI';
|
|
223
|
+
_htmlTplString = _htmlTplString || htmlTplString;
|
|
224
|
+
_jsTplString = _jsTplString || jsTplString;
|
|
225
|
+
const robotsMetaString = customRobots ? '<meta name="robots" content="' + customRobots + '" />' : '';
|
|
226
|
+
const favIconString = customfavIcon ? '<link rel="icon" href="' + customfavIcon + '" />' : favIconHtml;
|
|
227
|
+
const htmlWithCustomCss = _htmlTplString.toString().replace('<% customCss %>', customCss);
|
|
228
|
+
const htmlWithCustomRobots = htmlWithCustomCss.replace('<% robotsMetaString %>', robotsMetaString);
|
|
229
|
+
const htmlWithFavIcon = htmlWithCustomRobots.replace('<% favIconString %>', favIconString);
|
|
230
|
+
const htmlWithCustomJsUrl = htmlWithFavIcon.replace('<% customJs %>', toTags(customJs, toExternalScriptTag));
|
|
231
|
+
const htmlWithCustomJs = htmlWithCustomJsUrl.replace('<% customJsStr %>', toTags(customJsStr, toInlineScriptTag));
|
|
232
|
+
const htmlWithCustomCssUrl = htmlWithCustomJs.replace('<% customCssUrl %>', toTags(customCssUrl, toExternalStylesheetTag));
|
|
233
|
+
const initOptions = {
|
|
234
|
+
swaggerDoc: swaggerDoc || undefined,
|
|
235
|
+
customOptions: options,
|
|
236
|
+
swaggerUrl: swaggerUrl || undefined,
|
|
237
|
+
swaggerUrls: swaggerUrls || undefined
|
|
238
|
+
};
|
|
239
|
+
tslib_1.__classPrivateFieldSet(this, _SwaggerUiGenerator_swaggerInit, _jsTplString.toString().replace('<% swaggerOptions %>', stringify(initOptions)), "f");
|
|
240
|
+
return htmlWithCustomCssUrl.replace('<% title %>', customSiteTitle);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.SwaggerUiGenerator = SwaggerUiGenerator;
|
|
244
|
+
_SwaggerUiGenerator_swaggerInit = new WeakMap();
|
|
245
|
+
//# sourceMappingURL=SwaggerUiGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwaggerUiGenerator.js","sourceRoot":"","sources":["../../../src/services/docs/SwaggerUiGenerator.ts"],"names":[],"mappings":";;;;;AAAA,uDAAuD;AACvD,0FAAoE;AAEpE,MAAM,WAAW,GAAG,+EAA+E;IAC/F,+EAA+E,CAAA;AAEnF,MAAM,SAAS,GAAG,UAAU,GAAQ;IAChC,MAAM,WAAW,GAAG,6BAA6B,CAAA;IACjD,MAAM,GAAG,GAAU,EAAE,CAAA;IACrB,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,IAAI,EAAE,KAAK;QAChD,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;YAC9B,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACf,OAAO,WAAW,CAAA;QACtB,CAAC;QACD,OAAO,KAAK,CAAA;IAChB,CAAC,EAAE,CAAC,CAAC,CAAA;IACL,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,WAAW,GAAG,GAAG,EAAE,GAAG,CAAC,EAAE;QAC1D,OAAO,GAAG,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC,CAAC,CAAA;IACF,OAAO,gBAAgB,GAAG,IAAI,GAAG,GAAG,CAAA;AACxC,CAAC,CAAA;AAED,MAAM,aAAa,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AAyB,GAAG,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,WAAW,CAAA;QACtG,MAAM,iBAAiB,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAA;QACzF,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,OAAO,CAAC,wBAAwB,EAAE,gBAAgB,CAAC,CAAA;QAClG,MAAM,eAAe,GAAG,oBAAoB,CAAC,OAAO,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAA;QAC1F,MAAM,mBAAmB,GAAG,eAAe,CAAC,OAAO,CAAC,gBAAgB,EAAE,MAAM,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC,CAAA;QAC5G,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAA;QACjH,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,OAAO,CAAC,oBAAoB,EAAE,MAAM,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAC,CAAA;QAE1H,MAAM,WAAW,GAAG;YAChB,UAAU,EAAE,UAAU,IAAI,SAAS;YACnC,aAAa,EAAE,OAAO;YACtB,UAAU,EAAE,UAAU,IAAI,SAAS;YACnC,WAAW,EAAE,WAAW,IAAI,SAAS;SACxC,CAAA;QAED,+BAAA,IAAI,mCAAgB,YAAY,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,sBAAsB,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC,MAAA,CAAA;QACnG,OAAO,oBAAoB,CAAC,OAAO,CAAC,aAAa,EAAE,eAAe,CAAC,CAAA;IACvE,CAAC;CACJ;AAzED,gDAyEC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ExampleObject, LicenseObject, ReferenceObject, SchemaObject, ServerObject, TagObject } from '@novice1/api-doc-generator/lib/generators/openapi/definitions';
|
|
2
|
+
import { Folder } from '@novice1/api-doc-generator/lib/generators/postman/definitions';
|
|
3
|
+
import { BaseAuthUtil } from '@novice1/api-doc-generator/lib/utils/auth/baseAuthUtils';
|
|
4
|
+
import { BaseResponseUtil } from '@novice1/api-doc-generator/lib/utils/responses/baseResponseUtils';
|
|
5
|
+
import { OpenAPIOptions, Postman, PostmanOptions } from '@novice1/api-doc-generator';
|
|
6
|
+
import { SwaggerUiOptions } from './SwaggerUiGenerator';
|
|
7
|
+
import { KaapiOpenAPI } from './generators';
|
|
8
|
+
import { HandlerDecorations, Lifecycle, ReqRef, ReqRefDefaults } from '@hapi/hapi';
|
|
9
|
+
import { KaapiServerRoute } from '@kaapi/server';
|
|
10
|
+
export type DocsTag = TagObject & Omit<Folder, 'item'>;
|
|
11
|
+
export type DocsSwaggerUIOptions = Omit<Omit<SwaggerUiOptions, 'swaggerUrl'>, 'swaggerUrls'>;
|
|
12
|
+
export interface DocsOptions {
|
|
13
|
+
swagger?: DocsSwaggerUIOptions;
|
|
14
|
+
}
|
|
15
|
+
export interface DocsConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Disable docs routes.
|
|
18
|
+
*/
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
path?: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
consumes?: string[];
|
|
23
|
+
security?: BaseAuthUtil;
|
|
24
|
+
license?: LicenseObject | string;
|
|
25
|
+
version?: string;
|
|
26
|
+
host?: ServerObject;
|
|
27
|
+
examples?: Record<string, ReferenceObject | ExampleObject>;
|
|
28
|
+
schemas?: Record<string, SchemaObject | ReferenceObject>;
|
|
29
|
+
responses?: BaseResponseUtil;
|
|
30
|
+
tags?: DocsTag[];
|
|
31
|
+
options?: DocsOptions;
|
|
32
|
+
openAPIOptions?: OpenAPIOptions;
|
|
33
|
+
postmanOptions?: PostmanOptions;
|
|
34
|
+
}
|
|
35
|
+
export declare function createDocsRouter<Refs extends ReqRef = ReqRefDefaults>(path: string, { openapi, postman }: {
|
|
36
|
+
openapi: KaapiOpenAPI;
|
|
37
|
+
postman: Postman;
|
|
38
|
+
}, options?: DocsOptions): [
|
|
39
|
+
route: KaapiServerRoute<Refs>,
|
|
40
|
+
handler: HandlerDecorations | Lifecycle.Method<Refs, Lifecycle.ReturnValue<Refs>>
|
|
41
|
+
];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDocsRouter = createDocsRouter;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const SwaggerUiGenerator_1 = require("./SwaggerUiGenerator");
|
|
6
|
+
const boom_1 = tslib_1.__importDefault(require("@hapi/boom"));
|
|
7
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
8
|
+
const bootTime = Date.now();
|
|
9
|
+
function trimQuery(q) {
|
|
10
|
+
return q && q.split('?')[0];
|
|
11
|
+
}
|
|
12
|
+
function createDocsRouter(path, { openapi, postman }, options) {
|
|
13
|
+
const lastSlashPos = path.lastIndexOf('/');
|
|
14
|
+
const prefix = path.substring(0, lastSlashPos || path.length);
|
|
15
|
+
const ui = new SwaggerUiGenerator_1.SwaggerUiGenerator();
|
|
16
|
+
return [
|
|
17
|
+
{
|
|
18
|
+
path: `${prefix}/{any*}`,
|
|
19
|
+
method: '*'
|
|
20
|
+
},
|
|
21
|
+
(req, h) => {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
|
+
if (req.url.pathname == path) {
|
|
24
|
+
const html = ui.generateHTML(openapi.result(), options === null || options === void 0 ? void 0 : options.swagger, (_a = options === null || options === void 0 ? void 0 : options.swagger) === null || _a === void 0 ? void 0 : _a.swaggerOptions, (_b = options === null || options === void 0 ? void 0 : options.swagger) === null || _b === void 0 ? void 0 : _b.customCss, (_c = options === null || options === void 0 ? void 0 : options.swagger) === null || _c === void 0 ? void 0 : _c.customfavIcon, null, (_d = options === null || options === void 0 ? void 0 : options.swagger) === null || _d === void 0 ? void 0 : _d.customSiteTitle);
|
|
25
|
+
return h.response(html).header('Content-Type', 'text/html');
|
|
26
|
+
}
|
|
27
|
+
else if (req.url.pathname == `${path}${path.endsWith('/') ? '' : '/'}schema`) {
|
|
28
|
+
if (req.query &&
|
|
29
|
+
typeof req.query === 'object' &&
|
|
30
|
+
'format' in req.query &&
|
|
31
|
+
req.query.format == 'postman') {
|
|
32
|
+
return postman.result();
|
|
33
|
+
}
|
|
34
|
+
return openapi.result();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (trimQuery(req.url.pathname).endsWith('/package.json')) {
|
|
38
|
+
return boom_1.default.notFound();
|
|
39
|
+
}
|
|
40
|
+
else if (trimQuery(req.url.pathname).endsWith('/swagger-ui-init.js')) {
|
|
41
|
+
return h.response(ui.swaggerInit).header('Content-Type', 'application/javascript');
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const cacheDuration = 24 * 60 * 60 * 1000; // ms
|
|
45
|
+
const posFileName = trimQuery(req.url.pathname).lastIndexOf('/');
|
|
46
|
+
let filepath = '';
|
|
47
|
+
const swaggerUiFile = ui.getAbsoluteSwaggerFsPath()
|
|
48
|
+
+ trimQuery(req.url.pathname).substring(posFileName > -1 ? posFileName : 0);
|
|
49
|
+
if (node_fs_1.default.existsSync(swaggerUiFile)) {
|
|
50
|
+
filepath = swaggerUiFile;
|
|
51
|
+
}
|
|
52
|
+
if (filepath) {
|
|
53
|
+
let readStreamOptions = { encoding: 'utf-8' };
|
|
54
|
+
let cT = 'application/octet-stream';
|
|
55
|
+
if (filepath.endsWith('.js')) {
|
|
56
|
+
cT = 'application/javascript';
|
|
57
|
+
}
|
|
58
|
+
else if (filepath.endsWith('.css')) {
|
|
59
|
+
cT = 'text/css';
|
|
60
|
+
}
|
|
61
|
+
else if (filepath.endsWith('.png')) {
|
|
62
|
+
readStreamOptions = {};
|
|
63
|
+
cT = 'image/png';
|
|
64
|
+
}
|
|
65
|
+
return h.response(node_fs_1.default.createReadStream(filepath, readStreamOptions))
|
|
66
|
+
.ttl(cacheDuration).header('Last-Modified', (new Date(bootTime)).toUTCString()).header('Content-Type', cT);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.error(e);
|
|
71
|
+
}
|
|
72
|
+
return boom_1.default.notFound();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=docs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../src/services/docs/docs.ts"],"names":[],"mappings":";;AAuDA,4CAoFC;;AA/HD,6DAA2E;AAI3E,8DAA6B;AAC7B,8DAAwB;AAExB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE5B,SAAS,SAAS,CAAC,CAAS;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AAC/B,CAAC;AAgCD,SAAgB,gBAAgB,CAC5B,IAAY,EACZ,EAAE,OAAO,EAAE,OAAO,EAA+C,EACjE,OAAqB;IAKrB,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC,CAAA;IAE7D,MAAM,EAAE,GAAG,IAAI,uCAAkB,EAAE,CAAA;IAEnC,OAAO;QACH;YACI,IAAI,EAAE,GAAG,MAAM,SAAS;YACxB,MAAM,EAAE,GAAG;SACd;QACD,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;;YACP,IAAI,GAAG,CAAC,GAAG,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;gBAC3B,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CACxB,OAAO,CAAC,MAAM,EAAE,EAChB,OAAO,aAAP,OAA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EAAE,iBAAiB,CAAC,CAAC;6BAC9D,GAAG,CAAC,aAAa,CAAC,CAAC,MAAM,CACtB,eAAe,EACf,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CACrC,CAAC,MAAM,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;oBACrC,CAAC;gBACL,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;gBACpB,CAAC;gBAED,OAAO,cAAI,CAAC,QAAQ,EAAE,CAAA;YAC1B,CAAC;QACL,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OpenAPI, Postman, ProcessedRoute } from '@novice1/api-doc-generator';
|
|
2
|
+
import { KaapiServerRoute } from '@kaapi/server';
|
|
3
|
+
import { ReqRef, ReqRefDefaults, RequestRoute } from '@hapi/hapi';
|
|
4
|
+
export interface KaapiDocGenerator {
|
|
5
|
+
addRoutes<Refs extends ReqRef = ReqRefDefaults>(serverRoute: KaapiServerRoute<Refs>): ProcessedRoute[];
|
|
6
|
+
addRoutes<Refs extends ReqRef = ReqRefDefaults>(serverRoutes: KaapiServerRoute<Refs>[]): ProcessedRoute[];
|
|
7
|
+
addRequestRoute<Refs extends ReqRef = ReqRefDefaults>(serverRoute: RequestRoute<Refs>): ProcessedRoute[];
|
|
8
|
+
}
|
|
9
|
+
export declare class KaapiOpenAPI extends OpenAPI implements KaapiDocGenerator {
|
|
10
|
+
addRoutes<Refs extends ReqRef = ReqRefDefaults>(serverRoutes: KaapiServerRoute<Refs>[] | KaapiServerRoute<Refs>): ProcessedRoute[];
|
|
11
|
+
addRequestRoute<Refs extends ReqRef = ReqRefDefaults>(reqRoute: RequestRoute<Refs>): ProcessedRoute[];
|
|
12
|
+
}
|
|
13
|
+
export declare class KaapiPostman extends Postman implements KaapiDocGenerator {
|
|
14
|
+
addRoutes<Refs extends ReqRef = ReqRefDefaults>(serverRoutes: KaapiServerRoute<Refs>[] | KaapiServerRoute<Refs>): ProcessedRoute[];
|
|
15
|
+
addRequestRoute<Refs extends ReqRef = ReqRefDefaults>(reqRoute: RequestRoute<Refs>): ProcessedRoute[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KaapiPostman = exports.KaapiOpenAPI = void 0;
|
|
4
|
+
const api_doc_generator_1 = require("@novice1/api-doc-generator");
|
|
5
|
+
const joiHelper_1 = require("@novice1/api-doc-generator/lib/generators/openapi/helpers/joiHelper");
|
|
6
|
+
class CustomHelper extends joiHelper_1.OpenAPIJoiHelper {
|
|
7
|
+
isFile() {
|
|
8
|
+
return this._joi['$_terms']
|
|
9
|
+
&& Array.isArray(this._joi['$_terms'].tags)
|
|
10
|
+
&& this._joi['$_terms'].tags.includes('files');
|
|
11
|
+
}
|
|
12
|
+
getRawSchema() {
|
|
13
|
+
return this._joi;
|
|
14
|
+
}
|
|
15
|
+
getFilesChildren() {
|
|
16
|
+
const r = {};
|
|
17
|
+
if (!this.isJoi()) {
|
|
18
|
+
return r;
|
|
19
|
+
}
|
|
20
|
+
if (this._joi.$_terms
|
|
21
|
+
&& this._joi.$_terms.keys && this._joi.$_terms.keys.length) {
|
|
22
|
+
this._joi.$_terms.keys.forEach((c) => {
|
|
23
|
+
const ch = new CustomHelper({ value: c.schema });
|
|
24
|
+
if (ch.isValid() && ch.isFile())
|
|
25
|
+
r[c.key] = ch.getRawSchema();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return r;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function formatRoutes(serverRoutes) {
|
|
32
|
+
let sRoutes = [];
|
|
33
|
+
if (Array.isArray(serverRoutes)) {
|
|
34
|
+
sRoutes = serverRoutes;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
sRoutes = [serverRoutes];
|
|
38
|
+
}
|
|
39
|
+
const routes = [];
|
|
40
|
+
sRoutes.forEach(sRoute => {
|
|
41
|
+
var _a, _b, _c, _d, _e;
|
|
42
|
+
// only string paths
|
|
43
|
+
if (typeof sRoute.path != 'string')
|
|
44
|
+
return;
|
|
45
|
+
if (!sRoute.path)
|
|
46
|
+
return;
|
|
47
|
+
const path = sRoute.path;
|
|
48
|
+
// require methods
|
|
49
|
+
if (!sRoute.method)
|
|
50
|
+
return;
|
|
51
|
+
if (sRoute.options &&
|
|
52
|
+
typeof sRoute.options === 'object' &&
|
|
53
|
+
(((_b = (_a = sRoute.options.plugins) === null || _a === void 0 ? void 0 : _a.kaapi) === null || _b === void 0 ? void 0 : _b.docs) === false || ((_e = (_d = (_c = sRoute.options.plugins) === null || _c === void 0 ? void 0 : _c.kaapi) === null || _d === void 0 ? void 0 : _d.docs) === null || _e === void 0 ? void 0 : _e.disabled))) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let methods = [];
|
|
57
|
+
if (Array.isArray(sRoute.method)) {
|
|
58
|
+
methods = sRoute.method;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
methods = [sRoute.method];
|
|
62
|
+
}
|
|
63
|
+
const formattedRoutes = methods.map(method => {
|
|
64
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
65
|
+
const route = {
|
|
66
|
+
methods: {
|
|
67
|
+
[method.toLowerCase()]: true
|
|
68
|
+
},
|
|
69
|
+
path: path,
|
|
70
|
+
auth: sRoute.auth || false,
|
|
71
|
+
//responses: sRoute.responses
|
|
72
|
+
};
|
|
73
|
+
if (typeof sRoute.options != 'function') {
|
|
74
|
+
route.tags = (_a = sRoute.options) === null || _a === void 0 ? void 0 : _a.tags;
|
|
75
|
+
route.description = (_b = sRoute.options) === null || _b === void 0 ? void 0 : _b.description;
|
|
76
|
+
let files = undefined;
|
|
77
|
+
if (((_c = sRoute.options) === null || _c === void 0 ? void 0 : _c.payload) && typeof ((_e = (_d = sRoute.options) === null || _d === void 0 ? void 0 : _d.validate) === null || _e === void 0 ? void 0 : _e.payload) === 'object') {
|
|
78
|
+
const helper = new CustomHelper({ value: sRoute.options.validate.payload });
|
|
79
|
+
if (helper.isValid() && helper.getType() === 'object') {
|
|
80
|
+
files = helper.getFilesChildren();
|
|
81
|
+
if (files && !Object.keys(files).length) {
|
|
82
|
+
files = undefined;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
route.parameters = ((_f = sRoute.options) === null || _f === void 0 ? void 0 : _f.validate) ? Object.assign(Object.assign({}, (_g = sRoute.options) === null || _g === void 0 ? void 0 : _g.validate), { body: (_h = sRoute.options) === null || _h === void 0 ? void 0 : _h.validate.payload, files: files }) : undefined;
|
|
87
|
+
if (route.parameters && ((_k = (_j = sRoute.options) === null || _j === void 0 ? void 0 : _j.payload) === null || _k === void 0 ? void 0 : _k.allow)) {
|
|
88
|
+
route.parameters.consumes = Array.isArray(sRoute.options.payload.allow) ? sRoute.options.payload.allow : [sRoute.options.payload.allow];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return route;
|
|
92
|
+
});
|
|
93
|
+
routes.push(...formattedRoutes);
|
|
94
|
+
});
|
|
95
|
+
return routes;
|
|
96
|
+
}
|
|
97
|
+
function formatRequestRoute(reqRoute) {
|
|
98
|
+
var _a, _b, _c, _d, _e;
|
|
99
|
+
const sRoute = reqRoute;
|
|
100
|
+
const routes = [];
|
|
101
|
+
// only string paths
|
|
102
|
+
if (typeof sRoute.path != 'string')
|
|
103
|
+
return routes;
|
|
104
|
+
if (!sRoute.path)
|
|
105
|
+
return routes;
|
|
106
|
+
const path = sRoute.path;
|
|
107
|
+
// require methods
|
|
108
|
+
if (!sRoute.method)
|
|
109
|
+
return routes;
|
|
110
|
+
if (sRoute.settings &&
|
|
111
|
+
typeof sRoute.settings === 'object' &&
|
|
112
|
+
(((_b = (_a = sRoute.settings.plugins) === null || _a === void 0 ? void 0 : _a.kaapi) === null || _b === void 0 ? void 0 : _b.docs) === false || ((_e = (_d = (_c = sRoute.settings.plugins) === null || _c === void 0 ? void 0 : _c.kaapi) === null || _d === void 0 ? void 0 : _d.docs) === null || _e === void 0 ? void 0 : _e.disabled))) {
|
|
113
|
+
return routes;
|
|
114
|
+
}
|
|
115
|
+
let methods = [];
|
|
116
|
+
if (Array.isArray(sRoute.method)) {
|
|
117
|
+
methods = sRoute.method;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
methods = [sRoute.method];
|
|
121
|
+
}
|
|
122
|
+
const formattedRoutes = methods.map(method => {
|
|
123
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
124
|
+
const route = {
|
|
125
|
+
methods: {
|
|
126
|
+
[method.toLowerCase()]: true
|
|
127
|
+
},
|
|
128
|
+
path: path,
|
|
129
|
+
auth: !!((_a = sRoute.settings.auth) === null || _a === void 0 ? void 0 : _a.mode),
|
|
130
|
+
//responses: sRoute.responses
|
|
131
|
+
};
|
|
132
|
+
if (typeof sRoute.settings != 'function') {
|
|
133
|
+
route.tags = (_b = sRoute.settings) === null || _b === void 0 ? void 0 : _b.tags;
|
|
134
|
+
route.description = (_c = sRoute.settings) === null || _c === void 0 ? void 0 : _c.description;
|
|
135
|
+
let files = undefined;
|
|
136
|
+
if (((_d = sRoute.settings) === null || _d === void 0 ? void 0 : _d.payload) && typeof ((_f = (_e = sRoute.settings) === null || _e === void 0 ? void 0 : _e.validate) === null || _f === void 0 ? void 0 : _f.payload) === 'object') {
|
|
137
|
+
const helper = new CustomHelper({ value: sRoute.settings.validate.payload });
|
|
138
|
+
if (helper.isValid() && helper.getType() === 'object') {
|
|
139
|
+
files = helper.getFilesChildren();
|
|
140
|
+
if (files && !Object.keys(files).length) {
|
|
141
|
+
files = undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
route.parameters = ((_g = sRoute.settings) === null || _g === void 0 ? void 0 : _g.validate) ? Object.assign(Object.assign({}, (_h = sRoute.settings) === null || _h === void 0 ? void 0 : _h.validate), { body: (_j = sRoute.settings) === null || _j === void 0 ? void 0 : _j.validate.payload, files: files }) : undefined;
|
|
146
|
+
if (route.parameters && ((_l = (_k = sRoute.settings) === null || _k === void 0 ? void 0 : _k.payload) === null || _l === void 0 ? void 0 : _l.allow)) {
|
|
147
|
+
route.parameters.consumes = Array.isArray(sRoute.settings.payload.allow) ? sRoute.settings.payload.allow : [sRoute.settings.payload.allow];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return route;
|
|
151
|
+
});
|
|
152
|
+
routes.push(...formattedRoutes);
|
|
153
|
+
return routes;
|
|
154
|
+
}
|
|
155
|
+
class KaapiOpenAPI extends api_doc_generator_1.OpenAPI {
|
|
156
|
+
addRoutes(serverRoutes) {
|
|
157
|
+
return super.add(formatRoutes(serverRoutes));
|
|
158
|
+
}
|
|
159
|
+
addRequestRoute(reqRoute) {
|
|
160
|
+
return super.add(formatRequestRoute(reqRoute));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.KaapiOpenAPI = KaapiOpenAPI;
|
|
164
|
+
class KaapiPostman extends api_doc_generator_1.Postman {
|
|
165
|
+
addRoutes(serverRoutes) {
|
|
166
|
+
return super.add(formatRoutes(serverRoutes));
|
|
167
|
+
}
|
|
168
|
+
addRequestRoute(reqRoute) {
|
|
169
|
+
return super.add(formatRequestRoute(reqRoute));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.KaapiPostman = KaapiPostman;
|
|
173
|
+
//# sourceMappingURL=generators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../../../src/services/docs/generators.ts"],"names":[],"mappings":";;;AAAA,kEAA8E;AAC9E,mGAAuG;AAMvG,MAAM,YAAa,SAAQ,4BAAgB;IACvC,MAAM;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,SAA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AAC,GAAG,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAA;IAClD,CAAC;CACJ;AARD,oCAQC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SwaggerUiOptions {
|
|
2
|
+
swaggerOptions: any;
|
|
3
|
+
customCss: string | string[];
|
|
4
|
+
customJs: string | string[];
|
|
5
|
+
customJsStr: string | string[];
|
|
6
|
+
customfavIcon: string;
|
|
7
|
+
customRobots: string;
|
|
8
|
+
swaggerUrl: any;
|
|
9
|
+
swaggerUrls: any;
|
|
10
|
+
explorer: boolean;
|
|
11
|
+
customSiteTitle: string;
|
|
12
|
+
customCssUrl: string | string[];
|
|
13
|
+
}
|
|
14
|
+
export declare let swaggerInit: string;
|
|
15
|
+
export declare function trimQuery(q: string): string;
|
|
16
|
+
export declare const generateHTML: (swaggerDoc: any, opts: any, options?: any, customCss?: any, customfavIcon?: any, swaggerUrl?: any, customSiteTitle?: any, _htmlTplString?: any, _jsTplString?: any) => any;
|
|
17
|
+
export declare const swaggerUi: {
|
|
18
|
+
createHandler: (path: string, generateSchema: (req?: any) => any, opts?: SwaggerUiOptions) => (req: any, res: any) => void;
|
|
19
|
+
handle: (req: any, res: any, config?: any) => boolean;
|
|
20
|
+
setup: (swaggerDoc: any, opts?: any, options?: any, customCss?: any, customfavIcon?: any, swaggerUrl?: any, customSiteTitle?: any) => (req: any, res: any) => void;
|
|
21
|
+
};
|