@pega/custom-dx-components 8.8.11 → 8.8.12
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 -1
- package/src/tasks/authenticate/helper.js +22 -21
- package/src/tasks/build-all/index.js +14 -21
- package/src/tasks/init/template/package.json.mustache +1 -1
- package/src/tasks/publish/helper.js +4 -4
- package/src/tasks/publish-all/helper.js +76 -27
- package/src/tasks/publish-all/index.js +19 -26
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import { getPegaServerConfig } from '../../util.js';
|
|
3
|
-
|
|
4
2
|
import { AUTHENTICATE_SCHEMA, AUTHENTICATE_DEFAULTS } from '../../constants.js';
|
|
5
3
|
|
|
6
4
|
export const getAuthQuestions = async (dxcbConfig) => {
|
|
7
5
|
const defaultPegaConfig = dxcbConfig;
|
|
8
|
-
const aAlwaysAsk = dxcbConfig
|
|
9
|
-
const aNeverAsk = dxcbConfig
|
|
10
|
-
const aAskOnce = dxcbConfig
|
|
11
|
-
const aAskedOnce = dxcbConfig
|
|
6
|
+
const aAlwaysAsk = dxcbConfig.questions_askAlways ? dxcbConfig.questions_askAlways.split(',') : [];
|
|
7
|
+
const aNeverAsk = dxcbConfig.questions_askNever ? dxcbConfig.questions_askNever.split(',') : [];
|
|
8
|
+
const aAskOnce = dxcbConfig.questions_askOnce ? dxcbConfig.questions_askOnce.split(',') : [];
|
|
9
|
+
const aAskedOnce = dxcbConfig.questions_askedOnce ? dxcbConfig.questions_askedOnce.split(',') : [];
|
|
12
10
|
|
|
13
11
|
// Ask if various must, never, once criteria are met
|
|
14
12
|
const askThisTime = (prop) => {
|
|
15
|
-
|
|
13
|
+
return aAlwaysAsk.includes(prop) ||
|
|
16
14
|
(!aNeverAsk.includes(prop) && (aAskOnce.includes(prop) && !aAskedOnce.includes(prop)));
|
|
17
|
-
return bAsk;
|
|
18
15
|
};
|
|
19
16
|
|
|
20
|
-
const initAnswer = (prop,
|
|
21
|
-
|
|
17
|
+
const initAnswer = (prop, defValue) => {
|
|
18
|
+
if (askThisTime(prop)) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return defaultPegaConfig[prop] ? defaultPegaConfig[prop] : defValue;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const initAnswers = (answers) => {
|
|
25
25
|
// Setup default answers (if they are present and non-empty)
|
|
26
|
-
answers.serverType = initAnswer('serverType',
|
|
27
|
-
answers.server = initAnswer('server',
|
|
28
|
-
answers.isolationId = initAnswer('isolationId'
|
|
29
|
-
answers.clientId = initAnswer('clientId',
|
|
30
|
-
answers.grantType = initAnswer('grantType',
|
|
31
|
-
answers.authService = initAnswer('authService',
|
|
26
|
+
answers.serverType = initAnswer('serverType', AUTHENTICATE_DEFAULTS.serverType);
|
|
27
|
+
answers.server = initAnswer('server', AUTHENTICATE_DEFAULTS.server);
|
|
28
|
+
answers.isolationId = initAnswer('isolationId');
|
|
29
|
+
answers.clientId = initAnswer('clientId', AUTHENTICATE_DEFAULTS.clientId);
|
|
30
|
+
answers.grantType = initAnswer('grantType', AUTHENTICATE_DEFAULTS.grantType);
|
|
31
|
+
answers.authService = initAnswer('authService', AUTHENTICATE_DEFAULTS.authService);
|
|
32
32
|
answers.redirectUri = initAnswer('redirectUri', AUTHENTICATE_DEFAULTS.redirectUri);
|
|
33
|
-
answers.clientSecret = initAnswer('clientSecret'
|
|
34
|
-
answers.user = initAnswer('user'
|
|
35
|
-
answers.password = initAnswer('password'
|
|
33
|
+
answers.clientSecret = initAnswer('clientSecret');
|
|
34
|
+
answers.user = initAnswer('user');
|
|
35
|
+
answers.password = initAnswer('password');
|
|
36
36
|
answers.aAsked = [];
|
|
37
37
|
};
|
|
38
38
|
|
|
@@ -192,14 +192,15 @@ export const getAuthQuestions = async (dxcbConfig) => {
|
|
|
192
192
|
type: 'password',
|
|
193
193
|
message: 'Enter clientSecret',
|
|
194
194
|
default: defaultPegaConfig.clientSecret,
|
|
195
|
-
validate:
|
|
195
|
+
validate: value => {
|
|
196
196
|
if (value.trim()) {
|
|
197
197
|
return true;
|
|
198
198
|
}
|
|
199
199
|
return 'clientSecret cannot be empty';
|
|
200
200
|
},
|
|
201
201
|
when: answers => {
|
|
202
|
-
return (answers.
|
|
202
|
+
return (((answers.serverType === "infinity" && answers.grantType !== "authCode") ||
|
|
203
|
+
answers.serverType === "launchpad") && fnStandardWhen('clientSecret', answers));
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
206
|
];
|
|
@@ -3,18 +3,16 @@ import Listr from 'listr';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
5
|
import validate from '../validator/index.js';
|
|
6
|
-
|
|
7
6
|
import bundleComponent from '../bundle/index.js';
|
|
8
|
-
import lintComponent from '../linter/index.js';
|
|
9
|
-
import {
|
|
10
|
-
import { getComponentDirectoryPath, showVersion, getComponentsObj } from '../../util.js';
|
|
7
|
+
import { lintComponent } from '../linter/index.js';
|
|
8
|
+
import { getComponentDirectoryPath, showVersion, getComponents } from '../../util.js';
|
|
11
9
|
|
|
12
|
-
import {
|
|
10
|
+
import { getBuildComponentQuestions, cleanUp } from './helper.js';
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
export function getCustomTasks(componentKey, sourceMap, devBuild) {
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
return new Listr(
|
|
18
16
|
[
|
|
19
17
|
{
|
|
20
18
|
title: 'Validate config schema',
|
|
@@ -32,7 +30,7 @@ export function getCustomTasks(componentKey, sourceMap, devBuild) {
|
|
|
32
30
|
},
|
|
33
31
|
{
|
|
34
32
|
title: 'Bundle component',
|
|
35
|
-
task: async () =>
|
|
33
|
+
task: async () => bundleComponent(componentKey, sourceMap, devBuild),
|
|
36
34
|
}
|
|
37
35
|
],
|
|
38
36
|
{
|
|
@@ -40,40 +38,35 @@ export function getCustomTasks(componentKey, sourceMap, devBuild) {
|
|
|
40
38
|
}
|
|
41
39
|
);
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
|
|
47
45
|
|
|
48
46
|
|
|
49
|
-
export default async
|
|
47
|
+
export default async () => {
|
|
50
48
|
showVersion();
|
|
51
49
|
|
|
52
|
-
let category = CATEGORY_CONSTELLATION;
|
|
53
50
|
|
|
54
|
-
const components = await
|
|
51
|
+
const components = await getComponents();
|
|
55
52
|
const questions = await getBuildComponentQuestions();
|
|
56
53
|
const answers = await inquirer.prompt(questions);
|
|
57
54
|
const { sourceMap, devBuild } = answers;
|
|
58
55
|
|
|
59
56
|
|
|
57
|
+
for (const componentKey of components) {
|
|
58
|
+
console.log(chalk.bold.green(`Building ${componentKey}`));
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for (var index in components) {
|
|
65
|
-
componentKey = components[index].value;
|
|
66
|
-
console.log(chalk.bold.green("Building: " + components[index].name));
|
|
67
|
-
|
|
68
|
-
let myCustomTasks = getCustomTasks(componentKey, sourceMap, devBuild );
|
|
60
|
+
const myCustomTasks = getCustomTasks(componentKey, sourceMap, devBuild );
|
|
69
61
|
|
|
62
|
+
// eslint-disable-next-line no-await-in-loop
|
|
70
63
|
await myCustomTasks.run().catch(err => {
|
|
71
64
|
console.log(chalk.bold.red(err.toString()));
|
|
72
65
|
});
|
|
73
66
|
}
|
|
74
67
|
|
|
75
|
-
|
|
76
|
-
cleanUp();
|
|
68
|
+
// once done, remove leftover directories
|
|
69
|
+
await cleanUp();
|
|
77
70
|
|
|
78
71
|
return true;
|
|
79
72
|
};
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@pega/configs": "^0.5.3",
|
|
59
|
-
"@pega/custom-dx-components": "^8.8.
|
|
59
|
+
"@pega/custom-dx-components": "^8.8.12",
|
|
60
60
|
"@pega/eslint-config": "^0.3.2",
|
|
61
61
|
"@storybook/addon-actions": "^6.5.12",
|
|
62
62
|
"@storybook/addon-essentials": "^6.5.12",
|
|
@@ -40,8 +40,8 @@ export const getPublishComponentQuestions = async () => {
|
|
|
40
40
|
}
|
|
41
41
|
return 'Ruleset name cannot be empty';
|
|
42
42
|
},
|
|
43
|
-
when:
|
|
44
|
-
return
|
|
43
|
+
when: () => {
|
|
44
|
+
return defaultPegaConfig.serverType === 'infinity';
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
{
|
|
@@ -54,8 +54,8 @@ export const getPublishComponentQuestions = async () => {
|
|
|
54
54
|
}
|
|
55
55
|
return 'Please provide compatible version e.g 01-01-01';
|
|
56
56
|
},
|
|
57
|
-
when:
|
|
58
|
-
return
|
|
57
|
+
when: () => {
|
|
58
|
+
return defaultPegaConfig.serverType === 'infinity';
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
{
|
|
@@ -9,14 +9,16 @@ import chalk from 'chalk';
|
|
|
9
9
|
import {
|
|
10
10
|
constructCompleteUrl,
|
|
11
11
|
getComponentDirectoryPath,
|
|
12
|
-
getComponents,
|
|
13
12
|
getPegaServerConfig,
|
|
14
13
|
validateRulesetVersion
|
|
15
14
|
} from '../../util.js';
|
|
16
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
|
|
17
|
+
LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
|
|
18
|
+
TOKEN_PATH
|
|
19
|
+
} from '../../constants.js';
|
|
17
20
|
|
|
18
21
|
export const getPublishComponentQuestions = async () => {
|
|
19
|
-
const components = await getComponents();
|
|
20
22
|
const defaultPegaConfig = await getPegaServerConfig();
|
|
21
23
|
|
|
22
24
|
return [
|
|
@@ -29,6 +31,9 @@ export const getPublishComponentQuestions = async () => {
|
|
|
29
31
|
return true;
|
|
30
32
|
}
|
|
31
33
|
return 'Ruleset name cannot be empty';
|
|
34
|
+
},
|
|
35
|
+
when: () => {
|
|
36
|
+
return defaultPegaConfig.serverType === 'infinity';
|
|
32
37
|
}
|
|
33
38
|
},
|
|
34
39
|
{
|
|
@@ -40,12 +45,16 @@ export const getPublishComponentQuestions = async () => {
|
|
|
40
45
|
return true;
|
|
41
46
|
}
|
|
42
47
|
return 'Please provide compatible version e.g 01-01-01';
|
|
48
|
+
},
|
|
49
|
+
when: () => {
|
|
50
|
+
return defaultPegaConfig.serverType === 'infinity';
|
|
43
51
|
}
|
|
44
52
|
},
|
|
45
53
|
{
|
|
46
54
|
name: 'sourceMap',
|
|
47
55
|
message: 'Generate source map ?',
|
|
48
56
|
default: defaultPegaConfig.sourceMap,
|
|
57
|
+
// eslint-disable-next-line sonarjs/no-redundant-boolean
|
|
49
58
|
when: () => false && !process.env.SOURCE_MAP
|
|
50
59
|
},
|
|
51
60
|
{
|
|
@@ -70,11 +79,11 @@ export const zipComponent = async componentKey => {
|
|
|
70
79
|
|
|
71
80
|
const configContent = Buffer.from(fs.readFileSync(`${srcDirectory}/config.json`)).toString();
|
|
72
81
|
// clean up now happens in function cleanUp
|
|
73
|
-
//fs.rmdir('dist', { recursive: true }, err => {
|
|
82
|
+
// fs.rmdir('dist', { recursive: true }, err => {
|
|
74
83
|
// if (err) {
|
|
75
84
|
// throw err;
|
|
76
85
|
// }
|
|
77
|
-
//});
|
|
86
|
+
// });
|
|
78
87
|
return { zipContent, configContent };
|
|
79
88
|
};
|
|
80
89
|
|
|
@@ -90,40 +99,68 @@ export const cleanUp = async () => {
|
|
|
90
99
|
throw err;
|
|
91
100
|
}
|
|
92
101
|
});
|
|
93
|
-
}
|
|
102
|
+
};
|
|
94
103
|
|
|
95
104
|
export const publishComponentToServer = async data => {
|
|
96
|
-
const { configContent, zipContent,
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const { configContent, zipContent, rulesetName, rulesetVersion } = data;
|
|
106
|
+
|
|
107
|
+
const defaultPegaServerConfig = await getPegaServerConfig();
|
|
108
|
+
const { serverType, isolationId } = defaultPegaServerConfig;
|
|
109
|
+
const isLaunchpad = serverType === 'launchpad';
|
|
110
|
+
const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace(
|
|
111
|
+
'{isolationId}',
|
|
112
|
+
isolationId
|
|
113
|
+
);
|
|
114
|
+
let apiBody;
|
|
115
|
+
|
|
116
|
+
if (isLaunchpad) {
|
|
117
|
+
apiBody = {
|
|
118
|
+
type: 'CustomComponent',
|
|
119
|
+
zipContent,
|
|
120
|
+
componentName: JSON.parse(configContent).componentKey,
|
|
121
|
+
pxUpdateDateTime: '',
|
|
122
|
+
environmentID: defaultPegaServerConfig.isolationId
|
|
123
|
+
};
|
|
124
|
+
} else {
|
|
125
|
+
apiBody = {
|
|
126
|
+
configContent,
|
|
127
|
+
zipContent,
|
|
128
|
+
componentKey: JSON.parse(configContent).componentKey,
|
|
129
|
+
publishFor: 'constellation',
|
|
130
|
+
rulesetName,
|
|
131
|
+
rulesetVersion,
|
|
132
|
+
category: ''
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
107
136
|
const defaultPegaConfig = await getPegaServerConfig();
|
|
108
137
|
const url = constructCompleteUrl(
|
|
109
138
|
defaultPegaConfig.server,
|
|
110
|
-
PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
|
|
139
|
+
isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
|
|
111
140
|
);
|
|
141
|
+
|
|
112
142
|
try {
|
|
113
143
|
const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
|
|
114
144
|
if (OauthData) {
|
|
115
145
|
const {
|
|
116
146
|
access_token: accessToken,
|
|
117
|
-
token_type: tokenType
|
|
118
|
-
refresh_token: refreshToken
|
|
147
|
+
token_type: tokenType
|
|
148
|
+
// refresh_token: refreshToken
|
|
119
149
|
} = JSON.parse(OauthData);
|
|
120
150
|
let status = 500;
|
|
151
|
+
const headers = {};
|
|
152
|
+
|
|
153
|
+
if (isLaunchpad) {
|
|
154
|
+
headers.cookie = `Pega-AAT=${accessToken}`;
|
|
155
|
+
headers['Content-Type'] = 'application/json';
|
|
156
|
+
} else {
|
|
157
|
+
headers.Authorization = `${tokenType} ${accessToken}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
121
160
|
fetch(url, {
|
|
122
161
|
method: 'POST',
|
|
123
162
|
agent: new https.Agent({ rejectUnauthorized: false }),
|
|
124
|
-
headers
|
|
125
|
-
Authorization: `${tokenType} ${accessToken}`
|
|
126
|
-
},
|
|
163
|
+
headers,
|
|
127
164
|
body: JSON.stringify(apiBody)
|
|
128
165
|
})
|
|
129
166
|
.then(response => {
|
|
@@ -131,20 +168,32 @@ export const publishComponentToServer = async data => {
|
|
|
131
168
|
return response.text();
|
|
132
169
|
})
|
|
133
170
|
.then(resp => {
|
|
134
|
-
const respData = JSON.parse(resp);
|
|
171
|
+
const respData = isLaunchpad ? resp : JSON.parse(resp);
|
|
135
172
|
if (status === 401) {
|
|
136
173
|
throw new Error(
|
|
137
174
|
'Error occurred in authentication. Please regenerate using authenticate'
|
|
138
175
|
);
|
|
139
176
|
// console.log(accessTokenUri, refreshToken);
|
|
140
177
|
/* TODO - Handle refresh_token */
|
|
141
|
-
} else if (status
|
|
142
|
-
console.log(chalk.bold.green(`Success : ${respData.message}`));
|
|
178
|
+
} else if (status === 200 || status === 201) {
|
|
179
|
+
console.log(chalk.bold.green(`Success : ${isLaunchpad ? respData : respData.message}`));
|
|
143
180
|
} else {
|
|
144
181
|
throw new Error(`${respData.message}`);
|
|
145
182
|
}
|
|
146
183
|
})
|
|
147
|
-
.catch(e =>
|
|
184
|
+
.catch(e => {
|
|
185
|
+
if (e.code === 'ECONNREFUSED') {
|
|
186
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
187
|
+
Promise.reject(
|
|
188
|
+
`${chalk.bold.red(
|
|
189
|
+
'Error occurred in authentication. Please regenerate using authenticate'
|
|
190
|
+
)}`
|
|
191
|
+
);
|
|
192
|
+
} else {
|
|
193
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
194
|
+
Promise.reject(`${chalk.bold.red(e)}`);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
148
197
|
} else {
|
|
149
198
|
throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
|
|
150
199
|
}
|
|
@@ -3,22 +3,19 @@ import Listr from 'listr';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
5
|
import validate from '../validator/index.js';
|
|
6
|
-
|
|
7
6
|
import bundleComponent from '../bundle/index.js';
|
|
8
7
|
import { lintComponent } from '../linter/index.js';
|
|
8
|
+
import { getComponents, getComponentDirectoryPath, showVersion } from '../../util.js';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
import { getPublishComponentQuestions, publishComponentToServer, zipComponent, cleanUp } from './helper.js';
|
|
12
10
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
getPublishComponentQuestions,
|
|
12
|
+
publishComponentToServer,
|
|
13
|
+
zipComponent,
|
|
14
|
+
cleanUp
|
|
15
|
+
} from './helper.js';
|
|
19
16
|
|
|
20
17
|
export function getCustomTasks(componentKey, sourceMap, devBuild, content, options) {
|
|
21
|
-
|
|
18
|
+
return new Listr(
|
|
22
19
|
[
|
|
23
20
|
{
|
|
24
21
|
title: 'Validate config schema',
|
|
@@ -28,7 +25,9 @@ export function getCustomTasks(componentKey, sourceMap, devBuild, content, optio
|
|
|
28
25
|
},
|
|
29
26
|
{
|
|
30
27
|
title: 'Bundle Component',
|
|
31
|
-
task: async () =>
|
|
28
|
+
task: async () => {
|
|
29
|
+
await bundleComponent(componentKey, sourceMap, devBuild);
|
|
30
|
+
},
|
|
32
31
|
skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined)
|
|
33
32
|
},
|
|
34
33
|
{
|
|
@@ -57,8 +56,6 @@ export function getCustomTasks(componentKey, sourceMap, devBuild, content, optio
|
|
|
57
56
|
exitOnError: true
|
|
58
57
|
}
|
|
59
58
|
);
|
|
60
|
-
|
|
61
|
-
return customTasks;
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
export default async options => {
|
|
@@ -67,29 +64,25 @@ export default async options => {
|
|
|
67
64
|
const components = await getComponents();
|
|
68
65
|
const questions = await getPublishComponentQuestions();
|
|
69
66
|
const answers = await inquirer.prompt(questions);
|
|
70
|
-
const {sourceMap, devBuild } = answers;
|
|
67
|
+
const { sourceMap, devBuild } = answers;
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
const content = {
|
|
73
70
|
...answers
|
|
74
71
|
};
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
for (const componentKey of components) {
|
|
74
|
+
console.log(chalk.bold.green(`Publishing: ${componentKey}`));
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
componentKey = components[index];
|
|
81
|
-
console.log(chalk.bold.green("Publishing: " + componentKey));
|
|
82
|
-
|
|
83
|
-
let myCustomTasks = getCustomTasks(componentKey, sourceMap, devBuild, content, options);
|
|
76
|
+
const myCustomTasks = getCustomTasks(componentKey, sourceMap, devBuild, content, options);
|
|
84
77
|
|
|
78
|
+
// eslint-disable-next-line no-await-in-loop
|
|
85
79
|
await myCustomTasks.run().catch(err => {
|
|
86
|
-
|
|
80
|
+
console.log(chalk.bold.red(err.toString()));
|
|
87
81
|
});
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
// once done, remove leftover directories
|
|
85
|
+
await cleanUp();
|
|
93
86
|
|
|
94
87
|
return true;
|
|
95
88
|
};
|