constants.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import { env } from '@/env';
  2. export const HIDDEN_PRODUCT_TAG = "nextjs-frontend-hidden";
  3. export const DEFAULT_OPTION = "Default Title";
  4. /**
  5. * productJsonLd constant
  6. */
  7. export const BASE_SCHEMA_URL = "https://schema.org";
  8. export const PRODUCT_TYPE = "Product";
  9. export const PRODUCT_OFFER_TYPE = "AggregateOffer";
  10. /**
  11. * cookies constant
  12. */
  13. export const TOKEN = "token";
  14. // -----Pagination--------//
  15. export const PAGE = "page";
  16. export const LIMIT = "limit";
  17. export const LOADING = "loading";
  18. export const QUERY = "q";
  19. export const SORT = "sort";
  20. /**
  21. * Placeholder Images
  22. */
  23. export const NOT_IMAGE = "/image/placeholder.webp";
  24. export const LOGO_IMG = "/image/logo.png";
  25. export const variants = {
  26. hidden: { opacity: 0, y: 50 },
  27. visible: { opacity: 1, y: 0 },
  28. };
  29. export function getImageUrl(url?: string, baseUrl: string = env.NEXT_PUBLIC_BAGISTO_ENDPOINT, fallback: string = NOT_IMAGE) {
  30. if (!url) return fallback;
  31. if (url.startsWith("http://") || url.startsWith("https://")) {
  32. return url;
  33. }
  34. return `${baseUrl}${url.startsWith("/") ? url : `/${url}`}`;
  35. }
  36. export type SortOrderTypes = {
  37. key: string;
  38. title: string;
  39. value: string;
  40. sortKey: string;
  41. reverse: boolean;
  42. };
  43. export const SortByFields: SortOrderTypes[] = [
  44. {
  45. key: "name-asc",
  46. title: "From A-Z",
  47. value: "name-asc",
  48. sortKey: "TITLE",
  49. reverse: false,
  50. },
  51. {
  52. key: "name-desc",
  53. title: "From Z-A",
  54. value: "name-desc",
  55. sortKey: "TITLE",
  56. reverse: true,
  57. },
  58. {
  59. key: "newest",
  60. title: "Newest First",
  61. value: "newest",
  62. sortKey: "CREATED_AT",
  63. reverse: true,
  64. },
  65. {
  66. key: "oldest",
  67. title: "Oldest First",
  68. value: "oldest",
  69. sortKey: "CREATED_AT",
  70. reverse: false,
  71. },
  72. {
  73. key: "price-asc",
  74. title: "Cheapest First",
  75. value: "price-asc",
  76. sortKey: "PRICE",
  77. reverse: false,
  78. },
  79. {
  80. key: "price-desc",
  81. title: "Expensive First",
  82. value: "price-desc",
  83. sortKey: "PRICE",
  84. reverse: true,
  85. },
  86. ];
  87. export const newSortByFields: SortOrderTypes[] = [
  88. {
  89. key: "featured",
  90. title: "Featured",
  91. value: "featured",
  92. sortKey: "FEATURED",
  93. reverse: false,
  94. },
  95. {
  96. key: "best-selling",
  97. title: "Best Selling",
  98. value: "best-selling",
  99. sortKey: "BEST_SELLING",
  100. reverse: false,
  101. },
  102. {
  103. key: "newest",
  104. title: "Newest First",
  105. value: "newest",
  106. sortKey: "NEWEST",
  107. reverse: false,
  108. },
  109. {
  110. key: "oldest",
  111. title: "Oldest First",
  112. value: "oldest",
  113. sortKey: "OLDEST",
  114. reverse: false,
  115. },
  116. {
  117. key: "price-asc",
  118. title: "Cheapest First",
  119. value: "price-asc",
  120. sortKey: "PRICE",
  121. reverse: false,
  122. },
  123. {
  124. key: "price-desc",
  125. title: "Expensive First",
  126. value: "price-desc",
  127. sortKey: "PRICE",
  128. reverse: true,
  129. },
  130. ];
  131. export const DEFAULT_EXPIRES_DAYS = 7; // cookie里的 GUEST_CART_TOKEN GUEST_CART_ID IS_GUEST 的过期时间
  132. const sameSite: boolean | "lax" | "none" | "strict" | undefined = "lax";
  133. export const GUEST_COOKIE_OPTION = {
  134. httpOnly: true,
  135. maxAge: DEFAULT_EXPIRES_DAYS * 24 * 3600,
  136. encode: true, // 默认编码,更加安全
  137. path: '/',
  138. // domain:,
  139. secure: env.NEXT_PUBLIC_APP_ENV !== 'development',
  140. sameSite: sameSite,
  141. };
  142. export const GUEST_CART_TOKEN = "guest_cart_token";
  143. export const GUEST_CART_ID = "guest_cart_id";
  144. export const IS_GUEST = "is_guest";
  145. export const CURRENT_CURRENCY = "current_currency";
  146. export const CURRENT_LOCAL = "current_local";
  147. export const CURRENT_CHANNEL = "current_channel";
  148. export const NEXTAUTH_TOKEN = "next-auth.session-token";
  149. export const NEXTAUTH_SECURE_TOKEN = "__Secure-next-auth.session-token";
  150. export const ORDER_ID = "order_id";
  151. export const EMAIL_REGEX = /^(?![.-])(?!.*[.-]@)(?!.*\.\.)[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+(\.[a-zA-Z]{2,})+$/;
  152. export const IS_VALID_INPUT = /^[a-zA-Z0-9\s]*$/;
  153. export const IS_VALID_ADDRESS = /^[a-zA-Z0-9\s,\/-]*$/;
  154. export const IS_VALID_PHONE = /^[0-9]{10}$/;
  155. export const IS_VALID_PHONECODE = /^(\+\d+\s|\+\d+\-\d+\s|\+\d+\-\d+and\d+\-\d+\s)/; // +23 / +1-234 / +1-809and1-829
  156. export const IS_VALID_FULL_PHONE = /^(\+\d+\s|\+\d+\-\d+\s|\+\d+\-\d+and\d+\-\d+\s)\d{9,12}$/;
  157. export const currencyCountryMap: Record<string, string> = {
  158. "USD": "US",
  159. "GBP": "GB",
  160. "CAD": "CA",
  161. "EUR": "",
  162. "AUD": "AU",
  163. "ZAR": "ZA"
  164. };
  165. export const paymentMethodImageMap:Record<string, string> = {
  166. klarna: '/image/payment/klarna.png',
  167. afterpay: '/image/payment/afterpay.png',
  168. applepay: '/image/payment/applepay.png',
  169. paypal_smart_button: '/image/payment/paypal.png',
  170. awxafterpay: '/image/payment/afterpay.png',
  171. awxklarna: '/image/payment/klarna.png',
  172. airwallex: '/image/payment/credit-card.png',
  173. default: '/image/payment/cash-icon.png'
  174. };