@redhat-cloud-services/frontend-components-config-utilities 1.5.17 → 1.5.20

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/README.md CHANGED
@@ -2,13 +2,17 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/%40redhat-cloud-services%2Ffrontend-components-config-utilities.svg)](https://badge.fury.io/js/%40redhat-cloud-services%2Ffrontend-components-config-utilities)
4
4
 
5
- - [RedHat Cloud Services frontend components - webpack config](#redhat-cloud-services-frontend-components---webpack-config-utilities)
6
- - [Chrome render loader](#chrome-render-loaded)
5
+ - [RedHat Cloud Services frontend components - webpack config utilities](#redhat-cloud-services-frontend-components---webpack-config-utilities)
6
+ - [Chrome render loader](#chrome-render-loader)
7
7
  - [Disable chrome 2](#disable-chrome-2)
8
8
  - [Chunk mapper](#chunk-mapper)
9
9
  - [Federated modules](#federated-modules)
10
- - [Override container ports](#Override container ports)
11
- - [List of shared deps](#list-of-shared-deps)
10
+ - [Override container ports](#override-container-ports)
11
+ - [List of shared deps](#list-of-shared-deps)
12
+ - [Extensions plugin](#extensions-plugin)
13
+ - [Arguments](#arguments)
14
+ - [`pluginConfig`](#pluginconfig)
15
+ - [extension object](#extension-object)
12
16
 
13
17
  ## Chrome render loader
14
18
 
@@ -95,6 +99,7 @@ We've aimed for easy plug and play, but feel free to override any fed mods parti
95
99
  * `moduleName` - used to generate the file under this name (generally your `insights.appname` - if you have dashes in your name replace them with cammel case)
96
100
  * `useFileHash` - in order to prevent caching we are using file hashes, you might want to turn this off in your dev env
97
101
  * `exclude` - if you want to exclude any shared module you can do it trough here (even for general dependencies added by us)
102
+ * `eager` - if set to `true`, turns eager fetch for shared modules on
98
103
 
99
104
  ### Override container ports
100
105
  The default ports for the RBAC server(**4012**) and/or the Keycloak server(**4001**) can be overridden using a corresponding variable in the environment.
@@ -3,24 +3,26 @@ const { resolve } = require('path');
3
3
  const { ModuleFederationPlugin } = require('webpack').container;
4
4
  const jsVarName = require('./jsVarName');
5
5
 
6
- const include = {
7
- '@patternfly/react-core': { eager: true },
8
- '@patternfly/react-table': { eager: true },
6
+ const createIncludes = (eager = false) => ({
7
+ '@patternfly/react-core': { eager },
8
+ '@patternfly/react-table': { eager },
9
9
  '@patternfly/react-tokens': {},
10
10
  '@patternfly/react-icons': {},
11
- '@patternfly/quickstarts': { singleton: true, eager: true },
11
+ '@patternfly/quickstarts': { singleton: true, eager },
12
12
  '@redhat-cloud-services/frontend-components': {},
13
13
  '@redhat-cloud-services/frontend-components-utilities': {},
14
14
  '@redhat-cloud-services/frontend-components-notifications': {},
15
15
  axios: {},
16
16
  lodash: {},
17
17
  'redux-promise-middleware': {},
18
- react: { singleton: true, eager: true },
19
- 'react-dom': { singleton: true, eager: true },
20
- 'react-router-dom': { eager: true },
21
- };
18
+ react: { singleton: true, eager },
19
+ 'react-dom': { singleton: true, eager },
20
+ 'react-router-dom': { eager },
21
+ });
22
+
23
+ module.exports = ({ root, exposes, shared = [], debug, moduleName, useFileHash = true, libType = 'var', libName, exclude = [], eager = false }) => {
24
+ const include = createIncludes(eager);
22
25
 
23
- module.exports = ({ root, exposes, shared = [], debug, moduleName, useFileHash = true, libType = 'var', libName, exclude = [] }) => {
24
26
  const { dependencies, insights } = require(resolve(root, './package.json')) || {};
25
27
  const appName = moduleName || (insights && jsVarName(insights.appname));
26
28
 
@@ -39,7 +41,7 @@ module.exports = ({ root, exposes, shared = [], debug, moduleName, useFileHash =
39
41
  * No application should be installing/interacting with scalprum directly.
40
42
  */
41
43
  if (dependencies['@redhat-cloud-services/frontend-components']) {
42
- sharedDeps.push({ '@scalprum/react-core': { requiredVersion: '*', singleton: true, eager: true } });
44
+ sharedDeps.push({ '@scalprum/react-core': { requiredVersion: '*', singleton: true, eager } });
43
45
  }
44
46
 
45
47
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config-utilities",
3
- "version": "1.5.17",
3
+ "version": "1.5.20",
4
4
  "description": "Utilities for shared config used in RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -18,5 +18,8 @@
18
18
  "homepage": "https://github.com/RedHatInsights/frontend-components#readme",
19
19
  "peerDependencies": {
20
20
  "webpack": "^5.0.0"
21
+ },
22
+ "dependencies": {
23
+ "node-fetch": "2.6.7"
21
24
  }
22
25
  }
package/proxy.js CHANGED
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable no-console */
2
2
  // Webpack proxy and express config for `useProxy: true` or `standalone: true`
3
3
  const { execSync } = require('child_process');
4
+ const fetch = require('node-fetch');
5
+ var express = require('express');
4
6
  const path = require('path');
5
7
  const HttpsProxyAgent = require('https-proxy-agent');
6
8
  const cookieTransform = require('./cookieTransform');
@@ -34,6 +36,8 @@ module.exports = ({
34
36
  registry = [],
35
37
  isChrome = false,
36
38
  onBeforeSetupMiddleware = () => {},
39
+ bounceProd = false,
40
+ useAgent = true,
37
41
  }) => {
38
42
  const proxy = [];
39
43
  const majorEnv = env.split('-')[0];
@@ -53,12 +57,17 @@ module.exports = ({
53
57
 
54
58
  let agent;
55
59
 
56
- if (env.startsWith('prod') || env.startsWith('stage')) {
57
- // PROD and stage are deployed with Akamai which requires a corporate proxy
60
+ const isProd = env.startsWith('prod');
61
+ const isStage = env.startsWith('stage');
62
+
63
+ const shouldBounceProdRequests = isProd && bounceProd && !useAgent;
64
+
65
+ if (isStage || (isProd && useAgent)) {
66
+ // stage is deployed with Akamai which requires a corporate proxy
58
67
  agent = new HttpsProxyAgent(proxyURL);
59
68
  }
60
69
 
61
- if (env.startsWith('stage')) {
70
+ if (isStage) {
62
71
  // stage-stable / stage-beta branches don't exist in build repos
63
72
  // Currently stage pulls from QA
64
73
  env = env.replace('stage', 'qa');
@@ -185,19 +194,37 @@ module.exports = ({
185
194
  return false;
186
195
  },
187
196
  target,
188
- ...(isChrome && {
189
- bypass: (req) => {
190
- /**
191
- * Bypass any HTML requests if using chrome
192
- * Serves as a historyApiFallback when refreshing on any other URL than '/'
193
- */
194
- if (!req.url.match(/\/api\//) && !req.url.match(/\./) && req.headers.accept.includes('text/html')) {
195
- return '/';
197
+ bypass: async (req, res) => {
198
+ /**
199
+ * Bypass any HTML requests if using chrome
200
+ * Serves as a historyApiFallback when refreshing on any other URL than '/'
201
+ */
202
+ if (isChrome && !req.url.match(/\/api\//) && !req.url.match(/\./) && req.headers.accept.includes('text/html')) {
203
+ return '/';
204
+ }
205
+
206
+ /**
207
+ * Use node-fetch to proxy all non-GET requests (this avoids all origin/host akamai policy)
208
+ * This enables using PROD proxy without VPN and agent
209
+ */
210
+ if (shouldBounceProdRequests && req.method !== 'GET') {
211
+ const result = await fetch((target + req.url).replace(/\/\//g, '/'), {
212
+ method: req.method,
213
+ body: JSON.stringify(req.body),
214
+ headers: { cookie: req.headers.cookie, 'Content-Type': 'application/json' },
215
+ });
216
+
217
+ const text = await result.text();
218
+ try {
219
+ const data = JSON.parse(text);
220
+ res.status(result.status).json(data);
221
+ } catch (err) {
222
+ res.status(result.status).send(text);
196
223
  }
224
+ }
197
225
 
198
- return null;
199
- },
200
- }),
226
+ return null;
227
+ },
201
228
  router: router(target, useCloud),
202
229
  ...(agent && {
203
230
  agent,
@@ -235,6 +262,12 @@ module.exports = ({
235
262
  },
236
263
  onBeforeSetupMiddleware({ app, compiler, options }) {
237
264
  app.enable('strict routing'); // trailing slashes are mean
265
+
266
+ if (shouldBounceProdRequests) {
267
+ app.use(express.json());
268
+ app.use(express.urlencoded({ extended: true }));
269
+ }
270
+
238
271
  /**
239
272
  * Allow serving chrome assets
240
273
  * This will allow running chrome as a host application