@pega/dx-component-builder-sdk 0.1.48 → 0.1.49

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.
@@ -4,7 +4,7 @@ import chalk from 'chalk';
4
4
 
5
5
  import validate from '../validator/index.js';
6
6
  import { getComponentDirectoryPath, showVersion, getOptionsCategory, getComponentsObj, getFramework, getLocalComponentKeyFromConfig, convertIntoKebabCase, convertIntoPascalCase } from '../../util.js';
7
- import { bundleReactComponent, bundleAngularComponent} from '../bundle/index.js';
7
+ import { bundleReactComponent, bundleAngularComponent, bundleAssociatedComponent} from '../bundle/index.js';
8
8
  import { updateComponentMap } from '../map/map.js';
9
9
  import { lintComponent } from '../linter/index.js';
10
10
  import { CATEGORY_CONSTELLATION, CATEGORY_CUSTOM } from '../../constants.js';
@@ -78,7 +78,7 @@ export function getCustomTasks(componentKey, category, sourceMap, devBuild, cont
78
78
  },
79
79
  {
80
80
  title: `Bundle associated component ${sDevBuild}`,
81
- task: async () => await bundleReactComponent(associatedComponentKey, sourceMap, devBuild, CATEGORY_CONSTELLATION),
81
+ task: async () => await bundleAssociatedComponent(associatedComponentKey, sourceMap, devBuild, CATEGORY_CONSTELLATION),
82
82
  skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
83
83
  },
84
84
  {
@@ -112,6 +112,9 @@ export function getOverrideTasks(componentKey, category, sourceMap, devBuild, co
112
112
  const sDevBuild = devBuild ? '(dev build)' : '';
113
113
  const sFramework = framework.split("-")[1];
114
114
 
115
+ // don't fetch if testing
116
+ const doFetch = options.params.length >= 7 ? false : true;
117
+
115
118
  return new Listr(
116
119
  [
117
120
  {
@@ -156,7 +159,7 @@ export function getOverrideTasks(componentKey, category, sourceMap, devBuild, co
156
159
  {
157
160
  title: 'Publish component config',
158
161
  task: async () => {
159
- await publishComponentToServer(content);
162
+ await publishComponentToServer(content, doFetch);
160
163
  }
161
164
  }
162
165
  ],
@@ -201,7 +204,7 @@ export default async options => {
201
204
  const catQuestion = await getBuildCategory(options);
202
205
  const catAnswers = await inquirer.prompt(catQuestion);
203
206
 
204
-
207
+
205
208
  category = catAnswers.category;
206
209
  if (category == null) {
207
210
  category = getOptionsCategory(options);
@@ -214,11 +217,11 @@ export default async options => {
214
217
  console.log(chalk.redBright("No components to publish"));
215
218
  process.exit(1);
216
219
  }
217
-
220
+
218
221
  const questions = await getPublishComponentQuestions(category);
219
222
  const answers = await inquirer.prompt(questions);
220
223
  ({sourceMap, devBuild } = answers);
221
-
224
+
222
225
  content = {
223
226
  ...answers
224
227
  };
package/src/util.js CHANGED
@@ -4,6 +4,7 @@ import { join } from 'path';
4
4
  import { promisify } from 'util';
5
5
  import https from 'https';
6
6
  import inquirer from 'inquirer';
7
+ import crypto from 'node:crypto';
7
8
  import { createRequire } from "module";
8
9
 
9
10
  import chalk from 'chalk';
@@ -195,8 +196,17 @@ export const deleteLocalComponent = async (componentKey, category = CATEGORY_CUS
195
196
  }
196
197
  };
197
198
 
199
+ export const getHttpsAgent = (serverConfig) => {
200
+ const agentOptions = { rejectUnauthorized: false };
201
+ if (serverConfig.legacyTLS) {
202
+ agentOptions.secureOptions = crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT;
203
+ }
204
+ return new https.Agent(agentOptions);
205
+ };
206
+
198
207
  export const deleteServerComponent = async componentKey => {
199
- const { server, user, password } = await getPegaServerConfig();
208
+ const serverConfig = await getPegaServerConfig();
209
+ const { server, user, password } = serverConfig;
200
210
  const url = constructCompleteUrl(server, DELETE_COMPONENT_SERVICE_REST_ENDPOINT);
201
211
  const [componentName, rulesetName, rulesetVersion] = componentKey.split('~|~');
202
212
  const deleteUrl = `${url}/${componentName}/rulesetname/${rulesetName}/rulesetversion/${rulesetVersion}`;
@@ -213,7 +223,7 @@ export const deleteServerComponent = async componentKey => {
213
223
  } = JSON.parse(OauthData);
214
224
  fetch(deleteUrl, {
215
225
  method: 'DELETE',
216
- agent: new https.Agent({ rejectUnauthorized: false }),
226
+ agent: getHttpsAgent(serverConfig),
217
227
  headers: {
218
228
  Authorization: `${tokenType} ${accessToken}`
219
229
  }
@@ -690,22 +700,6 @@ export const constructCompleteUrl = (baseServer, endPoint) => {
690
700
  return baseServer.endsWith('/') ? `${baseServer}${endPoint}` : `${baseServer}/${endPoint}`;
691
701
  };
692
702
 
693
- export const nodeFetch = (url, config) => {
694
- const { method, user, password, headers, ...restConfig } = config;
695
-
696
- if (url.startsWith('https')) restConfig.agent = new https.Agent({ rejectUnauthorized: false });
697
-
698
- return fetch(url, {
699
- method,
700
- ...restConfig,
701
- headers: {
702
- 'Content-Type': 'application/json;charset=utf-8',
703
- Authorization: `Basic ${Buffer.from(`${user}:${password}`).toString('base64')}`,
704
- ...headers
705
- }
706
- });
707
- };
708
-
709
703
  export const sanitize = str => {
710
704
  /* Allow only numbers and case insensitive alphabets */
711
705
  str = str.replace(/[^a-zA-Z0-9 ]/g, '');
@@ -754,7 +748,8 @@ export const getOOTBComponents = async () => {
754
748
  fs.readFile(OOTB_COMPONENTS, 'utf-8', async (err, data) => {
755
749
  if (err) {
756
750
  try {
757
- const { server } = await getPegaServerConfig();
751
+ const serverConfig = await getPegaServerConfig();
752
+ const { server } = serverConfig;
758
753
  const url = constructCompleteUrl(server, OOTB_COMPONENT_SERVICE_REST_ENDPOINT);
759
754
  const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
760
755
  if (OauthData) {
@@ -765,7 +760,7 @@ export const getOOTBComponents = async () => {
765
760
  } = JSON.parse(OauthData);
766
761
  fetch(url, {
767
762
  method: 'GET',
768
- agent: new https.Agent({ rejectUnauthorized: false }),
763
+ agent: getHttpsAgent(serverConfig),
769
764
  headers: {
770
765
  Authorization: `${tokenType} ${accessToken}`
771
766
  }