@vercel/microfrontends 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +3 -3
  2. package/dist/bin/cli.cjs +85 -60
  3. package/dist/config/client.d.ts +1 -1
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.d.ts +1 -1
  6. package/dist/config.js.map +1 -1
  7. package/dist/{index-83133f2d.d.ts → index-bf67a461.d.ts} +3 -10
  8. package/dist/next/client.cjs +1 -1
  9. package/dist/next/client.cjs.map +1 -1
  10. package/dist/next/client.js +1 -1
  11. package/dist/next/client.js.map +1 -1
  12. package/dist/next/endpoints.cjs.map +1 -1
  13. package/dist/next/endpoints.d.ts +1 -1
  14. package/dist/next/endpoints.js.map +1 -1
  15. package/dist/next/middleware.cjs +0 -29
  16. package/dist/next/middleware.cjs.map +1 -1
  17. package/dist/next/middleware.js +0 -29
  18. package/dist/next/middleware.js.map +1 -1
  19. package/dist/{types-a995174e.d.ts → types-a29d224a.d.ts} +1 -7
  20. package/dist/{types-15b7f215.d.ts → types-cfe3308b.d.ts} +1 -1
  21. package/dist/types-fc30696d.d.ts +11 -0
  22. package/dist/utils/mfe-port.cjs +70 -56
  23. package/dist/utils/mfe-port.cjs.map +1 -1
  24. package/dist/utils/mfe-port.js +67 -53
  25. package/dist/utils/mfe-port.js.map +1 -1
  26. package/dist/v2/config.cjs +0 -14
  27. package/dist/v2/config.cjs.map +1 -1
  28. package/dist/v2/config.d.ts +4 -3
  29. package/dist/v2/config.js +0 -14
  30. package/dist/v2/config.js.map +1 -1
  31. package/dist/v2/microfrontends/server.cjs +68 -54
  32. package/dist/v2/microfrontends/server.cjs.map +1 -1
  33. package/dist/v2/microfrontends/server.d.ts +6 -5
  34. package/dist/v2/microfrontends/server.js +65 -51
  35. package/dist/v2/microfrontends/server.js.map +1 -1
  36. package/dist/v2/microfrontends.cjs +0 -14
  37. package/dist/v2/microfrontends.cjs.map +1 -1
  38. package/dist/v2/microfrontends.d.ts +4 -3
  39. package/dist/v2/microfrontends.js +0 -14
  40. package/dist/v2/microfrontends.js.map +1 -1
  41. package/dist/v2/next/client.cjs +1 -1
  42. package/dist/v2/next/client.cjs.map +1 -1
  43. package/dist/v2/next/client.js +1 -1
  44. package/dist/v2/next/client.js.map +1 -1
  45. package/dist/v2/next/config.cjs +106 -60
  46. package/dist/v2/next/config.cjs.map +1 -1
  47. package/dist/v2/next/config.js +103 -57
  48. package/dist/v2/next/config.js.map +1 -1
  49. package/dist/v2/next/endpoints.cjs.map +1 -1
  50. package/dist/v2/next/endpoints.d.ts +13 -2
  51. package/dist/v2/next/endpoints.js.map +1 -1
  52. package/dist/v2/next/middleware.cjs +10 -54
  53. package/dist/v2/next/middleware.cjs.map +1 -1
  54. package/dist/v2/next/middleware.d.ts +7 -2
  55. package/dist/v2/next/middleware.js +10 -54
  56. package/dist/v2/next/middleware.js.map +1 -1
  57. package/dist/v2/next/testing.cjs +992 -0
  58. package/dist/v2/next/testing.cjs.map +1 -0
  59. package/dist/v2/next/testing.d.ts +55 -0
  60. package/dist/v2/next/testing.js +961 -0
  61. package/dist/v2/next/testing.js.map +1 -0
  62. package/dist/v2/overrides.d.ts +3 -3
  63. package/dist/v2/routing.cjs +19 -0
  64. package/dist/v2/routing.cjs.map +1 -0
  65. package/dist/v2/routing.d.ts +26 -0
  66. package/dist/v2/routing.js +1 -0
  67. package/dist/v2/routing.js.map +1 -0
  68. package/dist/v2/schema.cjs.map +1 -1
  69. package/dist/v2/schema.d.ts +1 -1
  70. package/dist/validation.cjs +0 -4
  71. package/dist/validation.cjs.map +1 -1
  72. package/dist/validation.d.ts +0 -6
  73. package/dist/validation.js +0 -4
  74. package/dist/validation.js.map +1 -1
  75. package/package.json +20 -5
  76. package/schema/schema-v2.json +0 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/client/link/multi-zones-link.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links-context.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links.tsx","../../src/config/client/use-client-config.ts","../../src/config/client/client-config.ts","../../src/config/client/paths.ts"],"sourcesContent":["import type { AnchorHTMLAttributes } from 'react';\nimport { forwardRef, useContext } from 'react';\nimport NextLink, { type LinkProps as NextLinkProps } from 'next/link';\nimport { PrefetchCrossZoneLinksContext } from '../prefetch';\nimport { getApplicationNameForPath } from '../../../config/client/paths';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\ninterface BaseProps {\n children: React.ReactNode;\n href: string;\n}\nexport type LinkProps = BaseProps &\n Omit<NextLinkProps, keyof BaseProps> &\n Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseProps>;\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport function useZoneForHref(href: LinkProps['href'] | undefined): {\n zoneOfHref: string | null;\n isDifferentZone: boolean;\n isLoading: boolean;\n} {\n const { clientConfig, isLoading } = useClientConfig({\n removeFlaggedPathsFromDefault: true,\n });\n const isRelativePath =\n typeof href === 'string' && (href as string).startsWith('/');\n const zoneOfHref = isRelativePath\n ? getApplicationNameForPath(clientConfig, href as string)\n : null;\n const isDifferentZone =\n !isRelativePath || (zoneOfHref ? CURRENT_ZONE !== zoneOfHref : false);\n return { zoneOfHref, isDifferentZone, isLoading };\n}\n\n/**\n * A Link component that works with Multi-Zones set-ups and will prefetch the\n * cross zone links automatically.\n */\nexport const Link = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ children, ...props }, ref): JSX.Element => {\n const { prefetchHref } = useContext(PrefetchCrossZoneLinksContext);\n const { zoneOfHref, isDifferentZone, isLoading } = useZoneForHref(\n props.href,\n );\n\n function onHoverPrefetch(): void {\n if (!props.href) {\n return;\n }\n prefetchHref(props.href);\n }\n\n if (isDifferentZone && zoneOfHref !== null) {\n const { prefetch: _, ...rest } = props;\n return (\n // biome-ignore lint/a11y/useKeyWithMouseEvents: Only used for prefetching.\n // biome-ignore lint/nursery/noStaticElementInteractions: Ignored using `--suppress`\n <a\n {...rest}\n data-zone={zoneOfHref}\n onMouseOver={props.prefetch !== false ? onHoverPrefetch : undefined}\n >\n {children}\n </a>\n );\n }\n\n return (\n <NextLink\n {...props}\n data-zone={!zoneOfHref ? 'null' : 'same'}\n prefetch={props.prefetch ?? (isLoading ? false : undefined)}\n ref={ref}\n >\n {children}\n </NextLink>\n );\n },\n);\nLink.displayName = 'MultiZonesLink';\n","import React, {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nexport interface PrefetchCrossZoneLinksContext {\n prefetchHref: (href: string) => void;\n}\n\nexport const PrefetchCrossZoneLinksContext =\n createContext<PrefetchCrossZoneLinksContext>({\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n prefetchHref: () => {},\n });\n\nexport function PrefetchCrossZoneLinksProvider({\n children,\n}: { children: React.ReactNode }): JSX.Element | null {\n const [seenHrefs, setSeenHrefs] = useState(new Set<string>());\n const [isSafariOrFirefox, setIsSafariOrFirefox] = useState(false);\n\n useEffect(() => {\n setIsSafariOrFirefox(\n typeof navigator !== 'undefined' &&\n (navigator.userAgent.includes('Firefox') ||\n (navigator.userAgent.includes('Safari') &&\n !navigator.userAgent.includes('Chrome'))),\n );\n }, []);\n\n const prefetchHref = useCallback(\n (href: string): void => {\n if (!seenHrefs.has(href)) {\n setSeenHrefs(new Set(seenHrefs).add(href));\n }\n },\n [seenHrefs],\n );\n\n const value = useMemo(() => ({ prefetchHref }), [prefetchHref]);\n\n if (!isSafariOrFirefox) {\n return <>{children}</>;\n }\n\n return (\n <PrefetchCrossZoneLinksContext.Provider value={value}>\n {children}\n {[...seenHrefs].map((href) => (\n <link as=\"fetch\" href={href} key={href} rel=\"preload\" />\n ))}\n </PrefetchCrossZoneLinksContext.Provider>\n );\n}\n","import { useEffect, useState } from 'react';\nimport Script from 'next/script';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\nconst PREFETCH_ATTR = 'data-prefetch';\nconst DATA_ATTR_SELECTORS = {\n anyZone: '[data-zone]',\n external: '[data-zone=\"null\"]',\n sameZone: '[data-zone=\"same\"]',\n prefetch: `[${PREFETCH_ATTR}]`,\n} as const;\n\nconst PREFETCH_ON_HOVER_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n ],\n};\n\nconst PREFETCH_WHEN_VISIBLE_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n { selector_matches: DATA_ATTR_SELECTORS.prefetch },\n ],\n};\n\nfunction checkVisibility(element: Element | null): boolean {\n if (!element) return true;\n\n if ('checkVisibility' in element) {\n return element.checkVisibility({ opacityProperty: true });\n }\n\n // hack to get around TS thinking element is never;\n const el = element as Element;\n const style = window.getComputedStyle(el);\n\n if (\n style.display === 'none' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false;\n }\n\n return checkVisibility(el.parentElement);\n}\n\nexport function PrefetchCrossZoneLinks(): JSX.Element | null {\n const { isLoading } = useClientConfig();\n const [links, setLinks] = useState<HTMLAnchorElement[]>([]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Intersection observer to add the data-prefetch attribute to cross-zone\n * links that have yet to be prefetched and are visible.\n */\n const observer = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (\n entry.isIntersecting &&\n !entry.target.hasAttribute(PREFETCH_ATTR) &&\n // lazy perform the visibility check for nodes that are intersecting the viewport\n // and have not been prefetched.\n checkVisibility(entry.target)\n ) {\n entry.target.setAttribute(PREFETCH_ATTR, 'true');\n }\n });\n },\n {\n root: null,\n rootMargin: '0px',\n threshold: 0.1,\n },\n );\n\n links.forEach((link) => observer.observe(link));\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading, links]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Mutation observer to notify when new nodes have entered/exited the document\n * or an href has changed.\n */\n const observer = new MutationObserver((mutations) => {\n const hasChanged = mutations.some((mutation) => {\n return (\n (mutation.type === 'childList' && mutation.addedNodes.length > 0) ||\n (mutation.type === 'attributes' && mutation.attributeName === 'href')\n );\n });\n\n if (hasChanged) {\n // Whenever there's a change, add all cross-zone links that haven't been\n // prefetched.\n setLinks(\n Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n `a${DATA_ATTR_SELECTORS.anyZone}:not(${DATA_ATTR_SELECTORS.prefetch}):not(${DATA_ATTR_SELECTORS.sameZone}):not(${DATA_ATTR_SELECTORS.external})`,\n ),\n ),\n );\n }\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['href'],\n });\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading]);\n\n // Wait till the zone-config loads to take into consideration any\n // flagged routes.\n if (isLoading) {\n return null;\n }\n\n // Prefetch links with moderate eagerness by default, immediately when marked \"data-prefetch\".\n // Prerender links with conservative eagerness by default, immediately when marked \"data-prefetch\".\n const speculationRules = {\n prefetch: [\n {\n eagerness: 'moderate',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n {\n eagerness: 'immediate',\n where: PREFETCH_WHEN_VISIBLE_PREDICATES,\n },\n ],\n prerender: [\n {\n eagerness: 'conservative',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n ],\n };\n\n return (\n <Script\n dangerouslySetInnerHTML={{\n __html: `${JSON.stringify(speculationRules)}`,\n }}\n id=\"prefetch-zones-links\"\n type=\"speculationrules\"\n />\n );\n}\n","'use client';\n\nimport { useState, useEffect } from 'react';\nimport type { ClientConfig, WellKnownClientData } from './types';\nimport { getClientConfigFromEnv } from './client-config';\n\nlet cachedServerClientConfigPromise: Promise<ClientConfig | null> | null = null;\n\nasync function fetchClientConfigFromServer(): Promise<ClientConfig | null> {\n try {\n const response = await fetch(\n '/.well-known/vercel/micro-frontends/client-config',\n );\n if (response.status !== 200) {\n return null;\n }\n const responseJson = (await response.json()) as WellKnownClientData;\n return responseJson.config;\n } catch (err) {\n return null;\n }\n}\n\nfunction isEqual(config1: ClientConfig, config2: ClientConfig): boolean {\n return JSON.stringify(config1) === JSON.stringify(config2);\n}\n\nfunction removeFlaggedPaths(config: ClientConfig): ClientConfig {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing.matches = app.routing.matches.filter(\n (match) => !match.options?.flag,\n );\n }\n }\n return config;\n}\n\n/**\n * Hook to use the client micro-frontends configuration. This hook will resolve\n * dynamic paths by fetching the configuration from the server if necessary,\n * allowing the server to specify the values for dynamic paths.\n */\nexport function useClientConfig({\n removeFlaggedPathsFromDefault,\n}: {\n removeFlaggedPathsFromDefault?: boolean;\n} = {}): {\n clientConfig: ClientConfig;\n isLoading: boolean;\n} {\n const [clientConfig, setClientConfig] = useState<ClientConfig>(\n removeFlaggedPathsFromDefault\n ? removeFlaggedPaths(getClientConfigFromEnv())\n : getClientConfigFromEnv(),\n );\n const [isLoading, setIsLoading] = useState(true);\n useEffect(() => {\n if (\n process.env.NODE_ENV === 'test' &&\n process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER !== '1'\n ) {\n setIsLoading(false);\n return;\n }\n // Since we may remove flagged paths from the client config above, we need\n // to use the original client config to determine if the config has any\n // dynamic paths.\n const originalClientConfig = getClientConfigFromEnv();\n // As an optimization, only fetch the config from the server if the\n // micro-frontends configuration has any dynamic paths. If it doesn't,\n // then the server won't return any different values.\n const hasDynamicPaths = Object.values(\n originalClientConfig.applications,\n ).some((app) => app.routing?.matches.some((group) => group.options?.flag));\n if (!hasDynamicPaths) {\n setIsLoading(false);\n return;\n }\n if (!cachedServerClientConfigPromise) {\n cachedServerClientConfigPromise = fetchClientConfigFromServer();\n }\n void cachedServerClientConfigPromise\n .then((newConfig) => {\n if (newConfig) {\n setClientConfig((prevConfig) => {\n return isEqual(prevConfig, newConfig) ? prevConfig : newConfig;\n });\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, [clientConfig.applications]);\n\n return { clientConfig, isLoading };\n}\n\nexport function resetCachedServerClientConfigPromise(): void {\n cachedServerClientConfigPromise = null;\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\nconst weakCache = new WeakMap<ClientConfig, Record<string, string>>();\n/**\n * Given a relative path, this function returns the name of the micro-frontend\n * that serves the path.\n */\nexport function getApplicationNameForPath(\n config: ClientConfig,\n path: string,\n): string {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n const cache = weakCache.get(config) ?? {};\n if (cache[path]) {\n return cache[path];\n }\n if (!weakCache.has(config)) {\n weakCache.set(config, cache);\n }\n const pathname = new URL(path, 'https://example.com').pathname;\n\n for (const [name, application] of Object.entries(config.applications)) {\n if (application.routing) {\n for (const group of application.routing.matches) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n cache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(config.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n throw new Error(\n 'No default application found. A default application must be configured in the micro-frontends configuration.',\n );\n }\n cache[path] = defaultApplication[0];\n return defaultApplication[0];\n}\n"],"mappings":";AACA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,QACvC,OAAOC,MAAmD,YCF1D,OACE,iBAAAC,EACA,eAAAC,EACA,aAAAC,EACA,WAAAC,EACA,YAAAC,MACK,QAuCI,mBAAAC,EAAA,OAAAC,EAIP,QAAAC,MAJO,oBAjCJ,IAAMC,EACXR,EAA6C,CAE3C,aAAc,IAAM,CAAC,CACvB,CAAC,EAEI,SAASS,EAA+B,CAC7C,SAAAC,CACF,EAAsD,CACpD,GAAM,CAACC,EAAWC,CAAY,EAAIR,EAAS,IAAI,GAAa,EACtD,CAACS,EAAmBC,CAAoB,EAAIV,EAAS,EAAK,EAEhEF,EAAU,IAAM,CACdY,EACE,OAAO,UAAc,MAClB,UAAU,UAAU,SAAS,SAAS,GACpC,UAAU,UAAU,SAAS,QAAQ,GACpC,CAAC,UAAU,UAAU,SAAS,QAAQ,EAC9C,CACF,EAAG,CAAC,CAAC,EAEL,IAAMC,EAAed,EAClBe,GAAuB,CACjBL,EAAU,IAAIK,CAAI,GACrBJ,EAAa,IAAI,IAAID,CAAS,EAAE,IAAIK,CAAI,CAAC,CAE7C,EACA,CAACL,CAAS,CACZ,EAEMM,EAAQd,EAAQ,KAAO,CAAE,aAAAY,CAAa,GAAI,CAACA,CAAY,CAAC,EAE9D,OAAKF,EAKHN,EAACC,EAA8B,SAA9B,CAAuC,MAAOS,EAC5C,UAAAP,EACA,CAAC,GAAGC,CAAS,EAAE,IAAKK,GACnBV,EAAC,QAAK,GAAG,QAAQ,KAAMU,EAAiB,IAAI,WAAVA,CAAoB,CACvD,GACH,EATOV,EAAAD,EAAA,CAAG,SAAAK,EAAS,CAWvB,CCxDA,OAAS,aAAAQ,EAAW,YAAAC,MAAgB,QACp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3B,UAAAH,CAAU,CAClD,CAMO,IAAMK,EAAOC,EAClB,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAM,EAAGC,IAAqB,CAC5C,GAAM,CAAE,aAAAC,CAAa,EAAIC,EAAWC,CAA6B,EAC3D,CAAE,WAAAT,EAAY,gBAAAU,EAAiB,UAAAb,CAAU,EAAIH,EACjDW,EAAM,IACR,EAEA,SAASM,GAAwB,CAC1BN,EAAM,MAGXE,EAAaF,EAAM,IAAI,CACzB,CAEA,GAAIK,GAAmBV,IAAe,KAAM,CAC1C,GAAM,CAAE,SAAUY,EAAG,GAAGC,CAAK,EAAIR,EACjC,OAGEb,EAAC,KACE,GAAGqB,EACJ,YAAWb,EACX,YAAaK,EAAM,WAAa,GAAQM,EAAkB,OAEzD,SAAAP,EACH,EAIJ,OACEZ,EAACsB,EAAA,CACE,GAAGT,EACJ,YAAYL,EAAsB,OAAT,OACzB,SAAUK,EAAM,WAAaR,EAAY,GAAQ,QACjD,IAAKS,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAF,EAAK,YAAc","names":["forwardRef","useContext","NextLink","createContext","useCallback","useEffect","useMemo","useState","Fragment","jsx","jsxs","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","useEffect","useState","Script","useState","useEffect","getClientConfigFromEnv","clientConfigJson","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","isEqual","config1","config2","removeFlaggedPaths","config","app","match","_a","useClientConfig","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","useState","getClientConfigFromEnv","isLoading","setIsLoading","useEffect","originalClientConfig","group","newConfig","prevConfig","jsx","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","useState","useEffect","observer","entries","entry","link","mutations","mutation","Script","pathToRegexp","weakCache","getApplicationNameForPath","config","path","cache","pathname","name","application","group","childPath","defaultApplication","jsx","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","getApplicationNameForPath","Link","forwardRef","children","props","ref","prefetchHref","useContext","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
1
+ {"version":3,"sources":["../../src/next/client/link/multi-zones-link.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links-context.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links.tsx","../../src/config/client/use-client-config.ts","../../src/config/client/client-config.ts","../../src/config/client/paths.ts"],"sourcesContent":["import type { AnchorHTMLAttributes } from 'react';\nimport { forwardRef, useContext } from 'react';\nimport NextLink, { type LinkProps as NextLinkProps } from 'next/link';\nimport { PrefetchCrossZoneLinksContext } from '../prefetch';\nimport { getApplicationNameForPath } from '../../../config/client/paths';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\ninterface BaseProps {\n children: React.ReactNode;\n href: string;\n}\nexport type LinkProps = BaseProps &\n Omit<NextLinkProps, keyof BaseProps> &\n Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof BaseProps>;\n\nconst CURRENT_ZONE = process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;\n\nexport function useZoneForHref(href: LinkProps['href'] | undefined): {\n zoneOfHref: string | null;\n isDifferentZone: boolean;\n isLoading: boolean;\n} {\n const { clientConfig, isLoading } = useClientConfig({\n removeFlaggedPathsFromDefault: true,\n });\n const isRelativePath =\n typeof href === 'string' && (href as string).startsWith('/');\n const zoneOfHref = isRelativePath\n ? getApplicationNameForPath(clientConfig, href as string)\n : null;\n const isDifferentZone =\n !isRelativePath || (zoneOfHref ? CURRENT_ZONE !== zoneOfHref : false);\n return { zoneOfHref, isDifferentZone, isLoading };\n}\n\n/**\n * A Link component that works with Multi-Zones set-ups and will prefetch the\n * cross zone links automatically.\n */\nexport const Link = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ children, ...props }, ref): JSX.Element => {\n const { prefetchHref } = useContext(PrefetchCrossZoneLinksContext);\n const { zoneOfHref, isDifferentZone, isLoading } = useZoneForHref(\n props.href,\n );\n\n function onHoverPrefetch(): void {\n if (!props.href) {\n return;\n }\n prefetchHref(props.href);\n }\n\n if (isDifferentZone && zoneOfHref !== null) {\n const { prefetch: _, ...rest } = props;\n return (\n // biome-ignore lint/a11y/useKeyWithMouseEvents: Only used for prefetching.\n // biome-ignore lint/nursery/noStaticElementInteractions: Ignored using `--suppress`\n <a\n {...rest}\n data-zone={zoneOfHref}\n onMouseOver={props.prefetch !== false ? onHoverPrefetch : undefined}\n >\n {children}\n </a>\n );\n }\n\n return (\n <NextLink\n {...props}\n data-zone={!zoneOfHref ? 'null' : 'same'}\n prefetch={props.prefetch ?? (isLoading ? false : undefined)}\n ref={ref}\n >\n {children}\n </NextLink>\n );\n },\n);\nLink.displayName = 'MultiZonesLink';\n","import React, {\n createContext,\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nexport interface PrefetchCrossZoneLinksContext {\n prefetchHref: (href: string) => void;\n}\n\nexport const PrefetchCrossZoneLinksContext =\n createContext<PrefetchCrossZoneLinksContext>({\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n prefetchHref: () => {},\n });\n\nexport function PrefetchCrossZoneLinksProvider({\n children,\n}: { children: React.ReactNode }): JSX.Element | null {\n const [seenHrefs, setSeenHrefs] = useState(new Set<string>());\n const [isSafariOrFirefox, setIsSafariOrFirefox] = useState(false);\n\n useEffect(() => {\n setIsSafariOrFirefox(\n typeof navigator !== 'undefined' &&\n (navigator.userAgent.includes('Firefox') ||\n (navigator.userAgent.includes('Safari') &&\n !navigator.userAgent.includes('Chrome'))),\n );\n }, []);\n\n const prefetchHref = useCallback(\n (href: string): void => {\n if (!seenHrefs.has(href)) {\n setSeenHrefs(new Set(seenHrefs).add(href));\n }\n },\n [seenHrefs],\n );\n\n const value = useMemo(() => ({ prefetchHref }), [prefetchHref]);\n\n if (!isSafariOrFirefox) {\n return <>{children}</>;\n }\n\n return (\n <PrefetchCrossZoneLinksContext.Provider value={value}>\n {children}\n {[...seenHrefs].map((href) => (\n <link as=\"fetch\" href={href} key={href} rel=\"preload\" />\n ))}\n </PrefetchCrossZoneLinksContext.Provider>\n );\n}\n","import { useEffect, useState } from 'react';\nimport Script from 'next/script';\nimport { useClientConfig } from '../../../config/client/use-client-config';\n\nconst PREFETCH_ATTR = 'data-prefetch';\nconst DATA_ATTR_SELECTORS = {\n anyZone: '[data-zone]',\n external: '[data-zone=\"null\"]',\n sameZone: '[data-zone=\"same\"]',\n prefetch: `[${PREFETCH_ATTR}]`,\n} as const;\n\nconst PREFETCH_ON_HOVER_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n ],\n};\n\nconst PREFETCH_WHEN_VISIBLE_PREDICATES = {\n and: [\n { href_matches: '/*' },\n { selector_matches: DATA_ATTR_SELECTORS.anyZone },\n { not: { selector_matches: DATA_ATTR_SELECTORS.sameZone } },\n { not: { selector_matches: DATA_ATTR_SELECTORS.external } },\n { selector_matches: DATA_ATTR_SELECTORS.prefetch },\n ],\n};\n\nfunction checkVisibility(element: Element | null): boolean {\n if (!element) return true;\n\n if ('checkVisibility' in element) {\n return element.checkVisibility({ opacityProperty: true });\n }\n\n // hack to get around TS thinking element is never;\n const el = element as Element;\n const style = window.getComputedStyle(el);\n\n if (\n style.display === 'none' ||\n style.visibility === 'hidden' ||\n style.opacity === '0'\n ) {\n return false;\n }\n\n return checkVisibility(el.parentElement);\n}\n\nexport function PrefetchCrossZoneLinks(): JSX.Element | null {\n const { isLoading } = useClientConfig();\n const [links, setLinks] = useState<HTMLAnchorElement[]>([]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Intersection observer to add the data-prefetch attribute to cross-zone\n * links that have yet to be prefetched and are visible.\n */\n const observer = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (\n entry.isIntersecting &&\n !entry.target.hasAttribute(PREFETCH_ATTR) &&\n // lazy perform the visibility check for nodes that are intersecting the viewport\n // and have not been prefetched.\n checkVisibility(entry.target)\n ) {\n entry.target.setAttribute(PREFETCH_ATTR, 'true');\n }\n });\n },\n {\n root: null,\n rootMargin: '0px',\n threshold: 0.1,\n },\n );\n\n links.forEach((link) => observer.observe(link));\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading, links]);\n\n useEffect(() => {\n if (isLoading) {\n return;\n }\n\n /**\n * Mutation observer to notify when new nodes have entered/exited the document\n * or an href has changed.\n */\n const observer = new MutationObserver((mutations) => {\n const hasChanged = mutations.some((mutation) => {\n return (\n (mutation.type === 'childList' && mutation.addedNodes.length > 0) ||\n (mutation.type === 'attributes' && mutation.attributeName === 'href')\n );\n });\n\n if (hasChanged) {\n // Whenever there's a change, add all cross-zone links that haven't been\n // prefetched.\n setLinks(\n Array.from(\n document.querySelectorAll<HTMLAnchorElement>(\n `a${DATA_ATTR_SELECTORS.anyZone}:not(${DATA_ATTR_SELECTORS.prefetch}):not(${DATA_ATTR_SELECTORS.sameZone}):not(${DATA_ATTR_SELECTORS.external})`,\n ),\n ),\n );\n }\n });\n\n observer.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n attributeFilter: ['href'],\n });\n\n return () => {\n observer.disconnect();\n };\n }, [isLoading]);\n\n // Wait till the zone-config loads to take into consideration any\n // flagged routes.\n if (isLoading) {\n return null;\n }\n\n // Prefetch links with moderate eagerness by default, immediately when marked \"data-prefetch\".\n // Prerender links with conservative eagerness by default, immediately when marked \"data-prefetch\".\n const speculationRules = {\n prefetch: [\n {\n eagerness: 'moderate',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n {\n eagerness: 'immediate',\n where: PREFETCH_WHEN_VISIBLE_PREDICATES,\n },\n ],\n prerender: [\n {\n eagerness: 'conservative',\n where: PREFETCH_ON_HOVER_PREDICATES,\n },\n ],\n };\n\n return (\n <Script\n dangerouslySetInnerHTML={{\n __html: `${JSON.stringify(speculationRules)}`,\n }}\n id=\"prefetch-zones-links\"\n type=\"speculationrules\"\n />\n );\n}\n","'use client';\n\nimport { useState, useEffect } from 'react';\nimport type { ClientConfig, WellKnownClientData } from './types';\nimport { getClientConfigFromEnv } from './client-config';\n\nlet cachedServerClientConfigPromise: Promise<ClientConfig | null> | null = null;\n\nasync function fetchClientConfigFromServer(): Promise<ClientConfig | null> {\n try {\n const response = await fetch(\n '/.well-known/vercel/microfrontends/client-config',\n );\n if (response.status !== 200) {\n return null;\n }\n const responseJson = (await response.json()) as WellKnownClientData;\n return responseJson.config;\n } catch (err) {\n return null;\n }\n}\n\nfunction isEqual(config1: ClientConfig, config2: ClientConfig): boolean {\n return JSON.stringify(config1) === JSON.stringify(config2);\n}\n\nfunction removeFlaggedPaths(config: ClientConfig): ClientConfig {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing.matches = app.routing.matches.filter(\n (match) => !match.options?.flag,\n );\n }\n }\n return config;\n}\n\n/**\n * Hook to use the client micro-frontends configuration. This hook will resolve\n * dynamic paths by fetching the configuration from the server if necessary,\n * allowing the server to specify the values for dynamic paths.\n */\nexport function useClientConfig({\n removeFlaggedPathsFromDefault,\n}: {\n removeFlaggedPathsFromDefault?: boolean;\n} = {}): {\n clientConfig: ClientConfig;\n isLoading: boolean;\n} {\n const [clientConfig, setClientConfig] = useState<ClientConfig>(\n removeFlaggedPathsFromDefault\n ? removeFlaggedPaths(getClientConfigFromEnv())\n : getClientConfigFromEnv(),\n );\n const [isLoading, setIsLoading] = useState(true);\n useEffect(() => {\n if (\n process.env.NODE_ENV === 'test' &&\n process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER !== '1'\n ) {\n setIsLoading(false);\n return;\n }\n // Since we may remove flagged paths from the client config above, we need\n // to use the original client config to determine if the config has any\n // dynamic paths.\n const originalClientConfig = getClientConfigFromEnv();\n // As an optimization, only fetch the config from the server if the\n // micro-frontends configuration has any dynamic paths. If it doesn't,\n // then the server won't return any different values.\n const hasDynamicPaths = Object.values(\n originalClientConfig.applications,\n ).some((app) => app.routing?.matches.some((group) => group.options?.flag));\n if (!hasDynamicPaths) {\n setIsLoading(false);\n return;\n }\n if (!cachedServerClientConfigPromise) {\n cachedServerClientConfigPromise = fetchClientConfigFromServer();\n }\n void cachedServerClientConfigPromise\n .then((newConfig) => {\n if (newConfig) {\n setClientConfig((prevConfig) => {\n return isEqual(prevConfig, newConfig) ? prevConfig : newConfig;\n });\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, [clientConfig.applications]);\n\n return { clientConfig, isLoading };\n}\n\nexport function resetCachedServerClientConfigPromise(): void {\n cachedServerClientConfigPromise = null;\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\nconst weakCache = new WeakMap<ClientConfig, Record<string, string>>();\n/**\n * Given a relative path, this function returns the name of the micro-frontend\n * that serves the path.\n */\nexport function getApplicationNameForPath(\n config: ClientConfig,\n path: string,\n): string {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n const cache = weakCache.get(config) ?? {};\n if (cache[path]) {\n return cache[path];\n }\n if (!weakCache.has(config)) {\n weakCache.set(config, cache);\n }\n const pathname = new URL(path, 'https://example.com').pathname;\n\n for (const [name, application] of Object.entries(config.applications)) {\n if (application.routing) {\n for (const group of application.routing.matches) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n cache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(config.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n throw new Error(\n 'No default application found. A default application must be configured in the micro-frontends configuration.',\n );\n }\n cache[path] = defaultApplication[0];\n return defaultApplication[0];\n}\n"],"mappings":";AACA,OAAS,cAAAA,EAAY,cAAAC,MAAkB,QACvC,OAAOC,MAAmD,YCF1D,OACE,iBAAAC,EACA,eAAAC,EACA,aAAAC,EACA,WAAAC,EACA,YAAAC,MACK,QAuCI,mBAAAC,EAAA,OAAAC,EAIP,QAAAC,MAJO,oBAjCJ,IAAMC,EACXR,EAA6C,CAE3C,aAAc,IAAM,CAAC,CACvB,CAAC,EAEI,SAASS,EAA+B,CAC7C,SAAAC,CACF,EAAsD,CACpD,GAAM,CAACC,EAAWC,CAAY,EAAIR,EAAS,IAAI,GAAa,EACtD,CAACS,EAAmBC,CAAoB,EAAIV,EAAS,EAAK,EAEhEF,EAAU,IAAM,CACdY,EACE,OAAO,UAAc,MAClB,UAAU,UAAU,SAAS,SAAS,GACpC,UAAU,UAAU,SAAS,QAAQ,GACpC,CAAC,UAAU,UAAU,SAAS,QAAQ,EAC9C,CACF,EAAG,CAAC,CAAC,EAEL,IAAMC,EAAed,EAClBe,GAAuB,CACjBL,EAAU,IAAIK,CAAI,GACrBJ,EAAa,IAAI,IAAID,CAAS,EAAE,IAAIK,CAAI,CAAC,CAE7C,EACA,CAACL,CAAS,CACZ,EAEMM,EAAQd,EAA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A,oBA3CR,IAAMC,EAAe,QAAQ,IAAI,oCAE1B,SAASC,EAAeC,EAI7B,CACA,GAAM,CAAE,aAAAC,EAAc,UAAAC,CAAU,EAAIC,EAAgB,CAClD,8BAA+B,EACjC,CAAC,EACKC,EACJ,OAAOJ,GAAS,UAAaA,EAAgB,WAAW,GAAG,EACvDK,EAAaD,EACfE,EAA0BL,EAAcD,CAAc,EACtD,KAGJ,MAAO,CAAE,WAAAK,EAAY,gBADnB,CAACD,IAAmBC,EAAaP,IAAiBO,EAAa,IAC3B,UAAAH,CAAU,CAClD,CAMO,IAAMK,EAAOC,EAClB,CAAC,CAAE,SAAAC,EAAU,GAAGC,CAAM,EAAGC,IAAqB,CAC5C,GAAM,CAAE,aAAAC,CAAa,EAAIC,EAAWC,CAA6B,EAC3D,CAAE,WAAAT,EAAY,gBAAAU,EAAiB,UAAAb,CAAU,EAAIH,EACjDW,EAAM,IACR,EAEA,SAASM,GAAwB,CAC1BN,EAAM,MAGXE,EAAaF,EAAM,IAAI,CACzB,CAEA,GAAIK,GAAmBV,IAAe,KAAM,CAC1C,GAAM,CAAE,SAAUY,EAAG,GAAGC,CAAK,EAAIR,EACjC,OAGEb,EAAC,KACE,GAAGqB,EACJ,YAAWb,EACX,YAAaK,EAAM,WAAa,GAAQM,EAAkB,OAEzD,SAAAP,EACH,EAIJ,OACEZ,EAACsB,EAAA,CACE,GAAGT,EACJ,YAAYL,EAAsB,OAAT,OACzB,SAAUK,EAAM,WAAaR,EAAY,GAAQ,QACjD,IAAKS,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAF,EAAK,YAAc","names":["forwardRef","useContext","NextLink","createContext","useCallback","useEffect","useMemo","useState","Fragment","jsx","jsxs","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","useEffect","useState","Script","useState","useEffect","getClientConfigFromEnv","clientConfigJson","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","isEqual","config1","config2","removeFlaggedPaths","config","app","match","_a","useClientConfig","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","useState","getClientConfigFromEnv","isLoading","setIsLoading","useEffect","originalClientConfig","group","newConfig","prevConfig","jsx","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","useState","useEffect","observer","entries","entry","link","mutations","mutation","Script","pathToRegexp","weakCache","getApplicationNameForPath","config","path","cache","pathname","name","application","group","childPath","defaultApplication","jsx","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","getApplicationNameForPath","Link","forwardRef","children","props","ref","prefetchHref","useContext","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/client/client-config.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/client/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/micro-frontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(await getWellKnownClientData());\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { getClientConfigFromEnv } from '../client/client-config';\nimport type { WellKnownClientData } from '../client/types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * micro-frontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/micro-frontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = getClientConfigFromEnv();\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing.matches) {\n if (pathGroup.options?.flag) {\n const flagName = pathGroup.options.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing.matches = newRoutingMatches;\n }\n\n return {\n config,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;;;ACqBtB,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;;;ACpBA,eAAsB,uBACpB,aAAqD,CAAC,GACxB;AAbhC;AAcE,QAAM,SAAS,uBAAuB;AACtC,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,WAAI,eAAU,YAAV,mBAAmB,MAAM;AAC3B,cAAM,WAAW,UAAU,QAAQ;AACnC,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,QAAQ,UAAU;AAAA,EAChC;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AFhCA,eAAsB,sCAA6D;AACjF,SAAO,2BAAa,KAA0B,MAAM,uBAAuB,CAAC;AAC9E;","names":[]}
1
+ {"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/client/client-config.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/client/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(await getWellKnownClientData());\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { getClientConfigFromEnv } from '../client/client-config';\nimport type { WellKnownClientData } from '../client/types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * micro-frontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = getClientConfigFromEnv();\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing.matches) {\n if (pathGroup.options?.flag) {\n const flagName = pathGroup.options.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing.matches = newRoutingMatches;\n }\n\n return {\n config,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;;;ACqBtB,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;;;ACpBA,eAAsB,uBACpB,aAAqD,CAAC,GACxB;AAbhC;AAcE,QAAM,SAAS,uBAAuB;AACtC,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,WAAI,eAAU,YAAV,mBAAmB,MAAM;AAC3B,cAAM,WAAW,UAAU,QAAQ;AACnC,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,QAAQ,UAAU;AAAA,EAChC;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AFhCA,eAAsB,sCAA6D;AACjF,SAAO,2BAAa,KAA0B,MAAM,uBAAuB,CAAC;AAC9E;","names":[]}
@@ -4,7 +4,7 @@ import { NextResponse } from 'next/server';
4
4
  * A Next.js App Router API handler to export the micro-frontends client config
5
5
  * data.
6
6
  *
7
- * @example In the `app/.well-known/vercel/micro-frontends/client-config/route.ts` file,
7
+ * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,
8
8
  * add this code:
9
9
  * ```
10
10
  * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/client/client-config.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/client/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/micro-frontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(await getWellKnownClientData());\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { getClientConfigFromEnv } from '../client/client-config';\nimport type { WellKnownClientData } from '../client/types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * micro-frontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/micro-frontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = getClientConfigFromEnv();\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing.matches) {\n if (pathGroup.options?.flag) {\n const flagName = pathGroup.options.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing.matches = newRoutingMatches;\n }\n\n return {\n config,\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACqBtB,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;;;ACpBA,eAAsB,uBACpB,aAAqD,CAAC,GACxB;AAbhC;AAcE,QAAM,SAAS,uBAAuB;AACtC,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,WAAI,eAAU,YAAV,mBAAmB,MAAM;AAC3B,cAAM,WAAW,UAAU,QAAQ;AACnC,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,QAAQ,UAAU;AAAA,EAChC;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AFhCA,eAAsB,sCAA6D;AACjF,SAAO,aAAa,KAA0B,MAAM,uBAAuB,CAAC;AAC9E;","names":[]}
1
+ {"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/client/client-config.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/client/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(await getWellKnownClientData());\n}\n","import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n","import { getClientConfigFromEnv } from '../client/client-config';\nimport type { WellKnownClientData } from '../client/types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * micro-frontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = getClientConfigFromEnv();\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing.matches) {\n if (pathGroup.options?.flag) {\n const flagName = pathGroup.options.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing.matches = newRoutingMatches;\n }\n\n return {\n config,\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACqBtB,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;;;ACpBA,eAAsB,uBACpB,aAAqD,CAAC,GACxB;AAbhC;AAcE,QAAM,SAAS,uBAAuB;AACtC,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,WAAI,eAAU,YAAV,mBAAmB,MAAM;AAC3B,cAAM,WAAW,UAAU,QAAQ;AACnC,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,QAAQ,UAAU;AAAA,EAChC;AAEA,SAAO;AAAA,IACL;AAAA,EACF;AACF;;;AFhCA,eAAsB,sCAA6D;AACjF,SAAO,aAAa,KAA0B,MAAM,uBAAuB,CAAC;AAC9E;","names":[]}
@@ -570,31 +570,6 @@ async function verifyPreviewDomain(req, rewriteDomain) {
570
570
  const vercelError = previewResponse.headers.get("x-vercel-error");
571
571
  return !(previewResponse.status === 404 && (vercelError === "DEPLOYMENT_NOT_FOUND" || vercelError === "NOT_FOUND"));
572
572
  }
573
- function microfrontendInternalRoutingHandler({
574
- config
575
- }) {
576
- return async (req) => {
577
- const payload = Object.fromEntries(
578
- await Promise.all(
579
- config.getAllApplications().map(async (application) => {
580
- let rewriteDomain = getDomainForCurrentEnvironment(application, {
581
- ignoreOverride: true
582
- });
583
- const isPreviewDomainAvailable = await verifyPreviewDomain(
584
- req,
585
- rewriteDomain
586
- );
587
- if (!isPreviewDomainAvailable) {
588
- rewriteDomain = application.production.toString();
589
- }
590
- const url = new URL(rewriteDomain);
591
- return [application.name, { routing: { host: url.host } }];
592
- })
593
- )
594
- );
595
- return import_server.NextResponse.json(payload);
596
- };
597
- }
598
573
  function getHandler({
599
574
  application,
600
575
  flagFn,
@@ -706,10 +681,6 @@ function getMicrofrontendsMiddleware({
706
681
  cookies: request.cookies.getAll()
707
682
  });
708
683
  const middlewares = [];
709
- middlewares.push({
710
- src: "/.well-known/vercel/microfrontend-routing",
711
- fn: microfrontendInternalRoutingHandler({ config })
712
- });
713
684
  for (const application of config.getAllApplications()) {
714
685
  if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
715
686
  continue;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/middleware/index.ts","../../src/next/middleware/middleware.ts","../../src/config/edge/microfrontend-config.ts","../../src/config/errors.ts","../../src/routing/url.ts","../../src/config/overrides/config.ts","../../src/config/common/host.ts","../../src/config/common/application.ts","../../src/config/common/microfrontend-config.ts","../../src/routing/get-domain-for-current-environment.ts"],"sourcesContent":["export * from './middleware';\nexport * from './types';\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicrofrontendConfigEdge } from '../../config/edge/microfrontend-config';\nimport { getDomainForCurrentEnvironment } from '../../routing/get-domain-for-current-environment';\nimport type { Application } from '../../config/common/application';\nimport type { HostConfig } from '../../config/schema';\nimport type {\n MicrofrontendsMiddleware,\n MicrofrontendsMiddlewareHandler,\n} from './types';\n\ninterface GetHandlerParams {\n application: Application;\n flagFn?: () => Promise<boolean>;\n pattern: RegExp;\n}\n\ninterface InternalRouting {\n routing: HostConfig;\n}\n\nasync function verifyPreviewDomain(\n req: NextRequest,\n rewriteDomain: string,\n): Promise<boolean> {\n const jwtCookie = req.cookies.get('_vercel_jwt')?.value;\n const deploymentProtectionBypassHeader = req.headers.get(\n 'x-vercel-protection-bypass',\n );\n\n // We make a `HEAD` request with `x-vercel-micro-frontends-check: 1` which will get handled in the proxy without reaching the deployment\n const previewResponse = await fetch(rewriteDomain, {\n method: 'HEAD',\n headers: {\n 'x-vercel-micro-frontends-check': '1',\n ...(jwtCookie ? { cookie: `_vercel_jwt=${jwtCookie}` } : {}),\n ...(deploymentProtectionBypassHeader\n ? {\n 'x-vercel-protection-bypass': deploymentProtectionBypassHeader,\n }\n : {}),\n },\n });\n\n const vercelError = previewResponse.headers.get('x-vercel-error');\n return !(\n previewResponse.status === 404 &&\n (vercelError === 'DEPLOYMENT_NOT_FOUND' || vercelError === 'NOT_FOUND')\n );\n}\n\nfunction microfrontendInternalRoutingHandler({\n config,\n}: { config: MicrofrontendConfigEdge }): MicrofrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse> => {\n const payload: Record<string, InternalRouting> = Object.fromEntries(\n await Promise.all(\n config.getAllApplications().map(async (application) => {\n let rewriteDomain = getDomainForCurrentEnvironment(application, {\n ignoreOverride: true,\n });\n const isPreviewDomainAvailable = await verifyPreviewDomain(\n req,\n rewriteDomain,\n );\n\n if (!isPreviewDomainAvailable) {\n rewriteDomain = application.production.toString();\n }\n\n const url = new URL(rewriteDomain);\n return [application.name, { routing: { host: url.host } }] as const;\n }),\n ),\n );\n\n return NextResponse.json(payload);\n };\n}\n\nfunction getHandler({\n application,\n flagFn,\n pattern,\n}: GetHandlerParams): MicrofrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse | undefined> => {\n const pathname = req.nextUrl.pathname;\n const search = req.nextUrl.search;\n\n // If this header is present, it means the proxy handled the routing.\n // Eventually the middleware should use proxy logic for all deployed envs (all except local)\n const proxyRouting = req.headers.get('X-Vercel-Mfe-Proxy') === '1';\n\n let rewriteDomain = proxyRouting\n ? null\n : getDomainForCurrentEnvironment(application);\n const patchedHeaders = new Headers(req.headers);\n\n const responseCallbacks: ((response: NextResponse) => void)[] = [];\n const onRewrite: (response: NextResponse) => NextResponse = (response) => {\n for (const callback of responseCallbacks) {\n callback(response);\n }\n\n return response;\n };\n\n // If this is a preview environment, we check the domain to make sure the project was deployed\n if (process.env.VERCEL_ENV === 'preview' && rewriteDomain) {\n const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;\n const assetPrefix = application.routing?.assetPrefix;\n\n if (\n assetPrefix &&\n pathname.startsWith(`/${assetPrefix}`) &&\n req.cookies.get(zoneFallbackCookieName)?.value === '1'\n ) {\n // If this is an asset request and we have the cookie, we can safely route to production without fetching\n rewriteDomain = application.production.toString();\n } else {\n try {\n let deploymentFound: boolean;\n if (req.headers.get('x-vercel-skip-deployment-existence-check')) {\n deploymentFound = true;\n } else {\n deploymentFound = await verifyPreviewDomain(req, rewriteDomain);\n }\n\n if (!deploymentFound) {\n // If the deployment is not found, we rewrite to the production domain\n rewriteDomain = application.production.toString();\n\n // We set a 1 minute cookie for the application to avoid checking again for every request\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '1', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 60, // 1 minute\n });\n });\n\n // When routing to a production url, we need to enable the toolbar manually,\n // since production deployments rely on the extension to do that, but the extension can't match the top-level domain\n try {\n const existingCookie = patchedHeaders.get('cookie');\n\n // If the request doesn't contain the toolbar cookie, we add it to support the middleware injection\n if (!existingCookie?.includes('__vercel_toolbar')) {\n patchedHeaders.set(\n 'cookie',\n [`__vercel_toolbar=1`, existingCookie].join('; '),\n );\n\n // We also return a `set-cookie` header to set the cookie locally, to support the Next.js injection which checks the document\n responseCallbacks.push((response) => {\n response.cookies.set('__vercel_toolbar', '1', {\n httpOnly: false,\n sameSite: 'lax',\n secure: true,\n maxAge: 29030400,\n });\n });\n }\n } catch (error) {\n // Do Nothing\n }\n } else if (req.cookies.get(zoneFallbackCookieName)?.value === '1') {\n // If the preview exists and we have the fallback cookie, we make sure to clear the cookie to route subsequent assets to the preview\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 0,\n });\n });\n }\n } catch {\n // Do Nothing\n }\n }\n }\n\n const isFlagEnabled = async (): Promise<boolean> =>\n flagFn ? flagFn() : true;\n\n // If the pattern doesn't match, we don't need to execute the flag\n if (pattern.test(pathname) && (await isFlagEnabled())) {\n if (proxyRouting) {\n const headers = new Headers(req.headers);\n /**\n * This header informs the proxy which zone the route the request to.\n * It will override any provided redirect / rewrite host.\n *\n * If a rewrite / redirect includes this header, the proxy will perform the\n * action, but will also replace the host with corresponding host for the zone.\n */\n headers.set('x-vercel-mfe-zone', application.name);\n return onRewrite(\n NextResponse.next({\n request: {\n headers,\n },\n headers: {\n // temporary, can delete when proxyRouting flag is removed\n 'x-vercel-mfe-middleware-sent-proxy': application.name,\n },\n }),\n );\n }\n return onRewrite(\n NextResponse.rewrite(`${rewriteDomain}${pathname}${search}`, {\n request: {\n headers: patchedHeaders,\n },\n }),\n );\n }\n };\n // If the path does not match the pattern, we don't do anything and let the request continue\n}\n\n/**\n * Returns an array of middleware functions that will handle routing to the\n * right microfrontends for the provided configuration.\n *\n * @param config - The microfrontends configuration object.\n * @param flagValues - An object that maps flag names to functions that return the flag value.\n */\nexport function getMicrofrontendsMiddleware({\n request,\n flagValues,\n}: {\n request: NextRequest;\n flagValues?: Record<string, () => Promise<boolean>>;\n}): MicrofrontendsMiddleware[] {\n const config = MicrofrontendConfigEdge.fromEnv({\n cookies: request.cookies.getAll(),\n });\n const middlewares: MicrofrontendsMiddleware[] = [];\n\n middlewares.push({\n src: '/.well-known/vercel/microfrontend-routing',\n fn: microfrontendInternalRoutingHandler({ config }),\n });\n\n for (const application of config.getAllApplications()) {\n if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {\n continue;\n }\n if (application.routing) {\n if (\n process.env.VERCEL_ENV === 'preview' &&\n application.routing.assetPrefix\n ) {\n const pattern = pathToRegexp(\n `/${application.routing.assetPrefix}/:path+`,\n );\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n pattern,\n }),\n });\n }\n for (const pathGroup of application.routing.matches) {\n if (process.env.VERCEL_ENV === 'preview' || pathGroup.options?.flag) {\n const flagName = pathGroup.options?.flag;\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let flagFn;\n if (flagName) {\n flagFn = flagValues?.[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${application.name} but not found in provided flag values.`,\n );\n }\n }\n for (const path of pathGroup.paths) {\n const pattern = pathToRegexp(path);\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n flagFn,\n pattern,\n }),\n });\n }\n }\n }\n }\n }\n return middlewares;\n}\n\n/**\n * Executes the middlewares returned by `getMicrofrontendsMiddleware` and\n * returns a `Response` if any of the microfrontends middlewares match or\n * `undefined` if none match. If a `Response` object is returned, the calling\n * code should return that Response from the Next.js middleware in order to\n * stop execution of the middleware and perform the rewrite.\n */\nexport async function runMicrofrontendsMiddleware(\n request: NextRequest,\n flagValues?: Record<string, () => Promise<boolean>>,\n): Promise<Response | undefined> {\n const pathname = request.nextUrl.pathname;\n const middlewares = getMicrofrontendsMiddleware({\n request,\n flagValues,\n });\n\n for (const mware of middlewares) {\n if (\n typeof mware.src === 'string'\n ? pathname === mware.src\n : mware.src.test(pathname)\n ) {\n // eslint-disable-next-line no-await-in-loop\n const response = await mware.fn(request);\n if (response) {\n return response;\n }\n }\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport { parse } from 'jsonc-parser';\nimport { MicrofrontendConfigCommon } from '../common/microfrontend-config';\nimport type { Config } from '../schema';\nimport { Overrides } from '../overrides';\n\n/**\n * Edge Runtime does not support ajv validation, or fs access.\n * This version of the MicrofrontendConfig does not validate the config shape,\n * and requires the config to be set on the environment.\n *\n * It should be used for Next.js middleware which runs in the Edge Runtime.\n */\nexport class MicrofrontendConfigEdge extends MicrofrontendConfigCommon {\n static fromEnv({\n cookies,\n }: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigEdge {\n return new MicrofrontendConfigCommon({\n config: parse(MicrofrontendConfigCommon.getConfigFromEnv()) as Config,\n overrides: Overrides.parseOverrides(cookies),\n });\n }\n}\n","export type MicrofrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'zone'\n | 'unknown';\n\nexport type MicrofrontendErrorSubtype =\n | 'not_found'\n | 'not_found_in_env'\n | 'invalid_asset_prefix'\n | 'invalid_main_path'\n | 'does_not_match_schema'\n | 'unable_to_read_file'\n | 'unsupported_validation_env'\n | 'unsupported_version'\n | 'invalid_path'\n | 'invalid_permissions'\n | 'invalid_syntax'\n | 'missing_microfrontend_config_path'\n | 'unsupported_operation';\n\n// A mapping of error types to their subtypes.\ninterface TypeToSubtype {\n zone:\n | 'invalid_asset_prefix'\n | 'invalid_path'\n | 'multiple_package_managers'\n | 'not_found';\n config:\n | 'conflicting_paths'\n | 'does_not_match_schema'\n | 'invalid_main_path'\n | 'invalid_preview_deployment_suffix'\n | 'multiple_default_applications'\n | 'no_default_application'\n | 'not_found_in_env'\n | 'not_found'\n | 'unable_to_read_file'\n | 'invalid_syntax'\n | 'invalid_permissions'\n | 'unsupported_operation'\n | 'unsupported_validation_env'\n | 'unsupported_version';\n packageJson:\n | 'missing_field_name'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n vercelJson:\n | 'missing_field_microFrontend_config_path'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n unknown: never;\n}\n\nexport type MicrofrontendErrorSource =\n | '@vercel/microfrontends'\n | '@vercel/microfrontends/next'\n | 'fs'\n | 'ajv';\n\nexport interface MicrofrontendErrorOptions<T extends MicrofrontendErrorType> {\n source?: MicrofrontendErrorSource;\n type?: T;\n subtype?: TypeToSubtype[T];\n}\n\ninterface HandleOptions {\n fileName?: string;\n}\n\nexport class MicrofrontendError<\n T extends MicrofrontendErrorType = 'unknown',\n> extends Error {\n public source: MicrofrontendErrorSource;\n public type: T;\n public subtype?: TypeToSubtype[T];\n\n constructor(message: string, opts?: MicrofrontendErrorOptions<T>) {\n super(message);\n this.name = 'MicrofrontendsError';\n this.source = opts?.source ?? '@vercel/microfrontends';\n this.type = opts?.type ?? ('unknown' as T);\n this.subtype = opts?.subtype;\n Error.captureStackTrace(this, MicrofrontendError);\n }\n\n isKnown(): boolean {\n return this.type !== 'unknown';\n }\n\n isUnknown(): boolean {\n return !this.isKnown();\n }\n\n /**\n * Converts an error to a MicrofrontendsError.\n * @param original - The original error to convert.\n * @returns The converted MicrofrontendsError.\n */\n static convert(\n original: Error,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (opts?.fileName) {\n const err = MicrofrontendError.convertFSError(original, opts.fileName);\n if (err) {\n return err;\n }\n }\n\n if (\n original.message.includes(\n 'Code generation from strings disallowed for this context',\n )\n ) {\n return new MicrofrontendError(original.message, {\n type: 'config',\n subtype: 'unsupported_validation_env',\n source: 'ajv',\n });\n }\n\n // unknown catch-all\n return new MicrofrontendError(original.message);\n }\n\n static convertFSError(\n original: Error,\n fileName: string,\n ): MicrofrontendError<MicrofrontendErrorType> | null {\n if (original instanceof Error && 'code' in original) {\n if (original.code === 'ENOENT') {\n return new MicrofrontendError(`Could not find \"${fileName}\"`, {\n type: 'config',\n subtype: 'unable_to_read_file',\n source: 'fs',\n });\n }\n if (original.code === 'EACCES') {\n return new MicrofrontendError(\n `Permission denied while accessing \"${fileName}\"`,\n {\n type: 'config',\n subtype: 'invalid_permissions',\n source: 'fs',\n },\n );\n }\n }\n\n if (original instanceof SyntaxError) {\n return new MicrofrontendError(\n `Failed to parse \"${fileName}\": Invalid JSON format.`,\n {\n type: 'config',\n subtype: 'invalid_syntax',\n source: 'fs',\n },\n );\n }\n\n return null;\n }\n\n /**\n * Handles an unknown error and returns a MicrofrontendsError instance.\n * @param err - The error to handle.\n * @returns A MicrofrontendsError instance.\n */\n static handle(\n err: unknown,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (err instanceof MicrofrontendError) {\n return err as MicrofrontendError<MicrofrontendErrorType>;\n }\n\n // handle Error instances\n if (err instanceof Error) {\n return MicrofrontendError.convert(err, opts);\n }\n\n // handle object errors\n if (typeof err === 'object' && err !== null) {\n if ('message' in err && typeof err.message === 'string') {\n return MicrofrontendError.convert(new Error(err.message), opts);\n }\n }\n\n return new MicrofrontendError('An unknown error occurred');\n }\n}\n","// NOTE: This is copied from https://github.com/vercel/api/blob/main/packages/util-func/src/url-safe-string.ts.\n// See https://linear.app/vercel/issue/FDRTN-199/spike-move-preview-domain-generation-logic-into-build-and-deploy\n// for cleaning this up before release.\n\ninterface Options {\n joinString?: string;\n lowercaseOnly?: boolean;\n maxLen?: number;\n regexRemovePattern?: RegExp;\n trimWhitespace?: boolean;\n}\n\n/**\n * This function allows to convert single string to URL-safe tags to use for routing,\n * SEO purposes, etc. It is taken from https://www.npmjs.com/package/url-safe-string\n * and implemented here to be typed and skip the dependency.\n */\nfunction buildUrlSafeString(givenOpts: Options = {}): {\n generate: (...args: string[]) => string;\n} {\n const options = {\n joinString: '-',\n lowercaseOnly: true,\n maxLen: 100,\n regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,\n trimWhitespace: true,\n ...givenOpts,\n };\n\n return {\n generate: (...args: string[]) => {\n const reJoinString = new RegExp(`${options.joinString}+`, 'g');\n\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let tag;\n\n if (args.length === 0) {\n throw new Error('generate method must be passed at least one argument');\n }\n\n // Validate, trim all arguments:\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (typeof arg !== 'string')\n throw new Error('all supplied arguments must be Strings');\n\n if (options.trimWhitespace) {\n args[i] = arg.trim();\n }\n }\n\n // Join strings and convert whitespace between words to join string\n tag = args.join(options.joinString);\n tag = tag.replace(/\\s/g, options.joinString);\n if (options.lowercaseOnly) tag = tag.toLowerCase();\n // Regex away anything \"unsafe\", but ignore the join string!\n tag = tag.replace(options.regexRemovePattern, (match) => {\n if (match === options.joinString) return match;\n\n return '';\n });\n\n // Truncate in excess of maxLen\n if (tag.length > options.maxLen) tag = tag.substring(0, options.maxLen);\n\n // Remove any duplicates of the join string using this pattern: /<join string>+/g\n tag = tag.replace(reJoinString, options.joinString);\n\n return tag;\n },\n };\n}\n\n/**\n * Export a preconfigured version for convenience.\n */\nexport const urlSafeString = buildUrlSafeString().generate;\n\nexport function makeUrlSafe(name: string): string {\n return urlSafeString(name.replace(/\\//g, '-'))\n .replace(/^-*/g, '')\n .replace(/-*$/g, '');\n}\n","import { makeUrlSafe } from '../../routing/url';\nimport type { MicrofrontendConfig } from '../microfrontend-config';\nimport type { OverridesConfig } from './types';\n\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\n\nexport class Overrides {\n config: OverridesConfig;\n\n constructor(config: OverridesConfig) {\n this.config = config;\n }\n\n static overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n\n static getAppEnvOverrideCookieName(zone: string): string {\n return `${Overrides.overrideEnvCookiePrefix}${zone}`;\n }\n\n static isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n }\n\n static getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n }): { zone: string; host: string } | undefined {\n if (!Overrides.isOverrideCookie(cookie) || !cookie.value) return;\n return {\n zone: cookie.name.replace(Overrides.overrideEnvCookiePrefix, ''),\n host: cookie.value,\n };\n }\n\n static parseOverrides(\n cookies: { name: string; value?: string | null }[],\n ): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = Overrides.getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.zone] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n }\n\n static validOverrideDomainsForZone(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n ): string[] {\n const projectName = microfrontendConfig.getZone(zone).vercel?.projectName;\n if (!projectName) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n const parsedProjectName = makeUrlSafe(projectName);\n const previewDeploymentSuffix =\n microfrontendConfig.options?.vercel?.previewDeploymentSuffix;\n const teamSlug = microfrontendConfig.options?.vercel?.teamSlug;\n if (!teamSlug && !previewDeploymentSuffix) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n\n const suffix = previewDeploymentSuffix\n ? `.${previewDeploymentSuffix}`\n : `-${teamSlug}.vercel.app`;\n\n // <project-name>-git-<branch-name>-<scope-slug>.vercel.app\n // <project-name>-git-<branch-name>.<custom-suffix>\n return [\n `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,\n microfrontendConfig.getZone(zone).production.host,\n ];\n }\n\n static validateOverrideDomain(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n domain: string,\n ): boolean {\n return new RegExp(\n `^${Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(\n '|',\n )}$`,\n ).test(domain);\n }\n\n serialize(): OverridesConfig {\n return this.config;\n }\n}\n","import type { HostConfig } from '../schema';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: HostConfig['host'];\n port: number;\n serialized: HostConfig;\n\n constructor({ protocol, host, port }: HostConfig) {\n this.protocol = protocol || 'https';\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.serialized = {\n protocol,\n host,\n ...(port ? { port } : undefined),\n };\n }\n\n isLocal(): boolean {\n return this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: { protocol: HostConfig['protocol']; port?: HostConfig['port'] }): number {\n if (!port) {\n if (protocol === 'http') {\n return 80;\n }\n return 443;\n }\n\n return port;\n }\n\n isDefaultPort(): boolean {\n return this.port === Host.getPort({ protocol: this.protocol });\n }\n\n toString(opts: HostDisplayOptions = {}): string {\n const url = this.toUrl(opts);\n // strip the trailing slash\n return url.toString().replace(/\\/$/, '');\n }\n\n toUrl(opts: HostDisplayOptions = {}): URL {\n const { includeDefaultPort } = opts;\n const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? '' : `:${this.port}`}`;\n\n return new URL(url);\n }\n\n serialize(): HostConfig {\n return this.serialized;\n }\n}\n","import type { ApplicationConfig, Routing, Vercel } from '../schema';\nimport type { ApplicationOverrideConfig } from '../overrides';\nimport { MicrofrontendError } from '../errors';\nimport { Host } from './host';\n\nexport class Application {\n default: boolean;\n routing?: Routing;\n name: string;\n development: {\n local: Host;\n fallback?: Host;\n };\n production: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: { app: ApplicationConfig; overrides?: ApplicationOverrideConfig },\n ) {\n // validate\n Application.validate(name, app);\n\n this.name = name;\n this.default = app.default;\n this.routing = app.routing;\n this.development = {\n local: new Host(app.development.local),\n fallback: app.development.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = new Host(app.production);\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n static validate(name: string, app: ApplicationConfig): void {\n // validate assetPrefix\n if (\n app.routing?.assetPrefix?.startsWith('/') ||\n app.routing?.assetPrefix?.endsWith('/')\n ) {\n throw new MicrofrontendError(\n `Invalid assetPrefix for application \"${name}\". Must not start or end with a slash.`,\n { type: 'zone', subtype: 'invalid_asset_prefix' },\n );\n }\n\n // validate routes\n for (const group of app.routing?.matches ?? []) {\n for (const p of group.paths) {\n if (p === '/') {\n continue;\n }\n if (p.endsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must not end with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n\n if (!p.startsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must start with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n }\n }\n }\n\n serialize(): ApplicationConfig {\n if (this.routing === undefined || this.default) {\n return {\n default: true,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n\n return {\n default: false,\n routing: this.routing,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n}\n","import type { ApplicationConfig, Config, Options } from '../schema';\nimport { MicrofrontendError } from '../errors';\nimport type { OverridesConfig } from '../overrides';\nimport { Overrides } from '../overrides/config';\nimport { Application } from './application';\n\nconst SUPPORTED_VERSIONS = ['1'];\nconst DEFAULT_LOCAL_PROXY_PORT = 3024;\n\n/**\n * A class to manage the microfrontends configuration.\n *\n * This class should not be used directly. Instead, use the `MicrofrontendConfig` or `MicrofrontendConfigEdgeRuntime` classes.\n */\nexport class MicrofrontendConfigCommon {\n config: Config;\n name?: string;\n zones: Record<string, Application> = {};\n version: string;\n overrides?: Overrides;\n options?: Options;\n $schema: string | undefined;\n\n constructor({\n config,\n overrides,\n }: { config: Config; overrides?: OverridesConfig }) {\n if (!SUPPORTED_VERSIONS.includes(config.version)) {\n throw new MicrofrontendError(\n `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n this.overrides =\n overrides && !disableOverrides ? new Overrides(overrides) : undefined;\n\n // create zones\n for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {\n this.zones[zoneName] = new Application(zoneName, {\n app: zoneConfig,\n overrides: !disableOverrides\n ? this.overrides?.config.applications[zoneName]\n : undefined,\n });\n }\n\n this.config = config;\n this.name = config.name;\n this.version = config.version;\n this.options = config.options;\n this.$schema = config.$schema;\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n protected static getConfigFromEnv(): string {\n const config = process.env.MFE_CONFIG;\n if (!config) {\n throw new MicrofrontendError(`Missing \"MFE_CONFIG\" in environment.`, {\n type: 'config',\n subtype: 'not_found_in_env',\n });\n }\n return config;\n }\n\n static fromEnv(_: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigCommon | Promise<MicrofrontendConfigCommon> {\n throw new Error('Not implemented');\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getAllApplications(): Application[] {\n return Object.values(this.zones);\n }\n\n getZone(name: string): Application {\n const zone = this.zones[name];\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find microfrontends configuration for application \"${name}\"`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n getApplicationByProjectId(projectId: string): Application | undefined {\n return Object.values(this.zones).find(\n (zone) => zone.vercel?.projectId === projectId,\n );\n }\n\n getDefaultZone(): Application {\n const zone = Object.values(this.zones).find((z) => z.default);\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find default zone in microfrontends configuration`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n /**\n * Returns the configured port for the local proxy\n */\n getLocalProxyPort(): number {\n return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;\n }\n\n /**\n * Serializes the class back to the Schema type.\n *\n * NOTE: This is used when writing the config to disk and must always match the input Schema\n */\n toSchemaJson(): Config {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n $schema: this.$schema,\n name: this.name,\n version: this.version,\n options: this.options,\n applications,\n };\n }\n\n serialize(): { config: Config; overrides?: OverridesConfig } {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n config: {\n name: this.name,\n version: this.version,\n applications,\n options: this.options,\n $schema: this.$schema,\n },\n overrides: this.overrides?.serialize(),\n };\n }\n\n write(_: string): void {\n throw new MicrofrontendError(\n `Writing to file to disk requires using an instance of \"MicrofrontendConfig\".`,\n { type: 'config', subtype: 'unsupported_operation' },\n );\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { Application } from '../config/common/application';\n\nfunction debugDomains(zone: string, env: string, domain: string): void {\n if (process.env.MFE_DEBUG === 'true') {\n const indent = ' '.repeat(4);\n const header = 'domains (zone (env) -> domain)';\n const separator = '⎯'.repeat(header.length);\n const line = `${indent} 1. ${zone} (${env}) -> ${domain}`;\n\n // eslint-disable-next-line no-console\n console.log(`${indent}${header}\\n${indent}${separator}\\n${line}\\n`);\n }\n}\n\n/**\n * Returns the Vercel domain for the given application based on the current\n * environment (local, preview, production).\n */\nexport function getDomainForCurrentEnvironment(\n zone: Application,\n opts: { ignoreOverride?: boolean } = {},\n): string {\n if (!opts.ignoreOverride && zone.overrides?.environment) {\n return zone.overrides.environment.toString();\n }\n const zoneName = zone.name;\n if (!process.env.VERCEL_ENV || process.env.VERCEL_ENV === 'development') {\n // TODO(mknichel): Convert this back to the local development domain once\n // there is local development proxy support.\n const domain =\n process.env.NODE_ENV === 'test'\n ? zone.development.local.toString()\n : zone.production.toString();\n debugDomains(zoneName, 'development', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'production') {\n const domain = zone.production.toString();\n debugDomains(zoneName, 'production', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'preview') {\n const MFE_PREVIEW_DOMAINS = JSON.parse(\n process.env.MFE_PREVIEW_DOMAINS ?? '{}',\n ) as Record<string, string>;\n if (MFE_PREVIEW_DOMAINS[zoneName]) {\n debugDomains(zoneName, 'preview', MFE_PREVIEW_DOMAINS[zoneName]);\n return MFE_PREVIEW_DOMAINS[zoneName];\n }\n\n throw new Error(\n `Could not find preview domain for application \"${zoneName}\"`,\n );\n }\n // TODO(mknichel): Add support in this function for custom environments.\n // Custom Vercel environments may have an arbitrary string for `VERCEL_ENV`.\n debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());\n return zone.production.toString();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,oBAA6B;AAC7B,4BAA6B;;;ACF7B,0BAAsB;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC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AA,MACH;AACA,iBAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,YAAI,QAAQ,IAAI,eAAe,eAAa,eAAU,YAAV,mBAAmB,OAAM;AACnE,gBAAM,YAAW,eAAU,YAAV,mBAAmB;AAEpC,cAAI;AACJ,cAAI,UAAU;AACZ,qBAAS,yCAAa;AACtB,gBAAI,CAAC,QAAQ;AACX,oBAAM,IAAI;AAAA,gBACR,SAAS,8DAA8D,UAAU,yBAAyB,YAAY;AAAA,cACxH;AAAA,YACF;AAAA,UACF;AACA,qBAAW,QAAQ,UAAU,OAAO;AAClC,kBAAM,cAAU,oCAAa,IAAI;AACjC,wBAAY,KAAK;AAAA,cACf,KAAK;AAAA,cACL,IAAI,WAAW;AAAA,gBACb;AAAA,gBACA;AAAA,gBACA;AAAA,cACF,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAsB,4BACpB,SACA,YAC+B;AAC/B,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,cAAc,4BAA4B;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,aAAW,SAAS,aAAa;AAC/B,QACE,OAAO,MAAM,QAAQ,WACjB,aAAa,MAAM,MACnB,MAAM,IAAI,KAAK,QAAQ,GAC3B;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,OAAO;AACvC,UAAI,UAAU;AACZ,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/next/middleware/index.ts","../../src/next/middleware/middleware.ts","../../src/config/edge/microfrontend-config.ts","../../src/config/errors.ts","../../src/routing/url.ts","../../src/config/overrides/config.ts","../../src/config/common/host.ts","../../src/config/common/application.ts","../../src/config/common/microfrontend-config.ts","../../src/routing/get-domain-for-current-environment.ts"],"sourcesContent":["export * from './middleware';\nexport * from './types';\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicrofrontendConfigEdge } from '../../config/edge/microfrontend-config';\nimport { getDomainForCurrentEnvironment } from '../../routing/get-domain-for-current-environment';\nimport type { Application } from '../../config/common/application';\nimport type {\n MicrofrontendsMiddleware,\n MicrofrontendsMiddlewareHandler,\n} from './types';\n\ninterface GetHandlerParams {\n application: Application;\n flagFn?: () => Promise<boolean>;\n pattern: RegExp;\n}\n\nasync function verifyPreviewDomain(\n req: NextRequest,\n rewriteDomain: string,\n): Promise<boolean> {\n const jwtCookie = req.cookies.get('_vercel_jwt')?.value;\n const deploymentProtectionBypassHeader = req.headers.get(\n 'x-vercel-protection-bypass',\n );\n\n // We make a `HEAD` request with `x-vercel-micro-frontends-check: 1` which will get handled in the proxy without reaching the deployment\n const previewResponse = await fetch(rewriteDomain, {\n method: 'HEAD',\n headers: {\n 'x-vercel-micro-frontends-check': '1',\n ...(jwtCookie ? { cookie: `_vercel_jwt=${jwtCookie}` } : {}),\n ...(deploymentProtectionBypassHeader\n ? {\n 'x-vercel-protection-bypass': deploymentProtectionBypassHeader,\n }\n : {}),\n },\n });\n\n const vercelError = previewResponse.headers.get('x-vercel-error');\n return !(\n previewResponse.status === 404 &&\n (vercelError === 'DEPLOYMENT_NOT_FOUND' || vercelError === 'NOT_FOUND')\n );\n}\n\nfunction getHandler({\n application,\n flagFn,\n pattern,\n}: GetHandlerParams): MicrofrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse | undefined> => {\n const pathname = req.nextUrl.pathname;\n const search = req.nextUrl.search;\n\n // If this header is present, it means the proxy handled the routing.\n // Eventually the middleware should use proxy logic for all deployed envs (all except local)\n const proxyRouting = req.headers.get('X-Vercel-Mfe-Proxy') === '1';\n\n let rewriteDomain = proxyRouting\n ? null\n : getDomainForCurrentEnvironment(application);\n const patchedHeaders = new Headers(req.headers);\n\n const responseCallbacks: ((response: NextResponse) => void)[] = [];\n const onRewrite: (response: NextResponse) => NextResponse = (response) => {\n for (const callback of responseCallbacks) {\n callback(response);\n }\n\n return response;\n };\n\n // If this is a preview environment, we check the domain to make sure the project was deployed\n if (process.env.VERCEL_ENV === 'preview' && rewriteDomain) {\n const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;\n const assetPrefix = application.routing?.assetPrefix;\n\n if (\n assetPrefix &&\n pathname.startsWith(`/${assetPrefix}`) &&\n req.cookies.get(zoneFallbackCookieName)?.value === '1'\n ) {\n // If this is an asset request and we have the cookie, we can safely route to production without fetching\n rewriteDomain = application.production.toString();\n } else {\n try {\n let deploymentFound: boolean;\n if (req.headers.get('x-vercel-skip-deployment-existence-check')) {\n deploymentFound = true;\n } else {\n deploymentFound = await verifyPreviewDomain(req, rewriteDomain);\n }\n\n if (!deploymentFound) {\n // If the deployment is not found, we rewrite to the production domain\n rewriteDomain = application.production.toString();\n\n // We set a 1 minute cookie for the application to avoid checking again for every request\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '1', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 60, // 1 minute\n });\n });\n\n // When routing to a production url, we need to enable the toolbar manually,\n // since production deployments rely on the extension to do that, but the extension can't match the top-level domain\n try {\n const existingCookie = patchedHeaders.get('cookie');\n\n // If the request doesn't contain the toolbar cookie, we add it to support the middleware injection\n if (!existingCookie?.includes('__vercel_toolbar')) {\n patchedHeaders.set(\n 'cookie',\n [`__vercel_toolbar=1`, existingCookie].join('; '),\n );\n\n // We also return a `set-cookie` header to set the cookie locally, to support the Next.js injection which checks the document\n responseCallbacks.push((response) => {\n response.cookies.set('__vercel_toolbar', '1', {\n httpOnly: false,\n sameSite: 'lax',\n secure: true,\n maxAge: 29030400,\n });\n });\n }\n } catch (error) {\n // Do Nothing\n }\n } else if (req.cookies.get(zoneFallbackCookieName)?.value === '1') {\n // If the preview exists and we have the fallback cookie, we make sure to clear the cookie to route subsequent assets to the preview\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 0,\n });\n });\n }\n } catch {\n // Do Nothing\n }\n }\n }\n\n const isFlagEnabled = async (): Promise<boolean> =>\n flagFn ? flagFn() : true;\n\n // If the pattern doesn't match, we don't need to execute the flag\n if (pattern.test(pathname) && (await isFlagEnabled())) {\n if (proxyRouting) {\n const headers = new Headers(req.headers);\n /**\n * This header informs the proxy which zone the route the request to.\n * It will override any provided redirect / rewrite host.\n *\n * If a rewrite / redirect includes this header, the proxy will perform the\n * action, but will also replace the host with corresponding host for the zone.\n */\n headers.set('x-vercel-mfe-zone', application.name);\n return onRewrite(\n NextResponse.next({\n request: {\n headers,\n },\n headers: {\n // temporary, can delete when proxyRouting flag is removed\n 'x-vercel-mfe-middleware-sent-proxy': application.name,\n },\n }),\n );\n }\n return onRewrite(\n NextResponse.rewrite(`${rewriteDomain}${pathname}${search}`, {\n request: {\n headers: patchedHeaders,\n },\n }),\n );\n }\n };\n // If the path does not match the pattern, we don't do anything and let the request continue\n}\n\n/**\n * Returns an array of middleware functions that will handle routing to the\n * right microfrontends for the provided configuration.\n *\n * @param config - The microfrontends configuration object.\n * @param flagValues - An object that maps flag names to functions that return the flag value.\n */\nexport function getMicrofrontendsMiddleware({\n request,\n flagValues,\n}: {\n request: NextRequest;\n flagValues?: Record<string, () => Promise<boolean>>;\n}): MicrofrontendsMiddleware[] {\n const config = MicrofrontendConfigEdge.fromEnv({\n cookies: request.cookies.getAll(),\n });\n const middlewares: MicrofrontendsMiddleware[] = [];\n\n for (const application of config.getAllApplications()) {\n if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {\n continue;\n }\n if (application.routing) {\n if (\n process.env.VERCEL_ENV === 'preview' &&\n application.routing.assetPrefix\n ) {\n const pattern = pathToRegexp(\n `/${application.routing.assetPrefix}/:path+`,\n );\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n pattern,\n }),\n });\n }\n for (const pathGroup of application.routing.matches) {\n if (process.env.VERCEL_ENV === 'preview' || pathGroup.options?.flag) {\n const flagName = pathGroup.options?.flag;\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let flagFn;\n if (flagName) {\n flagFn = flagValues?.[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${application.name} but not found in provided flag values.`,\n );\n }\n }\n for (const path of pathGroup.paths) {\n const pattern = pathToRegexp(path);\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n flagFn,\n pattern,\n }),\n });\n }\n }\n }\n }\n }\n return middlewares;\n}\n\n/**\n * Executes the middlewares returned by `getMicrofrontendsMiddleware` and\n * returns a `Response` if any of the microfrontends middlewares match or\n * `undefined` if none match. If a `Response` object is returned, the calling\n * code should return that Response from the Next.js middleware in order to\n * stop execution of the middleware and perform the rewrite.\n */\nexport async function runMicrofrontendsMiddleware(\n request: NextRequest,\n flagValues?: Record<string, () => Promise<boolean>>,\n): Promise<Response | undefined> {\n const pathname = request.nextUrl.pathname;\n const middlewares = getMicrofrontendsMiddleware({\n request,\n flagValues,\n });\n\n for (const mware of middlewares) {\n if (\n typeof mware.src === 'string'\n ? pathname === mware.src\n : mware.src.test(pathname)\n ) {\n // eslint-disable-next-line no-await-in-loop\n const response = await mware.fn(request);\n if (response) {\n return response;\n }\n }\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport { parse } from 'jsonc-parser';\nimport { MicrofrontendConfigCommon } from '../common/microfrontend-config';\nimport type { Config } from '../schema';\nimport { Overrides } from '../overrides';\n\n/**\n * Edge Runtime does not support ajv validation, or fs access.\n * This version of the MicrofrontendConfig does not validate the config shape,\n * and requires the config to be set on the environment.\n *\n * It should be used for Next.js middleware which runs in the Edge Runtime.\n */\nexport class MicrofrontendConfigEdge extends MicrofrontendConfigCommon {\n static fromEnv({\n cookies,\n }: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigEdge {\n return new MicrofrontendConfigCommon({\n config: parse(MicrofrontendConfigCommon.getConfigFromEnv()) as Config,\n overrides: Overrides.parseOverrides(cookies),\n });\n }\n}\n","export type MicrofrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'zone'\n | 'unknown';\n\nexport type MicrofrontendErrorSubtype =\n | 'not_found'\n | 'not_found_in_env'\n | 'invalid_asset_prefix'\n | 'invalid_main_path'\n | 'does_not_match_schema'\n | 'unable_to_read_file'\n | 'unsupported_validation_env'\n | 'unsupported_version'\n | 'invalid_path'\n | 'invalid_permissions'\n | 'invalid_syntax'\n | 'missing_microfrontend_config_path'\n | 'unsupported_operation';\n\n// A mapping of error types to their subtypes.\ninterface TypeToSubtype {\n zone:\n | 'invalid_asset_prefix'\n | 'invalid_path'\n | 'multiple_package_managers'\n | 'not_found';\n config:\n | 'conflicting_paths'\n | 'does_not_match_schema'\n | 'invalid_main_path'\n | 'invalid_preview_deployment_suffix'\n | 'multiple_default_applications'\n | 'no_default_application'\n | 'not_found_in_env'\n | 'not_found'\n | 'unable_to_read_file'\n | 'invalid_syntax'\n | 'invalid_permissions'\n | 'unsupported_operation'\n | 'unsupported_validation_env'\n | 'unsupported_version';\n packageJson:\n | 'missing_field_name'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n vercelJson:\n | 'missing_field_microFrontend_config_path'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n unknown: never;\n}\n\nexport type MicrofrontendErrorSource =\n | '@vercel/microfrontends'\n | '@vercel/microfrontends/next'\n | 'fs'\n | 'ajv';\n\nexport interface MicrofrontendErrorOptions<T extends MicrofrontendErrorType> {\n source?: MicrofrontendErrorSource;\n type?: T;\n subtype?: TypeToSubtype[T];\n}\n\ninterface HandleOptions {\n fileName?: string;\n}\n\nexport class MicrofrontendError<\n T extends MicrofrontendErrorType = 'unknown',\n> extends Error {\n public source: MicrofrontendErrorSource;\n public type: T;\n public subtype?: TypeToSubtype[T];\n\n constructor(message: string, opts?: MicrofrontendErrorOptions<T>) {\n super(message);\n this.name = 'MicrofrontendsError';\n this.source = opts?.source ?? '@vercel/microfrontends';\n this.type = opts?.type ?? ('unknown' as T);\n this.subtype = opts?.subtype;\n Error.captureStackTrace(this, MicrofrontendError);\n }\n\n isKnown(): boolean {\n return this.type !== 'unknown';\n }\n\n isUnknown(): boolean {\n return !this.isKnown();\n }\n\n /**\n * Converts an error to a MicrofrontendsError.\n * @param original - The original error to convert.\n * @returns The converted MicrofrontendsError.\n */\n static convert(\n original: Error,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (opts?.fileName) {\n const err = MicrofrontendError.convertFSError(original, opts.fileName);\n if (err) {\n return err;\n }\n }\n\n if (\n original.message.includes(\n 'Code generation from strings disallowed for this context',\n )\n ) {\n return new MicrofrontendError(original.message, {\n type: 'config',\n subtype: 'unsupported_validation_env',\n source: 'ajv',\n });\n }\n\n // unknown catch-all\n return new MicrofrontendError(original.message);\n }\n\n static convertFSError(\n original: Error,\n fileName: string,\n ): MicrofrontendError<MicrofrontendErrorType> | null {\n if (original instanceof Error && 'code' in original) {\n if (original.code === 'ENOENT') {\n return new MicrofrontendError(`Could not find \"${fileName}\"`, {\n type: 'config',\n subtype: 'unable_to_read_file',\n source: 'fs',\n });\n }\n if (original.code === 'EACCES') {\n return new MicrofrontendError(\n `Permission denied while accessing \"${fileName}\"`,\n {\n type: 'config',\n subtype: 'invalid_permissions',\n source: 'fs',\n },\n );\n }\n }\n\n if (original instanceof SyntaxError) {\n return new MicrofrontendError(\n `Failed to parse \"${fileName}\": Invalid JSON format.`,\n {\n type: 'config',\n subtype: 'invalid_syntax',\n source: 'fs',\n },\n );\n }\n\n return null;\n }\n\n /**\n * Handles an unknown error and returns a MicrofrontendsError instance.\n * @param err - The error to handle.\n * @returns A MicrofrontendsError instance.\n */\n static handle(\n err: unknown,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (err instanceof MicrofrontendError) {\n return err as MicrofrontendError<MicrofrontendErrorType>;\n }\n\n // handle Error instances\n if (err instanceof Error) {\n return MicrofrontendError.convert(err, opts);\n }\n\n // handle object errors\n if (typeof err === 'object' && err !== null) {\n if ('message' in err && typeof err.message === 'string') {\n return MicrofrontendError.convert(new Error(err.message), opts);\n }\n }\n\n return new MicrofrontendError('An unknown error occurred');\n }\n}\n","// NOTE: This is copied from https://github.com/vercel/api/blob/main/packages/util-func/src/url-safe-string.ts.\n// See https://linear.app/vercel/issue/FDRTN-199/spike-move-preview-domain-generation-logic-into-build-and-deploy\n// for cleaning this up before release.\n\ninterface Options {\n joinString?: string;\n lowercaseOnly?: boolean;\n maxLen?: number;\n regexRemovePattern?: RegExp;\n trimWhitespace?: boolean;\n}\n\n/**\n * This function allows to convert single string to URL-safe tags to use for routing,\n * SEO purposes, etc. It is taken from https://www.npmjs.com/package/url-safe-string\n * and implemented here to be typed and skip the dependency.\n */\nfunction buildUrlSafeString(givenOpts: Options = {}): {\n generate: (...args: string[]) => string;\n} {\n const options = {\n joinString: '-',\n lowercaseOnly: true,\n maxLen: 100,\n regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,\n trimWhitespace: true,\n ...givenOpts,\n };\n\n return {\n generate: (...args: string[]) => {\n const reJoinString = new RegExp(`${options.joinString}+`, 'g');\n\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let tag;\n\n if (args.length === 0) {\n throw new Error('generate method must be passed at least one argument');\n }\n\n // Validate, trim all arguments:\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (typeof arg !== 'string')\n throw new Error('all supplied arguments must be Strings');\n\n if (options.trimWhitespace) {\n args[i] = arg.trim();\n }\n }\n\n // Join strings and convert whitespace between words to join string\n tag = args.join(options.joinString);\n tag = tag.replace(/\\s/g, options.joinString);\n if (options.lowercaseOnly) tag = tag.toLowerCase();\n // Regex away anything \"unsafe\", but ignore the join string!\n tag = tag.replace(options.regexRemovePattern, (match) => {\n if (match === options.joinString) return match;\n\n return '';\n });\n\n // Truncate in excess of maxLen\n if (tag.length > options.maxLen) tag = tag.substring(0, options.maxLen);\n\n // Remove any duplicates of the join string using this pattern: /<join string>+/g\n tag = tag.replace(reJoinString, options.joinString);\n\n return tag;\n },\n };\n}\n\n/**\n * Export a preconfigured version for convenience.\n */\nexport const urlSafeString = buildUrlSafeString().generate;\n\nexport function makeUrlSafe(name: string): string {\n return urlSafeString(name.replace(/\\//g, '-'))\n .replace(/^-*/g, '')\n .replace(/-*$/g, '');\n}\n","import { makeUrlSafe } from '../../routing/url';\nimport type { MicrofrontendConfig } from '../microfrontend-config';\nimport type { OverridesConfig } from './types';\n\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\n\nexport class Overrides {\n config: OverridesConfig;\n\n constructor(config: OverridesConfig) {\n this.config = config;\n }\n\n static overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n\n static getAppEnvOverrideCookieName(zone: string): string {\n return `${Overrides.overrideEnvCookiePrefix}${zone}`;\n }\n\n static isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n }\n\n static getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n }): { zone: string; host: string } | undefined {\n if (!Overrides.isOverrideCookie(cookie) || !cookie.value) return;\n return {\n zone: cookie.name.replace(Overrides.overrideEnvCookiePrefix, ''),\n host: cookie.value,\n };\n }\n\n static parseOverrides(\n cookies: { name: string; value?: string | null }[],\n ): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = Overrides.getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.zone] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n }\n\n static validOverrideDomainsForZone(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n ): string[] {\n const projectName = microfrontendConfig.getZone(zone).vercel?.projectName;\n if (!projectName) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n const parsedProjectName = makeUrlSafe(projectName);\n const previewDeploymentSuffix =\n microfrontendConfig.options?.vercel?.previewDeploymentSuffix;\n const teamSlug = microfrontendConfig.options?.vercel?.teamSlug;\n if (!teamSlug && !previewDeploymentSuffix) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n\n const suffix = previewDeploymentSuffix\n ? `.${previewDeploymentSuffix}`\n : `-${teamSlug}.vercel.app`;\n\n // <project-name>-git-<branch-name>-<scope-slug>.vercel.app\n // <project-name>-git-<branch-name>.<custom-suffix>\n return [\n `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,\n microfrontendConfig.getZone(zone).production.host,\n ];\n }\n\n static validateOverrideDomain(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n domain: string,\n ): boolean {\n return new RegExp(\n `^${Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(\n '|',\n )}$`,\n ).test(domain);\n }\n\n serialize(): OverridesConfig {\n return this.config;\n }\n}\n","import type { HostConfig } from '../schema';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: HostConfig['host'];\n port: number;\n serialized: HostConfig;\n\n constructor({ protocol, host, port }: HostConfig) {\n this.protocol = protocol || 'https';\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.serialized = {\n protocol,\n host,\n ...(port ? { port } : undefined),\n };\n }\n\n isLocal(): boolean {\n return this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: { protocol: HostConfig['protocol']; port?: HostConfig['port'] }): number {\n if (!port) {\n if (protocol === 'http') {\n return 80;\n }\n return 443;\n }\n\n return port;\n }\n\n isDefaultPort(): boolean {\n return this.port === Host.getPort({ protocol: this.protocol });\n }\n\n toString(opts: HostDisplayOptions = {}): string {\n const url = this.toUrl(opts);\n // strip the trailing slash\n return url.toString().replace(/\\/$/, '');\n }\n\n toUrl(opts: HostDisplayOptions = {}): URL {\n const { includeDefaultPort } = opts;\n const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? '' : `:${this.port}`}`;\n\n return new URL(url);\n }\n\n serialize(): HostConfig {\n return this.serialized;\n }\n}\n","import type { ApplicationConfig, Routing, Vercel } from '../schema';\nimport type { ApplicationOverrideConfig } from '../overrides';\nimport { MicrofrontendError } from '../errors';\nimport { Host } from './host';\n\nexport class Application {\n default: boolean;\n routing?: Routing;\n name: string;\n development: {\n local: Host;\n fallback?: Host;\n };\n production: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: { app: ApplicationConfig; overrides?: ApplicationOverrideConfig },\n ) {\n // validate\n Application.validate(name, app);\n\n this.name = name;\n this.default = app.default;\n this.routing = app.routing;\n this.development = {\n local: new Host(app.development.local),\n fallback: app.development.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = new Host(app.production);\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n static validate(name: string, app: ApplicationConfig): void {\n // validate assetPrefix\n if (\n app.routing?.assetPrefix?.startsWith('/') ||\n app.routing?.assetPrefix?.endsWith('/')\n ) {\n throw new MicrofrontendError(\n `Invalid assetPrefix for application \"${name}\". Must not start or end with a slash.`,\n { type: 'zone', subtype: 'invalid_asset_prefix' },\n );\n }\n\n // validate routes\n for (const group of app.routing?.matches ?? []) {\n for (const p of group.paths) {\n if (p === '/') {\n continue;\n }\n if (p.endsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must not end with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n\n if (!p.startsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must start with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n }\n }\n }\n\n serialize(): ApplicationConfig {\n if (this.routing === undefined || this.default) {\n return {\n default: true,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n\n return {\n default: false,\n routing: this.routing,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n}\n","import type { ApplicationConfig, Config, Options } from '../schema';\nimport { MicrofrontendError } from '../errors';\nimport type { OverridesConfig } from '../overrides';\nimport { Overrides } from '../overrides/config';\nimport { Application } from './application';\n\nconst SUPPORTED_VERSIONS = ['1'];\nconst DEFAULT_LOCAL_PROXY_PORT = 3024;\n\n/**\n * A class to manage the microfrontends configuration.\n *\n * This class should not be used directly. Instead, use the `MicrofrontendConfig` or `MicrofrontendConfigEdgeRuntime` classes.\n */\nexport class MicrofrontendConfigCommon {\n config: Config;\n name?: string;\n zones: Record<string, Application> = {};\n version: string;\n overrides?: Overrides;\n options?: Options;\n $schema: string | undefined;\n\n constructor({\n config,\n overrides,\n }: { config: Config; overrides?: OverridesConfig }) {\n if (!SUPPORTED_VERSIONS.includes(config.version)) {\n throw new MicrofrontendError(\n `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n this.overrides =\n overrides && !disableOverrides ? new Overrides(overrides) : undefined;\n\n // create zones\n for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {\n this.zones[zoneName] = new Application(zoneName, {\n app: zoneConfig,\n overrides: !disableOverrides\n ? this.overrides?.config.applications[zoneName]\n : undefined,\n });\n }\n\n this.config = config;\n this.name = config.name;\n this.version = config.version;\n this.options = config.options;\n this.$schema = config.$schema;\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n protected static getConfigFromEnv(): string {\n const config = process.env.MFE_CONFIG;\n if (!config) {\n throw new MicrofrontendError(`Missing \"MFE_CONFIG\" in environment.`, {\n type: 'config',\n subtype: 'not_found_in_env',\n });\n }\n return config;\n }\n\n static fromEnv(_: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigCommon | Promise<MicrofrontendConfigCommon> {\n throw new Error('Not implemented');\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getAllApplications(): Application[] {\n return Object.values(this.zones);\n }\n\n getZone(name: string): Application {\n const zone = this.zones[name];\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find microfrontends configuration for application \"${name}\"`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n getApplicationByProjectId(projectId: string): Application | undefined {\n return Object.values(this.zones).find(\n (zone) => zone.vercel?.projectId === projectId,\n );\n }\n\n getDefaultZone(): Application {\n const zone = Object.values(this.zones).find((z) => z.default);\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find default zone in microfrontends configuration`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n /**\n * Returns the configured port for the local proxy\n */\n getLocalProxyPort(): number {\n return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;\n }\n\n /**\n * Serializes the class back to the Schema type.\n *\n * NOTE: This is used when writing the config to disk and must always match the input Schema\n */\n toSchemaJson(): Config {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n $schema: this.$schema,\n name: this.name,\n version: this.version,\n options: this.options,\n applications,\n };\n }\n\n serialize(): { config: Config; overrides?: OverridesConfig } {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n config: {\n name: this.name,\n version: this.version,\n applications,\n options: this.options,\n $schema: this.$schema,\n },\n overrides: this.overrides?.serialize(),\n };\n }\n\n write(_: string): void {\n throw new MicrofrontendError(\n `Writing to file to disk requires using an instance of \"MicrofrontendConfig\".`,\n { type: 'config', subtype: 'unsupported_operation' },\n );\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { Application } from '../config/common/application';\n\nfunction debugDomains(zone: string, env: string, domain: string): void {\n if (process.env.MFE_DEBUG === 'true') {\n const indent = ' '.repeat(4);\n const header = 'domains (zone (env) -> domain)';\n const separator = '⎯'.repeat(header.length);\n const line = `${indent} 1. ${zone} (${env}) -> ${domain}`;\n\n // eslint-disable-next-line no-console\n console.log(`${indent}${header}\\n${indent}${separator}\\n${line}\\n`);\n }\n}\n\n/**\n * Returns the Vercel domain for the given application based on the current\n * environment (local, preview, production).\n */\nexport function getDomainForCurrentEnvironment(\n zone: Application,\n opts: { ignoreOverride?: boolean } = {},\n): string {\n if (!opts.ignoreOverride && zone.overrides?.environment) {\n return zone.overrides.environment.toString();\n }\n const zoneName = zone.name;\n if (!process.env.VERCEL_ENV || process.env.VERCEL_ENV === 'development') {\n // TODO(mknichel): Convert this back to the local development domain once\n // there is local development proxy support.\n const domain =\n process.env.NODE_ENV === 'test'\n ? zone.development.local.toString()\n : zone.production.toString();\n debugDomains(zoneName, 'development', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'production') {\n const domain = zone.production.toString();\n debugDomains(zoneName, 'production', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'preview') {\n const MFE_PREVIEW_DOMAINS = JSON.parse(\n process.env.MFE_PREVIEW_DOMAINS ?? '{}',\n ) as Record<string, string>;\n if (MFE_PREVIEW_DOMAINS[zoneName]) {\n debugDomains(zoneName, 'preview', MFE_PREVIEW_DOMAINS[zoneName]);\n return MFE_PREVIEW_DOMAINS[zoneName];\n }\n\n throw new Error(\n `Could not find preview domain for application \"${zoneName}\"`,\n );\n }\n // TODO(mknichel): Add support in this function for custom environments.\n // Custom Vercel environments may have an arbitrary string for `VERCEL_ENV`.\n debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());\n return zone.production.toString();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,oBAA6B;AAC7B,4BAA6B;;;ACF7B,0BAAsB;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAAM,SAAS;AAC3B,SAAK,UAAU,6BAAM;AACrB,UAAM,kBAAkB,MAAM,kBAAkB;AAAA,EAClD;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YAAqB;AACnB,WAAO,CAAC,KAAK,QAAQ;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,QACL,UACA,MAC4C;AAC5C,QAAI,6BAAM,UAAU;AAClB,YAAM,MAAM,mBAAmB,eAAe,UAAU,KAAK,QAAQ;AACrE,UAAI,KAAK;AACP,eAAO;AAAA,MACT;AAAA,IACF;AAEA,QACE,SAAS,QAAQ;AAAA,MACf;AAAA,IACF,GACA;AACA,aAAO,IAAI,mBAAmB,SAAS,SAAS;AAAA,QAC9C,MAAM;AAAA,QACN,SAAS;AAAA,QACT,QAAQ;AAAA,MACV,CAAC;AAAA,IACH;AAGA,WAAO,IAAI,mBAAmB,SAAS,OAAO;AAAA,EAChD;AAAA,EAEA,OAAO,eACL,UACA,UACmD;AACnD,QAAI,oBAAoB,SAAS,UAAU,UAAU;AACnD,UAAI,SAAS,SAAS,UAAU;AAC9B,eAAO,IAAI,mBAAmB,mBAAmB,aAAa;AAAA,UAC5D,MAAM;AAAA,UACN,SAAS;AAAA,UACT,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AACA,UAAI,SAAS,SAAS,UAAU;AAC9B,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f,KAAK;AAAA,cACL,IAAI,WAAW;AAAA,gBACb;AAAA,gBACA;AAAA,gBACA;AAAA,cACF,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAsB,4BACpB,SACA,YAC+B;AAC/B,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,cAAc,4BAA4B;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,aAAW,SAAS,aAAa;AAC/B,QACE,OAAO,MAAM,QAAQ,WACjB,aAAa,MAAM,MACnB,MAAM,IAAI,KAAK,QAAQ,GAC3B;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,OAAO;AACvC,UAAI,UAAU;AACZ,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -543,31 +543,6 @@ async function verifyPreviewDomain(req, rewriteDomain) {
543
543
  const vercelError = previewResponse.headers.get("x-vercel-error");
544
544
  return !(previewResponse.status === 404 && (vercelError === "DEPLOYMENT_NOT_FOUND" || vercelError === "NOT_FOUND"));
545
545
  }
546
- function microfrontendInternalRoutingHandler({
547
- config
548
- }) {
549
- return async (req) => {
550
- const payload = Object.fromEntries(
551
- await Promise.all(
552
- config.getAllApplications().map(async (application) => {
553
- let rewriteDomain = getDomainForCurrentEnvironment(application, {
554
- ignoreOverride: true
555
- });
556
- const isPreviewDomainAvailable = await verifyPreviewDomain(
557
- req,
558
- rewriteDomain
559
- );
560
- if (!isPreviewDomainAvailable) {
561
- rewriteDomain = application.production.toString();
562
- }
563
- const url = new URL(rewriteDomain);
564
- return [application.name, { routing: { host: url.host } }];
565
- })
566
- )
567
- );
568
- return NextResponse.json(payload);
569
- };
570
- }
571
546
  function getHandler({
572
547
  application,
573
548
  flagFn,
@@ -679,10 +654,6 @@ function getMicrofrontendsMiddleware({
679
654
  cookies: request.cookies.getAll()
680
655
  });
681
656
  const middlewares = [];
682
- middlewares.push({
683
- src: "/.well-known/vercel/microfrontend-routing",
684
- fn: microfrontendInternalRoutingHandler({ config })
685
- });
686
657
  for (const application of config.getAllApplications()) {
687
658
  if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
688
659
  continue;