New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rxws

Package Overview
Dependencies
Maintainers
7
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rxws - npm Package Compare versions

Comparing version 5.4.0 to 5.4.1

32

lib/HTTPBackend.js

@@ -11,11 +11,13 @@ 'use strict';

exports.default = function (options) {
var url = options.url,
forceFail = options.forceFail,
onError = options.onError,
log = options.log,
backendOptions = options.backendOptions;
var url = options.url;
var forceFail = options.forceFail;
var onError = options.onError;
var log = options.log;
var backendOptions = options.backendOptions;
var _ref = backendOptions ? backendOptions : {},
fetch = _ref.fetch;
var _ref = backendOptions ? backendOptions : {};
var fetch = _ref.fetch;
var messageCallback = void 0;

@@ -35,3 +37,3 @@

}).catch(function (err) {
return messageCallback(JSON.stringify(unknownError(err, parsedRequest)));
return messageCallback(unknownError(err, parsedRequest));
});

@@ -80,10 +82,12 @@ },

return {
header: _extends({}, headers, { statusCode: 400 }),
body: {
errors: {
message: err.message
}
/* Status code 412 means "precondition failed", which is sort of what happened
* when the fetch api itself throws an Error.
*/
err.header = _extends({}, headers, { statusCode: 412 });
err.body = {
errors: {
message: "Unable to perform http request -- fetch threw a client side error"
}
};
return err;
}

@@ -90,0 +94,0 @@

@@ -473,3 +473,3 @@ 'use strict';

it('should catch unknown errors as 400', function (run) {
it('should catch unknown errors as a 412', function (run) {
(0, _HTTPBackend2.default)({

@@ -508,3 +508,7 @@ backendOptions: {

api.onMessage(function (resp) {
expect(resp).toBe('{"header":{"correlationId":"1","statusCode":400},"body":{"errors":{"message":"other error"}}}');
expect(resp instanceof Error).toBe(true);
expect(resp.message).toBe("other error");
expect(resp.header.correlationId).toBe("1");
expect(resp.header.statusCode).toBe(412);
expect(resp.body.errors.message).toBe("Unable to perform http request -- fetch threw a client side error");
run();

@@ -515,3 +519,3 @@ });

it('should catch root unknown errors as 400', function (run) {
it('should catch root unknown errors as 412', function (run) {
(0, _HTTPBackend2.default)({

@@ -535,3 +539,7 @@ backendOptions: {

api.onMessage(function (resp) {
expect(resp).toBe('{"header":{"correlationId":"1","statusCode":400},"body":{"errors":{"message":"ahhh"}}}');
expect(resp instanceof Error).toBe(true);
expect(resp.message).toBe("ahhh");
expect(resp.header.correlationId).toBe("1");
expect(resp.header.statusCode).toBe(412);
expect(resp.body.errors.message).toBe("Unable to perform http request -- fetch threw a client side error");
run();

@@ -538,0 +546,0 @@ });

@@ -78,3 +78,3 @@ 'use strict';

var response = JSON.parse(message);
var response = typeof message === 'string' ? JSON.parse(message) : message;
if (!request) {

@@ -136,3 +136,5 @@ request = response && response.header && requestMap[response.header.correlationId] ? requestMap[response.header.correlationId].request : null;

if (response.header.statusCode !== 200) {
if (response instanceof Error) {
observer.onError(response);
} else if (response.header.statusCode !== 200) {
observer.onError({

@@ -142,3 +144,2 @@ err: response.body,

});
observer.onCompleted(response.body);
} else {

@@ -196,3 +197,3 @@ observer.onNext(response.body);

function prepareRequest(observer, request) {
var tries = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var tries = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];

@@ -229,3 +230,3 @@

function setBackend() {
var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];

@@ -309,4 +310,4 @@ if (useMiddlewareQueue.length > 1) {

requestUse().subscribe(function (_ref) {
var req = _ref.req,
reply = _ref.reply;
var req = _ref.req;
var reply = _ref.reply;

@@ -313,0 +314,0 @@ var replyObj = { header: _extends({}, req.headers, { statusCode: 200 }) };

'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

@@ -42,6 +42,6 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

response: function response(_ref) {
var req = _ref.req,
send = _ref.send,
reply = _ref.reply,
next = _ref.next;
var req = _ref.req;
var send = _ref.send;
var reply = _ref.reply;
var next = _ref.next;

@@ -262,4 +262,4 @@ reply({

}, function (_ref2) {
var req = _ref2.req,
err = _ref2.err;
var req = _ref2.req;
var err = _ref2.err;

@@ -287,2 +287,33 @@ expect(err.__header.statusCode).toBe(404);

it('should pass Error objects through, as long as there are header and body properties on the Error', function () {
var backend = (0, _testUtils.makeMockBackend)();
(0, _request.setBackend)({ backend: backend, url: 'someUrl' });
(0, _rxws2.default)({
method: 'get',
resource: 'users'
}).subscribe(function (response) {
expect('This should not be called').toBe('But it was');
}, function (err) {
expect(err instanceof Error).toBe(true);
expect(err.message).toBe("Something went wrong");
expect(err.header.statusCode).toBe(412);
expect(_typeof(err.header.correlationId)).toBe('string');
});
var request = JSON.parse(backend.write.calls.argsFor(0));
var mockedMessage = new Error("Something went wrong");
mockedMessage.header = {
"correlationId": request.header.correlationId,
"statusCode": 412
};
mockedMessage.body = {
"users": [{
name: 'Ibn Al Haytham'
}]
};
backend.mockServerMessage(mockedMessage);
});
it('should make mocking a single return value easy for a given end point using key and value for body', function () {

@@ -391,5 +422,5 @@ var returnValue = [{ 'user1': 'hi' }];

response: function response(_ref3) {
var res = _ref3.res,
reply = _ref3.reply,
retry = _ref3.retry;
var res = _ref3.res;
var reply = _ref3.reply;
var retry = _ref3.retry;

@@ -431,6 +462,6 @@ reply(res);

response1: function response1(_ref4) {
var res = _ref4.res,
reply = _ref4.reply,
retry = _ref4.retry,
next = _ref4.next;
var res = _ref4.res;
var reply = _ref4.reply;
var retry = _ref4.retry;
var next = _ref4.next;

@@ -440,6 +471,6 @@ next();

response2: function response2(_ref5) {
var res = _ref5.res,
reply = _ref5.reply,
retry = _ref5.retry,
next = _ref5.next;
var res = _ref5.res;
var reply = _ref5.reply;
var retry = _ref5.retry;
var next = _ref5.next;

@@ -449,6 +480,6 @@ next();

response3: function response3(_ref6) {
var res = _ref6.res,
reply = _ref6.reply,
retry = _ref6.retry,
next = _ref6.next;
var res = _ref6.res;
var reply = _ref6.reply;
var retry = _ref6.retry;
var next = _ref6.next;

@@ -458,5 +489,5 @@ next();

response4: function response4(_ref7) {
var res = _ref7.res,
reply = _ref7.reply,
retry = _ref7.retry;
var res = _ref7.res;
var reply = _ref7.reply;
var retry = _ref7.retry;

@@ -507,6 +538,6 @@ reply(res);

response1: function response1(_ref8) {
var res = _ref8.res,
reply = _ref8.reply,
retry = _ref8.retry,
next = _ref8.next;
var res = _ref8.res;
var reply = _ref8.reply;
var retry = _ref8.retry;
var next = _ref8.next;

@@ -516,6 +547,6 @@ next();

response2: function response2(_ref9) {
var res = _ref9.res,
reply = _ref9.reply,
retry = _ref9.retry,
next = _ref9.next;
var res = _ref9.res;
var reply = _ref9.reply;
var retry = _ref9.retry;
var next = _ref9.next;

@@ -525,6 +556,6 @@ reply(res);

response3: function response3(_ref10) {
var res = _ref10.res,
reply = _ref10.reply,
retry = _ref10.retry,
next = _ref10.next;
var res = _ref10.res;
var reply = _ref10.reply;
var retry = _ref10.retry;
var next = _ref10.next;

@@ -534,5 +565,5 @@ next();

response4: function response4(_ref11) {
var res = _ref11.res,
reply = _ref11.reply,
retry = _ref11.retry;
var res = _ref11.res;
var reply = _ref11.reply;
var retry = _ref11.retry;

@@ -583,5 +614,5 @@ reply(res);

response: function response(_ref12) {
var res = _ref12.res,
reply = _ref12.reply,
retry = _ref12.retry;
var res = _ref12.res;
var reply = _ref12.reply;
var retry = _ref12.retry;

@@ -588,0 +619,0 @@ retry();

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

exports.default = function (options) {
var url = options.url,
forceFail = options.forceFail,
onSuccess = options.onSuccess,
onError = options.onError,
log = options.log,
backendOptions = options.backendOptions;
var url = options.url;
var forceFail = options.forceFail;
var onSuccess = options.onSuccess;
var onError = options.onError;
var log = options.log;
var backendOptions = options.backendOptions;

@@ -16,0 +16,0 @@

@@ -10,3 +10,3 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

@@ -54,3 +54,3 @@ exports.log = log;

function log() {
var level = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
var level = arguments.length <= 0 || arguments[0] === undefined ? 5 : arguments[0];
var message = arguments[1];

@@ -121,4 +121,4 @@

onNext: function onNext(_ref) {
var req = _ref.req,
send = _ref.send;
var req = _ref.req;
var send = _ref.send;

@@ -133,4 +133,4 @@ send(req);

onNext: function onNext(_ref2) {
var res = _ref2.res,
reply = _ref2.reply;
var res = _ref2.res;
var reply = _ref2.reply;

@@ -137,0 +137,0 @@ reply(res);

@@ -71,2 +71,3 @@ 'use strict';

// doesn't throw
// falsy, but valid
makeRequest();

@@ -73,0 +74,0 @@ });

{
"name": "rxws",
"version": "5.4.0",
"version": "5.4.1",
"description": "A RESTful reactive JavaScript implmentation on top of web sockets",

@@ -5,0 +5,0 @@ "main": "lib/rxws.js",

@@ -19,3 +19,3 @@ import { Observable } from 'rx';

.then(resp => setTimeout(() => messageCallback(JSON.stringify(resp))))
.catch(err => messageCallback(JSON.stringify(unknownError(err, parsedRequest))));
.catch(err => messageCallback(unknownError(err, parsedRequest)));
},

@@ -66,10 +66,12 @@

return {
header: { ...headers, statusCode: 400 },
body: {
errors: {
message: err.message
}
/* Status code 412 means "precondition failed", which is sort of what happened
* when the fetch api itself throws an Error.
*/
err.header = {...headers, statusCode: 412};
err.body = {
errors: {
message: "Unable to perform http request -- fetch threw a client side error"
}
}
return err;
}

@@ -76,0 +78,0 @@

@@ -464,3 +464,3 @@ import backend from './HTTPBackend';

it('should catch unknown errors as 400', function(run) {
it('should catch unknown errors as a 412', function(run) {
backend({

@@ -491,3 +491,7 @@ backendOptions: {

api.onMessage(function(resp) {
expect(resp).toBe('{"header":{"correlationId":"1","statusCode":400},"body":{"errors":{"message":"other error"}}}');
expect(resp instanceof Error).toBe(true);
expect(resp.message).toBe("other error");
expect(resp.header.correlationId).toBe("1");
expect(resp.header.statusCode).toBe(412);
expect(resp.body.errors.message).toBe("Unable to perform http request -- fetch threw a client side error");
run();

@@ -498,3 +502,3 @@ });

it('should catch root unknown errors as 400', function(run) {
it('should catch root unknown errors as 412', function(run) {
backend({

@@ -516,3 +520,7 @@ backendOptions: {

api.onMessage(function(resp) {
expect(resp).toBe('{"header":{"correlationId":"1","statusCode":400},"body":{"errors":{"message":"ahhh"}}}');
expect(resp instanceof Error).toBe(true);
expect(resp.message).toBe("ahhh");
expect(resp.header.correlationId).toBe("1");
expect(resp.header.statusCode).toBe(412);
expect(resp.body.errors.message).toBe("Unable to perform http request -- fetch threw a client side error");
run();

@@ -519,0 +527,0 @@ });

@@ -66,3 +66,3 @@ import { Observable } from 'rx';

let response = JSON.parse(message);
let response = typeof message === 'string' ? JSON.parse(message) : message;
if (!request) {

@@ -124,3 +124,5 @@ request = response && response.header && requestMap[response.header.correlationId] ? requestMap[response.header.correlationId].request : null;

if (response.header.statusCode !== 200) {
if (response instanceof Error) {
observer.onError(response);
} else if (response.header.statusCode !== 200) {
observer.onError({

@@ -130,3 +132,2 @@ err: response.body,

});
observer.onCompleted(response.body);
} else {

@@ -133,0 +134,0 @@ observer.onNext(response.body);

@@ -271,2 +271,38 @@ import makeRequest, { setBackend, reset, startMockingRequests, stopMockingRequests, mockReturn } from './request';

it('should pass Error objects through, as long as there are header and body properties on the Error', () => {
let backend = makeMockBackend();
setBackend({backend: backend, url: 'someUrl'});
rxws({
method: 'get',
resource: 'users'
}).subscribe(
response => {
expect('This should not be called').toBe('But it was');
},
err => {
expect(err instanceof Error).toBe(true);
expect(err.message).toBe("Something went wrong");
expect(err.header.statusCode).toBe(412);
expect(typeof err.header.correlationId).toBe('string');
}
);
let request = JSON.parse(backend.write.calls.argsFor(0));
const mockedMessage = new Error("Something went wrong");
mockedMessage.header = {
"correlationId": request.header.correlationId,
"statusCode": 412
};
mockedMessage.body = {
"users": [
{
name: 'Ibn Al Haytham'
}
]
};
backend.mockServerMessage(mockedMessage);
})
it('should make mocking a single return value easy for a given end point using key and value for body', () => {

@@ -273,0 +309,0 @@ const returnValue = [{'user1': 'hi'}];

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