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

@stepanjakl/apostrophe-stripe-products

v0.0.8

Published

Stripe Products For ApostropheCMS

Downloads

20

Readme

This module adds a piece module and utility operation to automatically synchronize Stripe Products with the database. Saved products can be easily accessed and viewed via the admin UI alongside other piece methods and features, including the built-in REST API.

Installation

Use your preferred package manager to install the module. You'll also need to install the read-only-field package alongside it:

npm install stripe-products@npm:@stepanjakl/apostrophe-stripe-products

npm install read-only-field@npm:@stepanjakl/apostrophe-read-only-field

Examples

It is highly recommended to explore the apostrophe-stripe-examples repository, which offers a comprehensive set of examples and full configurations demonstrating how to set up a complete e-commerce store experience.

Usage

First, add installed modules to your configuration in the app.js root file:

require('apostrophe')({
    shortName: 'project-name',
    modules: {
        // Custom fields
        'read-only-field': {},

        // Stripe Products
        'stripe-products': {},
        'stripe-products/product': {}
    }
});

Then, set global variables inside the .env file. It's important to set the STRIPE_TEST_MODE variable to anything other than false to enable test mode.

PORT='4000'
APOS_BASE_URL='http://localhost:4000'
APOS_RELEASE_ID='a4-boilerplate'
APOS_MONGODB_URI='mongodb://localhost:27017/a4-boilerplate'

STRIPE_KEY='sk_test_xyz'
STRIPE_TEST_MODE='false'
STRIPE_DASHBOARD_BASE_URL='https://dashboard.stripe.com'

Recommended use

This module is utilized to primarily mirror datasets fetched from the connected Stripe account. To enhance the front-end with additional custom data, it is recommended to create a separate piece type and link it to the Stripe product piece using a relationship schema field type. This enables the addition of extra schema fields for images, supporting documents, and other necessary data while keeping it decoupled from Stripe's data, which may change during synchronization.

module.exports = {
  extend: 'apostrophe-pieces',
  name: 'product',
  fields: {
    add: {
      _stripeProduct: {
        label: 'Stripe Product',
        type: 'relationship',
        withType: 'stripe-products/product',
        max: 1
      },
      _images: {
        label: 'Images',
        type: 'relationship',
        withType: '@apostrophecms/image'
      },
      _documents: {
        label: 'Documents',
        type: 'relationship',
        withType: '@apostrophecms/file'
      }
    }
  }
}

API Routes

'/api/v1/stripe-products/synchronize':

This API route is triggered by the Synchronize Products utility operation and handled via the '@apostrophecms/job' module. Upon execution, it compares the existing data with the received data and records the differences in the results object within the aposJobs collection document. Access to this endpoint is restricted to authenticated users with appropriate permissions.

'/api/v1/stripe-products/product':

Apostrophe provides a pre-configured REST endpoint to retrieve a list of all available products. Below is an example of how to use the Fetch API with error handling directly in the browser:

try {
  const response = await fetch('/api/v1/stripe-products/product');
  if (!response.ok) {
    throw new Error('Failed to fetch products');
  }
  const { results: products } = await response.json();

  products.forEach(product => {
    console.log('Product Name:', product.stripeProductObject.name);
  });

} catch (error) {
  console.error('Error fetching products:', error);
}

Unit Tests

To run tests locally, you'll need to set up the stripe/stripe-mock package:

brew install stripe/stripe-mock/stripe-mock

brew services start stripe-mock

Once set up, run tests using npm run tests to validate any changes before deploying them.

TODOs (Improvements)

  • fix disappering stripeProductObject and stripePriceObject data when moved between draft and published modes and vice versa
  • optional product piece type REST API or configurable schema fields
  • automatic synchronization on product catalog changes with global schema field to enable
  • two-way synchronization between ApostropheCMS and Stripe