Skip to content

chebacca/shared-firebase-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ BACKBONE v14.2 Shared Firebase Functions

Complete Firebase Functions implementation for all BACKBONE projects - 100% extraction from monolith

πŸ“Š COMPLETION STATUS: 100% βœ…

All Firebase functions have been successfully extracted from the main Dashboard monolith and organized into a modular, reusable structure.

πŸš€ Quick Start

# Install dependencies
npm install

# Build TypeScript
npm run build

# Deploy all functions
npm run deploy

# Or use the deployment script
./deploy.sh

πŸ“‹ Function Categories (80+ Total Functions - Hybrid Support)

πŸ”₯ HYBRID CALLING SUPPORT: All functions support both Firebase Callable (onCall) and HTTP (onRequest) calling methods for maximum flexibility!

πŸ” Authentication (16 functions - 8 pairs)

  • loginUser / loginUserHttp - User login with Firebase Auth
  • registerUser / registerUserHttp - User registration with validation
  • verifyEmail / verifyEmailHttp - Email verification
  • resendVerificationEmail / resendVerificationEmailHttp - Resend verification emails
  • forgotPassword / forgotPasswordHttp - Password reset initiation
  • resetPassword / resetPasswordHttp - Password reset completion
  • checkEmailAvailability / checkEmailAvailabilityHttp - Email availability check
  • validateSession / validateSessionHttp - Session validation

πŸ“ Project Management (7 functions)

  • createProject - Create new projects
  • listProjects - List projects with filtering
  • updateProject - Update project details
  • deleteProject - Delete projects
  • assignDatasetToProject - Assign datasets to projects
  • removeDatasetFromProject - Remove datasets from projects
  • getProjectDatasets - Get project datasets

πŸ“Š Dataset Management (4 functions)

  • createDataset - Create new datasets
  • listDatasets - List datasets with filtering
  • updateDataset - Update dataset details
  • deleteDataset - Delete datasets

🎬 Session Management (4 functions)

  • createSession - Create new sessions
  • listSessions - List sessions with filtering
  • updateSession - Update session details
  • deleteSession - Delete sessions

🎫 Licensing (4 functions)

  • createLicense - Create new licenses
  • listLicenses - List licenses with filtering
  • updateLicense - Update license details
  • deleteLicense - Delete licenses

πŸ’³ Payments (3 functions)

  • createPayment - Create payment records
  • listPayments - List payments with filtering
  • updatePayment - Update payment details

πŸ—„οΈ Database Management (4 functions)

  • createCollection - Create Firestore collections
  • createFirestoreIndexes - Create database indexes
  • updateSecurityRules - Update security rules
  • listCollections - List all collections

βš™οΈ System Operations (4 functions)

  • healthCheck - System health monitoring
  • initializeDatabase - Database initialization
  • migrateData - Data migration utilities
  • cleanupData - Data cleanup utilities

πŸ€– AI Processing (3 functions)

  • processDeliverableDocumentEnhanced - AI document processing
  • verifyDeliverableAccuracy - AI accuracy verification
  • generateWorkflowFromDeliverables - AI workflow generation

πŸ‘₯ Team Management (6 functions)

  • teamMemberAuth - Team member authentication
  • getProjectTeamMembers - Get project team members
  • getLicensedTeamMembers - Get licensed team members
  • addTeamMemberToProject - Add team member to project
  • removeTeamMemberFromProject - Remove team member from project
  • getAvailableProjectRoles - Get available project roles

πŸ“‹ Call Sheet Functions (12 functions - 6 pairs)

  • publishCallSheet / publishCallSheetHttp - Publish call sheet for public access
  • disablePublishedCallSheet / disablePublishedCallSheetHttp - Disable published call sheet
  • getPublishedCallSheet / getPublishedCallSheetHttp - Get published call sheet by public ID
  • authenticateTeamMember / authenticateTeamMemberHttp - Authenticate team member for call sheet access
  • getPublishedCallSheets / getPublishedCallSheetsHttp - Get all published call sheets
  • cleanupExpiredCallSheets / cleanupExpiredCallSheetsHttp - Cleanup expired call sheets

⏰ Timecard Functions (4 functions - 2 pairs)

  • getTimecardTemplates / getTimecardTemplatesHttp - Get timecard templates
  • createTimecardTemplate / createTimecardTemplateHttp - Create timecard template

πŸ› Debug & Utilities (1 function)

  • debugRoleConversion - Debug role conversion

🌐 Main API Router (1 function)

  • api - Central Express router for all endpoints

πŸ—οΈ Architecture

Modular Structure

src/
β”œβ”€β”€ auth/           # Authentication functions
β”œβ”€β”€ projects/       # Project management
β”œβ”€β”€ datasets/       # Dataset management
β”œβ”€β”€ sessions/       # Session management
β”œβ”€β”€ licensing/      # License management
β”œβ”€β”€ payments/       # Payment processing
β”œβ”€β”€ database/       # Database operations
β”œβ”€β”€ system/         # System operations
β”œβ”€β”€ ai/            # AI processing
β”œβ”€β”€ team/          # Team management
β”œβ”€β”€ debug/         # Debug utilities
β”œβ”€β”€ api/           # Main API router
└── shared/        # Shared utilities and types

Shared Utilities

  • Types: Comprehensive TypeScript interfaces
  • Middleware: Authentication and validation middleware
  • Utils: Common utility functions
  • Constants: Application constants

πŸ”₯ Hybrid Calling Methods

Firebase Callable Functions (onCall)

// Client-side usage
import { getFunctions, httpsCallable } from 'firebase/functions';

const functions = getFunctions();
const publishCallSheet = httpsCallable(functions, 'publishCallSheet');

const result = await publishCallSheet({
  callSheetId: 'call-sheet-123',
  organizationId: 'org-123',
  userId: 'user-123'
});

HTTP Functions (onRequest)

// Client-side usage
const response = await fetch('https://us-central1-backbone-logic.cloudfunctions.net/publishCallSheetHttp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    callSheetId: 'call-sheet-123',
    organizationId: 'org-123',
    userId: 'user-123'
  })
});

const result = await response.json();

Benefits of Hybrid Approach

  • βœ… Firebase Callable: Automatic authentication, type safety, error handling
  • βœ… HTTP Functions: Standard REST API, works with any HTTP client
  • βœ… Flexibility: Choose the best method for each use case
  • βœ… Compatibility: Works with web, mobile, and server applications
  • βœ… Consistency: Same functionality, different calling methods

πŸ”§ Configuration

Environment Variables

# Required
GEMINI_API_KEY=your_gemini_api_key
ENCRYPTION_KEY=your_32_byte_encryption_key  # For Slack/OAuth token encryption

# Video Transcript APIs (for extractTranscript function)
YOUTUBE_API_KEY=your_youtube_data_api_v3_key  # Required for YouTube transcripts
VIMEO_ACCESS_TOKEN=your_vimeo_api_access_token  # Optional, for Vimeo transcripts

# Optional
NODE_ENV=production
FIREBASE_PROJECT_ID=backbone-logic

Video Transcript API Setup

For transcript extraction functionality, see the detailed setup guide:

Setting Up Encryption Key for Slack Integration

The Slack integration requires an encryption key to securely store Slack access tokens.

Generate a secure encryption key:

# Generate a 32-byte hex key
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

Set the encryption key in Firebase Functions:

# For Firebase Functions v2 (recommended)
firebase functions:secrets:set ENCRYPTION_KEY

# Or for legacy config
firebase functions:config:set integrations.encryption_key="YOUR_HEX_KEY_HERE"

Security Note: This key is critical for protecting Slack tokens. Never commit it to version control or expose it in logs.

Firebase Configuration

  • Project: backbone-logic
  • Region: us-central1
  • Memory: 256MiB - 2GiB (function dependent)
  • Timeout: 30s - 300s (function dependent)

πŸš€ Deployment

Deploy All Functions

npm run deploy

Deploy by Category

npm run deploy:auth      # Authentication functions
npm run deploy:projects  # Project management
npm run deploy:datasets  # Dataset management
npm run deploy:sessions  # Session management
npm run deploy:licensing # License management
npm run deploy:payments  # Payment processing
npm run deploy:database  # Database operations
npm run deploy:system    # System operations
npm run deploy:ai        # AI processing
npm run deploy:team      # Team management
npm run deploy:debug     # Debug utilities
npm run deploy:api       # Main API router

🌐 API Endpoints

Base URL

https://us-central1-backbone-logic.cloudfunctions.net/api

Health Check

GET /api/health

API Documentation

GET /api/docs

Example Usage

// Authentication
const response = await fetch('https://us-central1-backbone-logic.cloudfunctions.net/api/auth/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email, password })
});

// Projects
const projects = await fetch('https://us-central1-backbone-logic.cloudfunctions.net/api/projects', {
  headers: { 'Authorization': `Bearer ${token}` }
});

πŸ”’ Security

Authentication

  • Firebase Auth token verification
  • Organization-based access control
  • Role-based permissions
  • Project-specific access

Validation

  • Input sanitization
  • Required field validation
  • Type checking
  • Error handling

πŸ“Š Monitoring

Health Monitoring

  • System health checks
  • Service status monitoring
  • Performance metrics
  • Error tracking

Logging

  • Structured logging
  • Error tracking
  • Performance monitoring
  • Debug information

πŸ§ͺ Testing

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Lint code
npm run lint

# Fix linting issues
npm run lint:fix

πŸ“ˆ Performance

Optimizations

  • Memory-optimized functions
  • Efficient database queries
  • Caching strategies
  • Batch operations

Scaling

  • Auto-scaling based on demand
  • Regional deployment
  • Load balancing
  • Resource optimization

πŸ”„ Migration from Monolith

Before (Monolith)

  • Single 36,000+ line file
  • All functions in one place
  • Difficult to maintain
  • No modularity

After (Modular)

  • 47 individual functions
  • Organized by category
  • Easy to maintain
  • Reusable across projects

🎯 Project Integration

Dashboard v14.2

  • Replace monolithic functions
  • Use shared function imports
  • Maintain existing API contracts

Licensing Website

  • Integrate with shared functions
  • Unified authentication
  • Consistent data access

Standalone Apps

  • Use shared functions for backend
  • Consistent API patterns
  • Unified error handling

πŸ“š Documentation

  • API Docs: /api/docs
  • Health Check: /api/health
  • Function List: See function categories above
  • Usage Examples: See API endpoints section

πŸ†˜ Support

Common Issues

  1. Build Errors: Run npm run build to check TypeScript compilation
  2. Deploy Errors: Check Firebase project configuration
  3. Runtime Errors: Check function logs in Firebase Console
  4. Permission Errors: Verify authentication and organization access

Debug Tools

  • debugRoleConversion - Debug role mapping
  • Health check endpoint
  • Function logs in Firebase Console
  • API documentation endpoint

πŸŽ‰ Success Metrics

  • βœ… 100% Function Extraction: All 47 functions extracted from monolith
  • βœ… Modular Architecture: Organized by functional categories
  • βœ… Type Safety: Full TypeScript implementation
  • βœ… Error Handling: Comprehensive error management
  • βœ… Documentation: Complete API documentation
  • βœ… Testing: Test framework ready
  • βœ… Deployment: Automated deployment scripts
  • βœ… Monitoring: Health check and logging
  • βœ… Security: Authentication and validation
  • βœ… Performance: Optimized for production

πŸš€ Next Steps

  1. Deploy Functions: Run ./deploy.sh to deploy all functions
  2. Update Projects: Integrate shared functions into all projects
  3. Test Integration: Verify all projects work with shared functions
  4. Monitor Performance: Use health check and logging
  5. Scale as Needed: Functions auto-scale based on demand

🎯 MISSION ACCOMPLISHED: 100% Firebase Functions Extraction Complete!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published