@spinajs/http 2.0.481 → 2.0.482
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/lib/cjs/config/http.d.ts.map +1 -1
- package/lib/cjs/config/http.js +11 -0
- package/lib/cjs/config/http.js.map +1 -1
- package/lib/cjs/controllers.d.ts.map +1 -1
- package/lib/cjs/controllers.js +48 -12
- package/lib/cjs/controllers.js.map +1 -1
- package/lib/cjs/decorators.d.ts +46 -4
- package/lib/cjs/decorators.d.ts.map +1 -1
- package/lib/cjs/decorators.js +127 -23
- package/lib/cjs/decorators.js.map +1 -1
- package/lib/cjs/error.js +3 -3
- package/lib/cjs/error.js.map +1 -1
- package/lib/cjs/file-middlewares/validation.d.ts +11 -0
- package/lib/cjs/file-middlewares/validation.d.ts.map +1 -1
- package/lib/cjs/file-middlewares/validation.js +52 -9
- package/lib/cjs/file-middlewares/validation.js.map +1 -1
- package/lib/cjs/file-middlewares/zip.d.ts.map +1 -1
- package/lib/cjs/file-middlewares/zip.js +6 -1
- package/lib/cjs/file-middlewares/zip.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +95 -1
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +100 -4
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middlewares/PerfRollup.d.ts +19 -0
- package/lib/cjs/middlewares/PerfRollup.d.ts.map +1 -0
- package/lib/cjs/middlewares/PerfRollup.js +61 -0
- package/lib/cjs/middlewares/PerfRollup.js.map +1 -0
- package/lib/cjs/middlewares/RequestId.d.ts +1 -2
- package/lib/cjs/middlewares/RequestId.d.ts.map +1 -1
- package/lib/cjs/middlewares/RequestId.js +19 -5
- package/lib/cjs/middlewares/RequestId.js.map +1 -1
- package/lib/cjs/middlewares/ResponseTime.d.ts +1 -2
- package/lib/cjs/middlewares/ResponseTime.d.ts.map +1 -1
- package/lib/cjs/middlewares/ResponseTime.js +29 -11
- package/lib/cjs/middlewares/ResponseTime.js.map +1 -1
- package/lib/cjs/response-methods/file.d.ts.map +1 -1
- package/lib/cjs/response-methods/file.js +47 -21
- package/lib/cjs/response-methods/file.js.map +1 -1
- package/lib/cjs/response-methods/index.d.ts +3 -0
- package/lib/cjs/response-methods/index.d.ts.map +1 -1
- package/lib/cjs/response-methods/index.js +3 -0
- package/lib/cjs/response-methods/index.js.map +1 -1
- package/lib/cjs/response-methods/redirect.d.ts +11 -4
- package/lib/cjs/response-methods/redirect.d.ts.map +1 -1
- package/lib/cjs/response-methods/redirect.js +14 -4
- package/lib/cjs/response-methods/redirect.js.map +1 -1
- package/lib/cjs/response-methods/xml.d.ts +17 -0
- package/lib/cjs/response-methods/xml.d.ts.map +1 -0
- package/lib/cjs/response-methods/xml.js +26 -0
- package/lib/cjs/response-methods/xml.js.map +1 -0
- package/lib/cjs/responses.d.ts +10 -0
- package/lib/cjs/responses.d.ts.map +1 -1
- package/lib/cjs/responses.js +94 -35
- package/lib/cjs/responses.js.map +1 -1
- package/lib/cjs/route-args/FromBody.d.ts.map +1 -1
- package/lib/cjs/route-args/FromBody.js +6 -1
- package/lib/cjs/route-args/FromBody.js.map +1 -1
- package/lib/cjs/route-args/FromForm.d.ts +1 -1
- package/lib/cjs/route-args/FromForm.d.ts.map +1 -1
- package/lib/cjs/route-args/FromForm.js +116 -37
- package/lib/cjs/route-args/FromForm.js.map +1 -1
- package/lib/cjs/route-args/FromXml.d.ts +17 -0
- package/lib/cjs/route-args/FromXml.d.ts.map +1 -0
- package/lib/cjs/route-args/FromXml.js +55 -0
- package/lib/cjs/route-args/FromXml.js.map +1 -0
- package/lib/cjs/route-args/RequestContext.d.ts +43 -0
- package/lib/cjs/route-args/RequestContext.d.ts.map +1 -0
- package/lib/cjs/route-args/RequestContext.js +94 -0
- package/lib/cjs/route-args/RequestContext.js.map +1 -0
- package/lib/cjs/route-args/RequestFields.d.ts +1 -1
- package/lib/cjs/route-args/RequestFields.d.ts.map +1 -1
- package/lib/cjs/route-args/RequestFields.js +1 -0
- package/lib/cjs/route-args/RequestFields.js.map +1 -1
- package/lib/cjs/route-args/RouteArgs.d.ts.map +1 -1
- package/lib/cjs/route-args/RouteArgs.js +50 -10
- package/lib/cjs/route-args/RouteArgs.js.map +1 -1
- package/lib/cjs/route-args/index.d.ts +2 -0
- package/lib/cjs/route-args/index.d.ts.map +1 -1
- package/lib/cjs/route-args/index.js +2 -0
- package/lib/cjs/route-args/index.js.map +1 -1
- package/lib/cjs/server.d.ts +36 -3
- package/lib/cjs/server.d.ts.map +1 -1
- package/lib/cjs/server.js +131 -42
- package/lib/cjs/server.js.map +1 -1
- package/lib/mjs/config/http.d.ts.map +1 -1
- package/lib/mjs/config/http.js +11 -0
- package/lib/mjs/config/http.js.map +1 -1
- package/lib/mjs/controllers.d.ts.map +1 -1
- package/lib/mjs/controllers.js +46 -10
- package/lib/mjs/controllers.js.map +1 -1
- package/lib/mjs/decorators.d.ts +46 -4
- package/lib/mjs/decorators.d.ts.map +1 -1
- package/lib/mjs/decorators.js +121 -24
- package/lib/mjs/decorators.js.map +1 -1
- package/lib/mjs/error.js +3 -3
- package/lib/mjs/error.js.map +1 -1
- package/lib/mjs/file-middlewares/validation.d.ts +11 -0
- package/lib/mjs/file-middlewares/validation.d.ts.map +1 -1
- package/lib/mjs/file-middlewares/validation.js +53 -10
- package/lib/mjs/file-middlewares/validation.js.map +1 -1
- package/lib/mjs/file-middlewares/zip.d.ts.map +1 -1
- package/lib/mjs/file-middlewares/zip.js +6 -1
- package/lib/mjs/file-middlewares/zip.js.map +1 -1
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +1 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +95 -1
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +65 -2
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middlewares/PerfRollup.d.ts +19 -0
- package/lib/mjs/middlewares/PerfRollup.d.ts.map +1 -0
- package/lib/mjs/middlewares/PerfRollup.js +58 -0
- package/lib/mjs/middlewares/PerfRollup.js.map +1 -0
- package/lib/mjs/middlewares/RequestId.d.ts +1 -2
- package/lib/mjs/middlewares/RequestId.d.ts.map +1 -1
- package/lib/mjs/middlewares/RequestId.js +19 -5
- package/lib/mjs/middlewares/RequestId.js.map +1 -1
- package/lib/mjs/middlewares/ResponseTime.d.ts +1 -2
- package/lib/mjs/middlewares/ResponseTime.d.ts.map +1 -1
- package/lib/mjs/middlewares/ResponseTime.js +29 -11
- package/lib/mjs/middlewares/ResponseTime.js.map +1 -1
- package/lib/mjs/response-methods/file.d.ts.map +1 -1
- package/lib/mjs/response-methods/file.js +41 -15
- package/lib/mjs/response-methods/file.js.map +1 -1
- package/lib/mjs/response-methods/index.d.ts +3 -0
- package/lib/mjs/response-methods/index.d.ts.map +1 -1
- package/lib/mjs/response-methods/index.js +3 -0
- package/lib/mjs/response-methods/index.js.map +1 -1
- package/lib/mjs/response-methods/redirect.d.ts +11 -4
- package/lib/mjs/response-methods/redirect.d.ts.map +1 -1
- package/lib/mjs/response-methods/redirect.js +15 -5
- package/lib/mjs/response-methods/redirect.js.map +1 -1
- package/lib/mjs/response-methods/xml.d.ts +17 -0
- package/lib/mjs/response-methods/xml.d.ts.map +1 -0
- package/lib/mjs/response-methods/xml.js +22 -0
- package/lib/mjs/response-methods/xml.js.map +1 -0
- package/lib/mjs/responses.d.ts +10 -0
- package/lib/mjs/responses.d.ts.map +1 -1
- package/lib/mjs/responses.js +93 -35
- package/lib/mjs/responses.js.map +1 -1
- package/lib/mjs/route-args/FromBody.d.ts.map +1 -1
- package/lib/mjs/route-args/FromBody.js +6 -1
- package/lib/mjs/route-args/FromBody.js.map +1 -1
- package/lib/mjs/route-args/FromForm.d.ts +1 -1
- package/lib/mjs/route-args/FromForm.d.ts.map +1 -1
- package/lib/mjs/route-args/FromForm.js +114 -38
- package/lib/mjs/route-args/FromForm.js.map +1 -1
- package/lib/mjs/route-args/FromXml.d.ts +17 -0
- package/lib/mjs/route-args/FromXml.d.ts.map +1 -0
- package/lib/mjs/route-args/FromXml.js +52 -0
- package/lib/mjs/route-args/FromXml.js.map +1 -0
- package/lib/mjs/route-args/RequestContext.d.ts +43 -0
- package/lib/mjs/route-args/RequestContext.d.ts.map +1 -0
- package/lib/mjs/route-args/RequestContext.js +91 -0
- package/lib/mjs/route-args/RequestContext.js.map +1 -0
- package/lib/mjs/route-args/RequestFields.d.ts +1 -1
- package/lib/mjs/route-args/RequestFields.d.ts.map +1 -1
- package/lib/mjs/route-args/RequestFields.js +1 -0
- package/lib/mjs/route-args/RequestFields.js.map +1 -1
- package/lib/mjs/route-args/RouteArgs.d.ts.map +1 -1
- package/lib/mjs/route-args/RouteArgs.js +51 -11
- package/lib/mjs/route-args/RouteArgs.js.map +1 -1
- package/lib/mjs/route-args/index.d.ts +2 -0
- package/lib/mjs/route-args/index.d.ts.map +1 -1
- package/lib/mjs/route-args/index.js +2 -0
- package/lib/mjs/route-args/index.js.map +1 -1
- package/lib/mjs/server.d.ts +36 -3
- package/lib/mjs/server.d.ts.map +1 -1
- package/lib/mjs/server.js +132 -43
- package/lib/mjs/server.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +16 -12
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
|
|
3
|
+
/**
|
|
4
|
+
* Emits one perf rollup per request ( eg. "orm.query x14 240ms" ). Creates the
|
|
5
|
+
* accumulator on `req.storage.perf` in `before()` — which is the SAME object the
|
|
6
|
+
* action's `AsyncLocalStorage.run(req.storage, …)` exposes, so measurements taken
|
|
7
|
+
* during the request land in it — then flushes it to every PerfSink on the
|
|
8
|
+
* response `finish` event.
|
|
9
|
+
*
|
|
10
|
+
* Config:
|
|
11
|
+
* http.perf.enabled (default true)
|
|
12
|
+
*/
|
|
13
|
+
export declare class PerfRollup extends ServerMiddleware {
|
|
14
|
+
protected Enabled: boolean;
|
|
15
|
+
constructor();
|
|
16
|
+
before(): ((req: sRequest, res: express.Response, next: express.NextFunction) => void) | null;
|
|
17
|
+
after(): null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=PerfRollup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerfRollup.d.ts","sourceRoot":"","sources":["../../../src/middlewares/PerfRollup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAKnC,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzE;;;;;;;;;GASG;AACH,qBACa,UAAW,SAAQ,gBAAgB;IAE9C,SAAS,CAAC,OAAO,EAAG,OAAO,CAAC;;IAQrB,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,GAAG,IAAI;IAe7F,KAAK,IAAI,IAAI;CAGrB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PerfRollup = void 0;
|
|
13
|
+
const di_1 = require("@spinajs/di");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
+
const log_1 = require("@spinajs/log");
|
|
16
|
+
const interfaces_js_1 = require("../interfaces.js");
|
|
17
|
+
/**
|
|
18
|
+
* Emits one perf rollup per request ( eg. "orm.query x14 240ms" ). Creates the
|
|
19
|
+
* accumulator on `req.storage.perf` in `before()` — which is the SAME object the
|
|
20
|
+
* action's `AsyncLocalStorage.run(req.storage, …)` exposes, so measurements taken
|
|
21
|
+
* during the request land in it — then flushes it to every PerfSink on the
|
|
22
|
+
* response `finish` event.
|
|
23
|
+
*
|
|
24
|
+
* Config:
|
|
25
|
+
* http.perf.enabled (default true)
|
|
26
|
+
*/
|
|
27
|
+
let PerfRollup = class PerfRollup extends interfaces_js_1.ServerMiddleware {
|
|
28
|
+
constructor() {
|
|
29
|
+
super();
|
|
30
|
+
// Needs req.storage ( ReqStorage = -2 ); sits alongside AccessLog ( Order 2 ).
|
|
31
|
+
this.Order = 2;
|
|
32
|
+
}
|
|
33
|
+
before() {
|
|
34
|
+
if (!this.Enabled)
|
|
35
|
+
return null;
|
|
36
|
+
return (req, res, next) => {
|
|
37
|
+
const startedAt = Date.now();
|
|
38
|
+
req.storage.perf = { requestId: req.storage.requestId, byName: {} };
|
|
39
|
+
res.on('finish', () => {
|
|
40
|
+
log_1.Perf.flushScope(req.storage.perf, {
|
|
41
|
+
labels: { method: req.method, route: req.route?.path ?? req.originalUrl, status: res.statusCode },
|
|
42
|
+
totalMs: Date.now() - startedAt,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
next();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
after() {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.PerfRollup = PerfRollup;
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, configuration_1.Config)('http.perf.enabled', { defaultValue: true }),
|
|
55
|
+
__metadata("design:type", Boolean)
|
|
56
|
+
], PerfRollup.prototype, "Enabled", void 0);
|
|
57
|
+
exports.PerfRollup = PerfRollup = __decorate([
|
|
58
|
+
(0, di_1.Injectable)(interfaces_js_1.ServerMiddleware),
|
|
59
|
+
__metadata("design:paramtypes", [])
|
|
60
|
+
], PerfRollup);
|
|
61
|
+
//# sourceMappingURL=PerfRollup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PerfRollup.js","sourceRoot":"","sources":["../../../src/middlewares/PerfRollup.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAyC;AACzC,0DAAgD;AAChD,sCAAoC;AAEpC,oDAAyE;AAEzE;;;;;;;;;GASG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gCAAgB;IAI9C;QACE,KAAK,EAAE,CAAC;QACR,+EAA+E;QAC/E,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEM,MAAM;QACX,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAC/B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YACxB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC7B,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;YACpE,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACpB,UAAI,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE;oBAChC,MAAM,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAG,GAAG,CAAC,KAA2B,EAAE,IAAI,IAAI,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE;oBACxH,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;iBAChC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA5BY,gCAAU;AAEX;IADT,IAAA,sBAAM,EAAC,mBAAmB,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;;2CACxB;qBAFjB,UAAU;IADtB,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,UAAU,CA4BtB"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Response, NextFunction } from 'express';
|
|
2
2
|
import { ServerMiddleware, Request as sRequest } from '../interfaces.js';
|
|
3
|
-
import * as express from 'express';
|
|
4
3
|
export declare class RequestId extends ServerMiddleware {
|
|
5
4
|
constructor();
|
|
6
|
-
after():
|
|
5
|
+
after(): null;
|
|
7
6
|
before(): (req: sRequest, res: Response<any, Record<string, any>>, next: NextFunction) => void;
|
|
8
7
|
}
|
|
9
8
|
//# sourceMappingURL=RequestId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestId.d.ts","sourceRoot":"","sources":["../../../src/middlewares/RequestId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"RequestId.d.ts","sourceRoot":"","sources":["../../../src/middlewares/RequestId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAMzE,qBACa,SAAU,SAAQ,gBAAgB;;IAMtC,KAAK,IAAI,IAAI;IAQb,MAAM,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI;CAqBtG"}
|
|
@@ -13,20 +13,34 @@ exports.RequestId = void 0;
|
|
|
13
13
|
const interfaces_js_1 = require("../interfaces.js");
|
|
14
14
|
const uuid_1 = require("uuid");
|
|
15
15
|
const di_1 = require("@spinajs/di");
|
|
16
|
+
const log_1 = require("@spinajs/log");
|
|
16
17
|
let RequestId = class RequestId extends interfaces_js_1.ServerMiddleware {
|
|
17
18
|
constructor() {
|
|
18
19
|
super();
|
|
19
20
|
this.Order = 1;
|
|
20
21
|
}
|
|
21
22
|
after() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// The x-request-id header is set in before() instead. ServerMiddleware
|
|
24
|
+
// after() handlers do NOT run for matched controller routes (the response
|
|
25
|
+
// is flushed inside the controllers router without calling next()), so
|
|
26
|
+
// setting the header here would silently drop it on every real response.
|
|
27
|
+
return null;
|
|
26
28
|
}
|
|
27
29
|
before() {
|
|
28
|
-
return (req,
|
|
30
|
+
return (req, res, next) => {
|
|
29
31
|
req.storage.requestId = (0, uuid_1.v4)();
|
|
32
|
+
// Continue an inbound W3C traceparent ( or start a new trace ) and seed
|
|
33
|
+
// traceId / spanId onto req.storage so the ambient log context merges them
|
|
34
|
+
// into every log line — trace ids are shared across services.
|
|
35
|
+
const tc = (0, log_1.newTraceContext)(req.headers['traceparent']);
|
|
36
|
+
req.storage.traceId = tc.traceId;
|
|
37
|
+
req.storage.spanId = tc.spanId;
|
|
38
|
+
// Emit the outbound traceparent here ( not in after() ) because the
|
|
39
|
+
// `sampled` flag lives on this freshly-computed context and req.storage —
|
|
40
|
+
// typed as the public IActionLocalStoregeContext — deliberately does not
|
|
41
|
+
// carry it. Setting a response header before next() is safe as long as the
|
|
42
|
+
// response has not been sent, mirroring x-request-id.
|
|
43
|
+
res.header('traceparent', (0, log_1.formatTraceparent)(tc));
|
|
30
44
|
next();
|
|
31
45
|
};
|
|
32
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestId.js","sourceRoot":"","sources":["../../../src/middlewares/RequestId.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAyE;AAEzE,+BAAoC;AACpC,oCAAyC;
|
|
1
|
+
{"version":3,"file":"RequestId.js","sourceRoot":"","sources":["../../../src/middlewares/RequestId.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAyE;AAEzE,+BAAoC;AACpC,oCAAyC;AACzC,sCAAiF;AAG1E,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,gCAAgB;IAC7C;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IAEM,KAAK;QACV,uEAAuE;QACvE,0EAA0E;QAC1E,uEAAuE;QACvE,yEAAyE;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,MAAM;QACX,OAAO,CAAC,GAAa,EAAE,GAAqB,EAAE,IAA0B,EAAE,EAAE;YAC1E,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAA,SAAM,GAAE,CAAC;YAEjC,wEAAwE;YACxE,2EAA2E;YAC3E,8DAA8D;YAC9D,MAAM,EAAE,GAAkB,IAAA,qBAAe,EAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAuB,CAAC,CAAC;YAC5F,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC;YACjC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,MAAM,CAAC;YAE/B,oEAAoE;YACpE,0EAA0E;YAC1E,yEAAyE;YACzE,2EAA2E;YAC3E,sDAAsD;YACtD,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,IAAA,uBAAiB,EAAC,EAAE,CAAC,CAAC,CAAC;YAEjD,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CACF,CAAA;AAnCY,8BAAS;oBAAT,SAAS;IADrB,IAAA,eAAU,EAAC,gCAAgB,CAAC;;GAChB,SAAS,CAmCrB"}
|
|
@@ -2,10 +2,9 @@ import { Request, Response, NextFunction } from 'express';
|
|
|
2
2
|
import { ParamsDictionary } from 'express-serve-static-core';
|
|
3
3
|
import { ParsedQs } from 'qs';
|
|
4
4
|
import { ServerMiddleware } from '../interfaces.js';
|
|
5
|
-
import * as express from 'express';
|
|
6
5
|
export declare class ResponseTime extends ServerMiddleware {
|
|
7
6
|
constructor();
|
|
8
|
-
after():
|
|
7
|
+
after(): null;
|
|
9
8
|
before(): (_req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => void;
|
|
10
9
|
}
|
|
11
10
|
//# sourceMappingURL=ResponseTime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponseTime.d.ts","sourceRoot":"","sources":["../../../src/middlewares/ResponseTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAuB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"ResponseTime.d.ts","sourceRoot":"","sources":["../../../src/middlewares/ResponseTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAuB,MAAM,kBAAkB,CAAC;AAIzE,qBACa,YAAa,SAAQ,gBAAgB;;IAazC,KAAK,IAAI,IAAI;IAQb,MAAM,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,gBAAgB,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI;CAsBjK"}
|
|
@@ -15,21 +15,39 @@ const di_1 = require("@spinajs/di");
|
|
|
15
15
|
let ResponseTime = class ResponseTime extends interfaces_js_1.ServerMiddleware {
|
|
16
16
|
constructor() {
|
|
17
17
|
super();
|
|
18
|
-
|
|
18
|
+
// Must sit ABOVE Compression (Order 0): the timing header is written from a
|
|
19
|
+
// res.end patch, and compression also patches res.end and flushes the
|
|
20
|
+
// headers. Whichever patch is applied last runs first (outermost), so we
|
|
21
|
+
// need a higher Order than compression to set our header before compression
|
|
22
|
+
// sends it. Same tier as the other end-of-response instrumentation
|
|
23
|
+
// (ServerTiming / AccessLog). The sub-millisecond difference in when the
|
|
24
|
+
// start timestamp is taken is irrelevant for a response-time metric.
|
|
25
|
+
this.Order = 2;
|
|
19
26
|
}
|
|
20
27
|
after() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
res.header('x-response-time', diff.toString());
|
|
27
|
-
next();
|
|
28
|
-
};
|
|
28
|
+
// Timing is finalised via a res.end patch in before() instead. After()
|
|
29
|
+
// handlers do NOT run for matched controller routes (the response is
|
|
30
|
+
// flushed inside the controllers router without calling next()), so the
|
|
31
|
+
// x-response-time header set here would be dropped on every real response.
|
|
32
|
+
return null;
|
|
29
33
|
}
|
|
30
34
|
before() {
|
|
31
|
-
return (req,
|
|
32
|
-
|
|
35
|
+
return (req, res, next) => {
|
|
36
|
+
const start = new Date();
|
|
37
|
+
req.storage.responseStart = start;
|
|
38
|
+
// Finalise timing and write the header just before the response is
|
|
39
|
+
// flushed, regardless of how the controller ended it. Headers are still
|
|
40
|
+
// mutable here because the original res.end hasn't run yet.
|
|
41
|
+
const originalEnd = res.end.bind(res);
|
|
42
|
+
res.end = function patchedEnd(...args) {
|
|
43
|
+
const end = new Date();
|
|
44
|
+
req.storage.responseEnd = end;
|
|
45
|
+
req.storage.responseTime = end.getTime() - start.getTime();
|
|
46
|
+
if (!res.headersSent) {
|
|
47
|
+
res.setHeader('x-response-time', String(req.storage.responseTime));
|
|
48
|
+
}
|
|
49
|
+
return originalEnd(...args);
|
|
50
|
+
};
|
|
33
51
|
next();
|
|
34
52
|
};
|
|
35
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponseTime.js","sourceRoot":"","sources":["../../../src/middlewares/ResponseTime.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oDAAyE;AAEzE,oCAAyC;AAGlC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,gCAAgB;IAChD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"ResponseTime.js","sourceRoot":"","sources":["../../../src/middlewares/ResponseTime.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,oDAAyE;AAEzE,oCAAyC;AAGlC,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,gCAAgB;IAChD;QACE,KAAK,EAAE,CAAC;QACR,4EAA4E;QAC5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|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/response-methods/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../../src/response-methods/file.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAMtF,qBAAa,WAAY,SAAQ,QAAQ;IAK3B,SAAS,CAAC,OAAO,EAAE,oBAAoB;IAAE,SAAS,CAAC,eAAe,CAAC,EAAE,gBAAgB;IAJjG;;;OAGG;gBACmB,OAAO,EAAE,oBAAoB,EAAY,eAAe,CAAC,EAAE,gBAAgB,YAAA;IAUpF,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CA+BlF;AAED,qBAAa,YAAa,SAAQ,QAAQ;IAK5B,SAAS,CAAC,OAAO,EAAE,oBAAoB;IAAE,SAAS,CAAC,eAAe,CAAC,EAAE,gBAAgB;IAJjG;;;OAGG;gBACmB,OAAO,EAAE,oBAAoB,EAAY,eAAe,CAAC,EAAE,gBAAgB,YAAA;IAWpF,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CA2DlF;AAED,qBAAa,gBAAiB,SAAQ,QAAQ;IAChC,SAAS,CAAC,IAAI,EAAE,GAAG;IAAE,SAAS,CAAC,QAAQ,EAAE,MAAM;IAAE,SAAS,CAAC,eAAe,CAAC,EAAE,gBAAgB;gBAAnF,IAAI,EAAE,GAAG,EAAY,QAAQ,EAAE,MAAM,EAAY,eAAe,CAAC,EAAE,gBAAgB,YAAA;IAI5F,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CA2BlF"}
|
|
@@ -7,9 +7,12 @@ exports.JsonFileResponse = exports.FileResponse = exports.ZipResponse = void 0;
|
|
|
7
7
|
const di_1 = require("@spinajs/di");
|
|
8
8
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
9
9
|
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
-
const
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const path_1 = require("path");
|
|
11
12
|
const interfaces_js_1 = require("./../interfaces.js");
|
|
12
|
-
|
|
13
|
+
// import from the defining module, not the package barrel - '../index.js' pulls
|
|
14
|
+
// the whole export graph back through interfaces.js and re-forms an import cycle
|
|
15
|
+
const responses_js_1 = require("../responses.js");
|
|
13
16
|
class ZipResponse extends interfaces_js_1.Response {
|
|
14
17
|
/**
|
|
15
18
|
* Sends zipped file to client at given path & filename. If file exists
|
|
@@ -19,7 +22,10 @@ class ZipResponse extends interfaces_js_1.Response {
|
|
|
19
22
|
super(null);
|
|
20
23
|
this.Options = Options;
|
|
21
24
|
this.responseOptions = responseOptions;
|
|
22
|
-
|
|
25
|
+
// The payload is always a zip archive — default to application/zip rather
|
|
26
|
+
// than deriving from the (original) download filename, which would mislabel
|
|
27
|
+
// e.g. a zipped `report.txt` as text/plain.
|
|
28
|
+
this.Options.mimeType = Options.mimeType ?? 'application/zip';
|
|
23
29
|
this.Options.provider = Options.provider ?? 'local';
|
|
24
30
|
}
|
|
25
31
|
async execute(_req, res) {
|
|
@@ -32,9 +38,9 @@ class ZipResponse extends interfaces_js_1.Response {
|
|
|
32
38
|
const fPath = zippedFile.asFilePath();
|
|
33
39
|
return new Promise((resolve, reject) => {
|
|
34
40
|
const encodedFilename = encodeURIComponent(this.Options.filename);
|
|
35
|
-
(0,
|
|
36
|
-
(0,
|
|
37
|
-
res.setHeader('Content-Type', this.Options.mimeType || 'application/
|
|
41
|
+
(0, responses_js_1._setCoockies)(res, this.responseOptions);
|
|
42
|
+
(0, responses_js_1._setHeaders)(res, this.responseOptions);
|
|
43
|
+
res.setHeader('Content-Type', this.Options.mimeType || 'application/zip');
|
|
38
44
|
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodedFilename}`);
|
|
39
45
|
res.sendFile(zippedFile.fs.resolvePath(fPath), (err) => {
|
|
40
46
|
zippedFile.fs.rm(fPath).finally(() => {
|
|
@@ -59,7 +65,11 @@ class FileResponse extends interfaces_js_1.Response {
|
|
|
59
65
|
super(null);
|
|
60
66
|
this.Options = Options;
|
|
61
67
|
this.responseOptions = responseOptions;
|
|
62
|
-
|
|
68
|
+
// Do NOT default the mime type here. When the caller doesn't specify one we
|
|
69
|
+
// let res.sendFile derive it from the actual file, which yields the correct
|
|
70
|
+
// charset for text types (e.g. `text/plain; charset=utf-8`) and the right
|
|
71
|
+
// type for binaries — deriving it from the filename dropped the charset.
|
|
72
|
+
this.Options.mimeType = Options.mimeType;
|
|
63
73
|
this.Options.provider = Options.provider ?? 'local';
|
|
64
74
|
}
|
|
65
75
|
async execute(_req, res) {
|
|
@@ -72,27 +82,41 @@ class FileResponse extends interfaces_js_1.Response {
|
|
|
72
82
|
throw new exceptions_1.ResourceNotFound(`File ${this.Options.path} not exists`);
|
|
73
83
|
}
|
|
74
84
|
const file = await provider.download(this.Options.path);
|
|
85
|
+
// A local provider returns the real on-disk file (must NOT be deleted); a
|
|
86
|
+
// remote provider downloads to a throwaway temp copy that must be cleaned
|
|
87
|
+
// up after sending. Detect the local case by the file living under the
|
|
88
|
+
// provider's own base path.
|
|
89
|
+
const basePath = provider.Options?.basePath;
|
|
90
|
+
const isLocalRealFile = !!basePath && (0, path_1.resolve)(file).startsWith((0, path_1.resolve)(basePath));
|
|
75
91
|
return new Promise((resolve, reject) => {
|
|
76
92
|
const encodedFilename = encodeURIComponent(this.Options.filename);
|
|
77
|
-
(0,
|
|
78
|
-
(0,
|
|
79
|
-
|
|
93
|
+
(0, responses_js_1._setCoockies)(res, this.responseOptions);
|
|
94
|
+
(0, responses_js_1._setHeaders)(res, this.responseOptions);
|
|
95
|
+
// Only pin the Content-Type when the caller gave an explicit mime type;
|
|
96
|
+
// otherwise let sendFile set it from the file (correct charset / type).
|
|
97
|
+
if (this.Options.mimeType) {
|
|
98
|
+
res.setHeader('Content-Type', this.Options.mimeType);
|
|
99
|
+
}
|
|
80
100
|
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodedFilename}`);
|
|
81
101
|
res.sendFile(file, (err) => {
|
|
82
|
-
const
|
|
102
|
+
const cleanups = [];
|
|
103
|
+
// Remove the source file on the provider when requested.
|
|
104
|
+
if (this.Options.deleteAfterDownload) {
|
|
105
|
+
cleanups.push(provider.rm(this.Options.path).catch(() => undefined));
|
|
106
|
+
}
|
|
107
|
+
// Remove the downloaded temp copy for remote providers (never the real
|
|
108
|
+
// local file).
|
|
109
|
+
if (!isLocalRealFile) {
|
|
110
|
+
cleanups.push(fs_1.promises.unlink(file).catch(() => undefined));
|
|
111
|
+
}
|
|
112
|
+
Promise.allSettled(cleanups).finally(() => {
|
|
83
113
|
if (!lodash_1.default.isNil(err)) {
|
|
84
114
|
reject(err);
|
|
85
115
|
}
|
|
86
116
|
else {
|
|
87
117
|
resolve();
|
|
88
118
|
}
|
|
89
|
-
};
|
|
90
|
-
if (this.Options.deleteAfterDownload) {
|
|
91
|
-
provider.rm(this.Options.path).finally(r);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
r();
|
|
95
|
-
}
|
|
119
|
+
});
|
|
96
120
|
});
|
|
97
121
|
});
|
|
98
122
|
}
|
|
@@ -108,11 +132,13 @@ class JsonFileResponse extends interfaces_js_1.Response {
|
|
|
108
132
|
async execute(_req, res) {
|
|
109
133
|
const provider = await di_1.DI.resolve('__file_provider__', ['fs-temp']);
|
|
110
134
|
const tmpPath = provider.tmppath();
|
|
111
|
-
|
|
135
|
+
// Must await: sendFile below races the write otherwise and can hit the
|
|
136
|
+
// path before it exists, producing an intermittent ENOENT / 500.
|
|
137
|
+
await provider.write(tmpPath, JSON.stringify(this.data));
|
|
112
138
|
return new Promise((resolve, reject) => {
|
|
113
139
|
const encodedFilename = encodeURIComponent(this.filename);
|
|
114
|
-
(0,
|
|
115
|
-
(0,
|
|
140
|
+
(0, responses_js_1._setCoockies)(res, this.responseOptions);
|
|
141
|
+
(0, responses_js_1._setHeaders)(res, this.responseOptions);
|
|
116
142
|
res.setHeader('Content-Type', 'application/json');
|
|
117
143
|
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodedFilename}`);
|
|
118
144
|
res.sendFile(tmpPath, (err) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/response-methods/file.ts"],"names":[],"mappings":";;;;;;AAAA,oCAAiC;AACjC,oDAA+D;AAE/D,oDAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/response-methods/file.ts"],"names":[],"mappings":";;;;;;AAAA,oCAAiC;AACjC,oDAA+D;AAE/D,oDAAuB;AACvB,2BAA8B;AAC9B,+BAA8C;AAC9C,sDAAsF;AAEtF,gFAAgF;AAChF,iFAAiF;AACjF,kDAA4D;AAE5D,MAAa,WAAY,SAAQ,wBAAQ;IACvC;;;OAGG;IACH,YAAsB,OAA6B,EAAY,eAAkC;QAC/F,KAAK,CAAC,IAAI,CAAC,CAAC;QADQ,YAAO,GAAP,OAAO,CAAsB;QAAY,oBAAe,GAAf,eAAe,CAAmB;QAG/F,0EAA0E;QAC1E,4EAA4E;QAC5E,4CAA4C;QAC5C,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,iBAAiB,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC;IACtD,CAAC;IAEM,KAAK,CAAC,OAA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AAC,CAAC;YAE1D,IAAA,2BAAY,EAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;YACxC,IAAA,0BAAW,EAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;YAEvC,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;YAClD,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,gCAAgC,eAAe,EAAE,CAAC,CAAC;YAExF,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;gBACnC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;oBAChC,IAAI,GAAG,EAAE,CAAC;wBACR,MAAM,CAAC,GAAG,CAAC,CAAC;oBACd,CAAC;yBAAM,CAAC;wBACN,OAAO,EAAE,CAAC;oBACZ,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhCD,4CAgCC"}
|
|
@@ -5,12 +5,15 @@ export * from './forbidden.js';
|
|
|
5
5
|
export * from './noContent.js';
|
|
6
6
|
export * from './notFound.js';
|
|
7
7
|
export * from './json.js';
|
|
8
|
+
export * from './xml.js';
|
|
8
9
|
export * from './ok.js';
|
|
9
10
|
export * from './template.js';
|
|
11
|
+
export * from './redirect.js';
|
|
10
12
|
export * from './serverError.js';
|
|
11
13
|
export * from './unauthorized.js';
|
|
12
14
|
export * from './conflict.js';
|
|
13
15
|
export * from './notAllowed.js';
|
|
16
|
+
export * from './notAcceptable.js';
|
|
14
17
|
export * from './validationError.js';
|
|
15
18
|
export * from './entityTooLarge.js';
|
|
16
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/response-methods/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/response-methods/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
@@ -21,12 +21,15 @@ __exportStar(require("./forbidden.js"), exports);
|
|
|
21
21
|
__exportStar(require("./noContent.js"), exports);
|
|
22
22
|
__exportStar(require("./notFound.js"), exports);
|
|
23
23
|
__exportStar(require("./json.js"), exports);
|
|
24
|
+
__exportStar(require("./xml.js"), exports);
|
|
24
25
|
__exportStar(require("./ok.js"), exports);
|
|
25
26
|
__exportStar(require("./template.js"), exports);
|
|
27
|
+
__exportStar(require("./redirect.js"), exports);
|
|
26
28
|
__exportStar(require("./serverError.js"), exports);
|
|
27
29
|
__exportStar(require("./unauthorized.js"), exports);
|
|
28
30
|
__exportStar(require("./conflict.js"), exports);
|
|
29
31
|
__exportStar(require("./notAllowed.js"), exports);
|
|
32
|
+
__exportStar(require("./notAcceptable.js"), exports);
|
|
30
33
|
__exportStar(require("./validationError.js"), exports);
|
|
31
34
|
__exportStar(require("./entityTooLarge.js"), exports);
|
|
32
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/response-methods/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,iDAA+B;AAC/B,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B;AAC1B,0CAAwB;AACxB,gDAA8B;AAC9B,mDAAiC;AACjC,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,uDAAqC;AACrC,sDAAoC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/response-methods/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,iDAA+B;AAC/B,iDAA+B;AAC/B,gDAA8B;AAC9B,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,gDAA8B;AAC9B,gDAA8B;AAC9B,mDAAiC;AACjC,oDAAkC;AAClC,gDAA8B;AAC9B,kDAAgC;AAChC,qDAAmC;AACnC,uDAAqC;AACrC,sDAAoC"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import { Response } from '../interfaces.js';
|
|
2
|
+
import { IResponseOptions, Response } from '../interfaces.js';
|
|
3
3
|
/**
|
|
4
|
-
* Redirects to another
|
|
4
|
+
* Redirects to another url. Simple alias over res.redirect for api consistency,
|
|
5
|
+
* with control over the redirect status code and the ability to set cookies /
|
|
6
|
+
* headers on the redirect response (useful for auth flows).
|
|
5
7
|
*
|
|
6
|
-
* @param url - url
|
|
8
|
+
* @param url - target url
|
|
9
|
+
* @param status - redirect status code (default 302 FOUND). Use 301/308 for
|
|
10
|
+
* permanent, 307 to preserve method/body.
|
|
11
|
+
* @param responseOptions - cookies / headers to set before redirecting
|
|
7
12
|
*/
|
|
8
13
|
export declare class Redirect extends Response {
|
|
14
|
+
protected responseOptions?: IResponseOptions | undefined;
|
|
9
15
|
protected url: string;
|
|
10
|
-
|
|
16
|
+
protected status: number;
|
|
17
|
+
constructor(url: string, status?: number, responseOptions?: IResponseOptions | undefined);
|
|
11
18
|
execute(_req: express.Request, res: express.Response): Promise<void>;
|
|
12
19
|
}
|
|
13
20
|
//# sourceMappingURL=redirect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../src/response-methods/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"redirect.d.ts","sourceRoot":"","sources":["../../../src/response-methods/redirect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAoB,gBAAgB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGhF;;;;;;;;;GASG;AACH,qBAAa,QAAS,SAAQ,QAAQ;IAI8B,SAAS,CAAC,eAAe,CAAC,EAAE,gBAAgB;IAH9G,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEb,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAA+B,EAAY,eAAe,CAAC,EAAE,gBAAgB,YAAA;IAOjG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ;CAMlE"}
|
|
@@ -2,18 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Redirect = void 0;
|
|
4
4
|
const interfaces_js_1 = require("../interfaces.js");
|
|
5
|
+
const responses_js_1 = require("../responses.js");
|
|
5
6
|
/**
|
|
6
|
-
* Redirects to another
|
|
7
|
+
* Redirects to another url. Simple alias over res.redirect for api consistency,
|
|
8
|
+
* with control over the redirect status code and the ability to set cookies /
|
|
9
|
+
* headers on the redirect response (useful for auth flows).
|
|
7
10
|
*
|
|
8
|
-
* @param url - url
|
|
11
|
+
* @param url - target url
|
|
12
|
+
* @param status - redirect status code (default 302 FOUND). Use 301/308 for
|
|
13
|
+
* permanent, 307 to preserve method/body.
|
|
14
|
+
* @param responseOptions - cookies / headers to set before redirecting
|
|
9
15
|
*/
|
|
10
16
|
class Redirect extends interfaces_js_1.Response {
|
|
11
|
-
constructor(url) {
|
|
17
|
+
constructor(url, status = interfaces_js_1.HTTP_STATUS_CODE.FOUND, responseOptions) {
|
|
12
18
|
super(null);
|
|
19
|
+
this.responseOptions = responseOptions;
|
|
13
20
|
this.url = url;
|
|
21
|
+
this.status = status;
|
|
14
22
|
}
|
|
15
23
|
async execute(_req, res) {
|
|
16
|
-
|
|
24
|
+
(0, responses_js_1._setCoockies)(res, this.responseOptions);
|
|
25
|
+
(0, responses_js_1._setHeaders)(res, this.responseOptions);
|
|
26
|
+
res.redirect(this.status, this.url);
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
29
|
exports.Redirect = Redirect;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../../src/response-methods/redirect.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"redirect.js","sourceRoot":"","sources":["../../../src/response-methods/redirect.ts"],"names":[],"mappings":";;;AACA,oDAAgF;AAChF,kDAA4D;AAE5D;;;;;;;;;GASG;AACH,MAAa,QAAS,SAAQ,wBAAQ;IAIpC,YAAY,GAAW,EAAE,SAAiB,gCAAgB,CAAC,KAAK,EAAY,eAAkC;QAC5G,KAAK,CAAC,IAAI,CAAC,CAAC;QAD8D,oBAAe,GAAf,eAAe,CAAmB;QAG5G,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,GAAqB;QAC/D,IAAA,2BAAY,EAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACxC,IAAA,0BAAW,EAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAEvC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF;AAjBD,4BAiBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { HTTP_STATUS_CODE, IResponseOptions, Response, ResponseFunction } from '../interfaces.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an HTTP 200 response with an XML body, bypassing Accept-header
|
|
5
|
+
* negotiation. Use when the endpoint must always respond with XML. The data
|
|
6
|
+
* should be a plain object graph; arrays / scalars are wrapped under a
|
|
7
|
+
* `<response>` root. Optional fast-xml-parser XMLBuilder options can be passed.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Xml<T = any> extends Response<T> {
|
|
10
|
+
protected options?: IResponseOptions | undefined;
|
|
11
|
+
protected xmlOptions?: any | undefined;
|
|
12
|
+
protected _errorCode: HTTP_STATUS_CODE;
|
|
13
|
+
protected _template: string;
|
|
14
|
+
constructor(data?: T | Promise<T> | null, options?: IResponseOptions | undefined, xmlOptions?: any | undefined);
|
|
15
|
+
execute(_req: express.Request, _res: express.Response): Promise<ResponseFunction | void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=xml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml.d.ts","sourceRoot":"","sources":["../../../src/response-methods/xml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGlG;;;;;GAKG;AACH,qBAAa,GAAG,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAID,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB;IAAE,SAAS,CAAC,UAAU,CAAC,EAAE,GAAG;IAH1G,SAAS,CAAC,UAAU,mBAAuB;IAC3C,SAAS,CAAC,SAAS,SAAM;gBAEb,IAAI,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAY,OAAO,CAAC,EAAE,gBAAgB,YAAA,EAAY,UAAU,CAAC,EAAE,GAAG,YAAA;IAI7F,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;CAItG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Xml = void 0;
|
|
4
|
+
const interfaces_js_1 = require("../interfaces.js");
|
|
5
|
+
const responses_js_1 = require("../responses.js");
|
|
6
|
+
/**
|
|
7
|
+
* Returns an HTTP 200 response with an XML body, bypassing Accept-header
|
|
8
|
+
* negotiation. Use when the endpoint must always respond with XML. The data
|
|
9
|
+
* should be a plain object graph; arrays / scalars are wrapped under a
|
|
10
|
+
* `<response>` root. Optional fast-xml-parser XMLBuilder options can be passed.
|
|
11
|
+
*/
|
|
12
|
+
class Xml extends interfaces_js_1.Response {
|
|
13
|
+
constructor(data, options, xmlOptions) {
|
|
14
|
+
super(data, options);
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.xmlOptions = xmlOptions;
|
|
17
|
+
this._errorCode = interfaces_js_1.HTTP_STATUS_CODE.OK;
|
|
18
|
+
this._template = '';
|
|
19
|
+
}
|
|
20
|
+
async execute(_req, _res) {
|
|
21
|
+
const data = await this.prepareResponse();
|
|
22
|
+
return (0, responses_js_1.xmlResponse)(data, { ...this.options, StatusCode: this.options?.StatusCode ?? this._errorCode }, this.xmlOptions);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Xml = Xml;
|
|
26
|
+
//# sourceMappingURL=xml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml.js","sourceRoot":"","sources":["../../../src/response-methods/xml.ts"],"names":[],"mappings":";;;AACA,oDAAkG;AAClG,kDAA8C;AAE9C;;;;;GAKG;AACH,MAAa,GAAa,SAAQ,wBAAW;IAI3C,YAAY,IAA4B,EAAY,OAA0B,EAAY,UAAgB;QACxG,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAD6B,YAAO,GAAP,OAAO,CAAmB;QAAY,eAAU,GAAV,UAAU,CAAM;QAHhG,eAAU,GAAG,gCAAgB,CAAC,EAAE,CAAC;QACjC,cAAS,GAAG,EAAE,CAAC;IAIzB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,IAAqB,EAAE,IAAsB;QAChE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QAC1C,OAAO,IAAA,0BAAW,EAAC,IAAI,EAAE,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1H,CAAC;CACF;AAZD,kBAYC"}
|
package/lib/cjs/responses.d.ts
CHANGED
|
@@ -16,6 +16,16 @@ export declare function jsonResponse(model: any, options?: IResponseOptions): (_
|
|
|
16
16
|
* @param status - status code
|
|
17
17
|
*/
|
|
18
18
|
export declare function textResponse(model: any, options?: IResponseOptions): (_req: express.Request, res: express.Response) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Serializes data to an XML body. The payload should be a plain object graph;
|
|
21
|
+
* arrays and scalars are wrapped under a `<response>` root so the output is a
|
|
22
|
+
* single well-formed document.
|
|
23
|
+
*
|
|
24
|
+
* @param model - data to serialize
|
|
25
|
+
* @param options - response options (status, headers, cookies)
|
|
26
|
+
* @param xmlOptions - fast-xml-parser XMLBuilder options
|
|
27
|
+
*/
|
|
28
|
+
export declare function xmlResponse(model: any, options?: IResponseOptions, xmlOptions?: any): (_req: express.Request, res: express.Response) => void;
|
|
19
29
|
/**
|
|
20
30
|
* Sends html response & sets proper header. If template is not avaible, handles proper error rendering.
|
|
21
31
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAwD,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAwD,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAmBzG,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,gBAAgB,QA6B7E;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,gBAAgB,QAI5E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,gBAAgB,IACzD,MAAM,OA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