@tailored-apps/api-connector
Advanced tools
Comparing version 1.1.0 to 1.2.0
# Changelog | ||
## 2018-04-04 | ||
* `[SEMVER_MINOR]` added `formData` property to request specs. Set to `true` if you want request payload to be sent as `form-data` rather than `application/json` | ||
* `[SEMVER_MINOR]` added `bodyProp` option to request spec. This allows you to specify the property name used for sending the request body (defaults to `body`, can be set to any other value that the `request` library supports, e.g. `form` or `formData`) | ||
## 2017-11-29 | ||
* Initial release as a standalone module |
@@ -38,3 +38,3 @@ const deepmerge = require('deepmerge') | ||
function getRequestSpec (baseUrl, endpoint, params) { | ||
const { route, method, doReplace, getPath, getQuery, getBody, formData = false, json = true } = endpoint // default to json = true for all endpoints | ||
const { route, method, doReplace, getPath, getQuery, getBody, bodyProp = 'body', json = true } = endpoint // default to json = true for all endpoints | ||
@@ -48,3 +48,2 @@ const canHaveBody = method === METHOD_PATCH || method === METHOD_POST || method === METHOD_PUT | ||
const body = canHaveBody ? (getBody ? getBody(params) : params) : undefined | ||
const form = canHaveBody && formData ? body : undefined | ||
@@ -56,5 +55,4 @@ return Object.assign({ }, endpoint, { | ||
qs, | ||
form, | ||
body: body && !formData ? body : undefined, | ||
json: formData ? false : json | ||
json, | ||
[bodyProp]: body | ||
}) | ||
@@ -61,0 +59,0 @@ } |
{ | ||
"name": "@tailored-apps/api-connector", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A small library providing various utility functions used in tailored apps backends (propably not very useful for anyone else)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -72,9 +72,8 @@ /* eslint-env mocha */ | ||
it('uses "form" property instead of body if specified', function () { | ||
it('allows a custom body property name to be specified', function () { | ||
const params = { a: 'b', c: 'd' } | ||
const spec = getSpec({ route: '/form', method: METHOD_POST, formData: true }, params) | ||
const spec = getSpec({ route: '/form', method: METHOD_POST, bodyProp: 'formData' }, params) | ||
expect(spec.body).to.equal(undefined) | ||
expect(spec.json).to.equal(false) | ||
expect(spec.form).to.deep.equal(params) | ||
expect(spec.formData).to.deep.equal(params) | ||
}) | ||
@@ -81,0 +80,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
69596
209