ellmo-ai-react 0.0.14 → 0.0.15

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.
@@ -35,7 +35,7 @@ type AppContext = {
35
35
  */
36
36
  export declare function withEllmoApp({ clientId, url, type }: {
37
37
  clientId: string;
38
- url: string;
38
+ url: (appContext: AppContext) => string;
39
39
  type?: EllmoApiType;
40
40
  }): (appContext: AppContext) => Promise<{
41
41
  pageProps: {};
@@ -1 +1 @@
1
- {"version":3,"file":"EllmoApiStatic.d.ts","sourceRoot":"","sources":["../src/EllmoApiStatic.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,YAAY,EAAE,YAAY,EAAE,CAAC;AAG7B,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,GAAG,CAAC;IACf,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,GAAG,EACH,IAAiB,EAClB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,IACe,YAAY,UAAU;;;;GAqBrC"}
1
+ {"version":3,"file":"EllmoApiStatic.d.ts","sourceRoot":"","sources":["../src/EllmoApiStatic.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7D,YAAY,EAAE,YAAY,EAAE,CAAC;AAG7B,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,GAAG,CAAC;IACf,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,GAAG,CAAC;CACb,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,GAAG,EACH,IAAiB,EAClB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC;IACxC,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,IACe,YAAY,UAAU;;;;GAqBrC"}
package/dist/index.d.ts CHANGED
@@ -191,7 +191,7 @@ type AppContext = {
191
191
  */
192
192
  declare function withEllmoApp({ clientId, url, type }: {
193
193
  clientId: string;
194
- url: string;
194
+ url: (appContext: AppContext) => string;
195
195
  type?: EllmoApiType;
196
196
  }): (appContext: AppContext) => Promise<{
197
197
  pageProps: {};
package/dist/index.js CHANGED
@@ -232,7 +232,7 @@ function withEllmoApp({ clientId, url, type = 'semantic' }) {
232
232
  // Fetch global Ellmo data
233
233
  const { data, error } = await fetchEllmoData({
234
234
  clientId,
235
- url,
235
+ url: url(appContext), // Use the function to get the URL
236
236
  type
237
237
  });
238
238
  // Call the page's getInitialProps if it exists
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/EllmoApi.tsx","../src/EllmoApiSSR.tsx","../src/shared.ts","../src/EllmoApiStatic.tsx","../src/middleware.ts"],"sourcesContent":["import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiProps {\n /**\n * The URL path to fetch data for (required).\n * \n * With middleware (recommended):\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * const pathname = getPathnameFromHeaders(headers());\n * <EllmoApi clientId=\"...\" url={pathname || '/'} />\n * ```\n * \n * Without middleware:\n * ```tsx\n * <EllmoApi clientId=\"...\" url=\"/about\" />\n * ```\n */\n url: string;\n /**\n * The API key/client identifier (required)\n */\n clientId: string;\n /**\n * Type of data to fetch\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children to render when data is available\n */\n children?: (data: any, error: Error | null) => React.ReactNode;\n}\n\n/**\n * Server-only Ellmo API component (React Server Component)\n * This component fetches data during server rendering.\n * It requires Next.js 13+ App Router or other RSC-compatible frameworks.\n * \n * @example\n * ```tsx\n * // In a server component (app/page.tsx)\n * export default async function Page() {\n * return <EllmoApi clientId=\"your-id\" url=\"/about\" />;\n * }\n * ```\n */\nconst EllmoApi = async ({\n url,\n clientId,\n type,\n className = '',\n showErrors = false,\n children\n}: EllmoApiProps): Promise<React.ReactElement | null> => {\n let data: any = null;\n let error: Error | null = null;\n\n let translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url prop is required. Please provide the page pathname.');\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data during server render\n const response = await fetch(apiUrl, {\n cache: 'no-store', // Always fetch fresh data\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n if (type === 'structured') {\n data = await response.text();\n } else if (type === 'semantic') {\n data = await response.text();\n } else {\n throw new Error(`Invalid type: ${type}`);\n }\n } catch (err) {\n error = err instanceof Error ? err : new Error('Unknown error occurred');\n }\n\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error.message}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{JSON.stringify(data, null, 2)}</pre>\n </div>\n );\n }\n\n // Invisible component by default - just fetches data during server render\n if (type === 'structured' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n } else if (type === 'semantic' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n }\n return null;\n};\n\nexport default EllmoApi;\n","import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiSSRProps {\n /**\n * The pre-fetched data from the Ellmo API\n */\n data?: string | null;\n /**\n * Error from fetching data\n */\n error?: string | null;\n /**\n * Type of data to render\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children render prop with data and error\n */\n children?: (data: string | null, error: string | null) => React.ReactNode;\n}\n\n/**\n * Ellmo API component for traditional SSR environments (Next.js Pages Router)\n * This component receives pre-fetched data and renders it.\n * Data fetching should be done in getServerSideProps or getStaticProps.\n * \n * @example\n * ```tsx\n * // In your page file (pages/about.tsx)\n * import { EllmoApiSSR, fetchEllmoData } from 'ellmo-ai-react';\n * \n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: 'your-client-id',\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * export default function AboutPage({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <h1>About Page</h1>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * </div>\n * );\n * }\n * ```\n */\nconst EllmoApiSSR: React.FC<EllmoApiSSRProps> = ({\n data = null,\n error = null,\n className = '',\n showErrors = false,\n children\n}) => {\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{data}</pre>\n </div>\n );\n }\n\n // Render HTML content if available\n if (data && !error) {\n return <div className={className} dangerouslySetInnerHTML={{ __html: data }} />;\n }\n\n // Return null if no data\n return null;\n};\n\nexport default EllmoApiSSR;\n \n","export type EllmoApiType = 'semantic' | 'structured';\n\n/**\n * Fetch data from Ellmo API\n * Use this in getServerSideProps, getStaticProps, or getInitialProps\n * \n * @example\n * ```tsx\n * // In getServerSideProps (Next.js Pages Router)\n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * // In getInitialProps (older Next.js API)\n * MyPage.getInitialProps = async (ctx) => {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: ctx.asPath || '/',\n * type: 'semantic'\n * });\n * \n * return { ellmoData: data, ellmoError: error };\n * };\n * ```\n */\nexport async function fetchEllmoData({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}): Promise<{ data: string | null; error: string | null }> {\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url is required. Please provide the page pathname.');\n }\n\n if (url.includes('.')) {\n // Sometimes urls contain a dot if they're images or other assets which are served by SSG (static generation)\n return { data: null, error: null };\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n const translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data\n const response = await fetch(apiUrl, {\n cache: 'no-store',\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n const data = await response.text();\n return { data, error: null };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';\n return { data: null, error: errorMessage };\n }\n}\n\n","import { fetchEllmoData, type EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\n// Type for Next.js App context\ntype AppContext = {\n Component: any;\n ctx: any;\n router: any;\n};\n\n\n/**\n * Helper for _app.tsx to fetch global Ellmo data and merge with page props\n * Automatically calls the page's getInitialProps and merges everything\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps, globalEllmoData, globalEllmoError }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR data={globalEllmoData} error={globalEllmoError} />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: '/global-header',\n * type: 'structured'\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}) {\n return async (appContext: AppContext) => {\n // Fetch global Ellmo data\n const { data, error } = await fetchEllmoData({\n clientId,\n url,\n type\n });\n\n // Call the page's getInitialProps if it exists\n let pageProps = {};\n if (appContext.Component.getInitialProps) {\n pageProps = await appContext.Component.getInitialProps(appContext.ctx);\n }\n\n // Return merged props\n return {\n pageProps,\n globalEllmoData: data,\n globalEllmoError: error\n };\n };\n}\n","/**\n * Custom header name for Ellmo AI to pass pathname information\n * Using 'x-ellmo-pathname' to avoid conflicts with other libraries\n */\nexport const ELLMO_PATHNAME_HEADER = 'x-ellmo-pathname';\n\n/**\n * Type definitions for Next.js middleware (to avoid requiring Next.js as a dependency)\n */\nexport interface EllmoRequest {\n nextUrl: {\n pathname: string;\n };\n}\n\nexport interface EllmoResponse {\n headers: {\n set(name: string, value: string): void;\n };\n}\n\n/**\n * Ellmo AI middleware helper for Next.js\n * \n * This is a vanilla helper that adds pathname to request headers.\n * It doesn't depend on Next.js - you provide the request/response objects.\n * \n * Usage in Next.js:\n * \n * ```ts\n * // middleware.ts\n * import { ellmoMiddleware } from 'ellmo-ai-react/middleware';\n * import { NextResponse } from 'next/server';\n * import type { NextRequest } from 'next/server';\n * \n * export function middleware(request: NextRequest) {\n * const response = NextResponse.next();\n * return ellmoMiddleware(request, response);\n * }\n * \n * export const config = {\n * matcher: [\n * '/((?!_next/static|_next/image|favicon.ico).*)',\n * ],\n * };\n * ```\n * \n * Composing with existing middleware:\n * \n * ```ts\n * export function middleware(request: NextRequest) {\n * let response = NextResponse.next();\n * \n * // Your logic here\n * if (someCondition) {\n * response = NextResponse.redirect(new URL('/login', request.url));\n * }\n * \n * // Apply Ellmo middleware\n * return ellmoMiddleware(request, response);\n * }\n * ```\n */\nexport function ellmoMiddleware<\n Req extends EllmoRequest,\n Res extends EllmoResponse\n>(\n request: Req,\n response: Res\n): Res {\n // Extract pathname from the request URL\n const pathname = request.nextUrl.pathname;\n \n // Add the pathname to a custom header\n response.headers.set(ELLMO_PATHNAME_HEADER, pathname);\n \n return response;\n}\n\n/**\n * Helper to extract pathname from headers object\n * \n * Usage in Next.js Server Components:\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * export default function Page() {\n * const headersList = headers();\n * const pathname = getPathnameFromHeaders(headersList);\n * \n * return <EllmoApi clientId=\"your-id\" url={pathname} />;\n * }\n * ```\n */\nexport function getPathnameFromHeaders(headers: { get(name: string): string | null }): string | null {\n return headers.get(ELLMO_PATHNAME_HEADER);\n}\n\nexport default ellmoMiddleware;\n"],"names":[],"mappings":";;;;AA8CA;;;;;;;;;;;;AAYG;AACG,MAAA,QAAQ,GAAG,OAAO,EACtB,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,KAAK,EAClB,QAAQ,EACM,KAAwC;IACtD,IAAI,IAAI,GAAQ,IAAI,CAAC;IACrB,IAAI,KAAK,GAAiB,I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cAAc,CAAC;YAC3C,QAAQ;YACR,GAAG;YACH,IAAI;AACL,SAAA,CAAC,CAAC;;QAGH,IAAI,SAAS,GAAG,EAAE,CAAC;AACnB,QAAA,IAAI,UAAU,CAAC,SAAS,CAAC,eAAe,EAAE;AACxC,YAAA,SAAS,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACxE;;QAGD,OAAO;YACL,SAAS;AACT,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,gBAAgB,EAAE,KAAK;SACxB,CAAC;AACJ,KAAC,CAAC;AACJ;;ACtEA;;;AAGG;AACI,MAAM,qBAAqB,GAAG,mBAAmB;AAiBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCG;AACa,SAAA,eAAe,CAI7B,OAAY,EACZ,QAAa,EAAA;;AAGb,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;;IAG1C,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;AAEtD,IAAA,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;AAeG;AACG,SAAU,sBAAsB,CAAC,OAA6C,EAAA;AAClF,IAAA,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAC5C;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/EllmoApi.tsx","../src/EllmoApiSSR.tsx","../src/shared.ts","../src/EllmoApiStatic.tsx","../src/middleware.ts"],"sourcesContent":["import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiProps {\n /**\n * The URL path to fetch data for (required).\n * \n * With middleware (recommended):\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * const pathname = getPathnameFromHeaders(headers());\n * <EllmoApi clientId=\"...\" url={pathname || '/'} />\n * ```\n * \n * Without middleware:\n * ```tsx\n * <EllmoApi clientId=\"...\" url=\"/about\" />\n * ```\n */\n url: string;\n /**\n * The API key/client identifier (required)\n */\n clientId: string;\n /**\n * Type of data to fetch\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children to render when data is available\n */\n children?: (data: any, error: Error | null) => React.ReactNode;\n}\n\n/**\n * Server-only Ellmo API component (React Server Component)\n * This component fetches data during server rendering.\n * It requires Next.js 13+ App Router or other RSC-compatible frameworks.\n * \n * @example\n * ```tsx\n * // In a server component (app/page.tsx)\n * export default async function Page() {\n * return <EllmoApi clientId=\"your-id\" url=\"/about\" />;\n * }\n * ```\n */\nconst EllmoApi = async ({\n url,\n clientId,\n type,\n className = '',\n showErrors = false,\n children\n}: EllmoApiProps): Promise<React.ReactElement | null> => {\n let data: any = null;\n let error: Error | null = null;\n\n let translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url prop is required. Please provide the page pathname.');\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data during server render\n const response = await fetch(apiUrl, {\n cache: 'no-store', // Always fetch fresh data\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n if (type === 'structured') {\n data = await response.text();\n } else if (type === 'semantic') {\n data = await response.text();\n } else {\n throw new Error(`Invalid type: ${type}`);\n }\n } catch (err) {\n error = err instanceof Error ? err : new Error('Unknown error occurred');\n }\n\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error.message}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{JSON.stringify(data, null, 2)}</pre>\n </div>\n );\n }\n\n // Invisible component by default - just fetches data during server render\n if (type === 'structured' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n } else if (type === 'semantic' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n }\n return null;\n};\n\nexport default EllmoApi;\n","import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiSSRProps {\n /**\n * The pre-fetched data from the Ellmo API\n */\n data?: string | null;\n /**\n * Error from fetching data\n */\n error?: string | null;\n /**\n * Type of data to render\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children render prop with data and error\n */\n children?: (data: string | null, error: string | null) => React.ReactNode;\n}\n\n/**\n * Ellmo API component for traditional SSR environments (Next.js Pages Router)\n * This component receives pre-fetched data and renders it.\n * Data fetching should be done in getServerSideProps or getStaticProps.\n * \n * @example\n * ```tsx\n * // In your page file (pages/about.tsx)\n * import { EllmoApiSSR, fetchEllmoData } from 'ellmo-ai-react';\n * \n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: 'your-client-id',\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * export default function AboutPage({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <h1>About Page</h1>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * </div>\n * );\n * }\n * ```\n */\nconst EllmoApiSSR: React.FC<EllmoApiSSRProps> = ({\n data = null,\n error = null,\n className = '',\n showErrors = false,\n children\n}) => {\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{data}</pre>\n </div>\n );\n }\n\n // Render HTML content if available\n if (data && !error) {\n return <div className={className} dangerouslySetInnerHTML={{ __html: data }} />;\n }\n\n // Return null if no data\n return null;\n};\n\nexport default EllmoApiSSR;\n \n","export type EllmoApiType = 'semantic' | 'structured';\n\n/**\n * Fetch data from Ellmo API\n * Use this in getServerSideProps, getStaticProps, or getInitialProps\n * \n * @example\n * ```tsx\n * // In getServerSideProps (Next.js Pages Router)\n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * // In getInitialProps (older Next.js API)\n * MyPage.getInitialProps = async (ctx) => {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: ctx.asPath || '/',\n * type: 'semantic'\n * });\n * \n * return { ellmoData: data, ellmoError: error };\n * };\n * ```\n */\nexport async function fetchEllmoData({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}): Promise<{ data: string | null; error: string | null }> {\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url is required. Please provide the page pathname.');\n }\n\n if (url.includes('.')) {\n // Sometimes urls contain a dot if they're images or other assets which are served by SSG (static generation)\n return { data: null, error: null };\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n const translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data\n const response = await fetch(apiUrl, {\n cache: 'no-store',\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n const data = await response.text();\n return { data, error: null };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';\n return { data: null, error: errorMessage };\n }\n}\n\n","import { fetchEllmoData, type EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\n// Type for Next.js App context\ntype AppContext = {\n Component: any;\n ctx: any;\n router: any;\n};\n\n\n/**\n * Helper for _app.tsx to fetch global Ellmo data and merge with page props\n * Automatically calls the page's getInitialProps and merges everything\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps, globalEllmoData, globalEllmoError }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR data={globalEllmoData} error={globalEllmoError} />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: '/global-header',\n * type: 'structured'\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n}) {\n return async (appContext: AppContext) => {\n // Fetch global Ellmo data\n const { data, error } = await fetchEllmoData({\n clientId,\n url: url(appContext), // Use the function to get the URL\n type\n });\n\n // Call the page's getInitialProps if it exists\n let pageProps = {};\n if (appContext.Component.getInitialProps) {\n pageProps = await appContext.Component.getInitialProps(appContext.ctx);\n }\n\n // Return merged props\n return {\n pageProps,\n globalEllmoData: data,\n globalEllmoError: error\n };\n };\n}\n","/**\n * Custom header name for Ellmo AI to pass pathname information\n * Using 'x-ellmo-pathname' to avoid conflicts with other libraries\n */\nexport const ELLMO_PATHNAME_HEADER = 'x-ellmo-pathname';\n\n/**\n * Type definitions for Next.js middleware (to avoid requiring Next.js as a dependency)\n */\nexport interface EllmoRequest {\n nextUrl: {\n pathname: string;\n };\n}\n\nexport interface EllmoResponse {\n headers: {\n set(name: string, value: string): void;\n };\n}\n\n/**\n * Ellmo AI middleware helper for Next.js\n * \n * This is a vanilla helper that adds pathname to request headers.\n * It doesn't depend on Next.js - you provide the request/response objects.\n * \n * Usage in Next.js:\n * \n * ```ts\n * // middleware.ts\n * import { ellmoMiddleware } from 'ellmo-ai-react/middleware';\n * import { NextResponse } from 'next/server';\n * import type { NextRequest } from 'next/server';\n * \n * export function middleware(request: NextRequest) {\n * const response = NextResponse.next();\n * return ellmoMiddleware(request, response);\n * }\n * \n * export const config = {\n * matcher: [\n * '/((?!_next/static|_next/image|favicon.ico).*)',\n * ],\n * };\n * ```\n * \n * Composing with existing middleware:\n * \n * ```ts\n * export function middleware(request: NextRequest) {\n * let response = NextResponse.next();\n * \n * // Your logic here\n * if (someCondition) {\n * response = NextResponse.redirect(new URL('/login', request.url));\n * }\n * \n * // Apply Ellmo middleware\n * return ellmoMiddleware(request, response);\n * }\n * ```\n */\nexport function ellmoMiddleware<\n Req extends EllmoRequest,\n Res extends EllmoResponse\n>(\n request: Req,\n response: Res\n): Res {\n // Extract pathname from the request URL\n const pathname = request.nextUrl.pathname;\n \n // Add the pathname to a custom header\n response.headers.set(ELLMO_PATHNAME_HEADER, pathname);\n \n return response;\n}\n\n/**\n * Helper to extract pathname from headers object\n * \n * Usage in Next.js Server Components:\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * export default function Page() {\n * const headersList = headers();\n * const pathname = getPathnameFromHeaders(headersList);\n * \n * return <EllmoApi clientId=\"your-id\" url={pathname} />;\n * }\n * ```\n */\nexport function getPathnameFromHeaders(headers: { get(name: string): string | null }): string | null {\n return headers.get(ELLMO_PATHNAME_HEADER);\n}\n\nexport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function withEllmoApp({ clientId, url, type = 'semantic' }) {
230
230
  // Fetch global Ellmo data
231
231
  const { data, error } = await fetchEllmoData({
232
232
  clientId,
233
- url,
233
+ url: url(appContext), // Use the function to get the URL
234
234
  type
235
235
  });
236
236
  // Call the page's getInitialProps if it exists
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/EllmoApi.tsx","../src/EllmoApiSSR.tsx","../src/shared.ts","../src/EllmoApiStatic.tsx","../src/middleware.ts"],"sourcesContent":["import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiProps {\n /**\n * The URL path to fetch data for (required).\n * \n * With middleware (recommended):\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * const pathname = getPathnameFromHeaders(headers());\n * <EllmoApi clientId=\"...\" url={pathname || '/'} />\n * ```\n * \n * Without middleware:\n * ```tsx\n * <EllmoApi clientId=\"...\" url=\"/about\" />\n * ```\n */\n url: string;\n /**\n * The API key/client identifier (required)\n */\n clientId: string;\n /**\n * Type of data to fetch\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children to render when data is available\n */\n children?: (data: any, error: Error | null) => React.ReactNode;\n}\n\n/**\n * Server-only Ellmo API component (React Server Component)\n * This component fetches data during server rendering.\n * It requires Next.js 13+ App Router or other RSC-compatible frameworks.\n * \n * @example\n * ```tsx\n * // In a server component (app/page.tsx)\n * export default async function Page() {\n * return <EllmoApi clientId=\"your-id\" url=\"/about\" />;\n * }\n * ```\n */\nconst EllmoApi = async ({\n url,\n clientId,\n type,\n className = '',\n showErrors = false,\n children\n}: EllmoApiProps): Promise<React.ReactElement | null> => {\n let data: any = null;\n let error: Error | null = null;\n\n let translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url prop is required. Please provide the page pathname.');\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data during server render\n const response = await fetch(apiUrl, {\n cache: 'no-store', // Always fetch fresh data\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n if (type === 'structured') {\n data = await response.text();\n } else if (type === 'semantic') {\n data = await response.text();\n } else {\n throw new Error(`Invalid type: ${type}`);\n }\n } catch (err) {\n error = err instanceof Error ? err : new Error('Unknown error occurred');\n }\n\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error.message}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{JSON.stringify(data, null, 2)}</pre>\n </div>\n );\n }\n\n // Invisible component by default - just fetches data during server render\n if (type === 'structured' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n } else if (type === 'semantic' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n }\n return null;\n};\n\nexport default EllmoApi;\n","import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiSSRProps {\n /**\n * The pre-fetched data from the Ellmo API\n */\n data?: string | null;\n /**\n * Error from fetching data\n */\n error?: string | null;\n /**\n * Type of data to render\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children render prop with data and error\n */\n children?: (data: string | null, error: string | null) => React.ReactNode;\n}\n\n/**\n * Ellmo API component for traditional SSR environments (Next.js Pages Router)\n * This component receives pre-fetched data and renders it.\n * Data fetching should be done in getServerSideProps or getStaticProps.\n * \n * @example\n * ```tsx\n * // In your page file (pages/about.tsx)\n * import { EllmoApiSSR, fetchEllmoData } from 'ellmo-ai-react';\n * \n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: 'your-client-id',\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * export default function AboutPage({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <h1>About Page</h1>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * </div>\n * );\n * }\n * ```\n */\nconst EllmoApiSSR: React.FC<EllmoApiSSRProps> = ({\n data = null,\n error = null,\n className = '',\n showErrors = false,\n children\n}) => {\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{data}</pre>\n </div>\n );\n }\n\n // Render HTML content if available\n if (data && !error) {\n return <div className={className} dangerouslySetInnerHTML={{ __html: data }} />;\n }\n\n // Return null if no data\n return null;\n};\n\nexport default EllmoApiSSR;\n \n","export type EllmoApiType = 'semantic' | 'structured';\n\n/**\n * Fetch data from Ellmo API\n * Use this in getServerSideProps, getStaticProps, or getInitialProps\n * \n * @example\n * ```tsx\n * // In getServerSideProps (Next.js Pages Router)\n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * // In getInitialProps (older Next.js API)\n * MyPage.getInitialProps = async (ctx) => {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: ctx.asPath || '/',\n * type: 'semantic'\n * });\n * \n * return { ellmoData: data, ellmoError: error };\n * };\n * ```\n */\nexport async function fetchEllmoData({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}): Promise<{ data: string | null; error: string | null }> {\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url is required. Please provide the page pathname.');\n }\n\n if (url.includes('.')) {\n // Sometimes urls contain a dot if they're images or other assets which are served by SSG (static generation)\n return { data: null, error: null };\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n const translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data\n const response = await fetch(apiUrl, {\n cache: 'no-store',\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n const data = await response.text();\n return { data, error: null };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';\n return { data: null, error: errorMessage };\n }\n}\n\n","import { fetchEllmoData, type EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\n// Type for Next.js App context\ntype AppContext = {\n Component: any;\n ctx: any;\n router: any;\n};\n\n\n/**\n * Helper for _app.tsx to fetch global Ellmo data and merge with page props\n * Automatically calls the page's getInitialProps and merges everything\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps, globalEllmoData, globalEllmoError }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR data={globalEllmoData} error={globalEllmoError} />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: '/global-header',\n * type: 'structured'\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}) {\n return async (appContext: AppContext) => {\n // Fetch global Ellmo data\n const { data, error } = await fetchEllmoData({\n clientId,\n url,\n type\n });\n\n // Call the page's getInitialProps if it exists\n let pageProps = {};\n if (appContext.Component.getInitialProps) {\n pageProps = await appContext.Component.getInitialProps(appContext.ctx);\n }\n\n // Return merged props\n return {\n pageProps,\n globalEllmoData: data,\n globalEllmoError: error\n };\n };\n}\n","/**\n * Custom header name for Ellmo AI to pass pathname information\n * Using 'x-ellmo-pathname' to avoid conflicts with other libraries\n */\nexport const ELLMO_PATHNAME_HEADER = 'x-ellmo-pathname';\n\n/**\n * Type definitions for Next.js middleware (to avoid requiring Next.js as a dependency)\n */\nexport interface EllmoRequest {\n nextUrl: {\n pathname: string;\n };\n}\n\nexport interface EllmoResponse {\n headers: {\n set(name: string, value: string): void;\n };\n}\n\n/**\n * Ellmo AI middleware helper for Next.js\n * \n * This is a vanilla helper that adds pathname to request headers.\n * It doesn't depend on Next.js - you provide the request/response objects.\n * \n * Usage in Next.js:\n * \n * ```ts\n * // middleware.ts\n * import { ellmoMiddleware } from 'ellmo-ai-react/middleware';\n * import { NextResponse } from 'next/server';\n * import type { NextRequest } from 'next/server';\n * \n * export function middleware(request: NextRequest) {\n * const response = NextResponse.next();\n * return ellmoMiddleware(request, response);\n * }\n * \n * export const config = {\n * matcher: [\n * '/((?!_next/static|_next/image|favicon.ico).*)',\n * ],\n * };\n * ```\n * \n * Composing with existing middleware:\n * \n * ```ts\n * export function middleware(request: NextRequest) {\n * let response = NextResponse.next();\n * \n * // Your logic here\n * if (someCondition) {\n * response = NextResponse.redirect(new URL('/login', request.url));\n * }\n * \n * // Apply Ellmo middleware\n * return ellmoMiddleware(request, response);\n * }\n * ```\n */\nexport function ellmoMiddleware<\n Req extends EllmoRequest,\n Res extends EllmoResponse\n>(\n request: Req,\n response: Res\n): Res {\n // Extract pathname from the request URL\n const pathname = request.nextUrl.pathname;\n \n // Add the pathname to a custom header\n response.headers.set(ELLMO_PATHNAME_HEADER, pathname);\n \n return response;\n}\n\n/**\n * Helper to extract pathname from headers object\n * \n * Usage in Next.js Server Components:\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * export default function Page() {\n * const headersList = headers();\n * const pathname = getPathnameFromHeaders(headersList);\n * \n * return <EllmoApi clientId=\"your-id\" url={pathname} />;\n * }\n * ```\n */\nexport function getPathnameFromHeaders(headers: { get(name: string): string | null }): string | null {\n return headers.get(ELLMO_PATHNAME_HEADER);\n}\n\nexport default ellmoMiddleware;\n"],"names":[],"mappings":";;AA8CA;;;;;;;;;;;;AAYG;AACG,MAAA,QAAQ,GAAG,OAAO,EACtB,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,KAAK,EAClB,QAAQ,EACM,KAAwC;IACtD,IAAI,IAAI,GAAQ,IAAI,CAAC;IACrB,IAAI,KAAK,GAAiB,IAAI,CAAC;AAE/B,IAAA,IAAI,cAAc,GAAG,IAAI,KAAK,YAAY,GAAG,YAAY,GAAG,UAAU,CAAC;AAEvE,IAAA,IAAI;;QAEF,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;SAC3F;QAED,IAAI,CAAC,GAAG,EAAE;AACR,YAAA,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;SAC5E;;AAGD,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;;QAG3C,MAAM,MAAM,GAAG,CAAkD,+CAAA,EAAA,QAAQ,MAAM,cAAc,CAAA,GAAA,EAAM,UAAU,CAAA,CAAE,CAAC;;AAGhH,Q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;;;;;;;;;;;;;AAyCG;AACa,SAAA,eAAe,CAI7B,OAAY,EACZ,QAAa,EAAA;;AAGb,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;;IAG1C,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;AAEtD,IAAA,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;AAeG;AACG,SAAU,sBAAsB,CAAC,OAA6C,EAAA;AAClF,IAAA,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAC5C;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/EllmoApi.tsx","../src/EllmoApiSSR.tsx","../src/shared.ts","../src/EllmoApiStatic.tsx","../src/middleware.ts"],"sourcesContent":["import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiProps {\n /**\n * The URL path to fetch data for (required).\n * \n * With middleware (recommended):\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * const pathname = getPathnameFromHeaders(headers());\n * <EllmoApi clientId=\"...\" url={pathname || '/'} />\n * ```\n * \n * Without middleware:\n * ```tsx\n * <EllmoApi clientId=\"...\" url=\"/about\" />\n * ```\n */\n url: string;\n /**\n * The API key/client identifier (required)\n */\n clientId: string;\n /**\n * Type of data to fetch\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children to render when data is available\n */\n children?: (data: any, error: Error | null) => React.ReactNode;\n}\n\n/**\n * Server-only Ellmo API component (React Server Component)\n * This component fetches data during server rendering.\n * It requires Next.js 13+ App Router or other RSC-compatible frameworks.\n * \n * @example\n * ```tsx\n * // In a server component (app/page.tsx)\n * export default async function Page() {\n * return <EllmoApi clientId=\"your-id\" url=\"/about\" />;\n * }\n * ```\n */\nconst EllmoApi = async ({\n url,\n clientId,\n type,\n className = '',\n showErrors = false,\n children\n}: EllmoApiProps): Promise<React.ReactElement | null> => {\n let data: any = null;\n let error: Error | null = null;\n\n let translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url prop is required. Please provide the page pathname.');\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data during server render\n const response = await fetch(apiUrl, {\n cache: 'no-store', // Always fetch fresh data\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n if (type === 'structured') {\n data = await response.text();\n } else if (type === 'semantic') {\n data = await response.text();\n } else {\n throw new Error(`Invalid type: ${type}`);\n }\n } catch (err) {\n error = err instanceof Error ? err : new Error('Unknown error occurred');\n }\n\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error.message}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{JSON.stringify(data, null, 2)}</pre>\n </div>\n );\n }\n\n // Invisible component by default - just fetches data during server render\n if (type === 'structured' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n } else if (type === 'semantic' && data) {\n return <div dangerouslySetInnerHTML={{ __html: data }} />;\n }\n return null;\n};\n\nexport default EllmoApi;\n","import React from 'react';\nimport type { EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\nexport interface EllmoApiSSRProps {\n /**\n * The pre-fetched data from the Ellmo API\n */\n data?: string | null;\n /**\n * Error from fetching data\n */\n error?: string | null;\n /**\n * Type of data to render\n */\n type?: EllmoApiType;\n /**\n * Custom className for styling\n */\n className?: string;\n /**\n * Whether to show errors\n */\n showErrors?: boolean;\n /**\n * Children render prop with data and error\n */\n children?: (data: string | null, error: string | null) => React.ReactNode;\n}\n\n/**\n * Ellmo API component for traditional SSR environments (Next.js Pages Router)\n * This component receives pre-fetched data and renders it.\n * Data fetching should be done in getServerSideProps or getStaticProps.\n * \n * @example\n * ```tsx\n * // In your page file (pages/about.tsx)\n * import { EllmoApiSSR, fetchEllmoData } from 'ellmo-ai-react';\n * \n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: 'your-client-id',\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * export default function AboutPage({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <h1>About Page</h1>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * </div>\n * );\n * }\n * ```\n */\nconst EllmoApiSSR: React.FC<EllmoApiSSRProps> = ({\n data = null,\n error = null,\n className = '',\n showErrors = false,\n children\n}) => {\n // If children prop is provided, use render prop pattern\n if (children) {\n return <>{children(data, error)}</>;\n }\n\n // Show errors if enabled\n if (error && showErrors) {\n return (\n <div className={`ellmo-api-error ${className}`}>\n <div>Error: {error}</div>\n </div>\n );\n }\n\n // Show data if showErrors is enabled (for debugging)\n if (data && showErrors) {\n return (\n <div className={`ellmo-api-data ${className}`}>\n <pre>{data}</pre>\n </div>\n );\n }\n\n // Render HTML content if available\n if (data && !error) {\n return <div className={className} dangerouslySetInnerHTML={{ __html: data }} />;\n }\n\n // Return null if no data\n return null;\n};\n\nexport default EllmoApiSSR;\n \n","export type EllmoApiType = 'semantic' | 'structured';\n\n/**\n * Fetch data from Ellmo API\n * Use this in getServerSideProps, getStaticProps, or getInitialProps\n * \n * @example\n * ```tsx\n * // In getServerSideProps (Next.js Pages Router)\n * export async function getServerSideProps(context) {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: context.resolvedUrl,\n * type: 'semantic'\n * });\n * \n * return {\n * props: { ellmoData: data, ellmoError: error }\n * };\n * }\n * \n * // In getInitialProps (older Next.js API)\n * MyPage.getInitialProps = async (ctx) => {\n * const { data, error } = await fetchEllmoData({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: ctx.asPath || '/',\n * type: 'semantic'\n * });\n * \n * return { ellmoData: data, ellmoError: error };\n * };\n * ```\n */\nexport async function fetchEllmoData({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n}): Promise<{ data: string | null; error: string | null }> {\n try {\n // Validate required props\n if (!clientId) {\n throw new Error('clientId is required. Please provide your Ellmo API client identifier.');\n }\n\n if (!url) {\n throw new Error('url is required. Please provide the page pathname.');\n }\n\n if (url.includes('.')) {\n // Sometimes urls contain a dot if they're images or other assets which are served by SSG (static generation)\n return { data: null, error: null };\n }\n\n // Encode the URL path for the API call\n const encodedUrl = encodeURIComponent(url);\n const translatedType = type === 'structured' ? 'structured' : 'semantic';\n\n // Build the API URL\n const apiUrl = `https://www.tryellmo.ai/public-api/wordpress?c=${clientId}&t=${translatedType}&u=${encodedUrl}`;\n\n // Fetch data\n const response = await fetch(apiUrl, {\n cache: 'no-store',\n });\n\n if (!response.ok) {\n throw new Error(`API request failed with status ${response.status}`);\n }\n\n const data = await response.text();\n return { data, error: null };\n } catch (err) {\n const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';\n return { data: null, error: errorMessage };\n }\n}\n\n","import { fetchEllmoData, type EllmoApiType } from './shared';\n\nexport type { EllmoApiType };\n\n// Type for Next.js App context\ntype AppContext = {\n Component: any;\n ctx: any;\n router: any;\n};\n\n\n/**\n * Helper for _app.tsx to fetch global Ellmo data and merge with page props\n * Automatically calls the page's getInitialProps and merges everything\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps, globalEllmoData, globalEllmoError }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR data={globalEllmoData} error={globalEllmoError} />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: '/global-header',\n * type: 'structured'\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic'\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n}) {\n return async (appContext: AppContext) => {\n // Fetch global Ellmo data\n const { data, error } = await fetchEllmoData({\n clientId,\n url: url(appContext), // Use the function to get the URL\n type\n });\n\n // Call the page's getInitialProps if it exists\n let pageProps = {};\n if (appContext.Component.getInitialProps) {\n pageProps = await appContext.Component.getInitialProps(appContext.ctx);\n }\n\n // Return merged props\n return {\n pageProps,\n globalEllmoData: data,\n globalEllmoError: error\n };\n };\n}\n","/**\n * Custom header name for Ellmo AI to pass pathname information\n * Using 'x-ellmo-pathname' to avoid conflicts with other libraries\n */\nexport const ELLMO_PATHNAME_HEADER = 'x-ellmo-pathname';\n\n/**\n * Type definitions for Next.js middleware (to avoid requiring Next.js as a dependency)\n */\nexport interface EllmoRequest {\n nextUrl: {\n pathname: string;\n };\n}\n\nexport interface EllmoResponse {\n headers: {\n set(name: string, value: string): void;\n };\n}\n\n/**\n * Ellmo AI middleware helper for Next.js\n * \n * This is a vanilla helper that adds pathname to request headers.\n * It doesn't depend on Next.js - you provide the request/response objects.\n * \n * Usage in Next.js:\n * \n * ```ts\n * // middleware.ts\n * import { ellmoMiddleware } from 'ellmo-ai-react/middleware';\n * import { NextResponse } from 'next/server';\n * import type { NextRequest } from 'next/server';\n * \n * export function middleware(request: NextRequest) {\n * const response = NextResponse.next();\n * return ellmoMiddleware(request, response);\n * }\n * \n * export const config = {\n * matcher: [\n * '/((?!_next/static|_next/image|favicon.ico).*)',\n * ],\n * };\n * ```\n * \n * Composing with existing middleware:\n * \n * ```ts\n * export function middleware(request: NextRequest) {\n * let response = NextResponse.next();\n * \n * // Your logic here\n * if (someCondition) {\n * response = NextResponse.redirect(new URL('/login', request.url));\n * }\n * \n * // Apply Ellmo middleware\n * return ellmoMiddleware(request, response);\n * }\n * ```\n */\nexport function ellmoMiddleware<\n Req extends EllmoRequest,\n Res extends EllmoResponse\n>(\n request: Req,\n response: Res\n): Res {\n // Extract pathname from the request URL\n const pathname = request.nextUrl.pathname;\n \n // Add the pathname to a custom header\n response.headers.set(ELLMO_PATHNAME_HEADER, pathname);\n \n return response;\n}\n\n/**\n * Helper to extract pathname from headers object\n * \n * Usage in Next.js Server Components:\n * ```tsx\n * import { headers } from 'next/headers';\n * import { getPathnameFromHeaders } from 'ellmo-ai-react/middleware';\n * \n * export default function Page() {\n * const headersList = headers();\n * const pathname = getPathnameFromHeaders(headersList);\n * \n * return <EllmoApi clientId=\"your-id\" url={pathname} />;\n * }\n * ```\n */\nexport function getPathnameFromHeaders(headers: { get(name: string): string | null }): string | null {\n return headers.get(ELLMO_PATHNAME_HEADER);\n}\n\nexport default ellmoMiddleware;\n"],"names":[],"mappings":";;AA8CA;;;;;;;;;;;;AAYG;AACG,MAAA,QAAQ,GAAG,OAAO,EACtB,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,KAAK,EAClB,QAAQ,EACM,KAAwC;IACtD,IAAI,IAAI,GAAQ,IAAI,CAAC;IACrB,IAAI,KAAK,GAAiB,IAAI,CAAC;AAE/B,IAAA,IAAI,cAAc,GAAG,IAAI,KAAK,YAAY,GAAG,YAAY,GAAG,UAAU,CAAC;AAEvE,IAAA,IAAI;;QAEF,IAAI,CAAC,QAAQ,EAAE;AACb,YAAA,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;SAC3F;QAED,IAAI,CAAC,GA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MAAM,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACxE;;QAGD,OAAO;YACL,SAAS;AACT,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,gBAAgB,EAAE,KAAK;SACxB,CAAC;AACJ,KAAC,CAAC;AACJ;;ACtEA;;;AAGG;AACI,MAAM,qBAAqB,GAAG,mBAAmB;AAiBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCG;AACa,SAAA,eAAe,CAI7B,OAAY,EACZ,QAAa,EAAA;;AAGb,IAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;;IAG1C,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC;AAEtD,IAAA,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;AAeG;AACG,SAAU,sBAAsB,CAAC,OAA6C,EAAA;AAClF,IAAA,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAC5C;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ellmo-ai-react",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "website": "https://www.tryellmo.ai?utm_source=npm&utm_medium=package&utm_campaign=ellmo-ai-react",
5
5
  "description": "React component for integration with Ellmo AI Platform",
6
6
  "main": "dist/index.js",