caccl-send-request
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -12,2 +12,4 @@ /** | ||
* fails | ||
* @param [opts.sendCrossDomainCredentials=true if in development mode] if true, | ||
* send cross-domain credentials even if not in dev mode | ||
* @returns { body, status, headers } on success | ||
@@ -26,2 +28,3 @@ */ | ||
numRetries?: number; | ||
sendCrossDomainCredentials?: boolean; | ||
}) => Promise<{ | ||
@@ -28,0 +31,0 @@ body: any; |
@@ -60,4 +60,4 @@ "use strict"; | ||
var ErrorCode_1 = __importDefault(require("./ErrorCode")); | ||
// Check if we should send cross-domain credentials | ||
var sendCrossDomainCredentials = (process.env.NODE_ENV === 'development'); | ||
// Check if we're currently in developer mode | ||
var thisIsDev = (process.env.NODE_ENV === 'development'); | ||
/** | ||
@@ -74,9 +74,15 @@ * Sends and retries an http request | ||
* fails | ||
* @param [opts.sendCrossDomainCredentials=true if in development mode] if true, | ||
* send cross-domain credentials even if not in dev mode | ||
* @returns { body, status, headers } on success | ||
*/ | ||
var sendRequest = function (opts) { return __awaiter(void 0, void 0, void 0, function () { | ||
var numRetries, method, stringifiedParams, query, url, headers, data, response, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var sendCrossDomainCredentials, numRetries, method, stringifiedParams, query, url, headers, data, response, err_1; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
sendCrossDomainCredentials = !!(opts.sendCrossDomainCredentials | ||
|| thisIsDev | ||
|| ((_a = opts.headers) === null || _a === void 0 ? void 0 : _a.credentials) === 'include'); | ||
numRetries = (opts.numRetries ? opts.numRetries : 0); | ||
@@ -108,5 +114,5 @@ method = (opts.method || 'GET'); | ||
} | ||
_a.label = 1; | ||
_b.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, (0, axios_1.default)({ | ||
@@ -120,3 +126,3 @@ method: method, | ||
case 2: | ||
response = _a.sent(); | ||
response = _b.sent(); | ||
// Process response | ||
@@ -129,3 +135,3 @@ return [2 /*return*/, { | ||
case 3: | ||
err_1 = _a.sent(); | ||
err_1 = _b.sent(); | ||
// Axios throws an error if the request status indicates an error | ||
@@ -132,0 +138,0 @@ // sendRequest is supposed to resolve if the request went through, whether |
{ | ||
"name": "caccl-send-request", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "The default request sender used throughout the CACCL project.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -11,4 +11,4 @@ // Import libs | ||
// Check if we should send cross-domain credentials | ||
const sendCrossDomainCredentials = (process.env.NODE_ENV === 'development'); | ||
// Check if we're currently in developer mode | ||
const thisIsDev = (process.env.NODE_ENV === 'development'); | ||
@@ -26,2 +26,4 @@ /** | ||
* fails | ||
* @param [opts.sendCrossDomainCredentials=true if in development mode] if true, | ||
* send cross-domain credentials even if not in dev mode | ||
* @returns { body, status, headers } on success | ||
@@ -37,2 +39,3 @@ */ | ||
numRetries?: number, | ||
sendCrossDomainCredentials?: boolean, | ||
}, | ||
@@ -44,2 +47,9 @@ ): Promise<{ | ||
}> => { | ||
// Check if we should be including credentials | ||
const sendCrossDomainCredentials = !!( | ||
opts.sendCrossDomainCredentials | ||
|| thisIsDev | ||
|| opts.headers?.credentials === 'include' | ||
); | ||
// Set max number of retries if not defined | ||
@@ -46,0 +56,0 @@ const numRetries = (opts.numRetries ? opts.numRetries : 0); |
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
20430
421