-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
458 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import _ from 'lodash'; | ||
|
||
/** | ||
* Creates new config with data pulled out from config request, | ||
* @param config | ||
* @returns config | ||
*/ | ||
export function buildRSAAConfig(config) { | ||
const rsaaConfig = { | ||
endpoint: config.request.endpoint, | ||
headers: config.request.headers, | ||
types: config.request.types, | ||
method: config.request.method, | ||
body: config.request.body, | ||
}; | ||
|
||
return _.omitBy(rsaaConfig, _.isNil); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import _ from 'lodash'; | ||
|
||
/** | ||
* Check if headers object supports entities() method. | ||
* @param {Headers} headers | ||
*/ | ||
function isHeadersEntriesSupported(headers) { | ||
return (_.isFunction(headers.entries)); | ||
} | ||
|
||
/** | ||
* Return existing or create new Headers object instance | ||
* @param {Headers|Object} headers | ||
*/ | ||
function getHeadersInstance(resource) { | ||
const headers = _.get(resource, 'headers'); | ||
|
||
if (headers instanceof Headers) { | ||
return headers; | ||
} | ||
|
||
return new Headers({ ...headers }); | ||
} | ||
|
||
/** | ||
* Extract Request/Response headers into a plain object | ||
* @param {Object} response | ||
*/ | ||
export function extractHeaders(resource) { | ||
const headers = getHeadersInstance(resource); | ||
const extractedHeaders = {}; | ||
|
||
if (isHeadersEntriesSupported(headers)) { | ||
for (const header of headers.entries()) { | ||
const [headerName, headerValue] = header; | ||
extractedHeaders[headerName] = headerValue; | ||
} | ||
} else { | ||
headers.forEach((headerValue, headerName) => { | ||
extractedHeaders[headerName] = headerValue; | ||
}); | ||
} | ||
|
||
return extractedHeaders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { extendMetaWithResponse } from './meta'; | ||
import { extractHeaders } from './headers'; | ||
import { buildRSAAConfig } from './config'; | ||
|
||
export { | ||
extendMetaWithResponse, | ||
extractHeaders, | ||
buildRSAAConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { extractHeaders } from './headers'; | ||
|
||
export function extendMetaWithResponse(meta) { | ||
return (action, state, res) => { | ||
const response = { | ||
status: res.status, | ||
headers: extractHeaders(res), | ||
}; | ||
return { ... meta, response }; | ||
|
||
return { ...meta, response }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.