Skip to content

Conversation

@kaposke
Copy link
Contributor

@kaposke kaposke commented Jan 6, 2026

Currently, postIntegration only creates an empty integration. To add auth settings (like client_id and secret) we have to call pathIntegration. To the new integration creation flow, where the user fills in the data at the moment of creating the integration, we need postIntegration to accept auth settings from the get-go.
This PR postIntegrations to accept auth settings, as well as general settings (integrationId, forwardWebhooks, etc).


The controller now relies on shared validation and build helpers to translate provider metadata and credentials into persisted configurations, enforce auth/provider compatibility and custom identifier uniqueness, provision MCP OAuth clients when required, and extend shared credential handling and webhook secret management, all backed by integration tests covering success and failure paths.

Key Changes

• Introduced packages/server/lib/controllers/v1/integrations/validation.ts with discriminated-union schemas reused by both postIntegration and patchIntegration
• Added packages/server/lib/controllers/v1/integrations/buildIntegrationConfig.ts to construct DBCreateIntegration payloads (unique key generation, credential mapping, webhook secret propagation)
• Expanded packages/server/lib/controllers/v1/integrations/postIntegration.ts to validate extended bodies, enforce integrationId uniqueness and auth-mode compatibility, optionally register MCP OAuth clients, and create provider configs via the new helper
• Updated packages/server/lib/controllers/v1/integrations/providerConfigKey/patchIntegration.ts and packages/types/lib/integration/api.ts to reuse shared typings/schemas for auth payloads
• Added comprehensive Vitest integration coverage in packages/server/lib/controllers/v1/integrations/postIntegration.integration.test.ts for validation errors and success cases

Affected Areas

packages/server/lib/controllers/v1/integrations/postIntegration.ts
packages/server/lib/controllers/v1/integrations/buildIntegrationConfig.ts
packages/server/lib/controllers/v1/integrations/validation.ts
packages/server/lib/controllers/v1/integrations/providerConfigKey/patchIntegration.ts
packages/types/lib/integration/api.ts
packages/server/lib/controllers/v1/integrations/postIntegration.integration.test.ts


This summary was automatically generated by @propel-code-bot

@kaposke kaposke requested a review from a team January 6, 2026 19:49
@linear
Copy link

linear bot commented Jan 6, 2026

@my-senior-dev-pr-review
Copy link

my-senior-dev-pr-review bot commented Jan 6, 2026

🤖 My Senior Dev — Analysis Complete

👤 For @kaposke

📁 Expert in packages/ (77 edits) • ⚡ 7th PR this month

View your contributor analytics →


📊 6 files reviewed • 1 high risk • 4 need attention

🚨 High Risk:

  • packages/server/lib/controllers/v1/integrations/buildIntegrationConfig.ts — Contains critically sensitive integration configuration handling, including authentication details.

⚠️ Needs Attention:

  • packages/server/lib/controllers/v1/integrations/buildIntegrationConfig.ts — Critical core functionality for building integration configuration, requires careful review of unique key generation and API consistency.

🚀 Open Interactive Review →

The full interface unlocks features not available in GitHub:

  • 💬 AI Chat — Ask questions on any file, get context-aware answers
  • 🔍 Smart Hovers — See symbol definitions and usage without leaving the diff
  • 📚 Code Archeology — Understand how files evolved over time (/archeology)
  • 🎯 Learning Insights — See how this PR compares to similar changes

💬 Chat here: @my-senior-dev explain this change — or try @chaos-monkey @security-auditor @optimizer @skeptic @junior-dev

📖 View all 12 personas & slash commands

You can interact with me by mentioning @my-senior-dev in any comment:

In PR comments or on any line of code:

  • Ask questions about the code or PR
  • Request explanations of specific changes
  • Get suggestions for improvements

Slash commands:

  • /help — Show all available commands
  • /archeology — See the history and evolution of changed files
  • /profile — Performance analysis and suggestions
  • /expertise — Find who knows this code best
  • /personas — List all available AI personas

AI Personas (mention to get their perspective):

Persona Focus
@chaos-monkey 🐵 Edge cases & failure scenarios
@skeptic 🤨 Challenge assumptions
@optimizer Performance & efficiency
@security-auditor 🔒 Security vulnerabilities
@accessibility-advocate Inclusive design
@junior-dev 🌱 Simple explanations
@tech-debt-collector 💳 Code quality & shortcuts
@ux-champion 🎨 User experience
@devops-engineer 🚀 Deployment & scaling
@documentation-nazi 📚 Documentation gaps
@legacy-whisperer 🏛️ Working with existing code
@test-driven-purist Testing & TDD

For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews.

// Determine unique_key
let unique_key: string;
if ('integrationId' in body && body.integrationId) {
unique_key = body.integrationId;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the passed integrationId already exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've screwed up the condition. Fixing...

* @param clientId - Optional client ID (for MCP_OAUTH2)
* @returns A DBCreateIntegration object ready to be passed to createProviderConfig
*/
export async function buildIntegrationConfig(body: PostIntegration['Body'], environmentId: number, mcpClientId?: string): Promise<DBCreateIntegration> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this function be reused in patchIntegration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the input format slightly different. I'm considering refactoring the patch method to be similar to this one later, just wanted to avoid work in patch and updating frontend for now.

* @param provider - The provider configuration
* @param environmentId - The environment ID
* @param existingCount - The count of existing integrations with the same provider name (for unique_key generation)
* @param clientId - Optional client ID (for MCP_OAUTH2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is called mcpClientId below?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should the mcp edge case be left outside of this function?

@kaposke kaposke force-pushed the gui/NAN-4478/feat-post-integration-accepts-data branch from 34600fe to 5f7a7cf Compare January 8, 2026 16:38
} else {
const exists = await configService.getIdByProviderConfigKey(environmentId, body.provider);
unique_key = !exists ? body.provider : `${body.provider}-${nanoid(4).toLocaleLowerCase()}`;
}
Copy link
Collaborator

@TBonnin TBonnin Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about

const getUniqueKey(string) = async (key) => {
    const exists = await configService.getIdByProviderConfigKey(environmentId, key);
    return exists ? `${key}-${nanoid(4).toLocaleLowerCase()}` : ;
}
const uniqueKey = getUniqueKey(body.integrationId ? body.integrationId : body.provider)

environment_id: environmentId,
unique_key,
provider: body.provider,
forward_webhooks: 'forward_webhooks' in body && body.forward_webhooks !== undefined ? body.forward_webhooks : true,
Copy link
Collaborator

@TBonnin TBonnin Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it the same as:

forward_webhooks: body.forward_webhooks ?? true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants