# Bkper

This is the main entry point of the [bkper-js](https://www.npmjs.com/package/bkper-js) library.

### Constructor

```ts
new Bkper(config?): Bkper;
```

Creates a new Bkper instance with the provided configuration.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `config?` | [`Config`](https://bkper.com/docs/api/bkper-js/interfaces/config.md) | The Config object containing API key and OAuth token providers. If not provided, uses the global configuration set via setConfig(). |

#### Returns

`Bkper`

### getApp()

```ts
getApp(id): Promise;
```

Gets the [[App]] with the specified id.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The App id (agentId) |

#### Returns

`Promise`\<[`App`](https://bkper.com/docs/api/bkper-js/classes/app.md)\>

The retrieved App

***

### getApps()

```ts
getApps(): Promise;
```

Gets all [[Apps]] available for the user.

#### Returns

`Promise`\<[`App`](https://bkper.com/docs/api/bkper-js/classes/app.md)[]\>

The retrieved list of Apps

***

### getBook()

```ts
getBook(
   id, 
   includeAccounts?, 
includeGroups?): Promise;
```

Gets the [[Book]] with the specified bookId from url param.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `id` | `string` | The universal book id - The same bookId param of URL you access at app.bkper.com |
| `includeAccounts?` | `boolean` | Optional parameter to include accounts in the retrieved Book |
| `includeGroups?` | `boolean` | Optional parameter to include groups in the retrieved Book If both includeAccounts and includeGroups are false, the Book will be returned with only the basic information. If includeAccounts is true, the Book will be returned with the accounts and groups. If includeGroups is true, the Book will be returned with the groups. |

#### Returns

`Promise`\<[`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)\>

The retrieved Book

***

### getBooks()

```ts
getBooks(query?): Promise;
```

Gets all [[Books]] the user has access to.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `query?` | `string` | Optional search term to filter books |

#### Returns

`Promise`\<[`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)[]\>

The retrieved list of Books

***

### getCollections()

```ts
getCollections(): Promise;
```

Gets all [[Collections]] the user has access to.

#### Returns

`Promise`\<[`Collection`](https://bkper.com/docs/api/bkper-js/classes/collection.md)[]\>

The retrieved list of Collections

***

### getConfig()

```ts
getConfig(): Config;
```

Gets the current instance configuration.

#### Returns

[`Config`](https://bkper.com/docs/api/bkper-js/interfaces/config.md)

The Config object for this Bkper instance

***

### getTemplates()

```ts
getTemplates(): Promise;
```

Gets all [[Templates]] available for the user.

#### Returns

`Promise`\<[`Template`](https://bkper.com/docs/api/bkper-js/classes/template.md)[]\>

The retrieved list of Templates

***

### getUser()

```ts
getUser(): Promise;
```

Gets the current logged [[User]].

#### Returns

`Promise`\<[`User`](https://bkper.com/docs/api/bkper-js/classes/user.md)\>

The retrieved User

***

### requestBookAccess()

```ts
requestBookAccess(
   bookId, 
   permission, 
message?): Promise<void>;
```

Requests access to a Book the current user cannot access.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `bookId` | `string` | The universal Book id |
| `permission` | [`Permission`](https://bkper.com/docs/api/bkper-js/enumerations/permission.md) | The permission requested in the Book |
| `message?` | `string` | An optional message to the Book owner |

#### Returns

`Promise`\<`void`\>

***

### setConfig()

```ts
static setConfig(config): void;
```

Sets the global API configuration for all Bkper operations.

WARNING: This configuration will be shared and should NOT be used on shared environments.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `config` | [`Config`](https://bkper.com/docs/api/bkper-js/interfaces/config.md) | The Config object containing API key and OAuth token providers |

#### Returns

`void`
