(input: {
stateHash: string;
apiKey: string;
metadata?: CommandCodeAuthMetadata;
})
| 129 | } |
| 130 | |
| 131 | export function markCommandCodeAuthSessionReceived(input: { |
| 132 | stateHash: string; |
| 133 | apiKey: string; |
| 134 | metadata?: CommandCodeAuthMetadata; |
| 135 | }): CommandCodeAuthSafeStatus | null { |
| 136 | const now = nowIso(); |
| 137 | markExpiredForState(input.stateHash, now); |
| 138 | const metadata: CommandCodeAuthMetadata = { |
| 139 | ...(input.metadata || {}), |
| 140 | receivedAt: now, |
| 141 | }; |
| 142 | const encryptedApiKey = encrypt(input.apiKey); |
| 143 | db() |
| 144 | .prepare( |
| 145 | `UPDATE command_code_auth_sessions |
| 146 | SET status = 'received', encrypted_api_key = ?, metadata_json = ?, received_at = ?, updated_at = ? |
| 147 | WHERE state_hash = ? AND status IN ('pending', 'received') AND expires_at > ?` |
| 148 | ) |
| 149 | .run(encryptedApiKey, JSON.stringify(metadata), now, now, input.stateHash, now); |
| 150 | |
| 151 | return getCommandCodeAuthSessionSafeStatus(input.stateHash); |
| 152 | } |
| 153 | |
| 154 | export function getCommandCodeAuthSessionSafeStatus( |
| 155 | stateHash: string |
no test coverage detected