MCPcopy Create free account
hub / github.com/diegosouzapw/OmniRoute / markCommandCodeAuthSessionReceived

Function markCommandCodeAuthSessionReceived

src/lib/db/commandCodeAuth.ts:131–152  ·  view source on GitHub ↗
(input: {
  stateHash: string;
  apiKey: string;
  metadata?: CommandCodeAuthMetadata;
})

Source from the content-addressed store, hash-verified

129}
130
131export 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
154export function getCommandCodeAuthSessionSafeStatus(
155 stateHash: string

Callers 1

POSTFunction · 0.90

Calls 7

encryptFunction · 0.90
nowIsoFunction · 0.85
markExpiredForStateFunction · 0.85
dbFunction · 0.70
runMethod · 0.65
prepareMethod · 0.65

Tested by

no test coverage detected