Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws4-axios

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws4-axios - npm Package Compare versions

Comparing version 1.8.0 to 1.9.0

32

dist/__tests__/apiGateway.it.js

@@ -172,2 +172,34 @@ "use strict";

}); });
it("sets content type as application/json when the body is an object", function () { return __awaiter(_this, void 0, void 0, function () {
var client, data, message, result, err_5;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
client = axios_1.default.create();
data = {
foo: "bar"
};
client.interceptors.request.use(__1.interceptor({ region: "eu-west-2", service: "execute-api" }));
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, client.request({
url: apiGateway,
method: "POST",
data: data
})];
case 2:
result = _a.sent();
return [3 /*break*/, 4];
case 3:
err_5 = _a.sent();
message = __2.getAuthErrorMessage(err_5);
return [3 /*break*/, 4];
case 4:
expect(message).toBe(undefined);
expect(result && result.status).toEqual(200);
return [2 /*return*/];
}
});
}); });
});

@@ -77,2 +77,43 @@ "use strict";

}); });
it("should preserve default headers - without interceptor", function () { return __awaiter(_this, void 0, void 0, function () {
var client, data, url, request;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
client = axios_1.default.create();
data = { foo: "bar" };
url = "https://localhost/foo";
moxios_1.default.stubOnce("POST", url, {});
// Act
return [4 /*yield*/, client.post(url, data, {})];
case 1:
// Act
_a.sent();
request = moxios_1.default.requests.first();
expect(request.headers["Content-Type"]).toEqual("application/json;charset=utf-8");
return [2 /*return*/];
}
});
}); });
it("should preserve default headers - with interceptor", function () { return __awaiter(_this, void 0, void 0, function () {
var client, data, url, request;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
client = axios_1.default.create();
client.interceptors.request.use(_1.default({ region: "local" }));
data = { foo: "bar" };
url = "https://localhost/foo";
moxios_1.default.stubOnce("POST", url, {});
// Act
return [4 /*yield*/, client.post(url, data, {})];
case 1:
// Act
_a.sent();
request = moxios_1.default.requests.first();
expect(request.headers["Content-Type"]).toEqual("application/json;charset=utf-8");
return [2 /*return*/];
}
});
}); });
});

22

dist/interceptor.js

@@ -24,4 +24,8 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var aws4_1 = require("aws4");
var axios_1 = __importDefault(require("axios"));
var url_1 = require("url");

@@ -51,2 +55,4 @@ /**

}
var transformRequest = getTransformer();
var transformedData = transformRequest(data, headers);
// Remove all the default Axios headers

@@ -56,3 +62,3 @@ var common = headers.common, _delete = headers.delete, // 'delete' is a reserved word

var signingOptions = __assign({ method: method && method.toUpperCase(), host: host, path: pathname + search, region: region,
service: service }, (signQuery !== undefined ? { signQuery: signQuery } : {}), { body: getBody(data), headers: headersToSign });
service: service }, (signQuery !== undefined ? { signQuery: signQuery } : {}), { body: transformedData, headers: headersToSign });
aws4_1.sign(signingOptions);

@@ -62,7 +68,13 @@ config.headers = __assign({}, signingOptions.headers, config.headers);

}; };
var getBody = function (data) {
if (typeof data === "string") {
return data;
var getTransformer = function () {
var transformRequest = axios_1.default.defaults.transformRequest;
if (transformRequest) {
if (typeof transformRequest === "function") {
return transformRequest;
}
else if (transformRequest.length) {
return transformRequest[0];
}
}
return JSON.stringify(data);
throw new Error("Could not get default transformRequest function from Axios defaults");
};

@@ -99,3 +99,3 @@ "use strict";

body: '{"foo":"bar"}',
headers: {}
headers: { "Content-Type": "application/json;charset=utf-8" }
});

@@ -102,0 +102,0 @@ });

{
"name": "aws4-axios",
"version": "1.8.0",
"version": "1.9.0",
"description": "Axios request interceptor for signing requests with AWSv4",

@@ -5,0 +5,0 @@ "author": "James Bourne",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc