@sitecore-content-sdk/nextjs 2.0.0-canary.3 → 2.0.0-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/editing/editing-render-middleware.js +14 -7
- package/dist/cjs/editing/types.js +2 -0
- package/dist/cjs/editing/utils.js +30 -1
- package/dist/cjs/route-handler/editing-render-route-handler.js +12 -5
- package/dist/esm/editing/editing-render-middleware.js +15 -8
- package/dist/esm/editing/types.js +1 -0
- package/dist/esm/editing/utils.js +28 -0
- package/dist/esm/route-handler/editing-render-route-handler.js +13 -6
- package/package.json +5 -5
- package/types/editing/editing-render-middleware.d.ts +7 -0
- package/types/editing/editing-render-middleware.d.ts.map +1 -1
- package/types/editing/index.d.ts +1 -0
- package/types/editing/index.d.ts.map +1 -1
- package/types/editing/types.d.ts +37 -0
- package/types/editing/types.d.ts.map +1 -0
- package/types/editing/utils.d.ts +11 -0
- package/types/editing/utils.d.ts.map +1 -1
- package/types/route-handler/editing-render-route-handler.d.ts +7 -0
- package/types/route-handler/editing-render-route-handler.d.ts.map +1 -1
|
@@ -34,7 +34,7 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
34
34
|
super();
|
|
35
35
|
this.config = config;
|
|
36
36
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
var _a, _b, _c, _d, _e;
|
|
37
|
+
var _a, _b, _c, _d, _e, _f;
|
|
38
38
|
const { body, method, headers, query } = req;
|
|
39
39
|
debug_1.default.editing('editing render middleware start: %o', {
|
|
40
40
|
method,
|
|
@@ -81,15 +81,22 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
81
81
|
const mode = query.mode;
|
|
82
82
|
const requiredQueryParams = (0, utils_2.getRequiredEditingParamsList)(mode);
|
|
83
83
|
const missingQueryParams = requiredQueryParams.filter((param) => !query[param]);
|
|
84
|
+
const { allowedQueryParams, missingAllowedParams } = (0, utils_2.getAllowedQueryParams)(query, (_b = this.config) === null || _b === void 0 ? void 0 : _b.allowedQueryParams);
|
|
84
85
|
// Validate query parameters
|
|
85
|
-
if (missingQueryParams.length) {
|
|
86
|
-
debug_1.default.editing('missing required query parameters: %o',
|
|
86
|
+
if (missingQueryParams.length || missingAllowedParams.length) {
|
|
87
|
+
debug_1.default.editing('missing required query parameters: %o', [
|
|
88
|
+
...missingQueryParams,
|
|
89
|
+
...missingAllowedParams,
|
|
90
|
+
]);
|
|
87
91
|
return res.status(400).json({
|
|
88
|
-
html: `<html><body>Missing required query parameters: ${
|
|
92
|
+
html: `<html><body>Missing required query parameters: ${[
|
|
93
|
+
...missingQueryParams,
|
|
94
|
+
...missingAllowedParams,
|
|
95
|
+
].join(', ')}</body></html>`,
|
|
89
96
|
});
|
|
90
97
|
}
|
|
91
98
|
const previewDataParams = (0, utils_2.mapEditingParams)(query);
|
|
92
|
-
res.setPreviewData(Object.assign(Object.assign({}, previewDataParams), { variantIds: (
|
|
99
|
+
res.setPreviewData(Object.assign(Object.assign(Object.assign({}, previewDataParams), allowedQueryParams), { variantIds: (_c = previewDataParams.variantIds) === null || _c === void 0 ? void 0 : _c.split(',') }), {
|
|
93
100
|
maxAge: 3,
|
|
94
101
|
});
|
|
95
102
|
// Set Preview mode identifier cookie, if the page is rendered in Sitecore Preview mode
|
|
@@ -101,8 +108,8 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
101
108
|
// Restrict the page to be rendered only within the allowed origins
|
|
102
109
|
res.setHeader('Content-Security-Policy', (0, utils_2.getCSPHeader)());
|
|
103
110
|
const encodedRoute = encodeURI(query.route);
|
|
104
|
-
const route = ((
|
|
105
|
-
const base = ((
|
|
111
|
+
const route = ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.resolvePageUrl) === null || _e === void 0 ? void 0 : _e.call(_d, encodedRoute)) || encodedRoute;
|
|
112
|
+
const base = ((_f = this.config) === null || _f === void 0 ? void 0 : _f.sitecoreInternalEditingHostUrl) || (0, utils_2.resolveServerUrl)(req);
|
|
106
113
|
const requestUrl = new URL(route, base);
|
|
107
114
|
const cookies = res.getHeader('Set-Cookie');
|
|
108
115
|
// Make actual render request for page route, passing on preview cookies as well as any approved query string parameters.
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getCSPHeader = exports.resolveServerUrl = exports.isDesignLibraryPreviewData = exports.getEditingRequestHtml = exports.getHeadersForPropagation = exports.getQueryParamsForPropagation = exports.getRequiredEditingParamsList = exports.getPreviewCookies = exports.cleanupNextPreviewCookies = exports.mapEditingParams = exports.getEditingSecretFromRequest = void 0;
|
|
12
|
+
exports.getCSPHeader = exports.resolveServerUrl = exports.isDesignLibraryPreviewData = exports.getEditingRequestHtml = exports.getHeadersForPropagation = exports.getQueryParamsForPropagation = exports.getRequiredEditingParamsList = exports.getPreviewCookies = exports.cleanupNextPreviewCookies = exports.getAllowedQueryParams = exports.mapEditingParams = exports.getEditingSecretFromRequest = void 0;
|
|
13
13
|
const editing_1 = require("@sitecore-content-sdk/content/editing");
|
|
14
14
|
const personalize_1 = require("@sitecore-content-sdk/content/personalize");
|
|
15
15
|
const site_1 = require("@sitecore-content-sdk/content/site");
|
|
@@ -69,6 +69,35 @@ const mapEditingParams = (query) => {
|
|
|
69
69
|
return params;
|
|
70
70
|
};
|
|
71
71
|
exports.mapEditingParams = mapEditingParams;
|
|
72
|
+
/**
|
|
73
|
+
* Parses the query parameters based on the provided allowed parameters or a resolver function, to extract additional parameters that should be allowed.
|
|
74
|
+
* @param {{ [key: string]: string | undefined }} queryParams Object of query parameters from incoming URL.
|
|
75
|
+
* @param {AllowedQueryParams} allowedParams Allowed parameters to map.
|
|
76
|
+
* @returns Object containing the list of missing required parameters and the allowed query parameters that were extracted.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
const getAllowedQueryParams = (queryParams, allowedParams) => {
|
|
80
|
+
const allowedQueryParamsList = typeof allowedParams === 'function'
|
|
81
|
+
? allowedParams(Object.keys(queryParams))
|
|
82
|
+
: Array.isArray(allowedParams)
|
|
83
|
+
? allowedParams
|
|
84
|
+
: [];
|
|
85
|
+
if (!allowedQueryParamsList.length)
|
|
86
|
+
return { missingAllowedParams: [], allowedQueryParams: {} };
|
|
87
|
+
return allowedQueryParamsList.reduce((acc, param) => {
|
|
88
|
+
const name = typeof param === 'string' ? param : param.name;
|
|
89
|
+
const required = typeof param === 'string' ? false : param.required;
|
|
90
|
+
const value = queryParams[name];
|
|
91
|
+
if (value !== undefined) {
|
|
92
|
+
acc.allowedQueryParams[name] = value;
|
|
93
|
+
return acc;
|
|
94
|
+
}
|
|
95
|
+
if (required)
|
|
96
|
+
acc.missingAllowedParams.push(name);
|
|
97
|
+
return acc;
|
|
98
|
+
}, { missingAllowedParams: [], allowedQueryParams: {} });
|
|
99
|
+
};
|
|
100
|
+
exports.getAllowedQueryParams = getAllowedQueryParams;
|
|
72
101
|
/**
|
|
73
102
|
* Filters out Next.js preview cookies from a cookie string or array
|
|
74
103
|
* @param {string | string[] | null} cookies cookie header value
|
|
@@ -116,11 +116,18 @@ const createEditingRenderRouteHandlers = (options) => {
|
|
|
116
116
|
const mode = query.mode;
|
|
117
117
|
const requiredQueryParams = (0, utils_2.getRequiredEditingParamsList)(mode);
|
|
118
118
|
const missingQueryParams = requiredQueryParams.filter((param) => !query[param]);
|
|
119
|
+
const { allowedQueryParams, missingAllowedParams } = (0, utils_2.getAllowedQueryParams)(query, options.allowedQueryParams);
|
|
119
120
|
// Validate query parameters
|
|
120
|
-
if (missingQueryParams.length) {
|
|
121
|
-
debug_1.default.editing('missing required query parameters: %o',
|
|
121
|
+
if (missingQueryParams.length || missingAllowedParams.length) {
|
|
122
|
+
debug_1.default.editing('missing required query parameters: %o', [
|
|
123
|
+
...missingQueryParams,
|
|
124
|
+
...missingAllowedParams,
|
|
125
|
+
]);
|
|
122
126
|
return Response.json({
|
|
123
|
-
html: `<html><body>Missing required query parameters: ${
|
|
127
|
+
html: `<html><body>Missing required query parameters: ${[
|
|
128
|
+
...missingQueryParams,
|
|
129
|
+
...missingAllowedParams,
|
|
130
|
+
].join(', ')}</body></html>`,
|
|
124
131
|
}, { status: 400, headers: responseHeaders });
|
|
125
132
|
}
|
|
126
133
|
const encodedRoute = encodeURI(query.route);
|
|
@@ -156,7 +163,7 @@ const createEditingRenderRouteHandlers = (options) => {
|
|
|
156
163
|
debug_1.default.editing('fetching page route for %s', query.route);
|
|
157
164
|
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
158
165
|
// Additionally ,in app router preview data is passed through query string instead of preview data cookie
|
|
159
|
-
const propagatedQsParams = Object.assign(Object.assign({}, (0, utils_2.getQueryParamsForPropagation)(query)), (0, utils_2.mapEditingParams)(query));
|
|
166
|
+
const propagatedQsParams = Object.assign(Object.assign(Object.assign({}, (0, utils_2.getQueryParamsForPropagation)(query)), (0, utils_2.mapEditingParams)(query)), allowedQueryParams);
|
|
160
167
|
// Get headers to propagate on subsequent requests
|
|
161
168
|
const propagatedHeaders = (0, utils_2.getHeadersForPropagation)(headers);
|
|
162
169
|
const html = yield (0, utils_2.getEditingRequestHtml)(requestUrl, propagatedQsParams, propagatedHeaders, convertedCookies, dataFetcher);
|
|
@@ -215,7 +222,7 @@ const createEditingRenderRouteHandlers = (options) => {
|
|
|
215
222
|
req.nextUrl.searchParams.forEach((value, key) => {
|
|
216
223
|
query[key] = value;
|
|
217
224
|
});
|
|
218
|
-
const propagatedQsParams = Object.assign(Object.assign({}, (0, utils_2.getQueryParamsForPropagation)(query)), (0, utils_2.mapEditingParams)(query));
|
|
225
|
+
const propagatedQsParams = Object.assign(Object.assign(Object.assign({}, (0, utils_2.getQueryParamsForPropagation)(query)), (0, utils_2.mapEditingParams)(query)), (0, utils_2.getAllowedQueryParams)(query, options.allowedQueryParams).allowedQueryParams);
|
|
219
226
|
const base = (0, utils_2.resolveServerUrl)(req);
|
|
220
227
|
const targetUrl = new URL('/', base);
|
|
221
228
|
for (const key in propagatedQsParams) {
|
|
@@ -14,7 +14,7 @@ import { getEditingSecret } from '../utils/utils';
|
|
|
14
14
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
15
15
|
import { getEnforcedCorsHeaders } from '@sitecore-content-sdk/core/tools';
|
|
16
16
|
import debug from '../debug';
|
|
17
|
-
import { getPreviewCookies, getRequiredEditingParamsList, mapEditingParams, cleanupNextPreviewCookies, getQueryParamsForPropagation, getHeadersForPropagation, getEditingRequestHtml, getCSPHeader, resolveServerUrl, } from './utils';
|
|
17
|
+
import { getPreviewCookies, getRequiredEditingParamsList, mapEditingParams, cleanupNextPreviewCookies, getQueryParamsForPropagation, getHeadersForPropagation, getEditingRequestHtml, getCSPHeader, resolveServerUrl, getAllowedQueryParams, } from './utils';
|
|
18
18
|
/**
|
|
19
19
|
* Middleware / handler for use in the editing render Next.js API route (e.g. '/api/editing/render')
|
|
20
20
|
* which is required for Sitecore editing support.
|
|
@@ -28,7 +28,7 @@ export class EditingRenderMiddleware extends RenderMiddlewareBase {
|
|
|
28
28
|
super();
|
|
29
29
|
this.config = config;
|
|
30
30
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
var _a, _b, _c, _d, _e;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f;
|
|
32
32
|
const { body, method, headers, query } = req;
|
|
33
33
|
debug.editing('editing render middleware start: %o', {
|
|
34
34
|
method,
|
|
@@ -75,15 +75,22 @@ export class EditingRenderMiddleware extends RenderMiddlewareBase {
|
|
|
75
75
|
const mode = query.mode;
|
|
76
76
|
const requiredQueryParams = getRequiredEditingParamsList(mode);
|
|
77
77
|
const missingQueryParams = requiredQueryParams.filter((param) => !query[param]);
|
|
78
|
+
const { allowedQueryParams, missingAllowedParams } = getAllowedQueryParams(query, (_b = this.config) === null || _b === void 0 ? void 0 : _b.allowedQueryParams);
|
|
78
79
|
// Validate query parameters
|
|
79
|
-
if (missingQueryParams.length) {
|
|
80
|
-
debug.editing('missing required query parameters: %o',
|
|
80
|
+
if (missingQueryParams.length || missingAllowedParams.length) {
|
|
81
|
+
debug.editing('missing required query parameters: %o', [
|
|
82
|
+
...missingQueryParams,
|
|
83
|
+
...missingAllowedParams,
|
|
84
|
+
]);
|
|
81
85
|
return res.status(400).json({
|
|
82
|
-
html: `<html><body>Missing required query parameters: ${
|
|
86
|
+
html: `<html><body>Missing required query parameters: ${[
|
|
87
|
+
...missingQueryParams,
|
|
88
|
+
...missingAllowedParams,
|
|
89
|
+
].join(', ')}</body></html>`,
|
|
83
90
|
});
|
|
84
91
|
}
|
|
85
92
|
const previewDataParams = mapEditingParams(query);
|
|
86
|
-
res.setPreviewData(Object.assign(Object.assign({}, previewDataParams), { variantIds: (
|
|
93
|
+
res.setPreviewData(Object.assign(Object.assign(Object.assign({}, previewDataParams), allowedQueryParams), { variantIds: (_c = previewDataParams.variantIds) === null || _c === void 0 ? void 0 : _c.split(',') }), {
|
|
87
94
|
maxAge: 3,
|
|
88
95
|
});
|
|
89
96
|
// Set Preview mode identifier cookie, if the page is rendered in Sitecore Preview mode
|
|
@@ -95,8 +102,8 @@ export class EditingRenderMiddleware extends RenderMiddlewareBase {
|
|
|
95
102
|
// Restrict the page to be rendered only within the allowed origins
|
|
96
103
|
res.setHeader('Content-Security-Policy', getCSPHeader());
|
|
97
104
|
const encodedRoute = encodeURI(query.route);
|
|
98
|
-
const route = ((
|
|
99
|
-
const base = ((
|
|
105
|
+
const route = ((_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.resolvePageUrl) === null || _e === void 0 ? void 0 : _e.call(_d, encodedRoute)) || encodedRoute;
|
|
106
|
+
const base = ((_f = this.config) === null || _f === void 0 ? void 0 : _f.sitecoreInternalEditingHostUrl) || resolveServerUrl(req);
|
|
100
107
|
const requestUrl = new URL(route, base);
|
|
101
108
|
const cookies = res.getHeader('Set-Cookie');
|
|
102
109
|
// Make actual render request for page route, passing on preview cookies as well as any approved query string parameters.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -64,6 +64,34 @@ export const mapEditingParams = (query) => {
|
|
|
64
64
|
};
|
|
65
65
|
return params;
|
|
66
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Parses the query parameters based on the provided allowed parameters or a resolver function, to extract additional parameters that should be allowed.
|
|
69
|
+
* @param {{ [key: string]: string | undefined }} queryParams Object of query parameters from incoming URL.
|
|
70
|
+
* @param {AllowedQueryParams} allowedParams Allowed parameters to map.
|
|
71
|
+
* @returns Object containing the list of missing required parameters and the allowed query parameters that were extracted.
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export const getAllowedQueryParams = (queryParams, allowedParams) => {
|
|
75
|
+
const allowedQueryParamsList = typeof allowedParams === 'function'
|
|
76
|
+
? allowedParams(Object.keys(queryParams))
|
|
77
|
+
: Array.isArray(allowedParams)
|
|
78
|
+
? allowedParams
|
|
79
|
+
: [];
|
|
80
|
+
if (!allowedQueryParamsList.length)
|
|
81
|
+
return { missingAllowedParams: [], allowedQueryParams: {} };
|
|
82
|
+
return allowedQueryParamsList.reduce((acc, param) => {
|
|
83
|
+
const name = typeof param === 'string' ? param : param.name;
|
|
84
|
+
const required = typeof param === 'string' ? false : param.required;
|
|
85
|
+
const value = queryParams[name];
|
|
86
|
+
if (value !== undefined) {
|
|
87
|
+
acc.allowedQueryParams[name] = value;
|
|
88
|
+
return acc;
|
|
89
|
+
}
|
|
90
|
+
if (required)
|
|
91
|
+
acc.missingAllowedParams.push(name);
|
|
92
|
+
return acc;
|
|
93
|
+
}, { missingAllowedParams: [], allowedQueryParams: {} });
|
|
94
|
+
};
|
|
67
95
|
/**
|
|
68
96
|
* Filters out Next.js preview cookies from a cookie string or array
|
|
69
97
|
* @param {string | string[] | null} cookies cookie header value
|
|
@@ -13,7 +13,7 @@ import { getEnforcedCorsHeaders } from '@sitecore-content-sdk/core/tools';
|
|
|
13
13
|
import { LayoutServicePageState } from '@sitecore-content-sdk/content/layout';
|
|
14
14
|
import { getEditingSecret } from '../utils/utils';
|
|
15
15
|
import { draftMode, cookies as nextCokies } from 'next/headers';
|
|
16
|
-
import { mapEditingParams, getEditingRequestHtml, cleanupNextPreviewCookies, getHeadersForPropagation, getQueryParamsForPropagation, getRequiredEditingParamsList, getCSPHeader, resolveServerUrl, } from '../editing/utils';
|
|
16
|
+
import { mapEditingParams, getEditingRequestHtml, cleanupNextPreviewCookies, getHeadersForPropagation, getQueryParamsForPropagation, getRequiredEditingParamsList, getCSPHeader, resolveServerUrl, getAllowedQueryParams, } from '../editing/utils';
|
|
17
17
|
import { SITE_KEY } from '@sitecore-content-sdk/content/site';
|
|
18
18
|
import debug from '../debug';
|
|
19
19
|
/**
|
|
@@ -109,11 +109,18 @@ export const createEditingRenderRouteHandlers = (options) => {
|
|
|
109
109
|
const mode = query.mode;
|
|
110
110
|
const requiredQueryParams = getRequiredEditingParamsList(mode);
|
|
111
111
|
const missingQueryParams = requiredQueryParams.filter((param) => !query[param]);
|
|
112
|
+
const { allowedQueryParams, missingAllowedParams } = getAllowedQueryParams(query, options.allowedQueryParams);
|
|
112
113
|
// Validate query parameters
|
|
113
|
-
if (missingQueryParams.length) {
|
|
114
|
-
debug.editing('missing required query parameters: %o',
|
|
114
|
+
if (missingQueryParams.length || missingAllowedParams.length) {
|
|
115
|
+
debug.editing('missing required query parameters: %o', [
|
|
116
|
+
...missingQueryParams,
|
|
117
|
+
...missingAllowedParams,
|
|
118
|
+
]);
|
|
115
119
|
return Response.json({
|
|
116
|
-
html: `<html><body>Missing required query parameters: ${
|
|
120
|
+
html: `<html><body>Missing required query parameters: ${[
|
|
121
|
+
...missingQueryParams,
|
|
122
|
+
...missingAllowedParams,
|
|
123
|
+
].join(', ')}</body></html>`,
|
|
117
124
|
}, { status: 400, headers: responseHeaders });
|
|
118
125
|
}
|
|
119
126
|
const encodedRoute = encodeURI(query.route);
|
|
@@ -149,7 +156,7 @@ export const createEditingRenderRouteHandlers = (options) => {
|
|
|
149
156
|
debug.editing('fetching page route for %s', query.route);
|
|
150
157
|
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
151
158
|
// Additionally ,in app router preview data is passed through query string instead of preview data cookie
|
|
152
|
-
const propagatedQsParams = Object.assign(Object.assign({}, getQueryParamsForPropagation(query)), mapEditingParams(query));
|
|
159
|
+
const propagatedQsParams = Object.assign(Object.assign(Object.assign({}, getQueryParamsForPropagation(query)), mapEditingParams(query)), allowedQueryParams);
|
|
153
160
|
// Get headers to propagate on subsequent requests
|
|
154
161
|
const propagatedHeaders = getHeadersForPropagation(headers);
|
|
155
162
|
const html = yield getEditingRequestHtml(requestUrl, propagatedQsParams, propagatedHeaders, convertedCookies, dataFetcher);
|
|
@@ -208,7 +215,7 @@ export const createEditingRenderRouteHandlers = (options) => {
|
|
|
208
215
|
req.nextUrl.searchParams.forEach((value, key) => {
|
|
209
216
|
query[key] = value;
|
|
210
217
|
});
|
|
211
|
-
const propagatedQsParams = Object.assign(Object.assign({}, getQueryParamsForPropagation(query)), mapEditingParams(query));
|
|
218
|
+
const propagatedQsParams = Object.assign(Object.assign(Object.assign({}, getQueryParamsForPropagation(query)), mapEditingParams(query)), getAllowedQueryParams(query, options.allowedQueryParams).allowedQueryParams);
|
|
212
219
|
const base = resolveServerUrl(req);
|
|
213
220
|
const targetUrl = new URL('/', base);
|
|
214
221
|
for (const key in propagatedQsParams) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "2.0.0-canary.
|
|
3
|
+
"version": "2.0.0-canary.4",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -91,9 +91,9 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@babel/parser": "^7.27.2",
|
|
94
|
-
"@sitecore-content-sdk/content": "2.0.0-canary.
|
|
95
|
-
"@sitecore-content-sdk/core": "2.0.0-canary.
|
|
96
|
-
"@sitecore-content-sdk/react": "2.0.0-canary.
|
|
94
|
+
"@sitecore-content-sdk/content": "2.0.0-canary.4",
|
|
95
|
+
"@sitecore-content-sdk/core": "2.0.0-canary.4",
|
|
96
|
+
"@sitecore-content-sdk/react": "2.0.0-canary.4",
|
|
97
97
|
"recast": "^0.23.11",
|
|
98
98
|
"regex-parser": "^2.3.1",
|
|
99
99
|
"sync-disk-cache": "^2.1.0"
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
},
|
|
178
178
|
"description": "",
|
|
179
179
|
"types": "types/index.d.ts",
|
|
180
|
-
"gitHead": "
|
|
180
|
+
"gitHead": "5c49b45ca02bc2f418f6018a2221ca69199e21be",
|
|
181
181
|
"files": [
|
|
182
182
|
"dist",
|
|
183
183
|
"types",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
2
|
import { EditingRenderQueryParams } from '@sitecore-content-sdk/content/editing';
|
|
3
3
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
4
|
+
import type { AllowedQueryParams } from './types';
|
|
4
5
|
/**
|
|
5
6
|
* Configuration for the Editing Render Middleware.
|
|
6
7
|
* @public
|
|
@@ -18,6 +19,12 @@ export type EditingRenderMiddlewareConfig = {
|
|
|
18
19
|
* The internal host URL for the Next.js application, used for server-side requests for page rendering during editing.
|
|
19
20
|
*/
|
|
20
21
|
sitecoreInternalEditingHostUrl?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Query string parameters to allow and include in the preview data.
|
|
24
|
+
* - Array: each item is a parameter name (string) or an object `{ name, required? }`.
|
|
25
|
+
* - Function: receives the request's query parameter names and returns the list of allowed parameters.
|
|
26
|
+
*/
|
|
27
|
+
allowedQueryParams?: AllowedQueryParams;
|
|
21
28
|
};
|
|
22
29
|
/**
|
|
23
30
|
* Next.js API request with editing request query parameters.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editing-render-middleware.d.ts","sourceRoot":"","sources":["../../src/editing/editing-render-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,EAIL,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAe3D;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,KAAK,EAAE,wBAAwB,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,oBAAoB;IAK5C,MAAM,CAAC,EAAE,6BAA6B;IAJzD,OAAO,CAAC,WAAW,CAAoB;IACvC;;OAEG;gBACgB,MAAM,CAAC,EAAE,6BAA6B,YAAA;IAKzD;;;OAGG;IACI,UAAU,IAAI,CAAC,GAAG,EAAE,qBAAqB,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC;IAIxF,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"editing-render-middleware.d.ts","sourceRoot":"","sources":["../../src/editing/editing-render-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,EAIL,wBAAwB,EACzB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAe3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,cAAc,GAAG;IACnD,KAAK,EAAE,wBAAwB,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,oBAAoB;IAK5C,MAAM,CAAC,EAAE,6BAA6B;IAJzD,OAAO,CAAC,WAAW,CAAoB;IACvC;;OAEG;gBACgB,MAAM,CAAC,EAAE,6BAA6B,YAAA;IAKzD;;;OAGG;IACI,UAAU,IAAI,CAAC,GAAG,EAAE,qBAAqB,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC;IAIxF,OAAO,CAAC,OAAO,CA6Jb;CACH"}
|
package/types/editing/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export { isDesignLibraryPreviewData, getQueryParamsForPropagation, getHeadersFor
|
|
|
4
4
|
export { FEAASRenderMiddleware, FEAASRenderMiddlewareConfig } from './feaas-render-middleware';
|
|
5
5
|
export { EditingConfigMiddleware, EditingConfigMiddlewareConfig, } from './editing-config-middleware';
|
|
6
6
|
export { RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-content-sdk/content/layout';
|
|
7
|
+
export type { AllowedQueryParam, AllowedQueryParamsResolver, AllowedQueryParams } from './types';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,aAAa,EACb,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,sCAAsC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,0BAA0B,EAC1B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,aAAa,EACb,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,sCAAsC,CAAC;AAC9C,YAAY,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an allowed query parameter.
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export interface AllowedQueryParam {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the query parameter to allow.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the query parameter is required.
|
|
12
|
+
*/
|
|
13
|
+
required?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resolver function for allowed query parameters, which can be used to extract additional parameters from the query string beyond the required editing parameters.
|
|
17
|
+
* @param {string[]} queryParams Array of query parameters from incoming URL.
|
|
18
|
+
* @returns {Array<AllowedQueryParam | string>} Allowed query editing parameters.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type AllowedQueryParamsResolver = (queryParams: string[]) => Array<AllowedQueryParam | string>;
|
|
22
|
+
/**
|
|
23
|
+
* Allowed query parameters which can be defined as an array of parameter names or objects, or a resolver function which can be used to extract additional parameters from the query string beyond the required editing parameters.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export type AllowedQueryParams = Array<AllowedQueryParam | string> | AllowedQueryParamsResolver;
|
|
27
|
+
/**
|
|
28
|
+
* Result of processing allowed query parameters, including any missing required parameters and the set of allowed parameters that were extracted from the query string.
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export interface GetAllowedQueryParamsResult {
|
|
32
|
+
missingAllowedParams: string[];
|
|
33
|
+
allowedQueryParams: {
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/editing/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,MAAM,MAAM,0BAA0B,GAAG,CACvC,WAAW,EAAE,MAAM,EAAE,KAClB,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,CAAC;AAEvC;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,GAAG,0BAA0B,CAAC;AAEhG;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CAChD"}
|
package/types/editing/utils.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { NextApiRequest } from 'next';
|
|
|
3
3
|
import { NextRequest } from 'next/server';
|
|
4
4
|
import { IncomingHttpHeaders } from 'http';
|
|
5
5
|
import { NativeDataFetcher } from '@sitecore-content-sdk/core';
|
|
6
|
+
import { AllowedQueryParams, GetAllowedQueryParamsResult } from './types';
|
|
6
7
|
/**
|
|
7
8
|
* Gets editing secret value from request
|
|
8
9
|
* @param {NextApiRequest | NextRequest} req incoming request
|
|
@@ -19,6 +20,16 @@ export declare const mapEditingParams: (query: {
|
|
|
19
20
|
}) => {
|
|
20
21
|
[key: string]: string | undefined;
|
|
21
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Parses the query parameters based on the provided allowed parameters or a resolver function, to extract additional parameters that should be allowed.
|
|
25
|
+
* @param {{ [key: string]: string | undefined }} queryParams Object of query parameters from incoming URL.
|
|
26
|
+
* @param {AllowedQueryParams} allowedParams Allowed parameters to map.
|
|
27
|
+
* @returns Object containing the list of missing required parameters and the allowed query parameters that were extracted.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export declare const getAllowedQueryParams: (queryParams: {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}, allowedParams?: AllowedQueryParams) => GetAllowedQueryParamsResult;
|
|
22
33
|
/**
|
|
23
34
|
* Next.js preview cookies enum
|
|
24
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/editing/utils.ts"],"names":[],"mappings":"A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types';
|
|
2
3
|
/**
|
|
3
4
|
* Helper function to handle cookie operations - can be mocked for testing
|
|
4
5
|
* @returns {Promise<NextCookies>} Next cookies
|
|
@@ -17,6 +18,12 @@ type EditingHandlerOptions = {
|
|
|
17
18
|
* The internal host URL for the Next.js application, used for server-side requests for page rendering during editing.
|
|
18
19
|
*/
|
|
19
20
|
sitecoreInternalEditingHostUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Query string parameters to allow and include in the search params.
|
|
23
|
+
* - Array: each item is a parameter name (string) or an object `{ name, required? }`.
|
|
24
|
+
* - Function: receives the request's query parameter names and returns the list of allowed parameters.
|
|
25
|
+
*/
|
|
26
|
+
allowedQueryParams?: AllowedQueryParams;
|
|
20
27
|
};
|
|
21
28
|
/**
|
|
22
29
|
* Creates a route handler for the editing render API route (e.g. '/api/editing/render')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editing-render-route-handler.d.ts","sourceRoot":"","sources":["../../src/route-handler/editing-render-route-handler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiB1C;;;GAGG;AACH,wBAAsB,cAAc,iBAMnC;AAED,KAAK,qBAAqB,GAAG;IAC3B;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAAI,SAAS,qBAAqB;eAwDrD,WAAW;
|
|
1
|
+
{"version":3,"file":"editing-render-route-handler.d.ts","sourceRoot":"","sources":["../../src/route-handler/editing-render-route-handler.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAiB1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;GAGG;AACH,wBAAsB,cAAc,iBAMnC;AAED,KAAK,qBAAqB,GAAG;IAC3B;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gCAAgC,GAAI,SAAS,qBAAqB;eAwDrD,WAAW;gBAiKV,WAAW;mBAnLd,WAAW;CAgSlC,CAAC"}
|