(name: string)
| 110 | })); |
| 111 | |
| 112 | export const deleteApiKey = async (name: string): Promise<{ success: boolean } | ServiceError> => sew(() => |
| 113 | withAuth(async ({ org, user, prisma }) => { |
| 114 | const apiKey = await prisma.apiKey.findFirst({ |
| 115 | where: { |
| 116 | name, |
| 117 | createdById: user.id, |
| 118 | }, |
| 119 | }); |
| 120 | |
| 121 | if (!apiKey) { |
| 122 | await createAudit({ |
| 123 | action: "api_key.deletion_failed", |
| 124 | actor: { |
| 125 | id: user.id, |
| 126 | type: "user" |
| 127 | }, |
| 128 | target: { |
| 129 | id: org.id.toString(), |
| 130 | type: "org" |
| 131 | }, |
| 132 | orgId: org.id, |
| 133 | metadata: { |
| 134 | message: `API key ${name} not found for user ${user.id}`, |
| 135 | api_key: name |
| 136 | } |
| 137 | }); |
| 138 | return { |
| 139 | statusCode: StatusCodes.NOT_FOUND, |
| 140 | errorCode: ErrorCode.API_KEY_NOT_FOUND, |
| 141 | message: `API key ${name} not found for user ${user.id}`, |
| 142 | } satisfies ServiceError; |
| 143 | } |
| 144 | |
| 145 | await prisma.apiKey.delete({ |
| 146 | where: { |
| 147 | hash: apiKey.hash, |
| 148 | }, |
| 149 | }); |
| 150 | |
| 151 | await createAudit({ |
| 152 | action: "api_key.deleted", |
| 153 | actor: { |
| 154 | id: user.id, |
| 155 | type: "user" |
| 156 | }, |
| 157 | target: { |
| 158 | id: apiKey.hash, |
| 159 | type: "api_key" |
| 160 | }, |
| 161 | orgId: org.id, |
| 162 | metadata: { |
| 163 | api_key: name |
| 164 | } |
| 165 | }); |
| 166 | |
| 167 | return { |
| 168 | success: true, |
| 169 | } |
no test coverage detected