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

creda-sdk

v1.0.0

Published

Simple SDK for managing loyalty points using Pocketbase.

Readme

Creda Loyalty SDK

Simple SDK for managing loyalty points using Pocketbase.

Installation

npm install creda-sdk

Quick Start

Step 1: Import and Initialize

const { Loyalty } = require('creda-sdk');

const loyalty = new Loyalty('your-secret-key');

Step 2: Give Points to Users

// Give 100 points to a user
const newBalance = await loyalty.mint('[email protected]', 100);
console.log(`New balance: ${newBalance}`);

Step 3: Check User Balance

// Check how many points a user has
const balance = await loyalty.getBalance('[email protected]');
console.log(`User has ${balance} points`);

Step 4: Transfer Points Between Users

// Send 50 points from one user to another
await loyalty.distribute('[email protected]', '[email protected]', 50);
console.log('Transfer completed');

Step 5: Deduct Points

// Remove 25 points from a user (when they make a purchase)
const remainingBalance = await loyalty.burn('[email protected]', 25);
console.log(`Remaining balance: ${remainingBalance}`);

Complete Example

const { Loyalty } = require('creda-sdk');

async function example() {
  const loyalty = new Loyalty('your-secret-key');
  
  try {
    // Give points
    await loyalty.mint('[email protected]', 100);
    
    // Check balance
    const balance = await loyalty.getBalance('[email protected]');
    console.log(`Alice has ${balance} points`);
    
    // Transfer points
    await loyalty.distribute('[email protected]', '[email protected]', 30);
    
    // Use points
    await loyalty.burn('[email protected]', 20);
    
    console.log('All operations completed!');
  } catch (error) {
    console.error('Error:', error.message);
  }
}

example();

API Methods

| Method | Description | Returns | |--------|-------------|---------| | mint(email, amount) | Add points to user | New balance | | distribute(fromEmail, toEmail, amount) | Transfer points | true | | getBalance(email) | Get user's points | Current balance | | burn(email, amount) | Remove points | New balance |

Error Handling

The SDK will throw errors for:

  • Invalid secret key
  • Insufficient balance for transfers/burns
  • Network connection issues

Always wrap SDK calls in try/catch blocks. z

Publishing to NPM

Step 1: Prepare for Publishing

# Login to NPM (you need an NPM account)
npm login

# Update package.json version if needed
npm version patch  # or minor/major

Step 2: Publish

npm publish

Step 3: Install from NPM

Once published, users can install your package:

npm install creda-sdk

Using with Next.js

Your SDK works perfectly with Next.js! Here are examples:

API Route (pages/api/loyalty.js or app/api/loyalty/route.js)

import { Loyalty } from 'creda-sdk';

const loyalty = new Loyalty(process.env.LOYALTY_SECRET_KEY);

// For Pages Router
export default async function handler(req, res) {
  try {
    const { email, amount } = req.body;
    const balance = await loyalty.mint(email, amount);
    res.json({ success: true, balance });
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
}

// For App Router
export async function POST(request) {
  try {
    const { email, amount } = await request.json();
    const balance = await loyalty.mint(email, amount);
    return Response.json({ success: true, balance });
  } catch (error) {
    return Response.json({ error: error.message }, { status: 500 });
  }
}

Client-side Usage (React Component)

'use client'; // for App Router

import { useState } from 'react';

export default function LoyaltyComponent() {
  const [balance, setBalance] = useState(0);
  const [email, setEmail] = useState('');

  const handleMint = async () => {
    try {
      const response = await fetch('/api/loyalty', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ email, amount: 100 })
      });
      const data = await response.json();
      setBalance(data.balance);
    } catch (error) {
      console.error('Error:', error);
    }
  };

  return (
    <div>
      <input 
        value={email} 
        onChange={(e) => setEmail(e.target.value)}
        placeholder="Enter email"
      />
      <button onClick={handleMint}>Give 100 Points</button>
      <p>Balance: {balance}</p>
    </div>
  );
}

Environment Variables

Add to your .env.local file:

LOYALTY_SECRET_KEY=your-secret-key-here

Ready to Use!

Your SDK is compatible with:

  • ✅ Node.js applications
  • ✅ Next.js (both Pages and App Router)
  • ✅ Express.js servers
  • ✅ Any JavaScript/TypeScript project