
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
@salla.sa/ecommerce-events-base
Advanced tools
A comprehensive TypeScript package providing type-safe ecommerce event tracking with automatic listener discovery for Salla applications.
npm install @salla.sa/ecommerce-events-base
// vite.config.ts
import { defineConfig } from 'vite';
import { AutoRegistryEventsPlugin } from '@salla.sa/ecommerce-events-base/plugin';
export default defineConfig({
plugins: [
AutoRegistryEventsPlugin()
]
});
Create listeners in your src/listeners/ directory following this pattern:
// src/listeners/product-viewed.ts
import { ProductViewedPayload, EcommerceEvents } from '@salla.sa/ecommerce-events-base';
export const eventName = EcommerceEvents.PRODUCT_VIEWED;
export default (payload: ProductViewedPayload): void => {
console.log('Product viewed:', payload);
// Your custom tracking logic here
// e.g., send to analytics service
};
import {
Product,
Order,
EcommerceEvents,
ProductViewedPayload,
SallaTracker
} from '@salla.sa/ecommerce-events-base';
// Type-safe product definition
const product: Product = {
product_id: '123',
name: 'Sample Product',
price: 29.99,
category: 'Electronics'
};
// Type-safe tracker implementation
const tracker: SallaTracker = {
name: 'my-custom-tracker',
track: (eventName: string, payload: any) => {
console.log(`Tracking ${eventName}:`, payload);
}
};
The AutoRegistryEventsPlugin automatically:
src/listeners/ directorysrc/listeners/ directory for .ts fileseventName and default exportsrc/auto-listeners-registry.ts with all mappings// src/listeners/[event-name].ts
import { [PayloadType], EcommerceEvents } from '@salla.sa/ecommerce-events-base';
// Required: Export the event name
export const eventName = EcommerceEvents.[EVENT_NAME];
// Required: Default export function with typed payload
export default (payload: [PayloadType]): void => {
// Your event handling logic
};
| Interface | Description |
|---|---|
Product | Product information structure |
Cart | Shopping cart structure |
Order | Order information structure |
Checkout | Checkout process structure |
Promotion | Promotion/discount structure |
| Payload Type | Event | Description |
|---|---|---|
ProductViewedPayload | Product Viewed | When a product is viewed |
ProductAddedPayload | Product Added | When a product is added to cart |
CartViewedPayload | Cart Viewed | When cart is viewed |
CheckoutStartedPayload | Checkout Started | When checkout process begins |
OrderCompletedPayload | Order Completed | When an order is completed |
CouponAppliedPayload | Coupon Applied | When a coupon is applied |
WishlistProductAddedPayload | Wishlist Product Added | When product added to wishlist |
| Enum | Description |
|---|---|
EcommerceEvents | All supported event names |
interface SallaTracker {
name: string;
track: (eventName: string, payload: EcommerceEventPayload) => void;
page?: (payload: any) => void;
}
// src/listeners/order-completed.ts
import { OrderCompletedPayload, EcommerceEvents } from '@salla.sa/ecommerce-events-base';
export const eventName = EcommerceEvents.ORDER_COMPLETED;
export default (payload: OrderCompletedPayload): void => {
// Send to analytics
gtag('event', 'purchase', {
transaction_id: payload.order_id,
value: payload.total,
currency: payload.currency,
items: payload.products.map(product => ({
item_id: product.product_id,
item_name: product.name,
category: product.category,
quantity: product.quantity,
price: product.price
}))
});
};
// src/listeners/product-added.ts
import { ProductAddedPayload, EcommerceEvents } from '@salla.sa/ecommerce-events-base';
export const eventName = EcommerceEvents.PRODUCT_ADDED;
export default (payload: ProductAddedPayload): void => {
// Multiple tracking services
// Google Analytics
gtag('event', 'add_to_cart', {
currency: 'SAR',
value: payload.price * (payload.quantity || 1),
items: [{
item_id: payload.product_id,
item_name: payload.name,
category: payload.category,
quantity: payload.quantity || 1,
price: payload.price
}]
});
// Facebook Pixel
fbq('track', 'AddToCart', {
content_ids: [payload.product_id],
content_type: 'product',
value: payload.price,
currency: 'SAR'
});
// Custom API
fetch('/api/track', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
event: 'product_added',
payload
})
});
};
The plugin works with zero configuration, but you can customize its behavior:
// vite.config.ts
import { defineConfig } from 'vite';
import { AutoRegistryEventsPlugin } from '@salla.sa/ecommerce-events-base/plugin';
export default defineConfig({
plugins: [
AutoRegistryEventsPlugin({
// Plugin automatically discovers listeners in src/listeners/
// No configuration needed for standard setups
})
]
});
your-project/
├── src/
│ ├── listeners/ # Event listeners directory
│ │ ├── product-viewed.ts
│ │ ├── cart-viewed.ts
│ │ ├── order-completed.ts
│ │ └── ...
│ ├── auto-listeners-registry.ts # Auto-generated (don't edit)
│ └── index.ts
├── vite.config.ts # Vite configuration
└── package.json
src/listeners/ following the patternEnsure your listeners follow the exact pattern:
src/listeners/ directoryeventName from EcommerceEvents enumMake sure you're importing types correctly:
import { EcommerceEvents, ProductViewedPayload } from '@salla.sa/ecommerce-events-base';
The plugin requires Node.js environment for file system operations. It's automatically excluded from browser builds.
MIT © Salla
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Base types and utilities for Salla ecommerce event tracking
We found that @salla.sa/ecommerce-events-base demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 131 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.