From 7861d7a31fb53c50a41660132b6ec72953b6eb7c Mon Sep 17 00:00:00 2001 From: panxl6 Date: Thu, 20 Jun 2024 17:24:28 +0800 Subject: [PATCH 1/7] feat: init project --- Jenkinsfile | 26 ++ README.md | 346 +++++++++++++++++- package.json | 32 ++ src/aftership.ts | 165 +++++++++ src/api/Courier.ts | 40 ++ src/api/EstimatedDeliveryDate.ts | 24 ++ src/api/LastCheckpoint.ts | 51 +++ src/api/Notification.ts | 116 ++++++ src/api/Tracking.ts | 205 +++++++++++ src/error/code.ts | 32 ++ src/error/index.ts | 25 ++ src/error/meta_code.ts | 33 ++ src/lib/authentication.ts | 116 ++++++ src/lib/rate_limit.ts | 24 ++ src/lib/request.ts | 237 ++++++++++++ ...ddNotificationBySlugTrackingNumberQuery.ts | 14 + src/model/AdditionalFieldsV1.ts | 15 + .../AftershipEstimatedDeliveryDateTracking.ts | 24 ++ src/model/CarbonEmissionsTracking.ts | 16 + src/model/Checkpoint.ts | 75 ++++ src/model/CoordinateCheckpoint.ts | 16 + src/model/Courier.ts | 48 +++ src/model/CourierResponseV1.ts | 18 + .../CustomEstimatedDeliveryDateTracking.ts | 24 ++ ...dateTrackingBySlugTrackingNumberRequest.ts | 8 + src/model/DataCourierResponseV1.ts | 17 + src/model/DataNotificationResponseV1.ts | 13 + src/model/DataTrackingDeleteResponseV1.ts | 13 + .../DataTrackingResponseGetMultipleV1.ts | 66 ++++ src/model/DataTrackingResponseV1.ts | 13 + ...teNotificationBySlugTrackingNumberQuery.ts | 14 + ...DeleteTrackingBySlugTrackingNumberQuery.ts | 14 + ...tionAddressEstimatedDeliveryDateRequest.ts | 28 ++ ...ionAddressEstimatedDeliveryDateResponse.ts | 28 ++ src/model/DetectCourierResponse.ts | 17 + src/model/EstimatedDeliveryDateRequest.ts | 44 +++ src/model/EstimatedDeliveryDateResponse.ts | 60 +++ ...matedPickupEstimatedDeliveryDateRequest.ts | 25 ++ ...atedPickupEstimatedDeliveryDateResponse.ts | 29 ++ src/model/EventsCheckpoint.ts | 17 + src/model/FirstEstimatedDeliveryTracking.ts | 28 ++ src/model/GetAllCouriersResponse.ts | 17 + .../GetCheckpointBySlugTrackingNumberQuery.ts | 16 + ...tCheckpointBySlugTrackingNumberResponse.ts | 38 ++ src/model/GetCheckpointByTrackingIdQuery.ts | 9 + .../GetCheckpointByTrackingIdResponse.ts | 38 ++ ...etNotificationBySlugTrackingNumberQuery.ts | 14 + src/model/GetTrackingByIdQuery.ts | 9 + .../GetTrackingBySlugTrackingNumberQuery.ts | 16 + src/model/GetTrackingsQuery.ts | 25 ++ src/model/GetTrackingsResponse.ts | 18 + src/model/GetUserCouriersResponse.ts | 17 + src/model/LatestEstimatedDeliveryTracking.ts | 28 ++ src/model/MarkTrackingCompletedByIdRequest.ts | 12 + ...ckingCompletedBySlugTrackingNumberQuery.ts | 14 + ...ingCompletedBySlugTrackingNumberRequest.ts | 12 + src/model/MetaV1.ts | 20 + src/model/NextCouriersTracking.ts | 20 + ...xtCouriersTrackingCreateTrackingRequest.ts | 16 + src/model/Notification.ts | 16 + src/model/NotificationRequestV1.ts | 16 + src/model/NotificationResponseV1.ts | 18 + ...matedPickupEstimatedDeliveryDateRequest.ts | 16 + ...atedPickupEstimatedDeliveryDateResponse.ts | 16 + ...iginAddressEstimatedDeliveryDateRequest.ts | 28 ++ ...ginAddressEstimatedDeliveryDateResponse.ts | 28 ++ src/model/Pagination.ts | 10 + src/model/PartialDeleteTracking.ts | 48 +++ src/model/PartialUpdateTracking.ts | 52 +++ src/model/PredictBatchRequest.ts | 13 + src/model/PredictBatchResponse.ts | 13 + src/model/ReasonEventsCheckpoint.ts | 12 + ...etrackTrackingBySlugTrackingNumberQuery.ts | 14 + src/model/SlugGroupV1.ts | 20 + src/model/TagV1.ts | 17 + src/model/Tracking.ts | 328 +++++++++++++++++ src/model/TrackingCreateTrackingRequest.ts | 174 +++++++++ src/model/TrackingDeleteResponseV1.ts | 18 + src/model/TrackingDetectCourierRequest.ts | 57 +++ src/model/TrackingResponseGetMultipleV1.ts | 18 + src/model/TrackingResponseV1.ts | 18 + .../TrackingUpdateTrackingByIdRequest.ts | 152 ++++++++ ...dateTrackingBySlugTrackingNumberRequest.ts | 109 ++++++ ...UpdateTrackingBySlugTrackingNumberQuery.ts | 14 + .../WeightEstimatedDeliveryDateRequest.ts | 16 + .../WeightEstimatedDeliveryDateResponse.ts | 16 + src/utils/parse_proxy.ts | 80 ++++ tsconfig.json | 24 ++ 88 files changed, 3855 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile create mode 100644 package.json create mode 100644 src/aftership.ts create mode 100644 src/api/Courier.ts create mode 100644 src/api/EstimatedDeliveryDate.ts create mode 100644 src/api/LastCheckpoint.ts create mode 100644 src/api/Notification.ts create mode 100644 src/api/Tracking.ts create mode 100644 src/error/code.ts create mode 100644 src/error/index.ts create mode 100644 src/error/meta_code.ts create mode 100644 src/lib/authentication.ts create mode 100644 src/lib/rate_limit.ts create mode 100644 src/lib/request.ts create mode 100644 src/model/AddNotificationBySlugTrackingNumberQuery.ts create mode 100644 src/model/AdditionalFieldsV1.ts create mode 100644 src/model/AftershipEstimatedDeliveryDateTracking.ts create mode 100644 src/model/CarbonEmissionsTracking.ts create mode 100644 src/model/Checkpoint.ts create mode 100644 src/model/CoordinateCheckpoint.ts create mode 100644 src/model/Courier.ts create mode 100644 src/model/CourierResponseV1.ts create mode 100644 src/model/CustomEstimatedDeliveryDateTracking.ts create mode 100644 src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts create mode 100644 src/model/DataCourierResponseV1.ts create mode 100644 src/model/DataNotificationResponseV1.ts create mode 100644 src/model/DataTrackingDeleteResponseV1.ts create mode 100644 src/model/DataTrackingResponseGetMultipleV1.ts create mode 100644 src/model/DataTrackingResponseV1.ts create mode 100644 src/model/DeleteNotificationBySlugTrackingNumberQuery.ts create mode 100644 src/model/DeleteTrackingBySlugTrackingNumberQuery.ts create mode 100644 src/model/DestinationAddressEstimatedDeliveryDateRequest.ts create mode 100644 src/model/DestinationAddressEstimatedDeliveryDateResponse.ts create mode 100644 src/model/DetectCourierResponse.ts create mode 100644 src/model/EstimatedDeliveryDateRequest.ts create mode 100644 src/model/EstimatedDeliveryDateResponse.ts create mode 100644 src/model/EstimatedPickupEstimatedDeliveryDateRequest.ts create mode 100644 src/model/EstimatedPickupEstimatedDeliveryDateResponse.ts create mode 100644 src/model/EventsCheckpoint.ts create mode 100644 src/model/FirstEstimatedDeliveryTracking.ts create mode 100644 src/model/GetAllCouriersResponse.ts create mode 100644 src/model/GetCheckpointBySlugTrackingNumberQuery.ts create mode 100644 src/model/GetCheckpointBySlugTrackingNumberResponse.ts create mode 100644 src/model/GetCheckpointByTrackingIdQuery.ts create mode 100644 src/model/GetCheckpointByTrackingIdResponse.ts create mode 100644 src/model/GetNotificationBySlugTrackingNumberQuery.ts create mode 100644 src/model/GetTrackingByIdQuery.ts create mode 100644 src/model/GetTrackingBySlugTrackingNumberQuery.ts create mode 100644 src/model/GetTrackingsQuery.ts create mode 100644 src/model/GetTrackingsResponse.ts create mode 100644 src/model/GetUserCouriersResponse.ts create mode 100644 src/model/LatestEstimatedDeliveryTracking.ts create mode 100644 src/model/MarkTrackingCompletedByIdRequest.ts create mode 100644 src/model/MarkTrackingCompletedBySlugTrackingNumberQuery.ts create mode 100644 src/model/MarkTrackingCompletedBySlugTrackingNumberRequest.ts create mode 100644 src/model/MetaV1.ts create mode 100644 src/model/NextCouriersTracking.ts create mode 100644 src/model/NextCouriersTrackingCreateTrackingRequest.ts create mode 100644 src/model/Notification.ts create mode 100644 src/model/NotificationRequestV1.ts create mode 100644 src/model/NotificationResponseV1.ts create mode 100644 src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest.ts create mode 100644 src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse.ts create mode 100644 src/model/OriginAddressEstimatedDeliveryDateRequest.ts create mode 100644 src/model/OriginAddressEstimatedDeliveryDateResponse.ts create mode 100644 src/model/Pagination.ts create mode 100644 src/model/PartialDeleteTracking.ts create mode 100644 src/model/PartialUpdateTracking.ts create mode 100644 src/model/PredictBatchRequest.ts create mode 100644 src/model/PredictBatchResponse.ts create mode 100644 src/model/ReasonEventsCheckpoint.ts create mode 100644 src/model/RetrackTrackingBySlugTrackingNumberQuery.ts create mode 100644 src/model/SlugGroupV1.ts create mode 100644 src/model/TagV1.ts create mode 100644 src/model/Tracking.ts create mode 100644 src/model/TrackingCreateTrackingRequest.ts create mode 100644 src/model/TrackingDeleteResponseV1.ts create mode 100644 src/model/TrackingDetectCourierRequest.ts create mode 100644 src/model/TrackingResponseGetMultipleV1.ts create mode 100644 src/model/TrackingResponseV1.ts create mode 100644 src/model/TrackingUpdateTrackingByIdRequest.ts create mode 100644 src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts create mode 100644 src/model/UpdateTrackingBySlugTrackingNumberQuery.ts create mode 100644 src/model/WeightEstimatedDeliveryDateRequest.ts create mode 100644 src/model/WeightEstimatedDeliveryDateResponse.ts create mode 100644 src/utils/parse_proxy.ts create mode 100644 tsconfig.json diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b9d2058 --- /dev/null +++ b/Jenkinsfile @@ -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 : "" + ] +} diff --git a/README.md b/README.md index fc48dc4..a37b621 100644 --- a/README.md +++ b/README.md @@ -1 +1,345 @@ -# tracking-sdk-nodejs \ No newline at end of file +# AfterShip Tracking API library for Node.js + +This library allows you to quickly and easily use the AfterShip Tracking API via Node.js. + +For updates to this library, see our GitHub release page. + +If you need support using AfterShip products, please contact support@aftership.com. + +## Table of Contents + +- [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) + - [Quick Start](#quick-start) + - [Installation](#installation) + - [Usage](#usage) + - [Constructor](#constructor) + - [Example](#example) + - [Rate Limiter](#rate-limiter) + - [Error Handling](#error-handling) + - [Error List](#error-list) + - [Endpoints](#endpoints) + - [/trackings](#trackings) + - [/couriers](#couriers) + - [/last\_checkpoint](#last_checkpoint) + - [/notifications](#notifications) + - [Help](#help) + - [License](#license) + + +## Before you begin + +Before you begin to integrate: + +- [Create an AfterShip account](https://admin.aftership.com/). +- [Create an API key](https://organization.automizely.com/api-keys). +- [Install Node.js](https://nodejs.org/en/download/) version 16 or later. + +## Quick Start + +### Installation +```bash +npm install --save aftership +``` + +### Usage +```javascript +// Step 1: Require the AfterShip client +import {AfterShip} from '@aftership/tracking-sdk'; +// or +const {AfterShip} = require('@aftership/tracking-sdk'); + + +// Step 2: Initialize the client object +const aftership = new AfterShip({api_key: 'YOUR_API_KEY'}); + +// Step 3: Create the request object +const createTrackingRequestBody = { + tracking_number: 'I-1-234567654654', + slug: 'testing-courier' +}; + +// Step 4: Make the request +aftership.tracking.createTracking(createTrackingRequestBody) + .then(tracking => console.log(tracking)) + .catch(error => console.log(error)); +``` + + +## Constructor + +Create AfterShip instance with options + +| Name | Type | Required | Description | +|------------|--------|----------|-----------------------------------------------------------------------------------------------------------------------------------| +| api_key | string | ✔ | Your AfterShip API key | +| auth_type | enum | | Default value: `AuthType.API_KEY`
AES authentication: `AuthType.AES`
RSA authentication: `AuthType.RSA` | +| api_secret | string | | Required if the authentication type is `AuthType.AES` or `AuthType.RSA` | +| domain | string | | AfterShip API domain. Default value: https://api.aftership.com | +| user_agent | string | | User-defined user-agent string, please follow [RFC9110](https://www.rfc-editor.org/rfc/rfc9110#field.user-agent) format standard. | +| proxy | string | | HTTP proxy URL to use for requests.
Default value: `null`
Example: `http://192.168.0.100:8888` | +| max_retry | number | | Number of retries for each request. Default value: 2. Min is 0, Max is 10. | +| timeout | number | | Timeout for each request in milliseconds. | + +### Example + +```javascript +import {AfterShip, AuthType} from '@aftership/tracking-sdk'; +// or +const {AfterShip, AuthType} = require('@aftership/tracking-sdk'); + +const aftership = new AfterShip( + { + api_key: 'YOUR_API_KEY', + api_secret: 'YOUR_API_SECRET', + auth_type: AuthType.AES + } +); +``` + +## Rate Limiter + +See the [Rate Limit](https://www.aftership.com/docs/aftership/quickstart/rate-limit) to understand the AfterShip rate limit policy. + +## Error Handling + +The SDK will return an error object when there is any error during the request, with the following specification: + +| Name | Type | Description | +|---------------|--------|--------------------------------| +| message | string | Detail message of the error | +| code | enum | Error code enum for API Error. | +| meta_code | number | API response meta code. | +| status_code | number | HTTP status code. | +| response_body | string | API response body. | + + +### Error List + +| code | meta_code | status_code | message | +|-----------------------------------|------------------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| INVALID_REQUEST | 400 | 400 | The request was invalid or cannot be otherwise served. | +| INVALID_JSON | 4001 | 400 | Invalid JSON data. | +| TRACKING_ALREADY_EXIST | 4003 | 400 | Tracking already exists. | +| TRACKING_DOES_NOT_EXIST | 4004 | 404 | Tracking does not exist. | +| TRACKING_NUMBER_INVALID | 4005 | 400 | The value of tracking_number is invalid. | +| TRACKING_REQUIRED | 4006 | 400 | tracking object is required. | +| TRACKING_NUMBER_REQUIRED | 4007 | 400 | tracking_number is required. | +| VALUE_INVALID | 4008 | 400 | The value of [field_name] is invalid. | +| VALUE_REQUIRED | 4009 | 400 | [field_name] is required. | +| SLUG_INVALID | 4010 | 400 | The value of slug is invalid. | +| MISSING_OR_INVALID_REQUIRED_FIELD | 4011 | 400 | Missing or invalid value of the required fields for this courier. Besides tracking_number, also required: [field_name] | +| BAD_COURIER | 4012 | 400 | The error message will be one of the following:
1. Unable to import shipment as the carrier is not on your approved list for carrier auto-detection. Add the carrier here: https://admin.aftership.com/settings/couriers
2. Unable to import shipment as we don’t recognize the carrier from this tracking number.
3. Unable to import shipment as the tracking number has an invalid format.
4. Unable to import shipment as this carrier is no longer supported.
5. Unable to import shipment as the tracking number does not belong to a carrier in that group. | +| INACTIVE_RETRACK_NOT_ALLOWED | 4013 | 400 | Retrack is not allowed. You can only retrack an inactive tracking. | +| NOTIFICATION_REUQIRED | 4014 | 400 | notification object is required. | +| ID_INVALID | 4015 | 400 | The value of id is invalid. | +| RETRACK_ONCE_ALLOWED | 4016 | 400 | Retrack is not allowed. You can only retrack each shipment once. | +| TRACKING_NUMBER_FORMAT_INVALID | 4017 | 400 | The format of tracking_number is invalid. | +| API_KEY_INVALID | 401 | 401 | The API key is invalid. | +| REQUEST_NOT_ALLOWED | 403 | 403 | The request is understood, but it has been refused or access is not allowed. | +| NOT_FOUND | 404 | 404 | The URI requested is invalid or the resource requested does not exist. | +| TOO_MANY_REQUEST | 429 | 429 | You have exceeded the API call rate limit. The default limit is 10 requests per second. | +| INTERNAL_ERROR | 500 502 503 504 | 500 502 503 504 | Something went wrong on AfterShip's end. | + +## Endpoints + +The AfterShip instance has the following properties which are exactly the same as the API endpoints: + +courier - Get a list of our supported couriers. +tracking - Create trackings, update trackings, and get tracking results. +last_checkpoint - Get tracking information of the last checkpoint of a tracking. +notification - Get, add or remove contacts (sms or email) to be notified when the status of a tracking has changed. + + +### /trackings + +**POST** /trackings + +```javascript +const payload = { + 'slug': 'usps', + 'tracking_number': '9261290284678900371871', + 'title': 'Title Name', + 'smses': [ + '+18555072509', + '+18555072501' + ], + 'emails': [ + 'email@yourdomain.com', + 'another_email@yourdomain.com' + ], + 'order_id': 'ID 1234', + 'order_id_path': 'http://www.aftership.com/order_id=1234', + 'custom_fields': { + 'product_name': 'iPhone Case', + 'product_price': 'USD19.99' + } +}; + +aftership.tracking + .createTracking(payload) + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**DELETE** /trackings/:id + +```javascript +aftership.tracking + .deleteTrackingById('g0qe97idgrrbrlwiyvzco018') + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**GET** /trackings + +```javascript +aftership.tracking + .getTrackings({ page: 1, limit: 10, fields: 'slug,tracking_number' }) + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**GET** /trackings/:id + +```javascript +aftership.tracking + .getTrackingById('rft4xu2rs1um1lwhm8j1p02r') + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +```javascript +// GET /trackings/:slug/:tracking_number?tracking_postal_code=:postal_code&tracking_ship_date=:ship_date +aftership.tracking + .getTrackingBySlugTrackingNumber('dhl-global-mail', '420028359261290339630717209661', { + tracking_postal_code: "1234", + tracking_ship_date: "20200423", + }) + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + + +> Pro Tip: You can always use /:id to replace /:slug/:tracking_number. +```javascript +// GET /trackings/:id +aftership.tracking + .getTrackingById('hqhyzb21sm0colweuats7001') + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**PUT** /trackings/:id + +```javascript +aftership.tracking + .updateTrackingById('hqhyzb21sm0colweuats7001',{title: 'New Title123'}) + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**POST** /trackings/:id/retrack + +```javascript +aftership.tracking + .retrackTrackingById('hqhyzb21sm0colweuats7001') + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +**POST** /trackings/:id/mark-as-completed + +```javascript +aftership.tracking + .markTrackingCompletedById('hqhyzb21sm0colweuats7001', { reason: 'DELIVERED' }) + .then((result) => console.log(result)) + .catch((e) => console.log(e)); +``` + +### /couriers +**GET** /couriers + +```javascript +aftership.courier + .getUserCouriers() + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +**GET** /couriers/all + +```javascript +aftership.courier + .getAllCouriers() + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +**POST** /couriers/detect + +```js +aftership.courier + .detectCourier({ tracking_number: '4209803811639200190316175613986809' }) + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +### /last_checkpoint + +**GET** /last_checkpoint/:id + +```javascript +aftership.lastCheckpoint + .getCheckpointByTrackingId('g0qe97idgrrbrlwiyvzco018') + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +### /notifications + +**GET** /notifications/:id + +```javascript +aftership.notification + .getNotificationByTrackingId('mg7ocgcbeicjqlrytw85600u') + .then(result => console.log(result)) + .catch(err => console.log(err)); +``` + +**POST** /notifications/:id/add + +```javascript +aftership.notification + .addNotificationByTrackingId('g0qe97idgrrbrlwiyvzco018',{ + 'emails': 'user1@gmail.com,user2@gmail.com,invalid EMail @ Gmail. com', + 'smses': '+85291239123,+85261236123,Invalid Mobile Phone Number' + }) + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +**POST** /notifications/:id/remove + +```javascript +aftership.notification + .deleteNotificationByTrackingId('g0qe97idgrrbrlwiyvzco018',{ + 'emails': 'user1@gmail.com', + 'smses': '+85291239123' + }) + .then(result => console.log(result)) + .catch(e => console.log(e)); +``` + +## Help + +If you get stuck, we're here to help: + +- [Issue Tracker](https://github.com/AfterShip/tracking-sdk-nodejs/issues) for questions, feature requests, bug reports and general discussion related to this package. Try searching before you create a new issue. +- Contact AfterShip official support via support@aftership.com + +## License +Copyright (c) 2024 AfterShip + +Licensed under the MIT license. \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..4d30c9b --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/src/aftership.ts b/src/aftership.ts new file mode 100644 index 0000000..bfd469b --- /dev/null +++ b/src/aftership.ts @@ -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 }; \ No newline at end of file diff --git a/src/api/Courier.ts b/src/api/Courier.ts new file mode 100644 index 0000000..4dcb120 --- /dev/null +++ b/src/api/Courier.ts @@ -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 { + + return this.request.makeRequest({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 { + + return this.request.makeRequest({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 { + + return this.request.makeRequest({url: `/tracking/2024-04/couriers/detect`, method: "POST", body, headers, request_legacy_tag: "tracking", response_legacy_tag: "", is_paging: false}) + } +} \ No newline at end of file diff --git a/src/api/EstimatedDeliveryDate.ts b/src/api/EstimatedDeliveryDate.ts new file mode 100644 index 0000000..83f4459 --- /dev/null +++ b/src/api/EstimatedDeliveryDate.ts @@ -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 { + + return this.request.makeRequest({url: `/tracking/2024-04/estimated-delivery-date/predict-batch`, method: "POST", body, headers, request_legacy_tag: "", response_legacy_tag: "", is_paging: false}) + } +} \ No newline at end of file diff --git a/src/api/LastCheckpoint.ts b/src/api/LastCheckpoint.ts new file mode 100644 index 0000000..ed5041f --- /dev/null +++ b/src/api/LastCheckpoint.ts @@ -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 { + 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/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 new file mode 100644 index 0000000..4836ed3 --- /dev/null +++ b/src/api/Notification.ts @@ -0,0 +1,116 @@ +/* + * 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 { NotificationRequestV1 } from "../model/NotificationRequestV1"; +import { DeleteNotificationBySlugTrackingNumberQuery } from "../model/DeleteNotificationBySlugTrackingNumberQuery"; +import { Notification } from "../model/Notification"; +import { GetNotificationBySlugTrackingNumberQuery } from "../model/GetNotificationBySlugTrackingNumberQuery"; +import { AddNotificationBySlugTrackingNumberQuery } from "../model/AddNotificationBySlugTrackingNumberQuery"; + +export class NotificationApi { + private readonly request: Request; + + constructor(request: Request) { + 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. + */ + public async deleteNotificationByTrackingId(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}/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. + */ + public async getNotificationBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetNotificationBySlugTrackingNumberQuery, 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}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "notification", is_paging: false}) + } + /** + * Add notification receivers to a tracking number. + */ + 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", + 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}/add`, method: "POST", body, query, 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. + */ + public async getNotificationByTrackingId(tracking_id: string, 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}`, method: "GET", headers, request_legacy_tag: "", 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}) + } +} \ No newline at end of file diff --git a/src/api/Tracking.ts b/src/api/Tracking.ts new file mode 100644 index 0000000..7bae783 --- /dev/null +++ b/src/api/Tracking.ts @@ -0,0 +1,205 @@ +/* + * 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 { 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 { 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 { GetTrackingsQuery } from "../model/GetTrackingsQuery"; +import { GetTrackingsResponse } from "../model/GetTrackingsResponse"; +import { GetTrackingBySlugTrackingNumberQuery } from "../model/GetTrackingBySlugTrackingNumberQuery"; + +export class TrackingApi { + private readonly request: Request; + + constructor(request: Request) { + this.request = request; + } + + /** + * Get tracking results of a single tracking. + */ + public async getTrackingById(id: string, query?: GetTrackingByIdQuery, 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}`, 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. + */ + public async deleteTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: DeleteTrackingBySlugTrackingNumberQuery, 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/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}) + } + /** + * Update a tracking. + */ + public async updateTrackingBySlugTrackingNumber(slug: string, tracking_number: string, body: TrackingUpdateTrackingBySlugTrackingNumberRequest,query?: UpdateTrackingBySlugTrackingNumberQuery, 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/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. + */ + public async retrackTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: RetrackTrackingBySlugTrackingNumberQuery, 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/trackings/${slug}/${tracking_number}/retrack`, method: "POST", 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 markTrackingCompletedBySlugTrackingNumber(slug: string, tracking_number: string, body: MarkTrackingCompletedBySlugTrackingNumberRequest,query?: MarkTrackingCompletedBySlugTrackingNumberQuery, 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/trackings/${slug}/${tracking_number}/mark-as-completed`, method: "POST", body, query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + } + /** + * Update a tracking. + */ + public async updateTrackingById(id: string, body: TrackingUpdateTrackingByIdRequest, 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}`, method: "PUT", body, headers, request_legacy_tag: "tracking", 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}) + } + /** + * Delete a tracking. + */ + public async deleteTrackingById(id: string, 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}`, method: "DELETE", headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + } + /** + * Retrack an expired tracking. Max 3 times per tracking. + */ + public async retrackTrackingById(id: string, 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}/retrack`, method: "POST", headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + } + /** + * Get tracking results of a single tracking. + */ + public async getTrackingBySlugTrackingNumber(slug: string, tracking_number: string, query?: GetTrackingBySlugTrackingNumberQuery, 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/trackings/${slug}/${tracking_number}`, method: "GET", query, headers, request_legacy_tag: "", response_legacy_tag: "tracking", is_paging: false}) + } +} \ No newline at end of file diff --git a/src/error/code.ts b/src/error/code.ts new file mode 100644 index 0000000..c7d326c --- /dev/null +++ b/src/error/code.ts @@ -0,0 +1,32 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export enum AfterShipErrorCodes { + INVALID_API_KEY = "INVALID_API_KEY", + INVALID_OPTION = "INVALID_OPTION", + RATE_LIMIT_EXCEED = "RATE_LIMIT_EXCEED", + TIMED_OUT = "TIMED_OUT", + INVALID_REQUEST = "INVALID_REQUEST", + INVALID_JSON = "INVALID_JSON", + TRACKING_ALREADY_EXIST = "TRACKING_ALREADY_EXIST", + TRACKING_DOES_NOT_EXIST = "TRACKING_DOES_NOT_EXIST", + TRACKING_NUMBER_INVALID = "TRACKING_NUMBER_INVALID", + TRACKING_REQUIRED = "TRACKING_REQUIRED", + TRACKING_NUMBER_REQUIRED = "TRACKING_NUMBER_REQUIRED", + VALUE_INVALID = "VALUE_INVALID", + VALUE_REQUIRED = "VALUE_REQUIRED", + SLUG_INVALID = "SLUG_INVALID", + MISSING_OR_INVALID_REQUIRED_FIELD = "MISSING_OR_INVALID_REQUIRED_FIELD", + BAD_COURIER = "BAD_COURIER", + INACTIVE_RETRACK_NOT_ALLOWED = "INACTIVE_RETRACK_NOT_ALLOWED", + NOTIFICATION_REUQIRED = "NOTIFICATION_REUQIRED", + ID_INVALID = "ID_INVALID", + RETRACK_ONCE_ALLOWED = "RETRACK_ONCE_ALLOWED", + TRACKING_NUMBER_FORMAT_INVALID = "TRACKING_NUMBER_FORMAT_INVALID", + API_KEY_INVALID = "API_KEY_INVALID", + REQUEST_NOT_ALLOWED = "REQUEST_NOT_ALLOWED", + NOT_FOUND = "NOT_FOUND", + TOO_MANY_REQUEST = "TOO_MANY_REQUEST", + INTERNAL_ERROR = "INTERNAL_ERROR", +} \ No newline at end of file diff --git a/src/error/index.ts b/src/error/index.ts new file mode 100644 index 0000000..e6c8373 --- /dev/null +++ b/src/error/index.ts @@ -0,0 +1,25 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { AfterShipErrorCodes } from "./code"; + +export class AftershipError extends Error { + public readonly meta_code: number | null; + public readonly message: string; + public readonly code: AfterShipErrorCodes | null; + public readonly status_code: string | null; + public readonly response_body: any | null; + + constructor(message: string, code: AfterShipErrorCodes, meta_code?: number, status_code?: string, response_body?: any) { + super(message); + this.message = message; + this.code = code; + this.meta_code = meta_code || null; + this.status_code = status_code || null; + this.response_body = response_body || null; + } +} + +export * from "./code"; +export * from "./meta_code"; diff --git a/src/error/meta_code.ts b/src/error/meta_code.ts new file mode 100644 index 0000000..2bcbc61 --- /dev/null +++ b/src/error/meta_code.ts @@ -0,0 +1,33 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { AfterShipErrorCodes } from "./code"; + +export const AfterShipMetaCodeMap: {[key: string]: AfterShipErrorCodes} = { + "400": AfterShipErrorCodes.INVALID_REQUEST, + "4001": AfterShipErrorCodes.INVALID_JSON, + "4003": AfterShipErrorCodes.TRACKING_ALREADY_EXIST, + "4004": AfterShipErrorCodes.TRACKING_DOES_NOT_EXIST, + "4005": AfterShipErrorCodes.TRACKING_NUMBER_INVALID, + "4006": AfterShipErrorCodes.TRACKING_REQUIRED, + "4007": AfterShipErrorCodes.TRACKING_NUMBER_REQUIRED, + "4008": AfterShipErrorCodes.VALUE_INVALID, + "4009": AfterShipErrorCodes.VALUE_REQUIRED, + "4010": AfterShipErrorCodes.SLUG_INVALID, + "4011": AfterShipErrorCodes.MISSING_OR_INVALID_REQUIRED_FIELD, + "4012": AfterShipErrorCodes.BAD_COURIER, + "4013": AfterShipErrorCodes.INACTIVE_RETRACK_NOT_ALLOWED, + "4014": AfterShipErrorCodes.NOTIFICATION_REUQIRED, + "4015": AfterShipErrorCodes.ID_INVALID, + "4016": AfterShipErrorCodes.RETRACK_ONCE_ALLOWED, + "4017": AfterShipErrorCodes.TRACKING_NUMBER_FORMAT_INVALID, + "401": AfterShipErrorCodes.API_KEY_INVALID, + "403": AfterShipErrorCodes.REQUEST_NOT_ALLOWED, + "404": AfterShipErrorCodes.NOT_FOUND, + "429": AfterShipErrorCodes.TOO_MANY_REQUEST, + "500": AfterShipErrorCodes.INTERNAL_ERROR, + "502": AfterShipErrorCodes.INTERNAL_ERROR, + "503": AfterShipErrorCodes.INTERNAL_ERROR, + "504": AfterShipErrorCodes.INTERNAL_ERROR, +} \ No newline at end of file diff --git a/src/lib/authentication.ts b/src/lib/authentication.ts new file mode 100644 index 0000000..6cb8527 --- /dev/null +++ b/src/lib/authentication.ts @@ -0,0 +1,116 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import crypto from "crypto"; + +const SEPERATOR = "\n"; + +export enum AuthType { + API_KEY = "API_KEY", + AES = "AES", + RSA = "RSA", +} + +interface SignParams { + url: string, + method: string, + body?: string, + content_type?: string, + date: string, + headers: { [key: string]: any }, + query?: any, + private_key?: string, + auth_type: string, +} + +export class Authentication { + public static sign(params: SignParams): string { + const canonicalized_headers = this.canonicalizedHeaders(params.headers); + const canonicalized_resource = this.canonicalizedResource(params.url, params.query); + const sign_message = this.signMessage(params.method, params.date, canonicalized_headers, canonicalized_resource, params.body, params.content_type); + if (params.auth_type === AuthType.AES) { + return this.signAES(sign_message, params.private_key); + } else if (params.auth_type === AuthType.RSA) { + return this.signRSA(sign_message, params.private_key); + } + return ""; + } + + private static signAES(message: any, private_key: string = ""): string { + const hmac = crypto.createHmac('sha256', private_key); + hmac.update(message); + + const signature = hmac.digest('base64'); + return signature; + } + + private static signRSA(message: any, private_key: string = ""): string { + const signer = crypto.createSign("RSA-SHA256"); + signer.update(message); + + const signature = signer.sign({ + key: private_key, + padding: crypto.constants.RSA_PKCS1_PSS_PADDING, + saltLength: crypto.constants.RSA_PSS_SALTLEN_DIGEST, + }); + + return signature.toString("base64"); + } + + public static signMessage( + method: string, + date: string, + canonicalized_headers: string, + canonicalized_resource: string, + body?: string, + content_type?: string, + ): string { + let result: string = method + SEPERATOR; + let md5_body = ''; + let _content_type = content_type; + if (body === undefined || body === null || body.length === 0) { + _content_type = ''; + } else { + const md5 = crypto.createHash('md5'); + md5_body = md5.update(body).digest('hex').toUpperCase(); + } + result += md5_body + SEPERATOR; + result += _content_type + SEPERATOR; + result += date + SEPERATOR; + result += canonicalized_headers + SEPERATOR; + result += canonicalized_resource; + return result; + } + + private static canonicalizedHeaders(headers: { [key: string]: any }): string { + const concatenate_headers: string[] = []; + const all_header_keys = Object.keys(headers).sort(); + for (const k of all_header_keys) { + if (k.startsWith("as")) { + const header_value = headers[k]; + concatenate_headers.push( + `${k.trim()}:${header_value ? header_value.trim() : ""}` + ); + } + } + return concatenate_headers.join("\n"); + } + + private static canonicalizedResource(url: string, query: any): string { + if (query) { + const query_keys = Object.keys(query).sort(); + const concatenate_querys: string[] = []; + if (query_keys.length) { + for (const k of query_keys) { + const qeury_value = query[k]; + concatenate_querys.push( + `${k.trim()}=${qeury_value ? qeury_value.trim() : ""}` + ); + } + } + return `${url}?${concatenate_querys.join("&")}`; + } + return url; + } +} diff --git a/src/lib/rate_limit.ts b/src/lib/rate_limit.ts new file mode 100644 index 0000000..4b83d0e --- /dev/null +++ b/src/lib/rate_limit.ts @@ -0,0 +1,24 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +interface _RateLimit { + x_ratelimit_reset: string; + x_ratelimit_limit: string; + x_ratelimit_remaining: string; +} + +export class RateLimit { + protected _ratelimit?: _RateLimit; + + set ratelimit(r: _RateLimit) { + this._ratelimit = r; + } + + public isExceeded(): boolean { + if (!this._ratelimit) { + return false; + } + return this._ratelimit.x_ratelimit_remaining === "0" && this._ratelimit.x_ratelimit_reset >= new Date().valueOf().toString(); + } +} \ No newline at end of file diff --git a/src/lib/request.ts b/src/lib/request.ts new file mode 100644 index 0000000..eaa2579 --- /dev/null +++ b/src/lib/request.ts @@ -0,0 +1,237 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import axios, { AxiosRequestConfig } from "axios"; +import { AuthType, Authentication } from "./authentication"; +import { RateLimit } from "./rate_limit"; +import { AftershipError } from "../error"; +import { AfterShipErrorCodes } from "../error/code"; +import { AfterShipMetaCodeMap } from "../error/meta_code"; +import { Proxy } from "../utils/parse_proxy"; + +export const DEFAULT_DOMAIN = "https://api.aftership.com"; +export const DEFAULT_TIMEOUT = 10000; +export const DEFAULT_MAX_RETRY = 3; +export const MAX_MAX_RETRY = 10; +export const MIN_MAX_RETRY = 0; +export const DEFAULT_USER_AGENT = "tracking-sdk-nodejs/9.0.0 (https://www.aftership.com) axios/1.7.2"; + +type ResponseData = { + meta: { + code: number; + message: number; + type: string; + }, + data: any; +} + +export interface RequestConfig { + url: string; + method: string; + body?: any; + query?: any; + headers?: { [key: string]: any }; + request_legacy_tag: string; + response_legacy_tag: string; + is_paging: boolean; +} + +export interface RequestOptions { + auth_type: string; + api_key?: string; + api_secrect?: string; + domain: string; + max_retry: number; + timeout: number; + user_agent?: string; + proxy?: Proxy; +} + +export class Request { + private readonly options: RequestOptions; + private readonly ratelimit: RateLimit; + + private readonly DELAY_BASE = 3000; + + constructor(options: RequestOptions) { + this.options = options; + this.ratelimit = new RateLimit(); + } + + private getHeaders(config: RequestConfig): { [key: string]: any } { + const content_type = "application/json"; + const headers: { [key: string]: any } = { + "as-api-key": this.options.api_key, + "Content-Type": content_type, + "User-Agent": this.options.user_agent || DEFAULT_USER_AGENT, + "aftership-client": DEFAULT_USER_AGENT, + ...config.headers, + }; + + if ( + this.options.auth_type === AuthType.AES || + this.options.auth_type === AuthType.RSA + ) { + const header_keys = this.options.auth_type === AuthType.AES ? "as-signature-hmac-sha256" : "as-signature-rsa-sha256" + const date_now = new Date().toUTCString(); + headers[header_keys] = Authentication.sign({ + method: config.method, + url: config.url, + body: config.body, + content_type, + query: config.query, + auth_type: this.options.auth_type, + date: date_now, + private_key: this.options.api_secrect, + headers, + }); + headers["date"] = date_now; + } + return headers; + } + + private shouldRetry(error: any): boolean { + if (error.code === "ECONNABORTED") { + return true; + } + if (error.response && error.response.status >= 500) { + return true; + } + return false; + } + + private delayWithJitter(retry_attempt: number): Promise { + const delay = (this.DELAY_BASE * 2) ^ (retry_attempt - 1); + + // jitter between -halfOfTheDelay seconds and halfOfTheDelay seconds + const jitter = delay * (Math.random() - 0.5); + + // to ensure the delay would not be less than 1 second even if the delayBase is smaller than 2 + const totalDelay = Math.max(1, delay + jitter); + + return new Promise((resolve) => { + setTimeout(resolve, totalDelay); + }); + } + + private setRateLimit(headers: any) { + if ( + headers && + headers["x-ratelimit-reset"] !== undefined && + headers["x-ratelimit-limit"] !== undefined && + headers["x-ratelimit-remaining"] !== undefined + ) { + this.ratelimit.ratelimit = { + x_ratelimit_remaining: headers["x-ratelimit-remaining"], + x_ratelimit_limit: headers["x-ratelimit-limit"], + x_ratelimit_reset: headers["x-ratelimit-reset"], + }; + } + } + + private async withRetry(requestConfig: AxiosRequestConfig, retry: number = 0): Promise { + try { + if (this.ratelimit.isExceeded()) { + throw new AftershipError( + "You have exceeded the API call rate limit. The default limit is 10 requests per second.", + AfterShipErrorCodes.RATE_LIMIT_EXCEED + ); + } + const response = await axios(requestConfig); + this.setRateLimit(response.headers); + return response.data; + } catch (error: any) { + if (error.response && error.response.headers) { + this.setRateLimit(error.response.headers); + } + if (this.shouldRetry(error) && retry < this.options.max_retry) { + await this.delayWithJitter(retry); + retry++; + return this.withRetry(requestConfig, retry); + } + throw error; + } + } + + public async makeRequest(config: RequestConfig): Promise { + const headers = this.getHeaders(config); + try { + const response = await this.withRetry( + { + url: config.url, + method: config.method, + headers, + params: config.query, + validateStatus: (status) => status >= 200 && status < 400, + baseURL: this.options.domain, + data: this.handleRequestData(config.request_legacy_tag, config.body), + timeout: this.options.timeout, + proxy: this.options.proxy, + } + ); + return this.handleResponseData(config.response_legacy_tag, config.is_paging, response) + } catch (error) { + throw this.handleError(error); + } + } + + private handleError(e: any): Error { + if (e.code === "ECONNABORTED") { + return new AftershipError( + "Request timed out.", + AfterShipErrorCodes.TIMED_OUT + ); + } else if (e instanceof AftershipError) { + return e; + } else if (e.response && e.response.status >= 500) { + return new AftershipError( + e.response?.data?.meta?.message || e.message, + AfterShipErrorCodes.INTERNAL_ERROR, + e.response.status, + e.response.status, + JSON.stringify(e.response?.data) + ); + } else { + return new AftershipError( + e.response?.data?.meta?.message, + AfterShipMetaCodeMap[e.response?.data?.meta?.code?.toString()], + e.response?.data?.meta?.code, + e.response?.status, + JSON.stringify(e.response?.data) + ); + } + } + + private handleResponseData(response_legacy_tag: string, is_paging: boolean, data: ResponseData): R { + if (response_legacy_tag && !is_paging) { + return data.data[response_legacy_tag]; + } + if (response_legacy_tag && is_paging) { + const pagination: any = { + page: data.data.page, + limit: data.data.limit, + has_next_page: data.data.has_next_page, + }; + let total: any; + if (data.data.total === undefined) { + total = data.data.count; + } + pagination.total = total; + return { + [response_legacy_tag]: data.data[response_legacy_tag], + pagination, + } as R + } + return data.data; + } + + private handleRequestData(request_legacy_tag: string, data: any): any { + if (!request_legacy_tag) { + return data; + } + return { + [request_legacy_tag]: data + } + } +} diff --git a/src/model/AddNotificationBySlugTrackingNumberQuery.ts b/src/model/AddNotificationBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..5603578 --- /dev/null +++ b/src/model/AddNotificationBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface AddNotificationBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/AdditionalFieldsV1.ts b/src/model/AdditionalFieldsV1.ts new file mode 100644 index 0000000..305c596 --- /dev/null +++ b/src/model/AdditionalFieldsV1.ts @@ -0,0 +1,15 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + + +export enum AdditionalFieldsV1 { + "tracking_account_number" = "tracking_account_number", + "tracking_postal_code" = "tracking_postal_code", + "tracking_ship_date" = "tracking_ship_date", + "tracking_key" = "tracking_key", + "tracking_origin_country" = "tracking_origin_country", + "tracking_destination_country" = "tracking_destination_country", + "tracking_state" = "tracking_state", +} diff --git a/src/model/AftershipEstimatedDeliveryDateTracking.ts b/src/model/AftershipEstimatedDeliveryDateTracking.ts new file mode 100644 index 0000000..b0bd3b4 --- /dev/null +++ b/src/model/AftershipEstimatedDeliveryDateTracking.ts @@ -0,0 +1,24 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface AftershipEstimatedDeliveryDateTracking { + /** + * The estimated arrival date of the shipment. + */ + estimated_delivery_date?: string; + /** + * Indicates the confidence level and associated reason for an AI EDD prediction request. For a comprehensive list of confidence codes, refer to . + */ + confidence_code?: number; + /** + * Earliest estimated delivery date of the shipment. + */ + estimated_delivery_date_min?: string; + /** + * Latest estimated delivery date of the shipment. + */ + estimated_delivery_date_max?: string; +} + diff --git a/src/model/CarbonEmissionsTracking.ts b/src/model/CarbonEmissionsTracking.ts new file mode 100644 index 0000000..7277424 --- /dev/null +++ b/src/model/CarbonEmissionsTracking.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface CarbonEmissionsTracking { + /** + * The unit in which the value field is expressed. Allowed values: kg + */ + unit?: string; + /** + * The total amount of carbon emissions + */ + value?: number; +} + diff --git a/src/model/Checkpoint.ts b/src/model/Checkpoint.ts new file mode 100644 index 0000000..c0db1ab --- /dev/null +++ b/src/model/Checkpoint.ts @@ -0,0 +1,75 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { CoordinateCheckpoint } from "./CoordinateCheckpoint"; +import { TagV1 } from "./TagV1"; +import { EventsCheckpoint } from "./EventsCheckpoint"; + +export interface Checkpoint { + /** + * The date and time of the checkpoint event was added to AfterShip. It uses the format `YYYY-MM-DDTHH:mm:ssZ` for the timezone GMT +0. + */ + created_at?: string; + /** + * The unique code of courier for this checkpoint. Get courier slug + */ + slug?: string; + /** + * The date and time of the checkpoint event, provided by the carrier. It uses the timezone of the checkpoint. The format may differ depending on how the carrier provides it:- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ + */ + checkpoint_time?: string; + /** + * Location info provided by carrier + */ + location?: string; + /** + * City info provided by carrier + */ + city?: string; + /** + * State info provided by carrier + */ + state?: string; + /** + * Postal code info provided by carrier + */ + zip?: string; + /** + * The latitude and longitude coordinates indicate the precise location of the shipments that are currently in transit. + */ + coordinate?: CoordinateCheckpoint; + /** + * Country/Region ISO Alpha-3 (three letters) of the checkpoint + */ + country_iso3?: string; + /** + * Country/Region name of the checkpoint, may also contain other location info. + */ + country_name?: string; + /** + * Checkpoint message + */ + message?: string; + /** + * Current status of tracking. ( + */ + tag?: TagV1; + /** + * Current subtag of checkpoint. ( + */ + subtag?: string; + /** + * Normalized checkpoint message. ( + */ + subtag_message?: string; + /** + * Checkpoint raw status provided by courier + */ + raw_tag?: string; + /** + * The array provides details about specific event(s) that occurred to a shipment, such as "returned_to_sender". You can find the full list of events and reasons </span>- The events' value for the same checkpoint message is subject to change as we consistently strive to enhance the performance of this feature. + */ + events?: EventsCheckpoint[]; +} + diff --git a/src/model/CoordinateCheckpoint.ts b/src/model/CoordinateCheckpoint.ts new file mode 100644 index 0000000..433048b --- /dev/null +++ b/src/model/CoordinateCheckpoint.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface CoordinateCheckpoint { + /** + * Represents the latitude. + */ + latitude?: number; + /** + * Represents the longitude. + */ + longitude?: number; +} + diff --git a/src/model/Courier.ts b/src/model/Courier.ts new file mode 100644 index 0000000..c47c3b2 --- /dev/null +++ b/src/model/Courier.ts @@ -0,0 +1,48 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface Courier { + /** + * Unique code of courier. Get the slugs from . + */ + slug?: string; + /** + * Name of courier + */ + name?: string; + /** + * Contact phone number of courier + */ + phone?: string; + /** + * Other name of courier + */ + other_name?: string; + /** + * Website link of courier + */ + web_url?: string; + /** + * The extra fields need for tracking, such as `tracking_account_number`, `tracking_postal_code`, `tracking_ship_date`, `tracking_key`, `tracking_destination_country` + */ + required_fields?: string[]; + /** + * The extra fields which are optional for tracking. Basically it's the same as required_fields, but the difference is that only some of the tracking numbers require these fields. + */ + optional_fields?: string[]; + /** + * Default language of tracking results + */ + default_language?: string; + /** + * Other supported languages + */ + support_languages?: string[]; + /** + * Country/Region code (ISO Alpha-3) where the courier provides service + */ + service_from_country_iso3?: string[]; +} + diff --git a/src/model/CourierResponseV1.ts b/src/model/CourierResponseV1.ts new file mode 100644 index 0000000..6a64342 --- /dev/null +++ b/src/model/CourierResponseV1.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { MetaV1 } from "./MetaV1"; +import { DataCourierResponseV1 } from "./DataCourierResponseV1"; + +export interface CourierResponseV1 { + /** + * Meta data + */ + meta: MetaV1; + /** + * + */ + data: DataCourierResponseV1; +} + diff --git a/src/model/CustomEstimatedDeliveryDateTracking.ts b/src/model/CustomEstimatedDeliveryDateTracking.ts new file mode 100644 index 0000000..548a62d --- /dev/null +++ b/src/model/CustomEstimatedDeliveryDateTracking.ts @@ -0,0 +1,24 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface CustomEstimatedDeliveryDateTracking { + /** + * The format of the EDD. Either a single date or a date range. + */ + type?: string; + /** + * The specific EDD date. + */ + datetime?: string; + /** + * For a date range EDD format, the date for the lower end of the range. + */ + datetime_min?: string; + /** + * For a date range EDD format, the date for the upper end of the range. + */ + datetime_max?: string; +} + diff --git a/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts b/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts new file mode 100644 index 0000000..119f547 --- /dev/null +++ b/src/model/CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest.ts @@ -0,0 +1,8 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest { +} + diff --git a/src/model/DataCourierResponseV1.ts b/src/model/DataCourierResponseV1.ts new file mode 100644 index 0000000..b1d25e1 --- /dev/null +++ b/src/model/DataCourierResponseV1.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Courier } from "./Courier"; + +export interface DataCourierResponseV1 { + /** + * Total count of courier objects + */ + total?: number; + /** + * Array of object. + */ + couriers?: Courier[]; +} + diff --git a/src/model/DataNotificationResponseV1.ts b/src/model/DataNotificationResponseV1.ts new file mode 100644 index 0000000..8925e2d --- /dev/null +++ b/src/model/DataNotificationResponseV1.ts @@ -0,0 +1,13 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Notification } from "./Notification"; + +export interface DataNotificationResponseV1 { + /** + * Object describes the notification information. + */ + notification?: Notification; +} + diff --git a/src/model/DataTrackingDeleteResponseV1.ts b/src/model/DataTrackingDeleteResponseV1.ts new file mode 100644 index 0000000..ec5a318 --- /dev/null +++ b/src/model/DataTrackingDeleteResponseV1.ts @@ -0,0 +1,13 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { PartialDeleteTracking } from "./PartialDeleteTracking"; + +export interface DataTrackingDeleteResponseV1 { + /** + * Partial tracking model + */ + tracking?: PartialDeleteTracking; +} + diff --git a/src/model/DataTrackingResponseGetMultipleV1.ts b/src/model/DataTrackingResponseGetMultipleV1.ts new file mode 100644 index 0000000..ea65f50 --- /dev/null +++ b/src/model/DataTrackingResponseGetMultipleV1.ts @@ -0,0 +1,66 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { TagV1 } from "./TagV1"; +import { Tracking } from "./Tracking"; + +export interface DataTrackingResponseGetMultipleV1 { + /** + * Page to show. (Default: 1) + */ + page?: number; + /** + * Number of trackings each page contain. (Default: 100, Max: 200) + */ + limit?: number; + /** + * Number of returned trackings + */ + count?: number; + /** + * Search the content of the tracking record fields: `tracking_number`, `title`, `order_id`, `customer_name`, `custom_fields`, `order_id`, `emails`, `smses` + */ + keyword?: string; + /** + * Unique + */ + slug?: string; + /** + * Origin country/region of trackings. Use + */ + origin?: string[]; + /** + * Destination country/region of trackings. Use + */ + destination?: string[]; + /** + * Current status of tracking. ( + */ + tag?: TagV1; + /** + * Start date and time of trackings created. AfterShip only stores data of 120 days. + */ + created_at_min?: string; + /** + * End date and time of trackings created. + */ + created_at_max?: string; + /** + * Date and time the tracking was last updated + */ + last_updated_at?: string; + /** + * Whether or not the shipment is returned to sender. Value is `true` when any of its checkpoints has subtag `Exception_010` (returning to sender) or `Exception_011` (returned to sender). Otherwise value is `false` + */ + return_to_sender?: boolean[]; + /** + * Destination country/region of the tracking detected from the courier. ISO Alpha-3 (three letters). Value will be `null` if the courier doesn't provide the destination country. + */ + courier_destination_country_iso3?: string[]; + /** + * Array of + */ + trackings?: Tracking[]; +} + diff --git a/src/model/DataTrackingResponseV1.ts b/src/model/DataTrackingResponseV1.ts new file mode 100644 index 0000000..8917333 --- /dev/null +++ b/src/model/DataTrackingResponseV1.ts @@ -0,0 +1,13 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Tracking } from "./Tracking"; + +export interface DataTrackingResponseV1 { + /** + * Object describes the tracking information.<div style="display:none; height: 0"></div> + */ + tracking?: Tracking; +} + diff --git a/src/model/DeleteNotificationBySlugTrackingNumberQuery.ts b/src/model/DeleteNotificationBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..1829eac --- /dev/null +++ b/src/model/DeleteNotificationBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface DeleteNotificationBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/DeleteTrackingBySlugTrackingNumberQuery.ts b/src/model/DeleteTrackingBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..42df390 --- /dev/null +++ b/src/model/DeleteTrackingBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface DeleteTrackingBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/DestinationAddressEstimatedDeliveryDateRequest.ts b/src/model/DestinationAddressEstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..ec3880f --- /dev/null +++ b/src/model/DestinationAddressEstimatedDeliveryDateRequest.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface DestinationAddressEstimatedDeliveryDateRequest { + /** + * The country/region of the destination location where the package will be delivered. Use 3 letters of ISO 3166-1 country code. + */ + country: string; + /** + * State, province, or the equivalent location of the destination address where the package will be delivered.Either `destination_address.state` or `destination_address.postal_code` is required. + */ + state?: string; + /** + * City of the destination address where the package will be delivered. + */ + city?: string; + /** + * Postal code of the destination address.Either `destination_address.state` or `destination_address.postal_code` is required. + */ + postal_code?: string; + /** + * Raw location of the destination address. A raw address will help AI to identify the accurate location of the destination address. + */ + raw_location?: string; +} + diff --git a/src/model/DestinationAddressEstimatedDeliveryDateResponse.ts b/src/model/DestinationAddressEstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..729a80e --- /dev/null +++ b/src/model/DestinationAddressEstimatedDeliveryDateResponse.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface DestinationAddressEstimatedDeliveryDateResponse { + /** + * The country/region of the destination location where the package will be delivered. Use 3 letters of ISO 3166-1 country code. + */ + country: string; + /** + * State, province, or the equivalent location of the destination address where the package will be delivered.Either `destination_address.state` or `destination_address.postal_code` is required. + */ + state?: string; + /** + * City of the destination address where the package will be delivered. + */ + city?: string; + /** + * Postal code of the destination address.Either `destination_address.state` or `destination_address.postal_code` is required. + */ + postal_code?: string; + /** + * Raw location of the destination address. A raw address will help AI to identify the accurate location of the destination address. + */ + raw_location?: string; +} + diff --git a/src/model/DetectCourierResponse.ts b/src/model/DetectCourierResponse.ts new file mode 100644 index 0000000..eacf5f1 --- /dev/null +++ b/src/model/DetectCourierResponse.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Courier } from "./Courier"; + +export interface DetectCourierResponse { + /** + * Total count of courier objects + */ + total?: number; + /** + * Array of object. + */ + couriers?: Courier[]; +} + diff --git a/src/model/EstimatedDeliveryDateRequest.ts b/src/model/EstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..54ae05b --- /dev/null +++ b/src/model/EstimatedDeliveryDateRequest.ts @@ -0,0 +1,44 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { OriginAddressEstimatedDeliveryDateRequest } from "./OriginAddressEstimatedDeliveryDateRequest"; +import { DestinationAddressEstimatedDeliveryDateRequest } from "./DestinationAddressEstimatedDeliveryDateRequest"; +import { WeightEstimatedDeliveryDateRequest } from "./WeightEstimatedDeliveryDateRequest"; +import { EstimatedPickupEstimatedDeliveryDateRequest } from "./EstimatedPickupEstimatedDeliveryDateRequest"; + +export interface EstimatedDeliveryDateRequest { + /** + * AfterShip's unique code of courier. Please refer to https://track.aftership.com/couriers/download. + */ + slug: string; + /** + * AfterShip’s unique code represents carrier’s shipping and delivery options. Refer to . + */ + service_type_name?: string; + /** + * The location from where the package is picked up by the carrier to be delivered to the final destination. + */ + origin_address: OriginAddressEstimatedDeliveryDateRequest; + /** + * The final destination of the customer where the delivery will be made. + */ + destination_address: DestinationAddressEstimatedDeliveryDateRequest; + /** + * AfterShip uses this object to calculate the total weight of the order. + */ + weight?: WeightEstimatedDeliveryDateRequest; + /** + * The number of packages. + */ + package_count?: number; + /** + * The local pickup time in the origin address time zone of the package.Either `pickup_time` or `estimated_pickup` is required. + */ + pickup_time?: string; + /** + * The local pickup time of the package.Either `pickup_time` or `estimated_pickup` is required. + */ + estimated_pickup?: EstimatedPickupEstimatedDeliveryDateRequest; +} + diff --git a/src/model/EstimatedDeliveryDateResponse.ts b/src/model/EstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..954a8ec --- /dev/null +++ b/src/model/EstimatedDeliveryDateResponse.ts @@ -0,0 +1,60 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { OriginAddressEstimatedDeliveryDateResponse } from "./OriginAddressEstimatedDeliveryDateResponse"; +import { DestinationAddressEstimatedDeliveryDateResponse } from "./DestinationAddressEstimatedDeliveryDateResponse"; +import { WeightEstimatedDeliveryDateResponse } from "./WeightEstimatedDeliveryDateResponse"; +import { EstimatedPickupEstimatedDeliveryDateResponse } from "./EstimatedPickupEstimatedDeliveryDateResponse"; + +export interface EstimatedDeliveryDateResponse { + /** + * AfterShip's unique code of courier. Please refer to https://track.aftership.com/couriers/download. + */ + slug: string; + /** + * AfterShip’s unique code represents carrier’s shipping and delivery options. Refer to . + */ + service_type_name?: string; + /** + * The location from where the package is picked up by the carrier to be delivered to the final destination. + */ + origin_address: OriginAddressEstimatedDeliveryDateResponse; + /** + * The final destination of the customer where the delivery will be made. + */ + destination_address: DestinationAddressEstimatedDeliveryDateResponse; + /** + * AfterShip uses this object to calculate the total weight of the order. + */ + weight?: WeightEstimatedDeliveryDateResponse; + /** + * The number of packages. + */ + package_count?: number; + /** + * The local pickup time in the origin address time zone of the package.Either `pickup_time` or `estimated_pickup` is required. + */ + pickup_time?: string; + /** + * The local pickup time of the package.Either `pickup_time` or `estimated_pickup` is required. + */ + estimated_pickup?: EstimatedPickupEstimatedDeliveryDateResponse; + /** + * The estimated arrival date of the shipment, provided by AfterShip. + */ + estimated_delivery_date?: string; + /** + * Indicates the confidence level and associated reason for an AI EDD prediction request. For a comprehensive list of confidence codes, refer to . + */ + confidence_code?: number; + /** + * The earliest estimated delivery date of the shipment, provided by AfterShip. + */ + estimated_delivery_date_min?: string; + /** + * The latest estimated delivery date of the shipment, provided by AfterShip. + */ + estimated_delivery_date_max?: string; +} + diff --git a/src/model/EstimatedPickupEstimatedDeliveryDateRequest.ts b/src/model/EstimatedPickupEstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..79728c0 --- /dev/null +++ b/src/model/EstimatedPickupEstimatedDeliveryDateRequest.ts @@ -0,0 +1,25 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest } from "./OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest"; + +export interface EstimatedPickupEstimatedDeliveryDateRequest { + /** + * The local order time in the origin address time zone of the package. + */ + order_time: string; + /** + * Order cut off time in the origin address time zone. The default value set by AfterShip is 18:00:00. + */ + order_cutoff_time?: string; + /** + * Operating days in a week. Number refers to the weekday.E.g., [1,2,3,4,5] means operating days are from Monday to Friday.AfterShip will set [1,2,3,4,5] as the default value. + */ + business_days?: number[]; + /** + * + */ + order_processing_time?: OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest; +} + diff --git a/src/model/EstimatedPickupEstimatedDeliveryDateResponse.ts b/src/model/EstimatedPickupEstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..92e503b --- /dev/null +++ b/src/model/EstimatedPickupEstimatedDeliveryDateResponse.ts @@ -0,0 +1,29 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse } from "./OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse"; + +export interface EstimatedPickupEstimatedDeliveryDateResponse { + /** + * The local order time in the origin address time zone of the package. + */ + order_time: string; + /** + * Order cut off time in the origin address time zone. The default value set by AfterShip is 18:00:00. + */ + order_cutoff_time?: string; + /** + * Operating days in a week. Number refers to the weekday.E.g., [1,2,3,4,5] means operating days are from Monday to Friday.AfterShip will set [1,2,3,4,5] as the default value. + */ + business_days?: number[]; + /** + * + */ + order_processing_time?: OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse; + /** + * The local pickup time of the package. + */ + pickup_time?: string; +} + diff --git a/src/model/EventsCheckpoint.ts b/src/model/EventsCheckpoint.ts new file mode 100644 index 0000000..4ceb4b0 --- /dev/null +++ b/src/model/EventsCheckpoint.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { ReasonEventsCheckpoint } from "./ReasonEventsCheckpoint"; + +export interface EventsCheckpoint { + /** + * Represents the event code. + */ + code?: string; + /** + * Describes the specific reason that led to the event. + */ + reason?: ReasonEventsCheckpoint; +} + diff --git a/src/model/FirstEstimatedDeliveryTracking.ts b/src/model/FirstEstimatedDeliveryTracking.ts new file mode 100644 index 0000000..307a3e4 --- /dev/null +++ b/src/model/FirstEstimatedDeliveryTracking.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface FirstEstimatedDeliveryTracking { + /** + * The format of the EDD. Either a single date or a date range. + */ + type?: string; + /** + * The source of the EDD. Either the carrier, AfterShip AI, or based on your custom EDD settings. + */ + source?: string; + /** + * The latest EDD time. + */ + datetime?: string; + /** + * For a date range EDD format, the date and time for the lower end of the range. + */ + datetime_min?: string; + /** + * For a date range EDD format, the date and time for the upper end of the range. + */ + datetime_max?: string; +} + diff --git a/src/model/GetAllCouriersResponse.ts b/src/model/GetAllCouriersResponse.ts new file mode 100644 index 0000000..af0e443 --- /dev/null +++ b/src/model/GetAllCouriersResponse.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Courier } from "./Courier"; + +export interface GetAllCouriersResponse { + /** + * Total count of courier objects + */ + total?: number; + /** + * Array of object. + */ + couriers?: Courier[]; +} + diff --git a/src/model/GetCheckpointBySlugTrackingNumberQuery.ts b/src/model/GetCheckpointBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..e069545 --- /dev/null +++ b/src/model/GetCheckpointBySlugTrackingNumberQuery.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetCheckpointBySlugTrackingNumberQuery { + fields?: string; + lang?: string; + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/GetCheckpointBySlugTrackingNumberResponse.ts b/src/model/GetCheckpointBySlugTrackingNumberResponse.ts new file mode 100644 index 0000000..9012942 --- /dev/null +++ b/src/model/GetCheckpointBySlugTrackingNumberResponse.ts @@ -0,0 +1,38 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { TagV1 } from "./TagV1"; +import { Checkpoint } from "./Checkpoint"; + +export interface GetCheckpointBySlugTrackingNumberResponse { + /** + * Tracking id + */ + id?: string; + /** + * Tracking number. + */ + tracking_number?: string; + /** + * Unique code of courier. + */ + slug?: string; + /** + * Current status of tracking. ( + */ + tag?: TagV1; + /** + * Current subtag of tracking. ( + */ + subtag?: string; + /** + * Normalized tracking message. ( + */ + subtag_message?: string; + /** + * Object describes checkpoint information. + */ + checkpoint?: Checkpoint; +} + diff --git a/src/model/GetCheckpointByTrackingIdQuery.ts b/src/model/GetCheckpointByTrackingIdQuery.ts new file mode 100644 index 0000000..363d3a5 --- /dev/null +++ b/src/model/GetCheckpointByTrackingIdQuery.ts @@ -0,0 +1,9 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetCheckpointByTrackingIdQuery { + fields?: string; + lang?: string; +} + diff --git a/src/model/GetCheckpointByTrackingIdResponse.ts b/src/model/GetCheckpointByTrackingIdResponse.ts new file mode 100644 index 0000000..8f01b4a --- /dev/null +++ b/src/model/GetCheckpointByTrackingIdResponse.ts @@ -0,0 +1,38 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { TagV1 } from "./TagV1"; +import { Checkpoint } from "./Checkpoint"; + +export interface GetCheckpointByTrackingIdResponse { + /** + * Tracking id + */ + id?: string; + /** + * Tracking number. + */ + tracking_number?: string; + /** + * Unique code of courier. + */ + slug?: string; + /** + * Current status of tracking. ( + */ + tag?: TagV1; + /** + * Current subtag of tracking. ( + */ + subtag?: string; + /** + * Normalized tracking message. ( + */ + subtag_message?: string; + /** + * Object describes checkpoint information. + */ + checkpoint?: Checkpoint; +} + diff --git a/src/model/GetNotificationBySlugTrackingNumberQuery.ts b/src/model/GetNotificationBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..11418af --- /dev/null +++ b/src/model/GetNotificationBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetNotificationBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/GetTrackingByIdQuery.ts b/src/model/GetTrackingByIdQuery.ts new file mode 100644 index 0000000..fe63fb5 --- /dev/null +++ b/src/model/GetTrackingByIdQuery.ts @@ -0,0 +1,9 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetTrackingByIdQuery { + fields?: string; + lang?: string; +} + diff --git a/src/model/GetTrackingBySlugTrackingNumberQuery.ts b/src/model/GetTrackingBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..378de2d --- /dev/null +++ b/src/model/GetTrackingBySlugTrackingNumberQuery.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetTrackingBySlugTrackingNumberQuery { + fields?: string; + lang?: string; + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/GetTrackingsQuery.ts b/src/model/GetTrackingsQuery.ts new file mode 100644 index 0000000..fb8d0d6 --- /dev/null +++ b/src/model/GetTrackingsQuery.ts @@ -0,0 +1,25 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface GetTrackingsQuery { + page?: number; + limit?: number; + keyword?: string; + tracking_numbers?: string; + slug?: string; + transit_time?: number; + origin?: string; + destination?: string; + tag?: string; + created_at_min?: string; + created_at_max?: string; + updated_at_min?: string; + updated_at_max?: string; + fields?: string; + return_to_sender?: string; + courier_destination_country_iso3?: string; + shipment_tags?: string; + order_id?: string; +} + diff --git a/src/model/GetTrackingsResponse.ts b/src/model/GetTrackingsResponse.ts new file mode 100644 index 0000000..7fa690e --- /dev/null +++ b/src/model/GetTrackingsResponse.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Tracking } from "./Tracking"; +import { Pagination } from "./Pagination"; + +export interface GetTrackingsResponse { + /** + * + */ + pagination: Pagination; + /** + * Array of + */ + trackings?: Tracking[]; +} + diff --git a/src/model/GetUserCouriersResponse.ts b/src/model/GetUserCouriersResponse.ts new file mode 100644 index 0000000..fa96b75 --- /dev/null +++ b/src/model/GetUserCouriersResponse.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { Courier } from "./Courier"; + +export interface GetUserCouriersResponse { + /** + * Total count of courier objects + */ + total?: number; + /** + * Array of object. + */ + couriers?: Courier[]; +} + diff --git a/src/model/LatestEstimatedDeliveryTracking.ts b/src/model/LatestEstimatedDeliveryTracking.ts new file mode 100644 index 0000000..b089912 --- /dev/null +++ b/src/model/LatestEstimatedDeliveryTracking.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface LatestEstimatedDeliveryTracking { + /** + * The format of the EDD. Either a single date or a date range. + */ + type?: string; + /** + * The source of the EDD. Either the carrier, AfterShip AI, or based on your custom EDD settings. + */ + source?: string; + /** + * The latest EDD time. + */ + datetime?: string; + /** + * For a date range EDD format, the date and time for the lower end of the range. + */ + datetime_min?: string; + /** + * For a date range EDD format, the date and time for the upper end of the range. + */ + datetime_max?: string; +} + diff --git a/src/model/MarkTrackingCompletedByIdRequest.ts b/src/model/MarkTrackingCompletedByIdRequest.ts new file mode 100644 index 0000000..be68925 --- /dev/null +++ b/src/model/MarkTrackingCompletedByIdRequest.ts @@ -0,0 +1,12 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface MarkTrackingCompletedByIdRequest { + /** + * One of `DELIVERED`, `LOST` or `RETURNED_TO_SENDER`.- Mark the tracking as completed with `DELIVERED`. The tag of the tracking will be updated to `Delivered` and the subtag will be updated to `Delivered_001`.- Mark the tracking as completed with `LOST`. The tag of the tracking will be updated to `Exception` and the subtag will be updated to `Exception_013`.- Mark the tracking as completed with `RETURNED_TO_SENDER`. The tag of the tracking will be updated to `Exception` and the subtag will be updated to `Exception_011`. + */ + reason: string; +} + diff --git a/src/model/MarkTrackingCompletedBySlugTrackingNumberQuery.ts b/src/model/MarkTrackingCompletedBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..1c2c0dc --- /dev/null +++ b/src/model/MarkTrackingCompletedBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface MarkTrackingCompletedBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/MarkTrackingCompletedBySlugTrackingNumberRequest.ts b/src/model/MarkTrackingCompletedBySlugTrackingNumberRequest.ts new file mode 100644 index 0000000..76c3224 --- /dev/null +++ b/src/model/MarkTrackingCompletedBySlugTrackingNumberRequest.ts @@ -0,0 +1,12 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface MarkTrackingCompletedBySlugTrackingNumberRequest { + /** + * One of `DELIVERED`, `LOST` or `RETURNED_TO_SENDER`.- Mark the tracking as completed with `DELIVERED`. The tag of the tracking will be updated to `Delivered` and the subtag will be updated to `Delivered_001`.- Mark the tracking as completed with `LOST`. The tag of the tracking will be updated to `Exception` and the subtag will be updated to `Exception_013`.- Mark the tracking as completed with `RETURNED_TO_SENDER`. The tag of the tracking will be updated to `Exception` and the subtag will be updated to `Exception_011`. + */ + reason: string; +} + diff --git a/src/model/MetaV1.ts b/src/model/MetaV1.ts new file mode 100644 index 0000000..754f25b --- /dev/null +++ b/src/model/MetaV1.ts @@ -0,0 +1,20 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface MetaV1 { + /** + * meta code + */ + code: number; + /** + * error message, only exist if the response status is not 2xx + */ + message?: string; + /** + * error type, only exist if the response status is not 2xx + */ + type?: string; +} + diff --git a/src/model/NextCouriersTracking.ts b/src/model/NextCouriersTracking.ts new file mode 100644 index 0000000..2ecc415 --- /dev/null +++ b/src/model/NextCouriersTracking.ts @@ -0,0 +1,20 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface NextCouriersTracking { + /** + * Unique code of courier. Get courier + */ + slug: string; + /** + * Tracking number. + */ + tracking_number: string; + /** + * Source of next couriers. + */ + source?: string; +} + diff --git a/src/model/NextCouriersTrackingCreateTrackingRequest.ts b/src/model/NextCouriersTrackingCreateTrackingRequest.ts new file mode 100644 index 0000000..20e314a --- /dev/null +++ b/src/model/NextCouriersTrackingCreateTrackingRequest.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface NextCouriersTrackingCreateTrackingRequest { + /** + * + */ + slug: string; + /** + * Tracking number of a shipment.Duplicated tracking numbers, tracking numbers with invalid tracking number format will not be accepted.We only accept tracking numbers with length from 4 to 100We currently support the following characters in a tracking number:- A - Z- 0 - 9- `-` (Hyphen)- . (Period)- _ (Underscore)- / (Slash) + */ + tracking_number: string; +} + diff --git a/src/model/Notification.ts b/src/model/Notification.ts new file mode 100644 index 0000000..bfefea7 --- /dev/null +++ b/src/model/Notification.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface Notification { + /** + * Email address(es) to receive email notifications. + */ + emails?: string[]; + /** + * The phone number(s) to receive sms notifications. + */ + smses?: string[]; +} + diff --git a/src/model/NotificationRequestV1.ts b/src/model/NotificationRequestV1.ts new file mode 100644 index 0000000..e6c1be3 --- /dev/null +++ b/src/model/NotificationRequestV1.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface NotificationRequestV1 { + /** + * Email address(es) to receive email notifications.Accept either array or comma separated as input. + */ + emails?: string[]; + /** + * The phone number(s) to receive sms notifications. Enter `+` and `area code` before phone number.Accept either array or comma separated as input. + */ + smses?: string[]; +} + diff --git a/src/model/NotificationResponseV1.ts b/src/model/NotificationResponseV1.ts new file mode 100644 index 0000000..a064fd5 --- /dev/null +++ b/src/model/NotificationResponseV1.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { MetaV1 } from "./MetaV1"; +import { DataNotificationResponseV1 } from "./DataNotificationResponseV1"; + +export interface NotificationResponseV1 { + /** + * Meta data + */ + meta?: MetaV1; + /** + * + */ + data?: DataNotificationResponseV1; +} + diff --git a/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest.ts b/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..d0bcff1 --- /dev/null +++ b/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateRequest { + /** + * Processing time of an order, from being placed to being picked up. Only support day as value now.AfterShip will set day as the default value. + */ + unit?: string; + /** + * Processing time of an order, from being placed to being picked up.AfterShip will set 0 as the default value. + */ + value?: number; +} + diff --git a/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse.ts b/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..e3e3782 --- /dev/null +++ b/src/model/OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface OrderProcessingTimeEstimatedPickupEstimatedDeliveryDateResponse { + /** + * Processing time of an order, from being placed to being picked up. Only support day as value now.AfterShip will set day as the default value. + */ + unit?: string; + /** + * Processing time of an order, from being placed to being picked up.AfterShip will set 0 as the default value. + */ + value?: number; +} + diff --git a/src/model/OriginAddressEstimatedDeliveryDateRequest.ts b/src/model/OriginAddressEstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..ebc2596 --- /dev/null +++ b/src/model/OriginAddressEstimatedDeliveryDateRequest.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface OriginAddressEstimatedDeliveryDateRequest { + /** + * The country/region of the origin location from where the package is picked up by the carrier to be delivered to the final destination. Use 3 letters of ISO 3166-1 country/region code. + */ + country: string; + /** + * State, province, or the equivalent location of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without state. Either `origin_address.state` or `origin_address.postal_code` is required. + */ + state?: string; + /** + * City of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without City. + */ + city?: string; + /** + * Postal code of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without postal code. Either `origin_address.state` or `origin_address.postal_code` is required. + */ + postal_code?: string; + /** + * Raw location of the origin address. A raw address will help AI to identify the accurate location of the origin address. + */ + raw_location?: string; +} + diff --git a/src/model/OriginAddressEstimatedDeliveryDateResponse.ts b/src/model/OriginAddressEstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..e78fc4d --- /dev/null +++ b/src/model/OriginAddressEstimatedDeliveryDateResponse.ts @@ -0,0 +1,28 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface OriginAddressEstimatedDeliveryDateResponse { + /** + * The country/region of the origin location from where the package is picked up by the carrier to be delivered to the final destination. Use 3 letters of ISO 3166-1 country/region code. + */ + country: string; + /** + * State, province, or the equivalent location of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without state. Either `origin_address.state` or `origin_address.postal_code` is required. + */ + state?: string; + /** + * City of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without City. + */ + city?: string; + /** + * Postal code of the origin address. Use 3 letters of ISO 3166-1 country/region code for countries/regions without postal code. Either `origin_address.state` or `origin_address.postal_code` is required. + */ + postal_code?: string; + /** + * Raw location of the origin address. A raw address will help AI to identify the accurate location of the origin address. + */ + raw_location?: string; +} + diff --git a/src/model/Pagination.ts b/src/model/Pagination.ts new file mode 100644 index 0000000..85b79ca --- /dev/null +++ b/src/model/Pagination.ts @@ -0,0 +1,10 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface Pagination { + total: number; + page: number; + limit: number; + has_next_page: boolean | null; +} \ No newline at end of file diff --git a/src/model/PartialDeleteTracking.ts b/src/model/PartialDeleteTracking.ts new file mode 100644 index 0000000..e3a27dc --- /dev/null +++ b/src/model/PartialDeleteTracking.ts @@ -0,0 +1,48 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface PartialDeleteTracking { + /** + * Tracking id + */ + id?: string; + /** + * Tracking number + */ + tracking_number?: string; + /** + * Unique code of courier. Get the slugs from . + */ + slug?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * (Legacy) Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * (Legacy) Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * (Legacy) Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * (Legacy) Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; +} + diff --git a/src/model/PartialUpdateTracking.ts b/src/model/PartialUpdateTracking.ts new file mode 100644 index 0000000..c75225d --- /dev/null +++ b/src/model/PartialUpdateTracking.ts @@ -0,0 +1,52 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface PartialUpdateTracking { + /** + * A unique identifier generated by AfterShip for the tracking. + */ + id?: string; + /** + * Tracking number. + */ + tracking_number?: string; + /** + * Unique code of courier. Get the slugs from . + */ + slug?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; + /** + * Whether or not AfterShip will continue tracking the shipments. Value is `false` when tag (status) is `Delivered`, `Expired`, or further updates for 30 days since last update. + */ + active?: boolean; +} + diff --git a/src/model/PredictBatchRequest.ts b/src/model/PredictBatchRequest.ts new file mode 100644 index 0000000..5676207 --- /dev/null +++ b/src/model/PredictBatchRequest.ts @@ -0,0 +1,13 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { EstimatedDeliveryDateRequest } from "./EstimatedDeliveryDateRequest"; + +export interface PredictBatchRequest { + /** + * + */ + estimated_delivery_dates: EstimatedDeliveryDateRequest[]; +} + diff --git a/src/model/PredictBatchResponse.ts b/src/model/PredictBatchResponse.ts new file mode 100644 index 0000000..ddce627 --- /dev/null +++ b/src/model/PredictBatchResponse.ts @@ -0,0 +1,13 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { EstimatedDeliveryDateResponse } from "./EstimatedDeliveryDateResponse"; + +export interface PredictBatchResponse { + /** + * + */ + estimated_delivery_dates: EstimatedDeliveryDateResponse[]; +} + diff --git a/src/model/ReasonEventsCheckpoint.ts b/src/model/ReasonEventsCheckpoint.ts new file mode 100644 index 0000000..64c7ddd --- /dev/null +++ b/src/model/ReasonEventsCheckpoint.ts @@ -0,0 +1,12 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface ReasonEventsCheckpoint { + /** + * The code of the reason. + */ + code?: string; +} + diff --git a/src/model/RetrackTrackingBySlugTrackingNumberQuery.ts b/src/model/RetrackTrackingBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..ee0b910 --- /dev/null +++ b/src/model/RetrackTrackingBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface RetrackTrackingBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/SlugGroupV1.ts b/src/model/SlugGroupV1.ts new file mode 100644 index 0000000..f2a91b2 --- /dev/null +++ b/src/model/SlugGroupV1.ts @@ -0,0 +1,20 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + + +export enum SlugGroupV1 { + "amazon-group" = "amazon-group", + "fedex-group" = "fedex-group", + "toll-group" = "toll-group", + "taqbin-group" = "taqbin-group", + "tnt-group" = "tnt-group", + "cj-group" = "cj-group", + "hermes-group" = "hermes-group", + "dpd-group" = "dpd-group", + "gls-group" = "gls-group", + "dhl-group" = "dhl-group", + "fastway-group" = "fastway-group", + "asendia-group" = "asendia-group", +} diff --git a/src/model/TagV1.ts b/src/model/TagV1.ts new file mode 100644 index 0000000..62e3a39 --- /dev/null +++ b/src/model/TagV1.ts @@ -0,0 +1,17 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + + +export enum TagV1 { + "Pending" = "Pending", + "InfoReceived" = "InfoReceived", + "InTransit" = "InTransit", + "OutForDelivery" = "OutForDelivery", + "AttemptFail" = "AttemptFail", + "Delivered" = "Delivered", + "AvailableForPickup" = "AvailableForPickup", + "Exception" = "Exception", + "Expired" = "Expired", +} diff --git a/src/model/Tracking.ts b/src/model/Tracking.ts new file mode 100644 index 0000000..b51554f --- /dev/null +++ b/src/model/Tracking.ts @@ -0,0 +1,328 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { TagV1 } from "./TagV1"; +import { Checkpoint } from "./Checkpoint"; +import { AftershipEstimatedDeliveryDateTracking } from "./AftershipEstimatedDeliveryDateTracking"; +import { CustomEstimatedDeliveryDateTracking } from "./CustomEstimatedDeliveryDateTracking"; +import { FirstEstimatedDeliveryTracking } from "./FirstEstimatedDeliveryTracking"; +import { LatestEstimatedDeliveryTracking } from "./LatestEstimatedDeliveryTracking"; +import { NextCouriersTracking } from "./NextCouriersTracking"; +import { CarbonEmissionsTracking } from "./CarbonEmissionsTracking"; + +export interface Tracking { + /** + * Tracking ID. + */ + id?: string; + /** + * The date and time the shipment was imported or added to AfterShip. It uses the format `YYYY-MM-DDTHH:mm:ssZ` for the timezone GMT +0. + */ + created_at?: string; + /** + * The date and time the shipment was updated. It uses the format `YYYY-MM-DDTHH:mm:ssZ` for the timezone GMT +0. + */ + updated_at?: string; + /** + * (Legacy) The date and time the shipment was updated. It uses the format `YYYY-MM-DDTHH:mm:ssZ` for the timezone GMT +0. + */ + last_updated_at?: string; + /** + * Tracking number. + */ + tracking_number?: string; + /** + * Unique courier code. When importing a shipment with no courier slug and the tracking number can’t be recognized, the courier will be marked as `unrecognized`. Get courier codes . + */ + slug?: string; + /** + * Whether or not AfterShip will continue tracking the shipments. Value is `false` when tag (status) is `Delivered`, `Expired`, or further updates for 30 days since last update. + */ + active?: boolean; + /** + * Custom fields that accept an object with string field. In order to protect the privacy of your customers, do not include any in custom fields. + */ + custom_fields?: {[key: string]: any}; + /** + * Customer name of the tracking. + */ + customer_name?: string; + /** + * Total transit time in days.- For delivered shipments: Transit time (in days) = Delivered date - Pick-up date- For undelivered shipments: Transit time (in days) = Current date - Pick-up dateValue as `null` for the shipment without pick-up date. + */ + transit_time?: number; + /** + * The for the origin country/region. E.g. USA for the United States. + */ + origin_country_iso3?: string; + /** + * The state of the sender’s address. + */ + origin_state?: string; + /** + * The city of the sender’s address. + */ + origin_city?: string; + /** + * The postal code of the sender’s address. + */ + origin_postal_code?: string; + /** + * The sender address that the shipment is shipping from. + */ + origin_raw_location?: string; + /** + * The for the destination country/region. E.g. USA for the United States. + */ + destination_country_iso3?: string; + /** + * The state of the recipient’s address. + */ + destination_state?: string; + /** + * The city of the recipient’s address. + */ + destination_city?: string; + /** + * The postal code of the recipient’s address. + */ + destination_postal_code?: string; + /** + * The shipping address that the shipment is shipping to. + */ + destination_raw_location?: string; + /** + * Destination country/region of the tracking detected from the courier. ISO Alpha-3 (three letters). Value will be `null` if the courier doesn't provide the destination country. + */ + courier_destination_country_iso3?: string; + /** + * Email address(es) to receive email notifications. + */ + emails?: string[]; + /** + * The estimated delivery date provided by the carrier. It uses the shipment recipient’s timezone and the format may differ depending on how the carrier provides it:- YYYY-MM-DD- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ + */ + expected_delivery?: string; + /** + * Text field for the note. + */ + note?: string; + /** + * A globally-unique identifier for the order. + */ + order_id?: string; + /** + * The URL for the order in your system or store. + */ + order_id_path?: string; + /** + * The date and time the order was created in your system or store. It uses the format: `YYYY-MM-DDTHH:mm:ssZ` based on whichever timezone you provide. + */ + order_date?: string; + /** + * Number of packages under the tracking. + */ + shipment_package_count?: number; + /** + * The date and time the shipment was picked up by the carrier. It uses the timezone where the pickup occured. The format may differ depending on how the carrier provides it:- YYYY-MM-DD- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ + */ + shipment_pickup_date?: string; + /** + * The date and time the shipment was delivered. It uses the shipment recipient’s timezone. The format may differ depending on how the carrier provides it:- YYYY-MM-DD- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ + */ + shipment_delivery_date?: string; + /** + * The carrier service type for the shipment. + */ + shipment_type?: string; + /** + * Shipment weight provied by carrier. + */ + shipment_weight?: number; + /** + * Weight unit provied by carrier. + */ + shipment_weight_unit?: string; + /** + * Signed by information for delivered shipment. + */ + signed_by?: string; + /** + * The phone number(s) to receive sms notifications. Phone number should begin with `+` and `Area Code` before phone number. Comma separated for multiple values. + */ + smses?: string[]; + /** + * Source of how this tracking is added. + */ + source?: string; + /** + * Current status of tracking. ( + */ + tag?: TagV1; + /** + * Current subtag of tracking. ( + */ + subtag?: string; + /** + * Normalized tracking message. ( + */ + subtag_message?: string; + /** + * By default this field shows the `tracking_number`, but you can customize it as you wish with any info (e.g. the order number). + */ + title?: string; + /** + * Number of attempts AfterShip tracks at courier's system. + */ + tracked_count?: number; + /** + * Indicates if the shipment is trackable till the final destination.Three possible values:- true- false- null + */ + last_mile_tracking_supported?: boolean; + /** + * The recipient’s language. If you set up AfterShip notifications in different languages, we use this to send the recipient tracking updates in their preferred language. + */ + language?: string; + /** + * Deprecated + */ + unique_token?: string; + /** + * Array of checkpoint object describes the checkpoint information. + */ + checkpoints?: Checkpoint[]; + /** + * Phone number(s) subscribed to receive sms notifications. Comma separated for multiple values + */ + subscribed_smses?: string[]; + /** + * Email address(es) subscribed to receive email notifications. Comma separated for multiple values + */ + subscribed_emails?: string[]; + /** + * Whether or not the shipment is returned to sender. Value is `true` when any of its checkpoints has subtag `Exception_010` (returning to sender) or `Exception_011` (returned to sender). Otherwise value is `false`. + */ + return_to_sender?: boolean; + /** + * The promised delivery date of the order. It uses the format `YYYY-MM-DD`. This has no timezone and uses whatever date you provide. + */ + order_promised_delivery_date?: string; + /** + * Shipment delivery type- pickup_at_store- pickup_at_courier- door_to_door + */ + delivery_type?: string; + /** + * Shipment pickup location for receiver + */ + pickup_location?: string; + /** + * Shipment pickup note for receiver + */ + pickup_note?: string; + /** + * Official tracking URL of the courier (if any). The language parameter of this link relies on the destination country/region and the language associated with the shipment, if the data regarding the destination country/region and language of the shipment is not available, AfterShip will set the language parameter of the link to "US" by default. + */ + courier_tracking_link?: string; + /** + * The date and time of the carrier’s first attempt to deliver the package to the recipient. It uses the shipment recipient’s timezone. The format may differ depending on how the carrier provides it:- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ + */ + first_attempted_at?: string; + /** + * Delivery instructions (delivery date or address) can be modified by visiting the link if supported by a carrier. The language parameter of this link relies on the destination country/region and the language associated with the shipment, if the data regarding the destination country/region and language of the shipment is not available, AfterShip will set the language parameter of the link to "US" by default. + */ + courier_redirect_link?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * Whether the tracking is delivered on time or not. + */ + on_time_status?: string; + /** + * The difference days of the on time. + */ + on_time_difference?: number; + /** + * The tags of the order. + */ + order_tags?: string[]; + /** + * The estimated delivery date of the shipment provided by AfterShip’s AI and shown to the recipients. It uses the format `YYYY-MM-DD` based on the shipment recipient’s timezone. + */ + aftership_estimated_delivery_date?: AftershipEstimatedDeliveryDateTracking; + /** + * Estimated delivery time of the shipment based on your . It uses the format `YYYY-MM-DD` based on the shipment recipient’s timezone. + */ + custom_estimated_delivery_date?: CustomEstimatedDeliveryDateTracking; + /** + * A unique, human-readable identifier for the order. + */ + order_number?: string; + /** + * The shipment’s original estimated delivery date. It could be provided by the carrier, AfterShip AI, or based on your custom settings. The format of carrier EDDs may differ depending on how the carrier provides it:- YYYY-MM-DD- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ AfterShip AI and custom EDDs always use the format `YYYY-MM-DD`. All EDDs use the shipment recipient’s timezone. + */ + first_estimated_delivery?: FirstEstimatedDeliveryTracking; + /** + * The most recently calculated estimated delivery date. It could be provided by the carrier, AfterShip AI, or based on your custom settings. The format of carrier EDDs may differ depending on how the carrier provides it:- YYYY-MM-DD- YYYY-MM-DDTHH:mm:ss- YYYY-MM-DDTHH:mm:ssZ AfterShip AI and custom EDDs always use the format `YYYY-MM-DD`. All EDDs use the shipment recipient’s timezone. + */ + latest_estimated_delivery?: LatestEstimatedDeliveryTracking; + /** + * Used to add tags to your shipments to help categorize and filter them easily. + */ + shipment_tags?: string[]; + /** + * If you have multiple accounts connected for a single carrier on AfterShip, we have introduced the courier_connection_id field to allow you to specify the carrier account associated with each shipment. By providing this information, you enable us to accurately track and monitor your shipments based on the correct carrier account.(</br>In the event that you do not specify the courier_connection_id, we will handle your shipment using the connection that was created earliest among your connected accounts. + */ + courier_connection_id?: string; + /** + * The next couriers get the second carrier information from user or AfterShip. + */ + next_couriers?: NextCouriersTracking[]; + /** + * (Legacy) Replaced by `origin_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * (Legacy) Replaced by `destination_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * (Legacy) Replaced by `destination_postal_code`. Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * (Legacy) Replaced by `destination_state`. Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; + /** + * The model contains the total amount of carbon emissions generated by the shipment. - AfterShip will provide this data only when it is available, and its availability is contingent upon the location and weight information that AfterShip can obtain.- The values will be accessible solely for shipments that have been successfully delivered. However, in the event of a shipping update after the delivery status has been achieved, the value may change.- It’s a paid service and only for Tracking Enterprise users, please contact your customer success manager if you want to know more. + */ + carbon_emissions?: CarbonEmissionsTracking; + /** + * The location_id refers to the place where you fulfilled the items. - If you provide a location_id, the system will automatically use it as the tracking's origin address. However, passing both location_id and any origin address information simultaneously is not allowed.- Please make sure you add your locations . + */ + location_id?: string; + /** + * The shipping_method string refers to the chosen method for delivering the package. Merchants typically offer various shipping methods to consumers during the checkout process, such as, Local Delivery, Free Express Worldwide Shipping, etc. + */ + shipping_method?: string; + /** + * By dynamically tracking failed delivery attempts during shipment, this field allows you to pinpoint carriers accountable for the most failures. Analyzing the root cause of these failures enables you to improve carriers' delivery standard operating procedures (SOP), leading to an overall enhancement in delivery service quality. + */ + failed_delivery_attempts?: number; + /** + * The signature_requirement field serves the purpose of validating the service option type, specifically proof of delivery. By collecting the recipient's signature upon delivery, it ensures the package reaches the intended recipient and prevents disputes related to non-delivery or lost packages.</br> + */ + signature_requirement?: string; +} + diff --git a/src/model/TrackingCreateTrackingRequest.ts b/src/model/TrackingCreateTrackingRequest.ts new file mode 100644 index 0000000..890bed2 --- /dev/null +++ b/src/model/TrackingCreateTrackingRequest.ts @@ -0,0 +1,174 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { SlugGroupV1 } from "./SlugGroupV1"; +import { NextCouriersTrackingCreateTrackingRequest } from "./NextCouriersTrackingCreateTrackingRequest"; + +export interface TrackingCreateTrackingRequest { + /** + * Tracking number of a shipment.Duplicated tracking numbers, tracking numbers with invalid tracking number format will not be accepted.We only accept tracking numbers with length from 4 to 100We currently support the following characters in a tracking number:- A - Z- 0 - 9- `-` (Hyphen)- . (Period)- _ (Underscore)- / (Slash) + */ + tracking_number: string; + /** + * Unique courier code. Get courier codes . + */ + slug?: string; + /** + * By default this field shows the `tracking_number`, but you can customize it as you wish with any info (e.g. the order number). + */ + title?: string; + /** + * A globally-unique identifier for the order. + */ + order_id?: string; + /** + * The URL for the order in your system or store. + */ + order_id_path?: string; + /** + * Custom fields that accept an object with string field. In order to protect the privacy of your customers, do not include any + */ + custom_fields?: {[key: string]: any}; + /** + * The recipient’s language. If you set up AfterShip notifications in different languages, we use this to send the recipient tracking updates in their preferred language. Use an to specify the language. + */ + language?: string; + /** + * The promised delivery date of the order. It uses the format YYYY-MM-DD. This has no timezone and uses whatever date you provide. Since other EDDs use the shipment recipient’s timezone, we suggest following the same logic here. + */ + order_promised_delivery_date?: string; + /** + * Shipment delivery type- pickup_at_store- pickup_at_courier- door_to_door + */ + delivery_type?: string; + /** + * Shipment pickup location for receiver + */ + pickup_location?: string; + /** + * Shipment pickup note for receiver + */ + pickup_note?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * Email address(es) to receive email notifications. Accept either array or comma separated as input. Supports up to 3 email addresses. + */ + emails?: string[]; + /** + * The phone number(s) to receive sms notifications. Enter `+` andarea `code before` phone number. Accept either array or comma separated as input. Supports up to 3 phone numbers. + */ + smses?: string[]; + /** + * Customer name of the tracking. + */ + customer_name?: string; + /** + * The for more details. + */ + origin_country_iso3?: string; + /** + * The state of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_state?: string; + /** + * The city of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_city?: string; + /** + * The postal of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_postal_code?: string; + /** + * The sender address that the shipment is shipping from. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_raw_location?: string; + /** + * The for more details. + */ + destination_country_iso3?: string; + /** + * The state of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. Also the additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + destination_state?: string; + /** + * The city of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + destination_city?: string; + /** + * The postal of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. Also the additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + destination_postal_code?: string; + /** + * The shipping address that the shipment is shipping to. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + destination_raw_location?: string; + /** + * Text field for the note + */ + note?: string; + /** + * Slug group is a group of slugs which belong to same courier. For example, when you inpit "fedex-group" as slug_group, AfterShip will detect the tracking with "fedex-uk", "fedex-fims", and other slugs which belong to "fedex". It cannot be used with slug at the same time. ( + */ + slug_group?: SlugGroupV1; + /** + * Order date in YYYY-MM-DDTHH:mm:ssZ format. e.g. 2021-07-26T11:23:51-05:00 + */ + order_date?: string; + /** + * A unique, human-readable identifier for the order. + */ + order_number?: string; + /** + * The carrier service type for the shipment. If you provide info for this field, AfterShip will not update it with info from the carrier. + */ + shipment_type?: string; + /** + * Used to add tags to your shipments to help categorize and filter them easily. + */ + shipment_tags?: string[]; + /** + * If you’ve connected multiple accounts for a single carrier on AfterShip, you can now use the courier_connection_id field to tell AfterShip which carrier account you’ve used to handle a shipment so we can track it. ( + */ + courier_connection_id?: string; + /** + * If a shipment has multiple carriers, you can use the next_couriers field to tell AfterShip who the second carrier is. This is useful if the first carrier does not send us this information. + */ + next_couriers?: NextCouriersTrackingCreateTrackingRequest[]; + /** + * (Legacy) Replaced by `origin_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * (Legacy) Replaced by `destination_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * (Legacy) Replaced by `destination_postal_code`. Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * (Legacy) Replaced by `destination_state`. Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; + /** + * The location_id refers to the place where you fulfilled the items. - If you provide a location_id, the system will automatically use it as the tracking's origin address. However, passing both location_id and any origin address information simultaneously is not allowed.- Please make sure you add your locations . + */ + location_id?: string; + /** + * The shipping_method string refers to the chosen method for delivering the package. Merchants typically offer various shipping methods to consumers during the checkout process, such as, Local Delivery, Free Express Worldwide Shipping, etc + */ + shipping_method?: string; +} + diff --git a/src/model/TrackingDeleteResponseV1.ts b/src/model/TrackingDeleteResponseV1.ts new file mode 100644 index 0000000..b054b54 --- /dev/null +++ b/src/model/TrackingDeleteResponseV1.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { MetaV1 } from "./MetaV1"; +import { DataTrackingDeleteResponseV1 } from "./DataTrackingDeleteResponseV1"; + +export interface TrackingDeleteResponseV1 { + /** + * Meta data + */ + meta: MetaV1; + /** + * + */ + data: DataTrackingDeleteResponseV1; +} + diff --git a/src/model/TrackingDetectCourierRequest.ts b/src/model/TrackingDetectCourierRequest.ts new file mode 100644 index 0000000..e7868e5 --- /dev/null +++ b/src/model/TrackingDetectCourierRequest.ts @@ -0,0 +1,57 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { SlugGroupV1 } from "./SlugGroupV1"; + +export interface TrackingDetectCourierRequest { + /** + * Tracking number of a shipment. + */ + tracking_number: string; + /** + * If not specified, Aftership will automatically detect the courier based on the tracking number format and your . Use array or comma separated to input a list of couriers for auto detect. Cannot be used with slug_group at the same time. + */ + slug?: string[]; + /** + * The postal code of receiver's address. Required by some couriers. Refer to for more details + */ + tracking_postal_code?: string; + /** + * Shipping date in `YYYYMMDD` format. Required by some couriers. Refer to for more details + */ + tracking_ship_date?: string; + /** + * Account number of the shipper for a specific courier. Required by some couriers. Refer to for more details + */ + tracking_account_number?: string; + /** + * Key of the shipment for a specific courier. Required by some couriers. Refer to for more details + */ + tracking_key?: string; + /** + * Origin Country/Region of the shipment for a specific courier. Required by some couriers. + */ + tracking_origin_country?: string; + /** + * Destination Country/Region of the shipment for a specific courier. Required by some couriers. Refer to for more details + */ + tracking_destination_country?: string; + /** + * State of the destination shipping address of the shipment. Required by some couriers. + */ + tracking_state?: string; + /** + * Slug group is a group of slugs which belong to same courier. For example, when you inpit "fedex-group" as slug_group, AfterShip will detect the tracking with "fedex-uk", "fedex-fims", and other slugs which belong to "fedex". It cannot be used with slug at the same time. ( + */ + slug_group?: SlugGroupV1; + /** + * Enter . + */ + origin_country_iso3?: string; + /** + * Enter . + */ + destination_country_iso3?: string; +} + diff --git a/src/model/TrackingResponseGetMultipleV1.ts b/src/model/TrackingResponseGetMultipleV1.ts new file mode 100644 index 0000000..f8a0a5a --- /dev/null +++ b/src/model/TrackingResponseGetMultipleV1.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { MetaV1 } from "./MetaV1"; +import { DataTrackingResponseGetMultipleV1 } from "./DataTrackingResponseGetMultipleV1"; + +export interface TrackingResponseGetMultipleV1 { + /** + * Meta data + */ + meta: MetaV1; + /** + * + */ + data?: DataTrackingResponseGetMultipleV1; +} + diff --git a/src/model/TrackingResponseV1.ts b/src/model/TrackingResponseV1.ts new file mode 100644 index 0000000..c8d7c4f --- /dev/null +++ b/src/model/TrackingResponseV1.ts @@ -0,0 +1,18 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { MetaV1 } from "./MetaV1"; +import { DataTrackingResponseV1 } from "./DataTrackingResponseV1"; + +export interface TrackingResponseV1 { + /** + * Meta data + */ + meta: MetaV1; + /** + * + */ + data: DataTrackingResponseV1; +} + diff --git a/src/model/TrackingUpdateTrackingByIdRequest.ts b/src/model/TrackingUpdateTrackingByIdRequest.ts new file mode 100644 index 0000000..bcfa51a --- /dev/null +++ b/src/model/TrackingUpdateTrackingByIdRequest.ts @@ -0,0 +1,152 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface TrackingUpdateTrackingByIdRequest { + /** + * The phone number(s) to receive sms notifications. Input `[]` to clear the value of this field. Supports up to 3 phone numbers. + */ + smses?: string[]; + /** + * Email address(es) to receive email notifications. Input `[]` to clear the value of this field. Supports up to 3 email addresses. + */ + emails?: string[]; + /** + * By default this field shows the `tracking_number`, but you can customize it as you wish with any info (e.g. the order number). + */ + title?: string; + /** + * Customer name of the tracking. + */ + customer_name?: string; + /** + * A globally-unique identifier for the order. + */ + order_id?: string; + /** + * The URL for the order in your system or store. + */ + order_id_path?: string; + /** + * Custom fields that accept an object with string field. In order to protect the privacy of your customers, do not include any + */ + custom_fields?: {[key: string]: any}; + /** + * Text field for the note.Input `""` to clear the value of this field. + */ + note?: string; + /** + * The recipient’s language. If you set up AfterShip notifications in different languages, we use this to send the recipient tracking updates in their preferred language. Use an to specify the language. + */ + language?: string; + /** + * The promised delivery date of the order. It uses the format YYYY-MM-DD. This has no timezone and uses whatever date you provide. Since other EDDs use the shipment recipient’s timezone, we suggest following the same logic here. + */ + order_promised_delivery_date?: string; + /** + * Shipment delivery type- `pickup_at_store`- `pickup_at_courier`- `door_to_door` + */ + delivery_type?: string; + /** + * Shipment pickup location for receiver + */ + pickup_location?: string; + /** + * Shipment pickup note for receiver + */ + pickup_note?: string; + /** + * Unique code of each courier. Provide a single courier.(https://admin.aftership.com/settings/couriers). Get a list of courier slug using + */ + slug?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * A unique, human-readable identifier for the order. + */ + order_number?: string; + /** + * Order date in YYYY-MM-DDTHH:mm:ssZ format. e.g. 2021-07-26T11:23:51-05:00 + */ + order_date?: string; + /** + * The carrier service type for the shipment. If you provide info for this field, AfterShip will not update it with info from the carrier. + */ + shipment_type?: string; + /** + * The for more details. + */ + origin_country_iso3?: string; + /** + * The state of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_state?: string; + /** + * The city of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_city?: string; + /** + * The postal of the sender’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_postal_code?: string; + /** + * The sender address that the shipment is shipping from. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + origin_raw_location?: string; + /** + * The for more details. + */ + destination_country_iso3?: string; + /** + * The state of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. Also the additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + destination_state?: string; + /** + * The city of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + destination_city?: string; + /** + * The postal of the recipient’s address. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. Also the additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + destination_postal_code?: string; + /** + * The shipping address that the shipment is shipping to. This can help AfterShip with various functions like tracking, carrier auto-detection and auto-correction, calculating an EDD, etc. + */ + destination_raw_location?: string; + /** + * (Legacy) Replaced by `origin_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * (Legacy) Replaced by `destination_country_iso3`. Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * (Legacy) Replaced by `destination_postal_code`. Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * (Legacy) Replaced by `destination_state`. Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; + /** + * The location_id refers to the place where you fulfilled the items. - If you provide a location_id, the system will automatically use it as the tracking's origin address. However, passing both location_id and any origin address information simultaneously is not allowed.- Please make sure you add your locations . + */ + location_id?: string; + /** + * The shipping_method string refers to the chosen method for delivering the package. Merchants typically offer various shipping methods to consumers during the checkout process, such as, Local Delivery, Free Express Worldwide Shipping, etc. + */ + shipping_method?: string; +} + diff --git a/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts b/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts new file mode 100644 index 0000000..b16b1ca --- /dev/null +++ b/src/model/TrackingUpdateTrackingBySlugTrackingNumberRequest.ts @@ -0,0 +1,109 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +import { CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest } from "./CustomFieldsTrackingUpdateTrackingBySlugTrackingNumberRequest"; + +export interface TrackingUpdateTrackingBySlugTrackingNumberRequest { + /** + * The phone number(s) to receive sms notifications. Supports up to 3 phone numbers. + */ + smses?: string[]; + /** + * Email address(es) to receive email notifications. Supports up to 3 email addresses. + */ + emails?: string[]; + /** + * By default this field shows the `tracking_number`, but you can customize it as you wish with any info (e.g. the order number). + */ + title?: string; + /** + * Customer name of the tracking. + */ + customer_name?: string; + /** + * A globally-unique identifier for the order. + */ + order_id?: string; + /** + * The URL for the order in your system or store. + */ + order_id_path?: string; + /** + * 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; + /** + * Text field for the note + */ + note?: string; + /** + * The recipient’s language. If you set up AfterShip notifications in different languages, we use this to send the recipient tracking updates in their preferred language. Use an to specify the language. + */ + language?: string; + /** + * The promised delivery date of the order. It uses the format YYYY-MM-DD. This has no timezone and uses whatever date you provide. Since other EDDs use the shipment recipient’s timezone, we suggest following the same logic here. + */ + order_promised_delivery_date?: string; + /** + * Shipment delivery type- `pickup_at_store`- `pickup_at_courier`- `door_to_door` + */ + delivery_type?: string; + /** + * Shipment pickup location for receiver + */ + pickup_location?: string; + /** + * Shipment pickup note for receiver + */ + pickup_note?: string; + /** + * Unique code of each courier. Provide a single courier.(https://admin.aftership.com/settings/couriers). Get a list of courier slug using + */ + slug?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on for more details. + */ + tracking_account_number?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on for more details. + */ + tracking_origin_country?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on for more details. + */ + tracking_destination_country?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on for more details. + */ + tracking_key?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on for more details. + */ + tracking_postal_code?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on for more details. + */ + tracking_ship_date?: string; + /** + * Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on for more details. + */ + tracking_state?: string; + /** + * A unique, human-readable identifier for the order. + */ + order_number?: string; + /** + * Order date in YYYY-MM-DDTHH:mm:ssZ format. e.g. 2021-07-26T11:23:51-05:00 + */ + order_date?: string; + /** + * The location_id refers to the place where you fulfilled the items. - If you provide a location_id, the system will automatically use it as the tracking's origin address. However, passing both location_id and any origin address information simultaneously is not allowed.- Please make sure you add your locations . + */ + location_id?: string; + /** + * The shipping_method string refers to the chosen method for delivering the package. Merchants typically offer various shipping methods to consumers during the checkout process, such as, Local Delivery, Free Express Worldwide Shipping, etc. + */ + shipping_method?: string; +} + diff --git a/src/model/UpdateTrackingBySlugTrackingNumberQuery.ts b/src/model/UpdateTrackingBySlugTrackingNumberQuery.ts new file mode 100644 index 0000000..7684597 --- /dev/null +++ b/src/model/UpdateTrackingBySlugTrackingNumberQuery.ts @@ -0,0 +1,14 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ +export interface UpdateTrackingBySlugTrackingNumberQuery { + tracking_account_number?: string; + tracking_origin_country?: string; + tracking_destination_country?: string; + tracking_key?: string; + tracking_postal_code?: string; + tracking_ship_date?: string; + tracking_state?: string; +} + diff --git a/src/model/WeightEstimatedDeliveryDateRequest.ts b/src/model/WeightEstimatedDeliveryDateRequest.ts new file mode 100644 index 0000000..5d166f6 --- /dev/null +++ b/src/model/WeightEstimatedDeliveryDateRequest.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface WeightEstimatedDeliveryDateRequest { + /** + * The weight unit of the package. + */ + unit: string; + /** + * The weight of the shipment. + */ + value: number; +} + diff --git a/src/model/WeightEstimatedDeliveryDateResponse.ts b/src/model/WeightEstimatedDeliveryDateResponse.ts new file mode 100644 index 0000000..69bdc8e --- /dev/null +++ b/src/model/WeightEstimatedDeliveryDateResponse.ts @@ -0,0 +1,16 @@ +/* + * This code was auto generated by AfterShip SDK Generator. + * Do not edit the class manually. + */ + +export interface WeightEstimatedDeliveryDateResponse { + /** + * The weight unit of the package. + */ + unit: string; + /** + * The weight of the shipment. + */ + value: number; +} + diff --git a/src/utils/parse_proxy.ts b/src/utils/parse_proxy.ts new file mode 100644 index 0000000..4705888 --- /dev/null +++ b/src/utils/parse_proxy.ts @@ -0,0 +1,80 @@ +import { AfterShipErrorCodes, AftershipError } from "../error"; + +export interface Proxy { + host: string; + port: number; + protocol?: string; + auth?: { + username: string; + password: string; + }; +} + +export function parseProxy(input?: string): Proxy | undefined { + if (!input) { + return undefined; + } + return { ...getAddress(input), ...getProtocol(input), ...getAuth(input) }; +} + +function getAddress(input: string): { host: string; port: number } { + if (input.includes("@")) { + input = input.substring(input.lastIndexOf("@") + 1); + } + else if (input.includes("://")) { + input = input.split("://")[1]; + } + if (!input.includes(":")) { + throw new AftershipError( + `Invalid option: proxy`, + AfterShipErrorCodes.INVALID_OPTION + ); + } + const host = input.split(":")[0]; + const port = parseInt(input.split(":")[1]); + if (/^\w+$/.test(host)) { + throw new AftershipError( + `Invalid option: proxy`, + AfterShipErrorCodes.INVALID_OPTION + ); + } + if (isNaN(port)) { + throw new AftershipError( + `Invalid option: proxy`, + AfterShipErrorCodes.INVALID_OPTION + ); + } + return { host: host, port: port }; +} + +function getProtocol(input: string): { protocol: string } { + if (!input.includes("://")) { + return { protocol: "http" }; + } + const protocol = input.split("://")[0]; + if (protocol.length < 3 || protocol.length > 6) { + throw new AftershipError( + `Invalid option: proxy`, + AfterShipErrorCodes.INVALID_OPTION + ); + } + return { protocol }; +} + +function getAuth(input: string): { auth: { username: string; password: string } } | undefined { + if (!input.includes("@")) { + return undefined; + } + if (input.includes("://")) { + input = input.split("://")[1]; + } + input = input.substring(0, input.lastIndexOf("@")); + if (!input.includes(":")) { + throw new AftershipError( + `Invalid option: proxy`, + AfterShipErrorCodes.INVALID_OPTION + ); + } + const [username, password] = input.split(":"); + return { auth: { username, password } }; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..75dd11e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "target": "ES6", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "strict": true, + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "noLib": false, + "declaration": true, + "lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"], + "outDir": "dist", + "typeRoots": ["node_modules/@types"] + }, + "include": ["src/**/*"], + "exclude": ["src/**/*.spec.js", "src/**/*.js"], + "jsdoc": { + "out": "support/jsdoc", + "access": "public" + } +} From d70e20c069f4a696baa54e4aa3ff991bc14fc0b9 Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 10:29:23 +0800 Subject: [PATCH 2/7] misc: updated document --- .gitignore | 2 ++ .npmignore | 1 + LICENSE.txt | 22 ++++++++++++++++++++++ README.md | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 LICENSE.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..bd6fcff --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +Jenkinsfile \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..cf9a7b7 --- /dev/null +++ b/LICENSE.txt @@ -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. \ No newline at end of file diff --git a/README.md b/README.md index a37b621..aa58be3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Before you begin to integrate: ### Installation ```bash -npm install --save aftership +npm install --save @aftership/tracking-sdk ``` ### Usage From 3dab715d3734b50210d89520794f11a961ec851a Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 11:00:13 +0800 Subject: [PATCH 3/7] doc: remove outdate document. --- README.md | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index aa58be3..561664c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ npm install --save @aftership/tracking-sdk // Step 1: Require the AfterShip client import {AfterShip} from '@aftership/tracking-sdk'; // or -const {AfterShip} = require('@aftership/tracking-sdk'); +// const {AfterShip} = require('@aftership/tracking-sdk'); // Step 2: Initialize the client object @@ -210,27 +210,6 @@ aftership.tracking .catch((e) => console.log(e)); ``` -```javascript -// GET /trackings/:slug/:tracking_number?tracking_postal_code=:postal_code&tracking_ship_date=:ship_date -aftership.tracking - .getTrackingBySlugTrackingNumber('dhl-global-mail', '420028359261290339630717209661', { - tracking_postal_code: "1234", - tracking_ship_date: "20200423", - }) - .then((result) => console.log(result)) - .catch((e) => console.log(e)); -``` - - -> Pro Tip: You can always use /:id to replace /:slug/:tracking_number. -```javascript -// GET /trackings/:id -aftership.tracking - .getTrackingById('hqhyzb21sm0colweuats7001') - .then((result) => console.log(result)) - .catch((e) => console.log(e)); -``` - **PUT** /trackings/:id ```javascript @@ -313,8 +292,8 @@ aftership.notification ```javascript aftership.notification .addNotificationByTrackingId('g0qe97idgrrbrlwiyvzco018',{ - 'emails': 'user1@gmail.com,user2@gmail.com,invalid EMail @ Gmail. com', - 'smses': '+85291239123,+85261236123,Invalid Mobile Phone Number' + 'emails': ['user1@gmail.com', 'user2@gmail.com'], + 'smses': ['+85291239123', '+85261236123'] }) .then(result => console.log(result)) .catch(e => console.log(e)); @@ -325,8 +304,8 @@ aftership.notification ```javascript aftership.notification .deleteNotificationByTrackingId('g0qe97idgrrbrlwiyvzco018',{ - 'emails': 'user1@gmail.com', - 'smses': '+85291239123' + 'emails': ['user1@gmail.com'], + 'smses': ['+85291239123'] }) .then(result => console.log(result)) .catch(e => console.log(e)); From ae6a28cd214814662b2a9719bd5246f865524907 Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 11:04:00 +0800 Subject: [PATCH 4/7] doc: add comment for optional code. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 561664c..0aafbfb 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Create AfterShip instance with options ```javascript import {AfterShip, AuthType} from '@aftership/tracking-sdk'; // or -const {AfterShip, AuthType} = require('@aftership/tracking-sdk'); +// const {AfterShip, AuthType} = require('@aftership/tracking-sdk'); const aftership = new AfterShip( { From d0b55d0568ff68d757173f2d2c2bc01535cadd8d Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 11:06:56 +0800 Subject: [PATCH 5/7] doc: modified format --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0aafbfb..a681585 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,10 @@ The SDK will return an error object when there is any error during the request, The AfterShip instance has the following properties which are exactly the same as the API endpoints: -courier - Get a list of our supported couriers. -tracking - Create trackings, update trackings, and get tracking results. -last_checkpoint - Get tracking information of the last checkpoint of a tracking. -notification - Get, add or remove contacts (sms or email) to be notified when the status of a tracking has changed. +- courier - Get a list of our supported couriers. +- tracking - Create trackings, update trackings, and get tracking results. +- last_checkpoint - Get tracking information of the last checkpoint of a tracking. +- notification - Get, add or remove contacts (sms or email) to be notified when the status of a tracking has changed. ### /trackings From 62445acb54e19d209bb93beff26ee69cff2729e1 Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 11:08:23 +0800 Subject: [PATCH 6/7] doc: modified example --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a681585..f1173ea 100644 --- a/README.md +++ b/README.md @@ -158,20 +158,20 @@ The AfterShip instance has the following properties which are exactly the same a ```javascript const payload = { - 'slug': 'usps', - 'tracking_number': '9261290284678900371871', - 'title': 'Title Name', - 'smses': [ + slug: 'usps', + tracking_number: '9261290284678900371871', + title: 'Title Name', + smses: [ '+18555072509', '+18555072501' ], - 'emails': [ + emails: [ 'email@yourdomain.com', 'another_email@yourdomain.com' ], - 'order_id': 'ID 1234', - 'order_id_path': 'http://www.aftership.com/order_id=1234', - 'custom_fields': { + order_id: 'ID 1234', + order_id_path: 'http://www.aftership.com/order_id=1234', + custom_fields: { 'product_name': 'iPhone Case', 'product_price': 'USD19.99' } From 4c58f83bdf30228249270c2679a38c98b55a0146 Mon Sep 17 00:00:00 2001 From: panxl6 Date: Fri, 21 Jun 2024 11:11:00 +0800 Subject: [PATCH 7/7] doc: add github release page url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1173ea..4334770 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This library allows you to quickly and easily use the AfterShip Tracking API via Node.js. -For updates to this library, see our GitHub release page. +For updates to this library, see our [GitHub release page](https://github.com/AfterShip/tracking-sdk-nodejs/releases). If you need support using AfterShip products, please contact support@aftership.com.