@shopify/hydrogen 2026.10.2 → 2026.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -5
- package/dist/cli/index.mjs +2 -2
- package/dist/client/client.mjs +44 -9
- package/dist/client/client.mjs.map +1 -1
- package/dist/client/i18n-variables.d.mts +1 -1
- package/dist/client/i18n-variables.mjs +14 -6
- package/dist/client/i18n-variables.mjs.map +1 -1
- package/dist/client/types.d.mts +12 -6
- package/dist/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/core/cart/cart.mjs +1 -1
- package/dist/core/cart/cookie.mjs +6 -1
- package/dist/core/cart/cookie.mjs.map +1 -1
- package/dist/core/cart/form.d.mts +17 -5
- package/dist/core/cart/form.mjs +5 -0
- package/dist/core/cart/form.mjs.map +1 -1
- package/dist/core/cart/index.d.mts +1 -1
- package/dist/core/collection/url.mjs +8 -1
- package/dist/core/collection/url.mjs.map +1 -1
- package/dist/core/constants.mjs +2 -1
- package/dist/core/constants.mjs.map +1 -1
- package/dist/core/csp/index.d.mts +56 -0
- package/dist/core/csp/index.mjs +117 -0
- package/dist/core/csp/index.mjs.map +1 -0
- package/dist/core/csp/types.d.mts +52 -0
- package/dist/core/headers.mjs +2 -2
- package/dist/core/headers.mjs.map +1 -1
- package/dist/core/i18n/define.d.mts +54 -0
- package/dist/core/i18n/define.mjs +135 -0
- package/dist/core/i18n/define.mjs.map +1 -0
- package/dist/core/i18n/errors.d.mts +18 -0
- package/dist/core/i18n/errors.mjs +24 -0
- package/dist/core/i18n/errors.mjs.map +1 -0
- package/dist/core/i18n/href.d.mts +28 -0
- package/dist/core/i18n/href.mjs +45 -0
- package/dist/core/i18n/href.mjs.map +1 -0
- package/dist/core/i18n/locale.d.mts +21 -0
- package/dist/core/i18n/locale.mjs +36 -0
- package/dist/core/i18n/locale.mjs.map +1 -0
- package/dist/core/i18n/match.d.mts +37 -0
- package/dist/core/i18n/match.mjs +82 -0
- package/dist/core/i18n/match.mjs.map +1 -0
- package/dist/core/i18n/types.d.mts +80 -0
- package/dist/core/index.d.mts +14 -5
- package/dist/core/index.mjs +9 -2
- package/dist/core/predictive-search/index.d.mts +2 -2
- package/dist/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/core/predictive-search/url.d.mts +2 -2
- package/dist/core/predictive-search/url.mjs.map +1 -1
- package/dist/core/product/accept-variant-id.mjs +1 -1
- package/dist/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/core/request-context.d.mts +61 -35
- package/dist/core/request-context.mjs +11 -7
- package/dist/core/request-context.mjs.map +1 -1
- package/dist/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/core/request-routing/registered-routes.mjs +13 -3
- package/dist/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/core/request-routing/route-types.d.mts +2 -2
- package/dist/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/core/shopify-scripts/constants.mjs +3 -1
- package/dist/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/core/shopify-scripts/global.mjs +13 -11
- package/dist/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/core/shopify-scripts/index.d.mts +1 -0
- package/dist/core/shopify-scripts/index.mjs +12 -9
- package/dist/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/core/shopify-scripts/types.d.mts +4 -2
- package/dist/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/core/standard-routes/build.d.mts +7 -2
- package/dist/core/standard-routes/build.mjs +10 -3
- package/dist/core/standard-routes/build.mjs.map +1 -1
- package/dist/core/standard-routes/match.mjs +11 -1
- package/dist/core/standard-routes/match.mjs.map +1 -1
- package/dist/core/standard-routes/path.mjs +14 -3
- package/dist/core/standard-routes/path.mjs.map +1 -1
- package/dist/core/standard-routes/types.d.mts +6 -1
- package/dist/core/url.mjs +5 -3
- package/dist/core/url.mjs.map +1 -1
- package/dist/customer-account/client.d.mts +14 -10
- package/dist/customer-account/client.mjs +4 -5
- package/dist/customer-account/client.mjs.map +1 -1
- package/dist/customer-account/graphql.d.mts +7 -1
- package/dist/customer-account/graphql.mjs +6 -7
- package/dist/customer-account/graphql.mjs.map +1 -1
- package/dist/customer-account/session.mjs +3 -4
- package/dist/customer-account/session.mjs.map +1 -1
- package/dist/development/client/client.mjs +44 -9
- package/dist/development/client/client.mjs.map +1 -1
- package/dist/development/client/i18n-variables.d.mts +1 -1
- package/dist/development/client/i18n-variables.mjs +13 -5
- package/dist/development/client/i18n-variables.mjs.map +1 -1
- package/dist/development/client/types.d.mts +12 -6
- package/dist/development/core/cache/fetch-with-cache.mjs +8 -1
- package/dist/development/core/cache/fetch-with-cache.mjs.map +1 -1
- package/dist/development/core/cart/cart.mjs +1 -1
- package/dist/development/core/cart/cookie.mjs +6 -1
- package/dist/development/core/cart/cookie.mjs.map +1 -1
- package/dist/development/core/cart/form.d.mts +17 -5
- package/dist/development/core/cart/form.mjs +5 -0
- package/dist/development/core/cart/form.mjs.map +1 -1
- package/dist/development/core/cart/index.d.mts +1 -1
- package/dist/development/core/cart/queries.d.mts +57 -57
- package/dist/development/core/collection/url.mjs +8 -1
- package/dist/development/core/collection/url.mjs.map +1 -1
- package/dist/development/core/constants.mjs +2 -1
- package/dist/development/core/constants.mjs.map +1 -1
- package/dist/development/core/csp/index.d.mts +56 -0
- package/dist/development/core/csp/index.mjs +128 -0
- package/dist/development/core/csp/index.mjs.map +1 -0
- package/dist/development/core/csp/types.d.mts +52 -0
- package/dist/development/core/development.d.mts +14 -5
- package/dist/development/core/development.mjs +9 -2
- package/dist/development/core/headers.mjs +2 -2
- package/dist/development/core/headers.mjs.map +1 -1
- package/dist/development/core/i18n/define.d.mts +54 -0
- package/dist/development/core/i18n/define.mjs +135 -0
- package/dist/development/core/i18n/define.mjs.map +1 -0
- package/dist/development/core/i18n/errors.d.mts +18 -0
- package/dist/development/core/i18n/errors.mjs +24 -0
- package/dist/development/core/i18n/errors.mjs.map +1 -0
- package/dist/development/core/i18n/href.d.mts +28 -0
- package/dist/development/core/i18n/href.mjs +45 -0
- package/dist/development/core/i18n/href.mjs.map +1 -0
- package/dist/development/core/i18n/locale.d.mts +21 -0
- package/dist/development/core/i18n/locale.mjs +36 -0
- package/dist/development/core/i18n/locale.mjs.map +1 -0
- package/dist/development/core/i18n/match.d.mts +37 -0
- package/dist/development/core/i18n/match.mjs +82 -0
- package/dist/development/core/i18n/match.mjs.map +1 -0
- package/dist/development/core/i18n/types.d.mts +80 -0
- package/dist/development/core/index.d.mts +13 -4
- package/dist/development/core/predictive-search/index.d.mts +2 -2
- package/dist/development/core/predictive-search/queries.d.mts +2 -2
- package/dist/development/core/predictive-search/server-handlers.d.mts +27 -6
- package/dist/development/core/predictive-search/server-handlers.mjs +1 -4
- package/dist/development/core/predictive-search/server-handlers.mjs.map +1 -1
- package/dist/development/core/predictive-search/url.d.mts +2 -2
- package/dist/development/core/predictive-search/url.mjs.map +1 -1
- package/dist/development/core/product/accept-variant-id.mjs +1 -1
- package/dist/development/core/product/accept-variant-id.mjs.map +1 -1
- package/dist/development/core/request-context.d.mts +61 -35
- package/dist/development/core/request-context.mjs +11 -7
- package/dist/development/core/request-context.mjs.map +1 -1
- package/dist/development/core/request-routing/handle-shopify-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs +9 -1
- package/dist/development/core/request-routing/interceptors/api-proxy.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/checkout.mjs +11 -5
- package/dist/development/core/request-routing/interceptors/checkout.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs +1 -1
- package/dist/development/core/request-routing/interceptors/standard-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs +2 -1
- package/dist/development/core/request-routing/interceptors/url-redirects.mjs.map +1 -1
- package/dist/development/core/request-routing/registered-routes.d.mts +10 -3
- package/dist/development/core/request-routing/registered-routes.mjs +13 -3
- package/dist/development/core/request-routing/registered-routes.mjs.map +1 -1
- package/dist/development/core/request-routing/route-types.d.mts +2 -2
- package/dist/development/core/shop-pay/shop-pay.mjs +5 -4
- package/dist/development/core/shop-pay/shop-pay.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/analytics.mjs +3 -5
- package/dist/development/core/shopify-scripts/analytics.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/constants.mjs +3 -1
- package/dist/development/core/shopify-scripts/constants.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/global.mjs +13 -11
- package/dist/development/core/shopify-scripts/global.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/hashes.d.mts +17 -0
- package/dist/development/core/shopify-scripts/hashes.mjs +12 -0
- package/dist/development/core/shopify-scripts/hashes.mjs.map +1 -0
- package/dist/development/core/shopify-scripts/index.d.mts +1 -0
- package/dist/development/core/shopify-scripts/index.mjs +12 -9
- package/dist/development/core/shopify-scripts/index.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/page-view.mjs +4 -1
- package/dist/development/core/shopify-scripts/page-view.mjs.map +1 -1
- package/dist/development/core/shopify-scripts/types.d.mts +4 -2
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs +4 -1
- package/dist/development/core/shopify-scripts/utils/inline-script.mjs.map +1 -1
- package/dist/development/core/standard-routes/build.d.mts +7 -2
- package/dist/development/core/standard-routes/build.mjs +10 -3
- package/dist/development/core/standard-routes/build.mjs.map +1 -1
- package/dist/development/core/standard-routes/match.mjs +11 -1
- package/dist/development/core/standard-routes/match.mjs.map +1 -1
- package/dist/development/core/standard-routes/path.mjs +14 -3
- package/dist/development/core/standard-routes/path.mjs.map +1 -1
- package/dist/development/core/standard-routes/types.d.mts +6 -1
- package/dist/development/core/url.mjs +5 -3
- package/dist/development/core/url.mjs.map +1 -1
- package/dist/development/customer-account/session.mjs.map +1 -1
- package/dist/development/globals.d.mts +8 -4
- package/dist/development/graphql/type-resolver.d.mts +13 -1
- package/dist/development/react/index.d.mts +2 -2
- package/dist/globals.d.mts +8 -4
- package/dist/graphql/type-resolver.d.mts +13 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/vite/index.mjs +1 -1
- package/dist/vue/shopify-scripts.d.mts +1 -1
- package/package.json +13 -3
- package/skills/hydrogen-analytics/SKILL.md +2 -2
- package/skills/hydrogen-analytics/references/react.md +2 -2
- package/skills/hydrogen-markets/SKILL.md +127 -93
- package/skills/hydrogen-markets/references/nextjs.md +77 -87
- package/skills/hydrogen-oxygen/references/react-router.md +1 -2
- package/skills/hydrogen-predictive-search/SKILL.md +18 -1
- package/skills/hydrogen-request-handlers/SKILL.md +23 -5
- package/skills/hydrogen-request-handlers/references/content-security-policy.md +103 -0
- package/skills/hydrogen-request-handlers/references/frameworks.md +8 -6
- package/skills/hydrogen-request-handlers/references/nextjs.md +7 -3
- package/skills/hydrogen-request-handlers/references/nuxt.md +7 -5
- package/skills/hydrogen-robots-txt/SKILL.md +87 -0
- package/skills/hydrogen-routing/SKILL.md +36 -14
- package/skills/hydrogen-setup/SKILL.md +2 -2
- package/skills/hydrogen-setup/references/analytics.md +5 -5
- package/skills/hydrogen-setup/steps/2-scaffold.md +3 -0
- package/skills/hydrogen-setup/steps/7-shopify-runtime-scripts.md +4 -3
- package/skills/hydrogen-setup/steps/9-account-page.md +1 -1
- package/skills/hydrogen-smoke-test/SKILL.md +9 -2
- package/skills/hydrogen-storefront-client/SKILL.md +27 -9
- package/skills/hydrogen-storefront-client/references/astro.md +8 -3
- package/skills/hydrogen-storefront-client/references/caching.md +2 -0
- package/skills/hydrogen-storefront-client/references/nextjs.md +8 -3
- package/skills/hydrogen-storefront-client/references/nuxt.md +9 -5
- package/skills/hydrogen-storefront-client/references/react-router.md +6 -3
- package/skills/hydrogen-storefront-client/references/solidstart.md +6 -2
- package/skills/hydrogen-storefront-client/references/sveltekit.md +10 -4
- package/skills/migrate-to-hydrogen-2026-10/SKILL.md +20 -22
- package/skills/migrate-to-hydrogen-2026-10/references/sitemap-and-seo.md +1 -0
- package/skills/migrate-to-hydrogen-2026-10/references/typescript-and-gql-tada.md +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registered-routes.mjs","names":[],"sources":["../../../../src/core/request-routing/registered-routes.ts"],"sourcesContent":["import type {\n CallableRouteHandler,\n HydrogenRouteInterceptor,\n ShopifyRouteHandlerContext,\n ShopifyRouteHandlerResult,\n ShopifyRedirectStatus,\n ShopifyRouteSessionManager,\n} from \"./route-types\";\n\nexport type {\n CallableRouteHandler,\n ShopifyRouteError,\n ShopifyRouteErrorResult,\n ShopifyRouteHandler,\n ShopifyRouteHandlerContext,\n ShopifyRouteHandlerGroup,\n ShopifyRouteHandlerResult,\n ShopifyRouteJsonResult,\n ShopifyRouteRedirectResult,\n ShopifyRedirectStatus,\n ShopifyRouteSessionManager,\n} from \"./route-types\";\n\nconst HTTP_OK_STATUS = 200;\nconst HTTP_SEE_OTHER_STATUS = 303;\nconst HTTP_METHOD_NOT_ALLOWED_STATUS = 405;\nconst HTTP_BAD_REQUEST_STATUS = 400;\nconst VALID_REDIRECT_STATUSES = [\n 301, 302, 303, 307, 308,\n] as const satisfies readonly ShopifyRedirectStatus[];\n\n/**\n * Creates a custom endpoint in your app for one pathname and HTTP method. Collect handlers in an\n * object, and pass an array of handler objects to `handleShopifyRoutes` in its `handlers` option.\n *\n * Use paths other than `/api/cart`, which the cart server handlers use. Return a JSON, redirect, or error result from the handler. Hydrogen sends a JSON result with status `200`, an error result with status `400` by default, and a redirect result with status `303` by default. When a redirect result uses a status other than `301`, `302`, `303`, 307, or 308, the promise from `handleShopifyRoutes` rejects.\n *\n * Annotate the handler's context parameter with only the fields the handler reads, for example\n * `Omit<ShopifyRouteHandlerContext, \"sessionManager\">`, so apps without a session manager can\n * register it.\n *\n * @param pathname The exact URL pathname that the handler matches. Hydrogen doesn't match path parameters or prefixes.\n * @param method The HTTP method that the handler matches, in uppercase, such as `POST`.\n * @param handler The function that receives the request, its context, the session, and the Storefront API client, and returns a JSON, redirect, or error result.\n * @returns The handler to add to a handler object.\n * @publicDocs\n */\nexport function createShopifyRouteHandler<\n const TPathname extends string,\n const TMethod extends string,\n TContext extends Partial<ShopifyRouteHandlerContext> = ShopifyRouteHandlerContext,\n>(\n pathname: TPathname,\n method: TMethod,\n handler: (context: TContext) => Promise<ShopifyRouteHandlerResult>,\n):
|
|
1
|
+
{"version":3,"file":"registered-routes.mjs","names":[],"sources":["../../../../src/core/request-routing/registered-routes.ts"],"sourcesContent":["import { stripI18nPathPrefix } from \"../standard-routes/path\";\nimport type {\n CallableRouteHandler,\n HydrogenRouteInterceptor,\n ShopifyRouteHandler,\n ShopifyRouteHandlerContext,\n ShopifyRouteHandlerResult,\n ShopifyRedirectStatus,\n ShopifyRouteSessionManager,\n} from \"./route-types\";\n\nexport type {\n CallableRouteHandler,\n ShopifyRouteError,\n ShopifyRouteErrorResult,\n ShopifyRouteHandler,\n ShopifyRouteHandlerContext,\n ShopifyRouteHandlerGroup,\n ShopifyRouteHandlerResult,\n ShopifyRouteJsonResult,\n ShopifyRouteRedirectResult,\n ShopifyRedirectStatus,\n ShopifyRouteSessionManager,\n} from \"./route-types\";\n\nconst HTTP_OK_STATUS = 200;\nconst HTTP_SEE_OTHER_STATUS = 303;\nconst HTTP_METHOD_NOT_ALLOWED_STATUS = 405;\nconst HTTP_BAD_REQUEST_STATUS = 400;\nconst VALID_REDIRECT_STATUSES = [\n 301, 302, 303, 307, 308,\n] as const satisfies readonly ShopifyRedirectStatus[];\n\n/**\n * Creates a custom endpoint in your app for one pathname and HTTP method. Collect handlers in an\n * object, and pass an array of handler objects to `handleShopifyRoutes` in its `handlers` option.\n *\n * Use paths other than `/api/cart`, which the cart server handlers use. Return a JSON, redirect, or error result from the handler. Hydrogen sends a JSON result with status `200`, an error result with status `400` by default, and a redirect result with status `303` by default. When a redirect result uses a status other than `301`, `302`, `303`, 307, or 308, the promise from `handleShopifyRoutes` rejects.\n *\n * Annotate the handler's context parameter with only the fields the handler reads, for example\n * `Omit<ShopifyRouteHandlerContext, \"sessionManager\">`, so apps without a session manager can\n * register it. Hydrogen infers the context only from an annotated parameter. A handler with no\n * parameter, or with an unannotated destructured parameter, gets the full context, so\n * `handleShopifyRoutes` still requires `sessionManager` for it.\n *\n * Marking `sessionManager` optional in the annotation doesn't make it optional at runtime. It\n * still makes `sessionManager` required, and when an untyped caller omits it, Hydrogen passes a\n * stand-in that throws when the handler uses it. A check such as `if (sessionManager)` is always\n * true, so don't use it as a fallback.\n *\n * @param pathname The exact URL pathname that the handler matches. Hydrogen doesn't match path parameters or prefixes.\n * @param method The HTTP method that the handler matches, in uppercase, such as `POST`.\n * @param handler The function that receives the request, its context, the session manager, and the Storefront API client, and returns a JSON, redirect, or error result.\n * @returns The handler to add to a handler object.\n * @publicDocs\n */\nexport function createShopifyRouteHandler<\n const TPathname extends string,\n const TMethod extends string,\n TContext extends Partial<ShopifyRouteHandlerContext> = ShopifyRouteHandlerContext,\n>(\n pathname: TPathname,\n method: TMethod,\n handler: (context: TContext) => Promise<ShopifyRouteHandlerResult>,\n): ShopifyRouteHandler<TPathname, TMethod, TContext> {\n return createCallableRouteHandler(pathname, method, handler);\n}\n\nexport function createCallableRouteHandler<\n const TPathname extends string,\n const TMethod extends string,\n TContext,\n TResult,\n>(\n pathname: TPathname,\n method: TMethod,\n handler: (context: TContext) => Promise<TResult>,\n): CallableRouteHandler<TContext, TResult, TPathname, TMethod> {\n return Object.assign(handler, { pathname, method });\n}\n\nexport const handleShopifyRouteHandlers: HydrogenRouteInterceptor = (\n url,\n { request, sessionManager, storefrontClient, requestContext, handlers = [] },\n) => {\n const routeHandlers = handlers.flatMap((group) => Object.values(group));\n if (routeHandlers.length === 0) return null;\n\n // Handlers register unprefixed pathnames; under pathname i18n routing the request may carry\n // the locale prefix (`/fr-ca/api/cart`), so match against the stripped path.\n const pathname = stripI18nPathPrefix(url.pathname, requestContext.locale.pathPrefix);\n const pathMatches = routeHandlers.filter((entry) => entry.pathname === pathname);\n if (pathMatches.length === 0) return null;\n\n const match = pathMatches.find((candidate) => candidate.method === request.method);\n if (!match)\n return Promise.resolve(\n new Response(\"Method Not Allowed\", { status: HTTP_METHOD_NOT_ALLOWED_STATUS }),\n );\n\n const context = {\n request,\n sessionManager: sessionManager ?? createMissingSessionManager(url.pathname),\n storefrontClient,\n requestContext,\n };\n return match(context).then((result) => createShopifyRouteResponse(result, request));\n};\n\n// The types already require `sessionManager` for handlers that read it; this\n// covers untyped callers, which would otherwise read `undefined` deep inside a handler.\nfunction createMissingSessionManager(pathname: string): ShopifyRouteSessionManager {\n const fail = (): never => {\n throw new Error(\n `The ${pathname} handler needs a session. Pass sessionManager to handleShopifyRoutes.`,\n );\n };\n return {\n getSessionOrigin: fail,\n getSessionItem: fail,\n setSessionItem: fail,\n removeSessionItem: fail,\n };\n}\n\nfunction createShopifyRouteResponse(result: ShopifyRouteHandlerResult, request: Request): Response {\n if (result.type === \"redirect\") {\n const headers = new Headers(result.headers);\n headers.set(\"location\", resolveRedirectLocation(result.location, request));\n return new Response(null, {\n status: getRedirectStatus(result.status),\n headers,\n });\n }\n\n if (result.type === \"error\") {\n const headers = new Headers(result.headers);\n headers.set(\"content-type\", \"application/json\");\n return new Response(JSON.stringify({ error: result.error }), {\n status: result.status ?? HTTP_BAD_REQUEST_STATUS,\n headers,\n });\n }\n\n const headers = new Headers(result.headers);\n headers.set(\"content-type\", \"application/json\");\n return new Response(JSON.stringify(result.data), {\n status: HTTP_OK_STATUS,\n headers,\n });\n}\n\nfunction getRedirectStatus(status: ShopifyRedirectStatus | undefined): ShopifyRedirectStatus {\n const redirectStatus = status ?? HTTP_SEE_OTHER_STATUS;\n if (VALID_REDIRECT_STATUSES.some((validStatus) => validStatus === redirectStatus)) {\n return redirectStatus;\n }\n\n throw new Error(\n `Invalid Shopify route redirect status ${redirectStatus}. Expected one of: ${VALID_REDIRECT_STATUSES.join(\", \")}.`,\n );\n}\n\nfunction resolveRedirectLocation(location: string, request: Request): string {\n // Absolute Location headers are the best common denominator: browsers accept\n // relative redirects, but framework proxy runtimes like Next.js can require\n // absolute URLs when returning a Response from middleware/proxy code.\n return new URL(location, new URL(request.url).origin).toString();\n}\n"],"mappings":";;;AAyBA,MAAM,iBAAiB;AACvB,MAAM,wBAAwB;AAC9B,MAAM,iCAAiC;AACvC,MAAM,0BAA0B;AAChC,MAAM,0BAA0B;CAC9B;CAAK;CAAK;CAAK;CAAK;CACrB;;;;;;;;;;;;;;;;;;;;;;;;AAyBD,SAAgB,0BAKd,UACA,QACA,SACmD;AACnD,QAAO,2BAA2B,UAAU,QAAQ,QAAQ;;AAG9D,SAAgB,2BAMd,UACA,QACA,SAC6D;AAC7D,QAAO,OAAO,OAAO,SAAS;EAAE;EAAU;EAAQ,CAAC;;AAGrD,MAAa,8BACX,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,UAAU;GACzB;GACD,CAAC;;CAGJ,MAAM,UAAU,IAAI,QAAQ,OAAO,QAAQ;AAC3C,SAAQ,IAAI,gBAAgB,mBAAmB;AAC/C,QAAO,IAAI,SAAS,KAAK,UAAU,OAAO,KAAK,EAAE;EAC/C,QAAQ;EACR;EACD,CAAC;;AAGJ,SAAS,kBAAkB,QAAkE;CAC3F,MAAM,iBAAiB,UAAU;AACjC,KAAI,wBAAwB,MAAM,gBAAgB,gBAAgB,eAAe,CAC/E,QAAO;AAGT,OAAM,IAAI,MACR,yCAAyC,eAAe,qBAAqB,wBAAwB,KAAK,KAAK,CAAC,GACjH;;AAGH,SAAS,wBAAwB,UAAkB,SAA0B;AAI3E,QAAO,IAAI,IAAI,UAAU,IAAI,IAAI,QAAQ,IAAI,CAAC,OAAO,CAAC,UAAU"}
|
|
@@ -15,7 +15,7 @@ type ShopifyRouteSessionManager = {
|
|
|
15
15
|
};
|
|
16
16
|
/** The values that Hydrogen passes to each registered route handler. */
|
|
17
17
|
type ShopifyRouteHandlerContext = {
|
|
18
|
-
/** The incoming request that matched the handler's pathname and method. */request: Request; /** Your app's session storage for the current request. */
|
|
18
|
+
/** The incoming request that matched the handler's pathname and method. */request: Request; /** Your app's session storage for the current request. `handleShopifyRoutes` requires it only when a registered handler's context includes this field. */
|
|
19
19
|
sessionManager: ShopifyRouteSessionManager; /** The Storefront API client for the current request. */
|
|
20
20
|
storefrontClient: StorefrontClient; /** The current request's context, the same one the Storefront API client uses. */
|
|
21
21
|
requestContext: ShopifyRequestContext;
|
|
@@ -59,7 +59,7 @@ type CallableRouteHandler<TContext, TResult, TPathname extends string = string,
|
|
|
59
59
|
readonly method: TMethod;
|
|
60
60
|
};
|
|
61
61
|
/** A handler for one pathname and HTTP method, created with createShopifyRouteHandler. */
|
|
62
|
-
type ShopifyRouteHandler<TPathname extends string = string, TMethod extends string = string> = CallableRouteHandler<
|
|
62
|
+
type ShopifyRouteHandler<TPathname extends string = string, TMethod extends string = string, TContext extends Partial<ShopifyRouteHandlerContext> = ShopifyRouteHandlerContext> = CallableRouteHandler<TContext, ShopifyRouteHandlerResult, TPathname, TMethod>;
|
|
63
63
|
/**
|
|
64
64
|
* An object of route handlers keyed by name. Pass an array of groups to `handleShopifyRoutes` as `handlers`.
|
|
65
65
|
*
|
|
@@ -83,12 +83,13 @@ function createShopPayButton(options) {
|
|
|
83
83
|
}
|
|
84
84
|
function initializeShopPayButtonElement(element, options) {
|
|
85
85
|
syncShopPayButtonElementAttributes(element, getShopPayButtonElementAttributes(options));
|
|
86
|
-
const shadowRoot = element.shadowRoot ?? element.attachShadow({ mode: "open" });
|
|
87
86
|
const template = element.querySelector("template[shadowrootmode]");
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
let shadowRoot = element.shadowRoot;
|
|
88
|
+
if (!shadowRoot) {
|
|
89
|
+
shadowRoot = element.attachShadow({ mode: "open" });
|
|
90
|
+
if (template instanceof HTMLTemplateElement) shadowRoot.append(template.content.cloneNode(true));
|
|
91
91
|
}
|
|
92
|
+
template?.remove();
|
|
92
93
|
renderShopPayButtonShadowRoot(shadowRoot, options);
|
|
93
94
|
}
|
|
94
95
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shop-pay.mjs","names":["#connected"],"sources":["../../../../src/core/shop-pay/shop-pay.ts"],"sourcesContent":["import { normalizeStoreDomain } from \"../url\";\nimport { parseGid } from \"../utils/parse-gid\";\n\nconst DEFAULT_SOURCE = \"hydrogen\";\nconst DEFAULT_ACCESSIBILITY_LABEL = \"Buy with Shop Pay\";\nconst ERROR_PREFIX = \"[hydrogen:error:ShopPay]\";\nconst CAN_USE_DOM = typeof document !== \"undefined\";\n/**\n * Tag name of the Shop Pay button custom element, `hydrogen-shop-pay-button`.\n *\n * Use the tag directly on a framework without a Hydrogen binding.\n *\n * @publicDocs\n */\nexport const SHOP_PAY_BUTTON_TAG_NAME = \"hydrogen-shop-pay-button\";\nexport const SHOP_PAY_BUTTON_CLASS_NAME = \"shop-pay-button\";\nconst SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [\n \"accessibility-label\",\n \"border-radius\",\n \"channel\",\n \"checkout-url\",\n \"disabled\",\n \"nonce\",\n \"payment-option\",\n \"source\",\n \"source-token\",\n \"variants\",\n \"width\",\n] as const;\n\n/** Button styles matching the hosted shop-js pay button. */\nexport const SHOP_PAY_BUTTON_STYLES =\n `:host{display:block}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}{position:relative;display:flex;align-items:center;box-sizing:border-box;margin:0;padding:10px 16px;overflow:visible;width:260px;border:none;border-radius:12px;background-color:#5433eb;color:#fff;cursor:pointer;text-decoration:none;transition:all .15s cubic-bezier(.4,0,.2,1)}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:hover{background-color:#4524db}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:focus-visible{outline:none;box-shadow:0 0 0 3px #9c83f8}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}[aria-disabled=true]{opacity:.5;pointer-events:none;cursor:default}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}__logo{position:relative;display:inline-block;margin:0 auto;width:88px;height:auto}`;\n\nconst SHOP_PAY_LOGO_SVG =\n `<svg class=\"${SHOP_PAY_BUTTON_CLASS_NAME}__logo\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 99 25\" aria-hidden=\"true\" focusable=\"false\">` +\n '<path fill=\"currentColor\" d=\"M70.842 7.915h2.25c1.561 0 2.328.642 2.328 1.715 0 1.074-.739 1.715-2.259 1.715h-2.32v-3.43ZM80.525 16.142c-.879 0-1.227-.474-1.227-.948 0-.642.725-.935 2.147-1.102l1.115-.125c-.07 1.227-.892 2.175-2.035 2.175Z\"/>' +\n '<path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M65.645.5a3.64 3.64 0 0 0-3.64 3.64V20.7a3.64 3.64 0 0 0 3.64 3.64h29.668a3.64 3.64 0 0 0 3.64-3.64V4.14A3.64 3.64 0 0 0 95.314.5H65.645Zm5.197 16.674v-4.197h2.64c2.412 0 3.695-1.353 3.695-3.402 0-2.05-1.283-3.277-3.695-3.277h-4.341v10.876h1.7Zm9.334.223c1.297 0 2.147-.572 2.538-1.548.112 1.088.767 1.645 2.189 1.269l.014-1.157c-.572.055-.683-.154-.683-.753v-2.845c0-1.673-1.102-2.663-3.138-2.663-2.008 0-3.165 1.004-3.165 2.705h1.562c0-.809.572-1.297 1.576-1.297 1.06 0 1.547.46 1.534 1.255v.363l-1.8.195c-2.021.223-3.137.99-3.137 2.329 0 1.101.781 2.147 2.51 2.147Zm9.906.32c-.711 1.73-1.855 2.245-3.64 2.245h-.766V18.54h.822c.977 0 1.45-.307 1.966-1.185L85.3 9.923h1.757l2.259 5.424 2.008-5.424h1.715l-2.956 7.795Z\" clip-rule=\"evenodd\"/>' +\n '<path fill=\"currentColor\" d=\"M6.992 11.055c-2.359-.509-3.41-.708-3.41-1.612 0-.85.711-1.274 2.134-1.274 1.25 0 2.165.544 2.839 1.61.05.081.155.11.241.066l2.655-1.335a.186.186 0 0 0 .076-.259c-1.102-1.9-3.137-2.94-5.818-2.94C2.188 5.311 0 7.037 0 9.781c0 2.915 2.664 3.651 5.027 4.16 2.362.51 3.417.709 3.417 1.613s-.769 1.33-2.303 1.33c-1.416 0-2.467-.644-3.102-1.896a.186.186 0 0 0-.251-.082L.14 16.21a.188.188 0 0 0-.083.253c1.051 2.102 3.207 3.285 6.087 3.285 3.668 0 5.885-1.698 5.885-4.527 0-2.83-2.677-3.651-5.037-4.16v-.007ZM21.218 5.311c-1.505 0-2.835.531-3.791 1.477-.06.057-.159.015-.159-.067V.687A.185.185 0 0 0 17.081.5h-3.322a.185.185 0 0 0-.187.187v18.73c0 .104.083.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-1.587 1.223-2.804 2.87-2.804 1.649 0 2.843 1.191 2.843 2.804v8.216c0 .104.082.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-3.452-2.274-5.89-5.459-5.89ZM33.415 4.774c-1.803 0-3.493.55-4.706 1.343a.186.186 0 0 0-.06.25l1.464 2.488c.054.089.168.12.257.066a5.853 5.853 0 0 1 3.052-.834c2.899 0 5.03 2.036 5.03 4.726 0 2.292-1.706 3.99-3.868 3.99-1.762 0-2.985-1.022-2.985-2.463 0-.825.352-1.502 1.27-1.98a.183.183 0 0 0 .073-.258l-1.381-2.327a.187.187 0 0 0-.226-.079c-1.85.683-3.15 2.327-3.15 4.533 0 3.338 2.67 5.83 6.396 5.83 4.35 0 7.478-3 7.478-7.303 0-4.612-3.64-7.982-8.644-7.982ZM51.776 5.283c-1.68 0-3.182.62-4.277 1.707a.093.093 0 0 1-.16-.066v-1.31a.185.185 0 0 0-.187-.186h-3.235a.185.185 0 0 0-.188.187v18.702c0 .104.083.186.188.186h3.32a.185.185 0 0 0 .188-.186v-6.133c0-.082.099-.123.16-.07 1.091 1.012 2.536 1.603 4.19 1.603 3.897 0 6.936-3.139 6.936-7.217 0-4.078-3.042-7.217-6.935-7.217Zm-.63 11.266c-2.215 0-3.895-1.754-3.895-4.074S48.928 8.4 51.147 8.4c2.22 0 3.893 1.726 3.893 4.075 0 2.348-1.651 4.074-3.896 4.074h.003Z\"/>' +\n \"</svg>\";\n\n/** Checkout target, attribution, and display settings shared by every Shop Pay button. */\ntype ShopPayButtonBaseOptions = {\n /**\n * Absolute checkout base URL. Omit the URL to link to the same-origin `/checkout` and\n * `/cart` permalink paths, which Hydrogen's Shopify route handler redirects to the\n * store's checkout.\n *\n * Pass the cart's checkout URL when your app doesn't send same-origin checkout paths through the Shopify route handler. The button URL keeps the query params of the checkout URL, replaces any params that Shop Pay sets, and drops the hash. A bare domain such as `my-store.myshopify.com` gets an HTTPS scheme. The Shop Pay functions throw an error when the value isn't a valid URL.\n */\n checkoutUrl?: string;\n /**\n * Checkout payment mode. Defaults to `shop_pay`. Use\n * `shop_pay_installments` to open Shop Pay Installments at checkout.\n */\n paymentOption?: \"shop_pay\" | \"shop_pay_installments\";\n /**\n * Attribution source that the checkout URL carries as `source`.\n * Defaults to `hydrogen`. Most storefronts shouldn't change the source.\n */\n source?: string;\n /**\n * Attribution token that the checkout URL carries as `source_token`.\n */\n sourceToken?: string;\n /**\n * Content Security Policy nonce for the button's style element.\n *\n * The nonce covers only the style element. Custom width and border radius values render as an inline style attribute, which a strict Content Security Policy must allow.\n */\n nonce?: string;\n /**\n * Sales channel that the checkout URL carries as `channel`. Omit the channel unless\n * checkout needs explicit `headless` or `hydrogen` attribution.\n */\n channel?: \"headless\" | \"hydrogen\";\n /**\n * Disables the button. A disabled button renders without an `href` and with\n * `aria-disabled=\"true\"`.\n */\n disabled?: boolean;\n /**\n * CSS width of the button, such as `100%`. Defaults to `260px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the width contains a semicolon or a curly brace.\n */\n width?: string;\n /**\n * CSS border radius of the button, such as `8px`. Defaults to `12px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the radius contains a semicolon or a curly brace.\n */\n borderRadius?: string;\n /**\n * Localized accessible label for the button. Defaults to `\"Buy with Shop Pay\"`.\n * Keep the brand name Shop Pay untranslated and in Latin script in every locale.\n *\n * @example English\n * `\"Buy with Shop Pay\"`\n *\n * @example Japanese\n * `\"Shop Payで購入\"`\n *\n * @example Hindi\n * `\"Shop Pay से खरीदें\"`\n *\n * @example Arabic\n * `\"الشراء باستخدام Shop Pay\"`\n */\n accessibilityLabel?: string;\n};\n\n/** A variant ID and an optional quantity for a Shop Pay checkout. */\ntype ShopPayVariantWithQuantity = {\n /** Product variant GID or numeric variant ID. Product IDs throw an error. */\n id: string;\n /** Quantity of the variant. Defaults to `1`. */\n quantity?: number;\n};\n\ntype ShopPayVariant = string | ShopPayVariantWithQuantity;\n/** Variants for a Shop Pay checkout, as all ID strings or all objects with an ID and a quantity. */\ntype ShopPayVariants = readonly string[] | readonly ShopPayVariantWithQuantity[];\n\n/** Checkout target, variants, attribution, and display settings for a Shop Pay button. */\nexport interface ShopPayButtonOptions extends ShopPayButtonBaseOptions {\n /**\n * Variants that the customer buys right away through a Shopify cart permalink. Omit the variants\n * to check out the current cart.\n *\n * Pass either all variant ID strings or all objects with an `id` and an optional `quantity`. Each quantity must be a positive integer. The Shop Pay functions throw an error for product IDs, non-numeric variant IDs, invalid quantities, and mixed formats.\n */\n variants?: ShopPayVariants;\n}\n\n/**\n * Returns the checkout URL for a Shop Pay button. Use the URL to build your own Shop Pay link.\n *\n * With variants, the URL is a cart permalink that checks out those variants. Without variants, the URL checks out the current cart.\n *\n * @param options The variants, checkout URL, payment mode, attribution, and disabled state for the checkout URL.\n * @returns The checkout URL, or `null` when `disabled` is `true`.\n * @publicDocs\n */\nexport function getShopPayButtonUrl(options: ShopPayButtonOptions): string | null {\n if (options.disabled) return null;\n\n const variants = getShopPayVariants(options);\n\n if (!options.checkoutUrl) {\n const search = getShopPaySearchParams(options);\n return `${variants ? `/cart/${variants}` : \"/checkout\"}?${search}`;\n }\n\n const url = variants\n ? getShopPayVariantModeUrl(options.checkoutUrl, variants)\n : getShopPayCheckoutModeUrl(options.checkoutUrl);\n\n for (const [name, value] of getShopPaySearchParams(options)) {\n url.searchParams.set(name, value);\n }\n\n return url.toString();\n}\n\n/**\n * Returns the Shop Pay button as an HTML string for server templates and frameworks without a Hydrogen binding.\n *\n * On the server, the markup includes the button's styles and link, and the button works without client JavaScript. In the browser, the function returns an empty element that renders the button when you add the element to the page.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button markup.\n * @publicDocs\n */\nexport function renderShopPayButton(options: ShopPayButtonOptions): string {\n defineShopPayButton();\n const attributes = serializeAttributes(getShopPayButtonElementAttributes(options));\n const content = CAN_USE_DOM ? \"\" : getShopPayButtonDeclarativeShadowDomHtml(options);\n return `<${SHOP_PAY_BUTTON_TAG_NAME}${attributes ? ` ${attributes}` : \"\"}>${content}</${SHOP_PAY_BUTTON_TAG_NAME}>`;\n}\n\n/**\n * Creates a Shop Pay button element in the browser. Append the element to the page.\n *\n * The function requires a DOM. Use `renderShopPayButton` during server rendering.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button element, ready to append to the page.\n * @publicDocs\n */\nexport function createShopPayButton(options: ShopPayButtonOptions): HTMLElement {\n defineShopPayButton();\n const element = document.createElement(SHOP_PAY_BUTTON_TAG_NAME);\n initializeShopPayButtonElement(element, options);\n\n return element;\n}\n\nexport function initializeShopPayButtonElement(\n element: HTMLElement,\n options: ShopPayButtonOptions,\n): void {\n syncShopPayButtonElementAttributes(element, getShopPayButtonElementAttributes(options));\n\n const shadowRoot = element.shadowRoot ?? element.attachShadow({ mode: \"open\" });\n const template = element.querySelector(\"template[shadowrootmode]\");\n\n if (template instanceof HTMLTemplateElement) {\n shadowRoot.append(template.content.cloneNode(true));\n template.remove();\n }\n\n renderShopPayButtonShadowRoot(shadowRoot, options);\n}\n\n/**\n * Registers the Shop Pay button custom element in the browser. Call the function when you use the `hydrogen-shop-pay-button` tag directly on a framework without a Hydrogen binding.\n *\n * The Hydrogen Shop Pay components, `createShopPayButton`, and `renderShopPayButton` register the element for you. The function does nothing during server rendering or when the browser already has the element.\n *\n * @returns Nothing.\n * @publicDocs\n */\nexport function defineShopPayButton(): void {\n if (\n typeof customElements === \"undefined\" ||\n typeof HTMLElement === \"undefined\" ||\n customElements.get(SHOP_PAY_BUTTON_TAG_NAME)\n ) {\n return;\n }\n\n customElements.define(\n SHOP_PAY_BUTTON_TAG_NAME,\n class extends HTMLElement {\n #connected = false;\n\n static observedAttributes = SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES;\n\n connectedCallback(): void {\n this.#connected = true;\n initializeShopPayButtonElement(this, getShopPayButtonOptions(this));\n }\n\n attributeChangedCallback(): void {\n if (!this.#connected || !this.shadowRoot) return;\n renderShopPayButtonShadowRoot(this.shadowRoot, getShopPayButtonOptions(this));\n }\n },\n );\n}\n\n/** Anchor attributes shared by server and browser shadow-root rendering. */\nexport function getShopPayButtonAnchorAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {\n class: SHOP_PAY_BUTTON_CLASS_NAME,\n target: \"_self\",\n };\n\n const href = getShopPayButtonUrl(options);\n if (href) {\n attributes.href = href;\n } else {\n attributes.role = \"link\";\n attributes[\"aria-disabled\"] = \"true\";\n }\n\n const style = serializeStyleProperties(getShopPayButtonStyleProperties(options));\n if (style) attributes.style = style;\n\n attributes[\"aria-label\"] = getShopPayAccessibilityLabel(options.accessibilityLabel);\n\n return attributes;\n}\n\nexport function getShopPayButtonElementContentHtml(options: ShopPayButtonOptions): string {\n return `<style${getShopPayButtonStyleNonceAttribute(options)}>${SHOP_PAY_BUTTON_STYLES}</style><a ${serializeAttributes(getShopPayButtonAnchorAttributes(options))}>${getShopPayButtonContentHtml()}</a>`;\n}\n\nexport function getShopPayButtonDeclarativeShadowDomHtml(options: ShopPayButtonOptions): string {\n return `<template shadowrootmode=\"open\" shadowroot=\"open\">${getShopPayButtonElementContentHtml(options)}</template>`;\n}\n\nexport function getShopPayButtonElementAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n const variants = getShopPayVariants(options);\n\n if (hasContent(options.accessibilityLabel)) {\n attributes[\"accessibility-label\"] = options.accessibilityLabel.trim();\n }\n if (hasContent(options.borderRadius)) {\n attributes[\"border-radius\"] = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n if (options.channel) attributes.channel = options.channel;\n if (options.checkoutUrl !== undefined) attributes[\"checkout-url\"] = options.checkoutUrl;\n if (options.disabled) attributes.disabled = \"\";\n if (hasContent(options.nonce)) attributes.nonce = options.nonce.trim();\n if (options.paymentOption) attributes[\"payment-option\"] = options.paymentOption;\n if (options.source !== undefined) attributes.source = options.source;\n if (options.sourceToken !== undefined) attributes[\"source-token\"] = options.sourceToken;\n if (variants) attributes.variants = variants;\n if (hasContent(options.width)) {\n attributes.width = normalizeCssValue(\"width\", options.width);\n }\n\n return attributes;\n}\n\n/** Inner HTML for the shadow root's anchor. */\nexport function getShopPayButtonContentHtml(): string {\n return SHOP_PAY_LOGO_SVG;\n}\n\nfunction getShopPayButtonStyleProperties(\n options: Pick<ShopPayButtonOptions, \"width\" | \"borderRadius\">,\n): Record<string, string> {\n const style: Record<string, string> = {};\n\n if (hasContent(options.width)) style.width = normalizeCssValue(\"width\", options.width);\n if (hasContent(options.borderRadius)) {\n style.borderRadius = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n\n return style;\n}\n\nfunction getShopPaySearchParams(options: ShopPayButtonOptions): URLSearchParams {\n const params = new URLSearchParams();\n params.set(\"payment\", options.paymentOption ?? \"shop_pay\");\n\n const source = options.source ?? DEFAULT_SOURCE;\n if (source) params.set(\"source\", source);\n if (options.sourceToken) params.set(\"source_token\", options.sourceToken);\n if (options.channel) params.set(\"channel\", options.channel);\n\n return params;\n}\n\nfunction getShopPayCheckoutModeUrl(checkoutUrl: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n if (url.pathname === \"/\") url.pathname = \"/checkout\";\n url.hash = \"\";\n return url;\n}\n\nfunction getShopPayVariantModeUrl(checkoutUrl: string, variants: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n url.pathname = `/cart/${variants}`;\n url.hash = \"\";\n return url;\n}\n\nfunction parseCheckoutUrl(checkoutUrl: string): URL {\n try {\n return new URL(normalizeStoreDomain(checkoutUrl.trim()));\n } catch {\n throw shopPayError('Shop Pay requires a valid \"checkoutUrl\" value.');\n }\n}\n\nfunction getShopPayVariants(options: ShopPayButtonOptions): string | undefined {\n const variantsInput: readonly ShopPayVariant[] | undefined = options.variants;\n\n if (!Array.isArray(variantsInput) || variantsInput.length === 0) return undefined;\n\n if (variantsInput.every(isVariantId)) {\n return variantsInput.map((id) => `${normalizeVariantId(id)}:1`).join(\",\");\n }\n\n if (variantsInput.every(isVariantWithQuantity)) {\n return variantsInput\n .map(({ id, quantity }) => {\n return `${normalizeVariantId(id)}:${normalizeQuantity(quantity)}`;\n })\n .join(\",\");\n }\n\n throw shopPayError(\n \"Shop Pay variants must be either variant IDs or objects with an id and quantity.\",\n );\n}\n\nfunction isVariantId(variant: ShopPayVariant): variant is string {\n return typeof variant === \"string\";\n}\n\nfunction getShopPayButtonOptions(element: HTMLElement): ShopPayButtonOptions {\n return {\n accessibilityLabel: element.getAttribute(\"accessibility-label\") ?? undefined,\n borderRadius: element.getAttribute(\"border-radius\") ?? undefined,\n channel: parseChannel(element.getAttribute(\"channel\")),\n checkoutUrl: element.getAttribute(\"checkout-url\") ?? undefined,\n disabled: element.hasAttribute(\"disabled\"),\n nonce: element.nonce || element.getAttribute(\"nonce\") || undefined,\n paymentOption: parsePaymentOption(element.getAttribute(\"payment-option\")),\n source: element.getAttribute(\"source\") ?? undefined,\n sourceToken: element.getAttribute(\"source-token\") ?? undefined,\n variants: parseVariantsAttribute(element.getAttribute(\"variants\")),\n width: element.getAttribute(\"width\") ?? undefined,\n };\n}\n\nfunction parseVariantsAttribute(value: string | null): ShopPayVariants | undefined {\n if (!value) return undefined;\n\n return value.split(\",\").map((entry) => {\n const [id = \"\", quantity] = entry.split(\":\");\n return { id, quantity: quantity === undefined ? undefined : Number(quantity) };\n });\n}\n\nfunction parsePaymentOption(value: string | null): ShopPayButtonOptions[\"paymentOption\"] {\n return value === \"shop_pay\" || value === \"shop_pay_installments\" ? value : undefined;\n}\n\nfunction parseChannel(value: string | null): ShopPayButtonOptions[\"channel\"] {\n return value === \"headless\" || value === \"hydrogen\" ? value : undefined;\n}\n\nfunction renderShopPayButtonShadowRoot(\n shadowRoot: ShadowRoot,\n options: ShopPayButtonOptions,\n): void {\n let style = shadowRoot.querySelector(\"style\");\n if (!(style instanceof HTMLStyleElement)) {\n style = shadowRoot.ownerDocument.createElement(\"style\");\n shadowRoot.prepend(style);\n }\n\n const nextNonce = hasContent(options.nonce) ? options.nonce.trim() : undefined;\n const nonceChanged = (style.nonce || undefined) !== nextNonce;\n if (nextNonce) {\n style.nonce = nextNonce;\n } else {\n style.removeAttribute(\"nonce\");\n }\n if (nonceChanged) style.textContent = \"\";\n if (style.textContent !== SHOP_PAY_BUTTON_STYLES) style.textContent = SHOP_PAY_BUTTON_STYLES;\n\n let anchor = shadowRoot.querySelector(\"a\");\n if (!(anchor instanceof HTMLAnchorElement)) {\n anchor = shadowRoot.ownerDocument.createElement(\"a\");\n shadowRoot.append(anchor);\n }\n\n syncAttributes(anchor, getShopPayButtonAnchorAttributes(options));\n const content = getShopPayButtonContentHtml();\n if (anchor.innerHTML !== content) anchor.innerHTML = content;\n}\n\nfunction syncAttributes(element: Element, attributes: Record<string, string>): void {\n for (const name of element.getAttributeNames()) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction syncShopPayButtonElementAttributes(\n element: Element,\n attributes: Record<string, string>,\n): void {\n for (const name of SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction isVariantWithQuantity(\n variant: ShopPayVariant | undefined,\n): variant is ShopPayVariantWithQuantity {\n return typeof variant === \"object\" && variant !== null && typeof variant.id === \"string\";\n}\n\nfunction normalizeVariantId(id: string): string {\n const parsed = parseGid(id);\n const bareId = parsed.id || id.trim();\n\n if (parsed.resource && parsed.resource !== \"ProductVariant\") {\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n }\n\n if (/^\\d+$/.test(bareId)) return bareId;\n\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n}\n\nfunction normalizeQuantity(quantity = 1): number {\n if (!Number.isInteger(quantity) || quantity < 1) {\n throw shopPayError(\"Shop Pay variant quantities must be positive integers.\");\n }\n\n return quantity;\n}\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \""\");\n}\n\nfunction getShopPayAccessibilityLabel(label: string | undefined): string {\n return hasContent(label) ? label.trim() : DEFAULT_ACCESSIBILITY_LABEL;\n}\n\nfunction getShopPayButtonStyleNonceAttribute(options: Pick<ShopPayButtonOptions, \"nonce\">): string {\n return hasContent(options.nonce) ? ` nonce=\"${escapeAttribute(options.nonce.trim())}\"` : \"\";\n}\n\nfunction hasContent(value: string | undefined): value is string {\n return typeof value === \"string\" && value.trim() !== \"\";\n}\n\nfunction normalizeCssValue(name: \"width\" | \"borderRadius\", value: string): string {\n const normalized = value.trim();\n if (/[;{}]/.test(normalized)) {\n throw shopPayError(`Shop Pay ${name} must be a single CSS value.`);\n }\n return normalized;\n}\n\nfunction serializeAttributes(attributes: Record<string, string>): string {\n return Object.entries(attributes)\n .map(([name, value]) => `${name}=\"${escapeAttribute(value)}\"`)\n .join(\" \");\n}\n\nfunction serializeStyleProperties(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([name, value]) => `${hyphenateStyleName(name)}:${value}`)\n .join(\";\");\n}\n\nfunction hyphenateStyleName(name: string): string {\n return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\n}\n\nfunction shopPayError(message: string): Error {\n return new Error(`${ERROR_PREFIX} ${message}`);\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;AACvB,MAAM,8BAA8B;AACpC,MAAM,eAAe;AACrB,MAAM,cAAc,OAAO,aAAa;;;;;;;;AAQxC,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAM,sCAAsC;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,yBACX,wBACI,2BAA2B,uRAC3B,2BAA2B,mCAC3B,2BAA2B,4DAC3B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,OAAO,QAAQ,WAAW,CAC9B,KAAK,CAAC,MAAM,WAAW,GAAG,KAAK,IAAI,gBAAgB,MAAM,CAAC,GAAG,CAC7D,KAAK,IAAI;;AAGd,SAAS,yBAAyB,OAAuC;AACvE,QAAO,OAAO,QAAQ,MAAM,CACzB,KAAK,CAAC,MAAM,WAAW,GAAG,mBAAmB,KAAK,CAAC,GAAG,QAAQ,CAC9D,KAAK,IAAI;;AAGd,SAAS,mBAAmB,MAAsB;AAChD,QAAO,KAAK,QAAQ,WAAW,UAAU,IAAI,MAAM,aAAa,GAAG;;AAGrE,SAAS,aAAa,SAAwB;AAC5C,wBAAO,IAAI,MAAM,GAAG,aAAa,GAAG,UAAU"}
|
|
1
|
+
{"version":3,"file":"shop-pay.mjs","names":["#connected"],"sources":["../../../../src/core/shop-pay/shop-pay.ts"],"sourcesContent":["import { normalizeStoreDomain } from \"../url\";\nimport { parseGid } from \"../utils/parse-gid\";\n\nconst DEFAULT_SOURCE = \"hydrogen\";\nconst DEFAULT_ACCESSIBILITY_LABEL = \"Buy with Shop Pay\";\nconst ERROR_PREFIX = \"[hydrogen:error:ShopPay]\";\nconst CAN_USE_DOM = typeof document !== \"undefined\";\n/**\n * Tag name of the Shop Pay button custom element, `hydrogen-shop-pay-button`.\n *\n * Use the tag directly on a framework without a Hydrogen binding.\n *\n * @publicDocs\n */\nexport const SHOP_PAY_BUTTON_TAG_NAME = \"hydrogen-shop-pay-button\";\nexport const SHOP_PAY_BUTTON_CLASS_NAME = \"shop-pay-button\";\nconst SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES = [\n \"accessibility-label\",\n \"border-radius\",\n \"channel\",\n \"checkout-url\",\n \"disabled\",\n \"nonce\",\n \"payment-option\",\n \"source\",\n \"source-token\",\n \"variants\",\n \"width\",\n] as const;\n\n/** Button styles matching the hosted shop-js pay button. */\nexport const SHOP_PAY_BUTTON_STYLES =\n `:host{display:block}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}{position:relative;display:flex;align-items:center;box-sizing:border-box;margin:0;padding:10px 16px;overflow:visible;width:260px;border:none;border-radius:12px;background-color:#5433eb;color:#fff;cursor:pointer;text-decoration:none;transition:all .15s cubic-bezier(.4,0,.2,1)}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:hover{background-color:#4524db}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}:focus-visible{outline:none;box-shadow:0 0 0 3px #9c83f8}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}[aria-disabled=true]{opacity:.5;pointer-events:none;cursor:default}` +\n `.${SHOP_PAY_BUTTON_CLASS_NAME}__logo{position:relative;display:inline-block;margin:0 auto;width:88px;height:auto}`;\n\nconst SHOP_PAY_LOGO_SVG =\n `<svg class=\"${SHOP_PAY_BUTTON_CLASS_NAME}__logo\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 99 25\" aria-hidden=\"true\" focusable=\"false\">` +\n '<path fill=\"currentColor\" d=\"M70.842 7.915h2.25c1.561 0 2.328.642 2.328 1.715 0 1.074-.739 1.715-2.259 1.715h-2.32v-3.43ZM80.525 16.142c-.879 0-1.227-.474-1.227-.948 0-.642.725-.935 2.147-1.102l1.115-.125c-.07 1.227-.892 2.175-2.035 2.175Z\"/>' +\n '<path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M65.645.5a3.64 3.64 0 0 0-3.64 3.64V20.7a3.64 3.64 0 0 0 3.64 3.64h29.668a3.64 3.64 0 0 0 3.64-3.64V4.14A3.64 3.64 0 0 0 95.314.5H65.645Zm5.197 16.674v-4.197h2.64c2.412 0 3.695-1.353 3.695-3.402 0-2.05-1.283-3.277-3.695-3.277h-4.341v10.876h1.7Zm9.334.223c1.297 0 2.147-.572 2.538-1.548.112 1.088.767 1.645 2.189 1.269l.014-1.157c-.572.055-.683-.154-.683-.753v-2.845c0-1.673-1.102-2.663-3.138-2.663-2.008 0-3.165 1.004-3.165 2.705h1.562c0-.809.572-1.297 1.576-1.297 1.06 0 1.547.46 1.534 1.255v.363l-1.8.195c-2.021.223-3.137.99-3.137 2.329 0 1.101.781 2.147 2.51 2.147Zm9.906.32c-.711 1.73-1.855 2.245-3.64 2.245h-.766V18.54h.822c.977 0 1.45-.307 1.966-1.185L85.3 9.923h1.757l2.259 5.424 2.008-5.424h1.715l-2.956 7.795Z\" clip-rule=\"evenodd\"/>' +\n '<path fill=\"currentColor\" d=\"M6.992 11.055c-2.359-.509-3.41-.708-3.41-1.612 0-.85.711-1.274 2.134-1.274 1.25 0 2.165.544 2.839 1.61.05.081.155.11.241.066l2.655-1.335a.186.186 0 0 0 .076-.259c-1.102-1.9-3.137-2.94-5.818-2.94C2.188 5.311 0 7.037 0 9.781c0 2.915 2.664 3.651 5.027 4.16 2.362.51 3.417.709 3.417 1.613s-.769 1.33-2.303 1.33c-1.416 0-2.467-.644-3.102-1.896a.186.186 0 0 0-.251-.082L.14 16.21a.188.188 0 0 0-.083.253c1.051 2.102 3.207 3.285 6.087 3.285 3.668 0 5.885-1.698 5.885-4.527 0-2.83-2.677-3.651-5.037-4.16v-.007ZM21.218 5.311c-1.505 0-2.835.531-3.791 1.477-.06.057-.159.015-.159-.067V.687A.185.185 0 0 0 17.081.5h-3.322a.185.185 0 0 0-.187.187v18.73c0 .104.083.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-1.587 1.223-2.804 2.87-2.804 1.649 0 2.843 1.191 2.843 2.804v8.216c0 .104.082.186.187.186h3.322a.185.185 0 0 0 .187-.186V11.2c0-3.452-2.274-5.89-5.459-5.89ZM33.415 4.774c-1.803 0-3.493.55-4.706 1.343a.186.186 0 0 0-.06.25l1.464 2.488c.054.089.168.12.257.066a5.853 5.853 0 0 1 3.052-.834c2.899 0 5.03 2.036 5.03 4.726 0 2.292-1.706 3.99-3.868 3.99-1.762 0-2.985-1.022-2.985-2.463 0-.825.352-1.502 1.27-1.98a.183.183 0 0 0 .073-.258l-1.381-2.327a.187.187 0 0 0-.226-.079c-1.85.683-3.15 2.327-3.15 4.533 0 3.338 2.67 5.83 6.396 5.83 4.35 0 7.478-3 7.478-7.303 0-4.612-3.64-7.982-8.644-7.982ZM51.776 5.283c-1.68 0-3.182.62-4.277 1.707a.093.093 0 0 1-.16-.066v-1.31a.185.185 0 0 0-.187-.186h-3.235a.185.185 0 0 0-.188.187v18.702c0 .104.083.186.188.186h3.32a.185.185 0 0 0 .188-.186v-6.133c0-.082.099-.123.16-.07 1.091 1.012 2.536 1.603 4.19 1.603 3.897 0 6.936-3.139 6.936-7.217 0-4.078-3.042-7.217-6.935-7.217Zm-.63 11.266c-2.215 0-3.895-1.754-3.895-4.074S48.928 8.4 51.147 8.4c2.22 0 3.893 1.726 3.893 4.075 0 2.348-1.651 4.074-3.896 4.074h.003Z\"/>' +\n \"</svg>\";\n\n/** Checkout target, attribution, and display settings shared by every Shop Pay button. */\ntype ShopPayButtonBaseOptions = {\n /**\n * Absolute checkout base URL. Omit the URL to link to the same-origin `/checkout` and\n * `/cart` permalink paths, which Hydrogen's Shopify route handler redirects to the\n * store's checkout.\n *\n * Pass the cart's checkout URL when your app doesn't send same-origin checkout paths through the Shopify route handler. The button URL keeps the query params of the checkout URL, replaces any params that Shop Pay sets, and drops the hash. A bare domain such as `my-store.myshopify.com` gets an HTTPS scheme. The Shop Pay functions throw an error when the value isn't a valid URL.\n */\n checkoutUrl?: string;\n /**\n * Checkout payment mode. Defaults to `shop_pay`. Use\n * `shop_pay_installments` to open Shop Pay Installments at checkout.\n */\n paymentOption?: \"shop_pay\" | \"shop_pay_installments\";\n /**\n * Attribution source that the checkout URL carries as `source`.\n * Defaults to `hydrogen`. Most storefronts shouldn't change the source.\n */\n source?: string;\n /**\n * Attribution token that the checkout URL carries as `source_token`.\n */\n sourceToken?: string;\n /**\n * Content Security Policy nonce for the button's style element.\n *\n * The nonce covers only the style element. Custom width and border radius values render as an inline style attribute, which a strict Content Security Policy must allow.\n */\n nonce?: string;\n /**\n * Sales channel that the checkout URL carries as `channel`. Omit the channel unless\n * checkout needs explicit `headless` or `hydrogen` attribution.\n */\n channel?: \"headless\" | \"hydrogen\";\n /**\n * Disables the button. A disabled button renders without an `href` and with\n * `aria-disabled=\"true\"`.\n */\n disabled?: boolean;\n /**\n * CSS width of the button, such as `100%`. Defaults to `260px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the width contains a semicolon or a curly brace.\n */\n width?: string;\n /**\n * CSS border radius of the button, such as `8px`. Defaults to `12px`.\n *\n * Pass a single CSS value. The Shop Pay functions throw an error when the radius contains a semicolon or a curly brace.\n */\n borderRadius?: string;\n /**\n * Localized accessible label for the button. Defaults to `\"Buy with Shop Pay\"`.\n * Keep the brand name Shop Pay untranslated and in Latin script in every locale.\n *\n * @example English\n * `\"Buy with Shop Pay\"`\n *\n * @example Japanese\n * `\"Shop Payで購入\"`\n *\n * @example Hindi\n * `\"Shop Pay से खरीदें\"`\n *\n * @example Arabic\n * `\"الشراء باستخدام Shop Pay\"`\n */\n accessibilityLabel?: string;\n};\n\n/** A variant ID and an optional quantity for a Shop Pay checkout. */\ntype ShopPayVariantWithQuantity = {\n /** Product variant GID or numeric variant ID. Product IDs throw an error. */\n id: string;\n /** Quantity of the variant. Defaults to `1`. */\n quantity?: number;\n};\n\ntype ShopPayVariant = string | ShopPayVariantWithQuantity;\n/** Variants for a Shop Pay checkout, as all ID strings or all objects with an ID and a quantity. */\ntype ShopPayVariants = readonly string[] | readonly ShopPayVariantWithQuantity[];\n\n/** Checkout target, variants, attribution, and display settings for a Shop Pay button. */\nexport interface ShopPayButtonOptions extends ShopPayButtonBaseOptions {\n /**\n * Variants that the customer buys right away through a Shopify cart permalink. Omit the variants\n * to check out the current cart.\n *\n * Pass either all variant ID strings or all objects with an `id` and an optional `quantity`. Each quantity must be a positive integer. The Shop Pay functions throw an error for product IDs, non-numeric variant IDs, invalid quantities, and mixed formats.\n */\n variants?: ShopPayVariants;\n}\n\n/**\n * Returns the checkout URL for a Shop Pay button. Use the URL to build your own Shop Pay link.\n *\n * With variants, the URL is a cart permalink that checks out those variants. Without variants, the URL checks out the current cart.\n *\n * @param options The variants, checkout URL, payment mode, attribution, and disabled state for the checkout URL.\n * @returns The checkout URL, or `null` when `disabled` is `true`.\n * @publicDocs\n */\nexport function getShopPayButtonUrl(options: ShopPayButtonOptions): string | null {\n if (options.disabled) return null;\n\n const variants = getShopPayVariants(options);\n\n if (!options.checkoutUrl) {\n const search = getShopPaySearchParams(options);\n return `${variants ? `/cart/${variants}` : \"/checkout\"}?${search}`;\n }\n\n const url = variants\n ? getShopPayVariantModeUrl(options.checkoutUrl, variants)\n : getShopPayCheckoutModeUrl(options.checkoutUrl);\n\n for (const [name, value] of getShopPaySearchParams(options)) {\n url.searchParams.set(name, value);\n }\n\n return url.toString();\n}\n\n/**\n * Returns the Shop Pay button as an HTML string for server templates and frameworks without a Hydrogen binding.\n *\n * On the server, the markup includes the button's styles and link, and the button works without client JavaScript. In the browser, the function returns an empty element that renders the button when you add the element to the page.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button markup.\n * @publicDocs\n */\nexport function renderShopPayButton(options: ShopPayButtonOptions): string {\n defineShopPayButton();\n const attributes = serializeAttributes(getShopPayButtonElementAttributes(options));\n const content = CAN_USE_DOM ? \"\" : getShopPayButtonDeclarativeShadowDomHtml(options);\n return `<${SHOP_PAY_BUTTON_TAG_NAME}${attributes ? ` ${attributes}` : \"\"}>${content}</${SHOP_PAY_BUTTON_TAG_NAME}>`;\n}\n\n/**\n * Creates a Shop Pay button element in the browser. Append the element to the page.\n *\n * The function requires a DOM. Use `renderShopPayButton` during server rendering.\n *\n * @param options The variants, checkout URL, and display settings for the button.\n * @returns The Shop Pay button element, ready to append to the page.\n * @publicDocs\n */\nexport function createShopPayButton(options: ShopPayButtonOptions): HTMLElement {\n defineShopPayButton();\n const element = document.createElement(SHOP_PAY_BUTTON_TAG_NAME);\n initializeShopPayButtonElement(element, options);\n\n return element;\n}\n\nexport function initializeShopPayButtonElement(\n element: HTMLElement,\n options: ShopPayButtonOptions,\n): void {\n syncShopPayButtonElementAttributes(element, getShopPayButtonElementAttributes(options));\n\n const template = element.querySelector(\"template[shadowrootmode]\");\n let shadowRoot = element.shadowRoot;\n\n if (!shadowRoot) {\n shadowRoot = element.attachShadow({ mode: \"open\" });\n if (template instanceof HTMLTemplateElement) {\n shadowRoot.append(template.content.cloneNode(true));\n }\n }\n template?.remove();\n\n renderShopPayButtonShadowRoot(shadowRoot, options);\n}\n\n/**\n * Registers the Shop Pay button custom element in the browser. Call the function when you use the `hydrogen-shop-pay-button` tag directly on a framework without a Hydrogen binding.\n *\n * The Hydrogen Shop Pay components, `createShopPayButton`, and `renderShopPayButton` register the element for you. The function does nothing during server rendering or when the browser already has the element.\n *\n * @returns Nothing.\n * @publicDocs\n */\nexport function defineShopPayButton(): void {\n if (\n typeof customElements === \"undefined\" ||\n typeof HTMLElement === \"undefined\" ||\n customElements.get(SHOP_PAY_BUTTON_TAG_NAME)\n ) {\n return;\n }\n\n customElements.define(\n SHOP_PAY_BUTTON_TAG_NAME,\n class extends HTMLElement {\n #connected = false;\n\n static observedAttributes = SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES;\n\n connectedCallback(): void {\n this.#connected = true;\n initializeShopPayButtonElement(this, getShopPayButtonOptions(this));\n }\n\n attributeChangedCallback(): void {\n if (!this.#connected || !this.shadowRoot) return;\n renderShopPayButtonShadowRoot(this.shadowRoot, getShopPayButtonOptions(this));\n }\n },\n );\n}\n\n/** Anchor attributes shared by server and browser shadow-root rendering. */\nexport function getShopPayButtonAnchorAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {\n class: SHOP_PAY_BUTTON_CLASS_NAME,\n target: \"_self\",\n };\n\n const href = getShopPayButtonUrl(options);\n if (href) {\n attributes.href = href;\n } else {\n attributes.role = \"link\";\n attributes[\"aria-disabled\"] = \"true\";\n }\n\n const style = serializeStyleProperties(getShopPayButtonStyleProperties(options));\n if (style) attributes.style = style;\n\n attributes[\"aria-label\"] = getShopPayAccessibilityLabel(options.accessibilityLabel);\n\n return attributes;\n}\n\nexport function getShopPayButtonElementContentHtml(options: ShopPayButtonOptions): string {\n return `<style${getShopPayButtonStyleNonceAttribute(options)}>${SHOP_PAY_BUTTON_STYLES}</style><a ${serializeAttributes(getShopPayButtonAnchorAttributes(options))}>${getShopPayButtonContentHtml()}</a>`;\n}\n\nexport function getShopPayButtonDeclarativeShadowDomHtml(options: ShopPayButtonOptions): string {\n return `<template shadowrootmode=\"open\" shadowroot=\"open\">${getShopPayButtonElementContentHtml(options)}</template>`;\n}\n\nexport function getShopPayButtonElementAttributes(\n options: ShopPayButtonOptions,\n): Record<string, string> {\n const attributes: Record<string, string> = {};\n const variants = getShopPayVariants(options);\n\n if (hasContent(options.accessibilityLabel)) {\n attributes[\"accessibility-label\"] = options.accessibilityLabel.trim();\n }\n if (hasContent(options.borderRadius)) {\n attributes[\"border-radius\"] = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n if (options.channel) attributes.channel = options.channel;\n if (options.checkoutUrl !== undefined) attributes[\"checkout-url\"] = options.checkoutUrl;\n if (options.disabled) attributes.disabled = \"\";\n if (hasContent(options.nonce)) attributes.nonce = options.nonce.trim();\n if (options.paymentOption) attributes[\"payment-option\"] = options.paymentOption;\n if (options.source !== undefined) attributes.source = options.source;\n if (options.sourceToken !== undefined) attributes[\"source-token\"] = options.sourceToken;\n if (variants) attributes.variants = variants;\n if (hasContent(options.width)) {\n attributes.width = normalizeCssValue(\"width\", options.width);\n }\n\n return attributes;\n}\n\n/** Inner HTML for the shadow root's anchor. */\nexport function getShopPayButtonContentHtml(): string {\n return SHOP_PAY_LOGO_SVG;\n}\n\nfunction getShopPayButtonStyleProperties(\n options: Pick<ShopPayButtonOptions, \"width\" | \"borderRadius\">,\n): Record<string, string> {\n const style: Record<string, string> = {};\n\n if (hasContent(options.width)) style.width = normalizeCssValue(\"width\", options.width);\n if (hasContent(options.borderRadius)) {\n style.borderRadius = normalizeCssValue(\"borderRadius\", options.borderRadius);\n }\n\n return style;\n}\n\nfunction getShopPaySearchParams(options: ShopPayButtonOptions): URLSearchParams {\n const params = new URLSearchParams();\n params.set(\"payment\", options.paymentOption ?? \"shop_pay\");\n\n const source = options.source ?? DEFAULT_SOURCE;\n if (source) params.set(\"source\", source);\n if (options.sourceToken) params.set(\"source_token\", options.sourceToken);\n if (options.channel) params.set(\"channel\", options.channel);\n\n return params;\n}\n\nfunction getShopPayCheckoutModeUrl(checkoutUrl: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n if (url.pathname === \"/\") url.pathname = \"/checkout\";\n url.hash = \"\";\n return url;\n}\n\nfunction getShopPayVariantModeUrl(checkoutUrl: string, variants: string): URL {\n const url = parseCheckoutUrl(checkoutUrl);\n url.pathname = `/cart/${variants}`;\n url.hash = \"\";\n return url;\n}\n\nfunction parseCheckoutUrl(checkoutUrl: string): URL {\n try {\n return new URL(normalizeStoreDomain(checkoutUrl.trim()));\n } catch {\n throw shopPayError('Shop Pay requires a valid \"checkoutUrl\" value.');\n }\n}\n\nfunction getShopPayVariants(options: ShopPayButtonOptions): string | undefined {\n const variantsInput: readonly ShopPayVariant[] | undefined = options.variants;\n\n if (!Array.isArray(variantsInput) || variantsInput.length === 0) return undefined;\n\n if (variantsInput.every(isVariantId)) {\n return variantsInput.map((id) => `${normalizeVariantId(id)}:1`).join(\",\");\n }\n\n if (variantsInput.every(isVariantWithQuantity)) {\n return variantsInput\n .map(({ id, quantity }) => {\n return `${normalizeVariantId(id)}:${normalizeQuantity(quantity)}`;\n })\n .join(\",\");\n }\n\n throw shopPayError(\n \"Shop Pay variants must be either variant IDs or objects with an id and quantity.\",\n );\n}\n\nfunction isVariantId(variant: ShopPayVariant): variant is string {\n return typeof variant === \"string\";\n}\n\nfunction getShopPayButtonOptions(element: HTMLElement): ShopPayButtonOptions {\n return {\n accessibilityLabel: element.getAttribute(\"accessibility-label\") ?? undefined,\n borderRadius: element.getAttribute(\"border-radius\") ?? undefined,\n channel: parseChannel(element.getAttribute(\"channel\")),\n checkoutUrl: element.getAttribute(\"checkout-url\") ?? undefined,\n disabled: element.hasAttribute(\"disabled\"),\n nonce: element.nonce || element.getAttribute(\"nonce\") || undefined,\n paymentOption: parsePaymentOption(element.getAttribute(\"payment-option\")),\n source: element.getAttribute(\"source\") ?? undefined,\n sourceToken: element.getAttribute(\"source-token\") ?? undefined,\n variants: parseVariantsAttribute(element.getAttribute(\"variants\")),\n width: element.getAttribute(\"width\") ?? undefined,\n };\n}\n\nfunction parseVariantsAttribute(value: string | null): ShopPayVariants | undefined {\n if (!value) return undefined;\n\n return value.split(\",\").map((entry) => {\n const [id = \"\", quantity] = entry.split(\":\");\n return { id, quantity: quantity === undefined ? undefined : Number(quantity) };\n });\n}\n\nfunction parsePaymentOption(value: string | null): ShopPayButtonOptions[\"paymentOption\"] {\n return value === \"shop_pay\" || value === \"shop_pay_installments\" ? value : undefined;\n}\n\nfunction parseChannel(value: string | null): ShopPayButtonOptions[\"channel\"] {\n return value === \"headless\" || value === \"hydrogen\" ? value : undefined;\n}\n\nfunction renderShopPayButtonShadowRoot(\n shadowRoot: ShadowRoot,\n options: ShopPayButtonOptions,\n): void {\n let style = shadowRoot.querySelector(\"style\");\n if (!(style instanceof HTMLStyleElement)) {\n style = shadowRoot.ownerDocument.createElement(\"style\");\n shadowRoot.prepend(style);\n }\n\n const nextNonce = hasContent(options.nonce) ? options.nonce.trim() : undefined;\n const nonceChanged = (style.nonce || undefined) !== nextNonce;\n if (nextNonce) {\n style.nonce = nextNonce;\n } else {\n style.removeAttribute(\"nonce\");\n }\n if (nonceChanged) style.textContent = \"\";\n if (style.textContent !== SHOP_PAY_BUTTON_STYLES) style.textContent = SHOP_PAY_BUTTON_STYLES;\n\n let anchor = shadowRoot.querySelector(\"a\");\n if (!(anchor instanceof HTMLAnchorElement)) {\n anchor = shadowRoot.ownerDocument.createElement(\"a\");\n shadowRoot.append(anchor);\n }\n\n syncAttributes(anchor, getShopPayButtonAnchorAttributes(options));\n const content = getShopPayButtonContentHtml();\n if (anchor.innerHTML !== content) anchor.innerHTML = content;\n}\n\nfunction syncAttributes(element: Element, attributes: Record<string, string>): void {\n for (const name of element.getAttributeNames()) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction syncShopPayButtonElementAttributes(\n element: Element,\n attributes: Record<string, string>,\n): void {\n for (const name of SHOP_PAY_BUTTON_OBSERVED_ATTRIBUTES) {\n if (!(name in attributes)) element.removeAttribute(name);\n }\n\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) element.setAttribute(name, value);\n }\n}\n\nfunction isVariantWithQuantity(\n variant: ShopPayVariant | undefined,\n): variant is ShopPayVariantWithQuantity {\n return typeof variant === \"object\" && variant !== null && typeof variant.id === \"string\";\n}\n\nfunction normalizeVariantId(id: string): string {\n const parsed = parseGid(id);\n const bareId = parsed.id || id.trim();\n\n if (parsed.resource && parsed.resource !== \"ProductVariant\") {\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n }\n\n if (/^\\d+$/.test(bareId)) return bareId;\n\n throw shopPayError(\n \"Shop Pay variant IDs must be Shopify ProductVariant GIDs or bare numeric variant IDs.\",\n );\n}\n\nfunction normalizeQuantity(quantity = 1): number {\n if (!Number.isInteger(quantity) || quantity < 1) {\n throw shopPayError(\"Shop Pay variant quantities must be positive integers.\");\n }\n\n return quantity;\n}\n\nfunction escapeText(value: string): string {\n return value.replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\");\n}\n\nfunction escapeAttribute(value: string): string {\n return escapeText(value).replace(/\"/g, \""\");\n}\n\nfunction getShopPayAccessibilityLabel(label: string | undefined): string {\n return hasContent(label) ? label.trim() : DEFAULT_ACCESSIBILITY_LABEL;\n}\n\nfunction getShopPayButtonStyleNonceAttribute(options: Pick<ShopPayButtonOptions, \"nonce\">): string {\n return hasContent(options.nonce) ? ` nonce=\"${escapeAttribute(options.nonce.trim())}\"` : \"\";\n}\n\nfunction hasContent(value: string | undefined): value is string {\n return typeof value === \"string\" && value.trim() !== \"\";\n}\n\nfunction normalizeCssValue(name: \"width\" | \"borderRadius\", value: string): string {\n const normalized = value.trim();\n if (/[;{}]/.test(normalized)) {\n throw shopPayError(`Shop Pay ${name} must be a single CSS value.`);\n }\n return normalized;\n}\n\nfunction serializeAttributes(attributes: Record<string, string>): string {\n return Object.entries(attributes)\n .map(([name, value]) => `${name}=\"${escapeAttribute(value)}\"`)\n .join(\" \");\n}\n\nfunction serializeStyleProperties(style: Record<string, string>): string {\n return Object.entries(style)\n .map(([name, value]) => `${hyphenateStyleName(name)}:${value}`)\n .join(\";\");\n}\n\nfunction hyphenateStyleName(name: string): string {\n return name.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);\n}\n\nfunction shopPayError(message: string): Error {\n return new Error(`${ERROR_PREFIX} ${message}`);\n}\n"],"mappings":";;;;AAGA,MAAM,iBAAiB;AACvB,MAAM,8BAA8B;AACpC,MAAM,eAAe;AACrB,MAAM,cAAc,OAAO,aAAa;;;;;;;;AAQxC,MAAa,2BAA2B;AACxC,MAAa,6BAA6B;AAC1C,MAAM,sCAAsC;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,yBACX,wBACI,2BAA2B,uRAC3B,2BAA2B,mCAC3B,2BAA2B,4DAC3B,2BAA2B,sEAC3B,2BAA2B;AAEjC,MAAM,oBACJ,eAAe,2BAA2B;;;;;;;;;;AA6G5C,SAAgB,oBAAoB,SAA8C;AAChF,KAAI,QAAQ,SAAU,QAAO;CAE7B,MAAM,WAAW,mBAAmB,QAAQ;AAE5C,KAAI,CAAC,QAAQ,aAAa;EACxB,MAAM,SAAS,uBAAuB,QAAQ;AAC9C,SAAO,GAAG,WAAW,SAAS,aAAa,YAAY,GAAG;;CA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Gd,SAAS,mBAAmB,MAAsB;AAChD,QAAO,KAAK,QAAQ,WAAW,UAAU,IAAI,MAAM,aAAa,GAAG;;AAGrE,SAAS,aAAa,SAAwB;AAC5C,wBAAO,IAAI,MAAM,GAAG,aAAa,GAAG,UAAU"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { asInlineScript } from "./utils/inline-script.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/shopify-scripts/analytics.ts
|
|
4
|
-
const initializeShopifyAnalyticsBus =
|
|
4
|
+
const initializeShopifyAnalyticsBus = /* @__PURE__ */ decodeURIComponent("(function()%7Blet%20e%3D%7Btrace%3A%60debug%60%2Cdebug%3A%60debug%60%2Cinfo%3A%60info%60%2Cwarn%3A%60warn%60%2Cerror%3A%60error%60%2Cfatal%3A%60error%60%7D%3Bfunction%20t(e%2Ct)%7Breturn%60%5Bhydrogen%3A%24%7Be%7D%3A%24%7Bt%7D%5D%60%7Dfunction%20n(n%2Cr%2Ci)%7Blet%7Bscope%3Aa%2Cerror%3Ao%2C...s%7D%3Di%3F%3F%7B%7D%2Cc%3D%5Ba%3F%60%24%7Bt(n%2Ca)%7D%20%24%7Br%7D%60%3Ar%5D%3Bo!%3D%3Dvoid%200%26%26c.push(o)%2CObject.keys(s).length%3E0%26%26c.push(s)%2Cconsole%5Be%5Bn%5D%5D(...c)%7Dlet%20r%3D%7Btrace%3A(e%2Ct)%3D%3En(%60trace%60%2Ce%2Ct)%2Cdebug%3A(e%2Ct)%3D%3En(%60debug%60%2Ce%2Ct)%2Cinfo%3A(e%2Ct)%3D%3En(%60info%60%2Ce%2Ct)%2Cwarn%3A(e%2Ct)%3D%3En(%60warn%60%2Ce%2Ct)%2Cerror%3A(e%2Ct)%3D%3En(%60error%60%2Ce%2Ct)%2Cfatal%3A(e%2Ct)%3D%3En(%60fatal%60%2Ce%2Ct)%7D%2Ci%3D%60https%3A%2F%2Fcdn.shopify.com%60%3B%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%2C%60%24%7Bi%7D%60%3Blet%20a%3D%60consentTrackingApiLoaded%60%2Co%3D%60visitorConsentCollected%60%3Bfunction%20s()%7Bif(typeof%20window%3E%60u%60)return%3Blet%20e%3Dwindow%3Breturn%20e.Shopify%3F%3F%3D%7B%7D%7Dfunction%20c(e)%7Breturn%20typeof%20e%3D%3D%60object%60%26%26!!e%26%26!Array.isArray(e)%7Dlet%20l%3DSymbol.for(%60shopify.hydrogen.custom-consent%60)%3Bfunction%20u(e)%7Blet%20t%3D(typeof%20window%3E%60u%60%3Fvoid%200%3Awindow.Shopify%3F.customerPrivacy)%3F.__internal%2Cn%3D%7BgenerateFallback%3A!0%2Ctag%3Ae%7D%3Breturn%7BuniqueToken%3At%3F.uniqueToken%3F.(n)%3F%3F%60%60%2CvisitToken%3At%3F.visitToken%3F.(n)%3F%3F%60%60%7D%7Dfunction%20d(e%2Ct)%7Be.nextReplaySequence%3DMath.max(e.nextReplaySequence%2Ct.sequence%2B1)%3Blet%20n%3De.subscriptions.get(t.event)%3Bif(n!%3D%3Dvoid%200)for(let%20i%20of%20n)try%7Bi(t.payload%2Ce.context)%7Dcatch(t)%7Br.error(%60error%20in%20analytics%20destination%20%22%24%7Be.name%7D%22%60%2C%7Bscope%3A%60analytics%60%2Cerror%3At%7D)%7D%7Dfunction%20f(e)%7Blet%20t%3D0%2Cn%3D!0%2Ci%3D%5B%5D%2Ca%3Dnew%20Set%2Co%3Dnew%20Set%2Cs%3Dnew%20Map%3Bfunction%20c(n)%7Bif(n.catchingUp)return%3Bn.catchingUp%3D!0%3Blet%20o%3Dt%3Btry%7Bfor(%3Ba.has(n)%26%26e.canTrack()%3B)%7Bif(t-o%3E500)%7Br.error(%60too%20many%20analytics%20events%20were%20published%20while%20delivering%20to%20destination%20%22%24%7Bn.name%7D%22%60%2C%7Bscope%3A%60analytics%60%7D)%3Breturn%7Dlet%20e%3Di%5B0%5D%3Bif(e%3D%3D%3Dvoid%200)return%3Blet%20a%3Di%5BMath.max(0%2Cn.nextReplaySequence-e.sequence)%5D%3Bif(a%3D%3D%3Dvoid%200)return%3Bd(n%2Ca)%7D%7Dfinally%7Bn.catchingUp%3D!1%7D%7Dfunction%20l(t%3D!1)%7Bif(!e.canTrack())%7Bt%26%26(i.length%3D0%2Cn%3D!1)%3Breturn%7Dn%3D!0%3Bfor(let%20e%20of%20a)c(e)%7Dfunction%20f(t)%7Bif(o.has(t.name))return%20r.warn(%60analytics%20destination%20%22%24%7Bt.name%7D%22%20is%20already%20registered%60%2C%7Bscope%3A%60analytics%60%7D)%2C()%3D%3E%7B%7D%3Bo.add(t.name)%3Blet%20n%3Ds.get(t.name)%3F%3F0%3Bs.delete(t.name)%3Blet%20i%3D%60hydrogen%3A%24%7Bt.name%7D%60%2Cc%3D%7Bname%3At.name%2Ccontext%3A%7BgetTrackingValues%3A()%3D%3Ee.canTrack()%3Fu(i)%3A%7BuniqueToken%3A%60%60%2CvisitToken%3A%60%60%7D%7D%2Csubscriptions%3Anew%20Map%2CnextReplaySequence%3An%2CcatchingUp%3A!1%7D%2Cd%3D!1%2Cf%3D(t%2Cn)%3D%3E%7Bif(d)return()%3D%3E%7B%7D%3Bif(e.isSupportedEvent%26%26!e.isSupportedEvent(t))return%20e.warnUnsupportedEvent%3F.(t)%2C()%3D%3E%7B%7D%3Blet%20r%3Dc.subscriptions.get(t)%3Breturn%20r%7C%7C(r%3Dnew%20Set%2Cc.subscriptions.set(t%2Cr))%2Cr.add(n)%2C()%3D%3E%7Blet%20e%3Dc.subscriptions.get(t)%3Be%3F.delete(n)%2Ce%3F.size%3D%3D%3D0%26%26c.subscriptions.delete(t)%7D%7D%2Cp%3D()%3D%3E%7Bif(!d)%7Bd%3D!0%2Ca.delete(c)%2Co.delete(t.name)%2Cs.set(t.name%2Cc.nextReplaySequence)%3Bfor(let%20e%20of%20c.subscriptions.values())e.clear()%3Bc.subscriptions.clear()%2Cc.cleanup%3F.()%7D%7D%2Cm%3De%3D%3E%7Bif(d)%7Be%3F.()%3Breturn%7Dtypeof%20e%3D%3D%60function%60%26%26(c.cleanup%3De)%2Ca.add(c)%2Cl()%7D%3Btry%7Blet%20n%3Dt.setup(%7Bsubscribe%3Af%2CgetConfig%3Ae.getConfig%7D)%3Bn%26%26typeof%20n.then%3D%3D%60function%60%3Fn.then(m).catch(e%3D%3E%7Br.error(%60error%20setting%20up%20analytics%20destination%20%22%24%7Bt.name%7D%22%60%2C%7Bscope%3A%60analytics%60%2Cerror%3Ae%7D)%2Cp()%7D)%3Am(n)%7Dcatch(e)%7Br.error(%60error%20setting%20up%20analytics%20destination%20%22%24%7Bt.name%7D%22%60%2C%7Bscope%3A%60analytics%60%2Cerror%3Ae%7D)%2Cp()%7Dreturn%20p%7Dfunction%20p(r%2Co)%7Blet%20s%3De.canTrack()%3Bif(s%26%26(n%3D!0)%2Cn%26%26(i.push(%7Bsequence%3At%2Cevent%3Ar%2Cpayload%3Ao%7D)%2Ci.length%3E500%26%26i.shift())%2Ct%2B%2B%2Cs)for(let%20e%20of%20a)c(e)%7Dfunction%20m()%7Bi.length%3D0%3Bfor(let%20e%20of%20a)e.subscriptions.clear()%2Ce.cleanup%3F.()%3Ba.clear()%2Co.clear()%2Cs.clear()%7Dreturn%7BaddDestination%3Af%2ConPublish%3Ap%2Creplay%3Al%2Cdestroy%3Am%7D%7Dlet%20p%3D%7BPAGE_VIEWED%3A%60page_viewed%60%2CPRODUCT_VIEWED%3A%60product_viewed%60%2CCOLLECTION_VIEWED%3A%60collection_viewed%60%2CCART_VIEWED%3A%60cart_viewed%60%2CSEARCH_VIEWED%3A%60search_viewed%60%2CCART_UPDATED%3A%60cart_updated%60%2CPRODUCT_ADD_TO_CART%3A%60product_added_to_cart%60%2CPRODUCT_REMOVED_FROM_CART%3A%60product_removed_from_cart%60%7D%2Cm%3D%60gid%3A%2F%2Fshopify%2FShop%2F%60%3Bfunction%20h(e)%7Breturn%20e.startsWith(m)%3Fe%3A%60%24%7Bm%7D%24%7Be%7D%60%7Dfunction%20g(e)%7Breturn%20e%3F%7B...e%2CshopId%3Ah(e.shopId)%7D%3Anull%7Dlet%20_%3Dnew%20Set(%5Bp.PAGE_VIEWED%2Cp.PRODUCT_VIEWED%2Cp.COLLECTION_VIEWED%2Cp.CART_VIEWED%2Cp.SEARCH_VIEWED%5D)%2Cv%3Dnew%20Set(Object.values(p))%3Bfunction%20y()%7Bif(!(typeof%20window%3E%60u%60))return%20window.location.href%7Dfunction%20b(e%2Ct)%7Breturn%20Object.prototype.hasOwnProperty.call(e%2Ct)%7Dfunction%20x(e%2Ct)%7Breturn%20c(e)%3Fb(e%2C%60shop%60)%3F%7B...e%2Cshop%3Ag(e.shop)%7D%3A%7B...e%2Cshop%3At%7D%3Ae%7Dfunction%20S(e%2Ct)%7Bif(!_.has(e)%7C%7C!c(t)%7C%7Ctypeof%20t.url%3D%3D%60string%60%26%26t.url.length%3E0)return%20t%3Blet%20n%3Dy()%3Breturn%20n%3F%7B...t%2Curl%3An%7D%3At%7Dfunction%20C()%7Btry%7Blet%20e%3Dwindow.Shopify%3F.customerPrivacy%3Bif(e%3F.consentStatus!%3D%3D%60loaded%60)return!1%3Blet%20t%3De.currentVisitorConsent%3F.()%3Breturn%20c(t)%26%26t.analytics%3D%3D%3D%60no%60%3F!1%3Ae%3F.analyticsProcessingAllowed%3F.()%3F%3F!1%7Dcatch%7Breturn!1%7D%7Dfunction%20w(e)%7Breturn%20typeof%20e%3D%3D%60string%60%26%26v.has(e)%7Dfunction%20T(e)%7Br.warn(%60unsupported%20analytics%20event%20%22%24%7BString(e)%7D%22%60%2C%7Bscope%3A%60analytics%60%7D)%7Dfunction%20E()%7Btry%7Blet%20e%3Dwindow.Shopify%3F.customerPrivacy%3Breturn%20typeof%20e%3F.shouldShowGDPRBanner%3D%3D%60function%60%3Fe.shouldShowGDPRBanner()%3A!0%7Dcatch%7Breturn!0%7D%7Dfunction%20D(e)%7Breturn%20e%3D%3D%3Dvoid%200%3F%7B%7D%3Ae%7Dfunction%20O(e)%7Bif(typeof%20window%3C%60u%60%26%26window.Shopify%3F.analytics)throw%20Error(%60Analytics%20bus%20already%20initialized.%20Only%20one%20instance%20is%20allowed%20per%20page.%60)%3Blet%7Bconsent%3At%2CcustomData%3An%7D%3De%2Ci%3Dt%3F.mode%3D%3D%3D%60default-banner%60%2Cu%3Dt%3F.mode%3D%3D%3D%60custom-banner%60%2Cd%3D!u%26%26!i%2Cp%3Dg(e.shop)%2Cm%3D!1%3Bfunction%20h()%7Breturn%7Bshop%3Ap%2Cconsent%3At%2CcustomData%3An%7D%7Dlet%20_%3Df(%7BcanTrack%3A()%3D%3Ed%26%26C()%2CgetConfig%3Ah%2CisSupportedEvent%3Aw%2CwarnUnsupportedEvent%3AT%7D)%3Bfunction%20v(e%2C...t)%7Bif(m)return%3Bif(!w(e))%7BT(e)%3Breturn%7Dlet%20n%3DS(e%2Cx(D(t%5B0%5D)%2Cp))%3B_.onPublish(e%2Cn)%7Dlet%20y%3Bfunction%20b()%7Bif(typeof%20document%3E%60u%60)return%3Blet%20e%2Ct%3D!1%2Cn%3D()%3D%3E%7Bm%7C%7C(d%3D!0%2C_.replay(!0))%7D%2Cs%3Dasync()%3D%3E%7Bif(!(m%7C%7Cwindow.Shopify%3F.customerPrivacy%3F.consentStatus!%3D%3D%60loaded%60))%7Bif(u)%7Bif(!e%7C%7Ct)return%3Bt%3D!0%3Btry%7Bawait%20e()%2Cn()%7Dcatch(e)%7Br.error(%60custom%20consent%20setup%20failed%60%2C%7Bscope%3A%60consent%60%2Cerror%3Ae%7D)%7Dreturn%7Dif(i%7C%7Cc(window.privacyBanner))%7Bif(t)%7B_.replay()%3Breturn%7Dif(t%3D!0%2CE())%7Bd%3D!1%3Breturn%7Dn()%3Breturn%7D_.replay()%7D%7D%2Cf%3D()%3D%3E%7Bm%7C%7Cu%26%26(s()%2C!d)%7C%7C(t%3D!0%2Cn())%7D%3Bu%26%26Object.defineProperty(A%2Cl%2C%7Bvalue(t)%7Be%3F%3F%3Dt%2Cs()%7D%7D)%2Cdocument.addEventListener(a%2Cs)%2Cdocument.addEventListener(o%2Cf)%2Cs()%2Cy%3D()%3D%3E%7Bdocument.removeEventListener(a%2Cs)%2Cdocument.removeEventListener(o%2Cf)%7D%7Dfunction%20O()%7Bif(typeof%20window%3E%60u%60)return%3Blet%20e%3DA%2Ct%3Ds()%3Bt%26%26(t.analytics%3De)%7Dfunction%20k()%7Bm%3D!0%2C_.destroy()%2Cy%3F.()%2Ctypeof%20window%3C%60u%60%26%26window.Shopify%3F.analytics%3D%3D%3DA%26%26delete%20window.Shopify.analytics%7Dlet%20A%3D%7Bpublish%3Av%2CaddDestination%3A_.addDestination%2CgetConfig%3Ah%7D%3Breturn%20p%3F.shopId%26%26String(p.shopId).endsWith(%60%2F68817551382%60)%26%26r.warn(%60mock%20shop%20detected%3B%20analytics%20will%20not%20work%20properly%60%2C%7Bscope%3A%60analytics%60%7D)%2Cb()%2CO()%2C%7Bbus%3AA%2Cdestroy%3Ak%7D%7Dfunction%20k(e)%7Be%26%26O(e)%7Dk(JSON.parse((document.currentScript%20instanceof%20HTMLScriptElement%20%26%26%20document.currentScript).dataset.config))%7D)()%3B");
|
|
5
5
|
function getShopifyAnalyticsConfig({ analytics, consent, shop }) {
|
|
6
6
|
const channel = analytics?.channel ?? "hydrogen";
|
|
7
7
|
return {
|
|
@@ -17,10 +17,8 @@ function getShopifyAnalyticsConfig({ analytics, consent, shop }) {
|
|
|
17
17
|
customData: analytics?.customData
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return asInlineScript(initializeShopifyAnalyticsBus)(analytics);
|
|
22
|
-
}
|
|
20
|
+
const shopifyAnalyticsBootstrap = /* @__PURE__ */ asInlineScript(initializeShopifyAnalyticsBus);
|
|
23
21
|
|
|
24
22
|
//#endregion
|
|
25
|
-
export {
|
|
23
|
+
export { getShopifyAnalyticsConfig, shopifyAnalyticsBootstrap };
|
|
26
24
|
//# sourceMappingURL=analytics.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/analytics.ts"],"sourcesContent":["import initializeShopifyAnalyticsBus from \"../analytics/cdn/bootstrap\" with { type: \"script\" };\nimport type { StorefrontAnalyticsConfig } from \"../analytics/types\";\nimport type { ShopifyScriptTagsOptions } from \"./types\";\nimport { asInlineScript } from \"./utils/inline-script\";\n\nexport function getShopifyAnalyticsConfig({\n analytics,\n consent,\n shop,\n}: Pick<ShopifyScriptTagsOptions, \"analytics\" | \"consent\" | \"shop\">): StorefrontAnalyticsConfig {\n const channel = analytics?.channel ?? \"hydrogen\";\n\n return {\n shop:\n channel === \"headless\"\n ? { shopId: shop.shopId, channel }\n : { shopId: shop.shopId, storefrontId: shop.storefrontId, channel },\n consent: consent?.mode ? { mode: consent.mode } : {},\n customData: analytics?.customData,\n };\n}\n\nexport
|
|
1
|
+
{"version":3,"file":"analytics.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/analytics.ts"],"sourcesContent":["import initializeShopifyAnalyticsBus from \"../analytics/cdn/bootstrap\" with { type: \"script\" };\nimport type { StorefrontAnalyticsConfig } from \"../analytics/types\";\nimport type { ShopifyScriptTagsOptions } from \"./types\";\nimport { asInlineScript } from \"./utils/inline-script\";\n\nexport function getShopifyAnalyticsConfig({\n analytics,\n consent,\n shop,\n}: Pick<ShopifyScriptTagsOptions, \"analytics\" | \"consent\" | \"shop\">): StorefrontAnalyticsConfig {\n const channel = analytics?.channel ?? \"hydrogen\";\n\n return {\n shop:\n channel === \"headless\"\n ? { shopId: shop.shopId, channel }\n : { shopId: shop.shopId, storefrontId: shop.storefrontId, channel },\n consent: consent?.mode ? { mode: consent.mode } : {},\n customData: analytics?.customData,\n };\n}\n\nexport const shopifyAnalyticsBootstrap = /* @__PURE__ */ asInlineScript(\n initializeShopifyAnalyticsBus,\n);\n"],"mappings":";;;AAAA,MAAM,gCAAwC,mCAAyB,qyRAAuB;AAK9F,SAAgB,0BAA0B,EACxC,WACA,SACA,QAC8F;CAC9F,MAAM,UAAU,WAAW,WAAW;AAEtC,QAAO;EACL,MACE,YAAY,aACR;GAAE,QAAQ,KAAK;GAAQ;GAAQ,GAC/B;GAAE,QAAQ,KAAK;GAAQ,cAAc,KAAK;GAAc;GAAS;EACvE,SAAS,SAAS,OAAO,EAAE,MAAM,QAAQ,MAAM,GAAG,EAAE;EACpD,YAAY,WAAW;EACxB;;AAGH,MAAa,4BAA4C,+BACvD,8BACD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/core/shopify-scripts/constants.ts
|
|
2
|
+
const SHOPIFY_ORIGIN = "https://shopify.com";
|
|
2
3
|
const SHOPIFY_CDN_ORIGIN = "https://cdn.shopify.com";
|
|
3
4
|
const SHOPIFY_SHOP_APP_ORIGIN = "https://shop.app";
|
|
5
|
+
const SHOPIFY_SHOP_COM_ORIGIN = "https://shop.com";
|
|
4
6
|
const SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-actions.js`;
|
|
5
7
|
const SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events.js`;
|
|
6
8
|
const SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events-inspector.js`;
|
|
@@ -17,5 +19,5 @@ const CONSENT_TRACKING_API_LOADED_EVENT = "consentTrackingApiLoaded";
|
|
|
17
19
|
const VISITOR_CONSENT_COLLECTED_EVENT = "visitorConsentCollected";
|
|
18
20
|
|
|
19
21
|
//#endregion
|
|
20
|
-
export { CONSENT_TRACKING_API_LOADED_EVENT, SHOPIFY_ACCOUNT_SCRIPT, SHOPIFY_CDN_ORIGIN, SHOPIFY_CONSENT_API_SCRIPT, SHOPIFY_CONSENT_SCRIPT_ID, SHOPIFY_INBOX_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT_ID, SHOPIFY_PRIVACY_BANNER_SCRIPT, SHOPIFY_SHOP_APP_ORIGIN, SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT, SHOPIFY_STOREFRONT_WEBMCP_SCRIPT, VISITOR_CONSENT_COLLECTED_EVENT };
|
|
22
|
+
export { CONSENT_TRACKING_API_LOADED_EVENT, SHOPIFY_ACCOUNT_SCRIPT, SHOPIFY_CDN_ORIGIN, SHOPIFY_CONSENT_API_SCRIPT, SHOPIFY_CONSENT_SCRIPT_ID, SHOPIFY_INBOX_SCRIPT, SHOPIFY_ORIGIN, SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT_ID, SHOPIFY_PRIVACY_BANNER_SCRIPT, SHOPIFY_SHOP_APP_ORIGIN, SHOPIFY_SHOP_COM_ORIGIN, SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT, SHOPIFY_STOREFRONT_WEBMCP_SCRIPT, VISITOR_CONSENT_COLLECTED_EVENT };
|
|
21
23
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/constants.ts"],"sourcesContent":["export const SHOPIFY_CDN_ORIGIN = \"https://cdn.shopify.com\";\nexport const SHOPIFY_SHOP_APP_ORIGIN = \"https://shop.app\";\nexport const SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-actions.js`;\nexport const SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events.js`;\nexport const SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events-inspector.js`;\nexport const SHOPIFY_STOREFRONT_WEBMCP_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/storefront/webmcp/webmcp.js`;\nexport const SHOPIFY_ACCOUNT_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/web-components/account.js`;\nexport const SHOPIFY_INBOX_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/web-components/agent.js`;\n\nexport const SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/analytics/shopify.js`;\n\nexport const SHOPIFY_PERF_KIT_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/perf-kit/shopify-perf-kit-spa.min.js?v2`;\nexport const SHOPIFY_CONSENT_API_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/consent-tracking-api/v0.2/consent-tracking-api.js`;\nexport const SHOPIFY_PRIVACY_BANNER_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/privacy-banner/storefront-banner.js`;\n\nexport const SHOPIFY_CONSENT_SCRIPT_ID = \"shopify-consent\";\nexport const SHOPIFY_PERF_KIT_SCRIPT_ID = \"shopify-perfkit\";\n\nexport const CONSENT_TRACKING_API_LOADED_EVENT = \"consentTrackingApiLoaded\";\nexport const VISITOR_CONSENT_COLLECTED_EVENT = \"visitorConsentCollected\";\n"],"mappings":";AAAA,MAAa,qBAAqB;AAClC,MAAa,0BAA0B;AACvC,MAAa,6CAA6C,GAAG,mBAAmB;AAChF,MAAa,4CAA4C,GAAG,mBAAmB;AAC/E,MAAa,sDAAsD,GAAG,mBAAmB;AACzF,MAAa,mCAAmC,GAAG,mBAAmB;AACtE,MAAa,yBAAyB,GAAG,mBAAmB;AAC5D,MAAa,uBAAuB,GAAG,mBAAmB;AAE1D,MAAa,sCAAsC,GAAG,mBAAmB;AAEzE,MAAa,0BAA0B,GAAG,mBAAmB;AAC7D,MAAa,6BAA6B,GAAG,mBAAmB;AAChE,MAAa,gCAAgC,GAAG,mBAAmB;AAEnE,MAAa,4BAA4B;AACzC,MAAa,6BAA6B;AAE1C,MAAa,oCAAoC;AACjD,MAAa,kCAAkC"}
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/constants.ts"],"sourcesContent":["export const SHOPIFY_ORIGIN = \"https://shopify.com\";\nexport const SHOPIFY_CDN_ORIGIN = \"https://cdn.shopify.com\";\nexport const SHOPIFY_SHOP_APP_ORIGIN = \"https://shop.app\";\n// Shop is moving from shop.app to shop.com, so allow both until the move completes.\nexport const SHOPIFY_SHOP_COM_ORIGIN = \"https://shop.com\";\nexport const SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-actions.js`;\nexport const SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events.js`;\nexport const SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/standard-events-inspector.js`;\nexport const SHOPIFY_STOREFRONT_WEBMCP_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/storefront/webmcp/webmcp.js`;\nexport const SHOPIFY_ACCOUNT_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/web-components/account.js`;\nexport const SHOPIFY_INBOX_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/web-components/agent.js`;\n\nexport const SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/storefront/analytics/shopify.js`;\n\nexport const SHOPIFY_PERF_KIT_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/perf-kit/shopify-perf-kit-spa.min.js?v2`;\nexport const SHOPIFY_CONSENT_API_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/consent-tracking-api/v0.2/consent-tracking-api.js`;\nexport const SHOPIFY_PRIVACY_BANNER_SCRIPT = `${SHOPIFY_CDN_ORIGIN}/shopifycloud/privacy-banner/storefront-banner.js`;\n\nexport const SHOPIFY_CONSENT_SCRIPT_ID = \"shopify-consent\";\nexport const SHOPIFY_PERF_KIT_SCRIPT_ID = \"shopify-perfkit\";\n\nexport const CONSENT_TRACKING_API_LOADED_EVENT = \"consentTrackingApiLoaded\";\nexport const VISITOR_CONSENT_COLLECTED_EVENT = \"visitorConsentCollected\";\n"],"mappings":";AAAA,MAAa,iBAAiB;AAC9B,MAAa,qBAAqB;AAClC,MAAa,0BAA0B;AAEvC,MAAa,0BAA0B;AACvC,MAAa,6CAA6C,GAAG,mBAAmB;AAChF,MAAa,4CAA4C,GAAG,mBAAmB;AAC/E,MAAa,sDAAsD,GAAG,mBAAmB;AACzF,MAAa,mCAAmC,GAAG,mBAAmB;AACtE,MAAa,yBAAyB,GAAG,mBAAmB;AAC5D,MAAa,uBAAuB,GAAG,mBAAmB;AAE1D,MAAa,sCAAsC,GAAG,mBAAmB;AAEzE,MAAa,0BAA0B,GAAG,mBAAmB;AAC7D,MAAa,6BAA6B,GAAG,mBAAmB;AAChE,MAAa,gCAAgC,GAAG,mBAAmB;AAEnE,MAAa,4BAA4B;AACzC,MAAa,6BAA6B;AAE1C,MAAa,oCAAoC;AACjD,MAAa,kCAAkC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { normalizePathPrefix, trimTrailingSlashes } from "../standard-routes/path.mjs";
|
|
1
2
|
import { matchStandardRouteUrl } from "../standard-routes/match.mjs";
|
|
2
3
|
import { resolveStandardRouteUrl } from "../standard-routes/redirects.mjs";
|
|
3
4
|
import { SHOPIFY_API_PROXY_PREFIX, isHydrogenServerHandoffPath } from "../url.mjs";
|
|
4
5
|
import { asInlineScript } from "./utils/inline-script.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/core/shopify-scripts/global.ts
|
|
7
|
-
const initializeShopifyGlobal =
|
|
8
|
+
const initializeShopifyGlobal = /* @__PURE__ */ decodeURIComponent("(function()%7Bfunction%20e(e)%7Blet%20t%3DSymbol.for(%60shopify.hydrogen.global.initialized%60)%2Cn%3Dwindow%3Bif(n%5Bt%5D%3D%3D%3D!0)return%3Blet%20r%3DObject.assign(n.Shopify%3F%3F%3D%7B%7D%2Ce%2C%7Bcomponents%3A%7Bconfig%3A%7BstoreDomain%3Awindow.location.origin%2Ccountry%3Ae.country%2Clanguage%3Ae.locale%7D%7D%7D)%3Br.customerPrivacy.config.consentDomain%3Dwindow.location.host%2Cn%5Bt%5D%3D!0%7De(JSON.parse((document.currentScript%20instanceof%20HTMLScriptElement%20%26%26%20document.currentScript).dataset.config))%7D)()%3B");
|
|
8
9
|
const DEFAULT_COUNTRY = "US";
|
|
9
10
|
const DEFAULT_LOCALE = "en";
|
|
10
11
|
const DEFAULT_ROUTES_ROOT = "/";
|
|
@@ -54,17 +55,19 @@ function shouldHandoff(url) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
function getShopifyRoutesRoot(pathPrefix) {
|
|
57
|
-
const normalizedPathPrefix = pathPrefix
|
|
58
|
-
return normalizedPathPrefix ?
|
|
58
|
+
const normalizedPathPrefix = normalizePathPrefix(pathPrefix);
|
|
59
|
+
return normalizedPathPrefix ? `${normalizedPathPrefix}/` : DEFAULT_ROUTES_ROOT;
|
|
59
60
|
}
|
|
60
61
|
function normalizeMyshopifyDomain(domain) {
|
|
61
|
-
return domain.trim().replace(/^https?:\/\//i, "")
|
|
62
|
+
return trimTrailingSlashes(domain.trim().replace(/^https?:\/\//i, ""));
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
const shopifyGlobalBootstrap = /* @__PURE__ */ asInlineScript(initializeShopifyGlobal);
|
|
65
|
+
function getShopifyGlobalConfig({ i18n, shop }) {
|
|
66
|
+
return {
|
|
67
|
+
application: {
|
|
68
|
+
name: "hydrogen",
|
|
69
|
+
version: "2026.10.3"
|
|
70
|
+
},
|
|
68
71
|
country: i18n?.country ?? DEFAULT_COUNTRY,
|
|
69
72
|
...i18n?.currency !== void 0 ? { currency: { active: i18n.currency.toUpperCase() } } : {},
|
|
70
73
|
locale: (i18n?.language ?? DEFAULT_LOCALE).toLowerCase(),
|
|
@@ -83,9 +86,8 @@ function getShopifyGlobalBootstrapScript({ i18n, shop }) {
|
|
|
83
86
|
} }
|
|
84
87
|
} }
|
|
85
88
|
};
|
|
86
|
-
return asInlineScript(initializeShopifyGlobal)(config);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
//#endregion
|
|
90
|
-
export { configureShopifyRouting, getShopifyGlobal,
|
|
92
|
+
export { configureShopifyRouting, getShopifyGlobal, getShopifyGlobalConfig, shopifyGlobalBootstrap };
|
|
91
93
|
//# sourceMappingURL=global.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/global.ts"],"sourcesContent":["import type { ShopifyGlobal } from \"../../globals\";\nimport type {
|
|
1
|
+
{"version":3,"file":"global.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/global.ts"],"sourcesContent":["import type { ShopifyGlobal } from \"../../globals\";\nimport type { ShopifyCountryCode, ShopifyLanguageCode } from \"../i18n/types\";\nimport {\n matchStandardRouteUrl,\n resolveStandardRouteUrl,\n type ShopifyRouteTemplates,\n} from \"../standard-routes/index\";\nimport { normalizePathPrefix, trimTrailingSlashes } from \"../standard-routes/path\";\nimport { SHOPIFY_API_PROXY_PREFIX, isHydrogenServerHandoffPath } from \"../url\";\nimport initializeShopifyGlobal from \"./global-script\" with { type: \"script\" };\nimport type { ShopifyScriptsI18n } from \"./types\";\nimport type { ShopifyScriptsShop } from \"./types\";\nimport { asInlineScript } from \"./utils/inline-script\";\n\nexport type ShopifyGlobalConfig = {\n application: ShopifyGlobal[\"application\"];\n country: ShopifyCountryCode;\n currency?: NonNullable<ShopifyGlobal[\"currency\"]>;\n locale: Lowercase<ShopifyLanguageCode>;\n customerPrivacy: {\n config: NonNullable<ShopifyGlobal[\"customerPrivacy\"][\"config\"]> & {\n /** Temporary diagnostic metadata for instrumentation; does not change consent or token behavior. */\n debug: {\n hydrogen: {\n generation: number;\n serverTiming: boolean;\n };\n };\n };\n };\n routes: {\n root: string;\n apiProxyPrefix: string;\n };\n shop: string;\n};\n\nexport type IncompleteCustomerPrivacy = Partial<\n Omit<ShopifyGlobal[\"customerPrivacy\"], \"config\">\n> & {\n config?: Partial<NonNullable<ShopifyGlobal[\"customerPrivacy\"][\"config\"]>>;\n};\n\nexport type IncompleteShopifyGlobal = Partial<Omit<ShopifyGlobal, \"customerPrivacy\" | \"routes\">> & {\n customerPrivacy?: IncompleteCustomerPrivacy;\n routes?: Partial<ShopifyGlobal[\"routes\"]> & Record<string, unknown>;\n [key: string]: unknown;\n};\n\nconst DEFAULT_COUNTRY: ShopifyGlobalConfig[\"country\"] = \"US\";\nconst DEFAULT_LOCALE: ShopifyGlobalConfig[\"locale\"] = \"en\";\nconst DEFAULT_ROUTES_ROOT: ShopifyGlobalConfig[\"routes\"][\"root\"] = \"/\";\n\n/**\n * Returns the browser's `window.Shopify` object, creating it when needed.\n *\n * This is SSR-safe and returns `undefined` outside the browser.\n */\nexport function getShopifyGlobal(): IncompleteShopifyGlobal | undefined {\n if (typeof window === \"undefined\") return undefined;\n\n const shopifyWindow: { Shopify?: IncompleteShopifyGlobal } = window;\n return (shopifyWindow.Shopify ??= {});\n}\n\n/**\n * Configures Shopify runtime routing hooks used by storefront scripts.\n *\n * This is SSR-safe and no-ops outside the browser.\n */\nexport function configureShopifyRouting({\n navigate,\n routes,\n}: {\n navigate?: ShopifyGlobal[\"routes\"][\"navigate\"];\n routes?: ShopifyRouteTemplates;\n}) {\n const shopify = getShopifyGlobal();\n if (!shopify) return;\n\n const getRouteOptions = (url: string) => ({\n baseUrl: window.location.href,\n pathPrefix: shopify.routes?.root,\n routeTemplates: routes ?? {},\n url,\n });\n\n shopify.routes ??= {};\n shopify.routes.match = (url) => matchStandardRouteUrl(getRouteOptions(url));\n shopify.routes.resolve = (url) => resolveStandardRouteUrl(getRouteOptions(url));\n\n const navigateTo = navigate ?? documentNavigate;\n shopify.routes.navigate = (url) => {\n if (shouldHandoff(url)) {\n return documentNavigate(url);\n }\n\n return navigateTo(shopify.routes?.resolve?.(url) ?? url);\n };\n // Deprecated, kept for temporary backwards compat with WebMCP\n shopify.navigate = shopify.routes.navigate;\n}\n\nfunction documentNavigate(url: string): void {\n window.location.assign(url);\n}\n\nfunction shouldHandoff(url: string): boolean {\n try {\n const parsedUrl = new URL(url, window.location.href);\n\n return (\n parsedUrl.origin === window.location.origin && isHydrogenServerHandoffPath(parsedUrl.pathname)\n );\n } catch {\n return false;\n }\n}\n\nfunction getShopifyRoutesRoot(pathPrefix: string | undefined): string {\n const normalizedPathPrefix = normalizePathPrefix(pathPrefix);\n\n return normalizedPathPrefix ? `${normalizedPathPrefix}/` : DEFAULT_ROUTES_ROOT;\n}\n\nfunction normalizeMyshopifyDomain(domain: string): string {\n return trimTrailingSlashes(domain.trim().replace(/^https?:\\/\\//i, \"\"));\n}\n\nexport const shopifyGlobalBootstrap = /* @__PURE__ */ asInlineScript(initializeShopifyGlobal);\n\nexport function getShopifyGlobalConfig({\n i18n,\n shop,\n}: {\n i18n?: ShopifyScriptsI18n;\n shop: ShopifyScriptsShop;\n}): ShopifyGlobalConfig {\n return {\n application: { name: \"hydrogen\", version: __HYDROGEN_VERSION__ },\n country: i18n?.country ?? DEFAULT_COUNTRY,\n ...(i18n?.currency !== undefined ? { currency: { active: i18n.currency.toUpperCase() } } : {}),\n // oxlint-disable-next-line typescript/consistent-type-assertions\n locale: (i18n?.language ?? DEFAULT_LOCALE).toLowerCase() as Lowercase<\n ShopifyGlobalConfig[\"locale\"]\n >,\n routes: {\n root: getShopifyRoutesRoot(i18n?.pathPrefix),\n apiProxyPrefix: SHOPIFY_API_PROXY_PREFIX,\n },\n shop: normalizeMyshopifyDomain(shop.myshopifyDomain),\n customerPrivacy: {\n config: {\n isHeadless: true,\n asyncConsent: true,\n asyncVisitorState: true,\n debug: {\n hydrogen: {\n generation: 3,\n serverTiming: false,\n },\n },\n },\n },\n };\n}\n"],"mappings":";;;;;;;AASA,MAAM,0BAAwC,mCAAqB,uhBAAU;AAwC7E,MAAM,kBAAkD;AACxD,MAAM,iBAAgD;AACtD,MAAM,sBAA6D;;;;;;AAOnE,SAAgB,mBAAwD;AACtE,KAAI,OAAO,WAAW,YAAa,QAAO;CAE1C,MAAM,gBAAuD;AAC7D,QAAQ,cAAc,YAAY,EAAE;;;;;;;AAQtC,SAAgB,wBAAwB,EACtC,UACA,UAIC;CACD,MAAM,UAAU,kBAAkB;AAClC,KAAI,CAAC,QAAS;CAEd,MAAM,mBAAmB,SAAiB;EACxC,SAAS,OAAO,SAAS;EACzB,YAAY,QAAQ,QAAQ;EAC5B,gBAAgB,UAAU,EAAE;EAC5B;EACD;AAED,SAAQ,WAAW,EAAE;AACrB,SAAQ,OAAO,SAAS,QAAQ,sBAAsB,gBAAgB,IAAI,CAAC;AAC3E,SAAQ,OAAO,WAAW,QAAQ,wBAAwB,gBAAgB,IAAI,CAAC;CAE/E,MAAM,aAAa,YAAY;AAC/B,SAAQ,OAAO,YAAY,QAAQ;AACjC,MAAI,cAAc,IAAI,CACpB,QAAO,iBAAiB,IAAI;AAG9B,SAAO,WAAW,QAAQ,QAAQ,UAAU,IAAI,IAAI,IAAI;;AAG1D,SAAQ,WAAW,QAAQ,OAAO;;AAGpC,SAAS,iBAAiB,KAAmB;AAC3C,QAAO,SAAS,OAAO,IAAI;;AAG7B,SAAS,cAAc,KAAsB;AAC3C,KAAI;EACF,MAAM,YAAY,IAAI,IAAI,KAAK,OAAO,SAAS,KAAK;AAEpD,SACE,UAAU,WAAW,OAAO,SAAS,UAAU,4BAA4B,UAAU,SAAQ;SAEzF;AACN,SAAO;;;AAIX,SAAS,qBAAqB,YAAwC;CACpE,MAAM,uBAAuB,oBAAoB,WAAW;AAE5D,QAAO,uBAAuB,GAAG,qBAAqB,KAAK;;AAG7D,SAAS,yBAAyB,QAAwB;AACxD,QAAO,oBAAoB,OAAO,MAAM,CAAC,QAAQ,iBAAiB,GAAG,CAAC;;AAGxE,MAAa,yBAAyC,+BAAe,wBAAwB;AAE7F,SAAgB,uBAAuB,EACrC,MACA,QAIsB;AACtB,QAAO;EACL,aAAa;GAAE,MAAM;GAAY;GAA+B;EAChE,SAAS,MAAM,WAAW;EAC1B,GAAI,MAAM,aAAa,SAAY,EAAE,UAAU,EAAE,QAAQ,KAAK,SAAS,aAAa,EAAE,EAAE,GAAG,EAAE;EAE7F,SAAS,MAAM,YAAY,gBAAgB,aAAa;EAGxD,QAAQ;GACN,MAAM,qBAAqB,MAAM,WAAW;GAC5C,gBAAgB;GACjB;EACD,MAAM,yBAAyB,KAAK,gBAAgB;EACpD,iBAAiB,EACf,QAAQ;GACN,YAAY;GACZ,cAAc;GACd,mBAAmB;GACnB,OAAO,EACL,UAAU;IACR,YAAY;IACZ,cAAc;IACf,EACF;GACF,EACF;EACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/core/shopify-scripts/hashes.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns CSP hashes for the static inline bootstraps rendered by ShopifyScripts and the tag helpers.
|
|
4
|
+
* Add these to script-src when using hashes instead of nonces. Values include CSP quotes by default;
|
|
5
|
+
* pass `quoted: false` for framework configuration that expects unquoted hashes.
|
|
6
|
+
* Hashes authorize Shopify's bootstraps, not framework scripts.
|
|
7
|
+
* @publicDocs
|
|
8
|
+
*/
|
|
9
|
+
declare function getShopifyScriptHashes(options: {
|
|
10
|
+
quoted: false;
|
|
11
|
+
}): `sha256-${string}`[];
|
|
12
|
+
declare function getShopifyScriptHashes(options?: {
|
|
13
|
+
quoted?: boolean;
|
|
14
|
+
}): string[];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { getShopifyScriptHashes };
|
|
17
|
+
//# sourceMappingURL=hashes.d.mts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/core/shopify-scripts/hashes.ts
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
const hashes = ["'sha256-0MNiDs/D7mtwHYpQm0rknKAzL5iffEbG8iRUm6TQoOs='","'sha256-W6HUmx+dw8rzw9biZP5defg/l0p3yfMInFj/BFw6e5E='"];
|
|
6
|
+
function getShopifyScriptHashes({ quoted = true } = {}) {
|
|
7
|
+
return quoted ? [...hashes] : hashes.map((hash) => hash.slice(1, -1));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getShopifyScriptHashes };
|
|
12
|
+
//# sourceMappingURL=hashes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashes.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/hashes.ts"],"sourcesContent":["/**\n * @internal\n */\nconst hashes = __SCRIPT_HASHES__;\n\n/**\n * Returns CSP hashes for the static inline bootstraps rendered by ShopifyScripts and the tag helpers.\n * Add these to script-src when using hashes instead of nonces. Values include CSP quotes by default;\n * pass `quoted: false` for framework configuration that expects unquoted hashes.\n * Hashes authorize Shopify's bootstraps, not framework scripts.\n * @publicDocs\n */\nexport function getShopifyScriptHashes(options: { quoted: false }): `sha256-${string}`[];\nexport function getShopifyScriptHashes(options?: { quoted?: boolean }): string[];\nexport function getShopifyScriptHashes({ quoted = true }: { quoted?: boolean } = {}): string[] {\n return quoted ? [...hashes] : hashes.map((hash) => hash.slice(1, -1));\n}\n"],"mappings":";;;;AAGA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,iHAAA;AAWf,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAgB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAuB,CAAA,CAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA+B,CAAA,CAAE,CAAA,CAAY;AAC7F,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAC,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAG,CAAA,CAAA,CAAG,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ShopifyRoutesOptions, ShopifyScriptTagDescriptor, ShopifyScriptTagDescriptors, ShopifyScriptTagsOptions, ShopifyScriptsAnalyticsConfig, ShopifyScriptsI18n, ShopifyScriptsOptions, ShopifyScriptsShop } from "./types.mjs";
|
|
2
|
+
import { getShopifyScriptHashes } from "./hashes.mjs";
|
|
2
3
|
import { initializeShopifyScripts } from "./initialize.mjs";
|
|
3
4
|
//#region src/core/shopify-scripts/index.d.ts
|
|
4
5
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { getShopifyAnalyticsBusScript, getShopifyAnalyticsConfig } from "./analytics.mjs";
|
|
2
1
|
import { CONSENT_TRACKING_API_LOADED_EVENT, SHOPIFY_ACCOUNT_SCRIPT, SHOPIFY_CDN_ORIGIN, SHOPIFY_CONSENT_API_SCRIPT, SHOPIFY_CONSENT_SCRIPT_ID, SHOPIFY_INBOX_SCRIPT, SHOPIFY_PERF_KIT_SCRIPT, SHOPIFY_PRIVACY_BANNER_SCRIPT, SHOPIFY_SHOP_APP_ORIGIN, SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT, SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT, SHOPIFY_STOREFRONT_WEBMCP_SCRIPT, VISITOR_CONSENT_COLLECTED_EVENT } from "./constants.mjs";
|
|
3
|
-
import {
|
|
2
|
+
import { getShopifyScriptHashes } from "./hashes.mjs";
|
|
3
|
+
import { getShopifyAnalyticsConfig, shopifyAnalyticsBootstrap } from "./analytics.mjs";
|
|
4
|
+
import { getShopifyGlobal, getShopifyGlobalConfig, shopifyGlobalBootstrap } from "./global.mjs";
|
|
4
5
|
import { getPerfKitScript } from "./perfkit.mjs";
|
|
5
6
|
import { renderShopifyScriptTag } from "./render.mjs";
|
|
6
7
|
import { initializeShopifyScripts } from "./initialize.mjs";
|
|
@@ -53,12 +54,13 @@ function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n
|
|
|
53
54
|
tagName: "script",
|
|
54
55
|
attributes: {
|
|
55
56
|
id: "shopify-global-bootstrap",
|
|
56
|
-
...nonceAttributes
|
|
57
|
+
...nonceAttributes,
|
|
58
|
+
...shopifyGlobalBootstrap.attributes(getShopifyGlobalConfig({
|
|
59
|
+
i18n,
|
|
60
|
+
shop
|
|
61
|
+
}))
|
|
57
62
|
},
|
|
58
|
-
innerHTML:
|
|
59
|
-
i18n,
|
|
60
|
-
shop
|
|
61
|
-
})
|
|
63
|
+
innerHTML: shopifyGlobalBootstrap.code
|
|
62
64
|
}, {
|
|
63
65
|
tagName: "script",
|
|
64
66
|
attributes: {
|
|
@@ -105,9 +107,10 @@ function getShopifyScriptTags({ account = false, analytics, consent, debug, i18n
|
|
|
105
107
|
tagName: "script",
|
|
106
108
|
attributes: {
|
|
107
109
|
id: "shopify-analytics-bus",
|
|
108
|
-
...nonceAttributes
|
|
110
|
+
...nonceAttributes,
|
|
111
|
+
...shopifyAnalyticsBootstrap.attributes(analyticsConfig)
|
|
109
112
|
},
|
|
110
|
-
innerHTML:
|
|
113
|
+
innerHTML: shopifyAnalyticsBootstrap.code
|
|
111
114
|
});
|
|
112
115
|
scripts.push({
|
|
113
116
|
tagName: "script",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/core/shopify-scripts/index.ts"],"sourcesContent":["import { shopifyAnalyticsBootstrap, getShopifyAnalyticsConfig } from \"./analytics\";\nimport {\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_SCRIPT_ID,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n} from \"./constants\";\nimport { getShopifyGlobalConfig, shopifyGlobalBootstrap } from \"./global\";\nimport { getPerfKitScript } from \"./perfkit\";\nimport { renderShopifyScriptTag } from \"./render\";\nimport type {\n ShopifyLinkDescriptor,\n ShopifyScriptDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n} from \"./types\";\n\nexport {\n CONSENT_TRACKING_API_LOADED_EVENT,\n SHOPIFY_ACCOUNT_SCRIPT,\n SHOPIFY_CDN_ORIGIN,\n SHOPIFY_CONSENT_API_SCRIPT,\n SHOPIFY_PERF_KIT_SCRIPT,\n SHOPIFY_PRIVACY_BANNER_SCRIPT,\n SHOPIFY_SHOP_APP_ORIGIN,\n SHOPIFY_INBOX_SCRIPT,\n SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n SHOPIFY_STOREFRONT_WEBMCP_SCRIPT,\n VISITOR_CONSENT_COLLECTED_EVENT,\n} from \"./constants\";\nexport { getShopifyGlobal } from \"./global\";\nexport { getShopifyScriptHashes } from \"./hashes\";\nexport { initializeShopifyScripts } from \"./initialize\";\nexport { renderShopifyScriptTag } from \"./render\";\nexport type {\n ShopifyScriptsAnalyticsConfig,\n ShopifyRoutesOptions,\n ShopifyScriptTagDescriptor,\n ShopifyScriptTagDescriptors,\n ShopifyScriptTagsOptions,\n ShopifyScriptsOptions,\n ShopifyScriptsI18n,\n ShopifyScriptsShop,\n} from \"./types\";\n\n/**\n * Returns Shopify's storefront script and link tags as descriptors.\n *\n * Render the descriptors in the document head during server rendering, then call\n * `initializeShopifyScripts` in the browser. Keep the tags in the returned order. The inline\n * scripts set up globals that later scripts read.\n *\n * @param options - The shop details, the localization, the consent configuration, and the features whose scripts to load.\n * @returns The link tags, the script tags, and a combined list with links first.\n * @publicDocs\n */\n// oxlint-disable-next-line complexity -- ordered assembly of optional Shopify script tags; each flag adds one branch and splitting would obscure the required load order\nexport function getShopifyScriptTags({\n account = false,\n analytics,\n consent,\n debug,\n i18n,\n nonce,\n shop,\n shopifyAnalytics = true,\n inbox = false,\n}: ShopifyScriptTagsOptions): ShopifyScriptTagDescriptors {\n const nonceAttributes = nonce !== undefined ? { nonce } : undefined;\n const analyticsConfig = getShopifyAnalyticsConfig({ analytics, consent, shop });\n\n const links: ShopifyLinkDescriptor[] = [\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_CDN_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"preconnect\",\n href: SHOPIFY_SHOP_APP_ORIGIN,\n },\n },\n {\n tagName: \"link\",\n attributes: {\n rel: \"prefetch\",\n as: \"script\",\n href: SHOPIFY_STOREFRONT_STANDARD_EVENTS_SCRIPT,\n crossorigin: \"anonymous\",\n },\n },\n ];\n const scripts: ShopifyScriptDescriptor[] = [\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-global-bootstrap\",\n ...nonceAttributes,\n ...shopifyGlobalBootstrap.attributes(getShopifyGlobalConfig({ i18n, shop })),\n },\n innerHTML: shopifyGlobalBootstrap.code,\n },\n {\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-actions\",\n type: \"module\",\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_ACTIONS_SCRIPT,\n },\n },\n ];\n\n if (__DEV__ && debug?.standardEventsInspector) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-standard-events-inspector\",\n defer: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_STANDARD_EVENTS_INSPECTOR_SCRIPT,\n },\n });\n }\n\n if (inbox) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-inbox\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_INBOX_SCRIPT,\n },\n });\n }\n\n if (account) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-account\",\n type: \"module\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_ACCOUNT_SCRIPT,\n },\n });\n }\n\n // Install readiness listeners before loading the async consent library so a\n // cached script cannot finish initialization before Hydrogen starts listening.\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-analytics-bus\",\n ...nonceAttributes,\n ...shopifyAnalyticsBootstrap.attributes(analyticsConfig),\n },\n innerHTML: shopifyAnalyticsBootstrap.code,\n });\n\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: SHOPIFY_CONSENT_SCRIPT_ID,\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src:\n consent?.mode === \"default-banner\"\n ? SHOPIFY_PRIVACY_BANNER_SCRIPT\n : SHOPIFY_CONSENT_API_SCRIPT,\n },\n });\n\n if (shopifyAnalytics) {\n scripts.push({\n tagName: \"script\",\n attributes: {\n id: \"shopify-storefront-analytics\",\n async: true,\n crossorigin: \"anonymous\",\n ...nonceAttributes,\n src: SHOPIFY_STOREFRONT_ANALYTICS_SCRIPT,\n },\n });\n }\n\n const perfKitScript = getPerfKitScript(shop, nonceAttributes);\n if (perfKitScript) {\n scripts.push(perfKitScript);\n }\n\n return {\n links,\n scripts,\n get tags() {\n return [...links, ...scripts];\n },\n };\n}\n\n/**\n * Renders Shopify's storefront script and link tags to HTML strings.\n *\n * Use the function when your framework accepts raw HTML in the document head.\n *\n * @param options The shop details and the features, such as account and analytics, whose scripts to load.\n * @returns One HTML string per tag, with link tags first.\n * @publicDocs\n */\nexport function renderShopifyScriptTags(options: ShopifyScriptTagsOptions): string[] {\n return getShopifyScriptTags(options).tags.map(renderShopifyScriptTag);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkEA,SAAgB,qBAAqB,EACnC,UAAU,OACV,WACA,SACA,OACA,MACA,O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P,aAAa;GACb,GAAG;GACH,KACE,SAAS,SAAS,mBACd,gCACA;GACP;EACF,CAAC;AAEF,KAAI,iBACF,SAAQ,KAAK;EACX,SAAS;EACT,YAAY;GACV,IAAI;GACJ,OAAO;GACP,aAAa;GACb,GAAG;GACH,KAAK;GACN;EACF,CAAC;CAGJ,MAAM,gBAAgB,iBAAiB,MAAM,gBAAgB;AAC7D,KAAI,cACF,SAAQ,KAAK,cAAc;AAG7B,QAAO;EACL;EACA;EACA,IAAI,OAAO;AACT,UAAO,CAAC,GAAG,OAAO,GAAG,QAAQ;;EAEhC;;;;;;;;;;;AAYH,SAAgB,wBAAwB,SAA6C;AACnF,QAAO,qBAAqB,QAAQ,CAAC,KAAK,IAAI,uBAAuB"}
|
|
@@ -5,7 +5,10 @@ import { observeNavigation } from "./utils/navigation.mjs";
|
|
|
5
5
|
let cleanupPageViewEvents;
|
|
6
6
|
const getPageKey = () => `${window.location.pathname}${window.location.search}`;
|
|
7
7
|
const getPageTemplate = (url = window.location.href) => window.Shopify?.routes?.match?.(url)?.pageTemplateName ?? "unknown";
|
|
8
|
-
const importStandardEventsFromCDN = () => import(
|
|
8
|
+
const importStandardEventsFromCDN = () => import(
|
|
9
|
+
/* webpackIgnore: true */
|
|
10
|
+
"https://cdn.shopify.com/storefront/standard-events.js"
|
|
11
|
+
);
|
|
9
12
|
function initializeShopifyPageViewEvents(importStandardEvents = importStandardEventsFromCDN) {
|
|
10
13
|
if (cleanupPageViewEvents) return cleanupPageViewEvents;
|
|
11
14
|
document.getElementById(SHOPIFY_PERF_KIT_SCRIPT_ID)?.setAttribute("data-page-type", getPageTemplate());
|