@vtex/faststore 0.0.1

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 (538) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +95 -0
  4. package/dist/actions.json +334 -0
  5. package/dist/catalog.json +6615 -0
  6. package/dist/client.d.ts +17 -0
  7. package/dist/client.js +8 -0
  8. package/dist/components.d.ts +87 -0
  9. package/dist/components.js +87 -0
  10. package/dist/content-types.json +684 -0
  11. package/dist/core/dist/actions/mock-action.d.ts +24 -0
  12. package/dist/core/dist/actions/mock-action.js +28 -0
  13. package/dist/core/dist/actions/mock-action.js.map +1 -0
  14. package/dist/core/dist/actions/registry.d.ts +24 -0
  15. package/dist/core/dist/actions/registry.js +28 -0
  16. package/dist/core/dist/actions/registry.js.map +1 -0
  17. package/dist/core/dist/define-component.d.ts +100 -0
  18. package/dist/core/dist/define-component.js +8 -0
  19. package/dist/core/dist/define-component.js.map +1 -0
  20. package/dist/core/dist/define-content-type.d.ts +95 -0
  21. package/dist/core/dist/define-content-type.js +283 -0
  22. package/dist/core/dist/define-content-type.js.map +1 -0
  23. package/dist/core/dist/index.d.ts +7 -0
  24. package/dist/core/dist/index.js +5 -0
  25. package/dist/core/dist/schema/generated/schema.d.ts +28 -0
  26. package/dist/core/dist/types.d.ts +1 -0
  27. package/dist/docs/access-code-field.md +100 -0
  28. package/dist/docs/access-code-sign-in.md +174 -0
  29. package/dist/docs/account-entry-point.md +155 -0
  30. package/dist/docs/address-summary.md +50 -0
  31. package/dist/docs/buy-button.md +162 -0
  32. package/dist/docs/carousel.md +105 -0
  33. package/dist/docs/cart-item.md +162 -0
  34. package/dist/docs/cart-totalizer.md +197 -0
  35. package/dist/docs/cart.md +495 -0
  36. package/dist/docs/client-preferences.md +184 -0
  37. package/dist/docs/client-profile-form.md +192 -0
  38. package/dist/docs/client-profile.md +117 -0
  39. package/dist/docs/container.md +97 -0
  40. package/dist/docs/document-field.md +97 -0
  41. package/dist/docs/email-field.md +93 -0
  42. package/dist/docs/email-identification.md +102 -0
  43. package/dist/docs/footer-copyright.md +112 -0
  44. package/dist/docs/footer-link-group.md +162 -0
  45. package/dist/docs/footer-root.md +145 -0
  46. package/dist/docs/footer-social.md +151 -0
  47. package/dist/docs/free-shipping-progress.md +87 -0
  48. package/dist/docs/gallery.md +84 -0
  49. package/dist/docs/header-root.md +150 -0
  50. package/dist/docs/identity-edit.md +88 -0
  51. package/dist/docs/identity-summary.md +106 -0
  52. package/dist/docs/incentives.md +151 -0
  53. package/dist/docs/logo.md +135 -0
  54. package/dist/docs/meter.md +67 -0
  55. package/dist/docs/navigation-link-list.md +171 -0
  56. package/dist/docs/navigation-link.md +163 -0
  57. package/dist/docs/navigation-menu.md +264 -0
  58. package/dist/docs/payment-methods.md +139 -0
  59. package/dist/docs/phone-field.md +106 -0
  60. package/dist/docs/postal-code-field.md +126 -0
  61. package/dist/docs/pricing.md +499 -0
  62. package/dist/docs/product-gallery.md +409 -0
  63. package/dist/docs/product-information.md +295 -0
  64. package/dist/docs/product-list.md +170 -0
  65. package/dist/docs/product-quantity.md +88 -0
  66. package/dist/docs/product-shelf.md +141 -0
  67. package/dist/docs/promotion.md +109 -0
  68. package/dist/docs/region.md +225 -0
  69. package/dist/docs/session.md +123 -0
  70. package/dist/docs/shipping-address.md +390 -0
  71. package/dist/docs/shipping-simulator.md +147 -0
  72. package/dist/docs/sign-in-form.md +117 -0
  73. package/dist/docs/tabs.md +176 -0
  74. package/dist/docs/toast.md +124 -0
  75. package/dist/docs/variant-selector.md +450 -0
  76. package/dist/graphql/define-subgraph.d.ts +12 -0
  77. package/dist/graphql/define-subgraph.js +15 -0
  78. package/dist/graphql/define-subgraph.js.map +1 -0
  79. package/dist/graphql/gql.d.ts +10 -0
  80. package/dist/graphql/gql.js +16 -0
  81. package/dist/graphql/gql.js.map +1 -0
  82. package/dist/graphql/types.d.ts +88 -0
  83. package/dist/graphql.d.ts +4 -0
  84. package/dist/graphql.js +3 -0
  85. package/dist/index.d.ts +19 -0
  86. package/dist/index.js +5 -0
  87. package/dist/internal/client.d.ts +24 -0
  88. package/dist/internal/client.js +23 -0
  89. package/dist/internal/content.d.ts +2 -0
  90. package/dist/internal/content.js +2 -0
  91. package/dist/internal/server.d.ts +7 -0
  92. package/dist/internal/server.js +6 -0
  93. package/dist/matter/access-code-sign-in/access-code-sign-in.d.ts +111 -0
  94. package/dist/matter/access-code-sign-in/access-code-sign-in.js +387 -0
  95. package/dist/matter/access-code-sign-in/access-code-sign-in.js.map +1 -0
  96. package/dist/matter/account-entry-point/account-entry-point.d.ts +64 -0
  97. package/dist/matter/account-entry-point/account-entry-point.js +151 -0
  98. package/dist/matter/account-entry-point/account-entry-point.js.map +1 -0
  99. package/dist/matter/breadcrumb/breadcrumb.d.ts +40 -0
  100. package/dist/matter/breadcrumb/breadcrumb.js +155 -0
  101. package/dist/matter/breadcrumb/breadcrumb.js.map +1 -0
  102. package/dist/matter/buy-button/buy-button.d.ts +95 -0
  103. package/dist/matter/buy-button/buy-button.js +259 -0
  104. package/dist/matter/buy-button/buy-button.js.map +1 -0
  105. package/dist/matter/cart/cart-namespace.d.ts +48 -0
  106. package/dist/matter/cart/cart-namespace.js +50 -0
  107. package/dist/matter/cart/cart-namespace.js.map +1 -0
  108. package/dist/matter/cart/cart.d.ts +312 -0
  109. package/dist/matter/cart/cart.js +1034 -0
  110. package/dist/matter/cart/cart.js.map +1 -0
  111. package/dist/matter/cart-item/cart-item.d.ts +103 -0
  112. package/dist/matter/cart-item/cart-item.js +672 -0
  113. package/dist/matter/cart-item/cart-item.js.map +1 -0
  114. package/dist/matter/cart-item-compositions/cart-item-compositions.d.ts +49 -0
  115. package/dist/matter/cart-item-compositions/cart-item-compositions.js +165 -0
  116. package/dist/matter/cart-item-compositions/cart-item-compositions.js.map +1 -0
  117. package/dist/matter/cart-item-customizations/cart-item-customizations.d.ts +28 -0
  118. package/dist/matter/cart-item-customizations/cart-item-customizations.js +73 -0
  119. package/dist/matter/cart-item-customizations/cart-item-customizations.js.map +1 -0
  120. package/dist/matter/cart-item-discounts/cart-item-discounts.d.ts +33 -0
  121. package/dist/matter/cart-item-discounts/cart-item-discounts.js +70 -0
  122. package/dist/matter/cart-item-discounts/cart-item-discounts.js.map +1 -0
  123. package/dist/matter/cart-item-seller-info/cart-item-seller-info.d.ts +24 -0
  124. package/dist/matter/cart-item-seller-info/cart-item-seller-info.js +54 -0
  125. package/dist/matter/cart-item-seller-info/cart-item-seller-info.js.map +1 -0
  126. package/dist/matter/cart-item-variations/cart-item-variations.d.ts +27 -0
  127. package/dist/matter/cart-item-variations/cart-item-variations.js +69 -0
  128. package/dist/matter/cart-item-variations/cart-item-variations.js.map +1 -0
  129. package/dist/matter/cart-totalizer/cart-totalizer.d.ts +78 -0
  130. package/dist/matter/cart-totalizer/cart-totalizer.js +220 -0
  131. package/dist/matter/cart-totalizer/cart-totalizer.js.map +1 -0
  132. package/dist/matter/client-preferences/client-preferences.d.ts +50 -0
  133. package/dist/matter/client-preferences/client-preferences.js +206 -0
  134. package/dist/matter/client-preferences/client-preferences.js.map +1 -0
  135. package/dist/matter/client-profile/client-profile.d.ts +59 -0
  136. package/dist/matter/client-profile/client-profile.js +185 -0
  137. package/dist/matter/client-profile/client-profile.js.map +1 -0
  138. package/dist/matter/client-profile-form/client-profile-form.d.ts +126 -0
  139. package/dist/matter/client-profile-form/client-profile-form.js +660 -0
  140. package/dist/matter/client-profile-form/client-profile-form.js.map +1 -0
  141. package/dist/matter/delivery-options/delivery-options-accordion.d.ts +30 -0
  142. package/dist/matter/delivery-options/delivery-options-accordion.js +189 -0
  143. package/dist/matter/delivery-options/delivery-options-accordion.js.map +1 -0
  144. package/dist/matter/delivery-options/delivery-options-controller.d.ts +49 -0
  145. package/dist/matter/delivery-options/delivery-options-controller.js +203 -0
  146. package/dist/matter/delivery-options/delivery-options-controller.js.map +1 -0
  147. package/dist/matter/delivery-options/delivery-options.d.ts +31 -0
  148. package/dist/matter/delivery-options/delivery-options.js +103 -0
  149. package/dist/matter/delivery-options/delivery-options.js.map +1 -0
  150. package/dist/matter/delivery-options/use-delivery-option-selection.d.ts +9 -0
  151. package/dist/matter/delivery-options/use-delivery-option-selection.js +76 -0
  152. package/dist/matter/delivery-options/use-delivery-option-selection.js.map +1 -0
  153. package/dist/matter/email-identification/email-identification.d.ts +37 -0
  154. package/dist/matter/email-identification/email-identification.js +111 -0
  155. package/dist/matter/email-identification/email-identification.js.map +1 -0
  156. package/dist/matter/free-shipping-progress/free-shipping-progress.d.ts +44 -0
  157. package/dist/matter/free-shipping-progress/free-shipping-progress.js +170 -0
  158. package/dist/matter/free-shipping-progress/free-shipping-progress.js.map +1 -0
  159. package/dist/matter/identity-edit/identity-edit.d.ts +52 -0
  160. package/dist/matter/identity-edit/identity-edit.js +148 -0
  161. package/dist/matter/identity-edit/identity-edit.js.map +1 -0
  162. package/dist/matter/identity-summary/identity-summary.d.ts +128 -0
  163. package/dist/matter/identity-summary/identity-summary.js +344 -0
  164. package/dist/matter/identity-summary/identity-summary.js.map +1 -0
  165. package/dist/matter/pricing/pricing.d.ts +162 -0
  166. package/dist/matter/pricing/pricing.js +793 -0
  167. package/dist/matter/pricing/pricing.js.map +1 -0
  168. package/dist/matter/product-gallery/product-gallery.d.ts +23 -0
  169. package/dist/matter/product-gallery/product-gallery.js +188 -0
  170. package/dist/matter/product-gallery/product-gallery.js.map +1 -0
  171. package/dist/matter/product-information/product-information.d.ts +61 -0
  172. package/dist/matter/product-information/product-information.js +355 -0
  173. package/dist/matter/product-information/product-information.js.map +1 -0
  174. package/dist/matter/product-list/product-list.d.ts +86 -0
  175. package/dist/matter/product-list/product-list.js +342 -0
  176. package/dist/matter/product-list/product-list.js.map +1 -0
  177. package/dist/matter/product-quantity/product-quantity.d.ts +50 -0
  178. package/dist/matter/product-quantity/product-quantity.js +111 -0
  179. package/dist/matter/product-quantity/product-quantity.js.map +1 -0
  180. package/dist/matter/product-shelf/product-shelf.d.ts +125 -0
  181. package/dist/matter/product-shelf/product-shelf.js +376 -0
  182. package/dist/matter/product-shelf/product-shelf.js.map +1 -0
  183. package/dist/matter/region/region.d.ts +211 -0
  184. package/dist/matter/region/region.js +579 -0
  185. package/dist/matter/region/region.js.map +1 -0
  186. package/dist/matter/session/session.d.ts +58 -0
  187. package/dist/matter/session/session.js +112 -0
  188. package/dist/matter/session/session.js.map +1 -0
  189. package/dist/matter/shipping-address/country-descriptors.js +101 -0
  190. package/dist/matter/shipping-address/country-descriptors.js.map +1 -0
  191. package/dist/matter/shipping-address/shipping-address.d.ts +284 -0
  192. package/dist/matter/shipping-address/shipping-address.js +1036 -0
  193. package/dist/matter/shipping-address/shipping-address.js.map +1 -0
  194. package/dist/matter/shipping-simulator/shipping-simulator.d.ts +143 -0
  195. package/dist/matter/shipping-simulator/shipping-simulator.js +644 -0
  196. package/dist/matter/shipping-simulator/shipping-simulator.js.map +1 -0
  197. package/dist/matter/sign-in-form/sign-in-form.d.ts +79 -0
  198. package/dist/matter/sign-in-form/sign-in-form.js +226 -0
  199. package/dist/matter/sign-in-form/sign-in-form.js.map +1 -0
  200. package/dist/matter/variant-selector/variant-selector.d.ts +183 -0
  201. package/dist/matter/variant-selector/variant-selector.js +840 -0
  202. package/dist/matter/variant-selector/variant-selector.js.map +1 -0
  203. package/dist/message-locales.json +7 -0
  204. package/dist/particles/access-code-field/access-code-field.d.ts +33 -0
  205. package/dist/particles/access-code-field/access-code-field.js +95 -0
  206. package/dist/particles/access-code-field/access-code-field.js.map +1 -0
  207. package/dist/particles/accordion/accordion.d.ts +45 -0
  208. package/dist/particles/accordion/accordion.js +156 -0
  209. package/dist/particles/accordion/accordion.js.map +1 -0
  210. package/dist/particles/address-summary/address-summary.d.ts +50 -0
  211. package/dist/particles/address-summary/address-summary.js +129 -0
  212. package/dist/particles/address-summary/address-summary.js.map +1 -0
  213. package/dist/particles/badge/badge.d.ts +10 -0
  214. package/dist/particles/badge/badge.js +27 -0
  215. package/dist/particles/badge/badge.js.map +1 -0
  216. package/dist/particles/button/button.d.ts +18 -0
  217. package/dist/particles/button/button.js +37 -0
  218. package/dist/particles/button/button.js.map +1 -0
  219. package/dist/particles/carousel/carousel.d.ts +60 -0
  220. package/dist/particles/carousel/carousel.js +335 -0
  221. package/dist/particles/carousel/carousel.js.map +1 -0
  222. package/dist/particles/checkbox/checkbox.d.ts +40 -0
  223. package/dist/particles/checkbox/checkbox.js +82 -0
  224. package/dist/particles/checkbox/checkbox.js.map +1 -0
  225. package/dist/particles/container/container.d.ts +20 -0
  226. package/dist/particles/container/container.js +36 -0
  227. package/dist/particles/container/container.js.map +1 -0
  228. package/dist/particles/dialog/dialog.d.ts +54 -0
  229. package/dist/particles/dialog/dialog.js +192 -0
  230. package/dist/particles/dialog/dialog.js.map +1 -0
  231. package/dist/particles/document-field/document-field.d.ts +61 -0
  232. package/dist/particles/document-field/document-field.js +146 -0
  233. package/dist/particles/document-field/document-field.js.map +1 -0
  234. package/dist/particles/drawer/drawer.d.ts +52 -0
  235. package/dist/particles/drawer/drawer.js +183 -0
  236. package/dist/particles/drawer/drawer.js.map +1 -0
  237. package/dist/particles/email-field/email-field.d.ts +37 -0
  238. package/dist/particles/email-field/email-field.js +106 -0
  239. package/dist/particles/email-field/email-field.js.map +1 -0
  240. package/dist/particles/field/field.d.ts +50 -0
  241. package/dist/particles/field/field.js +133 -0
  242. package/dist/particles/field/field.js.map +1 -0
  243. package/dist/particles/fieldset/fieldset.d.ts +16 -0
  244. package/dist/particles/fieldset/fieldset.js +52 -0
  245. package/dist/particles/fieldset/fieldset.js.map +1 -0
  246. package/dist/particles/footer-copyright/footer-copyright.d.ts +32 -0
  247. package/dist/particles/footer-copyright/footer-copyright.js +50 -0
  248. package/dist/particles/footer-copyright/footer-copyright.js.map +1 -0
  249. package/dist/particles/footer-link-group/footer-link-group.d.ts +66 -0
  250. package/dist/particles/footer-link-group/footer-link-group.js +154 -0
  251. package/dist/particles/footer-link-group/footer-link-group.js.map +1 -0
  252. package/dist/particles/footer-root/footer-root.d.ts +21 -0
  253. package/dist/particles/footer-root/footer-root.js +38 -0
  254. package/dist/particles/footer-root/footer-root.js.map +1 -0
  255. package/dist/particles/footer-social/footer-social.d.ts +79 -0
  256. package/dist/particles/footer-social/footer-social.js +176 -0
  257. package/dist/particles/footer-social/footer-social.js.map +1 -0
  258. package/dist/particles/gallery/gallery.d.ts +181 -0
  259. package/dist/particles/gallery/gallery.js +920 -0
  260. package/dist/particles/gallery/gallery.js.map +1 -0
  261. package/dist/particles/header-root/header-root.d.ts +21 -0
  262. package/dist/particles/header-root/header-root.js +38 -0
  263. package/dist/particles/header-root/header-root.js.map +1 -0
  264. package/dist/particles/icon/icon.d.ts +22 -0
  265. package/dist/particles/icon/icon.js +48 -0
  266. package/dist/particles/icon/icon.js.map +1 -0
  267. package/dist/particles/image/image.d.ts +13 -0
  268. package/dist/particles/image/image.js +59 -0
  269. package/dist/particles/image/image.js.map +1 -0
  270. package/dist/particles/incentives/incentives.d.ts +85 -0
  271. package/dist/particles/incentives/incentives.js +200 -0
  272. package/dist/particles/incentives/incentives.js.map +1 -0
  273. package/dist/particles/input/input.d.ts +9 -0
  274. package/dist/particles/input/input.js +28 -0
  275. package/dist/particles/input/input.js.map +1 -0
  276. package/dist/particles/logo/logo.d.ts +55 -0
  277. package/dist/particles/logo/logo.js +96 -0
  278. package/dist/particles/logo/logo.js.map +1 -0
  279. package/dist/particles/menu/menu.d.ts +103 -0
  280. package/dist/particles/menu/menu.js +409 -0
  281. package/dist/particles/menu/menu.js.map +1 -0
  282. package/dist/particles/menubar/menubar.d.ts +18 -0
  283. package/dist/particles/menubar/menubar.js +42 -0
  284. package/dist/particles/menubar/menubar.js.map +1 -0
  285. package/dist/particles/meter/meter.d.ts +36 -0
  286. package/dist/particles/meter/meter.js +132 -0
  287. package/dist/particles/meter/meter.js.map +1 -0
  288. package/dist/particles/navigation-link/navigation-link.d.ts +43 -0
  289. package/dist/particles/navigation-link/navigation-link.js +82 -0
  290. package/dist/particles/navigation-link/navigation-link.js.map +1 -0
  291. package/dist/particles/navigation-link-list/navigation-link-list.d.ts +59 -0
  292. package/dist/particles/navigation-link-list/navigation-link-list.js +103 -0
  293. package/dist/particles/navigation-link-list/navigation-link-list.js.map +1 -0
  294. package/dist/particles/navigation-menu/navigation-menu.d.ts +78 -0
  295. package/dist/particles/navigation-menu/navigation-menu.js +295 -0
  296. package/dist/particles/navigation-menu/navigation-menu.js.map +1 -0
  297. package/dist/particles/number-field/number-field.d.ts +46 -0
  298. package/dist/particles/number-field/number-field.js +169 -0
  299. package/dist/particles/number-field/number-field.js.map +1 -0
  300. package/dist/particles/password-field/password-field.d.ts +31 -0
  301. package/dist/particles/password-field/password-field.js +109 -0
  302. package/dist/particles/password-field/password-field.js.map +1 -0
  303. package/dist/particles/payment-methods/payment-methods.d.ts +72 -0
  304. package/dist/particles/payment-methods/payment-methods.js +151 -0
  305. package/dist/particles/payment-methods/payment-methods.js.map +1 -0
  306. package/dist/particles/phone-field/phone-field.d.ts +67 -0
  307. package/dist/particles/phone-field/phone-field.js +250 -0
  308. package/dist/particles/phone-field/phone-field.js.map +1 -0
  309. package/dist/particles/popover/popover.d.ts +68 -0
  310. package/dist/particles/popover/popover.js +284 -0
  311. package/dist/particles/popover/popover.js.map +1 -0
  312. package/dist/particles/postal-code-field/postal-code-field.d.ts +75 -0
  313. package/dist/particles/postal-code-field/postal-code-field.js +169 -0
  314. package/dist/particles/postal-code-field/postal-code-field.js.map +1 -0
  315. package/dist/particles/promotion/promotion.d.ts +46 -0
  316. package/dist/particles/promotion/promotion.js +78 -0
  317. package/dist/particles/promotion/promotion.js.map +1 -0
  318. package/dist/particles/quantity-selector/quantity-selector.d.ts +30 -0
  319. package/dist/particles/quantity-selector/quantity-selector.js +116 -0
  320. package/dist/particles/quantity-selector/quantity-selector.js.map +1 -0
  321. package/dist/particles/radio/radio.d.ts +36 -0
  322. package/dist/particles/radio/radio.js +76 -0
  323. package/dist/particles/radio/radio.js.map +1 -0
  324. package/dist/particles/scroll-area/scroll-area.d.ts +36 -0
  325. package/dist/particles/scroll-area/scroll-area.js +145 -0
  326. package/dist/particles/scroll-area/scroll-area.js.map +1 -0
  327. package/dist/particles/select/select.d.ts +125 -0
  328. package/dist/particles/select/select.js +478 -0
  329. package/dist/particles/select/select.js.map +1 -0
  330. package/dist/particles/separator/separator.d.ts +12 -0
  331. package/dist/particles/separator/separator.js +33 -0
  332. package/dist/particles/separator/separator.js.map +1 -0
  333. package/dist/particles/shared/input-mask.d.ts +5 -0
  334. package/dist/particles/shared/input-mask.js +58 -0
  335. package/dist/particles/shared/input-mask.js.map +1 -0
  336. package/dist/particles/spinner/spinner.d.ts +13 -0
  337. package/dist/particles/spinner/spinner.js +31 -0
  338. package/dist/particles/spinner/spinner.js.map +1 -0
  339. package/dist/particles/switch/switch.d.ts +27 -0
  340. package/dist/particles/switch/switch.js +59 -0
  341. package/dist/particles/switch/switch.js.map +1 -0
  342. package/dist/particles/tabs/tabs.d.ts +45 -0
  343. package/dist/particles/tabs/tabs.js +164 -0
  344. package/dist/particles/tabs/tabs.js.map +1 -0
  345. package/dist/particles/text/text.d.ts +24 -0
  346. package/dist/particles/text/text.js +40 -0
  347. package/dist/particles/text/text.js.map +1 -0
  348. package/dist/particles/toast/toast.d.ts +83 -0
  349. package/dist/particles/toast/toast.js +194 -0
  350. package/dist/particles/toast/toast.js.map +1 -0
  351. package/dist/particles/toggle/toggle.d.ts +26 -0
  352. package/dist/particles/toggle/toggle.js +61 -0
  353. package/dist/particles/toggle/toggle.js.map +1 -0
  354. package/dist/particles/tooltip/tooltip.d.ts +61 -0
  355. package/dist/particles/tooltip/tooltip.js +240 -0
  356. package/dist/particles/tooltip/tooltip.js.map +1 -0
  357. package/dist/schema.graphql +2953 -0
  358. package/dist/sdk/actions/cart-action-provider.d.ts +19 -0
  359. package/dist/sdk/actions/cart-action-provider.js +23 -0
  360. package/dist/sdk/actions/cart-action-provider.js.map +1 -0
  361. package/dist/sdk/actions/identity-action-provider.d.ts +15 -0
  362. package/dist/sdk/actions/identity-action-provider.js +19 -0
  363. package/dist/sdk/actions/identity-action-provider.js.map +1 -0
  364. package/dist/sdk/actions/index.d.ts +7 -0
  365. package/dist/sdk/actions/index.js +6 -0
  366. package/dist/sdk/actions/inject-actions.d.ts +14 -0
  367. package/dist/sdk/actions/inject-actions.js +36 -0
  368. package/dist/sdk/actions/inject-actions.js.map +1 -0
  369. package/dist/sdk/actions/region-action-provider.d.ts +15 -0
  370. package/dist/sdk/actions/region-action-provider.js +19 -0
  371. package/dist/sdk/actions/region-action-provider.js.map +1 -0
  372. package/dist/sdk/actions/session-action-provider.d.ts +15 -0
  373. package/dist/sdk/actions/session-action-provider.js +19 -0
  374. package/dist/sdk/actions/session-action-provider.js.map +1 -0
  375. package/dist/sdk/actions/shipping-action-provider.d.ts +15 -0
  376. package/dist/sdk/actions/shipping-action-provider.js +19 -0
  377. package/dist/sdk/actions/shipping-action-provider.js.map +1 -0
  378. package/dist/sdk/actions/types.d.ts +21 -0
  379. package/dist/sdk/cache/storefront-cache.js +35 -0
  380. package/dist/sdk/cache/storefront-cache.js.map +1 -0
  381. package/dist/sdk/cart/operations.d.ts +31 -0
  382. package/dist/sdk/cart/operations.js +215 -0
  383. package/dist/sdk/cart/operations.js.map +1 -0
  384. package/dist/sdk/cart/optimistic.d.ts +24 -0
  385. package/dist/sdk/cart/optimistic.js +164 -0
  386. package/dist/sdk/cart/optimistic.js.map +1 -0
  387. package/dist/sdk/cart/use-cart-actions.d.ts +56 -0
  388. package/dist/sdk/cart/use-cart-actions.js +348 -0
  389. package/dist/sdk/cart/use-cart-actions.js.map +1 -0
  390. package/dist/sdk/cart/use-cart-validate-on-open.js +50 -0
  391. package/dist/sdk/cart/use-cart-validate-on-open.js.map +1 -0
  392. package/dist/sdk/cart/write-gate.js +54 -0
  393. package/dist/sdk/cart/write-gate.js.map +1 -0
  394. package/dist/sdk/client/assert-api-url.js +20 -0
  395. package/dist/sdk/client/assert-api-url.js.map +1 -0
  396. package/dist/sdk/client/create-client.d.ts +23 -0
  397. package/dist/sdk/client/create-client.js +46 -0
  398. package/dist/sdk/client/create-client.js.map +1 -0
  399. package/dist/sdk/client/fetch-page-data.d.ts +39 -0
  400. package/dist/sdk/client/fetch-page-data.js +33 -0
  401. package/dist/sdk/client/fetch-page-data.js.map +1 -0
  402. package/dist/sdk/client/register-preload-query.d.ts +24 -0
  403. package/dist/sdk/client/register-preload-query.js +33 -0
  404. package/dist/sdk/client/register-preload-query.js.map +1 -0
  405. package/dist/sdk/content/create-content-runtime.d.ts +68 -0
  406. package/dist/sdk/content/create-content-runtime.js +503 -0
  407. package/dist/sdk/content/create-content-runtime.js.map +1 -0
  408. package/dist/sdk/context/headers.d.ts +15 -0
  409. package/dist/sdk/context/headers.js +21 -0
  410. package/dist/sdk/context/headers.js.map +1 -0
  411. package/dist/sdk/context/storefront-context.d.ts +11 -0
  412. package/dist/sdk/context/storefront-context.js +29 -0
  413. package/dist/sdk/context/storefront-context.js.map +1 -0
  414. package/dist/sdk/data/data-override-context.d.ts +12 -0
  415. package/dist/sdk/data/data-override-context.js +19 -0
  416. package/dist/sdk/data/data-override-context.js.map +1 -0
  417. package/dist/sdk/data/entity-subscriber.js +28 -0
  418. package/dist/sdk/data/entity-subscriber.js.map +1 -0
  419. package/dist/sdk/data/hot-data-provider.d.ts +19 -0
  420. package/dist/sdk/data/hot-data-provider.js +33 -0
  421. package/dist/sdk/data/hot-data-provider.js.map +1 -0
  422. package/dist/sdk/data/index.d.ts +8 -0
  423. package/dist/sdk/data/index.js +8 -0
  424. package/dist/sdk/data/list-item-ref-context.d.ts +20 -0
  425. package/dist/sdk/data/list-item-ref-context.js +11 -0
  426. package/dist/sdk/data/list-item-ref-context.js.map +1 -0
  427. package/dist/sdk/data/multiple-reactive-data-provider.d.ts +32 -0
  428. package/dist/sdk/data/multiple-reactive-data-provider.js +20 -0
  429. package/dist/sdk/data/multiple-reactive-data-provider.js.map +1 -0
  430. package/dist/sdk/data/page-reactive-data-root.d.ts +53 -0
  431. package/dist/sdk/data/page-reactive-data-root.js +153 -0
  432. package/dist/sdk/data/page-reactive-data-root.js.map +1 -0
  433. package/dist/sdk/data/reactive-data-provider.d.ts +25 -0
  434. package/dist/sdk/data/reactive-data-provider.js +24 -0
  435. package/dist/sdk/data/reactive-data-provider.js.map +1 -0
  436. package/dist/sdk/data/reactive-list-item-data-provider.d.ts +26 -0
  437. package/dist/sdk/data/reactive-list-item-data-provider.js +42 -0
  438. package/dist/sdk/data/reactive-list-item-data-provider.js.map +1 -0
  439. package/dist/sdk/data/use-reactive-entity.js +40 -0
  440. package/dist/sdk/data/use-reactive-entity.js.map +1 -0
  441. package/dist/sdk/format/client.d.ts +12 -0
  442. package/dist/sdk/format/client.js +20 -0
  443. package/dist/sdk/format/client.js.map +1 -0
  444. package/dist/sdk/format/formatters.d.ts +32 -0
  445. package/dist/sdk/format/formatters.js +45 -0
  446. package/dist/sdk/format/formatters.js.map +1 -0
  447. package/dist/sdk/generated/fragment-types.js +23 -0
  448. package/dist/sdk/generated/fragment-types.js.map +1 -0
  449. package/dist/sdk/generated/gql.js +51 -0
  450. package/dist/sdk/generated/gql.js.map +1 -0
  451. package/dist/sdk/generated/graphql.d.ts +622 -0
  452. package/dist/sdk/generated/graphql.js +11917 -0
  453. package/dist/sdk/generated/graphql.js.map +1 -0
  454. package/dist/sdk/graphql-tag.d.ts +10 -0
  455. package/dist/sdk/graphql-tag.js +21 -0
  456. package/dist/sdk/graphql-tag.js.map +1 -0
  457. package/dist/sdk/i18n/client.d.ts +4 -0
  458. package/dist/sdk/i18n/client.js +4 -0
  459. package/dist/sdk/i18n/locales.d.ts +8 -0
  460. package/dist/sdk/i18n/locales.js +57 -0
  461. package/dist/sdk/i18n/locales.js.map +1 -0
  462. package/dist/sdk/i18n/messages/en-US.js +24 -0
  463. package/dist/sdk/i18n/messages/en-US.js.map +1 -0
  464. package/dist/sdk/i18n/messages/en-US.json +19 -0
  465. package/dist/sdk/i18n/messages/en-US.json.d.ts +23 -0
  466. package/dist/sdk/i18n/messages/es-ES.js +24 -0
  467. package/dist/sdk/i18n/messages/es-ES.js.map +1 -0
  468. package/dist/sdk/i18n/messages/es-ES.json +19 -0
  469. package/dist/sdk/i18n/messages/pt-BR.js +24 -0
  470. package/dist/sdk/i18n/messages/pt-BR.js.map +1 -0
  471. package/dist/sdk/i18n/messages/pt-BR.json +19 -0
  472. package/dist/sdk/i18n/provider.d.ts +1 -0
  473. package/dist/sdk/i18n/provider.js +30 -0
  474. package/dist/sdk/i18n/provider.js.map +1 -0
  475. package/dist/sdk/i18n/server.d.ts +28 -0
  476. package/dist/sdk/i18n/server.js +59 -0
  477. package/dist/sdk/i18n/server.js.map +1 -0
  478. package/dist/sdk/identity/operations.d.ts +34 -0
  479. package/dist/sdk/identity/operations.js +78 -0
  480. package/dist/sdk/identity/operations.js.map +1 -0
  481. package/dist/sdk/identity/use-identity-actions.d.ts +62 -0
  482. package/dist/sdk/identity/use-identity-actions.js +180 -0
  483. package/dist/sdk/identity/use-identity-actions.js.map +1 -0
  484. package/dist/sdk/provider/index.d.ts +2 -0
  485. package/dist/sdk/provider/index.js +2 -0
  486. package/dist/sdk/provider/storefront-provider.d.ts +32 -0
  487. package/dist/sdk/provider/storefront-provider.js +111 -0
  488. package/dist/sdk/provider/storefront-provider.js.map +1 -0
  489. package/dist/sdk/region/operations.d.ts +6 -0
  490. package/dist/sdk/region/region-operations.d.ts +30 -0
  491. package/dist/sdk/region/region-operations.js +23 -0
  492. package/dist/sdk/region/region-operations.js.map +1 -0
  493. package/dist/sdk/region/use-region-actions.d.ts +23 -0
  494. package/dist/sdk/region/use-region-actions.js +66 -0
  495. package/dist/sdk/region/use-region-actions.js.map +1 -0
  496. package/dist/sdk/seller.js +11 -0
  497. package/dist/sdk/seller.js.map +1 -0
  498. package/dist/sdk/session/auth-operations.d.ts +47 -0
  499. package/dist/sdk/session/auth-operations.js +79 -0
  500. package/dist/sdk/session/auth-operations.js.map +1 -0
  501. package/dist/sdk/session/operations.d.ts +6 -0
  502. package/dist/sdk/session/use-session-actions.d.ts +27 -0
  503. package/dist/sdk/session/use-session-actions.js +126 -0
  504. package/dist/sdk/session/use-session-actions.js.map +1 -0
  505. package/dist/sdk/shipping/cart-operations.d.ts +3 -0
  506. package/dist/sdk/shipping/cart-operations.js +33 -0
  507. package/dist/sdk/shipping/cart-operations.js.map +1 -0
  508. package/dist/sdk/shipping/operations.d.ts +3 -0
  509. package/dist/sdk/shipping/operations.js +33 -0
  510. package/dist/sdk/shipping/operations.js.map +1 -0
  511. package/dist/sdk/shipping/option-select-operations.d.ts +24 -0
  512. package/dist/sdk/shipping/option-select-operations.js +45 -0
  513. package/dist/sdk/shipping/option-select-operations.js.map +1 -0
  514. package/dist/sdk/shipping/request-timeout.js +41 -0
  515. package/dist/sdk/shipping/request-timeout.js.map +1 -0
  516. package/dist/sdk/shipping/shipping-operations.d.ts +38 -0
  517. package/dist/sdk/shipping/shipping-operations.js +77 -0
  518. package/dist/sdk/shipping/shipping-operations.js.map +1 -0
  519. package/dist/sdk/shipping/use-cart-shipping-simulation.d.ts +7 -0
  520. package/dist/sdk/shipping/use-cart-shipping-simulation.js +72 -0
  521. package/dist/sdk/shipping/use-cart-shipping-simulation.js.map +1 -0
  522. package/dist/sdk/shipping/use-shipping-actions.d.ts +27 -0
  523. package/dist/sdk/shipping/use-shipping-actions.js +113 -0
  524. package/dist/sdk/shipping/use-shipping-actions.js.map +1 -0
  525. package/dist/sdk/shipping/use-shipping-simulation.d.ts +7 -0
  526. package/dist/sdk/shipping/use-shipping-simulation.js +72 -0
  527. package/dist/sdk/shipping/use-shipping-simulation.js.map +1 -0
  528. package/dist/sdk/state/cart.d.ts +42 -0
  529. package/dist/sdk/state/cart.js +64 -0
  530. package/dist/sdk/state/cart.js.map +1 -0
  531. package/dist/sdk/state/index.js +3 -0
  532. package/dist/sdk/state/variant-selector.d.ts +17 -0
  533. package/dist/sdk/state/variant-selector.js +14 -0
  534. package/dist/sdk/state/variant-selector.js.map +1 -0
  535. package/dist/utils/safe-href.js +63 -0
  536. package/dist/utils/safe-href.js.map +1 -0
  537. package/package.json +84 -0
  538. package/src/styles/tailwind.css +32 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-cart-actions.js","names":[],"sources":["../../../src/sdk/cart/use-cart-actions.ts"],"sourcesContent":["'use client';\n\nimport type { ApolloClient } from '@apollo/client';\nimport { useApolloClient, useMutation } from '@apollo/client/react';\nimport { defineActions } from '@vtex/fs-core';\nimport { useCallback, useMemo } from 'react';\nimport { cartCouponErrorsVar, cartLastAddVar, cartUserErrorsVar, orderFormIdVar } from '../state/cart.js';\nimport {\n CART_COUPON_APPLY,\n CART_COUPON_REMOVE,\n CART_ITEM_ADD,\n CART_ITEM_QUANTITY_DECREASE,\n CART_ITEM_QUANTITY_INCREASE,\n CART_ITEM_REMOVE,\n CART_ITEMS_REMOVE,\n CART_VALIDATE,\n type CartEntity,\n CartFragment,\n type CartItemEntity,\n type CartUserError,\n} from './operations.js';\nimport {\n buildOptimisticDecrease,\n buildOptimisticIncrease,\n buildOptimisticRemove,\n buildOptimisticRemoveItems,\n} from './optimistic.js';\nimport { markAvailabilityFresh, trackCartWrite } from './write-gate.js';\n\n/**\n * The `cart` action namespace — the consolidated, context-free owner of every cart write\n * (specs/actions.md, docs/storefront-core/adr-0010-actions-own-the-write-side.md).\n *\n * It replaces `useCartMutations` + the mutation handlers `CartRoot` used to publish through\n * `CartDataContext`. A handler reads the current cart from the normalized Apollo cache (keyed by\n * `orderFormIdVar`), not from component props or React context, so any component anywhere in the\n * tree can dispatch a write through the compiler-injected `$actions.cart.*` prop — the cache is the\n * only meeting point between the read side and the write side (ADR-0010).\n *\n * `userErrors` from every call are published to `cartUserErrorsVar` (cleared at the start of the\n * next call) so `CartError` can surface them without a data context, and also returned to the caller.\n */\n\n/**\n * Thrown by the existing-line handlers (remove / quantity) when invoked before the cart resolves.\n * The first `addItem` mints the cart and hydrates `orderFormIdVar`; until then there is no cached\n * cart entity to read for the optimistic response.\n */\nexport class CartNotReadyError extends Error {\n constructor(message?: string) {\n super(message ?? 'CartNotReadyError: no cart in cache yet; add an item (or load the cart) before mutating a line.');\n this.name = 'CartNotReadyError';\n }\n}\n\nexport type AddItemPayload = Readonly<{\n variantId: string;\n quantity?: number;\n /** Seller global Node ID, e.g. base64(\"Seller:1\"). The server rejects raw ids with INVALID_SELLER_ID. */\n seller: string;\n}>;\n\n/** Existing-line payloads address the line by its opaque cart-item `id`; the handler reads the rest from cache. */\nexport type CartLinePayload = Readonly<{ id: string }>;\n\n/** Batch payloads address several lines by their opaque cart-item `id`s. */\nexport type CartLinesPayload = Readonly<{ ids: readonly string[] }>;\n\nexport type CartQuantityPayload = Readonly<{ id: string; by?: number }>;\n\n/** Coupon writes address the coupon by its `code`; the server resolves the cart from the cookie. */\nexport type CartCouponPayload = Readonly<{ code: string }>;\n\n/**\n * The `cart` namespace surface. Item writes return the resulting `userErrors` (empty on success)\n * and publish them to `cartUserErrorsVar`; coupon writes publish to the dedicated\n * `cartCouponErrorsVar` (specs/fspg-830-coupon-entry.md AD-2).\n */\nexport type CartActions = Readonly<{\n /** Add an item to the cart. Async (no optimistic response). Creates the cart on first add. */\n addItem: (payload: AddItemPayload) => Promise<readonly CartUserError[]>;\n /** Remove a line entirely. Optimistic. */\n removeItem: (payload: CartLinePayload) => Promise<readonly CartUserError[]>;\n /** Remove several lines in one mutation. Optimistic. Ids missing from the cache are skipped. */\n removeItems: (payload: CartLinesPayload) => Promise<readonly CartUserError[]>;\n /** Increase a line's quantity by N (default 1). Optimistic. */\n increaseQuantity: (payload: CartQuantityPayload) => Promise<readonly CartUserError[]>;\n /** Decrease a line's quantity by N (default 1). Optimistic. Removes the line when result <= 0. */\n decreaseQuantity: (payload: CartQuantityPayload) => Promise<readonly CartUserError[]>;\n /** Apply a coupon code. Async (no optimistic). Publishes userErrors to cartCouponErrorsVar. */\n applyCoupon: (payload: CartCouponPayload) => Promise<readonly CartUserError[]>;\n /** Remove a coupon code by code. Async (no optimistic). Publishes userErrors to cartCouponErrorsVar. */\n removeCoupon: (payload: CartCouponPayload) => Promise<readonly CartUserError[]>;\n /**\n * Re-check the active cart against the platform and adopt corrected availability. Async (no\n * optimistic), read-only upstream. Returns userErrors (empty on success) to its caller and stamps\n * the freshness window on success. Unlike the item writes it does NOT publish to\n * `cartUserErrorsVar` — a speculative open-time failure must raise no error banner (Decision 6).\n */\n validate: () => Promise<readonly CartUserError[]>;\n}>;\n\nconst NETWORK_USER_ERROR: CartUserError = {\n code: 'NETWORK_ERROR',\n message: 'Unable to update cart. Please try again.',\n};\n\nfunction publish(errors: readonly CartUserError[]): readonly CartUserError[] {\n cartUserErrorsVar(errors);\n return errors;\n}\n\n/** Coupon-scoped publish — keeps coupon feedback off the shared item-error channel (AD-2). */\nfunction publishCoupon(errors: readonly CartUserError[]): readonly CartUserError[] {\n cartCouponErrorsVar(errors);\n return errors;\n}\n\n/**\n * Publish a write's outcome and, when it came back clean, stamp the availability freshness window —\n * a clean write's payload carries the platform's recomputed cart, which is what lets the\n * validate-on-open call skip (specs/mini-cart-validation-wiring.md, Decision 2). Used only on paths\n * where a mutation actually reached the server: a `userErrors` response carries `cart: null` and a\n * no-op (unknown line) issues no request, so neither refreshes availability.\n */\nfunction publishWrite(errors: readonly CartUserError[]): readonly CartUserError[] {\n if (errors.length === 0) markAvailabilityFresh();\n return publish(errors);\n}\n\n/** Coupon-channel counterpart of `publishWrite`. */\nfunction publishCouponWrite(errors: readonly CartUserError[]): readonly CartUserError[] {\n if (errors.length === 0) markAvailabilityFresh();\n return publishCoupon(errors);\n}\n\n/**\n * Backfill `orderFormIdVar` from a mutation's returned `cart.id` when local state is still cold.\n * A coupon op can be the first cart write (SSR cold / drawer closed on first load); without this the\n * later `requireLine` paths short-circuit on `orderFormIdVar() === null` and throw `CartNotReadyError`.\n * Mirrors the `addItem` first-add handoff.\n */\nfunction hydrateCartId(cartId: string | null): void {\n if (cartId && orderFormIdVar() === null) orderFormIdVar(cartId);\n}\n\n/**\n * Read the live cart entity from the normalized cache (ADR-0010), keyed by `orderFormIdVar`. Returns\n * null before the cart is minted/loaded. Module-level so it can be shared with the read-only callers\n * that live outside this hook — the pre-checkout gate re-reads the corrected cart this way after\n * `validate` resolves, because Apollo commits the mutation's cache write before the promise settles\n * (specs/mini-cart-validation-wiring.md, Decision 3). The codegen `CartFragment` document embeds its\n * nested fragments, so it is a self-contained read.\n */\nexport function readCartFromCache(client: ApolloClient): CartEntity | null {\n const cartId = orderFormIdVar();\n if (!cartId) return null;\n const cacheId = client.cache.identify({ __typename: 'Cart', id: cartId });\n if (!cacheId) return null;\n return (\n client.cache.readFragment<CartEntity>({ id: cacheId, fragment: CartFragment, fragmentName: 'CartFragment' }) ?? null\n );\n}\n\n/**\n * The `cart` namespace hook. Registered with the first-party action registry via `cartActions`\n * below; the compiler-emitted `CartActionProvider` calls it and threads the narrowed methods into\n * each consumer's `$actions.cart`.\n */\nexport function useCartActions(): CartActions {\n const client = useApolloClient();\n\n const [addMutation] = useMutation(CART_ITEM_ADD);\n const [removeMutation] = useMutation(CART_ITEM_REMOVE);\n const [removeItemsMutation] = useMutation(CART_ITEMS_REMOVE);\n const [increaseMutation] = useMutation(CART_ITEM_QUANTITY_INCREASE);\n const [decreaseMutation] = useMutation(CART_ITEM_QUANTITY_DECREASE);\n const [applyCouponMutation] = useMutation(CART_COUPON_APPLY);\n const [removeCouponMutation] = useMutation(CART_COUPON_REMOVE);\n const [validateMutation] = useMutation(CART_VALIDATE);\n\n const readCart = useCallback((): CartEntity | null => readCartFromCache(client), [client]);\n\n const requireLine = useCallback(\n (id: string): { cart: CartEntity; line: CartItemEntity } | null => {\n const cart = readCart();\n if (!cart) throw new CartNotReadyError();\n const line = cart.items.find((item) => item.id === id);\n if (!line) return null;\n return { cart, line };\n },\n [readCart],\n );\n\n const addItem = useCallback<CartActions['addItem']>(\n async (payload) => {\n cartUserErrorsVar([]);\n try {\n const result = await trackCartWrite(\n addMutation({\n variables: {\n input: { variantId: payload.variantId, quantity: payload.quantity ?? 1, seller: payload.seller },\n },\n }),\n );\n // Very-first add: the server minted a cart from the empty transport context. Hydrate the\n // var so the existing-line handlers unlock without requiring a cart query.\n if (orderFormIdVar() === null) {\n const newId = result.data?.cartItemAdd?.cart?.id ?? null;\n if (newId) orderFormIdVar(newId);\n }\n const errors = result.data?.cartItemAdd?.userErrors ?? [];\n // Bump the add-success pulse only on the clean branch; the post-add behavior components\n // (CartOpenOnAdd / CartRedirectOnAdd) key their effect on it. The userErrors and\n // network-catch branches leave it untouched (specs/fspg-822-minicart-open-on-add.md).\n if (errors.length === 0) cartLastAddVar(cartLastAddVar() + 1);\n return publishWrite(errors);\n } catch (error) {\n console.error('[cart.addItem] cartItemAdd failed', error);\n return publish([NETWORK_USER_ERROR]);\n }\n },\n [addMutation],\n );\n\n const removeItem = useCallback<CartActions['removeItem']>(\n async (payload) => {\n const found = requireLine(payload.id);\n if (!found) return publish([]);\n cartUserErrorsVar([]);\n try {\n const result = await trackCartWrite(\n removeMutation({\n variables: { input: { variantId: found.line.variant.variantId } },\n optimisticResponse: buildOptimisticRemove(found.cart, found.line),\n }),\n );\n return publishWrite(result.data?.cartItemRemove?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.removeItem] cartItemRemove failed', error);\n return publish([NETWORK_USER_ERROR]);\n }\n },\n [requireLine, removeMutation],\n );\n\n const removeItems = useCallback<CartActions['removeItems']>(\n async (payload) => {\n const cart = readCart();\n if (!cart) throw new CartNotReadyError();\n // Client-side tolerance mirroring removeItem's not-found no-op: ids without a cached line\n // are skipped, and the surviving set is deduped before the single mutation.\n const lines = cart.items.filter((item) => payload.ids.includes(item.id));\n if (lines.length === 0) return publish([]);\n const variantIds = [...new Set(lines.map((line) => line.variant.variantId))];\n cartUserErrorsVar([]);\n try {\n const result = await trackCartWrite(\n removeItemsMutation({\n variables: { input: { variantIds } },\n optimisticResponse: buildOptimisticRemoveItems(cart, lines),\n }),\n );\n return publishWrite(result.data?.cartItemsRemove?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.removeItems] cartItemsRemove failed', error);\n return publish([NETWORK_USER_ERROR]);\n }\n },\n [readCart, removeItemsMutation],\n );\n\n const increaseQuantity = useCallback<CartActions['increaseQuantity']>(\n async (payload) => {\n const by = payload.by ?? 1;\n const found = requireLine(payload.id);\n if (!found) return publish([]);\n cartUserErrorsVar([]);\n try {\n const result = await trackCartWrite(\n increaseMutation({\n variables: { input: { variantId: found.line.variant.variantId, quantityToAdd: by } },\n optimisticResponse: buildOptimisticIncrease(found.cart, found.line, by),\n }),\n );\n return publishWrite(result.data?.cartItemQuantityIncrease?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.increaseQuantity] cartItemQuantityIncrease failed', error);\n return publish([NETWORK_USER_ERROR]);\n }\n },\n [requireLine, increaseMutation],\n );\n\n const decreaseQuantity = useCallback<CartActions['decreaseQuantity']>(\n async (payload) => {\n const by = payload.by ?? 1;\n const found = requireLine(payload.id);\n if (!found) return publish([]);\n cartUserErrorsVar([]);\n try {\n const result = await trackCartWrite(\n decreaseMutation({\n variables: { input: { variantId: found.line.variant.variantId, quantityToRemove: by } },\n optimisticResponse: buildOptimisticDecrease(found.cart, found.line, by),\n }),\n );\n return publishWrite(result.data?.cartItemQuantityDecrease?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.decreaseQuantity] cartItemQuantityDecrease failed', error);\n return publish([NETWORK_USER_ERROR]);\n }\n },\n [requireLine, decreaseMutation],\n );\n\n // Coupons are cart-level: no `requireLine` gate (AD-9). No optimistic response and no client\n // rollback — totals and `isUnmatchedCondition` are server-computed and the server rolls back its\n // own single-coupon rejections; the returned cart (spreading the extended CartFragment)\n // self-updates the cache and every reactive subscriber (specs/fspg-830-coupon-entry.md AD-3/AD-8).\n const applyCoupon = useCallback<CartActions['applyCoupon']>(\n async (payload) => {\n cartCouponErrorsVar([]);\n try {\n const result = await trackCartWrite(applyCouponMutation({ variables: { input: { code: payload.code } } }));\n hydrateCartId(result.data?.cartCouponApply?.cart?.id ?? null);\n return publishCouponWrite(result.data?.cartCouponApply?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.applyCoupon] cartCouponApply failed', error);\n return publishCoupon([NETWORK_USER_ERROR]);\n }\n },\n [applyCouponMutation],\n );\n\n const removeCoupon = useCallback<CartActions['removeCoupon']>(\n async (payload) => {\n cartCouponErrorsVar([]);\n try {\n const result = await trackCartWrite(removeCouponMutation({ variables: { input: { code: payload.code } } }));\n hydrateCartId(result.data?.cartCouponRemove?.cart?.id ?? null);\n return publishCouponWrite(result.data?.cartCouponRemove?.userErrors ?? []);\n } catch (error) {\n console.error('[cart.removeCoupon] cartCouponRemove failed', error);\n return publishCoupon([NETWORK_USER_ERROR]);\n }\n },\n [removeCouponMutation],\n );\n\n // Read-only upstream (specs/mini-cart-validate-operation.md): re-simulates the cart and returns it\n // with `variant.availability` corrected, spreading CartFragment so the guard, the per-line alert,\n // and the badge re-render off the cache. Deliberately unlike the item writes: it does NOT register\n // as an in-flight write (it would gate itself) and it does NOT publish to cartUserErrorsVar — the\n // open call is speculative and the pre-checkout call is fail-open, so a failure must raise no error\n // banner (Decision 6). It stamps the freshness window on success so open-on-add does not re-check.\n const validate = useCallback<CartActions['validate']>(async () => {\n try {\n const result = await validateMutation();\n // Hydrate as the coupon writes do: the corrected cart is now in the cache, and the pre-checkout\n // gate finds it by `orderFormIdVar`. Without this a cold var would leave the gate reading null\n // and passing a cart it never actually checked.\n hydrateCartId(result.data?.cartValidate?.cart?.id ?? null);\n const errors = result.data?.cartValidate?.userErrors ?? [];\n if (errors.length === 0) markAvailabilityFresh();\n return errors;\n } catch (error) {\n console.error('[cart.validate] cartValidate failed', error);\n return [NETWORK_USER_ERROR];\n }\n }, [validateMutation]);\n\n return useMemo(\n () => ({\n addItem,\n removeItem,\n removeItems,\n increaseQuantity,\n decreaseQuantity,\n applyCoupon,\n removeCoupon,\n validate,\n }),\n [addItem, removeItem, removeItems, increaseQuantity, decreaseQuantity, applyCoupon, removeCoupon, validate],\n );\n}\n\n/**\n * Declares the `cart` action namespace — the single source of truth for its method/payload metadata,\n * runtime provider, and `use` hook (mirrors `defineComponent`). The native catalog builder\n * (`@vtex/sukima-node`'s `buildPackageCatalog`) statically reads this call to emit `actions.json`;\n * at runtime `CartActionProvider` calls `useCartActions` directly.\n */\nexport const cartActions = defineActions({\n namespace: 'cart',\n description: 'Mutation-backed writes against the current cart (consolidates useCartMutations / CartRoot).',\n provider: { name: 'CartActionProvider', importPath: '@vtex/faststore/internal/client' },\n methods: {\n addItem: {\n description: 'Add an item to the cart (async strategy). Creates the cart on first add.',\n payload: [\n { name: 'variantId', type: 'string' },\n { name: 'seller', type: 'string' },\n { name: 'quantity', type: 'number', optional: true },\n ],\n },\n removeItem: {\n description: 'Remove a line from the cart (optimistic strategy).',\n payload: [{ name: 'id', type: 'string' }],\n },\n removeItems: {\n description: 'Remove several lines from the cart in one call (optimistic strategy).',\n payload: [{ name: 'ids', type: 'string[]' }],\n },\n increaseQuantity: {\n description: \"Increase a line's quantity by N (default 1, optimistic strategy).\",\n payload: [\n { name: 'id', type: 'string' },\n { name: 'by', type: 'number', optional: true },\n ],\n },\n decreaseQuantity: {\n description: \"Decrease a line's quantity by N (default 1, optimistic). Removes the line at <= 0.\",\n payload: [\n { name: 'id', type: 'string' },\n { name: 'by', type: 'number', optional: true },\n ],\n },\n applyCoupon: {\n description: 'Apply a coupon code to the cart (async strategy). Server recomputes totals.',\n payload: [{ name: 'code', type: 'string' }],\n },\n removeCoupon: {\n description: 'Remove a coupon code from the cart (async strategy). Server recomputes totals.',\n payload: [{ name: 'code', type: 'string' }],\n },\n validate: {\n description:\n 'Re-check the active cart against the platform and adopt corrected availability (async, read-only upstream).',\n payload: [],\n },\n },\n use: useCartActions,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,IAAa,oBAAb,cAAuC,MAAM;CAC3C,YAAY,SAAkB;EAC5B,MAAM,W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;GAChB,aAAa;GACb,SAAS,CACP;IAAE,MAAM;IAAM,MAAM;GAAS,GAC7B;IAAE,MAAM;IAAM,MAAM;IAAU,UAAU;GAAK,CAC/C;EACF;EACA,kBAAkB;GAChB,aAAa;GACb,SAAS,CACP;IAAE,MAAM;IAAM,MAAM;GAAS,GAC7B;IAAE,MAAM;IAAM,MAAM;IAAU,UAAU;GAAK,CAC/C;EACF;EACA,aAAa;GACX,aAAa;GACb,SAAS,CAAC;IAAE,MAAM;IAAQ,MAAM;GAAS,CAAC;EAC5C;EACA,cAAc;GACZ,aAAa;GACb,SAAS,CAAC;IAAE,MAAM;IAAQ,MAAM;GAAS,CAAC;EAC5C;EACA,UAAU;GACR,aACE;GACF,SAAS,CAAC;EACZ;CACF;CACA,KAAK;AACP,CAAC"}
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { cartAvailabilityFreshAtVar, cartWritesInFlightVar, miniCartOpenVar } from "../state/cart.js";
3
+ import { readCartFromCache } from "./use-cart-actions.js";
4
+ import { useApolloClient, useReactiveVar } from "@apollo/client/react";
5
+ import { useEffect, useRef } from "react";
6
+ //#region src/sdk/cart/use-cart-validate-on-open.ts
7
+ /**
8
+ * Runs stock validation when the mini-cart overlay opens (specs/mini-cart-validation-wiring.md, FR-5).
9
+ *
10
+ * `miniCartOpenVar` is the overlay's single source of truth — the add-pulse open, the header trigger,
11
+ * and manual close all route through it — so watching its closed→open edge covers every way the
12
+ * drawer opens. The call is bounded and cooperative: it fires at most once per transition, and skips
13
+ * when there is nothing to gain — no validate action wired, a cart write in flight, availability
14
+ * refreshed within the staleness window (which is why open-on-add does not re-validate), or an empty
15
+ * cart. `validate` is the compiler-injected `$actions.cart.validate`; when it is absent the hook is a
16
+ * no-op, so a store without the action wired pays nothing.
17
+ *
18
+ * A dispatch is reserved synchronously with a ref latch, cleared when the call settles. Freshness is
19
+ * only stamped once `validate` resolves, so a close-and-reopen during that window would otherwise slip
20
+ * past the staleness guard and fire a second call; the latch closes that gap.
21
+ */
22
+ function useCartValidateOnOpen(validate) {
23
+ const client = useApolloClient();
24
+ const open = useReactiveVar(miniCartOpenVar);
25
+ const wasOpen = useRef(open);
26
+ const pending = useRef(false);
27
+ useEffect(() => {
28
+ const opened = open && !wasOpen.current;
29
+ wasOpen.current = open;
30
+ if (!opened || !validate || pending.current) return;
31
+ if (cartWritesInFlightVar() > 0) return;
32
+ if (Date.now() - cartAvailabilityFreshAtVar() < 3e4) return;
33
+ const cart = readCartFromCache(client);
34
+ if (!cart || cart.items.length === 0) return;
35
+ pending.current = true;
36
+ Promise.resolve(validate()).catch((error) => {
37
+ console.error("[cart.validateOnOpen] validate rejected", error);
38
+ }).finally(() => {
39
+ pending.current = false;
40
+ });
41
+ }, [
42
+ open,
43
+ validate,
44
+ client
45
+ ]);
46
+ }
47
+ //#endregion
48
+ export { useCartValidateOnOpen };
49
+
50
+ //# sourceMappingURL=use-cart-validate-on-open.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-cart-validate-on-open.js","names":[],"sources":["../../../src/sdk/cart/use-cart-validate-on-open.ts"],"sourcesContent":["'use client';\n\nimport { useApolloClient, useReactiveVar } from '@apollo/client/react';\nimport { useEffect, useRef } from 'react';\nimport {\n CART_VALIDATE_STALENESS_MS,\n cartAvailabilityFreshAtVar,\n cartWritesInFlightVar,\n miniCartOpenVar,\n} from '../state/cart.js';\nimport { readCartFromCache } from './use-cart-actions.js';\n\n/**\n * Runs stock validation when the mini-cart overlay opens (specs/mini-cart-validation-wiring.md, FR-5).\n *\n * `miniCartOpenVar` is the overlay's single source of truth — the add-pulse open, the header trigger,\n * and manual close all route through it — so watching its closed→open edge covers every way the\n * drawer opens. The call is bounded and cooperative: it fires at most once per transition, and skips\n * when there is nothing to gain — no validate action wired, a cart write in flight, availability\n * refreshed within the staleness window (which is why open-on-add does not re-validate), or an empty\n * cart. `validate` is the compiler-injected `$actions.cart.validate`; when it is absent the hook is a\n * no-op, so a store without the action wired pays nothing.\n *\n * A dispatch is reserved synchronously with a ref latch, cleared when the call settles. Freshness is\n * only stamped once `validate` resolves, so a close-and-reopen during that window would otherwise slip\n * past the staleness guard and fire a second call; the latch closes that gap.\n */\nexport function useCartValidateOnOpen(validate: (() => Promise<unknown>) | undefined): void {\n const client = useApolloClient();\n const open = useReactiveVar(miniCartOpenVar);\n const wasOpen = useRef(open);\n const pending = useRef(false);\n\n useEffect(() => {\n const opened = open && !wasOpen.current;\n wasOpen.current = open;\n if (!opened || !validate || pending.current) return;\n // A write in flight (or one that just settled, inside the window) already refreshed availability.\n if (cartWritesInFlightVar() > 0) return;\n if (Date.now() - cartAvailabilityFreshAtVar() < CART_VALIDATE_STALENESS_MS) return;\n // Nothing to validate on an empty cart, and T1 would only round-trip a single read for it.\n const cart = readCartFromCache(client);\n if (!cart || cart.items.length === 0) return;\n pending.current = true;\n // The current wiring never rejects (useCartActions().validate catches and resolves with\n // [NETWORK_USER_ERROR]); this guards a differently-injected validate so a rejection cannot\n // escape as an unhandled promise rejection.\n void Promise.resolve(validate())\n .catch((error) => {\n console.error('[cart.validateOnOpen] validate rejected', error);\n })\n .finally(() => {\n pending.current = false;\n });\n }, [open, validate, client]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBAAsB,UAAsD;CAC1F,MAAM,SAAS,gBAAgB;CAC/B,MAAM,OAAO,eAAe,eAAe;CAC3C,MAAM,UAAU,OAAO,IAAI;CAC3B,MAAM,UAAU,OAAO,KAAK;CAE5B,gBAAgB;EACd,MAAM,SAAS,QAAQ,CAAC,QAAQ;EAChC,QAAQ,UAAU;EAClB,IAAI,CAAC,UAAU,CAAC,YAAY,QAAQ,SAAS;EAE7C,IAAI,sBAAsB,IAAI,GAAG;EACjC,IAAI,KAAK,IAAI,IAAI,2BAA2B,IAAA,KAAgC;EAE5E,MAAM,OAAO,kBAAkB,MAAM;EACrC,IAAI,CAAC,QAAQ,KAAK,MAAM,WAAW,GAAG;EACtC,QAAQ,UAAU;EAIlB,QAAa,QAAQ,SAAS,CAAC,CAAC,CAC7B,OAAO,UAAU;GAChB,QAAQ,MAAM,2CAA2C,KAAK;EAChE,CAAC,CAAC,CACD,cAAc;GACb,QAAQ,UAAU;EACpB,CAAC;CACL,GAAG;EAAC;EAAM;EAAU;CAAM,CAAC;AAC7B"}
@@ -0,0 +1,54 @@
1
+ import { cartAvailabilityFreshAtVar, cartWritesInFlightVar } from "../state/cart.js";
2
+ //#region src/sdk/cart/write-gate.ts
3
+ /**
4
+ * In-flight cart-write registry (specs/mini-cart-validation-wiring.md, Decision 2).
5
+ *
6
+ * The stock-validation wiring needs two things the mutation contract never had to expose, because
7
+ * the open-time validate is the first cart call that is not user-initiated:
8
+ *
9
+ * - an observable "is a write running" signal, so the open call can *skip* while one is (that
10
+ * write's response already carries current availability); and
11
+ * - an `await`-settlement primitive, so the pre-checkout call can *wait* for any write before it
12
+ * re-checks the cart it is about to send to checkout.
13
+ *
14
+ * Both derive from one module-scoped set of pending write promises. `validate` is read-only upstream
15
+ * and must never register here — it would gate itself.
16
+ */
17
+ const inFlight = /* @__PURE__ */ new Set();
18
+ /**
19
+ * Stamp "availability is fresh as of now". Called only where the client actually received current
20
+ * availability: a cart write that came back clean, or a successful `validate`. A write answered with
21
+ * `userErrors` carries `cart: null` (mutation contract), so it learned nothing and must not stamp —
22
+ * otherwise the next overlay open would skip validation on the strength of a rejected write.
23
+ */
24
+ function markAvailabilityFresh() {
25
+ cartAvailabilityFreshAtVar(Date.now());
26
+ }
27
+ /**
28
+ * Register a cart write's promise for the lifetime of the call, publishing the reactive in-flight
29
+ * count so the validate-on-open call can skip while a write is outstanding. Tracking only — the
30
+ * freshness stamp belongs to the caller, which is the only place that can see whether the payload
31
+ * came back clean. Returns the same promise so callers can `await trackCartWrite(mutation(...))`.
32
+ */
33
+ function trackCartWrite(promise) {
34
+ inFlight.add(promise);
35
+ cartWritesInFlightVar(inFlight.size);
36
+ const clear = () => {
37
+ inFlight.delete(promise);
38
+ cartWritesInFlightVar(inFlight.size);
39
+ };
40
+ promise.then(clear, clear);
41
+ return promise;
42
+ }
43
+ /**
44
+ * Resolve once every write registered at call time has settled (fulfilled or rejected). Writes
45
+ * started afterwards are not awaited — this captures "any in-flight write" at the moment the
46
+ * pre-checkout call fires, which is exactly the ordering guarantee the checkout gate needs.
47
+ */
48
+ function awaitCartWrites() {
49
+ return Promise.allSettled(inFlight).then(() => void 0);
50
+ }
51
+ //#endregion
52
+ export { awaitCartWrites, markAvailabilityFresh, trackCartWrite };
53
+
54
+ //# sourceMappingURL=write-gate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-gate.js","names":[],"sources":["../../../src/sdk/cart/write-gate.ts"],"sourcesContent":["import { cartAvailabilityFreshAtVar, cartWritesInFlightVar } from '../state/cart.js';\n\n/**\n * In-flight cart-write registry (specs/mini-cart-validation-wiring.md, Decision 2).\n *\n * The stock-validation wiring needs two things the mutation contract never had to expose, because\n * the open-time validate is the first cart call that is not user-initiated:\n *\n * - an observable \"is a write running\" signal, so the open call can *skip* while one is (that\n * write's response already carries current availability); and\n * - an `await`-settlement primitive, so the pre-checkout call can *wait* for any write before it\n * re-checks the cart it is about to send to checkout.\n *\n * Both derive from one module-scoped set of pending write promises. `validate` is read-only upstream\n * and must never register here — it would gate itself.\n */\n\nconst inFlight = new Set<Promise<unknown>>();\n\n/**\n * Stamp \"availability is fresh as of now\". Called only where the client actually received current\n * availability: a cart write that came back clean, or a successful `validate`. A write answered with\n * `userErrors` carries `cart: null` (mutation contract), so it learned nothing and must not stamp —\n * otherwise the next overlay open would skip validation on the strength of a rejected write.\n */\nexport function markAvailabilityFresh(): void {\n cartAvailabilityFreshAtVar(Date.now());\n}\n\n/**\n * Register a cart write's promise for the lifetime of the call, publishing the reactive in-flight\n * count so the validate-on-open call can skip while a write is outstanding. Tracking only — the\n * freshness stamp belongs to the caller, which is the only place that can see whether the payload\n * came back clean. Returns the same promise so callers can `await trackCartWrite(mutation(...))`.\n */\nexport function trackCartWrite<T>(promise: Promise<T>): Promise<T> {\n inFlight.add(promise);\n cartWritesInFlightVar(inFlight.size);\n const clear = () => {\n inFlight.delete(promise);\n cartWritesInFlightVar(inFlight.size);\n };\n promise.then(clear, clear);\n return promise;\n}\n\n/**\n * Resolve once every write registered at call time has settled (fulfilled or rejected). Writes\n * started afterwards are not awaited — this captures \"any in-flight write\" at the moment the\n * pre-checkout call fires, which is exactly the ordering guarantee the checkout gate needs.\n */\nexport function awaitCartWrites(): Promise<void> {\n return Promise.allSettled(inFlight).then(() => undefined);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAM,2BAAW,IAAI,IAAsB;;;;;;;AAQ3C,SAAgB,wBAA8B;CAC5C,2BAA2B,KAAK,IAAI,CAAC;AACvC;;;;;;;AAQA,SAAgB,eAAkB,SAAiC;CACjE,SAAS,IAAI,OAAO;CACpB,sBAAsB,SAAS,IAAI;CACnC,MAAM,cAAc;EAClB,SAAS,OAAO,OAAO;EACvB,sBAAsB,SAAS,IAAI;CACrC;CACA,QAAQ,KAAK,OAAO,KAAK;CACzB,OAAO;AACT;;;;;;AAOA,SAAgB,kBAAiC;CAC/C,OAAO,QAAQ,WAAW,QAAQ,CAAC,CAAC,WAAW,KAAA,CAAS;AAC1D"}
@@ -0,0 +1,20 @@
1
+ //#region src/sdk/client/assert-api-url.ts
2
+ /**
3
+ * Validates that `apiUrl` is a parseable URL with an http(s) protocol. Used by
4
+ * `createClient` and `registerPreloadQuery` so misconfiguration (typo, missing
5
+ * protocol, `file://`, internal scheme) fails at startup with a clear message
6
+ * instead of surfacing as an opaque runtime fetch error.
7
+ */
8
+ function assertValidApiUrl(apiUrl, fnName) {
9
+ let parsed;
10
+ try {
11
+ parsed = new URL(apiUrl);
12
+ } catch {
13
+ throw new Error(`${fnName}: \`apiUrl\` is not a valid URL (got "${apiUrl}").`);
14
+ }
15
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new Error(`${fnName}: \`apiUrl\` must use http or https (got "${parsed.protocol}").`);
16
+ }
17
+ //#endregion
18
+ export { assertValidApiUrl };
19
+
20
+ //# sourceMappingURL=assert-api-url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-api-url.js","names":[],"sources":["../../../src/sdk/client/assert-api-url.ts"],"sourcesContent":["/**\n * Validates that `apiUrl` is a parseable URL with an http(s) protocol. Used by\n * `createClient` and `registerPreloadQuery` so misconfiguration (typo, missing\n * protocol, `file://`, internal scheme) fails at startup with a clear message\n * instead of surfacing as an opaque runtime fetch error.\n */\nexport function assertValidApiUrl(apiUrl: string, fnName: string): void {\n let parsed: URL;\n try {\n parsed = new URL(apiUrl);\n } catch {\n throw new Error(`${fnName}: \\`apiUrl\\` is not a valid URL (got \"${apiUrl}\").`);\n }\n\n if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {\n throw new Error(`${fnName}: \\`apiUrl\\` must use http or https (got \"${parsed.protocol}\").`);\n }\n}\n"],"mappings":";;;;;;;AAMA,SAAgB,kBAAkB,QAAgB,QAAsB;CACtE,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,MAAM;CACzB,QAAQ;EACN,MAAM,IAAI,MAAM,GAAG,OAAO,wCAAwC,OAAO,IAAI;CAC/E;CAEA,IAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UACrD,MAAM,IAAI,MAAM,GAAG,OAAO,4CAA4C,OAAO,SAAS,IAAI;AAE9F"}
@@ -0,0 +1,23 @@
1
+ import { StorefrontContext } from "../../core/dist/schema/generated/schema.js";
2
+ import "../../core/dist/index.js";
3
+ import { ApolloClient } from "@apollo/client";
4
+ //#region src/sdk/client/create-client.d.ts
5
+ export type CreateClientOptions = {
6
+ apiUrl?: string;
7
+ /** The compiler-emitted context; its three headers ride every operation this client sends. */
8
+ context?: StorefrontContext;
9
+ headers?: Record<string, string>;
10
+ };
11
+ /**
12
+ * Returns a fresh, stateless Apollo Client suitable for server-side
13
+ * rendering / RSC calls. Every invocation builds a new cache — callers
14
+ * that need "one client per lambda" are responsible for caching the
15
+ * returned instance themselves (see the generated `utils/query-client.ts`).
16
+ *
17
+ * The client shares its `typePolicies` + `possibleTypes` with the
18
+ * browser-side client via `buildCache()` so normalized entities line up
19
+ * across SSR / CSR boundaries.
20
+ */
21
+ export declare function createClient(options?: CreateClientOptions): ApolloClient;
22
+ //#endregion
23
+ //# sourceMappingURL=create-client.d.ts.map
@@ -0,0 +1,46 @@
1
+ import { buildStorefrontContextHeaders } from "../context/headers.js";
2
+ import { buildCache } from "../cache/storefront-cache.js";
3
+ import { assertValidApiUrl } from "./assert-api-url.js";
4
+ import { ApolloClient, HttpLink } from "@apollo/client";
5
+ //#region src/sdk/client/create-client.ts
6
+ /**
7
+ * Returns a fresh, stateless Apollo Client suitable for server-side
8
+ * rendering / RSC calls. Every invocation builds a new cache — callers
9
+ * that need "one client per lambda" are responsible for caching the
10
+ * returned instance themselves (see the generated `utils/query-client.ts`).
11
+ *
12
+ * The client shares its `typePolicies` + `possibleTypes` with the
13
+ * browser-side client via `buildCache()` so normalized entities line up
14
+ * across SSR / CSR boundaries.
15
+ */
16
+ function createClient(options = {}) {
17
+ const apiUrl = options.apiUrl ?? process.env.STOREFRONT_API_URL;
18
+ if (!apiUrl) throw new Error("createClient: `apiUrl` is required. Pass it via options or set the `STOREFRONT_API_URL` environment variable.");
19
+ assertValidApiUrl(apiUrl, "createClient");
20
+ const headers = options.context ? {
21
+ ...options.headers,
22
+ ...buildStorefrontContextHeaders(options.context)
23
+ } : options.headers;
24
+ const link = new HttpLink({
25
+ uri: apiUrl,
26
+ ...headers ? { headers } : {}
27
+ });
28
+ return new ApolloClient({
29
+ cache: buildCache(),
30
+ link,
31
+ defaultOptions: {
32
+ query: {
33
+ errorPolicy: "all",
34
+ fetchPolicy: "no-cache"
35
+ },
36
+ watchQuery: {
37
+ errorPolicy: "all",
38
+ fetchPolicy: "no-cache"
39
+ }
40
+ }
41
+ });
42
+ }
43
+ //#endregion
44
+ export { createClient };
45
+
46
+ //# sourceMappingURL=create-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-client.js","names":[],"sources":["../../../src/sdk/client/create-client.ts"],"sourcesContent":["import { ApolloClient, HttpLink } from '@apollo/client';\nimport type { StorefrontContext } from '@vtex/fs-core';\nimport { buildCache } from '../cache/storefront-cache.js';\nimport { buildStorefrontContextHeaders } from '../context/headers.js';\nimport { assertValidApiUrl } from './assert-api-url.js';\n\nexport type CreateClientOptions = {\n apiUrl?: string;\n /** The compiler-emitted context; its three headers ride every operation this client sends. */\n context?: StorefrontContext;\n headers?: Record<string, string>;\n};\n\n/**\n * Returns a fresh, stateless Apollo Client suitable for server-side\n * rendering / RSC calls. Every invocation builds a new cache — callers\n * that need \"one client per lambda\" are responsible for caching the\n * returned instance themselves (see the generated `utils/query-client.ts`).\n *\n * The client shares its `typePolicies` + `possibleTypes` with the\n * browser-side client via `buildCache()` so normalized entities line up\n * across SSR / CSR boundaries.\n */\nexport function createClient(options: CreateClientOptions = {}): ApolloClient {\n const apiUrl = options.apiUrl ?? process.env.STOREFRONT_API_URL;\n\n if (!apiUrl) {\n throw new Error(\n 'createClient: `apiUrl` is required. Pass it via options or set the ' +\n '`STOREFRONT_API_URL` environment variable.',\n );\n }\n\n assertValidApiUrl(apiUrl, 'createClient');\n\n // Context headers merge last: a caller cannot contradict the context the app rendered. To request a\n // different locale, binding or sales channel, pass a different `context`.\n const headers = options.context\n ? { ...options.headers, ...buildStorefrontContextHeaders(options.context) }\n : options.headers;\n\n const link = new HttpLink({\n uri: apiUrl,\n ...(headers ? { headers } : {}),\n });\n\n return new ApolloClient({\n cache: buildCache(),\n link,\n defaultOptions: {\n query: { errorPolicy: 'all', fetchPolicy: 'no-cache' },\n watchQuery: { errorPolicy: 'all', fetchPolicy: 'no-cache' },\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,UAA+B,CAAC,GAAiB;CAC5E,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,IAAI,CAAC,QACH,MAAM,IAAI,MACR,+GAEF;CAGF,kBAAkB,QAAQ,cAAc;CAIxC,MAAM,UAAU,QAAQ,UACpB;EAAE,GAAG,QAAQ;EAAS,GAAG,8BAA8B,QAAQ,OAAO;CAAE,IACxE,QAAQ;CAEZ,MAAM,OAAO,IAAI,SAAS;EACxB,KAAK;EACL,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;CAC/B,CAAC;CAED,OAAO,IAAI,aAAa;EACtB,OAAO,WAAW;EAClB;EACA,gBAAgB;GACd,OAAO;IAAE,aAAa;IAAO,aAAa;GAAW;GACrD,YAAY;IAAE,aAAa;IAAO,aAAa;GAAW;EAC5D;CACF,CAAC;AACH"}
@@ -0,0 +1,39 @@
1
+ import { ApolloClient, DocumentNode, ErrorLike, OperationVariables, TypedDocumentNode } from "@apollo/client";
2
+ //#region src/sdk/client/fetch-page-data.d.ts
3
+ /**
4
+ * Options bag accepted by {@link fetchPageData}.
5
+ *
6
+ * Mirrors Apollo Client 4.x's own `VariablesOption<TVars>` shape: when
7
+ * `TVars` has no required keys (the default `OperationVariables`), variables
8
+ * are optional; when the caller supplies a concrete variables object with
9
+ * required fields, variables become required — matching the contract of the
10
+ * underlying `client.query` call.
11
+ */
12
+ export type FetchPageDataOptions<TVars extends OperationVariables> = {} extends TVars ? {
13
+ variables?: TVars;
14
+ } : {
15
+ variables: TVars;
16
+ };
17
+ export type FetchPageDataResult<TData> = {
18
+ data: TData | null;
19
+ error?: ErrorLike;
20
+ };
21
+ /**
22
+ * Runs a single query against the provided Apollo Client with the options
23
+ * required for stateless RSC rendering (`errorPolicy: 'all'` — partial data
24
+ * is returned alongside the error — and `fetchPolicy: 'no-cache'` — the
25
+ * client's cache is never consulted, so a long-lived module-level client
26
+ * cannot leak state across requests).
27
+ *
28
+ * Never constructs a client itself; callers own the client lifetime via
29
+ * the generated `utils/query-client.ts` or a direct `createClient()` call.
30
+ *
31
+ * Under `errorPolicy: 'all'`, Apollo reports every failure — GraphQL errors
32
+ * and transport-level errors alike — via the `error` field alongside any
33
+ * partial `data` the server produced. Callers who need to distinguish the
34
+ * two can inspect `result.error` with `CombinedGraphQLErrors.is()` from
35
+ * `@apollo/client/errors`.
36
+ */
37
+ export declare function fetchPageData<TData = unknown, TVars extends OperationVariables = OperationVariables>(client: ApolloClient, document: DocumentNode | TypedDocumentNode<TData, TVars>, options?: FetchPageDataOptions<TVars>): Promise<FetchPageDataResult<TData>>;
38
+ //#endregion
39
+ //# sourceMappingURL=fetch-page-data.d.ts.map
@@ -0,0 +1,33 @@
1
+ //#region src/sdk/client/fetch-page-data.ts
2
+ /**
3
+ * Runs a single query against the provided Apollo Client with the options
4
+ * required for stateless RSC rendering (`errorPolicy: 'all'` — partial data
5
+ * is returned alongside the error — and `fetchPolicy: 'no-cache'` — the
6
+ * client's cache is never consulted, so a long-lived module-level client
7
+ * cannot leak state across requests).
8
+ *
9
+ * Never constructs a client itself; callers own the client lifetime via
10
+ * the generated `utils/query-client.ts` or a direct `createClient()` call.
11
+ *
12
+ * Under `errorPolicy: 'all'`, Apollo reports every failure — GraphQL errors
13
+ * and transport-level errors alike — via the `error` field alongside any
14
+ * partial `data` the server produced. Callers who need to distinguish the
15
+ * two can inspect `result.error` with `CombinedGraphQLErrors.is()` from
16
+ * `@apollo/client/errors`.
17
+ */
18
+ async function fetchPageData(client, document, options = {}) {
19
+ const result = await client.query({
20
+ ...options,
21
+ query: document,
22
+ errorPolicy: "all",
23
+ fetchPolicy: "no-cache"
24
+ });
25
+ return {
26
+ data: result.data ?? null,
27
+ ...result.error ? { error: result.error } : {}
28
+ };
29
+ }
30
+ //#endregion
31
+ export { fetchPageData };
32
+
33
+ //# sourceMappingURL=fetch-page-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-page-data.js","names":[],"sources":["../../../src/sdk/client/fetch-page-data.ts"],"sourcesContent":["import type { ApolloClient, DocumentNode, ErrorLike, OperationVariables, TypedDocumentNode } from '@apollo/client';\n\n/**\n * Options bag accepted by {@link fetchPageData}.\n *\n * Mirrors Apollo Client 4.x's own `VariablesOption<TVars>` shape: when\n * `TVars` has no required keys (the default `OperationVariables`), variables\n * are optional; when the caller supplies a concrete variables object with\n * required fields, variables become required — matching the contract of the\n * underlying `client.query` call.\n */\n// biome-ignore lint/complexity/noBannedTypes: `{} extends TVars` is the idiomatic probe for \"variables has no required keys\" — same pattern Apollo itself uses.\nexport type FetchPageDataOptions<TVars extends OperationVariables> = {} extends TVars\n ? { variables?: TVars }\n : { variables: TVars };\n\nexport type FetchPageDataResult<TData> = {\n data: TData | null;\n error?: ErrorLike;\n};\n\n/**\n * Runs a single query against the provided Apollo Client with the options\n * required for stateless RSC rendering (`errorPolicy: 'all'` — partial data\n * is returned alongside the error — and `fetchPolicy: 'no-cache'` — the\n * client's cache is never consulted, so a long-lived module-level client\n * cannot leak state across requests).\n *\n * Never constructs a client itself; callers own the client lifetime via\n * the generated `utils/query-client.ts` or a direct `createClient()` call.\n *\n * Under `errorPolicy: 'all'`, Apollo reports every failure — GraphQL errors\n * and transport-level errors alike — via the `error` field alongside any\n * partial `data` the server produced. Callers who need to distinguish the\n * two can inspect `result.error` with `CombinedGraphQLErrors.is()` from\n * `@apollo/client/errors`.\n */\nexport async function fetchPageData<TData = unknown, TVars extends OperationVariables = OperationVariables>(\n client: ApolloClient,\n document: DocumentNode | TypedDocumentNode<TData, TVars>,\n options: FetchPageDataOptions<TVars> = {} as FetchPageDataOptions<TVars>,\n): Promise<FetchPageDataResult<TData>> {\n const result = await client.query<TData, TVars>({\n ...options,\n query: document,\n errorPolicy: 'all',\n fetchPolicy: 'no-cache',\n });\n\n return {\n data: result.data ?? null,\n ...(result.error ? { error: result.error } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAqCA,eAAsB,cACpB,QACA,UACA,UAAuC,CAAC,GACH;CACrC,MAAM,SAAS,MAAM,OAAO,MAAoB;EAC9C,GAAG;EACH,OAAO;EACP,aAAa;EACb,aAAa;CACf,CAAC;CAED,OAAO;EACL,MAAM,OAAO,QAAQ;EACrB,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;CAChD;AACF"}
@@ -0,0 +1,24 @@
1
+ import { StorefrontContext } from "../../core/dist/schema/generated/schema.js";
2
+ import "../../core/dist/index.js";
3
+ import { ApolloClient, registerApolloClient } from "@apollo/client-integration-nextjs";
4
+ //#region src/sdk/client/register-preload-query.d.ts
5
+ export type RegisterPreloadQueryOptions = {
6
+ /** Storefront GraphQL endpoint. Defaults to `process.env.STOREFRONT_API_URL`. */
7
+ apiUrl?: string;
8
+ /** The compiler-emitted context; its three headers ride every RSC-side query. */
9
+ context?: StorefrontContext;
10
+ /** Headers forwarded with every RSC-side query. */
11
+ headers?: Record<string, string>;
12
+ };
13
+ export type PreloadQueryRegistry = ReturnType<typeof registerApolloClient<ApolloClient>>;
14
+ /**
15
+ * Registers an RSC-only ApolloClient using Apollo's streaming-aware classes and returns the
16
+ * destructurable `{ getClient, query, PreloadQuery }` shape. Call once at module level in the
17
+ * generated app (see `templates/nextjs-app/src/utils/query-client.ts`).
18
+ *
19
+ * The returned `PreloadQuery` prewarms the cache during RSC; the result is transported via
20
+ * Apollo's streaming protocol so `useSuspenseQuery` reads it synchronously on the client.
21
+ */
22
+ export declare function registerPreloadQuery(options?: RegisterPreloadQueryOptions): PreloadQueryRegistry;
23
+ //#endregion
24
+ //# sourceMappingURL=register-preload-query.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { buildStorefrontContextHeaders } from "../context/headers.js";
2
+ import { assertValidApiUrl } from "./assert-api-url.js";
3
+ import { HttpLink } from "@apollo/client";
4
+ import { ApolloClient as ApolloClient$1, InMemoryCache as InMemoryCache$1, registerApolloClient } from "@apollo/client-integration-nextjs";
5
+ //#region src/sdk/client/register-preload-query.ts
6
+ /**
7
+ * Registers an RSC-only ApolloClient using Apollo's streaming-aware classes and returns the
8
+ * destructurable `{ getClient, query, PreloadQuery }` shape. Call once at module level in the
9
+ * generated app (see `templates/nextjs-app/src/utils/query-client.ts`).
10
+ *
11
+ * The returned `PreloadQuery` prewarms the cache during RSC; the result is transported via
12
+ * Apollo's streaming protocol so `useSuspenseQuery` reads it synchronously on the client.
13
+ */
14
+ function registerPreloadQuery(options = {}) {
15
+ const apiUrl = options.apiUrl ?? process.env.STOREFRONT_API_URL;
16
+ if (!apiUrl) throw new Error("registerPreloadQuery: `apiUrl` is required. Pass it via options or set the `STOREFRONT_API_URL` environment variable.");
17
+ assertValidApiUrl(apiUrl, "registerPreloadQuery");
18
+ const headers = options.context ? {
19
+ ...options.headers,
20
+ ...buildStorefrontContextHeaders(options.context)
21
+ } : options.headers;
22
+ return registerApolloClient(() => new ApolloClient$1({
23
+ cache: new InMemoryCache$1(),
24
+ link: new HttpLink({
25
+ uri: apiUrl,
26
+ ...headers ? { headers } : {}
27
+ })
28
+ }));
29
+ }
30
+ //#endregion
31
+ export { registerPreloadQuery };
32
+
33
+ //# sourceMappingURL=register-preload-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-preload-query.js","names":["ApolloClient","InMemoryCache"],"sources":["../../../src/sdk/client/register-preload-query.ts"],"sourcesContent":["import { HttpLink } from '@apollo/client';\nimport { ApolloClient, InMemoryCache, registerApolloClient } from '@apollo/client-integration-nextjs';\nimport type { StorefrontContext } from '@vtex/fs-core';\nimport { buildStorefrontContextHeaders } from '../context/headers.js';\nimport { assertValidApiUrl } from './assert-api-url.js';\n\nexport type RegisterPreloadQueryOptions = {\n /** Storefront GraphQL endpoint. Defaults to `process.env.STOREFRONT_API_URL`. */\n apiUrl?: string;\n /** The compiler-emitted context; its three headers ride every RSC-side query. */\n context?: StorefrontContext;\n /** Headers forwarded with every RSC-side query. */\n headers?: Record<string, string>;\n};\n\nexport type PreloadQueryRegistry = ReturnType<typeof registerApolloClient<ApolloClient>>;\n\n/**\n * Registers an RSC-only ApolloClient using Apollo's streaming-aware classes and returns the\n * destructurable `{ getClient, query, PreloadQuery }` shape. Call once at module level in the\n * generated app (see `templates/nextjs-app/src/utils/query-client.ts`).\n *\n * The returned `PreloadQuery` prewarms the cache during RSC; the result is transported via\n * Apollo's streaming protocol so `useSuspenseQuery` reads it synchronously on the client.\n */\nexport function registerPreloadQuery(options: RegisterPreloadQueryOptions = {}): PreloadQueryRegistry {\n const apiUrl = options.apiUrl ?? process.env.STOREFRONT_API_URL;\n\n if (!apiUrl) {\n throw new Error(\n 'registerPreloadQuery: `apiUrl` is required. Pass it via options or set the ' +\n '`STOREFRONT_API_URL` environment variable.',\n );\n }\n\n assertValidApiUrl(apiUrl, 'registerPreloadQuery');\n\n // Context headers merge last: a caller cannot contradict the context the app rendered. To request a\n // different locale, binding or sales channel, pass a different `context`.\n const headers = options.context\n ? { ...options.headers, ...buildStorefrontContextHeaders(options.context) }\n : options.headers;\n\n return registerApolloClient(\n () =>\n new ApolloClient({\n cache: new InMemoryCache(),\n link: new HttpLink({\n uri: apiUrl,\n ...(headers ? { headers } : {}),\n }),\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,SAAgB,qBAAqB,UAAuC,CAAC,GAAyB;CACpG,MAAM,SAAS,QAAQ,UAAU,QAAQ,IAAI;CAE7C,IAAI,CAAC,QACH,MAAM,IAAI,MACR,uHAEF;CAGF,kBAAkB,QAAQ,sBAAsB;CAIhD,MAAM,UAAU,QAAQ,UACpB;EAAE,GAAG,QAAQ;EAAS,GAAG,8BAA8B,QAAQ,OAAO;CAAE,IACxE,QAAQ;CAEZ,OAAO,2BAEH,IAAIA,eAAa;EACf,OAAO,IAAIC,gBAAc;EACzB,MAAM,IAAI,SAAS;GACjB,KAAK;GACL,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC/B,CAAC;CACH,CAAC,CACL;AACF"}
@@ -0,0 +1,68 @@
1
+ import { ContentTypeDefinition } from "../../core/dist/define-content-type.js";
2
+ import "../../core/dist/index.js";
3
+ import { FC, ReactNode } from "react";
4
+ //#region src/sdk/content/create-content-runtime.d.ts
5
+ export type ContentRuntimeConfig = {
6
+ account: string;
7
+ storeId: string;
8
+ /** Canonical per-component models, verbatim from the aggregated content catalog, keyed by id. */
9
+ contentTypes: Record<string, ContentTypeDefinition>;
10
+ };
11
+ /** The coordinates of one composite read. `locale` arrives per call, so one build serves many. */
12
+ export type ReadContentSlicesArgs = {
13
+ contentTypeId: string;
14
+ entryId: string;
15
+ locale: string;
16
+ /** `element.id → per-component model id` for every content-backed element in the scope. */
17
+ elements: Record<string, string>;
18
+ };
19
+ /**
20
+ * The scope's slices, keyed by `element.id`. A key is absent when its element must be omitted — a
21
+ * missing key, a shape violation, or a whole-entry failure.
22
+ *
23
+ * The value type is unchecked on purpose: the generated page forwards it to a component whose
24
+ * `$content` is `ContentValue<that component's model>`, a type that exists only in the component
25
+ * package, and an index signature cannot satisfy a model's required properties. Stated once here
26
+ * rather than cast at every emitted prop; the read below validates every value against its model.
27
+ */
28
+ export type ContentSlices = {
29
+ [elementId: string]: any;
30
+ };
31
+ export type ContentEntryBoundaryProps = {
32
+ /** This element's slice, read at the top of the scope. `undefined` omits the component. */
33
+ value: unknown;
34
+ children: ReactNode;
35
+ };
36
+ export type ContentRuntime = {
37
+ readContentSlices: (args: ReadContentSlicesArgs) => Promise<ContentSlices>;
38
+ ContentEntryBoundary: FC<ContentEntryBoundaryProps>;
39
+ };
40
+ /**
41
+ * Internal result taxonomy: a read either finds a validated composite blob or fails for a definite,
42
+ * loggable reason. A transient upstream failure resolves `found` from the last-good store below when
43
+ * that store holds the entry, and degrades to `unavailable` — omitting the affected components —
44
+ * only when it does not.
45
+ */
46
+ export type ContentEntryResult = {
47
+ status: 'found';
48
+ blob: Record<string, unknown>;
49
+ } | {
50
+ status: 'not-found';
51
+ } | {
52
+ status: 'unavailable';
53
+ reason: string;
54
+ } | {
55
+ status: 'invalid';
56
+ reason: string;
57
+ };
58
+ /**
59
+ * Creates the one server-side content read surface for a store: a `React.cache`-deduped
60
+ * `readContentSlices` the generated page or layout awaits once at the top, and the
61
+ * `ContentEntryBoundary` the compiler wraps around each content-backed element. One read per scope
62
+ * yields every element's `$content` value keyed by `element.id`, so a page issues at most two Data
63
+ * Plane reads (its own entry plus its layout's) regardless of content-backed component count. Draft
64
+ * Mode switches the same read to Control Plane's preview endpoint through a server-only credential.
65
+ */
66
+ export declare function createContentRuntime(config: ContentRuntimeConfig): ContentRuntime;
67
+ //#endregion
68
+ //# sourceMappingURL=create-content-runtime.d.ts.map