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

fetchr

Package Overview
Dependencies
Maintainers
5
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetchr - npm Package Compare versions

Comparing version 0.5.37 to 0.5.38

17

libs/fetcher.js

@@ -83,2 +83,4 @@ /**

* statusCode, err, and time (elapsed time)
* @param {Function} [options.paramsProcessor] The function will be invoked with 3 arguments:
* the req object, the serviceInfo object, and the params object. It is expected to return the processed params object.
* @constructor

@@ -101,2 +103,3 @@ */

this._statsCollector = options.statsCollector;
this._paramsProcessor = options.paramsProcessor;
}

@@ -112,3 +115,5 @@

Request.prototype.params = function (params) {
this._params = params;
this._params = (typeof this._paramsProcessor === 'function')
? this._paramsProcessor(this.req, {operation: this.operation, resource: this.resource}, params)
: params;
return this;

@@ -249,2 +254,4 @@ };

* statusCode, err, and time (elapsed time)
* @param {Function} [options.paramsProcessor] The function will be invoked with 3 arguments:
* the req object, the serviceInfo object, and the params object. It is expected to return the processed params object.
* @constructor

@@ -346,2 +353,4 @@ */

statusCode, err, and time (elapsed time)
* @param {Function} [options.paramsProcessor] The function will be invoked with 3 arguments:
* the req object, the serviceInfo object, and the params object. It is expected to return the processed params object.
* @returns {Function} middleware

@@ -377,3 +386,4 @@ * @param {Object} req

serviceMeta: serviceMeta,
statsCollector: options.statsCollector
statsCollector: options.statsCollector,
paramsProcessor: options.paramsProcessor
});

@@ -442,3 +452,4 @@ request

serviceMeta: serviceMeta,
statsCollector: options.statsCollector
statsCollector: options.statsCollector,
paramsProcessor: options.paramsProcessor
});

@@ -445,0 +456,0 @@ request

12

package.json
{
"name": "fetchr",
"version": "0.5.37",
"version": "0.5.38",
"description": "Fetchr augments Flux applications by allowing Flux stores to be used on server and client to fetch data",

@@ -8,5 +8,5 @@ "main": "index.js",

"scripts": {
"cover": "istanbul cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --reporter spec --timeout 20000",
"cover": "istanbul cover --dir artifacts -- ./node_modules/mocha/bin/_mocha tests/unit/ --recursive --reporter spec --timeout 20000 --exit",
"lint": "jshint libs tests",
"test": "NODE_ENV=test mocha tests/unit/ --recursive --reporter spec --timeout 20000"
"test": "NODE_ENV=test mocha tests/unit/ --recursive --reporter spec --timeout 20000 --exit"
},

@@ -34,8 +34,8 @@ "repository": {

"body-parser": "^1.17.0",
"chai": "^3.0.0",
"coveralls": "^2.11.1",
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"express": "^4.15.0",
"istanbul": "^0.4.5",
"jshint": "^2.5.1",
"mocha": "^3.0.2",
"mocha": "^5.2.0",
"mockery": "^2.0.0",

@@ -42,0 +42,0 @@ "pre-commit": "^1.0.0",

@@ -300,2 +300,23 @@ # Fetchr

## XHR Params Processing
For some applications, there may be a situation where you need to process the service params passed in XHR request before params are sent to the actual service. Typically, you would process these params in the service itself. However, if you want to perform processing across many services (i.e. sanitization for security), then you can use the `paramsProcessor` option.
`paramsProcessor` is a function that is passed into the `Fetcher.middleware` method. It is passed three arguments, the request object, the serviceInfo object, and the service params object. The `paramsProcessor` function can then modify the service params if needed.
Here is an example:
```js
/**
Using the app.js from above, you can modify the Fetcher.middleware
method to pass in the paramsProcessor function.
*/
app.use('/myCustomAPIEndpoint', Fetcher.middleware({
paramsProcessor: function (req, serviceInfo, params) {
console.log(serviceInfo.resource, serviceInfo.operation);
return Object.assign({foo: 'fillDefaultValueForFoo'}, params);
}
}));
```
## XHR Response Formatting

@@ -302,0 +323,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