quidproquo-webserver 0.0.71 → 0.0.73

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.
@@ -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
@@ -1,4 +1,4 @@
1
1
  export * from './actions';
2
2
  export * from './config';
3
3
  export * from './types';
4
- export * as qpqWebServerUtils from './qpqWebServerUtils';
4
+ export * from './qpqWebServerUtils';
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
- exports.qpqWebServerUtils = __importStar(require("./qpqWebServerUtils"));
20
+ __exportStar(require("./qpqWebServerUtils"), exports);
@@ -1,30 +1 @@
1
- import { QPQConfig } from 'quidproquo-core';
2
- import { RouteQPQWebServerConfigSetting } from './config/settings/route';
3
- import { DnsQPQWebServerConfigSetting } from './config/settings/dns';
4
- import { SeoQPQWebServerConfigSetting } from './config/settings/seo';
5
- import { SubdomainRedirectQPQWebServerConfigSetting } from './config/settings/subdomainRedirect';
6
- import { OpenApiQPQWebServerConfigSetting } from './config/settings/openApi';
7
- import { HttpEventHeaders, HTTPEventParams, HTTPEventResponse } from './types/HTTPEvent';
8
- import { RouteOptions } from './config/settings/route';
9
- import { WebEntryQPQWebServerConfigSetting, ApiQPQWebServerConfigSetting } from './config';
10
- export declare const getAllRoutes: (configs: QPQConfig) => RouteQPQWebServerConfigSetting[];
11
- export declare const getAllSeo: (configs: QPQConfig) => SeoQPQWebServerConfigSetting[];
12
- export declare const getAllOpenApiSpecs: (configs: QPQConfig) => OpenApiQPQWebServerConfigSetting[];
13
- export declare const getAllSrcEntries: (configs: QPQConfig) => string[];
14
- export declare const getDomainName: (configs: QPQConfig) => string;
15
- export declare const getWebEntry: (configs: QPQConfig) => string;
16
- export declare const getWebEntryFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
17
- export declare const getWebEntrySeoFullPath: (qpqConfig: QPQConfig, webEntryQPQWebServerConfigSetting: WebEntryQPQWebServerConfigSetting) => string;
18
- export declare const getApiEntryFullPath: (qpqConfig: QPQConfig, apiConfig: ApiQPQWebServerConfigSetting) => string;
19
- export declare const getSubdomainRedirects: (configs: QPQConfig) => SubdomainRedirectQPQWebServerConfigSetting[];
20
- export declare const getApiConfigs: (configs: QPQConfig) => ApiQPQWebServerConfigSetting[];
21
- export declare const getDnsConfigs: (configs: QPQConfig) => DnsQPQWebServerConfigSetting[];
22
- export declare const getWebEntryConfigs: (configs: QPQConfig) => WebEntryQPQWebServerConfigSetting[];
23
- export declare const getEnvironmentDomainName: (configs: QPQConfig) => string;
24
- export declare const getBaseDomainName: (qpqConfig: QPQConfig) => string;
25
- export declare const getServiceDomainName: (qpqConfig: QPQConfig) => string;
26
- export declare const getHeaderValue: (header: string, headers: HttpEventHeaders) => string | null;
27
- export declare const getAllowedOrigins: (configs: QPQConfig, route: RouteOptions) => string[];
28
- export declare const getCorsHeaders: (configs: QPQConfig, route: RouteOptions, reqHeaders: HttpEventHeaders) => HttpEventHeaders;
29
- export declare const fromJsonEventRequest: <T>(httpJsonEvent: HTTPEventParams) => T;
30
- export declare const toJsonEventResponse: (item: any, status?: number) => HTTPEventResponse;
1
+ export * as qpqWebServerUtils from './utils';
@@ -23,155 +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.toJsonEventResponse = exports.fromJsonEventRequest = exports.getCorsHeaders = exports.getAllowedOrigins = exports.getHeaderValue = 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.getAllRoutes = void 0;
27
- const path = __importStar(require("path"));
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 getApiConfigs = (configs) => {
93
- return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.Api);
94
- };
95
- exports.getApiConfigs = getApiConfigs;
96
- const getDnsConfigs = (configs) => {
97
- return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.Dns);
98
- };
99
- exports.getDnsConfigs = getDnsConfigs;
100
- const getWebEntryConfigs = (configs) => {
101
- return quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.WebEntry);
102
- };
103
- exports.getWebEntryConfigs = getWebEntryConfigs;
104
- const getEnvironmentDomainName = (configs) => {
105
- const environment = (0, qpqCoreUtils_1.getApplicationModuleEnvironment)(configs);
106
- const apexDomainName = (0, exports.getDomainName)(configs);
107
- if (environment === 'production') {
108
- return apexDomainName;
109
- }
110
- return `${environment}.${apexDomainName}`;
111
- };
112
- exports.getEnvironmentDomainName = getEnvironmentDomainName;
113
- const getBaseDomainName = (qpqConfig) => {
114
- const environmentDomain = (0, exports.getEnvironmentDomainName)(qpqConfig);
115
- const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
116
- if (feature) {
117
- return `${feature}.${environmentDomain}`;
118
- }
119
- return environmentDomain;
120
- };
121
- exports.getBaseDomainName = getBaseDomainName;
122
- const getServiceDomainName = (qpqConfig) => {
123
- const service = quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
124
- const domainBase = (0, exports.getBaseDomainName)(qpqConfig);
125
- return `${service}.${domainBase}`;
126
- };
127
- exports.getServiceDomainName = getServiceDomainName;
128
- const getHeaderValue = (header, headers) => {
129
- const headerAsLower = header.toLowerCase();
130
- const realHeaderKey = Object.keys(headers).find((k) => k.toLowerCase() === headerAsLower);
131
- if (!realHeaderKey) {
132
- return null;
133
- }
134
- return headers[realHeaderKey] || null;
135
- };
136
- exports.getHeaderValue = getHeaderValue;
137
- const getAllowedOrigins = (configs, route) => {
138
- // Root domain
139
- const rootDomain = `https://${(0, exports.getBaseDomainName)(configs)}`;
140
- // generic settings
141
- const defaultRouteSettings = quidproquo_core_1.qpqCoreUtils.getConfigSettings(configs, QPQConfig_1.QPQWebServerConfigSettingType.DefaultRouteOptions) || [];
142
- const defaultAllowedOrigins = defaultRouteSettings.reduce((acc, cur) => [...acc, ...(cur.routeOptions.allowedOrigins || [])], []);
143
- // Route specific
144
- const routeAllowedOrigins = route.allowedOrigins || [];
145
- return [rootDomain, ...defaultAllowedOrigins, ...routeAllowedOrigins].map((o) => o.toLowerCase());
146
- };
147
- exports.getAllowedOrigins = getAllowedOrigins;
148
- const getCorsHeaders = (configs, route, reqHeaders) => {
149
- const origin = (0, exports.getHeaderValue)('origin', reqHeaders) || '';
150
- const allowedOrigins = (0, exports.getAllowedOrigins)(configs, route);
151
- const allowOrigin = allowedOrigins.find((ao) => ao === origin) || allowedOrigins[0];
152
- return {
153
- 'Access-Control-Allow-Headers': '*',
154
- 'Access-Control-Allow-Methods': '*',
155
- 'Access-Control-Allow-Origin': allowOrigin,
156
- Vary: 'Origin',
157
- };
158
- };
159
- exports.getCorsHeaders = getCorsHeaders;
160
- const fromJsonEventRequest = (httpJsonEvent) => {
161
- const item = JSON.parse(httpJsonEvent.isBase64Encoded
162
- ? Buffer.from(httpJsonEvent.body, 'base64').toString()
163
- : httpJsonEvent.body);
164
- return item;
165
- };
166
- exports.fromJsonEventRequest = fromJsonEventRequest;
167
- const toJsonEventResponse = (item, status = 200) => {
168
- return {
169
- status,
170
- body: JSON.stringify(item),
171
- isBase64Encoded: false,
172
- headers: {
173
- 'content-type': 'application/json',
174
- },
175
- };
176
- };
177
- exports.toJsonEventResponse = toJsonEventResponse;
26
+ exports.qpqWebServerUtils = void 0;
27
+ exports.qpqWebServerUtils = __importStar(require("./utils"));
@@ -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 HTTPEventParams<T = string> {
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[];
@@ -1,5 +1,8 @@
1
1
  import { QueueMessage } from 'quidproquo-core';
2
- export interface QueueEventParams<T extends QueueMessage<any>> {
2
+ export interface QueueEventTypeParams {
3
+ [key: string]: string;
4
+ }
5
+ export interface QueueEvent<T extends QueueMessage<any>> {
3
6
  message: T;
4
7
  }
5
8
  export type QueueEventResponse = boolean;
@@ -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 SeoEventParams<T = null> {
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[];
@@ -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,3 @@
1
+ import { HTTPEvent, HTTPEventResponse } from '../types/HTTPEvent';
2
+ export declare const fromJsonEventRequest: <T>(httpJsonEvent: HTTPEvent) => T;
3
+ export declare const toJsonEventResponse: (item: any, status?: number) => HTTPEventResponse;
@@ -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,4 @@
1
+ export * from './headerUtils';
2
+ export * from './httpEventUtils';
3
+ export * from './mergeRouteUtils';
4
+ export * from './qpqConfigAccessorsUtils';
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-webserver",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",