import { BuildOptions, Plugin } from 'esbuild'; import { Configuration, WebpackPluginInstance } from 'webpack'; 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}}` | 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; 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]; interface Metadata { geoip_asn: string; geoip_city: string; geoip_city_continent_code: string; geoip_city_country_code: string; geoip_city_country_name: string; geoip_continent_code: string; geoip_country_code: string; geoip_country_name: string; geoip_region: string; geoip_region_name: string; remote_addr: string; remote_port: string; remote_user: string; server_protocol: string; ssl_cipher: string; ssl_protocol: string; [key: string]: string; } /** * Represents the FetchEvent interface. */ interface FetchEvent extends Event { request: Request & { metadata: Metadata; }; waitUntil(promise: Promise): void; respondWith(response: Response | Promise): void; } /** * 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?: string; /** 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?: string; /** 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 PresetInput = string | AzionBuildPreset; type BuildEntryPoint = string | string[] | Record; interface AzionBuild { entry?: BuildEntryPoint; bundler?: 'webpack' | 'esbuild'; preset?: PresetInput; polyfills?: boolean; extend?: (context: T) => T; memoryFS?: { injectionDirs: string[]; removePathPrefix: string; }; } /** * Network list configuration for Azion. */ type AzionNetworkList = { /** Network list identifier */ id: number; /** Network list type */ listType: NetworkListType; /** List of networks */ listContent: string[] | number[]; }; /** * Function configuration for Azion. */ type AzionFunction = { /** Function name */ name: string; /** Function path */ path: string; /** Optional arguments to be passed to the function */ args?: Record; }; /** * 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[]; /** Functions configurations */ functions?: AzionFunction[]; /** 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?: 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[]; }; type BuildConfiguration = Omit, 'preset' | 'entry'> & { entry: Record; baseOutputDir?: string; preset: AzionBuildPreset; setup: BundlerSetup; }; interface BundlerSetup { contentToInject?: string; defineVars?: Record; } interface BuildContext { production: boolean; handler: BuildEntryPoint; skipFrameworkBuild?: boolean; } type PresetMetadata = { name: string; registry?: string; ext?: string; }; interface AzionBuildPreset { config: AzionConfig; handler?: (event: FetchEvent) => Promise; prebuild?: (config: BuildConfiguration, ctx: BuildContext) => Promise; postbuild?: (config: BuildConfiguration, ctx: BuildContext) => Promise; metadata: PresetMetadata; } interface AzionPrebuildResult { /** Files to be injected into memory during build process */ filesToInject: string[]; injection: { globals: { _ENTRIES?: string; AsyncLocalStorage?: string; [key: string]: string | undefined; }; entry?: string; banner?: string; }; bundler: { defineVars: { __CONFIG__?: string; __BUILD_METADATA__?: string; [key: string]: string | undefined; }; plugins: (Plugin | WebpackPluginInstance)[]; }; } /** * 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; /** * Helper function to provide IntelliSense for Azion configuration. * Similar to Vite's defineConfig - provides type safety without runtime overhead. * * @param {AzionConfig} config - The configuration object for the Azion Platform. * @returns {AzionConfig} The same configuration object (no validation or processing) * * @example * import { defineConfig } from 'azion/config'; * * export default defineConfig({ * build: { * preset: 'typescript', * }, * domain: { * name: 'example.com', * }, * // ... other configurations * }); */ declare function defineConfig(config: AzionConfig): AzionConfig; /** * AzionDomainsResponse 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 = { 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 & { 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 & { 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; /** * 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>} 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>; /** * 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>} 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>; /** * 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>} 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>; /** * 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>} 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>; /** * 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>} 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>; } /** * 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 { 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>} 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>; /** * 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>} 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>; } /** * 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 { } 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 { } 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; } interface ApiCreateFunctionInstancePayload { name: string; edge_function_id: number; args: Record; } 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 { } 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 { } interface ApiListOriginsParams { page?: number; page_size?: number; sort?: 'name' | 'id'; order?: OrderDirection; filter?: string; } declare enum OrderDirection { ASC = "asc", DESC = "desc" } declare enum OriginType { SINGLE_ORIGIN = "single_origin", LOAD_BALANCER = "load_balancer" } declare enum OriginProtocolPolicy { PRESERVE = "preserve", HTTP = "http", HTTPS = "https" } declare enum ServerRole { PRIMARY = "primary", BACKUP = "backup" } interface Address { address: string; weight?: number | null; server_role?: ServerRole; is_active?: boolean; } interface ApiOrigin { 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; } type ApiCreateOriginPayload = Omit & { origin_path?: string; hmac_authentication?: boolean; hmac_region_name?: string; hmac_access_key?: string; hmac_secret_key?: string; connection_timeout?: number; timeout_between_bytes?: number; }; type ApiUpdateOriginRequest = Partial & { id: number; }; type AzionOrigin = ApiOrigin; interface Rule { id: number; name: string; phase: 'request' | 'response'; behaviors: Behavior[]; criteria: Criterion[][]; is_active: boolean; order: number; description?: string; } interface Rule { id: number; name: string; phase: 'request' | 'response'; behaviors: Behavior[]; criteria: Criterion[][]; is_active: boolean; order: number; description?: string; } interface Behavior { name: string; target?: string | null | BehaviorTarget; } interface Behavior { name: string; target?: string | null | BehaviorTarget; } interface BehaviorTarget { captured_array: string; subject: string; regex: string; } interface BehaviorTarget { captured_array: string; subject: string; regex: string; } interface Criterion { variable: string; operator: string; conditional: 'if' | 'and' | 'or'; input_value: string; } interface Criterion { variable: string; operator: string; conditional: 'if' | 'and' | 'or'; input_value: string; } interface ApiCreateRulePayload { name: string; phase: 'request' | 'response'; behaviors: Behavior[]; criteria: Criterion[][]; is_active?: boolean; order?: number; description?: string; } interface ApiCreateRulePayload { name: string; phase: 'request' | 'response'; behaviors: Behavior[]; criteria: Criterion[][]; is_active?: boolean; order?: number; description?: string; } interface ApiUpdateRulePayload extends Partial { } interface ApiUpdateRulePayload extends Partial { } interface ApiRuleResponse { results: Rule; schema_version: number; } interface ApiRuleResponse { results: Rule; schema_version: number; } interface ApiListRulesParams { page?: number; page_size?: number; sort?: string; order?: 'asc' | 'desc'; filter?: string; } interface ApiListRulesParams { page?: number; page_size?: number; sort?: string; order?: 'asc' | 'desc'; filter?: string; } interface ApiListRulesParams { page?: number; page_size?: number; sort?: string; order?: 'asc' | 'desc'; filter?: string; } type AzionRule = ApiRuleResponse['results']; /** * @fileoverview This module defines the types and interfaces used throughout the Azion Application SDK. * It includes definitions for client options, response structures, and operation interfaces for various * Azion Edge Application features such as cache settings, origins, rules, device groups, and functions. * @module application/types */ /** * Options for configuring the Azion client behavior. * * @interface AzionClientOptions * @property {boolean} [debug] - Enable debug mode for detailed logging. * @property {boolean} [force] - Force the operation even if it might be destructive. */ interface AzionClientOptions$1 { debug?: boolean; force?: boolean; } /** * Options for retrieving a collection of Azion applications. * * @interface AzionApplicationCollectionOptions * @property {number} [page] - The page number for pagination. * @property {number} [page_size] - The number of items per page. * @property {'name' | 'id'} [sort] - The field to sort the results by. * @property {string} [order_by] - The order of the sorting (e.g., 'asc' or 'desc'). */ interface AzionApplicationCollectionOptions { page?: number; page_size?: number; sort?: 'name' | 'id'; order_by?: string; } /** * Generic response structure for Azion API calls. * * @interface AzionApplicationResponse * @template T - The type of data returned in the response. * @property {T} [data] - The response data. * @property {{ message: string; operation: string }} [error] - Error information if the call failed. */ interface AzionApplicationResponse { data?: T; error?: { message: string; operation: string; }; } /** * Generic response structure for Azion API calls returning collections. * * @interface AzionApplicationCollectionResponse * @template T - The type of items in the collection. * @property {{ count: number; total_pages: number; schema_version: number; links: { previous: string | null; next: string | null }; results: T[] }} [data] - The collection data. * @property {{ message: string; operation: string }} [error] - Error information if the call failed. */ interface AzionApplicationCollectionResponse { data?: { count: number; total_pages: number; schema_version: number; links: { previous: string | null; next: string | null; }; results: T[]; }; error?: { message: string; operation: string; }; } /** * Interface for cache setting operations. * * @interface CacheOperations */ interface CacheOperations { /** * Creates a new cache setting. * * @function * @name CacheOperations.createCacheSetting * @param {Object} params - The parameters for creating a cache setting. * @param {ApiCreateCacheSettingPayload} params.data - The data for the new cache setting. * @returns {Promise>} A promise that resolves with the created cache setting data or an error. * * @example * const { error, data } = await cacheOperations.createCacheSetting({ * data: { * name: 'My Cache Setting', * browser_cache_settings: 'override', * cdn_cache_settings: 'override', * cache_by_query_string: 'ignore', * cookie_names: ['session_id'], * enable_stale_cache: true * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created cache setting:', data); * } */ createCacheSetting: (params: { data: ApiCreateCacheSettingPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific cache setting. * * @function * @name CacheOperations.getCacheSetting * @param {Object} params - The parameters for retrieving a cache setting. * @param {number} params.cacheSettingId - The ID of the cache setting to retrieve. * @returns {Promise>} A promise that resolves with the cache setting data or an error. * * @example * const { error, data } = await cacheOperations.getCacheSetting({ * cacheSettingId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved cache setting:', data); * } */ getCacheSetting: (params: { cacheSettingId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of cache settings. * * @function * @name CacheOperations.getCacheSettings * @param {Object} params - The parameters for retrieving cache settings. * @param {ApiListCacheSettingsParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of cache settings or an error. * * @example * const { error, data } = await cacheOperations.getCacheSettings({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved cache settings:', data.results); * } */ getCacheSettings: (params: { params?: ApiListCacheSettingsParams; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing cache setting. * * @function * @name CacheOperations.updateCacheSetting * @param {Object} params - The parameters for updating a cache setting. * @param {number} params.cacheSettingId - The ID of the cache setting to update. * @param {ApiUpdateCacheSettingPayload} params.data - The updated data for the cache setting. * @returns {Promise>} A promise that resolves with the updated cache setting data or an error. * * @example * const { error, data } = await cacheOperations.updateCacheSetting({ * cacheSettingId: 123, * data: { * name: 'Updated Cache Setting', * browser_cache_settings: 'honor', * cdn_cache_settings: 'honor' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated cache setting:', data); * } */ updateCacheSetting: (params: { cacheSettingId: number; data: ApiUpdateCacheSettingPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes a cache setting. * * @function * @name CacheOperations.deleteCacheSetting * @param {Object} params - The parameters for deleting a cache setting. * @param {number} params.cacheSettingId - The ID of the cache setting to delete. * @returns {Promise>} A promise that resolves when the cache setting is deleted or rejects with an error. * * @example * const { error, data } = await cacheOperations.deleteCacheSetting({ * cacheSettingId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Cache setting deleted successfully'); * } */ deleteCacheSetting: (params: { cacheSettingId: number; options?: AzionClientOptions$1; }) => Promise>; } /** * Interface for origin operations. * * @interface OriginOperations */ interface OriginOperations { /** * Creates a new origin. * * @function * @name OriginOperations.createOrigin * @param {Object} params - The parameters for creating an origin. * @param {ApiCreateOriginPayload} params.data - The data for the new origin. * @returns {Promise>} A promise that resolves with the created origin data or an error. * * @example * const { error, data } = await originOperations.createOrigin({ * data: { * name: 'My Origin', * origin_type: 'single_origin', * addresses: [{ address: 'example.com' }], * host_header: 'example.com' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created origin:', data); * } */ createOrigin: (params: { data: ApiCreateOriginPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific origin. * * @function * @name OriginOperations.getOrigin * @param {Object} params - The parameters for retrieving an origin. * @param {string} params.originKey - The key of the origin to retrieve. * @returns {Promise>} A promise that resolves with the origin data or an error. * * @example * const { error, data } = await originOperations.getOrigin({ * originKey: 'abc123', * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved origin:', data); * } */ getOrigin: (params: { originKey: string; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of origins. * * @function * @name OriginOperations.getOrigins * @param {Object} params - The parameters for retrieving origins. * @param {ApiListOriginsParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of origins or an error. * * @example * const { error, data } = await originOperations.getOrigins({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved origins:', data.results); * } */ getOrigins: (params: { params?: ApiListOriginsParams; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing origin. * * @function * @name OriginOperations.updateOrigin * @param {Object} params - The parameters for updating an origin. * @param {string} params.originKey - The key of the origin to update. * @param {ApiUpdateOriginRequest} params.data - The updated data for the origin. * @returns {Promise>} A promise that resolves with the updated origin data or an error. * * @example * const { error, data } = await originOperations.updateOrigin({ * originKey: 'abc123', * data: { * name: 'Updated Origin', * host_header: 'updated-example.com' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated origin:', data); * } */ updateOrigin: (params: { originKey: string; data: ApiUpdateOriginRequest; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes an origin. * * @function * @name OriginOperations.deleteOrigin * @param {Object} params - The parameters for deleting an origin. * @param {string} params.originKey - The key of the origin to delete. * @returns {Promise>} A promise that resolves when the origin is deleted or rejects with an error. * * @example * const { error, data } = await originOperations.deleteOrigin({ * originKey: 'abc123', * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Origin deleted successfully'); * } */ deleteOrigin: (params: { originKey: string; options?: AzionClientOptions$1; }) => Promise>; } /** * Interface for rule operations. * * @interface RuleOperations */ interface RuleOperations { /** * Creates a new rule. * * @function * @name RuleOperations.createRule * @param {Object} params - The parameters for creating a rule. * @param {ApiCreateRulePayload} params.data - The data for the new rule. * @returns {Promise>} A promise that resolves with the created rule data or an error. * * @example * const { error, data } = await ruleOperations.createRule({ * data: { * name: 'My Rule', * phase: 'request', * behaviors: [{ name: 'set_origin', target: 'origin1' }], * criteria: [[{ conditional: 'if', input: '${uri}', operator: 'starts_with', value: '/api' }]] * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created rule:', data); * } */ createRule: (params: { data: ApiCreateRulePayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific rule. * * @function * @name RuleOperations.getRule * @param {Object} params - The parameters for retrieving a rule. * @param {number} params.ruleId - The ID of the rule to retrieve. * @returns {Promise>} A promise that resolves with the rule data or an error. * * @example * const { error, data } = await ruleOperations.getRule({ * ruleId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved rule:', data); * } */ getRule: (params: { ruleId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of rules. * * @function * @name RuleOperations.getRules * @param {Object} params - The parameters for retrieving rules. * @param {ApiListRulesParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of rules or an error. * * @example * const { error, data } = await ruleOperations.getRules({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved rules:', data.results); * } */ getRules: (params: { params?: ApiListRulesParams; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing rule. * * @function * @name RuleOperations.updateRule * @param {Object} params - The parameters for updating a rule. * @param {number} params.ruleId - The ID of the rule to update. * @param {ApiUpdateRulePayload} params.data - The updated data for the rule. * @returns {Promise>} A promise that resolves with the updated rule data or an error. * * @example * const { error, data } = await ruleOperations.updateRule({ * ruleId: 123, * data: { * name: 'Updated Rule', * behaviors: [{ name: 'set_origin', target: 'origin2' }] * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated rule:', data); * } */ updateRule: (params: { ruleId: number; data: ApiUpdateRulePayload; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes a rule. * * @function * @name RuleOperations.deleteRule * @param {Object} params - The parameters for deleting a rule. * @param {number} params.ruleId - The ID of the rule to delete. * @returns {Promise>} A promise that resolves when the rule is deleted or rejects with an error. * * @example * const { error, data } = await ruleOperations.deleteRule({ * ruleId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Rule deleted successfully'); * } */ deleteRule: (params: { ruleId: number; options?: AzionClientOptions$1; }) => Promise>; } /** * Interface for device group operations. * * @interface DeviceGroupOperations */ interface DeviceGroupOperations { /** * Creates a new device group. * * @function * @name DeviceGroupOperations.createDeviceGroup * @param {Object} params - The parameters for creating a device group. * @param {ApiCreateDeviceGroupPayload} params.data - The data for the new device group. * @returns {Promise>} A promise that resolves with the created device group data or an error. * * @example * const { error, data } = await deviceGroupOperations.createDeviceGroup({ * data: { * name: 'Mobile Devices', * user_agent: 'Mobile|Android|iPhone|iPad|iPod' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created device group:', data); * } */ createDeviceGroup: (params: { data: ApiCreateDeviceGroupPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific device group. * * @function * @name DeviceGroupOperations.getDeviceGroup * @param {Object} params - The parameters for retrieving a device group. * @param {number} params.deviceGroupId - The ID of the device group to retrieve. * @returns {Promise>} A promise that resolves with the device group data or an error. * * @example * const { error, data } = await deviceGroupOperations.getDeviceGroup({ * deviceGroupId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved device group:', data); * } */ getDeviceGroup: (params: { deviceGroupId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of device groups. * * @function * @name DeviceGroupOperations.getDeviceGroups * @param {Object} params - The parameters for retrieving device groups. * @param {ApiListDeviceGroupsParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of device groups or an error. * * @example * const { error, data } = await deviceGroupOperations.getDeviceGroups({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved device groups:', data.results); * } */ getDeviceGroups: (params: { params?: ApiListDeviceGroupsParams; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing device group. * * @function * @name DeviceGroupOperations.updateDeviceGroup * @param {Object} params - The parameters for updating a device group. * @param {number} params.deviceGroupId - The ID of the device group to update. * @param {ApiUpdateDeviceGroupPayload} params.data - The updated data for the device group. * @returns {Promise>} A promise that resolves with the updated device group data or an error. * * @example * const { error, data } = await deviceGroupOperations.updateDeviceGroup({ * deviceGroupId: 123, * data: { * name: 'Updated Mobile Devices', * user_agent: 'Mobile|Android|iPhone|iPad|iPod|BlackBerry' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated device group:', data); * } */ updateDeviceGroup: (params: { deviceGroupId: number; data: ApiUpdateDeviceGroupPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes a device group. * * @function * @name DeviceGroupOperations.deleteDeviceGroup * @param {Object} params - The parameters for deleting a device group. * @param {number} params.deviceGroupId - The ID of the device group to delete. * @returns {Promise>} A promise that resolves when the device group is deleted or rejects with an error. * * @example * const { error, data } = await deviceGroupOperations.deleteDeviceGroup({ * deviceGroupId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Device group deleted successfully'); * } */ deleteDeviceGroup: (params: { deviceGroupId: number; options?: AzionClientOptions$1; }) => Promise>; } /** * Interface for function operations. * * @interface FunctionOperations */ interface FunctionOperations { /** * Creates a new function instance. * * @function * @name FunctionOperations.createFunctionInstance * @param {Object} params - The parameters for creating a function instance. * @param {ApiCreateFunctionInstancePayload} params.data - The data for the new function instance. * @returns {Promise>} A promise that resolves with the created function instance data or an error. * * @example * const { error, data } = await functionOperations.createFunctionInstance({ * data: { * name: 'My Function', * code: 'async function handleRequest(request) { return new Response("Hello, World!"); }', * language: 'javascript' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created function instance:', data); * } */ createFunctionInstance: (params: { data: ApiCreateFunctionInstancePayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific function instance. * * @function * @name FunctionOperations.getFunctionInstance * @param {Object} params - The parameters for retrieving a function instance. * @param {number} params.functionInstanceId - The ID of the function instance to retrieve. * @returns {Promise>} A promise that resolves with the function instance data or an error. * * @example * const { error, data } = await functionOperations.getFunctionInstance({ * functionInstanceId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved function instance:', data); * } */ getFunctionInstance: (params: { functionInstanceId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of function instances. * * @function * @name FunctionOperations.getFunctionInstances * @param {Object} params - The parameters for retrieving function instances. * @param {ApiListFunctionInstancesParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of function instances or an error. * * @example * const { error, data } = await functionOperations.getFunctionInstances({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved function instances:', data.results); * } */ getFunctionInstances: (params: { params?: ApiListFunctionInstancesParams; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing function instance. * * @function * @name FunctionOperations.updateFunctionInstance * @param {Object} params - The parameters for updating a function instance. * @param {number} params.functionInstanceId - The ID of the function instance to update. * @param {ApiUpdateFunctionInstancePayload} params.data - The updated data for the function instance. * @returns {Promise>} A promise that resolves with the updated function instance data or an error. * * @example * const { error, data } = await functionOperations.updateFunctionInstance({ * functionInstanceId: 123, * data: { * name: 'Updated Function', * code: 'async function handleRequest(request) { return new Response("Hello, Updated World!"); }' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated function instance:', data); * } */ updateFunctionInstance: (params: { functionInstanceId: number; data: ApiUpdateFunctionInstancePayload; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes a function instance. * * @function * @name FunctionOperations.deleteFunctionInstance * @param {Object} params - The parameters for deleting a function instance. * @param {number} params.functionInstanceId - The ID of the function instance to delete. * @returns {Promise>} A promise that resolves when the function instance is deleted or rejects with an error. * * @example * const { error, data } = await functionOperations.deleteFunctionInstance({ * functionInstanceId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Function instance deleted successfully'); * } */ deleteFunctionInstance: (params: { functionInstanceId: number; options?: AzionClientOptions$1; }) => Promise>; } /** * Interface representing an Azion Application with all its associated operations. * * @interface AzionApplication * @extends ApiApplication */ interface AzionApplication extends ApiApplication { /** * Operations related to cache settings for the application. * @type {CacheOperations} * * @example * // Creating a new cache setting * const { error, data } = await application.cache.createCacheSetting({ * data: { * name: 'My Cache Setting', * browser_cache_settings: 'override', * cdn_cache_settings: 'override', * cache_by_query_string: 'ignore' * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created cache setting:', data); * } */ cache: CacheOperations; /** * Operations related to origins for the application. * @type {OriginOperations} * * @example * // Creating a new origin * const { error, data } = await application.origins.createOrigin({ * data: { * name: 'My Origin', * addresses: [{ address: 'example.com' }], * origin_type: 'single_origin', * host_header: 'example.com' * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created origin:', data); * } */ origins: OriginOperations; /** * Operations related to rules for the application. * @type {{ request: RuleOperations; response: RuleOperations }} */ rules: { /** * Operations for request rules. * @type {RuleOperations} * * @example * // Creating a new request rule * const { error, data } = await application.rules.request.createRule({ * data: { * name: 'My Request Rule', * phase: 'request', * behaviors: [{ name: 'set_origin', target: 'origin1' }], * criteria: [[{ conditional: 'if', input: '${uri}', operator: 'starts_with', value: '/api' }]] * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created request rule:', data); * } */ request: RuleOperations; /** * Operations for response rules. * @type {RuleOperations} * * @example * // Creating a new response rule * const { error, data } = await application.rules.response.createRule({ * data: { * name: 'My Response Rule', * phase: 'response', * behaviors: [{ name: 'add_response_header', target: 'X-Custom-Header', value: 'CustomValue' }], * criteria: [[{ conditional: 'if', input: '${status}', operator: 'is_equal', value: '200' }]] * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created response rule:', data); * } */ response: RuleOperations; }; /** * Operations related to device groups for the application. * @type {DeviceGroupOperations} * * @example * // Creating a new device group * const { error, data } = await application.devices.createDeviceGroup({ * data: { * name: 'Mobile Devices', * user_agent: 'Mobile|Android|iPhone|iPad|iPod' * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created device group:', data); * } */ devices: DeviceGroupOperations; /** * Operations related to functions for the application. * @type {FunctionOperations} * * @example * // Creating a new function instance * const { error, data } = await application.functions.createFunctionInstance({ * data: { * name: 'My Function', * edge_function_id: 5678, * args: {} * } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created function instance:', data); * } */ functions: FunctionOperations; } /** * Interface for the Azion Application Client, providing methods to interact with Azion Edge Applications. * * @interface AzionApplicationsClient */ interface AzionApplicationsClient { /** * Creates a new Azion Edge Application. * * @function * @name AzionApplicationsClient.createApplication * @param {Object} params - The parameters for creating an application. * @param {ApiCreateApplicationPayload} params.data - The data for the new application. * @returns {Promise>} A promise that resolves with the created application data or an error. * * @example * const { error, data } = await applicationClient.createApplication({ * data: { * name: 'My New Application', * delivery_protocol: 'http', * origin_type: 'single_origin', * address: 'example.com' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Created application:', data); * } */ createApplication: (params: { data: ApiCreateApplicationPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a specific Azion Edge Application. * * @function * @name AzionApplicationsClient.getApplication * @param {Object} params - The parameters for retrieving an application. * @param {number} params.applicationId - The ID of the application to retrieve. * @returns {Promise>} A promise that resolves with the application data or an error. * * @example * const { error, data } = await applicationClient.getApplication({ * applicationId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved application:', data); * } */ getApplication: (params: { applicationId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Retrieves a list of Azion Edge Applications. * * @function * @name AzionApplicationsClient.getApplications * @param {Object} params - The parameters for retrieving applications. * @param {AzionApplicationCollectionOptions} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} A promise that resolves with a collection of applications or an error. * * @example * const { error, data } = await applicationClient.getApplications({ * params: { page: 1, page_size: 20 }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Retrieved applications:', data.results); * } */ getApplications: (params: { params?: AzionApplicationCollectionOptions; options?: AzionClientOptions$1; }) => Promise>; /** * Updates an existing Azion Edge Application. * * @function * @name AzionApplicationsClient.putApplication * @param {Object} params - The parameters for updating an application. * @param {number} params.applicationId - The ID of the application to update. * @param {ApiUpdateApplicationPayload} params.data - The updated data for the application. * @returns {Promise>} A promise that resolves with the updated application data or an error. * * @example * const { error, data } = await applicationClient.putApplication({ * applicationId: 123, * data: { * name: 'Updated Application', * delivery_protocol: 'https' * }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Updated application:', data); * } */ putApplication: (params: { applicationId: number; data: ApiUpdateApplicationPayload; options?: AzionClientOptions$1; }) => Promise>; /** * Deletes an Azion Edge Application. * * @function * @name AzionApplicationsClient.deleteApplication * @param {Object} params - The parameters for deleting an application. * @param {number} params.applicationId - The ID of the application to delete. * @returns {Promise>} A promise that resolves when the application is deleted or rejects with an error. * * @example * const { error, data } = await applicationClient.deleteApplication({ * applicationId: 123, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Application deleted successfully'); * } */ deleteApplication: (params: { applicationId: number; options?: AzionClientOptions$1; }) => Promise>; /** * Partially updates an existing Azion Edge Application. * * @function * @name AzionApplicationsClient.patchApplication * @param {Object} params - The parameters for partially updating an application. * @param {number} params.applicationId - The ID of the application to update. * @param {Partial} params.data - The partial data for updating the application. * @returns {Promise>} A promise that resolves with the updated application data or an error. * * @example * const { error, data } = await applicationClient.patchApplication({ * applicationId: 123, * data: { name: 'Partially Updated Application' }, * options: { debug: true } * }); * if (error) { * console.error('Error:', error); * } else { * console.log('Partially updated application:', data); * } */ patchApplication: (params: { applicationId: number; data: Partial; options?: AzionClientOptions$1; }) => Promise>; } interface AzionPurgeResponse { data?: T; error?: { message: string; operation: string; }; } interface AzionPurge { state: 'executed' | 'pending'; items: string[]; } interface AzionPurgeClient { /** * Purge a URL from the Azion Edge cache. * * @param {string[]} url - URLs to purge. * @param {AzionClientOptions} [options] - Client options including debug mode. * @returns {Promise>} The purge response or error if the purge failed. * * @example * const { data: response, error } = await purgeClient.purgeURL(['http://www.domain.com/path/image.jpg'], { debug: true }); * if (response) { * console.log('Purge successful:', response); * } else { * console.error('Purge failed', error); * } */ purgeURL: (urls: string[]) => Promise>; /** * Purge a Cache Key from the Azion Edge cache. * * @param {string[]} cacheKey - Cache Keys to purge. * @param {AzionClientOptions} [options] - Client options including debug mode. * @returns {Promise>} The purge response or error if the purge failed. * * @example * const { data: response, error } = await purgeClient.purgeCacheKey(['http://www.domain.com/path/image.jpg'], { debug: true }); * if (response) { * console.log('Purge successful:', response); * } else { * console.error('Purge failed', error); * } */ purgeCacheKey: (cacheKeys: string[]) => Promise>; /** * Purge using a wildcard expression from the Azion Edge cache. * * @param {string[]} wildcard - Wildcard expressions to purge. * @param {AzionClientOptions} [options] - Client options including debug mode. * @returns {Promise>} The purge response or error if the purge failed. * * @example * const { data: response, error } = await purgeClient.purgeWildCard(['http://www.domain.com/path/image.jpg*'], { debug: true }); * if (response) { * console.log('Purge successful:', response); * } else { * console.error('Purge failed', error); * } */ purgeWildCard: (wildcards: string[]) => Promise>; } type JsonObjectQueryExecutionResponse = { results?: { statement?: string; rows: { [key: string]: any; }[]; }[]; }; type AzionDatabaseResponse = { data?: T; error?: { message: string; operation: string; }; }; interface AzionDatabase { id: number; name: string; clientId: string; status: string; createdAt: string; updatedAt: string; deletedAt: string | null; /** * Executes a query or multiple queries on the database. * * @param {string[]} statements - An array of SQL statements to execute. * @param {AzionClientOptions} [options] - Additional options for the query execution. * @returns {Promise} A promise that resolves to the query response or error if the operation faile>d. * * @example * const result = await database.query([ * 'SELECT * FROM users WHERE id = ?', * 'UPDATE users SET last_login = NOW() WHERE id = ?' * ], { debug: true }); */ query: (statements: string[], options?: AzionClientOptions) => Promise>; /** * Executes one or more SQL statements on the database. * * @param {string[]} statements - An array of SQL statements to execute. * @param {AzionClientOptions} [options] - Additional options for the execution. * @returns {Promise} A promise that resolves to the query response or error if the operation faile>d. * * @example * const result = await database.execute([ * 'INSERT INTO users (name, email) VALUES (?, ?)', * 'DELETE FROM old_users WHERE last_login < ?' * ], { force: true }); */ execute: (statements: string[], options?: AzionClientOptions) => Promise>; /** * Retrieves a list of tables in the database. * * @param {AzionClientOptions} [options] - Additional options for listing tables. * @returns {Promise} A promise that resolves to the query response or error if the operation faile>d. * * @example * const { data: tables, error } = await database.getTables({ debug: true }); */ getTables: (options?: AzionClientOptions) => Promise>; } type QueryResult = { columns?: string[]; rows?: (number | string)[][]; statement?: string; }; type AzionDatabaseQueryResponse = { state?: 'pending' | 'failed' | 'executed' | 'executed-runtime'; results?: QueryResult[]; toObject: () => JsonObjectQueryExecutionResponse | null; }; type AzionDatabaseCollections = { databases?: AzionDatabase[]; count?: number; }; type AzionDatabaseDeleteResponse = { state: 'pending' | 'failed' | 'executed'; id: number; }; interface AzionSQLClient { /** * Creates a new database with the specified name. * * @param {string} name - Name of the database to create. * @returns {Promise} Object confirming creation of the database or an error message. * * @example * const { data, error } = await sqlClient.createDatabase('my-db'); * if (data) { * console.log(`Database ${data.name} created successfully`); * } else { * console.error(`Failed to create database: ${error.message}`); * */ createDatabase: (name: string) => Promise>; /** * Deletes a database by its ID. * * @param {number} id - ID of the database to delete. * @returns {Promise>} Object confirming deletion or error if the operation failed. * * @example * const { data, error } = await sqlClient.deleteDatabase(123); * if (data) { * console.log(`Database ${data.name} (ID: ${data.id}) deleted successfully`); * } else { * console.error(`Failed to delete database: ${error.message}`); * */ deleteDatabase: (id: number) => Promise>; /** * Retrieves a database by its Name. * * @param {string} name - Name of the database to retrieve. * @returns {Promise>} The retrieved database object or null if not found. * * @example * const { data, error } = await sqlClient.getDatabase('my-db'); * if (data) { * console.log(`Retrieved database ${data.name} (ID: ${data.id})`); * } else { * console.error(`Failed to retrieve database: ${error.message}`); * */ getDatabase: (name: string) => Promise>; /** * Retrieves a list of databases with optional filtering and pagination. * * @param {AzionDatabaseCollectionOptions} [params] - Optional parameters for filtering and pagination. * @param {string} [params.ordering] - Field to order the results by. * @param {number} [params.page] - Page number for pagination. * @param {number} [params.page_size] - Number of items per page. * @param {string} [params.search] - Search term to filter databases. * @returns {Promise} Array of database objects or error message. * * @example * const { data, error } = await sqlClient.getDatabases({ page: 1, page_size: 10, search: 'test' }); * if (data) { * console.log(`Retrieved ${data.length} databases`); * } else { * console.error(`Failed to retrieve databases: ${error.message}`); * */ getDatabases: (params?: { ordering?: string; page?: number; page_size?: number; search?: string; }) => Promise>; } /** * Defines the execution environment for the Azion client. * * @type {('development' | 'staging' | 'production')} * * @property {'development'} development - Development environment for local testing * @property {'staging'} staging - Staging/testing environment * @property {'production'} production - Production environment * * @example * const environment: AzionEnvironment = 'development'; * * @example * const clientOptions = { * env: 'production' as AzionEnvironment * }; */ type AzionEnvironment = 'development' | 'staging' | 'production'; /** * 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. * @property {AzionEnvironment} [env] - Environment to use (dev, stage, prod). * @property {boolean} [external] - Force using external REST API instead of built-in runtime API. * * @example * const options: AzionClientOptions = { * debug: true, * force: false, * env: 'dev', * external: true * }; */ type AzionClientOptions = { /** Enable debug mode for detailed logging */ debug?: boolean; /** Force the operation even if it might be destructive */ force?: boolean; /** Environment to use (dev, stage, prod) */ env?: AzionEnvironment; /** Force using external REST API instead of built-in runtime API */ external?: boolean; }; /** * Edge access configuration for storage buckets. * * @type {'read_only' | 'read_write' | 'restricted'} * @property {'read_only'} read_only - Allows only read operations * @property {'read_write'} read_write - Allows both read and write operations * @property {'restricted'} restricted - Restricted access with limited permissions */ type EdgeAccessType = 'read_only' | 'read_write' | 'restricted'; type AzionStorageResponse = { data?: T; error?: { message: string; operation: string; }; }; /** * Represents an Azion storage bucket with methods to interact with objects. * * @interface AzionBucket * * @property {string} name - The name of the bucket. * @property {EdgeAccessType} edge_access - The edge access configuration for the bucket. * @property {'executed' | 'executed-runtime' | 'pending'} [state] - The current state of the bucket. */ interface AzionBucket { name: string; edge_access: EdgeAccessType; state?: 'executed' | 'executed-runtime' | 'pending'; /** * Retrieves a list of objects in the bucket. * * @param {Object} params - Parameters for retrieving objects. * @param {AzionObjectCollectionParams} params.params - Options for filtering and pagination. * @returns {Promise>} A promise that resolves to an array of bucket objects or error message. * * @example * const { data: objects, error } = await bucket.getObjects({ params: { max_object_count: 100 } }); */ getObjects: (params: { params: AzionObjectCollectionParams; }) => Promise>; /** * Retrieves a specific object from the bucket by its key. * * @param {Object} params - Parameters for retrieving the object. * @param {string} params.key - The key of the object to retrieve. * @returns {Promise>} A promise that resolves to the bucket object or error message. * * @example * const { data: object } = await bucket.getObjectByKey({ key: 'example.txt' }); */ getObjectByKey: (params: { key: string; }) => Promise>; /** * Creates a new object in the bucket. * * @param {Object} params - Parameters for creating the object. * @param {string} params.key - The key for the new object. * @param {string} params.content - The content of the new object. * @param {Object} [params.options] - Additional options for the object. * @param {string} [params.options.content_type] - The content type of the object. * @returns {Promise>} A promise that resolves to the created bucket object or error message. * * @example * const { data: newObject } = await bucket.createObject({ * key: 'new-file.txt', * content: 'Hello, World!', * options: { content_type: 'text/plain' } * }); */ createObject: (params: { key: string; content: string; options?: { content_type?: string; }; }) => Promise>; /** * Updates an existing object in the bucket. * * @param {Object} params - Parameters for updating the object. * @param {string} params.key - The key of the object to update. * @param {string} params.content - The new content for the object. * @param {Object} [params.options] - Additional options for the object. * @param {string} [params.options.content_type] - The new content type for the object. * @returns {Promise>} A promise that resolves to the updated bucket object or error message. * * @example * const { data: updatedObject } = await bucket.updateObject({ * key: 'existing-file.txt', * content: 'Updated content', * options: { content_type: 'text/plain' } * }); */ updateObject: (params: { key: string; content: string; options?: { content_type?: string; }; }) => Promise>; /** * Deletes an object from the bucket. * * @param {Object} params - Parameters for deleting the object. * @param {string} params.key - The key of the object to delete. * @returns {Promise>} A promise that resolves to the deleted bucket object or error if deletion failed. * * @example * const { data: deletedObject, error } = await bucket.deleteObject({ key: 'file-to-delete.txt' }); */ deleteObject: (params: { key: string; }) => Promise>; } interface AzionBucketObject { key: string; state?: 'executed' | 'executed-runtime' | 'pending'; size?: number; last_modified?: string; content_type?: string; content?: string; } interface AzionBucketObjects { objects: AzionBucketObject[]; count: number; } interface AzionDeletedBucketObject { key: string; state?: 'executed' | 'executed-runtime' | 'pending'; } interface AzionDeletedBucket { name: string; state?: 'executed' | 'executed-runtime' | 'pending'; } interface AzionBucketCollection { buckets: AzionBucket[]; count: number; } interface AzionStorageClient { /** * Retrieves a list of buckets with optional filtering and pagination. * @param {Object} params - Parameters for retrieving buckets. * @param {AzionBucketCollectionParams} [params.params] - Optional parameters for filtering and pagination. * @returns {Promise>} Array of buckets or error message. */ getBuckets: (params?: { params?: AzionBucketCollectionParams; }) => Promise>; /** * Creates a new bucket. * @param {Object} params - Parameters for creating a bucket. * @param {string} params.name - Name of the new bucket. * @param {EdgeAccessType} params.edge_access - Edge access configuration for the bucket. * @returns {Promise} The created bucket or error message. */ createBucket: (params: { name: string; edge_access: EdgeAccessType; }) => Promise>; /** * Updates a bucket by its name. * @param {Object} params - Parameters for updating a bucket. * @param {string} params.name - Name of the bucket to update. * @param {EdgeAccessType} params.edge_access - New edge access configuration for the bucket. * @returns {Promise>} The updated bucket or error message. */ updateBucket: (params: { name: string; edge_access: EdgeAccessType; }) => Promise>; /** * Deletes a bucket by its name. * @param {Object} params - Parameters for deleting a bucket. * @param {string} params.name - Name of the bucket to delete. * @returns {Promise>} Confirmation of deletion or error message. */ deleteBucket: (params: { name: string; }) => Promise>; /** * Retrieves a bucket by its name. * @param {Object} params - Parameters for retrieving a bucket. * @param {string} params.name - Name of the bucket to retrieve. * @returns {Promise>} The retrieved bucket or error message. */ getBucket: (params: { name: string; }) => Promise>; } type AzionBucketCollectionParams = { page?: number; page_size?: number; }; type AzionObjectCollectionParams = { max_object_count?: number; }; /** * Azion Client interface containing all available service clients. * * @interface AzionClient * * @property {AzionStorageClient} storage - Client for Azion Edge Storage operations. * @property {AzionSQLClient} sql - Client for Azion Edge SQL database operations. * @property {AzionPurgeClient} purge - Client for Azion Edge Purge operations. * @property {AzionDomainsClient} domains - Client for Azion Edge Domains operations. * @property {AzionApplicationsClient} applications - Client for Azion Edge Application operations. * @property {AzionAIClient} ai - Client for Azion AI operations. */ interface AzionClient { /** * Storage client with methods to interact with Azion Edge Storage. * * @type {AzionStorageClient} * * @example * // Create a new bucket * const newBucket = await client.storage.createBucket({ name: 'my-new-bucket', edge_access: 'public' }); * * @example * // Get all buckets * const { data: allBuckets } = await client.storage.getBuckets({ params: { page: 1, page_size: 10 } }); * * @example * // Get a specific bucket and perform operations * const { data: bucket } = await client.storage.getBucket({ name: 'my-bucket' }); * if (bucket) { * // Upload a new object * const { data: newObject } = await bucket.createObject({ key: 'example.txt', content: 'Hello, World!' }); * * // Get all objects in the bucket * const { data: objectsResult } = await bucket.getObjects({ params: { page: 1, page_size: 10 } }); * * // Get a specific object * const { data: object, error } = await bucket.getObjectByKey({ key: 'example.txt' }); * * // Update an object * const { data: updatedObject } = await bucket.updateObject({ key: 'example.txt', content: 'Updated content' }); * * // Delete an object * const { data: deletedObject } = await bucket.deleteObject({ key: 'example.txt' }); * } * * @example * // Delete a bucket * const deletedBucket = await client.storage.deleteBucket({ name: 'my-bucket' }); */ storage: AzionStorageClient; /** * SQL client with methods to interact with Azion Edge SQL databases. * * @type {AzionSQLClient} * * @example * // Create a new database * const { data: newDatabase } = await client.sql.createDatabase('my-new-db'); * * @example * // Get all databases * const { data, error } = await client.sql.getDatabases(); * * @example * // Get a specific database and perform operations * const { data: db, error } = await client.sql.getDatabase('my-db'); * if (db) { * // Execute a query * const queryResult = await db.query(['SELECT * FROM users WHERE id = ?', 1]); * * // Execute multiple statements * const executeResult = await db.execute([ * 'INSERT INTO users (name, email) VALUES (?, ?)', * 'UPDATE users SET last_login = NOW() WHERE id = ?' * ], ['John Doe', 'john@example.com', 1]); * * // List tables in the database * const tables = await db.getTables(); * } * * @example * // Delete a database * const { data, error } = await client.sql.deleteDatabase(123); // Using database ID */ sql: AzionSQLClient; /** * Purge client with methods to interact with Azion Edge Purge. * * @type {AzionPurgeClient} * * @example * // Purge a URL * const purgeResult = await client.purge.purgeURL(['http://example.com/image.jpg']); */ purge: AzionPurgeClient; domains: AzionDomainsClient; /** * Edge Application client with methods to interact with Azion Edge Applications. * * @type {AzionApplicationsClient} * * @example * // Create a new Edge Application * const { data: newApp } = await client.applications.createApplication({ * data: { * name: 'My New App', * delivery_protocol: 'http', * origin_type: 'single_origin', * address: 'example.com' * } * }); * * @example * // Get all Edge Applications * const { data: allApps } = await client.applications.getApplications({ * params: { page: 1, page_size: 20, sort: 'name', order_by: 'asc' } * }); * * @example * // Get a specific Edge Application and perform operations * const { data: app } = await client.applications.getApplication({ applicationId: 123 }); * if (app) { * // Create a new cache setting * const { data: newCacheSetting } = await app.cache.createCacheSetting({ * data: { name: 'My Cache Setting', browser_cache_settings: 'override' } * }); * * // Create a new origin * const { data: newOrigin } = await app.origins.createOrigin({ * data: { name: 'My Origin', addresses: [{ address: 'api.example.com' }] } * }); * * // Create a new rule * const { data: newRule } = await app.rules.request.createRule({ * data: { * name: 'My Rule', * behaviors: [{ name: 'set_origin', target: newOrigin.id }], * criteria: [{ condition: 'starts_with', variable: '${uri}', input: '/api' }] * } * }); * * // Create a new function instance * const { data: newFunction } = await app.functions.createFunctionInstance({ * data: { * name: 'My Function Instance', * edge_function_id: 1234, * args: {} * } * }); * } * * @example * // Update an Edge Application * const { data: updatedApp } = await client.applications.putApplication({ * applicationId: 123, * data: { name: 'Updated App Name', delivery_protocol: 'https' } * }); * * @example * // Delete an Edge Application * const { data: deletedApp } = await client.applications.deleteApplication({ applicationId: 123 }); */ applications: AzionApplicationsClient; /** * AI client with methods to interact with Azion AI services. * * @type {AzionAIClient} * * @example * // Using the chat method * const { data, error } = await client.ai.chat({ * messages: [{ role: 'user', content: 'Explique a computação quântica' }] * }); * if (data) { * console.log('Resposta da IA:', data.choices[0].message.content); * } else if (error) { * console.error('Erro:', error.message); * } * * @example * // Using the streamChat method * const stream = client.ai.streamChat({ * messages: [{ role: 'user', content: 'Escreva um poema sobre IA' }] * }); * for await (const { data, error } of stream) { * if (data) { * process.stdout.write(data.choices[0].delta.content || ''); * } else if (error) { * console.error('Erro de stream:', error.message); * } * } */ ai: AzionAIClient; } /** * Configuration options for creating an Azion client. * * @interface AzionClientConfig * * @property {string} [token] - The authentication token for Azion API. If not provided, * the client will attempt to use the AZION_TOKEN environment variable. * * @property {AzionClientOptions} [options] - Additional options for configuring the client. * @property {boolean} [options.debug] - Enable debug mode for detailed logging. * * @example * // Create a client with a token and debug mode enabled * const config: AzionClientConfig = { * token: 'your-api-token', * options: { debug: true } * }; * const client = createClient(config); * * @example * // Create a client using environment variables for token and default options * const client = createClient(); */ interface AzionClientConfig { token?: string; options?: AzionClientOptions; } /** * Creates an Azion Client with methods to interact with Azion services * * @param {AzionClientConfig} [config] - Client configuration options. * @param {string} [config.token] - Authentication token for Azion API. * @param {boolean} [config.debug=false] - Enable debug mode for detailed logging. * @returns {AzionClient} An object containing SQL, Storage, Purge, Edge Application, and AI clients. * * @example * // Create a client with a token and debug mode enabled * const client = createClient({ token: 'your-api-token', options: { debug: true } }); * * @example * // Create a client using environment variables for token * const client = createClient({ options: { debug: true } }); */ declare function createClient({ token, options }?: AzionClientConfig): AzionClient; export { type AzionClient, type AzionClientConfig, convertJsonConfigToObject, createClient, createClient as default, defineConfig, processConfig };