Skip to content

Commit d09e13b

Browse files
committed
Updated sources
1 parent 658edb7 commit d09e13b

12 files changed

Lines changed: 658 additions & 941 deletions

package-lock.json

Lines changed: 379 additions & 754 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "groupdocs-conversion-cloud",
3-
"version": "23.7.0",
3+
"version": "23.8.0",
44
"description": "GroupDocs.Conversion Cloud SDK for Node.js",
55
"homepage": "https://products.groupdocs.cloud/conversion",
66
"author": {
@@ -26,20 +26,23 @@
2626
"clean": "rimraf ./lib && rimraf ./node_modules",
2727
"lint": "npm install --no-save && tslint src/{,**/}*.ts test/{,**/}*.ts -t verbose --project ./tsconfig.json",
2828
"test": "npm install --no-save && mocha -r ts-node/register test/**/*.ts --timeout 60000 --reporter spec",
29+
"test1": "npm install --no-save && mocha -r ts-node/register test/**/test_conversion_api.ts --timeout 60000 --reporter spec",
2930
"build:dev": "rimraf ./lib && npm install --no-save && tsc --build ./tsconfig-dev.json",
3031
"build:lib": "rimraf ./lib && npm install --no-save && tsc --build ./tsconfig.json",
3132
"build:package": "npm pack"
3233
},
3334
"dependencies": {
34-
"@types/request": "*",
35-
"jsonwebtoken": "*",
36-
"request": "^2.88.2",
37-
"request-debug": "^0.2.0"
35+
"axios": "1.3.0",
36+
"form-data": "*",
37+
"jsonwebtoken": "9.0.1",
38+
"qs": "6.11.2"
3839
},
3940
"devDependencies": {
4041
"@types/chai": "^4.2.14",
42+
"@types/jsonwebtoken": "9.0.1",
4143
"@types/mocha": "^5.2.7",
4244
"@types/node": "^12.19.15",
45+
"@types/qs": "^6.9.7",
4346
"chai": "^4.2.0",
4447
"mocha": "^10.2.0",
4548
"ts-node": "^8.6.2",

src/api_client.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import request = require("request");
26-
import requestDebug = require("request-debug");
25+
import axios, { AxiosResponse, RawAxiosRequestConfig } from "axios";
2726
import { Configuration } from "./configuration";
2827
import { PackageVersion } from "./package_version";
2928

@@ -33,7 +32,7 @@ import { PackageVersion } from "./package_version";
3332
* @param config Configuration
3433
* @param skipAuth If enabled, auth is not applied to request
3534
*/
36-
export async function invokeApiMethod(requestOptions: request.Options, config: Configuration, skipAuth?: boolean): Promise<request.RequestResponse> {
35+
export async function invokeApiMethod(requestOptions: RawAxiosRequestConfig, config: Configuration, skipAuth?: boolean): Promise<AxiosResponse> {
3736
return await invokeApiMethodInternal(requestOptions, config, skipAuth);
3837
}
3938

@@ -64,14 +63,14 @@ export function addQueryParameterToUrl(url, queryParameters, parameterName, para
6463
* @param config Configuration
6564
* @param skipAuth If enabled, auth is not applied to request
6665
*/
67-
async function invokeApiMethodInternal(requestOptions: request.Options, config: Configuration, skipAuth?: boolean): Promise<request.RequestResponse> {
68-
if (config.debugging === true) {
69-
requestDebug(request, (type, data) => {
70-
const toLog = {};
71-
toLog[type] = data;
72-
console.log(JSON.stringify(toLog, undefined, 2));
73-
});
74-
}
66+
async function invokeApiMethodInternal(requestOptions: RawAxiosRequestConfig, config: Configuration, skipAuth?: boolean): Promise<AxiosResponse> {
67+
// if (config.debugging === true) {
68+
// requestDebug(request, (type, data) => {
69+
// const toLog = {};
70+
// toLog[type] = data;
71+
// console.log(JSON.stringify(toLog, undefined, 2));
72+
// });
73+
// }
7574

7675
if (!requestOptions.headers) {
7776
requestOptions.headers = {};
@@ -85,36 +84,37 @@ async function invokeApiMethodInternal(requestOptions: request.Options, config:
8584
await auth.applyToRequest(requestOptions, config);
8685
}
8786

88-
return new Promise<request.RequestResponse>((resolve, reject) => {
89-
request(requestOptions, async (error, response) => {
90-
if (error) {
91-
reject(error);
87+
return new Promise<AxiosResponse>((resolve, reject) => {
88+
axios(requestOptions)
89+
.then((response) => {
90+
if (response.status >= 200 && response.status <= 299) {
91+
resolve(response);
9292
} else {
93-
if (response.statusCode >= 200 && response.statusCode <= 299) {
94-
resolve(response);
95-
} else {
96-
try {
97-
let bodyContent = response.body;
98-
if (bodyContent instanceof Buffer) {
99-
bodyContent = JSON.parse(bodyContent.toString("utf8"));
100-
}
101-
if (bodyContent.error) {
102-
if (bodyContent.error.message) {
103-
reject({ message: bodyContent.error.message, code: bodyContent.error.code });
104-
} else {
105-
reject({ message: bodyContent.error, code: response.statusCode });
106-
}
107-
} else {
108-
if (bodyContent.message) {
109-
reject({ message: bodyContent.message, code: bodyContent.code });
110-
} else {
111-
reject({ message: bodyContent, code: response.statusCode });
112-
}
113-
}
114-
} catch (error) {
115-
reject({ message: "Error while parse server error: " + error });
93+
reject({ message: response.data, code: response.status });
94+
}
95+
})
96+
.catch((error: any) => {
97+
try {
98+
const response = error.response;
99+
let bodyContent = response.data;
100+
if (bodyContent instanceof Buffer) {
101+
bodyContent = JSON.parse(bodyContent.toString("utf8"));
102+
}
103+
if (bodyContent.error) {
104+
if (bodyContent.error.message) {
105+
reject({ message: bodyContent.error.message, code: bodyContent.error.code });
106+
} else {
107+
reject({ message: bodyContent.error, code: response.status });
116108
}
109+
} else {
110+
if (bodyContent.message) {
111+
reject({ message: bodyContent.message, code: bodyContent.code });
112+
} else {
113+
reject({ message: bodyContent, code: response.status });
114+
}
117115
}
116+
} catch (error) {
117+
reject({ message: "Error while parse server error: " + error });
118118
}
119119
});
120120
});

src/auth.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
*/
2424

2525
import jwt = require("jsonwebtoken");
26-
import request = require("request");
26+
import { RawAxiosRequestConfig } from "axios";
2727
import { invokeApiMethod } from "./api_client";
2828
import { Configuration } from "./configuration";
29+
import qs = require("qs");
2930

3031
/**
3132
* Authentication logic for api calls
@@ -34,7 +35,7 @@ export interface IAuthentication {
3435
/**
3536
* Apply authentication settings to header and query params.
3637
*/
37-
applyToRequest(requestOptions: request.Options, configuration: Configuration): void;
38+
applyToRequest(requestOptions: RawAxiosRequestConfig, configuration: Configuration): void;
3839

3940
}
4041

@@ -47,7 +48,7 @@ export class OAuth implements IAuthentication {
4748
/**
4849
* Apply authentication settings to header and query params
4950
*/
50-
public async applyToRequest(requestOptions: request.Options, configuration: Configuration): Promise<void> {
51+
public async applyToRequest(requestOptions: RawAxiosRequestConfig, configuration: Configuration): Promise<void> {
5152
if (this.accessToken == null || !this.isTokenValid()) {
5253
await this._requestToken(configuration);
5354
}
@@ -60,25 +61,27 @@ export class OAuth implements IAuthentication {
6061
}
6162

6263
private async _requestToken(configuration: Configuration): Promise<void> {
63-
const requestOptions: request.Options = {
64-
method: "POST",
65-
json: true,
66-
uri: configuration.apiBaseUrl + "/connect/token",
67-
form: {
68-
grant_type: "client_credentials",
69-
client_id: configuration.appSid,
70-
client_secret: configuration.appKey,
71-
},
64+
const requestOptions: RawAxiosRequestConfig = {
65+
method: "post",
66+
headers: { "content-type": "application/x-www-form-urlencoded" },
67+
maxBodyLength: Infinity,
68+
url: configuration.apiBaseUrl + "/connect/token",
69+
data : qs.stringify({
70+
grant_type: "client_credentials",
71+
client_id: configuration.appSid,
72+
client_secret: configuration.appKey,
73+
}),
7274
};
73-
75+
7476
const response = await invokeApiMethod(requestOptions, configuration, true);
75-
this.accessToken = response.body.access_token;
77+
this.accessToken = response.data.access_token;
78+
7679
return Promise.resolve();
7780
}
7881

7982
private isTokenValid() {
8083
try {
81-
const decodedToken = jwt.decode(this.accessToken);
84+
const decodedToken = jwt.decode(this.accessToken) as jwt.JwtPayload;
8285

8386
if (!decodedToken) {
8487
console.log("Invalid token.");

0 commit comments

Comments
 (0)