# AccountPush

> AccountPush: the browsers that show the signed-in person NoClick's notifications (Web Push).

## AccountPush

```typescript
class AccountPush
```

The browsers that show the signed-in person NoClick's notifications: a DM or

| Attribute | Type | Description |
| --- | --- | --- |
| `configured` | `boolean` | Whether this NoClick sends notifications to browsers. |
| `publicKey` | `string | null` | The key a browser subscribes with (`applicationServerKey`), base64url. |
| `devices` | `readonly PushDevice[]` |  |
| `raw` | `JsonObject` | The response JSON exactly as the API sent it. |

Types:

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

### AccountPush.get

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

Read the browsers that show the person's notifications, and the key a new one subscribes with.

    const { publicKey, devices } = await AccountPush.get();

Parameters:

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

Returns: The browsers (`devices`), whether this NoClick sends notifications to browsers (`configured`) and the
key a new one subscribes with (`public_key`).

### AccountPush.add

```typescript
static add(
  subscription: PushSubscriptionJson,
  options?: { device?: string; client?: NoClick },
): Promise<PushDevice>
```

Turn notifications on in this browser, with its push subscription: the same browser again (or one signed in to
another account before) is updated, never added twice. `device` names it for the person, like `iPhone`.

    const subscription = await registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: publicKey });
    const { id } = await AccountPush.add(subscription.toJSON(), { device: "iPhone" });

Parameters:

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

Returns: The browser, as it's kept.

Types:

```typescript
/** A browser's push subscription, as `PushSubscription.toJSON()` gives it. */
interface PushSubscriptionJson {
  endpoint?: string;
  keys?: Record<string, string>;
}
```

### AccountPush.remove

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

Turn notifications off in one browser.

    await AccountPush.remove(id);

Parameters:

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

Returns: Nothing.

## PushDevice

```typescript
interface PushDevice
```

One browser that shows the person's notifications, as its push service names it (`endpoint`).

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `string` |  |
| `device` | `string | null` |  |
| `endpoint` | `string` |  |
| `createdAt` | `Date | null` |  |
| `lastSentAt` | `Date | null` |  |
