Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lambdatest/node-rest-client

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lambdatest/node-rest-client - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

75

lib/api_client.js

@@ -0,55 +1,8 @@

const { version, baseUrl } = require("./config");
var request = require("request"),
logger,
Config = require("./config");
packageVersion = require("../../package.json").version;
/**
* Operates on an instance of ApiClient and returns latest version and list of supported versions.
* @param {!AutomationApiClient} settings An object that for lambda user credentials
* explanation that spans multiple lines.
* @param {number} retries for max attemt to fetch
* @param {Function} fnCallback is callback function.
* @return {Function|Error} return version that is supported by lambdaTest Rest Client e.g. v1, v2 etc.
*/
var fetchApiVersions_ = function(settings, retries, fnCallback) {
/** Check left retries */
if (retries >= 0) {
request(Config.httpApiVersionPath, function(e, response, body) {
if (e) {
logger.error("Error while fetching version from server path ", e);
fetchApiVersions_(settings, retries - 1, fnCallback);
} else {
/** use try-catch Possibly Error due to json parse of non-parseable */
try {
body = JSON.parse(body);
/** Check for supportedVersions list is there */
if (body.supportedVersions && body.supportedVersions.length) {
/** Check Requester request for version and exist in supportedVersions list */
if (settings.version) {
if (body.supportedVersions.indexOf(settings.version) === -1) {
return fnCallback(true, null);
} else {
return fnCallback(false, settings.version);
}
} else {
return fnCallback(false, body.latestVersion);
}
} else {
fetchApiVersions_(settings, retries - 1, fnCallback);
}
} catch (e) {
logger.error(
"Error while parse to json of output response of versions json path ",
e
);
/** Re-Attemp to fetch If getting Error */
fetchApiVersions_(settings, retries - 1, fnCallback);
}
}
});
} else {
return fnCallback(true, null);
}
};
/**
* ApiClient is a function based Class.

@@ -59,3 +12,3 @@ * @param {!AutomationApiClient} settings An object that for lambda user credentials

var ApiClient = function(settings) {
settings = settings || { };
settings = settings || {};
/**

@@ -75,3 +28,3 @@ * Required check for username.

}
if(!logger) {
if (!logger) {
logger = require("./logger")(settings.logFile);

@@ -99,14 +52,4 @@ }

if (ApiClient.baseUrl === undefined) {
/** Calling method for Update baseUrl and Request pass to Server for Getting Response
* @return {Function|Error} return response to Callable method or throw Error.
*/
fetchApiVersions_(ApiClient.settings, 5, function(e, response) {
if (e) {
logger.error("Error while fetching Versions", e);
throw new Error("Invalid Api version");
} else {
ApiClient.baseUrl = Config.baseUrl + response;
ApiClient.request(options, fnCallback);
}
});
ApiClient.baseUrl = baseUrl + version.latestVersion;
ApiClient.request(options, fnCallback);
} else {

@@ -118,3 +61,5 @@ /** Update Options with User Credential If It is object */

"Content-Type": "application/json",
Accept: "application/json"
Accept: "application/json",
client: "npm-rest-client",
version: packageVersion
};

@@ -121,0 +66,0 @@ options.url = ApiClient.baseUrl + options.url;

409

lib/automation_client.js

@@ -22,15 +22,34 @@ var ApiClient = require("./api_client");

AutomationApiClient.prototype.fetchBuilds = function(params, fnCallback) {
fnCallback = fnCallback || function() { };
if (typeof params === "function") {
fnCallback = params;
if (typeof fnCallback === "function") {
fnCallback = fnCallback || function() {};
if (typeof params === "function") {
fnCallback = params;
}
params = params || {};
ApiClient.request(
{
url: "/builds",
qs: params
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
params = params || {};
ApiClient.request(
{
url: "/builds",
qs: params
},
function(err, response) {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
}
params = params || {};
ApiClient.request(
{
url: "/builds",
qs: params
},
fnCallback
);
};

@@ -45,12 +64,28 @@

AutomationApiClient.prototype.fetchBuildById = function(buildId, fnCallback) {
fnCallback = fnCallback || function() { };
if(typeof buildId === 'function') {
throw new Error('buildId is Required');
if(typeof fnCallback === "function") {
if (typeof buildId === "function") {
throw new Error("buildId is Required");
}
ApiClient.request(
{
url: "/builds/" + buildId
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
ApiClient.request(
{
url: "/builds/" + buildId
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
})
}
ApiClient.request(
{
url: "/builds/" + buildId
},
fnCallback
);
};

@@ -65,13 +100,30 @@

AutomationApiClient.prototype.deleteBuildById = function(buildId, fnCallback) {
fnCallback = fnCallback || function() { };
if(typeof buildId === 'function') {
throw new Error('buildId is Required');
if(typeof fnCallback === "function") {
if (typeof buildId === "function") {
throw new Error("buildId is Required");
}
ApiClient.request(
{
url: "/builds/" + buildId,
method: "DELETE"
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
ApiClient.request(
{
url: "/builds/" + buildId,
method: "DELETE"
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
})
}
ApiClient.request(
{
url: "/builds/" + buildId,
method: "DELETE"
},
fnCallback
);
};

@@ -92,27 +144,62 @@

) {
fnCallback = fnCallback || function() { };
if(typeof buildId === 'function' || typeof buildId === 'object') {
throw new Error('buildId is Required');
}
/**
* Checking validity of requestBody payload.
* @return {Error|null}
*/
if (typeof requestBody === "object") {
// use try-catch Error possible due to json stringify
try {
requestBody = JSON.stringify(requestBody);
ApiClient.request(
{
url: "/builds/" + buildId,
body: requestBody,
method: "PATCH"
},
fnCallback
);
} catch (error) {
return fnCallback(error, null);
if(typeof fnCallback === "function") {
if (typeof buildId === "function" || typeof buildId === "object") {
throw new Error("buildId is Required");
}
/**
* Checking validity of requestBody payload.
* @return {Error|null}
*/
if (typeof requestBody === "object") {
// use try-catch Error possible due to json stringify
try {
requestBody = JSON.stringify(requestBody);
ApiClient.request(
{
url: "/builds/" + buildId,
body: requestBody,
method: "PATCH"
},
fnCallback
);
} catch (error) {
return fnCallback(error, null);
}
} else {
throw new Error("It's look like your requestBody Payload is Invalid");
}
} else {
throw new Error("It's look like your requestBody Payload is Invalid");
return new Promise((resolve, reject) => {
if (typeof buildId === "function" || typeof buildId === "object") {
throw new Error("buildId is Required");
}
/**
* Checking validity of requestBody payload.
* @return {Error|null}
*/
if (typeof requestBody === "object") {
// use try-catch Error possible due to json stringify
try {
requestBody = JSON.stringify(requestBody);
ApiClient.request(
{
url: "/builds/" + buildId,
body: requestBody,
method: "PATCH"
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
} catch (err) {
reject(err);
}
} else {
throw new Error("It's look like your requestBody Payload is Invalid");
}
})
}

@@ -128,13 +215,56 @@ };

AutomationApiClient.prototype.fetchSessions = function(params, fnCallback) {
if (typeof params === "function") {
if(typeof params !== "function" && typeof fnCallback !== "function") {
return new Promise((resolve, reject) => {
if(typeof params !== "object") {
params = { };
}
ApiClient.request(
{
url: "/sessions",
qs: params
},
function(err, response) {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
} else if(typeof params === "object" && typeof fnCallback === "function") {
ApiClient.request(
{
url: "/sessions",
qs: params
},
fnCallback
);
} else if(typeof params === "function") {
fnCallback = params;
ApiClient.request(
{
url: "/sessions",
qs: { }
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
params = { };
ApiClient.request(
{
url: "/sessions",
qs: params
},
function(err, response) {
if (err) {
reject(err);
} else {
resolve(response);
}
}
);
});
}
params = params || {};
ApiClient.request(
{
url: "/sessions",
qs: params
},
fnCallback
);
};

@@ -152,12 +282,28 @@

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}
ApiClient.request(
{
url: "/sessions/" + sessionId
},
fnCallback
);
if(typeof fnCallback === "function") {
ApiClient.request(
{
url: "/sessions/" + sessionId
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
ApiClient.request(
{
url: "/sessions/" + sessionId
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
})
}
};

@@ -175,13 +321,30 @@

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}
ApiClient.request(
{
url: "/sessions/" + sessionId,
method: "DELETE"
},
fnCallback
);
if(typeof fnCallback === "function") {
ApiClient.request(
{
url: "/sessions/" + sessionId,
method: "DELETE"
},
fnCallback
);
} else {
return new Promise((resolve, reject) => {
ApiClient.request(
{
url: "/sessions/" + sessionId,
method: "DELETE"
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
})
}
};

@@ -201,5 +364,4 @@

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -209,5 +371,7 @@ /**

* @return {Error|null}
*/
if (typeof requestBody === "object") {
// use try-catch Error possible due to json stringify
*/
if(typeof requestBody === "object") {
throw new Error("It's look like your requestBody Payload is Invalid");
}
if(typeof fnCallback === "function") {
try {

@@ -227,3 +391,24 @@ requestBody = JSON.stringify(requestBody);

} else {
throw new Error('It\'s look like your requestBody Payload is Invalid');
return new Promise((resolve, reject) => {
// use try-catch Error possible due to json stringify
try {
requestBody = JSON.stringify(requestBody);
ApiClient.request(
{
url: "/builds/" + buildId,
body: requestBody,
method: "PATCH"
},
function(err, response) {
if(err) {
reject(err);
} else {
resolve(response);
}
}
);
} catch (err) {
reject(err);
}
})
}

@@ -242,5 +427,5 @@ };

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -265,5 +450,5 @@ ApiClient.request(

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -288,5 +473,5 @@ ApiClient.request(

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -311,5 +496,5 @@ ApiClient.request(

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -334,5 +519,5 @@ ApiClient.request(

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -357,5 +542,5 @@ ApiClient.request(

) {
fnCallback = fnCallback || function() { };
if(typeof sessionId === 'function' || typeof sessionId === 'object') {
throw new Error('sessionId is Required');
fnCallback = fnCallback || function() {};
if (typeof sessionId === "function" || typeof sessionId === "object") {
throw new Error("sessionId is Required");
}

@@ -376,3 +561,3 @@ ApiClient.request(

AutomationApiClient.prototype.fetchTunnels = function(fnCallback) {
fnCallback = fnCallback || function() { };
fnCallback = fnCallback || function() {};
ApiClient.request(

@@ -396,5 +581,5 @@ {

) {
fnCallback = fnCallback || function() { };
if(typeof tunnelId === 'function' || typeof tunnelId === 'object') {
throw new Error('tunnelId is Required');
fnCallback = fnCallback || function() {};
if (typeof tunnelId === "function" || typeof tunnelId === "object") {
throw new Error("tunnelId is Required");
}

@@ -416,3 +601,3 @@ ApiClient.request(

AutomationApiClient.prototype.fetchPlatforms = function(fnCallback) {
fnCallback = fnCallback || function() { };
fnCallback = fnCallback || function() {};
ApiClient.request(

@@ -419,0 +604,0 @@ {

module.exports = {
httpApiVersionPath:
"https://downloads.lambdatest.com/npm/api/supported_versions.json",
version: {"latestVersion": "v1", "supportedVersions": ["v1"]},
baseUrl: "https://api.lambdatest.com/automation/api/"
};
{
"name": "@lambdatest/node-rest-client",
"version": "1.0.0",
"version": "1.0.1",
"description": "LambdaTest Rest Client for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

![LambdaTest Logo](https://www.lambdatest.com/static/images/logo.svg)
# Node LambdaTest
[![npm version](https://badge.fury.io/js/%40lambdatest%2Fnode-rest-client.svg)](https://badge.fury.io/js/%40lambdatest%2Fnode-rest-client)

@@ -198,1 +199,5 @@ A Node.js JavaScript client for working with [LambdaTest](https://www.lambdatest.com) through [Automation API](https://www.lambdatest.com/support/docs/api-doc).

- `callback` (`function(error, platforms)`): A callback to invoke when the API call is complete.
## About LambdaTest
[LambdaTest](https://www.lambdatest.com/) is a cloud based selenium grid infrastructure that can help you run automated cross browser compatibility tests on 2000+ different browser and operating system environments. LambdaTest supports all programming languages and frameworks that are supported with Selenium, and have easy integrations with all popular CI/CD platforms. It's a perfect solution to bring your [selenium automation testing](https://www.lambdatest.com/selenium-automation) to cloud based infrastructure that not only helps you increase your test coverage over multiple desktop and mobile browsers, but also allows you to cut down your test execution time by running tests on parallel.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc