@buttercup/dropbox-client
Advanced tools
Comparing version 0.1.1 to 0.2.0
# Dropbox Client changelog | ||
## v0.2.0 | ||
_2019-07-16_ | ||
* Replace `axios` with `cowl` for HTTP requests | ||
## v0.1.1 | ||
@@ -4,0 +9,0 @@ _2018-11-15_ |
{ | ||
"name": "@buttercup/dropbox-client", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Dropbox client library", | ||
@@ -26,3 +26,3 @@ "main": "source/index.js", | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"cowl": "^0.3.1", | ||
"hot-patcher": "^0.5.0" | ||
@@ -33,7 +33,7 @@ }, | ||
"chai-as-promised": "^7.1.1", | ||
"jsdoc-to-markdown": "^4.0.1", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"sinon": "^7.1.1" | ||
"jsdoc-to-markdown": "^5.0.0", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.1.1", | ||
"sinon": "^7.3.2" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # Dropbox Client | ||
This library is a barebones HTTP client that makes requests directly to Dropbox's HTTP API using a token (handled externally - this library will not be responsible for fetching them). The result is a tiny, portable script that is reliable and simple to understand. It uses [axios](https://github.com/axios/axios) to perform requests, which has been proven to be a stable cross-platform library perfect for this purpose. | ||
This library is a barebones HTTP client that makes requests directly to Dropbox's HTTP API using a token (handled externally - this library will not be responsible for fetching them). The result is a tiny, portable script that is reliable and simple to understand. It uses [cowl](https://github.com/perry-mitchell/cowl) to perform requests, which is designed to work similarly across multiple platforms. | ||
@@ -13,0 +13,0 @@ ## Installation |
/** | ||
* @typedef {Object} DirectoryResult | ||
* @property {String} name The file name | ||
* @property {String} path The parent path of the item | ||
* @property {String} type Either "file" or "directory" | ||
* @property {String} id The Dropbox item ID | ||
* @property {Number} size The size of the item | ||
*/ | ||
/** | ||
* @typedef {Object} DropboxItemResult | ||
* @property {String} name Item name | ||
* @property {String} path_display Item containing path | ||
* @property {String} ".tag" The item type | ||
* @property {String} id The Dropbox item ID | ||
* @property {Number} size The item size | ||
*/ | ||
/** | ||
* Convert a Dropbox result item to a common format | ||
* @param {DropboxItemResult} item | ||
* @returns {DirectoryResult} | ||
*/ | ||
function convertDirectoryResult(item) { | ||
@@ -6,0 +25,0 @@ const dropboxType = item[".tag"]; |
const HotPatcher = require("hot-patcher"); | ||
const axios = require("axios"); | ||
const { request } = require("cowl"); | ||
const { getDirectoryContents, getFileContents, putFileContents } = require("./requests.js"); | ||
@@ -13,3 +13,3 @@ const { createFsInterface } = require("./fs.js"); | ||
const patcher = new HotPatcher(); | ||
patcher.patch("request", axios); | ||
patcher.patch("request", request); | ||
/** | ||
@@ -22,5 +22,5 @@ * @class DropboxClientAdapter | ||
* @memberof DropboxClientAdapter | ||
* @see https://github.com/axios/axios | ||
* @see https://github.com/perry-mitchell/cowl | ||
*/ | ||
axios, | ||
request, | ||
/** | ||
@@ -27,0 +27,0 @@ * @type {HotPatcher} |
@@ -16,3 +16,3 @@ const { convertDirectoryResult } = require("./convert.js"); | ||
}, | ||
data: { | ||
body: { | ||
path, | ||
@@ -28,3 +28,2 @@ recursive: false, | ||
return patcher.execute("request", config) | ||
.then(handleResponse) | ||
.then(response => { | ||
@@ -49,13 +48,5 @@ const { entries } = response.data; | ||
return patcher.execute("request", config) | ||
.then(handleResponse) | ||
.then(response => response.data); | ||
} | ||
function handleResponse(response) { | ||
if (!response.status || response.status < 200 || response.status >= 300) { | ||
throw new Error(`Invalid response: ${response.status} ${response.statusText}`); | ||
} | ||
return response; | ||
} | ||
function putFileContents(filename, data, token, patcher) { | ||
@@ -65,3 +56,3 @@ const config = { | ||
url: UPLOAD_URL, | ||
params: { | ||
query: { | ||
arg: JSON.stringify({ | ||
@@ -79,6 +70,5 @@ path: filename, | ||
}, | ||
data | ||
body: data | ||
}; | ||
return patcher.execute("request", config) | ||
.then(handleResponse) | ||
.then(() => {}) | ||
@@ -85,0 +75,0 @@ } |
@@ -102,5 +102,5 @@ const { createClient, createFsInterface } = require("../../source/index.js"); | ||
const arg = this.request.firstCall.args[0]; | ||
expect(arg).to.have.nested.property("params.arg").that.is.a("string"); | ||
expect(arg).to.have.nested.property("params.reject_cors_preflight", "true"); | ||
const payload = JSON.parse(arg.params.arg); | ||
expect(arg).to.have.nested.property("query.arg").that.is.a("string"); | ||
expect(arg).to.have.nested.property("query.reject_cors_preflight", "true"); | ||
const payload = JSON.parse(arg.query.arg); | ||
expect(payload).to.deep.equal({ | ||
@@ -116,3 +116,3 @@ path: "/file.txt", | ||
const arg = this.request.firstCall.args[0]; | ||
expect(arg).to.have.nested.property("params.authorization", `Bearer ${FAKE_TOKEN}`); | ||
expect(arg).to.have.nested.property("query.authorization", `Bearer ${FAKE_TOKEN}`); | ||
expect(arg.headers).to.not.have.property("Authorization"); | ||
@@ -125,3 +125,3 @@ }); | ||
const arg = this.request.firstCall.args[0]; | ||
expect(arg).to.have.property("data", "testing"); | ||
expect(arg).to.have.property("body", "testing"); | ||
}); | ||
@@ -246,3 +246,3 @@ }); | ||
const arg = this.request.firstCall.args[0]; | ||
expect(arg).to.have.property("data", "test-content"); | ||
expect(arg).to.have.property("body", "test-content"); | ||
done(); | ||
@@ -249,0 +249,0 @@ }); |
29841
481
+ Addedcowl@^0.3.1
+ Addedarraybuffer-to-buffer@0.0.6(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcowl@0.3.2(transitive)
+ Addedget-headers@1.0.5(transitive)
+ Addedis-array-buffer@1.0.1(transitive)
+ Addedis-browser@2.1.0(transitive)
+ Addedxhr2@0.2.1(transitive)
- Removedaxios@^0.18.0
- Removedaxios@0.18.1(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedis-buffer@2.0.5(transitive)