Modules

SDK modules for interacting with Pelcro APIs

Overview

The Pelcro JavaScript SDK exposes modules on the global Pelcro object. Each module provides methods for interacting with specific Pelcro APIs.

// Example: Using the user module
Pelcro.user.login({ email, password }, (err, user) => {
  if (user) {
    console.log('Logged in:', user.email);
  }
});

Core Modules

ModuleDescription
SiteSite configuration and settings
UserUser authentication, registration, and profile management
LocationGeolocation and IP-based location
PaywallPaywall display and content restriction

Subscription & Membership

ModuleDescription
SubscriptionSubscription creation, cancellation, and lifecycle management
PlanSubscription plan information and selection
MembershipMembership operations and access control

Payments

ModuleDescription
Payment SourcePayment source (legacy card) management
Payment MethodPayment method management (cards, wallets)
InvoiceInvoice retrieval and payment
CouponCoupon validation and application

E-commerce

ModuleDescription
EcommerceE-commerce products and cart management
ProductProduct catalog and SKU information
OrderOrder creation and history

User Data

ModuleDescription
AddressUser address management
PasswordPassword reset and update
NewsletterNewsletter subscription management

Analytics & Marketing

ModuleDescription
CampaignCampaign tracking and automation
InsightAnalytics and event tracking

Module Pattern

All modules follow a consistent pattern:

Read Methods

// Synchronous read of cached data
const site = Pelcro.site.read();
const user = Pelcro.user.read();

Action Methods

// Asynchronous actions with callbacks
Pelcro.user.login({ email, password }, (err, user) => {
  if (err) {
    console.error('Login failed:', err.message);
    return;
  }
  console.log('Welcome:', user.first_name);
});

Check Methods

// Boolean checks
if (Pelcro.user.isAuthenticated()) {
  // User is logged in
}

Initialization

Modules are available after the SDK loads. For guaranteed access, wait for boot events:

// Safe to use most modules
document.addEventListener('PelcroSiteLoaded', () => {
  const site = Pelcro.site.read();
  console.log('Site:', site.name);
});

// Safe to use all modules including user data
document.addEventListener('PelcroBootComplete', () => {
  if (Pelcro.user.isAuthenticated()) {
    const user = Pelcro.user.read();
    console.log('User:', user.email);
  }
});