@stamhoofd/backend-middleware 2.1.3 → 2.1.4

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.
@@ -0,0 +1,4 @@
1
+ export * from "./src/LogMiddleware";
2
+ export * from "./src/CORSMiddleware";
3
+ export * from "./src/VersionMiddleware";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,yBAAyB,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,8DAAmC;AACnC,+DAAoC;AACpC,kEAAuC"}
@@ -0,0 +1,3 @@
1
+ import { ResponseMiddleware } from "@simonbackx/simple-endpoints";
2
+ export declare const CORSMiddleware: ResponseMiddleware;
3
+ //# sourceMappingURL=CORSMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CORSMiddleware.d.ts","sourceRoot":"","sources":["../../src/CORSMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAE5F,eAAO,MAAM,cAAc,EAAE,kBAyB5B,CAAA"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CORSMiddleware = void 0;
4
+ exports.CORSMiddleware = {
5
+ handleResponse(request, response) {
6
+ var _a, _b;
7
+ response.headers["Access-Control-Allow-Origin"] = (_a = request.headers.origin) !== null && _a !== void 0 ? _a : "*";
8
+ response.headers["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS, PATCH, PUT, DELETE";
9
+ response.headers["Access-Control-Allow-Headers"] = (_b = request.headers["access-control-request-headers"]) !== null && _b !== void 0 ? _b : "*";
10
+ response.headers["Access-Control-Max-Age"] = "86400"; // Cache 24h
11
+ if (request.method !== "OPTIONS") {
12
+ // Expose all headers
13
+ const exposeHeaders = Object.keys(response.headers).map(h => h.toLowerCase()).filter(h => !['content-length', 'cache-control', 'content-language', 'content-type', 'expires', 'last-modified', 'pragma'].includes(h)).join(", ");
14
+ if (exposeHeaders) {
15
+ response.headers["Access-Control-Expose-Headers"] = exposeHeaders;
16
+ }
17
+ }
18
+ // Not needed
19
+ // response.headers["Access-Control-Allow-Credentials"] = "true";
20
+ // API is public
21
+ response.headers["Cross-Origin-Resource-Policy"] = "cross-origin";
22
+ if (request.headers.origin && !response.headers["Vary"]) {
23
+ response.headers["Vary"] = "Origin";
24
+ }
25
+ }
26
+ };
27
+ //# sourceMappingURL=CORSMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CORSMiddleware.js","sourceRoot":"","sources":["../../src/CORSMiddleware.ts"],"names":[],"mappings":";;;AAEa,QAAA,cAAc,GAAuB;IAC9C,cAAc,CAAC,OAAgB,EAAE,QAAyB;;QACtD,QAAQ,CAAC,OAAO,CAAC,6BAA6B,CAAC,GAAG,MAAA,OAAO,CAAC,OAAO,CAAC,MAAM,mCAAI,GAAG,CAAA;QAC/E,QAAQ,CAAC,OAAO,CAAC,8BAA8B,CAAC,GAAG,wCAAwC,CAAA;QAC3F,QAAQ,CAAC,OAAO,CAAC,8BAA8B,CAAC,GAAG,MAAA,OAAO,CAAC,OAAO,CAAC,gCAAgC,CAAC,mCAAI,GAAG,CAAC;QAC5G,QAAQ,CAAC,OAAO,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,CAAC,YAAY;QAElE,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC/B,qBAAqB;YACrB,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjO,IAAI,aAAa,EAAE,CAAC;gBAChB,QAAQ,CAAC,OAAO,CAAC,+BAA+B,CAAC,GAAG,aAAa,CAAA;YACrE,CAAC;QACL,CAAC;QAED,aAAa;QACb,iEAAiE;QAEjE,gBAAgB;QAChB,QAAQ,CAAC,OAAO,CAAC,8BAA8B,CAAC,GAAG,cAAc,CAAA;QAEjE,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACtD,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAA;QACvC,CAAC;IACL,CAAC;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { RequestMiddleware, ResponseMiddleware } from "@simonbackx/simple-endpoints";
2
+ export declare const LogMiddleware: ResponseMiddleware & RequestMiddleware;
3
+ //# sourceMappingURL=LogMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogMiddleware.d.ts","sourceRoot":"","sources":["../../src/LogMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,iBAAiB,EAAC,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAgE9G,eAAO,MAAM,aAAa,EAAE,kBAAkB,GAAG,iBA8DhD,CAAA"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogMiddleware = void 0;
4
+ const simple_errors_1 = require("@simonbackx/simple-errors");
5
+ const simple_logging_1 = require("@simonbackx/simple-logging");
6
+ let requestCounter = 0;
7
+ function logRequestDetails(request) {
8
+ if (Object.keys(request.query).length) {
9
+ const json = { ...request.query };
10
+ if (json && json.password) {
11
+ json.password = '*******';
12
+ }
13
+ simple_logging_1.logger.error(...requestPrefix(request, 'query'), "Request query was ", json);
14
+ }
15
+ request.body.then((body) => {
16
+ if (!body) {
17
+ return;
18
+ }
19
+ try {
20
+ const json = JSON.parse(body);
21
+ if (Array.isArray(json) || Object.keys(json).length) {
22
+ if (json && json.password) {
23
+ json.password = '*******';
24
+ }
25
+ simple_logging_1.logger.error(...requestPrefix(request, 'body'), "Request body was ", json);
26
+ }
27
+ }
28
+ catch (e) {
29
+ simple_logging_1.logger.error(...requestPrefix(request, 'body'), "Request body was ", body);
30
+ }
31
+ }).catch(console.error);
32
+ }
33
+ function requestOneLiner(request) {
34
+ return [
35
+ new simple_logging_1.StyledText(request.method).addClass('request', 'method', request.method.toLowerCase()),
36
+ ' ',
37
+ new simple_logging_1.StyledText(request.url).addClass('request', 'url'),
38
+ ' (',
39
+ new simple_logging_1.StyledText(request.getIP()).addClass('request', 'ip'),
40
+ '@',
41
+ new simple_logging_1.StyledText(request.host).addClass('request', 'host'),
42
+ ')'
43
+ ];
44
+ }
45
+ function requestPrefix(request, ...classes) {
46
+ return [
47
+ new simple_logging_1.StyledText(`[R${request._uniqueIndex.toString().padStart(4, "0")}] `).addClass('request', 'tag', ...classes),
48
+ ];
49
+ }
50
+ exports.LogMiddleware = {
51
+ handleRequest(request) {
52
+ request._uniqueIndex = requestCounter++;
53
+ request._startTime = process.hrtime();
54
+ if (request.method == "OPTIONS") {
55
+ if (STAMHOOFD.environment === "development") {
56
+ simple_logging_1.logger.log(...requestPrefix(request), ...requestOneLiner(request));
57
+ }
58
+ return;
59
+ }
60
+ simple_logging_1.logger.log(...requestPrefix(request), ...requestOneLiner(request));
61
+ },
62
+ wrapRun(run, request) {
63
+ return simple_logging_1.logger.setContext({
64
+ prefixes: requestPrefix(request, 'output'),
65
+ tags: ['request', 'request-output']
66
+ }, run);
67
+ },
68
+ handleResponse(request, response, error) {
69
+ var _a;
70
+ const endTime = process.hrtime();
71
+ const startTime = (_a = request._startTime) !== null && _a !== void 0 ? _a : endTime;
72
+ const timeInMs = Math.round((endTime[0] - startTime[0]) * 1000 + (endTime[1] - startTime[1]) / 1000000);
73
+ if (request.method !== "OPTIONS") {
74
+ simple_logging_1.logger.log(...requestPrefix(request, 'time'), response.status + " - Finished in " + timeInMs + "ms");
75
+ }
76
+ if (error) {
77
+ if ((0, simple_errors_1.isSimpleError)(error) || (0, simple_errors_1.isSimpleErrors)(error)) {
78
+ if (!error.hasCode("expired_access_token") && !error.hasCode('unknown_domain') && !error.hasCode('unknown_webshop')) {
79
+ simple_logging_1.logger.error(...requestPrefix(request, 'error'), "Request with error in response ", new simple_logging_1.StyledText(error).addClass('request', 'error'));
80
+ logRequestDetails(request);
81
+ }
82
+ }
83
+ else {
84
+ simple_logging_1.logger.error(...requestPrefix(request, 'error'), "Request with internal error ", new simple_logging_1.StyledText(error).addClass('request', 'error'));
85
+ logRequestDetails(request);
86
+ }
87
+ }
88
+ }
89
+ };
90
+ //# sourceMappingURL=LogMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogMiddleware.js","sourceRoot":"","sources":["../../src/LogMiddleware.ts"],"names":[],"mappings":";;;AACA,6DAA0E;AAC1E,+DAAgE;AAChE,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB,SAAS,iBAAiB,CAAC,OAAgB;IACvC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QACpC,MAAM,IAAI,GAAQ,EAAC,GAAG,OAAO,CAAC,KAAK,EAAC,CAAA;QACpC,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAA;QAC7B,CAAC;QACD,uBAAM,CAAC,KAAK,CACR,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,EAClC,oBAAoB,EACpB,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,OAAO,CAAC,CACrD,CAAA;gBAED,iBAAiB,CAAC,OAAO,CAAC,CAAA;YAC9B,CAAC;QACL,CAAC;IACL,CAAC;CACJ,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { EncodedResponse, Request, RequestMiddleware, ResponseMiddleware } from "@simonbackx/simple-endpoints";
2
+ export declare class VersionMiddleware implements RequestMiddleware, ResponseMiddleware {
3
+ minimumVersion: number | undefined;
4
+ latestVersions: {
5
+ android: number;
6
+ ios: number;
7
+ web: number;
8
+ };
9
+ constructor(options: {
10
+ latestVersions: {
11
+ android: number;
12
+ ios: number;
13
+ web: number;
14
+ };
15
+ minimumVersion?: number;
16
+ });
17
+ handleRequest(request: Request): void;
18
+ handleResponse(request: Request, response: EncodedResponse): void;
19
+ }
20
+ //# sourceMappingURL=VersionMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VersionMiddleware.d.ts","sourceRoot":"","sources":["../../src/VersionMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAI/G,qBAAa,iBAAkB,YAAW,iBAAiB,EAAE,kBAAkB;IAC3E,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;IAClC,cAAc,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,CAAA;gBAE/C,OAAO,EAAE;QAAC,cAAc,EAAE;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAC,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAC;IAK3G,aAAa,CAAC,OAAO,EAAE,OAAO;IAmD9B,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe;CAmB7D"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionMiddleware = void 0;
4
+ const simple_errors_1 = require("@simonbackx/simple-errors");
5
+ const structures_1 = require("@stamhoofd/structures");
6
+ class VersionMiddleware {
7
+ constructor(options) {
8
+ this.minimumVersion = options.minimumVersion;
9
+ this.latestVersions = options.latestVersions;
10
+ }
11
+ handleRequest(request) {
12
+ if (!this.minimumVersion) {
13
+ return;
14
+ }
15
+ const platform = request.headers["x-platform"];
16
+ let version;
17
+ try {
18
+ version = request.getVersion();
19
+ }
20
+ catch (e) {
21
+ if (((0, simple_errors_1.isSimpleError)(e) || (0, simple_errors_1.isSimpleErrors)(e)) && e.hasCode('missing_version')) {
22
+ // Allow missing version on /openid/ path
23
+ if (request.url.startsWith("/openid/")) {
24
+ request.version = this.latestVersions.web;
25
+ return;
26
+ }
27
+ }
28
+ throw e;
29
+ }
30
+ /*if (request.getIP() === '') {
31
+ throw new SimpleError({
32
+ code: "blocked",
33
+ statusCode: 400,
34
+ message: "Temporary blocked",
35
+ human: "Jouw verbinding is tijdelijk geblokkeerd. Gelieve contact op te nemen met hallo@stamhoofd.be"
36
+ })
37
+ }*/
38
+ if (version < this.minimumVersion) {
39
+ // WARNING: update caddy config for on demand certificates, because we don't want to throw errors over there!
40
+ if (platform === "web" || platform === undefined) {
41
+ throw new simple_errors_1.SimpleError({
42
+ code: "client_update_required",
43
+ statusCode: 400,
44
+ message: "Er is een noodzakelijke update beschikbaar. Herlaad de pagina en wis indien nodig de cache van jouw browser.",
45
+ human: "Er is een noodzakelijke update beschikbaar. Herlaad de pagina en wis indien nodig de cache van jouw browser."
46
+ });
47
+ }
48
+ else {
49
+ throw new simple_errors_1.SimpleError({
50
+ code: "client_update_required",
51
+ statusCode: 400,
52
+ message: "Er is een noodzakelijke update beschikbaar. Update de app en probeer opnieuw!",
53
+ human: "Er is een noodzakelijke update beschikbaar. Update de app en probeer opnieuw!"
54
+ });
55
+ }
56
+ }
57
+ }
58
+ handleResponse(request, response) {
59
+ const platform = request.headers["x-platform"];
60
+ if (platform === "android") {
61
+ response.headers["X-Platform-Latest-Version"] = this.latestVersions.android;
62
+ }
63
+ if (platform === "ios") {
64
+ response.headers["X-Platform-Latest-Version"] = this.latestVersions.ios;
65
+ }
66
+ if (platform === "web") {
67
+ response.headers["X-Platform-Latest-Version"] = this.latestVersions.web;
68
+ }
69
+ try {
70
+ response.headers["X-Version"] = Math.min(structures_1.Version, request.getVersion());
71
+ }
72
+ catch (e) {
73
+ // No version provided or invalid version
74
+ }
75
+ }
76
+ }
77
+ exports.VersionMiddleware = VersionMiddleware;
78
+ //# sourceMappingURL=VersionMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VersionMiddleware.js","sourceRoot":"","sources":["../../src/VersionMiddleware.ts"],"names":[],"mappings":";;;AACA,6DAAuF;AACvF,sDAAgD;AAEhD,MAAa,iBAAiB;IAI1B,YAAY,OAA+F;QACvG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;QAC5C,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,CAAA;IAChD,CAAC;IAED,aAAa,CAAC,OAAgB;QAC1B,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACvB,OAAM;QACV,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAE/C,IAAI,OAAgB,CAAC;QAErB,IAAI,CAAC;YACD,OAAO,GAAG,OAAO,CAAC,UAAU,EAAE,CAAA;QAClC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,IAAI,CAAC,IAAA,6BAAa,EAAC,CAAC,CAAC,IAAI,IAAA,8BAAc,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC1E,yCAAyC;gBACzC,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CA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AI,CAAC;YACD,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,oBAAO,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAA;QAC3E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,yCAAyC;QAC7C,CAAC;IACL,CAAC;CACJ;AA/ED,8CA+EC"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@stamhoofd/backend-middleware",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "UNLICENCED",
7
7
  "sideEffects": false,
8
8
  "files": [
9
- "src"
9
+ "src",
10
+ "dist"
10
11
  ],
11
12
  "scripts": {
12
13
  "build": "tsc -b",
@@ -17,5 +18,5 @@
17
18
  "@simonbackx/simple-errors": "^1.4",
18
19
  "@simonbackx/simple-logging": "^1.0.1"
19
20
  },
20
- "gitHead": "b5773c547dceaae52b9c2a098b222417fcd42e4f"
21
+ "gitHead": "22be7c0740ce4705470d6fc79b5a50ccccabad9d"
21
22
  }