Register offers
Parse definitions first, then register them through a composed runtime during startup or an explicit configuration operation.
import { Access, Billing, Limits, Offer, Purchase, registerOffers,} from "@byfungsi/sapa";import { Effect } from "effect";
export const installOffers = Effect.gen(function* () { const access = yield* Access.entitlements({ entitlements: ["workspace.use"], duration: "purchased_period", }); const limit = yield* Limits.resource({ resource: "workspace.project", quantity: 100, entitlement: "workspace.use", }); const purchase = yield* Purchase.parse({ key: "workspace.plan", revision: 1, provides: [access, limit], }); const billing = yield* Billing.subscription({ family: "workspace", price: { currency: "IDR", amount: 300_000n }, interval: "month", }); const pro = yield* Offer.parse({ key: "workspace.pro", revision: 1, purchase, billing, });
return yield* registerOffers([pro]);});Provide your Sapa runtime Layer when running installOffers.
Registration guarantees
Section titled “Registration guarantees”- The collection is strictly decoded and bounded to 1,000 entries.
- Exact duplicate definitions deduplicate safely.
- Reusing an offer or purchase key and revision with changed terms conflicts.
- Referenced download assets, meters, fulfillment bindings, and merchant access policies must exist in the installed capability manifest.
- Registration does not charge customers, send email, or execute fulfillment.
Revision workflow
Section titled “Revision workflow”To change terms, copy the definition, increment its revision, and register both old and new revisions. Keep old revisions installed while historical purchases, renewals, invoices, or obligations still reference them.