Skip to content

Commit f155f5b

Browse files
authored
Merge pull request #32 from 1415003719/2025-07
fix sign header
2 parents 14dfce2 + 6d6531d commit f155f5b

File tree

8 files changed

+48
-26
lines changed

8 files changed

+48
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aftership/tracking-sdk",
3-
"version": "15.0.0",
3+
"version": "15.0.1",
44
"description": "Tracking NodeJS SDK",
55
"main": "dist/aftership.js",
66
"types": "dist/aftership.d.ts",

src/api/CourierConnection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
*/
55
import { Request } from "../lib/request";
66
import { AftershipError, AfterShipErrorCodes } from "../error";
7-
import { PutCourierConnectionsByIdResponse } from "../model/PutCourierConnectionsByIdResponse";
8-
import { DeleteCourierConnectionsByIdResponse } from "../model/DeleteCourierConnectionsByIdResponse";
9-
import { GetCourierConnectionsResponse } from "../model/GetCourierConnectionsResponse";
107
import { GetCourierConnectionsQuery } from "../model/GetCourierConnectionsQuery";
118
import { PostCourierConnectionsRequest } from "../model/PostCourierConnectionsRequest";
129
import { PostCourierConnectionsResponse } from "../model/PostCourierConnectionsResponse";
1310
import { GetCourierConnectionsByIdResponse } from "../model/GetCourierConnectionsByIdResponse";
1411
import { PutCourierConnectionsByIdRequest } from "../model/PutCourierConnectionsByIdRequest";
12+
import { PutCourierConnectionsByIdResponse } from "../model/PutCourierConnectionsByIdResponse";
13+
import { DeleteCourierConnectionsByIdResponse } from "../model/DeleteCourierConnectionsByIdResponse";
14+
import { GetCourierConnectionsResponse } from "../model/GetCourierConnectionsResponse";
1515

1616
export class CourierConnectionApi {
1717
private readonly request: Request;

src/api/Tracking.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
*/
55
import { Request } from "../lib/request";
66
import { AftershipError, AfterShipErrorCodes } from "../error";
7-
import { MarkTrackingCompletedByIdResponse } from "../model/MarkTrackingCompletedByIdResponse";
8-
import { GetTrackingByIdQuery } from "../model/GetTrackingByIdQuery";
9-
import { UpdateTrackingByIdRequest } from "../model/UpdateTrackingByIdRequest";
10-
import { UpdateTrackingByIdResponse } from "../model/UpdateTrackingByIdResponse";
11-
import { DeleteTrackingByIdResponse } from "../model/DeleteTrackingByIdResponse";
12-
import { GetTrackingsResponse } from "../model/GetTrackingsResponse";
137
import { GetTrackingsQuery } from "../model/GetTrackingsQuery";
148
import { CreateTrackingRequest } from "../model/CreateTrackingRequest";
15-
import { CreateTrackingResponse } from "../model/CreateTrackingResponse";
16-
import { GetTrackingByIdResponse } from "../model/GetTrackingByIdResponse";
9+
import { UpdateTrackingByIdRequest } from "../model/UpdateTrackingByIdRequest";
1710
import { RetrackTrackingByIdResponse } from "../model/RetrackTrackingByIdResponse";
1811
import { MarkTrackingCompletedByIdRequest } from "../model/MarkTrackingCompletedByIdRequest";
12+
import { MarkTrackingCompletedByIdResponse } from "../model/MarkTrackingCompletedByIdResponse";
13+
import { GetTrackingsResponse } from "../model/GetTrackingsResponse";
14+
import { CreateTrackingResponse } from "../model/CreateTrackingResponse";
15+
import { GetTrackingByIdResponse } from "../model/GetTrackingByIdResponse";
16+
import { GetTrackingByIdQuery } from "../model/GetTrackingByIdQuery";
17+
import { UpdateTrackingByIdResponse } from "../model/UpdateTrackingByIdResponse";
18+
import { DeleteTrackingByIdResponse } from "../model/DeleteTrackingByIdResponse";
1919

2020
export class TrackingApi {
2121
private readonly request: Request;

src/lib/request.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import { AftershipError } from "../error";
88
import { AfterShipErrorCodes } from "../error/code";
99
import { AfterShipMetaCodeMap } from "../error/meta_code";
1010
import { Proxy } from "../utils/parse_proxy";
11+
import querystring from "querystring";
1112

1213
export const DEFAULT_DOMAIN = "https://api.aftership.com";
1314
export const DEFAULT_TIMEOUT = 10000;
1415
export const DEFAULT_MAX_RETRY = 3;
1516
export const MAX_MAX_RETRY = 10;
1617
export const MIN_MAX_RETRY = 0;
1718
export 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

2021
type 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) {

src/model/Checkpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* This code was auto generated by AfterShip SDK Generator.
33
* Do not edit the class manually.
44
*/
5-
import { Tag } from "./Tag";
6-
import { CheckpointEvents } from "./CheckpointEvents";
75
import { CheckpointSource } from "./CheckpointSource";
86
import { CheckpointCoordinate } from "./CheckpointCoordinate";
7+
import { Tag } from "./Tag";
8+
import { CheckpointEvents } from "./CheckpointEvents";
99

1010
/**
1111
* Object describes checkpoint information.

src/model/EstimatedDeliveryDateRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* This code was auto generated by AfterShip SDK Generator.
33
* Do not edit the class manually.
44
*/
5-
import { EstimatedDeliveryDateRequestOriginAddress } from "./EstimatedDeliveryDateRequestOriginAddress";
65
import { EstimatedDeliveryDateRequestDestinationAddress } from "./EstimatedDeliveryDateRequestDestinationAddress";
76
import { EstimatedDeliveryDateRequestWeight } from "./EstimatedDeliveryDateRequestWeight";
87
import { EstimatedDeliveryDateRequestEstimatedPickup } from "./EstimatedDeliveryDateRequestEstimatedPickup";
8+
import { EstimatedDeliveryDateRequestOriginAddress } from "./EstimatedDeliveryDateRequestOriginAddress";
99

1010
/**
1111
*

src/model/Tracking.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
* This code was auto generated by AfterShip SDK Generator.
33
* Do not edit the class manually.
44
*/
5+
import { TrackingCourierEstimatedDeliveryDate } from "./TrackingCourierEstimatedDeliveryDate";
6+
import { TrackingShipmentWeight } from "./TrackingShipmentWeight";
7+
import { Tag } from "./Tag";
8+
import { Checkpoint } from "./Checkpoint";
59
import { TrackingAftershipEstimatedDeliveryDate } from "./TrackingAftershipEstimatedDeliveryDate";
10+
import { TrackingLatestEstimatedDelivery } from "./TrackingLatestEstimatedDelivery";
11+
import { TrackingSignatureRequirement } from "./TrackingSignatureRequirement";
612
import { TrackingCustomEstimatedDeliveryDate } from "./TrackingCustomEstimatedDeliveryDate";
713
import { TrackingFirstEstimatedDelivery } from "./TrackingFirstEstimatedDelivery";
8-
import { TrackingLatestEstimatedDelivery } from "./TrackingLatestEstimatedDelivery";
9-
import { TrackingCustomers } from "./TrackingCustomers";
10-
import { TrackingCourierEstimatedDeliveryDate } from "./TrackingCourierEstimatedDeliveryDate";
11-
import { Checkpoint } from "./Checkpoint";
1214
import { TrackingCarbonEmissions } from "./TrackingCarbonEmissions";
13-
import { TrackingSignatureRequirement } from "./TrackingSignatureRequirement";
1415
import { TrackingFirstMile } from "./TrackingFirstMile";
1516
import { TrackingLastMile } from "./TrackingLastMile";
16-
import { TrackingShipmentWeight } from "./TrackingShipmentWeight";
17-
import { Tag } from "./Tag";
17+
import { TrackingCustomers } from "./TrackingCustomers";
1818

1919
/**
2020
* Object describes the tracking information.&lt;div style=&#34;display:none; height: 0&#34;&gt;&lt;/div&gt;

src/model/TrackingResponseForGetTrackingsData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* This code was auto generated by AfterShip SDK Generator.
33
* Do not edit the class manually.
44
*/
5-
import { TrackingResponseForGetTrackingsDataPagination } from "./TrackingResponseForGetTrackingsDataPagination";
65
import { Tracking } from "./Tracking";
6+
import { TrackingResponseForGetTrackingsDataPagination } from "./TrackingResponseForGetTrackingsDataPagination";
77

88
/**
99
*

0 commit comments

Comments
 (0)