akamai-edgegrid 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # RELEASE NOTES
2
2
 
3
+ ## 3.1.4 (Mar 24, 2022)
4
+
5
+ #### IMPROVEMENTS:
6
+ * Remove deprecated `moment` dependency
7
+
8
+ #### BUG FIXES
9
+ * Fix response when Content-Type is `application/gzip` ([#83](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/83))
10
+
3
11
  ## 3.1.3 (Feb 22, 2022)
4
12
 
5
13
  #### IMPROVEMENTS:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akamai-edgegrid",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,6 @@
26
26
  "dependencies": {
27
27
  "axios": "^0.26.0",
28
28
  "log4js": "^6.4.0",
29
- "moment": "^2.29.1",
30
29
  "uuid": "^8.3.2"
31
30
  },
32
31
  "devDependencies": {
package/src/api.js CHANGED
@@ -84,6 +84,9 @@ EdgeGrid.prototype.auth = function (req) {
84
84
  this.config.access_token,
85
85
  this.config.host
86
86
  );
87
+ if (req.headers['Accept'] === 'application/gzip') {
88
+ this.request["responseType"] = 'arraybuffer';
89
+ }
87
90
  return this;
88
91
  };
89
92
 
package/src/helpers.js CHANGED
@@ -13,14 +13,32 @@
13
13
  // limitations under the License.
14
14
 
15
15
  const crypto = require('crypto'),
16
- moment = require('moment'),
17
16
  logger = require('./logger'),
18
17
  path = require('path'),
19
18
  os = require('os');
20
19
 
20
+ function twoDigitNumberPad(number) {
21
+ return String(number).padStart(2, '0');
22
+ }
23
+
21
24
  module.exports = {
25
+ /**
26
+ * Create timestamp with format "yyyyMMddTHH:mm:ss+0000"
27
+ *
28
+ * @see https://developer.akamai.com/legacy/introduction/Client_Auth.html#authorizationheaderfields
29
+ */
22
30
  createTimestamp: function () {
23
- return moment().utc().format('YYYYMMDDTHH:mm:ss+0000');
31
+ const date = new Date(Date.now());
32
+
33
+ return date.getUTCFullYear() +
34
+ twoDigitNumberPad(date.getUTCMonth() + 1) +
35
+ twoDigitNumberPad(date.getUTCDate()) +
36
+ 'T' +
37
+ twoDigitNumberPad(date.getUTCHours()) + ':' +
38
+ twoDigitNumberPad(date.getUTCMinutes()) +
39
+ ':' +
40
+ twoDigitNumberPad(date.getUTCSeconds()) +
41
+ '+0000';
24
42
  },
25
43
 
26
44
  contentHash: function (request, maxBody) {
@@ -221,6 +221,33 @@ describe('Api', function () {
221
221
  assert.strictEqual(this.api.request.somethingArbitrary, 'someValue');
222
222
  });
223
223
  });
224
+
225
+ describe("when gzip response format is expected", function () {
226
+ beforeEach(function () {
227
+ this.api.auth({
228
+ path: '/foo',
229
+ headers: {
230
+ 'Accept': `application/gzip`
231
+ }
232
+ });
233
+ });
234
+
235
+ it('adds an Authorization header to the request it is passed', function () {
236
+ assert.strictEqual(typeof this.api.request.headers.Authorization === 'string', true);
237
+ });
238
+
239
+ it('ensures a default GET method', function () {
240
+ assert.strictEqual(this.api.request.method, 'GET');
241
+ });
242
+
243
+ it('ensures a default empty body', function () {
244
+ assert.strictEqual(this.api.request.body, '');
245
+ });
246
+
247
+ it('should return response as buffer', function () {
248
+ assert.strictEqual(this.api.request["responseType"], "arraybuffer");
249
+ });
250
+ });
224
251
  });
225
252
 
226
253
  describe('#send', function () {
@@ -0,0 +1,5 @@
1
+ {
2
+ "edgeworker-version": "1.0",
3
+ "description" : "Four Events"
4
+ }
5
+
package/test1/main.js ADDED
@@ -0,0 +1,15 @@
1
+ export function onClientRequest(request) {
2
+ request.addHeader('EW_CLIENT_REQ', 'Automation Client Req');
3
+ }
4
+
5
+ export function onClientResponse(request, response) {
6
+ response.addHeader('EW_CLIENT_RSP', 'Automation Client Rsp');
7
+ }
8
+
9
+ export function onOriginResponse(request, response) {
10
+ response.addHeader('EW_ORIGIN_RSP', 'Automation Origin Rsp');
11
+ }
12
+
13
+ export function onOriginRequest(request) {
14
+ request.addHeader('EW_ORIGIN_REQ', 'Automation Origin Req');
15
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "edgeworker-version": "1.0",
3
+ "description" : "Four Events"
4
+ }
5
+
@@ -0,0 +1,15 @@
1
+ export function onClientRequest(request) {
2
+ request.addHeader('EW_CLIENT_REQ', 'Automation Client Req');
3
+ }
4
+
5
+ export function onClientResponse(request, response) {
6
+ response.addHeader('EW_CLIENT_RSP', 'Automation Client Rsp');
7
+ }
8
+
9
+ export function onOriginResponse(request, response) {
10
+ response.addHeader('EW_ORIGIN_RSP', 'Automation Origin Rsp');
11
+ }
12
+
13
+ export function onOriginRequest(request) {
14
+ request.addHeader('EW_ORIGIN_REQ', 'Automation Origin Req');
15
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "edgeworker-version": "1.0",
3
+ "description" : "Four Events"
4
+ }
5
+
package/test5/main.js ADDED
@@ -0,0 +1,15 @@
1
+ export function onClientRequest(request) {
2
+ request.addHeader('EW_CLIENT_REQ', 'Automation Client Req');
3
+ }
4
+
5
+ export function onClientResponse(request, response) {
6
+ response.addHeader('EW_CLIENT_RSP', 'Automation Client Rsp');
7
+ }
8
+
9
+ export function onOriginResponse(request, response) {
10
+ response.addHeader('EW_ORIGIN_RSP', 'Automation Origin Rsp');
11
+ }
12
+
13
+ export function onOriginRequest(request) {
14
+ request.addHeader('EW_ORIGIN_REQ', 'Automation Origin Req');
15
+ }