Skip to content

Commit

Permalink
Update SDK to solve vulnerability issues
Browse files Browse the repository at this point in the history
Like deprecation of request package

Solves:
#30
#23
#21
  • Loading branch information
YonatanKiron committed Jan 1, 2024
1 parent 15cca62 commit 0bf0210
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@
"t": "tsc -p src ; node dist/tester.js"
},
"devDependencies": {
"@types/node": "6.0.52",
"@types/request": "0.0.36",
"@types/node": "^13.11.1",
"chai": "^4.1.2",
"jsdoc": "^3.5.5",
"mocha": "^5.2.0",
"nyc": "^11.8.0",
"tslint": "^5.10.0",
"typescript": "2.1.4"
"jsdoc": "^4.0.2",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"tslint": "^5.20.1",
"typescript": "^5.3.3"
},
"dependencies": {
"axios": "^1.6.3",
"form-data": "^2.5.0",
"json-stringify-safe": "5.0.1",
"object-sizeof": "1.1.1",
"request": "2.88.0",
"rxjs": "5.4.0"
"proxy-from-env": "^1.1.0",
"rxjs": "^6.6.7",
"rxjs-compat": "^6.6.7"
},
"directories": {
"doc": "docs",
Expand Down
20 changes: 17 additions & 3 deletions src/entities/LoggerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @since 1.0.0
*/

import {AxiosBasicCredentials, AxiosProxyConfig} from "axios";
import {Constants} from "../constants";
import {IPHelper} from "../helpers/ip.helper";

Expand Down Expand Up @@ -67,14 +68,27 @@ export class LoggerConfig {
public debug: boolean = false;

/**
* @member {string|undefined} proxyUri
* @member {URL|undefined} proxyUri
* @memberOf LoggerConfig
* @description Proxy uri
* @default undefined
* @public
*/
public proxyUri?: string;
public proxyUri?: AxiosProxyConfig;

private getAxioProxyConfig(proxyUri?: string): AxiosProxyConfig | undefined {
if (proxyUri) {
const proxyURL = new URL(proxyUri)
const axioAuth: AxiosBasicCredentials = {username: proxyURL.username, password: proxyURL.password}
const proxyConfig: AxiosProxyConfig = {
host: proxyURL.host || proxyURL.hostname,
port: Number.parseInt(proxyURL.port),
auth: axioAuth,
protocol: proxyURL.protocol
}
return proxyConfig
}
}
/**
* @description Initialize new instance of logger configuration container class
* @param {object} [config] - Logger configuration parameters
Expand All @@ -85,6 +99,6 @@ export class LoggerConfig {
this.subsystemName = config.subsystemName || this.subsystemName;
this.computerName = config.computerName || this.computerName;
this.debug = config.debug;
this.proxyUri = config.proxyUri;
this.proxyUri = this.getAxioProxyConfig(config.proxyUri) ? config.proxyUri : null;
}
}
2 changes: 1 addition & 1 deletion src/helpers/rx.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @since 1.0.0
*/

import {Observable} from "rxjs";
import {Observable} from "rxjs-compat";

/**
* @namespace rxHelper
Expand Down
29 changes: 12 additions & 17 deletions src/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* @since 1.0.0
*/

import * as request from "request";
import {CoreOptions, UrlOptions} from "request";
import axios, {AxiosRequestConfig} from 'axios';
//import {CoreOptions, UrlOptions} from "request";
import {Observable} from "rxjs";
import {Constants} from "./constants";
import {LoggerConfig} from "./entities/LoggerConfig";
Expand All @@ -31,30 +31,25 @@ export namespace HttpHelper {
* @returns {Observable<HTTPResponse>} Valid HTTP response object
*/
export function sendBulk(jsonData: any, config: LoggerConfig): Observable<HTTPResponse> {
const options: CoreOptions & UrlOptions = {
body: jsonData,
gzip: true,
json: true,
method: "POST",
const options: AxiosRequestConfig = {
decompress: true,
timeout: Constants.HTTP_TIMEOUT,
url: Constants.CORALOGIX_LOG_URL,
};
if (config.proxyUri) {
options.proxy = config.proxyUri;
}

return Observable.create(observer => {
request(options, (error, response, body) => {
if (error || response.statusCode < 200 || response.statusCode > 299) {
if (!error) {
error = {code: response.statusCode};
}
observer.error(error);
axios.post(Constants.CORALOGIX_LOG_URL, jsonData, options)
.then(response => {
if (response.status < 200 || response.status > 299) {
observer.error({code: response.status})
} else {
observer.next(new HTTPResponse(response, body));
observer.next(new HTTPResponse(response, response.data.json));
}
observer.complete();
});
}).catch(error => {
observer.error(error);
}).finally(() => observer.complete());
});
}

Expand Down

0 comments on commit 0bf0210

Please sign in to comment.