Add Subscription Charts and Offers
MRR, churn and trial conversion charts, free-trial and win-back offers, promotional grants and Apple refund answers.
Install
npm i @dapplelight/signet-server @dapplelight/signet-ui recharts hono drizzle-ormThis builds on Add remote paywalls.
Create the charts
import { chartsCsv, createCharts } from "@dapplelight/signet-db/charts"
import { actor } from "./auth"
import { db } from "./db"
import { chartAudiences, customerEvents, offerings } from "./db/schema"
export const charts = createCharts(db, {
tables: { customerEvents, chartAudiences, offerings },
fx: { base: "USD", rates: { INR: 0.012, EUR: 1.08 } }, // optional: totals in one currency
})
const r = await charts.metrics({ from: "2026-10-01", to: "2026-10-31", store: "appstore", country: "IN" })
// r.days[i]: activeSubscribers, mrr, newRevenue, refunds, churned, trialConversions, ...
const a = await charts.saveAudience("India App Store", { store: "appstore", country: "IN" }, { actor })
await charts.csv({ from: "2026-10-01", to: "2026-10-31", audience: a.id })Log paywall views so conversion can be measured:
import { customers } from "../monetisation"
export async function logPaywallView(userId: string) {
await customers.logImpression(userId, { offering: "default", version: 3, country: "IN" })
}Serve and draw them
import { Hono } from "hono"
import { monetisationAdminRoutes } from "@dapplelight/signet-server/http/monetisation"
import { actor, authorize } from "./auth"
import { charts } from "./charts"
import { customers, off } from "./monetisation"
const app = new Hono()
app.route("/api/admin/billing", monetisationAdminRoutes({ offerings: off, customers, charts, authorize, actor }))import { SubscriptionCharts } from "@dapplelight/signet-ui/screens/subscription-charts"Publish a trial and a win-back offer
import { actor } from "./auth"
import { customers, off } from "./monetisation"
export async function publishOffers(userId: string, audience: Record<string, string>) {
await off.publish("default", {
products: [{
id: "pro.monthly", store: "appstore", plan: "pro", interval: "month",
offers: [
{ id: "trial7", type: "free_trial", days: 7 },
{ id: "winback50", type: "win_back", price: { amount: 249, currency: "USD" }, days: 30,
eligibility: { lapsedDays: 30 } },
],
}],
}, { actor })
const offering = await customers.withOffers(userId, await off.current("onboarding", audience))
await customers.redeemOffer(userId, offering, "winback50")
}Each offer is once per customer. redeemOffer claims it before you apply it at checkout.
Grant a promotional plan
import { actor } from "./auth"
import { customers } from "./monetisation"
export async function grantBeta(userId: string, grantId: string) {
await customers.grantPromotional(userId, { plan: "pro", days: 30, note: "Beta tester" }, { actor })
await customers.endPromotional(userId, grantId, { actor }) // early
}It lapses exactly at its expiry, with no job to run, and charts leave it out.
Answer Apple refund requests
import { createCustomers } from "@dapplelight/signet-db/customers"
import { db } from "./db"
import { tables } from "./db/schema"
import { ent, privacy, store } from "./services"
import { appstoreGateway } from "./gateways"
const customers = createCustomers(db, {
tables,
entitlements: ent,
payments: store,
consumption: {
consented: (subject) => privacy.has(subject, "apple_refund_info"), // no consent, no answer
},
})
onEvent: async (e) => {
await customers.record(e)
const r = await customers.consumptionInfo(e)
if (r.respond) await appstoreGateway.sendConsumptionInfo(r.transactionId, r.body)
}Apple wants the answer within 12 hours.