Skip to Content

Add a Waitlist, Invites, Referrals and Onboarding

Launch tooling in your own database: waitlist, one-shot invites, referral rewards, onboarding progress, a changelog and feedback.

Install

npm i @dapplelight/signet-db drizzle-orm

Create the tables and service

src/server/growth.ts
import { growthTables } from "@dapplelight/signet-db/columns/sqlite"
import { createGrowth } from "@dapplelight/signet-db/growth"
import { db } from "./db"

export const { waitlist, invites, referralCodes, referrals, marks, feedback } = growthTables()

export const growth = createGrowth(db, {
  tables: { waitlist, invites, referralCodes, referrals, marks, feedback },
  inviteTtlMs: 7 * 86_400_000,
})

Run the waitlist and invites

src/server/launch.ts
import { growth } from "./growth"

export async function launch(email: string, userId: string, orgId: string, referralCode?: string) {
  await growth.joinWaitlist(email, { source: "launch", referralCode })
  await growth.markInvited([email])

  const { invite, token } = await growth.createInvite({ invitedBy: userId, scope: orgId, role: "member", email })
  const result = await growth.acceptInvite(token, { userId, email })
}

The token is returned once; only its hash is stored.

Reward referrals once

src/server/referrals.ts
import { growth } from "./growth"

export async function referNewUser(userId: string, newUserId: string) {
  const code = await growth.referralCode(userId)
  await growth.refer(code, newUserId)

  const c = await growth.convertReferral(newUserId)
  if (c?.first) await growth.markRewarded(newUserId)
}

Track onboarding, changelog and feedback

src/server/onboarding.ts
import { growth } from "./growth"

export async function onboard(userId: string, entries: { date: Date }[], message: string) {
  await growth.completeStep(userId, "profile")
  const progress = await growth.onboarding(userId, ["profile", "invite", "first-project"])
  const unseen = await growth.unseenChangelog(userId, entries)
  await growth.sendFeedback({ subject: userId, kind: "bug", message, rating: 4, page: "/settings" })
}

Next