ExtantApe

payload plugin shipping

by ExtantApe
Stores & catalogs
v3
^3.80.0
MIT

Overview

Summary generated from the README

Adds shipping functions to Payload: address checks, rate quotes, label purchase, returns, refunds of unused labels and a tracking webhook endpoint. EasyPost is the first carrier provider. A beforeExternalCall hook must approve every outside call, and a purchases collection ensures each quote is bought only once. Requires Payload 3.80 or later and an EasyPost key; US addresses only.

Features

  • Quote, buy, return, refund and verify-address functions backed by a carrier provider
  • Hook that must return exactly true before any carrier call is sent
  • Each quote is bought once, using a hidden shipping-purchases collection
  • Webhook endpoint that fails closed with HMAC verification and replay protection
  • Parcel helpers for dimensional weight, billable weight and mailability
  • Fake carrier for tests and dry runs

Use cases

  • Buy postage labels for customer orders from a Payload-based store
  • Track parcels and map carrier statuses to delivery notices
  • Create prepaid return labels from customers to a fulfillment hub

From the author

Shipping for Payload: addresses, carrier rates, labels, refunds of unused labels and tracking webhooks, with EasyPost as the first carrier provider.

Installation

npm i @extantape/payload-plugin-shipping

0

Stars

0

Forks

0

Open Issues

6 days ago

Last Updated

220

Weekly Downloads

v0.2.0

npm Version

64.4 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 8

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
npm weekly downloads

220+220 since Nov 14

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026220
Dec 4, 2026214
Dec 3, 2026215
Dec 2, 2026198
Dec 1, 202622
Nov 30, 202623
Nov 29, 202623
Nov 28, 202620
Nov 27, 202620
Nov 26, 202617
Nov 25, 202623
Nov 24, 202630
Nov 23, 202640
Nov 22, 2026232
Nov 21, 2026229
Nov 20, 2026227
Nov 19, 2026227
Nov 18, 2026220
Nov 17, 2026208
Nov 16, 2026197
Nov 15, 20260
Nov 14, 20260

Each point is npm's rolling 7-day download count.

Health Score

75/100Excellent

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1456392848-root.svg)](https://payloaddirectory.dev/plugins/1456392848-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1456392848-root"><img src="https://payloaddirectory.dev/badge/1456392848-root.svg" alt="Payload Directory"></a>
Updated Nov 29, 2026Created Nov 13, 2026Published Nov 29, 2026

README

payload-plugin-shipping

Shipping for Payload: addresses, carrier rates, labels, refunds of unused labels and tracking webhooks, with EasyPost as the first carrier provider.

Status: 0.2.0 is the latest release (see CHANGELOG.md). 43 tests pass: 27 against Payload 3.92 with an in-memory MongoDB and a fake carrier, and 16 with no database, on the go-ahead, money, secrets and the webhook's refusals. The 27 cover addresses, parcels, buying, buying each quote once (in a row and at the same moment), returns, the side-effects hook and each answer it can give, production refused without it, a timed-out purchase, errors without addresses, and the webhook's 503, 401 (a custom provider's async check included), unknown, too-old, too-new, retry and refund cases, and purchases whose outcome is unclear. It has never called EasyPost: the request shapes follow EasyPost's documentation and are checked in test mode once a test key is saved. No site uses it yet.

What it does

  • Addresses of three kinds (street, PO Box, General Delivery), with addressProblems in plain codes, labelAddress (refuses a guessed or placeholder address), addressKey and carriersFor: PO Box and General Delivery take USPS only. Both addresses on a label always come from your records, never a carrier account's defaults.

  • Carrier calls, through a provider (EasyPost first):

    • quote: Ground Advantage first, else the cheapest allowed. A PO Box or General Delivery address on either side gets USPS only, whatever the caller asked;
    • buy, and buyLabel (a quote then a purchase). Each quote is bought once: see below;
    • buyReturn: from the customer to your hub's address, USPS only;
    • quoteReturn;
    • refund, for an unused label, within 30 days for USPS;
    • verifyAddress.
  • Your go-ahead before every outside call. beforeExternalCall({ action, mode }) runs before every verify, quote, buy and refund, and the external-call hook allows only true. The call goes ahead when the hook answers exactly true, or a promise of it. Every other answer refuses it and nothing is sent: false, nothing at all, 1, 'yes', an object, a throw or a rejected promise. A hook that only throws to refuse must now end with return true. Without the hook, test mode (an EZTK… key) is allowed and production mode is refused, so a copied live key can't buy postage from a test site by accident.

  • Errors in plain words, with a stable code. They never include a name, an address or your key. A purchase whose outcome is unknown (a timeout, a dropped connection, a 408, a 429, a 5xx, an unreadable reply, or a label with no tracking number) fails with MAYBE_BOUGHT. The error says the label may have been bought, carries the shipment's id as shipmentId, and says how to settle it. Address checks return EasyPost's codes, never its text.

  • Parcels: parcelFor (a box's outside size, longest side first, and weight), billableLb and dimWeightLb (USPS dimensional weight past one cubic foot), and mailability (too big, too heavy, the nonstandard fees, in words).

  • Tracking: trackingLink for USPS and UPS, and noticeFor, which maps a carrier status to out for delivery, delivered or an exception. Sending the emails is yours, through Notifications or your own code.

  • The webhook at /api/easypost/webhook (a root endpoint, webhookPath). It fails closed:

    • no secret configured: 503;
    • unsigned or wrongly signed: 401, with the HMAC checked over the raw bytes before anything is parsed. A custom provider's webhook.verify may be sync or async, and only an answer of exactly true counts: false, 1, an object such as { valid: false }, or an error thrown or rejected is a 401;
    • a tracker or refund event older than 7 days, or dated more than 10 minutes ahead, is ignored, so a captured body can't be replayed later;
    • an event no handler claims: 200 "unknown", nothing written;
    • a handler that throws, or answers anything but 'handled' or 'unknown': 500, so the carrier retries.

    Handlers are yours, or another plugin's, registered at config.custom.shippingHandlers with no import. They must be idempotent, because carriers retry.

  • Buy each quote once. buy and buyLabel claim the quote in a record with a unique key before the carrier is called, so one quote ends in one purchase, across repeated calls, calls made at the same moment and several server instances.

    • a second buy of a bought quote answers the first label, with no carrier call;
    • a buy that arrives while the first is still running is refused with BUY_IN_PROGRESS, with no carrier call. So is every later one if the server stopped mid-purchase;
    • after MAYBE_BOUGHT the quote stays locked, and every later buy of it answers MAYBE_BOUGHT with no carrier call. To settle it, look up the shipment (shipmentId on the error) with the carrier. If it has a label, use it or refund it. If it has none, get a new quote and buy that one;
    • after a clear refusal from the carrier nothing was bought, and the same quote can be tried again;
    • if the claim can't be stored, the answer is NOT_CLAIMED and nothing is sent.

    The purchase request also carries an Idempotency-Key header made from the quote's shipment and rate. EasyPost's documentation, as read on 2026-11-26, doesn't describe that header, so the plugin doesn't count on it: the record is what holds.

  • One collection, shipping-purchases, for those claims: the quote's key, a status, the shipment's id and the label that came back (tracking number, label link, price). It holds no name or address, it's hidden from the admin, and every access rule answers no, so only the plugin's server code reads or writes it. The claim is written outside any transaction of yours. Your own code still records each label against its order or kit.

  • A fake carrier for tests and dry runs, only from @extantape/payload-plugin-shipping/testing, so a production bundle can't pick it by accident. Its prices are made up, and every rate and label says fake: true.

On its own, and with others

On its own: Shipping needs only Payload and an EasyPost key, which your site passes in, or the fake carrier for tests. It adds one small collection, shipping-purchases, which keeps each quote to one purchase. Your own code records each label it buys against its order, and your own handlers answer the webhook.

Needs: Payload ^3.80.0 as a peer dependency. No other EXTANT APE plugin is required.

Works with:

  • Sample Kits: your site passes Shipping's functions into Sample Kits' adapters.shipping, and Sample Kits registers its tracking and refund handler at config.custom.shippingHandlers. The two never import each other.
  • Notifications: Shipping sends nothing itself. noticeFor turns a carrier status into out for delivery, delivered or a problem, and the plugin that owns the parcel can send that through Notifications.
  • Kitting: Kitting's box suggestions can use Shipping's rates. From Kitting 0.3, pass Shipping's quote to Kitting's adapter as it is: shipping: { provider: ratesFromShipping({ quote, from }) }. Neither plugin imports the other, and every quote still goes through your beforeExternalCall hook. If a quote fails, Kitting packs by its own postage rates and marks the suggestion.

Color Theory: none needed. It has no screens of its own, and its collections use Payload's standard admin, which takes Color Theory's admin colors when its applyToAdmin option is on.

Family: Shipping sits in the Fulfillment family, with Kitting, Restock, Sample Kits, Scan, Labels, Wizards, Custody and Sequences, though the families are a working draft and Fulfillment is due to be split into different groups.

Install

npm install @extantape/payload-plugin-shipping
import { easyPost, shippingPlugin } from '@extantape/payload-plugin-shipping'

shippingPlugin({
  provider: easyPost({ apiKey: process.env.EASYPOST_API_KEY, webhookSecret: process.env.EASYPOST_WEBHOOK_SECRET }),
  beforeExternalCall: ({ action, mode }) => mySideEffectsCheck('easypost', action, mode) === true, // only an exact true allows the call
  handlers: [{ owner: 'orders', onTracker: async ({ event }) => (await markTracking(event)) ? 'handled' : 'unknown' }],
})

The plugin reads no environment: your site passes the key and the secret in.

The go-ahead hook guards the plugin's functions (quote, buy, buyLabel, refund and the rest). The provider object itself, from easyPost() or config.custom.shipping.provider, calls the carrier directly: it's server code, so treat it like your key and go through the functions.

Limits

  • US addresses only for now.
  • EasyPost is the only provider. The contract allows others.
  • A label ledger across owners is planned, not in 0.1.
  • Buying once is per quote. buyLabel and buyReturn make a new quote on every call, so calling one of them twice for the same order buys two labels. To make a retry safe, call quote, keep the quote with the order, and buy that.
  • A locked quote is settled by hand, with the steps above. The plugin doesn't look the shipment up at the carrier for you yet.
  • Buying once is enforced in the plugin's functions. The provider object on its own keeps no record.

Commands

npm test          # integration tests, in-memory MongoDB, fake carrier
npm run typecheck
npm run build

License

MIT. See LICENSE.

Similar plugins