@uniformdev/canvas-next-rsc 19.121.0 → 19.123.1-alpha.9
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 +13 -0
- package/dist/handler.d.ts +13 -0
- package/dist/handler.js +12 -7
- package/dist/handler.mjs +12 -7
- package/package.json +11 -11
package/dist/handler.d.mts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
|
|
3
|
+
type ResolveFullPath = (options: {
|
|
4
|
+
/** The ID of the composition */
|
|
5
|
+
id?: string | null;
|
|
6
|
+
/** The slug of the composition */
|
|
7
|
+
slug?: string | null;
|
|
8
|
+
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
+
path?: string | null;
|
|
10
|
+
}) => string;
|
|
3
11
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
4
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
|
+
resolveFullPath?: ResolveFullPath;
|
|
5
18
|
};
|
|
6
19
|
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
7
20
|
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import { NextRequest } from 'next/server';
|
|
2
2
|
|
|
3
|
+
type ResolveFullPath = (options: {
|
|
4
|
+
/** The ID of the composition */
|
|
5
|
+
id?: string | null;
|
|
6
|
+
/** The slug of the composition */
|
|
7
|
+
slug?: string | null;
|
|
8
|
+
/** The path of the project map node attached to the composition, if there is one */
|
|
9
|
+
path?: string | null;
|
|
10
|
+
}) => string;
|
|
3
11
|
type CreatePreviewGETRouteHandlerOptions = {
|
|
4
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
|
+
resolveFullPath?: ResolveFullPath;
|
|
5
18
|
};
|
|
6
19
|
declare const createPreviewGETRouteHandler: (options?: CreatePreviewGETRouteHandlerOptions) => (request: NextRequest) => Promise<Response>;
|
|
7
20
|
|
package/dist/handler.js
CHANGED
|
@@ -297,14 +297,18 @@ var getQueryParam = (req, paramName) => {
|
|
|
297
297
|
}
|
|
298
298
|
return Array.isArray(value) ? value[0] : value;
|
|
299
299
|
};
|
|
300
|
+
var resolveFullPathDefault = ({ path }) => {
|
|
301
|
+
return path || "";
|
|
302
|
+
};
|
|
300
303
|
var createPreviewGETRouteHandler = (options) => {
|
|
301
304
|
return async (request) => {
|
|
305
|
+
const { playgroundPath, resolveFullPath = resolveFullPathDefault } = options || {};
|
|
302
306
|
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
303
307
|
if (isConfigCheck) {
|
|
304
308
|
return Response.json(
|
|
305
309
|
{
|
|
306
|
-
hasPlayground: Boolean(
|
|
307
|
-
isUsingCustomFullPathResolver:
|
|
310
|
+
hasPlayground: Boolean(playgroundPath),
|
|
311
|
+
isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
|
|
308
312
|
},
|
|
309
313
|
{
|
|
310
314
|
headers: {
|
|
@@ -324,15 +328,16 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
324
328
|
const path = searchParams.get("path");
|
|
325
329
|
const isPlayground = searchParams.get(import_canvas5.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
326
330
|
const id = searchParams.get("id");
|
|
331
|
+
const resolbedPath = resolveFullPath({ id, path });
|
|
327
332
|
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
328
333
|
return new Response("Invalid preview secret", { status: 401 });
|
|
329
334
|
}
|
|
330
335
|
if (!isPlayground) {
|
|
331
|
-
if (!
|
|
336
|
+
if (!resolbedPath) {
|
|
332
337
|
return new Response("Path not provided", { status: 401 });
|
|
333
338
|
}
|
|
334
339
|
const resolveResult = await retrieveRouteByPath({
|
|
335
|
-
path,
|
|
340
|
+
path: resolbedPath,
|
|
336
341
|
state: import_canvas5.CANVAS_DRAFT_STATE,
|
|
337
342
|
searchParams: {
|
|
338
343
|
// about to be in draft mode so pretend for now.
|
|
@@ -341,7 +346,7 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
341
346
|
});
|
|
342
347
|
(0, import_headers2.draftMode)().enable();
|
|
343
348
|
if (resolveResult.type === "redirect") {
|
|
344
|
-
const href = resolveRedirectHref(resolveResult,
|
|
349
|
+
const href = resolveRedirectHref(resolveResult, resolbedPath);
|
|
345
350
|
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
346
351
|
(0, import_navigation.redirect)(`${href}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
347
352
|
} else {
|
|
@@ -351,13 +356,13 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
351
356
|
if (resolveResult.type === "notFound") {
|
|
352
357
|
return new Response("Invalid path", { status: 401 });
|
|
353
358
|
}
|
|
354
|
-
(0, import_navigation.redirect)(`${
|
|
359
|
+
(0, import_navigation.redirect)(`${resolbedPath}?${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
355
360
|
} else {
|
|
356
361
|
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
357
362
|
return new Response("No playground path is configured", { status: 401 });
|
|
358
363
|
}
|
|
359
364
|
(0, import_headers2.draftMode)().enable();
|
|
360
|
-
(0, import_navigation.redirect)(`${
|
|
365
|
+
(0, import_navigation.redirect)(`${playgroundPath}?id=${id}&${import_canvas5.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
361
366
|
}
|
|
362
367
|
};
|
|
363
368
|
};
|
package/dist/handler.mjs
CHANGED
|
@@ -277,14 +277,18 @@ var getQueryParam = (req, paramName) => {
|
|
|
277
277
|
}
|
|
278
278
|
return Array.isArray(value) ? value[0] : value;
|
|
279
279
|
};
|
|
280
|
+
var resolveFullPathDefault = ({ path }) => {
|
|
281
|
+
return path || "";
|
|
282
|
+
};
|
|
280
283
|
var createPreviewGETRouteHandler = (options) => {
|
|
281
284
|
return async (request) => {
|
|
285
|
+
const { playgroundPath, resolveFullPath = resolveFullPathDefault } = options || {};
|
|
282
286
|
const isConfigCheck = getQueryParam(request, "is_config_check") === "true";
|
|
283
287
|
if (isConfigCheck) {
|
|
284
288
|
return Response.json(
|
|
285
289
|
{
|
|
286
|
-
hasPlayground: Boolean(
|
|
287
|
-
isUsingCustomFullPathResolver:
|
|
290
|
+
hasPlayground: Boolean(playgroundPath),
|
|
291
|
+
isUsingCustomFullPathResolver: resolveFullPath !== resolveFullPathDefault
|
|
288
292
|
},
|
|
289
293
|
{
|
|
290
294
|
headers: {
|
|
@@ -304,15 +308,16 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
304
308
|
const path = searchParams.get("path");
|
|
305
309
|
const isPlayground = searchParams.get(IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM) === "true";
|
|
306
310
|
const id = searchParams.get("id");
|
|
311
|
+
const resolbedPath = resolveFullPath({ id, path });
|
|
307
312
|
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
308
313
|
return new Response("Invalid preview secret", { status: 401 });
|
|
309
314
|
}
|
|
310
315
|
if (!isPlayground) {
|
|
311
|
-
if (!
|
|
316
|
+
if (!resolbedPath) {
|
|
312
317
|
return new Response("Path not provided", { status: 401 });
|
|
313
318
|
}
|
|
314
319
|
const resolveResult = await retrieveRouteByPath({
|
|
315
|
-
path,
|
|
320
|
+
path: resolbedPath,
|
|
316
321
|
state: CANVAS_DRAFT_STATE2,
|
|
317
322
|
searchParams: {
|
|
318
323
|
// about to be in draft mode so pretend for now.
|
|
@@ -321,7 +326,7 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
321
326
|
});
|
|
322
327
|
draftMode2().enable();
|
|
323
328
|
if (resolveResult.type === "redirect") {
|
|
324
|
-
const href = resolveRedirectHref(resolveResult,
|
|
329
|
+
const href = resolveRedirectHref(resolveResult, resolbedPath);
|
|
325
330
|
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
326
331
|
redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
327
332
|
} else {
|
|
@@ -331,13 +336,13 @@ var createPreviewGETRouteHandler = (options) => {
|
|
|
331
336
|
if (resolveResult.type === "notFound") {
|
|
332
337
|
return new Response("Invalid path", { status: 401 });
|
|
333
338
|
}
|
|
334
|
-
redirect(`${
|
|
339
|
+
redirect(`${resolbedPath}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
335
340
|
} else {
|
|
336
341
|
if (!(options == null ? void 0 : options.playgroundPath)) {
|
|
337
342
|
return new Response("No playground path is configured", { status: 401 });
|
|
338
343
|
}
|
|
339
344
|
draftMode2().enable();
|
|
340
|
-
redirect(`${
|
|
345
|
+
redirect(`${playgroundPath}?id=${id}&${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM2}=true`);
|
|
341
346
|
}
|
|
342
347
|
};
|
|
343
348
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.123.1-alpha.9+0f8fa37358",
|
|
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.123.1-alpha.9+0f8fa37358",
|
|
65
|
+
"@uniformdev/canvas-next-rsc-client": "^19.123.1-alpha.9+0f8fa37358",
|
|
66
|
+
"@uniformdev/canvas-next-rsc-shared": "^19.123.1-alpha.9+0f8fa37358",
|
|
67
|
+
"@uniformdev/canvas-react": "19.123.1-alpha.9+0f8fa37358",
|
|
68
|
+
"@uniformdev/context": "19.123.1-alpha.9+0f8fa37358",
|
|
69
|
+
"@uniformdev/project-map": "19.123.1-alpha.9+0f8fa37358",
|
|
70
|
+
"@uniformdev/redirect": "19.123.1-alpha.9+0f8fa37358",
|
|
71
|
+
"@uniformdev/richtext": "19.123.1-alpha.9+0f8fa37358",
|
|
72
|
+
"@uniformdev/webhooks": "19.123.1-alpha.9+0f8fa37358",
|
|
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": "0f8fa37358fa0d8bc2e77e00b09d456c7053ee63"
|
|
90
90
|
}
|