Comparing version 0.1.9 to 0.1.10
{ | ||
"name": "redux-nl", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "A GraphQL inspired rest client side network layer", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -121,13 +121,4 @@ /** | ||
}, | ||
/** | ||
* Normalises a successful response. | ||
* | ||
* @return {*[]} | ||
*/ | ||
normlzDataResponse: response => { | ||
return response.data.data || []; | ||
} | ||
}; | ||
export { createRequest }; |
@@ -28,11 +28,18 @@ /** | ||
const metaInSnakeCase = _omit(_mapKeys(meta, (_, key) => _snakeCase(key)), ["headers"]); | ||
// Extracts parameters from brackets e.g. "/user/orders/{id}" -> id (only supports a single query parameter) | ||
const extractedPathParameter = path | ||
.match(/\{(.+?)\}/g)?.[0] | ||
?.replace(/\{|}/g, ""); | ||
// This replaces path parameters with a variable from our 'payload' -> "/user/orders/{id}" -> "/user/orders/35" | ||
const pathWithParams = path.replace( | ||
/\{(.+?)\}/g, | ||
payloadInSnakeCase[extractedPathParameter] | ||
); | ||
// Can optionally include parameters in the path | ||
let pathWithParams = path; | ||
// If there are brackets in the request, we need to replace it with a variable in the payload | ||
if (path.match(/\{(.+?)\}/g) !== null) { | ||
// Extracts parameters from brackets e.g. "/user/orders/{id}" -> id (only supports a single query parameter) | ||
const extractedPathParameter = path | ||
.match(/\{(.+?)\}/g)?.[0] | ||
?.replace(/\{|}/g, ""); | ||
// This replaces path parameters with a variable from our 'payload' -> "/user/orders/{id}" -> "/user/orders/35" | ||
pathWithParams = path.replace( | ||
/\{(.+?)\}/g, | ||
payloadInSnakeCase[extractedPathParameter] | ||
); | ||
} | ||
// Build the URL for the request | ||
const url = createRequest.build(pathWithParams, metaInSnakeCase); | ||
@@ -59,3 +66,3 @@ | ||
.request(baseUrl, method.toLowerCase(), url, payloadInSnakeCase, meta?.headers) | ||
.then(response => resolve(createRequest.normlzDataResponse(response))) | ||
.then(response => resolve(response)) | ||
.catch(error => reject(error)); | ||
@@ -62,0 +69,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
32739
485