# Account

> Your account: its plan, balance, month's spend, counts, limits and defaults (`Account.get`), changing its defaults (`update`), the account at a glance with what waits and what failed (`status`), the public endpoints a publishable key may call, what an id or key prefix names (`resolve`), and a one-tap payment link for its owner.

## Account

```typescript
class Account
```

The account at a glance (`GET /v1/account`): its plan's `planTier`, `balance` (`remaining_usd`, null when it can't
be read, never 0), this `month`'s spend, how many of each thing it has (`counts`), its `limits` and `features`, its
`defaultRegion` and the default a paused user is told (`spendingPaused`), and what the platform offers (`scopes`,
`explicitScopes`). The signed-in owner also reads `email`, `spendCap` and `consoleKeyId`; one of the account's own
secret keys reads the rest.

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `email` | `string | null` |  |
| `owner` | `{ name?: string; email?: string; phone?: string } | null` | Who owns it, as NoClick knows them (`name`, `email`, `phone`, each only when known): the signed-in owner's view only. |
| `planTier` | `string | null` |  |
| `balance` | `JsonObject` |  |
| `month` | `JsonObject` |  |
| `spendCap` | `JsonObject | null` |  |
| `counts` | `Record<string, number>` |  |
| `limits` | `Record<string, number>` |  |
| `features` | `Record<string, boolean>` |  |
| `defaultRegion` | `string | null` |  |
| `spendingPaused` | `PausedSpendingDefault | null` |  |
| `consoleKeyId` | `string | null` |  |
| `scopes` | `string[]` | What a key with every scope (`*`) holds. |
| `explicitScopes` | `string[]` | The scopes a key holds only when it names them. |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

### Account.get

```typescript
static get(options?: AccountCallOptions): Promise<Account>
```

Read the account: the signed-in owner, or one of the account's own secret keys acting for it (a key acting for one
of its users is refused with `PermissionDenied`).

    const account = await Account.get();
    console.log(account.planTier, account.balance.remaining_usd);

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.signal` (`AbortSignal`)

Returns: The account.

### Account.update

```typescript
static update(
  changes: AccountChanges,
  options?: { client?: NoClick },
): Promise<Account>
```

Change the account's defaults: only the fields given; `null` clears one. The signed-in owner's alone. Resolves to
the account as it is now.

    await Account.update({ defaultRegion: "eu", spendCapUsd: 200 });

Parameters:

- `changes` (`AccountChanges`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The account as it is now.

Types:

```typescript
/** What `Account.update` changes: only the fields given; `null` clears one. */
interface AccountChanges {
  /** The region new resources take when a call names none; `null` clears it. */
  defaultRegion?: string | null;
  /** What a paused user is told when their spending is paused without a message; `null` removes it. */
  spendingPaused?: PausedSpendingDefault | null;
  /** The monthly spending cap in whole dollars; `null` removes it. Only the signed-in owner sets, raises or removes it. */
  spendCapUsd?: number | null;
}
```

### Account.status

```typescript
static status(options?: AccountCallOptions): Promise<AccountStatus>
```

The account at a glance, as the key calling sees it: which account (or which of its users the key acts for), its
plan, balance, this month's spend against its caps, approvals waiting on a person, what failed in the last day and
what ran last. A user's session is refused.

    const status = await Account.status();
    console.log(status.account.name ?? status.account.id, status.balance.remaining_usd);

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.signal` (`AbortSignal`)

Returns: The status.

### Account.publicEndpoints

```typescript
static publicEndpoints(options?: AccountCallOptions): Promise<PublicEndpoint[]>
```

What a publishable key may list: the account's public endpoints (a shared agent's page, a published workflow), each
by `kind` and `id`. The signed-in owner's alone.

    for (const endpoint of await Account.publicEndpoints()) console.log(endpoint.kind, endpoint.name, endpoint.url);

Parameters:

- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.signal` (`AbortSignal`)

Returns: Each `PublicEndpoint`.

### Account.resolve

```typescript
static resolve(ref: string, options?: AccountCallOptions): Promise<ObjectRef>
```

What `ref` names in the account: an object's id, a key's prefix (`nk_live_ab12…`) or one of your users' ids,
resolved to its `type` and `id` (and the user it belongs to). Nothing it names rejects with `NotFound`. The
signed-in owner's alone.

    const found = await Account.resolve("nk_live_ab12");
    console.log(found.type, found.id);

Parameters:

- `ref` (`string`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.
- `options.signal` (`AbortSignal`)

Returns: Its `type` and `id`, and the user it belongs to.

### Account.paymentLink

```typescript
static paymentLink(
  request: {
    kind?: "funds" | "plan" | "topup";
    amountUsd?: number;
    plan?: string;
    billingPeriod?: "monthly" | "yearly";
    creditsPerMonth?: number;
  },
  options?: { client?: NoClick },
): Promise<PaymentLink>
```

A one-tap link that pays for the account, made for its owner to open: funds for its balance (`amountUsd`, whole
dollars; the plan's fee is paid with them), or a `plan` to move to. Opening it needs no sign-in, so only the
signed-in owner and the account's assistant make one. Its operation (`operationId`) succeeds once they've paid;
the same purchase asked for again while its link is open answers that link.

    const link = await Account.paymentLink({ kind: "funds", amountUsd: 20 });
    console.log(link.priceUsd, link.url);

Parameters:

- `request` (`{ kind?: "funds" | "plan" | "topup"; amountUsd?: number; plan?: string; billingPeriod?: "monthly" | "yearly"; creditsPerMonth?: number }`, required)
- `options.client` (`NoClick`): The client to send with; defaults to the module client built from `NOCLICK_API_KEY`.

Returns: The link.

## AccountStatus

```typescript
interface AccountStatus
```

The account at a glance (`Account.status`): `account` (its `id`, `name`, `email`, or `acting_for`: the user a key
acts for), `userId`, its `plan`, `balance`, `month`, `caps` with what each spent, the approvals waiting on a
person (`approvalsPending`), what failed in the last day (`failing`) and what ran last (`operations`).

| Attribute | Type | Description |
| --- | --- | --- |
| `account` | `JsonObject` |  |
| `userId` | `string | null` |  |
| `plan` | `JsonObject | null` |  |
| `balance` | `JsonObject` |  |
| `month` | `JsonObject` |  |
| `caps` | `JsonObject[]` |  |
| `approvalsPending` | `JsonObject[]` |  |
| `failing` | `JsonObject[]` |  |
| `operations` | `JsonObject` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## ObjectRef

```typescript
interface ObjectRef
```

What `Account.resolve` found: the object's `type` and `id`, and the user it belongs to (null: the account).

| Attribute | Type | Description |
| --- | --- | --- |
| `type` | `string` |  |
| `id` | `string` |  |
| `userId` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## PausedSpendingDefault

```typescript
interface PausedSpendingDefault
```

What a paused user is told when a pause names no message, and the button with it.

| Attribute | Type | Description |
| --- | --- | --- |
| `message` | `string | null` |  |
| `action` | `{ label: string; url: string } | null` |  |

## PaymentLink

```typescript
interface PaymentLink
```

A payment link (`Account.paymentLink`): what it buys (`label`), what checkout charges (`priceUsd`), its `url`, when it lapses, and its operation.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `string` |  |
| `label` | `string` |  |
| `priceUsd` | `number` |  |
| `url` | `string` |  |
| `expiresAt` | `Date | null` |  |
| `operationId` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```

## PublicEndpoint

```typescript
interface PublicEndpoint
```

Something the owner made public that a publishable key may call; `name` and `url` are null once it stopped being public.

| Attribute | Type | Description |
| --- | --- | --- |
| `kind` | `string` |  |
| `id` | `string` |  |
| `name` | `string | null` |  |
| `url` | `string | null` |  |
| `userId` | `string | null` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

```typescript
type JsonObject = { [key: string]: unknown };
```
