@shopify/hydrogen-react 0.0.0-next-022e862 → 0.0.0-next-c23a62a

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 (230) hide show
  1. package/dist/dev/CartProvider.js +20 -20
  2. package/dist/dev/CartProvider.js.map +1 -1
  3. package/dist/dev/Metafield.js +8 -2
  4. package/dist/dev/Metafield.js.map +1 -1
  5. package/dist/dev/Metafield.mjs +6 -0
  6. package/dist/dev/Metafield.mjs.map +1 -1
  7. package/dist/dev/ModelViewer.js +4 -4
  8. package/dist/dev/ModelViewer.js.map +1 -1
  9. package/dist/dev/ProductProvider.js +14 -14
  10. package/dist/dev/ProductProvider.js.map +1 -1
  11. package/dist/dev/ShopifyProvider.js +4 -4
  12. package/dist/dev/ShopifyProvider.js.map +1 -1
  13. package/dist/dev/Video.js +2 -2
  14. package/dist/dev/_virtual/index.js +5 -0
  15. package/dist/dev/_virtual/index.js.map +1 -0
  16. package/dist/dev/_virtual/index.mjs +5 -0
  17. package/dist/dev/_virtual/index.mjs.map +1 -0
  18. package/dist/dev/_virtual/index2.js +5 -0
  19. package/dist/dev/_virtual/index2.js.map +1 -0
  20. package/dist/dev/_virtual/index2.mjs +5 -0
  21. package/dist/dev/_virtual/index2.mjs.map +1 -0
  22. package/dist/dev/_virtual/use-sync-external-store-shim.development.js +5 -0
  23. package/dist/dev/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  24. package/dist/dev/_virtual/use-sync-external-store-shim.development.mjs +5 -0
  25. package/dist/dev/_virtual/use-sync-external-store-shim.development.mjs.map +1 -0
  26. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  27. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  28. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.mjs +5 -0
  29. package/dist/dev/_virtual/use-sync-external-store-shim.production.min.mjs.map +1 -0
  30. package/dist/dev/_virtual/with-selector.development.js +5 -0
  31. package/dist/dev/_virtual/with-selector.development.js.map +1 -0
  32. package/dist/dev/_virtual/with-selector.development.mjs +5 -0
  33. package/dist/dev/_virtual/with-selector.development.mjs.map +1 -0
  34. package/dist/dev/_virtual/with-selector.js +5 -0
  35. package/dist/dev/_virtual/with-selector.js.map +1 -0
  36. package/dist/dev/_virtual/with-selector.mjs +5 -0
  37. package/dist/dev/_virtual/with-selector.mjs.map +1 -0
  38. package/dist/dev/_virtual/with-selector.production.min.js +5 -0
  39. package/dist/dev/_virtual/with-selector.production.min.js.map +1 -0
  40. package/dist/dev/_virtual/with-selector.production.min.mjs +5 -0
  41. package/dist/dev/_virtual/with-selector.production.min.mjs.map +1 -0
  42. package/dist/dev/cart-hooks.js +4 -4
  43. package/dist/dev/cart-hooks.js.map +1 -1
  44. package/dist/dev/cart-hooks.mjs +3 -3
  45. package/dist/dev/cart-hooks.mjs.map +1 -1
  46. package/dist/dev/index.js +2 -0
  47. package/dist/dev/index.js.map +1 -1
  48. package/dist/dev/index.mjs +2 -0
  49. package/dist/dev/index.mjs.map +1 -1
  50. package/dist/dev/load-script.js +3 -3
  51. package/dist/dev/load-script.js.map +1 -1
  52. package/dist/dev/metafield-parser.js +105 -0
  53. package/dist/dev/metafield-parser.js.map +1 -0
  54. package/dist/dev/metafield-parser.mjs +105 -0
  55. package/dist/dev/metafield-parser.mjs.map +1 -0
  56. package/dist/dev/node_modules/@xstate/fsm/es/index.js +158 -0
  57. package/dist/dev/node_modules/@xstate/fsm/es/index.js.map +1 -0
  58. package/dist/dev/node_modules/@xstate/fsm/es/index.mjs +159 -0
  59. package/dist/dev/node_modules/@xstate/fsm/es/index.mjs.map +1 -0
  60. package/dist/dev/node_modules/@xstate/react/es/fsm.js +94 -0
  61. package/dist/dev/node_modules/@xstate/react/es/fsm.js.map +1 -0
  62. package/dist/dev/node_modules/@xstate/react/es/fsm.mjs +94 -0
  63. package/dist/dev/node_modules/@xstate/react/es/fsm.mjs.map +1 -0
  64. package/dist/dev/node_modules/@xstate/react/es/useConstant.js +30 -0
  65. package/dist/dev/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  66. package/dist/dev/node_modules/@xstate/react/es/useConstant.mjs +12 -0
  67. package/dist/dev/node_modules/@xstate/react/es/useConstant.mjs.map +1 -0
  68. package/dist/dev/node_modules/ts-expect/dist/index.js +13 -0
  69. package/dist/dev/node_modules/ts-expect/dist/index.js.map +1 -0
  70. package/dist/dev/node_modules/ts-expect/dist/index.mjs +15 -0
  71. package/dist/dev/node_modules/ts-expect/dist/index.mjs.map +1 -0
  72. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +5 -0
  73. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  74. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs +6 -0
  75. package/dist/dev/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs.map +1 -0
  76. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +107 -0
  77. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  78. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +105 -0
  79. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -0
  80. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +74 -0
  81. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  82. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs +72 -0
  83. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -0
  84. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +138 -0
  85. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  86. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +136 -0
  87. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -0
  88. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +60 -0
  89. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  90. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs +58 -0
  91. package/dist/dev/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -0
  92. package/dist/dev/node_modules/use-sync-external-store/shim/index.js +21 -0
  93. package/dist/dev/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  94. package/dist/dev/node_modules/use-sync-external-store/shim/index.mjs +21 -0
  95. package/dist/dev/node_modules/use-sync-external-store/shim/index.mjs.map +1 -0
  96. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js +12 -0
  97. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  98. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.mjs +11 -0
  99. package/dist/dev/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -0
  100. package/dist/dev/node_modules/worktop/cookie/index.js +27 -0
  101. package/dist/dev/node_modules/worktop/cookie/index.js.map +1 -0
  102. package/dist/dev/node_modules/worktop/cookie/index.mjs +27 -0
  103. package/dist/dev/node_modules/worktop/cookie/index.mjs.map +1 -0
  104. package/dist/dev/useCartAPIStateMachine.js +12 -12
  105. package/dist/dev/useCartAPIStateMachine.js.map +1 -1
  106. package/dist/dev/useCartAPIStateMachine.mjs +8 -8
  107. package/dist/dev/useCartAPIStateMachine.mjs.map +1 -1
  108. package/dist/dev/useCartActions.js +11 -11
  109. package/dist/dev/useCartActions.js.map +1 -1
  110. package/dist/dev/useMoney.js +5 -5
  111. package/dist/dev/useMoney.js.map +1 -1
  112. package/dist/prod/CartProvider.js +20 -20
  113. package/dist/prod/CartProvider.js.map +1 -1
  114. package/dist/prod/Metafield.js +2 -2
  115. package/dist/prod/Metafield.js.map +1 -1
  116. package/dist/prod/Metafield.mjs.map +1 -1
  117. package/dist/prod/ModelViewer.js +4 -4
  118. package/dist/prod/ModelViewer.js.map +1 -1
  119. package/dist/prod/ProductProvider.js +14 -14
  120. package/dist/prod/ProductProvider.js.map +1 -1
  121. package/dist/prod/ShopifyProvider.js +4 -4
  122. package/dist/prod/ShopifyProvider.js.map +1 -1
  123. package/dist/prod/Video.js +2 -2
  124. package/dist/prod/_virtual/index.js +5 -0
  125. package/dist/prod/_virtual/index.js.map +1 -0
  126. package/dist/prod/_virtual/index.mjs +5 -0
  127. package/dist/prod/_virtual/index.mjs.map +1 -0
  128. package/dist/prod/_virtual/index2.js +5 -0
  129. package/dist/prod/_virtual/index2.js.map +1 -0
  130. package/dist/prod/_virtual/index2.mjs +5 -0
  131. package/dist/prod/_virtual/index2.mjs.map +1 -0
  132. package/dist/prod/_virtual/use-sync-external-store-shim.development.js +5 -0
  133. package/dist/prod/_virtual/use-sync-external-store-shim.development.js.map +1 -0
  134. package/dist/prod/_virtual/use-sync-external-store-shim.development.mjs +5 -0
  135. package/dist/prod/_virtual/use-sync-external-store-shim.development.mjs.map +1 -0
  136. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js +5 -0
  137. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.js.map +1 -0
  138. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.mjs +5 -0
  139. package/dist/prod/_virtual/use-sync-external-store-shim.production.min.mjs.map +1 -0
  140. package/dist/prod/_virtual/with-selector.development.js +5 -0
  141. package/dist/prod/_virtual/with-selector.development.js.map +1 -0
  142. package/dist/prod/_virtual/with-selector.development.mjs +5 -0
  143. package/dist/prod/_virtual/with-selector.development.mjs.map +1 -0
  144. package/dist/prod/_virtual/with-selector.js +5 -0
  145. package/dist/prod/_virtual/with-selector.js.map +1 -0
  146. package/dist/prod/_virtual/with-selector.mjs +5 -0
  147. package/dist/prod/_virtual/with-selector.mjs.map +1 -0
  148. package/dist/prod/_virtual/with-selector.production.min.js +5 -0
  149. package/dist/prod/_virtual/with-selector.production.min.js.map +1 -0
  150. package/dist/prod/_virtual/with-selector.production.min.mjs +5 -0
  151. package/dist/prod/_virtual/with-selector.production.min.mjs.map +1 -0
  152. package/dist/prod/cart-hooks.js +4 -4
  153. package/dist/prod/cart-hooks.js.map +1 -1
  154. package/dist/prod/cart-hooks.mjs +3 -3
  155. package/dist/prod/cart-hooks.mjs.map +1 -1
  156. package/dist/prod/index.js +2 -0
  157. package/dist/prod/index.js.map +1 -1
  158. package/dist/prod/index.mjs +2 -0
  159. package/dist/prod/index.mjs.map +1 -1
  160. package/dist/prod/load-script.js +3 -3
  161. package/dist/prod/load-script.js.map +1 -1
  162. package/dist/prod/metafield-parser.js +116 -0
  163. package/dist/prod/metafield-parser.js.map +1 -0
  164. package/dist/prod/metafield-parser.mjs +116 -0
  165. package/dist/prod/metafield-parser.mjs.map +1 -0
  166. package/dist/prod/node_modules/@xstate/fsm/es/index.js +158 -0
  167. package/dist/prod/node_modules/@xstate/fsm/es/index.js.map +1 -0
  168. package/dist/prod/node_modules/@xstate/fsm/es/index.mjs +159 -0
  169. package/dist/prod/node_modules/@xstate/fsm/es/index.mjs.map +1 -0
  170. package/dist/prod/node_modules/@xstate/react/es/fsm.js +94 -0
  171. package/dist/prod/node_modules/@xstate/react/es/fsm.js.map +1 -0
  172. package/dist/prod/node_modules/@xstate/react/es/fsm.mjs +94 -0
  173. package/dist/prod/node_modules/@xstate/react/es/fsm.mjs.map +1 -0
  174. package/dist/prod/node_modules/@xstate/react/es/useConstant.js +30 -0
  175. package/dist/prod/node_modules/@xstate/react/es/useConstant.js.map +1 -0
  176. package/dist/prod/node_modules/@xstate/react/es/useConstant.mjs +12 -0
  177. package/dist/prod/node_modules/@xstate/react/es/useConstant.mjs.map +1 -0
  178. package/dist/prod/node_modules/ts-expect/dist/index.js +13 -0
  179. package/dist/prod/node_modules/ts-expect/dist/index.js.map +1 -0
  180. package/dist/prod/node_modules/ts-expect/dist/index.mjs +15 -0
  181. package/dist/prod/node_modules/ts-expect/dist/index.mjs.map +1 -0
  182. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js +5 -0
  183. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.js.map +1 -0
  184. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs +6 -0
  185. package/dist/prod/node_modules/use-isomorphic-layout-effect/dist/use-isomorphic-layout-effect.browser.esm.mjs.map +1 -0
  186. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +107 -0
  187. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js.map +1 -0
  188. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs +105 -0
  189. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.mjs.map +1 -0
  190. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js +74 -0
  191. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.js.map +1 -0
  192. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs +72 -0
  193. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.min.mjs.map +1 -0
  194. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +138 -0
  195. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  196. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs +136 -0
  197. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.mjs.map +1 -0
  198. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js +60 -0
  199. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.js.map +1 -0
  200. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs +58 -0
  201. package/dist/prod/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.min.mjs.map +1 -0
  202. package/dist/prod/node_modules/use-sync-external-store/shim/index.js +21 -0
  203. package/dist/prod/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  204. package/dist/prod/node_modules/use-sync-external-store/shim/index.mjs +21 -0
  205. package/dist/prod/node_modules/use-sync-external-store/shim/index.mjs.map +1 -0
  206. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js +12 -0
  207. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.js.map +1 -0
  208. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.mjs +11 -0
  209. package/dist/prod/node_modules/use-sync-external-store/shim/with-selector.mjs.map +1 -0
  210. package/dist/prod/node_modules/worktop/cookie/index.js +27 -0
  211. package/dist/prod/node_modules/worktop/cookie/index.js.map +1 -0
  212. package/dist/prod/node_modules/worktop/cookie/index.mjs +27 -0
  213. package/dist/prod/node_modules/worktop/cookie/index.mjs.map +1 -0
  214. package/dist/prod/useCartAPIStateMachine.js +12 -12
  215. package/dist/prod/useCartAPIStateMachine.js.map +1 -1
  216. package/dist/prod/useCartAPIStateMachine.mjs +8 -8
  217. package/dist/prod/useCartAPIStateMachine.mjs.map +1 -1
  218. package/dist/prod/useCartActions.js +11 -11
  219. package/dist/prod/useCartActions.js.map +1 -1
  220. package/dist/prod/useMoney.js +5 -5
  221. package/dist/prod/useMoney.js.map +1 -1
  222. package/dist/types/Metafield.d.ts +3 -0
  223. package/dist/types/index.d.cts +1 -0
  224. package/dist/types/index.d.ts +1 -0
  225. package/dist/types/metafield-parser.d.ts +222 -0
  226. package/dist/umd/hydrogen-react.dev.js +114 -0
  227. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  228. package/dist/umd/hydrogen-react.prod.js +17 -17
  229. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  230. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cart-hooks.mjs","sources":["../../src/cart-hooks.tsx"],"sourcesContent":["import {useState, useCallback} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {CartInput, Cart as CartType} from './storefront-api-types.js';\nimport {CartCreate, defaultCartFragment} from './cart-queries.js';\nimport {Cart} from './cart-types.js';\nimport {\n SHOPIFY_STOREFRONT_ID_HEADER,\n STOREFRONT_API_PUBLIC_TOKEN_HEADER,\n SHOPIFY_STOREFRONT_Y_HEADER,\n SHOPIFY_STOREFRONT_S_HEADER,\n SHOPIFY_Y,\n SHOPIFY_S,\n} from './cart-constants.js';\nimport {parse} from 'worktop/cookie';\nimport type {StorefrontApiResponseOkPartial} from './storefront-api-response.types.js';\n\nexport function useCartFetch() {\n const {storeDomain, storefrontApiVersion, storefrontToken, storefrontId} =\n useShop();\n\n return useCallback(\n <ReturnDataGeneric,>({\n query,\n variables,\n }: {\n query: string;\n variables: Record<string, unknown>;\n }): Promise<StorefrontApiResponseOkPartial<ReturnDataGeneric>> => {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-SDK-Variant': 'hydrogen',\n 'X-SDK-Version': storefrontApiVersion,\n [STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken,\n };\n\n if (storefrontId) {\n headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;\n }\n\n // Find Shopify cookies\n const cookieData = parse(document.cookie);\n if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {\n headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];\n headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];\n }\n\n return fetch(\n `https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n query: query.toString(),\n variables,\n }),\n }\n )\n .then((res) => res.json())\n .catch((error) => {\n return {\n data: undefined,\n errors: error.toString(),\n };\n });\n },\n [storeDomain, storefrontApiVersion, storefrontToken, storefrontId]\n );\n}\n\nexport function useInstantCheckout() {\n const [cart, updateCart] = useState<Cart | undefined>();\n const [checkoutUrl, updateCheckoutUrl] = useState<Cart['checkoutUrl']>();\n const [error, updateError] = useState<string | undefined>();\n\n const fetch = useCartFetch();\n\n const createInstantCheckout = useCallback(\n async (cartInput: CartInput) => {\n const {data, errors} = await fetch<{\n cartCreate: {cart: CartType};\n }>({\n query: CartCreate(defaultCartFragment),\n variables: {\n input: cartInput,\n },\n });\n\n if (errors) {\n updateError(errors.toString());\n updateCart(undefined);\n updateCheckoutUrl(undefined);\n }\n\n if (data?.cartCreate?.cart) {\n const dataCart = data.cartCreate.cart;\n updateCart({\n ...dataCart,\n lines: flattenConnection(dataCart.lines),\n note: dataCart.note ?? undefined,\n });\n updateCheckoutUrl(dataCart.checkoutUrl);\n }\n },\n [fetch]\n );\n\n return {cart, checkoutUrl, error, createInstantCheckout};\n}\n"],"names":["useCartFetch","storeDomain","storefrontApiVersion","storefrontToken","storefrontId","useShop","useCallback","query","variables","headers","STOREFRONT_API_PUBLIC_TOKEN_HEADER","SHOPIFY_STOREFRONT_ID_HEADER","cookieData","parse","document","cookie","SHOPIFY_Y","SHOPIFY_S","SHOPIFY_STOREFRONT_Y_HEADER","SHOPIFY_STOREFRONT_S_HEADER","fetch","method","body","JSON","stringify","toString","then","res","json","catch","error","data","undefined","errors"],"mappings":";;;;AAiBO,SAASA,eAAe;AACvB,QAAA;AAAA,IAACC;AAAAA,IAAaC;AAAAA,IAAsBC;AAAAA,IAAiBC;AAAAA,MACzDC,QADF;AAGA,SAAOC,YACL,CAAqB;AAAA,IACnBC;AAAAA,IACAC;AAAAA,EAAAA,MAIgE;AAChE,UAAMC,UAAkC;AAAA,MACtC,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,iBAAiBP;AAAAA,MACjB,CAACQ,qCAAqCP;AAAAA,IAAAA;AAGxC,QAAIC,cAAc;AAChBK,cAAQE,gCAAgCP;AAAAA,IACzC;AAGKQ,UAAAA,aAAaC,MAAMC,SAASC,MAAV;AACpBH,QAAAA,WAAWI,cAAcJ,WAAWK,YAAY;AAClDR,cAAQS,+BAA+BN,WAAWI;AAClDP,cAAQU,+BAA+BP,WAAWK;AAAAA,IACnD;AAEMG,WAAAA,MACJ,WAAUnB,mBAAmBC,qCAC9B;AAAA,MACEmB,QAAQ;AAAA,MACRZ;AAAAA,MACAa,MAAMC,KAAKC,UAAU;AAAA,QACnBjB,OAAOA,MAAMkB,SADM;AAAA,QAEnBjB;AAAAA,MAAAA,CAFI;AAAA,IAAA,CALE,EAWTkB,KAAMC,CAAAA,QAAQA,IAAIC,MAXd,EAYJC,MAAOC,CAAU,UAAA;AACT,aAAA;AAAA,QACLC,MAAMC;AAAAA,QACNC,QAAQH,MAAML,SAAN;AAAA,MAAA;AAAA,IAFH,CAbJ;AAAA,KAmBT,CAACxB,aAAaC,sBAAsBC,iBAAiBC,YAArD,CA7CgB;AA+CnB;"}
1
+ {"version":3,"file":"cart-hooks.mjs","sources":["../../src/cart-hooks.tsx"],"sourcesContent":["import {useState, useCallback} from 'react';\nimport {useShop} from './ShopifyProvider.js';\nimport {flattenConnection} from './flatten-connection.js';\nimport {CartInput, Cart as CartType} from './storefront-api-types.js';\nimport {CartCreate, defaultCartFragment} from './cart-queries.js';\nimport {Cart} from './cart-types.js';\nimport {\n SHOPIFY_STOREFRONT_ID_HEADER,\n STOREFRONT_API_PUBLIC_TOKEN_HEADER,\n SHOPIFY_STOREFRONT_Y_HEADER,\n SHOPIFY_STOREFRONT_S_HEADER,\n SHOPIFY_Y,\n SHOPIFY_S,\n} from './cart-constants.js';\nimport {parse} from 'worktop/cookie';\nimport type {StorefrontApiResponseOkPartial} from './storefront-api-response.types.js';\n\nexport function useCartFetch() {\n const {storeDomain, storefrontApiVersion, storefrontToken, storefrontId} =\n useShop();\n\n return useCallback(\n <ReturnDataGeneric,>({\n query,\n variables,\n }: {\n query: string;\n variables: Record<string, unknown>;\n }): Promise<StorefrontApiResponseOkPartial<ReturnDataGeneric>> => {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-SDK-Variant': 'hydrogen',\n 'X-SDK-Version': storefrontApiVersion,\n [STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken,\n };\n\n if (storefrontId) {\n headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;\n }\n\n // Find Shopify cookies\n const cookieData = parse(document.cookie);\n if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {\n headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];\n headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];\n }\n\n return fetch(\n `https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`,\n {\n method: 'POST',\n headers,\n body: JSON.stringify({\n query: query.toString(),\n variables,\n }),\n }\n )\n .then((res) => res.json())\n .catch((error) => {\n return {\n data: undefined,\n errors: error.toString(),\n };\n });\n },\n [storeDomain, storefrontApiVersion, storefrontToken, storefrontId]\n );\n}\n\nexport function useInstantCheckout() {\n const [cart, updateCart] = useState<Cart | undefined>();\n const [checkoutUrl, updateCheckoutUrl] = useState<Cart['checkoutUrl']>();\n const [error, updateError] = useState<string | undefined>();\n\n const fetch = useCartFetch();\n\n const createInstantCheckout = useCallback(\n async (cartInput: CartInput) => {\n const {data, errors} = await fetch<{\n cartCreate: {cart: CartType};\n }>({\n query: CartCreate(defaultCartFragment),\n variables: {\n input: cartInput,\n },\n });\n\n if (errors) {\n updateError(errors.toString());\n updateCart(undefined);\n updateCheckoutUrl(undefined);\n }\n\n if (data?.cartCreate?.cart) {\n const dataCart = data.cartCreate.cart;\n updateCart({\n ...dataCart,\n lines: flattenConnection(dataCart.lines),\n note: dataCart.note ?? undefined,\n });\n updateCheckoutUrl(dataCart.checkoutUrl);\n }\n },\n [fetch]\n );\n\n return {cart, checkoutUrl, error, createInstantCheckout};\n}\n"],"names":["useCartFetch","storeDomain","storefrontApiVersion","storefrontToken","storefrontId","useShop","useCallback","query","variables","headers","STOREFRONT_API_PUBLIC_TOKEN_HEADER","SHOPIFY_STOREFRONT_ID_HEADER","cookieData","parse","document","cookie","SHOPIFY_Y","SHOPIFY_S","SHOPIFY_STOREFRONT_Y_HEADER","SHOPIFY_STOREFRONT_S_HEADER","fetch","method","body","JSON","stringify","toString","then","res","json","catch","error","data","undefined","errors"],"mappings":";;;;AAiBO,SAASA,eAAe;AACvB,QAAA;AAAA,IAACC;AAAAA,IAAaC;AAAAA,IAAsBC;AAAAA,IAAiBC;AAAAA,MACzDC,QADF;AAGA,SAAOC,YACL,CAAqB;AAAA,IACnBC;AAAAA,IACAC;AAAAA,EAAAA,MAIgE;AAChE,UAAMC,UAAkC;AAAA,MACtC,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,iBAAiBP;AAAAA,MACjB,CAACQ,qCAAqCP;AAAAA,IAAAA;AAGxC,QAAIC,cAAc;AAChBK,cAAQE,gCAAgCP;AAAAA,IACzC;AAGKQ,UAAAA,aAAaC,EAAMC,SAASC,MAAV;AACpBH,QAAAA,WAAWI,cAAcJ,WAAWK,YAAY;AAClDR,cAAQS,+BAA+BN,WAAWI;AAClDP,cAAQU,+BAA+BP,WAAWK;AAAAA,IACnD;AAEMG,WAAAA,MACJ,WAAUnB,mBAAmBC,qCAC9B;AAAA,MACEmB,QAAQ;AAAA,MACRZ;AAAAA,MACAa,MAAMC,KAAKC,UAAU;AAAA,QACnBjB,OAAOA,MAAMkB,SADM;AAAA,QAEnBjB;AAAAA,MAAAA,CAFI;AAAA,IAAA,CALE,EAWTkB,KAAMC,CAAAA,QAAQA,IAAIC,MAXd,EAYJC,MAAOC,CAAU,UAAA;AACT,aAAA;AAAA,QACLC,MAAMC;AAAAA,QACNC,QAAQH,MAAML,SAAN;AAAA,MAAA;AAAA,IAFH,CAbJ;AAAA,KAmBT,CAACxB,aAAaC,sBAAsBC,iBAAiBC,YAArD,CA7CgB;AA+CnB;"}
package/dist/dev/index.js CHANGED
@@ -5,6 +5,7 @@ const ExternalVideo = require("./ExternalVideo.js");
5
5
  const flattenConnection = require("./flatten-connection.js");
6
6
  const Image = require("./Image.js");
7
7
  const MediaFile = require("./MediaFile.js");
8
+ const metafieldParser = require("./metafield-parser.js");
8
9
  const Metafield = require("./Metafield.js");
9
10
  const ModelViewer = require("./ModelViewer.js");
10
11
  const Money = require("./Money.js");
@@ -21,6 +22,7 @@ exports.ExternalVideo = ExternalVideo.ExternalVideo;
21
22
  exports.flattenConnection = flattenConnection.flattenConnection;
22
23
  exports.Image = Image.Image;
23
24
  exports.MediaFile = MediaFile.MediaFile;
25
+ exports.metafieldParser = metafieldParser.metafieldParser;
24
26
  exports.Metafield = Metafield.Metafield;
25
27
  exports.parseMetafield = Metafield.parseMetafield;
26
28
  exports.parseMetafieldValue = Metafield.parseMetafieldValue;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -3,6 +3,7 @@ import { ExternalVideo } from "./ExternalVideo.mjs";
3
3
  import { flattenConnection } from "./flatten-connection.mjs";
4
4
  import { Image } from "./Image.mjs";
5
5
  import { MediaFile } from "./MediaFile.mjs";
6
+ import { metafieldParser } from "./metafield-parser.mjs";
6
7
  import { Metafield, parseMetafield, parseMetafieldValue } from "./Metafield.mjs";
7
8
  import { ModelViewer } from "./ModelViewer.mjs";
8
9
  import { Money } from "./Money.mjs";
@@ -28,6 +29,7 @@ export {
28
29
  Video,
29
30
  createStorefrontClient,
30
31
  flattenConnection,
32
+ metafieldParser,
31
33
  parseMetafield,
32
34
  parseMetafieldValue,
33
35
  useCart,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const react = require("react");
3
+ const require$$0 = require("react");
4
4
  const SCRIPTS_LOADED = {};
5
5
  function loadScript(src, options) {
6
6
  const isScriptLoaded = SCRIPTS_LOADED[src];
@@ -31,9 +31,9 @@ function loadScript(src, options) {
31
31
  return promise;
32
32
  }
33
33
  function useLoadScript(url, options) {
34
- const [status, setStatus] = react.useState("loading");
34
+ const [status, setStatus] = require$$0.useState("loading");
35
35
  const stringifiedOptions = JSON.stringify(options);
36
- react.useEffect(() => {
36
+ require$$0.useEffect(() => {
37
37
  async function loadScriptWrapper() {
38
38
  try {
39
39
  setStatus("loading");
@@ -1 +1 @@
1
- {"version":3,"file":"load-script.js","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\nexport function loadScript(\n src: string,\n options?: {module?: boolean; in?: 'head' | 'body'}\n): Promise<boolean> {\n const isScriptLoaded: Promise<boolean> = SCRIPTS_LOADED[src];\n\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = () => {\n resolve(true);\n };\n script.onerror = () => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1]\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n const stringifiedOptions = JSON.stringify(options);\n\n useEffect(() => {\n async function loadScriptWrapper() {\n try {\n setStatus('loading');\n await loadScript(url, options);\n setStatus('done');\n } catch (error) {\n setStatus('error');\n }\n }\n\n loadScriptWrapper();\n }, [url, stringifiedOptions, options]);\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":["SCRIPTS_LOADED","loadScript","src","options","isScriptLoaded","promise","Promise","resolve","reject","script","document","createElement","module","type","onload","onerror","in","head","appendChild","body","useLoadScript","url","status","setStatus","useState","stringifiedOptions","JSON","stringify","useEffect","loadScriptWrapper","error"],"mappings":";;;AAEA,MAAMA,iBAAmD,CAAA;AAEzCC,SAAAA,WACdC,KACAC,SACkB;AAClB,QAAMC,iBAAmCJ,eAAeE;AAExD,MAAIE,gBAAgB;AACXA,WAAAA;AAAAA,EACR;AAED,QAAMC,UAAU,IAAIC,QAAiB,CAACC,SAASC,WAAW;AAClDC,UAAAA,SAASC,SAASC,cAAc,QAAvB;AACf,QAAIR,mCAASS,QAAQ;AACnBH,aAAOI,OAAO;AAAA,IAAA,OACT;AACLJ,aAAOI,OAAO;AAAA,IACf;AACDJ,WAAOP,MAAMA;AACbO,WAAOK,SAAS,MAAM;AACpBP,cAAQ,IAAD;AAAA,IAAA;AAETE,WAAOM,UAAU,MAAM;AACrBP,aAAO,KAAD;AAAA,IAAA;AAEJL,SAAAA,mCAASa,QAAO,QAAQ;AACjBC,eAAAA,KAAKC,YAAYT,MAA1B;AAAA,IAAA,OACK;AACIU,eAAAA,KAAKD,YAAYT,MAA1B;AAAA,IACD;AAAA,EAAA,CAlBa;AAqBhBT,iBAAeE,OAAOG;AAEfA,SAAAA;AACR;AAOee,SAAAA,cACdC,KACAlB,SACa;AACb,QAAM,CAACmB,QAAQC,SAAT,IAAsBC,eAAsB,SAAd;AAC9BC,QAAAA,qBAAqBC,KAAKC,UAAUxB,OAAf;AAE3ByB,QAAAA,UAAU,MAAM;AACd,mBAAeC,oBAAoB;AAC7B,UAAA;AACFN,kBAAU,SAAD;AACHtB,cAAAA,WAAWoB,KAAKlB,OAAN;AAChBoB,kBAAU,MAAD;AAAA,eACFO;AACPP,kBAAU,OAAD;AAAA,MACV;AAAA,IACF;AAEgB;EAChB,GAAA,CAACF,KAAKI,oBAAoBtB,OAA1B,CAZM;AAcFmB,SAAAA;AACR;;;"}
1
+ {"version":3,"file":"load-script.js","sources":["../../src/load-script.tsx"],"sourcesContent":["import {useState, useEffect} from 'react';\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\nexport function loadScript(\n src: string,\n options?: {module?: boolean; in?: 'head' | 'body'}\n): Promise<boolean> {\n const isScriptLoaded: Promise<boolean> = SCRIPTS_LOADED[src];\n\n if (isScriptLoaded) {\n return isScriptLoaded;\n }\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement('script');\n if (options?.module) {\n script.type = 'module';\n } else {\n script.type = 'text/javascript';\n }\n script.src = src;\n script.onload = () => {\n resolve(true);\n };\n script.onerror = () => {\n reject(false);\n };\n if (options?.in === 'head') {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n\n return promise;\n}\n\ntype LoadScriptParams = Parameters<typeof loadScript>;\n\n/**\n * The `useLoadScript` hook loads an external script tag in the browser. It allows React components to lazy-load large third-party dependencies.\n */\nexport function useLoadScript(\n url: LoadScriptParams[0],\n options?: LoadScriptParams[1]\n): ScriptState {\n const [status, setStatus] = useState<ScriptState>('loading');\n const stringifiedOptions = JSON.stringify(options);\n\n useEffect(() => {\n async function loadScriptWrapper() {\n try {\n setStatus('loading');\n await loadScript(url, options);\n setStatus('done');\n } catch (error) {\n setStatus('error');\n }\n }\n\n loadScriptWrapper();\n }, [url, stringifiedOptions, options]);\n\n return status;\n}\n\ntype ScriptState = 'loading' | 'done' | 'error';\n"],"names":["SCRIPTS_LOADED","loadScript","src","options","isScriptLoaded","promise","Promise","resolve","reject","script","document","createElement","module","type","onload","onerror","in","head","appendChild","body","useLoadScript","url","status","setStatus","useState","stringifiedOptions","JSON","stringify","useEffect","loadScriptWrapper","error"],"mappings":";;;AAEA,MAAMA,iBAAmD,CAAA;AAEzCC,SAAAA,WACdC,KACAC,SACkB;AAClB,QAAMC,iBAAmCJ,eAAeE;AAExD,MAAIE,gBAAgB;AACXA,WAAAA;AAAAA,EACR;AAED,QAAMC,UAAU,IAAIC,QAAiB,CAACC,SAASC,WAAW;AAClDC,UAAAA,SAASC,SAASC,cAAc,QAAvB;AACf,QAAIR,mCAASS,QAAQ;AACnBH,aAAOI,OAAO;AAAA,IAAA,OACT;AACLJ,aAAOI,OAAO;AAAA,IACf;AACDJ,WAAOP,MAAMA;AACbO,WAAOK,SAAS,MAAM;AACpBP,cAAQ,IAAD;AAAA,IAAA;AAETE,WAAOM,UAAU,MAAM;AACrBP,aAAO,KAAD;AAAA,IAAA;AAEJL,SAAAA,mCAASa,QAAO,QAAQ;AACjBC,eAAAA,KAAKC,YAAYT,MAA1B;AAAA,IAAA,OACK;AACIU,eAAAA,KAAKD,YAAYT,MAA1B;AAAA,IACD;AAAA,EAAA,CAlBa;AAqBhBT,iBAAeE,OAAOG;AAEfA,SAAAA;AACR;AAOee,SAAAA,cACdC,KACAlB,SACa;AACb,QAAM,CAACmB,QAAQC,SAAT,IAAsBC,oBAAsB,SAAd;AAC9BC,QAAAA,qBAAqBC,KAAKC,UAAUxB,OAAf;AAE3ByB,aAAAA,UAAU,MAAM;AACd,mBAAeC,oBAAoB;AAC7B,UAAA;AACFN,kBAAU,SAAD;AACHtB,cAAAA,WAAWoB,KAAKlB,OAAN;AAChBoB,kBAAU,MAAD;AAAA,eACFO;AACPP,kBAAU,OAAD;AAAA,MACV;AAAA,IACF;AAEgB;EAChB,GAAA,CAACF,KAAKI,oBAAoBtB,OAA1B,CAZM;AAcFmB,SAAAA;AACR;;;"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const Metafield = require("./Metafield.js");
4
+ const index = require("./node_modules/ts-expect/dist/index.js");
5
+ const flattenConnection = require("./flatten-connection.js");
6
+ function metafieldParser(metafield) {
7
+ var _a, _b, _c, _d;
8
+ if (!metafield.type) {
9
+ const noTypeError = `metafieldParser(): The 'type' field is required in order to parse the Metafield.`;
10
+ {
11
+ throw new Error(noTypeError);
12
+ }
13
+ }
14
+ switch (metafield.type) {
15
+ case "boolean":
16
+ return {
17
+ ...metafield,
18
+ parsedValue: metafield.value === "true"
19
+ };
20
+ case "collection_reference":
21
+ case "file_reference":
22
+ case "page_reference":
23
+ case "product_reference":
24
+ case "variant_reference":
25
+ return {
26
+ ...metafield,
27
+ parsedValue: metafield.reference
28
+ };
29
+ case "color":
30
+ case "multi_line_text_field":
31
+ case "single_line_text_field":
32
+ case "url":
33
+ return {
34
+ ...metafield,
35
+ parsedValue: metafield.value
36
+ };
37
+ case "dimension":
38
+ case "money":
39
+ case "json":
40
+ case "rating":
41
+ case "volume":
42
+ case "weight":
43
+ case "list.color":
44
+ case "list.dimension":
45
+ case "list.number_integer":
46
+ case "list.number_decimal":
47
+ case "list.rating":
48
+ case "list.single_line_text_field":
49
+ case "list.url":
50
+ case "list.volume":
51
+ case "list.weight": {
52
+ let parsedValue = null;
53
+ try {
54
+ parsedValue = Metafield.parseJSON((_a = metafield.value) != null ? _a : "");
55
+ } catch (err) {
56
+ const parseError = `metafieldParser(): attempted to JSON.parse the 'metafield.value' property, but failed.`;
57
+ {
58
+ throw new Error(parseError);
59
+ }
60
+ }
61
+ return {
62
+ ...metafield,
63
+ parsedValue
64
+ };
65
+ }
66
+ case "date":
67
+ case "date_time":
68
+ return {
69
+ ...metafield,
70
+ parsedValue: new Date((_b = metafield.value) != null ? _b : "")
71
+ };
72
+ case "list.date":
73
+ case "list.date_time": {
74
+ const jsonParseValue = Metafield.parseJSON((_c = metafield == null ? void 0 : metafield.value) != null ? _c : "");
75
+ return {
76
+ ...metafield,
77
+ parsedValue: jsonParseValue.map((dateString) => new Date(dateString))
78
+ };
79
+ }
80
+ case "number_decimal":
81
+ case "number_integer":
82
+ return {
83
+ ...metafield,
84
+ parsedValue: Number(metafield.value)
85
+ };
86
+ case "list.collection_reference":
87
+ case "list.file_reference":
88
+ case "list.page_reference":
89
+ case "list.product_reference":
90
+ case "list.variant_reference":
91
+ return {
92
+ ...metafield,
93
+ parsedValue: flattenConnection.flattenConnection((_d = metafield.references) != null ? _d : void 0)
94
+ };
95
+ default: {
96
+ const typeNotFoundError = `metafieldParser(): the 'metafield.type' you passed in is not supported. Your type: "${metafield.type}". If you believe this is an error, please open an issue on GitHub.`;
97
+ {
98
+ throw new Error(typeNotFoundError);
99
+ }
100
+ }
101
+ }
102
+ }
103
+ index.expectType(true);
104
+ exports.metafieldParser = metafieldParser;
105
+ //# sourceMappingURL=metafield-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metafield-parser.js","sources":["../../src/metafield-parser.ts"],"sourcesContent":["import type {\n Collection,\n GenericFile,\n Metafield as MetafieldBaseType,\n MoneyV2,\n Page,\n Product,\n ProductVariant,\n} from './storefront-api-types.js';\nimport type {PartialDeep, Simplify} from 'type-fest';\nimport {parseJSON} from './Metafield.js';\nimport {TypeEqual, expectType} from 'ts-expect';\nimport {flattenConnection} from './flatten-connection.js';\n\n/**\n * A temporary function that will be renamed to `parseMetafield()` in a future release.\n *\n * A function that uses `metafield.type` to parse the Metafield's `value` or `reference` or `references` (depending on the `type`) and put it in `metafield.parsedValue`\n *\n * TypeScript developers can use the type `ParsedMetafields` from this package to get the returned object's type correct. For example:\n *\n * ```\n * metafieldParser<ParsedMetafields['boolean']>({type: 'boolean', value: 'false'}\n * ```\n */\nexport function metafieldParser<ReturnGeneric>(\n metafield: PartialDeep<MetafieldBaseType, {recurseIntoArrays: true}>\n): ReturnGeneric {\n if (!metafield.type) {\n const noTypeError = `metafieldParser(): The 'type' field is required in order to parse the Metafield.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noTypeError);\n } else {\n console.error(`${noTypeError} Returning 'parsedValue' of 'null'`);\n return {\n ...metafield,\n parsedValue: null,\n } as ReturnGeneric;\n }\n }\n\n switch (metafield.type) {\n case 'boolean':\n return {\n ...metafield,\n parsedValue: metafield.value === 'true',\n } as ReturnGeneric;\n\n case 'collection_reference':\n case 'file_reference':\n case 'page_reference':\n case 'product_reference':\n case 'variant_reference':\n return {\n ...metafield,\n parsedValue: metafield.reference,\n } as ReturnGeneric;\n\n case 'color':\n case 'multi_line_text_field':\n case 'single_line_text_field':\n case 'url':\n return {\n ...metafield,\n parsedValue: metafield.value,\n } as ReturnGeneric;\n\n // TODO: 'money' should probably be parsed even further to like `useMoney()`, but that logic needs to be extracted first so it's not a hook\n case 'dimension':\n case 'money':\n case 'json':\n case 'rating':\n case 'volume':\n case 'weight':\n case 'list.color':\n case 'list.dimension':\n case 'list.number_integer':\n case 'list.number_decimal':\n case 'list.rating':\n case 'list.single_line_text_field':\n case 'list.url':\n case 'list.volume':\n case 'list.weight': {\n let parsedValue = null;\n try {\n parsedValue = parseJSON(metafield.value ?? '');\n } catch (err) {\n const parseError = `metafieldParser(): attempted to JSON.parse the 'metafield.value' property, but failed.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(parseError);\n } else {\n console.error(`${parseError} Returning 'null' for 'parsedValue'`);\n }\n parsedValue = null;\n }\n return {\n ...metafield,\n parsedValue,\n } as ReturnGeneric;\n }\n\n case 'date':\n case 'date_time':\n return {\n ...metafield,\n parsedValue: new Date(metafield.value ?? ''),\n } as ReturnGeneric;\n\n case 'list.date':\n case 'list.date_time': {\n const jsonParseValue = parseJSON(metafield?.value ?? '') as string[];\n return {\n ...metafield,\n parsedValue: jsonParseValue.map((dateString) => new Date(dateString)),\n } as ReturnGeneric;\n }\n\n case 'number_decimal':\n case 'number_integer':\n return {\n ...metafield,\n parsedValue: Number(metafield.value),\n } as ReturnGeneric;\n\n case 'list.collection_reference':\n case 'list.file_reference':\n case 'list.page_reference':\n case 'list.product_reference':\n case 'list.variant_reference':\n return {\n ...metafield,\n parsedValue: flattenConnection(metafield.references ?? undefined),\n } as ReturnGeneric;\n\n default: {\n const typeNotFoundError = `metafieldParser(): the 'metafield.type' you passed in is not supported. Your type: \"${metafield.type}\". If you believe this is an error, please open an issue on GitHub.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(typeNotFoundError);\n } else {\n console.error(\n `${typeNotFoundError} Returning 'parsedValue' of 'null'`\n );\n return {\n ...metafield,\n parsedValue: null,\n } as ReturnGeneric;\n }\n }\n }\n}\n\n// taken from https://shopify.dev/apps/metafields/types\nexport const allMetafieldTypesArray = [\n 'boolean',\n 'collection_reference',\n 'color',\n 'date',\n 'date_time',\n 'dimension',\n 'file_reference',\n 'json',\n 'money',\n 'multi_line_text_field',\n 'number_decimal',\n 'number_integer',\n 'page_reference',\n 'product_reference',\n 'rating',\n 'single_line_text_field',\n 'url',\n 'variant_reference',\n 'volume',\n 'weight',\n // list metafields\n 'list.collection_reference',\n 'list.color',\n 'list.date',\n 'list.date_time',\n 'list.dimension',\n 'list.file_reference',\n 'list.number_integer',\n 'list.number_decimal',\n 'list.page_reference',\n 'list.product_reference',\n 'list.rating',\n 'list.single_line_text_field',\n 'list.url',\n 'list.variant_reference',\n 'list.volume',\n 'list.weight',\n] as const;\n\n/** A union of all the supported `metafield.type`s */\nexport type MetafieldTypeTypes = typeof allMetafieldTypesArray[number];\n\n/**\n * A mapping of a Metafield's `type` to the TypeScript type that is returned from `metafieldParser()`\n * For example, when using `metafieldParser()`, the type will be correctly returned when used like the following:\n *\n * ```\n * const parsedMetafield = metafieldParser<ParsedMetafields['boolean']>(metafield);`\n * ```\n * `parsedMetafield.parsedValue`'s type is now `boolean`\n */\nexport type ParsedMetafields<ExtraTypeGeneric = void> = {\n /** A Metafield that's been parsed, with a `parsedValue` of `boolean` */\n boolean: Simplify<BooleanParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Collection` object (as defined by the Storefront API) */\n collection_reference: Simplify<CollectionParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n color: Simplify<ColorParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Date` */\n date: Simplify<DatesParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Date` */\n date_time: Simplify<DatesParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n dimension: Simplify<MeasurementParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `GenericFile` object (as defined by the Storefront API) */\n file_reference: Simplify<FileRefParsedMetafield>;\n /**\n * A Metafield that's been parsed, with a `parsedValue` of type `unknown`, unless you pass in the type as a generic. For example:\n *\n * ```\n * ParsedMetafields<MyJsonType>['json']\n * ```\n */\n json: Simplify<JsonParsedMetafield<ExtraTypeGeneric>>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Money` */\n money: Simplify<MoneyParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n multi_line_text_field: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `number` */\n number_decimal: Simplify<NumberParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `number` */\n number_integer: Simplify<NumberParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Page` object (as defined by the Storefront API) */\n page_reference: Simplify<PageParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Product` object (as defined by the Storefront API) */\n product_reference: Simplify<ProductParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Rating` */\n rating: Simplify<RatingParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n single_line_text_field: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n url: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `ProductVariant` object (as defined by the Storefront API) */\n variant_reference: Simplify<VariantParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n volume: Simplify<MeasurementParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n weight: Simplify<MeasurementParsedMetafield>;\n // list metafields\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Collection` objects (as defined by the Storefront API) */\n 'list.collection_reference': Simplify<CollectionListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.color': Simplify<ColorListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of Date objects */\n 'list.date': Simplify<DatesListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of Date objects */\n 'list.date_time': Simplify<DatesListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement` objects */\n 'list.dimension': Simplify<MeasurementListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `GenericFile` objects (as defined by the Storefront API) */\n 'list.file_reference': Simplify<FileListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of numbers */\n 'list.number_integer': Simplify<NumberListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of numbers */\n 'list.number_decimal': Simplify<NumberListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Page` objects (as defined by the Storefront API) */\n 'list.page_reference': Simplify<PageListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Product` objects (as defined by the Storefront API) */\n 'list.product_reference': Simplify<ProductListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Rating`s */\n 'list.rating': Simplify<RatingListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.single_line_text_field': Simplify<TextListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.url': Simplify<TextListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `ProductVariant` objects (as defined by the Storefront API) */\n 'list.variant_reference': Simplify<VariantListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement`s */\n 'list.volume': Simplify<MeasurementListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement`s */\n 'list.weight': Simplify<MeasurementListParsedMetafield>;\n};\n\n// This test is to ensure that ParsedMetafields has a key for every item in 'allMetafieldsTypesArray'\nexpectType<TypeEqual<keyof ParsedMetafields, MetafieldTypeTypes>>(true);\n\ninterface ParsedBase extends MetafieldBaseType {\n type: MetafieldTypeTypes;\n parsedValue: unknown;\n}\n\ninterface BooleanParsedMetafield extends ParsedBase {\n type: 'boolean';\n parsedValue: boolean | null;\n}\ntype CollectionParsedRefMetafield = MetafieldBaseType & {\n type: 'collection_reference';\n parsedValue: Collection | null;\n};\ntype ColorParsedMetafield = MetafieldBaseType & {\n type: 'color';\n parsedValue: string | null;\n};\ntype DatesParsedMetafield = MetafieldBaseType & {\n type: 'date' | 'date_time';\n parsedValue: Date | null;\n};\n\ntype MeasurementParsedMetafield = MetafieldBaseType & {\n type: 'dimension' | 'weight' | 'volume';\n parsedValue: Measurement | null;\n};\n\ntype FileRefParsedMetafield = MetafieldBaseType & {\n type: 'file_reference';\n parsedValue: GenericFile | null;\n};\n\ntype JsonParsedMetafield<JsonTypeGeneric = void> = MetafieldBaseType & {\n type: 'json';\n parsedValue: JsonTypeGeneric extends void ? unknown : JsonTypeGeneric | null;\n};\n\ntype MoneyParsedMetafield = MetafieldBaseType & {\n type: 'money';\n parsedValue: MoneyV2 | null;\n};\n\ntype TextParsedMetafield = MetafieldBaseType & {\n type: 'single_line_text_field' | 'multi_line_text_field' | 'url';\n parsedValue: string | null;\n};\n\ntype NumberParsedMetafield = MetafieldBaseType & {\n type: 'number_decimal' | 'number_integer';\n parsedValue: number | null;\n};\n\ntype PageParsedRefMetafield = MetafieldBaseType & {\n type: 'page_reference';\n parsedValue: Page | null;\n};\n\ntype ProductParsedRefMetafield = MetafieldBaseType & {\n type: 'product_reference';\n parsedValue: Product | null;\n};\n\ntype RatingParsedMetafield = MetafieldBaseType & {\n type: 'rating';\n parsedValue: Rating | null;\n};\n\ntype VariantParsedRefMetafield = MetafieldBaseType & {\n type: 'variant_reference';\n parsedValue: ProductVariant | null;\n};\n\ntype CollectionListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.collection_reference';\n parsedValue: Array<Collection> | null;\n};\n\ntype ColorListParsedMetafield = MetafieldBaseType & {\n type: 'list.color';\n parsedValue: Array<string> | null;\n};\n\ntype DatesListParsedMetafield = MetafieldBaseType & {\n type: 'list.date' | 'list.date_time';\n parsedValue: Array<Date> | null;\n};\n\ntype MeasurementListParsedMetafield = MetafieldBaseType & {\n type: 'list.dimension' | 'list.weight' | 'list.volume';\n parsedValue: Array<Measurement> | null;\n};\n\ntype FileListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.file_reference';\n parsedValue: Array<GenericFile> | null;\n};\n\ntype TextListParsedMetafield = MetafieldBaseType & {\n type: 'list.single_line_text_field' | 'list.url';\n parsedValue: Array<string> | null;\n};\n\ntype NumberListParsedMetafield = MetafieldBaseType & {\n type: 'list.number_decimal' | 'list.number_integer';\n parsedValue: Array<number> | null;\n};\n\ntype PageListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.page_reference';\n parsedValue: Array<Page> | null;\n};\n\ntype ProductListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.product_reference';\n parsedValue: Array<Product> | null;\n};\n\ntype RatingListParsedMetafield = MetafieldBaseType & {\n type: 'list.rating';\n parsedValue: Array<Rating> | null;\n};\n\ntype VariantListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.variant_reference';\n parsedValue: Array<ProductVariant> | null;\n};\n\nexport type Measurement = {\n unit: string;\n value: number;\n};\n\nexport interface Rating {\n value: number;\n scale_min: number;\n scale_max: number;\n}\n"],"names":["parseJSON","flattenConnection","expectType"],"mappings":";;;;;AAyBO,SAAS,gBACd,WACe;;AACX,MAAA,CAAC,UAAU,MAAM;AACnB,UAAM,cAAc;AACE;AACd,YAAA,IAAI,MAAM,WAAW;AAAA,IAO7B;AAAA,EACF;AAEA,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,UAAU,UAAU;AAAA,MAAA;AAAA,IAGrC,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,UAAU;AAAA,MAAA;AAAA,IAG3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,UAAU;AAAA,MAAA;AAAA,IAI3B,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK,eAAe;AAClB,UAAI,cAAc;AACd,UAAA;AACY,sBAAAA,UAAAA,WAAU,eAAU,UAAV,YAAmB,EAAE;AAAA,eACtC;AACP,cAAM,aAAa;AACG;AACd,gBAAA,IAAI,MAAM,UAAU;AAAA,QAG5B;AAAA,MAEF;AACO,aAAA;AAAA,QACL,GAAG;AAAA,QACH;AAAA,MAAA;AAAA,IAEJ;AAAA,IAEA,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,IAAI,MAAK,eAAU,UAAV,YAAmB,EAAE;AAAA,MAAA;AAAA,IAG/C,KAAK;AAAA,IACL,KAAK,kBAAkB;AACrB,YAAM,iBAAiBA,UAAA,WAAU,4CAAW,UAAX,YAAoB,EAAE;AAChD,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,eAAe,IAAI,CAAC,eAAe,IAAI,KAAK,UAAU,CAAC;AAAA,MAAA;AAAA,IAExE;AAAA,IAEA,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,OAAO,UAAU,KAAK;AAAA,MAAA;AAAA,IAGvC,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAaC,kBAAAA,mBAAkB,eAAU,eAAV,YAAwB,MAAS;AAAA,MAAA;AAAA,IAGpE,SAAS;AACD,YAAA,oBAAoB,uFAAuF,UAAU;AACrG;AACd,cAAA,IAAI,MAAM,iBAAiB;AAAA,MASnC;AAAA,IACF;AAAA,EACF;AACF;AA0IAC,MAAA,WAAkE,IAAI;;"}
@@ -0,0 +1,105 @@
1
+ import { parseJSON } from "./Metafield.mjs";
2
+ import { expectType as expectType_1 } from "./node_modules/ts-expect/dist/index.mjs";
3
+ import { flattenConnection } from "./flatten-connection.mjs";
4
+ function metafieldParser(metafield) {
5
+ var _a, _b, _c, _d;
6
+ if (!metafield.type) {
7
+ const noTypeError = `metafieldParser(): The 'type' field is required in order to parse the Metafield.`;
8
+ {
9
+ throw new Error(noTypeError);
10
+ }
11
+ }
12
+ switch (metafield.type) {
13
+ case "boolean":
14
+ return {
15
+ ...metafield,
16
+ parsedValue: metafield.value === "true"
17
+ };
18
+ case "collection_reference":
19
+ case "file_reference":
20
+ case "page_reference":
21
+ case "product_reference":
22
+ case "variant_reference":
23
+ return {
24
+ ...metafield,
25
+ parsedValue: metafield.reference
26
+ };
27
+ case "color":
28
+ case "multi_line_text_field":
29
+ case "single_line_text_field":
30
+ case "url":
31
+ return {
32
+ ...metafield,
33
+ parsedValue: metafield.value
34
+ };
35
+ case "dimension":
36
+ case "money":
37
+ case "json":
38
+ case "rating":
39
+ case "volume":
40
+ case "weight":
41
+ case "list.color":
42
+ case "list.dimension":
43
+ case "list.number_integer":
44
+ case "list.number_decimal":
45
+ case "list.rating":
46
+ case "list.single_line_text_field":
47
+ case "list.url":
48
+ case "list.volume":
49
+ case "list.weight": {
50
+ let parsedValue = null;
51
+ try {
52
+ parsedValue = parseJSON((_a = metafield.value) != null ? _a : "");
53
+ } catch (err) {
54
+ const parseError = `metafieldParser(): attempted to JSON.parse the 'metafield.value' property, but failed.`;
55
+ {
56
+ throw new Error(parseError);
57
+ }
58
+ }
59
+ return {
60
+ ...metafield,
61
+ parsedValue
62
+ };
63
+ }
64
+ case "date":
65
+ case "date_time":
66
+ return {
67
+ ...metafield,
68
+ parsedValue: new Date((_b = metafield.value) != null ? _b : "")
69
+ };
70
+ case "list.date":
71
+ case "list.date_time": {
72
+ const jsonParseValue = parseJSON((_c = metafield == null ? void 0 : metafield.value) != null ? _c : "");
73
+ return {
74
+ ...metafield,
75
+ parsedValue: jsonParseValue.map((dateString) => new Date(dateString))
76
+ };
77
+ }
78
+ case "number_decimal":
79
+ case "number_integer":
80
+ return {
81
+ ...metafield,
82
+ parsedValue: Number(metafield.value)
83
+ };
84
+ case "list.collection_reference":
85
+ case "list.file_reference":
86
+ case "list.page_reference":
87
+ case "list.product_reference":
88
+ case "list.variant_reference":
89
+ return {
90
+ ...metafield,
91
+ parsedValue: flattenConnection((_d = metafield.references) != null ? _d : void 0)
92
+ };
93
+ default: {
94
+ const typeNotFoundError = `metafieldParser(): the 'metafield.type' you passed in is not supported. Your type: "${metafield.type}". If you believe this is an error, please open an issue on GitHub.`;
95
+ {
96
+ throw new Error(typeNotFoundError);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ expectType_1(true);
102
+ export {
103
+ metafieldParser
104
+ };
105
+ //# sourceMappingURL=metafield-parser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metafield-parser.mjs","sources":["../../src/metafield-parser.ts"],"sourcesContent":["import type {\n Collection,\n GenericFile,\n Metafield as MetafieldBaseType,\n MoneyV2,\n Page,\n Product,\n ProductVariant,\n} from './storefront-api-types.js';\nimport type {PartialDeep, Simplify} from 'type-fest';\nimport {parseJSON} from './Metafield.js';\nimport {TypeEqual, expectType} from 'ts-expect';\nimport {flattenConnection} from './flatten-connection.js';\n\n/**\n * A temporary function that will be renamed to `parseMetafield()` in a future release.\n *\n * A function that uses `metafield.type` to parse the Metafield's `value` or `reference` or `references` (depending on the `type`) and put it in `metafield.parsedValue`\n *\n * TypeScript developers can use the type `ParsedMetafields` from this package to get the returned object's type correct. For example:\n *\n * ```\n * metafieldParser<ParsedMetafields['boolean']>({type: 'boolean', value: 'false'}\n * ```\n */\nexport function metafieldParser<ReturnGeneric>(\n metafield: PartialDeep<MetafieldBaseType, {recurseIntoArrays: true}>\n): ReturnGeneric {\n if (!metafield.type) {\n const noTypeError = `metafieldParser(): The 'type' field is required in order to parse the Metafield.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(noTypeError);\n } else {\n console.error(`${noTypeError} Returning 'parsedValue' of 'null'`);\n return {\n ...metafield,\n parsedValue: null,\n } as ReturnGeneric;\n }\n }\n\n switch (metafield.type) {\n case 'boolean':\n return {\n ...metafield,\n parsedValue: metafield.value === 'true',\n } as ReturnGeneric;\n\n case 'collection_reference':\n case 'file_reference':\n case 'page_reference':\n case 'product_reference':\n case 'variant_reference':\n return {\n ...metafield,\n parsedValue: metafield.reference,\n } as ReturnGeneric;\n\n case 'color':\n case 'multi_line_text_field':\n case 'single_line_text_field':\n case 'url':\n return {\n ...metafield,\n parsedValue: metafield.value,\n } as ReturnGeneric;\n\n // TODO: 'money' should probably be parsed even further to like `useMoney()`, but that logic needs to be extracted first so it's not a hook\n case 'dimension':\n case 'money':\n case 'json':\n case 'rating':\n case 'volume':\n case 'weight':\n case 'list.color':\n case 'list.dimension':\n case 'list.number_integer':\n case 'list.number_decimal':\n case 'list.rating':\n case 'list.single_line_text_field':\n case 'list.url':\n case 'list.volume':\n case 'list.weight': {\n let parsedValue = null;\n try {\n parsedValue = parseJSON(metafield.value ?? '');\n } catch (err) {\n const parseError = `metafieldParser(): attempted to JSON.parse the 'metafield.value' property, but failed.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(parseError);\n } else {\n console.error(`${parseError} Returning 'null' for 'parsedValue'`);\n }\n parsedValue = null;\n }\n return {\n ...metafield,\n parsedValue,\n } as ReturnGeneric;\n }\n\n case 'date':\n case 'date_time':\n return {\n ...metafield,\n parsedValue: new Date(metafield.value ?? ''),\n } as ReturnGeneric;\n\n case 'list.date':\n case 'list.date_time': {\n const jsonParseValue = parseJSON(metafield?.value ?? '') as string[];\n return {\n ...metafield,\n parsedValue: jsonParseValue.map((dateString) => new Date(dateString)),\n } as ReturnGeneric;\n }\n\n case 'number_decimal':\n case 'number_integer':\n return {\n ...metafield,\n parsedValue: Number(metafield.value),\n } as ReturnGeneric;\n\n case 'list.collection_reference':\n case 'list.file_reference':\n case 'list.page_reference':\n case 'list.product_reference':\n case 'list.variant_reference':\n return {\n ...metafield,\n parsedValue: flattenConnection(metafield.references ?? undefined),\n } as ReturnGeneric;\n\n default: {\n const typeNotFoundError = `metafieldParser(): the 'metafield.type' you passed in is not supported. Your type: \"${metafield.type}\". If you believe this is an error, please open an issue on GitHub.`;\n if (__HYDROGEN_DEV__) {\n throw new Error(typeNotFoundError);\n } else {\n console.error(\n `${typeNotFoundError} Returning 'parsedValue' of 'null'`\n );\n return {\n ...metafield,\n parsedValue: null,\n } as ReturnGeneric;\n }\n }\n }\n}\n\n// taken from https://shopify.dev/apps/metafields/types\nexport const allMetafieldTypesArray = [\n 'boolean',\n 'collection_reference',\n 'color',\n 'date',\n 'date_time',\n 'dimension',\n 'file_reference',\n 'json',\n 'money',\n 'multi_line_text_field',\n 'number_decimal',\n 'number_integer',\n 'page_reference',\n 'product_reference',\n 'rating',\n 'single_line_text_field',\n 'url',\n 'variant_reference',\n 'volume',\n 'weight',\n // list metafields\n 'list.collection_reference',\n 'list.color',\n 'list.date',\n 'list.date_time',\n 'list.dimension',\n 'list.file_reference',\n 'list.number_integer',\n 'list.number_decimal',\n 'list.page_reference',\n 'list.product_reference',\n 'list.rating',\n 'list.single_line_text_field',\n 'list.url',\n 'list.variant_reference',\n 'list.volume',\n 'list.weight',\n] as const;\n\n/** A union of all the supported `metafield.type`s */\nexport type MetafieldTypeTypes = typeof allMetafieldTypesArray[number];\n\n/**\n * A mapping of a Metafield's `type` to the TypeScript type that is returned from `metafieldParser()`\n * For example, when using `metafieldParser()`, the type will be correctly returned when used like the following:\n *\n * ```\n * const parsedMetafield = metafieldParser<ParsedMetafields['boolean']>(metafield);`\n * ```\n * `parsedMetafield.parsedValue`'s type is now `boolean`\n */\nexport type ParsedMetafields<ExtraTypeGeneric = void> = {\n /** A Metafield that's been parsed, with a `parsedValue` of `boolean` */\n boolean: Simplify<BooleanParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Collection` object (as defined by the Storefront API) */\n collection_reference: Simplify<CollectionParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n color: Simplify<ColorParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Date` */\n date: Simplify<DatesParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Date` */\n date_time: Simplify<DatesParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n dimension: Simplify<MeasurementParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `GenericFile` object (as defined by the Storefront API) */\n file_reference: Simplify<FileRefParsedMetafield>;\n /**\n * A Metafield that's been parsed, with a `parsedValue` of type `unknown`, unless you pass in the type as a generic. For example:\n *\n * ```\n * ParsedMetafields<MyJsonType>['json']\n * ```\n */\n json: Simplify<JsonParsedMetafield<ExtraTypeGeneric>>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Money` */\n money: Simplify<MoneyParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n multi_line_text_field: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `number` */\n number_decimal: Simplify<NumberParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `number` */\n number_integer: Simplify<NumberParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Page` object (as defined by the Storefront API) */\n page_reference: Simplify<PageParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `Product` object (as defined by the Storefront API) */\n product_reference: Simplify<ProductParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Rating` */\n rating: Simplify<RatingParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n single_line_text_field: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `string` */\n url: Simplify<TextParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of a `ProductVariant` object (as defined by the Storefront API) */\n variant_reference: Simplify<VariantParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n volume: Simplify<MeasurementParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of type `Measurement` */\n weight: Simplify<MeasurementParsedMetafield>;\n // list metafields\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Collection` objects (as defined by the Storefront API) */\n 'list.collection_reference': Simplify<CollectionListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.color': Simplify<ColorListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of Date objects */\n 'list.date': Simplify<DatesListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of Date objects */\n 'list.date_time': Simplify<DatesListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement` objects */\n 'list.dimension': Simplify<MeasurementListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `GenericFile` objects (as defined by the Storefront API) */\n 'list.file_reference': Simplify<FileListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of numbers */\n 'list.number_integer': Simplify<NumberListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of numbers */\n 'list.number_decimal': Simplify<NumberListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Page` objects (as defined by the Storefront API) */\n 'list.page_reference': Simplify<PageListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Product` objects (as defined by the Storefront API) */\n 'list.product_reference': Simplify<ProductListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Rating`s */\n 'list.rating': Simplify<RatingListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.single_line_text_field': Simplify<TextListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of strings */\n 'list.url': Simplify<TextListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `ProductVariant` objects (as defined by the Storefront API) */\n 'list.variant_reference': Simplify<VariantListParsedRefMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement`s */\n 'list.volume': Simplify<MeasurementListParsedMetafield>;\n /** A Metafield that's been parsed, with a `parsedValue` of an array of `Measurement`s */\n 'list.weight': Simplify<MeasurementListParsedMetafield>;\n};\n\n// This test is to ensure that ParsedMetafields has a key for every item in 'allMetafieldsTypesArray'\nexpectType<TypeEqual<keyof ParsedMetafields, MetafieldTypeTypes>>(true);\n\ninterface ParsedBase extends MetafieldBaseType {\n type: MetafieldTypeTypes;\n parsedValue: unknown;\n}\n\ninterface BooleanParsedMetafield extends ParsedBase {\n type: 'boolean';\n parsedValue: boolean | null;\n}\ntype CollectionParsedRefMetafield = MetafieldBaseType & {\n type: 'collection_reference';\n parsedValue: Collection | null;\n};\ntype ColorParsedMetafield = MetafieldBaseType & {\n type: 'color';\n parsedValue: string | null;\n};\ntype DatesParsedMetafield = MetafieldBaseType & {\n type: 'date' | 'date_time';\n parsedValue: Date | null;\n};\n\ntype MeasurementParsedMetafield = MetafieldBaseType & {\n type: 'dimension' | 'weight' | 'volume';\n parsedValue: Measurement | null;\n};\n\ntype FileRefParsedMetafield = MetafieldBaseType & {\n type: 'file_reference';\n parsedValue: GenericFile | null;\n};\n\ntype JsonParsedMetafield<JsonTypeGeneric = void> = MetafieldBaseType & {\n type: 'json';\n parsedValue: JsonTypeGeneric extends void ? unknown : JsonTypeGeneric | null;\n};\n\ntype MoneyParsedMetafield = MetafieldBaseType & {\n type: 'money';\n parsedValue: MoneyV2 | null;\n};\n\ntype TextParsedMetafield = MetafieldBaseType & {\n type: 'single_line_text_field' | 'multi_line_text_field' | 'url';\n parsedValue: string | null;\n};\n\ntype NumberParsedMetafield = MetafieldBaseType & {\n type: 'number_decimal' | 'number_integer';\n parsedValue: number | null;\n};\n\ntype PageParsedRefMetafield = MetafieldBaseType & {\n type: 'page_reference';\n parsedValue: Page | null;\n};\n\ntype ProductParsedRefMetafield = MetafieldBaseType & {\n type: 'product_reference';\n parsedValue: Product | null;\n};\n\ntype RatingParsedMetafield = MetafieldBaseType & {\n type: 'rating';\n parsedValue: Rating | null;\n};\n\ntype VariantParsedRefMetafield = MetafieldBaseType & {\n type: 'variant_reference';\n parsedValue: ProductVariant | null;\n};\n\ntype CollectionListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.collection_reference';\n parsedValue: Array<Collection> | null;\n};\n\ntype ColorListParsedMetafield = MetafieldBaseType & {\n type: 'list.color';\n parsedValue: Array<string> | null;\n};\n\ntype DatesListParsedMetafield = MetafieldBaseType & {\n type: 'list.date' | 'list.date_time';\n parsedValue: Array<Date> | null;\n};\n\ntype MeasurementListParsedMetafield = MetafieldBaseType & {\n type: 'list.dimension' | 'list.weight' | 'list.volume';\n parsedValue: Array<Measurement> | null;\n};\n\ntype FileListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.file_reference';\n parsedValue: Array<GenericFile> | null;\n};\n\ntype TextListParsedMetafield = MetafieldBaseType & {\n type: 'list.single_line_text_field' | 'list.url';\n parsedValue: Array<string> | null;\n};\n\ntype NumberListParsedMetafield = MetafieldBaseType & {\n type: 'list.number_decimal' | 'list.number_integer';\n parsedValue: Array<number> | null;\n};\n\ntype PageListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.page_reference';\n parsedValue: Array<Page> | null;\n};\n\ntype ProductListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.product_reference';\n parsedValue: Array<Product> | null;\n};\n\ntype RatingListParsedMetafield = MetafieldBaseType & {\n type: 'list.rating';\n parsedValue: Array<Rating> | null;\n};\n\ntype VariantListParsedRefMetafield = MetafieldBaseType & {\n type: 'list.variant_reference';\n parsedValue: Array<ProductVariant> | null;\n};\n\nexport type Measurement = {\n unit: string;\n value: number;\n};\n\nexport interface Rating {\n value: number;\n scale_min: number;\n scale_max: number;\n}\n"],"names":["expectType"],"mappings":";;;AAyBO,SAAS,gBACd,WACe;;AACX,MAAA,CAAC,UAAU,MAAM;AACnB,UAAM,cAAc;AACE;AACd,YAAA,IAAI,MAAM,WAAW;AAAA,IAO7B;AAAA,EACF;AAEA,UAAQ,UAAU,MAAM;AAAA,IACtB,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,UAAU,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,MAAA;AAAA,IAGvC,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,aAAa,mBAAkB,eAAU,eAAV,YAAwB,MAAS;AAAA,MAAA;AAAA,IAGpE,SAAS;AACD,YAAA,oBAAoB,uFAAuF,UAAU;AACrG;AACd,cAAA,IAAI,MAAM,iBAAiB;AAAA,MASnC;AAAA,IACF;AAAA,EACF;AACF;AA0IAA,aAAkE,IAAI;"}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ /*! *****************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+ function t(t2, n) {
18
+ var e2 = "function" == typeof Symbol && t2[Symbol.iterator];
19
+ if (!e2)
20
+ return t2;
21
+ var r2, i2, o2 = e2.call(t2), a2 = [];
22
+ try {
23
+ for (; (void 0 === n || n-- > 0) && !(r2 = o2.next()).done; )
24
+ a2.push(r2.value);
25
+ } catch (t3) {
26
+ i2 = { error: t3 };
27
+ } finally {
28
+ try {
29
+ r2 && !r2.done && (e2 = o2.return) && e2.call(o2);
30
+ } finally {
31
+ if (i2)
32
+ throw i2.error;
33
+ }
34
+ }
35
+ return a2;
36
+ }
37
+ exports.InterpreterStatus = void 0;
38
+ !function(t2) {
39
+ t2[t2.NotStarted = 0] = "NotStarted", t2[t2.Running = 1] = "Running", t2[t2.Stopped = 2] = "Stopped";
40
+ }(exports.InterpreterStatus || (exports.InterpreterStatus = {}));
41
+ var e = { type: "xstate.init" };
42
+ function r(t2) {
43
+ return void 0 === t2 ? [] : [].concat(t2);
44
+ }
45
+ function i(t2) {
46
+ return { type: "xstate.assign", assignment: t2 };
47
+ }
48
+ function o(t2, n) {
49
+ return "string" == typeof (t2 = "string" == typeof t2 && n && n[t2] ? n[t2] : t2) ? { type: t2 } : "function" == typeof t2 ? { type: t2.name, exec: t2 } : t2;
50
+ }
51
+ function a(t2) {
52
+ return function(n) {
53
+ return t2 === n;
54
+ };
55
+ }
56
+ function u(t2) {
57
+ return "string" == typeof t2 ? { type: t2 } : t2;
58
+ }
59
+ function c(t2, n) {
60
+ return { value: t2, context: n, actions: [], changed: false, matches: a(t2) };
61
+ }
62
+ function f(t2, n, e2) {
63
+ var r2 = n, i2 = false;
64
+ return [t2.filter(function(t3) {
65
+ if ("xstate.assign" === t3.type) {
66
+ i2 = true;
67
+ var n2 = Object.assign({}, r2);
68
+ return "function" == typeof t3.assignment ? n2 = t3.assignment(r2, e2) : Object.keys(t3.assignment).forEach(function(i3) {
69
+ n2[i3] = "function" == typeof t3.assignment[i3] ? t3.assignment[i3](r2, e2) : t3.assignment[i3];
70
+ }), r2 = n2, false;
71
+ }
72
+ return true;
73
+ }), r2, i2];
74
+ }
75
+ function s(n, i2) {
76
+ void 0 === i2 && (i2 = {});
77
+ var s2 = t(f(r(n.states[n.initial].entry).map(function(t2) {
78
+ return o(t2, i2.actions);
79
+ }), n.context, e), 2), l2 = s2[0], v2 = s2[1], y = { config: n, _options: i2, initialState: { value: n.initial, actions: l2, context: v2, matches: a(n.initial) }, transition: function(e2, i3) {
80
+ var s3, l3, v3 = "string" == typeof e2 ? { value: e2, context: n.context } : e2, p = v3.value, g = v3.context, d = u(i3), x = n.states[p];
81
+ if (x.on) {
82
+ var m = r(x.on[d.type]);
83
+ try {
84
+ for (var h = function(t2) {
85
+ var n2 = "function" == typeof Symbol && Symbol.iterator, e3 = n2 && t2[n2], r2 = 0;
86
+ if (e3)
87
+ return e3.call(t2);
88
+ if (t2 && "number" == typeof t2.length)
89
+ return { next: function() {
90
+ return t2 && r2 >= t2.length && (t2 = void 0), { value: t2 && t2[r2++], done: !t2 };
91
+ } };
92
+ throw new TypeError(n2 ? "Object is not iterable." : "Symbol.iterator is not defined.");
93
+ }(m), b = h.next(); !b.done; b = h.next()) {
94
+ var S = b.value;
95
+ if (void 0 === S)
96
+ return c(p, g);
97
+ var w = "string" == typeof S ? { target: S } : S, j = w.target, E = w.actions, R = void 0 === E ? [] : E, N = w.cond, O = void 0 === N ? function() {
98
+ return true;
99
+ } : N, _ = void 0 === j, k = null != j ? j : p, T = n.states[k];
100
+ if (O(g, d)) {
101
+ var q = t(f((_ ? r(R) : [].concat(x.exit, R, T.entry).filter(function(t2) {
102
+ return t2;
103
+ })).map(function(t2) {
104
+ return o(t2, y._options.actions);
105
+ }), g, d), 3), z = q[0], A = q[1], B = q[2], C = null != j ? j : p;
106
+ return { value: C, context: A, actions: z, changed: j !== p || z.length > 0 || B, matches: a(C) };
107
+ }
108
+ }
109
+ } catch (t2) {
110
+ s3 = { error: t2 };
111
+ } finally {
112
+ try {
113
+ b && !b.done && (l3 = h.return) && l3.call(h);
114
+ } finally {
115
+ if (s3)
116
+ throw s3.error;
117
+ }
118
+ }
119
+ }
120
+ return c(p, g);
121
+ } };
122
+ return y;
123
+ }
124
+ var l = function(t2, n) {
125
+ return t2.actions.forEach(function(e2) {
126
+ var r2 = e2.exec;
127
+ return r2 && r2(t2.context, n);
128
+ });
129
+ };
130
+ function v(t2) {
131
+ var r2 = t2.initialState, i2 = exports.InterpreterStatus.NotStarted, o2 = /* @__PURE__ */ new Set(), c2 = { _machine: t2, send: function(e2) {
132
+ i2 === exports.InterpreterStatus.Running && (r2 = t2.transition(r2, e2), l(r2, u(e2)), o2.forEach(function(t3) {
133
+ return t3(r2);
134
+ }));
135
+ }, subscribe: function(t3) {
136
+ return o2.add(t3), t3(r2), { unsubscribe: function() {
137
+ return o2.delete(t3);
138
+ } };
139
+ }, start: function(o3) {
140
+ if (o3) {
141
+ var u2 = "object" == typeof o3 ? o3 : { context: t2.config.context, value: o3 };
142
+ r2 = { value: u2.value, actions: [], context: u2.context, matches: a(u2.value) };
143
+ } else
144
+ r2 = t2.initialState;
145
+ return i2 = exports.InterpreterStatus.Running, l(r2, e), c2;
146
+ }, stop: function() {
147
+ return i2 = exports.InterpreterStatus.Stopped, o2.clear(), c2;
148
+ }, get state() {
149
+ return r2;
150
+ }, get status() {
151
+ return i2;
152
+ } };
153
+ return c2;
154
+ }
155
+ exports.assign = i;
156
+ exports.createMachine = s;
157
+ exports.interpret = v;
158
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../../../../../node_modules/@xstate/fsm/es/index.js"],"sourcesContent":["/*! *****************************************************************************\nCopyright (c) Microsoft Corporation.\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\nPERFORMANCE OF THIS SOFTWARE.\n***************************************************************************** */\nfunction t(t,n){var e=\"function\"==typeof Symbol&&t[Symbol.iterator];if(!e)return t;var r,i,o=e.call(t),a=[];try{for(;(void 0===n||n-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(e=o.return)&&e.call(o)}finally{if(i)throw i.error}}return a}var n;!function(t){t[t.NotStarted=0]=\"NotStarted\",t[t.Running=1]=\"Running\",t[t.Stopped=2]=\"Stopped\"}(n||(n={}));var e={type:\"xstate.init\"};function r(t){return void 0===t?[]:[].concat(t)}function i(t){return{type:\"xstate.assign\",assignment:t}}function o(t,n){return\"string\"==typeof(t=\"string\"==typeof t&&n&&n[t]?n[t]:t)?{type:t}:\"function\"==typeof t?{type:t.name,exec:t}:t}function a(t){return function(n){return t===n}}function u(t){return\"string\"==typeof t?{type:t}:t}function c(t,n){return{value:t,context:n,actions:[],changed:!1,matches:a(t)}}function f(t,n,e){var r=n,i=!1;return[t.filter((function(t){if(\"xstate.assign\"===t.type){i=!0;var n=Object.assign({},r);return\"function\"==typeof t.assignment?n=t.assignment(r,e):Object.keys(t.assignment).forEach((function(i){n[i]=\"function\"==typeof t.assignment[i]?t.assignment[i](r,e):t.assignment[i]})),r=n,!1}return!0})),r,i]}function s(n,i){void 0===i&&(i={});var s=t(f(r(n.states[n.initial].entry).map((function(t){return o(t,i.actions)})),n.context,e),2),l=s[0],v=s[1],y={config:n,_options:i,initialState:{value:n.initial,actions:l,context:v,matches:a(n.initial)},transition:function(e,i){var s,l,v=\"string\"==typeof e?{value:e,context:n.context}:e,p=v.value,g=v.context,d=u(i),x=n.states[p];if(x.on){var m=r(x.on[d.type]);try{for(var h=function(t){var n=\"function\"==typeof Symbol&&Symbol.iterator,e=n&&t[n],r=0;if(e)return e.call(t);if(t&&\"number\"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(n?\"Object is not iterable.\":\"Symbol.iterator is not defined.\")}(m),b=h.next();!b.done;b=h.next()){var S=b.value;if(void 0===S)return c(p,g);var w=\"string\"==typeof S?{target:S}:S,j=w.target,E=w.actions,R=void 0===E?[]:E,N=w.cond,O=void 0===N?function(){return!0}:N,_=void 0===j,k=null!=j?j:p,T=n.states[k];if(O(g,d)){var q=t(f((_?r(R):[].concat(x.exit,R,T.entry).filter((function(t){return t}))).map((function(t){return o(t,y._options.actions)})),g,d),3),z=q[0],A=q[1],B=q[2],C=null!=j?j:p;return{value:C,context:A,actions:z,changed:j!==p||z.length>0||B,matches:a(C)}}}}catch(t){s={error:t}}finally{try{b&&!b.done&&(l=h.return)&&l.call(h)}finally{if(s)throw s.error}}}return c(p,g)}};return y}var l=function(t,n){return t.actions.forEach((function(e){var r=e.exec;return r&&r(t.context,n)}))};function v(t){var r=t.initialState,i=n.NotStarted,o=new Set,c={_machine:t,send:function(e){i===n.Running&&(r=t.transition(r,e),l(r,u(e)),o.forEach((function(t){return t(r)})))},subscribe:function(t){return o.add(t),t(r),{unsubscribe:function(){return o.delete(t)}}},start:function(o){if(o){var u=\"object\"==typeof o?o:{context:t.config.context,value:o};r={value:u.value,actions:[],context:u.context,matches:a(u.value)}}else r=t.initialState;return i=n.Running,l(r,e),c},stop:function(){return i=n.Stopped,o.clear(),c},get state(){return r},get status(){return i}};return c}export{n as InterpreterStatus,i as assign,s as createMachine,v as interpret};\n"],"names":["t","e","r","i","o","a","n","s","l","v","c","u"],"mappings":";;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,SAAS,EAAEA,IAAE,GAAE;AAAC,MAAIC,KAAE,cAAY,OAAO,UAAQD,GAAE,OAAO;AAAU,MAAG,CAACC;AAAE,WAAOD;AAAE,MAAIE,IAAEC,IAAEC,KAAEH,GAAE,KAAKD,EAAC,GAAEK,KAAE,CAAE;AAAC,MAAG;AAAC,YAA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