# Application types

The `azion/applications` module exports these types, except where a type says otherwise. Import them with `import type`.

---

## AzionApplicationsClient

The client that [createAzionApplicationClient](/en/documentation/devtools/azion-lib/application/application/#createazionapplicationclient) returns. Each method takes one object.

| Method              | Argument                                                                                              | Returns                                                         |
| ------------------- | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| `createApplication` | `{ data: ApiCreateApplicationPayload; options?: AzionClientOptions }`                                 | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `getApplication`    | `{ applicationId: number; options?: AzionClientOptions }`                                             | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `getApplications`   | `{ params?: AzionApplicationCollectionOptions; options?: AzionClientOptions }`                        | `Promise<AzionApplicationCollectionResponse<AzionApplication>>` |
| `putApplication`    | `{ applicationId: number; data: ApiUpdateApplicationPayload; options?: AzionClientOptions }`          | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `patchApplication`  | `{ applicationId: number; data: Partial<ApiUpdateApplicationPayload>; options?: AzionClientOptions }` | `Promise<AzionApplicationResponse<AzionApplication>>`           |
| `deleteApplication` | `{ applicationId: number; options?: AzionClientOptions }`                                             | `Promise<AzionApplicationResponse<void>>`                       |

---

## CreateAzionApplicationClient

The type of [createAzionApplicationClient](/en/documentation/devtools/azion-lib/application/application/#createazionapplicationclient).

```typescript
type CreateAzionApplicationClient = (config?: Partial<{
  token: string;
  options?: AzionClientOptions;
}>) => AzionApplicationsClient;
```

---

## AzionClientOptions

Request options that every function takes in `options`.

| Property | Type      | Required | Description                                           |
| -------- | --------- | -------- | ----------------------------------------------------- |
| `debug`  | `boolean` | No       | Turns on debug mode.                                  |
| `force`  | `boolean` | No       | Declared by the type. No sample on this page uses it. |

---

## AzionApplicationResponse

The envelope that every function except the list functions returns. For how to read it, refer to [Response envelope](/en/documentation/devtools/azion-lib/application/#response-envelope).

| Property | Type                                     | Required | Description                                                                         |
| -------- | ---------------------------------------- | -------- | ----------------------------------------------------------------------------------- |
| `data`   | `T`                                      | No       | The result of the call.                                                             |
| `error`  | `{ message: string; operation: string }` | No       | The error message and the operation that failed. A successful delete also fills it. |

---

## AzionApplicationCollectionResponse

The envelope that the list functions return.

| Property              | Type                                                     | Required | Description                                               |
| --------------------- | -------------------------------------------------------- | -------- | --------------------------------------------------------- |
| `data`                | `{ count; total_pages; schema_version; links; results }` | No       | The page of results.                                      |
| `data.count`          | `number`                                                 | Yes      | The number of objects in the whole list, not on the page. |
| `data.total_pages`    | `number`                                                 | Yes      | The number of pages.                                      |
| `data.schema_version` | `number`                                                 | Yes      | The schema version of the API response.                   |
| `data.links`          | `{ previous: string \| null; next: string \| null }`     | Yes      | The previous and next pages.                              |
| `data.results`        | `T[]`                                                    | Yes      | The objects on the page.                                  |
| `error`               | `{ message: string; operation: string }`                 | No       | The error message and the operation that failed.          |

---

## AzionApplication

An application: the fields of [ApiBaseApplicationPayload](#apibaseapplicationpayload), plus the ID and the [application methods](/en/documentation/devtools/azion-lib/application/application/#application-methods). `AzionApplicationSettings` is the same shape without the methods.

| Property    | Type                                                    | Required | Description                          |
| ----------- | ------------------------------------------------------- | -------- | ------------------------------------ |
| `id`        | `number`                                                | Yes      | The ID of the application.           |
| `origins`   | `OriginOperations`                                      | Yes      | The origin methods.                  |
| `cache`     | `CacheOperations`                                       | Yes      | The cache setting methods.           |
| `devices`   | `DeviceGroupOperations`                                 | Yes      | The device group methods.            |
| `functions` | `FunctionOperations`                                    | Yes      | The function instance methods.       |
| `rules`     | `{ request: RuleOperations; response: RuleOperations }` | Yes      | The rule methods, one set per phase. |

---

## ApiBaseApplicationPayload

The settings of an application. `name` is required and every other field is optional. `ApiCreateApplicationPayload`, which the module does not export, has the same shape, and `ApiUpdateApplicationPayload` makes every field optional. API v3 refuses `application_acceleration` in a create request.

```typescript
interface ApiBaseApplicationPayload {
  name: string;
  delivery_protocol?: DeliveryProtocol;
  http3?: boolean;
  http_port?: HttpPort[];
  https_port?: HttpsPort[];
  minimum_tls_version?: TlsVersion;
  active?: boolean;
  debug_rules?: boolean;
  application_acceleration?: boolean;
  caching?: boolean;
  device_detection?: boolean;
  edge_firewall?: boolean;
  edge_functions?: boolean;
  image_optimization?: boolean;
  l2_caching?: boolean;
  load_balancer?: boolean;
  raw_logs?: boolean;
  web_application_firewall?: boolean;
  supported_ciphers?: SupportedCiphers;
}
```

The enums of the application settings, which the module exports:

```typescript
enum DeliveryProtocol {
  HTTP = "http",
  HTTPS = "https",
  HTTP_HTTPS = "http,https"
}
enum HttpPort {
  PORT_80 = 80,
  PORT_8008 = 8008,
  PORT_8080 = 8080
}
enum HttpsPort {
  PORT_443 = 443,
  PORT_8443 = 8443,
  PORT_9440 = 9440,
  PORT_9441 = 9441,
  PORT_9442 = 9442,
  PORT_9443 = 9443
}
enum TlsVersion {
  TLS_1_0 = "tls_1_0",
  TLS_1_1 = "tls_1_1",
  TLS_1_2 = "tls_1_2",
  TLS_1_3 = "tls_1_3"
}
enum SupportedCiphers {
  ALL = "all",
  TLSv1_2_2018 = "TLSv1.2_2018",
  TLSv1_2_2019 = "TLSv1.2_2019",
  TLSv1_2_2021 = "TLSv1.2_2021",
  TLSv1_3_2022 = "TLSv1.3_2022"
}
```

---

## ApiListApplicationsParams

Pagination and ordering for [getApplications](/en/documentation/devtools/azion-lib/application/application/#getapplications). `AzionApplicationCollectionOptions`, which the client method takes, has the same keys.

| Property    | Type             | Required | Description                                           |
| ----------- | ---------------- | -------- | ----------------------------------------------------- |
| `page`      | `number`         | No       | The page number.                                      |
| `page_size` | `number`         | No       | The number of applications per page.                  |
| `sort`      | `'name' \| 'id'` | No       | Declared by the type. No sample on this page uses it. |
| `order_by`  | `string`         | No       | Declared by the type. No sample on this page uses it. |

---

## AzionOrigin

An origin, with its `origin_key`. `ApiCreateOriginPayload` takes every field below except `id` and `method`, all required, plus optional `origin_path`, `hmac_authentication`, `hmac_region_name`, `hmac_access_key`, `hmac_secret_key`, `connection_timeout`, and `timeout_between_bytes`. `ApiUpdateOriginRequest` makes every field optional and requires `id`.

```typescript
interface AzionOrigin {
  id: number;
  origin_key: string;
  name: string;
  origin_type: OriginType;
  addresses: Address[];
  origin_protocol_policy: OriginProtocolPolicy;
  is_origin_redirection_enabled: boolean;
  host_header: string;
  method: string;
  origin_path: string;
  connection_timeout: number;
  timeout_between_bytes: number;
  hmac_authentication: boolean;
  hmac_region_name: string;
  hmac_access_key: string;
  hmac_secret_key: string;
}
interface Address {
  address: string;
  weight?: number | null;
  server_role?: ServerRole;
  is_active?: boolean;
}
```

The enums of an origin, which the module does not export:

```typescript
enum OriginType {
  SINGLE_ORIGIN = "single_origin",
  LOAD_BALANCER = "load_balancer"
}
enum OriginProtocolPolicy {
  PRESERVE = "preserve",
  HTTP = "http",
  HTTPS = "https"
}
enum ServerRole {
  PRIMARY = "primary",
  BACKUP = "backup"
}
```

---

## AzionCacheSetting

A cache setting: the fields of [ApiBaseCacheSettingPayload](#apibasecachesettingpayload), plus its `id` (`number`).

---

## ApiBaseCacheSettingPayload

The settings of a cache setting. `name` is required and every other field is optional. `ApiUpdateCacheSettingPayload` makes every field optional.

```typescript
interface ApiBaseCacheSettingPayload {
  name: string;
  browser_cache_settings?: BrowserCacheSettings;
  browser_cache_settings_maximum_ttl?: number;
  cdn_cache_settings?: CdnCacheSettings;
  cdn_cache_settings_maximum_ttl?: number;
  cache_by_query_string?: CacheByQueryString;
  query_string_fields?: string[];
  enable_query_string_sort?: boolean;
  cache_by_cookies?: CacheByCookies;
  cookie_names?: string[];
  adaptive_delivery_action?: AdaptiveDeliveryAction;
  device_group?: string[];
  enable_caching_for_post?: boolean;
  l2_caching_enabled?: boolean;
  is_slice_configuration_enabled?: boolean;
  is_slice_edge_caching_enabled?: boolean;
  is_slice_l2_caching_enabled?: boolean;
  slice_configuration_range?: number;
  enable_caching_for_options?: boolean;
  enable_stale_cache?: boolean;
  l2_region?: string | null;
}
```

The enums of a cache setting, which the module does not export:

```typescript
enum BrowserCacheSettings {
  HONOR = "honor",
  OVERRIDE = "override",
  IGNORE = "ignore"
}
enum CdnCacheSettings {
  HONOR = "honor",
  OVERRIDE = "override"
}
enum CacheByQueryString {
  IGNORE = "ignore",
  WHITELIST = "whitelist",
  BLACKLIST = "blacklist",
  ALL = "all"
}
enum CacheByCookies {
  IGNORE = "ignore",
  WHITELIST = "whitelist",
  BLACKLIST = "blacklist",
  ALL = "all"
}
enum AdaptiveDeliveryAction {
  IGNORE = "ignore",
  OPTIMIZE = "optimize"
}
```

---

## AzionDeviceGroup

A device group. `ApiCreateDeviceGroupPayload` and `ApiUpdateDeviceGroupPayload`, which the module does not export, take `name` and `user_agent`, both required on create and optional on update.

| Property     | Type     | Required | Description                                                           |
| ------------ | -------- | -------- | --------------------------------------------------------------------- |
| `id`         | `number` | Yes      | The ID of the device group.                                           |
| `name`       | `string` | Yes      | The name of the group, with no spaces and no hyphens.                 |
| `user_agent` | `string` | Yes      | The regular expression compared with the `User-Agent` request header. |

---

## AzionFunctionInstance

A function instance. The API returns the four fields below, as the samples show.

| Property           | Type                      | Description                               |
| ------------------ | ------------------------- | ----------------------------------------- |
| `id`               | `number`                  | The ID of the function instance.          |
| `edge_function_id` | `number`                  | The ID of the function the instance runs. |
| `name`             | `string`                  | The name of the function instance.        |
| `args`             | `Record<string, unknown>` | The arguments the function receives.      |

The type declares other fields: `id` plus the fields of `ApiBaseFunctionInstancePayload`, which are `name`, `code`, `language` (`'JavaScript'`), `initiator_type` (`'edge_application' \| 'edge_firewall'`), `active`, and `json_args`. `ApiUpdateFunctionInstancePayload` makes those fields optional.

---

## ApiCreateFunctionInstancePayload

The payload of [createFunctionInstance](/en/documentation/devtools/azion-lib/application/function-instance/#createfunctioninstance). The module does not export this type.

| Property           | Type                      | Required | Description                                           |
| ------------------ | ------------------------- | -------- | ----------------------------------------------------- |
| `name`             | `string`                  | Yes      | The name of the function instance.                    |
| `edge_function_id` | `number`                  | Yes      | The ID of the function the instance runs.             |
| `args`             | `Record<string, unknown>` | Yes      | The arguments the function receives.                  |
| `active`           | `boolean`                 | No       | Declared by the type. No sample on this page uses it. |

---

## AzionRule

A rule: the fields of [ApiCreateRulePayload](#apicreaterulepayload), plus `id` (`number`). `AzionRule` declares `is_active` and `order` as required, and every rule in the samples carries both.

---

## ApiCreateRulePayload

The payload of [createRule](/en/documentation/devtools/azion-lib/application/rule/#createrule). `ApiUpdateRulePayload` makes every field optional.

| Property      | Type                      | Required | Description                                                                                                                                                         |
| ------------- | ------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `name`        | `string`                  | Yes      | The name of the rule.                                                                                                                                               |
| `phase`       | `'request' \| 'response'` | Yes      | The phase of the rule.                                                                                                                                              |
| `criteria`    | `Criterion[][]`           | Yes      | The condition groups. Each `Criterion` holds `variable` (`string`), `operator` (`string`), `conditional` (`'if' \| 'and' \| 'or'`), and `input_value` (`string`).   |
| `behaviors`   | `Behavior[]`              | Yes      | The actions. Each `Behavior` holds `name` (`string`) and an optional `target`: a `string`, `null`, or `{ captured_array: string; subject: string; regex: string }`. |
| `is_active`   | `boolean`                 | No       | Whether the rule is active. A rule created without it is active.                                                                                                    |
| `order`       | `number`                  | No       | The position of the rule in its phase.                                                                                                                              |
| `description` | `string`                  | No       | The description of the rule.                                                                                                                                        |

---

## List parameters

The `params` object of each sub-resource list function declares these keys. The samples send only `page` and `page_size`. `ApiListDeviceGroupsParams` is not exported.

| Type                             | Declared keys                                                                                     |
| -------------------------------- | ------------------------------------------------------------------------------------------------- |
| `ApiListOriginsParams`           | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`), `filter`             |
| `ApiListCacheSettingsParams`     | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`)                       |
| `ApiListDeviceGroupsParams`      | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`)                       |
| `ApiListFunctionInstancesParams` | `page`, `page_size`, `sort` (`'name' \| 'id'`), `order` (`'asc' \| 'desc'`), `order_by`, `filter` |
| `ApiListRulesParams`             | `page`, `page_size`, `sort` (`string`), `order` (`'asc' \| 'desc'`), `filter`                     |

---

## Related resources

- [Azion Lib](/en/documentation/devtools/azion-lib.md): The Azion Lib modules and the npm package each one ships in.
- [Applications](/en/documentation/devtools/azion-lib/application.md): The module's authentication, its response envelope, and the errors its functions report.
- [Application functions](/en/documentation/devtools/azion-lib/application/application.md): The functions that create, read, and update the application these types describe.
- [Client](/en/documentation/devtools/azion-lib/client.md): The client that exposes Applications next to Storage, SQL, Purge, Domains, and AI.
