@vercel/microfrontends 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +202 -0
  2. package/cli/index.cjs +21 -0
  3. package/dist/bin/cli.cjs +1604 -0
  4. package/dist/config/client.cjs +54 -0
  5. package/dist/config/client.cjs.map +1 -0
  6. package/dist/config/client.d.ts +23 -0
  7. package/dist/config/client.js +28 -0
  8. package/dist/config/client.js.map +1 -0
  9. package/dist/config/edge.cjs +508 -0
  10. package/dist/config/edge.cjs.map +1 -0
  11. package/dist/config/edge.d.ts +20 -0
  12. package/dist/config/edge.js +481 -0
  13. package/dist/config/edge.js.map +1 -0
  14. package/dist/config.cjs +1254 -0
  15. package/dist/config.cjs.map +1 -0
  16. package/dist/config.d.ts +25 -0
  17. package/dist/config.js +1212 -0
  18. package/dist/config.js.map +1 -0
  19. package/dist/index-eff254d8.d.ts +175 -0
  20. package/dist/micro-frontend-config-42886104.d.ts +154 -0
  21. package/dist/next/client.cjs +3 -0
  22. package/dist/next/client.cjs.map +1 -0
  23. package/dist/next/client.d.ts +45 -0
  24. package/dist/next/client.js +3 -0
  25. package/dist/next/client.js.map +1 -0
  26. package/dist/next/config.cjs +1793 -0
  27. package/dist/next/config.cjs.map +1 -0
  28. package/dist/next/config.d.ts +22 -0
  29. package/dist/next/config.js +1758 -0
  30. package/dist/next/config.js.map +1 -0
  31. package/dist/next/endpoints.cjs +82 -0
  32. package/dist/next/endpoints.cjs.map +1 -0
  33. package/dist/next/endpoints.d.ts +15 -0
  34. package/dist/next/endpoints.js +57 -0
  35. package/dist/next/endpoints.js.map +1 -0
  36. package/dist/next/middleware.cjs +763 -0
  37. package/dist/next/middleware.cjs.map +1 -0
  38. package/dist/next/middleware.d.ts +29 -0
  39. package/dist/next/middleware.js +735 -0
  40. package/dist/next/middleware.js.map +1 -0
  41. package/dist/next/testing.cjs +1430 -0
  42. package/dist/next/testing.cjs.map +1 -0
  43. package/dist/next/testing.d.ts +53 -0
  44. package/dist/next/testing.js +1389 -0
  45. package/dist/next/testing.js.map +1 -0
  46. package/dist/overrides.cjs +143 -0
  47. package/dist/overrides.cjs.map +1 -0
  48. package/dist/overrides.d.ts +2 -0
  49. package/dist/overrides.js +115 -0
  50. package/dist/overrides.js.map +1 -0
  51. package/dist/schema-83a75e61.d.ts +188 -0
  52. package/dist/types-4fd1c7c6.d.ts +157 -0
  53. package/dist/v2/config.cjs +720 -0
  54. package/dist/v2/config.cjs.map +1 -0
  55. package/dist/v2/config.d.ts +2 -0
  56. package/dist/v2/config.js +695 -0
  57. package/dist/v2/config.js.map +1 -0
  58. package/dist/v2/microfrontends/server.cjs +1312 -0
  59. package/dist/v2/microfrontends/server.cjs.map +1 -0
  60. package/dist/v2/microfrontends/server.d.ts +48 -0
  61. package/dist/v2/microfrontends/server.js +1277 -0
  62. package/dist/v2/microfrontends/server.js.map +1 -0
  63. package/dist/v2/microfrontends.cjs +803 -0
  64. package/dist/v2/microfrontends.cjs.map +1 -0
  65. package/dist/v2/microfrontends.d.ts +44 -0
  66. package/dist/v2/microfrontends.js +776 -0
  67. package/dist/v2/microfrontends.js.map +1 -0
  68. package/dist/v2/next/client.cjs +3 -0
  69. package/dist/v2/next/client.cjs.map +1 -0
  70. package/dist/v2/next/client.d.ts +45 -0
  71. package/dist/v2/next/client.js +3 -0
  72. package/dist/v2/next/client.js.map +1 -0
  73. package/dist/v2/next/config.cjs +1829 -0
  74. package/dist/v2/next/config.cjs.map +1 -0
  75. package/dist/v2/next/config.d.ts +22 -0
  76. package/dist/v2/next/config.js +1794 -0
  77. package/dist/v2/next/config.js.map +1 -0
  78. package/dist/v2/next/endpoints.cjs +138 -0
  79. package/dist/v2/next/endpoints.cjs.map +1 -0
  80. package/dist/v2/next/endpoints.d.ts +15 -0
  81. package/dist/v2/next/endpoints.js +113 -0
  82. package/dist/v2/next/endpoints.js.map +1 -0
  83. package/dist/v2/next/middleware.cjs +1110 -0
  84. package/dist/v2/next/middleware.cjs.map +1 -0
  85. package/dist/v2/next/middleware.d.ts +29 -0
  86. package/dist/v2/next/middleware.js +1082 -0
  87. package/dist/v2/next/middleware.js.map +1 -0
  88. package/dist/v2/schema.cjs +19 -0
  89. package/dist/v2/schema.cjs.map +1 -0
  90. package/dist/v2/schema.d.ts +1 -0
  91. package/dist/v2/schema.js +1 -0
  92. package/dist/v2/schema.js.map +1 -0
  93. package/dist/validation.cjs +754 -0
  94. package/dist/validation.cjs.map +1 -0
  95. package/dist/validation.d.ts +163 -0
  96. package/dist/validation.js +726 -0
  97. package/dist/validation.js.map +1 -0
  98. package/package.json +204 -0
  99. package/schema/schema-v2.json +288 -0
  100. package/schema/schema.json +352 -0
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/config/client/client-config.ts
21
+ var client_config_exports = {};
22
+ __export(client_config_exports, {
23
+ getClientConfigFromEnv: () => getClientConfigFromEnv,
24
+ getConfigForClient: () => getConfigForClient
25
+ });
26
+ module.exports = __toCommonJS(client_config_exports);
27
+ function getConfigForClient(config) {
28
+ return {
29
+ applications: Object.fromEntries(
30
+ Object.entries(config.applications).map(([name, application]) => [
31
+ name,
32
+ {
33
+ default: application.default,
34
+ routing: application.routing
35
+ }
36
+ ])
37
+ )
38
+ };
39
+ }
40
+ function getClientConfigFromEnv() {
41
+ const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;
42
+ if (!clientConfigJson) {
43
+ throw new Error(
44
+ "Could not find client micro-frontends config in the environment"
45
+ );
46
+ }
47
+ return JSON.parse(clientConfigJson);
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ getClientConfigFromEnv,
52
+ getConfigForClient
53
+ });
54
+ //# sourceMappingURL=client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/client/client-config.ts"],"sourcesContent":["import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,mBAAmB,QAA8B;AAC/D,SAAO;AAAA,IACL,cAAc,OAAO;AAAA,MACnB,OAAO,QAAQ,OAAO,YAAY,EAAE,IAAI,CAAC,CAAC,MAAM,WAAW,MAAM;AAAA,QAC/D;AAAA,QACA;AAAA,UACE,SAAS,YAAY;AAAA,UACrB,SAAS,YAAY;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;","names":[]}
@@ -0,0 +1,23 @@
1
+ import { A as ApplicationConfig, C as Config } from '../schema-83a75e61.js';
2
+
3
+ type ClientApplicationConfig = Pick<ApplicationConfig, 'default' | 'routing'>;
4
+ interface ClientConfig {
5
+ applications: Record<string, ClientApplicationConfig>;
6
+ }
7
+ /**
8
+ * Data that is returned from the `.well-known/vercel/micro-frontends/client-config`
9
+ * endpoint that is used by the client to ensure that navigations and prefetches
10
+ * are routed correctly.
11
+ */
12
+ interface WellKnownClientData {
13
+ config: ClientConfig;
14
+ }
15
+
16
+ /**
17
+ * Given a micro-frontends configuration, this returns a version that is
18
+ * acceptable to be used client-side without leaking any information.
19
+ */
20
+ declare function getConfigForClient(config: Config): ClientConfig;
21
+ declare function getClientConfigFromEnv(): ClientConfig;
22
+
23
+ export { ClientConfig, WellKnownClientData, getClientConfigFromEnv, getConfigForClient };
@@ -0,0 +1,28 @@
1
+ // src/config/client/client-config.ts
2
+ function getConfigForClient(config) {
3
+ return {
4
+ applications: Object.fromEntries(
5
+ Object.entries(config.applications).map(([name, application]) => [
6
+ name,
7
+ {
8
+ default: application.default,
9
+ routing: application.routing
10
+ }
11
+ ])
12
+ )
13
+ };
14
+ }
15
+ function getClientConfigFromEnv() {
16
+ const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;
17
+ if (!clientConfigJson) {
18
+ throw new Error(
19
+ "Could not find client micro-frontends config in the environment"
20
+ );
21
+ }
22
+ return JSON.parse(clientConfigJson);
23
+ }
24
+ export {
25
+ getClientConfigFromEnv,
26
+ getConfigForClient
27
+ };
28
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/client/client-config.ts"],"sourcesContent":["import type { Config } from '../schema';\nimport type { ClientConfig, WellKnownClientData } from './types';\n\n/**\n * Given a micro-frontends configuration, this returns a version that is\n * acceptable to be used client-side without leaking any information.\n */\nexport function getConfigForClient(config: Config): ClientConfig {\n return {\n applications: Object.fromEntries(\n Object.entries(config.applications).map(([name, application]) => [\n name,\n {\n default: application.default,\n routing: application.routing,\n },\n ]),\n ),\n };\n}\n\nexport function getClientConfigFromEnv(): ClientConfig {\n // This has to use the actual name rather than the constant variable in order\n // for the env var to be replaced during the build correctly.\n const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;\n if (!clientConfigJson) {\n throw new Error(\n 'Could not find client micro-frontends config in the environment',\n );\n }\n return JSON.parse(clientConfigJson) as ClientConfig;\n}\n\nexport type { ClientConfig, WellKnownClientData };\n"],"mappings":";AAOO,SAAS,mBAAmB,QAA8B;AAC/D,SAAO;AAAA,IACL,cAAc,OAAO;AAAA,MACnB,OAAO,QAAQ,OAAO,YAAY,EAAE,IAAI,CAAC,CAAC,MAAM,WAAW,MAAM;AAAA,QAC/D;AAAA,QACA;AAAA,UACE,SAAS,YAAY;AAAA,UACrB,SAAS,YAAY;AAAA,QACvB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,yBAAuC;AAGrD,QAAM,mBAAmB,QAAQ,IAAI;AACrC,MAAI,CAAC,kBAAkB;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,MAAM,gBAAgB;AACpC;","names":[]}
@@ -0,0 +1,508 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/config/edge/index.ts
21
+ var edge_exports = {};
22
+ __export(edge_exports, {
23
+ MicroFrontendConfigEdge: () => MicroFrontendConfigEdge
24
+ });
25
+ module.exports = __toCommonJS(edge_exports);
26
+
27
+ // src/config/edge/micro-frontend-config.ts
28
+ var import_jsonc_parser = require("jsonc-parser");
29
+
30
+ // src/config/errors.ts
31
+ var MicroFrontendError = class extends Error {
32
+ constructor(message, opts) {
33
+ super(message);
34
+ this.name = "MicroFrontendsError";
35
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
36
+ this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
37
+ this.subtype = opts == null ? void 0 : opts.subtype;
38
+ Error.captureStackTrace(this, MicroFrontendError);
39
+ }
40
+ isKnown() {
41
+ return this.type !== "unknown";
42
+ }
43
+ isUnknown() {
44
+ return !this.isKnown();
45
+ }
46
+ /**
47
+ * Converts an error to a MicroFrontendsError.
48
+ * @param original - The original error to convert.
49
+ * @returns The converted MicroFrontendsError.
50
+ */
51
+ static convert(original, opts) {
52
+ if (opts == null ? void 0 : opts.fileName) {
53
+ const err = MicroFrontendError.convertFSError(original, opts.fileName);
54
+ if (err) {
55
+ return err;
56
+ }
57
+ }
58
+ if (original.message.includes(
59
+ "Code generation from strings disallowed for this context"
60
+ )) {
61
+ return new MicroFrontendError(original.message, {
62
+ type: "config",
63
+ subtype: "unsupported_validation_env",
64
+ source: "ajv"
65
+ });
66
+ }
67
+ return new MicroFrontendError(original.message);
68
+ }
69
+ static convertFSError(original, fileName) {
70
+ if (original instanceof Error && "code" in original) {
71
+ if (original.code === "ENOENT") {
72
+ return new MicroFrontendError(`Could not find "${fileName}"`, {
73
+ type: "config",
74
+ subtype: "unable_to_read_file",
75
+ source: "fs"
76
+ });
77
+ }
78
+ if (original.code === "EACCES") {
79
+ return new MicroFrontendError(
80
+ `Permission denied while accessing "${fileName}"`,
81
+ {
82
+ type: "config",
83
+ subtype: "invalid_permissions",
84
+ source: "fs"
85
+ }
86
+ );
87
+ }
88
+ }
89
+ if (original instanceof SyntaxError) {
90
+ return new MicroFrontendError(
91
+ `Failed to parse "${fileName}": Invalid JSON format.`,
92
+ {
93
+ type: "config",
94
+ subtype: "invalid_syntax",
95
+ source: "fs"
96
+ }
97
+ );
98
+ }
99
+ return null;
100
+ }
101
+ /**
102
+ * Handles an unknown error and returns a MicroFrontendsError instance.
103
+ * @param err - The error to handle.
104
+ * @returns A MicroFrontendsError instance.
105
+ */
106
+ static handle(err, opts) {
107
+ if (err instanceof MicroFrontendError) {
108
+ return err;
109
+ }
110
+ if (err instanceof Error) {
111
+ return MicroFrontendError.convert(err, opts);
112
+ }
113
+ if (typeof err === "object" && err !== null) {
114
+ if ("message" in err && typeof err.message === "string") {
115
+ return MicroFrontendError.convert(new Error(err.message), opts);
116
+ }
117
+ }
118
+ return new MicroFrontendError("An unknown error occurred");
119
+ }
120
+ };
121
+
122
+ // src/routing/url.ts
123
+ function buildUrlSafeString(givenOpts = {}) {
124
+ const options = {
125
+ joinString: "-",
126
+ lowercaseOnly: true,
127
+ maxLen: 100,
128
+ regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
129
+ trimWhitespace: true,
130
+ ...givenOpts
131
+ };
132
+ return {
133
+ generate: (...args) => {
134
+ const reJoinString = new RegExp(`${options.joinString}+`, "g");
135
+ let tag;
136
+ if (args.length === 0) {
137
+ throw new Error("generate method must be passed at least one argument");
138
+ }
139
+ for (let i = 0; i < args.length; i++) {
140
+ const arg = args[i];
141
+ if (typeof arg !== "string")
142
+ throw new Error("all supplied arguments must be Strings");
143
+ if (options.trimWhitespace) {
144
+ args[i] = arg.trim();
145
+ }
146
+ }
147
+ tag = args.join(options.joinString);
148
+ tag = tag.replace(/\s/g, options.joinString);
149
+ if (options.lowercaseOnly)
150
+ tag = tag.toLowerCase();
151
+ tag = tag.replace(options.regexRemovePattern, (match) => {
152
+ if (match === options.joinString)
153
+ return match;
154
+ return "";
155
+ });
156
+ if (tag.length > options.maxLen)
157
+ tag = tag.substring(0, options.maxLen);
158
+ tag = tag.replace(reJoinString, options.joinString);
159
+ return tag;
160
+ }
161
+ };
162
+ }
163
+ var urlSafeString = buildUrlSafeString().generate;
164
+ function makeUrlSafe(name) {
165
+ return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
166
+ }
167
+
168
+ // src/config/overrides/config.ts
169
+ var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
170
+ var _Overrides = class {
171
+ constructor(config) {
172
+ this.config = config;
173
+ }
174
+ static getAppEnvOverrideCookieName(zone) {
175
+ return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
176
+ }
177
+ static isOverrideCookie(cookie) {
178
+ var _a;
179
+ return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
180
+ }
181
+ static getOverrideFromCookie(cookie) {
182
+ if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
183
+ return;
184
+ return {
185
+ zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
186
+ host: cookie.value
187
+ };
188
+ }
189
+ static parseOverrides(cookies) {
190
+ const overridesConfig = { applications: {} };
191
+ cookies.forEach((cookie) => {
192
+ const override = _Overrides.getOverrideFromCookie(cookie);
193
+ if (!override)
194
+ return;
195
+ overridesConfig.applications[override.zone] = {
196
+ environment: { host: override.host }
197
+ };
198
+ });
199
+ return overridesConfig;
200
+ }
201
+ static validOverrideDomainsForZone(microFrontendConfig, zone) {
202
+ var _a, _b, _c, _d, _e;
203
+ const projectName = (_a = microFrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
204
+ if (!projectName) {
205
+ return [microFrontendConfig.getZone(zone).production.host];
206
+ }
207
+ const parsedProjectName = makeUrlSafe(projectName);
208
+ const previewDeploymentSuffix = (_c = (_b = microFrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
209
+ const teamSlug = (_e = (_d = microFrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
210
+ if (!teamSlug && !previewDeploymentSuffix) {
211
+ return [microFrontendConfig.getZone(zone).production.host];
212
+ }
213
+ const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
214
+ return [
215
+ `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
216
+ microFrontendConfig.getZone(zone).production.host
217
+ ];
218
+ }
219
+ static validateOverrideDomain(microFrontendConfig, zone, domain) {
220
+ return new RegExp(
221
+ `^${_Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(
222
+ "|"
223
+ )}$`
224
+ ).test(domain);
225
+ }
226
+ serialize() {
227
+ return this.config;
228
+ }
229
+ };
230
+ var Overrides = _Overrides;
231
+ Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
232
+
233
+ // src/config/common/host.ts
234
+ var Host = class {
235
+ constructor({ protocol, host, port }) {
236
+ this.protocol = protocol || "https";
237
+ this.host = host;
238
+ this.port = Host.getPort({ port, protocol: this.protocol });
239
+ this.serialized = {
240
+ protocol,
241
+ host,
242
+ ...port ? { port } : void 0
243
+ };
244
+ }
245
+ isLocal() {
246
+ return this.host === "localhost" || this.host === "127.0.0.1";
247
+ }
248
+ static getPort({
249
+ protocol,
250
+ port
251
+ }) {
252
+ if (!port) {
253
+ if (protocol === "http") {
254
+ return 80;
255
+ }
256
+ return 443;
257
+ }
258
+ return port;
259
+ }
260
+ isDefaultPort() {
261
+ return this.port === Host.getPort({ protocol: this.protocol });
262
+ }
263
+ toString(opts = {}) {
264
+ const url = this.toUrl(opts);
265
+ return url.toString().replace(/\/$/, "");
266
+ }
267
+ toUrl(opts = {}) {
268
+ const { includeDefaultPort } = opts;
269
+ const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
270
+ return new URL(url);
271
+ }
272
+ serialize() {
273
+ return this.serialized;
274
+ }
275
+ };
276
+
277
+ // src/config/common/application.ts
278
+ var Application = class {
279
+ constructor(name, {
280
+ app,
281
+ overrides
282
+ }) {
283
+ Application.validate(name, app);
284
+ this.name = name;
285
+ this.default = app.default;
286
+ this.routing = app.routing;
287
+ this.development = {
288
+ local: new Host(app.development.local),
289
+ fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
290
+ };
291
+ this.production = new Host(app.production);
292
+ this.vercel = app.vercel;
293
+ this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
294
+ environment: new Host(overrides.environment)
295
+ } : void 0;
296
+ }
297
+ isDefault() {
298
+ return this.default;
299
+ }
300
+ static validate(name, app) {
301
+ var _a, _b, _c, _d, _e;
302
+ 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("/"))) {
303
+ throw new MicroFrontendError(
304
+ `Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
305
+ { type: "zone", subtype: "invalid_asset_prefix" }
306
+ );
307
+ }
308
+ for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
309
+ for (const p of group.paths) {
310
+ if (p === "/") {
311
+ continue;
312
+ }
313
+ if (p.endsWith("/")) {
314
+ throw new MicroFrontendError(
315
+ `Invalid path for application "${name}". ${p} must not end with a slash.`,
316
+ { type: "zone", subtype: "invalid_path" }
317
+ );
318
+ }
319
+ if (!p.startsWith("/")) {
320
+ throw new MicroFrontendError(
321
+ `Invalid path for application "${name}". ${p} must start with a slash.`,
322
+ { type: "zone", subtype: "invalid_path" }
323
+ );
324
+ }
325
+ }
326
+ }
327
+ }
328
+ serialize() {
329
+ var _a, _b;
330
+ if (this.routing === void 0 || this.default) {
331
+ return {
332
+ default: true,
333
+ development: {
334
+ local: this.development.local.serialize(),
335
+ fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
336
+ },
337
+ production: this.production.serialize(),
338
+ vercel: this.vercel
339
+ };
340
+ }
341
+ return {
342
+ default: false,
343
+ routing: this.routing,
344
+ development: {
345
+ local: this.development.local.serialize(),
346
+ fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
347
+ },
348
+ production: this.production.serialize(),
349
+ vercel: this.vercel
350
+ };
351
+ }
352
+ };
353
+
354
+ // src/config/common/micro-frontend-config.ts
355
+ var SUPPORTED_VERSIONS = ["1"];
356
+ var DEFAULT_LOCAL_PROXY_PORT = 3024;
357
+ var MicroFrontendConfigCommon = class {
358
+ constructor({
359
+ config,
360
+ overrides
361
+ }) {
362
+ this.zones = {};
363
+ var _a, _b, _c;
364
+ if (!SUPPORTED_VERSIONS.includes(config.version)) {
365
+ throw new MicroFrontendError(
366
+ `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
367
+ ", "
368
+ )}`,
369
+ { type: "config", subtype: "unsupported_version" }
370
+ );
371
+ }
372
+ const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
373
+ this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
374
+ for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
375
+ this.zones[zoneName] = new Application(zoneName, {
376
+ app: zoneConfig,
377
+ overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
378
+ });
379
+ }
380
+ this.config = config;
381
+ this.name = config.name;
382
+ this.version = config.version;
383
+ this.options = config.options;
384
+ this.$schema = config.$schema;
385
+ }
386
+ isOverridesDisabled() {
387
+ var _a, _b;
388
+ return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
389
+ }
390
+ static getConfigFromEnv() {
391
+ const config = process.env.MFE_CONFIG;
392
+ if (!config) {
393
+ throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
394
+ type: "config",
395
+ subtype: "not_found_in_env"
396
+ });
397
+ }
398
+ return config;
399
+ }
400
+ static fromEnv(_) {
401
+ throw new Error("Not implemented");
402
+ }
403
+ getConfig() {
404
+ return this.config;
405
+ }
406
+ getAllApplications() {
407
+ return Object.values(this.zones);
408
+ }
409
+ getZone(name) {
410
+ const zone = this.zones[name];
411
+ if (!zone) {
412
+ throw new MicroFrontendError(
413
+ `Could not find micro-frontends configuration for application "${name}"`,
414
+ {
415
+ type: "zone",
416
+ subtype: "not_found"
417
+ }
418
+ );
419
+ }
420
+ return zone;
421
+ }
422
+ getApplicationByProjectId(projectId) {
423
+ return Object.values(this.zones).find(
424
+ (zone) => {
425
+ var _a;
426
+ return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
427
+ }
428
+ );
429
+ }
430
+ getDefaultZone() {
431
+ const zone = Object.values(this.zones).find((z) => z.default);
432
+ if (!zone) {
433
+ throw new MicroFrontendError(
434
+ `Could not find default zone in micro-frontends configuration`,
435
+ {
436
+ type: "zone",
437
+ subtype: "not_found"
438
+ }
439
+ );
440
+ }
441
+ return zone;
442
+ }
443
+ /**
444
+ * Returns the configured port for the local proxy
445
+ */
446
+ getLocalProxyPort() {
447
+ var _a, _b;
448
+ return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
449
+ }
450
+ /**
451
+ * Serializes the class back to the Schema type.
452
+ *
453
+ * NOTE: This is used when writing the config to disk and must always match the input Schema
454
+ */
455
+ toSchemaJson() {
456
+ const applications = {};
457
+ for (const [name, zone] of Object.entries(this.zones)) {
458
+ applications[name] = zone.serialize();
459
+ }
460
+ return {
461
+ $schema: this.$schema,
462
+ name: this.name,
463
+ version: this.version,
464
+ options: this.options,
465
+ applications
466
+ };
467
+ }
468
+ serialize() {
469
+ var _a;
470
+ const applications = {};
471
+ for (const [name, zone] of Object.entries(this.zones)) {
472
+ applications[name] = zone.serialize();
473
+ }
474
+ return {
475
+ config: {
476
+ name: this.name,
477
+ version: this.version,
478
+ applications,
479
+ options: this.options,
480
+ $schema: this.$schema
481
+ },
482
+ overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
483
+ };
484
+ }
485
+ write(_) {
486
+ throw new MicroFrontendError(
487
+ `Writing to file to disk requires using an instance of "MicroFrontendConfig".`,
488
+ { type: "config", subtype: "unsupported_operation" }
489
+ );
490
+ }
491
+ };
492
+
493
+ // src/config/edge/micro-frontend-config.ts
494
+ var MicroFrontendConfigEdge = class extends MicroFrontendConfigCommon {
495
+ static fromEnv({
496
+ cookies
497
+ }) {
498
+ return new MicroFrontendConfigCommon({
499
+ config: (0, import_jsonc_parser.parse)(MicroFrontendConfigCommon.getConfigFromEnv()),
500
+ overrides: Overrides.parseOverrides(cookies)
501
+ });
502
+ }
503
+ };
504
+ // Annotate the CommonJS export names for ESM import in node:
505
+ 0 && (module.exports = {
506
+ MicroFrontendConfigEdge
507
+ });
508
+ //# sourceMappingURL=edge.cjs.map