HubSpot Integration

Bi-directional CRM sync between Renewa One and HubSpot. The most complex integration in the system — 14 backend service files, 7 database tables, and a full sync engine with mapping layer.

Architecture

LayerLocation
OAuthbackend/src/services/hubspot/auth.ts
Webhook receiverbackend/src/routes/hubspot/webhook.ts
Sync enginebackend/src/services/hubspot/sync-engine/
Mapping systembackend/src/services/hubspot/mapping/
Event handlersbackend/src/services/hubspot/event-handlers/
Main servicebackend/src/services/hubspot/hubspot-sync.service.ts
Admin servicebackend/src/services/hubspot/hubspot-sync-admin.service.ts
Sync queuebackend/src/lib/jobs/hubspot-sync-queue.ts
Frontend adminfrontend/src/pages/admin/HubSpot.tsx

Synced Entities

Renewa OneHubSpot Object
ContactsContacts
CompaniesCompanies
LeadsLeads
QuotesDeals
ProductsLine Items

Sync Engine

Located at backend/src/services/hubspot/sync-engine/:

ModulePurpose
entity-registryRegisters syncable entity types and their configurations
sync-operationsCore sync logic (create, update, delete)
batch-syncBulk sync operations for initial import/export
apply-mappingsApplies property mappings during sync

Mapping System

Located at backend/src/services/hubspot/mapping/:

ModulePurpose
property-mappingMaps Renewa fields to HubSpot properties
enum-mappingMaps enum values between systems
type-inferenceInfers field types for unmapped properties
value-transformerTransforms values during sync (dates, currencies, etc.)
mapping-suggestionAuto-suggests mappings based on field names
mapping-cacheCaches resolved mappings for performance

Database Tables

TablePurpose
hubspotConfigOAuth tokens (encrypted), sync settings
hubspotPropertyMappingsField-to-property mapping definitions
hubspotEnumValueMappingsEnum value translations
hubspotAssociationLabelsHubSpot association label definitions
hubspotAssociationsRecord-level associations
hubspotSyncLogSync operation audit trail
hubspotWebhookLogInbound webhook event log

Security

  • OAuth tokens: Encrypted at rest using ENCRYPTION_MASTER_KEY (AES-256-GCM)
  • Token refresh: Automatic, 5 minutes before expiry
  • Webhook validation: HMAC-SHA256 v3 signatures with 5-minute timestamp window
  • Secrets: HUBSPOT_CLIENT_ID (public), HUBSPOT_CLIENT_SECRET (webhook signature validation)

Background Processing

Sync operations are queued via Background Jobs (BullMQ) at backend/src/lib/jobs/hubspot-sync-queue.ts to avoid blocking API responses during large sync operations.