Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXE-2065 Release/v3.4.0 #134

Merged
merged 9 commits into from
Jan 26, 2023
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ node_modules
.DS_Store
.AppleDouble
.LSOverride
/.nyc_output/
/.idea/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# RELEASE NOTES

## 3.4.0 (Jan 26, 2023)

#### IMPROVEMENTS:
* Reads 'max_body' (alias 'max-body') field from `.edgerc` config file with default value of `131072` ([PR#1](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/1))
* Add default Accept header (related to [PR#43](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/43)
and [I#33](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/33))
* Add README section explaining how to use proxy (related to [PR#35](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/35)
and [I#59](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/59))
* Add README section explaining how to change request encoding (related to [PR#58](https://github.com/akamai/AkamaiOPEN-edgegrid-node/pull/58))
* Update various dependencies

## 3.3.0 (Nov 08, 2022)

#### IMPROVEMENTS:
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,62 @@ eg.auth({
// https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/papi/v1/cpcodes?contractId=ctr_1234&groupId=grp_1234
```

### Encoding

When interacting with binary data, such as during retrieval of PDF invoices, `responseType` should be specified as `arraybuffer` during the `auth` method call. Omission of `responseType` will cause an unreadable or blank response.

```javascript
const fs = require('fs');

eg.auth({
path : `/invoicing-api/v2/contracts/${contractId}/invoices/${invoiceNumber}/files/${fileName}`,
method: 'GET',
responseType: 'arraybuffer', // Important
}).send((err, response) => {
if (err) {
return console.log(err);
}
fs.writeFile(`./${fileName}`, response.data, 'binary', (err) => {
if (err){
return console.log(err);
}
console.log('File was saved!');
});
});
```

### Proxy
To use edgegrid with proxy, you can configure it with `proxy` field:

```javascript
eg.auth({
path : `/papi/v1/cpcodes`,
method: 'GET',
proxy: {
host: 'my.proxy.com',
protocol: "https",
port: 3128,
auth: {
username: 'my-user',
password: 'my-password'
}
}
}).send((err, response) => {
if (err) {
return console.log(err);
}
console.log('Success!');
// Do something with response
});
```

or use environment variable:

```shell
$ export https_proxy=https://username:password@host:port
$ node myapp.js
```

### Debug

With EdgeGrid you can enable debugging either as part of the EdgeGrid instantiation object
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akamai-edgegrid",
"version": "3.3.0",
"version": "3.4.0",
"description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
"main": "index.js",
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ EdgeGrid.prototype.auth = function (req) {
body: ''
});

req.headers = helpers.extendHeaders(req.headers)
req.headers = helpers.extendHeaders(req.headers);

let isTarball = req.body instanceof Uint8Array && req.headers['Content-Type'] === 'application/gzip';
let isTarball = req.body instanceof Uint8Array &&
(req.headers['Content-Type'] === 'application/gzip' || req.headers['Content-Type'] === 'application/tar+gzip');

// Convert body object to properly formatted string
if (req.body) {
Expand All @@ -77,7 +78,7 @@ EdgeGrid.prototype.auth = function (req) {
this.config.access_token,
this.config.host
);
if (req.headers['Accept'] === 'application/gzip') {
if (req.headers['Accept'] === 'application/gzip' || req.headers['Accept'] === 'application/tar+gzip') {
this.request["responseType"] = 'arraybuffer';
}
return this;
Expand Down
1 change: 0 additions & 1 deletion src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function makeURL(host, path, queryStringObj) {

module.exports = {
generateAuth: function (request, clientToken, clientSecret, accessToken, host, maxBody, guid, timestamp) {
maxBody = maxBody || 131072;
guid = guid || uuid.v4();
timestamp = timestamp || helpers.createTimestamp();

Expand Down
5 changes: 5 additions & 0 deletions src/edgerc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function getSection(lines, sectionName) {

function validatedConfig(config) {

config.max_body = config.max_body || 131072

if (!(config.host && config.access_token &&
config.client_secret && config.client_token)) {
let errorMessage = "";
Expand Down Expand Up @@ -78,6 +80,9 @@ function buildObj(configs) {
index = config.indexOf('=');
if (index > -1 && !isComment) {
key = config.substr(0, index);
if (key.startsWith("max-body")) {
key = key.replace('-', '_')
}
val = config.substring(index + 1);
// remove inline comments
parsedValue = val.replace(/^\s*(['"])((?:\\\1|.)*?)\1\s*(?:;.*)?$/, "$2");
Expand Down
5 changes: 4 additions & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = {
return dataToSignStr;
},

extend: function (a, b) {
extend: function (a, b) {
let key;

for (key in b) {
Expand All @@ -124,6 +124,9 @@ module.exports = {
if (!headers.hasOwnProperty('Content-Type')) {
headers['Content-Type'] = "application/json";
}
if (!headers.hasOwnProperty('Accept')) {
headers['Accept'] = "application/json";
}

let userAgents = [headers['User-Agent']];
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
Expand Down
Loading