@wix/agent-skills 1.21.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/package.json +1 -1
  2. package/skills/wix-app/SKILL.md +60 -4
  3. package/skills/wix-app/references/DASHBOARD_PAGE.md +11 -25
  4. package/skills/wix-app/references/DATA_COLLECTION.md +16 -219
  5. package/skills/wix-app/references/dashboard-page/DATA_SOURCES.md +182 -0
  6. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE.md +97 -0
  7. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_COLLECTION.md +184 -0
  8. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_ROUTER.md +203 -0
  9. package/skills/wix-app/references/dashboard-page/DRAFT_TEMPLATE_SETTINGS.md +44 -0
  10. package/skills/wix-app/references/dashboard-page/QUERY_AND_PAGING.md +182 -0
  11. package/skills/wix-app/references/dashboard-page/TABLE_STATE.md +133 -0
  12. package/skills/wix-app/references/dashboard-page/UX_SUCCESS_MODEL.md +10 -5
  13. package/skills/wix-app/references/data-collection/LIFECYCLE.md +68 -0
  14. package/skills/wix-app/references/data-collection/PERMISSIONS.md +47 -0
  15. package/skills/wix-app/references/data-collection/SCHEMA.md +181 -0
  16. package/skills/wix-app/references/data-collection/WIX_DATA.md +38 -66
  17. package/skills/wix-headless-fast/SKILL.md +61 -223
  18. package/skills/wix-headless-fast/cold-start/bootstrap.mjs +156 -0
  19. package/skills/wix-headless-fast/{entry/skill.md → cold-start/cold-start.md} +11 -12
  20. package/skills/wix-headless-fast/guides/existing-site.md +76 -0
  21. package/skills/wix-headless-fast/guides/reference-mode.md +97 -0
  22. package/skills/wix-headless-fast/install/AGENTS.md +6 -3
  23. package/skills/wix-headless-fast/install/attach.mjs +15 -47
  24. package/skills/wix-headless-fast/install/deploy.mjs +21 -60
  25. package/skills/wix-headless-fast/install/lock.mjs +55 -0
  26. package/skills/wix-headless-fast/install/setup.mjs +32 -12
  27. package/skills/wix-headless-fast/install/templates.mjs +168 -0
  28. package/skills/wix-manage/references/google-ads/google-ads-dashboard-navigation.md +27 -0
  29. package/skills/wix-manage/references/google-ads/manage-campaign-success-guide.md +83 -37
  30. package/skills/wix-headless-fast/references/blog/INSTRUCTIONS.md +0 -303
  31. package/skills/wix-headless-fast/references/blog/app/components/blog/BlogFeedView.tsx +0 -136
  32. package/skills/wix-headless-fast/references/blog/app/components/blog/PostView.tsx +0 -112
  33. package/skills/wix-headless-fast/references/blog/app/components/blog/RichContent.tsx +0 -42
  34. package/skills/wix-headless-fast/references/blog/app/hooks/blog/useBlogFeed.ts +0 -31
  35. package/skills/wix-headless-fast/references/blog/app/hooks/blog/usePost.ts +0 -22
  36. package/skills/wix-headless-fast/references/blog/app/wix/blog/blog-feed-store.ts +0 -137
  37. package/skills/wix-headless-fast/references/blog/app/wix/blog/post-store.ts +0 -78
  38. package/skills/wix-headless-fast/references/blog/app/wix/blog/posts-core.ts +0 -117
  39. package/skills/wix-headless-fast/references/blog/app/wix/blog/posts.ts +0 -52
  40. package/skills/wix-headless-fast/references/blog/app/wix/blog/taxonomy-core.ts +0 -47
  41. package/skills/wix-headless-fast/references/blog/app/wix/blog/taxonomy.ts +0 -58
  42. package/skills/wix-headless-fast/references/blog/app/wix/blog/types.ts +0 -62
  43. package/skills/wix-headless-fast/references/blog/app-astro/layouts/SiteLayout.astro +0 -40
  44. package/skills/wix-headless-fast/references/blog/app-astro/pages/blog/[...slug].astro +0 -97
  45. package/skills/wix-headless-fast/references/blog/app-astro/pages/blog.astro +0 -24
  46. package/skills/wix-headless-fast/references/blog/lock/astro/package-lock.json +0 -16156
  47. package/skills/wix-headless-fast/references/blog/rest/posts.ts +0 -42
  48. package/skills/wix-headless-fast/references/blog/rest/taxonomy.ts +0 -62
  49. package/skills/wix-headless-fast/references/blog/seed/SEED.md +0 -81
  50. package/skills/wix-headless-fast/references/blog/seed/read-site.mjs +0 -22
  51. package/skills/wix-headless-fast/references/blog/seed/seed-blog.mjs +0 -287
  52. package/skills/wix-headless-fast/references/bookings/INSTRUCTIONS.md +0 -277
  53. package/skills/wix-headless-fast/references/bookings/app/components/bookings/ServiceBookingView.tsx +0 -144
  54. package/skills/wix-headless-fast/references/bookings/app/components/bookings/ServicesView.tsx +0 -119
  55. package/skills/wix-headless-fast/references/bookings/app/hooks/bookings/useBookingFlow.ts +0 -32
  56. package/skills/wix-headless-fast/references/bookings/app/hooks/bookings/useServices.ts +0 -23
  57. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking-core.ts +0 -218
  58. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking-flow-store.ts +0 -169
  59. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/booking.ts +0 -121
  60. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services-core.ts +0 -92
  61. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services-store.ts +0 -90
  62. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/services.ts +0 -57
  63. package/skills/wix-headless-fast/references/bookings/app/wix/bookings/types.ts +0 -72
  64. package/skills/wix-headless-fast/references/bookings/app-astro/layouts/SiteLayout.astro +0 -40
  65. package/skills/wix-headless-fast/references/bookings/app-astro/pages/services/[slug].astro +0 -76
  66. package/skills/wix-headless-fast/references/bookings/app-astro/pages/services.astro +0 -22
  67. package/skills/wix-headless-fast/references/bookings/lock/astro/package-lock.json +0 -11962
  68. package/skills/wix-headless-fast/references/bookings/rest/booking.ts +0 -113
  69. package/skills/wix-headless-fast/references/bookings/rest/services.ts +0 -55
  70. package/skills/wix-headless-fast/references/bookings/seed/SEED.md +0 -71
  71. package/skills/wix-headless-fast/references/bookings/seed/read-site.mjs +0 -28
  72. package/skills/wix-headless-fast/references/bookings/seed/seed-bookings.mjs +0 -302
  73. package/skills/wix-headless-fast/references/cms/INSTRUCTIONS.md +0 -355
  74. package/skills/wix-headless-fast/references/cms/app/hooks/cms/useCollection.ts +0 -50
  75. package/skills/wix-headless-fast/references/cms/app/hooks/cms/useItem.ts +0 -37
  76. package/skills/wix-headless-fast/references/cms/app/wix/cms/collection-store.ts +0 -158
  77. package/skills/wix-headless-fast/references/cms/app/wix/cms/item-store.ts +0 -93
  78. package/skills/wix-headless-fast/references/cms/app/wix/cms/items-core.ts +0 -177
  79. package/skills/wix-headless-fast/references/cms/app/wix/cms/items.ts +0 -123
  80. package/skills/wix-headless-fast/references/cms/app/wix/cms/types.ts +0 -75
  81. package/skills/wix-headless-fast/references/cms/app-astro/layouts/SiteLayout.astro +0 -41
  82. package/skills/wix-headless-fast/references/cms/lock/astro/package-lock.json +0 -11262
  83. package/skills/wix-headless-fast/references/cms/rest/items.ts +0 -125
  84. package/skills/wix-headless-fast/references/cms/seed/SEED.md +0 -112
  85. package/skills/wix-headless-fast/references/cms/seed/read-site.mjs +0 -20
  86. package/skills/wix-headless-fast/references/cms/seed/seed-cms.mjs +0 -324
  87. package/skills/wix-headless-fast/references/events/INSTRUCTIONS.md +0 -307
  88. package/skills/wix-headless-fast/references/events/app/components/events/EventConfirmationView.tsx +0 -66
  89. package/skills/wix-headless-fast/references/events/app/components/events/EventRegistrationView.tsx +0 -178
  90. package/skills/wix-headless-fast/references/events/app/components/events/EventsView.tsx +0 -118
  91. package/skills/wix-headless-fast/references/events/app/hooks/events/useEventRegistration.ts +0 -35
  92. package/skills/wix-headless-fast/references/events/app/hooks/events/useEvents.ts +0 -24
  93. package/skills/wix-headless-fast/references/events/app/wix/events/events-core.ts +0 -130
  94. package/skills/wix-headless-fast/references/events/app/wix/events/events-store.ts +0 -97
  95. package/skills/wix-headless-fast/references/events/app/wix/events/events.ts +0 -55
  96. package/skills/wix-headless-fast/references/events/app/wix/events/registration-core.ts +0 -113
  97. package/skills/wix-headless-fast/references/events/app/wix/events/registration-store.ts +0 -156
  98. package/skills/wix-headless-fast/references/events/app/wix/events/registration.ts +0 -97
  99. package/skills/wix-headless-fast/references/events/app/wix/events/types.ts +0 -61
  100. package/skills/wix-headless-fast/references/events/app-astro/layouts/SiteLayout.astro +0 -40
  101. package/skills/wix-headless-fast/references/events/app-astro/pages/event-confirmation.astro +0 -12
  102. package/skills/wix-headless-fast/references/events/app-astro/pages/events/[slug].astro +0 -80
  103. package/skills/wix-headless-fast/references/events/app-astro/pages/events.astro +0 -21
  104. package/skills/wix-headless-fast/references/events/lock/astro/package-lock.json +0 -11884
  105. package/skills/wix-headless-fast/references/events/rest/events.ts +0 -57
  106. package/skills/wix-headless-fast/references/events/rest/registration.ts +0 -83
  107. package/skills/wix-headless-fast/references/events/seed/SEED.md +0 -95
  108. package/skills/wix-headless-fast/references/events/seed/read-site.mjs +0 -26
  109. package/skills/wix-headless-fast/references/events/seed/seed-events.mjs +0 -276
  110. package/skills/wix-headless-fast/references/forms/INSTRUCTIONS.md +0 -340
  111. package/skills/wix-headless-fast/references/forms/app/hooks/forms/useWixForm.ts +0 -85
  112. package/skills/wix-headless-fast/references/forms/app/wix/forms/form-store.ts +0 -332
  113. package/skills/wix-headless-fast/references/forms/app/wix/forms/forms-core.ts +0 -238
  114. package/skills/wix-headless-fast/references/forms/app/wix/forms/forms.ts +0 -54
  115. package/skills/wix-headless-fast/references/forms/app/wix/forms/submissions-core.ts +0 -216
  116. package/skills/wix-headless-fast/references/forms/app/wix/forms/submissions.ts +0 -59
  117. package/skills/wix-headless-fast/references/forms/app/wix/forms/types.ts +0 -135
  118. package/skills/wix-headless-fast/references/forms/lock/astro/package-lock.json +0 -10593
  119. package/skills/wix-headless-fast/references/forms/rest/forms.ts +0 -34
  120. package/skills/wix-headless-fast/references/forms/rest/submissions.ts +0 -56
  121. package/skills/wix-headless-fast/references/forms/seed/SEED.md +0 -116
  122. package/skills/wix-headless-fast/references/forms/seed/read-site.mjs +0 -20
  123. package/skills/wix-headless-fast/references/forms/seed/seed-forms.mjs +0 -327
  124. package/skills/wix-headless-fast/references/members/INSTRUCTIONS.md +0 -316
  125. package/skills/wix-headless-fast/references/members/app/components/members/AccountView.tsx +0 -60
  126. package/skills/wix-headless-fast/references/members/app/components/members/LoginForm.tsx +0 -155
  127. package/skills/wix-headless-fast/references/members/app/components/members/MemberMenu.tsx +0 -78
  128. package/skills/wix-headless-fast/references/members/app/components/members/RequireAuth.tsx +0 -47
  129. package/skills/wix-headless-fast/references/members/app/hooks/members/useMember.ts +0 -66
  130. package/skills/wix-headless-fast/references/members/app/wix/members/auth-core.ts +0 -105
  131. package/skills/wix-headless-fast/references/members/app/wix/members/auth.ts +0 -59
  132. package/skills/wix-headless-fast/references/members/app/wix/members/client.ts +0 -53
  133. package/skills/wix-headless-fast/references/members/app/wix/members/member-store.ts +0 -122
  134. package/skills/wix-headless-fast/references/members/app/wix/members/members-core.ts +0 -43
  135. package/skills/wix-headless-fast/references/members/app/wix/members/members.ts +0 -29
  136. package/skills/wix-headless-fast/references/members/app/wix/members/types.ts +0 -21
  137. package/skills/wix-headless-fast/references/members/app-astro/layouts/SiteLayout.astro +0 -42
  138. package/skills/wix-headless-fast/references/members/app-astro/pages/account.astro +0 -10
  139. package/skills/wix-headless-fast/references/members/app-astro/pages/login.astro +0 -11
  140. package/skills/wix-headless-fast/references/members/lock/astro/package-lock.json +0 -10329
  141. package/skills/wix-headless-fast/references/members/rest/auth.ts +0 -215
  142. package/skills/wix-headless-fast/references/members/rest/members.ts +0 -26
  143. package/skills/wix-headless-fast/references/members/seed/SEED.md +0 -39
  144. package/skills/wix-headless-fast/references/members/seed/read-site.mjs +0 -15
  145. package/skills/wix-headless-fast/references/members/seed/seed-members.mjs +0 -94
  146. package/skills/wix-headless-fast/references/portfolio/INSTRUCTIONS.md +0 -315
  147. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/CollectionProjectsView.tsx +0 -110
  148. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/CollectionsView.tsx +0 -90
  149. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/GalleryMedia.tsx +0 -35
  150. package/skills/wix-headless-fast/references/portfolio/app/components/portfolio/ProjectDetailView.tsx +0 -85
  151. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useCollectionProjects.ts +0 -32
  152. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useCollections.ts +0 -21
  153. package/skills/wix-headless-fast/references/portfolio/app/hooks/portfolio/useProjectDetail.ts +0 -31
  154. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/collection-projects-store.ts +0 -82
  155. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/collections-store.ts +0 -58
  156. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/portfolio-core.ts +0 -177
  157. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/portfolio.ts +0 -78
  158. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/project-detail-store.ts +0 -81
  159. package/skills/wix-headless-fast/references/portfolio/app/wix/portfolio/types.ts +0 -55
  160. package/skills/wix-headless-fast/references/portfolio/app-astro/layouts/SiteLayout.astro +0 -40
  161. package/skills/wix-headless-fast/references/portfolio/app-astro/pages/portfolio/[slug].astro +0 -30
  162. package/skills/wix-headless-fast/references/portfolio/app-astro/pages/portfolio.astro +0 -21
  163. package/skills/wix-headless-fast/references/portfolio/app-astro/pages/projects/[slug].astro +0 -29
  164. package/skills/wix-headless-fast/references/portfolio/lock/astro/package-lock.json +0 -10197
  165. package/skills/wix-headless-fast/references/portfolio/rest/portfolio.ts +0 -75
  166. package/skills/wix-headless-fast/references/portfolio/seed/SEED.md +0 -86
  167. package/skills/wix-headless-fast/references/portfolio/seed/read-site.mjs +0 -20
  168. package/skills/wix-headless-fast/references/portfolio/seed/seed-portfolio.mjs +0 -256
  169. package/skills/wix-headless-fast/references/pricing-plans/INSTRUCTIONS.md +0 -296
  170. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/PlanDetailView.tsx +0 -47
  171. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/PlansView.tsx +0 -101
  172. package/skills/wix-headless-fast/references/pricing-plans/app/components/pricing-plans/SubscribeButton.tsx +0 -41
  173. package/skills/wix-headless-fast/references/pricing-plans/app/hooks/pricing-plans/usePlanPurchase.ts +0 -16
  174. package/skills/wix-headless-fast/references/pricing-plans/app/hooks/pricing-plans/usePlans.ts +0 -22
  175. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plan-purchase-store.ts +0 -54
  176. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans-core.ts +0 -106
  177. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans-store.ts +0 -64
  178. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/plans.ts +0 -27
  179. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/purchase-core.ts +0 -43
  180. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/purchase.ts +0 -22
  181. package/skills/wix-headless-fast/references/pricing-plans/app/wix/pricing-plans/types.ts +0 -30
  182. package/skills/wix-headless-fast/references/pricing-plans/app-astro/layouts/SiteLayout.astro +0 -41
  183. package/skills/wix-headless-fast/references/pricing-plans/app-astro/pages/plans/[slug].astro +0 -40
  184. package/skills/wix-headless-fast/references/pricing-plans/app-astro/pages/plans.astro +0 -21
  185. package/skills/wix-headless-fast/references/pricing-plans/lock/astro/package-lock.json +0 -11226
  186. package/skills/wix-headless-fast/references/pricing-plans/rest/plans.ts +0 -31
  187. package/skills/wix-headless-fast/references/pricing-plans/rest/purchase.ts +0 -20
  188. package/skills/wix-headless-fast/references/pricing-plans/seed/SEED.md +0 -79
  189. package/skills/wix-headless-fast/references/pricing-plans/seed/read-site.mjs +0 -21
  190. package/skills/wix-headless-fast/references/pricing-plans/seed/seed-pricing-plans.mjs +0 -279
  191. package/skills/wix-headless-fast/references/restaurants/INSTRUCTIONS.md +0 -360
  192. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/MenuView.tsx +0 -142
  193. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/OrderCartButton.tsx +0 -26
  194. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/OrderCartDrawer.tsx +0 -121
  195. package/skills/wix-headless-fast/references/restaurants/app/components/restaurants/ReservationView.tsx +0 -155
  196. package/skills/wix-headless-fast/references/restaurants/app/hooks/restaurants/useMenus.ts +0 -34
  197. package/skills/wix-headless-fast/references/restaurants/app/hooks/restaurants/useOrderCart.ts +0 -43
  198. package/skills/wix-headless-fast/references/restaurants/app/hooks/restaurants/useReservation.ts +0 -34
  199. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu-core.ts +0 -155
  200. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu-store.ts +0 -89
  201. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/menu.ts +0 -71
  202. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/order-store.ts +0 -103
  203. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/ordering-core.ts +0 -124
  204. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/ordering.ts +0 -185
  205. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservation-store.ts +0 -193
  206. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservations-core.ts +0 -94
  207. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/reservations.ts +0 -74
  208. package/skills/wix-headless-fast/references/restaurants/app/wix/restaurants/types.ts +0 -168
  209. package/skills/wix-headless-fast/references/restaurants/app-astro/layouts/SiteLayout.astro +0 -47
  210. package/skills/wix-headless-fast/references/restaurants/app-astro/pages/menu.astro +0 -22
  211. package/skills/wix-headless-fast/references/restaurants/app-astro/pages/reservations.astro +0 -12
  212. package/skills/wix-headless-fast/references/restaurants/lock/astro/package-lock.json +0 -12560
  213. package/skills/wix-headless-fast/references/restaurants/rest/menu.ts +0 -60
  214. package/skills/wix-headless-fast/references/restaurants/rest/ordering.ts +0 -169
  215. package/skills/wix-headless-fast/references/restaurants/rest/reservations.ts +0 -68
  216. package/skills/wix-headless-fast/references/restaurants/seed/SEED.md +0 -89
  217. package/skills/wix-headless-fast/references/restaurants/seed/read-site.mjs +0 -25
  218. package/skills/wix-headless-fast/references/restaurants/seed/seed-restaurants.mjs +0 -499
  219. package/skills/wix-headless-fast/references/shared/CONTENT.md +0 -22
  220. package/skills/wix-headless-fast/references/shared/CUSTOM_OPERATIONS.md +0 -73
  221. package/skills/wix-headless-fast/references/shared/DESIGN.md +0 -26
  222. package/skills/wix-headless-fast/references/shared/SUPPLIED-CONTENT.md +0 -23
  223. package/skills/wix-headless-fast/references/shared/app/styles/global.css +0 -52
  224. package/skills/wix-headless-fast/references/shared/app/wix/config.ts +0 -15
  225. package/skills/wix-headless-fast/references/shared/app/wix/media.ts +0 -81
  226. package/skills/wix-headless-fast/references/shared/app/wix/money.ts +0 -24
  227. package/skills/wix-headless-fast/references/shared/app/wix/sdk.ts +0 -89
  228. package/skills/wix-headless-fast/references/shared/capabilities/media-upload/app/wix/media-upload/client.ts +0 -46
  229. package/skills/wix-headless-fast/references/shared/capabilities/media-upload/app-astro/pages/api/wix/media-upload.ts +0 -46
  230. package/skills/wix-headless-fast/references/shared/rest/client.ts +0 -155
  231. package/skills/wix-headless-fast/references/shared/rest/config.ts +0 -3
  232. package/skills/wix-headless-fast/references/shared/rest/media.ts +0 -65
  233. package/skills/wix-headless-fast/references/shared/seed/images.mjs +0 -145
  234. package/skills/wix-headless-fast/references/shared/seed/read-site.mjs +0 -99
  235. package/skills/wix-headless-fast/references/storefront/INSTRUCTIONS.md +0 -612
  236. package/skills/wix-headless-fast/references/storefront/app/components/storefront/CartButton.tsx +0 -26
  237. package/skills/wix-headless-fast/references/storefront/app/components/storefront/CartDrawer.tsx +0 -155
  238. package/skills/wix-headless-fast/references/storefront/app/components/storefront/FilterPanel.tsx +0 -266
  239. package/skills/wix-headless-fast/references/storefront/app/components/storefront/OptionPicker.tsx +0 -95
  240. package/skills/wix-headless-fast/references/storefront/app/components/storefront/QuickAdd.tsx +0 -136
  241. package/skills/wix-headless-fast/references/storefront/app/hooks/storefront/useCart.ts +0 -48
  242. package/skills/wix-headless-fast/references/storefront/app/hooks/storefront/useProductDetail.ts +0 -39
  243. package/skills/wix-headless-fast/references/storefront/app/hooks/storefront/useShop.ts +0 -34
  244. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/cart-core.ts +0 -121
  245. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/cart-store.ts +0 -107
  246. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/cart.ts +0 -138
  247. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/catalog-core.ts +0 -314
  248. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/catalog.ts +0 -133
  249. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/product-detail-store.ts +0 -147
  250. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/shop-store.ts +0 -289
  251. package/skills/wix-headless-fast/references/storefront/app/wix/storefront/types.ts +0 -169
  252. package/skills/wix-headless-fast/references/storefront/app-astro/layouts/SiteLayout.astro +0 -65
  253. package/skills/wix-headless-fast/references/storefront/lock/astro/package-lock.json +0 -12247
  254. package/skills/wix-headless-fast/references/storefront/rest/cart.ts +0 -132
  255. package/skills/wix-headless-fast/references/storefront/rest/catalog.ts +0 -123
  256. package/skills/wix-headless-fast/references/storefront/seed/SEED.md +0 -130
  257. package/skills/wix-headless-fast/references/storefront/seed/read-site.mjs +0 -38
  258. package/skills/wix-headless-fast/references/storefront/seed/seed-store.mjs +0 -561
@@ -1,125 +0,0 @@
1
- // Wix Data reads/writes over REST — the twin of app/wix/cms/items.ts. Same exports, same DTOs; the
2
- // rules and mappers come from items-core (the SAME file the SDK transport uses, deployed flat next
3
- // to this one by deploy.mjs --stack static), so this file is only the transport: one fetch with a
4
- // literal body per function. The reads are safe from a browser with a visitor token on any
5
- // collection whose read permission is ANYONE; the writes succeed only where the collection's
6
- // insert/update/remove permission covers the caller (403 WDE0027 otherwise — a permissions step,
7
- // not a code bug). Porting: keep the paths, keep the bodies, port the core once.
8
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/query-data-items.md
9
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/get-data-item.md
10
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/patch-data-item.md
11
- import { WixApiError, wixRequest } from "./client.js";
12
- import { imgSrc } from "./media.js";
13
- import { DEFAULT_LIMIT, patchModifications, queryBody, restHasNext, restWriteData, toItem, toPage, type Raw } from "./items-core.js";
14
- import type { CmsFilter, CmsItem, CmsPage, CmsQuery } from "./types.js";
15
-
16
- const notFound = (e: unknown): boolean => e instanceof WixApiError && e.status === 404;
17
-
18
- /**
19
- * Query one page of a collection. An empty result on a PUBLIC collection is a seed permissions bug
20
- * (read must be "ANYONE"), not a query bug.
21
- * POST /wix-data/v2/items/query { dataCollectionId, query: { filter, sort, paging: { limit, offset } }, includeReferences: [{ field }], returnTotalCount }
22
- * → { dataItems: [{ id, dataCollectionId, data: { _id, …fields } }], pagingMetadata: { count, offset, total?, hasNext } }
23
- */
24
- export async function queryItems(collectionId: string, query: CmsQuery = {}): Promise<CmsPage> {
25
- const { limit = DEFAULT_LIMIT, skip = 0 } = query;
26
- const res = await wixRequest<Raw>("/wix-data/v2/items/query", { body: queryBody(collectionId, query) });
27
- const items = ((res?.dataItems ?? []) as Raw[]).map((d) => d.data ?? {});
28
- return toPage(items, restHasNext(res?.pagingMetadata, skip, limit), res?.pagingMetadata?.total, imgSrc);
29
- }
30
-
31
- /**
32
- * Fetch one item by `_id`. Null when not found (404 WDE0073).
33
- * GET /wix-data/v2/items/{id}?dataCollectionId=…&includeReferences.field=… → { dataItem: { data } }
34
- */
35
- export async function getItemById(
36
- collectionId: string,
37
- itemId: string,
38
- { include = [] }: { include?: string[] } = {},
39
- ): Promise<CmsItem | null> {
40
- try {
41
- const res = await wixRequest<Raw>(`/wix-data/v2/items/${encodeURIComponent(itemId)}`, {
42
- method: "GET",
43
- query: { dataCollectionId: collectionId, ...(include.length ? { "includeReferences.field": include } : {}) },
44
- });
45
- return res?.dataItem?.data ? toItem(res.dataItem.data, imgSrc) : null;
46
- } catch (e) {
47
- if (notFound(e)) return null;
48
- throw e;
49
- }
50
- }
51
-
52
- /**
53
- * Fetch the first item whose `field` equals `value` — slug-style routing (Wix Data has no native
54
- * get-by-slug). Null when not found → render a not-found state, never invent an item.
55
- */
56
- export async function getItemBy(
57
- collectionId: string,
58
- field: string,
59
- value: string | number,
60
- { include = [] }: { include?: string[] } = {},
61
- ): Promise<CmsItem | null> {
62
- const page = await queryItems(collectionId, { filters: [{ field, op: "eq", value }], limit: 1, include });
63
- return page.items[0] ?? null;
64
- }
65
-
66
- /** Count items matching the filters — empty-state logic and result counts (returnTotalCount). */
67
- export async function countItems(collectionId: string, filters: CmsFilter[] = []): Promise<number> {
68
- const page = await queryItems(collectionId, { filters, limit: 1, withTotal: true });
69
- return page.total ?? page.items.length;
70
- }
71
-
72
- /**
73
- * Insert an item (visitor form / member submission). Never set `_owner` — Wix stamps it from the
74
- * caller's identity. Date fields must be Date objects (the core spells them `{ $date }` on the wire;
75
- * an ISO string is stored as text and breaks date queries).
76
- * POST /wix-data/v2/items { dataCollectionId, dataItem: { data } } → { dataItem: { data } }
77
- */
78
- export async function insertItem(collectionId: string, data: Record<string, unknown>): Promise<CmsItem> {
79
- const res = await wixRequest<Raw>("/wix-data/v2/items", { body: { dataCollectionId: collectionId, dataItem: { data: restWriteData(data) } } });
80
- return toItem(res?.dataItem?.data ?? {}, imgSrc);
81
- }
82
-
83
- /**
84
- * REPLACE an item — fields omitted from `item` are WIPED (update does not patch). Spread the full
85
- * item you hold and override; for an id + a few changed fields use patchItemFields. Wrap each date
86
- * field back into a Date (`new Date(iso)`) before updating.
87
- * PUT /wix-data/v2/items/{id} { dataCollectionId, dataItem: { id, data } } → { dataItem: { data } }
88
- */
89
- export async function updateItem(collectionId: string, item: CmsItem): Promise<CmsItem> {
90
- const res = await wixRequest<Raw>(`/wix-data/v2/items/${encodeURIComponent(item._id)}`, {
91
- method: "PUT",
92
- body: { dataCollectionId: collectionId, dataItem: { id: item._id, data: restWriteData(item) } },
93
- });
94
- return toItem(res?.dataItem?.data ?? {}, imgSrc);
95
- }
96
-
97
- /**
98
- * Patch only the named fields — the safe partial change.
99
- * PATCH /wix-data/v2/items/{id} { dataCollectionId, patch: { dataItemId, fieldModifications: [{ fieldPath, action: "SET_FIELD", setFieldOptions: { value } }] } }
100
- */
101
- export async function patchItemFields(
102
- collectionId: string,
103
- itemId: string,
104
- fields: Record<string, unknown>,
105
- ): Promise<CmsItem> {
106
- const res = await wixRequest<Raw>(`/wix-data/v2/items/${encodeURIComponent(itemId)}`, {
107
- method: "PATCH",
108
- body: { dataCollectionId: collectionId, patch: { dataItemId: itemId, fieldModifications: patchModifications(fields) } },
109
- });
110
- return toItem(res?.dataItem?.data ?? {}, imgSrc);
111
- }
112
-
113
- /**
114
- * Remove an item by `_id`. Irreversible. Returns the removed item (null if it didn't exist).
115
- * DELETE /wix-data/v2/items/{id}?dataCollectionId=… → { dataItem: { data } }
116
- */
117
- export async function removeItem(collectionId: string, itemId: string): Promise<CmsItem | null> {
118
- try {
119
- const res = await wixRequest<Raw>(`/wix-data/v2/items/${encodeURIComponent(itemId)}`, { method: "DELETE", query: { dataCollectionId: collectionId } });
120
- return res?.dataItem?.data ? toItem(res.dataItem.data, imgSrc) : null;
121
- } catch (e) {
122
- if (notFound(e)) return null;
123
- throw e;
124
- }
125
- }
@@ -1,112 +0,0 @@
1
- # CMS — seeding
2
-
3
- Seed by **running `seed-cms.mjs` with a plan file** — don't hand-write the REST calls.
4
- The script mints its own site token via the Wix CLI (logged-in session + `wix.config.json`
5
- required), installs the Wix Data (CMS) app if needed, resolves every IMAGE value into Wix
6
- Media in one parallel wave, and creates everything in order: per collection — create
7
- (schema + permissions) → bulk-insert items → wire multi-references → verify persistence.
8
-
9
- ```bash
10
- # from the project root (where wix.config.json lives):
11
- node <SKILL_ROOT>/references/cms/seed/seed-cms.mjs plan.json
12
- ```
13
-
14
- `plan.json` is plain data — **it IS the site's content model**: the collections, their field
15
- schemas, and the items the pages will render. Write it from the brief. Default to **one or
16
- two content collections with ~3–6 items each** (the seed shows the shape; the owner adds the
17
- rest in the dashboard). Give any collection that gets a detail page a `slug` TEXT field, and
18
- every content item an image on an IMAGE field (a content site without images looks broken).
19
-
20
- ```json
21
- {
22
- "collections": [
23
- {
24
- "id": "categories", "displayName": "Categories",
25
- "fields": [{ "key": "name", "type": "TEXT" }],
26
- "items": [{ "name": "Cakes" }, { "name": "Breads" }]
27
- },
28
- {
29
- "id": "recipes", "displayName": "Recipes",
30
- "fields": [
31
- { "key": "title", "type": "TEXT" },
32
- { "key": "slug", "type": "TEXT" },
33
- { "key": "summary", "type": "TEXT" },
34
- { "key": "body", "type": "RICH_TEXT" },
35
- { "key": "photo", "type": "IMAGE" },
36
- { "key": "publishDate", "type": "DATE" },
37
- { "key": "categories", "type": "MULTI_REFERENCE", "referencedCollectionId": "categories" }
38
- ],
39
- "items": [
40
- { "title": "Chocolate Layer Cake", "slug": "chocolate-layer-cake",
41
- "summary": "Three layers, one ganache.", "body": "<p>Cream the butter…</p>",
42
- "photo": "https://…", "publishDate": "2026-08-01", "categories": [0] },
43
- { "title": "Country Sourdough", "slug": "country-sourdough",
44
- "summary": "A 24-hour loaf.", "body": "<p>Feed the starter…</p>",
45
- "photo": "https://…", "publishDate": "2026-08-10", "categories": [1] },
46
- { "title": "Pavlova", "slug": "pavlova",
47
- "summary": "Crisp shell, soft heart.", "body": "<p>Whip the whites…</p>",
48
- "photo": "https://…", "publishDate": "2026-08-20", "categories": [0] }
49
- ]
50
- }
51
- ]
52
- }
53
- ```
54
-
55
- - `id` — the collection id the frontend binds to, verbatim (no namespace; Wix doesn't rename
56
- it). Item keys must match the field `key`s exactly — the script fails loud on a key the
57
- schema doesn't have (the API would silently drop it).
58
- - Field `type` — `TEXT`, `NUMBER`, `BOOLEAN`, `DATE`, `DATETIME`, `URL`, `EMAIL`, `IMAGE`,
59
- `RICH_TEXT` (an HTML string, stored verbatim), `REFERENCE`, `MULTI_REFERENCE`.
60
- - `IMAGE` values — the default is `{ "prompt": "..." }` (AI-generated, ~1 Wix AI credit per
61
- image, account-billed): brand-contextual — subject, aesthetic/mood, palette, lighting —
62
- always ending "no text, no watermarks". At least one image in the set shows the real subject of the business — the actual product/space/service, not abstract decoration. For an asset the user actually supplied use
63
- `{ "path": "..." }` (a file on this machine — uploaded to Wix Media) or an https URL string
64
- (their own hosted URL; verify it with `curl -sI` → 200) — never a stock-photo or guessed URL. Images
65
- resolve in parallel and never block the seed; a failed image leaves that field unset (the
66
- item stays text-only).
67
- - `DATE`/`DATETIME` values are ISO strings — the script wraps them as `{ "$date": iso }`.
68
- - References: **order collections so targets come first.** A `REFERENCE` value is the target
69
- item's index in its collection's `items` array; `MULTI_REFERENCE` is an array of indices
70
- (set at insert it would be silently dropped — the script wires these via
71
- `POST /wix-data/v2/bulk/items/insert-references`).
72
- - `permissions` — omit for the **public-read** default
73
- (`read: ANYONE`, writes `ADMIN`). Other shapes (per action: `ANYONE` › `SITE_MEMBER` ›
74
- `SITE_MEMBER_AUTHOR` › `ADMIN`):
75
-
76
- | preset | `read` / `insert` / `update` / `remove` | use |
77
- |---|---|---|
78
- | public-read (default) | `ANYONE` / `ADMIN` / `ADMIN` / `ADMIN` | admin content, anyone reads |
79
- | collaborative | `ANYONE` / `ANYONE` / `ANYONE` / `ANYONE` | visitor-written shared board (anonymous, unscoped) |
80
- | member-private | `SITE_MEMBER_AUTHOR` / `SITE_MEMBER` / `SITE_MEMBER_AUTHOR` / `SITE_MEMBER_AUTHOR` | per-user "my…" rows — **seed it EMPTY** (rows seeded here would be owned by the admin, invisible to members) |
81
- | member-shared-read-only | `SITE_MEMBER` / `ADMIN` / `ADMIN` / `ADMIN` | gated: any member reads, seed/admin writes |
82
- | public-wall | `ANYONE` / `SITE_MEMBER` / `SITE_MEMBER_AUTHOR` / `SITE_MEMBER_AUTHOR` | members post, everyone reads |
83
-
84
- `read` is the privacy decision — a public collection's `read` MUST be `ANYONE` or the
85
- visitor frontend reads **zero items with no error**.
86
-
87
- **Seeding is additive — never delete or overwrite existing content** (an existing collection
88
- is left as-is; its items are appended); ask first if a cleanup seems needed.
89
-
90
- ## Supplied content
91
-
92
- The general rules are in `references/shared/SUPPLIED-CONTENT.md`. For the CMS the user's data
93
- defines the schema: each distinct table, sheet or file becomes a collection, its columns become
94
- `fields` with a type read from the values (`TEXT`, `NUMBER`, `DATE`, `IMAGE` for image URLs,
95
- `RICH_TEXT` for HTML), and its rows become `items`. Keep the user's column names as field keys. A
96
- column whose values point at rows of another table becomes a `MULTI_REFERENCE`. When a column's
97
- type is ambiguous, ask.
98
-
99
- ## Escape hatch — individual functions
100
- `setupCms` composes exported steps — `installDataApp`, `createCollection`, `importImage`,
101
- `bulkInsertItems`, `insertReferences`, `verifyItems`, plus `makeCtx()` — import them only
102
- for a partial re-seed.
103
-
104
- ## Reference
105
- Unexpected shape or an uncovered operation → read the live Wix API reference; the
106
- authoritative source recipe is `wix-headless/references/inline-recipes/setup-cms.md`.
107
- Endpoints used: `POST /wix-data/v2/collections` (Create Data Collection),
108
- `POST /wix-data/v2/bulk/items/insert` (Bulk Insert Data Items),
109
- `POST /wix-data/v2/bulk/items/insert-references` (Bulk Insert Data Item References),
110
- `POST /wix-data/v2/items/query` (Query Data Items — the verify step),
111
- `POST /site-media/v1/files/import` (Import File),
112
- `POST /apps-installer-service/v1/app-instance/install` (Install App).
@@ -1,20 +0,0 @@
1
- // What the CMS holds: collections, their fields, item counts, a few sample items each.
2
- // node <SKILL_ROOT>/references/cms/seed/read-site.mjs [--site <siteId>] [--limit <n>]
3
- import { runReader } from "../../shared/seed/read-site.mjs";
4
-
5
- const D = "https://dev.wix.com/docs/api-reference/business-solutions/cms";
6
-
7
- await runReader({
8
- vertical: "cms",
9
- async read(api, { limit }) {
10
- const r = await api.call({ method: "GET", path: "/wix-data/v2/collections", docs: `${D}/collection-management/data-collections/list-data-collections` });
11
- const all = r.collections ?? r.dataCollections ?? [];
12
- const own = all.filter((c) => c.collectionType !== "WIX_APP");
13
- const collections = [];
14
- for (const c of own.slice(0, limit)) {
15
- const items = await api.tryCall({ path: "/wix-data/v2/items/query", body: { dataCollectionId: c.id, query: { paging: { limit: 3 } }, returnTotalCount: true }, docs: `${D}/data-items/query-data-items` });
16
- collections.push({ id: c.id, displayName: c.displayName, fields: (c.fields ?? []).map((f) => `${f.key}:${f.type}`), itemCount: items?.pagingMetadata?.total ?? null, sample: (items?.dataItems ?? []).map((i) => i.data?.title ?? i.data?.name ?? i.id) });
17
- }
18
- return { collectionCount: own.length, collections, appCollections: all.filter((c) => c.collectionType === "WIX_APP").map((c) => c.id) };
19
- },
20
- });
@@ -1,324 +0,0 @@
1
- // CMS seed — a BUILD-TIME script, never shipped in the app. Run from the project root
2
- // (where wix.config.json lives) with a plan file:
3
- //
4
- // node <SKILL_ROOT>/references/cms/seed/seed-cms.mjs plan.json
5
- //
6
- // It mints its own site token via the Wix CLI, installs the Wix Data (CMS) app if needed,
7
- // resolves every IMAGE value into Wix Media (url import / AI generation, one parallel wave),
8
- // creates each collection (field schema + permissions; an existing collection is left
9
- // as-is), bulk-inserts items, wires multi-references, and verifies persistence. Prints a
10
- // JSON result to stdout.
11
- //
12
- // Plan shape (see SEED.md):
13
- // { "collections": [{ "id", "displayName"?, "permissions"?,
14
- // "fields": [{ "key", "displayName"?, "type", "referencedCollectionId"? }],
15
- // "items": [{ "<fieldKey>": value, ... }] }] }
16
- // Reference fields: order collections so targets come FIRST. A REFERENCE value is the
17
- // target item's index in ITS collection's items array; MULTI_REFERENCE is an array of
18
- // indices. An IMAGE value is a verified https url STRING, { "prompt": "..." }
19
- // (AI-generated), or { "path": "..." } (a local file the user supplied, uploaded).
20
- //
21
- // Seeding is ADDITIVE — never deletes or overwrites existing content. Unexpected shapes →
22
- // read the live API reference; authoritative source recipe:
23
- // wix-headless/references/inline-recipes/setup-cms.md.
24
- import { execFileSync } from "node:child_process";
25
- import { readFileSync } from "node:fs";
26
- import { resolveItemImages } from "../../shared/seed/images.mjs";
27
-
28
- const API = "https://www.wixapis.com";
29
- const WIX_DATA_APP_ID = "e593b0bd-b783-45b8-97c2-873d42aacaf4";
30
-
31
- // Public collection default: read MUST be "ANYONE" or a visitor query silently returns 0
32
- // items (the single most common "empty page" cause). Other presets: SEED.md.
33
- const DEFAULT_PERMISSIONS = { insert: "ADMIN", update: "ADMIN", remove: "ADMIN", read: "ANYONE" };
34
-
35
- export function makeCtx({ cwd = process.cwd() } = {}) {
36
- const config = JSON.parse(readFileSync(`${cwd}/wix.config.json`, "utf8"));
37
- const siteId = config.siteId ?? config.projectId;
38
- if (!siteId) throw new Error("wix.config.json has no siteId — is this a Wix CLI project?");
39
- const token = execFileSync("npx", ["@wix/cli@latest", "token", "--site", siteId], {
40
- encoding: "utf8",
41
- cwd,
42
- }).trim();
43
- if (!token) throw new Error("The Wix CLI returned no token — run `npx @wix/cli@latest login` first.");
44
- return { token, siteId };
45
- }
46
-
47
- async function req(ctx, path, { method = "POST", body } = {}) {
48
- const res = await fetch(API + path, {
49
- method,
50
- headers: {
51
- Authorization: `Bearer ${ctx.token}`,
52
- "wix-site-id": ctx.siteId,
53
- "Content-Type": "application/json",
54
- },
55
- body: body ? JSON.stringify(body) : undefined,
56
- });
57
- const json = await res.json().catch(() => ({}));
58
- if (!res.ok) throw new Error(`${method} ${path} -> ${res.status}: ${JSON.stringify(json).slice(0, 400)}`);
59
- return json;
60
- }
61
-
62
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
63
-
64
- // A fresh site's Wix Data backend can transiently fail its FIRST calls while provisioning —
65
- // 403, 400 WDE0117 ("MetaSite not found"), or 5xx. Retry the same body ONCE after ~3s, then
66
- // fail loud (never loop).
67
- async function reqRetryOnce(ctx, path, opts) {
68
- try {
69
- return await req(ctx, path, opts);
70
- } catch (e) {
71
- const m = String(e.message);
72
- if (/-> (403|5\d\d):/.test(m) || m.includes("WDE0117")) {
73
- await sleep(3000);
74
- return req(ctx, path, opts);
75
- }
76
- throw e;
77
- }
78
- }
79
-
80
- // ---- operations ----------------------------------------------------------------------------------
81
-
82
- // Idempotent; strictly only needed when a data call errors WDE0110 (app not installed).
83
- // docs: https://dev.wix.com/docs/api-reference/articles/work-with-wix-apis/platform/about-apps-created-by-wix.md
84
- export async function installDataApp(ctx) {
85
- try {
86
- await req(ctx, "/apps-installer-service/v1/app-instance/install", { body: {
87
- tenant: { tenantType: "SITE", id: ctx.siteId },
88
- appInstance: { appDefId: WIX_DATA_APP_ID, enabled: true },
89
- } });
90
- } catch {
91
- /* already installed is fine */
92
- }
93
- }
94
-
95
- // The binding key is referencedCollectionId — the docs' stale `referencedCollection` is
96
- // accepted with a 200 but stores an EMPTY target, leaving every later link silently dead.
97
- // MULTI_REFERENCE additionally REQUIRES referencingFieldKey — the auto-created back-reference
98
- // field on the referenced collection (400 without it); synthesized from the owning
99
- // collection + field when the plan doesn't name one.
100
- function buildField(f, collectionId) {
101
- const out = { key: f.key, displayName: f.displayName ?? f.key, type: f.type };
102
- if (f.type === "MULTI_REFERENCE" || f.type === "REFERENCE") {
103
- if (!f.referencedCollectionId) {
104
- throw new Error(`field "${f.key}": ${f.type} requires referencedCollectionId`);
105
- }
106
- out.typeMetadata =
107
- f.type === "MULTI_REFERENCE"
108
- ? { multiReference: {
109
- referencedCollectionId: f.referencedCollectionId,
110
- referencingFieldKey: f.referencingFieldKey ?? `${collectionId}_${f.key}`.replace(/[^a-zA-Z0-9_]/g, "_"),
111
- referencingDisplayName: f.referencingDisplayName ?? `${displayNameOf(collectionId)} (${f.key})`,
112
- } }
113
- : { reference: { referencedCollectionId: f.referencedCollectionId } };
114
- }
115
- return out;
116
- }
117
-
118
- const displayNameOf = (id) => String(id).replace(/[-_]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
119
-
120
- // The permissions block is MANDATORY. 409 WDE0104 (already exists) is fine — additive.
121
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-collections/create-data-collection.md
122
- export async function createCollection(ctx, { id, displayName, fields = [], permissions }) {
123
- try {
124
- await reqRetryOnce(ctx, "/wix-data/v2/collections", { body: { collection: {
125
- id,
126
- displayName: displayName ?? id,
127
- fields: fields.map((f) => buildField(f, id)),
128
- permissions: permissions ?? DEFAULT_PERMISSIONS,
129
- } } });
130
- return { id, created: true };
131
- } catch (e) {
132
- const m = String(e.message);
133
- if (m.includes("WDE0104") || m.includes("-> 409:")) return { id, created: false };
134
- throw e;
135
- }
136
- }
137
-
138
- // An IMAGE field stores a permanent Wix Media URL — an external url must be imported first;
139
- // a { "prompt": ... } value is generated (Wix AI, 1 credit) then imported. Both live in the
140
- // shared util (parallel, resilient, never blocks the seed).
141
- export { importImage } from "../../shared/seed/images.mjs";
142
-
143
- // Ids come from results[].dataItem.id (there is no results[].item key).
144
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/bulk-insert-data-items.md
145
- export async function bulkInsertItems(ctx, dataCollectionId, dataItems) {
146
- const r = await reqRetryOnce(ctx, "/wix-data/v2/bulk/items/insert", { body: {
147
- dataCollectionId,
148
- dataItems: dataItems.map((data) => ({ data })),
149
- returnEntity: true,
150
- } });
151
- const results = [...(r.results ?? [])].sort(
152
- (a, b) => (a.itemMetadata?.originalIndex ?? 0) - (b.itemMetadata?.originalIndex ?? 0),
153
- );
154
- return {
155
- ids: results.map((res) => res.dataItem?.id ?? res.itemMetadata?.id),
156
- failures: r.bulkActionMetadata?.totalFailures ?? 0,
157
- };
158
- }
159
-
160
- // Body key is dataItemReferences with referringItemFieldName/referringItemId/referencedItemId
161
- // — the natural-looking `references` shape is rejected with 400 WDE0080.
162
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/bulk-insert-data-item-references.md
163
- export async function insertReferences(ctx, dataCollectionId, dataItemReferences) {
164
- if (!dataItemReferences.length) return 0;
165
- const r = await req(ctx, "/wix-data/v2/bulk/items/insert-references", {
166
- body: { dataCollectionId, dataItemReferences },
167
- });
168
- return r.bulkActionMetadata?.totalSuccesses ?? dataItemReferences.length;
169
- }
170
-
171
- // A 200 on insert does NOT prove persistence — query back and count.
172
- // docs: https://dev.wix.com/docs/api-reference/business-solutions/cms/data-items/query-data-items.md
173
- export async function verifyItems(ctx, dataCollectionId) {
174
- const r = await reqRetryOnce(ctx, "/wix-data/v2/items/query", { body: { dataCollectionId } });
175
- return (r.dataItems ?? []).length;
176
- }
177
-
178
- // plan item -> insert `data`, per field type. MULTI_REFERENCE values are silently dropped by
179
- // the insert endpoint (200, no error) — stripped here and wired after; a single REFERENCE is
180
- // set at insert as the target item's _id. DATE/DATETIME wrap as { "$date": iso }; RICH_TEXT
181
- // is an HTML string stored verbatim; IMAGE values were resolved to Wix Media files up front
182
- // (imageFiles, keyed by imageKey) — a failed image leaves the field unset.
183
- function buildItemData(col, item, idsByCollection, multiRefs, itemIndex, counters, imageFiles) {
184
- const fieldsByKey = new Map((col.fields ?? []).map((f) => [f.key, f]));
185
- const data = {};
186
- for (const [key, value] of Object.entries(item)) {
187
- const f = fieldsByKey.get(key);
188
- // A key the schema doesn't have is silently dropped by the API — fail loud instead.
189
- if (!f) throw new Error(`"${col.id}" item ${itemIndex}: key "${key}" is not in the collection's fields`);
190
- if (value == null) continue;
191
- if (f.type === "MULTI_REFERENCE") {
192
- for (const targetIndex of [].concat(value)) {
193
- multiRefs.push({ itemIndex, fieldKey: key, targetCollectionId: f.referencedCollectionId, targetIndex });
194
- }
195
- continue;
196
- }
197
- if (f.type === "REFERENCE") {
198
- const targetId = (idsByCollection.get(f.referencedCollectionId) ?? [])[value];
199
- if (!targetId) {
200
- throw new Error(
201
- `"${col.id}" item ${itemIndex}: REFERENCE "${key}" -> "${f.referencedCollectionId}"[${value}] — ` +
202
- `target not created yet (order collections so targets come first)`,
203
- );
204
- }
205
- data[key] = targetId;
206
- continue;
207
- }
208
- if (f.type === "IMAGE") {
209
- const file = imageFiles.get(imageKey(col.id, itemIndex, key));
210
- if (file) {
211
- data[key] = file.url;
212
- counters.imagesImported++;
213
- }
214
- continue;
215
- }
216
- if (f.type === "DATE" || f.type === "DATETIME") {
217
- data[key] = { $date: new Date(value).toISOString() };
218
- continue;
219
- }
220
- data[key] = value;
221
- }
222
- return data;
223
- }
224
-
225
- const imageKey = (colId, itemIndex, fieldKey) => `${colId}${itemIndex}${fieldKey}`;
226
-
227
- // Every IMAGE value across the plan (a url string or { prompt }), resolved to Wix Media files
228
- // in ONE parallel wave before any insert. Returns Map<imageKey, { id, url } | absent>.
229
- async function resolveAllImages(ctx, collections) {
230
- const keys = [];
231
- const specs = [];
232
- for (const col of collections) {
233
- const imageFields = new Set((col.fields ?? []).filter((f) => f.type === "IMAGE").map((f) => f.key));
234
- (col.items ?? []).forEach((item, i) => {
235
- for (const [key, value] of Object.entries(item)) {
236
- if (!imageFields.has(key) || value == null) continue;
237
- keys.push(imageKey(col.id, i, key));
238
- specs.push({
239
- url: typeof value === "string" ? value : undefined,
240
- path: typeof value === "object" ? value.path : undefined,
241
- prompt: typeof value === "object" ? value.prompt : undefined,
242
- displayName: `${col.id}-${i}-${key}.png`,
243
- });
244
- }
245
- });
246
- }
247
- const files = specs.length ? await resolveItemImages(ctx, specs) : [];
248
- const out = new Map();
249
- keys.forEach((k, i) => { if (files[i]) out.set(k, files[i]); });
250
- return out;
251
- }
252
-
253
- /**
254
- * ONE-CALL seed: install → resolve every IMAGE value in one parallel wave → per collection
255
- * (in plan order): create → bulk-insert → wire multi-references → verify; ids threaded in
256
- * memory. The default path.
257
- */
258
- export async function setupCms(ctx, { collections = [] } = {}) {
259
- await installDataApp(ctx);
260
-
261
- const imageFiles = await resolveAllImages(ctx, collections);
262
-
263
- const idsByCollection = new Map();
264
- const out = { collections: [] };
265
- for (const col of collections) {
266
- const created = await createCollection(ctx, col);
267
-
268
- const counters = { imagesImported: 0 };
269
- const multiRefs = [];
270
- const dataItems = [];
271
- const planItems = col.items ?? [];
272
- for (let i = 0; i < planItems.length; i++) {
273
- dataItems.push(buildItemData(col, planItems[i], idsByCollection, multiRefs, i, counters, imageFiles));
274
- }
275
-
276
- let ids = [];
277
- let failures = 0;
278
- if (dataItems.length) ({ ids, failures } = await bulkInsertItems(ctx, col.id, dataItems));
279
- idsByCollection.set(col.id, ids);
280
-
281
- const refs = multiRefs.map(({ itemIndex, fieldKey, targetCollectionId, targetIndex }) => {
282
- const referringItemId = ids[itemIndex];
283
- const referencedItemId = (idsByCollection.get(targetCollectionId) ?? [])[targetIndex];
284
- if (!referringItemId || !referencedItemId) {
285
- throw new Error(
286
- `"${col.id}" item ${itemIndex}: multi-reference "${fieldKey}" -> "${targetCollectionId}"[${targetIndex}] ` +
287
- `has no created id (order collections so targets come first)`,
288
- );
289
- }
290
- return { referringItemFieldName: fieldKey, referringItemId, referencedItemId };
291
- });
292
- const referencesLinked = await insertReferences(ctx, col.id, refs);
293
-
294
- out.collections.push({
295
- id: col.id,
296
- created: created.created,
297
- inserted: ids.length,
298
- failures,
299
- imagesImported: counters.imagesImported,
300
- referencesLinked,
301
- itemsInCollection: await verifyItems(ctx, col.id),
302
- });
303
- }
304
- return out;
305
- }
306
-
307
- // ---- CLI entry ----------------------------------------------------------------------------------
308
-
309
- const invokedDirectly = process.argv[1] && import.meta.url.endsWith(process.argv[1].split("/").pop());
310
- if (invokedDirectly) {
311
- const planPath = process.argv[2];
312
- if (!planPath) {
313
- console.error("usage: node seed-cms.mjs <plan.json> (run from the project root)");
314
- process.exit(1);
315
- }
316
- const plan = JSON.parse(readFileSync(planPath, "utf8"));
317
- const ctx = makeCtx();
318
- setupCms(ctx, plan)
319
- .then((result) => console.log(JSON.stringify(result, null, 2)))
320
- .catch((e) => {
321
- console.error(e.message);
322
- process.exit(1);
323
- });
324
- }