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

@everymundo/promise-data-to

Package Overview
Dependencies
Maintainers
22
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everymundo/promise-data-to - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/get-data-from-xdata.js

30

lib/promise-data-to.js

@@ -8,2 +8,4 @@ 'use strict';

{ setResTxt } = require('../lib/set-response-text'),
{ getDataFromXData } = require('../lib/get-data-from-xdata'),
{ setHeaders } = require('../lib/set-headers'),
protocols = {'http:': require('http'), 'https:': require('https')},

@@ -26,2 +28,3 @@ SIMULATE = +process.env.SIMULATE,

maxRetry = MAX_RETRY_ATTEMPTS,
compress = false // eslint-disable-line comma-dangle
}, xData) => new Promise((resolve, reject) => {

@@ -31,3 +34,4 @@ if (!http) http = protocols[protocol];

const
data = typeof xData === 'string' ? xData : JSON.stringify(xData),
// data = typeof xData === 'string' ? xData : JSON.stringify(xData),
data = getDataFromXData(xData, compress),
start = new Date(),

@@ -48,7 +52,12 @@ post_options = {

if (!headers['Content-type']) headers['Content-type'] = 'application/json';
setHeaders(headers, data, compress);
// if (!headers['Content-type']) headers['Content-type'] = 'application/json';
if (data) headers['Content-Length'] = Buffer.byteLength(data);
// if (compress && ['deflate', 'gzip'].includes(compress)) {
// headers['Content-Encoding'] = compress;
// }
function post() {
// if (data) headers['Content-Length'] = Buffer.byteLength(data);
const post = () => {
// Set up the request

@@ -104,5 +113,11 @@ const post_req = http.request(post_options, (res) => {

.on('error', (err) => {
logr.error('ERROR!', err);
logr.error('http.request', err);
const stats = {
code: 599, start, end: Date.now(), err, attempt, endpoint,
code: 599,
start,
end: Date.now(),
err,
attempt,
endpoint,
headers,
};

@@ -115,3 +130,3 @@ tryAgain(err, stats);

post_req.end();
}
};

@@ -140,2 +155,3 @@ function tryAgain(error, stats) {

loadedAt: new Date(),
getDataFromXData,
};
{
"name": "@everymundo/promise-data-to",
"version": "1.0.0",
"version": "1.1.0",
"description": "This is a helper to perform POST requests using promises and no external dependencies",

@@ -12,4 +12,4 @@ "main": "index.js",

"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"check-lint": "eslint *.js lib/*.js test/*.js routes/*.js",
"fix-lint": "eslint --fix *.js lib/*.js test/*.js routes/*.js",
"check-lint": "eslint *.js lib/*.js test/*.js",
"fix-lint": "eslint --fix *.js lib/*.js test/*.js",
"test": "RETRY_TIMEOUT_MS= MAX_RETRY_ATTEMPTS= SIMULATE= mocha"

@@ -42,8 +42,8 @@ },

"@everymundo/cleanrequire": "^1.1.1",
"@everymundo/simple-clone": "^1.0.0",
"@everymundo/simple-clone": "^1.1.0",
"chai": "^4.1.2",
"ghooks": "^2.0.2",
"ghooks": "^2.0.4",
"istanbul": "^0.4.5",
"mocha": "^5.0.4",
"sinon": "^4.4.6"
"mocha": "^5.2.0",
"sinon": "^4.5.0"
},

@@ -50,0 +50,0 @@ "dependencies": {

@@ -47,6 +47,5 @@ 'require strict';

Object.keys(expected).forEach(key =>
expect(lib[key]).to.be.instanceof(expected[key]));
Object.keys(expected).forEach(key => expect(lib[key]).to.be.instanceof(expected[key]));
});
});
});

@@ -8,2 +8,3 @@ 'require strict';

const
sinon = require('sinon'),
{ sandbox, spy } = require('sinon'),

@@ -60,12 +61,47 @@ { expect } = require('chai'),

const
config = {
http,
host: 'localhost',
port: 80,
path: '/path',
endpoint: 'http://localhost:80/path',
headers: { Authorization: 'Authorization' },
};
const config = {
http,
host: 'localhost',
port: 80,
path: '/path',
endpoint: 'http://localhost:80/path',
headers: { Authorization: 'Authorization' },
};
context('Calling setHeaders', () => {
const libSetHeaders = cleanrequire('../lib/set-headers.js');
beforeEach(() => {
box.stub(libSetHeaders, 'setHeaders');
});
it('should call setHeaders passing the correct arguments', () => {
const { setHeaders } = libSetHeaders;
const data = { a: 1, b: 2, c: 3 };
const expectedData = require('zlib').gzipSync(JSON.stringify(data));
httpRequest.callsFake((options, callback) => {
httpResponse.statusCode = 200;
callback(httpResponse);
return httpEmitter;
});
const { promiseDataTo } = loadLib();
const customConfig = clone(config);
const { headers } = customConfig;
customConfig.http = http;
customConfig.compress = 'gzip';
return promiseDataTo(customConfig, data)
.then(() => {
expect(setHeaders).to.have.property('calledOnce', true);
// expect(libSetHeaders.setHeaders.calledWith(headers, expectedData, 'gzip')).to.be.true;
sinon.assert.calledWith(setHeaders, headers, expectedData, 'gzip');
// expect(.calledWith(headers, expectedData, 'gzip')).to.be.true;
});
});
});
it('should success when status is between 200 and 299 using http', () => {

@@ -72,0 +108,0 @@ const

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