@vercel/microfrontends 0.13.0 → 0.15.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 (120) hide show
  1. package/README.md +3 -3
  2. package/dist/bin/cli.cjs +403 -1627
  3. package/dist/config.cjs +460 -1004
  4. package/dist/config.cjs.map +1 -1
  5. package/dist/config.d.ts +4 -25
  6. package/dist/config.js +456 -983
  7. package/dist/config.js.map +1 -1
  8. package/dist/{index-83133f2d.d.ts → index-bf67a461.d.ts} +3 -10
  9. package/dist/{v2/microfrontends → microfrontends}/server.cjs +128 -194
  10. package/dist/microfrontends/server.cjs.map +1 -0
  11. package/dist/{v2/microfrontends → microfrontends}/server.d.ts +6 -5
  12. package/dist/{v2/microfrontends → microfrontends}/server.js +125 -191
  13. package/dist/microfrontends/server.js.map +1 -0
  14. package/dist/{v2/microfrontends.cjs → microfrontends.cjs} +21 -35
  15. package/dist/microfrontends.cjs.map +1 -0
  16. package/dist/{v2/microfrontends.d.ts → microfrontends.d.ts} +4 -3
  17. package/dist/{v2/microfrontends.js → microfrontends.js} +20 -34
  18. package/dist/microfrontends.js.map +1 -0
  19. package/dist/next/client.cjs +1 -1
  20. package/dist/next/client.cjs.map +1 -1
  21. package/dist/next/client.js +1 -1
  22. package/dist/next/client.js.map +1 -1
  23. package/dist/next/config.cjs +1323 -1024
  24. package/dist/next/config.cjs.map +1 -1
  25. package/dist/next/config.d.ts +1 -1
  26. package/dist/next/config.js +1327 -1028
  27. package/dist/next/config.js.map +1 -1
  28. package/dist/next/endpoints.cjs +77 -18
  29. package/dist/next/endpoints.cjs.map +1 -1
  30. package/dist/next/endpoints.d.ts +14 -3
  31. package/dist/next/endpoints.js +77 -18
  32. package/dist/next/endpoints.js.map +1 -1
  33. package/dist/next/middleware.cjs +745 -425
  34. package/dist/next/middleware.cjs.map +1 -1
  35. package/dist/next/middleware.d.ts +10 -5
  36. package/dist/next/middleware.js +745 -425
  37. package/dist/next/middleware.js.map +1 -1
  38. package/dist/next/testing.cjs +595 -1032
  39. package/dist/next/testing.cjs.map +1 -1
  40. package/dist/next/testing.d.ts +14 -12
  41. package/dist/next/testing.js +589 -1016
  42. package/dist/next/testing.js.map +1 -1
  43. package/dist/overrides.cjs +40 -108
  44. package/dist/overrides.cjs.map +1 -1
  45. package/dist/overrides.d.ts +24 -2
  46. package/dist/overrides.js +36 -106
  47. package/dist/overrides.js.map +1 -1
  48. package/dist/routing.cjs +19 -0
  49. package/dist/routing.cjs.map +1 -0
  50. package/dist/routing.d.ts +26 -0
  51. package/dist/routing.js +1 -0
  52. package/dist/{v2/schema.cjs → schema.cjs} +1 -1
  53. package/dist/schema.cjs.map +1 -0
  54. package/dist/schema.d.ts +1 -0
  55. package/dist/schema.js.map +1 -0
  56. package/dist/{types-a995174e.d.ts → types-a29d224a.d.ts} +1 -7
  57. package/dist/{types-15b7f215.d.ts → types-cfe3308b.d.ts} +1 -1
  58. package/dist/types-fc30696d.d.ts +11 -0
  59. package/dist/utils/mfe-port.cjs +254 -1362
  60. package/dist/utils/mfe-port.cjs.map +1 -1
  61. package/dist/utils/mfe-port.js +250 -1358
  62. package/dist/utils/mfe-port.js.map +1 -1
  63. package/dist/validation.cjs +31 -365
  64. package/dist/validation.cjs.map +1 -1
  65. package/dist/validation.d.ts +3 -152
  66. package/dist/validation.js +30 -363
  67. package/dist/validation.js.map +1 -1
  68. package/package.json +32 -80
  69. package/schema/schema.json +174 -244
  70. package/dist/config/client.cjs +0 -54
  71. package/dist/config/client.cjs.map +0 -1
  72. package/dist/config/client.d.ts +0 -23
  73. package/dist/config/client.js +0 -28
  74. package/dist/config/client.js.map +0 -1
  75. package/dist/config/edge.cjs +0 -508
  76. package/dist/config/edge.cjs.map +0 -1
  77. package/dist/config/edge.d.ts +0 -20
  78. package/dist/config/edge.js +0 -481
  79. package/dist/config/edge.js.map +0 -1
  80. package/dist/microfrontend-config-983a5139.d.ts +0 -154
  81. package/dist/schema-2922d49e.d.ts +0 -182
  82. package/dist/v2/config.cjs +0 -723
  83. package/dist/v2/config.cjs.map +0 -1
  84. package/dist/v2/config.d.ts +0 -3
  85. package/dist/v2/config.js +0 -698
  86. package/dist/v2/config.js.map +0 -1
  87. package/dist/v2/microfrontends/server.cjs.map +0 -1
  88. package/dist/v2/microfrontends/server.js.map +0 -1
  89. package/dist/v2/microfrontends.cjs.map +0 -1
  90. package/dist/v2/microfrontends.js.map +0 -1
  91. package/dist/v2/next/client.cjs +0 -3
  92. package/dist/v2/next/client.cjs.map +0 -1
  93. package/dist/v2/next/client.d.ts +0 -45
  94. package/dist/v2/next/client.js +0 -3
  95. package/dist/v2/next/client.js.map +0 -1
  96. package/dist/v2/next/config.cjs +0 -2132
  97. package/dist/v2/next/config.cjs.map +0 -1
  98. package/dist/v2/next/config.d.ts +0 -22
  99. package/dist/v2/next/config.js +0 -2097
  100. package/dist/v2/next/config.js.map +0 -1
  101. package/dist/v2/next/endpoints.cjs +0 -141
  102. package/dist/v2/next/endpoints.cjs.map +0 -1
  103. package/dist/v2/next/endpoints.d.ts +0 -15
  104. package/dist/v2/next/endpoints.js +0 -116
  105. package/dist/v2/next/endpoints.js.map +0 -1
  106. package/dist/v2/next/middleware.cjs +0 -1143
  107. package/dist/v2/next/middleware.cjs.map +0 -1
  108. package/dist/v2/next/middleware.d.ts +0 -29
  109. package/dist/v2/next/middleware.js +0 -1115
  110. package/dist/v2/next/middleware.js.map +0 -1
  111. package/dist/v2/overrides.cjs +0 -75
  112. package/dist/v2/overrides.cjs.map +0 -1
  113. package/dist/v2/overrides.d.ts +0 -24
  114. package/dist/v2/overrides.js +0 -45
  115. package/dist/v2/overrides.js.map +0 -1
  116. package/dist/v2/schema.cjs.map +0 -1
  117. package/dist/v2/schema.d.ts +0 -1
  118. package/schema/schema-v2.json +0 -270
  119. /package/dist/{v2/schema.js.map → routing.js.map} +0 -0
  120. /package/dist/{v2/schema.js → schema.js} +0 -0
@@ -1,7 +1,7 @@
1
- // src/config-v2/microfrontends-config/isomorphic/index.ts
1
+ // src/config/microfrontends-config/isomorphic/index.ts
2
2
  import { parse } from "jsonc-parser";
3
3
 
4
- // src/config-v2/errors.ts
4
+ // src/config/errors.ts
5
5
  var MicrofrontendError = class extends Error {
6
6
  constructor(message, opts) {
7
7
  super(message);
@@ -93,7 +93,7 @@ var MicrofrontendError = class extends Error {
93
93
  }
94
94
  };
95
95
 
96
- // src/config-v2/microfrontends-config/utils/get-config-from-env.ts
96
+ // src/config/microfrontends-config/utils/get-config-from-env.ts
97
97
  function getConfigStringFromEnv() {
98
98
  const config = process.env.MFE_CONFIG;
99
99
  if (!config) {
@@ -105,17 +105,17 @@ function getConfigStringFromEnv() {
105
105
  return config;
106
106
  }
107
107
 
108
- // src/config-v2/schema/utils/is-main-config.ts
108
+ // src/config/schema/utils/is-main-config.ts
109
109
  function isMainConfig(c) {
110
110
  return !("partOf" in c);
111
111
  }
112
112
 
113
- // src/config-v2/schema/utils/is-default-app.ts
113
+ // src/config/schema/utils/is-default-app.ts
114
114
  function isDefaultApp(a) {
115
115
  return !("routing" in a);
116
116
  }
117
117
 
118
- // src/config-v2/microfrontends-config/client/index.ts
118
+ // src/config/microfrontends-config/client/index.ts
119
119
  import { pathToRegexp } from "path-to-regexp";
120
120
  var MicrofrontendConfigClient = class {
121
121
  constructor(config, opts) {
@@ -181,17 +181,17 @@ var MicrofrontendConfigClient = class {
181
181
  }
182
182
  };
183
183
 
184
- // src/config-v2/overrides/constants.ts
184
+ // src/config/overrides/constants.ts
185
185
  var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
186
186
  var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
187
187
 
188
- // src/config-v2/overrides/is-override-cookie.ts
188
+ // src/config/overrides/is-override-cookie.ts
189
189
  function isOverrideCookie(cookie) {
190
190
  var _a;
191
191
  return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
192
192
  }
193
193
 
194
- // src/config-v2/overrides/get-override-from-cookie.ts
194
+ // src/config/overrides/get-override-from-cookie.ts
195
195
  function getOverrideFromCookie(cookie) {
196
196
  if (!isOverrideCookie(cookie) || !cookie.value)
197
197
  return;
@@ -201,7 +201,7 @@ function getOverrideFromCookie(cookie) {
201
201
  };
202
202
  }
203
203
 
204
- // src/config-v2/overrides/parse-overrides.ts
204
+ // src/config/overrides/parse-overrides.ts
205
205
  function parseOverrides(cookies) {
206
206
  const overridesConfig = { applications: {} };
207
207
  cookies.forEach((cookie) => {
@@ -215,7 +215,7 @@ function parseOverrides(cookies) {
215
215
  return overridesConfig;
216
216
  }
217
217
 
218
- // src/config-v2/microfrontends-config/isomorphic/validation.ts
218
+ // src/config/microfrontends-config/isomorphic/validation.ts
219
219
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
220
220
  var SUPPORTED_VERSIONS = ["2"];
221
221
  var validateConfigVersion = (version) => {
@@ -343,21 +343,8 @@ var validateConfigDefaultApplication = (applicationConfigsById) => {
343
343
  );
344
344
  }
345
345
  };
346
- var validateConfigOptions = (options) => {
347
- var _a;
348
- if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
349
- if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
350
- options.vercel.previewDeploymentSuffix
351
- )) {
352
- throw new MicrofrontendError(
353
- `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
354
- { type: "config", subtype: "invalid_preview_deployment_suffix" }
355
- );
356
- }
357
- }
358
- };
359
346
 
360
- // src/config-v2/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
347
+ // src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
361
348
  var PREFIX = "vc-ap";
362
349
  function generateAssetPrefixFromName({
363
350
  name
@@ -368,7 +355,7 @@ function generateAssetPrefixFromName({
368
355
  return `${PREFIX}-${name}`;
369
356
  }
370
357
 
371
- // src/config-v2/microfrontends-config/isomorphic/utils/generate-port.ts
358
+ // src/config/microfrontends-config/isomorphic/utils/generate-port.ts
372
359
  function generatePortFromName({
373
360
  name,
374
361
  minPort = 3e3,
@@ -388,7 +375,7 @@ function generatePortFromName({
388
375
  return port;
389
376
  }
390
377
 
391
- // src/config-v2/microfrontends-config/isomorphic/host.ts
378
+ // src/config/microfrontends-config/isomorphic/host.ts
392
379
  var Host = class {
393
380
  constructor(hostConfig, options) {
394
381
  const { protocol = "https", host, port } = hostConfig;
@@ -437,7 +424,7 @@ var LocalHost = class extends Host {
437
424
  }
438
425
  };
439
426
 
440
- // src/config-v2/microfrontends-config/isomorphic/application.ts
427
+ // src/config/microfrontends-config/isomorphic/application.ts
441
428
  var Application = class {
442
429
  constructor(name, {
443
430
  app,
@@ -507,10 +494,10 @@ var ChildApplication = class extends Application {
507
494
  }
508
495
  };
509
496
 
510
- // src/config-v2/microfrontends-config/isomorphic/constants.ts
497
+ // src/config/microfrontends-config/isomorphic/constants.ts
511
498
  var DEFAULT_LOCAL_PROXY_PORT = 3024;
512
499
 
513
- // src/config-v2/microfrontends-config/isomorphic/index.ts
500
+ // src/config/microfrontends-config/isomorphic/index.ts
514
501
  var MicrofrontendConfigIsomorphic = class {
515
502
  constructor({
516
503
  config,
@@ -574,7 +561,6 @@ var MicrofrontendConfigIsomorphic = class {
574
561
  validateConfigPaths(c.applications);
575
562
  validateConfigDefaultApplication(c.applications);
576
563
  }
577
- validateConfigOptions(c.options);
578
564
  return c;
579
565
  }
580
566
  static fromEnv({
@@ -693,7 +679,7 @@ var MicrofrontendConfigIsomorphic = class {
693
679
  }
694
680
  };
695
681
 
696
- // src/config-v2/microfrontends-config/isomorphic/child.ts
682
+ // src/config/microfrontends-config/isomorphic/child.ts
697
683
  var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
698
684
  constructor({
699
685
  config,
@@ -706,7 +692,7 @@ var MicrofrontendChildConfig = class extends MicrofrontendConfigIsomorphic {
706
692
  }
707
693
  };
708
694
 
709
- // src/config-v2/microfrontends-config/isomorphic/main.ts
695
+ // src/config/microfrontends-config/isomorphic/main.ts
710
696
  var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
711
697
  constructor({
712
698
  config,
@@ -745,7 +731,7 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
745
731
  }
746
732
  };
747
733
 
748
- // src/config-v2/microfrontends/isomorphic/index.ts
734
+ // src/config/microfrontends/isomorphic/index.ts
749
735
  var Microfrontends = class {
750
736
  constructor({
751
737
  config,
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/config/microfrontends-config/isomorphic/index.ts","../src/config/errors.ts","../src/config/microfrontends-config/utils/get-config-from-env.ts","../src/config/schema/utils/is-main-config.ts","../src/config/schema/utils/is-default-app.ts","../src/config/microfrontends-config/client/index.ts","../src/config/overrides/constants.ts","../src/config/overrides/is-override-cookie.ts","../src/config/overrides/get-override-from-cookie.ts","../src/config/overrides/parse-overrides.ts","../src/config/microfrontends-config/isomorphic/validation.ts","../src/config/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts","../src/config/microfrontends-config/isomorphic/utils/generate-port.ts","../src/config/microfrontends-config/isomorphic/host.ts","../src/config/microfrontends-config/isomorphic/application.ts","../src/config/microfrontends-config/isomorphic/constants.ts","../src/config/microfrontends-config/isomorphic/child.ts","../src/config/microfrontends-config/isomorphic/main.ts","../src/config/microfrontends/isomorphic/index.ts"],"sourcesContent":["import { parse } from 'jsonc-parser';\nimport { getConfigStringFromEnv } from '../utils/get-config-from-env';\nimport { isMainConfig } from '../../schema/utils/is-main-config';\nimport { isDefaultApp } from '../../schema/utils/is-default-app';\nimport type { Config } from '../../schema/types';\nimport type { ClientConfig } from '../client/types';\nimport { MicrofrontendError } from '../../errors';\nimport { MicrofrontendConfigClient } from '../client';\nimport { type OverridesConfig, parseOverrides } from '../../overrides';\nimport { DefaultApplication, ChildApplication } from './application';\nimport { DEFAULT_LOCAL_PROXY_PORT } from './constants';\nimport {\n validateConfigDefaultApplication,\n validateConfigPaths,\n validateConfigVersion,\n} from './validation';\n\nexport interface ConfigMeta {\n /**\n * The application name that the configuration is being loaded from.\n */\n fromApp: string;\n}\n\n/**\n * A class to manage the microfrontends configuration.\n */\nexport class MicrofrontendConfigIsomorphic {\n config: Config;\n isMainConfig: boolean;\n partOf?: string;\n defaultApplication?: DefaultApplication;\n childApplications: Record<string, ChildApplication> = {};\n overrides?: OverridesConfig;\n options?: Config['options'];\n\n private readonly serialized: {\n config: Config;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n };\n\n constructor({\n config,\n overrides,\n meta,\n }: { config: Config; overrides?: OverridesConfig; meta: ConfigMeta }) {\n // run validation on init\n MicrofrontendConfigIsomorphic.validate(config);\n\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n this.overrides = overrides && !disableOverrides ? overrides : undefined;\n this.isMainConfig = isMainConfig(config);\n\n if (isMainConfig(config)) {\n // create applications\n for (const [appId, appConfig] of Object.entries(config.applications)) {\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[appId]\n : undefined;\n\n if (isDefaultApp(appConfig)) {\n this.defaultApplication = new DefaultApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n } else {\n this.childApplications[appId] = new ChildApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n }\n }\n } else {\n this.partOf = config.partOf;\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[meta.fromApp]\n : undefined;\n this.childApplications[meta.fromApp] = new ChildApplication(\n meta.fromApp,\n {\n // we don't know routing because we're not in the main config\n app: { routing: [] },\n overrides: appOverrides,\n },\n );\n }\n\n // the main configuration file should ALWAYS have the default\n if (isMainConfig(config) && !this.defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n this.config = config;\n this.options = config.options;\n this.serialized = {\n config,\n overrides,\n meta,\n };\n }\n\n static validate(config: string | Config): Config {\n // let this throw if it's not valid JSON\n const c = typeof config === 'string' ? (parse(config) as Config) : config;\n\n if (isMainConfig(c)) {\n // run validation\n validateConfigVersion(c.version);\n validateConfigPaths(c.applications);\n validateConfigDefaultApplication(c.applications);\n }\n\n return c;\n }\n\n static fromEnv({\n meta,\n cookies,\n }: {\n meta: ConfigMeta;\n cookies?: { name: string; value: string }[];\n }): MicrofrontendConfigIsomorphic {\n return new MicrofrontendConfigIsomorphic({\n config: parse(getConfigStringFromEnv()) as Config,\n overrides: parseOverrides(cookies ?? []),\n meta,\n });\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getApplicationsByType(): {\n defaultApplication?: DefaultApplication;\n applications: ChildApplication[];\n } {\n return {\n defaultApplication: this.defaultApplication,\n applications: Object.values(this.childApplications),\n };\n }\n\n getChildApplications(): ChildApplication[] {\n return Object.values(this.childApplications);\n }\n\n getAllApplications(): (DefaultApplication | ChildApplication)[] {\n return [\n this.defaultApplication,\n ...Object.values(this.childApplications),\n ].filter(Boolean) as (DefaultApplication | ChildApplication)[];\n }\n\n getApplication(name: string): DefaultApplication | ChildApplication {\n // check the default\n if (this.defaultApplication?.name === name) {\n return this.defaultApplication;\n }\n const app = this.childApplications[name];\n if (!app) {\n throw new MicrofrontendError(\n `Could not find microfrontends configuration for application \"${name}\"`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n return app;\n }\n\n getApplicationByProjectId(\n projectId: string,\n ): DefaultApplication | ChildApplication | undefined {\n // check the default\n if (this.defaultApplication?.vercel?.projectId === projectId) {\n return this.defaultApplication;\n }\n\n return Object.values(this.childApplications).find(\n (app) => app.vercel?.projectId === projectId,\n );\n }\n\n /**\n * Returns the default application. This can throw if the default application\n * is undefined ( )\n */\n getDefaultApplication(): DefaultApplication {\n if (!this.defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n\n return this.defaultApplication;\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 return this.serialized.config;\n }\n\n toClientConfig(): MicrofrontendConfigClient {\n const applications: ClientConfig['applications'] = Object.fromEntries(\n Object.entries(this.childApplications).map(([name, application]) => [\n name,\n {\n default: false,\n routing: application.routing,\n },\n ]),\n );\n\n // add the default application\n if (this.defaultApplication) {\n applications[this.defaultApplication.name] = {\n default: true,\n };\n }\n\n return new MicrofrontendConfigClient({\n applications,\n });\n }\n\n serialize(): {\n config: Config;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n } {\n return this.serialized;\n }\n}\n","export type MicrofrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'application'\n | 'unknown';\n\nexport type MicrofrontendErrorSubtype =\n | 'not_found'\n | 'inference_failed'\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 application:\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 | 'inference_failed'\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","import { MicrofrontendError } from '../../errors';\n\n/**\n * Utility to fetch the microfrontend configuration string from the environment.\n */\nexport function getConfigStringFromEnv(): 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","import type { Config, MainConfig } from '../types';\n\nexport function isMainConfig(c: Config): c is MainConfig {\n return !('partOf' in c);\n}\n","import type { Application, DefaultApplication } from '../types';\n\nexport function isDefaultApp(a: Application): a is DefaultApplication {\n return !('routing' in a);\n}\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","// cookie name needs to match proxy\n// https://github.com/vercel/proxy/blob/fb00d723136ad539a194e4a851dd272010527c35/lib/routing/micro_frontends_overrides.lua#L7\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\nexport const OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n","import { OVERRIDES_COOKIE_PREFIX } from './constants';\n\nexport function isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n}\n","import { isOverrideCookie } from './is-override-cookie';\nimport { OVERRIDES_ENV_COOKIE_PREFIX } from './constants';\n\nexport function getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n}): { application: string; host: string } | undefined {\n if (!isOverrideCookie(cookie) || !cookie.value) return;\n return {\n application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ''),\n host: cookie.value,\n };\n}\n","import type { OverridesConfig } from './types';\nimport { getOverrideFromCookie } from './get-override-from-cookie';\n\nexport function parseOverrides(\n cookies: { name: string; value?: string | null }[],\n): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.application] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n}\n","import { pathToRegexp, parse as parsePathRegexp } from 'path-to-regexp';\nimport type {\n ApplicationId,\n PathGroup,\n ApplicationRouting,\n ChildApplication as ChildApplicationConfig,\n} from '../../schema/types';\nimport { MicrofrontendError } from '../../errors';\nimport { isDefaultApp } from '../../schema/utils/is-default-app';\n\nconst SUPPORTED_VERSIONS = ['2'];\n\nexport const validateConfigVersion = (version: string): void => {\n if (!SUPPORTED_VERSIONS.includes(version)) {\n throw new MicrofrontendError(\n `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n};\n\n/**\n * Validate all paths in a configuration - ensures paths do not overlap\n */\nexport const validateConfigPaths = (\n applicationConfigsById?: ApplicationRouting,\n): void => {\n if (!applicationConfigsById) {\n return;\n }\n\n const pathsByApplicationId = new Map<\n PathGroup['paths'][number],\n {\n applications: ApplicationId[];\n matcher: RegExp;\n applicationId?: ApplicationId;\n }\n >();\n const errors: string[] = [];\n\n for (const [id, app] of Object.entries(applicationConfigsById)) {\n if (isDefaultApp(app)) {\n // default applications do not have routing\n continue;\n }\n\n for (const pathMatch of app.routing) {\n for (const path of pathMatch.paths) {\n const tokens = parsePathRegexp(path);\n for (const token of tokens.slice(0, -1)) {\n if (typeof token !== 'string') {\n errors.push(\n `Path ${path} may only have a :wildcard in the last path component`,\n );\n }\n }\n\n const existing = pathsByApplicationId.get(path);\n if (existing) {\n existing.applications.push(id);\n } else {\n pathsByApplicationId.set(path, {\n applications: [id],\n matcher: pathToRegexp(path),\n applicationId: id,\n });\n }\n }\n }\n }\n const entries = Array.from(pathsByApplicationId.entries());\n\n entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {\n if (ids.length > 1) {\n errors.push(\n `Duplicate path \"${path}\" for applications \"${ids.join(', ')}\"`,\n );\n }\n\n entries.forEach(\n ([\n matchPath,\n { applications: matchIds, applicationId: matchApplicationId },\n ]) => {\n if (path === matchPath) {\n // we're comparing to ourselves, so skip\n return;\n }\n\n if (applicationId === matchApplicationId) {\n // we're comparing to paths within our own application, which are allowed to overlap, so skip\n return;\n }\n\n if (matcher.test(matchPath)) {\n const source = `\"${path}\" of application${ids.length > 0 ? 's' : ''} ${ids.join(', ')}`;\n const destination = `\"${matchPath}\" of application${matchIds.length > 0 ? 's' : ''} ${matchIds.join(', ')}`;\n\n errors.push(\n `Overlapping path detected between ${source} and ${destination}`,\n );\n }\n },\n );\n });\n\n if (errors.length) {\n throw new MicrofrontendError(`Invalid paths: ${errors.join(', ')}`, {\n type: 'config',\n subtype: 'conflicting_paths',\n });\n }\n};\n\n/**\n * Validate all paths in an application - ensures paths are the correct format\n */\nexport const validateAppPaths = (\n name: string,\n app: ChildApplicationConfig,\n): void => {\n // validate routes\n for (const group of app.routing) {\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: 'application', 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: 'application', subtype: 'invalid_path' },\n );\n }\n }\n }\n};\n\n/**\n * Make sure only one `Application` defines routing\n * */\nexport const validateConfigDefaultApplication = (\n applicationConfigsById?: ApplicationRouting,\n): void => {\n if (!applicationConfigsById) {\n return;\n }\n\n // find all applications that have routing\n const applicationsWithRouting = Object.entries(applicationConfigsById).filter(\n ([, app]) => !isDefaultApp(app),\n );\n // get all the application names\n const applicationsWithRoutingNames = applicationsWithRouting.map(\n ([key]) => key,\n );\n const numApplications = Object.keys(applicationConfigsById).length;\n const numApplicationsWithRouting = applicationsWithRoutingNames.length;\n const numApplicationsWithoutRouting =\n numApplications - numApplicationsWithRouting;\n\n if (numApplicationsWithoutRouting === 0) {\n throw new MicrofrontendError(\n `No default application found. At least one application needs to be the default by omitting routing.`,\n { type: 'config', subtype: 'no_default_application' },\n );\n }\n\n if (numApplicationsWithoutRouting > 1) {\n throw new MicrofrontendError(\n `Only one application can omit \"routing\". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,\n { type: 'config', subtype: 'multiple_default_applications' },\n );\n }\n};\n","const PREFIX = 'vc-ap';\n\nexport function generateAssetPrefixFromName({\n name,\n}: {\n name: string;\n}): string {\n if (!name) {\n throw new Error('Name is required to generate an asset prefix');\n }\n\n return `${PREFIX}-${name}`;\n}\n","export function generatePortFromName({\n name,\n minPort = 3000,\n maxPort = 8000,\n}: {\n name: string;\n minPort?: number;\n maxPort?: number;\n}): number {\n if (!name) {\n throw new Error('Name is required to generate a port');\n }\n\n // hash the name\n let hash = 0;\n for (let i = 0; i < name.length; i++) {\n // eslint-disable-next-line no-bitwise\n hash = (hash << 5) - hash + name.charCodeAt(i);\n // Convert to 32-bit\n // eslint-disable-next-line no-bitwise\n hash |= 0;\n }\n hash = Math.abs(hash);\n\n // Map the hash to the port range\n const range = maxPort - minPort;\n const port = minPort + (hash % range);\n\n return port;\n}\n","import type {\n HostConfig as RemoteHostConfigSchema,\n LocalHostConfig as LocalHostConfigSchema,\n} from '../../schema/types';\nimport { generatePortFromName } from './utils/generate-port';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\ninterface HostOptions {\n isLocal?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: string;\n port: number;\n local: boolean | undefined;\n\n constructor(hostConfig: RemoteHostConfigSchema, options?: HostOptions) {\n const { protocol = 'https', host, port } = hostConfig;\n this.protocol = protocol;\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.local = options?.isLocal;\n }\n\n isLocal(): boolean {\n return this.local || this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: {\n protocol: RemoteHostConfigSchema['protocol'];\n port?: RemoteHostConfigSchema['port'];\n }): 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\n/**\n * A Host subclass with defaults for locally running applications\n */\nexport class LocalHost extends Host {\n constructor({\n appName,\n ...hostConfig\n }: LocalHostConfigSchema & { appName: string }) {\n // set defaults for local\n const host = hostConfig.host ?? 'localhost';\n const port = hostConfig.port ?? generatePortFromName({ name: appName });\n const protocol = hostConfig.protocol ?? 'http';\n\n super({ protocol, host, port });\n }\n}\n","import type {\n Application as ApplicationConfig,\n DefaultApplication as DefaultApplicationConfig,\n ChildApplication as ChildApplicationConfig,\n PathGroup,\n Vercel,\n} from '../../schema/types';\nimport type { ApplicationOverrideConfig } from '../../overrides';\nimport { validateAppPaths } from './validation';\nimport { generateAssetPrefixFromName } from './utils/generate-asset-prefix';\nimport { Host, LocalHost } from './host';\n\nexport class Application {\n readonly default: boolean;\n name: string;\n development: {\n local: LocalHost;\n fallback?: Host;\n };\n production?: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n readonly serialized: ApplicationConfig;\n\n constructor(\n name: string,\n {\n app,\n overrides,\n isDefault,\n }: {\n app: ApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n isDefault?: boolean;\n },\n ) {\n this.name = name;\n this.development = {\n local: new LocalHost({\n appName: name,\n ...app.development?.local,\n }),\n fallback: app.development?.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = app.production ? new Host(app.production) : undefined;\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n this.default = isDefault ?? false;\n this.serialized = app;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n getAssetPrefix(): string {\n return generateAssetPrefixFromName({ name: this.name });\n }\n\n serialize(): ApplicationConfig {\n return this.serialized;\n }\n}\n\nexport class DefaultApplication extends Application {\n readonly default = true;\n production: Host;\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: {\n app: DefaultApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n },\n ) {\n super(name, {\n app,\n overrides,\n isDefault: true,\n });\n\n this.production = new Host(app.production);\n }\n\n getAssetPrefix(): string {\n return '';\n }\n}\n\nexport class ChildApplication extends Application {\n readonly default = false;\n routing: PathGroup[];\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: {\n app: ChildApplicationConfig;\n overrides?: ApplicationOverrideConfig;\n },\n ) {\n // validate\n ChildApplication.validate(name, app);\n\n super(name, {\n app,\n overrides,\n isDefault: false,\n });\n\n this.routing = app.routing;\n }\n\n static validate(name: string, app: ChildApplicationConfig): void {\n // validate routes\n validateAppPaths(name, app);\n }\n}\n","export const DEFAULT_LOCAL_PROXY_PORT = 3024;\n","import type { ChildConfig } from '../../schema/types';\nimport type { OverridesConfig } from '../../overrides';\nimport { type ConfigMeta, MicrofrontendConfigIsomorphic } from '.';\n\nexport class MicrofrontendChildConfig extends MicrofrontendConfigIsomorphic {\n isMainConfig = false;\n partOf?: string;\n\n constructor({\n config,\n overrides,\n meta,\n }: {\n config: ChildConfig;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n }) {\n super({ config, overrides, meta });\n this.partOf = config.partOf;\n }\n}\n","import { isDefaultApp } from '../../schema/utils/is-default-app';\nimport type { MainConfig } from '../../schema/types';\nimport { MicrofrontendError } from '../../errors';\nimport type { OverridesConfig } from '../../overrides';\nimport { DefaultApplication, ChildApplication } from './application';\nimport { type ConfigMeta, MicrofrontendConfigIsomorphic } from '.';\n\nexport class MicrofrontendMainConfig extends MicrofrontendConfigIsomorphic {\n isMainConfig = true;\n defaultApplication: DefaultApplication;\n\n constructor({\n config,\n overrides,\n meta,\n }: {\n config: MainConfig;\n overrides?: OverridesConfig;\n meta: ConfigMeta;\n }) {\n super({ config, overrides, meta });\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n let defaultApplication: DefaultApplication | undefined;\n for (const [appId, appConfig] of Object.entries(config.applications)) {\n const appOverrides = !disableOverrides\n ? this.overrides?.applications[appId]\n : undefined;\n\n if (isDefaultApp(appConfig)) {\n defaultApplication = new DefaultApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n } else {\n this.childApplications[appId] = new ChildApplication(appId, {\n app: appConfig,\n overrides: appOverrides,\n });\n }\n }\n\n // validate that this.defaultApplication is defined\n if (!defaultApplication) {\n throw new MicrofrontendError(\n `Could not find default application in microfrontends configuration`,\n {\n type: 'application',\n subtype: 'not_found',\n },\n );\n }\n this.defaultApplication = defaultApplication;\n }\n}\n","import {\n type ConfigMeta,\n MicrofrontendConfigIsomorphic,\n} from '../../microfrontends-config/isomorphic';\nimport { MicrofrontendChildConfig } from '../../microfrontends-config/isomorphic/child';\nimport { MicrofrontendMainConfig } from '../../microfrontends-config/isomorphic/main';\nimport type { MicrofrontendsConfig } from '../types';\nimport type { Config } from '../../schema/types';\nimport type { OverridesConfig } from '../../overrides';\nimport { isMainConfig } from '../../schema/utils/is-main-config';\n\nexport class Microfrontends {\n config: MicrofrontendsConfig;\n\n constructor({\n config,\n overrides,\n meta,\n }: { config: Config; overrides?: OverridesConfig; meta: ConfigMeta }) {\n if (isMainConfig(config)) {\n this.config = new MicrofrontendMainConfig({ config, overrides, meta });\n } else {\n this.config = new MicrofrontendChildConfig({ config, overrides, meta });\n }\n }\n\n isChildConfig(): boolean {\n return this.config instanceof MicrofrontendChildConfig;\n }\n\n static fromEnv({\n cookies,\n meta,\n }: {\n cookies?: { name: string; value: string }[];\n meta: ConfigMeta;\n }): Microfrontends {\n const config = MicrofrontendConfigIsomorphic.fromEnv({\n cookies,\n meta,\n });\n return new Microfrontends(config.serialize());\n }\n}\n"],"mappings":";AAAA,SAAS,aAAa;;;AC2Ef,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,G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,GAAsE;AACpE,QAAI,aAAa,MAAM,GAAG;AACxB,WAAK,SAAS,IAAI,wBAAwB,EAAE,QAAQ,WAAW,KAAK,CAAC;AAAA,IACvE,OAAO;AACL,WAAK,SAAS,IAAI,yBAAyB,EAAE,QAAQ,WAAW,KAAK,CAAC;AAAA,IACxE;AAAA,EACF;AAAA,EAEA,gBAAyB;AACvB,WAAO,KAAK,kBAAkB;AAAA,EAChC;AAAA,EAEA,OAAO,QAAQ;AAAA,IACb;AAAA,IACA;AAAA,EACF,GAGmB;AACjB,UAAM,SAAS,8BAA8B,QAAQ;AAAA,MACnD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO,IAAI,eAAe,OAAO,UAAU,CAAC;AAAA,EAC9C;AACF;","names":["pathToRegexp","pathToRegexp","_a"]}
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- "use strict";var Z=Object.create;var C=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0})},b=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of M(t))!J.call(e,o)&&o!==n&&C(e,o,{get:()=>t[o],enumerable:!(s=I(t,o))||s.enumerable});return e};var k=(e,t,n)=>(n=e!=null?Z(D(e)):{},b(t||!e||!e.__esModule?C(n,"default",{value:e,enumerable:!0}):n,e)),W=e=>b(C({},"__esModule",{value:!0}),e);var q={};z(q,{Link:()=>H,PrefetchCrossZoneLinks:()=>j,PrefetchCrossZoneLinksContext:()=>g,PrefetchCrossZoneLinksProvider:()=>B,useZoneForHref:()=>T});module.exports=W(q);var P=require("react"),F=k(require("next/link"),1);var f=require("react"),u=require("react/jsx-runtime"),g=(0,f.createContext)({prefetchHref:()=>{}});function B({children:e}){let[t,n]=(0,f.useState)(new Set),[s,o]=(0,f.useState)(!1);(0,f.useEffect)(()=>{o(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let i=(0,f.useCallback)(r=>{t.has(r)||n(new Set(t).add(r))},[t]),a=(0,f.useMemo)(()=>({prefetchHref:i}),[i]);return s?(0,u.jsxs)(g.Provider,{value:a,children:[e,[...t].map(r=>(0,u.jsx)("link",{as:"fetch",href:r,rel:"preload"},r))]}):(0,u.jsx)(u.Fragment,{children:e})}var m=require("react"),O=k(require("next/script"),1);var p=require("react");function d(){let e=process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;if(!e)throw new Error("Could not find client micro-frontends config in the environment");return JSON.parse(e)}var y=null;async function V(){try{let e=await fetch("/.well-known/vercel/micro-frontends/client-config");return e.status!==200?null:(await e.json()).config}catch{return null}}function $(e,t){return JSON.stringify(e)===JSON.stringify(t)}function U(e){for(let t of Object.values(e.applications))t.routing&&(t.routing.matches=t.routing.matches.filter(n=>{var s;return!((s=n.options)!=null&&s.flag)}));return e}function E({removeFlaggedPathsFromDefault:e}={}){let[t,n]=(0,p.useState)(e?U(d()):d()),[s,o]=(0,p.useState)(!0);return(0,p.useEffect)(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){o(!1);return}let i=d();if(!Object.values(i.applications).some(r=>{var l;return(l=r.routing)==null?void 0:l.matches.some(h=>{var x;return(x=h.options)==null?void 0:x.flag})})){o(!1);return}y||(y=V()),y.then(r=>{r&&n(l=>$(l,r)?l:r)}).finally(()=>{o(!1)})},[t.applications]),{clientConfig:t,isLoading:s}}var S=require("react/jsx-runtime"),L="data-prefetch",c={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${L}]`},N={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}}]},X={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}},{selector_matches:c.prefetch}]};function R(e){if(!e)return!0;if("checkVisibility"in e)return e.checkVisibility({opacityProperty:!0});let t=e,n=window.getComputedStyle(t);return n.display==="none"||n.visibility==="hidden"||n.opacity==="0"?!1:R(t.parentElement)}function j(){let{isLoading:e}=E(),[t,n]=(0,m.useState)([]);return(0,m.useEffect)(()=>{if(e)return;let o=new IntersectionObserver(i=>{i.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(L)&&R(a.target)&&a.target.setAttribute(L,"true")})},{root:null,rootMargin:"0px",threshold:.1});return t.forEach(i=>o.observe(i)),()=>{o.disconnect()}},[e,t]),(0,m.useEffect)(()=>{if(e)return;let o=new MutationObserver(i=>{i.some(r=>r.type==="childList"&&r.addedNodes.length>0||r.type==="attributes"&&r.attributeName==="href")&&n(Array.from(document.querySelectorAll(`a${c.anyZone}:not(${c.prefetch}):not(${c.sameZone}):not(${c.external})`)))});return o.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{o.disconnect()}},[e]),e?null:(0,S.jsx)(O.default,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:N},{eagerness:"immediate",where:X}],prerender:[{eagerness:"conservative",where:N}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}var A=require("path-to-regexp"),v=new WeakMap;function w(e,t){if(!t.startsWith("/"))throw new Error("Path must start with a /");let n=v.get(e)??{};if(n[t])return n[t];v.has(e)||v.set(e,n);let s=new URL(t,"https://example.com").pathname;for(let[i,a]of Object.entries(e.applications))if(a.routing){for(let r of a.routing.matches)for(let l of r.paths)if((0,A.pathToRegexp)(l).test(s))return n[t]=i,i}let o=Object.entries(e.applications).find(([,i])=>i.default);if(!o)throw new Error("No default application found. A default application must be configured in the micro-frontends configuration.");return n[t]=o[0],o[0]}var _=require("react/jsx-runtime"),K=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function T(e){let{clientConfig:t,isLoading:n}=E({removeFlaggedPathsFromDefault:!0}),s=typeof e=="string"&&e.startsWith("/"),o=s?w(t,e):null;return{zoneOfHref:o,isDifferentZone:!s||(o?K!==o:!1),isLoading:n}}var H=(0,P.forwardRef)(({children:e,...t},n)=>{let{prefetchHref:s}=(0,P.useContext)(g),{zoneOfHref:o,isDifferentZone:i,isLoading:a}=T(t.href);function r(){t.href&&s(t.href)}if(i&&o!==null){let{prefetch:l,...h}=t;return(0,_.jsx)("a",{...h,"data-zone":o,onMouseOver:t.prefetch!==!1?r:void 0,children:e})}return(0,_.jsx)(F.default,{...t,"data-zone":o?"same":"null",prefetch:t.prefetch??(a?!1:void 0),ref:n,children:e})});H.displayName="MultiZonesLink";0&&(module.exports={Link,PrefetchCrossZoneLinks,PrefetchCrossZoneLinksContext,PrefetchCrossZoneLinksProvider,useZoneForHref});
2
+ "use strict";var M=Object.create;var C=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var Z=Object.getPrototypeOf,I=Object.prototype.hasOwnProperty;var D=(t,e)=>{for(var n in e)C(t,n,{get:e[n],enumerable:!0})},_=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of H(e))!I.call(t,r)&&r!==n&&C(t,r,{get:()=>e[r],enumerable:!(o=w(e,r))||o.enumerable});return t};var N=(t,e,n)=>(n=t!=null?M(Z(t)):{},_(e||!t||!t.__esModule?C(n,"default",{value:t,enumerable:!0}):n,t)),z=t=>_(C({},"__esModule",{value:!0}),t);var $={};D($,{Link:()=>F,PrefetchCrossZoneLinks:()=>U,PrefetchCrossZoneLinksContext:()=>E,PrefetchCrossZoneLinksProvider:()=>J,useZoneForHref:()=>T});module.exports=z($);var P=require("react"),S=N(require("next/link"),1);var d=require("react");var b=require("path-to-regexp"),l=class{constructor(e,n){this.pathCache={};if(this.serialized=e,n!=null&&n.removeFlaggedPaths)for(let o of Object.values(e.applications))o.routing&&(o.routing=o.routing.filter(r=>!r.flag));this.applications=e.applications}static fromEnv(e,n){if(!e)throw new Error("No microfrontends configuration found");return new l(JSON.parse(e),n)}isEqual(e){return JSON.stringify(this.applications)===JSON.stringify(e.applications)}getApplicationNameForPath(e){if(!e.startsWith("/"))throw new Error("Path must start with a /");if(this.pathCache[e])return this.pathCache[e];let n=new URL(e,"https://example.com").pathname;for(let[r,i]of Object.entries(this.applications))if(i.routing){for(let a of i.routing)for(let s of a.paths)if((0,b.pathToRegexp)(s).test(n))return this.pathCache[e]=r,r}let o=Object.entries(this.applications).find(([,r])=>r.default);return o?(this.pathCache[e]=o[0],o[0]):null}serialize(){return this.serialized}};var v=null;async function B(){try{let t=await fetch("/.well-known/vercel/microfrontends/client-config");if(t.status!==200)return null;let e=await t.json();return new l(e.config)}catch{return null}}function g(t,{removeFlaggedPathsFromDefault:e}={}){let[n,o]=(0,d.useState)(l.fromEnv(t,{removeFlaggedPaths:e})),[r,i]=(0,d.useState)(!0);return(0,d.useEffect)(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){i(!1);return}let a=l.fromEnv(t);if(!Object.values(a.applications).some(u=>{var p;return(p=u.routing)==null?void 0:p.some(A=>A.flag)})){i(!1);return}v||(v=B()),v.then(u=>{u&&o(p=>p.isEqual(u)?p:u)}).finally(()=>{i(!1)})},[t,n.applications]),{clientConfig:n,isLoading:r}}var f=require("react"),h=require("react/jsx-runtime"),E=(0,f.createContext)({prefetchHref:()=>{}});function J({children:t}){let[e,n]=(0,f.useState)(new Set),[o,r]=(0,f.useState)(!1);(0,f.useEffect)(()=>{r(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let i=(0,f.useCallback)(s=>{e.has(s)||n(new Set(e).add(s))},[e]),a=(0,f.useMemo)(()=>({prefetchHref:i}),[i]);return o?(0,h.jsxs)(E.Provider,{value:a,children:[t,[...e].map(s=>(0,h.jsx)("link",{as:"fetch",href:s,rel:"preload"},s))]}):(0,h.jsx)(h.Fragment,{children:t})}var m=require("react"),O=N(require("next/script"),1);var R=require("react/jsx-runtime"),L="data-prefetch",c={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${L}]`},x={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}}]},V={and:[{href_matches:"/*"},{selector_matches:c.anyZone},{not:{selector_matches:c.sameZone}},{not:{selector_matches:c.external}},{selector_matches:c.prefetch}]};function k(t){if(!t)return!0;if("checkVisibility"in t)return t.checkVisibility({opacityProperty:!0});let e=t,n=window.getComputedStyle(e);return n.display==="none"||n.visibility==="hidden"||n.opacity==="0"?!1:k(e.parentElement)}function U(){let{isLoading:t}=g(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG),[e,n]=(0,m.useState)([]);return(0,m.useEffect)(()=>{if(t)return;let r=new IntersectionObserver(i=>{i.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(L)&&k(a.target)&&a.target.setAttribute(L,"true")})},{root:null,rootMargin:"0px",threshold:.1});return e.forEach(i=>r.observe(i)),()=>{r.disconnect()}},[t,e]),(0,m.useEffect)(()=>{if(t)return;let r=new MutationObserver(i=>{i.some(s=>s.type==="childList"&&s.addedNodes.length>0||s.type==="attributes"&&s.attributeName==="href")&&n(Array.from(document.querySelectorAll(`a${c.anyZone}:not(${c.prefetch}):not(${c.sameZone}):not(${c.external})`)))});return r.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{r.disconnect()}},[t]),t?null:(0,R.jsx)(O.default,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:x},{eagerness:"immediate",where:V}],prerender:[{eagerness:"conservative",where:x}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}var y=require("react/jsx-runtime"),X=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function T(t){let{clientConfig:e,isLoading:n}=g(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,{removeFlaggedPathsFromDefault:!0}),o=typeof t=="string"&&t.startsWith("/"),r=o?e.getApplicationNameForPath(t):null;return{zoneOfHref:r,isDifferentZone:!o||(r?X!==r:!1),isLoading:n}}var F=(0,P.forwardRef)(({children:t,...e},n)=>{let{prefetchHref:o}=(0,P.useContext)(E),{zoneOfHref:r,isDifferentZone:i,isLoading:a}=T(e.href);function s(){e.href&&o(e.href)}if(i&&r!==null){let{prefetch:u,...p}=e;return(0,y.jsx)("a",{...p,"data-zone":r,onMouseOver:e.prefetch!==!1?s:void 0,children:t})}return(0,y.jsx)(S.default,{...e,"data-zone":r?"same":"null",prefetch:e.prefetch??(a?!1:void 0),ref:n,children:t})});F.displayName="MultiZonesLink";0&&(module.exports={Link,PrefetchCrossZoneLinks,PrefetchCrossZoneLinksContext,PrefetchCrossZoneLinksProvider,useZoneForHref});
3
3
  //# sourceMappingURL=client.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/client/index.ts","../../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":["export * from './link';\nexport * from './prefetch';\n","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":";0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,2BAAAC,EAAA,kCAAAC,EAAA,mCAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GCCA,IAAAQ,EAAuC,iBACvCC,EAA0D,0BCF1D,IAAAC,EAMO,iBAuCIC,EAAA,6BAjCEC,KACX,iBAA6C,CAE3C,aAAc,IAAM,CAAC,CACvB,CAAC,EAEI,SAASC,EAA+B,CAC7C,SAAAC,CACF,EAAsD,CACpD,GAAM,CAACC,EAAWC,CAA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AaP,EAAY,GAAQ,QACjD,IAAKQ,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAD,EAAK,YAAc","names":["client_exports","__export","Link","PrefetchCrossZoneLinks","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","useZoneForHref","__toCommonJS","import_react","import_link","import_react","import_jsx_runtime","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","import_react","import_script","import_react","getClientConfigFromEnv","clientConfigJson","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","isEqual","config1","config2","removeFlaggedPaths","config","app","match","_a","useClientConfig","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","getClientConfigFromEnv","isLoading","setIsLoading","originalClientConfig","group","newConfig","prevConfig","import_jsx_runtime","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","observer","entries","entry","link","mutations","mutation","Script","import_path_to_regexp","weakCache","getApplicationNameForPath","config","path","cache","pathname","name","application","group","childPath","defaultApplication","import_jsx_runtime","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","getApplicationNameForPath","Link","children","props","ref","prefetchHref","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
1
+ {"version":3,"sources":["../../src/next/client/index.ts","../../src/next/client/link/multi-zones-link.tsx","../../src/config/react/use-client-config.ts","../../src/config/microfrontends-config/client/index.ts","../../src/next/client/prefetch/prefetch-cross-zone-links-context.tsx","../../src/next/client/prefetch/prefetch-cross-zone-links.tsx"],"sourcesContent":["export * from './link';\nexport * from './prefetch';\n","import type { AnchorHTMLAttributes } from 'react';\nimport { forwardRef, useContext } from 'react';\nimport NextLink, { type LinkProps as NextLinkProps } from 'next/link';\nimport { useClientConfig } from '../../../config/react/use-client-config';\nimport { PrefetchCrossZoneLinksContext } from '../prefetch';\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 process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n {\n removeFlaggedPathsFromDefault: true,\n },\n );\n const isRelativePath =\n typeof href === 'string' && (href as string).startsWith('/');\n const zoneOfHref = isRelativePath\n ? clientConfig.getApplicationNameForPath(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","'use client';\n\nimport { useState, useEffect } from 'react';\nimport type { WellKnownClientData } from '../well-known/types';\nimport { MicrofrontendConfigClient } from '../microfrontends-config/client';\n\nlet cachedServerClientConfigPromise: Promise<MicrofrontendConfigClient | null> | null =\n null;\n\nasync function fetchClientConfigFromServer(): Promise<MicrofrontendConfigClient | 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 new MicrofrontendConfigClient(responseJson.config);\n } catch (err) {\n return null;\n }\n}\n\n/**\n * Hook to use the client microfrontends 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 config: string | undefined,\n {\n removeFlaggedPathsFromDefault,\n }: {\n removeFlaggedPathsFromDefault?: boolean;\n } = {},\n): {\n clientConfig: MicrofrontendConfigClient;\n isLoading: boolean;\n} {\n const [clientConfig, setClientConfig] = useState<MicrofrontendConfigClient>(\n MicrofrontendConfigClient.fromEnv(config, {\n removeFlaggedPaths: removeFlaggedPathsFromDefault,\n }),\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 = MicrofrontendConfigClient.fromEnv(config);\n // As an optimization, only fetch the config from the server if the\n // microfrontends 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?.some((group) => group.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 prevConfig.isEqual(newConfig) ? prevConfig : newConfig;\n });\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, [config, clientConfig.applications]);\n\n return { clientConfig, isLoading };\n}\n\nexport function resetCachedServerClientConfigPromise(): void {\n cachedServerClientConfigPromise = null;\n}\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\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/react/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 process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n );\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"],"mappings":";0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,UAAAE,EAAA,2BAAAC,EAAA,kCAAAC,EAAA,mCAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GCCA,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,YAAWV,EACX,YAAaG,EAAM,WAAa,GAAQK,EAAkB,OAEzD,SAAAN,EACH,EAIJ,SACE,OAAC,EAAAS,QAAA,CACE,GAAGR,EACJ,YAAYH,EAAsB,OAAT,OACzB,SAAUG,EAAM,WAAaN,EAAY,GAAQ,QACjD,IAAKO,EAEJ,SAAAF,EACH,CAEJ,CACF,EACAD,EAAK,YAAc","names":["client_exports","__export","Link","PrefetchCrossZoneLinks","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","useZoneForHref","__toCommonJS","import_react","import_link","import_react","import_path_to_regexp","MicrofrontendConfigClient","config","opts","app","match","other","path","pathname","name","application","group","childPath","defaultApplication","cachedServerClientConfigPromise","fetchClientConfigFromServer","response","responseJson","MicrofrontendConfigClient","useClientConfig","config","removeFlaggedPathsFromDefault","clientConfig","setClientConfig","isLoading","setIsLoading","originalClientConfig","app","_a","group","newConfig","prevConfig","import_react","import_jsx_runtime","PrefetchCrossZoneLinksContext","PrefetchCrossZoneLinksProvider","children","seenHrefs","setSeenHrefs","isSafariOrFirefox","setIsSafariOrFirefox","prefetchHref","href","value","import_react","import_script","import_jsx_runtime","PREFETCH_ATTR","DATA_ATTR_SELECTORS","PREFETCH_ON_HOVER_PREDICATES","PREFETCH_WHEN_VISIBLE_PREDICATES","checkVisibility","element","el","style","PrefetchCrossZoneLinks","isLoading","useClientConfig","links","setLinks","observer","entries","entry","link","mutations","mutation","Script","import_jsx_runtime","CURRENT_ZONE","useZoneForHref","href","clientConfig","isLoading","useClientConfig","isRelativePath","zoneOfHref","Link","children","props","ref","prefetchHref","PrefetchCrossZoneLinksContext","isDifferentZone","onHoverPrefetch","_","rest","NextLink"]}
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import{forwardRef as z,useContext as W}from"react";import B from"next/link";import{createContext as k,useCallback as N,useEffect as O,useMemo as R,useState as E}from"react";import{Fragment as S,jsx as P,jsxs as A}from"react/jsx-runtime";var m=k({prefetchHref:()=>{}});function K({children:e}){let[t,o]=E(new Set),[s,n]=E(!1);O(()=>{n(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let i=N(r=>{t.has(r)||o(new Set(t).add(r))},[t]),a=R(()=>({prefetchHref:i}),[i]);return s?A(m.Provider,{value:a,children:[e,[...t].map(r=>P("link",{as:"fetch",href:r,rel:"preload"},r))]}):P(S,{children:e})}import{useEffect as L,useState as Z}from"react";import I from"next/script";import{useState as y,useEffect as w}from"react";function u(){let e=process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;if(!e)throw new Error("Could not find client micro-frontends config in the environment");return JSON.parse(e)}var h=null;async function F(){try{let e=await fetch("/.well-known/vercel/micro-frontends/client-config");return e.status!==200?null:(await e.json()).config}catch{return null}}function T(e,t){return JSON.stringify(e)===JSON.stringify(t)}function H(e){for(let t of Object.values(e.applications))t.routing&&(t.routing.matches=t.routing.matches.filter(o=>{var s;return!((s=o.options)!=null&&s.flag)}));return e}function p({removeFlaggedPathsFromDefault:e}={}){let[t,o]=y(e?H(u()):u()),[s,n]=y(!0);return w(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){n(!1);return}let i=u();if(!Object.values(i.applications).some(r=>{var c;return(c=r.routing)==null?void 0:c.matches.some(l=>{var d;return(d=l.options)==null?void 0:d.flag})})){n(!1);return}h||(h=F()),h.then(r=>{r&&o(c=>T(c,r)?c:r)}).finally(()=>{n(!1)})},[t.applications]),{clientConfig:t,isLoading:s}}import{jsx as D}from"react/jsx-runtime";var C="data-prefetch",f={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${C}]`},v={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}}]},M={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}},{selector_matches:f.prefetch}]};function _(e){if(!e)return!0;if("checkVisibility"in e)return e.checkVisibility({opacityProperty:!0});let t=e,o=window.getComputedStyle(t);return o.display==="none"||o.visibility==="hidden"||o.opacity==="0"?!1:_(t.parentElement)}function ie(){let{isLoading:e}=p(),[t,o]=Z([]);return L(()=>{if(e)return;let n=new IntersectionObserver(i=>{i.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(C)&&_(a.target)&&a.target.setAttribute(C,"true")})},{root:null,rootMargin:"0px",threshold:.1});return t.forEach(i=>n.observe(i)),()=>{n.disconnect()}},[e,t]),L(()=>{if(e)return;let n=new MutationObserver(i=>{i.some(r=>r.type==="childList"&&r.addedNodes.length>0||r.type==="attributes"&&r.attributeName==="href")&&o(Array.from(document.querySelectorAll(`a${f.anyZone}:not(${f.prefetch}):not(${f.sameZone}):not(${f.external})`)))});return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{n.disconnect()}},[e]),e?null:D(I,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:v},{eagerness:"immediate",where:M}],prerender:[{eagerness:"conservative",where:v}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}import{pathToRegexp as J}from"path-to-regexp";var g=new WeakMap;function x(e,t){if(!t.startsWith("/"))throw new Error("Path must start with a /");let o=g.get(e)??{};if(o[t])return o[t];g.has(e)||g.set(e,o);let s=new URL(t,"https://example.com").pathname;for(let[i,a]of Object.entries(e.applications))if(a.routing){for(let r of a.routing.matches)for(let c of r.paths)if(J(c).test(s))return o[t]=i,i}let n=Object.entries(e.applications).find(([,i])=>i.default);if(!n)throw new Error("No default application found. A default application must be configured in the micro-frontends configuration.");return o[t]=n[0],n[0]}import{jsx as b}from"react/jsx-runtime";var V=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function $(e){let{clientConfig:t,isLoading:o}=p({removeFlaggedPathsFromDefault:!0}),s=typeof e=="string"&&e.startsWith("/"),n=s?x(t,e):null;return{zoneOfHref:n,isDifferentZone:!s||(n?V!==n:!1),isLoading:o}}var U=z(({children:e,...t},o)=>{let{prefetchHref:s}=W(m),{zoneOfHref:n,isDifferentZone:i,isLoading:a}=$(t.href);function r(){t.href&&s(t.href)}if(i&&n!==null){let{prefetch:c,...l}=t;return b("a",{...l,"data-zone":n,onMouseOver:t.prefetch!==!1?r:void 0,children:e})}return b(B,{...t,"data-zone":n?"same":"null",prefetch:t.prefetch??(a?!1:void 0),ref:o,children:e})});U.displayName="MultiZonesLink";export{U as Link,ie as PrefetchCrossZoneLinks,m as PrefetchCrossZoneLinksContext,K as PrefetchCrossZoneLinksProvider,$ as useZoneForHref};
2
+ import{forwardRef as Z,useContext as I}from"react";import D from"next/link";import{useState as C,useEffect as b}from"react";import{pathToRegexp as N}from"path-to-regexp";var c=class{constructor(e,r){this.pathCache={};if(this.serialized=e,r!=null&&r.removeFlaggedPaths)for(let i of Object.values(e.applications))i.routing&&(i.routing=i.routing.filter(n=>!n.flag));this.applications=e.applications}static fromEnv(e,r){if(!e)throw new Error("No microfrontends configuration found");return new c(JSON.parse(e),r)}isEqual(e){return JSON.stringify(this.applications)===JSON.stringify(e.applications)}getApplicationNameForPath(e){if(!e.startsWith("/"))throw new Error("Path must start with a /");if(this.pathCache[e])return this.pathCache[e];let r=new URL(e,"https://example.com").pathname;for(let[n,o]of Object.entries(this.applications))if(o.routing){for(let a of o.routing)for(let s of a.paths)if(N(s).test(r))return this.pathCache[e]=n,n}let i=Object.entries(this.applications).find(([,n])=>n.default);return i?(this.pathCache[e]=i[0],i[0]):null}serialize(){return this.serialized}};var h=null;async function x(){try{let t=await fetch("/.well-known/vercel/microfrontends/client-config");if(t.status!==200)return null;let e=await t.json();return new c(e.config)}catch{return null}}function p(t,{removeFlaggedPathsFromDefault:e}={}){let[r,i]=C(c.fromEnv(t,{removeFlaggedPaths:e})),[n,o]=C(!0);return b(()=>{if(process.env.NODE_ENV==="test"&&process.env.MFE_FORCE_CLIENT_CONFIG_FROM_SERVER!=="1"){o(!1);return}let a=c.fromEnv(t);if(!Object.values(a.applications).some(l=>{var u;return(u=l.routing)==null?void 0:u.some(_=>_.flag)})){o(!1);return}h||(h=x()),h.then(l=>{l&&i(u=>u.isEqual(l)?u:l)}).finally(()=>{o(!1)})},[t,r.applications]),{clientConfig:r,isLoading:n}}import{createContext as O,useCallback as k,useEffect as R,useMemo as S,useState as g}from"react";import{Fragment as T,jsx as E,jsxs as F}from"react/jsx-runtime";var d=O({prefetchHref:()=>{}});function j({children:t}){let[e,r]=g(new Set),[i,n]=g(!1);R(()=>{n(typeof navigator<"u"&&(navigator.userAgent.includes("Firefox")||navigator.userAgent.includes("Safari")&&!navigator.userAgent.includes("Chrome")))},[]);let o=k(s=>{e.has(s)||r(new Set(e).add(s))},[e]),a=S(()=>({prefetchHref:o}),[o]);return i?F(d.Provider,{value:a,children:[t,[...e].map(s=>E("link",{as:"fetch",href:s,rel:"preload"},s))]}):E(T,{children:t})}import{useEffect as P,useState as A}from"react";import M from"next/script";import{jsx as H}from"react/jsx-runtime";var m="data-prefetch",f={anyZone:"[data-zone]",external:'[data-zone="null"]',sameZone:'[data-zone="same"]',prefetch:`[${m}]`},v={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}}]},w={and:[{href_matches:"/*"},{selector_matches:f.anyZone},{not:{selector_matches:f.sameZone}},{not:{selector_matches:f.external}},{selector_matches:f.prefetch}]};function L(t){if(!t)return!0;if("checkVisibility"in t)return t.checkVisibility({opacityProperty:!0});let e=t,r=window.getComputedStyle(e);return r.display==="none"||r.visibility==="hidden"||r.opacity==="0"?!1:L(e.parentElement)}function ne(){let{isLoading:t}=p(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG),[e,r]=A([]);return P(()=>{if(t)return;let n=new IntersectionObserver(o=>{o.forEach(a=>{a.isIntersecting&&!a.target.hasAttribute(m)&&L(a.target)&&a.target.setAttribute(m,"true")})},{root:null,rootMargin:"0px",threshold:.1});return e.forEach(o=>n.observe(o)),()=>{n.disconnect()}},[t,e]),P(()=>{if(t)return;let n=new MutationObserver(o=>{o.some(s=>s.type==="childList"&&s.addedNodes.length>0||s.type==="attributes"&&s.attributeName==="href")&&r(Array.from(document.querySelectorAll(`a${f.anyZone}:not(${f.prefetch}):not(${f.sameZone}):not(${f.external})`)))});return n.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["href"]}),()=>{n.disconnect()}},[t]),t?null:H(M,{dangerouslySetInnerHTML:{__html:`${JSON.stringify({prefetch:[{eagerness:"moderate",where:v},{eagerness:"immediate",where:w}],prerender:[{eagerness:"conservative",where:v}]})}`},id:"prefetch-zones-links",type:"speculationrules"})}import{jsx as y}from"react/jsx-runtime";var z=process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION;function B(t){let{clientConfig:e,isLoading:r}=p(process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,{removeFlaggedPathsFromDefault:!0}),i=typeof t=="string"&&t.startsWith("/"),n=i?e.getApplicationNameForPath(t):null;return{zoneOfHref:n,isDifferentZone:!i||(n?z!==n:!1),isLoading:r}}var J=Z(({children:t,...e},r)=>{let{prefetchHref:i}=I(d),{zoneOfHref:n,isDifferentZone:o,isLoading:a}=B(e.href);function s(){e.href&&i(e.href)}if(o&&n!==null){let{prefetch:l,...u}=e;return y("a",{...u,"data-zone":n,onMouseOver:e.prefetch!==!1?s:void 0,children:t})}return y(D,{...e,"data-zone":n?"same":"null",prefetch:e.prefetch??(a?!1:void 0),ref:r,children:t})});J.displayName="MultiZonesLink";export{J as Link,ne as PrefetchCrossZoneLinks,d as PrefetchCrossZoneLinksContext,j as PrefetchCrossZoneLinksProvider,B as useZoneForHref};
3
3
  //# sourceMappingURL=client.js.map