@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,803 @@
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-v2/microfrontends/isomorphic/index.ts
21
+ var isomorphic_exports = {};
22
+ __export(isomorphic_exports, {
23
+ Microfrontends: () => Microfrontends
24
+ });
25
+ module.exports = __toCommonJS(isomorphic_exports);
26
+
27
+ // src/config-v2/microfrontends-config/isomorphic/index.ts
28
+ var import_jsonc_parser = require("jsonc-parser");
29
+
30
+ // src/config-v2/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/config-v2/microfrontends-config/utils/get-config-from-env.ts
123
+ function getConfigStringFromEnv() {
124
+ const config = process.env.MFE_CONFIG;
125
+ if (!config) {
126
+ throw new MicroFrontendError(`Missing "MFE_CONFIG" in environment.`, {
127
+ type: "config",
128
+ subtype: "not_found_in_env"
129
+ });
130
+ }
131
+ return config;
132
+ }
133
+
134
+ // src/config-v2/schema/utils/is-main-config.ts
135
+ function isMainConfig(c) {
136
+ return !("partOf" in c);
137
+ }
138
+
139
+ // src/config-v2/schema/utils/is-default-app.ts
140
+ function isDefaultApp(a) {
141
+ return !("routing" in a);
142
+ }
143
+
144
+ // src/config-v2/microfrontends-config/client/index.ts
145
+ var import_path_to_regexp = require("path-to-regexp");
146
+ var MicroFrontendConfigClient = class {
147
+ constructor(config, opts) {
148
+ this.pathCache = {};
149
+ this.serialized = config;
150
+ if (opts == null ? void 0 : opts.removeFlaggedPaths) {
151
+ for (const app of Object.values(config.applications)) {
152
+ if (app.routing) {
153
+ app.routing = app.routing.filter((match) => !match.flag);
154
+ }
155
+ }
156
+ }
157
+ this.applications = config.applications;
158
+ }
159
+ /**
160
+ * Create a new `MicroFrontendConfigClient` from a JSON string.
161
+ * Config must be passed in to remain framework agnostic
162
+ */
163
+ static fromEnv(config, opts) {
164
+ if (!config) {
165
+ throw new Error("No micro-frontends configuration found");
166
+ }
167
+ return new MicroFrontendConfigClient(
168
+ JSON.parse(config),
169
+ opts
170
+ );
171
+ }
172
+ isEqual(other) {
173
+ return JSON.stringify(this.applications) === JSON.stringify(other.applications);
174
+ }
175
+ getApplicationNameForPath(path) {
176
+ if (!path.startsWith("/")) {
177
+ throw new Error(`Path must start with a /`);
178
+ }
179
+ if (this.pathCache[path]) {
180
+ return this.pathCache[path];
181
+ }
182
+ const pathname = new URL(path, "https://example.com").pathname;
183
+ for (const [name, application] of Object.entries(this.applications)) {
184
+ if (application.routing) {
185
+ for (const group of application.routing) {
186
+ for (const childPath of group.paths) {
187
+ const regexp = (0, import_path_to_regexp.pathToRegexp)(childPath);
188
+ if (regexp.test(pathname)) {
189
+ this.pathCache[path] = name;
190
+ return name;
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ const defaultApplication = Object.entries(this.applications).find(
197
+ ([, application]) => application.default
198
+ );
199
+ if (!defaultApplication) {
200
+ return null;
201
+ }
202
+ this.pathCache[path] = defaultApplication[0];
203
+ return defaultApplication[0];
204
+ }
205
+ serialize() {
206
+ return this.serialized;
207
+ }
208
+ };
209
+
210
+ // src/config-v2/overrides/constants.ts
211
+ var OVERRIDES_COOKIE_PREFIX = "vercel-microfrontends-override";
212
+ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
213
+
214
+ // src/config-v2/overrides/is-override-cookie.ts
215
+ function isOverrideCookie(cookie) {
216
+ var _a;
217
+ return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
218
+ }
219
+
220
+ // src/config-v2/overrides/get-override-from-cookie.ts
221
+ function getOverrideFromCookie(cookie) {
222
+ if (!isOverrideCookie(cookie) || !cookie.value)
223
+ return;
224
+ return {
225
+ application: cookie.name.replace(OVERRIDES_ENV_COOKIE_PREFIX, ""),
226
+ host: cookie.value
227
+ };
228
+ }
229
+
230
+ // src/config-v2/overrides/parse-overrides.ts
231
+ function parseOverrides(cookies) {
232
+ const overridesConfig = { applications: {} };
233
+ cookies.forEach((cookie) => {
234
+ const override = getOverrideFromCookie(cookie);
235
+ if (!override)
236
+ return;
237
+ overridesConfig.applications[override.application] = {
238
+ environment: { host: override.host }
239
+ };
240
+ });
241
+ return overridesConfig;
242
+ }
243
+
244
+ // src/config-v2/microfrontends-config/isomorphic/validation.ts
245
+ var import_path_to_regexp2 = require("path-to-regexp");
246
+ var SUPPORTED_VERSIONS = ["2"];
247
+ var validateConfigVersion = (version) => {
248
+ if (!SUPPORTED_VERSIONS.includes(version)) {
249
+ throw new MicroFrontendError(
250
+ `Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
251
+ ", "
252
+ )}`,
253
+ { type: "config", subtype: "unsupported_version" }
254
+ );
255
+ }
256
+ };
257
+ var validateConfigPaths = (applicationConfigsById) => {
258
+ if (!applicationConfigsById) {
259
+ return;
260
+ }
261
+ const pathsByApplicationId = /* @__PURE__ */ new Map();
262
+ const errors = [];
263
+ for (const [id, app] of Object.entries(applicationConfigsById)) {
264
+ if (isDefaultApp(app)) {
265
+ continue;
266
+ }
267
+ for (const pathMatch of app.routing) {
268
+ for (const path of pathMatch.paths) {
269
+ const tokens = (0, import_path_to_regexp2.parse)(path);
270
+ for (const token of tokens.slice(0, -1)) {
271
+ if (typeof token !== "string") {
272
+ errors.push(
273
+ `Path ${path} may only have a :wildcard in the last path component`
274
+ );
275
+ }
276
+ }
277
+ const existing = pathsByApplicationId.get(path);
278
+ if (existing) {
279
+ existing.applications.push(id);
280
+ } else {
281
+ pathsByApplicationId.set(path, {
282
+ applications: [id],
283
+ matcher: (0, import_path_to_regexp2.pathToRegexp)(path),
284
+ applicationId: id
285
+ });
286
+ }
287
+ }
288
+ }
289
+ }
290
+ const entries = Array.from(pathsByApplicationId.entries());
291
+ entries.forEach(([path, { applications: ids, matcher, applicationId }]) => {
292
+ if (ids.length > 1) {
293
+ errors.push(
294
+ `Duplicate path "${path}" for applications "${ids.join(", ")}"`
295
+ );
296
+ }
297
+ entries.forEach(
298
+ ([
299
+ matchPath,
300
+ { applications: matchIds, applicationId: matchApplicationId }
301
+ ]) => {
302
+ if (path === matchPath) {
303
+ return;
304
+ }
305
+ if (applicationId === matchApplicationId) {
306
+ return;
307
+ }
308
+ if (matcher.test(matchPath)) {
309
+ const source = `"${path}" of application${ids.length > 0 ? "s" : ""} ${ids.join(", ")}`;
310
+ const destination = `"${matchPath}" of application${matchIds.length > 0 ? "s" : ""} ${matchIds.join(", ")}`;
311
+ errors.push(
312
+ `Overlapping path detected between ${source} and ${destination}`
313
+ );
314
+ }
315
+ }
316
+ );
317
+ });
318
+ if (errors.length) {
319
+ throw new MicroFrontendError(`Invalid paths: ${errors.join(", ")}`, {
320
+ type: "config",
321
+ subtype: "conflicting_paths"
322
+ });
323
+ }
324
+ };
325
+ var validateAppPaths = (name, app) => {
326
+ for (const group of app.routing) {
327
+ for (const p of group.paths) {
328
+ if (p === "/") {
329
+ continue;
330
+ }
331
+ if (p.endsWith("/")) {
332
+ throw new MicroFrontendError(
333
+ `Invalid path for application "${name}". ${p} must not end with a slash.`,
334
+ { type: "application", subtype: "invalid_path" }
335
+ );
336
+ }
337
+ if (!p.startsWith("/")) {
338
+ throw new MicroFrontendError(
339
+ `Invalid path for application "${name}". ${p} must start with a slash.`,
340
+ { type: "application", subtype: "invalid_path" }
341
+ );
342
+ }
343
+ }
344
+ }
345
+ };
346
+ var validateConfigDefaultApplication = (applicationConfigsById) => {
347
+ if (!applicationConfigsById) {
348
+ return;
349
+ }
350
+ const applicationsWithRouting = Object.entries(applicationConfigsById).filter(
351
+ ([, app]) => !isDefaultApp(app)
352
+ );
353
+ const applicationsWithRoutingNames = applicationsWithRouting.map(
354
+ ([key]) => key
355
+ );
356
+ const numApplications = Object.keys(applicationConfigsById).length;
357
+ const numApplicationsWithRouting = applicationsWithRoutingNames.length;
358
+ const numApplicationsWithoutRouting = numApplications - numApplicationsWithRouting;
359
+ if (numApplicationsWithoutRouting === 0) {
360
+ throw new MicroFrontendError(
361
+ `No default application found. At least one application needs to be the default by omitting routing.`,
362
+ { type: "config", subtype: "no_default_application" }
363
+ );
364
+ }
365
+ if (numApplicationsWithoutRouting > 1) {
366
+ throw new MicroFrontendError(
367
+ `Only one application can omit "routing". Found ${applicationsWithRoutingNames.length - Object.keys(applicationConfigsById).length > 1}.`,
368
+ { type: "config", subtype: "multiple_default_applications" }
369
+ );
370
+ }
371
+ };
372
+ var validateConfigOptions = (options) => {
373
+ var _a;
374
+ if ((_a = options == null ? void 0 : options.vercel) == null ? void 0 : _a.previewDeploymentSuffix) {
375
+ if (!/^[a-zA-Z]{2,}\.[a-zA-Z]{2,}$/.test(
376
+ options.vercel.previewDeploymentSuffix
377
+ )) {
378
+ throw new MicroFrontendError(
379
+ `Invalid preview deployment suffix: ${options.vercel.previewDeploymentSuffix}. Should have be formatted like "vercel.app".`,
380
+ { type: "config", subtype: "invalid_preview_deployment_suffix" }
381
+ );
382
+ }
383
+ }
384
+ };
385
+
386
+ // src/config-v2/microfrontends-config/isomorphic/utils/generate-asset-prefix.ts
387
+ var PREFIX = "vc-ap";
388
+ function generateAssetPrefixFromName({
389
+ name
390
+ }) {
391
+ if (!name) {
392
+ throw new Error("Name is required to generate an asset prefix");
393
+ }
394
+ return `${PREFIX}-${name}`;
395
+ }
396
+
397
+ // src/config-v2/microfrontends-config/isomorphic/utils/generate-port.ts
398
+ function generatePortFromName({
399
+ name,
400
+ minPort = 3e3,
401
+ maxPort = 8e3
402
+ }) {
403
+ if (!name) {
404
+ throw new Error("Name is required to generate a port");
405
+ }
406
+ let hash = 0;
407
+ for (let i = 0; i < name.length; i++) {
408
+ hash = (hash << 5) - hash + name.charCodeAt(i);
409
+ hash |= 0;
410
+ }
411
+ hash = Math.abs(hash);
412
+ const range = maxPort - minPort;
413
+ const port = minPort + hash % range;
414
+ return port;
415
+ }
416
+
417
+ // src/config-v2/microfrontends-config/isomorphic/host.ts
418
+ var Host = class {
419
+ constructor(hostConfig, options) {
420
+ const { protocol = "https", host, port } = hostConfig;
421
+ this.protocol = protocol;
422
+ this.host = host;
423
+ this.port = Host.getPort({ port, protocol: this.protocol });
424
+ this.local = options == null ? void 0 : options.isLocal;
425
+ }
426
+ isLocal() {
427
+ return this.local || this.host === "localhost" || this.host === "127.0.0.1";
428
+ }
429
+ static getPort({
430
+ protocol,
431
+ port
432
+ }) {
433
+ if (!port) {
434
+ if (protocol === "http") {
435
+ return 80;
436
+ }
437
+ return 443;
438
+ }
439
+ return port;
440
+ }
441
+ isDefaultPort() {
442
+ return this.port === Host.getPort({ protocol: this.protocol });
443
+ }
444
+ toString(opts = {}) {
445
+ const url = this.toUrl(opts);
446
+ return url.toString().replace(/\/$/, "");
447
+ }
448
+ toUrl(opts = {}) {
449
+ const { includeDefaultPort } = opts;
450
+ const url = `${this.protocol}://${this.host}${this.isDefaultPort() && !includeDefaultPort ? "" : `:${this.port}`}`;
451
+ return new URL(url);
452
+ }
453
+ };
454
+ var LocalHost = class extends Host {
455
+ constructor({
456
+ appName,
457
+ ...hostConfig
458
+ }) {
459
+ const host = hostConfig.host ?? "localhost";
460
+ const port = hostConfig.port ?? generatePortFromName({ name: appName });
461
+ const protocol = hostConfig.protocol ?? "http";
462
+ super({ protocol, host, port });
463
+ }
464
+ };
465
+
466
+ // src/config-v2/microfrontends-config/isomorphic/application.ts
467
+ var Application = class {
468
+ constructor(name, {
469
+ app,
470
+ overrides,
471
+ isDefault
472
+ }) {
473
+ var _a, _b;
474
+ this.name = name;
475
+ this.development = {
476
+ local: new LocalHost({
477
+ appName: name,
478
+ ...(_a = app.development) == null ? void 0 : _a.local
479
+ }),
480
+ fallback: ((_b = app.development) == null ? void 0 : _b.fallback) ? new Host(app.development.fallback) : void 0
481
+ };
482
+ this.production = app.production ? new Host(app.production) : void 0;
483
+ this.vercel = app.vercel;
484
+ this.overrides = (overrides == null ? void 0 : overrides.environment) ? {
485
+ environment: new Host(overrides.environment)
486
+ } : void 0;
487
+ this.default = isDefault ?? false;
488
+ this.serialized = app;
489
+ }
490
+ isDefault() {
491
+ return this.default;
492
+ }
493
+ getAssetPrefix() {
494
+ return generateAssetPrefixFromName({ name: this.name });
495
+ }
496
+ serialize() {
497
+ return this.serialized;
498
+ }
499
+ };
500
+ var DefaultApplication = class extends Application {
501
+ constructor(name, {
502
+ app,
503
+ overrides
504
+ }) {
505
+ super(name, {
506
+ app,
507
+ overrides,
508
+ isDefault: true
509
+ });
510
+ this.default = true;
511
+ this.production = new Host(app.production);
512
+ }
513
+ };
514
+ var ChildApplication = class extends Application {
515
+ constructor(name, {
516
+ app,
517
+ overrides
518
+ }) {
519
+ ChildApplication.validate(name, app);
520
+ super(name, {
521
+ app,
522
+ overrides,
523
+ isDefault: false
524
+ });
525
+ this.default = false;
526
+ this.routing = app.routing;
527
+ }
528
+ static validate(name, app) {
529
+ validateAppPaths(name, app);
530
+ }
531
+ };
532
+
533
+ // src/config-v2/microfrontends-config/isomorphic/constants.ts
534
+ var DEFAULT_LOCAL_PROXY_PORT = 3024;
535
+
536
+ // src/config-v2/microfrontends-config/isomorphic/index.ts
537
+ var MicroFrontendConfigIsomorphic = class {
538
+ constructor({
539
+ config,
540
+ overrides,
541
+ meta
542
+ }) {
543
+ this.childApplications = {};
544
+ var _a, _b, _c, _d;
545
+ MicroFrontendConfigIsomorphic.validate(config);
546
+ const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
547
+ this.overrides = overrides && !disableOverrides ? overrides : void 0;
548
+ this.isMainConfig = isMainConfig(config);
549
+ if (isMainConfig(config)) {
550
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
551
+ const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
552
+ if (isDefaultApp(appConfig)) {
553
+ this.defaultApplication = new DefaultApplication(appId, {
554
+ app: appConfig,
555
+ overrides: appOverrides
556
+ });
557
+ } else {
558
+ this.childApplications[appId] = new ChildApplication(appId, {
559
+ app: appConfig,
560
+ overrides: appOverrides
561
+ });
562
+ }
563
+ }
564
+ } else {
565
+ this.partOf = config.partOf;
566
+ const appOverrides = !disableOverrides ? (_d = this.overrides) == null ? void 0 : _d.applications[meta.fromApp] : void 0;
567
+ this.childApplications[meta.fromApp] = new ChildApplication(
568
+ meta.fromApp,
569
+ {
570
+ // we don't know routing because we're not in the main config
571
+ app: { routing: [] },
572
+ overrides: appOverrides
573
+ }
574
+ );
575
+ }
576
+ if (isMainConfig(config) && !this.defaultApplication) {
577
+ throw new MicroFrontendError(
578
+ `Could not find default application in microfrontends configuration`,
579
+ {
580
+ type: "application",
581
+ subtype: "not_found"
582
+ }
583
+ );
584
+ }
585
+ this.config = config;
586
+ this.options = config.options;
587
+ this.serialized = {
588
+ config,
589
+ overrides,
590
+ meta
591
+ };
592
+ }
593
+ static validate(config) {
594
+ const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
595
+ if (isMainConfig(c)) {
596
+ validateConfigVersion(c.version);
597
+ validateConfigPaths(c.applications);
598
+ validateConfigDefaultApplication(c.applications);
599
+ }
600
+ validateConfigOptions(c.options);
601
+ return c;
602
+ }
603
+ static fromEnv({
604
+ meta,
605
+ cookies
606
+ }) {
607
+ return new MicroFrontendConfigIsomorphic({
608
+ config: (0, import_jsonc_parser.parse)(getConfigStringFromEnv()),
609
+ overrides: parseOverrides(cookies ?? []),
610
+ meta
611
+ });
612
+ }
613
+ isOverridesDisabled() {
614
+ var _a, _b;
615
+ return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
616
+ }
617
+ getConfig() {
618
+ return this.config;
619
+ }
620
+ getApplicationsByType() {
621
+ return {
622
+ defaultApplication: this.defaultApplication,
623
+ applications: Object.values(this.childApplications)
624
+ };
625
+ }
626
+ getChildApplications() {
627
+ return Object.values(this.childApplications);
628
+ }
629
+ getAllApplications() {
630
+ return [
631
+ this.defaultApplication,
632
+ ...Object.values(this.childApplications)
633
+ ].filter(Boolean);
634
+ }
635
+ getApplication(name) {
636
+ var _a;
637
+ if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
638
+ return this.defaultApplication;
639
+ }
640
+ const app = this.childApplications[name];
641
+ if (!app) {
642
+ throw new MicroFrontendError(
643
+ `Could not find microfrontends configuration for application "${name}"`,
644
+ {
645
+ type: "application",
646
+ subtype: "not_found"
647
+ }
648
+ );
649
+ }
650
+ return app;
651
+ }
652
+ getApplicationByProjectId(projectId) {
653
+ var _a, _b;
654
+ if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
655
+ return this.defaultApplication;
656
+ }
657
+ return Object.values(this.childApplications).find(
658
+ (app) => {
659
+ var _a2;
660
+ return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
661
+ }
662
+ );
663
+ }
664
+ /**
665
+ * Returns the default application. This can throw if the default application
666
+ * is undefined ( )
667
+ */
668
+ getDefaultApplication() {
669
+ if (!this.defaultApplication) {
670
+ throw new MicroFrontendError(
671
+ `Could not find default application in microfrontends configuration`,
672
+ {
673
+ type: "application",
674
+ subtype: "not_found"
675
+ }
676
+ );
677
+ }
678
+ return this.defaultApplication;
679
+ }
680
+ /**
681
+ * Returns the configured port for the local proxy
682
+ */
683
+ getLocalProxyPort() {
684
+ var _a, _b;
685
+ return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
686
+ }
687
+ /**
688
+ * Serializes the class back to the Schema type.
689
+ *
690
+ * NOTE: This is used when writing the config to disk and must always match the input Schema
691
+ */
692
+ toSchemaJson() {
693
+ return this.serialized.config;
694
+ }
695
+ toClientConfig() {
696
+ const applications = Object.fromEntries(
697
+ Object.entries(this.childApplications).map(([name, application]) => [
698
+ name,
699
+ {
700
+ default: false,
701
+ routing: application.routing
702
+ }
703
+ ])
704
+ );
705
+ if (this.defaultApplication) {
706
+ applications[this.defaultApplication.name] = {
707
+ default: true
708
+ };
709
+ }
710
+ return new MicroFrontendConfigClient({
711
+ applications
712
+ });
713
+ }
714
+ serialize() {
715
+ return this.serialized;
716
+ }
717
+ };
718
+
719
+ // src/config-v2/microfrontends-config/isomorphic/child.ts
720
+ var MicroFrontendChildConfig = class extends MicroFrontendConfigIsomorphic {
721
+ constructor({
722
+ config,
723
+ overrides,
724
+ meta
725
+ }) {
726
+ super({ config, overrides, meta });
727
+ this.isMainConfig = false;
728
+ this.partOf = config.partOf;
729
+ }
730
+ };
731
+
732
+ // src/config-v2/microfrontends-config/isomorphic/main.ts
733
+ var MicroFrontendMainConfig = class extends MicroFrontendConfigIsomorphic {
734
+ constructor({
735
+ config,
736
+ overrides,
737
+ meta
738
+ }) {
739
+ var _a, _b, _c;
740
+ super({ config, overrides, meta });
741
+ this.isMainConfig = true;
742
+ this.provider = config.provider;
743
+ const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
744
+ let defaultApplication;
745
+ for (const [appId, appConfig] of Object.entries(config.applications)) {
746
+ const appOverrides = !disableOverrides ? (_c = this.overrides) == null ? void 0 : _c.applications[appId] : void 0;
747
+ if (isDefaultApp(appConfig)) {
748
+ defaultApplication = new DefaultApplication(appId, {
749
+ app: appConfig,
750
+ overrides: appOverrides
751
+ });
752
+ } else {
753
+ this.childApplications[appId] = new ChildApplication(appId, {
754
+ app: appConfig,
755
+ overrides: appOverrides
756
+ });
757
+ }
758
+ }
759
+ if (!defaultApplication) {
760
+ throw new MicroFrontendError(
761
+ `Could not find default application in microfrontends configuration`,
762
+ {
763
+ type: "application",
764
+ subtype: "not_found"
765
+ }
766
+ );
767
+ }
768
+ this.defaultApplication = defaultApplication;
769
+ }
770
+ };
771
+
772
+ // src/config-v2/microfrontends/isomorphic/index.ts
773
+ var Microfrontends = class {
774
+ constructor({
775
+ config,
776
+ overrides,
777
+ meta
778
+ }) {
779
+ if (isMainConfig(config)) {
780
+ this.config = new MicroFrontendMainConfig({ config, overrides, meta });
781
+ } else {
782
+ this.config = new MicroFrontendChildConfig({ config, overrides, meta });
783
+ }
784
+ }
785
+ isChildConfig() {
786
+ return this.config instanceof MicroFrontendChildConfig;
787
+ }
788
+ static fromEnv({
789
+ cookies,
790
+ meta
791
+ }) {
792
+ const config = MicroFrontendConfigIsomorphic.fromEnv({
793
+ cookies,
794
+ meta
795
+ });
796
+ return new Microfrontends(config.serialize());
797
+ }
798
+ };
799
+ // Annotate the CommonJS export names for ESM import in node:
800
+ 0 && (module.exports = {
801
+ Microfrontends
802
+ });
803
+ //# sourceMappingURL=microfrontends.cjs.map