@pega/custom-dx-components 8.8.10 → 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.
@@ -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 { PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH } from '../../constants.js';
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, componentKey, rulesetName, rulesetVersion } = data;
97
-
98
- const apiBody = {
99
- configContent,
100
- zipContent,
101
- componentKey: JSON.parse(configContent).componentKey,
102
- publishFor: 'constellation',
103
- rulesetName,
104
- rulesetVersion,
105
- category: ''
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 == 200) {
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 => Promise.reject(`${chalk.bold.red(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
- getComponents,
14
- getComponentDirectoryPath,
15
- showVersion
16
- } from '../../util.js';
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
- const customTasks = new Listr(
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 () => await bundleComponent(componentKey, sourceMap, devBuild),
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
- let content = {
69
+ const content = {
73
70
  ...answers
74
71
  };
75
72
 
76
- var componentKey;
77
-
73
+ for (const componentKey of components) {
74
+ console.log(chalk.bold.green(`Publishing: ${componentKey}`));
78
75
 
79
- for (var index in components) {
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
- console.log(chalk.bold.red(err.toString()));
80
+ console.log(chalk.bold.red(err.toString()));
87
81
  });
88
82
  }
89
83
 
90
- // once done, remove leftover directories
91
- cleanUp();
92
-
84
+ // once done, remove leftover directories
85
+ await cleanUp();
93
86
 
94
87
  return true;
95
88
  };