UNPKG

@preprio/prepr-nextjs

Version:

Next.js package for Prepr CMS preview functionality with advanced debugging and visual editing capabilities

74 lines (71 loc) 2.58 kB
import { PreprErrorCode, PreprSegment, PreprToolbarProps } from '../types/index.js'; export { default as createPreprMiddleware } from '../middleware/index.js'; import 'next/server'; /** * Custom error class for Prepr-related errors */ declare class PreprError extends Error { readonly code: PreprErrorCode; readonly context?: string | undefined; readonly originalError?: Error | undefined; constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined); } /** * Returns the Prepr Customer ID from the headers * @returns Prepr Customer ID */ declare function getPreprUUID(): Promise<string | null>; /** * Returns the active segment from the headers * @returns Active segment */ declare function getActiveSegment(): Promise<string | null>; /** * Returns the active variant from the headers * @returns Active variant */ declare function getActiveVariant(): Promise<string | null>; /** * Helper function to retrieve all Prepr headers * @returns Object with Prepr headers */ declare function getPreprHeaders(): Promise<Record<string, string>>; /** * Validates a Prepr GraphQL token * @param token - The token to validate * @returns Validation result with error details if invalid */ declare function validatePreprToken(token: string): { valid: boolean; error?: string; }; /** * Checks if the current environment is in preview mode * @returns True if in preview mode */ declare function isPreviewMode(): boolean; /** * Extracts the access token from a Prepr GraphQL URL * @param graphqlUrl - The full Prepr GraphQL URL * @returns The access token or null if invalid * @example * ```typescript * const token = extractAccessToken('https://graphql.prepr.io/abc123') * // Returns: 'abc123' * ``` */ declare function extractAccessToken(graphqlUrl: string): string | null; /** * Fetches the segments from the Prepr API * @param token Prepr GraphQL URL with scope 'segments' * @returns Array of PreprSegment * @throws PreprError if the request fails */ declare function getPreprEnvironmentSegments(token: string): Promise<PreprSegment[]>; /** * Fetches all the necessary previewbar props * @param token Prepr GraphQL URL with scope 'segments' * @returns Object with activeSegment, activeVariant and data */ declare function getToolbarProps(token: string): Promise<PreprToolbarProps>; export { PreprError, extractAccessToken, getActiveSegment, getActiveVariant, getPreprEnvironmentSegments, getPreprHeaders, getPreprUUID, getToolbarProps, isPreviewMode, validatePreprToken };