Description
Users frequently pass incorrect values for subdomains and other connection fields during account connection (e.g., passing https://mycompany.zendesk.com as a subdomain instead of just mycompany). This causes silent failures and broken connections.
This PR adds optional regex and expected_format properties to field definitions, enabling per-field value validation during connection creation with clear, actionable error messages.
Changes:
packages/auth-config/src/base.ts: Added optional regex and expected_format fields to DeprecatedAuthSchemaFieldSchema
apps/apollo/src/lib/toolkits/utils/schema.ts: Propagated regex/expected_format to AuthConfigFieldSchema
apps/apollo/src/lib/auth_config/getSingleAuthConfig.ts: Propagated to ExpectedInputFieldsSchema (returned in API responses for client-side validation)
apps/apollo/src/lib/toolkits/get_toolkits_by_slug.ts: Propagated through connectedAccountInitiation field mapping
apps/apollo/src/lib/connected_accounts/utils/validateConnectedAccount.ts: Added validateFieldValues() function that checks field values against regex patterns during connection creation, with clear error messages including the expected_format hint
apps/apollo/src/common/constants/error.ts: Added InvalidFieldValues error code (623)
How it works:
- Toolkit configs in Mercury can now define
regex and expected_format per field (e.g., regex: "^[a-zA-Z0-9-]+$" for subdomains)
- The API exposes these in
expectedInputFields so SDKs/UI can validate client-side too
- During connection creation,
validateConnectedAccountRequiredFieldsAndPopulateOptionalFields validates field values against regex patterns
- Invalid values return a 400 error with a clear message:
Invalid field values: Subdomain: "https://bad.com" is invalid. Just the subdomain (e.g. 'mycompany'), not the full URL
Backward compatible: Fields without regex continue to work as before (no validation applied).
How did I test this PR
- Added 12 unit tests in
validateConnectedAccount.test.ts — all passing
- Tests cover: regex matching, missing fields, non-string values, legacy field names, multiple errors, invalid regex handling, primary vs legacy name precedence
- Ran existing test suites (
s2s_oauth2_utils.test.ts, validateAuthConfig.test.ts) — all passing, no regressions
- Verified Apollo health and tool listing E2E against running server
Triggered by: Karan Vaidya karan@composio.dev | Source: slack
Session: https://zen-api-production-4c98.up.railway.app/dashboard/#/chat/zen-64b119c91570