import { env } from '@/env'; export const HIDDEN_PRODUCT_TAG = "nextjs-frontend-hidden"; export const DEFAULT_OPTION = "Default Title"; /** * productJsonLd constant */ export const BASE_SCHEMA_URL = "https://schema.org"; export const PRODUCT_TYPE = "Product"; export const PRODUCT_OFFER_TYPE = "AggregateOffer"; /** * cookies constant */ export const TOKEN = "token"; // -----Pagination--------// export const PAGE = "page"; export const LIMIT = "limit"; export const LOADING = "loading"; export const QUERY = "q"; export const SORT = "sort"; /** * Placeholder Images */ export const NOT_IMAGE = "/image/placeholder.webp"; export const LOGO_IMG = "/image/logo.png"; export const variants = { hidden: { opacity: 0, y: 50 }, visible: { opacity: 1, y: 0 }, }; export function getImageUrl(url?: string, baseUrl: string = env.NEXT_PUBLIC_BAGISTO_ENDPOINT, fallback: string = NOT_IMAGE) { if (!url) return fallback; if (url.startsWith("http://") || url.startsWith("https://")) { return url; } return `${baseUrl}${url.startsWith("/") ? url : `/${url}`}`; } export type SortOrderTypes = { key: string; title: string; value: string; sortKey: string; reverse: boolean; }; export const SortByFields: SortOrderTypes[] = [ { key: "name-asc", title: "From A-Z", value: "name-asc", sortKey: "TITLE", reverse: false, }, { key: "name-desc", title: "From Z-A", value: "name-desc", sortKey: "TITLE", reverse: true, }, { key: "newest", title: "Newest First", value: "newest", sortKey: "CREATED_AT", reverse: true, }, { key: "oldest", title: "Oldest First", value: "oldest", sortKey: "CREATED_AT", reverse: false, }, { key: "price-asc", title: "Cheapest First", value: "price-asc", sortKey: "PRICE", reverse: false, }, { key: "price-desc", title: "Expensive First", value: "price-desc", sortKey: "PRICE", reverse: true, }, ]; export const newSortByFields: SortOrderTypes[] = [ { key: "featured", title: "Featured", value: "featured", sortKey: "FEATURED", reverse: false, }, { key: "best-selling", title: "Best Selling", value: "best-selling", sortKey: "BEST_SELLING", reverse: false, }, { key: "newest", title: "Newest First", value: "newest", sortKey: "NEWEST", reverse: false, }, { key: "oldest", title: "Oldest First", value: "oldest", sortKey: "OLDEST", reverse: false, }, { key: "price-asc", title: "Cheapest First", value: "price-asc", sortKey: "PRICE", reverse: false, }, { key: "price-desc", title: "Expensive First", value: "price-desc", sortKey: "PRICE", reverse: true, }, ]; export const DEFAULT_EXPIRES_DAYS = 7; // cookie里的 GUEST_CART_TOKEN GUEST_CART_ID IS_GUEST 的过期时间 const sameSite: boolean | "lax" | "none" | "strict" | undefined = "lax"; export const GUEST_COOKIE_OPTION = { httpOnly: true, maxAge: DEFAULT_EXPIRES_DAYS * 24 * 3600, encode: true, // 默认编码,更加安全 path: '/', // domain:, secure: env.NEXT_PUBLIC_APP_ENV !== 'development', sameSite: sameSite, }; export const GUEST_CART_TOKEN = "guest_cart_token"; export const GUEST_CART_ID = "guest_cart_id"; export const IS_GUEST = "is_guest"; export const CURRENT_CURRENCY = "current_currency"; export const CURRENT_LOCAL = "current_local"; export const CURRENT_CHANNEL = "current_channel"; export const NEXTAUTH_TOKEN = "next-auth.session-token"; export const NEXTAUTH_SECURE_TOKEN = "__Secure-next-auth.session-token"; export const ORDER_ID = "order_id"; export const EMAIL_REGEX = /^(?![.-])(?!.*[.-]@)(?!.*\.\.)[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/; export const IS_VALID_INPUT = /^[a-zA-Z0-9\s]*$/; export const IS_VALID_ADDRESS = /^[a-zA-Z0-9\s,\/-]*$/; export const IS_VALID_PHONE = /^[0-9]{10}$/; export const IS_VALID_PHONECODE = /^(\+\d+\s|\+\d+\-\d+\s|\+\d+\-\d+and\d+\-\d+\s)/; // +23 / +1-234 / +1-809and1-829 export const IS_VALID_FULL_PHONE = /^(\+\d+\s|\+\d+\-\d+\s|\+\d+\-\d+and\d+\-\d+\s)\d{9,12}$/; export const currencyCountryMap: Record = { "USD": "US", "GBP": "GB", "CAD": "CA", "EUR": "", "AUD": "AU", "ZAR": "ZA" }; export const paymentMethodImageMap:Record = { klarna: '/image/payment/klarna.png', afterpay: '/image/payment/afterpay.png', applepay: '/image/payment/applepay.png', paypal_smart_button: '/image/payment/paypal.png', awxafterpay: '/image/payment/afterpay.png', awxklarna: '/image/payment/klarna.png', airwallex: '/image/payment/credit-card.png', default: '/image/payment/cash-icon.png' };