Poseidonas

payload downloads

by Poseidonas
Stores & catalogs
v3
>=3.88 <4
MIT

Overview

Summary generated from the README

Adds digital product delivery to a Payload store. Products or variants carry downloadable files, a completed order creates access grants, and customers get signed links that expire, count uses and stop working when an order is refunded or cancelled. Requires Payload 3.88 or newer and the official ecommerce plugin; local storage works by default and other storage needs a file resolver.

Features

  • Signed HMAC-SHA256 links with a short configurable lifetime
  • Per-order grants with download limits and optional expiry
  • Automatic revocation when an order is refunded or cancelled
  • Files streamed by the server so storage paths are never exposed
  • Customer endpoint listing own downloads, plus server helpers for order emails
  • Configurable grant statuses, collection slugs and field names

Use cases

  • Sell ebooks, software or templates from a Payload ecommerce store
  • Limit how many times and for how long a buyer can download a purchased file
  • Include secure download links in custom order confirmation emails

From the author

Digital products for Payload ecommerce: signed expiring download links, per order access and download limits.

Installation

npm i payload-downloads

1

Stars

0

Forks

0

Open Issues

2 weeks ago

Last Updated

26

Weekly Downloads

v1.0.2

npm Version

48.6 KB

Unpacked Size

0

Dependencies

GitHub stars

10 since Sep 6

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

22+3 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 202622
Dec 4, 202623
Dec 3, 202625
Dec 2, 202628
Dec 1, 202626
Nov 30, 202624
Nov 29, 202622
Nov 28, 202629
Nov 27, 202636
Nov 26, 2026223
Nov 25, 2026218
Nov 24, 2026217
Nov 23, 2026218
Nov 22, 2026214
Nov 21, 2026204
Nov 20, 2026195
Nov 19, 20268
Nov 18, 202610
Nov 17, 20269
Nov 16, 20267
Nov 15, 20267
Nov 14, 20269
Nov 13, 20268
Nov 12, 202612
Nov 11, 202610
Nov 10, 202611
Nov 9, 202611
Nov 8, 202612
Nov 7, 202612
Nov 6, 202613
Nov 5, 20269
Nov 4, 202610
Nov 3, 20269
Nov 2, 202610
Nov 1, 20267
Oct 31, 20265
Oct 30, 20264
Oct 29, 20262
Oct 28, 20261
Oct 27, 20262
Oct 26, 20262
Oct 25, 20263
Oct 24, 20263
Oct 23, 20263
Oct 22, 20267
Oct 21, 20267
Oct 20, 20267
Oct 19, 20266
Oct 18, 20265
Oct 17, 20265
Oct 16, 20265
Oct 15, 20264
Oct 14, 20265
Oct 13, 20264
Oct 12, 20264
Oct 11, 20265
Oct 10, 20267
Oct 9, 20267
Oct 8, 20265
Oct 7, 20265
Oct 6, 202610
Oct 5, 202611
Oct 4, 202613
Oct 3, 202612
Oct 2, 202617
Oct 1, 202616
Sep 30, 202616
Sep 29, 202615
Sep 28, 202614
Sep 27, 202613
Sep 26, 202616
Sep 25, 202613
Sep 24, 202613
Sep 23, 202612
Sep 22, 202611
Sep 21, 202612
Sep 20, 202613
Sep 19, 20269
Sep 18, 20267
Sep 17, 20269
Sep 16, 202611
Sep 15, 20269
Sep 14, 20269
Sep 13, 20267
Sep 12, 202610
Sep 11, 202612
Sep 10, 202610
Sep 9, 20269
Sep 8, 20269
Sep 7, 202613
Sep 6, 202619

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

Health Score

72/100Good

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/1340409911-root.svg)](https://payloaddirectory.dev/plugins/1340409911-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1340409911-root"><img src="https://payloaddirectory.dev/badge/1340409911-root.svg" alt="Payload Directory"></a>
Updated Nov 17, 2026Created Aug 20, 2026Published Nov 17, 2026

README

payload-downloads

npm node license payload

Sells digital products from a Payload store: a product or variant carries files, a paid order earns access to them, and the customer receives a signed link that expires, counts its uses and stops working the moment the order is refunded.

  • Works with @payloadcms/plugin-ecommerce and with any collection that holds orders
  • Signed links use node:crypto HMAC-SHA256, no runtime dependencies
  • The file is streamed by the plugin; no storage path, URL or bucket key ever reaches the client
  • No admin components, so it survives minor releases

Install

Requires Payload 3.88 or newer and @payloadcms/plugin-ecommerce 3.88 or newer. Verified against Payload 3.88.0 with the official plugin installed.

pnpm add payload-downloads
import { downloadsPlugin } from 'payload-downloads'

export default buildConfig({
  plugins: [
    downloadsPlugin({
      downloadLimit: 5,
      expiryDays: 30,
      linkTtlSeconds: 300,
    }),
  ],
})

Mark a product or variant downloadable, attach one or more files, and the plugin does the rest.

A signed in customer reads their own downloads from GET /api/downloads:

{
  "downloads": [
    {
      "id": "6a85...",
      "downloadCount": 1,
      "downloadLimit": 5,
      "expiresAt": "2026-09-18T10:00:00.000Z",
      "file": { "id": "3", "filename": "guide.pdf", "filesize": 918273, "mimeType": "application/pdf" },
      "remaining": 4,
      "url": "/api/downloads/file?expires=1800000300&file=3&grant=12&order=8&signature=Xk3...",
      "usable": true
    }
  ]
}

To put the same links in your own order email, call downloadLinksForOrder on the server.

What was measured

Why access is granted on completed and not on processing

Read from @payloadcms/[email protected]. The order status field is declared with defaultValue: 'processing', and confirmOrder writes status: 'processing' on every order it creates. processing is therefore the value an order carries because it exists, not because money settled: an order typed into the admin by hand, an import, or a second payment adapter all produce the same value without a payment having happened.

Handing over a file cannot be undone. The default grants on completed, which is a deliberate act by the shop. One line moves it earlier if that suits your trade:

downloadsPlugin({ grantOnStatuses: ['processing', 'completed'] })

Why a grant records the customer twice

Read from stripe/confirmOrder.ts, the order is written with

...(req.user ? { customer: req.user.id } : { customerEmail })

A logged in customer's order carries a customer and no customerEmail; a guest order carries an email and no customer. A grant records whichever the order has, and GET /api/downloads matches on both, so a customer who checked out as a guest and later registered with the same address still sees the download.

The signature

The link carries grant, order, file, expires and signature. The signature is

HMAC-SHA256( SHA256("payload-downloads:v1:" + secret), "v1\ngrant\norder\nfile\nexpires" )

base64url encoded, 43 characters. The key is derived from the secret rather than being the secret, so the same Payload secret used elsewhere is not the HMAC key. All four values are inside the signed message, separated by a character none of them may contain, so a signature cannot be moved to another file, another order, another grant or a later expiry. Verification compares with timingSafeEqual, and each of those five substitutions is refused by a test of its own.

A valid signature is not by itself permission to download. Before a byte is written the plugin also reloads the grant and refuses it if it is revoked, expired or at its limit, so a refund stops links that were already handed out, not only future ones.

Options

OptionDefaultMeaning
baseUrl''Text placed before a generated link. Empty gives a root relative link
customersSlug'users'Slug of the customers collection
disabledfalseStops granting, revoking and serving but keeps the fields and the collection, so the database keeps its shape
downloadableFieldName'downloadable'Checkbox marking a product or variant as downloadable
downloadLimit5Successful deliveries one grant allows. 0 means no limit
enableVariantstrueAdds the fields to variants and the variant column to a grant
endpointPath'/downloads'Path below the Payload API route
expiryDays0Days a grant stays usable. 0 means no expiry
filesFieldName'downloadFiles'Upload field holding the files
fileResolvernoneReads the bytes when the upload collection does not use local storage
grantOnStatuses['completed']Statuses that grant access on the way in
grantsSlug'download-grants'Collection holding one grant per order and file
isAdmin'admin' in req.user.rolesWho may read every grant. Customers always read their own
linkTtlSeconds300Seconds a signed link stays valid
ordersSlug'orders'Slug of the orders collection
productsSlug'products'Slug of the products collection
revokeOnStatuses['refunded', 'cancelled']Statuses that revoke access on the way in. [] never revokes
secretthe Payload secretKey the signature is derived from
uploadsSlug'media'Upload collection holding the files
variantsSlug'variants'Slug of the variants collection

A value that cannot be used is replaced by its default rather than being applied. A negative downloadLimit becomes 5, a linkTtlSeconds of 0 becomes 300, and 3.9 becomes 3. Nothing is silently reinterpreted: -5 never becomes 5. A status that appears in both lists revokes.

What it adds to your database

CollectionFieldTypeNotes
your products collectiondownloadablecheckboxindexed, defaults to false
your products collectiondownloadFilesupload, hasManyshown when downloadable is on
your variants collectiondownloadablecheckboxomitted when enableVariants is false
your variants collectiondownloadFilesupload, hasManya downloadable variant overrides its product
download-grantsorderrelationshipindexed, required
download-grantsfileuploadindexed, required
download-grantsproduct, variantrelationshipwhat the grant came from
download-grantscustomerrelationshipindexed, set for a signed in buyer
download-grantscustomerEmailemailindexed, set for a guest buyer
download-grantsdownloadCountnumbersuccessful deliveries so far
download-grantsdownloadLimitnumberthe limit in force when the grant was made
download-grantsexpiresAtdateempty when expiryDays is 0
download-grantslastDownloadedAtdate
download-grantsrevokedcheckboxindexed

The grants collection refuses create, update and delete through the API; it is written only by the plugin. Read is allowed to a customer for their own rows and to whoever isAdmin accepts.

Two endpoints are added: GET /api/downloads and GET /api/downloads/file.

Exported for server side use: downloadsPlugin, createDownloadLink, downloadLinksForOrder, grantAccess, revokeAccess, downloadableFilesForOrder, grantState, decideTransition, signDownload, verifyDownloadSignature, parseClaim, resolveConfig.

Honest limits

Local storage works out of the box, a storage adapter needs six lines. Payload has no stable public API for reading the bytes behind an upload document when a cloud adapter owns them. Rather than guess at an internal one, the plugin reads from the collection's staticDir and, when that is not available, asks you:

downloadsPlugin({
  fileResolver: async ({ filename }) => {
    const object = await s3.send(new GetObjectCommand({ Bucket: 'files', Key: filename }))
    return { body: object.Body as ReadableStream<Uint8Array>, size: object.ContentLength }
  },
})

Without one, a request for a file the plugin cannot read returns 501 and logs. It never redirects to the storage, because a redirect is the storage path.

A signed link is a bearer token. Anyone holding the URL inside its lifetime can download. It is not bound to an IP address, a session or a browser. linkTtlSeconds defaults to 300 for that reason; the customer gets a fresh link from GET /api/downloads whenever they need one.

Rotating the Payload secret invalidates every outstanding link. Set secret explicitly if you need the two to move independently.

A delivery is counted when the response starts, not when it finishes. A customer whose connection drops halfway has still used one of their five. There is no way to know from the server that a stream completed.

The count is atomic where the adapter allows it. The increment is written with $inc through payload.db.updateOne, which was measured at 50 concurrent increments on both the PostgreSQL and MongoDB adapters with none lost. If that call fails the plugin falls back to a read and a write, and in that fallback a burst of simultaneous requests using the same link can exceed the limit by the size of the burst. If the delivery cannot be recorded at all the request is refused with 500 rather than served unmetered.

Range requests are ignored. The whole file is sent from the beginning every time. Resuming an interrupted download starts again and, in the worst case, costs another unit of the limit.

Orders completed before you install get nothing. Grants are created when an order crosses into a granting status. Existing completed orders stay without grants until they are saved again.

Files are matched per order, not per line. Buying the same product twice on one order produces one grant with one limit, not two.

License

MIT. Copyright George Vasiliades, https://github.com/Poseidonas

Similar plugins