import { buildManifest, app, entity, field } from "@pylonsync/sdk";
import { stripe } from "@pylonsync/stripe";
export const Org = entity("Org", {
name: field.string(),
slug: field.string().unique(),
createdBy: field.id("User"),
createdAt: field.string(),
stripeCustomerId: field.string().optional(),
});
export const billing = stripe({
referenceType: "org", // or "user"
plans: [
{ name: "starter", priceId: process.env.STRIPE_PRICE_STARTER!, limits: { recordings: 50 } },
{ name: "pro", priceId: process.env.STRIPE_PRICE_PRO!, limits: { recordings: 500 } },
{ name: "scale", priceId: process.env.STRIPE_PRICE_SCALE!, limits: { recordings: -1 } },
],
hooks: {
onSubscriptionActivate: async (ctx, { referenceId, plan }) => {
// analytics, welcome email
},
onInvoice: async (ctx, { eventType, invoice }) => {
// record audit, slack alert on payment_failed
},
},
});
export default app({
name: "myapp",
entities: [Org /* + your entities */, ...billing.manifest.entities],
actions: [...billing.manifest.actions],
queries: [...billing.manifest.queries],
policies: [...billing.manifest.policies],
});