Skip to content

Commit

Permalink
feat: supported 2025-01 version.
Browse files Browse the repository at this point in the history
  • Loading branch information
panxl6 committed Jan 10, 2025
1 parent bd716b5 commit 7eb32ce
Show file tree
Hide file tree
Showing 151 changed files with 7,098 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2025 AfterShip

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
286 changes: 285 additions & 1 deletion README.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@aftership/tracking-sdk",
"version": "12.0.0",
"description": "Tracking NodeJS SDK",
"main": "dist/aftership.js",
"types": "dist/aftership.d.ts",
"engines": {
"node": ">=16.20.0"
},
"scripts": {
"build": "npm run build:clean && tsc",
"build:clean": "rm -rf ./dist ./coverage",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/aftership/tracking-sdk-nodejs"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/AfterShip/tracking-sdk-nodejs/issues"
},
"homepage": "https://github.com/aftership/tracking-sdk-nodejs/README.md",
"dependencies": {
"axios": "^1.7.2"
},
"keywords": [
"aftership",
"tracking"
],
"devDependencies": {
"@types/node": "^20.11.25",
"typescript": "^4.9.5"
}
}
163 changes: 163 additions & 0 deletions src/aftership.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
import { TrackingApi } from "./api/Tracking";
import { EstimatedDeliveryDateApi } from "./api/EstimatedDeliveryDate";
import { CourierApi } from "./api/Courier";
import { AftershipError, AfterShipErrorCodes } from "./error";
import { AuthType } from "./lib/authentication";
import {
DEFAULT_DOMAIN,
DEFAULT_MAX_RETRY,
DEFAULT_TIMEOUT,
DEFAULT_USER_AGENT,
MAX_MAX_RETRY,
MIN_MAX_RETRY,
Request,
} from "./lib/request";
import { parseProxy } from "./utils/parse_proxy";

export interface Options {
auth_type?: AuthType;
api_key?: string;
api_secret?: string;
domain?: string;
max_retry?: number;
timeout?: number;
user_agent?: string;
proxy?: string;
}

const SDK_ENV_PREFIX = "AFTERSHIP_TRACKING_SDK";

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

constructor(options?: Options) {
this.options = options === undefined ? {} : options;

if (this.options.api_key === undefined) {
this.options.api_key = process.env[`${SDK_ENV_PREFIX}_API_KEY`];
}
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`];
if (this.options.user_agent === undefined) {
this.options.user_agent = DEFAULT_USER_AGENT;
}
}
if (this.options.auth_type === undefined) {
this.options.auth_type = process.env[
`${SDK_ENV_PREFIX}_AUTHENTICATION_TYPE`
] as AuthType;
if (this.options.auth_type === undefined) {
this.options.auth_type = AuthType.API_KEY;
}
}
if (this.options.domain === undefined) {
this.options.domain = process.env[`${SDK_ENV_PREFIX}_DOMAIN`];
if (this.options.domain === undefined) {
this.options.domain = DEFAULT_DOMAIN;
}
}
if (this.options.proxy === undefined) {
this.options.proxy = process.env[`${SDK_ENV_PREFIX}_PROXY`];
}
if (this.options.max_retry === undefined) {
const env_max_retry = process.env[`${SDK_ENV_PREFIX}_MAX_RETRY`];
if (env_max_retry === undefined) {
this.options.max_retry = DEFAULT_MAX_RETRY;
} else {
this.options.max_retry = parseInt(env_max_retry);
}
}
if (this.options.timeout === undefined) {
const env_timeout = process.env[`${SDK_ENV_PREFIX}_TIMEOUT`];
if (env_timeout === undefined) {
this.options.timeout = DEFAULT_TIMEOUT;
} else {
this.options.timeout = parseInt(env_timeout);
}
}

this.validateOptions();

const request = new Request({
auth_type: this.options.auth_type,
api_key: this.options.api_key,
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.estimatedDeliveryDate = new EstimatedDeliveryDateApi(request);
this.courier = new CourierApi(request);
}

private validateOptions() {
if (this.options.api_key === undefined || this.options.api_key === "") {
throw new AftershipError(
"Invalid API key",
AfterShipErrorCodes.INVALID_API_KEY,
);
}
if (
(this.options.auth_type === AuthType.AES ||
this.options.auth_type === AuthType.RSA) &&
(this.options.api_secret === undefined || this.options.api_secret === "")
) {
throw new AftershipError(
`Invalid option: auth_type`,
AfterShipErrorCodes.INVALID_OPTION,
);
}
if (
this.options.domain &&
((this.options.domain.indexOf("http") < 0 &&
this.options.domain.indexOf("https") < 0) ||
this.options.domain.endsWith("/"))
) {
throw new AftershipError(
`Invalid option: domain`,
AfterShipErrorCodes.INVALID_OPTION,
);
}
if (
this.options.max_retry !== undefined &&
(isNaN(this.options.max_retry) ||
this.options.max_retry > MAX_MAX_RETRY ||
this.options.max_retry < MIN_MAX_RETRY)
) {
throw new AftershipError(
`Invalid option: max_retry`,
AfterShipErrorCodes.INVALID_OPTION,
);
}
if (
this.options.timeout !== undefined &&
(isNaN(this.options.timeout) || this.options.timeout < 0)
) {
throw new AftershipError(
`Invalid option: timeout`,
AfterShipErrorCodes.INVALID_OPTION,
);
}
if (this.options.proxy !== undefined && this.options.proxy.length === 0) {
throw new AftershipError(
`Invalid option: proxy`,
AfterShipErrorCodes.INVALID_OPTION,
);
}
}
}

export { AuthType, AfterShipErrorCodes, AftershipError };
66 changes: 66 additions & 0 deletions src/api/Courier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
import { Request } from "../lib/request";
import { AftershipError, AfterShipErrorCodes } from "../error";
import { GetUserCouriersResponse } from "../model/GetUserCouriersResponse";
import { DetectCourierRequest } from "../model/DetectCourierRequest";
import { DetectCourierResponse } from "../model/DetectCourierResponse";
import { GetAllCouriersResponse } from "../model/GetAllCouriersResponse";

export class CourierApi {
private readonly request: Request;

constructor(request: Request) {
this.request = request;
}

/**
* Return a list of .
*/
public async getUserCouriers(headers?: {
[key: string]: any;
}): Promise<GetUserCouriersResponse> {
return this.request.makeRequest<GetUserCouriersResponse>({
url: `/tracking/2025-01/couriers`,
method: "GET",
headers,
request_legacy_tag: "",
response_legacy_tag: "",
is_paging: false,
});
}
/**
* Return a list of matched couriers based on tracking number format and or a list of couriers.
*/
public async detectCourier(
body: DetectCourierRequest,
headers?: { [key: string]: any },
): Promise<DetectCourierResponse> {
return this.request.makeRequest<DetectCourierResponse>({
url: `/tracking/2025-01/couriers/detect`,
method: "POST",
body,
headers,
request_legacy_tag: "",
response_legacy_tag: "",
is_paging: false,
});
}
/**
* Return a list of all couriers.
*/
public async getAllCouriers(headers?: {
[key: string]: any;
}): Promise<GetAllCouriersResponse> {
return this.request.makeRequest<GetAllCouriersResponse>({
url: `/tracking/2025-01/couriers/all`,
method: "GET",
headers,
request_legacy_tag: "",
response_legacy_tag: "",
is_paging: false,
});
}
}
53 changes: 53 additions & 0 deletions src/api/EstimatedDeliveryDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This code was auto generated by AfterShip SDK Generator.
* Do not edit the class manually.
*/
import { Request } from "../lib/request";
import { AftershipError, AfterShipErrorCodes } from "../error";
import { PredictRequest } from "../model/PredictRequest";
import { PredictResponse } from "../model/PredictResponse";
import { PredictBatchRequest } from "../model/PredictBatchRequest";
import { PredictBatchResponse } from "../model/PredictBatchResponse";

export class EstimatedDeliveryDateApi {
private readonly request: Request;

constructor(request: Request) {
this.request = request;
}

/**
* &gt; The estimated delivery date is provided by AfterShip, based on its AI-predictive model. You can display the EDD on the product page, cart, and order checkout page. It indicates when a customer will receive the order.You can use to activate this feature.
*/
public async predict(
body: PredictRequest,
headers?: { [key: string]: any },
): Promise<PredictResponse> {
return this.request.makeRequest<PredictResponse>({
url: `/tracking/2025-01/estimated-delivery-date/predict`,
method: "POST",
body,
headers,
request_legacy_tag: "",
response_legacy_tag: "",
is_paging: false,
});
}
/**
* &gt; The estimated delivery date is provided by AfterShip, based on its AI-predictive model. You can display the EDD on the product page, cart, and order checkout page. It indicates when a customer will receive the order.You can use to activate this feature.Supported functionalities require:1. One `EstimatedDeliveryDate` object for one prediction result.2. Maximum 5 `EstimatedDeliveryDate` objects are allowed.3. API call will fail if any of the requests `EstimatedDeliveryDate` objects do not meet the specification requirement.
*/
public async predictBatch(
body: PredictBatchRequest,
headers?: { [key: string]: any },
): Promise<PredictBatchResponse> {
return this.request.makeRequest<PredictBatchResponse>({
url: `/tracking/2025-01/estimated-delivery-date/predict-batch`,
method: "POST",
body,
headers,
request_legacy_tag: "",
response_legacy_tag: "",
is_paging: false,
});
}
}
Loading

0 comments on commit 7eb32ce

Please sign in to comment.