@@ -11,7 +11,7 @@ import { createLogger } from '@sim/logger'
1111import { generateId } from '@sim/utils/id'
1212import { and , eq , sql } from 'drizzle-orm'
1313import type { NextRequest } from 'next/server'
14- import { asOrchestrationError , OrchestrationError } from '@/lib/core/orchestration/types'
14+ import { OrchestrationError } from '@/lib/core/orchestration/types'
1515import { decryptSecret } from '@/lib/core/security/encryption'
1616import { listSlackCredentialGroupConfigurationsForBot } from '@/lib/credential-groups/provider-configuration'
1717import {
@@ -45,7 +45,6 @@ import {
4545 SLACK_CUSTOM_BOT_PROVIDER_ID ,
4646 SLACK_CUSTOM_BOT_SECRET_TYPE ,
4747} from '@/lib/oauth/types'
48- import { captureServerEvent } from '@/lib/posthog/server'
4948
5049const logger = createLogger ( 'CredentialOrchestration' )
5150type CredentialRow = typeof credential . $inferSelect
@@ -618,89 +617,3 @@ export async function deleteCredentialRecord(
618617 reason : params . reason ,
619618 } )
620619}
621-
622- /** Preserves the legacy callers while application adapters migrate to the manager above. */
623- export async function performDeleteCredential (
624- params : CredentialActorParams
625- ) : Promise < PerformCredentialResult > {
626- try {
627- const access = await getCredentialActorContext ( params . credentialId , params . userId )
628- if ( ! access . credential ) {
629- return { success : false , error : 'Credential not found' , errorCode : 'not_found' }
630- }
631- if ( access . credential . type === 'managed_oauth' ) {
632- return { success : false , error : 'Credential not found' , errorCode : 'not_found' }
633- }
634- if ( ! access . hasWorkspaceAccess || ! access . isAdmin ) {
635- return {
636- success : false ,
637- error : 'Credential admin permission required' ,
638- errorCode : 'forbidden' ,
639- }
640- }
641- if ( params . allowedTypes && ! params . allowedTypes . includes ( access . credential . type ) ) {
642- return {
643- success : false ,
644- error : `Only ${ params . allowedTypes . join ( ', ' ) } credentials can be managed with this tool.` ,
645- errorCode : 'validation' ,
646- }
647- }
648-
649- const reason = params . reason ?? 'user_delete'
650- await deleteCredentialRecord ( { credential : access . credential , reason } )
651-
652- captureServerEvent (
653- params . userId ,
654- 'credential_deleted' ,
655- {
656- credential_type : access . credential . type ,
657- provider_id :
658- access . credential . providerId ?? access . credential . envKey ?? params . credentialId ,
659- workspace_id : access . credential . workspaceId ,
660- } ,
661- { groups : { workspace : access . credential . workspaceId } }
662- )
663-
664- const envDescription =
665- access . credential . type === 'env_personal'
666- ? `Deleted personal env credential "${ access . credential . envKey } "`
667- : access . credential . type === 'env_workspace'
668- ? `Deleted workspace env credential "${ access . credential . envKey } "`
669- : `Deleted ${ access . credential . type } credential "${ access . credential . displayName } " (${ reason } )`
670- recordAudit ( {
671- workspaceId : access . credential . workspaceId ,
672- actorId : params . userId ,
673- actorName : params . actorName ?? undefined ,
674- actorEmail : params . actorEmail ?? undefined ,
675- action : AuditAction . CREDENTIAL_DELETED ,
676- resourceType : AuditResourceType . CREDENTIAL ,
677- resourceId : params . credentialId ,
678- resourceName : access . credential . displayName ,
679- description : envDescription ,
680- metadata : {
681- reason,
682- credentialType : access . credential . type ,
683- providerId : access . credential . providerId ,
684- accountId : access . credential . accountId ,
685- envKey : access . credential . envKey ,
686- } ,
687- request : params . request ,
688- } )
689-
690- return { success : true , workspaceId : access . credential . workspaceId }
691- } catch ( error ) {
692- const orchestrationError = asOrchestrationError ( error )
693- if ( orchestrationError ) {
694- if ( orchestrationError . code !== 'not_found' && orchestrationError . code !== 'conflict' ) {
695- throw orchestrationError
696- }
697- return {
698- success : false ,
699- error : orchestrationError . message ,
700- errorCode : orchestrationError . code ,
701- }
702- }
703- logger . error ( 'Failed to delete credential' , { error } )
704- return { success : false , error : 'Internal server error' , errorCode : 'internal' }
705- }
706- }
0 commit comments