import { BaseResource } from "./base";
import type { Webhook, WebhookPayload, WebhookEvent, WebhookCreateParams, WebhookEventQueryParams } from "../models/webhooks";
import { PostRequestOptions } from "../models";
/**
 * Setter and getter interface to enable external/shared caching of webhook
 * signing keys.
 *
 * Accessor functions may be async (by returning a Promise) or sync (by returning a value).
 *
 * See the project README for example usage.
 *
 * @category API client
 */
export interface WebhookSigningKeyCache {
    get(key: string): string | null | Promise<string | null>;
    set(key: string, value: string): void | Promise<void>;
}
/**
 * @category API client config
 */
export type WebhookCacheConfig = {
    cache: WebhookSigningKeyCache;
    key: string;
    maxAgeMs: number;
};
/**
 * Utilities for managing, retrieving, and validating webhooks.
 *
 * {@link https://developers.akahu.nz/docs/reference-webhooks}
 *
 * @category Resource
 */
export declare class WebhooksResource extends BaseResource {
    private defaultKeyCache;
    /**
     * Gets active webhooks for the user associated with the specified `token`.
     *
     * {@link https://developers.akahu.nz/reference/get_webhooks}
     */
    list(token: string): Promise<Webhook[]>;
    /**
     * Subscribe to a webhook.
     *
     * @returns The newly created webhook id.
     *
     * {@link https://developers.akahu.nz/reference/post_webhooks}
     */
    subscribe(token: string, webhook: WebhookCreateParams, requestOptions?: PostRequestOptions): Promise<string>;
    /**
     * Unsubscribe from a previously created webhook.
     *
     * {@link https://developers.akahu.nz/reference/delete_webhooks-id}
     */
    unsubscribe(token: string, webhookId: string): Promise<void>;
    /**
     * List all webhook events with the specified status in the specified date
     * range (defaults to last 30 days).
     *
     * {@link https://developers.akahu.nz/reference/get_webhook-events}
     */
    listEvents(query: WebhookEventQueryParams): Promise<WebhookEvent[]>;
    /**
     * Get a webhook signing public-key by id.
     *
     * {@link https://developers.akahu.nz/reference/get_keys-id}
     */
    getPublicKey(keyId: string | number): Promise<string>;
    /**
     * Helper to validate a webhook request payload.
     *
     * See the project README for example usage.
     *
     * @returns The deserialized webhook payload after successful validation
     *
     * @throws {@link AkahuWebhookValidationError}
     * if validation of the webhook fails due to invalid signature or expired signing key.
     *
     * @throws {@link AkahuErrorResponse}
     * if the client fails to fetch the specified signing key from the Akahu API.
     *
     * {@link https://developers.akahu.nz/docs/reference-webhooks}
     */
    validateWebhook(keyId: string | number, signature: string, webhookRequestBody: string, cacheConfig?: Partial<WebhookCacheConfig>): Promise<WebhookPayload>;
    /**
     * Get the public key (by id) to validate a webhook signature.
     * The key will be retrieved from cache if possible, falling back to API lookup.
     * If a cached key exists with a newer id, an error will be thrown, as the existence of a newer
     * key implies that the key has been rotated and the requested key is no longer valid.
     *
     * {@link https://developers.akahu.nz/docs/reference-webhooks#caching}
     */
    private _getPublicKey;
    /**
     * Lookup current active public key from the cache.
     * If the key has been in the cache for more than `maxAgeMs` milliseconds, it is considered
     * stale, and will be ignored - causing it to be re-fetched from Akahu. `maxAgeMs` defaults to 24 hours.
     *
     * {@link https://developers.akahu.nz/docs/reference-webhooks#caching}
     */
    private _getPublicKeyFromCache;
    /**
     * Add the public key that has been fetched from the API to the cache.
     *
     * {@link https://developers.akahu.nz/docs/reference-webhooks#caching}
     */
    private _cacheKeyData;
    /**
     * Validate a webhook and associated signature using the public key fetched from the Akahu API.
     *
     * {@link https://developers.akahu.nz/docs/reference-webhooks#verification}
     */
    private _validateWebhookSignature;
}
