IAV-1045/feat(secondary-credential): add n8nCredentialId field, fix WHATSAPP_OAUTH mapping, and centralise CREDENTIAL_TYPE_MAPPINGS
Summary
This MR introduces three cohesive improvements around secondary credential handling and credential type mapping.
Changes
1. n8nCredentialId on secondary credentials
The AgentIntegrationSecondaryCredential entity and its response DTO (AgentIntegrationSecondaryCredentialResponse) now carry the n8nCredentialId field.
-
"Use existing" mode — the ID is fetched from
core-n8n-serviceviagetCredentialByInstanceUidand persisted alongside the credential instance UID. -
"Create new" mode — the ID is taken directly from the
CredentialResponseDTOreturned by the creation call. - Replication — the ID is copied from the source secondary credential entity.
This removes the need for callers to perform an additional lookup to obtain the N8N-side credential ID.
2. Centralised CREDENTIAL_TYPE_MAPPINGS
CREDENTIAL_TYPE_MAPPINGS was previously duplicated between the two service implementations (one private static final, one inline). It is now declared once as public static final in AgentIntegrationServiceImpl and referenced via a static import in AgentIntegrationSecondaryCredentialServiceImpl.
3. Fix: WHATSAPP_OAUTH N8N type
The mapping for CredentialType.WHATSAPP_OAUTH was pointing to the non-existent N8N type whatsAppOAuthApi. It is corrected to whatsAppTriggerApi, which matches the actual N8N credential type for WhatsApp webhook triggers.
4. MapStruct mapper cleanup
Both toEntity overloads in AgentIntegrationMapper now declare @Mapping(target = "secondaryCredentials", ignore = true), suppressing the unmapped-target warnings that were raised at compile time after the secondaryCredentials collection was added to the entity.
Testing
-
addSecondaryCredential(mode EXISTING) — verifyn8nCredentialIdis populated in response -
addSecondaryCredential(mode CREATE_NEW) — verifyn8nCredentialIdis populated in response -
replicateIntegrationwith secondary credentials — verifyn8nCredentialIdis copied correctly -
Integration with CredentialType.WHATSAPP_OAUTH— verify N8N credential creation useswhatsAppTriggerApi -
Mapper compilation — verify no unmapped-target warnings
Risk
Low. All changes are additive (new field) or corrective (wrong constant, duplicate code, compiler warning). No existing API contracts are broken; the new n8nCredentialId field is nullable and backward-compatible.
## Related Issues
Closes IAV-1045