( config: HubSpotWebhookConfig, logger?: Logger, requestId?: string )
| 531 | } |
| 532 | |
| 533 | function buildUserFilters( |
| 534 | config: HubSpotWebhookConfig, |
| 535 | logger?: Logger, |
| 536 | requestId?: string |
| 537 | ): FilterClause[] { |
| 538 | const filters: FilterClause[] = [] |
| 539 | |
| 540 | // Shortcut fields translate to common HubSpot filter conditions. |
| 541 | if (config.pipelineId?.trim()) { |
| 542 | const property = config.objectType === 'ticket' ? 'hs_pipeline' : 'pipeline' |
| 543 | filters.push({ propertyName: property, operator: 'EQ', value: config.pipelineId.trim() }) |
| 544 | } |
| 545 | if (config.stageId?.trim()) { |
| 546 | const property = config.objectType === 'ticket' ? 'hs_pipeline_stage' : 'dealstage' |
| 547 | filters.push({ propertyName: property, operator: 'EQ', value: config.stageId.trim() }) |
| 548 | } |
| 549 | if (config.ownerId?.trim()) { |
| 550 | filters.push({ propertyName: 'hubspot_owner_id', operator: 'EQ', value: config.ownerId.trim() }) |
| 551 | } |
| 552 | |
| 553 | const raw = config.filters |
| 554 | if (raw) { |
| 555 | try { |
| 556 | const parsed = typeof raw === 'string' ? JSON.parse(raw) : raw |
| 557 | if (Array.isArray(parsed)) { |
| 558 | for (const entry of parsed) { |
| 559 | if (!entry || typeof entry !== 'object') continue |
| 560 | const propertyName = String((entry as FilterClause).propertyName ?? '').trim() |
| 561 | const operator = String((entry as FilterClause).operator ?? '').trim() |
| 562 | if (!propertyName || !VALID_OPERATORS.has(operator)) continue |
| 563 | const clause: FilterClause = { propertyName, operator } |
| 564 | if (Array.isArray((entry as FilterClause).values)) { |
| 565 | clause.values = (entry as FilterClause).values |
| 566 | } else if ((entry as FilterClause).value !== undefined) { |
| 567 | clause.value = String((entry as FilterClause).value) |
| 568 | } |
| 569 | filters.push(clause) |
| 570 | } |
| 571 | } |
| 572 | } catch (error) { |
| 573 | logger?.warn( |
| 574 | `[${requestId ?? ''}] Could not parse user filters as JSON, ignoring:`, |
| 575 | getErrorMessage(error, 'parse error') |
| 576 | ) |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | return filters |
| 581 | } |
| 582 | |
| 583 | function resolvePropertySnapshot( |
| 584 | config: HubSpotWebhookConfig, |
no test coverage detected