diff --git a/README.md b/README.md index 8aa4206..53f787a 100644 --- a/README.md +++ b/README.md @@ -301,9 +301,11 @@ The Config library provides methods to configure and validate options for the Az import { AzionConfig } from 'azion'; const config = AzionConfig({ + domain: {}, origin: [], cache: [], rules: [], + purge: [], }); ``` @@ -311,13 +313,15 @@ const config = AzionConfig({ import { AzionConfig } from 'azion'; const config = AzionConfig({ + domain: {}, origin: [], cache: [], rules: [], + purge: [], }); ``` -Read more in the [CONFIG README](./packages/config/README.MD). +Read more in the [CONFIG README](./packages/config/README.md). ## Contributing diff --git a/packages/config/README.md b/packages/config/README.md index e4a7e01..11c7b02 100644 --- a/packages/config/README.md +++ b/packages/config/README.md @@ -1,6 +1,6 @@ # Azion Edge Application Configuration -This module provides a function to configure and validate options for the Azion Edge Application. It supports various configurations, including origin settings, cache settings, rules, and network lists. +This module provides a function to configure and validate options for the Azion Edge Application. It supports various configurations, including domain settings, origin settings, cache settings, rules, network lists, and purge operations. ## Table of Contents @@ -36,11 +36,29 @@ Here's an example of how to configure the Azion Edge Application: import { AzionConfig } from 'azion'; const config = AzionConfig({ + domain: { + name: 'example.com', + cnameAccessOnly: false, + cnames: ['www.example.com', 'cdn.example.com'], + edgeApplicationId: 12345, + edgeFirewallId: 67890, + digitalCertificateId: null, + mtls: { + verification: 'enforce', + trustedCaCertificateId: 98765, + }, + }, origin: [ { name: 'My Origin', type: 'single_origin', - addresses: ['example.com'], + addresses: [ + { + address: 'origin.example.com', + weight: 100, + }, + ], + protocolPolicy: 'https', }, ], cache: [ @@ -68,6 +86,14 @@ const config = AzionConfig({ }, ], }, + purge: [ + { + type: 'url', + urls: ['https://example.com/path/to/purge'], + method: 'delete', + layer: 'edge_caching', + }, + ], }); ``` @@ -80,14 +106,34 @@ Configures and validates the options for the Azion Edge Application. **Parameters:** - `config: AzionConfig` - The configuration object for the Azion Edge Application. - - `origin: Array` - Array of origin configurations. + - `domain?: DomainConfig` - Configuration for the domain. + - `name: string` - The domain name. + - `cnameAccessOnly?: boolean` - Whether to restrict access only to CNAMEs. + - `cnames?: string[]` - List of CNAMEs for the domain. + - `edgeApplicationId?: number` - ID of the edge application. + - `edgeFirewallId?: number` - ID of the edge firewall. + - `digitalCertificateId?: string | number | null` - ID of the digital certificate. + - `mtls?: MTLSConfig` - Configuration for mTLS. + - `verification: 'enforce' | 'permissive'` - mTLS verification mode. + - `trustedCaCertificateId: number` - ID of the trusted CA certificate. + - `crlList?: number[]` - List of Certificate Revocation Lists (CRLs). + - `origin?: OriginConfig[]` - Array of origin configurations. + - `id?: number` - ID of the origin. + - `key?: string` - Key for the origin. - `name: string` - Name of the origin. - `type: string` - Type of the origin (e.g., 'single_origin', 'load_balancer'). - - `bucket?: string` - Bucket name for storage origins. - - `prefix?: string` - Prefix for storage origins. - - `addresses?: string[]` - Array of addresses for the origin. + - `bucket?: string | null` - Bucket name for storage origins. + - `prefix?: string | null` - Prefix for storage origins. + - `addresses?: (string | { address: string; weight?: number })[]` - Array of addresses for the origin. - `hostHeader?: string` - Custom host header. - - `cache: Array` - Array of cache configurations. + - `protocolPolicy?: 'http' | 'https' | 'preserve'` - Protocol policy for the origin. + - `redirection?: boolean` - Whether to enable redirection. + - `method?: 'ip_hash' | 'least_connections' | 'round_robin'` - Load balancing method. + - `path?: string` - Path for the origin. + - `connectionTimeout?: number` - Connection timeout in seconds. + - `timeoutBetweenBytes?: number` - Timeout between bytes in seconds. + - `hmac?: { region: string; accessKey: string; secretKey: string }` - HMAC configuration for the origin. + - `cache?: CacheConfig[]` - Array of cache configurations. - `name: string` - Name of the cache configuration. - `stale?: boolean` - Whether to allow stale content. - `queryStringSort?: boolean` - Whether to sort query string parameters. @@ -105,24 +151,48 @@ Configures and validates the options for the Azion Edge Application. - `option: 'ignore' | 'varies' | 'whitelist' | 'blacklist'` - Cache by query string option. - `list?: string[]` - List of query string parameters to use for caching. - `rules?: RulesConfig` - Rules configuration. - - `request: Array` - Array of request rules. + - `request?: RequestRule[]` - Array of request rules. - `name: string` - Name of the request rule. - `description?: string` - Description of the request rule. - `active?: boolean` - Whether the rule is active. - `match: string` - Match condition for the rule. - `variable?: string` - Variable to match against. - `behavior?: RequestBehavior` - Behavior to apply when the rule matches. - - `response: Array` - Array of response rules. + - `setOrigin?: { name: string; type: string }` - Set origin behavior. + - `rewrite?: string` - URL rewrite behavior. + - `setHeaders?: string[]` - Headers to set. + - `bypassCache?: boolean | null` - Whether to bypass cache. + - `httpToHttps?: boolean | null` - Redirect HTTP to HTTPS. + - `redirectTo301?: string | null` - Redirect with 301 status. + - `redirectTo302?: string | null` - Redirect with 302 status. + - `forwardCookies?: boolean | null` - Whether to forward cookies. + - `setCookie?: string | null` - Set cookie behavior. + - `deliver?: boolean | null` - Whether to deliver the response. + - `capture?: { match: string; captured: string; subject: string }` - Capture behavior. + - `runFunction?: { path: string; name?: string | null }` - Run a custom function. + - `setCache?: string | { name: string; browser_cache_settings_maximum_ttl?: number | null; cdn_cache_settings_maximum_ttl?: number | null }` - Set cache behavior. + - `response?: ResponseRule[]` - Array of response rules. - `name: string` - Name of the response rule. - `description?: string` - Description of the response rule. - `active?: boolean` - Whether the rule is active. - `match: string` - Match condition for the rule. - `variable?: string` - Variable to match against. - `behavior?: ResponseBehavior` - Behavior to apply when the rule matches. - - `networkList?: Array` - Array of network list configurations. - - `id: number` - ID of the network list. - - `listType: string` - Type of the network list. - - `listContent: string[]` - Content of the network list. + - `setCookie?: string | null` - Set cookie behavior. + - `setHeaders?: string[]` - Headers to set. + - `deliver?: boolean | null` - Whether to deliver the response. + - `capture?: { match: string; captured: string; subject: string }` - Capture behavior. + - `enableGZIP?: boolean | null` - Enable GZIP compression. + - `filterCookie?: string | null` - Filter cookies. + - `filterHeader?: string | null` - Filter headers. + - `runFunction?: { path: string; name?: string | null }` - Run a custom function. + - `redirectTo301?: string | null` - Redirect with 301 status. + - `redirectTo302?: string | null` - Redirect with 302 status. + - `purge?: PurgeConfig[]` - Array of purge configurations. + - `type: 'url' | 'cachekey' | 'wildcard'` - Type of purge operation. + - `urls: string[]` - URLs to purge. + - `method?: 'delete'` - HTTP method to use for purging. + - `layer?: 'edge_caching' | 'l2_caching'` - Caching layer to target. **Returns:** @@ -136,13 +206,45 @@ The type definition for the AzionConfig. ```typescript export type AzionConfig = { + domain?: { + name: string; + cnameAccessOnly?: boolean; + cnames?: string[]; + edgeApplicationId?: number; + edgeFirewallId?: number; + digitalCertificateId?: string | number | null; + mtls?: { + verification: 'enforce' | 'permissive'; + trustedCaCertificateId: number; + crlList?: number[]; + }; + }; + origin?: { + id?: number; + key?: string; name: string; type: string; bucket?: string | null; prefix?: string | null; - addresses?: string[]; + addresses?: + | string[] + | { + address: string; + weight?: number; + }[]; hostHeader?: string; + protocolPolicy?: 'http' | 'https' | 'preserve'; + redirection?: boolean; + method?: 'ip_hash' | 'least_connections' | 'round_robin'; + path?: string; + connectionTimeout?: number; + timeoutBetweenBytes?: number; + hmac?: { + region: string; + accessKey: string; + secretKey: string; + }; }[]; cache?: { @@ -236,10 +338,11 @@ export type AzionConfig = { }[]; }; - networkList?: { - id: number; - listType: string; - listContent: string[]; + purge?: { + type: 'url' | 'cachekey' | 'wildcard'; + urls: string[]; + method?: 'delete'; + layer?: 'edge_caching' | 'l2_caching'; }[]; }; ``` diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index a130335..0624250 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -4,13 +4,38 @@ import { AzionConfig as AzionConfigType } from './types'; * Configures and validates the options for the Azion Edge Application. * * @param {AzionConfig} config - The configuration object for the Azion Edge Application. + * + * @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.edgeApplicationId] - 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 {string[]} [config.origin[].addresses] - Array of addresses for the origin. + * @param {Array} [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. @@ -38,21 +63,91 @@ import { AzionConfig as AzionConfigType } from './types'; * @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({ + * domain: { + * name: 'example.com', + * cnameAccessOnly: false, + * cnames: ['www.example.com', 'cdn.example.com'], + * edgeApplicationId: 12345, + * edgeFirewallId: 67890, + * digitalCertificateId: null, + * mtls: { + * verification: 'enforce', + * trustedCaCertificateId: 98765, + * }, + * }, * origin: [ * { * name: 'My Origin', * type: 'single_origin', - * addresses: ['example.com'], + * addresses: [ + * { + * address: 'origin.example.com', + * weight: 100, + * }, + * ], + * protocolPolicy: 'https', * }, * ], * cache: [ @@ -66,6 +161,28 @@ import { AzionConfig as AzionConfigType } from './types'; * }, * }, * ], + * 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 * }); */ diff --git a/packages/config/src/types.ts b/packages/config/src/types.ts index 4ff6956..acacccf 100644 --- a/packages/config/src/types.ts +++ b/packages/config/src/types.ts @@ -131,12 +131,6 @@ export type AzionConfig = { }[]; }; - networkList?: { - id: number; - listType: string; - listContent: string[]; - }[]; - purge?: { type: 'url' | 'cachekey' | 'wildcard'; urls: string[];