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 🙏

© 2025 – Pkg Stats / Ryan Hefner

joy-api-node

v1.0.4

Published

Node.js client for Joy Loyalty Program REST API v2

Readme

Joy API Node

A TypeScript/Node.js client library for the Joy Loyalty Program REST API v2.

Installation

npm install joy-api-node

Quick Start

import JoyApi from 'joy-api-node';

const joy = new JoyApi({
  appKey: 'your-app-key',
  secretKey: 'your-secret-key',
  baseUrl: 'https://dev-api.joy.so', // optional, defaults to production
  timeout: 30000, // optional, request timeout in ms
  maxRetries: 3 // optional, number of retries for failed requests
});

Usage Examples

Shop Information

// Get shop information
const shop = await joy.shop.whoami();
console.log(shop.data);

Customer Management

// List customers with pagination
const customers = await joy.customers.list({
  limit: 20,
  type: 'member',
  order: 'createdAt_desc'
});

// Get customer by ID
const customer = await joy.customers.get('customer-id');

// Get customer by Shopify ID
const customer = await joy.customers.getByShopifyId('7891234567890');

// Update customer
await joy.customers.update('customer-id', {
  dateOfBirth: '1990-05-15',
  birthday: '05/15'
});

// Update customer tier
await joy.customers.updateTier('customer-id', {
  tierId: 'tier-id',
  triggerReward: true
});

Programs

// Get earning programs
const earningPrograms = await joy.programs.getEarningPrograms();

// Get redemption programs
const redemptionPrograms = await joy.programs.getRedemptionPrograms({
  event: 'amount_discount'
});

// Calculate earning points
const calculation = await joy.programs.calculateEarningPoints({
  products: [
    { id: 'product-1', quantity: 2, price: 50.00 }
  ],
  shopifyCustomerId: '7891234567890'
});

// Redeem points
await joy.programs.redeem({
  programId: 'program-id',
  shopifyCustomerId: '7891234567890',
  quantity: 1
});

Transactions & Points

// List transactions
const transactions = await joy.transactions.list({
  shopifyCustomerId: '7891234567890',
  type: 'earn_point',
  limit: 10
});

// Award points
await joy.transactions.awardPoints({
  shopifyCustomerId: '7891234567890',
  point: 100,
  adminNote: 'Bonus points',
  userNote: 'Thank you for your loyalty!'
});

// Deduct points
await joy.transactions.deductPoints({
  shopifyCustomerId: '7891234567890',
  point: 50,
  reason: 'Point adjustment'
});

// Adjust points (can be positive or negative)
await joy.transactions.adjustPoints({
  shopifyCustomerId: '7891234567890',
  point: -25,
  reason: 'Balance correction'
});

// Reset points
await joy.transactions.resetPoints({
  shopifyCustomerId: '7891234567890',
  point: 0,
  reason: 'Program reset'
});

Rewards

// List customer rewards
const rewards = await joy.rewards.list({
  shopifyCustomerId: '7891234567890',
  status: 'active',
  limit: 10
});

// Get reward details
const reward = await joy.rewards.get('reward-id');

// Refund coupon
await joy.rewards.refundCoupon({
  discountCode: 'JOY-ABC123',
  shopifyCustomerId: '7891234567890',
  reason: 'Customer request'
});

Tiers

// List all tiers
const tiers = await joy.tiers.list();

// Get tier details
const tier = await joy.tiers.get('tier-id');

// Get tier rewards by type
const tierRewards = await joy.tiers.getRewardsByType('discount');

Referrals

// Create referral invitation
const invitation = await joy.referrals.createInvitation({
  email: '[email protected]'
});

// Get referral summary
const summary = await joy.referrals.getSummary('customer-id');

// Get referral analytics
const analytics = await joy.referrals.getAnalytics({
  startDate: '2024-01-01',
  endDate: '2024-12-31'
});

Simple Redemption

// Redeem points for rewards
const redemption = await joy.redemption.redeem({
  programId: 'program-id',
  shopifyCustomerId: '7891234567890',
  redeemPoint: 100
});

Error Handling

import { JoyApiError } from 'joy-api-node';

try {
  const customer = await joy.customers.get('invalid-id');
} catch (error) {
  if (error instanceof JoyApiError) {
    console.error('API Error:', error.message);
    console.error('Status Code:', error.statusCode);
    console.error('Error Code:', error.code);
    console.error('Details:', error.details);
  }
}

Pagination

Most list endpoints support cursor-based pagination:

// First page
const firstPage = await joy.customers.list({ limit: 20 });

// Get next page using the last item's ID
if (firstPage.meta?.pagination?.hasNext) {
  const lastCustomerId = firstPage.data[firstPage.data.length - 1].id;
  const nextPage = await joy.customers.list({ 
    limit: 20, 
    after: lastCustomerId 
  });
}

// Get previous page using the first item's ID
if (firstPage.meta?.pagination?.hasPre) {
  const firstCustomerId = firstPage.data[0].id;
  const prevPage = await joy.customers.list({ 
    limit: 20, 
    before: firstCustomerId 
  });
}

// Include total count (may increase response time)
const withCount = await joy.customers.list({ 
  limit: 20, 
  hasCount: true 
});
console.log('Total customers:', withCount.meta?.pagination?.total);

TypeScript Support

This library is written in TypeScript and provides full type definitions:

import { Customer, Program, Activity, Reward, Tier } from 'joy-api-node';

const processCustomer = (customer: Customer) => {
  console.log(`Customer ${customer.email} has ${customer.point} points`);
};

const processProgram = (program: Program) => {
  if (program.type === 'earning') {
    console.log(`Earn ${program.earnPoint} points`);
  }
};

API Documentation

For detailed API documentation, please refer to the Joy Loyalty Program API Documentation.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

Support

For issues and questions, please open an issue on GitHub.