azion
Version:
Azion Packages for Edge Computing.
173 lines (170 loc) • 6.79 kB
text/typescript
interface AzionPurgeResponse<T> {
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<AzionPurgeResponse<AzionPurge>>} 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<AzionPurgeResponse<AzionPurge>>;
/**
* 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<AzionPurgeResponse<AzionPurge>>} 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<AzionPurgeResponse<AzionPurge>>;
/**
* 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<AzionPurgeResponse<AzionPurge>>} 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<AzionPurgeResponse<AzionPurge>>;
}
/**
* Function type for creating an Azion Purge Client.
*
* @param {Object} [config] - Configuration options for the Purge client.
* @param {string} [config.token] - Authentication token for Azion API. If not provided,
* the client will attempt to use the AZION_TOKEN environment variable.
* @param {AzionClientOptions} [config.options] - Additional client options.
*
* @returns {AzionPurgeClient} An instance of the Azion Purge Client.
*
* @example
* // Create a Purge client with a token and debug mode enabled
* const purgeClient = createAzionPurgeClient({
* token: 'your-api-token',
* options: { debug: true }
* });
*
* @example
* // Create a Purge client using environment variables for token
* const purgeClient = createAzionPurgeClient();
*/
type CreateAzionPurgeClient = (config?: Partial<{
token: string;
options?: AzionClientOptions;
}>) => AzionPurgeClient;
/**
* 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 = {
debug?: boolean;
force?: boolean;
};
/**
* Purge a URL from the Azion Edge cache.
*
* @param {string[]} url - URLs to purge.
* @param {AzionClientOptions} [options] - Client options including debug mode.
* @returns {Promise<AzionPurgeResponse<AzionPurge>>} The purge response or null if the purge failed.
*
* @example
* const response = await purgeURL(['http://www.domain.com/path/image.jpg'], { debug: true });
* if (response) {
* console.log('Purge successful:', response);
* } else {
* console.error('Purge failed');
* }
*/
declare const purgeURLWrapper: (url: string[], options?: AzionClientOptions) => Promise<AzionPurgeResponse<AzionPurge>>;
/**
* 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<AzionPurgeResponse<AzionPurge>>} The purge response or null if the purge failed.
*
* @example
* const response = await purgeCacheKey(['http://www.domain.com/path/image.jpg'], { debug: true });
* if (response) {
* console.log('Purge successful:', response);
* } else {
* console.error('Purge failed');
* }
*/
declare const purgeCacheKeyWrapper: (cacheKey: string[], options?: AzionClientOptions) => Promise<AzionPurgeResponse<AzionPurge>>;
/**
* 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<AzionPurgeResponse<AzionPurge>>} The purge response or null if the purge failed.
*
* @example
* const response = await purgeWildCard(['http://www.domain.com/path/image.jpg*'], { debug: true });
* if (response) {
* console.log('Purge successful:', response);
* } else {
* console.error('Purge failed');
* }
*/
declare const purgeWildCardWrapper: (wildcard: string[], options?: AzionClientOptions) => Promise<AzionPurgeResponse<AzionPurge>>;
/**
* Creates a Purge client with methods to interact with Azion Edge Purge.
*
* @param {Partial<{ token: string; options?: AzionClientOptions }>} [config] - Configuration options for the Purge client.
* @returns {AzionPurgeClient} An object with methods to interact with Purge.
*
* @example
* const purgeClient = createClient({ token: 'your-api-token', options: { debug: true } });
*
* // Purge a URL
* const purgeResult = await purgeClient.purgeURL(['http://www.domain.com/path/image.jpg'], { debug: true });
*
* // Purge a Cache Key
* const cacheKeyResult = await purgeClient.purgeCacheKey(['http://www.domain.com/path/image.jpg'], { debug: true });
*
* // Purge using a wildcard
* const wildcardResult = await purgeClient.purgeWildCard(['http://www.domain.com/path/image.jpg*'], { debug: true });
*/
declare const client: CreateAzionPurgeClient;
export { type AzionClientOptions, type AzionPurge, type AzionPurgeClient, type AzionPurgeResponse, type CreateAzionPurgeClient, client as createClient, client as default, purgeCacheKeyWrapper as purgeCacheKey, purgeURLWrapper as purgeURL, purgeWildCardWrapper as purgeWildCard };