1
- import { entrypoint } from '../config/entrypoint' ;
1
+ import { ENTRYPOINT } from '../config/entrypoint' ;
2
2
import { SubmissionError } from 'redux-form' ;
3
3
import has from 'lodash/has' ;
4
4
import mapValues from 'lodash/mapValues' ;
5
5
6
- const jsonLdMimeType = 'application/ld+json' ;
6
+ const MIME_TYPE = 'application/ld+json' ;
7
7
8
8
export function fetch ( id , options = { } ) {
9
9
if ( 'undefined' === typeof options . headers ) options . headers = new Headers ( ) ;
10
10
if ( null === options . headers . get ( 'Accept' ) )
11
- options . headers . set ( 'Accept' , jsonLdMimeType ) ;
11
+ options . headers . set ( 'Accept' , MIME_TYPE ) ;
12
12
13
13
if (
14
14
'undefined' !== options . body &&
15
15
! ( options . body instanceof FormData ) &&
16
16
null === options . headers . get ( 'Content-Type' )
17
17
)
18
- options . headers . set ( 'Content-Type' , jsonLdMimeType ) ;
18
+ options . headers . set ( 'Content-Type' , MIME_TYPE ) ;
19
19
20
- return global . fetch ( new URL ( id , entrypoint ) , options ) . then ( response => {
20
+ return global . fetch ( new URL ( id , ENTRYPOINT ) , options ) . then ( response => {
21
21
if ( response . ok ) return response ;
22
22
23
23
return response . json ( ) . then ( json => {
@@ -41,7 +41,7 @@ export function mercureSubscribe(url) {
41
41
export function normalize ( data ) {
42
42
// Resolve IDs to absolute URLs
43
43
if ( has ( data , '@id' ) )
44
- data [ '@id' ] = new URL ( data [ '@id' ] , entrypoint ) . toString ( ) ;
44
+ data [ '@id' ] = new URL ( data [ '@id' ] , ENTRYPOINT ) . toString ( ) ;
45
45
46
46
if ( has ( data , 'hydra:member' ) ) {
47
47
// Normalize items in collections
@@ -54,9 +54,9 @@ export function normalize(data) {
54
54
mapValues ( data , value => {
55
55
if ( Array . isArray ( value ) )
56
56
return value . map (
57
- v => ( has ( v , '@id' ) ? new URL ( v [ '@id' ] , entrypoint ) . toString ( ) : v )
57
+ v => ( has ( v , '@id' ) ? new URL ( v [ '@id' ] , ENTRYPOINT ) . toString ( ) : v )
58
58
) ;
59
- if ( has ( value , '@id' ) ) return new URL ( value [ '@id' ] , entrypoint ) . toString ( ) ;
59
+ if ( has ( value , '@id' ) ) return new URL ( value [ '@id' ] , ENTRYPOINT ) . toString ( ) ;
60
60
return value ;
61
61
} ) ;
62
62
@@ -72,5 +72,5 @@ export function extractHubURL(response) {
72
72
) ;
73
73
if ( ! matches || ! matches [ 1 ] ) return null ;
74
74
75
- return new URL ( matches [ 1 ] , entrypoint ) ;
75
+ return new URL ( matches [ 1 ] , ENTRYPOINT ) ;
76
76
}
0 commit comments