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

@3halves-labs/score-loyalty-sdk

v1.0.2

Published

Official SDK for integrating with Score Anything Loyalty platform - manage points, challenges, rewards, and leaderboards

Readme

Score Anything Loyalty SDK

Official SDK for integrating with the Score Anything Loyalty platform. Manage points, challenges, rewards, leaderboards, and user profiles with ease.

Features

  • 🎯 Points Management - Award, deduct, and track loyalty points (Karma)
  • 🏆 Challenges - Create and manage user challenges with progress tracking
  • 🎁 Rewards - Handle reward catalog and redemption
  • 📊 Leaderboards - Query rankings and user positions
  • 👤 User Profiles - Manage user data and achievements
  • ⚛️ React Support - First-class React integration with hooks
  • 📘 TypeScript - Full TypeScript support with type definitions
  • 🔄 React Query - Built-in caching and state management

Installation

npm install @3halves-labs/score-loyalty-sdk

For React integration, you'll also need React Query:

npm install @tanstack/react-query

Quick Start

Basic Usage (JavaScript/TypeScript)

import { LoyaltyClient } from '@3halves-labs/score-loyalty-sdk';

// Initialize the client
const client = new LoyaltyClient({
  apiUrl: 'https://your-loyalty-api.com',
  apiKey: 'your-api-key',
  userId: 'user-123'
});

// Award points
await client.awardPoints(100, 'Completed first game');

// Get challenges
const challenges = await client.getChallenges({ status: 'active' });

// Redeem a reward
await client.redeemReward('reward-id');

React Integration

import { LoyaltyProvider, usePoints, useChallenges } from '@3halves-labs/score-loyalty-sdk/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const queryClient = new QueryClient();

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <LoyaltyProvider config={{
        apiUrl: 'https://your-api.com',
        apiKey: 'your-key',
        userId: 'user-123'
      }}>
        <Dashboard />
      </LoyaltyProvider>
    </QueryClientProvider>
  );
}

function Dashboard() {
  const { data: points, isLoading } = usePoints();
  const { data: challenges } = useChallenges({ status: 'active' });

  if (isLoading) return <div>Loading...</div>;

  return (
    <div>
      <h1>You have {points} points!</h1>
      <ChallengeList challenges={challenges?.data || []} />
    </div>
  );
}

Core API

Points

// Get current points
const points = await client.getPoints();

// Award points
await client.awardPoints(100, 'Challenge completed');

// Deduct points
await client.deductPoints(50, 'Reward redeemed');

// Get transaction history
const history = await client.getPointsHistory();

Challenges

// Get all challenges
const challenges = await client.getChallenges();

// Filter challenges
const activeChallenges = await client.getChallenges({
  status: 'active',
  type: 'daily'
});

// Get challenge progress
const progress = await client.getChallengeProgress('challenge-id');

// Complete a challenge
const completion = await client.completeChallenge('challenge-id', {
  score: 100
});

Rewards

// Get all rewards
const rewards = await client.getRewards();

// Filter rewards
const availableRewards = await client.getRewards({
  available: true,
  maxCost: 500
});

// Redeem a reward
const redemption = await client.redeemReward('reward-id');

// Get redemption history
const history = await client.getRedemptionHistory();

Leaderboard

// Get leaderboard
const leaderboard = await client.getLeaderboard({
  period: 'weekly',
  limit: 100
});

// Get user's rank
const rank = await client.getUserRank();

User Profile

// Get profile
const profile = await client.getProfile();

// Update profile
await client.updateProfile({
  userName: 'NewName',
  avatar: 'https://...'
});

// Get achievements
const achievements = await client.getAchievements();

React Hooks

All hooks support React Query options for caching, refetching, and more.

Points Hooks

const { data: points } = usePoints();
const { data: history } = usePointsHistory();
const { mutate: awardPoints } = useAwardPoints();

// Award points
awardPoints({ amount: 100, reason: 'Game completed' });

Challenge Hooks

const { data: challenges } = useChallenges({ status: 'active' });
const { data: challenge } = useChallenge('challenge-id');
const { data: progress } = useChallengeProgress('challenge-id');
const { mutate: complete } = useCompleteChallenge();

// Complete challenge
complete({ challengeId: 'challenge-id', data: { score: 100 } });

Reward Hooks

const { data: rewards } = useRewards({ available: true });
const { data: reward } = useReward('reward-id');
const { mutate: redeem } = useRedeemReward();

// Redeem reward
redeem({ rewardId: 'reward-id' });

Leaderboard Hooks

const { data: leaderboard } = useLeaderboard({ period: 'weekly' });
const { data: rank } = useUserRank();

Profile Hooks

const { data: profile } = useProfile();
const { mutate: updateProfile } = useUpdateProfile();

// Update profile
updateProfile({ updates: { userName: 'NewName' } });

TypeScript Support

The SDK is written in TypeScript and provides full type definitions:

import type {
  Challenge,
  Reward,
  UserProfile,
  LeaderboardEntry,
  PointTransaction
} from '@3halves-labs/score-loyalty-sdk';

const challenge: Challenge = {
  id: '123',
  name: 'Daily Login',
  type: 'daily',
  status: 'active',
  points: 10,
  // ... TypeScript will validate the structure
};

Error Handling

try {
  await client.awardPoints(100, 'Completed task');
} catch (error) {
  if (error instanceof Error) {
    console.error('Failed to award points:', error.message);
  }
}

With React hooks:

const { mutate, error, isError } = useAwardPoints({
  onError: (error) => {
    console.error('Award failed:', error.message);
  }
});

if (isError) {
  return <div>Error: {error.message}</div>;
}

Documentation

License

MIT © 3 Halves Labs

Support