@pega/custom-dx-components 0.23.5 → 0.23.7

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 (35) hide show
  1. package/package.json +1 -1
  2. package/src/auth.js +9 -3
  3. package/src/tasks/authenticate/index.js +42 -39
  4. package/src/tasks/build/helper.js +5 -19
  5. package/src/tasks/bundle/builder/webpack.config.js +2 -4
  6. package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -1
  7. package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -1
  8. package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -1
  9. package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -1
  10. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -1
  11. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -1
  12. package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -1
  13. package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -1
  14. package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -1
  15. package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -1
  16. package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -1
  17. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -1
  18. package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -1
  19. package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -1
  20. package/src/tasks/create/templates/Constellation/Field/TimeOfDay/styles.js.mustache +7 -1
  21. package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -1
  22. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -1
  23. package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -1
  24. package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -1
  25. package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -1
  26. package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +6 -0
  27. package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +6 -0
  28. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +6 -0
  29. package/src/tasks/create-all/index.js +51 -116
  30. package/src/tasks/init/index.js +15 -21
  31. package/src/tasks/init/template/package.json.mustache +1 -1
  32. package/src/tasks/list/helper.js +8 -6
  33. package/src/tasks/publish/helper.js +16 -30
  34. package/src/tasks/publish-all/helper.js +9 -27
  35. package/src/util.js +43 -78
@@ -6,17 +6,8 @@ import fetch from 'node-fetch';
6
6
  import AdmZip from 'adm-zip';
7
7
  import chalk from 'chalk';
8
8
 
9
- import {
10
- constructCompleteUrl,
11
- getComponentDirectoryPath,
12
- getPegaServerConfig,
13
- validateRulesetVersion
14
- } from '../../util.js';
15
- import {
16
- PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
17
- LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
18
- TOKEN_PATH
19
- } from '../../constants.js';
9
+ import { constructCompleteUrl, getComponentDirectoryPath, getPegaServerConfig, validateRulesetVersion, getHttpsAgent } from '../../util.js';
10
+ import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
20
11
 
21
12
  export const getPublishComponentQuestions = async () => {
22
13
  const defaultPegaConfig = await getPegaServerConfig();
@@ -108,10 +99,7 @@ export const publishComponentToServer = async (data, doFetch) => {
108
99
  const defaultPegaServerConfig = await getPegaServerConfig();
109
100
  const { serverType, isolationId } = defaultPegaServerConfig;
110
101
  const isLaunchpad = serverType === 'launchpad';
111
- const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace(
112
- '{isolationId}',
113
- isolationId
114
- );
102
+ const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace('{isolationId}', isolationId);
115
103
  let apiBody;
116
104
 
117
105
  if (isLaunchpad) {
@@ -135,10 +123,7 @@ export const publishComponentToServer = async (data, doFetch) => {
135
123
  }
136
124
 
137
125
  const defaultPegaConfig = await getPegaServerConfig();
138
- const url = constructCompleteUrl(
139
- defaultPegaConfig.server,
140
- isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
141
- );
126
+ const url = constructCompleteUrl(defaultPegaConfig.server, isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT);
142
127
 
143
128
  if (doFetch) {
144
129
  try {
@@ -161,20 +146,18 @@ export const publishComponentToServer = async (data, doFetch) => {
161
146
 
162
147
  fetch(url, {
163
148
  method: 'POST',
164
- agent: new https.Agent({ rejectUnauthorized: false }),
149
+ agent: getHttpsAgent(defaultPegaConfig),
165
150
  headers,
166
151
  body: JSON.stringify(apiBody)
167
152
  })
168
- .then((response) => {
153
+ .then((response) => {
169
154
  status = response.status;
170
155
  return response.text();
171
156
  })
172
- .then((resp) => {
157
+ .then((resp) => {
173
158
  const respData = isLaunchpad ? resp : JSON.parse(resp);
174
159
  if (status === 401) {
175
- throw new Error(
176
- 'Error occurred in authentication. Please regenerate using authenticate'
177
- );
160
+ throw new Error('Error occurred in authentication. Please regenerate using authenticate');
178
161
  // console.log(accessTokenUri, refreshToken);
179
162
  /* TODO - Handle refresh_token */
180
163
  } else if (status === 200 || status === 201) {
@@ -183,7 +166,7 @@ export const publishComponentToServer = async (data, doFetch) => {
183
166
  throw new Error(`${respData.message}`);
184
167
  }
185
168
  })
186
- .catch((e) => {
169
+ .catch((e) => {
187
170
  if (e.code === 'ECONNREFUSED') {
188
171
  // eslint-disable-next-line prefer-promise-reject-errors
189
172
  Promise.reject(`${chalk.bold.red('Error occurred in authentication. Please regenerate using authenticate')}`);
@@ -202,5 +185,4 @@ export const publishComponentToServer = async (data, doFetch) => {
202
185
  throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
203
186
  }
204
187
  }
205
-
206
188
  };
package/src/util.js CHANGED
@@ -2,21 +2,16 @@ import fs from 'fs';
2
2
  import { join } from 'path';
3
3
  import { promisify } from 'util';
4
4
  import https from 'https';
5
-
5
+ import crypto from 'node:crypto';
6
+ import { createRequire } from 'module';
6
7
 
7
8
  import chalk from 'chalk';
8
9
  import mustache from 'mustache';
9
10
  import pascalCase from 'pascalcase';
10
11
  import fetch from 'node-fetch';
11
- import { createRequire } from 'module';
12
-
13
12
  import checkGit from 'check-git';
14
13
 
15
- import * as currentPath from "./currentPath.cjs";
16
-
17
-
18
-
19
-
14
+ import * as currentPath from './currentPath.cjs';
20
15
  import {
21
16
  COMPONENTS_DIRECTORY_PATH,
22
17
  TASKS_CONFIG_JSON_FILENAME,
@@ -35,8 +30,7 @@ export const checkPathAccess = async (path, options = {}) => {
35
30
  try {
36
31
  await access(path, fs.constants.R_OK);
37
32
  } catch (err) {
38
- const message =
39
- errorMessage || `${chalk.red.bold('ERROR')} Could not able to access path - ${path}`;
33
+ const message = errorMessage || `${chalk.red.bold('ERROR')} Could not able to access path - ${path}`;
40
34
  console.error(message);
41
35
  process.exit(1);
42
36
  }
@@ -52,9 +46,7 @@ export const deleteLocalComponent = async (componentKey) => {
52
46
  data = JSON.parse(data);
53
47
 
54
48
  if (!data[COMPONENTS_DIRECTORY_PATH]) {
55
- console.error(
56
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
57
- );
49
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
58
50
  process.exit(1);
59
51
  }
60
52
 
@@ -63,15 +55,23 @@ export const deleteLocalComponent = async (componentKey) => {
63
55
  try {
64
56
  fs.rmSync(directory, { recursive: true });
65
57
  console.log(`${chalk.red.bold(componentKey)} is deleted from Local`);
58
+ } catch (err) {
59
+ console.log('no file');
60
+ throw new Error(`No such file ${componentKey}`);
66
61
  }
67
- catch (err) {
68
- console.log("no file");
69
- throw new Error (`No such file ${componentKey}`);
62
+ };
63
+
64
+ export const getHttpsAgent = (serverConfig) => {
65
+ const agentOptions = { rejectUnauthorized: false };
66
+ if (serverConfig.legacyTLS) {
67
+ agentOptions.secureOptions = crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT;
70
68
  }
69
+ return new https.Agent(agentOptions);
71
70
  };
72
71
 
73
- export const deleteServerComponent = async componentKey => {
74
- const { server, user, password } = await getPegaServerConfig();
72
+ export const deleteServerComponent = async (componentKey) => {
73
+ const serverConfig = await getPegaServerConfig();
74
+ const { server, user, password } = serverConfig;
75
75
  const url = constructCompleteUrl(server, DELETE_COMPONENT_SERVICE_REST_ENDPOINT);
76
76
  const [componentName, rulesetName, rulesetVersion] = componentKey.split('~|~');
77
77
  const deleteUrl = `${url}/${componentName}/rulesetname/${rulesetName}/rulesetversion/${rulesetVersion}`;
@@ -79,26 +79,20 @@ export const deleteServerComponent = async componentKey => {
79
79
  const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
80
80
 
81
81
  if (OauthData) {
82
- const {
83
- access_token: accessToken,
84
- token_type: tokenType,
85
- refresh_token: refreshToken
86
- } = JSON.parse(OauthData);
82
+ const { access_token: accessToken, token_type: tokenType, refresh_token: refreshToken } = JSON.parse(OauthData);
87
83
  fetch(deleteUrl, {
88
84
  method: 'DELETE',
89
- agent: new https.Agent({ rejectUnauthorized: false }),
85
+ agent: getHttpsAgent(serverConfig),
90
86
  headers: {
91
87
  Authorization: `${tokenType} ${accessToken}`
92
88
  }
93
89
  })
94
- .then(response => response.text())
95
- .then(resp => {
90
+ .then((response) => response.text())
91
+ .then((resp) => {
96
92
  let respData;
97
93
  try {
98
94
  respData = JSON.parse(resp);
99
-
100
- }
101
- catch (e) {
95
+ } catch (e) {
102
96
  console.log(chalk.bold.redBright(`Failure : ${resp}`));
103
97
  process.exit(1);
104
98
  }
@@ -108,17 +102,14 @@ export const deleteServerComponent = async componentKey => {
108
102
  } else {
109
103
  throw new Error(`${respData.message}`);
110
104
  }
111
-
112
-
113
105
  })
114
- .catch(e => Promise.reject(`${chalk.bold.red(e)}`));
106
+ .catch((e) => Promise.reject(`${chalk.bold.red(e)}`));
115
107
  }
116
108
  } catch (error) {
117
109
  console.log(`\n${chalk.bold.red(error)}`);
118
110
  }
119
111
  };
120
112
 
121
-
122
113
  export const getComponents = async () => {
123
114
  const currentDirectory = process.cwd();
124
115
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -130,34 +121,28 @@ export const getComponents = async () => {
130
121
  data = JSON.parse(data);
131
122
 
132
123
  if (!data[COMPONENTS_DIRECTORY_PATH]) {
133
- console.error(
134
- `${chalk.red.bold('ERROR')} Could not find components directory path in config.json`
135
- );
124
+ console.error(`${chalk.red.bold('ERROR')} Could not find components directory path in config.json`);
136
125
  process.exit(1);
137
126
  }
138
127
 
139
128
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH]);
140
129
  return fs
141
130
  .readdirSync(directory, { withFileTypes: true })
142
- .filter(dirent => dirent.isDirectory())
143
- .map(dirent => dirent.name);
131
+ .filter((dirent) => dirent.isDirectory())
132
+ .map((dirent) => dirent.name);
144
133
  };
145
134
 
146
-
147
-
148
-
149
135
  export const getSubComponents = async (directory, type) => {
150
-
151
136
  const subDirectory = join(directory, type);
152
137
  return fs
153
- .readdirSync(subDirectory, { withFileTypes: true })
138
+ .readdirSync(subDirectory, { withFileTypes: true })
154
139
  .filter((dirent) => dirent.isDirectory())
155
140
  .map((dirent) => dirent.name);
156
141
  };
157
142
 
158
143
  export const getDirectoryFiles = async (directory) => {
159
144
  return fs
160
- .readdirSync(directory, { withFileTypes: true })
145
+ .readdirSync(directory, { withFileTypes: true })
161
146
  .filter((dirent) => !dirent.isDirectory())
162
147
  .map((dirent) => dirent.name);
163
148
  };
@@ -168,18 +153,16 @@ export const getComponentsObj = async () => {
168
153
  // const componentList = await getDirectoryFiles(directory);
169
154
  const componentList = await getComponents();
170
155
 
171
-
172
156
  if (componentList.length > 0) {
173
-
174
- compList.push(...componentList.map(
175
- name => {
157
+ compList.push(
158
+ ...componentList.map((name) => {
176
159
  const container = {};
177
160
  container.name = name;
178
161
  container.value = name;
179
162
 
180
163
  return container;
181
- }
182
- ));
164
+ })
165
+ );
183
166
  }
184
167
 
185
168
  return compList;
@@ -217,9 +200,7 @@ export const getComponentDirectoryPath = async (componentKey) => {
217
200
  data = JSON.parse(data);
218
201
 
219
202
  if (!data[COMPONENTS_DIRECTORY_PATH]) {
220
- console.error(
221
- `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
222
- );
203
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
223
204
  process.exit(1);
224
205
  }
225
206
 
@@ -243,22 +224,6 @@ export const constructCompleteUrl = (baseServer, endPoint) => {
243
224
  return baseServer.endsWith('/') ? `${baseServer}${endPoint}` : `${baseServer}/${endPoint}`;
244
225
  };
245
226
 
246
- // export const nodeFetch = (url, config) => {
247
- // const { method, user, password, headers, ...restConfig } = config;
248
-
249
- // if (url.startsWith('https')) restConfig.agent = new https.Agent({ rejectUnauthorized: false });
250
-
251
- // return fetch(url, {
252
- // method,
253
- // ...restConfig,
254
- // headers: {
255
- // 'Content-Type': 'application/json;charset=utf-8',
256
- // Authorization: `Basic ${Buffer.from(`${user}:${password}`).toString('base64')}`,
257
- // ...headers
258
- // }
259
- // });
260
- // };
261
-
262
227
  export const sanitize = (str) => {
263
228
  /* Allow only numbers and case insensitive alphabets */
264
229
  str = str.replace(/[^a-zA-Z0-9 ]/g, '');
@@ -292,7 +257,7 @@ export const showVersion = () => {
292
257
  // const require = createRequire(import.meta.url);
293
258
  const require = createRequire(currentPath.default);
294
259
 
295
- const pData = require("@pega/custom-dx-components/package.json");
260
+ const pData = require('@pega/custom-dx-components/package.json');
296
261
 
297
262
  console.log(chalk.green(`DX Component Builder v${pData.version}`));
298
263
 
@@ -303,18 +268,16 @@ export const showVersion = () => {
303
268
  const nodeMinorVersion = parseInt(arNodeVersion[1]);
304
269
 
305
270
  if (nodeMajorVersion < 18) {
306
- console.log(chalk.redBright("DX Component Builder - SDK requires node v18 or greater, current version: " + process.version));
271
+ console.log(chalk.redBright(`DX Component Builder - SDK requires node v18 or greater, current version: ${process.version}`));
307
272
  process.exit(1);
308
273
  }
309
274
 
310
275
  const hasGit = checkGit(process.cwd());
311
276
 
312
277
  if (!hasGit) {
313
- console.log(chalk.redBright("DX Component Builder - SDK git to be installed."));
278
+ console.log(chalk.redBright('DX Component Builder - SDK git to be installed.'));
314
279
  process.exit(1);
315
280
  }
316
-
317
-
318
281
  };
319
282
 
320
283
  export const getOOTBComponents = async () => {
@@ -322,14 +285,15 @@ export const getOOTBComponents = async () => {
322
285
  fs.readFile(OOTB_COMPONENTS, 'utf-8', async (error, ootbComponentsData) => {
323
286
  if (error) {
324
287
  try {
325
- const { server } = await getPegaServerConfig();
288
+ const serverConfig = await getPegaServerConfig();
289
+ const { server } = serverConfig;
326
290
  const url = constructCompleteUrl(server, OOTB_COMPONENT_SERVICE_REST_ENDPOINT);
327
291
  const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
328
292
  if (OauthData) {
329
293
  const { access_token: accessToken, token_type: tokenType } = JSON.parse(OauthData);
330
294
  fetch(url, {
331
295
  method: 'GET',
332
- agent: new https.Agent({ rejectUnauthorized: false }),
296
+ agent: getHttpsAgent(serverConfig),
333
297
  headers: {
334
298
  Authorization: `${tokenType} ${accessToken}`
335
299
  }
@@ -369,7 +333,8 @@ export const getOOTBComponents = async () => {
369
333
  };
370
334
 
371
335
  export const deleteInfinityServerComponent = async (componentKey) => {
372
- const { server } = await getPegaServerConfig();
336
+ const serverConfig = await getPegaServerConfig();
337
+ const { server } = serverConfig;
373
338
  const url = constructCompleteUrl(server, DELETE_COMPONENT_SERVICE_REST_ENDPOINT);
374
339
  const [componentName, rulesetName, rulesetVersion] = componentKey.split('~|~');
375
340
  const deleteUrl = `${url}/${componentName}/rulesetname/${rulesetName}/rulesetversion/${rulesetVersion}`;
@@ -382,7 +347,7 @@ export const deleteInfinityServerComponent = async (componentKey) => {
382
347
  const { access_token: accessToken, token_type: tokenType } = JSON.parse(OauthData);
383
348
  fetch(deleteUrl, {
384
349
  method: 'DELETE',
385
- agent: new https.Agent({ rejectUnauthorized: false }),
350
+ agent: getHttpsAgent(serverConfig),
386
351
  headers: {
387
352
  Authorization: `${tokenType} ${accessToken}`
388
353
  }