@shopify/hydrogen 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1716](https://github.com/Shopify/hydrogen/pull/1716) [`4e6356e6`](https://github.com/Shopify/hydrogen/commit/4e6356e67bf92ff621573eac36fe34f37a1c326c) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Fix add to cart Shopify session tracking
8
+
9
+ * [#1713](https://github.com/Shopify/hydrogen/pull/1713) [`ea47ab68`](https://github.com/Shopify/hydrogen/commit/ea47ab68b112c0c1c5b28020c8a2fa91a54f0b78) Thanks [@frandiox](https://github.com/frandiox)! - Fix `fetchSync` when called with relative URLs.
10
+
3
11
  ## 1.0.0
4
12
 
5
13
  ### Major Changes
@@ -2,7 +2,8 @@ import React, { useState } from 'react';
2
2
  import { useShop } from '../../foundation';
3
3
  import { flattenConnection } from '../../utilities';
4
4
  import { CartCreate, defaultCartFragment } from './cart-queries';
5
- import { SHOPIFY_STOREFRONT_ID_HEADER, STOREFRONT_API_PUBLIC_TOKEN_HEADER, } from '../../constants';
5
+ import { SHOPIFY_STOREFRONT_ID_HEADER, STOREFRONT_API_PUBLIC_TOKEN_HEADER, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_STOREFRONT_S_HEADER, SHOPIFY_Y, SHOPIFY_S, } from '../../constants';
6
+ import { parse } from 'worktop/cookie';
6
7
  export function useCartFetch() {
7
8
  const { storeDomain, storefrontApiVersion, storefrontToken, storefrontId } = useShop();
8
9
  return React.useCallback(({ query, variables, }) => {
@@ -15,6 +16,12 @@ export function useCartFetch() {
15
16
  if (storefrontId) {
16
17
  headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
17
18
  }
19
+ // Find Shopify cookies
20
+ const cookieData = parse(document.cookie);
21
+ if (cookieData[SHOPIFY_Y] && cookieData[SHOPIFY_S]) {
22
+ headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
23
+ headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];
24
+ }
18
25
  return fetch(`https://${storeDomain}/api/${storefrontApiVersion}/graphql.json`, {
19
26
  method: 'POST',
20
27
  headers,
@@ -7,3 +7,7 @@ export declare const STOREFRONT_API_PUBLIC_TOKEN_HEADER = "X-Shopify-Storefront-
7
7
  export declare const STOREFRONT_API_BUYER_IP_HEADER = "Shopify-Storefront-Buyer-IP";
8
8
  export declare const SHOPIFY_STOREFRONT_ID_VARIABLE = "SHOPIFY_STOREFRONT_ID";
9
9
  export declare const SHOPIFY_STOREFRONT_ID_HEADER = "Shopify-Storefront-Id";
10
+ export declare const SHOPIFY_STOREFRONT_Y_HEADER = "Shopify-Storefront-Y";
11
+ export declare const SHOPIFY_STOREFRONT_S_HEADER = "Shopify-Storefront-S";
12
+ export declare const SHOPIFY_Y = "_shopify_y";
13
+ export declare const SHOPIFY_S = "_shopify_s";
@@ -7,3 +7,7 @@ export const STOREFRONT_API_PUBLIC_TOKEN_HEADER = 'X-Shopify-Storefront-Access-T
7
7
  export const STOREFRONT_API_BUYER_IP_HEADER = 'Shopify-Storefront-Buyer-IP';
8
8
  export const SHOPIFY_STOREFRONT_ID_VARIABLE = 'SHOPIFY_STOREFRONT_ID';
9
9
  export const SHOPIFY_STOREFRONT_ID_HEADER = 'Shopify-Storefront-Id';
10
+ export const SHOPIFY_STOREFRONT_Y_HEADER = 'Shopify-Storefront-Y';
11
+ export const SHOPIFY_STOREFRONT_S_HEADER = 'Shopify-Storefront-S';
12
+ export const SHOPIFY_Y = '_shopify_y';
13
+ export const SHOPIFY_S = '_shopify_s';
@@ -1,8 +1,8 @@
1
1
  import { useEffect } from 'react';
2
2
  import { parse, stringify } from 'worktop/cookie';
3
+ import { SHOPIFY_Y, SHOPIFY_S } from '../../../../constants';
3
4
  import { ClientAnalytics } from '../../ClientAnalytics';
4
5
  import { buildUUID, addDataIf } from './utils';
5
- import { SHOPIFY_S, SHOPIFY_Y } from './const';
6
6
  const longTermLength = 60 * 60 * 24 * 360 * 2; // ~2 year expiry
7
7
  const shortTermLength = 60 * 30; // 30 mins
8
8
  const myShopifyDomain = 'myshopify.com';
@@ -4,11 +4,11 @@ import AnalyticsErrorBoundary from '../../../AnalyticsErrorBoundary.client';
4
4
  import { useServerRequest } from '../../../ServerRequestProvider';
5
5
  import { useServerAnalytics } from '../../hook';
6
6
  import { useShop } from '../../../useShop';
7
- import { SHOPIFY_S, SHOPIFY_Y } from './const';
8
7
  import { ShopifyAnalyticsClient } from './ShopifyAnalytics.client';
9
8
  import { useShopQuery } from '../../../../hooks/useShopQuery';
10
9
  import { CacheLong } from '../../../Cache/strategies';
11
10
  import { gql } from '../../../../utilities/graphql-tag';
11
+ import { SHOPIFY_Y, SHOPIFY_S } from '../../../../constants';
12
12
  export function ShopifyAnalytics({ cookieDomain }) {
13
13
  const { storeDomain } = useShop();
14
14
  const request = useServerRequest();
@@ -1,5 +1,3 @@
1
- export declare const SHOPIFY_Y = "_shopify_y";
2
- export declare const SHOPIFY_S = "_shopify_s";
3
1
  export declare const ShopifyAnalyticsConstants: {
4
2
  pageType: {
5
3
  article: string;
@@ -1,5 +1,3 @@
1
- export const SHOPIFY_Y = '_shopify_y';
2
- export const SHOPIFY_S = '_shopify_s';
3
1
  // Shopify analytics constants
4
2
  const article = 'article';
5
3
  const blog = 'blog';
@@ -5,7 +5,7 @@ import { suspendFunction, preloadFunction } from '../../../utilities/suspense';
5
5
  */
6
6
  export function fetchSync(url, options) {
7
7
  const [text, response] = suspendFunction([url, options], async () => {
8
- const response = await globalThis.fetch(url, options);
8
+ const response = await globalThis.fetch(new URL(url, window.location.origin), options);
9
9
  const text = await response.text();
10
10
  return [text, response];
11
11
  });
@@ -1,5 +1,6 @@
1
1
  import { parseJSON } from '../../../utilities/parse';
2
2
  import { useQuery } from '../../useQuery/hooks';
3
+ import { useUrl } from '../../useUrl';
3
4
  /**
4
5
  * The `fetchSync` hook makes API requests and is the recommended way to make simple fetch calls on the server and the client.
5
6
  * It's designed similar to the [Web API's `fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch), only in a way
@@ -7,9 +8,11 @@ import { useQuery } from '../../useQuery/hooks';
7
8
  */
8
9
  export function fetchSync(url, options) {
9
10
  const { cache, preload, shouldCacheResponse, ...requestInit } = options ?? {};
11
+ // eslint-disable-next-line react-hooks/rules-of-hooks
12
+ const { origin } = useUrl();
10
13
  const { data: useQueryResponse, error } = useQuery(// eslint-disable-line react-hooks/rules-of-hooks
11
14
  [url, requestInit], async () => {
12
- const response = await globalThis.fetch(url, requestInit);
15
+ const response = await globalThis.fetch(new URL(url, origin), requestInit);
13
16
  const text = await response.text();
14
17
  return [text, response];
15
18
  }, {
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.0.0";
1
+ export declare const LIB_VERSION = "1.0.1";
@@ -1 +1 @@
1
- export const LIB_VERSION = '1.0.0';
1
+ export const LIB_VERSION = '1.0.1';
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "engines": {
8
8
  "node": ">=14"
9
9
  },
10
- "version": "1.0.0",
10
+ "version": "1.0.1",
11
11
  "description": "Modern custom Shopify storefronts",
12
12
  "license": "MIT",
13
13
  "main": "dist/esnext/index.js",