@shopify/hydrogen 2026.10.1 → 2026.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/README.md +3 -5
- package/dist/cli/index.mjs +8 -5
- package/dist/client/client.mjs +45 -12
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/i18n-variables.d.mts +13 -0
- package/dist/client/i18n-variables.mjs +92 -0
- package/dist/client/i18n-variables.mjs.map +1 -0
- package/dist/client/types.d.mts +21 -8
- package/dist/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cart/cart.mjs +111 -24
- package/dist/core/cart/cart.mjs.map +1 -1
- package/dist/core/cart/cookie.mjs +6 -1
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +17 -5
- package/dist/core/cart/form.mjs +5 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/cart/queries.d.mts +57 -57
- package/dist/core/collection/url.mjs +8 -1
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.mjs +2 -1
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/csp/index.d.mts +56 -0
- package/dist/core/csp/index.mjs +117 -0
- package/dist/core/csp/index.mjs.map +1 -0
- package/dist/core/csp/types.d.mts +52 -0
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/i18n/define.d.mts +54 -0
- package/dist/core/i18n/define.mjs +135 -0
- package/dist/core/i18n/define.mjs.map +1 -0
- package/dist/core/i18n/errors.d.mts +18 -0
- package/dist/core/i18n/errors.mjs +24 -0
- package/dist/core/i18n/errors.mjs.map +1 -0
- package/dist/core/i18n/href.d.mts +28 -0
- package/dist/core/i18n/href.mjs +45 -0
- package/dist/core/i18n/href.mjs.map +1 -0
- package/dist/core/i18n/locale.d.mts +21 -0
- package/dist/core/i18n/locale.mjs +36 -0
- package/dist/core/i18n/locale.mjs.map +1 -0
- package/dist/core/i18n/match.d.mts +37 -0
- package/dist/core/i18n/match.mjs +82 -0
- package/dist/core/i18n/match.mjs.map +1 -0
- package/dist/core/i18n/types.d.mts +80 -0
- package/dist/core/index.d.mts +14 -5
- package/dist/core/index.mjs +9 -2
- package/dist/core/predictive-search/index.d.mts +2 -2
- package/dist/core/predictive-search/queries.d.mts +2 -2
- package/dist/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +2 -2
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/accept-variant-id.mjs +1 -1
- package/dist/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/core/request-context.d.mts +61 -35
- package/dist/core/request-context.mjs +11 -7
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +13 -2
- package/dist/core/request-routing/registered-routes.mjs +33 -9
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +18 -8
- package/dist/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +3 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +13 -11
- package/dist/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/core/shopify-scripts/index.d.mts +1 -0
- package/dist/core/shopify-scripts/index.mjs +12 -9
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/core/shopify-scripts/perfkit.mjs +8 -2
- package/dist/core/shopify-scripts/perfkit.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +4 -2
- package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/core/standard-routes/build.d.mts +7 -2
- package/dist/core/standard-routes/build.mjs +10 -3
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/match.mjs +11 -1
- package/dist/core/standard-routes/match.mjs.map +1 -1
- package/dist/core/standard-routes/path.mjs +14 -3
- package/dist/core/standard-routes/path.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +6 -1
- package/dist/core/url.mjs +5 -3
- package/dist/core/url.mjs.map +1 -1
- package/dist/core/utils/load-script.mjs +6 -6
- package/dist/core/utils/load-script.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +14 -10
- package/dist/customer-account/client.mjs +4 -5
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +7 -1
- package/dist/customer-account/graphql.mjs +6 -7
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.mjs +3 -4
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/development/client/client.mjs +45 -12
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/i18n-variables.d.mts +13 -0
- package/dist/development/client/i18n-variables.mjs +92 -0
- package/dist/development/client/i18n-variables.mjs.map +1 -0
- package/dist/development/client/types.d.mts +21 -8
- package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cart/cart.mjs +111 -24
- package/dist/development/core/cart/cart.mjs.map +1 -1
- package/dist/development/core/cart/cookie.mjs +6 -1
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +17 -5
- package/dist/development/core/cart/form.mjs +5 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/queries.d.mts +57 -57
- package/dist/development/core/collection/url.mjs +8 -1
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs +2 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/csp/index.d.mts +56 -0
- package/dist/development/core/csp/index.mjs +128 -0
- package/dist/development/core/csp/index.mjs.map +1 -0
- package/dist/development/core/csp/types.d.mts +52 -0
- package/dist/development/core/development.d.mts +14 -5
- package/dist/development/core/development.mjs +9 -2
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/i18n/define.d.mts +54 -0
- package/dist/development/core/i18n/define.mjs +135 -0
- package/dist/development/core/i18n/define.mjs.map +1 -0
- package/dist/development/core/i18n/errors.d.mts +18 -0
- package/dist/development/core/i18n/errors.mjs +24 -0
- package/dist/development/core/i18n/errors.mjs.map +1 -0
- package/dist/development/core/i18n/href.d.mts +28 -0
- package/dist/development/core/i18n/href.mjs +45 -0
- package/dist/development/core/i18n/href.mjs.map +1 -0
- package/dist/development/core/i18n/locale.d.mts +21 -0
- package/dist/development/core/i18n/locale.mjs +36 -0
- package/dist/development/core/i18n/locale.mjs.map +1 -0
- package/dist/development/core/i18n/match.d.mts +37 -0
- package/dist/development/core/i18n/match.mjs +82 -0
- package/dist/development/core/i18n/match.mjs.map +1 -0
- package/dist/development/core/i18n/types.d.mts +80 -0
- package/dist/development/core/index.d.mts +13 -4
- package/dist/development/core/predictive-search/index.d.mts +2 -2
- package/dist/development/core/predictive-search/queries.d.mts +2 -2
- package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +2 -2
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/accept-variant-id.mjs +1 -1
- package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +61 -35
- package/dist/development/core/request-context.mjs +11 -7
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +13 -2
- package/dist/development/core/request-routing/registered-routes.mjs +33 -9
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +18 -8
- package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +3 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +13 -11
- package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/development/core/shopify-scripts/index.d.mts +1 -0
- package/dist/development/core/shopify-scripts/index.mjs +12 -9
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/perfkit.mjs +8 -2
- package/dist/development/core/shopify-scripts/perfkit.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +4 -2
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/development/core/standard-routes/build.d.mts +7 -2
- package/dist/development/core/standard-routes/build.mjs +10 -3
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/match.mjs +11 -1
- package/dist/development/core/standard-routes/match.mjs.map +1 -1
- package/dist/development/core/standard-routes/path.mjs +14 -3
- package/dist/development/core/standard-routes/path.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +6 -1
- package/dist/development/core/url.mjs +5 -3
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/core/utils/load-script.mjs +6 -6
- package/dist/development/core/utils/load-script.mjs.map +1 -1
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +8 -4
- package/dist/development/graphql/type-resolver.d.mts +39 -1
- package/dist/development/react/cart.mjs +79 -25
- package/dist/development/react/cart.mjs.map +1 -1
- package/dist/development/react/index.d.mts +2 -2
- package/dist/globals.d.mts +8 -4
- package/dist/graphql/type-resolver.d.mts +39 -1
- package/dist/react/cart.mjs +79 -25
- package/dist/react/cart.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/vite/index.d.mts +11 -1
- package/dist/vite/index.mjs +21 -1
- package/dist/vite/index.mjs.map +1 -0
- package/package.json +13 -3
- package/skills/hydrogen-analytics/SKILL.md +2 -2
- package/skills/hydrogen-analytics/references/react.md +2 -2
- package/skills/hydrogen-cart-ui/SKILL.md +2 -2
- package/skills/hydrogen-markets/SKILL.md +127 -93
- package/skills/hydrogen-markets/references/nextjs.md +77 -87
- package/skills/hydrogen-oxygen/references/react-router.md +1 -2
- package/skills/hydrogen-predictive-search/SKILL.md +18 -1
- package/skills/hydrogen-request-handlers/SKILL.md +24 -6
- package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
- package/skills/hydrogen-request-handlers/references/frameworks.md +9 -12
- package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
- package/skills/hydrogen-request-handlers/references/nuxt.md +7 -7
- package/skills/hydrogen-robots-txt/SKILL.md +87 -0
- package/skills/hydrogen-routing/SKILL.md +36 -14
- package/skills/hydrogen-setup/SKILL.md +2 -2
- package/skills/hydrogen-setup/references/analytics.md +5 -5
- package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
- package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
- package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
- package/skills/hydrogen-smoke-test/SKILL.md +9 -2
- package/skills/hydrogen-storefront-client/SKILL.md +29 -9
- package/skills/hydrogen-storefront-client/references/astro.md +8 -3
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
- package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
- package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
- package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
- package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
- package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
- package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
- package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
|
@@ -217,7 +217,9 @@ function parseCollectionSortKey(searchParams) {
|
|
|
217
217
|
const rawSortBy = searchParams.get("sort_by");
|
|
218
218
|
return rawSortBy ? STANDARD_EVENTS_COLLECTION_SORT_KEY[rawSortBy] : void 0;
|
|
219
219
|
}
|
|
220
|
+
const CANONICAL_DECIMAL = /^-?\d+(\.\d+)?$/;
|
|
220
221
|
function parseLocalizedNumber(value) {
|
|
222
|
+
if (CANONICAL_DECIMAL.test(value)) return Number(value);
|
|
221
223
|
try {
|
|
222
224
|
const locale = typeof window !== "undefined" ? window.Shopify?.locale : void 0;
|
|
223
225
|
const parts = new Intl.NumberFormat(locale ?? "en").formatToParts(1234.5);
|
|
@@ -230,7 +232,12 @@ function parseLocalizedNumber(value) {
|
|
|
230
232
|
return Number(value.replace(/[^\d.]/g, "")) || 0;
|
|
231
233
|
}
|
|
232
234
|
function decodeFilterKeyPart(value) {
|
|
233
|
-
|
|
235
|
+
const spaced = value.replace(/\+/g, " ");
|
|
236
|
+
try {
|
|
237
|
+
return decodeURIComponent(spaced);
|
|
238
|
+
} catch {
|
|
239
|
+
return spaced;
|
|
240
|
+
}
|
|
234
241
|
}
|
|
235
242
|
function getFilterParamEntries(filter) {
|
|
236
243
|
const entries = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.mjs","names":[],"sources":["../../../../src/core/collection/url.ts"],"sourcesContent":["import type { ProductFilter } from \"../../../vendor/standard-events\";\nimport type { ProductCollectionSortKeys } from \"../../graphql/generated/storefront-api-types\";\nimport type { CollectionState } from \"./state\";\n\n/**\n * The filters, sort key, and sort direction in a collection URL.\n */\nexport interface CollectionParams {\n /**\n * Active product filters from the `filter.*` URL params.\n *\n * The filters use the Storefront Standard Events filter type. When your query variables use generated Storefront API types, cast the filters to the generated filter type where you pass them as variables.\n */\n filters: ProductFilter[];\n /** Storefront API sort key from the `sort_by` param, or `undefined` when the param is missing or unrecognized. */\n sortKey: ProductCollectionSortKeys | undefined;\n /** `true` when the `sort_by` value ends with `-descending`. */\n reverse: boolean;\n}\n\nconst SORT_BY_DESCENDING_SUFFIX = \"-descending\";\nconst SORT_BY_ASCENDING_SUFFIX = \"-ascending\";\nconst PAGINATION_CURSOR_PARAMS: readonly string[] = [\"before\", \"after\"];\n\nconst SORT_KEY_TO_SORT_BY: Record<string, string> = {\n BEST_SELLING: \"best-selling\",\n CREATED: \"created\",\n PRICE: \"price\",\n TITLE: \"title\",\n MANUAL: \"manual\",\n ID: \"id\",\n RELEVANCE: \"relevance\",\n COLLECTION_DEFAULT: \"collection-default\",\n};\n\nconst SORT_BY_TO_SORT_KEY: Record<string, ProductCollectionSortKeys> = Object.fromEntries(\n Object.entries(SORT_KEY_TO_SORT_BY).map(([key, value]) => [\n value,\n key as ProductCollectionSortKeys,\n ]),\n);\n\nconst STANDARD_EVENTS_COLLECTION_SORT_KEY: Record<string, ProductCollectionSortKeys> = {\n \"best-selling\": \"BEST_SELLING\",\n \"created-ascending\": \"CREATED\",\n \"created-descending\": \"CREATED\",\n \"price-ascending\": \"PRICE\",\n \"price-descending\": \"PRICE\",\n \"title-ascending\": \"TITLE\",\n \"title-descending\": \"TITLE\",\n manual: \"MANUAL\",\n};\n\n/**\n * Reads collection filters and sort from URL search params. Pass the result to your Storefront API collection query.\n *\n * The function reads Liquid-compatible `filter.p.*` and `filter.v.*` keys and the `sort_by` param.\n *\n * A URL that sets availability to both in stock and out of stock produces no availability filter. The function recognizes the best-selling and manual sort values, plus created, price, and title with an ascending or descending suffix. For other sort values, the sort key is `undefined`. The `parseSortByValue` function also recognizes relevance, collection default, and ID.\n *\n * @param searchParams - URL search params to read.\n * @returns The filters, sort key, and sort direction from the URL.\n * @publicDocs\n */\nexport function parseCollectionParams(searchParams: URLSearchParams): CollectionParams {\n const filters = parseProductFilters(searchParams);\n const sortKey = parseCollectionSortKey(searchParams);\n const rawSortBy = searchParams.get(\"sort_by\");\n const reverse = rawSortBy?.endsWith(SORT_BY_DESCENDING_SUFFIX) ?? false;\n\n return { filters, sortKey, reverse };\n}\n\n/**\n * Converts collection filters and sort to URL search params with Liquid-compatible keys. Use the result to build collection URLs.\n *\n * The result holds only the `filter.*` and `sort_by` keys. The function leaves out `sort_by` for the collection's default sort.\n *\n * Category filters convert to `filter.p.category`, which `parseCollectionParams` doesn't read. A price filter with a minimum and a maximum produces two params. To build a filter checkbox, parse a filter value's `input` string and convert the parsed filter. The resulting entries give the checkbox name and value.\n *\n * @param state - The filters, sort key, and sort direction to convert.\n * @returns URL search params that hold the filters and sort.\n * @publicDocs\n */\nexport function serializeCollectionParams(\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): URLSearchParams {\n const params = new URLSearchParams();\n\n for (const filter of state.filters) {\n serializeFilter(params, filter);\n }\n\n if (state.sortKey) {\n params.set(\"sort_by\", getSortByValue(state.sortKey, state.reverse));\n }\n\n return params;\n}\n\n/** Returns `true` when the param key is owned by the collection store. */\nfunction isStoreOwnedParam(key: string): boolean {\n return key === \"sort_by\" || key.startsWith(\"filter.\");\n}\n\n/**\n * Removes a leading `?` from a search string. Normalize search strings before you compare them.\n *\n * @param search The search string from your router, with or without a leading `?`.\n * @returns The search string without a leading `?`.\n * @publicDocs\n */\nexport function normalizeCollectionSearch(search: string): string {\n return search.startsWith(\"?\") ? search.slice(1) : search;\n}\n\n/**\n * Merges store-owned params from `state` into `existing`, preserving\n * unrelated keys (e.g. `grid`, `view`) already present in the URL. Collection\n * pagination cursors (`before`, `after`) are cleared so changed browse intent\n * starts from the first page.\n */\nexport function mergeCollectionParams(\n existing: URLSearchParams,\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): URLSearchParams {\n const merged = new URLSearchParams(existing);\n\n for (const key of Array.from(merged.keys())) {\n if (isStoreOwnedParam(key)) {\n merged.delete(key);\n }\n }\n\n clearPaginationCursors(merged);\n\n for (const [key, value] of serializeCollectionParams(state)) {\n merged.append(key, value);\n }\n\n return merged;\n}\n\n/** Returns `true` when two router search strings describe the same collection filters and sort. */\nexport function collectionSearchEqual(a: string, b: string): boolean {\n const parsedA = parseCollectionParams(new URLSearchParams(normalizeCollectionSearch(a)));\n const parsedB = parseCollectionParams(new URLSearchParams(normalizeCollectionSearch(b)));\n\n return (\n parsedA.sortKey === parsedB.sortKey &&\n parsedA.reverse === parsedB.reverse &&\n filtersEqual(parsedA.filters, parsedB.filters)\n );\n}\n\n/** Returns `true` when URL params and collection browse state describe the same filters and sort. */\nexport function collectionParamsMatchState(\n searchParams: URLSearchParams,\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): boolean {\n const parsed = parseCollectionParams(searchParams);\n\n return (\n parsed.sortKey === state.sortKey &&\n parsed.reverse === state.reverse &&\n filtersEqual(parsed.filters, state.filters)\n );\n}\n\n/**\n * Builds a query string from the current URL params, minus the given filter. Use the string in plain remove-filter links.\n *\n * The function keeps every other param and drops the `before` and `after` pagination cursors, which sends the customer to the first page of results.\n *\n * @param currentParams The current URL search params.\n * @param filter The filter to remove from the URL.\n * @returns A query string that starts with `?`. The string is `?` alone when no params remain.\n * @publicDocs\n */\nexport function getFilterRemovalUrl(currentParams: URLSearchParams, filter: ProductFilter): string {\n const result = new URLSearchParams(currentParams);\n removeFilterParams(result, filter);\n clearPaginationCursors(result);\n const serialized = result.toString();\n return serialized ? `?${serialized}` : \"?\";\n}\n\n/** Returns `true` when the sort key supports ascending/descending direction suffixes. */\nexport function isDirectionalSortKey(sortKey: ProductCollectionSortKeys): boolean {\n return sortKey === \"PRICE\" || sortKey === \"TITLE\" || sortKey === \"CREATED\" || sortKey === \"ID\";\n}\n\n/**\n * Converts a Storefront API sort key and direction to a Liquid-compatible\n * `sort_by` value, such as `price-ascending` or `best-selling`.\n *\n * Only the price, title, created, and ID sort keys get a direction suffix.\n * Other sort keys, such as best selling, ignore the direction.\n *\n * @param sortKey - Storefront API product collection sort key.\n * @param reverse - `true` for descending, `false` for ascending.\n * @returns The value for the `sort_by` URL param.\n * @publicDocs\n */\nexport function getSortByValue(sortKey: ProductCollectionSortKeys, reverse: boolean): string {\n const base = SORT_KEY_TO_SORT_BY[sortKey] ?? sortKey.toLowerCase();\n\n if (!isDirectionalSortKey(sortKey)) return base;\n\n return reverse ? `${base}-descending` : `${base}-ascending`;\n}\n\n/**\n * Converts a Liquid-compatible `sort_by` value to a Storefront API\n * sort key and direction. The `getSortByValue` function does the opposite conversion.\n *\n * For unrecognized values, the sort key is `undefined`.\n *\n * @param value - A `sort_by` value, such as `price-ascending` or `best-selling`.\n * @returns The sort key and `reverse`, which reads `true` for descending values.\n * @publicDocs\n */\nexport function parseSortByValue(value: string): {\n sortKey: ProductCollectionSortKeys | undefined;\n reverse: boolean;\n} {\n if (value.endsWith(SORT_BY_DESCENDING_SUFFIX)) {\n const base = value.slice(0, -SORT_BY_DESCENDING_SUFFIX.length);\n return { sortKey: SORT_BY_TO_SORT_KEY[base], reverse: true };\n }\n\n if (value.endsWith(SORT_BY_ASCENDING_SUFFIX)) {\n const base = value.slice(0, -SORT_BY_ASCENDING_SUFFIX.length);\n return { sortKey: SORT_BY_TO_SORT_KEY[base], reverse: false };\n }\n\n return { sortKey: SORT_BY_TO_SORT_KEY[value], reverse: false };\n}\n\n/**\n * Mirrors `parseProductFilters` from storefront-standard-events.\n *\n * Keep this local because Hydrogen only vendors Standard Events\n * declarations, so importing CollectionUpdateEvent would require runtime JS.\n */\nfunction parseProductFilters(searchParams: URLSearchParams): ProductFilter[] {\n const filters: ProductFilter[] = [];\n const price: ProductFilter[\"price\"] = {};\n const minPrice = searchParams.get(\"filter.v.price.gte\");\n const maxPrice = searchParams.get(\"filter.v.price.lte\");\n\n if (minPrice) price.min = parseLocalizedNumber(minPrice);\n if (maxPrice) price.max = parseLocalizedNumber(maxPrice);\n if (price.min !== undefined || price.max !== undefined) filters.push({ price });\n\n const availability = searchParams.getAll(\"filter.v.availability\");\n const inStock = availability.includes(\"1\");\n const outOfStock = availability.includes(\"0\");\n if (inStock && !outOfStock) filters.push({ available: true });\n if (outOfStock && !inStock) filters.push({ available: false });\n\n for (const productType of searchParams.getAll(\"filter.p.product_type\")) {\n filters.push({ productType });\n }\n\n for (const productVendor of searchParams.getAll(\"filter.p.vendor\")) {\n filters.push({ productVendor });\n }\n\n for (const tag of searchParams.getAll(\"filter.p.tag\")) {\n filters.push({ tag });\n }\n\n for (const [key, value] of searchParams) {\n let match: RegExpMatchArray | null;\n\n if ((match = key.match(/^filter\\.v\\.option\\.(.+)$/))) {\n filters.push({ variantOption: { name: decodeFilterKeyPart(match[1]), value } });\n continue;\n }\n\n if ((match = key.match(/^filter\\.p\\.m\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n productMetafield: {\n namespace: decodeFilterKeyPart(match[1]),\n key: decodeFilterKeyPart(match[2]),\n value,\n },\n });\n continue;\n }\n\n if ((match = key.match(/^filter\\.v\\.m\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n variantMetafield: {\n namespace: decodeFilterKeyPart(match[1]),\n key: decodeFilterKeyPart(match[2]),\n value,\n },\n });\n continue;\n }\n\n if ((match = key.match(/^filter\\.v\\.t\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n taxonomyMetafield: {\n key: `${decodeFilterKeyPart(match[1])}.${decodeFilterKeyPart(match[2])}`,\n value,\n },\n });\n }\n }\n\n return filters;\n}\n\n/** Mirrors `getCollectionSortKey` from storefront-standard-events. */\nfunction parseCollectionSortKey(\n searchParams: URLSearchParams,\n): ProductCollectionSortKeys | undefined {\n const rawSortBy = searchParams.get(\"sort_by\");\n return rawSortBy ? STANDARD_EVENTS_COLLECTION_SORT_KEY[rawSortBy] : undefined;\n}\n\nfunction parseLocalizedNumber(value: string): number {\n try {\n const locale = typeof window !== \"undefined\" ? window.Shopify?.locale : undefined;\n const parts = new Intl.NumberFormat(locale ?? \"en\").formatToParts(1234.5);\n const group = parts.find((part) => part.type === \"group\")?.value ?? \",\";\n const decimal = parts.find((part) => part.type === \"decimal\")?.value ?? \".\";\n const normalized = value.split(group).join(\"\").replace(decimal, \".\");\n const number = Number(normalized);\n if (!Number.isNaN(number)) return number;\n } catch {}\n\n return Number(value.replace(/[^\\d.]/g, \"\")) || 0;\n}\n\nfunction decodeFilterKeyPart(value: string): string {\n return decodeURIComponent(value.replace(/\\+/g, \" \"));\n}\n\nfunction getFilterParamEntries(filter: ProductFilter): Array<{ key: string; value: string }> {\n const entries: Array<{ key: string; value: string }> = [];\n\n if (filter.available != null) {\n entries.push({ key: \"filter.v.availability\", value: filter.available ? \"1\" : \"0\" });\n }\n\n if (filter.price) {\n if (filter.price.min != null) {\n entries.push({ key: \"filter.v.price.gte\", value: String(filter.price.min) });\n }\n if (filter.price.max != null) {\n entries.push({ key: \"filter.v.price.lte\", value: String(filter.price.max) });\n }\n }\n\n if (filter.productType != null) {\n entries.push({ key: \"filter.p.product_type\", value: filter.productType });\n }\n\n if (filter.productVendor != null) {\n entries.push({ key: \"filter.p.vendor\", value: filter.productVendor });\n }\n\n if (filter.tag != null) {\n entries.push({ key: \"filter.p.tag\", value: filter.tag });\n }\n\n if (filter.variantOption) {\n entries.push({\n key: `filter.v.option.${encodeURIComponent(filter.variantOption.name)}`,\n value: filter.variantOption.value ?? \"\",\n });\n }\n\n if (filter.productMetafield) {\n const { namespace, key, value } = filter.productMetafield;\n entries.push({\n key: `filter.p.m.${encodeURIComponent(namespace)}.${encodeURIComponent(key)}`,\n value: value ?? \"\",\n });\n }\n\n if (filter.variantMetafield) {\n const { namespace, key, value } = filter.variantMetafield;\n entries.push({\n key: `filter.v.m.${encodeURIComponent(namespace)}.${encodeURIComponent(key)}`,\n value: value ?? \"\",\n });\n }\n\n if (filter.taxonomyMetafield) {\n const fullKey = filter.taxonomyMetafield.key;\n const dotIdx = fullKey.indexOf(\".\");\n const ns = dotIdx >= 0 ? fullKey.slice(0, dotIdx) : fullKey;\n const k = dotIdx >= 0 ? fullKey.slice(dotIdx + 1) : \"\";\n entries.push({\n key: `filter.v.t.${encodeURIComponent(ns)}.${encodeURIComponent(k)}`,\n value: filter.taxonomyMetafield.value,\n });\n }\n\n if (filter.category) {\n entries.push({ key: \"filter.p.category\", value: filter.category.id });\n }\n\n return entries;\n}\n\nfunction serializeFilter(params: URLSearchParams, filter: ProductFilter): void {\n for (const { key, value } of getFilterParamEntries(filter)) {\n params.append(key, value);\n }\n}\n\nfunction removeFilterParams(params: URLSearchParams, filter: ProductFilter): void {\n for (const { key, value } of getFilterParamEntries(filter)) {\n removeParamValue(params, key, value);\n }\n}\n\nfunction clearPaginationCursors(params: URLSearchParams): void {\n for (const key of PAGINATION_CURSOR_PARAMS) {\n params.delete(key);\n }\n}\n\n/**\n * Checks whether two product filters match.\n *\n * Price filters match when the minimum and maximum are equal, including ranges that set only one bound.\n *\n * @param a The first filter to compare.\n * @param b The second filter to compare.\n * @returns `true` when both filters are the same kind with the same values. `false` for different kinds or unrecognized filters.\n * @publicDocs\n */\nexport function filterEquals(a: ProductFilter, b: ProductFilter): boolean {\n const kindA = filterKind(a);\n const kindB = filterKind(b);\n if (kindA !== kindB || kindA == null) return false;\n\n switch (kindA) {\n case \"tag\":\n return a.tag === b.tag;\n case \"available\":\n return a.available === b.available;\n case \"price\":\n return priceRangeEquals(a.price, b.price);\n case \"productType\":\n return a.productType === b.productType;\n case \"productVendor\":\n return a.productVendor === b.productVendor;\n case \"variantOption\": {\n const aOpt = a.variantOption;\n const bOpt = b.variantOption;\n if (aOpt == null || bOpt == null) return false;\n return aOpt.name === bOpt.name && (aOpt.value ?? \"\") === (bOpt.value ?? \"\");\n }\n case \"productMetafield\": {\n const aMeta = a.productMetafield;\n const bMeta = b.productMetafield;\n if (aMeta == null || bMeta == null) return false;\n return metafieldEquals(aMeta, bMeta);\n }\n case \"variantMetafield\": {\n const aMeta = a.variantMetafield;\n const bMeta = b.variantMetafield;\n if (aMeta == null || bMeta == null) return false;\n return metafieldEquals(aMeta, bMeta);\n }\n case \"taxonomyMetafield\": {\n const aMeta = a.taxonomyMetafield;\n const bMeta = b.taxonomyMetafield;\n if (aMeta == null || bMeta == null) return false;\n return aMeta.key === bMeta.key && aMeta.value === bMeta.value;\n }\n case \"category\": {\n const aCat = a.category;\n const bCat = b.category;\n if (aCat == null || bCat == null) return false;\n return aCat.id === bCat.id;\n }\n }\n}\n\n/**\n * Checks whether a filter value's `input` JSON string from the Storefront API matches an active filter. Use the result to set the checked state of a filter control.\n *\n * The function compares filters the same way as `filterEquals`.\n *\n * @param activeFilters The active filters, such as `filters` from the collection state.\n * @param input The filter value's `input` JSON string.\n * @returns `true` when the parsed input matches an active filter. `false` when the input matches no active filter or isn't valid JSON.\n * @publicDocs\n */\nexport function isFilterInputActive(activeFilters: ProductFilter[], input: string): boolean {\n let parsed: ProductFilter;\n try {\n parsed = JSON.parse(input) as ProductFilter;\n } catch {\n return false;\n }\n return activeFilters.some((filter) => filterEquals(filter, parsed));\n}\n\nfunction filterKind(\n filter: ProductFilter,\n):\n | \"tag\"\n | \"available\"\n | \"price\"\n | \"productType\"\n | \"productVendor\"\n | \"variantOption\"\n | \"productMetafield\"\n | \"variantMetafield\"\n | \"taxonomyMetafield\"\n | \"category\"\n | null {\n if (filter.tag != null) return \"tag\";\n if (filter.available != null) return \"available\";\n if (filter.price != null) return \"price\";\n if (filter.productType != null) return \"productType\";\n if (filter.productVendor != null) return \"productVendor\";\n if (filter.variantOption != null) return \"variantOption\";\n if (filter.productMetafield != null) return \"productMetafield\";\n if (filter.variantMetafield != null) return \"variantMetafield\";\n if (filter.taxonomyMetafield != null) return \"taxonomyMetafield\";\n if (filter.category != null) return \"category\";\n return null;\n}\n\nfunction priceRangeEquals(a: ProductFilter[\"price\"], b: ProductFilter[\"price\"]): boolean {\n if (a == null || b == null) return a === b;\n return a.min === b.min && a.max === b.max;\n}\n\nfunction metafieldEquals(\n a: { namespace: string; key: string; value?: string },\n b: { namespace: string; key: string; value?: string },\n): boolean {\n return a.namespace === b.namespace && a.key === b.key && (a.value ?? \"\") === (b.value ?? \"\");\n}\n\nfunction filtersEqual(a: ProductFilter[], b: ProductFilter[]): boolean {\n if (a.length !== b.length) return false;\n\n const remaining = [...b];\n for (const filter of a) {\n const index = remaining.findIndex((candidate) => filterEquals(filter, candidate));\n if (index === -1) return false;\n remaining.splice(index, 1);\n }\n\n return true;\n}\n\nfunction removeParamValue(params: URLSearchParams, name: string, value: string): void {\n const remaining = params.getAll(name).filter((v) => v !== value);\n params.delete(name);\n for (const v of remaining) {\n params.append(name, v);\n }\n}\n"],"mappings":";AAoBA,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;AACjC,MAAM,2BAA8C,CAAC,UAAU,QAAQ;AAEvE,MAAM,sBAA8C;CAClD,cAAc;CACd,SAAS;CACT,OAAO;CACP,OAAO;CACP,QAAQ;CACR,IAAI;CACJ,WAAW;CACX,oBAAoB;CACrB;AAED,MAAM,sBAAiE,OAAO,YAC5E,OAAO,QAAQ,oBAAoB,CAAC,KAAK,CAAC,KAAK,WAAW,CACxD,OACA,IACD,CAAC,CACH;AAED,MAAM,sCAAiF;CACrF,gBAAgB;CAChB,qBAAqB;CACrB,sBAAsB;CACtB,mBAAmB;CACnB,oBAAoB;CACpB,mBAAmB;CACnB,oBAAoB;CACpB,QAAQ;CACT;;;;;;;;;;;;AAaD,SAAgB,sBAAsB,cAAiD;AAMrF,QAAO;EAAE,SALO,oBAAoB,aAKpB;EAAE,SAJF,uBAAuB,aAId;EAAE,SAHT,aAAa,IAAI,UACV,EAAE,SAAS,0BAA0B,IAAI;EAE9B;;;;;;;;;;;;;AActC,SAAgB,0BACd,OACiB;CACjB,MAAM,SAAS,IAAI,iBAAiB;AAEpC,MAAK,MAAM,UAAU,MAAM,QACzB,iBAAgB,QAA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,QAAO;AACrC,KAAI,OAAO,SAAS,KAAM,QAAO;AACjC,KAAI,OAAO,eAAe,KAAM,QAAO;AACvC,KAAI,OAAO,iBAAiB,KAAM,QAAO;AACzC,KAAI,OAAO,iBAAiB,KAAM,QAAO;AACzC,KAAI,OAAO,oBAAoB,KAAM,QAAO;AAC5C,KAAI,OAAO,oBAAoB,KAAM,QAAO;AAC5C,KAAI,OAAO,qBAAqB,KAAM,QAAO;AAC7C,KAAI,OAAO,YAAY,KAAM,QAAO;AACpC,QAAO;;AAGT,SAAS,iBAAiB,GAA2B,GAAoC;AACvF,KAAI,KAAK,QAAQ,KAAK,KAAM,QAAO,MAAM;AACzC,QAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE;;AAGxC,SAAS,gBACP,GACA,GACS;AACT,QAAO,EAAE,cAAc,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,SAAS,EAAE,SAAS;;AAG3F,SAAS,aAAa,GAAoB,GAA6B;AACrE,KAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;CAElC,MAAM,YAAY,CAAC,GAAG,EAAE;AACxB,MAAK,MAAM,UAAU,GAAG;EACtB,MAAM,QAAQ,UAAU,WAAW,cAAc,aAAa,QAAQ,UAAU,CAAC;AACjF,MAAI,UAAU,GAAI,QAAO;AACzB,YAAU,OAAO,OAAO,EAAE;;AAG5B,QAAO;;AAGT,SAAS,iBAAiB,QAAyB,MAAc,OAAqB;CACpF,MAAM,YAAY,OAAO,OAAO,KAAK,CAAC,QAAQ,MAAM,MAAM,MAAM;AAChE,QAAO,OAAO,KAAK;AACnB,MAAK,MAAM,KAAK,UACd,QAAO,OAAO,MAAM,EAAE"}
|
|
1
|
+
{"version":3,"file":"url.mjs","names":[],"sources":["../../../../src/core/collection/url.ts"],"sourcesContent":["import type { ProductFilter } from \"../../../vendor/standard-events\";\nimport type { ProductCollectionSortKeys } from \"../../graphql/generated/storefront-api-types\";\nimport type { CollectionState } from \"./state\";\n\n/**\n * The filters, sort key, and sort direction in a collection URL.\n */\nexport interface CollectionParams {\n /**\n * Active product filters from the `filter.*` URL params.\n *\n * The filters use the Storefront Standard Events filter type. When your query variables use generated Storefront API types, cast the filters to the generated filter type where you pass them as variables.\n */\n filters: ProductFilter[];\n /** Storefront API sort key from the `sort_by` param, or `undefined` when the param is missing or unrecognized. */\n sortKey: ProductCollectionSortKeys | undefined;\n /** `true` when the `sort_by` value ends with `-descending`. */\n reverse: boolean;\n}\n\nconst SORT_BY_DESCENDING_SUFFIX = \"-descending\";\nconst SORT_BY_ASCENDING_SUFFIX = \"-ascending\";\nconst PAGINATION_CURSOR_PARAMS: readonly string[] = [\"before\", \"after\"];\n\nconst SORT_KEY_TO_SORT_BY: Record<string, string> = {\n BEST_SELLING: \"best-selling\",\n CREATED: \"created\",\n PRICE: \"price\",\n TITLE: \"title\",\n MANUAL: \"manual\",\n ID: \"id\",\n RELEVANCE: \"relevance\",\n COLLECTION_DEFAULT: \"collection-default\",\n};\n\nconst SORT_BY_TO_SORT_KEY: Record<string, ProductCollectionSortKeys> = Object.fromEntries(\n Object.entries(SORT_KEY_TO_SORT_BY).map(([key, value]) => [\n value,\n key as ProductCollectionSortKeys,\n ]),\n);\n\nconst STANDARD_EVENTS_COLLECTION_SORT_KEY: Record<string, ProductCollectionSortKeys> = {\n \"best-selling\": \"BEST_SELLING\",\n \"created-ascending\": \"CREATED\",\n \"created-descending\": \"CREATED\",\n \"price-ascending\": \"PRICE\",\n \"price-descending\": \"PRICE\",\n \"title-ascending\": \"TITLE\",\n \"title-descending\": \"TITLE\",\n manual: \"MANUAL\",\n};\n\n/**\n * Reads collection filters and sort from URL search params. Pass the result to your Storefront API collection query.\n *\n * The function reads Liquid-compatible `filter.p.*` and `filter.v.*` keys and the `sort_by` param.\n *\n * A URL that sets availability to both in stock and out of stock produces no availability filter. The function recognizes the best-selling and manual sort values, plus created, price, and title with an ascending or descending suffix. For other sort values, the sort key is `undefined`. The `parseSortByValue` function also recognizes relevance, collection default, and ID.\n *\n * @param searchParams - URL search params to read.\n * @returns The filters, sort key, and sort direction from the URL.\n * @publicDocs\n */\nexport function parseCollectionParams(searchParams: URLSearchParams): CollectionParams {\n const filters = parseProductFilters(searchParams);\n const sortKey = parseCollectionSortKey(searchParams);\n const rawSortBy = searchParams.get(\"sort_by\");\n const reverse = rawSortBy?.endsWith(SORT_BY_DESCENDING_SUFFIX) ?? false;\n\n return { filters, sortKey, reverse };\n}\n\n/**\n * Converts collection filters and sort to URL search params with Liquid-compatible keys. Use the result to build collection URLs.\n *\n * The result holds only the `filter.*` and `sort_by` keys. The function leaves out `sort_by` for the collection's default sort.\n *\n * Category filters convert to `filter.p.category`, which `parseCollectionParams` doesn't read. A price filter with a minimum and a maximum produces two params. To build a filter checkbox, parse a filter value's `input` string and convert the parsed filter. The resulting entries give the checkbox name and value.\n *\n * @param state - The filters, sort key, and sort direction to convert.\n * @returns URL search params that hold the filters and sort.\n * @publicDocs\n */\nexport function serializeCollectionParams(\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): URLSearchParams {\n const params = new URLSearchParams();\n\n for (const filter of state.filters) {\n serializeFilter(params, filter);\n }\n\n if (state.sortKey) {\n params.set(\"sort_by\", getSortByValue(state.sortKey, state.reverse));\n }\n\n return params;\n}\n\n/** Returns `true` when the param key is owned by the collection store. */\nfunction isStoreOwnedParam(key: string): boolean {\n return key === \"sort_by\" || key.startsWith(\"filter.\");\n}\n\n/**\n * Removes a leading `?` from a search string. Normalize search strings before you compare them.\n *\n * @param search The search string from your router, with or without a leading `?`.\n * @returns The search string without a leading `?`.\n * @publicDocs\n */\nexport function normalizeCollectionSearch(search: string): string {\n return search.startsWith(\"?\") ? search.slice(1) : search;\n}\n\n/**\n * Merges store-owned params from `state` into `existing`, preserving\n * unrelated keys (e.g. `grid`, `view`) already present in the URL. Collection\n * pagination cursors (`before`, `after`) are cleared so changed browse intent\n * starts from the first page.\n */\nexport function mergeCollectionParams(\n existing: URLSearchParams,\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): URLSearchParams {\n const merged = new URLSearchParams(existing);\n\n for (const key of Array.from(merged.keys())) {\n if (isStoreOwnedParam(key)) {\n merged.delete(key);\n }\n }\n\n clearPaginationCursors(merged);\n\n for (const [key, value] of serializeCollectionParams(state)) {\n merged.append(key, value);\n }\n\n return merged;\n}\n\n/** Returns `true` when two router search strings describe the same collection filters and sort. */\nexport function collectionSearchEqual(a: string, b: string): boolean {\n const parsedA = parseCollectionParams(new URLSearchParams(normalizeCollectionSearch(a)));\n const parsedB = parseCollectionParams(new URLSearchParams(normalizeCollectionSearch(b)));\n\n return (\n parsedA.sortKey === parsedB.sortKey &&\n parsedA.reverse === parsedB.reverse &&\n filtersEqual(parsedA.filters, parsedB.filters)\n );\n}\n\n/** Returns `true` when URL params and collection browse state describe the same filters and sort. */\nexport function collectionParamsMatchState(\n searchParams: URLSearchParams,\n state: Pick<CollectionState, \"filters\" | \"sortKey\" | \"reverse\">,\n): boolean {\n const parsed = parseCollectionParams(searchParams);\n\n return (\n parsed.sortKey === state.sortKey &&\n parsed.reverse === state.reverse &&\n filtersEqual(parsed.filters, state.filters)\n );\n}\n\n/**\n * Builds a query string from the current URL params, minus the given filter. Use the string in plain remove-filter links.\n *\n * The function keeps every other param and drops the `before` and `after` pagination cursors, which sends the customer to the first page of results.\n *\n * @param currentParams The current URL search params.\n * @param filter The filter to remove from the URL.\n * @returns A query string that starts with `?`. The string is `?` alone when no params remain.\n * @publicDocs\n */\nexport function getFilterRemovalUrl(currentParams: URLSearchParams, filter: ProductFilter): string {\n const result = new URLSearchParams(currentParams);\n removeFilterParams(result, filter);\n clearPaginationCursors(result);\n const serialized = result.toString();\n return serialized ? `?${serialized}` : \"?\";\n}\n\n/** Returns `true` when the sort key supports ascending/descending direction suffixes. */\nexport function isDirectionalSortKey(sortKey: ProductCollectionSortKeys): boolean {\n return sortKey === \"PRICE\" || sortKey === \"TITLE\" || sortKey === \"CREATED\" || sortKey === \"ID\";\n}\n\n/**\n * Converts a Storefront API sort key and direction to a Liquid-compatible\n * `sort_by` value, such as `price-ascending` or `best-selling`.\n *\n * Only the price, title, created, and ID sort keys get a direction suffix.\n * Other sort keys, such as best selling, ignore the direction.\n *\n * @param sortKey - Storefront API product collection sort key.\n * @param reverse - `true` for descending, `false` for ascending.\n * @returns The value for the `sort_by` URL param.\n * @publicDocs\n */\nexport function getSortByValue(sortKey: ProductCollectionSortKeys, reverse: boolean): string {\n const base = SORT_KEY_TO_SORT_BY[sortKey] ?? sortKey.toLowerCase();\n\n if (!isDirectionalSortKey(sortKey)) return base;\n\n return reverse ? `${base}-descending` : `${base}-ascending`;\n}\n\n/**\n * Converts a Liquid-compatible `sort_by` value to a Storefront API\n * sort key and direction. The `getSortByValue` function does the opposite conversion.\n *\n * For unrecognized values, the sort key is `undefined`.\n *\n * @param value - A `sort_by` value, such as `price-ascending` or `best-selling`.\n * @returns The sort key and `reverse`, which reads `true` for descending values.\n * @publicDocs\n */\nexport function parseSortByValue(value: string): {\n sortKey: ProductCollectionSortKeys | undefined;\n reverse: boolean;\n} {\n if (value.endsWith(SORT_BY_DESCENDING_SUFFIX)) {\n const base = value.slice(0, -SORT_BY_DESCENDING_SUFFIX.length);\n return { sortKey: SORT_BY_TO_SORT_KEY[base], reverse: true };\n }\n\n if (value.endsWith(SORT_BY_ASCENDING_SUFFIX)) {\n const base = value.slice(0, -SORT_BY_ASCENDING_SUFFIX.length);\n return { sortKey: SORT_BY_TO_SORT_KEY[base], reverse: false };\n }\n\n return { sortKey: SORT_BY_TO_SORT_KEY[value], reverse: false };\n}\n\n/**\n * Mirrors `parseProductFilters` from storefront-standard-events.\n *\n * Keep this local because Hydrogen only vendors Standard Events\n * declarations, so importing CollectionUpdateEvent would require runtime JS.\n */\nfunction parseProductFilters(searchParams: URLSearchParams): ProductFilter[] {\n const filters: ProductFilter[] = [];\n const price: ProductFilter[\"price\"] = {};\n const minPrice = searchParams.get(\"filter.v.price.gte\");\n const maxPrice = searchParams.get(\"filter.v.price.lte\");\n\n if (minPrice) price.min = parseLocalizedNumber(minPrice);\n if (maxPrice) price.max = parseLocalizedNumber(maxPrice);\n if (price.min !== undefined || price.max !== undefined) filters.push({ price });\n\n const availability = searchParams.getAll(\"filter.v.availability\");\n const inStock = availability.includes(\"1\");\n const outOfStock = availability.includes(\"0\");\n if (inStock && !outOfStock) filters.push({ available: true });\n if (outOfStock && !inStock) filters.push({ available: false });\n\n for (const productType of searchParams.getAll(\"filter.p.product_type\")) {\n filters.push({ productType });\n }\n\n for (const productVendor of searchParams.getAll(\"filter.p.vendor\")) {\n filters.push({ productVendor });\n }\n\n for (const tag of searchParams.getAll(\"filter.p.tag\")) {\n filters.push({ tag });\n }\n\n for (const [key, value] of searchParams) {\n let match: RegExpMatchArray | null;\n\n if ((match = key.match(/^filter\\.v\\.option\\.(.+)$/))) {\n filters.push({ variantOption: { name: decodeFilterKeyPart(match[1]), value } });\n continue;\n }\n\n if ((match = key.match(/^filter\\.p\\.m\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n productMetafield: {\n namespace: decodeFilterKeyPart(match[1]),\n key: decodeFilterKeyPart(match[2]),\n value,\n },\n });\n continue;\n }\n\n if ((match = key.match(/^filter\\.v\\.m\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n variantMetafield: {\n namespace: decodeFilterKeyPart(match[1]),\n key: decodeFilterKeyPart(match[2]),\n value,\n },\n });\n continue;\n }\n\n if ((match = key.match(/^filter\\.v\\.t\\.([^.]+)\\.(.+)$/))) {\n filters.push({\n taxonomyMetafield: {\n key: `${decodeFilterKeyPart(match[1])}.${decodeFilterKeyPart(match[2])}`,\n value,\n },\n });\n }\n }\n\n return filters;\n}\n\n/** Mirrors `getCollectionSortKey` from storefront-standard-events. */\nfunction parseCollectionSortKey(\n searchParams: URLSearchParams,\n): ProductCollectionSortKeys | undefined {\n const rawSortBy = searchParams.get(\"sort_by\");\n return rawSortBy ? STANDARD_EVENTS_COLLECTION_SORT_KEY[rawSortBy] : undefined;\n}\n\nconst CANONICAL_DECIMAL = /^-?\\d+(\\.\\d+)?$/;\n\nfunction parseLocalizedNumber(value: string): number {\n // Canonical decimals come from String(n) in the serializer and from\n // <input type=\"number\">, so they must survive regardless of shop locale.\n if (CANONICAL_DECIMAL.test(value)) return Number(value);\n\n try {\n const locale = typeof window !== \"undefined\" ? window.Shopify?.locale : undefined;\n const parts = new Intl.NumberFormat(locale ?? \"en\").formatToParts(1234.5);\n const group = parts.find((part) => part.type === \"group\")?.value ?? \",\";\n const decimal = parts.find((part) => part.type === \"decimal\")?.value ?? \".\";\n const normalized = value.split(group).join(\"\").replace(decimal, \".\");\n const number = Number(normalized);\n if (!Number.isNaN(number)) return number;\n } catch {}\n\n return Number(value.replace(/[^\\d.]/g, \"\")) || 0;\n}\n\nfunction decodeFilterKeyPart(value: string): string {\n const spaced = value.replace(/\\+/g, \" \");\n try {\n return decodeURIComponent(spaced);\n } catch {\n // Keep a malformed percent sequence as literal text instead of failing the request.\n return spaced;\n }\n}\n\nfunction getFilterParamEntries(filter: ProductFilter): Array<{ key: string; value: string }> {\n const entries: Array<{ key: string; value: string }> = [];\n\n if (filter.available != null) {\n entries.push({ key: \"filter.v.availability\", value: filter.available ? \"1\" : \"0\" });\n }\n\n if (filter.price) {\n if (filter.price.min != null) {\n entries.push({ key: \"filter.v.price.gte\", value: String(filter.price.min) });\n }\n if (filter.price.max != null) {\n entries.push({ key: \"filter.v.price.lte\", value: String(filter.price.max) });\n }\n }\n\n if (filter.productType != null) {\n entries.push({ key: \"filter.p.product_type\", value: filter.productType });\n }\n\n if (filter.productVendor != null) {\n entries.push({ key: \"filter.p.vendor\", value: filter.productVendor });\n }\n\n if (filter.tag != null) {\n entries.push({ key: \"filter.p.tag\", value: filter.tag });\n }\n\n if (filter.variantOption) {\n entries.push({\n key: `filter.v.option.${encodeURIComponent(filter.variantOption.name)}`,\n value: filter.variantOption.value ?? \"\",\n });\n }\n\n if (filter.productMetafield) {\n const { namespace, key, value } = filter.productMetafield;\n entries.push({\n key: `filter.p.m.${encodeURIComponent(namespace)}.${encodeURIComponent(key)}`,\n value: value ?? \"\",\n });\n }\n\n if (filter.variantMetafield) {\n const { namespace, key, value } = filter.variantMetafield;\n entries.push({\n key: `filter.v.m.${encodeURIComponent(namespace)}.${encodeURIComponent(key)}`,\n value: value ?? \"\",\n });\n }\n\n if (filter.taxonomyMetafield) {\n const fullKey = filter.taxonomyMetafield.key;\n const dotIdx = fullKey.indexOf(\".\");\n const ns = dotIdx >= 0 ? fullKey.slice(0, dotIdx) : fullKey;\n const k = dotIdx >= 0 ? fullKey.slice(dotIdx + 1) : \"\";\n entries.push({\n key: `filter.v.t.${encodeURIComponent(ns)}.${encodeURIComponent(k)}`,\n value: filter.taxonomyMetafield.value,\n });\n }\n\n if (filter.category) {\n entries.push({ key: \"filter.p.category\", value: filter.category.id });\n }\n\n return entries;\n}\n\nfunction serializeFilter(params: URLSearchParams, filter: ProductFilter): void {\n for (const { key, value } of getFilterParamEntries(filter)) {\n params.append(key, value);\n }\n}\n\nfunction removeFilterParams(params: URLSearchParams, filter: ProductFilter): void {\n for (const { key, value } of getFilterParamEntries(filter)) {\n removeParamValue(params, key, value);\n }\n}\n\nfunction clearPaginationCursors(params: URLSearchParams): void {\n for (const key of PAGINATION_CURSOR_PARAMS) {\n params.delete(key);\n }\n}\n\n/**\n * Checks whether two product filters match.\n *\n * Price filters match when the minimum and maximum are equal, including ranges that set only one bound.\n *\n * @param a The first filter to compare.\n * @param b The second filter to compare.\n * @returns `true` when both filters are the same kind with the same values. `false` for different kinds or unrecognized filters.\n * @publicDocs\n */\nexport function filterEquals(a: ProductFilter, b: ProductFilter): boolean {\n const kindA = filterKind(a);\n const kindB = filterKind(b);\n if (kindA !== kindB || kindA == null) return false;\n\n switch (kindA) {\n case \"tag\":\n return a.tag === b.tag;\n case \"available\":\n return a.available === b.available;\n case \"price\":\n return priceRangeEquals(a.price, b.price);\n case \"productType\":\n return a.productType === b.productType;\n case \"productVendor\":\n return a.productVendor === b.productVendor;\n case \"variantOption\": {\n const aOpt = a.variantOption;\n const bOpt = b.variantOption;\n if (aOpt == null || bOpt == null) return false;\n return aOpt.name === bOpt.name && (aOpt.value ?? \"\") === (bOpt.value ?? \"\");\n }\n case \"productMetafield\": {\n const aMeta = a.productMetafield;\n const bMeta = b.productMetafield;\n if (aMeta == null || bMeta == null) return false;\n return metafieldEquals(aMeta, bMeta);\n }\n case \"variantMetafield\": {\n const aMeta = a.variantMetafield;\n const bMeta = b.variantMetafield;\n if (aMeta == null || bMeta == null) return false;\n return metafieldEquals(aMeta, bMeta);\n }\n case \"taxonomyMetafield\": {\n const aMeta = a.taxonomyMetafield;\n const bMeta = b.taxonomyMetafield;\n if (aMeta == null || bMeta == null) return false;\n return aMeta.key === bMeta.key && aMeta.value === bMeta.value;\n }\n case \"category\": {\n const aCat = a.category;\n const bCat = b.category;\n if (aCat == null || bCat == null) return false;\n return aCat.id === bCat.id;\n }\n }\n}\n\n/**\n * Checks whether a filter value's `input` JSON string from the Storefront API matches an active filter. Use the result to set the checked state of a filter control.\n *\n * The function compares filters the same way as `filterEquals`.\n *\n * @param activeFilters The active filters, such as `filters` from the collection state.\n * @param input The filter value's `input` JSON string.\n * @returns `true` when the parsed input matches an active filter. `false` when the input matches no active filter or isn't valid JSON.\n * @publicDocs\n */\nexport function isFilterInputActive(activeFilters: ProductFilter[], input: string): boolean {\n let parsed: ProductFilter;\n try {\n parsed = JSON.parse(input) as ProductFilter;\n } catch {\n return false;\n }\n return activeFilters.some((filter) => filterEquals(filter, parsed));\n}\n\nfunction filterKind(\n filter: ProductFilter,\n):\n | \"tag\"\n | \"available\"\n | \"price\"\n | \"productType\"\n | \"productVendor\"\n | \"variantOption\"\n | \"productMetafield\"\n | \"variantMetafield\"\n | \"taxonomyMetafield\"\n | \"category\"\n | null {\n if (filter.tag != null) return \"tag\";\n if (filter.available != null) return \"available\";\n if (filter.price != null) return \"price\";\n if (filter.productType != null) return \"productType\";\n if (filter.productVendor != null) return \"productVendor\";\n if (filter.variantOption != null) return \"variantOption\";\n if (filter.productMetafield != null) return \"productMetafield\";\n if (filter.variantMetafield != null) return \"variantMetafield\";\n if (filter.taxonomyMetafield != null) return \"taxonomyMetafield\";\n if (filter.category != null) return \"category\";\n return null;\n}\n\nfunction priceRangeEquals(a: ProductFilter[\"price\"], b: ProductFilter[\"price\"]): boolean {\n if (a == null || b == null) return a === b;\n return a.min === b.min && a.max === b.max;\n}\n\nfunction metafieldEquals(\n a: { namespace: string; key: string; value?: string },\n b: { namespace: string; key: string; value?: string },\n): boolean {\n return a.namespace === b.namespace && a.key === b.key && (a.value ?? \"\") === (b.value ?? \"\");\n}\n\nfunction filtersEqual(a: ProductFilter[], b: ProductFilter[]): boolean {\n if (a.length !== b.length) return false;\n\n const remaining = [...b];\n for (const filter of a) {\n const index = remaining.findIndex((candidate) => filterEquals(filter, candidate));\n if (index === -1) return false;\n remaining.splice(index, 1);\n }\n\n return true;\n}\n\nfunction removeParamValue(params: URLSearchParams, name: string, value: string): void {\n const remaining = params.getAll(name).filter((v) => v !== value);\n params.delete(name);\n for (const v of remaining) {\n params.append(name, v);\n }\n}\n"],"mappings":";AAoBA,MAAM,4BAA4B;AAClC,MAAM,2BAA2B;AACjC,MAAM,2BAA8C,CAAC,UAAU,QAAQ;AAEvE,MAAM,sBAA8C;CAClD,cAAc;CACd,SAAS;CACT,OAAO;CACP,OAAO;CACP,QAAQ;CACR,IAAI;CACJ,WAAW;CACX,oBAAoB;CACrB;AAED,MAAM,sBAAiE,OAAO,YAC5E,OAAO,QAAQ,oBAAoB,CAAC,KAAK,CAAC,KAAK,WAAW,CACxD,OACA,IACD,CAAC,CACH;AAED,MAAM,sCAAiF;CACrF,gBAAgB;CAChB,qBAAqB;CACrB,sBAAsB;CACtB,mBAAmB;CACnB,oBAAoB;CACpB,mBAAmB;CACnB,oBAAoB;CACpB,QAAQ;CACT;;;;;;;;;;;;AAaD,SAAgB,sBA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AAO,EAAE;;AAG5B,QAAO;;AAGT,SAAS,iBAAiB,QAAyB,MAAc,OAAqB;CACpF,MAAM,YAAY,OAAO,OAAO,KAAK,CAAC,QAAQ,MAAM,MAAM,MAAM;AAChE,QAAO,OAAO,KAAK;AACnB,MAAK,MAAM,KAAK,UACd,QAAO,OAAO,MAAM,EAAE"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
//#region src/core/constants.ts
|
|
2
2
|
const STOREFRONT_API_VERSION = "2026-10";
|
|
3
3
|
const DEFAULT_TIMEOUT_IN_MS = 3e4;
|
|
4
|
+
const HYDROGEN_USER_AGENT = `Hydrogen 2026.10.3`;
|
|
4
5
|
|
|
5
6
|
//#endregion
|
|
6
|
-
export { DEFAULT_TIMEOUT_IN_MS, STOREFRONT_API_VERSION };
|
|
7
|
+
export { DEFAULT_TIMEOUT_IN_MS, HYDROGEN_USER_AGENT, STOREFRONT_API_VERSION };
|
|
7
8
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/core/constants.ts"],"sourcesContent":["export const STOREFRONT_API_VERSION = \"2026-10\";\n/** @publicDocs */\nexport const CUSTOMER_ACCOUNT_API_VERSION = \"2026-10\";\nexport const DEFAULT_TIMEOUT_IN_MS = 30_000;\n"],"mappings":";AAAA,MAAa,yBAAyB;AAGtC,MAAa,wBAAwB"}
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../src/core/constants.ts"],"sourcesContent":["export const STOREFRONT_API_VERSION = \"2026-10\";\n/** @publicDocs */\nexport const CUSTOMER_ACCOUNT_API_VERSION = \"2026-10\";\nexport const DEFAULT_TIMEOUT_IN_MS = 30_000;\nexport const HYDROGEN_USER_AGENT = `Hydrogen ${__HYDROGEN_VERSION__}`;\n"],"mappings":";AAAA,MAAa,yBAAyB;AAGtC,MAAa,wBAAwB;AACrC,MAAa,sBAAsB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ContentSecurityPolicy, ContentSecurityPolicyDirectives, ContentSecurityPolicyShop, CreateContentSecurityPolicyOptions } from "./types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/core/csp/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Shopify-compatible Content Security Policy for one document response. By default it
|
|
6
|
+
* generates a nonce to pass to your framework renderer and Shopify's script tags. Set `nonce` to
|
|
7
|
+
* `false` for a nonce-free policy. Styles allow inline CSS for storefront components.
|
|
8
|
+
*
|
|
9
|
+
* Call the returned policy's `applyResponseHeaders()` to send CSP and prevent caching when it
|
|
10
|
+
* has a nonce. Set the forwarded `Content-Security-Policy` request header to `header` for a
|
|
11
|
+
* renderer such as Next.js. Incoming headers never configure the policy or its nonce.
|
|
12
|
+
*
|
|
13
|
+
* Each call creates a new policy; reuse that object throughout a document's rendering. The
|
|
14
|
+
* development build allows common local HMR connection origins. Add any additional
|
|
15
|
+
* framework development-script allowances explicitly. For static documents, authorize scripts
|
|
16
|
+
* explicitly with hashes or other sources appropriate for your framework.
|
|
17
|
+
*
|
|
18
|
+
* @publicDocs
|
|
19
|
+
*/
|
|
20
|
+
declare function createContentSecurityPolicy(options?: CreateContentSecurityPolicyOptions & {
|
|
21
|
+
nonce?: undefined;
|
|
22
|
+
}): ContentSecurityPolicy<string>;
|
|
23
|
+
declare function createContentSecurityPolicy(options: CreateContentSecurityPolicyOptions & {
|
|
24
|
+
nonce: false;
|
|
25
|
+
}): ContentSecurityPolicy<undefined>;
|
|
26
|
+
declare function createContentSecurityPolicy(options?: CreateContentSecurityPolicyOptions): ContentSecurityPolicy;
|
|
27
|
+
/**
|
|
28
|
+
* Returns fresh Shopify CSP defaults for a framework's own CSP configuration. Development
|
|
29
|
+
* connections are included by the development package export. Framework configuration loaded
|
|
30
|
+
* directly by Node can select that export with `--conditions=development`.
|
|
31
|
+
* `createContentSecurityPolicy` uses these same defaults. Pass `{ hashes: true }` as the second
|
|
32
|
+
* argument to include Shopify's bootstrap hashes in scriptSrc; other inline scripts still need
|
|
33
|
+
* authorization from the framework.
|
|
34
|
+
* @publicDocs
|
|
35
|
+
*/
|
|
36
|
+
declare function getShopifyCspDirectives(shop?: ContentSecurityPolicyShop, {
|
|
37
|
+
hashes
|
|
38
|
+
}?: {
|
|
39
|
+
hashes?: boolean;
|
|
40
|
+
}): {
|
|
41
|
+
defaultSrc: string[];
|
|
42
|
+
baseUri: string[];
|
|
43
|
+
objectSrc: string[];
|
|
44
|
+
frameAncestors: string[];
|
|
45
|
+
scriptSrc: string[];
|
|
46
|
+
scriptSrcAttr: string[];
|
|
47
|
+
styleSrc: string[];
|
|
48
|
+
imgSrc: string[];
|
|
49
|
+
fontSrc: string[];
|
|
50
|
+
mediaSrc: string[];
|
|
51
|
+
frameSrc: string[];
|
|
52
|
+
connectSrc: string[];
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { createContentSecurityPolicy, getShopifyCspDirectives };
|
|
56
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { normalizeStoreDomain } from "../url.mjs";
|
|
2
|
+
import { applyPrivateResponseCacheHeaders } from "../headers.mjs";
|
|
3
|
+
import { SHOPIFY_CDN_ORIGIN, SHOPIFY_ORIGIN, SHOPIFY_SHOP_APP_ORIGIN, SHOPIFY_SHOP_COM_ORIGIN } from "../shopify-scripts/constants.mjs";
|
|
4
|
+
import { getShopifyScriptHashes } from "../shopify-scripts/hashes.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/csp/index.ts
|
|
7
|
+
function createContentSecurityPolicy(options = {}) {
|
|
8
|
+
const nonce = options.nonce === false ? void 0 : generateNonce();
|
|
9
|
+
const directives = getShopifyCspDirectives(options.shop);
|
|
10
|
+
mergeDirectives(directives, options.directives);
|
|
11
|
+
if (nonce !== void 0) {
|
|
12
|
+
directives.scriptSrc = withNonce(directives.scriptSrc, nonce);
|
|
13
|
+
if (directives.scriptSrcElem != null) directives.scriptSrcElem = withNonce(directives.scriptSrcElem, nonce);
|
|
14
|
+
}
|
|
15
|
+
const header = serializeDirectives(directives);
|
|
16
|
+
return Object.freeze({
|
|
17
|
+
nonce,
|
|
18
|
+
header,
|
|
19
|
+
applyResponseHeaders(headers) {
|
|
20
|
+
headers.set("Content-Security-Policy", header);
|
|
21
|
+
if (nonce !== void 0) applyPrivateResponseCacheHeaders(headers);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function mergeDirectives(defaults, overrides) {
|
|
26
|
+
if (overrides === void 0) return;
|
|
27
|
+
const values = defaults;
|
|
28
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
29
|
+
if (value === void 0) continue;
|
|
30
|
+
if (!DIRECTIVE_KEY.test(key)) throw new TypeError(`Invalid CSP directive: ${key}`);
|
|
31
|
+
if (Array.isArray(value) && value.some((source) => /^'nonce-/i.test(source))) throw new TypeError("CSP directives cannot contain manually supplied nonces.");
|
|
32
|
+
values[key] = mergeSources(value, values[key]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function mergeSources(value, defaults) {
|
|
36
|
+
if (!Array.isArray(value) || !Array.isArray(defaults)) return value;
|
|
37
|
+
if (defaults.length > 0 && defaults.every((source) => source.toLowerCase() === "'none'")) return [...value];
|
|
38
|
+
return [...value, ...defaults];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns fresh Shopify CSP defaults for a framework's own CSP configuration. Development
|
|
42
|
+
* connections are included by the development package export. Framework configuration loaded
|
|
43
|
+
* directly by Node can select that export with `--conditions=development`.
|
|
44
|
+
* `createContentSecurityPolicy` uses these same defaults. Pass `{ hashes: true }` as the second
|
|
45
|
+
* argument to include Shopify's bootstrap hashes in scriptSrc; other inline scripts still need
|
|
46
|
+
* authorization from the framework.
|
|
47
|
+
* @publicDocs
|
|
48
|
+
*/
|
|
49
|
+
function getShopifyCspDirectives(shop = {}, { hashes = false } = {}) {
|
|
50
|
+
const shopOrigins = [shop.storeDomain, shop.checkoutDomain || void 0].filter((domain) => domain !== void 0).map(normalizeStoreDomain);
|
|
51
|
+
return {
|
|
52
|
+
defaultSrc: ["'self'"],
|
|
53
|
+
baseUri: ["'self'"],
|
|
54
|
+
objectSrc: ["'none'"],
|
|
55
|
+
frameAncestors: ["'none'"],
|
|
56
|
+
scriptSrc: [
|
|
57
|
+
"'self'",
|
|
58
|
+
SHOPIFY_CDN_ORIGIN,
|
|
59
|
+
...hashes ? getShopifyScriptHashes() : []
|
|
60
|
+
],
|
|
61
|
+
scriptSrcAttr: ["'none'"],
|
|
62
|
+
styleSrc: [
|
|
63
|
+
"'self'",
|
|
64
|
+
"'unsafe-inline'",
|
|
65
|
+
SHOPIFY_CDN_ORIGIN
|
|
66
|
+
],
|
|
67
|
+
imgSrc: [
|
|
68
|
+
"'self'",
|
|
69
|
+
SHOPIFY_CDN_ORIGIN,
|
|
70
|
+
"data:"
|
|
71
|
+
],
|
|
72
|
+
fontSrc: ["'self'", SHOPIFY_CDN_ORIGIN],
|
|
73
|
+
mediaSrc: ["'self'", SHOPIFY_CDN_ORIGIN],
|
|
74
|
+
frameSrc: [
|
|
75
|
+
"'self'",
|
|
76
|
+
SHOPIFY_ORIGIN,
|
|
77
|
+
SHOPIFY_SHOP_APP_ORIGIN,
|
|
78
|
+
SHOPIFY_SHOP_COM_ORIGIN,
|
|
79
|
+
...shopOrigins
|
|
80
|
+
],
|
|
81
|
+
connectSrc: [
|
|
82
|
+
"'self'",
|
|
83
|
+
SHOPIFY_CDN_ORIGIN,
|
|
84
|
+
SHOPIFY_SHOP_APP_ORIGIN,
|
|
85
|
+
SHOPIFY_SHOP_COM_ORIGIN,
|
|
86
|
+
SHOPIFY_ORIGIN,
|
|
87
|
+
"https://*.shopifysvc.com",
|
|
88
|
+
...shopOrigins,
|
|
89
|
+
...[
|
|
90
|
+
"http://localhost:*",
|
|
91
|
+
"https://localhost:*",
|
|
92
|
+
"ws://localhost:*",
|
|
93
|
+
"wss://localhost:*",
|
|
94
|
+
"http://127.0.0.1:*",
|
|
95
|
+
"https://127.0.0.1:*",
|
|
96
|
+
"ws://127.0.0.1:*",
|
|
97
|
+
"wss://127.0.0.1:*",
|
|
98
|
+
"ws://*.tryhydrogen.dev:*",
|
|
99
|
+
"wss://*.tryhydrogen.dev:*"
|
|
100
|
+
]
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function generateNonce() {
|
|
105
|
+
return btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(16))));
|
|
106
|
+
}
|
|
107
|
+
function withNonce(sources, nonce) {
|
|
108
|
+
return [...sources ?? [], `'nonce-${nonce}'`];
|
|
109
|
+
}
|
|
110
|
+
const DIRECTIVE_KEY = /^[a-z]+(?:[A-Z][a-z]*)*$/;
|
|
111
|
+
function serializeDirectives(directives) {
|
|
112
|
+
return Object.entries(directives).flatMap(([key, value]) => {
|
|
113
|
+
if (value == null) return [];
|
|
114
|
+
const name = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
115
|
+
if (typeof value === "boolean") return value ? [name] : [];
|
|
116
|
+
const sources = [...new Set(value.map(validateSource))];
|
|
117
|
+
if (sources.some((source) => source.toLowerCase() === "'none'") && sources.length > 1) throw new TypeError(`CSP directive ${key} cannot combine 'none' with other sources.`);
|
|
118
|
+
return [[name, ...sources].join(" ")];
|
|
119
|
+
}).join("; ");
|
|
120
|
+
}
|
|
121
|
+
function validateSource(value) {
|
|
122
|
+
if (!value || /[^\u0021-\u007e]|[;,]/.test(value)) throw new TypeError("CSP sources must be non-empty ASCII tokens without whitespace, commas, or semicolons.");
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
export { createContentSecurityPolicy, getShopifyCspDirectives };
|
|
128
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/core/csp/index.ts"],"sourcesContent":["import { applyPrivateResponseCacheHeaders } from \"../headers\";\nimport {\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_ORIGIN,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_SHOP_COM_ORIGIN,\n} from \"../shopify-scripts/constants\";\nimport { getShopifyScriptHashes } from \"../shopify-scripts/hashes\";\nimport { normalizeStoreDomain } from \"../url\";\nimport type {\n ContentSecurityPolicy,\n ContentSecurityPolicyDirectives,\n ContentSecurityPolicyShop,\n CreateContentSecurityPolicyOptions,\n} from \"./types\";\n\nexport type {\n ContentSecurityPolicy,\n ContentSecurityPolicyDirectives,\n ContentSecurityPolicyShop,\n CreateContentSecurityPolicyOptions,\n} from \"./types\";\n\n/**\n * Creates a Shopify-compatible Content Security Policy for one document response. By default it\n * generates a nonce to pass to your framework renderer and Shopify's script tags. Set `nonce` to\n * `false` for a nonce-free policy. Styles allow inline CSS for storefront components.\n *\n * Call the returned policy's `applyResponseHeaders()` to send CSP and prevent caching when it\n * has a nonce. Set the forwarded `Content-Security-Policy` request header to `header` for a\n * renderer such as Next.js. Incoming headers never configure the policy or its nonce.\n *\n * Each call creates a new policy; reuse that object throughout a document's rendering. The\n * development build allows common local HMR connection origins. Add any additional\n * framework development-script allowances explicitly. For static documents, authorize scripts\n * explicitly with hashes or other sources appropriate for your framework.\n *\n * @publicDocs\n */\nexport function createContentSecurityPolicy(\n options?: CreateContentSecurityPolicyOptions & { nonce?: undefined },\n): ContentSecurityPolicy<string>;\nexport function createContentSecurityPolicy(\n options: CreateContentSecurityPolicyOptions & { nonce: false },\n): ContentSecurityPolicy<undefined>;\nexport function createContentSecurityPolicy(\n options?: CreateContentSecurityPolicyOptions,\n): ContentSecurityPolicy;\nexport function createContentSecurityPolicy(\n options: CreateContentSecurityPolicyOptions = {},\n): ContentSecurityPolicy {\n const nonce = options.nonce === false ? undefined : generateNonce();\n const directives: ContentSecurityPolicyDirectives = getShopifyCspDirectives(options.shop);\n mergeDirectives(directives, options.directives);\n if (nonce !== undefined) {\n directives.scriptSrc = withNonce(directives.scriptSrc, nonce);\n if (directives.scriptSrcElem != null) {\n directives.scriptSrcElem = withNonce(directives.scriptSrcElem, nonce);\n }\n }\n const header = serializeDirectives(directives);\n return Object.freeze({\n nonce,\n header,\n applyResponseHeaders(headers: Headers) {\n headers.set(\"Content-Security-Policy\", header);\n // A cached document would reuse its nonce on subsequent responses.\n if (nonce !== undefined) applyPrivateResponseCacheHeaders(headers);\n },\n });\n}\n\nfunction mergeDirectives(\n defaults: ContentSecurityPolicyDirectives,\n overrides: ContentSecurityPolicyDirectives | undefined,\n): void {\n if (overrides === undefined) return;\n const values: Record<string, unknown> = defaults;\n for (const [key, value] of Object.entries(overrides)) {\n if (value === undefined) continue;\n if (!DIRECTIVE_KEY.test(key)) throw new TypeError(`Invalid CSP directive: ${key}`);\n // Only Hydrogen generates nonces, so a nonce can't be reused across cached responses.\n if (Array.isArray(value) && value.some((source) => /^'nonce-/i.test(source))) {\n throw new TypeError(\"CSP directives cannot contain manually supplied nonces.\");\n }\n values[key] = mergeSources(value, values[key]);\n }\n}\n\nfunction mergeSources(value: unknown, defaults: unknown): unknown {\n if (!Array.isArray(value) || !Array.isArray(defaults)) return value;\n if (defaults.length > 0 && defaults.every((source) => source.toLowerCase() === \"'none'\")) {\n return [...value];\n }\n return [...value, ...defaults];\n}\n\n/**\n * Returns fresh Shopify CSP defaults for a framework's own CSP configuration. Development\n * connections are included by the development package export. Framework configuration loaded\n * directly by Node can select that export with `--conditions=development`.\n * `createContentSecurityPolicy` uses these same defaults. Pass `{ hashes: true }` as the second\n * argument to include Shopify's bootstrap hashes in scriptSrc; other inline scripts still need\n * authorization from the framework.\n * @publicDocs\n */\nexport function getShopifyCspDirectives(\n shop: ContentSecurityPolicyShop = {},\n { hashes = false }: { hashes?: boolean } = {},\n) {\n const shopOrigins = [shop.storeDomain, shop.checkoutDomain || undefined]\n .filter((domain) => domain !== undefined)\n .map(normalizeStoreDomain);\n\n return {\n defaultSrc: [\"'self'\"],\n baseUri: [\"'self'\"],\n objectSrc: [\"'none'\"],\n frameAncestors: [\"'none'\"],\n scriptSrc: [\"'self'\", SHOPIFY_CDN_ORIGIN, ...(hashes ? getShopifyScriptHashes() : [])],\n scriptSrcAttr: [\"'none'\"],\n styleSrc: [\"'self'\", \"'unsafe-inline'\", SHOPIFY_CDN_ORIGIN],\n imgSrc: [\"'self'\", SHOPIFY_CDN_ORIGIN, \"data:\"],\n fontSrc: [\"'self'\", SHOPIFY_CDN_ORIGIN],\n mediaSrc: [\"'self'\", SHOPIFY_CDN_ORIGIN],\n frameSrc: [\n \"'self'\",\n SHOPIFY_ORIGIN,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_SHOP_COM_ORIGIN,\n ...shopOrigins,\n ],\n connectSrc: [\n \"'self'\",\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_SHOP_COM_ORIGIN,\n SHOPIFY_ORIGIN,\n \"https://*.shopifysvc.com\",\n ...shopOrigins,\n ...(__DEV__\n ? [\n \"http://localhost:*\",\n \"https://localhost:*\",\n \"ws://localhost:*\",\n \"wss://localhost:*\",\n \"http://127.0.0.1:*\",\n \"https://127.0.0.1:*\",\n \"ws://127.0.0.1:*\",\n \"wss://127.0.0.1:*\",\n \"ws://*.tryhydrogen.dev:*\",\n \"wss://*.tryhydrogen.dev:*\",\n ]\n : []),\n ],\n } satisfies ContentSecurityPolicyDirectives;\n}\n\nfunction generateNonce(): string {\n return btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(16))));\n}\n\nfunction withNonce(sources: readonly string[] | null | undefined, nonce: string): string[] {\n return [...(sources ?? []), `'nonce-${nonce}'`];\n}\n\n// camelCase only, so a key can't inject another directive or reach the prototype.\nconst DIRECTIVE_KEY = /^[a-z]+(?:[A-Z][a-z]*)*$/;\n\nfunction serializeDirectives(directives: ContentSecurityPolicyDirectives): string {\n return Object.entries(directives)\n .flatMap(([key, value]) => {\n if (value == null) return [];\n const name = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n if (typeof value === \"boolean\") return value ? [name] : [];\n const sources = [...new Set(value.map(validateSource))];\n if (sources.some((source) => source.toLowerCase() === \"'none'\") && sources.length > 1) {\n throw new TypeError(`CSP directive ${key} cannot combine 'none' with other sources.`);\n }\n return [[name, ...sources].join(\" \")];\n })\n .join(\"; \");\n}\n\nfunction validateSource(value: string): string {\n if (!value || /[^\\u0021-\\u007e]|[;,]/.test(value)) {\n throw new TypeError(\n \"CSP sources must be non-empty ASCII tokens without whitespace, commas, or semicolons.\",\n );\n }\n return value;\n}\n"],"mappings":";;;;;;AAgDA,SAAgB,4BACd,UAA8C,EAAE,EACzB;CACvB,MAAM,QAAQ,QAAQ,UAAU,QAAQ,SAAY,eAAe;CACnE,MAAM,aAA8C,wBAAwB,QAAQ,KAAK;AACzF,iBAAgB,YAAY,QAAQ,WAAW;AAC/C,KAAI,UAAU,QAAW;AACvB,aAAW,YAAY,UAAU,WAAW,WAAW,MAAM;AAC7D,MAAI,WAAW,iBAAiB,KAC9B,YAAW,gBAAgB,UAAU,WAAW,eAAe,MAAM;;CAGzE,MAAM,SAAS,oBAAoB,WAAW;AAC9C,QAAO,OAAO,OAAO;EACnB;EACA;EACA,qBAAqB,SAAkB;AACrC,WAAQ,IAAI,2BAA2B,OAAO;AAE9C,OAAI,UAAU,OAAW,kCAAiC,QAAQ;;EAErE,CAAC;;AAGJ,SAAS,gBACP,UACA,WACM;AACN,KAAI,cAAc,OAAW;CAC7B,MAAM,SAAkC;AACxC,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,UAAU,EAAE;AACpD,MAAI,UAAU,OAAW;AACzB,MAAI,CAAC,cAAc,KAAK,IAAI,CAAE,OAAM,IAAI,UAAU,0BAA0B,MAAM;AAElF,MAAI,MAAM,QAAQ,MAAM,IAAI,MAAM,MAAM,WAAW,YAAY,K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C,GAAI,WAAW,EAAE,EAAG,UAAU,MAAM,GAAG;;AAIjD,MAAM,gBAAgB;AAEtB,SAAS,oBAAoB,YAAqD;AAChF,QAAO,OAAO,QAAQ,WAAW,CAC9B,SAAS,CAAC,KAAK,WAAW;AACzB,MAAI,SAAS,KAAM,QAAO,EAAE;EAC5B,MAAM,OAAO,IAAI,QAAQ,WAAW,WAAW,IAAI,OAAO,aAAa,GAAG;AAC1E,MAAI,OAAO,UAAU,UAAW,QAAO,QAAQ,CAAC,KAAK,GAAG,EAAE;EAC1D,MAAM,UAAU,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,eAAe,CAAC,CAAC;AACvD,MAAI,QAAQ,MAAM,WAAW,OAAO,aAAa,KAAK,SAAS,IAAI,QAAQ,SAAS,EAClF,OAAM,IAAI,UAAU,iBAAiB,IAAI,4CAA4C;AAEvF,SAAO,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,KAAK,IAAI,CAAC;GACrC,CACD,KAAK,KAAK;;AAGf,SAAS,eAAe,OAAuB;AAC7C,KAAI,CAAC,SAAS,wBAAwB,KAAK,MAAM,CAC/C,OAAM,IAAI,UACR,wFACD;AAEH,QAAO"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/core/csp/types.d.ts
|
|
2
|
+
type Sources = readonly string[] | null;
|
|
3
|
+
/**
|
|
4
|
+
* CSP directives. Arrays extend a directive's defaults. An array replaces a default consisting
|
|
5
|
+
* only of `'none'`; `null` omits the directive, except that nonce mode still creates a
|
|
6
|
+
* `script-src` containing the generated nonce.
|
|
7
|
+
*/
|
|
8
|
+
type ContentSecurityPolicyDirectives = {
|
|
9
|
+
defaultSrc?: Sources;
|
|
10
|
+
scriptSrc?: Sources;
|
|
11
|
+
scriptSrcElem?: Sources;
|
|
12
|
+
scriptSrcAttr?: Sources;
|
|
13
|
+
styleSrc?: Sources;
|
|
14
|
+
styleSrcElem?: Sources;
|
|
15
|
+
styleSrcAttr?: Sources;
|
|
16
|
+
imgSrc?: Sources;
|
|
17
|
+
connectSrc?: Sources;
|
|
18
|
+
fontSrc?: Sources;
|
|
19
|
+
objectSrc?: Sources;
|
|
20
|
+
mediaSrc?: Sources;
|
|
21
|
+
frameSrc?: Sources;
|
|
22
|
+
childSrc?: Sources;
|
|
23
|
+
workerSrc?: Sources;
|
|
24
|
+
manifestSrc?: Sources;
|
|
25
|
+
baseUri?: Sources;
|
|
26
|
+
formAction?: Sources;
|
|
27
|
+
frameAncestors?: Sources;
|
|
28
|
+
sandbox?: Sources;
|
|
29
|
+
reportUri?: Sources;
|
|
30
|
+
reportTo?: Sources;
|
|
31
|
+
upgradeInsecureRequests?: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** The shop's domains that browser scripts may contact. */
|
|
34
|
+
type ContentSecurityPolicyShop = {
|
|
35
|
+
storeDomain?: string;
|
|
36
|
+
checkoutDomain?: string;
|
|
37
|
+
};
|
|
38
|
+
/** Options for a per-document policy. */
|
|
39
|
+
type CreateContentSecurityPolicyOptions = {
|
|
40
|
+
shop?: ContentSecurityPolicyShop; /** Extends individual defaults. In nonce mode, the nonce is added to `script-src` and any supplied `script-src-elem`. Browsers use `script-src-elem` over `script-src` for script elements. */
|
|
41
|
+
directives?: ContentSecurityPolicyDirectives; /** Set to `false` for a nonce-free policy. This does not automatically authorize inline scripts or disable caching. */
|
|
42
|
+
nonce?: false;
|
|
43
|
+
};
|
|
44
|
+
/** A document policy with its nonce, serialized header, and response header application. */
|
|
45
|
+
type ContentSecurityPolicy<Nonce extends string | undefined = string | undefined> = {
|
|
46
|
+
readonly nonce: Nonce;
|
|
47
|
+
readonly header: string; /** Overwrites the response's enforcing CSP and prevents caching when it contains a nonce. Preserves response report-only policies. */
|
|
48
|
+
applyResponseHeaders(headers: Headers): void;
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ContentSecurityPolicy, ContentSecurityPolicyDirectives, ContentSecurityPolicyShop, CreateContentSecurityPolicyOptions };
|
|
52
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Cache, CacheOptions, CachingStrategy } from "./cache/strategies.mjs";
|
|
2
2
|
import { CacheInstance, createRunWithCache } from "./cache/run-with-cache.mjs";
|
|
3
3
|
import { ProductCollectionSortKeys } from "../graphql/generated/storefront-api-types.mjs";
|
|
4
|
+
import { ShopifyCountryCode, ShopifyDomainLocale, ShopifyI18n, ShopifyI18nRouting, ShopifyLanguageCode, ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale, ShopifySupportedLocale } from "./i18n/types.mjs";
|
|
4
5
|
import { I18nConfig, ShopifyRequestContext, ShopifyRequestContextWithBuyerIp, createShopifyRequestContext } from "./request-context.mjs";
|
|
5
6
|
import { InferResult, InferVariables } from "../graphql/type-resolver.mjs";
|
|
6
7
|
import { AnyStorefrontQueryString, StorefrontQueryString, gql } from "../graphql/graphql.mjs";
|
|
7
8
|
import { ClientType, CreateStorefrontClientArgs, GqlRestParam, GraphQLFormattedError, PrivateClientOptions, PrivateNoBuyerContextClientOptions, PrivateNoBuyerContextStorefrontClient, PrivateStorefrontClient, PublicClientOptions, PublicStorefrontClient, RequestScopedPrivateStorefrontClient, StorefrontApi, StorefrontClient, StorefrontClientOptions, StorefrontGraphql, StorefrontGraphqlOptions, StorefrontGraphqlResult } from "../client/types.mjs";
|
|
8
9
|
import { createStorefrontClient } from "../client/client.mjs";
|
|
9
10
|
import { ShopifyRouteTemplates } from "./standard-routes/types.mjs";
|
|
10
|
-
import { createShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
11
|
+
import { createShopifyRouteTemplates, defineShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
11
12
|
import { RedirectOptions, handleShopifyRedirects } from "./request-routing/handle-shopify-redirects.mjs";
|
|
13
|
+
import { defineShopifyI18n, getSupportedLocales } from "./i18n/define.mjs";
|
|
14
|
+
import { UnsupportedLocaleError } from "./i18n/errors.mjs";
|
|
15
|
+
import { GetLocalizedHrefOptions, getLocalizedHref } from "./i18n/href.mjs";
|
|
16
|
+
import { getLocalePathSegment, isSameLocale } from "./i18n/locale.mjs";
|
|
17
|
+
import { LocaleMatchSource, matchLocale, resolveSupportedLocale } from "./i18n/match.mjs";
|
|
12
18
|
import { CallableRouteHandler, ShopifyRedirectStatus, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteHandler, ShopifyRouteHandlerContext, ShopifyRouteHandlerGroup, ShopifyRouteHandlerResult, ShopifyRouteJsonResult, ShopifyRouteRedirectResult } from "./request-routing/route-types.mjs";
|
|
13
19
|
import { createShopifyRouteHandler } from "./request-routing/registered-routes.mjs";
|
|
20
|
+
import { ContentSecurityPolicy, ContentSecurityPolicyDirectives, ContentSecurityPolicyShop, CreateContentSecurityPolicyOptions } from "./csp/types.mjs";
|
|
21
|
+
import { createContentSecurityPolicy, getShopifyCspDirectives } from "./csp/index.mjs";
|
|
14
22
|
import { createFetchWithCache } from "./cache/fetch-with-cache.mjs";
|
|
15
23
|
import { StorefrontApiError, StorefrontTimeoutError } from "../client/errors.mjs";
|
|
16
24
|
import { ProductFilter } from "../vendor/standard-events.mjs";
|
|
@@ -21,7 +29,7 @@ import { AnalyticsEvent, AnalyticsEventName } from "./analytics/events.mjs";
|
|
|
21
29
|
import { ShopifyGlobal } from "../globals.mjs";
|
|
22
30
|
import { ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop } from "./shopify-scripts/types.mjs";
|
|
23
31
|
import { AnalyticsCart, AnalyticsCartLine, AnalyticsEventMap, AnalyticsTrackingValues, CartLineUpdatePayload, CartUpdatePayload, CartViewPayload, CollectionViewPayload, ConsentConfig, ConsentPreferences, ConsentSetup, OtherData, PageViewPayload, PayloadFor, ProductPayload, ProductViewPayload, SearchViewPayload, ShopAnalytics, StorefrontAnalytics, StorefrontAnalyticsConfig, StorefrontAnalyticsDestination, StorefrontAnalyticsDestinationEventContext, StorefrontAnalyticsDestinationSetupContext } from "./analytics/types.mjs";
|
|
24
|
-
import { CartFormRegister, QuantityInputAttributes, SetButtonAttributes, createCartFormRegister } from "./cart/form.mjs";
|
|
32
|
+
import { CartFormRegister, QuantityInputAttributes, RemoveButtonAttributes, SetButtonAttributes, createCartFormRegister } from "./cart/form.mjs";
|
|
25
33
|
import { attachQuantityInput } from "./cart/attach-quantity-input.mjs";
|
|
26
34
|
import { CartAction, CartAttributeInput, CartLineAddInput, CartLineUpdateInput, parseCartRequest } from "./cart/actions.mjs";
|
|
27
35
|
import { cartQueries } from "./cart/queries.mjs";
|
|
@@ -29,6 +37,7 @@ import { createCartCookie } from "./cart/cookie.mjs";
|
|
|
29
37
|
import { CartDataFromQuery, CartResult, getCart, getCartId } from "./cart/get-cart.mjs";
|
|
30
38
|
import { CartDataFromHandlers, CartError, CartErrorCode, CartGetData, CartGetHandler, CartGetResult, CartPostHandler, CartPostResult, CartServerHandlers, CartServerHandlersWithCustomerSession, CreateCartServerHandlersOptions, createCartServerHandlers } from "./cart/server-handlers.mjs";
|
|
31
39
|
import { DEFAULT_MINIMUM_QUANTITY, NO_QUANTITY_LIMIT, sanitizeQuantity } from "./cart/quantity.mjs";
|
|
40
|
+
import { getShopifyScriptHashes } from "./shopify-scripts/hashes.mjs";
|
|
32
41
|
import { initializeShopifyScripts } from "./shopify-scripts/initialize.mjs";
|
|
33
42
|
import { getShopifyScriptTags, renderShopifyScriptTags } from "./shopify-scripts/index.mjs";
|
|
34
43
|
import { AvailableFilter, AvailableFilterValue, CollectionState, FilterPresentation, FilterType, createInitialCollectionState } from "./collection/state.mjs";
|
|
@@ -44,13 +53,13 @@ import { SHOP_PAY_BUTTON_TAG_NAME, ShopPayButtonOptions, createShopPayButton, de
|
|
|
44
53
|
import { PredictiveSearchFormAttributes, PredictiveSearchFormRegister, PredictiveSearchQueryInputAttributes, createPredictiveSearchFormRegister, getPredictiveSearchFormAttributes, readPredictiveSearchFormTerm } from "./predictive-search/form.mjs";
|
|
45
54
|
import { CreatePredictiveSearchQueriesOptions, PredictiveSearchFragments, makePredictiveSearchQueries } from "./predictive-search/queries.mjs";
|
|
46
55
|
import { PredictiveSearchData, QueryPredictiveSearchOptions, queryPredictiveSearch } from "./predictive-search/search.mjs";
|
|
47
|
-
import { CreatePredictiveSearchServerHandlersOptions, createPredictiveSearchServerHandlers } from "./predictive-search/server-handlers.mjs";
|
|
56
|
+
import { CreatePredictiveSearchServerHandlersOptions, PredictiveSearchDataFromHandlers, createPredictiveSearchServerHandlers } from "./predictive-search/server-handlers.mjs";
|
|
48
57
|
import { CreatePredictiveSearchStoreOptions, PredictiveSearchActions, PredictiveSearchState, PredictiveSearchStatus, PredictiveSearchStore, createPredictiveSearchStore } from "./predictive-search/store.mjs";
|
|
49
|
-
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, getPredictiveSearchItemUrl, getSearchResultUrl } from "./predictive-search/url.mjs";
|
|
58
|
+
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, SearchResultUrlOptions, getPredictiveSearchItemUrl, getSearchResultUrl } from "./predictive-search/url.mjs";
|
|
50
59
|
import { FormatMoneyOptions, FormattedMoney, FormattedMoneyRange, MoneyV2 } from "./money/types.mjs";
|
|
51
60
|
import { formatMoney } from "./money/format.mjs";
|
|
52
61
|
import { flattenConnection } from "./analytics/utils/flatten-connection.mjs";
|
|
53
62
|
import { HydrogenLogger, LogContext, LogLevel } from "./logging/types.mjs";
|
|
54
63
|
import { ConfigureLoggingOptions, configureLogging } from "./logging/logging.mjs";
|
|
55
64
|
import { handleShopifyRoutesDev } from "./request-routing/handle-shopify-routes.development.mjs";
|
|
56
|
-
export { AnalyticsCart, AnalyticsCartLine, AnalyticsEvent, AnalyticsEventMap, AnalyticsEventName, AnalyticsTrackingValues, AnyStorefrontQueryString, Attribute, AvailableFilter, AvailableFilterValue, Cache, CacheInstance, CacheOptions, CachingStrategy, CallableRouteHandler, CartAction, CartActions, CartAttributeInput, CartCost, CartData, CartDataFromHandlers, CartDataFromQuery, CartError, CartErrorCode, CartErrorGroup, CartErrorState, CartFormRegister, CartGetData, CartGetHandler, CartGetResult, CartLine, CartLineAddInput, CartLineConnection, CartLineCost, CartLineMerchandise, CartLineUpdateInput, CartLineUpdatePayload, CartNetworkEntry, CartNetworkError, CartPending, CartPostHandler, CartPostResult, CartResult, CartServerHandlers, CartServerHandlersWithCustomerSession, CartState, CartStore, CartUpdatePayload, CartUserError, CartViewPayload, CartWarning, ClientType, CollectionActions, CollectionData, CollectionParams, CollectionReconciler, CollectionState, CollectionStore, CollectionViewPayload, ConfigureLoggingOptions, ConsentConfig, ConsentPreferences, ConsentSetup, CreateCartServerHandlersOptions, CreateCartStoreOptions, CreateCollectionStoreOptions, CreatePredictiveSearchQueriesOptions, CreatePredictiveSearchServerHandlersOptions, CreatePredictiveSearchStoreOptions, CreateProductFormStoreOptions, CreateStorefrontClientArgs, DEFAULT_MINIMUM_QUANTITY, DiscountCode, EMPTY_CART_DATA, EMPTY_CART_STATE, FilterPresentation, FilterType, FormatMoneyOptions, FormattedMoney, FormattedMoneyRange, GqlRestParam, GraphQLFormattedError, HydrogenLogger, I18nConfig, InferResult, InferVariables, LogContext, LogLevel, MoneyV2, NO_QUANTITY_LIMIT, OtherData, PageViewPayload, PayloadFor, PredictiveSearchActions, PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchData, PredictiveSearchFormAttributes, PredictiveSearchFormRegister, PredictiveSearchFragments, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryInputAttributes, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, PredictiveSearchState, PredictiveSearchStatus, PredictiveSearchStore, PrivateClientOptions, PrivateNoBuyerContextClientOptions, PrivateNoBuyerContextStorefrontClient, PrivateStorefrontClient, ProductAddToCartProps, ProductCollectionSortKeys, ProductFilter, ProductFormErrors, ProductFormOptions, ProductFormRegister, ProductFormStore, ProductFormStoreState, ProductInput, ProductMerchandiseIdProps, ProductOptionInput, ProductOptionValueInput, ProductOptionValueProps, ProductPayload, ProductQuantityDefaultProps, ProductQuantityProps, ProductSelectionLinkStyle, ProductVariantFrom, ProductVariantInput, ProductViewPayload, PublicClientOptions, PublicStorefrontClient, QuantityInputAttributes, QueryPredictiveSearchOptions, ReconcilerCallbacks, RedirectOptions, RequestScopedPrivateStorefrontClient, SHOP_PAY_BUTTON_TAG_NAME, STANDARD_ACTION_TIMEOUT_IN_MS, SearchViewPayload, SelectedOption, SetButtonAttributes, ShopAnalytics, ShopPayButtonOptions, ShopifyGlobal, ShopifyRedirectStatus, ShopifyRequestContext, ShopifyRequestContextWithBuyerIp, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteHandler, ShopifyRouteHandlerContext, ShopifyRouteHandlerGroup, ShopifyRouteHandlerResult, ShopifyRouteJsonResult, ShopifyRouteRedirectResult, ShopifyRouteTemplates, ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop, StorefrontAnalytics, StorefrontAnalyticsConfig, StorefrontAnalyticsDestination, StorefrontAnalyticsDestinationEventContext, StorefrontAnalyticsDestinationSetupContext, StorefrontApi, StorefrontApiError, StorefrontClient, StorefrontClientOptions, StorefrontGraphql, StorefrontGraphqlOptions, StorefrontGraphqlResult, StorefrontQueryString, StorefrontTimeoutError, ValidProductSelectionResult, VariantOptionState, VariantOptionValueState, VariantSelectionResult, attachQuantityInput, buildProductSelectionSearchParams, canAddToCart, cartQueries, configureCartEndpoint, configureLogging, createCartCookie, createCartFormRegister, createCartServerHandlers, createCartStore, createCollectionReconciler, createCollectionStore, createEmptyCartErrors, createEmptyErrorGroup, createFetchWithCache, createInitialCollectionState, createPredictiveSearchFormRegister, createPredictiveSearchServerHandlers, createPredictiveSearchStore, createProductFormRegister, createProductFormStore, createRunWithCache, createShopPayButton, createShopifyRequestContext, createShopifyRouteHandler, createShopifyRouteTemplates, createStorefrontClient, defineShopPayButton, filterEquals, findCartLineByMerchandiseId, flattenConnection, formatMoney, getCart, getCartId, getFilterRemovalUrl, getPredictiveSearchFormAttributes, getPredictiveSearchItemUrl, getSearchResultUrl, getSelectedProductOptions, getSelectedVariant, getShopPayButtonUrl, getShopifyScriptTags, getSortByValue, gql, handleShopifyRedirects, handleShopifyRoutesDev as handleShopifyRoutes, initializeShopifyScripts, isFilterInputActive, makePredictiveSearchQueries, normalizeCollectionSearch, parseCartRequest, parseCollectionParams, parseSortByValue, queryPredictiveSearch, readPredictiveSearchFormTerm, renderShopPayButton, renderShopifyScriptTags, sanitizeQuantity, serializeCollectionParams, trackCartAnalytics };
|
|
65
|
+
export { AnalyticsCart, AnalyticsCartLine, AnalyticsEvent, AnalyticsEventMap, AnalyticsEventName, AnalyticsTrackingValues, AnyStorefrontQueryString, Attribute, AvailableFilter, AvailableFilterValue, Cache, CacheInstance, CacheOptions, CachingStrategy, CallableRouteHandler, CartAction, CartActions, CartAttributeInput, CartCost, CartData, CartDataFromHandlers, CartDataFromQuery, CartError, CartErrorCode, CartErrorGroup, CartErrorState, CartFormRegister, CartGetData, CartGetHandler, CartGetResult, CartLine, CartLineAddInput, CartLineConnection, CartLineCost, CartLineMerchandise, CartLineUpdateInput, CartLineUpdatePayload, CartNetworkEntry, CartNetworkError, CartPending, CartPostHandler, CartPostResult, CartResult, CartServerHandlers, CartServerHandlersWithCustomerSession, CartState, CartStore, CartUpdatePayload, CartUserError, CartViewPayload, CartWarning, ClientType, CollectionActions, CollectionData, CollectionParams, CollectionReconciler, CollectionState, CollectionStore, CollectionViewPayload, ConfigureLoggingOptions, ConsentConfig, ConsentPreferences, ConsentSetup, ContentSecurityPolicy, ContentSecurityPolicyDirectives, ContentSecurityPolicyShop, CreateCartServerHandlersOptions, CreateCartStoreOptions, CreateCollectionStoreOptions, CreateContentSecurityPolicyOptions, CreatePredictiveSearchQueriesOptions, CreatePredictiveSearchServerHandlersOptions, CreatePredictiveSearchStoreOptions, CreateProductFormStoreOptions, CreateStorefrontClientArgs, DEFAULT_MINIMUM_QUANTITY, DiscountCode, EMPTY_CART_DATA, EMPTY_CART_STATE, FilterPresentation, FilterType, FormatMoneyOptions, FormattedMoney, FormattedMoneyRange, GetLocalizedHrefOptions, GqlRestParam, GraphQLFormattedError, HydrogenLogger, I18nConfig, InferResult, InferVariables, LocaleMatchSource, LogContext, LogLevel, MoneyV2, NO_QUANTITY_LIMIT, OtherData, PageViewPayload, PayloadFor, PredictiveSearchActions, PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchData, PredictiveSearchDataFromHandlers, PredictiveSearchFormAttributes, PredictiveSearchFormRegister, PredictiveSearchFragments, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryInputAttributes, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, PredictiveSearchState, PredictiveSearchStatus, PredictiveSearchStore, PrivateClientOptions, PrivateNoBuyerContextClientOptions, PrivateNoBuyerContextStorefrontClient, PrivateStorefrontClient, ProductAddToCartProps, ProductCollectionSortKeys, ProductFilter, ProductFormErrors, ProductFormOptions, ProductFormRegister, ProductFormStore, ProductFormStoreState, ProductInput, ProductMerchandiseIdProps, ProductOptionInput, ProductOptionValueInput, ProductOptionValueProps, ProductPayload, ProductQuantityDefaultProps, ProductQuantityProps, ProductSelectionLinkStyle, ProductVariantFrom, ProductVariantInput, ProductViewPayload, PublicClientOptions, PublicStorefrontClient, QuantityInputAttributes, QueryPredictiveSearchOptions, ReconcilerCallbacks, RedirectOptions, RemoveButtonAttributes, RequestScopedPrivateStorefrontClient, SHOP_PAY_BUTTON_TAG_NAME, STANDARD_ACTION_TIMEOUT_IN_MS, SearchResultUrlOptions, SearchViewPayload, SelectedOption, SetButtonAttributes, ShopAnalytics, ShopPayButtonOptions, ShopifyCountryCode, ShopifyDomainLocale, ShopifyGlobal, ShopifyI18n, ShopifyI18nRouting, ShopifyLanguageCode, ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale, ShopifyRedirectStatus, ShopifyRequestContext, ShopifyRequestContextWithBuyerIp, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteHandler, ShopifyRouteHandlerContext, ShopifyRouteHandlerGroup, ShopifyRouteHandlerResult, ShopifyRouteJsonResult, ShopifyRouteRedirectResult, ShopifyRouteTemplates, ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop, ShopifySupportedLocale, StorefrontAnalytics, StorefrontAnalyticsConfig, StorefrontAnalyticsDestination, StorefrontAnalyticsDestinationEventContext, StorefrontAnalyticsDestinationSetupContext, StorefrontApi, StorefrontApiError, StorefrontClient, StorefrontClientOptions, StorefrontGraphql, StorefrontGraphqlOptions, StorefrontGraphqlResult, StorefrontQueryString, StorefrontTimeoutError, UnsupportedLocaleError, ValidProductSelectionResult, VariantOptionState, VariantOptionValueState, VariantSelectionResult, attachQuantityInput, buildProductSelectionSearchParams, canAddToCart, cartQueries, configureCartEndpoint, configureLogging, createCartCookie, createCartFormRegister, createCartServerHandlers, createCartStore, createCollectionReconciler, createCollectionStore, createContentSecurityPolicy, createEmptyCartErrors, createEmptyErrorGroup, createFetchWithCache, createInitialCollectionState, createPredictiveSearchFormRegister, createPredictiveSearchServerHandlers, createPredictiveSearchStore, createProductFormRegister, createProductFormStore, createRunWithCache, createShopPayButton, createShopifyRequestContext, createShopifyRouteHandler, createShopifyRouteTemplates, createStorefrontClient, defineShopPayButton, defineShopifyI18n, defineShopifyRouteTemplates, filterEquals, findCartLineByMerchandiseId, flattenConnection, formatMoney, getCart, getCartId, getFilterRemovalUrl, getLocalePathSegment, getLocalizedHref, getPredictiveSearchFormAttributes, getPredictiveSearchItemUrl, getSearchResultUrl, getSelectedProductOptions, getSelectedVariant, getShopPayButtonUrl, getShopifyCspDirectives, getShopifyScriptHashes, getShopifyScriptTags, getSortByValue, getSupportedLocales, gql, handleShopifyRedirects, handleShopifyRoutesDev as handleShopifyRoutes, initializeShopifyScripts, isFilterInputActive, isSameLocale, makePredictiveSearchQueries, matchLocale, normalizeCollectionSearch, parseCartRequest, parseCollectionParams, parseSortByValue, queryPredictiveSearch, readPredictiveSearchFormTerm, renderShopPayButton, renderShopifyScriptTags, resolveSupportedLocale, sanitizeQuantity, serializeCollectionParams, trackCartAnalytics };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { createShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
1
|
+
import { createShopifyRouteTemplates, defineShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
2
|
+
import { getLocalePathSegment, isSameLocale } from "./i18n/locale.mjs";
|
|
3
|
+
import { defineShopifyI18n, getSupportedLocales } from "./i18n/define.mjs";
|
|
4
|
+
import { UnsupportedLocaleError } from "./i18n/errors.mjs";
|
|
5
|
+
import { matchLocale, resolveSupportedLocale } from "./i18n/match.mjs";
|
|
6
|
+
import { getLocalizedHref } from "./i18n/href.mjs";
|
|
2
7
|
import { configureLogging } from "./logging/logging.mjs";
|
|
3
8
|
import { gql } from "../graphql/graphql.mjs";
|
|
4
9
|
import { handleShopifyRedirects } from "./request-routing/handle-shopify-redirects.mjs";
|
|
@@ -13,6 +18,8 @@ import { cartQueries } from "./cart/queries.mjs";
|
|
|
13
18
|
import { getCart, getCartId } from "./cart/get-cart.mjs";
|
|
14
19
|
import { createShopifyRouteHandler } from "./request-routing/registered-routes.mjs";
|
|
15
20
|
import { createShopifyRequestContext } from "./request-context.mjs";
|
|
21
|
+
import { getShopifyScriptHashes } from "./shopify-scripts/hashes.mjs";
|
|
22
|
+
import { createContentSecurityPolicy, getShopifyCspDirectives } from "./csp/index.mjs";
|
|
16
23
|
import { AnalyticsEvent } from "./analytics/events.mjs";
|
|
17
24
|
import { flattenConnection } from "./analytics/utils/flatten-connection.mjs";
|
|
18
25
|
import { trackCartAnalytics } from "./analytics/cart-tracker.mjs";
|
|
@@ -42,4 +49,4 @@ import { getPredictiveSearchItemUrl, getSearchResultUrl } from "./predictive-sea
|
|
|
42
49
|
import { formatMoney } from "./money/format.mjs";
|
|
43
50
|
import { handleShopifyRoutesDev } from "./request-routing/handle-shopify-routes.development.mjs";
|
|
44
51
|
|
|
45
|
-
export { AnalyticsEvent, Cache, CartNetworkError, DEFAULT_MINIMUM_QUANTITY, EMPTY_CART_DATA, EMPTY_CART_STATE, NO_QUANTITY_LIMIT, SHOP_PAY_BUTTON_TAG_NAME, STANDARD_ACTION_TIMEOUT_IN_MS, StorefrontApiError, StorefrontTimeoutError, attachQuantityInput, buildProductSelectionSearchParams, canAddToCart, cartQueries, configureCartEndpoint, configureLogging, createCartCookie, createCartFormRegister, createCartServerHandlers, createCartStore, createCollectionReconciler, createCollectionStore, createEmptyCartErrors, createEmptyErrorGroup, createFetchWithCache, createInitialCollectionState, createPredictiveSearchFormRegister, createPredictiveSearchServerHandlers, createPredictiveSearchStore, createProductFormRegister, createProductFormStore, createRunWithCache, createShopPayButton, createShopifyRequestContext, createShopifyRouteHandler, createShopifyRouteTemplates, createStorefrontClient, defineShopPayButton, filterEquals, findCartLineByMerchandiseId, flattenConnection, formatMoney, getCart, getCartId, getFilterRemovalUrl, getPredictiveSearchFormAttributes, getPredictiveSearchItemUrl, getSearchResultUrl, getSelectedProductOptions, getSelectedVariant, getShopPayButtonUrl, getShopifyScriptTags, getSortByValue, gql, handleShopifyRedirects, handleShopifyRoutesDev as handleShopifyRoutes, initializeShopifyScripts, isFilterInputActive, makePredictiveSearchQueries, normalizeCollectionSearch, parseCartRequest, parseCollectionParams, parseSortByValue, queryPredictiveSearch, readPredictiveSearchFormTerm, renderShopPayButton, renderShopifyScriptTags, sanitizeQuantity, serializeCollectionParams, trackCartAnalytics };
|
|
52
|
+
export { AnalyticsEvent, Cache, CartNetworkError, DEFAULT_MINIMUM_QUANTITY, EMPTY_CART_DATA, EMPTY_CART_STATE, NO_QUANTITY_LIMIT, SHOP_PAY_BUTTON_TAG_NAME, STANDARD_ACTION_TIMEOUT_IN_MS, StorefrontApiError, StorefrontTimeoutError, UnsupportedLocaleError, attachQuantityInput, buildProductSelectionSearchParams, canAddToCart, cartQueries, configureCartEndpoint, configureLogging, createCartCookie, createCartFormRegister, createCartServerHandlers, createCartStore, createCollectionReconciler, createCollectionStore, createContentSecurityPolicy, createEmptyCartErrors, createEmptyErrorGroup, createFetchWithCache, createInitialCollectionState, createPredictiveSearchFormRegister, createPredictiveSearchServerHandlers, createPredictiveSearchStore, createProductFormRegister, createProductFormStore, createRunWithCache, createShopPayButton, createShopifyRequestContext, createShopifyRouteHandler, createShopifyRouteTemplates, createStorefrontClient, defineShopPayButton, defineShopifyI18n, defineShopifyRouteTemplates, filterEquals, findCartLineByMerchandiseId, flattenConnection, formatMoney, getCart, getCartId, getFilterRemovalUrl, getLocalePathSegment, getLocalizedHref, getPredictiveSearchFormAttributes, getPredictiveSearchItemUrl, getSearchResultUrl, getSelectedProductOptions, getSelectedVariant, getShopPayButtonUrl, getShopifyCspDirectives, getShopifyScriptHashes, getShopifyScriptTags, getSortByValue, getSupportedLocales, gql, handleShopifyRedirects, handleShopifyRoutesDev as handleShopifyRoutes, initializeShopifyScripts, isFilterInputActive, isSameLocale, makePredictiveSearchQueries, matchLocale, normalizeCollectionSearch, parseCartRequest, parseCollectionParams, parseSortByValue, queryPredictiveSearch, readPredictiveSearchFormTerm, renderShopPayButton, renderShopifyScriptTags, resolveSupportedLocale, sanitizeQuantity, serializeCollectionParams, trackCartAnalytics };
|
|
@@ -30,13 +30,13 @@ function extractHeaders(getter, allowlist) {
|
|
|
30
30
|
}
|
|
31
31
|
function applyPrivateResponseCacheHeaders(headers) {
|
|
32
32
|
headers.set(CACHE_CONTROL_HEADER, "private, no-store, max-age=0, must-revalidate");
|
|
33
|
-
for (const header of Array.from(headers.keys())) if (
|
|
33
|
+
for (const header of Array.from(headers.keys())) if (/^.+-cache-control$/i.test(header) || header.toLowerCase() === "Surrogate-Control".toLowerCase()) headers.delete(header);
|
|
34
34
|
}
|
|
35
35
|
const COMMON_PROXY_HEADER_ALLOWLIST = defineHeaderList("accept", "accept-encoding", "accept-language", "content-type", "cookie", "origin", "referer", "user-agent");
|
|
36
36
|
const SFAPI_REQUEST_HEADER_ALLOWLIST = defineHeaderList(...COMMON_PROXY_HEADER_ALLOWLIST, "content-length", "access-control-request-headers", "access-control-request-method", STOREFRONT_ACCESS_TOKEN_HEADER, STOREFRONT_PRIVATE_TOKEN_HEADER, SHOPIFY_UNIQUE_TOKEN_HEADER, SHOPIFY_VISIT_TOKEN_HEADER);
|
|
37
37
|
const MCP_REQUEST_HEADER_ALLOWLIST = defineHeaderList(...COMMON_PROXY_HEADER_ALLOWLIST);
|
|
38
38
|
const AJAX_API_REQUEST_HEADER_ALLOWLIST = defineHeaderList(...COMMON_PROXY_HEADER_ALLOWLIST, "content-length", "x-requested-with");
|
|
39
|
-
const PROXY_REQUEST_HEADER_DENYLIST = defineHeaderList("cf-connecting-ip", "connection", "content-length", "host", "keep-alive", "proxy-authenticate", "proxy-authorization", "te", "trailer", "transfer-encoding", "upgrade");
|
|
39
|
+
const PROXY_REQUEST_HEADER_DENYLIST = defineHeaderList("cf-connecting-ip", "connection", "content-length", "forwarded", "host", "keep-alive", "oxygen-buyer-ip", "proxy-authenticate", "proxy-authorization", STOREFRONT_BUYER_IP_HEADER, "te", "trailer", "transfer-encoding", "true-client-ip", "upgrade", "x-client-ip", "x-forwarded-for", "x-forwarded-host", "x-forwarded-port", "x-forwarded-proto", "x-forwarded-scheme", "x-forwarded-ssl", "x-real-ip", "x-shopify-client-ip");
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
42
42
|
export { AJAX_API_REQUEST_HEADER_ALLOWLIST, CONSENT_MANAGEMENT_HEADER, HYDROGEN_VERSION_HEADER, MCP_REQUEST_HEADER_ALLOWLIST, PROXY_REQUEST_HEADER_DENYLIST, REQUEST_GROUP_ID_HEADER, SDK_VARIANT_HEADER, SDK_VARIANT_SOURCE_HEADER, SDK_VERSION_HEADER, SEC_GPC_HEADER, SFAPI_REQUEST_HEADER_ALLOWLIST, SHOPIFY_STOREFRONT_ORIGIN_HEADER, SHOPIFY_STOREFRONT_S_HEADER, SHOPIFY_STOREFRONT_Y_HEADER, SHOPIFY_UNIQUE_TOKEN_HEADER, SHOPIFY_VISIT_TOKEN_HEADER, STOREFRONT_ACCESS_TOKEN_HEADER, STOREFRONT_BUYER_IP_HEADER, STOREFRONT_ID_HEADER, STOREFRONT_PRIVATE_TOKEN_HEADER, STOREFRONT_URL_HEADER, applyPrivateResponseCacheHeaders, extractHeaders };
|