expresso-macchiato 1.0.0-dev.7 → 1.0.0-dev.9
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/dist/index.d.mts +68 -456
- package/dist/index.d.ts +68 -456
- package/dist/index.js +126 -306
- package/dist/index.mjs +111 -291
- package/package.json +2 -3
- package/types/db.sptypes.ts +6 -4
- package/types/router.sptypes.ts +10 -7
- package/types/swagger.sptypes.ts +0 -375
package/dist/index.mjs
CHANGED
|
@@ -114,267 +114,68 @@ _DbConnector.getDataSource = () => _DbConnector.DataSource;
|
|
|
114
114
|
var DbConnector = _DbConnector;
|
|
115
115
|
|
|
116
116
|
// src/Swagger.ts
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// ----------------------- GENERIC ----------------------- //
|
|
130
|
-
// ------------------------------------------------------- //
|
|
131
|
-
// ------------------------------------------------------- //
|
|
132
|
-
_Swagger.addServer = (server) => _Swagger.apiDocument.servers.push(server);
|
|
133
|
-
// Call at init to add current server
|
|
134
|
-
_Swagger.generateOpenAPIDocument = () => JSON.parse(JSON.stringify(_Swagger.apiDocument, null, 2));
|
|
135
|
-
// Generates json to be served in api
|
|
136
|
-
_Swagger.apiDocument = // static document to be populated
|
|
137
|
-
{
|
|
138
|
-
openapi: "3.0.4",
|
|
139
|
-
servers: [],
|
|
140
|
-
info: { title: "Dynamically Generated API", version: "1.0.0" },
|
|
141
|
-
paths: {},
|
|
142
|
-
components: {
|
|
143
|
-
schemas: {},
|
|
144
|
-
securitySchemes: {
|
|
145
|
-
bearerAuth: {
|
|
146
|
-
type: "http",
|
|
147
|
-
scheme: "bearer",
|
|
148
|
-
bearerFormat: "JWT"
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
security: [
|
|
153
|
-
{ "bearerAuth": [] }
|
|
154
|
-
]
|
|
155
|
-
};
|
|
156
|
-
// ------------------------------------------------------- //
|
|
157
|
-
// ------------------------------------------------------- //
|
|
158
|
-
// ----------------------- METHODS ----------------------- //
|
|
159
|
-
// ------------------------------------------------------- //
|
|
160
|
-
// ------------------------------------------------------- //
|
|
161
|
-
/**
|
|
162
|
-
* @Description
|
|
163
|
-
* - ❌ ROUTER-WRAPPER.
|
|
164
|
-
* - 🛠️ ADD-API-PATH
|
|
165
|
-
* - This method is not directly to insert inside the structur of addApiPath but is useful to create Schemas while not using the routerWrapper
|
|
166
|
-
*/
|
|
167
|
-
_Swagger.addSchema = (schema, properties) => {
|
|
168
|
-
if (!_Swagger.apiDocument.components || !_Swagger.apiDocument.components.schemas) _Swagger.apiDocument.components = { schemas: {} };
|
|
169
|
-
if (!_Swagger.apiDocument.components.schemas[schema]) _Swagger.apiDocument.components.schemas[schema] = {
|
|
170
|
-
type: "object",
|
|
171
|
-
properties
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* @Description
|
|
176
|
-
* - ❌ ROUTER-WRAPPER.
|
|
177
|
-
* - 🛠️ ADD-API-PATH
|
|
178
|
-
* - This method is thought to reduce the code in the addApiPath method
|
|
179
|
-
* - You can create a schema while declaring it and associating to the path calling this method
|
|
180
|
-
*/
|
|
181
|
-
_Swagger.getBasicPost = (schema, required, parameters, properties, description) => ({
|
|
182
|
-
responses: {},
|
|
183
|
-
parameters,
|
|
184
|
-
requestBody: {
|
|
185
|
-
required,
|
|
186
|
-
description,
|
|
187
|
-
schemaName: schema,
|
|
188
|
-
schema: {
|
|
189
|
-
[schema]: {
|
|
190
|
-
type: "object",
|
|
191
|
-
properties
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
/**
|
|
197
|
-
* @Description
|
|
198
|
-
* - ❌ **ROUTER-WRAPPER.**
|
|
199
|
-
* - 🛠️ **ADD-API-PATH**
|
|
200
|
-
* - This method is thought to reduce the code in the addApiPath method
|
|
201
|
-
*/
|
|
202
|
-
_Swagger.getBasicGet = (parameters) => ({
|
|
203
|
-
responses: {},
|
|
204
|
-
parameters
|
|
205
|
-
});
|
|
206
|
-
/**
|
|
207
|
-
* @Description
|
|
208
|
-
* - ❌ ROUTER-WRAPPER.
|
|
209
|
-
* - This method is useful if you don't want to use the router wrapper but add your swagger schema anyway.
|
|
210
|
-
* - **It is thought to be used inside the library**, iterating through the paths of the router wrapper.
|
|
211
|
-
* - **Devs can't use inside the parameters of a RouterWrapper constructor**
|
|
212
|
-
* - You can create the structure of a specified path and method, with a schema name that should be created elsewhere
|
|
213
|
-
*/
|
|
214
|
-
_Swagger.addSingleApiPath = (tag, basePath, _path, method, parameters, bodyObj, responses = {}) => {
|
|
215
|
-
const path3 = `${_Swagger.fromExpressParamsToSwagger(basePath)}${_Swagger.fromExpressParamsToSwagger(_path)}`;
|
|
216
|
-
const transcribedMethod = _Swagger.restMethodToSwaggerKeyMapping[method];
|
|
217
|
-
if (!_Swagger.apiDocument.paths[path3]) _Swagger.apiDocument.paths[path3] = {};
|
|
218
|
-
if (_Swagger.apiDocument.paths[path3][transcribedMethod]) return;
|
|
219
|
-
_Swagger.apiDocument.paths[path3][transcribedMethod] = {
|
|
220
|
-
responses,
|
|
221
|
-
parameters,
|
|
222
|
-
tags: [tag]
|
|
223
|
-
};
|
|
224
|
-
if (bodyObj) _Swagger.apiDocument.paths[path3][transcribedMethod].requestBody = {
|
|
225
|
-
required: bodyObj.required ?? false,
|
|
226
|
-
description: bodyObj.description,
|
|
227
|
-
content: {
|
|
228
|
-
[bodyObj.comType ?? "application/json"]: {
|
|
229
|
-
schema: { "$ref": "#/components/schemas/" + bodyObj.schema }
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
/**
|
|
235
|
-
* @Description
|
|
236
|
-
* - ❌ ROUTER-WRAPPER.
|
|
237
|
-
* - 🛠️ ADD-API-PATH
|
|
238
|
-
* - **This method is useful if you don't want to use the router wrapper but add your swagger schema anyway**.
|
|
239
|
-
* - You can use other other methods of this class to ease the writing
|
|
240
|
-
* - It is thought to create a full section of apis (hypotetically under one single tag) **while you create the schema in the meanwhile**
|
|
241
|
-
*/
|
|
242
|
-
_Swagger._addApiPath = (tag, basePath, options) => {
|
|
243
|
-
const finalPaths = {};
|
|
244
|
-
const finalSchemas = {};
|
|
245
|
-
for (const _path in options) {
|
|
246
|
-
const path3 = `${basePath}${_path}`;
|
|
247
|
-
if (options[_path].get?.tags) options[_path].get.tags = [tag];
|
|
248
|
-
finalPaths[path3] = {
|
|
249
|
-
get: options[_path].get,
|
|
250
|
-
$ref: options[_path].$ref,
|
|
251
|
-
head: options[_path].head,
|
|
252
|
-
parameters: options[_path].parameters
|
|
253
|
-
};
|
|
254
|
-
if (options[_path].get) options[_path].get.tags = [tag];
|
|
255
|
-
if (options[_path].post && options[_path].post.requestBody) {
|
|
256
|
-
finalPaths[path3].post = {
|
|
257
|
-
responses: {},
|
|
258
|
-
parameters: options[_path].post.parameters,
|
|
259
|
-
tags: [tag],
|
|
260
|
-
summary: options[_path].post.summary,
|
|
261
|
-
requestBody: {
|
|
262
|
-
required: options[_path].post.requestBody.required,
|
|
263
|
-
description: options[_path].post.requestBody.description,
|
|
264
|
-
content: {
|
|
265
|
-
"application/json": { schema: { "$ref": "#/components/schemas/" + options[_path].post.requestBody.schemaName } }
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
for (const key in options[_path].post.requestBody.schema) {
|
|
270
|
-
if (!finalSchemas[key]) finalSchemas[key] = options[_path].post.requestBody.schema[key];
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (options[_path].put && options[_path].put.requestBody) {
|
|
274
|
-
finalPaths[path3].put = {
|
|
275
|
-
responses: {},
|
|
276
|
-
tags: [tag],
|
|
277
|
-
parameters: options[_path].put.parameters,
|
|
278
|
-
summary: options[_path].put.summary,
|
|
279
|
-
requestBody: {
|
|
280
|
-
required: options[_path].put.requestBody.required,
|
|
281
|
-
description: options[_path].put.requestBody.description,
|
|
282
|
-
content: {
|
|
283
|
-
"application/json": { schema: { "$ref": "#/components/schemas/" + options[_path].put.requestBody.schemaName } }
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
for (const key in options[_path].put.requestBody.schema) {
|
|
288
|
-
if (!finalSchemas[key]) finalSchemas[key] = options[_path].put.requestBody.schema[key];
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (options[_path].delete) {
|
|
292
|
-
finalPaths[path3].delete = {
|
|
293
|
-
responses: {},
|
|
294
|
-
tags: [tag],
|
|
295
|
-
parameters: options[_path].delete.parameters,
|
|
296
|
-
summary: options[_path].delete.summary
|
|
297
|
-
};
|
|
298
|
-
if (options[_path].delete.requestBody) {
|
|
299
|
-
const finalComType = options[_path].delete.requestBody.comType ?? "application/json";
|
|
300
|
-
finalPaths[path3].delete.requestBody = {
|
|
301
|
-
required: options[_path].delete.requestBody.required,
|
|
302
|
-
description: options[_path].delete.requestBody.description,
|
|
303
|
-
content: {
|
|
304
|
-
[finalComType]: {
|
|
305
|
-
schema: { "$ref": "#/components/schemas/" + options[_path].delete.requestBody.schemaName }
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
for (const key in options[_path].delete.requestBody.schema) {
|
|
310
|
-
if (!finalSchemas[key]) finalSchemas[key] = options[_path].delete.requestBody.schema[key];
|
|
311
|
-
}
|
|
117
|
+
import { ExpressoSwagger } from "expresso-swagger";
|
|
118
|
+
var MySwagger = class extends ExpressoSwagger {
|
|
119
|
+
constructor() {
|
|
120
|
+
super({
|
|
121
|
+
info: {
|
|
122
|
+
title: "Expresso Macchiato API",
|
|
123
|
+
version: "1.0.0",
|
|
124
|
+
description: "API documentation for Expresso Macchiato"
|
|
125
|
+
},
|
|
126
|
+
settings: {
|
|
127
|
+
theme: "dark",
|
|
128
|
+
withCredentials: true
|
|
312
129
|
}
|
|
313
|
-
}
|
|
130
|
+
});
|
|
131
|
+
this.fromExpressParamsToSwagger = (str) => str.replace(/:(\w+)(?=\/|$)/g, "{$1}");
|
|
314
132
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const methodKey = method;
|
|
318
|
-
if (!_Swagger.apiDocument.paths[path3]) _Swagger.apiDocument.paths[path3] = {};
|
|
319
|
-
if (!_Swagger.apiDocument.paths[path3][methodKey]) _Swagger.apiDocument.paths[path3][methodKey] = finalPaths[path3][methodKey];
|
|
320
|
-
}
|
|
133
|
+
setBaseUrl(url) {
|
|
134
|
+
this.config.baseUrl = url;
|
|
321
135
|
}
|
|
322
|
-
|
|
323
|
-
if (!
|
|
324
|
-
|
|
136
|
+
addSchema(name, schema) {
|
|
137
|
+
if (!this.config.models) this.config.models = {};
|
|
138
|
+
this.config.models[name] = schema;
|
|
325
139
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
};
|
|
352
|
-
/**
|
|
353
|
-
* @Description
|
|
354
|
-
* - ✅ ROUTER-WRAPPER
|
|
355
|
-
* - Creates the swagger schema expected by your api
|
|
356
|
-
*/
|
|
357
|
-
_Swagger.createMultipartSchema = (name = "file", props) => ({
|
|
358
|
-
type: "object",
|
|
359
|
-
properties: {
|
|
360
|
-
[name]: { type: "string", format: "binary" },
|
|
361
|
-
...props ?? {}
|
|
140
|
+
/**
|
|
141
|
+
* Adds a single API path by accumulating it into the internal list.
|
|
142
|
+
*/
|
|
143
|
+
addSingleApiPath(group, basePath, _path, method, options) {
|
|
144
|
+
const fullPath = this.fromExpressParamsToSwagger(`${basePath}${_path}`);
|
|
145
|
+
const params = {};
|
|
146
|
+
const query = {};
|
|
147
|
+
if (options.parameters) {
|
|
148
|
+
options.parameters.forEach((p) => {
|
|
149
|
+
const def = { type: p.type || "string", required: p.required, description: p.description, default: p.default };
|
|
150
|
+
if (p.in === "path") params[p.name] = def;
|
|
151
|
+
if (p.in === "query") query[p.name] = def;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
this.endpoints.push({
|
|
155
|
+
path: fullPath,
|
|
156
|
+
method,
|
|
157
|
+
group,
|
|
158
|
+
name: options.name,
|
|
159
|
+
description: options.description,
|
|
160
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
161
|
+
query: Object.keys(query).length > 0 ? query : void 0,
|
|
162
|
+
body: options.body,
|
|
163
|
+
responses: options.responses
|
|
164
|
+
});
|
|
362
165
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
*/
|
|
369
|
-
_Swagger.createSchema = (props, required) => {
|
|
370
|
-
const finalSchemaObject = { type: "object", properties: {}, required };
|
|
371
|
-
for (const prop in props) {
|
|
372
|
-
if (typeof props[prop] === "string") finalSchemaObject.properties[prop] = { type: props[prop] };
|
|
373
|
-
else finalSchemaObject.properties[prop] = props[prop];
|
|
166
|
+
/**
|
|
167
|
+
* Instantiates ExpressoSwagger and generates the final document.
|
|
168
|
+
*/
|
|
169
|
+
generateDocument() {
|
|
170
|
+
return this.getDocument();
|
|
374
171
|
}
|
|
375
|
-
return finalSchemaObject;
|
|
376
172
|
};
|
|
377
|
-
|
|
173
|
+
MySwagger.getIdParam = (name = "id") => ({ name, in: "path", required: true, type: "string", description: `Unique identifier.` });
|
|
174
|
+
MySwagger.getPaginationParams = () => [
|
|
175
|
+
{ name: "page", in: "query", type: "number", default: 1 },
|
|
176
|
+
{ name: "limit", in: "query", type: "number", default: 10 }
|
|
177
|
+
];
|
|
178
|
+
var Swagger = new MySwagger();
|
|
378
179
|
|
|
379
180
|
// src/DynamicDbRouter.ts
|
|
380
181
|
var _DynamicDbRouter = class _DynamicDbRouter {
|
|
@@ -422,12 +223,12 @@ _DynamicDbRouter.createDbRouter = (options) => {
|
|
|
422
223
|
if (_DynamicDbRouter.listOptionsKeys.includes(key)) listOptions[key] = req.query[key];
|
|
423
224
|
}
|
|
424
225
|
const searchQuery = {};
|
|
425
|
-
for (const param of options.getParameters ??
|
|
426
|
-
const val = req.query[
|
|
427
|
-
if (param.required && !val) throw new Error(`Params Error: ${
|
|
226
|
+
for (const [key, param] of Object.entries(options.getParameters ?? {})) {
|
|
227
|
+
const val = req.query[key] ?? void 0;
|
|
228
|
+
if (param.required && !val) throw new Error(`Params Error: ${key} required`);
|
|
428
229
|
if (val !== void 0) {
|
|
429
|
-
if (param.like) searchQuery[
|
|
430
|
-
else searchQuery[
|
|
230
|
+
if (param.like) searchQuery[key] = Like(`%${val}%`);
|
|
231
|
+
else searchQuery[key] = Equal(val);
|
|
431
232
|
}
|
|
432
233
|
}
|
|
433
234
|
const secureSearchQuery = _DynamicDbRouter.setSecureParams("LIST", payload, options.secure);
|
|
@@ -577,19 +378,28 @@ _DynamicDbRouter.addDbRouterSwagger = (options) => {
|
|
|
577
378
|
}
|
|
578
379
|
if (!avoidList.includes("LIST")) {
|
|
579
380
|
const listOptions = { page: 0, pageSize: 10, order: "ASC", orderBy: options.primaryKey };
|
|
580
|
-
Swagger.addSingleApiPath(options.tag, options.basePath, "/", "GET",
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
381
|
+
Swagger.addSingleApiPath(options.tag, options.basePath, "/", "GET", {
|
|
382
|
+
name: "/",
|
|
383
|
+
responses: options.responses,
|
|
384
|
+
parameters: [
|
|
385
|
+
{ name: "page", in: "query", type: "number", default: 0, required: false },
|
|
386
|
+
...Object.entries(listOptions).map(([key, val]) => ({ name: key, in: "query", default: val, required: false, type: typeof val === "number" ? "number" : "string" })),
|
|
387
|
+
...options.getParameters ?? []
|
|
388
|
+
]
|
|
389
|
+
});
|
|
584
390
|
}
|
|
585
391
|
if (!avoidList.includes("GET")) {
|
|
586
|
-
Swagger.addSingleApiPath(options.tag, options.basePath, `/{${options.primaryKey}}`, "GET",
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
392
|
+
Swagger.addSingleApiPath(options.tag, options.basePath, `/{${options.primaryKey}}`, "GET", {
|
|
393
|
+
name: `/{${options.primaryKey}}`,
|
|
394
|
+
responses: options.responses,
|
|
395
|
+
parameters: [
|
|
396
|
+
{ name: options.primaryKey, in: "path", required: true, type: "string" },
|
|
397
|
+
...options.getParameters ?? []
|
|
398
|
+
]
|
|
399
|
+
});
|
|
590
400
|
}
|
|
591
401
|
if (!avoidList.includes("POST")) {
|
|
592
|
-
Swagger.addSingleApiPath(options.tag, options.basePath, "/", "POST",
|
|
402
|
+
Swagger.addSingleApiPath(options.tag, options.basePath, "/", "POST", { body: options.tag, responses: options.responses });
|
|
593
403
|
}
|
|
594
404
|
if (!avoidList.includes("PUT")) {
|
|
595
405
|
Swagger.addSingleApiPath(
|
|
@@ -597,14 +407,22 @@ _DynamicDbRouter.addDbRouterSwagger = (options) => {
|
|
|
597
407
|
options.basePath,
|
|
598
408
|
`/{${options.primaryKey}}`,
|
|
599
409
|
"PUT",
|
|
600
|
-
|
|
601
|
-
|
|
410
|
+
{
|
|
411
|
+
name: `/{${options.primaryKey}}`,
|
|
412
|
+
body: options.tag,
|
|
413
|
+
parameters: [{ name: options.primaryKey, in: "path", required: true, type: "string" }],
|
|
414
|
+
responses: options.responses
|
|
415
|
+
}
|
|
602
416
|
);
|
|
603
417
|
}
|
|
604
418
|
if (!avoidList.includes("DELETE")) {
|
|
605
|
-
Swagger.addSingleApiPath(options.tag, options.basePath, `/{${options.primaryKey}}`, "DELETE",
|
|
606
|
-
|
|
607
|
-
|
|
419
|
+
Swagger.addSingleApiPath(options.tag, options.basePath, `/{${options.primaryKey}}`, "DELETE", {
|
|
420
|
+
name: `/{${options.primaryKey}}`,
|
|
421
|
+
responses: options.responses,
|
|
422
|
+
parameters: [
|
|
423
|
+
{ name: options.primaryKey, in: "path", required: true, type: "string" }
|
|
424
|
+
]
|
|
425
|
+
});
|
|
608
426
|
}
|
|
609
427
|
};
|
|
610
428
|
_DynamicDbRouter.setSecureParams = (method, payload, secure) => {
|
|
@@ -637,7 +455,7 @@ var RouterWrapper = class {
|
|
|
637
455
|
for (const avoid of this.data.dbRouting.avoid ?? []) {
|
|
638
456
|
if (!avoidOptionsForDefinedApis.includes(avoid)) avoidOptionsForDefinedApis.push(avoid);
|
|
639
457
|
}
|
|
640
|
-
const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps } = this.data.dbRouting;
|
|
458
|
+
const { entity, bodyParameters, getParameters, primaryKey, secure, returningProps, responses } = this.data.dbRouting;
|
|
641
459
|
DynamicDbRouter.createDbRouter({
|
|
642
460
|
entity,
|
|
643
461
|
bodyParameters,
|
|
@@ -648,7 +466,8 @@ var RouterWrapper = class {
|
|
|
648
466
|
tag: this.data.tag,
|
|
649
467
|
avoid: avoidOptionsForDefinedApis,
|
|
650
468
|
secure,
|
|
651
|
-
returningProps
|
|
469
|
+
returningProps,
|
|
470
|
+
responses
|
|
652
471
|
});
|
|
653
472
|
}
|
|
654
473
|
if (this.data.swaggerNewSchemas) {
|
|
@@ -683,9 +502,12 @@ var RouterWrapper = class {
|
|
|
683
502
|
this.data.basePath,
|
|
684
503
|
path3,
|
|
685
504
|
method,
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
505
|
+
{
|
|
506
|
+
name: path3,
|
|
507
|
+
parameters: currentMethod.swaggerParameters,
|
|
508
|
+
body: currentMethod.swaggerBody ? currentMethod.swaggerBody.schema : void 0,
|
|
509
|
+
responses: currentMethod.swaggerResponses
|
|
510
|
+
}
|
|
689
511
|
);
|
|
690
512
|
}
|
|
691
513
|
}
|
|
@@ -810,10 +632,10 @@ var SocketWrapper = class {
|
|
|
810
632
|
|
|
811
633
|
// src/Starter.ts
|
|
812
634
|
import express from "express";
|
|
635
|
+
import { getUIPath } from "expresso-swagger";
|
|
813
636
|
import http from "http";
|
|
814
637
|
import path2 from "path";
|
|
815
638
|
import { Server } from "socket.io";
|
|
816
|
-
import swaggerUi from "swagger-ui-express";
|
|
817
639
|
var Starter = class {
|
|
818
640
|
constructor(options) {
|
|
819
641
|
this.init = async (options) => {
|
|
@@ -827,17 +649,12 @@ var Starter = class {
|
|
|
827
649
|
let swaggerLogs = null;
|
|
828
650
|
if (options.swagger === void 0 || options.swagger) {
|
|
829
651
|
const swaggerUrl = `http://127.0.0.1:${options.projectConfig.SERVER_PORT}`;
|
|
830
|
-
Swagger.
|
|
831
|
-
app.get("/
|
|
832
|
-
|
|
833
|
-
res.json(openAPIDocument);
|
|
652
|
+
Swagger.setBaseUrl(swaggerUrl);
|
|
653
|
+
app.get("/docs", (_, res) => {
|
|
654
|
+
res.json(Swagger.generateDocument());
|
|
834
655
|
});
|
|
835
|
-
app.use("/
|
|
836
|
-
|
|
837
|
-
url: "/swagger"
|
|
838
|
-
}
|
|
839
|
-
}));
|
|
840
|
-
swaggerLogs = [`Swagger docs available at ${swaggerUrl}/swagger`, `Swagger UI available at ${swaggerUrl}/swagger-ui`];
|
|
656
|
+
app.use("/docs-ui", express.static(getUIPath()));
|
|
657
|
+
swaggerLogs = [`Swagger docs available at ${swaggerUrl}/docs`, `Swagger UI available at ${swaggerUrl}/docs-ui`];
|
|
841
658
|
}
|
|
842
659
|
if (options.tokenOptions) DynamicDbRouter.setTokenInstance(options.tokenOptions.tokenInstance);
|
|
843
660
|
if (options.clientPath) {
|
|
@@ -904,9 +721,12 @@ var Token = class {
|
|
|
904
721
|
}
|
|
905
722
|
return this.keyStore.all({ use: "enc" })[0];
|
|
906
723
|
}
|
|
907
|
-
// Metodo per autorizzare una richiesta
|
|
724
|
+
// Metodo per autorizzare una richiesta (string is for sockets implementations outside this package)
|
|
908
725
|
async authorize(req) {
|
|
909
|
-
if (
|
|
726
|
+
if (typeof req === "string") {
|
|
727
|
+
const payload = await this.verifyJWE(req);
|
|
728
|
+
return payload;
|
|
729
|
+
} else if (this.TOKEN_COOKIE_NAME) {
|
|
910
730
|
const rawCookies = req.headers.cookie ?? "";
|
|
911
731
|
const cookies = parse(rawCookies);
|
|
912
732
|
const cookieToken = cookies[this.TOKEN_COOKIE_NAME] ?? null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expresso-macchiato",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.9",
|
|
4
4
|
"author": "Alessio Velluso",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Description",
|
|
@@ -33,13 +33,12 @@
|
|
|
33
33
|
"cors": "^2.8.5",
|
|
34
34
|
"dotenv": "^16.3.1",
|
|
35
35
|
"express": "^4.18.2",
|
|
36
|
+
"expresso-swagger": "^0.0.8",
|
|
36
37
|
"jsonwebtoken": "^9.0.2",
|
|
37
38
|
"multer": "^1.4.5-lts.1",
|
|
38
39
|
"node-jose": "^2.2.0",
|
|
39
40
|
"reflect-metadata": "^0.2.2",
|
|
40
41
|
"socket.io": "^4.8.1",
|
|
41
|
-
"swagger-jsdoc": "^6.2.8",
|
|
42
|
-
"swagger-ui-express": "^5.0.1",
|
|
43
42
|
"utils-logger-av": "^4.0.0",
|
|
44
43
|
"utils-stuff": "^4.5.0"
|
|
45
44
|
},
|
package/types/db.sptypes.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Router } from "express"
|
|
2
|
+
import { ExpressoSwaggerModel } from "expresso-swagger"
|
|
2
3
|
import { BaseEntity } from "typeorm"
|
|
4
|
+
import { CustomSwaggerParameter } from "../src/Swagger"
|
|
3
5
|
import { Methods } from "./generic.sptypes"
|
|
4
|
-
import { Parameter, SchemaV3 } from "./swagger.sptypes"
|
|
5
6
|
import { SecureTokenConfig } from "./token.sptypes"
|
|
6
7
|
|
|
7
8
|
export type DynamicDbRouterOptions<T extends typeof BaseEntity> = {
|
|
@@ -10,9 +11,10 @@ export type DynamicDbRouterOptions<T extends typeof BaseEntity> = {
|
|
|
10
11
|
primaryKey?:string,
|
|
11
12
|
tag:string
|
|
12
13
|
basePath:string,
|
|
13
|
-
getParameters?:Array<
|
|
14
|
-
bodyParameters?:
|
|
14
|
+
getParameters?:Array<CustomSwaggerParameter>,
|
|
15
|
+
bodyParameters?:ExpressoSwaggerModel
|
|
15
16
|
avoid?:Array<Methods | 'LIST'>,
|
|
16
17
|
secure?:SecureTokenConfig,
|
|
17
|
-
returningProps?:string[]
|
|
18
|
+
returningProps?:string[],
|
|
19
|
+
responses?:Record<string | number, { description: string, body?: any }>
|
|
18
20
|
}
|
package/types/router.sptypes.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { Response as ExpressResponse, Request, RequestHandler } from "express";
|
|
2
|
+
import { ExpressoSwaggerModel } from "expresso-swagger";
|
|
2
3
|
import { BaseEntity } from "typeorm";
|
|
4
|
+
import { CustomSwaggerParameter } from "../src/Swagger";
|
|
5
|
+
import { DynamicDbRouterOptions } from "./db.sptypes";
|
|
3
6
|
import { ExpressReturn, Methods } from "./generic.sptypes";
|
|
4
|
-
import { Parameter, Reference, SchemaV3, Response as SwaggerResponse } from "./swagger.sptypes";
|
|
5
7
|
import { SecureTokenConfig } from "./token.sptypes";
|
|
6
8
|
|
|
7
9
|
export interface RouterWrapperInterface<T extends typeof BaseEntity = typeof BaseEntity> {
|
|
8
10
|
basePath:string;
|
|
9
11
|
tag:string,
|
|
10
|
-
swaggerNewSchemas?:{ [schema:string]:
|
|
12
|
+
swaggerNewSchemas?:{ [schema:string]: ExpressoSwaggerModel },
|
|
11
13
|
dbRouting?:{
|
|
12
14
|
entity:T,
|
|
13
15
|
primaryKey?:string,
|
|
14
|
-
getParameters?:Array<
|
|
15
|
-
bodyParameters?:
|
|
16
|
+
getParameters?:Array<CustomSwaggerParameter>
|
|
17
|
+
bodyParameters?:ExpressoSwaggerModel,
|
|
16
18
|
avoid?:Array<Methods | 'LIST'>,
|
|
17
19
|
secure?:SecureTokenConfig,
|
|
18
|
-
returningProps?:string[]
|
|
20
|
+
returningProps?:string[],
|
|
21
|
+
responses?:Record<string | number, { description: string, body?: any }>
|
|
19
22
|
}
|
|
20
23
|
apis?: Record<string, {
|
|
21
24
|
'GET'?:MethodPathHandling
|
|
@@ -32,8 +35,8 @@ export type MethodPathHandling = {
|
|
|
32
35
|
description?:string,
|
|
33
36
|
comType?:'application/json' | 'multipart/form-data',
|
|
34
37
|
},
|
|
35
|
-
swaggerResponses?:
|
|
36
|
-
swaggerParameters?:Array<
|
|
38
|
+
swaggerResponses?:DynamicDbRouterOptions<any>['responses'],
|
|
39
|
+
swaggerParameters?:Array<CustomSwaggerParameter>
|
|
37
40
|
middlewares?: RequestHandler[];
|
|
38
41
|
handler: (req:Request, res:ExpressResponse) => Promise<ExpressReturn>
|
|
39
42
|
}
|