@gitkraken/account-tools
v0.2.0
Published
GitKraken account client: auth token exchange, user/organization lookups, AI credit balance, and account/review URL builders.
Downloads
455
Readme
@gitkraken/account-tools
GitKraken account client: auth-code/token exchange, user and organization
lookups, active-organization selection, AI credit balance and state, and the
account/purchase/login/review URL builders — ported from gkcli's
internal/actions/user, internal/actions/organization, internal/aicredits
and internal/mcp/internal/tools.
Install
pnpm add @gitkraken/account-toolsUsage
import { getUser, listOrganizations, resolveActiveOrganization } from '@gitkraken/account-tools';
const config = {
apiBaseUrl: 'https://api.gitkraken.dev/',
appBaseUrl: 'https://gitkraken.dev/',
getToken: async () => tokenStore.accessToken,
client: { name: 'my-client', version: '1.0.0' },
};
const user = await getUser(config);
const orgs = await listOrganizations(config);
const active = resolveActiveOrganization(orgs, { licensedFeatures: user.licensedFeatures });AI credits
getAiCreditUsage satisfies @gitkraken/shared-tools' GetAiCreditUsage, so it can
be injected directly into @gitkraken/ai-provider-tools without that package depending on
this one:
import { getAiCreditUsage, resolveAiCreditState } from '@gitkraken/account-tools';
const usage = await getAiCreditUsage(config);
const state = resolveAiCreditState(config, usage, { organizationId: user.organization?.id, source: 'my-client' });resolveAiCreditState is pure: role resolution (isAdmin) is the host's job, via
getOrganization's members list.
URLs and trials
The URL builders and startTrial take the calling product explicitly; the library
has no default:
import { buildLoginUrl, buildPurchaseUrl, startTrial } from '@gitkraken/account-tools';
const loginUrl = buildLoginUrl(config, 'my-client');
const purchaseUrl = buildPurchaseUrl(config, 'my-client', 'upgrade');
await startTrial(config, { client: 'my-client' });Errors
Every call rejects with an AccountError { code, status?, cause? } — HttpError
from @gitkraken/api-tools is never thrown directly.
Ports
Same shape as @gitkraken/api-tools' Transport: getToken, an optional request
(defaults to a fetch adapter), and an optional logger. The library
owns no storage, no browser, and no callback server — persisting the active
organization id, or scheduling a token refresh, is the host's job.
