contensis-cli 1.1.1-beta.1 → 1.1.1-beta.11

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.
@@ -189,12 +189,12 @@ class ContensisCli {
189
189
  }
190
190
  }
191
191
 
192
- PrintEnvironments = () => {
192
+ PrintEnvironments = async () => {
193
193
  const { log, messages } = this;
194
194
  const { currentEnvironment, environments = {} } = this.cache;
195
195
  const envKeys = Object.keys(environments);
196
196
  log.success(messages.envs.found(envKeys.length));
197
- this.HandleFormattingAndOutput(envKeys, () => {
197
+ await this.HandleFormattingAndOutput(envKeys, () => {
198
198
  // print the envKeys to console
199
199
  for (const env of envKeys) {
200
200
  console.log(` - ${currentEnvironment === env ? '* ' : ''}${env}`);
@@ -563,7 +563,7 @@ class ContensisCli {
563
563
 
564
564
  if (Array.isArray(projects)) {
565
565
  // Print contensis version to console
566
- this.HandleFormattingAndOutput(contensis.contensisVersion, () =>
566
+ await this.HandleFormattingAndOutput(contensis.contensisVersion, () =>
567
567
  log.raw(log.highlightText(contensis.contensisVersion))
568
568
  );
569
569
  }
@@ -586,7 +586,7 @@ class ContensisCli {
586
586
  );
587
587
  if (token) {
588
588
  // Print bearer token to console
589
- this.HandleFormattingAndOutput(token, () =>
589
+ await this.HandleFormattingAndOutput(token, () =>
590
590
  log.raw(log.highlightText(token))
591
591
  );
592
592
  }
@@ -625,7 +625,7 @@ class ContensisCli {
625
625
  log.success(messages.projects.list());
626
626
  log.raw('');
627
627
 
628
- this.HandleFormattingAndOutput(projects, () => {
628
+ await this.HandleFormattingAndOutput(projects, () => {
629
629
  // print the projects to console
630
630
  for (const project of projects.sort((a, b) =>
631
631
  a.id.localeCompare(b.id)
@@ -679,7 +679,7 @@ class ContensisCli {
679
679
 
680
680
  if (foundProject) {
681
681
  log.raw('');
682
- this.HandleFormattingAndOutput(foundProject, log.object);
682
+ await this.HandleFormattingAndOutput(foundProject, log.object);
683
683
  }
684
684
 
685
685
  if (projectsErr) {
@@ -744,7 +744,7 @@ class ContensisCli {
744
744
 
745
745
  if (Array.isArray(apiKeys)) {
746
746
  log.success(messages.keys.list(currentEnv));
747
- this.HandleFormattingAndOutput(apiKeys, () => {
747
+ await this.HandleFormattingAndOutput(apiKeys, () => {
748
748
  // print the keys to console
749
749
  for (const {
750
750
  id,
@@ -833,7 +833,7 @@ class ContensisCli {
833
833
 
834
834
  if (!roles.length) log.help(messages.roles.noneExist());
835
835
 
836
- this.HandleFormattingAndOutput(roles, () => {
836
+ await this.HandleFormattingAndOutput(roles, () => {
837
837
  // print the roles to console
838
838
  for (const {
839
839
  id,
@@ -916,7 +916,7 @@ class ContensisCli {
916
916
 
917
917
  const role = findByIdOrName(roles, roleNameOrId);
918
918
 
919
- if (role) this.HandleFormattingAndOutput(role, log.object);
919
+ if (role) await this.HandleFormattingAndOutput(role, log.object);
920
920
  else log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
921
921
  }
922
922
 
@@ -939,7 +939,7 @@ class ContensisCli {
939
939
  messages.roles.created(currentEnv, role.id || role.name || '')
940
940
  );
941
941
 
942
- this.HandleFormattingAndOutput(created, log.object);
942
+ await this.HandleFormattingAndOutput(created, log.object);
943
943
 
944
944
  log.help(messages.roles.tip());
945
945
  return role.id;
@@ -979,7 +979,7 @@ class ContensisCli {
979
979
  else {
980
980
  log.success(messages.roles.set());
981
981
 
982
- this.HandleFormattingAndOutput(updated, log.object);
982
+ await this.HandleFormattingAndOutput(updated, log.object);
983
983
  }
984
984
  } else {
985
985
  // Role does not exist
@@ -1043,7 +1043,7 @@ class ContensisCli {
1043
1043
  const stringFromLanguageObject = (o: { [lang: string]: string }) =>
1044
1044
  Object.values(o || {})?.[0];
1045
1045
 
1046
- this.HandleFormattingAndOutput(workflows, () => {
1046
+ await this.HandleFormattingAndOutput(workflows, () => {
1047
1047
  // print the workflows to console
1048
1048
  // log.object(workflows);
1049
1049
  for (const {
@@ -1106,7 +1106,8 @@ class ContensisCli {
1106
1106
 
1107
1107
  const workflow = findByIdOrName(workflows, workflowNameOrId);
1108
1108
 
1109
- if (workflow) this.HandleFormattingAndOutput(workflow, log.object);
1109
+ if (workflow)
1110
+ await this.HandleFormattingAndOutput(workflow, log.object);
1110
1111
  else
1111
1112
  log.error(messages.workflows.failedGet(currentEnv, workflowNameOrId));
1112
1113
  }
@@ -1128,7 +1129,7 @@ class ContensisCli {
1128
1129
  if (created) {
1129
1130
  log.success(messages.projects.created(currentEnv, project.id));
1130
1131
 
1131
- this.HandleFormattingAndOutput(created, () => {
1132
+ await this.HandleFormattingAndOutput(created, () => {
1132
1133
  // set the CLI project to the newly created project
1133
1134
  this.SetProject(project.id);
1134
1135
  // print all the projects to console
@@ -1156,7 +1157,7 @@ class ContensisCli {
1156
1157
  if (updated) {
1157
1158
  log.success(messages.projects.updated(currentEnv, currentProject));
1158
1159
 
1159
- this.HandleFormattingAndOutput(updated, log.object);
1160
+ await this.HandleFormattingAndOutput(updated, log.object);
1160
1161
  return updated.id;
1161
1162
  }
1162
1163
 
@@ -1216,7 +1217,7 @@ class ContensisCli {
1216
1217
 
1217
1218
  if (Array.isArray(returnModels)) {
1218
1219
  log.success(messages.models.list(currentProject));
1219
- this.HandleFormattingAndOutput(contentModelBackup, () => {
1220
+ await this.HandleFormattingAndOutput(contentModelBackup, () => {
1220
1221
  // print the content models to console
1221
1222
  for (const model of returnModels) {
1222
1223
  log.raw('');
@@ -1230,7 +1231,7 @@ class ContensisCli {
1230
1231
  );
1231
1232
  log.raw('');
1232
1233
  if (models?.length) {
1233
- this.HandleFormattingAndOutput(contentModelBackup, () => {
1234
+ await this.HandleFormattingAndOutput(contentModelBackup, () => {
1234
1235
  // print the content models to console
1235
1236
  for (const model of models) {
1236
1237
  const components = model.components?.length || 0;
@@ -1300,7 +1301,7 @@ class ContensisCli {
1300
1301
 
1301
1302
  if (migrateErr) logError(migrateErr);
1302
1303
  else
1303
- this.HandleFormattingAndOutput(result, () => {
1304
+ await this.HandleFormattingAndOutput(result, () => {
1304
1305
  // print the results to console
1305
1306
  if (!commit) {
1306
1307
  log.raw(log.boldText(`\nContent types:`));
@@ -1340,7 +1341,7 @@ class ContensisCli {
1340
1341
 
1341
1342
  if (Array.isArray(contentTypes)) {
1342
1343
  log.success(messages.contenttypes.list(currentProject));
1343
- this.HandleFormattingAndOutput(contentTypes, () => {
1344
+ await this.HandleFormattingAndOutput(contentTypes, () => {
1344
1345
  // print the content types to console
1345
1346
  for (const contentType of contentTypes) {
1346
1347
  const fieldsLength = contentType.fields?.length || 0;
@@ -1371,7 +1372,7 @@ class ContensisCli {
1371
1372
  messages.contenttypes.get(currentProject, contentType.id)
1372
1373
  );
1373
1374
  // print the content type to console
1374
- this.HandleFormattingAndOutput(contentType, log.object);
1375
+ await this.HandleFormattingAndOutput(contentType, log.object);
1375
1376
  } else {
1376
1377
  log.error(
1377
1378
  messages.contenttypes.failedGet(currentProject, contentTypeId)
@@ -1407,7 +1408,7 @@ class ContensisCli {
1407
1408
  )
1408
1409
  );
1409
1410
  // print the results to console
1410
- this.HandleFormattingAndOutput(result, () =>
1411
+ await this.HandleFormattingAndOutput(result, () =>
1411
1412
  log.object(jsonFormatter(result))
1412
1413
  );
1413
1414
  }
@@ -1460,7 +1461,7 @@ class ContensisCli {
1460
1461
  )
1461
1462
  );
1462
1463
  // print the content type to console
1463
- this.HandleFormattingAndOutput(contentType, () => {});
1464
+ await this.HandleFormattingAndOutput(contentType, () => {});
1464
1465
  }
1465
1466
  }
1466
1467
  }
@@ -1497,7 +1498,7 @@ class ContensisCli {
1497
1498
  if (err) log.error(err.message, err);
1498
1499
  if (result)
1499
1500
  // print the content type to console
1500
- this.HandleFormattingAndOutput(result, () => {
1501
+ await this.HandleFormattingAndOutput(result, () => {
1501
1502
  log.success(
1502
1503
  `Queried models ${log.infoText(
1503
1504
  `"${result.query.modelIds?.join(', ')}"`
@@ -1525,7 +1526,7 @@ class ContensisCli {
1525
1526
  if (Array.isArray(components)) {
1526
1527
  log.success(messages.components.list(currentProject));
1527
1528
 
1528
- this.HandleFormattingAndOutput(components, () => {
1529
+ await this.HandleFormattingAndOutput(components, () => {
1529
1530
  // print the components to console
1530
1531
  for (const component of components) {
1531
1532
  const fieldsLength = component.fields?.length || 0;
@@ -1554,7 +1555,7 @@ class ContensisCli {
1554
1555
  if (component) {
1555
1556
  log.success(messages.components.get(currentProject, component.id));
1556
1557
  // print the component to console
1557
- this.HandleFormattingAndOutput(component, log.object);
1558
+ await this.HandleFormattingAndOutput(component, log.object);
1558
1559
  } else {
1559
1560
  log.error(messages.components.failedGet(currentProject, componentId));
1560
1561
  }
@@ -1591,7 +1592,7 @@ class ContensisCli {
1591
1592
  )
1592
1593
  );
1593
1594
  // print the results to console
1594
- this.HandleFormattingAndOutput(result, () =>
1595
+ await this.HandleFormattingAndOutput(result, () =>
1595
1596
  log.info(jsonFormatter(result))
1596
1597
  );
1597
1598
  }
@@ -1644,7 +1645,7 @@ class ContensisCli {
1644
1645
  )
1645
1646
  );
1646
1647
  // print the component to console
1647
- this.HandleFormattingAndOutput(component, () => {});
1648
+ await this.HandleFormattingAndOutput(component, () => {});
1648
1649
  }
1649
1650
  }
1650
1651
  }
@@ -1665,7 +1666,7 @@ class ContensisCli {
1665
1666
  }
1666
1667
  const [err, result] = await contensis.DeleteEntries();
1667
1668
  if (result)
1668
- this.HandleFormattingAndOutput(result, () => {
1669
+ await this.HandleFormattingAndOutput(result, () => {
1669
1670
  // print the migrateResult to console
1670
1671
  printEntriesMigrateResult(this, result, {
1671
1672
  action: 'delete',
@@ -1701,7 +1702,7 @@ class ContensisCli {
1701
1702
  if (contensis) {
1702
1703
  log.line();
1703
1704
  const entries = await contensis.GetEntries({ withDependents });
1704
- this.HandleFormattingAndOutput(entries, () =>
1705
+ await this.HandleFormattingAndOutput(entries, () =>
1705
1706
  // print the entries to console
1706
1707
  logEntitiesTable({
1707
1708
  entries,
@@ -1744,10 +1745,11 @@ class ContensisCli {
1744
1745
 
1745
1746
  if (err) logError(err);
1746
1747
  else
1747
- this.HandleFormattingAndOutput(result, () => {
1748
+ await this.HandleFormattingAndOutput(result, () => {
1748
1749
  // print the migrateResult to console
1749
1750
  printEntriesMigrateResult(this, result, {
1750
1751
  showAll: logOutput === 'all',
1752
+ showDiff: logOutput === 'all' || logOutput === 'changes',
1751
1753
  showChanged: logOutput === 'changes',
1752
1754
  });
1753
1755
  });
@@ -1799,7 +1801,7 @@ class ContensisCli {
1799
1801
 
1800
1802
  log.success(messages.nodes.get(currentProject, rootPath, depth));
1801
1803
 
1802
- this.HandleFormattingAndOutput(nodes, () => {
1804
+ await this.HandleFormattingAndOutput(nodes, () => {
1803
1805
  // print the nodes to console
1804
1806
  log.object({ ...root, children: undefined, language: undefined });
1805
1807
  printNodeTreeOutput(this, root);
@@ -1843,7 +1845,7 @@ class ContensisCli {
1843
1845
 
1844
1846
  if (err) log.raw(``);
1845
1847
  else
1846
- this.HandleFormattingAndOutput(result, () => {
1848
+ await this.HandleFormattingAndOutput(result, () => {
1847
1849
  // print the migrateResult to console
1848
1850
  printNodeTreeOutput(this, migrateTree, logOutput, logLimit);
1849
1851
  printNodesMigrateResult(this, result, {
@@ -1912,7 +1914,7 @@ class ContensisCli {
1912
1914
  }
1913
1915
  const [err, result] = await contensis.DeleteNodes();
1914
1916
  if (result) {
1915
- this.HandleFormattingAndOutput(result, () => {
1917
+ await this.HandleFormattingAndOutput(result, () => {
1916
1918
  // print the migrateResult to console
1917
1919
  printNodeTreeOutput(
1918
1920
  this,
@@ -1969,7 +1971,7 @@ class ContensisCli {
1969
1971
  log.success(messages.webhooks.list(currentEnv));
1970
1972
  if (!webhooks?.length) log.warning(messages.webhooks.noneExist());
1971
1973
  else {
1972
- this.HandleFormattingAndOutput(filteredResults, () => {
1974
+ await this.HandleFormattingAndOutput(filteredResults, () => {
1973
1975
  // print the keys to console
1974
1976
  for (const {
1975
1977
  id,
@@ -2047,7 +2049,7 @@ class ContensisCli {
2047
2049
  const [err, blocks] = await contensis.blocks.GetBlocks();
2048
2050
 
2049
2051
  if (Array.isArray(blocks)) {
2050
- this.HandleFormattingAndOutput(blocks, () => {
2052
+ await this.HandleFormattingAndOutput(blocks, () => {
2051
2053
  // print the blocks to console
2052
2054
  log.success(messages.blocks.list(currentEnv, env.currentProject));
2053
2055
  for (const {
@@ -2102,7 +2104,7 @@ class ContensisCli {
2102
2104
  );
2103
2105
 
2104
2106
  if (blocks) {
2105
- this.HandleFormattingAndOutput(blocks, () => {
2107
+ await this.HandleFormattingAndOutput(blocks, () => {
2106
2108
  // print the version detail to console
2107
2109
  log.success(
2108
2110
  messages.blocks.get(blockId, currentEnv, env.currentProject)
@@ -2163,7 +2165,7 @@ class ContensisCli {
2163
2165
  );
2164
2166
  }
2165
2167
  if (blockVersion) {
2166
- this.HandleFormattingAndOutput(blockVersion, () => {
2168
+ await this.HandleFormattingAndOutput(blockVersion, () => {
2167
2169
  // print the version detail to console
2168
2170
  printBlockVersion(this, blockVersion);
2169
2171
  });
@@ -2254,7 +2256,7 @@ class ContensisCli {
2254
2256
  );
2255
2257
 
2256
2258
  if (blockVersion) {
2257
- this.HandleFormattingAndOutput(blockVersion, () => {
2259
+ await this.HandleFormattingAndOutput(blockVersion, () => {
2258
2260
  // print the version detail to console
2259
2261
  log.success(
2260
2262
  messages.blocks.actionComplete(
@@ -2314,7 +2316,7 @@ class ContensisCli {
2314
2316
  logs.endsWith('\n') ? logs.slice(0, logs.length - 1) : logs;
2315
2317
  const renderLogs = removeTrailingNewline(blockLogs);
2316
2318
 
2317
- this.HandleFormattingAndOutput(renderLogs, () => {
2319
+ await this.HandleFormattingAndOutput(renderLogs, () => {
2318
2320
  // print the logs to console
2319
2321
  console.log(
2320
2322
  ` - ${blockId} ${branch} ${
@@ -2418,7 +2420,7 @@ class ContensisCli {
2418
2420
  ); // TODO: resolve any cast;
2419
2421
 
2420
2422
  if (Array.isArray(proxies)) {
2421
- this.HandleFormattingAndOutput(proxies, () => {
2423
+ await this.HandleFormattingAndOutput(proxies, () => {
2422
2424
  // print the proxies to console
2423
2425
  log.success(messages.proxies.list(currentEnv, env.currentProject));
2424
2426
  for (const { id, name, description, endpoints, version } of proxies) {
@@ -2457,7 +2459,7 @@ class ContensisCli {
2457
2459
  ); // TODO: resolve any cast
2458
2460
 
2459
2461
  if (Array.isArray(renderers)) {
2460
- this.HandleFormattingAndOutput(renderers, () => {
2462
+ await this.HandleFormattingAndOutput(renderers, () => {
2461
2463
  // print the renderers to console
2462
2464
  log.success(messages.renderers.list(currentEnv, env.currentProject));
2463
2465
  for (const {
@@ -2493,7 +2495,7 @@ class ContensisCli {
2493
2495
  }
2494
2496
  }
2495
2497
  };
2496
- HandleFormattingAndOutput = <T>(obj: T, logFn: (obj: T) => void) => {
2498
+ HandleFormattingAndOutput = async <T>(obj: T, logFn: (obj: T) => void) => {
2497
2499
  const { format, log, messages, output } = this;
2498
2500
  const fields = this.contensis?.payload.query?.fields;
2499
2501
 
@@ -2502,7 +2504,7 @@ class ContensisCli {
2502
2504
  logFn(obj);
2503
2505
  } else if (format === 'csv') {
2504
2506
  log.raw('');
2505
- log.raw(log.infoText(csvFormatter(limitFields(obj, fields))));
2507
+ log.raw(log.infoText(await csvFormatter(limitFields(obj, fields))));
2506
2508
  } else if (format === 'xml') {
2507
2509
  log.raw('');
2508
2510
  log.raw(log.infoText(xmlFormatter(limitFields(obj, fields))));
@@ -2516,7 +2518,7 @@ class ContensisCli {
2516
2518
  let writeString = '';
2517
2519
  const isText = !tryParse(obj) && typeof obj === 'string';
2518
2520
  if (format === 'csv') {
2519
- writeString = csvFormatter(limitFields(obj, fields));
2521
+ writeString = await csvFormatter(limitFields(obj, fields));
2520
2522
  } else if (format === 'xml') {
2521
2523
  writeString = xmlFormatter(limitFields(obj, fields));
2522
2524
  } else
@@ -149,7 +149,7 @@ export const printEntriesMigrateResult = (
149
149
  ) {
150
150
  console.log(
151
151
  log.infoText(
152
- `${originalId} ${Object.entries(entryStatus || {})
152
+ `${Object.entries(entryStatus || {})
153
153
  .filter(x => x[0] !== 'entryTitle')
154
154
  .map(([projectId, projectStatus]) => {
155
155
  const [targetGuid, { status }] = (Object.entries(
@@ -158,11 +158,13 @@ export const printEntriesMigrateResult = (
158
158
  '',
159
159
  { x: { status: undefined } },
160
160
  ];
161
- return `${messages.migrate.status(status)(`${status}`)}${
162
- targetGuid !== originalId ? `-> ${targetGuid}` : ''
161
+ return `${messages.migrate.status(status)(
162
+ `${status}`
163
+ )} ${originalId}${
164
+ targetGuid !== originalId ? ` -> ${targetGuid}\n ` : ' '
163
165
  }`;
164
166
  })}`
165
- ) + ` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
167
+ ) + `${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
166
168
  );
167
169
 
168
170
  for (const [projectId, projectStatus] of Object.entries(
@@ -174,9 +176,7 @@ export const printEntriesMigrateResult = (
174
176
  if (error) log.error(error);
175
177
  if (diff && showDiff) {
176
178
  console.log(
177
- ` ${log.highlightText(`diff:`)} ${log.infoText(
178
- highlightDiffText(diff)
179
- )}\n`
179
+ ` ${log.infoText(`diff: ${highlightDiffText(diff)}`)}\n`
180
180
  );
181
181
  }
182
182
  }
@@ -1,9 +1,10 @@
1
- import { parse, stringify } from 'csv/sync';
1
+ import { parse, stringify } from 'csv';
2
+ // import { parse, stringify } from 'csv/sync';
2
3
  import { flattenObject } from './json.formatter';
3
4
 
4
- export const csvFormatter = <T>(entries: T | T[]) => {
5
+ export const csvFormatter = async <T>(entries: T | T[]) => {
5
6
  // Flatten the passed in object
6
- const flatEntries = [];
7
+ const flatEntries = [] as any[];
7
8
  if (Array.isArray(entries))
8
9
  for (const entry of entries) {
9
10
  flatEntries.push(flattenObject(entry));
@@ -11,15 +12,33 @@ export const csvFormatter = <T>(entries: T | T[]) => {
11
12
  else flatEntries.push(flattenObject(entries));
12
13
 
13
14
  // Parse the flattened object to csv
14
- const csv = stringify(flatEntries, { header: true });
15
-
15
+ // const csv = stringify(flatEntries, { header: true });
16
+ const csv = await new Promise<string>((resolve, reject) => {
17
+ stringify(flatEntries, { header: true }, (err, data) => {
18
+ if (err) reject(err);
19
+ resolve(data);
20
+ });
21
+ });
16
22
  return csv;
17
23
  };
18
24
 
19
- export const csvToJson = <T>(data: string): T[] => {
20
- return parse(data, {
21
- columns: true,
22
- skip_empty_lines: true,
25
+ export const csvToJson = async <T = any>(data: string): Promise<T[]> => {
26
+ // return parse(data, {
27
+ // columns: true,
28
+ // skip_empty_lines: true,
29
+ // });
30
+ return new Promise((resolve, reject) => {
31
+ parse(
32
+ data,
33
+ {
34
+ columns: true,
35
+ skip_empty_lines: true,
36
+ },
37
+ (err, records) => {
38
+ if (err) reject(err);
39
+ resolve(records);
40
+ }
41
+ );
23
42
  });
24
43
  };
25
44
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.1.1-beta.1";
1
+ export const LIB_VERSION = "1.1.1-beta.11";