@@ -3,6 +3,7 @@ import {DynamoDBDocumentClient, GetCommand, PutCommand, QueryCommand, UpdateComm
33import { addMinutes , addSeconds , getUnixTime } from 'date-fns'
44import type { webcrypto } from 'node:crypto'
55import type { ClaimSchema } from '../types'
6+ import { logger } from './logger'
67import type { JsonWebKeyWithKid , Key } from './oidc'
78
89/**
@@ -93,27 +94,21 @@ export async function getClaim(claimId: string): Promise<ClaimRecord | null> {
9394}
9495
9596/**
96- * Atomically mark a claim as exchanged and return the claim data
97+ * Mark a claim as successfully exchanged
9798 */
98- export async function exchangeClaim ( claimId : string ) : Promise < ClaimRecord | null > {
99+ export async function markClaimAsExchanged ( claimId : string ) : Promise < void > {
99100 try {
100- const result = await docClient . send (
101+ await docClient . send (
101102 new UpdateCommand ( {
102103 TableName : TABLE_NAME ,
103104 Key : { pk : `CLAIM#${ claimId } ` , sk : 'CLAIM' } ,
104105 UpdateExpression : 'SET exchanged = :true' ,
105- ConditionExpression : 'attribute_exists(pk) AND exchanged = :false' ,
106- ExpressionAttributeValues : { ':true' : true , ':false' : false } ,
107- ReturnValues : 'ALL_OLD' ,
106+ ConditionExpression : 'attribute_exists(pk)' ,
107+ ExpressionAttributeValues : { ':true' : true } ,
108108 } ) ,
109109 )
110- if ( ! result . Attributes ) return null
111- return result . Attributes as ClaimRecord
112110 } catch ( error ) {
113- if ( error instanceof Error && error . name === 'ConditionalCheckFailedException' ) {
114- return null
115- }
116- throw error
111+ logger . error ( 'Failed to mark claim as exchanged' , { claimId, error} )
117112 }
118113}
119114
0 commit comments