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
Subscription & Membership
| Module | Description |
|---|---|
| Subscription | Subscription creation, cancellation, and lifecycle management |
| Plan | Subscription plan information and selection |
| Membership | Membership operations and access control |
Payments
| Module | Description |
|---|---|
| Payment Source | Payment source (legacy card) management |
| Payment Method | Payment method management (cards, wallets) |
| Invoice | Invoice retrieval and payment |
| Coupon | Coupon validation and application |
E-commerce
User Data
| Module | Description |
|---|---|
| Address | User address management |
| Password | Password reset and update |
| Newsletter | Newsletter subscription management |
Analytics & Marketing
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);
}
});Updated 20 days ago
