@pega/custom-dx-components 2.0.24 → 2.0.25

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 (122) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -5
  3. package/src/cli.js +0 -18
  4. package/src/constants.js +2 -32
  5. package/src/tasks/authenticate/helper.js +8 -91
  6. package/src/tasks/authenticate/index.js +56 -125
  7. package/src/tasks/create/index.js +63 -59
  8. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
  9. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +16 -33
  10. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +2 -1
  11. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +67 -179
  12. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +17 -46
  13. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +1 -3
  14. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +1 -0
  15. package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js.mustache → date-utils.js} +0 -1
  16. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +0 -1
  17. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +17 -46
  18. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +0 -2
  19. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +17 -22
  20. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +1 -2
  21. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +17 -26
  22. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +4 -3
  23. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +17 -22
  24. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +2 -8
  25. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +17 -22
  26. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +1 -2
  27. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +16 -50
  28. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +1 -44
  29. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
  30. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +16 -23
  31. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +17 -21
  32. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +2 -44
  33. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
  34. package/src/tasks/create/templates/Constellation/Field/Text-Input/{StatusWork.jsx → StatusWork.js} +1 -0
  35. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +17 -21
  36. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +3 -46
  37. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
  38. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +17 -21
  39. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +2 -44
  40. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
  41. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +17 -19
  42. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +3 -47
  43. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
  44. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +17 -19
  45. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +1 -1
  46. package/src/tasks/create/templates/Constellation/Field/Text-URL/{text-url.jsx.mustache → text-url.js.mustache} +1 -2
  47. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +17 -30
  48. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +0 -1
  49. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +29 -14
  50. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +77 -3
  51. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +29 -14
  52. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +74 -3
  53. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +10 -6
  54. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +8 -10
  55. package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.jsx.mustache → GetNextWork.js.mustache} +0 -6
  56. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +7 -9
  57. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +1 -4
  58. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +0 -1
  59. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +8 -8
  60. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.jsx.mustache → Avatar.js.mustache} +0 -2
  61. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.jsx.mustache → Operator.js.mustache} +1 -2
  62. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
  63. package/src/tasks/delete/helper.js +0 -4
  64. package/src/tasks/delete/index.js +0 -4
  65. package/src/tasks/index.js +0 -3
  66. package/src/tasks/init/index.js +3 -3
  67. package/src/tasks/init/template/.eslintrc.json +5 -186
  68. package/src/tasks/init/template/README.md +59 -75
  69. package/src/tasks/init/template/package.json.mustache +6 -21
  70. package/src/tasks/init/template/tasks.config.json +4 -16
  71. package/src/tasks/list/index.js +0 -4
  72. package/src/tasks/{bundle → publish/bundle}/builder/webpack.config.js +2 -0
  73. package/src/tasks/{bundle → publish/bundle}/index.js +2 -2
  74. package/src/tasks/publish/index.js +1 -14
  75. package/src/util.js +6 -11
  76. package/src/auth.js +0 -573
  77. package/src/tasks/build/helper.js +0 -123
  78. package/src/tasks/build/index.js +0 -54
  79. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +0 -21
  80. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +0 -61
  81. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +0 -41
  82. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +0 -23
  83. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +0 -23
  84. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +0 -21
  85. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +0 -23
  86. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +0 -21
  87. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +0 -21
  88. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +0 -67
  89. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +0 -13
  90. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +0 -22
  91. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +0 -21
  92. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +0 -20
  93. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +0 -37
  94. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +0 -22
  95. package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +0 -20
  96. package/src/tasks/create/templates/Constellation/Template/DETAILS/StatusWork.jsx.mustache +0 -26
  97. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +0 -118
  98. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +0 -179
  99. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +0 -26
  100. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +0 -123
  101. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +0 -215
  102. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +0 -93
  103. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +0 -125
  104. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +0 -100
  105. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +0 -131
  106. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +0 -101
  107. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +0 -94
  108. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +0 -78
  109. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +0 -390
  110. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +0 -30
  111. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +0 -23
  112. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +0 -68
  113. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +0 -51
  114. package/src/tasks/delete-all/helper.js +0 -175
  115. package/src/tasks/delete-all/index.js +0 -49
  116. package/src/tasks/init/template/.eslintignore +0 -8
  117. package/src/tasks/linter/index.js +0 -46
  118. package/src/tasks/publish-all/helper.js +0 -139
  119. package/src/tasks/publish-all/index.js +0 -84
  120. /package/src/tasks/{bundle → publish/bundle}/builder/index.js +0 -0
  121. /package/src/tasks/{bundle → publish/bundle}/builder/modules.js +0 -0
  122. /package/src/tasks/{bundle → publish/bundle}/builder/paths.js +0 -0
package/README.md CHANGED
@@ -8,7 +8,7 @@ This project provides you with an environment to extend Constellation by giving
8
8
 
9
9
  Ensure you have access to the following in your system:
10
10
 
11
- - Pega Infinity Server version 8.7 or later
11
+ - Pega Infinity Server version 8.8 or later
12
12
 
13
13
  - Git version 2.30 or later
14
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "2.0.24",
3
+ "version": "2.0.25",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -23,10 +23,8 @@
23
23
  "babel-loader": "^8.2.5",
24
24
  "chalk": "^5.0.1",
25
25
  "compression-webpack-plugin": "^10.0.0",
26
- "crypto": "^1.0.1",
27
26
  "css-loader": "6.7.1",
28
27
  "css-minimizer-webpack-plugin": "^4.1.0",
29
- "eslint": "^8.4.1",
30
28
  "execa": "^6.1.0",
31
29
  "file-loader": "6.2.0",
32
30
  "fs-extra": "^10.1.0",
@@ -37,7 +35,6 @@
37
35
  "mustache": "^4.2.0",
38
36
  "ncp": "^2.0.0",
39
37
  "node-fetch": "^3.2.10",
40
- "open": "^8.4.2",
41
38
  "ora": "^6.1.2",
42
39
  "pascalcase": "^2.0.0",
43
40
  "postcss": "^8.4.16",
@@ -53,7 +50,7 @@
53
50
  "ts-loader": "^9.3.1",
54
51
  "typescript": "^4.8.3",
55
52
  "url-loader": "4.1.1",
56
- "webpack": "5.76.1"
53
+ "webpack": "^5.81.0"
57
54
  },
58
55
  "author": "Custom component dev",
59
56
  "license": "SEE LICENSE IN LICENSE",
@@ -64,6 +61,7 @@
64
61
  "devDependencies": {
65
62
  "@pega/configs": "^0.3.3",
66
63
  "cspell": "^6.9.0",
64
+ "eslint": "^8.23.1",
67
65
  "prettier": "2.7.1"
68
66
  }
69
67
  }
package/src/cli.js CHANGED
@@ -3,14 +3,11 @@ import chalk from 'chalk';
3
3
 
4
4
  import {
5
5
  authenticate,
6
- buildComponent,
7
6
  createComponent,
8
7
  deleteComponent,
9
- deleteAllComponents,
10
8
  initProject,
11
9
  listComponents,
12
10
  publishComponent,
13
- publishAllComponents,
14
11
  updateComponent,
15
12
  validate,
16
13
  upgrade
@@ -19,14 +16,11 @@ import {
19
16
  const TASKS = {
20
17
  INIT: 'init',
21
18
  CREATE: 'create',
22
- BUILD: 'buildComponent',
23
19
  PUBLISH: 'publish',
24
- PUBLISH_All: 'publishAll',
25
20
  LIST: 'list',
26
21
  VALIDATE_SCHEMA: 'validateSchema',
27
22
  UPDATE: 'update',
28
23
  DELETE: 'delete',
29
- DELETE_ALL: "deleteAll",
30
24
  AUTHENTICATE: 'authenticate',
31
25
  UPGRADE: 'upgrade'
32
26
  };
@@ -66,14 +60,6 @@ export default async (args = []) => {
66
60
  publishComponent(options);
67
61
  break;
68
62
  }
69
- case TASKS.PUBLISH_All: {
70
- publishAllComponents(options);
71
- break;
72
- }
73
- case TASKS.BUILD: {
74
- buildComponent(options);
75
- break;
76
- }
77
63
  case TASKS.LIST: {
78
64
  listComponents(options);
79
65
  break;
@@ -90,10 +76,6 @@ export default async (args = []) => {
90
76
  deleteComponent(options);
91
77
  break;
92
78
  }
93
- case TASKS.DELETE_ALL: {
94
- deleteAllComponents(options);
95
- break;
96
- }
97
79
  case TASKS.AUTHENTICATE: {
98
80
  authenticate(options);
99
81
  break;
package/src/constants.js CHANGED
@@ -10,37 +10,7 @@ export const PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/pub
10
10
  export const LIST_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/list_component';
11
11
  export const OOTB_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/ootb_component';
12
12
  export const DELETE_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/delete_component';
13
- export const INF_TOKEN_URL_V1 = 'PRRestService/oauth2/v1/token';
14
- export const INF_AUTHORIZE_URL_V1 = 'PRRestService/oauth2/v1/authorize';
15
- export const LP_TOKEN_URL = 'uas/oauth/token';
16
- export const LP_AUTHORIZE_URL = 'uas/oauth/authorize';
17
-
18
- export const AUTHENTICATE_SCHEMA = {
19
- serverType: [
20
- {
21
- name: 'Infinity',
22
- value: 'infinity'
23
- },
24
- {
25
- name: 'Launchpad',
26
- value: 'launchpad'
27
- }
28
- ],
29
- grantType: [
30
- {
31
- name: 'Authorization code',
32
- value: 'authCode'
33
- },
34
- {
35
- name: 'Password credentials',
36
- value: 'passwordCreds'
37
- },
38
- {
39
- name: 'Client credentials',
40
- value: 'clientCreds'
41
- }
42
- ]
43
- };
13
+ export const TOKEN_URL_V1 = 'PRRestService/oauth2/v1/token';
44
14
 
45
15
  export const COMPONENT_SCHEMA = {
46
16
  framework: [
@@ -138,7 +108,7 @@ export const COMPONENT_SCHEMA = {
138
108
  value: 'Picklist'
139
109
  }
140
110
  ],
141
- template: ['DETAILS', 'DETAILS-region', 'FORM', 'FORM-region', 'PAGE'],
111
+ template: ['DETAILS', 'DETAILS-region', 'FORM', 'FORM-region', 'PAGE' ],
142
112
  widget: [
143
113
  {
144
114
  name: 'CASE',
@@ -1,98 +1,24 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
2
  import { getPegaServerConfig } from '../../util.js';
3
3
 
4
- import { AUTHENTICATE_SCHEMA } from '../../constants.js';
5
-
6
- export const getAuthQuestions = async (dxcbConfig) => {
7
- const defaultPegaConfig = dxcbConfig;
8
- const aMustAsk = dxcbConfig['questions_askAlways'] ? dxcbConfig['questions_askAlways'].split(',') : [];
9
- const aNeverAsk = dxcbConfig['questions_askNever'] ? dxcbConfig['questions_askNever'].split(',') : [];
10
-
11
- const initAnswers = (answers) => {
12
- // Setup default answers (if they are present and non-empty)
13
- answers.serverType = defaultPegaConfig.serverType || "infinity";
14
- answers.server = defaultPegaConfig.server || undefined;
15
- answers.isolationId = defaultPegaConfig.isolationId || undefined;
16
- answers.clientId = defaultPegaConfig.clientId || undefined;
17
- answers.grantType = defaultPegaConfig.grantType || "authCode";
18
- answers.clientSecret = defaultPegaConfig.clientSecret || undefined;
19
- answers.user = defaultPegaConfig.user || undefined;
20
- answers.password = defaultPegaConfig.password || undefined;
21
- };
22
-
23
- const fnStandardWhen = (prop, answers) => {
24
- if (aNeverAsk.includes(prop)) {
25
- return false;
26
- }
27
- return aMustAsk.includes(prop) || !answers[prop];
28
- };
4
+ export const getAuthQuestions = async () => {
5
+ const defaultPegaConfig = await getPegaServerConfig();
29
6
 
30
7
  return [
31
- {
32
- name: 'serverType',
33
- type: 'rawlist',
34
- message: 'Enter Pega server type',
35
- default: answers => {
36
- return defaultPegaConfig.serverType;
37
- },
38
- choices: AUTHENTICATE_SCHEMA.serverType,
39
- validate: value => {
40
- if (value.trim()) {
41
- return true;
42
- }
43
- return 'Pega server type cannot be empty';
44
- },
45
- when: answers => {
46
- initAnswers(answers);
47
- return fnStandardWhen('serverType', answers);
48
- }
49
- },
50
8
  {
51
9
  name: 'server',
52
10
  message: 'Enter pega server url',
53
- default: defaultPegaConfig.server,
54
- when: answers => {
55
- return fnStandardWhen('server', answers);
56
- }
57
- },
58
- {
59
- name: 'isolationId',
60
- message: 'Enter isolation id',
61
- default: defaultPegaConfig.isolationId,
62
- when: answers => {
63
- return answers.serverType === "launchpad" && fnStandardWhen('isolationId', answers);
64
- }
65
- },
66
- {
67
- name: 'grantType',
68
- type: 'rawlist',
69
- message: 'Enter OAuth 2.0 grant type',
70
- default: defaultPegaConfig.grantType,
71
- choices: answers => {
72
- return AUTHENTICATE_SCHEMA.grantType.filter(gt => !(answers.serverType === "launchpad" && gt.value === "passwordCreds"));
73
- },
74
- validate: value => {
75
- if (value.trim()) {
76
- return true;
77
- }
78
- return 'Grant type cannot be empty';
79
- },
80
- when: answers => {
81
- return fnStandardWhen('grantType', answers);
82
- }
11
+ default: defaultPegaConfig.server
83
12
  },
84
13
  {
85
14
  name: 'user',
86
15
  message: 'Enter user id',
87
16
  default: defaultPegaConfig.user,
88
- validate: (value, answers) => {
89
- if (value.trim() || answers.grantType === "authCode") {
17
+ validate: value => {
18
+ if (value.trim()) {
90
19
  return true;
91
20
  }
92
21
  return 'Username cannot be empty';
93
- },
94
- when: answers => {
95
- return (answers.serverType === "infinity" && answers.grantType === "passwordCreds") && fnStandardWhen('user', answers);
96
22
  }
97
23
  },
98
24
  {
@@ -100,14 +26,11 @@ export const getAuthQuestions = async (dxcbConfig) => {
100
26
  type: 'password',
101
27
  message: 'Enter password',
102
28
  default: defaultPegaConfig.password,
103
- validate: (value, answers) => {
104
- if (value.trim() || answers.grantType === "authCode") {
29
+ validate: value => {
30
+ if (value.trim()) {
105
31
  return true;
106
32
  }
107
33
  return 'Password cannot be empty';
108
- },
109
- when: answers => {
110
- return (answers.user && (answers.serverType === "infinity" && answers.grantType === "passwordCreds") && fnStandardWhen('password', answers));
111
34
  }
112
35
  },
113
36
  {
@@ -119,9 +42,6 @@ export const getAuthQuestions = async (dxcbConfig) => {
119
42
  return true;
120
43
  }
121
44
  return 'clientId cannot be empty';
122
- },
123
- when: answers => {
124
- return fnStandardWhen('clientId', answers);
125
45
  }
126
46
  },
127
47
  {
@@ -129,14 +49,11 @@ export const getAuthQuestions = async (dxcbConfig) => {
129
49
  type: 'password',
130
50
  message: 'Enter clientSecret',
131
51
  default: defaultPegaConfig.clientSecret,
132
- validate: (value, answers) => {
52
+ validate: value => {
133
53
  if (value.trim()) {
134
54
  return true;
135
55
  }
136
56
  return 'clientSecret cannot be empty';
137
- },
138
- when: answers => {
139
- return (answers.grantType !== "authCode" && fnStandardWhen('clientSecret', answers));
140
57
  }
141
58
  }
142
59
  ];
@@ -1,150 +1,81 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
+ import https from 'https';
3
4
 
4
5
  import chalk from 'chalk';
5
6
  import inquirer from 'inquirer';
7
+ import fetch from 'node-fetch';
6
8
 
7
- import { checkPathAccess, showVersion } from '../../util.js';
8
- import { TOKEN_PATH, INF_TOKEN_URL_V1, INF_AUTHORIZE_URL_V1, LP_TOKEN_URL, LP_AUTHORIZE_URL } from '../../constants.js';
9
+ import { checkPathAccess, getTokenUrl } from '../../util.js';
10
+ import { TOKEN_PATH } from '../../constants.js';
9
11
 
10
12
  import { getAuthQuestions } from './helper.js';
11
- import PegaAuth from '../../auth.js';
12
13
 
13
14
  export const TASKS_CONFIG_JSON_FILENAME = 'tasks.config.json';
14
15
 
15
16
  const pegaConfigJsonPath = path.join(path.resolve(), TASKS_CONFIG_JSON_FILENAME);
16
- let server = null;
17
17
 
18
18
  const generateAccessToken = async config => {
19
-
20
- let authSuccess = false;
21
- const { serverType, isolationId, grantType, clientId, clientSecret, user, password } = config;
22
- const server = config.server.endsWith('/') ? config.server : `${config.server}/`;
23
-
24
- return new Promise((resolve, reject) => {
25
- const sTokenUri = `${server}${serverType === 'infinity' ? INF_TOKEN_URL_V1 : LP_TOKEN_URL}`;
26
- const sAuthorizeUri = `${server}${serverType === 'infinity' ? INF_AUTHORIZE_URL_V1 : LP_AUTHORIZE_URL}`;
27
- // console.log(`grantType: ${config.grantType}`);
28
-
29
- const authCodeConfig = grantType === 'authCode' ? {
30
- authorizeUri: sAuthorizeUri,
31
- redirectUri: config.redirectUri.endsWith('/') ? config.redirectUri : `${config.redirectUri}/`,
32
- cert: config.cert,
33
- key: config.key,
34
- winTitle: 'DX Component Dev',
35
- winBodyHtml: `Authentication is complete. This browser window may be closed.`
36
- } : {};
37
-
38
- // Build auth config structure
39
- const authConfig = {
40
- serverType: serverType,
41
- grantType: grantType,
42
- tokenUri: sTokenUri,
43
- clientId: clientId,
44
- clientSecret: clientSecret,
45
- ignoreInvalidCerts: true,
46
- ...authCodeConfig
47
- };
48
- if (serverType === 'infinity') {
49
- authConfig.authService = 'pega';
50
- if (grantType !== 'clientCreds' && user && password) {
51
- authConfig.userIdentifier = user;
52
- authConfig.password = Buffer.from(password).toString('base64');
19
+ const formData = new URLSearchParams();
20
+ formData.append('client_id', config.clientId);
21
+ formData.append('client_secret', config.clientSecret);
22
+ formData.append('username', config.user);
23
+ formData.append('password', config.password);
24
+ formData.append('grant_type', 'password');
25
+
26
+ const accessTokenUri = await getTokenUrl(config.server);
27
+ fetch(accessTokenUri, {
28
+ agent: new https.Agent({ rejectUnauthorized: false }),
29
+ method: 'POST',
30
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
31
+ body: formData.toString()
32
+ })
33
+ .then(response => {
34
+ if (response.ok && response.status === 200) {
35
+ return response.json();
36
+ } else {
37
+ throw new Error(`Failed with status: ${response.status}`);
53
38
  }
54
- }
55
- if (serverType === 'launchpad') {
56
- authConfig.isolationId = isolationId;
57
- // authConfig.noPKCE = true;
58
- }
59
- const auth = new PegaAuth(authConfig);
60
- // console.log(`...about to invoke auth.login\n${JSON.stringify(authConfig)}`);
61
-
62
- auth.login()
63
- .then((token) => {
64
- if (token?.token_type) {
65
- fs.writeFile(TOKEN_PATH, JSON.stringify(token), err => {
66
- if (err) {
67
- console.error(err);
68
- return reject(authSuccess);
69
- }
70
- console.log(`${chalk.bold.green('Authenticated successfully !!')}`);
71
- authSuccess = true;
72
- return resolve(authSuccess);
73
- });
74
- } else {
75
- console.log(`${chalk.bold.red('Authentication failed:' + JSON.stringify(token.errors ? token.errors : token))}`);
76
- return reject(authSuccess);
77
- }
78
- })
79
- .catch((e) => {
80
- console.log(`${chalk.bold.red(e)}`);
81
- return reject(authSuccess);
82
- });
83
- });
39
+ })
40
+ .then(data => {
41
+ if (data && data.errors) {
42
+ const errMessages = data.errors;
43
+ errMessages.forEach(msgArr => {
44
+ throw new Error(`Failed with error - ${JSON.stringify(msgArr.message)}`);
45
+ });
46
+ }
47
+ if (data.token_type) {
48
+ fs.writeFile(TOKEN_PATH, JSON.stringify(data), err => {
49
+ if (err) {
50
+ console.error(err);
51
+ }
52
+ console.log(`${chalk.bold.green('Authenticated successfully !!')}`);
53
+ });
54
+ }
55
+ })
56
+ .catch(e => console.log(`${chalk.bold.red(e)}`));
84
57
  };
85
58
 
86
59
  export default async options => {
87
-
88
- let authOK = false;
89
-
90
- showVersion();
91
-
92
60
  await checkPathAccess(pegaConfigJsonPath);
93
61
 
94
- let cfgData = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
95
- let data = null;
96
- if (cfgData) {
97
- try {
98
- data = JSON.parse(cfgData);
99
- } catch (e) {
100
- console.log(`${chalk.red('Invalid JSON within tasks.config.json')}`);
101
- process.exit(1);
102
- }
103
- }
62
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
63
+ data = data && JSON.parse(data);
104
64
 
105
65
  const serverConfig = data['server-config'];
106
- const isPwdNonEmpty = serverConfig['password'] ? true : false;
66
+ const params = options.params;
107
67
 
108
- // console.log(`serverConfig: ${JSON.stringify(serverConfig)}`);
109
- const questions = await getAuthQuestions(serverConfig);
110
- // console.log(`questions: ${JSON.stringify(questions)}`);
68
+ const questions = await getAuthQuestions(params);
111
69
  const answers = await inquirer.prompt(questions);
112
- const aProps = ['serverType', 'server', 'isolationId', 'clientId', 'grantType', 'clientSecret', 'user', 'password'];
113
- const isLaunchPad = answers.serverType === "launchpad";
114
- let bWriteUpdate = false;
115
- for (let i = 0; i < aProps.length; i += 1) {
116
- const prop = aProps[i];
117
- if (serverConfig[prop] !== answers[prop]) {
118
- // console.log(`property ${prop} changed from ${serverConfig[prop]} to ${answers[prop]}`);
119
- serverConfig[prop] = answers[prop];
120
- if (prop !== 'password' || isPwdNonEmpty) {
121
- bWriteUpdate = true;
122
- }
123
- }
124
- }
125
-
126
- try {
127
- // console.log(`serverConfig: ${JSON.stringify(serverConfig)}`);
128
- authOK = await generateAccessToken(serverConfig);
129
- } catch (e) {
130
- }
131
-
132
- if (authOK & bWriteUpdate) {
133
- // Don't write password value (unless it already had a value)
134
- if (!isPwdNonEmpty) {
135
- serverConfig['password'] = '';
136
- }
137
- console.log(`${chalk.green('Writing updated config...')}`);
138
- let updCfg = null;
139
- try {
140
- updCfg = JSON.stringify(data, null, 2);
141
- fs.writeFileSync(pegaConfigJsonPath, updCfg, err => {
142
- if (err) throw err;
143
- });
144
- } catch (e) {
145
-
146
- }
147
- }
148
-
149
- process.exit(1);
70
+ serverConfig.server = answers.server;
71
+ serverConfig.user = answers.user;
72
+ serverConfig.password = answers.password;
73
+ serverConfig.clientId = answers.clientId;
74
+ serverConfig.clientSecret = answers.clientSecret;
75
+ await generateAccessToken(serverConfig);
76
+
77
+ data = JSON.stringify(data, null, 2);
78
+ fs.writeFile(pegaConfigJsonPath, data, err => {
79
+ if (err) throw err;
80
+ });
150
81
  };
@@ -14,8 +14,7 @@ import {
14
14
  getComponents,
15
15
  getComponentDefaults,
16
16
  sanitize,
17
- validateSemver,
18
- showVersion
17
+ validateSemver
19
18
  } from '../../util.js';
20
19
  import { COMPONENT_SCHEMA } from '../../constants.js';
21
20
 
@@ -88,7 +87,7 @@ const compileMustacheTemplates = async (
88
87
  ALLOWEDAPPS: JSON.stringify(allowedApplications),
89
88
  TYPE: type,
90
89
  SUB_TYPE: JSON.stringify(mustacheSubType),
91
- DESCRIPTION: description || componentLabel,
90
+ DESCRIPTION: description,
92
91
  IS_TEMPLATE: isTemplate,
93
92
  IS_PICKLIST: isPicklist,
94
93
  IS_BOOLEAN: isBool,
@@ -173,17 +172,15 @@ const validateCompile = async (
173
172
  };
174
173
 
175
174
  export default async options => {
176
- showVersion();
177
-
178
- if (options.params[9]) {
179
-
180
- const type = options.params[3];
181
- const subtype = options.params[4];
182
- const componentName = options.params[5];
183
- const componentLabel = options.params[6];
184
- const library = options.params[7];
185
- const version = options.params[9];
186
- const description = options.params[9];
175
+ if (options.params[10]) {
176
+ const componentName = options.params[3];
177
+ const componentLabel = options.params[4];
178
+ const library = options.params[5];
179
+ const version = options.params[6];
180
+ const framework = options.params[7];
181
+ const type = options.params[8];
182
+ const subtype = options.params[9];
183
+ const description = options.params[10];
187
184
 
188
185
  await validateCompile(
189
186
  {
@@ -201,50 +198,6 @@ export default async options => {
201
198
  } else {
202
199
  const componentDefaults = await getComponentDefaults();
203
200
  const questions = [
204
- {
205
- name: 'type',
206
- type: 'rawlist',
207
- message: 'Enter type of component',
208
- default: componentDefaults.type,
209
- choices: COMPONENT_SCHEMA.type
210
- },
211
- {
212
- name: 'subtype',
213
- type: 'rawlist',
214
- message: 'Enter subtype of component',
215
- default: componentDefaults.subtype,
216
- choices: COMPONENT_SCHEMA.subtype.field,
217
- when(answers) {
218
- return answers.type === 'Field';
219
- }
220
- },
221
- {
222
- name: 'subtype',
223
- type: 'rawlist',
224
- message: 'Enter subtype of component',
225
- default: componentDefaults.subtype,
226
- choices: COMPONENT_SCHEMA.subtype.template,
227
- when(answers) {
228
- return answers.type === 'Template';
229
- }
230
- },
231
- {
232
- name: 'subtype',
233
- type: 'rawlist',
234
- message: 'Enter subtype of component',
235
- default: [componentDefaults.subtype || COMPONENT_SCHEMA.subtype.widget[0]],
236
- choices: COMPONENT_SCHEMA.subtype.widget,
237
- when(answers) {
238
- return answers.type === 'Widget';
239
- },
240
- validate: value => {
241
- /* value should not be empty */
242
- if (Array.isArray(value) && value.length) {
243
- return true;
244
- }
245
- return 'Please select subtype';
246
- }
247
- },
248
201
  {
249
202
  name: 'componentName',
250
203
  message: 'Enter component name (required)',
@@ -273,7 +226,6 @@ export default async options => {
273
226
  {
274
227
  name: 'version',
275
228
  message: 'Enter component version',
276
- default: componentDefaults.version,
277
229
  validate: value => {
278
230
  if (validateSemver(value)) {
279
231
  return true;
@@ -302,6 +254,57 @@ export default async options => {
302
254
  message: 'Please enter the application names to be supported (comma-separated). ',
303
255
  suffix: 'Keep empty for all applications'
304
256
  },
257
+ // {
258
+ // name: 'framework',
259
+ // type: 'rawlist',
260
+ // message: 'Enter framework a',
261
+ // default: 'COSMOS_React',
262
+ // choices: COMPONENT_SCHEMA.framework
263
+ // },
264
+ {
265
+ name: 'type',
266
+ type: 'rawlist',
267
+ message: 'Enter type of component',
268
+ default: componentDefaults.type,
269
+ choices: COMPONENT_SCHEMA.type
270
+ },
271
+ {
272
+ name: 'subtype',
273
+ type: 'rawlist',
274
+ message: 'Enter subtype of component',
275
+ default: componentDefaults.subtype,
276
+ choices: COMPONENT_SCHEMA.subtype.field,
277
+ when(answers) {
278
+ return answers.type === 'Field';
279
+ }
280
+ },
281
+ {
282
+ name: 'subtype',
283
+ type: 'rawlist',
284
+ message: 'Enter subtype of component',
285
+ default: componentDefaults.subtype,
286
+ choices: COMPONENT_SCHEMA.subtype.template,
287
+ when(answers) {
288
+ return answers.type === 'Template';
289
+ }
290
+ },
291
+ {
292
+ name: 'subtype',
293
+ type: 'rawlist',
294
+ message: 'Enter subtype of component',
295
+ default: [componentDefaults.subtype || COMPONENT_SCHEMA.subtype.widget[0]],
296
+ choices: COMPONENT_SCHEMA.subtype.widget,
297
+ when(answers) {
298
+ return answers.type === 'Widget';
299
+ },
300
+ validate: value => {
301
+ /* value should not be empty */
302
+ if (Array.isArray(value) && value.length) {
303
+ return true;
304
+ }
305
+ return 'Please select subtype';
306
+ }
307
+ },
305
308
  {
306
309
  name: 'description',
307
310
  message: 'Enter description for the component',
@@ -309,6 +312,7 @@ export default async options => {
309
312
  }
310
313
  ];
311
314
 
315
+ console.log(chalk.green("DX Component Builder v2.0.16"));
312
316
  await inquirer.prompt(questions).then(async answers => {
313
317
  const {
314
318
  componentName,