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>
149 lines • 4.95 kB
TypeScript
/**
* c15t backend implementation of the consent client interface.
* This client makes HTTP requests to the c15t consent management backend.
*/
import type { ConsentManagerCallbacks, ConsentManagerInterface, SetConsentRequestBody, SetConsentResponse, ShowConsentBannerResponse, VerifyConsentRequestBody, VerifyConsentResponse } from './client-interface';
import { type FetchOptions, type ResponseContext, type RetryConfig } from './types';
/**
* Configuration options for the c15t backend client
*/
export interface C15tClientOptions {
/**
* Backend URL for API endpoints. Can be absolute or relative.
*
* @default '/api/c15t'
*/
backendURL: string;
/**
* Additional HTTP headers to include in all API requests.
*/
headers?: Record<string, string>;
/**
* A custom fetch implementation to use instead of the global fetch.
*/
customFetch?: typeof fetch;
/**
* Global callbacks for handling API responses.
*/
callbacks?: ConsentManagerCallbacks;
/**
* CORS mode for fetch requests.
* @default 'cors'
*/
corsMode?: RequestMode;
/**
* Global retry configuration for fetch requests.
* Can be overridden per request in `FetchOptions`.
* @default { maxRetries: 3, initialDelayMs: 100, backoffFactor: 2, retryableStatusCodes: [500, 502, 503, 504] }
*/
retryConfig?: RetryConfig;
}
/**
* c15t backend implementation of the consent client interface.
* Makes HTTP requests to the c15t consent management backend.
*/
export declare class C15tClient implements ConsentManagerInterface {
/**
* Base URL for API requests (without trailing slash)
* @internal
*/
private backendURL;
/**
* Default headers to include with all requests
* @internal
*/
private headers;
/**
* Custom fetch implementation (if provided)
* @internal
*/
private customFetch?;
/**
* Callback functions for client events
* @internal
*/
private callbacks?;
/**
* CORS mode for fetch requests
* @internal
*/
private corsMode;
/**
* Global retry configuration for fetch requests.
* @internal
*/
private retryConfig;
/**
* Creates a new c15t client instance.
*
* @param options - Configuration options for the client
*/
constructor(options: C15tClientOptions);
/**
* Resolves a URL path against the backend URL, handling both absolute and relative URLs.
*
* @param backendURL - The backend URL (can be absolute or relative)
* @param path - The path to append
* @returns The resolved URL string
*/
private resolveUrl;
/**
* 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 response context object for success or error cases.
*/
private createResponseContext;
/**
* Makes an HTTP request to the API with retry logic.
*/
private fetcher;
/**
* Checks if a consent banner should be shown.
* If the API request fails, falls back to offline mode behavior.
*/
showConsentBanner(options?: FetchOptions<ShowConsentBannerResponse>): Promise<ResponseContext<ShowConsentBannerResponse>>;
/**
* Provides offline mode fallback for showConsentBanner API.
* Simulates the behavior of OfflineClient when API requests fail.
* @internal
*/
private offlineFallbackForConsentBanner;
/**
* Sets consent preferences for a subject.
* If the API request fails, falls back to offline mode behavior.
*/
setConsent(options?: FetchOptions<SetConsentResponse, SetConsentRequestBody>): Promise<ResponseContext<SetConsentResponse>>;
/**
* Provides offline mode fallback for setConsent API.
* Simulates the behavior of OfflineClient when API requests fail.
* @internal
*/
private offlineFallbackForSetConsent;
/**
* Verifies if valid consent exists.
*/
verifyConsent(options?: FetchOptions<VerifyConsentResponse, VerifyConsentRequestBody>): Promise<ResponseContext<VerifyConsentResponse>>;
/**
* Makes a custom API request to any endpoint.
*/
$fetch<ResponseType, BodyType = unknown, QueryType = unknown>(path: string, options?: FetchOptions<ResponseType, BodyType, QueryType>): Promise<ResponseContext<ResponseType>>;
/**
* Check for pending consent submissions on initialization
* @internal
*/
private checkPendingConsentSubmissions;
/**
* Process pending consent submissions
* @internal
*/
private processPendingSubmissions;
}
//# sourceMappingURL=client-c15t.d.ts.map