remote-components 0.0.34 → 0.0.36
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/dist/html/host.cjs +127 -117
- package/dist/html/host.cjs.map +1 -1
- package/dist/html/host.js +127 -117
- package/dist/html/host.js.map +1 -1
- package/dist/html/remote.cjs +4 -3
- package/dist/html/remote.cjs.map +1 -1
- package/dist/html/remote.js +4 -3
- package/dist/html/remote.js.map +1 -1
- package/dist/internal/next/host/app-router-client.cjs +4 -15
- package/dist/internal/next/host/app-router-client.cjs.map +1 -1
- package/dist/internal/next/host/app-router-client.js +10 -21
- package/dist/internal/next/host/app-router-client.js.map +1 -1
- package/dist/internal/next/host/app-router-compat.cjs.map +1 -1
- package/dist/internal/next/host/app-router-compat.d.ts +1 -1
- package/dist/internal/next/host/app-router-compat.js.map +1 -1
- package/dist/internal/next/remote/render-server.cjs +1 -1
- package/dist/internal/next/remote/render-server.cjs.map +1 -1
- package/dist/internal/next/remote/render-server.js +1 -1
- package/dist/internal/next/remote/render-server.js.map +1 -1
- package/dist/internal/shared/client/polyfill.cjs.map +1 -1
- package/dist/internal/shared/client/polyfill.js.map +1 -1
- package/dist/internal/shared/client/remote-component.cjs +179 -174
- package/dist/internal/shared/client/remote-component.cjs.map +1 -1
- package/dist/internal/shared/client/remote-component.d.ts +23 -23
- package/dist/internal/shared/client/remote-component.js +179 -174
- package/dist/internal/shared/client/remote-component.js.map +1 -1
- package/dist/internal/shared/error.cjs +1 -1
- package/dist/internal/shared/error.cjs.map +1 -1
- package/dist/internal/shared/error.js +1 -1
- package/dist/internal/shared/error.js.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.cjs +7 -3
- package/dist/internal/shared/ssr/dom-flight.cjs.map +1 -1
- package/dist/internal/shared/ssr/dom-flight.js +7 -3
- package/dist/internal/shared/ssr/dom-flight.js.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.cjs +4 -4
- package/dist/internal/shared/ssr/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/shared/ssr/fetch-remote-component.js +5 -5
- package/dist/internal/shared/ssr/fetch-remote-component.js.map +1 -1
- package/dist/next/config.cjs +100 -86
- package/dist/next/config.cjs.map +1 -1
- package/dist/next/config.js +100 -86
- package/dist/next/config.js.map +1 -1
- package/dist/next/host/app-router-server.cjs.map +1 -1
- package/dist/next/host/app-router-server.js +1 -1
- package/dist/next/host/app-router-server.js.map +1 -1
- package/dist/next/host/client/index.cjs +723 -718
- package/dist/next/host/client/index.cjs.map +1 -1
- package/dist/next/host/client/index.js +727 -722
- package/dist/next/host/client/index.js.map +1 -1
- package/dist/next/host/pages-router-server.cjs +4 -4
- package/dist/next/host/pages-router-server.cjs.map +1 -1
- package/dist/next/host/pages-router-server.js +4 -4
- package/dist/next/host/pages-router-server.js.map +1 -1
- package/dist/next/{middleware.cjs → proxy.cjs} +24 -14
- package/dist/next/proxy.cjs.map +1 -0
- package/dist/next/proxy.d.ts +29 -0
- package/dist/next/{middleware.js → proxy.js} +21 -11
- package/dist/next/proxy.js.map +1 -0
- package/dist/react/index.cjs +4 -4
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +11 -11
- package/dist/react/index.js.map +1 -1
- package/package.json +15 -9
- package/dist/next/middleware.cjs.map +0 -1
- package/dist/next/middleware.d.ts +0 -29
- package/dist/next/middleware.js.map +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
interface RemoteComponentMiddlewareOptions {
|
|
4
|
-
cors?: {
|
|
5
|
-
origin?: string | string[];
|
|
6
|
-
method?: string | string[];
|
|
7
|
-
headers?: string | string[];
|
|
8
|
-
credentials?: boolean;
|
|
9
|
-
maxAge?: string;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* This middleware is used to handle CORS and other remote component related tasks.
|
|
14
|
-
* It can be used to wrap a Next.js middleware function to add CORS headers and handle preflight requests.
|
|
15
|
-
*
|
|
16
|
-
* @param middleware - The Next.js middleware function to wrap.
|
|
17
|
-
* @param options - Optional configuration for handling remote components.
|
|
18
|
-
* @returns A Next.js middleware function that handles CORS and preflight requests
|
|
19
|
-
*/
|
|
20
|
-
declare function withRemoteComponents(middleware?: (request: NextRequest) => NextResponse | Promise<NextResponse>, options?: RemoteComponentMiddlewareOptions): (request: NextRequest) => Promise<Response>;
|
|
21
|
-
/**
|
|
22
|
-
* This configuration is used to specify the paths that the middleware should match.
|
|
23
|
-
* It matches all paths by default.
|
|
24
|
-
*/
|
|
25
|
-
declare const config: {
|
|
26
|
-
matcher: string;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { RemoteComponentMiddlewareOptions, config, withRemoteComponents };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/next/middleware/index.ts"],"sourcesContent":["import { type NextRequest, NextResponse } from 'next/server';\n\nexport interface RemoteComponentMiddlewareOptions {\n cors?: {\n origin?: string | string[];\n method?: string | string[];\n headers?: string | string[];\n credentials?: boolean;\n maxAge?: string;\n };\n}\n\nfunction corsHeadersFromOptions(\n options?: RemoteComponentMiddlewareOptions['cors'],\n headers?: Headers,\n) {\n const origin =\n headers?.get('origin') ??\n (headers?.has('referer')\n ? new URL(headers.get('referer') ?? '*').origin\n : '*');\n\n const ALLOWED_ORIGINS = (\n process.env.REMOTE_COMPONENTS_ALLOWED_ORIGINS ||\n (Array.isArray(options?.origin)\n ? options.origin.join(',')\n : options?.origin) ||\n '*'\n )\n .split(',')\n .map((allowedOrigin) => allowedOrigin.trim());\n\n const isAllowed =\n ALLOWED_ORIGINS.includes('*') || ALLOWED_ORIGINS.includes(origin);\n\n const allowedHeaders =\n process.env.REMOTE_COMPONENTS_ALLOW_HEADERS ||\n (Array.isArray(options?.headers)\n ? options.headers.map((h) => h.trim()).join(',')\n : options?.headers) ||\n headers?.get('access-control-request-headers');\n\n const CORS_HEADERS = (\n isAllowed\n ? {\n 'Access-Control-Allow-Origin': origin,\n 'Access-Control-Allow-Methods':\n process.env.REMOTE_COMPONENTS_ALLOW_METHODS ||\n (Array.isArray(options?.method)\n ? options.method.map((m) => m.trim()).join(',')\n : options?.method) ||\n 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS',\n ...(allowedHeaders\n ? { 'Access-Control-Allow-Headers': allowedHeaders }\n : {}),\n ...(process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS ||\n options?.credentials\n ? {\n 'Access-Control-Allow-Credentials':\n process.env.REMOTE_COMPONENTS_ALLOW_CREDENTIALS || 'true',\n }\n : {}),\n 'Access-Control-Max-Age': options?.maxAge || '600',\n Vary: 'Origin',\n }\n : {}\n ) as Record<string, string>;\n\n return CORS_HEADERS;\n}\n\n/**\n * This middleware is used to handle CORS and other remote component related tasks.\n * It can be used to wrap a Next.js middleware function to add CORS headers and handle preflight requests.\n *\n * @param middleware - The Next.js middleware function to wrap.\n * @param options - Optional configuration for handling remote components.\n * @returns A Next.js middleware function that handles CORS and preflight requests\n */\nexport function withRemoteComponents(\n middleware?: (request: NextRequest) => NextResponse | Promise<NextResponse>,\n options?: RemoteComponentMiddlewareOptions,\n) {\n return async (request: NextRequest) => {\n const corsHeaders = corsHeadersFromOptions(options?.cors, request.headers);\n\n // Handle preflight\n if (request.method === 'OPTIONS') {\n return new Response(null, {\n status: 200,\n headers: corsHeaders,\n });\n }\n\n // For all other requests, continue and attach CORS\n const response =\n typeof middleware === 'function'\n ? await middleware(request)\n : NextResponse.next();\n\n Object.entries(corsHeaders).forEach(([k, v]) => response.headers.set(k, v));\n\n return response;\n };\n}\n\n/**\n * This configuration is used to specify the paths that the middleware should match.\n * It matches all paths by default.\n */\nexport const config = {\n matcher: '/:path*',\n};\n"],"mappings":";AAAA,SAA2B,oBAAoB;AAY/C,SAAS,uBACP,SACA,SACA;AACA,QAAM,SACJ,SAAS,IAAI,QAAQ,MACpB,SAAS,IAAI,SAAS,IACnB,IAAI,IAAI,Q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