akamai-edgegrid 3.1.4 → 3.3.0
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 +13 -0
- package/index.d.ts +33 -0
- package/index.test-d.ts +19 -0
- package/package.json +10 -6
- package/src/api.js +9 -10
- package/src/helpers.js +22 -1
- package/test/src/api_test.js +83 -1
- package/test1/bundle.json +0 -5
- package/test1/main.js +0 -15
- package/test1 2/bundle.json +0 -5
- package/test1 2/main.js +0 -15
- package/test5/bundle.json +0 -5
- package/test5/main.js +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# RELEASE NOTES
|
|
2
2
|
|
|
3
|
+
## 3.3.0 (Nov 08, 2022)
|
|
4
|
+
|
|
5
|
+
#### IMPROVEMENTS:
|
|
6
|
+
* Update various dependencies
|
|
7
|
+
|
|
8
|
+
#### BUG FIXES
|
|
9
|
+
* Fix adding `User-Agent` header to the request
|
|
10
|
+
|
|
11
|
+
## 3.2.0 (Apr 26, 2022)
|
|
12
|
+
|
|
13
|
+
#### IMPROVEMENTS:
|
|
14
|
+
* Add Typescript declaration file ([#71](https://github.com/akamai/AkamaiOPEN-edgegrid-node/issues/71))
|
|
15
|
+
|
|
3
16
|
## 3.1.4 (Mar 24, 2022)
|
|
4
17
|
|
|
5
18
|
#### IMPROVEMENTS:
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse } from "axios";
|
|
2
|
+
|
|
3
|
+
declare class EdgeGrid {
|
|
4
|
+
constructor(clientTokenOrOptions: string | object,
|
|
5
|
+
clientSecret?: string,
|
|
6
|
+
accessToken?: string,
|
|
7
|
+
host?: string,
|
|
8
|
+
debug?: boolean);
|
|
9
|
+
|
|
10
|
+
request: object;
|
|
11
|
+
config: object;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sends the request and invokes the callback function.
|
|
15
|
+
*
|
|
16
|
+
* @param {Function} callback The callback function.
|
|
17
|
+
* @return EdgeGrid object (self)
|
|
18
|
+
*/
|
|
19
|
+
send(callback: (error: AxiosError, response?: AxiosResponse, body?: string) => void): EdgeGrid;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Builds the request using the properties of the local config Object.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} req The request Object. Can optionally contain a
|
|
25
|
+
* 'headersToSign' property: An ordered list header names
|
|
26
|
+
* that will be included in the signature. This will be
|
|
27
|
+
* provided by specific APIs.
|
|
28
|
+
* @return EdgeGrid object (self)
|
|
29
|
+
*/
|
|
30
|
+
auth(req: object): EdgeGrid;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export = EdgeGrid;
|
package/index.test-d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expectType } from 'tsd';
|
|
2
|
+
import EdgeGrid = require('.')
|
|
3
|
+
|
|
4
|
+
const eg = new EdgeGrid({
|
|
5
|
+
path: '/path/to/.edgerc',
|
|
6
|
+
section: 'section-name'
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
expectType<EdgeGrid>(eg)
|
|
10
|
+
|
|
11
|
+
var req = {
|
|
12
|
+
path: '/diagnostic-tools/v1/locations',
|
|
13
|
+
method: 'GET',
|
|
14
|
+
headers: {},
|
|
15
|
+
body: 'bodyData'
|
|
16
|
+
}
|
|
17
|
+
expectType<EdgeGrid>(eg.auth(req))
|
|
18
|
+
|
|
19
|
+
expectType<EdgeGrid>(eg.send((error, resp, body) => console.log(body)))
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akamai-edgegrid",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "EDGEGRID_ENV=test ./node_modules/.bin/mocha $(find test -name '*.js')"
|
|
7
|
+
"test": "EDGEGRID_ENV=test ./node_modules/.bin/mocha $(find test -name '*.js')",
|
|
8
|
+
"ci": "EDGEGRID_ENV=test MOCHA_FILE=./test/tests.xml nyc --reporter cobertura --report-dir test/coverage/ ./node_modules/.bin/mocha --reporter mocha-junit-reporter --reporter-options jenkinsMode=true --reporter-options antMode=true $(find test -name '*.js')"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -24,12 +25,15 @@
|
|
|
24
25
|
],
|
|
25
26
|
"license": "Apache-2.0",
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"axios": "^
|
|
28
|
+
"axios": "^1.1.2",
|
|
28
29
|
"log4js": "^6.4.0",
|
|
29
|
-
"uuid": "^
|
|
30
|
+
"uuid": "^9.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"mocha": "^
|
|
33
|
-
"
|
|
33
|
+
"mocha": "^10.0.0",
|
|
34
|
+
"mocha-junit-reporter": "^2.1.0",
|
|
35
|
+
"nock": "^13.2.2",
|
|
36
|
+
"nyc": "^15.1.0",
|
|
37
|
+
"tsd": "^0.24.1"
|
|
34
38
|
}
|
|
35
39
|
}
|
package/src/api.js
CHANGED
|
@@ -48,24 +48,17 @@ const EdgeGrid = function (client_token, client_secret, access_token, host, debu
|
|
|
48
48
|
* @return EdgeGrid object (self)
|
|
49
49
|
*/
|
|
50
50
|
EdgeGrid.prototype.auth = function (req) {
|
|
51
|
-
let headers = {
|
|
52
|
-
'Content-Type': "application/json"
|
|
53
|
-
};
|
|
54
|
-
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
|
|
55
|
-
headers['User-Agent'] = (headers['User-Agent'] ? headers['User-Agent'] + " " : "") + `AkamaiCLI/${process.env['AKAMAI_CLI_VERSION']}`;
|
|
56
|
-
}
|
|
57
|
-
if (process.env['AKAMAI_CLI_COMMAND'] && process.env['AKAMAI_CLI_COMMAND_VERSION']) {
|
|
58
|
-
headers['User-Agent'] = (headers['User-Agent'] ? headers['User-Agent'] + " " : "") + `AkamaiCLI-${process.env['AKAMAI_CLI_COMMAND']}/${process.env['AKAMAI_CLI_COMMAND_VERSION']}`;
|
|
59
|
-
}
|
|
60
51
|
req = helpers.extend(req, {
|
|
61
52
|
baseURL: this.config.host,
|
|
62
53
|
url: req.path,
|
|
63
54
|
method: 'GET',
|
|
64
|
-
headers:
|
|
55
|
+
headers: {},
|
|
65
56
|
maxRedirects: 0,
|
|
66
57
|
body: ''
|
|
67
58
|
});
|
|
68
59
|
|
|
60
|
+
req.headers = helpers.extendHeaders(req.headers)
|
|
61
|
+
|
|
69
62
|
let isTarball = req.body instanceof Uint8Array && req.headers['Content-Type'] === 'application/gzip';
|
|
70
63
|
|
|
71
64
|
// Convert body object to properly formatted string
|
|
@@ -90,6 +83,12 @@ EdgeGrid.prototype.auth = function (req) {
|
|
|
90
83
|
return this;
|
|
91
84
|
};
|
|
92
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Sends the request and invokes the callback function.
|
|
88
|
+
*
|
|
89
|
+
* @param {Function} callback The callback function.
|
|
90
|
+
* @return EdgeGrid object (self)
|
|
91
|
+
*/
|
|
93
92
|
EdgeGrid.prototype.send = function (callback) {
|
|
94
93
|
axios(this.request).then(response => {
|
|
95
94
|
callback(null, response, JSON.stringify(response.data));
|
package/src/helpers.js
CHANGED
|
@@ -108,7 +108,7 @@ module.exports = {
|
|
|
108
108
|
return dataToSignStr;
|
|
109
109
|
},
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
extend: function (a, b) {
|
|
112
112
|
let key;
|
|
113
113
|
|
|
114
114
|
for (key in b) {
|
|
@@ -120,6 +120,27 @@ module.exports = {
|
|
|
120
120
|
return a;
|
|
121
121
|
},
|
|
122
122
|
|
|
123
|
+
extendHeaders: function (headers) {
|
|
124
|
+
if (!headers.hasOwnProperty('Content-Type')) {
|
|
125
|
+
headers['Content-Type'] = "application/json";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let userAgents = [headers['User-Agent']];
|
|
129
|
+
if (process.env['AKAMAI_CLI'] && process.env['AKAMAI_CLI_VERSION']) {
|
|
130
|
+
userAgents.push(`AkamaiCLI/${process.env['AKAMAI_CLI_VERSION']}`);
|
|
131
|
+
}
|
|
132
|
+
if (process.env['AKAMAI_CLI_COMMAND'] && process.env['AKAMAI_CLI_COMMAND_VERSION']) {
|
|
133
|
+
userAgents.push(`AkamaiCLI-${process.env['AKAMAI_CLI_COMMAND']}/${process.env['AKAMAI_CLI_COMMAND_VERSION']}`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
userAgents = userAgents.filter(v => v)
|
|
137
|
+
if (userAgents.length > 0) {
|
|
138
|
+
headers['User-Agent'] = userAgents.join(' ')
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return headers;
|
|
142
|
+
},
|
|
143
|
+
|
|
123
144
|
isRedirect: function (statusCode) {
|
|
124
145
|
return [
|
|
125
146
|
300, 301, 302, 303, 307
|
package/test/src/api_test.js
CHANGED
|
@@ -186,6 +186,10 @@ describe('Api', function () {
|
|
|
186
186
|
it('ensures a url is properly declared', function () {
|
|
187
187
|
assert.strictEqual(this.api.request.url, 'https://base.com/foo');
|
|
188
188
|
});
|
|
189
|
+
|
|
190
|
+
it('ensures no User-Agent is added when AkamaiCLI env variables not set', function () {
|
|
191
|
+
assert.ok(!this.api.request.headers.hasOwnProperty('User-Agent'));
|
|
192
|
+
})
|
|
189
193
|
});
|
|
190
194
|
|
|
191
195
|
describe('when more specific request options are passed', function () {
|
|
@@ -196,7 +200,10 @@ describe('Api', function () {
|
|
|
196
200
|
body: {
|
|
197
201
|
foo: 'bar'
|
|
198
202
|
},
|
|
199
|
-
somethingArbitrary: 'someValue'
|
|
203
|
+
somethingArbitrary: 'someValue',
|
|
204
|
+
headers: {
|
|
205
|
+
'User-Agent': 'testUserAgent'
|
|
206
|
+
}
|
|
200
207
|
});
|
|
201
208
|
});
|
|
202
209
|
|
|
@@ -220,6 +227,10 @@ describe('Api', function () {
|
|
|
220
227
|
it('extends the default request options with any others specified', function () {
|
|
221
228
|
assert.strictEqual(this.api.request.somethingArbitrary, 'someValue');
|
|
222
229
|
});
|
|
230
|
+
|
|
231
|
+
it('ensures provided User-Agent header is preserved', function () {
|
|
232
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'testUserAgent');
|
|
233
|
+
});
|
|
223
234
|
});
|
|
224
235
|
|
|
225
236
|
describe("when gzip response format is expected", function () {
|
|
@@ -248,6 +259,77 @@ describe('Api', function () {
|
|
|
248
259
|
assert.strictEqual(this.api.request["responseType"], "arraybuffer");
|
|
249
260
|
});
|
|
250
261
|
});
|
|
262
|
+
|
|
263
|
+
describe("when akamai cli user agent is expected", function () {
|
|
264
|
+
beforeEach(function () {
|
|
265
|
+
process.env['AKAMAI_CLI'] = 'AkamaiCLI';
|
|
266
|
+
process.env['AKAMAI_CLI_VERSION'] = '1.0.0';
|
|
267
|
+
process.env['AKAMAI_CLI_COMMAND'] = 'command';
|
|
268
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '0.0.1';
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
afterEach(function () {
|
|
272
|
+
process.env['AKAMAI_CLI'] = '';
|
|
273
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
274
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
275
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
describe("when no User-Agent set in the request", function () {
|
|
279
|
+
beforeEach(function () {
|
|
280
|
+
this.api.auth({
|
|
281
|
+
path: '/foo'
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("should set User-Agent", function () {
|
|
286
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("when User-Agent is already in the request", function () {
|
|
291
|
+
beforeEach(function () {
|
|
292
|
+
this.api.auth({
|
|
293
|
+
path: '/foo',
|
|
294
|
+
headers: {
|
|
295
|
+
'User-Agent': 'testAgent'
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should append to already present User-Agent header", function () {
|
|
301
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'testAgent AkamaiCLI/1.0.0 AkamaiCLI-command/0.0.1');
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("when only AkamaiCLI info is set", function () {
|
|
306
|
+
beforeEach(function () {
|
|
307
|
+
process.env['AKAMAI_CLI_COMMAND'] = '';
|
|
308
|
+
process.env['AKAMAI_CLI_COMMAND_VERSION'] = '';
|
|
309
|
+
this.api.auth({
|
|
310
|
+
path: '/foo'
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
315
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI/1.0.0');
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("when only AkamaiCLI command info is set", function () {
|
|
320
|
+
beforeEach(function () {
|
|
321
|
+
process.env['AKAMAI_CLI'] = '';
|
|
322
|
+
process.env['AKAMAI_CLI_VERSION'] = '';
|
|
323
|
+
this.api.auth({
|
|
324
|
+
path: '/foo'
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should only set AkamaiCLI/version User-Agent", function () {
|
|
329
|
+
assert.strictEqual(this.api.request.headers['User-Agent'], 'AkamaiCLI-command/0.0.1');
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
251
333
|
});
|
|
252
334
|
|
|
253
335
|
describe('#send', function () {
|
package/test1/bundle.json
DELETED
package/test1/main.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
package/test1 2/bundle.json
DELETED
package/test1 2/main.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
package/test5/bundle.json
DELETED
package/test5/main.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|