@btst/stack 2.9.3 → 2.9.4
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/stack/src/plugins/blog/client/plugin.cjs +22 -11
- package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +22 -11
- package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +71 -39
- package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +71 -39
- package/dist/packages/stack/src/plugins/comments/client/plugin.cjs +62 -2
- package/dist/packages/stack/src/plugins/comments/client/plugin.mjs +63 -3
- package/dist/packages/stack/src/plugins/comments/client/utils.cjs +2 -11
- package/dist/packages/stack/src/plugins/comments/client/utils.mjs +2 -11
- package/dist/packages/stack/src/plugins/comments/error-utils.cjs +15 -0
- package/dist/packages/stack/src/plugins/comments/error-utils.mjs +13 -0
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +59 -31
- package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +59 -31
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.cjs +52 -25
- package/dist/packages/stack/src/plugins/ui-builder/client/plugin.mjs +53 -26
- package/dist/packages/stack/src/plugins/utils.cjs +6 -0
- package/dist/packages/stack/src/plugins/utils.mjs +5 -1
- package/dist/plugins/client/index.cjs +2 -0
- package/dist/plugins/client/index.d.cts +15 -1
- package/dist/plugins/client/index.d.mts +15 -1
- package/dist/plugins/client/index.d.ts +15 -1
- package/dist/plugins/client/index.mjs +1 -1
- package/dist/plugins/comments/client/index.d.cts +5 -0
- package/dist/plugins/comments/client/index.d.mts +5 -0
- package/dist/plugins/comments/client/index.d.ts +5 -0
- package/dist/plugins/comments/query-keys.cjs +4 -4
- package/dist/plugins/comments/query-keys.mjs +1 -1
- package/package.json +1 -1
- package/src/__tests__/client-plugin-ssr-loaders.test.ts +329 -0
- package/src/plugins/blog/client/plugin.tsx +23 -14
- package/src/plugins/client/index.ts +2 -0
- package/src/plugins/cms/client/plugin.tsx +73 -42
- package/src/plugins/comments/client/plugin.tsx +82 -2
- package/src/plugins/comments/client/utils.ts +2 -14
- package/src/plugins/comments/error-utils.ts +17 -0
- package/src/plugins/comments/query-keys.ts +1 -1
- package/src/plugins/form-builder/client/plugin.tsx +59 -35
- package/src/plugins/ui-builder/client/plugin.tsx +57 -27
- package/src/plugins/utils.ts +18 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { lazy } from 'react';
|
|
2
|
-
import { defineClientPlugin, isConnectionError } from '@btst/stack/plugins/client';
|
|
2
|
+
import { defineClientPlugin, createApiClient, isConnectionError } from '@btst/stack/plugins/client';
|
|
3
3
|
import { createRoute } from '@btst/yar';
|
|
4
|
+
import { createCommentsQueryKeys } from '../../../../../../plugins/comments/query-keys.mjs';
|
|
5
|
+
import { createSanitizedSSRLoaderError } from '../../utils.mjs';
|
|
4
6
|
|
|
5
7
|
const ModerationPageComponent = lazy(
|
|
6
8
|
() => import('./components/pages/moderation-page.mjs').then((m) => ({
|
|
@@ -15,7 +17,7 @@ const UserCommentsPageComponent = lazy(
|
|
|
15
17
|
function createModerationLoader(config) {
|
|
16
18
|
return async () => {
|
|
17
19
|
if (typeof window === "undefined") {
|
|
18
|
-
const { apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
20
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
19
21
|
const context = {
|
|
20
22
|
path: "/comments/moderation",
|
|
21
23
|
isSSR: true,
|
|
@@ -23,15 +25,40 @@ function createModerationLoader(config) {
|
|
|
23
25
|
apiBasePath,
|
|
24
26
|
headers
|
|
25
27
|
};
|
|
28
|
+
const client = createApiClient({
|
|
29
|
+
baseURL: apiBaseURL,
|
|
30
|
+
basePath: apiBasePath
|
|
31
|
+
});
|
|
32
|
+
const queries = createCommentsQueryKeys(client, headers);
|
|
33
|
+
const listQuery = queries.comments.list({
|
|
34
|
+
status: "pending",
|
|
35
|
+
limit: 20,
|
|
36
|
+
offset: 0
|
|
37
|
+
});
|
|
26
38
|
try {
|
|
27
39
|
if (hooks?.beforeLoadModeration) {
|
|
28
40
|
await hooks.beforeLoadModeration(context);
|
|
29
41
|
}
|
|
42
|
+
await queryClient.prefetchQuery(listQuery);
|
|
43
|
+
const queryState = queryClient.getQueryState(listQuery.queryKey);
|
|
44
|
+
if (queryState?.error && hooks?.onLoadError) {
|
|
45
|
+
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
46
|
+
await hooks.onLoadError(error, context);
|
|
47
|
+
}
|
|
30
48
|
} catch (error) {
|
|
31
49
|
if (isConnectionError(error)) {
|
|
32
50
|
console.warn(
|
|
33
51
|
"[btst/comments] route.loader() failed \u2014 no server running at build time."
|
|
34
52
|
);
|
|
53
|
+
} else {
|
|
54
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
55
|
+
await queryClient.prefetchQuery({
|
|
56
|
+
queryKey: listQuery.queryKey,
|
|
57
|
+
queryFn: () => {
|
|
58
|
+
throw errToStore;
|
|
59
|
+
},
|
|
60
|
+
retry: false
|
|
61
|
+
});
|
|
35
62
|
}
|
|
36
63
|
if (hooks?.onLoadError) {
|
|
37
64
|
await hooks.onLoadError(error, context);
|
|
@@ -43,7 +70,7 @@ function createModerationLoader(config) {
|
|
|
43
70
|
function createUserCommentsLoader(config) {
|
|
44
71
|
return async () => {
|
|
45
72
|
if (typeof window === "undefined") {
|
|
46
|
-
const { apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
73
|
+
const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
|
|
47
74
|
const context = {
|
|
48
75
|
path: "/comments",
|
|
49
76
|
isSSR: true,
|
|
@@ -51,15 +78,48 @@ function createUserCommentsLoader(config) {
|
|
|
51
78
|
apiBasePath,
|
|
52
79
|
headers
|
|
53
80
|
};
|
|
81
|
+
const client = createApiClient({
|
|
82
|
+
baseURL: apiBaseURL,
|
|
83
|
+
basePath: apiBasePath
|
|
84
|
+
});
|
|
85
|
+
const queries = createCommentsQueryKeys(client, headers);
|
|
86
|
+
const getUserListQuery = (currentUserId) => queries.comments.list({
|
|
87
|
+
authorId: currentUserId,
|
|
88
|
+
sort: "desc",
|
|
89
|
+
limit: 20,
|
|
90
|
+
offset: 0
|
|
91
|
+
});
|
|
54
92
|
try {
|
|
55
93
|
if (hooks?.beforeLoadUserComments) {
|
|
56
94
|
await hooks.beforeLoadUserComments(context);
|
|
57
95
|
}
|
|
96
|
+
const currentUserId = typeof context.currentUserId === "string" ? context.currentUserId : void 0;
|
|
97
|
+
if (currentUserId) {
|
|
98
|
+
const listQuery = getUserListQuery(currentUserId);
|
|
99
|
+
await queryClient.prefetchQuery(listQuery);
|
|
100
|
+
const queryState = queryClient.getQueryState(listQuery.queryKey);
|
|
101
|
+
if (queryState?.error && hooks?.onLoadError) {
|
|
102
|
+
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
103
|
+
await hooks.onLoadError(error, context);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
58
106
|
} catch (error) {
|
|
59
107
|
if (isConnectionError(error)) {
|
|
60
108
|
console.warn(
|
|
61
109
|
"[btst/comments] route.loader() failed \u2014 no server running at build time."
|
|
62
110
|
);
|
|
111
|
+
} else {
|
|
112
|
+
const currentUserId = typeof context.currentUserId === "string" ? context.currentUserId : void 0;
|
|
113
|
+
if (currentUserId) {
|
|
114
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
115
|
+
await queryClient.prefetchQuery({
|
|
116
|
+
queryKey: getUserListQuery(currentUserId).queryKey,
|
|
117
|
+
queryFn: () => {
|
|
118
|
+
throw errToStore;
|
|
119
|
+
},
|
|
120
|
+
retry: false
|
|
121
|
+
});
|
|
122
|
+
}
|
|
63
123
|
}
|
|
64
124
|
if (hooks?.onLoadError) {
|
|
65
125
|
await hooks.onLoadError(error, context);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const React = require('react');
|
|
4
|
+
const errorUtils = require('../error-utils.cjs');
|
|
4
5
|
|
|
5
6
|
function useResolvedCurrentUserId(raw) {
|
|
6
7
|
const [resolved, setResolved] = React.useState(
|
|
@@ -20,17 +21,7 @@ function useResolvedCurrentUserId(raw) {
|
|
|
20
21
|
}, [raw]);
|
|
21
22
|
return resolved;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
if (error instanceof Error) return error;
|
|
25
|
-
if (typeof error === "object" && error !== null) {
|
|
26
|
-
const obj = error;
|
|
27
|
-
const message = (typeof obj.message === "string" ? obj.message : null) || (typeof obj.error === "string" ? obj.error : null) || JSON.stringify(error);
|
|
28
|
-
const err = new Error(message);
|
|
29
|
-
Object.assign(err, error);
|
|
30
|
-
return err;
|
|
31
|
-
}
|
|
32
|
-
return new Error(String(error));
|
|
33
|
-
}
|
|
24
|
+
const toError = errorUtils.toError;
|
|
34
25
|
function getInitials(name) {
|
|
35
26
|
if (!name) return "?";
|
|
36
27
|
return name.split(" ").filter(Boolean).slice(0, 2).map((n) => n[0]).join("").toUpperCase();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
+
import { toError as toError$1 } from '../error-utils.mjs';
|
|
2
3
|
|
|
3
4
|
function useResolvedCurrentUserId(raw) {
|
|
4
5
|
const [resolved, setResolved] = useState(
|
|
@@ -18,17 +19,7 @@ function useResolvedCurrentUserId(raw) {
|
|
|
18
19
|
}, [raw]);
|
|
19
20
|
return resolved;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
if (error instanceof Error) return error;
|
|
23
|
-
if (typeof error === "object" && error !== null) {
|
|
24
|
-
const obj = error;
|
|
25
|
-
const message = (typeof obj.message === "string" ? obj.message : null) || (typeof obj.error === "string" ? obj.error : null) || JSON.stringify(error);
|
|
26
|
-
const err = new Error(message);
|
|
27
|
-
Object.assign(err, error);
|
|
28
|
-
return err;
|
|
29
|
-
}
|
|
30
|
-
return new Error(String(error));
|
|
31
|
-
}
|
|
22
|
+
const toError = toError$1;
|
|
32
23
|
function getInitials(name) {
|
|
33
24
|
if (!name) return "?";
|
|
34
25
|
return name.split(" ").filter(Boolean).slice(0, 2).map((n) => n[0]).join("").toUpperCase();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function toError(error) {
|
|
4
|
+
if (error instanceof Error) return error;
|
|
5
|
+
if (typeof error === "object" && error !== null) {
|
|
6
|
+
const obj = error;
|
|
7
|
+
const message = (typeof obj.message === "string" ? obj.message : null) || (typeof obj.error === "string" ? obj.error : null) || JSON.stringify(error);
|
|
8
|
+
const err = new Error(message);
|
|
9
|
+
Object.assign(err, error);
|
|
10
|
+
return err;
|
|
11
|
+
}
|
|
12
|
+
return new Error(String(error));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.toError = toError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function toError(error) {
|
|
2
|
+
if (error instanceof Error) return error;
|
|
3
|
+
if (typeof error === "object" && error !== null) {
|
|
4
|
+
const obj = error;
|
|
5
|
+
const message = (typeof obj.message === "string" ? obj.message : null) || (typeof obj.error === "string" ? obj.error : null) || JSON.stringify(error);
|
|
6
|
+
const err = new Error(message);
|
|
7
|
+
Object.assign(err, error);
|
|
8
|
+
return err;
|
|
9
|
+
}
|
|
10
|
+
return new Error(String(error));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { toError };
|
|
@@ -4,6 +4,7 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
const React = require('react');
|
|
5
5
|
const client = require('@btst/stack/plugins/client');
|
|
6
6
|
const yar = require('@btst/yar');
|
|
7
|
+
const utils = require('../../utils.cjs');
|
|
7
8
|
const plugins_formBuilder_queryKeys = require('../../../../../../plugins/form-builder/query-keys.cjs');
|
|
8
9
|
|
|
9
10
|
const FormListPageComponent = React.lazy(
|
|
@@ -32,6 +33,13 @@ function createFormListLoader(config) {
|
|
|
32
33
|
apiBasePath,
|
|
33
34
|
headers
|
|
34
35
|
};
|
|
36
|
+
const client$1 = client.createApiClient({
|
|
37
|
+
baseURL: apiBaseURL,
|
|
38
|
+
basePath: apiBasePath
|
|
39
|
+
});
|
|
40
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
41
|
+
const limit = 20;
|
|
42
|
+
const listQuery = queries.forms.list({ limit, offset: 0 });
|
|
35
43
|
try {
|
|
36
44
|
if (hooks?.beforeLoadFormList) {
|
|
37
45
|
await client.runClientHookWithShim(
|
|
@@ -39,13 +47,6 @@ function createFormListLoader(config) {
|
|
|
39
47
|
"Load prevented by beforeLoadFormList hook"
|
|
40
48
|
);
|
|
41
49
|
}
|
|
42
|
-
const client$1 = client.createApiClient({
|
|
43
|
-
baseURL: apiBaseURL,
|
|
44
|
-
basePath: apiBasePath
|
|
45
|
-
});
|
|
46
|
-
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
47
|
-
const limit = 20;
|
|
48
|
-
const listQuery = queries.forms.list({ limit, offset: 0 });
|
|
49
50
|
await queryClient.prefetchInfiniteQuery({
|
|
50
51
|
queryKey: listQuery.queryKey,
|
|
51
52
|
queryFn: async ({ pageParam = 0 }) => {
|
|
@@ -74,6 +75,16 @@ function createFormListLoader(config) {
|
|
|
74
75
|
console.warn(
|
|
75
76
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
76
77
|
);
|
|
78
|
+
} else {
|
|
79
|
+
const errToStore = utils.createSanitizedSSRLoaderError();
|
|
80
|
+
await queryClient.prefetchInfiniteQuery({
|
|
81
|
+
queryKey: listQuery.queryKey,
|
|
82
|
+
queryFn: () => {
|
|
83
|
+
throw errToStore;
|
|
84
|
+
},
|
|
85
|
+
initialPageParam: 0,
|
|
86
|
+
retry: false
|
|
87
|
+
});
|
|
77
88
|
}
|
|
78
89
|
if (hooks?.onLoadError) {
|
|
79
90
|
await hooks.onLoadError(error, context);
|
|
@@ -94,6 +105,12 @@ function createFormBuilderLoader(id, config) {
|
|
|
94
105
|
apiBasePath,
|
|
95
106
|
headers
|
|
96
107
|
};
|
|
108
|
+
const client$1 = client.createApiClient({
|
|
109
|
+
baseURL: apiBaseURL,
|
|
110
|
+
basePath: apiBasePath
|
|
111
|
+
});
|
|
112
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
113
|
+
const formQuery = id ? queries.forms.byId(id) : void 0;
|
|
97
114
|
try {
|
|
98
115
|
if (hooks?.beforeLoadFormBuilder) {
|
|
99
116
|
await client.runClientHookWithShim(
|
|
@@ -101,21 +118,14 @@ function createFormBuilderLoader(id, config) {
|
|
|
101
118
|
"Load prevented by beforeLoadFormBuilder hook"
|
|
102
119
|
);
|
|
103
120
|
}
|
|
104
|
-
const client$1 = client.createApiClient({
|
|
105
|
-
baseURL: apiBaseURL,
|
|
106
|
-
basePath: apiBasePath
|
|
107
|
-
});
|
|
108
|
-
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
109
121
|
if (id) {
|
|
110
|
-
await queryClient.prefetchQuery(
|
|
122
|
+
await queryClient.prefetchQuery(formQuery);
|
|
111
123
|
}
|
|
112
124
|
if (hooks?.afterLoadFormBuilder) {
|
|
113
125
|
await hooks.afterLoadFormBuilder(id, context);
|
|
114
126
|
}
|
|
115
127
|
if (id) {
|
|
116
|
-
const queryState = queryClient.getQueryState(
|
|
117
|
-
queries.forms.byId(id).queryKey
|
|
118
|
-
);
|
|
128
|
+
const queryState = queryClient.getQueryState(formQuery.queryKey);
|
|
119
129
|
if (queryState?.error && hooks?.onLoadError) {
|
|
120
130
|
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
121
131
|
await hooks.onLoadError(error, context);
|
|
@@ -126,6 +136,15 @@ function createFormBuilderLoader(id, config) {
|
|
|
126
136
|
console.warn(
|
|
127
137
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
128
138
|
);
|
|
139
|
+
} else if (formQuery) {
|
|
140
|
+
const errToStore = utils.createSanitizedSSRLoaderError();
|
|
141
|
+
await queryClient.prefetchQuery({
|
|
142
|
+
queryKey: formQuery.queryKey,
|
|
143
|
+
queryFn: () => {
|
|
144
|
+
throw errToStore;
|
|
145
|
+
},
|
|
146
|
+
retry: false
|
|
147
|
+
});
|
|
129
148
|
}
|
|
130
149
|
if (hooks?.onLoadError) {
|
|
131
150
|
await hooks.onLoadError(error, context);
|
|
@@ -146,6 +165,18 @@ function createSubmissionsLoader(formId, config) {
|
|
|
146
165
|
apiBasePath,
|
|
147
166
|
headers
|
|
148
167
|
};
|
|
168
|
+
const client$1 = client.createApiClient({
|
|
169
|
+
baseURL: apiBaseURL,
|
|
170
|
+
basePath: apiBasePath
|
|
171
|
+
});
|
|
172
|
+
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
173
|
+
const limit = 20;
|
|
174
|
+
const formQuery = queries.forms.byId(formId);
|
|
175
|
+
const submissionsQuery = queries.formSubmissions.list({
|
|
176
|
+
formId,
|
|
177
|
+
limit,
|
|
178
|
+
offset: 0
|
|
179
|
+
});
|
|
149
180
|
try {
|
|
150
181
|
if (hooks?.beforeLoadSubmissions) {
|
|
151
182
|
await client.runClientHookWithShim(
|
|
@@ -153,18 +184,7 @@ function createSubmissionsLoader(formId, config) {
|
|
|
153
184
|
"Load prevented by beforeLoadSubmissions hook"
|
|
154
185
|
);
|
|
155
186
|
}
|
|
156
|
-
|
|
157
|
-
baseURL: apiBaseURL,
|
|
158
|
-
basePath: apiBasePath
|
|
159
|
-
});
|
|
160
|
-
const queries = plugins_formBuilder_queryKeys.createFormBuilderQueryKeys(client$1, headers);
|
|
161
|
-
const limit = 20;
|
|
162
|
-
await queryClient.prefetchQuery(queries.forms.byId(formId));
|
|
163
|
-
const submissionsQuery = queries.formSubmissions.list({
|
|
164
|
-
formId,
|
|
165
|
-
limit,
|
|
166
|
-
offset: 0
|
|
167
|
-
});
|
|
187
|
+
await queryClient.prefetchQuery(formQuery);
|
|
168
188
|
await queryClient.prefetchInfiniteQuery({
|
|
169
189
|
queryKey: submissionsQuery.queryKey,
|
|
170
190
|
queryFn: async ({ pageParam = 0 }) => {
|
|
@@ -187,9 +207,7 @@ function createSubmissionsLoader(formId, config) {
|
|
|
187
207
|
if (hooks?.afterLoadSubmissions) {
|
|
188
208
|
await hooks.afterLoadSubmissions(formId, context);
|
|
189
209
|
}
|
|
190
|
-
const formState = queryClient.getQueryState(
|
|
191
|
-
queries.forms.byId(formId).queryKey
|
|
192
|
-
);
|
|
210
|
+
const formState = queryClient.getQueryState(formQuery.queryKey);
|
|
193
211
|
const submissionsState = queryClient.getQueryState(
|
|
194
212
|
submissionsQuery.queryKey
|
|
195
213
|
);
|
|
@@ -203,6 +221,16 @@ function createSubmissionsLoader(formId, config) {
|
|
|
203
221
|
console.warn(
|
|
204
222
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
205
223
|
);
|
|
224
|
+
} else {
|
|
225
|
+
const errToStore = utils.createSanitizedSSRLoaderError();
|
|
226
|
+
await queryClient.prefetchInfiniteQuery({
|
|
227
|
+
queryKey: submissionsQuery.queryKey,
|
|
228
|
+
queryFn: () => {
|
|
229
|
+
throw errToStore;
|
|
230
|
+
},
|
|
231
|
+
initialPageParam: 0,
|
|
232
|
+
retry: false
|
|
233
|
+
});
|
|
206
234
|
}
|
|
207
235
|
if (hooks?.onLoadError) {
|
|
208
236
|
await hooks.onLoadError(error, context);
|
|
@@ -2,6 +2,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { lazy } from 'react';
|
|
3
3
|
import { defineClientPlugin, createApiClient, runClientHookWithShim, isConnectionError } from '@btst/stack/plugins/client';
|
|
4
4
|
import { createRoute } from '@btst/yar';
|
|
5
|
+
import { createSanitizedSSRLoaderError } from '../../utils.mjs';
|
|
5
6
|
import { createFormBuilderQueryKeys } from '../../../../../../plugins/form-builder/query-keys.mjs';
|
|
6
7
|
|
|
7
8
|
const FormListPageComponent = lazy(
|
|
@@ -30,6 +31,13 @@ function createFormListLoader(config) {
|
|
|
30
31
|
apiBasePath,
|
|
31
32
|
headers
|
|
32
33
|
};
|
|
34
|
+
const client = createApiClient({
|
|
35
|
+
baseURL: apiBaseURL,
|
|
36
|
+
basePath: apiBasePath
|
|
37
|
+
});
|
|
38
|
+
const queries = createFormBuilderQueryKeys(client, headers);
|
|
39
|
+
const limit = 20;
|
|
40
|
+
const listQuery = queries.forms.list({ limit, offset: 0 });
|
|
33
41
|
try {
|
|
34
42
|
if (hooks?.beforeLoadFormList) {
|
|
35
43
|
await runClientHookWithShim(
|
|
@@ -37,13 +45,6 @@ function createFormListLoader(config) {
|
|
|
37
45
|
"Load prevented by beforeLoadFormList hook"
|
|
38
46
|
);
|
|
39
47
|
}
|
|
40
|
-
const client = createApiClient({
|
|
41
|
-
baseURL: apiBaseURL,
|
|
42
|
-
basePath: apiBasePath
|
|
43
|
-
});
|
|
44
|
-
const queries = createFormBuilderQueryKeys(client, headers);
|
|
45
|
-
const limit = 20;
|
|
46
|
-
const listQuery = queries.forms.list({ limit, offset: 0 });
|
|
47
48
|
await queryClient.prefetchInfiniteQuery({
|
|
48
49
|
queryKey: listQuery.queryKey,
|
|
49
50
|
queryFn: async ({ pageParam = 0 }) => {
|
|
@@ -72,6 +73,16 @@ function createFormListLoader(config) {
|
|
|
72
73
|
console.warn(
|
|
73
74
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
74
75
|
);
|
|
76
|
+
} else {
|
|
77
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
78
|
+
await queryClient.prefetchInfiniteQuery({
|
|
79
|
+
queryKey: listQuery.queryKey,
|
|
80
|
+
queryFn: () => {
|
|
81
|
+
throw errToStore;
|
|
82
|
+
},
|
|
83
|
+
initialPageParam: 0,
|
|
84
|
+
retry: false
|
|
85
|
+
});
|
|
75
86
|
}
|
|
76
87
|
if (hooks?.onLoadError) {
|
|
77
88
|
await hooks.onLoadError(error, context);
|
|
@@ -92,6 +103,12 @@ function createFormBuilderLoader(id, config) {
|
|
|
92
103
|
apiBasePath,
|
|
93
104
|
headers
|
|
94
105
|
};
|
|
106
|
+
const client = createApiClient({
|
|
107
|
+
baseURL: apiBaseURL,
|
|
108
|
+
basePath: apiBasePath
|
|
109
|
+
});
|
|
110
|
+
const queries = createFormBuilderQueryKeys(client, headers);
|
|
111
|
+
const formQuery = id ? queries.forms.byId(id) : void 0;
|
|
95
112
|
try {
|
|
96
113
|
if (hooks?.beforeLoadFormBuilder) {
|
|
97
114
|
await runClientHookWithShim(
|
|
@@ -99,21 +116,14 @@ function createFormBuilderLoader(id, config) {
|
|
|
99
116
|
"Load prevented by beforeLoadFormBuilder hook"
|
|
100
117
|
);
|
|
101
118
|
}
|
|
102
|
-
const client = createApiClient({
|
|
103
|
-
baseURL: apiBaseURL,
|
|
104
|
-
basePath: apiBasePath
|
|
105
|
-
});
|
|
106
|
-
const queries = createFormBuilderQueryKeys(client, headers);
|
|
107
119
|
if (id) {
|
|
108
|
-
await queryClient.prefetchQuery(
|
|
120
|
+
await queryClient.prefetchQuery(formQuery);
|
|
109
121
|
}
|
|
110
122
|
if (hooks?.afterLoadFormBuilder) {
|
|
111
123
|
await hooks.afterLoadFormBuilder(id, context);
|
|
112
124
|
}
|
|
113
125
|
if (id) {
|
|
114
|
-
const queryState = queryClient.getQueryState(
|
|
115
|
-
queries.forms.byId(id).queryKey
|
|
116
|
-
);
|
|
126
|
+
const queryState = queryClient.getQueryState(formQuery.queryKey);
|
|
117
127
|
if (queryState?.error && hooks?.onLoadError) {
|
|
118
128
|
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
119
129
|
await hooks.onLoadError(error, context);
|
|
@@ -124,6 +134,15 @@ function createFormBuilderLoader(id, config) {
|
|
|
124
134
|
console.warn(
|
|
125
135
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
126
136
|
);
|
|
137
|
+
} else if (formQuery) {
|
|
138
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
139
|
+
await queryClient.prefetchQuery({
|
|
140
|
+
queryKey: formQuery.queryKey,
|
|
141
|
+
queryFn: () => {
|
|
142
|
+
throw errToStore;
|
|
143
|
+
},
|
|
144
|
+
retry: false
|
|
145
|
+
});
|
|
127
146
|
}
|
|
128
147
|
if (hooks?.onLoadError) {
|
|
129
148
|
await hooks.onLoadError(error, context);
|
|
@@ -144,6 +163,18 @@ function createSubmissionsLoader(formId, config) {
|
|
|
144
163
|
apiBasePath,
|
|
145
164
|
headers
|
|
146
165
|
};
|
|
166
|
+
const client = createApiClient({
|
|
167
|
+
baseURL: apiBaseURL,
|
|
168
|
+
basePath: apiBasePath
|
|
169
|
+
});
|
|
170
|
+
const queries = createFormBuilderQueryKeys(client, headers);
|
|
171
|
+
const limit = 20;
|
|
172
|
+
const formQuery = queries.forms.byId(formId);
|
|
173
|
+
const submissionsQuery = queries.formSubmissions.list({
|
|
174
|
+
formId,
|
|
175
|
+
limit,
|
|
176
|
+
offset: 0
|
|
177
|
+
});
|
|
147
178
|
try {
|
|
148
179
|
if (hooks?.beforeLoadSubmissions) {
|
|
149
180
|
await runClientHookWithShim(
|
|
@@ -151,18 +182,7 @@ function createSubmissionsLoader(formId, config) {
|
|
|
151
182
|
"Load prevented by beforeLoadSubmissions hook"
|
|
152
183
|
);
|
|
153
184
|
}
|
|
154
|
-
|
|
155
|
-
baseURL: apiBaseURL,
|
|
156
|
-
basePath: apiBasePath
|
|
157
|
-
});
|
|
158
|
-
const queries = createFormBuilderQueryKeys(client, headers);
|
|
159
|
-
const limit = 20;
|
|
160
|
-
await queryClient.prefetchQuery(queries.forms.byId(formId));
|
|
161
|
-
const submissionsQuery = queries.formSubmissions.list({
|
|
162
|
-
formId,
|
|
163
|
-
limit,
|
|
164
|
-
offset: 0
|
|
165
|
-
});
|
|
185
|
+
await queryClient.prefetchQuery(formQuery);
|
|
166
186
|
await queryClient.prefetchInfiniteQuery({
|
|
167
187
|
queryKey: submissionsQuery.queryKey,
|
|
168
188
|
queryFn: async ({ pageParam = 0 }) => {
|
|
@@ -185,9 +205,7 @@ function createSubmissionsLoader(formId, config) {
|
|
|
185
205
|
if (hooks?.afterLoadSubmissions) {
|
|
186
206
|
await hooks.afterLoadSubmissions(formId, context);
|
|
187
207
|
}
|
|
188
|
-
const formState = queryClient.getQueryState(
|
|
189
|
-
queries.forms.byId(formId).queryKey
|
|
190
|
-
);
|
|
208
|
+
const formState = queryClient.getQueryState(formQuery.queryKey);
|
|
191
209
|
const submissionsState = queryClient.getQueryState(
|
|
192
210
|
submissionsQuery.queryKey
|
|
193
211
|
);
|
|
@@ -201,6 +219,16 @@ function createSubmissionsLoader(formId, config) {
|
|
|
201
219
|
console.warn(
|
|
202
220
|
"[btst/form-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.formBuilder.prefetchForRoute() for SSG data prefetching."
|
|
203
221
|
);
|
|
222
|
+
} else {
|
|
223
|
+
const errToStore = createSanitizedSSRLoaderError();
|
|
224
|
+
await queryClient.prefetchInfiniteQuery({
|
|
225
|
+
queryKey: submissionsQuery.queryKey,
|
|
226
|
+
queryFn: () => {
|
|
227
|
+
throw errToStore;
|
|
228
|
+
},
|
|
229
|
+
initialPageParam: 0,
|
|
230
|
+
retry: false
|
|
231
|
+
});
|
|
204
232
|
}
|
|
205
233
|
if (hooks?.onLoadError) {
|
|
206
234
|
await hooks.onLoadError(error, context);
|
|
@@ -5,6 +5,7 @@ const React = require('react');
|
|
|
5
5
|
const client = require('@btst/stack/plugins/client');
|
|
6
6
|
const yar = require('@btst/yar');
|
|
7
7
|
const plugins_cms_queryKeys = require('../../../../../../plugins/cms/query-keys.cjs');
|
|
8
|
+
const utils = require('../../utils.cjs');
|
|
8
9
|
const schemas = require('../schemas.cjs');
|
|
9
10
|
|
|
10
11
|
const PageListPageComponent = React.lazy(
|
|
@@ -29,6 +30,18 @@ function createPageListLoader(config) {
|
|
|
29
30
|
apiBasePath,
|
|
30
31
|
headers
|
|
31
32
|
};
|
|
33
|
+
const client$1 = client.createApiClient({
|
|
34
|
+
baseURL: apiBaseURL,
|
|
35
|
+
basePath: apiBasePath
|
|
36
|
+
});
|
|
37
|
+
const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
|
|
38
|
+
const limit = 20;
|
|
39
|
+
const listQuery = queries.cmsContent.list({
|
|
40
|
+
typeSlug,
|
|
41
|
+
limit,
|
|
42
|
+
offset: 0
|
|
43
|
+
});
|
|
44
|
+
const uiBuilderListQueryKey = [...listQuery.queryKey, "ui-builder"];
|
|
32
45
|
try {
|
|
33
46
|
if (hooks?.beforeLoadPageList) {
|
|
34
47
|
await client.runClientHookWithShim(
|
|
@@ -36,19 +49,8 @@ function createPageListLoader(config) {
|
|
|
36
49
|
"Load prevented by beforeLoadPageList hook"
|
|
37
50
|
);
|
|
38
51
|
}
|
|
39
|
-
const client$1 = client.createApiClient({
|
|
40
|
-
baseURL: apiBaseURL,
|
|
41
|
-
basePath: apiBasePath
|
|
42
|
-
});
|
|
43
|
-
const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
|
|
44
|
-
const limit = 20;
|
|
45
|
-
const listQuery = queries.cmsContent.list({
|
|
46
|
-
typeSlug,
|
|
47
|
-
limit,
|
|
48
|
-
offset: 0
|
|
49
|
-
});
|
|
50
52
|
await queryClient.prefetchInfiniteQuery({
|
|
51
|
-
queryKey:
|
|
53
|
+
queryKey: uiBuilderListQueryKey,
|
|
52
54
|
queryFn: async ({ pageParam = 0 }) => {
|
|
53
55
|
const response = await client$1("/content/:typeSlug", {
|
|
54
56
|
method: "GET",
|
|
@@ -67,14 +69,28 @@ function createPageListLoader(config) {
|
|
|
67
69
|
await hooks.afterLoadPageList(context);
|
|
68
70
|
}
|
|
69
71
|
const queryState = queryClient.getQueryState([
|
|
70
|
-
...
|
|
71
|
-
"ui-builder"
|
|
72
|
+
...uiBuilderListQueryKey
|
|
72
73
|
]);
|
|
73
74
|
if (queryState?.error && hooks?.onLoadError) {
|
|
74
75
|
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
75
76
|
await hooks.onLoadError(error, context);
|
|
76
77
|
}
|
|
77
78
|
} catch (error) {
|
|
79
|
+
if (client.isConnectionError(error)) {
|
|
80
|
+
console.warn(
|
|
81
|
+
"[btst/ui-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.uiBuilder.prefetchForRoute() for SSG data prefetching."
|
|
82
|
+
);
|
|
83
|
+
} else {
|
|
84
|
+
const errToStore = utils.createSanitizedSSRLoaderError();
|
|
85
|
+
await queryClient.prefetchInfiniteQuery({
|
|
86
|
+
queryKey: uiBuilderListQueryKey,
|
|
87
|
+
queryFn: () => {
|
|
88
|
+
throw errToStore;
|
|
89
|
+
},
|
|
90
|
+
initialPageParam: 0,
|
|
91
|
+
retry: false
|
|
92
|
+
});
|
|
93
|
+
}
|
|
78
94
|
if (hooks?.onLoadError) {
|
|
79
95
|
await hooks.onLoadError(error, context);
|
|
80
96
|
}
|
|
@@ -95,6 +111,12 @@ function createPageBuilderLoader(id, config) {
|
|
|
95
111
|
apiBasePath,
|
|
96
112
|
headers
|
|
97
113
|
};
|
|
114
|
+
const client$1 = client.createApiClient({
|
|
115
|
+
baseURL: apiBaseURL,
|
|
116
|
+
basePath: apiBasePath
|
|
117
|
+
});
|
|
118
|
+
const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
|
|
119
|
+
const pageQuery = id ? queries.cmsContent.detail(typeSlug, id) : void 0;
|
|
98
120
|
try {
|
|
99
121
|
if (hooks?.beforeLoadPageBuilder) {
|
|
100
122
|
await client.runClientHookWithShim(
|
|
@@ -102,29 +124,34 @@ function createPageBuilderLoader(id, config) {
|
|
|
102
124
|
"Load prevented by beforeLoadPageBuilder hook"
|
|
103
125
|
);
|
|
104
126
|
}
|
|
105
|
-
const client$1 = client.createApiClient({
|
|
106
|
-
baseURL: apiBaseURL,
|
|
107
|
-
basePath: apiBasePath
|
|
108
|
-
});
|
|
109
|
-
const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
|
|
110
127
|
if (id) {
|
|
111
|
-
await queryClient.prefetchQuery(
|
|
112
|
-
queries.cmsContent.detail(typeSlug, id)
|
|
113
|
-
);
|
|
128
|
+
await queryClient.prefetchQuery(pageQuery);
|
|
114
129
|
}
|
|
115
130
|
if (hooks?.afterLoadPageBuilder) {
|
|
116
131
|
await hooks.afterLoadPageBuilder(id, context);
|
|
117
132
|
}
|
|
118
133
|
if (id) {
|
|
119
|
-
const queryState = queryClient.getQueryState(
|
|
120
|
-
queries.cmsContent.detail(typeSlug, id).queryKey
|
|
121
|
-
);
|
|
134
|
+
const queryState = queryClient.getQueryState(pageQuery.queryKey);
|
|
122
135
|
if (queryState?.error && hooks?.onLoadError) {
|
|
123
136
|
const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
|
|
124
137
|
await hooks.onLoadError(error, context);
|
|
125
138
|
}
|
|
126
139
|
}
|
|
127
140
|
} catch (error) {
|
|
141
|
+
if (client.isConnectionError(error)) {
|
|
142
|
+
console.warn(
|
|
143
|
+
"[btst/ui-builder] route.loader() failed \u2014 no server running at build time. Use myStack.api.uiBuilder.prefetchForRoute() for SSG data prefetching."
|
|
144
|
+
);
|
|
145
|
+
} else if (pageQuery) {
|
|
146
|
+
const errToStore = utils.createSanitizedSSRLoaderError();
|
|
147
|
+
await queryClient.prefetchQuery({
|
|
148
|
+
queryKey: pageQuery.queryKey,
|
|
149
|
+
queryFn: () => {
|
|
150
|
+
throw errToStore;
|
|
151
|
+
},
|
|
152
|
+
retry: false
|
|
153
|
+
});
|
|
154
|
+
}
|
|
128
155
|
if (hooks?.onLoadError) {
|
|
129
156
|
await hooks.onLoadError(error, context);
|
|
130
157
|
}
|