# Objects

> The User and Permit objects the client answers with, field by field.

The shapes in `toolaby.d.ts`. Dates are `Date` objects, in the background and in a page alike; amounts are in minor units of their currency; ids are as the dashboard shows them.

## User

Returned by `getUser()` and `refresh()`.

| Field            | Type                                                                                  |                                                                                                                                                                                                                                                                                                       |
| ---------------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `paid`           | `boolean`                                                                             | Holds the tool by any means below.                                                                                                                                                                                                                                                                    |
| `via`            | `'subscription' \| 'licence' \| 'trial' \| 'grant' \| 'account' \| 'unknown' \| null` | How. `account` when Toolaby has confirmed the account holds it but not yet by what. `null` when unpaid.                                                                                                                                                                                               |
| `email`          | `string \| null`                                                                      | The signed-in account's address, else the licence's.                                                                                                                                                                                                                                                  |
| `paidAt`         | `Date \| null`                                                                        | When the entitlement began.                                                                                                                                                                                                                                                                           |
| `plan`           | [`Plan`](#plan) `\| null`                                                             | The plan held, as Pricing defines it.                                                                                                                                                                                                                                                                 |
| `subscription`   | `{ status, periodEnd, cancelAtPeriodEnd, cancelAt } \| null`                          | Stripe's status (`active`, `trialing`, `past_due`…), when the period ends, and whether it is set to end there.                                                                                                                                                                                        |
| `trial`          | `{ endsAt: Date \| null, active: boolean } \| null`                                   | A trial, when one is running or ran.                                                                                                                                                                                                                                                                  |
| `deviceLimit`    | `{ allowed: number, held: number \| null } \| null`                                   | The account holds a plan, and this device is past its device limit: the plan unlocks `allowed` devices at once, and `held` hold it. The device has the Free plan until the buyer signs another one out on the account page. `null` otherwise.                                                         |
| `account`        | `{ linked, email, name, image, linkedAt }`                                            | The account signed in on this device, if any. `name` and `image` are what the account carries — Google's, when they signed in with it — from the server's last word; null until then. The account bar shows the picture, else the initial.                                                            |
| `licenseKey`     | `{ present: boolean }`                                                                | A licence key was activated on this device.                                                                                                                                                                                                                                                           |
| `token`          | `{ issuedAt, expiresAt, offlineUntil, plan } \| null`                                 | The entitlement token's dates, epoch seconds. `offlineUntil` is how long it is honoured without Toolaby. `plan` is the id of the plan the token was signed for, while it verifies; `null` for a trial or a grant, and while unpaid.                                                                   |
| `access`         | [`Access`](#access)                                                                   | What the Free plan holds.                                                                                                                                                                                                                                                                             |
| `signInRequired` | `boolean`                                                                             | Whether using the tool needs an account at all. Signed out, `gate()` refuses with `sign_in` whatever the Free plan holds.                                                                                                                                                                             |
| `features`       | `string[] \| null`                                                                    | The feature keys this device holds. `null` means everything: the tool has no features, or the entitlement lists none.                                                                                                                                                                                 |
| `usage`          | `{ unlimited, used, limit, remaining, per, resetsAt? }`                               | Free uses on this device, or, where the tool requires an account, the signed-in account's. `remaining` is `null` when nothing is counted. `per` is `'ever'` when they are counted in total, or `'day'`, `'week'` or `'month'` when they start again (UTC), with `resetsAt`, a `Date`, when more come. |
| `version`        | [`VersionState`](#versionstate)                                                       | Whether this build may run.                                                                                                                                                                                                                                                                           |
| `installedAt`    | `Date \| null`                                                                        | When the extension was first run on this device.                                                                                                                                                                                                                                                      |
| `installId`      | `string \| null`                                                                      | The device's id, as listed under Devices on the account page.                                                                                                                                                                                                                                         |
| `billing`        | `'one_time' \| 'subscription'`                                                        | The tool's billing as configured.                                                                                                                                                                                                                                                                     |
| `tool`           | `string`                                                                              | The tool's id.                                                                                                                                                                                                                                                                                        |

## Permit

Returned by `gate()`. One of three shapes; check `allowed` first.

**Allowed**

| Field                      | Type                 |                                                                                                                         |
| -------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `allowed`                  | `true`               |                                                                                                                         |
| `isPremium`                | `boolean`            | A paid plan, trial or grant is behind the answer. `false` when a free use was spent.                                    |
| `unlimited`                | `boolean?`           | Nothing is counted: a paid plan, or a Free plan set to *Everything free*.                                               |
| `remaining` `limit` `used` | `number?`            | The meter after this use, when the Free plan counts.                                                                    |
| `per` `resetsAt`           | `string?` `Date?`    | When free uses start again each day, week or month: the period, and when more come. Not in an answer given offline.     |
| `deviceLimit`              | `{ allowed, held }?` | The account holds a plan, but this device is past its device limit: the answer is the Free plan's.                      |
| `sharedUses`               | `true?`              | A free use counted with every throwaway or unverified address of the tool: they share one count, as they have no trial. |
| `offline`                  | `boolean?`           | Answered from the device; Toolaby was unreachable.                                                                      |

**Refused**

| Field                 | Type                                                                  |                                                                                                                                                                                                                                                                                                                                      |
| --------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `allowed`             | `false`                                                               |                                                                                                                                                                                                                                                                                                                                      |
| `reason`              | `'sign_in' \| 'paid' \| 'limit' \| 'feature' \| 'count' \| 'refused'` | Sign-in required; a plan required; free uses spent; the plan does not hold the feature; a `count` that is not a whole number from 1 to 1000; Toolaby refused the request; or an answer allowed a paid use without a token signed for this device that holds the feature, or a free use the Free plan the device knows does not give. |
| `feature` `needs`     | `string?` `string[]?`                                                 | For `feature`: the key asked for, and the ids of the plans that hold it. Pass one to `openPaymentPage()`.                                                                                                                                                                                                                            |
| `remaining` `limit`   | `number?`                                                             | For `limit`.                                                                                                                                                                                                                                                                                                                         |
| `per` `resetsAt`      | `string?` `Date?`                                                     | For `limit`, when free uses start again each day, week or month: the period, and when more come. Not in a refusal given offline.                                                                                                                                                                                                     |
| `deviceLimit`         | `{ allowed, held }?`                                                  | The account holds a plan, but this device is past its device limit. `showPaywall()` says so, instead of the plans.                                                                                                                                                                                                                   |
| `sharedUses`          | `true?`                                                               | For `limit`: the free uses spent were the ones every throwaway or unverified address of the tool shares. They start again with the tool's period, or the next day (UTC) where the uses are counted in total. `showPaywall()` says why.                                                                                               |
| `isPremium` `offline` | `boolean?`                                                            | As above.                                                                                                                                                                                                                                                                                                                            |

**Blocked**

| Field     | Type             |                                                                 |
| --------- | ---------------- | --------------------------------------------------------------- |
| `allowed` | `false`          |                                                                 |
| `blocked` | `true`           | The build is below the minimum version, or on the refused list. |
| `message` | `string \| null` | Your message from Versions.                                     |

## Plan

| Field                    | Type                              |                                                                                 |
| ------------------------ | --------------------------------- | ------------------------------------------------------------------------------- |
| `id`                     | `string`                          | As each plan's card under **Pricing** shows it. What `openPaymentPage()` takes. |
| `name`                   | `string`                          |                                                                                 |
| `billing`                | `'one_time' \| 'subscription'`    |                                                                                 |
| `amountCents` `currency` | `number \| null` `string \| null` | The price, in minor units.                                                      |
| `interval`               | `'month' \| 'year' \| null`       | Subscriptions.                                                                  |

## Access

What the Free plan holds, as set under Pricing.

| Value       |                                                                                     |
| ----------- | ----------------------------------------------------------------------------------- |
| `open`      | Everything, for anyone.                                                             |
| `free_uses` | A number of uses per device (per account where the tool requires one), then a plan. |
| `paid`      | Nothing without a plan. `gate()` refuses with `paid`.                               |

## VersionState

| Field     | Type                                |                                                                                                                |
| --------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| `checked` | `boolean`                           | Toolaby has been asked about this build. The answer is kept across the worker's restarts until the next check. |
| `blocked` | `boolean`                           | This build is below the minimum.                                                                               |
| `reason`  | `'too_old' \| 'denylisted' \| null` |                                                                                                                |
| `message` | `string \| null`                    | Your message from Versions.                                                                                    |
