azion
Version:
Azion Packages for Edge Computing.
1,351 lines (1,337 loc) • 118 kB
TypeScript
declare const RULE_OPERATORS_WITH_VALUE: readonly ["is_equal", "is_not_equal", "starts_with", "does_not_start_with", "matches", "does_not_match"];
declare const RULE_OPERATORS_WITHOUT_VALUE: readonly ["exists", "does_not_exist"];
declare const RULE_CONDITIONALS: readonly ["if", "and", "or"];
declare const RULE_VARIABLES: readonly ("device_group" | "request" | "args" | "domain" | "geoip_city" | "geoip_city_continent_code" | "geoip_city_country_code" | "geoip_city_country_name" | "geoip_continent_code" | "geoip_country_code" | "geoip_country_name" | "geoip_region" | "geoip_region_name" | "host" | "remote_addr" | "remote_port" | "remote_user" | "request_body" | "request_method" | "request_uri" | "scheme" | "uri" | "server_addr" | "server_port" | "ssl_client_fingerprint" | "ssl_client_escaped_cert" | "ssl_client_s_dn" | "ssl_client_s_dn_parsed" | "ssl_client_cert" | "ssl_client_i_dn" | "ssl_client_serial" | "ssl_client_v_end" | "ssl_client_v_remain" | "ssl_client_v_start" | "ssl_client_verify" | "sent_http_name" | "status" | "tcpinfo_rtt" | "upstream_addr" | "upstream_status")[];
declare const FIREWALL_RATE_LIMIT_TYPES: readonly ["second", "minute"];
declare const FIREWALL_RATE_LIMIT_BY: readonly ["clientIp", "global"];
declare const FIREWALL_WAF_MODES: readonly ["learning", "blocking"];
type RuleOperatorWithValue = (typeof RULE_OPERATORS_WITH_VALUE)[number];
type RuleOperatorWithoutValue = (typeof RULE_OPERATORS_WITHOUT_VALUE)[number];
type RuleConditional = (typeof RULE_CONDITIONALS)[number];
type WithDollarBraces<T extends string> = `\${${T}}` | T;
type DynamicVariable = `arg_${string}` | `cookie_${string}` | `http_${string}` | `sent_http_${string}` | `upstream_cookie_${string}` | `upstream_http_${string}`;
type RuleVariable = WithDollarBraces<(typeof RULE_VARIABLES)[number]> | DynamicVariable | WithDollarBraces<DynamicVariable>;
type FirewallRateLimitType = (typeof FIREWALL_RATE_LIMIT_TYPES)[number];
type FirewallRateLimitBy = (typeof FIREWALL_RATE_LIMIT_BY)[number];
type FirewallWafMode = (typeof FIREWALL_WAF_MODES)[number];
declare const NETWORK_LIST_TYPES: readonly ["ip_cidr", "asn", "countries"];
type NetworkListType = (typeof NETWORK_LIST_TYPES)[number];
declare const WAF_MODE: readonly ["learning", "blocking", "counting"];
type WafMode = (typeof WAF_MODE)[number];
declare const WAF_SENSITIVITY: readonly ["low", "medium", "high"];
type WafSensitivity = (typeof WAF_SENSITIVITY)[number];
/**
* Domain configuration for Azion.
*/
type AzionDomain$1 = {
/** Domain name */
name: string;
/** Indicates if access is restricted to CNAME only */
cnameAccessOnly?: boolean;
/** List of CNAMEs associated with the domain */
cnames?: string[];
/** Associated edge application ID */
id?: number;
/** Associated edge appliaction ID */
edgeApplicationId?: number;
/** Associated edge firewall ID */
edgeFirewallId?: number;
/** Digital certificate ID */
digitalCertificateId?: string | number | null;
/** Indicates if the domain is active */
active?: boolean;
/** Mutual TLS configuration */
mtls?: {
/** Verification mode for MTLS */
verification: 'enforce' | 'permissive';
/** ID of the trusted CA certificate */
trustedCaCertificateId: number;
/** List of CRL (Certificate Revocation List) IDs */
crlList?: number[];
};
};
/**
* Origin configuration for Azion.
*/
type AzionOrigin$1 = {
/** Origin ID */
id?: number;
/** Origin key */
key?: string;
/** Origin name */
name: string;
/** Origin type */
type: string;
/** Bucket name for S3-like origins */
bucket?: string | null;
/** Prefix for S3-like origins */
prefix?: string | null;
/** Addresses for the origin */
addresses?: string[] | {
/** Address of the origin */
address: string;
/** Weight for load balancing */
weight?: number;
}[];
/** Host header to be sent to the origin */
hostHeader?: string;
/** Protocol policy for communicating with the origin */
protocolPolicy?: 'http' | 'https' | 'preserve';
/** Indicates if redirection should be used */
redirection?: boolean;
/** Load balancing method */
method?: 'ip_hash' | 'least_connections' | 'round_robin';
/** Path to be appended to the origin address */
path?: string;
/** Connection timeout in seconds */
connectionTimeout?: number;
/** Timeout between bytes in seconds */
timeoutBetweenBytes?: number;
/** HMAC authentication configuration */
hmac?: {
/** AWS region */
region: string;
/** AWS access key */
accessKey: string;
/** AWS secret key */
secretKey: string;
};
};
/**
* Cache configuration for Azion.
*/
type AzionCache = {
/** Cache name */
name: string;
/** Indicates if stale content should be served */
stale?: boolean;
/** Indicates if query string parameters should be sorted */
queryStringSort?: boolean;
/** HTTP methods to be cached */
methods?: {
/** Cache POST requests */
post?: boolean;
/** Cache OPTIONS requests */
options?: boolean;
};
/** Browser cache settings */
browser?: {
/** Maximum age for browser cache in seconds */
maxAgeSeconds: number | string;
};
/** Edge cache settings */
edge?: {
/** Maximum age for edge cache in seconds */
maxAgeSeconds: number | string;
};
/** Cache by cookie configuration */
cacheByCookie?: {
/** Cookie caching option */
option: 'ignore' | 'varies' | 'whitelist' | 'blacklist';
/** List of cookies to be considered */
list?: string[];
};
/** Cache by query string configuration */
cacheByQueryString?: {
/** Query string caching option */
option: 'ignore' | 'varies' | 'whitelist' | 'blacklist';
/** List of query string parameters to be considered */
list?: string[];
};
};
type AzionRuleCriteriaBase = {
/** Variable to be evaluated */
variable: RuleVariable;
/** Conditional type */
conditional: RuleConditional;
};
type AzionRuleCriteriaWithValue = AzionRuleCriteriaBase & {
/** Operator for comparison that requires input value */
operator: RuleOperatorWithValue;
/** Input value for comparison */
inputValue: string;
};
type AzionRuleCriteriaWithoutValue = AzionRuleCriteriaBase & {
/** Operator for comparison that doesn't require input value */
operator: RuleOperatorWithoutValue;
};
type AzionRuleCriteria = AzionRuleCriteriaWithValue | AzionRuleCriteriaWithoutValue;
/**
* Request rule configuration for Azion.
*/
type AzionRequestRule = {
/** Rule name */
name: string;
/** Rule description */
description?: string;
/** Indicates if the rule is active */
active?: boolean;
/** Match criteria for the rule */
match?: string;
/** Variable to be used in the match */
variable?: RuleVariable;
/** Array of criteria for complex conditions */
criteria?: AzionRuleCriteria[];
/** Behavior to be applied when the rule matches */
behavior?: {
/** Set a new origin */
setOrigin?: {
/** Origin name */
name: string;
/** Origin type */
type: string;
};
/** Rewrite the request */
rewrite?: string;
/** Set headers */
setHeaders?: string[];
/** Bypass cache */
bypassCache?: boolean | null;
/** Force HTTPS */
httpToHttps?: boolean | null;
/** Redirect with 301 status */
redirectTo301?: string | null;
/** Redirect with 302 status */
redirectTo302?: string | null;
/** Forward cookies */
forwardCookies?: boolean | null;
/** Set a cookie */
setCookie?: string | null;
/** Deliver the content */
deliver?: boolean | null;
/** Deny */
deny?: boolean | null;
/** No content */
noContent?: boolean | null;
/** enable GZIP compression */
enableGZIP?: boolean | null;
/** Filter cookie */
filterCookie?: string | null;
/** Filter header */
filterHeader?: string | null;
/** Optimize images */
optimizeImages?: boolean | null;
/** Capture configuration */
capture?: {
/** Match pattern */
match: string;
/** Captured value */
captured: string;
/** Subject to capture from */
subject: string;
};
/** Run a serverless function */
runFunction?: {
/** Function path */
path: string;
/** Function name */
name?: string | null;
};
/** Set cache configuration */
setCache?: string | {
/** Cache name */
name: string;
/** Browser cache TTL */
browser_cache_settings_maximum_ttl?: number | null;
/** CDN cache TTL */
cdn_cache_settings_maximum_ttl?: number | null;
};
};
};
/**
* Response rule configuration for Azion.
*/
type AzionResponseRule = {
/** Rule name */
name: string;
/** Rule description */
description?: string;
/** Indicates if the rule is active */
active?: boolean;
/** Match criteria for the rule */
match?: string;
/** Variable to be used in the match */
variable?: RuleVariable;
/** Array of criteria for complex conditions */
criteria?: AzionRuleCriteria[];
/** Behavior to be applied when the rule matches */
behavior?: {
/** Set a cookie */
setCookie?: string | null;
/** Set headers */
setHeaders?: string[];
/** Deliver the content */
deliver?: boolean | null;
/** Capture configuration */
capture?: {
/** Match pattern */
match: string;
/** Captured value */
captured: string;
/** Subject to capture from */
subject: string;
};
/** Enable GZIP compression */
enableGZIP?: boolean | null;
/** Filter a cookie */
filterCookie?: string | null;
/** Filter a header */
filterHeader?: string | null;
/** Run a serverless function */
runFunction?: {
/** Function path */
path: string;
/** Function name */
name?: string | null;
};
/** Redirect with 301 status */
redirectTo301?: string | null;
/** Redirect with 302 status */
redirectTo302?: string | null;
};
};
/**
* Rules configuration for Azion.
*/
type AzionRules = {
/** Request rules */
request?: AzionRequestRule[];
/** Response rules */
response?: AzionResponseRule[];
};
/**
* Purge configuration for Azion.
*/
type AzionPurge$1 = {
/** Purge type */
type: 'url' | 'cachekey' | 'wildcard';
/** URLs to be purged */
urls: string[];
/** HTTP method for purge request */
method?: 'delete';
/** Cache layer to be purged */
layer?: 'edge_caching' | 'l2_caching';
};
type AzionBuild = {
/** JavaScript bundler to be used for building the application */
builder?: 'webpack' | 'esbuild';
/** Entry file for the build */
entry?: string;
/** Preset configuration e.g next */
preset?: {
name: string;
};
/** MemoryFS configuration */
memoryFS?: {
/** List of directories to be injected */
injectionDirs: string[];
/** Remove path prefix */
removePathPrefix: string;
};
/** Polyfills enabled */
polyfills?: boolean;
/** if true will use the owner worker with addEventListener */
worker?: boolean;
/** Custom configuration to bundlers e.g minify: true */
custom?: Record<string, any>;
};
/**
* Network list configuration for Azion.
*/
type AzionNetworkList = {
/** Network list identifier */
id: number;
/** Network list type */
listType: NetworkListType;
/** List of networks */
listContent: string[] | number[];
};
/**
* Main configuration type for Azion.
*/
type AzionConfig = {
/** Build configuration */
build?: AzionBuild;
/** Domain configuration */
domain?: AzionDomain$1;
/** Origin configurations */
origin?: AzionOrigin$1[];
/** Cache configurations */
cache?: AzionCache[];
/** Rules configuration */
rules?: AzionRules;
/** Purge configurations */
purge?: AzionPurge$1[];
/** Firewall configuration */
firewall?: AzionFirewall;
/** Network list configurations */
networkList?: AzionNetworkList[];
/** WAF configuration */
waf?: AzionWaf[];
};
/**
* Firewall behavior configuration for Azion.
*/
type AzionFirewallBehavior = {
/** Run a serverless function */
runFunction?: {
/** Function path */
path: string;
};
/** Set WAF ruleset */
setWafRuleset?: {
/** WAF mode */
wafMode: FirewallWafMode;
/** WAF ID */
wafId: string;
};
/** Set rate limit */
setRateLimit?: {
/** Rate limit type */
type: FirewallRateLimitType;
/** Rate limit by */
limitBy: FirewallRateLimitBy;
/** Average rate limit */
averageRateLimit: string;
/** Maximum burst size */
maximumBurstSize: string;
};
/** Deny the request */
deny?: boolean;
/** Drop the request */
drop?: boolean;
/** Set custom response */
setCustomResponse?: {
/** HTTP status code (200-499) */
statusCode: number | string;
/** Response content type */
contentType: string;
/** Response content body */
contentBody: string;
};
};
type AzionFirewallCriteriaBase = {
/** Variable to be evaluated */
variable: RuleVariable;
/** Conditional type */
conditional: RuleConditional;
};
type AzionFirewallCriteriaWithValue = AzionFirewallCriteriaBase & {
/** Operator for comparison that requires input value */
operator: RuleOperatorWithValue;
/** Input value for comparison */
inputValue: string;
};
type AzionFirewallCriteriaWithoutValue = AzionFirewallCriteriaBase & {
/** Operator for comparison that doesn't require input value */
operator: RuleOperatorWithoutValue;
};
type AzionFirewallCriteria = AzionFirewallCriteriaWithValue | AzionFirewallCriteriaWithoutValue;
/**
* Firewall rule configuration for Azion.
*/
type AzionFirewallRule = {
/** Rule name */
name: string;
/** Rule description */
description?: string;
/** Indicates if the rule is active */
active?: boolean;
/** Match criteria for the rule */
match?: string;
/** Variable to be used in the match */
variable?: RuleVariable;
/** Array of criteria for complex conditions */
criteria?: AzionFirewallCriteria[];
/** Behavior to be applied when the rule matches */
behavior: AzionFirewallBehavior;
};
/**
* Firewall configuration for Azion.
*/
type AzionFirewall = {
/** Firewall name */
name: string;
/** List of domains */
domains?: string[];
/** Indicates if the firewall is active */
active?: boolean;
/** Indicates if Edge Functions are enabled */
edgeFunctions?: boolean;
/** Indicates if Network Protection is enabled */
networkProtection?: boolean;
/** Indicates if WAF is enabled */
waf?: boolean;
/** Variable to be used in the match */
variable?: RuleVariable;
/** List of firewall rules */
rules?: AzionFirewallRule[];
/** Debug mode */
debugRules?: boolean;
};
type AzionWaf = {
/** WAF ID */
id?: number;
/** WAF name */
name: string;
/** WAF mode */
mode: WafMode;
/** WAF active */
active: boolean;
/** WAF sqlInjection */
sqlInjection?: {
sensitivity: WafSensitivity;
};
/** WAF remoteFileInclusion */
remoteFileInclusion?: {
sensitivity: WafSensitivity;
};
/** WAF directoryTraversal */
directoryTraversal?: {
sensitivity: WafSensitivity;
};
/** WAF crossSiteScripting */
crossSiteScripting?: {
sensitivity: WafSensitivity;
};
/** WAF evadingTricks */
evadingTricks?: {
sensitivity: WafSensitivity;
};
/** WAF fileUpload */
fileUpload?: {
sensitivity: WafSensitivity;
};
/** WAF unwantedAccess */
unwantedAccess?: {
sensitivity: WafSensitivity;
};
/** WAF identifiedAttack */
identifiedAttack?: {
sensitivity: WafSensitivity;
};
/** WAF bypassAddress */
bypassAddresses?: string[];
};
/**
* Converts a JSON string to an AzionConfig object.
* @param {string} config - The JSON string to be converted.
* @returns {AzionConfig} The AzionConfig object.
* @throws {Error} Throws an error if the provided JSON string is invalid.
*
* @example
* const config = `{
* "origin": [
* {
* "name": "My Origin",
* "origin_type": "single_origin",
* "origin_path": '',
* "method": 'ip_hash',
* "addresses": [
* {
* "address": "origin.example.com",
* "weight": 100
* }
* ],
* }
* ]
*}`;
* const configObject = convertJsonConfigToObject(config);
* console.log(configObject);
*
*/
declare function convertJsonConfigToObject(config: string): AzionConfig;
/**
* Processes the provided configuration object and returns a JSON object that can be used to create or update an Azion CDN configuration.
* @param inputConfig AzionConfig
* @returns
*
* @example
* const config = {
* origin: [
* {
* name: 'My Origin',
* type: 'single_origin',
* addresses: [
* {
* address: 'origin.example.com',
* weight: 100,
* },
* ],
* protocolPolicy: 'https',
* },
* ],
* }
* const payloadCDN = processConfig(config);
* console.log(payloadCDN);
*/
declare function processConfig(inputConfig: AzionConfig): any;
/**
* Configures and validates the options for the Azion Edge Application.
*
* @param {AzionConfig} config - The configuration object for the Azion Edge Application.
*
* @param {Object} [config.build] - Configuration for the build.
* @param {string} config.build.builder - Bundler to use for the build.
* @param {string} config.build.entry - Entry file for the build.
* @param {Object} config.build.preset - Preset configuration for the build.
* @param {string} config.build.preset.name - Name of the preset.
* @param {Object} [config.build.memoryFS] - Configuration for the MemoryFS.
* @param {string[]} config.build.memoryFS.injectionDirs - List of directories to inject.
* @param {string} config.build.memoryFS.removePathPrefix - Path prefix to remove.
* @param {boolean} [config.build.polyfills] - Whether to enable polyfills.
* @param {boolean} [config.build.worker] - Whether to use the owner worker with addEventListener.
* @param {Object} [config.build.custom] - Custom configuration for the bundler.
* @param {Object} [config.build.custom.*] - Custom configuration options for the bundler.
* @param {Object} [config.domain] - Configuration for the domain.
* @param {string} config.domain.name - The domain name.
* @param {boolean} [config.domain.cnameAccessOnly] - Whether to restrict access only to CNAMEs.
* @param {string[]} [config.domain.cnames] - List of CNAMEs for the domain.
* @param {number} [config.domain.Id] - ID of the edge application.
* @param {number} [config.domain.edgeFirewallId] - ID of the edge firewall.
* @param {string|number|null} [config.domain.digitalCertificateId] - ID of the digital certificate.
* @param {Object} [config.domain.mtls] - Configuration for mTLS.
* @param {('enforce'|'permissive')} config.domain.mtls.verification - mTLS verification mode.
* @param {number} config.domain.mtls.trustedCaCertificateId - ID of the trusted CA certificate.
* @param {number[]} [config.domain.mtls.crlList] - List of Certificate Revocation Lists (CRLs).
*
* @param {Object[]} [config.origin] - Array of origin configurations.
* @param {number} [config.origin[].id] - ID of the origin.
* @param {string} [config.origin[].key] - Key for the origin.
* @param {string} config.origin[].name - Name of the origin.
* @param {string} config.origin[].type - Type of the origin (e.g., 'single_origin', 'load_balancer').
* @param {string} [config.origin[].bucket] - Bucket name for storage origins.
* @param {string} [config.origin[].prefix] - Prefix for storage origins.
* @param {Array<string|{address: string, weight?: number}>} [config.origin[].addresses] - Array of addresses for the origin.
* @param {string} [config.origin[].hostHeader] - Custom host header.
* @param {('http'|'https'|'preserve')} [config.origin[].protocolPolicy] - Protocol policy for the origin.
* @param {boolean} [config.origin[].redirection] - Whether to enable redirection.
* @param {('ip_hash'|'least_connections'|'round_robin')} [config.origin[].method] - Load balancing method.
* @param {string} [config.origin[].path] - Path for the origin.
* @param {number} [config.origin[].connectionTimeout] - Connection timeout in seconds.
* @param {number} [config.origin[].timeoutBetweenBytes] - Timeout between bytes in seconds.
* @param {Object} [config.origin[].hmac] - HMAC configuration for the origin.
* @param {string} config.origin[].hmac.region - HMAC region.
* @param {string} config.origin[].hmac.accessKey - HMAC access key.
* @param {string} config.origin[].hmac.secretKey - HMAC secret key.
*
* @param {Object[]} [config.cache] - Array of cache configurations.
* @param {string} config.cache[].name - Name of the cache configuration.
* @param {boolean} [config.cache[].stale] - Whether to allow stale content.
* @param {boolean} [config.cache[].queryStringSort] - Whether to sort query string parameters.
* @param {Object} [config.cache[].methods] - HTTP methods to cache.
* @param {boolean} [config.cache[].methods.post] - Whether to cache POST requests.
* @param {boolean} [config.cache[].methods.options] - Whether to cache OPTIONS requests.
* @param {Object} [config.cache[].browser] - Browser cache settings.
* @param {number|string} config.cache[].browser.maxAgeSeconds - Maximum age for browser cache in seconds.
* @param {Object} [config.cache[].edge] - Edge cache settings.
* @param {number|string} config.cache[].edge.maxAgeSeconds - Maximum age for edge cache in seconds.
* @param {Object} [config.cache[].cacheByCookie] - Cache by cookie settings.
* @param {('ignore'|'varies'|'whitelist'|'blacklist')} config.cache[].cacheByCookie.option - Cache by cookie option.
* @param {string[]} [config.cache[].cacheByCookie.list] - List of cookies to use for caching.
* @param {Object} [config.cache[].cacheByQueryString] - Cache by query string settings.
* @param {('ignore'|'varies'|'whitelist'|'blacklist')} config.cache[].cacheByQueryString.option - Cache by query string option.
* @param {string[]} [config.cache[].cacheByQueryString.list] - List of query string parameters to use for caching.
*
* @param {Object} [config.rules] - Rules configuration.
* @param {Object[]} [config.rules.request] - Array of request rules.
* @param {string} config.rules.request[].name - Name of the request rule.
* @param {string} [config.rules.request[].description] - Description of the request rule.
* @param {boolean} [config.rules.request[].active] - Whether the rule is active.
* @param {string} config.rules.request[].match - Match condition for the rule.
* @param {string} [config.rules.request[].variable] - Variable to match against.
* @param {Object} [config.rules.request[].behavior] - Behavior to apply when the rule matches.
* @param {Object} [config.rules.request[].behavior.setOrigin] - Set origin behavior.
* @param {string} config.rules.request[].behavior.setOrigin.name - Name of the origin to set.
* @param {string} config.rules.request[].behavior.setOrigin.type - Type of the origin to set.
* @param {string} [config.rules.request[].behavior.rewrite] - URL rewrite behavior.
* @param {string[]} [config.rules.request[].behavior.setHeaders] - Headers to set.
* @param {boolean|null} [config.rules.request[].behavior.bypassCache] - Whether to bypass cache.
* @param {boolean|null} [config.rules.request[].behavior.httpToHttps] - Redirect HTTP to HTTPS.
* @param {string|null} [config.rules.request[].behavior.redirectTo301] - Redirect with 301 status.
* @param {string|null} [config.rules.request[].behavior.redirectTo302] - Redirect with 302 status.
* @param {boolean|null} [config.rules.request[].behavior.forwardCookies] - Whether to forward cookies.
* @param {string|null} [config.rules.request[].behavior.setCookie] - Set cookie behavior.
* @param {boolean|null} [config.rules.request[].behavior.deliver] - Whether to deliver the response.
* @param {Object} [config.rules.request[].behavior.capture] - Capture behavior.
* @param {string} config.rules.request[].behavior.capture.match - Capture match condition.
* @param {string} config.rules.request[].behavior.capture.captured - Captured content.
* @param {string} config.rules.request[].behavior.capture.subject - Subject for capture.
* @param {Object} [config.rules.request[].behavior.runFunction] - Run a custom function.
* @param {string} config.rules.request[].behavior.runFunction.path - Path to the function.
* @param {string|null} [config.rules.request[].behavior.runFunction.name] - Name of the function.
* @param {string|Object} [config.rules.request[].behavior.setCache] - Set cache behavior.
* @param {string} config.rules.request[].behavior.setCache.name - Cache name.
* @param {number|null} [config.rules.request[].behavior.setCache.browser_cache_settings_maximum_ttl] - Browser cache maximum TTL.
* @param {number|null} [config.rules.request[].behavior.setCache.cdn_cache_settings_maximum_ttl] - CDN cache maximum TTL.
*
* @param {Object[]} [config.rules.response] - Array of response rules.
* @param {string} config.rules.response[].name - Name of the response rule.
* @param {string} [config.rules.response[].description] - Description of the response rule.
* @param {boolean} [config.rules.response[].active] - Whether the rule is active.
* @param {string} config.rules.response[].match - Match condition for the rule.
* @param {string} [config.rules.response[].variable] - Variable to match against.
* @param {Object} [config.rules.response[].behavior] - Behavior to apply when the rule matches.
* @param {string|null} [config.rules.response[].behavior.setCookie] - Set cookie behavior.
* @param {string[]} [config.rules.response[].behavior.setHeaders] - Headers to set.
* @param {boolean|null} [config.rules.response[].behavior.deliver] - Whether to deliver the response.
* @param {Object} [config.rules.response[].behavior.capture] - Capture behavior.
* @param {string} config.rules.response[].behavior.capture.match - Capture match condition.
* @param {string} config.rules.response[].behavior.capture.captured - Captured content.
* @param {string} config.rules.response[].behavior.capture.subject - Subject for capture.
* @param {boolean|null} [config.rules.response[].behavior.enableGZIP] - Enable GZIP compression.
* @param {string|null} [config.rules.response[].behavior.filterCookie] - Filter cookies.
* @param {string|null} [config.rules.response[].behavior.filterHeader] - Filter headers.
* @param {Object} [config.rules.response[].behavior.runFunction] - Run a custom function.
* @param {string} config.rules.response[].behavior.runFunction.path - Path to the function.
* @param {string|null} [config.rules.response[].behavior.runFunction.name] - Name of the function.
* @param {string|null} [config.rules.response[].behavior.redirectTo301] - Redirect with 301 status.
* @param {string|null} [config.rules.response[].behavior.redirectTo302] - Redirect with 302 status.
*
* @param {Object[]} [config.networkList] - Array of network list configurations.
* @param {number} config.networkList[].id - ID of the network list.
* @param {string} config.networkList[].listType - Type of the network list.
* @param {string[]} config.networkList[].listContent - Content of the network list.
*
* @param {Object[]} [config.purge] - Array of purge configurations.
* @param {('url'|'cachekey'|'wildcard')} config.purge[].type - Type of purge operation.
* @param {string[]} config.purge[].urls - URLs to purge.
* @param {('delete')} [config.purge[].method] - HTTP method to use for purging.
* @param {('edge_caching'|'l2_caching')} [config.purge[].layer] - Caching layer to target.
*
* @returns {AzionConfig} The validated configuration object.
*
* @example
* const config = AzionConfig({
* build: {
* builder: 'webpack',
* preset: {
* name: 'react',
* },
* polyfills: true,
* },
* domain: {
* name: 'example.com',
* cnameAccessOnly: false,
* cnames: ['www.example.com', 'cdn.example.com'],
* Id: 12345,
* edgeFirewallId: 67890,
* digitalCertificateId: null,
* mtls: {
* verification: 'enforce',
* trustedCaCertificateId: 98765,
* },
* },
* origin: [
* {
* name: 'My Origin',
* type: 'single_origin',
* addresses: [
* {
* address: 'origin.example.com',
* weight: 100,
* },
* ],
* protocolPolicy: 'https',
* },
* ],
* cache: [
* {
* name: 'Default Cache',
* browser: {
* maxAgeSeconds: 3600,
* },
* edge: {
* maxAgeSeconds: 7200,
* },
* },
* ],
* rules: {
* request: [
* {
* name: 'Example Rule',
* match: 'path',
* behavior: {
* setOrigin: {
* name: 'My Origin',
* type: 'single_origin',
* },
* },
* },
* ],
* },
* purge: [
* {
* type: 'url',
* urls: ['https://example.com/path/to/purge'],
* method: 'delete',
* layer: 'edge_caching',
* },
* ],
* // ... other configurations
* });
*/
declare function defineConfig(config: AzionConfig): AzionConfig;
/**
* AzionDomainsResponse<T> is a generic type that represents the response of the Azion API.
* It can be either a success response with the data or an error response with the error message and operation.
*
* @param T The type of the data that the response contains.
* @returns An object with the data or an error message and operation.
*/
type AzionDomainsResponse<T> = {
data?: T;
error?: {
message: string;
operation: string;
};
};
/**
* ResponseState is a type that represents the state of the response of the Azion API.
* It can be either pending, executed or failed.
* @returns A string with the state of the response.
*/
type ResponseState = 'pending' | 'executed' | 'failed';
/**
* AzionDomain is a type that represents the domain object in the Azion API.
* @param state The state of the response.
* @param id The id of the domain.
* @param url The url of the domain.
* @param environment The environment of the domain.
* @param active The status of the domain.
* @param name The name of the domain.
* @param cnameAccessOnly The status of the domain.
* @param cnames The cnames of the domain.
* @param edgeApplicationId The id of the edge application.
* @param edgeFirewallId The id of the edge firewall.
* @param digitalCertificateId The id of the digital certificate.
* @param mtls The mtls object.
* @returns An object with the domain data.
*/
type AzionDomain = {
state?: ResponseState;
id?: number;
url?: string;
environment?: string;
active?: boolean;
name: string;
cnameAccessOnly?: boolean;
cnames?: string[];
edgeApplicationId?: number;
edgeFirewallId?: number;
digitalCertificateId?: string | number | null;
mtls?: {
verification: 'enforce' | 'permissive';
trustedCaCertificateId: number;
crlList?: number[];
};
};
/**
* AzionDomainCollection is a type that represents the domains object in the Azion API.
* @param state The state of the response.
* @param count The count of the domains.
* @param pages The number of pages.
* @param results The list of domains.
* @returns An object with the domains data.
*/
type AzionCreateDomain = Omit<AzionDomain, 'id' | 'environment' | 'active' | 'url' | 'state' | 'edgeApplicationId'> & {
edgeApplicationId: number;
};
/**
* AzionUpdateDomain is a type that represents the domain object in the Azion API.
* @param active The status of the domain.
* @param name The name of the domain.
* @param cnameAccessOnly The status of the domain.
* @param cnames The cnames of the domain.
* @param edgeApplicationId The id of the edge application.
* @param edgeFirewallId The id of the edge firewall.
* @param digitalCertificateId The id of the digital certificate.
* @param mtls The mtls object.
* @returns An object with the domain data.
*/
type AzionUpdateDomain = Omit<AzionDomain, 'id' | 'environment' | 'url' | 'edgeApplicationId' | 'state'> & {
edgeApplicationId: number;
};
/**
* AzionDeletedDomain is a type that represents the domain object in the Azion API.
* @param id The id of the domain.
* @param state The state of the response.
* @returns An object with the domain data.
*/
type AzionDeletedDomain = Pick<AzionDomain, 'id' | 'state'>;
/**
* AzionClientOptions is a type that represents the options of the Azion API client.
* @param debug The debug option.
* @param force The force option.
* @returns An object with the options of the client.
*/
type AzionClientOptions$3 = {
debug?: boolean | undefined;
force?: boolean | undefined;
};
/**
* AzionDomainCollection is a type that represents the domains object in the Azion API.
* @param state The state of the response.
* @param count The count of the domains.
* @param pages The number of pages.
* @param results The list of domains.
* @returns An object with the domains data.
*/
type AzionDomainCollection = {
state: ResponseState;
count: number;
pages: number;
results: AzionDomain[];
};
/**
* AzionDomainsClient is a type that represents the client of the Azion domains API.
* @param createDomain The function to create a domain.
* @param getDomains The function to get the domains.
* @param getDomain The function to get a domain.
* @param updateDomain The function to update a domain.
* @param deleteDomain The function to delete a domain.
* @returns An object with the client functions.
*/
interface AzionDomainsClient {
/**
* createDomain is a function that creates a domain in the Azion API.
* @param {AzionCreateDomain} domain The domain object.
* @param { AzionClientOptions } options The options of the client.
* @returns {Promise<AzionDomainsResponse<AzionDomain>>} The response of the API.
* @example
* const domain = {
* name: 'example.com',
* edgeApplicationId: 1,
* };
* const { data, error } = await client.createDomain(domain);
* if (error) {
* console.error(error.message);
* } else {
* console.log(data);
* }
*/
createDomain: (domain: AzionCreateDomain, options?: AzionClientOptions$3) => Promise<AzionDomainsResponse<AzionDomain>>;
/**
* getDomains is a function that gets the domains in the Azion API.
* @param {AzionClientOptions} options The options of the client.
* @param {{ orderBy?: 'id' | 'name'; page?: number; pageSize?: number; sort?: 'asc' | 'desc' }} queryParams The query parameters of the request.
* @returns {Promise<AzionDomainsResponse<AzionDomainCollection>>} The response of the API.
* @example
* const { data, error } = await client.getDomains();
* if (error) {
* console.error(error.message);
* } else {
* console.log(data.results);
* }
*/
getDomains: (options?: AzionClientOptions$3, queryParams?: {
orderBy?: 'id' | 'name';
page?: number;
pageSize?: number;
sort?: 'asc' | 'desc';
}) => Promise<AzionDomainsResponse<AzionDomainCollection>>;
/**
* getDomain is a function that gets a domain in the Azion API.
* @param {number} domainId The id of the domain.
* @param {AzionClientOptions} options The options of the client.
* @returns {Promise<AzionDomainsResponse<AzionDomain>>} The response of the API.
* @example
* const { data, error } = await client.getDomain(1);
* if (error) {
* console.error(error.message);
* } else {
* console.log(data);
* }
*/
getDomain: (domainId: number, options?: AzionClientOptions$3) => Promise<AzionDomainsResponse<AzionDomain>>;
/**
* updateDomain is a function that updates a domain in the Azion API.
* @param {number} domainId The id of the domain.
* @param {AzionUpdateDomain} domain The domain object.
* @param {AzionClientOptions} options The options of the client.
* @returns {Promise<AzionDomainsResponse<AzionDomain>>} The response of the API.
* @example
* const domain = {
* name: 'example.com',
* edgeApplicationId: 1,
* };
* const { data, error } = await client.updateDomain(1, domain);
* if (error) {
* console.error(error.message);
* } else {
* console.log(data);
* }
*/
updateDomain: (domainId: number, domain: AzionUpdateDomain, options?: AzionClientOptions$3) => Promise<AzionDomainsResponse<AzionDomain>>;
/**
* deleteDomain is a function that deletes a domain in the Azion API.
* @param {number} domainId The id of the domain.
* @param {AzionClientOptions} options The options of the client.
* @returns {Promise<AzionDomainsResponse<AzionDeletedDomain>>} The response of the API.
* @example
* const { data, error } = await client.deleteDomain(1);
* if (error) {
* console.error(error.message);
* } else {
* console.log(data.id);
* }
*/
deleteDomain: (domainId: number, options?: AzionClientOptions$3) => Promise<AzionDomainsResponse<AzionDeletedDomain>>;
}
/**
* Represents a message in the AI conversation.
*
* @property {('system' | 'user' | 'assistant')} role - The role of the message sender.
* @property {string} content - The content of the message.
*/
interface AzionAIMessage {
role: 'system' | 'user' | 'assistant';
content: string;
}
/**
* Configuration options for the Azion AI request.
*
* @property {string} [session_id] - Unique identifier for the session.
* @property {string} [url] - URL associated with the request.
* @property {string} [app] - Application identifier.
* @property {string} [user_name] - Name of the user.
* @property {string} [client_id] - Client identifier.
* @property {string} [system_prompt] - System-level prompt.
* @property {string} [user_prompt] - User-level prompt.
*/
interface AzionAIConfig {
session_id?: string;
url?: string;
app?: string;
user_name?: string;
client_id?: string;
system_prompt?: string;
user_prompt?: string;
}
/**
* Structure of an AI request to be sent to the Azion AI service.
*
* @property {AzionAIMessage[]} messages - Array of messages in the conversation.
* @property {AzionAIConfig} [azion] - Additional Azion-specific configuration.
* @property {boolean} [stream] - Whether to use streaming for the response.
*/
interface AzionAIRequest {
messages: AzionAIMessage[];
azion?: AzionAIConfig;
stream?: boolean;
}
/**
* Structure of the AI response received from the Azion AI service.
*
* @property {Object[]} choices - Array of response choices.
* @property {string} choices[].finish_reason - Reason for finishing the response.
* @property {number} choices[].index - Index of the choice.
* @property {Object} choices[].message - Message content and role.
* @property {string} choices[].message.content - Content of the message.
* @property {string} choices[].message.role - Role of the message sender.
* @property {null} choices[].logprobs - Log probabilities (null in this case).
* @property {number} created - Timestamp of when the response was created.
* @property {string} id - Unique identifier for the response.
* @property {string} model - Model used for generating the response.
* @property {string} object - Type of object returned.
* @property {Object} usage - Token usage statistics.
* @property {number} usage.completion_tokens - Number of tokens in the completion.
* @property {number} usage.prompt_tokens - Number of tokens in the prompt.
* @property {number} usage.total_tokens - Total number of tokens used.
* @property {Object} usage.completion_tokens_details - Detailed token usage for completion.
* @property {number} usage.completion_tokens_details.reasoning_tokens - Number of tokens used for reasoning.
*/
interface AzionAIResponse {
choices: {
finish_reason: string;
index: number;
message: {
content: string;
role: string;
};
logprobs: null;
}[];
created: number;
id: string;
model: string;
object: string;
usage: {
completion_tokens: number;
prompt_tokens: number;
total_tokens: number;
completion_tokens_details: {
reasoning_tokens: number;
};
};
}
/**
* Structure of a streaming AI response from the Azion AI service.
*
* @property {Object[]} choices - Array of response choices.
* @property {Object} choices[].delta - Delta of the response content.
* @property {string} [choices[].delta.content] - Content of the delta, if any.
* @property {string | null} choices[].finish_reason - Reason for finishing the response, if applicable.
* @property {number} choices[].index - Index of the choice.
* @property {null} choices[].logprobs - Log probabilities (null in this case).
* @property {number} created - Timestamp of when the response was created.
* @property {string} id - Unique identifier for the response.
* @property {string} model - Model used for generating the response.
* @property {string} object - Type of object returned.
* @property {string} system_fingerprint - Fingerprint of the system.
*/
interface AzionAIStreamResponse {
choices: {
delta: {
content?: string;
};
finish_reason: string | null;
index: number;
logprobs: null;
}[];
created: number;
id: string;
model: string;
object: string;
system_fingerprint: string;
}
/**
* Generic result type for Azion AI operations.
*
* @template T - The type of data expected in the result.
* @property {T | null} data - The data returned from the operation, if successful.
* @property {Error | null} error - The error object, if the operation failed.
*/
interface AzionAIResult<T> {
data: T | null;
error: Error | null;
}
/**
* Interface for the Azion AI client, providing methods to interact with the AI service.
*/
interface AzionAIClient {
/**
* Sends a chat request to the AI service.
*
* @param {AzionAIRequest} request - The chat request to be sent.
* @param {AzionClientOptions} [options] - Additional options for the request.
* @returns {Promise<AzionAIResult<AzionAIResponse>>} A promise that resolves to the chat result or an error.
*
* @example
* const result = await aiClient.chat({
* messages: [{ role: 'user', content: 'Hello, AI!' }]
* });
* if (result.data) {
* console.log('AI response:', result.data.choices[0].message.content);
* } else {
* console.error('Error:', result.error);
* }
*/
chat: (request: AzionAIRequest, options?: AzionClientOptions$2) => Promise<AzionAIResult<AzionAIResponse>>;
/**
* Sends a streaming chat request to the AI service.
*
* @param {AzionAIRequest} request - The chat request to be sent.
* @param {AzionClientOptions} [options] - Additional options for the request.
* @returns {AsyncGenerator<AzionAIResult<AzionAIStreamResponse>>} An async generator that produces partial chat results.
*
* @example
* const stream = aiClient.streamChat({
* messages: [{ role: 'user', content: 'Tell me a story' }]
* });
* for await (const chunk of stream) {
* if (chunk.data) {
* console.log('AI chunk:', chunk.data.choices[0].delta.content);
* } else {
* console.error('Error:', chunk.error);
* }
* }
*/
streamChat: (request: AzionAIRequest, options?: AzionClientOptions$2) => AsyncGenerator<AzionAIResult<AzionAIStreamResponse>>;
}
/**
* Options for configuring the Azion client behavior.
*
* @property {boolean} [debug] - Enable debug mode for detailed logging.
* @property {boolean} [force] - Force the operation even if it might be destructive.
*
* @example
* const options: AzionClientOptions = {
* debug: true,
* force: false
* };
*/
type AzionClientOptions$2 = {
debug?: boolean;
force?: boolean;
};
declare enum BrowserCacheSettings {
HONOR = "honor",
OVERRIDE = "override",
IGNORE = "ignore"
}
declare enum CdnCacheSettings {
HONOR = "honor",
OVERRIDE = "override"
}
declare enum CacheByQueryString {
IGNORE = "ignore",
WHITELIST = "whitelist",
BLACKLIST = "blacklist",
ALL = "all"
}
declare enum CacheByCookies {
IGNORE = "ignore",
WHITELIST = "whitelist",
BLACKLIST = "blacklist",
ALL = "all"
}
declare enum AdaptiveDeliveryAction {
IGNORE = "ignore",
OPTIMIZE = "optimize"
}
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;
}
interface ApiCreateCacheSettingPayload extends ApiBaseCacheSettingPayload {
}
interface ApiCacheSetting extends ApiBaseCacheSettingPayload {
id: number;
}
interface ApiListCacheSettingsParams {
page?: number;
page_size?: number;
sort?: 'name' | 'id';
order?: 'asc' | 'desc';
}
interface ApiUpdateCacheSettingPayload extends Partial<ApiBaseCacheSettingPayload> {
}
type AzionCacheSetting = ApiCacheSetting;
interface ApiBaseDeviceGroupPayload {
name: string;
user_agent: string;
}
interface ApiCreateDeviceGroupPayload extends ApiBaseDeviceGroupPayload {
}
interface ApiListDeviceGroupsParams {
page?: number;
page_size?: number;
sort?: 'name' | 'id';
order?: 'asc' | 'desc';
}
interface ApiUpdateDeviceGroupPayload extends Partial<ApiBaseDeviceGroupPayload> {
}
interface AzionDeviceGroup {
id: number;
name: string;
user_agent: string;
}
interface ApiBaseFunctionInstancePayload {
name: string;
code: string;
language: 'JavaScript';
initiator_type: 'edge_application' | 'edge_firewall';
active: boolean;
json_args: Record<string, unknown>;
}
interface ApiCreateFunctionInstancePayload {
name: string;
edge_function_id: number;
args: Record<string, unknown>;
}
interface ApiFunctionInstance extends ApiBaseFunctionInstancePayload {
id: number;
}
interface ApiListFunctionInstancesParams {
page?: number;
page_size?: number;
sort?: 'name' | 'id';
order?: 'asc' | 'desc';
order_by?: string;
filter?: string;
}
interface ApiUpdateFunctionInstancePayload extends Partial<ApiBaseFunctionInstancePayload> {
}
type AzionFunctionInstance = ApiFunctionInstance;
declare enum DeliveryProtocol {
HTTP = "http",
HTTPS = "https",
HTTP_HTTPS = "http,https"
}
declare enum HttpPort {
PORT_80 = 80,
PORT_8008 = 8008,
PORT_8080 = 8080
}
declare enum HttpsPort {
PORT_443 = 443,
PORT_8443 = 8443,
PORT_9440 = 9440,
PORT_9441 = 9441,
PORT_9442 = 9442,
PORT_9443 = 9443
}
declare 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"
}
declare 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"
}
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;
}
interface ApiCreateApplicationPayload extends ApiBaseApplicationPayload {
}
interface ApiApplication extends ApiBaseApplicationPayload {
id: number;
}
interface ApiUpdateApplicationPayload extends Partial<ApiBaseApplicationPayload> {
}
interface ApiListOriginsParams {
page?: number;
page_size?: number;
sort?: 'name' | 'id