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

mappersmith

Package Overview
Dependencies
Maintainers
3
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mappersmith - npm Package Compare versions

Comparing version 0.13.2 to 0.13.3

7

CHANGELOG.md
# Changelog
# 0.13.2
## 0.13.3
- Included beforeSend callback, this should be configured through Global configurations and URL matching. It will follow the same behavior as the processor callback
- bugfix: some body parsers are super strict and will fail if charset has a “;” termination. PR #26 introduced this bug trying to solve issue #27
## 0.13.2
- bugfix: prioritizes user-defined content-type header even for post/put/patch/delete methods. `application/x-www-form-urlencoded` is not forced if Content-Type header is defined.

@@ -6,0 +11,0 @@

2

package.json
{
"name": "mappersmith",
"version": "0.13.2",
"version": "0.13.3",
"description": "It is a lightweight, isomorphic, dependency-free, rest client mapper for javascript",

@@ -5,0 +5,0 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>",

@@ -26,2 +26,3 @@ var Env = require('./env');

this.processor = args.processor;
this.beforeSend = args.beforeSend;
this.opts = args.opts || {};

@@ -42,2 +43,3 @@

this.timeStart = Utils.performanceNow();
if (this.beforeSend) this.beforeSend(this);

@@ -44,0 +46,0 @@ if (Env.USE_FIXTURES && Env.Fixture) {

@@ -30,3 +30,3 @@ var Utils = require('../utils');

opts.headers = Utils.extend({}, {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
'Content-Length': body.length

@@ -33,0 +33,0 @@ }, opts.headers);

@@ -127,3 +127,3 @@ var Utils = require('../utils');

if (!contentType) contentType = 'application/x-www-form-urlencoded; charset=UTF-8;';
if (!contentType) contentType = 'application/x-www-form-urlencoded;charset=utf-8';
request.setRequestHeader('Content-Type', contentType);

@@ -130,0 +130,0 @@ },

@@ -152,2 +152,3 @@ var Utils = require('./utils');

processor: descriptor.processor || rules.processor,
beforeSend: descriptor.beforeSend || rules.beforeSend,
opts: opts

@@ -154,0 +155,0 @@ });

@@ -109,8 +109,9 @@ var Mappersmith = require('../index');

describe('#call', function() {
var gateway, performanceNowValue;
var gateway, performanceNowValue, beforeSendSpy;
beforeEach(function() {
performanceNowValue = 88;
beforeSendSpy = sinon.spy(function() {});
sinon.stub(Utils, 'performanceNow').returns(performanceNowValue);
gateway = new Gateway({url: url, method: verb}).call();
gateway = new Gateway({url: url, method: verb, beforeSend: beforeSendSpy}).call();
});

@@ -126,2 +127,7 @@

it('calls "beforeSend" callback before action with gateway', function() {
expect(beforeSendSpy).calledBefore(methodStub);
expect(beforeSendSpy).to.have.been.deep.calledWith(gateway);
});
it('calls the configured method with the url', function() {

@@ -128,0 +134,0 @@ expect(methodStub).to.have.been.called;

@@ -196,3 +196,4 @@ var $ = require('jquery');

gateway: newGateway({body: body}),
assertBodyData: bodyData
assertBodyData: bodyData,
assertHeader: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'}
}, done);

@@ -199,0 +200,0 @@ });

@@ -28,3 +28,6 @@ var shared = require('shared-examples-for');

Photo: {
byCategory: {path: '/v1/photos/{category}/all.json'},
byCategory: {
path: '/v1/photos/{category}/all.json',
beforeSend: function(gateway) {}
},
add: {method: 'post', path: '/v1/photos/create.json'},

@@ -313,3 +316,4 @@ byId: {

opts: opts.gateway,
processor: opts.processor
processor: opts.processor,
beforeSend: opts.beforeSend,
});

@@ -321,3 +325,7 @@ });

beforeEach(function() {
opts = {gateway: {global: true}, processor: Utils.noop};
opts = {
gateway: {global: true},
processor: Utils.noop,
beforeSend: Utils.noop
};
manifest.rules = [{values: opts}];

@@ -332,3 +340,7 @@ mapper = new Mapper(manifest, gateway);

beforeEach(function() {
opts = {gateway: {matchUrl: true}, processor: Utils.noop};
opts = {
gateway: {matchUrl: true},
processor: Utils.noop,
beforeSend: Utils.noop
};
manifest.rules = [{match: /\/v1\/books/, values: opts}];

@@ -363,3 +375,4 @@ mapper = new Mapper(manifest, gateway);

opts: {matchUrl: true},
processor: opts.processor
processor: opts.processor,
beforeSend: opts.beforeSend
});

@@ -397,7 +410,9 @@ });

gateway: {global: true, headers: {a: 1}},
processor: function globalMatch() {}
processor: function globalMatch() {},
beforeSend: function beforeSendGlobalMatch() {}
};
optsMatch = {
gateway: {matchUrl: true, headers: {b: 2}},
processor: function urlMatch() {}
processor: function urlMatch() {},
beforeSend: function beforeSendUrlMatch() {}
};

@@ -427,3 +442,4 @@

opts: {global: true, headers: {a: 1, b: 2}, matchUrl: true},
processor: optsMatch.processor
processor: optsMatch.processor,
beforeSend: optsMatch.beforeSend
});

@@ -451,3 +467,4 @@ });

opts: {global: true, headers: expectedHeaders, matchUrl: true},
processor: optsMatch.processor
processor: optsMatch.processor,
beforeSend: optsMatch.beforeSend
});

@@ -690,3 +707,2 @@ });

describe('with params in the path, query string and an alternative empty host', function() {

@@ -838,3 +854,3 @@ it('calls the gateway with the configured values', function() {

describe('processors', function() {
it('should be passed to gateway', function() {
it('it\'s passed to gateway', function() {
var path = manifest.resources.Photo.byId.path;

@@ -858,2 +874,23 @@ var processor = manifest.resources.Photo.byId.processor;

});
describe('beforeSend', function() {
it('it\'s passed to gateway', function() {
var path = manifest.resources.Photo.byCategory.path;
var beforeSend = manifest.resources.Photo.byCategory.beforeSend;
var params = {category: 'unicorns'};
var resolvedPath = mapper.resolvePath(path, params);
var url = mapper.resolveHost() + resolvedPath;
result.Photo.byCategory(params, callback);
expect(gateway).to.have.been.calledWith({
url: url,
host: mapper.resolveHost(),
path: resolvedPath,
params: params,
method: method,
beforeSend: beforeSend
});
expect(gateway.prototype.success).to.have.been.calledWith(callback);
});
});
});

@@ -860,0 +897,0 @@ });

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