1.0.3 • Published 4 months ago
pink-bears v1.0.3
🚀 BackendTemplate
A powerful, flexible OAuth integration framework for seamless third-party API connections
✨ Features
- OAuth 2.0 Integration - Seamless authentication flow with automatic token refresh
- Intelligent Request Handling - Robust error handling and request retries
- Persistent Storage - Built-in storage management for tokens and user data
- Feature Verification - Easy verification of available features for users
- Comprehensive Logging - Detailed logging for debugging and monitoring
📦 Installation
npm install backend-template
🔧 Quick Start
const BackendTemplate = require('backend-template');
// Initialize with your credentials
const integration = new BackendTemplate(
'appnestUserId',
'productId',
'userId',
'clientId',
'clientSecret',
'https://your-redirect-uri.com/callback',
'YourIntegrationName'
);
// Make authenticated API requests
async function getUser() {
try {
const user = await integration.getUser();
console.log('User data:', user);
} catch (error) {
console.error('Error fetching user:', error);
}
}
🔑 Authentication
The BackendTemplate handles the complete OAuth 2.0 flow:
// Exchange authorization code for tokens
const authResponse = await integration.exchangeAuthCode('authorization_code');
// Tokens are automatically refreshed when expired
const data = await integration.makeRequest({
method: 'GET',
endPoint: '/v3/users',
});
💾 Storage Management
// Store data
await integration.setStorageV2({
key: 'userData',
data: { name: 'John Doe', email: 'john@example.com' }
});
// Retrieve data
const userData = await integration.getStorageV2({ key: 'userData' });
🛠️ API Reference
Constructor
new BackendTemplate(
appnestUserId,
productId,
userId,
clientId,
clientSecret,
redirectUri,
IntegrationName
)
Methods
makeRequest({ method, endPoint, queryString, payload, apiKey })
- Make authenticated API requestsgetUser()
- Get the current user informationcheckHasFeature(featureName)
- Check if a feature is availableexchangeAuthCode(code)
- Exchange authorization code for access tokenssetStorageV2({ key, data })
- Store data in persistent storagegetStorageV2({ key })
- Retrieve data from persistent storage
📄 License
MIT © Your Organization