@shopify/hydrogen 2026.10.2 → 2026.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/cli/index.mjs +2 -2
- package/dist/client/client.mjs +44 -9
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/i18n-variables.d.mts +1 -1
- package/dist/client/i18n-variables.mjs +14 -6
- package/dist/client/i18n-variables.mjs.map +1 -1
- package/dist/client/types.d.mts +12 -6
- package/dist/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cart/cart.mjs +1 -1
- package/dist/core/cart/cookie.mjs +6 -1
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +17 -5
- package/dist/core/cart/form.mjs +5 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/collection/url.mjs +8 -1
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.mjs +2 -1
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/csp/index.d.mts +56 -0
- package/dist/core/csp/index.mjs +117 -0
- package/dist/core/csp/index.mjs.map +1 -0
- package/dist/core/csp/types.d.mts +52 -0
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/i18n/define.d.mts +54 -0
- package/dist/core/i18n/define.mjs +135 -0
- package/dist/core/i18n/define.mjs.map +1 -0
- package/dist/core/i18n/errors.d.mts +18 -0
- package/dist/core/i18n/errors.mjs +24 -0
- package/dist/core/i18n/errors.mjs.map +1 -0
- package/dist/core/i18n/href.d.mts +28 -0
- package/dist/core/i18n/href.mjs +45 -0
- package/dist/core/i18n/href.mjs.map +1 -0
- package/dist/core/i18n/locale.d.mts +21 -0
- package/dist/core/i18n/locale.mjs +36 -0
- package/dist/core/i18n/locale.mjs.map +1 -0
- package/dist/core/i18n/match.d.mts +37 -0
- package/dist/core/i18n/match.mjs +82 -0
- package/dist/core/i18n/match.mjs.map +1 -0
- package/dist/core/i18n/types.d.mts +80 -0
- package/dist/core/index.d.mts +14 -5
- package/dist/core/index.mjs +9 -2
- package/dist/core/predictive-search/index.d.mts +2 -2
- package/dist/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +2 -2
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/accept-variant-id.mjs +1 -1
- package/dist/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/core/request-context.d.mts +61 -35
- package/dist/core/request-context.mjs +11 -7
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/core/request-routing/registered-routes.mjs +13 -3
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +2 -2
- package/dist/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +3 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +13 -11
- package/dist/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/core/shopify-scripts/index.d.mts +1 -0
- package/dist/core/shopify-scripts/index.mjs +12 -9
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +4 -2
- package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/core/standard-routes/build.d.mts +7 -2
- package/dist/core/standard-routes/build.mjs +10 -3
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/match.mjs +11 -1
- package/dist/core/standard-routes/match.mjs.map +1 -1
- package/dist/core/standard-routes/path.mjs +14 -3
- package/dist/core/standard-routes/path.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +6 -1
- package/dist/core/url.mjs +5 -3
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +14 -10
- package/dist/customer-account/client.mjs +4 -5
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +7 -1
- package/dist/customer-account/graphql.mjs +6 -7
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.mjs +3 -4
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/development/client/client.mjs +44 -9
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/i18n-variables.d.mts +1 -1
- package/dist/development/client/i18n-variables.mjs +13 -5
- package/dist/development/client/i18n-variables.mjs.map +1 -1
- package/dist/development/client/types.d.mts +12 -6
- package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cart/cart.mjs +1 -1
- package/dist/development/core/cart/cookie.mjs +6 -1
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +17 -5
- package/dist/development/core/cart/form.mjs +5 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/queries.d.mts +57 -57
- package/dist/development/core/collection/url.mjs +8 -1
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs +2 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/csp/index.d.mts +56 -0
- package/dist/development/core/csp/index.mjs +128 -0
- package/dist/development/core/csp/index.mjs.map +1 -0
- package/dist/development/core/csp/types.d.mts +52 -0
- package/dist/development/core/development.d.mts +14 -5
- package/dist/development/core/development.mjs +9 -2
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/i18n/define.d.mts +54 -0
- package/dist/development/core/i18n/define.mjs +135 -0
- package/dist/development/core/i18n/define.mjs.map +1 -0
- package/dist/development/core/i18n/errors.d.mts +18 -0
- package/dist/development/core/i18n/errors.mjs +24 -0
- package/dist/development/core/i18n/errors.mjs.map +1 -0
- package/dist/development/core/i18n/href.d.mts +28 -0
- package/dist/development/core/i18n/href.mjs +45 -0
- package/dist/development/core/i18n/href.mjs.map +1 -0
- package/dist/development/core/i18n/locale.d.mts +21 -0
- package/dist/development/core/i18n/locale.mjs +36 -0
- package/dist/development/core/i18n/locale.mjs.map +1 -0
- package/dist/development/core/i18n/match.d.mts +37 -0
- package/dist/development/core/i18n/match.mjs +82 -0
- package/dist/development/core/i18n/match.mjs.map +1 -0
- package/dist/development/core/i18n/types.d.mts +80 -0
- package/dist/development/core/index.d.mts +13 -4
- package/dist/development/core/predictive-search/index.d.mts +2 -2
- package/dist/development/core/predictive-search/queries.d.mts +2 -2
- package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +2 -2
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/accept-variant-id.mjs +1 -1
- package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +61 -35
- package/dist/development/core/request-context.mjs +11 -7
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/development/core/request-routing/registered-routes.mjs +13 -3
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +2 -2
- package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +3 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +13 -11
- package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/development/core/shopify-scripts/index.d.mts +1 -0
- package/dist/development/core/shopify-scripts/index.mjs +12 -9
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +4 -2
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/development/core/standard-routes/build.d.mts +7 -2
- package/dist/development/core/standard-routes/build.mjs +10 -3
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/match.mjs +11 -1
- package/dist/development/core/standard-routes/match.mjs.map +1 -1
- package/dist/development/core/standard-routes/path.mjs +14 -3
- package/dist/development/core/standard-routes/path.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +6 -1
- package/dist/development/core/url.mjs +5 -3
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +8 -4
- package/dist/development/graphql/type-resolver.d.mts +13 -1
- package/dist/development/react/index.d.mts +2 -2
- package/dist/globals.d.mts +8 -4
- package/dist/graphql/type-resolver.d.mts +13 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/vite/index.mjs +1 -1
- package/dist/vue/shopify-scripts.d.mts +1 -1
- package/package.json +13 -3
- package/skills/hydrogen-analytics/SKILL.md +2 -2
- package/skills/hydrogen-analytics/references/react.md +2 -2
- package/skills/hydrogen-markets/SKILL.md +127 -93
- package/skills/hydrogen-markets/references/nextjs.md +77 -87
- package/skills/hydrogen-oxygen/references/react-router.md +1 -2
- package/skills/hydrogen-predictive-search/SKILL.md +18 -1
- package/skills/hydrogen-request-handlers/SKILL.md +23 -5
- package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
- package/skills/hydrogen-request-handlers/references/frameworks.md +8 -6
- package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
- package/skills/hydrogen-request-handlers/references/nuxt.md +7 -5
- package/skills/hydrogen-robots-txt/SKILL.md +87 -0
- package/skills/hydrogen-routing/SKILL.md +36 -14
- package/skills/hydrogen-setup/SKILL.md +2 -2
- package/skills/hydrogen-setup/references/analytics.md +5 -5
- package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
- package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
- package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
- package/skills/hydrogen-smoke-test/SKILL.md +9 -2
- package/skills/hydrogen-storefront-client/SKILL.md +27 -9
- package/skills/hydrogen-storefront-client/references/astro.md +8 -3
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
- package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
- package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
- package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
- package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
- package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
- package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
- package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
|
@@ -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;
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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 +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
|
|
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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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>;
|
|
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;
|
|
@@ -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
|
|
57
|
-
return `https://${domain}
|
|
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":["
|
|
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"}
|