@shopify/hydrogen 2023.10.2 → 2023.10.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.
- package/dist/development/index.cjs +91 -57
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +93 -57
- package/dist/development/index.js.map +1 -1
- package/dist/production/index.cjs +57 -59
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.d.cts +47 -6
- package/dist/production/index.d.ts +47 -6
- package/dist/production/index.js +23 -23
- package/dist/production/index.js.map +1 -1
- package/package.json +4 -12
|
@@ -457,7 +457,7 @@ var warnOnce = (string) => {
|
|
|
457
457
|
};
|
|
458
458
|
|
|
459
459
|
// src/version.ts
|
|
460
|
-
var LIB_VERSION = "2023.10.
|
|
460
|
+
var LIB_VERSION = "2023.10.3";
|
|
461
461
|
|
|
462
462
|
// src/utils/graphql.ts
|
|
463
463
|
function minifyQuery(string) {
|
|
@@ -1435,11 +1435,12 @@ function Pagination({
|
|
|
1435
1435
|
pageInfo: {
|
|
1436
1436
|
endCursor,
|
|
1437
1437
|
hasPreviousPage,
|
|
1438
|
+
hasNextPage,
|
|
1438
1439
|
startCursor
|
|
1439
1440
|
},
|
|
1440
1441
|
nodes
|
|
1441
1442
|
}),
|
|
1442
|
-
[endCursor, hasPreviousPage, startCursor, nodes]
|
|
1443
|
+
[endCursor, hasNextPage, hasPreviousPage, startCursor, nodes]
|
|
1443
1444
|
);
|
|
1444
1445
|
const NextLink = react.useMemo(
|
|
1445
1446
|
() => react.forwardRef(function NextLink2(props, ref) {
|
|
@@ -1511,17 +1512,52 @@ function usePagination(connection) {
|
|
|
1511
1512
|
const params = new URLSearchParams(search);
|
|
1512
1513
|
const direction = params.get("direction");
|
|
1513
1514
|
const isPrevious = direction === "previous";
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1515
|
+
const nodes = react.useMemo(() => {
|
|
1516
|
+
if (!globalThis?.window?.__hydrogenHydrated || !state || !state?.nodes) {
|
|
1517
|
+
return hydrogenReact.flattenConnection(connection);
|
|
1518
|
+
}
|
|
1519
|
+
if (isPrevious) {
|
|
1520
|
+
return [...hydrogenReact.flattenConnection(connection), ...state.nodes];
|
|
1521
|
+
} else {
|
|
1522
|
+
return [...state.nodes, ...hydrogenReact.flattenConnection(connection)];
|
|
1523
|
+
}
|
|
1524
|
+
}, [state, connection]);
|
|
1525
|
+
const currentPageInfo = react.useMemo(() => {
|
|
1526
|
+
const hydrogenHydrated = globalThis?.window?.__hydrogenHydrated;
|
|
1527
|
+
let pageStartCursor = !hydrogenHydrated || state?.pageInfo?.startCursor === void 0 ? connection.pageInfo.startCursor : state.pageInfo.startCursor;
|
|
1528
|
+
let pageEndCursor = !hydrogenHydrated || state?.pageInfo?.endCursor === void 0 ? connection.pageInfo.endCursor : state.pageInfo.endCursor;
|
|
1529
|
+
let previousPageExists = !hydrogenHydrated || state?.pageInfo?.hasPreviousPage === void 0 ? connection.pageInfo.hasPreviousPage : state.pageInfo.hasPreviousPage;
|
|
1530
|
+
let nextPageExists = !hydrogenHydrated || state?.pageInfo?.hasNextPage === void 0 ? connection.pageInfo.hasNextPage : state.pageInfo.hasNextPage;
|
|
1531
|
+
if (state?.nodes) {
|
|
1532
|
+
if (isPrevious) {
|
|
1533
|
+
pageStartCursor = connection.pageInfo.startCursor;
|
|
1534
|
+
previousPageExists = connection.pageInfo.hasPreviousPage;
|
|
1535
|
+
} else {
|
|
1536
|
+
pageEndCursor = connection.pageInfo.endCursor;
|
|
1537
|
+
nextPageExists = connection.pageInfo.hasNextPage;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
return {
|
|
1541
|
+
startCursor: pageStartCursor,
|
|
1542
|
+
endCursor: pageEndCursor,
|
|
1543
|
+
hasPreviousPage: previousPageExists,
|
|
1544
|
+
hasNextPage: nextPageExists
|
|
1545
|
+
};
|
|
1546
|
+
}, [
|
|
1547
|
+
isPrevious,
|
|
1548
|
+
state,
|
|
1549
|
+
connection.pageInfo.hasNextPage,
|
|
1550
|
+
connection.pageInfo.hasPreviousPage,
|
|
1551
|
+
connection.pageInfo.startCursor,
|
|
1552
|
+
connection.pageInfo.endCursor
|
|
1553
|
+
]);
|
|
1521
1554
|
const urlRef = react.useRef({
|
|
1522
1555
|
params: getParamsWithoutPagination(search),
|
|
1523
1556
|
pathname
|
|
1524
1557
|
});
|
|
1558
|
+
react.useEffect(() => {
|
|
1559
|
+
window.__hydrogenHydrated = true;
|
|
1560
|
+
}, []);
|
|
1525
1561
|
react.useEffect(() => {
|
|
1526
1562
|
if (
|
|
1527
1563
|
// If the URL changes (independent of pagination params)
|
|
@@ -1537,39 +1573,8 @@ function usePagination(connection) {
|
|
|
1537
1573
|
preventScrollReset: true,
|
|
1538
1574
|
state: { nodes: void 0, pageInfo: void 0 }
|
|
1539
1575
|
});
|
|
1540
|
-
} else if (state?.nodes) {
|
|
1541
|
-
setNodes(
|
|
1542
|
-
isPrevious ? [...hydrogenReact.flattenConnection(connection), ...state.nodes] : [...state.nodes, ...hydrogenReact.flattenConnection(connection)]
|
|
1543
|
-
);
|
|
1544
|
-
if (state?.pageInfo) {
|
|
1545
|
-
let pageStartCursor = state?.pageInfo?.startCursor === void 0 ? connection.pageInfo.startCursor : state.pageInfo.startCursor;
|
|
1546
|
-
let pageEndCursor = state?.pageInfo?.endCursor === void 0 ? connection.pageInfo.endCursor : state.pageInfo.endCursor;
|
|
1547
|
-
let previousPageExists = state?.pageInfo?.hasPreviousPage === void 0 ? connection.pageInfo.hasPreviousPage : state.pageInfo.hasPreviousPage;
|
|
1548
|
-
let nextPageExists = state?.pageInfo?.hasNextPage === void 0 ? connection.pageInfo.hasNextPage : state.pageInfo.hasNextPage;
|
|
1549
|
-
if (isPrevious) {
|
|
1550
|
-
pageStartCursor = connection.pageInfo.startCursor;
|
|
1551
|
-
previousPageExists = connection.pageInfo.hasPreviousPage;
|
|
1552
|
-
} else {
|
|
1553
|
-
pageEndCursor = connection.pageInfo.endCursor;
|
|
1554
|
-
nextPageExists = connection.pageInfo.hasNextPage;
|
|
1555
|
-
}
|
|
1556
|
-
setCurrentPageInfo({
|
|
1557
|
-
startCursor: pageStartCursor,
|
|
1558
|
-
endCursor: pageEndCursor,
|
|
1559
|
-
hasPreviousPage: previousPageExists,
|
|
1560
|
-
hasNextPage: nextPageExists
|
|
1561
|
-
});
|
|
1562
|
-
}
|
|
1563
|
-
} else {
|
|
1564
|
-
setNodes(hydrogenReact.flattenConnection(connection));
|
|
1565
|
-
setCurrentPageInfo({
|
|
1566
|
-
startCursor: connection.pageInfo.startCursor,
|
|
1567
|
-
endCursor: connection.pageInfo.endCursor,
|
|
1568
|
-
hasPreviousPage: connection.pageInfo.hasPreviousPage,
|
|
1569
|
-
hasNextPage: connection.pageInfo.hasNextPage
|
|
1570
|
-
});
|
|
1571
1576
|
}
|
|
1572
|
-
}, [
|
|
1577
|
+
}, [pathname, search]);
|
|
1573
1578
|
const previousPageUrl = react.useMemo(() => {
|
|
1574
1579
|
const params2 = new URLSearchParams(search);
|
|
1575
1580
|
params2.set("direction", "previous");
|
|
@@ -1815,14 +1820,20 @@ function toHexString(byteArray) {
|
|
|
1815
1820
|
}
|
|
1816
1821
|
|
|
1817
1822
|
// src/customer/customer.ts
|
|
1823
|
+
var DEFAULT_CUSTOMER_API_VERSION = "2024-01";
|
|
1818
1824
|
function createCustomerClient({
|
|
1819
1825
|
session,
|
|
1820
1826
|
customerAccountId,
|
|
1821
1827
|
customerAccountUrl,
|
|
1822
|
-
customerApiVersion =
|
|
1828
|
+
customerApiVersion = DEFAULT_CUSTOMER_API_VERSION,
|
|
1823
1829
|
request,
|
|
1824
1830
|
waitUntil
|
|
1825
1831
|
}) {
|
|
1832
|
+
if (customerApiVersion !== DEFAULT_CUSTOMER_API_VERSION) {
|
|
1833
|
+
console.log(
|
|
1834
|
+
`[h2:warn:createCustomerClient] You are using Customer Account API version ${customerApiVersion} when this version of Hydrogen was built for ${DEFAULT_CUSTOMER_API_VERSION}.`
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1826
1837
|
if (!request?.url) {
|
|
1827
1838
|
throw new Error(
|
|
1828
1839
|
"[h2:error:createCustomerClient] The request object does not contain a URL."
|
|
@@ -1901,7 +1912,7 @@ function createCustomerClient({
|
|
|
1901
1912
|
throwGraphQLError({ ...errorOptions, errors });
|
|
1902
1913
|
}
|
|
1903
1914
|
try {
|
|
1904
|
-
return parseJSON(body)
|
|
1915
|
+
return parseJSON(body);
|
|
1905
1916
|
} catch (e) {
|
|
1906
1917
|
throwGraphQLError({ ...errorOptions, errors: [{ message: body }] });
|
|
1907
1918
|
}
|
|
@@ -2056,6 +2067,17 @@ function createCustomerClient({
|
|
|
2056
2067
|
}
|
|
2057
2068
|
};
|
|
2058
2069
|
}
|
|
2070
|
+
|
|
2071
|
+
// src/changelogHandler.ts
|
|
2072
|
+
var DEFAULT_GITHUB_CHANGELOG_URL = "https://raw.githubusercontent.com/Shopify/hydrogen/main/docs/changelog.json";
|
|
2073
|
+
async function changelogHandler({
|
|
2074
|
+
request,
|
|
2075
|
+
changelogUrl
|
|
2076
|
+
}) {
|
|
2077
|
+
new URL(request.url).searchParams;
|
|
2078
|
+
const GITHUB_CHANGELOG_URL = changelogUrl || DEFAULT_GITHUB_CHANGELOG_URL;
|
|
2079
|
+
return fetch(GITHUB_CHANGELOG_URL);
|
|
2080
|
+
}
|
|
2059
2081
|
var INPUT_NAME = "cartFormInput";
|
|
2060
2082
|
function CartForm({
|
|
2061
2083
|
children,
|
|
@@ -2866,21 +2888,32 @@ function createContentSecurityPolicy(directives = {}) {
|
|
|
2866
2888
|
}
|
|
2867
2889
|
function createCSPHeader(nonce, directives = {}) {
|
|
2868
2890
|
const nonceString = `'nonce-${nonce}'`;
|
|
2891
|
+
const styleSrc = ["'self'", "'unsafe-inline'", "https://cdn.shopify.com"];
|
|
2892
|
+
const connectSrc = ["'self'", "https://monorail-edge.shopifysvc.com"];
|
|
2893
|
+
const defaultSrc = [
|
|
2894
|
+
"'self'",
|
|
2895
|
+
nonceString,
|
|
2896
|
+
"https://cdn.shopify.com",
|
|
2897
|
+
// Used for the Customer Account API
|
|
2898
|
+
"https://shopify.com"
|
|
2899
|
+
];
|
|
2869
2900
|
const defaultDirectives = {
|
|
2870
2901
|
baseUri: ["'self'"],
|
|
2871
|
-
defaultSrc
|
|
2872
|
-
"'self'",
|
|
2873
|
-
nonceString,
|
|
2874
|
-
"https://cdn.shopify.com",
|
|
2875
|
-
// Used for the Customer Account API
|
|
2876
|
-
"https://shopify.com"
|
|
2877
|
-
],
|
|
2902
|
+
defaultSrc,
|
|
2878
2903
|
frameAncestors: ["none"],
|
|
2879
|
-
styleSrc
|
|
2880
|
-
connectSrc
|
|
2904
|
+
styleSrc,
|
|
2905
|
+
connectSrc
|
|
2881
2906
|
};
|
|
2882
2907
|
{
|
|
2883
|
-
defaultDirectives.
|
|
2908
|
+
defaultDirectives.styleSrc = [...styleSrc, "localhost:*"];
|
|
2909
|
+
defaultDirectives.defaultSrc = [...defaultSrc, "localhost:*"];
|
|
2910
|
+
defaultDirectives.connectSrc = [
|
|
2911
|
+
...connectSrc,
|
|
2912
|
+
"localhost:*",
|
|
2913
|
+
// For HMR:
|
|
2914
|
+
"ws://localhost:*",
|
|
2915
|
+
"ws://127.0.0.1:*"
|
|
2916
|
+
];
|
|
2884
2917
|
}
|
|
2885
2918
|
const combinedDirectives = Object.assign({}, defaultDirectives, directives);
|
|
2886
2919
|
if (combinedDirectives.scriptSrc instanceof Array && !combinedDirectives.scriptSrc.includes(nonceString)) {
|
|
@@ -2929,6 +2962,9 @@ function OptimisticInput({ id, data }) {
|
|
|
2929
2962
|
)
|
|
2930
2963
|
] });
|
|
2931
2964
|
}
|
|
2965
|
+
function ShopPayButton(props) {
|
|
2966
|
+
return /* @__PURE__ */ jsxRuntime.jsx(hydrogenReact.ShopPayButton, { channel: "hydrogen", ...props });
|
|
2967
|
+
}
|
|
2932
2968
|
//! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartCreate
|
|
2933
2969
|
//! @see https://shopify.dev/docs/api/storefront/latest/queries/cart
|
|
2934
2970
|
//! @see: https://shopify.dev/docs/api/storefront/latest/mutations/cartLinesAdd
|
|
@@ -2973,10 +3009,6 @@ Object.defineProperty(exports, 'Money', {
|
|
|
2973
3009
|
enumerable: true,
|
|
2974
3010
|
get: function () { return hydrogenReact.Money; }
|
|
2975
3011
|
});
|
|
2976
|
-
Object.defineProperty(exports, 'ShopPayButton', {
|
|
2977
|
-
enumerable: true,
|
|
2978
|
-
get: function () { return hydrogenReact.ShopPayButton; }
|
|
2979
|
-
});
|
|
2980
3012
|
Object.defineProperty(exports, 'ShopifySalesChannel', {
|
|
2981
3013
|
enumerable: true,
|
|
2982
3014
|
get: function () { return hydrogenReact.ShopifySalesChannel; }
|
|
@@ -3035,6 +3067,7 @@ exports.OptimisticInput = OptimisticInput;
|
|
|
3035
3067
|
exports.Pagination = Pagination;
|
|
3036
3068
|
exports.Script = Script;
|
|
3037
3069
|
exports.Seo = Seo;
|
|
3070
|
+
exports.ShopPayButton = ShopPayButton;
|
|
3038
3071
|
exports.StorefrontApiError = StorefrontApiError;
|
|
3039
3072
|
exports.VariantSelector = VariantSelector;
|
|
3040
3073
|
exports.cartAttributesUpdateDefault = cartAttributesUpdateDefault;
|
|
@@ -3051,6 +3084,7 @@ exports.cartMetafieldsSetDefault = cartMetafieldsSetDefault;
|
|
|
3051
3084
|
exports.cartNoteUpdateDefault = cartNoteUpdateDefault;
|
|
3052
3085
|
exports.cartSelectedDeliveryOptionsUpdateDefault = cartSelectedDeliveryOptionsUpdateDefault;
|
|
3053
3086
|
exports.cartSetIdDefault = cartSetIdDefault;
|
|
3087
|
+
exports.changelogHandler = changelogHandler;
|
|
3054
3088
|
exports.createCartHandler = createCartHandler;
|
|
3055
3089
|
exports.createContentSecurityPolicy = createContentSecurityPolicy;
|
|
3056
3090
|
exports.createCustomerClient__unstable = createCustomerClient;
|