@redhat-cloud-services/frontend-components-config-utilities 2.1.0 → 3.0.0-beta.0

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.
Files changed (80) hide show
  1. package/babel-transform-imports.d.ts +14 -0
  2. package/babel-transform-imports.js +164 -0
  3. package/babel-transform-imports.js.map +1 -0
  4. package/cookieTransform.d.ts +16 -0
  5. package/cookieTransform.js +41 -52
  6. package/cookieTransform.js.map +1 -0
  7. package/extension-mapper.d.ts +14 -0
  8. package/extension-mapper.js +56 -75
  9. package/extension-mapper.js.map +1 -0
  10. package/extensions-plugin.d.ts +1 -0
  11. package/extensions-plugin.js +44 -51
  12. package/extensions-plugin.js.map +1 -0
  13. package/federated-modules.d.ts +20 -0
  14. package/federated-modules.js +111 -112
  15. package/federated-modules.js.map +1 -0
  16. package/generate-pf-shared-assets-list.d.ts +2 -0
  17. package/generate-pf-shared-assets-list.js +101 -0
  18. package/generate-pf-shared-assets-list.js.map +1 -0
  19. package/index.d.ts +15 -0
  20. package/index.js +43 -1
  21. package/index.js.map +1 -0
  22. package/jsVarName.d.ts +2 -0
  23. package/jsVarName.js +8 -10
  24. package/jsVarName.js.map +1 -0
  25. package/package.json +14 -2
  26. package/proxy.d.ts +38 -0
  27. package/proxy.js +322 -359
  28. package/proxy.js.map +1 -0
  29. package/search-ignored-styles.d.ts +2 -0
  30. package/search-ignored-styles.js +71 -33
  31. package/search-ignored-styles.js.map +1 -0
  32. package/serve-federated.d.ts +2 -0
  33. package/serve-federated.js +35 -33
  34. package/serve-federated.js.map +1 -0
  35. package/serveLocalFile.d.ts +11 -0
  36. package/serveLocalFile.js +19 -16
  37. package/serveLocalFile.js.map +1 -0
  38. package/standalone/helpers/checkout.d.ts +5 -0
  39. package/standalone/helpers/checkout.js +67 -46
  40. package/standalone/helpers/checkout.js.map +1 -0
  41. package/standalone/helpers/index.d.ts +8 -0
  42. package/standalone/helpers/index.js +47 -62
  43. package/standalone/helpers/index.js.map +1 -0
  44. package/standalone/helpers/router.d.ts +3 -0
  45. package/standalone/helpers/router.js +17 -10
  46. package/standalone/helpers/router.js.map +1 -0
  47. package/standalone/index.d.ts +1 -0
  48. package/standalone/index.js +18 -1
  49. package/standalone/index.js.map +1 -0
  50. package/standalone/services/backofficeProxy.d.ts +7 -0
  51. package/standalone/services/backofficeProxy.js +54 -51
  52. package/standalone/services/backofficeProxy.js.map +1 -0
  53. package/standalone/services/default/chrome.d.ts +24 -0
  54. package/standalone/services/default/chrome.js +98 -81
  55. package/standalone/services/default/chrome.js.map +1 -0
  56. package/standalone/services/default/config.d.ts +13 -0
  57. package/standalone/services/default/config.js +13 -6
  58. package/standalone/services/default/config.js.map +1 -0
  59. package/standalone/services/default/entitlements.d.ts +19 -0
  60. package/standalone/services/default/entitlements.js +37 -34
  61. package/standalone/services/default/entitlements.js.map +1 -0
  62. package/standalone/services/default/index.d.ts +56 -0
  63. package/standalone/services/default/index.js +15 -11
  64. package/standalone/services/default/index.js.map +1 -0
  65. package/standalone/services/default/keycloak/realm_export.json +4805 -4805
  66. package/standalone/services/default/landing.d.ts +14 -0
  67. package/standalone/services/default/landing.js +19 -14
  68. package/standalone/services/default/landing.js.map +1 -0
  69. package/standalone/services/index.d.ts +91 -0
  70. package/standalone/services/index.js +13 -9
  71. package/standalone/services/index.js.map +1 -0
  72. package/standalone/services/rbac.d.ts +29 -0
  73. package/standalone/services/rbac.js +53 -61
  74. package/standalone/services/rbac.js.map +1 -0
  75. package/standalone/startService.d.ts +13 -0
  76. package/standalone/startService.js +82 -33
  77. package/standalone/startService.js.map +1 -0
  78. package/chrome-render-loader.js +0 -8
  79. package/chrome-render-loader.test.js +0 -44
  80. package/standalone/services/default/keycloak/export_keycloak.sh +0 -8
package/proxy.js CHANGED
@@ -1,371 +1,334 @@
1
- /* eslint-disable no-console */
2
- // Webpack proxy and express config for `useProxy: true` or `standalone: true`
3
- const { execSync } = require('child_process');
4
- const fetch = require('node-fetch');
5
- var express = require('express');
6
- const path = require('path');
7
- const HttpsProxyAgent = require('https-proxy-agent');
8
- const cookieTransform = require('./cookieTransform');
9
- const router = require('./standalone/helpers/router');
10
- const { getConfig, isGitUrl, getExposedPort, resolvePath } = require('./standalone/helpers/index');
11
- const { checkoutRepo } = require('./standalone/helpers/checkout');
12
- const { startService, stopService } = require('./standalone/startService');
13
- const { NET } = require('./standalone/helpers');
14
- const defaultServices = require('./standalone/services/default');
15
- const { registerChrome } = require('./standalone/services/default/chrome');
16
-
17
- const defaultReposDir = path.join(__dirname, 'repos');
18
-
19
- const checkLocalAppHost = (appName, hostUrl, port) => {
20
- const check = execSync(`curl --max-time 5 --silent --head ${hostUrl} | awk '/^HTTP/{print $2}'`).toString().trim();
21
-
22
- if (check !== '200') {
23
- console.error('\n' + appName[0].toUpperCase() + appName.substring(1) + ' is not running or available via ' + hostUrl);
24
- console.log(
25
- '\nMake sure to run `npm run start -- --port=' +
26
- port +
27
- '` in the ' +
28
- appName +
29
- " application directory to start it's webpack dev server and the bundle is built.\n"
30
- );
31
-
32
- return false;
33
- } else {
34
- return true;
35
- }
36
- };
37
-
38
- const buildRoutes = (routes, target) =>
39
- Object.entries(routes || {}).map(([route, redirect]) => {
40
- const currTarget = redirect.host || redirect;
41
- delete redirect.host;
42
- return {
43
- context: (path) => path.includes(route),
44
- target: currTarget === 'PORTAL_BACKEND_MARKER' ? target : currTarget,
45
- secure: false,
46
- changeOrigin: true,
47
- autoRewrite: true,
48
- ws: true,
49
- onProxyReq: cookieTransform,
50
- ...(currTarget === 'PORTAL_BACKEND_MARKER' && { router }),
51
- ...(typeof redirect === 'object' ? redirect : {}),
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
52
10
  };
53
- });
54
-
55
- const buildLocalAppRoutes = (localApps, defaultLocalAppHost, target) =>
56
- buildRoutes(
57
- (!Array.isArray(localApps) ? localApps.split(',') : localApps).reduce((acc, curr) => {
58
- const [appName, appConfig] = (curr || '').split(':');
59
- const [appPort = 8003, protocol = 'http'] = appConfig.split('~');
60
- const appUrl = `${protocol}://${defaultLocalAppHost}:${appPort}`;
61
-
62
- if (checkLocalAppHost(appName, appUrl, appPort)) {
63
- console.log('Creating app proxy routes for: ' + appName + ' to ' + appUrl);
64
-
65
- return {
66
- ...acc,
67
- [`/apps/${appName}`]: {
68
- host: appUrl,
69
- },
70
- [`/preview/apps/${appName}`]: {
71
- host: appUrl,
72
- },
73
- };
74
- } else {
75
- process.exit();
76
- }
77
- }, {}),
78
- target
79
- );
80
-
81
- module.exports = ({
82
- env = 'ci-beta',
83
- customProxy = [],
84
- routes,
85
- routesPath,
86
- useProxy,
87
- proxyURL = 'http://squid.corp.redhat.com:3128',
88
- standalone,
89
- port,
90
- reposDir = defaultReposDir,
91
- localChrome,
92
- appUrl = [],
93
- publicPath,
94
- proxyVerbose,
95
- useCloud = false,
96
- target = '',
97
- keycloakUri = '',
98
- registry = [],
99
- isChrome = false,
100
- onBeforeSetupMiddleware = () => {},
101
- bounceProd = false,
102
- useAgent = true,
103
- useDevBuild = true,
104
- localApps = process.env.LOCAL_APPS,
105
- }) => {
106
- const proxy = [];
107
- const majorEnv = env.split('-')[0];
108
- const defaultLocalAppHost = process.env.LOCAL_APP_HOST || majorEnv + '.foo.redhat.com';
109
-
110
- if (target === '') {
111
- target += 'https://';
112
- if (!['prod', 'stage'].includes(majorEnv)) {
113
- target += majorEnv + '.';
114
- }
115
-
116
- target += useCloud ? 'cloud' : 'console';
117
- if (majorEnv === 'stage') {
118
- target += '.stage';
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
119
47
  }
120
-
121
- target += '.redhat.com/';
122
- }
123
-
124
- let agent;
125
-
126
- const isProd = env.startsWith('prod');
127
- const isStage = env.startsWith('stage');
128
-
129
- const shouldBounceProdRequests = isProd && bounceProd && !useAgent;
130
-
131
- if (isStage || (isProd && useAgent)) {
132
- // stage is deployed with Akamai which requires a corporate proxy
133
- agent = new HttpsProxyAgent(proxyURL);
134
- }
135
-
136
- if (isStage) {
137
- // stage-stable / stage-beta branches don't exist in build repos
138
- // Currently stage pulls from QA
139
- env = env.replace('stage', 'qa');
140
- }
141
-
142
- if (!Array.isArray(appUrl)) {
143
- appUrl = [appUrl];
144
- }
145
-
146
- appUrl.push(publicPath);
147
-
148
- if (routesPath) {
149
- routes = require(routesPath);
150
- }
151
-
152
- if (routes) {
153
- routes = routes.routes || routes;
154
- proxy.push(...buildRoutes(routes, target));
155
- }
156
-
157
- if (localApps?.length > 0) {
158
- proxy.push(...buildLocalAppRoutes(localApps, defaultLocalAppHost, target));
159
- }
160
-
161
- if (customProxy) {
162
- proxy.push(...customProxy);
163
- }
164
-
165
- let standaloneConfig;
166
- if (standalone) {
167
- standaloneConfig = getConfig(standalone, localChrome, env, port);
168
- // Create network for services.
169
- execSync(`docker network inspect ${NET} >/dev/null 2>&1 || docker network create ${NET}`);
170
-
171
- // Clone repos and resolve functions
172
- // If we manage the repos it's okay to overwrite the contents
173
- const overwrite = reposDir === defaultReposDir;
174
-
175
- // Resolve config functions for cross-service references
176
- for (const [, proj] of Object.entries(standaloneConfig)) {
177
- const { services, path, assets, register } = proj;
178
- if (typeof register === 'function') {
179
- registry.push(register);
180
- }
181
-
182
- if (isGitUrl(path)) {
183
- // Add typical branch if not included
184
- if (!path.includes('#')) {
185
- proj.path = `${path}#${env}`;
186
- }
187
-
188
- proj.path = checkoutRepo({ repo: proj.path, reposDir, overwrite });
189
- }
190
-
191
- Object.keys(assets || []).forEach((key) => {
192
- if (isGitUrl(assets[key])) {
193
- assets[key] = checkoutRepo({ repo: assets[key], reposDir, overwrite });
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
194
57
  }
195
- });
196
-
197
- // Resolve functions that depend on env, port, or assets
198
- if (typeof services === 'function') {
199
- proj.services = services({ env, port, assets });
200
- }
58
+ return t;
59
+ };
60
+ var __importDefault = (this && this.__importDefault) || function (mod) {
61
+ return (mod && mod.__esModule) ? mod : { "default": mod };
62
+ };
63
+ Object.defineProperty(exports, "__esModule", { value: true });
64
+ var child_process_1 = require("child_process");
65
+ var node_fetch_1 = __importDefault(require("node-fetch"));
66
+ var express_1 = __importDefault(require("express"));
67
+ var path_1 = __importDefault(require("path"));
68
+ var https_proxy_agent_1 = require("https-proxy-agent");
69
+ var cookieTransform_1 = __importDefault(require("./cookieTransform"));
70
+ var router_1 = __importDefault(require("./standalone/helpers/router"));
71
+ var index_1 = require("./standalone/helpers/index");
72
+ var checkout_1 = require("./standalone/helpers/checkout");
73
+ var startService_1 = require("./standalone/startService");
74
+ var helpers_1 = require("./standalone/helpers");
75
+ var default_1 = __importDefault(require("./standalone/services/default"));
76
+ var chrome_1 = require("./standalone/services/default/chrome");
77
+ var defaultReposDir = path_1.default.join(__dirname, 'repos');
78
+ var checkLocalAppHost = function (appName, hostUrl, port) {
79
+ var check = (0, child_process_1.execSync)("curl --max-time 5 --silent --head ".concat(hostUrl, " | awk '/^HTTP/{print $2}'")).toString().trim();
80
+ if (check !== '200') {
81
+ console.error('\n' + appName[0].toUpperCase() + appName.substring(1) + ' is not running or available via ' + hostUrl);
82
+ console.log('\nMake sure to run `npm run start -- --port=' +
83
+ port +
84
+ '` in the ' +
85
+ appName +
86
+ " application directory to start it's webpack dev server and the bundle is built.\n");
87
+ return false;
201
88
  }
202
-
203
- // Start standalone services.
204
- for (const [projName, proj] of Object.entries(standaloneConfig)) {
205
- const { services, path, assets, onProxyReq, keycloakUri, register, target, ...rest } = proj;
206
- const serviceNames = [];
207
- for (let [subServiceName, subService] of Object.entries(proj.services || {})) {
208
- const name = [projName, subServiceName].join('_');
209
- startService(standaloneConfig, name, subService);
210
- serviceNames.push(name);
211
- const port = getExposedPort(subService.args);
212
- console.log('Container', name, 'listening', port ? 'on' : '', port || '');
213
- }
214
-
215
- process.on('SIGINT', () => serviceNames.forEach(stopService));
216
-
217
- if (target) {
218
- proxy.push({
219
- secure: false,
220
- changeOrigin: true,
221
- onProxyReq: cookieTransform,
222
- target,
223
- ...rest,
224
- });
225
- }
89
+ else {
90
+ return true;
226
91
  }
227
-
228
- process.on('SIGINT', () => process.exit());
229
- }
230
-
231
- if (useProxy) {
232
- // Catch-all
233
- proxy.push({
234
- secure: false,
235
- changeOrigin: true,
236
- autoRewrite: true,
237
- context: (url) => {
238
- const shouldProxy = !appUrl.find((u) => (typeof u === 'string' ? url.startsWith(u) : u.test(url)));
239
- if (shouldProxy) {
240
- if (proxyVerbose) {
241
- console.log('proxy', url);
242
- }
243
-
244
- return true;
92
+ };
93
+ var buildRoutes = function (routes, target) {
94
+ return Object.entries(routes || {}).map(function (_a) {
95
+ var route = _a[0], redirect = _a[1];
96
+ var currTarget = typeof redirect === 'object' ? redirect.host : redirect;
97
+ if (typeof redirect === 'object') {
98
+ delete redirect.host;
245
99
  }
246
-
247
- return false;
248
- },
249
- target,
250
- bypass: async (req, res) => {
251
- /**
252
- * Bypass any HTML requests if using chrome
253
- * Serves as a historyApiFallback when refreshing on any other URL than '/'
254
- */
255
- if (isChrome && !req.url.match(/\/api\//) && !req.url.match(/\./) && req.headers.accept.includes('text/html')) {
256
- return '/';
100
+ var result = __assign(__assign({ context: function (path) { return path.includes(route); }, target: currTarget === 'PORTAL_BACKEND_MARKER' ? target : currTarget || undefined, secure: false, changeOrigin: true, autoRewrite: true, ws: true, onProxyReq: cookieTransform_1.default }, (currTarget === 'PORTAL_BACKEND_MARKER' && { router: (0, router_1.default)(target, false) })), (typeof redirect === 'object' ? redirect : {}));
101
+ return result;
102
+ });
103
+ };
104
+ var buildLocalAppRoutes = function (localApps, defaultLocalAppHost, target) {
105
+ return buildRoutes((!Array.isArray(localApps) ? localApps.split(',') : localApps).reduce(function (acc, curr) {
106
+ var _a;
107
+ var _b = (curr || '').split(':'), appName = _b[0], appConfig = _b[1];
108
+ var _c = appConfig.split('~'), _d = _c[0], appPort = _d === void 0 ? 8003 : _d, _e = _c[1], protocol = _e === void 0 ? 'http' : _e;
109
+ var appUrl = "".concat(protocol, "://").concat(defaultLocalAppHost, ":").concat(appPort);
110
+ if (checkLocalAppHost(appName, appUrl, appPort)) {
111
+ console.log('Creating app proxy routes for: ' + appName + ' to ' + appUrl);
112
+ return __assign(__assign({}, acc), (_a = {}, _a["/apps/".concat(appName)] = {
113
+ host: appUrl,
114
+ }, _a["/preview/apps/".concat(appName)] = {
115
+ host: appUrl,
116
+ }, _a));
257
117
  }
258
-
259
- /**
260
- * Use node-fetch to proxy all non-GET requests (this avoids all origin/host akamai policy)
261
- * This enables using PROD proxy without VPN and agent
262
- */
263
- if (shouldBounceProdRequests && req.method !== 'GET') {
264
- const result = await fetch((target + req.url).replace(/\/\//g, '/'), {
265
- method: req.method,
266
- body: JSON.stringify(req.body),
267
- headers: { cookie: req.headers.cookie, 'Content-Type': 'application/json' },
268
- });
269
-
270
- const text = await result.text();
271
- try {
272
- const data = JSON.parse(text);
273
- res.status(result.status).json(data);
274
- } catch (err) {
275
- res.status(result.status).send(text);
276
- }
118
+ else {
119
+ process.exit();
277
120
  }
278
-
279
- return null;
280
- },
281
- router: router(target, useCloud),
282
- ...(agent && {
283
- agent,
284
- headers: {
285
- // Staging Akamai CORS gives 403s for non-GET requests from non-origin hosts
286
- Host: target.replace('https://', ''),
287
- Origin: target,
288
- },
289
- }),
290
- });
291
- }
292
-
293
- return {
294
- ...(proxy.length > 0 && { proxy }),
295
- onListening(server) {
296
- if (useProxy || standaloneConfig) {
297
- const host = useProxy ? `${majorEnv}.foo.redhat.com` : 'localhost';
298
- const origin = `http${server.options.https ? 's' : ''}://${host}:${server.options.port}`;
299
- console.log('App should run on:');
300
-
301
- console.log('\u001b[34m'); // Use same webpack-dev-server blue
302
- if (appUrl.length > 0) {
303
- appUrl.slice(0, appUrl.length - 1).forEach((url) => console.log(` - ${origin}${url}`));
304
-
305
- console.log('\x1b[0m');
306
- console.log('Static assets are available at:');
307
- console.log('\u001b[34m'); // Use same webpack-dev-server blue
308
- console.log(` - ${origin}${appUrl[appUrl.length - 1]}`);
309
- } else {
310
- console.log(` - ${origin}`);
121
+ }, {}), target);
122
+ };
123
+ var proxy = function (_a) {
124
+ var _b = _a.env, env = _b === void 0 ? 'ci-beta' : _b, _c = _a.customProxy, customProxy = _c === void 0 ? [] : _c, routes = _a.routes, routesPath = _a.routesPath, useProxy = _a.useProxy, _d = _a.proxyURL, proxyURL = _d === void 0 ? 'http://squid.corp.redhat.com:3128' : _d, standalone = _a.standalone, port = _a.port, _e = _a.reposDir, reposDir = _e === void 0 ? defaultReposDir : _e, localChrome = _a.localChrome, _f = _a.appUrl, appUrl = _f === void 0 ? [] : _f, publicPath = _a.publicPath, proxyVerbose = _a.proxyVerbose, _g = _a.useCloud, useCloud = _g === void 0 ? false : _g, _h = _a.target, target = _h === void 0 ? '' : _h, _j = _a.keycloakUri, keycloakUri = _j === void 0 ? '' : _j, _k = _a.registry, registry = _k === void 0 ? [] : _k, _l = _a.isChrome, isChrome = _l === void 0 ? false : _l, _m = _a.onBeforeSetupMiddleware, onBeforeSetupMiddleware = _m === void 0 ? function () { return undefined; } : _m, _o = _a.bounceProd, bounceProd = _o === void 0 ? false : _o, _p = _a.useAgent, useAgent = _p === void 0 ? true : _p, _q = _a.useDevBuild, useDevBuild = _q === void 0 ? true : _q, _r = _a.localApps, localApps = _r === void 0 ? process.env.LOCAL_APPS : _r;
125
+ var proxy = [];
126
+ var majorEnv = env.split('-')[0];
127
+ var defaultLocalAppHost = process.env.LOCAL_APP_HOST || majorEnv + '.foo.redhat.com';
128
+ if (target === '') {
129
+ target += 'https://';
130
+ if (!['prod', 'stage'].includes(majorEnv)) {
131
+ target += majorEnv + '.';
311
132
  }
312
-
313
- console.log('\u001b[0m');
314
- }
315
- },
316
- onBeforeSetupMiddleware({ app, compiler, options }) {
317
- app.enable('strict routing'); // trailing slashes are mean
318
-
319
- if (shouldBounceProdRequests) {
320
- app.use(express.json());
321
- app.use(express.urlencoded({ extended: true }));
322
- }
323
-
324
- /**
325
- * Allow serving chrome assets
326
- * This will allow running chrome as a host application
327
- */
328
- if (!isChrome) {
329
- let chromePath = localChrome;
330
- if (standaloneConfig) {
331
- if (standaloneConfig.chrome) {
332
- chromePath = resolvePath(reposDir, standaloneConfig.chrome.path);
333
- keycloakUri = standaloneConfig.chrome.keycloakUri;
334
- }
335
- } else if (!localChrome && useProxy) {
336
- if (typeof defaultServices.chrome === 'function') {
337
- defaultServices.chrome = defaultServices.chrome({});
338
- }
339
-
340
- const chromeEnv = useDevBuild ? (env.includes('-beta') ? 'dev-beta' : 'dev-stable') : env;
341
- chromePath = checkoutRepo({
342
- repo: `${defaultServices.chrome.path}#${chromeEnv}`,
343
- reposDir,
344
- overwrite: true,
345
- });
133
+ target += useCloud ? 'cloud' : 'console';
134
+ if (majorEnv === 'stage') {
135
+ target += '.stage';
346
136
  }
347
-
348
- onBeforeSetupMiddleware({ chromePath });
349
-
350
- if (chromePath) {
351
- registerChrome({
352
- app,
353
- chromePath,
354
- keycloakUri,
355
- https: Boolean(options.https),
356
- proxyVerbose,
357
- });
137
+ target += '.redhat.com/';
138
+ }
139
+ var agent;
140
+ var isProd = env.startsWith('prod');
141
+ var isStage = env.startsWith('stage');
142
+ var shouldBounceProdRequests = isProd && bounceProd && !useAgent;
143
+ if (isStage || (isProd && useAgent)) {
144
+ agent = new https_proxy_agent_1.HttpsProxyAgent(proxyURL);
145
+ }
146
+ if (isStage) {
147
+ env = env.replace('stage', 'qa');
148
+ }
149
+ if (!Array.isArray(appUrl)) {
150
+ appUrl = [appUrl];
151
+ }
152
+ appUrl.push(publicPath);
153
+ if (routesPath) {
154
+ routes = require(routesPath);
155
+ }
156
+ if (routes) {
157
+ routes = routes.routes || routes;
158
+ proxy.push.apply(proxy, buildRoutes(routes, target));
159
+ }
160
+ if (localApps && localApps.length > 0) {
161
+ proxy.push.apply(proxy, buildLocalAppRoutes(localApps, defaultLocalAppHost, target));
162
+ }
163
+ if (customProxy) {
164
+ proxy.push.apply(proxy, customProxy);
165
+ }
166
+ var standaloneConfig;
167
+ if (standalone) {
168
+ standaloneConfig = (0, index_1.getConfig)(standalone, localChrome, env, port);
169
+ (0, child_process_1.execSync)("docker network inspect ".concat(helpers_1.NET, " >/dev/null 2>&1 || docker network create ").concat(helpers_1.NET));
170
+ var overwrite_1 = reposDir === defaultReposDir;
171
+ var _loop_1 = function (proj) {
172
+ var services = proj.services, path_2 = proj.path, assets = proj.assets, register = proj.register;
173
+ if (typeof register === 'function') {
174
+ registry.push(register);
175
+ }
176
+ if ((0, index_1.isGitUrl)(path_2)) {
177
+ if (!path_2.includes('#')) {
178
+ proj.path = "".concat(path_2, "#").concat(env);
179
+ }
180
+ proj.path = (0, checkout_1.checkoutRepo)({ repo: proj.path, reposDir: reposDir, overwrite: overwrite_1 });
181
+ }
182
+ Object.keys(assets || []).forEach(function (key) {
183
+ if ((0, index_1.isGitUrl)(assets[key])) {
184
+ assets[key] = (0, checkout_1.checkoutRepo)({ repo: assets[key], reposDir: reposDir, overwrite: overwrite_1 });
185
+ }
186
+ });
187
+ if (typeof services === 'function') {
188
+ proj.services = services({ env: env, port: port, assets: assets });
189
+ }
190
+ };
191
+ for (var _i = 0, _s = Object.entries(standaloneConfig); _i < _s.length; _i++) {
192
+ var _t = _s[_i], proj = _t[1];
193
+ _loop_1(proj);
358
194
  }
359
- }
360
-
361
- registry.forEach((cb) =>
362
- cb({
363
- app,
364
- options,
365
- compiler,
366
- config: standaloneConfig,
367
- })
368
- );
369
- },
370
- };
195
+ var _loop_2 = function (projName, proj) {
196
+ var services = proj.services, path_3 = proj.path, assets = proj.assets, onProxyReq = proj.onProxyReq, keycloakUri_1 = proj.keycloakUri, register = proj.register, target_1 = proj.target, rest = __rest(proj, ["services", "path", "assets", "onProxyReq", "keycloakUri", "register", "target"]);
197
+ var serviceNames = [];
198
+ for (var _x = 0, _y = Object.entries(proj.services || {}); _x < _y.length; _x++) {
199
+ var _z = _y[_x], subServiceName = _z[0], subService = _z[1];
200
+ var name_1 = [projName, subServiceName].join('_');
201
+ (0, startService_1.startService)(standaloneConfig, name_1, subService);
202
+ serviceNames.push(name_1);
203
+ var port_1 = (0, index_1.getExposedPort)(subService.args);
204
+ console.log('Container', name_1, 'listening', port_1 ? 'on' : '', port_1 || '');
205
+ }
206
+ process.on('SIGINT', function () { return serviceNames.forEach(startService_1.stopService); });
207
+ if (target_1) {
208
+ proxy.push(__assign({ secure: false, changeOrigin: true, onProxyReq: cookieTransform_1.default, target: target_1 }, rest));
209
+ }
210
+ };
211
+ for (var _u = 0, _v = Object.entries(standaloneConfig); _u < _v.length; _u++) {
212
+ var _w = _v[_u], projName = _w[0], proj = _w[1];
213
+ _loop_2(projName, proj);
214
+ }
215
+ process.on('SIGINT', function () { return process.exit(); });
216
+ }
217
+ if (useProxy) {
218
+ proxy.push(__assign({ secure: false, changeOrigin: true, autoRewrite: true, context: function (url) {
219
+ var shouldProxy = !appUrl.find(function (u) { return (typeof u === 'string' ? url.startsWith(u) : u.test(url)); });
220
+ if (shouldProxy) {
221
+ if (proxyVerbose) {
222
+ console.log('proxy', url);
223
+ }
224
+ return true;
225
+ }
226
+ return false;
227
+ }, target: target, bypass: function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
228
+ var result, text, data;
229
+ var _a;
230
+ return __generator(this, function (_b) {
231
+ switch (_b.label) {
232
+ case 0:
233
+ if (isChrome && !req.url.match(/\/api\//) && !req.url.match(/\./) && ((_a = req.headers.accept) === null || _a === void 0 ? void 0 : _a.includes('text/html'))) {
234
+ return [2, '/'];
235
+ }
236
+ if (!(shouldBounceProdRequests && req.method !== 'GET')) return [3, 3];
237
+ return [4, (0, node_fetch_1.default)((target + req.url).replace(/\/\//g, '/'), {
238
+ method: req.method,
239
+ body: JSON.stringify(req.body),
240
+ headers: __assign(__assign({}, (req.headers.cookie && {
241
+ cookie: req.headers.cookie,
242
+ })), { 'Content-Type': 'application/json' }),
243
+ })];
244
+ case 1:
245
+ result = _b.sent();
246
+ return [4, result.text()];
247
+ case 2:
248
+ text = _b.sent();
249
+ try {
250
+ data = JSON.parse(text);
251
+ res.status(result.status).json(data);
252
+ }
253
+ catch (err) {
254
+ res.status(result.status).send(text);
255
+ }
256
+ _b.label = 3;
257
+ case 3: return [2, null];
258
+ }
259
+ });
260
+ }); }, router: (0, router_1.default)(target, useCloud) }, (agent && {
261
+ agent: agent,
262
+ headers: {
263
+ Host: target.replace('https://', ''),
264
+ Origin: target,
265
+ },
266
+ })));
267
+ }
268
+ var config = __assign(__assign({}, (proxy.length > 0 && { proxy: proxy })), { onListening: function (server) {
269
+ if (useProxy || standaloneConfig) {
270
+ var host = useProxy ? "".concat(majorEnv, ".foo.redhat.com") : 'localhost';
271
+ var origin_1 = "http".concat(server.options.https ? 's' : '', "://").concat(host, ":").concat(server.options.port);
272
+ console.log('App should run on:');
273
+ console.log('\u001b[34m');
274
+ if (appUrl.length > 0) {
275
+ appUrl.slice(0, appUrl.length - 1).forEach(function (url) { return console.log(" - ".concat(origin_1).concat(url)); });
276
+ console.log('\x1b[0m');
277
+ console.log('Static assets are available at:');
278
+ console.log('\u001b[34m');
279
+ console.log(" - ".concat(origin_1).concat(appUrl[appUrl.length - 1]));
280
+ }
281
+ else {
282
+ console.log(" - ".concat(origin_1));
283
+ }
284
+ console.log('\u001b[0m');
285
+ }
286
+ }, onBeforeSetupMiddleware: function (_a) {
287
+ var app = _a.app, compiler = _a.compiler, options = _a.options;
288
+ app === null || app === void 0 ? void 0 : app.enable('strict routing');
289
+ if (shouldBounceProdRequests) {
290
+ app === null || app === void 0 ? void 0 : app.use(express_1.default.json());
291
+ app === null || app === void 0 ? void 0 : app.use(express_1.default.urlencoded({ extended: true }));
292
+ }
293
+ if (!isChrome) {
294
+ var chromePath = localChrome;
295
+ if (standaloneConfig) {
296
+ if (standaloneConfig.chrome) {
297
+ chromePath = (0, index_1.resolvePath)(reposDir, standaloneConfig.chrome.path);
298
+ keycloakUri = standaloneConfig.chrome.keycloakUri;
299
+ }
300
+ }
301
+ else if (!localChrome && useProxy) {
302
+ var chromeConfig = typeof default_1.default.chrome === 'function' ? default_1.default.chrome({}) : default_1.default.chrome;
303
+ var chromeEnv = useDevBuild ? (env.includes('-beta') ? 'dev-beta' : 'dev-stable') : env;
304
+ chromePath = (0, checkout_1.checkoutRepo)({
305
+ repo: "".concat(chromeConfig.path, "#").concat(chromeEnv),
306
+ reposDir: reposDir,
307
+ overwrite: true,
308
+ });
309
+ }
310
+ onBeforeSetupMiddleware({ chromePath: chromePath });
311
+ if (app && chromePath) {
312
+ (0, chrome_1.registerChrome)({
313
+ app: app,
314
+ chromePath: chromePath,
315
+ keycloakUri: keycloakUri,
316
+ https: Boolean(options.https),
317
+ proxyVerbose: proxyVerbose,
318
+ });
319
+ }
320
+ }
321
+ registry.forEach(function (cb) {
322
+ return cb({
323
+ app: app,
324
+ options: options,
325
+ compiler: compiler,
326
+ config: standaloneConfig,
327
+ });
328
+ });
329
+ } });
330
+ return config;
371
331
  };
332
+ exports.default = proxy;
333
+ module.exports = proxy;
334
+ //# sourceMappingURL=proxy.js.map