maker-ramp-edge
v2.0.9
Published
Client library for fetching product groups from API
Downloads
50
Readme
Maker.RampEdge
Maker.RampEdge is a comprehensive client library for interacting with the Maker Platform API. It provides a seamless interface for managing product groups, user authentication, shopping carts, and e-commerce operations. The library handles all the complexity of API communication, token management, and error handling, allowing developers to focus on building their applications.
Features
Robust Authentication
- Token-based authentication system
- Automatic token refresh handling
- Secure token storage management
- SSO integration support
E-commerce Integration
- Shopping cart management
- Product catalog access
- Order processing
- Stripe payment integration
- Address management
Developer Experience
- Automatic error handling
- Type-safe API interfaces
- Comprehensive documentation
- Easy-to-use API methods
- Built-in retry mechanisms
- Request/Response interceptors
Performance & Security
- Efficient request caching
- Automatic token renewal
- Secure credential handling
- Rate limiting protection
- Connection pooling
Available methods (summary)
Authentication Methods
registerUser(email, password)- Register a new userlogin(username, password)- Login and get authentication tokensrefreshToken()- Refresh an expired access tokenrequestSsoCode()- Request SSO authentication code
Authorized Methods (Requires Authentication)
getAllOrders(page, pageSize)- Get user's order historygetUser(userDetail)- Get user profile informationgetCart()- Get user's shopping cartclearCart()- Clear user's shopping cartgetAddress()- Get user's saved addressesupsertAddress(request)- Create or update user's addressaddProductsToCart(cartItems)- Add items to cartremoveProductFromCart(slug)- Remove item from cartcreateCheckoutSession(request)- Create Stripe checkout sessionaddProductReport(request)- Submit a product reportupdateProductReport(request)- Update an existing reportaddRating(request)- Add product ratinginsertUserActivity(request)- Track user activitysendStripeWebhook(payloadJson, signature)- Process Stripe webhook (testing helper)
Public Methods (No Authentication Required)
getProductGroups()- Get all product groupsgetProductsBySlug(slug)- Get product by sluggetProductDetails(request)- Get detailed product informationgetReportByProduct(barID)- Get product reportsgetRatingByProduct({ barID })- Get product ratingsgetAboutInfo()- Get about page informationgetBlogs()- Get blog postsgetDocumentation()- Get documentationgetServices()- Get available services
Installation
npm install
Install the main package:
npm install maker-ramp-edgenpm install dotenvRequired peer dependencies:
npm install axiosConfigure Environment Variables
Create a .env file at the root of your project:
BUSINESS_UNIT_KEY=your_business_unit_key
API_BASE_URL=https://your.api.base.urlNote: All methods return a promise which resolves to the API response (or throws an error via the client's error handler). For authorized methods, the client automatically handles token management - you don't need to pass tokens manually.
Add this to the top of your index.js to load .env variables:
import dotenv from 'dotenv';
dotenv.config();Basic Usage
Initializing the Client
The ProductGroupClient requires two parameters: businessUnitKey and apiBaseUrl.
import { ProductGroupClient } from 'maker-ramp-edge';
const client = new ProductGroupClient(
"YOUR_BUSINESS_UNIT_KEY",
"https://your-api-base-url.com"
);Authentication and Protected Endpoints Example
import { ProductGroupClient } from 'maker-ramp-edge';
async function example() {
// Initialize the client
const client = new ProductGroupClient(
'your-business-unit-key',
'https://your-api-base-url.com'
);
try {
// Login to get authentication tokens
await client.login('[email protected]', 'your-password');
// After successful login, tokens are automatically stored
// Now you can call any protected endpoint
// Example: Get user's cart
const cart = await client.getCart();
console.log('Cart contents:', cart);
// The client will automatically:
// - Use the stored token for authentication
// - Refresh the token if it expires
// - Handle unauthorized errors
} catch (error) {
console.error('Error:', error.message);
}
}Example in React Component
import { ProductGroupClient } from 'maker-ramp-edge';
// Create a new instance with your business unit key
const client = new ProductGroupClient(
'your-business-unit-key',
'https://your-api-base-url.com'
);
// Example usage in a React component
function ProductList() {
const [products, setProducts] = useState([]);
const [error, setError] = useState(null);
useEffect(() => {
async function fetchProducts() {
try {
const data = await client.getProductGroups();
setProducts(data.products);
} catch (err) {
setError(err.message);
}
}
fetchProducts();
}, []);
if (error) return <div>Error: {error}</div>;
if (!products) return <div>Loading...</div>;
return (
<div>
{products.map(product => (
<div key={product.slug}>
<h2>{product.name}</h2>
<p>ID: {product.friendlyID}</p>
{product.asset && <img src={product.asset.url} alt={product.name} />}
</div>
))}
</div>
);
}Project Structure
Node.js Client (maker-ramp-edge)
Maker.RampEdge/
├── src/
│ ├── index.js # Main client implementation
│ └── tokenStorage.js # Token management implementation
├── bin/
│ └── print-products.js # CLI utilities
├── dist/ # Compiled output
│ ├── index.js
│ └── index.js.map
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
├── .babelrc # Babel configuration
└── .env # Environment variables