@pega/custom-dx-components 0.25.10 → 0.25.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.
Files changed (42) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +4 -3
  3. package/src/tasks/build-lib/index.js +7 -7
  4. package/src/tasks/delete/helper.js +6 -1
  5. package/src/tasks/delete-lib/index.js +2 -2
  6. package/src/tasks/export-archive/index.js +1 -1
  7. package/src/tasks/import-archive/index.js +2 -2
  8. package/src/tasks/init/template/package.json.mustache +1 -1
  9. package/src/tasks/list/helper.js +5 -1
  10. package/src/tasks/move/index.js +1 -1
  11. package/src/tasks/publish/helper.js +3 -1
  12. package/src/tasks/publish/index.js +34 -3
  13. package/src/tasks/publish-all/index.js +3 -1
  14. package/src/tasks/publish-lib/index.js +224 -5
  15. package/src/tasks/switch-lib/index.js +1 -1
  16. package/src/tasks/switch-version/index.js +1 -1
  17. package/src/util.js +72 -6
  18. package/tests/assets/library/components/{create/shared → createAll/Constellation/Pega_DXIL_MyDetails}/Avatar.tsx +1 -1
  19. package/tests/assets/{original/components/create/shared → library/components/createAll/Constellation/Pega_DXIL_MyDetails}/Operator.tsx +1 -1
  20. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyDetails/demo.stories.tsx +1 -1
  21. package/tests/assets/{original/components/create/shared → library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget}/Avatar.tsx +3 -4
  22. package/tests/assets/library/components/{create/shared → createAll/Constellation/Pega_DXIL_MyPageCaseWidget}/Operator.tsx +3 -3
  23. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyPageCaseWidget/index.tsx +1 -1
  24. package/tests/assets/library/components/createAll/Constellation/{shared → Pega_DXIL_MyTwoColumnDetails}/Avatar.tsx +6 -6
  25. package/tests/assets/{original/components/createAll/Constellation/shared → library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails}/Operator.tsx +3 -3
  26. package/tests/assets/library/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +1 -1
  27. package/tests/functional/localCreatePublishAllDeleteAll.test.js +1 -1
  28. package/tests/functional/localLibCreateLibExportImportLib.test.js +7 -7
  29. package/tests/functional/localLibCreateLibExportLib.test.js +3 -3
  30. package/tests/assets/library/components/createAll/Constellation/shared/Operator.tsx +0 -215
  31. package/tests/assets/original/components/create/shared/PConnProps.d.ts +0 -46
  32. package/tests/assets/original/components/create/shared/create-nonce.ts +0 -6
  33. package/tests/assets/original/components/create/shared/suggestions-handler.ts +0 -9
  34. package/tests/assets/original/components/createAll/Constellation/shared/Avatar.tsx +0 -76
  35. package/tests/assets/original/components/createAll/Constellation/shared/PConnProps.d.ts +0 -46
  36. package/tests/assets/original/components/createAll/Constellation/shared/create-nonce.ts +0 -6
  37. package/tests/assets/original/components/createAll/Constellation/shared/suggestions-handler.ts +0 -9
  38. package/tests/assets/original/components/createAll/Launchpad/shared/Avatar.tsx +0 -76
  39. package/tests/assets/original/components/createAll/Launchpad/shared/Operator.tsx +0 -215
  40. package/tests/assets/original/components/createAll/Launchpad/shared/PConnProps.d.ts +0 -46
  41. package/tests/assets/original/components/createAll/Launchpad/shared/create-nonce.ts +0 -6
  42. package/tests/assets/original/components/createAll/Launchpad/shared/suggestions-handler.ts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.25.10",
3
+ "version": "0.25.12",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -12,6 +12,7 @@ export const COMPONENTS_PATH = 'component';
12
12
  export const TOKEN_PATH = 'node_modules/@pega/custom-dx-components/.access_token';
13
13
  export const OOTB_COMPONENTS = 'node_modules/@pega/custom-dx-components/.ootb_components';
14
14
  export const LIBRARY_BASED = 'libraryMode';
15
+ export const LIBRARY_BASED_CL = 'libraryModeCL';
15
16
  export const SHARED_DIRECTORY = 'shared';
16
17
  export const SHOW_DEBUG = 'showDebug';
17
18
  export const ARCHIVES_PATH = 'store';
@@ -37,6 +38,8 @@ export const LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT =
37
38
  export const LP_DELETE_COMPONENT_SERVICE_REST_ENDPOINT =
38
39
  'pegalaunchpad/c11n/isolations/{isolationId}/v102/assetsUpdate';
39
40
 
41
+ export const PUBLISH_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/publish_component_library';
42
+
40
43
  export const FIELD_PATH = '/field';
41
44
  export const TEMPLATE_PATH = '/template';
42
45
  export const WIDGET_PATH = '/widget';
@@ -71,9 +74,7 @@ export const AUTHENTICATE_DEFAULTS = {
71
74
  export const SHARED_FILE_NAMES = [
72
75
  "suggestions-handler.ts",
73
76
  "PConnProps.d.ts",
74
- "create-nonce.ts",
75
- "Operator.tsx",
76
- "Avatar.tsx"
77
+ "create-nonce.ts"
77
78
  ];
78
79
 
79
80
  export const AUTHENTICATE_SCHEMA = {
@@ -132,7 +132,7 @@ export default async options => {
132
132
  process.exit();
133
133
  }
134
134
 
135
- if (options.params.length != 4) {
135
+ if (options.params.length != 7) {
136
136
  // internal so already called
137
137
  await showVersion();
138
138
  await checkLibraryAndArchives();
@@ -150,17 +150,17 @@ addDebugLog("buildLibrary", "", "+");
150
150
  let version;
151
151
  let devBuild;
152
152
 
153
- if (options.params.length >= 5) {
154
- version = options.params[3];
155
- const dBuild = options.params[4];
156
- devBuild = !!(dBuild === 'Y' || dBuild === 'y' || dBuild === true || dBuild === 'true');
157
- }
158
- else if (options.params.length === 4) {
153
+ if (options.params.length === 6) {
159
154
  // internally called from publish
160
155
  const orgLib = getConfigDefaults();
161
156
  version = orgLib.version;
162
157
  devBuild = await getConfigDevBuild();
163
158
  }
159
+ else if (options.params.length >= 5) {
160
+ version = options.params[3];
161
+ const dBuild = options.params[4];
162
+ devBuild = !!(dBuild === 'Y' || dBuild === 'y' || dBuild === true || dBuild === 'true');
163
+ }
164
164
  else {
165
165
  console.log(`\nLibrary ${chalk.bold.green(currentOrgLib)} `);
166
166
  const questions = await getBuildComponentQuestions(compDef.version);
@@ -14,7 +14,8 @@ import {
14
14
  getPegaServerConfig,
15
15
  standardizeStr,
16
16
  sanitize,
17
- addDebugLog
17
+ addDebugLog,
18
+ checkAccessTokenExpiration
18
19
  } from '../../util.js';
19
20
  import { getComponentsFromServer } from '../list/helper.js';
20
21
 
@@ -137,6 +138,10 @@ addDebugLog("deleteServerComponents", `sourceOfComponents: ${sourceOfComponents}
137
138
  const defaultPegaServerConfig = await getPegaServerConfig();
138
139
  const isLaunchpad = defaultPegaServerConfig.serverType === 'launchpad';
139
140
 
141
+ if (!isLaunchpad) {
142
+ await checkAccessTokenExpiration();
143
+ }
144
+
140
145
 
141
146
  if (isLaunchpad) {
142
147
  const questions = await getLaunchPadFilterQuestions();
@@ -152,7 +152,7 @@ addDebugLog("deleteLibraryVersion", "END", "-");
152
152
  if (archiveLibraries.includes(libraryName)) {
153
153
  const archLibVersions = await getLibraryArchivesVersions(libraryName, "");
154
154
  const lastVersion = archLibVersions[archLibVersions.length -1];
155
- const switchToFileName = `${libraryName}_${lastVersion}.zip`;
155
+ const switchToFileName = `${libraryName}_${lastVersion}.arch.zip`;
156
156
  await restoreFromArchive(switchToFileName, libraryName, lastVersion);
157
157
 
158
158
  await forceDefaultsUpdate();
@@ -166,7 +166,7 @@ addDebugLog("deleteLibraryVersion", "END", "-");
166
166
  const newLib = archiveLibraries[0];
167
167
  const archLibVersions = await getLibraryArchivesVersions(newLib, "");
168
168
  const lastVersion = archLibVersions[archLibVersions.length -1];
169
- const switchToFileName = `${newLib}_${lastVersion}.zip`;
169
+ const switchToFileName = `${newLib}_${lastVersion}.arch.zip`;
170
170
  await restoreFromArchive(switchToFileName, newLib, lastVersion);
171
171
 
172
172
 
@@ -170,7 +170,7 @@ export const exportArch = async(exportPath, orgLibName, selectedVersion, fullArc
170
170
  addDebugLog("exportArch", `exportPath: ${exportPath}, orgLibName: ${orgLibName}, selectedVersion: ${selectedVersion}`, "");
171
171
  const currentDirectory = process.cwd();
172
172
  const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${selectedVersion}`);
173
- const fileName = `${orgLibName}_${selectedVersion}.zip`;
173
+ const fileName = `${orgLibName}_${selectedVersion}.arch.zip`;
174
174
  const archFileName = join(archiveDirectory, fileName);
175
175
  const configDef = await getConfigDefaults();
176
176
 
@@ -186,7 +186,7 @@ export const moveComp = async(componentKey, orgLibName, version, copyShared, opt
186
186
  const currentDirectory = process.cwd();
187
187
  const tempDirectory = join(currentDirectory, TEMP_PATH);
188
188
  const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
189
- const fileName = `${orgLibName}_${version}.zip`;
189
+ const fileName = `${orgLibName}_${version}.arch.zip`;
190
190
  const archFileName = join(archiveDirectory, fileName);
191
191
 
192
192
 
@@ -372,7 +372,7 @@ addDebugLog("importArch", `filePath: ${filePath}, fileName: ${fileName}`, "");
372
372
  console.log(`You can switch to ${chalk.green(`${orgLibName}/${version}`)} via npm run switchLib.\n`);
373
373
  }
374
374
  else {
375
- const switchToFileName = `${orgLibName}_${version}.zip`;
375
+ const switchToFileName = `${orgLibName}_${version}.arch.zip`;
376
376
 
377
377
  const tasks = new Listr(
378
378
  [
@@ -106,7 +106,7 @@
106
106
  "@babel/preset-react": "^7.26.3",
107
107
  "@babel/preset-typescript": "^7.26.0",
108
108
  "@pega/configs": "^0.16.2",
109
- "@pega/custom-dx-components": "~0.25.10",
109
+ "@pega/custom-dx-components": "~0.25.12",
110
110
  "@pega/pcore-pconnect-typedefs": "^4.1.0-alpha.1",
111
111
  "@storybook/addon-actions": "^7.6.19",
112
112
  "@storybook/addon-essentials": "^7.6.19",
@@ -5,7 +5,7 @@ import fetch from 'node-fetch';
5
5
  import { join } from 'path';
6
6
 
7
7
  import { LIST_COMPONENT_SERVICE_REST_ENDPOINT, LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT, TOKEN_PATH, COMPONENT_SCHEMA, TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
8
- import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent, addDebugLog, getLibraryBased, getComponentsConfigs, getConfigDefaults } from '../../util.js';
8
+ import { constructCompleteUrl, getComponents, getPegaServerConfig, getHttpsAgent, addDebugLog, getLibraryBased, getComponentsConfigs, getConfigDefaults, checkAccessTokenExpiration } from '../../util.js';
9
9
 
10
10
  export const SOURCE_OF_COMPONENT_TYPES = {
11
11
  SERVER: 'Server',
@@ -208,6 +208,10 @@ addDebugLog("getComponentsFromServer", `library: ${library}, organization: ${org
208
208
  isLaunchpad ? LP_LIST_COMPONENT_SERVICE_REST_ENDPOINT : LIST_COMPONENT_SERVICE_REST_ENDPOINT
209
209
  );
210
210
 
211
+ if (!isLaunchpad) {
212
+ await checkAccessTokenExpiration;
213
+ }
214
+
211
215
 
212
216
 
213
217
  return new Promise((resolve, reject) => {
@@ -176,7 +176,7 @@ export const moveComp = async(componentKey, copyMove, orgLibName, version, copyS
176
176
  const currentDirectory = process.cwd();
177
177
  const tempDirectory = join(currentDirectory, TEMP_PATH);
178
178
  const archiveDirectory = join (currentDirectory, ARCHIVES_PATH, `${orgLibName}`, `${version}`);
179
- const fileName = `${orgLibName}_${version}.zip`;
179
+ const fileName = `${orgLibName}_${version}.arch.zip`;
180
180
  const archFileName = join(archiveDirectory, fileName);
181
181
  const currentCompPath = join(currentDirectory, "src", "components");
182
182
  const tempCompPath = join(tempDirectory, "src", "components");
@@ -17,6 +17,7 @@ import {
17
17
  import {
18
18
  PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
19
19
  LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
20
+ PUBLISH_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT,
20
21
  TOKEN_PATH
21
22
  } from '../../constants.js';
22
23
 
@@ -79,7 +80,8 @@ addDebugLog("getPublishComponentQuestions", `componentKey: ${componentKey}`, "")
79
80
  name: 'devBuild',
80
81
  type: 'confirm',
81
82
  message: 'Generate development build ?',
82
- default: defaultPegaConfig.devBuild
83
+ default: defaultPegaConfig.devBuild,
84
+ when: () => componentKey !== "LibraryMode"
83
85
  }
84
86
  ];
85
87
  };
@@ -6,7 +6,7 @@ import fs from 'fs';
6
6
  import validate from '../validator/index.js';
7
7
  import bundleComponent from '../bundle/index.js';
8
8
  import { lintComponent } from '../linter/index.js';
9
- import { getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives, getConfigDevBuild, checkJWTExpiration, getConfigDefaults } from '../../util.js';
9
+ import { getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives, getConfigDevBuild, checkAccessTokenExpiration, checkJWTExpiration, getConfigDefaults } from '../../util.js';
10
10
 
11
11
  import { getPublishComponentQuestions, publishComponentToServer, zipComponent } from './helper.js';
12
12
  import { default as buildLibrary } from '../build-lib/index.js';
@@ -24,20 +24,21 @@ export default async options => {
24
24
 
25
25
  addDebugLog("publish", "", "+");
26
26
 
27
+ await checkAccessTokenExpiration();
28
+
27
29
  if (isLibraryBased) {
28
30
 
29
31
  await checkJWTExpiration();
30
32
 
31
33
  const devBuild = await getConfigDevBuild();
32
34
  let okToPublish = false;
35
+ // let content;
33
36
 
34
37
  const orgLib = getConfigDefaults();
35
38
  const currentOrgLib = orgLib.currentOrgLib;
36
39
  // const currentVersion = devBuild ? `${orgLib.version}-dev`: orgLib.version;
37
40
  const currentVersion = orgLib.buildVersion;
38
41
 
39
-
40
-
41
42
  const publishThisVersion = await inquirer.prompt([
42
43
  {
43
44
  name: 'confirmPublish',
@@ -51,6 +52,33 @@ addDebugLog("publish", "", "+");
51
52
  okToPublish = true;
52
53
  }
53
54
 
55
+
56
+
57
+ if (okToPublish) {
58
+ if (options.params.length >= 8) {
59
+ // const rulesetName = options.params[3];
60
+ // const rulesetVersion = options.params[4]
61
+
62
+
63
+ // content = { rulesetName, rulesetVersion };
64
+ } else {
65
+ // VS Code pluggin would send in the component
66
+ let paramComponentKey;
67
+ if (options.params.length == 4) {
68
+ paramComponentKey = options.params[3];
69
+ }
70
+
71
+ const questions = await getPublishComponentQuestions("LibraryMode");
72
+ const answers = await inquirer.prompt(questions);
73
+
74
+ // content = {
75
+ // ...answers
76
+ // };
77
+ options.params.push(answers.rulesetName);
78
+ options.params.push(answers.rulesetVersion);
79
+ }
80
+ }
81
+
54
82
  if (okToPublish && !devBuild) {
55
83
  okToPublish = false;
56
84
  console.log("");
@@ -71,8 +99,11 @@ addDebugLog("publish", "", "+");
71
99
  // marking as internal, so no questions will be ask
72
100
  options.params.push("internal");
73
101
 
102
+
74
103
  await buildLibrary(options);
75
104
  await publishLibrary(options);
105
+
106
+
76
107
  }
77
108
 
78
109
  return true;
@@ -5,7 +5,7 @@ import chalk from 'chalk';
5
5
  import validate from '../validator/index.js';
6
6
  import bundleComponent from '../bundle/index.js';
7
7
  import { lintComponent } from '../linter/index.js';
8
- import { getComponents, getComponentDirectoryPath, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives } from '../../util.js';
8
+ import { getComponents, getComponentDirectoryPath, checkAccessTokenExpiration, showVersion, getLibraryBased, addDebugLog, getPegaServerConfig, updateServerConfigRuleSetAndVersion, checkLibraryAndArchives } from '../../util.js';
9
9
 
10
10
  import {
11
11
  getPublishComponentQuestions,
@@ -72,6 +72,8 @@ export default async options => {
72
72
  await showVersion();
73
73
  await checkLibraryAndArchives();
74
74
 
75
+ await checkAccessTokenExpiration();
76
+
75
77
  addDebugLog("publishAll", "", "+");
76
78
 
77
79
  const components = await getComponents();
@@ -1,15 +1,25 @@
1
1
  import inquirer from 'inquirer';
2
2
  import { Listr } from 'listr2';
3
3
  import chalk from 'chalk';
4
+ import fetch from 'node-fetch';
5
+ import archiver from 'archiver';
6
+ import path from 'path';
7
+ import fs from 'fs';
4
8
 
5
9
  import validate from '../validator/index.js';
6
10
  import { lintComponent } from '../linter/index.js';
7
- import { getComponentDirectoryPath, showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, deletePublishExtras, addDebugLog, checkLibraryAndArchives, checkJWTExpiration, getConfigDefaults } from '../../util.js';
11
+ import { constructCompleteUrl, getComponentDirectoryPath, getHttpsAgent, getPegaServerConfig, showVersion, getC11NB2STokenAndStaticServer, getLocalLibraryVersions, getLibraryBased, getLibraryBasedCL, deletePublishExtras, addDebugLog, checkLibraryAndArchives, checkJWTExpiration, getConfigDefaults } from '../../util.js';
8
12
 
9
13
  import { publishLib, listLibJSONResponse, deleteLibVersion } from '@pega/constellation-dx-components-build-utils/index.js';
10
14
 
11
15
  import { getLibraryVersionQuestion } from './helper.js';
12
16
 
17
+ import {
18
+ LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT,
19
+ PUBLISH_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT,
20
+ TOKEN_PATH
21
+ } from '../../constants.js';
22
+
13
23
 
14
24
  export function getCustomTasks(componentKey, sourceMap, devBuild, options) {
15
25
  addDebugLog("getCustomTasks", `componentKey: ${componentKey}, sourceMap: ${sourceMap}, devBuild: ${devBuild}`, "");
@@ -54,6 +64,191 @@ addDebugLog("doesLibraryExist", `libraryName: ${libraryName}, libraryVersion: ${
54
64
  }
55
65
 
56
66
 
67
+ export const zipLibraryComponent = async (libraryName, version) => {
68
+ const currentDirectory = process.cwd();
69
+ const libraryDirName = `${libraryName}/${version}`;
70
+ const libraryDirectory = path.join(currentDirectory, libraryDirName);
71
+ const componentsConfigJson = `${libraryDirectory}/componentsconfig.json`;
72
+
73
+
74
+ const archive = archiver('zip', { zlib: { level: 9 } });
75
+ const zipChunks = [];
76
+ archive.on('data', chunk => zipChunks.push(chunk));
77
+
78
+ // Add src directory
79
+ archive.directory(libraryDirectory, 'src');
80
+
81
+ // Add config.json file
82
+ if (fs.existsSync(componentsConfigJson)) {
83
+ archive.file(componentsConfigJson, { name: path.basename(componentsConfigJson) });
84
+ }
85
+
86
+
87
+ await archive.finalize();
88
+
89
+ const zipBuffer = Buffer.concat(zipChunks);
90
+ console.log(chalk.green(`component zipped with size: ${Math.ceil(zipBuffer.length / 1024)} KB`));
91
+ const zipContent = zipBuffer.toString('base64');
92
+
93
+ const configContent = Buffer.from(fs.readFileSync(componentsConfigJson)).toString();
94
+
95
+ // if (fs.existsSync(libraryDirectory)) {
96
+ // fs.rm(libraryDirectory, { recursive: true }, err => {
97
+ // if (err) {
98
+ // throw err;
99
+ // }
100
+ // });
101
+ // }
102
+
103
+ return { zipContent, configContent };
104
+ };
105
+
106
+
107
+ export const publishComponentLibraryToServer = async (data, doFetch) => {
108
+ addDebugLog("publishComponentToServer", `data: ${data}`, "");
109
+ const { configContent, zipContent, rulesetName, rulesetVersion, libraryName, version } = data;
110
+
111
+ const defaultPegaServerConfig = await getPegaServerConfig();
112
+ const { serverType, isolationId } = defaultPegaServerConfig;
113
+ const isLaunchpad = serverType === 'launchpad';
114
+ const launchpadRestEndpoint = LP_PUBLISH_COMPONENT_SERVICE_REST_ENDPOINT.replace(
115
+ '{isolationId}',
116
+ isolationId || 'undefined'
117
+ );
118
+ let apiBody;
119
+
120
+ if (isLaunchpad) {
121
+ // currently no launchpad records to rule resolve a library
122
+
123
+ // apiBody = {
124
+ // type: 'CustomComponent',
125
+ // zipContent,
126
+ // componentName: JSON.parse(configContent).componentKey,
127
+ // pxUpdateDateTime: '',
128
+ // environmentID: defaultPegaServerConfig.isolationId
129
+ // };
130
+ } else {
131
+ apiBody = {
132
+ configContent,
133
+ zipContent,
134
+ publishFor: 'constellation',
135
+ rulesetName,
136
+ rulesetVersion,
137
+ libraryName,
138
+ version,
139
+ category: ''
140
+ };
141
+ }
142
+
143
+ const defaultPegaConfig = await getPegaServerConfig();
144
+ const url = constructCompleteUrl(
145
+ defaultPegaConfig.server,
146
+ isLaunchpad ? launchpadRestEndpoint : PUBLISH_COMPONENT_LIBRARY_SERVICE_REST_ENDPOINT
147
+ );
148
+
149
+ if (doFetch) {
150
+ try {
151
+ const OauthData = fs.readFileSync(TOKEN_PATH, 'utf8');
152
+ if (OauthData) {
153
+ const {
154
+ access_token: accessToken,
155
+ token_type: tokenType
156
+ // refresh_token: refreshToken
157
+ } = JSON.parse(OauthData);
158
+ let status = 500;
159
+ let headers = {};
160
+
161
+ if (isLaunchpad) {
162
+ headers.cookie = `Pega-AAT=${accessToken}`;
163
+ headers['Content-Type'] = 'application/json';
164
+ } else {
165
+ headers.Authorization = `${tokenType} ${accessToken}`;
166
+ }
167
+
168
+ const response = await fetch(url, {
169
+ method: 'POST',
170
+ agent: getHttpsAgent(defaultPegaConfig),
171
+ headers,
172
+ body: JSON.stringify(apiBody)
173
+ });
174
+
175
+ status = response.status;
176
+ if (!response.ok) {
177
+ if (status === 401) {
178
+ throw new Error(
179
+ 'Error occurred in authentication. Please regenerate using authenticate'
180
+ );
181
+ // console.log(accessTokenUri, refreshToken);
182
+ /* TODO - Handle refresh_token */
183
+ } else if (status === 404) {
184
+ throw new Error('404: Server resource not found');
185
+ } else if (status === 405) {
186
+ throw new Error('405: Server method not allowed');
187
+ } else if (status === 408) {
188
+ throw new Error('408: Server timed out');
189
+ } else if (response.status === 403) {
190
+ throw new Error('Error forbidden: User does not have privileges to Publish.');
191
+ }
192
+ }
193
+
194
+ try {
195
+ const respData = isLaunchpad ? await response.text() : await response.json();
196
+ console.log(chalk.bold.green(`Success : ${isLaunchpad ? respData : respData.message}`));
197
+
198
+ if (status === 500) {
199
+ status = 999;
200
+ throw new Error(respData.message);
201
+ }
202
+ } catch (err) {
203
+ if (status === 500) {
204
+ throw new Error(
205
+ `Error occurred in authentication. Please regenerate using authenticate`
206
+ );
207
+ } else if (status === 999) {
208
+ throw new Error(err);
209
+ }
210
+ }
211
+ } else {
212
+ throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
213
+ }
214
+ } catch (err) {
215
+ // throw new Error(`Error occurred in authentication. Please regenerate using authenticate`);
216
+ throw new Error(err);
217
+ }
218
+ }
219
+ };
220
+
221
+
222
+ export const publishUILibraryComponentToInfinity = async (content) => {
223
+ // const compDef = getConfigDefaults();
224
+ // const organization = compDef.organization;
225
+ // const library = compDef.library;
226
+ // const version = compDef.buildVersion;
227
+ // // const currentOrgLib = organization.concat('_').concat(library);
228
+ // const currentOrgLib = compDef.currentOrgLib;
229
+
230
+ console.log(chalk.green(`Publishing ${content.libraryName}/${content.version} to server...`));
231
+
232
+ const fromZip = await zipLibraryComponent(content.libraryName, content.version);
233
+
234
+ content = { ...fromZip, ...content };
235
+
236
+ // console.log(content);
237
+ try {
238
+ await publishComponentLibraryToServer(content, true );
239
+ // console.log(chalk.green.bold(`Success: Published ${content.libraryName}/${content.version} to server as a CL.`));
240
+ }
241
+ catch (ex) {
242
+ console.log(chalk.bold.red(err.toString()));
243
+ }
244
+
245
+
246
+
247
+ }
248
+
249
+
250
+
251
+
57
252
  export const publishNewLibraryAsync = async (libraryName, version, checkDeleted = false) => {
58
253
  addDebugLog("publishNewLibraryAsync", `libraryName: ${libraryName}, version: ${version}, checkDeleted: ${checkDeleted} `, "");
59
254
 
@@ -87,6 +282,9 @@ addDebugLog("publishLib", "services call", "");
87
282
  await publishLib(libraryName, version, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
88
283
  addDebugLog("deleteLib", "services end", "");
89
284
 
285
+
286
+
287
+
90
288
  }
91
289
 
92
290
 
@@ -97,7 +295,7 @@ export default async (options) => {
97
295
  process.exit();
98
296
  }
99
297
 
100
- if (options.params.length != 4) {
298
+ if (options.params.length >= 4) {
101
299
  // internal so already called
102
300
  await showVersion();
103
301
  await checkLibraryAndArchives();
@@ -111,21 +309,29 @@ addDebugLog("publishLibrary", "", "+");
111
309
  let version;
112
310
  let devBuild;
113
311
  let internalPublish = false;
312
+ let rulesetName;
313
+ let rulesetVersion;
114
314
 
115
315
  let libraryName;
116
316
  let noRealPublish = false;
117
317
 
118
318
 
119
- if (options.params.length === 5) {
319
+ if (options.params.length === 7) {
120
320
  libraryName = options.params[3];
121
321
  version = options.params[4];
322
+ rulesetName = options.params[5];
323
+ rulesetVersion = options.params[6];
122
324
  }
123
- else if (options.params.length === 6) {
325
+ else if (options.params.length === 8) {
124
326
  libraryName = options.params[3];
125
327
  version = options.params[4];
328
+ rulesetName = options.params[5];
329
+ rulesetVersion = options.params[6];
126
330
  noRealPublish = true;
127
331
  }
128
- else if (options.params.length === 4) {
332
+ else if (options.params.length === 6) {
333
+ rulesetName = options.params[3];
334
+ rulesetVersion = options.params[4];
129
335
  // internal call from publish
130
336
  internalPublish = true;
131
337
  const orgLib = getConfigDefaults();
@@ -181,6 +387,7 @@ addDebugLog("publishLibrary", "", "+");
181
387
 
182
388
  let okToPublish = true;
183
389
 
390
+
184
391
  // this check matches check below, but for JEST, we don't want to go any further, just verifying if will
185
392
  // be caught
186
393
  if (noRealPublish && !version.includes("-dev")) {
@@ -212,6 +419,8 @@ addDebugLog("publishLibrary", "", "+");
212
419
 
213
420
  if (okToPublish) {
214
421
 
422
+ // /*
423
+
215
424
  let libVersionExists = await doesLibraryExist(libraryName, version);
216
425
  let overrideExisting = false;
217
426
  let checkDeleted = false;
@@ -254,6 +463,16 @@ addDebugLog("publishLibrary", "END", "-");
254
463
  // need a timeout to give services time to delete the library
255
464
  // setTimeout( function(){ await publishNewLibraryAsync(libraryName, version, checkDeleted)}, 700 );
256
465
  await publishNewLibraryAsync(libraryName, version, checkDeleted);
466
+ // */
467
+
468
+ // developer test
469
+ const isLibraryBasedCL = getLibraryBasedCL();
470
+ if (isLibraryBasedCL) {
471
+ let content = { libraryName, version, rulesetName, rulesetVersion };
472
+
473
+ await publishUILibraryComponentToInfinity(content);
474
+ }
475
+
257
476
  }
258
477
 
259
478
  }
@@ -103,7 +103,7 @@ addDebugLog("switchLibrary", "", "+");
103
103
  const existingOrgLib = orgLib.currentOrgLib;
104
104
  let oldVersion = orgLib.buildVersion;
105
105
 
106
- const switchToFileName = `${newOrgLib}_${newVersion}.zip`;
106
+ const switchToFileName = `${newOrgLib}_${newVersion}.arch.zip`;
107
107
 
108
108
  console.log("");
109
109
 
@@ -75,7 +75,7 @@ addDebugLog("switchVersion", "", "+");
75
75
  const existingOrgLib = orgLib.currentOrgLib;
76
76
  const oldVersion = orgLib.buildVersion;
77
77
 
78
- const switchToFileName = `${existingOrgLib}_${newVersion}.zip`;
78
+ const switchToFileName = `${existingOrgLib}_${newVersion}.arch.zip`;
79
79
 
80
80
  console.log("");
81
81