npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@classytic/referral

v0.1.0

Published

Referral ATTRIBUTION engine — shareable codes, who-referred-whom, conversion tracking, dedupe + self-referral guard. Single responsibility: it answers 'who drove this sale', NOT money (that's @classytic/revenue) or points (that's @classytic/loyalty). Powe

Readme

@classytic/referral

Referral attribution engine for MongoDB — shareable codes, who-referred-whom, conversion tracking, dedupe + self-referral guard, and an optional approve/reject review gate.

Single responsibility. It answers "who drove this sale" — nothing more. It does not move money (that's @classytic/revenue — make the referrer a split participant) and does not award points (that's @classytic/loyalty). It emits referral:converted; the host rewards however it likes. Clean bounded context, composable.

Install

npm i @classytic/referral

Peers: @classytic/mongokit >=3.16, @classytic/primitives >=0.7.1, @classytic/repo-core >=0.6, mongoose >=9.4, zod >=4.

Quick start

import { createReferral } from '@classytic/referral';

const referral = await createReferral({
  connection: mongoose.connection,
  tenant: { fieldType: 'objectId' },
});

// A creator/affiliate gets a shareable code (idempotent per owner).
const { code } = await referral.repositories.referralCode.generateCode(creatorId, 'user', ctx);

// At checkout: resolve the code → referrer and record the attribution in one call.
const r = await referral.attributeSale(
  { code, refereeRef: buyerId, refereeModel: 'user', sourceRef: orderId, sourceModel: 'Order' },
  ctx,
);
// r === null → unknown code (sale just proceeds). Otherwise a Referral (status 'converted').

// Optional review gate (fraud/eligibility) before rewarding:
await referral.repositories.referral.approve(String(r._id), { decidedBy: mgrId }, ctx);

How the host rewards the referrer

attributeSale returns the referrer; turn that into whatever reward fits:

  • Money cut (recommended): add the referrer as a referrer participant in your @classytic/revenue split → settlement → wallet → payout.
  • Affiliate % with tiers/clawbacks: feed it to @classytic/commission.
  • Points (refer-a-friend): @classytic/loyalty.

API

  • referralCode: generateCode(ownerRef, ownerModel, ctx) (idempotent), lookupByCode(code, ctx), deactivate(code, ctx).
  • referral: recordConversion(input, ctx) (idempotent per source, self-referral guard), approve / reject (gated by ApprovalChain from @classytic/primitives/approval, P7), updateApprovals, listForReferrer.
  • engine: resolveReferrer(code, ctx), attributeSale(input, ctx), syncIndexes(), destroy().
  • Events: referral:code.created / code.deactivated / converted / approved / rejected (referralEventDefinitions for arc's registry).

Conventions

Built on @classytic/primitives + @classytic/repo-core per PACKAGE_RULES.md. ESM-only, subpath exports, verbatimModuleSyntax, no sourcemaps/declaration maps. Multi-tenant, soft-delete, dedupe via partial-unique indexes. Tests follow testing-infrastructure.md (unit + integration + tenant probe).