1.0.3 • Published 4 months ago

pink-bears v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

🚀 BackendTemplate

A powerful, flexible OAuth integration framework for seamless third-party API connections

License: MIT Node.js Version

✨ 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 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