expresso-macchiato 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "expresso-macchiato",
3
+ "version": "0.3.0",
4
+ "author": "Alessio Velluso",
5
+ "license": "MIT",
6
+ "description": "Description",
7
+ "devDependencies": {
8
+ "@types/bcrypt": "^5.0.2",
9
+ "@types/body-parser": "^1.19.5",
10
+ "@types/cors": "^2.8.17",
11
+ "@types/express": "^4.17.21",
12
+ "@types/jsonwebtoken": "^9.0.5",
13
+ "@types/multer": "^1.4.12",
14
+ "@types/node": "^22.13.10",
15
+ "@types/node-jose": "^1.1.13",
16
+ "@types/swagger-ui-express": "^4.1.8",
17
+ "@types/validator": "^13.12.2",
18
+ "@types/winston": "^2.4.4",
19
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
20
+ "@typescript-eslint/parser": "^6.18.1",
21
+ "eslint": "^8.56.0",
22
+ "express-winston": "^4.2.0",
23
+ "nodemon": "^3.0.2",
24
+ "ts-node": "^10.9.2",
25
+ "tsup": "^8.1.0",
26
+ "typescript": "^5.3.3",
27
+ "winston": "^3.11.0"
28
+ },
29
+ "dependencies": {
30
+ "bcrypt": "^5.1.1",
31
+ "body-parser": "^1.20.2",
32
+ "cors": "^2.8.5",
33
+ "dotenv": "^16.3.1",
34
+ "express": "^4.18.2",
35
+ "jsonwebtoken": "^9.0.2",
36
+ "swagger-jsdoc": "^6.2.8",
37
+ "swagger-ui-express": "^5.0.1",
38
+ "multer": "^1.4.5-lts.1",
39
+ "node-jose": "^2.2.0",
40
+ "reflect-metadata": "^0.2.2",
41
+ "utils-logger-av": "^3.2.3",
42
+ "utils-stuff": "^4.5.0"
43
+ },
44
+ "peerDependencies": {
45
+ "typeorm": "^0.3.21"
46
+ },
47
+ "repository": {
48
+ "url": ""
49
+ },
50
+ "main": "dist/index.js",
51
+ "module": "dist/index.mjs",
52
+ "types": "dist/index.d.ts",
53
+ "exports": {
54
+ ".": {
55
+ "import": "./dist/index.mjs",
56
+ "require": "./dist/index.js"
57
+ }
58
+ },
59
+ "scripts": {
60
+ "build": "tsup"
61
+ },
62
+ "keywords": []
63
+ }
@@ -0,0 +1,18 @@
1
+ import { Router } from "express"
2
+ import { BaseEntity } from "typeorm"
3
+ import { Methods } from "./generic.sptypes"
4
+ import { Parameter, SchemaV3 } from "./swagger.sptypes"
5
+ import { SecureTokenConfig } from "./token.sptypes"
6
+
7
+ export type DynamicDbRouterOptions<T extends typeof BaseEntity> = {
8
+ router:Router,
9
+ entity:T,
10
+ primaryKey?:string,
11
+ tag:string
12
+ basePath:string,
13
+ getParameters?:Array<Parameter>
14
+ bodyParameters?:SchemaV3
15
+ avoid?:Array<Methods | 'LIST'>,
16
+ secure?:SecureTokenConfig,
17
+ returningProps?:string[]
18
+ }
@@ -0,0 +1,35 @@
1
+ export type ErrorsMapping = Record<string, { status?:number, responseMessage?:string }>;
2
+
3
+ export type Methods = "GET" | "DELETE" | "PUT" | "POST"
4
+
5
+ export type ExpressReturn = { isOk:boolean, result:any, status:number, contentType?:string }
6
+
7
+ export type SwaggerMetadataInterface = {
8
+ required?:boolean, hide?:boolean,
9
+ }
10
+
11
+ export type ProjectConfigs =
12
+ {
13
+ SERVER_PORT:number,
14
+
15
+ DB_DIALECT?:string
16
+ DB_NAME?:string
17
+
18
+ DB_HOST?:string
19
+ DB_PORT?:number
20
+ DB_USER?:string
21
+ DB_PASSWORD?:string
22
+
23
+ API_URL?:string
24
+ ERROR_FILE_PATH?:string
25
+
26
+ // MINIO_ENDPOINT:string,
27
+ // MINIO_PORT?:number,
28
+ // MINIO_SSL?:boolean,
29
+ // MINIO_ACCESS_KEY?:string,
30
+ // MINIO_SECRET_KEY?:string,
31
+ }
32
+
33
+
34
+ export type SearchQuery = Record<string, string | number | boolean | undefined | null>
35
+ export type ListOptions = { pageSize?:number, page?:number, orderBy?:string, order?:'ASC' | 'DESC'} & SearchQuery;
@@ -0,0 +1,39 @@
1
+ import { Response as ExpressResponse, Request, RequestHandler } from "express";
2
+ import { BaseEntity } from "typeorm";
3
+ import { ExpressReturn, Methods } from "./generic.sptypes";
4
+ import { Parameter, Reference, SchemaV3, Response as SwaggerResponse } from "./swagger.sptypes";
5
+ import { SecureTokenConfig } from "./token.sptypes";
6
+
7
+ export interface RouterWrapperInterface<T extends typeof BaseEntity = typeof BaseEntity> {
8
+ basePath:string;
9
+ tag:string,
10
+ swaggerNewSchemas?:{ [schema:string]: SchemaV3 },
11
+ dbRouting?:{
12
+ entity:T,
13
+ primaryKey?:string,
14
+ getParameters?:Array<Parameter>
15
+ bodyParameters?:SchemaV3,
16
+ avoid?:Array<Methods | 'LIST'>,
17
+ secure?:SecureTokenConfig,
18
+ returningProps?:string[]
19
+ }
20
+ apis?: Record<string, {
21
+ 'GET'?:MethodPathHandling
22
+ 'POST'?:MethodPathHandling
23
+ 'PUT'?:MethodPathHandling
24
+ 'DELETE'?:MethodPathHandling
25
+ }>
26
+ }
27
+
28
+ export type MethodPathHandling = {
29
+ swaggerBody?:{
30
+ schema:string,
31
+ required?:boolean,
32
+ description?:string,
33
+ comType?:'application/json' | 'multipart/form-data',
34
+ },
35
+ swaggerResponses?:Record<string, Reference | SwaggerResponse>,
36
+ swaggerParameters?:Array<Parameter>
37
+ middlewares?: RequestHandler[];
38
+ handler: (req:Request, res:ExpressResponse) => Promise<ExpressReturn>
39
+ }
@@ -0,0 +1,36 @@
1
+ import { Express } from "express"
2
+ import http from "http"
3
+ import { EntitySchema, MixedList } from "typeorm"
4
+ import { RouterWrapper } from "../src/RouterWrapper"
5
+ import { Token } from "../src/Token"
6
+ import { ProjectConfigs } from "./generic.sptypes"
7
+ import { TokenApiOptions } from "./token.sptypes"
8
+
9
+ export type StarterOptions = {
10
+ plugins?:Array<any>,
11
+ routers?:Array<RouterWrapper>,
12
+ clientPath?:string,
13
+ swagger?:boolean,
14
+ projectConfig:ProjectConfigs,
15
+ beforeStartListening?:(app:Express, server?:http.Server) => void,
16
+ socket?:boolean,
17
+ tokenOptions?: {
18
+ tokenInstance: Token,
19
+ api?:TokenApiOptions
20
+ }
21
+ db?:{
22
+ entities:MixedList<Function | string |EntitySchema>,
23
+ migrations?:string[],
24
+ sync?:boolean,
25
+ afterDbConnection?:() => Promise<void>
26
+ },
27
+ }
28
+
29
+
30
+
31
+ export type SocketWrapperConstructor = {
32
+ name:string,
33
+ beforeConnection?:() => Promise<void>
34
+ onDisconnect?:(...params:any[]) => Promise<void>
35
+ listeners?:Record<string, (...params:any[]) => Promise<void>>
36
+ }
@@ -0,0 +1,375 @@
1
+ export interface Info {
2
+ title: string;
3
+ version: string;
4
+ description?: string | undefined;
5
+ termsOfService?: string | undefined;
6
+ contact?: Contact | undefined;
7
+ license?: License | undefined;
8
+ }
9
+
10
+ export interface Contact {
11
+ name?: string | undefined;
12
+ email?: string | undefined;
13
+ url?: string | undefined;
14
+ }
15
+
16
+ export interface License {
17
+ name: string;
18
+ url?: string | undefined;
19
+ }
20
+
21
+ export interface ExternalDocs {
22
+ url: string;
23
+ description?: string | undefined;
24
+ }
25
+
26
+ export interface Tag {
27
+ name: string;
28
+ description?: string | undefined;
29
+ externalDocs?: ExternalDocs | undefined;
30
+ }
31
+
32
+ export interface Header extends BaseSchema {
33
+ type: ParameterType;
34
+ }
35
+
36
+ // ----------------------------- Parameter -----------------------------------
37
+
38
+ export type ParameterType = "string" | "number" | "integer" | "boolean" | "array" | "object" | "file" | "date";
39
+
40
+ export type BaseParameter = {
41
+ name: string;
42
+ in: "body" | "query" | "path" | "header" | "formData";
43
+ required?: boolean | undefined;
44
+ description?: string | undefined;
45
+ };
46
+
47
+ export type BodyParameter = BaseParameter & {
48
+ in: "body";
49
+ schema?: Schema | undefined;
50
+ };
51
+
52
+ export type GenericFormat = {
53
+ type?: ParameterType | undefined;
54
+ format?: string | undefined;
55
+ };
56
+
57
+ export type IntegerFormat = {
58
+ type: "integer";
59
+ format?: "int32" | "int64" | undefined;
60
+ };
61
+
62
+ export type NumberFormat = {
63
+ type: "number";
64
+ format?: "float" | "double" | undefined;
65
+ };
66
+
67
+ export type StringFormat = {
68
+ type: "string";
69
+ format?: "" | "byte" | "binary" | "date" | "date-time" | "password" | undefined;
70
+ };
71
+
72
+ export type SchemaFormatConstraints = GenericFormat | IntegerFormat | NumberFormat | StringFormat;
73
+ export type BaseFormatContrainedParameter = BaseParameter & SchemaFormatConstraints;
74
+ export type ParameterCollectionFormat = "csv" | "ssv" | "tsv" | "pipes" | "multi";
75
+
76
+ export type QueryParameter =
77
+ & BaseFormatContrainedParameter
78
+ & BaseSchema
79
+ & {
80
+ in: "query";
81
+ allowEmptyValue?: boolean | undefined;
82
+ collectionFormat?: ParameterCollectionFormat | undefined;
83
+ };
84
+
85
+ export type PathParameter =
86
+ & BaseFormatContrainedParameter
87
+ & BaseSchema
88
+ & {
89
+ in: "path";
90
+ required: boolean;
91
+ };
92
+
93
+ export type HeaderParameter =
94
+ & BaseFormatContrainedParameter
95
+ & BaseSchema
96
+ & {
97
+ in: "header";
98
+ };
99
+
100
+ export type FormDataParameter =
101
+ & BaseFormatContrainedParameter
102
+ & BaseSchema
103
+ & {
104
+ in: "formData";
105
+ type: ParameterType | "file";
106
+ allowEmptyValue?: boolean | undefined;
107
+ collectionFormat?: ParameterCollectionFormat | undefined;
108
+ };
109
+
110
+ export type Parameter = { like?:boolean} & (BodyParameter | FormDataParameter | QueryParameter | PathParameter | HeaderParameter);
111
+
112
+ // ------------------------------- Path --------------------------------------
113
+ export interface Path {
114
+ $ref?: string | undefined;
115
+ get?: Operation | undefined;
116
+ put?: Operation | undefined;
117
+ post?: Operation | undefined;
118
+ delete?: Operation | undefined;
119
+ options?: Operation | undefined;
120
+ head?: Operation | undefined;
121
+ patch?: Operation | undefined;
122
+ parameters?: Array<Parameter | Reference> | undefined;
123
+ }
124
+
125
+
126
+
127
+ export interface DynamicSwaggerPath {
128
+ $ref?: string | undefined;
129
+ get?: DynamicSwaggerOperation | undefined;
130
+ put?: DynamicSwaggerOperationBody | undefined;
131
+ post?: DynamicSwaggerOperationBody | undefined;
132
+ delete?: DynamicSwaggerOperationBody | undefined;
133
+ options?: DynamicSwaggerOperation | undefined;
134
+ head?: DynamicSwaggerOperation | undefined;
135
+ patch?: DynamicSwaggerOperation | undefined;
136
+ parameters?: Array<Parameter | Reference> | undefined;
137
+ }
138
+
139
+
140
+
141
+ // ----------------------------- Components -----------------------------------
142
+ export interface Components {
143
+ schemas?: { [schemaName: string]: SchemaV3 };
144
+ parameters?: { [parameterName: string]: Parameter };
145
+ securitySchemes?:Record<string, {
146
+ type: 'http',
147
+ scheme: 'bearer',
148
+ bearerFormat?: 'JWT'
149
+ }>
150
+ }
151
+
152
+
153
+
154
+ // ----------------------------- Operation -----------------------------------
155
+ export interface Operation {
156
+ responses: { [responseName: string]: Response | Reference };
157
+ summary?: string | undefined;
158
+ description?: string | undefined;
159
+ externalDocs?: ExternalDocs | undefined;
160
+ operationId?: string | undefined;
161
+ produces?: string[] | undefined;
162
+ consumes?: string[] | undefined;
163
+ parameters?: Array<Parameter | Reference> | undefined;
164
+ schemes?: string[] | undefined;
165
+ deprecated?: boolean | undefined;
166
+ security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
167
+ tags?: string[] | undefined;
168
+ requestBody?:RequestBodyOperation
169
+ }
170
+
171
+ export interface DynamicSwaggerOperation {
172
+ responses: { [responseName: string]: Response | Reference };
173
+ summary?: string | undefined;
174
+ description?: string | undefined;
175
+ operationId?: string | undefined;
176
+ parameters?: Array<Parameter | Reference> | undefined;
177
+ deprecated?: boolean | undefined;
178
+ security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
179
+ tags?: string[] | undefined;
180
+ }
181
+ export interface DynamicSwaggerOperationBody {
182
+ responses: { [responseName: string]: Response | Reference };
183
+ summary?: string | undefined;
184
+ description?: string | undefined;
185
+ operationId?: string | undefined;
186
+ parameters?: Array<Parameter | Reference> | undefined;
187
+ deprecated?: boolean | undefined;
188
+ security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
189
+ tags?: string[] | undefined;
190
+ requestBody?:{
191
+ required:boolean,
192
+ description?:string,
193
+ schemaName:string,
194
+ schema?:{ [key:string]: SchemaV3 },
195
+ comType?:'multipart/form-data' | 'application/json' | undefined;
196
+ }
197
+ }
198
+
199
+
200
+
201
+
202
+ export type RequestBodyOperation = {
203
+ description?: string;
204
+ required:boolean;
205
+ content: {
206
+ "application/json": {
207
+ schema: { $ref: string }
208
+ }
209
+ }
210
+ | {
211
+ "multipart/form-data": {
212
+ schema: { $ref: string }
213
+ }
214
+ };
215
+ }
216
+ export type DynamicSwaggerRequestBodyOperation = {
217
+ description?: string;
218
+ required:boolean;
219
+ content: {
220
+ "application/json": {
221
+ schema: { $ref: string }
222
+ }
223
+ }
224
+ }
225
+ // ----------------------------- Reference -----------------------------------
226
+ export interface Reference {
227
+ $ref: string;
228
+ }
229
+
230
+ // ----------------------------- Response ------------------------------------
231
+ export interface Response {
232
+ description: string;
233
+ schema?: Schema | undefined;
234
+ headers?: { [headerName: string]: Header } | undefined;
235
+ examples?: { [exampleName: string]: {} } | undefined;
236
+ }
237
+
238
+ // ------------------------------ Schema -------------------------------------
239
+ export type BaseSchema = {
240
+ type?: ParameterType | undefined;
241
+ format?: string | undefined;
242
+ title?: string | undefined;
243
+ description?: string | undefined;
244
+ default?: any;
245
+ multipleOf?: number | undefined;
246
+ maximum?: number | undefined;
247
+ exclusiveMaximum?: boolean | undefined;
248
+ minimum?: number | undefined;
249
+ exclusiveMinimum?: boolean | undefined;
250
+ maxLength?: number | undefined;
251
+ minLength?: number | undefined;
252
+ pattern?: string | undefined;
253
+ maxItems?: number | undefined;
254
+ minItems?: number | undefined;
255
+ uniqueItems?: boolean | undefined;
256
+ maxProperties?: number | undefined;
257
+ minProperties?: number | undefined;
258
+ enum?: any[] | undefined;
259
+ items?: Schema | Schema[] | undefined;
260
+ };
261
+
262
+ export interface Schema extends BaseSchema {
263
+ $ref?: string | undefined;
264
+ allOf?: Schema[] | undefined;
265
+ additionalProperties?: Schema | boolean | undefined;
266
+ properties?: { [propertyName: string]: Schema } | undefined;
267
+ discriminator?: string | undefined;
268
+ readOnly?: boolean | undefined;
269
+ xml?: XML | undefined;
270
+ externalDocs?: ExternalDocs | undefined;
271
+ example?: any;
272
+ required?:boolean;
273
+ }
274
+
275
+ export interface SchemaV3 extends BaseSchema {
276
+ type:"object"
277
+ properties?: { [propertyName: string]: Schema } | undefined;
278
+ required?:boolean;
279
+ }
280
+
281
+ export interface XML {
282
+ name?: string | undefined;
283
+ namespace?: string | undefined;
284
+ prefix?: string | undefined;
285
+ attribute?: boolean | undefined;
286
+ wrapped?: boolean | undefined;
287
+ }
288
+
289
+ // ----------------------------- Security ------------------------------------
290
+ export interface BaseSecurity {
291
+ type: "basic" | "apiKey" | "oauth2";
292
+ description?: string | undefined;
293
+ }
294
+
295
+ export interface BasicAuthenticationSecurity extends BaseSecurity {
296
+ type: "basic";
297
+ }
298
+
299
+ export interface ApiKeySecurity extends BaseSecurity {
300
+ type: "apiKey";
301
+ name: string;
302
+ in: "query" | "header";
303
+ }
304
+
305
+ export interface BaseOAuthSecurity extends BaseSecurity {
306
+ type: "oauth2";
307
+ flow: "accessCode" | "application" | "implicit" | "password";
308
+ scopes?: OAuthScope | undefined;
309
+ }
310
+
311
+ export interface OAuth2ImplicitSecurity extends BaseOAuthSecurity {
312
+ type: "oauth2";
313
+ flow: "implicit";
314
+ authorizationUrl: string;
315
+ }
316
+
317
+ export interface OAuth2PasswordSecurity extends BaseOAuthSecurity {
318
+ type: "oauth2";
319
+ flow: "password";
320
+ tokenUrl: string;
321
+ }
322
+
323
+ export interface OAuth2ApplicationSecurity extends BaseOAuthSecurity {
324
+ type: "oauth2";
325
+ flow: "application";
326
+ tokenUrl: string;
327
+ }
328
+
329
+ export interface OAuth2AccessCodeSecurity extends BaseOAuthSecurity {
330
+ type: "oauth2";
331
+ flow: "accessCode";
332
+ tokenUrl: string;
333
+ authorizationUrl: string;
334
+ }
335
+
336
+ export interface OAuthScope {
337
+ [scopeName: string]: string;
338
+ }
339
+
340
+ export type Security =
341
+ | BasicAuthenticationSecurity
342
+ | OAuth2AccessCodeSecurity
343
+ | OAuth2ApplicationSecurity
344
+ | OAuth2ImplicitSecurity
345
+ | OAuth2PasswordSecurity
346
+ | ApiKeySecurity;
347
+
348
+ // --------------------------------- Spec ------------------------------------
349
+ export type Server = {
350
+ url:string;
351
+ description?:string;
352
+ }
353
+
354
+
355
+ export interface Spec {
356
+ openapi:"3.0.4";
357
+ info: Info;
358
+ servers: Server[];
359
+ paths: { [pathName: string]: Path };
360
+ tags?: Tag[];
361
+ components?:Components;
362
+
363
+ externalDocs?: ExternalDocs | undefined;
364
+ host?: string | undefined;
365
+ basePath?: string | undefined;
366
+ schemes?: string[] | undefined;
367
+ consumes?: string[] | undefined;
368
+ produces?: string[] | undefined;
369
+ definitions?: { [definitionsName: string]: Schema } | undefined;
370
+ parameters?: { [parameterName: string]: BodyParameter | QueryParameter } | undefined;
371
+ responses?: { [responseName: string]: Response } | undefined;
372
+ security?: Array<{ [securityDefinitionName: string]: string[] }> | undefined;
373
+ securityDefinitions?: { [securityDefinitionName: string]: Security } | undefined;
374
+
375
+ }
@@ -0,0 +1,20 @@
1
+ import { Request, Response } from "express"
2
+ import { Methods } from "./generic.sptypes"
3
+
4
+ export type DefaultTokenPayload = { id: string, [key:string]:any }
5
+
6
+ export type SecureTokenConfig = boolean | { [columnName:string]:{
7
+ tokenKey:string,
8
+ methods:"*" | Array<Methods | "LIST">
9
+ } }
10
+
11
+
12
+ export type TokenConstructor =
13
+ {
14
+ SECRET_KEY:string,
15
+ ExpTime:number,
16
+ EncAlgorithm:string // https://github.com/panva/jose/issues/210#jwe-alg
17
+ KeyLength:number
18
+ }
19
+
20
+ export type TokenApiOptions = { path?:string, callback:(req:Request, res:Response) => Promise<void> }