(keyId: string)
| 149 | * last-used tracking. |
| 150 | */ |
| 151 | export async function updateApiKeyLastUsed(keyId: string): Promise<void> { |
| 152 | try { |
| 153 | const staleBefore = new Date(Date.now() - LAST_USED_STALENESS_WINDOW_MS) |
| 154 | await db |
| 155 | .update(apiKeyTable) |
| 156 | .set({ lastUsed: new Date() }) |
| 157 | .where( |
| 158 | and( |
| 159 | eq(apiKeyTable.id, keyId), |
| 160 | or(isNull(apiKeyTable.lastUsed), lt(apiKeyTable.lastUsed, staleBefore)) |
| 161 | ) |
| 162 | ) |
| 163 | } catch (error) { |
| 164 | logger.error('Error updating API key last used:', error) |
| 165 | } |
| 166 | } |
no test coverage detected