@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
@@ -18,7 +18,7 @@ import { prependPathPrefix } from "./path.mjs";
18
18
  * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.
19
19
  * @example
20
20
  * ```ts
21
- * const routeTemplates = createShopifyRouteTemplates({
21
+ * const routeTemplates = defineShopifyRouteTemplates({
22
22
  * product: "/p/:productHandle",
23
23
  * collection: "/c/:collectionHandle",
24
24
  * article: "/journal/:blogHandle/:articleHandle",
@@ -28,9 +28,16 @@ import { prependPathPrefix } from "./path.mjs";
28
28
  * ```
29
29
  * @publicDocs
30
30
  */
31
- function createShopifyRouteTemplates(routes) {
31
+ function defineShopifyRouteTemplates(routes) {
32
32
  return routes;
33
33
  }
34
+ /**
35
+ * @deprecated Renamed to `defineShopifyRouteTemplates`. This alias will be removed in the next
36
+ * major release.
37
+ */
38
+ function createShopifyRouteTemplates(routes) {
39
+ return defineShopifyRouteTemplates(routes);
40
+ }
34
41
  function getStandardRoute(routeTemplates, route, params, options = {}) {
35
42
  return buildStandardRouteTarget(routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0], params, options.pathPrefix);
36
43
  }
@@ -49,5 +56,5 @@ function interpolateRouteTemplate(template, params) {
49
56
  }
50
57
 
51
58
  //#endregion
52
- export { buildStandardRouteTarget, createShopifyRouteTemplates, getStandardRoute };
59
+ export { buildStandardRouteTarget, createShopifyRouteTemplates, defineShopifyRouteTemplates, getStandardRoute };
53
60
  //# sourceMappingURL=build.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.mjs","names":[],"sources":["../../../src/core/standard-routes/build.ts"],"sourcesContent":["import { DEFAULT_STANDARD_ROUTES, isStandardRouteParamName } from \"./defaults\";\nimport { prependPathPrefix } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n StandardRouteName,\n StandardRouteOptions,\n StandardRouteParams,\n StandardRouteParamsByName,\n} from \"./types\";\n\n/**\n * Tells Hydrogen where your app serves products, collections, and other Shopify resources. Pass\n * the returned object to `handleShopifyRoutes`, `handleShopifyRedirects`, the `ShopifyScripts` `routes`\n * option, and the predictive search URL helpers.\n *\n * Add a key only for a route that your app serves at a non-standard path. Hydrogen uses Shopify's\n * default path for each key that you leave out. Pass an empty object when your app serves every\n * route at its default path. Each template starts with `/` and includes the handle placeholders\n * for its route. Leave the locale path prefix out of templates. Hydrogen adds the prefix for you.\n *\n * TypeScript checks the shape of each template. The function returns the object that you pass.\n *\n * @param routes The non-standard paths that your app serves, keyed by standard route name.\n * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.\n * @example\n * ```ts\n * const routeTemplates = createShopifyRouteTemplates({\n * product: \"/p/:productHandle\",\n * collection: \"/c/:collectionHandle\",\n * article: \"/journal/:blogHandle/:articleHandle\",\n * cart: \"/basket\",\n * policy: \"/legal/:policyHandle\",\n * });\n * ```\n * @publicDocs\n */\nexport function createShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return routes;\n}\n\nexport function getStandardRoute<const TRoute extends StandardRouteName>(\n routeTemplates: ShopifyRouteTemplates,\n route: TRoute,\n params: StandardRouteParamsByName[TRoute],\n options: StandardRouteOptions = {},\n): string {\n const target = routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0];\n\n return buildStandardRouteTarget(target, params, options.pathPrefix);\n}\n\n/**\n * Builds a pathname from a route template, handle params, and optional i18n path prefix.\n */\nexport function buildStandardRouteTarget(\n template: string,\n params: StandardRouteParams,\n pathPrefix: string | undefined,\n): string {\n return prependPathPrefix(interpolateRouteTemplate(template, params), pathPrefix);\n}\n\nfunction interpolateRouteTemplate(template: string, params: StandardRouteParams): string {\n return template.replace(/:([A-Za-z][A-Za-z0-9_]*)/g, (placeholder, name: string) => {\n if (!isStandardRouteParamName(name)) return placeholder;\n\n const value = params[name];\n return value === undefined ? placeholder : encodeURIComponent(value);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,4BACd,QACS;AACT,QAAO;;AAGT,SAAgB,iBACd,gBACA,OACA,QACA,UAAgC,EAAE,EAC1B;AAGR,QAAO,yBAFQ,eAAe,UAAU,wBAAwB,OAAO,IAE/B,QAAQ,QAAQ,WAAW;;;;;AAMrE,SAAgB,yBACd,UACA,QACA,YACQ;AACR,QAAO,kBAAkB,yBAAyB,UAAU,OAAO,EAAE,WAAW;;AAGlF,SAAS,yBAAyB,UAAkB,QAAqC;AACvF,QAAO,SAAS,QAAQ,8BAA8B,aAAa,SAAiB;AAClF,MAAI,CAAC,yBAAyB,KAAK,CAAE,QAAO;EAE5C,MAAM,QAAQ,OAAO;AACrB,SAAO,UAAU,SAAY,cAAc,mBAAmB,MAAM;GACpE"}
1
+ {"version":3,"file":"build.mjs","names":[],"sources":["../../../src/core/standard-routes/build.ts"],"sourcesContent":["import { DEFAULT_STANDARD_ROUTES, isStandardRouteParamName } from \"./defaults\";\nimport { prependPathPrefix } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n StandardRouteName,\n StandardRouteOptions,\n StandardRouteParams,\n StandardRouteParamsByName,\n} from \"./types\";\n\n/**\n * Tells Hydrogen where your app serves products, collections, and other Shopify resources. Pass\n * the returned object to `handleShopifyRoutes`, `handleShopifyRedirects`, the `ShopifyScripts` `routes`\n * option, and the predictive search URL helpers.\n *\n * Add a key only for a route that your app serves at a non-standard path. Hydrogen uses Shopify's\n * default path for each key that you leave out. Pass an empty object when your app serves every\n * route at its default path. Each template starts with `/` and includes the handle placeholders\n * for its route. Leave the locale path prefix out of templates. Hydrogen adds the prefix for you.\n *\n * TypeScript checks the shape of each template. The function returns the object that you pass.\n *\n * @param routes The non-standard paths that your app serves, keyed by standard route name.\n * @returns The route templates, typed for Hydrogen's route, redirect, and URL helpers.\n * @example\n * ```ts\n * const routeTemplates = defineShopifyRouteTemplates({\n * product: \"/p/:productHandle\",\n * collection: \"/c/:collectionHandle\",\n * article: \"/journal/:blogHandle/:articleHandle\",\n * cart: \"/basket\",\n * policy: \"/legal/:policyHandle\",\n * });\n * ```\n * @publicDocs\n */\nexport function defineShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return routes;\n}\n\n/**\n * @deprecated Renamed to `defineShopifyRouteTemplates`. This alias will be removed in the next\n * major release.\n */\nexport function createShopifyRouteTemplates<const TRoutes extends ShopifyRouteTemplates>(\n routes: TRoutes,\n): TRoutes {\n return defineShopifyRouteTemplates(routes);\n}\n\nexport function getStandardRoute<const TRoute extends StandardRouteName>(\n routeTemplates: ShopifyRouteTemplates,\n route: TRoute,\n params: StandardRouteParamsByName[TRoute],\n options: StandardRouteOptions = {},\n): string {\n const target = routeTemplates[route] ?? DEFAULT_STANDARD_ROUTES[route][0];\n\n return buildStandardRouteTarget(target, params, options.pathPrefix);\n}\n\n/**\n * Builds a pathname from a route template, handle params, and optional i18n path prefix.\n */\nexport function buildStandardRouteTarget(\n template: string,\n params: StandardRouteParams,\n pathPrefix: string | undefined,\n): string {\n return prependPathPrefix(interpolateRouteTemplate(template, params), pathPrefix);\n}\n\nfunction interpolateRouteTemplate(template: string, params: StandardRouteParams): string {\n return template.replace(/:([A-Za-z][A-Za-z0-9_]*)/g, (placeholder, name: string) => {\n if (!isStandardRouteParamName(name)) return placeholder;\n\n const value = params[name];\n return value === undefined ? placeholder : encodeURIComponent(value);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAgB,4BACd,QACS;AACT,QAAO;;;;;;AAOT,SAAgB,4BACd,QACS;AACT,QAAO,4BAA4B,OAAO;;AAG5C,SAAgB,iBACd,gBACA,OACA,QACA,UAAgC,EAAE,EAC1B;AAGR,QAAO,yBAFQ,eAAe,UAAU,wBAAwB,OAAO,IAE/B,QAAQ,QAAQ,WAAW;;;;;AAMrE,SAAgB,yBACd,UACA,QACA,YACQ;AACR,QAAO,kBAAkB,yBAAyB,UAAU,OAAO,EAAE,WAAW;;AAGlF,SAAS,yBAAyB,UAAkB,QAAqC;AACvF,QAAO,SAAS,QAAQ,8BAA8B,aAAa,SAAiB;AAClF,MAAI,CAAC,yBAAyB,KAAK,CAAE,QAAO;EAE5C,MAAM,QAAQ,OAAO;AACrB,SAAO,UAAU,SAAY,cAAc,mBAAmB,MAAM;GACpE"}
@@ -23,7 +23,7 @@ function matchStandardRouteUrl({ baseUrl, pathPrefix, routeTemplates, url }) {
23
23
  return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;
24
24
  }
25
25
  function addStandardRouteContext(match, pathPrefix, routeTemplates) {
26
- const standardTemplate = match.route === "index" ? "/" : DEFAULT_STANDARD_ROUTES[match.route][0];
26
+ const standardTemplate = standardTemplateFor(match);
27
27
  const customTemplate = match.route === "index" ? standardTemplate : routeTemplates[match.route] ?? standardTemplate;
28
28
  return {
29
29
  ...match,
@@ -35,6 +35,16 @@ function addStandardRouteContext(match, pathPrefix, routeTemplates) {
35
35
  };
36
36
  }
37
37
  /**
38
+ * Shopify's default template for a match. A collection-scoped product template may leave out
39
+ * `:collectionHandle`; a match through one has no collection to put in the default
40
+ * collection-scoped path, so its standard path is the product's.
41
+ */
42
+ function standardTemplateFor(match) {
43
+ if (match.route === "index") return "/";
44
+ if (match.route === "productInCollection" && match.params.collectionHandle === void 0) return DEFAULT_STANDARD_ROUTES.product[0];
45
+ return DEFAULT_STANDARD_ROUTES[match.route][0];
46
+ }
47
+ /**
38
48
  * Iterates over known Shopify route names and tries the templates supplied by the caller.
39
49
  *
40
50
  * Different callers choose different template sets: redirects only match default Shopify templates
@@ -1 +1 @@
1
- {"version":3,"file":"match.mjs","names":[],"sources":["../../../src/core/standard-routes/match.ts"],"sourcesContent":["import { buildStandardRouteTarget } from \"./build\";\nimport { DEFAULT_STANDARD_ROUTES, isStandardRouteName, isStandardRouteParamName } from \"./defaults\";\nimport { parseSameOriginUrl, stripI18nPathPrefix, stripTrailingSlash } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n ShopifyPageTemplateName,\n ShopifyStandardRouteMatch,\n ShopifyStandardRouteName,\n StandardRouteName,\n StandardRouteParams,\n} from \"./types\";\n\n/**\n * Matches a URL against both configured app route templates and standard storefront routes.\n *\n * This powers browser current-page detection, where consumers need to recognize the standard\n * Shopify resource represented by either a custom app URL like `/p/snowboard` or a standard URL\n * like `/products/snowboard`. The root and standard storefront routes retain their page-template\n * identities; configured templates identify otherwise non-standard app paths.\n */\nexport function matchStandardRouteUrl({\n baseUrl,\n pathPrefix,\n routeTemplates,\n url,\n}: {\n baseUrl?: string;\n pathPrefix?: string;\n routeTemplates: ShopifyRouteTemplates;\n url: string;\n}): ShopifyStandardRouteMatch | null {\n const parsedUrl = parseSameOriginUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const pathname = stripI18nPathPrefix(stripTrailingSlash(parsedUrl.pathname), pathPrefix);\n if (pathname === \"/\") {\n return addStandardRouteContext(\n { route: \"index\", pageTemplateName: \"index\", params: {} },\n pathPrefix,\n routeTemplates,\n );\n }\n\n const match =\n matchStandardRouteTemplates(\n parsedUrl.pathname,\n pathPrefix,\n (route) => DEFAULT_STANDARD_ROUTES[route],\n ) ??\n matchStandardRouteTemplates(parsedUrl.pathname, pathPrefix, (route) => [routeTemplates[route]]);\n\n return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;\n}\n\nfunction addStandardRouteContext(\n match: Pick<ShopifyStandardRouteMatch, \"pageTemplateName\" | \"params\" | \"route\">,\n pathPrefix: string | undefined,\n routeTemplates: ShopifyRouteTemplates,\n): ShopifyStandardRouteMatch {\n const standardTemplate = match.route === \"index\" ? \"/\" : DEFAULT_STANDARD_ROUTES[match.route][0];\n const customTemplate =\n match.route === \"index\" ? standardTemplate : (routeTemplates[match.route] ?? standardTemplate);\n\n return {\n ...match,\n standardPathname: buildStandardRouteTarget(standardTemplate, match.params, pathPrefix),\n templates: {\n standard: standardTemplate,\n custom: customTemplate,\n },\n };\n}\n\n/**\n * Iterates over known Shopify route names and tries the templates supplied by the caller.\n *\n * Different callers choose different template sets: redirects only match default Shopify templates\n * for resources with custom app templates, while browser matching tries Shopify defaults before\n * configured app templates.\n */\nexport function matchStandardRouteTemplates(\n pathname: string,\n pathPrefix: string | undefined,\n getTemplatesForRoute: (route: StandardRouteName) => ReadonlyArray<string | undefined>,\n): Pick<\n ShopifyStandardRouteMatch<StandardRouteName>,\n \"pageTemplateName\" | \"params\" | \"route\"\n> | null {\n const normalizedPathname = stripI18nPathPrefix(stripTrailingSlash(pathname), pathPrefix);\n\n for (const route in DEFAULT_STANDARD_ROUTES) {\n if (!isStandardRouteName(route)) continue;\n\n for (const template of getTemplatesForRoute(route)) {\n if (!template) continue;\n\n const match = matchRouteTemplate(normalizedPathname, template);\n if (match) {\n return {\n route,\n params: match,\n pageTemplateName: normalizeStandardRouteTemplateName(route),\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Converts a standard route identity to the corresponding page template name.\n * Collection-scoped product URLs still render the `product` template, while\n * the collection-listing route uses the hyphenated `list-collections` name.\n */\nfunction normalizeStandardRouteTemplateName<TRoute extends ShopifyStandardRouteName>(\n route: TRoute,\n): ShopifyPageTemplateName<TRoute>;\nfunction normalizeStandardRouteTemplateName(\n route: ShopifyStandardRouteName,\n): ShopifyPageTemplateName {\n if (route === \"productInCollection\") return \"product\";\n if (route === \"collectionList\") return \"list-collections\";\n return route;\n}\n\n/**\n * Matches a normalized pathname against one route template and returns decoded handle params.\n */\nfunction matchRouteTemplate(pathname: string, template: string): StandardRouteParams | null {\n const match = templateToPattern(template).exec(pathname);\n if (!match) return null;\n\n const params: StandardRouteParams = {};\n for (const [name, value] of Object.entries(match.groups ?? {})) {\n if (!isStandardRouteParamName(name)) continue;\n\n params[name] = decodePathSegment(value);\n }\n\n return params;\n}\n\n/**\n * Converts a route template into a regular expression with named capture groups.\n *\n * Static path text is escaped first so regex metacharacters in templates are treated literally.\n * Then known placeholders such as `:productHandle` become segment-safe captures like\n * `(?<productHandle>[^/]+)`.\n */\nfunction templateToPattern(template: string): RegExp {\n const source = escapeRegExp(stripTrailingSlash(template)).replace(\n /:([A-Za-z][A-Za-z0-9_]*)/g,\n (placeholder, name: string) =>\n isStandardRouteParamName(name) ? `(?<${name}>[^/]+)` : placeholder,\n );\n\n return new RegExp(`^${source}$`);\n}\n\n/**\n * Escapes regex metacharacters so template text can be embedded in a `RegExp` literally.\n *\n * For example, `/products/:productHandle.json` must match a literal `.json` suffix; without\n * escaping, `.` would mean \"any character\" in the generated regex.\n */\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction decodePathSegment(segment: string): string {\n try {\n return decodeURIComponent(segment);\n } catch {\n return segment;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,EACpC,SACA,YACA,gBACA,OAMmC;CACnC,MAAM,YAAY,mBAAmB,KAAK,QAAQ;AAClD,KAAI,CAAC,UAAW,QAAO;AAGvB,KADiB,oBAAoB,mBAAmB,UAAU,SAAS,EAAE,WACjE,KAAK,IACf,QAAO,wBACL;EAAE,OAAO;EAAS,kBAAkB;EAAS,QAAQ,EAAE;EAAE,EACzD,YACA,eACD;CAGH,MAAM,QACJ,4BACE,UAAU,UACV,aACC,UAAU,wBAAwB,OACpC,IACD,4BAA4B,UAAU,UAAU,aAAa,UAAU,CAAC,eAAe,OAAO,CAAC;AAEjG,QAAO,QAAQ,wBAAwB,OAAO,YAAY,eAAe,GAAG;;AAG9E,SAAS,wBACP,OACA,YACA,gBAC2B;CAC3B,MAAM,mBAAmB,MAAM,UAAU,UAAU,MAAM,wBAAwB,MAAM,OAAO;CAC9F,MAAM,iBACJ,MAAM,UAAU,UAAU,mBAAoB,eAAe,MAAM,UAAU;AAE/E,QAAO;EAC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AAQ;SAC5B;AACN,SAAO"}
1
+ {"version":3,"file":"match.mjs","names":[],"sources":["../../../src/core/standard-routes/match.ts"],"sourcesContent":["import { buildStandardRouteTarget } from \"./build\";\nimport { DEFAULT_STANDARD_ROUTES, isStandardRouteName, isStandardRouteParamName } from \"./defaults\";\nimport { parseSameOriginUrl, stripI18nPathPrefix, stripTrailingSlash } from \"./path\";\nimport type {\n ShopifyRouteTemplates,\n ShopifyPageTemplateName,\n ShopifyStandardRouteMatch,\n ShopifyStandardRouteName,\n StandardRouteName,\n StandardRouteParams,\n} from \"./types\";\n\n/**\n * Matches a URL against both configured app route templates and standard storefront routes.\n *\n * This powers browser current-page detection, where consumers need to recognize the standard\n * Shopify resource represented by either a custom app URL like `/p/snowboard` or a standard URL\n * like `/products/snowboard`. The root and standard storefront routes retain their page-template\n * identities; configured templates identify otherwise non-standard app paths.\n */\nexport function matchStandardRouteUrl({\n baseUrl,\n pathPrefix,\n routeTemplates,\n url,\n}: {\n baseUrl?: string;\n pathPrefix?: string;\n routeTemplates: ShopifyRouteTemplates;\n url: string;\n}): ShopifyStandardRouteMatch | null {\n const parsedUrl = parseSameOriginUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const pathname = stripI18nPathPrefix(stripTrailingSlash(parsedUrl.pathname), pathPrefix);\n if (pathname === \"/\") {\n return addStandardRouteContext(\n { route: \"index\", pageTemplateName: \"index\", params: {} },\n pathPrefix,\n routeTemplates,\n );\n }\n\n const match =\n matchStandardRouteTemplates(\n parsedUrl.pathname,\n pathPrefix,\n (route) => DEFAULT_STANDARD_ROUTES[route],\n ) ??\n matchStandardRouteTemplates(parsedUrl.pathname, pathPrefix, (route) => [routeTemplates[route]]);\n\n return match ? addStandardRouteContext(match, pathPrefix, routeTemplates) : null;\n}\n\nfunction addStandardRouteContext(\n match: Pick<ShopifyStandardRouteMatch, \"pageTemplateName\" | \"params\" | \"route\">,\n pathPrefix: string | undefined,\n routeTemplates: ShopifyRouteTemplates,\n): ShopifyStandardRouteMatch {\n const standardTemplate = standardTemplateFor(match);\n const customTemplate =\n match.route === \"index\" ? standardTemplate : (routeTemplates[match.route] ?? standardTemplate);\n\n return {\n ...match,\n standardPathname: buildStandardRouteTarget(standardTemplate, match.params, pathPrefix),\n templates: {\n standard: standardTemplate,\n custom: customTemplate,\n },\n };\n}\n\n/**\n * Shopify's default template for a match. A collection-scoped product template may leave out\n * `:collectionHandle`; a match through one has no collection to put in the default\n * collection-scoped path, so its standard path is the product's.\n */\nfunction standardTemplateFor(match: Pick<ShopifyStandardRouteMatch, \"params\" | \"route\">): string {\n if (match.route === \"index\") return \"/\";\n if (match.route === \"productInCollection\" && match.params.collectionHandle === undefined) {\n return DEFAULT_STANDARD_ROUTES.product[0];\n }\n return DEFAULT_STANDARD_ROUTES[match.route][0];\n}\n\n/**\n * Iterates over known Shopify route names and tries the templates supplied by the caller.\n *\n * Different callers choose different template sets: redirects only match default Shopify templates\n * for resources with custom app templates, while browser matching tries Shopify defaults before\n * configured app templates.\n */\nexport function matchStandardRouteTemplates(\n pathname: string,\n pathPrefix: string | undefined,\n getTemplatesForRoute: (route: StandardRouteName) => ReadonlyArray<string | undefined>,\n): Pick<\n ShopifyStandardRouteMatch<StandardRouteName>,\n \"pageTemplateName\" | \"params\" | \"route\"\n> | null {\n const normalizedPathname = stripI18nPathPrefix(stripTrailingSlash(pathname), pathPrefix);\n\n for (const route in DEFAULT_STANDARD_ROUTES) {\n if (!isStandardRouteName(route)) continue;\n\n for (const template of getTemplatesForRoute(route)) {\n if (!template) continue;\n\n const match = matchRouteTemplate(normalizedPathname, template);\n if (match) {\n return {\n route,\n params: match,\n pageTemplateName: normalizeStandardRouteTemplateName(route),\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Converts a standard route identity to the corresponding page template name.\n * Collection-scoped product URLs still render the `product` template, while\n * the collection-listing route uses the hyphenated `list-collections` name.\n */\nfunction normalizeStandardRouteTemplateName<TRoute extends ShopifyStandardRouteName>(\n route: TRoute,\n): ShopifyPageTemplateName<TRoute>;\nfunction normalizeStandardRouteTemplateName(\n route: ShopifyStandardRouteName,\n): ShopifyPageTemplateName {\n if (route === \"productInCollection\") return \"product\";\n if (route === \"collectionList\") return \"list-collections\";\n return route;\n}\n\n/**\n * Matches a normalized pathname against one route template and returns decoded handle params.\n */\nfunction matchRouteTemplate(pathname: string, template: string): StandardRouteParams | null {\n const match = templateToPattern(template).exec(pathname);\n if (!match) return null;\n\n const params: StandardRouteParams = {};\n for (const [name, value] of Object.entries(match.groups ?? {})) {\n if (!isStandardRouteParamName(name)) continue;\n\n params[name] = decodePathSegment(value);\n }\n\n return params;\n}\n\n/**\n * Converts a route template into a regular expression with named capture groups.\n *\n * Static path text is escaped first so regex metacharacters in templates are treated literally.\n * Then known placeholders such as `:productHandle` become segment-safe captures like\n * `(?<productHandle>[^/]+)`.\n */\nfunction templateToPattern(template: string): RegExp {\n const source = escapeRegExp(stripTrailingSlash(template)).replace(\n /:([A-Za-z][A-Za-z0-9_]*)/g,\n (placeholder, name: string) =>\n isStandardRouteParamName(name) ? `(?<${name}>[^/]+)` : placeholder,\n );\n\n return new RegExp(`^${source}$`);\n}\n\n/**\n * Escapes regex metacharacters so template text can be embedded in a `RegExp` literally.\n *\n * For example, `/products/:productHandle.json` must match a literal `.json` suffix; without\n * escaping, `.` would mean \"any character\" in the generated regex.\n */\nfunction escapeRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction decodePathSegment(segment: string): string {\n try {\n return decodeURIComponent(segment);\n } catch {\n return segment;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAoBA,SAAgB,sBAAsB,EACpC,SACA,YACA,gBACA,OAMmC;CACnC,MAAM,YAAY,mBAAmB,KAAK,QAAQ;AAClD,KAAI,CAAC,UAAW,QAAO;AAGvB,KADiB,oBAAoB,mBAAmB,UAAU,SAAS,EAAE,WACjE,KAAK,IACf,QAAO,wBACL;EAAE,OAAO;EAAS,kBAAkB;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ACxD,KAAI,CAAC,MAAO,QAAO;CAEnB,MAAM,SAA8B,EAAE;AACtC,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,UAAU,EAAE,CAAC,EAAE;AAC9D,MAAI,CAAC,yBAAyB,KAAK,CAAE;AAErC,SAAO,QAAQ,kBAAkB,MAAM;;AAGzC,QAAO;;;;;;;;;AAUT,SAAS,kBAAkB,UAA0B;CACnD,MAAM,SAAS,aAAa,mBAAmB,SAAS,CAAC,CAAC,QACxD,8BACC,aAAa,SACZ,yBAAyB,KAAK,GAAG,MAAM,KAAK,WAAW,YAC1D;AAED,QAAO,IAAI,OAAO,IAAI,OAAO,GAAG;;;;;;;;AASlC,SAAS,aAAa,OAAuB;AAC3C,QAAO,MAAM,QAAQ,uBAAuB,OAAO;;AAGrD,SAAS,kBAAkB,SAAyB;AAClD,KAAI;AACF,SAAO,mBAAmB,QAAQ;SAC5B;AACN,SAAO"}
@@ -6,9 +6,20 @@ function prependPathPrefix(pathname, pathPrefix) {
6
6
  }
7
7
  function normalizePathPrefix(pathPrefix) {
8
8
  if (!pathPrefix) return "";
9
- const trimmedPathPrefix = pathPrefix.trim().replace(/^\/+|\/+$/g, "");
9
+ const trimmedPathPrefix = trimTrailingSlashes(pathPrefix.trim().replace(/^\/+/, ""));
10
10
  return trimmedPathPrefix ? `/${trimmedPathPrefix}` : "";
11
11
  }
12
+ /**
13
+ * Removes every trailing `/`.
14
+ *
15
+ * A loop instead of `/\/+$/`: the regex rescans the slash run from each start position, so a
16
+ * request path with a long run of slashes not at the end takes quadratic time.
17
+ */
18
+ function trimTrailingSlashes(value) {
19
+ let end = value.length;
20
+ while (end > 0 && value[end - 1] === "/") end--;
21
+ return value.slice(0, end);
22
+ }
12
23
  function parseUrl(url, baseUrl) {
13
24
  try {
14
25
  return new URL(url, baseUrl ?? "https://shopify.local");
@@ -34,7 +45,7 @@ function isAbsoluteUrl(url) {
34
45
  }
35
46
  function stripTrailingSlash(pathname) {
36
47
  if (pathname === "/") return pathname;
37
- return pathname.replace(/\/+$/, "");
48
+ return trimTrailingSlashes(pathname);
38
49
  }
39
50
  /**
40
51
  * Removes the locale prefix before matching route templates.
@@ -54,5 +65,5 @@ function stripI18nPathPrefix(pathname, pathPrefix) {
54
65
  }
55
66
 
56
67
  //#endregion
57
- export { isAbsoluteUrl, normalizePathPrefix, parseSameOriginUrl, prependPathPrefix, stripI18nPathPrefix, stripTrailingSlash };
68
+ export { isAbsoluteUrl, normalizePathPrefix, parseSameOriginUrl, prependPathPrefix, stripI18nPathPrefix, stripTrailingSlash, trimTrailingSlashes };
58
69
  //# sourceMappingURL=path.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"path.mjs","names":[],"sources":["../../../src/core/standard-routes/path.ts"],"sourcesContent":["export function prependPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n return `${normalizedPathPrefix}/${pathname.replace(/^\\/+/, \"\")}`;\n}\n\nexport function normalizePathPrefix(pathPrefix: string | undefined): string {\n if (!pathPrefix) return \"\";\n\n const trimmedPathPrefix = pathPrefix.trim().replace(/^\\/+|\\/+$/g, \"\");\n return trimmedPathPrefix ? `/${trimmedPathPrefix}` : \"\";\n}\n\nfunction parseUrl(url: string, baseUrl: string | undefined): URL | null {\n try {\n return new URL(url, baseUrl ?? \"https://shopify.local\");\n } catch {\n return null;\n }\n}\n\n/**\n * Parses a URL and rejects absolute URLs that do not share `baseUrl`'s origin.\n *\n * Relative URLs are resolved against `baseUrl` when provided, or against a throwaway local origin\n * when no base is available.\n */\nexport function parseSameOriginUrl(url: string, baseUrl: string | undefined): URL | null {\n const parsedUrl = parseUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const parsedBaseUrl = baseUrl ? parseUrl(baseUrl, undefined) : null;\n if (parsedBaseUrl && parsedUrl.origin !== parsedBaseUrl.origin) return null;\n\n return parsedUrl;\n}\n\nexport function isAbsoluteUrl(url: string): boolean {\n return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(url);\n}\n\nexport function stripTrailingSlash(pathname: string): string {\n if (pathname === \"/\") return pathname;\n return pathname.replace(/\\/+$/, \"\");\n}\n\n/**\n * Removes the locale prefix before matching route templates.\n *\n * `ShopifyScripts` stores `routes.root` with a trailing slash, while server i18n uses\n * `pathPrefix`; both are normalized here so `/fr-ca/products/snowboard` can match the same\n * template as `/products/snowboard`.\n */\nexport function stripI18nPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n const lowerPathname = pathname.toLowerCase();\n const lowerPathPrefix = normalizedPathPrefix.toLowerCase();\n\n if (lowerPathname === lowerPathPrefix) return \"/\";\n if (!lowerPathname.startsWith(`${lowerPathPrefix}/`)) return pathname;\n\n return pathname.slice(normalizedPathPrefix.length) || \"/\";\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB,UAAkB,YAAwC;CAC1F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;AAElC,QAAO,GAAG,qBAAqB,GAAG,SAAS,QAAQ,QAAQ,GAAG;;AAGhE,SAAgB,oBAAoB,YAAwC;AAC1E,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,oBAAoB,WAAW,MAAM,CAAC,QAAQ,cAAc,GAAG;AACrE,QAAO,oBAAoB,IAAI,sBAAsB;;AAGvD,SAAS,SAAS,KAAa,SAAyC;AACtE,KAAI;AACF,SAAO,IAAI,IAAI,KAAK,WAAW,wBAAwB;SACjD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,mBAAmB,KAAa,SAAyC;CACvF,MAAM,YAAY,SAAS,KAAK,QAAQ;AACxC,KAAI,CAAC,UAAW,QAAO;CAEvB,MAAM,gBAAgB,UAAU,SAAS,SAAS,OAAU,GAAG;AAC/D,KAAI,iBAAiB,UAAU,WAAW,cAAc,OAAQ,QAAO;AAEvE,QAAO;;AAGT,SAAgB,cAAc,KAAsB;AAClD,QAAO,4BAA4B,KAAK,IAAI;;AAG9C,SAAgB,mBAAmB,UAA0B;AAC3D,KAAI,aAAa,IAAK,QAAO;AAC7B,QAAO,SAAS,QAAQ,QAAQ,GAAG;;;;;;;;;AAUrC,SAAgB,oBAAoB,UAAkB,YAAwC;CAC5F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;CAElC,MAAM,gBAAgB,SAAS,aAAa;CAC5C,MAAM,kBAAkB,qBAAqB,aAAa;AAE1D,KAAI,kBAAkB,gBAAiB,QAAO;AAC9C,KAAI,CAAC,cAAc,WAAW,GAAG,gBAAgB,GAAG,CAAE,QAAO;AAE7D,QAAO,SAAS,MAAM,qBAAqB,OAAO,IAAI"}
1
+ {"version":3,"file":"path.mjs","names":[],"sources":["../../../src/core/standard-routes/path.ts"],"sourcesContent":["export function prependPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n return `${normalizedPathPrefix}/${pathname.replace(/^\\/+/, \"\")}`;\n}\n\nexport function normalizePathPrefix(pathPrefix: string | undefined): string {\n if (!pathPrefix) return \"\";\n\n const trimmedPathPrefix = trimTrailingSlashes(pathPrefix.trim().replace(/^\\/+/, \"\"));\n return trimmedPathPrefix ? `/${trimmedPathPrefix}` : \"\";\n}\n\n/**\n * Removes every trailing `/`.\n *\n * A loop instead of `/\\/+$/`: the regex rescans the slash run from each start position, so a\n * request path with a long run of slashes not at the end takes quadratic time.\n */\nexport function trimTrailingSlashes(value: string): string {\n let end = value.length;\n while (end > 0 && value[end - 1] === \"/\") end--;\n return value.slice(0, end);\n}\n\nfunction parseUrl(url: string, baseUrl: string | undefined): URL | null {\n try {\n return new URL(url, baseUrl ?? \"https://shopify.local\");\n } catch {\n return null;\n }\n}\n\n/**\n * Parses a URL and rejects absolute URLs that do not share `baseUrl`'s origin.\n *\n * Relative URLs are resolved against `baseUrl` when provided, or against a throwaway local origin\n * when no base is available.\n */\nexport function parseSameOriginUrl(url: string, baseUrl: string | undefined): URL | null {\n const parsedUrl = parseUrl(url, baseUrl);\n if (!parsedUrl) return null;\n\n const parsedBaseUrl = baseUrl ? parseUrl(baseUrl, undefined) : null;\n if (parsedBaseUrl && parsedUrl.origin !== parsedBaseUrl.origin) return null;\n\n return parsedUrl;\n}\n\nexport function isAbsoluteUrl(url: string): boolean {\n return /^[A-Za-z][A-Za-z0-9+.-]*:/.test(url);\n}\n\nexport function stripTrailingSlash(pathname: string): string {\n if (pathname === \"/\") return pathname;\n return trimTrailingSlashes(pathname);\n}\n\n/**\n * Removes the locale prefix before matching route templates.\n *\n * `ShopifyScripts` stores `routes.root` with a trailing slash, while server i18n uses\n * `pathPrefix`; both are normalized here so `/fr-ca/products/snowboard` can match the same\n * template as `/products/snowboard`.\n */\nexport function stripI18nPathPrefix(pathname: string, pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n if (!normalizedPathPrefix) return pathname;\n\n const lowerPathname = pathname.toLowerCase();\n const lowerPathPrefix = normalizedPathPrefix.toLowerCase();\n\n if (lowerPathname === lowerPathPrefix) return \"/\";\n if (!lowerPathname.startsWith(`${lowerPathPrefix}/`)) return pathname;\n\n return pathname.slice(normalizedPathPrefix.length) || \"/\";\n}\n"],"mappings":";AAAA,SAAgB,kBAAkB,UAAkB,YAAwC;CAC1F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;AAElC,QAAO,GAAG,qBAAqB,GAAG,SAAS,QAAQ,QAAQ,GAAG;;AAGhE,SAAgB,oBAAoB,YAAwC;AAC1E,KAAI,CAAC,WAAY,QAAO;CAExB,MAAM,oBAAoB,oBAAoB,WAAW,MAAM,CAAC,QAAQ,QAAQ,GAAG,CAAC;AACpF,QAAO,oBAAoB,IAAI,sBAAsB;;;;;;;;AASvD,SAAgB,oBAAoB,OAAuB;CACzD,IAAI,MAAM,MAAM;AAChB,QAAO,MAAM,KAAK,MAAM,MAAM,OAAO,IAAK;AAC1C,QAAO,MAAM,MAAM,GAAG,IAAI;;AAG5B,SAAS,SAAS,KAAa,SAAyC;AACtE,KAAI;AACF,SAAO,IAAI,IAAI,KAAK,WAAW,wBAAwB;SACjD;AACN,SAAO;;;;;;;;;AAUX,SAAgB,mBAAmB,KAAa,SAAyC;CACvF,MAAM,YAAY,SAAS,KAAK,QAAQ;AACxC,KAAI,CAAC,UAAW,QAAO;CAEvB,MAAM,gBAAgB,UAAU,SAAS,SAAS,OAAU,GAAG;AAC/D,KAAI,iBAAiB,UAAU,WAAW,cAAc,OAAQ,QAAO;AAEvE,QAAO;;AAGT,SAAgB,cAAc,KAAsB;AAClD,QAAO,4BAA4B,KAAK,IAAI;;AAG9C,SAAgB,mBAAmB,UAA0B;AAC3D,KAAI,aAAa,IAAK,QAAO;AAC7B,QAAO,oBAAoB,SAAS;;;;;;;;;AAUtC,SAAgB,oBAAoB,UAAkB,YAAwC;CAC5F,MAAM,uBAAuB,oBAAoB,WAAW;AAC5D,KAAI,CAAC,qBAAsB,QAAO;CAElC,MAAM,gBAAgB,SAAS,aAAa;CAC5C,MAAM,kBAAkB,qBAAqB,aAAa;AAE1D,KAAI,kBAAkB,gBAAiB,QAAO;AAC9C,KAAI,CAAC,cAAc,WAAW,GAAG,gBAAgB,GAAG,CAAE,QAAO;AAE7D,QAAO,SAAS,MAAM,qBAAqB,OAAO,IAAI"}
@@ -90,7 +90,12 @@ type ShopifyStandardRouteMatch<TRoute extends ShopifyStandardRouteName = Shopify
90
90
  /** Shopify's default path for the matched resource, with the locale path prefix applied. */standardPathname: string; /** The decoded handle values from the matched URL. */
91
91
  params: StandardRouteParams; /** The standard route name that the URL matched, or `index` for the home page. */
92
92
  route: TRoute; /** The page template name for the matched route, such as `product` or `list-collections`. */
93
- pageTemplateName: ShopifyPageTemplateName<TRoute>; /** Shopify's default template for the matched route and your app's custom template, which falls back to the default. */
93
+ pageTemplateName: ShopifyPageTemplateName<TRoute>;
94
+ /**
95
+ * Shopify's default template for the matched resource and your app's custom template, which
96
+ * falls back to the default. A collection-scoped product match without a collection handle uses
97
+ * the product template as its standard template.
98
+ */
94
99
  templates: {
95
100
  standard: string;
96
101
  custom: string;
package/dist/core/url.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { trimTrailingSlashes } from "./standard-routes/path.mjs";
2
+
1
3
  //#region src/core/url.ts
2
4
  const SFAPI_RE = /^\/api\/(unstable|2\d{3}-\d{2})\/graphql\.json$/;
3
5
  const SHOPIFY_API_PROXY_PREFIX = "/__shopify";
@@ -53,10 +55,10 @@ function getSameOriginPath(target, origin) {
53
55
  }
54
56
  function normalizeStoreDomain(domain) {
55
57
  if (!domain) throw new Error("Storefront `storeDomain` is required.");
56
- if (domain.startsWith("http://") || domain.startsWith("https://")) return domain.replace(/\/+$/, "");
57
- return `https://${domain}`.replace(/\/+$/, "");
58
+ if (domain.startsWith("http://") || domain.startsWith("https://")) return trimTrailingSlashes(domain);
59
+ return trimTrailingSlashes(`https://${domain}`);
58
60
  }
59
61
 
60
62
  //#endregion
61
- export { AJAX_CART_RE, BUY_PERMALINK_RE, CHECKOUT_RE, CUSTOMER_ACCOUNT_PATHS, MCP_RE, SFAPI_RE, SHOPIFY_API_PROXY_PREFIX, SHOPIFY_API_PROXY_RE, UCP_MCP_RE, UCP_RE, WELL_KNOWN_RE, getSameOriginPath, isHydrogenServerHandoffPath, normalizeStoreDomain };
63
+ export { AJAX_CART_RE, BUY_PERMALINK_RE, CART_PERMALINK_RE, CHECKOUT_RE, CUSTOMER_ACCOUNT_PATHS, MCP_RE, SFAPI_RE, SHOPIFY_API_PROXY_PREFIX, SHOPIFY_API_PROXY_RE, UCP_MCP_RE, UCP_RE, WELL_KNOWN_RE, getSameOriginPath, isHydrogenServerHandoffPath, normalizeStoreDomain };
62
64
  //# sourceMappingURL=url.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"url.mjs","names":[],"sources":["../../src/core/url.ts"],"sourcesContent":["export const SFAPI_RE = /^\\/api\\/(unstable|2\\d{3}-\\d{2})\\/graphql\\.json$/;\nexport const SHOPIFY_API_PROXY_PREFIX = \"/__shopify\";\nexport const SHOPIFY_API_PROXY_RE = /^\\/__shopify(?:\\/|$)/;\nexport const MCP_RE = /^\\/api\\/mcp$/;\nexport const UCP_MCP_RE = /^\\/api\\/ucp\\/mcp$/;\nexport const CHECKOUT_RE = /^\\/checkout$/;\nexport const CART_PERMALINK_RE = /^\\/cart\\/\\d+:\\d+(?:,\\d+:\\d+)*$/;\nconst BUY_ITEM_PAIR = String.raw`(?:[A-Za-z0-9._-]+|~[A-Za-z0-9_-]+):[1-9]\\d*`;\n// Items are required so a storefront's own /buy pages keep routing to the app.\nexport const BUY_PERMALINK_RE = new RegExp(`^/buy/${BUY_ITEM_PAIR}(?:,${BUY_ITEM_PAIR})*$`);\nexport const CUSTOMER_ACCOUNT_PATHS = {\n authorize: \"/account/authorize\",\n login: \"/account/login\",\n logout: \"/account/logout\",\n refresh: \"/account/refresh\",\n} as const;\n\nconst CUSTOMER_ACCOUNT_HANDOFF_PATHS: ReadonlySet<string> = new Set(\n Object.values(CUSTOMER_ACCOUNT_PATHS),\n);\n\n/**\n * Returns whether the pathname conventionally represents a Hydrogen document-level server handoff.\n *\n * Keep this aligned with the routes intercepted before framework routing. API and protocol\n * interceptors are intentionally excluded because they are not browser navigation destinations.\n */\nexport function isHydrogenServerHandoffPath(pathname: string): boolean {\n return (\n CHECKOUT_RE.test(pathname) ||\n CART_PERMALINK_RE.test(pathname) ||\n BUY_PERMALINK_RE.test(pathname) ||\n CUSTOMER_ACCOUNT_HANDOFF_PATHS.has(pathname)\n );\n}\n\n// UCP profiles need JSON validation and caching separate from the other well-known resources.\nexport const UCP_RE = /^\\/\\.well-known\\/ucp$/;\n\n/**\n * Allowlisted `.well-known` resources proxied to the Online Store origin:\n * - `apple-developer-merchantid-domain-association` — Apple Pay domain verification.\n * - `shopify/fec/produce` — Frontend Event Collector ingress. On the Online\n * Store the myshopify.com edge forwards this first-party path to the\n * collector; headless storefronts have no such edge, so Hydrogen proxies it\n * to the same origin (used by WebMCP's Event Refinery client).\n */\nexport const WELL_KNOWN_RE =\n /^\\/\\.well-known\\/(?:apple-developer-merchantid-domain-association|shopify\\/fec\\/produce)$/;\nexport const AJAX_CART_RE =\n /^(?:\\/[a-z]{2}(?:-[a-z]{2})?)?\\/cart(?:\\.(?:js|json)|\\/(?:add|update|change|clear)(?:\\.(?:js|json))?)$/i;\n\n/**\n * Normalizes `target` to a path on `origin` that is safe to use as a redirect location.\n * Returns `undefined` unless `target` is a path starting with `/` or an absolute URL,\n * stays on `origin`, and its normalized pathname does not start with `//`.\n */\nexport function getSameOriginPath(\n target: string | null | undefined,\n origin: string,\n): string | undefined {\n if (!target) return undefined;\n\n try {\n // Parse absolute URLs without a base so scheme-relative forms like `https:evil.example`\n // resolve to their own host, as a browser would, instead of onto `origin`.\n const url = target.startsWith(\"/\") ? new URL(target, origin) : new URL(target);\n if (url.origin !== origin) return undefined;\n const path = `${url.pathname}${url.search}${url.hash}`;\n // The parsed pathname can itself start with `//` (e.g. from `/x/..//evil`),\n // which a redirect would resolve as a protocol-relative URL to another host.\n return path.startsWith(\"//\") ? undefined : path;\n } catch {\n return undefined;\n }\n}\n\nexport function normalizeStoreDomain(domain: string): string {\n if (!domain) {\n throw new Error(\"Storefront `storeDomain` is required.\");\n }\n\n if (domain.startsWith(\"http://\") || domain.startsWith(\"https://\")) {\n return domain.replace(/\\/+$/, \"\");\n }\n return `https://${domain}`.replace(/\\/+$/, \"\");\n}\n"],"mappings":";AAAA,MAAa,WAAW;AACxB,MAAa,2BAA2B;AACxC,MAAa,uBAAuB;AACpC,MAAa,SAAS;AACtB,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,oBAAoB;AACjC,MAAM,gBAAgB,OAAO,GAAG;AAEhC,MAAa,mBAAmB,IAAI,OAAO,SAAS,cAAc,MAAM,cAAc,KAAK;AAC3F,MAAa,yBAAyB;CACpC,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACV;AAED,MAAM,iCAAsD,IAAI,IAC9D,OAAO,OAAO,uBAAuB,CACtC;;;;;;;AAQD,SAAgB,4BAA4B,UAA2B;AACrE,QACE,YAAY,KAAK,SAAS,IAC1B,kBAAkB,KAAK,SAAS,IAChC,iBAAiB,KAAK,SAAS,IAC/B,+BAA+B,IAAI,SAAS;;AAKhD,MAAa,SAAS;;;;;;;;;AAUtB,MAAa,gBACX;AACF,MAAa,eACX;;;;;;AAOF,SAAgB,kBACd,QACA,QACoB;AACpB,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI;EAGF,MAAM,MAAM,OAAO,WAAW,IAAI,GAAG,IAAI,IAAI,QAAQ,OAAO,GAAG,IAAI,IAAI,OAAO;AAC9E,MAAI,IAAI,WAAW,OAAQ,QAAO;EAClC,MAAM,OAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;AAGhD,SAAO,KAAK,WAAW,KAAK,GAAG,SAAY;SACrC;AACN;;;AAIJ,SAAgB,qBAAqB,QAAwB;AAC3D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,wCAAwC;AAG1D,KAAI,OAAO,WAAW,UAAU,IAAI,OAAO,WAAW,WAAW,CAC/D,QAAO,OAAO,QAAQ,QAAQ,GAAG;AAEnC,QAAO,WAAW,SAAS,QAAQ,QAAQ,GAAG"}
1
+ {"version":3,"file":"url.mjs","names":[],"sources":["../../src/core/url.ts"],"sourcesContent":["import { trimTrailingSlashes } from \"./standard-routes/path\";\n\nexport const SFAPI_RE = /^\\/api\\/(unstable|2\\d{3}-\\d{2})\\/graphql\\.json$/;\nexport const SHOPIFY_API_PROXY_PREFIX = \"/__shopify\";\nexport const SHOPIFY_API_PROXY_RE = /^\\/__shopify(?:\\/|$)/;\nexport const MCP_RE = /^\\/api\\/mcp$/;\nexport const UCP_MCP_RE = /^\\/api\\/ucp\\/mcp$/;\nexport const CHECKOUT_RE = /^\\/checkout$/;\nexport const CART_PERMALINK_RE = /^\\/cart\\/\\d+:\\d+(?:,\\d+:\\d+)*$/;\nconst BUY_ITEM_PAIR = String.raw`(?:[A-Za-z0-9._-]+|~[A-Za-z0-9_-]+):[1-9]\\d*`;\n// Items are required so a storefront's own /buy pages keep routing to the app.\nexport const BUY_PERMALINK_RE = new RegExp(`^/buy/${BUY_ITEM_PAIR}(?:,${BUY_ITEM_PAIR})*$`);\nexport const CUSTOMER_ACCOUNT_PATHS = {\n authorize: \"/account/authorize\",\n login: \"/account/login\",\n logout: \"/account/logout\",\n refresh: \"/account/refresh\",\n} as const;\n\nconst CUSTOMER_ACCOUNT_HANDOFF_PATHS: ReadonlySet<string> = new Set(\n Object.values(CUSTOMER_ACCOUNT_PATHS),\n);\n\n/**\n * Returns whether the pathname conventionally represents a Hydrogen document-level server handoff.\n *\n * Keep this aligned with the routes intercepted before framework routing. API and protocol\n * interceptors are intentionally excluded because they are not browser navigation destinations.\n */\nexport function isHydrogenServerHandoffPath(pathname: string): boolean {\n return (\n CHECKOUT_RE.test(pathname) ||\n CART_PERMALINK_RE.test(pathname) ||\n BUY_PERMALINK_RE.test(pathname) ||\n CUSTOMER_ACCOUNT_HANDOFF_PATHS.has(pathname)\n );\n}\n\n// UCP profiles need JSON validation and caching separate from the other well-known resources.\nexport const UCP_RE = /^\\/\\.well-known\\/ucp$/;\n\n/**\n * Allowlisted `.well-known` resources proxied to the Online Store origin:\n * - `apple-developer-merchantid-domain-association` — Apple Pay domain verification.\n * - `shopify/fec/produce` — Frontend Event Collector ingress. On the Online\n * Store the myshopify.com edge forwards this first-party path to the\n * collector; headless storefronts have no such edge, so Hydrogen proxies it\n * to the same origin (used by WebMCP's Event Refinery client).\n */\nexport const WELL_KNOWN_RE =\n /^\\/\\.well-known\\/(?:apple-developer-merchantid-domain-association|shopify\\/fec\\/produce)$/;\nexport const AJAX_CART_RE =\n /^(?:\\/[a-z]{2}(?:-[a-z]{2})?)?\\/cart(?:\\.(?:js|json)|\\/(?:add|update|change|clear)(?:\\.(?:js|json))?)$/i;\n\n/**\n * Normalizes `target` to a path on `origin` that is safe to use as a redirect location.\n * Returns `undefined` unless `target` is a path starting with `/` or an absolute URL,\n * stays on `origin`, and its normalized pathname does not start with `//`.\n */\nexport function getSameOriginPath(\n target: string | null | undefined,\n origin: string,\n): string | undefined {\n if (!target) return undefined;\n\n try {\n // Parse absolute URLs without a base so scheme-relative forms like `https:evil.example`\n // resolve to their own host, as a browser would, instead of onto `origin`.\n const url = target.startsWith(\"/\") ? new URL(target, origin) : new URL(target);\n if (url.origin !== origin) return undefined;\n const path = `${url.pathname}${url.search}${url.hash}`;\n // The parsed pathname can itself start with `//` (e.g. from `/x/..//evil`),\n // which a redirect would resolve as a protocol-relative URL to another host.\n return path.startsWith(\"//\") ? undefined : path;\n } catch {\n return undefined;\n }\n}\n\nexport function normalizeStoreDomain(domain: string): string {\n if (!domain) {\n throw new Error(\"Storefront `storeDomain` is required.\");\n }\n\n if (domain.startsWith(\"http://\") || domain.startsWith(\"https://\")) {\n return trimTrailingSlashes(domain);\n }\n return trimTrailingSlashes(`https://${domain}`);\n}\n"],"mappings":";;;AAEA,MAAa,WAAW;AACxB,MAAa,2BAA2B;AACxC,MAAa,uBAAuB;AACpC,MAAa,SAAS;AACtB,MAAa,aAAa;AAC1B,MAAa,cAAc;AAC3B,MAAa,oBAAoB;AACjC,MAAM,gBAAgB,OAAO,GAAG;AAEhC,MAAa,mBAAmB,IAAI,OAAO,SAAS,cAAc,MAAM,cAAc,KAAK;AAC3F,MAAa,yBAAyB;CACpC,WAAW;CACX,OAAO;CACP,QAAQ;CACR,SAAS;CACV;AAED,MAAM,iCAAsD,IAAI,IAC9D,OAAO,OAAO,uBAAuB,CACtC;;;;;;;AAQD,SAAgB,4BAA4B,UAA2B;AACrE,QACE,YAAY,KAAK,SAAS,IAC1B,kBAAkB,KAAK,SAAS,IAChC,iBAAiB,KAAK,SAAS,IAC/B,+BAA+B,IAAI,SAAS;;AAKhD,MAAa,SAAS;;;;;;;;;AAUtB,MAAa,gBACX;AACF,MAAa,eACX;;;;;;AAOF,SAAgB,kBACd,QACA,QACoB;AACpB,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI;EAGF,MAAM,MAAM,OAAO,WAAW,IAAI,GAAG,IAAI,IAAI,QAAQ,OAAO,GAAG,IAAI,IAAI,OAAO;AAC9E,MAAI,IAAI,WAAW,OAAQ,QAAO;EAClC,MAAM,OAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;AAGhD,SAAO,KAAK,WAAW,KAAK,GAAG,SAAY;SACrC;AACN;;;AAIJ,SAAgB,qBAAqB,QAAwB;AAC3D,KAAI,CAAC,OACH,OAAM,IAAI,MAAM,wCAAwC;AAG1D,KAAI,OAAO,WAAW,UAAU,IAAI,OAAO,WAAW,WAAW,CAC/D,QAAO,oBAAoB,OAAO;AAEpC,QAAO,oBAAoB,WAAW,SAAS"}
@@ -1,6 +1,8 @@
1
1
  import { ShopifyRequestContext } from "../core/request-context.mjs";
2
+ import { InferVariableNamesByEnumValue, InferVariableNamesDeclaredAs } from "../graphql/type-resolver.mjs";
2
3
  import { GraphQLFormattedError } from "../client/types.mjs";
3
- import { AnyCustomerAccountDocument, CustomerAccountDocument } from "./graphql.mjs";
4
+ import { introspection } from "../graphql/generated/customer-account-graphql-env.mjs";
5
+ import { AnyCustomerAccountDocument, CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES, CustomerAccountDocument, SourceOf } from "./graphql.mjs";
4
6
 
5
7
  //#region src/customer-account/client.d.ts
6
8
  /**
@@ -17,7 +19,7 @@ type CreateCustomerAccountClientOptions = {
17
19
  *
18
20
  * The context's URL must use HTTPS, or creating the client throws. Local `http://` URLs on localhost, 127.0.0.1, and ::1 also work for development.
19
21
  *
20
- * The client fills `$language` from the context's language and stops requests when the context's signal aborts.
22
+ * The client fills `$language: LanguageCode` from the context's language and stops requests when the context's signal aborts.
21
23
  */
22
24
  requestContext: ShopifyRequestContext; /** Custom fetch implementation. Defaults to the global fetch. */
23
25
  fetch?: typeof globalThis.fetch;
@@ -32,7 +34,7 @@ type CreateCustomerAccountClientOptions = {
32
34
  type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {
33
35
  /** The customer's access token, such as one from the customer session's `getOrRefreshAccessToken()` method. */accessToken: string;
34
36
  /**
35
- * The document's variables. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.
37
+ * The document's variables. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.
36
38
  */
37
39
  variables?: Variables;
38
40
  /**
@@ -43,11 +45,13 @@ type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {
43
45
  type ResultOfDoc<Doc> = Doc extends CustomerAccountDocument<infer Result, never, string> ? Result : never;
44
46
  /** The variables that a Customer Account document declares. */
45
47
  type VariablesOfDoc<Doc> = Doc extends CustomerAccountDocument<unknown, infer Variables, string> ? Variables : never;
46
- /** An optional `language` variable for a document that declares `$language`. The client fills a missing value from the request context. */
47
- type OptionalAutoVariables<Variables> = "language" extends keyof Variables ? {
48
- language?: Variables["language"];
49
- } : {};
50
- type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, "language"> & OptionalAutoVariables<VariablesOfDoc<Doc>>;
48
+ type I18nVariableTypes = typeof CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES;
49
+ type I18nVariableNamesByValue<Variables> = InferVariableNamesByEnumValue<Variables, I18nVariableTypes, introspection>;
50
+ /** The variables the client fills when omitted: those declared with the expected type, such as `$language: LanguageCode`. */
51
+ type I18nVariableNamesOfDoc<Doc> = string extends SourceOf<Doc> ? I18nVariableNamesByValue<VariablesOfDoc<Doc>> : InferVariableNamesDeclaredAs<SourceOf<Doc>, I18nVariableTypes>;
52
+ /** Optional versions of the variables that the client fills from the request context when you omit them. */
53
+ type OptionalI18nVariables<Variables, Names> = { [K in keyof Variables & Names]?: Variables[K] };
54
+ type UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>> & OptionalI18nVariables<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>>;
51
55
  type HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;
52
56
  /**
53
57
  * Result of a Customer Account API request. Check `errors` to tell the outcomes apart.
@@ -66,7 +70,7 @@ type CustomerAccountGraphqlResult<Result = unknown> = {
66
70
  /**
67
71
  * The options argument for a Customer Account API request.
68
72
  *
69
- * Pass `variables` when the document declares a required variable other than `language`. TypeScript reports an error when a required variable is missing.
73
+ * Pass `variables` when the document declares a required variable other than `$language: LanguageCode`. TypeScript reports an error when a required variable is missing.
70
74
  */
71
75
  type CustomerAccountGqlRestParam<Doc extends AnyCustomerAccountDocument> = HasNoRequiredKeys<UserVariables<Doc>> extends true ? [options: CustomerAccountGraphqlOptions<UserVariables<Doc>>] : [options: CustomerAccountGraphqlOptions<UserVariables<Doc>> & {
72
76
  variables: UserVariables<Doc>;
@@ -79,7 +83,7 @@ type CustomerAccountClient = {
79
83
  /**
80
84
  * Sends a Customer Account API query or mutation with the customer's access token, and returns the data, any GraphQL errors, and the response headers. Pass a document from the Customer Account `gql` function.
81
85
  *
82
- * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.
86
+ * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.
83
87
  *
84
88
  * The method throws a `TypeError` for a document from any other `gql` function, including the Storefront API `gql` function, and for variables that aren't an object. When a signal aborts, the method throws the signal's reason. A missing or malformed access token throws `CustomerAccountAuthenticationError`, a timeout throws `CustomerAccountTimeoutError`, and other request failures throw `CustomerAccountApiError`.
85
89
  *
@@ -1,4 +1,4 @@
1
- import { CUSTOMER_ACCOUNT_API_VERSION, DEFAULT_TIMEOUT_IN_MS } from "../core/constants.mjs";
1
+ import { CUSTOMER_ACCOUNT_API_VERSION, DEFAULT_TIMEOUT_IN_MS, HYDROGEN_USER_AGENT } from "../core/constants.mjs";
2
2
  import { CustomerAccountApiError, CustomerAccountAuthenticationError, CustomerAccountTimeoutError } from "./errors.mjs";
3
3
  import { isObjectRecord } from "../core/utils/record.mjs";
4
4
  import { assertCustomerAccountDocument } from "./graphql.mjs";
@@ -15,7 +15,6 @@ const LOCAL_ORIGIN_HOSTS = new Set([
15
15
  "::1",
16
16
  "[::1]"
17
17
  ]);
18
- const USER_AGENT = `Hydrogen 2026.10.2`;
19
18
  const CUSTOMER_ACCOUNT_GRAPHQL_PERSONALIZATION_REASON = "customer-account-graphql";
20
19
  /**
21
20
  * Creates a client that sends Customer Account API requests from your server. Create the client with the current request's context.
@@ -62,7 +61,7 @@ function createCustomerAccountClient({ shopId, customerApiVersion = CUSTOMER_ACC
62
61
  externalSignals.push(timeoutSignal);
63
62
  const signal = AbortSignal.any(externalSignals);
64
63
  try {
65
- const variables = getVariables(document, getOptionalVariables(options.variables), requestContext.i18n.language);
64
+ const variables = getVariables(document, getOptionalVariables(options.variables), requestContext.locale.language);
66
65
  return await readCustomerAccountGraphqlResponse(await fetchCustomerAccountGraphql({
67
66
  fetch: resolvedFetch,
68
67
  apiUrl,
@@ -91,7 +90,7 @@ async function fetchCustomerAccountGraphql({ fetch, apiUrl, accessToken, origin,
91
90
  Authorization: accessToken,
92
91
  "Content-Type": "application/json",
93
92
  Origin: origin,
94
- "User-Agent": USER_AGENT
93
+ "User-Agent": HYDROGEN_USER_AGENT
95
94
  }),
96
95
  body: JSON.stringify({
97
96
  query,
@@ -181,7 +180,7 @@ function withAbort(promise, signal) {
181
180
  });
182
181
  }
183
182
  function getVariables(document, variables, language) {
184
- if (!document.variableNames.has("language")) return variables;
183
+ if (!document.i18nVariableNames.has("language")) return variables;
185
184
  if ("language" in variables) return variables;
186
185
  return {
187
186
  ...variables,
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":[],"sources":["../../src/customer-account/client.ts"],"sourcesContent":["import type { GraphQLFormattedError } from \"../client/types\";\nimport { CUSTOMER_ACCOUNT_API_VERSION, DEFAULT_TIMEOUT_IN_MS } from \"../core/constants\";\nimport type { ShopifyRequestContext } from \"../core/request-context\";\nimport { isObjectRecord } from \"../core/utils/record\";\nimport {\n CustomerAccountApiError,\n CustomerAccountAuthenticationError,\n CustomerAccountTimeoutError,\n} from \"./errors\";\nimport {\n assertCustomerAccountDocument,\n type AnyCustomerAccountDocument,\n type CustomerAccountDocument,\n} from \"./graphql\";\n\nconst SHOP_ID_RE = /^\\d+$/;\nconst CUSTOMER_API_VERSION_RE = /^\\d{4}-\\d{2}$/;\nconst MAX_ASCII_CONTROL_CODE_POINT = 31;\nconst ASCII_DELETE_CODE_POINT = 127;\nconst MAX_SET_TIMEOUT_IN_MS = 2_147_483_647;\nconst LOCAL_ORIGIN_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"::1\", \"[::1]\"]);\nconst USER_AGENT = `Hydrogen ${__HYDROGEN_VERSION__}`;\nconst CUSTOMER_ACCOUNT_GRAPHQL_PERSONALIZATION_REASON = \"customer-account-graphql\";\n\n/** A Customer Account API access token, or `null` or `undefined` when the customer has none. */\ntype AccessToken = string | null | undefined;\ntype FetchCustomerAccountGraphqlParams = {\n fetch: typeof globalThis.fetch;\n apiUrl: string;\n accessToken: string;\n origin: string;\n query: string;\n variables: Record<string, unknown>;\n signal: AbortSignal;\n timeoutSignal: AbortSignal;\n timeoutInMs: number;\n};\n\n/**\n * Options for creating a Customer Account API client.\n */\nexport type CreateCustomerAccountClientOptions = {\n /** Numeric Shopify shop ID as a string of digits, such as `12345`. */\n shopId: string;\n /**\n * Customer Account API version in `YYYY-MM` format. Defaults to `2026-10`.\n */\n customerApiVersion?: string;\n /**\n * The context for the current request, from `createShopifyRequestContext`.\n *\n * The context's URL must use HTTPS, or creating the client throws. Local `http://` URLs on localhost, 127.0.0.1, and ::1 also work for development.\n *\n * The client fills `$language` from the context's language and stops requests when the context's signal aborts.\n */\n requestContext: ShopifyRequestContext;\n /** Custom fetch implementation. Defaults to the global fetch. */\n fetch?: typeof globalThis.fetch;\n /**\n * Timeout for each request in milliseconds. Must be a positive integer no greater than 2,147,483,647. Defaults to `30000`.\n */\n defaultTimeoutInMs?: number;\n};\n\n/**\n * Options for a single Customer Account API request.\n */\nexport type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {\n /** The customer's access token, such as one from the customer session's `getOrRefreshAccessToken()` method. */\n accessToken: string;\n /**\n * The document's variables. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.\n */\n variables?: Variables;\n /**\n * Stops this request when the signal aborts. The request also stops when the request context's signal aborts or the timeout passes.\n */\n signal?: AbortSignal;\n};\n\ntype ResultOfDoc<Doc> =\n Doc extends CustomerAccountDocument<infer Result, never, string> ? Result : never;\n/** The variables that a Customer Account document declares. */\ntype VariablesOfDoc<Doc> =\n Doc extends CustomerAccountDocument<unknown, infer Variables, string> ? Variables : never;\n/** An optional `language` variable for a document that declares `$language`. The client fills a missing value from the request context. */\ntype OptionalAutoVariables<Variables> = \"language\" extends keyof Variables\n ? { language?: Variables[\"language\"] }\n : {};\ntype UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, \"language\"> &\n OptionalAutoVariables<VariablesOfDoc<Doc>>;\ntype HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;\n\n/**\n * Result of a Customer Account API request. Check `errors` to tell the outcomes apart.\n *\n * On success, `data` holds the result and `errors` is `undefined`. When the response has GraphQL errors, `errors` holds them and `data` can be `null`. Every result includes the raw response headers.\n */\nexport type CustomerAccountGraphqlResult<Result = unknown> =\n | { data: Result; errors?: undefined; headers: Headers }\n | { data: Result | null; errors: GraphQLFormattedError[]; headers: Headers };\n\n/**\n * The options argument for a Customer Account API request.\n *\n * Pass `variables` when the document declares a required variable other than `language`. TypeScript reports an error when a required variable is missing.\n */\nexport type CustomerAccountGqlRestParam<Doc extends AnyCustomerAccountDocument> =\n HasNoRequiredKeys<UserVariables<Doc>> extends true\n ? [options: CustomerAccountGraphqlOptions<UserVariables<Doc>>]\n : [\n options: CustomerAccountGraphqlOptions<UserVariables<Doc>> & {\n variables: UserVariables<Doc>;\n },\n ];\n\n/**\n * A client that sends Customer Account API requests from your server for the current request.\n */\nexport type CustomerAccountClient = {\n /** The GraphQL endpoint, `https://shopify.com/{shopId}/account/customer/api/{version}/graphql`. */\n readonly apiUrl: string;\n /**\n * Sends a Customer Account API query or mutation with the customer's access token, and returns the data, any GraphQL errors, and the response headers. Pass a document from the Customer Account `gql` function.\n *\n * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language` and you omit it, the client fills the variable from the request context's language.\n *\n * The method throws a `TypeError` for a document from any other `gql` function, including the Storefront API `gql` function, and for variables that aren't an object. When a signal aborts, the method throws the signal's reason. A missing or malformed access token throws `CustomerAccountAuthenticationError`, a timeout throws `CustomerAccountTimeoutError`, and other request failures throw `CustomerAccountApiError`.\n *\n * @throws {TypeError} When another gql function created the document, or when the variables aren't an object.\n * @throws {CustomerAccountAuthenticationError} When the options object is missing or the access token fails validation.\n * @throws {CustomerAccountTimeoutError} When the request exceeds the client's timeout.\n * @throws {CustomerAccountApiError} On a non-OK HTTP status, unparseable JSON, a response without data, or a network failure.\n *\n * @example\n * ```ts\n * const result = await client.graphql(\n * gql(`query { customer { firstName lastName } }`),\n * { accessToken },\n * );\n *\n * if (result.errors) {\n * console.error(result.errors);\n * } else {\n * console.log(result.data.customer.firstName);\n * }\n * ```\n */\n graphql: <const Doc extends AnyCustomerAccountDocument>(\n document: Doc,\n ...options: CustomerAccountGqlRestParam<Doc>\n ) => Promise<CustomerAccountGraphqlResult<ResultOfDoc<Doc>>>;\n};\n\n/**\n * Creates a client that sends Customer Account API requests from your server. Create the client with the current request's context.\n *\n * The function throws when the shop ID, API version, or timeout is invalid, when the request context has no HTTPS URL, when no fetch implementation is available, and when the function runs in a browser.\n *\n * @example\n * ```ts\n * import { createCustomerAccountClient, gql } from \"@shopify/hydrogen/customer-account\";\n *\n * const customerAccount = createCustomerAccountClient({\n * shopId: \"12345\",\n * requestContext,\n * });\n *\n * const { data } = await customerAccount.graphql(\n * gql(`query { customer { firstName } }`),\n * { accessToken },\n * );\n * ```\n *\n * @param options - The shop ID, the API version, the request context, a custom fetch, and the request timeout.\n * @returns A client with the GraphQL endpoint URL and a `graphql()` method for Customer Account API requests.\n * @throws {Error} When called in a browser, when the shop ID, API version, or timeout is invalid, when no fetch is available, or when the request context URL is missing or not HTTPS.\n * @publicDocs\n */\nexport function createCustomerAccountClient({\n shopId,\n customerApiVersion = CUSTOMER_ACCOUNT_API_VERSION,\n requestContext,\n fetch: customFetch,\n defaultTimeoutInMs = DEFAULT_TIMEOUT_IN_MS,\n}: CreateCustomerAccountClientOptions): CustomerAccountClient {\n if (typeof document !== \"undefined\") {\n throw new Error(\n \"Customer Account API tokens cannot be used in a browser context. Use this client from server or edge routes only.\",\n );\n }\n\n validateShopId(shopId);\n validateCustomerApiVersion(customerApiVersion);\n validateTimeout(defaultTimeoutInMs);\n\n const resolvedFetch = customFetch ?? globalThis.fetch;\n if (typeof resolvedFetch !== \"function\") {\n throw new Error(\n \"No fetch function available. Pass a fetch option or ensure globalThis.fetch exists.\",\n );\n }\n\n const origin = getOrigin(requestContext.url);\n const apiUrl = `https://shopify.com/${shopId}/account/customer/api/${customerApiVersion}/graphql`;\n\n async function graphql<const Doc extends AnyCustomerAccountDocument>(\n document: Doc,\n ...rest: CustomerAccountGqlRestParam<Doc>\n ): Promise<CustomerAccountGraphqlResult<ResultOfDoc<Doc>>>;\n async function graphql(\n document: AnyCustomerAccountDocument,\n ...rest: [options?: CustomerAccountGraphqlOptions<unknown>]\n ): Promise<CustomerAccountGraphqlResult<unknown>> {\n assertCustomerAccountDocument(document);\n const options = validateGraphqlOptions(rest[0]);\n requestContext.markResponseAsPersonalized(CUSTOMER_ACCOUNT_GRAPHQL_PERSONALIZATION_REASON);\n const accessToken = validateAccessToken(options.accessToken);\n const externalSignals = [requestContext.signal, options.signal].filter(\n (signal): signal is AbortSignal => Boolean(signal),\n );\n throwIfAlreadyAborted(externalSignals);\n\n const { signal: timeoutSignal, cleanup: cleanupTimeout } =\n createCustomerAccountTimeoutSignal(defaultTimeoutInMs);\n externalSignals.push(timeoutSignal);\n const signal = AbortSignal.any(externalSignals);\n\n try {\n const variables = getVariables(\n document,\n getOptionalVariables(options.variables),\n requestContext.i18n.language,\n );\n const response = await fetchCustomerAccountGraphql({\n fetch: resolvedFetch,\n apiUrl,\n accessToken,\n origin,\n query: document.source,\n variables,\n signal,\n timeoutSignal,\n timeoutInMs: defaultTimeoutInMs,\n });\n\n return await readCustomerAccountGraphqlResponse(\n response,\n signal,\n timeoutSignal,\n defaultTimeoutInMs,\n );\n } finally {\n cleanupTimeout();\n }\n }\n\n return { apiUrl, graphql };\n}\n\nasync function fetchCustomerAccountGraphql({\n fetch,\n apiUrl,\n accessToken,\n origin,\n query,\n variables,\n signal,\n timeoutSignal,\n timeoutInMs,\n}: FetchCustomerAccountGraphqlParams): Promise<Response> {\n try {\n return await withAbort(\n fetch(apiUrl, {\n method: \"POST\",\n headers: new Headers({\n Authorization: accessToken,\n \"Content-Type\": \"application/json\",\n Origin: origin,\n \"User-Agent\": USER_AGENT,\n }),\n body: JSON.stringify({ query, variables }),\n cache: \"no-store\",\n redirect: \"manual\",\n signal,\n }),\n signal,\n );\n } catch (cause) {\n throwIfCustomerAccountSignalAborted(signal, timeoutSignal, timeoutInMs);\n if (isAbortError(cause)) throw cause;\n throw new CustomerAccountApiError(\"Customer Account API request failed\", { cause });\n }\n}\n\nasync function readCustomerAccountGraphqlResponse(\n response: Response,\n signal: AbortSignal,\n timeoutSignal: AbortSignal,\n timeoutInMs: number,\n): Promise<CustomerAccountGraphqlResult<unknown>> {\n const requestId = response.headers.get(\"x-request-id\") ?? undefined;\n if (!response.ok) {\n cancelResponseBody(response);\n throw new CustomerAccountApiError(`Customer Account API responded with ${response.status}`, {\n status: response.status,\n requestId,\n retryAfter: response.headers.get(\"retry-after\") ?? undefined,\n });\n }\n\n let body: { data?: unknown; errors?: GraphQLFormattedError[] };\n try {\n body = parseGraphqlResponse(await withAbort(response.json(), signal));\n } catch (cause) {\n cancelResponseBody(response);\n\n throwIfCustomerAccountSignalAborted(signal, timeoutSignal, timeoutInMs);\n if (isAbortError(cause)) throw cause;\n throw new CustomerAccountApiError(\"Failed to parse Customer Account API response as JSON\", {\n status: response.status,\n requestId,\n cause,\n });\n }\n\n if (body.errors) {\n return { data: body.data ?? null, errors: body.errors, headers: response.headers };\n }\n\n if (body.data == null) {\n throw new CustomerAccountApiError(\"Customer Account API response did not include data\", {\n status: response.status,\n requestId,\n });\n }\n\n return { data: body.data, headers: response.headers };\n}\n\nfunction cancelResponseBody(response: Response): void {\n try {\n void response.body?.cancel().catch(() => undefined);\n } catch {}\n}\n\nfunction validateTimeout(timeoutInMs: number): void {\n if (\n !Number.isSafeInteger(timeoutInMs) ||\n timeoutInMs <= 0 ||\n timeoutInMs > MAX_SET_TIMEOUT_IN_MS\n ) {\n throw new Error(\n `defaultTimeoutInMs must be a positive safe integer no greater than ${MAX_SET_TIMEOUT_IN_MS}`,\n );\n }\n}\n\nfunction createCustomerAccountTimeoutSignal(timeoutInMs: number): {\n signal: AbortSignal;\n cleanup: () => void;\n} {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => {\n controller.abort(new CustomerAccountTimeoutError(timeoutInMs));\n }, timeoutInMs);\n\n return { signal: controller.signal, cleanup: () => clearTimeout(timeoutId) };\n}\n\nfunction withAbort<T>(promise: T | Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n if (!signal) return Promise.resolve(promise);\n if (signal.aborted) {\n return Promise.reject(\n signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\"),\n );\n }\n\n return new Promise<T>((resolve, reject) => {\n const abort = () => {\n signal.removeEventListener(\"abort\", abort);\n const reason =\n signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n reject(reason);\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n Promise.resolve(promise).then(\n (value) => {\n signal.removeEventListener(\"abort\", abort);\n resolve(value);\n },\n (error) => {\n signal.removeEventListener(\"abort\", abort);\n reject(error);\n },\n );\n });\n}\n\nfunction getVariables(\n document: { variableNames: ReadonlySet<string> },\n variables: Record<string, unknown>,\n language: ShopifyRequestContext[\"i18n\"][\"language\"],\n): Record<string, unknown> {\n if (!document.variableNames.has(\"language\")) return variables;\n if (\"language\" in variables) return variables;\n return { ...variables, language };\n}\n\nfunction throwIfAlreadyAborted(signals: AbortSignal[]): void {\n const abortedSignal = signals.find((signal) => signal.aborted);\n if (!abortedSignal) return;\n throw abortedSignal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n}\n\nfunction throwIfCustomerAccountSignalAborted(\n signal: AbortSignal,\n timeoutSignal: AbortSignal,\n timeoutInMs: number,\n): void {\n if (!signal.aborted) return;\n if (timeoutSignal.aborted && signal.reason === timeoutSignal.reason) {\n const reason = timeoutSignal.reason;\n throw reason instanceof CustomerAccountTimeoutError\n ? reason\n : new CustomerAccountTimeoutError(timeoutInMs);\n }\n throw signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n}\n\nfunction isAbortError(cause: unknown): cause is DOMException {\n return cause instanceof DOMException && cause.name === \"AbortError\";\n}\n\nfunction parseGraphqlResponse(json: unknown): {\n data?: unknown;\n errors?: GraphQLFormattedError[];\n} {\n if (!isObjectRecord(json)) {\n throw new Error(\"Customer Account API returned unexpected JSON type\");\n }\n\n if (!(\"data\" in json) && !(\"errors\" in json)) {\n throw new Error(\"Customer Account API response must include data or errors\");\n }\n const errors = json.errors;\n if (errors !== undefined && !isGraphqlErrorArray(errors)) {\n throw new Error(\"Customer Account API returned invalid GraphQL errors\");\n }\n return { data: json.data, errors };\n}\n\nfunction isGraphqlErrorArray(value: unknown): value is GraphQLFormattedError[] {\n if (!Array.isArray(value)) return false;\n return value.every((error) => {\n return typeof error === \"object\" && error !== null && typeof error.message === \"string\";\n });\n}\n\nfunction validateShopId(shopId: string): void {\n if (!SHOP_ID_RE.test(shopId)) {\n throw new Error(\"shopId must be a numeric Shopify shop ID string\");\n }\n}\n\nfunction validateCustomerApiVersion(customerApiVersion: string): void {\n if (!CUSTOMER_API_VERSION_RE.test(customerApiVersion)) {\n throw new Error(\"customerApiVersion must use YYYY-MM format\");\n }\n}\n\nfunction validateAccessToken(accessToken: AccessToken): string {\n if (\n typeof accessToken !== \"string\" ||\n accessToken === \"\" ||\n accessToken.trim() !== accessToken ||\n hasAsciiControlCharacter(accessToken)\n ) {\n throw new CustomerAccountAuthenticationError();\n }\n return accessToken;\n}\n\nfunction validateGraphqlOptions(\n options: CustomerAccountGraphqlOptions<unknown> | undefined,\n): CustomerAccountGraphqlOptions<unknown> {\n if (typeof options !== \"object\" || options === null) {\n throw new CustomerAccountAuthenticationError();\n }\n return options;\n}\n\nfunction getOptionalVariables(variables: unknown): Record<string, unknown> {\n if (variables === undefined) return {};\n if (!isObjectRecord(variables)) {\n throw new TypeError(\"Customer Account API variables must be an object\");\n }\n return variables;\n}\n\nfunction hasAsciiControlCharacter(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n const codePoint = value.charCodeAt(index);\n if (codePoint <= MAX_ASCII_CONTROL_CODE_POINT || codePoint === ASCII_DELETE_CODE_POINT) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Customer Account API requires an HTTPS Origin, but local dev frameworks often\n * receive `http://localhost` requests. Keep that local-only exception without\n * weakening origin validation for non-local requests.\n */\nfunction getOrigin(requestUrl: string | undefined): string {\n if (!requestUrl) {\n throw new Error(\"requestContext.url is required for Customer Account API requests\");\n }\n\n const url = new URL(requestUrl);\n if (url.protocol === \"https:\") return url.origin;\n if (url.protocol === \"http:\" && LOCAL_ORIGIN_HOSTS.has(url.hostname)) {\n return `https://${url.host}`;\n }\n throw new Error(`Customer Account API origin must use H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AkC;AAC7D,KACE,OAAO,gBAAgB,YACvB,gBAAgB,MAChB,YAAY,MAAM,KAAK,eACvB,yBAAyB,YAAY,CAErC,OAAM,IAAI,oCAAoC;AAEhD,QAAO;;AAGT,SAAS,uBACP,SACwC;AACxC,KAAI,OAAO,YAAY,YAAY,YAAY,KAC7C,OAAM,IAAI,oCAAoC;AAEhD,QAAO;;AAGT,SAAS,qBAAqB,WAA6C;AACzE,KAAI,cAAc,OAAW,QAAO,EAAE;AACtC,KAAI,CAAC,eAAe,UAAU,CAC5B,OAAM,IAAI,UAAU,mDAAmD;AAEzE,QAAO;;AAGT,SAAS,yBAAyB,OAAwB;AACxD,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,YAAY,MAAM,WAAW,MAAM;AACzC,MAAI,aAAa,gCAAgC,cAAc,wBAC7D,QAAO;;AAGX,QAAO;;;;;;;AAQT,SAAS,UAAU,YAAwC;AACzD,KAAI,CAAC,WACH,OAAM,IAAI,MAAM,mEAAmE;CAGrF,MAAM,MAAM,IAAI,IAAI,WAAW;AAC/B,KAAI,IAAI,aAAa,SAAU,QAAO,IAAI;AAC1C,KAAI,IAAI,aAAa,WAAW,mBAAmB,IAAI,IAAI,SAAS,CAClE,QAAO,WAAW,IAAI;AAExB,OAAM,IAAI,MAAM,yDAAyD,aAAa"}
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../src/customer-account/client.ts"],"sourcesContent":["import type { GraphQLFormattedError } from \"../client/types\";\nimport {\n CUSTOMER_ACCOUNT_API_VERSION,\n DEFAULT_TIMEOUT_IN_MS,\n HYDROGEN_USER_AGENT,\n} from \"../core/constants\";\nimport type { ShopifyRequestContext } from \"../core/request-context\";\nimport { isObjectRecord } from \"../core/utils/record\";\nimport type { introspection } from \"../graphql/generated/customer-account-graphql-env\";\nimport type {\n InferVariableNamesByEnumValue,\n InferVariableNamesDeclaredAs,\n} from \"../graphql/type-resolver\";\nimport {\n CustomerAccountApiError,\n CustomerAccountAuthenticationError,\n CustomerAccountTimeoutError,\n} from \"./errors\";\nimport {\n assertCustomerAccountDocument,\n type AnyCustomerAccountDocument,\n type CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES,\n type CustomerAccountDocument,\n type SourceOf,\n} from \"./graphql\";\n\nconst SHOP_ID_RE = /^\\d+$/;\nconst CUSTOMER_API_VERSION_RE = /^\\d{4}-\\d{2}$/;\nconst MAX_ASCII_CONTROL_CODE_POINT = 31;\nconst ASCII_DELETE_CODE_POINT = 127;\nconst MAX_SET_TIMEOUT_IN_MS = 2_147_483_647;\nconst LOCAL_ORIGIN_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"::1\", \"[::1]\"]);\nconst CUSTOMER_ACCOUNT_GRAPHQL_PERSONALIZATION_REASON = \"customer-account-graphql\";\n\n/** A Customer Account API access token, or `null` or `undefined` when the customer has none. */\ntype AccessToken = string | null | undefined;\ntype FetchCustomerAccountGraphqlParams = {\n fetch: typeof globalThis.fetch;\n apiUrl: string;\n accessToken: string;\n origin: string;\n query: string;\n variables: Record<string, unknown>;\n signal: AbortSignal;\n timeoutSignal: AbortSignal;\n timeoutInMs: number;\n};\n\n/**\n * Options for creating a Customer Account API client.\n */\nexport type CreateCustomerAccountClientOptions = {\n /** Numeric Shopify shop ID as a string of digits, such as `12345`. */\n shopId: string;\n /**\n * Customer Account API version in `YYYY-MM` format. Defaults to `2026-10`.\n */\n customerApiVersion?: string;\n /**\n * The context for the current request, from `createShopifyRequestContext`.\n *\n * The context's URL must use HTTPS, or creating the client throws. Local `http://` URLs on localhost, 127.0.0.1, and ::1 also work for development.\n *\n * The client fills `$language: LanguageCode` from the context's language and stops requests when the context's signal aborts.\n */\n requestContext: ShopifyRequestContext;\n /** Custom fetch implementation. Defaults to the global fetch. */\n fetch?: typeof globalThis.fetch;\n /**\n * Timeout for each request in milliseconds. Must be a positive integer no greater than 2,147,483,647. Defaults to `30000`.\n */\n defaultTimeoutInMs?: number;\n};\n\n/**\n * Options for a single Customer Account API request.\n */\nexport type CustomerAccountGraphqlOptions<Variables = Record<string, unknown>> = {\n /** The customer's access token, such as one from the customer session's `getOrRefreshAccessToken()` method. */\n accessToken: string;\n /**\n * The document's variables. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.\n */\n variables?: Variables;\n /**\n * Stops this request when the signal aborts. The request also stops when the request context's signal aborts or the timeout passes.\n */\n signal?: AbortSignal;\n};\n\ntype ResultOfDoc<Doc> =\n Doc extends CustomerAccountDocument<infer Result, never, string> ? Result : never;\n/** The variables that a Customer Account document declares. */\ntype VariablesOfDoc<Doc> =\n Doc extends CustomerAccountDocument<unknown, infer Variables, string> ? Variables : never;\ntype I18nVariableTypes = typeof CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES;\ntype I18nVariableNamesByValue<Variables> = InferVariableNamesByEnumValue<\n Variables,\n I18nVariableTypes,\n introspection\n>;\n/** The variables the client fills when omitted: those declared with the expected type, such as `$language: LanguageCode`. */\ntype I18nVariableNamesOfDoc<Doc> =\n string extends SourceOf<Doc>\n ? I18nVariableNamesByValue<VariablesOfDoc<Doc>>\n : InferVariableNamesDeclaredAs<SourceOf<Doc>, I18nVariableTypes>;\n/** Optional versions of the variables that the client fills from the request context when you omit them. */\ntype OptionalI18nVariables<Variables, Names> = {\n [K in keyof Variables & Names]?: Variables[K];\n};\ntype UserVariables<Doc> = Omit<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>> &\n OptionalI18nVariables<VariablesOfDoc<Doc>, I18nVariableNamesOfDoc<Doc>>;\ntype HasNoRequiredKeys<T> = Record<string, never> extends T ? true : false;\n\n/**\n * Result of a Customer Account API request. Check `errors` to tell the outcomes apart.\n *\n * On success, `data` holds the result and `errors` is `undefined`. When the response has GraphQL errors, `errors` holds them and `data` can be `null`. Every result includes the raw response headers.\n */\nexport type CustomerAccountGraphqlResult<Result = unknown> =\n | { data: Result; errors?: undefined; headers: Headers }\n | { data: Result | null; errors: GraphQLFormattedError[]; headers: Headers };\n\n/**\n * The options argument for a Customer Account API request.\n *\n * Pass `variables` when the document declares a required variable other than `$language: LanguageCode`. TypeScript reports an error when a required variable is missing.\n */\nexport type CustomerAccountGqlRestParam<Doc extends AnyCustomerAccountDocument> =\n HasNoRequiredKeys<UserVariables<Doc>> extends true\n ? [options: CustomerAccountGraphqlOptions<UserVariables<Doc>>]\n : [\n options: CustomerAccountGraphqlOptions<UserVariables<Doc>> & {\n variables: UserVariables<Doc>;\n },\n ];\n\n/**\n * A client that sends Customer Account API requests from your server for the current request.\n */\nexport type CustomerAccountClient = {\n /** The GraphQL endpoint, `https://shopify.com/{shopId}/account/customer/api/{version}/graphql`. */\n readonly apiUrl: string;\n /**\n * Sends a Customer Account API query or mutation with the customer's access token, and returns the data, any GraphQL errors, and the response headers. Pass a document from the Customer Account `gql` function.\n *\n * The request makes the final response private and uncacheable when you call `applyResponseHeaders()`. When the document declares `$language: LanguageCode` and you omit it, the client fills the variable from the request context's language. A `$language` variable of any other type stays yours.\n *\n * The method throws a `TypeError` for a document from any other `gql` function, including the Storefront API `gql` function, and for variables that aren't an object. When a signal aborts, the method throws the signal's reason. A missing or malformed access token throws `CustomerAccountAuthenticationError`, a timeout throws `CustomerAccountTimeoutError`, and other request failures throw `CustomerAccountApiError`.\n *\n * @throws {TypeError} When another gql function created the document, or when the variables aren't an object.\n * @throws {CustomerAccountAuthenticationError} When the options object is missing or the access token fails validation.\n * @throws {CustomerAccountTimeoutError} When the request exceeds the client's timeout.\n * @throws {CustomerAccountApiError} On a non-OK HTTP status, unparseable JSON, a response without data, or a network failure.\n *\n * @example\n * ```ts\n * const result = await client.graphql(\n * gql(`query { customer { firstName lastName } }`),\n * { accessToken },\n * );\n *\n * if (result.errors) {\n * console.error(result.errors);\n * } else {\n * console.log(result.data.customer.firstName);\n * }\n * ```\n */\n graphql: <const Doc extends AnyCustomerAccountDocument>(\n document: Doc,\n ...options: CustomerAccountGqlRestParam<Doc>\n ) => Promise<CustomerAccountGraphqlResult<ResultOfDoc<Doc>>>;\n};\n\n/**\n * Creates a client that sends Customer Account API requests from your server. Create the client with the current request's context.\n *\n * The function throws when the shop ID, API version, or timeout is invalid, when the request context has no HTTPS URL, when no fetch implementation is available, and when the function runs in a browser.\n *\n * @example\n * ```ts\n * import { createCustomerAccountClient, gql } from \"@shopify/hydrogen/customer-account\";\n *\n * const customerAccount = createCustomerAccountClient({\n * shopId: \"12345\",\n * requestContext,\n * });\n *\n * const { data } = await customerAccount.graphql(\n * gql(`query { customer { firstName } }`),\n * { accessToken },\n * );\n * ```\n *\n * @param options - The shop ID, the API version, the request context, a custom fetch, and the request timeout.\n * @returns A client with the GraphQL endpoint URL and a `graphql()` method for Customer Account API requests.\n * @throws {Error} When called in a browser, when the shop ID, API version, or timeout is invalid, when no fetch is available, or when the request context URL is missing or not HTTPS.\n * @publicDocs\n */\nexport function createCustomerAccountClient({\n shopId,\n customerApiVersion = CUSTOMER_ACCOUNT_API_VERSION,\n requestContext,\n fetch: customFetch,\n defaultTimeoutInMs = DEFAULT_TIMEOUT_IN_MS,\n}: CreateCustomerAccountClientOptions): CustomerAccountClient {\n if (typeof document !== \"undefined\") {\n throw new Error(\n \"Customer Account API tokens cannot be used in a browser context. Use this client from server or edge routes only.\",\n );\n }\n\n validateShopId(shopId);\n validateCustomerApiVersion(customerApiVersion);\n validateTimeout(defaultTimeoutInMs);\n\n const resolvedFetch = customFetch ?? globalThis.fetch;\n if (typeof resolvedFetch !== \"function\") {\n throw new Error(\n \"No fetch function available. Pass a fetch option or ensure globalThis.fetch exists.\",\n );\n }\n\n const origin = getOrigin(requestContext.url);\n const apiUrl = `https://shopify.com/${shopId}/account/customer/api/${customerApiVersion}/graphql`;\n\n async function graphql<const Doc extends AnyCustomerAccountDocument>(\n document: Doc,\n ...rest: CustomerAccountGqlRestParam<Doc>\n ): Promise<CustomerAccountGraphqlResult<ResultOfDoc<Doc>>>;\n async function graphql(\n document: AnyCustomerAccountDocument,\n ...rest: [options?: CustomerAccountGraphqlOptions<unknown>]\n ): Promise<CustomerAccountGraphqlResult<unknown>> {\n assertCustomerAccountDocument(document);\n const options = validateGraphqlOptions(rest[0]);\n requestContext.markResponseAsPersonalized(CUSTOMER_ACCOUNT_GRAPHQL_PERSONALIZATION_REASON);\n const accessToken = validateAccessToken(options.accessToken);\n const externalSignals = [requestContext.signal, options.signal].filter(\n (signal): signal is AbortSignal => Boolean(signal),\n );\n throwIfAlreadyAborted(externalSignals);\n\n const { signal: timeoutSignal, cleanup: cleanupTimeout } =\n createCustomerAccountTimeoutSignal(defaultTimeoutInMs);\n externalSignals.push(timeoutSignal);\n const signal = AbortSignal.any(externalSignals);\n\n try {\n const variables = getVariables(\n document,\n getOptionalVariables(options.variables),\n requestContext.locale.language,\n );\n const response = await fetchCustomerAccountGraphql({\n fetch: resolvedFetch,\n apiUrl,\n accessToken,\n origin,\n query: document.source,\n variables,\n signal,\n timeoutSignal,\n timeoutInMs: defaultTimeoutInMs,\n });\n\n return await readCustomerAccountGraphqlResponse(\n response,\n signal,\n timeoutSignal,\n defaultTimeoutInMs,\n );\n } finally {\n cleanupTimeout();\n }\n }\n\n return { apiUrl, graphql };\n}\n\nasync function fetchCustomerAccountGraphql({\n fetch,\n apiUrl,\n accessToken,\n origin,\n query,\n variables,\n signal,\n timeoutSignal,\n timeoutInMs,\n}: FetchCustomerAccountGraphqlParams): Promise<Response> {\n try {\n return await withAbort(\n fetch(apiUrl, {\n method: \"POST\",\n headers: new Headers({\n Authorization: accessToken,\n \"Content-Type\": \"application/json\",\n Origin: origin,\n \"User-Agent\": HYDROGEN_USER_AGENT,\n }),\n body: JSON.stringify({ query, variables }),\n cache: \"no-store\",\n redirect: \"manual\",\n signal,\n }),\n signal,\n );\n } catch (cause) {\n throwIfCustomerAccountSignalAborted(signal, timeoutSignal, timeoutInMs);\n if (isAbortError(cause)) throw cause;\n throw new CustomerAccountApiError(\"Customer Account API request failed\", { cause });\n }\n}\n\nasync function readCustomerAccountGraphqlResponse(\n response: Response,\n signal: AbortSignal,\n timeoutSignal: AbortSignal,\n timeoutInMs: number,\n): Promise<CustomerAccountGraphqlResult<unknown>> {\n const requestId = response.headers.get(\"x-request-id\") ?? undefined;\n if (!response.ok) {\n cancelResponseBody(response);\n throw new CustomerAccountApiError(`Customer Account API responded with ${response.status}`, {\n status: response.status,\n requestId,\n retryAfter: response.headers.get(\"retry-after\") ?? undefined,\n });\n }\n\n let body: { data?: unknown; errors?: GraphQLFormattedError[] };\n try {\n body = parseGraphqlResponse(await withAbort(response.json(), signal));\n } catch (cause) {\n cancelResponseBody(response);\n\n throwIfCustomerAccountSignalAborted(signal, timeoutSignal, timeoutInMs);\n if (isAbortError(cause)) throw cause;\n throw new CustomerAccountApiError(\"Failed to parse Customer Account API response as JSON\", {\n status: response.status,\n requestId,\n cause,\n });\n }\n\n if (body.errors) {\n return { data: body.data ?? null, errors: body.errors, headers: response.headers };\n }\n\n if (body.data == null) {\n throw new CustomerAccountApiError(\"Customer Account API response did not include data\", {\n status: response.status,\n requestId,\n });\n }\n\n return { data: body.data, headers: response.headers };\n}\n\nfunction cancelResponseBody(response: Response): void {\n try {\n void response.body?.cancel().catch(() => undefined);\n } catch {}\n}\n\nfunction validateTimeout(timeoutInMs: number): void {\n if (\n !Number.isSafeInteger(timeoutInMs) ||\n timeoutInMs <= 0 ||\n timeoutInMs > MAX_SET_TIMEOUT_IN_MS\n ) {\n throw new Error(\n `defaultTimeoutInMs must be a positive safe integer no greater than ${MAX_SET_TIMEOUT_IN_MS}`,\n );\n }\n}\n\nfunction createCustomerAccountTimeoutSignal(timeoutInMs: number): {\n signal: AbortSignal;\n cleanup: () => void;\n} {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => {\n controller.abort(new CustomerAccountTimeoutError(timeoutInMs));\n }, timeoutInMs);\n\n return { signal: controller.signal, cleanup: () => clearTimeout(timeoutId) };\n}\n\nfunction withAbort<T>(promise: T | Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n if (!signal) return Promise.resolve(promise);\n if (signal.aborted) {\n return Promise.reject(\n signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\"),\n );\n }\n\n return new Promise<T>((resolve, reject) => {\n const abort = () => {\n signal.removeEventListener(\"abort\", abort);\n const reason =\n signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n reject(reason);\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n Promise.resolve(promise).then(\n (value) => {\n signal.removeEventListener(\"abort\", abort);\n resolve(value);\n },\n (error) => {\n signal.removeEventListener(\"abort\", abort);\n reject(error);\n },\n );\n });\n}\n\nfunction getVariables(\n document: { i18nVariableNames: ReadonlySet<keyof I18nVariableTypes> },\n variables: Record<string, unknown>,\n language: ShopifyRequestContext[\"locale\"][\"language\"],\n): Record<string, unknown> {\n if (!document.i18nVariableNames.has(\"language\")) return variables;\n if (\"language\" in variables) return variables;\n return { ...variables, language };\n}\n\nfunction throwIfAlreadyAborted(signals: AbortSignal[]): void {\n const abortedSignal = signals.find((signal) => signal.aborted);\n if (!abortedSignal) return;\n throw abortedSignal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n}\n\nfunction throwIfCustomerAccountSignalAborted(\n signal: AbortSignal,\n timeoutSignal: AbortSignal,\n timeoutInMs: number,\n): void {\n if (!signal.aborted) return;\n if (timeoutSignal.aborted && signal.reason === timeoutSignal.reason) {\n const reason = timeoutSignal.reason;\n throw reason instanceof CustomerAccountTimeoutError\n ? reason\n : new CustomerAccountTimeoutError(timeoutInMs);\n }\n throw signal.reason ?? new DOMException(\"signal is aborted without reason\", \"AbortError\");\n}\n\nfunction isAbortError(cause: unknown): cause is DOMException {\n return cause instanceof DOMException && cause.name === \"AbortError\";\n}\n\nfunction parseGraphqlResponse(json: unknown): {\n data?: unknown;\n errors?: GraphQLFormattedError[];\n} {\n if (!isObjectRecord(json)) {\n throw new Error(\"Customer Account API returned unexpected JSON type\");\n }\n\n if (!(\"data\" in json) && !(\"errors\" in json)) {\n throw new Error(\"Customer Account API response must include data or errors\");\n }\n const errors = json.errors;\n if (errors !== undefined && !isGraphqlErrorArray(errors)) {\n throw new Error(\"Customer Account API returned invalid GraphQL errors\");\n }\n return { data: json.data, errors };\n}\n\nfunction isGraphqlErrorArray(value: unknown): value is GraphQLFormattedError[] {\n if (!Array.isArray(value)) return false;\n return value.every((error) => {\n return typeof error === \"object\" && error !== null && typeof error.message === \"string\";\n });\n}\n\nfunction validateShopId(shopId: string): void {\n if (!SHOP_ID_RE.test(shopId)) {\n throw new Error(\"shopId must be a numeric Shopify shop ID string\");\n }\n}\n\nfunction validateCustomerApiVersion(customerApiVersion: string): void {\n if (!CUSTOMER_API_VERSION_RE.test(customerApiVersion)) {\n throw new Error(\"customerApiVersion must use YYYY-MM format\");\n }\n}\n\nfunction validateAccessToken(accessToken: AccessToken): string {\n if (\n typeof accessToken !== \"string\" ||\n accessToken === \"\" ||\n accessToken.trim() !== accessToken ||\n hasAsciiControlCharacter(accessToken)\n ) {\n throw new CustomerAccountAuthenticationError();\n }\n return accessToken;\n}\n\nfunction validateGraphqlOptions(\n options: CustomerAccountGraphqlOptions<unknown> | undefined,\n): CustomerAccountGraphqlOptions<unknown> {\n if (typeof options !== \"object\" || options === null) {\n throw new CustomerAccountAuthenticationError();\n }\n return options;\n}\n\nfunction getOptionalVariables(variables: unknown): Record<string, unknown> {\n if (variables === undefined) return {};\n if (!isObjectRecord(variables)) {\n throw new TypeError(\"Customer Account API variables must be an object\");\n }\n return variables;\n}\n\nfunction hasAsciiControlCharacter(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n const codePoint = value.charCodeAt(index);\n if (codePoint <= MAX_ASCII_CONTROL_CODE_POINT || codePoint === ASCII_DELETE_CODE_POINT) {\n return true;\n }\n }\n return false;\n}\n\n/**\n * Customer Account API requires an HTTPS Origin, but local dev frameworks often\n * receive `http://localhost` requests. Keep that local-only exception without\n * weakening origin validation for non-local requests.\n */\nfunction getOrigin(requestUrl: string | undefined): string {\n if (!requestUrl) {\n throw new Error(\"requestContext.url is required for Customer Account API requests\");\n }\n\n const url = new URL(requestUrl);\n if (url.protocol === \"https:\") return url.origin;\n if (url.protocol === \"http:\" && LOCAL_ORIGIN_HOSTS.has(url.hostname)) {\n return `https://${url.host}`;\n }\n throw new Error(`Customer Account API origin must use HTTPS. Received: ${requestUrl}`);\n}\n"],"mappings":";;;;;;AA0BA,MAAM,aAAa;AACnB,MAAM,0BAA0B;AAChC,MAAM,+BAA+B;AACrC,MAAM,0BAA0B;AAChC,MAAM,wBAAwB;AAC9B,MAAM,qBAAqB,IAAI,IAAI;CAAC;CAAa;CAAa;CAAO;CAAQ,CAAC;AAC9E,MAAM,kDAAkD;;;;;;;;;;;;;;;;;;;;;;;;;;AAwKxD,SAAgB,4BAA4B,EAC1C,QACA,qBAAqB,8BACrB,gBACA,OAAO,aACP,qBAAqB,yBACuC;AAC5D,KAAI,OAAO,aAAa,YACtB,OAAM,IAAI,MACR,oHACD;AAGH,gBAAe,OAAO;AACtB,4BAA2B,mBAAmB;AAC9C,iBAAgB,mBAAmB;CAEnC,MAAM,gBAAgB,eAAe,WAAW;AAChD,KAAI,OAAO,kBAAkB,WAC3B,OAAM,IAAI,MACR,sFACD;CAGH,MAAM,SAAS,UAAU,eAAe,IAAI;CAC5C,MAAM,SAAS,uBAAuB,OAAO,wBAAwB,mBAAmB;CAMxF,eAAe,QACb,UACA,GAAG,MAC6C;AAChD,gCAA8B,SAAS;EACvC,MAAM,UAAU,uBAAuB,KAAK,GAAG;AAC/C,iBAAe,2BAA2B,gDAAgD;EAC1F,MAAM,cAAc,oBAAoB,QAAQ,YAAY;EAC5D,MAAM,kBAAkB,CAAC,eAAe,QAAQ,QAAQ,OAAO,CAAC,QAC7D,WAAkC,QAAQ,OAAO,CACnD;AACD,wBAAsB,gBAAgB;EAEtC,MAAM,EAAE,QAAQ,eAAe,SAAS,mBACtC,mCAAmC,mBAAmB;AACxD,kBAAgB,KAAK,cAAc;EACnC,MAAM,S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AC,WAAW,KAAK,OAAO,CAC1B,OAAM,IAAI,MAAM,kDAAkD;;AAItE,SAAS,2BAA2B,oBAAkC;AACpE,KAAI,CAAC,wBAAwB,KAAK,mBAAmB,CACnD,OAAM,IAAI,MAAM,6CAA6C;;AAIjE,SAAS,oBAAoB,aAAkC;AAC7D,KACE,OAAO,gBAAgB,YACvB,gBAAgB,MAChB,YAAY,MAAM,KAAK,eACvB,yBAAyB,YAAY,CAErC,OAAM,IAAI,oCAAoC;AAEhD,QAAO;;AAGT,SAAS,uBACP,SACwC;AACxC,KAAI,OAAO,YAAY,YAAY,YAAY,KAC7C,OAAM,IAAI,oCAAoC;AAEhD,QAAO;;AAGT,SAAS,qBAAqB,WAA6C;AACzE,KAAI,cAAc,OAAW,QAAO,EAAE;AACtC,KAAI,CAAC,eAAe,UAAU,CAC5B,OAAM,IAAI,UAAU,mDAAmD;AAEzE,QAAO;;AAGT,SAAS,yBAAyB,OAAwB;AACxD,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,YAAY,MAAM,WAAW,MAAM;AACzC,MAAI,aAAa,gCAAgC,cAAc,wBAC7D,QAAO;;AAGX,QAAO;;;;;;;AAQT,SAAS,UAAU,YAAwC;AACzD,KAAI,CAAC,WACH,OAAM,IAAI,MAAM,mEAAmE;CAGrF,MAAM,MAAM,IAAI,IAAI,WAAW;AAC/B,KAAI,IAAI,aAAa,SAAU,QAAO,IAAI;AAC1C,KAAI,IAAI,aAAa,WAAW,mBAAmB,IAAI,IAAI,SAAS,CAClE,QAAO,WAAW,IAAI;AAExB,OAAM,IAAI,MAAM,yDAAyD,aAAa"}
@@ -9,6 +9,12 @@ type CustomerAccountTadaGql = initGraphQLTada<{
9
9
  scalars: CustomerAccountScalars;
10
10
  }>;
11
11
  declare const CUSTOMER_ACCOUNT_DOCUMENT: unique symbol;
12
+ /**
13
+ * Variables the Customer Account client fills from `requestContext.locale` when the caller omits them, with the named type each must be declared as. Same-named variables of any other type belong to the caller.
14
+ */
15
+ declare const CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES: {
16
+ readonly language: "LanguageCode";
17
+ };
12
18
  /**
13
19
  * A Customer Account API query or mutation that `gql` from `@shopify/hydrogen/customer-account` returns. TypeScript infers the result and variables types from the document's GraphQL source.
14
20
  *
@@ -81,5 +87,5 @@ type CustomerAccountGql = {
81
87
  */
82
88
  declare const gql: CustomerAccountGql;
83
89
  //#endregion
84
- export { AnyCustomerAccountDocument, ComposedSource, CustomerAccountDocument, FragmentSources, SourceOf, gql };
90
+ export { AnyCustomerAccountDocument, CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES, ComposedSource, CustomerAccountDocument, FragmentSources, SourceOf, gql };
85
91
  //# sourceMappingURL=graphql.d.mts.map
@@ -1,8 +1,12 @@
1
+ import { getVariableNamesDeclaredAs } from "../client/i18n-variables.mjs";
1
2
  import { isObjectRecord } from "../core/utils/record.mjs";
2
3
 
3
4
  //#region src/customer-account/graphql.ts
4
5
  const CUSTOMER_ACCOUNT_DOCUMENT = Symbol("CustomerAccountDocument");
5
- const VARIABLE_DEFINITION_RE = /\$([_A-Za-z][_0-9A-Za-z]*)\s*:/g;
6
+ /**
7
+ * Variables the Customer Account client fills from `requestContext.locale` when the caller omits them, with the named type each must be declared as. Same-named variables of any other type belong to the caller.
8
+ */
9
+ const CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES = { language: "LanguageCode" };
6
10
  /**
7
11
  * Creates a typed Customer Account API query or mutation from a GraphQL source string. Pass the document to the Customer Account API client. Call `gql` as a regular function. Tagged template syntax doesn't work.
8
12
  *
@@ -59,7 +63,7 @@ const gql = ((source, fragments) => {
59
63
  return {
60
64
  [CUSTOMER_ACCOUNT_DOCUMENT]: true,
61
65
  source: query,
62
- variableNames: getVariableNames(query)
66
+ i18nVariableNames: new Set(getVariableNamesDeclaredAs(query, CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES))
63
67
  };
64
68
  });
65
69
  function isCustomerAccountDocument(value) {
@@ -69,11 +73,6 @@ function isCustomerAccountDocument(value) {
69
73
  function assertCustomerAccountDocument(value) {
70
74
  if (!isCustomerAccountDocument(value)) throw new TypeError("Expected a Customer Account API document returned by CAAPI.gql().");
71
75
  }
72
- function getVariableNames(source) {
73
- const names = /* @__PURE__ */ new Set();
74
- for (const match of source.matchAll(VARIABLE_DEFINITION_RE)) names.add(match[1]);
75
- return names;
76
- }
77
76
 
78
77
  //#endregion
79
78
  export { assertCustomerAccountDocument, gql };
@@ -1 +1 @@
1
- {"version":3,"file":"graphql.mjs","names":[],"sources":["../../src/customer-account/graphql.ts"],"sourcesContent":["import type { DocumentDecoration, initGraphQLTada as InitGraphQLTada } from \"gql.tada\";\n\nimport { isObjectRecord } from \"../core/utils/record\";\nimport type { introspection } from \"../graphql/generated/customer-account-graphql-env\";\nimport type { CustomerAccountScalars } from \"../graphql/scalars\";\nimport type { InferResult, InferVariables } from \"./type-resolver\";\n\ntype CustomerAccountTadaGql = InitGraphQLTada<{\n introspection: introspection;\n scalars: CustomerAccountScalars;\n}>;\n\nconst CUSTOMER_ACCOUNT_DOCUMENT = Symbol(\"CustomerAccountDocument\");\nconst VARIABLE_DEFINITION_RE = /\\$([_A-Za-z][_0-9A-Za-z]*)\\s*:/g;\n\n/**\n * A Customer Account API query or mutation that `gql` from `@shopify/hydrogen/customer-account` returns. TypeScript infers the result and variables types from the document's GraphQL source.\n *\n * Create documents only with the Customer Account `gql` function. The client throws a `TypeError` for any other object.\n */\nexport type CustomerAccountDocument<\n Result = unknown,\n Variables = never,\n Source extends string = string,\n> = DocumentDecoration<Result, Variables> & {\n readonly [CUSTOMER_ACCOUNT_DOCUMENT]: true;\n readonly source: Source;\n};\n\n/** Any Customer Account API document. Use the type as a constraint when a function accepts any document. */\nexport type AnyCustomerAccountDocument = CustomerAccountDocument<unknown, never, string>;\n\n/** Extracts the source string literal type from a Customer Account document. */\nexport type SourceOf<Doc> = Doc extends { readonly source: infer Source extends string }\n ? Source\n : never;\n\n/**\n * Joins the source strings of a tuple of fragment documents with newlines at the type level. An empty tuple produces `\"\"`.\n */\nexport type FragmentSources<Fragments extends readonly AnyCustomerAccountDocument[]> =\n Fragments extends readonly []\n ? \"\"\n : Fragments extends readonly [infer Only extends AnyCustomerAccountDocument]\n ? SourceOf<Only>\n : Fragments extends readonly [\n infer First extends AnyCustomerAccountDocument,\n ...infer Rest extends readonly AnyCustomerAccountDocument[],\n ]\n ? `${SourceOf<First>}\\n${FragmentSources<Rest>}`\n : string;\n\n/**\n * Combines an operation source with the sources of its fragments at the type level. With no fragments, the result is the operation source.\n *\n * @publicDocs\n */\nexport type ComposedSource<\n Source extends string,\n Fragments extends readonly AnyCustomerAccountDocument[],\n> = FragmentSources<Fragments> extends \"\" ? Source : `${Source}\\n${FragmentSources<Fragments>}`;\n\ntype CustomerAccountDocumentValue = AnyCustomerAccountDocument & {\n readonly variableNames: ReadonlySet<string>;\n};\n\ntype CustomerAccountGql = {\n <const Source extends string>(\n source: Source,\n ): CustomerAccountDocument<InferResult<Source>, InferVariables<Source>, Source>;\n <\n const Source extends string,\n const Fragments extends readonly AnyCustomerAccountDocument[],\n const DocumentSource extends string = ComposedSource<Source, Fragments>,\n >(\n source: Source,\n fragments: Fragments,\n ): CustomerAccountDocument<\n InferResult<DocumentSource>,\n InferVariables<DocumentSource>,\n DocumentSource\n >;\n} & CustomerAccountTadaGql;\n\n/**\n * Creates a typed Customer Account API query or mutation from a GraphQL source string. Pass the document to the Customer Account API client. Call `gql` as a regular function. Tagged template syntax doesn't work.\n *\n * Pass an array of fragment documents as the second argument to append the fragments to the operation. Each fragment must come from this `gql` function, or the call throws a `TypeError`.\n *\n * @example\n * ```ts\n * import { gql } from \"@shopify/hydrogen/customer-account\";\n *\n * const CUSTOMER_QUERY = gql(`\n * query CustomerDetails {\n * customer {\n * firstName\n * lastName\n * emailAddress { emailAddress }\n * }\n * }\n * `);\n * ```\n *\n * @example\n * ```ts\n * const ORDER_FIELDS = gql(`\n * fragment OrderFields on Order {\n * id\n * totalPrice { amount currencyCode }\n * }\n * `);\n *\n * const ORDERS_QUERY = gql(`\n * query CustomerOrders {\n * customer {\n * orders(first: 10) {\n * nodes { ...OrderFields }\n * }\n * }\n * }\n * `, [ORDER_FIELDS]);\n * ```\n * @publicDocs\n */\n// oxlint-disable-next-line typescript-eslint/consistent-type-assertions -- gql.tada adds phantom helper properties to the function type that are not used at runtime.\nexport const gql = ((source: string, fragments?: readonly CustomerAccountDocument[]) => {\n let query = source;\n\n if (fragments) {\n const seen = new Set<string>();\n for (const fragment of fragments) {\n assertCustomerAccountDocument(fragment);\n if (!seen.has(fragment.source)) {\n seen.add(fragment.source);\n query += \"\\n\" + fragment.source;\n }\n }\n }\n\n const document = {\n [CUSTOMER_ACCOUNT_DOCUMENT]: true,\n source: query,\n variableNames: getVariableNames(query),\n } satisfies CustomerAccountDocumentValue;\n return document;\n}) as unknown as CustomerAccountGql;\n\nexport function isCustomerAccountDocument(value: unknown): value is CustomerAccountDocumentValue {\n if (!isObjectRecord(value)) return false;\n return value[CUSTOMER_ACCOUNT_DOCUMENT] === true && typeof value.source === \"string\";\n}\n\nexport function assertCustomerAccountDocument(\n value: unknown,\n): asserts value is CustomerAccountDocumentValue {\n if (!isCustomerAccountDocument(value)) {\n throw new TypeError(\"Expected a Customer Account API document returned by CAAPI.gql().\");\n }\n}\n\nfunction getVariableNames(source: string): ReadonlySet<string> {\n const names = new Set<string>();\n for (const match of source.matchAll(VARIABLE_DEFINITION_RE)) {\n names.add(match[1]);\n }\n return names;\n}\n\n/**\n * Creates a typed Customer Account API query or mutation from a GraphQL source string. Pass the document to the Customer Account API client. Call `gql` as a regular function.\n *\n * Pass an array of fragment documents as the second argument to append the fragments to the operation. Each fragment must come from this `gql` function, or the call throws a `TypeError`.\n *\n * To validate documents, run `hydrogen gql check` in your `typecheck` script with the `@shopify/hydrogen/ts-plugin` setup. Framework typecheck commands don't validate the documents.\n *\n * @publicDocs\n */\nexport type CustomerAccountGqlForDocs =\n /**\n * @param source - The GraphQL source of an operation or a fragment.\n * @param fragments - The fragment documents that the operation uses.\n * @returns A typed document to pass to the Customer Account API client.\n */\n (source: string, fragments?: readonly AnyCustomerAccountDocument[]) => AnyCustomerAccountDocument;\n"],"mappings":";;;AAYA,MAAM,4BAA4B,OAAO,0BAA0B;AACnE,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiH/B,MAAa,QAAQ,QAAgB,cAAmD;CACtF,IAAI,QAAQ;AAEZ,KAAI,WAAW;EACb,MAAM,uBAAO,IAAI,KAAa;AAC9B,OAAK,MAAM,YAAY,WAAW;AAChC,iCAA8B,SAAS;AACvC,OAAI,CAAC,KAAK,IAAI,SAAS,OAAO,EAAE;AAC9B,SAAK,IAAI,SAAS,OAAO;AACzB,aAAS,OAAO,SAAS;;;;AAU/B,QAAO;GAJJ,4BAA4B;EAC7B,QAAQ;EACR,eAAe,iBAAiB,MAAM;EAEzB;;AAGjB,SAAgB,0BAA0B,OAAuD;AAC/F,KAAI,CAAC,eAAe,MAAM,CAAE,QAAO;AACnC,QAAO,MAAM,+BAA+B,QAAQ,OAAO,MAAM,WAAW;;AAG9E,SAAgB,8BACd,OAC+C;AAC/C,KAAI,CAAC,0BAA0B,MAAM,CACnC,OAAM,IAAI,UAAU,oEAAoE;;AAI5F,SAAS,iBAAiB,QAAqC;CAC7D,MAAM,wBAAQ,IAAI,KAAa;AAC/B,MAAK,MAAM,SAAS,OAAO,SAAS,uBAAuB,CACzD,OAAM,IAAI,MAAM,GAAG;AAErB,QAAO"}
1
+ {"version":3,"file":"graphql.mjs","names":[],"sources":["../../src/customer-account/graphql.ts"],"sourcesContent":["import type { DocumentDecoration, initGraphQLTada as InitGraphQLTada } from \"gql.tada\";\n\nimport { getVariableNamesDeclaredAs } from \"../client/i18n-variables\";\nimport { isObjectRecord } from \"../core/utils/record\";\nimport type { introspection } from \"../graphql/generated/customer-account-graphql-env\";\nimport type { CustomerAccountScalars } from \"../graphql/scalars\";\nimport type { InferResult, InferVariables } from \"./type-resolver\";\n\ntype CustomerAccountTadaGql = InitGraphQLTada<{\n introspection: introspection;\n scalars: CustomerAccountScalars;\n}>;\n\nconst CUSTOMER_ACCOUNT_DOCUMENT = Symbol(\"CustomerAccountDocument\");\n\n/**\n * Variables the Customer Account client fills from `requestContext.locale` when the caller omits them, with the named type each must be declared as. Same-named variables of any other type belong to the caller.\n */\nexport const CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES = {\n language: \"LanguageCode\",\n} as const;\n\ntype CustomerAccountI18nVariableName = keyof typeof CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES;\n\n/**\n * A Customer Account API query or mutation that `gql` from `@shopify/hydrogen/customer-account` returns. TypeScript infers the result and variables types from the document's GraphQL source.\n *\n * Create documents only with the Customer Account `gql` function. The client throws a `TypeError` for any other object.\n */\nexport type CustomerAccountDocument<\n Result = unknown,\n Variables = never,\n Source extends string = string,\n> = DocumentDecoration<Result, Variables> & {\n readonly [CUSTOMER_ACCOUNT_DOCUMENT]: true;\n readonly source: Source;\n};\n\n/** Any Customer Account API document. Use the type as a constraint when a function accepts any document. */\nexport type AnyCustomerAccountDocument = CustomerAccountDocument<unknown, never, string>;\n\n/** Extracts the source string literal type from a Customer Account document. */\nexport type SourceOf<Doc> = Doc extends { readonly source: infer Source extends string }\n ? Source\n : never;\n\n/**\n * Joins the source strings of a tuple of fragment documents with newlines at the type level. An empty tuple produces `\"\"`.\n */\nexport type FragmentSources<Fragments extends readonly AnyCustomerAccountDocument[]> =\n Fragments extends readonly []\n ? \"\"\n : Fragments extends readonly [infer Only extends AnyCustomerAccountDocument]\n ? SourceOf<Only>\n : Fragments extends readonly [\n infer First extends AnyCustomerAccountDocument,\n ...infer Rest extends readonly AnyCustomerAccountDocument[],\n ]\n ? `${SourceOf<First>}\\n${FragmentSources<Rest>}`\n : string;\n\n/**\n * Combines an operation source with the sources of its fragments at the type level. With no fragments, the result is the operation source.\n *\n * @publicDocs\n */\nexport type ComposedSource<\n Source extends string,\n Fragments extends readonly AnyCustomerAccountDocument[],\n> = FragmentSources<Fragments> extends \"\" ? Source : `${Source}\\n${FragmentSources<Fragments>}`;\n\ntype CustomerAccountDocumentValue = AnyCustomerAccountDocument & {\n /** The i18n variables that the first operation declares with their expected type, such as `$language: LanguageCode`. */\n readonly i18nVariableNames: ReadonlySet<CustomerAccountI18nVariableName>;\n};\n\ntype CustomerAccountGql = {\n <const Source extends string>(\n source: Source,\n ): CustomerAccountDocument<InferResult<Source>, InferVariables<Source>, Source>;\n <\n const Source extends string,\n const Fragments extends readonly AnyCustomerAccountDocument[],\n const DocumentSource extends string = ComposedSource<Source, Fragments>,\n >(\n source: Source,\n fragments: Fragments,\n ): CustomerAccountDocument<\n InferResult<DocumentSource>,\n InferVariables<DocumentSource>,\n DocumentSource\n >;\n} & CustomerAccountTadaGql;\n\n/**\n * Creates a typed Customer Account API query or mutation from a GraphQL source string. Pass the document to the Customer Account API client. Call `gql` as a regular function. Tagged template syntax doesn't work.\n *\n * Pass an array of fragment documents as the second argument to append the fragments to the operation. Each fragment must come from this `gql` function, or the call throws a `TypeError`.\n *\n * @example\n * ```ts\n * import { gql } from \"@shopify/hydrogen/customer-account\";\n *\n * const CUSTOMER_QUERY = gql(`\n * query CustomerDetails {\n * customer {\n * firstName\n * lastName\n * emailAddress { emailAddress }\n * }\n * }\n * `);\n * ```\n *\n * @example\n * ```ts\n * const ORDER_FIELDS = gql(`\n * fragment OrderFields on Order {\n * id\n * totalPrice { amount currencyCode }\n * }\n * `);\n *\n * const ORDERS_QUERY = gql(`\n * query CustomerOrders {\n * customer {\n * orders(first: 10) {\n * nodes { ...OrderFields }\n * }\n * }\n * }\n * `, [ORDER_FIELDS]);\n * ```\n * @publicDocs\n */\n// oxlint-disable-next-line typescript-eslint/consistent-type-assertions -- gql.tada adds phantom helper properties to the function type that are not used at runtime.\nexport const gql = ((source: string, fragments?: readonly CustomerAccountDocument[]) => {\n let query = source;\n\n if (fragments) {\n const seen = new Set<string>();\n for (const fragment of fragments) {\n assertCustomerAccountDocument(fragment);\n if (!seen.has(fragment.source)) {\n seen.add(fragment.source);\n query += \"\\n\" + fragment.source;\n }\n }\n }\n\n const document = {\n [CUSTOMER_ACCOUNT_DOCUMENT]: true,\n source: query,\n i18nVariableNames: new Set(\n getVariableNamesDeclaredAs(query, CUSTOMER_ACCOUNT_I18N_VARIABLE_TYPES),\n ),\n } satisfies CustomerAccountDocumentValue;\n return document;\n}) as unknown as CustomerAccountGql;\n\nexport function isCustomerAccountDocument(value: unknown): value is CustomerAccountDocumentValue {\n if (!isObjectRecord(value)) return false;\n return value[CUSTOMER_ACCOUNT_DOCUMENT] === true && typeof value.source === \"string\";\n}\n\nexport function assertCustomerAccountDocument(\n value: unknown,\n): asserts value is CustomerAccountDocumentValue {\n if (!isCustomerAccountDocument(value)) {\n throw new TypeError(\"Expected a Customer Account API document returned by CAAPI.gql().\");\n }\n}\n\n/**\n * Creates a typed Customer Account API query or mutation from a GraphQL source string. Pass the document to the Customer Account API client. Call `gql` as a regular function.\n *\n * Pass an array of fragment documents as the second argument to append the fragments to the operation. Each fragment must come from this `gql` function, or the call throws a `TypeError`.\n *\n * To validate documents, run `hydrogen gql check` in your `typecheck` script with the `@shopify/hydrogen/ts-plugin` setup. Framework typecheck commands don't validate the documents.\n *\n * @publicDocs\n */\nexport type CustomerAccountGqlForDocs =\n /**\n * @param source - The GraphQL source of an operation or a fragment.\n * @param fragments - The fragment documents that the operation uses.\n * @returns A typed document to pass to the Customer Account API client.\n */\n (source: string, fragments?: readonly AnyCustomerAccountDocument[]) => AnyCustomerAccountDocument;\n"],"mappings":";;;;AAaA,MAAM,4BAA4B,OAAO,0BAA0B;;;;AAKnE,MAAa,uCAAuC,EAClD,UAAU,gBACX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHD,MAAa,QAAQ,QAAgB,cAAmD;CACtF,IAAI,QAAQ;AAEZ,KAAI,WAAW;EACb,MAAM,uBAAO,IAAI,KAAa;AAC9B,OAAK,MAAM,YAAY,WAAW;AAChC,iCAA8B,SAAS;AACvC,OAAI,CAAC,KAAK,IAAI,SAAS,OAAO,EAAE;AAC9B,SAAK,IAAI,SAAS,OAAO;AACzB,aAAS,OAAO,SAAS;;;;AAY/B,QAAO;GANJ,4BAA4B;EAC7B,QAAQ;EACR,mBAAmB,IAAI,IACrB,2BAA2B,OAAO,qCAAqC,CACxE;EAEY;;AAGjB,SAAgB,0BAA0B,OAAuD;AAC/F,KAAI,CAAC,eAAe,MAAM,CAAE,QAAO;AACnC,QAAO,MAAM,+BAA+B,QAAQ,OAAO,MAAM,WAAW;;AAG9E,SAAgB,8BACd,OAC+C;AAC/C,KAAI,CAAC,0BAA0B,MAAM,CACnC,OAAM,IAAI,UAAU,oEAAoE"}