directus-sdk-javascript
Advanced tools
Comparing version 2.2.0 to 2.3.0
{ | ||
"name": "directus-sdk-javascript", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "WIP - Directus SDK for JavaScript (Node and Browser)", | ||
@@ -27,3 +27,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"axios": "^0.16.2" | ||
"axios": "^0.16.2", | ||
"qs": "^6.5.1" | ||
}, | ||
@@ -30,0 +31,0 @@ "devDependencies": { |
const axios = require('axios'); | ||
const qs = require('qs'); | ||
class RemoteInstance { | ||
constructor(options) { | ||
const {accessToken, url} = options; | ||
const {accessToken, url, headers} = options; | ||
this.accessToken = accessToken; | ||
this.headers = headers; | ||
@@ -17,3 +19,3 @@ if (!url) { | ||
get _requestHeaders() { | ||
const headers = {}; | ||
const headers = this.headers; | ||
@@ -31,3 +33,7 @@ if (this.accessToken) { | ||
return new Promise((resolve, reject) => { | ||
axios.get(this.url + endpoint, {params, headers}) | ||
axios.get(this.url + endpoint, { | ||
params, | ||
headers, | ||
paramsSerializer: params => qs.stringify(params, {arrayFormat: 'brackets'}) | ||
}) | ||
.then(res => resolve(res.data)) | ||
@@ -92,2 +98,18 @@ .catch(err => { | ||
// Authentication | ||
// ------------------------------------------- | ||
authenticate(email = requiredParam('email'), password = requiredParam('password')) { | ||
return new Promise((resolve, reject) => { | ||
this._post('auth/request-token', {email, password}) | ||
.then(res => { | ||
if (res.success) { | ||
this.accessToken = res.data.token; | ||
return resolve(res); | ||
} | ||
return reject(res); | ||
}) | ||
.catch(err => reject(err)); | ||
}); | ||
} | ||
// Items | ||
@@ -115,2 +137,32 @@ // ---------------------------------------------------------------------------------- | ||
createBulk(table = requiredParam('table'), data = requiredParam('data')) { | ||
if (Array.isArray(data) === false) { | ||
throw new TypeError(`Parameter data should be an array of objects`); | ||
} | ||
return this._post(`tables/${table}/rows/bulk`, { | ||
rows: data | ||
}); | ||
} | ||
updateBulk(table = requiredParam('table'), data = requiredParam('data')) { | ||
if (Array.isArray(data) === false) { | ||
throw new TypeError(`Parameter data should be an array of objects`); | ||
} | ||
return this._put(`tables/${table}/rows/bulk`, { | ||
rows: data | ||
}); | ||
} | ||
deleteBulk(table = requiredParam('table'), data = requiredParam('data')) { | ||
if (Array.isArray(data) === false) { | ||
throw new TypeError(`Parameter data should be an array of objects`); | ||
} | ||
return this._delete(`tables/${table}/rows/bulk`, { | ||
rows: data | ||
}); | ||
} | ||
// Files | ||
@@ -117,0 +169,0 @@ // ---------------------------------------------------------------------------------- |
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
45958
273
2
+ Addedqs@^6.5.1
+ Addedcall-bind@1.0.7(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedside-channel@1.0.6(transitive)