# createHostedApp

> The same app object, for an app Storeware hosts, with its installations and data.

Source: https://storeware.ai/docs/sdk/hosted

```ts
import { ... } from '@storeware/plugin-sdk';
```

### createHostedApp

The same `StorewareApp` as `createStorewareApp`, for an app Storeware hosts.

```ts
function createHostedApp(env: HostedEnv, options?: HostedAppOptions): StorewareApp<HostedInstallation>
```

### appData

The small store Storeware keeps for one installation of a hosted app: settings, a cursor, what a shop chose. Kept as JSON, so what reads back is what `JSON.stringify` made of what was written.

```ts
function appData(env: HostedEnv, installationId: string): AppData
```

### AppDataError

Something an app asked of its data that would break a limit, found before asking.

```ts
new AppDataError(message: string)
```

### HostedInstallation

An installation of this app, as Storeware's runtime hands it over.

| Name | Type | Description |
| --- | --- | --- |
| `installationId` | `string` |  |
| `storeId` | `string` |  |
| `status` | `'active' \| 'uninstalled'` |  |
| `scopes` | `string[]` |  |
| `webhookSecret` | `string` | Verifies Storeware's signed requests for this installation. |
| `sessionSecret` | `string` | Verifies admin session tokens for this installation. |
| `accessToken` | `string \| null` | A short-lived API token for the shop. Null once uninstalled, and for a moment when the installation has asked for too many this minute. |
| `accessTokenExpiresAt` | `number \| null` | Milliseconds since the epoch. Null with no token. |

### AppDataEntry

One key this app keeps for one installation.

| Name | Type | Description |
| --- | --- | --- |
| `key` | `string` |  |
| `value` | `T` |  |
| `updatedAt` | `string` |  |

### StorewareHost

`env.STOREWARE`: the capability Storeware's runtime hands a hosted app.

| Name | Type | Description |
| --- | --- | --- |
| `installation` | `(by: { storeId: string; } \| { installationId: string; }) => Promise<HostedInstallation \| null>` | An installation of this app, by shop or by id. Null when it is not this app's, or when that shop runs a different release of it: code only ever reaches the shops that run it. |
| `dataGet` | `(installationId: string, key: string) => Promise<AppDataEntry \| null>` |  |
| `dataPut` | `(installationId: string, key: string, value: unknown) => Promise<AppDataEntry>` |  |
| `dataDelete` | `(installationId: string, key: string) => Promise<boolean>` |  |
| `dataList` | `(installationId: string, options?: { prefix?: string; cursor?: string; limit?: number; }) => Promise<{ entries: AppDataEntry[]; cursor: string \| null; }>` |  |

### HostedEnv

The whole `env` of a hosted app. Nothing else is in it.

| Name | Type | Description |
| --- | --- | --- |
| `STOREWARE` | `StorewareHost` |  |
| `STOREWARE_API_URL` | `string` | `https://api.storeware.ai`, the one host the code may always reach. |
| `STOREWARE_APP` | `string` | This app's slug. |
| `STOREWARE_APP_ORIGIN` | `string` | Where this app is served, `https://&lt;slug&gt;.storewareapps.com`. |

### HostedAppOptions

Where a hosted app's API calls and install links point, when not Storeware's own.

| Name | Type | Description |
| --- | --- | --- |
| `apiUrl?` | `string` | Storeware's API. `env.STOREWARE_API_URL` when not given. |
| `adminUrl?` | `string` | Where install links point. Storeware's admin when not given. |
| `fetchImpl?` | `typeof fetch` |  |

### AppData

One installation's data, typed.

| Name | Type | Description |
| --- | --- | --- |
| `get` | `<T = unknown>(key: string) => Promise<AppDataEntry<T> \| null>` |  |
| `put` | `<T = unknown>(key: string, value: T) => Promise<AppDataEntry<T>>` |  |
| `delete` | `(key: string) => Promise<boolean>` |  |
| `list` | `<T = unknown>(options?: { prefix?: string; cursor?: string; limit?: number; }) => Promise<{ entries: AppDataEntry<T>[]; cursor: string \| null; }>` | A page of keys in order, from `cursor` when given. At most 100 a page. |

### APP_DATA_MAX_VALUE_BYTES

The largest value kept under one key, as JSON, in bytes.

```ts
const APP_DATA_MAX_VALUE_BYTES: number
```

### APP_DATA_MAX_KEYS

The most keys one installation may keep.

```ts
const APP_DATA_MAX_KEYS: 1000
```

### APP_DATA_MAX_TOTAL_BYTES

The most bytes one installation may keep, across every key.

```ts
const APP_DATA_MAX_TOTAL_BYTES: number
```

### APP_DATA_MAX_KEY_LENGTH

The longest key.

```ts
const APP_DATA_MAX_KEY_LENGTH: 200
```
