| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- // import { parseCsv } from './helper';
- export const CACHE_KEY = {
- homeTheme: "collection-homepage",
- headerMenus: "header-menus",
- footerLink: "footer-link",
- };
- /**
- * Caching Tags for caching
- */
- export const TAGS = {
- collections: "collections",
- products: "products",
- cart: "cart",
- carDetail: "carDetail",
- address: "address",
- themeCustomize: "themeCustomize",
- defaultChannel: "channel",
- };
- /**
- * Checkout Caching Tags
- */
- export const CHECKOUT = {
- shipping: "collections",
- method: "products",
- cart: "cart",
- };
- export const HIDDEN_PRODUCT_TAG = "nextjs-frontend-hidden";
- export const DEFAULT_OPTION = "Default Title";
- export const BAGISTO_GRAPHQL_API_ENDPOINT = "/api/graphql";
- export const BAGISTO_REST_API_ENDPOINT = "/api/shop";
- /**
- * 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 BAGISTO_SESSION = process.env.BAGISTO_SESSION ?? "bagisto_session";
- export const TOKEN = "token";
- export const BASE_URL = process.env.NEXTAUTH_URL;
- export const baseUrl = process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT;
- export const GRAPHQL_URL = `${(process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT || '').replace(/\/$/, '')}${BAGISTO_GRAPHQL_API_ENDPOINT}`;
- export const REST_API_URL = `${(process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT || '').replace(/\/$/, '')}${BAGISTO_REST_API_ENDPOINT}`;
- export const NEXT_AUTH_SECRET = process.env.NEXTAUTH_SECRET;
- // Server-only: Use non-public env var, fallback to public for backwards compatibility
- export const STOREFRONT_KEY = process.env.BAGISTO_STOREFRONT_KEY || process.env.NEXT_PUBLIC_BAGISTO_STOREFRONT_KEY || "";
- export const OPERATION_TO_ROUTE_MAP: Record<string, string> = {
- };
- // -----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 SIGNUP_IMG = "/image/sign-in.webp";
- export const SIGNIN_IMG = "/image/login.webp";
- export const FORGET_PASSWORD_IMG = "/image/forget-password.webp";
- 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 const configHeader = [
- // Security headers for all routes
- {
- source: "/:path*",
- headers: [
- { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
- { key: "X-Frame-Options", value: "DENY" },
- { key: "X-Content-Type-Options", value: "nosniff" },
- { key: "X-XSS-Protection", value: "1; mode=block" },
- {
- key: "Permissions-Policy",
- value:
- "camera=(), microphone=(), geolocation=(), browsing-topics=()",
- },
- ],
- },
- // Cache dynamic pages - shorter cache for frequently updated content
- {
- source: "/category/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, s-maxage=3600, stale-while-revalidate=86400",
- },
- ],
- },
- {
- source: "/product/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, s-maxage=3600, stale-while-revalidate=86400",
- },
- {
- key: "Vary",
- value: "Accept-Encoding",
- },
- ],
- },
- {
- source: "/checkout/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "private, no-cache, no-store, must-revalidate",
- },
- ],
- },
- {
- source: "/customer/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "private, no-cache, no-store, must-revalidate",
- },
- ],
- },
- // Next.js static assets - long cache with immutable
- {
- source: "/_next/static/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, max-age=31536000, immutable",
- },
- ],
- },
- {
- source: "/_next/image/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, max-age=31536000, immutable",
- },
- ],
- },
- // Public folder assets - long cache
- {
- source: "/image/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, max-age=31536000, immutable",
- },
- ],
- },
- {
- source: "/fonts/:path*",
- headers: [
- {
- key: "Cache-Control",
- value: "public, max-age=31536000, immutable",
- },
- ],
- },
- ]
- export const imageProtocol = (process.env.NEXT_SERVER_MAGENTO_PROTOCOL ||
- "https") as "http" | "https";
- export function getImageUrl(url?: string, baseUrl?: string, 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 GUEST_CART_TOKEN = "guest_cart_token";
- export const GUEST_CART_ID = "guest_cart_id";
- export const IS_GUEST = "is_guest";
- 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}$/;
|