@vercel/microfrontends 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bin/cli.cjs +1483 -186
- 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 +66 -60
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +3 -3
- package/dist/config.js +65 -59
- package/dist/config.js.map +1 -1
- package/dist/{index-eff254d8.d.ts → index-05742bef.d.ts} +11 -22
- package/dist/{micro-frontend-config-42886104.d.ts → microfrontend-config-2425db74.d.ts} +12 -12
- package/dist/next/config.cjs +83 -77
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.d.ts +3 -3
- package/dist/next/config.js +82 -76
- package/dist/next/config.js.map +1 -1
- package/dist/next/middleware.cjs +55 -55
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.d.ts +11 -11
- package/dist/next/middleware.js +53 -53
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +79 -73
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +9 -9
- package/dist/next/testing.js +79 -73
- 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 +1 -1
- package/dist/overrides.js +9 -9
- package/dist/overrides.js.map +1 -1
- package/dist/types-13f3e535.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 +2 -1
- package/dist/v2/config.js +38 -38
- package/dist/v2/config.js.map +1 -1
- package/dist/v2/microfrontends/server.cjs +102 -65
- package/dist/v2/microfrontends/server.cjs.map +1 -1
- package/dist/v2/microfrontends/server.d.ts +6 -1
- package/dist/v2/microfrontends/server.js +102 -65
- 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 +5 -4
- 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 +120 -83
- package/dist/v2/next/config.cjs.map +1 -1
- package/dist/v2/next/config.d.ts +4 -4
- package/dist/v2/next/config.js +119 -82
- 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 +54 -54
- package/dist/v2/next/middleware.cjs.map +1 -1
- package/dist/v2/next/middleware.d.ts +8 -8
- package/dist/v2/next/middleware.js +52 -52
- 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/validation.cjs +20 -20
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.js +20 -20
- package/dist/validation.js.map +1 -1
- package/package.json +10 -3
package/dist/next/middleware.cjs
CHANGED
|
@@ -20,8 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/next/middleware/index.ts
|
|
21
21
|
var middleware_exports = {};
|
|
22
22
|
__export(middleware_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
getMicrofrontendsMiddleware: () => getMicrofrontendsMiddleware,
|
|
24
|
+
runMicrofrontendsMiddleware: () => runMicrofrontendsMiddleware
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(middleware_exports);
|
|
27
27
|
|
|
@@ -29,18 +29,18 @@ module.exports = __toCommonJS(middleware_exports);
|
|
|
29
29
|
var import_server = require("next/server");
|
|
30
30
|
var import_path_to_regexp = require("path-to-regexp");
|
|
31
31
|
|
|
32
|
-
// src/config/edge/
|
|
32
|
+
// src/config/edge/microfrontend-config.ts
|
|
33
33
|
var import_jsonc_parser = require("jsonc-parser");
|
|
34
34
|
|
|
35
35
|
// src/config/errors.ts
|
|
36
|
-
var
|
|
36
|
+
var MicrofrontendError = class extends Error {
|
|
37
37
|
constructor(message, opts) {
|
|
38
38
|
super(message);
|
|
39
|
-
this.name = "
|
|
40
|
-
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/
|
|
39
|
+
this.name = "MicrofrontendsError";
|
|
40
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/microfrontends";
|
|
41
41
|
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
42
42
|
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
43
|
-
Error.captureStackTrace(this,
|
|
43
|
+
Error.captureStackTrace(this, MicrofrontendError);
|
|
44
44
|
}
|
|
45
45
|
isKnown() {
|
|
46
46
|
return this.type !== "unknown";
|
|
@@ -49,13 +49,13 @@ var MicroFrontendError = class extends Error {
|
|
|
49
49
|
return !this.isKnown();
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Converts an error to a
|
|
52
|
+
* Converts an error to a MicrofrontendsError.
|
|
53
53
|
* @param original - The original error to convert.
|
|
54
|
-
* @returns The converted
|
|
54
|
+
* @returns The converted MicrofrontendsError.
|
|
55
55
|
*/
|
|
56
56
|
static convert(original, opts) {
|
|
57
57
|
if (opts == null ? void 0 : opts.fileName) {
|
|
58
|
-
const err =
|
|
58
|
+
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
59
59
|
if (err) {
|
|
60
60
|
return err;
|
|
61
61
|
}
|
|
@@ -63,25 +63,25 @@ var MicroFrontendError = class extends Error {
|
|
|
63
63
|
if (original.message.includes(
|
|
64
64
|
"Code generation from strings disallowed for this context"
|
|
65
65
|
)) {
|
|
66
|
-
return new
|
|
66
|
+
return new MicrofrontendError(original.message, {
|
|
67
67
|
type: "config",
|
|
68
68
|
subtype: "unsupported_validation_env",
|
|
69
69
|
source: "ajv"
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
return new
|
|
72
|
+
return new MicrofrontendError(original.message);
|
|
73
73
|
}
|
|
74
74
|
static convertFSError(original, fileName) {
|
|
75
75
|
if (original instanceof Error && "code" in original) {
|
|
76
76
|
if (original.code === "ENOENT") {
|
|
77
|
-
return new
|
|
77
|
+
return new MicrofrontendError(`Could not find "${fileName}"`, {
|
|
78
78
|
type: "config",
|
|
79
79
|
subtype: "unable_to_read_file",
|
|
80
80
|
source: "fs"
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
if (original.code === "EACCES") {
|
|
84
|
-
return new
|
|
84
|
+
return new MicrofrontendError(
|
|
85
85
|
`Permission denied while accessing "${fileName}"`,
|
|
86
86
|
{
|
|
87
87
|
type: "config",
|
|
@@ -92,7 +92,7 @@ var MicroFrontendError = class extends Error {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
if (original instanceof SyntaxError) {
|
|
95
|
-
return new
|
|
95
|
+
return new MicrofrontendError(
|
|
96
96
|
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
97
97
|
{
|
|
98
98
|
type: "config",
|
|
@@ -104,23 +104,23 @@ var MicroFrontendError = class extends Error {
|
|
|
104
104
|
return null;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
|
-
* Handles an unknown error and returns a
|
|
107
|
+
* Handles an unknown error and returns a MicrofrontendsError instance.
|
|
108
108
|
* @param err - The error to handle.
|
|
109
|
-
* @returns A
|
|
109
|
+
* @returns A MicrofrontendsError instance.
|
|
110
110
|
*/
|
|
111
111
|
static handle(err, opts) {
|
|
112
|
-
if (err instanceof
|
|
112
|
+
if (err instanceof MicrofrontendError) {
|
|
113
113
|
return err;
|
|
114
114
|
}
|
|
115
115
|
if (err instanceof Error) {
|
|
116
|
-
return
|
|
116
|
+
return MicrofrontendError.convert(err, opts);
|
|
117
117
|
}
|
|
118
118
|
if (typeof err === "object" && err !== null) {
|
|
119
119
|
if ("message" in err && typeof err.message === "string") {
|
|
120
|
-
return
|
|
120
|
+
return MicrofrontendError.convert(new Error(err.message), opts);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
return new
|
|
123
|
+
return new MicrofrontendError("An unknown error occurred");
|
|
124
124
|
}
|
|
125
125
|
};
|
|
126
126
|
|
|
@@ -203,27 +203,27 @@ var _Overrides = class {
|
|
|
203
203
|
});
|
|
204
204
|
return overridesConfig;
|
|
205
205
|
}
|
|
206
|
-
static validOverrideDomainsForZone(
|
|
206
|
+
static validOverrideDomainsForZone(microfrontendConfig, zone) {
|
|
207
207
|
var _a, _b, _c, _d, _e;
|
|
208
|
-
const projectName = (_a =
|
|
208
|
+
const projectName = (_a = microfrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
|
|
209
209
|
if (!projectName) {
|
|
210
|
-
return [
|
|
210
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
211
211
|
}
|
|
212
212
|
const parsedProjectName = makeUrlSafe(projectName);
|
|
213
|
-
const previewDeploymentSuffix = (_c = (_b =
|
|
214
|
-
const teamSlug = (_e = (_d =
|
|
213
|
+
const previewDeploymentSuffix = (_c = (_b = microfrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
|
|
214
|
+
const teamSlug = (_e = (_d = microfrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
|
|
215
215
|
if (!teamSlug && !previewDeploymentSuffix) {
|
|
216
|
-
return [
|
|
216
|
+
return [microfrontendConfig.getZone(zone).production.host];
|
|
217
217
|
}
|
|
218
218
|
const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
|
|
219
219
|
return [
|
|
220
220
|
`${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
|
|
221
|
-
|
|
221
|
+
microfrontendConfig.getZone(zone).production.host
|
|
222
222
|
];
|
|
223
223
|
}
|
|
224
|
-
static validateOverrideDomain(
|
|
224
|
+
static validateOverrideDomain(microfrontendConfig, zone, domain) {
|
|
225
225
|
return new RegExp(
|
|
226
|
-
`^${_Overrides.validOverrideDomainsForZone(
|
|
226
|
+
`^${_Overrides.validOverrideDomainsForZone(microfrontendConfig, zone).join(
|
|
227
227
|
"|"
|
|
228
228
|
)}$`
|
|
229
229
|
).test(domain);
|
|
@@ -305,7 +305,7 @@ var Application = class {
|
|
|
305
305
|
static validate(name, app) {
|
|
306
306
|
var _a, _b, _c, _d, _e;
|
|
307
307
|
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("/"))) {
|
|
308
|
-
throw new
|
|
308
|
+
throw new MicrofrontendError(
|
|
309
309
|
`Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
|
|
310
310
|
{ type: "zone", subtype: "invalid_asset_prefix" }
|
|
311
311
|
);
|
|
@@ -316,13 +316,13 @@ var Application = class {
|
|
|
316
316
|
continue;
|
|
317
317
|
}
|
|
318
318
|
if (p.endsWith("/")) {
|
|
319
|
-
throw new
|
|
319
|
+
throw new MicrofrontendError(
|
|
320
320
|
`Invalid path for application "${name}". ${p} must not end with a slash.`,
|
|
321
321
|
{ type: "zone", subtype: "invalid_path" }
|
|
322
322
|
);
|
|
323
323
|
}
|
|
324
324
|
if (!p.startsWith("/")) {
|
|
325
|
-
throw new
|
|
325
|
+
throw new MicrofrontendError(
|
|
326
326
|
`Invalid path for application "${name}". ${p} must start with a slash.`,
|
|
327
327
|
{ type: "zone", subtype: "invalid_path" }
|
|
328
328
|
);
|
|
@@ -356,10 +356,10 @@ var Application = class {
|
|
|
356
356
|
}
|
|
357
357
|
};
|
|
358
358
|
|
|
359
|
-
// src/config/common/
|
|
359
|
+
// src/config/common/microfrontend-config.ts
|
|
360
360
|
var SUPPORTED_VERSIONS = ["1"];
|
|
361
361
|
var DEFAULT_LOCAL_PROXY_PORT = 3024;
|
|
362
|
-
var
|
|
362
|
+
var MicrofrontendConfigCommon = class {
|
|
363
363
|
constructor({
|
|
364
364
|
config,
|
|
365
365
|
overrides
|
|
@@ -367,7 +367,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
367
367
|
this.zones = {};
|
|
368
368
|
var _a, _b, _c;
|
|
369
369
|
if (!SUPPORTED_VERSIONS.includes(config.version)) {
|
|
370
|
-
throw new
|
|
370
|
+
throw new MicrofrontendError(
|
|
371
371
|
`Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
372
372
|
", "
|
|
373
373
|
)}`,
|
|
@@ -395,7 +395,7 @@ var MicroFrontendConfigCommon = class {
|
|
|
395
395
|
static getConfigFromEnv() {
|
|
396
396
|
const config = process.env.MFE_CONFIG;
|
|
397
397
|
if (!config) {
|
|
398
|
-
throw new
|
|
398
|
+
throw new MicrofrontendError(`Missing "MFE_CONFIG" in environment.`, {
|
|
399
399
|
type: "config",
|
|
400
400
|
subtype: "not_found_in_env"
|
|
401
401
|
});
|
|
@@ -414,8 +414,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
414
414
|
getZone(name) {
|
|
415
415
|
const zone = this.zones[name];
|
|
416
416
|
if (!zone) {
|
|
417
|
-
throw new
|
|
418
|
-
`Could not find
|
|
417
|
+
throw new MicrofrontendError(
|
|
418
|
+
`Could not find microfrontends configuration for application "${name}"`,
|
|
419
419
|
{
|
|
420
420
|
type: "zone",
|
|
421
421
|
subtype: "not_found"
|
|
@@ -435,8 +435,8 @@ var MicroFrontendConfigCommon = class {
|
|
|
435
435
|
getDefaultZone() {
|
|
436
436
|
const zone = Object.values(this.zones).find((z) => z.default);
|
|
437
437
|
if (!zone) {
|
|
438
|
-
throw new
|
|
439
|
-
`Could not find default zone in
|
|
438
|
+
throw new MicrofrontendError(
|
|
439
|
+
`Could not find default zone in microfrontends configuration`,
|
|
440
440
|
{
|
|
441
441
|
type: "zone",
|
|
442
442
|
subtype: "not_found"
|
|
@@ -488,20 +488,20 @@ var MicroFrontendConfigCommon = class {
|
|
|
488
488
|
};
|
|
489
489
|
}
|
|
490
490
|
write(_) {
|
|
491
|
-
throw new
|
|
492
|
-
`Writing to file to disk requires using an instance of "
|
|
491
|
+
throw new MicrofrontendError(
|
|
492
|
+
`Writing to file to disk requires using an instance of "MicrofrontendConfig".`,
|
|
493
493
|
{ type: "config", subtype: "unsupported_operation" }
|
|
494
494
|
);
|
|
495
495
|
}
|
|
496
496
|
};
|
|
497
497
|
|
|
498
|
-
// src/config/edge/
|
|
499
|
-
var
|
|
498
|
+
// src/config/edge/microfrontend-config.ts
|
|
499
|
+
var MicrofrontendConfigEdge = class extends MicrofrontendConfigCommon {
|
|
500
500
|
static fromEnv({
|
|
501
501
|
cookies
|
|
502
502
|
}) {
|
|
503
|
-
return new
|
|
504
|
-
config: (0, import_jsonc_parser.parse)(
|
|
503
|
+
return new MicrofrontendConfigCommon({
|
|
504
|
+
config: (0, import_jsonc_parser.parse)(MicrofrontendConfigCommon.getConfigFromEnv()),
|
|
505
505
|
overrides: Overrides.parseOverrides(cookies)
|
|
506
506
|
});
|
|
507
507
|
}
|
|
@@ -570,7 +570,7 @@ async function verifyPreviewDomain(req, rewriteDomain) {
|
|
|
570
570
|
const vercelError = previewResponse.headers.get("x-vercel-error");
|
|
571
571
|
return !(previewResponse.status === 404 && (vercelError === "DEPLOYMENT_NOT_FOUND" || vercelError === "NOT_FOUND"));
|
|
572
572
|
}
|
|
573
|
-
function
|
|
573
|
+
function microfrontendInternalRoutingHandler({
|
|
574
574
|
config
|
|
575
575
|
}) {
|
|
576
576
|
return async (req) => {
|
|
@@ -681,18 +681,18 @@ function getHandler({
|
|
|
681
681
|
}
|
|
682
682
|
};
|
|
683
683
|
}
|
|
684
|
-
function
|
|
684
|
+
function getMicrofrontendsMiddleware({
|
|
685
685
|
request,
|
|
686
686
|
flagValues
|
|
687
687
|
}) {
|
|
688
688
|
var _a, _b, _c;
|
|
689
|
-
const config =
|
|
689
|
+
const config = MicrofrontendConfigEdge.fromEnv({
|
|
690
690
|
cookies: request.cookies.getAll()
|
|
691
691
|
});
|
|
692
692
|
const middlewares = [];
|
|
693
693
|
middlewares.push({
|
|
694
694
|
src: "/.well-known/vercel/microfrontend-routing",
|
|
695
|
-
fn:
|
|
695
|
+
fn: microfrontendInternalRoutingHandler({ config })
|
|
696
696
|
});
|
|
697
697
|
for (const application of config.getAllApplications()) {
|
|
698
698
|
if (application.name === process.env.NEXT_PUBLIC_MFE_CURRENT_APPLICATION) {
|
|
@@ -740,9 +740,9 @@ function getMicroFrontendsMiddleware({
|
|
|
740
740
|
}
|
|
741
741
|
return middlewares;
|
|
742
742
|
}
|
|
743
|
-
async function
|
|
743
|
+
async function runMicrofrontendsMiddleware(request, flagValues) {
|
|
744
744
|
const pathname = request.nextUrl.pathname;
|
|
745
|
-
const middlewares =
|
|
745
|
+
const middlewares = getMicrofrontendsMiddleware({
|
|
746
746
|
request,
|
|
747
747
|
flagValues
|
|
748
748
|
});
|
|
@@ -757,7 +757,7 @@ async function runMicroFrontendsMiddleware(request, flagValues) {
|
|
|
757
757
|
}
|
|
758
758
|
// Annotate the CommonJS export names for ESM import in node:
|
|
759
759
|
0 && (module.exports = {
|
|
760
|
-
|
|
761
|
-
|
|
760
|
+
getMicrofrontendsMiddleware,
|
|
761
|
+
runMicrofrontendsMiddleware
|
|
762
762
|
});
|
|
763
763
|
//# sourceMappingURL=middleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/middleware/index.ts","../../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":["export * from './middleware';\nexport * from './types';\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicroFrontendConfigEdge } from '../../config/edge/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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,oBAA6B;AAC7B,4BAA6B;;;ACF7B,0BAAsB;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAAM,SAAS;AAC3B,SAAK,UAAU,6BAAM;AACrB,UAAM,kBAAkB,MAAM,kBAAkB;AAAA,EAClD;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YAAqB;AACnB,WAAO,CAAC,KAAK,QAAQ;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,QACL,UACA,MAC4C;AAC5C,QAAI,6BAAM,UAAU;AAClB,YAAM,MAAM,mBAAmB,eAAe,UAAU,KAAK,QAAQ;AACrE,UAAI,KAAK;AACP,eAAO;AAAA,MACT;AAAA,IACF;AAEA,QACE,SAAS,QAAQ;AAAA,MACf;AAAA,IACF,GACA;AACA,aAAO,IAAI,mBAAmB,SAAS,SAAS;AAAA,QAC9C,MAAM;AAAA,QACN,SAAS;AAAA,QACT,QAAQ;AAAA,MACV,CAA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IAAI,YAAY,QAAQ;AAAA,QAC1B;AACA,oBAAY,KAAK;AAAA,UACf,KAAK;AAAA,UACL,IAAI,WAAW;AAAA,YACb;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AACA,iBAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,YACE,QAAQ,IAAI,eAAe,eAC3B,eAAU,YAAV,mBAAmB,WACnB,eAAU,YAAV,mBAAmB,4BACnB;AACA,gBAAM,YAAW,eAAU,YAAV,mBAAmB;AAEpC,cAAI;AACJ,cAAI,UAAU;AACZ,qBAAS,yCAAa;AACtB,gBAAI,CAAC,QAAQ;AACX,oBAAM,IAAI;AAAA,gBACR,SAAS,8DAA8D,UAAU,yBAAyB,YAAY;AAAA,cACxH;AAAA,YACF;AAAA,UACF;AACA,qBAAW,QAAQ,UAAU,OAAO;AAClC,kBAAM,cAAU,oCAAa,IAAI;AACjC,wBAAY,KAAK;AAAA,cACf,KAAK;AAAA,cACL,IAAI,WAAW;AAAA,gBACb;AAAA,gBACA;AAAA,gBACA;AAAA,cACF,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAsB,4BACpB,SACA,YAC+B;AAC/B,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,cAAc,4BAA4B;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,aAAW,SAAS,aAAa;AAC/B,QACE,OAAO,MAAM,QAAQ,WACjB,aAAa,MAAM,MACnB,MAAM,IAAI,KAAK,QAAQ,GAC3B;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,OAAO;AACvC,UAAI,UAAU;AACZ,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/next/middleware/index.ts","../../src/next/middleware/middleware.ts","../../src/config/edge/microfrontend-config.ts","../../src/config/errors.ts","../../src/routing/url.ts","../../src/config/overrides/config.ts","../../src/config/common/host.ts","../../src/config/common/application.ts","../../src/config/common/microfrontend-config.ts","../../src/routing/get-domain-for-current-environment.ts"],"sourcesContent":["export * from './middleware';\nexport * from './types';\n","/// <reference types=\"@edge-runtime/types\" />\n\nimport type { NextRequest } from 'next/server';\nimport { NextResponse } from 'next/server';\nimport { pathToRegexp } from 'path-to-regexp';\nimport { MicrofrontendConfigEdge } from '../../config/edge/microfrontend-config';\nimport { getDomainForCurrentEnvironment } from '../../routing/get-domain-for-current-environment';\nimport type { Application } from '../../config/common/application';\nimport type { 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 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 (\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 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,oBAA6B;AAC7B,4BAA6B;;;ACF7B,0BAAsB;;;ACuEf,IAAM,qBAAN,cAEG,MAAM;AAAA,EAKd,YAAY,SAAiB,MAAqC;AAChE,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAS,6BAAM,WAAU;AAC9B,SAAK,QAAO,6BAAM,SAAS;AAC3B,SAAK,UAAU,6BAAM;AACrB,UAAM,kBAAkB,MAAM,kBAAkB;AAAA,EAClD;AAAA,EAEA,UAAmB;AACjB,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAEA,YAAqB;AACnB,WAAO,CAAC,KAAK,QAAQ;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,QACL,UACA,MAC4C;AAC5C,QAAI,6BAAM,UAAU;AAClB,YAAM,MAAM,mBAAmB,eAAe,UAAU,KAAK,QAAQ;AACrE,UAAI,KAAK;AACP,eAAO;AAAA,MACT;AAAA,IACF;AAEA,QACE,SAAS,QAAQ;AAAA,MACf;AAAA,IACF,GACA;AACA,aAAO,IAAI,mBAAmB,SAAS,SAAS;AAAA,QAC9C,MAAM;AAAA,QACN,SAAS;AAAA,QACT,QAAQ;AAAA,MACV,CAAC;AAAA,IACH;AAGA,WAAO,IAAI,mBAAmB,SAAS,OAA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;AAAA,UACf,KAAK;AAAA,UACL,IAAI,WAAW;AAAA,YACb;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AACA,iBAAW,aAAa,YAAY,QAAQ,SAAS;AACnD,YACE,QAAQ,IAAI,eAAe,eAC3B,eAAU,YAAV,mBAAmB,WACnB,eAAU,YAAV,mBAAmB,4BACnB;AACA,gBAAM,YAAW,eAAU,YAAV,mBAAmB;AAEpC,cAAI;AACJ,cAAI,UAAU;AACZ,qBAAS,yCAAa;AACtB,gBAAI,CAAC,QAAQ;AACX,oBAAM,IAAI;AAAA,gBACR,SAAS,8DAA8D,UAAU,yBAAyB,YAAY;AAAA,cACxH;AAAA,YACF;AAAA,UACF;AACA,qBAAW,QAAQ,UAAU,OAAO;AAClC,kBAAM,cAAU,oCAAa,IAAI;AACjC,wBAAY,KAAK;AAAA,cACf,KAAK;AAAA,cACL,IAAI,WAAW;AAAA,gBACb;AAAA,gBACA;AAAA,gBACA;AAAA,cACF,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AASA,eAAsB,4BACpB,SACA,YAC+B;AAC/B,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,cAAc,4BAA4B;AAAA,IAC9C;AAAA,IACA;AAAA,EACF,CAAC;AAED,aAAW,SAAS,aAAa;AAC/B,QACE,OAAO,MAAM,QAAQ,WACjB,aAAa,MAAM,MACnB,MAAM,IAAI,KAAK,QAAQ,GAC3B;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,OAAO;AACvC,UAAI,UAAU;AACZ,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
|
|
3
|
-
type
|
|
4
|
-
interface
|
|
3
|
+
type MicrofrontendsMiddlewareHandler = (request: NextRequest) => Promise<Response | undefined>;
|
|
4
|
+
interface MicrofrontendsMiddleware {
|
|
5
5
|
src: string | RegExp;
|
|
6
|
-
fn:
|
|
6
|
+
fn: MicrofrontendsMiddlewareHandler;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Returns an array of middleware functions that will handle routing to the
|
|
11
|
-
* right
|
|
11
|
+
* right microfrontends for the provided configuration.
|
|
12
12
|
*
|
|
13
|
-
* @param config - The
|
|
13
|
+
* @param config - The microfrontends configuration object.
|
|
14
14
|
* @param flagValues - An object that maps flag names to functions that return the flag value.
|
|
15
15
|
*/
|
|
16
|
-
declare function
|
|
16
|
+
declare function getMicrofrontendsMiddleware({ request, flagValues, }: {
|
|
17
17
|
request: NextRequest;
|
|
18
18
|
flagValues?: Record<string, () => Promise<boolean>>;
|
|
19
|
-
}):
|
|
19
|
+
}): MicrofrontendsMiddleware[];
|
|
20
20
|
/**
|
|
21
|
-
* Executes the middlewares returned by `
|
|
22
|
-
* returns a `Response` if any of the
|
|
21
|
+
* Executes the middlewares returned by `getMicrofrontendsMiddleware` and
|
|
22
|
+
* returns a `Response` if any of the microfrontends middlewares match or
|
|
23
23
|
* `undefined` if none match. If a `Response` object is returned, the calling
|
|
24
24
|
* code should return that Response from the Next.js middleware in order to
|
|
25
25
|
* stop execution of the middleware and perform the rewrite.
|
|
26
26
|
*/
|
|
27
|
-
declare function
|
|
27
|
+
declare function runMicrofrontendsMiddleware(request: NextRequest, flagValues?: Record<string, () => Promise<boolean>>): Promise<Response | undefined>;
|
|
28
28
|
|
|
29
|
-
export {
|
|
29
|
+
export { MicrofrontendsMiddleware, MicrofrontendsMiddlewareHandler, getMicrofrontendsMiddleware, runMicrofrontendsMiddleware };
|