Skip to content

Commit

Permalink
fix RSA and AES signture
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson Zuo committed Oct 14, 2024
1 parent 38594c6 commit 8f9f7ae
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 136 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ If you need support using AfterShip products, please contact [email protected]
- [AfterShip Tracking API library for Node.js](#aftership-tracking-api-library-for-nodejs)
- [Table of Contents](#table-of-contents)
- [Before you begin](#before-you-begin)
- [API and SDK Version](#api-and-sdk-version)
- [Quick Start](#quick-start)
- [Installation](#installation)
- [Usage](#usage)
Expand All @@ -37,16 +36,6 @@ Before you begin to integrate:
- [Create an API key](https://organization.automizely.com/api-keys).
- [Install Node.js](https://nodejs.org/en/download/) version 16 or later.

### API and SDK Version

Each SDK version is designed to work with a specific API version. Please refer to the table below to identify the supported API versions for each SDK version, ensuring you select the appropriate SDK version for the API version you intend to use.

| SDK Version | Supported API Version | Branch |
| --- | --- | --- |
| 9.x.x | 2024-04 | https://github.com/AfterShip/tracking-sdk-nodejs/tree/2024-04 |
| 8.x.x | 2023-10 | https://github.com/AfterShip/aftership-sdk-nodejs |
| <=7.x.x | Legacy API | https://github.com/AfterShip/aftership-sdk-nodejs |

## Quick Start

### Installation
Expand Down Expand Up @@ -332,4 +321,4 @@ If you get stuck, we're here to help:
## License
Copyright (c) 2024 AfterShip

Licensed under the MIT license.
Licensed under the MIT license.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"dependencies": {
"axios": "^1.7.2"
},
"keywords": [
"aftership", "tracking"
],
"devDependencies": {
"@types/node": "^20.11.25",
"typescript": "^4.9.5"
Expand Down
24 changes: 12 additions & 12 deletions src/aftership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Do not edit the class manually.
*/
import { TrackingApi } from "./api/Tracking";
import { CourierApi } from "./api/Courier";
import { NotificationApi } from "./api/Notification";
import { EstimatedDeliveryDateApi } from "./api/EstimatedDeliveryDate";
import { LastCheckpointApi } from "./api/LastCheckpoint";
import { EstimatedDeliveryDateApi } from "./api/EstimatedDeliveryDate";
import { CourierApi } from "./api/Courier";
import { AftershipError, AfterShipErrorCodes } from "./error";
import { AuthType } from "./lib/authentication";
import {
Expand All @@ -23,7 +23,7 @@ import { parseProxy } from "./utils/parse_proxy";
export interface Options {
auth_type?: AuthType;
api_key?: string;
api_secrect?: string;
api_secret?: string;
domain?: string;
max_retry?: number;
timeout?: number;
Expand All @@ -35,10 +35,10 @@ const SDK_ENV_PREFIX = "AFTERSHIP_TRACKING_SDK";

export class AfterShip {
public readonly tracking: TrackingApi;
public readonly courier: CourierApi;
public readonly notification: NotificationApi;
public readonly estimatedDeliveryDate: EstimatedDeliveryDateApi;
public readonly lastCheckpoint: LastCheckpointApi;
public readonly estimatedDeliveryDate: EstimatedDeliveryDateApi;
public readonly courier: CourierApi;
private readonly options: Options;

constructor(options?: Options) {
Expand All @@ -47,8 +47,8 @@ export class AfterShip {
if (this.options.api_key === undefined) {
this.options.api_key = process.env[`${SDK_ENV_PREFIX}_API_KEY`];
}
if (this.options.api_secrect === undefined) {
this.options.api_secrect = process.env[`${SDK_ENV_PREFIX}_API_SECRET`];
if (this.options.api_secret === undefined) {
this.options.api_secret = process.env[`${SDK_ENV_PREFIX}_API_SECRET`];
}
if (this.options.user_agent === undefined) {
this.options.user_agent = process.env[`${SDK_ENV_PREFIX}_USER_AGENT`];
Expand Down Expand Up @@ -93,18 +93,18 @@ export class AfterShip {
const request = new Request({
auth_type: this.options.auth_type,
api_key: this.options.api_key,
api_secrect: this.options.api_secrect,
api_secret: this.options.api_secret,
domain: this.options.domain,
max_retry: this.options.max_retry,
timeout: this.options.timeout,
user_agent: this.options.user_agent,
proxy: parseProxy(this.options.proxy),
});
this.tracking = new TrackingApi(request);
this.courier = new CourierApi(request);
this.notification = new NotificationApi(request);
this.estimatedDeliveryDate = new EstimatedDeliveryDateApi(request);
this.lastCheckpoint = new LastCheckpointApi(request);
this.estimatedDeliveryDate = new EstimatedDeliveryDateApi(request);
this.courier = new CourierApi(request);
}

private validateOptions() {
Expand All @@ -117,8 +117,8 @@ export class AfterShip {
if (
(this.options.auth_type === AuthType.AES ||
this.options.auth_type === AuthType.RSA) &&
(this.options.api_secrect === undefined ||
this.options.api_secrect === "")
(this.options.api_secret === undefined ||
this.options.api_secret === "")
) {
throw new AftershipError(
`Invalid option: auth_type`,
Expand Down
30 changes: 15 additions & 15 deletions src/api/LastCheckpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
import { Request } from "../lib/request";
import { AftershipError, AfterShipErrorCodes } from "../error";
import { GetCheckpointBySlugTrackingNumberQuery } from "../model/GetCheckpointBySlugTrackingNumberQuery";
import { GetCheckpointBySlugTrackingNumberResponse } from "../model/GetCheckpointBySlugTrackingNumberResponse";
import { GetCheckpointByTrackingIdQuery } from "../model/GetCheckpointByTrackingIdQuery";
import { GetCheckpointByTrackingIdResponse } from "../model/GetCheckpointByTrackingIdResponse";
import { GetCheckpointBySlugTrackingNumberQuery } from "../model/GetCheckpointBySlugTrackingNumberQuery";
import { GetCheckpointBySlugTrackingNumberResponse } from "../model/GetCheckpointBySlugTrackingNumberResponse";

export class LastCheckpointApi {
private readonly request: Request;
Expand All @@ -16,6 +16,19 @@ export class LastCheckpointApi {
this.request = request;
}

/**
* Return the tracking information of the last checkpoint of a single tracking.
*/
public async getCheckpointByTrackingId(tracking_id: string, query?: GetCheckpointByTrackingIdQuery, headers?: {[key: string]: any}): Promise<GetCheckpointByTrackingIdResponse> {
if (!tracking_id) {
throw new AftershipError(
"Invalid params: tracking_id",
AfterShipErrorCodes.VALUE_INVALID
);
}

return this.request.makeRequest<GetCheckpointByTrackingIdResponse>({url: `/tracking/2024-04/last_checkpoint/${tracking_id}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false})
}
/**
* Return the tracking information of the last checkpoint of a single tracking.
*/
Expand All @@ -35,17 +48,4 @@ export class LastCheckpointApi {

return this.request.makeRequest<GetCheckpointBySlugTrackingNumberResponse>({url: `/tracking/2024-04/last_checkpoint/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false})
}
/**
* Return the tracking information of the last checkpoint of a single tracking.
*/
public async getCheckpointByTrackingId(tracking_id: string, query?: GetCheckpointByTrackingIdQuery, headers?: {[key: string]: any}): Promise<GetCheckpointByTrackingIdResponse> {
if (!tracking_id) {
throw new AftershipError(
"Invalid params: tracking_id",
AfterShipErrorCodes.VALUE_INVALID
);
}

return this.request.makeRequest<GetCheckpointByTrackingIdResponse>({url: `/tracking/2024-04/last_checkpoint/${tracking_id}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false})
}
}
64 changes: 32 additions & 32 deletions src/api/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import { Request } from "../lib/request";
import { AftershipError, AfterShipErrorCodes } from "../error";
import { NotificationRequestV1 } from "../model/NotificationRequestV1";
import { DeleteNotificationBySlugTrackingNumberQuery } from "../model/DeleteNotificationBySlugTrackingNumberQuery";
import { Notification } from "../model/Notification";
import { GetNotificationBySlugTrackingNumberQuery } from "../model/GetNotificationBySlugTrackingNumberQuery";
import { AddNotificationBySlugTrackingNumberQuery } from "../model/AddNotificationBySlugTrackingNumberQuery";
import { DeleteNotificationBySlugTrackingNumberQuery } from "../model/DeleteNotificationBySlugTrackingNumberQuery";
import { GetNotificationBySlugTrackingNumberQuery } from "../model/GetNotificationBySlugTrackingNumberQuery";

export class NotificationApi {
private readonly request: Request;
Expand All @@ -17,25 +17,6 @@ export class NotificationApi {
this.request = request;
}

/**
* Remove notification receivers from a tracking number.
*/
public async deleteNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: DeleteNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
if (!slug) {
throw new AftershipError(
"Invalid params: slug",
AfterShipErrorCodes.VALUE_INVALID
);
}
if (!tracking_number) {
throw new AftershipError(
"Invalid params: tracking_number",
AfterShipErrorCodes.VALUE_INVALID
);
}

return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}/remove`, method: "POST", body, query, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
}
/**
* Remove notification receivers from a tracking number.
*/
Expand All @@ -50,9 +31,9 @@ export class NotificationApi {
return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${tracking_id}/remove`, method: "POST", body, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
}
/**
* Get contact information for the users to notify when the tracking changes. Please note that only customer receivers will be returned. Any `email`, `sms` or `webhook` that belongs to the Store will not be returned.
* Add notification receivers to a tracking number.
*/
public async getNotificationBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
public async addNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: AddNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
if (!slug) {
throw new AftershipError(
"Invalid params: slug",
Expand All @@ -66,12 +47,12 @@ export class NotificationApi {
);
}

return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "notification", is_paging: false})
return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}/add`, method: "POST", body, query, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
}
/**
* Add notification receivers to a tracking number.
* Remove notification receivers from a tracking number.
*/
public async addNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: AddNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
public async deleteNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: DeleteNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
if (!slug) {
throw new AftershipError(
"Invalid params: slug",
Expand All @@ -85,7 +66,20 @@ export class NotificationApi {
);
}

return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}/add`, method: "POST", body, query, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}/remove`, method: "POST", body, query, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
}
/**
* Add notification receivers to a tracking number.
*/
public async addNotificationByTrackingId(tracking_id: string, body: NotificationRequestV1, headers?: {[key: string]: any}): Promise<Notification> {
if (!tracking_id) {
throw new AftershipError(
"Invalid params: tracking_id",
AfterShipErrorCodes.VALUE_INVALID
);
}

return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${tracking_id}/add`, method: "POST", body, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
}
/**
* Get contact information for the users to notify when the tracking changes. Please note that only customer receivers will be returned. Any `email`, `sms` or `webhook` that belongs to the Store will not be returned.
Expand All @@ -101,16 +95,22 @@ export class NotificationApi {
return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${tracking_id}`, method: "GET", headers, request_legacy_tag: "", response_legacy_tag: "notification", is_paging: false})
}
/**
* Add notification receivers to a tracking number.
* Get contact information for the users to notify when the tracking changes. Please note that only customer receivers will be returned. Any `email`, `sms` or `webhook` that belongs to the Store will not be returned.
*/
public async addNotificationByTrackingId(tracking_id: string, body: NotificationRequestV1, headers?: {[key: string]: any}): Promise<Notification> {
if (!tracking_id) {
public async getNotificationBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<Notification> {
if (!slug) {
throw new AftershipError(
"Invalid params: tracking_id",
"Invalid params: slug",
AfterShipErrorCodes.VALUE_INVALID
);
}
if (!tracking_number) {
throw new AftershipError(
"Invalid params: tracking_number",
AfterShipErrorCodes.VALUE_INVALID
);
}

return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${tracking_id}/add`, method: "POST", body, headers, request_legacy_tag: "notification", response_legacy_tag: "notification", is_paging: false})
return this.request.makeRequest<Notification>({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "notification", is_paging: false})
}
}
Loading

0 comments on commit 8f9f7ae

Please sign in to comment.