@vercel/microfrontends 0.17.1 → 0.17.3
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/LICENSE +21 -0
- package/README.md +48 -89
- package/dist/bin/cli.cjs +299 -200
- package/dist/config.cjs +22 -45
- package/dist/config.cjs.map +1 -1
- package/dist/config.d.ts +4 -4
- package/dist/config.js +22 -45
- package/dist/config.js.map +1 -1
- package/dist/{types-a29d224a.d.ts → index-5fcf0863.d.ts} +2 -2
- package/dist/{index-4399aa8e.d.ts → index-f094deb1.d.ts} +5 -4
- package/dist/microfrontends/server.cjs +68 -75
- package/dist/microfrontends/server.cjs.map +1 -1
- package/dist/microfrontends/server.d.ts +4 -4
- package/dist/microfrontends/server.js +68 -75
- package/dist/microfrontends/server.js.map +1 -1
- package/dist/microfrontends.cjs +24 -48
- package/dist/microfrontends.cjs.map +1 -1
- package/dist/microfrontends.d.ts +4 -4
- package/dist/microfrontends.js +24 -48
- package/dist/microfrontends.js.map +1 -1
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/config.cjs +86 -101
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +86 -101
- package/dist/next/config.js.map +1 -1
- package/dist/next/endpoints.cjs +1 -1
- package/dist/next/endpoints.cjs.map +1 -1
- package/dist/next/endpoints.d.ts +2 -2
- package/dist/next/endpoints.js +1 -1
- package/dist/next/endpoints.js.map +1 -1
- package/dist/next/middleware.cjs +32 -63
- package/dist/next/middleware.cjs.map +1 -1
- package/dist/next/middleware.js +32 -63
- package/dist/next/middleware.js.map +1 -1
- package/dist/next/testing.cjs +27 -54
- package/dist/next/testing.cjs.map +1 -1
- package/dist/next/testing.d.ts +4 -4
- package/dist/next/testing.js +27 -54
- package/dist/next/testing.js.map +1 -1
- package/dist/overrides.cjs +1 -2
- package/dist/overrides.cjs.map +1 -1
- package/dist/overrides.d.ts +3 -3
- package/dist/overrides.js +1 -2
- package/dist/overrides.js.map +1 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.ts +1 -1
- package/dist/{types-fc30696d.d.ts → types-5900be7c.d.ts} +1 -1
- package/dist/{types-cfe3308b.d.ts → types-ecd7b91b.d.ts} +1 -1
- package/dist/utils/mfe-port.cjs +68 -75
- package/dist/utils/mfe-port.cjs.map +1 -1
- package/dist/utils/mfe-port.js +68 -75
- package/dist/utils/mfe-port.js.map +1 -1
- package/dist/validation.cjs +46 -17
- package/dist/validation.cjs.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.js +46 -17
- package/dist/validation.js.map +1 -1
- package/package.json +18 -22
- package/schema/schema.json +15 -8
package/dist/next/endpoints.cjs
CHANGED
|
@@ -31,7 +31,7 @@ var MicrofrontendConfigClient = class {
|
|
|
31
31
|
constructor(config, opts) {
|
|
32
32
|
this.pathCache = {};
|
|
33
33
|
this.serialized = config;
|
|
34
|
-
if (opts
|
|
34
|
+
if (opts?.removeFlaggedPaths) {
|
|
35
35
|
for (const app of Object.values(config.applications)) {
|
|
36
36
|
if (app.routing) {
|
|
37
37
|
app.routing = app.routing.filter((match) => !match.flag);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;;;ACA7B,4BAA6B;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,
|
|
1
|
+
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":"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","names":[]}
|
package/dist/next/endpoints.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextResponse } from 'next/server';
|
|
2
|
-
import { C as ClientConfig } from '../types-
|
|
3
|
-
import '../
|
|
2
|
+
import { C as ClientConfig } from '../types-5900be7c.js';
|
|
3
|
+
import '../index-5fcf0863.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Data that is returned from the `.well-known/vercel/microfrontends/client-config`
|
package/dist/next/endpoints.js
CHANGED
|
@@ -7,7 +7,7 @@ var MicrofrontendConfigClient = class {
|
|
|
7
7
|
constructor(config, opts) {
|
|
8
8
|
this.pathCache = {};
|
|
9
9
|
this.serialized = config;
|
|
10
|
-
if (opts
|
|
10
|
+
if (opts?.removeFlaggedPaths) {
|
|
11
11
|
for (const app of Object.values(config.applications)) {
|
|
12
12
|
if (app.routing) {
|
|
13
13
|
app.routing = app.routing.filter((match) => !match.flag);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,oBAAoB;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,
|
|
1
|
+
{"version":3,"sources":["../../src/next/endpoints/index.ts","../../src/config/microfrontends-config/client/index.ts","../../src/config/well-known/endpoints.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { getWellKnownClientData } from '../../config/well-known/endpoints';\nimport type { WellKnownClientData } from '../../config/well-known/types';\n\n/**\n * A Next.js App Router API handler to export the micro-frontends client config\n * data.\n *\n * @example In the `app/.well-known/vercel/microfrontends/client-config/route.ts` file,\n * add this code:\n * ```\n * export { wellKnownNextjsClientConfigAppRoute as GET } from '@vercel/microfrontends/next/endpoints';\n * ```\n */\nexport async function wellKnownNextjsClientConfigAppRoute(\n flagValues: Record<string, () => Promise<boolean>>,\n): Promise<NextResponse> {\n return NextResponse.json<WellKnownClientData>(\n await getWellKnownClientData(\n process.env.NEXT_PUBLIC_MFE_CLIENT_CONFIG,\n flagValues,\n ),\n );\n}\n\nexport type { WellKnownClientData };\n","import { pathToRegexp } from 'path-to-regexp';\nimport type { ClientConfig } from './types';\n\ninterface MicrofrontendConfigClientOptions {\n removeFlaggedPaths?: boolean;\n}\n\nexport class MicrofrontendConfigClient {\n applications: ClientConfig['applications'];\n pathCache: Record<string, string> = {};\n private readonly serialized: ClientConfig;\n\n constructor(config: ClientConfig, opts?: MicrofrontendConfigClientOptions) {\n this.serialized = config;\n if (opts?.removeFlaggedPaths) {\n for (const app of Object.values(config.applications)) {\n if (app.routing) {\n app.routing = app.routing.filter((match) => !match.flag);\n }\n }\n }\n this.applications = config.applications;\n }\n\n /**\n * Create a new `MicrofrontendConfigClient` from a JSON string.\n * Config must be passed in to remain framework agnostic\n */\n static fromEnv(\n config: string | undefined,\n opts?: MicrofrontendConfigClientOptions,\n ): MicrofrontendConfigClient {\n if (!config) {\n throw new Error('No microfrontends configuration found');\n }\n return new MicrofrontendConfigClient(\n JSON.parse(config) as ClientConfig,\n opts,\n );\n }\n\n isEqual(other: MicrofrontendConfigClient): boolean {\n return (\n JSON.stringify(this.applications) === JSON.stringify(other.applications)\n );\n }\n\n getApplicationNameForPath(path: string): string | null {\n if (!path.startsWith('/')) {\n throw new Error(`Path must start with a /`);\n }\n\n if (this.pathCache[path]) {\n return this.pathCache[path];\n }\n\n const pathname = new URL(path, 'https://example.com').pathname;\n for (const [name, application] of Object.entries(this.applications)) {\n if (application.routing) {\n for (const group of application.routing) {\n for (const childPath of group.paths) {\n const regexp = pathToRegexp(childPath);\n if (regexp.test(pathname)) {\n this.pathCache[path] = name;\n return name;\n }\n }\n }\n }\n }\n const defaultApplication = Object.entries(this.applications).find(\n ([, application]) => application.default,\n );\n if (!defaultApplication) {\n return null;\n }\n\n this.pathCache[path] = defaultApplication[0];\n return defaultApplication[0];\n }\n\n serialize(): ClientConfig {\n return this.serialized;\n }\n}\n","import { MicrofrontendConfigClient } from '../microfrontends-config/client';\nimport type { WellKnownClientData } from './types';\n\n/**\n * Returns data used by the client to ensure that navigations across\n * microfrontend boundaries are routed and prefetched correctly. The client\n * configuration is safe to expose to users.\n *\n * This data should be exposed in a `.well-known/vercel/microfrontends/client-config`\n * endpoint.\n */\nexport async function getWellKnownClientData(\n clientConfig: string | undefined,\n flagValues: Record<string, () => Promise<boolean>> = {},\n): Promise<WellKnownClientData> {\n const config = MicrofrontendConfigClient.fromEnv(clientConfig);\n for (const [applicationName, application] of Object.entries(\n config.applications,\n )) {\n if (!application.routing) {\n continue;\n }\n const newRoutingMatches = [];\n for (const pathGroup of application.routing) {\n if (pathGroup.flag) {\n const flagName = pathGroup.flag;\n const flagFn = flagValues[flagName];\n if (!flagFn) {\n throw new Error(\n `Flag \"${flagName}\" was specified to control routing for path group \"${pathGroup.group}\" in application ${applicationName} but not found in provided flag values.`,\n );\n }\n // eslint-disable-next-line no-await-in-loop\n const flagEnabled = await flagFn();\n if (flagEnabled) {\n newRoutingMatches.push(pathGroup);\n }\n } else {\n newRoutingMatches.push(pathGroup);\n }\n }\n application.routing = newRoutingMatches;\n }\n\n return {\n config: config.serialize(),\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;;;ACA7B,SAAS,oBAAoB;AAOtB,IAAM,4BAAN,MAAgC;AAAA,EAKrC,YAAY,QAAsB,MAAyC;AAH3E,qBAAoC,CAAC;AAInC,SAAK,aAAa;AAClB,QAAI,MAAM,oBAAoB;AAC5B,iBAAW,OAAO,OAAO,OAAO,OAAO,YAAY,GAAG;AACpD,YAAI,IAAI,SAAS;AACf,cAAI,UAAU,IAAI,QAAQ,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AACA,SAAK,eAAe,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,QACL,QACA,MAC2B;AAC3B,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AACA,WAAO,IAAI;AAAA,MACT,KAAK,MAAM,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,QAAQ,OAA2C;AACjD,WACE,KAAK,UAAU,KAAK,YAAY,MAAM,KAAK,UAAU,MAAM,YAAY;AAAA,EAE3E;AAAA,EAEA,0BAA0B,MAA6B;AACrD,QAAI,CAAC,KAAK,WAAW,GAAG,GAAG;AACzB,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,QAAI,KAAK,UAAU,IAAI,GAAG;AACxB,aAAO,KAAK,UAAU,IAAI;AAAA,IAC5B;AAEA,UAAM,WAAW,IAAI,IAAI,MAAM,qBAAqB,EAAE;AACtD,eAAW,CAAC,MAAM,WAAW,KAAK,OAAO,QAAQ,KAAK,YAAY,GAAG;AACnE,UAAI,YAAY,SAAS;AACvB,mBAAW,SAAS,YAAY,SAAS;AACvC,qBAAW,aAAa,MAAM,OAAO;AACnC,kBAAM,SAAS,aAAa,SAAS;AACrC,gBAAI,OAAO,KAAK,QAAQ,GAAG;AACzB,mBAAK,UAAU,IAAI,IAAI;AACvB,qBAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AACA,UAAM,qBAAqB,OAAO,QAAQ,KAAK,YAAY,EAAE;AAAA,MAC3D,CAAC,CAAC,EAAE,WAAW,MAAM,YAAY;AAAA,IACnC;AACA,QAAI,CAAC,oBAAoB;AACvB,aAAO;AAAA,IACT;AAEA,SAAK,UAAU,IAAI,IAAI,mBAAmB,CAAC;AAC3C,WAAO,mBAAmB,CAAC;AAAA,EAC7B;AAAA,EAEA,YAA0B;AACxB,WAAO,KAAK;AAAA,EACd;AACF;;;ACzEA,eAAsB,uBACpB,cACA,aAAqD,CAAC,GACxB;AAC9B,QAAM,SAAS,0BAA0B,QAAQ,YAAY;AAC7D,aAAW,CAAC,iBAAiB,WAAW,KAAK,OAAO;AAAA,IAClD,OAAO;AAAA,EACT,GAAG;AACD,QAAI,CAAC,YAAY,SAAS;AACxB;AAAA,IACF;AACA,UAAM,oBAAoB,CAAC;AAC3B,eAAW,aAAa,YAAY,SAAS;AAC3C,UAAI,UAAU,MAAM;AAClB,cAAM,WAAW,UAAU;AAC3B,cAAM,SAAS,WAAW,QAAQ;AAClC,YAAI,CAAC,QAAQ;AACX,gBAAM,IAAI;AAAA,YACR,SAAS,8DAA8D,UAAU,yBAAyB;AAAA,UAC5G;AAAA,QACF;AAEA,cAAM,cAAc,MAAM,OAAO;AACjC,YAAI,aAAa;AACf,4BAAkB,KAAK,SAAS;AAAA,QAClC;AAAA,MACF,OAAO;AACL,0BAAkB,KAAK,SAAS;AAAA,MAClC;AAAA,IACF;AACA,gBAAY,UAAU;AAAA,EACxB;AAEA,SAAO;AAAA,IACL,QAAQ,OAAO,UAAU;AAAA,EAC3B;AACF;;;AFjCA,eAAsB,oCACpB,YACuB;AACvB,SAAO,aAAa;AAAA,IAClB,MAAM;AAAA,MACJ,QAAQ,IAAI;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/next/middleware.cjs
CHANGED
|
@@ -37,9 +37,9 @@ var MicrofrontendError = class extends Error {
|
|
|
37
37
|
constructor(message, opts) {
|
|
38
38
|
super(message);
|
|
39
39
|
this.name = "MicrofrontendsError";
|
|
40
|
-
this.source =
|
|
41
|
-
this.type =
|
|
42
|
-
this.subtype = opts
|
|
40
|
+
this.source = opts?.source ?? "@vercel/microfrontends";
|
|
41
|
+
this.type = opts?.type ?? "unknown";
|
|
42
|
+
this.subtype = opts?.subtype;
|
|
43
43
|
Error.captureStackTrace(this, MicrofrontendError);
|
|
44
44
|
}
|
|
45
45
|
isKnown() {
|
|
@@ -54,7 +54,7 @@ var MicrofrontendError = class extends Error {
|
|
|
54
54
|
* @returns The converted MicrofrontendsError.
|
|
55
55
|
*/
|
|
56
56
|
static convert(original, opts) {
|
|
57
|
-
if (opts
|
|
57
|
+
if (opts?.fileName) {
|
|
58
58
|
const err = MicrofrontendError.convertFSError(original, opts.fileName);
|
|
59
59
|
if (err) {
|
|
60
60
|
return err;
|
|
@@ -152,7 +152,7 @@ var MicrofrontendConfigClient = class {
|
|
|
152
152
|
constructor(config, opts) {
|
|
153
153
|
this.pathCache = {};
|
|
154
154
|
this.serialized = config;
|
|
155
|
-
if (opts
|
|
155
|
+
if (opts?.removeFlaggedPaths) {
|
|
156
156
|
for (const app of Object.values(config.applications)) {
|
|
157
157
|
if (app.routing) {
|
|
158
158
|
app.routing = app.routing.filter((match) => !match.flag);
|
|
@@ -218,8 +218,7 @@ var OVERRIDES_ENV_COOKIE_PREFIX = `${OVERRIDES_COOKIE_PREFIX}:env:`;
|
|
|
218
218
|
|
|
219
219
|
// src/config/overrides/is-override-cookie.ts
|
|
220
220
|
function isOverrideCookie(cookie) {
|
|
221
|
-
|
|
222
|
-
return Boolean((_a = cookie.name) == null ? void 0 : _a.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
221
|
+
return Boolean(cookie.name?.startsWith(OVERRIDES_COOKIE_PREFIX));
|
|
223
222
|
}
|
|
224
223
|
|
|
225
224
|
// src/config/overrides/get-override-from-cookie.ts
|
|
@@ -248,17 +247,6 @@ function parseOverrides(cookies) {
|
|
|
248
247
|
|
|
249
248
|
// src/config/microfrontends-config/isomorphic/validation.ts
|
|
250
249
|
var import_path_to_regexp2 = require("path-to-regexp");
|
|
251
|
-
var SUPPORTED_VERSIONS = ["2"];
|
|
252
|
-
var validateConfigVersion = (version) => {
|
|
253
|
-
if (!SUPPORTED_VERSIONS.includes(version)) {
|
|
254
|
-
throw new MicrofrontendError(
|
|
255
|
-
`Unsupported version: ${version}. Supported versions are: ${SUPPORTED_VERSIONS.join(
|
|
256
|
-
", "
|
|
257
|
-
)}`,
|
|
258
|
-
{ type: "config", subtype: "unsupported_version" }
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
250
|
var validateConfigPaths = (applicationConfigsById) => {
|
|
263
251
|
if (!applicationConfigsById) {
|
|
264
252
|
return;
|
|
@@ -434,7 +422,7 @@ var Host = class {
|
|
|
434
422
|
this.protocol = protocol;
|
|
435
423
|
this.host = host;
|
|
436
424
|
this.port = Host.getPort({ port, protocol: this.protocol });
|
|
437
|
-
this.local = options
|
|
425
|
+
this.local = options?.isLocal;
|
|
438
426
|
}
|
|
439
427
|
isLocal() {
|
|
440
428
|
return this.local || this.host === "localhost" || this.host === "127.0.0.1";
|
|
@@ -483,18 +471,17 @@ var Application = class {
|
|
|
483
471
|
overrides,
|
|
484
472
|
isDefault
|
|
485
473
|
}) {
|
|
486
|
-
var _a, _b;
|
|
487
474
|
this.name = name;
|
|
488
475
|
this.development = {
|
|
489
476
|
local: new LocalHost({
|
|
490
477
|
appName: name,
|
|
491
|
-
...
|
|
478
|
+
...app.development?.local
|
|
492
479
|
}),
|
|
493
|
-
fallback:
|
|
480
|
+
fallback: app.development?.fallback ? new Host(app.development.fallback) : void 0
|
|
494
481
|
};
|
|
495
482
|
this.production = app.production ? new Host(app.production) : void 0;
|
|
496
483
|
this.vercel = app.vercel;
|
|
497
|
-
this.overrides =
|
|
484
|
+
this.overrides = overrides?.environment ? {
|
|
498
485
|
environment: new Host(overrides.environment)
|
|
499
486
|
} : void 0;
|
|
500
487
|
this.default = isDefault ?? false;
|
|
@@ -554,17 +541,17 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
554
541
|
constructor({
|
|
555
542
|
config,
|
|
556
543
|
overrides,
|
|
557
|
-
meta
|
|
544
|
+
meta,
|
|
545
|
+
opts
|
|
558
546
|
}) {
|
|
559
547
|
this.childApplications = {};
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const disableOverrides = ((_b = (_a = config.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
548
|
+
MicrofrontendConfigIsomorphic.validate(config, opts);
|
|
549
|
+
const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
|
|
563
550
|
this.overrides = overrides && !disableOverrides ? overrides : void 0;
|
|
564
551
|
this.isMainConfig = isMainConfig(config);
|
|
565
552
|
if (isMainConfig(config)) {
|
|
566
553
|
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
567
|
-
const appOverrides = !disableOverrides ?
|
|
554
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
568
555
|
if (isDefaultApp(appConfig)) {
|
|
569
556
|
this.defaultApplication = new DefaultApplication(appId, {
|
|
570
557
|
app: appConfig,
|
|
@@ -579,7 +566,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
579
566
|
}
|
|
580
567
|
} else {
|
|
581
568
|
this.partOf = config.partOf;
|
|
582
|
-
const appOverrides = !disableOverrides ?
|
|
569
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[meta.fromApp] : void 0;
|
|
583
570
|
this.childApplications[meta.fromApp] = new ChildApplication(
|
|
584
571
|
meta.fromApp,
|
|
585
572
|
{
|
|
@@ -607,12 +594,9 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
607
594
|
};
|
|
608
595
|
}
|
|
609
596
|
static validate(config, opts) {
|
|
610
|
-
const skipValidation =
|
|
597
|
+
const skipValidation = opts?.skipValidation ?? [];
|
|
611
598
|
const c = typeof config === "string" ? (0, import_jsonc_parser.parse)(config) : config;
|
|
612
599
|
if (isMainConfig(c)) {
|
|
613
|
-
if (!skipValidation.includes("version")) {
|
|
614
|
-
validateConfigVersion(c.version);
|
|
615
|
-
}
|
|
616
600
|
if (!skipValidation.includes("paths")) {
|
|
617
601
|
validateConfigPaths(c.applications);
|
|
618
602
|
}
|
|
@@ -633,8 +617,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
633
617
|
});
|
|
634
618
|
}
|
|
635
619
|
isOverridesDisabled() {
|
|
636
|
-
|
|
637
|
-
return ((_b = (_a = this.options) == null ? void 0 : _a.vercel) == null ? void 0 : _b.disableOverrides) ?? false;
|
|
620
|
+
return this.options?.vercel?.disableOverrides ?? false;
|
|
638
621
|
}
|
|
639
622
|
getConfig() {
|
|
640
623
|
return this.config;
|
|
@@ -655,8 +638,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
655
638
|
].filter(Boolean);
|
|
656
639
|
}
|
|
657
640
|
getApplication(name) {
|
|
658
|
-
|
|
659
|
-
if (((_a = this.defaultApplication) == null ? void 0 : _a.name) === name) {
|
|
641
|
+
if (this.defaultApplication?.name === name) {
|
|
660
642
|
return this.defaultApplication;
|
|
661
643
|
}
|
|
662
644
|
const app = this.childApplications[name];
|
|
@@ -672,15 +654,11 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
672
654
|
return app;
|
|
673
655
|
}
|
|
674
656
|
getApplicationByProjectId(projectId) {
|
|
675
|
-
|
|
676
|
-
if (((_b = (_a = this.defaultApplication) == null ? void 0 : _a.vercel) == null ? void 0 : _b.projectId) === projectId) {
|
|
657
|
+
if (this.defaultApplication?.vercel?.projectId === projectId) {
|
|
677
658
|
return this.defaultApplication;
|
|
678
659
|
}
|
|
679
660
|
return Object.values(this.childApplications).find(
|
|
680
|
-
(app) =>
|
|
681
|
-
var _a2;
|
|
682
|
-
return ((_a2 = app.vercel) == null ? void 0 : _a2.projectId) === projectId;
|
|
683
|
-
}
|
|
661
|
+
(app) => app.vercel?.projectId === projectId
|
|
684
662
|
);
|
|
685
663
|
}
|
|
686
664
|
/**
|
|
@@ -703,8 +681,7 @@ var MicrofrontendConfigIsomorphic = class {
|
|
|
703
681
|
* Returns the configured port for the local proxy
|
|
704
682
|
*/
|
|
705
683
|
getLocalProxyPort() {
|
|
706
|
-
|
|
707
|
-
return ((_b = (_a = this.config.options) == null ? void 0 : _a.localProxy) == null ? void 0 : _b.port) ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
684
|
+
return this.config.options?.localProxy?.port ?? DEFAULT_LOCAL_PROXY_PORT;
|
|
708
685
|
}
|
|
709
686
|
/**
|
|
710
687
|
* Serializes the class back to the Schema type.
|
|
@@ -758,13 +735,12 @@ var MicrofrontendMainConfig = class extends MicrofrontendConfigIsomorphic {
|
|
|
758
735
|
overrides,
|
|
759
736
|
meta
|
|
760
737
|
}) {
|
|
761
|
-
var _a, _b, _c;
|
|
762
738
|
super({ config, overrides, meta });
|
|
763
739
|
this.isMainConfig = true;
|
|
764
|
-
const disableOverrides =
|
|
740
|
+
const disableOverrides = config.options?.vercel?.disableOverrides ?? false;
|
|
765
741
|
let defaultApplication;
|
|
766
742
|
for (const [appId, appConfig] of Object.entries(config.applications)) {
|
|
767
|
-
const appOverrides = !disableOverrides ?
|
|
743
|
+
const appOverrides = !disableOverrides ? this.overrides?.applications[appId] : void 0;
|
|
768
744
|
if (isDefaultApp(appConfig)) {
|
|
769
745
|
defaultApplication = new DefaultApplication(appId, {
|
|
770
746
|
app: appConfig,
|
|
@@ -823,21 +799,17 @@ function getDomainFromEnvironment({
|
|
|
823
799
|
app,
|
|
824
800
|
target
|
|
825
801
|
}) {
|
|
826
|
-
var _a;
|
|
827
802
|
const mfeProjects = JSON.parse(
|
|
828
803
|
process.env.VERCEL_MICROFRONTENDS_PROJECTS ?? "[]"
|
|
829
804
|
);
|
|
830
805
|
if (mfeProjects.length === 0) {
|
|
831
806
|
throw new Error("Missing related microfrontends project information");
|
|
832
807
|
}
|
|
833
|
-
if (!
|
|
808
|
+
if (!app.vercel?.projectId) {
|
|
834
809
|
throw new Error(`Missing applications[${app.name}].vercel.projectId`);
|
|
835
810
|
}
|
|
836
811
|
const vercelProject = mfeProjects.find(
|
|
837
|
-
(p) =>
|
|
838
|
-
var _a2;
|
|
839
|
-
return p.project.id === ((_a2 = app.vercel) == null ? void 0 : _a2.projectId);
|
|
840
|
-
}
|
|
812
|
+
(p) => p.project.id === app.vercel?.projectId
|
|
841
813
|
);
|
|
842
814
|
if (!vercelProject) {
|
|
843
815
|
throw new Error(
|
|
@@ -880,9 +852,8 @@ function getCurrentEnvironment() {
|
|
|
880
852
|
return { group: "custom", name: process.env.VERCEL_ENV };
|
|
881
853
|
}
|
|
882
854
|
function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
883
|
-
var _a;
|
|
884
855
|
const app = config.getApplication(appName);
|
|
885
|
-
if (!opts.ignoreOverride &&
|
|
856
|
+
if (!opts.ignoreOverride && app.overrides?.environment) {
|
|
886
857
|
return app.overrides.environment.toString();
|
|
887
858
|
}
|
|
888
859
|
const { group } = getCurrentEnvironment();
|
|
@@ -909,8 +880,7 @@ function getDomainForCurrentEnvironment(config, appName, opts = {}) {
|
|
|
909
880
|
|
|
910
881
|
// src/next/middleware/middleware.ts
|
|
911
882
|
async function verifyPreviewDomain(req, rewriteDomain) {
|
|
912
|
-
|
|
913
|
-
const jwtCookie = (_a = req.cookies.get("_vercel_jwt")) == null ? void 0 : _a.value;
|
|
883
|
+
const jwtCookie = req.cookies.get("_vercel_jwt")?.value;
|
|
914
884
|
const deploymentProtectionBypassHeader = req.headers.get(
|
|
915
885
|
"x-vercel-protection-bypass"
|
|
916
886
|
);
|
|
@@ -935,7 +905,6 @@ function getHandler({
|
|
|
935
905
|
production
|
|
936
906
|
}) {
|
|
937
907
|
return async (req) => {
|
|
938
|
-
var _a, _b;
|
|
939
908
|
try {
|
|
940
909
|
const pathname = req.nextUrl.pathname;
|
|
941
910
|
const search = req.nextUrl.search;
|
|
@@ -952,7 +921,7 @@ function getHandler({
|
|
|
952
921
|
if (process.env.VERCEL_ENV === "preview" && rewriteDomain) {
|
|
953
922
|
const zoneFallbackCookieName = `__zone_${application.name}_production_fallback`;
|
|
954
923
|
const assetPrefix = application.getAssetPrefix();
|
|
955
|
-
if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) &&
|
|
924
|
+
if (assetPrefix && pathname.startsWith(`/${assetPrefix}`) && req.cookies.get(zoneFallbackCookieName)?.value === "1") {
|
|
956
925
|
rewriteDomain = production.toString();
|
|
957
926
|
} else {
|
|
958
927
|
try {
|
|
@@ -975,7 +944,7 @@ function getHandler({
|
|
|
975
944
|
});
|
|
976
945
|
try {
|
|
977
946
|
const existingCookie = patchedHeaders.get("cookie");
|
|
978
|
-
if (!
|
|
947
|
+
if (!existingCookie?.includes("__vercel_toolbar")) {
|
|
979
948
|
patchedHeaders.set(
|
|
980
949
|
"cookie",
|
|
981
950
|
[`__vercel_toolbar=1`, existingCookie].join("; ")
|
|
@@ -991,7 +960,7 @@ function getHandler({
|
|
|
991
960
|
}
|
|
992
961
|
} catch (error) {
|
|
993
962
|
}
|
|
994
|
-
} else if (
|
|
963
|
+
} else if (req.cookies.get(zoneFallbackCookieName)?.value === "1") {
|
|
995
964
|
responseCallbacks.push((response) => {
|
|
996
965
|
response.cookies.set(zoneFallbackCookieName, "", {
|
|
997
966
|
httpOnly: true,
|
|
@@ -1074,7 +1043,7 @@ function getMicrofrontendsMiddleware({
|
|
|
1074
1043
|
const flagName = pathGroup.flag;
|
|
1075
1044
|
let flagFn;
|
|
1076
1045
|
if (flagName) {
|
|
1077
|
-
flagFn = flagValues
|
|
1046
|
+
flagFn = flagValues?.[flagName];
|
|
1078
1047
|
if (!flagFn) {
|
|
1079
1048
|
throw new Error(
|
|
1080
1049
|
`Flag "${flagName}" was specified to control routing for path group "${pathGroup.group}" in application ${application.name} but not found in provided flag values.`
|