@pega/custom-dx-components 25.1.10-alpha-0.1 → 25.1.10-alpha-0.2

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": "@pega/custom-dx-components",
3
- "version": "25.1.10-alpha-0.1",
3
+ "version": "25.1.10-alpha-0.2",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "@babel/plugin-transform-class-properties": "^7.27.1",
20
20
  "@babel/preset-react": "^7.27.1",
21
21
  "@pega/auth": "^0.2.24",
22
- "@pega/constellation-dx-components-build-utils": "^2.0.3-dev",
22
+ "@pega/constellation-dx-components-build-utils": "^2.0.4",
23
23
  "@pega/inquirer-fuzzy-path": "^3.0.0",
24
24
  "ajv": "^8.17.1",
25
25
  "ajv-keywords": "^5.1.0",
package/src/constants.js CHANGED
@@ -22,7 +22,7 @@ export const ARCHIVES_PATH = 'store';
22
22
  export const BIN_ARCHIVES_PATH = 'bin-arch';
23
23
  export const TEMP_PATH = 'store/temp';
24
24
  export const COMPONENTS_CONFIG_FILE_NAME = 'componentsconfig.json';
25
-
25
+ export const MAX_RFT_CHARS = 64;
26
26
 
27
27
 
28
28
  /* REST end points */
@@ -23,7 +23,8 @@ import {
23
23
  addDebugLog,
24
24
  checkLibraryAndArchives,
25
25
  getConfigDefaults,
26
- getSubTypeLabel
26
+ getSubTypeLabel,
27
+ getMaxComponentNameCount
27
28
  } from '../../util.js';
28
29
  import { COMPONENT_SCHEMA, SHARED_FILE_NAMES } from '../../constants.js';
29
30
 
@@ -309,6 +310,7 @@ addDebugLog("create", "", "+");
309
310
  );
310
311
  } else {
311
312
  const componentDefaults = getConfigDefaults();
313
+ const maxChars = getMaxComponentNameCount();
312
314
  const questions = [
313
315
  {
314
316
  name: 'type',
@@ -356,7 +358,7 @@ addDebugLog("create", "", "+");
356
358
  },
357
359
  {
358
360
  name: 'componentName',
359
- message: 'Enter component name (required)',
361
+ message: `Enter component name (required) (${maxChars} max chars)`,
360
362
  validate: value => {
361
363
  /* value should not be empty
362
364
  It should not have spaces
@@ -364,8 +366,12 @@ addDebugLog("create", "", "+");
364
366
  Only case-insensitive alphanumeric values are allowed
365
367
  */
366
368
  if (value && !/^\d/.test(value) && value === sanitize(value)) {
369
+ if (value.length > maxChars) {
370
+ return `${value.length - maxChars} too many characters.`
371
+ }
367
372
  return true;
368
373
  }
374
+
369
375
  return 'Only alphanumeric values are allowed, starting with alphabets, no spaces.';
370
376
  }
371
377
  },
@@ -24,7 +24,8 @@ import { checkPathAccess, showVersion ,
24
24
  addDebugLog,
25
25
  checkLibraryAndArchives,
26
26
  getConfigDefaults,
27
- getSubTypeLabel
27
+ getSubTypeLabel,
28
+ getMaxPrefixCount
28
29
  } from '../../util.js';
29
30
 
30
31
  import { COMPONENT_SCHEMA, COMPONENTS_DIRECTORY_PATH, TASKS_CONFIG_JSON_FILENAME, COMPONENTS_PATH, CATEGORY_CONSTELLATION, SHARED_FILE_NAMES } from '../../constants.js';
@@ -409,10 +410,25 @@ addDebugLog("createAll", "", "+");
409
410
  options
410
411
  );
411
412
  } else {
413
+ const maxPrefixCount = getMaxPrefixCount();
412
414
  const questions = [
413
415
  {
414
416
  name: 'prefix',
415
- message: 'Enter prefix label'
417
+ message: `Enter prefix label (${maxPrefixCount} max chars)`,
418
+ validate: value => {
419
+ /* value should not be empty
420
+ It should not start with a number
421
+ Only case-insensitive alphanumeric values are allowed
422
+ */
423
+ if (value && !/^\d/.test(value) ) {
424
+ if (value.length > maxPrefixCount) {
425
+ return `${value.length - maxPrefixCount} too many characters.`
426
+ }
427
+ return true;
428
+ }
429
+
430
+ return 'Only alphanumeric values are allowed, starting with alphabets';
431
+ }
416
432
  },
417
433
  {
418
434
  name: 'version',
@@ -62,11 +62,10 @@ addDebugLog("getCreateLibComponentQuestions", "", "");
62
62
 
63
63
  const isLibraryBasedCL = getLibraryBasedCL();
64
64
 
65
-
66
65
  return [
67
66
  {
68
67
  name: 'libraryName',
69
- message: 'Enter libray name',
68
+ message: 'Enter library name',
70
69
  default: libraryName,
71
70
  validate: value => {
72
71
  /* value should not be empty
@@ -326,7 +326,7 @@ export const importArch = async(filePath, fileName, hadArchive) => {
326
326
  const newLibNameAnswers = await inquirer.prompt([
327
327
  {
328
328
  name: 'libraryName',
329
- message: 'Enter new libray name',
329
+ message: 'Enter new library name',
330
330
  validate: value => {
331
331
  /* value should not be empty
332
332
  It should not have spaces
@@ -524,7 +524,7 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
524
524
  const newLibNameAnswers = await inquirer.prompt([
525
525
  {
526
526
  name: 'libraryName',
527
- message: 'Enter new libray name',
527
+ message: 'Enter new library name',
528
528
  validate: value => {
529
529
  /* value should not be empty
530
530
  It should not have spaces
@@ -107,7 +107,7 @@
107
107
  "@babel/preset-react": "^7.27.1",
108
108
  "@babel/preset-typescript": "^7.27.1",
109
109
  "@pega/configs": "^0.16.3",
110
- "@pega/custom-dx-components": "~25.1.10-alpha-0.1",
110
+ "@pega/custom-dx-components": "~25.1.10-alpha-0.2",
111
111
  "@pega/pcore-pconnect-typedefs": "^4.1.0-alpha.1",
112
112
  "@storybook/addon-actions": "^8.6.12",
113
113
  "@storybook/addon-essentials": "^8.6.12",
@@ -12,6 +12,7 @@ import {
12
12
  getComponentDirectoryPath,
13
13
  getComponents,
14
14
  getOOTBComponents,
15
+ isComponentValidLength,
15
16
  addDebugLog } from '../../util.js';
16
17
 
17
18
  const ajv = new Ajv({ allErrors: true });
@@ -340,6 +341,10 @@ export default async (option) => {
340
341
  throwTheError = true;
341
342
  }
342
343
 
344
+ if (!isComponentValidLength(componentToValidate)) {
345
+ throw new Error(`Invalid: componentName is too long.`);
346
+ }
347
+
343
348
  const componentDirectory = await getComponentDirectoryPath(componentToValidate);
344
349
  let configFileName = "config.json";
345
350
 
package/src/util.js CHANGED
@@ -44,7 +44,8 @@ import {
44
44
  TEMP_PATH,
45
45
  JEST_TESTS_FUNCTIONAL_PATH,
46
46
  IMPORT_RELATIVE_PATH,
47
- EXPORT_RELATIVE_PATH
47
+ EXPORT_RELATIVE_PATH,
48
+ MAX_RFT_CHARS
48
49
  } from './constants.js';
49
50
 
50
51
 
@@ -2500,7 +2501,7 @@ if (showDebug) addDebugLog("restoreFromArchive", `fileName: ${fileName}, orgLibN
2500
2501
 
2501
2502
 
2502
2503
  // remove temp (windows not working well with "sync", can be async, since as long as deleted, fine)
2503
- fs.rm(tempDirectory, { recursive: true, force: true, maxRetries: 5 }, () => {});
2504
+ fs.rmSync(tempDirectory, { recursive: true, force: true, maxRetries: 5 }, () => {});
2504
2505
 
2505
2506
  };
2506
2507
 
@@ -2712,6 +2713,33 @@ export const getSubTypeLabel = (type, subtype) => {
2712
2713
  return "";
2713
2714
  }
2714
2715
 
2716
+ export const getMaxComponentNameCount = () => {
2717
+ let count = MAX_RFT_CHARS - 1; // one less than max
2718
+ const configDef = getConfigDefaults();
2719
+ const orgLibCount = configDef.currentOrgLib.length + 1;
2720
+ const versionCount = configDef.version.length - 2;
2721
+ const prefixCount = versionCount + 4;
2722
+
2723
+ count = count - orgLibCount - prefixCount - 9; // 9 chars for trailing hash
2724
+
2725
+ return count;
2726
+
2727
+ }
2728
+
2729
+ export const getMaxPrefixCount = () => {
2730
+ // TwoColumnDetails is 16 chars
2731
+ return (getMaxComponentNameCount() - 16);
2732
+ }
2733
+
2734
+ export const isComponentValidLength = (componentKey) => {
2735
+ const configDef = getConfigDefaults();
2736
+ const componentName = componentKey.replace(configDef.currentOrgLib + "_", "");
2737
+ if (componentName.length < getMaxComponentNameCount()) {
2738
+ return true;
2739
+ }
2740
+
2741
+ return false;
2742
+ }
2715
2743
 
2716
2744
  // init
2717
2745
  await forceDefaultsUpdate();