@mints-cloud/cxf-codegen 1.0.2 → 1.0.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/README.md +40 -1
- package/dist/components/ApiCall.d.ts +5 -0
- package/dist/components/ApiCall.d.ts.map +1 -1
- package/dist/components/ApiCall.js +18 -3
- package/dist/components/JsonLdSchemas.d.ts +104 -0
- package/dist/components/JsonLdSchemas.d.ts.map +1 -0
- package/dist/components/JsonLdSchemas.js +380 -0
- package/dist/components/MetadataOverrides.d.ts +84 -0
- package/dist/components/MetadataOverrides.d.ts.map +1 -0
- package/dist/components/MetadataOverrides.js +270 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- 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/assets-query-params.d.ts +11 -0
- package/dist/lib/assets-query-params.d.ts.map +1 -0
- package/dist/lib/assets-query-params.js +130 -0
- package/dist/lib/cxf-auth.d.ts +7 -3
- package/dist/lib/cxf-auth.d.ts.map +1 -1
- package/dist/lib/cxf-auth.js +17 -6
- package/dist/lib/seo-utils.d.ts +22 -0
- package/dist/lib/seo-utils.d.ts.map +1 -0
- package/dist/lib/seo-utils.js +228 -0
- package/dist/lib/server-props.d.ts.map +1 -1
- package/dist/lib/server-props.js +46 -4
- package/dist/pages/api/assets.d.ts.map +1 -1
- package/dist/pages/api/assets.js +27 -1
- 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 +4 -1
- package/dist/pages/app.d.ts.map +1 -1
- package/dist/pages/app.js +11 -6
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +193 -2
- package/package.json +13 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets-query-params.d.ts","sourceRoot":"","sources":["../../src/lib/assets-query-params.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,8BAA8B,2BAA2B,CAAC;AAEvE,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAChD,MAAM,MAAM,oBAAoB,GAC5B,cAAc,GACd,cAAc,EAAE,GAChB,IAAI,GACJ,SAAS,CAAC;AACd,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;AACpE,MAAM,MAAM,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;AAgB3E,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC1C,0BAA0B,CA8B5B;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC1C,MAAM,CAMR;AAED,wBAAgB,iCAAiC,CAC/C,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACtC,0BAA0B,CAqB5B;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,QAsBlF"}
|
|
@@ -0,0 +1,130 @@
|
|
|
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.ASSET_QUERY_PARAMS_COOKIE_NAME = void 0;
|
|
37
|
+
exports.normalizeAssetQueryParams = normalizeAssetQueryParams;
|
|
38
|
+
exports.serializeAssetQueryParamsCookie = serializeAssetQueryParamsCookie;
|
|
39
|
+
exports.extractAssetQueryParamsFromCookie = extractAssetQueryParamsFromCookie;
|
|
40
|
+
exports.useSyncAssetQueryParams = useSyncAssetQueryParams;
|
|
41
|
+
const React = __importStar(require("react"));
|
|
42
|
+
exports.ASSET_QUERY_PARAMS_COOKIE_NAME = "cxf_asset_query_params";
|
|
43
|
+
function isPrimitiveParamValue(value) {
|
|
44
|
+
const valueType = typeof value;
|
|
45
|
+
return valueType === "string" || valueType === "number" || valueType === "boolean";
|
|
46
|
+
}
|
|
47
|
+
function sortObjectKeys(value) {
|
|
48
|
+
return Object.keys(value)
|
|
49
|
+
.sort()
|
|
50
|
+
.reduce((acc, key) => {
|
|
51
|
+
acc[key] = value[key];
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
}
|
|
55
|
+
function normalizeAssetQueryParams(params) {
|
|
56
|
+
if (!params || typeof params !== "object" || Array.isArray(params)) {
|
|
57
|
+
return {};
|
|
58
|
+
}
|
|
59
|
+
const normalized = {};
|
|
60
|
+
for (const key of Object.keys(params)) {
|
|
61
|
+
if (!key || key === "path")
|
|
62
|
+
continue;
|
|
63
|
+
const rawValue = params[key];
|
|
64
|
+
if (rawValue == null)
|
|
65
|
+
continue;
|
|
66
|
+
if (Array.isArray(rawValue)) {
|
|
67
|
+
const values = rawValue
|
|
68
|
+
.filter((entry) => isPrimitiveParamValue(entry))
|
|
69
|
+
.map((entry) => String(entry));
|
|
70
|
+
if (values.length === 1) {
|
|
71
|
+
normalized[key] = values[0];
|
|
72
|
+
}
|
|
73
|
+
else if (values.length > 1) {
|
|
74
|
+
normalized[key] = values;
|
|
75
|
+
}
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (isPrimitiveParamValue(rawValue)) {
|
|
79
|
+
normalized[key] = String(rawValue);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return sortObjectKeys(normalized);
|
|
83
|
+
}
|
|
84
|
+
function serializeAssetQueryParamsCookie(params) {
|
|
85
|
+
const normalized = normalizeAssetQueryParams(params);
|
|
86
|
+
if (Object.keys(normalized).length === 0) {
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
return encodeURIComponent(JSON.stringify(normalized));
|
|
90
|
+
}
|
|
91
|
+
function extractAssetQueryParamsFromCookie(cookieHeader) {
|
|
92
|
+
if (!cookieHeader)
|
|
93
|
+
return {};
|
|
94
|
+
const targetPrefix = `${exports.ASSET_QUERY_PARAMS_COOKIE_NAME}=`;
|
|
95
|
+
const cookieEntry = cookieHeader
|
|
96
|
+
.split(";")
|
|
97
|
+
.map((part) => part.trim())
|
|
98
|
+
.find((part) => part.startsWith(targetPrefix));
|
|
99
|
+
if (!cookieEntry)
|
|
100
|
+
return {};
|
|
101
|
+
const rawValue = cookieEntry.slice(targetPrefix.length);
|
|
102
|
+
if (!rawValue)
|
|
103
|
+
return {};
|
|
104
|
+
try {
|
|
105
|
+
const decoded = decodeURIComponent(rawValue);
|
|
106
|
+
const parsed = JSON.parse(decoded);
|
|
107
|
+
return normalizeAssetQueryParams(parsed);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function useSyncAssetQueryParams(params) {
|
|
114
|
+
const cookieValue = serializeAssetQueryParamsCookie(params);
|
|
115
|
+
React.useEffect(() => {
|
|
116
|
+
if (typeof document === "undefined") {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const secureAttr = typeof window !== "undefined" && window.location.protocol === "https:"
|
|
120
|
+
? "; Secure"
|
|
121
|
+
: "";
|
|
122
|
+
if (!cookieValue) {
|
|
123
|
+
document.cookie = `${exports.ASSET_QUERY_PARAMS_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax${secureAttr}`;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
// Persist for 30 days; refreshed whenever params change.
|
|
127
|
+
const maxAgeSeconds = 30 * 24 * 60 * 60;
|
|
128
|
+
document.cookie = `${exports.ASSET_QUERY_PARAMS_COOKIE_NAME}=${cookieValue}; Path=/; Max-Age=${maxAgeSeconds}; SameSite=Lax${secureAttr}`;
|
|
129
|
+
}, [cookieValue]);
|
|
130
|
+
}
|
package/dist/lib/cxf-auth.d.ts
CHANGED
|
@@ -14,15 +14,19 @@ 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;
|
|
22
|
+
extraHeaders?: Record<string, string | undefined>;
|
|
20
23
|
tokens?: CxfTokens;
|
|
21
24
|
apiKey?: string | null;
|
|
22
25
|
userToken?: string | null;
|
|
23
26
|
cookieHeader?: string | null;
|
|
24
27
|
retryOnAuthError?: boolean;
|
|
25
|
-
}
|
|
28
|
+
}
|
|
29
|
+
export declare function makeAuthenticatedRequest(url: string, options?: AuthenticatedRequestOptions): Promise<{
|
|
26
30
|
response: Response;
|
|
27
31
|
newTokens: CxfTokens;
|
|
28
32
|
}>;
|
|
@@ -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,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAiBD,wBAAgB,oBAAoB,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAS5E;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,SAAS,EACjB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,EACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"cxf-auth.d.ts","sourceRoot":"","sources":["../../src/lib/cxf-auth.ts"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Q,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,28 @@ 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, extraHeaders, 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);
|
|
66
|
+
if (extraHeaders) {
|
|
67
|
+
for (const [key, value] of Object.entries(extraHeaders)) {
|
|
68
|
+
if (value)
|
|
69
|
+
headers[key] = value;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
67
72
|
if (cookieStr) {
|
|
68
73
|
headers.Cookie = cookieStr;
|
|
69
74
|
}
|
|
70
75
|
const requestOptions = { method, headers };
|
|
71
|
-
if (
|
|
72
|
-
|
|
76
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
77
|
+
headers["Content-Type"] = contentType || "application/json";
|
|
78
|
+
if (rawBody) {
|
|
79
|
+
requestOptions.body = new Uint8Array(rawBody);
|
|
80
|
+
}
|
|
81
|
+
else if (body) {
|
|
82
|
+
requestOptions.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
return requestOptions;
|
|
75
86
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type MaybeString = string | null | undefined;
|
|
2
|
+
export type MaybeStringList = string[] | string | null | undefined;
|
|
3
|
+
type ParseJsonFn = (value: string) => unknown;
|
|
4
|
+
interface ParseOptions {
|
|
5
|
+
parseJson?: ParseJsonFn;
|
|
6
|
+
}
|
|
7
|
+
export declare function cleanString(value: unknown): string | undefined;
|
|
8
|
+
export declare function pickFirstString(...values: unknown[]): string | undefined;
|
|
9
|
+
export declare function parseObject<T extends object>(value: T | string | null | undefined, options?: ParseOptions): T | undefined;
|
|
10
|
+
export declare function parseObjectArray<T extends object>(value: T[] | string | null | undefined, options?: ParseOptions): T[];
|
|
11
|
+
export declare function parseStringList(value: unknown): string[];
|
|
12
|
+
export declare function toOriginUrl(url: MaybeString): string | undefined;
|
|
13
|
+
export declare function resolveUrlBase(...candidates: MaybeString[]): string | undefined;
|
|
14
|
+
export declare function getCurrentOrigin(): string | undefined;
|
|
15
|
+
export declare function buildOrganizationId(baseUrl: MaybeString): string | undefined;
|
|
16
|
+
export declare function toAbsoluteUrl(pathOrUrl: MaybeString, baseUrl: MaybeString): string | undefined;
|
|
17
|
+
export declare function safeJsonForInlineScript(value: unknown): string;
|
|
18
|
+
export declare function toDomId(value: string): string;
|
|
19
|
+
export declare function removeDuplicateJsonLdScripts(scriptId: string, scriptKey: string, json: string): void;
|
|
20
|
+
export declare function tryParseLooseJson(value: string): unknown;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=seo-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seo-utils.d.ts","sourceRoot":"","sources":["../../src/lib/seo-utils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AACpD,MAAM,MAAM,eAAe,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAEnE,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAE9C,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAI9D;AAED,wBAAgB,eAAe,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,GAAG,SAAS,CAMxE;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,CAAC,EAAE,YAAY,GACrB,CAAC,GAAG,SAAS,CAuBf;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAC/C,KAAK,EAAE,CAAC,EAAE,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,OAAO,CAAC,EAAE,YAAY,GACrB,CAAC,EAAE,CAkBL;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,CAyBxD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAUhE;AAED,wBAAgB,cAAc,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,GAAG,SAAS,CAM/E;AAED,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAGrD;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAI5E;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAiB9F;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE9D;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAoB7F;AA0DD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUxD"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cleanString = cleanString;
|
|
4
|
+
exports.pickFirstString = pickFirstString;
|
|
5
|
+
exports.parseObject = parseObject;
|
|
6
|
+
exports.parseObjectArray = parseObjectArray;
|
|
7
|
+
exports.parseStringList = parseStringList;
|
|
8
|
+
exports.toOriginUrl = toOriginUrl;
|
|
9
|
+
exports.resolveUrlBase = resolveUrlBase;
|
|
10
|
+
exports.getCurrentOrigin = getCurrentOrigin;
|
|
11
|
+
exports.buildOrganizationId = buildOrganizationId;
|
|
12
|
+
exports.toAbsoluteUrl = toAbsoluteUrl;
|
|
13
|
+
exports.safeJsonForInlineScript = safeJsonForInlineScript;
|
|
14
|
+
exports.toDomId = toDomId;
|
|
15
|
+
exports.removeDuplicateJsonLdScripts = removeDuplicateJsonLdScripts;
|
|
16
|
+
exports.tryParseLooseJson = tryParseLooseJson;
|
|
17
|
+
function cleanString(value) {
|
|
18
|
+
if (typeof value !== "string")
|
|
19
|
+
return undefined;
|
|
20
|
+
const trimmed = value.trim();
|
|
21
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
22
|
+
}
|
|
23
|
+
function pickFirstString(...values) {
|
|
24
|
+
for (const value of values) {
|
|
25
|
+
const cleaned = cleanString(value);
|
|
26
|
+
if (cleaned)
|
|
27
|
+
return cleaned;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function parseObject(value, options) {
|
|
32
|
+
if (value == null)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (typeof value !== "string")
|
|
38
|
+
return undefined;
|
|
39
|
+
const maybeJson = value.trim();
|
|
40
|
+
if (!maybeJson)
|
|
41
|
+
return undefined;
|
|
42
|
+
const parseJson = options?.parseJson ?? JSON.parse;
|
|
43
|
+
try {
|
|
44
|
+
const parsed = parseJson(maybeJson);
|
|
45
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
function parseObjectArray(value, options) {
|
|
55
|
+
if (Array.isArray(value))
|
|
56
|
+
return value;
|
|
57
|
+
if (typeof value !== "string")
|
|
58
|
+
return [];
|
|
59
|
+
const maybeJson = value.trim();
|
|
60
|
+
if (!maybeJson)
|
|
61
|
+
return [];
|
|
62
|
+
const parseJson = options?.parseJson ?? JSON.parse;
|
|
63
|
+
try {
|
|
64
|
+
const parsed = parseJson(maybeJson);
|
|
65
|
+
if (Array.isArray(parsed)) {
|
|
66
|
+
return parsed.filter((item) => item && typeof item === "object");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
function parseStringList(value) {
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
return value
|
|
77
|
+
.map((item) => cleanString(item))
|
|
78
|
+
.filter((item) => Boolean(item));
|
|
79
|
+
}
|
|
80
|
+
const raw = cleanString(value);
|
|
81
|
+
if (!raw)
|
|
82
|
+
return [];
|
|
83
|
+
try {
|
|
84
|
+
const parsed = JSON.parse(raw);
|
|
85
|
+
if (Array.isArray(parsed)) {
|
|
86
|
+
return parsed
|
|
87
|
+
.map((item) => cleanString(item))
|
|
88
|
+
.filter((item) => Boolean(item));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Fall back to comma-separated values.
|
|
93
|
+
}
|
|
94
|
+
return raw
|
|
95
|
+
.split(",")
|
|
96
|
+
.map((item) => item.trim())
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
}
|
|
99
|
+
function toOriginUrl(url) {
|
|
100
|
+
const cleaned = cleanString(url);
|
|
101
|
+
if (!cleaned)
|
|
102
|
+
return undefined;
|
|
103
|
+
const withProtocol = cleaned.startsWith("//") ? `https:${cleaned}` : cleaned;
|
|
104
|
+
try {
|
|
105
|
+
return new URL(withProtocol).origin;
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function resolveUrlBase(...candidates) {
|
|
112
|
+
for (const candidate of candidates) {
|
|
113
|
+
const origin = toOriginUrl(candidate);
|
|
114
|
+
if (origin)
|
|
115
|
+
return origin;
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
function getCurrentOrigin() {
|
|
120
|
+
if (typeof window === "undefined")
|
|
121
|
+
return undefined;
|
|
122
|
+
return toOriginUrl(window.location.origin);
|
|
123
|
+
}
|
|
124
|
+
function buildOrganizationId(baseUrl) {
|
|
125
|
+
const origin = toOriginUrl(baseUrl);
|
|
126
|
+
if (!origin)
|
|
127
|
+
return undefined;
|
|
128
|
+
return `${origin}/#organization`;
|
|
129
|
+
}
|
|
130
|
+
function toAbsoluteUrl(pathOrUrl, baseUrl) {
|
|
131
|
+
const value = cleanString(pathOrUrl);
|
|
132
|
+
if (!value)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (/^https?:\/\//i.test(value))
|
|
135
|
+
return value;
|
|
136
|
+
if (value.startsWith("//"))
|
|
137
|
+
return `https:${value}`;
|
|
138
|
+
const normalizedBase = resolveUrlBase(baseUrl);
|
|
139
|
+
const relativePath = value.startsWith("/") ? value : `/${value}`;
|
|
140
|
+
if (!normalizedBase)
|
|
141
|
+
return relativePath;
|
|
142
|
+
try {
|
|
143
|
+
return new URL(relativePath, `${normalizedBase}/`).href;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return relativePath;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function safeJsonForInlineScript(value) {
|
|
150
|
+
return JSON.stringify(value).replace(/</g, "\\u003c");
|
|
151
|
+
}
|
|
152
|
+
function toDomId(value) {
|
|
153
|
+
return value.replace(/[^a-zA-Z0-9\-_:.]/g, "-");
|
|
154
|
+
}
|
|
155
|
+
function removeDuplicateJsonLdScripts(scriptId, scriptKey, json) {
|
|
156
|
+
if (typeof document === "undefined")
|
|
157
|
+
return;
|
|
158
|
+
const canonical = document.getElementById(scriptId);
|
|
159
|
+
const allJsonLdScripts = Array.from(document.querySelectorAll("script[type='application/ld+json']"));
|
|
160
|
+
allJsonLdScripts.forEach((script) => {
|
|
161
|
+
if (script === canonical)
|
|
162
|
+
return;
|
|
163
|
+
const sameId = script.id === scriptId;
|
|
164
|
+
const sameKey = script.getAttribute("data-jsonld-key") === scriptKey;
|
|
165
|
+
const samePayloadOutsideHead = script.parentElement !== document.head && (script.textContent ?? "") === json;
|
|
166
|
+
if (sameId || sameKey || samePayloadOutsideHead) {
|
|
167
|
+
script.remove();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function isEscaped(input, index) {
|
|
172
|
+
let slashCount = 0;
|
|
173
|
+
for (let i = index - 1; i >= 0 && input[i] === "\\"; i -= 1) {
|
|
174
|
+
slashCount += 1;
|
|
175
|
+
}
|
|
176
|
+
return slashCount % 2 === 1;
|
|
177
|
+
}
|
|
178
|
+
function repairJsonInnerQuotes(input) {
|
|
179
|
+
let repaired = "";
|
|
180
|
+
let inString = false;
|
|
181
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
182
|
+
const ch = input[i];
|
|
183
|
+
if (ch !== "\"") {
|
|
184
|
+
repaired += ch;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (isEscaped(input, i)) {
|
|
188
|
+
repaired += ch;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!inString) {
|
|
192
|
+
inString = true;
|
|
193
|
+
repaired += ch;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
let nextNonSpace = i + 1;
|
|
197
|
+
while (nextNonSpace < input.length && /\s/.test(input[nextNonSpace])) {
|
|
198
|
+
nextNonSpace += 1;
|
|
199
|
+
}
|
|
200
|
+
const next = input[nextNonSpace];
|
|
201
|
+
const closesString = nextNonSpace >= input.length ||
|
|
202
|
+
next === "," ||
|
|
203
|
+
next === "}" ||
|
|
204
|
+
next === "]" ||
|
|
205
|
+
next === ":";
|
|
206
|
+
if (closesString) {
|
|
207
|
+
inString = false;
|
|
208
|
+
repaired += ch;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Heuristic: treat inner raw quotes (commonly from HTML attributes) as escaped.
|
|
212
|
+
repaired += "\\\"";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return repaired;
|
|
216
|
+
}
|
|
217
|
+
function tryParseLooseJson(value) {
|
|
218
|
+
try {
|
|
219
|
+
return JSON.parse(value);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
const repaired = repairJsonInnerQuotes(value);
|
|
223
|
+
if (repaired !== value) {
|
|
224
|
+
return JSON.parse(repaired);
|
|
225
|
+
}
|
|
226
|
+
throw new Error("Invalid JSON");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -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,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAKpD,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,OA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AAG,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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../../src/pages/api/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../../src/pages/api/assets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAoB5D,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,eAAe,iBAwC/E;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/pages/api/assets.js
CHANGED
|
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.assetsApiHandler = assetsApiHandler;
|
|
4
4
|
const cxf_auth_1 = require("../../lib/cxf-auth");
|
|
5
5
|
const api_route_helpers_1 = require("../../lib/api-route-helpers");
|
|
6
|
+
const assets_query_params_1 = require("../../lib/assets-query-params");
|
|
7
|
+
const CONDITIONAL_REQUEST_HEADERS = ["if-none-match", "if-modified-since"];
|
|
8
|
+
const CACHE_RESPONSE_HEADERS = ["cache-control", "etag", "last-modified", "expires", "vary"];
|
|
9
|
+
function getHeaderValue(header) {
|
|
10
|
+
if (Array.isArray(header))
|
|
11
|
+
return header.join(", ");
|
|
12
|
+
return header;
|
|
13
|
+
}
|
|
14
|
+
function forwardResponseHeaders(res, response) {
|
|
15
|
+
for (const headerName of CACHE_RESPONSE_HEADERS) {
|
|
16
|
+
const value = response.headers.get(headerName);
|
|
17
|
+
if (value)
|
|
18
|
+
res.setHeader(headerName, value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
async function assetsApiHandler(req, res) {
|
|
7
22
|
if (req.method !== "GET") {
|
|
8
23
|
res.setHeader("Allow", "GET");
|
|
@@ -11,15 +26,26 @@ async function assetsApiHandler(req, res) {
|
|
|
11
26
|
try {
|
|
12
27
|
const baseUrl = (0, cxf_auth_1.getCxfBaseUrl)();
|
|
13
28
|
const normalizedPath = (0, api_route_helpers_1.normalizePath)(req.query.path);
|
|
14
|
-
const
|
|
29
|
+
const paramsFromCookie = (0, assets_query_params_1.extractAssetQueryParamsFromCookie)(req.headers.cookie || null);
|
|
30
|
+
const mergedQuery = {
|
|
31
|
+
...paramsFromCookie,
|
|
32
|
+
...req.query,
|
|
33
|
+
};
|
|
34
|
+
const targetUrl = `${baseUrl}/assets/${normalizedPath}${(0, api_route_helpers_1.buildQueryString)(mergedQuery)}`;
|
|
35
|
+
const extraHeaders = CONDITIONAL_REQUEST_HEADERS.reduce((acc, headerName) => {
|
|
36
|
+
acc[headerName] = getHeaderValue(req.headers[headerName]);
|
|
37
|
+
return acc;
|
|
38
|
+
}, {});
|
|
15
39
|
const { response, newTokens } = await (0, cxf_auth_1.makeAuthenticatedRequest)(targetUrl, {
|
|
16
40
|
method: "GET",
|
|
17
41
|
cookieHeader: req.headers.cookie || null,
|
|
18
42
|
retryOnAuthError: false,
|
|
43
|
+
extraHeaders,
|
|
19
44
|
});
|
|
20
45
|
const setCookieHeaders = (0, cxf_auth_1.extractSetCookieHeaders)(response);
|
|
21
46
|
const tokens = (0, cxf_auth_1.extractTokensFromSetCookie)(setCookieHeaders);
|
|
22
47
|
const finalTokens = tokens.accessToken || tokens.refreshToken ? tokens : newTokens;
|
|
48
|
+
forwardResponseHeaders(res, response);
|
|
23
49
|
(0, api_route_helpers_1.setAuthCookies)(res, finalTokens);
|
|
24
50
|
return (0, api_route_helpers_1.sendResponse)(res, response);
|
|
25
51
|
}
|
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"}
|