UNPKG

@lorenstuff/amazon-selling-partner-api

Version:

A package for interacting with the Amazon Selling Partner API.

119 lines 4.65 kB
// // Imports // import { AmazonSellingPartnerAPIError } from "./AmazonSellingPartnerAPIError.js"; // // Class // /** A client for v1 of the Shipping endpoints of the Amazon Selling Partner API. */ export class AmazonSellingPartnerShippingAPIClient { amazonSellingPartnerApiClient; constructor(amazonSellingPartnerApiClient) { this.amazonSellingPartnerApiClient = amazonSellingPartnerApiClient; } async cancelShipment(shipmentId) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/shipments/" + shipmentId + "/cancel", }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async createShipment(body) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/shipments", body: JSON.stringify(body), }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async getAccount() { const response = await this.amazonSellingPartnerApiClient.request({ method: "GET", path: "/shipping/v1/account", }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async getRates(body) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/rates", body: JSON.stringify(body), }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async getShipment(shipmentId) { const response = await this.amazonSellingPartnerApiClient.request({ method: "GET", path: "/shipping/v1/shipments/" + shipmentId, }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async getTrackingInformation(trackingId) { const response = await this.amazonSellingPartnerApiClient.request({ method: "GET", path: "/shipping/v1/tracking/" + trackingId, }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async purchaseLabels(shipmentId, body) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/shipments/" + shipmentId + "/purchaseLabels", body: JSON.stringify(body), }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async purchaseShipment(body) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/purchaseShipment", body: JSON.stringify(body), }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } async retrieveShippingLabel(shipmentId, trackingId, body) { const response = await this.amazonSellingPartnerApiClient.request({ method: "POST", path: "/shipping/v1/shipments/" + shipmentId + "/containers/" + trackingId + "/label", body: JSON.stringify(body), }); const responseData = await response.json(); if ("errors" in responseData) { throw new AmazonSellingPartnerAPIError(response, responseData.errors ?? []); } return responseData; } } //# sourceMappingURL=AmazonSellingPartnerShippingAPIClient.js.map