@pega/custom-dx-components 0.24.15 → 0.242.1

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 (69) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +32 -2
  3. package/src/constants.js +9 -0
  4. package/src/tasks/authenticate/index.js +12 -1
  5. package/src/tasks/build-lib/helper.js +71 -0
  6. package/src/tasks/build-lib/index.js +165 -0
  7. package/src/tasks/create/index.js +59 -6
  8. package/src/tasks/create/templates/Constellation/Field/Icon-Button-URL/index.tsx.mustache +1 -0
  9. package/src/tasks/create/templates/Constellation/Template/DETAILS/Avatar.tsx.mustache +78 -0
  10. package/src/tasks/create/templates/Constellation/Template/DETAILS/HighlightRender.tsx.mustache +1 -1
  11. package/src/tasks/create/templates/Constellation/Template/DETAILS/Operator.tsx.mustache +218 -0
  12. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.tsx.mustache +46 -13
  13. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.tsx.mustache +2 -2
  14. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.ts.mustache +55 -0
  15. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/Avatar.tsx.mustache +78 -0
  16. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/HighlightRender.tsx.mustache +1 -1
  17. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/Operator.tsx.mustache +218 -0
  18. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.tsx.mustache +46 -12
  19. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.tsx.mustache +2 -2
  20. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.ts.mustache +55 -0
  21. package/src/tasks/create/templates/Constellation/Template/FORM/index.tsx.mustache +1 -1
  22. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.tsx.mustache +2 -2
  23. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.tsx.mustache +1 -0
  24. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/index.tsx.mustache +1 -0
  25. package/src/tasks/create/templates/Launchpad/Widget/PAGE/index.tsx.mustache +1 -0
  26. package/src/tasks/create-all/index.js +57 -6
  27. package/src/tasks/delete/index.js +8 -2
  28. package/src/tasks/delete-all/index.js +8 -2
  29. package/src/tasks/delete-lib/helper.js +75 -0
  30. package/src/tasks/delete-lib/index.js +97 -0
  31. package/src/tasks/index.js +5 -0
  32. package/src/tasks/init/template/package.json.mustache +32 -9
  33. package/src/tasks/init/template/tasks.config.json +3 -2
  34. package/src/tasks/list/index.js +9 -3
  35. package/src/tasks/list-lib/helper.js +72 -0
  36. package/src/tasks/list-lib/index.js +75 -0
  37. package/src/tasks/promote-webpack/index.js +8 -1
  38. package/src/tasks/promote-webpack/webpack.config.js +26 -0
  39. package/src/tasks/publish/index.js +8 -1
  40. package/src/tasks/publish-all/index.js +8 -1
  41. package/src/tasks/publish-lib/helper.js +53 -0
  42. package/src/tasks/publish-lib/index.js +212 -0
  43. package/src/tasks/rename-lib/index.js +353 -0
  44. package/src/tasks/revert-webpack/index.js +8 -1
  45. package/src/util.js +201 -2
  46. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/Avatar.tsx +78 -0
  47. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/Operator.tsx +215 -0
  48. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/demo.stories.tsx +46 -13
  49. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/index.tsx +2 -2
  50. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/mock.ts +55 -0
  51. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyForm/index.tsx +1 -1
  52. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/Avatar.tsx +78 -0
  53. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/Operator.tsx +215 -0
  54. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +46 -12
  55. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/index.tsx +2 -2
  56. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/mock.ts +55 -0
  57. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnForm/index.tsx +2 -2
  58. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/Avatar.tsx +78 -0
  59. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/Operator.tsx +215 -0
  60. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/demo.stories.tsx +46 -13
  61. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/index.tsx +2 -2
  62. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/mock.ts +55 -0
  63. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyForm/index.tsx +1 -1
  64. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/Avatar.tsx +78 -0
  65. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/Operator.tsx +215 -0
  66. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/demo.stories.tsx +46 -12
  67. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/index.tsx +2 -2
  68. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/mock.ts +55 -0
  69. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnForm/index.tsx +2 -2
@@ -0,0 +1,353 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import { promisify } from 'util';
4
+ import { join } from 'path';
5
+
6
+ import inquirer from 'inquirer';
7
+ import ncp from 'ncp';
8
+ import chalk from 'chalk';
9
+
10
+ import { checkPathAccess, showVersion, getComponentsObj, getDirectoryFiles, getPegaServerConfig, getLibraryBased, deleteLocalLibrary, getC11NB2STokenAndStaticServer, updateComponentDefaultLibrary, updateDefaultOrganization } from '../../util.js';
11
+ import { TASKS_CONFIG_JSON_FILENAME, COMPONENTS_DIRECTORY_PATH, COMPONENTS_PATH } from '../../constants.js';
12
+
13
+ import { buildLib } from '@pega/constellation-dx-components-build-utils/index.js';
14
+
15
+ export const DXCB_CONFIG_INTERNAL_JSON_FILENAME = 'src/dxcb.config.json';
16
+ const currentDirectory = process.cwd();
17
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
18
+
19
+ const isLibraryBased = await getLibraryBased();
20
+
21
+
22
+ import {
23
+ convertIntoPascalCase,
24
+ getComponentDirectoryPath,
25
+ getPegaConfig,
26
+ getComponentDefaults,
27
+ getComponents,
28
+ sanitize
29
+ } from '../../util.js';
30
+ import { deleteLocalComponents } from '@pega/custom-dx-components/src/tasks/delete/helper.js';
31
+
32
+ const copy = promisify(ncp);
33
+
34
+
35
+ export const getOrgLib = async () => {
36
+ const defaultPegaConfig = await getPegaServerConfig();
37
+
38
+ await checkPathAccess(pegaConfigJsonPath);
39
+
40
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
41
+ data = data && JSON.parse(data);
42
+
43
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
44
+ console.error(`${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`);
45
+ process.exit(1);
46
+ }
47
+
48
+ const componentData = data[COMPONENTS_PATH];
49
+
50
+ let library;
51
+ ({ library } = componentData);
52
+ let { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
53
+
54
+ const componentDefaults = await getComponentDefaults();
55
+ componentDefaults.library = library;
56
+ componentDefaults.organization = organization;
57
+
58
+ return componentDefaults;
59
+ }
60
+
61
+ export const updateConfig = async (
62
+ {
63
+ oldComponentKey,
64
+ newComponentKey,
65
+ library,
66
+ organization,
67
+ componentName,
68
+ componentLabel,
69
+ version,
70
+ description,
71
+ allowedApplications,
72
+ targetDirectory,
73
+ },
74
+ options,
75
+ onlyCompanion = false
76
+ ) => {
77
+
78
+ let configData = fs.readFileSync(join(targetDirectory, "/config.json"), { encoding: 'utf8' });
79
+ configData = configData && JSON.parse(configData);
80
+
81
+ configData.name = newComponentKey;
82
+ configData.label = componentLabel;
83
+ configData.organization = organization;
84
+ if (configData.componentKey) configData.componentKey = newComponentKey;
85
+ configData.library = library;
86
+ configData.version = version;
87
+ configData.description = (description != '') ? description : componentLabel;
88
+
89
+ configData.allowedApplications = allowedApplications;
90
+
91
+ // stringify "4", makes the json string look like JSON in the file, formated instead of a single line
92
+ fs.writeFileSync(join(targetDirectory, "/config.json"), JSON.stringify(configData, null, 4), { encoding: 'utf8' });
93
+
94
+ };
95
+
96
+ export const updateFile = async (
97
+ fileName,
98
+ oldComponentKeyPC,
99
+ newComponentKeyPC,
100
+ targetDirectory,
101
+ ) => {
102
+
103
+ let fileData = fs.readFileSync(join(targetDirectory, "/", fileName), { encoding: 'utf8' });
104
+
105
+ if (fileData.indexOf(oldComponentKeyPC) >= 0) {
106
+ fileData = fileData.replaceAll(oldComponentKeyPC, newComponentKeyPC);
107
+
108
+ fs.writeFileSync(join(targetDirectory, "/", fileName), fileData, { encoding: 'utf8' });
109
+ }
110
+
111
+ };
112
+
113
+ export const renameLibrary = async ({library, organization}, options) => {
114
+
115
+ const compDef = await getOrgLib();
116
+ const currentOrganization = compDef.organization;
117
+ const currentLibrary = compDef.library;
118
+ const currentVersion = compDef.version;
119
+
120
+ let compVersion;
121
+
122
+ const tokenAndStaticServer = await getC11NB2STokenAndStaticServer();
123
+
124
+ if (tokenAndStaticServer.C11NB2S === undefined) {
125
+ console.log(chalk.redBright("Need to authenticate, missing services token.\nBuilding a library requires authentication to acquire a token to build."));
126
+ process.exit(1);
127
+
128
+ }
129
+
130
+ const currentOrgLib = currentOrganization.concat("_").concat(currentLibrary);
131
+ const newOrgLib = organization.concat("_").concat(library);
132
+
133
+ // reaname all the components
134
+ const components = await getComponents();
135
+ for (const index in components) {
136
+ const componentKey = components[index];
137
+ const componentName = componentKey.split('_')[2];
138
+ const currentDirectory = await getComponentDirectoryPath(componentKey);
139
+
140
+ let configData = fs.readFileSync(join(currentDirectory, "/config.json"), { encoding: 'utf8' });
141
+ configData = configData && JSON.parse(configData);
142
+
143
+ const componentLabel = configData.label.substring(0, configData.label.indexOf("(")).concat(`(${newOrgLib})`);
144
+ const description = configData.description.substring(0, configData.description.indexOf("(")).concat(`(${newOrgLib})`);
145
+ const version = configData.version;
146
+ compVersion = version;
147
+ const allowedApplications = configData.allowedApplications;
148
+
149
+ await renameComponent({library, organization, componentKey, componentName, componentLabel,
150
+ version, description, allowedApplications}, options);
151
+
152
+
153
+
154
+ }
155
+
156
+
157
+ // delete and rebuild library
158
+ try {
159
+ await deleteLocalLibrary(currentOrgLib);
160
+ }
161
+ catch (ex) {}
162
+
163
+
164
+ // update config
165
+ await updateComponentDefaultLibrary(library);
166
+ await updateDefaultOrganization(organization);
167
+
168
+ // call constellation-dx-components-build-utils build library, which will create a directory of the "buildLibName"
169
+ // with subdirectories for each version.
170
+ // If "buildDev", we append to version "-dev". Currently, only "-dev" versions, when published, can be deleted.
171
+ buildLib(newOrgLib, compVersion, tokenAndStaticServer.C11NB2S, tokenAndStaticServer.appStaticContentServer);
172
+
173
+
174
+
175
+
176
+ }
177
+
178
+
179
+ export const renameComponent = async (
180
+ {
181
+ library,
182
+ organization,
183
+ componentKey,
184
+ componentName,
185
+ componentLabel,
186
+ version,
187
+ description,
188
+ allowedApplications
189
+ },
190
+ options,
191
+ onlyCompanion = false
192
+ ) => {
193
+
194
+
195
+ let pegaConfig = await getPegaConfig();
196
+
197
+ const newComponentKey = `${organization}_${library}_${componentName}`;
198
+
199
+ const oldComponentKey = componentKey;
200
+ const newComponentKeyPC = convertIntoPascalCase(newComponentKey);
201
+ const oldComponentKeyPC = convertIntoPascalCase(oldComponentKey);
202
+
203
+ const currentDirectory = await getComponentDirectoryPath(componentKey);
204
+ const targetDirectory = await getComponentDirectoryPath(newComponentKey);
205
+
206
+
207
+
208
+
209
+ // custom component
210
+ try {
211
+ fs.renameSync(currentDirectory, targetDirectory);
212
+ } catch(err) {
213
+ console.log(err)
214
+ }
215
+
216
+ const targetFileList = await getDirectoryFiles(targetDirectory);
217
+
218
+ for (var fileIndex in targetFileList) {
219
+ const fileName = targetFileList[fileIndex];
220
+
221
+ if (fileName === "config.json") {
222
+ await updateConfig(
223
+ {
224
+ oldComponentKey,
225
+ newComponentKey,
226
+ componentName,
227
+ componentLabel,
228
+ library,
229
+ version,
230
+ description,
231
+ allowedApplications,
232
+ organization,
233
+ targetDirectory,
234
+ },
235
+ options
236
+ );
237
+ }
238
+ else {
239
+ await updateFile(
240
+ fileName,
241
+ oldComponentKeyPC,
242
+ newComponentKeyPC,
243
+ targetDirectory );
244
+
245
+ }
246
+
247
+ } // for
248
+
249
+
250
+ console.log(chalk.green(`Component ${oldComponentKey} renamed to ${newComponentKey}`));
251
+
252
+ };
253
+
254
+
255
+
256
+
257
+
258
+ export default async options => {
259
+ if (!isLibraryBased) {
260
+ console.log(`Command only supported for ${chalk.bold.green('library based')} components.`)
261
+ process.exit();
262
+ }
263
+
264
+ showVersion();
265
+
266
+ await checkPathAccess(pegaConfigJsonPath);
267
+
268
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
269
+ data = data && JSON.parse(data);
270
+
271
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
272
+ console.error(
273
+ `${chalk.red.bold('ERROR')} Could not able find components directory path in config.json`
274
+ );
275
+ process.exit(1);
276
+ }
277
+
278
+ const componentData = data[COMPONENTS_PATH];
279
+
280
+ const { library } = componentData;
281
+ const { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
282
+
283
+ let componentDefaults = await getComponentDefaults();
284
+ componentDefaults.library = library;
285
+
286
+ const localComponents = await getComponentsObj();
287
+
288
+
289
+ if (options.params.length >= 11) {
290
+ const organization = options.params[6];
291
+ const library = options.params[8];
292
+
293
+
294
+ await renameLibrary(
295
+ {
296
+ library,
297
+ organization
298
+ },
299
+ options
300
+ );
301
+
302
+ }
303
+ else {
304
+ const questions = [
305
+ {
306
+ name: 'organization',
307
+ message: 'Enter new component organization',
308
+ default: organization,
309
+ validate: value => {
310
+ if (value) {
311
+ return true;
312
+ }
313
+ return 'Please provide value for organization';
314
+ }
315
+ },
316
+ {
317
+ name: 'library',
318
+ message: 'Enter new library name',
319
+ default: componentDefaults.library,
320
+ validate: value => {
321
+ /* value should not be empty
322
+ It should not have spaces
323
+ It should not start with a number
324
+ Only case-insensitive alphanumeric values are allowed
325
+ */
326
+ if (value && !/^\d/.test(value) && value === sanitize(value)) {
327
+ return true;
328
+ }
329
+ return 'Only alphanumeric values are allowed, starting with alphabets';
330
+ }
331
+ }
332
+ ];
333
+
334
+ await inquirer.prompt(questions).then(async answers => {
335
+ const {
336
+ organization,
337
+ library
338
+ } = answers;
339
+
340
+ await renameLibrary(
341
+ {
342
+ library,
343
+ organization
344
+ },
345
+ options
346
+ );
347
+
348
+ });
349
+ }
350
+
351
+
352
+
353
+ };
@@ -9,13 +9,15 @@ import { up } from 'inquirer/lib/utils/readline.js';
9
9
  import {
10
10
  convertIntoPascalCase,
11
11
  showVersion,
12
- updateUseWebPackPromotion
12
+ updateUseWebPackPromotion,
13
+ getLibraryBased
13
14
  } from '../../util.js';
14
15
  import {
15
16
  WEBPACK_CONFIG_JS_FILENAME,
16
17
  BUILDER_INDEX_FILE_PATH
17
18
  } from '../../constants.js';
18
19
 
20
+ const isLibraryBased = await getLibraryBased();
19
21
 
20
22
 
21
23
  export const renamePromotedWebPack = async () => {
@@ -42,6 +44,11 @@ export const renamePromotedWebPack = async () => {
42
44
 
43
45
 
44
46
  export default async options => {
47
+ if (isLibraryBased) {
48
+ console.log(`Command only supported for ${chalk.bold.green('non library based')} components.`)
49
+ process.exit();
50
+ }
51
+
45
52
  showVersion();
46
53
 
47
54
  await renamePromotedWebPack();
package/src/util.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'fs';
2
+ import path from 'path';
2
3
  import { join } from 'path';
3
4
  import { promisify } from 'util';
4
5
  import https from 'https';
@@ -20,7 +21,10 @@ import {
20
21
  DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
21
22
  LP_DELETE_COMPONENT_SERVICE_REST_ENDPOINT,
22
23
  OOTB_COMPONENTS,
23
- USE_PROMOTED_WEB_PACK
24
+ USE_PROMOTED_WEB_PACK,
25
+ BOOTSTRAP_CONFIG,
26
+ LIBRARY_BASED,
27
+ SHARED_DIRECTORY
24
28
  } from './constants.js';
25
29
 
26
30
  const access = promisify(fs.access);
@@ -100,6 +104,21 @@ export const updateUseWebPackPromotion = async ( useValue = false ) => {
100
104
 
101
105
  }
102
106
 
107
+ export const getLibraryBased = async () => {
108
+ const currentDirectory = process.cwd();
109
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
110
+
111
+ await checkPathAccess(pegaConfigJsonPath);
112
+
113
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
114
+ data = JSON.parse(data);
115
+
116
+ if (data[LIBRARY_BASED]) {
117
+ return data[LIBRARY_BASED];
118
+ }
119
+ else return false;
120
+ }
121
+
103
122
  export const deleteLocalComponent = async componentKey => {
104
123
  const currentDirectory = process.cwd();
105
124
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -180,6 +199,39 @@ export const deleteServerComponent = async componentKey => {
180
199
  }
181
200
  };
182
201
 
202
+ export const copyFileToShared = async ( fileName, fileContents) => {
203
+ const currentDirectory = process.cwd();
204
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
205
+
206
+ await checkPathAccess(pegaConfigJsonPath);
207
+
208
+ let data = fs.readFileSync(pegaConfigJsonPath, { encoding: 'utf8' });
209
+
210
+ data = JSON.parse(data);
211
+
212
+ if (!data[COMPONENTS_DIRECTORY_PATH]) {
213
+ console.error(
214
+ `${chalk.red.bold('ERROR')} Could not find components directory path in config.json`
215
+ );
216
+ process.exit(1);
217
+ }
218
+
219
+ const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH]);
220
+ const sharedDirectory = join(directory, SHARED_DIRECTORY);
221
+
222
+ // if shared doesn't exist, create it
223
+ if (!fs.existsSync(sharedDirectory)) {
224
+ fs.mkdirSync(sharedDirectory, { recursive: true });
225
+ }
226
+
227
+ const filePath = join(sharedDirectory, fileName);
228
+ if (!fs.existsSync(filePath)) {
229
+ fs.writeFileSync(filePath, fileContents);
230
+ }
231
+
232
+
233
+ };
234
+
183
235
  export const getComponents = async () => {
184
236
  const currentDirectory = process.cwd();
185
237
  const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
@@ -200,7 +252,7 @@ export const getComponents = async () => {
200
252
  const directory = join(currentDirectory, data[COMPONENTS_DIRECTORY_PATH]);
201
253
  return fs
202
254
  .readdirSync(directory, { withFileTypes: true })
203
- .filter(dirent => dirent.isDirectory())
255
+ .filter(dirent => dirent.isDirectory() && dirent.name !== SHARED_DIRECTORY)
204
256
  .map(dirent => dirent.name);
205
257
  };
206
258
 
@@ -262,6 +314,45 @@ export const getComponentDefaults = async () => {
262
314
  return config.component;
263
315
  };
264
316
 
317
+ export const updateComponentDefaultLibrary = async (library) => {
318
+ const currentDirectory = process.cwd();
319
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
320
+
321
+ await checkPathAccess(pegaConfigJsonPath);
322
+
323
+ let config = await getPegaConfig();
324
+ let componentsDefault = config.component;
325
+ componentsDefault.library = library;
326
+
327
+
328
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8' });
329
+
330
+ }
331
+
332
+ export const updateComponentDefaultVersion = async (version) => {
333
+ const currentDirectory = process.cwd();
334
+ const pegaConfigJsonPath = join(currentDirectory, TASKS_CONFIG_JSON_FILENAME);
335
+
336
+ await checkPathAccess(pegaConfigJsonPath);
337
+
338
+ let config = await getPegaConfig();
339
+ let componentsDefault = config.component;
340
+ componentsDefault.version = version;
341
+
342
+
343
+ fs.writeFileSync(pegaConfigJsonPath, JSON.stringify(config, null, 4), { encoding: 'utf8' });
344
+
345
+ }
346
+
347
+ export const updateDefaultOrganization = async (organization) => {
348
+ let packageData = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf-8'));
349
+
350
+ packageData.organization = organization;
351
+
352
+ fs.writeFileSync(path.resolve('package.json'), JSON.stringify(packageData, null, 4), { encoding: 'utf8' });
353
+
354
+ }
355
+
265
356
  export const getServerType = async () => {
266
357
  const defaultPegaServerConfig = await getPegaServerConfig();
267
358
  return defaultPegaServerConfig.serverType;
@@ -592,3 +683,111 @@ export const deleteLaunchpadServerComponent = async componentKey => {
592
683
  throw new Error(error);
593
684
  }
594
685
  };
686
+
687
+ export const getBootstrapConfig = async (restServerUrl, authorizationHeader) => {
688
+
689
+ const serverConfig = await getPegaServerConfig();
690
+
691
+ return fetch(`${restServerUrl}/${BOOTSTRAP_CONFIG}`, {
692
+ method: 'GET',
693
+ agent: getHttpsAgent(serverConfig),
694
+ headers: new Headers({
695
+ Authorization: authorizationHeader
696
+ })
697
+ }).then((response) => {
698
+ if (response.ok) {
699
+ return response.json();
700
+ }
701
+ throw Error('D_pxBootstrapConfig load failed.', { cause: response.status });
702
+ });
703
+ };
704
+
705
+ export const updateC11NB2SForInfinity = async () => {
706
+ const serverConfig = await getPegaServerConfig();
707
+ const { server } = serverConfig;
708
+ const OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
709
+
710
+ if (OAuthData) {
711
+ const { access_token: accessToken, token_type: tokenType } = JSON.parse(OAuthData);
712
+
713
+ const bootstrapJSON = await getBootstrapConfig(server, `${tokenType} ${accessToken}`);
714
+
715
+ if (bootstrapJSON) {
716
+ const bootstrap = JSON.parse(bootstrapJSON.pyConfigJSON);
717
+
718
+ const objOauthData = JSON.parse(OAuthData);
719
+ objOauthData["C11NB2S"] = bootstrap.tokens.C11NB2S;
720
+ objOauthData["appStaticContentServer"] = bootstrap.serviceConfig.appStaticContentServer;
721
+
722
+ // write out file
723
+ fs.writeFileSync(TOKEN_PATH, JSON.stringify(objOauthData), { encoding: 'utf8' });
724
+ }
725
+
726
+ }
727
+ };
728
+
729
+ export const updateC11NB2SForLaunchpad = async () => {
730
+
731
+
732
+
733
+ };
734
+
735
+ export const getC11NB2STokenAndStaticServer = async () => {
736
+ const serverConfig = await getPegaServerConfig();
737
+ const { server } = serverConfig;
738
+ let OAuthData;
739
+ try {
740
+ OAuthData = fs.readFileSync(TOKEN_PATH, 'utf8');
741
+ }
742
+ catch (ex) {
743
+ return ({});
744
+ }
745
+
746
+ if (OAuthData) {
747
+ const { C11NB2S, appStaticContentServer } = JSON.parse(OAuthData)
748
+
749
+ if (C11NB2S) {
750
+ return ({ C11NB2S, appStaticContentServer});
751
+ }
752
+
753
+ }
754
+ return ({});
755
+ }
756
+
757
+ export const getLibraryVersions = async (libraryName) => {
758
+ const currentDirectory = process.cwd();
759
+
760
+ const directory = join(currentDirectory, libraryName);
761
+ return fs
762
+ .readdirSync(directory, { withFileTypes: true })
763
+ .filter(dirent => dirent.isDirectory())
764
+ .map(dirent => dirent.name);
765
+ };
766
+
767
+ export const deleteLocalLibrary = async (libraryName) => {
768
+ const currentDirectory = process.cwd();
769
+
770
+ const directory = join(currentDirectory, libraryName);
771
+ fs.rmSync(directory, { recursive: true }, err => {
772
+ if (err) {
773
+ throw err;
774
+ }
775
+ else {
776
+ console.log(`Library:${chalk.green.bold(libraryName)} is deleted from Local`);
777
+ }
778
+ });
779
+ }
780
+
781
+ export const deleteLocalLibraryVersion = async (libraryName, libraryVersion) => {
782
+ const currentDirectory = process.cwd();
783
+
784
+ const directory = join(currentDirectory, libraryName, libraryVersion);
785
+ fs.rmSync(directory, { recursive: true }, err => {
786
+ if (err) {
787
+ throw err;
788
+ }
789
+ else {
790
+ console.log(`Library version:${chalk.green.bold(libraryName)}:${chalk.green.bold(libraryVersion)} is deleted from Local`);
791
+ }
792
+ });
793
+ }
@@ -0,0 +1,78 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks */
2
+ import React from 'react';
3
+ import { useEffect, useState } from 'react';
4
+ import { Avatar as CosmosAvatar, withConfiguration } from '@pega/cosmos-react-core';
5
+ import type { PConnFieldProps } from './PConnProps';
6
+
7
+
8
+ // interface for props
9
+ interface PegaDxilMyDetailsAvatarProps extends PConnFieldProps {
10
+ // If any, enter additional props that only exist on TextInput here
11
+ metaObj: any;
12
+ showStatus: boolean;
13
+
14
+ }
15
+
16
+ function Avatar(props: PegaDxilMyDetailsAvatarProps) {
17
+ const { metaObj, showStatus = false } = props;
18
+ const [imageBlobUrl, setImageBlobUrl] = useState(null);
19
+ let userName: string;
20
+ let userIdentifier: string;
21
+
22
+ // TODO Below if conditions can be removed once we have apis to get worklist/mywork info
23
+ // This is non CaseView case (Dashboard, MyWork etc)
24
+ if (!metaObj) {
25
+ userName = PCore.getEnvironmentInfo().getOperatorName();
26
+ userIdentifier = PCore.getEnvironmentInfo().getOperatorIdentifier();
27
+ } else {
28
+ userName = metaObj.name;
29
+ userIdentifier = metaObj.ID;
30
+ }
31
+ if (!userName && userIdentifier) {
32
+ userName = userIdentifier;
33
+ }
34
+
35
+ useEffect(() => {
36
+ const imageKey = !metaObj ? PCore.getEnvironmentInfo().getOperatorImageInsKey() : metaObj.image;
37
+ if (imageKey) {
38
+ PCore.getAssetLoader()
39
+ .getSvcImage(imageKey)
40
+ .then((blob) => window.URL.createObjectURL(blob))
41
+ .then((imagePath) => setImageBlobUrl(imagePath as React.SetStateAction<any>));
42
+ }
43
+ }, [metaObj]);
44
+
45
+ if (showStatus) {
46
+ const currentState = PCore.getMessagingServiceManager().getUserPresence().getUserState(userIdentifier);
47
+ const [userState, setUserState]: any = useState(currentState === 'online' ? 'active' : 'inactive');
48
+
49
+ // @ts-ignore
50
+ const handleUserStateChange = ({ state }) => {
51
+ setUserState(state === 'online' ? 'active' : 'inactive');
52
+ };
53
+
54
+ useEffect(() => {
55
+ const subId = PCore.getMessagingServiceManager()
56
+ .getUserPresence()
57
+ // @ts-ignore
58
+ .subscribe(userIdentifier, handleUserStateChange);
59
+
60
+ return function cleanup() {
61
+ PCore.getMessagingServiceManager().getUserPresence().unsubscribe(userIdentifier, subId);
62
+ };
63
+ }, [userIdentifier, handleUserStateChange]);
64
+ // @ts-ignore
65
+ return <CosmosAvatar name={userName} imageSrc={imageBlobUrl as React.SetStateAction<any>} status={userState} />;
66
+ }
67
+
68
+ // Do not render when userName does not exists
69
+ // TODO : In CNR case, pxRequestor is not available, please remove this condition once it populates
70
+ if (!userName) {
71
+ return null;
72
+ }
73
+
74
+ return <CosmosAvatar name={userName} imageSrc={imageBlobUrl as React.SetStateAction<any>} />;
75
+ }
76
+
77
+
78
+ export default withConfiguration(Avatar);