quidproquo-webserver 0.0.70 → 0.0.72
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/settings/route.d.ts +7 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -14
- package/lib/qpqWebServerUtils.d.ts +1 -26
- package/lib/qpqWebServerUtils.js +2 -140
- package/lib/types/HTTPEvent.d.ts +4 -1
- package/lib/types/QueueEvent.d.ts +8 -0
- package/lib/types/QueueEvent.js +2 -0
- package/lib/types/SEOEvent.d.ts +4 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/utils/headerUtils.d.ts +6 -0
- package/lib/utils/headerUtils.js +38 -0
- package/lib/utils/httpEventUtils.d.ts +3 -0
- package/lib/utils/httpEventUtils.js +21 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +20 -0
- package/lib/utils/mergeRouteUtils.d.ts +6 -0
- package/lib/utils/mergeRouteUtils.js +35 -0
- package/lib/utils/qpqConfigAccessorsUtils.d.ts +21 -0
- package/lib/utils/qpqConfigAccessorsUtils.js +136 -0
- package/package.json +1 -1
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { QPQConfigSetting, HTTPMethod } from 'quidproquo-core';
|
|
2
|
+
export interface RouteAuthSettings {
|
|
3
|
+
userDirectoryName?: string;
|
|
4
|
+
applicationName?: string;
|
|
5
|
+
serviceName?: string;
|
|
6
|
+
scopes?: string[];
|
|
7
|
+
}
|
|
2
8
|
export type RouteOptions = {
|
|
3
9
|
allowedOrigins?: string[];
|
|
10
|
+
routeAuthSettings?: RouteAuthSettings;
|
|
4
11
|
};
|
|
5
12
|
export interface RouteQPQWebServerConfigSetting extends QPQConfigSetting {
|
|
6
13
|
method: HTTPMethod;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -10,24 +10,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.qpqWebServerUtils = void 0;
|
|
30
17
|
__exportStar(require("./actions"), exports);
|
|
31
18
|
__exportStar(require("./config"), exports);
|
|
32
19
|
__exportStar(require("./types"), exports);
|
|
33
|
-
|
|
20
|
+
__exportStar(require("./qpqWebServerUtils"), exports);
|
|
@@ -1,26 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { RouteQPQWebServerConfigSetting } from './config/settings/route';
|
|
3
|
-
import { SeoQPQWebServerConfigSetting } from './config/settings/seo';
|
|
4
|
-
import { SubdomainRedirectQPQWebServerConfigSetting } from './config/settings/subdomainRedirect';
|
|
5
|
-
import { OpenApiQPQWebServerConfigSetting } from './config/settings/openApi';
|
|
6
|
-
import { HttpEventHeaders, HTTPEventParams, HTTPEventResponse } from './types/HTTPEvent';
|
|
7
|
-
import { RouteOptions } from './config/settings/route';
|
|
8
|
-
import { WebEntryQPQWebServerConfigSetting, ApiQPQWebServerConfigSetting } from './config';
|
|
9
|
-
export declare const getAllRoutes: (configs: QPQConfig) => RouteQPQWebServerConfigSetting[];
|
|
10
|
-
export declare const getAllSeo: (configs: QPQConfig) => SeoQPQWebServerConfigSetting[];
|
|
11
|
-
export declare const getAllOpenApiSpecs: (configs: QPQConfig) => OpenApiQPQWebServerConfigSetting[];
|
|
12
|
-
export declare const getAllSrcEntries: (configs: QPQConfig) => string[];
|
|
13
|
-
export declare const getDomainName: (configs: QPQConfig) => string;
|
|
14
|
-
export declare const getWebEntry: (configs: QPQConfig) => string;
|
|
15
|
-
export declare const getWebEntryFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
|
|
16
|
-
export declare const getWebEntrySeoFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
|
|
17
|
-
export declare const getApiEntryFullPath: (qpqConfig: QPQConfig, apiConfig: ApiQPQWebServerConfigSetting) => string;
|
|
18
|
-
export declare const getSubdomainRedirects: (configs: QPQConfig) => SubdomainRedirectQPQWebServerConfigSetting[];
|
|
19
|
-
export declare const getEnvironmentDomainName: (configs: QPQConfig) => string;
|
|
20
|
-
export declare const getBaseDomainName: (qpqConfig: QPQConfig) => string;
|
|
21
|
-
export declare const getServiceDomainName: (qpqConfig: QPQConfig) => string;
|
|
22
|
-
export declare const getHeaderValue: (header: string, headers: HttpEventHeaders) => string | null;
|
|
23
|
-
export declare const getAllowedOrigins: (configs: QPQConfig, route: RouteOptions) => string[];
|
|
24
|
-
export declare const getCorsHeaders: (configs: QPQConfig, route: RouteOptions, reqHeaders: HttpEventHeaders) => HttpEventHeaders;
|
|
25
|
-
export declare const fromJsonEventRequest: <T>(httpJsonEvent: HTTPEventParams) => T;
|
|
26
|
-
export declare const toJsonEventResponse: (item: any, status?: number) => HTTPEventResponse;
|
|
1
|
+
export * as qpqWebServerUtils from './utils';
|
package/lib/qpqWebServerUtils.js
CHANGED
|
@@ -23,143 +23,5 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
|
|
28
|
-
const quidproquo_core_1 = require("quidproquo-core");
|
|
29
|
-
const QPQConfig_1 = require("./config/QPQConfig");
|
|
30
|
-
const qpqCoreUtils_1 = require("quidproquo-core/lib/qpqCoreUtils");
|
|
31
|
-
const getAllRoutes = (configs) => {
|
|
32
|
-
const routes = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.Route);
|
|
33
|
-
return routes;
|
|
34
|
-
};
|
|
35
|
-
exports.getAllRoutes = getAllRoutes;
|
|
36
|
-
const getAllSeo = (configs) => {
|
|
37
|
-
const seoConfigs = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.Seo);
|
|
38
|
-
return seoConfigs;
|
|
39
|
-
};
|
|
40
|
-
exports.getAllSeo = getAllSeo;
|
|
41
|
-
const getAllOpenApiSpecs = (configs) => {
|
|
42
|
-
const openApiSpecs = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.OpenApi);
|
|
43
|
-
return openApiSpecs;
|
|
44
|
-
};
|
|
45
|
-
exports.getAllOpenApiSpecs = getAllOpenApiSpecs;
|
|
46
|
-
// Used in bundlers to know where and what to build and index
|
|
47
|
-
// Events, routes, etc
|
|
48
|
-
const getAllSrcEntries = (configs) => {
|
|
49
|
-
return [
|
|
50
|
-
...(0, exports.getAllRoutes)(configs).map((r) => r.src),
|
|
51
|
-
...(0, exports.getAllOpenApiSpecs)(configs).map((r) => r.openApiSpecPath),
|
|
52
|
-
...(0, exports.getAllSeo)(configs).map((seo) => seo.src),
|
|
53
|
-
];
|
|
54
|
-
};
|
|
55
|
-
exports.getAllSrcEntries = getAllSrcEntries;
|
|
56
|
-
const getDomainName = (configs) => {
|
|
57
|
-
const dnsSettings = quidproquo_core_1.qpqCoreUtils.getConfigSetting(configs, QPQConfig_1.QPQWebServerConfigSettingType.Dns);
|
|
58
|
-
return (dnsSettings === null || dnsSettings === void 0 ? void 0 : dnsSettings.dnsBase) || '';
|
|
59
|
-
};
|
|
60
|
-
exports.getDomainName = getDomainName;
|
|
61
|
-
const getWebEntry = (configs) => {
|
|
62
|
-
const webEntry = quidproquo_core_1.qpqCoreUtils.getConfigSetting(configs, QPQConfig_1.QPQWebServerConfigSettingType.WebEntry);
|
|
63
|
-
if (!(webEntry === null || webEntry === void 0 ? void 0 : webEntry.buildPath)) {
|
|
64
|
-
throw new Error('please use defineWebEntry in your qpq config');
|
|
65
|
-
}
|
|
66
|
-
return webEntry === null || webEntry === void 0 ? void 0 : webEntry.buildPath;
|
|
67
|
-
};
|
|
68
|
-
exports.getWebEntry = getWebEntry;
|
|
69
|
-
const getWebEntryFullPath = (qpqConfig, webEntryQPQWebServerConfigSetting) => {
|
|
70
|
-
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), webEntryQPQWebServerConfigSetting.buildPath || '');
|
|
71
|
-
};
|
|
72
|
-
exports.getWebEntryFullPath = getWebEntryFullPath;
|
|
73
|
-
const getWebEntrySeoFullPath = (qpqConfig, webEntryQPQWebServerConfigSetting) => {
|
|
74
|
-
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), webEntryQPQWebServerConfigSetting.seoBuildPath ||
|
|
75
|
-
webEntryQPQWebServerConfigSetting.buildPath ||
|
|
76
|
-
'');
|
|
77
|
-
};
|
|
78
|
-
exports.getWebEntrySeoFullPath = getWebEntrySeoFullPath;
|
|
79
|
-
const getApiEntryFullPath = (qpqConfig, apiConfig) => {
|
|
80
|
-
const apiEntry = apiConfig.buildPath;
|
|
81
|
-
if (!apiEntry) {
|
|
82
|
-
throw new Error('please use defineWebEntry in your qpq config');
|
|
83
|
-
}
|
|
84
|
-
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), apiEntry);
|
|
85
|
-
};
|
|
86
|
-
exports.getApiEntryFullPath = getApiEntryFullPath;
|
|
87
|
-
const getSubdomainRedirects = (configs) => {
|
|
88
|
-
const subdomainRedirects = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.SubdomainRedirect);
|
|
89
|
-
return subdomainRedirects;
|
|
90
|
-
};
|
|
91
|
-
exports.getSubdomainRedirects = getSubdomainRedirects;
|
|
92
|
-
const getEnvironmentDomainName = (configs) => {
|
|
93
|
-
const environment = (0, qpqCoreUtils_1.getApplicationModuleEnvironment)(configs);
|
|
94
|
-
const apexDomainName = (0, exports.getDomainName)(configs);
|
|
95
|
-
if (environment === 'production') {
|
|
96
|
-
return apexDomainName;
|
|
97
|
-
}
|
|
98
|
-
return `${environment}.${apexDomainName}`;
|
|
99
|
-
};
|
|
100
|
-
exports.getEnvironmentDomainName = getEnvironmentDomainName;
|
|
101
|
-
const getBaseDomainName = (qpqConfig) => {
|
|
102
|
-
const environmentDomain = (0, exports.getEnvironmentDomainName)(qpqConfig);
|
|
103
|
-
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
104
|
-
if (feature) {
|
|
105
|
-
return `${feature}.${environmentDomain}`;
|
|
106
|
-
}
|
|
107
|
-
return environmentDomain;
|
|
108
|
-
};
|
|
109
|
-
exports.getBaseDomainName = getBaseDomainName;
|
|
110
|
-
const getServiceDomainName = (qpqConfig) => {
|
|
111
|
-
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
112
|
-
const domainBase = (0, exports.getBaseDomainName)(qpqConfig);
|
|
113
|
-
return `${service}.${domainBase}`;
|
|
114
|
-
};
|
|
115
|
-
exports.getServiceDomainName = getServiceDomainName;
|
|
116
|
-
const getHeaderValue = (header, headers) => {
|
|
117
|
-
const headerAsLower = header.toLowerCase();
|
|
118
|
-
const realHeaderKey = Object.keys(headers).find((k) => k.toLowerCase() === headerAsLower);
|
|
119
|
-
if (!realHeaderKey) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
return headers[realHeaderKey] || null;
|
|
123
|
-
};
|
|
124
|
-
exports.getHeaderValue = getHeaderValue;
|
|
125
|
-
const getAllowedOrigins = (configs, route) => {
|
|
126
|
-
// Root domain
|
|
127
|
-
const rootDomain = `https://${(0, exports.getBaseDomainName)(configs)}`;
|
|
128
|
-
// generic settings
|
|
129
|
-
const defaultRouteSettings = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.DefaultRouteOptions) || [];
|
|
130
|
-
const defaultAllowedOrigins = defaultRouteSettings.reduce((acc, cur) => [...acc, ...(cur.routeOptions.allowedOrigins || [])], []);
|
|
131
|
-
// Route specific
|
|
132
|
-
const routeAllowedOrigins = route.allowedOrigins || [];
|
|
133
|
-
return [rootDomain, ...defaultAllowedOrigins, ...routeAllowedOrigins].map((o) => o.toLowerCase());
|
|
134
|
-
};
|
|
135
|
-
exports.getAllowedOrigins = getAllowedOrigins;
|
|
136
|
-
const getCorsHeaders = (configs, route, reqHeaders) => {
|
|
137
|
-
const origin = (0, exports.getHeaderValue)('origin', reqHeaders) || '';
|
|
138
|
-
const allowedOrigins = (0, exports.getAllowedOrigins)(configs, route);
|
|
139
|
-
const allowOrigin = allowedOrigins.find((ao) => ao === origin) || allowedOrigins[0];
|
|
140
|
-
return {
|
|
141
|
-
'Access-Control-Allow-Headers': '*',
|
|
142
|
-
'Access-Control-Allow-Methods': '*',
|
|
143
|
-
'Access-Control-Allow-Origin': allowOrigin,
|
|
144
|
-
Vary: 'Origin',
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
exports.getCorsHeaders = getCorsHeaders;
|
|
148
|
-
const fromJsonEventRequest = (httpJsonEvent) => {
|
|
149
|
-
const item = JSON.parse(httpJsonEvent.isBase64Encoded
|
|
150
|
-
? Buffer.from(httpJsonEvent.body, 'base64').toString()
|
|
151
|
-
: httpJsonEvent.body);
|
|
152
|
-
return item;
|
|
153
|
-
};
|
|
154
|
-
exports.fromJsonEventRequest = fromJsonEventRequest;
|
|
155
|
-
const toJsonEventResponse = (item, status = 200) => {
|
|
156
|
-
return {
|
|
157
|
-
status,
|
|
158
|
-
body: JSON.stringify(item),
|
|
159
|
-
isBase64Encoded: false,
|
|
160
|
-
headers: {
|
|
161
|
-
'content-type': 'application/json',
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
exports.toJsonEventResponse = toJsonEventResponse;
|
|
26
|
+
exports.qpqWebServerUtils = void 0;
|
|
27
|
+
exports.qpqWebServerUtils = __importStar(require("./utils"));
|
package/lib/types/HTTPEvent.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { HTTPMethod } from 'quidproquo-core';
|
|
|
2
2
|
export interface HttpEventHeaders {
|
|
3
3
|
[key: string]: undefined | string;
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
5
|
+
export interface HttpEventRouteParams {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HTTPEvent<T = string> {
|
|
6
9
|
path: string;
|
|
7
10
|
query: {
|
|
8
11
|
[key: string]: undefined | string | string[];
|
package/lib/types/SEOEvent.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { HTTPMethod } from 'quidproquo-core';
|
|
|
2
2
|
export interface SeoEventHeaders {
|
|
3
3
|
[key: string]: undefined | string;
|
|
4
4
|
}
|
|
5
|
-
export interface
|
|
5
|
+
export interface SeoEventRouteParams {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SeoEvent<T = null> {
|
|
6
9
|
path: string;
|
|
7
10
|
query: {
|
|
8
11
|
[key: string]: undefined | string | string[];
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/index.js
CHANGED
|
@@ -15,5 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./HTTPEvent"), exports);
|
|
18
|
+
__exportStar(require("./QueueEvent"), exports);
|
|
18
19
|
__exportStar(require("./SEOEvent"), exports);
|
|
19
20
|
__exportStar(require("./constants"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QPQConfig } from 'quidproquo-core';
|
|
2
|
+
import { HttpEventHeaders } from '../types/HTTPEvent';
|
|
3
|
+
import { RouteOptions } from '../config/settings/route';
|
|
4
|
+
export declare const getHeaderValue: (header: string, headers: HttpEventHeaders) => string | null;
|
|
5
|
+
export declare const getAllowedOrigins: (qpqConfig: QPQConfig, route: RouteOptions) => string[];
|
|
6
|
+
export declare const getCorsHeaders: (qpqConfig: QPQConfig, route: RouteOptions, reqHeaders: HttpEventHeaders) => HttpEventHeaders;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCorsHeaders = exports.getAllowedOrigins = exports.getHeaderValue = void 0;
|
|
4
|
+
const qpqConfigAccessorsUtils_1 = require("./qpqConfigAccessorsUtils");
|
|
5
|
+
const qpqWebServerUtils_1 = require("../qpqWebServerUtils");
|
|
6
|
+
const getHeaderValue = (header, headers) => {
|
|
7
|
+
const headerAsLower = header.toLowerCase();
|
|
8
|
+
const realHeaderKey = Object.keys(headers).find((k) => k.toLowerCase() === headerAsLower);
|
|
9
|
+
if (!realHeaderKey) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return headers[realHeaderKey] || null;
|
|
13
|
+
};
|
|
14
|
+
exports.getHeaderValue = getHeaderValue;
|
|
15
|
+
const getAllowedOrigins = (qpqConfig, route) => {
|
|
16
|
+
// Root domain
|
|
17
|
+
const rootDomain = `https://${(0, qpqConfigAccessorsUtils_1.getBaseDomainName)(qpqConfig)}`;
|
|
18
|
+
// generic settings
|
|
19
|
+
const defaultRouteSettings = qpqWebServerUtils_1.qpqWebServerUtils.getDefaultRouteSettings(qpqConfig);
|
|
20
|
+
const defaultAllowedOrigins = defaultRouteSettings.reduce((acc, cur) => [...acc, ...(cur.routeOptions.allowedOrigins || [])], []);
|
|
21
|
+
// Route specific
|
|
22
|
+
const routeAllowedOrigins = route.allowedOrigins || [];
|
|
23
|
+
return [rootDomain, ...defaultAllowedOrigins, ...routeAllowedOrigins].map((o) => o.toLowerCase());
|
|
24
|
+
};
|
|
25
|
+
exports.getAllowedOrigins = getAllowedOrigins;
|
|
26
|
+
const getCorsHeaders = (qpqConfig, route, reqHeaders) => {
|
|
27
|
+
const origin = (0, exports.getHeaderValue)('origin', reqHeaders) || '';
|
|
28
|
+
const allowedOrigins = (0, exports.getAllowedOrigins)(qpqConfig, route);
|
|
29
|
+
const allowOrigin = allowedOrigins.find((ao) => ao === origin) || allowedOrigins[0];
|
|
30
|
+
return {
|
|
31
|
+
'Access-Control-Allow-Headers': '*',
|
|
32
|
+
'Access-Control-Allow-Methods': '*',
|
|
33
|
+
'Access-Control-Allow-Origin': allowOrigin,
|
|
34
|
+
'Access-Control-Allow-Credentials': `${!!route.routeAuthSettings}`,
|
|
35
|
+
Vary: 'Origin',
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
exports.getCorsHeaders = getCorsHeaders;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toJsonEventResponse = exports.fromJsonEventRequest = void 0;
|
|
4
|
+
const fromJsonEventRequest = (httpJsonEvent) => {
|
|
5
|
+
const item = JSON.parse(httpJsonEvent.isBase64Encoded
|
|
6
|
+
? Buffer.from(httpJsonEvent.body, 'base64').toString()
|
|
7
|
+
: httpJsonEvent.body);
|
|
8
|
+
return item;
|
|
9
|
+
};
|
|
10
|
+
exports.fromJsonEventRequest = fromJsonEventRequest;
|
|
11
|
+
const toJsonEventResponse = (item, status = 200) => {
|
|
12
|
+
return {
|
|
13
|
+
status,
|
|
14
|
+
body: JSON.stringify(item),
|
|
15
|
+
isBase64Encoded: false,
|
|
16
|
+
headers: {
|
|
17
|
+
'content-type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
exports.toJsonEventResponse = toJsonEventResponse;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./headerUtils"), exports);
|
|
18
|
+
__exportStar(require("./httpEventUtils"), exports);
|
|
19
|
+
__exportStar(require("./mergeRouteUtils"), exports);
|
|
20
|
+
__exportStar(require("./qpqConfigAccessorsUtils"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { QPQConfig } from 'quidproquo-core';
|
|
2
|
+
import { RouteAuthSettings, RouteQPQWebServerConfigSetting } from '../config/settings/route';
|
|
3
|
+
import { RouteOptions } from '../config/settings/route';
|
|
4
|
+
export declare const mergeRouteAuthSettings: (routeAuthSettingsA?: RouteAuthSettings, routeAuthSettingsB?: RouteAuthSettings) => RouteAuthSettings;
|
|
5
|
+
export declare const mergeRouteOptions: (routeOptionsA: RouteOptions, routeOptionsB: RouteOptions) => RouteOptions;
|
|
6
|
+
export declare const mergeAllRouteOptions: (activeApi: string, routeConfig: RouteQPQWebServerConfigSetting, qpqConfig: QPQConfig) => RouteOptions;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeAllRouteOptions = exports.mergeRouteOptions = exports.mergeRouteAuthSettings = void 0;
|
|
4
|
+
const qpqConfigAccessorsUtils_1 = require("./qpqConfigAccessorsUtils");
|
|
5
|
+
const mergeRouteAuthSettings = (routeAuthSettingsA, routeAuthSettingsB) => {
|
|
6
|
+
return {
|
|
7
|
+
applicationName: (routeAuthSettingsB === null || routeAuthSettingsB === void 0 ? void 0 : routeAuthSettingsB.applicationName) || (routeAuthSettingsA === null || routeAuthSettingsA === void 0 ? void 0 : routeAuthSettingsA.applicationName),
|
|
8
|
+
serviceName: (routeAuthSettingsB === null || routeAuthSettingsB === void 0 ? void 0 : routeAuthSettingsB.serviceName) || (routeAuthSettingsA === null || routeAuthSettingsA === void 0 ? void 0 : routeAuthSettingsA.serviceName),
|
|
9
|
+
userDirectoryName: (routeAuthSettingsB === null || routeAuthSettingsB === void 0 ? void 0 : routeAuthSettingsB.userDirectoryName) || (routeAuthSettingsA === null || routeAuthSettingsA === void 0 ? void 0 : routeAuthSettingsA.userDirectoryName),
|
|
10
|
+
scopes: [
|
|
11
|
+
...new Set([...((routeAuthSettingsB === null || routeAuthSettingsB === void 0 ? void 0 : routeAuthSettingsB.scopes) || []), ...((routeAuthSettingsB === null || routeAuthSettingsB === void 0 ? void 0 : routeAuthSettingsB.scopes) || [])]),
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.mergeRouteAuthSettings = mergeRouteAuthSettings;
|
|
16
|
+
const mergeRouteOptions = (routeOptionsA, routeOptionsB) => {
|
|
17
|
+
return {
|
|
18
|
+
allowedOrigins: [
|
|
19
|
+
...new Set([
|
|
20
|
+
...(routeOptionsB.allowedOrigins || []),
|
|
21
|
+
...(routeOptionsA.allowedOrigins || []),
|
|
22
|
+
]),
|
|
23
|
+
],
|
|
24
|
+
routeAuthSettings: (0, exports.mergeRouteAuthSettings)(routeOptionsA.routeAuthSettings, routeOptionsB.routeAuthSettings),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.mergeRouteOptions = mergeRouteOptions;
|
|
28
|
+
const mergeAllRouteOptions = (activeApi, routeConfig, qpqConfig) => {
|
|
29
|
+
// TODO: This needs to filter active route on the current route Config
|
|
30
|
+
// activeApi
|
|
31
|
+
const defaultOptions = (0, qpqConfigAccessorsUtils_1.getDefaultRouteSettings)(qpqConfig).map((o) => o.routeOptions);
|
|
32
|
+
const routeOptions = routeConfig.options;
|
|
33
|
+
return [...defaultOptions, routeOptions].reduce((acc, opt) => (0, exports.mergeRouteOptions)(acc, opt), {});
|
|
34
|
+
};
|
|
35
|
+
exports.mergeAllRouteOptions = mergeAllRouteOptions;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { QPQConfig } from 'quidproquo-core';
|
|
2
|
+
import { RouteQPQWebServerConfigSetting, DnsQPQWebServerConfigSetting, SeoQPQWebServerConfigSetting, SubdomainRedirectQPQWebServerConfigSetting, OpenApiQPQWebServerConfigSetting, DefaultRouteOptionsQPQWebServerConfigSetting } from '../config';
|
|
3
|
+
import { WebEntryQPQWebServerConfigSetting, ApiQPQWebServerConfigSetting } from '../config';
|
|
4
|
+
export declare const getAllRoutes: (qpqConfig: QPQConfig) => RouteQPQWebServerConfigSetting[];
|
|
5
|
+
export declare const getAllRoutesForApi: (apiName: string, qpqConfig: QPQConfig) => RouteQPQWebServerConfigSetting[];
|
|
6
|
+
export declare const getAllSeo: (qpqConfig: QPQConfig) => SeoQPQWebServerConfigSetting[];
|
|
7
|
+
export declare const getAllOpenApiSpecs: (configs: QPQConfig) => OpenApiQPQWebServerConfigSetting[];
|
|
8
|
+
export declare const getAllSrcEntries: (configs: QPQConfig) => string[];
|
|
9
|
+
export declare const getDomainName: (configs: QPQConfig) => string;
|
|
10
|
+
export declare const getWebEntry: (configs: QPQConfig) => string;
|
|
11
|
+
export declare const getWebEntryFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
|
|
12
|
+
export declare const getWebEntrySeoFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
|
|
13
|
+
export declare const getApiEntryFullPath: (qpqConfig: QPQConfig, apiConfig: ApiQPQWebServerConfigSetting) => string;
|
|
14
|
+
export declare const getSubdomainRedirects: (configs: QPQConfig) => SubdomainRedirectQPQWebServerConfigSetting[];
|
|
15
|
+
export declare const getApiConfigs: (configs: QPQConfig) => ApiQPQWebServerConfigSetting[];
|
|
16
|
+
export declare const getDnsConfigs: (configs: QPQConfig) => DnsQPQWebServerConfigSetting[];
|
|
17
|
+
export declare const getWebEntryConfigs: (configs: QPQConfig) => WebEntryQPQWebServerConfigSetting[];
|
|
18
|
+
export declare const getEnvironmentDomainName: (configs: QPQConfig) => string;
|
|
19
|
+
export declare const getBaseDomainName: (qpqConfig: QPQConfig) => string;
|
|
20
|
+
export declare const getServiceDomainName: (qpqConfig: QPQConfig) => string;
|
|
21
|
+
export declare const getDefaultRouteSettings: (qpqConfig: QPQConfig) => DefaultRouteOptionsQPQWebServerConfigSetting[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getDefaultRouteSettings = exports.getServiceDomainName = exports.getBaseDomainName = exports.getEnvironmentDomainName = exports.getWebEntryConfigs = exports.getDnsConfigs = exports.getApiConfigs = exports.getSubdomainRedirects = exports.getApiEntryFullPath = exports.getWebEntrySeoFullPath = exports.getWebEntryFullPath = exports.getWebEntry = exports.getDomainName = exports.getAllSrcEntries = exports.getAllOpenApiSpecs = exports.getAllSeo = exports.getAllRoutesForApi = exports.getAllRoutes = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const quidproquo_core_1 = require("quidproquo-core");
|
|
29
|
+
const config_1 = require("../config");
|
|
30
|
+
const getAllRoutes = (qpqConfig) => {
|
|
31
|
+
const routes = quidproquo_core_1.qpqCoreUtils.getConfigSettings(qpqConfig, config_1.QPQWebServerConfigSettingType.Route);
|
|
32
|
+
return routes;
|
|
33
|
+
};
|
|
34
|
+
exports.getAllRoutes = getAllRoutes;
|
|
35
|
+
const getAllRoutesForApi = (apiName, qpqConfig) => {
|
|
36
|
+
const routes = (0, exports.getAllRoutes)(qpqConfig);
|
|
37
|
+
return routes;
|
|
38
|
+
};
|
|
39
|
+
exports.getAllRoutesForApi = getAllRoutesForApi;
|
|
40
|
+
const getAllSeo = (qpqConfig) => {
|
|
41
|
+
const seoConfigs = quidproquo_core_1.qpqCoreUtils.getConfigSettings(qpqConfig, config_1.QPQWebServerConfigSettingType.Seo);
|
|
42
|
+
return seoConfigs;
|
|
43
|
+
};
|
|
44
|
+
exports.getAllSeo = getAllSeo;
|
|
45
|
+
const getAllOpenApiSpecs = (configs) => {
|
|
46
|
+
const openApiSpecs = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, config_1.QPQWebServerConfigSettingType.OpenApi);
|
|
47
|
+
return openApiSpecs;
|
|
48
|
+
};
|
|
49
|
+
exports.getAllOpenApiSpecs = getAllOpenApiSpecs;
|
|
50
|
+
// Used in bundlers to know where and what to build and index
|
|
51
|
+
// Events, routes, etc
|
|
52
|
+
const getAllSrcEntries = (configs) => {
|
|
53
|
+
return [
|
|
54
|
+
...(0, exports.getAllRoutes)(configs).map((r) => r.src),
|
|
55
|
+
...(0, exports.getAllOpenApiSpecs)(configs).map((r) => r.openApiSpecPath),
|
|
56
|
+
...(0, exports.getAllSeo)(configs).map((seo) => seo.src),
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
exports.getAllSrcEntries = getAllSrcEntries;
|
|
60
|
+
const getDomainName = (configs) => {
|
|
61
|
+
const dnsSettings = quidproquo_core_1.qpqCoreUtils.getConfigSetting(configs, config_1.QPQWebServerConfigSettingType.Dns);
|
|
62
|
+
return (dnsSettings === null || dnsSettings === void 0 ? void 0 : dnsSettings.dnsBase) || '';
|
|
63
|
+
};
|
|
64
|
+
exports.getDomainName = getDomainName;
|
|
65
|
+
const getWebEntry = (configs) => {
|
|
66
|
+
const webEntry = quidproquo_core_1.qpqCoreUtils.getConfigSetting(configs, config_1.QPQWebServerConfigSettingType.WebEntry);
|
|
67
|
+
if (!(webEntry === null || webEntry === void 0 ? void 0 : webEntry.buildPath)) {
|
|
68
|
+
throw new Error('please use defineWebEntry in your qpq config');
|
|
69
|
+
}
|
|
70
|
+
return webEntry === null || webEntry === void 0 ? void 0 : webEntry.buildPath;
|
|
71
|
+
};
|
|
72
|
+
exports.getWebEntry = getWebEntry;
|
|
73
|
+
const getWebEntryFullPath = (qpqConfig, webEntryQPQWebServerConfigSetting) => {
|
|
74
|
+
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), webEntryQPQWebServerConfigSetting.buildPath || '');
|
|
75
|
+
};
|
|
76
|
+
exports.getWebEntryFullPath = getWebEntryFullPath;
|
|
77
|
+
const getWebEntrySeoFullPath = (qpqConfig, webEntryQPQWebServerConfigSetting) => {
|
|
78
|
+
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), webEntryQPQWebServerConfigSetting.seoBuildPath ||
|
|
79
|
+
webEntryQPQWebServerConfigSetting.buildPath ||
|
|
80
|
+
'');
|
|
81
|
+
};
|
|
82
|
+
exports.getWebEntrySeoFullPath = getWebEntrySeoFullPath;
|
|
83
|
+
const getApiEntryFullPath = (qpqConfig, apiConfig) => {
|
|
84
|
+
const apiEntry = apiConfig.buildPath;
|
|
85
|
+
if (!apiEntry) {
|
|
86
|
+
throw new Error('please use defineWebEntry in your qpq config');
|
|
87
|
+
}
|
|
88
|
+
return path.join(quidproquo_core_1.qpqCoreUtils.getConfigRoot(qpqConfig), apiEntry);
|
|
89
|
+
};
|
|
90
|
+
exports.getApiEntryFullPath = getApiEntryFullPath;
|
|
91
|
+
const getSubdomainRedirects = (configs) => {
|
|
92
|
+
const subdomainRedirects = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, config_1.QPQWebServerConfigSettingType.SubdomainRedirect);
|
|
93
|
+
return subdomainRedirects;
|
|
94
|
+
};
|
|
95
|
+
exports.getSubdomainRedirects = getSubdomainRedirects;
|
|
96
|
+
const getApiConfigs = (configs) => {
|
|
97
|
+
return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, config_1.QPQWebServerConfigSettingType.Api);
|
|
98
|
+
};
|
|
99
|
+
exports.getApiConfigs = getApiConfigs;
|
|
100
|
+
const getDnsConfigs = (configs) => {
|
|
101
|
+
return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, config_1.QPQWebServerConfigSettingType.Dns);
|
|
102
|
+
};
|
|
103
|
+
exports.getDnsConfigs = getDnsConfigs;
|
|
104
|
+
const getWebEntryConfigs = (configs) => {
|
|
105
|
+
return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, config_1.QPQWebServerConfigSettingType.WebEntry);
|
|
106
|
+
};
|
|
107
|
+
exports.getWebEntryConfigs = getWebEntryConfigs;
|
|
108
|
+
const getEnvironmentDomainName = (configs) => {
|
|
109
|
+
const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(configs);
|
|
110
|
+
const apexDomainName = (0, exports.getDomainName)(configs);
|
|
111
|
+
if (environment === 'production') {
|
|
112
|
+
return apexDomainName;
|
|
113
|
+
}
|
|
114
|
+
return `${environment}.${apexDomainName}`;
|
|
115
|
+
};
|
|
116
|
+
exports.getEnvironmentDomainName = getEnvironmentDomainName;
|
|
117
|
+
const getBaseDomainName = (qpqConfig) => {
|
|
118
|
+
const environmentDomain = (0, exports.getEnvironmentDomainName)(qpqConfig);
|
|
119
|
+
const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
|
|
120
|
+
if (feature) {
|
|
121
|
+
return `${feature}.${environmentDomain}`;
|
|
122
|
+
}
|
|
123
|
+
return environmentDomain;
|
|
124
|
+
};
|
|
125
|
+
exports.getBaseDomainName = getBaseDomainName;
|
|
126
|
+
const getServiceDomainName = (qpqConfig) => {
|
|
127
|
+
const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
|
|
128
|
+
const domainBase = (0, exports.getBaseDomainName)(qpqConfig);
|
|
129
|
+
return `${service}.${domainBase}`;
|
|
130
|
+
};
|
|
131
|
+
exports.getServiceDomainName = getServiceDomainName;
|
|
132
|
+
const getDefaultRouteSettings = (qpqConfig) => {
|
|
133
|
+
const defaultRouteSettings = quidproquo_core_1.qpqCoreUtils.getConfigSettings(qpqConfig, config_1.QPQWebServerConfigSettingType.DefaultRouteOptions) || [];
|
|
134
|
+
return defaultRouteSettings;
|
|
135
|
+
};
|
|
136
|
+
exports.getDefaultRouteSettings = getDefaultRouteSettings;
|