@flocon-ai/react 0.0.1 → 0.0.2
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/index.cjs +18 -13
- package/dist/index.d.cts +16 -11
- package/dist/index.d.ts +16 -11
- package/dist/index.js +18 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -508,19 +508,18 @@ function removeTrailingSlash(url) {
|
|
|
508
508
|
|
|
509
509
|
// src/client.ts
|
|
510
510
|
var PACKAGES_API_URL = "https://api.flocon-ai.com";
|
|
511
|
-
function createFloconClient() {
|
|
511
|
+
function createFloconClient({ token = process.env.FLOCON_TOKEN } = {}) {
|
|
512
512
|
if (typeof window !== "undefined") {
|
|
513
513
|
throw new Error("Flocon: call this on the server only (route loader, server function), never in the browser");
|
|
514
514
|
}
|
|
515
|
-
|
|
516
|
-
if (!token) throw new Error("FLOCON_TOKEN is missing");
|
|
515
|
+
if (!token) throw new Error("FLOCON_TOKEN is missing (or pass the `token` option)");
|
|
517
516
|
return createClient({
|
|
518
517
|
baseUrl: PACKAGES_API_URL,
|
|
519
518
|
headers: { Authorization: `Bearer ${token}` }
|
|
520
519
|
});
|
|
521
520
|
}
|
|
522
|
-
async function getPage({ path, locale }) {
|
|
523
|
-
const client = createFloconClient();
|
|
521
|
+
async function getPage({ path, locale, token }) {
|
|
522
|
+
const client = createFloconClient({ token });
|
|
524
523
|
const { data: website, error: websiteError } = await client.GET("/website");
|
|
525
524
|
if (!website) throw new Error(`Flocon: could not load the website: ${JSON.stringify(websiteError)}`);
|
|
526
525
|
const res = await client.GET("/pages/{locale}/{path}", {
|
|
@@ -537,14 +536,14 @@ async function getPage({ path, locale }) {
|
|
|
537
536
|
}
|
|
538
537
|
|
|
539
538
|
// src/pages.ts
|
|
540
|
-
async function getAllPages() {
|
|
541
|
-
const { data, error } = await createFloconClient().GET("/pages");
|
|
539
|
+
async function getAllPages(options = {}) {
|
|
540
|
+
const { data, error } = await createFloconClient(options).GET("/pages");
|
|
542
541
|
if (!data) throw new Error(`Flocon getAllPages failed: ${JSON.stringify(error)}`);
|
|
543
542
|
return data;
|
|
544
543
|
}
|
|
545
544
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
546
|
-
async function floconSitemap({ url }) {
|
|
547
|
-
const pages = await getAllPages();
|
|
545
|
+
async function floconSitemap({ url, token }) {
|
|
546
|
+
const pages = await getAllPages({ token });
|
|
548
547
|
const entries = pages.map((page) => {
|
|
549
548
|
const links = [page.locale, ...page.alternates].map((l) => `<xhtml:link rel="alternate" hreflang="${xml(l)}" href="${xml(url({ locale: l, path: page.path }))}"/>`).join("");
|
|
550
549
|
return `<url><loc>${xml(url(page))}</loc><lastmod>${xml(page.updatedAt)}</lastmod>${links}</url>`;
|
|
@@ -555,9 +554,13 @@ async function floconSitemap({ url }) {
|
|
|
555
554
|
</urlset>
|
|
556
555
|
`;
|
|
557
556
|
}
|
|
558
|
-
async function floconLlmsTxt({ url }) {
|
|
559
|
-
const pages = await getAllPages();
|
|
560
|
-
|
|
557
|
+
async function floconLlmsTxt({ url, token }) {
|
|
558
|
+
const [pages, website] = await Promise.all([getAllPages({ token }), createFloconClient({ token }).GET("/website")]);
|
|
559
|
+
if (!website.data) throw new Error(`Flocon floconLlmsTxt failed: ${JSON.stringify(website.error)}`);
|
|
560
|
+
const text = pages.map((page) => `- [${page.title}](${url(page)})`).join("\n") + "\n";
|
|
561
|
+
return website.data.badge ? `${text}
|
|
562
|
+
Made with [Flocon AI](https://flocon-ai.com)
|
|
563
|
+
` : text;
|
|
561
564
|
}
|
|
562
565
|
|
|
563
566
|
// src/markdown.tsx
|
|
@@ -762,7 +765,7 @@ function FloconPage({ page, url }) {
|
|
|
762
765
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flocon-space", "aria-hidden": "true" }, i);
|
|
763
766
|
}
|
|
764
767
|
}),
|
|
765
|
-
page.badge && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "flocon-badge", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: "https://flocon-ai.com", children: "\u2744 Made with Flocon AI" }) })
|
|
768
|
+
page.badge && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "flocon-badge", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", { href: "https://flocon-ai.com", children: "\u2744 Made with Flocon AI \xB7 flocon-ai.com" }) })
|
|
766
769
|
] });
|
|
767
770
|
}
|
|
768
771
|
|
|
@@ -780,6 +783,8 @@ function getFloconMetadata({ page, url }) {
|
|
|
780
783
|
title: page.seo.title,
|
|
781
784
|
description: page.seo.description,
|
|
782
785
|
keywords: page.seo.keywords,
|
|
786
|
+
/** Free plan: `<meta name="generator" content="Flocon AI">`. Put it in the `<head>`. */
|
|
787
|
+
...page.badge && { generator: "Flocon AI" },
|
|
783
788
|
canonical,
|
|
784
789
|
/** hreflang: locale (or "x-default") → URL. */
|
|
785
790
|
languages,
|
package/dist/index.d.cts
CHANGED
|
@@ -287,14 +287,18 @@ type FloconPageData = components["schemas"]["PackagesPage"] & {
|
|
|
287
287
|
/** Website default locale. Used for `x-default` in the hreflang links. */
|
|
288
288
|
defaultLocale?: string;
|
|
289
289
|
};
|
|
290
|
-
|
|
291
|
-
type
|
|
290
|
+
/** Optional on every helper that calls the Packages API. Not given = `FLOCON_TOKEN`. */
|
|
291
|
+
type TokenOption = {
|
|
292
|
+
token?: string;
|
|
293
|
+
};
|
|
294
|
+
declare function createFloconClient({ token }?: TokenOption): openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
295
|
+
type GetPageOptions = TokenOption & {
|
|
292
296
|
/** Page path, e.g. "/vs/notion". */
|
|
293
297
|
path: string;
|
|
294
298
|
/** Defaults to the website's default locale. No fallback to another locale. */
|
|
295
299
|
locale?: string;
|
|
296
300
|
};
|
|
297
|
-
declare function getPage({ path, locale }: GetPageOptions): Promise<FloconPageData | null>;
|
|
301
|
+
declare function getPage({ path, locale, token }: GetPageOptions): Promise<FloconPageData | null>;
|
|
298
302
|
|
|
299
303
|
type PageEntry = components["schemas"]["PackagesSitemapEntry"];
|
|
300
304
|
type UrlOption = {
|
|
@@ -302,10 +306,10 @@ type UrlOption = {
|
|
|
302
306
|
locale: string;
|
|
303
307
|
path: string;
|
|
304
308
|
}) => string;
|
|
305
|
-
};
|
|
306
|
-
declare function getAllPages(): Promise<PageEntry[]>;
|
|
307
|
-
declare function floconSitemap({ url }: UrlOption): Promise<string>;
|
|
308
|
-
declare function floconLlmsTxt({ url }: UrlOption): Promise<string>;
|
|
309
|
+
} & TokenOption;
|
|
310
|
+
declare function getAllPages(options?: TokenOption): Promise<PageEntry[]>;
|
|
311
|
+
declare function floconSitemap({ url, token }: UrlOption): Promise<string>;
|
|
312
|
+
declare function floconLlmsTxt({ url, token }: UrlOption): Promise<string>;
|
|
309
313
|
|
|
310
314
|
type Props = {
|
|
311
315
|
/** Page data from `getPage()`. No fetching here. */
|
|
@@ -322,9 +326,6 @@ type Options = UrlOption & {
|
|
|
322
326
|
page: FloconPageData;
|
|
323
327
|
};
|
|
324
328
|
declare function getFloconMetadata({ page, url }: Options): {
|
|
325
|
-
title: string;
|
|
326
|
-
description: string;
|
|
327
|
-
keywords: string[] | undefined;
|
|
328
329
|
canonical: string;
|
|
329
330
|
/** hreflang: locale (or "x-default") → URL. */
|
|
330
331
|
languages: Record<string, string>;
|
|
@@ -340,6 +341,10 @@ declare function getFloconMetadata({ page, url }: Options): {
|
|
|
340
341
|
title: string;
|
|
341
342
|
description: string;
|
|
342
343
|
};
|
|
344
|
+
generator?: string | undefined;
|
|
345
|
+
title: string;
|
|
346
|
+
description: string;
|
|
347
|
+
keywords: string[] | undefined;
|
|
343
348
|
};
|
|
344
349
|
|
|
345
|
-
export { FloconPage, type FloconPageData, type PageEntry, type UrlOption, type components, createFloconClient, floconLlmsTxt, floconSitemap, getAllPages, getFloconMetadata, getPage, type paths };
|
|
350
|
+
export { FloconPage, type FloconPageData, type PageEntry, type TokenOption, type UrlOption, type components, createFloconClient, floconLlmsTxt, floconSitemap, getAllPages, getFloconMetadata, getPage, type paths };
|
package/dist/index.d.ts
CHANGED
|
@@ -287,14 +287,18 @@ type FloconPageData = components["schemas"]["PackagesPage"] & {
|
|
|
287
287
|
/** Website default locale. Used for `x-default` in the hreflang links. */
|
|
288
288
|
defaultLocale?: string;
|
|
289
289
|
};
|
|
290
|
-
|
|
291
|
-
type
|
|
290
|
+
/** Optional on every helper that calls the Packages API. Not given = `FLOCON_TOKEN`. */
|
|
291
|
+
type TokenOption = {
|
|
292
|
+
token?: string;
|
|
293
|
+
};
|
|
294
|
+
declare function createFloconClient({ token }?: TokenOption): openapi_fetch.Client<paths, `${string}/${string}`>;
|
|
295
|
+
type GetPageOptions = TokenOption & {
|
|
292
296
|
/** Page path, e.g. "/vs/notion". */
|
|
293
297
|
path: string;
|
|
294
298
|
/** Defaults to the website's default locale. No fallback to another locale. */
|
|
295
299
|
locale?: string;
|
|
296
300
|
};
|
|
297
|
-
declare function getPage({ path, locale }: GetPageOptions): Promise<FloconPageData | null>;
|
|
301
|
+
declare function getPage({ path, locale, token }: GetPageOptions): Promise<FloconPageData | null>;
|
|
298
302
|
|
|
299
303
|
type PageEntry = components["schemas"]["PackagesSitemapEntry"];
|
|
300
304
|
type UrlOption = {
|
|
@@ -302,10 +306,10 @@ type UrlOption = {
|
|
|
302
306
|
locale: string;
|
|
303
307
|
path: string;
|
|
304
308
|
}) => string;
|
|
305
|
-
};
|
|
306
|
-
declare function getAllPages(): Promise<PageEntry[]>;
|
|
307
|
-
declare function floconSitemap({ url }: UrlOption): Promise<string>;
|
|
308
|
-
declare function floconLlmsTxt({ url }: UrlOption): Promise<string>;
|
|
309
|
+
} & TokenOption;
|
|
310
|
+
declare function getAllPages(options?: TokenOption): Promise<PageEntry[]>;
|
|
311
|
+
declare function floconSitemap({ url, token }: UrlOption): Promise<string>;
|
|
312
|
+
declare function floconLlmsTxt({ url, token }: UrlOption): Promise<string>;
|
|
309
313
|
|
|
310
314
|
type Props = {
|
|
311
315
|
/** Page data from `getPage()`. No fetching here. */
|
|
@@ -322,9 +326,6 @@ type Options = UrlOption & {
|
|
|
322
326
|
page: FloconPageData;
|
|
323
327
|
};
|
|
324
328
|
declare function getFloconMetadata({ page, url }: Options): {
|
|
325
|
-
title: string;
|
|
326
|
-
description: string;
|
|
327
|
-
keywords: string[] | undefined;
|
|
328
329
|
canonical: string;
|
|
329
330
|
/** hreflang: locale (or "x-default") → URL. */
|
|
330
331
|
languages: Record<string, string>;
|
|
@@ -340,6 +341,10 @@ declare function getFloconMetadata({ page, url }: Options): {
|
|
|
340
341
|
title: string;
|
|
341
342
|
description: string;
|
|
342
343
|
};
|
|
344
|
+
generator?: string | undefined;
|
|
345
|
+
title: string;
|
|
346
|
+
description: string;
|
|
347
|
+
keywords: string[] | undefined;
|
|
343
348
|
};
|
|
344
349
|
|
|
345
|
-
export { FloconPage, type FloconPageData, type PageEntry, type UrlOption, type components, createFloconClient, floconLlmsTxt, floconSitemap, getAllPages, getFloconMetadata, getPage, type paths };
|
|
350
|
+
export { FloconPage, type FloconPageData, type PageEntry, type TokenOption, type UrlOption, type components, createFloconClient, floconLlmsTxt, floconSitemap, getAllPages, getFloconMetadata, getPage, type paths };
|
package/dist/index.js
CHANGED
|
@@ -476,19 +476,18 @@ function removeTrailingSlash(url) {
|
|
|
476
476
|
|
|
477
477
|
// src/client.ts
|
|
478
478
|
var PACKAGES_API_URL = "https://api.flocon-ai.com";
|
|
479
|
-
function createFloconClient() {
|
|
479
|
+
function createFloconClient({ token = process.env.FLOCON_TOKEN } = {}) {
|
|
480
480
|
if (typeof window !== "undefined") {
|
|
481
481
|
throw new Error("Flocon: call this on the server only (route loader, server function), never in the browser");
|
|
482
482
|
}
|
|
483
|
-
|
|
484
|
-
if (!token) throw new Error("FLOCON_TOKEN is missing");
|
|
483
|
+
if (!token) throw new Error("FLOCON_TOKEN is missing (or pass the `token` option)");
|
|
485
484
|
return createClient({
|
|
486
485
|
baseUrl: PACKAGES_API_URL,
|
|
487
486
|
headers: { Authorization: `Bearer ${token}` }
|
|
488
487
|
});
|
|
489
488
|
}
|
|
490
|
-
async function getPage({ path, locale }) {
|
|
491
|
-
const client = createFloconClient();
|
|
489
|
+
async function getPage({ path, locale, token }) {
|
|
490
|
+
const client = createFloconClient({ token });
|
|
492
491
|
const { data: website, error: websiteError } = await client.GET("/website");
|
|
493
492
|
if (!website) throw new Error(`Flocon: could not load the website: ${JSON.stringify(websiteError)}`);
|
|
494
493
|
const res = await client.GET("/pages/{locale}/{path}", {
|
|
@@ -505,14 +504,14 @@ async function getPage({ path, locale }) {
|
|
|
505
504
|
}
|
|
506
505
|
|
|
507
506
|
// src/pages.ts
|
|
508
|
-
async function getAllPages() {
|
|
509
|
-
const { data, error } = await createFloconClient().GET("/pages");
|
|
507
|
+
async function getAllPages(options = {}) {
|
|
508
|
+
const { data, error } = await createFloconClient(options).GET("/pages");
|
|
510
509
|
if (!data) throw new Error(`Flocon getAllPages failed: ${JSON.stringify(error)}`);
|
|
511
510
|
return data;
|
|
512
511
|
}
|
|
513
512
|
var xml = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
514
|
-
async function floconSitemap({ url }) {
|
|
515
|
-
const pages = await getAllPages();
|
|
513
|
+
async function floconSitemap({ url, token }) {
|
|
514
|
+
const pages = await getAllPages({ token });
|
|
516
515
|
const entries = pages.map((page) => {
|
|
517
516
|
const links = [page.locale, ...page.alternates].map((l) => `<xhtml:link rel="alternate" hreflang="${xml(l)}" href="${xml(url({ locale: l, path: page.path }))}"/>`).join("");
|
|
518
517
|
return `<url><loc>${xml(url(page))}</loc><lastmod>${xml(page.updatedAt)}</lastmod>${links}</url>`;
|
|
@@ -523,9 +522,13 @@ async function floconSitemap({ url }) {
|
|
|
523
522
|
</urlset>
|
|
524
523
|
`;
|
|
525
524
|
}
|
|
526
|
-
async function floconLlmsTxt({ url }) {
|
|
527
|
-
const pages = await getAllPages();
|
|
528
|
-
|
|
525
|
+
async function floconLlmsTxt({ url, token }) {
|
|
526
|
+
const [pages, website] = await Promise.all([getAllPages({ token }), createFloconClient({ token }).GET("/website")]);
|
|
527
|
+
if (!website.data) throw new Error(`Flocon floconLlmsTxt failed: ${JSON.stringify(website.error)}`);
|
|
528
|
+
const text = pages.map((page) => `- [${page.title}](${url(page)})`).join("\n") + "\n";
|
|
529
|
+
return website.data.badge ? `${text}
|
|
530
|
+
Made with [Flocon AI](https://flocon-ai.com)
|
|
531
|
+
` : text;
|
|
529
532
|
}
|
|
530
533
|
|
|
531
534
|
// src/markdown.tsx
|
|
@@ -730,7 +733,7 @@ function FloconPage({ page, url }) {
|
|
|
730
733
|
return /* @__PURE__ */ jsx2("div", { className: "flocon-space", "aria-hidden": "true" }, i);
|
|
731
734
|
}
|
|
732
735
|
}),
|
|
733
|
-
page.badge && /* @__PURE__ */ jsx2("p", { className: "flocon-badge", children: /* @__PURE__ */ jsx2("a", { href: "https://flocon-ai.com", children: "\u2744 Made with Flocon AI" }) })
|
|
736
|
+
page.badge && /* @__PURE__ */ jsx2("p", { className: "flocon-badge", children: /* @__PURE__ */ jsx2("a", { href: "https://flocon-ai.com", children: "\u2744 Made with Flocon AI \xB7 flocon-ai.com" }) })
|
|
734
737
|
] });
|
|
735
738
|
}
|
|
736
739
|
|
|
@@ -748,6 +751,8 @@ function getFloconMetadata({ page, url }) {
|
|
|
748
751
|
title: page.seo.title,
|
|
749
752
|
description: page.seo.description,
|
|
750
753
|
keywords: page.seo.keywords,
|
|
754
|
+
/** Free plan: `<meta name="generator" content="Flocon AI">`. Put it in the `<head>`. */
|
|
755
|
+
...page.badge && { generator: "Flocon AI" },
|
|
751
756
|
canonical,
|
|
752
757
|
/** hreflang: locale (or "x-default") → URL. */
|
|
753
758
|
languages,
|