2020-08-11 00:16:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { controls as dataControls } from '@wordpress/data-controls';
|
|
|
|
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
|
|
|
|
export const fetchWithHeaders = ( options ) => {
|
|
|
|
return {
|
|
|
|
type: 'FETCH_WITH_HEADERS',
|
|
|
|
options,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const controls = {
|
|
|
|
...dataControls,
|
|
|
|
FETCH_WITH_HEADERS( { options } ) {
|
|
|
|
return apiFetch( { ...options, parse: false } )
|
|
|
|
.then( ( response ) => {
|
2020-08-18 13:04:58 +00:00
|
|
|
return Promise.all( [
|
|
|
|
response.headers,
|
|
|
|
response.status,
|
|
|
|
response.json(),
|
|
|
|
] );
|
2020-08-11 00:16:27 +00:00
|
|
|
} )
|
2020-08-18 13:04:58 +00:00
|
|
|
.then( ( [ headers, status, data ] ) => ( {
|
|
|
|
headers,
|
|
|
|
status,
|
|
|
|
data,
|
|
|
|
} ) );
|
2020-08-11 00:16:27 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default controls;
|