Skip to content

Commit

Permalink
[update] axios version due to an error,added 2nd param to connection …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
Lucky-victory committed Apr 26, 2022
1 parent 1a6e9ba commit 4e3c517
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 44 deletions.
38 changes: 25 additions & 13 deletions lib/core/harpeeConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ const util = require("../helpers/util");

const harpeeConnectConfig = require("./harpeeConnectConfig");

/**
*
* @typedef {{host:string,username:string,password:string,token?:string}} Config
*/
/**
* Creates a Connection to your harperDB instance, this is the only connection you will need. it covers the connections required for `Utilities` and `Logger` classes.
* @param {object} config - config object that takes in `host`, `username`,`password` and `token`.
* @param {string} config.host - your harperdb host url.
* @param {string} config.username - your harperdb username.
* @param {string} config.password - your harperdb password.
* @param {string} [config.token] - your generated JWT token.
* @param {Config} config - config object that takes in `host`, `username`,`password` and/or `token`.
* @param {(info?:Config,error?:any)=>void} [connectionInfo] - get the connection details or error if any
* @returns {void}
**/
function createConnection(config) {
if (!util.isObject(config)) {
throw new TypeError("connection `config` must be an Object");
*/
function createConnection(config,connectionInfo) {
try{

if (!util.isObject(config)) {
throw new TypeError("connection `config` must be an Object");
}
if (!config.host) {
throw new Error("`host` is required");
Expand All @@ -22,17 +25,26 @@ function createConnection(config) {
const username = config.username || null;
const password = config.password || null;
const token = config.token || null;

if ((username && !password) || (password && !username)) {
throw new Error("you must include both `username` and `password`");
}
if ((username && password && token)) {
throw new Error(
"you should include `username` and `password` or only `token`"
);
);
}
const connectionConfig = { host, username, password, token };
harpeeConnectConfig.setConfig(connectionConfig);
if(util.isFunction(connectionInfo)){
connectionInfo(connectionConfig,null)
}
}
catch(error){
if(util.isFunction(connectionInfo)){
connectionInfo(null,error);
}
}
const connectionConfig = { host, username, password, token };
harpeeConnectConfig.setConfig(connectionConfig);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions lib/core/harpeeHttp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require('axios').default;
const axios = require('axios');
const util =require("../helpers/util");

class HarpeeHttp {
Expand All @@ -16,9 +16,7 @@ class HarpeeHttp {
*/
$requestHandler(reqBody, callback) {
let auth;
const username = this.config.username;
const password = this.config.password;
const token = this.config.token;
const {username,password,token,host} = this.config;
if (token) {
auth = "Bearer " + token;
}
Expand All @@ -30,7 +28,7 @@ class HarpeeHttp {
);
}
const errorObj = {};
axios({url:this.config.host,
axios({url:host,
method: "post",
headers: {
"Content-Type": "application/json",
Expand Down
121 changes: 110 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harpee",
"version": "3.0.12",
"version": "3.0.13",
"description": "Harpee is a modeling tool for HarperDB, harpee supports both callbacks and Promises.",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand All @@ -25,13 +25,13 @@
"license": "MIT",
"typings": "./types/index.d.ts",
"dependencies": {
"axios":"^0.25.0"
"axios": "^0.27.1"
},
"devDependencies": {
"typescript": "^4.3.5",
"@babel/cli": "7.16.8",
"@babel/core": "7.16.7",
"@babel/preset-env": "7.16.8"
"@babel/preset-env": "7.16.8",
"typescript": "^4.3.5"
},
"repository": {
"type": "git",
Expand Down
24 changes: 13 additions & 11 deletions types/core/harpeeConnect.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/**
* Creates a Connection to your harperDB instance, this is the only connection you will need. it covers the connections required for `Utilities` and `Logger` classes.
* @param {object} config - config object that takes in `host`, `username`,`password` and `token`.
* @param {string} config.host - your harperdb host url.
* @param {string} config.username - your harperdb username.
* @param {string} config.password - your harperdb password.
* @param {string} [config.token] - your generated JWT token.
* @returns {void}
**/
export function createConnection(config: {
export type Config = {
host: string;
username: string;
password: string;
token?: string;
}): void;
};
/**
*
* @typedef {{host:string,username:string,password:string,token?:string}} Config
*/
/**
* Creates a Connection to your harperDB instance, this is the only connection you will need. it covers the connections required for `Utilities` and `Logger` classes.
* @param {Config} config - config object that takes in `host`, `username`,`password` and/or `token`.
* @param {(info?:Config,error?:any)=>void} [connectionInfo] - get the connection details or error if any
* @returns {void}
*/
export function createConnection(config: Config, connectionInfo?: (info?: Config, error?: any) => void): void;
/**
* An alias for `createConnection`, to support older versions of **Harpee**.
* @deprecated
Expand Down

0 comments on commit 4e3c517

Please sign in to comment.