@@ -233,26 +233,15 @@ async function findDeletedIdentityMatch(
233233 return Boolean ( match )
234234}
235235
236- /**
237- * Runs a lookup on `executor`. Inside a caller's transaction it runs in a savepoint, so a failed
238- * lookup rolls back only itself instead of aborting the caller's transaction.
239- */
240- function readIdentity < T > ( executor : DbOrTx , read : ( reader : DbOrTx ) => Promise < T > ) : Promise < T > {
241- return executor === db ? read ( db ) : executor . transaction ( read )
242- }
243-
244236/**
245237 * Whether any of these identities belonged to an account deleted within the
246238 * retention window. Fails open: a lookup error returns `false` and is logged,
247239 * because refusing a legitimate person's allowance is worse than one missed match.
248240 */
249- export async function isDeletedAccountIdentity (
250- identity : SignInIdentity ,
251- executor : DbOrTx = db
252- ) : Promise < boolean > {
241+ export async function isDeletedAccountIdentity ( identity : SignInIdentity ) : Promise < boolean > {
253242 if ( ! isBillingEnabled ) return false
254243 try {
255- return await readIdentity ( executor , ( reader ) => findDeletedIdentityMatch ( reader , identity ) )
244+ return await findDeletedIdentityMatch ( db , identity )
256245 } catch ( error ) {
257246 logger . error ( 'Deleted-identity lookup failed; granting the free allowance' , { error } )
258247 return false
@@ -264,20 +253,22 @@ export async function isDeletedAccountIdentity(
264253 * the retention window: always its email, and its linked social sign-ins only
265254 * when `includeSignIns` is set, which callers do only for a user created in the
266255 * current signup request (a sign-in linked later never withholds anything).
267- * Pass the caller's transaction as `executor` to read on it. Fails open like
268- * {@link isDeletedAccountIdentity}.
256+ * Pass the caller's transaction as `executor` to read on it; the read then runs
257+ * in a savepoint, so a failed lookup never aborts that transaction. Fails open
258+ * like {@link isDeletedAccountIdentity}.
269259 */
270260export async function userHasDeletedAccountIdentity (
271261 userId : string ,
272262 { includeSignIns } : { includeSignIns : boolean } ,
273263 executor : DbOrTx = db
274264) : Promise < boolean > {
275265 if ( ! isBillingEnabled ) return false
266+ const read = async ( reader : DbOrTx ) => {
267+ const identity = await loadSignInIdentity ( reader , userId )
268+ return findDeletedIdentityMatch ( reader , includeSignIns ? identity : { email : identity . email } )
269+ }
276270 try {
277- return await readIdentity ( executor , async ( reader ) => {
278- const identity = await loadSignInIdentity ( reader , userId )
279- return findDeletedIdentityMatch ( reader , includeSignIns ? identity : { email : identity . email } )
280- } )
271+ return await ( executor === db ? read ( db ) : executor . transaction ( read ) )
281272 } catch ( error ) {
282273 logger . error ( 'Deleted-identity lookup failed; granting the free allowance' , { userId, error } )
283274 return false
0 commit comments