@pega/custom-dx-components 2.0.23 → 8.5.1
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 +1 -2
- package/src/auth.js +20 -10
- package/src/cli.js +18 -0
- package/src/constants.js +35 -1
- package/src/tasks/authenticate/helper.js +39 -14
- package/src/tasks/authenticate/index.js +101 -48
- package/src/tasks/build/helper.js +3 -3
- package/src/tasks/build-all/helper.js +69 -0
- package/src/tasks/build-all/index.js +79 -0
- package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text/config.json.mustache +14 -0
- package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Field/TimeofDay/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +4 -1
- package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +1 -1
- package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +1 -1
- package/src/tasks/create-all/index.js +400 -0
- package/src/tasks/index.js +3 -0
- package/src/tasks/init/template/package.json.mustache +5 -2
- package/src/tasks/init/template/tasks.config.json +15 -6
- package/src/tasks/list/helper.js +19 -6
- package/src/tasks/publish/helper.js +3 -3
- package/src/tasks/publish-all/helper.js +20 -6
- package/src/tasks/publish-all/index.js +29 -18
- package/src/tasks/rename/index.js +315 -0
- package/src/tasks/validator/index.js +182 -7
- package/src/util.js +66 -3
- package/src/tasks/create/template/config.json.mustache +0 -62
- package/src/tasks/create/template/demo.stories.jsx.mustache +0 -44
- package/src/tasks/create/template/index.jsx.mustache +0 -55
- package/src/tasks/create/template/styles.js.mustache +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pega/custom-dx-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"description": "Utility for building custom UI components",
|
|
5
5
|
"bin": "./bin/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"file-loader": "6.2.0",
|
|
32
32
|
"fs-extra": "^10.1.0",
|
|
33
33
|
"gitignore": "^0.7.0",
|
|
34
|
-
"http": "^0.0.1-security",
|
|
35
34
|
"inquirer": "^9.1.1",
|
|
36
35
|
"listr": "^0.14.3",
|
|
37
36
|
"mini-css-extract-plugin": "2.6.1",
|
package/src/auth.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import fetch from 'node-fetch';
|
|
5
5
|
import open from 'open';
|
|
6
|
-
import crypto from 'crypto';
|
|
7
|
-
import
|
|
6
|
+
import crypto from 'node:crypto';
|
|
7
|
+
import https from 'node:https';
|
|
8
|
+
import http from 'node:http';
|
|
9
|
+
import fs from 'node:fs';
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class PegaAuth {
|
|
@@ -56,8 +58,8 @@ class PegaAuth {
|
|
|
56
58
|
|
|
57
59
|
// For PKCE the authorize includes a code_challenge & code_challenge_method as well
|
|
58
60
|
async #buildAuthorizeUrl(state) {
|
|
59
|
-
const { serverType, clientId, redirectUri, authorizeUri, authService, sessionIndex, appAlias,
|
|
60
|
-
this.config;
|
|
61
|
+
const { serverType, clientId, redirectUri, authorizeUri, authService, sessionIndex, appAlias,
|
|
62
|
+
userIdentifier, password, noPKCE, isolationId } = this.config;
|
|
61
63
|
|
|
62
64
|
if (!noPKCE) {
|
|
63
65
|
// Generate random string of 64 chars for verifier. RFC 7636 says from 43-128 chars
|
|
@@ -91,7 +93,7 @@ class PegaAuth {
|
|
|
91
93
|
(sessionIndex && this.config.sessionIndexAttempts < 3 ? `&session_index=${sessionIndex}` : '') +
|
|
92
94
|
(userIdentifier
|
|
93
95
|
? `&UserIdentifier=${encodeURIComponent(userIdentifier)}${password ? `&Password=${encodeURIComponent(this.#atob(password))}` : ''}` : '')
|
|
94
|
-
:
|
|
96
|
+
: `&isolationID=${isolationId}`);
|
|
95
97
|
|
|
96
98
|
let pkceArgs = '';
|
|
97
99
|
if (!noPKCE) {
|
|
@@ -277,12 +279,17 @@ class PegaAuth {
|
|
|
277
279
|
} else {
|
|
278
280
|
if (this.isNode) {
|
|
279
281
|
// Determine port to listen to by extracting it from redirect uri
|
|
280
|
-
const { redirectUri } = this.config;
|
|
282
|
+
const { redirectUri, cert, key } = this.config;
|
|
283
|
+
const isHttp = redirectUri.startsWith('http:');
|
|
281
284
|
const nLocalhost = redirectUri.indexOf("localhost:");
|
|
282
285
|
const nSlash = redirectUri.indexOf('/', nLocalhost + 10);
|
|
283
286
|
const nPort = parseInt(redirectUri.substring(nLocalhost + 10, nSlash));
|
|
284
287
|
if (-1 !== nLocalhost) {
|
|
285
|
-
const
|
|
288
|
+
const options = key && cert && !isHttp ? {
|
|
289
|
+
key: fs.readFileSync(key),
|
|
290
|
+
cert: fs.readFileSync(cert)
|
|
291
|
+
} : {};
|
|
292
|
+
const server = (isHttp ? http : https).createServer(options, (req, res) => {
|
|
286
293
|
const { method, url } = req;
|
|
287
294
|
const { winTitle, winBodyHtml } = this.config;
|
|
288
295
|
// console.log(`HTTP request received: ${url}`);
|
|
@@ -331,7 +338,7 @@ class PegaAuth {
|
|
|
331
338
|
this.#reloadConfig();
|
|
332
339
|
|
|
333
340
|
const { serverType, isolationId, clientId, clientSecret, redirectUri, tokenUri, codeVerifier, grantType,
|
|
334
|
-
sessionIndex, customTokenParams, userIdentifier, password, noPKCE } = this.config;
|
|
341
|
+
sessionIndex, customTokenParams, userIdentifier, password, noPKCE, ignoreInvalidCerts } = this.config;
|
|
335
342
|
|
|
336
343
|
const bAuthCode = !grantType || grantType === 'authCode';
|
|
337
344
|
if (bAuthCode && !authCode && !this.isNode) {
|
|
@@ -378,6 +385,7 @@ class PegaAuth {
|
|
|
378
385
|
// console.log(`getToken form data: ${formData.toString()}`);
|
|
379
386
|
|
|
380
387
|
return fetch(tokenUri, {
|
|
388
|
+
agent: this.isNode && ignoreInvalidCerts ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
|
381
389
|
method: 'POST',
|
|
382
390
|
headers: new Headers({
|
|
383
391
|
'content-type': 'application/x-www-form-urlencoded'
|
|
@@ -418,7 +426,7 @@ class PegaAuth {
|
|
|
418
426
|
|
|
419
427
|
/* eslint-disable camelcase */
|
|
420
428
|
async refreshToken(refresh_token) {
|
|
421
|
-
const { clientId, clientSecret, tokenUri } = this.config;
|
|
429
|
+
const { clientId, clientSecret, tokenUri, ignoreInvalidCerts } = this.config;
|
|
422
430
|
|
|
423
431
|
const formData = new URLSearchParams();
|
|
424
432
|
formData.append('client_id', clientId);
|
|
@@ -429,6 +437,7 @@ class PegaAuth {
|
|
|
429
437
|
formData.append('refresh_token', refresh_token);
|
|
430
438
|
|
|
431
439
|
return fetch(tokenUri, {
|
|
440
|
+
agent: this.isNode && ignoreInvalidCerts ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
|
432
441
|
method: 'POST',
|
|
433
442
|
headers: new Headers({
|
|
434
443
|
'content-type': 'application/x-www-form-urlencoded'
|
|
@@ -460,7 +469,7 @@ class PegaAuth {
|
|
|
460
469
|
// Must have a config structure to proceed
|
|
461
470
|
return;
|
|
462
471
|
}
|
|
463
|
-
const { clientId, clientSecret, revokeUri } = this.config;
|
|
472
|
+
const { clientId, clientSecret, revokeUri, ignoreInvalidCerts } = this.config;
|
|
464
473
|
|
|
465
474
|
let hdrs = { 'content-type': 'application/x-www-form-urlencoded' };
|
|
466
475
|
if (clientSecret) {
|
|
@@ -478,6 +487,7 @@ class PegaAuth {
|
|
|
478
487
|
formData.append('token', prop === 'access_token' ? access_token : refresh_token);
|
|
479
488
|
formData.append('token_type_hint', prop);
|
|
480
489
|
fetch(revokeUri, {
|
|
490
|
+
agent: this.isNode && ignoreInvalidCerts ? new https.Agent({ rejectUnauthorized: false }) : undefined,
|
|
481
491
|
method: 'POST',
|
|
482
492
|
headers: new Headers(hdrs),
|
|
483
493
|
body: formData.toString()
|
package/src/cli.js
CHANGED
|
@@ -4,13 +4,16 @@ import chalk from 'chalk';
|
|
|
4
4
|
import {
|
|
5
5
|
authenticate,
|
|
6
6
|
buildComponent,
|
|
7
|
+
buildAllComponents,
|
|
7
8
|
createComponent,
|
|
9
|
+
createAllComponents,
|
|
8
10
|
deleteComponent,
|
|
9
11
|
deleteAllComponents,
|
|
10
12
|
initProject,
|
|
11
13
|
listComponents,
|
|
12
14
|
publishComponent,
|
|
13
15
|
publishAllComponents,
|
|
16
|
+
renameComponent,
|
|
14
17
|
updateComponent,
|
|
15
18
|
validate,
|
|
16
19
|
upgrade
|
|
@@ -19,9 +22,12 @@ import {
|
|
|
19
22
|
const TASKS = {
|
|
20
23
|
INIT: 'init',
|
|
21
24
|
CREATE: 'create',
|
|
25
|
+
CREATE_ALL: 'createAll',
|
|
22
26
|
BUILD: 'buildComponent',
|
|
27
|
+
BUILD_ALL: 'buildAllComponents',
|
|
23
28
|
PUBLISH: 'publish',
|
|
24
29
|
PUBLISH_All: 'publishAll',
|
|
30
|
+
RENAME: 'rename',
|
|
25
31
|
LIST: 'list',
|
|
26
32
|
VALIDATE_SCHEMA: 'validateSchema',
|
|
27
33
|
UPDATE: 'update',
|
|
@@ -62,6 +68,10 @@ export default async (args = []) => {
|
|
|
62
68
|
createComponent(options);
|
|
63
69
|
break;
|
|
64
70
|
}
|
|
71
|
+
case TASKS.CREATE_ALL: {
|
|
72
|
+
createAllComponents(options);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
65
75
|
case TASKS.PUBLISH: {
|
|
66
76
|
publishComponent(options);
|
|
67
77
|
break;
|
|
@@ -70,10 +80,18 @@ export default async (args = []) => {
|
|
|
70
80
|
publishAllComponents(options);
|
|
71
81
|
break;
|
|
72
82
|
}
|
|
83
|
+
case TASKS.RENAME: {
|
|
84
|
+
renameComponent(options);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
73
87
|
case TASKS.BUILD: {
|
|
74
88
|
buildComponent(options);
|
|
75
89
|
break;
|
|
76
90
|
}
|
|
91
|
+
case TASKS.BUILD_ALL: {
|
|
92
|
+
buildAllComponents(options);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
77
95
|
case TASKS.LIST: {
|
|
78
96
|
listComponents(options);
|
|
79
97
|
break;
|
package/src/constants.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export const TASKS_CONFIG_JSON_FILENAME = 'tasks.config.json';
|
|
3
3
|
export const BUILD_CONFIG_JSON_FILENAME = 'build.config.json';
|
|
4
4
|
export const COMPONENTS_DIRECTORY_PATH = 'components-directory-path';
|
|
5
|
+
export const COMPONENTS_PATH = 'component'
|
|
5
6
|
export const TOKEN_PATH = 'node_modules/@pega/custom-dx-components/.access_token';
|
|
6
7
|
export const OOTB_COMPONENTS = 'node_modules/@pega/custom-dx-components/.ootb_components';
|
|
7
8
|
|
|
@@ -14,6 +15,18 @@ export const INF_TOKEN_URL_V1 = 'PRRestService/oauth2/v1/token';
|
|
|
14
15
|
export const INF_AUTHORIZE_URL_V1 = 'PRRestService/oauth2/v1/authorize';
|
|
15
16
|
export const LP_TOKEN_URL = 'uas/oauth/token';
|
|
16
17
|
export const LP_AUTHORIZE_URL = 'uas/oauth/authorize';
|
|
18
|
+
export const LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT = 'pegalaunchpad/c11n/v103/app/appstudiox/componentslist';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export const FIELD_PATH = '/field';
|
|
22
|
+
export const TEMPLATE_PATH = '/template';
|
|
23
|
+
export const WIDGET_PATH = '/widget';
|
|
24
|
+
|
|
25
|
+
export const COMPONENT_PREFIX_FIELD_PATH = "field/";
|
|
26
|
+
export const COMPONENT_PREFIX_TEMPLATE_PATH = "template/";
|
|
27
|
+
export const COMPONENT_PREFIX_WIDGET_PATH = "widget/";
|
|
28
|
+
|
|
29
|
+
export const CATEGORY_CONSTELLATION = "constellation";
|
|
17
30
|
|
|
18
31
|
export const AUTHENTICATE_SCHEMA = {
|
|
19
32
|
serverType: [
|
|
@@ -138,7 +151,28 @@ export const COMPONENT_SCHEMA = {
|
|
|
138
151
|
value: 'Picklist'
|
|
139
152
|
}
|
|
140
153
|
],
|
|
141
|
-
template: [
|
|
154
|
+
template: [
|
|
155
|
+
{
|
|
156
|
+
name: 'DETAILS',
|
|
157
|
+
value: 'DETAILS'
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: 'DETAILS region',
|
|
161
|
+
value: 'DETAILS-region'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'FORM',
|
|
165
|
+
value: 'FORM'
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'FORM region',
|
|
169
|
+
value: 'FORM-region'
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: 'PAGE',
|
|
173
|
+
value: 'PAGE'
|
|
174
|
+
}
|
|
175
|
+
],
|
|
142
176
|
widget: [
|
|
143
177
|
{
|
|
144
178
|
name: 'CASE',
|
|
@@ -3,8 +3,29 @@ import { getPegaServerConfig } from '../../util.js';
|
|
|
3
3
|
|
|
4
4
|
import { AUTHENTICATE_SCHEMA } from '../../constants.js';
|
|
5
5
|
|
|
6
|
-
export const getAuthQuestions = async () => {
|
|
7
|
-
const defaultPegaConfig =
|
|
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
|
+
};
|
|
8
29
|
|
|
9
30
|
return [
|
|
10
31
|
{
|
|
@@ -22,26 +43,24 @@ export const getAuthQuestions = async () => {
|
|
|
22
43
|
return 'Pega server type cannot be empty';
|
|
23
44
|
},
|
|
24
45
|
when: answers => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
else if (!defaultPegaConfig.askServerType) {
|
|
29
|
-
answers.serverType = defaultPegaConfig.serverType;
|
|
30
|
-
}
|
|
31
|
-
return (defaultPegaConfig.askServerType ? true : false);
|
|
46
|
+
initAnswers(answers);
|
|
47
|
+
return fnStandardWhen('serverType', answers);
|
|
32
48
|
}
|
|
33
49
|
},
|
|
34
50
|
{
|
|
35
51
|
name: 'server',
|
|
36
52
|
message: 'Enter pega server url',
|
|
37
|
-
default: defaultPegaConfig.server
|
|
53
|
+
default: defaultPegaConfig.server,
|
|
54
|
+
when: answers => {
|
|
55
|
+
return fnStandardWhen('server', answers);
|
|
56
|
+
}
|
|
38
57
|
},
|
|
39
58
|
{
|
|
40
59
|
name: 'isolationId',
|
|
41
60
|
message: 'Enter isolation id',
|
|
42
61
|
default: defaultPegaConfig.isolationId,
|
|
43
62
|
when: answers => {
|
|
44
|
-
return answers.serverType === "launchpad";
|
|
63
|
+
return answers.serverType === "launchpad" && fnStandardWhen('isolationId', answers);
|
|
45
64
|
}
|
|
46
65
|
},
|
|
47
66
|
{
|
|
@@ -57,6 +76,9 @@ export const getAuthQuestions = async () => {
|
|
|
57
76
|
return true;
|
|
58
77
|
}
|
|
59
78
|
return 'Grant type cannot be empty';
|
|
79
|
+
},
|
|
80
|
+
when: answers => {
|
|
81
|
+
return fnStandardWhen('grantType', answers);
|
|
60
82
|
}
|
|
61
83
|
},
|
|
62
84
|
{
|
|
@@ -70,7 +92,7 @@ export const getAuthQuestions = async () => {
|
|
|
70
92
|
return 'Username cannot be empty';
|
|
71
93
|
},
|
|
72
94
|
when: answers => {
|
|
73
|
-
return (answers.serverType === "infinity" && answers.grantType
|
|
95
|
+
return (answers.serverType === "infinity" && answers.grantType === "passwordCreds") && fnStandardWhen('user', answers);
|
|
74
96
|
}
|
|
75
97
|
},
|
|
76
98
|
{
|
|
@@ -85,7 +107,7 @@ export const getAuthQuestions = async () => {
|
|
|
85
107
|
return 'Password cannot be empty';
|
|
86
108
|
},
|
|
87
109
|
when: answers => {
|
|
88
|
-
return (answers.user && (answers.serverType === "infinity" && answers.grantType
|
|
110
|
+
return (answers.user && (answers.serverType === "infinity" && answers.grantType === "passwordCreds") && fnStandardWhen('password', answers));
|
|
89
111
|
}
|
|
90
112
|
},
|
|
91
113
|
{
|
|
@@ -97,6 +119,9 @@ export const getAuthQuestions = async () => {
|
|
|
97
119
|
return true;
|
|
98
120
|
}
|
|
99
121
|
return 'clientId cannot be empty';
|
|
122
|
+
},
|
|
123
|
+
when: answers => {
|
|
124
|
+
return fnStandardWhen('clientId', answers);
|
|
100
125
|
}
|
|
101
126
|
},
|
|
102
127
|
{
|
|
@@ -111,7 +136,7 @@ export const getAuthQuestions = async () => {
|
|
|
111
136
|
return 'clientSecret cannot be empty';
|
|
112
137
|
},
|
|
113
138
|
when: answers => {
|
|
114
|
-
return (answers.grantType !== "authCode");
|
|
139
|
+
return (answers.grantType !== "authCode" && fnStandardWhen('clientSecret', answers));
|
|
115
140
|
}
|
|
116
141
|
}
|
|
117
142
|
];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
3
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import inquirer from 'inquirer';
|
|
@@ -18,27 +18,59 @@ let server = null;
|
|
|
18
18
|
const generateAccessToken = async config => {
|
|
19
19
|
|
|
20
20
|
let authSuccess = false;
|
|
21
|
-
const { serverType, isolationId, grantType, clientId, clientSecret, user, password } = config;
|
|
21
|
+
const { serverType, authService, isolationId, grantType, clientId, clientSecret, user, password } = config;
|
|
22
|
+
// Try to gracefully deal with missing trailing slashes for server (and later conditionally for redirectUri)
|
|
22
23
|
const server = config.server.endsWith('/') ? config.server : `${config.server}/`;
|
|
23
24
|
|
|
24
25
|
return new Promise((resolve, reject) => {
|
|
25
26
|
const sTokenUri = `${server}${serverType === 'infinity' ? INF_TOKEN_URL_V1 : LP_TOKEN_URL}`;
|
|
26
27
|
const sAuthorizeUri = `${server}${serverType === 'infinity' ? INF_AUTHORIZE_URL_V1 : LP_AUTHORIZE_URL}`;
|
|
27
28
|
// console.log(`grantType: ${config.grantType}`);
|
|
29
|
+
const browserAuthSuccessMarkup = `<div style="width: 300px; padding: 10px;">
|
|
30
|
+
<svg xmlns="http://www. w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 311 68" version="1.1">
|
|
31
|
+
<title>Logo</title>
|
|
32
|
+
<defs/>
|
|
33
|
+
<g id="Symbols" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
34
|
+
<g id="Logo">
|
|
35
|
+
<g id="pega_logo_horizontal_positive_rgb">
|
|
36
|
+
<path d="M136.36,17.098 L136.173,17.009 C136.154,16.998 133.96,16.01 132.245,17.815 L132.026,18.046 L135.539,19.768 L136.36,17.098 Z M152.441,36.389 C152.441,36.389 150.91,39.13 150.224,40.143 C149.535,41.164 147.38,41.798 145.517,40.908 C144.665,40.503 136.694,35.854 133.644,36.12 C118.205,37.466 113.999,31.105 113.503,30.527 C113.005,29.949 112.077,30.218 112.74,31.355 C116.127,37.163 126.15,39.856 126.15,39.856 C128.771,46.172 129.085,50.597 129.085,50.597 C126.489,48.574 123.687,46.869 120.714,45.453 C112.768,40.121 100.329,33.518 83.207,29.379 C84.191,15.797 91.044,-3.837 123.092,0.806 C123.092,0.806 129.522,1.86 133.809,4.824 C133.809,4.824 132.779,5.904 131.425,7.256 C130.071,8.605 131.569,9.471 131.569,9.471 L138.338,14.792 C138.417,17.607 138.533,18.396 140.651,20.944 C142.769,23.487 151.004,32.112 152.081,33.266 C153.329,34.6 152.441,36.389 152.441,36.389 Z M78.633,9.915 C76.938,16.897 77.068,23.049 77.939,28.221 C76.33,27.901 74.697,27.594 73.014,27.32 C37.94,21.612 27.361,38.899 31.455,52.916 C19.86,57.274 8.963,62.263 0.214,67.162 C13.98,34.146 43.896,5.087 69.145,1.268 C77.389,0.181 79.708,5.529 78.633,9.915 L78.633,9.915 Z" id="Fill-1" fill="#1F2555"/>
|
|
37
|
+
<path d="M83.492,40.09 C97.157,39.01 110.054,40.381 120.713,45.453 C112.768,40.121 100.329,33.518 83.206,29.379 C82.864,34.111 83.23,38.107 83.492,40.09 Z M81.52,40.262 C66.209,41.723 48.105,46.663 31.455,52.916 C27.361,38.899 37.941,21.612 73.014,27.32 C74.697,27.594 76.33,27.901 77.938,28.221 C78.77,33.166 80.276,37.228 81.52,40.262 L81.52,40.262 Z" id="Fill-2" fill="#00A6A7"/>
|
|
38
|
+
<path d="M286.63,35.039 L291.379,23.446 L296.129,35.039 L286.63,35.039 Z M287.854,14 L272.536,50 L280.553,50 L283.819,41.985 L298.938,41.985 L302.204,50 L310.427,50 L295.108,14 L287.854,14 Z M188.647,26.704 C188.647,29.787 186.335,32.153 182.375,32.153 L176.1,32.153 L176.1,21.149 L182.219,21.149 C186.181,21.149 188.647,23.052 188.647,26.601 L188.647,26.704 Z M182.889,14 L168.18,14 L168.18,50 L176.1,50 L176.1,39.2 L182.115,39.2 C190.19,39.2 196.673,34.878 196.673,26.547 L196.673,26.444 C196.673,19.09 191.48,14 182.889,14 Z M239.764,18.02 C235.989,21.708 234.075,26.376 234.075,31.896 C234.075,37.421 235.953,42.054 239.663,45.675 C243.366,49.292 248.022,51.123 253.503,51.123 C259.992,51.123 265.064,49.159 268.587,45.284 L268.769,45.08 L268.769,28.556 L253.112,28.556 L253.112,35.244 L261.279,35.244 L261.279,41.993 C259.164,43.252 256.525,43.891 253.429,43.891 C250.221,43.891 247.454,42.792 245.203,40.62 C242.958,38.458 241.819,35.527 241.819,31.926 C241.819,28.322 242.992,25.379 245.304,23.18 C247.624,20.972 250.538,19.852 253.966,19.852 C255.769,19.852 257.366,20.074 258.711,20.512 C259.973,20.922 261.251,21.667 262.517,22.712 L266.897,17.183 C264.586,15.147 260.427,12.467 253.503,12.467 C248.162,12.467 243.539,14.336 239.764,18.02 Z M210.336,35.604 L225.842,35.604 L225.842,28.556 L210.336,28.556 L210.336,21.042 L229.623,21.042 L229.623,14 L202.466,14 L202.466,50 L229.879,50 L229.879,42.955 L210.336,42.955 L210.336,35.604 L210.336,35.604 Z" id="Fill-3" fill="#1F2555"/>
|
|
39
|
+
</g>
|
|
40
|
+
</g>
|
|
41
|
+
</g>
|
|
42
|
+
</svg>
|
|
43
|
+
</div>
|
|
44
|
+
<div style="font-size: 2em; font-family: Arial; padding: 10px">
|
|
45
|
+
Authentication is complete!!
|
|
46
|
+
</div>
|
|
47
|
+
<div style="font-size: 13m; font-family: Arial; padding: 10px">
|
|
48
|
+
This browser tab or window may be closed.
|
|
49
|
+
</div>
|
|
50
|
+
<div style="padding: 10px;">
|
|
51
|
+
</div>`;
|
|
52
|
+
|
|
53
|
+
const authCodeConfig = grantType === 'authCode' ? {
|
|
54
|
+
authorizeUri: sAuthorizeUri,
|
|
55
|
+
redirectUri: config.redirectUri.endsWith('/') ? config.redirectUri : `${config.redirectUri}/`,
|
|
56
|
+
cert: config.cert,
|
|
57
|
+
key: config.key,
|
|
58
|
+
winTitle: 'DX Component Dev',
|
|
59
|
+
winBodyHtml: browserAuthSuccessMarkup
|
|
60
|
+
} : {};
|
|
28
61
|
|
|
29
62
|
// Build auth config structure
|
|
30
63
|
const authConfig = {
|
|
31
64
|
serverType: serverType,
|
|
65
|
+
authService: authService,
|
|
32
66
|
grantType: grantType,
|
|
33
|
-
authorizeUri: sAuthorizeUri,
|
|
34
67
|
tokenUri: sTokenUri,
|
|
35
68
|
clientId: clientId,
|
|
36
69
|
clientSecret: clientSecret,
|
|
37
|
-
|
|
38
|
-
|
|
70
|
+
ignoreInvalidCerts: true,
|
|
71
|
+
...authCodeConfig
|
|
39
72
|
};
|
|
40
73
|
if (serverType === 'infinity') {
|
|
41
|
-
authConfig.authService = 'pega';
|
|
42
74
|
if (grantType !== 'clientCreds' && user && password) {
|
|
43
75
|
authConfig.userIdentifier = user;
|
|
44
76
|
authConfig.password = Buffer.from(password).toString('base64');
|
|
@@ -46,35 +78,43 @@ const generateAccessToken = async config => {
|
|
|
46
78
|
}
|
|
47
79
|
if (serverType === 'launchpad') {
|
|
48
80
|
authConfig.isolationId = isolationId;
|
|
49
|
-
|
|
81
|
+
authConfig.noPKCE = true;
|
|
50
82
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const auth = new PegaAuth(authConfig);
|
|
86
|
+
if (grantType === 'authCode') {
|
|
87
|
+
console.log(`${chalk.green('Awaiting authorization to complete (Ctrl-C to exit). You may need to enter credentials within your default browser.')}`);
|
|
88
|
+
}
|
|
89
|
+
// console.log(`authConfig: ${JSON.stringify(authConfig)}`);
|
|
90
|
+
|
|
91
|
+
auth.login()
|
|
92
|
+
.then((token) => {
|
|
93
|
+
if (token?.token_type) {
|
|
94
|
+
fs.writeFile(TOKEN_PATH, JSON.stringify(token), err => {
|
|
95
|
+
if (err) {
|
|
96
|
+
console.error(err);
|
|
97
|
+
return reject(authSuccess);
|
|
98
|
+
}
|
|
99
|
+
console.log(`${chalk.bold.green('Authenticated successfully !!')}`);
|
|
100
|
+
authSuccess = true;
|
|
101
|
+
return resolve(authSuccess);
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
console.log(`${chalk.bold.red('Authentication failed:' + JSON.stringify(token.errors ? token.errors : token))}`);
|
|
105
|
+
return reject(authSuccess);
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
.catch((e) => {
|
|
109
|
+
console.log(`${chalk.bold.red('Authentication failed:' + e)}`);
|
|
71
110
|
return reject(authSuccess);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(`Authentication failed: Problem initializing OAuth library`);
|
|
115
|
+
return reject(authSuccess);
|
|
116
|
+
}
|
|
117
|
+
|
|
78
118
|
});
|
|
79
119
|
};
|
|
80
120
|
|
|
@@ -98,34 +138,47 @@ export default async options => {
|
|
|
98
138
|
}
|
|
99
139
|
|
|
100
140
|
const serverConfig = data['server-config'];
|
|
101
|
-
const
|
|
141
|
+
const isPwdNonEmpty = serverConfig['password'] ? true : false;
|
|
102
142
|
|
|
103
|
-
|
|
143
|
+
// console.log(`serverConfig: ${JSON.stringify(serverConfig)}`);
|
|
144
|
+
const questions = await getAuthQuestions(serverConfig);
|
|
145
|
+
// console.log(`questions: ${JSON.stringify(questions)}`);
|
|
104
146
|
const answers = await inquirer.prompt(questions);
|
|
105
|
-
|
|
106
|
-
serverConfig.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
serverConfig
|
|
114
|
-
|
|
147
|
+
const aProps = ['serverType', 'server', 'isolationId', 'clientId', 'grantType', 'clientSecret', 'user', 'password'];
|
|
148
|
+
serverConfig.authService = serverConfig.authService || 'pega';
|
|
149
|
+
const isLaunchPad = answers.serverType === "launchpad";
|
|
150
|
+
let bWriteUpdate = false;
|
|
151
|
+
for (let i = 0; i < aProps.length; i += 1) {
|
|
152
|
+
const prop = aProps[i];
|
|
153
|
+
const configValue = serverConfig[prop];
|
|
154
|
+
const answerValue = answers[prop];
|
|
155
|
+
// Treat an empty serverConfig property value as same as an undefined answer response
|
|
156
|
+
if (configValue !== answerValue && !(configValue === '' && answerValue === undefined)) {
|
|
157
|
+
// console.log(`property ${prop} changed from ${configValue} to ${answerValue}`);
|
|
158
|
+
serverConfig[prop] = answerValue;
|
|
159
|
+
if (prop !== 'password' || isPwdNonEmpty) {
|
|
160
|
+
bWriteUpdate = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
115
163
|
}
|
|
116
|
-
serverConfig.clientId = answers.clientId;
|
|
117
|
-
serverConfig.clientSecret = answers.clientSecret;
|
|
118
164
|
|
|
119
165
|
try {
|
|
166
|
+
// console.log(`serverConfig: ${JSON.stringify(serverConfig)}`);
|
|
120
167
|
authOK = await generateAccessToken(serverConfig);
|
|
121
168
|
} catch (e) {
|
|
169
|
+
console.log(`${chalk.bold.red('Authentication failed:' + JSON.stringify(e))}`);
|
|
122
170
|
}
|
|
123
171
|
|
|
124
|
-
if (authOK) {
|
|
172
|
+
if (authOK & bWriteUpdate) {
|
|
173
|
+
// Don't write password value (unless it already had a value)
|
|
174
|
+
if (!isPwdNonEmpty) {
|
|
175
|
+
serverConfig['password'] = '';
|
|
176
|
+
}
|
|
125
177
|
console.log(`${chalk.green('Writing updated config...')}`);
|
|
126
178
|
let updCfg = null;
|
|
127
179
|
try {
|
|
128
180
|
updCfg = JSON.stringify(data, null, 2);
|
|
181
|
+
// console.log(`updated config: ${updCfg}`);
|
|
129
182
|
fs.writeFileSync(pegaConfigJsonPath, updCfg, err => {
|
|
130
183
|
if (err) throw err;
|
|
131
184
|
});
|
|
@@ -103,7 +103,7 @@ export const publishComponentToServer = async data => {
|
|
|
103
103
|
const respData = JSON.parse(resp);
|
|
104
104
|
if (status === 401) {
|
|
105
105
|
throw new Error(
|
|
106
|
-
'Error
|
|
106
|
+
'Error occurred in authentication. Please regenerate using authenticate'
|
|
107
107
|
);
|
|
108
108
|
// console.log(accessTokenUri, refreshToken);
|
|
109
109
|
/* TODO - Handle refresh_token */
|
|
@@ -115,9 +115,9 @@ export const publishComponentToServer = async data => {
|
|
|
115
115
|
})
|
|
116
116
|
.catch(e => Promise.reject(`${chalk.bold.red(e)}`));
|
|
117
117
|
} else {
|
|
118
|
-
throw new Error(`Error
|
|
118
|
+
throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
|
|
119
119
|
}
|
|
120
120
|
} catch (err) {
|
|
121
|
-
throw new Error(`Error
|
|
121
|
+
throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
|
|
122
122
|
}
|
|
123
123
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import AdmZip from 'adm-zip';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
getComponentDirectoryPath,
|
|
9
|
+
getComponents,
|
|
10
|
+
getPegaServerConfig
|
|
11
|
+
} from '../../util.js';
|
|
12
|
+
import { COMPONENT_SCHEMA } from '../../constants.js';
|
|
13
|
+
|
|
14
|
+
export const cleanUp = async () => {
|
|
15
|
+
fs.rm('dist/components', { recursive: true }, err => {
|
|
16
|
+
if (err) {
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
fs.rm('lib', { recursive: true }, err => {
|
|
22
|
+
if (err) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
export const getBuildComponentQuestions = async () => {
|
|
31
|
+
const components = await getComponents();
|
|
32
|
+
const defaultPegaConfig = await getPegaServerConfig();
|
|
33
|
+
|
|
34
|
+
if (components.length == 0) {
|
|
35
|
+
console.log(chalk.bold.yellow(`No components to build`));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
name: 'devBuild',
|
|
42
|
+
message: 'Generate development build ?',
|
|
43
|
+
default: defaultPegaConfig.devBuild
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
export const zipComponent = async (componentKey) => {
|
|
51
|
+
const srcDirectory = await getComponentDirectoryPath(componentKey);
|
|
52
|
+
const buildDirectory = await path.join(path.resolve(), 'dist/components', componentKey);
|
|
53
|
+
const configJson = `${srcDirectory}/config.json`;
|
|
54
|
+
|
|
55
|
+
const zip = new AdmZip();
|
|
56
|
+
|
|
57
|
+
zip.addLocalFolder(srcDirectory, 'src/');
|
|
58
|
+
zip.addLocalFile(configJson);
|
|
59
|
+
zip.addLocalFolder(buildDirectory);
|
|
60
|
+
const zipContent = zip.toBuffer().toString('base64');
|
|
61
|
+
|
|
62
|
+
const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
|
|
63
|
+
// fs.rmd('dist/components', { recursive: true }, err => {
|
|
64
|
+
// if (err) {
|
|
65
|
+
// throw err;
|
|
66
|
+
// }
|
|
67
|
+
// });
|
|
68
|
+
return { zipContent, configContent };
|
|
69
|
+
};
|