@btst/stack 1.1.6 → 1.1.8

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 (37) hide show
  1. package/dist/packages/better-stack/src/plugins/blog/api/plugin.cjs +29 -34
  2. package/dist/packages/better-stack/src/plugins/blog/api/plugin.mjs +29 -34
  3. package/dist/packages/better-stack/src/plugins/blog/client/components/pages/post-page.internal.cjs +3 -3
  4. package/dist/packages/better-stack/src/plugins/blog/client/components/pages/post-page.internal.mjs +4 -4
  5. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/default-error.cjs +1 -1
  6. package/dist/packages/better-stack/src/plugins/blog/client/components/shared/default-error.mjs +1 -1
  7. package/dist/packages/better-stack/src/plugins/blog/client/hooks/blog-hooks.cjs +16 -16
  8. package/dist/packages/better-stack/src/plugins/blog/client/hooks/blog-hooks.mjs +16 -16
  9. package/dist/packages/better-stack/src/plugins/blog/client/plugin.cjs +50 -8
  10. package/dist/packages/better-stack/src/plugins/blog/client/plugin.mjs +50 -8
  11. package/dist/plugins/blog/api/index.d.cts +1 -1
  12. package/dist/plugins/blog/api/index.d.mts +1 -1
  13. package/dist/plugins/blog/api/index.d.ts +1 -1
  14. package/dist/plugins/blog/client/hooks/index.d.cts +3 -3
  15. package/dist/plugins/blog/client/hooks/index.d.mts +3 -3
  16. package/dist/plugins/blog/client/hooks/index.d.ts +3 -3
  17. package/dist/plugins/blog/client/index.d.cts +11 -4
  18. package/dist/plugins/blog/client/index.d.mts +11 -4
  19. package/dist/plugins/blog/client/index.d.ts +11 -4
  20. package/dist/plugins/blog/query-keys.cjs +19 -13
  21. package/dist/plugins/blog/query-keys.d.cts +6 -6
  22. package/dist/plugins/blog/query-keys.d.mts +6 -6
  23. package/dist/plugins/blog/query-keys.d.ts +6 -6
  24. package/dist/plugins/blog/query-keys.mjs +19 -13
  25. package/dist/plugins/blog/style.css +2 -5
  26. package/package.json +3 -3
  27. package/src/plugins/blog/api/plugin.ts +56 -36
  28. package/src/plugins/blog/client/components/pages/post-page.internal.tsx +4 -4
  29. package/src/plugins/blog/client/components/shared/default-error.tsx +4 -1
  30. package/src/plugins/blog/client/hooks/blog-hooks.tsx +16 -16
  31. package/src/plugins/blog/client/overrides.ts +4 -0
  32. package/src/plugins/blog/client/plugin.tsx +67 -11
  33. package/src/plugins/blog/query-keys.ts +13 -3
  34. package/src/plugins/blog/style.css +2 -5
  35. package/dist/shared/{stack.CbuN2zVV.d.cts → stack.CoPoHVfV.d.cts} +2 -2
  36. package/dist/shared/{stack.CbuN2zVV.d.mts → stack.CoPoHVfV.d.mts} +2 -2
  37. package/dist/shared/{stack.CbuN2zVV.d.ts → stack.CoPoHVfV.d.ts} +2 -2
@@ -482,15 +482,12 @@ const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
482
482
  }
483
483
  }
484
484
  const date = query.date;
485
- const previousPost = await adapter.findMany({
485
+ const targetTime = new Date(date).getTime();
486
+ const WINDOW_SIZE = 100;
487
+ const allPosts = await adapter.findMany({
486
488
  model: "post",
487
- limit: 1,
489
+ limit: WINDOW_SIZE,
488
490
  where: [
489
- {
490
- field: "createdAt",
491
- value: date,
492
- operator: "lt"
493
- },
494
491
  {
495
492
  field: "published",
496
493
  value: true,
@@ -502,29 +499,27 @@ const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
502
499
  direction: "desc"
503
500
  }
504
501
  });
505
- const nextPost = await adapter.findMany({
506
- model: "post",
507
- limit: 1,
508
- where: [
509
- {
510
- field: "createdAt",
511
- value: date,
512
- operator: "gt"
513
- },
514
- {
515
- field: "published",
516
- value: true,
517
- operator: "eq"
518
- }
519
- ],
520
- sortBy: {
521
- field: "createdAt",
522
- direction: "asc"
523
- }
502
+ const sortedPosts = allPosts.sort((a, b) => {
503
+ const timeA = new Date(a.createdAt).getTime();
504
+ const timeB = new Date(b.createdAt).getTime();
505
+ return timeB - timeA;
524
506
  });
507
+ let previousPost = null;
508
+ let nextPost = null;
509
+ for (let i = 0; i < sortedPosts.length; i++) {
510
+ const post = sortedPosts[i];
511
+ if (!post) continue;
512
+ const postTime = new Date(post.createdAt).getTime();
513
+ if (postTime > targetTime) {
514
+ nextPost = post;
515
+ } else if (postTime < targetTime) {
516
+ previousPost = post;
517
+ break;
518
+ }
519
+ }
525
520
  const postIds = [
526
- ...previousPost?.[0] ? [previousPost[0].id] : [],
527
- ...nextPost?.[0] ? [nextPost[0].id] : []
521
+ ...previousPost ? [previousPost.id] : [],
522
+ ...nextPost ? [nextPost.id] : []
528
523
  ];
529
524
  const postTagsMap = await loadTagsForPosts(
530
525
  postIds,
@@ -532,13 +527,13 @@ const blogBackendPlugin = (hooks) => api.defineBackendPlugin({
532
527
  postTagCache
533
528
  );
534
529
  return {
535
- previous: previousPost?.[0] ? {
536
- ...previousPost[0],
537
- tags: postTagsMap.get(previousPost[0].id) || []
530
+ previous: previousPost ? {
531
+ ...previousPost,
532
+ tags: postTagsMap.get(previousPost.id) || []
538
533
  } : null,
539
- next: nextPost?.[0] ? {
540
- ...nextPost[0],
541
- tags: postTagsMap.get(nextPost[0].id) || []
534
+ next: nextPost ? {
535
+ ...nextPost,
536
+ tags: postTagsMap.get(nextPost.id) || []
542
537
  } : null
543
538
  };
544
539
  } catch (error) {
@@ -480,15 +480,12 @@ const blogBackendPlugin = (hooks) => defineBackendPlugin({
480
480
  }
481
481
  }
482
482
  const date = query.date;
483
- const previousPost = await adapter.findMany({
483
+ const targetTime = new Date(date).getTime();
484
+ const WINDOW_SIZE = 100;
485
+ const allPosts = await adapter.findMany({
484
486
  model: "post",
485
- limit: 1,
487
+ limit: WINDOW_SIZE,
486
488
  where: [
487
- {
488
- field: "createdAt",
489
- value: date,
490
- operator: "lt"
491
- },
492
489
  {
493
490
  field: "published",
494
491
  value: true,
@@ -500,29 +497,27 @@ const blogBackendPlugin = (hooks) => defineBackendPlugin({
500
497
  direction: "desc"
501
498
  }
502
499
  });
503
- const nextPost = await adapter.findMany({
504
- model: "post",
505
- limit: 1,
506
- where: [
507
- {
508
- field: "createdAt",
509
- value: date,
510
- operator: "gt"
511
- },
512
- {
513
- field: "published",
514
- value: true,
515
- operator: "eq"
516
- }
517
- ],
518
- sortBy: {
519
- field: "createdAt",
520
- direction: "asc"
521
- }
500
+ const sortedPosts = allPosts.sort((a, b) => {
501
+ const timeA = new Date(a.createdAt).getTime();
502
+ const timeB = new Date(b.createdAt).getTime();
503
+ return timeB - timeA;
522
504
  });
505
+ let previousPost = null;
506
+ let nextPost = null;
507
+ for (let i = 0; i < sortedPosts.length; i++) {
508
+ const post = sortedPosts[i];
509
+ if (!post) continue;
510
+ const postTime = new Date(post.createdAt).getTime();
511
+ if (postTime > targetTime) {
512
+ nextPost = post;
513
+ } else if (postTime < targetTime) {
514
+ previousPost = post;
515
+ break;
516
+ }
517
+ }
523
518
  const postIds = [
524
- ...previousPost?.[0] ? [previousPost[0].id] : [],
525
- ...nextPost?.[0] ? [nextPost[0].id] : []
519
+ ...previousPost ? [previousPost.id] : [],
520
+ ...nextPost ? [nextPost.id] : []
526
521
  ];
527
522
  const postTagsMap = await loadTagsForPosts(
528
523
  postIds,
@@ -530,13 +525,13 @@ const blogBackendPlugin = (hooks) => defineBackendPlugin({
530
525
  postTagCache
531
526
  );
532
527
  return {
533
- previous: previousPost?.[0] ? {
534
- ...previousPost[0],
535
- tags: postTagsMap.get(previousPost[0].id) || []
528
+ previous: previousPost ? {
529
+ ...previousPost,
530
+ tags: postTagsMap.get(previousPost.id) || []
536
531
  } : null,
537
- next: nextPost?.[0] ? {
538
- ...nextPost[0],
539
- tags: postTagsMap.get(nextPost[0].id) || []
532
+ next: nextPost ? {
533
+ ...nextPost,
534
+ tags: postTagsMap.get(nextPost.id) || []
540
535
  } : null
541
536
  };
542
537
  } catch (error) {
@@ -63,7 +63,7 @@ function PostPage({ slug }) {
63
63
  childrenTop: /* @__PURE__ */ jsxRuntime.jsx(PostHeaderTop, { post })
64
64
  }
65
65
  ),
66
- post.image && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 mt-6 aspect-video w-full relative", children: /* @__PURE__ */ jsxRuntime.jsx(
66
+ post.image && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2 my-6 aspect-video w-full relative", children: /* @__PURE__ */ jsxRuntime.jsx(
67
67
  Image,
68
68
  {
69
69
  src: post.image,
@@ -92,9 +92,9 @@ function PostHeaderTop({ post }) {
92
92
  Link: defaults.DefaultLink
93
93
  });
94
94
  const basePath = context.useBasePath();
95
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2 flex-wrap mt-8", children: [
95
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center justify-center gap-2 flex-wrap mt-8", children: [
96
96
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-light text-muted-foreground text-sm", children: dateFns.formatDate(post.createdAt, "MMMM d, yyyy") }),
97
- post.tags && post.tags.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: post.tags.map((tag) => /* @__PURE__ */ jsxRuntime.jsx(Link, { href: `${basePath}/blog/tag/${tag.slug}`, children: /* @__PURE__ */ jsxRuntime.jsx(badge.Badge, { variant: "secondary", className: "text-xs", children: tag.name }) }, tag.id)) })
97
+ post.tags && post.tags.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: post.tags.map((tag) => /* @__PURE__ */ jsxRuntime.jsx(Link, { href: `${basePath}/blog/tag/${tag.slug}`, children: /* @__PURE__ */ jsxRuntime.jsx(badge.Badge, { variant: "secondary", className: "text-xs", children: tag.name }) }, tag.id)) })
98
98
  ] });
99
99
  }
100
100
 
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { usePluginOverrides, useBasePath } from '@btst/stack/context';
4
4
  import { formatDate } from 'date-fns';
5
5
  import { useSuspensePost, useNextPreviousPosts, useRecentPosts } from '../../hooks/blog-hooks.mjs';
@@ -61,7 +61,7 @@ function PostPage({ slug }) {
61
61
  childrenTop: /* @__PURE__ */ jsx(PostHeaderTop, { post })
62
62
  }
63
63
  ),
64
- post.image && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 mt-6 aspect-video w-full relative", children: /* @__PURE__ */ jsx(
64
+ post.image && /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2 my-6 aspect-video w-full relative", children: /* @__PURE__ */ jsx(
65
65
  Image,
66
66
  {
67
67
  src: post.image,
@@ -90,9 +90,9 @@ function PostHeaderTop({ post }) {
90
90
  Link: DefaultLink
91
91
  });
92
92
  const basePath = useBasePath();
93
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2 flex-wrap mt-8", children: [
93
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-center gap-2 flex-wrap mt-8", children: [
94
94
  /* @__PURE__ */ jsx("span", { className: "font-light text-muted-foreground text-sm", children: formatDate(post.createdAt, "MMMM d, yyyy") }),
95
- post.tags && post.tags.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: post.tags.map((tag) => /* @__PURE__ */ jsx(Link, { href: `${basePath}/blog/tag/${tag.slug}`, children: /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: tag.name }) }, tag.id)) })
95
+ post.tags && post.tags.length > 0 && /* @__PURE__ */ jsx(Fragment, { children: post.tags.map((tag) => /* @__PURE__ */ jsx(Link, { href: `${basePath}/blog/tag/${tag.slug}`, children: /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: tag.name }) }, tag.id)) })
96
96
  ] });
97
97
  }
98
98
 
@@ -11,7 +11,7 @@ function DefaultError({ error }) {
11
11
  localization: index.BLOG_LOCALIZATION
12
12
  });
13
13
  const title = localization.BLOG_GENERIC_ERROR_TITLE;
14
- const message = error?.message ?? localization.BLOG_GENERIC_ERROR_MESSAGE;
14
+ const message = process.env.NODE_ENV === "production" ? localization.BLOG_GENERIC_ERROR_MESSAGE : error?.message ?? localization.BLOG_GENERIC_ERROR_MESSAGE;
15
15
  return /* @__PURE__ */ jsxRuntime.jsx(errorPlaceholder.ErrorPlaceholder, { title, message });
16
16
  }
17
17
 
@@ -9,7 +9,7 @@ function DefaultError({ error }) {
9
9
  localization: BLOG_LOCALIZATION
10
10
  });
11
11
  const title = localization.BLOG_GENERIC_ERROR_TITLE;
12
- const message = error?.message ?? localization.BLOG_GENERIC_ERROR_MESSAGE;
12
+ const message = process.env.NODE_ENV === "production" ? localization.BLOG_GENERIC_ERROR_MESSAGE : error?.message ?? localization.BLOG_GENERIC_ERROR_MESSAGE;
13
13
  return /* @__PURE__ */ jsx(ErrorPlaceholder, { title, message });
14
14
  }
15
15
 
@@ -20,7 +20,7 @@ const SHARED_QUERY_CONFIG = {
20
20
  // 10 minutes
21
21
  };
22
22
  function usePosts(options = {}) {
23
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
23
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
24
24
  const client$1 = client.createApiClient({
25
25
  baseURL: apiBaseURL,
26
26
  basePath: apiBasePath
@@ -33,7 +33,7 @@ function usePosts(options = {}) {
33
33
  query,
34
34
  published
35
35
  } = options;
36
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
36
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
37
37
  const queryParams = {
38
38
  tag,
39
39
  tagSlug,
@@ -73,7 +73,7 @@ function usePosts(options = {}) {
73
73
  };
74
74
  }
75
75
  function useSuspensePosts(options = {}) {
76
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
76
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
77
77
  const client$1 = client.createApiClient({
78
78
  baseURL: apiBaseURL,
79
79
  basePath: apiBasePath
@@ -86,7 +86,7 @@ function useSuspensePosts(options = {}) {
86
86
  query,
87
87
  published
88
88
  } = options;
89
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
89
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
90
90
  const queryParams = { tag, tagSlug, limit, query, published };
91
91
  const basePosts = queries.posts.list(queryParams);
92
92
  const {
@@ -120,12 +120,12 @@ function useSuspensePosts(options = {}) {
120
120
  };
121
121
  }
122
122
  function usePost(slug) {
123
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
123
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
124
124
  const client$1 = client.createApiClient({
125
125
  baseURL: apiBaseURL,
126
126
  basePath: apiBasePath
127
127
  });
128
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
128
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
129
129
  const basePost = queries.posts.detail(slug ?? "");
130
130
  const { data, isLoading, error, refetch } = reactQuery.useQuery({
131
131
  ...basePost,
@@ -140,12 +140,12 @@ function usePost(slug) {
140
140
  };
141
141
  }
142
142
  function useSuspensePost(slug) {
143
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
143
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
144
144
  const client$1 = client.createApiClient({
145
145
  baseURL: apiBaseURL,
146
146
  basePath: apiBasePath
147
147
  });
148
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
148
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
149
149
  const basePost = queries.posts.detail(slug);
150
150
  const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
151
151
  ...basePost,
@@ -157,12 +157,12 @@ function useSuspensePost(slug) {
157
157
  return { post: data || null, refetch };
158
158
  }
159
159
  function useTags() {
160
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
160
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
161
161
  const client$1 = client.createApiClient({
162
162
  baseURL: apiBaseURL,
163
163
  basePath: apiBasePath
164
164
  });
165
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
165
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
166
166
  const baseTags = queries.tags.list();
167
167
  const { data, isLoading, error, refetch } = reactQuery.useQuery({
168
168
  ...baseTags,
@@ -177,12 +177,12 @@ function useTags() {
177
177
  };
178
178
  }
179
179
  function useSuspenseTags() {
180
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
180
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
181
181
  const client$1 = client.createApiClient({
182
182
  baseURL: apiBaseURL,
183
183
  basePath: apiBasePath
184
184
  });
185
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
185
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
186
186
  const baseTags = queries.tags.list();
187
187
  const { data, refetch, error, isFetching } = reactQuery.useSuspenseQuery({
188
188
  ...baseTags,
@@ -336,12 +336,12 @@ function usePostSearch({
336
336
  };
337
337
  }
338
338
  function useNextPreviousPosts(createdAt, options = {}) {
339
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
339
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
340
340
  const client$1 = client.createApiClient({
341
341
  baseURL: apiBaseURL,
342
342
  basePath: apiBasePath
343
343
  });
344
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
344
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
345
345
  const { ref, inView } = reactIntersectionObserver.useInView({
346
346
  // start a little early so the data is ready as it scrolls in
347
347
  rootMargin: "200px 0px",
@@ -366,12 +366,12 @@ function useNextPreviousPosts(createdAt, options = {}) {
366
366
  };
367
367
  }
368
368
  function useRecentPosts(options = {}) {
369
- const { apiBaseURL, apiBasePath } = context.usePluginOverrides("blog");
369
+ const { apiBaseURL, apiBasePath, headers } = context.usePluginOverrides("blog");
370
370
  const client$1 = client.createApiClient({
371
371
  baseURL: apiBaseURL,
372
372
  basePath: apiBasePath
373
373
  });
374
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
374
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
375
375
  const { ref, inView } = reactIntersectionObserver.useInView({
376
376
  // start a little early so the data is ready as it scrolls in
377
377
  rootMargin: "200px 0px",
@@ -18,7 +18,7 @@ const SHARED_QUERY_CONFIG = {
18
18
  // 10 minutes
19
19
  };
20
20
  function usePosts(options = {}) {
21
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
21
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
22
22
  const client = createApiClient({
23
23
  baseURL: apiBaseURL,
24
24
  basePath: apiBasePath
@@ -31,7 +31,7 @@ function usePosts(options = {}) {
31
31
  query,
32
32
  published
33
33
  } = options;
34
- const queries = createBlogQueryKeys(client);
34
+ const queries = createBlogQueryKeys(client, headers);
35
35
  const queryParams = {
36
36
  tag,
37
37
  tagSlug,
@@ -71,7 +71,7 @@ function usePosts(options = {}) {
71
71
  };
72
72
  }
73
73
  function useSuspensePosts(options = {}) {
74
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
74
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
75
75
  const client = createApiClient({
76
76
  baseURL: apiBaseURL,
77
77
  basePath: apiBasePath
@@ -84,7 +84,7 @@ function useSuspensePosts(options = {}) {
84
84
  query,
85
85
  published
86
86
  } = options;
87
- const queries = createBlogQueryKeys(client);
87
+ const queries = createBlogQueryKeys(client, headers);
88
88
  const queryParams = { tag, tagSlug, limit, query, published };
89
89
  const basePosts = queries.posts.list(queryParams);
90
90
  const {
@@ -118,12 +118,12 @@ function useSuspensePosts(options = {}) {
118
118
  };
119
119
  }
120
120
  function usePost(slug) {
121
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
121
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
122
122
  const client = createApiClient({
123
123
  baseURL: apiBaseURL,
124
124
  basePath: apiBasePath
125
125
  });
126
- const queries = createBlogQueryKeys(client);
126
+ const queries = createBlogQueryKeys(client, headers);
127
127
  const basePost = queries.posts.detail(slug ?? "");
128
128
  const { data, isLoading, error, refetch } = useQuery({
129
129
  ...basePost,
@@ -138,12 +138,12 @@ function usePost(slug) {
138
138
  };
139
139
  }
140
140
  function useSuspensePost(slug) {
141
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
141
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
142
142
  const client = createApiClient({
143
143
  baseURL: apiBaseURL,
144
144
  basePath: apiBasePath
145
145
  });
146
- const queries = createBlogQueryKeys(client);
146
+ const queries = createBlogQueryKeys(client, headers);
147
147
  const basePost = queries.posts.detail(slug);
148
148
  const { data, refetch, error, isFetching } = useSuspenseQuery({
149
149
  ...basePost,
@@ -155,12 +155,12 @@ function useSuspensePost(slug) {
155
155
  return { post: data || null, refetch };
156
156
  }
157
157
  function useTags() {
158
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
158
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
159
159
  const client = createApiClient({
160
160
  baseURL: apiBaseURL,
161
161
  basePath: apiBasePath
162
162
  });
163
- const queries = createBlogQueryKeys(client);
163
+ const queries = createBlogQueryKeys(client, headers);
164
164
  const baseTags = queries.tags.list();
165
165
  const { data, isLoading, error, refetch } = useQuery({
166
166
  ...baseTags,
@@ -175,12 +175,12 @@ function useTags() {
175
175
  };
176
176
  }
177
177
  function useSuspenseTags() {
178
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
178
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
179
179
  const client = createApiClient({
180
180
  baseURL: apiBaseURL,
181
181
  basePath: apiBasePath
182
182
  });
183
- const queries = createBlogQueryKeys(client);
183
+ const queries = createBlogQueryKeys(client, headers);
184
184
  const baseTags = queries.tags.list();
185
185
  const { data, refetch, error, isFetching } = useSuspenseQuery({
186
186
  ...baseTags,
@@ -334,12 +334,12 @@ function usePostSearch({
334
334
  };
335
335
  }
336
336
  function useNextPreviousPosts(createdAt, options = {}) {
337
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
337
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
338
338
  const client = createApiClient({
339
339
  baseURL: apiBaseURL,
340
340
  basePath: apiBasePath
341
341
  });
342
- const queries = createBlogQueryKeys(client);
342
+ const queries = createBlogQueryKeys(client, headers);
343
343
  const { ref, inView } = useInView({
344
344
  // start a little early so the data is ready as it scrolls in
345
345
  rootMargin: "200px 0px",
@@ -364,12 +364,12 @@ function useNextPreviousPosts(createdAt, options = {}) {
364
364
  };
365
365
  }
366
366
  function useRecentPosts(options = {}) {
367
- const { apiBaseURL, apiBasePath } = usePluginOverrides("blog");
367
+ const { apiBaseURL, apiBasePath, headers } = usePluginOverrides("blog");
368
368
  const client = createApiClient({
369
369
  baseURL: apiBaseURL,
370
370
  basePath: apiBasePath
371
371
  });
372
- const queries = createBlogQueryKeys(client);
372
+ const queries = createBlogQueryKeys(client, headers);
373
373
  const { ref, inView } = useInView({
374
374
  // start a little early so the data is ready as it scrolls in
375
375
  rootMargin: "200px 0px",
@@ -13,7 +13,7 @@ const postPage = require('./components/pages/post-page.cjs');
13
13
  function createPostsLoader(published, config) {
14
14
  return async () => {
15
15
  if (typeof window === "undefined") {
16
- const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
16
+ const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
17
17
  const context = {
18
18
  path: published ? "/blog" : "/blog/drafts",
19
19
  isSSR: true,
@@ -32,7 +32,7 @@ function createPostsLoader(published, config) {
32
32
  baseURL: apiBaseURL,
33
33
  basePath: apiBasePath
34
34
  });
35
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
35
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
36
36
  const listQuery = queries.posts.list({
37
37
  query: void 0,
38
38
  limit,
@@ -46,7 +46,14 @@ function createPostsLoader(published, config) {
46
46
  await queryClient.prefetchQuery(tagsQuery);
47
47
  if (hooks?.afterLoadPosts) {
48
48
  const posts = queryClient.getQueryData(listQuery.queryKey) || null;
49
- await hooks.afterLoadPosts(posts, { published }, context);
49
+ const canContinue = await hooks.afterLoadPosts(
50
+ posts,
51
+ { published },
52
+ context
53
+ );
54
+ if (canContinue === false) {
55
+ throw new Error("Load prevented by afterLoadPosts hook");
56
+ }
50
57
  }
51
58
  const queryState = queryClient.getQueryState(listQuery.queryKey);
52
59
  if (queryState?.error) {
@@ -66,7 +73,7 @@ function createPostsLoader(published, config) {
66
73
  function createPostLoader(slug, config) {
67
74
  return async () => {
68
75
  if (typeof window === "undefined") {
69
- const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
76
+ const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
70
77
  const context = {
71
78
  path: `/blog/${slug}`,
72
79
  params: { slug },
@@ -85,12 +92,15 @@ function createPostLoader(slug, config) {
85
92
  baseURL: apiBaseURL,
86
93
  basePath: apiBasePath
87
94
  });
88
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
95
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
89
96
  const postQuery = queries.posts.detail(slug);
90
97
  await queryClient.prefetchQuery(postQuery);
91
98
  if (hooks?.afterLoadPost) {
92
99
  const post = queryClient.getQueryData(postQuery.queryKey) || null;
93
- await hooks.afterLoadPost(post, slug, context);
100
+ const canContinue = await hooks.afterLoadPost(post, slug, context);
101
+ if (canContinue === false) {
102
+ throw new Error("Load prevented by afterLoadPost hook");
103
+ }
94
104
  }
95
105
  const queryState = queryClient.getQueryState(postQuery.queryKey);
96
106
  if (queryState?.error) {
@@ -107,10 +117,41 @@ function createPostLoader(slug, config) {
107
117
  }
108
118
  };
109
119
  }
120
+ function createNewPostLoader(config) {
121
+ return async () => {
122
+ if (typeof window === "undefined") {
123
+ const { apiBasePath, apiBaseURL, hooks } = config;
124
+ const context = {
125
+ path: "/blog/new",
126
+ isSSR: true,
127
+ apiBaseURL,
128
+ apiBasePath
129
+ };
130
+ try {
131
+ if (hooks?.beforeLoadNewPost) {
132
+ const canLoad = await hooks.beforeLoadNewPost(context);
133
+ if (!canLoad) {
134
+ throw new Error("Load prevented by beforeLoadNewPost hook");
135
+ }
136
+ }
137
+ if (hooks?.afterLoadNewPost) {
138
+ const canContinue = await hooks.afterLoadNewPost(context);
139
+ if (canContinue === false) {
140
+ throw new Error("Load prevented by afterLoadNewPost hook");
141
+ }
142
+ }
143
+ } catch (error) {
144
+ if (hooks?.onLoadError) {
145
+ await hooks.onLoadError(error, context);
146
+ }
147
+ }
148
+ }
149
+ };
150
+ }
110
151
  function createTagLoader(tagSlug, config) {
111
152
  return async () => {
112
153
  if (typeof window === "undefined") {
113
- const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
154
+ const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
114
155
  const context = {
115
156
  path: `/blog/tag/${tagSlug}`,
116
157
  params: { tagSlug },
@@ -124,7 +165,7 @@ function createTagLoader(tagSlug, config) {
124
165
  baseURL: apiBaseURL,
125
166
  basePath: apiBasePath
126
167
  });
127
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1);
168
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
128
169
  const listQuery = queries.posts.list({
129
170
  query: void 0,
130
171
  limit,
@@ -382,6 +423,7 @@ const blogClientPlugin = (config) => client.defineClientPlugin({
382
423
  newPost: yar.createRoute("/blog/new", () => {
383
424
  return {
384
425
  PageComponent: newPostPage.NewPostPageComponent,
426
+ loader: createNewPostLoader(config),
385
427
  meta: createNewPostMeta(config)
386
428
  };
387
429
  }),