# AccountPhones

> AccountPhones: the phone numbers your account's owner messages and calls NoClick from, each proven theirs.

## AccountPhones

```typescript
class AccountPhones
```

The numbers linked to your account. A linked number reaches the account: texts and calls from it go to its owner's
NoClick, and the web's phone sign-in signs in to the account with it. So these are the signed-in owner's, or a key
of your account's own that names the `account:phones` scope (a key with `*` doesn't hold it unless it's named too);
any other caller rejects with `PermissionDenied`. Refusals carry their kind in `error.details.reason`
(`invalid_code`, `expired`, `already_linked`, `linked_elsewhere`, `last_way_in`, ...).

| Attribute | Type | Description |
| --- | --- | --- |
| `configured` | `boolean` | Whether this NoClick sends codes to link a number. |
| `maxPhones` | `number` | How many numbers an account may link. |
| `phones` | `readonly LinkedPhone[]` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

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

### AccountPhones.get

```typescript
static get(options?: { client?: NoClick }): Promise<AccountPhones>
```

Read the numbers linked to the account.

    const { phones, maxPhones } = await AccountPhones.get();

Parameters:

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

Returns: The linked numbers (`phones`), whether this NoClick sends codes to link one (`configured`) and how
many an account may link (`max_phones`).

### AccountPhones.link

```typescript
static link(
  phone: string,
  options?: { client?: NoClick },
): Promise<PhoneChallenge>
```

Text a code to `phone` (with its country code, like `+14155550123`) to link it. Resolves to the challenge the code
is checked against with `AccountPhones.verify`, within ten minutes.

    const challenge = await AccountPhones.link("+14155550123");

Parameters:

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

Returns: The challenge the code is checked against with `AccountPhones.verify`, within ten minutes.

### AccountPhones.verify

```typescript
static verify(
  challengeId: string,
  code: string,
  options?: { client?: NoClick },
): Promise<LinkedPhone>
```

Link the challenge's number with the code texted to it. A wrong code rejects with `InvalidRequest` (`reason`
`invalid_code`) and can be tried again; an expired challenge (`Expired`) or too many tries (`RateLimited`) needs a
new code.

    await AccountPhones.verify(challenge.id, "123456");

Parameters:

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

Returns: The number, linked: proven by a code (`source` `verify`), and when.

### AccountPhones.unlink

```typescript
static unlink(phone: string, options?: { client?: NoClick }): Promise<void>
```

Unlink a number: texts and calls from it no longer reach the account, at once. The only number of an account with
no email rejects with `Conflict` (`reason` `last_way_in`).

    await AccountPhones.unlink("+14155550123");

Parameters:

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

## LinkedPhone

```typescript
interface LinkedPhone
```

One number linked to the account: how it was proven (`verify`, a code texted to it; `whatsapp` or `imessage`, it
texted NoClick) and when.

| Attribute | Type | Description |
| --- | --- | --- |
| `phone` | `string` |  |
| `source` | `string` |  |
| `verifiedAt` | `Date | null` |  |

## PhoneChallenge

```typescript
interface PhoneChallenge
```

A code texted to a number to link it: check it with `AccountPhones.verify` before `expiresAt`.

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

Types:

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