(params: DeleteCredentialParams)
| 28 | * records an audit entry. Idempotent when the row no longer exists. |
| 29 | */ |
| 30 | export async function deleteCredential(params: DeleteCredentialParams): Promise<void> { |
| 31 | const { credentialId, actorId, actorName, actorEmail, reason, request } = params |
| 32 | |
| 33 | const [row] = await db |
| 34 | .select({ |
| 35 | id: schema.credential.id, |
| 36 | workspaceId: schema.credential.workspaceId, |
| 37 | type: schema.credential.type, |
| 38 | displayName: schema.credential.displayName, |
| 39 | providerId: schema.credential.providerId, |
| 40 | accountId: schema.credential.accountId, |
| 41 | }) |
| 42 | .from(schema.credential) |
| 43 | .where(eq(schema.credential.id, credentialId)) |
| 44 | .limit(1) |
| 45 | |
| 46 | if (!row) return |
| 47 | |
| 48 | await clearCredentialRefs(credentialId, row.workspaceId) |
| 49 | |
| 50 | await db.delete(schema.credential).where(eq(schema.credential.id, credentialId)) |
| 51 | |
| 52 | recordAudit({ |
| 53 | workspaceId: row.workspaceId, |
| 54 | actorId, |
| 55 | actorName: actorName ?? undefined, |
| 56 | actorEmail: actorEmail ?? undefined, |
| 57 | action: AuditAction.CREDENTIAL_DELETED, |
| 58 | resourceType: AuditResourceType.CREDENTIAL, |
| 59 | resourceId: credentialId, |
| 60 | resourceName: row.displayName, |
| 61 | description: `Deleted ${row.type} credential "${row.displayName}" (${reason})`, |
| 62 | metadata: { |
| 63 | reason, |
| 64 | credentialType: row.type, |
| 65 | providerId: row.providerId, |
| 66 | accountId: row.accountId, |
| 67 | }, |
| 68 | request, |
| 69 | }) |
| 70 | |
| 71 | logger.info('Deleted credential', { credentialId, workspaceId: row.workspaceId, reason }) |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Clears stored references to a credential across mutable workspace state |
no test coverage detected