Skip to content

src/accounts.ts

30 lines · 1.2 KB · TypeScript
Raw
export type { CloudflareAccount, CloudflareAccountInfo, CloudflareAuthOptions } from './auth.ts'
export {
	DEFAULT_CLOUDFLARE_ACCOUNT,
	KCD_CLOUDFLARE_ACCOUNT_ID,
	KODY_CLOUDFLARE_ACCOUNT_ID,
	accounts,
	getAccountInfo,
	resolveApiTokenSecretName,
	resolveKnownAccountId,
} from './auth.ts'
import { accounts } from './auth.ts'

/**
 * List Cloudflare token aliases with their secret name, known account id,
 * and what each token can and cannot do. No network call, no secret needed.
 * Use it to pick `account` (and find `accountId`) before calling other exports.
 *
 * `accountId` is set when the alias maps to one account (`kody` → Kody,
 * `pages` → KCD). For `default` (spans several accounts) it is `null`: call
 * `./verify` to get `accessibleAccounts`, or pass `accountId` explicitly.
 *
 * @returns Array of `{ account, secretName, accountId, accountName, useWhen, avoidWhen, can, cannot }`.
 * @example
 * import listCloudflareAccounts from 'kody:@kentcdodds/cloudflare/accounts'
 * const accounts = listCloudflareAccounts()
 * // => [{ account: 'default', accountId: null, can: [...] }, { account: 'pages', accountId: 'a41d…', accountName: 'KCD', ... }, ...]
 */
export default function listCloudflareAccounts() {
	return accounts()
}