Socket
Socket
Sign inDemoInstall

dispatch-node

Package Overview
Dependencies
263
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dispatch-node

The node wrapper for the dispatch Sender API.


Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Install size
2.54 MB
Created
Weekly downloads
 

Readme

Source

Dispatch Sender Node.js Library

The Dispatch Sender Node library provides convenient access to the Dispatch Sender API from applications written in server-side JavaScript. Detailed documentation can be found here.

Installation

Install the package with:

npm install dispatch-node --save

Usage

The package needs to be configured with your account's API Key, which is available in the Dispatch Dashboard.

const Dispatch = require("dispatch-node");
const dispatch = new Dispatch("key_EHKD5tbatzX59DArnTBjhr46G5n1f4aJkvwPByft");

dispatch.deliveries
  .list()
  .then((response) => console.log(response.data))
  .catch((error) => console.error(error));

Using Promises

Every method returns a chainable promise which can be used instead of a regular callback:

// Create a new delivery and then select the cheapest rate to purchase

const sender = {
  name: "Dispatch Roasters",
  email: "roasters@getdispatch.app",
  location_id: "loc_1uzCQL4cTjjw3vRfE2qYk1",
};

const recipient = {
  name: "Jamie Jones",
  email: "jamie.jones@getdispatch.app",
  address: {
    address_line1: "500 7th Ave",
    city: "New York",
    state: "NY",
    zipcode: "10018",
  },
};

const parcel = {
  length: 10, // inches
  width: 10, // inches
  height: 10, // inches
  weight: 5.5, // pounds
};

dispatch.deliveries
  .create(sender, recipient, [parcel]) //parcel is passed in an array since you can pass multiple parcels as part of one delivery
  .then((response) => {
    const delivery = response.data;

    //your logic to select the rate you want.
    //You could have a customer select it or
    //you can filter by price or service level

    //in this example, we're selecting the first rate
    const rate = delivery.rates[0];
    return dispatch.deliveries.buy(delivery.id, rate.id);
  })
  .then((response) => {
    //new delivery was created
  })
  .catch((err) => {
    //deal with the error
  });

Webhooks

From the Dispatch Dashboard you can configure webhooks. There are several webhook statuses you can choose from. Our webhooks expect a response with a status code of 200 within 5 seconds. This should be enough time to process the data and respond back to us. If we do not receieve a response back from you within 5 seconds, we'll retry the webhook a second time after waiting for 3 seconds.

Our webhooks will attempt to POST to your endpoint.

EventDescription
delivery_createdThis will fire when the delivery intent was created. This is before the purchase was made
delivery_expiredThis will fire after a delivery intent expires. Delivery intents that are not captured within 15 minutes after automatically expired
delivery_purchasedThis webhook will fire after a delivery intent is successfully captured
tracking_updatedThis webhook will fire when there are any tracking updates to the package. The tracking updated webhook does not fire when the inital delivery intent is created or purchased.

Each webhook will contain the entire Delivery object. Most often, you're probably interested in the tracking_updates property which is an ordered array of Tracker objects or the tracking_status property which is the current Tracker object.

Package Statues

Dispatch packages have two "statues": the status and substatus. The status describes the general concept of what is happening to the package, and the substatus gives you more detail about the package. For example, the status could be in_transit but the substatus will give you details about the transit like out_for_delivery. Internally at Dispatch, we use the substatus field more often. The status and substatus can be found on the Delivery object and the Tracker object.

Below is the list of statuses that we support. Keep in mind that the Tracker object will always have a human readable message that you can display.

statussubstatusis_issuedescription
pre_transitcreatedfalsePackage was created
transitaddress_issuetrueIssue with the address
transitcourier_at_senderfalseCourier arrived to pickup up the package
transitcontact_couriertrueCourier needs to be contacted
transitdelayedtruePackage will not get there on time
transitdelivery_attemptedtrueDelivery attempted but not compelted
transitdelivery_rescheduledtrueDelivery rescheduled
transitdelivery_scheduledfalseDelivery data scheduled
transitlocation_inaccessibletrueCourier could not get to the location
transitout_for_deliveryfalsePackage it out for delivery
transitpackage_acceptedfalsePackage was accepted. Taken from sender.
transitpackage_at_waypointfalsePackage was accepted by an intermediate location
transitin_transitfalsePackage is in transit
transitpickup_availblefalsePickup avaible
transitpackage_damagedtruePackage was damaged in transit
delivereddeliveredfalsePackage was successfully delivered
returnedreturn_to_sendertruePackage was returned
failedpackage_undeliverabletruePackage could not be delivered
failedpackage_losttruePackage was lost
canceledcanceledtrueThis delivery was canceled. Usually do to a refund
unknownunknowntrueDispatch doesn't know what happened

Keywords

FAQs

Last updated on 28 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc