@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,1254 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/config/index.ts
31
+ var config_exports = {};
32
+ __export(config_exports, {
33
+ MicroFrontendConfig: () => MicroFrontendConfig,
34
+ getClientConfigFromEnv: () => getClientConfigFromEnv,
35
+ getConfigForClient: () => getConfigForClient,
36
+ getWellKnownClientData: () => getWellKnownClientData,
37
+ isCommonApplicationConfig: () => isCommonApplicationConfig,
38
+ isDefaultApplicationConfig: () => isDefaultApplicationConfig
39
+ });
40
+ module.exports = __toCommonJS(config_exports);
41
+
42
+ // src/config/client/client-config.ts
43
+ function getConfigForClient(config) {
44
+ return {
45
+ applications: Object.fromEntries(
46
+ Object.entries(config.applications).map(([name, application]) => [
47
+ name,
48
+ {
49
+ default: application.default,
50
+ routing: application.routing
51
+ }
52
+ ])
53
+ )
54
+ };
55
+ }
56
+ function getClientConfigFromEnv() {
57
+ const clientConfigJson = process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG;
58
+ if (!clientConfigJson) {
59
+ throw new Error(
60
+ "Could not find client micro-frontends config in the environment"
61
+ );
62
+ }
63
+ return JSON.parse(clientConfigJson);
64
+ }
65
+
66
+ // src/config/well-known/endpoints.ts
67
+ async function getWellKnownClientData(flagValues = {}) {
68
+ var _a;
69
+ const config = getClientConfigFromEnv();
70
+ for (const [applicationName, application] of Object.entries(
71
+ config.applications
72
+ )) {
73
+ if (!application.routing) {
74
+ continue;
75
+ }
76
+ const newRoutingMatches = [];
77
+ for (const pathGroup of application.routing.matches) {
78
+ if ((_a = pathGroup.options) == null ? void 0 : _a.flag) {
79
+ const flagName = pathGroup.options.flag;
80
+ const flagFn = flagValues[flagName];
81
+ if (!flagFn) {
82
+ throw new Error(
83
+ `Flag "${flagName}" was specified to control routing for path group "${pathGroup.group}" in application ${applicationName} but not found in provided flag values.`
84
+ );
85
+ }
86
+ const flagEnabled = await flagFn();
87
+ if (flagEnabled) {
88
+ newRoutingMatches.push(pathGroup);
89
+ }
90
+ } else {
91
+ newRoutingMatches.push(pathGroup);
92
+ }
93
+ }
94
+ application.routing.matches = newRoutingMatches;
95
+ }
96
+ return {
97
+ config
98
+ };
99
+ }
100
+
101
+ // src/config/types.ts
102
+ var isCommonApplicationConfig = (app) => !app.default && typeof app.routing === "object";
103
+ var isDefaultApplicationConfig = (app) => app.default && typeof app.routing === "undefined";
104
+
105
+ // src/config/micro-frontend-config.ts
106
+ var import_node_fs2 = __toESM(require("fs"), 1);
107
+
108
+ // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
109
+ var import_node_path = __toESM(require("path"), 1);
110
+
111
+ // src/config-v2/microfrontends/server/constants.ts
112
+ var MFE_CONFIG_DEFAULT_FILE_PATH = "microfrontends";
113
+ var MFE_CONFIG_DEFAULT_FILE_NAME = "microfrontends.json";
114
+
115
+ // src/utils/is-vercel.ts
116
+ function isVercel() {
117
+ return process.env.VERCEL === "1";
118
+ }
119
+
120
+ // src/config-v2/microfrontends/server/utils/get-output-file-path.ts
121
+ function getOutputFilePath() {
122
+ if (isVercel()) {
123
+ return import_node_path.default.join(
124
+ ".vercel",
125
+ MFE_CONFIG_DEFAULT_FILE_PATH,
126
+ MFE_CONFIG_DEFAULT_FILE_NAME
127
+ );
128
+ }
129
+ return import_node_path.default.join(MFE_CONFIG_DEFAULT_FILE_PATH, MFE_CONFIG_DEFAULT_FILE_NAME);
130
+ }
131
+
132
+ // src/config/errors.ts
133
+ var MicroFrontendError = class extends Error {
134
+ constructor(message, opts) {
135
+ super(message);
136
+ this.name = "MicroFrontendsError";
137
+ this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
138
+ this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
139
+ this.subtype = opts == null ? void 0 : opts.subtype;
140
+ Error.captureStackTrace(this, MicroFrontendError);
141
+ }
142
+ isKnown() {
143
+ return this.type !== "unknown";
144
+ }
145
+ isUnknown() {
146
+ return !this.isKnown();
147
+ }
148
+ /**
149
+ * Converts an error to a MicroFrontendsError.
150
+ * @param original - The original error to convert.
151
+ * @returns The converted MicroFrontendsError.
152
+ */
153
+ static convert(original, opts) {
154
+ if (opts == null ? void 0 : opts.fileName) {
155
+ const err = MicroFrontendError.convertFSError(original, opts.fileName);
156
+ if (err) {
157
+ return err;
158
+ }
159
+ }
160
+ if (original.message.includes(
161
+ "Code generation from strings disallowed for this context"
162
+ )) {
163
+ return new MicroFrontendError(original.message, {
164
+ type: "config",
165
+ subtype: "unsupported_validation_env",
166
+ source: "ajv"
167
+ });
168
+ }
169
+ return new MicroFrontendError(original.message);
170
+ }
171
+ static convertFSError(original, fileName) {
172
+ if (original instanceof Error && "code" in original) {
173
+ if (original.code === "ENOENT") {
174
+ return new MicroFrontendError(`Could not find "${fileName}"`, {
175
+ type: "config",
176
+ subtype: "unable_to_read_file",
177
+ source: "fs"
178
+ });
179
+ }
180
+ if (original.code === "EACCES") {
181
+ return new MicroFrontendError(
182
+ `Permission denied while accessing "${fileName}"`,
183
+ {
184
+ type: "config",
185
+ subtype: "invalid_permissions",
186
+ source: "fs"
187
+ }
188
+ );
189
+ }
190
+ }
191
+ if (original instanceof SyntaxError) {
192
+ return new MicroFrontendError(
193
+ `Failed to parse "${fileName}": Invalid JSON format.`,
194
+ {
195
+ type: "config",
196
+ subtype: "invalid_syntax",
197
+ source: "fs"
198
+ }
199
+ );
200
+ }
201
+ return null;
202
+ }
203
+ /**
204
+ * Handles an unknown error and returns a MicroFrontendsError instance.
205
+ * @param err - The error to handle.
206
+ * @returns A MicroFrontendsError instance.
207
+ */
208
+ static handle(err, opts) {
209
+ if (err instanceof MicroFrontendError) {
210
+ return err;
211
+ }
212
+ if (err instanceof Error) {
213
+ return MicroFrontendError.convert(err, opts);
214
+ }
215
+ if (typeof err === "object" && err !== null) {
216
+ if ("message" in err && typeof err.message === "string") {
217
+ return MicroFrontendError.convert(new Error(err.message), opts);
218
+ }
219
+ }
220
+ return new MicroFrontendError("An unknown error occurred");
221
+ }
222
+ };
223
+
224
+ // src/routing/url.ts
225
+ function buildUrlSafeString(givenOpts = {}) {
226
+ const options = {
227
+ joinString: "-",
228
+ lowercaseOnly: true,
229
+ maxLen: 100,
230
+ regexRemovePattern: /(?:(?!(?:[a-z0-9])).)/gi,
231
+ trimWhitespace: true,
232
+ ...givenOpts
233
+ };
234
+ return {
235
+ generate: (...args) => {
236
+ const reJoinString = new RegExp(`${options.joinString}+`, "g");
237
+ let tag;
238
+ if (args.length === 0) {
239
+ throw new Error("generate method must be passed at least one argument");
240
+ }
241
+ for (let i = 0; i < args.length; i++) {
242
+ const arg = args[i];
243
+ if (typeof arg !== "string")
244
+ throw new Error("all supplied arguments must be Strings");
245
+ if (options.trimWhitespace) {
246
+ args[i] = arg.trim();
247
+ }
248
+ }
249
+ tag = args.join(options.joinString);
250
+ tag = tag.replace(/\s/g, options.joinString);
251
+ if (options.lowercaseOnly)
252
+ tag = tag.toLowerCase();
253
+ tag = tag.replace(options.regexRemovePattern, (match) => {
254
+ if (match === options.joinString)
255
+ return match;
256
+ return "";
257
+ });
258
+ if (tag.length > options.maxLen)
259
+ tag = tag.substring(0, options.maxLen);
260
+ tag = tag.replace(reJoinString, options.joinString);
261
+ return tag;
262
+ }
263
+ };
264
+ }
265
+ var urlSafeString = buildUrlSafeString().generate;
266
+ function makeUrlSafe(name) {
267
+ return urlSafeString(name.replace(/\//g, "-")).replace(/^-*/g, "").replace(/-*$/g, "");
268
+ }
269
+
270
+ // src/config/overrides/config.ts
271
+ var OVERRIDES_COOKIE_PREFIX = "vercel-micro-frontends-override";
272
+ var _Overrides = class {
273
+ constructor(config) {
274
+ this.config = config;
275
+ }
276
+ static getAppEnvOverrideCookieName(zone) {
277
+ return `${_Overrides.overrideEnvCookiePrefix}${zone}`;
278
+ }
279
+ static isOverrideCookie(cookie) {
280
+ var _a;
281
+ return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
282
+ }
283
+ static getOverrideFromCookie(cookie) {
284
+ if (!_Overrides.isOverrideCookie(cookie) || !cookie.value)
285
+ return;
286
+ return {
287
+ zone: cookie.name.replace(_Overrides.overrideEnvCookiePrefix, ""),
288
+ host: cookie.value
289
+ };
290
+ }
291
+ static parseOverrides(cookies) {
292
+ const overridesConfig = { applications: {} };
293
+ cookies.forEach((cookie) => {
294
+ const override = _Overrides.getOverrideFromCookie(cookie);
295
+ if (!override)
296
+ return;
297
+ overridesConfig.applications[override.zone] = {
298
+ environment: { host: override.host }
299
+ };
300
+ });
301
+ return overridesConfig;
302
+ }
303
+ static validOverrideDomainsForZone(microFrontendConfig, zone) {
304
+ var _a, _b, _c, _d, _e;
305
+ const projectName = (_a = microFrontendConfig.getZone(zone).vercel) == null ? void 0 : _a.projectName;
306
+ if (!projectName) {
307
+ return [microFrontendConfig.getZone(zone).production.host];
308
+ }
309
+ const parsedProjectName = makeUrlSafe(projectName);
310
+ const previewDeploymentSuffix = (_c = (_b = microFrontendConfig.options) == null ? void 0 : _b.vercel) == null ? void 0 : _c.previewDeploymentSuffix;
311
+ const teamSlug = (_e = (_d = microFrontendConfig.options) == null ? void 0 : _d.vercel) == null ? void 0 : _e.teamSlug;
312
+ if (!teamSlug && !previewDeploymentSuffix) {
313
+ return [microFrontendConfig.getZone(zone).production.host];
314
+ }
315
+ const suffix = previewDeploymentSuffix ? `.${previewDeploymentSuffix}` : `-${teamSlug}.vercel.app`;
316
+ return [
317
+ `${parsedProjectName}-git-([a-zA-Z0-9-]+)${suffix}`,
318
+ microFrontendConfig.getZone(zone).production.host
319
+ ];
320
+ }
321
+ static validateOverrideDomain(microFrontendConfig, zone, domain) {
322
+ return new RegExp(
323
+ `^${_Overrides.validOverrideDomainsForZone(microFrontendConfig, zone).join(
324
+ "|"
325
+ )}$`
326
+ ).test(domain);
327
+ }
328
+ serialize() {
329
+ return this.config;
330
+ }
331
+ };
332
+ var Overrides = _Overrides;
333
+ Overrides.overrideEnvCookiePrefix = `${OVERRIDES_COOKIE_PREFIX}:env:`;
334
+
335
+ // src/config/common/host.ts
336
+ var Host = class {
337
+ constructor({ protocol, host, port }) {
338
+ this.protocol = protocol || "https";
339
+ this.host = host;
340
+ this.port = Host.getPort({ port, protocol: this.protocol });
341
+ this.serialized = {
342
+ protocol,
343
+ host,
344
+ ...port ? { port } : void 0
345
+ };
346
+ }
347
+ isLocal() {
348
+ return this.host === "localhost" || this.host === "127.0.0.1";
349
+ }
350
+ static getPort({
351
+ protocol,
352
+ port
353
+ }) {
354
+ if (!port) {
355
+ if (protocol === "http") {
356
+ return 80;
357
+ }
358
+ return 443;
359
+ }
360
+ return port;
361
+ }
362
+ isDefaultPort() {
363
+ return this.port === Host.getPort({ protocol: this.protocol });
364
+ }
365
+ toString(opts = {}) {
366
+ const url = this.toUrl(opts);
367
+ return url.toString().replace(/\/$/, "");
368
+ }
369
+ toUrl(opts = {}) {
370
+ const { includeDefaultPort } = opts;
371
+ const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
372
+ return new URL(url);
373
+ }
374
+ serialize() {
375
+ return this.serialized;
376
+ }
377
+ };
378
+
379
+ // src/config/common/application.ts
380
+ var Application = class {
381
+ constructor(name, {
382
+ app,
383
+ overrides
384
+ }) {
385
+ Application.validate(name, app);
386
+ this.name = name;
387
+ this.default = app.default;
388
+ this.routing = app.routing;
389
+ this.development = {
390
+ local: new Host(app.development.local),
391
+ fallback: app.development.fallback ? new Host(app.development.fallback) : void 0
392
+ };
393
+ this.production = new Host(app.production);
394
+ this.vercel = app.vercel;
395
+ this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
396
+ environment: new Host(overrides.environment)
397
+ } : void 0;
398
+ }
399
+ isDefault() {
400
+ return this.default;
401
+ }
402
+ static validate(name, app) {
403
+ var _a, _b, _c, _d, _e;
404
+ 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("/"))) {
405
+ throw new MicroFrontendError(
406
+ `Invalid assetPrefix for application "${name}". Must not start or end with a slash.`,
407
+ { type: "zone", subtype: "invalid_asset_prefix" }
408
+ );
409
+ }
410
+ for (const group of ((_e = app.routing) == null ? void 0 : _e.matches) ?? []) {
411
+ for (const p of group.paths) {
412
+ if (p === "/") {
413
+ continue;
414
+ }
415
+ if (p.endsWith("/")) {
416
+ throw new MicroFrontendError(
417
+ `Invalid path for application "${name}". ${p} must not end with a slash.`,
418
+ { type: "zone", subtype: "invalid_path" }
419
+ );
420
+ }
421
+ if (!p.startsWith("/")) {
422
+ throw new MicroFrontendError(
423
+ `Invalid path for application "${name}". ${p} must start with a slash.`,
424
+ { type: "zone", subtype: "invalid_path" }
425
+ );
426
+ }
427
+ }
428
+ }
429
+ }
430
+ serialize() {
431
+ var _a, _b;
432
+ if (this.routing === void 0 || this.default) {
433
+ return {
434
+ default: true,
435
+ development: {
436
+ local: this.development.local.serialize(),
437
+ fallback: (_a = this.development.fallback) == null ? void 0 : _a.serialize()
438
+ },
439
+ production: this.production.serialize(),
440
+ vercel: this.vercel
441
+ };
442
+ }
443
+ return {
444
+ default: false,
445
+ routing: this.routing,
446
+ development: {
447
+ local: this.development.local.serialize(),
448
+ fallback: (_b = this.development.fallback) == null ? void 0 : _b.serialize()
449
+ },
450
+ production: this.production.serialize(),
451
+ vercel: this.vercel
452
+ };
453
+ }
454
+ };
455
+
456
+ // src/config/common/micro-frontend-config.ts
457
+ var SUPPORTED_VERSIONS = ["1"];
458
+ var DEFAULT_LOCAL_PROXY_PORT = 3024;
459
+ var MicroFrontendConfigCommon = class {
460
+ constructor({
461
+ config,
462
+ overrides
463
+ }) {
464
+ this.zones = {};
465
+ var _a, _b, _c;
466
+ if (!SUPPORTED_VERSIONS.includes(config.version)) {
467
+ throw new MicroFrontendError(
468
+ `Unsupported version: ${config.version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
469
+ ", "
470
+ )}`,
471
+ { type: "config", subtype: "unsupported_version" }
472
+ );
473
+ }
474
+ const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
475
+ this.overrides = overrides && !disableOverrides ? new Overrides(overrides) : void 0;
476
+ for (const [zoneName, zoneConfig] of Object.entries(config.applications)) {
477
+ this.zones[zoneName] = new Application(zoneName, {
478
+ app: zoneConfig,
479
+ overrides: !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.config.applications[zoneName] : void 0
480
+ });
481
+ }
482
+ this.config = config;
483
+ this.name = config.name;
484
+ this.version = config.version;
485
+ this.options = config.options;
486
+ this.$schema = config.$schema;
487
+ }
488
+ isOverridesDisabled() {
489
+ var _a, _b;
490
+ return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
491
+ }
492
+ static getConfigFromEnv() {
493
+ const config = process.env.MFE_CONFIG;
494
+ if (!config) {
495
+ throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
496
+ type: "config",
497
+ subtype: "not_found_in_env"
498
+ });
499
+ }
500
+ return config;
501
+ }
502
+ static fromEnv(_) {
503
+ throw new Error("Not implemented");
504
+ }
505
+ getConfig() {
506
+ return this.config;
507
+ }
508
+ getAllApplications() {
509
+ return Object.values(this.zones);
510
+ }
511
+ getZone(name) {
512
+ const zone = this.zones[name];
513
+ if (!zone) {
514
+ throw new MicroFrontendError(
515
+ `Could not find micro-frontends configuration for application "${name}"`,
516
+ {
517
+ type: "zone",
518
+ subtype: "not_found"
519
+ }
520
+ );
521
+ }
522
+ return zone;
523
+ }
524
+ getApplicationByProjectId(projectId) {
525
+ return Object.values(this.zones).find(
526
+ (zone) => {
527
+ var _a;
528
+ return ((_a = zone.vercel) == null ? void 0 : _a.projectId) === projectId;
529
+ }
530
+ );
531
+ }
532
+ getDefaultZone() {
533
+ const zone = Object.values(this.zones).find((z) => z.default);
534
+ if (!zone) {
535
+ throw new MicroFrontendError(
536
+ `Could not find default zone in micro-frontends configuration`,
537
+ {
538
+ type: "zone",
539
+ subtype: "not_found"
540
+ }
541
+ );
542
+ }
543
+ return zone;
544
+ }
545
+ /**
546
+ * Returns the configured port for the local proxy
547
+ */
548
+ getLocalProxyPort() {
549
+ var _a, _b;
550
+ return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
551
+ }
552
+ /**
553
+ * Serializes the class back to the Schema type.
554
+ *
555
+ * NOTE: This is used when writing the config to disk and must always match the input Schema
556
+ */
557
+ toSchemaJson() {
558
+ const applications = {};
559
+ for (const [name, zone] of Object.entries(this.zones)) {
560
+ applications[name] = zone.serialize();
561
+ }
562
+ return {
563
+ $schema: this.$schema,
564
+ name: this.name,
565
+ version: this.version,
566
+ options: this.options,
567
+ applications
568
+ };
569
+ }
570
+ serialize() {
571
+ var _a;
572
+ const applications = {};
573
+ for (const [name, zone] of Object.entries(this.zones)) {
574
+ applications[name] = zone.serialize();
575
+ }
576
+ return {
577
+ config: {
578
+ name: this.name,
579
+ version: this.version,
580
+ applications,
581
+ options: this.options,
582
+ $schema: this.$schema
583
+ },
584
+ overrides: (_a = this.overrides) == null ? void 0 : _a.serialize()
585
+ };
586
+ }
587
+ write(_) {
588
+ throw new MicroFrontendError(
589
+ `Writing to file to disk requires using an instance of "MicroFrontendConfig".`,
590
+ { type: "config", subtype: "unsupported_operation" }
591
+ );
592
+ }
593
+ };
594
+
595
+ // src/config/utils/get-output-file-path.ts
596
+ var import_node_path2 = __toESM(require("path"), 1);
597
+
598
+ // src/config/constants.ts
599
+ var MFE_CONFIG_DEFAULT_FILE_PATH2 = "micro-frontends";
600
+ var MFE_CONFIG_DEFAULT_FILE_NAME2 = "micro-frontends.config.json";
601
+
602
+ // src/config/utils/get-output-file-path.ts
603
+ function getOutputFilePath2() {
604
+ if (isVercel()) {
605
+ return import_node_path2.default.join(
606
+ ".vercel",
607
+ MFE_CONFIG_DEFAULT_FILE_PATH2,
608
+ MFE_CONFIG_DEFAULT_FILE_NAME2
609
+ );
610
+ }
611
+ return import_node_path2.default.join(MFE_CONFIG_DEFAULT_FILE_PATH2, MFE_CONFIG_DEFAULT_FILE_NAME2);
612
+ }
613
+
614
+ // src/config/validation.ts
615
+ var import_jsonc_parser = require("jsonc-parser");
616
+ var import_path_to_regexp = require("path-to-regexp");
617
+ var import_ajv = require("ajv");
618
+
619
+ // schema/schema.json
620
+ var schema_default = {
621
+ $schema: "http://json-schema.org/draft-07/schema#",
622
+ $ref: "#/definitions/Config",
623
+ definitions: {
624
+ Config: {
625
+ type: "object",
626
+ properties: {
627
+ version: {
628
+ type: "string"
629
+ },
630
+ $schema: {
631
+ type: "string"
632
+ },
633
+ name: {
634
+ type: "string",
635
+ description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
636
+ },
637
+ applications: {
638
+ $ref: "#/definitions/ApplicationConfigsById"
639
+ },
640
+ options: {
641
+ $ref: "#/definitions/Options",
642
+ description: "Optional configuration for the entire micro-frontends setup."
643
+ }
644
+ },
645
+ required: ["version", "applications"],
646
+ description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
647
+ },
648
+ ApplicationConfigsById: {
649
+ type: "object",
650
+ additionalProperties: {
651
+ $ref: "#/definitions/ApplicationConfig"
652
+ }
653
+ },
654
+ ApplicationConfig: {
655
+ anyOf: [
656
+ {
657
+ $ref: "#/definitions/DefaultApplicationConfig"
658
+ },
659
+ {
660
+ $ref: "#/definitions/CommonApplicationConfig"
661
+ }
662
+ ],
663
+ description: "A Micro-Frontend Deployment Target"
664
+ },
665
+ DefaultApplicationConfig: {
666
+ type: "object",
667
+ properties: {
668
+ default: {
669
+ type: "boolean",
670
+ const: true,
671
+ description: "The default application is used no other application is matched via the routing config"
672
+ },
673
+ routing: {
674
+ $ref: "#/definitions/Routing"
675
+ },
676
+ development: {
677
+ type: "object",
678
+ properties: {
679
+ local: {
680
+ $ref: "#/definitions/HostConfig"
681
+ },
682
+ fallback: {
683
+ $ref: "#/definitions/HostConfig",
684
+ description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
685
+ },
686
+ task: {
687
+ type: "string",
688
+ description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
689
+ }
690
+ },
691
+ required: ["local"]
692
+ },
693
+ production: {
694
+ $ref: "#/definitions/HostConfig"
695
+ },
696
+ metadata: {
697
+ type: "object",
698
+ additionalProperties: {
699
+ type: "string"
700
+ }
701
+ },
702
+ federation: {
703
+ type: "object",
704
+ properties: {
705
+ exposes: {
706
+ type: "array",
707
+ items: {
708
+ type: "object",
709
+ properties: {
710
+ name: {
711
+ type: "string",
712
+ description: "The name of the module - should be used when importing the module from another application"
713
+ },
714
+ path: {
715
+ type: "string",
716
+ description: "Relative path to the module within its `application`"
717
+ }
718
+ },
719
+ required: ["name", "path"]
720
+ },
721
+ description: "Modules that are exposed by this application"
722
+ },
723
+ uses: {
724
+ type: "array",
725
+ items: {
726
+ type: "string"
727
+ },
728
+ description: "Modules that are used by this application. Only the name of the module is required."
729
+ }
730
+ }
731
+ },
732
+ vercel: {
733
+ $ref: "#/definitions/Vercel"
734
+ }
735
+ },
736
+ required: ["default", "development", "production"]
737
+ },
738
+ Routing: {
739
+ type: "object",
740
+ properties: {
741
+ assetPrefix: {
742
+ type: "string",
743
+ description: "[assetPrefix] for the application"
744
+ },
745
+ matches: {
746
+ type: "array",
747
+ items: {
748
+ $ref: "#/definitions/PathGroup"
749
+ },
750
+ description: "Path expressions that are routed to this application."
751
+ }
752
+ },
753
+ required: ["matches"]
754
+ },
755
+ PathGroup: {
756
+ type: "object",
757
+ properties: {
758
+ group: {
759
+ type: "string",
760
+ description: "Optional group name for the paths"
761
+ },
762
+ options: {
763
+ type: "object",
764
+ properties: {
765
+ flag: {
766
+ type: "string",
767
+ description: "flag name that can be used to enable/disable all paths in the group"
768
+ },
769
+ routeToDefaultApplication: {
770
+ type: "boolean",
771
+ description: "True to route the request to the default application for this micro-frontends set-up. This must be `true` when using `flag` or when you want to use custom logic to make the routing decision for this group of paths."
772
+ }
773
+ }
774
+ },
775
+ paths: {
776
+ type: "array",
777
+ items: {
778
+ type: "string"
779
+ }
780
+ }
781
+ },
782
+ required: ["paths"]
783
+ },
784
+ HostConfig: {
785
+ type: "object",
786
+ properties: {
787
+ protocol: {
788
+ type: "string",
789
+ enum: ["http", "https"],
790
+ description: 'The protocol to be used for the connection.\n- `http`: Hypertext Transfer Protocol (HTTP).\n- `https`: Secure Hypertext Transfer Protocol (HTTPS).\n\n* @defaultValue "https"'
791
+ },
792
+ host: {
793
+ type: "string",
794
+ description: "The hostname or IP address of the server. This can be a domain name (e.g., `example.com`) or an IP address (e.g., `192.168.1.1`)."
795
+ },
796
+ port: {
797
+ type: "number",
798
+ description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS.\n\nThis field is optional and can be omitted if the default ports for the specified protocol are used"
799
+ }
800
+ },
801
+ required: ["host"]
802
+ },
803
+ Vercel: {
804
+ type: "object",
805
+ properties: {
806
+ projectId: {
807
+ type: "string",
808
+ description: "Vercel project ID"
809
+ },
810
+ projectName: {
811
+ type: "string",
812
+ description: "Vercel project name (temporary until we can use project ID)"
813
+ },
814
+ defaultRoute: {
815
+ type: "string",
816
+ description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
817
+ },
818
+ routeSpeedInsightsToDefaultZone: {
819
+ type: "boolean",
820
+ description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
821
+ }
822
+ },
823
+ required: ["projectId"]
824
+ },
825
+ CommonApplicationConfig: {
826
+ type: "object",
827
+ properties: {
828
+ default: {
829
+ type: "boolean",
830
+ const: false,
831
+ description: "The default application is used no other application is matched via the routing config"
832
+ },
833
+ routing: {
834
+ $ref: "#/definitions/Routing"
835
+ },
836
+ development: {
837
+ type: "object",
838
+ properties: {
839
+ local: {
840
+ $ref: "#/definitions/HostConfig"
841
+ },
842
+ fallback: {
843
+ $ref: "#/definitions/HostConfig",
844
+ description: "Fallback for local development, could be a host config that points to any environment. If this is not provided, or the application is not running - requests to the application in local development will error."
845
+ },
846
+ task: {
847
+ type: "string",
848
+ description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
849
+ }
850
+ },
851
+ required: ["local"]
852
+ },
853
+ production: {
854
+ $ref: "#/definitions/HostConfig"
855
+ },
856
+ metadata: {
857
+ type: "object",
858
+ additionalProperties: {
859
+ type: "string"
860
+ }
861
+ },
862
+ federation: {
863
+ type: "object",
864
+ properties: {
865
+ exposes: {
866
+ type: "array",
867
+ items: {
868
+ type: "object",
869
+ properties: {
870
+ name: {
871
+ type: "string",
872
+ description: "The name of the module - should be used when importing the module from another application"
873
+ },
874
+ path: {
875
+ type: "string",
876
+ description: "Relative path to the module within its `application`"
877
+ }
878
+ },
879
+ required: ["name", "path"]
880
+ },
881
+ description: "Modules that are exposed by this application"
882
+ },
883
+ uses: {
884
+ type: "array",
885
+ items: {
886
+ type: "string"
887
+ },
888
+ description: "Modules that are used by this application. Only the name of the module is required."
889
+ }
890
+ }
891
+ },
892
+ vercel: {
893
+ $ref: "#/definitions/Vercel"
894
+ }
895
+ },
896
+ required: ["default", "development", "production", "routing"]
897
+ },
898
+ Options: {
899
+ type: "object",
900
+ properties: {
901
+ vercel: {
902
+ $ref: "#/definitions/VercelOptions",
903
+ description: "Micro-Frontends wide options for Vercel."
904
+ },
905
+ localProxy: {
906
+ $ref: "#/definitions/LocalProxyOptions",
907
+ description: "Options for local proxy."
908
+ }
909
+ }
910
+ },
911
+ VercelOptions: {
912
+ type: "object",
913
+ properties: {
914
+ previewDeploymentSuffix: {
915
+ type: "string",
916
+ description: "If your team uses a custom Preview Deployment Suffix, please specify it here. See https://vercel.com/docs/deployments/preview-deployment-suffix. The default is `vercel.app`."
917
+ },
918
+ teamSlug: {
919
+ type: "string",
920
+ description: "Team slug for the Vercel team"
921
+ },
922
+ disableOverrides: {
923
+ type: "boolean",
924
+ description: "If you want to disable the overrides for the site. For example, if you are managing rewrites between applications externally, you may wish to disable the overrides on the toolbar as they will have no effect."
925
+ }
926
+ }
927
+ },
928
+ LocalProxyOptions: {
929
+ type: "object",
930
+ properties: {
931
+ port: {
932
+ type: "number",
933
+ description: "The port number used by the local proxy server.\n\nThe default is `3024`."
934
+ }
935
+ }
936
+ }
937
+ }
938
+ };
939
+
940
+ // src/config/utils/load-schema.ts
941
+ var SCHEMA = schema_default;
942
+
943
+ // src/config/validation.ts
944
+ var validateSchema = (configString) => {
945
+ const parsedConfig = (0, import_jsonc_parser.parse)(configString);
946
+ const ajv = new import_ajv.Ajv();
947
+ const validate = ajv.compile(SCHEMA);
948
+ const isValid = validate(parsedConfig);
949
+ if (!isValid) {
950
+ throw new MicroFrontendError(
951
+ `Invalid config: ${ajv.errorsText(validate.errors)}`,
952
+ { type: "config", subtype: "does_not_match_schema" }
953
+ );
954
+ }
955
+ return parsedConfig;
956
+ };
957
+ var SUPPORTED_VERSIONS2 = ["1"];
958
+ var validateVersion = (version) => {
959
+ if (!SUPPORTED_VERSIONS2.includes(version)) {
960
+ throw new MicroFrontendError(
961
+ `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS2.join(
962
+ ", "
963
+ )}`,
964
+ { type: "config", subtype: "unsupported_version" }
965
+ );
966
+ }
967
+ };
968
+ function validateMainPath(applicationConfigsById) {
969
+ for (const [id, app] of Object.entries(applicationConfigsById)) {
970
+ const { defaultRoute } = app.vercel ?? {};
971
+ if (!defaultRoute) {
972
+ continue;
973
+ }
974
+ if (isDefaultApplicationConfig(app)) {
975
+ const pathsWithApp = [];
976
+ for (const [otherId, otherApp] of Object.entries(
977
+ applicationConfigsById
978
+ )) {
979
+ if (isDefaultApplicationConfig(otherApp)) {
980
+ continue;
981
+ }
982
+ pathsWithApp.push({
983
+ id: otherId,
984
+ paths: otherApp.routing.matches.flatMap((match) => match.paths)
985
+ });
986
+ }
987
+ for (const { id: otherId, paths } of pathsWithApp) {
988
+ const isValid = paths.every((path3) => {
989
+ const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
990
+ return !matcher.test(defaultRoute);
991
+ });
992
+ if (!isValid) {
993
+ throw new MicroFrontendError(
994
+ `default route "${defaultRoute}" cannot be used for "${id}" because it is matched by "${otherId}"`,
995
+ { type: "config", subtype: "invalid_main_path" }
996
+ );
997
+ }
998
+ }
999
+ } else {
1000
+ const allPaths = app.routing.matches.flatMap((match) => match.paths);
1001
+ const isValid = allPaths.some((path3) => {
1002
+ const matcher = (0, import_path_to_regexp.pathToRegexp)(path3);
1003
+ return matcher.test(defaultRoute);
1004
+ });
1005
+ if (!isValid) {
1006
+ throw new MicroFrontendError(
1007
+ `default route "${defaultRoute}" is not included by the routing config for application "${id}"`,
1008
+ { type: "config", subtype: "invalid_main_path" }
1009
+ );
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+ var validatePaths = (applicationConfigsById) => {
1015
+ const pathsByApplicationId = /* @__PURE__ */ new Map();
1016
+ const errors = [];
1017
+ for (const [id, app] of Object.entries(applicationConfigsById)) {
1018
+ if (isDefaultApplicationConfig(app)) {
1019
+ continue;
1020
+ }
1021
+ for (const pathMatch of app.routing.matches) {
1022
+ for (const path3 of pathMatch.paths) {
1023
+ const maybeError = validatePathExpression(path3);
1024
+ if (maybeError) {
1025
+ errors.push(maybeError);
1026
+ }
1027
+ const existing = pathsByApplicationId.get(path3);
1028
+ if (existing) {
1029
+ existing.applications.push(id);
1030
+ } else {
1031
+ pathsByApplicationId.set(path3, {
1032
+ applications: [id],
1033
+ matcher: (0, import_path_to_regexp.pathToRegexp)(path3),
1034
+ applicationId: id
1035
+ });
1036
+ }
1037
+ }
1038
+ }
1039
+ }
1040
+ const entries = Array.from(pathsByApplicationId.entries());
1041
+ entries.forEach(([path3, { applications: ids, matcher, applicationId }]) => {
1042
+ if (ids.length > 1) {
1043
+ errors.push(
1044
+ `Duplicate path "${path3}" for applications "${ids.join(", ")}"`
1045
+ );
1046
+ }
1047
+ entries.forEach(
1048
+ ([
1049
+ matchPath,
1050
+ { applications: matchIds, applicationId: matchApplicationId }
1051
+ ]) => {
1052
+ if (path3 === matchPath) {
1053
+ return;
1054
+ }
1055
+ if (applicationId === matchApplicationId) {
1056
+ return;
1057
+ }
1058
+ if (matcher.test(matchPath)) {
1059
+ const source = `"${path3}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
1060
+ const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
1061
+ errors.push(
1062
+ `Overlapping path detected between ${source} and ${destination}`
1063
+ );
1064
+ }
1065
+ }
1066
+ );
1067
+ });
1068
+ if (errors.length) {
1069
+ throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
1070
+ type: "config",
1071
+ subtype: "conflicting_paths"
1072
+ });
1073
+ }
1074
+ };
1075
+ var PATH_DEFAULT_PATTERN = "[^\\/#\\?]+?";
1076
+ function validatePathExpression(path3) {
1077
+ const tokens = (0, import_path_to_regexp.parse)(path3);
1078
+ for (let i = 0; i < tokens.length; i++) {
1079
+ const token = tokens[i];
1080
+ if (token === void 0) {
1081
+ return `token ${i} in ${path3} is undefined, this shouldn't happen`;
1082
+ }
1083
+ if (typeof token !== "string") {
1084
+ if (token.pattern !== PATH_DEFAULT_PATTERN) {
1085
+ return `Path ${path3} cannot use a regular expression wildcard`;
1086
+ }
1087
+ if (token.prefix !== "/") {
1088
+ return `Wildcard :${token.name} must be immediately after a / in ${path3}`;
1089
+ }
1090
+ if (token.suffix) {
1091
+ return `Wildcard suffix on :${token.name} is not allowed. Suffixes are not supported`;
1092
+ }
1093
+ if (token.modifier && i !== tokens.length - 1) {
1094
+ return `Modifier ${token.modifier} is not allowed on wildcard :${token.name} in ${path3}. Modifiers are only allowed in the last path component`;
1095
+ }
1096
+ }
1097
+ }
1098
+ return void 0;
1099
+ }
1100
+ var validateDefaults = (applicationConfigsById) => {
1101
+ const defaultApplicationIds = Object.entries(applicationConfigsById).reduce((acc, [id, app]) => app.default ? [...acc, id] : acc, []);
1102
+ if (defaultApplicationIds.length === 0) {
1103
+ throw new MicroFrontendError(
1104
+ `No default application found. At least one application must be marked as default.`,
1105
+ { type: "config", subtype: "no_default_application" }
1106
+ );
1107
+ }
1108
+ if (defaultApplicationIds.length > 1) {
1109
+ throw new MicroFrontendError(
1110
+ `Only one default application is allowed. Found ${defaultApplicationIds.join(", ")}.`,
1111
+ { type: "config", subtype: "multiple_default_applications" }
1112
+ );
1113
+ }
1114
+ };
1115
+ var validateOptions = (options) => {
1116
+ var _a;
1117
+ if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
1118
+ if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
1119
+ options.vercel.previewDeploymentSuffix
1120
+ )) {
1121
+ throw new MicroFrontendError(
1122
+ `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
1123
+ { type: "config", subtype: "invalid_preview_deployment_suffix" }
1124
+ );
1125
+ }
1126
+ }
1127
+ };
1128
+
1129
+ // src/config/utils/convert.ts
1130
+ function convertV1RoutingToV2Routing(routing) {
1131
+ return routing.matches.map((group) => {
1132
+ var _a, _b;
1133
+ return {
1134
+ group: group.group,
1135
+ flag: (_a = group.options) == null ? void 0 : _a.flag,
1136
+ routeToDefaultApplication: (_b = group.options) == null ? void 0 : _b.routeToDefaultApplication,
1137
+ paths: group.paths
1138
+ };
1139
+ });
1140
+ }
1141
+ function convertV1ApplicationToV2Application(application) {
1142
+ const common = {
1143
+ production: application.production,
1144
+ development: application.development,
1145
+ vercel: application.vercel
1146
+ };
1147
+ if (application.default) {
1148
+ return common;
1149
+ }
1150
+ return {
1151
+ ...common,
1152
+ routing: convertV1RoutingToV2Routing(application.routing)
1153
+ };
1154
+ }
1155
+ function convertV1ConfigToV2Config(config, fromApp) {
1156
+ if (!config.applications[fromApp]) {
1157
+ throw new Error(`Application "${fromApp}" not found in the config`);
1158
+ }
1159
+ const common = {
1160
+ version: "2",
1161
+ options: config.options
1162
+ };
1163
+ if (config.applications[fromApp].default) {
1164
+ return {
1165
+ ...common,
1166
+ // this is assumed for now, and by the time this is released we won't need this conversion
1167
+ provider: "vercel",
1168
+ applications: Object.fromEntries(
1169
+ Object.entries(config.applications).map(([id, application]) => [
1170
+ id,
1171
+ convertV1ApplicationToV2Application(application)
1172
+ ])
1173
+ )
1174
+ };
1175
+ }
1176
+ return {
1177
+ ...common,
1178
+ partOf: fromApp
1179
+ };
1180
+ }
1181
+
1182
+ // src/config/utils/write-file.ts
1183
+ var import_node_fs = __toESM(require("fs"), 1);
1184
+ var import_node_path3 = require("path");
1185
+ function writeFile(outputPath, config, prettify) {
1186
+ import_node_fs.default.mkdirSync((0, import_node_path3.dirname)(outputPath), { recursive: true });
1187
+ import_node_fs.default.writeFileSync(
1188
+ outputPath,
1189
+ JSON.stringify(config, null, prettify ? 2 : void 0)
1190
+ );
1191
+ }
1192
+
1193
+ // src/config/micro-frontend-config.ts
1194
+ var MicroFrontendConfig = class extends MicroFrontendConfigCommon {
1195
+ static validate(configString) {
1196
+ const config = validateSchema(configString);
1197
+ validateVersion(config.version);
1198
+ validatePaths(config.applications);
1199
+ validateMainPath(config.applications);
1200
+ validateDefaults(config.applications);
1201
+ validateOptions(config.options);
1202
+ return config;
1203
+ }
1204
+ static fromEnv({
1205
+ cookies
1206
+ }) {
1207
+ return new MicroFrontendConfigCommon({
1208
+ config: MicroFrontendConfig.validate(
1209
+ MicroFrontendConfigCommon.getConfigFromEnv()
1210
+ ),
1211
+ overrides: Overrides.parseOverrides(cookies)
1212
+ });
1213
+ }
1214
+ static fromFile({
1215
+ filePath
1216
+ }) {
1217
+ try {
1218
+ const config = import_node_fs2.default.readFileSync(filePath, "utf-8");
1219
+ return new MicroFrontendConfig({
1220
+ config: MicroFrontendConfig.validate(config)
1221
+ });
1222
+ } catch (e) {
1223
+ throw MicroFrontendError.handle(e, {
1224
+ fileName: filePath
1225
+ });
1226
+ }
1227
+ }
1228
+ /**
1229
+ * Writes the configuration to a file.
1230
+ */
1231
+ write(fromApp, opts = {}) {
1232
+ const { pretty = true, versions = ["v1", "v2"] } = opts;
1233
+ const config = this.toSchemaJson();
1234
+ if (versions.includes("v1")) {
1235
+ const outputPath = getOutputFilePath2();
1236
+ writeFile(outputPath, config, pretty);
1237
+ }
1238
+ if (versions.includes("v2")) {
1239
+ const outputPath = getOutputFilePath();
1240
+ const v2Config = convertV1ConfigToV2Config(config, fromApp);
1241
+ writeFile(outputPath, v2Config, pretty);
1242
+ }
1243
+ }
1244
+ };
1245
+ // Annotate the CommonJS export names for ESM import in node:
1246
+ 0 && (module.exports = {
1247
+ MicroFrontendConfig,
1248
+ getClientConfigFromEnv,
1249
+ getConfigForClient,
1250
+ getWellKnownClientData,
1251
+ isCommonApplicationConfig,
1252
+ isDefaultApplicationConfig
1253
+ });
1254
+ //# sourceMappingURL=config.cjs.map