Comparing version 0.5.37 to 0.5.38
@@ -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 |
{ | ||
"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 @@ |
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
75450
1390
554
9