Comparing version 0.5.40 to 0.5.41
@@ -263,2 +263,4 @@ /** | ||
Fetcher._deprecatedServicesDefinitions = []; | ||
/** | ||
@@ -286,8 +288,21 @@ * DEPRECATED | ||
*/ | ||
Fetcher.registerService = function (fetcher) { | ||
if (!fetcher || !fetcher.name) { | ||
throw new Error('Service is not defined correctly'); | ||
Fetcher.registerService = function (service) { | ||
if (!service) { | ||
throw new Error( | ||
'Fetcher.registerService requires a service definition (ex. registerService(service)).' | ||
); | ||
} | ||
Fetcher.services[fetcher.name] = fetcher; | ||
debug('fetcher ' + fetcher.name + ' added'); | ||
var resource; | ||
if (typeof service.resource !== 'undefined') { | ||
resource = service.resource; | ||
} else if (typeof service.name !== 'undefined') { | ||
resource = service.name; | ||
Fetcher._deprecatedServicesDefinitions.push(resource); | ||
} else { | ||
throw new Error('"resource" property is missing in service definition.'); | ||
} | ||
Fetcher.services[resource] = service; | ||
debug('fetcher ' + resource + ' added'); | ||
return; | ||
@@ -299,6 +314,4 @@ }; | ||
* Retrieve a data fetcher by name | ||
* @method getFetcher | ||
* @memberof Fetcher | ||
* @param {String} name of fetcher | ||
* @returns {Function} fetcher | ||
* @method getFetcheresourceof Fetcher | ||
* @param {String} name oresource @returns {Function} fetcher | ||
*/ | ||
@@ -364,5 +377,19 @@ Fetcher.getFetcher = function (name) { | ||
}; | ||
if (Fetcher._deprecatedServicesDefinitions.length && 'production' !== process.env.NODE_ENV) { | ||
var deprecatedServices = Fetcher._deprecatedServicesDefinitions.sort().join(', '); | ||
console.warn( | ||
'You have registered services using a deprecated property. ' + | ||
'Please, replace the property "name" by "resource" in the ' + | ||
'following services definitions:\n' + | ||
deprecatedServices + '.' | ||
); | ||
} | ||
return function (req, res, next) { | ||
var request; | ||
var error; | ||
var errorMsg; | ||
var resourceName; | ||
var serviceMeta; | ||
@@ -374,5 +401,13 @@ | ||
if (!resource) { | ||
error = fumble.http.badRequest('No resource specified', { debug: 'Bad resource' }); | ||
error.source = 'fetchr'; | ||
return next(error); | ||
} | ||
if (!Fetcher.isRegistered(resource)) { | ||
error = fumble.http.badRequest('Invalid Fetchr Access', { | ||
debug: 'Bad resource ' + sanitizeResourceName(resource) | ||
resourceName = sanitizeResourceName(resource); | ||
errorMsg = 'Resource "' + resourceName + '" is not registered'; | ||
error = fumble.http.badRequest(errorMsg, { | ||
debug: 'Bad resource ' + resourceName | ||
}); | ||
@@ -422,3 +457,3 @@ error.source = 'fetchr'; | ||
if (!requests || Object.keys(requests).length === 0) { | ||
error = fumble.http.badRequest('Invalid Fetchr Access', { | ||
error = fumble.http.badRequest('No resource specified', { | ||
debug: 'No resources' | ||
@@ -432,6 +467,8 @@ }); | ||
var singleRequest = requests[DEFAULT_GUID]; | ||
resourceName = sanitizeResourceName(singleRequest.resource); | ||
if (!Fetcher.isRegistered(singleRequest.resource)) { | ||
error = fumble.http.badRequest('Invalid Fetchr Access', { | ||
debug: 'Bad resource ' + sanitizeResourceName(singleRequest.resource) | ||
errorMsg = 'Resource "' + resourceName + '" is not registered'; | ||
error = fumble.http.badRequest(errorMsg, { | ||
debug: 'Bad resource ' + resourceName | ||
}); | ||
@@ -443,5 +480,6 @@ error.source = 'fetchr'; | ||
if(operation !== OP_CREATE && operation !== OP_UPDATE && operation !== OP_DELETE && operation !== OP_READ) { | ||
error = fumble.http.badRequest('Invalid Fetchr Access', { | ||
debug: 'Unsupported operation : operation must be create or read or update or delete' | ||
}); | ||
error = fumble.http.badRequest( | ||
'Unsupported "' + resourceName + '.' + operation + '" operation', | ||
{ debug: 'Only "create", "read", "update" or "delete" operations are allowed' } | ||
); | ||
error.source = 'fetchr'; | ||
@@ -448,0 +486,0 @@ return next(error); |
{ | ||
"name": "fetchr", | ||
"version": "0.5.40", | ||
"version": "0.5.41", | ||
"description": "Fetchr augments Flux applications by allowing Flux stores to be used on server and client to fetch data", | ||
@@ -45,3 +45,3 @@ "main": "index.js", | ||
"sinon": "^9.0.2", | ||
"supertest": "^5.0.0" | ||
"supertest": "^6.0.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "jshintConfig": { |
@@ -56,5 +56,8 @@ # Fetchr | ||
You will need to register any data services that you wish to use in your application. | ||
The interface for your service will be an object that must define a `name` property and at least one [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operation. | ||
The `name` propety will be used when you call one of the CRUD operations. | ||
You will need to register any data services that you wish to use in | ||
your application. The interface for your service will be an object | ||
that must define a `resource` property and at least one | ||
[CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) | ||
operation. The `resource` property will be used when you call one of the | ||
CRUD operations. | ||
@@ -71,4 +74,4 @@ ```js | ||
module.exports = { | ||
// name is required | ||
name: 'data_service', | ||
// resource is required | ||
resource: 'data_service', | ||
// at least one of the CRUD methods is required | ||
@@ -166,3 +169,3 @@ read: function(req, resource, params, config, callback) { | ||
module.exports = { | ||
name: 'data_service', | ||
resource: 'data_service', | ||
read: function(req, resource, params, config, callback) { | ||
@@ -226,3 +229,3 @@ // business logic | ||
module.exports = { | ||
name: 'FooService', | ||
resource: 'FooService', | ||
read: function create(req, resource, params, configs, callback) { | ||
@@ -229,0 +232,0 @@ var err = new Error('it failed'); |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
76790
1423
555
1