-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from panxl6/2024-04
updated document
- Loading branch information
Showing
91 changed files
with
3,859 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Jenkinsfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env groovy | ||
@Library("jenkins-pipeline-library@automation") _ | ||
entry { | ||
isDryRun = false | ||
flow = "frontend" | ||
configInfo = [ | ||
deploymentGroup : "aftership", | ||
appName : "tracking-sdk-nodejs", | ||
gitRepoName : "tracking-sdk-nodejs.git", | ||
chartName : "", | ||
essentialDockerImage : "nodejs-essential", | ||
essentialTag : "nodejs-18.18.2", | ||
requireStaticAsset : false, | ||
uploadAssetCredential : "", | ||
domainType : "", | ||
unitTest : "", | ||
integrationTest : "", | ||
useEnvironmentVariable : false, | ||
hasStagingEnvironment : false, | ||
hasProductionEnvironment : true, | ||
useNPM : false, | ||
npmPackageOnly : true, | ||
prePublishScript : "yarn build", | ||
optionsForAftershipPublish : "" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2024 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "@aftership/tracking-sdk", | ||
"version": "0.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" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.11.25", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* This code was auto generated by AfterShip SDK Generator. | ||
* 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 { 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_secrect?: 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 courier: CourierApi; | ||
public readonly notification: NotificationApi; | ||
public readonly estimatedDeliveryDate: EstimatedDeliveryDateApi; | ||
public readonly lastCheckpoint: LastCheckpointApi; | ||
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_secrect === undefined) { | ||
this.options.api_secrect = 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_secrect: this.options.api_secrect, | ||
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); | ||
} | ||
|
||
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_secrect === undefined || | ||
this.options.api_secrect === "") | ||
) { | ||
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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 { GetAllCouriersResponse } from "../model/GetAllCouriersResponse"; | ||
import { GetUserCouriersResponse } from "../model/GetUserCouriersResponse"; | ||
import { TrackingDetectCourierRequest } from "../model/TrackingDetectCourierRequest"; | ||
import { DetectCourierResponse } from "../model/DetectCourierResponse"; | ||
|
||
export class CourierApi { | ||
private readonly request: Request; | ||
|
||
constructor(request: Request) { | ||
this.request = request; | ||
} | ||
|
||
/** | ||
* Return a list of all couriers. | ||
*/ | ||
public async getAllCouriers( headers?: {[key: string]: any}): Promise<GetAllCouriersResponse> { | ||
|
||
return this.request.makeRequest<GetAllCouriersResponse>({url: `/tracking/2024-04/couriers/all`, method: "GET", headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false}) | ||
} | ||
/** | ||
* Return a list of . | ||
*/ | ||
public async getUserCouriers( headers?: {[key: string]: any}): Promise<GetUserCouriersResponse> { | ||
|
||
return this.request.makeRequest<GetUserCouriersResponse>({url: `/tracking/2024-04/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: TrackingDetectCourierRequest, headers?: {[key: string]: any}): Promise<DetectCourierResponse> { | ||
|
||
return this.request.makeRequest<DetectCourierResponse>({url: `/tracking/2024-04/couriers/detect`, method: "POST", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "", is_paging: false}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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 { PredictBatchRequest } from "../model/PredictBatchRequest"; | ||
import { PredictBatchResponse } from "../model/PredictBatchResponse"; | ||
|
||
export class EstimatedDeliveryDateApi { | ||
private readonly request: Request; | ||
|
||
constructor(request: Request) { | ||
this.request = request; | ||
} | ||
|
||
/** | ||
* > 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/2024-04/estimated-delivery-date/predict-batch`, method: "POST", body, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 { GetCheckpointBySlugTrackingNumberQuery } from "../model/GetCheckpointBySlugTrackingNumberQuery"; | ||
import { GetCheckpointBySlugTrackingNumberResponse } from "../model/GetCheckpointBySlugTrackingNumberResponse"; | ||
import { GetCheckpointByTrackingIdQuery } from "../model/GetCheckpointByTrackingIdQuery"; | ||
import { GetCheckpointByTrackingIdResponse } from "../model/GetCheckpointByTrackingIdResponse"; | ||
|
||
export class LastCheckpointApi { | ||
private readonly request: Request; | ||
|
||
constructor(request: Request) { | ||
this.request = request; | ||
} | ||
|
||
/** | ||
* Return the tracking information of the last checkpoint of a single tracking. | ||
*/ | ||
public async getCheckpointBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetCheckpointBySlugTrackingNumberQuery, headers?: {[key: string]: any}): Promise<GetCheckpointBySlugTrackingNumberResponse> { | ||
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<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}) | ||
} | ||
} |
Oops, something went wrong.