Socket
Socket
Sign inDemoInstall

saucelabs

Package Overview
Dependencies
Maintainers
4
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

saucelabs - npm Package Compare versions

Comparing version 3.1.1 to 4.0.0

aa.js

9

build/constants.js

@@ -8,7 +8,5 @@ "use strict";

var _changeCase = _interopRequireDefault(require("change-case"));
var _changeCase = require("change-case");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const protocols = [require('../apis/sauce.json'), require('../apis/rdc.json'), require('../apis/performance.json'), require('../apis/orchestrator.json')];
const protocols = [require('../apis/sauce.json'), require('../apis/rdc.json'), require('../apis/performance.json')];
const protocolFlattened = new Map();

@@ -29,3 +27,3 @@ const parametersFlattened = new Map();

for (const [method, description] of Object.entries(methods)) {
let commandName = _changeCase.default.camelCase(description.operationId);
let commandName = (0, _changeCase.camelCase)(description.operationId);
/**

@@ -35,3 +33,2 @@ * mark commands as depcrecated in the command names

if (description.deprecated) {

@@ -38,0 +35,0 @@ commandName += 'Deprecated';

@@ -10,12 +10,8 @@ "use strict";

var _zlib = _interopRequireDefault(require("zlib"));
var _path = _interopRequireDefault(require("path"));
var _request = _interopRequireDefault(require("request"));
var _got = _interopRequireDefault(require("got"));
var _changeCase = _interopRequireDefault(require("change-case"));
var _changeCase = require("change-case");
var _formData = _interopRequireDefault(require("form-data"));
var _utils = require("./utils");

@@ -32,6 +28,3 @@

this._accessKey = this._options.key;
this._auth = {
user: this.username,
pass: this._accessKey
};
this._auth = `${this.username}:${this._accessKey}`;
this.proxy = this._options.proxy;

@@ -44,3 +37,8 @@ /**

this.headless = this._options.headless;
return new Proxy({}, {
return new Proxy({
username: this.username,
key: `XXXXXXXX-XXXX-XXXX-XXXX-XXXXXX${(this._accessKey || '').slice(-6)}`,
region: this._options.region,
headless: this._options.headless
}, {
get: this.get.bind(this)

@@ -50,3 +48,3 @@ });

get(obj, propName) {
get(_, propName) {
/**

@@ -56,2 +54,4 @@ * print to string output

*/
/* istanbul ignore next */
if (propName === _constants.SYMBOL_INSPECT || propName === 'inspect') {

@@ -91,2 +91,4 @@ return () => (0, _utils.toString)(this);

*/
/* istanbul ignore next */
if (typeof propName !== 'string') {

@@ -106,12 +108,4 @@ return;

}
/**
* have special implementations for certain operations
*/
if (propName === 'uploadJobAssets') {
return this.uploadJobAssets.bind(this);
}
return (...args) => {
return async (...args) => {
const {

@@ -164,5 +158,3 @@ description,

const expectedType = optionParam.type.replace('integer', 'number');
const optionName = _changeCase.default.camelCase(optionParam.name);
const optionName = (0, _changeCase.camelCase)(optionParam.name);
const option = options[optionName];

@@ -193,28 +185,17 @@ const isRequired = Boolean(optionParam.required) || typeof optionParam.required === 'undefined' && typeof optionParam.default === 'undefined';

const uri = (0, _utils.getSauceEndpoint)('localhost:3000' + '', this._options.region, this._options.headless, 'http://') + url;
console.log(uri);
return new Promise((resolve, reject) => (0, _request.default)({
uri,
method: method.toUpperCase(),
[method === 'get' ? 'qs' : 'body']: body,
json: true,
auth: this._auth,
strictSSL: (0, _utils.getStrictSsl)(),
proxy: this.proxy,
useQuerystring: true
}, (err, response, body) => {
/* istanbul ignore if */
if (err) {
return reject(err);
}
/* istanbul ignore if */
const uri = (0, _utils.getSauceEndpoint)(host + basePath, this._options.region, this._options.headless) + url;
if (response.statusCode !== 200 && response.statusCode !== 204) {
const reason = (0, _utils.getErrorReason)(body);
return reject(new Error(`Failed calling ${propName}, status code: ${response.statusCode}, reason: ${reason}`));
}
return resolve(body);
}));
try {
const response = await _got.default[method](uri, {
[method === 'get' ? 'searchParams' : 'body']: body,
json: true,
auth: this._auth,
rejectUnauthorized: (0, _utils.getStrictSsl)(),
proxy: this.proxy
});
return response.body;
} catch (err) {
const reason = (0, _utils.getErrorReason)(err.body);
throw new Error(`Failed calling ${propName}, status code: ${err.statusCode}, reason: ${reason}`);
}
};

@@ -233,98 +214,30 @@ }

const host = (0, _utils.getSauceEndpoint)('saucelabs.com', this._options.region, this._options.headless, 'https://assets.');
return new Promise((resolve, reject) => {
const req = (0, _request.default)({
try {
const res = await _got.default.get(`${host}/jobs/${jobId}/${assetName}?ts=${Date.now()}&auth=${hmac}`, {
method: 'GET',
strictSSL: (0, _utils.getStrictSsl)(),
proxy: this.proxy,
uri: `${host}/jobs/${jobId}/${assetName}?ts=${Date.now()}&auth=${hmac}`
}, (err, res, body) => {
/**
* check if request was successful
*/
if (err) {
return reject(err);
}
/**
* check if we received the asset
*/
if (res.statusCode !== 200) {
const reason = (0, _utils.getErrorReason)(body);
return reject(new Error(`There was an error downloading asset ${assetName}, status code: ${res.statusCode}, reason: ${reason}`));
}
/**
* parse asset as json if proper content type is given
*/
if (res.headers['content-type'] === 'application/json') {
try {
body = JSON.parse(body);
} catch (e) {// do nothing
}
}
return resolve(body);
rejectUnauthorized: (0, _utils.getStrictSsl)(),
proxy: this.proxy
});
/**
* parse asset as json if proper content type is given
*/
if (res.headers['content-type'] === 'application/json' && typeof res.body === 'string') {
res.body = JSON.parse(res.body);
}
/**
* only pipe asset to file if path is given
*/
if (typeof downloadPath === 'string') {
const fd = _fs.default.createWriteStream(_path.default.resolve(process.cwd(), downloadPath));
/**
* unzip gzipped logs
* ToDo: this only affects tracing logs which are uploaded gzipped,
* there should be seperate api definition for extended debugging
*/
if (assetName.endsWith('.gz')) {
const gunzip = _zlib.default.createGunzip();
req.pipe(gunzip).pipe(fd);
} else {
req.pipe(fd);
}
_fs.default.writeFileSync(_path.default.resolve(process.cwd(), downloadPath), res.body);
}
});
}
async uploadJobAssets(jobId, filePaths) {
const base = 'http://localhost:3000'; // getSauceEndpoint('saucelabs.com', this._options.region, this._options.headless)
const uri = base + `/v1/job/${jobId}/upload`;
const form = new _formData.default();
for (const filePath of filePaths) {
const readStream = _fs.default.createReadStream(filePath.startsWith('/') ? filePath : _path.default.join(process.cwd(), filePath));
form.append('file[]', readStream);
return res.body;
} catch (err) {
const reason = (0, _utils.getErrorReason)(err.body);
throw new Error(`There was an error downloading asset ${assetName}, status code: ${err.statusCode}, reason: ${reason}`);
}
return new Promise((resolve, reject) => {
const req = (0, _request.default)({
uri,
auth: {
/**
* ToDo get real auth
*/
user: 'admin',
pass: 'foobar'
},
method: 'PUT',
headers: form.getHeaders()
}, (err, res, body) => {
/**
* check if request was successful
*/
if (err) {
return reject(err);
}
return resolve(body);
});
form.pipe(req);
});
}

@@ -331,0 +244,0 @@

@@ -20,2 +20,10 @@ "use strict";

/**
* Create HMAC token to receive job assets
*
* @param {string} username username of user
* @param {string} key access key of user
* @param {string} jobId job id of job you want to get access to
* @return {string} hmac token
*/
function createHMAC(username, key, jobId) {

@@ -78,3 +86,3 @@ const hmac = _crypto.default.createHmac('md5', `${username}:${key}`);

return `${_constants.TO_STRING_TAG} {
user: '${scope.username}',
username: '${scope.username}',
key: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXX${scope._accessKey.slice(-6)}',

@@ -81,0 +89,0 @@ region: '${scope._options.region}',

{
"name": "saucelabs",
"version": "3.1.1",
"version": "4.0.0",
"author": "Christian Bromann <christian@saucelabs.com>",

@@ -27,3 +27,3 @@ "description": "A wrapper around Sauce Labs REST API",

"generate:docs": "babel-node ./scripts/generate-docs",
"generate:typings": "",
"generate:typings": "babel-node ./scripts/generate-typings",
"prepublishOnly": "NODE_ENV=production run-s build generate:typings",

@@ -39,7 +39,6 @@ "release": "npm run release:patch",

"dependencies": {
"change-case": "^3.1.0",
"form-data": "^3.0.0",
"change-case": "^4.1.1",
"got": "^10.6.0",
"hash.js": "^1.1.7",
"request": "^2.88.0",
"yargs": "^13.2.2"
"yargs": "^15.3.1"
},

@@ -46,0 +45,0 @@ "devDependencies": {

@@ -7,3 +7,3 @@ <p align="center">

Wrapper around the Sauce Labs REST APIs for [Node.js](http://nodejs.org/) (v8 or higher).
Wrapper around all Sauce Labs REST APIs for [Node.js](http://nodejs.org/) (v8 or higher) and the browser.

@@ -40,2 +40,3 @@ ## Install

- `eu-central-1` (short `eu`)
- `us-east-1` (headless)

@@ -52,13 +53,12 @@ Type: `string`<br>

## Usage
### proxy
All accessible API commands with descriptions can be found [here](docs/interface.md). In order to route requests through a proxy set `HTTP_PROXY`, `HTTPS_PROXY` or `NO_PROXY` as environment variable. For more information on this, read [here](https://github.com/request/request#controlling-proxy-behaviour-using-environment-variables). Alternatively you can pass the proxy to be used during initialization:
If you want to tunnel your API request through a proxy please see the [got proxy docs](https://github.com/sindresorhus/got/blob/master/readme.md#proxies) for more information.
```js
import SauceLabs from 'saucelabs';
Type: `object`<br>
Default: `null`
...
## Usage
const myAccount = new SauceLabs({ proxy: 'http://localproxy.com' });
```
All accessible API commands with descriptions can be found [here](docs/interface.md).

@@ -65,0 +65,0 @@ ### As CLI Tool

Sorry, the diff of this file is not supported yet

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