@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashes.mjs","names":[],"sources":["../../../src/core/shopify-scripts/hashes.ts"],"sourcesContent":["/**\n * @internal\n */\nconst hashes = __SCRIPT_HASHES__;\n\n/**\n * Returns CSP hashes for the static inline bootstraps rendered by ShopifyScripts and the tag helpers.\n * Add these to script-src when using hashes instead of nonces. Values include CSP quotes by default;\n * pass `quoted: false` for framework configuration that expects unquoted hashes.\n * Hashes authorize Shopify's bootstraps, not framework scripts.\n * @publicDocs\n */\nexport function getShopifyScriptHashes(options: { quoted: false }): `sha256-${string}`[];\nexport function getShopifyScriptHashes(options?: { quoted?: boolean }): string[];\nexport function getShopifyScriptHashes({ quoted = true }: { quoted?: boolean } = {}): string[] {\n return quoted ? [...hashes] : hashes.map((hash) => hash.slice(1, -1));\n}\n"],"mappings":";;;;AAGA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,iHAAA;AAWf,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAuB,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA+B,CAAA,CAAE,CAAA,CAAY;AAC7F,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAC,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop } from "./types.mjs";
2
+ import { getShopifyScriptHashes } from "./hashes.mjs";
2
3
  import { initializeShopifyScripts } from "./initialize.mjs";
3
4
  //#region src/core/shopify-scripts/index.d.ts
4
5
  /**
@@ -1,6 +1,7 @@
1
- import { getShopifyAnalyticsBusScript, getShopifyAnalyticsConfig } from "./analytics.mjs";
2
1
  import { CONSENT_TRACKING_API_LOADED_EVENT, SHOPIFY_ACCOUNT_SCRIPT, SHOPIFY_CDN_ORIGIN, SHOPIFY_CONSENT_API_SCRIPT, SHOPIFY_CONSENT_SCRIPT_ID, SHOPIFY_INBOX_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PRIVACY_BANNER_SCRIPT, SHOPIFY_SHOP_APP_ORIGIN, SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT, SHOPIFY_STOREFRONT_WEBMCP_SCRIPT, VISITOR_CONSENT_COLLECTED_EVENT } from "./constants.mjs";
3
- import { getShopifyGlobal, getShopifyGlobalBootstrapScript } from "./global.mjs";
2
+ import { getShopifyScriptHashes } from "./hashes.mjs";
3
+ import { getShopifyAnalyticsConfig, shopifyAnalyticsBootstrap } from "./analytics.mjs";
4
+ import { getShopifyGlobal, getShopifyGlobalConfig, shopifyGlobalBootstrap } from "./global.mjs";
4
5
  import { getPerfKitScript } from "./perfkit.mjs";
5
6
  import { renderShopifyScriptTag } from "./render.mjs";
6
7
  import { initializeShopifyScripts } from "./initialize.mjs";
@@ -53,12 +54,13 @@ function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n
53
54
  tagName: "script",
54
55
  attributes: {
55
56
  id: "shopify-global-bootstrap",
56
- ...nonceAttributes
57
+ ...nonceAttributes,
58
+ ...shopifyGlobalBootstrap.attributes(getShopifyGlobalConfig({
59
+ i18n,
60
+ shop
61
+ }))
57
62
  },
58
- innerHTML: getShopifyGlobalBootstrapScript({
59
- i18n,
60
- shop
61
- })
63
+ innerHTML: shopifyGlobalBootstrap.code
62
64
  }, {
63
65
  tagName: "script",
64
66
  attributes: {
@@ -95,9 +97,10 @@ function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n
95
97
  tagName: "script",
96
98
  attributes: {
97
99
  id: "shopify-analytics-bus",
98
- ...nonceAttributes
100
+ ...nonceAttributes,
101
+ ...shopifyAnalyticsBootstrap.attributes(analyticsConfig)
99
102
  },
100
- innerHTML: getShopifyAnalyticsBusScript(analyticsConfig)
103
+ innerHTML: shopifyAnalyticsBootstrap.code
101
104
  });
102
105
  scripts.push({
103
106
  tagName: "script",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import { getShopifyAnalyticsBusScript, getShopifyAnalyticsConfig } from \"./analytics\";\nimport {\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_SCRIPT_ID,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n} from \"./constants\";\nimport { getShopifyGlobalBootstrapScript } from \"./global\";\nimport { getPerfKitScript } from \"./perfkit\";\nimport { renderShopifyScriptTag } from \"./render\";\nimport type {\n ShopifyLinkDescriptor,\n ShopifyScriptDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n} from \"./types\";\n\nexport {\n CONSENT_TRACKING_API_LOADED_EVENT,\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_PERF_KIT_SCRIPT,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n SHOPIFY_STOREFRONT_WEBMCP_SCRIPT,\n VISITOR_CONSENT_COLLECTED_EVENT,\n} from \"./constants\";\nexport { getShopifyGlobal, getShopifyGlobalBootstrapScript } from \"./global\";\nexport { initializeShopifyScripts } from \"./initialize\";\nexport { renderShopifyScriptTag } from \"./render\";\nexport type {\n ShopifyScriptsAnalyticsConfig,\n ShopifyRoutesOptions,\n ShopifyScriptTagDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n ShopifyScriptsOptions,\n ShopifyScriptsI18n,\n ShopifyScriptsShop,\n} from \"./types\";\n\n/**\n * Returns Shopify's storefront script and link tags as descriptors.\n *\n * Render the descriptors in the document head during server rendering, then call\n * `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline\n * scripts set up globals that later scripts read.\n *\n * @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.\n * @returns The link tags, the script tags, and a combined list with links first.\n * @publicDocs\n */\n// oxlint-disable-next-line complexity -- ordered assembly of optional Shopify script tags; each flag adds one branch and splitting would obscure the required load order\nexport function getShopifyScriptTags({\n account = false,\n analytics,\n consent,\n debug,\n i18n,\n nonce,\n shop,\n shopifyAnalytics = true,\n inbox = false,\n}: ShopifyScriptTagsOptions): ShopifyScriptTagDescriptors {\n const nonceAttributes = nonce !== undefined ? { nonce } : undefined;\n const analyticsConfig = getShopifyAnalyticsConfig({ analytics, consent, shop });\n\n const links: ShopifyLinkDescriptor[] = [\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_CDN_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_SHOP_APP_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"prefetch\",\n as: \"script\",\n href: SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n crossorigin: \"anonymous\",\n },\n },\n ];\n const scripts: ShopifyScriptDescriptor[] = [\n {\n tagName: \"script\",\n attributes: { id: \"shopify-global-bootstrap\", ...nonceAttributes },\n innerHTML: getShopifyGlobalBootstrapScript({ i18n, shop }),\n },\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-actions\",\n type: \"module\",\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n },\n },\n ];\n\n if (__DEV__ && debug?.standardEventsInspector) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-events-inspector\",\n defer: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n },\n });\n }\n\n if (inbox) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-inbox\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_INBOX_SCRIPT,\n },\n });\n }\n\n if (account) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-account\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_ACCOUNT_SCRIPT,\n },\n });\n }\n\n // Install readiness listeners before loading the async consent library so a\n // cached script cannot finish initialization before Hydrogen starts listening.\n scripts.push({\n tagName: \"script\",\n attributes: { id: \"shopify-analytics-bus\", ...nonceAttributes },\n innerHTML: getShopifyAnalyticsBusScript(analyticsConfig),\n });\n\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_CONSENT_SCRIPT_ID,\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src:\n consent?.mode === \"default-banner\"\n ? SHOPIFY_PRIVACY_BANNER_SCRIPT\n : SHOPIFY_CONSENT_API_SCRIPT,\n },\n });\n\n if (shopifyAnalytics) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-storefront-analytics\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n },\n });\n }\n\n const perfKitScript = getPerfKitScript(shop, nonceAttributes);\n if (perfKitScript) {\n scripts.push(perfKitScript);\n }\n\n return {\n links,\n scripts,\n get tags() {\n return [...links, ...scripts];\n },\n };\n}\n\n/**\n * Renders Shopify's storefront script and link tags to HTML strings.\n *\n * Use the function when your framework accepts raw HTML in the document head.\n *\n * @param options The shop details and the features, such as account and analytics, whose scripts to load.\n * @returns One HTML string per tag, with link tags first.\n * @publicDocs\n */\nexport function renderShopifyScriptTags(options: ShopifyScriptTagsOptions): string[] {\n return getShopifyScriptTags(options).tags.map(renderShopifyScriptTag);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,qBAAqB,EACnC,UAAU,OACV,WACA,SACA,OACA,MACA,OACA,MACA,mBAAmB,MACnB,QAAQ,SACgD;CACxD,MAAM,kBAAkB,UAAU,SAAY,EAAE,OAAO,GAAG;CAC1D,MAAM,kBAAkB,0BAA0B;EAAE;EAAW;EAAS;EAAM,CAAC;CAE/E,MAAM,QAAiC;EACrC;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,aAAa;IACd;GACF;EACF;CACD,MAAM,UAAqC,CACzC;EACE,SAAS;EACT,YAAY;GAAE,IAAI;GAA4B,GAAG;GAAiB;EAClE,WAAW,gCAAgC;GAAE;GAAM;GAAM,CAAC;EAC3D,EACD;EACE,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CACF;AAeD,KAAI,MACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAGJ,KAAI,QACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAKJ,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GAAE,IAAI;GAAyB,GAAG;GAAiB;EAC/D,WAAW,6BAA6B,gBAAgB;EACzD,CAAC;AAEF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KACE,SAAS,SAAS,mBACd,gCACA;GACP;EACF,CAAC;AAEF,KAAI,iBACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;CAGJ,MAAM,gBAAgB,iBAAiB,MAAM,gBAAgB;AAC7D,KAAI,cACF,SAAQ,KAAK,cAAc;AAG7B,QAAO;EACL;EACA;EACA,IAAI,OAAO;AACT,UAAO,CAAC,GAAG,OAAO,GAAG,QAAQ;;EAEhC;;;;;;;;;;;AAYH,SAAgB,wBAAwB,SAA6C;AACnF,QAAO,qBAAqB,QAAQ,CAAC,KAAK,IAAI,uBAAuB"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import { shopifyAnalyticsBootstrap, getShopifyAnalyticsConfig } from \"./analytics\";\nimport {\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_SCRIPT_ID,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n} from \"./constants\";\nimport { getShopifyGlobalConfig, shopifyGlobalBootstrap } from \"./global\";\nimport { getPerfKitScript } from \"./perfkit\";\nimport { renderShopifyScriptTag } from \"./render\";\nimport type {\n ShopifyLinkDescriptor,\n ShopifyScriptDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n} from \"./types\";\n\nexport {\n CONSENT_TRACKING_API_LOADED_EVENT,\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_PERF_KIT_SCRIPT,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n SHOPIFY_STOREFRONT_WEBMCP_SCRIPT,\n VISITOR_CONSENT_COLLECTED_EVENT,\n} from \"./constants\";\nexport { getShopifyGlobal } from \"./global\";\nexport { getShopifyScriptHashes } from \"./hashes\";\nexport { initializeShopifyScripts } from \"./initialize\";\nexport { renderShopifyScriptTag } from \"./render\";\nexport type {\n ShopifyScriptsAnalyticsConfig,\n ShopifyRoutesOptions,\n ShopifyScriptTagDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n ShopifyScriptsOptions,\n ShopifyScriptsI18n,\n ShopifyScriptsShop,\n} from \"./types\";\n\n/**\n * Returns Shopify's storefront script and link tags as descriptors.\n *\n * Render the descriptors in the document head during server rendering, then call\n * `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline\n * scripts set up globals that later scripts read.\n *\n * @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.\n * @returns The link tags, the script tags, and a combined list with links first.\n * @publicDocs\n */\n// oxlint-disable-next-line complexity -- ordered assembly of optional Shopify script tags; each flag adds one branch and splitting would obscure the required load order\nexport function getShopifyScriptTags({\n account = false,\n analytics,\n consent,\n debug,\n i18n,\n nonce,\n shop,\n shopifyAnalytics = true,\n inbox = false,\n}: ShopifyScriptTagsOptions): ShopifyScriptTagDescriptors {\n const nonceAttributes = nonce !== undefined ? { nonce } : undefined;\n const analyticsConfig = getShopifyAnalyticsConfig({ analytics, consent, shop });\n\n const links: ShopifyLinkDescriptor[] = [\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_CDN_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_SHOP_APP_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"prefetch\",\n as: \"script\",\n href: SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n crossorigin: \"anonymous\",\n },\n },\n ];\n const scripts: ShopifyScriptDescriptor[] = [\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-global-bootstrap\",\n ...nonceAttributes,\n ...shopifyGlobalBootstrap.attributes(getShopifyGlobalConfig({ i18n, shop })),\n },\n innerHTML: shopifyGlobalBootstrap.code,\n },\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-actions\",\n type: \"module\",\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n },\n },\n ];\n\n if (__DEV__ && debug?.standardEventsInspector) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-events-inspector\",\n defer: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n },\n });\n }\n\n if (inbox) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-inbox\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_INBOX_SCRIPT,\n },\n });\n }\n\n if (account) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-account\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_ACCOUNT_SCRIPT,\n },\n });\n }\n\n // Install readiness listeners before loading the async consent library so a\n // cached script cannot finish initialization before Hydrogen starts listening.\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-analytics-bus\",\n ...nonceAttributes,\n ...shopifyAnalyticsBootstrap.attributes(analyticsConfig),\n },\n innerHTML: shopifyAnalyticsBootstrap.code,\n });\n\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_CONSENT_SCRIPT_ID,\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src:\n consent?.mode === \"default-banner\"\n ? SHOPIFY_PRIVACY_BANNER_SCRIPT\n : SHOPIFY_CONSENT_API_SCRIPT,\n },\n });\n\n if (shopifyAnalytics) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-storefront-analytics\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n },\n });\n }\n\n const perfKitScript = getPerfKitScript(shop, nonceAttributes);\n if (perfKitScript) {\n scripts.push(perfKitScript);\n }\n\n return {\n links,\n scripts,\n get tags() {\n return [...links, ...scripts];\n },\n };\n}\n\n/**\n * Renders Shopify's storefront script and link tags to HTML strings.\n *\n * Use the function when your framework accepts raw HTML in the document head.\n *\n * @param options The shop details and the features, such as account and analytics, whose scripts to load.\n * @returns One HTML string per tag, with link tags first.\n * @publicDocs\n */\nexport function renderShopifyScriptTags(options: ShopifyScriptTagsOptions): string[] {\n return getShopifyScriptTags(options).tags.map(renderShopifyScriptTag);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,qBAAqB,EACnC,UAAU,OACV,WACA,SACA,OACA,MACA,OACA,MACA,mBAAmB,MACnB,QAAQ,SACgD;CACxD,MAAM,kBAAkB,UAAU,SAAY,EAAE,OAAO,GAAG;CAC1D,MAAM,kBAAkB,0BAA0B;EAAE;EAAW;EAAS;EAAM,CAAC;CAE/E,MAAM,QAAiC;EACrC;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,MAAM;IACP;GACF;EACD;GACE,SAAS;GACT,YAAY;IACV,KAAK;IACL,IAAI;IACJ,MAAM;IACN,aAAa;IACd;GACF;EACF;CACD,MAAM,UAAqC,CACzC;EACE,SAAS;EACT,YAAY;GACV,IAAI;GACJ,GAAG;GACH,GAAG,uBAAuB,WAAW,uBAAuB;IAAE;IAAM;IAAM,CAAC,CAAC;GAC7E;EACD,WAAW,uBAAuB;EACnC,EACD;EACE,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CACF;AAeD,KAAI,MACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAGJ,KAAI,QACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,MAAM;GACN,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;AAKJ,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,GAAG;GACH,GAAG,0BAA0B,WAAW,gBAAgB;GACzD;EACD,WAAW,0BAA0B;EACtC,CAAC;AAEF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KACE,SAAS,SAAS,mBACd,gCACA;GACP;EACF,CAAC;AAEF,KAAI,iBACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;CAGJ,MAAM,gBAAgB,iBAAiB,MAAM,gBAAgB;AAC7D,KAAI,cACF,SAAQ,KAAK,cAAc;AAG7B,QAAO;EACL;EACA;EACA,IAAI,OAAO;AACT,UAAO,CAAC,GAAG,OAAO,GAAG,QAAQ;;EAEhC;;;;;;;;;;;AAYH,SAAgB,wBAAwB,SAA6C;AACnF,QAAO,qBAAqB,QAAQ,CAAC,KAAK,IAAI,uBAAuB"}
@@ -5,7 +5,10 @@ import { observeNavigation } from "./utils/navigation.mjs";
5
5
  let cleanupPageViewEvents;
6
6
  const getPageKey = () => `${window.location.pathname}${window.location.search}`;
7
7
  const getPageTemplate = (url = window.location.href) => window.Shopify?.routes?.match?.(url)?.pageTemplateName ?? "unknown";
8
- const importStandardEventsFromCDN = () => import("https://cdn.shopify.com/storefront/standard-events.js");
8
+ const importStandardEventsFromCDN = () => import(
9
+ /* webpackIgnore: true */
10
+ "https://cdn.shopify.com/storefront/standard-events.js"
11
+ );
9
12
  function initializeShopifyPageViewEvents(importStandardEvents = importStandardEventsFromCDN) {
10
13
  if (cleanupPageViewEvents) return cleanupPageViewEvents;
11
14
  document.getElementById(SHOPIFY_PERF_KIT_SCRIPT_ID)?.setAttribute("data-page-type", getPageTemplate());
@@ -1 +1 @@
1
- {"version":3,"file":"page-view.mjs","names":[],"sources":["../../../src/core/shopify-scripts/page-view.ts"],"sourcesContent":["import type * as StandardEventsModule from \"../../../vendor/standard-events\";\nimport { SHOPIFY_PERF_KIT_SCRIPT_ID } from \"./constants\";\nimport { observeNavigation } from \"./utils/navigation\";\n\nlet cleanupPageViewEvents: (() => void) | undefined;\n\nconst getPageKey = () => `${window.location.pathname}${window.location.search}`;\nconst getPageTemplate = (url = window.location.href) =>\n window.Shopify?.routes?.match?.(url)?.pageTemplateName ?? \"unknown\";\n\n// Keep this URL inline so consumer bundlers such as Vite recognize it as an external import.\nconst importStandardEventsFromCDN: () => Promise<\n Pick<typeof StandardEventsModule, \"PageViewEvent\">\n> = () =>\n // @ts-expect-error CDN package without automatic types\n import(\"https://cdn.shopify.com/storefront/standard-events.js\");\n\nexport function initializeShopifyPageViewEvents(\n importStandardEvents = importStandardEventsFromCDN,\n) {\n if (cleanupPageViewEvents) return cleanupPageViewEvents;\n\n // Update the PerfKit script with the current page type since it\n // might miss the initial page view if it was loaded after the script.\n document\n .getElementById(SHOPIFY_PERF_KIT_SCRIPT_ID)\n ?.setAttribute(\"data-page-type\", getPageTemplate());\n\n const standardEventsPromise = importStandardEvents().catch(() => undefined);\n let lastPageKey = getPageKey();\n let scheduledNavigation: number | undefined;\n\n const emitPageView = () => {\n const page = {\n template: getPageTemplate(),\n title: document.title,\n url: window.location.href,\n } satisfies StandardEventsModule.PageViewEvent[\"page\"];\n\n void standardEventsPromise.then((StandardEvents) => {\n if (!StandardEvents) return;\n document.dispatchEvent(new StandardEvents.PageViewEvent({ page }));\n });\n };\n\n const stopObservingNavigation = observeNavigation(() => {\n const pageKey = getPageKey();\n if (pageKey === lastPageKey) return;\n\n lastPageKey = pageKey;\n if (scheduledNavigation !== undefined) {\n cancelAnimationFrame(scheduledNavigation);\n }\n scheduledNavigation = requestAnimationFrame(() => {\n scheduledNavigation = undefined;\n emitPageView();\n });\n });\n\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", emitPageView, { once: true });\n } else {\n emitPageView();\n }\n\n cleanupPageViewEvents = () => {\n document.removeEventListener(\"DOMContentLoaded\", emitPageView);\n stopObservingNavigation();\n if (scheduledNavigation !== undefined) cancelAnimationFrame(scheduledNavigation);\n cleanupPageViewEvents = undefined;\n };\n\n return cleanupPageViewEvents;\n}\n"],"mappings":";;;;AAIA,IAAI;AAEJ,MAAM,mBAAmB,GAAG,OAAO,SAAS,WAAW,OAAO,SAAS;AACvE,MAAM,mBAAmB,MAAM,OAAO,SAAS,SAC7C,OAAO,SAAS,QAAQ,QAAQ,IAAI,EAAE,oBAAoB;AAG5D,MAAM,oCAIJ,OAAO;AAET,SAAgB,gCACd,uBAAuB,6BACvB;AACA,KAAI,sBAAuB,QAAO;AAIlC,UACG,eAAe,2BAA2B,EACzC,aAAa,kBAAkB,iBAAiB,CAAC;CAErD,MAAM,wBAAwB,sBAAsB,CAAC,YAAY,OAAU;CAC3E,IAAI,cAAc,YAAY;CAC9B,IAAI;CAEJ,MAAM,qBAAqB;EACzB,MAAM,OAAO;GACX,UAAU,iBAAiB;GAC3B,OAAO,SAAS;GAChB,KAAK,OAAO,SAAS;GACtB;AAED,EAAK,sBAAsB,MAAM,mBAAmB;AAClD,OAAI,CAAC,eAAgB;AACrB,YAAS,cAAc,IAAI,eAAe,cAAc,EAAE,MAAM,CAAC,CAAC;IAClE;;CAGJ,MAAM,0BAA0B,wBAAwB;EACtD,MAAM,UAAU,YAAY;AAC5B,MAAI,YAAY,YAAa;AAE7B,gBAAc;AACd,MAAI,wBAAwB,OAC1B,sBAAqB,oBAAoB;AAE3C,wBAAsB,4BAA4B;AAChD,yBAAsB;AACtB,iBAAc;IACd;GACF;AAEF,KAAI,SAAS,eAAe,UAC1B,UAAS,iBAAiB,oBAAoB,cAAc,EAAE,MAAM,MAAM,CAAC;KAE3E,eAAc;AAGhB,+BAA8B;AAC5B,WAAS,oBAAoB,oBAAoB,aAAa;AAC9D,2BAAyB;AACzB,MAAI,wBAAwB,OAAW,sBAAqB,oBAAoB;AAChF,0BAAwB;;AAG1B,QAAO"}
1
+ {"version":3,"file":"page-view.mjs","names":[],"sources":["../../../src/core/shopify-scripts/page-view.ts"],"sourcesContent":["import type * as StandardEventsModule from \"../../../vendor/standard-events\";\nimport { SHOPIFY_PERF_KIT_SCRIPT_ID } from \"./constants\";\nimport { observeNavigation } from \"./utils/navigation\";\n\nlet cleanupPageViewEvents: (() => void) | undefined;\n\nconst getPageKey = () => `${window.location.pathname}${window.location.search}`;\nconst getPageTemplate = (url = window.location.href) =>\n window.Shopify?.routes?.match?.(url)?.pageTemplateName ?? \"unknown\";\n\n// Keep this URL inline so consumer bundlers such as Vite recognize it as an external import.\n// webpack can't build URL imports and Turbopack turns them into a require() that fails in the\n// browser, so webpackIgnore tells both to leave the native import alone.\nconst importStandardEventsFromCDN: () => Promise<\n Pick<typeof StandardEventsModule, \"PageViewEvent\">\n> = () =>\n // @ts-expect-error CDN package without automatic types\n import(/* webpackIgnore: true */ \"https://cdn.shopify.com/storefront/standard-events.js\");\n\nexport function initializeShopifyPageViewEvents(\n importStandardEvents = importStandardEventsFromCDN,\n) {\n if (cleanupPageViewEvents) return cleanupPageViewEvents;\n\n // Update the PerfKit script with the current page type since it\n // might miss the initial page view if it was loaded after the script.\n document\n .getElementById(SHOPIFY_PERF_KIT_SCRIPT_ID)\n ?.setAttribute(\"data-page-type\", getPageTemplate());\n\n const standardEventsPromise = importStandardEvents().catch(() => undefined);\n let lastPageKey = getPageKey();\n let scheduledNavigation: number | undefined;\n\n const emitPageView = () => {\n const page = {\n template: getPageTemplate(),\n title: document.title,\n url: window.location.href,\n } satisfies StandardEventsModule.PageViewEvent[\"page\"];\n\n void standardEventsPromise.then((StandardEvents) => {\n if (!StandardEvents) return;\n document.dispatchEvent(new StandardEvents.PageViewEvent({ page }));\n });\n };\n\n const stopObservingNavigation = observeNavigation(() => {\n const pageKey = getPageKey();\n if (pageKey === lastPageKey) return;\n\n lastPageKey = pageKey;\n if (scheduledNavigation !== undefined) {\n cancelAnimationFrame(scheduledNavigation);\n }\n scheduledNavigation = requestAnimationFrame(() => {\n scheduledNavigation = undefined;\n emitPageView();\n });\n });\n\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", emitPageView, { once: true });\n } else {\n emitPageView();\n }\n\n cleanupPageViewEvents = () => {\n document.removeEventListener(\"DOMContentLoaded\", emitPageView);\n stopObservingNavigation();\n if (scheduledNavigation !== undefined) cancelAnimationFrame(scheduledNavigation);\n cleanupPageViewEvents = undefined;\n };\n\n return cleanupPageViewEvents;\n}\n"],"mappings":";;;;AAIA,IAAI;AAEJ,MAAM,mBAAmB,GAAG,OAAO,SAAS,WAAW,OAAO,SAAS;AACvE,MAAM,mBAAmB,MAAM,OAAO,SAAS,SAC7C,OAAO,SAAS,QAAQ,QAAQ,IAAI,EAAE,oBAAoB;AAK5D,MAAM,oCAIJ;;CAAiC;;AAEnC,SAAgB,gCACd,uBAAuB,6BACvB;AACA,KAAI,sBAAuB,QAAO;AAIlC,UACG,eAAe,2BAA2B,EACzC,aAAa,kBAAkB,iBAAiB,CAAC;CAErD,MAAM,wBAAwB,sBAAsB,CAAC,YAAY,OAAU;CAC3E,IAAI,cAAc,YAAY;CAC9B,IAAI;CAEJ,MAAM,qBAAqB;EACzB,MAAM,OAAO;GACX,UAAU,iBAAiB;GAC3B,OAAO,SAAS;GAChB,KAAK,OAAO,SAAS;GACtB;AAED,EAAK,sBAAsB,MAAM,mBAAmB;AAClD,OAAI,CAAC,eAAgB;AACrB,YAAS,cAAc,IAAI,eAAe,cAAc,EAAE,MAAM,CAAC,CAAC;IAClE;;CAGJ,MAAM,0BAA0B,wBAAwB;EACtD,MAAM,UAAU,YAAY;AAC5B,MAAI,YAAY,YAAa;AAE7B,gBAAc;AACd,MAAI,wBAAwB,OAC1B,sBAAqB,oBAAoB;AAE3C,wBAAsB,4BAA4B;AAChD,yBAAsB;AACtB,iBAAc;IACd;GACF;AAEF,KAAI,SAAS,eAAe,UAC1B,UAAS,iBAAiB,oBAAoB,cAAc,EAAE,MAAM,MAAM,CAAC;KAE3E,eAAc;AAGhB,+BAA8B;AAC5B,WAAS,oBAAoB,oBAAoB,aAAa;AAC9D,2BAAyB;AACzB,MAAI,wBAAwB,OAAW,sBAAqB,oBAAoB;AAChF,0BAAwB;;AAG1B,QAAO"}
@@ -1,8 +1,10 @@
1
+ import { SHOPIFY_API_PROXY_PREFIX } from "../url.mjs";
1
2
  import { SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT_ID } from "./constants.mjs";
2
3
 
3
4
  //#region src/core/shopify-scripts/perfkit.ts
4
5
  const SHOPIFY_SHOP_ID_PATTERN = /^\d+$/;
5
- function getPerfKitScript(shop, extraAttributes) {
6
+ const SHS_BEACON_ENDPOINT = `${SHOPIFY_API_PROXY_PREFIX}/api/collect`;
7
+ function getPerfKitScript(shop, extraAttributes, { shs = true } = {}) {
6
8
  if (!shop.storefrontId) return;
7
9
  const shopId = parseNumericShopId(shop.shopId);
8
10
  if (!shopId) return;
@@ -18,7 +20,11 @@ function getPerfKitScript(shop, extraAttributes) {
18
20
  "data-storefront-id": shop.storefrontId,
19
21
  "data-monorail-region": "global",
20
22
  "data-spa-mode": "true",
21
- "data-resource-timing-sampling-rate": "10"
23
+ "data-resource-timing-sampling-rate": "10",
24
+ ...shs ? {
25
+ "data-shs": "true",
26
+ "data-shs-beacon-endpoint": SHS_BEACON_ENDPOINT
27
+ } : {}
22
28
  }
23
29
  };
24
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"perfkit.mjs","names":[],"sources":["../../../src/core/shopify-scripts/perfkit.ts"],"sourcesContent":["import { SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT_ID } from \"./constants\";\nimport type {\n ShopifyScriptDescriptor,\n ShopifyScriptsShop,\n ShopifyScriptTagAttributes,\n} from \"./types\";\n\nconst SHOPIFY_SHOP_ID_PATTERN = /^\\d+$/;\n\nexport function getPerfKitScript(\n shop: ShopifyScriptsShop,\n extraAttributes?: Pick<ShopifyScriptTagAttributes, \"nonce\">,\n): ShopifyScriptDescriptor | undefined {\n if (!shop.storefrontId) return;\n\n const shopId = parseNumericShopId(shop.shopId);\n if (!shopId) return;\n\n return {\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_PERF_KIT_SCRIPT_ID,\n ...extraAttributes,\n async: true,\n src: SHOPIFY_PERF_KIT_SCRIPT,\n \"data-application\": \"hydrogen\",\n \"data-shop-id\": shopId,\n \"data-storefront-id\": shop.storefrontId,\n \"data-monorail-region\": \"global\",\n \"data-spa-mode\": \"true\",\n \"data-resource-timing-sampling-rate\": \"10\",\n },\n };\n}\n\nfunction parseNumericShopId(shopId: ShopifyScriptsShop[\"shopId\"]): string | undefined {\n const parsedShopId = shopId.split(\"/\").pop();\n if (!parsedShopId) return;\n\n return SHOPIFY_SHOP_ID_PATTERN.test(parsedShopId) ? parsedShopId : undefined;\n}\n"],"mappings":";;;AAOA,MAAM,0BAA0B;AAEhC,SAAgB,iBACd,MACA,iBACqC;AACrC,KAAI,CAAC,KAAK,aAAc;CAExB,MAAM,SAAS,mBAAmB,KAAK,OAAO;AAC9C,KAAI,CAAC,OAAQ;AAEb,QAAO;EACL,SAAS;EACT,YAAY;GACV,IAAI;GACJ,GAAG;GACH,OAAO;GACP,KAAK;GACL,oBAAoB;GACpB,gBAAgB;GAChB,sBAAsB,KAAK;GAC3B,wBAAwB;GACxB,iBAAiB;GACjB,sCAAsC;GACvC;EACF;;AAGH,SAAS,mBAAmB,QAA0D;CACpF,MAAM,eAAe,OAAO,MAAM,IAAI,CAAC,KAAK;AAC5C,KAAI,CAAC,aAAc;AAEnB,QAAO,wBAAwB,KAAK,aAAa,GAAG,eAAe"}
1
+ {"version":3,"file":"perfkit.mjs","names":[],"sources":["../../../src/core/shopify-scripts/perfkit.ts"],"sourcesContent":["import { SHOPIFY_API_PROXY_PREFIX } from \"../url\";\nimport { SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT_ID } from \"./constants\";\nimport type {\n ShopifyScriptDescriptor,\n ShopifyScriptsShop,\n ShopifyScriptTagAttributes,\n} from \"./types\";\n\nconst SHOPIFY_SHOP_ID_PATTERN = /^\\d+$/;\nconst SHS_BEACON_ENDPOINT = `${SHOPIFY_API_PROXY_PREFIX}/api/collect`;\n\ntype PerfKitScriptOptions = {\n shs?: boolean;\n};\n\nexport function getPerfKitScript(\n shop: ShopifyScriptsShop,\n extraAttributes?: Pick<ShopifyScriptTagAttributes, \"nonce\">,\n { shs = !__DEV__ }: PerfKitScriptOptions = {},\n): ShopifyScriptDescriptor | undefined {\n if (!shop.storefrontId) return;\n\n const shopId = parseNumericShopId(shop.shopId);\n if (!shopId) return;\n\n return {\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_PERF_KIT_SCRIPT_ID,\n ...extraAttributes,\n async: true,\n src: SHOPIFY_PERF_KIT_SCRIPT,\n \"data-application\": \"hydrogen\",\n \"data-shop-id\": shopId,\n \"data-storefront-id\": shop.storefrontId,\n \"data-monorail-region\": \"global\",\n \"data-spa-mode\": \"true\",\n \"data-resource-timing-sampling-rate\": \"10\",\n ...(shs\n ? {\n \"data-shs\": \"true\",\n \"data-shs-beacon-endpoint\": SHS_BEACON_ENDPOINT,\n }\n : {}),\n },\n };\n}\n\nfunction parseNumericShopId(shopId: ShopifyScriptsShop[\"shopId\"]): string | undefined {\n const parsedShopId = shopId.split(\"/\").pop();\n if (!parsedShopId) return;\n\n return SHOPIFY_SHOP_ID_PATTERN.test(parsedShopId) ? parsedShopId : undefined;\n}\n"],"mappings":";;;;AAQA,MAAM,0BAA0B;AAChC,MAAM,sBAAsB,GAAG,yBAAyB;AAMxD,SAAgB,iBACd,MACA,iBACA,EAAE,MAAM,SAAmC,EAAE,EACR;AACrC,KAAI,CAAC,KAAK,aAAc;CAExB,MAAM,SAAS,mBAAmB,KAAK,OAAO;AAC9C,KAAI,CAAC,OAAQ;AAEb,QAAO;EACL,SAAS;EACT,YAAY;GACV,IAAI;GACJ,GAAG;GACH,OAAO;GACP,KAAK;GACL,oBAAoB;GACpB,gBAAgB;GAChB,sBAAsB,KAAK;GAC3B,wBAAwB;GACxB,iBAAiB;GACjB,sCAAsC;GACtC,GAAI,MACA;IACE,YAAY;IACZ,4BAA4B;IAC7B,GACD,EAAE;GACP;EACF;;AAGH,SAAS,mBAAmB,QAA0D;CACpF,MAAM,eAAe,OAAO,MAAM,IAAI,CAAC,KAAK;AAC5C,KAAI,CAAC,aAAc;AAEnB,QAAO,wBAAwB,KAAK,aAAa,GAAG,eAAe"}
@@ -1,4 +1,4 @@
1
- import { I18nConfig } from "../request-context.mjs";
1
+ import { ShopifyLocale } from "../i18n/types.mjs";
2
2
  import { ShopifyRouteTemplates } from "../standard-routes/types.mjs";
3
3
  import { ShopifyGlobal } from "../../globals.mjs";
4
4
  import { ConsentConfig, ShopAnalyticsChannel, StorefrontAnalyticsConfig } from "../analytics/types.mjs";
@@ -10,7 +10,9 @@ type ShopifyScriptsAnalyticsConfig = {
10
10
  customData?: StorefrontAnalyticsConfig["customData"];
11
11
  };
12
12
  /** The locale that Shopify's scripts read from the browser's Shopify global. */
13
- interface ShopifyScriptsI18n extends Pick<I18nConfig, "country" | "language">, Partial<Pick<I18nConfig, "pathPrefix">> {
13
+ interface ShopifyScriptsI18n extends ShopifyLocale {
14
+ /** The URL prefix for localized routes, such as `/es-es`. Leave it empty for the default locale. */
15
+ pathPrefix?: string;
14
16
  /** The active currency code. Hydrogen converts it to uppercase. */
15
17
  currency?: string;
16
18
  }
@@ -1,6 +1,9 @@
1
1
  //#region src/core/shopify-scripts/utils/inline-script.ts
2
2
  function asInlineScript(script) {
3
- return script;
3
+ return {
4
+ code: script,
5
+ attributes: (config) => ({ "data-config": JSON.stringify(config).replace(/&/g, "\\u0026") })
6
+ };
4
7
  }
5
8
 
6
9
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"inline-script.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/utils/inline-script.ts"],"sourcesContent":["type InlineScriptSource = (...args: never[]) => unknown;\n\ntype InlineScriptFactory<T extends InlineScriptSource> = (...args: Parameters<T>) => string;\n\nexport function asInlineScript<T extends InlineScriptSource>(script: T): InlineScriptFactory<T>;\nexport function asInlineScript(script: InlineScriptSource) {\n return script;\n}\n"],"mappings":";AAKA,SAAgB,eAAe,QAA4B;AACzD,QAAO"}
1
+ {"version":3,"file":"inline-script.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/utils/inline-script.ts"],"sourcesContent":["type InlineScriptSource = (...args: never[]) => unknown;\n\ntype InlineScript<T extends InlineScriptSource> = {\n readonly code: string;\n attributes(config: NonNullable<Parameters<T>[0]>): { \"data-config\": string };\n};\n\nexport function asInlineScript<T extends InlineScriptSource>(script: T): InlineScript<T>;\nexport function asInlineScript(script: InlineScriptSource): unknown {\n return {\n code: script,\n // Some attribute renderers only escape quotes. Prevent HTML entity decoding from changing JSON.\n attributes: (config: unknown) => ({\n \"data-config\": JSON.stringify(config).replace(/&/g, \"\\\\u0026\"),\n }),\n };\n}\n"],"mappings":";AAQA,SAAgB,eAAe,QAAqC;AAClE,QAAO;EACL,MAAM;EAEN,aAAa,YAAqB,EAChC,eAAe,KAAK,UAAU,OAAO,CAAC,QAAQ,MAAM,UAAU,EAC/D;EACF"}
@@ -17,7 +17,7 @@ import { ShopifyRouteTemplates } from "./types.mjs";
17
17
  * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.
18
18
  * @example
19
19
  * ```ts
20
- * const routeTemplates = createShopifyRouteTemplates({
20
+ * const routeTemplates = defineShopifyRouteTemplates({
21
21
  * product: "/p/:productHandle",
22
22
  * collection: "/c/:collectionHandle",
23
23
  * article: "/journal/:blogHandle/:articleHandle",
@@ -27,7 +27,12 @@ import { ShopifyRouteTemplates } from "./types.mjs";
27
27
  * ```
28
28
  * @publicDocs
29
29
  */
30
+ declare function defineShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(routes: TRoutes): TRoutes;
31
+ /**
32
+ * @deprecated Renamed to `defineShopifyRouteTemplates`. This alias will be removed in the next
33
+ * major release.
34
+ */
30
35
  declare function createShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(routes: TRoutes): TRoutes;
31
36
  //#endregion
32
- export { createShopifyRouteTemplates };
37
+ export { createShopifyRouteTemplates, defineShopifyRouteTemplates };
33
38
  //# sourceMappingURL=build.d.mts.map
@@ -18,7 +18,7 @@ import { prependPathPrefix } from "./path.mjs";
18
18
  * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.
19
19
  * @example
20
20
  * ```ts
21
- * const routeTemplates = createShopifyRouteTemplates({
21
+ * const routeTemplates = defineShopifyRouteTemplates({
22
22
  * product: "/p/:productHandle",
23
23
  * collection: "/c/:collectionHandle",
24
24
  * article: "/journal/:blogHandle/:articleHandle",
@@ -28,9 +28,16 @@ import { prependPathPrefix } from "./path.mjs";
28
28
  * ```
29
29
  * @publicDocs
30
30
  */
31
- function createShopifyRouteTemplates(routes) {
31
+ function defineShopifyRouteTemplates(routes) {
32
32
  return routes;
33
33
  }
34
+ /**
35
+ * @deprecated Renamed to `defineShopifyRouteTemplates`. This alias will be removed in the next
36
+ * major release.
37
+ */
38
+ function createShopifyRouteTemplates(routes) {
39
+ return defineShopifyRouteTemplates(routes);
40
+ }
34
41
  function getStandardRoute(routeTemplates, route, params, options = {}) {
35
42
  return buildStandardRouteTarget(routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0], params, options.pathPrefix);
36
43
  }
@@ -49,5 +56,5 @@ function interpolateRouteTemplate(template, params) {
49
56
  }
50
57
 
51
58
  //#endregion
52
- export { buildStandardRouteTarget, createShopifyRouteTemplates, getStandardRoute };
59
+ export { buildStandardRouteTarget, createShopifyRouteTemplates, defineShopifyRouteTemplates, getStandardRoute };
53
60
  //# sourceMappingURL=build.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.mjs","names":[],"sources":["../../../src/core/standard-routes/build.ts"],"sourcesContent":["import { DEFAULT_STANDARD_ROUTES, isStandardRouteParamName } from \"./defaults\";\nimport { prependPathPrefix } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n StandardRouteName,\n StandardRouteOptions,\n StandardRouteParams,\n StandardRouteParamsByName,\n} from \"./types\";\n\n/**\n * Tells Hydrogen where your app serves products, collections, and other Shopify resources. Pass\n * the returned object to `handleShopifyRoutes`, `handleShopifyRedirects`, the `ShopifyScripts` `routes`\n * option, and the predictive search URL helpers.\n *\n * Add a key only for a route that your app serves at a non-standard path. Hydrogen uses Shopify's\n * default path for each key that you leave out. Pass an empty object when your app serves every\n * route at its default path. Each template starts with `/` and includes the handle placeholders\n * for its route. Leave the locale path prefix out of templates. Hydrogen adds the prefix for you.\n *\n * TypeScript checks the shape of each template. The function returns the object that you pass.\n *\n * @param routes The non-standard paths that your app serves, keyed by standard route name.\n * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.\n * @example\n * ```ts\n * const routeTemplates = createShopifyRouteTemplates({\n * product: \"/p/:productHandle\",\n * collection: \"/c/:collectionHandle\",\n * article: \"/journal/:blogHandle/:articleHandle\",\n * cart: \"/basket\",\n * policy: \"/legal/:policyHandle\",\n * });\n * ```\n * @publicDocs\n */\nexport function createShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return routes;\n}\n\nexport function getStandardRoute<const TRoute extends StandardRouteName>(\n routeTemplates: ShopifyRouteTemplates,\n route: TRoute,\n params: StandardRouteParamsByName[TRoute],\n options: StandardRouteOptions = {},\n): string {\n const target = routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0];\n\n return buildStandardRouteTarget(target, params, options.pathPrefix);\n}\n\n/**\n * Builds a pathname from a route template, handle params, and optional i18n path prefix.\n */\nexport function buildStandardRouteTarget(\n template: string,\n params: StandardRouteParams,\n pathPrefix: string | undefined,\n): string {\n return prependPathPrefix(interpolateRouteTemplate(template, params), pathPrefix);\n}\n\nfunction interpolateRouteTemplate(template: string, params: StandardRouteParams): string {\n return template.replace(/:([A-Za-z][A-Za-z0-9_]*)/g, (placeholder, name: string) => {\n if (!isStandardRouteParamName(name)) return placeholder;\n\n const value = params[name];\n return value === undefined ? placeholder : encodeURIComponent(value);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,4BACd,QACS;AACT,QAAO;;AAGT,SAAgB,iBACd,gBACA,OACA,QACA,UAAgC,EAAE,EAC1B;AAGR,QAAO,yBAFQ,eAAe,UAAU,wBAAwB,OAAO,IAE/B,QAAQ,QAAQ,WAAW;;;;;AAMrE,SAAgB,yBACd,UACA,QACA,YACQ;AACR,QAAO,kBAAkB,yBAAyB,UAAU,OAAO,EAAE,WAAW;;AAGlF,SAAS,yBAAyB,UAAkB,QAAqC;AACvF,QAAO,SAAS,QAAQ,8BAA8B,aAAa,SAAiB;AAClF,MAAI,CAAC,yBAAyB,KAAK,CAAE,QAAO;EAE5C,MAAM,QAAQ,OAAO;AACrB,SAAO,UAAU,SAAY,cAAc,mBAAmB,MAAM;GACpE"}
1
+ {"version":3,"file":"build.mjs","names":[],"sources":["../../../src/core/standard-routes/build.ts"],"sourcesContent":["import { DEFAULT_STANDARD_ROUTES, isStandardRouteParamName } from \"./defaults\";\nimport { prependPathPrefix } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n StandardRouteName,\n StandardRouteOptions,\n StandardRouteParams,\n StandardRouteParamsByName,\n} from \"./types\";\n\n/**\n * Tells Hydrogen where your app serves products, collections, and other Shopify resources. Pass\n * the returned object to `handleShopifyRoutes`, `handleShopifyRedirects`, the `ShopifyScripts` `routes`\n * option, and the predictive search URL helpers.\n *\n * Add a key only for a route that your app serves at a non-standard path. Hydrogen uses Shopify's\n * default path for each key that you leave out. Pass an empty object when your app serves every\n * route at its default path. Each template starts with `/` and includes the handle placeholders\n * for its route. Leave the locale path prefix out of templates. Hydrogen adds the prefix for you.\n *\n * TypeScript checks the shape of each template. The function returns the object that you pass.\n *\n * @param routes The non-standard paths that your app serves, keyed by standard route name.\n * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.\n * @example\n * ```ts\n * const routeTemplates = defineShopifyRouteTemplates({\n * product: \"/p/:productHandle\",\n * collection: \"/c/:collectionHandle\",\n * article: \"/journal/:blogHandle/:articleHandle\",\n * cart: \"/basket\",\n * policy: \"/legal/:policyHandle\",\n * });\n * ```\n * @publicDocs\n */\nexport function defineShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return routes;\n}\n\n/**\n * @deprecated Renamed to `defineShopifyRouteTemplates`. This alias will be removed in the next\n * major release.\n */\nexport function createShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return defineShopifyRouteTemplates(routes);\n}\n\nexport function getStandardRoute<const TRoute extends StandardRouteName>(\n routeTemplates: ShopifyRouteTemplates,\n route: TRoute,\n params: StandardRouteParamsByName[TRoute],\n options: StandardRouteOptions = {},\n): string {\n const target = routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0];\n\n return buildStandardRouteTarget(target, params, options.pathPrefix);\n}\n\n/**\n * Builds a pathname from a route template, handle params, and optional i18n path prefix.\n */\nexport function buildStandardRouteTarget(\n template: string,\n params: StandardRouteParams,\n pathPrefix: string | undefined,\n): string {\n return prependPathPrefix(interpolateRouteTemplate(template, params), pathPrefix);\n}\n\nfunction interpolateRouteTemplate(template: string, params: StandardRouteParams): string {\n return template.replace(/:([A-Za-z][A-Za-z0-9_]*)/g, (placeholder, name: string) => {\n if (!isStandardRouteParamName(name)) return placeholder;\n\n const value = params[name];\n return value === undefined ? placeholder : encodeURIComponent(value);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,4BACd,QACS;AACT,QAAO;;;;;;AAOT,SAAgB,4BACd,QACS;AACT,QAAO,4BAA4B,OAAO;;AAG5C,SAAgB,iBACd,gBACA,OACA,QACA,UAAgC,EAAE,EAC1B;AAGR,QAAO,yBAFQ,eAAe,UAAU,wBAAwB,OAAO,IAE/B,QAAQ,QAAQ,WAAW;;;;;AAMrE,SAAgB,yBACd,UACA,QACA,YACQ;AACR,QAAO,kBAAkB,yBAAyB,UAAU,OAAO,EAAE,WAAW;;AAGlF,SAAS,yBAAyB,UAAkB,QAAqC;AACvF,QAAO,SAAS,QAAQ,8BAA8B,aAAa,SAAiB;AAClF,MAAI,CAAC,yBAAyB,KAAK,CAAE,QAAO;EAE5C,MAAM,QAAQ,OAAO;AACrB,SAAO,UAAU,SAAY,cAAc,mBAAmB,MAAM;GACpE"}
@@ -23,7 +23,7 @@ function matchStandardRouteUrl({ baseUrl, pathPrefix, routeTemplates, url }) {
23
23
  return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;
24
24
  }
25
25
  function addStandardRouteContext(match, pathPrefix, routeTemplates) {
26
- const standardTemplate = match.route === "index" ? "/" : DEFAULT_STANDARD_ROUTES[match.route][0];
26
+ const standardTemplate = standardTemplateFor(match);
27
27
  const customTemplate = match.route === "index" ? standardTemplate : routeTemplates[match.route] ?? standardTemplate;
28
28
  return {
29
29
  ...match,
@@ -35,6 +35,16 @@ function addStandardRouteContext(match, pathPrefix, routeTemplates) {
35
35
  };
36
36
  }
37
37
  /**
38
+ * Shopify's default template for a match. A collection-scoped product template may leave out
39
+ * `:collectionHandle`; a match through one has no collection to put in the default
40
+ * collection-scoped path, so its standard path is the product's.
41
+ */
42
+ function standardTemplateFor(match) {
43
+ if (match.route === "index") return "/";
44
+ if (match.route === "productInCollection" && match.params.collectionHandle === void 0) return DEFAULT_STANDARD_ROUTES.product[0];
45
+ return DEFAULT_STANDARD_ROUTES[match.route][0];
46
+ }
47
+ /**
38
48
  * Iterates over known Shopify route names and tries the templates supplied by the caller.
39
49
  *
40
50
  * Different callers choose different template sets: redirects only match default Shopify templates
@@ -1 +1 @@
1
- {"version":3,"file":"match.mjs","names":[],"sources":["../../../src/core/standard-routes/match.ts"],"sourcesContent":["import { buildStandardRouteTarget } from \"./build\";\nimport { DEFAULT_STANDARD_ROUTES, isStandardRouteName, isStandardRouteParamName } from \"./defaults\";\nimport { parseSameOriginUrl, stripI18nPathPrefix, stripTrailingSlash } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n ShopifyPageTemplateName,\n ShopifyStandardRouteMatch,\n ShopifyStandardRouteName,\n StandardRouteName,\n StandardRouteParams,\n} from \"./types\";\n\n/**\n * Matches a URL against both configured app route templates and standard storefront routes.\n *\n * This powers browser current-page detection, where consumers need to recognize the standard\n * Shopify resource represented by either a custom app URL like `/p/snowboard` or a standard URL\n * like `/products/snowboard`. The root and standard storefront routes retain their page-template\n * identities; configured templates identify otherwise non-standard app paths.\n */\nexport function matchStandardRouteUrl({\n baseUrl,\n pathPrefix,\n routeTemplates,\n url,\n}: {\n baseUrl?: string;\n pathPrefix?: string;\n routeTemplates: ShopifyRouteTemplates;\n url: string;\n}): ShopifyStandardRouteMatch | null {\n const parsedUrl = parseSameOriginUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const pathname = stripI18nPathPrefix(stripTrailingSlash(parsedUrl.pathname), pathPrefix);\n if (pathname === \"/\") {\n return addStandardRouteContext(\n { route: \"index\", pageTemplateName: \"index\", params: {} },\n pathPrefix,\n routeTemplates,\n );\n }\n\n const match =\n matchStandardRouteTemplates(\n parsedUrl.pathname,\n pathPrefix,\n (route) => DEFAULT_STANDARD_ROUTES[route],\n ) ??\n matchStandardRouteTemplates(parsedUrl.pathname, pathPrefix, (route) => [routeTemplates[route]]);\n\n return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;\n}\n\nfunction addStandardRouteContext(\n match: Pick<ShopifyStandardRouteMatch, \"pageTemplateName\" | \"params\" | \"route\">,\n pathPrefix: string | undefined,\n routeTemplates: ShopifyRouteTemplates,\n): ShopifyStandardRouteMatch {\n const standardTemplate = match.route === \"index\" ? \"/\" : DEFAULT_STANDARD_ROUTES[match.route][0];\n const customTemplate =\n match.route === \"index\" ? standardTemplate : (routeTemplates[match.route] ?? standardTemplate);\n\n return {\n ...match,\n standardPathname: buildStandardRouteTarget(standardTemplate, match.params, pathPrefix),\n templates: {\n standard: standardTemplate,\n custom: customTemplate,\n },\n };\n}\n\n/**\n * Iterates over known Shopify route names and tries the templates supplied by the caller.\n *\n * Different callers choose different template sets: redirects only match default Shopify templates\n * for resources with custom app templates, while browser matching tries Shopify defaults before\n * configured app templates.\n */\nexport function matchStandardRouteTemplates(\n pathname: string,\n pathPrefix: string | undefined,\n getTemplatesForRoute: (route: StandardRouteName) => ReadonlyArray<string | undefined>,\n): Pick<\n ShopifyStandardRouteMatch<StandardRouteName>,\n \"pageTemplateName\" | \"params\" | \"route\"\n> | null {\n const normalizedPathname = stripI18nPathPrefix(stripTrailingSlash(pathname), pathPrefix);\n\n for (const route in DEFAULT_STANDARD_ROUTES) {\n if (!isStandardRouteName(route)) continue;\n\n for (const template of getTemplatesForRoute(route)) {\n if (!template) continue;\n\n const match = matchRouteTemplate(normalizedPathname, template);\n if (match) {\n return {\n route,\n params: match,\n pageTemplateName: normalizeStandardRouteTemplateName(route),\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Converts a standard route identity to the corresponding page template name.\n * Collection-scoped product URLs still render the `product` template, while\n * the collection-listing route uses the hyphenated `list-collections` name.\n */\nfunction normalizeStandardRouteTemplateName<TRoute extends ShopifyStandardRouteName>(\n route: TRoute,\n): ShopifyPageTemplateName<TRoute>;\nfunction normalizeStandardRouteTemplateName(\n route: ShopifyStandardRouteName,\n): ShopifyPageTemplateName {\n if (route === \"productInCollection\") return \"product\";\n if (route === \"collectionList\") return \"list-collections\";\n return route;\n}\n\n/**\n * Matches a normalized pathname against one route template and returns decoded handle params.\n */\nfunction matchRouteTemplate(pathname: string, template: string): StandardRouteParams | null {\n const match = templateToPattern(template).exec(pathname);\n if (!match) return null;\n\n const params: StandardRouteParams = {};\n for (const [name, value] of Object.entries(match.groups ?? {})) {\n if (!isStandardRouteParamName(name)) continue;\n\n params[name] = decodePathSegment(value);\n }\n\n return params;\n}\n\n/**\n * Converts a route template into a regular expression with named capture groups.\n *\n * Static path text is escaped first so regex metacharacters in templates are treated literally.\n * Then known placeholders such as `:productHandle` become segment-safe captures like\n * `(?<productHandle>[^/]+)`.\n */\nfunction templateToPattern(template: string): RegExp {\n const source = escapeRegExp(stripTrailingSlash(template)).replace(\n /:([A-Za-z][A-Za-z0-9_]*)/g,\n (placeholder, name: string) =>\n isStandardRouteParamName(name) ? `(?<${name}>[^/]+)` : placeholder,\n );\n\n return new RegExp(`^${source}$`);\n}\n\n/**\n * Escapes regex metacharacters so template text can be embedded in a `RegExp` literally.\n *\n * For example, `/products/:productHandle.json` must match a literal `.json` suffix; without\n * escaping, `.` would mean \"any character\" in the generated regex.\n */\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction decodePathSegment(segment: string): string {\n try {\n return decodeURIComponent(segment);\n } catch {\n return segment;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,EACpC,SACA,YACA,gBACA,OAMmC;CACnC,MAAM,YAAY,mBAAmB,KAAK,QAAQ;AAClD,KAAI,CAAC,UAAW,QAAO;AAGvB,KADiB,oBAAoB,mBAAmB,UAAU,SAAS,EAAE,WACjE,KAAK,IACf,QAAO,wBACL;EAAE,OAAO;EAAS,kBAAkB;EAAS,QAAQ,EAAE;EAAE,EACzD,YACA,eACD;CAGH,MAAM,QACJ,4BACE,UAAU,UACV,aACC,UAAU,wBAAwB,OACpC,IACD,4BAA4B,UAAU,UAAU,aAAa,UAAU,CAAC,eAAe,OAAO,CAAC;AAEjG,QAAO,QAAQ,wBAAwB,OAAO,YAAY,eAAe,GAAG;;AAG9E,SAAS,wBACP,OACA,YACA,gBAC2B;CAC3B,MAAM,mBAAmB,MAAM,UAAU,UAAU,MAAM,wBAAwB,MAAM,OAAO;CAC9F,MAAM,iBACJ,MAAM,UAAU,UAAU,mBAAoB,eAAe,MAAM,UAAU;AAE/E,QAAO;EACL,GAAG;EACH,kBAAkB,yBAAyB,kBAAkB,MAAM,QAAQ,WAAW;EACtF,WAAW;GACT,UAAU;GACV,QAAQ;GACT;EACF;;;;;;;;;AAUH,SAAgB,4BACd,UACA,YACA,sBAIO;CACP,MAAM,qBAAqB,oBAAoB,mBAAmB,SAAS,EAAE,WAAW;AAExF,MAAK,MAAM,SAAS,yBAAyB;AAC3C,MAAI,CAAC,oBAAoB,MAAM,CAAE;AAEjC,OAAK,MAAM,YAAY,qBAAqB,MAAM,EAAE;AAClD,OAAI,CAAC,SAAU;GAEf,MAAM,QAAQ,mBAAmB,oBAAoB,SAAS;AAC9D,OAAI,MACF,QAAO;IACL;IACA,QAAQ;IACR,kBAAkB,mCAAmC,MAAM;IAC5D;;;AAKP,QAAO;;AAWT,SAAS,mCACP,OACyB;AACzB,KAAI,UAAU,sBAAuB,QAAO;AAC5C,KAAI,UAAU,iBAAkB,QAAO;AACvC,QAAO;;;;;AAMT,SAAS,mBAAmB,UAAkB,UAA8C;CAC1F,MAAM,QAAQ,kBAAkB,SAAS,CAAC,KAAK,SAAS;AACxD,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,UAAU,EAAE,CAAC,EAAE;AAC9D,MAAI,CAAC,yBAAyB,KAAK,CAAE;AAErC,SAAO,QAAQ,kBAAkB,MAAM;;AAGzC,QAAO;;;;;;;;;AAUT,SAAS,kBAAkB,UAA0B;CACnD,MAAM,SAAS,aAAa,mBAAmB,SAAS,CAAC,CAAC,QACxD,8BACC,aAAa,SACZ,yBAAyB,KAAK,GAAG,MAAM,KAAK,WAAW,YAC1D;AAED,QAAO,IAAI,OAAO,IAAI,OAAO,GAAG;;;;;;;;AASlC,SAAS,aAAa,OAAuB;AAC3C,QAAO,MAAM,QAAQ,uBAAuB,OAAO;;AAGrD,SAAS,kBAAkB,SAAyB;AAClD,KAAI;AACF,SAAO,mBAAmB,QAAQ;SAC5B;AACN,SAAO"}
1
+ {"version":3,"file":"match.mjs","names":[],"sources":["../../../src/core/standard-routes/match.ts"],"sourcesContent":["import { buildStandardRouteTarget } from \"./build\";\nimport { DEFAULT_STANDARD_ROUTES, isStandardRouteName, isStandardRouteParamName } from \"./defaults\";\nimport { parseSameOriginUrl, stripI18nPathPrefix, stripTrailingSlash } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n ShopifyPageTemplateName,\n ShopifyStandardRouteMatch,\n ShopifyStandardRouteName,\n StandardRouteName,\n StandardRouteParams,\n} from \"./types\";\n\n/**\n * Matches a URL against both configured app route templates and standard storefront routes.\n *\n * This powers browser current-page detection, where consumers need to recognize the standard\n * Shopify resource represented by either a custom app URL like `/p/snowboard` or a standard URL\n * like `/products/snowboard`. The root and standard storefront routes retain their page-template\n * identities; configured templates identify otherwise non-standard app paths.\n */\nexport function matchStandardRouteUrl({\n baseUrl,\n pathPrefix,\n routeTemplates,\n url,\n}: {\n baseUrl?: string;\n pathPrefix?: string;\n routeTemplates: ShopifyRouteTemplates;\n url: string;\n}): ShopifyStandardRouteMatch | null {\n const parsedUrl = parseSameOriginUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const pathname = stripI18nPathPrefix(stripTrailingSlash(parsedUrl.pathname), pathPrefix);\n if (pathname === \"/\") {\n return addStandardRouteContext(\n { route: \"index\", pageTemplateName: \"index\", params: {} },\n pathPrefix,\n routeTemplates,\n );\n }\n\n const match =\n matchStandardRouteTemplates(\n parsedUrl.pathname,\n pathPrefix,\n (route) => DEFAULT_STANDARD_ROUTES[route],\n ) ??\n matchStandardRouteTemplates(parsedUrl.pathname, pathPrefix, (route) => [routeTemplates[route]]);\n\n return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;\n}\n\nfunction addStandardRouteContext(\n match: Pick<ShopifyStandardRouteMatch, \"pageTemplateName\" | \"params\" | \"route\">,\n pathPrefix: string | undefined,\n routeTemplates: ShopifyRouteTemplates,\n): ShopifyStandardRouteMatch {\n const standardTemplate = standardTemplateFor(match);\n const customTemplate =\n match.route === \"index\" ? standardTemplate : (routeTemplates[match.route] ?? standardTemplate);\n\n return {\n ...match,\n standardPathname: buildStandardRouteTarget(standardTemplate, match.params, pathPrefix),\n templates: {\n standard: standardTemplate,\n custom: customTemplate,\n },\n };\n}\n\n/**\n * Shopify's default template for a match. A collection-scoped product template may leave out\n * `:collectionHandle`; a match through one has no collection to put in the default\n * collection-scoped path, so its standard path is the product's.\n */\nfunction standardTemplateFor(match: Pick<ShopifyStandardRouteMatch, \"params\" | \"route\">): string {\n if (match.route === \"index\") return \"/\";\n if (match.route === \"productInCollection\" && match.params.collectionHandle === undefined) {\n return DEFAULT_STANDARD_ROUTES.product[0];\n }\n return DEFAULT_STANDARD_ROUTES[match.route][0];\n}\n\n/**\n * Iterates over known Shopify route names and tries the templates supplied by the caller.\n *\n * Different callers choose different template sets: redirects only match default Shopify templates\n * for resources with custom app templates, while browser matching tries Shopify defaults before\n * configured app templates.\n */\nexport function matchStandardRouteTemplates(\n pathname: string,\n pathPrefix: string | undefined,\n getTemplatesForRoute: (route: StandardRouteName) => ReadonlyArray<string | undefined>,\n): Pick<\n ShopifyStandardRouteMatch<StandardRouteName>,\n \"pageTemplateName\" | \"params\" | \"route\"\n> | null {\n const normalizedPathname = stripI18nPathPrefix(stripTrailingSlash(pathname), pathPrefix);\n\n for (const route in DEFAULT_STANDARD_ROUTES) {\n if (!isStandardRouteName(route)) continue;\n\n for (const template of getTemplatesForRoute(route)) {\n if (!template) continue;\n\n const match = matchRouteTemplate(normalizedPathname, template);\n if (match) {\n return {\n route,\n params: match,\n pageTemplateName: normalizeStandardRouteTemplateName(route),\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Converts a standard route identity to the corresponding page template name.\n * Collection-scoped product URLs still render the `product` template, while\n * the collection-listing route uses the hyphenated `list-collections` name.\n */\nfunction normalizeStandardRouteTemplateName<TRoute extends ShopifyStandardRouteName>(\n route: TRoute,\n): ShopifyPageTemplateName<TRoute>;\nfunction normalizeStandardRouteTemplateName(\n route: ShopifyStandardRouteName,\n): ShopifyPageTemplateName {\n if (route === \"productInCollection\") return \"product\";\n if (route === \"collectionList\") return \"list-collections\";\n return route;\n}\n\n/**\n * Matches a normalized pathname against one route template and returns decoded handle params.\n */\nfunction matchRouteTemplate(pathname: string, template: string): StandardRouteParams | null {\n const match = templateToPattern(template).exec(pathname);\n if (!match) return null;\n\n const params: StandardRouteParams = {};\n for (const [name, value] of Object.entries(match.groups ?? {})) {\n if (!isStandardRouteParamName(name)) continue;\n\n params[name] = decodePathSegment(value);\n }\n\n return params;\n}\n\n/**\n * Converts a route template into a regular expression with named capture groups.\n *\n * Static path text is escaped first so regex metacharacters in templates are treated literally.\n * Then known placeholders such as `:productHandle` become segment-safe captures like\n * `(?<productHandle>[^/]+)`.\n */\nfunction templateToPattern(template: string): RegExp {\n const source = escapeRegExp(stripTrailingSlash(template)).replace(\n /:([A-Za-z][A-Za-z0-9_]*)/g,\n (placeholder, name: string) =>\n isStandardRouteParamName(name) ? `(?<${name}>[^/]+)` : placeholder,\n );\n\n return new RegExp(`^${source}$`);\n}\n\n/**\n * Escapes regex metacharacters so template text can be embedded in a `RegExp` literally.\n *\n * For example, `/products/:productHandle.json` must match a literal `.json` suffix; without\n * escaping, `.` would mean \"any character\" in the generated regex.\n */\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction decodePathSegment(segment: string): string {\n try {\n return decodeURIComponent(segment);\n } catch {\n return segment;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,EACpC,SACA,YACA,gBACA,OAMmC;CACnC,MAAM,YAAY,mBAAmB,KAAK,QAAQ;AAClD,KAAI,CAAC,UAAW,QAAO;AAGvB,KADiB,oBAAoB,mBAAmB,UAAU,SAAS,EAAE,WACjE,KAAK,IACf,QAAO,wBACL;EAAE,OAAO;EAAS,kBAAkB;EAAS,QAAQ,EAAE;EAAE,EACzD,YACA,eACD;CAGH,MAAM,QACJ,4BACE,UAAU,UACV,aACC,UAAU,wBAAwB,OACpC,IACD,4BAA4B,UAAU,UAAU,aAAa,UAAU,CAAC,eAAe,OAAO,CAAC;AAEjG,QAAO,QAAQ,wBAAwB,OAAO,YAAY,eAAe,GAAG;;AAG9E,SAAS,wBACP,OACA,YACA,gBAC2B;CAC3B,MAAM,mBAAmB,oBAAoB,MAAM;CACnD,MAAM,iBACJ,MAAM,UAAU,UAAU,mBAAoB,eAAe,MAAM,UAAU;AAE/E,QAAO;EACL,GAAG;EACH,kBAAkB,yBAAyB,kBAAkB,MAAM,QAAQ,WAAW;EACtF,WAAW;GACT,UAAU;GACV,QAAQ;GACT;EACF;;;;;;;AAQH,SAAS,oBAAoB,OAAoE;AAC/F,KAAI,MAAM,UAAU,QAAS,QAAO;AACpC,KAAI,MAAM,UAAU,yBAAyB,MAAM,OAAO,qBAAqB,OAC7E,QAAO,wBAAwB,QAAQ;AAEzC,QAAO,wBAAwB,MAAM,OAAO;;;;;;;;;AAU9C,SAAgB,4BACd,UACA,YACA,sBAIO;CACP,MAAM,qBAAqB,oBAAoB,mBAAmB,SAAS,EAAE,WAAW;AAExF,MAAK,MAAM,SAAS,yBAAyB;AAC3C,MAAI,CAAC,oBAAoB,MAAM,CAAE;AAEjC,OAAK,MAAM,YAAY,qBAAqB,MAAM,EAAE;AAClD,OAAI,CAAC,SAAU;GAEf,MAAM,QAAQ,mBAAmB,oBAAoB,SAAS;AAC9D,OAAI,MACF,QAAO;IACL;IACA,QAAQ;IACR,kBAAkB,mCAAmC,MAAM;IAC5D;;;AAKP,QAAO;;AAWT,SAAS,mCACP,OACyB;AACzB,KAAI,UAAU,sBAAuB,QAAO;AAC5C,KAAI,UAAU,iBAAkB,QAAO;AACvC,QAAO;;;;;AAMT,SAAS,mBAAmB,UAAkB,UAA8C;CAC1F,MAAM,QAAQ,kBAAkB,SAAS,CAAC,KAAK,SAAS;AACxD,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,UAAU,EAAE,CAAC,EAAE;AAC9D,MAAI,CAAC,yBAAyB,KAAK,CAAE;AAErC,SAAO,QAAQ,kBAAkB,MAAM;;AAGzC,QAAO;;;;;;;;;AAUT,SAAS,kBAAkB,UAA0B;CACnD,MAAM,SAAS,aAAa,mBAAmB,SAAS,CAAC,CAAC,QACxD,8BACC,aAAa,SACZ,yBAAyB,KAAK,GAAG,MAAM,KAAK,WAAW,YAC1D;AAED,QAAO,IAAI,OAAO,IAAI,OAAO,GAAG;;;;;;;;AASlC,SAAS,aAAa,OAAuB;AAC3C,QAAO,MAAM,QAAQ,uBAAuB,OAAO;;AAGrD,SAAS,kBAAkB,SAAyB;AAClD,KAAI;AACF,SAAO,mBAAmB,QAAQ;SAC5B;AACN,SAAO"}
@@ -6,9 +6,20 @@ function prependPathPrefix(pathname, pathPrefix) {
6
6
  }
7
7
  function normalizePathPrefix(pathPrefix) {
8
8
  if (!pathPrefix) return "";
9
- const trimmedPathPrefix = pathPrefix.trim().replace(/^\/+|\/+$/g, "");
9
+ const trimmedPathPrefix = trimTrailingSlashes(pathPrefix.trim().replace(/^\/+/, ""));
10
10
  return trimmedPathPrefix ? `/${trimmedPathPrefix}` : "";
11
11
  }
12
+ /**
13
+ * Removes every trailing `/`.
14
+ *
15
+ * A loop instead of `/\/+$/`: the regex rescans the slash run from each start position, so a
16
+ * request path with a long run of slashes not at the end takes quadratic time.
17
+ */
18
+ function trimTrailingSlashes(value) {
19
+ let end = value.length;
20
+ while (end > 0 && value[end - 1] === "/") end--;
21
+ return value.slice(0, end);
22
+ }
12
23
  function parseUrl(url, baseUrl) {
13
24
  try {
14
25
  return new URL(url, baseUrl ?? "https://shopify.local");
@@ -34,7 +45,7 @@ function isAbsoluteUrl(url) {
34
45
  }
35
46
  function stripTrailingSlash(pathname) {
36
47
  if (pathname === "/") return pathname;
37
- return pathname.replace(/\/+$/, "");
48
+ return trimTrailingSlashes(pathname);
38
49
  }
39
50
  /**
40
51
  * Removes the locale prefix before matching route templates.
@@ -54,5 +65,5 @@ function stripI18nPathPrefix(pathname, pathPrefix) {
54
65
  }
55
66
 
56
67
  //#endregion
57
- export { isAbsoluteUrl, normalizePathPrefix, parseSameOriginUrl, prependPathPrefix, stripI18nPathPrefix, stripTrailingSlash };
68
+ export { isAbsoluteUrl, normalizePathPrefix, parseSameOriginUrl, prependPathPrefix, stripI18nPathPrefix, stripTrailingSlash, trimTrailingSlashes };
58
69
  //# sourceMappingURL=path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"path.mjs","names":[],"sources":["../../../src/core/standard-routes/path.ts"],"sourcesContent":["export function prependPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n return `${normalizedPathPrefix}/${pathname.replace(/^\\/+/, \"\")}`;\n}\n\nexport function normalizePathPrefix(pathPrefix: string | undefined): string {\n if (!pathPrefix) return \"\";\n\n const trimmedPathPrefix = pathPrefix.trim().replace(/^\\/+|\\/+$/g, \"\");\n return trimmedPathPrefix ? `/${trimmedPathPrefix}` : \"\";\n}\n\nfunction parseUrl(url: string, baseUrl: string | undefined): URL | null {\n try {\n return new URL(url, baseUrl ?? \"https://shopify.local\");\n } catch {\n return null;\n }\n}\n\n/**\n * Parses a URL and rejects absolute URLs that do not share `baseUrl`'s origin.\n *\n * Relative URLs are resolved against `baseUrl` when provided, or against a throwaway local origin\n * when no base is available.\n */\nexport function parseSameOriginUrl(url: string, baseUrl: string | undefined): URL | null {\n const parsedUrl = parseUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const parsedBaseUrl = baseUrl ? parseUrl(baseUrl, undefined) : null;\n if (parsedBaseUrl && parsedUrl.origin !== parsedBaseUrl.origin) return null;\n\n return parsedUrl;\n}\n\nexport function isAbsoluteUrl(url: string): boolean {\n return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(url);\n}\n\nexport function stripTrailingSlash(pathname: string): string {\n if (pathname === \"/\") return pathname;\n return pathname.replace(/\\/+$/, \"\");\n}\n\n/**\n * Removes the locale prefix before matching route templates.\n *\n * `ShopifyScripts` stores `routes.root` with a trailing slash, while server i18n uses\n * `pathPrefix`; both are normalized here so `/fr-ca/products/snowboard` can match the same\n * template as `/products/snowboard`.\n */\nexport function stripI18nPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n const lowerPathname = pathname.toLowerCase();\n const lowerPathPrefix = normalizedPathPrefix.toLowerCase();\n\n if (lowerPathname === lowerPathPrefix) return \"/\";\n if (!lowerPathname.startsWith(`${lowerPathPrefix}/`)) return pathname;\n\n return pathname.slice(normalizedPathPrefix.length) || \"/\";\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB,UAAkB,YAAwC;CAC1F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;AAElC,QAAO,GAAG,qBAAqB,GAAG,SAAS,QAAQ,QAAQ,GAAG;;AAGhE,SAAgB,oBAAoB,YAAwC;AAC1E,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,oBAAoB,WAAW,MAAM,CAAC,QAAQ,cAAc,GAAG;AACrE,QAAO,oBAAoB,IAAI,sBAAsB;;AAGvD,SAAS,SAAS,KAAa,SAAyC;AACtE,KAAI;AACF,SAAO,IAAI,IAAI,KAAK,WAAW,wBAAwB;SACjD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,mBAAmB,KAAa,SAAyC;CACvF,MAAM,YAAY,SAAS,KAAK,QAAQ;AACxC,KAAI,CAAC,UAAW,QAAO;CAEvB,MAAM,gBAAgB,UAAU,SAAS,SAAS,OAAU,GAAG;AAC/D,KAAI,iBAAiB,UAAU,WAAW,cAAc,OAAQ,QAAO;AAEvE,QAAO;;AAGT,SAAgB,cAAc,KAAsB;AAClD,QAAO,4BAA4B,KAAK,IAAI;;AAG9C,SAAgB,mBAAmB,UAA0B;AAC3D,KAAI,aAAa,IAAK,QAAO;AAC7B,QAAO,SAAS,QAAQ,QAAQ,GAAG;;;;;;;;;AAUrC,SAAgB,oBAAoB,UAAkB,YAAwC;CAC5F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;CAElC,MAAM,gBAAgB,SAAS,aAAa;CAC5C,MAAM,kBAAkB,qBAAqB,aAAa;AAE1D,KAAI,kBAAkB,gBAAiB,QAAO;AAC9C,KAAI,CAAC,cAAc,WAAW,GAAG,gBAAgB,GAAG,CAAE,QAAO;AAE7D,QAAO,SAAS,MAAM,qBAAqB,OAAO,IAAI"}
1
+ {"version":3,"file":"path.mjs","names":[],"sources":["../../../src/core/standard-routes/path.ts"],"sourcesContent":["export function prependPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n return `${normalizedPathPrefix}/${pathname.replace(/^\\/+/, \"\")}`;\n}\n\nexport function normalizePathPrefix(pathPrefix: string | undefined): string {\n if (!pathPrefix) return \"\";\n\n const trimmedPathPrefix = trimTrailingSlashes(pathPrefix.trim().replace(/^\\/+/, \"\"));\n return trimmedPathPrefix ? `/${trimmedPathPrefix}` : \"\";\n}\n\n/**\n * Removes every trailing `/`.\n *\n * A loop instead of `/\\/+$/`: the regex rescans the slash run from each start position, so a\n * request path with a long run of slashes not at the end takes quadratic time.\n */\nexport function trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === \"/\") end--;\n return value.slice(0, end);\n}\n\nfunction parseUrl(url: string, baseUrl: string | undefined): URL | null {\n try {\n return new URL(url, baseUrl ?? \"https://shopify.local\");\n } catch {\n return null;\n }\n}\n\n/**\n * Parses a URL and rejects absolute URLs that do not share `baseUrl`'s origin.\n *\n * Relative URLs are resolved against `baseUrl` when provided, or against a throwaway local origin\n * when no base is available.\n */\nexport function parseSameOriginUrl(url: string, baseUrl: string | undefined): URL | null {\n const parsedUrl = parseUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const parsedBaseUrl = baseUrl ? parseUrl(baseUrl, undefined) : null;\n if (parsedBaseUrl && parsedUrl.origin !== parsedBaseUrl.origin) return null;\n\n return parsedUrl;\n}\n\nexport function isAbsoluteUrl(url: string): boolean {\n return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(url);\n}\n\nexport function stripTrailingSlash(pathname: string): string {\n if (pathname === \"/\") return pathname;\n return trimTrailingSlashes(pathname);\n}\n\n/**\n * Removes the locale prefix before matching route templates.\n *\n * `ShopifyScripts` stores `routes.root` with a trailing slash, while server i18n uses\n * `pathPrefix`; both are normalized here so `/fr-ca/products/snowboard` can match the same\n * template as `/products/snowboard`.\n */\nexport function stripI18nPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n const lowerPathname = pathname.toLowerCase();\n const lowerPathPrefix = normalizedPathPrefix.toLowerCase();\n\n if (lowerPathname === lowerPathPrefix) return \"/\";\n if (!lowerPathname.startsWith(`${lowerPathPrefix}/`)) return pathname;\n\n return pathname.slice(normalizedPathPrefix.length) || \"/\";\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB,UAAkB,YAAwC;CAC1F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;AAElC,QAAO,GAAG,qBAAqB,GAAG,SAAS,QAAQ,QAAQ,GAAG;;AAGhE,SAAgB,oBAAoB,YAAwC;AAC1E,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,oBAAoB,oBAAoB,WAAW,MAAM,CAAC,QAAQ,QAAQ,GAAG,CAAC;AACpF,QAAO,oBAAoB,IAAI,sBAAsB;;;;;;;;AASvD,SAAgB,oBAAoB,OAAuB;CACzD,IAAI,MAAM,MAAM;AAChB,QAAO,MAAM,KAAK,MAAM,MAAM,OAAO,IAAK;AAC1C,QAAO,MAAM,MAAM,GAAG,IAAI;;AAG5B,SAAS,SAAS,KAAa,SAAyC;AACtE,KAAI;AACF,SAAO,IAAI,IAAI,KAAK,WAAW,wBAAwB;SACjD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,mBAAmB,KAAa,SAAyC;CACvF,MAAM,YAAY,SAAS,KAAK,QAAQ;AACxC,KAAI,CAAC,UAAW,QAAO;CAEvB,MAAM,gBAAgB,UAAU,SAAS,SAAS,OAAU,GAAG;AAC/D,KAAI,iBAAiB,UAAU,WAAW,cAAc,OAAQ,QAAO;AAEvE,QAAO;;AAGT,SAAgB,cAAc,KAAsB;AAClD,QAAO,4BAA4B,KAAK,IAAI;;AAG9C,SAAgB,mBAAmB,UAA0B;AAC3D,KAAI,aAAa,IAAK,QAAO;AAC7B,QAAO,oBAAoB,SAAS;;;;;;;;;AAUtC,SAAgB,oBAAoB,UAAkB,YAAwC;CAC5F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;CAElC,MAAM,gBAAgB,SAAS,aAAa;CAC5C,MAAM,kBAAkB,qBAAqB,aAAa;AAE1D,KAAI,kBAAkB,gBAAiB,QAAO;AAC9C,KAAI,CAAC,cAAc,WAAW,GAAG,gBAAgB,GAAG,CAAE,QAAO;AAE7D,QAAO,SAAS,MAAM,qBAAqB,OAAO,IAAI"}
@@ -90,7 +90,12 @@ type ShopifyStandardRouteMatch<TRoute extends ShopifyStandardRouteName = Shopify
90
90
  /** Shopify's default path for the matched resource, with the locale path prefix applied. */standardPathname: string; /** The decoded handle values from the matched URL. */
91
91
  params: StandardRouteParams; /** The standard route name that the URL matched, or `index` for the home page. */
92
92
  route: TRoute; /** The page template name for the matched route, such as `product` or `list-collections`. */
93
- pageTemplateName: ShopifyPageTemplateName<TRoute>; /** Shopify's default template for the matched route and your app's custom template, which falls back to the default. */
93
+ pageTemplateName: ShopifyPageTemplateName<TRoute>;
94
+ /**
95
+ * Shopify's default template for the matched resource and your app's custom template, which
96
+ * falls back to the default. A collection-scoped product match without a collection handle uses
97
+ * the product template as its standard template.
98
+ */
94
99
  templates: {
95
100
  standard: string;
96
101
  custom: string;
package/dist/core/url.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { trimTrailingSlashes } from "./standard-routes/path.mjs";
2
+
1
3
  //#region src/core/url.ts
2
4
  const SFAPI_RE = /^\/api\/(unstable|2\d{3}-\d{2})\/graphql\.json$/;
3
5
  const SHOPIFY_API_PROXY_PREFIX = "/__shopify";
@@ -53,10 +55,10 @@ function getSameOriginPath(target, origin) {
53
55
  }
54
56
  function normalizeStoreDomain(domain) {
55
57
  if (!domain) throw new Error("Storefront `storeDomain` is required.");
56
- if (domain.startsWith("http://") || domain.startsWith("https://")) return domain.replace(/\/+$/, "");
57
- return `https://${domain}`.replace(/\/+$/, "");
58
+ if (domain.startsWith("http://") || domain.startsWith("https://")) return trimTrailingSlashes(domain);
59
+ return trimTrailingSlashes(`https://${domain}`);
58
60
  }
59
61
 
60
62
  //#endregion
61
- export { AJAX_CART_RE, BUY_PERMALINK_RE, CHECKOUT_RE, CUSTOMER_ACCOUNT_PATHS, MCP_RE, SFAPI_RE, SHOPIFY_API_PROXY_PREFIX, SHOPIFY_API_PROXY_RE, UCP_MCP_RE, UCP_RE, WELL_KNOWN_RE, getSameOriginPath, isHydrogenServerHandoffPath, normalizeStoreDomain };
63
+ export { AJAX_CART_RE, BUY_PERMALINK_RE, CART_PERMALINK_RE, CHECKOUT_RE, CUSTOMER_ACCOUNT_PATHS, MCP_RE, SFAPI_RE, SHOPIFY_API_PROXY_PREFIX, SHOPIFY_API_PROXY_RE, UCP_MCP_RE, UCP_RE, WELL_KNOWN_RE, getSameOriginPath, isHydrogenServerHandoffPath, normalizeStoreDomain };
62
64
  //# sourceMappingURL=url.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.mjs","names":[],"sources":["../../src/core/url.ts"],"sourcesContent":["export const SFAPI_RE = /^\\/api\\/(unstable|2\\d{3}-\\d{2})\\/graphql\\.json$/;\nexport const SHOPIFY_API_PROXY_PREFIX = \"/__shopify\";\nexport const SHOPIFY_API_PROXY_RE = /^\\/__shopify(?:\\/|$)/;\nexport const MCP_RE = /^\\/api\\/mcp$/;\nexport const UCP_MCP_RE = /^\\/api\\/ucp\\/mcp$/;\nexport const CHECKOUT_RE = /^\\/checkout$/;\nexport const CART_PERMALINK_RE = /^\\/cart\\/\\d+:\\d+(?:,\\d+:\\d+)*$/;\nconst BUY_ITEM_PAIR = String.raw`(?:[A-Za-z0-9._-]+|~[A-Za-z0-9_-]+):[1-9]\\d*`;\n// Items are required so a storefront's own /buy pages keep routing to the app.\nexport const BUY_PERMALINK_RE = new RegExp(`^/buy/${BUY_ITEM_PAIR}(?:,${BUY_ITEM_PAIR})*$`);\nexport const CUSTOMER_ACCOUNT_PATHS = {\n authorize: \"/account/authorize\",\n login: \"/account/login\",\n logout: \"/account/logout\",\n refresh: \"/account/refresh\",\n} as const;\n\nconst CUSTOMER_ACCOUNT_HANDOFF_PATHS: ReadonlySet<string> = new Set(\n Object.values(CUSTOMER_ACCOUNT_PATHS),\n);\n\n/**\n * Returns whether the pathname conventionally represents a Hydrogen document-level server handoff.\n *\n * Keep this aligned with the routes intercepted before framework routing. API and protocol\n * interceptors are intentionally excluded because they are not browser navigation destinations.\n */\nexport function isHydrogenServerHandoffPath(pathname: string): boolean {\n return (\n CHECKOUT_RE.test(pathname) ||\n CART_PERMALINK_RE.test(pathname) ||\n BUY_PERMALINK_RE.test(pathname) ||\n CUSTOMER_ACCOUNT_HANDOFF_PATHS.has(pathname)\n );\n}\n\n// UCP profiles need JSON validation and caching separate from the other well-known resources.\nexport const UCP_RE = /^\\/\\.well-known\\/ucp$/;\n\n/**\n * Allowlisted `.well-known` resources proxied to the Online Store origin:\n * - `apple-developer-merchantid-domain-association` — Apple Pay domain verification.\n * - `shopify/fec/produce` — Frontend Event Collector ingress. On the Online\n * Store the myshopify.com edge forwards this first-party path to the\n * collector; headless storefronts have no such edge, so Hydrogen proxies it\n * to the same origin (used by WebMCP's Event Refinery client).\n */\nexport const WELL_KNOWN_RE =\n /^\\/\\.well-known\\/(?:apple-developer-merchantid-domain-association|shopify\\/fec\\/produce)$/;\nexport const AJAX_CART_RE =\n /^(?:\\/[a-z]{2}(?:-[a-z]{2})?)?\\/cart(?:\\.(?:js|json)|\\/(?:add|update|change|clear)(?:\\.(?:js|json))?)$/i;\n\n/**\n * Normalizes `target` to a path on `origin` that is safe to use as a redirect location.\n * Returns `undefined` unless `target` is a path starting with `/` or an absolute URL,\n * stays on `origin`, and its normalized pathname does not start with `//`.\n */\nexport function getSameOriginPath(\n target: string | null | undefined,\n origin: string,\n): string | undefined {\n if (!target) return undefined;\n\n try {\n // Parse absolute URLs without a base so scheme-relative forms like `https:evil.example`\n // resolve to their own host, as a browser would, instead of onto `origin`.\n const url = target.startsWith(\"/\") ? new URL(target, origin) : new URL(target);\n if (url.origin !== origin) return undefined;\n const path = `${url.pathname}${url.search}${url.hash}`;\n // The parsed pathname can itself start with `//` (e.g. from `/x/..//evil`),\n // which a redirect would resolve as a protocol-relative URL to another host.\n return path.startsWith(\"//\") ? undefined : path;\n } catch {\n return undefined;\n }\n}\n\nexport function normalizeStoreDomain(domain: string): string {\n if (!domain) {\n throw new Error(\"Storefront `storeDomain` is required.\");\n }\n\n if (domain.startsWith(\"http://\") || domain.startsWith(\"https://\")) {\n return domain.replace(/\\/+$/, \"\");\n }\n return `https://${domain}`.replace(/\\/+$/, \"\");\n}\n"],"mappings":";AAAA,MAAa,WAAW;AACxB,MAAa,2BAA2B;AACxC,MAAa,uBAAuB;AACpC,MAAa,SAAS;AACtB,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,oBAAoB;AACjC,MAAM,gBAAgB,OAAO,GAAG;AAEhC,MAAa,mBAAmB,IAAI,OAAO,SAAS,cAAc,MAAM,cAAc,KAAK;AAC3F,MAAa,yBAAyB;CACpC,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACV;AAED,MAAM,iCAAsD,IAAI,IAC9D,OAAO,OAAO,uBAAuB,CACtC;;;;;;;AAQD,SAAgB,4BAA4B,UAA2B;AACrE,QACE,YAAY,KAAK,SAAS,IAC1B,kBAAkB,KAAK,SAAS,IAChC,iBAAiB,KAAK,SAAS,IAC/B,+BAA+B,IAAI,SAAS;;AAKhD,MAAa,SAAS;;;;;;;;;AAUtB,MAAa,gBACX;AACF,MAAa,eACX;;;;;;AAOF,SAAgB,kBACd,QACA,QACoB;AACpB,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI;EAGF,MAAM,MAAM,OAAO,WAAW,IAAI,GAAG,IAAI,IAAI,QAAQ,OAAO,GAAG,IAAI,IAAI,OAAO;AAC9E,MAAI,IAAI,WAAW,OAAQ,QAAO;EAClC,MAAM,OAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;AAGhD,SAAO,KAAK,WAAW,KAAK,GAAG,SAAY;SACrC;AACN;;;AAIJ,SAAgB,qBAAqB,QAAwB;AAC3D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,wCAAwC;AAG1D,KAAI,OAAO,WAAW,UAAU,IAAI,OAAO,WAAW,WAAW,CAC/D,QAAO,OAAO,QAAQ,QAAQ,GAAG;AAEnC,QAAO,WAAW,SAAS,QAAQ,QAAQ,GAAG"}
1
+ {"version":3,"file":"url.mjs","names":[],"sources":["../../src/core/url.ts"],"sourcesContent":["import { trimTrailingSlashes } from \"./standard-routes/path\";\n\nexport const SFAPI_RE = /^\\/api\\/(unstable|2\\d{3}-\\d{2})\\/graphql\\.json$/;\nexport const SHOPIFY_API_PROXY_PREFIX = \"/__shopify\";\nexport const SHOPIFY_API_PROXY_RE = /^\\/__shopify(?:\\/|$)/;\nexport const MCP_RE = /^\\/api\\/mcp$/;\nexport const UCP_MCP_RE = /^\\/api\\/ucp\\/mcp$/;\nexport const CHECKOUT_RE = /^\\/checkout$/;\nexport const CART_PERMALINK_RE = /^\\/cart\\/\\d+:\\d+(?:,\\d+:\\d+)*$/;\nconst BUY_ITEM_PAIR = String.raw`(?:[A-Za-z0-9._-]+|~[A-Za-z0-9_-]+):[1-9]\\d*`;\n// Items are required so a storefront's own /buy pages keep routing to the app.\nexport const BUY_PERMALINK_RE = new RegExp(`^/buy/${BUY_ITEM_PAIR}(?:,${BUY_ITEM_PAIR})*$`);\nexport const CUSTOMER_ACCOUNT_PATHS = {\n authorize: \"/account/authorize\",\n login: \"/account/login\",\n logout: \"/account/logout\",\n refresh: \"/account/refresh\",\n} as const;\n\nconst CUSTOMER_ACCOUNT_HANDOFF_PATHS: ReadonlySet<string> = new Set(\n Object.values(CUSTOMER_ACCOUNT_PATHS),\n);\n\n/**\n * Returns whether the pathname conventionally represents a Hydrogen document-level server handoff.\n *\n * Keep this aligned with the routes intercepted before framework routing. API and protocol\n * interceptors are intentionally excluded because they are not browser navigation destinations.\n */\nexport function isHydrogenServerHandoffPath(pathname: string): boolean {\n return (\n CHECKOUT_RE.test(pathname) ||\n CART_PERMALINK_RE.test(pathname) ||\n BUY_PERMALINK_RE.test(pathname) ||\n CUSTOMER_ACCOUNT_HANDOFF_PATHS.has(pathname)\n );\n}\n\n// UCP profiles need JSON validation and caching separate from the other well-known resources.\nexport const UCP_RE = /^\\/\\.well-known\\/ucp$/;\n\n/**\n * Allowlisted `.well-known` resources proxied to the Online Store origin:\n * - `apple-developer-merchantid-domain-association` — Apple Pay domain verification.\n * - `shopify/fec/produce` — Frontend Event Collector ingress. On the Online\n * Store the myshopify.com edge forwards this first-party path to the\n * collector; headless storefronts have no such edge, so Hydrogen proxies it\n * to the same origin (used by WebMCP's Event Refinery client).\n */\nexport const WELL_KNOWN_RE =\n /^\\/\\.well-known\\/(?:apple-developer-merchantid-domain-association|shopify\\/fec\\/produce)$/;\nexport const AJAX_CART_RE =\n /^(?:\\/[a-z]{2}(?:-[a-z]{2})?)?\\/cart(?:\\.(?:js|json)|\\/(?:add|update|change|clear)(?:\\.(?:js|json))?)$/i;\n\n/**\n * Normalizes `target` to a path on `origin` that is safe to use as a redirect location.\n * Returns `undefined` unless `target` is a path starting with `/` or an absolute URL,\n * stays on `origin`, and its normalized pathname does not start with `//`.\n */\nexport function getSameOriginPath(\n target: string | null | undefined,\n origin: string,\n): string | undefined {\n if (!target) return undefined;\n\n try {\n // Parse absolute URLs without a base so scheme-relative forms like `https:evil.example`\n // resolve to their own host, as a browser would, instead of onto `origin`.\n const url = target.startsWith(\"/\") ? new URL(target, origin) : new URL(target);\n if (url.origin !== origin) return undefined;\n const path = `${url.pathname}${url.search}${url.hash}`;\n // The parsed pathname can itself start with `//` (e.g. from `/x/..//evil`),\n // which a redirect would resolve as a protocol-relative URL to another host.\n return path.startsWith(\"//\") ? undefined : path;\n } catch {\n return undefined;\n }\n}\n\nexport function normalizeStoreDomain(domain: string): string {\n if (!domain) {\n throw new Error(\"Storefront `storeDomain` is required.\");\n }\n\n if (domain.startsWith(\"http://\") || domain.startsWith(\"https://\")) {\n return trimTrailingSlashes(domain);\n }\n return trimTrailingSlashes(`https://${domain}`);\n}\n"],"mappings":";;;AAEA,MAAa,WAAW;AACxB,MAAa,2BAA2B;AACxC,MAAa,uBAAuB;AACpC,MAAa,SAAS;AACtB,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,oBAAoB;AACjC,MAAM,gBAAgB,OAAO,GAAG;AAEhC,MAAa,mBAAmB,IAAI,OAAO,SAAS,cAAc,MAAM,cAAc,KAAK;AAC3F,MAAa,yBAAyB;CACpC,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACV;AAED,MAAM,iCAAsD,IAAI,IAC9D,OAAO,OAAO,uBAAuB,CACtC;;;;;;;AAQD,SAAgB,4BAA4B,UAA2B;AACrE,QACE,YAAY,KAAK,SAAS,IAC1B,kBAAkB,KAAK,SAAS,IAChC,iBAAiB,KAAK,SAAS,IAC/B,+BAA+B,IAAI,SAAS;;AAKhD,MAAa,SAAS;;;;;;;;;AAUtB,MAAa,gBACX;AACF,MAAa,eACX;;;;;;AAOF,SAAgB,kBACd,QACA,QACoB;AACpB,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI;EAGF,MAAM,MAAM,OAAO,WAAW,IAAI,GAAG,IAAI,IAAI,QAAQ,OAAO,GAAG,IAAI,IAAI,OAAO;AAC9E,MAAI,IAAI,WAAW,OAAQ,QAAO;EAClC,MAAM,OAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;AAGhD,SAAO,KAAK,WAAW,KAAK,GAAG,SAAY;SACrC;AACN;;;AAIJ,SAAgB,qBAAqB,QAAwB;AAC3D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,wCAAwC;AAG1D,KAAI,OAAO,WAAW,UAAU,IAAI,OAAO,WAAW,WAAW,CAC/D,QAAO,oBAAoB,OAAO;AAEpC,QAAO,oBAAoB,WAAW,SAAS"}
@@ -10,6 +10,12 @@ function loadScript(src, options) {
10
10
  const promise = new Promise((resolve, reject) => {
11
11
  const script = document.createElement("script");
12
12
  script.type = options?.module ? "module" : "text/javascript";
13
+ if (options?.attributes) {
14
+ const { attributes } = options;
15
+ Object.keys(attributes).forEach((key) => {
16
+ script.setAttribute(key, attributes[key]);
17
+ });
18
+ }
13
19
  script.src = src;
14
20
  script.addEventListener("load", () => resolve(true));
15
21
  script.addEventListener("error", () => {
@@ -18,12 +24,6 @@ function loadScript(src, options) {
18
24
  });
19
25
  if (options?.in === "head") document.head.appendChild(script);
20
26
  else document.body.appendChild(script);
21
- if (options?.attributes) {
22
- const { attributes } = options;
23
- Object.keys(attributes).forEach((key) => {
24
- script.setAttribute(key, attributes[key]);
25
- });
26
- }
27
27
  });
28
28
  SCRIPTS_LOADED[src] = promise;
29
29
  return promise;
@@ -1 +1 @@
1
- {"version":3,"file":"load-script.mjs","names":[],"sources":["../../../src/core/utils/load-script.ts"],"sourcesContent":["/**\n * Inlined from @shopify/hydrogen-react/load-script.\n * Pure DOM script loader with no framework dependency.\n */\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: \"head\" | \"body\";\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(src: string, options?: LoadScriptOptions): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n if (isScriptLoaded) return isScriptLoaded;\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = options?.module ? \"module\" : \"text/javascript\";\n script.src = src;\n script.addEventListener(\"load\", () => resolve(true));\n script.addEventListener(\"error\", () => {\n delete SCRIPTS_LOADED[src];\n reject(false);\n });\n\n if (options?.in === \"head\") {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n\n if (options?.attributes) {\n const { attributes } = options;\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n return promise;\n}\n"],"mappings":";;;;;AAKA,MAAM,iBAAmD,EAAE;AAQ3D,SAAgB,WAAW,KAAa,SAA+C;CACrF,MAAM,iBAAiB,eAAe;AACtC,KAAI,eAAgB,QAAO;CAE3B,MAAM,UAAU,IAAI,SAAkB,SAAS,WAAW;EACxD,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,OAAO,SAAS,SAAS,WAAW;AAC3C,SAAO,MAAM;AACb,SAAO,iBAAiB,cAAc,QAAQ,KAAK,CAAC;AACpD,SAAO,iBAAiB,eAAe;AACrC,UAAO,eAAe;AACtB,UAAO,MAAM;IACb;AAEF,MAAI,SAAS,OAAO,OAClB,UAAS,KAAK,YAAY,OAAO;MAEjC,UAAS,KAAK,YAAY,OAAO;AAGnC,MAAI,SAAS,YAAY;GACvB,MAAM,EAAE,eAAe;AACvB,UAAO,KAAK,WAAW,CAAC,SAAS,QAAQ;AACvC,WAAO,aAAa,KAAK,WAAW,KAAK;KACzC;;GAEJ;AAEF,gBAAe,OAAO;AACtB,QAAO"}
1
+ {"version":3,"file":"load-script.mjs","names":[],"sources":["../../../src/core/utils/load-script.ts"],"sourcesContent":["/**\n * Inlined from @shopify/hydrogen-react/load-script.\n * Pure DOM script loader with no framework dependency.\n */\n\nconst SCRIPTS_LOADED: Record<string, Promise<boolean>> = {};\n\ntype LoadScriptOptions = {\n module?: boolean;\n in?: \"head\" | \"body\";\n attributes?: Record<string, string>;\n};\n\nexport function loadScript(src: string, options?: LoadScriptOptions): Promise<boolean> {\n const isScriptLoaded = SCRIPTS_LOADED[src];\n if (isScriptLoaded) return isScriptLoaded;\n\n const promise = new Promise<boolean>((resolve, reject) => {\n const script = document.createElement(\"script\");\n script.type = options?.module ? \"module\" : \"text/javascript\";\n\n if (options?.attributes) {\n const { attributes } = options;\n Object.keys(attributes).forEach((key) => {\n script.setAttribute(key, attributes[key]);\n });\n }\n\n script.src = src;\n script.addEventListener(\"load\", () => resolve(true));\n script.addEventListener(\"error\", () => {\n delete SCRIPTS_LOADED[src];\n reject(false);\n });\n\n if (options?.in === \"head\") {\n document.head.appendChild(script);\n } else {\n document.body.appendChild(script);\n }\n });\n\n SCRIPTS_LOADED[src] = promise;\n return promise;\n}\n"],"mappings":";;;;;AAKA,MAAM,iBAAmD,EAAE;AAQ3D,SAAgB,WAAW,KAAa,SAA+C;CACrF,MAAM,iBAAiB,eAAe;AACtC,KAAI,eAAgB,QAAO;CAE3B,MAAM,UAAU,IAAI,SAAkB,SAAS,WAAW;EACxD,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,SAAO,OAAO,SAAS,SAAS,WAAW;AAE3C,MAAI,SAAS,YAAY;GACvB,MAAM,EAAE,eAAe;AACvB,UAAO,KAAK,WAAW,CAAC,SAAS,QAAQ;AACvC,WAAO,aAAa,KAAK,WAAW,KAAK;KACzC;;AAGJ,SAAO,MAAM;AACb,SAAO,iBAAiB,cAAc,QAAQ,KAAK,CAAC;AACpD,SAAO,iBAAiB,eAAe;AACrC,UAAO,eAAe;AACtB,UAAO,MAAM;IACb;AAEF,MAAI,SAAS,OAAO,OAClB,UAAS,KAAK,YAAY,OAAO;MAEjC,UAAS,KAAK,YAAY,OAAO;GAEnC;AAEF,gBAAe,OAAO;AACtB,QAAO"}
@@ -1,6 +1,8 @@
1
1
  import { ShopifyRequestContext } from "../core/request-context.mjs";
2
+ import { InferVariableNamesByEnumValue, InferVariableNamesDeclaredAs } from "../graphql/type-resolver.mjs";
2
3
  import { GraphQLFormattedError } from "../client/types.mjs";
3
- import { AnyCustomerAccountDocument, CustomerAccountDocument } from "./graphql.mjs";
4
+ import { introspection } from "../graphql/generated/customer-account-graphql-env.mjs";
5
+ import { AnyCustomerAccountDocument, CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES, CustomerAccountDocument, SourceOf } from "./graphql.mjs";
4
6
 
5
7
  //#region src/customer-account/client.d.ts
6
8
  /**
@@ -17,7 +19,7 @@ type CreateCustomerAccountClientOptions = {
17
19
  *
18
20
  * The context's URL must use HTTPS, or creating the client throws. Local `http://` URLs on localhost, 127.0.0.1, and ::1 also work for development.
19
21
  *
20
- * The client fills `$language` from the context's language and stops requests when the context's signal aborts.
22
+ * The client fills `$language: LanguageCode` from the context's language and stops requests when the context's signal aborts.
21
23
  */
22
24
  requestContext: ShopifyRequestContext; /** Custom fetch implementation. Defaults to the global fetch. */
23
25
  fetch?: typeof globalThis.fetch;
@@ -32,7 +34,7 @@ type CreateCustomerAccountClientOptions = {
32
34
  type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {
33
35
  /** The customer's access token, such as one from the customer session's `getOrRefreshAccessToken()` method. */accessToken: string;
34
36
  /**
35
- * The document's variables. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.
37
+ * The document's variables. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.
36
38
  */
37
39
  variables?: Variables;
38
40
  /**
@@ -43,11 +45,13 @@ type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {
43
45
  type ResultOfDoc<Doc> = Doc extends CustomerAccountDocument<infer Result, never, string> ? Result : never;
44
46
  /** The variables that a Customer Account document declares. */
45
47
  type VariablesOfDoc<Doc> = Doc extends CustomerAccountDocument<unknown, infer Variables, string> ? Variables : never;
46
- /** An optional `language` variable for a document that declares `$language`. The client fills a missing value from the request context. */
47
- type OptionalAutoVariables<Variables> = "language" extends keyof Variables ? {
48
- language?: Variables["language"];
49
- } : {};
50
- type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, "language"> & OptionalAutoVariables<VariablesOfDoc<Doc>>;
48
+ type I18nVariableTypes = typeof CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES;
49
+ type I18nVariableNamesByValue<Variables> = InferVariableNamesByEnumValue<Variables, I18nVariableTypes, introspection>;
50
+ /** The variables the client fills when omitted: those declared with the expected type, such as `$language: LanguageCode`. */
51
+ type I18nVariableNamesOfDoc<Doc> = string extends SourceOf<Doc> ? I18nVariableNamesByValue<VariablesOfDoc<Doc>> : InferVariableNamesDeclaredAs<SourceOf<Doc>, I18nVariableTypes>;
52
+ /** Optional versions of the variables that the client fills from the request context when you omit them. */
53
+ type OptionalI18nVariables<Variables, Names> = { [K in keyof Variables & Names]?: Variables[K] };
54
+ type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>> & OptionalI18nVariables<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>>;
51
55
  type HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;
52
56
  /**
53
57
  * Result of a Customer Account API request. Check `errors` to tell the outcomes apart.
@@ -66,7 +70,7 @@ type CustomerAccountGraphqlResult<Result = unknown> = {
66
70
  /**
67
71
  * The options argument for a Customer Account API request.
68
72
  *
69
- * Pass `variables` when the document declares a required variable other than `language`. TypeScript reports an error when a required variable is missing.
73
+ * Pass `variables` when the document declares a required variable other than `$language: LanguageCode`. TypeScript reports an error when a required variable is missing.
70
74
  */
71
75
  type CustomerAccountGqlRestParam<Doc extends AnyCustomerAccountDocument> = HasNoRequiredKeys<UserVariables<Doc>> extends true ? [options: CustomerAccountGraphqlOptions<UserVariables<Doc>>] : [options: CustomerAccountGraphqlOptions<UserVariables<Doc>> & {
72
76
  variables: UserVariables<Doc>;
@@ -79,7 +83,7 @@ type CustomerAccountClient = {
79
83
  /**
80
84
  * Sends a Customer Account API query or mutation with the customer's access token, and returns the data, any GraphQL errors, and the response headers. Pass a document from the Customer Account `gql` function.
81
85
  *
82
- * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.
86
+ * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.
83
87
  *
84
88
  * The method throws a `TypeError` for a document from any other `gql` function, including the Storefront API `gql` function, and for variables that aren't an object. When a signal aborts, the method throws the signal's reason. A missing or malformed access token throws `CustomerAccountAuthenticationError`, a timeout throws `CustomerAccountTimeoutError`, and other request failures throw `CustomerAccountApiError`.
85
89
  *