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

iap-apple

v3.0.4

Published

Integration with Apples InAppPurchases in Typescript, available for NodeJS environments.

Readme

| Statements | Branches | Functions | Lines | | --------------------------- | ----------------------- | ------------------------- | ----------------- | | Statements | Branches | Functions | Lines |

iap-apple

npm version npm downloads GitHub issues License: ISC

Lightweight Apple App Store receipt validation for Node.js - Zero dependencies, TypeScript-first, blazing fast.

Why iap-apple? 🤔

| Feature | iap-apple | Others | |---------|-----------|--------| | Runtime Dependencies | 0 | 5-10+ | | TypeScript | Native | Partial/None | | Bundle Size | ~15KB | 100KB+ | | Node.js Fetch | Native | axios/request | | Maintained | 2024+ | Often stale |

  • Zero Dependencies - Uses Node.js native fetch, no bloat
  • TypeScript-First - Full type definitions, great IDE support
  • Production Ready - 93%+ test coverage, battle-tested
  • Simple API - One function to validate, intuitive helpers

Installation 📦

# pnpm (recommended)
pnpm add iap-apple

# npm
npm install iap-apple

# yarn
yarn add iap-apple

Requirements: Node.js 22+

Quick Start 🚀

import { verify, getPurchasedItems, isPurchasedItemExpired } from 'iap-apple';

// Validate a receipt
const response = await verify(receiptData, {
  appSharedSecret: 'your-shared-secret',
});

// Get purchased items (sorted by date, deduplicated)
const items = getPurchasedItems(response);

// Check subscription status
const latestPurchase = items[0];
if (!isPurchasedItemExpired(latestPurchase)) {
  console.log('Subscription is active!');
}

API Reference 📚

verify(receipt, config)

Validates a receipt against Apple's verifyReceipt endpoint. Automatically handles production/sandbox fallback.

import { verify, IAPAppleError } from 'iap-apple';

try {
  const response = await verify(receiptData, {
    // Required: Your app's shared secret from App Store Connect
    appSharedSecret: 'your-shared-secret',

    // Optional: Exclude old transactions (default: false)
    appleExcludeOldTransactions: true,

    // Optional: Force sandbox environment (default: false)
    test: false,

    // Optional: Debug logging
    logger: console,
  });

  console.log('Receipt validated:', response.status === 0);
} catch (error) {
  const { rejectionMessage, data } = error as IAPAppleError;
  console.error('Validation failed:', rejectionMessage);
}

isVerifiedReceipt(response)

Check if a receipt validation was successful.

import { verify, isVerifiedReceipt } from 'iap-apple';

const response = await verify(receipt, config);
if (isVerifiedReceipt(response)) {
  // Receipt is valid
}

getPurchasedItems(response)

Extract purchased items from the response. Returns items sorted by purchase date (newest first), deduplicated by original_transaction_id.

import { verify, getPurchasedItems } from 'iap-apple';

const response = await verify(receipt, config);
const items = getPurchasedItems(response);

for (const item of items) {
  console.log(`Product: ${item.productId}`);
  console.log(`Purchased: ${new Date(item.purchaseDateMS)}`);
  console.log(`Expires: ${item.expirationDateMS ? new Date(item.expirationDateMS) : 'Never'}`);
}

isPurchasedItemExpired(item)

Check if a subscription has expired or been cancelled.

import { getPurchasedItems, isPurchasedItemExpired } from 'iap-apple';

const items = getPurchasedItems(response);
const subscription = items[0];

if (isPurchasedItemExpired(subscription)) {
  console.log('Subscription expired or cancelled');
} else {
  console.log('Subscription is active');
}

isPurchasedItemCanceled(item)

Check if a purchase was cancelled (refunded).

import { getPurchasedItems, isPurchasedItemCanceled } from 'iap-apple';

const items = getPurchasedItems(response);
if (isPurchasedItemCanceled(items[0])) {
  console.log('User received a refund');
}

Types 📝

PurchasedItem

interface PurchasedItem {
  bundleId: string;
  appItemId: string;
  transactionId: string;
  originalTransactionId?: string;
  productId: string;
  purchaseDateMS: number;
  originalPurchaseDateMS?: number;
  expirationDateMS?: number;
  cancellationDateMS?: number;
  isTrialPeriod: boolean;
  quantity: number;
}

IIAPAppleConfig

interface IIAPAppleConfig {
  appSharedSecret: string;           // Required
  appleExcludeOldTransactions?: boolean;  // Default: false
  test?: boolean;                    // Default: false
  logger?: ILogger | null;           // Default: null
}

Error Handling

All errors are thrown as IAPAppleError:

interface IAPAppleError {
  rejectionMessage: string;
  data?: IVerifyReceiptResponseBody | null;
}

Common status codes:

  • 21002 - Malformed receipt data
  • 21003 - Receipt authentication failed
  • 21004 - Shared secret mismatch
  • 21005 - Apple server unavailable
  • 21006 - Subscription expired
  • 21007 - Sandbox receipt sent to production
  • 21008 - Production receipt sent to sandbox

StoreKit 2 / App Store Server API 🆕

This library uses Apple's legacy verifyReceipt endpoint, which still works but is deprecated for new apps.

For new projects using StoreKit 2, consider Apple's official library:

npm install @apple/app-store-server-library

When to use iap-apple:

  • Existing apps using StoreKit 1
  • Need zero dependencies
  • Want a simpler API
  • Validating receipts from older iOS versions

When to use Apple's library:

  • New apps with StoreKit 2
  • Need App Store Server Notifications V2
  • Need subscription offer signing

Contributing 🤝

Contributions are welcome! Please open an issue or submit a PR.

License 📄

ISC