@shopify/hydrogen 2023.7.2 → 2023.7.3

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.
@@ -164,7 +164,9 @@ function CacheLong(overrideOptions) {
164
164
  return {
165
165
  mode: PUBLIC,
166
166
  maxAge: 3600,
167
+ // 1 hour
167
168
  staleWhileRevalidate: 82800,
169
+ // 23 Hours
168
170
  ...overrideOptions
169
171
  };
170
172
  }
@@ -218,7 +220,7 @@ async function setItem(cache, request, response, userCacheOptions) {
218
220
  );
219
221
  response.headers.set("cache-control", paddedCacheControlString);
220
222
  response.headers.set("real-cache-control", cacheControlString);
221
- response.headers.set("cache-put-date", new Date().toUTCString());
223
+ response.headers.set("cache-put-date", (/* @__PURE__ */ new Date()).toUTCString());
222
224
  await cache.put(request, response);
223
225
  }
224
226
  async function deleteItem(cache, request) {
@@ -235,7 +237,7 @@ function calculateAge(response, responseDate) {
235
237
  responseMaxAge = parseFloat(maxAgeMatch[1]);
236
238
  }
237
239
  }
238
- const ageInMs = new Date().valueOf() - new Date(responseDate).valueOf();
240
+ const ageInMs = (/* @__PURE__ */ new Date()).valueOf() - new Date(responseDate).valueOf();
239
241
  return [ageInMs / 1e3, responseMaxAge];
240
242
  }
241
243
  function isStale(request, response) {
@@ -321,6 +323,7 @@ async function runWithCache(cacheKey, actionFn, {
321
323
  return actionFn();
322
324
  }
323
325
  const key = hashKey([
326
+ // '__HYDROGEN_CACHE_ID__', // TODO purgeQueryCacheOnBuild
324
327
  ...typeof cacheKey === "string" ? [cacheKey] : cacheKey
325
328
  ]);
326
329
  const cachedItem = await getItemFromCache(cacheInstance, key);
@@ -419,7 +422,7 @@ var warnOnce = (string) => {
419
422
  };
420
423
 
421
424
  // src/version.ts
422
- var LIB_VERSION = "2023.7.2";
425
+ var LIB_VERSION = "2023.7.3";
423
426
 
424
427
  // src/storefront.ts
425
428
  var StorefrontApiError = class extends Error {
@@ -537,6 +540,20 @@ function createStorefrontClient(options) {
537
540
  }
538
541
  return {
539
542
  storefront: {
543
+ /**
544
+ * Sends a GraphQL query to the Storefront API.
545
+ *
546
+ * Example:
547
+ *
548
+ * ```js
549
+ * async function loader ({context: {storefront}}) {
550
+ * const data = await storefront.query('query { ... }', {
551
+ * variables: {},
552
+ * cache: storefront.CacheLong()
553
+ * });
554
+ * }
555
+ * ```
556
+ */
540
557
  query: (query, payload) => {
541
558
  query = minifyQuery(query);
542
559
  if (isMutationRE.test(query)) {
@@ -546,6 +563,19 @@ function createStorefrontClient(options) {
546
563
  }
547
564
  return fetchStorefrontApi({ ...payload, query });
548
565
  },
566
+ /**
567
+ * Sends a GraphQL mutation to the Storefront API.
568
+ *
569
+ * Example:
570
+ *
571
+ * ```js
572
+ * async function loader ({context: {storefront}}) {
573
+ * await storefront.mutate('mutation { ... }', {
574
+ * variables: {},
575
+ * });
576
+ * }
577
+ * ```
578
+ */
549
579
  mutate: (mutation, payload) => {
550
580
  mutation = minifyQuery(mutation);
551
581
  if (isQueryRE.test(mutation)) {
@@ -565,6 +595,25 @@ function createStorefrontClient(options) {
565
595
  getPrivateTokenHeaders,
566
596
  getShopifyDomain,
567
597
  getApiUrl: getStorefrontApiUrl,
598
+ /**
599
+ * Wether it's a GraphQL error returned in the Storefront API response.
600
+ *
601
+ * Example:
602
+ *
603
+ * ```js
604
+ * async function loader ({context: {storefront}}) {
605
+ * try {
606
+ * await storefront.query(...);
607
+ * } catch(error) {
608
+ * if (storefront.isApiError(error)) {
609
+ * // ...
610
+ * }
611
+ *
612
+ * throw error;
613
+ * }
614
+ * }
615
+ * ```
616
+ */
568
617
  isApiError: isStorefrontApiError,
569
618
  i18n: i18n ?? defaultI18n
570
619
  }
@@ -787,11 +836,11 @@ var graphiqlLoader = async function graphiqlLoader2({
787
836
  <script
788
837
  crossorigin
789
838
  src="https://unpkg.com/react@18/umd/react.development.js"
790
- ><\/script>
839
+ ></script>
791
840
  <script
792
841
  crossorigin
793
842
  src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
794
- ><\/script>
843
+ ></script>
795
844
  <link rel="stylesheet" href="https://unpkg.com/graphiql@3/graphiql.min.css" />
796
845
  </head>
797
846
 
@@ -800,7 +849,7 @@ var graphiqlLoader = async function graphiqlLoader2({
800
849
  <script
801
850
  src="https://unpkg.com/graphiql@3/graphiql.min.js"
802
851
  type="application/javascript"
803
- ><\/script>
852
+ ></script>
804
853
  <script>
805
854
  const windowUrl = new URL(document.URL);
806
855
 
@@ -830,7 +879,7 @@ var graphiqlLoader = async function graphiqlLoader2({
830
879
  variables
831
880
  }),
832
881
  );
833
- <\/script>
882
+ </script>
834
883
  </body>
835
884
  </html>
836
885
  `,
@@ -1013,6 +1062,7 @@ function generateSeoTags(seoInput) {
1013
1062
  type: "application/ld+json",
1014
1063
  children: JSON.stringify(block)
1015
1064
  },
1065
+ // @ts-expect-error
1016
1066
  `json-ld-${block?.["@type"] || block?.name || index++}`
1017
1067
  );
1018
1068
  tagResults.push(tag);
@@ -1398,18 +1448,17 @@ function CartForm({
1398
1448
  route
1399
1449
  }) {
1400
1450
  const fetcher = react$1.useFetcher();
1401
- return /* @__PURE__ */ jsxRuntime.jsxs(fetcher.Form, {
1402
- action: route || "",
1403
- method: "post",
1404
- children: [
1405
- (action || inputs) && /* @__PURE__ */ jsxRuntime.jsx("input", {
1451
+ return /* @__PURE__ */ jsxRuntime.jsxs(fetcher.Form, { action: route || "", method: "post", children: [
1452
+ (action || inputs) && /* @__PURE__ */ jsxRuntime.jsx(
1453
+ "input",
1454
+ {
1406
1455
  type: "hidden",
1407
1456
  name: INPUT_NAME,
1408
1457
  value: JSON.stringify({ action, inputs })
1409
- }),
1410
- typeof children === "function" ? children(fetcher) : children
1411
- ]
1412
- });
1458
+ }
1459
+ ),
1460
+ typeof children === "function" ? children(fetcher) : children
1461
+ ] });
1413
1462
  }
1414
1463
  CartForm.INPUT_NAME = INPUT_NAME;
1415
1464
  CartForm.ACTIONS = {
@@ -2125,7 +2174,10 @@ function VariantSelector({
2125
2174
  )
2126
2175
  );
2127
2176
  const currentParam = searchParams.get(option.name);
2128
- const calculatedActiveValue = currentParam ? currentParam === value : false;
2177
+ const calculatedActiveValue = currentParam ? (
2178
+ // If a URL parameter exists for the current option, check if it equals the current value
2179
+ currentParam === value
2180
+ ) : false;
2129
2181
  if (calculatedActiveValue) {
2130
2182
  activeValue = value;
2131
2183
  }
@@ -2168,22 +2220,25 @@ function useVariantPath(handle) {
2168
2220
  const searchParams = new URLSearchParams(search);
2169
2221
  return {
2170
2222
  searchParams,
2223
+ // If the current pathname matches the product page, we need to make sure
2224
+ // that we append to the current search params. Otherwise all the search
2225
+ // params can be generated new.
2171
2226
  alreadyOnProductPage: path === pathname,
2172
2227
  path
2173
2228
  };
2174
2229
  }, [pathname, search, handle]);
2175
2230
  }
2176
- //! @see https://shopify.dev/docs/api/storefront/2023-07/mutations/cartMetafieldDelete
2177
- //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartBuyerIdentityUpdate
2178
- //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartDiscountCodesUpdate
2179
- //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartMetafieldsSet
2180
- //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartNoteUpdate
2181
- //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartSelectedDeliveryOptionsUpdate
2182
- //! @see https://shopify.dev/docs/api/storefront/latest/queries/cart
2183
2231
  //! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartCreate
2232
+ //! @see https://shopify.dev/docs/api/storefront/latest/queries/cart
2184
2233
  //! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartLinesAdd
2185
- //! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartLinesRemove
2186
2234
  //! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartLinesUpdate
2235
+ //! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartLinesRemove
2236
+ //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartDiscountCodesUpdate
2237
+ //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartBuyerIdentityUpdate
2238
+ //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartNoteUpdate
2239
+ //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartSelectedDeliveryOptionsUpdate
2240
+ //! @see https://shopify.dev/docs/api/storefront/latest/mutations/cartMetafieldsSet
2241
+ //! @see https://shopify.dev/docs/api/storefront/2023-07/mutations/cartMetafieldDelete
2187
2242
 
2188
2243
  Object.defineProperty(exports, 'AnalyticsEventName', {
2189
2244
  enumerable: true,