/** * Core types for Nucleus Generic API Caller */ export type { BaseError, CustomFetchResult, ErrorResponse, HttpMethod, SuccessResponse, } from "@hidayetcanozcan/custom-fetch"; export declare enum GenericMethods { GET = "GET", CREATE = "CREATE", UPDATE = "UPDATE", DELETE = "DELETE", TOGGLE = "TOGGLE", VERIFICATION = "VERIFICATION" } export type PayloadMode = "query" | "body" | "form-data" | "none"; export interface RouteSetting { method: string; checkAuthCookie: boolean; headers: Record; payload_mode: PayloadMode; path: string; } export interface ApiResponse { isSuccess?: boolean; data?: S; errors?: E | null; status?: number; message?: string; } export interface Pagination { page: number; limit: number; total: number; totalPages: number; } export type FactoryPayloadValue = string | number | boolean | null | undefined | Date | Blob | File | ReadonlyArray | { [k: string]: FactoryPayloadValue; }; export interface SchemaDefinition { tablename: string; columns?: Record; excluded_methods?: GenericMethods[]; is_formdata?: boolean; store?: unknown; } export type SchemaCollection = Record; export interface ActionTypeDefinition { payload: unknown; success: unknown; error?: unknown; } export type ActionTypesMap = Record; export interface ActionState { isPending: boolean; data: R | undefined; responseCode: number | null; errors: E | undefined; } export interface StartOptions { payload?: TPayload | FormData; onAfterHandle?: (data: TData | undefined) => void; onErrorHandle?: (error: unknown, code: number | null) => void; disableAutoRedirect?: boolean; } export interface GenericActionEntry { start: (options?: StartOptions) => Promise; state: ActionState | undefined; setState: (next: ActionState | undefined) => void; } export interface CookieOptions { httpOnly?: boolean; maxAge?: number; path?: string; sameSite?: "lax" | "strict" | "none"; secure?: boolean; expires?: Date; domain?: string; priority?: "low" | "medium" | "high"; } export interface CookieHandler { get: (name: string) => { value: string; } | undefined; set: (name: string, value: string, options?: CookieOptions) => void; delete: (name: string) => void; } export interface HeadersHandler { get: (name: string) => string | null; forEach: (callback: (value: string, key: string) => void) => void; } export interface NucleusApiConfig { /** Base URL for API requests */ baseUrl: string; /** Alternative base URL (e.g., external APIs like Vorion) */ alternateBaseUrl?: string; /** Function to determine if endpoint uses alternate URL */ shouldUseAlternateUrl?: (endpoint: string) => boolean; /** Route settings for all endpoints */ settings: Record; /** Auth cookie name (default: nucleus_access_token) */ authCookieName?: string; /** Refresh token cookie name (default: nucleus_refresh_token) */ refreshCookieName?: string; /** Refresh endpoint path (default: /v2/auth/refresh) */ refreshEndpoint?: string; /** Endpoints that skip refresh flow */ refreshExcludedEndpoints?: string[]; /** Endpoints that create auth sessions (don't send existing cookie) */ authCreationEndpoints?: string[]; /** Endpoints that set cookies on success */ cookieSettingEndpoints?: string[]; /** Logout endpoint for frontend cookie cleanup */ logoutEndpoint?: string; /** Enable bypass header for development */ enableBypassHeader?: boolean; /** Debug mode */ debug?: boolean; } export interface HookConfig> { endpoints: TEndpoints; customEndpoints?: Record; schemas?: SchemaCollection; factory: (endpoint: string) => Promise<(payload: unknown, endpoint: string) => Promise>; onStoreUpdate?: (storeKey: string, method: GenericMethods, methodKey: string, data: unknown) => void; routerPush?: (path: string) => void; redirectCodes?: { unauthorized?: string; forbidden?: string; notFound?: string; serverError?: string; }; }