|
@@ -1,5 +1,3 @@ |
|
|
/* api wrapper */ |
|
|
|
|
|
|
|
|
|
|
|
// utilities |
|
|
// utilities |
|
|
// generate downloadable csv |
|
|
// generate downloadable csv |
|
|
const download = (options={}) => { |
|
|
const download = (options={}) => { |
|
@@ -109,8 +107,21 @@ const _make_api = (api_root, need_auth=true) => { |
|
|
|
|
|
|
|
|
// expose authentication module |
|
|
// expose authentication module |
|
|
auth: _auth, |
|
|
auth: _auth, |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// wrap m.request with authentication validation |
|
|
|
|
|
|
|
|
/* api wrapper */ |
|
|
|
|
|
/* |
|
|
|
|
|
* api.request(options): all options will be forwarded to m.request, except a |
|
|
|
|
|
* few: |
|
|
|
|
|
* |
|
|
|
|
|
* 1. options.queries: an array of object '{label: <>, value: <>, op: <>}' to |
|
|
|
|
|
* build postgrest query easily |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
export default (api_root, auth={}) => { |
|
|
|
|
|
return { |
|
|
|
|
|
// wrap m.request with authentication validation if demanded |
|
|
request: (options = {}) => { |
|
|
request: (options = {}) => { |
|
|
/* normalize arguments */ |
|
|
/* normalize arguments */ |
|
|
if (typeof options === 'string') { |
|
|
if (typeof options === 'string') { |
|
@@ -119,11 +130,11 @@ const _make_api = (api_root, need_auth=true) => { |
|
|
|
|
|
|
|
|
/* normalize url */ |
|
|
/* normalize url */ |
|
|
if (options.url.startsWith('/')) |
|
|
if (options.url.startsWith('/')) |
|
|
options.url = _root + options.url |
|
|
|
|
|
|
|
|
options.url = api_root + options.url |
|
|
|
|
|
|
|
|
/* normalize headers */ |
|
|
/* normalize headers */ |
|
|
// 1. check if auth is required |
|
|
// 1. check if auth is required |
|
|
if (need_auth) { |
|
|
|
|
|
|
|
|
if (false/*need_auth*/) { |
|
|
// insert auth header if availible |
|
|
// insert auth header if availible |
|
|
if (_auth.token()) { |
|
|
if (_auth.token()) { |
|
|
options.headers = { |
|
|
options.headers = { |
|
@@ -193,5 +204,3 @@ const _make_api = (api_root, need_auth=true) => { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default _make_api('https://api-dev.uidt.net/phanerozoic/v1', false) |
|
|
|