8.8 KiB
Bulk Read Functionality Refactoring Summary
Overview
The bulk read functionality has been completely refactored to support multiple service providers and services instead of being limited to Zoho only. This refactoring enables the system to handle data from various providers like Zoho, Salesforce, HubSpot, Keka, BambooHR, Intuit/QuickBooks, etc.
Key Changes
1. Database Schema Changes
New Provider-Agnostic Tables
Created new module-specific tables that support multiple providers:
contacts_bulk- Contact data from any provider/serviceleads_bulk- Lead data from any provider/serviceaccounts_bulk- Account data from any provider/servicedeals_bulk- Deal/Opportunity data from any provider/servicetasks_bulk- Task data from any provider/servicevendors_bulk- Vendor data from any provider/serviceinvoices_bulk- Invoice data from any provider/servicesales_orders_bulk- Sales order data from any provider/servicepurchase_orders_bulk- Purchase order data from any provider/serviceemployees_bulk- Employee/HR data from any provider/serviceproducts_bulk- Product/inventory data from any provider/servicecustomers_bulk- Customer data from any provider/service
New Job Tracking Table
bulk_read_jobs- Provider-agnostic job tracking table replacingzoho_bulk_read_jobs
Key Schema Features
- Provider Field: Identifies the service provider (zoho, salesforce, hubspot, etc.)
- Service Field: Identifies the specific service within a provider (crm, books, hr, etc.)
- Optional Fields: Most data fields are now optional/nullable to accommodate varying data structures
- Raw Data Field: JSON field to store original response data
- Enhanced Indexing: Composite indexes on (user_uuid, provider, service) for efficient querying
2. API Endpoint Changes
Updated Routes in bulkReadRoutes.js
Before:
POST /api/v1/bulk-read/initiate
Body: { module, fields, page, limit }
GET /api/v1/bulk-read/data/:module
After:
POST /api/v1/bulk-read/initiate
Body: { provider, service, module, fields, page, limit }
GET /api/v1/bulk-read/data/:provider/:service/:module
GET /api/v1/bulk-read/providers
GET /api/v1/bulk-read/modules/:provider/:service
New Query Parameters
- Added
provider,service,modulefilters for job listing - Enhanced filtering capabilities for multi-provider support
3. Service Layer Refactoring
BulkReadService Updates
Provider Configuration System:
- Configurable provider endpoints and authentication methods
- Support for multiple services per provider
- Provider-specific request formatting
Supported Providers & Services:
{
zoho: { services: ['crm', 'books', 'inventory'] },
salesforce: { services: ['crm'] },
hubspot: { services: ['crm'] },
keka: { services: ['hr'] },
bamboohr: { services: ['hr'] },
intuit: { services: ['accounting'] },
quickbooks: { services: ['accounting'] }
}
Key Methods:
initiateBulkRead(userId, provider, service, module, fields, options)getBulkReadData(userId, provider, service, module, options)getAvailableProviders()- Returns all supported providers/servicesgetAvailableModules(provider, service)- Returns modules for specific provider/service
Provider-Specific Adapters
- Request Formatting: Each provider has custom request structure
- Authentication Headers: Provider-specific auth token handling
- Response Parsing: Custom job ID extraction per provider
4. Repository Layer Changes
New bulkReadRepository.js
Replaces provider-specific repositories with a unified repository that:
- Handles multiple table operations
- Supports provider/service filtering
- Provides bulk data insertion capabilities
- Includes error handling for non-existent tables
Key Methods
createBulkReadJob()- Creates jobs in new schemagetUserData(userId, provider, service, module)- Gets filtered datainsertBulkData(module, data)- Inserts processed webhook data
5. Data Models
New Sequelize Models
Created contactsBulk.js and bulkReadJobs.js models following the new schema structure.
Features
- Provider/service aware models
- JSON field support for raw data
- Comprehensive indexing strategy
- Foreign key relationships maintained
Migration Path
Database Migrations (Files 014-026)
- 014-022: Core module tables (contacts, leads, accounts, deals, tasks, vendors, invoices, sales_orders, purchase_orders)
- 023: New bulk_read_jobs table
- 024-026: Additional provider tables (employees, products, customers)
Backward Compatibility
The refactoring maintains API compatibility for existing Zoho integrations while extending support for new providers.
Provider-Specific Implementation Details
Zoho Integration
- CRM Service: contacts, leads, accounts, deals, tasks, vendors
- Books Service: invoices, sales_orders, purchase_orders, customers, vendors
- Inventory Service: products, customers, vendors, sales_orders, purchase_orders
Salesforce Integration
- CRM Service: contacts, leads, accounts, deals, tasks
- Uses SOQL query format for bulk operations
- Bearer token authentication
HubSpot Integration
- CRM Service: contacts, leads, accounts, deals
- REST API with properties-based queries
- Bearer token authentication
HR Providers (Keka, BambooHR)
- HR Service: employees
- Employee data with comprehensive fields (hire_date, department, salary, etc.)
Accounting Providers (Intuit, QuickBooks)
- Accounting Service: customers, vendors, invoices, products
- Financial data with proper decimal handling
Benefits of Refactoring
- Scalability: Easy to add new providers and services
- Maintainability: Single codebase handles all providers
- Flexibility: Optional fields accommodate varying data structures
- Performance: Optimized indexing for multi-provider queries
- Extensibility: JSON raw_data field preserves original data
- Consistency: Unified API across all providers
Usage Examples
Initiating a Bulk Read Job
// Zoho CRM Contacts
POST /api/v1/bulk-read/initiate
{
"provider": "zoho",
"service": "crm",
"module": "contacts",
"fields": ["first_name", "last_name", "email", "phone"]
}
// Salesforce CRM Leads
POST /api/v1/bulk-read/initiate
{
"provider": "salesforce",
"service": "crm",
"module": "leads",
"fields": ["FirstName", "LastName", "Company", "Email"]
}
// Keka HR Employees
POST /api/v1/bulk-read/initiate
{
"provider": "keka",
"service": "hr",
"module": "employees",
"fields": ["employee_id", "first_name", "last_name", "department"]
}
Retrieving Data
// Get Zoho CRM contacts
GET /api/v1/bulk-read/data/zoho/crm/contacts
// Get Salesforce leads
GET /api/v1/bulk-read/data/salesforce/crm/leads
// Get employee data from Keka
GET /api/v1/bulk-read/data/keka/hr/employees
Discovery Endpoints
// Get all available providers
GET /api/v1/bulk-read/providers
// Get modules for Zoho CRM
GET /api/v1/bulk-read/modules/zoho/crm
// Get modules for Salesforce CRM
GET /api/v1/bulk-read/modules/salesforce/crm
Next Steps
- Run Database Migrations: Execute migrations 014-026 to create new schema
- Update Webhook Handlers: Modify webhook processors to use new repository methods
- Test Provider Integrations: Validate each provider's bulk read functionality
- Update Documentation: Update API documentation with new endpoints
- Monitor Performance: Ensure new indexing strategy performs well with real data
Files Modified/Created
New Migrations
src/db/migrations/014_create_contacts_bulk.sqlsrc/db/migrations/015_create_leads_bulk.sqlsrc/db/migrations/016_create_accounts_bulk.sqlsrc/db/migrations/017_create_deals_bulk.sqlsrc/db/migrations/018_create_tasks_bulk.sqlsrc/db/migrations/019_create_vendors_bulk.sqlsrc/db/migrations/020_create_invoices_bulk.sqlsrc/db/migrations/021_create_sales_orders_bulk.sqlsrc/db/migrations/022_create_purchase_orders_bulk.sqlsrc/db/migrations/023_create_bulk_read_jobs.sqlsrc/db/migrations/024_create_employees_bulk.sqlsrc/db/migrations/025_create_products_bulk.sqlsrc/db/migrations/026_create_customers_bulk.sql
Updated Files
src/api/routes/bulkReadRoutes.js- Updated for multi-provider supportsrc/services/bulkReadService.js- Complete refactoring for provider-agnostic operations
New Files
src/data/repositories/bulkReadRepository.js- Unified repository for all providerssrc/data/models/contactsBulk.js- Example model for new schemasrc/data/models/bulkReadJobs.js- New job tracking model
This refactoring provides a solid foundation for supporting multiple service providers while maintaining clean, maintainable code architecture.