import { LocaleUrlStrategy } from '../localization'; import { PzNextRequest } from '../middlewares'; import { NextFetchEvent } from 'next/server'; import { NextURL } from 'next/dist/server/web/next-url'; import { Control, FieldError } from 'react-hook-form'; import { ReactNode } from 'react'; import { UsePaginationType } from '../hooks/use-pagination'; declare global { interface Window { // we did it like this because declare types needs to be identical, if not it will fail // eslint-disable-next-line @typescript-eslint/ban-types dataLayer?: Object[]; [key: string]: any; } } export * from './commerce'; export * from './gtm'; export * from './metadata'; export interface Locale { label: string; /** * Lowercased locale value in `ISO 639-1` format or including country code in `ISO 3166-1 alpha-2` format. * * -- If you use uppercase characters, it will be considered as lowercase. * * *** * @example * value: 'en' * value: 'en-us' * value: 'tr' * * @see https://en.wikipedia.org/wiki/ISO_639-1 * @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 */ value: string; localePath?: string; /** * Corresponding Commerce API value for fetching data. It will be used in `Accept-Language` header. */ apiValue: string; rtl?: boolean; } export interface Currency { /** * It will be used for displaying currency in currency switcher. * Can be symbol, code, etc. * * @example * label: '$' * label: '€' * label: 'USD' * label: 'US Dollar' * label: '$ - USD' */ label: string; /** * Lowercased currency code in `ISO 4217` format. * * It should match with one of the values returned from Commerce API. * * @example * code: 'usd' * code: 'eur' * code: 'try' * * @see https://en.wikipedia.org/wiki/ISO_4217 */ code: string; /** * Number of decimal places to display. * * @example * decimalScale: 3 */ decimalScale?: number; } export interface Settings { webVitals?: { enabled: boolean; }; usePrettyUrlRoute?: boolean; commerceUrl: string; redis: { defaultExpirationTime: number; }; commonProductAttributes: Array<{ translationKey: string; key: string; }>; localization: { locales: Locale[]; currencies: Array; /** * Default locale value in `ISO 639-1` format or including country code in `ISO 3166-1 alpha-2` format. * * It will be used for redirections and fallbacks. * * It should be one of the values in `locales` array. */ defaultLocaleValue: string; /** * Determines url behavior according to locale. * * Available options: * - LocaleUrlStrategy.HideDefaultLocale * - LocaleUrlStrategy.HideAllLocales * - LocaleUrlStrategy.ShowAllLocales * * @default LocaleUrlStrategy.HideDefaultLocale * * @example * // Example configuration * locales: [{ value: 'en'}, { value: 'tr' }] * defaultLocaleValue: 'en' * // ------------------------------- * * LocaleUrlStrategy.HideDefaultLocale: * en -> "/women" * tr -> "/tr/women" * * LocaleUrlStrategy.ShowAllLocales: * en -> "/en/women" * tr -> "/tr/women" * * LocaleUrlStrategy.HideAllLocales: * en -> "/women" * tr -> "/women" */ localeUrlStrategy?: LocaleUrlStrategy; redirectToDefaultLocale?: boolean; defaultCurrencyCode: string; /** * The default behavior of `getActiveCurrencyCode` function is to get active currency code from cookie named `pz-currency`. * * You can use this function to override existing and get currency code from cookie, header, url, etc. * * If return value does not match with any currency code in `currencies` array, default currency code will be used. * * @param req - Incoming request. You can use this to get cookie, header, url, etc. * @param locale - Active locale value. E.g. 'en', 'tr', 'en-us', 'tr-tr' * @param defaultCurrencyCode - Default currency code in `ISO 4217` format. E.g. 'usd', 'eur', 'try' * @returns Currency code in `ISO 4217` format. E.g. 'usd', 'eur', 'try' * * @example * getActiveCurrencyCode: ({ req, locale, defaultCurrencyCode }) => { * const [, countryCode] = locale.split('-'); * * if (countryCode === 'ae') { * return 'aed'; * } else if (countryCode === 'qa') { * return 'qar'; * } * * return defaultCurrencyCode; * } */ getActiveCurrencyCode?: ({ req, locale, defaultCurrencyCode }: { req: PzNextRequest; locale: string; defaultCurrencyCode: string; }) => string; /** * By default, pretty url resolver excludes locale from url. * In some cases, you may want to create flatpages and include locale in urls. * This is useful if you want to manage your flatpages for different countries by using locale value. * * @example * // URL entered in Omnitron: /en-us/pages/about-us * // Locale Strategy: LocaleUrlStrategy.ShowAllLocales * * // If you don't use this option, pretty url resolver will remove the locale and it will be resolved as '/pages/about-us' and you will get 404. Because there is no page with this url. But if you use this option, it will be resolved as '/en-us/pages/about-us' and you will get the page. * // Following pattern will include locale for all urls including '/pages/'. * localeIncludedPrettyUrlPattern: new RegExp('.+/pages/.+$') */ localeIncludedPrettyUrlPattern?: RegExp; }; rewrites?: Array<{ source: string; destination: string; }>; checkout?: { /** * @deprecated All payment options will be excluded from the iframe by default. This option is deprecated and will be removed in future releases. * * If there is a need to exclude certain payment options from the iframe, for instance, due to CORS issues, this option can be utilized by passing the slugs associated with the desired payment options. */ iframeExcludedPaymentOptions?: string[]; /** * If there is a need to include certain payment options in the iframe, this option can be utilized by passing the slugs associated with the desired payment options. */ iframeIncludedPaymentOptions?: string[]; extraPaymentTypes?: string[]; masterpassJsUrl?: string; }; customNotFoundEnabled: boolean; useOptimizedTranslations?: boolean; plugins?: Record>; includedProxyHeaders?: string[]; commerceRedirectionIgnoreList?: string[]; /** * By default, the currency will be reset when the currency is changed. * If you want to keep the basket when the currency is changed, you can set this option to `false`. */ resetBasketOnCurrencyChange?: boolean; frontendIds?: Record; usePzSegment?: boolean; pzSegments?: { separator?: string; segments: PzSegmentDefinition[]; }; } export interface CacheOptions { cache?: boolean; expire?: number; useProxy?: boolean; compressed?: boolean; } export interface SetCookieOptions { expires?: number; // days path?: string; domain?: string; secure?: boolean; sameSite?: 'strict' | 'lax' | 'none'; } export interface ClientRequestOptions { useTrailingSlash?: boolean; useFormData?: boolean; accept?: string; contentType?: string; responseType?: 'json' | 'text'; } export type CDNOptions = { width?: number; height?: number; quality?: number; crop?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'none'; upscale?: boolean; }; export type ImageOptions = CDNOptions & { sources?: Array<{ media: string; options: CDNOptions }>; }; export type Translations = { [key: string]: object }; export interface PzSegmentResolveContext { req: PzNextRequest; event: NextFetchEvent; url: NextURL; locale: string; currency: string; pathname: string; } export interface PzSegmentDefinition { name: string; resolve?: (context: PzSegmentResolveContext) => string; } export interface PzSegmentsConfig { separator: string; segments: PzSegmentDefinition[]; } // Search params type compatible with both Next.js resolved searchParams and URLSearchParams export type SearchParams = Record | URLSearchParams; // Raw Next 16 server prop shape, used at the middleware/HOC boundary before normalization export type RawSearchParams = Record; // Page/Layout props — sync params for backward compatibility with v1 brands. // `searchParams` is always exposed as `URLSearchParams` (matching v1 behavior). // The server HOC normalizes Next 16's raw Record into a URLSearchParams instance. export interface PageProps { params: T & { pz?: string; commerce?: string; locale?: string; currency?: string; url?: string; [key: string]: any; }; searchParams: URLSearchParams; } export interface LayoutProps extends PageProps { children: React.ReactNode; } export interface RootLayoutProps extends LayoutProps { translations: Translations; locale: Locale & { isoCode: string; }; } // Async versions for Next.js 16 generateMetadata and internal use export interface AsyncPageProps { params: Promise; searchParams: Promise<{ [key: string]: string | string[] | undefined }>; } // Resolved (sync) versions for inner components after withSegmentDefaults resolves props export interface ResolvedPageProps { params: T & { locale: string; currency: string }; searchParams: URLSearchParams; } export interface ResolvedLayoutProps extends ResolvedPageProps { children: React.ReactNode; } export interface ResolvedRootLayoutProps< T = { commerce: string; locale: string; currency: string; } > extends ResolvedLayoutProps { translations: Translations; locale: Locale & { isoCode: string; }; } export type RadioProps = React.HTMLProps; export interface AuthError { type: string; data?: any; } export interface IconProps extends React.ComponentPropsWithRef<'i'> { name: string; size?: number; className?: string; } export interface ButtonProps extends React.ButtonHTMLAttributes { appearance?: 'filled' | 'outlined' | 'ghost' | 'link' | string; size?: 'sm' | 'md' | 'lg' | 'xl'; href?: string; target?: '_blank' | '_self' | '_parent' | '_top'; } export interface FileInputProps extends React.HTMLProps { fileClassName?: string; fileNameWrapperClassName?: string; fileInputClassName?: string; onChange?: (event: React.ChangeEvent) => void; buttonClassName?: string; } export interface PriceProps { currencyCode?: string; useCurrencySymbol?: boolean; useCurrencyAfterPrice?: boolean; useCurrencySpace?: boolean; useNegative?: boolean; useNegativeSpace?: boolean; } export interface InputProps extends React.HTMLProps { label?: string; labelStyle?: 'default' | 'floating'; error?: FieldError | undefined; control?: Control; required?: boolean; } export interface AccordionProps { isCollapse?: boolean; collapseClassName?: string; title?: string; subTitle?: string; icons?: string[]; iconSize?: number; iconColor?: string; children?: ReactNode; headerClassName?: string; className?: string; titleClassName?: string; subTitleClassName?: string; dataTestId?: string; contentClassName?: string; } export interface PluginModuleComponentProps { settings?: Record; } export interface PaginationProps { total: number | undefined; limit?: number | undefined; currentPage: number | undefined; numberOfPages?: number | undefined; containerClassName?: string; moreButtonClassName?: string; prevClassName?: string; nextClassName?: string; pageClassName?: string; threshold?: number | undefined; delta?: number | undefined; render?: (pagination: UsePaginationType) => ReactNode; type?: 'infinite' | 'list' | 'more'; onPageChange?: (page: number) => void; direction?: 'next' | 'prev'; isLoading?: boolean; } export interface ModalProps { portalId: string; children?: React.ReactNode; open?: boolean; setOpen?: (open: boolean) => void; title?: React.ReactNode; showCloseButton?: React.ReactNode; className?: string; overlayClassName?: string; headerWrapperClassName?: string; titleClassName?: string; closeButtonClassName?: string; iconName?: string; iconSize?: number; iconClassName?: string; }