← Public packages
@kentcdodds/google
Google helpers for Gmail, Calendar, Drive, People, YouTube (including upload), and Analytics.
src/auth-fetch.ts
35 lines · 1.1 KB · TypeScriptimport { createAuthenticatedFetch } from 'kody:runtime'
import {
type GoogleAccountInfo,
resolveGoogleAccount,
} from './accounts.ts'
/**
* Literal-name authenticated fetch for a resolved Google account alias.
* Publish stamps each `createAuthenticatedFetch("…")` call site.
*/
export async function createGoogleAuthenticatedFetch(
account: GoogleAccountInfo | string | { account?: string },
): Promise<typeof fetch> {
const resolved =
typeof account === 'object' &&
account !== null &&
'integrationName' in account &&
'account' in account
? (account as GoogleAccountInfo)
: resolveGoogleAccount(account)
switch (resolved.account) {
case 'personal':
return await createAuthenticatedFetch('google')
case 'business':
return await createAuthenticatedFetch('google-business')
case 'youtube-brand':
return await createAuthenticatedFetch('google-youtube-brand')
case 'youtube-plus':
return await createAuthenticatedFetch('google-youtube-plus')
default: {
const exhaustive: never = resolved.account
throw new Error(`Unhandled Google account: ${String(exhaustive)}`)
}
}
}