AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PlanSchema.php 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. 'hero' => ['centered', 'split'],
  62. 'product_grid' => ['grid', 'minimal'],
  63. 'featured_product' => ['image-left', 'image-right'],
  64. 'about' => ['simple', 'with-stats'],
  65. 'testimonials' => ['cards', 'single'],
  66. 'faq' => ['list', 'two-column'],
  67. 'newsletter' => ['banner', 'card'],
  68. 'contact' => ['simple', 'card'],
  69. 'footer' => ['simple', 'centered'],
  70. ];
  71. /**
  72. * Section types a page may contain. The header and footer are not here:
  73. * they live once at the top of the plan and appear on every page.
  74. *
  75. * @return array<string, list<string>>
  76. */
  77. public static function pageSections(): array
  78. {
  79. return array_diff_key(self::SECTIONS, ['header' => true, 'footer' => true]);
  80. }
  81. /** Sections per page. */
  82. public const int MAX_SECTIONS = 20;
  83. public const int MAX_PAGES = 10;
  84. /** The first page of every plan. */
  85. public const string HOME_PAGE = 'home';
  86. /**
  87. * Page ids the AI and merchants may not use, because the app has its own pages at these addresses.
  88. *
  89. * @var list<string>
  90. */
  91. public const array RESERVED_PAGE_IDS = ['shop', 'products', 'cart', 'checkout', 'orders', 'account', 'search'];
  92. /**
  93. * Links may only point inside the page, inside the site, or to safe outside targets.
  94. * This blocks things like "javascript:" links.
  95. */
  96. public const string LINK_PATTERN = '/^(#[A-Za-z0-9_-]*|\/(?!\/)[^\s]*|https:\/\/[^\s]+|mailto:[^\s]+|tel:[0-9+\-\s]+)$/';
  97. public const string COLOR_PATTERN = '/^#[0-9A-Fa-f]{6}$/';
  98. /** Used for both section ids and page ids. */
  99. public const string SECTION_ID_PATTERN = '/^[a-z][a-z0-9-]{0,39}$/';
  100. /**
  101. * Validation rules for the content of one section type.
  102. * Keys are relative to the section's "content" object.
  103. *
  104. * @return array<string, list<string>>
  105. */
  106. public static function contentRules(string $type): array
  107. {
  108. $text = fn (int $max) => ['required', 'string', 'max:'.$max];
  109. $optionalText = fn (int $max) => ['nullable', 'string', 'max:'.$max];
  110. $link = ['required', 'string', 'max:300', 'regex:'.self::LINK_PATTERN];
  111. $price = ['required', 'numeric', 'min:0', 'max:999999'];
  112. return match ($type) {
  113. 'header' => [
  114. 'logoText' => $text(40),
  115. 'links' => ['present', 'array', 'max:6'],
  116. 'links.*.label' => $text(30),
  117. 'links.*.href' => $link,
  118. 'cta' => ['nullable', 'array'],
  119. 'cta.label' => ['required_with:cta', 'string', 'max:30'],
  120. 'cta.href' => ['required_with:cta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  121. ],
  122. 'hero' => [
  123. 'eyebrow' => $optionalText(60),
  124. 'headline' => $text(120),
  125. 'subheadline' => $text(300),
  126. 'primaryCta' => ['required', 'array'],
  127. 'primaryCta.label' => $text(30),
  128. 'primaryCta.href' => $link,
  129. 'secondaryCta' => ['nullable', 'array'],
  130. 'secondaryCta.label' => ['required_with:secondaryCta', 'string', 'max:30'],
  131. 'secondaryCta.href' => ['required_with:secondaryCta', 'string', 'max:300', 'regex:'.self::LINK_PATTERN],
  132. ],
  133. 'product_grid' => [
  134. 'heading' => $text(80),
  135. 'subheading' => $optionalText(200),
  136. 'items' => ['required', 'array', 'min:2', 'max:8'],
  137. 'items.*.name' => $text(80),
  138. 'items.*.price' => $price,
  139. 'items.*.badge' => $optionalText(20),
  140. ],
  141. 'featured_product' => [
  142. 'eyebrow' => $optionalText(60),
  143. 'name' => $text(80),
  144. 'description' => $text(500),
  145. 'price' => $price,
  146. 'bullets' => ['present', 'array', 'max:5'],
  147. 'bullets.*' => $text(100),
  148. 'cta' => ['required', 'array'],
  149. 'cta.label' => $text(30),
  150. 'cta.href' => $link,
  151. ],
  152. 'about' => [
  153. 'heading' => $text(80),
  154. 'body' => $text(1200),
  155. 'stats' => ['present', 'array', 'max:4'],
  156. 'stats.*.value' => $text(12),
  157. 'stats.*.label' => $text(40),
  158. ],
  159. 'testimonials' => [
  160. 'heading' => $text(80),
  161. 'items' => ['required', 'array', 'min:1', 'max:6'],
  162. 'items.*.quote' => $text(400),
  163. 'items.*.name' => $text(60),
  164. 'items.*.role' => $optionalText(60),
  165. ],
  166. 'faq' => [
  167. 'heading' => $text(80),
  168. 'items' => ['required', 'array', 'min:1', 'max:10'],
  169. 'items.*.question' => $text(160),
  170. 'items.*.answer' => $text(600),
  171. ],
  172. 'newsletter' => [
  173. 'heading' => $text(80),
  174. 'body' => $optionalText(240),
  175. 'placeholder' => $text(40),
  176. 'buttonLabel' => $text(30),
  177. ],
  178. 'contact' => [
  179. 'heading' => $text(80),
  180. 'body' => $optionalText(300),
  181. 'email' => ['nullable', 'email', 'max:120'],
  182. 'phone' => $optionalText(30),
  183. 'whatsapp' => ['nullable', 'string', 'regex:/^[0-9]{8,15}$/'],
  184. 'address' => $optionalText(200),
  185. ],
  186. 'footer' => [
  187. 'text' => $text(160),
  188. 'links' => ['present', 'array', 'max:8'],
  189. 'links.*.label' => $text(30),
  190. 'links.*.href' => $link,
  191. ],
  192. default => [],
  193. };
  194. }
  195. }