Types
Azion Lib types of the @aziontech/types package for function handlers, the request and its metadata, and the handler context.
The @aziontech/types package is the Azion Lib library of TypeScript types for code that runs on Azion Runtime. It declares the handler shapes of a function, the request with its metadata, and the context a handler receives. The package holds types only: its JavaScript module exports nothing and makes no API call, so you import every name with import type.
Install the package:
The TypeScript samples on this page import their types with import type. The metadata sample runs in Node.js, and the handler samples run inside a function served locally with azion dev.
AzionRuntimeRequestMetadata
The metadata object that AzionRuntimeRequest carries in metadata. The interface declares 26 keys, every one a required string, plus a string index signature that types any other key.
| Property | Type | Required | Description |
|---|---|---|---|
geoip_asn | string | Yes | Autonomous system number. |
geoip_city | string | Yes | City code. |
geoip_city_continent_code | string | Yes | Continent code of the city. |
geoip_city_country_code | string | Yes | Country code of the city. |
geoip_city_country_name | string | Yes | Country name of the city. |
geoip_continent_code | string | Yes | Continent code. |
geoip_country_code | string | Yes | Country code. |
geoip_country_name | string | Yes | Country name. |
geoip_region | string | Yes | Region code. |
geoip_region_name | string | Yes | Region name. |
remote_addr | string | Yes | IP address of the client. |
remote_port | string | Yes | TCP port of the client. |
remote_user | string | Yes | User given in the URL. |
server_protocol | string | Yes | Protocol of the request. |
server_fingerprint | string | Yes | Server TLS fingerprint. |
server_fingerprint_ja4h | string | Yes | Server JA4H fingerprint. |
ssl_cipher | string | Yes | TLS cipher of the session. |
ssl_protocol | string | Yes | TLS protocol of the session. |
client_fingerprint | string | Yes | Client fingerprint. |
client_id | string | Yes | Identifier of the Azion account that owns the workload. |
configuration_id | string | Yes | Identifier of the workload that received the request. |
edge_connector_id | string | Yes | — |
function_id | string | Yes | Identifier of the function that runs for the request. |
http_ssl_ja4 | string | Yes | JA4 TLS fingerprint of the request. |
request_id | string | Yes | Unique ID of the request. |
solution_id | string | Yes | Internal identifier of the solution that handles the request. |
[key: string] | string | No | Any other key of the object. |
An object literal typed as AzionRuntimeRequestMetadata must carry all 26 keys, or tsc stops with error TS2740 and names the missing ones. To type an object that holds some of the keys, wrap the interface in Partial.
This sample builds a metadata object with 16 of the keys:
Output:
AzionRuntimeRequest
The request a module handler receives: the standard Request with a metadata property.
| Property | Type | Required | Description |
|---|---|---|---|
metadata | AzionRuntimeRequestMetadata | Yes | The metadata of the request. |
AzionRuntimeModule
The default export of a function in the module form: an object with a fetch handler, a firewall handler, or both. The module form is the handler shape Handlers recommends.
| Property | Type | Required | Description |
|---|---|---|---|
fetch | (request: AzionRuntimeRequest, env?: null, ctx?: AzionRuntimeCtx) => Promise<Response> | No | The handler Azion Runtime calls for a request. |
firewall | (request: AzionRuntimeRequest, env?: null, ctx?: AzionRuntimeCtx) => Promise<Response> | No | The firewall handler, as the type declares it. |
This function checks its default export against the type with satisfies, and responds with the city of the client:
Served locally with azion dev, where the request carries no metadata, a request returns:
The function logs:
AzionRuntimeCtx
The context that AzionRuntimeModule declares as the third argument of both handlers.
| Property | Type | Required | Description |
|---|---|---|---|
waitUntil | (promise: Promise<unknown>) => void | Yes | Extends the execution until promise settles. |
args | Record<string, unknown> | No | The args of the function instance. |
AzionFetchEvent
The event a listener registered with addEventListener for the fetch type receives. It extends the standard Event.
| Property | Type | Required | Description |
|---|---|---|---|
request | Request & { metadata: AzionRuntimeRequestMetadata } | Yes | The request, with its metadata. |
waitUntil | (promise: Promise<unknown>) => void | Yes | Declared by the type. |
respondWith | (response: Response | Promise<Response>) => void | Yes | Sets the response the function sends to the client. |
In a JavaScript function, a JSDoc comment applies the type to the event. This listener responds with the city of the client:
Served locally with azion dev, the listener returns the same response as the AzionRuntimeModule sample and logs the same three lines:
FetchEventListener
The type of a listener for the fetch event.
| Parameter | Type | Required | Description |
|---|---|---|---|
event | AzionFetchEvent | Yes | The fetch event. |
args | Record<string, unknown> | No | The args the listener receives. |
AzionFirewallEvent
The event type the package declares for a firewall listener. It extends AzionFetchEvent with three methods.
| Property | Type | Required | Description |
|---|---|---|---|
deny | () => void | Yes | Declared by the type. |
drop | () => void | Yes | Declared by the type. |
continue | () => void | Yes | Declared by the type. |
request, waitUntil, respondWith | as in AzionFetchEvent | Yes | Inherited from AzionFetchEvent. |
AzionRuntimeFirewallCtx
The context type the package declares for firewall modules. It extends AzionRuntimeCtx with three methods. AzionRuntimeModule types the ctx of its firewall handler as AzionRuntimeCtx, not as this type.
| Property | Type | Required | Description |
|---|---|---|---|
deny | () => void | Yes | Declared by the type. |
continue | () => void | Yes | Declared by the type. |
drop | () => void | Yes | Declared by the type. |
waitUntil | (promise: Promise<unknown>) => void | Yes | Inherited from AzionRuntimeCtx. |
args | Record<string, unknown> | No | Inherited from AzionRuntimeCtx. |
FirewallEventListener
The type of a listener for the firewall event.
| Parameter | Type | Required | Description |
|---|---|---|---|
event | AzionFirewallEvent | Yes | The firewall event. |
args | Record<string, unknown> | No | The args the listener receives. |
Azion namespace
The package also exports the Azion namespace, which declares the Azion.Storage and Azion.Sql namespaces. For the runtime APIs these names describe, refer to Object Storage API and SQL Database API.