@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.
- package/README.md +3 -5
- package/dist/cli/index.mjs +8 -5
- package/dist/client/client.mjs +45 -12
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/i18n-variables.d.mts +13 -0
- package/dist/client/i18n-variables.mjs +92 -0
- package/dist/client/i18n-variables.mjs.map +1 -0
- package/dist/client/types.d.mts +21 -8
- package/dist/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cart/cart.mjs +111 -24
- package/dist/core/cart/cart.mjs.map +1 -1
- package/dist/core/cart/cookie.mjs +6 -1
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +17 -5
- package/dist/core/cart/form.mjs +5 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/cart/queries.d.mts +57 -57
- package/dist/core/collection/url.mjs +8 -1
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.mjs +2 -1
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/csp/index.d.mts +56 -0
- package/dist/core/csp/index.mjs +117 -0
- package/dist/core/csp/index.mjs.map +1 -0
- package/dist/core/csp/types.d.mts +52 -0
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/i18n/define.d.mts +54 -0
- package/dist/core/i18n/define.mjs +135 -0
- package/dist/core/i18n/define.mjs.map +1 -0
- package/dist/core/i18n/errors.d.mts +18 -0
- package/dist/core/i18n/errors.mjs +24 -0
- package/dist/core/i18n/errors.mjs.map +1 -0
- package/dist/core/i18n/href.d.mts +28 -0
- package/dist/core/i18n/href.mjs +45 -0
- package/dist/core/i18n/href.mjs.map +1 -0
- package/dist/core/i18n/locale.d.mts +21 -0
- package/dist/core/i18n/locale.mjs +36 -0
- package/dist/core/i18n/locale.mjs.map +1 -0
- package/dist/core/i18n/match.d.mts +37 -0
- package/dist/core/i18n/match.mjs +82 -0
- package/dist/core/i18n/match.mjs.map +1 -0
- package/dist/core/i18n/types.d.mts +80 -0
- package/dist/core/index.d.mts +14 -5
- package/dist/core/index.mjs +9 -2
- package/dist/core/predictive-search/index.d.mts +2 -2
- package/dist/core/predictive-search/queries.d.mts +2 -2
- package/dist/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +2 -2
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/accept-variant-id.mjs +1 -1
- package/dist/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/core/request-context.d.mts +61 -35
- package/dist/core/request-context.mjs +11 -7
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +13 -2
- package/dist/core/request-routing/registered-routes.mjs +33 -9
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +18 -8
- package/dist/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +3 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +13 -11
- package/dist/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/core/shopify-scripts/index.d.mts +1 -0
- package/dist/core/shopify-scripts/index.mjs +12 -9
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/core/shopify-scripts/perfkit.mjs +8 -2
- package/dist/core/shopify-scripts/perfkit.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +4 -2
- package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/core/standard-routes/build.d.mts +7 -2
- package/dist/core/standard-routes/build.mjs +10 -3
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/match.mjs +11 -1
- package/dist/core/standard-routes/match.mjs.map +1 -1
- package/dist/core/standard-routes/path.mjs +14 -3
- package/dist/core/standard-routes/path.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +6 -1
- package/dist/core/url.mjs +5 -3
- package/dist/core/url.mjs.map +1 -1
- package/dist/core/utils/load-script.mjs +6 -6
- package/dist/core/utils/load-script.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +14 -10
- package/dist/customer-account/client.mjs +4 -5
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +7 -1
- package/dist/customer-account/graphql.mjs +6 -7
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.mjs +3 -4
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/development/client/client.mjs +45 -12
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/i18n-variables.d.mts +13 -0
- package/dist/development/client/i18n-variables.mjs +92 -0
- package/dist/development/client/i18n-variables.mjs.map +1 -0
- package/dist/development/client/types.d.mts +21 -8
- package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cart/cart.mjs +111 -24
- package/dist/development/core/cart/cart.mjs.map +1 -1
- package/dist/development/core/cart/cookie.mjs +6 -1
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +17 -5
- package/dist/development/core/cart/form.mjs +5 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/queries.d.mts +57 -57
- package/dist/development/core/collection/url.mjs +8 -1
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs +2 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/csp/index.d.mts +56 -0
- package/dist/development/core/csp/index.mjs +128 -0
- package/dist/development/core/csp/index.mjs.map +1 -0
- package/dist/development/core/csp/types.d.mts +52 -0
- package/dist/development/core/development.d.mts +14 -5
- package/dist/development/core/development.mjs +9 -2
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/i18n/define.d.mts +54 -0
- package/dist/development/core/i18n/define.mjs +135 -0
- package/dist/development/core/i18n/define.mjs.map +1 -0
- package/dist/development/core/i18n/errors.d.mts +18 -0
- package/dist/development/core/i18n/errors.mjs +24 -0
- package/dist/development/core/i18n/errors.mjs.map +1 -0
- package/dist/development/core/i18n/href.d.mts +28 -0
- package/dist/development/core/i18n/href.mjs +45 -0
- package/dist/development/core/i18n/href.mjs.map +1 -0
- package/dist/development/core/i18n/locale.d.mts +21 -0
- package/dist/development/core/i18n/locale.mjs +36 -0
- package/dist/development/core/i18n/locale.mjs.map +1 -0
- package/dist/development/core/i18n/match.d.mts +37 -0
- package/dist/development/core/i18n/match.mjs +82 -0
- package/dist/development/core/i18n/match.mjs.map +1 -0
- package/dist/development/core/i18n/types.d.mts +80 -0
- package/dist/development/core/index.d.mts +13 -4
- package/dist/development/core/predictive-search/index.d.mts +2 -2
- package/dist/development/core/predictive-search/queries.d.mts +2 -2
- package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +2 -2
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/accept-variant-id.mjs +1 -1
- package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +61 -35
- package/dist/development/core/request-context.mjs +11 -7
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +13 -2
- package/dist/development/core/request-routing/registered-routes.mjs +33 -9
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +18 -8
- package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +3 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +13 -11
- package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/development/core/shopify-scripts/index.d.mts +1 -0
- package/dist/development/core/shopify-scripts/index.mjs +12 -9
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/perfkit.mjs +8 -2
- package/dist/development/core/shopify-scripts/perfkit.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +4 -2
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/development/core/standard-routes/build.d.mts +7 -2
- package/dist/development/core/standard-routes/build.mjs +10 -3
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/match.mjs +11 -1
- package/dist/development/core/standard-routes/match.mjs.map +1 -1
- package/dist/development/core/standard-routes/path.mjs +14 -3
- package/dist/development/core/standard-routes/path.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +6 -1
- package/dist/development/core/url.mjs +5 -3
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/core/utils/load-script.mjs +6 -6
- package/dist/development/core/utils/load-script.mjs.map +1 -1
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +8 -4
- package/dist/development/graphql/type-resolver.d.mts +39 -1
- package/dist/development/react/cart.mjs +79 -25
- package/dist/development/react/cart.mjs.map +1 -1
- package/dist/development/react/index.d.mts +2 -2
- package/dist/globals.d.mts +8 -4
- package/dist/graphql/type-resolver.d.mts +39 -1
- package/dist/react/cart.mjs +79 -25
- package/dist/react/cart.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/vite/index.d.mts +11 -1
- package/dist/vite/index.mjs +21 -1
- package/dist/vite/index.mjs.map +1 -0
- package/package.json +13 -3
- package/skills/hydrogen-analytics/SKILL.md +2 -2
- package/skills/hydrogen-analytics/references/react.md +2 -2
- package/skills/hydrogen-cart-ui/SKILL.md +2 -2
- package/skills/hydrogen-markets/SKILL.md +127 -93
- package/skills/hydrogen-markets/references/nextjs.md +77 -87
- package/skills/hydrogen-oxygen/references/react-router.md +1 -2
- package/skills/hydrogen-predictive-search/SKILL.md +18 -1
- package/skills/hydrogen-request-handlers/SKILL.md +24 -6
- package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
- package/skills/hydrogen-request-handlers/references/frameworks.md +9 -12
- package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
- package/skills/hydrogen-request-handlers/references/nuxt.md +7 -7
- package/skills/hydrogen-robots-txt/SKILL.md +87 -0
- package/skills/hydrogen-routing/SKILL.md +36 -14
- package/skills/hydrogen-setup/SKILL.md +2 -2
- package/skills/hydrogen-setup/references/analytics.md +5 -5
- package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
- package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
- package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
- package/skills/hydrogen-smoke-test/SKILL.md +9 -2
- package/skills/hydrogen-storefront-client/SKILL.md +29 -9
- package/skills/hydrogen-storefront-client/references/astro.md +8 -3
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
- package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
- package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
- package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
- package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
- package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
- package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
- package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CountryCode, LanguageCode } from "../../graphql/generated/customer-account-api-types.mjs";
|
|
2
|
+
import { CountryCode as CountryCode$1, LanguageCode as LanguageCode$1 } from "../../graphql/generated/storefront-api-types.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/core/i18n/types.d.ts
|
|
5
|
+
type ShopifyLanguageCode = Extract<LanguageCode$1, LanguageCode>;
|
|
6
|
+
type ShopifyCountryCode = Extract<CountryCode$1, CountryCode>;
|
|
7
|
+
/** A `{language, country}` pair identifying one locale a storefront serves. */
|
|
8
|
+
type ShopifyLocale = {
|
|
9
|
+
language: ShopifyLanguageCode;
|
|
10
|
+
country: ShopifyCountryCode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A locale served under a URL path prefix.
|
|
14
|
+
*
|
|
15
|
+
* The prefix is derived from the locale as `/{language}-{country}` (lowercased, `_` → `-`), so
|
|
16
|
+
* `{language: "FR", country: "CA"}` is served at `/fr-ca`. Set `pathSegment` when the derived
|
|
17
|
+
* segment is undesirable, for example `PT_BR` + `BR` derives to `pt-br-br`. A segment is a single
|
|
18
|
+
* path part: no slashes.
|
|
19
|
+
*/
|
|
20
|
+
type ShopifyPathnameLocale = ShopifyLocale & {
|
|
21
|
+
pathSegment?: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A locale served from its own hostname. Match is exact on `URL.hostname` (no port), so
|
|
25
|
+
* `fr.example.com`, `example.fr`, and `example.com` are three separate entries. Aliases such as
|
|
26
|
+
* `www.` are a redirect concern and must not be listed here.
|
|
27
|
+
*/
|
|
28
|
+
type ShopifyDomainLocale = ShopifyLocale & {
|
|
29
|
+
hostname: string;
|
|
30
|
+
};
|
|
31
|
+
type ShopifyI18nRouting = {
|
|
32
|
+
type: "pathname";
|
|
33
|
+
/**
|
|
34
|
+
* Locales served under a prefix. `defaultLocale` is served unprefixed only and must not be
|
|
35
|
+
* listed here, so every page has one canonical URL.
|
|
36
|
+
*/
|
|
37
|
+
locales: readonly ShopifyPathnameLocale[];
|
|
38
|
+
} | {
|
|
39
|
+
type: "domain";
|
|
40
|
+
/**
|
|
41
|
+
* Locales served per hostname. `defaultLocale` must be listed here so it has a canonical
|
|
42
|
+
* hostname for links and sitemaps; it is also what unrecognized hosts (localhost, preview
|
|
43
|
+
* URLs) resolve to.
|
|
44
|
+
*/
|
|
45
|
+
locales: readonly ShopifyDomainLocale[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Module-scope internationalization definition shared by the server request context, route
|
|
49
|
+
* matching, URL builders, and client scripts. Create it with `defineShopifyI18n`.
|
|
50
|
+
*/
|
|
51
|
+
type ShopifyI18n = {
|
|
52
|
+
/** Locale used when routing determines nothing: unprefixed paths or unrecognized hostnames. */defaultLocale: ShopifyLocale; /** Omit for single-locale storefronts. */
|
|
53
|
+
routing?: ShopifyI18nRouting;
|
|
54
|
+
};
|
|
55
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
56
|
+
/**
|
|
57
|
+
* `TRouting` is a naked type parameter so this distributes over `ShopifyI18nRouting | undefined`.
|
|
58
|
+
* Under domain routing the default locale is one of the entries (it carries the hostname), so
|
|
59
|
+
* the raw `defaultLocale` is not part of the union there.
|
|
60
|
+
*/
|
|
61
|
+
type SupportedLocaleForRouting<TDefault, TRouting> = TRouting extends {
|
|
62
|
+
type: "domain";
|
|
63
|
+
locales: readonly (infer TLocale)[];
|
|
64
|
+
} ? TLocale : TRouting extends {
|
|
65
|
+
type: "pathname";
|
|
66
|
+
locales: readonly (infer TLocale)[];
|
|
67
|
+
} ? TDefault | TLocale : TDefault;
|
|
68
|
+
/** Every locale entry a definition can resolve to, keeping any extra per-locale fields. */
|
|
69
|
+
type ShopifySupportedLocale<TI18n extends ShopifyI18n = ShopifyI18n> = SupportedLocaleForRouting<TI18n["defaultLocale"], TI18n["routing"]>;
|
|
70
|
+
/**
|
|
71
|
+
* A locale resolved for one request. `pathSegment` is replaced by the derived `pathPrefix`
|
|
72
|
+
* (`""` for the default locale and under domain routing), which is what URL builders consume.
|
|
73
|
+
* Domain-routed locales keep their `hostname` so canonical and `hreflang` URLs can be built.
|
|
74
|
+
*/
|
|
75
|
+
type ShopifyMatchedLocale<TI18n extends ShopifyI18n = ShopifyI18n> = DistributiveOmit<ShopifySupportedLocale<TI18n>, "pathSegment"> & {
|
|
76
|
+
pathPrefix: string;
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ShopifyCountryCode, ShopifyDomainLocale, ShopifyI18n, ShopifyI18nRouting, ShopifyLanguageCode, ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale, ShopifySupportedLocale };
|
|
80
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { Cache, CacheOptions, CachingStrategy } from "./cache/strategies.mjs";
|
|
2
2
|
import { CacheInstance, createRunWithCache } from "./cache/run-with-cache.mjs";
|
|
3
3
|
import { ProductCollectionSortKeys } from "../graphql/generated/storefront-api-types.mjs";
|
|
4
|
+
import { ShopifyCountryCode, ShopifyDomainLocale, ShopifyI18n, ShopifyI18nRouting, ShopifyLanguageCode, ShopifyLocale, ShopifyMatchedLocale, ShopifyPathnameLocale, ShopifySupportedLocale } from "./i18n/types.mjs";
|
|
4
5
|
import { I18nConfig, ShopifyRequestContext, ShopifyRequestContextWithBuyerIp, createShopifyRequestContext } from "./request-context.mjs";
|
|
5
6
|
import { InferResult, InferVariables } from "../graphql/type-resolver.mjs";
|
|
6
7
|
import { AnyStorefrontQueryString, StorefrontQueryString, gql } from "../graphql/graphql.mjs";
|
|
7
8
|
import { ClientType, CreateStorefrontClientArgs, GqlRestParam, GraphQLFormattedError, PrivateClientOptions, PrivateNoBuyerContextClientOptions, PrivateNoBuyerContextStorefrontClient, PrivateStorefrontClient, PublicClientOptions, PublicStorefrontClient, RequestScopedPrivateStorefrontClient, StorefrontApi, StorefrontClient, StorefrontClientOptions, StorefrontGraphql, StorefrontGraphqlOptions, StorefrontGraphqlResult } from "../client/types.mjs";
|
|
8
9
|
import { createStorefrontClient } from "../client/client.mjs";
|
|
9
10
|
import { ShopifyRouteTemplates } from "./standard-routes/types.mjs";
|
|
10
|
-
import { createShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
11
|
+
import { createShopifyRouteTemplates, defineShopifyRouteTemplates } from "./standard-routes/build.mjs";
|
|
11
12
|
import { RedirectOptions, handleShopifyRedirects } from "./request-routing/handle-shopify-redirects.mjs";
|
|
13
|
+
import { defineShopifyI18n, getSupportedLocales } from "./i18n/define.mjs";
|
|
14
|
+
import { UnsupportedLocaleError } from "./i18n/errors.mjs";
|
|
15
|
+
import { GetLocalizedHrefOptions, getLocalizedHref } from "./i18n/href.mjs";
|
|
16
|
+
import { getLocalePathSegment, isSameLocale } from "./i18n/locale.mjs";
|
|
17
|
+
import { LocaleMatchSource, matchLocale, resolveSupportedLocale } from "./i18n/match.mjs";
|
|
12
18
|
import { CallableRouteHandler, ShopifyRedirectStatus, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteHandler, ShopifyRouteHandlerContext, ShopifyRouteHandlerGroup, ShopifyRouteHandlerResult, ShopifyRouteJsonResult, ShopifyRouteRedirectResult } from "./request-routing/route-types.mjs";
|
|
13
19
|
import { createShopifyRouteHandler } from "./request-routing/registered-routes.mjs";
|
|
20
|
+
import { ContentSecurityPolicy, ContentSecurityPolicyDirectives, ContentSecurityPolicyShop, CreateContentSecurityPolicyOptions } from "./csp/types.mjs";
|
|
21
|
+
import { createContentSecurityPolicy, getShopifyCspDirectives } from "./csp/index.mjs";
|
|
14
22
|
import { createFetchWithCache } from "./cache/fetch-with-cache.mjs";
|
|
15
23
|
import { StorefrontApiError, StorefrontTimeoutError } from "../client/errors.mjs";
|
|
16
24
|
import { ProductFilter } from "../vendor/standard-events.mjs";
|
|
@@ -21,7 +29,7 @@ import { AnalyticsEvent, AnalyticsEventName } from "./analytics/events.mjs";
|
|
|
21
29
|
import { ShopifyGlobal } from "../globals.mjs";
|
|
22
30
|
import { ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop } from "./shopify-scripts/types.mjs";
|
|
23
31
|
import { AnalyticsCart, AnalyticsCartLine, AnalyticsEventMap, AnalyticsTrackingValues, CartLineUpdatePayload, CartUpdatePayload, CartViewPayload, CollectionViewPayload, ConsentConfig, ConsentPreferences, ConsentSetup, OtherData, PageViewPayload, PayloadFor, ProductPayload, ProductViewPayload, SearchViewPayload, ShopAnalytics, StorefrontAnalytics, StorefrontAnalyticsConfig, StorefrontAnalyticsDestination, StorefrontAnalyticsDestinationEventContext, StorefrontAnalyticsDestinationSetupContext } from "./analytics/types.mjs";
|
|
24
|
-
import { CartFormRegister, QuantityInputAttributes, SetButtonAttributes, createCartFormRegister } from "./cart/form.mjs";
|
|
32
|
+
import { CartFormRegister, QuantityInputAttributes, RemoveButtonAttributes, SetButtonAttributes, createCartFormRegister } from "./cart/form.mjs";
|
|
25
33
|
import { attachQuantityInput } from "./cart/attach-quantity-input.mjs";
|
|
26
34
|
import { CartAction, CartAttributeInput, CartLineAddInput, CartLineUpdateInput, parseCartRequest } from "./cart/actions.mjs";
|
|
27
35
|
import { cartQueries } from "./cart/queries.mjs";
|
|
@@ -29,6 +37,7 @@ import { createCartCookie } from "./cart/cookie.mjs";
|
|
|
29
37
|
import { CartDataFromQuery, CartResult, getCart, getCartId } from "./cart/get-cart.mjs";
|
|
30
38
|
import { CartDataFromHandlers, CartError, CartErrorCode, CartGetData, CartGetHandler, CartGetResult, CartPostHandler, CartPostResult, CartServerHandlers, CartServerHandlersWithCustomerSession, CreateCartServerHandlersOptions, createCartServerHandlers } from "./cart/server-handlers.mjs";
|
|
31
39
|
import { DEFAULT_MINIMUM_QUANTITY, NO_QUANTITY_LIMIT, sanitizeQuantity } from "./cart/quantity.mjs";
|
|
40
|
+
import { getShopifyScriptHashes } from "./shopify-scripts/hashes.mjs";
|
|
32
41
|
import { initializeShopifyScripts } from "./shopify-scripts/initialize.mjs";
|
|
33
42
|
import { getShopifyScriptTags, renderShopifyScriptTags } from "./shopify-scripts/index.mjs";
|
|
34
43
|
import { AvailableFilter, AvailableFilterValue, CollectionState, FilterPresentation, FilterType, createInitialCollectionState } from "./collection/state.mjs";
|
|
@@ -44,9 +53,9 @@ import { SHOP_PAY_BUTTON_TAG_NAME, ShopPayButtonOptions, createShopPayButton, de
|
|
|
44
53
|
import { PredictiveSearchFormAttributes, PredictiveSearchFormRegister, PredictiveSearchQueryInputAttributes, createPredictiveSearchFormRegister, getPredictiveSearchFormAttributes, readPredictiveSearchFormTerm } from "./predictive-search/form.mjs";
|
|
45
54
|
import { CreatePredictiveSearchQueriesOptions, PredictiveSearchFragments, makePredictiveSearchQueries } from "./predictive-search/queries.mjs";
|
|
46
55
|
import { PredictiveSearchData, QueryPredictiveSearchOptions, queryPredictiveSearch } from "./predictive-search/search.mjs";
|
|
47
|
-
import { CreatePredictiveSearchServerHandlersOptions, createPredictiveSearchServerHandlers } from "./predictive-search/server-handlers.mjs";
|
|
56
|
+
import { CreatePredictiveSearchServerHandlersOptions, PredictiveSearchDataFromHandlers, createPredictiveSearchServerHandlers } from "./predictive-search/server-handlers.mjs";
|
|
48
57
|
import { CreatePredictiveSearchStoreOptions, PredictiveSearchActions, PredictiveSearchState, PredictiveSearchStatus, PredictiveSearchStore, createPredictiveSearchStore } from "./predictive-search/store.mjs";
|
|
49
|
-
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, getPredictiveSearchItemUrl, getSearchResultUrl } from "./predictive-search/url.mjs";
|
|
58
|
+
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, SearchResultUrlOptions, getPredictiveSearchItemUrl, getSearchResultUrl } from "./predictive-search/url.mjs";
|
|
50
59
|
import { FormatMoneyOptions, FormattedMoney, FormattedMoneyRange, MoneyV2 } from "./money/types.mjs";
|
|
51
60
|
import { formatMoney } from "./money/format.mjs";
|
|
52
61
|
import { flattenConnection } from "./analytics/utils/flatten-connection.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PredictiveSearchFormAttributes, PredictiveSearchFormRegister, PredictiveSearchQueryInputAttributes, createPredictiveSearchFormRegister, getPredictiveSearchFormAttributes, readPredictiveSearchFormTerm } from "./form.mjs";
|
|
2
2
|
import { CreatePredictiveSearchQueriesOptions, PredictiveSearchFragments, makePredictiveSearchQueries, predictiveSearchQueries } from "./queries.mjs";
|
|
3
3
|
import { PredictiveSearchData, PredictiveSearchDataForOptions, QueryPredictiveSearchOptions, queryPredictiveSearch } from "./search.mjs";
|
|
4
|
-
import { CreatePredictiveSearchServerHandlersOptions, createPredictiveSearchServerHandlers } from "./server-handlers.mjs";
|
|
4
|
+
import { CreatePredictiveSearchServerHandlersOptions, PredictiveSearchDataFromHandlers, createPredictiveSearchServerHandlers } from "./server-handlers.mjs";
|
|
5
5
|
import { CreatePredictiveSearchStoreOptions, PredictiveSearchActions, PredictiveSearchState, PredictiveSearchStatus, PredictiveSearchStore, createPredictiveSearchStore } from "./store.mjs";
|
|
6
|
-
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, getPredictiveSearchItemUrl, getSearchResultUrl } from "./url.mjs";
|
|
6
|
+
import { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, SearchResultUrlOptions, getPredictiveSearchItemUrl, getSearchResultUrl } from "./url.mjs";
|
|
@@ -73,8 +73,8 @@ declare const PREDICTIVE_SEARCH_QUERY: StorefrontQueryString<{
|
|
|
73
73
|
term: string;
|
|
74
74
|
limitScope?: "ALL" | "EACH" | null | undefined;
|
|
75
75
|
limit?: number | null | undefined;
|
|
76
|
-
language?: "ID" | "AF" | "
|
|
77
|
-
country?: "ID" | "AF" | "
|
|
76
|
+
language?: "ID" | "AF" | "DZ" | "AR" | "AM" | "AZ" | "BS" | "BE" | "BM" | "BO" | "BR" | "BN" | "BG" | "CA" | "KY" | "KM" | "HR" | "CU" | "CY" | "SV" | "EE" | "ET" | "FO" | "FI" | "FR" | "GA" | "DE" | "GL" | "GD" | "HU" | "IS" | "IT" | "KI" | "KW" | "LA" | "LV" | "LB" | "LT" | "LU" | "MO" | "MG" | "MY" | "ML" | "MT" | "MR" | "MN" | "MS" | "NL" | "NE" | "MK" | "NO" | "OM" | "PS" | "PA" | "PL" | "PT" | "RO" | "RU" | "RW" | "SH" | "KN" | "SA" | "SN" | "SC" | "SL" | "SG" | "SK" | "SI" | "SO" | "ES" | "SD" | "SR" | "SE" | "TH" | "TG" | "TK" | "TO" | "TT" | "TA" | "TR" | "UG" | "UZ" | "AK" | "AS" | "CE" | "CKB" | "CS" | "DA" | "EL" | "EN" | "EO" | "EU" | "FA" | "FF" | "FIL" | "FY" | "GU" | "GV" | "HA" | "HE" | "HI" | "HY" | "IA" | "IG" | "II" | "JA" | "JV" | "KA" | "KK" | "KL" | "KO" | "KS" | "KU" | "LG" | "LN" | "LO" | "MI" | "NB" | "ND" | "NN" | "OR" | "OS" | "PT_BR" | "PT_PT" | "QU" | "RM" | "RN" | "SQ" | "SU" | "SW" | "TE" | "TI" | "UK" | "UR" | "VI" | "WO" | "XH" | "YI" | "YO" | "ZH_CN" | "ZH_TW" | "ZU" | "ZH" | "VO" | null | undefined;
|
|
77
|
+
country?: "ID" | "AF" | "AX" | "AL" | "DZ" | "AD" | "AO" | "AI" | "AG" | "AR" | "AM" | "AW" | "AC" | "AU" | "AT" | "AZ" | "BS" | "BH" | "BD" | "BB" | "BY" | "BE" | "BZ" | "BJ" | "BM" | "BT" | "BO" | "BA" | "BW" | "BV" | "BR" | "IO" | "BN" | "BG" | "BF" | "BI" | "KH" | "CA" | "CV" | "BQ" | "KY" | "CF" | "TD" | "CL" | "CN" | "CX" | "CC" | "CO" | "KM" | "CG" | "CD" | "CK" | "CR" | "HR" | "CU" | "CW" | "CY" | "CZ" | "CI" | "DK" | "DJ" | "DM" | "DO" | "EC" | "EG" | "SV" | "GQ" | "ER" | "EE" | "SZ" | "ET" | "FK" | "FO" | "FJ" | "FI" | "FR" | "GF" | "PF" | "TF" | "GA" | "GM" | "GE" | "DE" | "GH" | "GI" | "GR" | "GL" | "GD" | "GP" | "GT" | "GG" | "GN" | "GW" | "GY" | "HT" | "HM" | "VA" | "HN" | "HK" | "HU" | "IS" | "IN" | "IR" | "IQ" | "IE" | "IM" | "IL" | "IT" | "JM" | "JP" | "JE" | "JO" | "KZ" | "KE" | "KI" | "KP" | "XK" | "KW" | "KG" | "LA" | "LV" | "LB" | "LS" | "LR" | "LY" | "LI" | "LT" | "LU" | "MO" | "MG" | "MW" | "MY" | "MV" | "ML" | "MT" | "MQ" | "MR" | "MU" | "YT" | "MX" | "MD" | "MC" | "MN" | "ME" | "MS" | "MA" | "MZ" | "MM" | "NA" | "NR" | "NP" | "NL" | "AN" | "NC" | "NZ" | "NI" | "NE" | "NG" | "NU" | "NF" | "MK" | "NO" | "OM" | "PK" | "PS" | "PA" | "PG" | "PY" | "PE" | "PH" | "PN" | "PL" | "PT" | "QA" | "CM" | "RE" | "RO" | "RU" | "RW" | "BL" | "SH" | "KN" | "LC" | "MF" | "PM" | "WS" | "SM" | "ST" | "SA" | "SN" | "RS" | "SC" | "SL" | "SG" | "SX" | "SK" | "SI" | "SB" | "SO" | "ZA" | "GS" | "KR" | "SS" | "ES" | "LK" | "VC" | "SD" | "SR" | "SJ" | "SE" | "CH" | "SY" | "TW" | "TJ" | "TZ" | "TH" | "TL" | "TG" | "TK" | "TO" | "TT" | "TA" | "TN" | "TR" | "TM" | "TC" | "TV" | "UG" | "UA" | "AE" | "GB" | "US" | "UM" | "UY" | "UZ" | "VU" | "VE" | "VN" | "VG" | "WF" | "EH" | "YE" | "ZM" | "ZW" | "ZZ" | null | undefined;
|
|
78
78
|
}, "query PredictiveSearch(\n $country: CountryCode\n $language: LanguageCode\n $limit: Int\n $limitScope: PredictiveSearchLimitScope\n $term: String!\n $types: [PredictiveSearchType!]\n $searchableFields: [SearchableField!]\n $unavailableProducts: SearchUnavailableProductsType\n ) @inContext(country: $country, language: $language) {\n predictiveSearch(\n limit: $limit\n limitScope: $limitScope\n query: $term\n types: $types\n searchableFields: $searchableFields\n unavailableProducts: $unavailableProducts\n ) {\n articles {\n ...HydrogenPredictiveSearchArticleFragment\n ...PredictiveSearchArticleFragment\n }\n collections {\n ...HydrogenPredictiveSearchCollectionFragment\n ...PredictiveSearchCollectionFragment\n }\n pages {\n ...HydrogenPredictiveSearchPageFragment\n ...PredictiveSearchPageFragment\n }\n products {\n ...HydrogenPredictiveSearchProductFragment\n ...PredictiveSearchProductFragment\n }\n queries {\n ...HydrogenPredictiveSearchQueryFragment\n ...PredictiveSearchQueryFragment\n }\n }\n }\n\n fragment HydrogenPredictiveSearchProductFragment on Product {\n __typename\n id\n title\n handle\n trackingParameters\n selectedOrFirstAvailableVariant(\n selectedOptions: []\n ignoreUnknownOptions: true\n caseInsensitiveMatch: true\n ) {\n id\n image {\n url\n altText\n width\n height\n }\n price {\n amount\n currencyCode\n }\n }\n }\n\n\n fragment HydrogenPredictiveSearchCollectionFragment on Collection {\n __typename\n id\n title\n handle\n image {\n url\n altText\n width\n height\n }\n trackingParameters\n }\n\n\n fragment HydrogenPredictiveSearchPageFragment on Page {\n __typename\n id\n title\n handle\n trackingParameters\n }\n\n\n fragment HydrogenPredictiveSearchArticleFragment on Article {\n __typename\n id\n title\n handle\n blog {\n handle\n }\n image {\n url\n altText\n width\n height\n }\n trackingParameters\n }\n\n\n fragment HydrogenPredictiveSearchQueryFragment on SearchQuerySuggestion {\n __typename\n text\n styledText\n trackingParameters\n }\n">;
|
|
79
79
|
declare const DEFAULT_PRODUCT_FRAGMENT: StorefrontQueryString<{
|
|
80
80
|
id: string;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { PredictiveSearchLimitScope, PredictiveSearchType, SearchUnavailableProductsType, SearchableField } from "../../graphql/generated/storefront-api-types.mjs";
|
|
2
2
|
import { CallableRouteHandler, ShopifyRouteError, ShopifyRouteErrorResult, ShopifyRouteJsonResult } from "../request-routing/route-types.mjs";
|
|
3
|
-
import { CreatePredictiveSearchQueriesOptions
|
|
4
|
-
import { PredictiveSearchDataForOptions, QueryPredictiveSearchOptions } from "./search.mjs";
|
|
3
|
+
import { CreatePredictiveSearchQueriesOptions } from "./queries.mjs";
|
|
4
|
+
import { PredictiveSearchData, PredictiveSearchDataForOptions, QueryPredictiveSearchOptions } from "./search.mjs";
|
|
5
5
|
import { PREDICTIVE_SEARCH_GET_METHOD } from "./constants.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/core/predictive-search/server-handlers.d.ts
|
|
8
|
-
declare const predictiveSearchServerHandlersQuery: unique symbol;
|
|
9
8
|
type PredictiveSearchHandlerContext = {
|
|
10
9
|
request: Request;
|
|
11
10
|
storefrontClient: QueryPredictiveSearchOptions["storefrontClient"];
|
|
@@ -20,9 +19,31 @@ type PredictiveSearchError = ShopifyRouteError & {
|
|
|
20
19
|
type PredictiveSearchGetHandler<TData = PredictiveSearchDataForOptions<{}>> = CallableRouteHandler<PredictiveSearchHandlerContext, PredictiveSearchGetResult<TData>, string, typeof PREDICTIVE_SEARCH_GET_METHOD>;
|
|
21
20
|
/** Predictive search route handlers to pass to `handleShopifyRoutes`. */
|
|
22
21
|
type PredictiveSearchServerHandlers<TOptions extends CreatePredictiveSearchServerHandlersOptions = {}, TData = PredictiveSearchDataForOptions<TOptions>> = {
|
|
23
|
-
/**
|
|
24
|
-
get: PredictiveSearchGetHandler<TData>;
|
|
22
|
+
/** Answers GET requests with predictive search results as JSON. */get: PredictiveSearchGetHandler<TData>;
|
|
25
23
|
};
|
|
24
|
+
type AsyncHandlerResult<THandler> = THandler extends ((...args: infer _Args) => Promise<infer TResult>) ? TResult : never;
|
|
25
|
+
type JsonResultData<TResult> = TResult extends {
|
|
26
|
+
type: "json";
|
|
27
|
+
data: {
|
|
28
|
+
items: infer TItems;
|
|
29
|
+
};
|
|
30
|
+
} ? PredictiveSearchData<TItems> : never;
|
|
31
|
+
/**
|
|
32
|
+
* Infers the {@link PredictiveSearchData} shape returned by handlers from {@link createPredictiveSearchServerHandlers}.
|
|
33
|
+
*
|
|
34
|
+
* Pass it as the type argument to `usePredictiveSearch` so client state includes the handlers' custom fragment fields.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* type SearchData = PredictiveSearchDataFromHandlers<typeof predictiveSearchHandlers>;
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
type PredictiveSearchDataFromHandlers<THandlers extends {
|
|
42
|
+
get: (context: never) => Promise<{
|
|
43
|
+
type: string;
|
|
44
|
+
data?: PredictiveSearchData<unknown>;
|
|
45
|
+
}>;
|
|
46
|
+
}> = JsonResultData<AsyncHandlerResult<THandlers["get"]>>;
|
|
26
47
|
/**
|
|
27
48
|
* Route path, custom fragments, and default search settings for the predictive search route.
|
|
28
49
|
*
|
|
@@ -57,5 +78,5 @@ interface CreatePredictiveSearchServerHandlersOptions extends CreatePredictiveSe
|
|
|
57
78
|
declare function createPredictiveSearchServerHandlers(): PredictiveSearchServerHandlers;
|
|
58
79
|
declare function createPredictiveSearchServerHandlers<const TOptions extends CreatePredictiveSearchServerHandlersOptions>(options: TOptions): PredictiveSearchServerHandlers<TOptions>;
|
|
59
80
|
//#endregion
|
|
60
|
-
export { CreatePredictiveSearchServerHandlersOptions, createPredictiveSearchServerHandlers };
|
|
81
|
+
export { CreatePredictiveSearchServerHandlersOptions, PredictiveSearchDataFromHandlers, createPredictiveSearchServerHandlers };
|
|
61
82
|
//# sourceMappingURL=server-handlers.d.mts.map
|
|
@@ -5,7 +5,6 @@ import { makePredictiveSearchQueries, predictiveSearchQueries } from "./queries.
|
|
|
5
5
|
import { DEFAULT_PREDICTIVE_SEARCH_LIMIT_SCOPE, DEFAULT_PREDICTIVE_SEARCH_UNAVAILABLE_PRODUCTS, fetchPredictiveSearch } from "./search.mjs";
|
|
6
6
|
|
|
7
7
|
//#region src/core/predictive-search/server-handlers.ts
|
|
8
|
-
const predictiveSearchServerHandlersQuery = Symbol("hydrogen.predictiveSearchQuery");
|
|
9
8
|
const VALID_LIMIT_SCOPES = ["ALL", "EACH"];
|
|
10
9
|
const VALID_PREDICTIVE_SEARCH_TYPES = [
|
|
11
10
|
"ARTICLE",
|
|
@@ -36,9 +35,7 @@ const VALID_UNAVAILABLE_PRODUCTS = [
|
|
|
36
35
|
*/
|
|
37
36
|
function createPredictiveSearchServerHandlers(options = {}) {
|
|
38
37
|
const queries = options.fragments ? makePredictiveSearchQueries(options) : predictiveSearchQueries;
|
|
39
|
-
|
|
40
|
-
Object.defineProperty(handlers, predictiveSearchServerHandlersQuery, { value: queries.predictiveSearch });
|
|
41
|
-
return handlers;
|
|
38
|
+
return { get: createCallableRouteHandler(options.path ?? "/api/predictive-search", "GET", (context) => handleGet(context, options, queries)) };
|
|
42
39
|
}
|
|
43
40
|
async function handleGet({ request, storefrontClient }, options, queries) {
|
|
44
41
|
let searchOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-handlers.mjs","names":[],"sources":["../../../../src/core/predictive-search/server-handlers.ts"],"sourcesContent":["import type {\n PredictiveSearchLimitScope,\n PredictiveSearchType,\n SearchUnavailableProductsType,\n SearchableField,\n} from \"../../graphql/generated/storefront-api-types\";\nimport { createProxyResponseHeaders } from \"../request-routing/interceptors/proxy\";\nimport type {\n CallableRouteHandler,\n ShopifyRouteError,\n ShopifyRouteErrorResult,\n ShopifyRouteJsonResult,\n} from \"../request-routing/registered-routes\";\nimport { createCallableRouteHandler } from \"../request-routing/registered-routes\";\nimport { PREDICTIVE_SEARCH_API_PATH, PREDICTIVE_SEARCH_GET_METHOD } from \"./constants\";\nimport {\n makePredictiveSearchQueries,\n predictiveSearchQueries,\n type CreatePredictiveSearchQueriesOptions,\n type PredictiveSearchQueriesForOptions,\n} from \"./queries\";\nimport {\n DEFAULT_PREDICTIVE_SEARCH_LIMIT,\n DEFAULT_PREDICTIVE_SEARCH_LIMIT_SCOPE,\n DEFAULT_PREDICTIVE_SEARCH_UNAVAILABLE_PRODUCTS,\n fetchPredictiveSearch,\n type PredictiveSearchDataForOptions,\n type QueryPredictiveSearchOptions,\n} from \"./search\";\n\nconst predictiveSearchServerHandlersQuery: unique symbol = Symbol(\"hydrogen.predictiveSearchQuery\");\n\nconst VALID_LIMIT_SCOPES: readonly PredictiveSearchLimitScope[] = [\"ALL\", \"EACH\"];\nconst VALID_PREDICTIVE_SEARCH_TYPES: readonly PredictiveSearchType[] = [\n \"ARTICLE\",\n \"COLLECTION\",\n \"PAGE\",\n \"PRODUCT\",\n \"QUERY\",\n];\nconst VALID_SEARCHABLE_FIELDS: readonly SearchableField[] = [\n \"AUTHOR\",\n \"BODY\",\n \"PRODUCT_TYPE\",\n \"TAG\",\n \"TITLE\",\n \"VARIANTS_BARCODE\",\n \"VARIANTS_SKU\",\n \"VARIANTS_TITLE\",\n \"VENDOR\",\n];\nconst VALID_UNAVAILABLE_PRODUCTS: readonly SearchUnavailableProductsType[] = [\n \"HIDE\",\n \"LAST\",\n \"SHOW\",\n];\n\ntype PredictiveSearchHandlerContext = {\n request: Request;\n storefrontClient: QueryPredictiveSearchOptions[\"storefrontClient\"];\n};\n\ntype PredictiveSearchGetData<TData = PredictiveSearchDataForOptions<{}>> = TData;\ntype PredictiveSearchGetResult<TData = PredictiveSearchDataForOptions<{}>> =\n | ShopifyRouteJsonResult<PredictiveSearchGetData<TData>>\n | ShopifyRouteErrorResult<PredictiveSearchError>;\n\ntype PredictiveSearchErrorCode = \"invalid_predictive_search_request\";\ntype PredictiveSearchError = ShopifyRouteError & {\n code: PredictiveSearchErrorCode;\n};\n\n/** GET route handler that returns predictive search results or an error. */\ntype PredictiveSearchGetHandler<TData = PredictiveSearchDataForOptions<{}>> = CallableRouteHandler<\n PredictiveSearchHandlerContext,\n PredictiveSearchGetResult<TData>,\n string,\n typeof PREDICTIVE_SEARCH_GET_METHOD\n>;\n\n/** Predictive search route handlers to pass to `handleShopifyRoutes`. */\ntype PredictiveSearchServerHandlers<\n TOptions extends CreatePredictiveSearchServerHandlersOptions = {},\n TData = PredictiveSearchDataForOptions<TOptions>,\n> = {\n /** Query that the handlers run, with any custom fragments. */\n readonly [predictiveSearchServerHandlersQuery]: PredictiveSearchQueriesForOptions<TOptions>[\"predictiveSearch\"];\n /** Answers GET requests with predictive search results as JSON. */\n get: PredictiveSearchGetHandler<TData>;\n};\n\n/**\n * Route path, custom fragments, and default search settings for the predictive search route.\n *\n * A request overrides a default search setting with a URL parameter of the same name.\n */\nexport interface CreatePredictiveSearchServerHandlersOptions extends CreatePredictiveSearchQueriesOptions {\n /** Route path that the GET handler serves. Defaults to `/api/predictive-search`. */\n path?: string;\n /** Default maximum number of results, from 1 to 10. Applies when a request has no numeric `limit` parameter. Predictive search clamps other values to that range. Defaults to `5`. */\n limit?: number;\n /** Default limit scope. Defaults to `EACH`. */\n limitScope?: PredictiveSearchLimitScope;\n /** Default result types. A request can set `types` to a comma-separated list. */\n types?: PredictiveSearchType[];\n /** Default fields to search. A request can set `searchableFields` to a comma-separated list. */\n searchableFields?: SearchableField[];\n /** Default handling of unavailable products. Defaults to `HIDE`. */\n unavailableProducts?: SearchUnavailableProductsType;\n}\n\n/**\n * Creates the route that answers predictive search requests from the browser.\n * Register the handlers with `handleShopifyRoutes`. The default route path matches\n * the default endpoint of `createPredictiveSearchStore` and `PredictiveSearchProvider`.\n *\n * The route reads the search term from the `q` URL parameter. A URL parameter with the same name as a search setting overrides the setting's default.\n *\n * An invalid setting value or a failed Storefront API query returns HTTP status `400` with a JSON body of `{error: {code, message}}`. The `code` value is `invalid_predictive_search_request`.\n * A successful response forwards the Storefront API response headers except the content encoding, content length, and server timing headers.\n *\n * @publicDocs\n */\nexport function createPredictiveSearchServerHandlers(): PredictiveSearchServerHandlers;\nexport function createPredictiveSearchServerHandlers<\n const TOptions extends CreatePredictiveSearchServerHandlersOptions,\n>(options: TOptions): PredictiveSearchServerHandlers<TOptions>;\n/**\n * @param options Route path, custom fragments, and default search settings for the route.\n * @returns Route handlers to pass to `handleShopifyRoutes`.\n */\nexport function createPredictiveSearchServerHandlers(\n options: CreatePredictiveSearchServerHandlersOptions = {},\n): PredictiveSearchServerHandlers<CreatePredictiveSearchServerHandlersOptions> {\n const queries = options.fragments\n ? makePredictiveSearchQueries(options)\n : predictiveSearchQueries;\n const handler = createCallableRouteHandler(\n options.path ?? PREDICTIVE_SEARCH_API_PATH,\n PREDICTIVE_SEARCH_GET_METHOD,\n (context: PredictiveSearchHandlerContext) => handleGet(context, options, queries),\n );\n const handlers = {\n get: handler,\n } as PredictiveSearchServerHandlers<CreatePredictiveSearchServerHandlersOptions>;\n\n Object.defineProperty(handlers, predictiveSearchServerHandlersQuery, {\n value: queries.predictiveSearch,\n });\n return handlers;\n}\n\nasync function handleGet(\n { request, storefrontClient }: PredictiveSearchHandlerContext,\n options: CreatePredictiveSearchServerHandlersOptions,\n queries: PredictiveSearchQueriesForOptions<CreatePredictiveSearchServerHandlersOptions>,\n): Promise<PredictiveSearchGetResult> {\n let searchOptions: ParsedPredictiveSearchRequest;\n try {\n searchOptions = parsePredictiveSearchRequest(request, options);\n } catch (error) {\n return errorResult(getErrorMessage(error, \"Invalid predictive search request\"));\n }\n\n try {\n const result = await fetchPredictiveSearch({\n storefrontClient,\n query: queries.predictiveSearch,\n ...searchOptions,\n });\n return {\n type: \"json\",\n data: result.data,\n headers: createProxyResponseHeaders(result.headers),\n };\n } catch (error) {\n return errorResult(getErrorMessage(error, \"Predictive search request failed\"));\n }\n}\n\ntype ParsedPredictiveSearchRequest = Omit<\n QueryPredictiveSearchOptions,\n \"storefrontClient\" | \"query\" | \"signal\"\n>;\n\nfunction parsePredictiveSearchRequest(\n request: Request,\n options: CreatePredictiveSearchServerHandlersOptions,\n): ParsedPredictiveSearchRequest {\n const searchParams = new URL(request.url).searchParams;\n return {\n term: searchParams.get(\"q\") ?? \"\",\n limit: parseLimit(searchParams, options),\n limitScope:\n parseOne(searchParams, \"limitScope\", VALID_LIMIT_SCOPES) ??\n options.limitScope ??\n DEFAULT_PREDICTIVE_SEARCH_LIMIT_SCOPE,\n types: parseMany(searchParams, \"types\", VALID_PREDICTIVE_SEARCH_TYPES) ?? options.types,\n searchableFields:\n parseMany(searchParams, \"searchableFields\", VALID_SEARCHABLE_FIELDS) ??\n options.searchableFields,\n unavailableProducts:\n parseOne(searchParams, \"unavailableProducts\", VALID_UNAVAILABLE_PRODUCTS) ??\n options.unavailableProducts ??\n DEFAULT_PREDICTIVE_SEARCH_UNAVAILABLE_PRODUCTS,\n };\n}\n\n// Invalid enum params return a typed error, but an unparseable limit falls back to the configured default.\nfunction parseLimit(\n searchParams: URLSearchParams,\n options: CreatePredictiveSearchServerHandlersOptions,\n): number {\n const defaultLimit = options.limit ?? DEFAULT_PREDICTIVE_SEARCH_LIMIT;\n const rawLimit = searchParams.get(\"limit\")?.trim() ?? \"\";\n if (rawLimit === \"\") return defaultLimit;\n\n const limit = Number(rawLimit);\n return Number.isFinite(limit) ? limit : defaultLimit;\n}\n\nfunction parseOne<TValue extends string>(\n searchParams: URLSearchParams,\n name: string,\n allowedValues: readonly TValue[],\n): TValue | undefined {\n const value = searchParams.get(name);\n if (value === null || value === \"\") return undefined;\n if (isAllowedValue(value, allowedValues)) return value;\n throw new Error(`Invalid ${name} value \"${value}\".`);\n}\n\nfunction parseMany<TValue extends string>(\n searchParams: URLSearchParams,\n name: string,\n allowedValues: readonly TValue[],\n): TValue[] | undefined {\n const values = splitParamValues(searchParams, name);\n if (values.length === 0) return undefined;\n return values.map((value) => parseAllowedValue(name, value, allowedValues));\n}\n\nfunction splitParamValues(searchParams: URLSearchParams, name: string): string[] {\n return searchParams\n .getAll(name)\n .flatMap((value) => value.split(\",\"))\n .map((value) => value.trim())\n .filter(Boolean);\n}\n\nfunction parseAllowedValue<TValue extends string>(\n name: string,\n value: string,\n allowedValues: readonly TValue[],\n): TValue {\n if (isAllowedValue(value, allowedValues)) return value;\n throw new Error(`Invalid ${name} value \"${value}\".`);\n}\n\nfunction isAllowedValue<TValue extends string>(\n value: string,\n allowedValues: readonly TValue[],\n): value is TValue {\n return allowedValues.some((allowedValue) => allowedValue === value);\n}\n\nfunction errorResult(message: string): ShopifyRouteErrorResult<PredictiveSearchError> {\n return {\n type: \"error\",\n error: {\n code: \"invalid_predictive_search_request\",\n message,\n },\n };\n}\n\nfunction getErrorMessage(error: unknown, fallback: string): string {\n return error instanceof Error ? error.message : fallback;\n}\n"],"mappings":";;;;;;;AA8BA,MAAM,sCAAqD,OAAO,iCAAiC;AAEnG,MAAM,qBAA4D,CAAC,OAAO,OAAO;AACjF,MAAM,gCAAiE;CACrE;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,0BAAsD;CAC1D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,6BAAuE;CAC3E;CACA;CACA;CACD;;;;;AA4ED,SAAgB,qCACd,UAAuD,EAAE,EACoB;CAC7E,MAAM,UAAU,QAAQ,YACpB,4BAA4B,QAAQ,GACpC;CAMJ,MAAM,WAAW,EACf,KANc,2BACd,QAAQ,0CAEP,YAA4C,UAAU,SAAS,SAAS,QAAQ,CAGrE,EACb;AAED,QAAO,eAAe,UAAU,qCAAqC,EACnE,OAAO,QAAQ,kBAChB,CAAC;AACF,QAAO;;AAGT,eAAe,UACb,EAAE,SAAS,oBACX,SACA,SACoC;CACpC,IAAI;AACJ,KAAI;AACF,kBAAgB,6BAA6B,SAAS,QAAQ;UACvD,OAAO;AACd,SAAO,YAAY,gBAAgB,OAAO,oCAAoC,CAAC;;AAGjF,KAAI;EACF,MAAM,SAAS,MAAM,sBAAsB;GACzC;GACA,OAAO,QAAQ;GACf,GAAG;GACJ,CAAC;AACF,SAAO;GACL,MAAM;GACN,MAAM,OAAO;GACb,SAAS,2BAA2B,OAAO,QAAQ;GACpD;UACM,OAAO;AACd,SAAO,YAAY,gBAAgB,OAAO,mCAAmC,CAAC;;;AASlF,SAAS,6BACP,SACA,SAC+B;CAC/B,MAAM,eAAe,IAAI,IAAI,QAAQ,IAAI,CAAC;AAC1C,QAAO;EACL,MAAM,aAAa,IAAI,IAAI,IAAI;EAC/B,OAAO,WAAW,cAAc,QAAQ;EACxC,YACE,SAAS,cAAc,cAAc,mBAAmB,IACxD,QAAQ;EAEV,OAAO,UAAU,cAAc,SAAS,8BAA8B,IAAI,QAAQ;EAClF,kBACE,UAAU,cAAc,oBAAoB,wBAAwB,IACpE,QAAQ;EACV,qBACE,SAAS,cAAc,uBAAuB,2BAA2B,IACzE,QAAQ;EAEX;;AAIH,SAAS,WACP,cACA,SACQ;CACR,MAAM,eAAe,QAAQ;CAC7B,MAAM,WAAW,aAAa,IAAI,QAAQ,EAAE,MAAM,IAAI;AACtD,KAAI,aAAa,GAAI,QAAO;CAE5B,MAAM,QAAQ,OAAO,SAAS;AAC9B,QAAO,OAAO,SAAS,MAAM,GAAG,QAAQ;;AAG1C,SAAS,SACP,cACA,MACA,eACoB;CACpB,MAAM,QAAQ,aAAa,IAAI,KAAK;AACpC,KAAI,UAAU,QAAQ,UAAU,GAAI,QAAO;AAC3C,KAAI,eAAe,OAAO,cAAc,CAAE,QAAO;AACjD,OAAM,IAAI,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI;;AAGtD,SAAS,UACP,cACA,MACA,eACsB;CACtB,MAAM,SAAS,iBAAiB,cAAc,KAAK;AACnD,KAAI,OAAO,WAAW,EAAG,QAAO;AAChC,QAAO,OAAO,KAAK,UAAU,kBAAkB,MAAM,OAAO,cAAc,CAAC;;AAG7E,SAAS,iBAAiB,cAA+B,MAAwB;AAC/E,QAAO,aACJ,OAAO,KAAK,CACZ,SAAS,UAAU,MAAM,MAAM,IAAI,CAAC,CACpC,KAAK,UAAU,MAAM,MAAM,CAAC,CAC5B,OAAO,QAAQ;;AAGpB,SAAS,kBACP,MACA,OACA,eACQ;AACR,KAAI,eAAe,OAAO,cAAc,CAAE,QAAO;AACjD,OAAM,IAAI,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI;;AAGtD,SAAS,eACP,OACA,eACiB;AACjB,QAAO,cAAc,MAAM,iBAAiB,iBAAiB,MAAM;;AAGrE,SAAS,YAAY,SAAiE;AACpF,QAAO;EACL,MAAM;EACN,OAAO;GACL,MAAM;GACN;GACD;EACF;;AAGH,SAAS,gBAAgB,OAAgB,UAA0B;AACjE,QAAO,iBAAiB,QAAQ,MAAM,UAAU"}
|
|
1
|
+
{"version":3,"file":"server-handlers.mjs","names":[],"sources":["../../../../src/core/predictive-search/server-handlers.ts"],"sourcesContent":["import type {\n PredictiveSearchLimitScope,\n PredictiveSearchType,\n SearchUnavailableProductsType,\n SearchableField,\n} from \"../../graphql/generated/storefront-api-types\";\nimport { createProxyResponseHeaders } from \"../request-routing/interceptors/proxy\";\nimport type {\n CallableRouteHandler,\n ShopifyRouteError,\n ShopifyRouteErrorResult,\n ShopifyRouteJsonResult,\n} from \"../request-routing/registered-routes\";\nimport { createCallableRouteHandler } from \"../request-routing/registered-routes\";\nimport { PREDICTIVE_SEARCH_API_PATH, PREDICTIVE_SEARCH_GET_METHOD } from \"./constants\";\nimport {\n makePredictiveSearchQueries,\n predictiveSearchQueries,\n type CreatePredictiveSearchQueriesOptions,\n type PredictiveSearchQueriesForOptions,\n} from \"./queries\";\nimport {\n DEFAULT_PREDICTIVE_SEARCH_LIMIT,\n DEFAULT_PREDICTIVE_SEARCH_LIMIT_SCOPE,\n DEFAULT_PREDICTIVE_SEARCH_UNAVAILABLE_PRODUCTS,\n fetchPredictiveSearch,\n type PredictiveSearchData,\n type PredictiveSearchDataForOptions,\n type QueryPredictiveSearchOptions,\n} from \"./search\";\n\nconst VALID_LIMIT_SCOPES: readonly PredictiveSearchLimitScope[] = [\"ALL\", \"EACH\"];\nconst VALID_PREDICTIVE_SEARCH_TYPES: readonly PredictiveSearchType[] = [\n \"ARTICLE\",\n \"COLLECTION\",\n \"PAGE\",\n \"PRODUCT\",\n \"QUERY\",\n];\nconst VALID_SEARCHABLE_FIELDS: readonly SearchableField[] = [\n \"AUTHOR\",\n \"BODY\",\n \"PRODUCT_TYPE\",\n \"TAG\",\n \"TITLE\",\n \"VARIANTS_BARCODE\",\n \"VARIANTS_SKU\",\n \"VARIANTS_TITLE\",\n \"VENDOR\",\n];\nconst VALID_UNAVAILABLE_PRODUCTS: readonly SearchUnavailableProductsType[] = [\n \"HIDE\",\n \"LAST\",\n \"SHOW\",\n];\n\ntype PredictiveSearchHandlerContext = {\n request: Request;\n storefrontClient: QueryPredictiveSearchOptions[\"storefrontClient\"];\n};\n\ntype PredictiveSearchGetData<TData = PredictiveSearchDataForOptions<{}>> = TData;\ntype PredictiveSearchGetResult<TData = PredictiveSearchDataForOptions<{}>> =\n | ShopifyRouteJsonResult<PredictiveSearchGetData<TData>>\n | ShopifyRouteErrorResult<PredictiveSearchError>;\n\ntype PredictiveSearchErrorCode = \"invalid_predictive_search_request\";\ntype PredictiveSearchError = ShopifyRouteError & {\n code: PredictiveSearchErrorCode;\n};\n\n/** GET route handler that returns predictive search results or an error. */\ntype PredictiveSearchGetHandler<TData = PredictiveSearchDataForOptions<{}>> = CallableRouteHandler<\n PredictiveSearchHandlerContext,\n PredictiveSearchGetResult<TData>,\n string,\n typeof PREDICTIVE_SEARCH_GET_METHOD\n>;\n\n/** Predictive search route handlers to pass to `handleShopifyRoutes`. */\ntype PredictiveSearchServerHandlers<\n TOptions extends CreatePredictiveSearchServerHandlersOptions = {},\n TData = PredictiveSearchDataForOptions<TOptions>,\n> = {\n /** Answers GET requests with predictive search results as JSON. */\n get: PredictiveSearchGetHandler<TData>;\n};\n\ntype AsyncHandlerResult<THandler> = THandler extends (\n ...args: infer _Args\n) => Promise<infer TResult>\n ? TResult\n : never;\n\n// Rebuilt on PredictiveSearchData: TypeScript compares PredictiveSearchDataForOptions instantiations\n// through their type arguments and can't tell fragment options apart, so handler data would be interchangeable.\ntype JsonResultData<TResult> = TResult extends { type: \"json\"; data: { items: infer TItems } }\n ? PredictiveSearchData<TItems>\n : never;\n\n/**\n * Infers the {@link PredictiveSearchData} shape returned by handlers from {@link createPredictiveSearchServerHandlers}.\n *\n * Pass it as the type argument to `usePredictiveSearch` so client state includes the handlers' custom fragment fields.\n *\n * @example\n * ```ts\n * type SearchData = PredictiveSearchDataFromHandlers<typeof predictiveSearchHandlers>;\n * ```\n */\nexport type PredictiveSearchDataFromHandlers<\n THandlers extends {\n get: (context: never) => Promise<{ type: string; data?: PredictiveSearchData<unknown> }>;\n },\n> = JsonResultData<AsyncHandlerResult<THandlers[\"get\"]>>;\n\n/**\n * Route path, custom fragments, and default search settings for the predictive search route.\n *\n * A request overrides a default search setting with a URL parameter of the same name.\n */\nexport interface CreatePredictiveSearchServerHandlersOptions extends CreatePredictiveSearchQueriesOptions {\n /** Route path that the GET handler serves. Defaults to `/api/predictive-search`. */\n path?: string;\n /** Default maximum number of results, from 1 to 10. Applies when a request has no numeric `limit` parameter. Predictive search clamps other values to that range. Defaults to `5`. */\n limit?: number;\n /** Default limit scope. Defaults to `EACH`. */\n limitScope?: PredictiveSearchLimitScope;\n /** Default result types. A request can set `types` to a comma-separated list. */\n types?: PredictiveSearchType[];\n /** Default fields to search. A request can set `searchableFields` to a comma-separated list. */\n searchableFields?: SearchableField[];\n /** Default handling of unavailable products. Defaults to `HIDE`. */\n unavailableProducts?: SearchUnavailableProductsType;\n}\n\n/**\n * Creates the route that answers predictive search requests from the browser.\n * Register the handlers with `handleShopifyRoutes`. The default route path matches\n * the default endpoint of `createPredictiveSearchStore` and `PredictiveSearchProvider`.\n *\n * The route reads the search term from the `q` URL parameter. A URL parameter with the same name as a search setting overrides the setting's default.\n *\n * An invalid setting value or a failed Storefront API query returns HTTP status `400` with a JSON body of `{error: {code, message}}`. The `code` value is `invalid_predictive_search_request`.\n * A successful response forwards the Storefront API response headers except the content encoding, content length, and server timing headers.\n *\n * @publicDocs\n */\nexport function createPredictiveSearchServerHandlers(): PredictiveSearchServerHandlers;\nexport function createPredictiveSearchServerHandlers<\n const TOptions extends CreatePredictiveSearchServerHandlersOptions,\n>(options: TOptions): PredictiveSearchServerHandlers<TOptions>;\n/**\n * @param options Route path, custom fragments, and default search settings for the route.\n * @returns Route handlers to pass to `handleShopifyRoutes`.\n */\nexport function createPredictiveSearchServerHandlers(\n options: CreatePredictiveSearchServerHandlersOptions = {},\n): PredictiveSearchServerHandlers<CreatePredictiveSearchServerHandlersOptions> {\n const queries = options.fragments\n ? makePredictiveSearchQueries(options)\n : predictiveSearchQueries;\n const handler = createCallableRouteHandler(\n options.path ?? PREDICTIVE_SEARCH_API_PATH,\n PREDICTIVE_SEARCH_GET_METHOD,\n (context: PredictiveSearchHandlerContext) => handleGet(context, options, queries),\n );\n return { get: handler };\n}\n\nasync function handleGet(\n { request, storefrontClient }: PredictiveSearchHandlerContext,\n options: CreatePredictiveSearchServerHandlersOptions,\n queries: PredictiveSearchQueriesForOptions<CreatePredictiveSearchServerHandlersOptions>,\n): Promise<PredictiveSearchGetResult> {\n let searchOptions: ParsedPredictiveSearchRequest;\n try {\n searchOptions = parsePredictiveSearchRequest(request, options);\n } catch (error) {\n return errorResult(getErrorMessage(error, \"Invalid predictive search request\"));\n }\n\n try {\n const result = await fetchPredictiveSearch({\n storefrontClient,\n query: queries.predictiveSearch,\n ...searchOptions,\n });\n return {\n type: \"json\",\n data: result.data,\n headers: createProxyResponseHeaders(result.headers),\n };\n } catch (error) {\n return errorResult(getErrorMessage(error, \"Predictive search request failed\"));\n }\n}\n\ntype ParsedPredictiveSearchRequest = Omit<\n QueryPredictiveSearchOptions,\n \"storefrontClient\" | \"query\" | \"signal\"\n>;\n\nfunction parsePredictiveSearchRequest(\n request: Request,\n options: CreatePredictiveSearchServerHandlersOptions,\n): ParsedPredictiveSearchRequest {\n const searchParams = new URL(request.url).searchParams;\n return {\n term: searchParams.get(\"q\") ?? \"\",\n limit: parseLimit(searchParams, options),\n limitScope:\n parseOne(searchParams, \"limitScope\", VALID_LIMIT_SCOPES) ??\n options.limitScope ??\n DEFAULT_PREDICTIVE_SEARCH_LIMIT_SCOPE,\n types: parseMany(searchParams, \"types\", VALID_PREDICTIVE_SEARCH_TYPES) ?? options.types,\n searchableFields:\n parseMany(searchParams, \"searchableFields\", VALID_SEARCHABLE_FIELDS) ??\n options.searchableFields,\n unavailableProducts:\n parseOne(searchParams, \"unavailableProducts\", VALID_UNAVAILABLE_PRODUCTS) ??\n options.unavailableProducts ??\n DEFAULT_PREDICTIVE_SEARCH_UNAVAILABLE_PRODUCTS,\n };\n}\n\n// Invalid enum params return a typed error, but an unparseable limit falls back to the configured default.\nfunction parseLimit(\n searchParams: URLSearchParams,\n options: CreatePredictiveSearchServerHandlersOptions,\n): number {\n const defaultLimit = options.limit ?? DEFAULT_PREDICTIVE_SEARCH_LIMIT;\n const rawLimit = searchParams.get(\"limit\")?.trim() ?? \"\";\n if (rawLimit === \"\") return defaultLimit;\n\n const limit = Number(rawLimit);\n return Number.isFinite(limit) ? limit : defaultLimit;\n}\n\nfunction parseOne<TValue extends string>(\n searchParams: URLSearchParams,\n name: string,\n allowedValues: readonly TValue[],\n): TValue | undefined {\n const value = searchParams.get(name);\n if (value === null || value === \"\") return undefined;\n if (isAllowedValue(value, allowedValues)) return value;\n throw new Error(`Invalid ${name} value \"${value}\".`);\n}\n\nfunction parseMany<TValue extends string>(\n searchParams: URLSearchParams,\n name: string,\n allowedValues: readonly TValue[],\n): TValue[] | undefined {\n const values = splitParamValues(searchParams, name);\n if (values.length === 0) return undefined;\n return values.map((value) => parseAllowedValue(name, value, allowedValues));\n}\n\nfunction splitParamValues(searchParams: URLSearchParams, name: string): string[] {\n return searchParams\n .getAll(name)\n .flatMap((value) => value.split(\",\"))\n .map((value) => value.trim())\n .filter(Boolean);\n}\n\nfunction parseAllowedValue<TValue extends string>(\n name: string,\n value: string,\n allowedValues: readonly TValue[],\n): TValue {\n if (isAllowedValue(value, allowedValues)) return value;\n throw new Error(`Invalid ${name} value \"${value}\".`);\n}\n\nfunction isAllowedValue<TValue extends string>(\n value: string,\n allowedValues: readonly TValue[],\n): value is TValue {\n return allowedValues.some((allowedValue) => allowedValue === value);\n}\n\nfunction errorResult(message: string): ShopifyRouteErrorResult<PredictiveSearchError> {\n return {\n type: \"error\",\n error: {\n code: \"invalid_predictive_search_request\",\n message,\n },\n };\n}\n\nfunction getErrorMessage(error: unknown, fallback: string): string {\n return error instanceof Error ? error.message : fallback;\n}\n"],"mappings":";;;;;;;AA+BA,MAAM,qBAA4D,CAAC,OAAO,OAAO;AACjF,MAAM,gCAAiE;CACrE;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,0BAAsD;CAC1D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AACD,MAAM,6BAAuE;CAC3E;CACA;CACA;CACD;;;;;AAsGD,SAAgB,qCACd,UAAuD,EAAE,EACoB;CAC7E,MAAM,UAAU,QAAQ,YACpB,4BAA4B,QAAQ,GACpC;AAMJ,QAAO,EAAE,KALO,2BACd,QAAQ,0CAEP,YAA4C,UAAU,SAAS,SAAS,QAAQ,CAE9D,EAAE;;AAGzB,eAAe,UACb,EAAE,SAAS,oBACX,SACA,SACoC;CACpC,IAAI;AACJ,KAAI;AACF,kBAAgB,6BAA6B,SAAS,QAAQ;UACvD,OAAO;AACd,SAAO,YAAY,gBAAgB,OAAO,oCAAoC,CAAC;;AAGjF,KAAI;EACF,MAAM,SAAS,MAAM,sBAAsB;GACzC;GACA,OAAO,QAAQ;GACf,GAAG;GACJ,CAAC;AACF,SAAO;GACL,MAAM;GACN,MAAM,OAAO;GACb,SAAS,2BAA2B,OAAO,QAAQ;GACpD;UACM,OAAO;AACd,SAAO,YAAY,gBAAgB,OAAO,mCAAmC,CAAC;;;AASlF,SAAS,6BACP,SACA,SAC+B;CAC/B,MAAM,eAAe,IAAI,IAAI,QAAQ,IAAI,CAAC;AAC1C,QAAO;EACL,MAAM,aAAa,IAAI,IAAI,IAAI;EAC/B,OAAO,WAAW,cAAc,QAAQ;EACxC,YACE,SAAS,cAAc,cAAc,mBAAmB,IACxD,QAAQ;EAEV,OAAO,UAAU,cAAc,SAAS,8BAA8B,IAAI,QAAQ;EAClF,kBACE,UAAU,cAAc,oBAAoB,wBAAwB,IACpE,QAAQ;EACV,qBACE,SAAS,cAAc,uBAAuB,2BAA2B,IACzE,QAAQ;EAEX;;AAIH,SAAS,WACP,cACA,SACQ;CACR,MAAM,eAAe,QAAQ;CAC7B,MAAM,WAAW,aAAa,IAAI,QAAQ,EAAE,MAAM,IAAI;AACtD,KAAI,aAAa,GAAI,QAAO;CAE5B,MAAM,QAAQ,OAAO,SAAS;AAC9B,QAAO,OAAO,SAAS,MAAM,GAAG,QAAQ;;AAG1C,SAAS,SACP,cACA,MACA,eACoB;CACpB,MAAM,QAAQ,aAAa,IAAI,KAAK;AACpC,KAAI,UAAU,QAAQ,UAAU,GAAI,QAAO;AAC3C,KAAI,eAAe,OAAO,cAAc,CAAE,QAAO;AACjD,OAAM,IAAI,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI;;AAGtD,SAAS,UACP,cACA,MACA,eACsB;CACtB,MAAM,SAAS,iBAAiB,cAAc,KAAK;AACnD,KAAI,OAAO,WAAW,EAAG,QAAO;AAChC,QAAO,OAAO,KAAK,UAAU,kBAAkB,MAAM,OAAO,cAAc,CAAC;;AAG7E,SAAS,iBAAiB,cAA+B,MAAwB;AAC/E,QAAO,aACJ,OAAO,KAAK,CACZ,SAAS,UAAU,MAAM,MAAM,IAAI,CAAC,CACpC,KAAK,UAAU,MAAM,MAAM,CAAC,CAC5B,OAAO,QAAQ;;AAGpB,SAAS,kBACP,MACA,OACA,eACQ;AACR,KAAI,eAAe,OAAO,cAAc,CAAE,QAAO;AACjD,OAAM,IAAI,MAAM,WAAW,KAAK,UAAU,MAAM,IAAI;;AAGtD,SAAS,eACP,OACA,eACiB;AACjB,QAAO,cAAc,MAAM,iBAAiB,iBAAiB,MAAM;;AAGrE,SAAS,YAAY,SAAiE;AACpF,QAAO;EACL,MAAM;EACN,OAAO;GACL,MAAM;GACN;GACD;EACF;;AAGH,SAAS,gBAAgB,OAAgB,UAA0B;AACjE,QAAO,iBAAiB,QAAQ,MAAM,UAAU"}
|
|
@@ -23,7 +23,7 @@ type PredictiveSearchItem = PredictiveSearchResourceItem | PredictiveSearchQuery
|
|
|
23
23
|
* Pass the route templates and the customer's search term.
|
|
24
24
|
*/
|
|
25
25
|
type PredictiveSearchItemUrlOptions = {
|
|
26
|
-
/** Prefix to add before the route path, such as a locale prefix. */pathPrefix?: string; /** Route templates for product, collection, page, and article paths, from `
|
|
26
|
+
/** Prefix to add before the route path, such as a locale prefix. */pathPrefix?: string; /** Route templates for product, collection, page, and article paths, from `defineShopifyRouteTemplates`. */
|
|
27
27
|
routes: ShopifyRouteTemplates; /** Search term that the customer typed. The link carries the term in the `q` URL parameter. */
|
|
28
28
|
term: string;
|
|
29
29
|
};
|
|
@@ -78,5 +78,5 @@ declare function getSearchResultUrl({
|
|
|
78
78
|
searchParamName
|
|
79
79
|
}: SearchResultUrlOptions): string;
|
|
80
80
|
//#endregion
|
|
81
|
-
export { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, getPredictiveSearchItemUrl, getSearchResultUrl };
|
|
81
|
+
export { PredictiveSearchArticleItem, PredictiveSearchCollectionItem, PredictiveSearchItem, PredictiveSearchItemUrlOptions, PredictiveSearchPageItem, PredictiveSearchProductItem, PredictiveSearchQueryItem, PredictiveSearchQueryItemUrlOptions, PredictiveSearchResourceItem, SearchResultUrlOptions, getPredictiveSearchItemUrl, getSearchResultUrl };
|
|
82
82
|
//# sourceMappingURL=url.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.mjs","names":[],"sources":["../../../../src/core/predictive-search/url.ts"],"sourcesContent":["import { getStandardRoute, type ShopifyRouteTemplates } from \"../standard-routes/index\";\nimport type { PredictiveSearchData } from \"./search\";\n\nconst RELATIVE_URL_BASE = \"https://hydrogen.local\";\n\ntype PredictiveSearchItems = PredictiveSearchData[\"items\"];\n\n/** A product result from predictive search. */\nexport type PredictiveSearchProductItem = PredictiveSearchItems[\"products\"][number];\n/** A collection result from predictive search. */\nexport type PredictiveSearchCollectionItem = PredictiveSearchItems[\"collections\"][number];\n/** A page result from predictive search. */\nexport type PredictiveSearchPageItem = PredictiveSearchItems[\"pages\"][number];\n/** An article result from predictive search. */\nexport type PredictiveSearchArticleItem = PredictiveSearchItems[\"articles\"][number];\n/** A suggested search term from predictive search. */\nexport type PredictiveSearchQueryItem = PredictiveSearchItems[\"queries\"][number];\n\n/** A product, collection, page, or article result. Excludes query suggestions. */\nexport type PredictiveSearchResourceItem =\n | PredictiveSearchProductItem\n | PredictiveSearchCollectionItem\n | PredictiveSearchPageItem\n | PredictiveSearchArticleItem;\n\n/** Any predictive search result, including query suggestions. */\nexport type PredictiveSearchItem = PredictiveSearchResourceItem | PredictiveSearchQueryItem;\n\n/**\n * Options for the link of a product, collection, page, or article result.\n *\n * Pass the route templates and the customer's search term.\n */\nexport type PredictiveSearchItemUrlOptions = {\n /** Prefix to add before the route path, such as a locale prefix. */\n pathPrefix?: string;\n /** Route templates for product, collection, page, and article paths, from `createShopifyRouteTemplates`. */\n routes: ShopifyRouteTemplates;\n /** Search term that the customer typed. The link carries the term in the `q` URL parameter. */\n term: string;\n};\n\n/**\n * Options for the link of a query suggestion.\n *\n * By default, a suggestion links to the standard search route and searches for the suggestion's text.\n */\nexport type PredictiveSearchQueryItemUrlOptions = {\n /** Prefix to add before the search route, such as a locale prefix. Has no effect when you set a search path. */\n pathPrefix?: string;\n /** Route templates that set the search page path. Defaults to Hydrogen's standard search route. */\n routes?: ShopifyRouteTemplates;\n /** Search page path or URL to use as is, without the route templates or the path prefix. */\n searchPath?: string;\n};\n\n/** URL options for any predictive search result, either resource options or query suggestion options. */\ntype AnyPredictiveSearchItemUrlOptions =\n | PredictiveSearchItemUrlOptions\n | PredictiveSearchQueryItemUrlOptions;\n\n/** Options for a search result URL. */\ntype SearchResultUrlOptions = {\n /** Search page path or absolute URL. */\n baseUrl: string;\n /** Search term to add to the URL. */\n term: string;\n /** Tracking parameters from a Storefront API search result. Pass the result's `trackingParameters` value unchanged. */\n trackingParameters?: string | null;\n /** Extra URL parameters, such as a result type filter. The search term replaces an extra parameter with the same name. */\n params?: Record<string, string>;\n /** URL parameter that carries the search term. Defaults to `q`. */\n searchParamName?: string;\n};\n\n/**\n * Builds the link for a predictive search result. A product, collection, page, or\n * article result links to the resource's page with the search term. A query suggestion links to\n * the search page and searches for the suggestion's text. Every link keeps the\n * result's tracking parameters.\n *\n * For a product, collection, page, or article, pass the route templates and the search term. The function throws an error without them.\n *\n * @throws {Error} When you pass a resource item without `routes` and `term` in the options.\n * @publicDocs\n */\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchQueryItem,\n options?: PredictiveSearchQueryItemUrlOptions,\n): string;\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchResourceItem,\n options: PredictiveSearchItemUrlOptions,\n): string;\n/**\n * @param item The predictive search result to link to.\n * @param options Route templates, search term, and path settings for the link.\n * @returns The link URL. The URL is relative unless you pass an absolute search path.\n */\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchItem,\n options?: AnyPredictiveSearchItemUrlOptions,\n): string {\n return getSearchResultUrl({\n baseUrl: getPredictiveSearchItemBaseUrl(item, options),\n term: getPredictiveSearchItemSearchTerm(item, options),\n trackingParameters: item.trackingParameters,\n });\n}\n\n/**\n * Builds a search page URL from a path, a search term, and optional extra\n * parameters. Use the function for search page links, such as a link to every\n * result for the current term.\n *\n * The search term and the extra parameters replace values with the same names in the base URL.\n *\n * @param options - The base URL, the search term, the extra and tracking parameters, and the search parameter name.\n * @returns A relative URL, or an absolute URL when the base URL is absolute.\n *\n * @publicDocs\n */\nexport function getSearchResultUrl({\n baseUrl,\n term,\n trackingParameters,\n params,\n searchParamName = \"q\",\n}: SearchResultUrlOptions): string {\n const url = new URL(baseUrl, RELATIVE_URL_BASE);\n\n for (const [name, value] of Object.entries(params ?? {})) {\n url.searchParams.set(name, value);\n }\n\n url.searchParams.set(searchParamName, term);\n appendTrackingParameters(url.searchParams, trackingParameters);\n\n if (isAbsoluteUrl(baseUrl)) return url.href;\n return `${url.pathname}${url.search}${url.hash}`;\n}\n\nfunction getPredictiveSearchItemBaseUrl(\n item: PredictiveSearchItem,\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): string {\n if (item.__typename === \"SearchQuerySuggestion\") return getQueryBaseUrl(options);\n\n const { pathPrefix, routes } = requirePredictiveSearchItemUrlOptions(options);\n return getResourceBaseUrl(item, routes, pathPrefix);\n}\n\nfunction getQueryBaseUrl(options: AnyPredictiveSearchItemUrlOptions | undefined): string {\n if (options && \"searchPath\" in options && options.searchPath) return options.searchPath;\n\n return getStandardRoute(\n options?.routes ?? {},\n \"search\",\n {},\n {\n pathPrefix: options?.pathPrefix,\n },\n );\n}\n\nfunction getResourceBaseUrl(\n item: PredictiveSearchResourceItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n switch (item.__typename) {\n case \"Product\":\n return getProductBaseUrl(item, routes, pathPrefix);\n case \"Collection\":\n return getCollectionBaseUrl(item, routes, pathPrefix);\n case \"Page\":\n return getPageBaseUrl(item, routes, pathPrefix);\n case \"Article\":\n return getArticleBaseUrl(item, routes, pathPrefix);\n }\n}\n\nfunction getProductBaseUrl(\n product: PredictiveSearchProductItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(routes, \"product\", { productHandle: product.handle }, { pathPrefix });\n}\n\nfunction getCollectionBaseUrl(\n collection: PredictiveSearchCollectionItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(\n routes,\n \"collection\",\n { collectionHandle: collection.handle },\n { pathPrefix },\n );\n}\n\nfunction getPageBaseUrl(\n page: PredictiveSearchPageItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(routes, \"page\", { pageHandle: page.handle }, { pathPrefix });\n}\n\nfunction getArticleBaseUrl(\n article: PredictiveSearchArticleItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(\n routes,\n \"article\",\n { articleHandle: article.handle, blogHandle: article.blog.handle },\n { pathPrefix },\n );\n}\n\nfunction getPredictiveSearchItemSearchTerm(\n item: PredictiveSearchItem,\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): string {\n if (item.__typename === \"SearchQuerySuggestion\") return item.text;\n return requirePredictiveSearchItemUrlOptions(options).term;\n}\n\nfunction requirePredictiveSearchItemUrlOptions(\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): PredictiveSearchItemUrlOptions {\n if (options && \"term\" in options && \"routes\" in options) return options;\n\n throw new Error(\n \"Predictive search resource URLs require route templates and the typed search term.\",\n );\n}\n\nfunction appendTrackingParameters(params: URLSearchParams, trackingParameters?: string | null) {\n if (!trackingParameters) return;\n\n const tracking = new URLSearchParams(trackingParameters);\n for (const [name, value] of tracking) {\n params.append(name, value);\n }\n}\n\nfunction isAbsoluteUrl(url: string): boolean {\n return URL.canParse(url);\n}\n"],"mappings":";;;AAGA,MAAM,oBAAoB;;;;;;AAgG1B,SAAgB,2BACd,MACA,SACQ;AACR,QAAO,mBAAmB;EACxB,SAAS,+BAA+B,MAAM,QAAQ;EACtD,MAAM,kCAAkC,MAAM,QAAQ;EACtD,oBAAoB,KAAK;EAC1B,CAAC;;;;;;;;;;;;;;AAeJ,SAAgB,mBAAmB,EACjC,SACA,MACA,oBACA,QACA,kBAAkB,OACe;CACjC,MAAM,MAAM,IAAI,IAAI,SAAS,kBAAkB;AAE/C,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,EAAE,CAAC,CACtD,KAAI,aAAa,IAAI,MAAM,MAAM;AAGnC,KAAI,aAAa,IAAI,iBAAiB,KAAK;AAC3C,0BAAyB,IAAI,cAAc,mBAAmB;AAE9D,KAAI,cAAc,QAAQ,CAAE,QAAO,IAAI;AACvC,QAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;;AAG5C,SAAS,+BACP,MACA,SACQ;AACR,KAAI,KAAK,eAAe,wBAAyB,QAAO,gBAAgB,QAAQ;CAEhF,MAAM,EAAE,YAAY,WAAW,sCAAsC,QAAQ;AAC7E,QAAO,mBAAmB,MAAM,QAAQ,WAAW;;AAGrD,SAAS,gBAAgB,SAAgE;AACvF,KAAI,WAAW,gBAAgB,WAAW,QAAQ,WAAY,QAAO,QAAQ;AAE7E,QAAO,iBACL,SAAS,UAAU,EAAE,EACrB,UACA,EAAE,EACF,EACE,YAAY,SAAS,YACtB,CACF;;AAGH,SAAS,mBACP,MACA,QACA,YACQ;AACR,SAAQ,KAAK,YAAb;EACE,KAAK,UACH,QAAO,kBAAkB,MAAM,QAAQ,WAAW;EACpD,KAAK,aACH,QAAO,qBAAqB,MAAM,QAAQ,WAAW;EACvD,KAAK,OACH,QAAO,eAAe,MAAM,QAAQ,WAAW;EACjD,KAAK,UACH,QAAO,kBAAkB,MAAM,QAAQ,WAAW;;;AAIxD,SAAS,kBACP,SACA,QACA,YACQ;AACR,QAAO,iBAAiB,QAAQ,WAAW,EAAE,eAAe,QAAQ,QAAQ,EAAE,EAAE,YAAY,CAAC;;AAG/F,SAAS,qBACP,YACA,QACA,YACQ;AACR,QAAO,iBACL,QACA,cACA,EAAE,kBAAkB,WAAW,QAAQ,EACvC,EAAE,YAAY,CACf;;AAGH,SAAS,eACP,MACA,QACA,YACQ;AACR,QAAO,iBAAiB,QAAQ,QAAQ,EAAE,YAAY,KAAK,QAAQ,EAAE,EAAE,YAAY,CAAC;;AAGtF,SAAS,kBACP,SACA,QACA,YACQ;AACR,QAAO,iBACL,QACA,WACA;EAAE,eAAe,QAAQ;EAAQ,YAAY,QAAQ,KAAK;EAAQ,EAClE,EAAE,YAAY,CACf;;AAGH,SAAS,kCACP,MACA,SACQ;AACR,KAAI,KAAK,eAAe,wBAAyB,QAAO,KAAK;AAC7D,QAAO,sCAAsC,QAAQ,CAAC;;AAGxD,SAAS,sCACP,SACgC;AAChC,KAAI,WAAW,UAAU,WAAW,YAAY,QAAS,QAAO;AAEhE,OAAM,IAAI,MACR,qFACD;;AAGH,SAAS,yBAAyB,QAAyB,oBAAoC;AAC7F,KAAI,CAAC,mBAAoB;CAEzB,MAAM,WAAW,IAAI,gBAAgB,mBAAmB;AACxD,MAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,QAAO,OAAO,MAAM,MAAM;;AAI9B,SAAS,cAAc,KAAsB;AAC3C,QAAO,IAAI,SAAS,IAAI"}
|
|
1
|
+
{"version":3,"file":"url.mjs","names":[],"sources":["../../../../src/core/predictive-search/url.ts"],"sourcesContent":["import { getStandardRoute, type ShopifyRouteTemplates } from \"../standard-routes/index\";\nimport type { PredictiveSearchData } from \"./search\";\n\nconst RELATIVE_URL_BASE = \"https://hydrogen.local\";\n\ntype PredictiveSearchItems = PredictiveSearchData[\"items\"];\n\n/** A product result from predictive search. */\nexport type PredictiveSearchProductItem = PredictiveSearchItems[\"products\"][number];\n/** A collection result from predictive search. */\nexport type PredictiveSearchCollectionItem = PredictiveSearchItems[\"collections\"][number];\n/** A page result from predictive search. */\nexport type PredictiveSearchPageItem = PredictiveSearchItems[\"pages\"][number];\n/** An article result from predictive search. */\nexport type PredictiveSearchArticleItem = PredictiveSearchItems[\"articles\"][number];\n/** A suggested search term from predictive search. */\nexport type PredictiveSearchQueryItem = PredictiveSearchItems[\"queries\"][number];\n\n/** A product, collection, page, or article result. Excludes query suggestions. */\nexport type PredictiveSearchResourceItem =\n | PredictiveSearchProductItem\n | PredictiveSearchCollectionItem\n | PredictiveSearchPageItem\n | PredictiveSearchArticleItem;\n\n/** Any predictive search result, including query suggestions. */\nexport type PredictiveSearchItem = PredictiveSearchResourceItem | PredictiveSearchQueryItem;\n\n/**\n * Options for the link of a product, collection, page, or article result.\n *\n * Pass the route templates and the customer's search term.\n */\nexport type PredictiveSearchItemUrlOptions = {\n /** Prefix to add before the route path, such as a locale prefix. */\n pathPrefix?: string;\n /** Route templates for product, collection, page, and article paths, from `defineShopifyRouteTemplates`. */\n routes: ShopifyRouteTemplates;\n /** Search term that the customer typed. The link carries the term in the `q` URL parameter. */\n term: string;\n};\n\n/**\n * Options for the link of a query suggestion.\n *\n * By default, a suggestion links to the standard search route and searches for the suggestion's text.\n */\nexport type PredictiveSearchQueryItemUrlOptions = {\n /** Prefix to add before the search route, such as a locale prefix. Has no effect when you set a search path. */\n pathPrefix?: string;\n /** Route templates that set the search page path. Defaults to Hydrogen's standard search route. */\n routes?: ShopifyRouteTemplates;\n /** Search page path or URL to use as is, without the route templates or the path prefix. */\n searchPath?: string;\n};\n\n/** URL options for any predictive search result, either resource options or query suggestion options. */\ntype AnyPredictiveSearchItemUrlOptions =\n | PredictiveSearchItemUrlOptions\n | PredictiveSearchQueryItemUrlOptions;\n\n/** Options for a search result URL. */\nexport type SearchResultUrlOptions = {\n /** Search page path or absolute URL. */\n baseUrl: string;\n /** Search term to add to the URL. */\n term: string;\n /** Tracking parameters from a Storefront API search result. Pass the result's `trackingParameters` value unchanged. */\n trackingParameters?: string | null;\n /** Extra URL parameters, such as a result type filter. The search term replaces an extra parameter with the same name. */\n params?: Record<string, string>;\n /** URL parameter that carries the search term. Defaults to `q`. */\n searchParamName?: string;\n};\n\n/**\n * Builds the link for a predictive search result. A product, collection, page, or\n * article result links to the resource's page with the search term. A query suggestion links to\n * the search page and searches for the suggestion's text. Every link keeps the\n * result's tracking parameters.\n *\n * For a product, collection, page, or article, pass the route templates and the search term. The function throws an error without them.\n *\n * @throws {Error} When you pass a resource item without `routes` and `term` in the options.\n * @publicDocs\n */\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchQueryItem,\n options?: PredictiveSearchQueryItemUrlOptions,\n): string;\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchResourceItem,\n options: PredictiveSearchItemUrlOptions,\n): string;\n/**\n * @param item The predictive search result to link to.\n * @param options Route templates, search term, and path settings for the link.\n * @returns The link URL. The URL is relative unless you pass an absolute search path.\n */\nexport function getPredictiveSearchItemUrl(\n item: PredictiveSearchItem,\n options?: AnyPredictiveSearchItemUrlOptions,\n): string {\n return getSearchResultUrl({\n baseUrl: getPredictiveSearchItemBaseUrl(item, options),\n term: getPredictiveSearchItemSearchTerm(item, options),\n trackingParameters: item.trackingParameters,\n });\n}\n\n/**\n * Builds a search page URL from a path, a search term, and optional extra\n * parameters. Use the function for search page links, such as a link to every\n * result for the current term.\n *\n * The search term and the extra parameters replace values with the same names in the base URL.\n *\n * @param options - The base URL, the search term, the extra and tracking parameters, and the search parameter name.\n * @returns A relative URL, or an absolute URL when the base URL is absolute.\n *\n * @publicDocs\n */\nexport function getSearchResultUrl({\n baseUrl,\n term,\n trackingParameters,\n params,\n searchParamName = \"q\",\n}: SearchResultUrlOptions): string {\n const url = new URL(baseUrl, RELATIVE_URL_BASE);\n\n for (const [name, value] of Object.entries(params ?? {})) {\n url.searchParams.set(name, value);\n }\n\n url.searchParams.set(searchParamName, term);\n appendTrackingParameters(url.searchParams, trackingParameters);\n\n if (isAbsoluteUrl(baseUrl)) return url.href;\n return `${url.pathname}${url.search}${url.hash}`;\n}\n\nfunction getPredictiveSearchItemBaseUrl(\n item: PredictiveSearchItem,\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): string {\n if (item.__typename === \"SearchQuerySuggestion\") return getQueryBaseUrl(options);\n\n const { pathPrefix, routes } = requirePredictiveSearchItemUrlOptions(options);\n return getResourceBaseUrl(item, routes, pathPrefix);\n}\n\nfunction getQueryBaseUrl(options: AnyPredictiveSearchItemUrlOptions | undefined): string {\n if (options && \"searchPath\" in options && options.searchPath) return options.searchPath;\n\n return getStandardRoute(\n options?.routes ?? {},\n \"search\",\n {},\n {\n pathPrefix: options?.pathPrefix,\n },\n );\n}\n\nfunction getResourceBaseUrl(\n item: PredictiveSearchResourceItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n switch (item.__typename) {\n case \"Product\":\n return getProductBaseUrl(item, routes, pathPrefix);\n case \"Collection\":\n return getCollectionBaseUrl(item, routes, pathPrefix);\n case \"Page\":\n return getPageBaseUrl(item, routes, pathPrefix);\n case \"Article\":\n return getArticleBaseUrl(item, routes, pathPrefix);\n }\n}\n\nfunction getProductBaseUrl(\n product: PredictiveSearchProductItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(routes, \"product\", { productHandle: product.handle }, { pathPrefix });\n}\n\nfunction getCollectionBaseUrl(\n collection: PredictiveSearchCollectionItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(\n routes,\n \"collection\",\n { collectionHandle: collection.handle },\n { pathPrefix },\n );\n}\n\nfunction getPageBaseUrl(\n page: PredictiveSearchPageItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(routes, \"page\", { pageHandle: page.handle }, { pathPrefix });\n}\n\nfunction getArticleBaseUrl(\n article: PredictiveSearchArticleItem,\n routes: ShopifyRouteTemplates,\n pathPrefix: string | undefined,\n): string {\n return getStandardRoute(\n routes,\n \"article\",\n { articleHandle: article.handle, blogHandle: article.blog.handle },\n { pathPrefix },\n );\n}\n\nfunction getPredictiveSearchItemSearchTerm(\n item: PredictiveSearchItem,\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): string {\n if (item.__typename === \"SearchQuerySuggestion\") return item.text;\n return requirePredictiveSearchItemUrlOptions(options).term;\n}\n\nfunction requirePredictiveSearchItemUrlOptions(\n options: AnyPredictiveSearchItemUrlOptions | undefined,\n): PredictiveSearchItemUrlOptions {\n if (options && \"term\" in options && \"routes\" in options) return options;\n\n throw new Error(\n \"Predictive search resource URLs require route templates and the typed search term.\",\n );\n}\n\nfunction appendTrackingParameters(params: URLSearchParams, trackingParameters?: string | null) {\n if (!trackingParameters) return;\n\n const tracking = new URLSearchParams(trackingParameters);\n for (const [name, value] of tracking) {\n params.append(name, value);\n }\n}\n\nfunction isAbsoluteUrl(url: string): boolean {\n return URL.canParse(url);\n}\n"],"mappings":";;;AAGA,MAAM,oBAAoB;;;;;;AAgG1B,SAAgB,2BACd,MACA,SACQ;AACR,QAAO,mBAAmB;EACxB,SAAS,+BAA+B,MAAM,QAAQ;EACtD,MAAM,kCAAkC,MAAM,QAAQ;EACtD,oBAAoB,KAAK;EAC1B,CAAC;;;;;;;;;;;;;;AAeJ,SAAgB,mBAAmB,EACjC,SACA,MACA,oBACA,QACA,kBAAkB,OACe;CACjC,MAAM,MAAM,IAAI,IAAI,SAAS,kBAAkB;AAE/C,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,EAAE,CAAC,CACtD,KAAI,aAAa,IAAI,MAAM,MAAM;AAGnC,KAAI,aAAa,IAAI,iBAAiB,KAAK;AAC3C,0BAAyB,IAAI,cAAc,mBAAmB;AAE9D,KAAI,cAAc,QAAQ,CAAE,QAAO,IAAI;AACvC,QAAO,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;;AAG5C,SAAS,+BACP,MACA,SACQ;AACR,KAAI,KAAK,eAAe,wBAAyB,QAAO,gBAAgB,QAAQ;CAEhF,MAAM,EAAE,YAAY,WAAW,sCAAsC,QAAQ;AAC7E,QAAO,mBAAmB,MAAM,QAAQ,WAAW;;AAGrD,SAAS,gBAAgB,SAAgE;AACvF,KAAI,WAAW,gBAAgB,WAAW,QAAQ,WAAY,QAAO,QAAQ;AAE7E,QAAO,iBACL,SAAS,UAAU,EAAE,EACrB,UACA,EAAE,EACF,EACE,YAAY,SAAS,YACtB,CACF;;AAGH,SAAS,mBACP,MACA,QACA,YACQ;AACR,SAAQ,KAAK,YAAb;EACE,KAAK,UACH,QAAO,kBAAkB,MAAM,QAAQ,WAAW;EACpD,KAAK,aACH,QAAO,qBAAqB,MAAM,QAAQ,WAAW;EACvD,KAAK,OACH,QAAO,eAAe,MAAM,QAAQ,WAAW;EACjD,KAAK,UACH,QAAO,kBAAkB,MAAM,QAAQ,WAAW;;;AAIxD,SAAS,kBACP,SACA,QACA,YACQ;AACR,QAAO,iBAAiB,QAAQ,WAAW,EAAE,eAAe,QAAQ,QAAQ,EAAE,EAAE,YAAY,CAAC;;AAG/F,SAAS,qBACP,YACA,QACA,YACQ;AACR,QAAO,iBACL,QACA,cACA,EAAE,kBAAkB,WAAW,QAAQ,EACvC,EAAE,YAAY,CACf;;AAGH,SAAS,eACP,MACA,QACA,YACQ;AACR,QAAO,iBAAiB,QAAQ,QAAQ,EAAE,YAAY,KAAK,QAAQ,EAAE,EAAE,YAAY,CAAC;;AAGtF,SAAS,kBACP,SACA,QACA,YACQ;AACR,QAAO,iBACL,QACA,WACA;EAAE,eAAe,QAAQ;EAAQ,YAAY,QAAQ,KAAK;EAAQ,EAClE,EAAE,YAAY,CACf;;AAGH,SAAS,kCACP,MACA,SACQ;AACR,KAAI,KAAK,eAAe,wBAAyB,QAAO,KAAK;AAC7D,QAAO,sCAAsC,QAAQ,CAAC;;AAGxD,SAAS,sCACP,SACgC;AAChC,KAAI,WAAW,UAAU,WAAW,YAAY,QAAS,QAAO;AAEhE,OAAM,IAAI,MACR,qFACD;;AAGH,SAAS,yBAAyB,QAAyB,oBAAoC;AAC7F,KAAI,CAAC,mBAAoB;CAEzB,MAAM,WAAW,IAAI,gBAAgB,mBAAmB;AACxD,MAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,QAAO,OAAO,MAAM,MAAM;;AAI9B,SAAS,cAAc,KAAsB;AAC3C,QAAO,IAAI,SAAS,IAAI"}
|
|
@@ -33,7 +33,7 @@ const handleProductVariantId = (url, { request, requestContext, storefrontClient
|
|
|
33
33
|
if (request.method !== "GET" && request.method !== "HEAD") return null;
|
|
34
34
|
const variantId = parseVariantSearchParam(url.searchParams.get(VARIANT_SEARCH_PARAM));
|
|
35
35
|
if (!variantId) return null;
|
|
36
|
-
const pathPrefix = requestContext.
|
|
36
|
+
const pathPrefix = requestContext.locale.pathPrefix;
|
|
37
37
|
const match = matchStandardRouteUrl({
|
|
38
38
|
routeTemplates,
|
|
39
39
|
pathPrefix,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accept-variant-id.mjs","names":[],"sources":["../../../../src/core/product/accept-variant-id.ts"],"sourcesContent":["import type { StorefrontClient } from \"../../client\";\nimport { withStorefrontClientCache } from \"../../client/client\";\nimport { StorefrontApiError } from \"../../client/errors\";\nimport { gql } from \"../../graphql\";\nimport { Cache } from \"../cache\";\nimport { getLogger } from \"../logging\";\nimport type { HydrogenRouteInterceptor } from \"../request-routing/route-types\";\nimport { getStandardRoute } from \"../standard-routes/build\";\nimport { matchStandardRouteUrl } from \"../standard-routes/match\";\nimport type { ShopifyRouteTemplates } from \"../standard-routes/types\";\nimport {\n buildProductSelectionSearchParams,\n parseVariantSearchParam,\n VARIANT_SEARCH_PARAM,\n} from \"./url\";\n\nconst log = getLogger(\"product\");\n\nconst HTTP_FOUND_STATUS = 302;\n\nconst VARIANT_SELECTED_OPTIONS_QUERY = gql(`\n query VariantSelectedOptions($id: ID!, $country: CountryCode, $language: LanguageCode)\n @inContext(country: $country, language: $language) {\n node(id: $id) {\n ... on ProductVariant {\n selectedOptions {\n name\n value\n }\n product {\n handle\n }\n }\n }\n }\n`);\n\ntype SelectedOptionsVariant = {\n selectedOptions: { name: string; value: string }[];\n product: { handle: string };\n};\n\n/**\n * Accepts Liquid-style `?variant=<numeric id>` links on product pages by redirecting them\n * to the canonical option-params URL, e.g. `/products/snowboard?variant=123` →\n * `302 /products/snowboard?Color=Red&Size=M`.\n *\n * `handleShopifyRoutes` runs this before app routing. It claims only GET/HEAD requests\n * whose URL matches a product route template and carries a numeric `variant` param;\n * everything else falls through to the framework. When both `variant` and option params\n * are present, the variant wins and the option params are replaced.\n * Unknown/deleted variant ids redirect to the same URL with the `variant` param stripped,\n * preserving any remaining params for the product loader. Params unrelated to the\n * selection (`?ref=campaign`) are preserved. On cross-product (combined listing) redirects,\n * params matching the *source* product's option names are not stripped — the handler only\n * knows the target variant's options; loaders filtering with `allowedOptionNames` ignore\n * the leftovers.\n *\n * Configure the app's URL shape once with `handleShopifyRoutes({ routeTemplates })`.\n */\nexport const handleProductVariantId: HydrogenRouteInterceptor = (\n url,\n { request, requestContext, storefrontClient, routeTemplates = {} },\n) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return null;\n\n const variantId = parseVariantSearchParam(url.searchParams.get(VARIANT_SEARCH_PARAM));\n if (!variantId) return null;\n\n const pathPrefix = requestContext.
|
|
1
|
+
{"version":3,"file":"accept-variant-id.mjs","names":[],"sources":["../../../../src/core/product/accept-variant-id.ts"],"sourcesContent":["import type { StorefrontClient } from \"../../client\";\nimport { withStorefrontClientCache } from \"../../client/client\";\nimport { StorefrontApiError } from \"../../client/errors\";\nimport { gql } from \"../../graphql\";\nimport { Cache } from \"../cache\";\nimport { getLogger } from \"../logging\";\nimport type { HydrogenRouteInterceptor } from \"../request-routing/route-types\";\nimport { getStandardRoute } from \"../standard-routes/build\";\nimport { matchStandardRouteUrl } from \"../standard-routes/match\";\nimport type { ShopifyRouteTemplates } from \"../standard-routes/types\";\nimport {\n buildProductSelectionSearchParams,\n parseVariantSearchParam,\n VARIANT_SEARCH_PARAM,\n} from \"./url\";\n\nconst log = getLogger(\"product\");\n\nconst HTTP_FOUND_STATUS = 302;\n\nconst VARIANT_SELECTED_OPTIONS_QUERY = gql(`\n query VariantSelectedOptions($id: ID!, $country: CountryCode, $language: LanguageCode)\n @inContext(country: $country, language: $language) {\n node(id: $id) {\n ... on ProductVariant {\n selectedOptions {\n name\n value\n }\n product {\n handle\n }\n }\n }\n }\n`);\n\ntype SelectedOptionsVariant = {\n selectedOptions: { name: string; value: string }[];\n product: { handle: string };\n};\n\n/**\n * Accepts Liquid-style `?variant=<numeric id>` links on product pages by redirecting them\n * to the canonical option-params URL, e.g. `/products/snowboard?variant=123` →\n * `302 /products/snowboard?Color=Red&Size=M`.\n *\n * `handleShopifyRoutes` runs this before app routing. It claims only GET/HEAD requests\n * whose URL matches a product route template and carries a numeric `variant` param;\n * everything else falls through to the framework. When both `variant` and option params\n * are present, the variant wins and the option params are replaced.\n * Unknown/deleted variant ids redirect to the same URL with the `variant` param stripped,\n * preserving any remaining params for the product loader. Params unrelated to the\n * selection (`?ref=campaign`) are preserved. On cross-product (combined listing) redirects,\n * params matching the *source* product's option names are not stripped — the handler only\n * knows the target variant's options; loaders filtering with `allowedOptionNames` ignore\n * the leftovers.\n *\n * Configure the app's URL shape once with `handleShopifyRoutes({ routeTemplates })`.\n */\nexport const handleProductVariantId: HydrogenRouteInterceptor = (\n url,\n { request, requestContext, storefrontClient, routeTemplates = {} },\n) => {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") return null;\n\n const variantId = parseVariantSearchParam(url.searchParams.get(VARIANT_SEARCH_PARAM));\n if (!variantId) return null;\n\n const pathPrefix = requestContext.locale.pathPrefix;\n const match = matchStandardRouteUrl({ routeTemplates, pathPrefix, url: url.href });\n if (match?.pageTemplateName !== \"product\") return null;\n\n return resolveVariantRedirect({\n pathPrefix,\n requestedHandle: match.params.productHandle,\n routeTemplates,\n storefrontClient,\n url,\n variantId,\n });\n};\n\nasync function resolveVariantRedirect({\n pathPrefix,\n requestedHandle,\n routeTemplates,\n storefrontClient,\n url,\n variantId,\n}: {\n pathPrefix: string | undefined;\n requestedHandle: string | undefined;\n routeTemplates: ShopifyRouteTemplates;\n storefrontClient: StorefrontClient;\n url: URL;\n variantId: string;\n}): Promise<Response> {\n const variant = await queryVariantSelectedOptions(storefrontClient, variantId);\n\n const searchParams = buildProductSelectionSearchParams({\n selectedOptions: variant?.selectedOptions ?? [],\n optionNames: [],\n base: url.searchParams,\n });\n\n const pathname =\n variant && !isSameHandle(variant.product.handle, requestedHandle)\n ? getStandardRoute(\n routeTemplates,\n \"product\",\n { productHandle: variant.product.handle },\n { pathPrefix },\n )\n : url.pathname;\n\n const search = searchParams.toString();\n const location = search ? `${pathname}?${search}` : pathname;\n return new Response(null, {\n status: HTTP_FOUND_STATUS,\n headers: { location: new URL(location, url.origin).toString() },\n });\n}\n\nasync function queryVariantSelectedOptions(\n storefrontClient: StorefrontClient,\n variantId: string,\n): Promise<SelectedOptionsVariant | null> {\n try {\n const result = await storefrontClient.graphql(\n VARIANT_SELECTED_OPTIONS_QUERY,\n withStorefrontClientCache(\n storefrontClient,\n { variables: { id: variantId } },\n Cache.long(),\n hasResolvedVariant,\n ),\n );\n\n if (result.errors) {\n log.error(\"variant id redirect lookup failed\", { errors: result.errors, variantId });\n return null;\n }\n\n const node = result.data?.node;\n if (node && \"selectedOptions\" in node) return node;\n } catch (error) {\n if (!(error instanceof StorefrontApiError)) throw error;\n\n // Losing the requested selection beats failing the page: strip the param and render\n // the default variant instead of surfacing a 5xx for a lookup the buyer cannot retry.\n log.error(\"variant id redirect lookup failed\", { error, variantId });\n }\n\n return null;\n}\n\nfunction hasResolvedVariant(body: object): boolean {\n if (!(\"data\" in body) || typeof body.data !== \"object\" || body.data == null) return false;\n return \"node\" in body.data && body.data.node != null;\n}\n\nfunction isSameHandle(variantProductHandle: string, requestedHandle: string | undefined): boolean {\n return requestedHandle !== undefined\n ? variantProductHandle.toLowerCase() === requestedHandle.toLowerCase()\n : true;\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAA,MAAA,UAAA,UAAA;AAEA,MAAA,oBAAA;AAEA,MAAA,iCAAA,IAAA,iNAeA;;;;;;;;;;;;;;;;;;;AAyBA,MAAA,0BACA,KACA,EAAA,SAAA,gBAAA,kBAAA,iBAAA,EAAA,OACA;AACA,KAAA,QAAA,WAAA,SAAA,QAAA,WAAA,OAAA,QAAA;CAEA,MAAA,YAAA,wBAAA,IAAA,aAAA,IAAA,qBAAA,CAAA;AACA,KAAA,CAAA,UAAA,QAAA;CAEA,MAAA,aAAA,eAAA,OAAA;CACA,MAAA,QAAA,sBAAA;EAAA;EAAA;EAAA,KAAA,IAAA;EAAA,CAAA;AACA,KAAA,OAAA,qBAAA,UAAA,QAAA;AAEA,QAAA,uBAAA;EACA;EACA,iBAAA,MAAA,OAAA;EACA;EACA;EACA;EACA;EACA,CAAA;;AAGA,eAAA,uBAAA,EACA,YACA,iBACA,gBACA,kBACA,KACA,aAQA;CACA,MAAA,UAAA,MAAA,4BAAA,kBAAA,UAAA;CAEA,MAAA,eAAA,kCAAA;EACA,iBAAA,SAAA,mBAAA,EAAA;EACA,aAAA,EAAA;EACA,MAAA,IAAA;EACA,CAAA;CAEA,MAAA,WACA,WAAA,CAAA,aAAA,QAAA,QAAA,QAAA,gBAAA,GACA,iBACA,gBACA,WACA,EAAA,eAAA,QAAA,QAAA,QAAA,EACA,EAAA,YAAA,CACA,GACA,IAAA;CAEA,MAAA,SAAA,aAAA,UAAA;CACA,MAAA,WAAA,SAAA,GAAA,SAAA,GAAA,WAAA;AACA,QAAA,IAAA,SAAA,MAAA;EACA,QAAA;EACA,SAAA,EAAA,UAAA,IAAA,IAAA,UAAA,IAAA,OAAA,CAAA,UAAA,EAAA;EACA,CAAA;;AAGA,eAAA,4BACA,kBACA,WACA;AACA,KAAA;EACA,MAAA,SAAA,MAAA,iBAAA,QACA,gCACA,0BACA,kBACA,EAAA,WAAA,EAAA,IAAA,WAAA,EAAA,EACA,MAAA,MAAA,EACA,mBACA,CACA;AAEA,MAAA,OAAA,QAAA;AACA,OAAA,MAAA,qCAAA;IAAA,QAAA,OAAA;IAAA;IAAA,CAAA;AACA,UAAA;;EAGA,MAAA,OAAA,OAAA,MAAA;AACA,MAAA,QAAA,qBAAA,KAAA,QAAA;UACA,OAAA;AACA,MAAA,EAAA,iBAAA,oBAAA,OAAA;AAIA,MAAA,MAAA,qCAAA;GAAA;GAAA;GAAA,CAAA;;AAGA,QAAA;;AAGA,SAAA,mBAAA,MAAA;AACA,KAAA,EAAA,UAAA,SAAA,OAAA,KAAA,SAAA,YAAA,KAAA,QAAA,KAAA,QAAA;AACA,QAAA,UAAA,KAAA,QAAA,KAAA,KAAA,QAAA;;AAGA,SAAA,aAAA,sBAAA,iBAAA;AACA,QAAA,oBAAA,SACA,qBAAA,aAAA,KAAA,gBAAA,aAAA,GACA"}
|