1.0.1 • Published 4 months ago
mona-gallery-client v1.0.1
Mona Gallery Client Library
A simple and lightweight client library for integrating Mona Gallery functionality into your web applications.
Installation
Using NPM
npm install mona-gallery-client
Using CDN
<script src="https://cdn.jsdelivr.net/npm/mona-gallery-client@1.0.0/mona-client.js"></script>
Usage
Initialize the client
// If using modules
import MonaClient from 'mona-gallery-client';
// Create a new instance
const mona = new MonaClient();
// Optionally configure with custom options
const mona = new MonaClient({
baseUrl: 'https://custom-api-url.com' // Optional: defaults to https://api.mona.gallery
});
Authentication
// Request OTP
const requestResult = await mona.requestOTP('user@example.com');
// Verify OTP
const verifyResult = await mona.verifyOTP('user@example.com', '123456');
// The access token is automatically stored in the client instance
Get User Profile
const profile = await mona.getUserProfile();
Get Assets
// Get community assets
const communityAssets = await mona.getCommunityAssets();
// Get user's assets
const userAssets = await mona.getUserAssets();
Token Management
// Manually set an access token
mona.setAccessToken('your-access-token');
// Get the current access token
const token = mona.getAccessToken();
Error Handling
All methods return promises and can throw errors. It's recommended to use try-catch blocks:
try {
const profile = await mona.getUserProfile();
} catch (error) {
console.error('Error fetching profile:', error);
}
Examples
Complete Authentication Flow
try {
// Request OTP
await mona.requestOTP('user@example.com');
// After user receives OTP via email
const result = await mona.verifyOTP('user@example.com', '123456');
if (result.accessToken) {
// Get user profile
const profile = await mona.getUserProfile();
console.log('Logged in user:', profile);
// Get user's assets
const assets = await mona.getUserAssets();
console.log('User assets:', assets);
}
} catch (error) {
console.error('Error:', error);
}
License
MIT License