nextpress-core 1.0.3 → 2.0.0

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.
Files changed (211) hide show
  1. package/cli/install.js +27 -0
  2. package/{dist/acf-functions/core/acf-builder.js → lib/acf-functions/core/acf-builder.ts} +45 -17
  3. package/{dist/acf-functions/core/acf-component-autoloader.js → lib/acf-functions/core/acf-component-autoloader.ts} +13 -7
  4. package/{dist/acf-functions/core/acf-field-group-autoloader.js → lib/acf-functions/core/acf-field-group-autoloader.ts} +11 -5
  5. package/{dist/acf-functions/services/define-field-group.d.ts → lib/acf-functions/services/define-field-group.ts} +4 -1
  6. package/{dist/acf-functions/services/define-layout.d.ts → lib/acf-functions/services/define-layout.ts} +4 -1
  7. package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +20 -0
  8. package/{dist/acf-functions/services/map-fields/map-fields.js → lib/acf-functions/services/map-fields/map-fields.ts} +128 -89
  9. package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts} +49 -28
  10. package/lib/acf-functions/types/acf-field.ts +2853 -0
  11. package/lib/acf-functions/types/acf-layout.ts +22 -0
  12. package/lib/acf-functions/types/components/field-props.ts +189 -0
  13. package/{dist/acf-functions/types/components/nextpress-component.d.ts → lib/acf-functions/types/components/nextpress-component.ts} +4 -3
  14. package/lib/ambient.d.ts +16 -0
  15. package/{dist/entities/common.d.ts → lib/entities/common.ts} +6 -4
  16. package/{dist/entities/option/option.interface.d.ts → lib/entities/option/option.interface.ts} +3 -3
  17. package/{dist/entities/option/option.js → lib/entities/option/option.ts} +21 -14
  18. package/{dist/entities/post/post.interface.d.ts → lib/entities/post/post.interface.ts} +26 -21
  19. package/lib/entities/post/post.ts +209 -0
  20. package/{dist/entities/term/term.interface.d.ts → lib/entities/term/term.interface.ts} +3 -3
  21. package/lib/entities/term/term.ts +82 -0
  22. package/{dist/entities/user/user.interface.d.ts → lib/entities/user/user.interface.ts} +2 -1
  23. package/lib/entities/user/user.ts +86 -0
  24. package/{dist/globals/entity-loader/entity-loader-base.js → lib/globals/entity-loader/entity-loader-base.ts} +64 -10
  25. package/{dist/globals/entity-loader/entity-loader.interface.d.ts → lib/globals/entity-loader/entity-loader.ts} +2 -4
  26. package/lib/globals/entity-loader/option-loader.ts +56 -0
  27. package/lib/globals/entity-loader/post-loader.ts +60 -0
  28. package/lib/globals/entity-loader/term-loader.ts +60 -0
  29. package/lib/globals/entity-loader/user-loader.ts +61 -0
  30. package/lib/globals/get-field/get-field.ts +76 -0
  31. package/{dist/globals/globals.js → lib/globals/globals.ts} +8 -3
  32. package/{dist/globals/nextpress-config/nextpress-config.interface.d.ts → lib/globals/nextpress-config/nextpress-config.interface.ts} +10 -6
  33. package/lib/globals/nextpress-config/nextpress-config.ts +8 -0
  34. package/lib/globals/queried-object/queried-object.ts +124 -0
  35. package/{dist/repository/optionquery/option-query-args.d.ts → lib/repository/optionquery/option-query-args.ts} +5 -2
  36. package/lib/repository/optionquery/option-query.ts +29 -0
  37. package/{dist/repository/postquery/post-query-args.d.ts → lib/repository/postquery/post-query-args.ts} +10 -6
  38. package/lib/repository/postquery/post-query.ts +282 -0
  39. package/{dist/repository/termquery/term-query-args.d.ts → lib/repository/termquery/term-query-args.ts} +16 -6
  40. package/lib/repository/termquery/term-query.ts +244 -0
  41. package/{dist/repository/userquery/user-query-args.d.ts → lib/repository/userquery/user-query-args.ts} +19 -7
  42. package/{dist/repository/userquery/user-query.js → lib/repository/userquery/user-query.ts} +93 -76
  43. package/{dist/router/helpers.js → lib/router/helpers.ts} +4 -4
  44. package/{dist/router/nextpress-layout.js → lib/router/nextpress-layout.tsx} +28 -9
  45. package/{dist/router/routes/not-found-page.js → lib/router/nextpress-not-found-route.tsx} +7 -5
  46. package/{dist/router/nextpress-proxy.js → lib/router/nextpress-proxy.ts} +15 -3
  47. package/{dist/router/nextpress-static-params.js → lib/router/nextpress-static-params.ts} +17 -5
  48. package/{dist/router/router.js → lib/router/router.tsx} +29 -22
  49. package/{dist/router/routes/api/api-get-admin-bar.js → lib/router/routes/api/api-get-admin-bar.ts} +8 -6
  50. package/{dist/router/routes/api/api-get-draft-mode.js → lib/router/routes/api/api-get-draft-mode.ts} +15 -6
  51. package/{dist/router/routes/api/api-get-field-groups.js → lib/router/routes/api/api-get-field-groups.ts} +13 -8
  52. package/{dist/router/routes/api/api-post-revalidate.js → lib/router/routes/api/api-post-revalidate.ts} +6 -4
  53. package/{dist/router/routes/api/helpers.js → lib/router/routes/api/helpers.ts} +4 -3
  54. package/lib/router/routes/author-archive.tsx +75 -0
  55. package/lib/router/routes/post-index-page.tsx +58 -0
  56. package/lib/router/routes/singular-page.tsx +78 -0
  57. package/lib/router/routes/site-front-page.tsx +51 -0
  58. package/lib/router/routes/term-archive.tsx +93 -0
  59. package/{dist/router/types.d.ts → lib/router/types.ts} +4 -2
  60. package/{dist/services/get-menu.js → lib/services/get-menu.ts} +56 -32
  61. package/{dist/services/get-theme-mods.js → lib/services/get-theme-mods.ts} +6 -4
  62. package/{dist/services/metadata/get-blogname.js → lib/services/metadata/get-blogname.ts} +2 -2
  63. package/{dist/services/metadata/get-favicon-url.js → lib/services/metadata/get-favicon-url.ts} +5 -4
  64. package/{dist/services/metadata/get-language-attribute.js → lib/services/metadata/get-language-attribute.ts} +1 -1
  65. package/{dist/services/utilities/capitalise-first-letter.js → lib/services/utilities/capitalise-first-letter.ts} +2 -3
  66. package/{dist/services/utilities/esc-html.js → lib/services/utilities/esc-html.ts} +3 -1
  67. package/{dist/services/utilities/get-date-time-formatter.js → lib/services/utilities/get-date-time-formatter.ts} +16 -6
  68. package/{dist/services/utilities/kses-post.js → lib/services/utilities/kses-post.ts} +2 -1
  69. package/{dist/services/utilities/process-url.js → lib/services/utilities/process-url.ts} +4 -3
  70. package/{dist/template-heirarchy/_autoloader/template-autoloader.js → lib/template-heirarchy/_autoloader/template-autoloader.ts} +18 -9
  71. package/{dist/template-heirarchy/archive/archive.js → lib/template-heirarchy/archive/archive.tsx} +10 -7
  72. package/{dist/template-heirarchy/archive/author.js → lib/template-heirarchy/archive/author.tsx} +10 -7
  73. package/{dist/template-heirarchy/archive/category.js → lib/template-heirarchy/archive/category.tsx} +11 -7
  74. package/{dist/template-heirarchy/archive/posttypearchive.js → lib/template-heirarchy/archive/posttypearchive.tsx} +11 -8
  75. package/{dist/template-heirarchy/archive/tag.js → lib/template-heirarchy/archive/tag.tsx} +12 -7
  76. package/{dist/template-heirarchy/archive/taxonomy.js → lib/template-heirarchy/archive/taxonomy.tsx} +10 -7
  77. package/{dist/template-heirarchy/home/home.js → lib/template-heirarchy/home/home.tsx} +10 -7
  78. package/{dist/template-heirarchy/index.js → lib/template-heirarchy/index.tsx} +9 -5
  79. package/{dist/template-heirarchy/not-found.tsx/not-found.js → lib/template-heirarchy/not-found.tsx/not-found.tsx} +10 -7
  80. package/{dist/template-heirarchy/page/page.js → lib/template-heirarchy/page/page.tsx} +10 -7
  81. package/{dist/template-heirarchy/page/posttype.js → lib/template-heirarchy/page/posttype.tsx} +12 -8
  82. package/{dist/template-heirarchy/page/single.js → lib/template-heirarchy/page/single.tsx} +10 -7
  83. package/{dist/template-heirarchy/page/singular.js → lib/template-heirarchy/page/singular.tsx} +10 -7
  84. package/lib/ui/render-attachment-image.tsx +28 -0
  85. package/lib/ui/render-components.tsx +12 -0
  86. package/lib/ui/render-the-admin-bar.tsx +79 -0
  87. package/lib/ui/render-the-logo.tsx +24 -0
  88. package/{dist/wpdb/wpdb.interface.d.ts → lib/wpdb/wpdb.interface.ts} +20 -1
  89. package/{dist/wpdb/wpdb.js → lib/wpdb/wpdb.ts} +9 -5
  90. package/package.json +8 -15
  91. package/dist/acf-functions/core/acf-builder.d.ts +0 -51
  92. package/dist/acf-functions/core/acf-component-autoloader.d.ts +0 -11
  93. package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +0 -10
  94. package/dist/acf-functions/field-props.d.ts +0 -196
  95. package/dist/acf-functions/field-props.js +0 -1
  96. package/dist/acf-functions/services/define-field-group.js +0 -10
  97. package/dist/acf-functions/services/define-layout.js +0 -10
  98. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +0 -2
  99. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +0 -18
  100. package/dist/acf-functions/services/map-fields/map-fields.d.ts +0 -21
  101. package/dist/acf-functions/types/acf-field-group.js +0 -1
  102. package/dist/acf-functions/types/acf-field.d.ts +0 -2813
  103. package/dist/acf-functions/types/acf-field.js +0 -1
  104. package/dist/acf-functions/types/acf-layout.d.ts +0 -19
  105. package/dist/acf-functions/types/acf-layout.js +0 -1
  106. package/dist/acf-functions/types/acf-values.js +0 -1
  107. package/dist/acf-functions/types/components/field-props.d.ts +0 -196
  108. package/dist/acf-functions/types/components/field-props.js +0 -1
  109. package/dist/acf-functions/types/components/nextpress-component.js +0 -1
  110. package/dist/entities/common.js +0 -1
  111. package/dist/entities/option/option.d.ts +0 -19
  112. package/dist/entities/option/option.interface.js +0 -2
  113. package/dist/entities/post/post.d.ts +0 -50
  114. package/dist/entities/post/post.interface.js +0 -2
  115. package/dist/entities/post/post.js +0 -184
  116. package/dist/entities/term/term.d.ts +0 -28
  117. package/dist/entities/term/term.interface.js +0 -1
  118. package/dist/entities/term/term.js +0 -67
  119. package/dist/entities/user/user.d.ts +0 -27
  120. package/dist/entities/user/user.interface.js +0 -1
  121. package/dist/entities/user/user.js +0 -74
  122. package/dist/globals/entity-loader/entity-loader-base.d.ts +0 -65
  123. package/dist/globals/entity-loader/entity-loader.interface.js +0 -1
  124. package/dist/globals/entity-loader/option-loader.d.ts +0 -15
  125. package/dist/globals/entity-loader/option-loader.js +0 -31
  126. package/dist/globals/entity-loader/post-loader.d.ts +0 -21
  127. package/dist/globals/entity-loader/post-loader.js +0 -28
  128. package/dist/globals/entity-loader/term-loader.d.ts +0 -21
  129. package/dist/globals/entity-loader/term-loader.js +0 -28
  130. package/dist/globals/entity-loader/user-loader.d.ts +0 -21
  131. package/dist/globals/entity-loader/user-loader.js +0 -28
  132. package/dist/globals/get-field/get-field.d.ts +0 -18
  133. package/dist/globals/get-field/get-field.js +0 -44
  134. package/dist/globals/globals.d.ts +0 -18
  135. package/dist/globals/nextpress-config/nextpress-config.d.ts +0 -4
  136. package/dist/globals/nextpress-config/nextpress-config.interface.js +0 -1
  137. package/dist/globals/nextpress-config/nextpress-config.js +0 -2
  138. package/dist/globals/queried-object/queried-object.d.ts +0 -62
  139. package/dist/globals/queried-object/queried-object.js +0 -56
  140. package/dist/repository/optionquery/option-query-args.js +0 -1
  141. package/dist/repository/optionquery/option-query.d.ts +0 -12
  142. package/dist/repository/optionquery/option-query.js +0 -20
  143. package/dist/repository/postquery/post-query-args.js +0 -1
  144. package/dist/repository/postquery/post-query.d.ts +0 -12
  145. package/dist/repository/postquery/post-query.js +0 -272
  146. package/dist/repository/termquery/term-query-args.js +0 -1
  147. package/dist/repository/termquery/term-query.d.ts +0 -11
  148. package/dist/repository/termquery/term-query.js +0 -213
  149. package/dist/repository/userquery/user-query-args.js +0 -1
  150. package/dist/repository/userquery/user-query.d.ts +0 -12
  151. package/dist/router/helpers.d.ts +0 -14
  152. package/dist/router/nextpress-layout.d.ts +0 -11
  153. package/dist/router/nextpress-proxy.d.ts +0 -8
  154. package/dist/router/nextpress-static-params.d.ts +0 -9
  155. package/dist/router/router.d.ts +0 -23
  156. package/dist/router/routes/api/api-get-admin-bar.d.ts +0 -8
  157. package/dist/router/routes/api/api-get-draft-mode.d.ts +0 -8
  158. package/dist/router/routes/api/api-get-field-groups.d.ts +0 -7
  159. package/dist/router/routes/api/api-post-revalidate.d.ts +0 -7
  160. package/dist/router/routes/api/helpers.d.ts +0 -8
  161. package/dist/router/routes/author-archive.d.ts +0 -25
  162. package/dist/router/routes/author-archive.js +0 -49
  163. package/dist/router/routes/not-found-page.d.ts +0 -15
  164. package/dist/router/routes/post-index-page.d.ts +0 -25
  165. package/dist/router/routes/post-index-page.js +0 -33
  166. package/dist/router/routes/singular-page.d.ts +0 -29
  167. package/dist/router/routes/singular-page.js +0 -51
  168. package/dist/router/routes/site-front-page.d.ts +0 -27
  169. package/dist/router/routes/site-front-page.js +0 -26
  170. package/dist/router/routes/term-archive.d.ts +0 -29
  171. package/dist/router/routes/term-archive.js +0 -65
  172. package/dist/router/types.js +0 -1
  173. package/dist/services/get-menu.d.ts +0 -13
  174. package/dist/services/get-theme-mods.d.ts +0 -7
  175. package/dist/services/metadata/get-blogname.d.ts +0 -6
  176. package/dist/services/metadata/get-favicon-url.d.ts +0 -6
  177. package/dist/services/metadata/get-language-attribute.d.ts +0 -6
  178. package/dist/services/services.d.ts +0 -3
  179. package/dist/services/services.js +0 -3
  180. package/dist/services/utilities/capitalise-first-letter.d.ts +0 -7
  181. package/dist/services/utilities/esc-html.d.ts +0 -7
  182. package/dist/services/utilities/get-date-time-formatter.d.ts +0 -6
  183. package/dist/services/utilities/index.d.ts +0 -0
  184. package/dist/services/utilities/index.js +0 -1
  185. package/dist/services/utilities/kses-post.d.ts +0 -7
  186. package/dist/services/utilities/process-url.d.ts +0 -7
  187. package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +0 -9
  188. package/dist/template-heirarchy/archive/archive.d.ts +0 -16
  189. package/dist/template-heirarchy/archive/author.d.ts +0 -16
  190. package/dist/template-heirarchy/archive/category.d.ts +0 -16
  191. package/dist/template-heirarchy/archive/posttypearchive.d.ts +0 -24
  192. package/dist/template-heirarchy/archive/tag.d.ts +0 -16
  193. package/dist/template-heirarchy/archive/taxonomy.d.ts +0 -16
  194. package/dist/template-heirarchy/home/home.d.ts +0 -16
  195. package/dist/template-heirarchy/index.d.ts +0 -17
  196. package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +0 -16
  197. package/dist/template-heirarchy/page/page.d.ts +0 -16
  198. package/dist/template-heirarchy/page/posttype.d.ts +0 -24
  199. package/dist/template-heirarchy/page/single.d.ts +0 -16
  200. package/dist/template-heirarchy/page/singular.d.ts +0 -16
  201. package/dist/ui/render-attachment-image.d.ts +0 -12
  202. package/dist/ui/render-attachment-image.js +0 -24
  203. package/dist/ui/render-components.d.ts +0 -9
  204. package/dist/ui/render-components.js +0 -7
  205. package/dist/ui/render-the-admin-bar.d.ts +0 -8
  206. package/dist/ui/render-the-admin-bar.js +0 -36
  207. package/dist/ui/render-the-logo.d.ts +0 -10
  208. package/dist/ui/render-the-logo.js +0 -16
  209. package/dist/wpdb/wpdb.d.ts +0 -3
  210. package/dist/wpdb/wpdb.interface.js +0 -5
  211. /package/{dist/acf-functions/types/acf-values.d.ts → lib/acf-functions/types/acf-values.ts} +0 -0
@@ -1,20 +1,22 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { NotFoundMetadata, NotFoundTemplate } from "@/template-heirarchy/not-found.tsx/not-found";
1
+ import { Metadata } from "next";
2
+ import { NotFoundMetadata, NotFoundTemplate } from "nextpress/template-heirarchy/not-found.tsx/not-found";
3
+
3
4
  /**
4
5
  * Generates the metadata for the generic Not Found page.
5
6
  * Maps to the Nextpress `NotFoundMetadata` which falls back to `IndexMetadata`.
6
7
  *
7
8
  * @returns {Promise<Metadata>} The generated metadata object.
8
9
  */
9
- export async function notFoundMetadata() {
10
+ export async function NextpressNotFoundMetadata(): Promise<Metadata> {
10
11
  return await NotFoundMetadata();
11
12
  }
13
+
12
14
  /**
13
15
  * Default Not Found component to handle unmatched routes.
14
16
  * Maps to the Nextpress `NotFoundTemplate` which defaults back to `IndexTemplate` if not defined.
15
17
  *
16
18
  * @returns {Promise<JSX.Element>} The rendered Not Found template.
17
19
  */
18
- export async function NotFoundPage() {
19
- return _jsx(NotFoundTemplate, {});
20
+ export async function NextpressNotFoundRoute() {
21
+ return <NotFoundTemplate/>
20
22
  }
@@ -1,18 +1,22 @@
1
- import { NextResponse } from "next/server";
1
+ import { NextRequest, NextResponse } from "next/server";
2
+
2
3
  /**
3
4
  * Processes incoming requests to manage WordPress session cookies and redirects.
4
5
  *
5
6
  * @param {NextRequest} request - Incoming request.
6
7
  * @returns {NextResponse} Response to proceed or redirect.
7
8
  */
8
- export function nextpressProxy(request) {
9
+ export function nextpressProxy(request: NextRequest): NextResponse {
9
10
  const url = request.nextUrl;
11
+
10
12
  if (url.pathname.startsWith('/api/draft')) {
11
13
  return NextResponse.next();
12
14
  }
15
+
13
16
  if (url.searchParams.has('nextpress_logged_in_user_id')) {
14
17
  const loggedInUserId = url.searchParams.get('nextpress_logged_in_user_id');
15
18
  url.searchParams.delete('nextpress_logged_in_user_id');
19
+
16
20
  const response = NextResponse.redirect(url);
17
21
  response.cookies.set('nextpress_logged_in_user_id', loggedInUserId || '0');
18
22
  return response;
@@ -20,14 +24,22 @@ export function nextpressProxy(request) {
20
24
  if (request.cookies.has('nextpress_logged_in_user_id')) {
21
25
  return NextResponse.next();
22
26
  }
27
+
23
28
  const cookies = request.cookies;
24
- const hasWordpressCookie = cookies.getAll().some(cookie => cookie.name.startsWith('wordpress_logged_in_'));
29
+
30
+ const hasWordpressCookie = cookies.getAll().some(cookie =>
31
+ cookie.name.startsWith('wordpress_logged_in_')
32
+ );
33
+
25
34
  if (hasWordpressCookie) {
26
35
  const currentPath = url.pathname + url.search;
36
+
27
37
  const redirectUrl = url.clone();
28
38
  redirectUrl.pathname = '/api/draft';
29
39
  redirectUrl.searchParams.set('redirect', currentPath);
40
+
30
41
  return NextResponse.redirect(redirectUrl);
31
42
  }
43
+
32
44
  return NextResponse.next();
33
45
  }
@@ -1,13 +1,17 @@
1
1
  import { splitPath } from "./helpers";
2
+ import { NextpressRouterProps } from "./router";
3
+
4
+ export type NextpressStaticParams = Awaited<NextpressRouterProps['params']>[];
5
+
2
6
  const { publicPostTypes, archivedPostTypes } = nextpressConfig;
7
+
3
8
  /**
4
9
  * Generates static parameters for Next.js build-time prerendering.
5
10
  * Queries authors, terms, and posts to generate a comprehensive list of all active routes.
6
11
  *
7
12
  * @returns {NextpressStaticParams} An array containing the route parameters to be generated statically.
8
13
  */
9
- export async function nextpressStaticParams() {
10
- var _a;
14
+ export async function nextpressStaticParams(): Promise<NextpressStaticParams> {
11
15
  const { ids: authorIds } = await userLoader.findAndPrime({
12
16
  hasPublishedPosts: true,
13
17
  noFoundRows: false,
@@ -15,28 +19,35 @@ export async function nextpressStaticParams() {
15
19
  });
16
20
  const authors = await getUsers(authorIds);
17
21
  const authorPaths = authors.map((author) => ['author', author.userLogin]);
22
+
18
23
  const { ids: termIds } = await termLoader.findAndPrime({});
19
24
  const terms = await getTerms(termIds);
20
25
  const termPaths = terms.map(term => [term.taxonomy, ...splitPath(term.path)]);
26
+
21
27
  const { ids: archivedPostIds } = await postLoader.findAndPrime({
22
28
  postStatus: 'publish',
23
- postType: (_a = archivedPostTypes === null || archivedPostTypes === void 0 ? void 0 : archivedPostTypes.filter(p => !(publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.includes(p)))) !== null && _a !== void 0 ? _a : 'post',
29
+ postType: archivedPostTypes?.filter(p => !publicPostTypes?.includes(p)) ?? 'post',
24
30
  ignoreStickyPosts: true,
25
31
  noFoundRows: true,
26
32
  noPaging: true,
27
33
  });
28
34
  const { ids: postIds } = await postLoader.findAndPrime({
29
35
  postStatus: 'publish',
30
- postType: archivedPostTypes !== null && archivedPostTypes !== void 0 ? archivedPostTypes : 'post',
36
+ postType: archivedPostTypes ?? 'post',
31
37
  ignoreStickyPosts: true,
32
38
  noFoundRows: true,
33
39
  noPaging: true,
34
40
  });
41
+
35
42
  const archivedPosts = await getPosts(archivedPostIds);
36
43
  const posts = await getPosts(postIds);
44
+
37
45
  const archivedPostsPaths = archivedPosts.map(post => splitPath(post.path));
38
- const archivedPostArchivePaths = (archivedPostTypes !== null && archivedPostTypes !== void 0 ? archivedPostTypes : []).map(type => [type]);
46
+
47
+ const archivedPostArchivePaths = (archivedPostTypes ?? []).map(type => [type]);
48
+
39
49
  const postPaths = posts.map(post => splitPath(post.path));
50
+
40
51
  const allPaths = [
41
52
  ...authorPaths,
42
53
  ...termPaths,
@@ -44,6 +55,7 @@ export async function nextpressStaticParams() {
44
55
  ...archivedPostArchivePaths,
45
56
  ...postPaths
46
57
  ];
58
+
47
59
  return allPaths.map(segments => ({
48
60
  path: segments.filter(Boolean)
49
61
  }));
@@ -1,10 +1,17 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import "../globals/globals";
1
+ import { Metadata } from "next";
3
2
  import { AuthorArchive } from "./routes/author-archive";
4
3
  import { SingularPage } from "./routes/singular-page";
5
4
  import { SiteFrontPage } from "./routes/site-front-page";
6
5
  import { TermArchive } from "./routes/term-archive";
6
+
7
+ export type NextpressRouterProps = {
8
+ params: Promise<{
9
+ path: string[] | undefined;
10
+ }>;
11
+ }
12
+
7
13
  const { publicTaxonomies } = nextpressConfig;
14
+
8
15
  /**
9
16
  * Generates metadata dynamically for a given request path.
10
17
  * Routes the path to the correct Nextpress routing function based on the configuration logic.
@@ -12,22 +19,22 @@ const { publicTaxonomies } = nextpressConfig;
12
19
  * @param {NextpressRouterProps} props - The dynamic properties for this page route.
13
20
  * @returns {Promise<Metadata>} The Metadata object for the matched route.
14
21
  */
15
- export async function generateNextpressMetadata({ params }) {
16
- var _a;
17
- const path = (_a = (await params).path) !== null && _a !== void 0 ? _a : [];
22
+ export async function generateNextpressMetadata({ params }: NextpressRouterProps): Promise<Metadata> {
23
+ const path = (await params).path ?? [];
24
+
18
25
  if (!path.length) {
19
- return await SiteFrontPage({ path, metadata: true });
26
+ return await SiteFrontPage({path, metadata: true});
20
27
  }
21
- if (publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.includes(path[0])) {
22
- return await TermArchive({ path, metadata: true });
28
+ if (publicTaxonomies?.includes(path[0]!)) {
29
+ return await TermArchive({path, metadata: true});
23
30
  }
24
31
  if (path[0] === 'author') {
25
- return await AuthorArchive({ path, metadata: true });
26
- }
27
- else {
28
- return await SingularPage({ path, metadata: true });
32
+ return await AuthorArchive({path, metadata: true});
33
+ } else {
34
+ return await SingularPage({path, metadata: true});
29
35
  }
30
36
  }
37
+
31
38
  /**
32
39
  * The main catch-all Page component that renders the layout for matched routes.
33
40
  * Routes the path to the correct Nextpress routing component to return a template.
@@ -35,19 +42,19 @@ export async function generateNextpressMetadata({ params }) {
35
42
  * @param {NextpressRouterProps} props - The dynamic properties for this page route.
36
43
  * @returns {Promise<JSX.Element>} The rendered React component mapping to the matched route's template.
37
44
  */
38
- export default async function NextPressPage({ params }) {
39
- var _a;
40
- const path = (_a = (await params).path) !== null && _a !== void 0 ? _a : [];
45
+ export async function NextPressPage({ params }: NextpressRouterProps) {
46
+ const path = (await params).path ?? [];
47
+
41
48
  if (!path.length) {
42
- return _jsx(SiteFrontPage, { path: path });
49
+ return <SiteFrontPage path={path}/>
43
50
  }
44
- if (publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.includes(path[0])) {
45
- return _jsx(TermArchive, { path: path });
51
+ if (publicTaxonomies?.includes(path[0]!)) {
52
+ return <TermArchive path={path}/>
46
53
  }
47
54
  if (path[0] === 'author') {
48
- return _jsx(AuthorArchive, { path: path });
49
- }
50
- else {
51
- return _jsx(SingularPage, { path: path });
55
+ return <AuthorArchive path={path}/>
56
+ } else {
57
+ return <SingularPage path={path}/>
52
58
  }
53
59
  }
60
+
@@ -1,26 +1,28 @@
1
- import { NextResponse } from "next/server";
1
+ import { NextRequest, NextResponse } from "next/server";
2
+
2
3
  /**
3
4
  * Processes GET requests to fetch WordPress admin bar data.
4
5
  *
5
6
  * @param {NextRequest} request - Incoming request.
6
7
  * @returns {Promise<NextResponse>} Response containing admin bar data or error.
7
8
  */
8
- export async function apiGetAdminBar(request) {
9
+ export async function apiGetAdminBar(request: NextRequest): Promise<NextResponse> {
9
10
  const { searchParams } = new URL(request.url);
10
11
  const userId = searchParams.get('user_id');
11
12
  const path = searchParams.get('path');
13
+
12
14
  try {
13
15
  const response = await fetch(`${process.env.WP_SERVICE_URL}/wp-json/nextpress/v1/get-admin-bar?user_id=${userId}&path=${path}`, {
14
16
  headers: {
15
17
  'Authorization': `api-key ${process.env.CROSS_CONTAINER_API_KEY}`
16
18
  }
17
19
  });
18
- if (!response.ok)
19
- return NextResponse.json({ error: 'Failed to fetch from WP' }, { status: response.status });
20
+
21
+ if (!response.ok) return NextResponse.json({ error: 'Failed to fetch from WP' }, { status: response.status });
22
+
20
23
  const data = await response.json();
21
24
  return NextResponse.json(data);
22
- }
23
- catch (error) {
25
+ } catch (error: any) {
24
26
  console.error(error.message);
25
27
  return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
26
28
  }
@@ -1,38 +1,47 @@
1
1
  import { draftMode } from 'next/headers';
2
2
  import { redirect } from 'next/navigation';
3
+ import { NextRequest } from "next/server";
4
+
3
5
  /**
4
6
  * Processes GET requests to validate WordPress session and enable draft mode.
5
7
  *
6
8
  * @param {NextRequest} request - Incoming request.
7
9
  * @returns {Promise<never>} Redirects to target URL.
8
10
  */
9
- export async function apiGetDraftMode(request) {
11
+ export async function apiGetDraftMode(request: NextRequest): Promise<never> {
10
12
  const { searchParams } = new URL(request.url);
11
13
  const redirectUrl = searchParams.get('redirect') || '/';
14
+
12
15
  const draft = await draftMode();
16
+
13
17
  const cookies = request.cookies.getAll();
14
18
  const wpCookie = cookies.find(cookie => cookie.name.startsWith('wordpress_logged_in_'));
19
+
15
20
  let userId = 0;
16
- if (!(wpCookie === null || wpCookie === void 0 ? void 0 : wpCookie.value)) {
21
+
22
+ if (!wpCookie?.value) {
17
23
  console.warn('Wordpress login cookie missing.');
18
24
  draft.disable();
19
25
  redirect(redirectUrl + `?nextpress_logged_in_user_id=${userId}`);
20
26
  }
27
+
21
28
  try {
22
29
  const validLogin = await fetch(`${process.env.WP_SERVICE_URL}/wp-json/nextpress/v1/validate-user-session/?user_hash=${wpCookie.value}`, {
23
30
  headers: {
24
31
  'Authorization': `api-key ${process.env.CROSS_CONTAINER_API_KEY}`
25
32
  }
26
33
  });
27
- if (!validLogin.ok)
28
- throw new Error(`Validation failed with status code: ${validLogin.status}`);
34
+
35
+ if (!validLogin.ok) throw new Error(`Validation failed with status code: ${validLogin.status}`);
36
+
29
37
  const response = await validLogin.json();
30
38
  userId = Number(response.user_id) || 0;
39
+
31
40
  draft.enable();
32
- }
33
- catch (error) {
41
+ } catch (error: any) {
34
42
  console.warn('Could not validate Wordpress login:', error.message);
35
43
  draft.disable();
36
44
  }
45
+
37
46
  redirect(redirectUrl + `?nextpress_logged_in_user_id=${userId}`);
38
47
  }
@@ -1,24 +1,29 @@
1
1
  import { headers } from "next/headers";
2
2
  import { NextResponse } from "next/server";
3
3
  import { isAuthorized } from "./helpers";
4
- import { acfFieldGroupAutoloader } from "@/acf-functions/core/acf-field-group-autoloader";
5
- import { ACFBuilder } from "@/acf-functions/core/acf-builder";
4
+ import { acfFieldGroupAutoloader } from "nextpress/acf-functions/core/acf-field-group-autoloader";
5
+ import { ACFBuilder } from "nextpress/acf-functions/core/acf-builder";
6
+
6
7
  /**
7
8
  * Processes GET requests to retrieve built ACF field groups.
8
9
  *
9
10
  * @returns {Promise<NextResponse>} Response containing field groups or error.
10
11
  */
11
- export async function apiGetFieldGroups() {
12
+ export async function apiGetFieldGroups(): Promise<NextResponse> {
12
13
  if (!isAuthorized(await headers())) {
13
- return NextResponse.json('Unauthorized access', { status: 403 });
14
+ return NextResponse.json('Unauthorized access', { status: 403 })
14
15
  }
16
+
15
17
  try {
16
18
  const fieldGroups = await acfFieldGroupAutoloader();
17
19
  const acfBuilder = new ACFBuilder().registerFieldGroups(fieldGroups);
20
+
18
21
  return NextResponse.json(acfBuilder.getFieldGroups(), { status: 200 });
19
- }
20
- catch (error) {
21
- console.error('Field Group API:', error.message);
22
- return NextResponse.json({ message: 'Error building ACF fields', error: String(error) }, { status: 500 });
22
+ } catch (error: any) {
23
+ console.error('Field Group API:', error.message)
24
+ return NextResponse.json(
25
+ { message: 'Error building ACF fields', error: String(error) },
26
+ { status: 500 }
27
+ );
23
28
  }
24
29
  }
@@ -2,23 +2,25 @@ import { revalidatePath } from "next/cache";
2
2
  import { headers } from "next/headers";
3
3
  import { NextResponse } from "next/server";
4
4
  import { isAuthorized } from "./helpers";
5
+
5
6
  /**
6
7
  * Processes POST requests to revalidate root layout path.
7
8
  *
8
9
  * @returns {Promise<NextResponse>} Response indicating success or error.
9
10
  */
10
- export async function apiPostRevalidate() {
11
+ export async function apiPostRevalidate(): Promise<NextResponse> {
11
12
  if (!isAuthorized(await headers())) {
12
- return NextResponse.json('Unauthorized access', { status: 403 });
13
+ return NextResponse.json('Unauthorized access', { status: 403 })
13
14
  }
14
15
  try {
15
16
  revalidatePath('/', 'layout');
17
+
16
18
  return NextResponse.json({
17
19
  success: true,
18
20
  message: 'Saving and revalidation successful'
19
21
  }, { status: 200 });
20
- }
21
- catch (error) {
22
+
23
+ } catch (error) {
22
24
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
23
25
  return NextResponse.json({
24
26
  success: false,
@@ -1,16 +1,17 @@
1
+ import { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
2
+
1
3
  /**
2
4
  * Checks if request is authorized using API key.
3
5
  *
4
6
  * @param {ReadonlyHeaders} headerList - Headers from request.
5
7
  * @returns {boolean} True if authorized, false otherwise.
6
8
  */
7
- export function isAuthorized(headerList) {
9
+ export function isAuthorized(headerList: ReadonlyHeaders): boolean {
8
10
  const authHeader = headerList.get('Authorization');
9
11
  if (authHeader && authHeader.startsWith('api-key ')) {
10
12
  const apiKey = authHeader.split(' ')[1];
11
13
  return apiKey === process.env.CROSS_CONTAINER_API_KEY;
12
- }
13
- else {
14
+ } else {
14
15
  return false;
15
16
  }
16
17
  }
@@ -0,0 +1,75 @@
1
+ import { MetadataResult, RouteProps, TemplateResult } from "../types";
2
+ import { getPageNumber } from "../helpers";
3
+ import { notFound } from "next/navigation";
4
+ import { queriedObjectState } from "nextpress/globals/globals";
5
+ import { AuthorMetadata, AuthorTemplate } from "nextpress/template-heirarchy/archive/author";
6
+
7
+ /**
8
+ * Resolves the author archive route and maps it to the template hierarchy to return Metadata.
9
+ * * Routing Behavior:
10
+ * - Unconditionally routes to `AuthorMetadata`.
11
+ *
12
+ * @param {{ path: string[], metadata: true }} props - Route properties requesting metadata.
13
+ * @returns {Promise<MetadataResult>} The generated metadata.
14
+ */
15
+ export function AuthorArchive(props: { path: string[], metadata: true }): Promise<MetadataResult>;
16
+
17
+ /**
18
+ * Resolves the author archive route and maps it to the template hierarchy to return a Template.
19
+ * * Routing Behavior:
20
+ * - Unconditionally routes to `AuthorTemplate`.
21
+ *
22
+ * @param {{ path: string[], metadata?: false }} props - Route properties requesting a template.
23
+ * @returns {Promise<TemplateResult>} The rendered template component.
24
+ */
25
+ export function AuthorArchive(props: { path: string[], metadata?: false }): Promise<TemplateResult>;
26
+
27
+ /**
28
+ * Core implementation for the author archive route.
29
+ * Retrieves posts published by a specific author and updates the queried object state.
30
+ *
31
+ * @param {RouteProps} props - Route properties including the path array and metadata flag.
32
+ * @returns {Promise<MetadataResult | TemplateResult>} The metadata or template result based on the hierarchy.
33
+ * @throws {Error} Throws a Next.js notFound error if the author is not found.
34
+ */
35
+ export async function AuthorArchive({ path, metadata = false }: RouteProps) {
36
+ const postsPerPage = Number(await getOption('posts_per_page')) ?? 10;
37
+
38
+ const page = getPageNumber(path) || 1;
39
+
40
+ const login = path[1];
41
+ if (!login) notFound();
42
+
43
+ const userQuery = await userLoader.findAndPrime({
44
+ login: login,
45
+ multiple: false,
46
+ noFoundRows: true
47
+ });
48
+
49
+ const user = await getUser(userQuery.ids[0] ?? 0)
50
+ if (!user) notFound();
51
+
52
+ const postIds = await postLoader.findAndPrime({
53
+ authorId: user.ID,
54
+ noFoundRows: false,
55
+ noPaging: false,
56
+ postType: 'post',
57
+ page: page,
58
+ postsPerPage: postsPerPage,
59
+ postStatus: 'publish',
60
+ orderBy: 'date'
61
+ });
62
+
63
+ const currentQueriedObject = {
64
+ objectType: 'user',
65
+ posts: postIds.ids,
66
+ page,
67
+ pageCount: Math.ceil(postIds.count / postsPerPage),
68
+ user: user.ID
69
+ }
70
+
71
+ const state = queriedObjectState();
72
+ state.currentState = currentQueriedObject;
73
+
74
+ return metadata ? await AuthorMetadata() : <AuthorTemplate/>;
75
+ }
@@ -0,0 +1,58 @@
1
+ import { MetadataResult, RouteProps, TemplateResult } from "../types";
2
+ import { getPageNumber } from "../helpers";
3
+ import { queriedObjectState } from "nextpress/globals/globals";
4
+ import { HomeMetadata, HomeTemplate } from "nextpress/template-heirarchy/home/home";
5
+
6
+ /**
7
+ * Resolves the post index page (blog home) route and maps it to the template hierarchy to return Metadata.
8
+ * * Routing Behavior:
9
+ * - Unconditionally routes to `HomeMetadata`.
10
+ *
11
+ * @param {{ path: string[], metadata: true }} props - Route properties requesting metadata.
12
+ * @returns {Promise<MetadataResult>} The generated metadata.
13
+ */
14
+ export function PostIndexPage(props: { path: string[], metadata: true }): Promise<MetadataResult>;
15
+
16
+ /**
17
+ * Resolves the post index page (blog home) route and maps it to the template hierarchy to return a Template.
18
+ * * Routing Behavior:
19
+ * - Unconditionally routes to `HomeTemplate`.
20
+ *
21
+ * @param {{ path: string[], metadata?: false }} props - Route properties requesting a template.
22
+ * @returns {Promise<TemplateResult>} The rendered template component.
23
+ */
24
+ export function PostIndexPage(props: { path: string[], metadata?: false }): Promise<TemplateResult>;
25
+
26
+ /**
27
+ * Core implementation for the post index page route.
28
+ * Fetches the paginated list of all published posts and updates the queried object state.
29
+ *
30
+ * @param {RouteProps} props - Route properties including the path array and metadata flag.
31
+ * @returns {Promise<MetadataResult | TemplateResult>} The metadata or template result based on the hierarchy.
32
+ */
33
+ export async function PostIndexPage({ path, metadata = false }: RouteProps) {
34
+ const page = getPageNumber(path) || 1;
35
+ const postsPerPage = Number(await getOption('posts_per_page')) ?? 10;
36
+
37
+ const postIds = await postLoader.findAndPrime({
38
+ noFoundRows: false,
39
+ noPaging: false,
40
+ postType: 'post',
41
+ page: page,
42
+ postsPerPage: postsPerPage,
43
+ postStatus: 'publish',
44
+ orderBy: 'date'
45
+ });
46
+
47
+ const currentQueriedObject = {
48
+ posts: postIds.ids,
49
+ page,
50
+ pageCount: postIds.count / postsPerPage
51
+ }
52
+
53
+ const state = queriedObjectState();
54
+ state.currentState = currentQueriedObject;
55
+
56
+ return metadata ? await HomeMetadata() : <HomeTemplate/>;
57
+ }
58
+
@@ -0,0 +1,78 @@
1
+ import { MetadataResult, RouteProps, TemplateResult } from "../types";
2
+ import { PostIndexPage } from "./post-index-page";
3
+ import { getPageNumber } from "../helpers";
4
+ import { notFound } from "next/navigation";
5
+ import { queriedObjectState } from "nextpress/globals/globals";
6
+ import { SingleMetadata, SingleTemplate } from "nextpress/template-heirarchy/page/single";
7
+ import { PageMetadata, PageTemplate } from "nextpress/template-heirarchy/page/page";
8
+
9
+ /**
10
+ * Resolves the singular page route and maps it to the template hierarchy to return Metadata.
11
+ * * Routing Behavior:
12
+ * - If the post_type is 'post', it routes to `SingleMetadata`.
13
+ * - If the post ID matches the 'page_for_posts' option, it delegates routing to `PostIndexPage`.
14
+ * - Otherwise, it defaults to routing to `PageMetadata`.
15
+ *
16
+ * @param {{ path: string[], metadata: true }} props - Route properties requesting metadata.
17
+ * @returns {Promise<MetadataResult>} The generated metadata.
18
+ */
19
+ export function SingularPage(props: { path: string[], metadata: true }): Promise<MetadataResult>;
20
+
21
+ /**
22
+ * Resolves the singular page route and maps it to the template hierarchy to return a Template.
23
+ * * Routing Behavior:
24
+ * - If the post_type is 'post', it routes to `SingleTemplate`.
25
+ * - If the post ID matches the 'page_for_posts' option, it delegates routing to `PostIndexPage`.
26
+ * - Otherwise, it defaults to routing to `PageTemplate`.
27
+ *
28
+ * @param {{ path: string[], metadata?: false }} props - Route properties requesting a template.
29
+ * @returns {Promise<TemplateResult>} The rendered template component.
30
+ */
31
+ export function SingularPage(props: { path: string[], metadata?: false }): Promise<TemplateResult>;
32
+
33
+ /**
34
+ * Core implementation for the singular page/post route.
35
+ * Resolves the path to a specific post ID and updates the queried object state.
36
+ *
37
+ * @param {RouteProps} props - Route properties including the path array and metadata flag.
38
+ * @returns {Promise<MetadataResult | TemplateResult>} The metadata or template result based on the hierarchy.
39
+ * @throws {Error} Throws a Next.js notFound error if the path does not match any post or page.
40
+ */
41
+ export async function SingularPage({ path, metadata = false }: RouteProps) {
42
+ let page = getPageNumber(path);
43
+ if (page) {
44
+ path = path.slice(0, -2);
45
+ } else {
46
+ page = 1;
47
+ }
48
+
49
+ const postId = (await postLoader.findAndPrime({
50
+ path: `/${path.join('/')}`,
51
+ multiple: false,
52
+ noFoundRows: true,
53
+ noPaging: true,
54
+ ignoreStickyPosts: true,
55
+ })).ids[0];
56
+ if (!postId) notFound();
57
+
58
+ const post = await getPost(postId) ?? notFound()
59
+
60
+ const postType = post.postType
61
+
62
+ const currentQueriedObject = {
63
+ objectType: 'post',
64
+ posts: [postId]
65
+ }
66
+ const state = queriedObjectState();
67
+ state.currentState = currentQueriedObject;
68
+
69
+ if (postType === 'post') {
70
+ return metadata ? await SingleMetadata() : <SingleTemplate/>;
71
+ }
72
+ if (post.ID !== Number(await getOption('page_for_posts'))) {
73
+ return metadata ? await PageMetadata() : <PageTemplate/>;
74
+ } else {
75
+ return metadata ? await PostIndexPage({path, metadata: true}) : <PostIndexPage path={path}/>
76
+ }
77
+ }
78
+