diff --git a/package-lock.json b/package-lock.json index cd3ea0c..350be3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@agility/content-fetch", - "version": "0.8.0", + "version": "0.8.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2656,7 +2656,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2677,12 +2678,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2697,17 +2700,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -2824,7 +2830,8 @@ "inherits": { "version": "2.0.4", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -2836,6 +2843,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2850,6 +2858,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2857,12 +2866,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2881,6 +2892,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2970,7 +2982,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2982,6 +2995,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3067,7 +3081,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -3103,6 +3118,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3122,6 +3138,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3165,12 +3182,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index 01581f2..26b6048 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "dist/agility-content-fetch.node.js", "scripts": { "test": "nyc --reporter=html --reporter=text mocha --require @babel/register --recursive ./test/", + "test-r": "nyc --reporter=html --reporter=text mocha --require @babel/register --recursive ./test/getUrlRedirections.tests.js", "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose", "build": "webpack --config webpack.config -p" }, diff --git a/src/api-client.js b/src/api-client.js index 0c8fd25..2d16d64 100644 --- a/src/api-client.js +++ b/src/api-client.js @@ -83,9 +83,13 @@ export default function createClient(userConfig) { adapter = cache.adapter; } + const https= require("https") //create apply the adapter to our axios instance const api = axios.create({ + httpsAgent: new https.Agent({ + rejectUnauthorized: false + }), adapter: adapter, }) @@ -107,16 +111,7 @@ export default function createClient(userConfig) { data['fromCache'] = true; } - if (! reqConfig.returnHeaders) { - //if they just wanted the data... - return data; - } else { - //if they indicated they wanted the headers as well as the data... - return { - headers: response.headers, - data - } - } + return data; }) diff --git a/src/methods/getUrlRedirections.js b/src/methods/getUrlRedirections.js index f317b8c..ea28aa1 100644 --- a/src/methods/getUrlRedirections.js +++ b/src/methods/getUrlRedirections.js @@ -34,6 +34,11 @@ function getUrlRedirections(requestParams) { let url = ""; if (requestParams.lastAccessDate) { + + if (! requestParams.lastAccessDate.toISOString) { + requestParams.lastAccessDate = new Date(requestParams.lastAccessDate); + } + url = `/?lastAccessDate=${requestParams.lastAccessDate.toISOString()}` } @@ -43,35 +48,22 @@ function getUrlRedirections(requestParams) { method: 'get', baseURL: buildRequestUrlPath(this.config, 'urlredirection'), headers: buildAuthHeader(this.config), - params: {}, - returnHeaders: true + params: {} }; const self = this; let promise = new Promise(function (resolve, reject) { self.makeRequest(req) - .then(response => { + .then(data => { - if (response == undefined || ! response) { + if (data == undefined || ! data) { reject(new Error("The URL redirections could not be retrieved.")); } else { - - const {headers, data} = response; - - //pull the lastAccessDate from the header - let lastAccessDate = null; - if (headers) { - let dateStr = headers["x-lastaccessdate"]; - if (dateStr) lastAccessDate = new Date(dateStr); - } - - //return an object with items and lastAccessDate - resolve({ lastAccessDate, items: data }); + resolve(data); } }) .catch(error => { - console.log("error in url redir") reject(error); } ); @@ -81,8 +73,15 @@ function getUrlRedirections(requestParams) { function validateRequestParams(requestParams) { - if (requestParams.lastAccessDate && ! requestParams.lastAccessDate.toISOString) { - throw new TypeError('You must include a valid Datetime for the lastAccessDate.'); + if (requestParams.lastAccessDate) { + + if (! requestParams.lastAccessDate.toISOString) { + let dt = new Date(requestParams.lastAccessDate); + + if (isNaN(dt)) { + throw new TypeError('You must include a valid Datetime for the lastAccessDate.'); + } + } } else { return; } diff --git a/src/types/UrlRedirection.js b/src/types/UrlRedirection.js new file mode 100644 index 0000000..a3100ee --- /dev/null +++ b/src/types/UrlRedirection.js @@ -0,0 +1,11 @@ + /** + * Defines **URL Redirection** . + * @typedef URLRedirection + * @memberof AgilityFetch.Types + * @property {Number} id - The id of this URL Redirection + * @property {String} originUrl - The URL to redirect from + * @property {String} destinationUrl - The URL to redirect to + * @property {Number} statusCode - Either a 301 or 302 status code for the redirect + */ + + diff --git a/src/types/UrlRedirectionResponse.js b/src/types/UrlRedirectionResponse.js new file mode 100644 index 0000000..b11e41c --- /dev/null +++ b/src/types/UrlRedirectionResponse.js @@ -0,0 +1,9 @@ + /** + * Defines **URL Redirection** response. + * @typedef URLRedirectionResponse + * @memberof AgilityFetch.Types + * @property {Array} syncToken - The sync token to be used in the next call as a continuation token for syncing content. If this is empty, you are up to date. + * @property {Array.} items - The paginated array of items returned by the request. + */ + + diff --git a/test/apiClients.config.js b/test/apiClients.config.js index ff45764..3133364 100644 --- a/test/apiClients.config.js +++ b/test/apiClients.config.js @@ -5,6 +5,7 @@ const guid = 'c741222b-1080-45f6-9a7f-982381c5a485'; const apiKeyFetch = 'UnitTestsFetch.2ace650991363fbcffa6776d411d1b0d616b8e3424ce842b81cba7af0039197e'; const apiKeyPreview = 'UnitTestsPreview.69e6bca345ced0b7ca5ab358b351ea5c870790a5945c25d749a865332906b124'; + function createApiClient() { var api = agility.getApi({ guid: guid, diff --git a/test/getContentList.tests.js b/test/getContentList.tests.js index 4ecb63e..9dacc08 100644 --- a/test/getContentList.tests.js +++ b/test/getContentList.tests.js @@ -3,7 +3,7 @@ const assert = chai.assert; const expect = chai.expect; import { createApiClient, createPreviewApiClient, createCatchedApiClient } from './apiClients.config' -/* +/* This file contains static references to content from the instance configured in the apiClient.config file. */ @@ -26,7 +26,7 @@ describe('getContentList:', function() { }) .catch(done); }); - + it('should retrieve a content list in preview mode', function(done) { var api = createPreviewApiClient(); api.getContentList({ @@ -40,7 +40,7 @@ describe('getContentList:', function() { }) .catch(done); }); - + it('should throw error if referenceName not passed as argument for getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -57,7 +57,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if languageCode param is missing in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -73,7 +73,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if take parameter is NOT a number in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -91,7 +91,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if take parameter is a number less than 1 in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -109,7 +109,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if take parameter is a number greater than 50 in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -127,7 +127,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if skip parameter is a number less than 0 in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -145,7 +145,7 @@ describe('getContentList:', function() { }).to.throw( TypeError ); done(); }); - + it('should throw error if skip parameter is NOT a number in getContentList', function(done) { expect(function() { var api = createApiClient(); @@ -192,8 +192,7 @@ describe('getContentList:', function() { direction: api.types.SortDirections.DESC }) .then(function(contentList) { - assert.strictEqual(contentList.items[0].contentID, 16); - assert.strictEqual(contentList.items[1].contentID, 15); + assert.isTrue(contentList.items[0].contentID > contentList.items[1].contentID); done(); }) .catch(done); diff --git a/test/getUrlRedirections.tests.js b/test/getUrlRedirections.tests.js index cb62ad0..1304791 100644 --- a/test/getUrlRedirections.tests.js +++ b/test/getUrlRedirections.tests.js @@ -22,11 +22,16 @@ describe('getUrlRedirections:', function() { api.getUrlRedirections({ lastAccessDate: null }) - .then(function({lastAccessDate, items}) { + .then(function({ lastAccessDate, isUpToDate, items }) { assert.isArray(items, "the items should be an array."); - assert.isDefined(lastAccessDate.getUTCFullYear, "the lastAccessDate should be a date object."); - assert.isTrue(lastAccessDate.getUTCFullYear() > 2000, "the lastAccessDate should be a recent date.") + + assert.isFalse(isUpToDate, "the results should NOT be up to date" ) + assert.isDefined(lastAccessDate, "the lastAccessDate should be a returned."); + + let dt = new Date(lastAccessDate); + + assert.isTrue(dt.getUTCFullYear() > 2000, "the lastAccessDate should be a recent date.") persistedLastAccessDate = lastAccessDate; @@ -40,10 +45,10 @@ describe('getUrlRedirections:', function() { api.getUrlRedirections({ lastAccessDate: persistedLastAccessDate }) - .then(function({lastAccessDate, items}) { + .then(function({lastAccessDate, items, isUpToDate}) { assert.isArray(items, "the items should be an array."); - + assert.isTrue(isUpToDate, "the results should be up to date" ) assert.equal(items.length, 0, "the list of items should be empty.") done();