@uniformdev/canvas-next-rsc 19.122.1-alpha.0 → 19.125.2-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handler.d.mts +12 -1
- package/dist/handler.d.ts +12 -1
- package/dist/handler.js +167 -251
- package/dist/handler.mjs +169 -256
- package/package.json +11 -11
package/dist/handler.d.mts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
|
|
3
|
+
type ResolveFullPath = (options: {
|
|
4
|
+
/** The ID of the composition */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** The slug of the composition */
|
|
7
|
+
slug?: string;
|
|
8
|
+
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
+
path?: string;
|
|
10
|
+
/** The preview locale selected in Visual Canvas, available only if Localization is set up */
|
|
11
|
+
locale?: string;
|
|
12
|
+
}) => string | undefined;
|
|
3
13
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
14
|
+
resolveFullPath?: ResolveFullPath;
|
|
4
15
|
playgroundPath?: string;
|
|
5
16
|
};
|
|
6
|
-
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
17
|
+
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response | undefined>;
|
|
7
18
|
|
|
8
19
|
declare const createPreviewOPTIONSRouteHandler: () => () => Promise<Response>;
|
|
9
20
|
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
|
|
3
|
+
type ResolveFullPath = (options: {
|
|
4
|
+
/** The ID of the composition */
|
|
5
|
+
id?: string;
|
|
6
|
+
/** The slug of the composition */
|
|
7
|
+
slug?: string;
|
|
8
|
+
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
+
path?: string;
|
|
10
|
+
/** The preview locale selected in Visual Canvas, available only if Localization is set up */
|
|
11
|
+
locale?: string;
|
|
12
|
+
}) => string | undefined;
|
|
3
13
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
14
|
+
resolveFullPath?: ResolveFullPath;
|
|
4
15
|
playgroundPath?: string;
|
|
5
16
|
};
|
|
6
|
-
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
17
|
+
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response | undefined>;
|
|
7
18
|
|
|
8
19
|
declare const createPreviewOPTIONSRouteHandler: () => () => Promise<Response>;
|
|
9
20
|
|
package/dist/handler.js
CHANGED
|
@@ -27,86 +27,144 @@ __export(handler_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(handler_exports);
|
|
28
28
|
|
|
29
29
|
// src/handler/createPreviewGETRouteHandler.ts
|
|
30
|
-
var import_canvas5 = require("@uniformdev/canvas");
|
|
31
|
-
var import_headers2 = require("next/headers");
|
|
32
|
-
var import_navigation = require("next/navigation");
|
|
33
|
-
|
|
34
|
-
// src/utils/route.ts
|
|
35
|
-
var import_canvas4 = require("@uniformdev/canvas");
|
|
36
|
-
var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
|
|
37
|
-
var import_redirect = require("@uniformdev/redirect");
|
|
38
|
-
|
|
39
|
-
// src/clients/canvasClient.ts
|
|
40
|
-
var import_canvas2 = require("@uniformdev/canvas");
|
|
41
|
-
|
|
42
|
-
// src/config/helpers.ts
|
|
43
|
-
var import_canvas_next_rsc_shared = require("@uniformdev/canvas-next-rsc-shared");
|
|
44
|
-
|
|
45
|
-
// src/utils/draft.ts
|
|
46
30
|
var import_canvas = require("@uniformdev/canvas");
|
|
47
31
|
var import_headers = require("next/headers");
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let draftModeEnabled = false;
|
|
55
|
-
try {
|
|
56
|
-
draftModeEnabled = (0, import_headers.draftMode)().isEnabled;
|
|
57
|
-
} catch (e) {
|
|
32
|
+
var import_navigation = require("next/navigation");
|
|
33
|
+
var BASE_URL_EXAMPLE = "https://example.com";
|
|
34
|
+
var getQueryParam = (req, paramName) => {
|
|
35
|
+
const value = req.nextUrl.searchParams.get(paramName);
|
|
36
|
+
if (typeof value === "undefined") {
|
|
37
|
+
return void 0;
|
|
58
38
|
}
|
|
59
|
-
return
|
|
60
|
-
};
|
|
61
|
-
var isIncontextEditingEnabled = ({
|
|
62
|
-
searchParams
|
|
63
|
-
}) => {
|
|
64
|
-
const containsKey = typeof (searchParams == null ? void 0 : searchParams[import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== "undefined";
|
|
65
|
-
return containsKey;
|
|
66
|
-
};
|
|
67
|
-
var isOnVercelPreviewEnvironment = () => {
|
|
68
|
-
return process.env.VERCEL_ENV === "preview";
|
|
69
|
-
};
|
|
70
|
-
var isDevelopmentEnvironment = () => {
|
|
71
|
-
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
39
|
+
return Array.isArray(value) ? value[0] : value;
|
|
72
40
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
41
|
+
var contextualEditingQueryParams = [
|
|
42
|
+
import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
43
|
+
import_canvas.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
|
|
44
|
+
];
|
|
45
|
+
var createPreviewGETRouteHandler = (options) => {
|
|
46
|
+
return async (request) => {
|
|
47
|
+
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
48
|
+
if (isConfigCheck) {
|
|
49
|
+
return Response.json(
|
|
50
|
+
{
|
|
51
|
+
hasPlayground: Boolean(options == null ? void 0 : options.playgroundPath),
|
|
52
|
+
isUsingCustomFullPathResolver: false
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
headers: {
|
|
56
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
62
|
+
return new Response(null, { status: 204 });
|
|
63
|
+
}
|
|
64
|
+
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
65
|
+
return new Response("No preview secret is configured", { status: 401 });
|
|
66
|
+
}
|
|
67
|
+
const { searchParams } = new URL(request.url);
|
|
68
|
+
const isPlayground = searchParams.get(import_canvas.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
69
|
+
let pathToRedirectTo;
|
|
70
|
+
if (isPlayground) {
|
|
71
|
+
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
72
|
+
return new Response("No playground path is configured", { status: 401 });
|
|
73
|
+
}
|
|
74
|
+
pathToRedirectTo = options.playgroundPath;
|
|
75
|
+
}
|
|
76
|
+
const id = getQueryParam(request, compositionQueryParam.id);
|
|
77
|
+
const slug = getQueryParam(request, compositionQueryParam.slug);
|
|
78
|
+
const path = getQueryParam(request, compositionQueryParam.path);
|
|
79
|
+
const locale = getQueryParam(request, compositionQueryParam.locale);
|
|
80
|
+
const disable = getQueryParam(request, "disable");
|
|
81
|
+
const secret = getQueryParam(request, import_canvas.SECRET_QUERY_STRING_PARAM);
|
|
82
|
+
const referer = request.headers.get("referer");
|
|
83
|
+
const isUniformContextualEditing = getQueryParam(request, import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true" && (0, import_canvas.isAllowedReferrer)(referer || void 0);
|
|
84
|
+
if (typeof pathToRedirectTo === "undefined") {
|
|
85
|
+
const resolveFullPath = (options == null ? void 0 : options.resolveFullPath) || resolveFullPathDefault;
|
|
86
|
+
pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
|
|
87
|
+
}
|
|
88
|
+
validateLocalRedirectUrl(pathToRedirectTo);
|
|
89
|
+
if (!pathToRedirectTo) {
|
|
90
|
+
return new Response("Could not resolve the full path of the preview page", { status: 400 });
|
|
91
|
+
}
|
|
92
|
+
if (disable) {
|
|
93
|
+
(0, import_headers.draftMode)().disable();
|
|
94
|
+
(0, import_navigation.redirect)(pathToRedirectTo);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
98
|
+
return new Response("Invalid preview secret", { status: 401 });
|
|
99
|
+
}
|
|
100
|
+
(0, import_headers.draftMode)().enable();
|
|
101
|
+
const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
|
|
102
|
+
assignRequestQueryToSearchParams(redirectionUrl.searchParams, searchParams);
|
|
103
|
+
if (!isUniformContextualEditing) {
|
|
104
|
+
contextualEditingQueryParams.forEach((param) => {
|
|
105
|
+
redirectionUrl.searchParams.delete(param);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
|
|
109
|
+
(0, import_navigation.redirect)(fullPathToRedirectTo);
|
|
88
110
|
};
|
|
89
111
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
function validateLocalRedirectUrl(pathToRedirectTo) {
|
|
113
|
+
if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
|
|
114
|
+
throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
118
|
+
return path || slug;
|
|
119
|
+
};
|
|
120
|
+
var compositionQueryParam = {
|
|
121
|
+
id: "id",
|
|
122
|
+
slug: "slug",
|
|
123
|
+
path: "path",
|
|
124
|
+
locale: "locale"
|
|
125
|
+
};
|
|
126
|
+
var assignRequestQueryToSearchParams = (searchParams, query) => {
|
|
127
|
+
const compositionQueryParamNames = Object.values(compositionQueryParam);
|
|
128
|
+
for (const [name, value] of query.entries()) {
|
|
129
|
+
if (name === import_canvas.SECRET_QUERY_STRING_PARAM) {
|
|
130
|
+
continue;
|
|
97
131
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
if (compositionQueryParamNames.includes(name)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (typeof value === "undefined") {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
searchParams.append(name, value);
|
|
104
139
|
}
|
|
105
|
-
|
|
106
|
-
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
143
|
+
var createPreviewOPTIONSRouteHandler = () => {
|
|
144
|
+
return async () => {
|
|
145
|
+
return new Response(null, {
|
|
146
|
+
headers: {
|
|
147
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
148
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
149
|
+
"Access-Control-Allow-Headers": "*"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
107
152
|
};
|
|
108
153
|
};
|
|
109
154
|
|
|
155
|
+
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
156
|
+
var import_canvas5 = require("@uniformdev/canvas");
|
|
157
|
+
var import_cache = require("next/cache");
|
|
158
|
+
|
|
159
|
+
// src/handler/helpers.ts
|
|
160
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
161
|
+
var import_canvas_next_rsc_shared = require("@uniformdev/canvas-next-rsc-shared");
|
|
162
|
+
var import_edge_config = require("@vercel/edge-config");
|
|
163
|
+
var import_svix = require("svix");
|
|
164
|
+
|
|
165
|
+
// src/clients/canvasClient.ts
|
|
166
|
+
var import_canvas2 = require("@uniformdev/canvas");
|
|
167
|
+
|
|
110
168
|
// src/env/index.ts
|
|
111
169
|
var env = {
|
|
112
170
|
getProjectId: () => {
|
|
@@ -196,6 +254,31 @@ var getCanvasClient = (options) => {
|
|
|
196
254
|
});
|
|
197
255
|
};
|
|
198
256
|
|
|
257
|
+
// src/clients/projectMapClient.ts
|
|
258
|
+
var import_project_map = require("@uniformdev/project-map");
|
|
259
|
+
var getProjectMapClient = (options) => {
|
|
260
|
+
const manifestClient = new import_project_map.ProjectMapClient({
|
|
261
|
+
apiHost: env.getApiHost(),
|
|
262
|
+
apiKey: env.getApiKey(),
|
|
263
|
+
projectId: env.getProjectId(),
|
|
264
|
+
fetch: (req, init) => {
|
|
265
|
+
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
266
|
+
return fetch(req, {
|
|
267
|
+
...init,
|
|
268
|
+
headers: {
|
|
269
|
+
...init == null ? void 0 : init.headers,
|
|
270
|
+
"x-bypass-cache": "true"
|
|
271
|
+
},
|
|
272
|
+
cache,
|
|
273
|
+
next: {
|
|
274
|
+
revalidate
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
return manifestClient;
|
|
280
|
+
};
|
|
281
|
+
|
|
199
282
|
// src/clients/routeClient.ts
|
|
200
283
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
201
284
|
var getRouteClient = (options) => {
|
|
@@ -242,173 +325,6 @@ var getRouteClient = (options) => {
|
|
|
242
325
|
});
|
|
243
326
|
return client;
|
|
244
327
|
};
|
|
245
|
-
var getDefaultRouteClient = ({ searchParams }) => {
|
|
246
|
-
return getRouteClient({
|
|
247
|
-
cache: getCanvasCacheStrategy({
|
|
248
|
-
searchParams
|
|
249
|
-
})
|
|
250
|
-
});
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/utils/route.ts
|
|
254
|
-
var retrieveRouteByPath = async ({
|
|
255
|
-
path,
|
|
256
|
-
state,
|
|
257
|
-
searchParams,
|
|
258
|
-
fetchOptions
|
|
259
|
-
}) => {
|
|
260
|
-
var _a;
|
|
261
|
-
const client = getDefaultRouteClient({
|
|
262
|
-
searchParams
|
|
263
|
-
});
|
|
264
|
-
let queryPath = path;
|
|
265
|
-
if (searchParams && Object.keys(searchParams).length > 0) {
|
|
266
|
-
const helper = new URL((0, import_canvas_next_rsc_shared2.getBaseUrl)());
|
|
267
|
-
helper.pathname = path;
|
|
268
|
-
Object.entries(searchParams).forEach(([key, value]) => {
|
|
269
|
-
if (typeof value === "string") {
|
|
270
|
-
helper.searchParams.set(key, value);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
if (helper.searchParams.size > 0) {
|
|
274
|
-
queryPath = `${helper.pathname}${helper.search}`;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return await client.getRoute({
|
|
278
|
-
...fetchOptions,
|
|
279
|
-
path: queryPath,
|
|
280
|
-
state,
|
|
281
|
-
withComponentIDs: true,
|
|
282
|
-
withContentSourceMap: isOnVercelPreviewEnvironment() && ((_a = (0, import_canvas_next_rsc_shared2.getServerConfig)().experimental) == null ? void 0 : _a.vercelVisualEditing)
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
var resolveRedirectHref = (resolveResult, path) => {
|
|
286
|
-
const requestUrl = `${(0, import_canvas_next_rsc_shared2.getBaseUrl)()}${path}`;
|
|
287
|
-
const expandedUrl = (0, import_redirect.getTargetVariableExpandedUrl)(requestUrl, resolveResult.redirect);
|
|
288
|
-
const url = new URL(expandedUrl);
|
|
289
|
-
return url.pathname;
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// src/handler/createPreviewGETRouteHandler.ts
|
|
293
|
-
var getQueryParam = (req, paramName) => {
|
|
294
|
-
const value = req.nextUrl.searchParams.get(paramName);
|
|
295
|
-
if (typeof value === "undefined") {
|
|
296
|
-
return void 0;
|
|
297
|
-
}
|
|
298
|
-
return Array.isArray(value) ? value[0] : value;
|
|
299
|
-
};
|
|
300
|
-
var createPreviewGETRouteHandler = (options) => {
|
|
301
|
-
return async (request) => {
|
|
302
|
-
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
303
|
-
if (isConfigCheck) {
|
|
304
|
-
return Response.json(
|
|
305
|
-
{
|
|
306
|
-
hasPlayground: Boolean(options == null ? void 0 : options.playgroundPath),
|
|
307
|
-
isUsingCustomFullPathResolver: false
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
headers: {
|
|
311
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
317
|
-
return new Response(null, { status: 204 });
|
|
318
|
-
}
|
|
319
|
-
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
320
|
-
return new Response("No preview secret is configured", { status: 401 });
|
|
321
|
-
}
|
|
322
|
-
const { searchParams } = new URL(request.url);
|
|
323
|
-
const secret = searchParams.get("secret");
|
|
324
|
-
const path = searchParams.get("path");
|
|
325
|
-
const isPlayground = searchParams.get(import_canvas5.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
326
|
-
const id = searchParams.get("id");
|
|
327
|
-
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
328
|
-
return new Response("Invalid preview secret", { status: 401 });
|
|
329
|
-
}
|
|
330
|
-
if (!isPlayground) {
|
|
331
|
-
if (!path) {
|
|
332
|
-
return new Response("Path not provided", { status: 401 });
|
|
333
|
-
}
|
|
334
|
-
const resolveResult = await retrieveRouteByPath({
|
|
335
|
-
path,
|
|
336
|
-
state: import_canvas5.CANVAS_DRAFT_STATE,
|
|
337
|
-
searchParams: {
|
|
338
|
-
// about to be in draft mode so pretend for now.
|
|
339
|
-
[import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]: "true"
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
(0, import_headers2.draftMode)().enable();
|
|
343
|
-
if (resolveResult.type === "redirect") {
|
|
344
|
-
const href = resolveRedirectHref(resolveResult, path);
|
|
345
|
-
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
346
|
-
(0, import_navigation.redirect)(`${href}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
347
|
-
} else {
|
|
348
|
-
(0, import_navigation.redirect)(href);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (resolveResult.type === "notFound") {
|
|
352
|
-
return new Response("Invalid path", { status: 401 });
|
|
353
|
-
}
|
|
354
|
-
(0, import_navigation.redirect)(`${path}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
355
|
-
} else {
|
|
356
|
-
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
357
|
-
return new Response("No playground path is configured", { status: 401 });
|
|
358
|
-
}
|
|
359
|
-
(0, import_headers2.draftMode)().enable();
|
|
360
|
-
(0, import_navigation.redirect)(`${options.playgroundPath}?id=${id}&${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
366
|
-
var createPreviewOPTIONSRouteHandler = () => {
|
|
367
|
-
return async () => {
|
|
368
|
-
return new Response(null, {
|
|
369
|
-
headers: {
|
|
370
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
371
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
372
|
-
"Access-Control-Allow-Headers": "*"
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
379
|
-
var import_canvas7 = require("@uniformdev/canvas");
|
|
380
|
-
var import_cache = require("next/cache");
|
|
381
|
-
|
|
382
|
-
// src/handler/helpers.ts
|
|
383
|
-
var import_canvas6 = require("@uniformdev/canvas");
|
|
384
|
-
var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
|
|
385
|
-
var import_edge_config = require("@vercel/edge-config");
|
|
386
|
-
var import_svix = require("svix");
|
|
387
|
-
|
|
388
|
-
// src/clients/projectMapClient.ts
|
|
389
|
-
var import_project_map = require("@uniformdev/project-map");
|
|
390
|
-
var getProjectMapClient = (options) => {
|
|
391
|
-
const manifestClient = new import_project_map.ProjectMapClient({
|
|
392
|
-
apiHost: env.getApiHost(),
|
|
393
|
-
apiKey: env.getApiKey(),
|
|
394
|
-
projectId: env.getProjectId(),
|
|
395
|
-
fetch: (req, init) => {
|
|
396
|
-
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
397
|
-
return fetch(req, {
|
|
398
|
-
...init,
|
|
399
|
-
headers: {
|
|
400
|
-
...init == null ? void 0 : init.headers,
|
|
401
|
-
"x-bypass-cache": "true"
|
|
402
|
-
},
|
|
403
|
-
cache,
|
|
404
|
-
next: {
|
|
405
|
-
revalidate
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
return manifestClient;
|
|
411
|
-
};
|
|
412
328
|
|
|
413
329
|
// src/handler/helpers.ts
|
|
414
330
|
var isSvixMessage = async (request) => {
|
|
@@ -480,7 +396,7 @@ var getComposition = async ({ compositionId }) => {
|
|
|
480
396
|
});
|
|
481
397
|
return composition;
|
|
482
398
|
} catch (err) {
|
|
483
|
-
if (err instanceof
|
|
399
|
+
if (err instanceof import_canvas4.ApiClientError && err.statusCode === 404) {
|
|
484
400
|
return null;
|
|
485
401
|
}
|
|
486
402
|
throw err;
|
|
@@ -528,7 +444,7 @@ var processEdgeConfigChange = async ({ source_url }) => {
|
|
|
528
444
|
console.warn("UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert");
|
|
529
445
|
return;
|
|
530
446
|
}
|
|
531
|
-
const config = (0,
|
|
447
|
+
const config = (0, import_canvas_next_rsc_shared.getServerConfig)();
|
|
532
448
|
const routeClient = getRouteClient({
|
|
533
449
|
cache: {
|
|
534
450
|
type: "no-cache"
|
|
@@ -618,7 +534,7 @@ var handleManifestPublished = async (body) => {
|
|
|
618
534
|
};
|
|
619
535
|
|
|
620
536
|
// src/handler/messages/handleProjectMapNodeDelete.ts
|
|
621
|
-
var
|
|
537
|
+
var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
|
|
622
538
|
var import_webhooks5 = require("@uniformdev/webhooks");
|
|
623
539
|
var handleProjectMapNodeDelete = async (body) => {
|
|
624
540
|
var _a;
|
|
@@ -628,7 +544,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
628
544
|
}
|
|
629
545
|
const tags = [];
|
|
630
546
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
631
|
-
const config = (0,
|
|
547
|
+
const config = (0, import_canvas_next_rsc_shared2.getServerConfig)();
|
|
632
548
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
633
549
|
await processEdgeConfigChange({
|
|
634
550
|
source_url: parsed.data.path
|
|
@@ -640,7 +556,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
640
556
|
};
|
|
641
557
|
|
|
642
558
|
// src/handler/messages/handleProjectMapNodeInsert.ts
|
|
643
|
-
var
|
|
559
|
+
var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
|
|
644
560
|
var import_webhooks6 = require("@uniformdev/webhooks");
|
|
645
561
|
var handleProjectMapNodeInsert = async (body) => {
|
|
646
562
|
var _a;
|
|
@@ -650,7 +566,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
650
566
|
}
|
|
651
567
|
const tags = [];
|
|
652
568
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
653
|
-
const config = (0,
|
|
569
|
+
const config = (0, import_canvas_next_rsc_shared3.getServerConfig)();
|
|
654
570
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
655
571
|
await processEdgeConfigChange({
|
|
656
572
|
source_url: parsed.data.path
|
|
@@ -662,7 +578,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
662
578
|
};
|
|
663
579
|
|
|
664
580
|
// src/handler/messages/handleProjectMapNodeUpdate.ts
|
|
665
|
-
var
|
|
581
|
+
var import_canvas_next_rsc_shared4 = require("@uniformdev/canvas-next-rsc-shared");
|
|
666
582
|
var import_webhooks7 = require("@uniformdev/webhooks");
|
|
667
583
|
var handleProjectMapNodeUpdate = async (body) => {
|
|
668
584
|
var _a;
|
|
@@ -673,7 +589,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
673
589
|
const tags = [];
|
|
674
590
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
675
591
|
tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
|
|
676
|
-
const config = (0,
|
|
592
|
+
const config = (0, import_canvas_next_rsc_shared4.getServerConfig)();
|
|
677
593
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
678
594
|
await processEdgeConfigChange({
|
|
679
595
|
source_url: parsed.data.path
|
|
@@ -685,7 +601,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
685
601
|
};
|
|
686
602
|
|
|
687
603
|
// src/handler/messages/handleRedirectDelete.ts
|
|
688
|
-
var
|
|
604
|
+
var import_canvas_next_rsc_shared5 = require("@uniformdev/canvas-next-rsc-shared");
|
|
689
605
|
var import_webhooks8 = require("@uniformdev/webhooks");
|
|
690
606
|
var handleRedirectDelete = async (body) => {
|
|
691
607
|
var _a;
|
|
@@ -693,7 +609,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
693
609
|
if (!parsed.success) {
|
|
694
610
|
return void 0;
|
|
695
611
|
}
|
|
696
|
-
const config = (0,
|
|
612
|
+
const config = (0, import_canvas_next_rsc_shared5.getServerConfig)();
|
|
697
613
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
698
614
|
await processEdgeConfigChange(parsed.data);
|
|
699
615
|
}
|
|
@@ -701,7 +617,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
701
617
|
};
|
|
702
618
|
|
|
703
619
|
// src/handler/messages/handleRedirectInsert.ts
|
|
704
|
-
var
|
|
620
|
+
var import_canvas_next_rsc_shared6 = require("@uniformdev/canvas-next-rsc-shared");
|
|
705
621
|
var import_webhooks9 = require("@uniformdev/webhooks");
|
|
706
622
|
var handleRedirectInsert = async (body) => {
|
|
707
623
|
var _a;
|
|
@@ -709,7 +625,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
709
625
|
if (!parsed.success) {
|
|
710
626
|
return void 0;
|
|
711
627
|
}
|
|
712
|
-
const config = (0,
|
|
628
|
+
const config = (0, import_canvas_next_rsc_shared6.getServerConfig)();
|
|
713
629
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
714
630
|
await processEdgeConfigChange(parsed.data);
|
|
715
631
|
}
|
|
@@ -717,7 +633,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
717
633
|
};
|
|
718
634
|
|
|
719
635
|
// src/handler/messages/handleRedirectUpdate.ts
|
|
720
|
-
var
|
|
636
|
+
var import_canvas_next_rsc_shared7 = require("@uniformdev/canvas-next-rsc-shared");
|
|
721
637
|
var import_webhooks10 = require("@uniformdev/webhooks");
|
|
722
638
|
var handleRedirectUpdate = async (body) => {
|
|
723
639
|
var _a;
|
|
@@ -725,7 +641,7 @@ var handleRedirectUpdate = async (body) => {
|
|
|
725
641
|
if (!parsed.success) {
|
|
726
642
|
return void 0;
|
|
727
643
|
}
|
|
728
|
-
const config = (0,
|
|
644
|
+
const config = (0, import_canvas_next_rsc_shared7.getServerConfig)();
|
|
729
645
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
730
646
|
await processEdgeConfigChange(parsed.data);
|
|
731
647
|
}
|
|
@@ -737,7 +653,7 @@ var createPreviewPOSTRouteHandler = () => {
|
|
|
737
653
|
return async (request) => {
|
|
738
654
|
let previewSecretPassed = false;
|
|
739
655
|
if (process.env.UNIFORM_PREVIEW_SECRET) {
|
|
740
|
-
const secretValue = request.nextUrl.searchParams.get(
|
|
656
|
+
const secretValue = request.nextUrl.searchParams.get(import_canvas5.SECRET_QUERY_STRING_PARAM);
|
|
741
657
|
if (secretValue !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
742
658
|
console.warn(
|
|
743
659
|
"The preview secret passed in the query string does not match the UNIFORM_PREVIEW_SECRET env var."
|
package/dist/handler.mjs
CHANGED
|
@@ -1,92 +1,147 @@
|
|
|
1
1
|
// src/handler/createPreviewGETRouteHandler.ts
|
|
2
2
|
import {
|
|
3
|
-
CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2,
|
|
4
3
|
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
|
|
5
|
-
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
|
|
4
|
+
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
5
|
+
isAllowedReferrer,
|
|
6
|
+
SECRET_QUERY_STRING_PARAM
|
|
6
7
|
} from "@uniformdev/canvas";
|
|
7
|
-
import { draftMode as draftMode2 } from "next/headers";
|
|
8
|
-
import { redirect } from "next/navigation";
|
|
9
|
-
|
|
10
|
-
// src/utils/route.ts
|
|
11
|
-
import {
|
|
12
|
-
CANVAS_DRAFT_STATE,
|
|
13
|
-
CANVAS_EDITOR_STATE,
|
|
14
|
-
CANVAS_PUBLISHED_STATE
|
|
15
|
-
} from "@uniformdev/canvas";
|
|
16
|
-
import { getBaseUrl, getServerConfig as getServerConfig2, resolvePath } from "@uniformdev/canvas-next-rsc-shared";
|
|
17
|
-
import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
|
|
18
|
-
|
|
19
|
-
// src/clients/canvasClient.ts
|
|
20
|
-
import { CanvasClient } from "@uniformdev/canvas";
|
|
21
|
-
|
|
22
|
-
// src/config/helpers.ts
|
|
23
|
-
import { getServerConfig } from "@uniformdev/canvas-next-rsc-shared";
|
|
24
|
-
|
|
25
|
-
// src/utils/draft.ts
|
|
26
|
-
import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
27
8
|
import { draftMode } from "next/headers";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
let draftModeEnabled = false;
|
|
35
|
-
try {
|
|
36
|
-
draftModeEnabled = draftMode().isEnabled;
|
|
37
|
-
} catch (e) {
|
|
9
|
+
import { redirect } from "next/navigation";
|
|
10
|
+
var BASE_URL_EXAMPLE = "https://example.com";
|
|
11
|
+
var getQueryParam = (req, paramName) => {
|
|
12
|
+
const value = req.nextUrl.searchParams.get(paramName);
|
|
13
|
+
if (typeof value === "undefined") {
|
|
14
|
+
return void 0;
|
|
38
15
|
}
|
|
39
|
-
return
|
|
40
|
-
};
|
|
41
|
-
var isIncontextEditingEnabled = ({
|
|
42
|
-
searchParams
|
|
43
|
-
}) => {
|
|
44
|
-
const containsKey = typeof (searchParams == null ? void 0 : searchParams[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== "undefined";
|
|
45
|
-
return containsKey;
|
|
46
|
-
};
|
|
47
|
-
var isOnVercelPreviewEnvironment = () => {
|
|
48
|
-
return process.env.VERCEL_ENV === "preview";
|
|
49
|
-
};
|
|
50
|
-
var isDevelopmentEnvironment = () => {
|
|
51
|
-
return process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
|
|
16
|
+
return Array.isArray(value) ? value[0] : value;
|
|
52
17
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
18
|
+
var contextualEditingQueryParams = [
|
|
19
|
+
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
20
|
+
IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
|
|
21
|
+
];
|
|
22
|
+
var createPreviewGETRouteHandler = (options) => {
|
|
23
|
+
return async (request) => {
|
|
24
|
+
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
25
|
+
if (isConfigCheck) {
|
|
26
|
+
return Response.json(
|
|
27
|
+
{
|
|
28
|
+
hasPlayground: Boolean(options == null ? void 0 : options.playgroundPath),
|
|
29
|
+
isUsingCustomFullPathResolver: false
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
headers: {
|
|
33
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
39
|
+
return new Response(null, { status: 204 });
|
|
40
|
+
}
|
|
41
|
+
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
42
|
+
return new Response("No preview secret is configured", { status: 401 });
|
|
43
|
+
}
|
|
44
|
+
const { searchParams } = new URL(request.url);
|
|
45
|
+
const isPlayground = searchParams.get(IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
46
|
+
let pathToRedirectTo;
|
|
47
|
+
if (isPlayground) {
|
|
48
|
+
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
49
|
+
return new Response("No playground path is configured", { status: 401 });
|
|
50
|
+
}
|
|
51
|
+
pathToRedirectTo = options.playgroundPath;
|
|
52
|
+
}
|
|
53
|
+
const id = getQueryParam(request, compositionQueryParam.id);
|
|
54
|
+
const slug = getQueryParam(request, compositionQueryParam.slug);
|
|
55
|
+
const path = getQueryParam(request, compositionQueryParam.path);
|
|
56
|
+
const locale = getQueryParam(request, compositionQueryParam.locale);
|
|
57
|
+
const disable = getQueryParam(request, "disable");
|
|
58
|
+
const secret = getQueryParam(request, SECRET_QUERY_STRING_PARAM);
|
|
59
|
+
const referer = request.headers.get("referer");
|
|
60
|
+
const isUniformContextualEditing = getQueryParam(request, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM) === "true" && isAllowedReferrer(referer || void 0);
|
|
61
|
+
if (typeof pathToRedirectTo === "undefined") {
|
|
62
|
+
const resolveFullPath = (options == null ? void 0 : options.resolveFullPath) || resolveFullPathDefault;
|
|
63
|
+
pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
|
|
64
|
+
}
|
|
65
|
+
validateLocalRedirectUrl(pathToRedirectTo);
|
|
66
|
+
if (!pathToRedirectTo) {
|
|
67
|
+
return new Response("Could not resolve the full path of the preview page", { status: 400 });
|
|
68
|
+
}
|
|
69
|
+
if (disable) {
|
|
70
|
+
draftMode().disable();
|
|
71
|
+
redirect(pathToRedirectTo);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
75
|
+
return new Response("Invalid preview secret", { status: 401 });
|
|
76
|
+
}
|
|
77
|
+
draftMode().enable();
|
|
78
|
+
const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
|
|
79
|
+
assignRequestQueryToSearchParams(redirectionUrl.searchParams, searchParams);
|
|
80
|
+
if (!isUniformContextualEditing) {
|
|
81
|
+
contextualEditingQueryParams.forEach((param) => {
|
|
82
|
+
redirectionUrl.searchParams.delete(param);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
|
|
86
|
+
redirect(fullPathToRedirectTo);
|
|
68
87
|
};
|
|
69
88
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
function validateLocalRedirectUrl(pathToRedirectTo) {
|
|
90
|
+
if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
|
|
91
|
+
throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
var resolveFullPathDefault = ({ slug, path }) => {
|
|
95
|
+
return path || slug;
|
|
96
|
+
};
|
|
97
|
+
var compositionQueryParam = {
|
|
98
|
+
id: "id",
|
|
99
|
+
slug: "slug",
|
|
100
|
+
path: "path",
|
|
101
|
+
locale: "locale"
|
|
102
|
+
};
|
|
103
|
+
var assignRequestQueryToSearchParams = (searchParams, query) => {
|
|
104
|
+
const compositionQueryParamNames = Object.values(compositionQueryParam);
|
|
105
|
+
for (const [name, value] of query.entries()) {
|
|
106
|
+
if (name === SECRET_QUERY_STRING_PARAM) {
|
|
107
|
+
continue;
|
|
77
108
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
109
|
+
if (compositionQueryParamNames.includes(name)) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (typeof value === "undefined") {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
searchParams.append(name, value);
|
|
84
116
|
}
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
120
|
+
var createPreviewOPTIONSRouteHandler = () => {
|
|
121
|
+
return async () => {
|
|
122
|
+
return new Response(null, {
|
|
123
|
+
headers: {
|
|
124
|
+
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
125
|
+
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
126
|
+
"Access-Control-Allow-Headers": "*"
|
|
127
|
+
}
|
|
128
|
+
});
|
|
87
129
|
};
|
|
88
130
|
};
|
|
89
131
|
|
|
132
|
+
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
133
|
+
import { SECRET_QUERY_STRING_PARAM as SECRET_QUERY_STRING_PARAM2 } from "@uniformdev/canvas";
|
|
134
|
+
import { revalidateTag } from "next/cache";
|
|
135
|
+
|
|
136
|
+
// src/handler/helpers.ts
|
|
137
|
+
import { ApiClientError } from "@uniformdev/canvas";
|
|
138
|
+
import { getServerConfig } from "@uniformdev/canvas-next-rsc-shared";
|
|
139
|
+
import { parseConnectionString } from "@vercel/edge-config";
|
|
140
|
+
import { Webhook } from "svix";
|
|
141
|
+
|
|
142
|
+
// src/clients/canvasClient.ts
|
|
143
|
+
import { CanvasClient } from "@uniformdev/canvas";
|
|
144
|
+
|
|
90
145
|
// src/env/index.ts
|
|
91
146
|
var env = {
|
|
92
147
|
getProjectId: () => {
|
|
@@ -176,6 +231,31 @@ var getCanvasClient = (options) => {
|
|
|
176
231
|
});
|
|
177
232
|
};
|
|
178
233
|
|
|
234
|
+
// src/clients/projectMapClient.ts
|
|
235
|
+
import { ProjectMapClient } from "@uniformdev/project-map";
|
|
236
|
+
var getProjectMapClient = (options) => {
|
|
237
|
+
const manifestClient = new ProjectMapClient({
|
|
238
|
+
apiHost: env.getApiHost(),
|
|
239
|
+
apiKey: env.getApiKey(),
|
|
240
|
+
projectId: env.getProjectId(),
|
|
241
|
+
fetch: (req, init) => {
|
|
242
|
+
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
243
|
+
return fetch(req, {
|
|
244
|
+
...init,
|
|
245
|
+
headers: {
|
|
246
|
+
...init == null ? void 0 : init.headers,
|
|
247
|
+
"x-bypass-cache": "true"
|
|
248
|
+
},
|
|
249
|
+
cache,
|
|
250
|
+
next: {
|
|
251
|
+
revalidate
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return manifestClient;
|
|
257
|
+
};
|
|
258
|
+
|
|
179
259
|
// src/clients/routeClient.ts
|
|
180
260
|
import { RouteClient } from "@uniformdev/canvas";
|
|
181
261
|
var getRouteClient = (options) => {
|
|
@@ -222,173 +302,6 @@ var getRouteClient = (options) => {
|
|
|
222
302
|
});
|
|
223
303
|
return client;
|
|
224
304
|
};
|
|
225
|
-
var getDefaultRouteClient = ({ searchParams }) => {
|
|
226
|
-
return getRouteClient({
|
|
227
|
-
cache: getCanvasCacheStrategy({
|
|
228
|
-
searchParams
|
|
229
|
-
})
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
// src/utils/route.ts
|
|
234
|
-
var retrieveRouteByPath = async ({
|
|
235
|
-
path,
|
|
236
|
-
state,
|
|
237
|
-
searchParams,
|
|
238
|
-
fetchOptions
|
|
239
|
-
}) => {
|
|
240
|
-
var _a;
|
|
241
|
-
const client = getDefaultRouteClient({
|
|
242
|
-
searchParams
|
|
243
|
-
});
|
|
244
|
-
let queryPath = path;
|
|
245
|
-
if (searchParams && Object.keys(searchParams).length > 0) {
|
|
246
|
-
const helper = new URL(getBaseUrl());
|
|
247
|
-
helper.pathname = path;
|
|
248
|
-
Object.entries(searchParams).forEach(([key, value]) => {
|
|
249
|
-
if (typeof value === "string") {
|
|
250
|
-
helper.searchParams.set(key, value);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
if (helper.searchParams.size > 0) {
|
|
254
|
-
queryPath = `${helper.pathname}${helper.search}`;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return await client.getRoute({
|
|
258
|
-
...fetchOptions,
|
|
259
|
-
path: queryPath,
|
|
260
|
-
state,
|
|
261
|
-
withComponentIDs: true,
|
|
262
|
-
withContentSourceMap: isOnVercelPreviewEnvironment() && ((_a = getServerConfig2().experimental) == null ? void 0 : _a.vercelVisualEditing)
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
var resolveRedirectHref = (resolveResult, path) => {
|
|
266
|
-
const requestUrl = `${getBaseUrl()}${path}`;
|
|
267
|
-
const expandedUrl = getTargetVariableExpandedUrl(requestUrl, resolveResult.redirect);
|
|
268
|
-
const url = new URL(expandedUrl);
|
|
269
|
-
return url.pathname;
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
// src/handler/createPreviewGETRouteHandler.ts
|
|
273
|
-
var getQueryParam = (req, paramName) => {
|
|
274
|
-
const value = req.nextUrl.searchParams.get(paramName);
|
|
275
|
-
if (typeof value === "undefined") {
|
|
276
|
-
return void 0;
|
|
277
|
-
}
|
|
278
|
-
return Array.isArray(value) ? value[0] : value;
|
|
279
|
-
};
|
|
280
|
-
var createPreviewGETRouteHandler = (options) => {
|
|
281
|
-
return async (request) => {
|
|
282
|
-
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
283
|
-
if (isConfigCheck) {
|
|
284
|
-
return Response.json(
|
|
285
|
-
{
|
|
286
|
-
hasPlayground: Boolean(options == null ? void 0 : options.playgroundPath),
|
|
287
|
-
isUsingCustomFullPathResolver: false
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
headers: {
|
|
291
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
297
|
-
return new Response(null, { status: 204 });
|
|
298
|
-
}
|
|
299
|
-
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
300
|
-
return new Response("No preview secret is configured", { status: 401 });
|
|
301
|
-
}
|
|
302
|
-
const { searchParams } = new URL(request.url);
|
|
303
|
-
const secret = searchParams.get("secret");
|
|
304
|
-
const path = searchParams.get("path");
|
|
305
|
-
const isPlayground = searchParams.get(IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
306
|
-
const id = searchParams.get("id");
|
|
307
|
-
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
308
|
-
return new Response("Invalid preview secret", { status: 401 });
|
|
309
|
-
}
|
|
310
|
-
if (!isPlayground) {
|
|
311
|
-
if (!path) {
|
|
312
|
-
return new Response("Path not provided", { status: 401 });
|
|
313
|
-
}
|
|
314
|
-
const resolveResult = await retrieveRouteByPath({
|
|
315
|
-
path,
|
|
316
|
-
state: CANVAS_DRAFT_STATE2,
|
|
317
|
-
searchParams: {
|
|
318
|
-
// about to be in draft mode so pretend for now.
|
|
319
|
-
[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2]: "true"
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
draftMode2().enable();
|
|
323
|
-
if (resolveResult.type === "redirect") {
|
|
324
|
-
const href = resolveRedirectHref(resolveResult, path);
|
|
325
|
-
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
326
|
-
redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
327
|
-
} else {
|
|
328
|
-
redirect(href);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
if (resolveResult.type === "notFound") {
|
|
332
|
-
return new Response("Invalid path", { status: 401 });
|
|
333
|
-
}
|
|
334
|
-
redirect(`${path}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
335
|
-
} else {
|
|
336
|
-
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
337
|
-
return new Response("No playground path is configured", { status: 401 });
|
|
338
|
-
}
|
|
339
|
-
draftMode2().enable();
|
|
340
|
-
redirect(`${options.playgroundPath}?id=${id}&${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
346
|
-
var createPreviewOPTIONSRouteHandler = () => {
|
|
347
|
-
return async () => {
|
|
348
|
-
return new Response(null, {
|
|
349
|
-
headers: {
|
|
350
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
351
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
352
|
-
"Access-Control-Allow-Headers": "*"
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
};
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
359
|
-
import { SECRET_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
360
|
-
import { revalidateTag } from "next/cache";
|
|
361
|
-
|
|
362
|
-
// src/handler/helpers.ts
|
|
363
|
-
import { ApiClientError } from "@uniformdev/canvas";
|
|
364
|
-
import { getServerConfig as getServerConfig3 } from "@uniformdev/canvas-next-rsc-shared";
|
|
365
|
-
import { parseConnectionString } from "@vercel/edge-config";
|
|
366
|
-
import { Webhook } from "svix";
|
|
367
|
-
|
|
368
|
-
// src/clients/projectMapClient.ts
|
|
369
|
-
import { ProjectMapClient } from "@uniformdev/project-map";
|
|
370
|
-
var getProjectMapClient = (options) => {
|
|
371
|
-
const manifestClient = new ProjectMapClient({
|
|
372
|
-
apiHost: env.getApiHost(),
|
|
373
|
-
apiKey: env.getApiKey(),
|
|
374
|
-
projectId: env.getProjectId(),
|
|
375
|
-
fetch: (req, init) => {
|
|
376
|
-
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
377
|
-
return fetch(req, {
|
|
378
|
-
...init,
|
|
379
|
-
headers: {
|
|
380
|
-
...init == null ? void 0 : init.headers,
|
|
381
|
-
"x-bypass-cache": "true"
|
|
382
|
-
},
|
|
383
|
-
cache,
|
|
384
|
-
next: {
|
|
385
|
-
revalidate
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
return manifestClient;
|
|
391
|
-
};
|
|
392
305
|
|
|
393
306
|
// src/handler/helpers.ts
|
|
394
307
|
var isSvixMessage = async (request) => {
|
|
@@ -508,7 +421,7 @@ var processEdgeConfigChange = async ({ source_url }) => {
|
|
|
508
421
|
console.warn("UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert");
|
|
509
422
|
return;
|
|
510
423
|
}
|
|
511
|
-
const config =
|
|
424
|
+
const config = getServerConfig();
|
|
512
425
|
const routeClient = getRouteClient({
|
|
513
426
|
cache: {
|
|
514
427
|
type: "no-cache"
|
|
@@ -598,7 +511,7 @@ var handleManifestPublished = async (body) => {
|
|
|
598
511
|
};
|
|
599
512
|
|
|
600
513
|
// src/handler/messages/handleProjectMapNodeDelete.ts
|
|
601
|
-
import { getServerConfig as
|
|
514
|
+
import { getServerConfig as getServerConfig2 } from "@uniformdev/canvas-next-rsc-shared";
|
|
602
515
|
import { ProjectMapNodeDeleteDefinition } from "@uniformdev/webhooks";
|
|
603
516
|
var handleProjectMapNodeDelete = async (body) => {
|
|
604
517
|
var _a;
|
|
@@ -608,7 +521,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
608
521
|
}
|
|
609
522
|
const tags = [];
|
|
610
523
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
611
|
-
const config =
|
|
524
|
+
const config = getServerConfig2();
|
|
612
525
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
613
526
|
await processEdgeConfigChange({
|
|
614
527
|
source_url: parsed.data.path
|
|
@@ -620,7 +533,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
620
533
|
};
|
|
621
534
|
|
|
622
535
|
// src/handler/messages/handleProjectMapNodeInsert.ts
|
|
623
|
-
import { getServerConfig as
|
|
536
|
+
import { getServerConfig as getServerConfig3 } from "@uniformdev/canvas-next-rsc-shared";
|
|
624
537
|
import { ProjectMapNodeInsertDefinition } from "@uniformdev/webhooks";
|
|
625
538
|
var handleProjectMapNodeInsert = async (body) => {
|
|
626
539
|
var _a;
|
|
@@ -630,7 +543,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
630
543
|
}
|
|
631
544
|
const tags = [];
|
|
632
545
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
633
|
-
const config =
|
|
546
|
+
const config = getServerConfig3();
|
|
634
547
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
635
548
|
await processEdgeConfigChange({
|
|
636
549
|
source_url: parsed.data.path
|
|
@@ -642,7 +555,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
642
555
|
};
|
|
643
556
|
|
|
644
557
|
// src/handler/messages/handleProjectMapNodeUpdate.ts
|
|
645
|
-
import { getServerConfig as
|
|
558
|
+
import { getServerConfig as getServerConfig4 } from "@uniformdev/canvas-next-rsc-shared";
|
|
646
559
|
import { ProjectMapNodeUpdateDefinition } from "@uniformdev/webhooks";
|
|
647
560
|
var handleProjectMapNodeUpdate = async (body) => {
|
|
648
561
|
var _a;
|
|
@@ -653,7 +566,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
653
566
|
const tags = [];
|
|
654
567
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
655
568
|
tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
|
|
656
|
-
const config =
|
|
569
|
+
const config = getServerConfig4();
|
|
657
570
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
658
571
|
await processEdgeConfigChange({
|
|
659
572
|
source_url: parsed.data.path
|
|
@@ -665,7 +578,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
665
578
|
};
|
|
666
579
|
|
|
667
580
|
// src/handler/messages/handleRedirectDelete.ts
|
|
668
|
-
import { getServerConfig as
|
|
581
|
+
import { getServerConfig as getServerConfig5 } from "@uniformdev/canvas-next-rsc-shared";
|
|
669
582
|
import { RedirectDeleteDefinition } from "@uniformdev/webhooks";
|
|
670
583
|
var handleRedirectDelete = async (body) => {
|
|
671
584
|
var _a;
|
|
@@ -673,7 +586,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
673
586
|
if (!parsed.success) {
|
|
674
587
|
return void 0;
|
|
675
588
|
}
|
|
676
|
-
const config =
|
|
589
|
+
const config = getServerConfig5();
|
|
677
590
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
678
591
|
await processEdgeConfigChange(parsed.data);
|
|
679
592
|
}
|
|
@@ -681,7 +594,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
681
594
|
};
|
|
682
595
|
|
|
683
596
|
// src/handler/messages/handleRedirectInsert.ts
|
|
684
|
-
import { getServerConfig as
|
|
597
|
+
import { getServerConfig as getServerConfig6 } from "@uniformdev/canvas-next-rsc-shared";
|
|
685
598
|
import { RedirectInsertDefinition } from "@uniformdev/webhooks";
|
|
686
599
|
var handleRedirectInsert = async (body) => {
|
|
687
600
|
var _a;
|
|
@@ -689,7 +602,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
689
602
|
if (!parsed.success) {
|
|
690
603
|
return void 0;
|
|
691
604
|
}
|
|
692
|
-
const config =
|
|
605
|
+
const config = getServerConfig6();
|
|
693
606
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
694
607
|
await processEdgeConfigChange(parsed.data);
|
|
695
608
|
}
|
|
@@ -697,7 +610,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
697
610
|
};
|
|
698
611
|
|
|
699
612
|
// src/handler/messages/handleRedirectUpdate.ts
|
|
700
|
-
import { getServerConfig as
|
|
613
|
+
import { getServerConfig as getServerConfig7 } from "@uniformdev/canvas-next-rsc-shared";
|
|
701
614
|
import { RedirectUpdateDefinition } from "@uniformdev/webhooks";
|
|
702
615
|
var handleRedirectUpdate = async (body) => {
|
|
703
616
|
var _a;
|
|
@@ -705,7 +618,7 @@ var handleRedirectUpdate = async (body) => {
|
|
|
705
618
|
if (!parsed.success) {
|
|
706
619
|
return void 0;
|
|
707
620
|
}
|
|
708
|
-
const config =
|
|
621
|
+
const config = getServerConfig7();
|
|
709
622
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
710
623
|
await processEdgeConfigChange(parsed.data);
|
|
711
624
|
}
|
|
@@ -717,7 +630,7 @@ var createPreviewPOSTRouteHandler = () => {
|
|
|
717
630
|
return async (request) => {
|
|
718
631
|
let previewSecretPassed = false;
|
|
719
632
|
if (process.env.UNIFORM_PREVIEW_SECRET) {
|
|
720
|
-
const secretValue = request.nextUrl.searchParams.get(
|
|
633
|
+
const secretValue = request.nextUrl.searchParams.get(SECRET_QUERY_STRING_PARAM2);
|
|
721
634
|
if (secretValue !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
722
635
|
console.warn(
|
|
723
636
|
"The preview secret passed in the query string does not match the UNIFORM_PREVIEW_SECRET env var."
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.125.2-alpha.3+6bb657551a",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -61,15 +61,15 @@
|
|
|
61
61
|
"react-dom": "18.2.0"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@uniformdev/canvas": "19.
|
|
65
|
-
"@uniformdev/canvas-next-rsc-client": "^19.
|
|
66
|
-
"@uniformdev/canvas-next-rsc-shared": "^19.
|
|
67
|
-
"@uniformdev/canvas-react": "19.
|
|
68
|
-
"@uniformdev/context": "19.
|
|
69
|
-
"@uniformdev/project-map": "19.
|
|
70
|
-
"@uniformdev/redirect": "19.
|
|
71
|
-
"@uniformdev/richtext": "19.
|
|
72
|
-
"@uniformdev/webhooks": "19.
|
|
64
|
+
"@uniformdev/canvas": "19.125.2-alpha.3+6bb657551a",
|
|
65
|
+
"@uniformdev/canvas-next-rsc-client": "^19.125.2-alpha.3+6bb657551a",
|
|
66
|
+
"@uniformdev/canvas-next-rsc-shared": "^19.125.2-alpha.3+6bb657551a",
|
|
67
|
+
"@uniformdev/canvas-react": "19.125.2-alpha.3+6bb657551a",
|
|
68
|
+
"@uniformdev/context": "19.125.2-alpha.3+6bb657551a",
|
|
69
|
+
"@uniformdev/project-map": "19.125.2-alpha.3+6bb657551a",
|
|
70
|
+
"@uniformdev/redirect": "19.125.2-alpha.3+6bb657551a",
|
|
71
|
+
"@uniformdev/richtext": "19.125.2-alpha.3+6bb657551a",
|
|
72
|
+
"@uniformdev/webhooks": "19.125.2-alpha.3+6bb657551a",
|
|
73
73
|
"@vercel/edge-config": "^0.4.0",
|
|
74
74
|
"encoding": "^0.1.13",
|
|
75
75
|
"server-only": "^0.0.1",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "6bb657551ac6e37a7990deace389c581b94176fc"
|
|
90
90
|
}
|