Skip to content

Downloads

A download benefit references one exact asset key and revision.

import { DownloadEmails, Downloads } from "@byfungsi/sapa";
import { Effect } from "effect";
const ebookBenefits = Effect.all([
Downloads.download({
asset: { key: "ebook.pdf", revision: 1 },
duration: "perpetual",
}),
DownloadEmails.customer({
asset: { key: "ebook.pdf", revision: 1 },
}),
]);

The email benefit is optional and must reference a download supplied by the same purchase. Parsing, registration, and replay never send email.

import { authorizeDownload } from "@byfungsi/sapa";
const authorization = authorizeDownload({
externalCustomerId: "customer-42",
asset: { key: "ebook.pdf", revision: 1 },
});

The runtime verifies customer history and exact asset eligibility, then returns the exact asset revision, a bearer URL, and expiresAt.

  • Install every referenced asset revision in the runtime manifest.
  • Generate bounded URLs only after SAPA authorizes the request.
  • Authenticate the customer in your application before passing externalCustomerId.
  • Do not expose storage bucket credentials or stable origin URLs.
  • Treat the returned URL as a secret until it expires.

Version a changed file as a new asset revision. Never silently replace bytes behind a revision already accepted by a purchase.