@vercel/microfrontends 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/bin/cli.cjs +1604 -221
- package/dist/config/client.d.ts +1 -1
- package/dist/config/edge.cjs +47 -47
- package/dist/config/edge.cjs.map +1 -1
- package/dist/config/edge.d.ts +6 -6
- package/dist/config/edge.js +46 -46
- package/dist/config/edge.js.map +1 -1
- package/dist/config.cjs +67 -66
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +66 -65
- package/dist/config.js.map +1 -1
- package/dist/{index-eff254d8.d.ts → index-acb44057.d.ts} +12 -23
- package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-983a5139.d.ts} +13 -13
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +86 -87
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +3 -3
- package/dist/next/config.js +85 -86
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +60 -62
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +11 -11
- package/dist/next/middleware.js +58 -60
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +80 -79
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +10 -10
- package/dist/next/testing.js +80 -79
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +9 -9
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +2 -2
- package/dist/overrides.js +9 -9
- package/dist/overrides.js.map +1 -1
- package/dist/{schema-83a75e61.d.ts → schema-2922d49e.d.ts} +1 -7
- package/dist/{types-4fd1c7c6.d.ts → types-7b1cd9f7.d.ts} +1 -7
- package/dist/types-c3d15d04.d.ts +15 -0
- package/dist/v2/config.cjs +39 -39
- package/dist/v2/config.cjs.map +1 -1
- package/dist/v2/config.d.ts +3 -2
- package/dist/v2/config.js +38 -38
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +223 -96
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +11 -3
- package/dist/v2/microfrontends/server.js +223 -96
- package/dist/v2/microfrontends/server.js.map +1 -1
- package/dist/v2/microfrontends.cjs +44 -44
- package/dist/v2/microfrontends.cjs.map +1 -1
- package/dist/v2/microfrontends.d.ts +6 -5
- package/dist/v2/microfrontends.js +44 -44
- package/dist/v2/microfrontends.js.map +1 -1
- package/dist/v2/next/client.cjs +1 -1
- package/dist/v2/next/client.cjs.map +1 -1
- package/dist/v2/next/client.js +1 -1
- package/dist/v2/next/client.js.map +1 -1
- package/dist/v2/next/config.cjs +247 -122
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.d.ts +4 -4
- package/dist/v2/next/config.js +246 -121
- package/dist/v2/next/config.js.map +1 -1
- package/dist/v2/next/endpoints.cjs +5 -5
- package/dist/v2/next/endpoints.cjs.map +1 -1
- package/dist/v2/next/endpoints.js +5 -5
- package/dist/v2/next/endpoints.js.map +1 -1
- package/dist/v2/next/middleware.cjs +55 -55
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.d.ts +8 -8
- package/dist/v2/next/middleware.js +53 -53
- package/dist/v2/next/middleware.js.map +1 -1
- package/dist/v2/overrides.cjs +75 -0
- package/dist/v2/overrides.cjs.map +1 -0
- package/dist/v2/overrides.d.ts +24 -0
- package/dist/v2/overrides.js +45 -0
- package/dist/v2/overrides.js.map +1 -0
- package/dist/v2/schema.cjs.map +1 -1
- package/dist/v2/schema.d.ts +1 -1
- package/dist/validation.cjs +20 -28
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +2 -8
- package/dist/validation.js +20 -28
- package/dist/validation.js.map +1 -1
- package/package.json +15 -7
- package/schema/schema-v2.json +0 -4
- package/schema/schema.json +0 -4
package/dist/next/middleware.js
CHANGED
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
3
|
import { pathToRegexp } from "path-to-regexp";
|
|
4
4
|
|
|
5
|
-
// src/config/edge/
|
|
5
|
+
// src/config/edge/microfrontend-config.ts
|
|
6
6
|
import { parse } from "jsonc-parser";
|
|
7
7
|
|
|
8
8
|
// src/config/errors.ts
|
|
9
|
-
var
|
|
9
|
+
var MicrofrontendError = class extends Error {
|
|
10
10
|
constructor(message, opts) {
|
|
11
11
|
super(message);
|
|
12
|
-
this.name = "
|
|
13
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
12
|
+
this.name = "MicrofrontendsError";
|
|
13
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
14
14
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
15
15
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
16
|
-
Error.captureStackTrace(this,
|
|
16
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
17
17
|
}
|
|
18
18
|
isKnown() {
|
|
19
19
|
return this.type !== "unknown";
|
|
@@ -22,13 +22,13 @@ var MicroFrontendError = class extends Error {
|
|
|
22
22
|
return !this.isKnown();
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Converts an error to a
|
|
25
|
+
* Converts an error to a MicrofrontendsError.
|
|
26
26
|
* @param original - The original error to convert.
|
|
27
|
-
* @returns The converted
|
|
27
|
+
* @returns The converted MicrofrontendsError.
|
|
28
28
|
*/
|
|
29
29
|
static convert(original, opts) {
|
|
30
30
|
if (opts == null ? void 0 : opts.fileName) {
|
|
31
|
-
const err =
|
|
31
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
32
32
|
if (err) {
|
|
33
33
|
return err;
|
|
34
34
|
}
|
|
@@ -36,25 +36,25 @@ var MicroFrontendError = class extends Error {
|
|
|
36
36
|
if (original.message.includes(
|
|
37
37
|
"Code generation from strings disallowed for this context"
|
|
38
38
|
)) {
|
|
39
|
-
return new
|
|
39
|
+
return new MicrofrontendError(original.message, {
|
|
40
40
|
type: "config",
|
|
41
41
|
subtype: "unsupported_validation_env",
|
|
42
42
|
source: "ajv"
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
-
return new
|
|
45
|
+
return new MicrofrontendError(original.message);
|
|
46
46
|
}
|
|
47
47
|
static convertFSError(original, fileName) {
|
|
48
48
|
if (original instanceof Error && "code" in original) {
|
|
49
49
|
if (original.code === "ENOENT") {
|
|
50
|
-
return new
|
|
50
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
51
51
|
type: "config",
|
|
52
52
|
subtype: "unable_to_read_file",
|
|
53
53
|
source: "fs"
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
if (original.code === "EACCES") {
|
|
57
|
-
return new
|
|
57
|
+
return new MicrofrontendError(
|
|
58
58
|
`Permission denied while accessing "${fileName}"`,
|
|
59
59
|
{
|
|
60
60
|
type: "config",
|
|
@@ -65,7 +65,7 @@ var MicroFrontendError = class extends Error {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (original instanceof SyntaxError) {
|
|
68
|
-
return new
|
|
68
|
+
return new MicrofrontendError(
|
|
69
69
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
70
70
|
{
|
|
71
71
|
type: "config",
|
|
@@ -77,23 +77,23 @@ var MicroFrontendError = class extends Error {
|
|
|
77
77
|
return null;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Handles an unknown error and returns a
|
|
80
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
81
81
|
* @param err - The error to handle.
|
|
82
|
-
* @returns A
|
|
82
|
+
* @returns A MicrofrontendsError instance.
|
|
83
83
|
*/
|
|
84
84
|
static handle(err, opts) {
|
|
85
|
-
if (err instanceof
|
|
85
|
+
if (err instanceof MicrofrontendError) {
|
|
86
86
|
return err;
|
|
87
87
|
}
|
|
88
88
|
if (err instanceof Error) {
|
|
89
|
-
return
|
|
89
|
+
return MicrofrontendError.convert(err, opts);
|
|
90
90
|
}
|
|
91
91
|
if (typeof err === "object" && err !== null) {
|
|
92
92
|
if ("message" in err && typeof err.message === "string") {
|
|
93
|
-
return
|
|
93
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
return new
|
|
96
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
|
|
@@ -176,27 +176,27 @@ var _Overrides = class {
|
|
|
176
176
|
});
|
|
177
177
|
return overridesConfig;
|
|
178
178
|
}
|
|
179
|
-
static validOverrideDomainsForZone(
|
|
179
|
+
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
180
180
|
var _a, _b, _c, _d, _e;
|
|
181
|
-
const projectName = (_a =
|
|
181
|
+
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
182
182
|
if (!projectName) {
|
|
183
|
-
return [
|
|
183
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
184
184
|
}
|
|
185
185
|
const parsedProjectName = makeUrlSafe(projectName);
|
|
186
|
-
const previewDeploymentSuffix = (_c = (_b =
|
|
187
|
-
const teamSlug = (_e = (_d =
|
|
186
|
+
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
187
|
+
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
188
188
|
if (!teamSlug && !previewDeploymentSuffix) {
|
|
189
|
-
return [
|
|
189
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
190
190
|
}
|
|
191
191
|
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
192
192
|
return [
|
|
193
193
|
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
194
|
-
|
|
194
|
+
microfrontendConfig.getZone(zone).production.host
|
|
195
195
|
];
|
|
196
196
|
}
|
|
197
|
-
static validateOverrideDomain(
|
|
197
|
+
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
198
198
|
return new RegExp(
|
|
199
|
-
`^${_Overrides.validOverrideDomainsForZone(
|
|
199
|
+
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
200
200
|
"|"
|
|
201
201
|
)}$`
|
|
202
202
|
).test(domain);
|
|
@@ -278,7 +278,7 @@ var Application = class {
|
|
|
278
278
|
static validate(name, app) {
|
|
279
279
|
var _a, _b, _c, _d, _e;
|
|
280
280
|
if (((_b = (_a = app.routing) == null ? void 0 : _a.assetPrefix) == null ? void 0 : _b.startsWith("/")) || ((_d = (_c = app.routing) == null ? void 0 : _c.assetPrefix) == null ? void 0 : _d.endsWith("/"))) {
|
|
281
|
-
throw new
|
|
281
|
+
throw new MicrofrontendError(
|
|
282
282
|
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
283
283
|
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
284
284
|
);
|
|
@@ -289,13 +289,13 @@ var Application = class {
|
|
|
289
289
|
continue;
|
|
290
290
|
}
|
|
291
291
|
if (p.endsWith("/")) {
|
|
292
|
-
throw new
|
|
292
|
+
throw new MicrofrontendError(
|
|
293
293
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
294
294
|
{ type: "zone", subtype: "invalid_path" }
|
|
295
295
|
);
|
|
296
296
|
}
|
|
297
297
|
if (!p.startsWith("/")) {
|
|
298
|
-
throw new
|
|
298
|
+
throw new MicrofrontendError(
|
|
299
299
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
300
300
|
{ type: "zone", subtype: "invalid_path" }
|
|
301
301
|
);
|
|
@@ -329,10 +329,10 @@ var Application = class {
|
|
|
329
329
|
}
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
-
// src/config/common/
|
|
332
|
+
// src/config/common/microfrontend-config.ts
|
|
333
333
|
var SUPPORTED_VERSIONS = ["1"];
|
|
334
334
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
335
|
-
var
|
|
335
|
+
var MicrofrontendConfigCommon = class {
|
|
336
336
|
constructor({
|
|
337
337
|
config,
|
|
338
338
|
overrides
|
|
@@ -340,7 +340,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
340
340
|
this.zones = {};
|
|
341
341
|
var _a, _b, _c;
|
|
342
342
|
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
343
|
-
throw new
|
|
343
|
+
throw new MicrofrontendError(
|
|
344
344
|
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
345
345
|
", "
|
|
346
346
|
)}`,
|
|
@@ -368,7 +368,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
368
368
|
static getConfigFromEnv() {
|
|
369
369
|
const config = process.env.MFE_CONFIG;
|
|
370
370
|
if (!config) {
|
|
371
|
-
throw new
|
|
371
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
372
372
|
type: "config",
|
|
373
373
|
subtype: "not_found_in_env"
|
|
374
374
|
});
|
|
@@ -387,8 +387,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
387
387
|
getZone(name) {
|
|
388
388
|
const zone = this.zones[name];
|
|
389
389
|
if (!zone) {
|
|
390
|
-
throw new
|
|
391
|
-
`Could not find
|
|
390
|
+
throw new MicrofrontendError(
|
|
391
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
392
392
|
{
|
|
393
393
|
type: "zone",
|
|
394
394
|
subtype: "not_found"
|
|
@@ -408,8 +408,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
408
408
|
getDefaultZone() {
|
|
409
409
|
const zone = Object.values(this.zones).find((z) => z.default);
|
|
410
410
|
if (!zone) {
|
|
411
|
-
throw new
|
|
412
|
-
`Could not find default zone in
|
|
411
|
+
throw new MicrofrontendError(
|
|
412
|
+
`Could not find default zone in microfrontends configuration`,
|
|
413
413
|
{
|
|
414
414
|
type: "zone",
|
|
415
415
|
subtype: "not_found"
|
|
@@ -461,20 +461,20 @@ var MicroFrontendConfigCommon = class {
|
|
|
461
461
|
};
|
|
462
462
|
}
|
|
463
463
|
write(_) {
|
|
464
|
-
throw new
|
|
465
|
-
`Writing to file to disk requires using an instance of "
|
|
464
|
+
throw new MicrofrontendError(
|
|
465
|
+
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
466
466
|
{ type: "config", subtype: "unsupported_operation" }
|
|
467
467
|
);
|
|
468
468
|
}
|
|
469
469
|
};
|
|
470
470
|
|
|
471
|
-
// src/config/edge/
|
|
472
|
-
var
|
|
471
|
+
// src/config/edge/microfrontend-config.ts
|
|
472
|
+
var MicrofrontendConfigEdge = class extends MicrofrontendConfigCommon {
|
|
473
473
|
static fromEnv({
|
|
474
474
|
cookies
|
|
475
475
|
}) {
|
|
476
|
-
return new
|
|
477
|
-
config: parse(
|
|
476
|
+
return new MicrofrontendConfigCommon({
|
|
477
|
+
config: parse(MicrofrontendConfigCommon.getConfigFromEnv()),
|
|
478
478
|
overrides: Overrides.parseOverrides(cookies)
|
|
479
479
|
});
|
|
480
480
|
}
|
|
@@ -543,7 +543,7 @@ async function verifyPreviewDomain(req, rewriteDomain) {
|
|
|
543
543
|
const vercelError = previewResponse.headers.get("x-vercel-error");
|
|
544
544
|
return !(previewResponse.status === 404 && (vercelError === "DEPLOYMENT_NOT_FOUND" || vercelError === "NOT_FOUND"));
|
|
545
545
|
}
|
|
546
|
-
function
|
|
546
|
+
function microfrontendInternalRoutingHandler({
|
|
547
547
|
config
|
|
548
548
|
}) {
|
|
549
549
|
return async (req) => {
|
|
@@ -558,10 +558,8 @@ function microFrontendInternalRoutingHandler({
|
|
|
558
558
|
if (!isPreviewDomainAvailable) {
|
|
559
559
|
rewriteDomain = application.production.toString();
|
|
560
560
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
{ routing: { host: rewriteDomain } }
|
|
564
|
-
];
|
|
561
|
+
const url = new URL(rewriteDomain);
|
|
562
|
+
return [application.name, { routing: { host: url.host } }];
|
|
565
563
|
})
|
|
566
564
|
)
|
|
567
565
|
);
|
|
@@ -654,18 +652,18 @@ function getHandler({
|
|
|
654
652
|
}
|
|
655
653
|
};
|
|
656
654
|
}
|
|
657
|
-
function
|
|
655
|
+
function getMicrofrontendsMiddleware({
|
|
658
656
|
request,
|
|
659
657
|
flagValues
|
|
660
658
|
}) {
|
|
661
|
-
var _a, _b
|
|
662
|
-
const config =
|
|
659
|
+
var _a, _b;
|
|
660
|
+
const config = MicrofrontendConfigEdge.fromEnv({
|
|
663
661
|
cookies: request.cookies.getAll()
|
|
664
662
|
});
|
|
665
663
|
const middlewares = [];
|
|
666
664
|
middlewares.push({
|
|
667
665
|
src: "/.well-known/vercel/microfrontend-routing",
|
|
668
|
-
fn:
|
|
666
|
+
fn: microfrontendInternalRoutingHandler({ config })
|
|
669
667
|
});
|
|
670
668
|
for (const application of config.getAllApplications()) {
|
|
671
669
|
if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
|
|
@@ -685,8 +683,8 @@ function getMicroFrontendsMiddleware({
|
|
|
685
683
|
});
|
|
686
684
|
}
|
|
687
685
|
for (const pathGroup of application.routing.matches) {
|
|
688
|
-
if (process.env.VERCEL_ENV === "preview" || ((_a = pathGroup.options) == null ? void 0 : _a.flag)
|
|
689
|
-
const flagName = (
|
|
686
|
+
if (process.env.VERCEL_ENV === "preview" || ((_a = pathGroup.options) == null ? void 0 : _a.flag)) {
|
|
687
|
+
const flagName = (_b = pathGroup.options) == null ? void 0 : _b.flag;
|
|
690
688
|
let flagFn;
|
|
691
689
|
if (flagName) {
|
|
692
690
|
flagFn = flagValues == null ? void 0 : flagValues[flagName];
|
|
@@ -713,9 +711,9 @@ function getMicroFrontendsMiddleware({
|
|
|
713
711
|
}
|
|
714
712
|
return middlewares;
|
|
715
713
|
}
|
|
716
|
-
async function
|
|
714
|
+
async function runMicrofrontendsMiddleware(request, flagValues) {
|
|
717
715
|
const pathname = request.nextUrl.pathname;
|
|
718
|
-
const middlewares =
|
|
716
|
+
const middlewares = getMicrofrontendsMiddleware({
|
|
719
717
|
request,
|
|
720
718
|
flagValues
|
|
721
719
|
});
|
|
@@ -729,7 +727,7 @@ async function runMicroFrontendsMiddleware(request, flagValues) {
|
|
|
729
727
|
}
|
|
730
728
|
}
|
|
731
729
|
export {
|
|
732
|
-
|
|
733
|
-
|
|
730
|
+
getMicrofrontendsMiddleware,
|
|
731
|
+
runMicrofrontendsMiddleware
|
|
734
732
|
};
|
|
735
733
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/middleware/middleware.ts","../../src/config/edge/micro-frontend-config.ts","../../src/config/errors.ts","../../src/routing/url.ts","../../src/config/overrides/config.ts","../../src/config/common/host.ts","../../src/config/common/application.ts","../../src/config/common/micro-frontend-config.ts","../../src/routing/get-domain-for-current-environment.ts"],"sourcesContent":["/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicroFrontendConfigEdge } from '../../config/edge/micro-frontend-config';\nimport { getDomainForCurrentEnvironment } from '../../routing/get-domain-for-current-environment';\nimport type { Application } from '../../config/common/application';\nimport type { HostConfig } from '../../config/schema';\nimport type {\n MicroFrontendsMiddleware,\n MicroFrontendsMiddlewareHandler,\n} from './types';\n\ninterface GetHandlerParams {\n application: Application;\n flagFn?: () => Promise<boolean>;\n pattern: RegExp;\n}\n\ninterface InternalRouting {\n routing: HostConfig;\n}\n\nasync function verifyPreviewDomain(\n req: NextRequest,\n rewriteDomain: string,\n): Promise<boolean> {\n const jwtCookie = req.cookies.get('_vercel_jwt')?.value;\n const deploymentProtectionBypassHeader = req.headers.get(\n 'x-vercel-protection-bypass',\n );\n\n // We make a `HEAD` request with `x-vercel-micro-frontends-check: 1` which will get handled in the proxy without reaching the deployment\n const previewResponse = await fetch(rewriteDomain, {\n method: 'HEAD',\n headers: {\n 'x-vercel-micro-frontends-check': '1',\n ...(jwtCookie ? { cookie: `_vercel_jwt=${jwtCookie}` } : {}),\n ...(deploymentProtectionBypassHeader\n ? {\n 'x-vercel-protection-bypass': deploymentProtectionBypassHeader,\n }\n : {}),\n },\n });\n\n const vercelError = previewResponse.headers.get('x-vercel-error');\n return !(\n previewResponse.status === 404 &&\n (vercelError === 'DEPLOYMENT_NOT_FOUND' || vercelError === 'NOT_FOUND')\n );\n}\n\nfunction microFrontendInternalRoutingHandler({\n config,\n}: { config: MicroFrontendConfigEdge }): MicroFrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse> => {\n const payload: Record<string, InternalRouting> = Object.fromEntries(\n await Promise.all(\n config.getAllApplications().map(async (application) => {\n let rewriteDomain = getDomainForCurrentEnvironment(application);\n const isPreviewDomainAvailable = await verifyPreviewDomain(\n req,\n rewriteDomain,\n );\n\n if (!isPreviewDomainAvailable) {\n rewriteDomain = application.production.toString();\n }\n\n return [\n application.name,\n { routing: { host: rewriteDomain } },\n ] as const;\n }),\n ),\n );\n\n return NextResponse.json(payload);\n };\n}\n\nfunction getHandler({\n application,\n flagFn,\n pattern,\n}: GetHandlerParams): MicroFrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse | undefined> => {\n const pathname = req.nextUrl.pathname;\n const search = req.nextUrl.search;\n\n let rewriteDomain = getDomainForCurrentEnvironment(application);\n const patchedHeaders = new Headers(req.headers);\n\n const responseCallbacks: ((response: NextResponse) => void)[] = [];\n const onRewrite: (response: NextResponse) => NextResponse = (response) => {\n for (const callback of responseCallbacks) {\n callback(response);\n }\n\n return response;\n };\n\n // If this is a preview environment, we check the domain to make sure the project was deployed\n if (process.env.VERCEL_ENV === 'preview' && rewriteDomain) {\n const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;\n const assetPrefix = application.routing?.assetPrefix;\n\n if (\n assetPrefix &&\n pathname.startsWith(`/${assetPrefix}`) &&\n req.cookies.get(zoneFallbackCookieName)?.value === '1'\n ) {\n // If this is an asset request and we have the cookie, we can safely route to production without fetching\n rewriteDomain = application.production.toString();\n } else {\n try {\n let deploymentFound: boolean;\n if (req.headers.get('x-vercel-skip-deployment-existence-check')) {\n deploymentFound = true;\n } else {\n deploymentFound = await verifyPreviewDomain(req, rewriteDomain);\n }\n\n if (!deploymentFound) {\n // If the deployment is not found, we rewrite to the production domain\n rewriteDomain = application.production.toString();\n\n // We set a 1 minute cookie for the application to avoid checking again for every request\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '1', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 60, // 1 minute\n });\n });\n\n // When routing to a production url, we need to enable the toolbar manually,\n // since production deployments rely on the extension to do that, but the extension can't match the top-level domain\n try {\n const existingCookie = patchedHeaders.get('cookie');\n\n // If the request doesn't contain the toolbar cookie, we add it to support the middleware injection\n if (!existingCookie?.includes('__vercel_toolbar')) {\n patchedHeaders.set(\n 'cookie',\n [`__vercel_toolbar=1`, existingCookie].join('; '),\n );\n\n // We also return a `set-cookie` header to set the cookie locally, to support the Next.js injection which checks the document\n responseCallbacks.push((response) => {\n response.cookies.set('__vercel_toolbar', '1', {\n httpOnly: false,\n sameSite: 'lax',\n secure: true,\n maxAge: 29030400,\n });\n });\n }\n } catch (error) {\n // Do Nothing\n }\n } else if (req.cookies.get(zoneFallbackCookieName)?.value === '1') {\n // If the preview exists and we have the fallback cookie, we make sure to clear the cookie to route subsequent assets to the preview\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 0,\n });\n });\n }\n } catch {\n // Do Nothing\n }\n }\n }\n\n const isFlagEnabled = async (): Promise<boolean> =>\n flagFn ? flagFn() : true;\n\n // If the pattern doesn't match, we don't need to execute the flag\n if (pattern.test(pathname) && (await isFlagEnabled())) {\n return onRewrite(\n NextResponse.rewrite(`${rewriteDomain}${pathname}${search}`, {\n request: {\n headers: patchedHeaders,\n },\n }),\n );\n }\n };\n // If the path does not match the pattern, we don't do anything and let the request continue\n}\n\n/**\n * Returns an array of middleware functions that will handle routing to the\n * right micro-frontends for the provided configuration.\n *\n * @param config - The micro-frontends configuration object.\n * @param flagValues - An object that maps flag names to functions that return the flag value.\n */\nexport function getMicroFrontendsMiddleware({\n request,\n flagValues,\n}: {\n request: NextRequest;\n flagValues?: Record<string, () => Promise<boolean>>;\n}): MicroFrontendsMiddleware[] {\n const config = MicroFrontendConfigEdge.fromEnv({\n cookies: request.cookies.getAll(),\n });\n const middlewares: MicroFrontendsMiddleware[] = [];\n\n middlewares.push({\n src: '/.well-known/vercel/microfrontend-routing',\n fn: microFrontendInternalRoutingHandler({ config }),\n });\n\n for (const application of config.getAllApplications()) {\n if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {\n continue;\n }\n if (application.routing) {\n if (\n process.env.VERCEL_ENV === 'preview' &&\n application.routing.assetPrefix\n ) {\n const pattern = pathToRegexp(\n `/${application.routing.assetPrefix}/:path+`,\n );\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n pattern,\n }),\n });\n }\n for (const pathGroup of application.routing.matches) {\n if (\n process.env.VERCEL_ENV === 'preview' ||\n pathGroup.options?.flag ||\n pathGroup.options?.routeToDefaultApplication\n ) {\n const flagName = pathGroup.options?.flag;\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let flagFn;\n if (flagName) {\n flagFn = flagValues?.[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${application.name} but not found in provided flag values.`,\n );\n }\n }\n for (const path of pathGroup.paths) {\n const pattern = pathToRegexp(path);\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n flagFn,\n pattern,\n }),\n });\n }\n }\n }\n }\n }\n return middlewares;\n}\n\n/**\n * Executes the middlewares returned by `getMicroFrontendsMiddleware` and\n * returns a `Response` if any of the micro-frontends middlewares match or\n * `undefined` if none match. If a `Response` object is returned, the calling\n * code should return that Response from the Next.js middleware in order to\n * stop execution of the middleware and perform the rewrite.\n */\nexport async function runMicroFrontendsMiddleware(\n request: NextRequest,\n flagValues?: Record<string, () => Promise<boolean>>,\n): Promise<Response | undefined> {\n const pathname = request.nextUrl.pathname;\n const middlewares = getMicroFrontendsMiddleware({\n request,\n flagValues,\n });\n\n for (const mware of middlewares) {\n if (\n typeof mware.src === 'string'\n ? pathname === mware.src\n : mware.src.test(pathname)\n ) {\n // eslint-disable-next-line no-await-in-loop\n const response = await mware.fn(request);\n if (response) {\n return response;\n }\n }\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport { parse } from 'jsonc-parser';\nimport { MicroFrontendConfigCommon } from '../common/micro-frontend-config';\nimport type { Config } from '../schema';\nimport { Overrides } from '../overrides';\n\n/**\n * Edge Runtime does not support ajv validation, or fs access.\n * This version of the MicroFrontendConfig does not validate the config shape,\n * and requires the config to be set on the environment.\n *\n * It should be used for Next.js middleware which runs in the Edge Runtime.\n */\nexport class MicroFrontendConfigEdge extends MicroFrontendConfigCommon {\n static fromEnv({\n cookies,\n }: {\n cookies: { name: string; value: string }[];\n }): MicroFrontendConfigEdge {\n return new MicroFrontendConfigCommon({\n config: parse(MicroFrontendConfigCommon.getConfigFromEnv()) as Config,\n overrides: Overrides.parseOverrides(cookies),\n });\n }\n}\n","export type MicroFrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'zone'\n | 'unknown';\n\nexport type MicroFrontendErrorSubtype =\n | 'not_found'\n | 'not_found_in_env'\n | 'invalid_asset_prefix'\n | 'invalid_main_path'\n | 'does_not_match_schema'\n | 'unable_to_read_file'\n | 'unsupported_validation_env'\n | 'unsupported_version'\n | 'invalid_path'\n | 'invalid_permissions'\n | 'invalid_syntax'\n | 'missing_microFrontend_config_path'\n | 'unsupported_operation';\n\n// A mapping of error types to their subtypes.\ninterface TypeToSubtype {\n zone:\n | 'invalid_asset_prefix'\n | 'invalid_path'\n | 'multiple_package_managers'\n | 'not_found';\n config:\n | 'conflicting_paths'\n | 'does_not_match_schema'\n | 'invalid_main_path'\n | 'invalid_preview_deployment_suffix'\n | 'multiple_default_applications'\n | 'no_default_application'\n | 'not_found_in_env'\n | 'not_found'\n | 'unable_to_read_file'\n | 'invalid_syntax'\n | 'invalid_permissions'\n | 'unsupported_operation'\n | 'unsupported_validation_env'\n | 'unsupported_version';\n packageJson:\n | 'missing_field_name'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n vercelJson:\n | 'missing_field_microFrontend_config_path'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n unknown: never;\n}\n\nexport type MicroFrontendErrorSource =\n | '@vercel/micro-frontends'\n | '@vercel/micro-frontends/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/micro-frontends';\n this.type = opts?.type ?? ('unknown' as T);\n this.subtype = opts?.subtype;\n Error.captureStackTrace(this, MicroFrontendError);\n }\n\n isKnown(): boolean {\n return this.type !== 'unknown';\n }\n\n isUnknown(): boolean {\n return !this.isKnown();\n }\n\n /**\n * Converts an error to a MicroFrontendsError.\n * @param original - The original error to convert.\n * @returns The converted MicroFrontendsError.\n */\n static convert(\n original: Error,\n opts?: HandleOptions,\n ): MicroFrontendError<MicroFrontendErrorType> {\n if (opts?.fileName) {\n const err = MicroFrontendError.convertFSError(original, opts.fileName);\n if (err) {\n return err;\n }\n }\n\n if (\n original.message.includes(\n 'Code generation from strings disallowed for this context',\n )\n ) {\n return new MicroFrontendError(original.message, {\n type: 'config',\n subtype: 'unsupported_validation_env',\n source: 'ajv',\n });\n }\n\n // unknown catch-all\n return new MicroFrontendError(original.message);\n }\n\n static convertFSError(\n original: Error,\n fileName: string,\n ): MicroFrontendError<MicroFrontendErrorType> | null {\n if (original instanceof Error && 'code' in original) {\n if (original.code === 'ENOENT') {\n return new MicroFrontendError(`Could not find \"${fileName}\"`, {\n type: 'config',\n subtype: 'unable_to_read_file',\n source: 'fs',\n });\n }\n if (original.code === 'EACCES') {\n return new MicroFrontendError(\n `Permission denied while accessing \"${fileName}\"`,\n {\n type: 'config',\n subtype: 'invalid_permissions',\n source: 'fs',\n },\n );\n }\n }\n\n if (original instanceof SyntaxError) {\n return new MicroFrontendError(\n `Failed to parse \"${fileName}\": Invalid JSON format.`,\n {\n type: 'config',\n subtype: 'invalid_syntax',\n source: 'fs',\n },\n );\n }\n\n return null;\n }\n\n /**\n * Handles an unknown error and returns a MicroFrontendsError instance.\n * @param err - The error to handle.\n * @returns A MicroFrontendsError instance.\n */\n static handle(\n err: unknown,\n opts?: HandleOptions,\n ): MicroFrontendError<MicroFrontendErrorType> {\n if (err instanceof MicroFrontendError) {\n return err as MicroFrontendError<MicroFrontendErrorType>;\n }\n\n // handle Error instances\n if (err instanceof Error) {\n return MicroFrontendError.convert(err, opts);\n }\n\n // handle object errors\n if (typeof err === 'object' && err !== null) {\n if ('message' in err && typeof err.message === 'string') {\n return MicroFrontendError.convert(new Error(err.message), opts);\n }\n }\n\n return new MicroFrontendError('An unknown error occurred');\n }\n}\n","// NOTE: This is copied from https://github.com/vercel/api/blob/main/packages/util-func/src/url-safe-string.ts.\n// See https://linear.app/vercel/issue/FDRTN-199/spike-move-preview-domain-generation-logic-into-build-and-deploy\n// for cleaning this up before release.\n\ninterface Options {\n joinString?: string;\n lowercaseOnly?: boolean;\n maxLen?: number;\n regexRemovePattern?: RegExp;\n trimWhitespace?: boolean;\n}\n\n/**\n * This function allows to convert single string to URL-safe tags to use for routing,\n * SEO purposes, etc. It is taken from https://www.npmjs.com/package/url-safe-string\n * and implemented here to be typed and skip the dependency.\n */\nfunction buildUrlSafeString(givenOpts: Options = {}): {\n generate: (...args: string[]) => string;\n} {\n const options = {\n joinString: '-',\n lowercaseOnly: true,\n maxLen: 100,\n regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,\n trimWhitespace: true,\n ...givenOpts,\n };\n\n return {\n generate: (...args: string[]) => {\n const reJoinString = new RegExp(`${options.joinString}+`, 'g');\n\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let tag;\n\n if (args.length === 0) {\n throw new Error('generate method must be passed at least one argument');\n }\n\n // Validate, trim all arguments:\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (typeof arg !== 'string')\n throw new Error('all supplied arguments must be Strings');\n\n if (options.trimWhitespace) {\n args[i] = arg.trim();\n }\n }\n\n // Join strings and convert whitespace between words to join string\n tag = args.join(options.joinString);\n tag = tag.replace(/\\s/g, options.joinString);\n if (options.lowercaseOnly) tag = tag.toLowerCase();\n // Regex away anything \"unsafe\", but ignore the join string!\n tag = tag.replace(options.regexRemovePattern, (match) => {\n if (match === options.joinString) return match;\n\n return '';\n });\n\n // Truncate in excess of maxLen\n if (tag.length > options.maxLen) tag = tag.substring(0, options.maxLen);\n\n // Remove any duplicates of the join string using this pattern: /<join string>+/g\n tag = tag.replace(reJoinString, options.joinString);\n\n return tag;\n },\n };\n}\n\n/**\n * Export a preconfigured version for convenience.\n */\nexport const urlSafeString = buildUrlSafeString().generate;\n\nexport function makeUrlSafe(name: string): string {\n return urlSafeString(name.replace(/\\//g, '-'))\n .replace(/^-*/g, '')\n .replace(/-*$/g, '');\n}\n","import { makeUrlSafe } from '../../routing/url';\nimport type { MicroFrontendConfig } from '../micro-frontend-config';\nimport type { OverridesConfig } from './types';\n\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\n\nexport class Overrides {\n config: OverridesConfig;\n\n constructor(config: OverridesConfig) {\n this.config = config;\n }\n\n static overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n\n static getAppEnvOverrideCookieName(zone: string): string {\n return `${Overrides.overrideEnvCookiePrefix}${zone}`;\n }\n\n static isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n }\n\n static getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n }): { zone: string; host: string } | undefined {\n if (!Overrides.isOverrideCookie(cookie) || !cookie.value) return;\n return {\n zone: cookie.name.replace(Overrides.overrideEnvCookiePrefix, ''),\n host: cookie.value,\n };\n }\n\n static parseOverrides(\n cookies: { name: string; value?: string | null }[],\n ): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = Overrides.getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.zone] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n }\n\n static validOverrideDomainsForZone(\n microFrontendConfig: MicroFrontendConfig,\n zone: string,\n ): string[] {\n const projectName = microFrontendConfig.getZone(zone).vercel?.projectName;\n if (!projectName) {\n return [microFrontendConfig.getZone(zone).production.host];\n }\n const parsedProjectName = makeUrlSafe(projectName);\n const previewDeploymentSuffix =\n microFrontendConfig.options?.vercel?.previewDeploymentSuffix;\n const teamSlug = microFrontendConfig.options?.vercel?.teamSlug;\n if (!teamSlug && !previewDeploymentSuffix) {\n return [microFrontendConfig.getZone(zone).production.host];\n }\n\n const suffix = previewDeploymentSuffix\n ? `.${previewDeploymentSuffix}`\n : `-${teamSlug}.vercel.app`;\n\n // <project-name>-git-<branch-name>-<scope-slug>.vercel.app\n // <project-name>-git-<branch-name>.<custom-suffix>\n return [\n `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,\n microFrontendConfig.getZone(zone).production.host,\n ];\n }\n\n static validateOverrideDomain(\n microFrontendConfig: MicroFrontendConfig,\n zone: string,\n domain: string,\n ): boolean {\n return new RegExp(\n `^${Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(\n '|',\n )}$`,\n ).test(domain);\n }\n\n serialize(): OverridesConfig {\n return this.config;\n }\n}\n","import type { HostConfig } from '../schema';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: HostConfig['host'];\n port: number;\n serialized: HostConfig;\n\n constructor({ protocol, host, port }: HostConfig) {\n this.protocol = protocol || 'https';\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.serialized = {\n protocol,\n host,\n ...(port ? { port } : undefined),\n };\n }\n\n isLocal(): boolean {\n return this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: { protocol: HostConfig['protocol']; port?: HostConfig['port'] }): number {\n if (!port) {\n if (protocol === 'http') {\n return 80;\n }\n return 443;\n }\n\n return port;\n }\n\n isDefaultPort(): boolean {\n return this.port === Host.getPort({ protocol: this.protocol });\n }\n\n toString(opts: HostDisplayOptions = {}): string {\n const url = this.toUrl(opts);\n // strip the trailing slash\n return url.toString().replace(/\\/$/, '');\n }\n\n toUrl(opts: HostDisplayOptions = {}): URL {\n const { includeDefaultPort } = opts;\n const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? '' : `:${this.port}`}`;\n\n return new URL(url);\n }\n\n serialize(): HostConfig {\n return this.serialized;\n }\n}\n","import type { ApplicationConfig, Routing, Vercel } from '../schema';\nimport type { ApplicationOverrideConfig } from '../overrides';\nimport { MicroFrontendError } from '../errors';\nimport { Host } from './host';\n\nexport class Application {\n default: boolean;\n routing?: Routing;\n name: string;\n development: {\n local: Host;\n fallback?: Host;\n };\n production: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: { app: ApplicationConfig; overrides?: ApplicationOverrideConfig },\n ) {\n // validate\n Application.validate(name, app);\n\n this.name = name;\n this.default = app.default;\n this.routing = app.routing;\n this.development = {\n local: new Host(app.development.local),\n fallback: app.development.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = new Host(app.production);\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n static validate(name: string, app: ApplicationConfig): void {\n // validate assetPrefix\n if (\n app.routing?.assetPrefix?.startsWith('/') ||\n app.routing?.assetPrefix?.endsWith('/')\n ) {\n throw new MicroFrontendError(\n `Invalid assetPrefix for application \"${name}\". Must not start or end with a slash.`,\n { type: 'zone', subtype: 'invalid_asset_prefix' },\n );\n }\n\n // validate routes\n for (const group of app.routing?.matches ?? []) {\n for (const p of group.paths) {\n if (p === '/') {\n continue;\n }\n if (p.endsWith('/')) {\n throw new MicroFrontendError(\n `Invalid path for application \"${name}\". ${p} must not end with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n\n if (!p.startsWith('/')) {\n throw new MicroFrontendError(\n `Invalid path for application \"${name}\". ${p} must start with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n }\n }\n }\n\n serialize(): ApplicationConfig {\n if (this.routing === undefined || this.default) {\n return {\n default: true,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n\n return {\n default: false,\n routing: this.routing,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n}\n","import type { ApplicationConfig, Config, Options } from '../schema';\nimport { MicroFrontendError } from '../errors';\nimport type { OverridesConfig } from '../overrides';\nimport { Overrides } from '../overrides/config';\nimport { Application } from './application';\n\nconst SUPPORTED_VERSIONS = ['1'];\nconst DEFAULT_LOCAL_PROXY_PORT = 3024;\n\n/**\n * A class to manage the micro-frontends configuration.\n *\n * This class should not be used directly. Instead, use the `MicroFrontendConfig` or `MicroFrontendConfigEdgeRuntime` classes.\n */\nexport class MicroFrontendConfigCommon {\n config: Config;\n name?: string;\n zones: Record<string, Application> = {};\n version: string;\n overrides?: Overrides;\n options?: Options;\n $schema: string | undefined;\n\n constructor({\n config,\n overrides,\n }: { config: Config; overrides?: OverridesConfig }) {\n if (!SUPPORTED_VERSIONS.includes(config.version)) {\n throw new MicroFrontendError(\n `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n this.overrides =\n overrides && !disableOverrides ? new Overrides(overrides) : undefined;\n\n // create zones\n for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {\n this.zones[zoneName] = new Application(zoneName, {\n app: zoneConfig,\n overrides: !disableOverrides\n ? this.overrides?.config.applications[zoneName]\n : undefined,\n });\n }\n\n this.config = config;\n this.name = config.name;\n this.version = config.version;\n this.options = config.options;\n this.$schema = config.$schema;\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n protected static getConfigFromEnv(): string {\n const config = process.env.MFE_CONFIG;\n if (!config) {\n throw new MicroFrontendError(`Missing \"MFE_CONFIG\" in environment.`, {\n type: 'config',\n subtype: 'not_found_in_env',\n });\n }\n return config;\n }\n\n static fromEnv(_: {\n cookies: { name: string; value: string }[];\n }): MicroFrontendConfigCommon | Promise<MicroFrontendConfigCommon> {\n throw new Error('Not implemented');\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getAllApplications(): Application[] {\n return Object.values(this.zones);\n }\n\n getZone(name: string): Application {\n const zone = this.zones[name];\n if (!zone) {\n throw new MicroFrontendError(\n `Could not find micro-frontends configuration for application \"${name}\"`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n getApplicationByProjectId(projectId: string): Application | undefined {\n return Object.values(this.zones).find(\n (zone) => zone.vercel?.projectId === projectId,\n );\n }\n\n getDefaultZone(): Application {\n const zone = Object.values(this.zones).find((z) => z.default);\n if (!zone) {\n throw new MicroFrontendError(\n `Could not find default zone in micro-frontends configuration`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n /**\n * Returns the configured port for the local proxy\n */\n getLocalProxyPort(): number {\n return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;\n }\n\n /**\n * Serializes the class back to the Schema type.\n *\n * NOTE: This is used when writing the config to disk and must always match the input Schema\n */\n toSchemaJson(): Config {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n $schema: this.$schema,\n name: this.name,\n version: this.version,\n options: this.options,\n applications,\n };\n }\n\n serialize(): { config: Config; overrides?: OverridesConfig } {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n config: {\n name: this.name,\n version: this.version,\n applications,\n options: this.options,\n $schema: this.$schema,\n },\n overrides: this.overrides?.serialize(),\n };\n }\n\n write(_: string): void {\n throw new MicroFrontendError(\n `Writing to file to disk requires using an instance of \"MicroFrontendConfig\".`,\n { type: 'config', subtype: 'unsupported_operation' },\n );\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { Application } from '../config/common/application';\n\nfunction debugDomains(zone: string, env: string, domain: string): void {\n if (process.env.MFE_DEBUG === 'true') {\n const indent = ' '.repeat(4);\n const header = 'domains (zone (env) -> domain)';\n const separator = '⎯'.repeat(header.length);\n const line = `${indent} 1. ${zone} (${env}) -> ${domain}`;\n\n // eslint-disable-next-line no-console\n console.log(`${indent}${header}\\n${indent}${separator}\\n${line}\\n`);\n }\n}\n\n/**\n * Returns the Vercel domain for the given application based on the current\n * environment (local, preview, production).\n */\nexport function getDomainForCurrentEnvironment(zone: Application): string {\n if (zone.overrides?.environment) {\n return zone.overrides.environment.toString();\n }\n const zoneName = zone.name;\n if (!process.env.VERCEL_ENV || process.env.VERCEL_ENV === 'development') {\n // TODO(mknichel): Convert this back to the local development domain once\n // there is local development proxy support.\n const domain =\n process.env.NODE_ENV === 'test'\n ? zone.development.local.toString()\n : zone.production.toString();\n debugDomains(zoneName, 'development', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'production') {\n const domain = zone.production.toString();\n debugDomains(zoneName, 'production', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'preview') {\n const MFE_PREVIEW_DOMAINS = JSON.parse(\n process.env.MFE_PREVIEW_DOMAINS ?? '{}',\n ) as Record<string, string>;\n if (MFE_PREVIEW_DOMAINS[zoneName]) {\n debugDomains(zoneName, 'preview', MFE_PREVIEW_DOMAINS[zoneName]);\n return MFE_PREVIEW_DOMAINS[zoneName];\n }\n\n throw new Error(\n `Could not find preview domain for application \"${zoneName}\"`,\n );\n }\n // TODO(mknichel): Add support in this function for custom environments.\n // Custom Vercel environments may have an arbitrary string for `VERCEL_ENV`.\n debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());\n return zone.production.toString();\n}\n"],"mappings":";AAGA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;;;ACF7B,SAAS,aAAa;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAA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CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAsB,4BACpB,SACA,YAC+B;AAC/B,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,cAAc,4BAA4B;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,aAAW,SAAS,aAAa;AAC/B,QACE,OAAO,MAAM,QAAQ,WACjB,aAAa,MAAM,MACnB,MAAM,IAAI,KAAK,QAAQ,GAC3B;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,OAAO;AACvC,UAAI,UAAU;AACZ,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/middleware/middleware.ts","../../src/config/edge/microfrontend-config.ts","../../src/config/errors.ts","../../src/routing/url.ts","../../src/config/overrides/config.ts","../../src/config/common/host.ts","../../src/config/common/application.ts","../../src/config/common/microfrontend-config.ts","../../src/routing/get-domain-for-current-environment.ts"],"sourcesContent":["/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicrofrontendConfigEdge } from '../../config/edge/microfrontend-config';\nimport { getDomainForCurrentEnvironment } from '../../routing/get-domain-for-current-environment';\nimport type { Application } from '../../config/common/application';\nimport type { HostConfig } from '../../config/schema';\nimport type {\n MicrofrontendsMiddleware,\n MicrofrontendsMiddlewareHandler,\n} from './types';\n\ninterface GetHandlerParams {\n application: Application;\n flagFn?: () => Promise<boolean>;\n pattern: RegExp;\n}\n\ninterface InternalRouting {\n routing: HostConfig;\n}\n\nasync function verifyPreviewDomain(\n req: NextRequest,\n rewriteDomain: string,\n): Promise<boolean> {\n const jwtCookie = req.cookies.get('_vercel_jwt')?.value;\n const deploymentProtectionBypassHeader = req.headers.get(\n 'x-vercel-protection-bypass',\n );\n\n // We make a `HEAD` request with `x-vercel-micro-frontends-check: 1` which will get handled in the proxy without reaching the deployment\n const previewResponse = await fetch(rewriteDomain, {\n method: 'HEAD',\n headers: {\n 'x-vercel-micro-frontends-check': '1',\n ...(jwtCookie ? { cookie: `_vercel_jwt=${jwtCookie}` } : {}),\n ...(deploymentProtectionBypassHeader\n ? {\n 'x-vercel-protection-bypass': deploymentProtectionBypassHeader,\n }\n : {}),\n },\n });\n\n const vercelError = previewResponse.headers.get('x-vercel-error');\n return !(\n previewResponse.status === 404 &&\n (vercelError === 'DEPLOYMENT_NOT_FOUND' || vercelError === 'NOT_FOUND')\n );\n}\n\nfunction microfrontendInternalRoutingHandler({\n config,\n}: { config: MicrofrontendConfigEdge }): MicrofrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse> => {\n const payload: Record<string, InternalRouting> = Object.fromEntries(\n await Promise.all(\n config.getAllApplications().map(async (application) => {\n let rewriteDomain = getDomainForCurrentEnvironment(application);\n const isPreviewDomainAvailable = await verifyPreviewDomain(\n req,\n rewriteDomain,\n );\n\n if (!isPreviewDomainAvailable) {\n rewriteDomain = application.production.toString();\n }\n\n const url = new URL(rewriteDomain);\n return [application.name, { routing: { host: url.host } }] as const;\n }),\n ),\n );\n\n return NextResponse.json(payload);\n };\n}\n\nfunction getHandler({\n application,\n flagFn,\n pattern,\n}: GetHandlerParams): MicrofrontendsMiddlewareHandler {\n return async (req: NextRequest): Promise<NextResponse | undefined> => {\n const pathname = req.nextUrl.pathname;\n const search = req.nextUrl.search;\n\n let rewriteDomain = getDomainForCurrentEnvironment(application);\n const patchedHeaders = new Headers(req.headers);\n\n const responseCallbacks: ((response: NextResponse) => void)[] = [];\n const onRewrite: (response: NextResponse) => NextResponse = (response) => {\n for (const callback of responseCallbacks) {\n callback(response);\n }\n\n return response;\n };\n\n // If this is a preview environment, we check the domain to make sure the project was deployed\n if (process.env.VERCEL_ENV === 'preview' && rewriteDomain) {\n const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;\n const assetPrefix = application.routing?.assetPrefix;\n\n if (\n assetPrefix &&\n pathname.startsWith(`/${assetPrefix}`) &&\n req.cookies.get(zoneFallbackCookieName)?.value === '1'\n ) {\n // If this is an asset request and we have the cookie, we can safely route to production without fetching\n rewriteDomain = application.production.toString();\n } else {\n try {\n let deploymentFound: boolean;\n if (req.headers.get('x-vercel-skip-deployment-existence-check')) {\n deploymentFound = true;\n } else {\n deploymentFound = await verifyPreviewDomain(req, rewriteDomain);\n }\n\n if (!deploymentFound) {\n // If the deployment is not found, we rewrite to the production domain\n rewriteDomain = application.production.toString();\n\n // We set a 1 minute cookie for the application to avoid checking again for every request\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '1', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 60, // 1 minute\n });\n });\n\n // When routing to a production url, we need to enable the toolbar manually,\n // since production deployments rely on the extension to do that, but the extension can't match the top-level domain\n try {\n const existingCookie = patchedHeaders.get('cookie');\n\n // If the request doesn't contain the toolbar cookie, we add it to support the middleware injection\n if (!existingCookie?.includes('__vercel_toolbar')) {\n patchedHeaders.set(\n 'cookie',\n [`__vercel_toolbar=1`, existingCookie].join('; '),\n );\n\n // We also return a `set-cookie` header to set the cookie locally, to support the Next.js injection which checks the document\n responseCallbacks.push((response) => {\n response.cookies.set('__vercel_toolbar', '1', {\n httpOnly: false,\n sameSite: 'lax',\n secure: true,\n maxAge: 29030400,\n });\n });\n }\n } catch (error) {\n // Do Nothing\n }\n } else if (req.cookies.get(zoneFallbackCookieName)?.value === '1') {\n // If the preview exists and we have the fallback cookie, we make sure to clear the cookie to route subsequent assets to the preview\n responseCallbacks.push((response) => {\n response.cookies.set(zoneFallbackCookieName, '', {\n httpOnly: true,\n sameSite: 'lax',\n secure: true,\n maxAge: 0,\n });\n });\n }\n } catch {\n // Do Nothing\n }\n }\n }\n\n const isFlagEnabled = async (): Promise<boolean> =>\n flagFn ? flagFn() : true;\n\n // If the pattern doesn't match, we don't need to execute the flag\n if (pattern.test(pathname) && (await isFlagEnabled())) {\n return onRewrite(\n NextResponse.rewrite(`${rewriteDomain}${pathname}${search}`, {\n request: {\n headers: patchedHeaders,\n },\n }),\n );\n }\n };\n // If the path does not match the pattern, we don't do anything and let the request continue\n}\n\n/**\n * Returns an array of middleware functions that will handle routing to the\n * right microfrontends for the provided configuration.\n *\n * @param config - The microfrontends configuration object.\n * @param flagValues - An object that maps flag names to functions that return the flag value.\n */\nexport function getMicrofrontendsMiddleware({\n request,\n flagValues,\n}: {\n request: NextRequest;\n flagValues?: Record<string, () => Promise<boolean>>;\n}): MicrofrontendsMiddleware[] {\n const config = MicrofrontendConfigEdge.fromEnv({\n cookies: request.cookies.getAll(),\n });\n const middlewares: MicrofrontendsMiddleware[] = [];\n\n middlewares.push({\n src: '/.well-known/vercel/microfrontend-routing',\n fn: microfrontendInternalRoutingHandler({ config }),\n });\n\n for (const application of config.getAllApplications()) {\n if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {\n continue;\n }\n if (application.routing) {\n if (\n process.env.VERCEL_ENV === 'preview' &&\n application.routing.assetPrefix\n ) {\n const pattern = pathToRegexp(\n `/${application.routing.assetPrefix}/:path+`,\n );\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n pattern,\n }),\n });\n }\n for (const pathGroup of application.routing.matches) {\n if (process.env.VERCEL_ENV === 'preview' || pathGroup.options?.flag) {\n const flagName = pathGroup.options?.flag;\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let flagFn;\n if (flagName) {\n flagFn = flagValues?.[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${application.name} but not found in provided flag values.`,\n );\n }\n }\n for (const path of pathGroup.paths) {\n const pattern = pathToRegexp(path);\n middlewares.push({\n src: pattern,\n fn: getHandler({\n application,\n flagFn,\n pattern,\n }),\n });\n }\n }\n }\n }\n }\n return middlewares;\n}\n\n/**\n * Executes the middlewares returned by `getMicrofrontendsMiddleware` and\n * returns a `Response` if any of the microfrontends middlewares match or\n * `undefined` if none match. If a `Response` object is returned, the calling\n * code should return that Response from the Next.js middleware in order to\n * stop execution of the middleware and perform the rewrite.\n */\nexport async function runMicrofrontendsMiddleware(\n request: NextRequest,\n flagValues?: Record<string, () => Promise<boolean>>,\n): Promise<Response | undefined> {\n const pathname = request.nextUrl.pathname;\n const middlewares = getMicrofrontendsMiddleware({\n request,\n flagValues,\n });\n\n for (const mware of middlewares) {\n if (\n typeof mware.src === 'string'\n ? pathname === mware.src\n : mware.src.test(pathname)\n ) {\n // eslint-disable-next-line no-await-in-loop\n const response = await mware.fn(request);\n if (response) {\n return response;\n }\n }\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport { parse } from 'jsonc-parser';\nimport { MicrofrontendConfigCommon } from '../common/microfrontend-config';\nimport type { Config } from '../schema';\nimport { Overrides } from '../overrides';\n\n/**\n * Edge Runtime does not support ajv validation, or fs access.\n * This version of the MicrofrontendConfig does not validate the config shape,\n * and requires the config to be set on the environment.\n *\n * It should be used for Next.js middleware which runs in the Edge Runtime.\n */\nexport class MicrofrontendConfigEdge extends MicrofrontendConfigCommon {\n static fromEnv({\n cookies,\n }: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigEdge {\n return new MicrofrontendConfigCommon({\n config: parse(MicrofrontendConfigCommon.getConfigFromEnv()) as Config,\n overrides: Overrides.parseOverrides(cookies),\n });\n }\n}\n","export type MicrofrontendErrorType =\n | 'config'\n | 'packageJson'\n | 'vercelJson'\n | 'zone'\n | 'unknown';\n\nexport type MicrofrontendErrorSubtype =\n | 'not_found'\n | 'not_found_in_env'\n | 'invalid_asset_prefix'\n | 'invalid_main_path'\n | 'does_not_match_schema'\n | 'unable_to_read_file'\n | 'unsupported_validation_env'\n | 'unsupported_version'\n | 'invalid_path'\n | 'invalid_permissions'\n | 'invalid_syntax'\n | 'missing_microfrontend_config_path'\n | 'unsupported_operation';\n\n// A mapping of error types to their subtypes.\ninterface TypeToSubtype {\n zone:\n | 'invalid_asset_prefix'\n | 'invalid_path'\n | 'multiple_package_managers'\n | 'not_found';\n config:\n | 'conflicting_paths'\n | 'does_not_match_schema'\n | 'invalid_main_path'\n | 'invalid_preview_deployment_suffix'\n | 'multiple_default_applications'\n | 'no_default_application'\n | 'not_found_in_env'\n | 'not_found'\n | 'unable_to_read_file'\n | 'invalid_syntax'\n | 'invalid_permissions'\n | 'unsupported_operation'\n | 'unsupported_validation_env'\n | 'unsupported_version';\n packageJson:\n | 'missing_field_name'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n vercelJson:\n | 'missing_field_microFrontend_config_path'\n | 'unable_to_read_file'\n | 'invalid_permissions'\n | 'invalid_syntax';\n unknown: never;\n}\n\nexport type MicrofrontendErrorSource =\n | '@vercel/microfrontends'\n | '@vercel/microfrontends/next'\n | 'fs'\n | 'ajv';\n\nexport interface MicrofrontendErrorOptions<T extends MicrofrontendErrorType> {\n source?: MicrofrontendErrorSource;\n type?: T;\n subtype?: TypeToSubtype[T];\n}\n\ninterface HandleOptions {\n fileName?: string;\n}\n\nexport class MicrofrontendError<\n T extends MicrofrontendErrorType = 'unknown',\n> extends Error {\n public source: MicrofrontendErrorSource;\n public type: T;\n public subtype?: TypeToSubtype[T];\n\n constructor(message: string, opts?: MicrofrontendErrorOptions<T>) {\n super(message);\n this.name = 'MicrofrontendsError';\n this.source = opts?.source ?? '@vercel/microfrontends';\n this.type = opts?.type ?? ('unknown' as T);\n this.subtype = opts?.subtype;\n Error.captureStackTrace(this, MicrofrontendError);\n }\n\n isKnown(): boolean {\n return this.type !== 'unknown';\n }\n\n isUnknown(): boolean {\n return !this.isKnown();\n }\n\n /**\n * Converts an error to a MicrofrontendsError.\n * @param original - The original error to convert.\n * @returns The converted MicrofrontendsError.\n */\n static convert(\n original: Error,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (opts?.fileName) {\n const err = MicrofrontendError.convertFSError(original, opts.fileName);\n if (err) {\n return err;\n }\n }\n\n if (\n original.message.includes(\n 'Code generation from strings disallowed for this context',\n )\n ) {\n return new MicrofrontendError(original.message, {\n type: 'config',\n subtype: 'unsupported_validation_env',\n source: 'ajv',\n });\n }\n\n // unknown catch-all\n return new MicrofrontendError(original.message);\n }\n\n static convertFSError(\n original: Error,\n fileName: string,\n ): MicrofrontendError<MicrofrontendErrorType> | null {\n if (original instanceof Error && 'code' in original) {\n if (original.code === 'ENOENT') {\n return new MicrofrontendError(`Could not find \"${fileName}\"`, {\n type: 'config',\n subtype: 'unable_to_read_file',\n source: 'fs',\n });\n }\n if (original.code === 'EACCES') {\n return new MicrofrontendError(\n `Permission denied while accessing \"${fileName}\"`,\n {\n type: 'config',\n subtype: 'invalid_permissions',\n source: 'fs',\n },\n );\n }\n }\n\n if (original instanceof SyntaxError) {\n return new MicrofrontendError(\n `Failed to parse \"${fileName}\": Invalid JSON format.`,\n {\n type: 'config',\n subtype: 'invalid_syntax',\n source: 'fs',\n },\n );\n }\n\n return null;\n }\n\n /**\n * Handles an unknown error and returns a MicrofrontendsError instance.\n * @param err - The error to handle.\n * @returns A MicrofrontendsError instance.\n */\n static handle(\n err: unknown,\n opts?: HandleOptions,\n ): MicrofrontendError<MicrofrontendErrorType> {\n if (err instanceof MicrofrontendError) {\n return err as MicrofrontendError<MicrofrontendErrorType>;\n }\n\n // handle Error instances\n if (err instanceof Error) {\n return MicrofrontendError.convert(err, opts);\n }\n\n // handle object errors\n if (typeof err === 'object' && err !== null) {\n if ('message' in err && typeof err.message === 'string') {\n return MicrofrontendError.convert(new Error(err.message), opts);\n }\n }\n\n return new MicrofrontendError('An unknown error occurred');\n }\n}\n","// NOTE: This is copied from https://github.com/vercel/api/blob/main/packages/util-func/src/url-safe-string.ts.\n// See https://linear.app/vercel/issue/FDRTN-199/spike-move-preview-domain-generation-logic-into-build-and-deploy\n// for cleaning this up before release.\n\ninterface Options {\n joinString?: string;\n lowercaseOnly?: boolean;\n maxLen?: number;\n regexRemovePattern?: RegExp;\n trimWhitespace?: boolean;\n}\n\n/**\n * This function allows to convert single string to URL-safe tags to use for routing,\n * SEO purposes, etc. It is taken from https://www.npmjs.com/package/url-safe-string\n * and implemented here to be typed and skip the dependency.\n */\nfunction buildUrlSafeString(givenOpts: Options = {}): {\n generate: (...args: string[]) => string;\n} {\n const options = {\n joinString: '-',\n lowercaseOnly: true,\n maxLen: 100,\n regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,\n trimWhitespace: true,\n ...givenOpts,\n };\n\n return {\n generate: (...args: string[]) => {\n const reJoinString = new RegExp(`${options.joinString}+`, 'g');\n\n // biome-ignore lint/suspicious/noImplicitAnyLet: Ignored using `--suppress`\n let tag;\n\n if (args.length === 0) {\n throw new Error('generate method must be passed at least one argument');\n }\n\n // Validate, trim all arguments:\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (typeof arg !== 'string')\n throw new Error('all supplied arguments must be Strings');\n\n if (options.trimWhitespace) {\n args[i] = arg.trim();\n }\n }\n\n // Join strings and convert whitespace between words to join string\n tag = args.join(options.joinString);\n tag = tag.replace(/\\s/g, options.joinString);\n if (options.lowercaseOnly) tag = tag.toLowerCase();\n // Regex away anything \"unsafe\", but ignore the join string!\n tag = tag.replace(options.regexRemovePattern, (match) => {\n if (match === options.joinString) return match;\n\n return '';\n });\n\n // Truncate in excess of maxLen\n if (tag.length > options.maxLen) tag = tag.substring(0, options.maxLen);\n\n // Remove any duplicates of the join string using this pattern: /<join string>+/g\n tag = tag.replace(reJoinString, options.joinString);\n\n return tag;\n },\n };\n}\n\n/**\n * Export a preconfigured version for convenience.\n */\nexport const urlSafeString = buildUrlSafeString().generate;\n\nexport function makeUrlSafe(name: string): string {\n return urlSafeString(name.replace(/\\//g, '-'))\n .replace(/^-*/g, '')\n .replace(/-*$/g, '');\n}\n","import { makeUrlSafe } from '../../routing/url';\nimport type { MicrofrontendConfig } from '../microfrontend-config';\nimport type { OverridesConfig } from './types';\n\nexport const OVERRIDES_COOKIE_PREFIX = 'vercel-micro-frontends-override';\n\nexport class Overrides {\n config: OverridesConfig;\n\n constructor(config: OverridesConfig) {\n this.config = config;\n }\n\n static overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;\n\n static getAppEnvOverrideCookieName(zone: string): string {\n return `${Overrides.overrideEnvCookiePrefix}${zone}`;\n }\n\n static isOverrideCookie(cookie: { name?: string }): boolean {\n return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));\n }\n\n static getOverrideFromCookie(cookie: {\n name: string;\n value?: string | null;\n }): { zone: string; host: string } | undefined {\n if (!Overrides.isOverrideCookie(cookie) || !cookie.value) return;\n return {\n zone: cookie.name.replace(Overrides.overrideEnvCookiePrefix, ''),\n host: cookie.value,\n };\n }\n\n static parseOverrides(\n cookies: { name: string; value?: string | null }[],\n ): OverridesConfig {\n const overridesConfig: OverridesConfig = { applications: {} };\n\n cookies.forEach((cookie) => {\n const override = Overrides.getOverrideFromCookie(cookie);\n if (!override) return;\n overridesConfig.applications[override.zone] = {\n environment: { host: override.host },\n };\n });\n\n return overridesConfig;\n }\n\n static validOverrideDomainsForZone(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n ): string[] {\n const projectName = microfrontendConfig.getZone(zone).vercel?.projectName;\n if (!projectName) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n const parsedProjectName = makeUrlSafe(projectName);\n const previewDeploymentSuffix =\n microfrontendConfig.options?.vercel?.previewDeploymentSuffix;\n const teamSlug = microfrontendConfig.options?.vercel?.teamSlug;\n if (!teamSlug && !previewDeploymentSuffix) {\n return [microfrontendConfig.getZone(zone).production.host];\n }\n\n const suffix = previewDeploymentSuffix\n ? `.${previewDeploymentSuffix}`\n : `-${teamSlug}.vercel.app`;\n\n // <project-name>-git-<branch-name>-<scope-slug>.vercel.app\n // <project-name>-git-<branch-name>.<custom-suffix>\n return [\n `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,\n microfrontendConfig.getZone(zone).production.host,\n ];\n }\n\n static validateOverrideDomain(\n microfrontendConfig: MicrofrontendConfig,\n zone: string,\n domain: string,\n ): boolean {\n return new RegExp(\n `^${Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(\n '|',\n )}$`,\n ).test(domain);\n }\n\n serialize(): OverridesConfig {\n return this.config;\n }\n}\n","import type { HostConfig } from '../schema';\n\ninterface HostDisplayOptions {\n includeDefaultPort?: boolean;\n}\n\nexport class Host {\n protocol: 'http' | 'https';\n host: HostConfig['host'];\n port: number;\n serialized: HostConfig;\n\n constructor({ protocol, host, port }: HostConfig) {\n this.protocol = protocol || 'https';\n this.host = host;\n this.port = Host.getPort({ port, protocol: this.protocol });\n this.serialized = {\n protocol,\n host,\n ...(port ? { port } : undefined),\n };\n }\n\n isLocal(): boolean {\n return this.host === 'localhost' || this.host === '127.0.0.1';\n }\n\n static getPort({\n protocol,\n port,\n }: { protocol: HostConfig['protocol']; port?: HostConfig['port'] }): number {\n if (!port) {\n if (protocol === 'http') {\n return 80;\n }\n return 443;\n }\n\n return port;\n }\n\n isDefaultPort(): boolean {\n return this.port === Host.getPort({ protocol: this.protocol });\n }\n\n toString(opts: HostDisplayOptions = {}): string {\n const url = this.toUrl(opts);\n // strip the trailing slash\n return url.toString().replace(/\\/$/, '');\n }\n\n toUrl(opts: HostDisplayOptions = {}): URL {\n const { includeDefaultPort } = opts;\n const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? '' : `:${this.port}`}`;\n\n return new URL(url);\n }\n\n serialize(): HostConfig {\n return this.serialized;\n }\n}\n","import type { ApplicationConfig, Routing, Vercel } from '../schema';\nimport type { ApplicationOverrideConfig } from '../overrides';\nimport { MicrofrontendError } from '../errors';\nimport { Host } from './host';\n\nexport class Application {\n default: boolean;\n routing?: Routing;\n name: string;\n development: {\n local: Host;\n fallback?: Host;\n };\n production: Host;\n vercel?: Vercel;\n overrides?: {\n environment?: Host;\n };\n\n constructor(\n name: string,\n {\n app,\n overrides,\n }: { app: ApplicationConfig; overrides?: ApplicationOverrideConfig },\n ) {\n // validate\n Application.validate(name, app);\n\n this.name = name;\n this.default = app.default;\n this.routing = app.routing;\n this.development = {\n local: new Host(app.development.local),\n fallback: app.development.fallback\n ? new Host(app.development.fallback)\n : undefined,\n };\n this.production = new Host(app.production);\n this.vercel = app.vercel;\n this.overrides = overrides?.environment\n ? {\n environment: new Host(overrides.environment),\n }\n : undefined;\n }\n\n isDefault(): boolean {\n return this.default;\n }\n\n static validate(name: string, app: ApplicationConfig): void {\n // validate assetPrefix\n if (\n app.routing?.assetPrefix?.startsWith('/') ||\n app.routing?.assetPrefix?.endsWith('/')\n ) {\n throw new MicrofrontendError(\n `Invalid assetPrefix for application \"${name}\". Must not start or end with a slash.`,\n { type: 'zone', subtype: 'invalid_asset_prefix' },\n );\n }\n\n // validate routes\n for (const group of app.routing?.matches ?? []) {\n for (const p of group.paths) {\n if (p === '/') {\n continue;\n }\n if (p.endsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must not end with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n\n if (!p.startsWith('/')) {\n throw new MicrofrontendError(\n `Invalid path for application \"${name}\". ${p} must start with a slash.`,\n { type: 'zone', subtype: 'invalid_path' },\n );\n }\n }\n }\n }\n\n serialize(): ApplicationConfig {\n if (this.routing === undefined || this.default) {\n return {\n default: true,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n\n return {\n default: false,\n routing: this.routing,\n development: {\n local: this.development.local.serialize(),\n fallback: this.development.fallback?.serialize(),\n },\n production: this.production.serialize(),\n vercel: this.vercel,\n };\n }\n}\n","import type { ApplicationConfig, Config, Options } from '../schema';\nimport { MicrofrontendError } from '../errors';\nimport type { OverridesConfig } from '../overrides';\nimport { Overrides } from '../overrides/config';\nimport { Application } from './application';\n\nconst SUPPORTED_VERSIONS = ['1'];\nconst DEFAULT_LOCAL_PROXY_PORT = 3024;\n\n/**\n * A class to manage the microfrontends configuration.\n *\n * This class should not be used directly. Instead, use the `MicrofrontendConfig` or `MicrofrontendConfigEdgeRuntime` classes.\n */\nexport class MicrofrontendConfigCommon {\n config: Config;\n name?: string;\n zones: Record<string, Application> = {};\n version: string;\n overrides?: Overrides;\n options?: Options;\n $schema: string | undefined;\n\n constructor({\n config,\n overrides,\n }: { config: Config; overrides?: OverridesConfig }) {\n if (!SUPPORTED_VERSIONS.includes(config.version)) {\n throw new MicrofrontendError(\n `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(\n ', ',\n )}`,\n { type: 'config', subtype: 'unsupported_version' },\n );\n }\n const disableOverrides = config.options?.vercel?.disableOverrides ?? false;\n\n this.overrides =\n overrides && !disableOverrides ? new Overrides(overrides) : undefined;\n\n // create zones\n for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {\n this.zones[zoneName] = new Application(zoneName, {\n app: zoneConfig,\n overrides: !disableOverrides\n ? this.overrides?.config.applications[zoneName]\n : undefined,\n });\n }\n\n this.config = config;\n this.name = config.name;\n this.version = config.version;\n this.options = config.options;\n this.$schema = config.$schema;\n }\n\n isOverridesDisabled(): boolean {\n return this.options?.vercel?.disableOverrides ?? false;\n }\n\n protected static getConfigFromEnv(): string {\n const config = process.env.MFE_CONFIG;\n if (!config) {\n throw new MicrofrontendError(`Missing \"MFE_CONFIG\" in environment.`, {\n type: 'config',\n subtype: 'not_found_in_env',\n });\n }\n return config;\n }\n\n static fromEnv(_: {\n cookies: { name: string; value: string }[];\n }): MicrofrontendConfigCommon | Promise<MicrofrontendConfigCommon> {\n throw new Error('Not implemented');\n }\n\n getConfig(): Config {\n return this.config;\n }\n\n getAllApplications(): Application[] {\n return Object.values(this.zones);\n }\n\n getZone(name: string): Application {\n const zone = this.zones[name];\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find microfrontends configuration for application \"${name}\"`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n getApplicationByProjectId(projectId: string): Application | undefined {\n return Object.values(this.zones).find(\n (zone) => zone.vercel?.projectId === projectId,\n );\n }\n\n getDefaultZone(): Application {\n const zone = Object.values(this.zones).find((z) => z.default);\n if (!zone) {\n throw new MicrofrontendError(\n `Could not find default zone in microfrontends configuration`,\n {\n type: 'zone',\n subtype: 'not_found',\n },\n );\n }\n\n return zone;\n }\n\n /**\n * Returns the configured port for the local proxy\n */\n getLocalProxyPort(): number {\n return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;\n }\n\n /**\n * Serializes the class back to the Schema type.\n *\n * NOTE: This is used when writing the config to disk and must always match the input Schema\n */\n toSchemaJson(): Config {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n $schema: this.$schema,\n name: this.name,\n version: this.version,\n options: this.options,\n applications,\n };\n }\n\n serialize(): { config: Config; overrides?: OverridesConfig } {\n const applications: Record<string, ApplicationConfig> = {};\n for (const [name, zone] of Object.entries(this.zones)) {\n applications[name] = zone.serialize();\n }\n\n return {\n config: {\n name: this.name,\n version: this.version,\n applications,\n options: this.options,\n $schema: this.$schema,\n },\n overrides: this.overrides?.serialize(),\n };\n }\n\n write(_: string): void {\n throw new MicrofrontendError(\n `Writing to file to disk requires using an instance of \"MicrofrontendConfig\".`,\n { type: 'config', subtype: 'unsupported_operation' },\n );\n }\n}\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { Application } from '../config/common/application';\n\nfunction debugDomains(zone: string, env: string, domain: string): void {\n if (process.env.MFE_DEBUG === 'true') {\n const indent = ' '.repeat(4);\n const header = 'domains (zone (env) -> domain)';\n const separator = '⎯'.repeat(header.length);\n const line = `${indent} 1. ${zone} (${env}) -> ${domain}`;\n\n // eslint-disable-next-line no-console\n console.log(`${indent}${header}\\n${indent}${separator}\\n${line}\\n`);\n }\n}\n\n/**\n * Returns the Vercel domain for the given application based on the current\n * environment (local, preview, production).\n */\nexport function getDomainForCurrentEnvironment(zone: Application): string {\n if (zone.overrides?.environment) {\n return zone.overrides.environment.toString();\n }\n const zoneName = zone.name;\n if (!process.env.VERCEL_ENV || process.env.VERCEL_ENV === 'development') {\n // TODO(mknichel): Convert this back to the local development domain once\n // there is local development proxy support.\n const domain =\n process.env.NODE_ENV === 'test'\n ? zone.development.local.toString()\n : zone.production.toString();\n debugDomains(zoneName, 'development', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'production') {\n const domain = zone.production.toString();\n debugDomains(zoneName, 'production', domain);\n return domain;\n } else if (process.env.VERCEL_ENV === 'preview') {\n const MFE_PREVIEW_DOMAINS = JSON.parse(\n process.env.MFE_PREVIEW_DOMAINS ?? '{}',\n ) as Record<string, string>;\n if (MFE_PREVIEW_DOMAINS[zoneName]) {\n debugDomains(zoneName, 'preview', MFE_PREVIEW_DOMAINS[zoneName]);\n return MFE_PREVIEW_DOMAINS[zoneName];\n }\n\n throw new Error(\n `Could not find preview domain for application \"${zoneName}\"`,\n );\n }\n // TODO(mknichel): Add support in this function for custom environments.\n // Custom Vercel environments may have an arbitrary string for `VERCEL_ENV`.\n debugDomains(zoneName, process.env.VERCEL_ENV, zone.production.toString());\n return zone.production.toString();\n}\n"],"mappings":";AAGA,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;;;ACF7B,SAAS,aAAa;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAAM,SAAS;AAC3B,SAAK,UAAU,6BAAM;AACrB,UAAM,kBAAkB,MAAM,kBAAkB;AAAA,EAClD;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YAAqB;AACnB,WAAO,CAA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