ts-node-client 3.2.1 → 3.2.2

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.
package/lib/pkg.js CHANGED
@@ -1,36 +1,36 @@
1
- /* eslint-disable */
2
- /**********************************************************
3
- * Copyright (c) 2022. Enterprise Architecture Group, EACG
4
- *
5
- * SPDX-License-Identifier: Apache-2.0
6
- *********************************************************/
7
- /* eslint-enable */
8
-
9
- const PackageURL = {};
10
-
11
- PackageURL.get = function get(manager, org, key, version) {
12
- // scheme:type/namespace/name@version?qualifiers#subpath
13
- const parts = [];
14
- let partVersion;
15
- if (manager) {
16
- parts.push(fixPart(manager));
17
- }
18
- if (org) {
19
- parts.push(fixPart(org));
20
- }
21
- if (key) {
22
- parts.push(fixPart(key));
23
- }
24
- if (version) {
25
- partVersion = `@${fixPart(version)}`;
26
- }
27
- return `pkg:${parts.join('/')}${partVersion}`;
28
- };
29
-
30
- function fixPart(str) {
31
- const newStr = encodeURI(str);
32
- return newStr.split('%3A').join(':');
33
- }
34
-
35
- module.exports = PackageURL;
36
-
1
+ /* eslint-disable */
2
+ /**********************************************************
3
+ * Copyright (c) 2022. Enterprise Architecture Group, EACG
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *********************************************************/
7
+ /* eslint-enable */
8
+
9
+ const PackageURL = {};
10
+
11
+ PackageURL.get = function get(manager, org, key, version) {
12
+ // scheme:type/namespace/name@version?qualifiers#subpath
13
+ const parts = [];
14
+ let partVersion;
15
+ if (manager) {
16
+ parts.push(fixPart(manager));
17
+ }
18
+ if (org) {
19
+ parts.push(fixPart(org));
20
+ }
21
+ if (key) {
22
+ parts.push(fixPart(key));
23
+ }
24
+ if (version) {
25
+ partVersion = `@${fixPart(version)}`;
26
+ }
27
+ return `pkg:${parts.join('/')}${partVersion}`;
28
+ };
29
+
30
+ function fixPart(str) {
31
+ const newStr = encodeURI(str);
32
+ return newStr.split('%3A').join(':');
33
+ }
34
+
35
+ module.exports = PackageURL;
36
+
@@ -1,129 +1,129 @@
1
- /* eslint-disable */
2
- /**********************************************************
3
- * Copyright (c) 2017. Enterprise Architecture Group, EACG
4
- *
5
- * SPDX-License-Identifier: Apache-2.0
6
- *********************************************************/
7
- /* eslint-enable */
8
- const axios = require('axios').default;
9
- const debuglog = (require('debuglog'))('ts-rest-client');
10
- const pckgJson = require('../package.json');
11
-
12
-
13
- function RestClient(options) {
14
- if (options === undefined) {
15
- throw new TypeError('Please specify options for rest client');
16
- } else if (options.url === undefined) {
17
- throw new TypeError('Please specify \'url\' attribute in options for rest client');
18
- }
19
- this.options = options;
20
- }
21
-
22
- function checkWarnings(options) {
23
- return options.breakOnWarnings;
24
- }
25
-
26
- function hasWarnings(analysis) {
27
- const stats = analysis.statistics;
28
- return stats ? stats.legal.warnings + stats.vulnerability.warnings + stats.viability.warnings + stats.versioning.warnings : 0;
29
- }
30
-
31
- function checkViolations(options) {
32
- return options.breakOnViolations;
33
- }
34
-
35
- function hasViolations(analysis) {
36
- const stats = analysis.statistics;
37
- return stats ? stats.legal.violations + stats.vulnerability.violations + stats.viability.violations + stats.versioning.violations : 0;
38
- }
39
-
40
- function checkAnalysisResults(options, getReqOpts, cb, i) {
41
- axios(getReqOpts)
42
- .then((response) => {
43
- const scanData = response && response.data;
44
- if (response && response.status === 200 && scanData && scanData.analysisStatus === 'Finished') {
45
- if (checkViolations(options) && hasViolations(scanData)) {
46
- cb(`Analysis found ${hasViolations(scanData)} violations, see more details: ${response.data.url}`);
47
- }
48
- if (checkWarnings(options) && hasWarnings(scanData)) {
49
- cb(`Analysis found ${hasWarnings(scanData)} warnings, see more details: ${response.data.url}`);
50
- }
51
- // eslint-disable-next-line no-underscore-dangle
52
- cb(null, { scanId: scanData._id });
53
- } else {
54
- const retryPeriod = i * 5000;
55
- console.log('Analysis is', ((scanData && scanData.analysisStatus) || 'Scheduled'), 'Retry in ', retryPeriod / 1000, 'sec');
56
- setTimeout(() => {
57
- i += 1;
58
- checkAnalysisResults(options, getReqOpts, cb, i);
59
- }, retryPeriod);
60
- }
61
- })
62
- .catch((error) => {
63
- const errorData = error && typeof error.toJSON === 'function' ? error.toJSON() : false;
64
- if (errorData && (errorData.status === 404)) {
65
- const retryPeriod = i * 5000;
66
- console.log('Analysis is Scheduled', 'Retry in ', retryPeriod / 1000, 'sec');
67
- setTimeout(() => {
68
- i += 1;
69
- checkAnalysisResults(options, getReqOpts, cb, i);
70
- }, retryPeriod);
71
- } else {
72
- debuglog('unexpected getResponse: error=', error);
73
- cb(JSON.stringify(error));
74
- }
75
- });
76
- }
77
-
78
- exports.RestClient = RestClient;
79
-
80
- RestClient.prototype.transfer = function transfer(scan, cb) {
81
- const { options } = this;
82
- debuglog('transfer started, options:', options);
83
-
84
- const reqOpts = options.requestOptions || {};
85
- reqOpts.method = 'post';
86
- reqOpts.url = `${options.url}/api/v1/scans`;
87
- if (options.proxy) {
88
- reqOpts.proxy = options.proxy;
89
- }
90
- reqOpts.headers = {
91
- 'Content-Type': 'application/json',
92
- 'User-Agent': `${pckgJson.name}/${pckgJson.version}`,
93
- 'X-ApiKey': options.apiKey
94
- };
95
- reqOpts.json = true;
96
- reqOpts.data = scan;
97
- if (options.branch) {
98
- reqOpts.data.branch = options.branch;
99
- }
100
- if (options.tag) {
101
- reqOpts.data.tag = options.tag;
102
- }
103
- if (options.binaryLinks) {
104
- let links = options.binaryLinks.split(',');
105
- if (links.length) {
106
- links = links.map((value) => ({
107
- name: value
108
- }));
109
- reqOpts.data.binaryLinks = links;
110
- }
111
- }
112
- return axios(reqOpts)
113
- .then((response) => {
114
- if (options.breakOnWarnings || options.breakOnViolations) {
115
- const getReqOpts = reqOpts;
116
- getReqOpts.method = 'get';
117
- getReqOpts.url += `/${response.data.scanId}`;
118
- delete getReqOpts.data;
119
- let i = 1; // eslint-disable-line prefer-const
120
- checkAnalysisResults(options, getReqOpts, cb, i);
121
- } else {
122
- cb(null, response.data);
123
- }
124
- })
125
- .catch((error) => {
126
- debuglog('unexpected response: error=', error);
127
- cb(JSON.stringify(error));
128
- });
129
- };
1
+ /* eslint-disable */
2
+ /**********************************************************
3
+ * Copyright (c) 2017. Enterprise Architecture Group, EACG
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *********************************************************/
7
+ /* eslint-enable */
8
+ const axios = require('axios').default;
9
+ const debuglog = (require('debuglog'))('ts-rest-client');
10
+ const pckgJson = require('../package.json');
11
+
12
+
13
+ function RestClient(options) {
14
+ if (options === undefined) {
15
+ throw new TypeError('Please specify options for rest client');
16
+ } else if (options.url === undefined) {
17
+ throw new TypeError('Please specify \'url\' attribute in options for rest client');
18
+ }
19
+ this.options = options;
20
+ }
21
+
22
+ function checkWarnings(options) {
23
+ return options.breakOnWarnings;
24
+ }
25
+
26
+ function hasWarnings(analysis) {
27
+ const stats = analysis.statistics;
28
+ return stats ? stats.legal.warnings + stats.vulnerability.warnings + stats.viability.warnings + stats.versioning.warnings : 0;
29
+ }
30
+
31
+ function checkViolations(options) {
32
+ return options.breakOnViolations;
33
+ }
34
+
35
+ function hasViolations(analysis) {
36
+ const stats = analysis.statistics;
37
+ return stats ? stats.legal.violations + stats.vulnerability.violations + stats.viability.violations + stats.versioning.violations : 0;
38
+ }
39
+
40
+ function checkAnalysisResults(options, getReqOpts, cb, i) {
41
+ axios(getReqOpts)
42
+ .then((response) => {
43
+ const scanData = response && response.data;
44
+ if (response && response.status === 200 && scanData && scanData.analysisStatus === 'Finished') {
45
+ if (checkViolations(options) && hasViolations(scanData)) {
46
+ cb(`Analysis found ${hasViolations(scanData)} violations, see more details: ${response.data.url}`);
47
+ }
48
+ if (checkWarnings(options) && hasWarnings(scanData)) {
49
+ cb(`Analysis found ${hasWarnings(scanData)} warnings, see more details: ${response.data.url}`);
50
+ }
51
+ // eslint-disable-next-line no-underscore-dangle
52
+ cb(null, { scanId: scanData._id });
53
+ } else {
54
+ const retryPeriod = i * 5000;
55
+ console.log('Analysis is', ((scanData && scanData.analysisStatus) || 'Scheduled'), 'Retry in ', retryPeriod / 1000, 'sec');
56
+ setTimeout(() => {
57
+ i += 1;
58
+ checkAnalysisResults(options, getReqOpts, cb, i);
59
+ }, retryPeriod);
60
+ }
61
+ })
62
+ .catch((error) => {
63
+ const errorData = error && typeof error.toJSON === 'function' ? error.toJSON() : false;
64
+ if (errorData && (errorData.status === 404)) {
65
+ const retryPeriod = i * 5000;
66
+ console.log('Analysis is Scheduled', 'Retry in ', retryPeriod / 1000, 'sec');
67
+ setTimeout(() => {
68
+ i += 1;
69
+ checkAnalysisResults(options, getReqOpts, cb, i);
70
+ }, retryPeriod);
71
+ } else {
72
+ debuglog('unexpected getResponse: error=', error);
73
+ cb(JSON.stringify(error));
74
+ }
75
+ });
76
+ }
77
+
78
+ exports.RestClient = RestClient;
79
+
80
+ RestClient.prototype.transfer = function transfer(scan, cb) {
81
+ const { options } = this;
82
+ debuglog('transfer started, options:', options);
83
+
84
+ const reqOpts = options.requestOptions || {};
85
+ reqOpts.method = 'post';
86
+ reqOpts.url = `${options.url}/api/v1/scans`;
87
+ if (options.proxy) {
88
+ reqOpts.proxy = options.proxy;
89
+ }
90
+ reqOpts.headers = {
91
+ 'Content-Type': 'application/json',
92
+ 'User-Agent': `${pckgJson.name}/${pckgJson.version}`,
93
+ 'X-ApiKey': options.apiKey
94
+ };
95
+ reqOpts.json = true;
96
+ reqOpts.data = scan;
97
+ if (options.branch) {
98
+ reqOpts.data.branch = options.branch;
99
+ }
100
+ if (options.tag) {
101
+ reqOpts.data.tag = options.tag;
102
+ }
103
+ if (options.binaryLinks) {
104
+ let links = options.binaryLinks.split(',');
105
+ if (links.length) {
106
+ links = links.map((value) => ({
107
+ name: value
108
+ }));
109
+ reqOpts.data.binaryLinks = links;
110
+ }
111
+ }
112
+ return axios(reqOpts)
113
+ .then((response) => {
114
+ if (options.breakOnWarnings || options.breakOnViolations) {
115
+ const getReqOpts = reqOpts;
116
+ getReqOpts.method = 'get';
117
+ getReqOpts.url += `/${response.data.scanId}`;
118
+ delete getReqOpts.data;
119
+ let i = 1; // eslint-disable-line prefer-const
120
+ checkAnalysisResults(options, getReqOpts, cb, i);
121
+ } else {
122
+ cb(null, response.data);
123
+ }
124
+ })
125
+ .catch((error) => {
126
+ debuglog('unexpected response: error=', error);
127
+ cb(JSON.stringify(error));
128
+ });
129
+ };
package/lib/scanresult.js CHANGED
@@ -1,32 +1,32 @@
1
- /* eslint-disable */
2
- /**********************************************************
3
- * Copyright (c) 2017. Enterprise Architecture Group, EACG
4
- *
5
- * SPDX-License-Identifier: Apache-2.0
6
- *********************************************************/
7
- /* eslint-enable */
8
-
9
-
10
- const Dependency = require('./dependency');
11
-
12
- function ScanResult(project, module, moduleId, dependencies) {
13
- this.project = project;
14
- this.module = module;
15
- this.moduleId = moduleId;
16
- this.dependencies = [];
17
-
18
-
19
- if (dependencies instanceof Dependency) {
20
- this.dependencies.push(dependencies);
21
- } else if (dependencies instanceof Object) {
22
- // works also for arrays
23
- Object.keys(dependencies).forEach((key) => {
24
- if (dependencies[key] instanceof Dependency) {
25
- this.dependencies.push(dependencies[key]);
26
- }
27
- });
28
- }
29
- }
30
-
31
-
32
- module.exports = ScanResult;
1
+ /* eslint-disable */
2
+ /**********************************************************
3
+ * Copyright (c) 2017. Enterprise Architecture Group, EACG
4
+ *
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *********************************************************/
7
+ /* eslint-enable */
8
+
9
+
10
+ const Dependency = require('./dependency');
11
+
12
+ function ScanResult(project, module, moduleId, dependencies) {
13
+ this.project = project;
14
+ this.module = module;
15
+ this.moduleId = moduleId;
16
+ this.dependencies = [];
17
+
18
+
19
+ if (dependencies instanceof Dependency) {
20
+ this.dependencies.push(dependencies);
21
+ } else if (dependencies instanceof Object) {
22
+ // works also for arrays
23
+ Object.keys(dependencies).forEach((key) => {
24
+ if (dependencies[key] instanceof Dependency) {
25
+ this.dependencies.push(dependencies[key]);
26
+ }
27
+ });
28
+ }
29
+ }
30
+
31
+
32
+ module.exports = ScanResult;