Skip to content

Instantly share code, notes, and snippets.

@aquapi
Last active March 9, 2025 04:39
Show Gist options
  • Save aquapi/baa16e26a31d4a0b422f7d34bd85207d to your computer and use it in GitHub Desktop.
Save aquapi/baa16e26a31d4a0b422f7d34bd85207d to your computer and use it in GitHub Desktop.
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