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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config-utilities",
3
- "version": "1.5.14",
3
+ "version": "1.5.17",
4
4
  "description": "Utilities for shared config used in RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -2,12 +2,12 @@ const path = require('path');
2
2
  const fs = require('fs');
3
3
  const concurrently = require('concurrently');
4
4
 
5
- async function federate(argv, cwd) {
6
- let configPath = argv.config;
5
+ function federate(argv, cwd) {
6
+ let configPath = argv.config || './node_modules/@redhat-cloud-services/frontend-components-config/src/scripts/prod.webpack.config.js';
7
7
  const WEBPACK_PATH = path.resolve(cwd, './node_modules/.bin/webpack');
8
8
  const HTTP_SERVER_PATH = path.resolve(cwd, './node_modules/.bin/http-server');
9
9
  if (typeof configPath !== 'string') {
10
- console.error('Missing webpack config path');
10
+ console.error('Invalid webpack config path!');
11
11
  process.exit(1);
12
12
  }
13
13
 
@@ -17,15 +17,17 @@ async function federate(argv, cwd) {
17
17
  fs.statSync(configPath);
18
18
  let config = require(configPath);
19
19
  if (typeof config === 'function') {
20
- config = await Promise.resolve(config(process.env));
20
+ config = config(process.env);
21
21
  }
22
22
 
23
- const outputPath = config.output.path;
23
+ Promise.resolve(config).then((config) => {
24
+ const outputPath = config.output.path;
24
25
 
25
- concurrently([
26
- `${WEBPACK_PATH} --config ${configPath} --watch --output-path ${path.join(outputPath, config.output.publicPath)}`,
27
- `${HTTP_SERVER_PATH} ${outputPath} -p ${argv.port || 8003} -c-1`,
28
- ]);
26
+ concurrently([
27
+ `${WEBPACK_PATH} --config ${configPath} --watch --output-path ${path.join(outputPath, config.output.publicPath)}`,
28
+ `${HTTP_SERVER_PATH} ${outputPath} -p ${argv.port || 8003} -c-1`,
29
+ ]);
30
+ });
29
31
  } catch (error) {
30
32
  console.error(error);
31
33
  process.exit(1);
@@ -19,17 +19,25 @@ module.exports = ({ env }) => ({
19
19
  'entitlements-config': `https://github.com/redhatinsights/entitlements-config#${getEntitlementsBranch(env)}`
20
20
  },
21
21
  register({ app, config }) {
22
- app.get('/api/entitlements/v1/services', (_req, res) => {
23
- const configPath = path.join(config.entitlements.assets['entitlements-config'], '/configs/bundles.yml');
24
- // Use { json: true } in case of duplicate keys
25
- const serviceSKUs = yaml.load(fs.readFileSync(configPath, 'utf8'), { json: true });
26
- const services = serviceSKUs.map(serviceSKU => serviceSKU.name);
27
- // Grant access to all services
28
- const entitlements = services.reduce((acc, cur) => {
29
- acc[cur] = { is_entitled: true, is_trial: false };
30
- return acc;
31
- }, {});
32
- res.json(entitlements);
33
- });
34
- }
22
+ app.get('/api/entitlements/v1/services', (_req, res) => {
23
+ try {
24
+ const configPath = path.join(config.entitlements.assets['entitlements-config'], '/configs/stage/bundles.yml');
25
+
26
+ // Use { json: true } in case of duplicate keys
27
+ const outerYaml = yaml.load(fs.readFileSync(configPath, 'utf8'), { json: true });
28
+ const serviceSKUs = yaml.load(outerYaml.objects[0].data['bundles.yml'], { json: true });
29
+
30
+ const services = serviceSKUs.map(serviceSKU => serviceSKU.name);
31
+ // Grant access to all services
32
+ const entitlements = services.reduce((acc, cur) => {
33
+ acc[cur] = { is_entitled: true, is_trial: false };
34
+ return acc;
35
+ }, {});
36
+
37
+ res.json(entitlements);
38
+ } catch (error) {
39
+ res.status(500).json({ error });
40
+ }
41
+ });
42
+ },
35
43
  });