@@ -8,14 +8,15 @@ import { AftershipError } from "../error";
88import { AfterShipErrorCodes } from "../error/code" ;
99import { AfterShipMetaCodeMap } from "../error/meta_code" ;
1010import { Proxy } from "../utils/parse_proxy" ;
11+ import querystring from "querystring" ;
1112
1213export const DEFAULT_DOMAIN = "https://api.aftership.com" ;
1314export const DEFAULT_TIMEOUT = 10000 ;
1415export const DEFAULT_MAX_RETRY = 3 ;
1516export const MAX_MAX_RETRY = 10 ;
1617export const MIN_MAX_RETRY = 0 ;
1718export const DEFAULT_USER_AGENT =
18- "tracking-sdk-nodejs/15.0.0 (https://www.aftership.com) axios/1.7.2" ;
19+ "tracking-sdk-nodejs/15.0.1 (https://www.aftership.com) axios/1.7.2" ;
1920
2021type ResponseData = {
2122 meta : {
@@ -133,7 +134,7 @@ export class Request {
133134 public async makeRequest < T > ( config : RequestConfig ) : Promise < T > {
134135 const headers = this . getHeaders ( config ) ;
135136 try {
136- const response = await this . withRetry < ResponseData > ( {
137+ const axiosConfig : AxiosRequestConfig = {
137138 url : config . url ,
138139 method : config . method ,
139140 headers,
@@ -143,7 +144,28 @@ export class Request {
143144 data : config . body ,
144145 timeout : this . options . timeout ,
145146 proxy : this . options . proxy ,
146- } ) ;
147+ } ;
148+
149+ // Use custom paramsSerializer to match signature calculation encoding (RFC 3986)
150+ // Signature calculation uses querystring.escape(), so we need to use the same encoding
151+ if ( config . query ) {
152+ axiosConfig . paramsSerializer = ( params : any ) => {
153+ const query_keys = Object . keys ( params ) . sort ( ) ;
154+ const parts : string [ ] = [ ] ;
155+ for ( const k of query_keys ) {
156+ const value = params [ k ] ;
157+ if ( value !== null && value !== undefined ) {
158+ const key = k . trim ( ) ;
159+ const val = value . toString ( ) . trim ( ) ;
160+ // Use querystring.escape (RFC 3986) to match signature calculation
161+ parts . push ( `${ key } =${ querystring . escape ( val ) } ` ) ;
162+ }
163+ }
164+ return parts . join ( "&" ) ;
165+ } ;
166+ }
167+
168+ const response = await this . withRetry < ResponseData > ( axiosConfig ) ;
147169
148170 const plainHeaders : Record < string , string > = { } ;
149171 if ( response . headers ) {
0 commit comments