express-zod-api 4.1.0 → 5.1.0-beta1
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 +67 -0
- package/README.md +34 -3
- package/SECURITY.md +2 -1
- package/dist/config-type.d.ts +6 -0
- package/dist/config-type.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/mock.d.ts +30 -0
- package/dist/mock.js +56 -0
- package/dist/mock.js.map +1 -0
- 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/index.js +1 -0
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/mock.js +52 -0
- package/dist-esm/mock.js.map +1 -0
- 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 +15 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Version 5
|
|
4
|
+
|
|
5
|
+
### v5.1.0-beta1
|
|
6
|
+
|
|
7
|
+
- Feature #252: a helper method for testing your endpoints: `testEndpoint()`.
|
|
8
|
+
- Requires `jest` (and optionally `@types/jest`) to be installed.
|
|
9
|
+
- The method helps to mock the request, response, config and logger required to execute the endpoint.
|
|
10
|
+
- The method executes the endpoint and returns the created mocks.
|
|
11
|
+
- After that you only need to assert your expectations in the test.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { testEndpoint } from "express-zod-api";
|
|
15
|
+
|
|
16
|
+
test("should respond successfully", async () => {
|
|
17
|
+
const { responseMock, loggerMock } = await testEndpoint({
|
|
18
|
+
endpoint: yourEndpoint,
|
|
19
|
+
requestProps: {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: { ... },
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
expect(loggerMock.error).toBeCalledTimes(0);
|
|
25
|
+
expect(responseMock.status).toBeCalledWith(200);
|
|
26
|
+
expect(responseMock.json).toBeCalledWith({
|
|
27
|
+
status: "success",
|
|
28
|
+
data: { ... },
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### v5.0.0
|
|
34
|
+
|
|
35
|
+
- No changes.
|
|
36
|
+
|
|
37
|
+
### v5.0.0-beta1
|
|
38
|
+
|
|
39
|
+
- The ability to configure and run an additional HTTPS server to process requests over a secure protocol.
|
|
40
|
+
- This option is only available when using `createServer()` method.
|
|
41
|
+
- **Breaking changes**: Instead of HTTP Server the method `createServer()` now returns an object with the following
|
|
42
|
+
entities: `app, httpServer, httpsServer, logger`.
|
|
43
|
+
- New configuration option `https`:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { createConfig } from "express-zod-api";
|
|
47
|
+
|
|
48
|
+
const config = createConfig({
|
|
49
|
+
server: {
|
|
50
|
+
listen: 80,
|
|
51
|
+
},
|
|
52
|
+
// enables HTTPS server as well
|
|
53
|
+
https: {
|
|
54
|
+
// at least "cert" and "key" options required
|
|
55
|
+
options: {
|
|
56
|
+
cert: fs.readFileSync("fullchain.pem", "utf-8"),
|
|
57
|
+
key: fs.readFileSync("privkey.pem", "utf-8"),
|
|
58
|
+
},
|
|
59
|
+
listen: 443, // port or socket
|
|
60
|
+
},
|
|
61
|
+
// ...
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
3
65
|
## Version 4
|
|
4
66
|
|
|
67
|
+
### v4.2.0
|
|
68
|
+
|
|
69
|
+
- `express` version is 4.17.2.
|
|
70
|
+
- `http-errors` version is 2.0.0.
|
|
71
|
+
|
|
5
72
|
### v4.1.0
|
|
6
73
|
|
|
7
74
|
- Feature #230. The shorthand method `EndpointsFactory::addOptions()`.
|
package/README.md
CHANGED
|
@@ -38,14 +38,15 @@ Start your API server with I/O schema validation and custom middlewares in minut
|
|
|
38
38
|
10. [Usage with your own express app](#usage-with-your-own-express-app)
|
|
39
39
|
11. [Multiple schemas for one route](#multiple-schemas-for-one-route)
|
|
40
40
|
12. [Customizing input sources](#customizing-input-sources)
|
|
41
|
-
13. [
|
|
42
|
-
14. [
|
|
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)
|
|
43
44
|
5. [Known issues](#known-issues)
|
|
44
45
|
1. [Excessive properties in endpoint output](#excessive-properties-in-endpoint-output)
|
|
45
46
|
6. [Your input to my output](#your-input-to-my-output)
|
|
46
47
|
|
|
47
48
|
You can find the release notes in [Changelog](CHANGELOG.md). Along with recommendations for migrating from
|
|
48
|
-
[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).
|
|
49
50
|
|
|
50
51
|
# Why and what is it for
|
|
51
52
|
|
|
@@ -573,6 +574,36 @@ createConfig({
|
|
|
573
574
|
});
|
|
574
575
|
```
|
|
575
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
|
+
|
|
576
607
|
## Exporting endpoint types to frontend
|
|
577
608
|
|
|
578
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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { createServer, attachRouting } from "./server";
|
|
|
12
12
|
export { OpenAPI } from "./open-api";
|
|
13
13
|
export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors";
|
|
14
14
|
export { withMeta } from "./metadata";
|
|
15
|
+
export { testEndpoint } from "./mock";
|
|
15
16
|
import * as z from "./extend-zod";
|
|
16
17
|
import createHttpError from "http-errors";
|
|
17
18
|
export { createHttpError, z };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.z = exports.createHttpError = exports.withMeta = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.markOutput = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
|
|
25
|
+
exports.z = exports.createHttpError = exports.testEndpoint = exports.withMeta = exports.RoutingError = exports.DependsOnMethodError = exports.OpenAPIError = exports.OpenAPI = exports.attachRouting = exports.createServer = exports.DependsOnMethod = exports.defaultResultHandler = exports.createResultHandler = exports.createMiddleware = exports.createLogger = exports.createApiResponse = exports.markOutput = exports.defaultEndpointsFactory = exports.EndpointsFactory = exports.AbstractEndpoint = exports.createConfig = void 0;
|
|
26
26
|
var config_type_1 = require("./config-type");
|
|
27
27
|
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_type_1.createConfig; } });
|
|
28
28
|
var endpoint_1 = require("./endpoint");
|
|
@@ -54,6 +54,8 @@ Object.defineProperty(exports, "DependsOnMethodError", { enumerable: true, get:
|
|
|
54
54
|
Object.defineProperty(exports, "RoutingError", { enumerable: true, get: function () { return errors_1.RoutingError; } });
|
|
55
55
|
var metadata_1 = require("./metadata");
|
|
56
56
|
Object.defineProperty(exports, "withMeta", { enumerable: true, get: function () { return metadata_1.withMeta; } });
|
|
57
|
+
var mock_1 = require("./mock");
|
|
58
|
+
Object.defineProperty(exports, "testEndpoint", { enumerable: true, get: function () { return mock_1.testEndpoint; } });
|
|
57
59
|
const z = __importStar(require("./extend-zod"));
|
|
58
60
|
exports.z = z;
|
|
59
61
|
const http_errors_1 = __importDefault(require("http-errors"));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAKoB;AAJlB,4GAAA,gBAAgB,OAAA;AAMlB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAClD,mDAAoE;AAArC,4GAAA,UAAU,OAAA;AACzC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,mDAA6E;AAApE,qHAAA,mBAAmB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAClD,qCAAqD;AAAnC,0GAAA,eAAe,OAAA;AACjC,mCAAuD;AAA9C,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AACpC,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAChB,mCAA4E;AAAnE,sGAAA,YAAY,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACzD,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2D;AAAlD,2GAAA,YAAY,OAAA;AACrB,uCAKoB;AAJlB,4GAAA,gBAAgB,OAAA;AAMlB,yDAAgF;AAAvE,qHAAA,gBAAgB,OAAA;AAAE,4HAAA,uBAAuB,OAAA;AAClD,mDAAoE;AAArC,4GAAA,UAAU,OAAA;AACzC,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA;AAC1B,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAgD;AAAvC,8GAAA,gBAAgB,OAAA;AACzB,mDAA6E;AAApE,qHAAA,mBAAmB,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAClD,qCAAqD;AAAnC,0GAAA,eAAe,OAAA;AACjC,mCAAuD;AAA9C,sGAAA,YAAY,OAAA;AAAE,uGAAA,aAAa,OAAA;AACpC,uCAAqC;AAA5B,mGAAA,OAAO,OAAA;AAChB,mCAA4E;AAAnE,sGAAA,YAAY,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AACzD,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AAErB,gDAAkC;AAGR,cAAC;AAF3B,8DAA0C;AAEjC,0BAFF,qBAAe,CAEE"}
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="qs" />
|
|
2
|
+
/// <reference types="jest" />
|
|
3
|
+
import { Request, Response } from "express";
|
|
4
|
+
import { Logger } from "winston";
|
|
5
|
+
import { CommonConfig } from "./config-type";
|
|
6
|
+
import { AbstractEndpoint } from "./endpoint";
|
|
7
|
+
interface TestEndpointProps<REQ, RES, LOG> {
|
|
8
|
+
endpoint: AbstractEndpoint;
|
|
9
|
+
requestProps?: REQ;
|
|
10
|
+
responseProps?: RES;
|
|
11
|
+
configProps?: Partial<CommonConfig>;
|
|
12
|
+
loggerProps?: LOG;
|
|
13
|
+
/** @deprecated for testing purposes only */
|
|
14
|
+
__noJest?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @description You need to install Jest and probably @types/jest to use this method
|
|
18
|
+
*/
|
|
19
|
+
export declare const testEndpoint: <REQ extends Partial<Record<keyof Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, any>> | undefined = undefined, RES extends Partial<Record<keyof Response<any, Record<string, any>>, any>> | undefined = undefined, LOG extends Partial<Record<keyof Logger, any>> | undefined = undefined>({ endpoint, requestProps, responseProps, configProps, loggerProps, __noJest, }: TestEndpointProps<REQ, RES, LOG>) => Promise<{
|
|
20
|
+
requestMock: {
|
|
21
|
+
method: string;
|
|
22
|
+
} & Record<"header", jest.Mock<any, any>> & (REQ extends undefined ? {} : REQ);
|
|
23
|
+
responseMock: {
|
|
24
|
+
writableEnded: boolean;
|
|
25
|
+
statusCode: number;
|
|
26
|
+
statusMessage: string;
|
|
27
|
+
} & Record<"json" | "status" | "set" | "end", jest.Mock<any, any>> & (RES extends undefined ? {} : RES);
|
|
28
|
+
loggerMock: Record<"error" | "warn" | "debug" | "info", jest.Mock<any, any>> & (LOG extends undefined ? {} : LOG);
|
|
29
|
+
}>;
|
|
30
|
+
export {};
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.testEndpoint = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
const mime_1 = require("./mime");
|
|
6
|
+
/**
|
|
7
|
+
* @description You need to install Jest and probably @types/jest to use this method
|
|
8
|
+
*/
|
|
9
|
+
const testEndpoint = async ({ endpoint, requestProps, responseProps, configProps, loggerProps, __noJest, }) => {
|
|
10
|
+
if (!jest || __noJest) {
|
|
11
|
+
throw new Error("You need to install Jest in order to use testEndpoint().");
|
|
12
|
+
}
|
|
13
|
+
const requestMock = {
|
|
14
|
+
method: "GET",
|
|
15
|
+
header: jest.fn(() => mime_1.mimeJson),
|
|
16
|
+
...requestProps,
|
|
17
|
+
};
|
|
18
|
+
const responseMock = {
|
|
19
|
+
writableEnded: false,
|
|
20
|
+
statusCode: 200,
|
|
21
|
+
statusMessage: (0, index_1.createHttpError)(200).message,
|
|
22
|
+
set: jest.fn(() => responseMock),
|
|
23
|
+
status: jest.fn((value) => {
|
|
24
|
+
responseMock.statusCode = value;
|
|
25
|
+
responseMock.statusMessage = (0, index_1.createHttpError)(value).message;
|
|
26
|
+
return responseMock;
|
|
27
|
+
}),
|
|
28
|
+
json: jest.fn(() => responseMock),
|
|
29
|
+
end: jest.fn(() => {
|
|
30
|
+
responseMock.writableEnded = true;
|
|
31
|
+
return responseMock;
|
|
32
|
+
}),
|
|
33
|
+
...responseProps,
|
|
34
|
+
};
|
|
35
|
+
const loggerMock = {
|
|
36
|
+
info: jest.fn(),
|
|
37
|
+
warn: jest.fn(),
|
|
38
|
+
error: jest.fn(),
|
|
39
|
+
debug: jest.fn(),
|
|
40
|
+
...loggerProps,
|
|
41
|
+
};
|
|
42
|
+
const configMock = {
|
|
43
|
+
cors: false,
|
|
44
|
+
logger: loggerMock,
|
|
45
|
+
...configProps,
|
|
46
|
+
};
|
|
47
|
+
await endpoint.execute({
|
|
48
|
+
request: requestMock,
|
|
49
|
+
response: responseMock,
|
|
50
|
+
config: configMock,
|
|
51
|
+
logger: loggerMock,
|
|
52
|
+
});
|
|
53
|
+
return { requestMock, responseMock, loggerMock };
|
|
54
|
+
};
|
|
55
|
+
exports.testEndpoint = testEndpoint;
|
|
56
|
+
//# sourceMappingURL=mock.js.map
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;QACC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,QAAQ,CAAC,OAAO,CAAC;QACrB,OAAO,EAAE,WAAiC;QAC1C,QAAQ,EAAE,YAAmC;QAC7C,MAAM,EAAE,UAA0B;QAClC,MAAM,EAAE,UAA+B;KACxC,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACnD,CAAC,CAAC;AArEW,QAAA,YAAY,gBAqEvB"}
|
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
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,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C;IAEd,GAAG,CAAC,GAAG,CAAE,CAAC,UAAU,CAAsB,CAAC,MAAM,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1E,GAAG,CAAC,GAAG,CAAC,IAAA,kCAA0B,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1D,IAAA,qBAAW,EAAC,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9C,GAAG,CAAC,GAAG,CAAC,IAAA,6BAAqB,EAAC,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,eAAK;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;AAvCD,oCAuCC"}
|
package/dist/startup-logo.js
CHANGED
|
@@ -17,7 +17,7 @@ const getStartupLogo = () => {
|
|
|
17
17
|
[95m8888888888 888 888 88888P" 888 "Y8888 88888P' 88888P' d8888888888 "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"}
|
package/dist-esm/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { createServer, attachRouting } from "./server.js";
|
|
|
11
11
|
export { OpenAPI } from "./open-api.js";
|
|
12
12
|
export { OpenAPIError, DependsOnMethodError, RoutingError } from "./errors.js";
|
|
13
13
|
export { withMeta } from "./metadata.js";
|
|
14
|
+
export { testEndpoint } from "./mock.js";
|
|
14
15
|
import * as z from "./extend-zod.js";
|
|
15
16
|
import createHttpError from "http-errors";
|
|
16
17
|
export { createHttpError, z };
|
package/dist-esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,gBAAgB,GAIjB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAwB,UAAU,EAAE,MAAM,kBAAkB,CAAC;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,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,eAAe,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC"}
|
package/dist-esm/mock.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHttpError } from "./index.js";
|
|
2
|
+
import { mimeJson } from "./mime.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description You need to install Jest and probably @types/jest to use this method
|
|
5
|
+
*/
|
|
6
|
+
export const testEndpoint = async ({ endpoint, requestProps, responseProps, configProps, loggerProps, __noJest, }) => {
|
|
7
|
+
if (!jest || __noJest) {
|
|
8
|
+
throw new Error("You need to install Jest in order to use testEndpoint().");
|
|
9
|
+
}
|
|
10
|
+
const requestMock = {
|
|
11
|
+
method: "GET",
|
|
12
|
+
header: jest.fn(() => mimeJson),
|
|
13
|
+
...requestProps,
|
|
14
|
+
};
|
|
15
|
+
const responseMock = {
|
|
16
|
+
writableEnded: false,
|
|
17
|
+
statusCode: 200,
|
|
18
|
+
statusMessage: createHttpError(200).message,
|
|
19
|
+
set: jest.fn(() => responseMock),
|
|
20
|
+
status: jest.fn((value) => {
|
|
21
|
+
responseMock.statusCode = value;
|
|
22
|
+
responseMock.statusMessage = createHttpError(value).message;
|
|
23
|
+
return responseMock;
|
|
24
|
+
}),
|
|
25
|
+
json: jest.fn(() => responseMock),
|
|
26
|
+
end: jest.fn(() => {
|
|
27
|
+
responseMock.writableEnded = true;
|
|
28
|
+
return responseMock;
|
|
29
|
+
}),
|
|
30
|
+
...responseProps,
|
|
31
|
+
};
|
|
32
|
+
const loggerMock = {
|
|
33
|
+
info: jest.fn(),
|
|
34
|
+
warn: jest.fn(),
|
|
35
|
+
error: jest.fn(),
|
|
36
|
+
debug: jest.fn(),
|
|
37
|
+
...loggerProps,
|
|
38
|
+
};
|
|
39
|
+
const configMock = {
|
|
40
|
+
cors: false,
|
|
41
|
+
logger: loggerMock,
|
|
42
|
+
...configProps,
|
|
43
|
+
};
|
|
44
|
+
await endpoint.execute({
|
|
45
|
+
request: requestMock,
|
|
46
|
+
response: responseMock,
|
|
47
|
+
config: configMock,
|
|
48
|
+
logger: loggerMock,
|
|
49
|
+
});
|
|
50
|
+
return { requestMock, responseMock, loggerMock };
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAYlC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAI/B,EACA,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,WAAW,EACX,WAAW,EACX,QAAQ,GACyB,EAAE,EAAE;IACrC,IAAI,CAAC,IAAI,IAAI,QAAQ,EAAE;QACrB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC7E;IACD,MAAM,WAAW,GAGhB;QACC,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC;QAC/B,GAAG,YAAY;KAChB,CAAC;IACF,MAAM,YAAY,GAOjB;QACC,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,GAAG;QACf,aAAa,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO;QAC3C,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QAChC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;YACxB,YAAY,CAAC,UAAU,GAAG,KAAK,CAAC;YAChC,YAAY,CAAC,aAAa,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;YAC5D,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;QACjC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YAChB,YAAY,CAAC,aAAa,GAAG,IAAI,CAAC;YAClC,OAAO,YAAY,CAAC;QACtB,CAAC,CAAC;QACF,GAAG,aAAa;KACjB,CAAC;IACF,MAAM,UAAU,GAGf;QACC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;QAChB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,UAAU;QAClB,GAAG,WAAW;KACf,CAAC;IACF,MAAM,QAAQ,CAAC,OAAO,CAAC;QACrB,OAAO,EAAE,WAAiC;QAC1C,QAAQ,EAAE,YAAmC;QAC7C,MAAM,EAAE,UAA0B;QAClC,MAAM,EAAE,UAA+B;KACxC,CAAC,CAAC;IACH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;AACnD,CAAC,CAAC"}
|
package/dist-esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"
|
|
1
|
+
{"type":"module","version":"5.1.0-beta1"}
|
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,Y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M,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1E,GAAG,CAAC,GAAG,CAAC,0BAA0B,CAAC,YAAY,EAAE,MAAM,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.1.0-beta1",
|
|
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",
|
|
@@ -44,6 +44,18 @@
|
|
|
44
44
|
"winston": "3.3.3",
|
|
45
45
|
"zod": "3.11.6"
|
|
46
46
|
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"jest": ">=25 <28",
|
|
49
|
+
"@types/jest": "*"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"jest": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@types/jest": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
47
59
|
"devDependencies": {
|
|
48
60
|
"@tsconfig/node12": "^1.0.9",
|
|
49
61
|
"@types/express": "^4.17.13",
|