@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.
Files changed (245) hide show
  1. package/README.md +3 -5
  2. package/dist/cli/index.mjs +2 -2
  3. package/dist/client/client.mjs +44 -9
  4. package/dist/client/client.mjs.map +1 -1
  5. package/dist/client/i18n-variables.d.mts +1 -1
  6. package/dist/client/i18n-variables.mjs +14 -6
  7. package/dist/client/i18n-variables.mjs.map +1 -1
  8. package/dist/client/types.d.mts +12 -6
  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 +1 -1
  12. package/dist/core/cart/cookie.mjs +6 -1
  13. package/dist/core/cart/cookie.mjs.map +1 -1
  14. package/dist/core/cart/form.d.mts +17 -5
  15. package/dist/core/cart/form.mjs +5 -0
  16. package/dist/core/cart/form.mjs.map +1 -1
  17. package/dist/core/cart/index.d.mts +1 -1
  18. package/dist/core/collection/url.mjs +8 -1
  19. package/dist/core/collection/url.mjs.map +1 -1
  20. package/dist/core/constants.mjs +2 -1
  21. package/dist/core/constants.mjs.map +1 -1
  22. package/dist/core/csp/index.d.mts +56 -0
  23. package/dist/core/csp/index.mjs +117 -0
  24. package/dist/core/csp/index.mjs.map +1 -0
  25. package/dist/core/csp/types.d.mts +52 -0
  26. package/dist/core/headers.mjs +2 -2
  27. package/dist/core/headers.mjs.map +1 -1
  28. package/dist/core/i18n/define.d.mts +54 -0
  29. package/dist/core/i18n/define.mjs +135 -0
  30. package/dist/core/i18n/define.mjs.map +1 -0
  31. package/dist/core/i18n/errors.d.mts +18 -0
  32. package/dist/core/i18n/errors.mjs +24 -0
  33. package/dist/core/i18n/errors.mjs.map +1 -0
  34. package/dist/core/i18n/href.d.mts +28 -0
  35. package/dist/core/i18n/href.mjs +45 -0
  36. package/dist/core/i18n/href.mjs.map +1 -0
  37. package/dist/core/i18n/locale.d.mts +21 -0
  38. package/dist/core/i18n/locale.mjs +36 -0
  39. package/dist/core/i18n/locale.mjs.map +1 -0
  40. package/dist/core/i18n/match.d.mts +37 -0
  41. package/dist/core/i18n/match.mjs +82 -0
  42. package/dist/core/i18n/match.mjs.map +1 -0
  43. package/dist/core/i18n/types.d.mts +80 -0
  44. package/dist/core/index.d.mts +14 -5
  45. package/dist/core/index.mjs +9 -2
  46. package/dist/core/predictive-search/index.d.mts +2 -2
  47. package/dist/core/predictive-search/server-handlers.d.mts +27 -6
  48. package/dist/core/predictive-search/server-handlers.mjs +1 -4
  49. package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
  50. package/dist/core/predictive-search/url.d.mts +2 -2
  51. package/dist/core/predictive-search/url.mjs.map +1 -1
  52. package/dist/core/product/accept-variant-id.mjs +1 -1
  53. package/dist/core/product/accept-variant-id.mjs.map +1 -1
  54. package/dist/core/request-context.d.mts +61 -35
  55. package/dist/core/request-context.mjs +11 -7
  56. package/dist/core/request-context.mjs.map +1 -1
  57. package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  58. package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
  59. package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  60. package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
  61. package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
  62. package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
  63. package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  64. package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
  65. package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  66. package/dist/core/request-routing/registered-routes.d.mts +10 -3
  67. package/dist/core/request-routing/registered-routes.mjs +13 -3
  68. package/dist/core/request-routing/registered-routes.mjs.map +1 -1
  69. package/dist/core/request-routing/route-types.d.mts +2 -2
  70. package/dist/core/shop-pay/shop-pay.mjs +5 -4
  71. package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
  72. package/dist/core/shopify-scripts/analytics.mjs +3 -5
  73. package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
  74. package/dist/core/shopify-scripts/constants.mjs +3 -1
  75. package/dist/core/shopify-scripts/constants.mjs.map +1 -1
  76. package/dist/core/shopify-scripts/global.mjs +13 -11
  77. package/dist/core/shopify-scripts/global.mjs.map +1 -1
  78. package/dist/core/shopify-scripts/hashes.d.mts +17 -0
  79. package/dist/core/shopify-scripts/hashes.mjs +12 -0
  80. package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
  81. package/dist/core/shopify-scripts/index.d.mts +1 -0
  82. package/dist/core/shopify-scripts/index.mjs +12 -9
  83. package/dist/core/shopify-scripts/index.mjs.map +1 -1
  84. package/dist/core/shopify-scripts/page-view.mjs +4 -1
  85. package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
  86. package/dist/core/shopify-scripts/types.d.mts +4 -2
  87. package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
  88. package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  89. package/dist/core/standard-routes/build.d.mts +7 -2
  90. package/dist/core/standard-routes/build.mjs +10 -3
  91. package/dist/core/standard-routes/build.mjs.map +1 -1
  92. package/dist/core/standard-routes/match.mjs +11 -1
  93. package/dist/core/standard-routes/match.mjs.map +1 -1
  94. package/dist/core/standard-routes/path.mjs +14 -3
  95. package/dist/core/standard-routes/path.mjs.map +1 -1
  96. package/dist/core/standard-routes/types.d.mts +6 -1
  97. package/dist/core/url.mjs +5 -3
  98. package/dist/core/url.mjs.map +1 -1
  99. package/dist/customer-account/client.d.mts +14 -10
  100. package/dist/customer-account/client.mjs +4 -5
  101. package/dist/customer-account/client.mjs.map +1 -1
  102. package/dist/customer-account/graphql.d.mts +7 -1
  103. package/dist/customer-account/graphql.mjs +6 -7
  104. package/dist/customer-account/graphql.mjs.map +1 -1
  105. package/dist/customer-account/session.mjs +3 -4
  106. package/dist/customer-account/session.mjs.map +1 -1
  107. package/dist/development/client/client.mjs +44 -9
  108. package/dist/development/client/client.mjs.map +1 -1
  109. package/dist/development/client/i18n-variables.d.mts +1 -1
  110. package/dist/development/client/i18n-variables.mjs +13 -5
  111. package/dist/development/client/i18n-variables.mjs.map +1 -1
  112. package/dist/development/client/types.d.mts +12 -6
  113. package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
  114. package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
  115. package/dist/development/core/cart/cart.mjs +1 -1
  116. package/dist/development/core/cart/cookie.mjs +6 -1
  117. package/dist/development/core/cart/cookie.mjs.map +1 -1
  118. package/dist/development/core/cart/form.d.mts +17 -5
  119. package/dist/development/core/cart/form.mjs +5 -0
  120. package/dist/development/core/cart/form.mjs.map +1 -1
  121. package/dist/development/core/cart/index.d.mts +1 -1
  122. package/dist/development/core/cart/queries.d.mts +57 -57
  123. package/dist/development/core/collection/url.mjs +8 -1
  124. package/dist/development/core/collection/url.mjs.map +1 -1
  125. package/dist/development/core/constants.mjs +2 -1
  126. package/dist/development/core/constants.mjs.map +1 -1
  127. package/dist/development/core/csp/index.d.mts +56 -0
  128. package/dist/development/core/csp/index.mjs +128 -0
  129. package/dist/development/core/csp/index.mjs.map +1 -0
  130. package/dist/development/core/csp/types.d.mts +52 -0
  131. package/dist/development/core/development.d.mts +14 -5
  132. package/dist/development/core/development.mjs +9 -2
  133. package/dist/development/core/headers.mjs +2 -2
  134. package/dist/development/core/headers.mjs.map +1 -1
  135. package/dist/development/core/i18n/define.d.mts +54 -0
  136. package/dist/development/core/i18n/define.mjs +135 -0
  137. package/dist/development/core/i18n/define.mjs.map +1 -0
  138. package/dist/development/core/i18n/errors.d.mts +18 -0
  139. package/dist/development/core/i18n/errors.mjs +24 -0
  140. package/dist/development/core/i18n/errors.mjs.map +1 -0
  141. package/dist/development/core/i18n/href.d.mts +28 -0
  142. package/dist/development/core/i18n/href.mjs +45 -0
  143. package/dist/development/core/i18n/href.mjs.map +1 -0
  144. package/dist/development/core/i18n/locale.d.mts +21 -0
  145. package/dist/development/core/i18n/locale.mjs +36 -0
  146. package/dist/development/core/i18n/locale.mjs.map +1 -0
  147. package/dist/development/core/i18n/match.d.mts +37 -0
  148. package/dist/development/core/i18n/match.mjs +82 -0
  149. package/dist/development/core/i18n/match.mjs.map +1 -0
  150. package/dist/development/core/i18n/types.d.mts +80 -0
  151. package/dist/development/core/index.d.mts +13 -4
  152. package/dist/development/core/predictive-search/index.d.mts +2 -2
  153. package/dist/development/core/predictive-search/queries.d.mts +2 -2
  154. package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
  155. package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
  156. package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
  157. package/dist/development/core/predictive-search/url.d.mts +2 -2
  158. package/dist/development/core/predictive-search/url.mjs.map +1 -1
  159. package/dist/development/core/product/accept-variant-id.mjs +1 -1
  160. package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
  161. package/dist/development/core/request-context.d.mts +61 -35
  162. package/dist/development/core/request-context.mjs +11 -7
  163. package/dist/development/core/request-context.mjs.map +1 -1
  164. package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  165. package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
  166. package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  167. package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
  168. package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
  169. package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
  170. package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  171. package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
  172. package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  173. package/dist/development/core/request-routing/registered-routes.d.mts +10 -3
  174. package/dist/development/core/request-routing/registered-routes.mjs +13 -3
  175. package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
  176. package/dist/development/core/request-routing/route-types.d.mts +2 -2
  177. package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
  178. package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
  179. package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
  180. package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
  181. package/dist/development/core/shopify-scripts/constants.mjs +3 -1
  182. package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
  183. package/dist/development/core/shopify-scripts/global.mjs +13 -11
  184. package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
  185. package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
  186. package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
  187. package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
  188. package/dist/development/core/shopify-scripts/index.d.mts +1 -0
  189. package/dist/development/core/shopify-scripts/index.mjs +12 -9
  190. package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
  191. package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
  192. package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
  193. package/dist/development/core/shopify-scripts/types.d.mts +4 -2
  194. package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
  195. package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  196. package/dist/development/core/standard-routes/build.d.mts +7 -2
  197. package/dist/development/core/standard-routes/build.mjs +10 -3
  198. package/dist/development/core/standard-routes/build.mjs.map +1 -1
  199. package/dist/development/core/standard-routes/match.mjs +11 -1
  200. package/dist/development/core/standard-routes/match.mjs.map +1 -1
  201. package/dist/development/core/standard-routes/path.mjs +14 -3
  202. package/dist/development/core/standard-routes/path.mjs.map +1 -1
  203. package/dist/development/core/standard-routes/types.d.mts +6 -1
  204. package/dist/development/core/url.mjs +5 -3
  205. package/dist/development/core/url.mjs.map +1 -1
  206. package/dist/development/customer-account/session.mjs.map +1 -1
  207. package/dist/development/globals.d.mts +8 -4
  208. package/dist/development/graphql/type-resolver.d.mts +13 -1
  209. package/dist/development/react/index.d.mts +2 -2
  210. package/dist/globals.d.mts +8 -4
  211. package/dist/graphql/type-resolver.d.mts +13 -1
  212. package/dist/react/index.d.mts +2 -2
  213. package/dist/vite/index.mjs +1 -1
  214. package/dist/vue/shopify-scripts.d.mts +1 -1
  215. package/package.json +13 -3
  216. package/skills/hydrogen-analytics/SKILL.md +2 -2
  217. package/skills/hydrogen-analytics/references/react.md +2 -2
  218. package/skills/hydrogen-markets/SKILL.md +127 -93
  219. package/skills/hydrogen-markets/references/nextjs.md +77 -87
  220. package/skills/hydrogen-oxygen/references/react-router.md +1 -2
  221. package/skills/hydrogen-predictive-search/SKILL.md +18 -1
  222. package/skills/hydrogen-request-handlers/SKILL.md +23 -5
  223. package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
  224. package/skills/hydrogen-request-handlers/references/frameworks.md +8 -6
  225. package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
  226. package/skills/hydrogen-request-handlers/references/nuxt.md +7 -5
  227. package/skills/hydrogen-robots-txt/SKILL.md +87 -0
  228. package/skills/hydrogen-routing/SKILL.md +36 -14
  229. package/skills/hydrogen-setup/SKILL.md +2 -2
  230. package/skills/hydrogen-setup/references/analytics.md +5 -5
  231. package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
  232. package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
  233. package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
  234. package/skills/hydrogen-smoke-test/SKILL.md +9 -2
  235. package/skills/hydrogen-storefront-client/SKILL.md +27 -9
  236. package/skills/hydrogen-storefront-client/references/astro.md +8 -3
  237. package/skills/hydrogen-storefront-client/references/caching.md +2 -0
  238. package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
  239. package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
  240. package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
  241. package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
  242. package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
  243. package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
  244. package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
  245. package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
@@ -0,0 +1,135 @@
1
+ import { formatLocale, getLocaleHostname, getLocalePathSegment, isSameLocale } from "./locale.mjs";
2
+
3
+ //#region src/core/i18n/define.ts
4
+ const VALIDATION_URL_BASE = "https://shopify.local";
5
+ /**
6
+ * Defines the module-scope internationalization configuration for a storefront.
7
+ *
8
+ * Returns the input unchanged with its literal types preserved, so it is serializable and safe to
9
+ * import from server and client code alike. Pass it to `createShopifyRequestContext({i18n})` to
10
+ * resolve the request locale, and to the URL helpers (`getLocalizedHref`) to build links.
11
+ *
12
+ * Validation happens here, once at module load, so an invalid definition fails at startup rather
13
+ * than on the first request that would hit the bad entry.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * // Single locale: every request resolves to the default.
18
+ * export const i18n = defineShopifyI18n({
19
+ * defaultLocale: { language: "EN", country: "US" },
20
+ * });
21
+ *
22
+ * // Path-prefixed locales: `/fr-ca/products/x`, default served unprefixed.
23
+ * export const i18n = defineShopifyI18n({
24
+ * defaultLocale: { language: "EN", country: "US" },
25
+ * routing: {
26
+ * type: "pathname",
27
+ * locales: [
28
+ * { language: "FR", country: "CA" },
29
+ * { language: "PT_BR", country: "BR", pathSegment: "br" },
30
+ * ],
31
+ * },
32
+ * });
33
+ *
34
+ * // One hostname per locale; the default must be listed so it has a canonical host.
35
+ * export const i18n = defineShopifyI18n({
36
+ * defaultLocale: { language: "EN", country: "US" },
37
+ * routing: {
38
+ * type: "domain",
39
+ * locales: [
40
+ * { language: "EN", country: "US", hostname: "example.com" },
41
+ * { language: "FR", country: "CA", hostname: "fr.example.ca" },
42
+ * ],
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ function defineShopifyI18n(i18n) {
48
+ assertLocale(i18n.defaultLocale, "defaultLocale");
49
+ const routing = i18n.routing;
50
+ if (!routing) return i18n;
51
+ if (routing.locales.length === 0) throw new Error(`defineShopifyI18n: routing.locales is empty. Omit "routing" for a single-locale storefront.`);
52
+ switch (routing.type) {
53
+ case "pathname":
54
+ validatePathnameLocales(i18n.defaultLocale, routing.locales);
55
+ break;
56
+ case "domain":
57
+ validateDomainLocales(i18n.defaultLocale, routing.locales);
58
+ break;
59
+ default: throw new Error(`defineShopifyI18n: unknown routing.type.`);
60
+ }
61
+ return i18n;
62
+ }
63
+ function getSupportedLocales(i18n) {
64
+ const routing = i18n.routing;
65
+ if (!routing) return [i18n.defaultLocale];
66
+ if (routing.type === "domain") {
67
+ const isDefault = (locale) => isSameLocale(locale, i18n.defaultLocale);
68
+ return [...routing.locales.filter(isDefault), ...routing.locales.filter((locale) => !isDefault(locale))];
69
+ }
70
+ return [i18n.defaultLocale, ...routing.locales];
71
+ }
72
+ function assertLocale(locale, label) {
73
+ if (!locale?.language || !locale?.country) throw new Error(`defineShopifyI18n: ${label} requires both "language" and "country".`);
74
+ }
75
+ function validatePathnameLocales(defaultLocale, locales) {
76
+ const seenSegments = new Map([[getLocalePathSegment(defaultLocale), defaultLocale]]);
77
+ const seenLocales = [];
78
+ for (const locale of locales) {
79
+ const label = `routing.locales entry ${formatLocale(locale)}`;
80
+ assertLocale(locale, label);
81
+ if (isSameLocale(locale, defaultLocale)) throw new Error(`defineShopifyI18n: defaultLocale ${formatLocale(defaultLocale)} must not appear in pathname routing.locales. It is served unprefixed so each page has one canonical URL.`);
82
+ if (seenLocales.some((seen) => isSameLocale(seen, locale))) throw new Error(`defineShopifyI18n: ${label} is listed more than once.`);
83
+ seenLocales.push(locale);
84
+ if (locale.pathSegment !== void 0 && !isSinglePathSegment(locale.pathSegment)) throw new Error(`defineShopifyI18n: ${label} has invalid pathSegment ${JSON.stringify(locale.pathSegment)}. Use one path segment that URL parsing leaves unchanged: no slashes, whitespace, "?", "#", "\\", or characters that need percent-encoding, for example "br".`);
85
+ const segment = getLocalePathSegment(locale);
86
+ const collision = seenSegments.get(segment);
87
+ if (collision) throw new Error(`defineShopifyI18n: ${label} and ${formatLocale(collision)} both resolve to the path segment "${segment}". Set a distinct pathSegment on one of them.`);
88
+ seenSegments.set(segment, locale);
89
+ }
90
+ }
91
+ /**
92
+ * Matching compares `URL.pathname` against the segment verbatim, so anything the URL parser
93
+ * normalizes away (`.`, `..`, `?`, `#`, `\`) or percent-encodes (whitespace, non-ASCII) would
94
+ * define fine but never match a request.
95
+ */
96
+ function isSinglePathSegment(segment) {
97
+ if (segment === "" || segment.includes("/")) return false;
98
+ return new URL(`/${segment}`, VALIDATION_URL_BASE).pathname === `/${segment}`;
99
+ }
100
+ function validateDomainLocales(defaultLocale, locales) {
101
+ const seenHostnames = /* @__PURE__ */ new Map();
102
+ const seenLocales = [];
103
+ let defaultListed = false;
104
+ for (const locale of locales) {
105
+ const label = `routing.locales entry ${formatLocale(locale)}`;
106
+ assertLocale(locale, label);
107
+ if (seenLocales.some((seen) => isSameLocale(seen, locale))) throw new Error(`defineShopifyI18n: ${label} is listed more than once.`);
108
+ seenLocales.push(locale);
109
+ if (isSameLocale(locale, defaultLocale)) defaultListed = true;
110
+ const hostname = locale.hostname;
111
+ if (typeof hostname !== "string" || parseHostname(hostname) !== hostname.toLowerCase()) throw new Error(`defineShopifyI18n: ${label} has invalid hostname ${JSON.stringify(hostname)}. Use the bare hostname exactly as URL.hostname reports it (no scheme, port, or path; punycode for non-ASCII), for example "fr.example.com".`);
112
+ const normalizedHostname = getLocaleHostname(locale);
113
+ const collision = seenHostnames.get(normalizedHostname);
114
+ if (collision) throw new Error(`defineShopifyI18n: ${label} and ${formatLocale(collision)} both use hostname "${normalizedHostname}". Each hostname maps to exactly one locale.`);
115
+ seenHostnames.set(normalizedHostname, locale);
116
+ }
117
+ if (!defaultListed) throw new Error(`defineShopifyI18n: defaultLocale ${formatLocale(defaultLocale)} must appear in domain routing.locales so it has a canonical hostname.`);
118
+ }
119
+ /**
120
+ * Matching compares `URL.hostname`, which lowercases, strips userinfo/port/path, and encodes
121
+ * Unicode as punycode. Returns that canonical form, or `undefined` when the value is not a
122
+ * hostname at all, so the caller can reject anything that would define fine but never match.
123
+ */
124
+ function parseHostname(hostname) {
125
+ if (hostname === "") return void 0;
126
+ try {
127
+ return new URL(`https://${hostname}`).hostname;
128
+ } catch {
129
+ return;
130
+ }
131
+ }
132
+
133
+ //#endregion
134
+ export { defineShopifyI18n, getSupportedLocales };
135
+ //# sourceMappingURL=define.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define.mjs","names":[],"sources":["../../../src/core/i18n/define.ts"],"sourcesContent":["import { formatLocale, getLocaleHostname, getLocalePathSegment, isSameLocale } from \"./locale\";\nimport type {\n ShopifyDomainLocale,\n ShopifyI18n,\n ShopifyLocale,\n ShopifyPathnameLocale,\n ShopifySupportedLocale,\n} from \"./types\";\n\nconst VALIDATION_URL_BASE = \"https://shopify.local\";\n\n/**\n * Defines the module-scope internationalization configuration for a storefront.\n *\n * Returns the input unchanged with its literal types preserved, so it is serializable and safe to\n * import from server and client code alike. Pass it to `createShopifyRequestContext({i18n})` to\n * resolve the request locale, and to the URL helpers (`getLocalizedHref`) to build links.\n *\n * Validation happens here, once at module load, so an invalid definition fails at startup rather\n * than on the first request that would hit the bad entry.\n *\n * @example\n * ```ts\n * // Single locale: every request resolves to the default.\n * export const i18n = defineShopifyI18n({\n * defaultLocale: { language: \"EN\", country: \"US\" },\n * });\n *\n * // Path-prefixed locales: `/fr-ca/products/x`, default served unprefixed.\n * export const i18n = defineShopifyI18n({\n * defaultLocale: { language: \"EN\", country: \"US\" },\n * routing: {\n * type: \"pathname\",\n * locales: [\n * { language: \"FR\", country: \"CA\" },\n * { language: \"PT_BR\", country: \"BR\", pathSegment: \"br\" },\n * ],\n * },\n * });\n *\n * // One hostname per locale; the default must be listed so it has a canonical host.\n * export const i18n = defineShopifyI18n({\n * defaultLocale: { language: \"EN\", country: \"US\" },\n * routing: {\n * type: \"domain\",\n * locales: [\n * { language: \"EN\", country: \"US\", hostname: \"example.com\" },\n * { language: \"FR\", country: \"CA\", hostname: \"fr.example.ca\" },\n * ],\n * },\n * });\n * ```\n */\nexport function defineShopifyI18n<const TI18n extends ShopifyI18n>(i18n: TI18n): TI18n {\n assertLocale(i18n.defaultLocale, \"defaultLocale\");\n\n const routing = i18n.routing;\n if (!routing) return i18n;\n\n if (routing.locales.length === 0) {\n throw new Error(\n `defineShopifyI18n: routing.locales is empty. Omit \"routing\" for a single-locale storefront.`,\n );\n }\n\n switch (routing.type) {\n case \"pathname\":\n validatePathnameLocales(i18n.defaultLocale, routing.locales);\n break;\n case \"domain\":\n validateDomainLocales(i18n.defaultLocale, routing.locales);\n break;\n default:\n routing satisfies never;\n throw new Error(`defineShopifyI18n: unknown routing.type.`);\n }\n\n return i18n;\n}\n\n/**\n * Every locale the definition can resolve to, default first. Entries keep their routing keys\n * (`pathSegment`, `hostname`) and any extra fields, so sitemaps and selectors can enumerate URLs.\n */\nexport function getSupportedLocales<const TI18n extends ShopifyI18n>(\n i18n: TI18n,\n): ShopifySupportedLocale<TI18n>[];\nexport function getSupportedLocales(i18n: ShopifyI18n): ShopifySupportedLocale[] {\n const routing = i18n.routing;\n if (!routing) return [i18n.defaultLocale];\n\n // Domain routing lists the default locale itself (it needs a hostname); pathname routing\n // keeps it out of the list so the default stays unprefixed.\n if (routing.type === \"domain\") {\n const isDefault = (locale: ShopifyLocale) => isSameLocale(locale, i18n.defaultLocale);\n return [\n ...routing.locales.filter(isDefault),\n ...routing.locales.filter((locale) => !isDefault(locale)),\n ];\n }\n\n return [i18n.defaultLocale, ...routing.locales];\n}\n\nfunction assertLocale(locale: ShopifyLocale | undefined, label: string): void {\n if (!locale?.language || !locale?.country) {\n throw new Error(`defineShopifyI18n: ${label} requires both \"language\" and \"country\".`);\n }\n}\n\nfunction validatePathnameLocales(\n defaultLocale: ShopifyLocale,\n locales: readonly ShopifyPathnameLocale[],\n): void {\n // The default locale is served unprefixed but keeps a segment for `[locale]` route params, so\n // no routed locale may reuse it.\n const seenSegments = new Map<string, ShopifyLocale>([\n [getLocalePathSegment(defaultLocale), defaultLocale],\n ]);\n const seenLocales: ShopifyLocale[] = [];\n\n for (const locale of locales) {\n const label = `routing.locales entry ${formatLocale(locale)}`;\n assertLocale(locale, label);\n\n if (isSameLocale(locale, defaultLocale)) {\n throw new Error(\n `defineShopifyI18n: defaultLocale ${formatLocale(defaultLocale)} must not appear in pathname routing.locales. It is served unprefixed so each page has one canonical URL.`,\n );\n }\n if (seenLocales.some((seen) => isSameLocale(seen, locale))) {\n throw new Error(`defineShopifyI18n: ${label} is listed more than once.`);\n }\n seenLocales.push(locale);\n\n if (locale.pathSegment !== undefined && !isSinglePathSegment(locale.pathSegment)) {\n throw new Error(\n `defineShopifyI18n: ${label} has invalid pathSegment ${JSON.stringify(locale.pathSegment)}. Use one path segment that URL parsing leaves unchanged: no slashes, whitespace, \"?\", \"#\", \"\\\\\", or characters that need percent-encoding, for example \"br\".`,\n );\n }\n\n const segment = getLocalePathSegment(locale);\n const collision = seenSegments.get(segment);\n if (collision) {\n throw new Error(\n `defineShopifyI18n: ${label} and ${formatLocale(collision)} both resolve to the path segment \"${segment}\". Set a distinct pathSegment on one of them.`,\n );\n }\n seenSegments.set(segment, locale);\n }\n}\n\n/**\n * Matching compares `URL.pathname` against the segment verbatim, so anything the URL parser\n * normalizes away (`.`, `..`, `?`, `#`, `\\`) or percent-encodes (whitespace, non-ASCII) would\n * define fine but never match a request.\n */\nfunction isSinglePathSegment(segment: string): boolean {\n if (segment === \"\" || segment.includes(\"/\")) return false;\n return new URL(`/${segment}`, VALIDATION_URL_BASE).pathname === `/${segment}`;\n}\n\nfunction validateDomainLocales(\n defaultLocale: ShopifyLocale,\n locales: readonly ShopifyDomainLocale[],\n): void {\n const seenHostnames = new Map<string, ShopifyDomainLocale>();\n const seenLocales: ShopifyLocale[] = [];\n let defaultListed = false;\n\n for (const locale of locales) {\n const label = `routing.locales entry ${formatLocale(locale)}`;\n assertLocale(locale, label);\n\n if (seenLocales.some((seen) => isSameLocale(seen, locale))) {\n throw new Error(`defineShopifyI18n: ${label} is listed more than once.`);\n }\n seenLocales.push(locale);\n if (isSameLocale(locale, defaultLocale)) defaultListed = true;\n\n const hostname = locale.hostname;\n if (typeof hostname !== \"string\" || parseHostname(hostname) !== hostname.toLowerCase()) {\n throw new Error(\n `defineShopifyI18n: ${label} has invalid hostname ${JSON.stringify(hostname)}. Use the bare hostname exactly as URL.hostname reports it (no scheme, port, or path; punycode for non-ASCII), for example \"fr.example.com\".`,\n );\n }\n\n const normalizedHostname = getLocaleHostname(locale);\n const collision = seenHostnames.get(normalizedHostname);\n if (collision) {\n throw new Error(\n `defineShopifyI18n: ${label} and ${formatLocale(collision)} both use hostname \"${normalizedHostname}\". Each hostname maps to exactly one locale.`,\n );\n }\n seenHostnames.set(normalizedHostname, locale);\n }\n\n if (!defaultListed) {\n throw new Error(\n `defineShopifyI18n: defaultLocale ${formatLocale(defaultLocale)} must appear in domain routing.locales so it has a canonical hostname.`,\n );\n }\n}\n\n/**\n * Matching compares `URL.hostname`, which lowercases, strips userinfo/port/path, and encodes\n * Unicode as punycode. Returns that canonical form, or `undefined` when the value is not a\n * hostname at all, so the caller can reject anything that would define fine but never match.\n */\nfunction parseHostname(hostname: string): string | undefined {\n if (hostname === \"\") return undefined;\n try {\n return new URL(`https://${hostname}`).hostname;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;AASA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4C5B,SAAgB,kBAAmD,MAAoB;AACrF,cAAa,KAAK,eAAe,gBAAgB;CAEjD,MAAM,UAAU,KAAK;AACrB,KAAI,CAAC,QAAS,QAAO;AAErB,KAAI,QAAQ,QAAQ,WAAW,EAC7B,OAAM,IAAI,MACR,8FACD;AAGH,SAAQ,QAAQ,MAAhB;EACE,KAAK;AACH,2BAAwB,KAAK,eAAe,QAAQ,QAAQ;AAC5D;EACF,KAAK;AACH,yBAAsB,KAAK,eAAe,QAAQ,QAAQ;AAC1D;EACF,QAEE,OAAM,IAAI,MAAM,2CAA2C;;AAG/D,QAAO;;AAUT,SAAgB,oBAAoB,MAA6C;CAC/E,MAAM,UAAU,KAAK;AACrB,KAAI,CAAC,QAAS,QAAO,CAAC,KAAK,cAAc;AAIzC,KAAI,QAAQ,SAAS,UAAU;EAC7B,MAAM,aAAa,WAA0B,aAAa,QAAQ,KAAK,cAAc;AACrF,SAAO,CACL,GAAG,QAAQ,QAAQ,OAAO,UAAU,EACpC,GAAG,QAAQ,QAAQ,QAAQ,WAAW,CAAC,UAAU,OAAO,CAAC,CAC1D;;AAGH,QAAO,CAAC,KAAK,eAAe,GAAG,QAAQ,QAAQ;;AAGjD,SAAS,aAAa,QAAmC,OAAqB;AAC5E,KAAI,CAAC,QAAQ,YAAY,CAAC,QAAQ,QAChC,OAAM,IAAI,MAAM,sBAAsB,MAAM,0CAA0C;;AAI1F,SAAS,wBACP,eACA,SACM;CAGN,MAAM,eAAe,IAAI,IAA2B,CAClD,CAAC,qBAAqB,cAAc,EAAE,cAAc,CACrD,CAAC;CACF,MAAM,cAA+B,EAAE;AAEvC,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,QAAQ,yBAAyB,aAAa,OAAO;AAC3D,eAAa,QAAQ,MAAM;AAE3B,MAAI,aAAa,QAAQ,cAAc,CACrC,OAAM,IAAI,MACR,oCAAoC,aAAa,cAAc,CAAC,2GACjE;AAEH,MAAI,YAAY,MAAM,SAAS,aAAa,MAAM,OAAO,CAAC,CACxD,OAAM,IAAI,MAAM,sBAAsB,MAAM,4BAA4B;AAE1E,cAAY,KAAK,OAAO;AAExB,MAAI,OAAO,gBAAgB,UAAa,CAAC,oBAAoB,OAAO,YAAY,CAC9E,OAAM,IAAI,MACR,sBAAsB,MAAM,2BAA2B,KAAK,UAAU,OAAO,YAAY,CAAC,+JAC3F;EAGH,MAAM,UAAU,qBAAqB,OAAO;EAC5C,MAAM,YAAY,aAAa,IAAI,QAAQ;AAC3C,MAAI,UACF,OAAM,IAAI,MACR,sBAAsB,MAAM,OAAO,aAAa,UAAU,CAAC,qCAAqC,QAAQ,+CACzG;AAEH,eAAa,IAAI,SAAS,OAAO;;;;;;;;AASrC,SAAS,oBAAoB,SAA0B;AACrD,KAAI,YAAY,MAAM,QAAQ,SAAS,IAAI,CAAE,QAAO;AACpD,QAAO,IAAI,IAAI,IAAI,WAAW,oBAAoB,CAAC,aAAa,IAAI;;AAGtE,SAAS,sBACP,eACA,SACM;CACN,MAAM,gCAAgB,IAAI,KAAkC;CAC5D,MAAM,cAA+B,EAAE;CACvC,IAAI,gBAAgB;AAEpB,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,QAAQ,yBAAyB,aAAa,OAAO;AAC3D,eAAa,QAAQ,MAAM;AAE3B,MAAI,YAAY,MAAM,SAAS,aAAa,MAAM,OAAO,CAAC,CACxD,OAAM,IAAI,MAAM,sBAAsB,MAAM,4BAA4B;AAE1E,cAAY,KAAK,OAAO;AACxB,MAAI,aAAa,QAAQ,cAAc,CAAE,iBAAgB;EAEzD,MAAM,WAAW,OAAO;AACxB,MAAI,OAAO,aAAa,YAAY,cAAc,SAAS,KAAK,SAAS,aAAa,CACpF,OAAM,IAAI,MACR,sBAAsB,MAAM,wBAAwB,KAAK,UAAU,SAAS,CAAC,8IAC9E;EAGH,MAAM,qBAAqB,kBAAkB,OAAO;EACpD,MAAM,YAAY,cAAc,IAAI,mBAAmB;AACvD,MAAI,UACF,OAAM,IAAI,MACR,sBAAsB,MAAM,OAAO,aAAa,UAAU,CAAC,sBAAsB,mBAAmB,8CACrG;AAEH,gBAAc,IAAI,oBAAoB,OAAO;;AAG/C,KAAI,CAAC,cACH,OAAM,IAAI,MACR,oCAAoC,aAAa,cAAc,CAAC,wEACjE;;;;;;;AASL,SAAS,cAAc,UAAsC;AAC3D,KAAI,aAAa,GAAI,QAAO;AAC5B,KAAI;AACF,SAAO,IAAI,IAAI,WAAW,WAAW,CAAC;SAChC;AACN"}
@@ -0,0 +1,18 @@
1
+ import { ShopifyLocale } from "./types.mjs";
2
+
3
+ //#region src/core/i18n/errors.d.ts
4
+ /**
5
+ * A locale (or its path segment) is not one of the definition's supported locales.
6
+ *
7
+ * Thrown by `resolveSupportedLocale`, and therefore by `createShopifyRequestContext({locale})`
8
+ * and `getLocalizedHref`. Catch it where an unknown locale is a routing outcome rather than a
9
+ * bug, for example to return a 404 from a `[locale]` route segment.
10
+ */
11
+ declare class UnsupportedLocaleError extends Error {
12
+ readonly requested: ShopifyLocale | string;
13
+ readonly supported: readonly ShopifyLocale[];
14
+ constructor(requested: ShopifyLocale | string, supported: readonly ShopifyLocale[]);
15
+ }
16
+ //#endregion
17
+ export { UnsupportedLocaleError };
18
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1,24 @@
1
+ //#region src/core/i18n/errors.ts
2
+ /**
3
+ * A locale (or its path segment) is not one of the definition's supported locales.
4
+ *
5
+ * Thrown by `resolveSupportedLocale`, and therefore by `createShopifyRequestContext({locale})`
6
+ * and `getLocalizedHref`. Catch it where an unknown locale is a routing outcome rather than a
7
+ * bug, for example to return a 404 from a `[locale]` route segment.
8
+ */
9
+ var UnsupportedLocaleError = class extends Error {
10
+ requested;
11
+ supported;
12
+ constructor(requested, supported) {
13
+ const requestedLabel = typeof requested === "string" ? `Path segment "${requested}"` : `Locale ${requested.language}-${requested.country}`;
14
+ const supportedLabel = supported.map((l) => `${l.language}-${l.country}`).join(", ");
15
+ super(`${requestedLabel} is not defined in this storefront's i18n. Supported locales: ${supportedLabel}.`);
16
+ this.name = "UnsupportedLocaleError";
17
+ this.requested = requested;
18
+ this.supported = supported;
19
+ }
20
+ };
21
+
22
+ //#endregion
23
+ export { UnsupportedLocaleError };
24
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../src/core/i18n/errors.ts"],"sourcesContent":["import type { ShopifyLocale } from \"./types\";\n\n/**\n * A locale (or its path segment) is not one of the definition's supported locales.\n *\n * Thrown by `resolveSupportedLocale`, and therefore by `createShopifyRequestContext({locale})`\n * and `getLocalizedHref`. Catch it where an unknown locale is a routing outcome rather than a\n * bug, for example to return a 404 from a `[locale]` route segment.\n */\nexport class UnsupportedLocaleError extends Error {\n readonly requested: ShopifyLocale | string;\n readonly supported: readonly ShopifyLocale[];\n\n constructor(requested: ShopifyLocale | string, supported: readonly ShopifyLocale[]) {\n const requestedLabel =\n typeof requested === \"string\"\n ? `Path segment \"${requested}\"`\n : `Locale ${requested.language}-${requested.country}`;\n const supportedLabel = supported.map((l) => `${l.language}-${l.country}`).join(\", \");\n super(\n `${requestedLabel} is not defined in this storefront's i18n. Supported locales: ${supportedLabel}.`,\n );\n this.name = \"UnsupportedLocaleError\";\n this.requested = requested;\n this.supported = supported;\n }\n}\n"],"mappings":";;;;;;;;AASA,IAAa,yBAAb,cAA4C,MAAM;CAChD,AAAS;CACT,AAAS;CAET,YAAY,WAAmC,WAAqC;EAClF,MAAM,iBACJ,OAAO,cAAc,WACjB,iBAAiB,UAAU,KAC3B,UAAU,UAAU,SAAS,GAAG,UAAU;EAChD,MAAM,iBAAiB,UAAU,KAAK,MAAM,GAAG,EAAE,SAAS,GAAG,EAAE,UAAU,CAAC,KAAK,KAAK;AACpF,QACE,GAAG,eAAe,gEAAgE,eAAe,GAClG;AACD,OAAK,OAAO;AACZ,OAAK,YAAY;AACjB,OAAK,YAAY"}
@@ -0,0 +1,28 @@
1
+ import { ShopifyI18n, ShopifyLocale } from "./types.mjs";
2
+
3
+ //#region src/core/i18n/href.d.ts
4
+ type GetLocalizedHrefOptions = {
5
+ i18n: ShopifyI18n; /** Target locale. Must be one of the definition's supported locales. */
6
+ locale: ShopifyLocale;
7
+ };
8
+ /**
9
+ * Rewrites an href so it points at the same page in another locale.
10
+ *
11
+ * The result is always valid for `href` or a `Location` header, but its shape follows the routing
12
+ * strategy:
13
+ * - pathname routing returns a path (`/fr-ca/products/x`); any existing locale prefix is replaced.
14
+ * - domain routing returns an absolute URL on the target locale's hostname.
15
+ * - no routing returns the href unchanged.
16
+ *
17
+ * Absolute inputs keep their scheme; relative inputs stay relative under pathname routing and use
18
+ * `https:` under domain routing.
19
+ *
20
+ * @throws when `locale` is not defined in `i18n`.
21
+ */
22
+ declare function getLocalizedHref(href: string, {
23
+ i18n,
24
+ locale
25
+ }: GetLocalizedHrefOptions): string;
26
+ //#endregion
27
+ export { GetLocalizedHrefOptions, getLocalizedHref };
28
+ //# sourceMappingURL=href.d.mts.map
@@ -0,0 +1,45 @@
1
+ import { isAbsoluteUrl, stripI18nPathPrefix } from "../standard-routes/path.mjs";
2
+ import { matchLocale, resolveSupportedLocale } from "./match.mjs";
3
+
4
+ //#region src/core/i18n/href.ts
5
+ const RELATIVE_URL_BASE = "https://shopify.local";
6
+ /**
7
+ * Rewrites an href so it points at the same page in another locale.
8
+ *
9
+ * The result is always valid for `href` or a `Location` header, but its shape follows the routing
10
+ * strategy:
11
+ * - pathname routing returns a path (`/fr-ca/products/x`); any existing locale prefix is replaced.
12
+ * - domain routing returns an absolute URL on the target locale's hostname.
13
+ * - no routing returns the href unchanged.
14
+ *
15
+ * Absolute inputs keep their scheme; relative inputs stay relative under pathname routing and use
16
+ * `https:` under domain routing.
17
+ *
18
+ * @throws when `locale` is not defined in `i18n`.
19
+ */
20
+ function getLocalizedHref(href, { i18n, locale }) {
21
+ const target = resolveSupportedLocale(locale, i18n);
22
+ const routing = i18n.routing;
23
+ if (!routing) return href;
24
+ const absolute = isAbsoluteUrl(href);
25
+ const url = new URL(href, RELATIVE_URL_BASE);
26
+ switch (routing.type) {
27
+ case "pathname": {
28
+ const current = matchLocale(url, i18n);
29
+ const unprefixedPathname = stripI18nPathPrefix(url.pathname, current.pathPrefix);
30
+ url.pathname = unprefixedPathname === "/" ? target.pathPrefix || "/" : `${target.pathPrefix}${unprefixedPathname}`;
31
+ return absolute ? url.toString() : `${url.pathname}${url.search}${url.hash}`;
32
+ }
33
+ case "domain":
34
+ if (!("hostname" in target) || typeof target.hostname !== "string") throw new Error(`getLocalizedHref: locale ${target.language}-${target.country} has no hostname under domain routing.`);
35
+ url.hostname = target.hostname;
36
+ url.port = "";
37
+ if (!absolute) url.protocol = "https:";
38
+ return url.toString();
39
+ default: return href;
40
+ }
41
+ }
42
+
43
+ //#endregion
44
+ export { getLocalizedHref };
45
+ //# sourceMappingURL=href.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"href.mjs","names":[],"sources":["../../../src/core/i18n/href.ts"],"sourcesContent":["import { isAbsoluteUrl, stripI18nPathPrefix } from \"../standard-routes/path\";\nimport { matchLocale, resolveSupportedLocale } from \"./match\";\nimport type { ShopifyI18n, ShopifyLocale } from \"./types\";\n\nconst RELATIVE_URL_BASE = \"https://shopify.local\";\n\nexport type GetLocalizedHrefOptions = {\n i18n: ShopifyI18n;\n /** Target locale. Must be one of the definition's supported locales. */\n locale: ShopifyLocale;\n};\n\n/**\n * Rewrites an href so it points at the same page in another locale.\n *\n * The result is always valid for `href` or a `Location` header, but its shape follows the routing\n * strategy:\n * - pathname routing returns a path (`/fr-ca/products/x`); any existing locale prefix is replaced.\n * - domain routing returns an absolute URL on the target locale's hostname.\n * - no routing returns the href unchanged.\n *\n * Absolute inputs keep their scheme; relative inputs stay relative under pathname routing and use\n * `https:` under domain routing.\n *\n * @throws when `locale` is not defined in `i18n`.\n */\nexport function getLocalizedHref(href: string, { i18n, locale }: GetLocalizedHrefOptions): string {\n // Validate first so an unsupported locale throws regardless of routing strategy.\n const target = resolveSupportedLocale(locale, i18n);\n\n const routing = i18n.routing;\n if (!routing) return href;\n\n const absolute = isAbsoluteUrl(href);\n const url = new URL(href, RELATIVE_URL_BASE);\n\n switch (routing.type) {\n case \"pathname\": {\n const current = matchLocale(url, i18n);\n const unprefixedPathname = stripI18nPathPrefix(url.pathname, current.pathPrefix);\n // Keep the locale root free of a trailing slash so `/fr-ca` stays the one canonical URL.\n url.pathname =\n unprefixedPathname === \"/\"\n ? target.pathPrefix || \"/\"\n : `${target.pathPrefix}${unprefixedPathname}`;\n\n return absolute ? url.toString() : `${url.pathname}${url.search}${url.hash}`;\n }\n case \"domain\": {\n // Define-time validation guarantees every domain-routed locale carries a hostname.\n if (!(\"hostname\" in target) || typeof target.hostname !== \"string\") {\n throw new Error(\n `getLocalizedHref: locale ${target.language}-${target.country} has no hostname under domain routing.`,\n );\n }\n url.hostname = target.hostname;\n url.port = \"\";\n if (!absolute) url.protocol = \"https:\";\n\n return url.toString();\n }\n default:\n routing satisfies never;\n return href;\n }\n}\n"],"mappings":";;;;AAIA,MAAM,oBAAoB;;;;;;;;;;;;;;;AAsB1B,SAAgB,iBAAiB,MAAc,EAAE,MAAM,UAA2C;CAEhG,MAAM,SAAS,uBAAuB,QAAQ,KAAK;CAEnD,MAAM,UAAU,KAAK;AACrB,KAAI,CAAC,QAAS,QAAO;CAErB,MAAM,WAAW,cAAc,KAAK;CACpC,MAAM,MAAM,IAAI,IAAI,MAAM,kBAAkB;AAE5C,SAAQ,QAAQ,MAAhB;EACE,KAAK,YAAY;GACf,MAAM,UAAU,YAAY,KAAK,KAAK;GACtC,MAAM,qBAAqB,oBAAoB,IAAI,UAAU,QAAQ,WAAW;AAEhF,OAAI,WACF,uBAAuB,MACnB,OAAO,cAAc,MACrB,GAAG,OAAO,aAAa;AAE7B,UAAO,WAAW,IAAI,UAAU,GAAG,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;;EAExE,KAAK;AAEH,OAAI,EAAE,cAAc,WAAW,OAAO,OAAO,aAAa,SACxD,OAAM,IAAI,MACR,4BAA4B,OAAO,SAAS,GAAG,OAAO,QAAQ,wCAC/D;AAEH,OAAI,WAAW,OAAO;AACtB,OAAI,OAAO;AACX,OAAI,CAAC,SAAU,KAAI,WAAW;AAE9B,UAAO,IAAI,UAAU;EAEvB,QAEE,QAAO"}
@@ -0,0 +1,21 @@
1
+ import { ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale } from "./types.mjs";
2
+
3
+ //#region src/core/i18n/locale.d.ts
4
+ declare function isSameLocale(a: ShopifyLocale, b: ShopifyLocale): boolean;
5
+ /**
6
+ * The URL path segment that identifies a locale: `pathSegment` when set, otherwise
7
+ * `{language}-{country}` lowercased with `_` replaced by `-` (`FR`/`CA` → `fr-ca`, `PT_BR`/`BR` →
8
+ * `pt-br-br`).
9
+ *
10
+ * Defined for every locale regardless of routing type, so it doubles as a stable identifier
11
+ * where the URL cannot carry the locale itself: a `[locale]` route param that static rendering
12
+ * derives the locale from, or the internal path a domain-routed request is rewritten to.
13
+ * `resolveSupportedLocale` accepts this segment back.
14
+ *
15
+ * Accepts matched locales too: `matchLocale` replaces `pathSegment` with the derived
16
+ * `pathPrefix`, so a non-empty prefix is the segment's source of truth there.
17
+ */
18
+ declare function getLocalePathSegment(locale: ShopifyPathnameLocale | ShopifyMatchedLocale): string;
19
+ //#endregion
20
+ export { getLocalePathSegment, isSameLocale };
21
+ //# sourceMappingURL=locale.d.mts.map
@@ -0,0 +1,36 @@
1
+ //#region src/core/i18n/locale.ts
2
+ function isSameLocale(a, b) {
3
+ return a.language === b.language && a.country === b.country;
4
+ }
5
+ function formatLocale(locale) {
6
+ return `${locale.language}-${locale.country}`;
7
+ }
8
+ /**
9
+ * The URL path segment that identifies a locale: `pathSegment` when set, otherwise
10
+ * `{language}-{country}` lowercased with `_` replaced by `-` (`FR`/`CA` → `fr-ca`, `PT_BR`/`BR` →
11
+ * `pt-br-br`).
12
+ *
13
+ * Defined for every locale regardless of routing type, so it doubles as a stable identifier
14
+ * where the URL cannot carry the locale itself: a `[locale]` route param that static rendering
15
+ * derives the locale from, or the internal path a domain-routed request is rewritten to.
16
+ * `resolveSupportedLocale` accepts this segment back.
17
+ *
18
+ * Accepts matched locales too: `matchLocale` replaces `pathSegment` with the derived
19
+ * `pathPrefix`, so a non-empty prefix is the segment's source of truth there.
20
+ */
21
+ function getLocalePathSegment(locale) {
22
+ if ("pathSegment" in locale && locale.pathSegment !== void 0) return locale.pathSegment.toLowerCase();
23
+ if ("pathPrefix" in locale && locale.pathPrefix !== "") return locale.pathPrefix.slice(1).toLowerCase();
24
+ return deriveLocalePathSegment(locale);
25
+ }
26
+ /** The locale's hostname in the form `URL.hostname` reports it. */
27
+ function getLocaleHostname(locale) {
28
+ return locale.hostname.toLowerCase();
29
+ }
30
+ function deriveLocalePathSegment(locale) {
31
+ return `${locale.language.replaceAll("_", "-")}-${locale.country}`.toLowerCase();
32
+ }
33
+
34
+ //#endregion
35
+ export { formatLocale, getLocaleHostname, getLocalePathSegment, isSameLocale };
36
+ //# sourceMappingURL=locale.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.mjs","names":[],"sources":["../../../src/core/i18n/locale.ts"],"sourcesContent":["import type {\n ShopifyDomainLocale,\n ShopifyLocale,\n ShopifyMatchedLocale,\n ShopifyPathnameLocale,\n} from \"./types\";\n\nexport function isSameLocale(a: ShopifyLocale, b: ShopifyLocale): boolean {\n return a.language === b.language && a.country === b.country;\n}\n\nexport function formatLocale(locale: ShopifyLocale): string {\n return `${locale.language}-${locale.country}`;\n}\n\n/**\n * The URL path segment that identifies a locale: `pathSegment` when set, otherwise\n * `{language}-{country}` lowercased with `_` replaced by `-` (`FR`/`CA` → `fr-ca`, `PT_BR`/`BR` →\n * `pt-br-br`).\n *\n * Defined for every locale regardless of routing type, so it doubles as a stable identifier\n * where the URL cannot carry the locale itself: a `[locale]` route param that static rendering\n * derives the locale from, or the internal path a domain-routed request is rewritten to.\n * `resolveSupportedLocale` accepts this segment back.\n *\n * Accepts matched locales too: `matchLocale` replaces `pathSegment` with the derived\n * `pathPrefix`, so a non-empty prefix is the segment's source of truth there.\n */\nexport function getLocalePathSegment(locale: ShopifyPathnameLocale | ShopifyMatchedLocale): string {\n if (\"pathSegment\" in locale && locale.pathSegment !== undefined) {\n return locale.pathSegment.toLowerCase();\n }\n if (\"pathPrefix\" in locale && locale.pathPrefix !== \"\") {\n return locale.pathPrefix.slice(1).toLowerCase();\n }\n return deriveLocalePathSegment(locale);\n}\n\n/** The locale's hostname in the form `URL.hostname` reports it. */\nexport function getLocaleHostname(locale: ShopifyDomainLocale): string {\n return locale.hostname.toLowerCase();\n}\n\nfunction deriveLocalePathSegment(locale: ShopifyLocale): string {\n return `${locale.language.replaceAll(\"_\", \"-\")}-${locale.country}`.toLowerCase();\n}\n"],"mappings":";AAOA,SAAgB,aAAa,GAAkB,GAA2B;AACxE,QAAO,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE;;AAGtD,SAAgB,aAAa,QAA+B;AAC1D,QAAO,GAAG,OAAO,SAAS,GAAG,OAAO;;;;;;;;;;;;;;;AAgBtC,SAAgB,qBAAqB,QAA8D;AACjG,KAAI,iBAAiB,UAAU,OAAO,gBAAgB,OACpD,QAAO,OAAO,YAAY,aAAa;AAEzC,KAAI,gBAAgB,UAAU,OAAO,eAAe,GAClD,QAAO,OAAO,WAAW,MAAM,EAAE,CAAC,aAAa;AAEjD,QAAO,wBAAwB,OAAO;;;AAIxC,SAAgB,kBAAkB,QAAqC;AACrE,QAAO,OAAO,SAAS,aAAa;;AAGtC,SAAS,wBAAwB,QAA+B;AAC9D,QAAO,GAAG,OAAO,SAAS,WAAW,KAAK,IAAI,CAAC,GAAG,OAAO,UAAU,aAAa"}
@@ -0,0 +1,37 @@
1
+ import { ShopifyI18n, ShopifyLocale, ShopifyMatchedLocale } from "./types.mjs";
2
+
3
+ //#region src/core/i18n/match.d.ts
4
+ /** Anything the locale can be matched from: a `Request`, a `URL`, or a URL or pathname string. */
5
+ type LocaleMatchSource = Pick<Request, "url"> | URL | string;
6
+ /**
7
+ * Resolves the locale of a request URL according to the definition's routing.
8
+ *
9
+ * Pure and synchronous: the URL is the only input, so the same URL always resolves to the same
10
+ * locale. Unknown prefixes or hostnames, and a missing URL, resolve to `defaultLocale`. Pathnames
11
+ * such as `/fr-ca/products/x` are matched under pathname routing; domain routing needs an
12
+ * absolute URL to read the hostname from.
13
+ *
14
+ * @throws when the source is a string that is neither a URL nor a pathname.
15
+ *
16
+ * Only the first path segment (pathname routing) or the hostname (domain routing) is read. The
17
+ * URL is matched as-is: framework-specific rewrites of that segment must be normalized by the
18
+ * caller. React Router single-fetch requests the locale root as `/fr-ca.data`, for example, so
19
+ * strip the suffix before matching or pass the resolved locale to `createShopifyRequestContext`.
20
+ */
21
+ declare function matchLocale<const TI18n extends ShopifyI18n>(source: LocaleMatchSource | undefined, i18n: TI18n): ShopifyMatchedLocale<TI18n>;
22
+ /**
23
+ * Resolves an explicitly chosen locale against the definition, for callers that already know the
24
+ * locale and must not derive it from a URL: static rendering, locale switchers, or a `[locale]`
25
+ * route param.
26
+ *
27
+ * Accepts either a `{language, country}` pair or the locale's path segment as returned by
28
+ * `getLocalePathSegment` (case-insensitive), so a route param can be resolved directly.
29
+ *
30
+ * @throws {UnsupportedLocaleError} when the locale or segment is not one of the definition's
31
+ * supported locales, so a stale or mistyped choice fails fast instead of silently producing an
32
+ * unroutable URL or request context. Catch it to turn an unknown route param into a 404.
33
+ */
34
+ declare function resolveSupportedLocale<const TI18n extends ShopifyI18n>(locale: ShopifyLocale | string, i18n: TI18n): ShopifyMatchedLocale<TI18n>;
35
+ //#endregion
36
+ export { LocaleMatchSource, matchLocale, resolveSupportedLocale };
37
+ //# sourceMappingURL=match.d.mts.map
@@ -0,0 +1,82 @@
1
+ import { getLocaleHostname, getLocalePathSegment, isSameLocale } from "./locale.mjs";
2
+ import { getSupportedLocales } from "./define.mjs";
3
+ import { UnsupportedLocaleError } from "./errors.mjs";
4
+
5
+ //#region src/core/i18n/match.ts
6
+ const RELATIVE_URL_BASE = "https://shopify.local";
7
+ function matchLocale(source, i18n) {
8
+ const routing = i18n.routing;
9
+ if (!routing) return toDefaultMatchedLocale(i18n);
10
+ const url = toUrl(source);
11
+ if (!url) return toDefaultMatchedLocale(i18n);
12
+ switch (routing.type) {
13
+ case "pathname": {
14
+ const segment = getFirstPathSegment(url.pathname);
15
+ const locale = segment === "" ? void 0 : routing.locales.find((candidate) => getLocalePathSegment(candidate) === segment);
16
+ return locale ? toPathnameMatchedLocale(locale) : toDefaultMatchedLocale(i18n);
17
+ }
18
+ case "domain": {
19
+ const hostname = url.hostname.toLowerCase();
20
+ const locale = routing.locales.find((candidate) => getLocaleHostname(candidate) === hostname);
21
+ return locale ? toDomainMatchedLocale(locale) : toDefaultMatchedLocale(i18n);
22
+ }
23
+ default: return toDefaultMatchedLocale(i18n);
24
+ }
25
+ }
26
+ function resolveSupportedLocale(locale, i18n) {
27
+ const matches = typeof locale === "string" ? (candidate) => getLocalePathSegment(candidate) === locale.toLowerCase() : (candidate) => isSameLocale(candidate, locale);
28
+ if (matches(i18n.defaultLocale)) return toDefaultMatchedLocale(i18n);
29
+ const routing = i18n.routing;
30
+ switch (routing?.type) {
31
+ case "pathname": {
32
+ const match = routing.locales.find(matches);
33
+ if (match) return toPathnameMatchedLocale(match);
34
+ break;
35
+ }
36
+ case "domain": {
37
+ const match = routing.locales.find(matches);
38
+ if (match) return toDomainMatchedLocale(match);
39
+ break;
40
+ }
41
+ case void 0: break;
42
+ default:
43
+ }
44
+ throw new UnsupportedLocaleError(locale, getSupportedLocales(i18n));
45
+ }
46
+ function toDefaultMatchedLocale(i18n) {
47
+ return {
48
+ ...i18n.routing?.type === "domain" ? i18n.routing.locales.find((candidate) => isSameLocale(candidate, i18n.defaultLocale)) ?? i18n.defaultLocale : i18n.defaultLocale,
49
+ pathPrefix: ""
50
+ };
51
+ }
52
+ function toPathnameMatchedLocale(locale) {
53
+ const { pathSegment: _pathSegment, ...rest } = locale;
54
+ return {
55
+ ...rest,
56
+ pathPrefix: `/${getLocalePathSegment(locale)}`
57
+ };
58
+ }
59
+ function toDomainMatchedLocale(locale) {
60
+ return {
61
+ ...locale,
62
+ pathPrefix: ""
63
+ };
64
+ }
65
+ function getFirstPathSegment(pathname) {
66
+ const [segment = ""] = pathname.replace(/^\/+/, "").split("/", 1);
67
+ return segment.toLowerCase();
68
+ }
69
+ function toUrl(source) {
70
+ if (source === void 0) return null;
71
+ if (source instanceof URL) return source;
72
+ const url = typeof source === "string" ? source : source.url;
73
+ try {
74
+ return new URL(url, RELATIVE_URL_BASE);
75
+ } catch {
76
+ throw new Error(`matchLocale: ${JSON.stringify(url)} is not a URL or pathname.`);
77
+ }
78
+ }
79
+
80
+ //#endregion
81
+ export { matchLocale, resolveSupportedLocale };
82
+ //# sourceMappingURL=match.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"match.mjs","names":[],"sources":["../../../src/core/i18n/match.ts"],"sourcesContent":["import { getSupportedLocales } from \"./define\";\nimport { UnsupportedLocaleError } from \"./errors\";\nimport { getLocaleHostname, getLocalePathSegment, isSameLocale } from \"./locale\";\nimport type {\n ShopifyDomainLocale,\n ShopifyI18n,\n ShopifyLocale,\n ShopifyMatchedLocale,\n ShopifyPathnameLocale,\n} from \"./types\";\n\nconst RELATIVE_URL_BASE = \"https://shopify.local\";\n\n/** Anything the locale can be matched from: a `Request`, a `URL`, or a URL or pathname string. */\nexport type LocaleMatchSource = Pick<Request, \"url\"> | URL | string;\n\n/**\n * Resolves the locale of a request URL according to the definition's routing.\n *\n * Pure and synchronous: the URL is the only input, so the same URL always resolves to the same\n * locale. Unknown prefixes or hostnames, and a missing URL, resolve to `defaultLocale`. Pathnames\n * such as `/fr-ca/products/x` are matched under pathname routing; domain routing needs an\n * absolute URL to read the hostname from.\n *\n * @throws when the source is a string that is neither a URL nor a pathname.\n *\n * Only the first path segment (pathname routing) or the hostname (domain routing) is read. The\n * URL is matched as-is: framework-specific rewrites of that segment must be normalized by the\n * caller. React Router single-fetch requests the locale root as `/fr-ca.data`, for example, so\n * strip the suffix before matching or pass the resolved locale to `createShopifyRequestContext`.\n */\nexport function matchLocale<const TI18n extends ShopifyI18n>(\n source: LocaleMatchSource | undefined,\n i18n: TI18n,\n): ShopifyMatchedLocale<TI18n>;\nexport function matchLocale(\n source: LocaleMatchSource | undefined,\n i18n: ShopifyI18n,\n): ShopifyMatchedLocale {\n const routing = i18n.routing;\n if (!routing) return toDefaultMatchedLocale(i18n);\n\n const url = toUrl(source);\n if (!url) return toDefaultMatchedLocale(i18n);\n\n switch (routing.type) {\n case \"pathname\": {\n const segment = getFirstPathSegment(url.pathname);\n const locale =\n segment === \"\"\n ? undefined\n : routing.locales.find((candidate) => getLocalePathSegment(candidate) === segment);\n return locale ? toPathnameMatchedLocale(locale) : toDefaultMatchedLocale(i18n);\n }\n case \"domain\": {\n const hostname = url.hostname.toLowerCase();\n const locale = routing.locales.find((candidate) => getLocaleHostname(candidate) === hostname);\n return locale ? toDomainMatchedLocale(locale) : toDefaultMatchedLocale(i18n);\n }\n default:\n routing satisfies never;\n return toDefaultMatchedLocale(i18n);\n }\n}\n\n/**\n * Resolves an explicitly chosen locale against the definition, for callers that already know the\n * locale and must not derive it from a URL: static rendering, locale switchers, or a `[locale]`\n * route param.\n *\n * Accepts either a `{language, country}` pair or the locale's path segment as returned by\n * `getLocalePathSegment` (case-insensitive), so a route param can be resolved directly.\n *\n * @throws {UnsupportedLocaleError} when the locale or segment is not one of the definition's\n * supported locales, so a stale or mistyped choice fails fast instead of silently producing an\n * unroutable URL or request context. Catch it to turn an unknown route param into a 404.\n */\nexport function resolveSupportedLocale<const TI18n extends ShopifyI18n>(\n locale: ShopifyLocale | string,\n i18n: TI18n,\n): ShopifyMatchedLocale<TI18n>;\nexport function resolveSupportedLocale(\n locale: ShopifyLocale | string,\n i18n: ShopifyI18n,\n): ShopifyMatchedLocale {\n const matches =\n typeof locale === \"string\"\n ? (candidate: ShopifyLocale) => getLocalePathSegment(candidate) === locale.toLowerCase()\n : (candidate: ShopifyLocale) => isSameLocale(candidate, locale);\n\n if (matches(i18n.defaultLocale)) return toDefaultMatchedLocale(i18n);\n\n const routing = i18n.routing;\n switch (routing?.type) {\n case \"pathname\": {\n const match = routing.locales.find(matches);\n if (match) return toPathnameMatchedLocale(match);\n break;\n }\n case \"domain\": {\n const match = routing.locales.find(matches);\n if (match) return toDomainMatchedLocale(match);\n break;\n }\n case undefined:\n break;\n default:\n routing satisfies never;\n }\n\n throw new UnsupportedLocaleError(locale, getSupportedLocales(i18n));\n}\n\nfunction toDefaultMatchedLocale(i18n: ShopifyI18n): ShopifyMatchedLocale {\n // Under domain routing the default locale's entry carries its hostname; prefer it.\n const entry =\n i18n.routing?.type === \"domain\"\n ? (i18n.routing.locales.find((candidate) => isSameLocale(candidate, i18n.defaultLocale)) ??\n i18n.defaultLocale)\n : i18n.defaultLocale;\n\n return { ...entry, pathPrefix: \"\" };\n}\n\nfunction toPathnameMatchedLocale(locale: ShopifyPathnameLocale): ShopifyMatchedLocale {\n const { pathSegment: _pathSegment, ...rest } = locale;\n return { ...rest, pathPrefix: `/${getLocalePathSegment(locale)}` };\n}\n\nfunction toDomainMatchedLocale(locale: ShopifyDomainLocale): ShopifyMatchedLocale {\n return { ...locale, pathPrefix: \"\" };\n}\n\nfunction getFirstPathSegment(pathname: string): string {\n const [segment = \"\"] = pathname.replace(/^\\/+/, \"\").split(\"/\", 1);\n return segment.toLowerCase();\n}\n\nfunction toUrl(source: LocaleMatchSource | undefined): URL | null {\n if (source === undefined) return null;\n if (source instanceof URL) return source;\n\n const url = typeof source === \"string\" ? source : source.url;\n try {\n return new URL(url, RELATIVE_URL_BASE);\n } catch {\n throw new Error(`matchLocale: ${JSON.stringify(url)} is not a URL or pathname.`);\n }\n}\n"],"mappings":";;;;;AAWA,MAAM,oBAAoB;AAwB1B,SAAgB,YACd,QACA,MACsB;CACtB,MAAM,UAAU,KAAK;AACrB,KAAI,CAAC,QAAS,QAAO,uBAAuB,KAAK;CAEjD,MAAM,MAAM,MAAM,OAAO;AACzB,KAAI,CAAC,IAAK,QAAO,uBAAuB,KAAK;AAE7C,SAAQ,QAAQ,MAAhB;EACE,KAAK,YAAY;GACf,MAAM,UAAU,oBAAoB,IAAI,SAAS;GACjD,MAAM,SACJ,YAAY,KACR,SACA,QAAQ,QAAQ,MAAM,cAAc,qBAAqB,UAAU,KAAK,QAAQ;AACtF,UAAO,SAAS,wBAAwB,OAAO,GAAG,uBAAuB,KAAK;;EAEhF,KAAK,UAAU;GACb,MAAM,WAAW,IAAI,SAAS,aAAa;GAC3C,MAAM,SAAS,QAAQ,QAAQ,MAAM,cAAc,kBAAkB,UAAU,KAAK,SAAS;AAC7F,UAAO,SAAS,sBAAsB,OAAO,GAAG,uBAAuB,KAAK;;EAE9E,QAEE,QAAO,uBAAuB,KAAK;;;AAoBzC,SAAgB,uBACd,QACA,MACsB;CACtB,MAAM,UACJ,OAAO,WAAW,YACb,cAA6B,qBAAqB,UAAU,KAAK,OAAO,aAAa,IACrF,cAA6B,aAAa,WAAW,OAAO;AAEnE,KAAI,QAAQ,KAAK,cAAc,CAAE,QAAO,uBAAuB,KAAK;CAEpE,MAAM,UAAU,KAAK;AACrB,SAAQ,SAAS,MAAjB;EACE,KAAK,YAAY;GACf,MAAM,QAAQ,QAAQ,QAAQ,KAAK,QAAQ;AAC3C,OAAI,MAAO,QAAO,wBAAwB,MAAM;AAChD;;EAEF,KAAK,UAAU;GACb,MAAM,QAAQ,QAAQ,QAAQ,KAAK,QAAQ;AAC3C,OAAI,MAAO,QAAO,sBAAsB,MAAM;AAC9C;;EAEF,KAAK,OACH;EACF;;AAIF,OAAM,IAAI,uBAAuB,QAAQ,oBAAoB,KAAK,CAAC;;AAGrE,SAAS,uBAAuB,MAAyC;AAQvE,QAAO;EAAE,GALP,KAAK,SAAS,SAAS,WAClB,KAAK,QAAQ,QAAQ,MAAM,cAAc,aAAa,WAAW,KAAK,cAAc,CAAC,IACtF,KAAK,gBACL,KAAK;EAEQ,YAAY;EAAI;;AAGrC,SAAS,wBAAwB,QAAqD;CACpF,MAAM,EAAE,aAAa,cAAc,GAAG,SAAS;AAC/C,QAAO;EAAE,GAAG;EAAM,YAAY,IAAI,qBAAqB,OAAO;EAAI;;AAGpE,SAAS,sBAAsB,QAAmD;AAChF,QAAO;EAAE,GAAG;EAAQ,YAAY;EAAI;;AAGtC,SAAS,oBAAoB,UAA0B;CACrD,MAAM,CAAC,UAAU,MAAM,SAAS,QAAQ,QAAQ,GAAG,CAAC,MAAM,KAAK,EAAE;AACjE,QAAO,QAAQ,aAAa;;AAG9B,SAAS,MAAM,QAAmD;AAChE,KAAI,WAAW,OAAW,QAAO;AACjC,KAAI,kBAAkB,IAAK,QAAO;CAElC,MAAM,MAAM,OAAO,WAAW,WAAW,SAAS,OAAO;AACzD,KAAI;AACF,SAAO,IAAI,IAAI,KAAK,kBAAkB;SAChC;AACN,QAAM,IAAI,MAAM,gBAAgB,KAAK,UAAU,IAAI,CAAC,4BAA4B"}
@@ -0,0 +1,80 @@
1
+ import { CountryCode, LanguageCode } from "../../graphql/generated/customer-account-api-types.mjs";
2
+ import { CountryCode as CountryCode$1, LanguageCode as LanguageCode$1 } from "../../graphql/generated/storefront-api-types.mjs";
3
+
4
+ //#region src/core/i18n/types.d.ts
5
+ type ShopifyLanguageCode = Extract<LanguageCode$1, LanguageCode>;
6
+ type ShopifyCountryCode = Extract<CountryCode$1, CountryCode>;
7
+ /** A `{language, country}` pair identifying one locale a storefront serves. */
8
+ type ShopifyLocale = {
9
+ language: ShopifyLanguageCode;
10
+ country: ShopifyCountryCode;
11
+ };
12
+ /**
13
+ * A locale served under a URL path prefix.
14
+ *
15
+ * The prefix is derived from the locale as `/{language}-{country}` (lowercased, `_` → `-`), so
16
+ * `{language: "FR", country: "CA"}` is served at `/fr-ca`. Set `pathSegment` when the derived
17
+ * segment is undesirable, for example `PT_BR` + `BR` derives to `pt-br-br`. A segment is a single
18
+ * path part: no slashes.
19
+ */
20
+ type ShopifyPathnameLocale = ShopifyLocale & {
21
+ pathSegment?: string;
22
+ };
23
+ /**
24
+ * A locale served from its own hostname. Match is exact on `URL.hostname` (no port), so
25
+ * `fr.example.com`, `example.fr`, and `example.com` are three separate entries. Aliases such as
26
+ * `www.` are a redirect concern and must not be listed here.
27
+ */
28
+ type ShopifyDomainLocale = ShopifyLocale & {
29
+ hostname: string;
30
+ };
31
+ type ShopifyI18nRouting = {
32
+ type: "pathname";
33
+ /**
34
+ * Locales served under a prefix. `defaultLocale` is served unprefixed only and must not be
35
+ * listed here, so every page has one canonical URL.
36
+ */
37
+ locales: readonly ShopifyPathnameLocale[];
38
+ } | {
39
+ type: "domain";
40
+ /**
41
+ * Locales served per hostname. `defaultLocale` must be listed here so it has a canonical
42
+ * hostname for links and sitemaps; it is also what unrecognized hosts (localhost, preview
43
+ * URLs) resolve to.
44
+ */
45
+ locales: readonly ShopifyDomainLocale[];
46
+ };
47
+ /**
48
+ * Module-scope internationalization definition shared by the server request context, route
49
+ * matching, URL builders, and client scripts. Create it with `defineShopifyI18n`.
50
+ */
51
+ type ShopifyI18n = {
52
+ /** Locale used when routing determines nothing: unprefixed paths or unrecognized hostnames. */defaultLocale: ShopifyLocale; /** Omit for single-locale storefronts. */
53
+ routing?: ShopifyI18nRouting;
54
+ };
55
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
56
+ /**
57
+ * `TRouting` is a naked type parameter so this distributes over `ShopifyI18nRouting | undefined`.
58
+ * Under domain routing the default locale is one of the entries (it carries the hostname), so
59
+ * the raw `defaultLocale` is not part of the union there.
60
+ */
61
+ type SupportedLocaleForRouting<TDefault, TRouting> = TRouting extends {
62
+ type: "domain";
63
+ locales: readonly (infer TLocale)[];
64
+ } ? TLocale : TRouting extends {
65
+ type: "pathname";
66
+ locales: readonly (infer TLocale)[];
67
+ } ? TDefault | TLocale : TDefault;
68
+ /** Every locale entry a definition can resolve to, keeping any extra per-locale fields. */
69
+ type ShopifySupportedLocale<TI18n extends ShopifyI18n = ShopifyI18n> = SupportedLocaleForRouting<TI18n["defaultLocale"], TI18n["routing"]>;
70
+ /**
71
+ * A locale resolved for one request. `pathSegment` is replaced by the derived `pathPrefix`
72
+ * (`""` for the default locale and under domain routing), which is what URL builders consume.
73
+ * Domain-routed locales keep their `hostname` so canonical and `hreflang` URLs can be built.
74
+ */
75
+ type ShopifyMatchedLocale<TI18n extends ShopifyI18n = ShopifyI18n> = DistributiveOmit<ShopifySupportedLocale<TI18n>, "pathSegment"> & {
76
+ pathPrefix: string;
77
+ };
78
+ //#endregion
79
+ export { ShopifyCountryCode, ShopifyDomainLocale, ShopifyI18n, ShopifyI18nRouting, ShopifyLanguageCode, ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale, ShopifySupportedLocale };
80
+ //# sourceMappingURL=types.d.mts.map