ellmo-ai-react 0.0.17 → 0.0.22
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/EllmoApiStatic.d.ts +89 -0
- package/dist/EllmoApiStatic.d.ts.map +1 -1
- package/dist/index.d.ts +90 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/EllmoApiStatic.d.ts
CHANGED
|
@@ -5,6 +5,14 @@ type AppContext = {
|
|
|
5
5
|
ctx: any;
|
|
6
6
|
router: any;
|
|
7
7
|
};
|
|
8
|
+
type GetStaticPropsContext = {
|
|
9
|
+
params?: Record<string, string | string[]>;
|
|
10
|
+
preview?: boolean;
|
|
11
|
+
previewData?: any;
|
|
12
|
+
locale?: string;
|
|
13
|
+
locales?: string[];
|
|
14
|
+
defaultLocale?: string;
|
|
15
|
+
};
|
|
8
16
|
/**
|
|
9
17
|
* Helper for _app.tsx to fetch global Ellmo data and merge with page props
|
|
10
18
|
* Automatically calls the page's getInitialProps and merges everything
|
|
@@ -56,4 +64,85 @@ export declare function withEllmoApp({ clientId, url, type, debugging }: {
|
|
|
56
64
|
pageEllmoData: string | null;
|
|
57
65
|
};
|
|
58
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Higher-order function to wrap getStaticProps with Ellmo data fetching
|
|
69
|
+
* Automatically calls the page's existing getStaticProps and merges Ellmo data
|
|
70
|
+
*
|
|
71
|
+
* @param clientId - Your Ellmo client ID
|
|
72
|
+
* @param url - Function that returns the URL path from GetStaticPropsContext
|
|
73
|
+
* @param type - Content type: 'semantic' or 'structured' (default: 'semantic')
|
|
74
|
+
* @param debugging - Include ellmoError in props for debugging (default: false)
|
|
75
|
+
*
|
|
76
|
+
* Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* import { withEllmoStatic } from 'ellmo-ai-react';
|
|
81
|
+
*
|
|
82
|
+
* export const getStaticProps = withEllmoStatic({
|
|
83
|
+
* clientId: process.env.ELLMO_CLIENT_ID!,
|
|
84
|
+
* url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',
|
|
85
|
+
* type: 'semantic',
|
|
86
|
+
* debugging: process.env.NODE_ENV === 'development'
|
|
87
|
+
* });
|
|
88
|
+
*
|
|
89
|
+
* // In page component - access directly
|
|
90
|
+
* export default function BlogPost({ ellmoData, ellmoError }) {
|
|
91
|
+
* return (
|
|
92
|
+
* <div>
|
|
93
|
+
* <EllmoApiSSR data={ellmoData} error={ellmoError} />
|
|
94
|
+
* <h1>Blog Post</h1>
|
|
95
|
+
* </div>
|
|
96
|
+
* );
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* // In _app.tsx - access via pageProps
|
|
100
|
+
* function MyApp({ Component, pageProps }) {
|
|
101
|
+
* return (
|
|
102
|
+
* <div>
|
|
103
|
+
* <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />
|
|
104
|
+
* <Component {...pageProps} />
|
|
105
|
+
* </div>
|
|
106
|
+
* );
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function withEllmoStatic<P extends Record<string, any> = Record<string, any>>({ clientId, url, type, debugging }: {
|
|
111
|
+
clientId: string;
|
|
112
|
+
url: (context: GetStaticPropsContext) => string;
|
|
113
|
+
type?: EllmoApiType;
|
|
114
|
+
debugging?: boolean;
|
|
115
|
+
}): (context: GetStaticPropsContext) => Promise<{
|
|
116
|
+
props: P & {
|
|
117
|
+
ellmoData: string | null;
|
|
118
|
+
ellmoError?: string | null;
|
|
119
|
+
pageProps?: {
|
|
120
|
+
pageEllmoData: string | null;
|
|
121
|
+
pageEllmoError?: string | null;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}>;
|
|
125
|
+
/**
|
|
126
|
+
* Build standardized Ellmo props synchronously from provided data and error.
|
|
127
|
+
* Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Fetch Ellmo data and return standardized props (no Next.js dependency).
|
|
131
|
+
* Accepts a plain URL string and returns the same shape as buildEllmoProps.
|
|
132
|
+
*/
|
|
133
|
+
export declare function getEllmoStaticProps({ clientId, url, type, debugging }: {
|
|
134
|
+
clientId: string;
|
|
135
|
+
url: string;
|
|
136
|
+
type?: EllmoApiType;
|
|
137
|
+
debugging?: boolean;
|
|
138
|
+
}): Promise<{
|
|
139
|
+
props: {
|
|
140
|
+
ellmoData: string | null;
|
|
141
|
+
ellmoError?: string | null;
|
|
142
|
+
pageProps: {
|
|
143
|
+
pageEllmoData: string | null;
|
|
144
|
+
pageEllmoError?: string | null;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
}>;
|
|
59
148
|
//# sourceMappingURL=EllmoApiStatic.d.ts.map
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,GAAG,EACH,IAAiB,EACjB,SAAiB,EAClB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC;IACx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EAAE,GAAG,CAAC,EAAE,EACnF,QAAQ,EACR,GAAG,EACH,IAAiB,EACjB,SAAiB,EAClB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,MAAM,CAAC;IAChD,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,IACe,SAAS,qBAAqB;WAMnB,CAAC,GAAG;QAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,SAAS,CAAC,EAAE;YAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE;GAEpK;AAED;;;GAGG;AAGH;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,QAAQ,EACR,GAAG,EACH,IAAiB,EACjB,SAAiB,EAClB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,SAAS,EAAE;YAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAAC,CAe5J"}
|
package/dist/index.d.ts
CHANGED
|
@@ -161,6 +161,14 @@ type AppContext = {
|
|
|
161
161
|
ctx: any;
|
|
162
162
|
router: any;
|
|
163
163
|
};
|
|
164
|
+
type GetStaticPropsContext = {
|
|
165
|
+
params?: Record<string, string | string[]>;
|
|
166
|
+
preview?: boolean;
|
|
167
|
+
previewData?: any;
|
|
168
|
+
locale?: string;
|
|
169
|
+
locales?: string[];
|
|
170
|
+
defaultLocale?: string;
|
|
171
|
+
};
|
|
164
172
|
/**
|
|
165
173
|
* Helper for _app.tsx to fetch global Ellmo data and merge with page props
|
|
166
174
|
* Automatically calls the page's getInitialProps and merges everything
|
|
@@ -212,6 +220,87 @@ declare function withEllmoApp({ clientId, url, type, debugging }: {
|
|
|
212
220
|
pageEllmoData: string | null;
|
|
213
221
|
};
|
|
214
222
|
}>;
|
|
223
|
+
/**
|
|
224
|
+
* Higher-order function to wrap getStaticProps with Ellmo data fetching
|
|
225
|
+
* Automatically calls the page's existing getStaticProps and merges Ellmo data
|
|
226
|
+
*
|
|
227
|
+
* @param clientId - Your Ellmo client ID
|
|
228
|
+
* @param url - Function that returns the URL path from GetStaticPropsContext
|
|
229
|
+
* @param type - Content type: 'semantic' or 'structured' (default: 'semantic')
|
|
230
|
+
* @param debugging - Include ellmoError in props for debugging (default: false)
|
|
231
|
+
*
|
|
232
|
+
* Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```tsx
|
|
236
|
+
* import { withEllmoStatic } from 'ellmo-ai-react';
|
|
237
|
+
*
|
|
238
|
+
* export const getStaticProps = withEllmoStatic({
|
|
239
|
+
* clientId: process.env.ELLMO_CLIENT_ID!,
|
|
240
|
+
* url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',
|
|
241
|
+
* type: 'semantic',
|
|
242
|
+
* debugging: process.env.NODE_ENV === 'development'
|
|
243
|
+
* });
|
|
244
|
+
*
|
|
245
|
+
* // In page component - access directly
|
|
246
|
+
* export default function BlogPost({ ellmoData, ellmoError }) {
|
|
247
|
+
* return (
|
|
248
|
+
* <div>
|
|
249
|
+
* <EllmoApiSSR data={ellmoData} error={ellmoError} />
|
|
250
|
+
* <h1>Blog Post</h1>
|
|
251
|
+
* </div>
|
|
252
|
+
* );
|
|
253
|
+
* }
|
|
254
|
+
*
|
|
255
|
+
* // In _app.tsx - access via pageProps
|
|
256
|
+
* function MyApp({ Component, pageProps }) {
|
|
257
|
+
* return (
|
|
258
|
+
* <div>
|
|
259
|
+
* <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />
|
|
260
|
+
* <Component {...pageProps} />
|
|
261
|
+
* </div>
|
|
262
|
+
* );
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
declare function withEllmoStatic<P extends Record<string, any> = Record<string, any>>({ clientId, url, type, debugging }: {
|
|
267
|
+
clientId: string;
|
|
268
|
+
url: (context: GetStaticPropsContext) => string;
|
|
269
|
+
type?: EllmoApiType;
|
|
270
|
+
debugging?: boolean;
|
|
271
|
+
}): (context: GetStaticPropsContext) => Promise<{
|
|
272
|
+
props: P & {
|
|
273
|
+
ellmoData: string | null;
|
|
274
|
+
ellmoError?: string | null;
|
|
275
|
+
pageProps?: {
|
|
276
|
+
pageEllmoData: string | null;
|
|
277
|
+
pageEllmoError?: string | null;
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Build standardized Ellmo props synchronously from provided data and error.
|
|
283
|
+
* Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.
|
|
284
|
+
*/
|
|
285
|
+
/**
|
|
286
|
+
* Fetch Ellmo data and return standardized props (no Next.js dependency).
|
|
287
|
+
* Accepts a plain URL string and returns the same shape as buildEllmoProps.
|
|
288
|
+
*/
|
|
289
|
+
declare function getEllmoStaticProps({ clientId, url, type, debugging }: {
|
|
290
|
+
clientId: string;
|
|
291
|
+
url: string;
|
|
292
|
+
type?: EllmoApiType;
|
|
293
|
+
debugging?: boolean;
|
|
294
|
+
}): Promise<{
|
|
295
|
+
props: {
|
|
296
|
+
ellmoData: string | null;
|
|
297
|
+
ellmoError?: string | null;
|
|
298
|
+
pageProps: {
|
|
299
|
+
pageEllmoData: string | null;
|
|
300
|
+
pageEllmoError?: string | null;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
}>;
|
|
215
304
|
|
|
216
305
|
/**
|
|
217
306
|
* Custom header name for Ellmo AI to pass pathname information
|
|
@@ -294,4 +383,4 @@ declare function getPathnameFromHeaders(headers: {
|
|
|
294
383
|
get(name: string): string | null;
|
|
295
384
|
}): string | null;
|
|
296
385
|
|
|
297
|
-
export { ELLMO_PATHNAME_HEADER, EllmoApi, EllmoApiProps, EllmoApiSSR, EllmoApiSSRProps, EllmoApiType, EllmoRequest, EllmoResponse, ellmoMiddleware, fetchEllmoData, getPathnameFromHeaders, ellmoMiddleware as middleware, withEllmoApp };
|
|
386
|
+
export { ELLMO_PATHNAME_HEADER, EllmoApi, EllmoApiProps, EllmoApiSSR, EllmoApiSSRProps, EllmoApiType, EllmoRequest, EllmoResponse, ellmoMiddleware, fetchEllmoData, getEllmoStaticProps, getPathnameFromHeaders, ellmoMiddleware as middleware, withEllmoApp, withEllmoStatic };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,YAAY,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGtF,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -262,6 +262,82 @@ function withEllmoApp({ clientId, url, type = 'semantic', debugging = false }) {
|
|
|
262
262
|
};
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Higher-order function to wrap getStaticProps with Ellmo data fetching
|
|
267
|
+
* Automatically calls the page's existing getStaticProps and merges Ellmo data
|
|
268
|
+
*
|
|
269
|
+
* @param clientId - Your Ellmo client ID
|
|
270
|
+
* @param url - Function that returns the URL path from GetStaticPropsContext
|
|
271
|
+
* @param type - Content type: 'semantic' or 'structured' (default: 'semantic')
|
|
272
|
+
* @param debugging - Include ellmoError in props for debugging (default: false)
|
|
273
|
+
*
|
|
274
|
+
* Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```tsx
|
|
278
|
+
* import { withEllmoStatic } from 'ellmo-ai-react';
|
|
279
|
+
*
|
|
280
|
+
* export const getStaticProps = withEllmoStatic({
|
|
281
|
+
* clientId: process.env.ELLMO_CLIENT_ID!,
|
|
282
|
+
* url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',
|
|
283
|
+
* type: 'semantic',
|
|
284
|
+
* debugging: process.env.NODE_ENV === 'development'
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* // In page component - access directly
|
|
288
|
+
* export default function BlogPost({ ellmoData, ellmoError }) {
|
|
289
|
+
* return (
|
|
290
|
+
* <div>
|
|
291
|
+
* <EllmoApiSSR data={ellmoData} error={ellmoError} />
|
|
292
|
+
* <h1>Blog Post</h1>
|
|
293
|
+
* </div>
|
|
294
|
+
* );
|
|
295
|
+
* }
|
|
296
|
+
*
|
|
297
|
+
* // In _app.tsx - access via pageProps
|
|
298
|
+
* function MyApp({ Component, pageProps }) {
|
|
299
|
+
* return (
|
|
300
|
+
* <div>
|
|
301
|
+
* <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />
|
|
302
|
+
* <Component {...pageProps} />
|
|
303
|
+
* </div>
|
|
304
|
+
* );
|
|
305
|
+
* }
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
function withEllmoStatic({ clientId, url, type = 'semantic', debugging = false }) {
|
|
309
|
+
return async (context) => {
|
|
310
|
+
return getEllmoStaticProps({
|
|
311
|
+
clientId,
|
|
312
|
+
url: url(context),
|
|
313
|
+
type,
|
|
314
|
+
debugging
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Build standardized Ellmo props synchronously from provided data and error.
|
|
320
|
+
* Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.
|
|
321
|
+
*/
|
|
322
|
+
// (removed buildEllmoProps to reduce surface area)
|
|
323
|
+
/**
|
|
324
|
+
* Fetch Ellmo data and return standardized props (no Next.js dependency).
|
|
325
|
+
* Accepts a plain URL string and returns the same shape as buildEllmoProps.
|
|
326
|
+
*/
|
|
327
|
+
async function getEllmoStaticProps({ clientId, url, type = 'semantic', debugging = false }) {
|
|
328
|
+
const { data, error } = await fetchEllmoData({ clientId, url, type });
|
|
329
|
+
const props = {
|
|
330
|
+
ellmoData: data,
|
|
331
|
+
pageProps: {
|
|
332
|
+
pageEllmoData: data
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
if (debugging) {
|
|
336
|
+
props.ellmoError = error;
|
|
337
|
+
props.pageProps.pageEllmoError = error;
|
|
338
|
+
}
|
|
339
|
+
return { props };
|
|
340
|
+
}
|
|
265
341
|
|
|
266
342
|
/**
|
|
267
343
|
* Custom header name for Ellmo AI to pass pathname information
|
|
@@ -342,7 +418,9 @@ exports.EllmoApi = EllmoApi;
|
|
|
342
418
|
exports.EllmoApiSSR = EllmoApiSSR;
|
|
343
419
|
exports.ellmoMiddleware = ellmoMiddleware;
|
|
344
420
|
exports.fetchEllmoData = fetchEllmoData;
|
|
421
|
+
exports.getEllmoStaticProps = getEllmoStaticProps;
|
|
345
422
|
exports.getPathnameFromHeaders = getPathnameFromHeaders;
|
|
346
423
|
exports.middleware = ellmoMiddleware;
|
|
347
424
|
exports.withEllmoApp = withEllmoApp;
|
|
425
|
+
exports.withEllmoStatic = withEllmoStatic;
|
|
348
426
|
//# sourceMappingURL=index.js.map
|
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 * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from app context\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include pageEllmoError in props for debugging (default: false)\n * \n * Returns pageEllmoData in pageProps. If debugging is enabled, also includes pageEllmoError.\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR \n * data={pageProps.pageEllmoData} \n * error={pageProps.pageEllmoError} \n * showErrors={true} // Show errors in development\n * />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: (appContext) => '/global-header',\n * type: 'structured',\n * debugging: process.env.NODE_ENV === 'development' // Enable error prop in development\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\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 with ellmo data inside pageProps\n return {\n pageProps: {\n ...pageProps,\n pageEllmoData: data,\n ...(debugging ? { pageEllmoError: error } : {}), // Only add error if debugging is enabled\n }\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,QAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YACnC,KAAK,EAAE,UAAU;AAClB,SAAA,CAAC,CAAC;AAEH,QAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,CAAA,+BAAA,EAAkC,QAAQ,CAAC,MAAM,CAA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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// Type for Next.js GetStaticProps context (minimal definition to avoid next.js dependency)\ntype GetStaticPropsContext = {\n params?: Record<string, string | string[]>;\n preview?: boolean;\n previewData?: any;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\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 * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from app context\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include pageEllmoError in props for debugging (default: false)\n * \n * Returns pageEllmoData in pageProps. If debugging is enabled, also includes pageEllmoError.\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR \n * data={pageProps.pageEllmoData} \n * error={pageProps.pageEllmoError} \n * showErrors={true} // Show errors in development\n * />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: (appContext) => '/global-header',\n * type: 'structured',\n * debugging: process.env.NODE_ENV === 'development' // Enable error prop in development\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\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 with ellmo data inside pageProps\n return {\n pageProps: {\n ...pageProps,\n pageEllmoData: data,\n ...(debugging ? { pageEllmoError: error } : {}), // Only add error if debugging is enabled\n }\n };\n };\n}\n\n/**\n * Higher-order function to wrap getStaticProps with Ellmo data fetching\n * Automatically calls the page's existing getStaticProps and merges Ellmo data\n *\n * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from GetStaticPropsContext\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include ellmoError in props for debugging (default: false)\n *\n * Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.\n *\n * @example\n * ```tsx\n * import { withEllmoStatic } from 'ellmo-ai-react';\n *\n * export const getStaticProps = withEllmoStatic({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',\n * type: 'semantic',\n * debugging: process.env.NODE_ENV === 'development'\n * });\n *\n * // In page component - access directly\n * export default function BlogPost({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * <h1>Blog Post</h1>\n * </div>\n * );\n * }\n *\n * // In _app.tsx - access via pageProps\n * function MyApp({ Component, pageProps }) {\n * return (\n * <div>\n * <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />\n * <Component {...pageProps} />\n * </div>\n * );\n * }\n * ```\n */\nexport function withEllmoStatic<P extends Record<string, any> = Record<string, any>>({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (context: GetStaticPropsContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\n}) {\n return async (context: GetStaticPropsContext) => {\n return getEllmoStaticProps({\n clientId,\n url: url(context),\n type,\n debugging\n }) as Promise<{ props: P & { ellmoData: string | null; ellmoError?: string | null; pageProps?: { pageEllmoData: string | null; pageEllmoError?: string | null } } }>;\n };\n}\n\n/**\n * Build standardized Ellmo props synchronously from provided data and error.\n * Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.\n */\n// (removed buildEllmoProps to reduce surface area)\n\n/**\n * Fetch Ellmo data and return standardized props (no Next.js dependency).\n * Accepts a plain URL string and returns the same shape as buildEllmoProps.\n */\nexport async function getEllmoStaticProps({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n debugging?: boolean;\n}): Promise<{ props: { ellmoData: string | null; ellmoError?: string | null; pageProps: { pageEllmoData: string | null; pageEllmoError?: string | null } } }> {\n const { data, error } = await fetchEllmoData({ clientId, url, type });\n const props: { ellmoData: string | null; ellmoError?: string | null; pageProps: { pageEllmoData: string | null; pageEllmoError?: string | null } } = {\n ellmoData: data,\n pageProps: {\n pageEllmoData: data\n }\n };\n\n if (debugging) {\n props.ellmoError = error;\n props.pageProps.pageEllmoError = error;\n }\n\n return { props };\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,QAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YACnC,KAAK,EAAE,UAAU;AAClB,SAAA,CAAC,CAAC;AAE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E,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/dist/index.mjs
CHANGED
|
@@ -260,6 +260,82 @@ function withEllmoApp({ clientId, url, type = 'semantic', debugging = false }) {
|
|
|
260
260
|
};
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Higher-order function to wrap getStaticProps with Ellmo data fetching
|
|
265
|
+
* Automatically calls the page's existing getStaticProps and merges Ellmo data
|
|
266
|
+
*
|
|
267
|
+
* @param clientId - Your Ellmo client ID
|
|
268
|
+
* @param url - Function that returns the URL path from GetStaticPropsContext
|
|
269
|
+
* @param type - Content type: 'semantic' or 'structured' (default: 'semantic')
|
|
270
|
+
* @param debugging - Include ellmoError in props for debugging (default: false)
|
|
271
|
+
*
|
|
272
|
+
* Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```tsx
|
|
276
|
+
* import { withEllmoStatic } from 'ellmo-ai-react';
|
|
277
|
+
*
|
|
278
|
+
* export const getStaticProps = withEllmoStatic({
|
|
279
|
+
* clientId: process.env.ELLMO_CLIENT_ID!,
|
|
280
|
+
* url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',
|
|
281
|
+
* type: 'semantic',
|
|
282
|
+
* debugging: process.env.NODE_ENV === 'development'
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // In page component - access directly
|
|
286
|
+
* export default function BlogPost({ ellmoData, ellmoError }) {
|
|
287
|
+
* return (
|
|
288
|
+
* <div>
|
|
289
|
+
* <EllmoApiSSR data={ellmoData} error={ellmoError} />
|
|
290
|
+
* <h1>Blog Post</h1>
|
|
291
|
+
* </div>
|
|
292
|
+
* );
|
|
293
|
+
* }
|
|
294
|
+
*
|
|
295
|
+
* // In _app.tsx - access via pageProps
|
|
296
|
+
* function MyApp({ Component, pageProps }) {
|
|
297
|
+
* return (
|
|
298
|
+
* <div>
|
|
299
|
+
* <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />
|
|
300
|
+
* <Component {...pageProps} />
|
|
301
|
+
* </div>
|
|
302
|
+
* );
|
|
303
|
+
* }
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
function withEllmoStatic({ clientId, url, type = 'semantic', debugging = false }) {
|
|
307
|
+
return async (context) => {
|
|
308
|
+
return getEllmoStaticProps({
|
|
309
|
+
clientId,
|
|
310
|
+
url: url(context),
|
|
311
|
+
type,
|
|
312
|
+
debugging
|
|
313
|
+
});
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Build standardized Ellmo props synchronously from provided data and error.
|
|
318
|
+
* Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.
|
|
319
|
+
*/
|
|
320
|
+
// (removed buildEllmoProps to reduce surface area)
|
|
321
|
+
/**
|
|
322
|
+
* Fetch Ellmo data and return standardized props (no Next.js dependency).
|
|
323
|
+
* Accepts a plain URL string and returns the same shape as buildEllmoProps.
|
|
324
|
+
*/
|
|
325
|
+
async function getEllmoStaticProps({ clientId, url, type = 'semantic', debugging = false }) {
|
|
326
|
+
const { data, error } = await fetchEllmoData({ clientId, url, type });
|
|
327
|
+
const props = {
|
|
328
|
+
ellmoData: data,
|
|
329
|
+
pageProps: {
|
|
330
|
+
pageEllmoData: data
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
if (debugging) {
|
|
334
|
+
props.ellmoError = error;
|
|
335
|
+
props.pageProps.pageEllmoError = error;
|
|
336
|
+
}
|
|
337
|
+
return { props };
|
|
338
|
+
}
|
|
263
339
|
|
|
264
340
|
/**
|
|
265
341
|
* Custom header name for Ellmo AI to pass pathname information
|
|
@@ -335,5 +411,5 @@ function getPathnameFromHeaders(headers) {
|
|
|
335
411
|
return headers.get(ELLMO_PATHNAME_HEADER);
|
|
336
412
|
}
|
|
337
413
|
|
|
338
|
-
export { ELLMO_PATHNAME_HEADER, EllmoApi, EllmoApiSSR, ellmoMiddleware, fetchEllmoData, getPathnameFromHeaders, ellmoMiddleware as middleware, withEllmoApp };
|
|
414
|
+
export { ELLMO_PATHNAME_HEADER, EllmoApi, EllmoApiSSR, ellmoMiddleware, fetchEllmoData, getEllmoStaticProps, getPathnameFromHeaders, ellmoMiddleware as middleware, withEllmoApp, withEllmoStatic };
|
|
339
415
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from app context\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include pageEllmoError in props for debugging (default: false)\n * \n * Returns pageEllmoData in pageProps. If debugging is enabled, also includes pageEllmoError.\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR \n * data={pageProps.pageEllmoData} \n * error={pageProps.pageEllmoError} \n * showErrors={true} // Show errors in development\n * />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: (appContext) => '/global-header',\n * type: 'structured',\n * debugging: process.env.NODE_ENV === 'development' // Enable error prop in development\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\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 with ellmo data inside pageProps\n return {\n pageProps: {\n ...pageProps,\n pageEllmoData: data,\n ...(debugging ? { pageEllmoError: error } : {}), // Only add error if debugging is enabled\n }\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,QAA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C5C;;;;"}
|
|
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// Type for Next.js GetStaticProps context (minimal definition to avoid next.js dependency)\ntype GetStaticPropsContext = {\n params?: Record<string, string | string[]>;\n preview?: boolean;\n previewData?: any;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\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 * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from app context\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include pageEllmoError in props for debugging (default: false)\n * \n * Returns pageEllmoData in pageProps. If debugging is enabled, also includes pageEllmoError.\n * \n * @example\n * ```tsx\n * import { withEllmoApp } from 'ellmo-ai-react';\n * \n * function MyApp({ Component, pageProps }) {\n * return (\n * <>\n * <header>\n * <EllmoApiSSR \n * data={pageProps.pageEllmoData} \n * error={pageProps.pageEllmoError} \n * showErrors={true} // Show errors in development\n * />\n * </header>\n * <Component {...pageProps} />\n * </>\n * );\n * }\n * \n * MyApp.getInitialProps = withEllmoApp({\n * clientId: process.env.NEXT_PUBLIC_ELLMO_CLIENT_ID!,\n * url: (appContext) => '/global-header',\n * type: 'structured',\n * debugging: process.env.NODE_ENV === 'development' // Enable error prop in development\n * });\n * \n * export default MyApp;\n * ```\n */\nexport function withEllmoApp({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (appContext: AppContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\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 with ellmo data inside pageProps\n return {\n pageProps: {\n ...pageProps,\n pageEllmoData: data,\n ...(debugging ? { pageEllmoError: error } : {}), // Only add error if debugging is enabled\n }\n };\n };\n}\n\n/**\n * Higher-order function to wrap getStaticProps with Ellmo data fetching\n * Automatically calls the page's existing getStaticProps and merges Ellmo data\n *\n * @param clientId - Your Ellmo client ID\n * @param url - Function that returns the URL path from GetStaticPropsContext\n * @param type - Content type: 'semantic' or 'structured' (default: 'semantic')\n * @param debugging - Include ellmoError in props for debugging (default: false)\n *\n * Returns ellmoData and ellmoError in props at both root level and inside pageProps for flexibility.\n *\n * @example\n * ```tsx\n * import { withEllmoStatic } from 'ellmo-ai-react';\n *\n * export const getStaticProps = withEllmoStatic({\n * clientId: process.env.ELLMO_CLIENT_ID!,\n * url: (context) => context.params?.slug ? `/blog/${context.params.slug}` : '/',\n * type: 'semantic',\n * debugging: process.env.NODE_ENV === 'development'\n * });\n *\n * // In page component - access directly\n * export default function BlogPost({ ellmoData, ellmoError }) {\n * return (\n * <div>\n * <EllmoApiSSR data={ellmoData} error={ellmoError} />\n * <h1>Blog Post</h1>\n * </div>\n * );\n * }\n *\n * // In _app.tsx - access via pageProps\n * function MyApp({ Component, pageProps }) {\n * return (\n * <div>\n * <EllmoApiSSR data={pageProps.pageEllmoData} error={pageProps.pageEllmoError} />\n * <Component {...pageProps} />\n * </div>\n * );\n * }\n * ```\n */\nexport function withEllmoStatic<P extends Record<string, any> = Record<string, any>>({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: (context: GetStaticPropsContext) => string;\n type?: EllmoApiType;\n debugging?: boolean;\n}) {\n return async (context: GetStaticPropsContext) => {\n return getEllmoStaticProps({\n clientId,\n url: url(context),\n type,\n debugging\n }) as Promise<{ props: P & { ellmoData: string | null; ellmoError?: string | null; pageProps?: { pageEllmoData: string | null; pageEllmoError?: string | null } } }>;\n };\n}\n\n/**\n * Build standardized Ellmo props synchronously from provided data and error.\n * Returns ellmoData/ellmoError at root and pageEllmoData/pageEllmoError inside pageProps.\n */\n// (removed buildEllmoProps to reduce surface area)\n\n/**\n * Fetch Ellmo data and return standardized props (no Next.js dependency).\n * Accepts a plain URL string and returns the same shape as buildEllmoProps.\n */\nexport async function getEllmoStaticProps({\n clientId,\n url,\n type = 'semantic',\n debugging = false\n}: {\n clientId: string;\n url: string;\n type?: EllmoApiType;\n debugging?: boolean;\n}): Promise<{ props: { ellmoData: string | null; ellmoError?: string | null; pageProps: { pageEllmoData: string | null; pageEllmoError?: string | null } } }> {\n const { data, error } = await fetchEllmoData({ clientId, url, type });\n const props: { ellmoData: string | null; ellmoError?: string | null; pageProps: { pageEllmoData: string | null; pageEllmoError?: string | null } } = {\n ellmoData: data,\n pageProps: {\n pageEllmoData: data\n }\n };\n\n if (debugging) {\n props.ellmoError = error;\n props.pageProps.pageEllmoError = error;\n }\n\n return { props };\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 head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
|
"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",
|