@uniformdev/canvas-next-rsc 19.123.1-alpha.9 → 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 +8 -10
- package/dist/handler.d.ts +8 -10
- package/dist/handler.js +167 -256
- package/dist/handler.mjs +169 -261
- package/package.json +11 -11
package/dist/handler.d.mts
CHANGED
|
@@ -2,21 +2,19 @@ import { NextRequest } from 'next/server';
|
|
|
2
2
|
|
|
3
3
|
type ResolveFullPath = (options: {
|
|
4
4
|
/** The ID of the composition */
|
|
5
|
-
id?: string
|
|
5
|
+
id?: string;
|
|
6
6
|
/** The slug of the composition */
|
|
7
|
-
slug?: string
|
|
7
|
+
slug?: string;
|
|
8
8
|
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
-
path?: string
|
|
10
|
-
|
|
9
|
+
path?: string;
|
|
10
|
+
/** The preview locale selected in Visual Canvas, available only if Localization is set up */
|
|
11
|
+
locale?: string;
|
|
12
|
+
}) => string | undefined;
|
|
11
13
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
12
|
-
playgroundPath?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Should return the full path to redirect to. Will respond with `400` error if `undefined` is returned.
|
|
15
|
-
* defaults to a function that returns the `path` if truthy, otherwise returns `slug`.
|
|
16
|
-
*/
|
|
17
14
|
resolveFullPath?: ResolveFullPath;
|
|
15
|
+
playgroundPath?: string;
|
|
18
16
|
};
|
|
19
|
-
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
17
|
+
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response | undefined>;
|
|
20
18
|
|
|
21
19
|
declare const createPreviewOPTIONSRouteHandler: () => () => Promise<Response>;
|
|
22
20
|
|
package/dist/handler.d.ts
CHANGED
|
@@ -2,21 +2,19 @@ import { NextRequest } from 'next/server';
|
|
|
2
2
|
|
|
3
3
|
type ResolveFullPath = (options: {
|
|
4
4
|
/** The ID of the composition */
|
|
5
|
-
id?: string
|
|
5
|
+
id?: string;
|
|
6
6
|
/** The slug of the composition */
|
|
7
|
-
slug?: string
|
|
7
|
+
slug?: string;
|
|
8
8
|
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
-
path?: string
|
|
10
|
-
|
|
9
|
+
path?: string;
|
|
10
|
+
/** The preview locale selected in Visual Canvas, available only if Localization is set up */
|
|
11
|
+
locale?: string;
|
|
12
|
+
}) => string | undefined;
|
|
11
13
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
12
|
-
playgroundPath?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Should return the full path to redirect to. Will respond with `400` error if `undefined` is returned.
|
|
15
|
-
* defaults to a function that returns the `path` if truthy, otherwise returns `slug`.
|
|
16
|
-
*/
|
|
17
14
|
resolveFullPath?: ResolveFullPath;
|
|
15
|
+
playgroundPath?: string;
|
|
18
16
|
};
|
|
19
|
-
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
17
|
+
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response | undefined>;
|
|
20
18
|
|
|
21
19
|
declare const createPreviewOPTIONSRouteHandler: () => () => Promise<Response>;
|
|
22
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,178 +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 resolveFullPathDefault = ({ path }) => {
|
|
301
|
-
return path || "";
|
|
302
|
-
};
|
|
303
|
-
var createPreviewGETRouteHandler = (options) => {
|
|
304
|
-
return async (request) => {
|
|
305
|
-
const { playgroundPath, resolveFullPath = resolveFullPathDefault } = options || {};
|
|
306
|
-
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
307
|
-
if (isConfigCheck) {
|
|
308
|
-
return Response.json(
|
|
309
|
-
{
|
|
310
|
-
hasPlayground: Boolean(playgroundPath),
|
|
311
|
-
isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
|
|
312
|
-
},
|
|
313
|
-
{
|
|
314
|
-
headers: {
|
|
315
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
321
|
-
return new Response(null, { status: 204 });
|
|
322
|
-
}
|
|
323
|
-
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
324
|
-
return new Response("No preview secret is configured", { status: 401 });
|
|
325
|
-
}
|
|
326
|
-
const { searchParams } = new URL(request.url);
|
|
327
|
-
const secret = searchParams.get("secret");
|
|
328
|
-
const path = searchParams.get("path");
|
|
329
|
-
const isPlayground = searchParams.get(import_canvas5.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
330
|
-
const id = searchParams.get("id");
|
|
331
|
-
const resolbedPath = resolveFullPath({ id, path });
|
|
332
|
-
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
333
|
-
return new Response("Invalid preview secret", { status: 401 });
|
|
334
|
-
}
|
|
335
|
-
if (!isPlayground) {
|
|
336
|
-
if (!resolbedPath) {
|
|
337
|
-
return new Response("Path not provided", { status: 401 });
|
|
338
|
-
}
|
|
339
|
-
const resolveResult = await retrieveRouteByPath({
|
|
340
|
-
path: resolbedPath,
|
|
341
|
-
state: import_canvas5.CANVAS_DRAFT_STATE,
|
|
342
|
-
searchParams: {
|
|
343
|
-
// about to be in draft mode so pretend for now.
|
|
344
|
-
[import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]: "true"
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
(0, import_headers2.draftMode)().enable();
|
|
348
|
-
if (resolveResult.type === "redirect") {
|
|
349
|
-
const href = resolveRedirectHref(resolveResult, resolbedPath);
|
|
350
|
-
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
351
|
-
(0, import_navigation.redirect)(`${href}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
352
|
-
} else {
|
|
353
|
-
(0, import_navigation.redirect)(href);
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (resolveResult.type === "notFound") {
|
|
357
|
-
return new Response("Invalid path", { status: 401 });
|
|
358
|
-
}
|
|
359
|
-
(0, import_navigation.redirect)(`${resolbedPath}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
360
|
-
} else {
|
|
361
|
-
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
362
|
-
return new Response("No playground path is configured", { status: 401 });
|
|
363
|
-
}
|
|
364
|
-
(0, import_headers2.draftMode)().enable();
|
|
365
|
-
(0, import_navigation.redirect)(`${playgroundPath}?id=${id}&${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
371
|
-
var createPreviewOPTIONSRouteHandler = () => {
|
|
372
|
-
return async () => {
|
|
373
|
-
return new Response(null, {
|
|
374
|
-
headers: {
|
|
375
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
376
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
377
|
-
"Access-Control-Allow-Headers": "*"
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
};
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
384
|
-
var import_canvas7 = require("@uniformdev/canvas");
|
|
385
|
-
var import_cache = require("next/cache");
|
|
386
|
-
|
|
387
|
-
// src/handler/helpers.ts
|
|
388
|
-
var import_canvas6 = require("@uniformdev/canvas");
|
|
389
|
-
var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
|
|
390
|
-
var import_edge_config = require("@vercel/edge-config");
|
|
391
|
-
var import_svix = require("svix");
|
|
392
|
-
|
|
393
|
-
// src/clients/projectMapClient.ts
|
|
394
|
-
var import_project_map = require("@uniformdev/project-map");
|
|
395
|
-
var getProjectMapClient = (options) => {
|
|
396
|
-
const manifestClient = new import_project_map.ProjectMapClient({
|
|
397
|
-
apiHost: env.getApiHost(),
|
|
398
|
-
apiKey: env.getApiKey(),
|
|
399
|
-
projectId: env.getProjectId(),
|
|
400
|
-
fetch: (req, init) => {
|
|
401
|
-
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
402
|
-
return fetch(req, {
|
|
403
|
-
...init,
|
|
404
|
-
headers: {
|
|
405
|
-
...init == null ? void 0 : init.headers,
|
|
406
|
-
"x-bypass-cache": "true"
|
|
407
|
-
},
|
|
408
|
-
cache,
|
|
409
|
-
next: {
|
|
410
|
-
revalidate
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
return manifestClient;
|
|
416
|
-
};
|
|
417
328
|
|
|
418
329
|
// src/handler/helpers.ts
|
|
419
330
|
var isSvixMessage = async (request) => {
|
|
@@ -485,7 +396,7 @@ var getComposition = async ({ compositionId }) => {
|
|
|
485
396
|
});
|
|
486
397
|
return composition;
|
|
487
398
|
} catch (err) {
|
|
488
|
-
if (err instanceof
|
|
399
|
+
if (err instanceof import_canvas4.ApiClientError && err.statusCode === 404) {
|
|
489
400
|
return null;
|
|
490
401
|
}
|
|
491
402
|
throw err;
|
|
@@ -533,7 +444,7 @@ var processEdgeConfigChange = async ({ source_url }) => {
|
|
|
533
444
|
console.warn("UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert");
|
|
534
445
|
return;
|
|
535
446
|
}
|
|
536
|
-
const config = (0,
|
|
447
|
+
const config = (0, import_canvas_next_rsc_shared.getServerConfig)();
|
|
537
448
|
const routeClient = getRouteClient({
|
|
538
449
|
cache: {
|
|
539
450
|
type: "no-cache"
|
|
@@ -623,7 +534,7 @@ var handleManifestPublished = async (body) => {
|
|
|
623
534
|
};
|
|
624
535
|
|
|
625
536
|
// src/handler/messages/handleProjectMapNodeDelete.ts
|
|
626
|
-
var
|
|
537
|
+
var import_canvas_next_rsc_shared2 = require("@uniformdev/canvas-next-rsc-shared");
|
|
627
538
|
var import_webhooks5 = require("@uniformdev/webhooks");
|
|
628
539
|
var handleProjectMapNodeDelete = async (body) => {
|
|
629
540
|
var _a;
|
|
@@ -633,7 +544,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
633
544
|
}
|
|
634
545
|
const tags = [];
|
|
635
546
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
636
|
-
const config = (0,
|
|
547
|
+
const config = (0, import_canvas_next_rsc_shared2.getServerConfig)();
|
|
637
548
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
638
549
|
await processEdgeConfigChange({
|
|
639
550
|
source_url: parsed.data.path
|
|
@@ -645,7 +556,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
645
556
|
};
|
|
646
557
|
|
|
647
558
|
// src/handler/messages/handleProjectMapNodeInsert.ts
|
|
648
|
-
var
|
|
559
|
+
var import_canvas_next_rsc_shared3 = require("@uniformdev/canvas-next-rsc-shared");
|
|
649
560
|
var import_webhooks6 = require("@uniformdev/webhooks");
|
|
650
561
|
var handleProjectMapNodeInsert = async (body) => {
|
|
651
562
|
var _a;
|
|
@@ -655,7 +566,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
655
566
|
}
|
|
656
567
|
const tags = [];
|
|
657
568
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
658
|
-
const config = (0,
|
|
569
|
+
const config = (0, import_canvas_next_rsc_shared3.getServerConfig)();
|
|
659
570
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
660
571
|
await processEdgeConfigChange({
|
|
661
572
|
source_url: parsed.data.path
|
|
@@ -667,7 +578,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
667
578
|
};
|
|
668
579
|
|
|
669
580
|
// src/handler/messages/handleProjectMapNodeUpdate.ts
|
|
670
|
-
var
|
|
581
|
+
var import_canvas_next_rsc_shared4 = require("@uniformdev/canvas-next-rsc-shared");
|
|
671
582
|
var import_webhooks7 = require("@uniformdev/webhooks");
|
|
672
583
|
var handleProjectMapNodeUpdate = async (body) => {
|
|
673
584
|
var _a;
|
|
@@ -678,7 +589,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
678
589
|
const tags = [];
|
|
679
590
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
680
591
|
tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
|
|
681
|
-
const config = (0,
|
|
592
|
+
const config = (0, import_canvas_next_rsc_shared4.getServerConfig)();
|
|
682
593
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
683
594
|
await processEdgeConfigChange({
|
|
684
595
|
source_url: parsed.data.path
|
|
@@ -690,7 +601,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
690
601
|
};
|
|
691
602
|
|
|
692
603
|
// src/handler/messages/handleRedirectDelete.ts
|
|
693
|
-
var
|
|
604
|
+
var import_canvas_next_rsc_shared5 = require("@uniformdev/canvas-next-rsc-shared");
|
|
694
605
|
var import_webhooks8 = require("@uniformdev/webhooks");
|
|
695
606
|
var handleRedirectDelete = async (body) => {
|
|
696
607
|
var _a;
|
|
@@ -698,7 +609,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
698
609
|
if (!parsed.success) {
|
|
699
610
|
return void 0;
|
|
700
611
|
}
|
|
701
|
-
const config = (0,
|
|
612
|
+
const config = (0, import_canvas_next_rsc_shared5.getServerConfig)();
|
|
702
613
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
703
614
|
await processEdgeConfigChange(parsed.data);
|
|
704
615
|
}
|
|
@@ -706,7 +617,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
706
617
|
};
|
|
707
618
|
|
|
708
619
|
// src/handler/messages/handleRedirectInsert.ts
|
|
709
|
-
var
|
|
620
|
+
var import_canvas_next_rsc_shared6 = require("@uniformdev/canvas-next-rsc-shared");
|
|
710
621
|
var import_webhooks9 = require("@uniformdev/webhooks");
|
|
711
622
|
var handleRedirectInsert = async (body) => {
|
|
712
623
|
var _a;
|
|
@@ -714,7 +625,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
714
625
|
if (!parsed.success) {
|
|
715
626
|
return void 0;
|
|
716
627
|
}
|
|
717
|
-
const config = (0,
|
|
628
|
+
const config = (0, import_canvas_next_rsc_shared6.getServerConfig)();
|
|
718
629
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
719
630
|
await processEdgeConfigChange(parsed.data);
|
|
720
631
|
}
|
|
@@ -722,7 +633,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
722
633
|
};
|
|
723
634
|
|
|
724
635
|
// src/handler/messages/handleRedirectUpdate.ts
|
|
725
|
-
var
|
|
636
|
+
var import_canvas_next_rsc_shared7 = require("@uniformdev/canvas-next-rsc-shared");
|
|
726
637
|
var import_webhooks10 = require("@uniformdev/webhooks");
|
|
727
638
|
var handleRedirectUpdate = async (body) => {
|
|
728
639
|
var _a;
|
|
@@ -730,7 +641,7 @@ var handleRedirectUpdate = async (body) => {
|
|
|
730
641
|
if (!parsed.success) {
|
|
731
642
|
return void 0;
|
|
732
643
|
}
|
|
733
|
-
const config = (0,
|
|
644
|
+
const config = (0, import_canvas_next_rsc_shared7.getServerConfig)();
|
|
734
645
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
735
646
|
await processEdgeConfigChange(parsed.data);
|
|
736
647
|
}
|
|
@@ -742,7 +653,7 @@ var createPreviewPOSTRouteHandler = () => {
|
|
|
742
653
|
return async (request) => {
|
|
743
654
|
let previewSecretPassed = false;
|
|
744
655
|
if (process.env.UNIFORM_PREVIEW_SECRET) {
|
|
745
|
-
const secretValue = request.nextUrl.searchParams.get(
|
|
656
|
+
const secretValue = request.nextUrl.searchParams.get(import_canvas5.SECRET_QUERY_STRING_PARAM);
|
|
746
657
|
if (secretValue !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
747
658
|
console.warn(
|
|
748
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,178 +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 resolveFullPathDefault = ({ path }) => {
|
|
281
|
-
return path || "";
|
|
282
|
-
};
|
|
283
|
-
var createPreviewGETRouteHandler = (options) => {
|
|
284
|
-
return async (request) => {
|
|
285
|
-
const { playgroundPath, resolveFullPath = resolveFullPathDefault } = options || {};
|
|
286
|
-
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
287
|
-
if (isConfigCheck) {
|
|
288
|
-
return Response.json(
|
|
289
|
-
{
|
|
290
|
-
hasPlayground: Boolean(playgroundPath),
|
|
291
|
-
isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
headers: {
|
|
295
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app"
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
if (request.headers.get("sec-fetch-mode") === "no-cors") {
|
|
301
|
-
return new Response(null, { status: 204 });
|
|
302
|
-
}
|
|
303
|
-
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
304
|
-
return new Response("No preview secret is configured", { status: 401 });
|
|
305
|
-
}
|
|
306
|
-
const { searchParams } = new URL(request.url);
|
|
307
|
-
const secret = searchParams.get("secret");
|
|
308
|
-
const path = searchParams.get("path");
|
|
309
|
-
const isPlayground = searchParams.get(IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
310
|
-
const id = searchParams.get("id");
|
|
311
|
-
const resolbedPath = resolveFullPath({ id, path });
|
|
312
|
-
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
313
|
-
return new Response("Invalid preview secret", { status: 401 });
|
|
314
|
-
}
|
|
315
|
-
if (!isPlayground) {
|
|
316
|
-
if (!resolbedPath) {
|
|
317
|
-
return new Response("Path not provided", { status: 401 });
|
|
318
|
-
}
|
|
319
|
-
const resolveResult = await retrieveRouteByPath({
|
|
320
|
-
path: resolbedPath,
|
|
321
|
-
state: CANVAS_DRAFT_STATE2,
|
|
322
|
-
searchParams: {
|
|
323
|
-
// about to be in draft mode so pretend for now.
|
|
324
|
-
[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2]: "true"
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
draftMode2().enable();
|
|
328
|
-
if (resolveResult.type === "redirect") {
|
|
329
|
-
const href = resolveRedirectHref(resolveResult, resolbedPath);
|
|
330
|
-
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
331
|
-
redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
332
|
-
} else {
|
|
333
|
-
redirect(href);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
if (resolveResult.type === "notFound") {
|
|
337
|
-
return new Response("Invalid path", { status: 401 });
|
|
338
|
-
}
|
|
339
|
-
redirect(`${resolbedPath}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
340
|
-
} else {
|
|
341
|
-
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
342
|
-
return new Response("No playground path is configured", { status: 401 });
|
|
343
|
-
}
|
|
344
|
-
draftMode2().enable();
|
|
345
|
-
redirect(`${playgroundPath}?id=${id}&${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// src/handler/createPreviewOPTIONSRouteHandler.ts
|
|
351
|
-
var createPreviewOPTIONSRouteHandler = () => {
|
|
352
|
-
return async () => {
|
|
353
|
-
return new Response(null, {
|
|
354
|
-
headers: {
|
|
355
|
-
"Access-Control-Allow-Origin": process.env.UNIFORM_CLI_BASE_URL || "https://uniform.app",
|
|
356
|
-
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
|
|
357
|
-
"Access-Control-Allow-Headers": "*"
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
};
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// src/handler/createPreviewPOSTRouteHandler.ts
|
|
364
|
-
import { SECRET_QUERY_STRING_PARAM } from "@uniformdev/canvas";
|
|
365
|
-
import { revalidateTag } from "next/cache";
|
|
366
|
-
|
|
367
|
-
// src/handler/helpers.ts
|
|
368
|
-
import { ApiClientError } from "@uniformdev/canvas";
|
|
369
|
-
import { getServerConfig as getServerConfig3 } from "@uniformdev/canvas-next-rsc-shared";
|
|
370
|
-
import { parseConnectionString } from "@vercel/edge-config";
|
|
371
|
-
import { Webhook } from "svix";
|
|
372
|
-
|
|
373
|
-
// src/clients/projectMapClient.ts
|
|
374
|
-
import { ProjectMapClient } from "@uniformdev/project-map";
|
|
375
|
-
var getProjectMapClient = (options) => {
|
|
376
|
-
const manifestClient = new ProjectMapClient({
|
|
377
|
-
apiHost: env.getApiHost(),
|
|
378
|
-
apiKey: env.getApiKey(),
|
|
379
|
-
projectId: env.getProjectId(),
|
|
380
|
-
fetch: (req, init) => {
|
|
381
|
-
const { cache, revalidate } = determineFetchCacheOptions(options.cache);
|
|
382
|
-
return fetch(req, {
|
|
383
|
-
...init,
|
|
384
|
-
headers: {
|
|
385
|
-
...init == null ? void 0 : init.headers,
|
|
386
|
-
"x-bypass-cache": "true"
|
|
387
|
-
},
|
|
388
|
-
cache,
|
|
389
|
-
next: {
|
|
390
|
-
revalidate
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
return manifestClient;
|
|
396
|
-
};
|
|
397
305
|
|
|
398
306
|
// src/handler/helpers.ts
|
|
399
307
|
var isSvixMessage = async (request) => {
|
|
@@ -513,7 +421,7 @@ var processEdgeConfigChange = async ({ source_url }) => {
|
|
|
513
421
|
console.warn("UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert");
|
|
514
422
|
return;
|
|
515
423
|
}
|
|
516
|
-
const config =
|
|
424
|
+
const config = getServerConfig();
|
|
517
425
|
const routeClient = getRouteClient({
|
|
518
426
|
cache: {
|
|
519
427
|
type: "no-cache"
|
|
@@ -603,7 +511,7 @@ var handleManifestPublished = async (body) => {
|
|
|
603
511
|
};
|
|
604
512
|
|
|
605
513
|
// src/handler/messages/handleProjectMapNodeDelete.ts
|
|
606
|
-
import { getServerConfig as
|
|
514
|
+
import { getServerConfig as getServerConfig2 } from "@uniformdev/canvas-next-rsc-shared";
|
|
607
515
|
import { ProjectMapNodeDeleteDefinition } from "@uniformdev/webhooks";
|
|
608
516
|
var handleProjectMapNodeDelete = async (body) => {
|
|
609
517
|
var _a;
|
|
@@ -613,7 +521,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
613
521
|
}
|
|
614
522
|
const tags = [];
|
|
615
523
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
616
|
-
const config =
|
|
524
|
+
const config = getServerConfig2();
|
|
617
525
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
618
526
|
await processEdgeConfigChange({
|
|
619
527
|
source_url: parsed.data.path
|
|
@@ -625,7 +533,7 @@ var handleProjectMapNodeDelete = async (body) => {
|
|
|
625
533
|
};
|
|
626
534
|
|
|
627
535
|
// src/handler/messages/handleProjectMapNodeInsert.ts
|
|
628
|
-
import { getServerConfig as
|
|
536
|
+
import { getServerConfig as getServerConfig3 } from "@uniformdev/canvas-next-rsc-shared";
|
|
629
537
|
import { ProjectMapNodeInsertDefinition } from "@uniformdev/webhooks";
|
|
630
538
|
var handleProjectMapNodeInsert = async (body) => {
|
|
631
539
|
var _a;
|
|
@@ -635,7 +543,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
635
543
|
}
|
|
636
544
|
const tags = [];
|
|
637
545
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
638
|
-
const config =
|
|
546
|
+
const config = getServerConfig3();
|
|
639
547
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
640
548
|
await processEdgeConfigChange({
|
|
641
549
|
source_url: parsed.data.path
|
|
@@ -647,7 +555,7 @@ var handleProjectMapNodeInsert = async (body) => {
|
|
|
647
555
|
};
|
|
648
556
|
|
|
649
557
|
// src/handler/messages/handleProjectMapNodeUpdate.ts
|
|
650
|
-
import { getServerConfig as
|
|
558
|
+
import { getServerConfig as getServerConfig4 } from "@uniformdev/canvas-next-rsc-shared";
|
|
651
559
|
import { ProjectMapNodeUpdateDefinition } from "@uniformdev/webhooks";
|
|
652
560
|
var handleProjectMapNodeUpdate = async (body) => {
|
|
653
561
|
var _a;
|
|
@@ -658,7 +566,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
658
566
|
const tags = [];
|
|
659
567
|
tags.push(...buildProjectMapNodePaths(parsed.data.path));
|
|
660
568
|
tags.push(...buildProjectMapNodePaths(parsed.data.previous_path));
|
|
661
|
-
const config =
|
|
569
|
+
const config = getServerConfig4();
|
|
662
570
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeCompositions) {
|
|
663
571
|
await processEdgeConfigChange({
|
|
664
572
|
source_url: parsed.data.path
|
|
@@ -670,7 +578,7 @@ var handleProjectMapNodeUpdate = async (body) => {
|
|
|
670
578
|
};
|
|
671
579
|
|
|
672
580
|
// src/handler/messages/handleRedirectDelete.ts
|
|
673
|
-
import { getServerConfig as
|
|
581
|
+
import { getServerConfig as getServerConfig5 } from "@uniformdev/canvas-next-rsc-shared";
|
|
674
582
|
import { RedirectDeleteDefinition } from "@uniformdev/webhooks";
|
|
675
583
|
var handleRedirectDelete = async (body) => {
|
|
676
584
|
var _a;
|
|
@@ -678,7 +586,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
678
586
|
if (!parsed.success) {
|
|
679
587
|
return void 0;
|
|
680
588
|
}
|
|
681
|
-
const config =
|
|
589
|
+
const config = getServerConfig5();
|
|
682
590
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
683
591
|
await processEdgeConfigChange(parsed.data);
|
|
684
592
|
}
|
|
@@ -686,7 +594,7 @@ var handleRedirectDelete = async (body) => {
|
|
|
686
594
|
};
|
|
687
595
|
|
|
688
596
|
// src/handler/messages/handleRedirectInsert.ts
|
|
689
|
-
import { getServerConfig as
|
|
597
|
+
import { getServerConfig as getServerConfig6 } from "@uniformdev/canvas-next-rsc-shared";
|
|
690
598
|
import { RedirectInsertDefinition } from "@uniformdev/webhooks";
|
|
691
599
|
var handleRedirectInsert = async (body) => {
|
|
692
600
|
var _a;
|
|
@@ -694,7 +602,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
694
602
|
if (!parsed.success) {
|
|
695
603
|
return void 0;
|
|
696
604
|
}
|
|
697
|
-
const config =
|
|
605
|
+
const config = getServerConfig6();
|
|
698
606
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
699
607
|
await processEdgeConfigChange(parsed.data);
|
|
700
608
|
}
|
|
@@ -702,7 +610,7 @@ var handleRedirectInsert = async (body) => {
|
|
|
702
610
|
};
|
|
703
611
|
|
|
704
612
|
// src/handler/messages/handleRedirectUpdate.ts
|
|
705
|
-
import { getServerConfig as
|
|
613
|
+
import { getServerConfig as getServerConfig7 } from "@uniformdev/canvas-next-rsc-shared";
|
|
706
614
|
import { RedirectUpdateDefinition } from "@uniformdev/webhooks";
|
|
707
615
|
var handleRedirectUpdate = async (body) => {
|
|
708
616
|
var _a;
|
|
@@ -710,7 +618,7 @@ var handleRedirectUpdate = async (body) => {
|
|
|
710
618
|
if (!parsed.success) {
|
|
711
619
|
return void 0;
|
|
712
620
|
}
|
|
713
|
-
const config =
|
|
621
|
+
const config = getServerConfig7();
|
|
714
622
|
if ((_a = config.experimental) == null ? void 0 : _a.edgeRedirects) {
|
|
715
623
|
await processEdgeConfigChange(parsed.data);
|
|
716
624
|
}
|
|
@@ -722,7 +630,7 @@ var createPreviewPOSTRouteHandler = () => {
|
|
|
722
630
|
return async (request) => {
|
|
723
631
|
let previewSecretPassed = false;
|
|
724
632
|
if (process.env.UNIFORM_PREVIEW_SECRET) {
|
|
725
|
-
const secretValue = request.nextUrl.searchParams.get(
|
|
633
|
+
const secretValue = request.nextUrl.searchParams.get(SECRET_QUERY_STRING_PARAM2);
|
|
726
634
|
if (secretValue !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
727
635
|
console.warn(
|
|
728
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
|
}
|