diff --git a/src/postgrest.js b/src/postgrest.js index 809bf48..58e4432 100644 --- a/src/postgrest.js +++ b/src/postgrest.js @@ -1,5 +1,3 @@ -/* api wrapper */ - // utilities // generate downloadable csv const download = (options={}) => { @@ -109,8 +107,21 @@ const _make_api = (api_root, need_auth=true) => { // expose authentication module 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 = {}) => { /* normalize arguments */ if (typeof options === 'string') { @@ -119,11 +130,11 @@ const _make_api = (api_root, need_auth=true) => { /* normalize url */ if (options.url.startsWith('/')) - options.url = _root + options.url + options.url = api_root + options.url /* normalize headers */ // 1. check if auth is required - if (need_auth) { + if (false/*need_auth*/) { // insert auth header if availible if (_auth.token()) { 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)