@uppy/companion-client
Advanced tools
Comparing version 1.5.1 to 1.5.2
@@ -35,12 +35,8 @@ 'use strict'; | ||
_proto.headers = function headers() { | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_RequestClient.prototype.headers.call(_this2).then(function (headers) { | ||
_this2.getAuthToken().then(function (token) { | ||
resolve(_extends({}, headers, { | ||
'uppy-auth-token': token | ||
})); | ||
}); | ||
}).catch(reject); | ||
return Promise.all([_RequestClient.prototype.headers.call(this), this.getAuthToken()]).then(function (_ref) { | ||
var headers = _ref[0], | ||
token = _ref[1]; | ||
return _extends({}, headers, { | ||
'uppy-auth-token': token | ||
}); | ||
}); | ||
@@ -82,10 +78,9 @@ }; | ||
_proto.logout = function logout() { | ||
var _this3 = this; | ||
var _this2 = this; | ||
return new Promise(function (resolve, reject) { | ||
_this3.get(_this3.id + "/logout").then(function (res) { | ||
_this3.uppy.getPlugin(_this3.pluginId).storage.removeItem(_this3.tokenKey).then(function () { | ||
return resolve(res); | ||
}).catch(reject); | ||
}).catch(reject); | ||
return this.get(this.id + "/logout").then(function (response) { | ||
return Promise.all([response, _this2.uppy.getPlugin(_this2.pluginId).storage.removeItem(_this2.tokenKey)]); | ||
}).then(function (_ref2) { | ||
var response = _ref2[0]; | ||
return response; | ||
}); | ||
@@ -92,0 +87,0 @@ }; |
@@ -95,24 +95,22 @@ 'use strict'; | ||
return new Promise(function (resolve, reject) { | ||
if (_this2.preflightDone) { | ||
return resolve(_this2.allowedHeaders.slice()); | ||
if (this.preflightDone) { | ||
return Promise.resolve(this.allowedHeaders.slice()); | ||
} | ||
return fetch(this._getUrl(path), { | ||
method: 'OPTIONS' | ||
}).then(function (response) { | ||
if (response.headers.has('access-control-allow-headers')) { | ||
_this2.allowedHeaders = response.headers.get('access-control-allow-headers').split(',').map(function (headerName) { | ||
return headerName.trim().toLowerCase(); | ||
}); | ||
} | ||
fetch(_this2._getUrl(path), { | ||
method: 'OPTIONS' | ||
}).then(function (response) { | ||
if (response.headers.has('access-control-allow-headers')) { | ||
_this2.allowedHeaders = response.headers.get('access-control-allow-headers').split(',').map(function (headerName) { | ||
return headerName.trim().toLowerCase(); | ||
}); | ||
} | ||
_this2.preflightDone = true; | ||
return _this2.allowedHeaders.slice(); | ||
}).catch(function (err) { | ||
_this2.uppy.log("[CompanionClient] unable to make preflight request " + err, 'warning'); | ||
_this2.preflightDone = true; | ||
resolve(_this2.allowedHeaders.slice()); | ||
}).catch(function (err) { | ||
_this2.uppy.log("[CompanionClient] unable to make preflight request " + err, 'warning'); | ||
_this2.preflightDone = true; | ||
resolve(_this2.allowedHeaders.slice()); | ||
}); | ||
_this2.preflightDone = true; | ||
return _this2.allowedHeaders.slice(); | ||
}); | ||
@@ -142,15 +140,13 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
_this4.preflightAndHeaders(path).then(function (headers) { | ||
fetchWithNetworkError(_this4._getUrl(path), { | ||
method: 'get', | ||
headers: headers, | ||
credentials: 'same-origin' | ||
}).then(_this4._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this4._json(res).then(resolve); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not get " + _this4._getUrl(path) + ". " + err); | ||
reject(err); | ||
}); | ||
}).catch(reject); | ||
return this.preflightAndHeaders(path).then(function (headers) { | ||
return fetchWithNetworkError(_this4._getUrl(path), { | ||
method: 'get', | ||
headers: headers, | ||
credentials: 'same-origin' | ||
}); | ||
}).then(this._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this4._json(res); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not get " + _this4._getUrl(path) + ". " + err); | ||
return Promise.reject(err); | ||
}); | ||
@@ -162,16 +158,14 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
_this5.preflightAndHeaders(path).then(function (headers) { | ||
fetchWithNetworkError(_this5._getUrl(path), { | ||
method: 'post', | ||
headers: headers, | ||
credentials: 'same-origin', | ||
body: JSON.stringify(data) | ||
}).then(_this5._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this5._json(res).then(resolve); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not post " + _this5._getUrl(path) + ". " + err); | ||
reject(err); | ||
}); | ||
}).catch(reject); | ||
return this.preflightAndHeaders(path).then(function (headers) { | ||
return fetchWithNetworkError(_this5._getUrl(path), { | ||
method: 'post', | ||
headers: headers, | ||
credentials: 'same-origin', | ||
body: JSON.stringify(data) | ||
}); | ||
}).then(this._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this5._json(res); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not post " + _this5._getUrl(path) + ". " + err); | ||
return Promise.reject(err); | ||
}); | ||
@@ -183,16 +177,14 @@ }; | ||
return new Promise(function (resolve, reject) { | ||
_this6.preflightAndHeaders(path).then(function (headers) { | ||
fetchWithNetworkError(_this6.hostname + "/" + path, { | ||
method: 'delete', | ||
headers: headers, | ||
credentials: 'same-origin', | ||
body: data ? JSON.stringify(data) : null | ||
}).then(_this6._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this6._json(res).then(resolve); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not delete " + _this6._getUrl(path) + ". " + err); | ||
reject(err); | ||
}); | ||
}).catch(reject); | ||
return this.preflightAndHeaders(path).then(function (headers) { | ||
return fetchWithNetworkError(_this6.hostname + "/" + path, { | ||
method: 'delete', | ||
headers: headers, | ||
credentials: 'same-origin', | ||
body: data ? JSON.stringify(data) : null | ||
}); | ||
}).then(this._getPostResponseFunc(skipPostResponse)).then(function (res) { | ||
return _this6._json(res); | ||
}).catch(function (err) { | ||
err = err.isAuthError ? err : new Error("Could not delete " + _this6._getUrl(path) + ". " + err); | ||
return Promise.reject(err); | ||
}); | ||
@@ -222,2 +214,2 @@ }; | ||
return RequestClient; | ||
}(), _class.VERSION = "1.5.1", _temp); | ||
}(), _class.VERSION = "1.5.2", _temp); |
{ | ||
"name": "@uppy/companion-client", | ||
"description": "Client library for communication with Companion. Intended for use in Uppy plugins.", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"license": "MIT", | ||
@@ -24,6 +24,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^3.2.0", | ||
"@uppy/utils": "^3.2.1", | ||
"namespace-emitter": "^2.0.1" | ||
}, | ||
"gitHead": "16686fc0cae55dd40f449f63005273145aba7df3" | ||
"gitHead": "2d91641ddd1efbb7b21ba850156d865491999106" | ||
} |
@@ -18,3 +18,3 @@ # @uppy/companion-client | ||
const uppy = Uppy() | ||
const uppy = new Uppy() | ||
@@ -21,0 +21,0 @@ const client = new RequestClient(uppy, { companionUrl: 'https://uppy.mywebsite.com/' }) |
@@ -21,9 +21,6 @@ 'use strict' | ||
headers () { | ||
return new Promise((resolve, reject) => { | ||
super.headers().then((headers) => { | ||
this.getAuthToken().then((token) => { | ||
resolve(Object.assign({}, headers, { 'uppy-auth-token': token })) | ||
}) | ||
}).catch(reject) | ||
}) | ||
return Promise.all([super.headers(), this.getAuthToken()]) | ||
.then(([headers, token]) => | ||
Object.assign({}, headers, { 'uppy-auth-token': token }) | ||
) | ||
} | ||
@@ -62,10 +59,7 @@ | ||
logout () { | ||
return new Promise((resolve, reject) => { | ||
this.get(`${this.id}/logout`) | ||
.then((res) => { | ||
this.uppy.getPlugin(this.pluginId).storage.removeItem(this.tokenKey) | ||
.then(() => resolve(res)) | ||
.catch(reject) | ||
}).catch(reject) | ||
}) | ||
return this.get(`${this.id}/logout`) | ||
.then((response) => Promise.all([ | ||
response, | ||
this.uppy.getPlugin(this.pluginId).storage.removeItem(this.tokenKey) | ||
])).then(([response]) => response) | ||
} | ||
@@ -72,0 +66,0 @@ |
@@ -95,24 +95,22 @@ 'use strict' | ||
preflight (path) { | ||
return new Promise((resolve, reject) => { | ||
if (this.preflightDone) { | ||
return resolve(this.allowedHeaders.slice()) | ||
} | ||
if (this.preflightDone) { | ||
return Promise.resolve(this.allowedHeaders.slice()) | ||
} | ||
fetch(this._getUrl(path), { | ||
method: 'OPTIONS' | ||
return fetch(this._getUrl(path), { | ||
method: 'OPTIONS' | ||
}) | ||
.then((response) => { | ||
if (response.headers.has('access-control-allow-headers')) { | ||
this.allowedHeaders = response.headers.get('access-control-allow-headers') | ||
.split(',').map((headerName) => headerName.trim().toLowerCase()) | ||
} | ||
this.preflightDone = true | ||
return this.allowedHeaders.slice() | ||
}) | ||
.then((response) => { | ||
if (response.headers.has('access-control-allow-headers')) { | ||
this.allowedHeaders = response.headers.get('access-control-allow-headers') | ||
.split(',').map((headerName) => headerName.trim().toLowerCase()) | ||
} | ||
this.preflightDone = true | ||
resolve(this.allowedHeaders.slice()) | ||
}) | ||
.catch((err) => { | ||
this.uppy.log(`[CompanionClient] unable to make preflight request ${err}`, 'warning') | ||
this.preflightDone = true | ||
resolve(this.allowedHeaders.slice()) | ||
}) | ||
}) | ||
.catch((err) => { | ||
this.uppy.log(`[CompanionClient] unable to make preflight request ${err}`, 'warning') | ||
this.preflightDone = true | ||
return this.allowedHeaders.slice() | ||
}) | ||
} | ||
@@ -136,4 +134,4 @@ | ||
get (path, skipPostResponse) { | ||
return new Promise((resolve, reject) => { | ||
this.preflightAndHeaders(path).then((headers) => { | ||
return this.preflightAndHeaders(path) | ||
.then((headers) => | ||
fetchWithNetworkError(this._getUrl(path), { | ||
@@ -143,16 +141,14 @@ method: 'get', | ||
credentials: 'same-origin' | ||
}) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res).then(resolve)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not get ${this._getUrl(path)}. ${err}`) | ||
reject(err) | ||
}) | ||
}).catch(reject) | ||
}) | ||
})) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not get ${this._getUrl(path)}. ${err}`) | ||
return Promise.reject(err) | ||
}) | ||
} | ||
post (path, data, skipPostResponse) { | ||
return new Promise((resolve, reject) => { | ||
this.preflightAndHeaders(path).then((headers) => { | ||
return this.preflightAndHeaders(path) | ||
.then((headers) => | ||
fetchWithNetworkError(this._getUrl(path), { | ||
@@ -163,16 +159,14 @@ method: 'post', | ||
body: JSON.stringify(data) | ||
}) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res).then(resolve)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not post ${this._getUrl(path)}. ${err}`) | ||
reject(err) | ||
}) | ||
}).catch(reject) | ||
}) | ||
})) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not post ${this._getUrl(path)}. ${err}`) | ||
return Promise.reject(err) | ||
}) | ||
} | ||
delete (path, data, skipPostResponse) { | ||
return new Promise((resolve, reject) => { | ||
this.preflightAndHeaders(path).then((headers) => { | ||
return this.preflightAndHeaders(path) | ||
.then((headers) => | ||
fetchWithNetworkError(`${this.hostname}/${path}`, { | ||
@@ -183,12 +177,10 @@ method: 'delete', | ||
body: data ? JSON.stringify(data) : null | ||
}) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res).then(resolve)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not delete ${this._getUrl(path)}. ${err}`) | ||
reject(err) | ||
}) | ||
}).catch(reject) | ||
}) | ||
})) | ||
.then(this._getPostResponseFunc(skipPostResponse)) | ||
.then((res) => this._json(res)) | ||
.catch((err) => { | ||
err = err.isAuthError ? err : new Error(`Could not delete ${this._getUrl(path)}. ${err}`) | ||
return Promise.reject(err) | ||
}) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
66191
948
Updated@uppy/utils@^3.2.1