@pega/custom-dx-components 0.25.18 → 0.25.20

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 (71) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +6 -0
  3. package/src/constants.js +3 -1
  4. package/src/tasks/build-jest-assets/index.js +5 -5
  5. package/src/tasks/create-version/helper.js +30 -0
  6. package/src/tasks/create-version/index.js +12 -4
  7. package/src/tasks/delete-pub/helper.js +1 -1
  8. package/src/tasks/delete-pub/index.js +6 -1
  9. package/src/tasks/export-archive/helper.js +12 -12
  10. package/src/tasks/export-archive/index.js +6 -0
  11. package/src/tasks/import-archive/helper.js +205 -3
  12. package/src/tasks/import-archive/index.js +146 -31
  13. package/src/tasks/index.js +1 -0
  14. package/src/tasks/init/template/package.json.mustache +2 -1
  15. package/src/tasks/list-pub/helper.js +3 -3
  16. package/src/tasks/publish-archive/index.js +5 -2
  17. package/src/tasks/restore/index.js +72 -0
  18. package/src/tasks/show-help/index.js +25 -7
  19. package/src/tasks/show-status/index.js +10 -6
  20. package/src/util.js +58 -1
  21. package/tests/assets/library/components/create/Pega_DXIL_MyTestText/config.json +1 -1
  22. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyBoolean/config.json +1 -1
  23. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/config.json +1 -1
  24. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/localizations.json +8 -0
  25. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyCurrency/config.json +1 -1
  26. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDate/config.json +1 -1
  27. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDateTime/config.json +1 -1
  28. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDecimal/config.json +1 -1
  29. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDetails/config.json +1 -1
  30. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyEmail/config.json +1 -1
  31. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyForm/config.json +1 -1
  32. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/config.json +1 -1
  33. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/localizations.json +10 -0
  34. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyInteger/config.json +1 -1
  35. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPage/config.json +1 -1
  36. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/config.json +1 -1
  37. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageWidget/config.json +1 -1
  38. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageWidget/localizations.json +10 -0
  39. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyParagraph/config.json +1 -1
  40. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPercentage/config.json +1 -1
  41. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPhone/config.json +1 -1
  42. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPicklist/config.json +1 -1
  43. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyRadiobuttons/config.json +1 -1
  44. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MySearchbox/config.json +1 -1
  45. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MySearchbox/localizations.json +5 -0
  46. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyText/config.json +1 -1
  47. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTextInput/config.json +1 -1
  48. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTimeOfDay/config.json +1 -1
  49. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/config.json +1 -1
  50. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnForm/config.json +1 -1
  51. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyURL/config.json +1 -1
  52. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyCaseWidget/localizations.json +8 -0
  53. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/localizations.json +10 -0
  54. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MyPageWidget/localizations.json +10 -0
  55. package/tests/assets/original/components/createAll/Constellation/Pega_DXIL_MySearchbox/localizations.json +5 -0
  56. package/tests/assets/original/components/createAll/Launchpad/Pega_DXIL_MySearchbox/localizations.json +5 -0
  57. package/tests/functional/localCreateAllListDeleteAll.test.js +8 -8
  58. package/tests/functional/localLibCreateLibAlreadyDeleteLib.test.js +14 -14
  59. package/tests/functional/localLibCreateLibBuildLibDeleteLib.test.js +17 -17
  60. package/tests/functional/localLibCreateLibBuildLibListPubDeleteLib.test.js +20 -20
  61. package/tests/functional/localLibCreateLibDeleteLib.test.js +17 -17
  62. package/tests/functional/localLibCreateLibExportImportLib.test.js +27 -27
  63. package/tests/functional/localLibCreateLibExportLib.test.js +19 -19
  64. package/tests/functional/localLibCreateLibImportCompDeleteLib.test.js +14 -14
  65. package/tests/functional/localLibCreateLibListDeleteLib.test.js +22 -22
  66. package/tests/functional/localLibCreateLibListMoveDeleteLib.test.js +31 -31
  67. package/tests/functional/localLibCreateLibListSwitchDeleteLib.test.js +20 -20
  68. package/tests/functional/localLibCreateLibStatusDeleteLib.test.js +13 -29
  69. package/tests/functional/localLibCreateLibValidateDeleteLib.test.js +15 -15
  70. package/tests/functional/localLibCreateLibVersionDeleteLib.test.js +27 -27
  71. package/tests/functional/localLibCreateLibPermDeleteLib.test.js +0 -144
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.25.18",
3
+ "version": "0.25.20",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/cli.js CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  moveComponent,
33
33
  renameLibrary,
34
34
  restoreConfig,
35
+ restore,
35
36
  revertWebPack,
36
37
  promoteWebPack,
37
38
  showStatus,
@@ -63,6 +64,7 @@ const TASKS = {
63
64
  RENAME: 'rename',
64
65
  RENAME_LIB: 'renameLibrary',
65
66
  RESTORE_CONFIG: 'restoreConfig',
67
+ RESTORE_LIB: 'restore',
66
68
  QUARANTINE: 'quarantine',
67
69
  MOVE: 'moveComponent',
68
70
  LIST: 'list',
@@ -170,6 +172,10 @@ export default async (args = []) => {
170
172
  restoreConfig(options);
171
173
  break;
172
174
  }
175
+ case TASKS.RESTORE_LIB: {
176
+ restore(options);
177
+ break;
178
+ }
173
179
  case TASKS.QUARANTINE: {
174
180
  quarantine(options);
175
181
  break;
package/src/constants.js CHANGED
@@ -40,9 +40,11 @@ export const LP_DELETE_COMPONENT_SERVICE_REST_ENDPOINT =
40
40
  'pegalaunchpad/c11n/isolations/{isolationId}/v102/assetsUpdate';
41
41
 
42
42
  export const PUBLISH_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component_library';
43
- export const PUBLISH_COMPONENT_ARCHIVE_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component_archive';
43
+ export const PUBLISH_COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component_library_archive';
44
44
  export const LIST_COMPONENT_LIBRARIES_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/list_component_libraries';
45
+ export const LIST_COMPONENT_LIBRARY_ARCHIVES_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/list_component_library_archives';
45
46
  export const DELETE_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/delete_component_library';
47
+ export const COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/component_library_archive';
46
48
 
47
49
 
48
50
  export const FIELD_PATH = '/field';
@@ -5,7 +5,7 @@ import inquirer from 'inquirer';
5
5
  import { Listr } from 'listr2';
6
6
  import chalk from 'chalk';
7
7
 
8
- import { showVersion, getServerType, setServerType, getSubComponents, deleteLocalComponent, checkPathAccess, getComponents, getLibraryBased, setLibraryBased, forceDefaultsUpdate } from '../../util.js';
8
+ import { showVersion, getServerType, setServerType, getSubComponents, deleteLocalComponent, checkPathAccess, getComponents, getLibraryBasedCL, setLibraryBasedCL, forceDefaultsUpdate } from '../../util.js';
9
9
  import createAll from '../create-all/index.js';
10
10
  import create from '../create/index.js';
11
11
  import createLib from '../create-lib/index.js';
@@ -220,9 +220,9 @@ export default async options => {
220
220
  if (buildAssets) {
221
221
  // get current server type
222
222
  const savedServerType = await getServerType();
223
- const savedLibraryBased = getLibraryBased();
223
+ const savedLibraryBasedCL = getLibraryBasedCL();
224
224
 
225
- await setLibraryBased(false);
225
+ await setLibraryBasedCL(false);
226
226
 
227
227
  // Constellation
228
228
  await setServerType("infinity");
@@ -233,7 +233,7 @@ export default async options => {
233
233
  await createJestOriginalAssets(true);
234
234
 
235
235
  // Constellation Library
236
- await setLibraryBased(true);
236
+ await setLibraryBasedCL(true);
237
237
  await setServerType("infinity");
238
238
 
239
239
  await createJestLibraryAssets(false);
@@ -246,7 +246,7 @@ export default async options => {
246
246
 
247
247
  // restore serverType
248
248
  await setServerType(savedServerType);
249
- await setLibraryBased(savedLibraryBased);
249
+ await setLibraryBasedCL(savedLibraryBasedCL);
250
250
 
251
251
  }
252
252
 
@@ -80,3 +80,33 @@ addDebugLog("getCreateVersionComponentQuestions", "", "");
80
80
  },
81
81
  ];
82
82
  };
83
+
84
+
85
+ export const getCreateVersionComponentCLQuestions = async () => {
86
+ addDebugLog("getCreateVersionComponentCLQuestions", "", "");
87
+ const componentDefaults = getConfigDefaults();
88
+
89
+ // increment the version
90
+ const incrVersion = await getNextVersion();
91
+ console.log(`\nCurrent library: ${chalk.green(`${componentDefaults.currentOrgLib}`)}`);
92
+
93
+ return [
94
+ {
95
+ name: 'version',
96
+ message: 'Enter version ',
97
+ default: incrVersion,
98
+ validate: value => {
99
+ if (validateSemver(value)) {
100
+ return true;
101
+ }
102
+ return 'Please provide semver compatible version e.g 0.0.1';
103
+ }
104
+ },
105
+ {
106
+ name: 'copyExisting',
107
+ type: 'confirm',
108
+ message: 'Copy current components to new version ?',
109
+ default: true
110
+ },
111
+ ];
112
+ };
@@ -21,7 +21,7 @@ import {
21
21
  cleanUpTemp
22
22
  } from '../../util.js';
23
23
 
24
- import { getCreateVersionComponentQuestions, updateAllComponentsConfig } from './helper.js';
24
+ import { getCreateVersionComponentQuestions, updateAllComponentsConfig, getCreateVersionComponentCLQuestions } from './helper.js';
25
25
  import { showCurrentStatus } from '../show-status/index.js';
26
26
 
27
27
  export default async options => {
@@ -65,9 +65,17 @@ addDebugLog("createVersion", "", "+");
65
65
  copyExisting = !!(copyExist === 'Y' || copyExist === 'y' || copyExist === true || copyExist === 'true');
66
66
 
67
67
  } else {
68
- const questions = await getCreateVersionComponentQuestions();
69
- const answers = await inquirer.prompt(questions);
70
- ({ version, permBuild, copyExisting } = answers);
68
+ if (isLibraryBasedCL) {
69
+ const questions = await getCreateVersionComponentCLQuestions();
70
+ const answers = await inquirer.prompt(questions);
71
+ ({ version, copyExisting } = answers);
72
+ }
73
+ else {
74
+ const questions = await getCreateVersionComponentQuestions();
75
+ const answers = await inquirer.prompt(questions);
76
+ ({ version, permBuild, copyExisting } = answers);
77
+ }
78
+
71
79
  }
72
80
 
73
81
  if (isLibraryBasedCL) {
@@ -135,7 +135,7 @@ addDebugLog("getInfinityLibraries", '', "");
135
135
 
136
136
  // inquire
137
137
 
138
- let urlParams = `/AppName/${ApplicationName}/AppVersion/${ApplicationVersion}/ruleset/${rulesetName}/rulesetVersion/${rulesetVersion}`;
138
+ let urlParams = `/app-name/${ApplicationName}/app-version/${ApplicationVersion}/rulesetname/${rulesetName}/rulesetversion/${rulesetVersion}`;
139
139
  //let urlParams = `&ApplicationName=${ApplicationName}&ApplicationVersion=${ApplicationVersion}&RulesetName=${rulesetName}&RulesetVersion=${rulesetVersion}`;
140
140
  //urlParams = encodeURIComponent(urlParams);
141
141
 
@@ -3,7 +3,7 @@ import ora from 'ora';
3
3
 
4
4
  import chalk from 'chalk';
5
5
 
6
- import { showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deleteLocalLibrary, deleteLocalLibraryVersion, addDebugLog, getConfigDefaults, getLibraryBasedCL, getPegaServerConfig, deleteInfinityServerComponentLibrary } from '../../util.js';
6
+ import { showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deleteLocalLibrary, deleteLocalLibraryVersion, addDebugLog, getConfigDefaults, getLibraryBasedCL, getPegaServerConfig, deleteInfinityServerComponentLibrary, checkAccessTokenExpiration } from '../../util.js';
7
7
  import { deleteLib } from '@pega/constellation-dx-components-build-utils/index.js';
8
8
 
9
9
  import { getDeleteLibraryQuestions, getLibraryVersionQuestion, getRulesetAndVersionQuestion, SOURCE_OF_COMPONENT_TYPES, getInfinityLibraries } from './helper.js';
@@ -85,7 +85,12 @@ addDebugLog("deletePublished", "END", "-");
85
85
 
86
86
  }
87
87
  else {
88
+ // server
89
+
90
+ await checkAccessTokenExpiration();
91
+
88
92
  const isLibraryBasedCL = getLibraryBasedCL();
93
+
89
94
  if (isLibraryBasedCL) {
90
95
 
91
96
  const serverConfg = await getPegaServerConfig();
@@ -111,18 +111,18 @@ addDebugLog("getLibraryVersionQuestion", "", "");
111
111
  };
112
112
 
113
113
  export const getServerOrDirectoryQuestion = async () => {
114
- addDebugLog("getLibraryVersionQuestion", "", "");
115
-
116
- return [
117
- {
118
- name: 'exportTo',
119
- type: 'rawlist',
120
- message: `Export to`,
121
- choices: [{name: 'Local directory', value: 'Directory'}, {name: 'Server', value: 'Server'}],
122
- defaut: 'Directory'
123
- }
124
- ];
125
- };
114
+ addDebugLog("getLibraryVersionQuestion", "", "");
115
+
116
+ return [
117
+ {
118
+ name: 'exportTo',
119
+ type: 'rawlist',
120
+ message: `Export to`,
121
+ choices: [{name: 'Local directory', value: 'Directory'}, {name: 'Server', value: 'Server'}],
122
+ default: 'Directory'
123
+ }
124
+ ];
125
+ };
126
126
 
127
127
  export const getFullArchiveQuestions = async () => {
128
128
 
@@ -191,6 +191,7 @@ addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName},
191
191
 
192
192
  if (orgLibName === configDef.currentOrgLib && selectedVersion === configDef.buildVersion) {
193
193
 
194
+ /*
194
195
  let currentOrStore = currentOrArchive;
195
196
  if (currentOrArchive === "") {
196
197
  console.log("\nYou've selected the current working library/version.");
@@ -212,6 +213,11 @@ addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName},
212
213
  if (currentOrStore === "Current") {
213
214
  archiveBeforeStore = true;
214
215
  }
216
+ */
217
+
218
+ // We are just going to archive before store and not ask
219
+ archiveBeforeStore = true;
220
+
215
221
  }
216
222
 
217
223
  if (!fs.existsSync(exportPath)) {
@@ -1,10 +1,11 @@
1
1
  import chalk from 'chalk';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
+ import fetch from 'node-fetch';
4
5
  import { join } from 'path';
5
6
  import { Listr } from 'listr2';
6
- import { addDebugLog, getConfigDefaults, convertIntoPascalCase, getComponents, getComponentDirectoryPath, getDirectoryFiles, setConfigImportRelativePath, forceDefaultsUpdate } from '../../util.js';
7
- import { TASKS_CONFIG_JSON_FILENAME, TEMP_PATH, PACKAGE_JSON_FILENAME } from '../../constants.js';
7
+ import { addDebugLog, getHttpsAgent, getConfigDefaults, getPegaServerConfig, convertIntoPascalCase, getComponents, getComponentDirectoryPath, getDirectoryFiles, setConfigImportRelativePath, forceDefaultsUpdate, constructCompleteUrl } from '../../util.js';
8
+ import { TASKS_CONFIG_JSON_FILENAME, TEMP_PATH, PACKAGE_JSON_FILENAME, LIST_COMPONENT_LIBRARY_ARCHIVES_SERVICE_REST_ENDPOINT, COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT, TOKEN_PATH} from '../../constants.js';
8
9
 
9
10
 
10
11
 
@@ -229,6 +230,20 @@ export const updateTempArchive = async(libraryName, version, devBuild) => {
229
230
 
230
231
  }
231
232
 
233
+ export const getServerOrDirectoryQuestion = async () => {
234
+ addDebugLog("getLibraryVersionQuestion", "", "");
235
+
236
+ return [
237
+ {
238
+ name: 'importFrom',
239
+ type: 'rawlist',
240
+ message: `Import from`,
241
+ choices: [{name: 'Local directory', value: 'Directory'}, {name: 'Server', value: 'Server'}],
242
+ defaut: 'Directory'
243
+ }
244
+ ];
245
+ };
246
+
232
247
 
233
248
  export const getFilePathQuestions = async () => {
234
249
  addDebugLog("getFilePathQuestions", "", "");
@@ -304,7 +319,6 @@ addDebugLog("getFileNameQuestions", "", "");
304
319
  export const updateSavedFilePath = async(filePath) => {
305
320
  const currentDirectory = process.cwd();
306
321
  const arPathParts = currentDirectory.split(path.sep);
307
- const configDef = getConfigDefaults();
308
322
 
309
323
  let defaultPath = join(path.sep, arPathParts[0], arPathParts[1], arPathParts[2]);
310
324
 
@@ -345,3 +359,191 @@ export const updateSavedFilePath = async(filePath) => {
345
359
  }
346
360
 
347
361
  }
362
+
363
+
364
+
365
+
366
+
367
+ async function fetchComponentLibraryArchivesFromInfinity(apiUrl, headers) {
368
+ addDebugLog("fetchComponentLibraryArchivesFromInfinity", `apiUrl: ${apiUrl}`, "");
369
+ const serverConfig = await getPegaServerConfig();
370
+ return new Promise((resolve, reject) => {
371
+ let status = 500;
372
+ fetch(apiUrl, {
373
+ method: 'GET',
374
+ agent: getHttpsAgent(serverConfig),
375
+ headers
376
+ })
377
+ .then((response) => {
378
+ status = response.status;
379
+ if (status === 401) {
380
+ throw new Error('Error occurred in authentication. Please regenerate using authenticate');
381
+ }
382
+ else if (status === 404){
383
+ throw new Error('404: Server resource not found');
384
+ }
385
+ else if (status === 405){
386
+ throw new Error('405: Server method not allowed');
387
+ }
388
+ else if (status === 408){
389
+ throw new Error('408: Server timed out');
390
+ }
391
+ return response.json();
392
+ })
393
+ .then((resp) => {
394
+ // const respData = JSON.parse(resp);
395
+ if (status === 401) {
396
+ throw new Error('Error occurred in authentication. Please regenerate using authenticate');
397
+ // console.log(accessTokenUri, refreshToken);
398
+ /* TODO - Handle refresh_token */
399
+ } else if (status === 200) {
400
+ resolve(resp);
401
+ } else {
402
+ throw new Error(`${resp.message}`);
403
+ }
404
+ })
405
+ // eslint-disable-next-line prefer-promise-reject-errors
406
+ .catch((e) => reject(`${chalk.bold.red(e)}`));
407
+ });
408
+ }
409
+
410
+ export const getServerLibraryArchives = async() => {
411
+ addDebugLog("getServerLibraryArchives", '', "");
412
+
413
+ const defaultPegaServerConfig = await getPegaServerConfig();
414
+ let url = constructCompleteUrl(
415
+ defaultPegaServerConfig.server,
416
+ LIST_COMPONENT_LIBRARY_ARCHIVES_SERVICE_REST_ENDPOINT
417
+ );
418
+
419
+
420
+ return new Promise((resolve, reject) => {
421
+ try {
422
+ fs.readFile(TOKEN_PATH, 'utf8', (err, data) => {
423
+ if (err) {
424
+ // eslint-disable-next-line prefer-promise-reject-errors
425
+ reject(`\n${chalk.bold.red('Error occurred in authentication. Please regenerate using authenticate')}`);
426
+ }
427
+ if (data) {
428
+ const { access_token: accessToken, token_type: tokenType } = JSON.parse(data);
429
+
430
+ const headers = {};
431
+ headers.Authorization = `${tokenType} ${accessToken}`;
432
+
433
+ fetchComponentLibraryArchivesFromInfinity(url, headers)
434
+ .then((response) => resolve(response))
435
+ .catch((e) => reject(e));
436
+
437
+ }
438
+ });
439
+ } catch (error) {
440
+ console.log(`\n${chalk.bold.red(error)}`);
441
+ // eslint-disable-next-line prefer-promise-reject-errors
442
+ reject(`${chalk.bold.red(error)}`);
443
+ }
444
+ });
445
+
446
+ }
447
+
448
+
449
+ export const getLibraryArchiveQuestion = async (archiveVersions) => {
450
+ addDebugLog("getLibraryArchiveQuestion", `archiveVersions: ${archiveVersions}`, "");
451
+ return [
452
+ {
453
+ name: 'archiveData',
454
+ type: 'rawlist',
455
+ message: `Select an archive`,
456
+ choices: archiveVersions
457
+ }
458
+ ];
459
+ };
460
+
461
+
462
+
463
+ async function fetchComponentLibraryArchiveFromInfinity(apiUrl, headers) {
464
+ addDebugLog("fetchComponentLibraryArchivesFromInfinity", `apiUrl: ${apiUrl}`, "");
465
+ const serverConfig = await getPegaServerConfig();
466
+ return new Promise((resolve, reject) => {
467
+ let status = 500;
468
+ fetch(apiUrl, {
469
+ method: 'GET',
470
+ agent: getHttpsAgent(serverConfig),
471
+ headers
472
+ })
473
+ .then((response) => {
474
+ status = response.status;
475
+ if (status === 401) {
476
+ throw new Error('Error occurred in authentication. Please regenerate using authenticate');
477
+ }
478
+ else if (status === 404){
479
+ throw new Error('404: Server resource not found');
480
+ }
481
+ else if (status === 405){
482
+ throw new Error('405: Server method not allowed');
483
+ }
484
+ else if (status === 408){
485
+ throw new Error('408: Server timed out');
486
+ }
487
+ return response.json();
488
+ })
489
+ .then((resp) => {
490
+ // const respData = JSON.parse(resp);
491
+ if (status === 401) {
492
+ throw new Error('Error occurred in authentication. Please regenerate using authenticate');
493
+ // console.log(accessTokenUri, refreshToken);
494
+ /* TODO - Handle refresh_token */
495
+ } else if (status === 200) {
496
+ resolve(resp);
497
+ } else {
498
+ throw new Error(`${resp.message}`);
499
+ }
500
+ })
501
+ // eslint-disable-next-line prefer-promise-reject-errors
502
+ .catch((e) => reject(`${chalk.bold.red(e)}`));
503
+ });
504
+ }
505
+
506
+ export const getServerLibraryArchive = async(appName, fileName, fileType, ruleSet, ruleSetVersion) => {
507
+ addDebugLog("getServerLibraryArchives", '', "");
508
+
509
+ const defaultPegaServerConfig = await getPegaServerConfig();
510
+ let url = constructCompleteUrl(
511
+ defaultPegaServerConfig.server,
512
+ COMPONENT_LIBRARY_ARCHIVE_SERVICE_REST_ENDPOINT
513
+ );
514
+
515
+ let urlParams = `/app-name/${appName}/file-name/${fileName}/file-type/${fileType}/rulesetname/${ruleSet}/rulesetversion/${ruleSetVersion}`;
516
+ //let urlParams = `&ApplicationName=${ApplicationName}&ApplicationVersion=${ApplicationVersion}&RulesetName=${rulesetName}&RulesetVersion=${rulesetVersion}`;
517
+ //urlParams = encodeURIComponent(urlParams);
518
+
519
+
520
+ url = url.concat(urlParams);
521
+
522
+
523
+ return new Promise((resolve, reject) => {
524
+ try {
525
+ fs.readFile(TOKEN_PATH, 'utf8', (err, data) => {
526
+ if (err) {
527
+ // eslint-disable-next-line prefer-promise-reject-errors
528
+ reject(`\n${chalk.bold.red('Error occurred in authentication. Please regenerate using authenticate')}`);
529
+ }
530
+ if (data) {
531
+ const { access_token: accessToken, token_type: tokenType } = JSON.parse(data);
532
+
533
+ const headers = {};
534
+ headers.Authorization = `${tokenType} ${accessToken}`;
535
+
536
+ fetchComponentLibraryArchiveFromInfinity(url, headers)
537
+ .then((response) => resolve(response))
538
+ .catch((e) => reject(e));
539
+
540
+ }
541
+ });
542
+ } catch (error) {
543
+ console.log(`\n${chalk.bold.red(error)}`);
544
+ // eslint-disable-next-line prefer-promise-reject-errors
545
+ reject(`${chalk.bold.red(error)}`);
546
+ }
547
+ });
548
+
549
+ }