@kaapi/kaapi 0.0.12 → 0.0.14
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 +4 -0
- package/lib/abstract-app.d.ts +23 -0
- package/lib/abstract-app.js +23 -0
- package/lib/abstract-app.js.map +1 -0
- package/lib/app.d.ts +17 -11
- package/lib/app.js +41 -44
- package/lib/app.js.map +1 -1
- package/lib/base-app.d.ts +23 -0
- package/lib/base-app.js +23 -0
- package/lib/base-app.js.map +1 -0
- package/lib/baseApp.js +1 -1
- package/lib/baseApp.js.map +1 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/services/docs/docs.d.ts +4 -4
- package/lib/services/docs/docs.js +2 -2
- package/lib/services/docs/docs.js.map +1 -1
- package/lib/services/docs/generators.js +14 -3
- package/lib/services/docs/generators.js.map +1 -1
- package/lib/services/docs/swagger-ui-generator.d.ts +19 -0
- package/lib/services/docs/swagger-ui-generator.js +245 -0
- package/lib/services/docs/swagger-ui-generator.js.map +1 -0
- package/lib/services/docs/utils.d.ts +15 -0
- package/lib/services/docs/utils.js +41 -0
- package/lib/services/docs/utils.js.map +1 -0
- package/lib/services/log.js +1 -1
- package/lib/services/log.js.map +1 -1
- package/lib/services/plugin.d.ts +27 -1
- package/lib/services/plugin.js +55 -2
- package/lib/services/plugin.js.map +1 -1
- package/lib/services/plugins/auth-designs/api-key-auth-design.d.ts +42 -0
- package/lib/services/plugins/auth-designs/api-key-auth-design.js +116 -0
- package/lib/services/plugins/auth-designs/api-key-auth-design.js.map +1 -0
- package/lib/services/plugins/auth-designs/basic-auth-design.d.ts +29 -0
- package/lib/services/plugins/auth-designs/basic-auth-design.js +88 -0
- package/lib/services/plugins/auth-designs/basic-auth-design.js.map +1 -0
- package/lib/services/plugins/auth-designs/bearer-auth-design.d.ts +29 -0
- package/lib/services/plugins/auth-designs/bearer-auth-design.js +87 -0
- package/lib/services/plugins/auth-designs/bearer-auth-design.js.map +1 -0
- package/lib/services/plugins/plugin.d.ts +88 -0
- package/lib/services/plugins/plugin.js +86 -0
- package/lib/services/plugins/plugin.js.map +1 -0
- package/package.json +3 -3
- package/types/overrides.d.ts +3 -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=swagger-ui-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-ui-generator.js","sourceRoot":"","sources":["../../../src/services/docs/swagger-ui-generator.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,GAA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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,15 @@
|
|
|
1
|
+
import { GroupAuthUtil, OAuth2Util } from '@novice1/api-doc-generator';
|
|
2
|
+
import { BaseAuthUtil } from '@novice1/api-doc-generator/lib/utils/auth/baseAuthUtils';
|
|
3
|
+
/**
|
|
4
|
+
* Special class to group multiple security schemes
|
|
5
|
+
*/
|
|
6
|
+
export declare class KaapiGroupAuthUtil extends OAuth2Util {
|
|
7
|
+
protected authUtils: BaseAuthUtil[];
|
|
8
|
+
protected groupAuth: GroupAuthUtil;
|
|
9
|
+
constructor(authUtils: BaseAuthUtil[]);
|
|
10
|
+
setHost(host: string): this;
|
|
11
|
+
removeHost(): string | undefined;
|
|
12
|
+
toPostman(): import("@novice1/api-doc-generator/lib/generators/postman/definitions").Auth;
|
|
13
|
+
toOpenAPISecurity(): import("@novice1/api-doc-generator/lib/generators/openapi/definitions").SecurityRequirementObject[];
|
|
14
|
+
toOpenAPI(): Record<string, import("@novice1/api-doc-generator/lib/generators/openapi/definitions").SecuritySchemeObject>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KaapiGroupAuthUtil = void 0;
|
|
4
|
+
const api_doc_generator_1 = require("@novice1/api-doc-generator");
|
|
5
|
+
/**
|
|
6
|
+
* Special class to group multiple security schemes
|
|
7
|
+
*/
|
|
8
|
+
class KaapiGroupAuthUtil extends api_doc_generator_1.OAuth2Util {
|
|
9
|
+
constructor(authUtils) {
|
|
10
|
+
super('');
|
|
11
|
+
this.authUtils = authUtils;
|
|
12
|
+
this.groupAuth = new api_doc_generator_1.GroupAuthUtil(authUtils);
|
|
13
|
+
}
|
|
14
|
+
setHost(host) {
|
|
15
|
+
this.authUtils.forEach(builder => {
|
|
16
|
+
if (builder instanceof api_doc_generator_1.OAuth2Util) {
|
|
17
|
+
builder.setHost(host);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return super.setHost(host);
|
|
21
|
+
}
|
|
22
|
+
removeHost() {
|
|
23
|
+
this.authUtils.forEach(builder => {
|
|
24
|
+
if (builder instanceof api_doc_generator_1.OAuth2Util) {
|
|
25
|
+
builder.removeHost();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return super.removeHost();
|
|
29
|
+
}
|
|
30
|
+
toPostman() {
|
|
31
|
+
return this.groupAuth.toPostman();
|
|
32
|
+
}
|
|
33
|
+
toOpenAPISecurity() {
|
|
34
|
+
return this.groupAuth.toOpenAPISecurity();
|
|
35
|
+
}
|
|
36
|
+
toOpenAPI() {
|
|
37
|
+
return this.groupAuth.toOpenAPI();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.KaapiGroupAuthUtil = KaapiGroupAuthUtil;
|
|
41
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/services/docs/utils.ts"],"names":[],"mappings":";;;AACA,kEAAsE;AAGtE;;GAEG;AACH,MAAa,kBAAmB,SAAQ,8BAAU;IAG9C,YAAY,SAAyB;QACjC,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAa,CAAC,SAAS,CAAC,CAAA;IACjD,CAAC;IAED,OAAO,CAAC,IAAY;QAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC7B,IAAI,OAAO,YAAY,8BAAU,EAAE,CAAC;gBAChC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACzB,CAAC;QACL,CAAC,CAAC,CAAA;QACF,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,UAAU;QACN,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAC7B,IAAI,OAAO,YAAY,8BAAU,EAAE,CAAC;gBAChC,OAAO,CAAC,UAAU,EAAE,CAAA;YACxB,CAAC;QACL,CAAC,CAAC,CAAA;QACF,OAAO,KAAK,CAAC,UAAU,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED,iBAAiB;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC;IAC9C,CAAC;IAED,SAAS;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;CACJ;AAtCD,gDAsCC"}
|
package/lib/services/log.js
CHANGED
|
@@ -27,7 +27,7 @@ function wrap(loggerFn) {
|
|
|
27
27
|
}
|
|
28
28
|
function createLogger(options) {
|
|
29
29
|
const wlogger = winston_1.default.createLogger(options);
|
|
30
|
-
return Object.assign(wrap(wlogger.
|
|
30
|
+
return Object.assign(wrap(wlogger.info), {
|
|
31
31
|
silly: wrap(wlogger.silly),
|
|
32
32
|
debug: wrap(wlogger.debug),
|
|
33
33
|
verbose: wrap(wlogger.verbose),
|
package/lib/services/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/services/log.ts"],"names":[],"mappings":";;AAgCA,oCAgBC;;AAhDD,8DAA8B;AAc9B,SAAS,IA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AS,CAAC,CAAC,CAAC,CAAC;YACpD,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACV,IAAI,CAAC;oBACD,IAAI,OAAO,CAAC,IAAI,QAAQ;wBAAE,CAAC,GAAG,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,QAAQ,EAAE,CAAC;gBAChD,CAAC;gBAAC,OAAO,EAAE,EAAE,CAAC;oBACV,EAAE;gBACN,CAAC;YACL,CAAC;YACD,OAAO,CAAC,CAAC;QACb,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAClB,CAAC,CAAA;AACL,CAAC;AAED,SAAgB,YAAY,CAAC,OAA+B;IACxD,MAAM,OAAO,GAAG,iBAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAE9C,OAAO,MAAM,CAAC,MAAM,CAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAClB;QACI,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAC9B,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACxB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QACxB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;QAC3B,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;QACxB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;KAC7B,CACJ,CAAA;AACL,CAAC"}
|
package/lib/services/plugin.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { ILogger } from './log';
|
|
|
3
3
|
import { KaapiServerRoute } from '@kaapi/server';
|
|
4
4
|
import { KaapiOpenAPI, KaapiPostman } from './docs/generators';
|
|
5
5
|
import { BaseAuthUtil } from '@novice1/api-doc-generator/lib/utils/auth/baseAuthUtils';
|
|
6
|
+
import { KaapiGroupAuthUtil } from './docs/utils';
|
|
6
7
|
/**
|
|
7
8
|
*
|
|
8
9
|
* Set of tools
|
|
@@ -58,5 +59,30 @@ export declare abstract class AuthDesign implements KaapiPlugin {
|
|
|
58
59
|
/**
|
|
59
60
|
* Where authentication schemes and strategies should be registered.
|
|
60
61
|
*/
|
|
61
|
-
abstract integrateStrategy(t: KaapiTools): void
|
|
62
|
+
abstract integrateStrategy(t: KaapiTools): void;
|
|
63
|
+
/**
|
|
64
|
+
* The name of the strategy, for info purpose
|
|
65
|
+
*/
|
|
66
|
+
abstract getStrategyName(): string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* An auth design that groups multiple auth designs.
|
|
70
|
+
*
|
|
71
|
+
* Usefull to regroup the auth schemes in the documentation and register the strategies in parallel.
|
|
72
|
+
* ```ts
|
|
73
|
+
* const authdesigns = new GroupAuthDesign([
|
|
74
|
+
* authdesign1,
|
|
75
|
+
* authdesign2
|
|
76
|
+
* ])
|
|
77
|
+
* app.extend(authdesigns)
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare class GroupAuthDesign extends AuthDesign {
|
|
81
|
+
protected designs: AuthDesign[];
|
|
82
|
+
constructor(designs: AuthDesign[]);
|
|
83
|
+
docs(): KaapiGroupAuthUtil;
|
|
84
|
+
integrateStrategy(t: KaapiTools): void;
|
|
85
|
+
integrateHook(t: KaapiTools): Promise<void>;
|
|
86
|
+
getStrategyName(): string;
|
|
87
|
+
getStrategies(): string[];
|
|
62
88
|
}
|
package/lib/services/plugin.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthDesign = void 0;
|
|
3
|
+
exports.GroupAuthDesign = exports.AuthDesign = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const api_doc_generator_1 = require("@novice1/api-doc-generator");
|
|
6
|
+
const utils_1 = require("./docs/utils");
|
|
6
7
|
/**
|
|
7
8
|
* AuthDesign plugin
|
|
8
9
|
*/
|
|
@@ -10,7 +11,14 @@ class AuthDesign {
|
|
|
10
11
|
integrate(t) {
|
|
11
12
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
12
13
|
var _a, _b, _c;
|
|
13
|
-
|
|
14
|
+
try {
|
|
15
|
+
this.integrateStrategy(t);
|
|
16
|
+
t.log.debug(`Auth Design "${this.constructor.name}" set strategy (integrateStrategy).`);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
t.log.error(`Auth Design "${this.constructor.name}" failed to integrate auth strategy: ${err}`);
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
14
22
|
const securityScheme = this.docs();
|
|
15
23
|
if (securityScheme) {
|
|
16
24
|
(_a = t.openapi) === null || _a === void 0 ? void 0 : _a.addSecurityScheme(securityScheme).setDefaultSecurity(securityScheme);
|
|
@@ -18,6 +26,10 @@ class AuthDesign {
|
|
|
18
26
|
securityScheme.setHost(t.postman.getHost()[0]);
|
|
19
27
|
}
|
|
20
28
|
(_c = t.postman) === null || _c === void 0 ? void 0 : _c.setDefaultSecurity(securityScheme);
|
|
29
|
+
t.log.debug(`Auth Design "${this.constructor.name}" set security scheme (docs).`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
t.log.warn(`Auth Design "${this.constructor.name}" did not provide a security scheme (docs()).`);
|
|
21
33
|
}
|
|
22
34
|
yield this.integrateHook(t);
|
|
23
35
|
});
|
|
@@ -31,4 +43,45 @@ class AuthDesign {
|
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
45
|
exports.AuthDesign = AuthDesign;
|
|
46
|
+
/**
|
|
47
|
+
* An auth design that groups multiple auth designs.
|
|
48
|
+
*
|
|
49
|
+
* Usefull to regroup the auth schemes in the documentation and register the strategies in parallel.
|
|
50
|
+
* ```ts
|
|
51
|
+
* const authdesigns = new GroupAuthDesign([
|
|
52
|
+
* authdesign1,
|
|
53
|
+
* authdesign2
|
|
54
|
+
* ])
|
|
55
|
+
* app.extend(authdesigns)
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
class GroupAuthDesign extends AuthDesign {
|
|
59
|
+
constructor(designs) {
|
|
60
|
+
super();
|
|
61
|
+
this.designs = designs;
|
|
62
|
+
}
|
|
63
|
+
docs() {
|
|
64
|
+
return new utils_1.KaapiGroupAuthUtil(this.designs
|
|
65
|
+
.map(d => d.docs())
|
|
66
|
+
.filter(d => typeof d != 'undefined'));
|
|
67
|
+
}
|
|
68
|
+
integrateStrategy(t) {
|
|
69
|
+
for (const d of this.designs) {
|
|
70
|
+
d.integrateStrategy(t);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
integrateHook(t) {
|
|
74
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
yield Promise.all(this.designs
|
|
76
|
+
.map(d => d.integrateHook(t)));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getStrategyName() {
|
|
80
|
+
return this.getStrategies()[0] || '';
|
|
81
|
+
}
|
|
82
|
+
getStrategies() {
|
|
83
|
+
return this.designs.map(d => d.getStrategyName()).filter(n => n);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.GroupAuthDesign = GroupAuthDesign;
|
|
34
87
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/services/plugin.ts"],"names":[],"mappings":";;;;AAKA,kEAAwD;
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/services/plugin.ts"],"names":[],"mappings":";;;;AAKA,kEAAwD;AACxD,wCAAkD;AAoDlD;;GAEG;AACH,MAAsB,UAAU;IACtB,SAAS,CAAC,CAAa;;;YAEzB,IAAI,CAAC;gBACD,IAAI,CAAC,iBAAiB,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;;;;;;;;;;GAWG;AACH,MAAa,eAAgB,SAAQ,UAAU;IAI3C,YAAY,OAAqB;QAC7B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI;QACA,OAAO,IAAI,0BAAkB,CAAC,IAAI,CAAC,OAAO;aACrC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,WAAW,CAAC,CACxC,CAAA;IACL,CAAC;IACD,iBAAiB,CAAC,CAAa;QAC3B,KAAI,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC1B,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAA;QAC1B,CAAC;IACL,CAAC;IACK,aAAa,CAAC,CAAa;;YAC7B,MAAM,OAAO,CAAC,GAAG,CACb,IAAI,CAAC,OAAO;iBACX,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAChC,CAAA;QACL,CAAC;KAAA;IAED,eAAe;QACX,OAAO,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;IAED,aAAa;QACT,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACpE,CAAC;CACJ;AAlCD,0CAkCC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Boom from '@hapi/boom';
|
|
2
|
+
import { Auth, AuthCredentials, ReqRef, ReqRefDefaults, Request, ResponseToolkit } from '@hapi/hapi';
|
|
3
|
+
import { ApiKeyLocation, ApiKeyUtil } from '@novice1/api-doc-generator';
|
|
4
|
+
import { AuthDesign, KaapiTools } from '../plugin';
|
|
5
|
+
export type APIKeyAuthOptions<Refs extends ReqRef = ReqRefDefaults> = {
|
|
6
|
+
/**
|
|
7
|
+
* e.g.: "Bearer" or "Session" or ...
|
|
8
|
+
*/
|
|
9
|
+
headerTokenType?: string;
|
|
10
|
+
validate?(request: Request<Refs>, token: any, h: ResponseToolkit<Refs>): Promise<{
|
|
11
|
+
isValid?: boolean;
|
|
12
|
+
artifacts?: unknown;
|
|
13
|
+
credentials?: AuthCredentials;
|
|
14
|
+
message?: string;
|
|
15
|
+
} | Auth | Boom.Boom>;
|
|
16
|
+
};
|
|
17
|
+
export interface APIKeyAuthArg {
|
|
18
|
+
/**
|
|
19
|
+
* Default: "Authorization" (header)
|
|
20
|
+
*/
|
|
21
|
+
key?: string;
|
|
22
|
+
auth?: APIKeyAuthOptions;
|
|
23
|
+
strategyName?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class APIKeyAuthDesign extends AuthDesign {
|
|
26
|
+
#private;
|
|
27
|
+
protected strategyName: string;
|
|
28
|
+
protected description?: string;
|
|
29
|
+
protected apiKeyLocation: ApiKeyLocation;
|
|
30
|
+
protected auth: APIKeyAuthOptions;
|
|
31
|
+
get key(): string;
|
|
32
|
+
constructor(arg?: APIKeyAuthArg);
|
|
33
|
+
setDescription(description: string): this;
|
|
34
|
+
getStrategyName(): string;
|
|
35
|
+
getDescription(): string | undefined;
|
|
36
|
+
inCookie(): this;
|
|
37
|
+
inHeader(): this;
|
|
38
|
+
inQuery(): this;
|
|
39
|
+
docs(): ApiKeyUtil;
|
|
40
|
+
integrateStrategy(t: KaapiTools): void | Promise<void>;
|
|
41
|
+
toString(): string;
|
|
42
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// APIKeyAuthDesign
|
|
3
|
+
var _APIKeyAuthDesign_key;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.APIKeyAuthDesign = void 0;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const boom_1 = tslib_1.__importDefault(require("@hapi/boom"));
|
|
8
|
+
const api_doc_generator_1 = require("@novice1/api-doc-generator");
|
|
9
|
+
const plugin_1 = require("../plugin");
|
|
10
|
+
class APIKeyAuthDesign extends plugin_1.AuthDesign {
|
|
11
|
+
get key() {
|
|
12
|
+
return tslib_1.__classPrivateFieldGet(this, _APIKeyAuthDesign_key, "f");
|
|
13
|
+
}
|
|
14
|
+
constructor(arg) {
|
|
15
|
+
super();
|
|
16
|
+
_APIKeyAuthDesign_key.set(this, 'Authorization');
|
|
17
|
+
this.strategyName = 'api-key-auth-design';
|
|
18
|
+
this.apiKeyLocation = api_doc_generator_1.ApiKeyLocation.header;
|
|
19
|
+
if (arg === null || arg === void 0 ? void 0 : arg.key)
|
|
20
|
+
tslib_1.__classPrivateFieldSet(this, _APIKeyAuthDesign_key, arg.key, "f");
|
|
21
|
+
if (arg === null || arg === void 0 ? void 0 : arg.strategyName)
|
|
22
|
+
this.strategyName = arg.strategyName;
|
|
23
|
+
this.auth = (arg === null || arg === void 0 ? void 0 : arg.auth) ? Object.assign({}, arg.auth) : {};
|
|
24
|
+
}
|
|
25
|
+
setDescription(description) {
|
|
26
|
+
this.description = description;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
getStrategyName() {
|
|
30
|
+
return this.strategyName;
|
|
31
|
+
}
|
|
32
|
+
getDescription() {
|
|
33
|
+
return this.description;
|
|
34
|
+
}
|
|
35
|
+
inCookie() {
|
|
36
|
+
this.apiKeyLocation = api_doc_generator_1.ApiKeyLocation.cookie;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
inHeader() {
|
|
40
|
+
this.apiKeyLocation = api_doc_generator_1.ApiKeyLocation.header;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
inQuery() {
|
|
44
|
+
this.apiKeyLocation = api_doc_generator_1.ApiKeyLocation.query;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
docs() {
|
|
48
|
+
const docs = new api_doc_generator_1.ApiKeyUtil(this.strategyName)
|
|
49
|
+
.setApiKeyLocation(this.apiKeyLocation)
|
|
50
|
+
.setKey(this.key);
|
|
51
|
+
if (this.description) {
|
|
52
|
+
docs.setDescription(this.description);
|
|
53
|
+
}
|
|
54
|
+
return docs;
|
|
55
|
+
}
|
|
56
|
+
integrateStrategy(t) {
|
|
57
|
+
const strategyName = this.strategyName;
|
|
58
|
+
const apiKeyLocation = this.apiKeyLocation;
|
|
59
|
+
const key = this.key;
|
|
60
|
+
t.scheme(strategyName, (_server, options) => {
|
|
61
|
+
return {
|
|
62
|
+
authenticate: (request, h) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const settings = options || {};
|
|
65
|
+
const authorization = apiKeyLocation == api_doc_generator_1.ApiKeyLocation.cookie ?
|
|
66
|
+
request.state[key] : apiKeyLocation == api_doc_generator_1.ApiKeyLocation.query ?
|
|
67
|
+
request.query[key] :
|
|
68
|
+
request.raw.req.headers[key.toLowerCase()];
|
|
69
|
+
let token = authorization;
|
|
70
|
+
if (apiKeyLocation == api_doc_generator_1.ApiKeyLocation.header && settings.headerTokenType) {
|
|
71
|
+
const authSplit = typeof authorization === 'string' ? authorization.split(/\s+/) : ['', ''];
|
|
72
|
+
const tokenType = authSplit[0];
|
|
73
|
+
token = authSplit[1];
|
|
74
|
+
if (tokenType.toLowerCase() !== ((_a = settings.headerTokenType) === null || _a === void 0 ? void 0 : _a.toLowerCase())) {
|
|
75
|
+
return boom_1.default.unauthorized(null, settings.headerTokenType);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (settings.validate) {
|
|
79
|
+
try {
|
|
80
|
+
const result = yield ((_b = settings.validate) === null || _b === void 0 ? void 0 : _b.call(settings, request, token, h));
|
|
81
|
+
if (result && 'isAuth' in result) {
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
if (result && 'isBoom' in result) {
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
if (result) {
|
|
88
|
+
const { isValid, credentials, artifacts, message } = result;
|
|
89
|
+
if (isValid && credentials) {
|
|
90
|
+
return h.authenticated({ credentials, artifacts });
|
|
91
|
+
}
|
|
92
|
+
if (message) {
|
|
93
|
+
return h.unauthenticated(boom_1.default.unauthorized(message, (api_doc_generator_1.ApiKeyLocation.header && settings.headerTokenType) || strategyName), {
|
|
94
|
+
credentials: credentials || {},
|
|
95
|
+
artifacts
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
return boom_1.default.internal(err instanceof Error ? err : `${err}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return boom_1.default.unauthorized(null, (api_doc_generator_1.ApiKeyLocation.header && settings.headerTokenType) || strategyName);
|
|
105
|
+
}),
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
t.strategy(strategyName, strategyName, this.auth);
|
|
109
|
+
}
|
|
110
|
+
toString() {
|
|
111
|
+
return this.getStrategyName();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.APIKeyAuthDesign = APIKeyAuthDesign;
|
|
115
|
+
_APIKeyAuthDesign_key = new WeakMap();
|
|
116
|
+
//# sourceMappingURL=api-key-auth-design.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-key-auth-design.js","sourceRoot":"","sources":["../../../../src/services/plugins/auth-designs/api-key-auth-design.ts"],"names":[],"mappings":";AAAA,mBAAmB;;;;;AAEnB,8DAA8B;AAS9B,kEAAwE;AACxE,sCAGmB;AA4BnB,MAAa,gBAAiB,SAAQ,mBAAU;IAQ5C,IAAW,GAAG;QACV,OAAO,+BAAA,IAAI,6BAAK,CAAA;IACpB,CAAC;IAED,YACI,GAAmB;QAEnB,KAAK,EAAE,CAAA;QAbX,gCAA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BAC/D,CAAC;oBACL,CAAC;oBAED,OAAO,cAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,kCAAc,CAAC,MAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,IAAI,YAAY,CAAC,CAAA;gBACvG,CAAC,CAAA;aACJ,CAAA;QACL,CAAC,CAAC,CAAA;QACF,CAAC,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;IACrD,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,eAAe,EAAE,CAAA;IACjC,CAAC;CACJ;AA1ID,4CA0IC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Boom from '@hapi/boom';
|
|
2
|
+
import { Auth, AuthCredentials, ReqRef, ReqRefDefaults, Request, ResponseToolkit } from '@hapi/hapi';
|
|
3
|
+
import { BasicAuthUtil } from '@novice1/api-doc-generator';
|
|
4
|
+
import { AuthDesign, KaapiTools } from '../plugin';
|
|
5
|
+
export type BasicAuthOptions<Refs extends ReqRef = ReqRefDefaults> = {
|
|
6
|
+
validate?(request: Request<Refs>, username: string, password: string, h: ResponseToolkit<Refs>): Promise<{
|
|
7
|
+
isValid?: boolean;
|
|
8
|
+
artifacts?: unknown;
|
|
9
|
+
credentials?: AuthCredentials;
|
|
10
|
+
message?: string;
|
|
11
|
+
} | Auth | Boom.Boom>;
|
|
12
|
+
};
|
|
13
|
+
export interface BasicAuthArg {
|
|
14
|
+
auth?: BasicAuthOptions;
|
|
15
|
+
strategyName?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class BasicAuthDesign extends AuthDesign {
|
|
18
|
+
readonly key = "Authorization";
|
|
19
|
+
protected strategyName: string;
|
|
20
|
+
protected description?: string;
|
|
21
|
+
protected auth: BasicAuthOptions;
|
|
22
|
+
constructor(arg?: BasicAuthArg);
|
|
23
|
+
setDescription(description: string): this;
|
|
24
|
+
getStrategyName(): string;
|
|
25
|
+
getDescription(): string | undefined;
|
|
26
|
+
docs(): BasicAuthUtil;
|
|
27
|
+
integrateStrategy(t: KaapiTools): void | Promise<void>;
|
|
28
|
+
toString(): string;
|
|
29
|
+
}
|