@shopify/hydrogen-react 0.0.0-next-992334e → 0.0.0-next-9b64572
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/dist/browser-dev/ShopifyProvider.mjs +23 -5
- package/dist/browser-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-dev/cart-constants.mjs +1 -3
- package/dist/browser-dev/cart-constants.mjs.map +1 -1
- package/dist/browser-dev/cart-hooks.mjs +9 -13
- package/dist/browser-dev/cart-hooks.mjs.map +1 -1
- package/dist/browser-dev/storefront-client.mjs +18 -10
- package/dist/browser-dev/storefront-client.mjs.map +1 -1
- package/dist/browser-prod/ShopifyProvider.mjs +23 -5
- package/dist/browser-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/browser-prod/cart-constants.mjs +1 -3
- package/dist/browser-prod/cart-constants.mjs.map +1 -1
- package/dist/browser-prod/cart-hooks.mjs +9 -13
- package/dist/browser-prod/cart-hooks.mjs.map +1 -1
- package/dist/browser-prod/storefront-client.mjs +18 -10
- package/dist/browser-prod/storefront-client.mjs.map +1 -1
- package/dist/node-dev/ShopifyProvider.js +23 -5
- package/dist/node-dev/ShopifyProvider.js.map +1 -1
- package/dist/node-dev/ShopifyProvider.mjs +23 -5
- package/dist/node-dev/ShopifyProvider.mjs.map +1 -1
- package/dist/node-dev/cart-constants.js +0 -2
- package/dist/node-dev/cart-constants.js.map +1 -1
- package/dist/node-dev/cart-constants.mjs +1 -3
- package/dist/node-dev/cart-constants.mjs.map +1 -1
- package/dist/node-dev/cart-hooks.js +8 -12
- package/dist/node-dev/cart-hooks.js.map +1 -1
- package/dist/node-dev/cart-hooks.mjs +9 -13
- package/dist/node-dev/cart-hooks.mjs.map +1 -1
- package/dist/node-dev/storefront-client.js +17 -9
- package/dist/node-dev/storefront-client.js.map +1 -1
- package/dist/node-dev/storefront-client.mjs +18 -10
- package/dist/node-dev/storefront-client.mjs.map +1 -1
- package/dist/node-prod/ShopifyProvider.js +23 -5
- package/dist/node-prod/ShopifyProvider.js.map +1 -1
- package/dist/node-prod/ShopifyProvider.mjs +23 -5
- package/dist/node-prod/ShopifyProvider.mjs.map +1 -1
- package/dist/node-prod/cart-constants.js +0 -2
- package/dist/node-prod/cart-constants.js.map +1 -1
- package/dist/node-prod/cart-constants.mjs +1 -3
- package/dist/node-prod/cart-constants.mjs.map +1 -1
- package/dist/node-prod/cart-hooks.js +8 -12
- package/dist/node-prod/cart-hooks.js.map +1 -1
- package/dist/node-prod/cart-hooks.mjs +9 -13
- package/dist/node-prod/cart-hooks.mjs.map +1 -1
- package/dist/node-prod/storefront-client.js +17 -9
- package/dist/node-prod/storefront-client.js.map +1 -1
- package/dist/node-prod/storefront-client.mjs +18 -10
- package/dist/node-prod/storefront-client.mjs.map +1 -1
- package/dist/types/CartLineProvider.d.ts +16 -0
- package/dist/types/ShopifyProvider.d.ts +35 -2
- package/dist/types/cart-constants.d.ts +0 -1
- package/dist/types/storefront-client.d.ts +9 -2
- package/dist/umd/hydrogen-react.dev.js +105 -86
- package/dist/umd/hydrogen-react.dev.js.map +1 -1
- package/dist/umd/hydrogen-react.prod.js +16 -16
- package/dist/umd/hydrogen-react.prod.js.map +1 -1
- package/package.json +1 -1
|
@@ -766,6 +766,80 @@ query CartQuery($id: ID!, $numCartLines: Int = 250, $country: CountryCode = ZZ)
|
|
|
766
766
|
${cartFragment}
|
|
767
767
|
`;
|
|
768
768
|
const SFAPI_VERSION = "2022-10";
|
|
769
|
+
function createStorefrontClient({
|
|
770
|
+
storeDomain,
|
|
771
|
+
privateStorefrontToken,
|
|
772
|
+
publicStorefrontToken,
|
|
773
|
+
storefrontApiVersion,
|
|
774
|
+
contentType
|
|
775
|
+
}) {
|
|
776
|
+
if (storefrontApiVersion !== SFAPI_VERSION) {
|
|
777
|
+
console.warn(
|
|
778
|
+
`StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen-UI is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${SFAPI_VERSION}"`
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
if (!privateStorefrontToken && !globalThis.document) {
|
|
782
|
+
console.warn(
|
|
783
|
+
`StorefrontClient: Using a private storefront token is recommended for server environments. Refer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details. `
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
if (privateStorefrontToken && globalThis) {
|
|
787
|
+
console.warn(
|
|
788
|
+
`StorefrontClient: You are attempting to use a private token in an environment where it can be easily accessed by anyone. This is a security risk; please use the public token and the 'publicStorefrontToken' prop`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
return {
|
|
792
|
+
getStorefrontApiUrl(overrideProps) {
|
|
793
|
+
var _a, _b;
|
|
794
|
+
return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : storefrontApiVersion}/graphql.json`;
|
|
795
|
+
},
|
|
796
|
+
getPrivateTokenHeaders(overrideProps) {
|
|
797
|
+
var _a, _b, _c;
|
|
798
|
+
if (!privateStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.privateStorefrontToken)) {
|
|
799
|
+
throw new Error(
|
|
800
|
+
`StorefrontClient: You did not pass in a 'privateStorefrontToken' while using 'getPrivateTokenHeaders()'`
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
if (!(overrideProps == null ? void 0 : overrideProps.buyerIp)) {
|
|
804
|
+
console.warn(
|
|
805
|
+
`StorefrontClient: it is recommended to pass in the 'buyerIp' property which improves analytics and data in the admin.`
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
|
|
809
|
+
return {
|
|
810
|
+
"content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
|
|
811
|
+
"X-SDK-Variant": "hydrogen-ui",
|
|
812
|
+
"X-SDK-Variant-Source": "react",
|
|
813
|
+
"X-SDK-Version": storefrontApiVersion,
|
|
814
|
+
"Shopify-Storefront-Private-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) != null ? _b : privateStorefrontToken) != null ? _c : "",
|
|
815
|
+
...(overrideProps == null ? void 0 : overrideProps.buyerIp) ? { "Shopify-Storefront-Buyer-IP": overrideProps.buyerIp } : {}
|
|
816
|
+
};
|
|
817
|
+
},
|
|
818
|
+
getPublicTokenHeaders(overrideProps) {
|
|
819
|
+
var _a, _b, _c, _d;
|
|
820
|
+
if (!publicStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.publicStorefrontToken)) {
|
|
821
|
+
throw new Error(
|
|
822
|
+
`StorefrontClient: You did not pass in a 'publicStorefrontToken' while using 'getPublicTokenHeaders()'`
|
|
823
|
+
);
|
|
824
|
+
}
|
|
825
|
+
const finalContentType = (_b = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType) != null ? _b : "json";
|
|
826
|
+
return getPublicTokenHeadersRaw(
|
|
827
|
+
finalContentType,
|
|
828
|
+
storefrontApiVersion,
|
|
829
|
+
(_d = (_c = overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) != null ? _c : publicStorefrontToken) != null ? _d : ""
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
function getPublicTokenHeadersRaw(contentType, storefrontApiVersion, accessToken) {
|
|
835
|
+
return {
|
|
836
|
+
"content-type": contentType === "graphql" ? "application/graphql" : "application/json",
|
|
837
|
+
"X-SDK-Variant": "hydrogen-ui",
|
|
838
|
+
"X-SDK-Variant-Source": "react",
|
|
839
|
+
"X-SDK-Version": storefrontApiVersion,
|
|
840
|
+
"X-Shopify-Storefront-Access-Token": accessToken
|
|
841
|
+
};
|
|
842
|
+
}
|
|
769
843
|
var _jsxFileName$f = "/home/runner/work/hydrogen-ui/hydrogen-ui/packages/react/src/ShopifyProvider.tsx";
|
|
770
844
|
const ShopifyContext = React.createContext({
|
|
771
845
|
storeDomain: "test.myshopify.com",
|
|
@@ -777,7 +851,13 @@ ${cartFragment}
|
|
|
777
851
|
language: {
|
|
778
852
|
isoCode: "EN"
|
|
779
853
|
},
|
|
780
|
-
locale: "EN-US"
|
|
854
|
+
locale: "EN-US",
|
|
855
|
+
getStorefrontApiUrl() {
|
|
856
|
+
return "";
|
|
857
|
+
},
|
|
858
|
+
getPublicTokenHeaders() {
|
|
859
|
+
return {};
|
|
860
|
+
}
|
|
781
861
|
});
|
|
782
862
|
function ShopifyProvider({
|
|
783
863
|
children,
|
|
@@ -789,16 +869,27 @@ ${cartFragment}
|
|
|
789
869
|
if (shopifyConfig.storefrontApiVersion !== SFAPI_VERSION) {
|
|
790
870
|
console.warn(`This version of Hydrogen-UI is built for Shopify's Storefront API version ${SFAPI_VERSION}, but it looks like you're using version ${shopifyConfig.storefrontApiVersion}. There may be issues or bugs if you use a mismatched version of Hydrogen-UI and the Storefront API.`);
|
|
791
871
|
}
|
|
792
|
-
const finalConfig = React.useMemo(() =>
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
872
|
+
const finalConfig = React.useMemo(() => {
|
|
873
|
+
const storeDomain = shopifyConfig.storeDomain.replace(/^https?:\/\//, "");
|
|
874
|
+
return {
|
|
875
|
+
...shopifyConfig,
|
|
876
|
+
storeDomain,
|
|
877
|
+
getPublicTokenHeaders(overrideProps) {
|
|
878
|
+
var _a;
|
|
879
|
+
return getPublicTokenHeadersRaw(overrideProps.contentType, shopifyConfig.storefrontApiVersion, (_a = overrideProps.storefrontToken) != null ? _a : shopifyConfig.storefrontToken);
|
|
880
|
+
},
|
|
881
|
+
getStorefrontApiUrl(overrideProps) {
|
|
882
|
+
var _a, _b;
|
|
883
|
+
return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : shopifyConfig.storefrontApiVersion}/graphql.json`;
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
}, [shopifyConfig]);
|
|
796
887
|
return /* @__PURE__ */ React__default.default.createElement(ShopifyContext.Provider, {
|
|
797
888
|
value: finalConfig,
|
|
798
889
|
__self: this,
|
|
799
890
|
__source: {
|
|
800
891
|
fileName: _jsxFileName$f,
|
|
801
|
-
lineNumber:
|
|
892
|
+
lineNumber: 69,
|
|
802
893
|
columnNumber: 5
|
|
803
894
|
}
|
|
804
895
|
}, children);
|
|
@@ -811,7 +902,6 @@ ${cartFragment}
|
|
|
811
902
|
return shopContext;
|
|
812
903
|
}
|
|
813
904
|
const CART_ID_STORAGE_KEY = "shopifyCartId";
|
|
814
|
-
const STOREFRONT_API_PUBLIC_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token";
|
|
815
905
|
const SHOPIFY_STOREFRONT_ID_HEADER = "Shopify-Storefront-Id";
|
|
816
906
|
const SHOPIFY_STOREFRONT_Y_HEADER = "Shopify-Storefront-Y";
|
|
817
907
|
const SHOPIFY_STOREFRONT_S_HEADER = "Shopify-Storefront-S";
|
|
@@ -842,21 +932,17 @@ ${cartFragment}
|
|
|
842
932
|
}
|
|
843
933
|
function useCartFetch() {
|
|
844
934
|
const {
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
storefrontId
|
|
935
|
+
storefrontId,
|
|
936
|
+
getPublicTokenHeaders,
|
|
937
|
+
getStorefrontApiUrl
|
|
849
938
|
} = useShop();
|
|
850
939
|
return React.useCallback(({
|
|
851
940
|
query,
|
|
852
941
|
variables
|
|
853
942
|
}) => {
|
|
854
|
-
const headers = {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
"X-SDK-Version": storefrontApiVersion,
|
|
858
|
-
[STOREFRONT_API_PUBLIC_TOKEN_HEADER]: storefrontToken
|
|
859
|
-
};
|
|
943
|
+
const headers = getPublicTokenHeaders({
|
|
944
|
+
contentType: "json"
|
|
945
|
+
});
|
|
860
946
|
if (storefrontId) {
|
|
861
947
|
headers[SHOPIFY_STOREFRONT_ID_HEADER] = storefrontId;
|
|
862
948
|
}
|
|
@@ -865,7 +951,7 @@ ${cartFragment}
|
|
|
865
951
|
headers[SHOPIFY_STOREFRONT_Y_HEADER] = cookieData[SHOPIFY_Y];
|
|
866
952
|
headers[SHOPIFY_STOREFRONT_S_HEADER] = cookieData[SHOPIFY_S];
|
|
867
953
|
}
|
|
868
|
-
return fetch(
|
|
954
|
+
return fetch(getStorefrontApiUrl(), {
|
|
869
955
|
method: "POST",
|
|
870
956
|
headers,
|
|
871
957
|
body: JSON.stringify({
|
|
@@ -878,7 +964,7 @@ ${cartFragment}
|
|
|
878
964
|
errors: error.toString()
|
|
879
965
|
};
|
|
880
966
|
});
|
|
881
|
-
}, [
|
|
967
|
+
}, [getPublicTokenHeaders, storefrontId, getStorefrontApiUrl]);
|
|
882
968
|
}
|
|
883
969
|
function useCartActions({
|
|
884
970
|
numCartLines,
|
|
@@ -3361,73 +3447,6 @@ fragment ImageFragment on Image {
|
|
|
3361
3447
|
}
|
|
3362
3448
|
const MissingPropsErrorMessage = `You must pass in either "variantIds" or "variantIdsAndQuantities" to ShopPayButton`;
|
|
3363
3449
|
const DoublePropsErrorMessage = `You must provide either a variantIds or variantIdsAndQuantities prop, but not both in the ShopPayButton component`;
|
|
3364
|
-
function createStorefrontClient({
|
|
3365
|
-
storeDomain,
|
|
3366
|
-
privateStorefrontToken,
|
|
3367
|
-
publicStorefrontToken,
|
|
3368
|
-
storefrontApiVersion,
|
|
3369
|
-
contentType
|
|
3370
|
-
}) {
|
|
3371
|
-
if (storefrontApiVersion !== SFAPI_VERSION) {
|
|
3372
|
-
console.warn(
|
|
3373
|
-
`StorefrontClient: The Storefront API version that you're using is different than the version this build of Hydrogen-UI is targeting. You may run into unexpected errors if these versions don't match. Received verion: "${storefrontApiVersion}"; expected version "${SFAPI_VERSION}"`
|
|
3374
|
-
);
|
|
3375
|
-
}
|
|
3376
|
-
if (!privateStorefrontToken && !globalThis.document) {
|
|
3377
|
-
console.warn(
|
|
3378
|
-
`StorefrontClient: Using a private storefront token is recommended for server environments. Refer to the authentication https://shopify.dev/api/storefront#authentication documentation for more details. `
|
|
3379
|
-
);
|
|
3380
|
-
}
|
|
3381
|
-
if (privateStorefrontToken && globalThis) {
|
|
3382
|
-
console.warn(
|
|
3383
|
-
`StorefrontClient: You are attempting to use a private token in an environment where it can be easily accessed by anyone. This is a security risk; please use the public token and the 'publicStorefrontToken' prop`
|
|
3384
|
-
);
|
|
3385
|
-
}
|
|
3386
|
-
return {
|
|
3387
|
-
getStorefrontApiUrl(overrideProps) {
|
|
3388
|
-
var _a, _b;
|
|
3389
|
-
return `https://${(_a = overrideProps == null ? void 0 : overrideProps.storeDomain) != null ? _a : storeDomain}.myshopify.com/api/${(_b = overrideProps == null ? void 0 : overrideProps.storefrontApiVersion) != null ? _b : storefrontApiVersion}/graphql.json`;
|
|
3390
|
-
},
|
|
3391
|
-
getPrivateTokenHeaders(overrideProps) {
|
|
3392
|
-
var _a, _b, _c;
|
|
3393
|
-
if (!privateStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.privateStorefrontToken)) {
|
|
3394
|
-
throw new Error(
|
|
3395
|
-
`StorefrontClient: You did not pass in a 'privateStorefrontToken' while using 'getPrivateTokenHeaders()'`
|
|
3396
|
-
);
|
|
3397
|
-
}
|
|
3398
|
-
if (!(overrideProps == null ? void 0 : overrideProps.buyerIp)) {
|
|
3399
|
-
console.warn(
|
|
3400
|
-
`StorefrontClient: it is recommended to pass in the 'buyerIp' property which improves analytics and data in the admin.`
|
|
3401
|
-
);
|
|
3402
|
-
}
|
|
3403
|
-
const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
|
|
3404
|
-
return {
|
|
3405
|
-
"content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
|
|
3406
|
-
"X-SDK-Variant": "hydrogen-ui",
|
|
3407
|
-
"X-SDK-Variant-Source": "react",
|
|
3408
|
-
"X-SDK-Version": storefrontApiVersion,
|
|
3409
|
-
"Shopify-Storefront-Private-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.privateStorefrontToken) != null ? _b : privateStorefrontToken) != null ? _c : "",
|
|
3410
|
-
...(overrideProps == null ? void 0 : overrideProps.buyerIp) ? { "Shopify-Storefront-Buyer-IP": overrideProps.buyerIp } : {}
|
|
3411
|
-
};
|
|
3412
|
-
},
|
|
3413
|
-
getPublicTokenHeaders(overrideProps) {
|
|
3414
|
-
var _a, _b, _c;
|
|
3415
|
-
if (!publicStorefrontToken && !(overrideProps == null ? void 0 : overrideProps.publicStorefrontToken)) {
|
|
3416
|
-
throw new Error(
|
|
3417
|
-
`StorefrontClient: You did not pass in a 'publicStorefrontToken' while using 'getPublicTokenHeaders()'`
|
|
3418
|
-
);
|
|
3419
|
-
}
|
|
3420
|
-
const finalContentType = (_a = overrideProps == null ? void 0 : overrideProps.contentType) != null ? _a : contentType;
|
|
3421
|
-
return {
|
|
3422
|
-
"content-type": finalContentType === "graphql" ? "application/graphql" : "application/json",
|
|
3423
|
-
"X-SDK-Variant": "hydrogen-ui",
|
|
3424
|
-
"X-SDK-Variant-Source": "react",
|
|
3425
|
-
"X-SDK-Version": storefrontApiVersion,
|
|
3426
|
-
"X-Shopify-Storefront-Access-Token": (_c = (_b = overrideProps == null ? void 0 : overrideProps.publicStorefrontToken) != null ? _b : publicStorefrontToken) != null ? _c : ""
|
|
3427
|
-
};
|
|
3428
|
-
}
|
|
3429
|
-
};
|
|
3430
|
-
}
|
|
3431
3450
|
exports2.AddToCartButton = AddToCartButton;
|
|
3432
3451
|
exports2.BuyNowButton = BuyNowButton;
|
|
3433
3452
|
exports2.CartCheckoutButton = CartCheckoutButton;
|