Task: Updated sdk client and updated the missing types for http tunnel client

This commit is contained in:
Sambo Chea 2022-07-09 21:17:08 +07:00
parent 23c7bda220
commit 1af63d5955
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
3 changed files with 11 additions and 12 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules/ node_modules/
npm-debug.log npm-debug.log
dist/

View File

@ -9,7 +9,7 @@ import { TunnelRequest, TunnelResponse } from "./lib";
import { generateUUID, addPrefixOnHttpSchema } from "./util"; import { generateUUID, addPrefixOnHttpSchema } from "./util";
import { Socket } from 'socket.io-client'; import { Socket } from 'socket.io-client';
const sdk = require("../sdk"); import { getTokenFree } from './sdk'
const packageInfo = require("../package.json"); const packageInfo = require("../package.json");
@ -276,9 +276,8 @@ program
if (!config.token) { if (!config.token) {
console.log("Generating token..."); console.log("Generating token...");
await sdk await getTokenFree(config.server)
.getTokenFree(config.server) .then((resp: any) => {
.then((resp) => {
if (resp.data?.token) { if (resp.data?.token) {
config.token = resp.data?.token; config.token = resp.data?.token;
} else { } else {
@ -286,7 +285,7 @@ program
return; return;
} }
}) })
.catch((err) => { .catch((err: any) => {
console.error("cannot get free token from server", err); console.error("cannot get free token from server", err);
return; return;
}); });
@ -430,9 +429,8 @@ program
// FREE // FREE
if (config.access === TOKEN_FREE) { if (config.access === TOKEN_FREE) {
await sdk await getTokenFree(config.server)
.getTokenFree(config.server) .then((resp: any) => {
.then((resp) => {
if (resp.data?.token) { if (resp.data?.token) {
config.token = resp.data?.token; config.token = resp.data?.token;
} else { } else {
@ -440,7 +438,7 @@ program
return; return;
} }
}) })
.catch((err) => { .catch((err: any) => {
console.error("cannot get free token from server", err); console.error("cannot get free token from server", err);
return; return;
}); });

View File

@ -1,6 +1,6 @@
const axios = require("axios").default; const axios = require("axios").default;
const getTokenFree = async (baseUrl, data = {}) => { const getTokenFree = async (baseUrl: string, data: any = {}) => {
const url = `${baseUrl}/__free__/api/get_token`; const url = `${baseUrl}/__free__/api/get_token`;
return axios({ return axios({
method: "POST", method: "POST",
@ -14,6 +14,6 @@ const getTokenFree = async (baseUrl, data = {}) => {
}); });
}; };
module.exports = { export {
getTokenFree, getTokenFree,
}; };