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

@86d-app/referrals

v0.0.25

Published

Customer referral program module for 86d commerce platform

Readme

[!WARNING] This project is under active development and is not ready for production use. Please proceed with caution. Use at your own risk.

Referrals Module

Customer referral program with unique shareable codes, referral tracking, and configurable reward rules. Supports percentage discounts, fixed discounts, and store credit rewards for both referrers and referees.

Installation

npm install @86d-app/referrals

Usage

import referrals from "@86d-app/referrals";

const module = referrals({
  maxCodesPerCustomer: "1",
});

Configuration

| Option | Type | Default | Description | |---|---|---|---| | maxCodesPerCustomer | string | "1" | Maximum referral codes a single customer can create |

Store Endpoints

| Method | Path | Description | |---|---|---| | GET | /referrals/my-code | Get the current customer's referral code | | GET | /referrals/my-referrals | List the current customer's referrals | | GET | /referrals/my-stats | Get referral stats for the current customer | | POST | /referrals/apply | Apply a referral code |

Admin Endpoints

| Method | Path | Description | |---|---|---| | GET | /admin/referrals | List all referrals | | GET | /admin/referrals/stats | Get global referral statistics | | GET | /admin/referrals/codes | List all referral codes | | GET | /admin/referrals/rules | List reward rules | | POST | /admin/referrals/rules/create | Create a reward rule | | GET | /admin/referrals/codes/:id | Get a referral code | | POST | /admin/referrals/codes/:id/deactivate | Deactivate a referral code | | GET | /admin/referrals/:id | Get a referral | | POST | /admin/referrals/:id/complete | Complete a referral | | POST | /admin/referrals/:id/revoke | Revoke a referral | | PUT | /admin/referrals/rules/:id/update | Update a reward rule | | DELETE | /admin/referrals/rules/:id/delete | Delete a reward rule |

Controller API

The ReferralController interface is exported for inter-module use (e.g. checkout applying referral discounts).

interface ReferralController {
  // Codes
  createCode(params: { customerId: string; maxUses?: number; expiresAt?: Date }): Promise<ReferralCode>;
  getCode(id: string): Promise<ReferralCode | null>;
  getCodeByCode(code: string): Promise<ReferralCode | null>;
  getCodeForCustomer(customerId: string): Promise<ReferralCode | null>;
  listCodes(params?: { active?: boolean; take?: number; skip?: number }): Promise<ReferralCode[]>;
  deactivateCode(id: string): Promise<ReferralCode | null>;

  // Referrals
  createReferral(params: { referralCodeId: string; refereeCustomerId: string; refereeEmail: string }): Promise<Referral | null>;
  getReferral(id: string): Promise<Referral | null>;
  listReferrals(params?: { referrerCustomerId?: string; refereeCustomerId?: string; status?: ReferralStatus; take?: number; skip?: number }): Promise<Referral[]>;
  completeReferral(id: string): Promise<Referral | null>;
  revokeReferral(id: string): Promise<Referral | null>;

  // Reward Rules
  createRewardRule(params: { name: string; referrerRewardType: RewardType; referrerRewardValue: number; refereeRewardType: RewardType; refereeRewardValue: number; minOrderAmount?: number }): Promise<ReferralRewardRule>;
  listRewardRules(params?: { active?: boolean }): Promise<ReferralRewardRule[]>;
  updateRewardRule(id: string, params: Partial<ReferralRewardRule>): Promise<ReferralRewardRule | null>;
  deleteRewardRule(id: string): Promise<boolean>;

  // Stats
  getStats(): Promise<ReferralStats>;
  getStatsForCustomer(customerId: string): Promise<{ code: ReferralCode | null; totalReferrals: number; completedReferrals: number; pendingReferrals: number }>;
}

Types

type ReferralStatus = "pending" | "completed" | "expired" | "revoked";
type RewardType = "percentage_discount" | "fixed_discount" | "store_credit";

interface ReferralCode {
  id: string;
  customerId: string;
  code: string;
  active: boolean;
  usageCount: number;
  maxUses: number;
  expiresAt?: Date;
  createdAt: Date;
}

interface Referral {
  id: string;
  referrerCodeId: string;
  referrerCustomerId: string;
  refereeCustomerId: string;
  refereeEmail: string;
  status: ReferralStatus;
  referrerRewarded: boolean;
  refereeRewarded: boolean;
  completedAt?: Date;
  createdAt: Date;
}

interface ReferralRewardRule {
  id: string;
  name: string;
  referrerRewardType: RewardType;
  referrerRewardValue: number;
  refereeRewardType: RewardType;
  refereeRewardValue: number;
  minOrderAmount: number;
  active: boolean;
  createdAt: Date;
  updatedAt: Date;
}

interface ReferralStats {
  totalCodes: number;
  totalReferrals: number;
  completedReferrals: number;
  pendingReferrals: number;
  conversionRate: number;
}

Store Components

ReferralApply

Provides a form for customers to enter and submit a referral code. Handles validation, displays success or error states, and automatically uppercases the code before submission.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<ReferralApply />

Best used on a checkout page or dedicated referral redemption page where customers can apply a friend's referral code.

ReferralDashboard

Displays the customer's referral statistics including their referral code, total referrals, completed referrals, and pending referrals. Fetches stats automatically from the module client.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<ReferralDashboard />

Best used on a customer account page to show referral program performance at a glance.

ReferralShare

Shows the customer's referral code with copy-to-clipboard buttons for both the code and a shareable referral URL. Fetches the customer's referral code and usage count from the module client.

Props

None. The component manages its own state and fetches data via the module client.

Usage in MDX

<ReferralShare />

Best used on a referral program page or account dashboard where customers can grab their referral link to share with friends.

Notes

  • Each customer can have up to maxCodesPerCustomer referral codes (default 1).
  • Setting maxUses: 0 on a code means unlimited uses.
  • Reward fulfillment is tracked independently for referrer (referrerRewarded) and referee (refereeRewarded).
  • The referral flow is: customer generates code, referee applies it, admin completes the referral, then rewards are granted.