@btst/stack 1.1.5 → 1.1.7
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/packages/better-stack/src/plugins/blog/api/plugin.cjs +14 -7
- package/dist/packages/better-stack/src/plugins/blog/api/plugin.mjs +14 -7
- package/dist/packages/better-stack/src/plugins/blog/client/hooks/blog-hooks.cjs +16 -16
- package/dist/packages/better-stack/src/plugins/blog/client/hooks/blog-hooks.mjs +16 -16
- package/dist/packages/better-stack/src/plugins/blog/client/plugin.cjs +6 -6
- package/dist/packages/better-stack/src/plugins/blog/client/plugin.mjs +6 -6
- package/dist/plugins/blog/api/index.d.cts +1 -1
- package/dist/plugins/blog/api/index.d.mts +1 -1
- package/dist/plugins/blog/api/index.d.ts +1 -1
- package/dist/plugins/blog/client/hooks/index.d.cts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.mts +2 -2
- package/dist/plugins/blog/client/hooks/index.d.ts +2 -2
- package/dist/plugins/blog/client/index.d.cts +6 -1
- package/dist/plugins/blog/client/index.d.mts +6 -1
- package/dist/plugins/blog/client/index.d.ts +6 -1
- package/dist/plugins/blog/query-keys.cjs +19 -13
- package/dist/plugins/blog/query-keys.d.cts +4 -3
- package/dist/plugins/blog/query-keys.d.mts +4 -3
- package/dist/plugins/blog/query-keys.d.ts +4 -3
- package/dist/plugins/blog/query-keys.mjs +19 -13
- package/package.json +5 -3
- package/src/plugins/blog/api/plugin.ts +14 -6
- package/src/plugins/blog/client/hooks/blog-hooks.tsx +16 -16
- package/src/plugins/blog/client/overrides.ts +4 -0
- package/src/plugins/blog/client/plugin.tsx +9 -6
- package/src/plugins/blog/query-keys.ts +13 -3
- package/dist/shared/{stack.CoPoHVfV.d.cts → stack.Cr2JoQdo.d.cts} +1 -1
- package/dist/shared/{stack.CoPoHVfV.d.mts → stack.Cr2JoQdo.d.mts} +1 -1
- package/dist/shared/{stack.CoPoHVfV.d.ts → stack.Cr2JoQdo.d.ts} +1 -1
|
@@ -18,13 +18,13 @@ function toError(error) {
|
|
|
18
18
|
}
|
|
19
19
|
return new Error(String(error));
|
|
20
20
|
}
|
|
21
|
-
function createBlogQueryKeys(client) {
|
|
22
|
-
const posts = createPostsQueries(client);
|
|
23
|
-
const drafts = createDraftsQueries(client);
|
|
24
|
-
const tags = createTagsQueries(client);
|
|
21
|
+
function createBlogQueryKeys(client, headers) {
|
|
22
|
+
const posts = createPostsQueries(client, headers);
|
|
23
|
+
const drafts = createDraftsQueries(client, headers);
|
|
24
|
+
const tags = createTagsQueries(client, headers);
|
|
25
25
|
return queryKeyFactory.mergeQueryKeys(posts, drafts, tags);
|
|
26
26
|
}
|
|
27
|
-
function createPostsQueries(client) {
|
|
27
|
+
function createPostsQueries(client, headers) {
|
|
28
28
|
return queryKeyFactory.createQueryKeys("posts", {
|
|
29
29
|
list: (params) => ({
|
|
30
30
|
queryKey: [
|
|
@@ -45,7 +45,8 @@ function createPostsQueries(client) {
|
|
|
45
45
|
limit: params?.limit ?? 10,
|
|
46
46
|
published: params?.published !== void 0 ? params.published ? "true" : "false" : void 0,
|
|
47
47
|
tagSlug: params?.tagSlug
|
|
48
|
-
}
|
|
48
|
+
},
|
|
49
|
+
headers
|
|
49
50
|
});
|
|
50
51
|
if (isErrorResponse(response)) {
|
|
51
52
|
const errorResponse = response;
|
|
@@ -65,7 +66,8 @@ function createPostsQueries(client) {
|
|
|
65
66
|
try {
|
|
66
67
|
const response = await client("/posts", {
|
|
67
68
|
method: "GET",
|
|
68
|
-
query: { slug, limit: 1 }
|
|
69
|
+
query: { slug, limit: 1 },
|
|
70
|
+
headers
|
|
69
71
|
});
|
|
70
72
|
if (isErrorResponse(response)) {
|
|
71
73
|
const errorResponse = response;
|
|
@@ -87,7 +89,8 @@ function createPostsQueries(client) {
|
|
|
87
89
|
method: "GET",
|
|
88
90
|
query: {
|
|
89
91
|
date: dateValue.toISOString()
|
|
90
|
-
}
|
|
92
|
+
},
|
|
93
|
+
headers
|
|
91
94
|
});
|
|
92
95
|
if (isErrorResponse(response)) {
|
|
93
96
|
const errorResponse = response;
|
|
@@ -107,7 +110,8 @@ function createPostsQueries(client) {
|
|
|
107
110
|
query: {
|
|
108
111
|
limit: params?.limit ?? 5,
|
|
109
112
|
published: "true"
|
|
110
|
-
}
|
|
113
|
+
},
|
|
114
|
+
headers
|
|
111
115
|
});
|
|
112
116
|
if (isErrorResponse(response)) {
|
|
113
117
|
const errorResponse = response;
|
|
@@ -125,7 +129,7 @@ function createPostsQueries(client) {
|
|
|
125
129
|
})
|
|
126
130
|
});
|
|
127
131
|
}
|
|
128
|
-
function createDraftsQueries(client) {
|
|
132
|
+
function createDraftsQueries(client, headers) {
|
|
129
133
|
return queryKeyFactory.createQueryKeys("drafts", {
|
|
130
134
|
list: (params) => ({
|
|
131
135
|
queryKey: [
|
|
@@ -142,7 +146,8 @@ function createDraftsQueries(client) {
|
|
|
142
146
|
offset: pageParam ?? 0,
|
|
143
147
|
limit: params?.limit ?? 10,
|
|
144
148
|
published: "false"
|
|
145
|
-
}
|
|
149
|
+
},
|
|
150
|
+
headers
|
|
146
151
|
});
|
|
147
152
|
if (isErrorResponse(response)) {
|
|
148
153
|
const errorResponse = response;
|
|
@@ -156,14 +161,15 @@ function createDraftsQueries(client) {
|
|
|
156
161
|
})
|
|
157
162
|
});
|
|
158
163
|
}
|
|
159
|
-
function createTagsQueries(client) {
|
|
164
|
+
function createTagsQueries(client, headers) {
|
|
160
165
|
return queryKeyFactory.createQueryKeys("tags", {
|
|
161
166
|
list: () => ({
|
|
162
167
|
queryKey: ["tags"],
|
|
163
168
|
queryFn: async () => {
|
|
164
169
|
try {
|
|
165
170
|
const response = await client("/tags", {
|
|
166
|
-
method: "GET"
|
|
171
|
+
method: "GET",
|
|
172
|
+
headers
|
|
167
173
|
});
|
|
168
174
|
if (isErrorResponse(response)) {
|
|
169
175
|
const errorResponse = response;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
|
|
2
2
|
import * as better_call from 'better-call';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.
|
|
4
|
+
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.Cr2JoQdo.cjs';
|
|
5
5
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
6
|
import { createApiClient } from '@btst/stack/plugins/client';
|
|
7
7
|
|
|
@@ -24,6 +24,7 @@ interface BlogApiContext<TBody = any, TParams = any, TQuery = any> {
|
|
|
24
24
|
params?: TParams;
|
|
25
25
|
query?: TQuery;
|
|
26
26
|
request?: Request;
|
|
27
|
+
headers?: Headers;
|
|
27
28
|
[key: string]: any;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -172,12 +173,12 @@ declare const blogBackendPlugin: (hooks?: BlogBackendHooks) => _btst_stack_plugi
|
|
|
172
173
|
options: {
|
|
173
174
|
method: "POST";
|
|
174
175
|
body: z.ZodObject<{
|
|
176
|
+
title: z.ZodString;
|
|
175
177
|
slug: z.ZodOptional<z.ZodString>;
|
|
176
178
|
published: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
177
179
|
createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
178
180
|
publishedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
179
181
|
updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
180
|
-
title: z.ZodString;
|
|
181
182
|
content: z.ZodString;
|
|
182
183
|
excerpt: z.ZodString;
|
|
183
184
|
image: z.ZodOptional<z.ZodString>;
|
|
@@ -437,7 +438,7 @@ interface PostsListParams {
|
|
|
437
438
|
published?: boolean;
|
|
438
439
|
tagSlug?: string;
|
|
439
440
|
}
|
|
440
|
-
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter
|
|
441
|
+
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter>>, headers?: HeadersInit): {
|
|
441
442
|
posts: {
|
|
442
443
|
_def: readonly ["posts"];
|
|
443
444
|
} & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
|
|
2
2
|
import * as better_call from 'better-call';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.
|
|
4
|
+
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.Cr2JoQdo.mjs';
|
|
5
5
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
6
|
import { createApiClient } from '@btst/stack/plugins/client';
|
|
7
7
|
|
|
@@ -24,6 +24,7 @@ interface BlogApiContext<TBody = any, TParams = any, TQuery = any> {
|
|
|
24
24
|
params?: TParams;
|
|
25
25
|
query?: TQuery;
|
|
26
26
|
request?: Request;
|
|
27
|
+
headers?: Headers;
|
|
27
28
|
[key: string]: any;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -172,12 +173,12 @@ declare const blogBackendPlugin: (hooks?: BlogBackendHooks) => _btst_stack_plugi
|
|
|
172
173
|
options: {
|
|
173
174
|
method: "POST";
|
|
174
175
|
body: z.ZodObject<{
|
|
176
|
+
title: z.ZodString;
|
|
175
177
|
slug: z.ZodOptional<z.ZodString>;
|
|
176
178
|
published: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
177
179
|
createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
178
180
|
publishedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
179
181
|
updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
180
|
-
title: z.ZodString;
|
|
181
182
|
content: z.ZodString;
|
|
182
183
|
excerpt: z.ZodString;
|
|
183
184
|
image: z.ZodOptional<z.ZodString>;
|
|
@@ -437,7 +438,7 @@ interface PostsListParams {
|
|
|
437
438
|
published?: boolean;
|
|
438
439
|
tagSlug?: string;
|
|
439
440
|
}
|
|
440
|
-
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter
|
|
441
|
+
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter>>, headers?: HeadersInit): {
|
|
441
442
|
posts: {
|
|
442
443
|
_def: readonly ["posts"];
|
|
443
444
|
} & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _btst_stack_plugins_api from '@btst/stack/plugins/api';
|
|
2
2
|
import * as better_call from 'better-call';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.
|
|
4
|
+
import { c as createPostSchema, u as updatePostSchema, P as Post, T as Tag, S as SerializedPost, a as SerializedTag } from '../../shared/stack.Cr2JoQdo.js';
|
|
5
5
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
6
|
import { createApiClient } from '@btst/stack/plugins/client';
|
|
7
7
|
|
|
@@ -24,6 +24,7 @@ interface BlogApiContext<TBody = any, TParams = any, TQuery = any> {
|
|
|
24
24
|
params?: TParams;
|
|
25
25
|
query?: TQuery;
|
|
26
26
|
request?: Request;
|
|
27
|
+
headers?: Headers;
|
|
27
28
|
[key: string]: any;
|
|
28
29
|
}
|
|
29
30
|
/**
|
|
@@ -172,12 +173,12 @@ declare const blogBackendPlugin: (hooks?: BlogBackendHooks) => _btst_stack_plugi
|
|
|
172
173
|
options: {
|
|
173
174
|
method: "POST";
|
|
174
175
|
body: z.ZodObject<{
|
|
176
|
+
title: z.ZodString;
|
|
175
177
|
slug: z.ZodOptional<z.ZodString>;
|
|
176
178
|
published: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
177
179
|
createdAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
178
180
|
publishedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
179
181
|
updatedAt: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
180
|
-
title: z.ZodString;
|
|
181
182
|
content: z.ZodString;
|
|
182
183
|
excerpt: z.ZodString;
|
|
183
184
|
image: z.ZodOptional<z.ZodString>;
|
|
@@ -437,7 +438,7 @@ interface PostsListParams {
|
|
|
437
438
|
published?: boolean;
|
|
438
439
|
tagSlug?: string;
|
|
439
440
|
}
|
|
440
|
-
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter
|
|
441
|
+
declare function createBlogQueryKeys(client: ReturnType<typeof createApiClient<BlogApiRouter>>, headers?: HeadersInit): {
|
|
441
442
|
posts: {
|
|
442
443
|
_def: readonly ["posts"];
|
|
443
444
|
} & {
|
|
@@ -16,13 +16,13 @@ function toError(error) {
|
|
|
16
16
|
}
|
|
17
17
|
return new Error(String(error));
|
|
18
18
|
}
|
|
19
|
-
function createBlogQueryKeys(client) {
|
|
20
|
-
const posts = createPostsQueries(client);
|
|
21
|
-
const drafts = createDraftsQueries(client);
|
|
22
|
-
const tags = createTagsQueries(client);
|
|
19
|
+
function createBlogQueryKeys(client, headers) {
|
|
20
|
+
const posts = createPostsQueries(client, headers);
|
|
21
|
+
const drafts = createDraftsQueries(client, headers);
|
|
22
|
+
const tags = createTagsQueries(client, headers);
|
|
23
23
|
return mergeQueryKeys(posts, drafts, tags);
|
|
24
24
|
}
|
|
25
|
-
function createPostsQueries(client) {
|
|
25
|
+
function createPostsQueries(client, headers) {
|
|
26
26
|
return createQueryKeys("posts", {
|
|
27
27
|
list: (params) => ({
|
|
28
28
|
queryKey: [
|
|
@@ -43,7 +43,8 @@ function createPostsQueries(client) {
|
|
|
43
43
|
limit: params?.limit ?? 10,
|
|
44
44
|
published: params?.published !== void 0 ? params.published ? "true" : "false" : void 0,
|
|
45
45
|
tagSlug: params?.tagSlug
|
|
46
|
-
}
|
|
46
|
+
},
|
|
47
|
+
headers
|
|
47
48
|
});
|
|
48
49
|
if (isErrorResponse(response)) {
|
|
49
50
|
const errorResponse = response;
|
|
@@ -63,7 +64,8 @@ function createPostsQueries(client) {
|
|
|
63
64
|
try {
|
|
64
65
|
const response = await client("/posts", {
|
|
65
66
|
method: "GET",
|
|
66
|
-
query: { slug, limit: 1 }
|
|
67
|
+
query: { slug, limit: 1 },
|
|
68
|
+
headers
|
|
67
69
|
});
|
|
68
70
|
if (isErrorResponse(response)) {
|
|
69
71
|
const errorResponse = response;
|
|
@@ -85,7 +87,8 @@ function createPostsQueries(client) {
|
|
|
85
87
|
method: "GET",
|
|
86
88
|
query: {
|
|
87
89
|
date: dateValue.toISOString()
|
|
88
|
-
}
|
|
90
|
+
},
|
|
91
|
+
headers
|
|
89
92
|
});
|
|
90
93
|
if (isErrorResponse(response)) {
|
|
91
94
|
const errorResponse = response;
|
|
@@ -105,7 +108,8 @@ function createPostsQueries(client) {
|
|
|
105
108
|
query: {
|
|
106
109
|
limit: params?.limit ?? 5,
|
|
107
110
|
published: "true"
|
|
108
|
-
}
|
|
111
|
+
},
|
|
112
|
+
headers
|
|
109
113
|
});
|
|
110
114
|
if (isErrorResponse(response)) {
|
|
111
115
|
const errorResponse = response;
|
|
@@ -123,7 +127,7 @@ function createPostsQueries(client) {
|
|
|
123
127
|
})
|
|
124
128
|
});
|
|
125
129
|
}
|
|
126
|
-
function createDraftsQueries(client) {
|
|
130
|
+
function createDraftsQueries(client, headers) {
|
|
127
131
|
return createQueryKeys("drafts", {
|
|
128
132
|
list: (params) => ({
|
|
129
133
|
queryKey: [
|
|
@@ -140,7 +144,8 @@ function createDraftsQueries(client) {
|
|
|
140
144
|
offset: pageParam ?? 0,
|
|
141
145
|
limit: params?.limit ?? 10,
|
|
142
146
|
published: "false"
|
|
143
|
-
}
|
|
147
|
+
},
|
|
148
|
+
headers
|
|
144
149
|
});
|
|
145
150
|
if (isErrorResponse(response)) {
|
|
146
151
|
const errorResponse = response;
|
|
@@ -154,14 +159,15 @@ function createDraftsQueries(client) {
|
|
|
154
159
|
})
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
|
-
function createTagsQueries(client) {
|
|
162
|
+
function createTagsQueries(client, headers) {
|
|
158
163
|
return createQueryKeys("tags", {
|
|
159
164
|
list: () => ({
|
|
160
165
|
queryKey: ["tags"],
|
|
161
166
|
queryFn: async () => {
|
|
162
167
|
try {
|
|
163
168
|
const response = await client("/tags", {
|
|
164
|
-
method: "GET"
|
|
169
|
+
method: "GET",
|
|
170
|
+
headers
|
|
165
171
|
});
|
|
166
172
|
if (isErrorResponse(response)) {
|
|
167
173
|
const errorResponse = response;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btst/stack",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "A composable, plugin-based library for building full-stack applications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -158,20 +158,20 @@
|
|
|
158
158
|
},
|
|
159
159
|
"dependencies": {
|
|
160
160
|
"@btst/db": "1.0.2",
|
|
161
|
-
"@btst/yar": "1.1.1",
|
|
162
161
|
"@lukemorales/query-key-factory": "^1.3.4",
|
|
163
162
|
"@milkdown/crepe": "^7.17.1",
|
|
164
163
|
"@milkdown/kit": "^7.17.1",
|
|
165
|
-
"better-call": "1.0.19",
|
|
166
164
|
"slug": "^11.0.1"
|
|
167
165
|
},
|
|
168
166
|
"peerDependencies": {
|
|
167
|
+
"@btst/yar": ">=1.1.0",
|
|
169
168
|
"@hookform/resolvers": ">=5.0.0",
|
|
170
169
|
"@radix-ui/react-dialog": ">=1.1.0",
|
|
171
170
|
"@radix-ui/react-label": ">=2.1.0",
|
|
172
171
|
"@radix-ui/react-slot": ">=1.1.0",
|
|
173
172
|
"@radix-ui/react-switch": ">=1.1.0",
|
|
174
173
|
"@tanstack/react-query": "^5.0.0",
|
|
174
|
+
"better-call": ">=1.0.0",
|
|
175
175
|
"class-variance-authority": ">=0.7.0",
|
|
176
176
|
"clsx": ">=2.1.0",
|
|
177
177
|
"cmdk": ">=1.1.0",
|
|
@@ -197,9 +197,11 @@
|
|
|
197
197
|
},
|
|
198
198
|
"devDependencies": {
|
|
199
199
|
"@btst/adapter-memory": "1.0.2",
|
|
200
|
+
"@btst/yar": "1.1.1",
|
|
200
201
|
"@types/react": "^19.0.0",
|
|
201
202
|
"@types/slug": "^5.0.9",
|
|
202
203
|
"@workspace/ui": "workspace:*",
|
|
204
|
+
"better-call": "1.0.19",
|
|
203
205
|
"react": "^19.1.1",
|
|
204
206
|
"react-dom": "^19.1.1",
|
|
205
207
|
"react-error-boundary": "^4.1.2",
|
|
@@ -36,6 +36,7 @@ export interface BlogApiContext<TBody = any, TParams = any, TQuery = any> {
|
|
|
36
36
|
params?: TParams;
|
|
37
37
|
query?: TQuery;
|
|
38
38
|
request?: Request;
|
|
39
|
+
headers?: Headers;
|
|
39
40
|
[key: string]: any;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -282,8 +283,8 @@ export const blogBackendPlugin = (hooks?: BlogBackendHooks) =>
|
|
|
282
283
|
query: PostListQuerySchema,
|
|
283
284
|
},
|
|
284
285
|
async (ctx) => {
|
|
285
|
-
const { query } = ctx;
|
|
286
|
-
const context: BlogApiContext = { query };
|
|
286
|
+
const { query, headers } = ctx;
|
|
287
|
+
const context: BlogApiContext = { query, headers };
|
|
287
288
|
const tagCache = createTagCache();
|
|
288
289
|
const postTagCache = createPostTagCache();
|
|
289
290
|
|
|
@@ -402,7 +403,10 @@ export const blogBackendPlugin = (hooks?: BlogBackendHooks) =>
|
|
|
402
403
|
body: createPostSchema,
|
|
403
404
|
},
|
|
404
405
|
async (ctx) => {
|
|
405
|
-
const context: BlogApiContext = {
|
|
406
|
+
const context: BlogApiContext = {
|
|
407
|
+
body: ctx.body,
|
|
408
|
+
headers: ctx.headers,
|
|
409
|
+
};
|
|
406
410
|
const tagCache = createTagCache();
|
|
407
411
|
|
|
408
412
|
try {
|
|
@@ -475,6 +479,7 @@ export const blogBackendPlugin = (hooks?: BlogBackendHooks) =>
|
|
|
475
479
|
const context: BlogApiContext = {
|
|
476
480
|
body: ctx.body,
|
|
477
481
|
params: ctx.params,
|
|
482
|
+
headers: ctx.headers,
|
|
478
483
|
};
|
|
479
484
|
const tagCache = createTagCache();
|
|
480
485
|
|
|
@@ -583,7 +588,10 @@ export const blogBackendPlugin = (hooks?: BlogBackendHooks) =>
|
|
|
583
588
|
method: "DELETE",
|
|
584
589
|
},
|
|
585
590
|
async (ctx) => {
|
|
586
|
-
const context: BlogApiContext = {
|
|
591
|
+
const context: BlogApiContext = {
|
|
592
|
+
params: ctx.params,
|
|
593
|
+
headers: ctx.headers,
|
|
594
|
+
};
|
|
587
595
|
|
|
588
596
|
try {
|
|
589
597
|
// Authorization hook
|
|
@@ -634,8 +642,8 @@ export const blogBackendPlugin = (hooks?: BlogBackendHooks) =>
|
|
|
634
642
|
query: NextPreviousPostsQuerySchema,
|
|
635
643
|
},
|
|
636
644
|
async (ctx) => {
|
|
637
|
-
const { query } = ctx;
|
|
638
|
-
const context: BlogApiContext = { query };
|
|
645
|
+
const { query, headers } = ctx;
|
|
646
|
+
const context: BlogApiContext = { query, headers };
|
|
639
647
|
const tagCache = createTagCache();
|
|
640
648
|
const postTagCache = createPostTagCache();
|
|
641
649
|
|
|
@@ -86,7 +86,7 @@ export type PostUpdateInput = z.infer<typeof updatePostSchema>;
|
|
|
86
86
|
* Hook for fetching paginated posts with load more functionality
|
|
87
87
|
*/
|
|
88
88
|
export function usePosts(options: UsePostsOptions = {}): UsePostsResult {
|
|
89
|
-
const { apiBaseURL, apiBasePath } =
|
|
89
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
90
90
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
91
91
|
const client = createApiClient<BlogApiRouter>({
|
|
92
92
|
baseURL: apiBaseURL,
|
|
@@ -100,7 +100,7 @@ export function usePosts(options: UsePostsOptions = {}): UsePostsResult {
|
|
|
100
100
|
query,
|
|
101
101
|
published,
|
|
102
102
|
} = options;
|
|
103
|
-
const queries = createBlogQueryKeys(client);
|
|
103
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
104
104
|
|
|
105
105
|
const queryParams = {
|
|
106
106
|
tag,
|
|
@@ -155,7 +155,7 @@ export function useSuspensePosts(options: UsePostsOptions = {}): {
|
|
|
155
155
|
isLoadingMore: boolean;
|
|
156
156
|
refetch: () => Promise<unknown>;
|
|
157
157
|
} {
|
|
158
|
-
const { apiBaseURL, apiBasePath } =
|
|
158
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
159
159
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
160
160
|
const client = createApiClient<BlogApiRouter>({
|
|
161
161
|
baseURL: apiBaseURL,
|
|
@@ -169,7 +169,7 @@ export function useSuspensePosts(options: UsePostsOptions = {}): {
|
|
|
169
169
|
query,
|
|
170
170
|
published,
|
|
171
171
|
} = options;
|
|
172
|
-
const queries = createBlogQueryKeys(client);
|
|
172
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
173
173
|
|
|
174
174
|
const queryParams = { tag, tagSlug, limit, query, published };
|
|
175
175
|
const basePosts = queries.posts.list(queryParams);
|
|
@@ -214,13 +214,13 @@ export function useSuspensePosts(options: UsePostsOptions = {}): {
|
|
|
214
214
|
* Hook for fetching a single post by slug
|
|
215
215
|
*/
|
|
216
216
|
export function usePost(slug?: string): UsePostResult {
|
|
217
|
-
const { apiBaseURL, apiBasePath } =
|
|
217
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
218
218
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
219
219
|
const client = createApiClient<BlogApiRouter>({
|
|
220
220
|
baseURL: apiBaseURL,
|
|
221
221
|
basePath: apiBasePath,
|
|
222
222
|
});
|
|
223
|
-
const queries = createBlogQueryKeys(client);
|
|
223
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
224
224
|
|
|
225
225
|
const basePost = queries.posts.detail(slug ?? "");
|
|
226
226
|
const { data, isLoading, error, refetch } = useQuery<
|
|
@@ -247,13 +247,13 @@ export function useSuspensePost(slug: string): {
|
|
|
247
247
|
post: SerializedPost | null;
|
|
248
248
|
refetch: () => Promise<unknown>;
|
|
249
249
|
} {
|
|
250
|
-
const { apiBaseURL, apiBasePath } =
|
|
250
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
251
251
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
252
252
|
const client = createApiClient<BlogApiRouter>({
|
|
253
253
|
baseURL: apiBaseURL,
|
|
254
254
|
basePath: apiBasePath,
|
|
255
255
|
});
|
|
256
|
-
const queries = createBlogQueryKeys(client);
|
|
256
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
257
257
|
const basePost = queries.posts.detail(slug);
|
|
258
258
|
const { data, refetch, error, isFetching } = useSuspenseQuery<
|
|
259
259
|
SerializedPost | null,
|
|
@@ -283,13 +283,13 @@ export function useTags(): {
|
|
|
283
283
|
error: Error | null;
|
|
284
284
|
refetch: () => void;
|
|
285
285
|
} {
|
|
286
|
-
const { apiBaseURL, apiBasePath } =
|
|
286
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
287
287
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
288
288
|
const client = createApiClient<BlogApiRouter>({
|
|
289
289
|
baseURL: apiBaseURL,
|
|
290
290
|
basePath: apiBasePath,
|
|
291
291
|
});
|
|
292
|
-
const queries = createBlogQueryKeys(client);
|
|
292
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
293
293
|
const baseTags = queries.tags.list();
|
|
294
294
|
const { data, isLoading, error, refetch } = useQuery<
|
|
295
295
|
SerializedTag[] | null,
|
|
@@ -315,13 +315,13 @@ export function useSuspenseTags(): {
|
|
|
315
315
|
tags: SerializedTag[];
|
|
316
316
|
refetch: () => Promise<unknown>;
|
|
317
317
|
} {
|
|
318
|
-
const { apiBaseURL, apiBasePath } =
|
|
318
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
319
319
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
320
320
|
const client = createApiClient<BlogApiRouter>({
|
|
321
321
|
baseURL: apiBaseURL,
|
|
322
322
|
basePath: apiBasePath,
|
|
323
323
|
});
|
|
324
|
-
const queries = createBlogQueryKeys(client);
|
|
324
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
325
325
|
const baseTags = queries.tags.list();
|
|
326
326
|
const { data, refetch, error, isFetching } = useSuspenseQuery<
|
|
327
327
|
SerializedTag[] | null,
|
|
@@ -555,13 +555,13 @@ export function useNextPreviousPosts(
|
|
|
555
555
|
ref: (node: Element | null) => void;
|
|
556
556
|
inView: boolean;
|
|
557
557
|
} {
|
|
558
|
-
const { apiBaseURL, apiBasePath } =
|
|
558
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
559
559
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
560
560
|
const client = createApiClient<BlogApiRouter>({
|
|
561
561
|
baseURL: apiBaseURL,
|
|
562
562
|
basePath: apiBasePath,
|
|
563
563
|
});
|
|
564
|
-
const queries = createBlogQueryKeys(client);
|
|
564
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
565
565
|
|
|
566
566
|
const { ref, inView } = useInView({
|
|
567
567
|
// start a little early so the data is ready as it scrolls in
|
|
@@ -619,13 +619,13 @@ export function useRecentPosts(
|
|
|
619
619
|
ref: (node: Element | null) => void;
|
|
620
620
|
inView: boolean;
|
|
621
621
|
} {
|
|
622
|
-
const { apiBaseURL, apiBasePath } =
|
|
622
|
+
const { apiBaseURL, apiBasePath, headers } =
|
|
623
623
|
usePluginOverrides<BlogPluginOverrides>("blog");
|
|
624
624
|
const client = createApiClient<BlogApiRouter>({
|
|
625
625
|
baseURL: apiBaseURL,
|
|
626
626
|
basePath: apiBasePath,
|
|
627
627
|
});
|
|
628
|
-
const queries = createBlogQueryKeys(client);
|
|
628
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
629
629
|
|
|
630
630
|
const { ref, inView } = useInView({
|
|
631
631
|
// start a little early so the data is ready as it scrolls in
|
|
@@ -57,6 +57,10 @@ export interface BlogPluginOverrides {
|
|
|
57
57
|
* Whether to show the attribution
|
|
58
58
|
*/
|
|
59
59
|
showAttribution?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Optional headers to pass with API requests (e.g., for SSR auth)
|
|
62
|
+
*/
|
|
63
|
+
headers?: HeadersInit;
|
|
60
64
|
|
|
61
65
|
// Lifecycle Hooks (optional)
|
|
62
66
|
/**
|
|
@@ -58,6 +58,9 @@ export interface BlogClientConfig {
|
|
|
58
58
|
|
|
59
59
|
// Optional hooks
|
|
60
60
|
hooks?: BlogClientHooks;
|
|
61
|
+
|
|
62
|
+
// Optional headers for SSR (e.g., forwarding cookies)
|
|
63
|
+
headers?: HeadersInit;
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
/**
|
|
@@ -91,7 +94,7 @@ export interface BlogClientHooks {
|
|
|
91
94
|
function createPostsLoader(published: boolean, config: BlogClientConfig) {
|
|
92
95
|
return async () => {
|
|
93
96
|
if (typeof window === "undefined") {
|
|
94
|
-
const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
|
|
97
|
+
const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
|
|
95
98
|
|
|
96
99
|
const context: LoaderContext = {
|
|
97
100
|
path: published ? "/blog" : "/blog/drafts",
|
|
@@ -116,7 +119,7 @@ function createPostsLoader(published: boolean, config: BlogClientConfig) {
|
|
|
116
119
|
});
|
|
117
120
|
|
|
118
121
|
// note: for a module not to be bundled with client, and to be shared by client and server we need to add it to build.config.ts as an entry
|
|
119
|
-
const queries = createBlogQueryKeys(client);
|
|
122
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
120
123
|
const listQuery = queries.posts.list({
|
|
121
124
|
query: undefined,
|
|
122
125
|
limit,
|
|
@@ -170,7 +173,7 @@ function createPostsLoader(published: boolean, config: BlogClientConfig) {
|
|
|
170
173
|
function createPostLoader(slug: string, config: BlogClientConfig) {
|
|
171
174
|
return async () => {
|
|
172
175
|
if (typeof window === "undefined") {
|
|
173
|
-
const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
|
|
176
|
+
const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
|
|
174
177
|
|
|
175
178
|
const context: LoaderContext = {
|
|
176
179
|
path: `/blog/${slug}`,
|
|
@@ -193,7 +196,7 @@ function createPostLoader(slug: string, config: BlogClientConfig) {
|
|
|
193
196
|
baseURL: apiBaseURL,
|
|
194
197
|
basePath: apiBasePath,
|
|
195
198
|
});
|
|
196
|
-
const queries = createBlogQueryKeys(client);
|
|
199
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
197
200
|
const postQuery = queries.posts.detail(slug);
|
|
198
201
|
await queryClient.prefetchQuery(postQuery);
|
|
199
202
|
|
|
@@ -235,7 +238,7 @@ function createPostLoader(slug: string, config: BlogClientConfig) {
|
|
|
235
238
|
function createTagLoader(tagSlug: string, config: BlogClientConfig) {
|
|
236
239
|
return async () => {
|
|
237
240
|
if (typeof window === "undefined") {
|
|
238
|
-
const { queryClient, apiBasePath, apiBaseURL, hooks } = config;
|
|
241
|
+
const { queryClient, apiBasePath, apiBaseURL, hooks, headers } = config;
|
|
239
242
|
|
|
240
243
|
const context: LoaderContext = {
|
|
241
244
|
path: `/blog/tag/${tagSlug}`,
|
|
@@ -252,7 +255,7 @@ function createTagLoader(tagSlug: string, config: BlogClientConfig) {
|
|
|
252
255
|
basePath: apiBasePath,
|
|
253
256
|
});
|
|
254
257
|
|
|
255
|
-
const queries = createBlogQueryKeys(client);
|
|
258
|
+
const queries = createBlogQueryKeys(client, headers);
|
|
256
259
|
const listQuery = queries.posts.list({
|
|
257
260
|
query: undefined,
|
|
258
261
|
limit,
|