@cubejs-client/core
Advanced tools
Comparing version 0.11.7 to 0.11.9
@@ -6,2 +6,13 @@ # Change Log | ||
## [0.11.9](https://github.com/statsbotco/cubejs-client/compare/v0.11.8...v0.11.9) (2019-10-23) | ||
### Bug Fixes | ||
* Support `apiToken` to be an async function: first request sends incorrect token ([a2d0c77](https://github.com/statsbotco/cubejs-client/commit/a2d0c77)) | ||
## [0.11.7](https://github.com/statsbotco/cubejs-client/compare/v0.11.6...v0.11.7) (2019-10-22) | ||
@@ -8,0 +19,0 @@ |
@@ -845,3 +845,3 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread'; | ||
this.transport = options.transport || new HttpTransport({ | ||
authorization: apiToken, | ||
authorization: typeof apiToken === 'function' ? undefined : apiToken, | ||
apiUrl: this.apiUrl | ||
@@ -876,3 +876,5 @@ }); | ||
var requestInstance = request(); | ||
var requestPromise = this.updateTransportAuthorization().then(function () { | ||
return request(); | ||
}); | ||
var unsubscribed = false; | ||
@@ -886,2 +888,3 @@ | ||
_regeneratorRuntime.mark(function _callee() { | ||
var requestInstance; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -891,4 +894,10 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context.sent; | ||
if (!(options.mutexObj && options.mutexObj[mutexKey] !== mutexValue)) { | ||
_context.next = 6; | ||
_context.next = 9; | ||
break; | ||
@@ -900,13 +909,13 @@ } | ||
if (!requestInstance.unsubscribe) { | ||
_context.next = 5; | ||
_context.next = 8; | ||
break; | ||
} | ||
_context.next = 5; | ||
_context.next = 8; | ||
return requestInstance.unsubscribe(); | ||
case 5: | ||
case 8: | ||
throw MUTEX_ERROR; | ||
case 6: | ||
case 9: | ||
case "end": | ||
@@ -930,3 +939,3 @@ return _context.stop(); | ||
_regeneratorRuntime.mark(function _callee4(response, next) { | ||
var subscribeNext, continueWait, token, body, error, result; | ||
var requestInstance, subscribeNext, continueWait, body, error, result; | ||
return _regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
@@ -936,2 +945,8 @@ while (1) { | ||
case 0: | ||
_context4.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context4.sent; | ||
subscribeNext = | ||
@@ -1032,17 +1047,5 @@ /*#__PURE__*/ | ||
if (!(typeof _this.apiToken === 'function')) { | ||
_context4.next = 7; | ||
break; | ||
} | ||
_context4.next = 7; | ||
return _this.updateTransportAuthorization(); | ||
_context4.next = 5; | ||
return _this.apiToken(); | ||
case 5: | ||
token = _context4.sent; | ||
if (_this.transport.authorization !== token) { | ||
_this.transport.authorization = token; | ||
} | ||
case 7: | ||
@@ -1162,3 +1165,5 @@ if (!(response.status === 502)) { | ||
var promise = mutexPromise(requestInstance.subscribe(loadImpl)); | ||
var promise = requestPromise.then(function (requestInstance) { | ||
return mutexPromise(requestInstance.subscribe(loadImpl)); | ||
}); | ||
@@ -1171,2 +1176,3 @@ if (callback) { | ||
_regeneratorRuntime.mark(function _callee5() { | ||
var requestInstance; | ||
return _regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
@@ -1176,6 +1182,11 @@ while (1) { | ||
case 0: | ||
_context5.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context5.sent; | ||
unsubscribed = true; | ||
if (!requestInstance.unsubscribe) { | ||
_context5.next = 3; | ||
_context5.next = 6; | ||
break; | ||
@@ -1186,6 +1197,6 @@ } | ||
case 3: | ||
case 6: | ||
return _context5.abrupt("return", null); | ||
case 4: | ||
case 7: | ||
case "end": | ||
@@ -1207,2 +1218,40 @@ return _context5.stop(); | ||
} | ||
}, { | ||
key: "updateTransportAuthorization", | ||
value: function () { | ||
var _updateTransportAuthorization = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee6() { | ||
var token; | ||
return _regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
if (!(typeof this.apiToken === 'function')) { | ||
_context6.next = 5; | ||
break; | ||
} | ||
_context6.next = 3; | ||
return this.apiToken(); | ||
case 3: | ||
token = _context6.sent; | ||
if (this.transport.authorization !== token) { | ||
this.transport.authorization = token; | ||
} | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
return function updateTransportAuthorization() { | ||
return _updateTransportAuthorization.apply(this, arguments); | ||
}; | ||
}() | ||
/** | ||
@@ -1322,2 +1371,3 @@ * Fetch data for passed `query`. | ||
* In the development mode, Cube.js Backend will print the API token to the console on on startup. | ||
* Can be an async function without arguments that returns API token. | ||
* @param options - options object. | ||
@@ -1324,0 +1374,0 @@ * @param options.apiUrl - URL of your Cube.js Backend. |
@@ -851,3 +851,3 @@ 'use strict'; | ||
this.transport = options.transport || new HttpTransport({ | ||
authorization: apiToken, | ||
authorization: typeof apiToken === 'function' ? undefined : apiToken, | ||
apiUrl: this.apiUrl | ||
@@ -882,3 +882,5 @@ }); | ||
var requestInstance = request(); | ||
var requestPromise = this.updateTransportAuthorization().then(function () { | ||
return request(); | ||
}); | ||
var unsubscribed = false; | ||
@@ -892,2 +894,3 @@ | ||
_regeneratorRuntime.mark(function _callee() { | ||
var requestInstance; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -897,4 +900,10 @@ while (1) { | ||
case 0: | ||
_context.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context.sent; | ||
if (!(options.mutexObj && options.mutexObj[mutexKey] !== mutexValue)) { | ||
_context.next = 6; | ||
_context.next = 9; | ||
break; | ||
@@ -906,13 +915,13 @@ } | ||
if (!requestInstance.unsubscribe) { | ||
_context.next = 5; | ||
_context.next = 8; | ||
break; | ||
} | ||
_context.next = 5; | ||
_context.next = 8; | ||
return requestInstance.unsubscribe(); | ||
case 5: | ||
case 8: | ||
throw MUTEX_ERROR; | ||
case 6: | ||
case 9: | ||
case "end": | ||
@@ -936,3 +945,3 @@ return _context.stop(); | ||
_regeneratorRuntime.mark(function _callee4(response, next) { | ||
var subscribeNext, continueWait, token, body, error, result; | ||
var requestInstance, subscribeNext, continueWait, body, error, result; | ||
return _regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
@@ -942,2 +951,8 @@ while (1) { | ||
case 0: | ||
_context4.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context4.sent; | ||
subscribeNext = | ||
@@ -1038,17 +1053,5 @@ /*#__PURE__*/ | ||
if (!(typeof _this.apiToken === 'function')) { | ||
_context4.next = 7; | ||
break; | ||
} | ||
_context4.next = 7; | ||
return _this.updateTransportAuthorization(); | ||
_context4.next = 5; | ||
return _this.apiToken(); | ||
case 5: | ||
token = _context4.sent; | ||
if (_this.transport.authorization !== token) { | ||
_this.transport.authorization = token; | ||
} | ||
case 7: | ||
@@ -1168,3 +1171,5 @@ if (!(response.status === 502)) { | ||
var promise = mutexPromise(requestInstance.subscribe(loadImpl)); | ||
var promise = requestPromise.then(function (requestInstance) { | ||
return mutexPromise(requestInstance.subscribe(loadImpl)); | ||
}); | ||
@@ -1177,2 +1182,3 @@ if (callback) { | ||
_regeneratorRuntime.mark(function _callee5() { | ||
var requestInstance; | ||
return _regeneratorRuntime.wrap(function _callee5$(_context5) { | ||
@@ -1182,6 +1188,11 @@ while (1) { | ||
case 0: | ||
_context5.next = 2; | ||
return requestPromise; | ||
case 2: | ||
requestInstance = _context5.sent; | ||
unsubscribed = true; | ||
if (!requestInstance.unsubscribe) { | ||
_context5.next = 3; | ||
_context5.next = 6; | ||
break; | ||
@@ -1192,6 +1203,6 @@ } | ||
case 3: | ||
case 6: | ||
return _context5.abrupt("return", null); | ||
case 4: | ||
case 7: | ||
case "end": | ||
@@ -1213,2 +1224,40 @@ return _context5.stop(); | ||
} | ||
}, { | ||
key: "updateTransportAuthorization", | ||
value: function () { | ||
var _updateTransportAuthorization = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
_regeneratorRuntime.mark(function _callee6() { | ||
var token; | ||
return _regeneratorRuntime.wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
if (!(typeof this.apiToken === 'function')) { | ||
_context6.next = 5; | ||
break; | ||
} | ||
_context6.next = 3; | ||
return this.apiToken(); | ||
case 3: | ||
token = _context6.sent; | ||
if (this.transport.authorization !== token) { | ||
this.transport.authorization = token; | ||
} | ||
case 5: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6, this); | ||
})); | ||
return function updateTransportAuthorization() { | ||
return _updateTransportAuthorization.apply(this, arguments); | ||
}; | ||
}() | ||
/** | ||
@@ -1328,2 +1377,3 @@ * Fetch data for passed `query`. | ||
* In the development mode, Cube.js Backend will print the API token to the console on on startup. | ||
* Can be an async function without arguments that returns API token. | ||
* @param options - options object. | ||
@@ -1330,0 +1380,0 @@ * @param options.apiUrl - URL of your Cube.js Backend. |
{ | ||
"name": "@cubejs-client/core", | ||
"version": "0.11.7", | ||
"version": "0.11.9", | ||
"description": "cube.js client", | ||
@@ -30,3 +30,3 @@ "main": "dist/cubejs-client-core.js", | ||
}, | ||
"gitHead": "79d226fbff8946c1354f3b24745ce66893556ca1" | ||
"gitHead": "693b6fd46c1da37e6cc5050dc5629ae8ee2e5ce6" | ||
} |
@@ -38,3 +38,6 @@ /** | ||
this.apiUrl = options.apiUrl || API_URL; | ||
this.transport = options.transport || new HttpTransport({ authorization: apiToken, apiUrl: this.apiUrl }); | ||
this.transport = options.transport || new HttpTransport({ | ||
authorization: typeof apiToken === 'function' ? undefined : apiToken, | ||
apiUrl: this.apiUrl | ||
}); | ||
this.pollInterval = options.pollInterval || 5; | ||
@@ -61,3 +64,3 @@ } | ||
const requestInstance = request(); | ||
const requestPromise = this.updateTransportAuthorization().then(() => request()); | ||
@@ -67,2 +70,4 @@ let unsubscribed = false; | ||
const checkMutex = async () => { | ||
const requestInstance = await requestPromise; | ||
if (options.mutexObj && options.mutexObj[mutexKey] !== mutexValue) { | ||
@@ -78,2 +83,4 @@ unsubscribed = true; | ||
const loadImpl = async (response, next) => { | ||
const requestInstance = await requestPromise; | ||
const subscribeNext = async () => { | ||
@@ -101,8 +108,3 @@ if (options.subscribe && !unsubscribed) { | ||
if (typeof this.apiToken === 'function') { | ||
const token = await this.apiToken(); | ||
if (this.transport.authorization !== token) { | ||
this.transport.authorization = token; | ||
} | ||
} | ||
await this.updateTransportAuthorization(); | ||
@@ -149,3 +151,3 @@ if (response.status === 502) { | ||
const promise = mutexPromise(requestInstance.subscribe(loadImpl)); | ||
const promise = requestPromise.then(requestInstance => mutexPromise(requestInstance.subscribe(loadImpl))); | ||
@@ -155,2 +157,4 @@ if (callback) { | ||
unsubscribe: async () => { | ||
const requestInstance = await requestPromise; | ||
unsubscribed = true; | ||
@@ -168,2 +172,11 @@ if (requestInstance.unsubscribe) { | ||
async updateTransportAuthorization() { | ||
if (typeof this.apiToken === 'function') { | ||
const token = await this.apiToken(); | ||
if (this.transport.authorization !== token) { | ||
this.transport.authorization = token; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -261,2 +274,3 @@ * Fetch data for passed `query`. | ||
* In the development mode, Cube.js Backend will print the API token to the console on on startup. | ||
* Can be an async function without arguments that returns API token. | ||
* @param options - options object. | ||
@@ -263,0 +277,0 @@ * @param options.apiUrl - URL of your Cube.js Backend. |
Sorry, the diff of this file is too big to display
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
607077
16535