@mints-cloud/cxf-codegen 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +117 -0
  2. package/dist/components/ApiCall.d.ts +19 -0
  3. package/dist/components/ApiCall.d.ts.map +1 -0
  4. package/dist/components/ApiCall.js +92 -0
  5. package/dist/components/IsrPageWrapper.d.ts +1 -0
  6. package/dist/components/IsrPageWrapper.d.ts.map +1 -0
  7. package/dist/components/IsrPageWrapper.js +1 -0
  8. package/dist/index.d.ts +12 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +53 -0
  11. package/dist/lib/api-call-hooks.d.ts +25 -0
  12. package/dist/lib/api-call-hooks.d.ts.map +1 -0
  13. package/dist/lib/api-call-hooks.js +267 -0
  14. package/dist/lib/api-route-helpers.d.ts +10 -0
  15. package/dist/lib/api-route-helpers.d.ts.map +1 -0
  16. package/dist/lib/api-route-helpers.js +73 -0
  17. package/dist/lib/cxf-auth.d.ts +43 -0
  18. package/dist/lib/cxf-auth.d.ts.map +1 -0
  19. package/dist/lib/cxf-auth.js +189 -0
  20. package/dist/lib/server-props.d.ts +77 -0
  21. package/dist/lib/server-props.d.ts.map +1 -0
  22. package/dist/lib/server-props.js +353 -0
  23. package/dist/next.config.d.ts +9 -0
  24. package/dist/next.config.d.ts.map +1 -0
  25. package/dist/next.config.js +19 -0
  26. package/dist/pages/api/assets.d.ts +4 -0
  27. package/dist/pages/api/assets.d.ts.map +1 -0
  28. package/dist/pages/api/assets.js +30 -0
  29. package/dist/pages/api/cxf.d.ts +4 -0
  30. package/dist/pages/api/cxf.d.ts.map +1 -0
  31. package/dist/pages/api/cxf.js +48 -0
  32. package/dist/pages/app.d.ts +4 -0
  33. package/dist/pages/app.d.ts.map +1 -0
  34. package/dist/pages/app.js +28 -0
  35. package/dist/pages/plasmic-host.d.ts +3 -0
  36. package/dist/pages/plasmic-host.d.ts.map +1 -0
  37. package/dist/pages/plasmic-host.js +15 -0
  38. package/dist/register.d.ts +2 -0
  39. package/dist/register.d.ts.map +1 -0
  40. package/dist/register.js +91 -0
  41. package/package.json +100 -0
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # cxf-codegen
2
+
3
+ Plasmic + CXF integration library for Next.js projects. Provides API call components, server-side rendering helpers, and authentication utilities.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install cxf-codegen
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ Your project needs thin wrapper files that import from this library. The `create-plasmic-app` CLI generates these automatically, but you can also create them manually:
14
+
15
+ ### `pages/_app.tsx`
16
+
17
+ ```tsx
18
+ import "cxf-codegen/register";
19
+ export { default } from "cxf-codegen/pages/app";
20
+ ```
21
+
22
+ ### `pages/api/[...path].ts`
23
+
24
+ ```ts
25
+ export { default } from "cxf-codegen/pages/api/cxf";
26
+ ```
27
+
28
+ ### `pages/api/assets/[...path].ts`
29
+
30
+ ```ts
31
+ export { default } from "cxf-codegen/pages/api/assets";
32
+ ```
33
+
34
+ ### `pages/plasmic-host.tsx`
35
+
36
+ ```tsx
37
+ import "cxf-codegen/register";
38
+ export { default } from "cxf-codegen/pages/plasmic-host";
39
+ ```
40
+
41
+ ### `next.config.mjs`
42
+
43
+ ```js
44
+ import { cxfNextConfig } from "cxf-codegen";
45
+ export default cxfNextConfig;
46
+ ```
47
+
48
+ ## Environment Variables
49
+
50
+ Set these in your `.env` file:
51
+
52
+ ```
53
+ CXF_BASE_URL=https://your-cxf-instance.com
54
+ CXF_API_KEY=your-public-api-key
55
+ ```
56
+
57
+ Optional:
58
+
59
+ ```
60
+ CXF_DEV_API_KEY=your-dev-api-key
61
+ CXF_USER_API_KEY=your-user-api-key
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ### ApiCall Component
67
+
68
+ In Plasmic, use the `ApiCall` component to fetch data:
69
+
70
+ - **apiType**: `endpoint`, `contact`, `dev`, or `user`
71
+ - **path**: API path (e.g., `me`, `blog-posts`)
72
+ - **method**: HTTP method
73
+ - **params**: Query parameters
74
+ - **body**: Request body (for POST/PATCH/PUT/DELETE)
75
+
76
+ Data is available via `$ctx.response.*`:
77
+ - `$ctx.response.data` - The response data
78
+ - `$ctx.response.error` - Error message if failed
79
+ - `$ctx.response.loading` - Loading state
80
+ - `$ctx.response.success` - Boolean for success
81
+ - `$ctx.response.failed` - Boolean for failure
82
+
83
+ ### Server-Side Rendering (ISR/SSR)
84
+
85
+ Use `createServerProps` for pages that need pre-fetched data:
86
+
87
+ ```tsx
88
+ import { ServerPageWrapper, createServerProps, ServerPageProps } from "cxf-codegen";
89
+ import { PlasmicHomepage } from "../components/plasmic/Homepage";
90
+
91
+ function Homepage(props: ServerPageProps) {
92
+ return (
93
+ <ServerPageWrapper {...props}>
94
+ <PlasmicHomepage />
95
+ </ServerPageWrapper>
96
+ );
97
+ }
98
+
99
+ export default Homepage;
100
+
101
+ // ISR (default)
102
+ export const { getStaticProps } = createServerProps("/", PlasmicHomepage);
103
+
104
+ // Or SSR for authenticated pages
105
+ export const { getServerSideProps } = createServerProps("/profile", PlasmicProfile, {
106
+ mode: "ssr"
107
+ });
108
+ ```
109
+
110
+ ## Updating
111
+
112
+ To update the library across all your projects:
113
+
114
+ ```bash
115
+ npm update cxf-codegen
116
+ ```
117
+
@@ -0,0 +1,19 @@
1
+ import * as React from "react";
2
+ export type ApiType = "endpoint" | "contact" | "dev" | "user";
3
+ export interface ApiCallProps {
4
+ apiType?: ApiType;
5
+ path: string;
6
+ method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
7
+ params?: Record<string, any>;
8
+ body?: Record<string, any>;
9
+ initialData?: any;
10
+ autoFetch?: boolean;
11
+ trigger?: number;
12
+ onSuccess?: (data: any) => void;
13
+ onError?: (error: string) => void;
14
+ loadingContent?: React.ReactNode;
15
+ children?: React.ReactNode;
16
+ }
17
+ export declare function ApiCall(props: ApiCallProps): import("react/jsx-runtime").JSX.Element | null;
18
+ export default ApiCall;
19
+ //# sourceMappingURL=ApiCall.d.ts.map
@@ -0,0 +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,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,WAAW,CAAC,EAAE,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,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAsBD,wBAAgB,OAAO,CAAC,KAAK,EAAE,YAAY,kDAqD1C;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,92 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ApiCall = ApiCall;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const React = __importStar(require("react"));
39
+ const host_1 = require("@plasmicapp/host");
40
+ const api_call_hooks_1 = require("../lib/api-call-hooks");
41
+ function trimSlashes(p) {
42
+ return String(p || "").replace(/^\/+|\/+$/g, "");
43
+ }
44
+ function buildEndpointPath(apiType, rawPath) {
45
+ const clean = trimSlashes(rawPath);
46
+ switch (apiType) {
47
+ case "endpoint":
48
+ return `v1/endpoints/${clean}`;
49
+ case "contact":
50
+ return `v1/${clean}`;
51
+ case "dev":
52
+ return `dev/v1/${clean}`;
53
+ case "user":
54
+ return `user/v1/${clean}`;
55
+ default:
56
+ return clean;
57
+ }
58
+ }
59
+ function ApiCall(props) {
60
+ const { apiType = "contact", path, method = "GET", params, body, initialData, autoFetch, trigger, onSuccess, onError, loadingContent, children, } = props;
61
+ const endpointPath = React.useMemo(() => buildEndpointPath(apiType, path), [apiType, path]);
62
+ const shouldAutoFetch = autoFetch !== undefined ? autoFetch : method === "GET";
63
+ const { preloaded, hasExactPreload } = (0, api_call_hooks_1.useIsrPrefetch)(endpointPath, params, method, initialData);
64
+ const { data, error, loading } = (0, api_call_hooks_1.useApiFetch)({
65
+ endpointPath,
66
+ method,
67
+ params,
68
+ body,
69
+ preloaded,
70
+ hasExactPreload,
71
+ shouldAutoFetch,
72
+ trigger,
73
+ onSuccess,
74
+ onError,
75
+ unwrapData: true,
76
+ });
77
+ // If no children, render nothing (still performs the call + callbacks)
78
+ if (!children)
79
+ return null;
80
+ // If children exist, respect loadingContent for UX
81
+ if (loading)
82
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: loadingContent ?? (0, jsx_runtime_1.jsx)("div", { children: "Loading\u2026" }) });
83
+ const responseData = {
84
+ data: error ? null : data,
85
+ error,
86
+ loading,
87
+ success: !loading && !error && data !== null,
88
+ failed: !loading && error !== null,
89
+ };
90
+ return ((0, jsx_runtime_1.jsx)(host_1.DataProvider, { name: "response", data: responseData, children: children }));
91
+ }
92
+ exports.default = ApiCall;
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=IsrPageWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IsrPageWrapper.d.ts","sourceRoot":"","sources":["../../src/components/IsrPageWrapper.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,12 @@
1
+ export { ApiCall, type ApiCallProps, type ApiType } from "./components/ApiCall";
2
+ export { registerCodeComponents } from "./register";
3
+ export { CXF_COOKIE_NAMES, CXF_HEADER_NAMES, type CxfTokens, getTokensFromCookies, buildAuthHeaders, makeAuthenticatedRequest, extractSetCookieHeaders, extractTokensFromSetCookie, buildCookieHeader, getCxfBaseUrl, getCxfApiKey, buildCookieString, setTokensAsCookies, clearAuthCookies, } from "./lib/cxf-auth";
4
+ export { buildQueryString as buildApiQueryString, normalizePath, setAuthCookies, handleError, sendResponse, } from "./lib/api-route-helpers";
5
+ export { useIsrPrefetch, useApiFetch, type PreloadedDataResult, type UseApiFetchOptions, } from "./lib/api-call-hooks";
6
+ export { EndpointDataContext, PrefetchCollectorContext, PrefetchCollectorProvider, ServerPageWrapper, createServerProps, normalizeEndpointPath, buildQueryString, buildEndpointKey, type EndpointConfig, type ServerPageProps, type ServerPageWrapperProps, type PrefetchRequest, } from "./lib/server-props";
7
+ export { CxfApp } from "./pages/app";
8
+ export { PlasmicHost } from "./pages/plasmic-host";
9
+ export { cxfApiHandler } from "./pages/api/cxf";
10
+ export { assetsApiHandler } from "./pages/api/assets";
11
+ export { cxfNextConfig } from "./next.config";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,SAAS,EACd,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,gBAAgB,IAAI,mBAAmB,EACvC,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,cAAc,EACd,WAAW,EACX,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,GACxB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cxfNextConfig = exports.assetsApiHandler = exports.cxfApiHandler = exports.PlasmicHost = exports.CxfApp = exports.buildEndpointKey = exports.buildQueryString = exports.normalizeEndpointPath = exports.createServerProps = exports.ServerPageWrapper = exports.PrefetchCollectorProvider = exports.PrefetchCollectorContext = exports.EndpointDataContext = exports.useApiFetch = exports.useIsrPrefetch = exports.sendResponse = exports.handleError = exports.setAuthCookies = exports.normalizePath = exports.buildApiQueryString = exports.clearAuthCookies = exports.setTokensAsCookies = exports.buildCookieString = exports.getCxfApiKey = exports.getCxfBaseUrl = exports.buildCookieHeader = exports.extractTokensFromSetCookie = exports.extractSetCookieHeaders = exports.makeAuthenticatedRequest = exports.buildAuthHeaders = exports.getTokensFromCookies = exports.CXF_HEADER_NAMES = exports.CXF_COOKIE_NAMES = exports.registerCodeComponents = exports.ApiCall = void 0;
4
+ // Main exports
5
+ var ApiCall_1 = require("./components/ApiCall");
6
+ Object.defineProperty(exports, "ApiCall", { enumerable: true, get: function () { return ApiCall_1.ApiCall; } });
7
+ var register_1 = require("./register");
8
+ Object.defineProperty(exports, "registerCodeComponents", { enumerable: true, get: function () { return register_1.registerCodeComponents; } });
9
+ // Library exports
10
+ var cxf_auth_1 = require("./lib/cxf-auth");
11
+ Object.defineProperty(exports, "CXF_COOKIE_NAMES", { enumerable: true, get: function () { return cxf_auth_1.CXF_COOKIE_NAMES; } });
12
+ Object.defineProperty(exports, "CXF_HEADER_NAMES", { enumerable: true, get: function () { return cxf_auth_1.CXF_HEADER_NAMES; } });
13
+ Object.defineProperty(exports, "getTokensFromCookies", { enumerable: true, get: function () { return cxf_auth_1.getTokensFromCookies; } });
14
+ Object.defineProperty(exports, "buildAuthHeaders", { enumerable: true, get: function () { return cxf_auth_1.buildAuthHeaders; } });
15
+ Object.defineProperty(exports, "makeAuthenticatedRequest", { enumerable: true, get: function () { return cxf_auth_1.makeAuthenticatedRequest; } });
16
+ Object.defineProperty(exports, "extractSetCookieHeaders", { enumerable: true, get: function () { return cxf_auth_1.extractSetCookieHeaders; } });
17
+ Object.defineProperty(exports, "extractTokensFromSetCookie", { enumerable: true, get: function () { return cxf_auth_1.extractTokensFromSetCookie; } });
18
+ Object.defineProperty(exports, "buildCookieHeader", { enumerable: true, get: function () { return cxf_auth_1.buildCookieHeader; } });
19
+ Object.defineProperty(exports, "getCxfBaseUrl", { enumerable: true, get: function () { return cxf_auth_1.getCxfBaseUrl; } });
20
+ Object.defineProperty(exports, "getCxfApiKey", { enumerable: true, get: function () { return cxf_auth_1.getCxfApiKey; } });
21
+ Object.defineProperty(exports, "buildCookieString", { enumerable: true, get: function () { return cxf_auth_1.buildCookieString; } });
22
+ Object.defineProperty(exports, "setTokensAsCookies", { enumerable: true, get: function () { return cxf_auth_1.setTokensAsCookies; } });
23
+ Object.defineProperty(exports, "clearAuthCookies", { enumerable: true, get: function () { return cxf_auth_1.clearAuthCookies; } });
24
+ var api_route_helpers_1 = require("./lib/api-route-helpers");
25
+ Object.defineProperty(exports, "buildApiQueryString", { enumerable: true, get: function () { return api_route_helpers_1.buildQueryString; } });
26
+ Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return api_route_helpers_1.normalizePath; } });
27
+ Object.defineProperty(exports, "setAuthCookies", { enumerable: true, get: function () { return api_route_helpers_1.setAuthCookies; } });
28
+ Object.defineProperty(exports, "handleError", { enumerable: true, get: function () { return api_route_helpers_1.handleError; } });
29
+ Object.defineProperty(exports, "sendResponse", { enumerable: true, get: function () { return api_route_helpers_1.sendResponse; } });
30
+ var api_call_hooks_1 = require("./lib/api-call-hooks");
31
+ Object.defineProperty(exports, "useIsrPrefetch", { enumerable: true, get: function () { return api_call_hooks_1.useIsrPrefetch; } });
32
+ Object.defineProperty(exports, "useApiFetch", { enumerable: true, get: function () { return api_call_hooks_1.useApiFetch; } });
33
+ var server_props_1 = require("./lib/server-props");
34
+ Object.defineProperty(exports, "EndpointDataContext", { enumerable: true, get: function () { return server_props_1.EndpointDataContext; } });
35
+ Object.defineProperty(exports, "PrefetchCollectorContext", { enumerable: true, get: function () { return server_props_1.PrefetchCollectorContext; } });
36
+ Object.defineProperty(exports, "PrefetchCollectorProvider", { enumerable: true, get: function () { return server_props_1.PrefetchCollectorProvider; } });
37
+ Object.defineProperty(exports, "ServerPageWrapper", { enumerable: true, get: function () { return server_props_1.ServerPageWrapper; } });
38
+ Object.defineProperty(exports, "createServerProps", { enumerable: true, get: function () { return server_props_1.createServerProps; } });
39
+ Object.defineProperty(exports, "normalizeEndpointPath", { enumerable: true, get: function () { return server_props_1.normalizeEndpointPath; } });
40
+ Object.defineProperty(exports, "buildQueryString", { enumerable: true, get: function () { return server_props_1.buildQueryString; } });
41
+ Object.defineProperty(exports, "buildEndpointKey", { enumerable: true, get: function () { return server_props_1.buildEndpointKey; } });
42
+ // Page exports
43
+ var app_1 = require("./pages/app");
44
+ Object.defineProperty(exports, "CxfApp", { enumerable: true, get: function () { return app_1.CxfApp; } });
45
+ var plasmic_host_1 = require("./pages/plasmic-host");
46
+ Object.defineProperty(exports, "PlasmicHost", { enumerable: true, get: function () { return plasmic_host_1.PlasmicHost; } });
47
+ var cxf_1 = require("./pages/api/cxf");
48
+ Object.defineProperty(exports, "cxfApiHandler", { enumerable: true, get: function () { return cxf_1.cxfApiHandler; } });
49
+ var assets_1 = require("./pages/api/assets");
50
+ Object.defineProperty(exports, "assetsApiHandler", { enumerable: true, get: function () { return assets_1.assetsApiHandler; } });
51
+ // Config exports
52
+ var next_config_1 = require("./next.config");
53
+ Object.defineProperty(exports, "cxfNextConfig", { enumerable: true, get: function () { return next_config_1.cxfNextConfig; } });
@@ -0,0 +1,25 @@
1
+ export interface PreloadedDataResult {
2
+ preloaded: any;
3
+ hasExactPreload: boolean;
4
+ }
5
+ export declare function useIsrPrefetch(endpointPath: string | undefined, params: Record<string, any> | undefined, method?: string, initialData?: any): PreloadedDataResult;
6
+ export interface UseApiFetchOptions {
7
+ endpointPath: string;
8
+ method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
9
+ params?: Record<string, any>;
10
+ body?: Record<string, any>;
11
+ preloaded?: any;
12
+ hasExactPreload?: boolean;
13
+ shouldAutoFetch?: boolean;
14
+ trigger?: number;
15
+ onSuccess?: (data: any) => void;
16
+ onError?: (error: string) => void;
17
+ unwrapData?: boolean;
18
+ }
19
+ export declare function useApiFetch(options: UseApiFetchOptions): {
20
+ data: any;
21
+ error: string | null;
22
+ loading: boolean;
23
+ fetchData: () => (() => void) | undefined;
24
+ };
25
+ //# sourceMappingURL=api-call-hooks.d.ts.map
@@ -0,0 +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,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,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,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAkCD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB;;;;;EAyLtD"}
@@ -0,0 +1,267 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useIsrPrefetch = useIsrPrefetch;
37
+ exports.useApiFetch = useApiFetch;
38
+ const React = __importStar(require("react"));
39
+ const server_props_1 = require("./server-props");
40
+ function useIsrPrefetch(endpointPath, params, method, initialData) {
41
+ const prefetchCollector = React.useContext(server_props_1.PrefetchCollectorContext);
42
+ const didRegisterRef = React.useRef(false);
43
+ const isGet = !method || method === "GET";
44
+ if (typeof window === "undefined" &&
45
+ prefetchCollector &&
46
+ !didRegisterRef.current &&
47
+ endpointPath &&
48
+ isGet) {
49
+ try {
50
+ prefetchCollector.register({ endpointPath, params });
51
+ didRegisterRef.current = true;
52
+ }
53
+ catch (error) {
54
+ // Silently fail registration errors to avoid breaking the prepass
55
+ if (process.env.NODE_ENV !== "production") {
56
+ console.warn(`Failed to register prefetch for ${endpointPath}:`, error);
57
+ }
58
+ }
59
+ }
60
+ const endpointDataMap = React.useContext(server_props_1.EndpointDataContext);
61
+ return React.useMemo(() => {
62
+ if (initialData != null) {
63
+ return { preloaded: initialData, hasExactPreload: true };
64
+ }
65
+ if (!endpointPath || !isGet) {
66
+ return { preloaded: undefined, hasExactPreload: false };
67
+ }
68
+ const runtimeKey = (0, server_props_1.buildEndpointKey)(endpointPath, params);
69
+ const exact = endpointDataMap?.[runtimeKey];
70
+ if (exact !== undefined) {
71
+ return { preloaded: exact, hasExactPreload: true };
72
+ }
73
+ const normalizedPath = (0, server_props_1.normalizeEndpointPath)(endpointPath);
74
+ const matchingKey = Object.keys(endpointDataMap || {}).find((k) => k === normalizedPath || k.startsWith(`${normalizedPath}?`));
75
+ return matchingKey
76
+ ? { preloaded: endpointDataMap[matchingKey], hasExactPreload: false }
77
+ : { preloaded: undefined, hasExactPreload: false };
78
+ }, [initialData, endpointPath, params, endpointDataMap, isGet]);
79
+ }
80
+ function unwrapResponseData(data, shouldUnwrap) {
81
+ if (!shouldUnwrap ||
82
+ !data ||
83
+ typeof data !== "object" ||
84
+ Array.isArray(data) ||
85
+ !("data" in data) ||
86
+ Object.keys(data).length !== 1) {
87
+ return data;
88
+ }
89
+ return data.data;
90
+ }
91
+ function getUtmParamsFromLocation() {
92
+ if (typeof window === "undefined")
93
+ return null;
94
+ try {
95
+ const search = window.location?.search || "";
96
+ if (!search)
97
+ return null;
98
+ const usp = new URLSearchParams(search);
99
+ const utmParams = {};
100
+ usp.forEach((value, key) => {
101
+ if (key.toLowerCase().startsWith("utm_") && value) {
102
+ utmParams[key] = value;
103
+ }
104
+ });
105
+ return Object.keys(utmParams).length > 0 ? utmParams : null;
106
+ }
107
+ catch {
108
+ return null;
109
+ }
110
+ }
111
+ function useApiFetch(options) {
112
+ const { endpointPath, method = "GET", params, body, preloaded, hasExactPreload, shouldAutoFetch = true, trigger, onSuccess, onError, unwrapData = false, } = options;
113
+ // Also check context directly in case preloaded prop hasn't updated yet during hydration
114
+ const endpointDataMap = React.useContext(server_props_1.EndpointDataContext);
115
+ const contextData = React.useMemo(() => {
116
+ if (!endpointPath || method !== "GET")
117
+ return undefined;
118
+ const runtimeKey = (0, server_props_1.buildEndpointKey)(endpointPath, params);
119
+ const exact = endpointDataMap?.[runtimeKey];
120
+ if (exact !== undefined)
121
+ return exact;
122
+ const normalizedPath = (0, server_props_1.normalizeEndpointPath)(endpointPath);
123
+ const matchingKey = Object.keys(endpointDataMap || {}).find((k) => k === normalizedPath || k.startsWith(`${normalizedPath}?`));
124
+ return matchingKey ? endpointDataMap[matchingKey] : undefined;
125
+ }, [endpointPath, params, endpointDataMap, method]);
126
+ // Use context data if preloaded is not available (hydration case)
127
+ const effectivePreloaded = preloaded !== undefined ? preloaded : contextData;
128
+ const hasPreloadedData = effectivePreloaded !== undefined && effectivePreloaded !== null;
129
+ const [data, setData] = React.useState(effectivePreloaded ?? null);
130
+ const [error, setError] = React.useState(null);
131
+ // Only show loading if we don't have preloaded data and should auto-fetch
132
+ const [loading, setLoading] = React.useState(shouldAutoFetch && !hasPreloadedData);
133
+ const hasTriggeredSuccessRef = React.useRef(false);
134
+ const hasTriggeredErrorRef = React.useRef(false);
135
+ const isHydratingRef = React.useRef(true);
136
+ const hasCheckedHydrationRef = React.useRef(false);
137
+ // Mark hydration as complete after first render
138
+ React.useEffect(() => {
139
+ if (typeof window !== "undefined" && !hasCheckedHydrationRef.current) {
140
+ hasCheckedHydrationRef.current = true;
141
+ // Wait one tick to allow context to be available
142
+ const timeoutId = setTimeout(() => {
143
+ isHydratingRef.current = false;
144
+ }, 0);
145
+ return () => clearTimeout(timeoutId);
146
+ }
147
+ }, []);
148
+ // Update data when preloaded or context data changes (e.g., during SSR hydration)
149
+ React.useEffect(() => {
150
+ if (effectivePreloaded !== undefined && effectivePreloaded !== data) {
151
+ setData(effectivePreloaded);
152
+ setLoading(false);
153
+ // If we get preloaded data during hydration, mark hydration as complete
154
+ if (isHydratingRef.current)
155
+ isHydratingRef.current = false;
156
+ }
157
+ }, [effectivePreloaded, data]);
158
+ const fetchData = React.useCallback(() => {
159
+ if (!endpointPath)
160
+ return;
161
+ const controller = new AbortController();
162
+ (async () => {
163
+ try {
164
+ setLoading(true);
165
+ setError(null);
166
+ hasTriggeredSuccessRef.current = false;
167
+ hasTriggeredErrorRef.current = false;
168
+ const normalizedPath = (0, server_props_1.normalizeEndpointPath)(endpointPath);
169
+ // Merge current page UTM params into request params for GET requests.
170
+ // Explicit params take precedence over UTM values if keys overlap.
171
+ const utmParams = method === "GET" ? getUtmParamsFromLocation() : null;
172
+ const mergedParams = method === "GET"
173
+ ? { ...(utmParams || {}), ...(params || {}) }
174
+ : params;
175
+ const queryString = method === "GET" ? (0, server_props_1.buildQueryString)(mergedParams) : "";
176
+ const url = `/api/${normalizedPath}${queryString}`;
177
+ const fetchOptions = {
178
+ method,
179
+ headers: {
180
+ Accept: "application/json",
181
+ "Content-Type": "application/json",
182
+ },
183
+ credentials: "include",
184
+ signal: controller.signal,
185
+ };
186
+ if (method !== "GET" && body) {
187
+ fetchOptions.body = JSON.stringify(body);
188
+ }
189
+ const resp = await fetch(url, fetchOptions);
190
+ if (!resp.ok) {
191
+ if (resp.status === 401 || resp.status === 419) {
192
+ throw new Error("Authentication required. Please log in again.");
193
+ }
194
+ const errorText = await resp.text().catch(() => `Request failed (${resp.status})`);
195
+ throw new Error(errorText || `Request failed (${resp.status})`);
196
+ }
197
+ const contentType = resp.headers.get("content-type") || "";
198
+ const responseData = contentType.includes("application/json")
199
+ ? await resp.json()
200
+ : await resp.text();
201
+ const unwrappedData = unwrapResponseData(responseData, unwrapData);
202
+ setData(unwrappedData);
203
+ setError(null);
204
+ }
205
+ catch (e) {
206
+ if (e?.name === "AbortError")
207
+ return;
208
+ setError(e?.message || "Unknown error");
209
+ setData(null);
210
+ }
211
+ finally {
212
+ setLoading(false);
213
+ }
214
+ })();
215
+ return () => controller.abort();
216
+ }, [endpointPath, method, params, body, unwrapData]);
217
+ const prevTriggerRef = React.useRef(trigger);
218
+ React.useEffect(() => {
219
+ if (trigger !== undefined && trigger !== prevTriggerRef.current) {
220
+ prevTriggerRef.current = trigger;
221
+ if (trigger > 0)
222
+ fetchData();
223
+ }
224
+ }, [trigger, fetchData]);
225
+ // Only fetch if we should auto-fetch AND we don't have exact preloaded data
226
+ React.useEffect(() => {
227
+ // Skip fetch if we already have any preloaded data (exact or fuzzy)
228
+ if (hasPreloadedData)
229
+ return;
230
+ // Skip fetch if auto-fetch is disabled
231
+ if (!shouldAutoFetch)
232
+ return;
233
+ // During hydration, wait a bit to allow context to be available
234
+ if (isHydratingRef.current && typeof window !== "undefined") {
235
+ const timeoutId = setTimeout(() => {
236
+ // Re-check context and preloaded after hydration delay
237
+ const stillNoData = effectivePreloaded === undefined || effectivePreloaded === null;
238
+ if (stillNoData && shouldAutoFetch && !hasExactPreload) {
239
+ fetchData();
240
+ }
241
+ }, 0);
242
+ return () => clearTimeout(timeoutId);
243
+ }
244
+ // Fetch if we don't have preloaded data (non-hydration case)
245
+ if (!hasPreloadedData) {
246
+ return fetchData();
247
+ }
248
+ }, [shouldAutoFetch, hasExactPreload, hasPreloadedData, effectivePreloaded, fetchData]);
249
+ React.useEffect(() => {
250
+ if (data !== null && error === null && !loading && !hasTriggeredSuccessRef.current) {
251
+ hasTriggeredSuccessRef.current = true;
252
+ onSuccess?.(data);
253
+ }
254
+ }, [data, error, loading, onSuccess]);
255
+ React.useEffect(() => {
256
+ if (error !== null && !loading && !hasTriggeredErrorRef.current) {
257
+ hasTriggeredErrorRef.current = true;
258
+ onError?.(error);
259
+ }
260
+ }, [error, loading, onError]);
261
+ return {
262
+ data,
263
+ error,
264
+ loading,
265
+ fetchData,
266
+ };
267
+ }
@@ -0,0 +1,10 @@
1
+ import type { NextApiRequest, NextApiResponse } from "next";
2
+ export declare function buildQueryString(query: NextApiRequest["query"]): string;
3
+ export declare function normalizePath(pathSegments: string[] | string | undefined): string;
4
+ export declare function setAuthCookies(res: NextApiResponse, tokens: {
5
+ accessToken: string | null;
6
+ refreshToken: string | null;
7
+ }): void;
8
+ export declare function handleError(res: NextApiResponse, err: any): void;
9
+ export declare function sendResponse(res: NextApiResponse, response: Response): Promise<void>;
10
+ //# sourceMappingURL=api-route-helpers.d.ts.map
@@ -0,0 +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"}