Quickstart
This example defines a one-time purchase that grants perpetual desktop access and permits three active license installations.
import { Access, Billing, Licensing, Offer, Purchase } from "@byfungsi/sapa";import { Effect } from "effect";
export const desktopOffer = Effect.gen(function* () { const access = yield* Access.entitlements({ entitlements: ["desktop.use"], duration: "perpetual", });
const licensing = yield* Licensing.eligibility({ entitlement: "desktop.use", activationLimit: 3, });
const purchase = yield* Purchase.parse({ key: "desktop.use", revision: 1, provides: [access, licensing], }); const billing = yield* Billing.oneTime({ price: { currency: "IDR", amount: 1_499_000n }, });
return yield* Offer.parse({ key: "desktop.perpetual", revision: 1, purchase, billing, });});Run the pure definition program at an application boundary:
import { Effect } from "effect";import { desktopOffer } from "./desktop-offer.js";
const offer = await Effect.runPromise(desktopOffer);console.log(offer.key, offer.revision);What SAPA validates
Section titled “What SAPA validates”- Definition keys and revisions have valid branded representations.
- The license entitlement is provided by the same purchase.
- Billing uses a supported variant.
1_499_000nis an exact minor-unit amount, not floating-point currency.- Unknown or excess fields fail at strict workflow boundaries.
Definition versus execution
Section titled “Definition versus execution”Offer.parse validates immutable commercial terms. It does not perform network
or persistence I/O. Durable registration and checkout operations require a
Sapa Layer supplied by the host application. See
runtime composition.