@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.
Files changed (265) hide show
  1. package/README.md +3 -5
  2. package/dist/cli/index.mjs +8 -5
  3. package/dist/client/client.mjs +45 -12
  4. package/dist/client/client.mjs.map +1 -1
  5. package/dist/client/i18n-variables.d.mts +13 -0
  6. package/dist/client/i18n-variables.mjs +92 -0
  7. package/dist/client/i18n-variables.mjs.map +1 -0
  8. package/dist/client/types.d.mts +21 -8
  9. package/dist/core/cache/fetch-with-cache.mjs +8 -1
  10. package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
  11. package/dist/core/cart/cart.mjs +111 -24
  12. package/dist/core/cart/cart.mjs.map +1 -1
  13. package/dist/core/cart/cookie.mjs +6 -1
  14. package/dist/core/cart/cookie.mjs.map +1 -1
  15. package/dist/core/cart/form.d.mts +17 -5
  16. package/dist/core/cart/form.mjs +5 -0
  17. package/dist/core/cart/form.mjs.map +1 -1
  18. package/dist/core/cart/index.d.mts +1 -1
  19. package/dist/core/cart/queries.d.mts +57 -57
  20. package/dist/core/collection/url.mjs +8 -1
  21. package/dist/core/collection/url.mjs.map +1 -1
  22. package/dist/core/constants.mjs +2 -1
  23. package/dist/core/constants.mjs.map +1 -1
  24. package/dist/core/csp/index.d.mts +56 -0
  25. package/dist/core/csp/index.mjs +117 -0
  26. package/dist/core/csp/index.mjs.map +1 -0
  27. package/dist/core/csp/types.d.mts +52 -0
  28. package/dist/core/headers.mjs +2 -2
  29. package/dist/core/headers.mjs.map +1 -1
  30. package/dist/core/i18n/define.d.mts +54 -0
  31. package/dist/core/i18n/define.mjs +135 -0
  32. package/dist/core/i18n/define.mjs.map +1 -0
  33. package/dist/core/i18n/errors.d.mts +18 -0
  34. package/dist/core/i18n/errors.mjs +24 -0
  35. package/dist/core/i18n/errors.mjs.map +1 -0
  36. package/dist/core/i18n/href.d.mts +28 -0
  37. package/dist/core/i18n/href.mjs +45 -0
  38. package/dist/core/i18n/href.mjs.map +1 -0
  39. package/dist/core/i18n/locale.d.mts +21 -0
  40. package/dist/core/i18n/locale.mjs +36 -0
  41. package/dist/core/i18n/locale.mjs.map +1 -0
  42. package/dist/core/i18n/match.d.mts +37 -0
  43. package/dist/core/i18n/match.mjs +82 -0
  44. package/dist/core/i18n/match.mjs.map +1 -0
  45. package/dist/core/i18n/types.d.mts +80 -0
  46. package/dist/core/index.d.mts +14 -5
  47. package/dist/core/index.mjs +9 -2
  48. package/dist/core/predictive-search/index.d.mts +2 -2
  49. package/dist/core/predictive-search/queries.d.mts +2 -2
  50. package/dist/core/predictive-search/server-handlers.d.mts +27 -6
  51. package/dist/core/predictive-search/server-handlers.mjs +1 -4
  52. package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
  53. package/dist/core/predictive-search/url.d.mts +2 -2
  54. package/dist/core/predictive-search/url.mjs.map +1 -1
  55. package/dist/core/product/accept-variant-id.mjs +1 -1
  56. package/dist/core/product/accept-variant-id.mjs.map +1 -1
  57. package/dist/core/request-context.d.mts +61 -35
  58. package/dist/core/request-context.mjs +11 -7
  59. package/dist/core/request-context.mjs.map +1 -1
  60. package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  61. package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
  62. package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  63. package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
  64. package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
  65. package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
  66. package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
  67. package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  68. package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
  69. package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  70. package/dist/core/request-routing/registered-routes.d.mts +13 -2
  71. package/dist/core/request-routing/registered-routes.mjs +33 -9
  72. package/dist/core/request-routing/registered-routes.mjs.map +1 -1
  73. package/dist/core/request-routing/route-types.d.mts +18 -8
  74. package/dist/core/shop-pay/shop-pay.mjs +5 -4
  75. package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
  76. package/dist/core/shopify-scripts/analytics.mjs +3 -5
  77. package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
  78. package/dist/core/shopify-scripts/constants.mjs +3 -1
  79. package/dist/core/shopify-scripts/constants.mjs.map +1 -1
  80. package/dist/core/shopify-scripts/global.mjs +13 -11
  81. package/dist/core/shopify-scripts/global.mjs.map +1 -1
  82. package/dist/core/shopify-scripts/hashes.d.mts +17 -0
  83. package/dist/core/shopify-scripts/hashes.mjs +12 -0
  84. package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
  85. package/dist/core/shopify-scripts/index.d.mts +1 -0
  86. package/dist/core/shopify-scripts/index.mjs +12 -9
  87. package/dist/core/shopify-scripts/index.mjs.map +1 -1
  88. package/dist/core/shopify-scripts/page-view.mjs +4 -1
  89. package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
  90. package/dist/core/shopify-scripts/perfkit.mjs +8 -2
  91. package/dist/core/shopify-scripts/perfkit.mjs.map +1 -1
  92. package/dist/core/shopify-scripts/types.d.mts +4 -2
  93. package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
  94. package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  95. package/dist/core/standard-routes/build.d.mts +7 -2
  96. package/dist/core/standard-routes/build.mjs +10 -3
  97. package/dist/core/standard-routes/build.mjs.map +1 -1
  98. package/dist/core/standard-routes/match.mjs +11 -1
  99. package/dist/core/standard-routes/match.mjs.map +1 -1
  100. package/dist/core/standard-routes/path.mjs +14 -3
  101. package/dist/core/standard-routes/path.mjs.map +1 -1
  102. package/dist/core/standard-routes/types.d.mts +6 -1
  103. package/dist/core/url.mjs +5 -3
  104. package/dist/core/url.mjs.map +1 -1
  105. package/dist/core/utils/load-script.mjs +6 -6
  106. package/dist/core/utils/load-script.mjs.map +1 -1
  107. package/dist/customer-account/client.d.mts +14 -10
  108. package/dist/customer-account/client.mjs +4 -5
  109. package/dist/customer-account/client.mjs.map +1 -1
  110. package/dist/customer-account/graphql.d.mts +7 -1
  111. package/dist/customer-account/graphql.mjs +6 -7
  112. package/dist/customer-account/graphql.mjs.map +1 -1
  113. package/dist/customer-account/session.mjs +3 -4
  114. package/dist/customer-account/session.mjs.map +1 -1
  115. package/dist/development/client/client.mjs +45 -12
  116. package/dist/development/client/client.mjs.map +1 -1
  117. package/dist/development/client/i18n-variables.d.mts +13 -0
  118. package/dist/development/client/i18n-variables.mjs +92 -0
  119. package/dist/development/client/i18n-variables.mjs.map +1 -0
  120. package/dist/development/client/types.d.mts +21 -8
  121. package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
  122. package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
  123. package/dist/development/core/cart/cart.mjs +111 -24
  124. package/dist/development/core/cart/cart.mjs.map +1 -1
  125. package/dist/development/core/cart/cookie.mjs +6 -1
  126. package/dist/development/core/cart/cookie.mjs.map +1 -1
  127. package/dist/development/core/cart/form.d.mts +17 -5
  128. package/dist/development/core/cart/form.mjs +5 -0
  129. package/dist/development/core/cart/form.mjs.map +1 -1
  130. package/dist/development/core/cart/index.d.mts +1 -1
  131. package/dist/development/core/cart/queries.d.mts +57 -57
  132. package/dist/development/core/collection/url.mjs +8 -1
  133. package/dist/development/core/collection/url.mjs.map +1 -1
  134. package/dist/development/core/constants.mjs +2 -1
  135. package/dist/development/core/constants.mjs.map +1 -1
  136. package/dist/development/core/csp/index.d.mts +56 -0
  137. package/dist/development/core/csp/index.mjs +128 -0
  138. package/dist/development/core/csp/index.mjs.map +1 -0
  139. package/dist/development/core/csp/types.d.mts +52 -0
  140. package/dist/development/core/development.d.mts +14 -5
  141. package/dist/development/core/development.mjs +9 -2
  142. package/dist/development/core/headers.mjs +2 -2
  143. package/dist/development/core/headers.mjs.map +1 -1
  144. package/dist/development/core/i18n/define.d.mts +54 -0
  145. package/dist/development/core/i18n/define.mjs +135 -0
  146. package/dist/development/core/i18n/define.mjs.map +1 -0
  147. package/dist/development/core/i18n/errors.d.mts +18 -0
  148. package/dist/development/core/i18n/errors.mjs +24 -0
  149. package/dist/development/core/i18n/errors.mjs.map +1 -0
  150. package/dist/development/core/i18n/href.d.mts +28 -0
  151. package/dist/development/core/i18n/href.mjs +45 -0
  152. package/dist/development/core/i18n/href.mjs.map +1 -0
  153. package/dist/development/core/i18n/locale.d.mts +21 -0
  154. package/dist/development/core/i18n/locale.mjs +36 -0
  155. package/dist/development/core/i18n/locale.mjs.map +1 -0
  156. package/dist/development/core/i18n/match.d.mts +37 -0
  157. package/dist/development/core/i18n/match.mjs +82 -0
  158. package/dist/development/core/i18n/match.mjs.map +1 -0
  159. package/dist/development/core/i18n/types.d.mts +80 -0
  160. package/dist/development/core/index.d.mts +13 -4
  161. package/dist/development/core/predictive-search/index.d.mts +2 -2
  162. package/dist/development/core/predictive-search/queries.d.mts +2 -2
  163. package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
  164. package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
  165. package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
  166. package/dist/development/core/predictive-search/url.d.mts +2 -2
  167. package/dist/development/core/predictive-search/url.mjs.map +1 -1
  168. package/dist/development/core/product/accept-variant-id.mjs +1 -1
  169. package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
  170. package/dist/development/core/request-context.d.mts +61 -35
  171. package/dist/development/core/request-context.mjs +11 -7
  172. package/dist/development/core/request-context.mjs.map +1 -1
  173. package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  174. package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
  175. package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  176. package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
  177. package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
  178. package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
  179. package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
  180. package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  181. package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
  182. package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  183. package/dist/development/core/request-routing/registered-routes.d.mts +13 -2
  184. package/dist/development/core/request-routing/registered-routes.mjs +33 -9
  185. package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
  186. package/dist/development/core/request-routing/route-types.d.mts +18 -8
  187. package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
  188. package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
  189. package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
  190. package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
  191. package/dist/development/core/shopify-scripts/constants.mjs +3 -1
  192. package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
  193. package/dist/development/core/shopify-scripts/global.mjs +13 -11
  194. package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
  195. package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
  196. package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
  197. package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
  198. package/dist/development/core/shopify-scripts/index.d.mts +1 -0
  199. package/dist/development/core/shopify-scripts/index.mjs +12 -9
  200. package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
  201. package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
  202. package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
  203. package/dist/development/core/shopify-scripts/perfkit.mjs +8 -2
  204. package/dist/development/core/shopify-scripts/perfkit.mjs.map +1 -1
  205. package/dist/development/core/shopify-scripts/types.d.mts +4 -2
  206. package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
  207. package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  208. package/dist/development/core/standard-routes/build.d.mts +7 -2
  209. package/dist/development/core/standard-routes/build.mjs +10 -3
  210. package/dist/development/core/standard-routes/build.mjs.map +1 -1
  211. package/dist/development/core/standard-routes/match.mjs +11 -1
  212. package/dist/development/core/standard-routes/match.mjs.map +1 -1
  213. package/dist/development/core/standard-routes/path.mjs +14 -3
  214. package/dist/development/core/standard-routes/path.mjs.map +1 -1
  215. package/dist/development/core/standard-routes/types.d.mts +6 -1
  216. package/dist/development/core/url.mjs +5 -3
  217. package/dist/development/core/url.mjs.map +1 -1
  218. package/dist/development/core/utils/load-script.mjs +6 -6
  219. package/dist/development/core/utils/load-script.mjs.map +1 -1
  220. package/dist/development/customer-account/session.mjs.map +1 -1
  221. package/dist/development/globals.d.mts +8 -4
  222. package/dist/development/graphql/type-resolver.d.mts +39 -1
  223. package/dist/development/react/cart.mjs +79 -25
  224. package/dist/development/react/cart.mjs.map +1 -1
  225. package/dist/development/react/index.d.mts +2 -2
  226. package/dist/globals.d.mts +8 -4
  227. package/dist/graphql/type-resolver.d.mts +39 -1
  228. package/dist/react/cart.mjs +79 -25
  229. package/dist/react/cart.mjs.map +1 -1
  230. package/dist/react/index.d.mts +2 -2
  231. package/dist/vite/index.d.mts +11 -1
  232. package/dist/vite/index.mjs +21 -1
  233. package/dist/vite/index.mjs.map +1 -0
  234. package/package.json +13 -3
  235. package/skills/hydrogen-analytics/SKILL.md +2 -2
  236. package/skills/hydrogen-analytics/references/react.md +2 -2
  237. package/skills/hydrogen-cart-ui/SKILL.md +2 -2
  238. package/skills/hydrogen-markets/SKILL.md +127 -93
  239. package/skills/hydrogen-markets/references/nextjs.md +77 -87
  240. package/skills/hydrogen-oxygen/references/react-router.md +1 -2
  241. package/skills/hydrogen-predictive-search/SKILL.md +18 -1
  242. package/skills/hydrogen-request-handlers/SKILL.md +24 -6
  243. package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
  244. package/skills/hydrogen-request-handlers/references/frameworks.md +9 -12
  245. package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
  246. package/skills/hydrogen-request-handlers/references/nuxt.md +7 -7
  247. package/skills/hydrogen-robots-txt/SKILL.md +87 -0
  248. package/skills/hydrogen-routing/SKILL.md +36 -14
  249. package/skills/hydrogen-setup/SKILL.md +2 -2
  250. package/skills/hydrogen-setup/references/analytics.md +5 -5
  251. package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
  252. package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
  253. package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
  254. package/skills/hydrogen-smoke-test/SKILL.md +9 -2
  255. package/skills/hydrogen-storefront-client/SKILL.md +29 -9
  256. package/skills/hydrogen-storefront-client/references/astro.md +8 -3
  257. package/skills/hydrogen-storefront-client/references/caching.md +2 -0
  258. package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
  259. package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
  260. package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
  261. package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
  262. package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
  263. package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
  264. package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
  265. 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
- return decodeURIComponent(value.replace(/\+/g, " "));
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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,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);\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,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"}
@@ -3,7 +3,8 @@ const STOREFRONT_API_VERSION = "2026-10";
3
3
  /** @publicDocs */
4
4
  const CUSTOMER_ACCOUNT_API_VERSION = "2026-10";
5
5
  const DEFAULT_TIMEOUT_IN_MS = 3e4;
6
+ const HYDROGEN_USER_AGENT = `Hydrogen 2026.10.3`;
6
7
 
7
8
  //#endregion
8
- export { CUSTOMER_ACCOUNT_API_VERSION, DEFAULT_TIMEOUT_IN_MS, STOREFRONT_API_VERSION };
9
+ export { CUSTOMER_ACCOUNT_API_VERSION, DEFAULT_TIMEOUT_IN_MS, HYDROGEN_USER_AGENT, STOREFRONT_API_VERSION };
9
10
  //# 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;;AAEtC,MAAa,+BAA+B;AAC5C,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;;AAEtC,MAAa,+BAA+B;AAC5C,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,117 @@
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
+ ]
91
+ };
92
+ }
93
+ function generateNonce() {
94
+ return btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(16))));
95
+ }
96
+ function withNonce(sources, nonce) {
97
+ return [...sources ?? [], `'nonce-${nonce}'`];
98
+ }
99
+ const DIRECTIVE_KEY = /^[a-z]+(?:[A-Z][a-z]*)*$/;
100
+ function serializeDirectives(directives) {
101
+ return Object.entries(directives).flatMap(([key, value]) => {
102
+ if (value == null) return [];
103
+ const name = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
104
+ if (typeof value === "boolean") return value ? [name] : [];
105
+ const sources = [...new Set(value.map(validateSource))];
106
+ if (sources.some((source) => source.toLowerCase() === "'none'") && sources.length > 1) throw new TypeError(`CSP directive ${key} cannot combine 'none' with other sources.`);
107
+ return [[name, ...sources].join(" ")];
108
+ }).join("; ");
109
+ }
110
+ function validateSource(value) {
111
+ if (!value || /[^\u0021-\u007e]|[;,]/.test(value)) throw new TypeError("CSP sources must be non-empty ASCII tokens without whitespace, commas, or semicolons.");
112
+ return value;
113
+ }
114
+
115
+ //#endregion
116
+ export { createContentSecurityPolicy, getShopifyCspDirectives };
117
+ //# 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,CA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H,SAAS,gBAAwB;AAC/B,QAAO,KAAK,OAAO,aAAa,GAAG,OAAO,gBAAgB,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC;;AAGjF,SAAS,UAAU,SAA+C,OAAyB;AACzF,QAAO,CAAC,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
@@ -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 (/^(?:.+-)?cdn-cache-control$/i.test(header) || header.toLowerCase() === "Surrogate-Control".toLowerCase()) headers.delete(header);
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 };
@@ -1 +1 @@
1
- {"version":3,"file":"headers.mjs","names":[],"sources":["../../src/core/headers.ts"],"sourcesContent":["export const CACHE_CONTROL_HEADER = \"Cache-Control\";\nexport const CONSENT_MANAGEMENT_HEADER = \"Shopify-Storefront-Consent-Management\";\nexport const HYDROGEN_VERSION_HEADER = \"X-Hydrogen-Version\";\nexport const SURROGATE_CONTROL_HEADER = \"Surrogate-Control\";\nexport const REQUEST_GROUP_ID_HEADER = \"Custom-Storefront-Request-Group-ID\";\nexport const SDK_VARIANT_HEADER = \"X-SDK-Variant\";\nexport const SDK_VARIANT_SOURCE_HEADER = \"X-SDK-Variant-Source\";\nexport const SDK_VERSION_HEADER = \"X-SDK-Version\";\nexport const SEC_GPC_HEADER = \"Sec-GPC\";\nexport const SHOPIFY_STOREFRONT_ORIGIN_HEADER = \"Sec-Shopify-Storefront-Origin\";\nexport const STOREFRONT_ID_HEADER = \"Shopify-Storefront-Id\";\nexport const SHOPIFY_STOREFRONT_S_HEADER = \"Shopify-Storefront-S\";\nexport const SHOPIFY_STOREFRONT_Y_HEADER = \"Shopify-Storefront-Y\";\nexport const SHOPIFY_UNIQUE_TOKEN_HEADER = \"X-Shopify-UniqueToken\";\nexport const SHOPIFY_VISIT_TOKEN_HEADER = \"X-Shopify-VisitToken\";\nexport const STOREFRONT_ACCESS_TOKEN_HEADER = \"X-Shopify-Storefront-Access-Token\";\nexport const STOREFRONT_BUYER_IP_HEADER = \"Shopify-Storefront-Buyer-IP\";\nexport const STOREFRONT_PRIVATE_TOKEN_HEADER = \"Shopify-Storefront-Private-Token\";\nexport const STOREFRONT_URL_HEADER = \"x-storefront-url\";\n\nexport type StandardHeaderName =\n | \"accept\"\n | \"accept-encoding\"\n | \"accept-language\"\n | \"access-control-request-headers\"\n | \"access-control-request-method\"\n | typeof CACHE_CONTROL_HEADER\n | \"cf-connecting-ip\"\n | \"connection\"\n | \"content-length\"\n | \"content-type\"\n | \"cookie\"\n | \"host\"\n | \"keep-alive\"\n | \"origin\"\n | \"proxy-authenticate\"\n | \"proxy-authorization\"\n | \"referer\"\n | typeof SEC_GPC_HEADER\n | typeof SURROGATE_CONTROL_HEADER\n | \"te\"\n | \"trailer\"\n | \"transfer-encoding\"\n | \"upgrade\"\n | \"user-agent\"\n | \"x-requested-with\";\n\nexport type ShopifyHeaderName =\n | typeof CONSENT_MANAGEMENT_HEADER\n | typeof HYDROGEN_VERSION_HEADER\n | typeof REQUEST_GROUP_ID_HEADER\n | typeof SDK_VARIANT_HEADER\n | typeof SDK_VARIANT_SOURCE_HEADER\n | typeof SDK_VERSION_HEADER\n | typeof SHOPIFY_STOREFRONT_ORIGIN_HEADER\n | typeof SHOPIFY_STOREFRONT_S_HEADER\n | typeof SHOPIFY_STOREFRONT_Y_HEADER\n | typeof SHOPIFY_UNIQUE_TOKEN_HEADER\n | typeof SHOPIFY_VISIT_TOKEN_HEADER\n | typeof STOREFRONT_ACCESS_TOKEN_HEADER\n | typeof STOREFRONT_BUYER_IP_HEADER\n | typeof STOREFRONT_ID_HEADER\n | typeof STOREFRONT_PRIVATE_TOKEN_HEADER\n | typeof STOREFRONT_URL_HEADER;\n\ntype KnownHeaderName = StandardHeaderName | ShopifyHeaderName;\n\nexport function defineHeaderList<const HeaderNames extends readonly KnownHeaderName[]>(\n ...headerNames: HeaderNames\n): HeaderNames {\n return headerNames;\n}\n\nexport function extractHeaders(\n getter: (key: string) => string | null,\n allowlist: readonly string[],\n): [string, string][] {\n return allowlist.reduce<[string, string][]>((acc, key) => {\n const value = getter(key);\n if (value != null) acc.push([key, value]);\n return acc;\n }, []);\n}\n\nexport function applyPrivateResponseCacheHeaders(headers: Headers): void {\n headers.set(CACHE_CONTROL_HEADER, \"private, no-store, max-age=0, must-revalidate\");\n for (const header of Array.from(headers.keys())) {\n if (\n /^(?:.+-)?cdn-cache-control$/i.test(header) ||\n header.toLowerCase() === SURROGATE_CONTROL_HEADER.toLowerCase()\n ) {\n headers.delete(header);\n }\n }\n}\n\nconst COMMON_PROXY_HEADER_ALLOWLIST = defineHeaderList(\n \"accept\",\n \"accept-encoding\",\n \"accept-language\",\n \"content-type\",\n \"cookie\",\n \"origin\",\n \"referer\",\n \"user-agent\",\n);\n\nexport const SFAPI_REQUEST_HEADER_ALLOWLIST = defineHeaderList(\n ...COMMON_PROXY_HEADER_ALLOWLIST,\n \"content-length\",\n \"access-control-request-headers\",\n \"access-control-request-method\",\n STOREFRONT_ACCESS_TOKEN_HEADER,\n STOREFRONT_PRIVATE_TOKEN_HEADER,\n SHOPIFY_UNIQUE_TOKEN_HEADER,\n SHOPIFY_VISIT_TOKEN_HEADER,\n);\n\nexport const MCP_REQUEST_HEADER_ALLOWLIST = defineHeaderList(...COMMON_PROXY_HEADER_ALLOWLIST);\n\nexport const AJAX_API_REQUEST_HEADER_ALLOWLIST = defineHeaderList(\n ...COMMON_PROXY_HEADER_ALLOWLIST,\n \"content-length\",\n \"x-requested-with\",\n);\n\n// Hop-by-hop headers must not be forwarded by proxies. `host` and\n// `content-length` are also removed so fetch can derive them for the upstream\n// request. See https://www.rfc-editor.org/rfc/rfc9110.html#section-7.6.1\nexport const PROXY_REQUEST_HEADER_DENYLIST = defineHeaderList(\n \"cf-connecting-ip\",\n \"connection\",\n \"content-length\",\n \"host\",\n \"keep-alive\",\n \"proxy-authen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,sBACA,uBACA,MACA,WACA,qBACA,UACD"}
1
+ {"version":3,"file":"headers.mjs","names":[],"sources":["../../src/core/headers.ts"],"sourcesContent":["export const CACHE_CONTROL_HEADER = \"Cache-Control\";\nexport const CONSENT_MANAGEMENT_HEADER = \"Shopify-Storefront-Consent-Management\";\nexport const HYDROGEN_VERSION_HEADER = \"X-Hydrogen-Version\";\nexport const SURROGATE_CONTROL_HEADER = \"Surrogate-Control\";\nexport const REQUEST_GROUP_ID_HEADER = \"Custom-Storefront-Request-Group-ID\";\nexport const SDK_VARIANT_HEADER = \"X-SDK-Variant\";\nexport const SDK_VARIANT_SOURCE_HEADER = \"X-SDK-Variant-Source\";\nexport const SDK_VERSION_HEADER = \"X-SDK-Version\";\nexport const SEC_GPC_HEADER = \"Sec-GPC\";\nexport const SHOPIFY_STOREFRONT_ORIGIN_HEADER = \"Sec-Shopify-Storefront-Origin\";\nexport const STOREFRONT_ID_HEADER = \"Shopify-Storefront-Id\";\nexport const SHOPIFY_STOREFRONT_S_HEADER = \"Shopify-Storefront-S\";\nexport const SHOPIFY_STOREFRONT_Y_HEADER = \"Shopify-Storefront-Y\";\nexport const SHOPIFY_UNIQUE_TOKEN_HEADER = \"X-Shopify-UniqueToken\";\nexport const SHOPIFY_VISIT_TOKEN_HEADER = \"X-Shopify-VisitToken\";\nexport const STOREFRONT_ACCESS_TOKEN_HEADER = \"X-Shopify-Storefront-Access-Token\";\nexport const STOREFRONT_BUYER_IP_HEADER = \"Shopify-Storefront-Buyer-IP\";\nexport const STOREFRONT_PRIVATE_TOKEN_HEADER = \"Shopify-Storefront-Private-Token\";\nexport const STOREFRONT_URL_HEADER = \"x-storefront-url\";\n\nexport type StandardHeaderName =\n | \"accept\"\n | \"accept-encoding\"\n | \"accept-language\"\n | \"access-control-request-headers\"\n | \"access-control-request-method\"\n | typeof CACHE_CONTROL_HEADER\n | \"cf-connecting-ip\"\n | \"connection\"\n | \"content-length\"\n | \"content-type\"\n | \"cookie\"\n | \"forwarded\"\n | \"host\"\n | \"keep-alive\"\n | \"origin\"\n | \"oxygen-buyer-ip\"\n | \"proxy-authenticate\"\n | \"proxy-authorization\"\n | \"referer\"\n | typeof SEC_GPC_HEADER\n | typeof SURROGATE_CONTROL_HEADER\n | \"te\"\n | \"trailer\"\n | \"transfer-encoding\"\n | \"true-client-ip\"\n | \"upgrade\"\n | \"user-agent\"\n | \"x-client-ip\"\n | \"x-forwarded-for\"\n | \"x-forwarded-host\"\n | \"x-forwarded-port\"\n | \"x-forwarded-proto\"\n | \"x-forwarded-scheme\"\n | \"x-forwarded-ssl\"\n | \"x-real-ip\"\n | \"x-requested-with\"\n | \"x-shopify-client-ip\";\n\nexport type ShopifyHeaderName =\n | typeof CONSENT_MANAGEMENT_HEADER\n | typeof HYDROGEN_VERSION_HEADER\n | typeof REQUEST_GROUP_ID_HEADER\n | typeof SDK_VARIANT_HEADER\n | typeof SDK_VARIANT_SOURCE_HEADER\n | typeof SDK_VERSION_HEADER\n | typeof SHOPIFY_STOREFRONT_ORIGIN_HEADER\n | typeof SHOPIFY_STOREFRONT_S_HEADER\n | typeof SHOPIFY_STOREFRONT_Y_HEADER\n | typeof SHOPIFY_UNIQUE_TOKEN_HEADER\n | typeof SHOPIFY_VISIT_TOKEN_HEADER\n | typeof STOREFRONT_ACCESS_TOKEN_HEADER\n | typeof STOREFRONT_BUYER_IP_HEADER\n | typeof STOREFRONT_ID_HEADER\n | typeof STOREFRONT_PRIVATE_TOKEN_HEADER\n | typeof STOREFRONT_URL_HEADER;\n\ntype KnownHeaderName = StandardHeaderName | ShopifyHeaderName;\n\nexport function defineHeaderList<const HeaderNames extends readonly KnownHeaderName[]>(\n ...headerNames: HeaderNames\n): HeaderNames {\n return headerNames;\n}\n\nexport function extractHeaders(\n getter: (key: string) => string | null,\n allowlist: readonly string[],\n): [string, string][] {\n return allowlist.reduce<[string, string][]>((acc, key) => {\n const value = getter(key);\n if (value != null) acc.push([key, value]);\n return acc;\n }, []);\n}\n\nexport function applyPrivateResponseCacheHeaders(headers: Headers): void {\n headers.set(CACHE_CONTROL_HEADER, \"private, no-store, max-age=0, must-revalidate\");\n for (const header of Array.from(headers.keys())) {\n // Delete every vendor `*-Cache-Control` header (`CDN-`, `Cloudflare-CDN-`, `Oxygen-`, ...):\n // targeted caches such as Oxygen's full-page cache prefer their own header over\n // `Cache-Control`, so leaving one in place would override the private value set above.\n if (\n /^.+-cache-control$/i.test(header) ||\n header.toLowerCase() === SURROGATE_CONTROL_HEADER.toLowerCase()\n ) {\n headers.delete(header);\n }\n }\n}\n\nconst COMMON_PROXY_HEADER_ALLOWLIST = defineHeaderList(\n \"accept\",\n \"accept-encoding\",\n \"accept-language\",\n \"content-type\",\n \"cookie\",\n \"origin\",\n \"referer\",\n \"user-agent\",\n);\n\nexport const SFAPI_REQUEST_HEADER_ALLOWLIST = defineHeaderList(\n ...COMMON_PROXY_HEADER_ALLOWLIST,\n \"content-length\",\n \"access-control-request-headers\",\n \"access-control-request-method\",\n STOREFRONT_ACCESS_TOKEN_HEADER,\n STOREFRONT_PRIVATE_TOKEN_HEADER,\n SHOPIFY_UNIQUE_TOKEN_HEADER,\n SHOPIFY_VISIT_TOKEN_HEADER,\n);\n\nexport const MCP_REQUEST_HEADER_ALLOWLIST = defineHeaderList(...COMMON_PROXY_HEADER_ALLOWLIST);\n\nexport const AJAX_API_REQUEST_HEADER_ALLOWLIST = defineHeaderList(\n ...COMMON_PROXY_HEADER_ALLOWLIST,\n \"content-length\",\n \"x-requested-with\",\n);\n\n// Hop-by-hop headers must not be forwarded by proxies. `host` and\n// `content-length` are also removed so fetch can derive them for the upstream\n// request. See https://www.rfc-editor.org/rfc/rfc9110.html#section-7.6.1\n// Client IP and forwarding headers are removed because the caller controls them.\nexport const PROXY_REQUEST_HEADER_DENYLIST = defineHeaderList(\n \"cf-connecting-ip\",\n \"connection\",\n \"content-length\",\n \"forwarded\",\n \"host\",\n \"keep-alive\",\n \"oxygen-buyer-ip\",\n \"proxy-authenticate\",\n \"proxy-authorization\",\n STOREFRONT_BUYER_IP_HEADER,\n \"te\",\n \"trailer\",\n \"transfer-encoding\",\n \"true-client-ip\",\n \"upgrade\",\n \"x-client-ip\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-port\",\n \"x-forwarded-proto\",\n \"x-forwarded-scheme\",\n \"x-forwarded-ssl\",\n \"x-real-ip\",\n \"x-shopify-client-ip\",\n);\n"],"mappings":";AAAA,MAAa,uBAAuB;AACpC,MAAa,4BAA4B;AACzC,MAAa,0BAA0B;AACvC,MAAa,2BAA2B;AACxC,MAAa,0BAA0B;AACvC,MAAa,qBAAqB;AAClC,MAAa,4BAA4B;AACzC,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,mCAAmC;AAChD,MAAa,uBAAuB;AACpC,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAC3C,MAAa,6BAA6B;AAC1C,MAAa,iCAAiC;AAC9C,MAAa,6BAA6B;AAC1C,MAAa,kCAAkC;AAC/C,MAAa,wBAAwB;AA6DrC,SAAgB,iBACd,GAAG,aACU;AACb,QAAO;;AAGT,SAAgB,eACd,QACA,WACoB;AACpB,QAAO,UAAU,QAA4B,KAAK,QAAQ;EACxD,MAAM,QAAQ,OAAO,IAAI;AACzB,MAAI,SAAS,KAAM,KAAI,KAAK,CAAC,KAAK,MAAM,CAAC;AACzC,SAAO;IACN,EAAE,CAAC;;AAGR,SAAgB,iCAAiC,SAAwB;AACvE,SAAQ,IAAI,sBAAsB,gDAAgD;AAClF,MAAK,MAAM,UAAU,MAAM,KAAK,QAAQ,MAAM,CAAC,CAI7C,KACE,sBAAsB,KAAK,OAAO,IAClC,OAAO,aAAa,yBAA8B,aAAa,CAE/D,SAAQ,OAAO,OAAO;;AAK5B,MAAM,gCAAgC,iBACpC,UACA,mBACA,mBACA,gBACA,UACA,UACA,WACA,aACD;AAED,MAAa,iCAAiC,iBAC5C,GAAG,+BACH,kBACA,kCACA,iCACA,gCACA,iCACA,6BACA,2BACD;AAED,MAAa,+BAA+B,iBAAiB,GAAG,8BAA8B;AAE9F,MAAa,oCAAoC,iBAC/C,GAAG,+BACH,kBACA,mBACD;AAMD,MAAa,gCAAgC,iBAC3C,oBACA,cACA,kBACA,aACA,QACA,cACA,mBACA,sBACA,uBACA,4BACA,MACA,WACA,qBACA,kBACA,WACA,eACA,mBACA,oBACA,oBACA,qBACA,sBACA,mBACA,aACA,sBACD"}
@@ -0,0 +1,54 @@
1
+ import { ShopifyI18n, ShopifySupportedLocale } from "./types.mjs";
2
+
3
+ //#region src/core/i18n/define.d.ts
4
+ /**
5
+ * Defines the module-scope internationalization configuration for a storefront.
6
+ *
7
+ * Returns the input unchanged with its literal types preserved, so it is serializable and safe to
8
+ * import from server and client code alike. Pass it to `createShopifyRequestContext({i18n})` to
9
+ * resolve the request locale, and to the URL helpers (`getLocalizedHref`) to build links.
10
+ *
11
+ * Validation happens here, once at module load, so an invalid definition fails at startup rather
12
+ * than on the first request that would hit the bad entry.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * // Single locale: every request resolves to the default.
17
+ * export const i18n = defineShopifyI18n({
18
+ * defaultLocale: { language: "EN", country: "US" },
19
+ * });
20
+ *
21
+ * // Path-prefixed locales: `/fr-ca/products/x`, default served unprefixed.
22
+ * export const i18n = defineShopifyI18n({
23
+ * defaultLocale: { language: "EN", country: "US" },
24
+ * routing: {
25
+ * type: "pathname",
26
+ * locales: [
27
+ * { language: "FR", country: "CA" },
28
+ * { language: "PT_BR", country: "BR", pathSegment: "br" },
29
+ * ],
30
+ * },
31
+ * });
32
+ *
33
+ * // One hostname per locale; the default must be listed so it has a canonical host.
34
+ * export const i18n = defineShopifyI18n({
35
+ * defaultLocale: { language: "EN", country: "US" },
36
+ * routing: {
37
+ * type: "domain",
38
+ * locales: [
39
+ * { language: "EN", country: "US", hostname: "example.com" },
40
+ * { language: "FR", country: "CA", hostname: "fr.example.ca" },
41
+ * ],
42
+ * },
43
+ * });
44
+ * ```
45
+ */
46
+ declare function defineShopifyI18n<const TI18n extends ShopifyI18n>(i18n: TI18n): TI18n;
47
+ /**
48
+ * Every locale the definition can resolve to, default first. Entries keep their routing keys
49
+ * (`pathSegment`, `hostname`) and any extra fields, so sitemaps and selectors can enumerate URLs.
50
+ */
51
+ declare function getSupportedLocales<const TI18n extends ShopifyI18n>(i18n: TI18n): ShopifySupportedLocale<TI18n>[];
52
+ //#endregion
53
+ export { defineShopifyI18n, getSupportedLocales };
54
+ //# sourceMappingURL=define.d.mts.map