@pega/custom-dx-components 0.23.6 → 0.23.8
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/auth.js +9 -3
- package/src/tasks/authenticate/index.js +42 -39
- package/src/tasks/build/helper.js +5 -19
- package/src/tasks/bundle/builder/webpack.config.js +2 -4
- package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Field/TimeOfDay/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +13 -6
- package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +13 -6
- package/src/tasks/create-all/index.js +51 -116
- package/src/tasks/init/index.js +5 -1
- package/src/tasks/init/template/package.json.mustache +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyBoolean/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyBoolean/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyCaseWidget/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyCaseWidget/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyCurrency/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyCurrency/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDate/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDate/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDateTime/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDateTime/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDecimal/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDecimal/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDetails/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyDetails/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyEmail/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyEmail/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyForm/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyForm/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyInteger/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyInteger/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPage/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPage/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPageCaseWidget/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPageCaseWidget/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPageWidget/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPageWidget/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyParagraph/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyParagraph/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPercentage/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPercentage/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPhone/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPhone/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPicklist/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyPicklist/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyText/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyText/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTextInput/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTextInput/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTimeOfDay/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTimeOfDay/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTwoColumnDetails/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTwoColumnDetails/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTwoColumnForm/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyTwoColumnForm/styles.js +13 -6
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyURL/config.json +2 -2
- package/src/tasks/init/template/test/assets/components/createAll/Pega_DXIL_MyURL/styles.js +13 -6
- package/src/tasks/init/template/test/functionTest/localCreateAllListDeleteAll.test.js +1 -1
- package/src/tasks/list/helper.js +10 -8
- package/src/tasks/publish/helper.js +16 -30
- package/src/tasks/publish-all/helper.js +9 -27
- package/src/util.js +43 -78
|
@@ -15,7 +15,7 @@ describe('createAll list and deleteAll local', () => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
it('npm run createAll Local', async () => {
|
|
18
|
-
const script = `npm run createAll "My
|
|
18
|
+
const script = `npm run createAll "My" 0.0.1 DXIL "" Pega`;
|
|
19
19
|
|
|
20
20
|
const { stdout, stderr } = await exec(script);
|
|
21
21
|
// console.log(stdout);
|
package/src/tasks/list/helper.js
CHANGED
|
@@ -4,8 +4,8 @@ import https from 'https';
|
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import fetch from 'node-fetch';
|
|
6
6
|
|
|
7
|
-
import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
|
|
8
|
-
import { constructCompleteUrl, getComponents, getPegaServerConfig } from '../../util.js';
|
|
7
|
+
import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA } from '../../constants.js';
|
|
8
|
+
import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent } from '../../util.js';
|
|
9
9
|
|
|
10
10
|
export const SOURCE_OF_COMPONENT_TYPES = {
|
|
11
11
|
SERVER: 'Server',
|
|
@@ -40,12 +40,13 @@ export const listLocalComponents = async (sourceOfComponents) => {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
function fetchComponentsFromInfinity(apiUrl, headers) {
|
|
43
|
+
async function fetchComponentsFromInfinity(apiUrl, headers) {
|
|
44
|
+
const serverConfig = await getPegaServerConfig();
|
|
44
45
|
return new Promise((resolve, reject) => {
|
|
45
46
|
let status = 500;
|
|
46
47
|
fetch(apiUrl, {
|
|
47
48
|
method: 'GET',
|
|
48
|
-
agent:
|
|
49
|
+
agent: getHttpsAgent(serverConfig),
|
|
49
50
|
headers
|
|
50
51
|
})
|
|
51
52
|
.then((response) => {
|
|
@@ -69,8 +70,9 @@ function fetchComponentsFromInfinity(apiUrl, headers) {
|
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
function fetchComponentsFromLaunchpad(apiUrl, headers) {
|
|
73
|
-
|
|
73
|
+
async function fetchComponentsFromLaunchpad(apiUrl, headers) {
|
|
74
|
+
const serverConfig = await getPegaServerConfig();
|
|
75
|
+
// constructing urls for all type of components
|
|
74
76
|
const urls = COMPONENT_SCHEMA.type.map((type) => apiUrl.replace('{type}', type.value));
|
|
75
77
|
const statuses = [];
|
|
76
78
|
|
|
@@ -79,7 +81,7 @@ function fetchComponentsFromLaunchpad(apiUrl, headers) {
|
|
|
79
81
|
urls.map(async (url) => {
|
|
80
82
|
return fetch(url, {
|
|
81
83
|
method: 'GET',
|
|
82
|
-
agent:
|
|
84
|
+
agent: getHttpsAgent(serverConfig),
|
|
83
85
|
headers
|
|
84
86
|
});
|
|
85
87
|
})
|
|
@@ -150,7 +152,7 @@ export const getComponentsFromServer = async () => {
|
|
|
150
152
|
|
|
151
153
|
fetch(url, {
|
|
152
154
|
method: 'GET',
|
|
153
|
-
agent:
|
|
155
|
+
agent: getHttpsAgent(defaultPegaServerConfig),
|
|
154
156
|
headers
|
|
155
157
|
})
|
|
156
158
|
.then(response => {
|
|
@@ -11,19 +11,16 @@ import {
|
|
|
11
11
|
getComponentDirectoryPath,
|
|
12
12
|
getComponents,
|
|
13
13
|
getPegaServerConfig,
|
|
14
|
-
validateRulesetVersion
|
|
14
|
+
validateRulesetVersion,
|
|
15
|
+
getHttpsAgent
|
|
15
16
|
} from '../../util.js';
|
|
16
|
-
import {
|
|
17
|
-
PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
|
|
18
|
-
LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
|
|
19
|
-
TOKEN_PATH
|
|
20
|
-
} from '../../constants.js';
|
|
17
|
+
import { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
|
|
21
18
|
|
|
22
19
|
export const getPublishComponentQuestions = async () => {
|
|
23
20
|
const components = await getComponents();
|
|
24
21
|
|
|
25
22
|
if (components.length == 0) {
|
|
26
|
-
console.log(chalk.redBright(
|
|
23
|
+
console.log(chalk.redBright('No components to publish'));
|
|
27
24
|
process.exit(1);
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -40,7 +37,7 @@ export const getPublishComponentQuestions = async () => {
|
|
|
40
37
|
name: 'rulesetName',
|
|
41
38
|
message: 'Enter ruleset name',
|
|
42
39
|
default: defaultPegaConfig.rulesetName,
|
|
43
|
-
validate: value => {
|
|
40
|
+
validate: (value) => {
|
|
44
41
|
if (value.trim()) {
|
|
45
42
|
return true;
|
|
46
43
|
}
|
|
@@ -54,7 +51,7 @@ export const getPublishComponentQuestions = async () => {
|
|
|
54
51
|
name: 'rulesetVersion',
|
|
55
52
|
message: 'Enter ruleset version',
|
|
56
53
|
default: defaultPegaConfig.rulesetVersion,
|
|
57
|
-
validate: value => {
|
|
54
|
+
validate: (value) => {
|
|
58
55
|
if (validateRulesetVersion(value)) {
|
|
59
56
|
return true;
|
|
60
57
|
}
|
|
@@ -109,10 +106,7 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
109
106
|
const defaultPegaServerConfig = await getPegaServerConfig();
|
|
110
107
|
const { serverType, isolationId } = defaultPegaServerConfig;
|
|
111
108
|
const isLaunchpad = serverType === 'launchpad';
|
|
112
|
-
const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace(
|
|
113
|
-
'{isolationId}',
|
|
114
|
-
isolationId
|
|
115
|
-
);
|
|
109
|
+
const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace('{isolationId}', isolationId);
|
|
116
110
|
let apiBody;
|
|
117
111
|
|
|
118
112
|
if (isLaunchpad) {
|
|
@@ -136,10 +130,7 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
136
130
|
}
|
|
137
131
|
|
|
138
132
|
const defaultPegaConfig = await getPegaServerConfig();
|
|
139
|
-
const url = constructCompleteUrl(
|
|
140
|
-
defaultPegaConfig.server,
|
|
141
|
-
isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT
|
|
142
|
-
);
|
|
133
|
+
const url = constructCompleteUrl(defaultPegaConfig.server, isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT);
|
|
143
134
|
|
|
144
135
|
if (doFetch) {
|
|
145
136
|
try {
|
|
@@ -151,9 +142,9 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
151
142
|
// refresh_token: refreshToken
|
|
152
143
|
} = JSON.parse(OauthData);
|
|
153
144
|
let status = 500;
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
145
|
+
const headers = {
|
|
146
|
+
Authorization: `${tokenType} ${accessToken}`
|
|
147
|
+
};
|
|
157
148
|
|
|
158
149
|
if (isLaunchpad) {
|
|
159
150
|
headers.cookie = `Pega-AAT=${accessToken}`;
|
|
@@ -162,20 +153,18 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
162
153
|
|
|
163
154
|
fetch(url, {
|
|
164
155
|
method: 'POST',
|
|
165
|
-
agent:
|
|
156
|
+
agent: getHttpsAgent(defaultPegaConfig),
|
|
166
157
|
headers,
|
|
167
158
|
body: JSON.stringify(apiBody)
|
|
168
159
|
})
|
|
169
|
-
|
|
160
|
+
.then((response) => {
|
|
170
161
|
status = response.status;
|
|
171
162
|
return response.text();
|
|
172
163
|
})
|
|
173
|
-
|
|
164
|
+
.then((resp) => {
|
|
174
165
|
const respData = isLaunchpad ? resp : JSON.parse(resp);
|
|
175
166
|
if (status === 401) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
'Error occurred in authentication. Please regenerate using authenticate'
|
|
178
|
-
);
|
|
167
|
+
throw new Error('Error occurred in authentication. Please regenerate using authenticate');
|
|
179
168
|
// console.log(accessTokenUri, refreshToken);
|
|
180
169
|
/* TODO - Handle refresh_token */
|
|
181
170
|
} else if (status === 200 || status === 201) {
|
|
@@ -184,7 +173,7 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
184
173
|
throw new Error(`${respData.message}`);
|
|
185
174
|
}
|
|
186
175
|
})
|
|
187
|
-
|
|
176
|
+
.catch((e) => {
|
|
188
177
|
if (e.code === 'ECONNREFUSED') {
|
|
189
178
|
// eslint-disable-next-line prefer-promise-reject-errors
|
|
190
179
|
Promise.reject(`${chalk.bold.red('Error occurred in authentication. Please regenerate using authenticate')}`);
|
|
@@ -202,8 +191,5 @@ export const publishComponentToServer = async (data, doFetch) => {
|
|
|
202
191
|
} catch (err) {
|
|
203
192
|
throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
|
|
204
193
|
}
|
|
205
|
-
|
|
206
194
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
195
|
};
|
|
@@ -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
|
-
|
|
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:
|
|
149
|
+
agent: getHttpsAgent(defaultPegaConfig),
|
|
165
150
|
headers,
|
|
166
151
|
body: JSON.stringify(apiBody)
|
|
167
152
|
})
|
|
168
|
-
|
|
153
|
+
.then((response) => {
|
|
169
154
|
status = response.status;
|
|
170
155
|
return response.text();
|
|
171
156
|
})
|
|
172
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
|
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:
|
|
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
|
|
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:
|
|
350
|
+
agent: getHttpsAgent(serverConfig),
|
|
386
351
|
headers: {
|
|
387
352
|
Authorization: `${tokenType} ${accessToken}`
|
|
388
353
|
}
|