UNPKG

2.32 kBJavaScriptView Raw
1/* jshint
2browser: true, jquery: true, node: true,
3bitwise: true, camelcase: false, curly: true, eqeqeq: true, es3: true, evil: true, expr: true, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, quotmark: single, regexdash: true, strict: true, sub: true, trailing: true, undef: true, unused: vars, white: true
4*/
5
6'use strict';
7
8var _ = require('lodash');
9var config = require('./test-config');
10
11var api = require('./index').configure(
12 config.PSA_SERVER_HOST,
13 config.INTEGRATION_COMPANY_NAME,
14 config.INTEGRATION_LOGIN_ID,
15 config.INTEGRATION_PASSWORD
16);
17
18function sortAvailableReports(normalizedReports) {
19 var sortMap = function (map) {
20 return _(map).keys().sort().reduce(function (sortedMap, key) {
21 sortedMap[key] = map[key];
22 return sortedMap;
23 }, {});
24 };
25
26 return sortMap(_.transform(normalizedReports, function (reports, report, reportName) {
27 reports[reportName] = sortMap(report);
28 }));
29}
30
31function markdownAvailableReports(normalizedReports) {
32 return _.reduce(normalizedReports, function (markdown, fields, reportName) {
33 markdown += '#### ' + reportName + '\r\n';
34 markdown += '| | | |\r\n' +
35 '|-------------|-------------|-----|\r\n';
36 markdown += _.reduce(fields, function (markdown, attributes, fieldName) {
37 markdown += '| `' + fieldName + '` | ' + attributes.Type + ' | ' + (attributes.IsNullable.toLowerCase() === 'true' ? 'nullable' : '') + ' |\r\n';
38 return markdown;
39 }, '') + '\r\n';
40 return markdown;
41 }, '');
42}
43
44api.action('GetConnectWiseVersionAction', {}, function (error, result) {
45 error && console.error(error);
46 if (!result) { return; }
47
48 console.log('### Available Reports for ConnectWise ' + result.GetConnectWiseVersionAction.CwVersionInfo.Version);
49 console.log('---');
50
51 api.action('GetAvailableReportsAction', { IncludeFields: true }, function (error, response) {
52 error && console.error(error);
53 if (response) {
54 var reports = api.normalizeGetAvailableReportsActionResponse(response);
55 reports = sortAvailableReports(reports);
56 console.log(markdownAvailableReports(reports));
57 }
58 });
59});
\No newline at end of file