@vercel/microfrontends 0.17.1 → 0.17.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -89
  3. package/dist/bin/cli.cjs +299 -200
  4. package/dist/config.cjs +22 -45
  5. package/dist/config.cjs.map +1 -1
  6. package/dist/config.d.ts +4 -4
  7. package/dist/config.js +22 -45
  8. package/dist/config.js.map +1 -1
  9. package/dist/{types-a29d224a.d.ts → index-5fcf0863.d.ts} +2 -2
  10. package/dist/{index-4399aa8e.d.ts → index-f094deb1.d.ts} +5 -4
  11. package/dist/microfrontends/server.cjs +68 -75
  12. package/dist/microfrontends/server.cjs.map +1 -1
  13. package/dist/microfrontends/server.d.ts +4 -4
  14. package/dist/microfrontends/server.js +68 -75
  15. package/dist/microfrontends/server.js.map +1 -1
  16. package/dist/microfrontends.cjs +24 -48
  17. package/dist/microfrontends.cjs.map +1 -1
  18. package/dist/microfrontends.d.ts +4 -4
  19. package/dist/microfrontends.js +24 -48
  20. package/dist/microfrontends.js.map +1 -1
  21. package/dist/next/client.cjs +1 -1
  22. package/dist/next/client.cjs.map +1 -1
  23. package/dist/next/client.js +1 -1
  24. package/dist/next/client.js.map +1 -1
  25. package/dist/next/config.cjs +86 -101
  26. package/dist/next/config.cjs.map +1 -1
  27. package/dist/next/config.js +86 -101
  28. package/dist/next/config.js.map +1 -1
  29. package/dist/next/endpoints.cjs +1 -1
  30. package/dist/next/endpoints.cjs.map +1 -1
  31. package/dist/next/endpoints.d.ts +2 -2
  32. package/dist/next/endpoints.js +1 -1
  33. package/dist/next/endpoints.js.map +1 -1
  34. package/dist/next/middleware.cjs +32 -63
  35. package/dist/next/middleware.cjs.map +1 -1
  36. package/dist/next/middleware.js +32 -63
  37. package/dist/next/middleware.js.map +1 -1
  38. package/dist/next/testing.cjs +27 -54
  39. package/dist/next/testing.cjs.map +1 -1
  40. package/dist/next/testing.d.ts +4 -4
  41. package/dist/next/testing.js +27 -54
  42. package/dist/next/testing.js.map +1 -1
  43. package/dist/overrides.cjs +1 -2
  44. package/dist/overrides.cjs.map +1 -1
  45. package/dist/overrides.d.ts +3 -3
  46. package/dist/overrides.js +1 -2
  47. package/dist/overrides.js.map +1 -1
  48. package/dist/schema.cjs.map +1 -1
  49. package/dist/schema.d.ts +1 -1
  50. package/dist/{types-fc30696d.d.ts → types-5900be7c.d.ts} +1 -1
  51. package/dist/{types-cfe3308b.d.ts → types-ecd7b91b.d.ts} +1 -1
  52. package/dist/utils/mfe-port.cjs +68 -75
  53. package/dist/utils/mfe-port.cjs.map +1 -1
  54. package/dist/utils/mfe-port.js +68 -75
  55. package/dist/utils/mfe-port.js.map +1 -1
  56. package/dist/validation.cjs +46 -17
  57. package/dist/validation.cjs.map +1 -1
  58. package/dist/validation.d.ts +1 -1
  59. package/dist/validation.js +46 -17
  60. package/dist/validation.js.map +1 -1
  61. package/package.json +18 -22
  62. package/schema/schema.json +15 -8
@@ -10,9 +10,9 @@ var MicrofrontendError = class extends Error {
10
10
  constructor(message, opts) {
11
11
  super(message);
12
12
  this.name = "MicrofrontendsError";
13
- this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
14
- this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
15
- this.subtype = opts == null ? void 0 : opts.subtype;
13
+ this.source = opts?.source ?? "@vercel/microfrontends";
14
+ this.type = opts?.type ?? "unknown";
15
+ this.subtype = opts?.subtype;
16
16
  Error.captureStackTrace(this, MicrofrontendError);
17
17
  }
18
18
  isKnown() {
@@ -27,7 +27,7 @@ var MicrofrontendError = class extends Error {
27
27
  * @returns The converted MicrofrontendsError.
28
28
  */
29
29
  static convert(original, opts) {
30
- if (opts == null ? void 0 : opts.fileName) {
30
+ if (opts?.fileName) {
31
31
  const err = MicrofrontendError.convertFSError(original, opts.fileName);
32
32
  if (err) {
33
33
  return err;
@@ -125,7 +125,7 @@ var MicrofrontendConfigClient = class {
125
125
  constructor(config, opts) {
126
126
  this.pathCache = {};
127
127
  this.serialized = config;
128
- if (opts == null ? void 0 : opts.removeFlaggedPaths) {
128
+ if (opts?.removeFlaggedPaths) {
129
129
  for (const app of Object.values(config.applications)) {
130
130
  if (app.routing) {
131
131
  app.routing = app.routing.filter((match) => !match.flag);
@@ -191,8 +191,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
191
191
 
192
192
  // src/config/overrides/is-override-cookie.ts
193
193
  function isOverrideCookie(cookie) {
194
- var _a;
195
- return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
194
+ return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
196
195
  }
197
196
 
198
197
  // src/config/overrides/get-override-from-cookie.ts
@@ -221,17 +220,6 @@ function parseOverrides(cookies) {
221
220
 
222
221
  // src/config/microfrontends-config/isomorphic/validation.ts
223
222
  import { pathToRegexp as pathToRegexp2, parse as parsePathRegexp } from "path-to-regexp";
224
- var SUPPORTED_VERSIONS = ["2"];
225
- var validateConfigVersion = (version) => {
226
- if (!SUPPORTED_VERSIONS.includes(version)) {
227
- throw new MicrofrontendError(
228
- `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
229
- ", "
230
- )}`,
231
- { type: "config", subtype: "unsupported_version" }
232
- );
233
- }
234
- };
235
223
  var validateConfigPaths = (applicationConfigsById) => {
236
224
  if (!applicationConfigsById) {
237
225
  return;
@@ -407,7 +395,7 @@ var Host = class {
407
395
  this.protocol = protocol;
408
396
  this.host = host;
409
397
  this.port = Host.getPort({ port, protocol: this.protocol });
410
- this.local = options == null ? void 0 : options.isLocal;
398
+ this.local = options?.isLocal;
411
399
  }
412
400
  isLocal() {
413
401
  return this.local || this.host === "localhost" || this.host === "127.0.0.1";
@@ -456,18 +444,17 @@ var Application = class {
456
444
  overrides,
457
445
  isDefault
458
446
  }) {
459
- var _a, _b;
460
447
  this.name = name;
461
448
  this.development = {
462
449
  local: new LocalHost({
463
450
  appName: name,
464
- ...(_a = app.development) == null ? void 0 : _a.local
451
+ ...app.development?.local
465
452
  }),
466
- fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
453
+ fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
467
454
  };
468
455
  this.production = app.production ? new Host(app.production) : void 0;
469
456
  this.vercel = app.vercel;
470
- this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
457
+ this.overrides = overrides?.environment ? {
471
458
  environment: new Host(overrides.environment)
472
459
  } : void 0;
473
460
  this.default = isDefault ?? false;
@@ -527,17 +514,17 @@ var MicrofrontendConfigIsomorphic = class {
527
514
  constructor({
528
515
  config,
529
516
  overrides,
530
- meta
517
+ meta,
518
+ opts
531
519
  }) {
532
520
  this.childApplications = {};
533
- var _a, _b, _c, _d;
534
- MicrofrontendConfigIsomorphic.validate(config);
535
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
521
+ MicrofrontendConfigIsomorphic.validate(config, opts);
522
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
536
523
  this.overrides = overrides && !disableOverrides ? overrides : void 0;
537
524
  this.isMainConfig = isMainConfig(config);
538
525
  if (isMainConfig(config)) {
539
526
  for (const [appId, appConfig] of Object.entries(config.applications)) {
540
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
527
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
541
528
  if (isDefaultApp(appConfig)) {
542
529
  this.defaultApplication = new DefaultApplication(appId, {
543
530
  app: appConfig,
@@ -552,7 +539,7 @@ var MicrofrontendConfigIsomorphic = class {
552
539
  }
553
540
  } else {
554
541
  this.partOf = config.partOf;
555
- const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
542
+ const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
556
543
  this.childApplications[meta.fromApp] = new ChildApplication(
557
544
  meta.fromApp,
558
545
  {
@@ -580,12 +567,9 @@ var MicrofrontendConfigIsomorphic = class {
580
567
  };
581
568
  }
582
569
  static validate(config, opts) {
583
- const skipValidation = (opts == null ? void 0 : opts.skipValidation) ?? [];
570
+ const skipValidation = opts?.skipValidation ?? [];
584
571
  const c = typeof config === "string" ? parse(config) : config;
585
572
  if (isMainConfig(c)) {
586
- if (!skipValidation.includes("version")) {
587
- validateConfigVersion(c.version);
588
- }
589
573
  if (!skipValidation.includes("paths")) {
590
574
  validateConfigPaths(c.applications);
591
575
  }
@@ -606,8 +590,7 @@ var MicrofrontendConfigIsomorphic = class {
606
590
  });
607
591
  }
608
592
  isOverridesDisabled() {
609
- var _a, _b;
610
- return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
593
+ return this.options?.vercel?.disableOverrides ?? false;
611
594
  }
612
595
  getConfig() {
613
596
  return this.config;
@@ -628,8 +611,7 @@ var MicrofrontendConfigIsomorphic = class {
628
611
  ].filter(Boolean);
629
612
  }
630
613
  getApplication(name) {
631
- var _a;
632
- if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
614
+ if (this.defaultApplication?.name === name) {
633
615
  return this.defaultApplication;
634
616
  }
635
617
  const app = this.childApplications[name];
@@ -645,15 +627,11 @@ var MicrofrontendConfigIsomorphic = class {
645
627
  return app;
646
628
  }
647
629
  getApplicationByProjectId(projectId) {
648
- var _a, _b;
649
- if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
630
+ if (this.defaultApplication?.vercel?.projectId === projectId) {
650
631
  return this.defaultApplication;
651
632
  }
652
633
  return Object.values(this.childApplications).find(
653
- (app) => {
654
- var _a2;
655
- return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
656
- }
634
+ (app) => app.vercel?.projectId === projectId
657
635
  );
658
636
  }
659
637
  /**
@@ -676,8 +654,7 @@ var MicrofrontendConfigIsomorphic = class {
676
654
  * Returns the configured port for the local proxy
677
655
  */
678
656
  getLocalProxyPort() {
679
- var _a, _b;
680
- return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
657
+ return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
681
658
  }
682
659
  /**
683
660
  * Serializes the class back to the Schema type.
@@ -731,13 +708,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
731
708
  overrides,
732
709
  meta
733
710
  }) {
734
- var _a, _b, _c;
735
711
  super({ config, overrides, meta });
736
712
  this.isMainConfig = true;
737
- const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
713
+ const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
738
714
  let defaultApplication;
739
715
  for (const [appId, appConfig] of Object.entries(config.applications)) {
740
- const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
716
+ const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
741
717
  if (isDefaultApp(appConfig)) {
742
718
  defaultApplication = new DefaultApplication(appId, {
743
719
  app: appConfig,
@@ -796,21 +772,17 @@ function getDomainFromEnvironment({
796
772
  app,
797
773
  target
798
774
  }) {
799
- var _a;
800
775
  const mfeProjects = JSON.parse(
801
776
  process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
802
777
  );
803
778
  if (mfeProjects.length === 0) {
804
779
  throw new Error("Missing related microfrontends project information");
805
780
  }
806
- if (!((_a = app.vercel) == null ? void 0 : _a.projectId)) {
781
+ if (!app.vercel?.projectId) {
807
782
  throw new Error(`Missing applications[${app.name}].vercel.projectId`);
808
783
  }
809
784
  const vercelProject = mfeProjects.find(
810
- (p) => {
811
- var _a2;
812
- return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
813
- }
785
+ (p) => p.project.id === app.vercel?.projectId
814
786
  );
815
787
  if (!vercelProject) {
816
788
  throw new Error(
@@ -853,9 +825,8 @@ function getCurrentEnvironment() {
853
825
  return { group: "custom", name: process.env.VERCEL_ENV };
854
826
  }
855
827
  function getDomainForCurrentEnvironment(config, appName, opts = {}) {
856
- var _a;
857
828
  const app = config.getApplication(appName);
858
- if (!opts.ignoreOverride && ((_a = app.overrides) == null ? void 0 : _a.environment)) {
829
+ if (!opts.ignoreOverride && app.overrides?.environment) {
859
830
  return app.overrides.environment.toString();
860
831
  }
861
832
  const { group } = getCurrentEnvironment();
@@ -882,8 +853,7 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
882
853
 
883
854
  // src/next/middleware/middleware.ts
884
855
  async function verifyPreviewDomain(req, rewriteDomain) {
885
- var _a;
886
- const jwtCookie = (_a = req.cookies.get("_vercel_jwt")) == null ? void 0 : _a.value;
856
+ const jwtCookie = req.cookies.get("_vercel_jwt")?.value;
887
857
  const deploymentProtectionBypassHeader = req.headers.get(
888
858
  "x-vercel-protection-bypass"
889
859
  );
@@ -908,7 +878,6 @@ function getHandler({
908
878
  production
909
879
  }) {
910
880
  return async (req) => {
911
- var _a, _b;
912
881
  try {
913
882
  const pathname = req.nextUrl.pathname;
914
883
  const search = req.nextUrl.search;
@@ -925,7 +894,7 @@ function getHandler({
925
894
  if (process.env.VERCEL_ENV === "preview" && rewriteDomain) {
926
895
  const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;
927
896
  const assetPrefix = application.getAssetPrefix();
928
- if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) && ((_a = req.cookies.get(zoneFallbackCookieName)) == null ? void 0 : _a.value) === "1") {
897
+ if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) && req.cookies.get(zoneFallbackCookieName)?.value === "1") {
929
898
  rewriteDomain = production.toString();
930
899
  } else {
931
900
  try {
@@ -948,7 +917,7 @@ function getHandler({
948
917
  });
949
918
  try {
950
919
  const existingCookie = patchedHeaders.get("cookie");
951
- if (!(existingCookie == null ? void 0 : existingCookie.includes("__vercel_toolbar"))) {
920
+ if (!existingCookie?.includes("__vercel_toolbar")) {
952
921
  patchedHeaders.set(
953
922
  "cookie",
954
923
  [`__vercel_toolbar=1`, existingCookie].join("; ")
@@ -964,7 +933,7 @@ function getHandler({
964
933
  }
965
934
  } catch (error) {
966
935
  }
967
- } else if (((_b = req.cookies.get(zoneFallbackCookieName)) == null ? void 0 : _b.value) === "1") {
936
+ } else if (req.cookies.get(zoneFallbackCookieName)?.value === "1") {
968
937
  responseCallbacks.push((response) => {
969
938
  response.cookies.set(zoneFallbackCookieName, "", {
970
939
  httpOnly: true,
@@ -1047,7 +1016,7 @@ function getMicrofrontendsMiddleware({
1047
1016
  const flagName = pathGroup.flag;
1048
1017
  let flagFn;
1049
1018
  if (flagName) {
1050
- flagFn = flagValues == null ? void 0 : flagValues[flagName];
1019
+ flagFn = flagValues?.[flagName];
1051
1020
  if (!flagFn) {
1052
1021
  throw new Error(
1053
1022
  `Flag "${flagName}" was specified to control routing for path group "${pathGroup.group}" in application ${application.name} but not found in provided flag values.`