UNPKG

c15t

Version:

<div align="center"> <img src="https://c15t.com/logo-icon.png" alt="c15t Logo" width="64" height="64" /> <h1>c15t</h1> <p>Transform privacy consent from a compliance checkbox into a fully observable system</p>

106 lines 3.76 kB
/** * Custom implementation of the consent client interface. * This client uses provided handlers instead of making HTTP requests. */ import type { ConsentManagerCallbacks, ConsentManagerInterface, SetConsentRequestBody, SetConsentResponse, ShowConsentBannerResponse, VerifyConsentRequestBody, VerifyConsentResponse } from './client-interface'; import type { FetchOptions, ResponseContext } from './types'; /** * Handler function for a specific endpoint */ export type EndpointHandler<ResponseType = unknown, BodyType = unknown, QueryType = unknown> = (options?: FetchOptions<ResponseType, BodyType, QueryType>) => Promise<ResponseContext<ResponseType>>; /** * Collection of endpoint handlers */ export interface EndpointHandlers { /** * Handler for the showConsentBanner endpoint */ showConsentBanner: EndpointHandler<ShowConsentBannerResponse>; /** * Handler for the setConsent endpoint */ setConsent: EndpointHandler<SetConsentResponse, SetConsentRequestBody>; /** * Handler for the verifyConsent endpoint */ verifyConsent: EndpointHandler<VerifyConsentResponse, VerifyConsentRequestBody>; } /** * Configuration options for the custom client */ export interface CustomClientOptions { /** * Custom endpoint handlers */ endpointHandlers: EndpointHandlers; /** * Global callbacks for handling responses */ callbacks?: ConsentManagerCallbacks; } /** * Custom implementation of the consent client interface. * Uses provided handlers instead of making HTTP requests. */ export declare class CustomClient implements ConsentManagerInterface { /** * Custom endpoint handlers * @internal */ private endpointHandlers; /** * Dynamic endpoint handlers for custom paths * @internal */ private dynamicHandlers; /** * Callback functions for client events * @internal */ private callbacks?; /** * Creates a new custom client instance. * * @param options - Configuration options for the client */ constructor(options: CustomClientOptions); /** * Returns the client's configured callbacks. * * @returns The callbacks object or undefined if no callbacks are configured */ getCallbacks(): ConsentManagerCallbacks | undefined; /** * Sets the client's callback functions. */ setCallbacks(callbacks: ConsentManagerCallbacks): void; /** * Creates a basic response context for error cases. */ private createErrorResponse; /** * Handles execution of a specific endpoint handler. */ private executeHandler; /** * Checks if a consent banner should be shown. */ showConsentBanner(options?: FetchOptions<ShowConsentBannerResponse>): Promise<ResponseContext<ShowConsentBannerResponse>>; /** * Sets consent preferences for a subject. */ setConsent(options?: FetchOptions<SetConsentResponse, SetConsentRequestBody>): Promise<ResponseContext<SetConsentResponse>>; /** * Verifies if valid consent exists. */ verifyConsent(options?: FetchOptions<VerifyConsentResponse, VerifyConsentRequestBody>): Promise<ResponseContext<VerifyConsentResponse>>; /** * Registers a dynamic endpoint handler */ registerHandler<ResponseType, BodyType = unknown, QueryType = unknown>(path: string, handler: EndpointHandler<ResponseType, BodyType, QueryType>): void; /** * Makes a custom API request to any endpoint. */ $fetch<ResponseType, BodyType = unknown, QueryType = unknown>(path: string, options?: FetchOptions<ResponseType, BodyType, QueryType>): Promise<ResponseContext<ResponseType>>; } //# sourceMappingURL=client-custom.d.ts.map