diff --git a/lib/includes.polyfill.js b/lib/includes.polyfill.js new file mode 100644 index 0000000..6a50b25 --- /dev/null +++ b/lib/includes.polyfill.js @@ -0,0 +1,51 @@ +// https://tc39.github.io/ecma262/#sec-array.prototype.includes +if (!Array.prototype.includes) { + Object.defineProperty(Array.prototype, 'includes', { + value: function(searchElement, fromIndex) { + + if (this == null) { + throw new TypeError('"this" is null or not defined'); + } + + // 1. Let O be ? ToObject(this value). + var o = Object(this); + + // 2. Let len be ? ToLength(? Get(O, "length")). + var len = o.length >>> 0; + + // 3. If len is 0, return false. + if (len === 0) { + return false; + } + + // 4. Let n be ? ToInteger(fromIndex). + // (If fromIndex is undefined, this step produces the value 0.) + var n = fromIndex | 0; + + // 5. If n ≥ 0, then + // a. Let k be n. + // 6. Else n < 0, + // a. Let k be len + n. + // b. If k < 0, let k be 0. + var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); + + function sameValueZero(x, y) { + return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); + } + + // 7. Repeat, while k < len + while (k < len) { + // a. Let elementK be the result of ? Get(O, ! ToString(k)). + // b. If SameValueZero(searchElement, elementK) is true, return true. + if (sameValueZero(o[k], searchElement)) { + return true; + } + // c. Increase k by 1. + k++; + } + + // 8. Return false + return false; + } + }); + } diff --git a/lib/ovh.es5.js b/lib/ovh.es5.js index 98c51af..00e75a7 100644 --- a/lib/ovh.es5.js +++ b/lib/ovh.es5.js @@ -26,6 +26,9 @@ */ 'use strict'; +// String.includes polyfill +require('./includes.polyfill'); + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -51,6 +54,7 @@ var Ovh = function () { this.timeout = params.timeout; this.apiTimeDiff = params.apiTimeDiff || null; this.endpoint = params.endpoint || null; + this.noAuthPaths = params.noAuthPaths || ['/auth/credential', '/auth/time']; // Preconfigured API endpoints if (this.endpoint) { @@ -363,7 +367,7 @@ var Ovh = function () { } } - if (path.indexOf('/auth') < 0) { + if (!this.noAuthPaths.includes(path)) { options.headers['X-Ovh-Timestamp'] = Math.round(Date.now() / 1000) + this.apiTimeDiff; // Sign request diff --git a/lib/ovh.es6.js b/lib/ovh.es6.js index 3d0013b..bc3fe34 100644 --- a/lib/ovh.es6.js +++ b/lib/ovh.es6.js @@ -26,6 +26,9 @@ */ 'use strict'; +// String.includes polyfill +require('./includes.polyfill'); + let https = require('https'), Bluebird = require('bluebird'), querystring = require('querystring'), @@ -43,6 +46,7 @@ class Ovh { this.timeout = params.timeout; this.apiTimeDiff = params.apiTimeDiff || null; this.endpoint = params.endpoint || null; + this.noAuthPaths = params.noAuthPaths || ['/auth/credential', '/auth/time']; // Preconfigured API endpoints if (this.endpoint) { @@ -356,7 +360,7 @@ class Ovh { } } - if (path.indexOf('/auth') < 0) { + if (!this.noAuthPaths.includes(path)) { options.headers['X-Ovh-Timestamp'] = Math.round(Date.now() / 1000) + this.apiTimeDiff; // Sign request @@ -487,4 +491,4 @@ class Ovh { module.exports = function (params) { return new Ovh(params || {}); -}; \ No newline at end of file +};