# PersonalisedToken Model

**Implements [`TokenInterface`](../../src/types/token.ts)**

## Table of Contents

-   [Initiate PersonalisedToken Class](#Initiate-PersonalisedToken-Class)
-   [Properties of a PersonalisedToken](#Properties-of-a-PersonalisedToken)
-   [Prototypes](#Prototypes)
-   [Membership RedeemableToken Response](#Membership-RedeemableToken-Response)

### Initiate PersonalisedToken Class

```js
const token = new PersonalisedToken(tokenData);
```

##### Parameters

| Properties                 | Required | Type   | Description                                             | Example                                  |
| -------------------------- | -------- | ------ | ------------------------------------------------------- | ---------------------------------------- |
| tokenData                  | Yes      | Object | The data to initialise the token with                   |                                          |
| tokenData.id               | Yes      | String | ID of the token                                         | `'00000000-0000-0000-0000-000000000001'` |
| tokenData.emailAddress     | Yes      | String | The email address for the user the token can be used by | `'example@ft.com'`                       |
| tokenData.creationDateTime | Yes      | String | The time that the token was created                     | `'2019-06-27T11:05:20.858+0000'`         |
| tokenData.accessLicenceId  | Yes      | String | A licence ID (used to get access to a licence)          | `'00000000-0000-0000-0000-000000000020'` |
| tokenData.externalUserId   | No       | String | An external user ID per client's numenclature           | `'free format string'` |

### Properties of a PersonalisedToken

| Properties       | Type   | Description                                             | Example                                  |
| ---------------- | ------ | ------------------------------------------------------- | ---------------------------------------- |
| id               | String | ID of the token                                         | `'00000000-0000-0000-0000-000000000001'` |
| emailAddress     | String | The email address for the user the token can be used by | `'example@ft.com'`                       |
| creationDateTime | String | The time that the token was created                     | `'2019-06-27T11:05:20.858+0000'`         |
| accessLicenceId  | String | A licence ID (used to get access to a licence)          | `'00000000-0000-0000-0000-000000000020'` |

### Methods

-   [isValid](#isValid)

#### `.isValid() : boolean`

```js
const token = new PersonalisedToken({…});

token.isValid(); // true
```

##### Parameters

None

##### Returns

`true` (since personalised tokens only exist when they’re valid, this always returns true)

#### `.matchesEmail(email: string) : boolean`

```js
const token = new PersonalisedToken({ emailAddress: 'example@ft.com', … });

token.matchesEmail('example@ft.com'); // true
token.matchesEmail('invalid@ft.com'); // false
```

##### Parameters

| Properties | Required | Type   | Description                | Example            |
| ---------- | -------- | ------ | -------------------------- | ------------------ |
| email      | Yes      | String | the email to match against | `'example@ft.com'` |

None

##### Returns

`boolean` – Whether the email provided matches the email address the token is associated to.
