## Installing the npm package
The client can be installed through the npm repository and has a crucial role in transforming packets and seding them to the websocket.
```code
npm i moons-ta-client
```
Once installed we can run some basic scripts in any JS/TS file. I strongly recommend the use of TS, as it is what I will be using in the examples which I provide.

## Let's run a basic script
We will construct a script which will connect to the default TournamentAssistant server and get the information of a tournament.
```ts
import { Response_ResponseType, TAClient } from 'moons-ta-client';

const taClient: TAClient = new TAClient();

taClient.setAuthToken("JWT HERE");

const connectResult = await taClient.connect('server.tournamentassistant.net', '8676');

if (connectResult.details.oneofKind !== "connect" || connectResult.type === Response_ResponseType.Fail) {
    throw new Error(connectResult.details.connect.message);
}

taClient.disconnect();
```
You might notice that we have not actually connected to a tournament or fetched any details. This is intentional, as the connectResult already inclides the current state of the given TA server.

<div class="info-box">
    <span class="material-icons">info</span>
    <div>
        <strong>Note:</strong> As of now, it is not possible to host your own TA server. This is not the intention of the new TA, rather it is meant to centralise everything as it is difficult for everyone to swap servers constantly.
    </div>
</div>

The connectResult has the following schema:
```ts
{
    type: Response_ReaponseType,
    respondingToPacketId: 'Packet-Guid',
    details: {
        oneofKind: 'connect',
        connect: { serverVersion: 1220, message: '', reason: 0, state: Object }
    }
}
```
The state object includes the current list of tournaments, hence they do not need to be fetched again.
The state object looks as follows:
```ts
{
    tournaments: [
        {
            guid: '97a9de91-646b-409e-b6ea-be5ad7b9a27e',
            users: [],
            matches: [],
            qualifiers: [],
            settings: Object,
            server: Object
        }
    ],
    knownServers: [
        {
            name: 'Default Server',
            address: 'server.tournamentassistant.net',
            port: 8675,
            websocketPort: 8676
        }
    ]
}
```
`connectResult.details.connect.knownServers` includes all of the main TA servers which are currently running. In the future it may be that BSWC or some large tournaments opt to run their own TA servers, however this is highly unlikely as it is not the direction TA is going.

`connectResult.details.connect.tournaments` is an array of all of the tournaments on the server which you just connected to. It includes the `guid` of the tournament, which we will use to join it and perform other operations. It also includes the `users` array which is going to play a crucial role in determining players etc. Note that the `users` array includes ALL users. It includes bot users, coordinators, players in matches, players in the lobby, and anyone connected. We will get to the other properties soon, however it is best if you jump to the section with the tournament proto model.
