directus-sdk-javascript
Advanced tools
Comparing version 3.0.0-8 to 3.0.0-9
{ | ||
"name": "directus-sdk-javascript", | ||
"version": "3.0.0-8", | ||
"version": "3.0.0-9", | ||
"description": "WIP - Directus SDK for JavaScript (Node and Browser)", | ||
@@ -28,3 +28,2 @@ "main": "index.js", | ||
"axios": "^0.16.2", | ||
"base-64": "^0.1.0", | ||
"qs": "^6.5.1" | ||
@@ -31,0 +30,0 @@ }, |
const axios = require('axios'); | ||
const base64 = require('base-64'); | ||
const qs = require('qs'); | ||
@@ -14,13 +13,11 @@ | ||
class RemoteInstance { | ||
constructor(options = {}) { | ||
// Headers to be send with every request | ||
this._headers = options.headers || {}; | ||
const RemoteInstance = { | ||
// Headers to be send with every request | ||
headers: {}, | ||
// The currently in use full unparsed access token | ||
this._accessToken = options.accessToken || {}; | ||
// The currently in use full unparsed access token | ||
accessToken: null, | ||
// The currently in use api url | ||
this._url = options.url || {}; | ||
} | ||
// The currently in use api url | ||
url: null, | ||
@@ -37,27 +34,11 @@ // Private methods | ||
_createHeaders() { | ||
const headers = this._headers || {}; | ||
const headers = this.headers || {}; | ||
if (this._accessToken) { | ||
headers.Authorization = 'Bearer ' + this._accessToken; | ||
if (this.accessToken) { | ||
headers.Authorization = 'Bearer ' + this.accessToken; | ||
} | ||
return headers; | ||
} | ||
}, | ||
get url() { | ||
return this._url; | ||
} | ||
set url(val) { | ||
this._url = val; | ||
} | ||
get accessToken() { | ||
return this._accessToken; | ||
} | ||
set accessToken(val) { | ||
this._accessToken = val; | ||
} | ||
// --------------------------------------------------------------------------- | ||
@@ -80,3 +61,3 @@ | ||
request(method, url, requestData = {}) { | ||
if (Boolean(this._url) === false) throw 'No API URL set'; | ||
if (Boolean(this.url) === false) throw 'No API URL set'; | ||
@@ -89,3 +70,3 @@ const requestConfig = { | ||
headers: this._createHeaders(), | ||
baseURL: this._url, | ||
baseURL: this.url, | ||
@@ -97,3 +78,3 @@ // Use QS to format params | ||
return axios.request(requestConfig).then(response => response.data); | ||
} | ||
}, | ||
@@ -106,7 +87,7 @@ // --------------------------------------------------------------------------- | ||
return this.request('post', '/auth/authenticate', userCredentials); | ||
} | ||
}, | ||
refreshToken(token) { | ||
return this.request('post', '/auth/refresh', { token }); | ||
} | ||
}, | ||
@@ -117,19 +98,19 @@ // Items | ||
return this.request('get', `items/${table}`, params); | ||
} | ||
}, | ||
getItem(table = requiredParam('table'), primaryKey = requiredParam('primaryKey'), params = {}) { | ||
return this.request('get', `items/${table}/${primaryKey}`, params); | ||
} | ||
}, | ||
updateItem(table = requiredParam('table'), primaryKey = requiredParam('primaryKey'), data = {}) { | ||
return this.request('patch', `items/${table}/${primaryKey}`, data); | ||
} | ||
}, | ||
createItem(table = requiredParam('table'), data = {}) { | ||
return this.request('post', `items/${table}`, data); | ||
} | ||
}, | ||
deleteItem(table = requiredParam('table'), primaryKey = requiredParam('primaryKey')) { | ||
return this.request('delete', `items/${table}/${primaryKey}`); | ||
} | ||
}, | ||
@@ -140,8 +121,8 @@ // Tables | ||
return this.request('get', 'tables', params); | ||
} | ||
}, | ||
getTable(table = requiredParam('table'), params = {}) { | ||
return this.request('get', `tables/${table}`, params); | ||
} | ||
} | ||
}, | ||
}; | ||
@@ -148,0 +129,0 @@ function requiredParam(name) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
40448
103
- Removedbase-64@^0.1.0
- Removedbase-64@0.1.0(transitive)