Skip to content

Commit ebbb047

Browse files
authored
Merge pull request #95 from route4me/1.0.27
Updated "superagent" dependency to v8.0.9.
2 parents a974dd5 + d7944ee commit ebbb047

File tree

4 files changed

+11
-243
lines changed

4 files changed

+11
-243
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "route4me-nodejs-sdk",
3-
"version": "1.0.25",
3+
"version": "1.0.27",
44
"description": "Access Route4Me's logistics-as-a-service API using our Node.js SDK",
55
"main": "src/index.js",
66
"browser": "src/route4me.js",
@@ -57,12 +57,11 @@
5757
},
5858
"homepage": "http://route4me.com",
5959
"dependencies": {
60-
"cookiejar": "^2.1.3",
6160
"debug": "^4.3.2",
6261
"del": "^6.0.0",
6362
"platform": "^1.3.6",
6463
"qs": "^6.10.3",
65-
"superagent": "^7.1.1"
64+
"superagent": "^8.0.9"
6665
},
6766
"devDependencies": {
6867
"ajv": "^6.12.6",

src/request-manager.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict"
22

33
const request = require("superagent")
4+
const qstr = require("qs")
45
const errors = require("./errors")
5-
const utils = require("./utils")
66

77
class ResponseHandler {
88
constructor(PromiseConstructor, logger, validate, validateContext, callback, returns) {
@@ -247,11 +247,7 @@ class RequestManager {
247247
.timeout(timeouts)
248248
.redirects(1000) // unlimited number of redirects
249249
.accept("application/json")
250-
.query(qs)
251-
252-
if (options.indices) {
253-
utils.patchRequest.bind(req)(req)
254-
}
250+
.query(options.indices ? qstr.stringify(qs, { arrayFormat: "indices" }) : qs)
255251

256252
if (form) {
257253
req.type("multipart/form-data")

src/utils.js

-227
Original file line numberDiff line numberDiff line change
@@ -218,233 +218,6 @@ function toIsoDateString(d) {
218218
return d.toISOString().substring(0, 10)
219219
}
220220

221-
// ( added by 0x000f, 20220910
222-
// bc superagent has hardcoded "indices: false" it prevent to have array indexes in query string
223-
// also added dependencies to project 'cookiejar' and 'qs'
224-
// use in request-manager.js RequestManager._makeRequest()
225-
226-
/* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
227-
global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
228-
no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
229-
function patchRequest(Request) {
230-
const parse = require("url").parse
231-
const qs = require("qs")
232-
const https = require("https")
233-
const http = require("http")
234-
const CookieJar = require("cookiejar")
235-
236-
const exports = {
237-
protocols: {
238-
"http:": http,
239-
"https:": https,
240-
"http2:": null // TODO: add http2
241-
}
242-
}
243-
244-
const hasOwn = Object.hasOwn || function (object, property) {
245-
if (object == null) {
246-
throw new TypeError("Cannot convert undefined or null to object")
247-
}
248-
return Object.prototype.hasOwnProperty.call(new Object(object), property)
249-
}
250-
251-
function _typeof(obj) {
252-
"@babel/helpers - typeof"
253-
254-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator
255-
? function (obj) {
256-
return typeof obj
257-
}
258-
: function (obj) {
259-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
260-
}, _typeof(obj)
261-
}
262-
263-
Request.request = function () {
264-
var _this4 = this
265-
266-
if (this.req) return this.req
267-
var options = {}
268-
269-
try {
270-
var query = qs.stringify(this.qs, {
271-
// ( changed by 0x000f
272-
// indices: false,
273-
indices: true,
274-
// changed by 0x000f )
275-
strictNullHandling: true
276-
})
277-
278-
if (query) {
279-
this.qs = {}
280-
281-
this._query.push(query)
282-
}
283-
284-
this._finalizeQueryString()
285-
} catch (err) {
286-
return this.emit("error", err)
287-
}
288-
289-
var url = this.url
290-
var retries = this._retries // Capture backticks as-is from the final query string built above.
291-
// Note: this'll only find backticks entered in req.query(String)
292-
// calls, because qs.stringify unconditionally encodes backticks.
293-
294-
var queryStringBackticks
295-
296-
if (url.includes("`")) {
297-
var queryStartIndex = url.indexOf("?")
298-
299-
if (queryStartIndex !== -1) {
300-
var queryString = url.slice(queryStartIndex + 1)
301-
queryStringBackticks = queryString.match(/`|%60/g)
302-
}
303-
} // default to http://
304-
305-
if (url.indexOf("http") !== 0) url = "http://".concat(url)
306-
url = parse(url) // See https://github.com/visionmedia/superagent/issues/1367
307-
308-
if (queryStringBackticks) {
309-
var i = 0
310-
url.query = url.query.replace(/%60/g, function () {
311-
return queryStringBackticks[i++]
312-
})
313-
url.search = "?".concat(url.query)
314-
url.path = url.pathname + url.search
315-
} // support unix sockets
316-
317-
if (/^https?\+unix:/.test(url.protocol) === true) {
318-
// get the protocol
319-
url.protocol = "".concat(url.protocol.split("+")[0], ":") // get the socket, path
320-
321-
var unixParts = url.path.match(/^([^/]+)(.+)$/)
322-
options.socketPath = unixParts[1].replace(/%2F/g, "/")
323-
url.path = unixParts[2]
324-
} // Override IP address of a hostname
325-
326-
if (this._connectOverride) {
327-
var _url = url
328-
var hostname = _url.hostname
329-
var match = hostname in this._connectOverride ? this._connectOverride[hostname] : this._connectOverride["*"]
330-
331-
if (match) {
332-
// backup the real host
333-
if (!this._header.host) {
334-
this.set("host", url.host)
335-
}
336-
337-
var newHost
338-
var newPort
339-
340-
if (_typeof(match) === "object") {
341-
newHost = match.host
342-
newPort = match.port
343-
} else {
344-
newHost = match
345-
newPort = url.port
346-
} // wrap [ipv6]
347-
348-
url.host = /:/.test(newHost) ? "[".concat(newHost, "]") : newHost
349-
350-
if (newPort) {
351-
url.host += ":".concat(newPort)
352-
url.port = newPort
353-
}
354-
355-
url.hostname = newHost
356-
}
357-
} // options
358-
359-
options.method = this.method
360-
options.port = url.port
361-
options.path = url.path
362-
options.host = url.hostname
363-
options.ca = this._ca
364-
options.key = this._key
365-
options.pfx = this._pfx
366-
options.cert = this._cert
367-
options.passphrase = this._passphrase
368-
options.agent = this._agent
369-
options.lookup = this._lookup
370-
options.rejectUnauthorized = typeof this._disableTLSCerts === "boolean" ? !this._disableTLSCerts : process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0" // Allows request.get('https://1.2.3.4/').set('Host', 'example.com')
371-
372-
if (this._header.host) {
373-
options.servername = this._header.host.replace(/:\d+$/, "")
374-
}
375-
376-
if (this._trustLocalhost && /^(?:localhost|127\.0\.0\.\d+|(0*:)+:0*1)$/.test(url.hostname)) {
377-
options.rejectUnauthorized = false
378-
} // initiate request
379-
380-
var module_ = this._enableHttp2 ? exports.protocols["http2:"].setProtocol(url.protocol) : exports.protocols[url.protocol] // request
381-
382-
this.req = module_.request(options)
383-
var req = this.req // set tcp no delay
384-
385-
req.setNoDelay(true)
386-
387-
if (options.method !== "HEAD") {
388-
req.setHeader("Accept-Encoding", "gzip, deflate")
389-
}
390-
391-
this.protocol = url.protocol
392-
this.host = url.host // expose events
393-
394-
req.once("drain", function () {
395-
_this4.emit("drain")
396-
})
397-
req.on("error", function (error) {
398-
// flag abortion here for out timeouts
399-
// because node will emit a faux-error "socket hang up"
400-
// when request is aborted before a connection is made
401-
// if not the same, we are in the **old** (cancelled) request,
402-
// so need to continue (same as for above)
403-
if (_this4._aborted) return
404-
405-
// if we've received a response then we don't want to let
406-
// an error in the request blow up the response
407-
if (_this4._retries !== retries) return
408-
409-
if (_this4.response) return
410-
411-
_this4.callback(error)
412-
}) // auth
413-
414-
if (url.auth) {
415-
var auth = url.auth.split(":")
416-
this.auth(auth[0], auth[1])
417-
}
418-
419-
if (this.username && this.password) {
420-
this.auth(this.username, this.password)
421-
}
422-
423-
for (var key in this.header) {
424-
if (hasOwn(this.header, key)) req.setHeader(key, this.header[key])
425-
} // add cookies
426-
427-
if (this.cookies) {
428-
if (hasOwn(this._header, "cookie")) {
429-
// merge
430-
var temporaryJar = new CookieJar.CookieJar()
431-
temporaryJar.setCookies(this._header.cookie.split(""))
432-
temporaryJar.setCookies(this.cookies.split(""))
433-
req.setHeader("Cookie", temporaryJar.getCookies(CookieJar.CookieAccessInfo.All).toValueString())
434-
} else {
435-
req.setHeader("Cookie", this.cookies)
436-
}
437-
}
438-
return req
439-
}
440-
}
441-
/* eslint-disable func-names, yoda, no-new-object, no-param-reassign, no-var, vars-on-top,
442-
global-require, prefer-destructuring, prefer-arrow-callback, no-plusplus, no-return-assign,
443-
no-func-assign, eqeqeq, no-shadow, no-sequences, no-restricted-syntax */
444-
445-
exports.patchRequest = patchRequest
446-
// added by 0x000f, 20220910 )
447-
448221
exports.ILogger = ILogger
449222
exports.CustomInternalPostProcessing = CustomInternalPostProcessing
450223

test/resources/vehicles-v5.spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ describe(helper.toSuiteName(__filename), () => {
118118
"page": "1",
119119
"per_page": "10",
120120
"show": "all",
121-
"search_query": "TST 15"
121+
"search_query": "TST%2015"
122122
},
123123
null
124124
)
@@ -494,7 +494,7 @@ describe(helper.toSuiteName(__filename), () => {
494494
"GET",
495495
route4meClient.baseUrl5() + "/api/v5.0/vehicles/location",
496496
{
497-
"ids": "004ADB6E1335BA6BCE4FB8A89E6311"
497+
"ids%5B0%5D": "004ADB6E1335BA6BCE4FB8A89E6311"
498498
},
499499
null
500500
)
@@ -546,7 +546,7 @@ describe(helper.toSuiteName(__filename), () => {
546546
"POST",
547547
route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/delete",
548548
{
549-
"vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
549+
"vehicle_ids%5B0%5D": "004ADB6E1335BA6BCE4FB8A89E6311"
550550
},
551551
null
552552
)
@@ -567,7 +567,7 @@ describe(helper.toSuiteName(__filename), () => {
567567
"POST",
568568
route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/activate",
569569
{
570-
"vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
570+
"vehicle_ids%5B0%5D": "004ADB6E1335BA6BCE4FB8A89E6311"
571571
},
572572
null
573573
)
@@ -603,7 +603,7 @@ describe(helper.toSuiteName(__filename), () => {
603603
"POST",
604604
route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/deactivate",
605605
{
606-
"vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
606+
"vehicle_ids%5B0%5D": "004ADB6E1335BA6BCE4FB8A89E6311"
607607
},
608608
null
609609
)
@@ -639,7 +639,7 @@ describe(helper.toSuiteName(__filename), () => {
639639
"POST",
640640
route4meClient.baseUrl5() + "/api/v5.0/vehicles/bulk/restore",
641641
{
642-
"vehicle_ids": "004ADB6E1335BA6BCE4FB8A89E6311"
642+
"vehicle_ids%5B0%5D": "004ADB6E1335BA6BCE4FB8A89E6311"
643643
},
644644
null
645645
)
@@ -746,7 +746,7 @@ describe(helper.toSuiteName(__filename), () => {
746746
"mergePagesParam": "true",
747747
"page": "1",
748748
"per_page": "10",
749-
"search_query": "TST 15"
749+
"search_query": "TST%2015"
750750
},
751751
null
752752
)

0 commit comments

Comments
 (0)