express-zod-api 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/README.md +59 -13
- package/SECURITY.md +2 -1
- package/dist/config-type.d.ts +6 -0
- package/dist/config-type.js.map +1 -1
- package/dist/endpoints-factory.d.ts +1 -0
- package/dist/endpoints-factory.js +8 -0
- package/dist/endpoints-factory.js.map +1 -1
- package/dist/server.d.ts +7 -2
- package/dist/server.js +11 -1
- package/dist/server.js.map +1 -1
- package/dist/startup-logo.js +1 -1
- package/dist-esm/config-type.js.map +1 -1
- package/dist-esm/endpoints-factory.js +8 -0
- package/dist-esm/endpoints-factory.js.map +1 -1
- package/dist-esm/package.json +1 -1
- package/dist-esm/server.js +11 -1
- package/dist-esm/server.js.map +1 -1
- package/dist-esm/startup-logo.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,72 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Version 5
|
|
4
|
+
|
|
5
|
+
### v5.0.0
|
|
6
|
+
|
|
7
|
+
- No changes.
|
|
8
|
+
|
|
9
|
+
### v5.0.0-beta1
|
|
10
|
+
|
|
11
|
+
- The ability to configure and run an additional HTTPS server to process requests over a secure protocol.
|
|
12
|
+
- This option is only available when using `createServer()` method.
|
|
13
|
+
- **Breaking changes**: Instead of HTTP Server the method `createServer()` now returns an object with the following
|
|
14
|
+
entities: `app, httpServer, httpsServer, logger`.
|
|
15
|
+
- New configuration option `https`:
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { createConfig } from "express-zod-api";
|
|
19
|
+
|
|
20
|
+
const config = createConfig({
|
|
21
|
+
server: {
|
|
22
|
+
listen: 80,
|
|
23
|
+
},
|
|
24
|
+
// enables HTTPS server as well
|
|
25
|
+
https: {
|
|
26
|
+
// at least "cert" and "key" options required
|
|
27
|
+
options: {
|
|
28
|
+
cert: fs.readFileSync("fullchain.pem", "utf-8"),
|
|
29
|
+
key: fs.readFileSync("privkey.pem", "utf-8"),
|
|
30
|
+
},
|
|
31
|
+
listen: 443, // port or socket
|
|
32
|
+
},
|
|
33
|
+
// ...
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
3
37
|
## Version 4
|
|
4
38
|
|
|
39
|
+
### v4.2.0
|
|
40
|
+
|
|
41
|
+
- `express` version is 4.17.2.
|
|
42
|
+
- `http-errors` version is 2.0.0.
|
|
43
|
+
|
|
44
|
+
### v4.1.0
|
|
45
|
+
|
|
46
|
+
- Feature #230. The shorthand method `EndpointsFactory::addOptions()`.
|
|
47
|
+
- You may find it useful in case you'd like to provide your Endpoint's handler with some entities that do not depend
|
|
48
|
+
on Request, maybe a database connection instance of similar.
|
|
49
|
+
- Under the hood the method creates a middleware with an empty input and attaches it to the factory.
|
|
50
|
+
- The argument supplied to the method is available within `options` parameter of the Endpoint's `handler`.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { defaultEndpointsFactory } from "express-zod-api";
|
|
54
|
+
|
|
55
|
+
const newFactory = defaultEndpointsFactory.addOptions({
|
|
56
|
+
db: mongoose.connect("mongodb://connection.string"),
|
|
57
|
+
privateKey: fs.readFileSync("private-key.pem", "utf-8"),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const endpoint = newFactory.build({
|
|
61
|
+
method: "get",
|
|
62
|
+
input: z.object({}),
|
|
63
|
+
output: z.object({}),
|
|
64
|
+
handler: async ({ options }) => {
|
|
65
|
+
return {}; // options: { db, privateKey }
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
5
70
|
### v4.0.0
|
|
6
71
|
|
|
7
72
|
- The deprecated parameter `type` of `EndpointsFactory::build({...})` has been removed.
|
package/README.md
CHANGED
|
@@ -27,24 +27,26 @@ Start your API server with I/O schema validation and custom middlewares in minut
|
|
|
27
27
|
7. [Try it](#try-it)
|
|
28
28
|
4. [Fascinating features](#fascinating-features)
|
|
29
29
|
1. [Middlewares](#middlewares)
|
|
30
|
-
2. [
|
|
31
|
-
3. [
|
|
32
|
-
4. [
|
|
33
|
-
5. [
|
|
34
|
-
6. [
|
|
35
|
-
7. [
|
|
36
|
-
8. [
|
|
37
|
-
9. [
|
|
38
|
-
10. [
|
|
39
|
-
11. [
|
|
40
|
-
12. [
|
|
41
|
-
13. [
|
|
30
|
+
2. [Options](#options)
|
|
31
|
+
3. [Refinements](#refinements)
|
|
32
|
+
4. [Transformations](#transformations)
|
|
33
|
+
5. [Route path params](#route-path-params)
|
|
34
|
+
6. [Response customization](#response-customization)
|
|
35
|
+
7. [Non-object response](#non-object-response) including file downloads
|
|
36
|
+
8. [File uploads](#file-uploads)
|
|
37
|
+
9. [Customizing logger](#customizing-logger)
|
|
38
|
+
10. [Usage with your own express app](#usage-with-your-own-express-app)
|
|
39
|
+
11. [Multiple schemas for one route](#multiple-schemas-for-one-route)
|
|
40
|
+
12. [Customizing input sources](#customizing-input-sources)
|
|
41
|
+
13. [Enabling HTTPS](#enabling-https)
|
|
42
|
+
14. [Exporting endpoint types to frontend](#exporting-endpoint-types-to-frontend)
|
|
43
|
+
15. [Creating a documentation](#creating-a-documentation)
|
|
42
44
|
5. [Known issues](#known-issues)
|
|
43
45
|
1. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
|
|
44
46
|
6. [Your input to my output](#your-input-to-my-output)
|
|
45
47
|
|
|
46
48
|
You can find the release notes in [Changelog](CHANGELOG.md). Along with recommendations for migrating from
|
|
47
|
-
[v3](CHANGELOG.md#v400), [v2](CHANGELOG.md#v300-beta1) and [v1](CHANGELOG.md#v200-beta1).
|
|
49
|
+
[v4](CHANGELOG.md#v500-beta1), [v3](CHANGELOG.md#v400), [v2](CHANGELOG.md#v300-beta1) and [v1](CHANGELOG.md#v200-beta1).
|
|
48
50
|
|
|
49
51
|
# Why and what is it for
|
|
50
52
|
|
|
@@ -265,6 +267,20 @@ const endpointsFactory = defaultEndpointsFactory.addMiddleware(authMiddleware);
|
|
|
265
267
|
|
|
266
268
|
You can connect as many middlewares as you want, they will be executed in order.
|
|
267
269
|
|
|
270
|
+
## Options
|
|
271
|
+
|
|
272
|
+
In case you'd like to provide your endpoints with options that do not depend on Request, like database connection
|
|
273
|
+
instance, consider shorthand method `addOptions`.
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { defaultEndpointsFactory } from "express-zod-api";
|
|
277
|
+
|
|
278
|
+
const endpointsFactory = defaultEndpointsFactory.addOptions({
|
|
279
|
+
db: mongoose.connect("mongodb://connection.string"),
|
|
280
|
+
privateKey: fs.readFileSync("private-key.pem", "utf-8"),
|
|
281
|
+
});
|
|
282
|
+
```
|
|
283
|
+
|
|
268
284
|
## Refinements
|
|
269
285
|
|
|
270
286
|
By the way, you can implement additional validation within schema.
|
|
@@ -558,6 +574,36 @@ createConfig({
|
|
|
558
574
|
});
|
|
559
575
|
```
|
|
560
576
|
|
|
577
|
+
## Enabling HTTPS
|
|
578
|
+
|
|
579
|
+
The modern API standard often assumes the use of a secure data transfer protocol, confirmed by a TLS certificate, also
|
|
580
|
+
often called an SSL certificate in habit. When using the `createServer()` method, you can additionally configure and
|
|
581
|
+
run the HTTPS server.
|
|
582
|
+
|
|
583
|
+
```typescript
|
|
584
|
+
import { createConfig, createServer } from "express-zod-api";
|
|
585
|
+
|
|
586
|
+
const config = createConfig({
|
|
587
|
+
server: {
|
|
588
|
+
listen: 80,
|
|
589
|
+
},
|
|
590
|
+
https: {
|
|
591
|
+
options: {
|
|
592
|
+
cert: fs.readFileSync("fullchain.pem", "utf-8"),
|
|
593
|
+
key: fs.readFileSync("privkey.pem", "utf-8"),
|
|
594
|
+
},
|
|
595
|
+
listen: 443, // port or socket
|
|
596
|
+
},
|
|
597
|
+
// ... cors, logger, etc
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
const { app, httpServer, httpsServer, logger } = createServer(config, routing);
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
At least you need to specify the port or socket (usually it is 443), certificate and the key, issued by the
|
|
604
|
+
certifying authority. For example, you can acquire a free TLS certificate for your API at
|
|
605
|
+
[Let's Encrypt](https://letsencrypt.org/).
|
|
606
|
+
|
|
561
607
|
## Exporting endpoint types to frontend
|
|
562
608
|
|
|
563
609
|
You can export only the types of your endpoints for your frontend. Here is an approach:
|
package/SECURITY.md
CHANGED
package/dist/config-type.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { NextHandleFunction } from "connect";
|
|
2
3
|
import { Express, Request } from "express";
|
|
3
4
|
import fileUpload from "express-fileupload";
|
|
5
|
+
import { ServerOptions } from "https";
|
|
4
6
|
import { Logger } from "winston";
|
|
5
7
|
import { Method } from "./method";
|
|
6
8
|
import { ResultHandlerDefinition } from "./result-handler";
|
|
@@ -20,6 +22,10 @@ export interface ServerConfig {
|
|
|
20
22
|
jsonParser?: NextHandleFunction;
|
|
21
23
|
upload?: boolean | UploadOptions;
|
|
22
24
|
};
|
|
25
|
+
https?: {
|
|
26
|
+
options: ServerOptions;
|
|
27
|
+
listen: number | string;
|
|
28
|
+
};
|
|
23
29
|
}
|
|
24
30
|
export interface AppConfig {
|
|
25
31
|
app: Express;
|
package/dist/config-type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":";;;AAQa,QAAA,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;AA0DK,MAAM,YAAY,GAAG,CAG1B,MAAS,EACN,EAAE,CAAC,MAAM,CAAC;AAJF,QAAA,YAAY,gBAIV"}
|
|
@@ -17,6 +17,7 @@ export declare class EndpointsFactory<MwIN, MwOUT, POS extends ApiResponse, NEG
|
|
|
17
17
|
protected middlewares: MiddlewareDefinition<any, any, any>[];
|
|
18
18
|
constructor(resultHandler: ResultHandlerDefinition<POS, NEG>);
|
|
19
19
|
addMiddleware<IN extends IOSchema, OUT extends FlatObject>(definition: MiddlewareDefinition<IN, MwOUT, OUT>): EndpointsFactory<Merge<IN, MwIN>, MwOUT & OUT, POS, NEG>;
|
|
20
|
+
addOptions<OUT extends FlatObject>(options: OUT): EndpointsFactory<MwIN, MwOUT & OUT, POS, NEG>;
|
|
20
21
|
build<IN extends IOSchema, OUT extends IOSchema, M extends Method>({ input, output, handler, description, ...rest }: BuildProps<IN, OUT, MwIN, MwOUT, M>): Endpoint<IN, OUT, MwIN, MwOUT, M, POS, NEG>;
|
|
21
22
|
}
|
|
22
23
|
export declare const defaultEndpointsFactory: EndpointsFactory<unknown, unknown, ApiResponse<z.ZodObject<{
|
|
@@ -7,8 +7,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
7
7
|
var _a, _EndpointsFactory_create;
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.defaultEndpointsFactory = exports.EndpointsFactory = void 0;
|
|
10
|
+
const zod_1 = require("zod");
|
|
10
11
|
const endpoint_1 = require("./endpoint");
|
|
11
12
|
const common_helpers_1 = require("./common-helpers");
|
|
13
|
+
const middleware_1 = require("./middleware");
|
|
12
14
|
const mime_1 = require("./mime");
|
|
13
15
|
const result_handler_1 = require("./result-handler");
|
|
14
16
|
class EndpointsFactory {
|
|
@@ -20,6 +22,12 @@ class EndpointsFactory {
|
|
|
20
22
|
addMiddleware(definition) {
|
|
21
23
|
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(definition), this.resultHandler);
|
|
22
24
|
}
|
|
25
|
+
addOptions(options) {
|
|
26
|
+
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat((0, middleware_1.createMiddleware)({
|
|
27
|
+
input: zod_1.z.object({}),
|
|
28
|
+
middleware: async () => options,
|
|
29
|
+
})), this.resultHandler);
|
|
30
|
+
}
|
|
23
31
|
build({ input, output, handler, description, ...rest }) {
|
|
24
32
|
return new endpoint_1.Endpoint({
|
|
25
33
|
handler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAwB;AAExB,yCAA+C;AAC/C,qDAA0E;AAE1E,6CAAsE;AACtE,iCAAiD;AACjD,qDAG0B;AAe1B,MAAa,gBAAgB;IAQ3B,YAAsB,aAAgD;QAAhD,kBAAa,GAAb,aAAa,CAAmC;QAF5D,gBAAW,GAA0C,EAAE,CAAC;QAGhE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAkBM,aAAa,CAClB,UAAgD;QAEhD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EACrB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EACnC,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAEM,UAAU,CAAyB,OAAY;QACpD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EACrB,IAAI,CAAC,WAAW,CAAC,MAAM,CACrB,IAAA,6BAAgB,EAAC;YACf,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO;SAChC,CAAC,CACH,EACD,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAEM,KAAK,CAA8D,EACxE,KAAK,EACL,MAAM,EACN,OAAO,EACP,WAAW,EACX,GAAG,IAAI,EAC6B;QACpC,OAAO,IAAI,mBAAQ,CAAoC;YACrD,OAAO;YACP,WAAW;YACX,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,MAAM;YACpB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAA,0BAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,oBAAa,CAAC,CAAC,CAAC,CAAC,CAAC,eAAQ,CAAC;YAC1D,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;AAnED,4CAmEC;oFAjDG,WAAkD,EAClD,aAAoD;IAEpD,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAClC,aAAa,CACd,CAAC;IACF,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AA2CU,QAAA,uBAAuB,GAAG,IAAI,gBAAgB,CACzD,qCAAoB,CACrB,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import express, { ErrorRequestHandler, RequestHandler } from "express";
|
|
4
|
-
import
|
|
4
|
+
import https from "https";
|
|
5
5
|
import { Logger } from "winston";
|
|
6
6
|
import { AppConfig, CommonConfig, ServerConfig } from "./config-type";
|
|
7
7
|
import { Routing } from "./routing";
|
|
@@ -11,4 +11,9 @@ export declare function attachRouting(config: AppConfig & CommonConfig, routing:
|
|
|
11
11
|
notFoundHandler: express.RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
12
12
|
logger: Logger;
|
|
13
13
|
};
|
|
14
|
-
export declare function createServer(config: ServerConfig & CommonConfig, routing: Routing):
|
|
14
|
+
export declare function createServer(config: ServerConfig & CommonConfig, routing: Routing): {
|
|
15
|
+
app: import("express-serve-static-core").Express;
|
|
16
|
+
httpServer: import("http").Server;
|
|
17
|
+
httpsServer: https.Server | undefined;
|
|
18
|
+
logger: Logger;
|
|
19
|
+
};
|
package/dist/server.js
CHANGED
|
@@ -25,6 +25,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.createServer = exports.attachRouting = exports.createNotFoundHandler = exports.createParserFailureHandler = void 0;
|
|
26
26
|
const express_1 = __importStar(require("express"));
|
|
27
27
|
const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
28
|
+
const https_1 = __importDefault(require("https"));
|
|
28
29
|
const errors_1 = require("./errors");
|
|
29
30
|
const common_helpers_1 = require("./common-helpers");
|
|
30
31
|
const logger_1 = require("./logger");
|
|
@@ -98,9 +99,18 @@ function createServer(config, routing) {
|
|
|
98
99
|
app.use((0, exports.createParserFailureHandler)(errorHandler, logger));
|
|
99
100
|
(0, routing_1.initRouting)({ app, routing, logger, config });
|
|
100
101
|
app.use((0, exports.createNotFoundHandler)(errorHandler, logger));
|
|
101
|
-
|
|
102
|
+
const httpServer = app.listen(config.server.listen, () => {
|
|
102
103
|
logger.info(`Listening ${config.server.listen}`);
|
|
103
104
|
});
|
|
105
|
+
let httpsServer;
|
|
106
|
+
if (config.https) {
|
|
107
|
+
httpsServer = https_1.default
|
|
108
|
+
.createServer(config.https.options, app)
|
|
109
|
+
.listen(config.https.listen, () => {
|
|
110
|
+
logger.info(`Listening ${config.https.listen}`);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return { app, httpServer, httpsServer, logger };
|
|
104
114
|
}
|
|
105
115
|
exports.createServer = createServer;
|
|
106
116
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA6E;AAC7E,4EAA4C;
|
|
1
|
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Y88P" "Y88888 d88P 888 888 8888888[39m[94m[39m
|
|
18
18
|
[94m 888[39m
|
|
19
19
|
[94m 888[3m Proudly supports transgender community.[23m[39m
|
|
20
|
-
[94m[3mfor
|
|
20
|
+
[94m[3mfor Ella [23m 888[3m Start your API server with I/O schema validation and custom middlewares in minutes.[23m[39m[90m[39m
|
|
21
21
|
[90m[3m Thank you for choosing Express Zod API for your project.[23m[39m[0m[0m
|
|
22
22
|
[0m[0m
|
|
23
23
|
[0m[0m
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config-type.js","sourceRoot":"","sources":["../src/config-type.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,IAAI;CACZ,CAAC;AA0DF,MAAM,CAAC,MAAM,YAAY,GAAG,CAG1B,MAAS,EACN,EAAE,CAAC,MAAM,CAAC"}
|
|
@@ -4,8 +4,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _a, _EndpointsFactory_create;
|
|
7
|
+
import { z } from "zod";
|
|
7
8
|
import { Endpoint } from "./endpoint.js";
|
|
8
9
|
import { hasUpload } from "./common-helpers.js";
|
|
10
|
+
import { createMiddleware } from "./middleware.js";
|
|
9
11
|
import { mimeJson, mimeMultipart } from "./mime.js";
|
|
10
12
|
import { defaultResultHandler, } from "./result-handler.js";
|
|
11
13
|
export class EndpointsFactory {
|
|
@@ -17,6 +19,12 @@ export class EndpointsFactory {
|
|
|
17
19
|
addMiddleware(definition) {
|
|
18
20
|
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(definition), this.resultHandler);
|
|
19
21
|
}
|
|
22
|
+
addOptions(options) {
|
|
23
|
+
return __classPrivateFieldGet(EndpointsFactory, _a, "m", _EndpointsFactory_create).call(EndpointsFactory, this.middlewares.concat(createMiddleware({
|
|
24
|
+
input: z.object({}),
|
|
25
|
+
middleware: async () => options,
|
|
26
|
+
})), this.resultHandler);
|
|
27
|
+
}
|
|
20
28
|
build({ input, output, handler, description, ...rest }) {
|
|
21
29
|
return new Endpoint({
|
|
22
30
|
handler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"endpoints-factory.js","sourceRoot":"","sources":["../src/endpoints-factory.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAW,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAwB,SAAS,EAAS,MAAM,kBAAkB,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAwB,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,oBAAoB,GAErB,MAAM,kBAAkB,CAAC;AAe1B,MAAM,OAAO,gBAAgB;IAQ3B,YAAsB,aAAgD;QAAhD,kBAAa,GAAb,aAAa,CAAmC;QAF5D,gBAAW,GAA0C,EAAE,CAAC;QAGhE,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAkBM,aAAa,CAClB,UAAgD;QAEhD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EACrB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EACnC,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAEM,UAAU,CAAyB,OAAY;QACpD,OAAO,uBAAA,gBAAgB,oCAAQ,MAAxB,gBAAgB,EACrB,IAAI,CAAC,WAAW,CAAC,MAAM,CACrB,gBAAgB,CAAC;YACf,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;YACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO;SAChC,CAAC,CACH,EACD,IAAI,CAAC,aAAa,CACnB,CAAC;IACJ,CAAC;IAEM,KAAK,CAA8D,EACxE,KAAK,EACL,MAAM,EACN,OAAO,EACP,WAAW,EACX,GAAG,IAAI,EAC6B;QACpC,OAAO,IAAI,QAAQ,CAAoC;YACrD,OAAO;YACP,WAAW;YACX,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,KAAK;YAClB,YAAY,EAAE,MAAM;YACpB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YAC1D,GAAG,IAAI;SACR,CAAC,CAAC;IACL,CAAC;CACF;oFAjDG,WAAkD,EAClD,aAAoD;IAEpD,MAAM,OAAO,GAAG,IAAI,gBAAgB,CAClC,aAAa,CACd,CAAC;IACF,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC;AA2CH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,gBAAgB,CACzD,oBAAoB,CACrB,CAAC"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"
|
|
1
|
+
{"type":"module","version":"5.0.0"}
|
package/dist-esm/server.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import express, { json } from "express";
|
|
2
2
|
import fileUpload from "express-fileupload";
|
|
3
|
+
import https from "https";
|
|
3
4
|
import { ResultHandlerError } from "./errors.js";
|
|
4
5
|
import { isLoggerConfig } from "./common-helpers.js";
|
|
5
6
|
import { createLogger } from "./logger.js";
|
|
@@ -70,8 +71,17 @@ export function createServer(config, routing) {
|
|
|
70
71
|
app.use(createParserFailureHandler(errorHandler, logger));
|
|
71
72
|
initRouting({ app, routing, logger, config });
|
|
72
73
|
app.use(createNotFoundHandler(errorHandler, logger));
|
|
73
|
-
|
|
74
|
+
const httpServer = app.listen(config.server.listen, () => {
|
|
74
75
|
logger.info(`Listening ${config.server.listen}`);
|
|
75
76
|
});
|
|
77
|
+
let httpsServer;
|
|
78
|
+
if (config.https) {
|
|
79
|
+
httpsServer = https
|
|
80
|
+
.createServer(config.https.options, app)
|
|
81
|
+
.listen(config.https.listen, () => {
|
|
82
|
+
logger.info(`Listening ${config.https.listen}`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return { app, httpServer, httpsServer, logger };
|
|
76
86
|
}
|
|
77
87
|
//# sourceMappingURL=server.js.map
|
package/dist-esm/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAuC,IAAI,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,UAAU,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAuC,IAAI,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,UAAU,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OA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M,CAAC,CAAC,CAAC;IAC1D,WAAW,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,GAAG,CAAC,GAAG,CAAC,qBAAqB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAErD,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE;QACvD,MAAM,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;IAEH,IAAI,WAAqC,CAAC;IAC1C,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,WAAW,GAAG,KAAK;aAChB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC;aACvC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,KAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;KACN;IAED,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAClD,CAAC"}
|
package/dist-esm/startup-logo.js
CHANGED
|
@@ -14,7 +14,7 @@ export const getStartupLogo = () => {
|
|
|
14
14
|
[95m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "Y88P" "Y88888 d88P 888 888 8888888[39m[94m[39m
|
|
15
15
|
[94m 888[39m
|
|
16
16
|
[94m 888[3m Proudly supports transgender community.[23m[39m
|
|
17
|
-
[94m[3mfor
|
|
17
|
+
[94m[3mfor Ella [23m 888[3m Start your API server with I/O schema validation and custom middlewares in minutes.[23m[39m[90m[39m
|
|
18
18
|
[90m[3m Thank you for choosing Express Zod API for your project.[23m[39m[0m[0m
|
|
19
19
|
[0m[0m
|
|
20
20
|
[0m[0m
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-zod-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A Typescript library to help you get an API server up and running with I/O schema validation and custom middlewares in minutes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"import": "./dist-esm/index.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"express": "4.17.
|
|
37
|
+
"express": "4.17.2",
|
|
38
38
|
"express-fileupload": "1.2.1",
|
|
39
|
-
"http-errors": "
|
|
39
|
+
"http-errors": "2.0.0",
|
|
40
40
|
"mime": "3.0.0",
|
|
41
41
|
"openapi3-ts": "2.0.1",
|
|
42
42
|
"ramda": "0.27.1",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"jest": "^27.3.1",
|
|
69
69
|
"make-coverage-badge": "^1.2.0",
|
|
70
70
|
"node-fetch": "^2.6.5",
|
|
71
|
-
"prettier": "2.5.
|
|
71
|
+
"prettier": "2.5.1",
|
|
72
72
|
"ts-jest": "^27.0.7",
|
|
73
73
|
"ts-node": "^10.4.0",
|
|
74
74
|
"tsd": "^0.19.0",
|