@shopify/hydrogen 2026.10.1 → 2026.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +3 -5
  2. package/dist/cli/index.mjs +8 -5
  3. package/dist/client/client.mjs +45 -12
  4. package/dist/client/client.mjs.map +1 -1
  5. package/dist/client/i18n-variables.d.mts +13 -0
  6. package/dist/client/i18n-variables.mjs +92 -0
  7. package/dist/client/i18n-variables.mjs.map +1 -0
  8. package/dist/client/types.d.mts +21 -8
  9. package/dist/core/cache/fetch-with-cache.mjs +8 -1
  10. package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
  11. package/dist/core/cart/cart.mjs +111 -24
  12. package/dist/core/cart/cart.mjs.map +1 -1
  13. package/dist/core/cart/cookie.mjs +6 -1
  14. package/dist/core/cart/cookie.mjs.map +1 -1
  15. package/dist/core/cart/form.d.mts +17 -5
  16. package/dist/core/cart/form.mjs +5 -0
  17. package/dist/core/cart/form.mjs.map +1 -1
  18. package/dist/core/cart/index.d.mts +1 -1
  19. package/dist/core/cart/queries.d.mts +57 -57
  20. package/dist/core/collection/url.mjs +8 -1
  21. package/dist/core/collection/url.mjs.map +1 -1
  22. package/dist/core/constants.mjs +2 -1
  23. package/dist/core/constants.mjs.map +1 -1
  24. package/dist/core/csp/index.d.mts +56 -0
  25. package/dist/core/csp/index.mjs +117 -0
  26. package/dist/core/csp/index.mjs.map +1 -0
  27. package/dist/core/csp/types.d.mts +52 -0
  28. package/dist/core/headers.mjs +2 -2
  29. package/dist/core/headers.mjs.map +1 -1
  30. package/dist/core/i18n/define.d.mts +54 -0
  31. package/dist/core/i18n/define.mjs +135 -0
  32. package/dist/core/i18n/define.mjs.map +1 -0
  33. package/dist/core/i18n/errors.d.mts +18 -0
  34. package/dist/core/i18n/errors.mjs +24 -0
  35. package/dist/core/i18n/errors.mjs.map +1 -0
  36. package/dist/core/i18n/href.d.mts +28 -0
  37. package/dist/core/i18n/href.mjs +45 -0
  38. package/dist/core/i18n/href.mjs.map +1 -0
  39. package/dist/core/i18n/locale.d.mts +21 -0
  40. package/dist/core/i18n/locale.mjs +36 -0
  41. package/dist/core/i18n/locale.mjs.map +1 -0
  42. package/dist/core/i18n/match.d.mts +37 -0
  43. package/dist/core/i18n/match.mjs +82 -0
  44. package/dist/core/i18n/match.mjs.map +1 -0
  45. package/dist/core/i18n/types.d.mts +80 -0
  46. package/dist/core/index.d.mts +14 -5
  47. package/dist/core/index.mjs +9 -2
  48. package/dist/core/predictive-search/index.d.mts +2 -2
  49. package/dist/core/predictive-search/queries.d.mts +2 -2
  50. package/dist/core/predictive-search/server-handlers.d.mts +27 -6
  51. package/dist/core/predictive-search/server-handlers.mjs +1 -4
  52. package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
  53. package/dist/core/predictive-search/url.d.mts +2 -2
  54. package/dist/core/predictive-search/url.mjs.map +1 -1
  55. package/dist/core/product/accept-variant-id.mjs +1 -1
  56. package/dist/core/product/accept-variant-id.mjs.map +1 -1
  57. package/dist/core/request-context.d.mts +61 -35
  58. package/dist/core/request-context.mjs +11 -7
  59. package/dist/core/request-context.mjs.map +1 -1
  60. package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  61. package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
  62. package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  63. package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
  64. package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
  65. package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
  66. package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
  67. package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  68. package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
  69. package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  70. package/dist/core/request-routing/registered-routes.d.mts +13 -2
  71. package/dist/core/request-routing/registered-routes.mjs +33 -9
  72. package/dist/core/request-routing/registered-routes.mjs.map +1 -1
  73. package/dist/core/request-routing/route-types.d.mts +18 -8
  74. package/dist/core/shop-pay/shop-pay.mjs +5 -4
  75. package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
  76. package/dist/core/shopify-scripts/analytics.mjs +3 -5
  77. package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
  78. package/dist/core/shopify-scripts/constants.mjs +3 -1
  79. package/dist/core/shopify-scripts/constants.mjs.map +1 -1
  80. package/dist/core/shopify-scripts/global.mjs +13 -11
  81. package/dist/core/shopify-scripts/global.mjs.map +1 -1
  82. package/dist/core/shopify-scripts/hashes.d.mts +17 -0
  83. package/dist/core/shopify-scripts/hashes.mjs +12 -0
  84. package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
  85. package/dist/core/shopify-scripts/index.d.mts +1 -0
  86. package/dist/core/shopify-scripts/index.mjs +12 -9
  87. package/dist/core/shopify-scripts/index.mjs.map +1 -1
  88. package/dist/core/shopify-scripts/page-view.mjs +4 -1
  89. package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
  90. package/dist/core/shopify-scripts/perfkit.mjs +8 -2
  91. package/dist/core/shopify-scripts/perfkit.mjs.map +1 -1
  92. package/dist/core/shopify-scripts/types.d.mts +4 -2
  93. package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
  94. package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  95. package/dist/core/standard-routes/build.d.mts +7 -2
  96. package/dist/core/standard-routes/build.mjs +10 -3
  97. package/dist/core/standard-routes/build.mjs.map +1 -1
  98. package/dist/core/standard-routes/match.mjs +11 -1
  99. package/dist/core/standard-routes/match.mjs.map +1 -1
  100. package/dist/core/standard-routes/path.mjs +14 -3
  101. package/dist/core/standard-routes/path.mjs.map +1 -1
  102. package/dist/core/standard-routes/types.d.mts +6 -1
  103. package/dist/core/url.mjs +5 -3
  104. package/dist/core/url.mjs.map +1 -1
  105. package/dist/core/utils/load-script.mjs +6 -6
  106. package/dist/core/utils/load-script.mjs.map +1 -1
  107. package/dist/customer-account/client.d.mts +14 -10
  108. package/dist/customer-account/client.mjs +4 -5
  109. package/dist/customer-account/client.mjs.map +1 -1
  110. package/dist/customer-account/graphql.d.mts +7 -1
  111. package/dist/customer-account/graphql.mjs +6 -7
  112. package/dist/customer-account/graphql.mjs.map +1 -1
  113. package/dist/customer-account/session.mjs +3 -4
  114. package/dist/customer-account/session.mjs.map +1 -1
  115. package/dist/development/client/client.mjs +45 -12
  116. package/dist/development/client/client.mjs.map +1 -1
  117. package/dist/development/client/i18n-variables.d.mts +13 -0
  118. package/dist/development/client/i18n-variables.mjs +92 -0
  119. package/dist/development/client/i18n-variables.mjs.map +1 -0
  120. package/dist/development/client/types.d.mts +21 -8
  121. package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
  122. package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
  123. package/dist/development/core/cart/cart.mjs +111 -24
  124. package/dist/development/core/cart/cart.mjs.map +1 -1
  125. package/dist/development/core/cart/cookie.mjs +6 -1
  126. package/dist/development/core/cart/cookie.mjs.map +1 -1
  127. package/dist/development/core/cart/form.d.mts +17 -5
  128. package/dist/development/core/cart/form.mjs +5 -0
  129. package/dist/development/core/cart/form.mjs.map +1 -1
  130. package/dist/development/core/cart/index.d.mts +1 -1
  131. package/dist/development/core/cart/queries.d.mts +57 -57
  132. package/dist/development/core/collection/url.mjs +8 -1
  133. package/dist/development/core/collection/url.mjs.map +1 -1
  134. package/dist/development/core/constants.mjs +2 -1
  135. package/dist/development/core/constants.mjs.map +1 -1
  136. package/dist/development/core/csp/index.d.mts +56 -0
  137. package/dist/development/core/csp/index.mjs +128 -0
  138. package/dist/development/core/csp/index.mjs.map +1 -0
  139. package/dist/development/core/csp/types.d.mts +52 -0
  140. package/dist/development/core/development.d.mts +14 -5
  141. package/dist/development/core/development.mjs +9 -2
  142. package/dist/development/core/headers.mjs +2 -2
  143. package/dist/development/core/headers.mjs.map +1 -1
  144. package/dist/development/core/i18n/define.d.mts +54 -0
  145. package/dist/development/core/i18n/define.mjs +135 -0
  146. package/dist/development/core/i18n/define.mjs.map +1 -0
  147. package/dist/development/core/i18n/errors.d.mts +18 -0
  148. package/dist/development/core/i18n/errors.mjs +24 -0
  149. package/dist/development/core/i18n/errors.mjs.map +1 -0
  150. package/dist/development/core/i18n/href.d.mts +28 -0
  151. package/dist/development/core/i18n/href.mjs +45 -0
  152. package/dist/development/core/i18n/href.mjs.map +1 -0
  153. package/dist/development/core/i18n/locale.d.mts +21 -0
  154. package/dist/development/core/i18n/locale.mjs +36 -0
  155. package/dist/development/core/i18n/locale.mjs.map +1 -0
  156. package/dist/development/core/i18n/match.d.mts +37 -0
  157. package/dist/development/core/i18n/match.mjs +82 -0
  158. package/dist/development/core/i18n/match.mjs.map +1 -0
  159. package/dist/development/core/i18n/types.d.mts +80 -0
  160. package/dist/development/core/index.d.mts +13 -4
  161. package/dist/development/core/predictive-search/index.d.mts +2 -2
  162. package/dist/development/core/predictive-search/queries.d.mts +2 -2
  163. package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
  164. package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
  165. package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
  166. package/dist/development/core/predictive-search/url.d.mts +2 -2
  167. package/dist/development/core/predictive-search/url.mjs.map +1 -1
  168. package/dist/development/core/product/accept-variant-id.mjs +1 -1
  169. package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
  170. package/dist/development/core/request-context.d.mts +61 -35
  171. package/dist/development/core/request-context.mjs +11 -7
  172. package/dist/development/core/request-context.mjs.map +1 -1
  173. package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
  174. package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
  175. package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
  176. package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
  177. package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
  178. package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
  179. package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
  180. package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
  181. package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
  182. package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
  183. package/dist/development/core/request-routing/registered-routes.d.mts +13 -2
  184. package/dist/development/core/request-routing/registered-routes.mjs +33 -9
  185. package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
  186. package/dist/development/core/request-routing/route-types.d.mts +18 -8
  187. package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
  188. package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
  189. package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
  190. package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
  191. package/dist/development/core/shopify-scripts/constants.mjs +3 -1
  192. package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
  193. package/dist/development/core/shopify-scripts/global.mjs +13 -11
  194. package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
  195. package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
  196. package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
  197. package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
  198. package/dist/development/core/shopify-scripts/index.d.mts +1 -0
  199. package/dist/development/core/shopify-scripts/index.mjs +12 -9
  200. package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
  201. package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
  202. package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
  203. package/dist/development/core/shopify-scripts/perfkit.mjs +8 -2
  204. package/dist/development/core/shopify-scripts/perfkit.mjs.map +1 -1
  205. package/dist/development/core/shopify-scripts/types.d.mts +4 -2
  206. package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
  207. package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
  208. package/dist/development/core/standard-routes/build.d.mts +7 -2
  209. package/dist/development/core/standard-routes/build.mjs +10 -3
  210. package/dist/development/core/standard-routes/build.mjs.map +1 -1
  211. package/dist/development/core/standard-routes/match.mjs +11 -1
  212. package/dist/development/core/standard-routes/match.mjs.map +1 -1
  213. package/dist/development/core/standard-routes/path.mjs +14 -3
  214. package/dist/development/core/standard-routes/path.mjs.map +1 -1
  215. package/dist/development/core/standard-routes/types.d.mts +6 -1
  216. package/dist/development/core/url.mjs +5 -3
  217. package/dist/development/core/url.mjs.map +1 -1
  218. package/dist/development/core/utils/load-script.mjs +6 -6
  219. package/dist/development/core/utils/load-script.mjs.map +1 -1
  220. package/dist/development/customer-account/session.mjs.map +1 -1
  221. package/dist/development/globals.d.mts +8 -4
  222. package/dist/development/graphql/type-resolver.d.mts +39 -1
  223. package/dist/development/react/cart.mjs +79 -25
  224. package/dist/development/react/cart.mjs.map +1 -1
  225. package/dist/development/react/index.d.mts +2 -2
  226. package/dist/globals.d.mts +8 -4
  227. package/dist/graphql/type-resolver.d.mts +39 -1
  228. package/dist/react/cart.mjs +79 -25
  229. package/dist/react/cart.mjs.map +1 -1
  230. package/dist/react/index.d.mts +2 -2
  231. package/dist/vite/index.d.mts +11 -1
  232. package/dist/vite/index.mjs +21 -1
  233. package/dist/vite/index.mjs.map +1 -0
  234. package/package.json +13 -3
  235. package/skills/hydrogen-analytics/SKILL.md +2 -2
  236. package/skills/hydrogen-analytics/references/react.md +2 -2
  237. package/skills/hydrogen-cart-ui/SKILL.md +2 -2
  238. package/skills/hydrogen-markets/SKILL.md +127 -93
  239. package/skills/hydrogen-markets/references/nextjs.md +77 -87
  240. package/skills/hydrogen-oxygen/references/react-router.md +1 -2
  241. package/skills/hydrogen-predictive-search/SKILL.md +18 -1
  242. package/skills/hydrogen-request-handlers/SKILL.md +24 -6
  243. package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
  244. package/skills/hydrogen-request-handlers/references/frameworks.md +9 -12
  245. package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
  246. package/skills/hydrogen-request-handlers/references/nuxt.md +7 -7
  247. package/skills/hydrogen-robots-txt/SKILL.md +87 -0
  248. package/skills/hydrogen-routing/SKILL.md +36 -14
  249. package/skills/hydrogen-setup/SKILL.md +2 -2
  250. package/skills/hydrogen-setup/references/analytics.md +5 -5
  251. package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
  252. package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
  253. package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
  254. package/skills/hydrogen-smoke-test/SKILL.md +9 -2
  255. package/skills/hydrogen-storefront-client/SKILL.md +29 -9
  256. package/skills/hydrogen-storefront-client/references/astro.md +8 -3
  257. package/skills/hydrogen-storefront-client/references/caching.md +2 -0
  258. package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
  259. package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
  260. package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
  261. package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
  262. package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
  263. package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
  264. package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
  265. package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
@@ -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.1`;
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 HTTPS. Received: ${requestUrl}`);\n}\n"],"mappings":";;;;;;AAeA,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,aAAa;AACnB,MAAM,kDAAkD;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JxD,SAAgB,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tC,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+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;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"}
@@ -1,6 +1,6 @@
1
1
  import { getLogger } from "../core/logging/logging.mjs";
2
2
  import { CUSTOMER_ACCOUNT_PATHS, getSameOriginPath } from "../core/url.mjs";
3
- import { DEFAULT_TIMEOUT_IN_MS } from "../core/constants.mjs";
3
+ import { DEFAULT_TIMEOUT_IN_MS, HYDROGEN_USER_AGENT } from "../core/constants.mjs";
4
4
  import { createCallableRouteHandler } from "../core/request-routing/registered-routes.mjs";
5
5
  import { getCartBuyerIdentitySync } from "../core/cart/buyer-identity-sync.mjs";
6
6
  import { CustomerAccountApiError, CustomerAccountOAuthError } from "./errors.mjs";
@@ -44,7 +44,6 @@ const AUTHORIZATION_CODE_GRANT_TYPE = "authorization_code";
44
44
  const REFRESH_TOKEN_GRANT_TYPE = "refresh_token";
45
45
  const CUSTOMER_ACCOUNT_SCOPE = "openid email customer-account-api:full";
46
46
  const CODE_CHALLENGE_METHOD = "S256";
47
- const USER_AGENT = `Hydrogen 2026.10.1`;
48
47
  const EXPIRY_BUFFER_IN_SECONDS = 120;
49
48
  const PENDING_LOGIN_TTL_IN_MINUTES = 10;
50
49
  const SECONDS_PER_MINUTE = 60;
@@ -266,7 +265,7 @@ async function handleLoginRoute(customerSession, sessionManager, requestContext,
266
265
  return redirectResult(await customerSession.prepareLoginUrl(sessionManager, requestContext, {
267
266
  origin,
268
267
  returnTo,
269
- countryCode: requestContext.i18n.country,
268
+ countryCode: requestContext.locale.country,
270
269
  locale: getOptionalSearchParam(requestUrl, "locale"),
271
270
  acrValues: getOptionalSearchParam(requestUrl, "acr_values"),
272
271
  loginHint: getOptionalSearchParam(requestUrl, "login_hint"),
@@ -518,7 +517,7 @@ async function postTokenRequest({ url, origin, body, fetch, signal }) {
518
517
  method: "POST",
519
518
  headers: new Headers({
520
519
  "Content-Type": "application/x-www-form-urlencoded",
521
- "User-Agent": USER_AGENT,
520
+ "User-Agent": HYDROGEN_USER_AGENT,
522
521
  Origin: origin
523
522
  }),
524
523
  body,