Skip to content

Quickstart

This example defines a one-time purchase that grants perpetual desktop access and permits three active license installations.

desktop-offer.ts
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:

main.ts
import { Effect } from "effect";
import { desktopOffer } from "./desktop-offer.js";
const offer = await Effect.runPromise(desktopOffer);
console.log(offer.key, offer.revision);
  • Definition keys and revisions have valid branded representations.
  • The license entitlement is provided by the same purchase.
  • Billing uses a supported variant.
  • 1_499_000n is an exact minor-unit amount, not floating-point currency.
  • Unknown or excess fields fail at strict workflow boundaries.

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.