UNPKG

pink-bears

Version:

Intelligent rate limiting middleware with MongoDB integration and caching for Node.js applications

105 lines (80 loc) 2.66 kB
# 🚀 BackendTemplate > A powerful, flexible OAuth integration framework for seamless third-party API connections [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Node.js Version](https://img.shields.io/badge/node-%3E%3D14.0.0-brightgreen.svg)](https://nodejs.org/) ## ✨ 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 ```bash npm install backend-template ``` ## 🔧 Quick Start ```javascript 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: ```javascript // 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 ```javascript // 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 ```javascript new BackendTemplate( appnestUserId, productId, userId, clientId, clientSecret, redirectUri, IntegrationName ) ``` ### Methods - `makeRequest({ method, endPoint, queryString, payload, apiKey })` - Make authenticated API requests - `getUser()` - Get the current user information - `checkHasFeature(featureName)` - Check if a feature is available - `exchangeAuthCode(code)` - Exchange authorization code for access tokens - `setStorageV2({ key, data })` - Store data in persistent storage - `getStorageV2({ key })` - Retrieve data from persistent storage ## 📄 License MIT © [Your Organization]