AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. namespace App\StorePlan;
  3. /**
  4. * The single definition of what a "store plan" may contain.
  5. *
  6. * A store plan is the saved design of a store:
  7. * - a theme (colours, fonts, corner radius)
  8. * - one header and one footer, shared by every page
  9. * - one or more pages, each an ordered list of sections. The first page is always "home".
  10. * It belongs to us, not to any AI provider. Whoever writes a plan (a person, Claude,
  11. * DeepSeek, anything later) must produce this shape, and PlanValidator checks it.
  12. *
  13. * Keep this file in step with resources/js/storefront/types.ts.
  14. */
  15. final class PlanSchema
  16. {
  17. public const int VERSION = 2;
  18. /**
  19. * Theme colours every plan must define, as 6-digit hex values.
  20. *
  21. * @var list<string>
  22. */
  23. public const array COLORS = [
  24. 'background',
  25. 'surface',
  26. 'foreground',
  27. 'muted',
  28. 'primary',
  29. 'primaryForeground',
  30. 'accent',
  31. 'border',
  32. ];
  33. /**
  34. * Fonts the storefront can load. Key is what the plan stores, value is the font family name.
  35. *
  36. * @var array<string, string>
  37. */
  38. public const array FONTS = [
  39. 'inter' => 'Inter',
  40. 'dm-sans' => 'DM Sans',
  41. 'poppins' => 'Poppins',
  42. 'manrope' => 'Manrope',
  43. 'space-grotesk' => 'Space Grotesk',
  44. 'playfair-display' => 'Playfair Display',
  45. 'lora' => 'Lora',
  46. 'fraunces' => 'Fraunces',
  47. ];
  48. /**
  49. * How rounded corners are.
  50. *
  51. * @var list<string>
  52. */
  53. public const array RADII = ['none', 'small', 'medium', 'large', 'full'];
  54. /**
  55. * Section types and the layout variants each one supports.
  56. *
  57. * @var array<string, list<string>>
  58. */
  59. public const array SECTIONS = [
  60. 'header' => ['simple', 'centered'],
  61. // centered: text only. split: text beside a photo. image-full: a full-width photo with the text on it.
  62. 'hero' => ['centered', 'split', 'image-full'],
  63. // A row of short reassurances, such as free shipping and secure payment. row: a band. boxed: small cards.
  64. 'trust_bar' => ['row', 'boxed'],
  65. 'product_grid' => ['grid', 'minimal'],
  66. 'featured_product' => ['image-left', 'image-right'],
  67. 'about' => ['simple', 'with-stats'],
  68. 'testimonials' => ['cards', 'single'],
  69. 'faq' => ['list', 'two-column'],
  70. 'newsletter' => ['banner', 'card'],
  71. 'contact' => ['simple', 'card'],
  72. 'footer' => ['simple', 'centered'],
  73. ];
  74. /**
  75. * Section types a page may contain. The header and footer are not here:
  76. * they live once at the top of the plan and appear on every page.
  77. *
  78. * @return array<string, list<string>>
  79. */
  80. public static function pageSections(): array
  81. {
  82. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  83. }
  84. /** What a trust row item can be. */
  85. public const array TRUST_KINDS = ['shipping', 'payment', 'whatsapp', 'custom'];
  86. /** Icons a trust row item may use. */
  87. public const array TRUST_ICONS = ['truck', 'shield', 'chat', 'refresh', 'leaf', 'star', 'gift', 'clock', 'heart', 'award', 'map-pin', 'package'];
  88. /** Sections per page. */
  89. public const int MAX_SECTIONS = 20;
  90. public const int MAX_PAGES = 10;
  91. /**
  92. * Addresses inside a store that are not pages of the plan but still exist, so links to them are fine.
  93. *
  94. * @var list<string>
  95. */
  96. public const array BUILT_IN_PATHS = ['shop', 'products', 'cart'];
  97. /** The first page of every plan. */
  98. public const string HOME_PAGE = 'home';
  99. /**
  100. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  101. *
  102. * @var list<string>
  103. */
  104. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
  105. /**
  106. * Links may only point inside the page, inside the site, or to safe outside targets.
  107. * This blocks things like "javascript:" links.
  108. */
  109. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  110. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  111. public const string PRODUCT_SLUG_PATTERN = '/^[a-z0-9]+(?:-[a-z0-9]+)*$/';
  112. /** Used for both section ids and page ids. */
  113. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  114. /**
  115. * Validation rules for the content of one section type.
  116. * Keys are relative to the section's "content" object.
  117. *
  118. * @return array<string, list<string>>
  119. */
  120. public static function contentRules(string $type): array
  121. {
  122. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  123. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  124. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  125. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  126. return match ($type) {
  127. 'header' => [
  128. 'logoText' => $text(40),
  129. 'links' => ['present', 'array', 'max:6'],
  130. 'links.*.label' => $text(30),
  131. 'links.*.href' => $link,
  132. 'cta' => ['nullable', 'array'],
  133. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  134. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  135. ],
  136. 'hero' => [
  137. 'eyebrow' => $optionalText(60),
  138. 'headline' => $text(120),
  139. 'subheadline' => $text(300),
  140. 'primaryCta' => ['required', 'array'],
  141. 'primaryCta.label' => $text(30),
  142. 'primaryCta.href' => $link,
  143. 'secondaryCta' => ['nullable', 'array'],
  144. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  145. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  146. // "upload:12" (a photo uploaded in the Design tab) or "product:web-address-name" (a product's main photo).
  147. // Null means automatic: the store's own product photos are used.
  148. 'image' => ['nullable', 'string', 'max:140', 'regex:'.HeroImages::PATTERN],
  149. ],
  150. 'product_grid' => [
  151. 'heading' => $text(80),
  152. 'subheading' => $optionalText(200),
  153. 'items' => ['required', 'array', 'min:2', 'max:8'],
  154. 'items.*.name' => $text(80),
  155. 'items.*.price' => $price,
  156. 'items.*.badge' => $optionalText(20),
  157. ],
  158. 'featured_product' => [
  159. 'eyebrow' => $optionalText(60),
  160. 'name' => $text(80),
  161. 'description' => $text(500),
  162. 'price' => $price,
  163. 'bullets' => ['present', 'array', 'max:5'],
  164. 'bullets.*' => $text(100),
  165. 'cta' => ['required', 'array'],
  166. 'cta.label' => $text(30),
  167. 'cta.href' => $link,
  168. // The web-address name of one of the store's real products. When set, the store shows that
  169. // product's real name, price and photo instead of "name" and "price" above.
  170. 'productSlug' => ['nullable', 'string', 'max:120', 'regex:'.self::PRODUCT_SLUG_PATTERN],
  171. ],
  172. 'about' => [
  173. 'heading' => $text(80),
  174. 'body' => $text(1200),
  175. 'stats' => ['present', 'array', 'max:4'],
  176. 'stats.*.value' => $text(12),
  177. 'stats.*.label' => $text(40),
  178. ],
  179. 'trust_bar' => [
  180. 'items' => ['required', 'array', 'min:2', 'max:4'],
  181. // shipping, payment and whatsapp are written by the store itself from its real settings, so they
  182. // stay true when the merchant changes them. custom uses the title and text below.
  183. 'items.*.kind' => ['required', 'string', 'in:'.implode(',', self::TRUST_KINDS)],
  184. 'items.*.icon' => ['nullable', 'string', 'in:'.implode(',', self::TRUST_ICONS)],
  185. 'items.*.title' => ['required_if:items.*.kind,custom', 'nullable', 'string', 'max:40'],
  186. 'items.*.text' => ['nullable', 'string', 'max:80'],
  187. ],
  188. 'testimonials' => [
  189. 'heading' => $text(80),
  190. 'items' => ['required', 'array', 'min:1', 'max:6'],
  191. 'items.*.quote' => $text(400),
  192. 'items.*.name' => $text(60),
  193. 'items.*.role' => $optionalText(60),
  194. ],
  195. 'faq' => [
  196. 'heading' => $text(80),
  197. 'items' => ['required', 'array', 'min:1', 'max:10'],
  198. 'items.*.question' => $text(160),
  199. 'items.*.answer' => $text(600),
  200. ],
  201. 'newsletter' => [
  202. 'heading' => $text(80),
  203. 'body' => $optionalText(240),
  204. 'placeholder' => $text(40),
  205. 'buttonLabel' => $text(30),
  206. ],
  207. 'contact' => [
  208. 'heading' => $text(80),
  209. 'body' => $optionalText(300),
  210. 'email' => ['nullable', 'email', 'max:120'],
  211. 'phone' => $optionalText(30),
  212. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  213. 'address' => $optionalText(200),
  214. ],
  215. 'footer' => [
  216. 'text' => $text(160),
  217. 'links' => ['present', 'array', 'max:8'],
  218. 'links.*.label' => $text(30),
  219. 'links.*.href' => $link,
  220. ],
  221. default => [],
  222. };
  223. }
  224. }