@datadome/module-nextjs
Version:
DataDome module for Next.js applications
90 lines • 3.95 kB
TypeScript
import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
import { NextRequest } from 'next/server';
import { GraphQLData, RequestData } from './middleware';
/**
* This function is used to attach the list of headers from the DataDome's protection API response to the incoming request.
* This function is mainly used to attach the DataDome's enriched headers.
* @see {@link https://docs.datadome.co/docs/logs-integration} for the available enriched headers.
* @param reqHeaders - The headers of the incoming request.
* @param dataDomeResHeaders - The headers of the DataDome's protection API response.
* @param listKey - The header key we want to retrieve.
* @returns A map of string.
*/
export declare function convertHeadersToMap(reqHeaders: Headers, dataDomeResHeaders: Headers, listKey: string): Map<string, string>;
/**
* This functions is used to return all the headers from the request in a string separated by commas.
* @param req - The incoming request.
* @returns A comma separated list of headers.
*/
export declare function getHeadersList(req: NextRequest): string;
/**
* This function is used to return the length of the Authorization header.
* @param req - The incoming request.
* @returns The length of the Authorization header.
*/
export declare function getAuthorizationLength(req: NextRequest): number | undefined;
/**
* This function is used to create an URL-encoded string of the payload of the Protection API.
* @param obj - The truncated payload for the Protection API.
* @returns An URL-encoded string of the truncated payload.
*/
export declare function stringify(obj: RequestData): string;
/**
* Returns the value of the `datadome` cookie.
* @param cookies - the cookies of the request.
* @returns The Client ID of the request.
*/
export declare function getCookieData(cookies: RequestCookies): string;
/**
* Determine if the incoming request is a GraphQL request
* @param {Object} request
* @param {URL} request.url - The URL of the request.
* @param {string} request.method - The HTTP method of the request.
* @param {boolean} request.bodyExists - Indicate if the request body is present.
* @param {string} request.contentType - The Content-Type of the request.
* @returns {boolean} - Returns `true` if the request is likely a GraphQL request, `false` otherwise.
*/
export declare function isGraphQLRequest({ url, method, bodyExists, contentType, }: {
url: URL;
method: string;
bodyExists: boolean;
contentType: string | null;
}): boolean;
/**
* Returns true if at least one GraphQL operation was detected.
* @param {GraphQLData} graphQLData - GraphQL properties extracted from a request
* @returns {boolean} true if the object contains GraphQL data
*/
export declare function isGraphQLDataAvailable(graphQLData: GraphQLData): boolean;
/**
* Collect the GraphQL information from the request
* @param {NextRequest} request
* @param {URL} fullUrl
* @param {number} maximumBodySize
* @returns {GraphQLData}
*/
export declare function collectGraphQL(request: NextRequest, fullUrl: URL, maximumBodySize: number): Promise<GraphQLData>;
/**
* Parse a Set-Cookie header string and extract cookie attributes.
*
* This function parses all standard Set-Cookie attributes as defined in:
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie
*
* @param cookieString - The Set-Cookie header value (e.g., "name=value; Path=/; Max-Age=3600")
* @returns Parsed cookie data with name, value, and options, or null if invalid
*/
export declare function parseCookieAttributes(cookieString: string): {
name: string;
value: string;
options: {
secure?: boolean;
httpOnly?: boolean;
domain?: string;
path?: string;
sameSite?: 'lax' | 'strict' | 'none';
maxAge?: number;
expires?: Date;
partitioned?: boolean;
};
} | null;
//# sourceMappingURL=utils.d.ts.map