From 8f9f7ae58893ea371d5ee9cc02913e8253d244b7 Mon Sep 17 00:00:00 2001 From: Watson Zuo Date: Mon, 14 Oct 2024 16:07:59 +0800 Subject: [PATCH] fix RSA and AES signture --- README.md | 13 +-- package.json | 3 + src/aftership.ts | 24 ++--- src/api/LastCheckpoint.ts | 30 +++--- src/api/Notification.ts | 64 +++++------ src/api/Tracking.ts | 102 +++++++++--------- src/lib/request.ts | 9 +- ...dateTrackingBySlugTrackingNumberRequest.ts | 8 -- ...dateTrackingBySlugTrackingNumberRequest.ts | 3 +- 9 files changed, 120 insertions(+), 136 deletions(-) delete mode 100644 src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts diff --git a/README.md b/README.md index 4f95c03..4334770 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ If you need support using AfterShip products, please contact support@aftership.c - [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) @@ -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 @@ -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. \ No newline at end of file diff --git a/package.json b/package.json index 4d30c9b..8d249b7 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,9 @@ "dependencies": { "axios": "^1.7.2" }, + "keywords": [ + "aftership", "tracking" + ], "devDependencies": { "@types/node": "^20.11.25", "typescript": "^4.9.5" diff --git a/src/aftership.ts b/src/aftership.ts index bfd469b..7af1b42 100644 --- a/src/aftership.ts +++ b/src/aftership.ts @@ -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 { @@ -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; @@ -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) { @@ -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`]; @@ -93,7 +93,7 @@ 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, @@ -101,10 +101,10 @@ export class AfterShip { 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() { @@ -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`, diff --git a/src/api/LastCheckpoint.ts b/src/api/LastCheckpoint.ts index ed5041f..72b081b 100644 --- a/src/api/LastCheckpoint.ts +++ b/src/api/LastCheckpoint.ts @@ -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; @@ -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 { + if (!tracking_id) { + throw new AftershipError( + "Invalid params: tracking_id", + AfterShipErrorCodes.VALUE_INVALID + ); + } + + return this.request.makeRequest({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. */ @@ -35,17 +48,4 @@ export class LastCheckpointApi { return this.request.makeRequest({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 { - if (!tracking_id) { - throw new AftershipError( - "Invalid params: tracking_id", - AfterShipErrorCodes.VALUE_INVALID - ); - } - - return this.request.makeRequest({url: `/tracking/2024-04/last_checkpoint/${tracking_id}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false}) - } } \ No newline at end of file diff --git a/src/api/Notification.ts b/src/api/Notification.ts index 4836ed3..3c57770 100644 --- a/src/api/Notification.ts +++ b/src/api/Notification.ts @@ -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; @@ -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 { - 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({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. */ @@ -50,9 +31,9 @@ export class NotificationApi { return this.request.makeRequest({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 { + public async addNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: AddNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { if (!slug) { throw new AftershipError( "Invalid params: slug", @@ -66,12 +47,12 @@ export class NotificationApi { ); } - return this.request.makeRequest({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({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 { + public async deleteNotificationBySlugTrackingNumber(slug: string, tracking_number: string, body: NotificationRequestV1,query?: DeleteNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { if (!slug) { throw new AftershipError( "Invalid params: slug", @@ -85,7 +66,20 @@ export class NotificationApi { ); } - return this.request.makeRequest({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({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 { + if (!tracking_id) { + throw new AftershipError( + "Invalid params: tracking_id", + AfterShipErrorCodes.VALUE_INVALID + ); + } + + return this.request.makeRequest({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. @@ -101,16 +95,22 @@ export class NotificationApi { return this.request.makeRequest({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 { - if (!tracking_id) { + public async getNotificationBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetNotificationBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { + 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({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({url: `/tracking/2024-04/notifications/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "notification", is_paging: false}) } } \ No newline at end of file diff --git a/src/api/Tracking.ts b/src/api/Tracking.ts index 7bae783..7b46edb 100644 --- a/src/api/Tracking.ts +++ b/src/api/Tracking.ts @@ -6,20 +6,20 @@ import { Request } from "../lib/request"; import { AftershipError, AfterShipErrorCodes } from "../error"; import { GetTrackingByIdQuery } from "../model/GetTrackingByIdQuery"; import { Tracking } from "../model/Tracking"; -import { MarkTrackingCompletedByIdRequest } from "../model/MarkTrackingCompletedByIdRequest"; -import { DeleteTrackingBySlugTrackingNumberQuery } from "../model/DeleteTrackingBySlugTrackingNumberQuery"; -import { PartialDeleteTracking } from "../model/PartialDeleteTracking"; -import { TrackingCreateTrackingRequest } from "../model/TrackingCreateTrackingRequest"; +import { GetTrackingBySlugTrackingNumberQuery } from "../model/GetTrackingBySlugTrackingNumberQuery"; import { TrackingUpdateTrackingBySlugTrackingNumberRequest } from "../model/TrackingUpdateTrackingBySlugTrackingNumberRequest"; import { UpdateTrackingBySlugTrackingNumberQuery } from "../model/UpdateTrackingBySlugTrackingNumberQuery"; -import { RetrackTrackingBySlugTrackingNumberQuery } from "../model/RetrackTrackingBySlugTrackingNumberQuery"; -import { PartialUpdateTracking } from "../model/PartialUpdateTracking"; import { MarkTrackingCompletedBySlugTrackingNumberRequest } from "../model/MarkTrackingCompletedBySlugTrackingNumberRequest"; import { MarkTrackingCompletedBySlugTrackingNumberQuery } from "../model/MarkTrackingCompletedBySlugTrackingNumberQuery"; import { TrackingUpdateTrackingByIdRequest } from "../model/TrackingUpdateTrackingByIdRequest"; +import { MarkTrackingCompletedByIdRequest } from "../model/MarkTrackingCompletedByIdRequest"; +import { RetrackTrackingBySlugTrackingNumberQuery } from "../model/RetrackTrackingBySlugTrackingNumberQuery"; +import { PartialUpdateTracking } from "../model/PartialUpdateTracking"; +import { TrackingCreateTrackingRequest } from "../model/TrackingCreateTrackingRequest"; +import { PartialDeleteTracking } from "../model/PartialDeleteTracking"; import { GetTrackingsQuery } from "../model/GetTrackingsQuery"; import { GetTrackingsResponse } from "../model/GetTrackingsResponse"; -import { GetTrackingBySlugTrackingNumberQuery } from "../model/GetTrackingBySlugTrackingNumberQuery"; +import { DeleteTrackingBySlugTrackingNumberQuery } from "../model/DeleteTrackingBySlugTrackingNumberQuery"; export class TrackingApi { private readonly request: Request; @@ -42,22 +42,9 @@ export class TrackingApi { return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** - * Mark a tracking as completed. The tracking won't auto update until retrack it. - */ - public async markTrackingCompletedById(id: string, body: MarkTrackingCompletedByIdRequest, headers?: {[key: string]: any}): Promise { - if (!id) { - throw new AftershipError( - "Invalid params: id", - AfterShipErrorCodes.VALUE_INVALID - ); - } - - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}/mark-as-completed`, method: "POST", body, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) - } - /** - * Delete a tracking. + * Get tracking results of a single tracking. */ - public async deleteTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: DeleteTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { + public async getTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { if (!slug) { throw new AftershipError( "Invalid params: slug", @@ -71,14 +58,7 @@ export class TrackingApi { ); } - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}`, method: "DELETE", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) - } - /** - * Create a tracking.<div style="visibility:hidden; height: 0"></div> - */ - public async createTracking(body: TrackingCreateTrackingRequest, headers?: {[key: string]: any}): Promise { - - return this.request.makeRequest({url: `/tracking/2024-04/trackings`, method: "POST", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "tracking", is_paging: false}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** * Update a tracking. @@ -100,9 +80,9 @@ export class TrackingApi { return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}`, method: "PUT", body, query, headers, request_legacy_tag: "tracking", response_legacy_tag: "tracking", is_paging: false}) } /** - * Retrack an expired tracking. Max 3 times per tracking. + * Mark a tracking as completed. The tracking won't auto update until retrack it. */ - public async retrackTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: RetrackTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { + public async markTrackingCompletedBySlugTrackingNumber(slug: string, tracking_number: string, body: MarkTrackingCompletedBySlugTrackingNumberRequest,query?: MarkTrackingCompletedBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { if (!slug) { throw new AftershipError( "Invalid params: slug", @@ -116,46 +96,59 @@ export class TrackingApi { ); } - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}/retrack`, method: "POST", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}/mark-as-completed`, method: "POST", body, query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** - * Mark a tracking as completed. The tracking won't auto update until retrack it. + * Update a tracking. */ - public async markTrackingCompletedBySlugTrackingNumber(slug: string, tracking_number: string, body: MarkTrackingCompletedBySlugTrackingNumberRequest,query?: MarkTrackingCompletedBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { - if (!slug) { + public async updateTrackingById(id: string, body: TrackingUpdateTrackingByIdRequest, headers?: {[key: string]: any}): Promise { + if (!id) { throw new AftershipError( - "Invalid params: slug", + "Invalid params: id", AfterShipErrorCodes.VALUE_INVALID ); } - if (!tracking_number) { + + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}`, method: "PUT", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "tracking", is_paging: false}) + } + /** + * Mark a tracking as completed. The tracking won't auto update until retrack it. + */ + public async markTrackingCompletedById(id: string, body: MarkTrackingCompletedByIdRequest, headers?: {[key: string]: any}): Promise { + if (!id) { throw new AftershipError( - "Invalid params: tracking_number", + "Invalid params: id", AfterShipErrorCodes.VALUE_INVALID ); } - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}/mark-as-completed`, method: "POST", body, query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}/mark-as-completed`, method: "POST", body, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** - * Update a tracking. + * Retrack an expired tracking. Max 3 times per tracking. */ - public async updateTrackingById(id: string, body: TrackingUpdateTrackingByIdRequest, headers?: {[key: string]: any}): Promise { - if (!id) { + public async retrackTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: RetrackTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { + if (!slug) { throw new AftershipError( - "Invalid params: id", + "Invalid params: slug", + AfterShipErrorCodes.VALUE_INVALID + ); + } + if (!tracking_number) { + throw new AftershipError( + "Invalid params: tracking_number", AfterShipErrorCodes.VALUE_INVALID ); } - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}`, method: "PUT", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "tracking", is_paging: false}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}/retrack`, method: "POST", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** - * Get tracking results of multiple trackings.<div style="visibility:hidden; height: 0"></div> + * Create a tracking.<div style="visibility:hidden; height: 0"></div> */ - public async getTrackings(query?: GetTrackingsQuery, headers?: {[key: string]: any}): Promise { + public async createTracking(body: TrackingCreateTrackingRequest, headers?: {[key: string]: any}): Promise { - return this.request.makeRequest({url: `/tracking/2024-04/trackings`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "trackings", is_paging: true}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings`, method: "POST", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "tracking", is_paging: false}) } /** * Delete a tracking. @@ -170,6 +163,13 @@ export class TrackingApi { return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}`, method: "DELETE", headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } + /** + * Get tracking results of multiple trackings.<div style="visibility:hidden; height: 0"></div> + */ + public async getTrackings(query?: GetTrackingsQuery, headers?: {[key: string]: any}): Promise { + + return this.request.makeRequest({url: `/tracking/2024-04/trackings`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "trackings", is_paging: true}) + } /** * Retrack an expired tracking. Max 3 times per tracking. */ @@ -184,9 +184,9 @@ export class TrackingApi { return this.request.makeRequest({url: `/tracking/2024-04/trackings/${id}/retrack`, method: "POST", headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } /** - * Get tracking results of a single tracking. + * Delete a tracking. */ - public async getTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { + public async deleteTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: DeleteTrackingBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise { if (!slug) { throw new AftershipError( "Invalid params: slug", @@ -200,6 +200,6 @@ export class TrackingApi { ); } - return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + return this.request.makeRequest({url: `/tracking/2024-04/trackings/${slug}/${tracking_number}`, method: "DELETE", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) } } \ No newline at end of file diff --git a/src/lib/request.ts b/src/lib/request.ts index eaa2579..d684423 100644 --- a/src/lib/request.ts +++ b/src/lib/request.ts @@ -40,7 +40,7 @@ export interface RequestConfig { export interface RequestOptions { auth_type: string; api_key?: string; - api_secrect?: string; + api_secret?: string; domain: string; max_retry: number; timeout: number; @@ -78,12 +78,12 @@ export class Request { headers[header_keys] = Authentication.sign({ method: config.method, url: config.url, - body: config.body, + body: JSON.stringify(config.body), content_type, query: config.query, auth_type: this.options.auth_type, date: date_now, - private_key: this.options.api_secrect, + private_key: this.options.api_secret, headers, }); headers["date"] = date_now; @@ -155,6 +155,7 @@ export class Request { } public async makeRequest(config: RequestConfig): Promise { + config.body = this.handleRequestData(config.request_legacy_tag, config.body) const headers = this.getHeaders(config); try { const response = await this.withRetry( @@ -165,7 +166,7 @@ export class Request { params: config.query, validateStatus: (status) => status >= 200 && status < 400, baseURL: this.options.domain, - data: this.handleRequestData(config.request_legacy_tag, config.body), + data: config.body, timeout: this.options.timeout, proxy: this.options.proxy, } diff --git a/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts b/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts deleted file mode 100644 index 119f547..0000000 --- a/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * This code was auto generated by AfterShip SDK Generator. - * Do not edit the class manually. - */ - -export interface CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest { -} - diff --git a/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts b/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts index b16b1ca..dcf47c6 100644 --- a/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts +++ b/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts @@ -2,7 +2,6 @@ * This code was auto generated by AfterShip SDK Generator. * Do not edit the class manually. */ -import { CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest } from "./CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest"; export interface TrackingUpdateTrackingBySlugTrackingNumberRequest { /** @@ -32,7 +31,7 @@ export interface TrackingUpdateTrackingBySlugTrackingNumberRequest { /** * Custom fields that accept an object with string field. In order to protect the privacy of your customers, do not include any */ - custom_fields?: CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest; + custom_fields?: {[key: string]: any}; /** * Text field for the note */