quidproquo-webserver 0.0.26 → 0.0.27
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/config/QPQConfig.d.ts +2 -1
- package/lib/config/QPQConfig.js +1 -0
- package/lib/config/settings/defaultRouteOptions.d.ts +6 -0
- package/lib/config/settings/defaultRouteOptions.js +9 -0
- package/lib/config/settings/index.d.ts +1 -0
- package/lib/config/settings/index.js +1 -0
- package/lib/config/settings/route.d.ts +3 -1
- package/lib/qpqWebServerUtils.d.ts +6 -0
- package/lib/qpqWebServerUtils.js +43 -3
- package/lib/types/HTTPEvent.d.ts +4 -3
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare enum QPQWebServerConfigSettingType {
|
|
2
2
|
Route = "@quidproquo-webserver/config/Route",
|
|
3
3
|
Dns = "@quidproquo-webserver/config/Dns",
|
|
4
|
-
OpenApi = "@quidproquo-webserver/config/OpenApi"
|
|
4
|
+
OpenApi = "@quidproquo-webserver/config/OpenApi",
|
|
5
|
+
DefaultRouteOptions = "@quidproquo-webserver/config/DefaultRouteOptions"
|
|
5
6
|
}
|
package/lib/config/QPQConfig.js
CHANGED
|
@@ -6,4 +6,5 @@ var QPQWebServerConfigSettingType;
|
|
|
6
6
|
QPQWebServerConfigSettingType["Route"] = "@quidproquo-webserver/config/Route";
|
|
7
7
|
QPQWebServerConfigSettingType["Dns"] = "@quidproquo-webserver/config/Dns";
|
|
8
8
|
QPQWebServerConfigSettingType["OpenApi"] = "@quidproquo-webserver/config/OpenApi";
|
|
9
|
+
QPQWebServerConfigSettingType["DefaultRouteOptions"] = "@quidproquo-webserver/config/DefaultRouteOptions";
|
|
9
10
|
})(QPQWebServerConfigSettingType = exports.QPQWebServerConfigSettingType || (exports.QPQWebServerConfigSettingType = {}));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QPQConfigSetting } from 'quidproquo-core';
|
|
2
|
+
import { RouteOptions } from './route';
|
|
3
|
+
export interface DefaultRouteOptionsQPQWebServerConfigSetting extends QPQConfigSetting {
|
|
4
|
+
routeOptions: RouteOptions;
|
|
5
|
+
}
|
|
6
|
+
export declare const defineDefaultRouteOptions: (routeOptions: RouteOptions) => DefaultRouteOptionsQPQWebServerConfigSetting;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineDefaultRouteOptions = void 0;
|
|
4
|
+
const QPQConfig_1 = require("../QPQConfig");
|
|
5
|
+
const defineDefaultRouteOptions = (routeOptions) => ({
|
|
6
|
+
configSettingType: QPQConfig_1.QPQWebServerConfigSettingType.DefaultRouteOptions,
|
|
7
|
+
routeOptions,
|
|
8
|
+
});
|
|
9
|
+
exports.defineDefaultRouteOptions = defineDefaultRouteOptions;
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./defaultRouteOptions"), exports);
|
|
17
18
|
__exportStar(require("./dns"), exports);
|
|
18
19
|
__exportStar(require("./openApi"), exports);
|
|
19
20
|
__exportStar(require("./route"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { QPQConfigSetting, HTTPMethod } from 'quidproquo-core';
|
|
2
|
-
export type RouteOptions = {
|
|
2
|
+
export type RouteOptions = {
|
|
3
|
+
allowedOrigins?: string[];
|
|
4
|
+
};
|
|
3
5
|
export interface RouteQPQWebServerConfigSetting extends QPQConfigSetting {
|
|
4
6
|
method: HTTPMethod;
|
|
5
7
|
path: string;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { QPQConfig } from 'quidproquo-core';
|
|
2
2
|
import { RouteQPQWebServerConfigSetting } from './config/settings/route';
|
|
3
3
|
import { OpenApiQPQWebServerConfigSetting } from './config/settings/openApi';
|
|
4
|
+
import { HttpEventHeaders } from './types/HTTPEvent';
|
|
5
|
+
import { RouteOptions } from './config/settings/route';
|
|
4
6
|
export declare const getAllRoutes: (configs: QPQConfig) => RouteQPQWebServerConfigSetting[];
|
|
5
7
|
export declare const getAllOpenApiSpecs: (configs: QPQConfig) => OpenApiQPQWebServerConfigSetting[];
|
|
6
8
|
export declare const getAllSrcEntries: (configs: QPQConfig) => string[];
|
|
7
9
|
export declare const getDomainName: (configs: QPQConfig) => string;
|
|
10
|
+
export declare const getFeatureDomainName: (configs: QPQConfig) => string;
|
|
11
|
+
export declare const getHeaderValue: (header: string, headers: HttpEventHeaders) => string | null;
|
|
12
|
+
export declare const getAllowedOrigins: (configs: QPQConfig, route: RouteOptions) => string[];
|
|
13
|
+
export declare const getCorsHeaders: (configs: QPQConfig, route: RouteOptions, reqHeaders: HttpEventHeaders) => HttpEventHeaders;
|
package/lib/qpqWebServerUtils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDomainName = exports.getAllSrcEntries = exports.getAllOpenApiSpecs = exports.getAllRoutes = void 0;
|
|
3
|
+
exports.getCorsHeaders = exports.getAllowedOrigins = exports.getHeaderValue = exports.getFeatureDomainName = exports.getDomainName = exports.getAllSrcEntries = exports.getAllOpenApiSpecs = exports.getAllRoutes = void 0;
|
|
4
4
|
const quidproquo_core_1 = require("quidproquo-core");
|
|
5
5
|
const QPQConfig_1 = require("./config/QPQConfig");
|
|
6
|
+
const qpqCoreUtils_1 = require("quidproquo-core/lib/qpqCoreUtils");
|
|
6
7
|
const getAllRoutes = (configs) => {
|
|
7
8
|
const routes = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.Route);
|
|
8
9
|
return routes;
|
|
@@ -22,10 +23,49 @@ const getAllSrcEntries = (configs) => {
|
|
|
22
23
|
];
|
|
23
24
|
};
|
|
24
25
|
exports.getAllSrcEntries = getAllSrcEntries;
|
|
25
|
-
// Used in bundlers to know where and what to build and index
|
|
26
|
-
// Events, routes, etc
|
|
27
26
|
const getDomainName = (configs) => {
|
|
28
27
|
const dnsSettings = quidproquo_core_1.qpqCoreUtils.getConfigSetting(configs, QPQConfig_1.QPQWebServerConfigSettingType.Dns);
|
|
29
28
|
return (dnsSettings === null || dnsSettings === void 0 ? void 0 : dnsSettings.dnsBase) || '';
|
|
30
29
|
};
|
|
31
30
|
exports.getDomainName = getDomainName;
|
|
31
|
+
const getFeatureDomainName = (configs) => {
|
|
32
|
+
const feature = (0, qpqCoreUtils_1.getAppFeature)(configs);
|
|
33
|
+
const apexDomainName = (0, exports.getDomainName)(configs);
|
|
34
|
+
if (feature === 'production') {
|
|
35
|
+
return apexDomainName;
|
|
36
|
+
}
|
|
37
|
+
return `${feature}.${apexDomainName}`;
|
|
38
|
+
};
|
|
39
|
+
exports.getFeatureDomainName = getFeatureDomainName;
|
|
40
|
+
const getHeaderValue = (header, headers) => {
|
|
41
|
+
const headerAsLower = header.toLowerCase();
|
|
42
|
+
const realHeaderKey = Object.keys(headers).find((k) => k.toLowerCase() === headerAsLower);
|
|
43
|
+
if (!realHeaderKey) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return headers[realHeaderKey] || null;
|
|
47
|
+
};
|
|
48
|
+
exports.getHeaderValue = getHeaderValue;
|
|
49
|
+
const getAllowedOrigins = (configs, route) => {
|
|
50
|
+
// Root domain
|
|
51
|
+
const rootDomain = `https://${(0, exports.getFeatureDomainName)(configs)}`;
|
|
52
|
+
// generic settings
|
|
53
|
+
const defaultRouteSettings = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.DefaultRouteOptions) || [];
|
|
54
|
+
const defaultAllowedOrigins = defaultRouteSettings.reduce((acc, cur) => [...acc, ...(cur.routeOptions.allowedOrigins || [])], []);
|
|
55
|
+
// Route specific
|
|
56
|
+
const routeAllowedOrigins = route.allowedOrigins || [];
|
|
57
|
+
return [rootDomain, ...defaultAllowedOrigins, ...routeAllowedOrigins].map((o) => o.toLowerCase());
|
|
58
|
+
};
|
|
59
|
+
exports.getAllowedOrigins = getAllowedOrigins;
|
|
60
|
+
const getCorsHeaders = (configs, route, reqHeaders) => {
|
|
61
|
+
const origin = (0, exports.getHeaderValue)('origin', reqHeaders) || '';
|
|
62
|
+
const allowedOrigins = (0, exports.getAllowedOrigins)(configs, route);
|
|
63
|
+
const allowOrigin = allowedOrigins.find((ao) => ao === origin) || allowedOrigins[0];
|
|
64
|
+
return {
|
|
65
|
+
'Access-Control-Allow-Headers': '*',
|
|
66
|
+
'Access-Control-Allow-Methods': '*',
|
|
67
|
+
'Access-Control-Allow-Origin': allowOrigin,
|
|
68
|
+
Vary: 'Origin',
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
exports.getCorsHeaders = getCorsHeaders;
|
package/lib/types/HTTPEvent.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { HTTPMethod } from 'quidproquo-core';
|
|
2
|
+
export interface HttpEventHeaders {
|
|
3
|
+
[key: string]: undefined | string;
|
|
4
|
+
}
|
|
2
5
|
export interface HTTPEventParams<T> {
|
|
3
6
|
path: string;
|
|
4
7
|
query: {
|
|
5
8
|
[key: string]: undefined | string | string[];
|
|
6
9
|
};
|
|
7
10
|
body: T;
|
|
8
|
-
headers:
|
|
9
|
-
[key: string]: undefined | string;
|
|
10
|
-
};
|
|
11
|
+
headers: HttpEventHeaders;
|
|
11
12
|
method: HTTPMethod;
|
|
12
13
|
correlation: string;
|
|
13
14
|
sourceIp: string;
|