@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.
- package/README.md +202 -0
- package/cli/index.cjs +21 -0
- package/dist/bin/cli.cjs +1604 -0
- package/dist/config/client.cjs +54 -0
- package/dist/config/client.cjs.map +1 -0
- package/dist/config/client.d.ts +23 -0
- package/dist/config/client.js +28 -0
- package/dist/config/client.js.map +1 -0
- package/dist/config/edge.cjs +508 -0
- package/dist/config/edge.cjs.map +1 -0
- package/dist/config/edge.d.ts +20 -0
- package/dist/config/edge.js +481 -0
- package/dist/config/edge.js.map +1 -0
- package/dist/config.cjs +1254 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.ts +25 -0
- package/dist/config.js +1212 -0
- package/dist/config.js.map +1 -0
- package/dist/index-eff254d8.d.ts +175 -0
- package/dist/micro-frontend-config-42886104.d.ts +154 -0
- package/dist/next/client.cjs +3 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.ts +45 -0
- package/dist/next/client.js +3 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/config.cjs +1793 -0
- package/dist/next/config.cjs.map +1 -0
- package/dist/next/config.d.ts +22 -0
- package/dist/next/config.js +1758 -0
- package/dist/next/config.js.map +1 -0
- package/dist/next/endpoints.cjs +82 -0
- package/dist/next/endpoints.cjs.map +1 -0
- package/dist/next/endpoints.d.ts +15 -0
- package/dist/next/endpoints.js +57 -0
- package/dist/next/endpoints.js.map +1 -0
- package/dist/next/middleware.cjs +763 -0
- package/dist/next/middleware.cjs.map +1 -0
- package/dist/next/middleware.d.ts +29 -0
- package/dist/next/middleware.js +735 -0
- package/dist/next/middleware.js.map +1 -0
- package/dist/next/testing.cjs +1430 -0
- package/dist/next/testing.cjs.map +1 -0
- package/dist/next/testing.d.ts +53 -0
- package/dist/next/testing.js +1389 -0
- package/dist/next/testing.js.map +1 -0
- package/dist/overrides.cjs +143 -0
- package/dist/overrides.cjs.map +1 -0
- package/dist/overrides.d.ts +2 -0
- package/dist/overrides.js +115 -0
- package/dist/overrides.js.map +1 -0
- package/dist/schema-83a75e61.d.ts +188 -0
- package/dist/types-4fd1c7c6.d.ts +157 -0
- package/dist/v2/config.cjs +720 -0
- package/dist/v2/config.cjs.map +1 -0
- package/dist/v2/config.d.ts +2 -0
- package/dist/v2/config.js +695 -0
- package/dist/v2/config.js.map +1 -0
- package/dist/v2/microfrontends/server.cjs +1312 -0
- package/dist/v2/microfrontends/server.cjs.map +1 -0
- package/dist/v2/microfrontends/server.d.ts +48 -0
- package/dist/v2/microfrontends/server.js +1277 -0
- package/dist/v2/microfrontends/server.js.map +1 -0
- package/dist/v2/microfrontends.cjs +803 -0
- package/dist/v2/microfrontends.cjs.map +1 -0
- package/dist/v2/microfrontends.d.ts +44 -0
- package/dist/v2/microfrontends.js +776 -0
- package/dist/v2/microfrontends.js.map +1 -0
- package/dist/v2/next/client.cjs +3 -0
- package/dist/v2/next/client.cjs.map +1 -0
- package/dist/v2/next/client.d.ts +45 -0
- package/dist/v2/next/client.js +3 -0
- package/dist/v2/next/client.js.map +1 -0
- package/dist/v2/next/config.cjs +1829 -0
- package/dist/v2/next/config.cjs.map +1 -0
- package/dist/v2/next/config.d.ts +22 -0
- package/dist/v2/next/config.js +1794 -0
- package/dist/v2/next/config.js.map +1 -0
- package/dist/v2/next/endpoints.cjs +138 -0
- package/dist/v2/next/endpoints.cjs.map +1 -0
- package/dist/v2/next/endpoints.d.ts +15 -0
- package/dist/v2/next/endpoints.js +113 -0
- package/dist/v2/next/endpoints.js.map +1 -0
- package/dist/v2/next/middleware.cjs +1110 -0
- package/dist/v2/next/middleware.cjs.map +1 -0
- package/dist/v2/next/middleware.d.ts +29 -0
- package/dist/v2/next/middleware.js +1082 -0
- package/dist/v2/next/middleware.js.map +1 -0
- package/dist/v2/schema.cjs +19 -0
- package/dist/v2/schema.cjs.map +1 -0
- package/dist/v2/schema.d.ts +1 -0
- package/dist/v2/schema.js +1 -0
- package/dist/v2/schema.js.map +1 -0
- package/dist/validation.cjs +754 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.ts +163 -0
- package/dist/validation.js +726 -0
- package/dist/validation.js.map +1 -0
- package/package.json +204 -0
- package/schema/schema-v2.json +288 -0
- package/schema/schema.json +352 -0
|
@@ -0,0 +1,754 @@
|
|
|
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/schema/validation.ts
|
|
21
|
+
var validation_exports = {};
|
|
22
|
+
__export(validation_exports, {
|
|
23
|
+
validateV1Schema: () => validateSchema2,
|
|
24
|
+
validateV2Schema: () => validateSchema
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(validation_exports);
|
|
27
|
+
|
|
28
|
+
// src/config-v2/microfrontends/server/validation.ts
|
|
29
|
+
var import_jsonc_parser = require("jsonc-parser");
|
|
30
|
+
var import_ajv = require("ajv");
|
|
31
|
+
|
|
32
|
+
// src/config/errors.ts
|
|
33
|
+
var MicroFrontendError = class extends Error {
|
|
34
|
+
constructor(message, opts) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "MicroFrontendsError";
|
|
37
|
+
this.source = (opts == null ? void 0 : opts.source) ?? "@vercel/micro-frontends";
|
|
38
|
+
this.type = (opts == null ? void 0 : opts.type) ?? "unknown";
|
|
39
|
+
this.subtype = opts == null ? void 0 : opts.subtype;
|
|
40
|
+
Error.captureStackTrace(this, MicroFrontendError);
|
|
41
|
+
}
|
|
42
|
+
isKnown() {
|
|
43
|
+
return this.type !== "unknown";
|
|
44
|
+
}
|
|
45
|
+
isUnknown() {
|
|
46
|
+
return !this.isKnown();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Converts an error to a MicroFrontendsError.
|
|
50
|
+
* @param original - The original error to convert.
|
|
51
|
+
* @returns The converted MicroFrontendsError.
|
|
52
|
+
*/
|
|
53
|
+
static convert(original, opts) {
|
|
54
|
+
if (opts == null ? void 0 : opts.fileName) {
|
|
55
|
+
const err = MicroFrontendError.convertFSError(original, opts.fileName);
|
|
56
|
+
if (err) {
|
|
57
|
+
return err;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (original.message.includes(
|
|
61
|
+
"Code generation from strings disallowed for this context"
|
|
62
|
+
)) {
|
|
63
|
+
return new MicroFrontendError(original.message, {
|
|
64
|
+
type: "config",
|
|
65
|
+
subtype: "unsupported_validation_env",
|
|
66
|
+
source: "ajv"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return new MicroFrontendError(original.message);
|
|
70
|
+
}
|
|
71
|
+
static convertFSError(original, fileName) {
|
|
72
|
+
if (original instanceof Error && "code" in original) {
|
|
73
|
+
if (original.code === "ENOENT") {
|
|
74
|
+
return new MicroFrontendError(`Could not find "${fileName}"`, {
|
|
75
|
+
type: "config",
|
|
76
|
+
subtype: "unable_to_read_file",
|
|
77
|
+
source: "fs"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (original.code === "EACCES") {
|
|
81
|
+
return new MicroFrontendError(
|
|
82
|
+
`Permission denied while accessing "${fileName}"`,
|
|
83
|
+
{
|
|
84
|
+
type: "config",
|
|
85
|
+
subtype: "invalid_permissions",
|
|
86
|
+
source: "fs"
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (original instanceof SyntaxError) {
|
|
92
|
+
return new MicroFrontendError(
|
|
93
|
+
`Failed to parse "${fileName}": Invalid JSON format.`,
|
|
94
|
+
{
|
|
95
|
+
type: "config",
|
|
96
|
+
subtype: "invalid_syntax",
|
|
97
|
+
source: "fs"
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handles an unknown error and returns a MicroFrontendsError instance.
|
|
105
|
+
* @param err - The error to handle.
|
|
106
|
+
* @returns A MicroFrontendsError instance.
|
|
107
|
+
*/
|
|
108
|
+
static handle(err, opts) {
|
|
109
|
+
if (err instanceof MicroFrontendError) {
|
|
110
|
+
return err;
|
|
111
|
+
}
|
|
112
|
+
if (err instanceof Error) {
|
|
113
|
+
return MicroFrontendError.convert(err, opts);
|
|
114
|
+
}
|
|
115
|
+
if (typeof err === "object" && err !== null) {
|
|
116
|
+
if ("message" in err && typeof err.message === "string") {
|
|
117
|
+
return MicroFrontendError.convert(new Error(err.message), opts);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return new MicroFrontendError("An unknown error occurred");
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// schema/schema-v2.json
|
|
125
|
+
var schema_v2_default = {
|
|
126
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
127
|
+
$ref: "#/definitions/Config",
|
|
128
|
+
definitions: {
|
|
129
|
+
Config: {
|
|
130
|
+
anyOf: [
|
|
131
|
+
{
|
|
132
|
+
$ref: "#/definitions/MainConfig"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
$ref: "#/definitions/ChildConfig"
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
MainConfig: {
|
|
140
|
+
type: "object",
|
|
141
|
+
properties: {
|
|
142
|
+
$schema: {
|
|
143
|
+
type: "string"
|
|
144
|
+
},
|
|
145
|
+
version: {
|
|
146
|
+
type: "string",
|
|
147
|
+
const: "2"
|
|
148
|
+
},
|
|
149
|
+
options: {
|
|
150
|
+
$ref: "#/definitions/Options"
|
|
151
|
+
},
|
|
152
|
+
remotes: {
|
|
153
|
+
type: "object",
|
|
154
|
+
additionalProperties: {
|
|
155
|
+
$ref: "#/definitions/Application"
|
|
156
|
+
},
|
|
157
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
158
|
+
},
|
|
159
|
+
provider: {
|
|
160
|
+
$ref: "#/definitions/Provider"
|
|
161
|
+
},
|
|
162
|
+
applications: {
|
|
163
|
+
$ref: "#/definitions/ApplicationRouting",
|
|
164
|
+
description: "Mapping of application names to the routes that they host. Only needs to be defined in the application that owns the primary microfrontend domain"
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
required: ["applications", "provider", "version"]
|
|
168
|
+
},
|
|
169
|
+
Options: {
|
|
170
|
+
type: "object",
|
|
171
|
+
properties: {
|
|
172
|
+
vercel: {
|
|
173
|
+
$ref: "#/definitions/VercelOptions",
|
|
174
|
+
description: "Micro-Frontends wide options for Vercel."
|
|
175
|
+
},
|
|
176
|
+
localProxy: {
|
|
177
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
178
|
+
description: "Options for local proxy."
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
VercelOptions: {
|
|
183
|
+
type: "object",
|
|
184
|
+
properties: {
|
|
185
|
+
previewDeploymentSuffix: {
|
|
186
|
+
type: "string",
|
|
187
|
+
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`."
|
|
188
|
+
},
|
|
189
|
+
teamSlug: {
|
|
190
|
+
type: "string",
|
|
191
|
+
description: "Team slug for the Vercel team"
|
|
192
|
+
},
|
|
193
|
+
disableOverrides: {
|
|
194
|
+
type: "boolean",
|
|
195
|
+
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."
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
LocalProxyOptions: {
|
|
200
|
+
type: "object",
|
|
201
|
+
properties: {
|
|
202
|
+
port: {
|
|
203
|
+
type: "number",
|
|
204
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
Application: {
|
|
209
|
+
anyOf: [
|
|
210
|
+
{
|
|
211
|
+
$ref: "#/definitions/DefaultApplication"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
$ref: "#/definitions/ChildApplication"
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
DefaultApplication: {
|
|
219
|
+
type: "object",
|
|
220
|
+
properties: {
|
|
221
|
+
vercel: {
|
|
222
|
+
$ref: "#/definitions/Vercel"
|
|
223
|
+
},
|
|
224
|
+
development: {
|
|
225
|
+
$ref: "#/definitions/Development"
|
|
226
|
+
},
|
|
227
|
+
production: {
|
|
228
|
+
$ref: "#/definitions/HostConfig"
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
required: ["production"]
|
|
232
|
+
},
|
|
233
|
+
Vercel: {
|
|
234
|
+
type: "object",
|
|
235
|
+
properties: {
|
|
236
|
+
projectId: {
|
|
237
|
+
type: "string",
|
|
238
|
+
description: "Vercel project ID"
|
|
239
|
+
},
|
|
240
|
+
routeSpeedInsightsToDefaultZone: {
|
|
241
|
+
type: "boolean"
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
required: ["projectId"]
|
|
245
|
+
},
|
|
246
|
+
Development: {
|
|
247
|
+
type: "object",
|
|
248
|
+
properties: {
|
|
249
|
+
local: {
|
|
250
|
+
$ref: "#/definitions/LocalHostConfig"
|
|
251
|
+
},
|
|
252
|
+
fallback: {
|
|
253
|
+
$ref: "#/definitions/HostConfig",
|
|
254
|
+
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."
|
|
255
|
+
},
|
|
256
|
+
task: {
|
|
257
|
+
type: "string",
|
|
258
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
LocalHostConfig: {
|
|
263
|
+
type: "object",
|
|
264
|
+
properties: {
|
|
265
|
+
host: {
|
|
266
|
+
type: "string",
|
|
267
|
+
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`)."
|
|
268
|
+
},
|
|
269
|
+
protocol: {
|
|
270
|
+
type: "string",
|
|
271
|
+
enum: ["http", "https"],
|
|
272
|
+
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 "http" for local development, "https" for otherwise'
|
|
273
|
+
},
|
|
274
|
+
port: {
|
|
275
|
+
type: "number",
|
|
276
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
HostConfig: {
|
|
281
|
+
type: "object",
|
|
282
|
+
properties: {
|
|
283
|
+
protocol: {
|
|
284
|
+
type: "string",
|
|
285
|
+
enum: ["http", "https"],
|
|
286
|
+
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 "http" for local development, "https" for otherwise'
|
|
287
|
+
},
|
|
288
|
+
host: {
|
|
289
|
+
type: "string",
|
|
290
|
+
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`)."
|
|
291
|
+
},
|
|
292
|
+
port: {
|
|
293
|
+
type: "number",
|
|
294
|
+
description: "The port number to be used for the connection. Common values include `80` for HTTP and `443` for HTTPS."
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
required: ["host"]
|
|
298
|
+
},
|
|
299
|
+
ChildApplication: {
|
|
300
|
+
type: "object",
|
|
301
|
+
properties: {
|
|
302
|
+
vercel: {
|
|
303
|
+
$ref: "#/definitions/Vercel"
|
|
304
|
+
},
|
|
305
|
+
development: {
|
|
306
|
+
$ref: "#/definitions/Development"
|
|
307
|
+
},
|
|
308
|
+
routing: {
|
|
309
|
+
$ref: "#/definitions/Routing",
|
|
310
|
+
description: "Groups of path expressions that are routed to this application."
|
|
311
|
+
},
|
|
312
|
+
production: {
|
|
313
|
+
$ref: "#/definitions/HostConfig"
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
required: ["routing"]
|
|
317
|
+
},
|
|
318
|
+
Routing: {
|
|
319
|
+
type: "array",
|
|
320
|
+
items: {
|
|
321
|
+
$ref: "#/definitions/PathGroup"
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
PathGroup: {
|
|
325
|
+
type: "object",
|
|
326
|
+
properties: {
|
|
327
|
+
group: {
|
|
328
|
+
type: "string",
|
|
329
|
+
description: "Optional group name for the paths"
|
|
330
|
+
},
|
|
331
|
+
flag: {
|
|
332
|
+
type: "string",
|
|
333
|
+
description: "flag name that can be used to enable/disable all paths in the group"
|
|
334
|
+
},
|
|
335
|
+
routeToDefaultApplication: {
|
|
336
|
+
type: "boolean",
|
|
337
|
+
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."
|
|
338
|
+
},
|
|
339
|
+
paths: {
|
|
340
|
+
type: "array",
|
|
341
|
+
items: {
|
|
342
|
+
type: "string"
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
required: ["paths"]
|
|
347
|
+
},
|
|
348
|
+
Provider: {
|
|
349
|
+
type: "string",
|
|
350
|
+
enum: ["vercel", "other"]
|
|
351
|
+
},
|
|
352
|
+
ApplicationRouting: {
|
|
353
|
+
type: "object",
|
|
354
|
+
additionalProperties: {
|
|
355
|
+
$ref: "#/definitions/Application"
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
ChildConfig: {
|
|
359
|
+
type: "object",
|
|
360
|
+
properties: {
|
|
361
|
+
$schema: {
|
|
362
|
+
type: "string"
|
|
363
|
+
},
|
|
364
|
+
version: {
|
|
365
|
+
type: "string",
|
|
366
|
+
const: "2"
|
|
367
|
+
},
|
|
368
|
+
options: {
|
|
369
|
+
$ref: "#/definitions/Options"
|
|
370
|
+
},
|
|
371
|
+
remotes: {
|
|
372
|
+
type: "object",
|
|
373
|
+
additionalProperties: {
|
|
374
|
+
$ref: "#/definitions/Application"
|
|
375
|
+
},
|
|
376
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
377
|
+
},
|
|
378
|
+
partOf: {
|
|
379
|
+
type: "string",
|
|
380
|
+
description: "Applications that only serve a subset of the microfrontend routes only need to reference the name of the primary application that owns the full microfrontends configuration."
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
required: ["partOf", "version"]
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/config-v2/schema/utils/load.ts
|
|
389
|
+
var SCHEMA = schema_v2_default;
|
|
390
|
+
|
|
391
|
+
// src/config-v2/microfrontends/server/validation.ts
|
|
392
|
+
function validateSchema(configString) {
|
|
393
|
+
const parsedConfig = (0, import_jsonc_parser.parse)(configString);
|
|
394
|
+
const ajv = new import_ajv.Ajv();
|
|
395
|
+
const validate = ajv.compile(SCHEMA);
|
|
396
|
+
const isValid = validate(parsedConfig);
|
|
397
|
+
if (!isValid) {
|
|
398
|
+
throw new MicroFrontendError(
|
|
399
|
+
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
400
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
return parsedConfig;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/config/validation.ts
|
|
407
|
+
var import_jsonc_parser2 = require("jsonc-parser");
|
|
408
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
409
|
+
var import_ajv2 = require("ajv");
|
|
410
|
+
|
|
411
|
+
// schema/schema.json
|
|
412
|
+
var schema_default = {
|
|
413
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
414
|
+
$ref: "#/definitions/Config",
|
|
415
|
+
definitions: {
|
|
416
|
+
Config: {
|
|
417
|
+
type: "object",
|
|
418
|
+
properties: {
|
|
419
|
+
version: {
|
|
420
|
+
type: "string"
|
|
421
|
+
},
|
|
422
|
+
$schema: {
|
|
423
|
+
type: "string"
|
|
424
|
+
},
|
|
425
|
+
name: {
|
|
426
|
+
type: "string",
|
|
427
|
+
description: 'Name for the micro-frontend site (eg. "vercel.com", "vercel-site" etc.).'
|
|
428
|
+
},
|
|
429
|
+
applications: {
|
|
430
|
+
$ref: "#/definitions/ApplicationConfigsById"
|
|
431
|
+
},
|
|
432
|
+
options: {
|
|
433
|
+
$ref: "#/definitions/Options",
|
|
434
|
+
description: "Optional configuration for the entire micro-frontends setup."
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
required: ["version", "applications"],
|
|
438
|
+
description: "Configuration for micro-frontend applications\n\nTODO: Add proxy configuration"
|
|
439
|
+
},
|
|
440
|
+
ApplicationConfigsById: {
|
|
441
|
+
type: "object",
|
|
442
|
+
additionalProperties: {
|
|
443
|
+
$ref: "#/definitions/ApplicationConfig"
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
ApplicationConfig: {
|
|
447
|
+
anyOf: [
|
|
448
|
+
{
|
|
449
|
+
$ref: "#/definitions/DefaultApplicationConfig"
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
$ref: "#/definitions/CommonApplicationConfig"
|
|
453
|
+
}
|
|
454
|
+
],
|
|
455
|
+
description: "A Micro-Frontend Deployment Target"
|
|
456
|
+
},
|
|
457
|
+
DefaultApplicationConfig: {
|
|
458
|
+
type: "object",
|
|
459
|
+
properties: {
|
|
460
|
+
default: {
|
|
461
|
+
type: "boolean",
|
|
462
|
+
const: true,
|
|
463
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
464
|
+
},
|
|
465
|
+
routing: {
|
|
466
|
+
$ref: "#/definitions/Routing"
|
|
467
|
+
},
|
|
468
|
+
development: {
|
|
469
|
+
type: "object",
|
|
470
|
+
properties: {
|
|
471
|
+
local: {
|
|
472
|
+
$ref: "#/definitions/HostConfig"
|
|
473
|
+
},
|
|
474
|
+
fallback: {
|
|
475
|
+
$ref: "#/definitions/HostConfig",
|
|
476
|
+
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."
|
|
477
|
+
},
|
|
478
|
+
task: {
|
|
479
|
+
type: "string",
|
|
480
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
required: ["local"]
|
|
484
|
+
},
|
|
485
|
+
production: {
|
|
486
|
+
$ref: "#/definitions/HostConfig"
|
|
487
|
+
},
|
|
488
|
+
metadata: {
|
|
489
|
+
type: "object",
|
|
490
|
+
additionalProperties: {
|
|
491
|
+
type: "string"
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
federation: {
|
|
495
|
+
type: "object",
|
|
496
|
+
properties: {
|
|
497
|
+
exposes: {
|
|
498
|
+
type: "array",
|
|
499
|
+
items: {
|
|
500
|
+
type: "object",
|
|
501
|
+
properties: {
|
|
502
|
+
name: {
|
|
503
|
+
type: "string",
|
|
504
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
505
|
+
},
|
|
506
|
+
path: {
|
|
507
|
+
type: "string",
|
|
508
|
+
description: "Relative path to the module within its `application`"
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
required: ["name", "path"]
|
|
512
|
+
},
|
|
513
|
+
description: "Modules that are exposed by this application"
|
|
514
|
+
},
|
|
515
|
+
uses: {
|
|
516
|
+
type: "array",
|
|
517
|
+
items: {
|
|
518
|
+
type: "string"
|
|
519
|
+
},
|
|
520
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
vercel: {
|
|
525
|
+
$ref: "#/definitions/Vercel"
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
required: ["default", "development", "production"]
|
|
529
|
+
},
|
|
530
|
+
Routing: {
|
|
531
|
+
type: "object",
|
|
532
|
+
properties: {
|
|
533
|
+
assetPrefix: {
|
|
534
|
+
type: "string",
|
|
535
|
+
description: "[assetPrefix] for the application"
|
|
536
|
+
},
|
|
537
|
+
matches: {
|
|
538
|
+
type: "array",
|
|
539
|
+
items: {
|
|
540
|
+
$ref: "#/definitions/PathGroup"
|
|
541
|
+
},
|
|
542
|
+
description: "Path expressions that are routed to this application."
|
|
543
|
+
}
|
|
544
|
+
},
|
|
545
|
+
required: ["matches"]
|
|
546
|
+
},
|
|
547
|
+
PathGroup: {
|
|
548
|
+
type: "object",
|
|
549
|
+
properties: {
|
|
550
|
+
group: {
|
|
551
|
+
type: "string",
|
|
552
|
+
description: "Optional group name for the paths"
|
|
553
|
+
},
|
|
554
|
+
options: {
|
|
555
|
+
type: "object",
|
|
556
|
+
properties: {
|
|
557
|
+
flag: {
|
|
558
|
+
type: "string",
|
|
559
|
+
description: "flag name that can be used to enable/disable all paths in the group"
|
|
560
|
+
},
|
|
561
|
+
routeToDefaultApplication: {
|
|
562
|
+
type: "boolean",
|
|
563
|
+
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."
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
paths: {
|
|
568
|
+
type: "array",
|
|
569
|
+
items: {
|
|
570
|
+
type: "string"
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
required: ["paths"]
|
|
575
|
+
},
|
|
576
|
+
HostConfig: {
|
|
577
|
+
type: "object",
|
|
578
|
+
properties: {
|
|
579
|
+
protocol: {
|
|
580
|
+
type: "string",
|
|
581
|
+
enum: ["http", "https"],
|
|
582
|
+
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"'
|
|
583
|
+
},
|
|
584
|
+
host: {
|
|
585
|
+
type: "string",
|
|
586
|
+
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`)."
|
|
587
|
+
},
|
|
588
|
+
port: {
|
|
589
|
+
type: "number",
|
|
590
|
+
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"
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
required: ["host"]
|
|
594
|
+
},
|
|
595
|
+
Vercel: {
|
|
596
|
+
type: "object",
|
|
597
|
+
properties: {
|
|
598
|
+
projectId: {
|
|
599
|
+
type: "string",
|
|
600
|
+
description: "Vercel project ID"
|
|
601
|
+
},
|
|
602
|
+
projectName: {
|
|
603
|
+
type: "string",
|
|
604
|
+
description: "Vercel project name (temporary until we can use project ID)"
|
|
605
|
+
},
|
|
606
|
+
defaultRoute: {
|
|
607
|
+
type: "string",
|
|
608
|
+
description: "The default route for the application. Used to render screenshots, favicons, and provide direct zone links"
|
|
609
|
+
},
|
|
610
|
+
routeSpeedInsightsToDefaultZone: {
|
|
611
|
+
type: "boolean",
|
|
612
|
+
description: "Whether to route Speed Insights to the default zone or each individual microfrontend."
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
required: ["projectId"]
|
|
616
|
+
},
|
|
617
|
+
CommonApplicationConfig: {
|
|
618
|
+
type: "object",
|
|
619
|
+
properties: {
|
|
620
|
+
default: {
|
|
621
|
+
type: "boolean",
|
|
622
|
+
const: false,
|
|
623
|
+
description: "The default application is used no other application is matched via the routing config"
|
|
624
|
+
},
|
|
625
|
+
routing: {
|
|
626
|
+
$ref: "#/definitions/Routing"
|
|
627
|
+
},
|
|
628
|
+
development: {
|
|
629
|
+
type: "object",
|
|
630
|
+
properties: {
|
|
631
|
+
local: {
|
|
632
|
+
$ref: "#/definitions/HostConfig"
|
|
633
|
+
},
|
|
634
|
+
fallback: {
|
|
635
|
+
$ref: "#/definitions/HostConfig",
|
|
636
|
+
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."
|
|
637
|
+
},
|
|
638
|
+
task: {
|
|
639
|
+
type: "string",
|
|
640
|
+
description: "Optional task to run when starting the development server. Should reference a script in the package.json of the application."
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
required: ["local"]
|
|
644
|
+
},
|
|
645
|
+
production: {
|
|
646
|
+
$ref: "#/definitions/HostConfig"
|
|
647
|
+
},
|
|
648
|
+
metadata: {
|
|
649
|
+
type: "object",
|
|
650
|
+
additionalProperties: {
|
|
651
|
+
type: "string"
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
federation: {
|
|
655
|
+
type: "object",
|
|
656
|
+
properties: {
|
|
657
|
+
exposes: {
|
|
658
|
+
type: "array",
|
|
659
|
+
items: {
|
|
660
|
+
type: "object",
|
|
661
|
+
properties: {
|
|
662
|
+
name: {
|
|
663
|
+
type: "string",
|
|
664
|
+
description: "The name of the module - should be used when importing the module from another application"
|
|
665
|
+
},
|
|
666
|
+
path: {
|
|
667
|
+
type: "string",
|
|
668
|
+
description: "Relative path to the module within its `application`"
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
required: ["name", "path"]
|
|
672
|
+
},
|
|
673
|
+
description: "Modules that are exposed by this application"
|
|
674
|
+
},
|
|
675
|
+
uses: {
|
|
676
|
+
type: "array",
|
|
677
|
+
items: {
|
|
678
|
+
type: "string"
|
|
679
|
+
},
|
|
680
|
+
description: "Modules that are used by this application. Only the name of the module is required."
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
},
|
|
684
|
+
vercel: {
|
|
685
|
+
$ref: "#/definitions/Vercel"
|
|
686
|
+
}
|
|
687
|
+
},
|
|
688
|
+
required: ["default", "development", "production", "routing"]
|
|
689
|
+
},
|
|
690
|
+
Options: {
|
|
691
|
+
type: "object",
|
|
692
|
+
properties: {
|
|
693
|
+
vercel: {
|
|
694
|
+
$ref: "#/definitions/VercelOptions",
|
|
695
|
+
description: "Micro-Frontends wide options for Vercel."
|
|
696
|
+
},
|
|
697
|
+
localProxy: {
|
|
698
|
+
$ref: "#/definitions/LocalProxyOptions",
|
|
699
|
+
description: "Options for local proxy."
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
},
|
|
703
|
+
VercelOptions: {
|
|
704
|
+
type: "object",
|
|
705
|
+
properties: {
|
|
706
|
+
previewDeploymentSuffix: {
|
|
707
|
+
type: "string",
|
|
708
|
+
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`."
|
|
709
|
+
},
|
|
710
|
+
teamSlug: {
|
|
711
|
+
type: "string",
|
|
712
|
+
description: "Team slug for the Vercel team"
|
|
713
|
+
},
|
|
714
|
+
disableOverrides: {
|
|
715
|
+
type: "boolean",
|
|
716
|
+
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."
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
LocalProxyOptions: {
|
|
721
|
+
type: "object",
|
|
722
|
+
properties: {
|
|
723
|
+
port: {
|
|
724
|
+
type: "number",
|
|
725
|
+
description: "The port number used by the local proxy server.\n\nThe default is `3024`."
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
// src/config/utils/load-schema.ts
|
|
733
|
+
var SCHEMA2 = schema_default;
|
|
734
|
+
|
|
735
|
+
// src/config/validation.ts
|
|
736
|
+
var validateSchema2 = (configString) => {
|
|
737
|
+
const parsedConfig = (0, import_jsonc_parser2.parse)(configString);
|
|
738
|
+
const ajv = new import_ajv2.Ajv();
|
|
739
|
+
const validate = ajv.compile(SCHEMA2);
|
|
740
|
+
const isValid = validate(parsedConfig);
|
|
741
|
+
if (!isValid) {
|
|
742
|
+
throw new MicroFrontendError(
|
|
743
|
+
`Invalid config: ${ajv.errorsText(validate.errors)}`,
|
|
744
|
+
{ type: "config", subtype: "does_not_match_schema" }
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
return parsedConfig;
|
|
748
|
+
};
|
|
749
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
750
|
+
0 && (module.exports = {
|
|
751
|
+
validateV1Schema,
|
|
752
|
+
validateV2Schema
|
|
753
|
+
});
|
|
754
|
+
//# sourceMappingURL=validation.cjs.map
|