@flyo/nitro-next 1.0.4 → 1.1.1
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/server.d.mts +48 -2
- package/dist/server.d.ts +48 -2
- package/dist/server.js +51 -21
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +47 -20
- package/dist/server.mjs.map +1 -1
- package/package.json +6 -6
package/dist/server.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Metadata } from 'next';
|
|
2
3
|
import { Configuration, ConfigResponse, PagesApi, EntitiesApi, Page, Block } from '@flyo/nitro-typescript';
|
|
3
4
|
|
|
4
5
|
declare const initNitro: ({ accessToken, lang, components, showMissingComponentAlert }: {
|
|
@@ -7,9 +8,17 @@ declare const initNitro: ({ accessToken, lang, components, showMissingComponentA
|
|
|
7
8
|
components?: object;
|
|
8
9
|
showMissingComponentAlert?: boolean;
|
|
9
10
|
}) => (() => Configuration);
|
|
10
|
-
declare
|
|
11
|
+
declare const getNitroConfig: () => Promise<ConfigResponse>;
|
|
11
12
|
declare function getNitroPages(): PagesApi;
|
|
12
13
|
declare function getNitroEntities(): EntitiesApi;
|
|
14
|
+
/**
|
|
15
|
+
* Route params type for Next.js catch-all routes
|
|
16
|
+
*/
|
|
17
|
+
type RouteParams = {
|
|
18
|
+
params: Promise<{
|
|
19
|
+
slug?: string[];
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
13
22
|
/**
|
|
14
23
|
* NitroPage component renders all blocks from a Flyo page
|
|
15
24
|
*/
|
|
@@ -19,5 +28,42 @@ declare function NitroPage({ page, }: {
|
|
|
19
28
|
declare function NitroBlock({ block, }: {
|
|
20
29
|
block: Block;
|
|
21
30
|
}): react_jsx_runtime.JSX.Element | null;
|
|
31
|
+
/**
|
|
32
|
+
* Default page route handler for Nitro pages
|
|
33
|
+
* Can be re-exported directly from Next.js app routes
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // app/[[...slug]]/page.tsx
|
|
38
|
+
* export { nitroPageRoute as default } from '@flyo/nitro-next/server';
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function nitroPageRoute(props: RouteParams): Promise<react_jsx_runtime.JSX.Element>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate metadata for Nitro pages
|
|
44
|
+
* Provides basic meta tags based on Flyo page data
|
|
45
|
+
* Can be re-exported directly from Next.js app routes
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // app/[[...slug]]/page.tsx
|
|
50
|
+
* export { nitroGenerateMetadata as generateMetadata } from '@flyo/nitro-next/server';
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function nitroGenerateMetadata(props: RouteParams): Promise<Metadata>;
|
|
54
|
+
/**
|
|
55
|
+
* Generate static params for all Nitro pages
|
|
56
|
+
* Enables static site generation (SSG) for all pages
|
|
57
|
+
* Can be re-exported directly from Next.js app routes
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // app/[[...slug]]/page.tsx
|
|
62
|
+
* export { nitroGenerateStaticParams as generateStaticParams } from '@flyo/nitro-next/server';
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function nitroGenerateStaticParams(): Promise<{
|
|
66
|
+
slug: string[] | undefined;
|
|
67
|
+
}[]>;
|
|
22
68
|
|
|
23
|
-
export { NitroBlock, NitroPage, getNitroConfig, getNitroEntities, getNitroPages, initNitro };
|
|
69
|
+
export { NitroBlock, NitroPage, getNitroConfig, getNitroEntities, getNitroPages, initNitro, nitroGenerateMetadata, nitroGenerateStaticParams, nitroPageRoute };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { Metadata } from 'next';
|
|
2
3
|
import { Configuration, ConfigResponse, PagesApi, EntitiesApi, Page, Block } from '@flyo/nitro-typescript';
|
|
3
4
|
|
|
4
5
|
declare const initNitro: ({ accessToken, lang, components, showMissingComponentAlert }: {
|
|
@@ -7,9 +8,17 @@ declare const initNitro: ({ accessToken, lang, components, showMissingComponentA
|
|
|
7
8
|
components?: object;
|
|
8
9
|
showMissingComponentAlert?: boolean;
|
|
9
10
|
}) => (() => Configuration);
|
|
10
|
-
declare
|
|
11
|
+
declare const getNitroConfig: () => Promise<ConfigResponse>;
|
|
11
12
|
declare function getNitroPages(): PagesApi;
|
|
12
13
|
declare function getNitroEntities(): EntitiesApi;
|
|
14
|
+
/**
|
|
15
|
+
* Route params type for Next.js catch-all routes
|
|
16
|
+
*/
|
|
17
|
+
type RouteParams = {
|
|
18
|
+
params: Promise<{
|
|
19
|
+
slug?: string[];
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
13
22
|
/**
|
|
14
23
|
* NitroPage component renders all blocks from a Flyo page
|
|
15
24
|
*/
|
|
@@ -19,5 +28,42 @@ declare function NitroPage({ page, }: {
|
|
|
19
28
|
declare function NitroBlock({ block, }: {
|
|
20
29
|
block: Block;
|
|
21
30
|
}): react_jsx_runtime.JSX.Element | null;
|
|
31
|
+
/**
|
|
32
|
+
* Default page route handler for Nitro pages
|
|
33
|
+
* Can be re-exported directly from Next.js app routes
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* // app/[[...slug]]/page.tsx
|
|
38
|
+
* export { nitroPageRoute as default } from '@flyo/nitro-next/server';
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function nitroPageRoute(props: RouteParams): Promise<react_jsx_runtime.JSX.Element>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate metadata for Nitro pages
|
|
44
|
+
* Provides basic meta tags based on Flyo page data
|
|
45
|
+
* Can be re-exported directly from Next.js app routes
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // app/[[...slug]]/page.tsx
|
|
50
|
+
* export { nitroGenerateMetadata as generateMetadata } from '@flyo/nitro-next/server';
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function nitroGenerateMetadata(props: RouteParams): Promise<Metadata>;
|
|
54
|
+
/**
|
|
55
|
+
* Generate static params for all Nitro pages
|
|
56
|
+
* Enables static site generation (SSG) for all pages
|
|
57
|
+
* Can be re-exported directly from Next.js app routes
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // app/[[...slug]]/page.tsx
|
|
62
|
+
* export { nitroGenerateStaticParams as generateStaticParams } from '@flyo/nitro-next/server';
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function nitroGenerateStaticParams(): Promise<{
|
|
66
|
+
slug: string[] | undefined;
|
|
67
|
+
}[]>;
|
|
22
68
|
|
|
23
|
-
export { NitroBlock, NitroPage, getNitroConfig, getNitroEntities, getNitroPages, initNitro };
|
|
69
|
+
export { NitroBlock, NitroPage, getNitroConfig, getNitroEntities, getNitroPages, initNitro, nitroGenerateMetadata, nitroGenerateStaticParams, nitroPageRoute };
|
package/dist/server.js
CHANGED
|
@@ -25,14 +25,17 @@ __export(server_exports, {
|
|
|
25
25
|
getNitroConfig: () => getNitroConfig,
|
|
26
26
|
getNitroEntities: () => getNitroEntities,
|
|
27
27
|
getNitroPages: () => getNitroPages,
|
|
28
|
-
initNitro: () => initNitro
|
|
28
|
+
initNitro: () => initNitro,
|
|
29
|
+
nitroGenerateMetadata: () => nitroGenerateMetadata,
|
|
30
|
+
nitroGenerateStaticParams: () => nitroGenerateStaticParams,
|
|
31
|
+
nitroPageRoute: () => nitroPageRoute
|
|
29
32
|
});
|
|
30
33
|
module.exports = __toCommonJS(server_exports);
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var import_navigation = require("next/navigation");
|
|
31
36
|
var import_nitro_typescript = require("@flyo/nitro-typescript");
|
|
32
37
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
38
|
var globalConfiguration = null;
|
|
34
|
-
var configResponse = null;
|
|
35
|
-
var configPromise = null;
|
|
36
39
|
var globalLang = null;
|
|
37
40
|
var globalComponents = {};
|
|
38
41
|
var globalShowMissingComponentAlert = false;
|
|
@@ -47,31 +50,34 @@ var initNitro = ({ accessToken, lang, components, showMissingComponentAlert }) =
|
|
|
47
50
|
globalShowMissingComponentAlert = showMissingComponentAlert ?? false;
|
|
48
51
|
return () => globalConfiguration;
|
|
49
52
|
};
|
|
50
|
-
|
|
51
|
-
console.log("\n[getNitroConfig] call");
|
|
52
|
-
if (configResponse) {
|
|
53
|
-
return configResponse;
|
|
54
|
-
}
|
|
55
|
-
if (configPromise) {
|
|
56
|
-
return configPromise;
|
|
57
|
-
}
|
|
53
|
+
var getNitroConfig = (0, import_react.cache)(async () => {
|
|
58
54
|
const configApi = new import_nitro_typescript.ConfigApi(globalConfiguration);
|
|
59
55
|
const useLang = globalLang ?? void 0;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}).finally(() => {
|
|
64
|
-
configPromise = null;
|
|
65
|
-
console.log("\n[getNitroConfig] fetched config");
|
|
66
|
-
});
|
|
67
|
-
return configPromise;
|
|
68
|
-
}
|
|
56
|
+
const config = await configApi.config({ lang: useLang });
|
|
57
|
+
return config;
|
|
58
|
+
});
|
|
69
59
|
function getNitroPages() {
|
|
70
60
|
return new import_nitro_typescript.PagesApi(globalConfiguration);
|
|
71
61
|
}
|
|
72
62
|
function getNitroEntities() {
|
|
73
63
|
return new import_nitro_typescript.EntitiesApi(globalConfiguration);
|
|
74
64
|
}
|
|
65
|
+
var resolveNitroRoute = (0, import_react.cache)(async ({ params }) => {
|
|
66
|
+
const { slug } = await params;
|
|
67
|
+
const path = slug?.join("/") ?? "";
|
|
68
|
+
const cfg = await getNitroConfig();
|
|
69
|
+
if (!cfg.pages?.includes(path)) {
|
|
70
|
+
(0, import_navigation.notFound)();
|
|
71
|
+
}
|
|
72
|
+
const page = await getNitroPages().page({ slug: path }).catch((error) => {
|
|
73
|
+
console.error("Error fetching page:", path, error);
|
|
74
|
+
(0, import_navigation.notFound)();
|
|
75
|
+
});
|
|
76
|
+
if (!page) {
|
|
77
|
+
(0, import_navigation.notFound)();
|
|
78
|
+
}
|
|
79
|
+
return { page, path, cfg };
|
|
80
|
+
});
|
|
75
81
|
function NitroPage({
|
|
76
82
|
page
|
|
77
83
|
}) {
|
|
@@ -105,6 +111,27 @@ function NitroBlock({
|
|
|
105
111
|
}
|
|
106
112
|
return null;
|
|
107
113
|
}
|
|
114
|
+
async function nitroPageRoute(props) {
|
|
115
|
+
const { page } = await resolveNitroRoute(props);
|
|
116
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NitroPage, { page });
|
|
117
|
+
}
|
|
118
|
+
async function nitroGenerateMetadata(props) {
|
|
119
|
+
const { page } = await resolveNitroRoute(props);
|
|
120
|
+
const meta = page.meta_json;
|
|
121
|
+
const title = meta?.title ?? page.title ?? "Page";
|
|
122
|
+
const description = meta?.description ?? "";
|
|
123
|
+
return {
|
|
124
|
+
title,
|
|
125
|
+
description
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function nitroGenerateStaticParams() {
|
|
129
|
+
const cfg = await getNitroConfig();
|
|
130
|
+
const pages = cfg.pages ?? [];
|
|
131
|
+
return pages.map((path) => ({
|
|
132
|
+
slug: path === "" ? void 0 : path.split("/")
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
108
135
|
// Annotate the CommonJS export names for ESM import in node:
|
|
109
136
|
0 && (module.exports = {
|
|
110
137
|
NitroBlock,
|
|
@@ -112,6 +139,9 @@ function NitroBlock({
|
|
|
112
139
|
getNitroConfig,
|
|
113
140
|
getNitroEntities,
|
|
114
141
|
getNitroPages,
|
|
115
|
-
initNitro
|
|
142
|
+
initNitro,
|
|
143
|
+
nitroGenerateMetadata,
|
|
144
|
+
nitroGenerateStaticParams,
|
|
145
|
+
nitroPageRoute
|
|
116
146
|
});
|
|
117
147
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.tsx"],"sourcesContent":["import {\n Page,\n Block,\n ConfigApi,\n ConfigResponse,\n Configuration,\n PagesApi,\n EntitiesApi\n} from '@flyo/nitro-typescript';\n\nlet globalConfiguration: Configuration | null = null;\nlet
|
|
1
|
+
{"version":3,"sources":["../src/server.tsx"],"sourcesContent":["import { cache } from 'react';\nimport type { Metadata } from 'next';\nimport { notFound } from 'next/navigation';\nimport {\n Page,\n Block,\n ConfigApi,\n ConfigResponse,\n Configuration,\n PagesApi,\n EntitiesApi\n} from '@flyo/nitro-typescript';\n\nlet globalConfiguration: Configuration | null = null;\nlet globalLang: string | null = null;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet globalComponents: Record<string, any> = {};\nlet globalShowMissingComponentAlert: boolean = false;\n\nexport const initNitro = ({accessToken, lang, components, showMissingComponentAlert}: {accessToken: string, lang?: string, components?: object, showMissingComponentAlert?: boolean}): ( () => Configuration ) => {\n\n if (!globalConfiguration) {\n globalConfiguration = new Configuration({\n apiKey: accessToken,\n });\n }\n\n globalLang = lang ?? null;\n globalComponents = components ?? {};\n globalShowMissingComponentAlert = showMissingComponentAlert ?? false;\n\n return () => globalConfiguration!;\n}\n\nexport const getNitroConfig = cache(async (): Promise<ConfigResponse> => {\n\n const configApi = new ConfigApi(globalConfiguration!);\n const useLang = globalLang ?? undefined;\n\n const config = await configApi.config({ lang: useLang });\n \n return config;\n});\n\nexport function getNitroPages(): PagesApi {\n return new PagesApi(globalConfiguration!);\n}\n\nexport function getNitroEntities(): EntitiesApi {\n return new EntitiesApi(globalConfiguration!);\n}\n\n/**\n * Route params type for Next.js catch-all routes\n */\ntype RouteParams = {\n params: Promise<{ slug?: string[] }>;\n};\n\n/**\n * Internal helper to resolve Nitro page from route params\n * Uses React cache to avoid duplicate fetching\n */\nconst resolveNitroRoute = cache(async ({ params }: RouteParams) => {\n const { slug } = await params;\n const path = slug?.join('/') ?? '';\n\n const cfg = await getNitroConfig();\n\n if (!cfg.pages?.includes(path)) {\n notFound();\n }\n\n const page = await getNitroPages()\n .page({ slug: path })\n .catch((error: unknown) => {\n console.error('Error fetching page:', path, error);\n notFound();\n });\n\n if (!page) {\n notFound();\n }\n\n return { page, path, cfg };\n});\n\n\n/**\n * NitroPage component renders all blocks from a Flyo page\n */\nexport function NitroPage({\n page,\n}: {\n page: Page\n}) {\n if (!page?.json || !Array.isArray(page.json)) {\n return null;\n }\n\n return (\n <>\n {page.json.map((block: Block, index: number) => (\n <NitroBlock\n key={block.uid || index}\n block={block}\n />\n ))}\n </>\n );\n}\n\nexport function NitroBlock({\n block,\n}: {\n block: Block\n}) {\n if (!block) {\n return null;\n }\n\n const Component = block.component ? globalComponents[block.component] : undefined;\n\n if (Component) {\n return <Component block={block} />;\n }\n\n if (globalShowMissingComponentAlert) {\n return (\n <div style={{ border: '1px solid #fff', padding: '1rem', marginBottom: '1rem', backgroundColor: 'red' }}>\n Component <b>{block.component}</b> not found.\n </div>\n );\n }\n\n return null;\n}\n\n/**\n * Default page route handler for Nitro pages\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroPageRoute as default } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroPageRoute(props: RouteParams) {\n const { page } = await resolveNitroRoute(props);\n return <NitroPage page={page} />;\n}\n\n/**\n * Generate metadata for Nitro pages\n * Provides basic meta tags based on Flyo page data\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroGenerateMetadata as generateMetadata } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroGenerateMetadata(\n props: RouteParams\n): Promise<Metadata> {\n const { page } = await resolveNitroRoute(props);\n\n // Extract meta information from page\n const meta = page.meta_json;\n \n const title = meta?.title ?? page.title ?? 'Page';\n const description = meta?.description ?? '';\n\n return {\n title,\n description,\n };\n}\n\n/**\n * Generate static params for all Nitro pages\n * Enables static site generation (SSG) for all pages\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroGenerateStaticParams as generateStaticParams } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroGenerateStaticParams() {\n const cfg = await getNitroConfig();\n const pages = cfg.pages ?? [];\n\n return pages.map((path: string) => ({\n slug: path === '' ? undefined : path.split('/'),\n }));\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAEtB,wBAAyB;AACzB,8BAQO;AA0FH;AAxFJ,IAAI,sBAA4C;AAChD,IAAI,aAA4B;AAEhC,IAAI,mBAAwC,CAAC;AAC7C,IAAI,kCAA2C;AAExC,IAAM,YAAY,CAAC,EAAC,aAAa,MAAM,YAAY,0BAAyB,MAAiI;AAEhN,MAAI,CAAC,qBAAqB;AACxB,0BAAsB,IAAI,sCAAc;AAAA,MACtC,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAEA,eAAa,QAAQ;AACrB,qBAAmB,cAAc,CAAC;AAClC,oCAAkC,6BAA6B;AAE/D,SAAO,MAAM;AACjB;AAEO,IAAM,qBAAiB,oBAAM,YAAqC;AAErE,QAAM,YAAY,IAAI,kCAAU,mBAAoB;AACpD,QAAM,UAAU,cAAc;AAE9B,QAAM,SAAS,MAAM,UAAU,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEvD,SAAO;AACX,CAAC;AAEM,SAAS,gBAA0B;AACxC,SAAO,IAAI,iCAAS,mBAAoB;AAC1C;AAEO,SAAS,mBAAgC;AAC9C,SAAO,IAAI,oCAAY,mBAAoB;AAC7C;AAaA,IAAM,wBAAoB,oBAA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AAkB,KAAK;AAC9C,SAAO,4CAAC,aAAU,MAAY;AAChC;AAaA,eAAsB,sBACpB,OACmB;AACnB,QAAM,EAAE,KAAK,IAAI,MAAM,kBAAkB,KAAK;AAG9C,QAAM,OAAO,KAAK;AAElB,QAAM,QAAQ,MAAM,SAAS,KAAK,SAAS;AAC3C,QAAM,cAAc,MAAM,eAAe;AAEzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAaA,eAAsB,4BAA4B;AAChD,QAAM,MAAM,MAAM,eAAe;AACjC,QAAM,QAAQ,IAAI,SAAS,CAAC;AAE5B,SAAO,MAAM,IAAI,CAAC,UAAkB;AAAA,IAClC,MAAM,SAAS,KAAK,SAAY,KAAK,MAAM,GAAG;AAAA,EAChD,EAAE;AACJ;","names":[]}
|
package/dist/server.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// src/server.tsx
|
|
2
|
+
import { cache } from "react";
|
|
3
|
+
import { notFound } from "next/navigation";
|
|
2
4
|
import {
|
|
3
5
|
ConfigApi,
|
|
4
6
|
Configuration,
|
|
@@ -7,8 +9,6 @@ import {
|
|
|
7
9
|
} from "@flyo/nitro-typescript";
|
|
8
10
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
11
|
var globalConfiguration = null;
|
|
10
|
-
var configResponse = null;
|
|
11
|
-
var configPromise = null;
|
|
12
12
|
var globalLang = null;
|
|
13
13
|
var globalComponents = {};
|
|
14
14
|
var globalShowMissingComponentAlert = false;
|
|
@@ -23,31 +23,34 @@ var initNitro = ({ accessToken, lang, components, showMissingComponentAlert }) =
|
|
|
23
23
|
globalShowMissingComponentAlert = showMissingComponentAlert ?? false;
|
|
24
24
|
return () => globalConfiguration;
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
console.log("\n[getNitroConfig] call");
|
|
28
|
-
if (configResponse) {
|
|
29
|
-
return configResponse;
|
|
30
|
-
}
|
|
31
|
-
if (configPromise) {
|
|
32
|
-
return configPromise;
|
|
33
|
-
}
|
|
26
|
+
var getNitroConfig = cache(async () => {
|
|
34
27
|
const configApi = new ConfigApi(globalConfiguration);
|
|
35
28
|
const useLang = globalLang ?? void 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}).finally(() => {
|
|
40
|
-
configPromise = null;
|
|
41
|
-
console.log("\n[getNitroConfig] fetched config");
|
|
42
|
-
});
|
|
43
|
-
return configPromise;
|
|
44
|
-
}
|
|
29
|
+
const config = await configApi.config({ lang: useLang });
|
|
30
|
+
return config;
|
|
31
|
+
});
|
|
45
32
|
function getNitroPages() {
|
|
46
33
|
return new PagesApi(globalConfiguration);
|
|
47
34
|
}
|
|
48
35
|
function getNitroEntities() {
|
|
49
36
|
return new EntitiesApi(globalConfiguration);
|
|
50
37
|
}
|
|
38
|
+
var resolveNitroRoute = cache(async ({ params }) => {
|
|
39
|
+
const { slug } = await params;
|
|
40
|
+
const path = slug?.join("/") ?? "";
|
|
41
|
+
const cfg = await getNitroConfig();
|
|
42
|
+
if (!cfg.pages?.includes(path)) {
|
|
43
|
+
notFound();
|
|
44
|
+
}
|
|
45
|
+
const page = await getNitroPages().page({ slug: path }).catch((error) => {
|
|
46
|
+
console.error("Error fetching page:", path, error);
|
|
47
|
+
notFound();
|
|
48
|
+
});
|
|
49
|
+
if (!page) {
|
|
50
|
+
notFound();
|
|
51
|
+
}
|
|
52
|
+
return { page, path, cfg };
|
|
53
|
+
});
|
|
51
54
|
function NitroPage({
|
|
52
55
|
page
|
|
53
56
|
}) {
|
|
@@ -81,12 +84,36 @@ function NitroBlock({
|
|
|
81
84
|
}
|
|
82
85
|
return null;
|
|
83
86
|
}
|
|
87
|
+
async function nitroPageRoute(props) {
|
|
88
|
+
const { page } = await resolveNitroRoute(props);
|
|
89
|
+
return /* @__PURE__ */ jsx(NitroPage, { page });
|
|
90
|
+
}
|
|
91
|
+
async function nitroGenerateMetadata(props) {
|
|
92
|
+
const { page } = await resolveNitroRoute(props);
|
|
93
|
+
const meta = page.meta_json;
|
|
94
|
+
const title = meta?.title ?? page.title ?? "Page";
|
|
95
|
+
const description = meta?.description ?? "";
|
|
96
|
+
return {
|
|
97
|
+
title,
|
|
98
|
+
description
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function nitroGenerateStaticParams() {
|
|
102
|
+
const cfg = await getNitroConfig();
|
|
103
|
+
const pages = cfg.pages ?? [];
|
|
104
|
+
return pages.map((path) => ({
|
|
105
|
+
slug: path === "" ? void 0 : path.split("/")
|
|
106
|
+
}));
|
|
107
|
+
}
|
|
84
108
|
export {
|
|
85
109
|
NitroBlock,
|
|
86
110
|
NitroPage,
|
|
87
111
|
getNitroConfig,
|
|
88
112
|
getNitroEntities,
|
|
89
113
|
getNitroPages,
|
|
90
|
-
initNitro
|
|
114
|
+
initNitro,
|
|
115
|
+
nitroGenerateMetadata,
|
|
116
|
+
nitroGenerateStaticParams,
|
|
117
|
+
nitroPageRoute
|
|
91
118
|
};
|
|
92
119
|
//# sourceMappingURL=server.mjs.map
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.tsx"],"sourcesContent":["import {\n Page,\n Block,\n ConfigApi,\n ConfigResponse,\n Configuration,\n PagesApi,\n EntitiesApi\n} from '@flyo/nitro-typescript';\n\nlet globalConfiguration: Configuration | null = null;\nlet
|
|
1
|
+
{"version":3,"sources":["../src/server.tsx"],"sourcesContent":["import { cache } from 'react';\nimport type { Metadata } from 'next';\nimport { notFound } from 'next/navigation';\nimport {\n Page,\n Block,\n ConfigApi,\n ConfigResponse,\n Configuration,\n PagesApi,\n EntitiesApi\n} from '@flyo/nitro-typescript';\n\nlet globalConfiguration: Configuration | null = null;\nlet globalLang: string | null = null;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet globalComponents: Record<string, any> = {};\nlet globalShowMissingComponentAlert: boolean = false;\n\nexport const initNitro = ({accessToken, lang, components, showMissingComponentAlert}: {accessToken: string, lang?: string, components?: object, showMissingComponentAlert?: boolean}): ( () => Configuration ) => {\n\n if (!globalConfiguration) {\n globalConfiguration = new Configuration({\n apiKey: accessToken,\n });\n }\n\n globalLang = lang ?? null;\n globalComponents = components ?? {};\n globalShowMissingComponentAlert = showMissingComponentAlert ?? false;\n\n return () => globalConfiguration!;\n}\n\nexport const getNitroConfig = cache(async (): Promise<ConfigResponse> => {\n\n const configApi = new ConfigApi(globalConfiguration!);\n const useLang = globalLang ?? undefined;\n\n const config = await configApi.config({ lang: useLang });\n \n return config;\n});\n\nexport function getNitroPages(): PagesApi {\n return new PagesApi(globalConfiguration!);\n}\n\nexport function getNitroEntities(): EntitiesApi {\n return new EntitiesApi(globalConfiguration!);\n}\n\n/**\n * Route params type for Next.js catch-all routes\n */\ntype RouteParams = {\n params: Promise<{ slug?: string[] }>;\n};\n\n/**\n * Internal helper to resolve Nitro page from route params\n * Uses React cache to avoid duplicate fetching\n */\nconst resolveNitroRoute = cache(async ({ params }: RouteParams) => {\n const { slug } = await params;\n const path = slug?.join('/') ?? '';\n\n const cfg = await getNitroConfig();\n\n if (!cfg.pages?.includes(path)) {\n notFound();\n }\n\n const page = await getNitroPages()\n .page({ slug: path })\n .catch((error: unknown) => {\n console.error('Error fetching page:', path, error);\n notFound();\n });\n\n if (!page) {\n notFound();\n }\n\n return { page, path, cfg };\n});\n\n\n/**\n * NitroPage component renders all blocks from a Flyo page\n */\nexport function NitroPage({\n page,\n}: {\n page: Page\n}) {\n if (!page?.json || !Array.isArray(page.json)) {\n return null;\n }\n\n return (\n <>\n {page.json.map((block: Block, index: number) => (\n <NitroBlock\n key={block.uid || index}\n block={block}\n />\n ))}\n </>\n );\n}\n\nexport function NitroBlock({\n block,\n}: {\n block: Block\n}) {\n if (!block) {\n return null;\n }\n\n const Component = block.component ? globalComponents[block.component] : undefined;\n\n if (Component) {\n return <Component block={block} />;\n }\n\n if (globalShowMissingComponentAlert) {\n return (\n <div style={{ border: '1px solid #fff', padding: '1rem', marginBottom: '1rem', backgroundColor: 'red' }}>\n Component <b>{block.component}</b> not found.\n </div>\n );\n }\n\n return null;\n}\n\n/**\n * Default page route handler for Nitro pages\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroPageRoute as default } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroPageRoute(props: RouteParams) {\n const { page } = await resolveNitroRoute(props);\n return <NitroPage page={page} />;\n}\n\n/**\n * Generate metadata for Nitro pages\n * Provides basic meta tags based on Flyo page data\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroGenerateMetadata as generateMetadata } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroGenerateMetadata(\n props: RouteParams\n): Promise<Metadata> {\n const { page } = await resolveNitroRoute(props);\n\n // Extract meta information from page\n const meta = page.meta_json;\n \n const title = meta?.title ?? page.title ?? 'Page';\n const description = meta?.description ?? '';\n\n return {\n title,\n description,\n };\n}\n\n/**\n * Generate static params for all Nitro pages\n * Enables static site generation (SSG) for all pages\n * Can be re-exported directly from Next.js app routes\n * \n * @example\n * ```ts\n * // app/[[...slug]]/page.tsx\n * export { nitroGenerateStaticParams as generateStaticParams } from '@flyo/nitro-next/server';\n * ```\n */\nexport async function nitroGenerateStaticParams() {\n const cfg = await getNitroConfig();\n const pages = cfg.pages ?? [];\n\n return pages.map((path: string) => ({\n slug: path === '' ? undefined : path.split('/'),\n }));\n}"],"mappings":";AAAA,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AACzB;AAAA,EAGE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA0FH,mBAEI,KA0BF,YA5BF;AAxFJ,IAAI,sBAA4C;AAChD,IAAI,aAA4B;AAEhC,IAAI,mBAAwC,CAAC;AAC7C,IAAI,kCAA2C;AAExC,IAAM,YAAY,CAAC,EAAC,aAAa,MAAM,YAAY,0BAAyB,MAAiI;AAEhN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AA,EAEpB,CACD,GACH;AAEJ;AAEO,SAAS,WAAW;AAAA,EACzB;AACF,GAEG;AACD,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,MAAM,YAAY,iBAAiB,MAAM,SAAS,IAAI;AAExE,MAAI,WAAW;AACb,WAAO,oBAAC,aAAU,OAAc;AAAA,EAClC;AAEA,MAAI,iCAAiC;AACnC,WACE,qBAAC,SAAI,OAAO,EAAE,QAAQ,kBAAkB,SAAS,QAAQ,cAAc,QAAQ,iBAAiB,MAAM,GAAG;AAAA;AAAA,MAC7F,oBAAC,OAAG,gBAAM,WAAU;AAAA,MAAI;AAAA,OACpC;AAAA,EAEJ;AAEA,SAAO;AACT;AAYA,eAAsB,eAAe,OAAoB;AACvD,QAAM,EAAE,KAAK,IAAI,MAAM,kBAAkB,KAAK;AAC9C,SAAO,oBAAC,aAAU,MAAY;AAChC;AAaA,eAAsB,sBACpB,OACmB;AACnB,QAAM,EAAE,KAAK,IAAI,MAAM,kBAAkB,KAAK;AAG9C,QAAM,OAAO,KAAK;AAElB,QAAM,QAAQ,MAAM,SAAS,KAAK,SAAS;AAC3C,QAAM,cAAc,MAAM,eAAe;AAEzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAaA,eAAsB,4BAA4B;AAChD,QAAM,MAAM,MAAM,eAAe;AACjC,QAAM,QAAQ,IAAI,SAAS,CAAC;AAE5B,SAAO,MAAM,IAAI,CAAC,UAAkB;AAAA,IAClC,MAAM,SAAS,KAAK,SAAY,KAAK,MAAM,GAAG;AAAA,EAChD,EAAE;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flyo/nitro-next",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Connecting Flyo Headless Content Hub into your Next.js project.",
|
|
5
5
|
"homepage": "https://dev.flyo.cloud/nitro",
|
|
6
6
|
"keywords": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "jest",
|
|
19
19
|
"test:watch": "jest --watch",
|
|
20
20
|
"test:coverage": "jest --coverage",
|
|
21
|
-
"lint": "eslint src"
|
|
21
|
+
"lint": "eslint src *.js"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"next": ">=16.0.4",
|
|
49
|
-
"react": "
|
|
50
|
-
"react-dom": "
|
|
49
|
+
"react": "^19.2.1",
|
|
50
|
+
"react-dom": "^19.2.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@testing-library/jest-dom": "^6.1.5",
|
|
54
54
|
"@testing-library/react": "^14.1.2",
|
|
55
55
|
"@types/jest": "^29.5.11",
|
|
56
56
|
"@types/node": "^20.10.0",
|
|
57
|
-
"@types/react": "^
|
|
58
|
-
"@types/react-dom": "^
|
|
57
|
+
"@types/react": "^19.2.1",
|
|
58
|
+
"@types/react-dom": "^19.2.1",
|
|
59
59
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
60
60
|
"@typescript-eslint/parser": "^7.18.0",
|
|
61
61
|
"eslint": "^8.57.1",
|