@shopify/hydrogen-react 2023.10.0 → 2023.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/browser-dev/ShopPayButton.mjs +22 -1
  2. package/dist/browser-dev/ShopPayButton.mjs.map +1 -1
  3. package/dist/browser-dev/storefront-client.mjs +2 -2
  4. package/dist/browser-dev/storefront-client.mjs.map +1 -1
  5. package/dist/browser-prod/ShopPayButton.mjs +22 -1
  6. package/dist/browser-prod/ShopPayButton.mjs.map +1 -1
  7. package/dist/browser-prod/storefront-client.mjs +1 -1
  8. package/dist/browser-prod/storefront-client.mjs.map +1 -1
  9. package/dist/node-dev/ShopPayButton.js +22 -1
  10. package/dist/node-dev/ShopPayButton.js.map +1 -1
  11. package/dist/node-dev/ShopPayButton.mjs +22 -1
  12. package/dist/node-dev/ShopPayButton.mjs.map +1 -1
  13. package/dist/node-dev/storefront-client.js +2 -2
  14. package/dist/node-dev/storefront-client.js.map +1 -1
  15. package/dist/node-dev/storefront-client.mjs +2 -2
  16. package/dist/node-dev/storefront-client.mjs.map +1 -1
  17. package/dist/node-prod/ShopPayButton.js +22 -1
  18. package/dist/node-prod/ShopPayButton.js.map +1 -1
  19. package/dist/node-prod/ShopPayButton.mjs +22 -1
  20. package/dist/node-prod/ShopPayButton.mjs.map +1 -1
  21. package/dist/node-prod/storefront-client.js +1 -1
  22. package/dist/node-prod/storefront-client.js.map +1 -1
  23. package/dist/node-prod/storefront-client.mjs +1 -1
  24. package/dist/node-prod/storefront-client.mjs.map +1 -1
  25. package/dist/types/ShopPayButton.d.ts +8 -2
  26. package/dist/umd/hydrogen-react.dev.js +23 -3
  27. package/dist/umd/hydrogen-react.dev.js.map +1 -1
  28. package/dist/umd/hydrogen-react.prod.js +18 -18
  29. package/dist/umd/hydrogen-react.prod.js.map +1 -1
  30. package/package.json +3 -3
@@ -797,6 +797,7 @@
797
797
  `
798
798
  );
799
799
  const SFAPI_VERSION = "2023-10";
800
+ const isMockShop = (domain) => domain.includes("mock.shop");
800
801
  function createStorefrontClient(props) {
801
802
  const {
802
803
  storeDomain,
@@ -817,7 +818,7 @@ Received "${storeDomain}".`
817
818
  You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${SFAPI_VERSION}"`
818
819
  );
819
820
  }
820
- if (!privateStorefrontToken && !globalThis.document) {
821
+ if (!privateStorefrontToken && !globalThis.document && !isMockShop(storeDomain)) {
821
822
  warnOnce(
822
823
  `Using a private storefront token is recommended for server environments.
823
824
  Refer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details.`
@@ -828,7 +829,6 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
828
829
  "You are attempting to use a private token in an environment where it can be easily accessed by anyone.\nThis is a security risk; please use the public token and the `publicStorefrontToken` prop"
829
830
  );
830
831
  }
831
- const isMockShop = (domain) => domain.includes("mock.shop");
832
832
  const getShopifyDomain = (overrideProps) => {
833
833
  const domain = (overrideProps == null ? void 0 : overrideProps.storeDomain) ?? storeDomain;
834
834
  return domain.includes("://") ? domain : `https://${domain}`;
@@ -3832,7 +3832,11 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
3832
3832
  return /* @__PURE__ */ React.createElement(Money, { ...passthroughProps, data: price });
3833
3833
  }
3834
3834
  const SHOPJS_URL = "https://cdn.shopify.com/shopifycloud/shop-js/v1.0/client.js";
3835
+ function isChannel(channel) {
3836
+ return channel === "headless" || channel === "hydrogen";
3837
+ }
3835
3838
  function ShopPayButton({
3839
+ channel,
3836
3840
  variantIds,
3837
3841
  className,
3838
3842
  variantIdsAndQuantities,
@@ -3843,6 +3847,7 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
3843
3847
  const storeDomain = _storeDomain || (shop == null ? void 0 : shop.storeDomain);
3844
3848
  const shopPayLoadedStatus = useLoadScript(SHOPJS_URL);
3845
3849
  let ids = [];
3850
+ let channelAttribution;
3846
3851
  if (!storeDomain || storeDomain === defaultShopifyContext.storeDomain) {
3847
3852
  throw new Error(MissingStoreDomainErrorMessage);
3848
3853
  }
@@ -3852,6 +3857,13 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
3852
3857
  if (!variantIds && !variantIdsAndQuantities) {
3853
3858
  throw new Error(MissingPropsErrorMessage);
3854
3859
  }
3860
+ if (channel) {
3861
+ if (isChannel(channel)) {
3862
+ channelAttribution = channel;
3863
+ } else {
3864
+ throw new Error(InvalidChannelErrorMessage);
3865
+ }
3866
+ }
3855
3867
  if (variantIds) {
3856
3868
  ids = variantIds.reduce((prev, curr) => {
3857
3869
  const bareId = parseGid(curr).id;
@@ -3877,12 +3889,20 @@ Refer to the authentication https://shopify.dev/api/storefront#authentication do
3877
3889
  const style = width ? {
3878
3890
  "--shop-pay-button-width": width
3879
3891
  } : void 0;
3880
- return /* @__PURE__ */ React.createElement("div", { className, style }, shopPayLoadedStatus === "done" && /* @__PURE__ */ React.createElement("shop-pay-button", { "store-url": storeDomain, variants: ids.join(",") }));
3892
+ return /* @__PURE__ */ React.createElement("div", { className, style }, shopPayLoadedStatus === "done" && /* @__PURE__ */ React.createElement(
3893
+ "shop-pay-button",
3894
+ {
3895
+ ...channelAttribution ? { channel: channelAttribution } : {},
3896
+ "store-url": storeDomain,
3897
+ variants: ids.join(",")
3898
+ }
3899
+ ));
3881
3900
  }
3882
3901
  const MissingStoreDomainErrorMessage = 'You must pass a "storeDomain" prop to the "ShopPayButton" component, or wrap it in a "ShopifyProvider" component.';
3883
3902
  const InvalidPropsErrorMessage = `You must pass in "variantIds" in the form of ["gid://shopify/ProductVariant/1"]`;
3884
3903
  const MissingPropsErrorMessage = `You must pass in either "variantIds" or "variantIdsAndQuantities" to ShopPayButton`;
3885
3904
  const DoublePropsErrorMessage = `You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component`;
3905
+ const InvalidChannelErrorMessage = `Invalid channel attribution value. Must be either "headless" or "hydrogen"`;
3886
3906
  const longTermLength = 60 * 60 * 24 * 360 * 1;
3887
3907
  const shortTermLength = 60 * 30;
3888
3908
  function useShopifyCookies(options) {