Socket
Socket
Sign inDemoInstall

mappersmith

Package Overview
Dependencies
Maintainers
1
Versions
120
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 2.29.3 to 2.30.0

4

manifest.js

@@ -44,2 +44,3 @@ "use strict";

this.timeoutAttr = obj.timeoutAttr;
this.hostAttr = obj.hostAttr;
this.clientId = obj.clientId || null;

@@ -88,3 +89,4 @@ this.gatewayConfigs = (0, _utils.assign)({}, gatewayConfigs, obj.gatewayConfigs);

authAttr: this.authAttr,
timeoutAttr: this.timeoutAttr
timeoutAttr: this.timeoutAttr,
hostAttr: this.hostAttr
}, definition));

@@ -91,0 +93,0 @@ },

@@ -16,3 +16,3 @@ "use strict";

/* global VERSION */
var version = "2.29.3";
var version = "2.30.0";
exports.version = version;

@@ -19,0 +19,0 @@ var configs = {

@@ -21,2 +21,3 @@ "use strict";

* @param {Number} obj.timeoutAttr - timeout attribute name. Default: 'timeout'
* @param {String} obj.hostAttr - host attribute name. Default: 'host'
*/

@@ -35,4 +36,5 @@ function MethodDescriptor(obj) {

this.timeoutAttr = obj.timeoutAttr || 'timeout';
this.hostAttr = obj.hostAttr || 'host';
var resourceMiddleware = obj.middleware || obj.middlewares || [];
this.middleware = resourceMiddleware;
}

@@ -7,3 +7,14 @@ "use strict";

exports.default = exports.CONTENT_TYPE_JSON = void 0;
var CONTENT_TYPE_JSON = 'application/json;charset=utf-8';
var mediaType = 'application/json';
var charset = 'charset=utf-8';
var CONTENT_TYPE_JSON = "".concat(mediaType, ";").concat(charset);
exports.CONTENT_TYPE_JSON = CONTENT_TYPE_JSON;
var isJson = function isJson(contentType) {
return contentType === mediaType || contentType.startsWith("".concat(mediaType, ";"));
};
var alreadyEncoded = function alreadyEncoded(body) {
return typeof body === 'string';
};
/**

@@ -18,3 +29,2 @@ * Automatically encode your objects into JSON

exports.CONTENT_TYPE_JSON = CONTENT_TYPE_JSON;

@@ -26,8 +36,13 @@ var EncodeJsonMiddleware = function EncodeJsonMiddleware() {

try {
if (request.body()) {
var body = request.body();
var contentType = request.header('content-type');
if (body) {
var shouldEncodeBody = contentType == null || isJson(contentType) && !alreadyEncoded(body);
var encodedBody = shouldEncodeBody ? JSON.stringify(body) : body;
return request.enhance({
headers: {
'content-type': CONTENT_TYPE_JSON
'content-type': contentType == null ? CONTENT_TYPE_JSON : contentType
},
body: JSON.stringify(request.body())
body: encodedBody
});

@@ -34,0 +49,0 @@ }

{
"name": "mappersmith",
"version": "2.29.3",
"version": "2.30.0",
"description": "It is a lightweight rest client for node.js and the browser",

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

@@ -310,2 +310,26 @@ [![npm version](https://badge.fury.io/js/mappersmith.svg)](http://badge.fury.io/js/mappersmith)

In case you need to overwrite the host for a specific call, you can do so through the param `host`:
```javascript
// ...
{
all: { path: '/users', host: 'http://old-api.com' }
}
// ...
client.User.all({ host: 'http://very-old-api.com' }) // http://very-old-api.com/users
```
If `host` is not possible as a special parameter for your API, you can configure it through the param `hostAttr`:
```javascript
// ...
{
all: { path: '/users', hostAttr: 'baseUrl' }
}
// ...
client.User.all({ baseUrl: 'http://very-old-api.com' }) // http://very-old-api.com/users
```
### <a name="binary-data"></a> Binary data

@@ -312,0 +336,0 @@

@@ -33,3 +33,3 @@ "use strict";

var isParam = function isParam(key) {
return key !== _this.methodDescriptor.headersAttr && key !== _this.methodDescriptor.bodyAttr && key !== _this.methodDescriptor.authAttr && key !== _this.methodDescriptor.timeoutAttr;
return key !== _this.methodDescriptor.headersAttr && key !== _this.methodDescriptor.bodyAttr && key !== _this.methodDescriptor.authAttr && key !== _this.methodDescriptor.timeoutAttr && key !== _this.methodDescriptor.hostAttr;
};

@@ -62,3 +62,4 @@

host: function host() {
return (this.methodDescriptor.host || '').replace(REGEXP_TRAILING_SLASH, '');
var originalHost = this.requestParams[this.methodDescriptor.hostAttr] || this.methodDescriptor.host || '';
return originalHost.replace(REGEXP_TRAILING_SLASH, '');
},

@@ -165,2 +166,3 @@

* @param {Number} extras.timeout - it will replace the current timeout
* @param {String} extras.host - it will replace the current timeout
*/

@@ -172,2 +174,3 @@ enhance: function enhance(extras) {

var timeoutKey = this.methodDescriptor.timeoutAttr;
var hostKey = this.methodDescriptor.hostAttr;
var requestParams = (0, _utils.assign)({}, this.requestParams, extras.params);

@@ -178,2 +181,3 @@ requestParams[headerKey] = (0, _utils.assign)({}, this.requestParams[headerKey], extras.headers);

extras.timeout && (requestParams[timeoutKey] = extras.timeout);
extras.host && (requestParams[hostKey] = extras.host);
return new Request(this.methodDescriptor, requestParams);

@@ -180,0 +184,0 @@ },

@@ -36,2 +36,3 @@ /// <reference path="./middleware/basic-auth.d.ts" />

readonly timeout: number
readonly host: string
}

@@ -110,2 +111,3 @@

readonly host?: string
readonly ignoreGlobalMiddleware?: boolean
readonly middleware?: Middleware[]

@@ -112,0 +114,0 @@ // @alias middleware

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc