@uniformdev/canvas-next-rsc 19.30.1-alpha.0 → 19.33.0
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/components/UniformComposition.js +5 -4
- package/dist/components/retrieveRoute.d.ts +10 -0
- package/dist/components/retrieveRoute.js +70 -0
- package/dist/config/models.d.ts +6 -0
- package/dist/handler/createPreviewGETRouteHandler.js +6 -6
- package/dist/handler/helpers.js +26 -5
- package/dist/handler/messages/handleProjectMapNodeDelete.js +8 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.js +8 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +8 -0
- package/dist/utils/tag.js +2 -1
- package/package.json +8 -8
- package/dist/components/resolveRoute.d.ts +0 -25
- package/dist/components/resolveRoute.js +0 -106
|
@@ -6,7 +6,7 @@ import { getManifestFromApi } from '../client/manifestClient';
|
|
|
6
6
|
import { isDraftModeEnabled, isOnVercelPreviewEnvironment } from '../utils/draft';
|
|
7
7
|
import { evaluateComposition } from './evaluateComposition';
|
|
8
8
|
import { resolvePath } from './resolvePath';
|
|
9
|
-
import {
|
|
9
|
+
import { resolveRedirectHref, retrieveRoute } from './retrieveRoute';
|
|
10
10
|
import { UniformComponent } from './UniformComponent';
|
|
11
11
|
import { UniformProvider } from './UniformContext';
|
|
12
12
|
import { UniformScript } from './UniformScript';
|
|
@@ -31,14 +31,15 @@ const UniformCompositionInner = async ({ params, searchParams, children }) => {
|
|
|
31
31
|
params,
|
|
32
32
|
});
|
|
33
33
|
// resolve the route from the path
|
|
34
|
-
const resolveResult = await
|
|
34
|
+
const resolveResult = await retrieveRoute({
|
|
35
35
|
path,
|
|
36
36
|
state: draftMode || previewEnvironment ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE,
|
|
37
37
|
searchParams,
|
|
38
38
|
});
|
|
39
39
|
// if the route is a redirect, redirect
|
|
40
40
|
if (resolveResult.type === 'redirect') {
|
|
41
|
-
|
|
41
|
+
const href = resolveRedirectHref(resolveResult, path);
|
|
42
|
+
redirect(href);
|
|
42
43
|
}
|
|
43
44
|
// if the route is not found, return 404
|
|
44
45
|
if (resolveResult.type === 'notFound') {
|
|
@@ -46,7 +47,7 @@ const UniformCompositionInner = async ({ params, searchParams, children }) => {
|
|
|
46
47
|
}
|
|
47
48
|
// evaluate the composition
|
|
48
49
|
const { cookieValue, composition: evaluatedComposition, seenComponents, } = await evaluateComposition({
|
|
49
|
-
root: resolveResult.composition,
|
|
50
|
+
root: resolveResult.compositionApiResponse.composition,
|
|
50
51
|
params,
|
|
51
52
|
searchParams: searchParams !== null && searchParams !== void 0 ? searchParams : {},
|
|
52
53
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ResolvedRouteGetResponse, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
2
|
+
export type ResolveRouteOptions = {
|
|
3
|
+
path: string;
|
|
4
|
+
state?: number;
|
|
5
|
+
searchParams: {
|
|
6
|
+
[key: string]: string | undefined;
|
|
7
|
+
} | undefined;
|
|
8
|
+
};
|
|
9
|
+
export declare const retrieveRoute: (data: ResolveRouteOptions) => Promise<ResolvedRouteGetResponse>;
|
|
10
|
+
export declare const resolveRedirectHref: (resolveResult: RouteGetResponseRedirect, path: string) => string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CANVAS_DRAFT_STATE } from '@uniformdev/canvas';
|
|
2
|
+
import { RedirectClient } from '@uniformdev/redirect';
|
|
3
|
+
import { get } from '@vercel/edge-config';
|
|
4
|
+
import { getRouteClient } from '../client/routeClient';
|
|
5
|
+
import { getRouteRevalidateInterval } from '../config/helpers';
|
|
6
|
+
import config from '../config/uniform.server.config';
|
|
7
|
+
import { isOnVercelPreviewEnvironment } from '../utils/draft';
|
|
8
|
+
import { buildPathTag } from '../utils/tag';
|
|
9
|
+
import { getBaseUrl } from '../utils/url';
|
|
10
|
+
export const retrieveRoute = async (data) => {
|
|
11
|
+
void resolveRouteByEdgeConfig(data);
|
|
12
|
+
void resolveRouteByRouteApi(data);
|
|
13
|
+
const edgeConfigValue = await resolveRouteByEdgeConfig(data);
|
|
14
|
+
let result;
|
|
15
|
+
if (edgeConfigValue) {
|
|
16
|
+
result = edgeConfigValue;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const routeApiValue = await resolveRouteByRouteApi(data);
|
|
20
|
+
result = routeApiValue;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
export const resolveRedirectHref = (resolveResult, path) => {
|
|
25
|
+
let href;
|
|
26
|
+
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
27
|
+
const requestUrl = `${getBaseUrl()}${path}`;
|
|
28
|
+
const expandedUrl = RedirectClient.getTargetVariableExpandedUrl(requestUrl, resolveResult.redirect);
|
|
29
|
+
const url = new URL(expandedUrl);
|
|
30
|
+
href = url.pathname;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
href = resolveResult.redirect.targetUrl;
|
|
34
|
+
}
|
|
35
|
+
return href;
|
|
36
|
+
};
|
|
37
|
+
const resolveRouteByEdgeConfig = async (data) => {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) || !process.env.EDGE_CONFIG) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
const sourcePathKey = buildPathTag(data.path);
|
|
43
|
+
const key = sourcePathKey.replace(/\W+/g, '');
|
|
44
|
+
let edgeConfig;
|
|
45
|
+
try {
|
|
46
|
+
edgeConfig = await get(key);
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.warn('Failed to retrieve edge config', e);
|
|
51
|
+
}
|
|
52
|
+
if (!edgeConfig) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return edgeConfig;
|
|
56
|
+
};
|
|
57
|
+
const resolveRouteByRouteApi = async (data) => {
|
|
58
|
+
const routeClient = getRouteClient({
|
|
59
|
+
revalidate: getRouteRevalidateInterval({
|
|
60
|
+
searchParams: data.searchParams,
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
const routeResult = await routeClient.getRoute({
|
|
64
|
+
path: data.path,
|
|
65
|
+
state: data.state,
|
|
66
|
+
withComponentIDs: data.state === CANVAS_DRAFT_STATE,
|
|
67
|
+
withContentSourceMap: isOnVercelPreviewEnvironment(),
|
|
68
|
+
});
|
|
69
|
+
return routeResult;
|
|
70
|
+
};
|
package/dist/config/models.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CANVAS_DRAFT_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from '@uniformdev/canvas';
|
|
2
2
|
import { draftMode } from 'next/headers';
|
|
3
3
|
import { redirect } from 'next/navigation';
|
|
4
|
-
import {
|
|
4
|
+
import { resolveRedirectHref, retrieveRoute } from '../components/retrieveRoute';
|
|
5
5
|
export const createPreviewGETRouteHandler = () => {
|
|
6
6
|
return async (request) => {
|
|
7
7
|
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
@@ -16,7 +16,7 @@ export const createPreviewGETRouteHandler = () => {
|
|
|
16
16
|
if (!path) {
|
|
17
17
|
return new Response('Path not provided', { status: 401 });
|
|
18
18
|
}
|
|
19
|
-
const resolveResult = await
|
|
19
|
+
const resolveResult = await retrieveRoute({
|
|
20
20
|
path,
|
|
21
21
|
state: CANVAS_DRAFT_STATE,
|
|
22
22
|
searchParams: {
|
|
@@ -26,13 +26,13 @@ export const createPreviewGETRouteHandler = () => {
|
|
|
26
26
|
});
|
|
27
27
|
draftMode().enable();
|
|
28
28
|
if (resolveResult.type === 'redirect') {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
29
|
+
const href = resolveRedirectHref(resolveResult, path);
|
|
30
|
+
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
31
31
|
// do we need this query string param still with draft mode cookie?
|
|
32
|
-
redirect(`${
|
|
32
|
+
redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
redirect(
|
|
35
|
+
redirect(href);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
if (resolveResult.type === 'notFound') {
|
package/dist/handler/helpers.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { parseConnectionString } from '@vercel/edge-config';
|
|
1
2
|
import { Webhook } from 'svix';
|
|
2
3
|
import { getProjectMapClient } from '../client/projectMapClient';
|
|
3
4
|
import { getRouteClient } from '../client/routeClient';
|
|
5
|
+
import config from '../config/uniform.server.config';
|
|
4
6
|
import { buildPathTag } from '../utils/tag';
|
|
5
7
|
export const isSvixMessage = async (request) => {
|
|
6
8
|
const requiredHeaders = ['svix-id', 'svix-timestamp', 'svix-signature'];
|
|
@@ -39,9 +41,15 @@ export const processCompositionChange = async (compositionId) => {
|
|
|
39
41
|
compositionId,
|
|
40
42
|
});
|
|
41
43
|
const tags = [];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
if (nodes) {
|
|
45
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
46
|
+
const node = nodes[i];
|
|
47
|
+
await processEdgeConfigChange({
|
|
48
|
+
source_url: node.path,
|
|
49
|
+
});
|
|
50
|
+
tags.push(buildPathTag(node.path));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
45
53
|
return {
|
|
46
54
|
tags,
|
|
47
55
|
};
|
|
@@ -64,6 +72,7 @@ export const processRedirectChange = async (sourceUrl) => {
|
|
|
64
72
|
};
|
|
65
73
|
};
|
|
66
74
|
export const processEdgeConfigChange = async ({ source_url }) => {
|
|
75
|
+
var _a, _b;
|
|
67
76
|
if (!process.env.UNIFORM_VERCEL_EDGE_CONFIG_TOKEN) {
|
|
68
77
|
// eslint-disable-next-line no-console
|
|
69
78
|
console.warn('UNIFORM_VERCEL_EDGE_CONFIG_TOKEN is not set, skipping edge redirect upsert');
|
|
@@ -76,12 +85,24 @@ export const processEdgeConfigChange = async ({ source_url }) => {
|
|
|
76
85
|
path: source_url,
|
|
77
86
|
});
|
|
78
87
|
let valueToStore = undefined;
|
|
79
|
-
|
|
88
|
+
const shouldSaveRedirect = route.type === 'redirect' && ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects);
|
|
89
|
+
const shouldSaveComposition = route.type === 'composition' && ((_b = config.experimental) === null || _b === void 0 ? void 0 : _b.edgeCompositions);
|
|
90
|
+
if (shouldSaveRedirect || shouldSaveComposition) {
|
|
80
91
|
valueToStore = route;
|
|
81
92
|
}
|
|
82
93
|
const sourcePath = getPathName(source_url);
|
|
83
94
|
const soucrcePathKey = buildPathTag(sourcePath);
|
|
84
|
-
const
|
|
95
|
+
const { id } = parseConnectionString(process.env.EDGE_CONFIG) || {};
|
|
96
|
+
if (!id) {
|
|
97
|
+
// eslint-disable-next-line no-console
|
|
98
|
+
console.warn('EDGE_CONFIG is not set or not a connection string, skipping edge redirect upsert');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const url = new URL(`https://api.vercel.com/v1/edge-config/${id}/items`);
|
|
102
|
+
if (process.env.UNIFORM_VERCEL_EDGE_CONFIG_TEAM_ID) {
|
|
103
|
+
url.searchParams.set('teamId', process.env.UNIFORM_VERCEL_EDGE_CONFIG_TEAM_ID);
|
|
104
|
+
}
|
|
105
|
+
const response = await fetch(url.toString(), {
|
|
85
106
|
method: 'PATCH',
|
|
86
107
|
headers: {
|
|
87
108
|
'Content-Type': 'application/json',
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { ProjectMapNodeDeleteDefinition } from '@uniformdev/webhooks';
|
|
2
|
+
import config from '../../config/uniform.server.config';
|
|
2
3
|
import { buildPathTag } from '../../utils/tag';
|
|
4
|
+
import { processEdgeConfigChange } from '../helpers';
|
|
3
5
|
export const handleProjectMapNodeDelete = async (body) => {
|
|
6
|
+
var _a;
|
|
4
7
|
const parsed = ProjectMapNodeDeleteDefinition.schema.safeParse(body);
|
|
5
8
|
if (!parsed.success) {
|
|
6
9
|
return undefined;
|
|
7
10
|
}
|
|
8
11
|
const tags = [];
|
|
9
12
|
tags.push(buildPathTag(parsed.data.path));
|
|
13
|
+
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
14
|
+
await processEdgeConfigChange({
|
|
15
|
+
source_url: parsed.data.path,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
tags,
|
|
12
20
|
};
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { ProjectMapNodeInsertDefinition } from '@uniformdev/webhooks';
|
|
2
|
+
import config from '../../config/uniform.server.config';
|
|
2
3
|
import { buildPathTag } from '../../utils/tag';
|
|
4
|
+
import { processEdgeConfigChange } from '../helpers';
|
|
3
5
|
export const handleProjectMapNodeInsert = async (body) => {
|
|
6
|
+
var _a;
|
|
4
7
|
const parsed = ProjectMapNodeInsertDefinition.schema.safeParse(body);
|
|
5
8
|
if (!parsed.success) {
|
|
6
9
|
return undefined;
|
|
7
10
|
}
|
|
8
11
|
const tags = [];
|
|
9
12
|
tags.push(buildPathTag(parsed.data.path));
|
|
13
|
+
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
14
|
+
await processEdgeConfigChange({
|
|
15
|
+
source_url: parsed.data.path,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
10
18
|
return {
|
|
11
19
|
tags,
|
|
12
20
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ProjectMapNodeUpdateDefinition } from '@uniformdev/webhooks';
|
|
2
|
+
import config from '../../config/uniform.server.config';
|
|
2
3
|
import { buildPathTag } from '../../utils/tag';
|
|
4
|
+
import { processEdgeConfigChange } from '../helpers';
|
|
3
5
|
export const handleProjectMapNodeUpdate = async (body) => {
|
|
6
|
+
var _a;
|
|
4
7
|
const parsed = ProjectMapNodeUpdateDefinition.schema.safeParse(body);
|
|
5
8
|
if (!parsed.success) {
|
|
6
9
|
return undefined;
|
|
@@ -8,6 +11,11 @@ export const handleProjectMapNodeUpdate = async (body) => {
|
|
|
8
11
|
const tags = [];
|
|
9
12
|
tags.push(buildPathTag(parsed.data.path));
|
|
10
13
|
tags.push(buildPathTag(parsed.data.previous_path));
|
|
14
|
+
if ((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeCompositions) {
|
|
15
|
+
await processEdgeConfigChange({
|
|
16
|
+
source_url: parsed.data.path,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
11
19
|
return {
|
|
12
20
|
tags,
|
|
13
21
|
};
|
package/dist/utils/tag.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.33.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "pnpm build --watch",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"typescript": "^5.0.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@uniformdev/canvas": "^19.
|
|
60
|
-
"@uniformdev/canvas-react": "^19.
|
|
61
|
-
"@uniformdev/context": "^19.
|
|
62
|
-
"@uniformdev/project-map": "^19.
|
|
63
|
-
"@uniformdev/redirect": "^19.
|
|
64
|
-
"@uniformdev/webhooks": "^19.
|
|
59
|
+
"@uniformdev/canvas": "^19.33.0",
|
|
60
|
+
"@uniformdev/canvas-react": "^19.33.0",
|
|
61
|
+
"@uniformdev/context": "^19.33.0",
|
|
62
|
+
"@uniformdev/project-map": "^19.33.0",
|
|
63
|
+
"@uniformdev/redirect": "^19.33.0",
|
|
64
|
+
"@uniformdev/webhooks": "^19.33.0",
|
|
65
65
|
"@vercel/edge-config": "^0.1.5",
|
|
66
66
|
"dequal": "^2.0.3",
|
|
67
67
|
"js-cookie": "^3.0.5",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "a26cf289e832737b2cf4c9b6d767640b627a6368"
|
|
79
79
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { RootComponentInstance } from '@uniformdev/canvas';
|
|
2
|
-
export type CompositionRouteResult = {
|
|
3
|
-
type: 'composition';
|
|
4
|
-
composition: RootComponentInstance;
|
|
5
|
-
};
|
|
6
|
-
export type RedirectRouteResult = {
|
|
7
|
-
type: 'redirect';
|
|
8
|
-
redirect: {
|
|
9
|
-
href: string;
|
|
10
|
-
statusCode: number;
|
|
11
|
-
nodeId: string | undefined;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export type NotFoundRouteResult = {
|
|
15
|
-
type: 'notFound';
|
|
16
|
-
};
|
|
17
|
-
export type ResolveRouteResult = CompositionRouteResult | RedirectRouteResult | NotFoundRouteResult;
|
|
18
|
-
export type ResolveRouteOptions = {
|
|
19
|
-
path: string;
|
|
20
|
-
state?: number;
|
|
21
|
-
searchParams: {
|
|
22
|
-
[key: string]: string | undefined;
|
|
23
|
-
} | undefined;
|
|
24
|
-
};
|
|
25
|
-
export declare const resolveRoute: (data: ResolveRouteOptions) => Promise<ResolveRouteResult>;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { CANVAS_DRAFT_STATE } from '@uniformdev/canvas';
|
|
2
|
-
import { RedirectClient } from '@uniformdev/redirect';
|
|
3
|
-
import { get } from '@vercel/edge-config';
|
|
4
|
-
import { getRouteClient } from '../client/routeClient';
|
|
5
|
-
import { getRouteRevalidateInterval } from '../config/helpers';
|
|
6
|
-
import config from '../config/uniform.server.config';
|
|
7
|
-
import { isOnVercelPreviewEnvironment } from '../utils/draft';
|
|
8
|
-
import { buildPathTag } from '../utils/tag';
|
|
9
|
-
import { getBaseUrl } from '../utils/url';
|
|
10
|
-
export const resolveRoute = async (data) => {
|
|
11
|
-
const apiPromise = resolveRouteByRouteApi(data);
|
|
12
|
-
const edgeConfigPromise = resolveRouteByEdgeConfig(data);
|
|
13
|
-
const first = await Promise.race([apiPromise, edgeConfigPromise]);
|
|
14
|
-
let result;
|
|
15
|
-
if (first === null || first === void 0 ? void 0 : first.value) {
|
|
16
|
-
result = first.value;
|
|
17
|
-
}
|
|
18
|
-
else if ((first === null || first === void 0 ? void 0 : first.source) === 'edgeConfig') {
|
|
19
|
-
const apiResult = await apiPromise;
|
|
20
|
-
result = apiResult === null || apiResult === void 0 ? void 0 : apiResult.value;
|
|
21
|
-
}
|
|
22
|
-
else if ((first === null || first === void 0 ? void 0 : first.source) === 'routeApi') {
|
|
23
|
-
const edgeConfigResult = await edgeConfigPromise;
|
|
24
|
-
result = edgeConfigResult === null || edgeConfigResult === void 0 ? void 0 : edgeConfigResult.value;
|
|
25
|
-
}
|
|
26
|
-
if (result) {
|
|
27
|
-
const processed = processRouteResponse(data.path, result);
|
|
28
|
-
if (processed) {
|
|
29
|
-
return processed;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
type: 'notFound',
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const resolveRouteByEdgeConfig = async (data) => {
|
|
37
|
-
var _a;
|
|
38
|
-
if (!((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) || !process.env.EDGE_CONFIG) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
const soucrcePathKey = buildPathTag(data.path);
|
|
42
|
-
const key = soucrcePathKey.replace(/\W+/g, '');
|
|
43
|
-
const edgeConfig = await get(key);
|
|
44
|
-
if (!edgeConfig) {
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
source: 'edgeConfig',
|
|
49
|
-
value: edgeConfig,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
const resolveRouteByRouteApi = async (data) => {
|
|
53
|
-
const routeClient = getRouteClient({
|
|
54
|
-
revalidate: getRouteRevalidateInterval({
|
|
55
|
-
searchParams: data.searchParams,
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
58
|
-
const routeResult = await routeClient.getRoute({
|
|
59
|
-
path: data.path,
|
|
60
|
-
state: data.state,
|
|
61
|
-
withComponentIDs: data.state === CANVAS_DRAFT_STATE,
|
|
62
|
-
withContentSourceMap: isOnVercelPreviewEnvironment(),
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
source: 'routeApi',
|
|
66
|
-
value: routeResult,
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
const processRouteResponse = (path, routeResult) => {
|
|
70
|
-
if (routeResult.type === 'notFound') {
|
|
71
|
-
return {
|
|
72
|
-
type: 'notFound',
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
else if (routeResult.type === 'composition') {
|
|
76
|
-
return {
|
|
77
|
-
type: 'composition',
|
|
78
|
-
composition: routeResult.compositionApiResponse.composition,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
else if (routeResult.type === 'redirect') {
|
|
82
|
-
let href;
|
|
83
|
-
if (routeResult.redirect.targetProjectMapNodeId) {
|
|
84
|
-
const requestUrl = `${getBaseUrl()}${path}`;
|
|
85
|
-
const expandedUrl = RedirectClient.getTargetVariableExpandedUrl(requestUrl, routeResult.redirect);
|
|
86
|
-
const url = new URL(expandedUrl);
|
|
87
|
-
href = url.pathname;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
href = routeResult.redirect.targetUrl;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
type: 'redirect',
|
|
94
|
-
redirect: {
|
|
95
|
-
href,
|
|
96
|
-
statusCode: routeResult.redirect.targetStatusCode,
|
|
97
|
-
nodeId: routeResult.redirect.targetProjectMapNodeId,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
return {
|
|
103
|
-
type: 'notFound',
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
};
|