@shopify/hydrogen 2023.7.10 → 2023.7.12

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.
@@ -424,14 +424,13 @@ async function fetchWithServerCache(url, requestInit, {
424
424
  }
425
425
  ).then(fromSerializableResponse);
426
426
  }
427
- var getCallerStackLine = () => {
428
- const stackInfo = { stack: "" };
429
- Error.captureStackTrace(stackInfo);
430
- return stackInfo.stack.split("\n").slice(3, 4).join("\n") || "";
431
- } ;
432
427
 
433
428
  // src/constants.ts
434
429
  var STOREFRONT_REQUEST_GROUP_ID_HEADER = "Custom-Storefront-Request-Group-ID";
430
+ var STOREFRONT_ACCESS_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
431
+ var SDK_VARIANT_HEADER = "X-SDK-Variant";
432
+ var SDK_VARIANT_SOURCE_HEADER = "X-SDK-Variant-Source";
433
+ var SDK_VERSION_HEADER = "X-SDK-Version";
435
434
 
436
435
  // src/utils/uuid.ts
437
436
  function generateUUID() {
@@ -452,7 +451,7 @@ var warnOnce = (string) => {
452
451
  };
453
452
 
454
453
  // src/version.ts
455
- var LIB_VERSION = "2023.7.10";
454
+ var LIB_VERSION = "2023.7.12";
456
455
 
457
456
  // src/storefront.ts
458
457
  var StorefrontApiError = class extends Error {
@@ -514,8 +513,7 @@ function createStorefrontClient(options) {
514
513
  variables,
515
514
  cache: cacheOptions,
516
515
  headers = [],
517
- storefrontApiVersion,
518
- stackLine
516
+ storefrontApiVersion
519
517
  }) {
520
518
  const userHeaders = headers instanceof Headers ? Object.fromEntries(headers.entries()) : Array.isArray(headers) ? Object.fromEntries(headers) : headers;
521
519
  query = query ?? mutation;
@@ -541,11 +539,11 @@ function createStorefrontClient(options) {
541
539
  method: requestInit.method,
542
540
  headers: {
543
541
  "content-type": defaultHeaders["content-type"],
544
- "X-SDK-Variant": defaultHeaders["X-SDK-Variant"],
545
- "X-SDK-Variant-Source": defaultHeaders["X-SDK-Variant-Source"],
546
- "X-SDK-Version": defaultHeaders["X-SDK-Version"],
547
- "X-Shopify-Storefront-Access-Token": defaultHeaders["X-Shopify-Storefront-Access-Token"],
548
- "user-agent": defaultHeaders["user-agent"]
542
+ "user-agent": defaultHeaders["user-agent"],
543
+ [SDK_VARIANT_HEADER]: defaultHeaders[SDK_VARIANT_HEADER],
544
+ [SDK_VARIANT_SOURCE_HEADER]: defaultHeaders[SDK_VARIANT_SOURCE_HEADER],
545
+ [SDK_VERSION_HEADER]: defaultHeaders[SDK_VERSION_HEADER],
546
+ [STOREFRONT_ACCESS_TOKEN_HEADER]: defaultHeaders[STOREFRONT_ACCESS_TOKEN_HEADER]
549
547
  },
550
548
  body: requestInit.body
551
549
  }
@@ -556,7 +554,11 @@ function createStorefrontClient(options) {
556
554
  cacheKey,
557
555
  shouldCacheResponse: checkGraphQLErrors,
558
556
  waitUntil,
559
- debugInfo: { stackLine, graphql: graphqlData }
557
+ debugInfo: {
558
+ graphql: graphqlData,
559
+ requestId: requestInit.headers[STOREFRONT_REQUEST_GROUP_ID_HEADER],
560
+ purpose: storefrontHeaders?.purpose
561
+ }
560
562
  });
561
563
  const errorOptions = {
562
564
  response,
@@ -609,8 +611,7 @@ function createStorefrontClient(options) {
609
611
  }
610
612
  const result = fetchStorefrontApi({
611
613
  ...payload,
612
- query,
613
- stackLine: getCallerStackLine?.()
614
+ query
614
615
  });
615
616
  result.catch(() => {
616
617
  });
@@ -638,8 +639,7 @@ function createStorefrontClient(options) {
638
639
  }
639
640
  const result = fetchStorefrontApi({
640
641
  ...payload,
641
- mutation,
642
- stackLine: getCallerStackLine?.()
642
+ mutation
643
643
  });
644
644
  result.catch(() => {
645
645
  });
@@ -706,17 +706,30 @@ function throwError({
706
706
  );
707
707
  }
708
708
 
709
+ // src/utils/request.ts
710
+ function getHeader(request, key) {
711
+ const value = request.headers?.get?.(key) ?? request.headers?.[key];
712
+ return typeof value === "string" ? value : null;
713
+ }
714
+ function getDebugHeaders(request) {
715
+ return request ? {
716
+ requestId: getHeader(request, "request-id"),
717
+ purpose: getHeader(request, "purpose")
718
+ } : {};
719
+ }
720
+
709
721
  // src/with-cache.ts
710
- function createWithCache(options) {
711
- const { cache, waitUntil } = options;
722
+ function createWithCache({
723
+ cache,
724
+ waitUntil,
725
+ request
726
+ }) {
712
727
  return function withCache(cacheKey, strategy, actionFn) {
713
728
  return runWithCache(cacheKey, actionFn, {
714
729
  strategy,
715
730
  cacheInstance: cache,
716
731
  waitUntil,
717
- debugInfo: {
718
- stackLine: getCallerStackLine?.()
719
- }
732
+ debugInfo: getDebugHeaders(request)
720
733
  });
721
734
  };
722
735
  }
@@ -2549,6 +2562,7 @@ exports.OptimisticInput = OptimisticInput;
2549
2562
  exports.Pagination = Pagination;
2550
2563
  exports.Script = Script;
2551
2564
  exports.Seo = Seo;
2565
+ exports.StorefrontApiError = StorefrontApiError;
2552
2566
  exports.VariantSelector = VariantSelector;
2553
2567
  exports.cartAttributesUpdateDefault = cartAttributesUpdateDefault;
2554
2568
  exports.cartBuyerIdentityUpdateDefault = cartBuyerIdentityUpdateDefault;