constants.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. // import { parseCsv } from './helper';
  2. export const CACHE_KEY = {
  3. homeTheme: "collection-homepage",
  4. headerMenus: "header-menus",
  5. footerLink: "footer-link",
  6. };
  7. /**
  8. * Caching Tags for caching
  9. */
  10. export const TAGS = {
  11. collections: "collections",
  12. products: "products",
  13. cart: "cart",
  14. carDetail: "carDetail",
  15. address: "address",
  16. themeCustomize: "themeCustomize",
  17. defaultChannel: "channel",
  18. };
  19. /**
  20. * Checkout Caching Tags
  21. */
  22. export const CHECKOUT = {
  23. shipping: "collections",
  24. method: "products",
  25. cart: "cart",
  26. };
  27. export const HIDDEN_PRODUCT_TAG = "nextjs-frontend-hidden";
  28. export const DEFAULT_OPTION = "Default Title";
  29. export const BAGISTO_GRAPHQL_API_ENDPOINT = "/api/graphql";
  30. export const BAGISTO_REST_API_ENDPOINT = "/api/shop";
  31. /**
  32. * productJsonLd constant
  33. */
  34. export const BASE_SCHEMA_URL = "https://schema.org";
  35. export const PRODUCT_TYPE = "Product";
  36. export const PRODUCT_OFFER_TYPE = "AggregateOffer";
  37. /**
  38. * cookies constant
  39. */
  40. export const BAGISTO_SESSION = process.env.BAGISTO_SESSION ?? "bagisto_session";
  41. export const TOKEN = "token";
  42. export const BASE_URL = process.env.NEXTAUTH_URL;
  43. export const baseUrl = process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT;
  44. export const GRAPHQL_URL = `${(process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT || '').replace(/\/$/, '')}${BAGISTO_GRAPHQL_API_ENDPOINT}`;
  45. export const REST_API_URL = `${(process.env.NEXT_PUBLIC_BAGISTO_ENDPOINT || '').replace(/\/$/, '')}${BAGISTO_REST_API_ENDPOINT}`;
  46. export const NEXT_AUTH_SECRET = process.env.NEXTAUTH_SECRET;
  47. // Server-only: Use non-public env var, fallback to public for backwards compatibility
  48. export const STOREFRONT_KEY = process.env.BAGISTO_STOREFRONT_KEY || process.env.NEXT_PUBLIC_BAGISTO_STOREFRONT_KEY || "";
  49. export const OPERATION_TO_ROUTE_MAP: Record<string, string> = {
  50. };
  51. // -----Pagination--------//
  52. export const PAGE = "page";
  53. export const LIMIT = "limit";
  54. export const LOADING = "loading";
  55. export const QUERY = "q";
  56. export const SORT = "sort";
  57. /**
  58. * Placeholder Images
  59. */
  60. export const SIGNUP_IMG = "/image/sign-in.webp";
  61. export const SIGNIN_IMG = "/image/login.webp";
  62. export const FORGET_PASSWORD_IMG = "/image/forget-password.webp";
  63. export const NOT_IMAGE = "/image/placeholder.webp";
  64. export const LOGO_IMG = "/image/logo.png";
  65. export const variants = {
  66. hidden: { opacity: 0, y: 50 },
  67. visible: { opacity: 1, y: 0 },
  68. };
  69. export const configHeader = [
  70. // Security headers for all routes
  71. {
  72. source: "/:path*",
  73. headers: [
  74. { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
  75. { key: "X-Frame-Options", value: "DENY" },
  76. { key: "X-Content-Type-Options", value: "nosniff" },
  77. { key: "X-XSS-Protection", value: "1; mode=block" },
  78. {
  79. key: "Permissions-Policy",
  80. value:
  81. "camera=(), microphone=(), geolocation=(), browsing-topics=()",
  82. },
  83. ],
  84. },
  85. // Cache dynamic pages - shorter cache for frequently updated content
  86. {
  87. source: "/category/:path*",
  88. headers: [
  89. {
  90. key: "Cache-Control",
  91. value: "public, s-maxage=3600, stale-while-revalidate=86400",
  92. },
  93. ],
  94. },
  95. {
  96. source: "/product/:path*",
  97. headers: [
  98. {
  99. key: "Cache-Control",
  100. value: "public, s-maxage=3600, stale-while-revalidate=86400",
  101. },
  102. {
  103. key: "Vary",
  104. value: "Accept-Encoding",
  105. },
  106. ],
  107. },
  108. {
  109. source: "/checkout/:path*",
  110. headers: [
  111. {
  112. key: "Cache-Control",
  113. value: "private, no-cache, no-store, must-revalidate",
  114. },
  115. ],
  116. },
  117. {
  118. source: "/customer/:path*",
  119. headers: [
  120. {
  121. key: "Cache-Control",
  122. value: "private, no-cache, no-store, must-revalidate",
  123. },
  124. ],
  125. },
  126. // Next.js static assets - long cache with immutable
  127. {
  128. source: "/_next/static/:path*",
  129. headers: [
  130. {
  131. key: "Cache-Control",
  132. value: "public, max-age=31536000, immutable",
  133. },
  134. ],
  135. },
  136. {
  137. source: "/_next/image/:path*",
  138. headers: [
  139. {
  140. key: "Cache-Control",
  141. value: "public, max-age=31536000, immutable",
  142. },
  143. ],
  144. },
  145. // Public folder assets - long cache
  146. {
  147. source: "/image/:path*",
  148. headers: [
  149. {
  150. key: "Cache-Control",
  151. value: "public, max-age=31536000, immutable",
  152. },
  153. ],
  154. },
  155. {
  156. source: "/fonts/:path*",
  157. headers: [
  158. {
  159. key: "Cache-Control",
  160. value: "public, max-age=31536000, immutable",
  161. },
  162. ],
  163. },
  164. ]
  165. export const imageProtocol = (process.env.NEXT_SERVER_MAGENTO_PROTOCOL ||
  166. "https") as "http" | "https";
  167. export function getImageUrl(url?: string, baseUrl?: string, fallback: string = NOT_IMAGE) {
  168. if (!url) return fallback;
  169. if (url.startsWith("http://") || url.startsWith("https://")) {
  170. return url;
  171. }
  172. return `${baseUrl}${url.startsWith("/") ? url : `/${url}`}`;
  173. }
  174. export type SortOrderTypes = {
  175. key: string;
  176. title: string;
  177. value: string;
  178. sortKey: string;
  179. reverse: boolean;
  180. };
  181. export const SortByFields: SortOrderTypes[] = [
  182. {
  183. key: "name-asc",
  184. title: "From A-Z",
  185. value: "name-asc",
  186. sortKey: "TITLE",
  187. reverse: false,
  188. },
  189. {
  190. key: "name-desc",
  191. title: "From Z-A",
  192. value: "name-desc",
  193. sortKey: "TITLE",
  194. reverse: true,
  195. },
  196. {
  197. key: "newest",
  198. title: "Newest First",
  199. value: "newest",
  200. sortKey: "CREATED_AT",
  201. reverse: true,
  202. },
  203. {
  204. key: "oldest",
  205. title: "Oldest First",
  206. value: "oldest",
  207. sortKey: "CREATED_AT",
  208. reverse: false,
  209. },
  210. {
  211. key: "price-asc",
  212. title: "Cheapest First",
  213. value: "price-asc",
  214. sortKey: "PRICE",
  215. reverse: false,
  216. },
  217. {
  218. key: "price-desc",
  219. title: "Expensive First",
  220. value: "price-desc",
  221. sortKey: "PRICE",
  222. reverse: true,
  223. },
  224. ];
  225. export const GUEST_CART_TOKEN = "guest_cart_token";
  226. export const GUEST_CART_ID = "guest_cart_id";
  227. export const IS_GUEST = "is_guest";
  228. export const NEXTAUTH_TOKEN = "next-auth.session-token";
  229. export const NEXTAUTH_SECURE_TOKEN = "__Secure-next-auth.session-token";
  230. export const ORDER_ID = "order_id";
  231. export const EMAIL_REGEX = /^(?![.-])(?!.*[.-]@)(?!.*\.\.)[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/;
  232. export const IS_VALID_INPUT = /^[a-zA-Z0-9\s]*$/;
  233. export const IS_VALID_ADDRESS = /^[a-zA-Z0-9\s,\/-]*$/;
  234. export const IS_VALID_PHONE = /^[0-9]{10}$/;