@mints-cloud/cxf-codegen 1.0.1 → 1.0.3
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/README.md +15 -2
- package/dist/components/ApiCall.d.ts +5 -0
- package/dist/components/ApiCall.d.ts.map +1 -1
- package/dist/components/ApiCall.js +4 -2
- package/dist/lib/api-call-hooks.d.ts +2 -1
- package/dist/lib/api-call-hooks.d.ts.map +1 -1
- package/dist/lib/api-call-hooks.js +64 -11
- package/dist/lib/api-route-helpers.d.ts +1 -0
- package/dist/lib/api-route-helpers.d.ts.map +1 -1
- package/dist/lib/api-route-helpers.js +13 -0
- package/dist/lib/cxf-auth.d.ts +6 -3
- package/dist/lib/cxf-auth.d.ts.map +1 -1
- package/dist/lib/cxf-auth.js +11 -6
- package/dist/lib/server-props.d.ts.map +1 -1
- package/dist/lib/server-props.js +46 -4
- package/dist/pages/api/cxf.d.ts +5 -0
- package/dist/pages/api/cxf.d.ts.map +1 -1
- package/dist/pages/api/cxf.js +37 -4
- package/dist/pages/app.d.ts +6 -1
- package/dist/pages/app.d.ts.map +1 -1
- package/dist/pages/app.js +172 -10
- package/dist/pages/plasmic-host.d.ts +15 -1
- package/dist/pages/plasmic-host.d.ts.map +1 -1
- package/dist/pages/plasmic-host.js +55 -7
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,13 @@ Your project needs thin wrapper files that import from this library. The `create
|
|
|
17
17
|
```tsx
|
|
18
18
|
import '@/styles/globals.css'
|
|
19
19
|
import '@mints-cloud/cxf-codegen/register';
|
|
20
|
-
|
|
20
|
+
import type { AppProps } from 'next/app';
|
|
21
|
+
import CxfApp from '@mints-cloud/cxf-codegen/pages/app';
|
|
22
|
+
import projectcss from '../components/plasmic/<your-project>/plasmic.module.css';
|
|
23
|
+
|
|
24
|
+
export default function App(props: AppProps) {
|
|
25
|
+
return <CxfApp {...props} tokenClass={projectcss.plasmic_tokens} />;
|
|
26
|
+
}
|
|
21
27
|
```
|
|
22
28
|
|
|
23
29
|
### `pages/api/[...path].ts`
|
|
@@ -36,9 +42,16 @@ export { default } from '@mints-cloud/cxf-codegen/pages/api/assets';
|
|
|
36
42
|
|
|
37
43
|
```tsx
|
|
38
44
|
import '@mints-cloud/cxf-codegen/register';
|
|
39
|
-
|
|
45
|
+
import { PlasmicHost } from '@mints-cloud/cxf-codegen/pages/plasmic-host';
|
|
46
|
+
import projectcss from '../components/plasmic/<your-project>/plasmic.module.css';
|
|
47
|
+
|
|
48
|
+
export default function MyPlasmicHost() {
|
|
49
|
+
return <PlasmicHost tokenClass={projectcss.plasmic_tokens} />;
|
|
50
|
+
}
|
|
40
51
|
```
|
|
41
52
|
|
|
53
|
+
The `tokenClass` prop ensures Plasmic design tokens are applied correctly in the canvas.
|
|
54
|
+
|
|
42
55
|
### `next.config.mjs`
|
|
43
56
|
|
|
44
57
|
```js
|
|
@@ -12,6 +12,11 @@ export interface ApiCallProps {
|
|
|
12
12
|
onSuccess?: (data: any) => void;
|
|
13
13
|
onError?: (error: string) => void;
|
|
14
14
|
loadingContent?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* In Plasmic Studio canvas, throttle automatic GET refetches to this interval.
|
|
17
|
+
* Defaults to 5 minutes. Runtime pages are unaffected.
|
|
18
|
+
*/
|
|
19
|
+
canvasAutoFetchCooldownMs?: number;
|
|
15
20
|
children?: React.ReactNode;
|
|
16
21
|
}
|
|
17
22
|
export declare function ApiCall(props: ApiCallProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiCall.d.ts","sourceRoot":"","sources":["../../src/components/ApiCall.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAE9D,MAA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AAE,GAAG,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACjC;;;OAGG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAsBD,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,kDAyD1C;AAED,eAAe,OAAO,CAAC"}
|
|
@@ -57,7 +57,7 @@ function buildEndpointPath(apiType, rawPath) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function ApiCall(props) {
|
|
60
|
-
const { apiType = "contact", path, method = "GET", params, body, initialData, autoFetch, trigger, onSuccess, onError, loadingContent, children, } = props;
|
|
60
|
+
const { apiType = "contact", path, method = "GET", params, body, initialData, autoFetch, trigger, onSuccess, onError, loadingContent, canvasAutoFetchCooldownMs, children, } = props;
|
|
61
61
|
const endpointPath = React.useMemo(() => buildEndpointPath(apiType, path), [apiType, path]);
|
|
62
62
|
const shouldAutoFetch = autoFetch !== undefined ? autoFetch : method === "GET";
|
|
63
63
|
const { preloaded, hasExactPreload } = (0, api_call_hooks_1.useIsrPrefetch)(endpointPath, params, method, initialData);
|
|
@@ -73,13 +73,15 @@ function ApiCall(props) {
|
|
|
73
73
|
onSuccess,
|
|
74
74
|
onError,
|
|
75
75
|
unwrapData: true,
|
|
76
|
+
canvasAutoFetchCooldownMs,
|
|
76
77
|
});
|
|
77
78
|
// If no children, render nothing (still performs the call + callbacks)
|
|
78
79
|
if (!children)
|
|
79
80
|
return null;
|
|
80
81
|
// If children exist, respect loadingContent for UX
|
|
81
|
-
if (loading)
|
|
82
|
+
if (loading) {
|
|
82
83
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: loadingContent ?? (0, jsx_runtime_1.jsx)("div", { children: "Loading\u2026" }) });
|
|
84
|
+
}
|
|
83
85
|
const responseData = {
|
|
84
86
|
data: error ? null : data,
|
|
85
87
|
error,
|
|
@@ -15,11 +15,12 @@ export interface UseApiFetchOptions {
|
|
|
15
15
|
onSuccess?: (data: any) => void;
|
|
16
16
|
onError?: (error: string) => void;
|
|
17
17
|
unwrapData?: boolean;
|
|
18
|
+
canvasAutoFetchCooldownMs?: number;
|
|
18
19
|
}
|
|
19
20
|
export declare function useApiFetch(options: UseApiFetchOptions): {
|
|
20
21
|
data: any;
|
|
21
22
|
error: string | null;
|
|
22
23
|
loading: boolean;
|
|
23
|
-
fetchData: () => (() => void) | undefined;
|
|
24
|
+
fetchData: (reason?: "auto" | "trigger" | "manual") => (() => void) | undefined;
|
|
24
25
|
};
|
|
25
26
|
//# sourceMappingURL=api-call-hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-call-hooks.d.ts","sourceRoot":"","sources":["../../src/lib/api-call-hooks.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,GAAG,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,EACvC,MAAM,CAAC,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,GAAG,GAChB,mBAAmB,CA+CrB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAA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,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAmED,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB;;;;yBA0ER,MAAM,GAAG,SAAS,GAAG,QAAQ;EAuI3E"}
|
|
@@ -77,6 +77,21 @@ function useIsrPrefetch(endpointPath, params, method, initialData) {
|
|
|
77
77
|
: { preloaded: undefined, hasExactPreload: false };
|
|
78
78
|
}, [initialData, endpointPath, params, endpointDataMap, isGet]);
|
|
79
79
|
}
|
|
80
|
+
const EDITOR_AUTO_FETCH_COOLDOWN_MS = 5 * 60 * 1000;
|
|
81
|
+
const editorAutoFetchTimestamps = new Map();
|
|
82
|
+
const MAX_EDITOR_FETCH_KEYS = 20;
|
|
83
|
+
function pruneOldestEditorFetchEntries() {
|
|
84
|
+
if (editorAutoFetchTimestamps.size <= MAX_EDITOR_FETCH_KEYS)
|
|
85
|
+
return;
|
|
86
|
+
const overflowCount = editorAutoFetchTimestamps.size - MAX_EDITOR_FETCH_KEYS;
|
|
87
|
+
let removed = 0;
|
|
88
|
+
for (const key of editorAutoFetchTimestamps.keys()) {
|
|
89
|
+
editorAutoFetchTimestamps.delete(key);
|
|
90
|
+
removed += 1;
|
|
91
|
+
if (removed >= overflowCount)
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
80
95
|
function unwrapResponseData(data, shouldUnwrap) {
|
|
81
96
|
if (!shouldUnwrap ||
|
|
82
97
|
!data ||
|
|
@@ -88,6 +103,25 @@ function unwrapResponseData(data, shouldUnwrap) {
|
|
|
88
103
|
}
|
|
89
104
|
return data.data;
|
|
90
105
|
}
|
|
106
|
+
function stableSerialize(value) {
|
|
107
|
+
if (value === undefined)
|
|
108
|
+
return "";
|
|
109
|
+
if (value === null)
|
|
110
|
+
return "null";
|
|
111
|
+
if (Array.isArray(value)) {
|
|
112
|
+
return `[${value.map((item) => stableSerialize(item)).join(",")}]`;
|
|
113
|
+
}
|
|
114
|
+
if (typeof value === "object") {
|
|
115
|
+
const keys = Object.keys(value).sort();
|
|
116
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${stableSerialize(value[k])}`).join(",")}}`;
|
|
117
|
+
}
|
|
118
|
+
return JSON.stringify(value);
|
|
119
|
+
}
|
|
120
|
+
function isPlasmicHostRuntime() {
|
|
121
|
+
if (typeof window === "undefined")
|
|
122
|
+
return false;
|
|
123
|
+
return window.location.pathname.includes("/plasmic-host");
|
|
124
|
+
}
|
|
91
125
|
function getUtmParamsFromLocation() {
|
|
92
126
|
if (typeof window === "undefined")
|
|
93
127
|
return null;
|
|
@@ -109,7 +143,13 @@ function getUtmParamsFromLocation() {
|
|
|
109
143
|
}
|
|
110
144
|
}
|
|
111
145
|
function useApiFetch(options) {
|
|
112
|
-
const { endpointPath, method = "GET", params, body, preloaded, hasExactPreload, shouldAutoFetch = true, trigger, onSuccess, onError, unwrapData = false, } = options;
|
|
146
|
+
const { endpointPath, method = "GET", params, body, preloaded, hasExactPreload, shouldAutoFetch = true, trigger, onSuccess, onError, unwrapData = false, canvasAutoFetchCooldownMs = EDITOR_AUTO_FETCH_COOLDOWN_MS, } = options;
|
|
147
|
+
const paramsSignature = stableSerialize(params);
|
|
148
|
+
const bodySignature = stableSerialize(body);
|
|
149
|
+
const paramsRef = React.useRef(params);
|
|
150
|
+
const bodyRef = React.useRef(body);
|
|
151
|
+
paramsRef.current = params;
|
|
152
|
+
bodyRef.current = body;
|
|
113
153
|
// Also check context directly in case preloaded prop hasn't updated yet during hydration
|
|
114
154
|
const endpointDataMap = React.useContext(server_props_1.EndpointDataContext);
|
|
115
155
|
const contextData = React.useMemo(() => {
|
|
@@ -155,23 +195,36 @@ function useApiFetch(options) {
|
|
|
155
195
|
isHydratingRef.current = false;
|
|
156
196
|
}
|
|
157
197
|
}, [effectivePreloaded, data]);
|
|
158
|
-
const fetchData = React.useCallback(() => {
|
|
198
|
+
const fetchData = React.useCallback((reason = "manual") => {
|
|
159
199
|
if (!endpointPath)
|
|
160
200
|
return;
|
|
161
201
|
const controller = new AbortController();
|
|
162
202
|
(async () => {
|
|
163
203
|
try {
|
|
204
|
+
const normalizedPath = (0, server_props_1.normalizeEndpointPath)(endpointPath);
|
|
205
|
+
const requestKey = `${method}:${normalizedPath}:${paramsSignature}:${bodySignature}`;
|
|
206
|
+
if (reason === "auto" &&
|
|
207
|
+
method === "GET" &&
|
|
208
|
+
isPlasmicHostRuntime()) {
|
|
209
|
+
const now = Date.now();
|
|
210
|
+
const lastFetchAt = editorAutoFetchTimestamps.get(requestKey) ?? 0;
|
|
211
|
+
if (now - lastFetchAt < canvasAutoFetchCooldownMs) {
|
|
212
|
+
setLoading(false);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
editorAutoFetchTimestamps.set(requestKey, now);
|
|
216
|
+
pruneOldestEditorFetchEntries();
|
|
217
|
+
}
|
|
164
218
|
setLoading(true);
|
|
165
219
|
setError(null);
|
|
166
220
|
hasTriggeredSuccessRef.current = false;
|
|
167
221
|
hasTriggeredErrorRef.current = false;
|
|
168
|
-
const normalizedPath = (0, server_props_1.normalizeEndpointPath)(endpointPath);
|
|
169
222
|
// Merge current page UTM params into request params for GET requests.
|
|
170
223
|
// Explicit params take precedence over UTM values if keys overlap.
|
|
171
224
|
const utmParams = method === "GET" ? getUtmParamsFromLocation() : null;
|
|
172
225
|
const mergedParams = method === "GET"
|
|
173
|
-
? { ...(utmParams || {}), ...(
|
|
174
|
-
:
|
|
226
|
+
? { ...(utmParams || {}), ...(paramsRef.current || {}) }
|
|
227
|
+
: paramsRef.current;
|
|
175
228
|
const queryString = method === "GET" ? (0, server_props_1.buildQueryString)(mergedParams) : "";
|
|
176
229
|
const url = `/api/${normalizedPath}${queryString}`;
|
|
177
230
|
const fetchOptions = {
|
|
@@ -183,8 +236,8 @@ function useApiFetch(options) {
|
|
|
183
236
|
credentials: "include",
|
|
184
237
|
signal: controller.signal,
|
|
185
238
|
};
|
|
186
|
-
if (method !== "GET" &&
|
|
187
|
-
fetchOptions.body = JSON.stringify(
|
|
239
|
+
if (method !== "GET" && bodyRef.current) {
|
|
240
|
+
fetchOptions.body = JSON.stringify(bodyRef.current);
|
|
188
241
|
}
|
|
189
242
|
const resp = await fetch(url, fetchOptions);
|
|
190
243
|
if (!resp.ok) {
|
|
@@ -213,13 +266,13 @@ function useApiFetch(options) {
|
|
|
213
266
|
}
|
|
214
267
|
})();
|
|
215
268
|
return () => controller.abort();
|
|
216
|
-
}, [endpointPath, method,
|
|
269
|
+
}, [endpointPath, method, paramsSignature, bodySignature, unwrapData, canvasAutoFetchCooldownMs]);
|
|
217
270
|
const prevTriggerRef = React.useRef(trigger);
|
|
218
271
|
React.useEffect(() => {
|
|
219
272
|
if (trigger !== undefined && trigger !== prevTriggerRef.current) {
|
|
220
273
|
prevTriggerRef.current = trigger;
|
|
221
274
|
if (trigger > 0)
|
|
222
|
-
fetchData();
|
|
275
|
+
fetchData("trigger");
|
|
223
276
|
}
|
|
224
277
|
}, [trigger, fetchData]);
|
|
225
278
|
// Only fetch if we should auto-fetch AND we don't have exact preloaded data
|
|
@@ -236,14 +289,14 @@ function useApiFetch(options) {
|
|
|
236
289
|
// Re-check context and preloaded after hydration delay
|
|
237
290
|
const stillNoData = effectivePreloaded === undefined || effectivePreloaded === null;
|
|
238
291
|
if (stillNoData && shouldAutoFetch && !hasExactPreload) {
|
|
239
|
-
fetchData();
|
|
292
|
+
fetchData("auto");
|
|
240
293
|
}
|
|
241
294
|
}, 0);
|
|
242
295
|
return () => clearTimeout(timeoutId);
|
|
243
296
|
}
|
|
244
297
|
// Fetch if we don't have preloaded data (non-hydration case)
|
|
245
298
|
if (!hasPreloadedData) {
|
|
246
|
-
return fetchData();
|
|
299
|
+
return fetchData("auto");
|
|
247
300
|
}
|
|
248
301
|
}, [shouldAutoFetch, hasExactPreload, hasPreloadedData, effectivePreloaded, fetchData]);
|
|
249
302
|
React.useEffect(() => {
|
|
@@ -5,6 +5,7 @@ export declare function setAuthCookies(res: NextApiResponse, tokens: {
|
|
|
5
5
|
accessToken: string | null;
|
|
6
6
|
refreshToken: string | null;
|
|
7
7
|
}): void;
|
|
8
|
+
export declare function forwardExtraCookies(res: NextApiResponse, setCookieHeaders: string[]): void;
|
|
8
9
|
export declare function handleError(res: NextApiResponse, err: any): void;
|
|
9
10
|
export declare function sendResponse(res: NextApiResponse, response: Response): Promise<void>;
|
|
10
11
|
//# sourceMappingURL=api-route-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-route-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/api-route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAG5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,MAAM,CAavE;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAOjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE;IAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,QAavH;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,GAAG,QAMzD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,iBAwB1E"}
|
|
1
|
+
{"version":3,"file":"api-route-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/api-route-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAG5D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,MAAM,CAavE;AAED,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAOjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,MAAM,EAAE;IAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,QAavH;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,EAAE,QAYnF;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,GAAG,QAMzD;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,iBAwB1E"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildQueryString = buildQueryString;
|
|
4
4
|
exports.normalizePath = normalizePath;
|
|
5
5
|
exports.setAuthCookies = setAuthCookies;
|
|
6
|
+
exports.forwardExtraCookies = forwardExtraCookies;
|
|
6
7
|
exports.handleError = handleError;
|
|
7
8
|
exports.sendResponse = sendResponse;
|
|
8
9
|
const cxf_auth_1 = require("./cxf-auth");
|
|
@@ -42,6 +43,18 @@ function setAuthCookies(res, tokens) {
|
|
|
42
43
|
res.setHeader("Set-Cookie", cookies);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
function forwardExtraCookies(res, setCookieHeaders) {
|
|
47
|
+
const authCookieNames = new Set([cxf_auth_1.CXF_COOKIE_NAMES.ACCESS_TOKEN, cxf_auth_1.CXF_COOKIE_NAMES.REFRESH_TOKEN]);
|
|
48
|
+
const extraCookies = setCookieHeaders.filter((header) => {
|
|
49
|
+
const name = header.split("=")[0]?.trim();
|
|
50
|
+
return !authCookieNames.has(name);
|
|
51
|
+
});
|
|
52
|
+
if (extraCookies.length > 0) {
|
|
53
|
+
const existing = res.getHeader("Set-Cookie");
|
|
54
|
+
const current = Array.isArray(existing) ? existing : existing ? [String(existing)] : [];
|
|
55
|
+
res.setHeader("Set-Cookie", [...current, ...extraCookies]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
function handleError(res, err) {
|
|
46
59
|
const dev = process.env.NODE_ENV !== "production";
|
|
47
60
|
return res.status(500).json({
|
package/dist/lib/cxf-auth.d.ts
CHANGED
|
@@ -14,15 +14,18 @@ export interface CxfTokens {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function getTokensFromCookies(cookieHeader?: string | null): CxfTokens;
|
|
16
16
|
export declare function buildAuthHeaders(tokens: CxfTokens, apiKey?: string | null, userToken?: string | null): Record<string, string>;
|
|
17
|
-
export
|
|
17
|
+
export interface AuthenticatedRequestOptions {
|
|
18
18
|
method?: string;
|
|
19
|
-
body?:
|
|
19
|
+
body?: string | Record<string, unknown>;
|
|
20
|
+
rawBody?: Buffer | Uint8Array;
|
|
21
|
+
contentType?: string;
|
|
20
22
|
tokens?: CxfTokens;
|
|
21
23
|
apiKey?: string | null;
|
|
22
24
|
userToken?: string | null;
|
|
23
25
|
cookieHeader?: string | null;
|
|
24
26
|
retryOnAuthError?: boolean;
|
|
25
|
-
}
|
|
27
|
+
}
|
|
28
|
+
export declare function makeAuthenticatedRequest(url: string, options?: AuthenticatedRequestOptions): Promise<{
|
|
26
29
|
response: Response;
|
|
27
30
|
newTokens: CxfTokens;
|
|
28
31
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cxf-auth.d.ts","sourceRoot":"","sources":["../../src/lib/cxf-auth.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC;AAEX,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,C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IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAsB,wBAAwB,CAC5C,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC,CA0DD;AAMD,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE,CAUpE;AAED,wBAAgB,0BAA0B,CACxC,gBAAgB,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,GAC5C,SAAS,CAmBX;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAS3D;AAED,wBAAgB,aAAa,IAAI,MAAM,CAMtC;AAED,wBAAgB,YAAY,CAAC,IAAI,GAAE,QAAQ,GAAG,KAAK,GAAG,MAAiB,GAAG,MAAM,GAAG,IAAI,CAYtF;AAMD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACf,GACL,MAAM,CAaR;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAuB1D;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAQvC"}
|
package/dist/lib/cxf-auth.js
CHANGED
|
@@ -47,7 +47,6 @@ function getTokensFromCookies(cookieHeader) {
|
|
|
47
47
|
function buildAuthHeaders(tokens, apiKey, userToken) {
|
|
48
48
|
const headers = {
|
|
49
49
|
Accept: "application/json",
|
|
50
|
-
"Content-Type": "application/json",
|
|
51
50
|
};
|
|
52
51
|
if (apiKey)
|
|
53
52
|
headers[exports.CXF_HEADER_NAMES.API_KEY] = apiKey;
|
|
@@ -60,16 +59,22 @@ function buildAuthHeaders(tokens, apiKey, userToken) {
|
|
|
60
59
|
return headers;
|
|
61
60
|
}
|
|
62
61
|
async function makeAuthenticatedRequest(url, options = {}) {
|
|
63
|
-
const { method = "GET", body, tokens: providedTokens, apiKey, userToken, cookieHeader, retryOnAuthError = true, } = options;
|
|
62
|
+
const { method = "GET", body, rawBody, contentType, tokens: providedTokens, apiKey, userToken, cookieHeader, retryOnAuthError = true, } = options;
|
|
64
63
|
const tokens = providedTokens || getTokensFromCookies(cookieHeader);
|
|
65
|
-
const buildRequestOptions = (
|
|
66
|
-
const headers = buildAuthHeaders(
|
|
64
|
+
const buildRequestOptions = (reqTokens, cookieStr) => {
|
|
65
|
+
const headers = buildAuthHeaders(reqTokens, apiKey, userToken);
|
|
67
66
|
if (cookieStr) {
|
|
68
67
|
headers.Cookie = cookieStr;
|
|
69
68
|
}
|
|
70
69
|
const requestOptions = { method, headers };
|
|
71
|
-
if (
|
|
72
|
-
|
|
70
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
71
|
+
headers["Content-Type"] = contentType || "application/json";
|
|
72
|
+
if (rawBody) {
|
|
73
|
+
requestOptions.body = new Uint8Array(rawBody);
|
|
74
|
+
}
|
|
75
|
+
else if (body) {
|
|
76
|
+
requestOptions.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
return requestOptions;
|
|
75
80
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-props.d.ts","sourceRoot":"","sources":["../../src/lib/server-props.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAC;AAG1D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EACV,YAAY,EACZ,OAAO,EACP,cAAc,EACd,YAAY,GACb,EAAE,sBAAsB,2CAwCxB;AAqID;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe,EAC3E,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,aAAa,CAAC,GAAG,CAAC,EACpC,OAAO,GAAE;IACP,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,KAAK,CAAC;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC,CAAC;CACxE,GACL;IACD,cAAc,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACnC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAC5C,CA0GA"}
|
package/dist/lib/server-props.js
CHANGED
|
@@ -93,6 +93,46 @@ function extractUtmParamsFromQuery(query) {
|
|
|
93
93
|
}
|
|
94
94
|
return result;
|
|
95
95
|
}
|
|
96
|
+
function extractDynamicParamNames(routePattern) {
|
|
97
|
+
const names = [];
|
|
98
|
+
if (!routePattern)
|
|
99
|
+
return names;
|
|
100
|
+
const regex = /\[\[?\.\.\.([^\]]+)\]?\]|\[([^\]]+)\]/g;
|
|
101
|
+
let match = null;
|
|
102
|
+
while ((match = regex.exec(routePattern))) {
|
|
103
|
+
const paramName = match[1] || match[2];
|
|
104
|
+
if (paramName && !names.includes(paramName)) {
|
|
105
|
+
names.push(paramName);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return names;
|
|
109
|
+
}
|
|
110
|
+
function extractRouteParams(context, dynamicParamNames) {
|
|
111
|
+
const result = {};
|
|
112
|
+
if (dynamicParamNames.length === 0)
|
|
113
|
+
return result;
|
|
114
|
+
const paramsSource = (context?.params || context?.query || {});
|
|
115
|
+
for (const name of dynamicParamNames) {
|
|
116
|
+
const value = paramsSource[name];
|
|
117
|
+
if (value != null) {
|
|
118
|
+
result[name] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
function mergeRequestParams(routeParams, utmParams, explicitParams) {
|
|
124
|
+
const merged = { ...(routeParams || {}), ...(utmParams || {}) };
|
|
125
|
+
if (!explicitParams || typeof explicitParams !== "object")
|
|
126
|
+
return merged;
|
|
127
|
+
for (const key of Object.keys(explicitParams)) {
|
|
128
|
+
const value = explicitParams[key];
|
|
129
|
+
// Nullish explicit values should not erase route-derived defaults.
|
|
130
|
+
if (value !== null && value !== undefined) {
|
|
131
|
+
merged[key] = value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return merged;
|
|
135
|
+
}
|
|
96
136
|
exports.PrefetchCollectorContext = React.createContext(null);
|
|
97
137
|
// Provider that collects prefetch requests during component rendering
|
|
98
138
|
// Used during build-time prepass to discover all API calls
|
|
@@ -267,6 +307,7 @@ async function fetchEndpointData(endpointPath, params, cookieHeader) {
|
|
|
267
307
|
* - SSR: Fresh data on every request, always has access to request cookies
|
|
268
308
|
*/
|
|
269
309
|
function createServerProps(path, PlasmicComponent, options = {}) {
|
|
310
|
+
const dynamicParamNames = extractDynamicParamNames(path);
|
|
270
311
|
const { mode = "isr", revalidate = 60, endpoints = [] } = options;
|
|
271
312
|
const finalRevalidate = process.env.NODE_ENV === "production" ? revalidate : 60;
|
|
272
313
|
const isSSR = mode === "ssr";
|
|
@@ -312,18 +353,19 @@ function createServerProps(path, PlasmicComponent, options = {}) {
|
|
|
312
353
|
const cookieHeader = isSSR
|
|
313
354
|
? context.req?.headers?.cookie || null
|
|
314
355
|
: context.req?.headers?.cookie || null;
|
|
356
|
+
const routeParams = extractRouteParams(context, dynamicParamNames);
|
|
315
357
|
const utmFromRequest = isSSR ? extractUtmParamsFromQuery(context?.query) : {};
|
|
316
358
|
const endpointData = {};
|
|
317
359
|
if (merged.length > 0) {
|
|
318
360
|
const seen = new Set();
|
|
319
361
|
const fetchPromises = merged.map(async (cfg) => {
|
|
320
|
-
// Merge UTM params from the
|
|
321
|
-
const
|
|
322
|
-
const key = buildEndpointKey(cfg.endpointPath,
|
|
362
|
+
// Merge route params + UTM params from the request; explicit component params override when non-null.
|
|
363
|
+
const requestParams = mergeRequestParams(routeParams, utmFromRequest, cfg.params);
|
|
364
|
+
const key = buildEndpointKey(cfg.endpointPath, requestParams);
|
|
323
365
|
if (seen.has(key))
|
|
324
366
|
return; // Deduplicate
|
|
325
367
|
seen.add(key);
|
|
326
|
-
const data = await fetchEndpointData(cfg.endpointPath,
|
|
368
|
+
const data = await fetchEndpointData(cfg.endpointPath, requestParams, cookieHeader);
|
|
327
369
|
if (data !== null) {
|
|
328
370
|
endpointData[key] = data;
|
|
329
371
|
}
|
package/dist/pages/api/cxf.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
2
|
+
export declare const config: {
|
|
3
|
+
api: {
|
|
4
|
+
bodyParser: boolean;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
2
7
|
export declare function cxfApiHandler(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
3
8
|
export default cxfApiHandler;
|
|
4
9
|
//# sourceMappingURL=cxf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cxf.d.ts","sourceRoot":"","sources":["../../../src/pages/api/cxf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"cxf.d.ts","sourceRoot":"","sources":["../../../src/pages/api/cxf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAK5D,eAAO,MAAM,MAAM;;;;CAElB,CAAC;AAcF,wBAAsB,aAAa,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,eAAe,iBAqE5E;AAED,eAAe,aAAa,CAAC"}
|
package/dist/pages/api/cxf.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.config = void 0;
|
|
3
4
|
exports.cxfApiHandler = cxfApiHandler;
|
|
4
5
|
const cxf_auth_1 = require("../../lib/cxf-auth");
|
|
5
6
|
const api_route_helpers_1 = require("../../lib/api-route-helpers");
|
|
7
|
+
// Disable Next.js body parser to support multipart/binary requests
|
|
8
|
+
exports.config = {
|
|
9
|
+
api: { bodyParser: false },
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Reads the raw body from a Next.js request as a Buffer.
|
|
13
|
+
*/
|
|
14
|
+
function getRawBody(req) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const chunks = [];
|
|
17
|
+
req.on("data", (chunk) => chunks.push(chunk));
|
|
18
|
+
req.on("end", () => resolve(Buffer.concat(chunks)));
|
|
19
|
+
req.on("error", reject);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
6
22
|
async function cxfApiHandler(req, res) {
|
|
7
23
|
const allowedMethods = ["GET", "POST", "PATCH", "PUT", "DELETE"];
|
|
8
24
|
if (!allowedMethods.includes(req.method || "")) {
|
|
@@ -25,20 +41,37 @@ async function cxfApiHandler(req, res) {
|
|
|
25
41
|
? normalizedPath
|
|
26
42
|
: `v1/endpoints/${normalizedPath}`;
|
|
27
43
|
const targetUrl = `${baseUrl}/api/${targetPath}${(0, api_route_helpers_1.buildQueryString)(req.query)}`;
|
|
28
|
-
const body = req.method !== "GET" && req.method !== "HEAD" && req.body ? req.body : undefined;
|
|
29
44
|
const retryOnAuthError = !normalizedPath.match(/^(v1\/(login|register)|dev\/v1\/)/);
|
|
30
|
-
const
|
|
45
|
+
const isGet = req.method === "GET" || req.method === "HEAD";
|
|
46
|
+
const requestOptions = {
|
|
31
47
|
method: req.method || "GET",
|
|
32
|
-
body,
|
|
33
48
|
apiKey,
|
|
34
49
|
userToken: null,
|
|
35
50
|
cookieHeader: req.headers.cookie || null,
|
|
36
51
|
retryOnAuthError,
|
|
37
|
-
}
|
|
52
|
+
};
|
|
53
|
+
if (!isGet) {
|
|
54
|
+
const rawBody = await getRawBody(req);
|
|
55
|
+
const contentType = req.headers["content-type"] || "";
|
|
56
|
+
const isMultipart = contentType.includes("multipart/form-data");
|
|
57
|
+
if (rawBody.length > 0) {
|
|
58
|
+
if (isMultipart) {
|
|
59
|
+
// Forward raw body preserving multipart boundaries
|
|
60
|
+
requestOptions.rawBody = rawBody;
|
|
61
|
+
requestOptions.contentType = contentType;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// JSON/text body
|
|
65
|
+
requestOptions.body = rawBody.toString("utf-8");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const { response, newTokens } = await (0, cxf_auth_1.makeAuthenticatedRequest)(targetUrl, requestOptions);
|
|
38
70
|
const setCookieHeaders = (0, cxf_auth_1.extractSetCookieHeaders)(response);
|
|
39
71
|
const tokens = (0, cxf_auth_1.extractTokensFromSetCookie)(setCookieHeaders);
|
|
40
72
|
const finalTokens = tokens.accessToken || tokens.refreshToken ? tokens : newTokens;
|
|
41
73
|
(0, api_route_helpers_1.setAuthCookies)(res, finalTokens);
|
|
74
|
+
(0, api_route_helpers_1.forwardExtraCookies)(res, setCookieHeaders);
|
|
42
75
|
return (0, api_route_helpers_1.sendResponse)(res, response);
|
|
43
76
|
}
|
|
44
77
|
catch (err) {
|
package/dist/pages/app.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { AppProps } from "next/app";
|
|
2
|
-
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type CxfAppProps = AppProps & {
|
|
4
|
+
tokenClass?: string;
|
|
5
|
+
appRootId?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function CxfApp({ Component, pageProps, tokenClass, appRootId }: CxfAppProps): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<React.AwaitedReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
3
8
|
export default CxfApp;
|
|
4
9
|
//# sourceMappingURL=app.d.ts.map
|
package/dist/pages/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/pages/app.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/pages/app.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,KAAK,WAAW,GAAG,QAAQ,GAAG;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAYF,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAyB,EAAE,EAAE,WAAW,iKAkLlG;AAED,eAAe,MAAM,CAAC"}
|
package/dist/pages/app.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -9,20 +42,149 @@ const react_web_1 = require("@plasmicapp/react-web");
|
|
|
9
42
|
const query_1 = require("@plasmicapp/react-web/lib/query");
|
|
10
43
|
const head_1 = __importDefault(require("next/head"));
|
|
11
44
|
const link_1 = __importDefault(require("next/link"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
45
|
+
const React = __importStar(require("react"));
|
|
46
|
+
function isNonEmptyObject(value) {
|
|
47
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
48
|
+
}
|
|
49
|
+
function CxfApp({ Component, pageProps, tokenClass, appRootId = "plasmic-app" }) {
|
|
50
|
+
const storeRef = React.useRef({
|
|
51
|
+
endpointData: {},
|
|
52
|
+
queryCache: {},
|
|
53
|
+
meta: {},
|
|
54
|
+
});
|
|
55
|
+
// Merge page props from hard loads / direct SSR navigation.
|
|
56
|
+
const incoming = pageProps;
|
|
57
|
+
if (isNonEmptyObject(incoming.endpointData)) {
|
|
58
|
+
storeRef.current.endpointData = {
|
|
59
|
+
...storeRef.current.endpointData,
|
|
60
|
+
...incoming.endpointData,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (isNonEmptyObject(incoming.queryCache)) {
|
|
64
|
+
storeRef.current.queryCache = {
|
|
65
|
+
...storeRef.current.queryCache,
|
|
66
|
+
...incoming.queryCache,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (incoming.buildId) {
|
|
70
|
+
storeRef.current.meta.buildId = incoming.buildId;
|
|
71
|
+
}
|
|
72
|
+
if (incoming.buildTimestamp) {
|
|
73
|
+
storeRef.current.meta.buildTimestamp = incoming.buildTimestamp;
|
|
74
|
+
}
|
|
75
|
+
if (incoming._prefetchEnabled != null) {
|
|
76
|
+
storeRef.current.meta._prefetchEnabled = incoming._prefetchEnabled;
|
|
77
|
+
}
|
|
78
|
+
// Merge page props from /_next/data responses used by client navigation + prefetch.
|
|
79
|
+
React.useEffect(() => {
|
|
80
|
+
if (typeof window === "undefined") {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const originalFetch = window.fetch.bind(window);
|
|
84
|
+
window.fetch = async (...args) => {
|
|
85
|
+
const response = await originalFetch(...args);
|
|
86
|
+
try {
|
|
87
|
+
const input = args[0];
|
|
88
|
+
let url = "";
|
|
89
|
+
if (typeof input === "string") {
|
|
90
|
+
url = input;
|
|
91
|
+
}
|
|
92
|
+
else if (input instanceof URL) {
|
|
93
|
+
url = input.toString();
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
url = input.url;
|
|
97
|
+
}
|
|
98
|
+
if (url.includes("/_next/data/")) {
|
|
99
|
+
const clone = response.clone();
|
|
100
|
+
const contentType = clone.headers.get("content-type") || "";
|
|
101
|
+
if (clone.ok && contentType.includes("application/json")) {
|
|
102
|
+
const json = (await clone.json());
|
|
103
|
+
const nextPageProps = json?.pageProps;
|
|
104
|
+
if (isNonEmptyObject(nextPageProps?.endpointData)) {
|
|
105
|
+
storeRef.current.endpointData = {
|
|
106
|
+
...storeRef.current.endpointData,
|
|
107
|
+
...nextPageProps.endpointData,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (isNonEmptyObject(nextPageProps?.queryCache)) {
|
|
111
|
+
storeRef.current.queryCache = {
|
|
112
|
+
...storeRef.current.queryCache,
|
|
113
|
+
...nextPageProps.queryCache,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (nextPageProps?.buildId) {
|
|
117
|
+
storeRef.current.meta.buildId = nextPageProps.buildId;
|
|
118
|
+
}
|
|
119
|
+
if (nextPageProps?.buildTimestamp) {
|
|
120
|
+
storeRef.current.meta.buildTimestamp = nextPageProps.buildTimestamp;
|
|
121
|
+
}
|
|
122
|
+
if (nextPageProps?._prefetchEnabled != null) {
|
|
123
|
+
storeRef.current.meta._prefetchEnabled = nextPageProps._prefetchEnabled;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// Intentionally ignore parsing issues; never block navigation.
|
|
130
|
+
}
|
|
131
|
+
return response;
|
|
132
|
+
};
|
|
133
|
+
return () => {
|
|
134
|
+
window.fetch = originalFetch;
|
|
135
|
+
};
|
|
136
|
+
}, []);
|
|
137
|
+
React.useEffect(() => {
|
|
138
|
+
if (!tokenClass) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const applyTokenClass = () => {
|
|
142
|
+
document.documentElement.classList.add(tokenClass);
|
|
143
|
+
document.body.classList.add(tokenClass);
|
|
144
|
+
document.getElementById(appRootId)?.classList.add(tokenClass);
|
|
145
|
+
};
|
|
146
|
+
applyTokenClass();
|
|
147
|
+
const observer = new MutationObserver(() => {
|
|
148
|
+
applyTokenClass();
|
|
149
|
+
});
|
|
150
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
151
|
+
return () => {
|
|
152
|
+
observer.disconnect();
|
|
153
|
+
document.documentElement.classList.remove(tokenClass);
|
|
154
|
+
document.body.classList.remove(tokenClass);
|
|
155
|
+
document.getElementById(appRootId)?.classList.remove(tokenClass);
|
|
156
|
+
};
|
|
157
|
+
}, [tokenClass, appRootId]);
|
|
158
|
+
const mergedEndpointData = storeRef.current.endpointData;
|
|
159
|
+
const mergedQueryCache = storeRef.current.queryCache;
|
|
160
|
+
const safePageProps = {
|
|
161
|
+
...pageProps,
|
|
162
|
+
...storeRef.current.meta,
|
|
163
|
+
...(isNonEmptyObject(mergedEndpointData)
|
|
164
|
+
? { endpointData: { ...mergedEndpointData } }
|
|
165
|
+
: { endpointData: undefined }),
|
|
166
|
+
...(isNonEmptyObject(mergedQueryCache)
|
|
167
|
+
? { queryCache: { ...mergedQueryCache } }
|
|
168
|
+
: { queryCache: undefined }),
|
|
169
|
+
};
|
|
170
|
+
// Detect ISR/SSR pages using explicit markers and merged caches.
|
|
171
|
+
const serverPageProps = safePageProps;
|
|
15
172
|
const isServerPage = Boolean(serverPageProps._prefetchEnabled ||
|
|
16
173
|
Component.isrEnabled ||
|
|
17
174
|
serverPageProps.queryCache ||
|
|
18
175
|
serverPageProps.endpointData);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
176
|
+
const wrapWithTokenClass = (node) => {
|
|
177
|
+
if (!tokenClass) {
|
|
178
|
+
return node;
|
|
179
|
+
}
|
|
180
|
+
return (0, jsx_runtime_1.jsx)("div", { className: tokenClass, children: node });
|
|
181
|
+
};
|
|
182
|
+
// Fast path: minimal server-side rendering for ISR pages.
|
|
183
|
+
if (typeof window === "undefined" && isServerPage) {
|
|
184
|
+
return wrapWithTokenClass((0, jsx_runtime_1.jsx)(react_web_1.PlasmicRootProvider, { Head: head_1.default, Link: link_1.default, children: (0, jsx_runtime_1.jsx)(Component, { ...safePageProps }) }));
|
|
23
185
|
}
|
|
24
|
-
// Regular path: full initialization for client-side and non-ISR pages
|
|
25
|
-
|
|
26
|
-
return (
|
|
186
|
+
// Regular path: full initialization for client-side and non-ISR pages.
|
|
187
|
+
const content = ((0, jsx_runtime_1.jsx)(react_web_1.PlasmicRootProvider, { Head: head_1.default, Link: link_1.default, children: (0, jsx_runtime_1.jsx)(query_1.PlasmicQueryDataProvider, { suspense: true, children: (0, jsx_runtime_1.jsx)(Component, { ...safePageProps }) }) }));
|
|
188
|
+
return wrapWithTokenClass(content);
|
|
27
189
|
}
|
|
28
190
|
exports.default = CxfApp;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface PlasmicHostProps {
|
|
2
|
+
/**
|
|
3
|
+
* The Plasmic token class to apply to document elements.
|
|
4
|
+
* Typically obtained from your project's plasmic.module.css file:
|
|
5
|
+
* `import projectcss from "./components/plasmic/<project>/plasmic.module.css"`
|
|
6
|
+
* Then pass `projectcss.plasmic_tokens` as the tokenClass prop.
|
|
7
|
+
*/
|
|
8
|
+
tokenClass?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The ID of the app root element to apply the token class to.
|
|
11
|
+
* Defaults to "plasmic-app".
|
|
12
|
+
*/
|
|
13
|
+
appRootId?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function PlasmicHost({ tokenClass, appRootId }: PlasmicHostProps): import("react/jsx-runtime").JSX.Element;
|
|
2
16
|
export default PlasmicHost;
|
|
3
17
|
//# sourceMappingURL=plasmic-host.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plasmic-host.d.ts","sourceRoot":"","sources":["../../src/pages/plasmic-host.tsx"],"names":[],"mappings":"AAUA,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"plasmic-host.d.ts","sourceRoot":"","sources":["../../src/pages/plasmic-host.tsx"],"names":[],"mappings":"AAUA,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,WAAW,CAAC,EAAE,UAAU,EAAE,SAAyB,EAAE,EAAE,gBAAgB,2CA2BtF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1,15 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.PlasmicHost = PlasmicHost;
|
|
4
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const React = __importStar(require("react"));
|
|
5
39
|
const host_1 = require("@plasmicapp/host");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
40
|
+
function PlasmicHost({ tokenClass, appRootId = 'plasmic-app' }) {
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (!tokenClass)
|
|
43
|
+
return;
|
|
44
|
+
const applyTokenClass = () => {
|
|
45
|
+
document.documentElement.classList.add(tokenClass);
|
|
46
|
+
document.body.classList.add(tokenClass);
|
|
47
|
+
document.getElementById(appRootId)?.classList.add(tokenClass);
|
|
48
|
+
};
|
|
49
|
+
applyTokenClass();
|
|
50
|
+
const observer = new MutationObserver(() => {
|
|
51
|
+
applyTokenClass();
|
|
52
|
+
});
|
|
53
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
54
|
+
return () => {
|
|
55
|
+
observer.disconnect();
|
|
56
|
+
document.documentElement.classList.remove(tokenClass);
|
|
57
|
+
document.body.classList.remove(tokenClass);
|
|
58
|
+
document.getElementById(appRootId)?.classList.remove(tokenClass);
|
|
59
|
+
};
|
|
60
|
+
}, [tokenClass, appRootId]);
|
|
13
61
|
return (0, jsx_runtime_1.jsx)(host_1.PlasmicCanvasHost, {});
|
|
14
62
|
}
|
|
15
63
|
exports.default = PlasmicHost;
|
package/dist/register.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,SA4GrC"}
|
package/dist/register.js
CHANGED
|
@@ -51,6 +51,14 @@ function registerCodeComponents() {
|
|
|
51
51
|
description: "Automatically fetch on mount (default: true for GET, false for others).",
|
|
52
52
|
advanced: true,
|
|
53
53
|
},
|
|
54
|
+
canvasAutoFetchCooldownMs: {
|
|
55
|
+
type: "number",
|
|
56
|
+
displayName: "Canvas refresh interval (ms)",
|
|
57
|
+
description: "In Plasmic Studio only, identical GET requests are throttled to this interval (default: 300000). Runtime pages are unaffected.",
|
|
58
|
+
defaultValue: 300000,
|
|
59
|
+
advanced: true,
|
|
60
|
+
hidden: (props) => props.method && props.method !== "GET",
|
|
61
|
+
},
|
|
54
62
|
trigger: {
|
|
55
63
|
type: "number",
|
|
56
64
|
displayName: "Trigger",
|
|
@@ -85,6 +93,23 @@ function registerCodeComponents() {
|
|
|
85
93
|
},
|
|
86
94
|
},
|
|
87
95
|
},
|
|
96
|
+
actions: [
|
|
97
|
+
{
|
|
98
|
+
type: "button-action",
|
|
99
|
+
label: "Refetch now",
|
|
100
|
+
hidden: (props) => props.method && props.method !== "GET",
|
|
101
|
+
onClick: ({ componentProps, studioOps }) => {
|
|
102
|
+
const nextTrigger = Number(componentProps?.trigger ?? 0) + 1;
|
|
103
|
+
if (typeof studioOps?.updateProps === "function") {
|
|
104
|
+
studioOps.updateProps({ trigger: nextTrigger });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (typeof studioOps?.updateStates === "function") {
|
|
108
|
+
studioOps.updateStates({ trigger: nextTrigger });
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
88
113
|
});
|
|
89
114
|
}
|
|
90
115
|
// Auto-register when imported
|