From 40c80f4b6829568055ecaea0200613c9becc5732 Mon Sep 17 00:00:00 2001 From: Victor Santos Date: Wed, 26 Nov 2025 10:49:05 -0300 Subject: [PATCH] refactor: remove deprecated native integration error handling and streamline integration token saving process in API routes --- .../routes/v1/integration-auth-router.ts | 48 ++++------ .../server/routes/v1/integration-router.ts | 96 +++++++++---------- 2 files changed, 63 insertions(+), 81 deletions(-) diff --git a/backend/src/server/routes/v1/integration-auth-router.ts b/backend/src/server/routes/v1/integration-auth-router.ts index 40bb8fa13..e5156724d 100644 --- a/backend/src/server/routes/v1/integration-auth-router.ts +++ b/backend/src/server/routes/v1/integration-auth-router.ts @@ -2,7 +2,6 @@ import { z } from "zod"; import { EventType } from "@app/ee/services/audit-log/audit-log-types"; import { ApiDocsTags, INTEGRATION_AUTH } from "@app/lib/api-docs"; -import { ForbiddenRequestError } from "@app/lib/errors"; import { readLimit, writeLimit } from "@app/server/config/rateLimiter"; import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; import { AuthMode } from "@app/services/auth/auth-type"; @@ -11,9 +10,6 @@ import { Integrations } from "@app/services/integration-auth/integration-list"; import { integrationAuthPubSchema } from "../sanitizedSchemas"; -const NATIVE_INTEGRATION_DEPRECATION_MESSAGE = - "We're moving Native Integrations to Secret Syncs. Check the documentation at https://infisical.com/docs/integrations/secret-syncs/overview. If the integration you need isn't available in the Secret Syncs, please get in touch with us at team@infisical.com."; - export const registerIntegrationAuthRouter = async (server: FastifyZodProvider) => { server.route({ method: "GET", @@ -337,33 +333,27 @@ export const registerIntegrationAuthRouter = async (server: FastifyZodProvider) }) } }, - handler: async (_) => { - throw new ForbiddenRequestError({ - message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE + handler: async (req) => { + const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({ + actorId: req.permission.id, + actor: req.permission.type, + actorAuthMethod: req.permission.authMethod, + actorOrgId: req.permission.orgId, + projectId: req.body.workspaceId, + ...req.body }); - // We are keeping the old response commented out for an easy revert on the API if we need to before the full phase out. - - // const integrationAuth = await server.services.integrationAuth.saveIntegrationToken({ - // actorId: req.permission.id, - // actor: req.permission.type, - // actorAuthMethod: req.permission.authMethod, - // actorOrgId: req.permission.orgId, - // projectId: req.body.workspaceId, - // ...req.body - // }); - - // await server.services.auditLog.createAuditLog({ - // ...req.auditLogInfo, - // projectId: req.body.workspaceId, - // event: { - // type: EventType.AUTHORIZE_INTEGRATION, - // metadata: { - // integration: integrationAuth.integration - // } - // } - // }); - // return { integrationAuth }; + await server.services.auditLog.createAuditLog({ + ...req.auditLogInfo, + projectId: req.body.workspaceId, + event: { + type: EventType.AUTHORIZE_INTEGRATION, + metadata: { + integration: integrationAuth.integration + } + } + }); + return { integrationAuth }; } }); diff --git a/backend/src/server/routes/v1/integration-router.ts b/backend/src/server/routes/v1/integration-router.ts index 183c5a38b..95477c341 100644 --- a/backend/src/server/routes/v1/integration-router.ts +++ b/backend/src/server/routes/v1/integration-router.ts @@ -3,19 +3,17 @@ import { z } from "zod"; import { IntegrationsSchema } from "@app/db/schemas"; import { EventType } from "@app/ee/services/audit-log/audit-log-types"; import { ApiDocsTags, INTEGRATION } from "@app/lib/api-docs"; -import { ForbiddenRequestError } from "@app/lib/errors"; import { removeTrailingSlash, shake } from "@app/lib/fn"; import { readLimit, writeLimit } from "@app/server/config/rateLimiter"; +import { getTelemetryDistinctId } from "@app/server/lib/telemetry"; import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; import { AuthMode } from "@app/services/auth/auth-type"; import { IntegrationMetadataSchema } from "@app/services/integration/integration-schema"; import { Integrations } from "@app/services/integration-auth/integration-list"; +import { PostHogEventTypes, TIntegrationCreatedEvent } from "@app/services/telemetry/telemetry-types"; import {} from "../sanitizedSchemas"; -const NATIVE_INTEGRATION_DEPRECATION_MESSAGE = - "We're moving Native Integrations to Secret Syncs. Check the documentation at https://infisical.com/docs/integrations/secret-syncs/overview. If the integration you need isn't available in the Secret Syncs, please get in touch with us at team@infisical.com."; - export const registerIntegrationRouter = async (server: FastifyZodProvider) => { server.route({ method: "POST", @@ -68,58 +66,52 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => { } }, onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]), - handler: async (_) => { - throw new ForbiddenRequestError({ - message: NATIVE_INTEGRATION_DEPRECATION_MESSAGE + handler: async (req) => { + const { integration, integrationAuth } = await server.services.integration.createIntegration({ + actorId: req.permission.id, + actor: req.permission.type, + actorAuthMethod: req.permission.authMethod, + actorOrgId: req.permission.orgId, + ...req.body }); - // We are keeping the old response commented out for an easy revert on the API if we need to before the full phase out. + const createIntegrationEventProperty = shake({ + integrationId: integration.id.toString(), + integration: integration.integration, + environment: req.body.sourceEnvironment, + secretPath: req.body.secretPath, + url: integration.url, + app: integration.app, + appId: integration.appId, + targetEnvironment: integration.targetEnvironment, + targetEnvironmentId: integration.targetEnvironmentId, + targetService: integration.targetService, + targetServiceId: integration.targetServiceId, + path: integration.path, + region: integration.region + }) as TIntegrationCreatedEvent["properties"]; - // const { integration, integrationAuth } = await server.services.integration.createIntegration({ - // actorId: req.permission.id, - // actor: req.permission.type, - // actorAuthMethod: req.permission.authMethod, - // actorOrgId: req.permission.orgId, - // ...req.body - // }); + await server.services.auditLog.createAuditLog({ + ...req.auditLogInfo, + projectId: integrationAuth.projectId, + event: { + type: EventType.CREATE_INTEGRATION, + // eslint-disable-next-line + metadata: createIntegrationEventProperty + } + }); - // const createIntegrationEventProperty = shake({ - // integrationId: integration.id.toString(), - // integration: integration.integration, - // environment: req.body.sourceEnvironment, - // secretPath: req.body.secretPath, - // url: integration.url, - // app: integration.app, - // appId: integration.appId, - // targetEnvironment: integration.targetEnvironment, - // targetEnvironmentId: integration.targetEnvironmentId, - // targetService: integration.targetService, - // targetServiceId: integration.targetServiceId, - // path: integration.path, - // region: integration.region - // }) as TIntegrationCreatedEvent["properties"]; - - // await server.services.auditLog.createAuditLog({ - // ...req.auditLogInfo, - // projectId: integrationAuth.projectId, - // event: { - // type: EventType.CREATE_INTEGRATION, - // // eslint-disable-next-line - // metadata: createIntegrationEventProperty - // } - // }); - - // await server.services.telemetry.sendPostHogEvents({ - // event: PostHogEventTypes.IntegrationCreated, - // organizationId: req.permission.orgId, - // distinctId: getTelemetryDistinctId(req), - // properties: { - // ...createIntegrationEventProperty, - // projectId: integrationAuth.projectId, - // ...req.auditLogInfo - // } - // }); - // return { integration }; + await server.services.telemetry.sendPostHogEvents({ + event: PostHogEventTypes.IntegrationCreated, + organizationId: req.permission.orgId, + distinctId: getTelemetryDistinctId(req), + properties: { + ...createIntegrationEventProperty, + projectId: integrationAuth.projectId, + ...req.auditLogInfo + } + }); + return { integration }; } });