Last active
March 9, 2025 04:39
-
-
Save aquapi/baa16e26a31d4a0b422f7d34bd85207d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as st from 'safe-throw'; | |
import * as retry from 'safe-throw/retry'; | |
const fetchDomainByNameForUser = retry.untilAsync( | |
(res) => !st.isErr(res), | |
async (domainName: string, userId: string) => { | |
const authResult = await native.tryPromise( | |
Auth.check({ | |
action: 'query', | |
resource: 'domains', | |
userId | |
}) | |
); | |
if (st.isErr(authResult)) return authResult; | |
const domain = await native.tryPromise({ | |
db.query('domains', { name: domainName }) | |
}); | |
return st.isErr(domain) || domain != null | |
? domain | |
: st.err('Domain not found'); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment