@uniformdev/canvas-next-rsc 20.31.1-alpha.1 → 20.31.1-alpha.185
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/UniformComposition-0pvEHduc.d.mts +64 -0
- package/dist/UniformComposition-0pvEHduc.d.ts +77 -0
- package/dist/UniformComposition-38e22896.d.ts +74 -0
- package/dist/UniformComposition-B-Z17dUt.d.mts +67 -0
- package/dist/UniformComposition-B-Z17dUt.d.ts +80 -0
- package/dist/UniformComposition-D4tBQ2U4.d.mts +64 -0
- package/dist/UniformComposition-D4tBQ2U4.d.ts +77 -0
- package/dist/UniformComposition-Dw55RFP6.d.mts +67 -0
- package/dist/UniformComposition-Dw55RFP6.d.ts +67 -0
- package/dist/UniformComposition-IWWzoI_H.d.mts +82 -0
- package/dist/UniformComposition-IWWzoI_H.d.ts +82 -0
- package/dist/UniformComposition-d178d865.d.ts +77 -0
- package/dist/actions/updateContext.d.ts +2 -0
- package/dist/actions/updateContext.js +17 -0
- package/dist/client/canvasClient.d.ts +5 -0
- package/dist/client/canvasClient.js +53 -0
- package/dist/client/manifestClient.d.ts +209 -0
- package/dist/client/manifestClient.js +33 -0
- package/dist/client/projectMapClient.d.ts +5 -0
- package/dist/client/projectMapClient.js +17 -0
- package/dist/client/routeClient.d.ts +5 -0
- package/dist/client/routeClient.js +68 -0
- package/dist/components/DefaultNotImplementedComponent.d.ts +4 -0
- package/dist/components/DefaultNotImplementedComponent.js +45 -0
- package/dist/components/GoogleTagManagerAnalytics.d.ts +3 -0
- package/dist/components/GoogleTagManagerAnalytics.js +44 -0
- package/dist/components/UniformComponent.d.ts +35 -0
- package/dist/components/UniformComponent.js +14 -0
- package/dist/components/UniformComposition.d.ts +47 -0
- package/dist/components/UniformComposition.js +35 -0
- package/dist/components/UniformContext.d.ts +13 -0
- package/dist/components/UniformContext.js +19 -0
- package/dist/components/UniformRichText.d.ts +42 -0
- package/dist/components/UniformRichText.js +15 -0
- package/dist/components/UniformRichTextNode.d.ts +14 -0
- package/dist/components/UniformRichTextNode.js +49 -0
- package/dist/components/UniformScript.d.ts +5 -0
- package/dist/components/UniformScript.js +49 -0
- package/dist/components/UniformSlot.d.ts +48 -0
- package/dist/components/UniformSlot.js +38 -0
- package/dist/components/UniformText.d.ts +10 -0
- package/dist/components/UniformText.js +5 -0
- package/dist/components/__tests__/evaluateComposition.spec.d.ts +1 -0
- package/dist/components/__tests__/evaluateComposition.spec.js +80 -0
- package/dist/components/convertComponentToProps.d.ts +18 -0
- package/dist/components/convertComponentToProps.js +22 -0
- package/dist/components/evaluateComposition.d.ts +32 -0
- package/dist/components/evaluateComposition.js +183 -0
- package/dist/components/getEnrichmentTags.d.ts +5 -0
- package/dist/components/getEnrichmentTags.js +13 -0
- package/dist/components/getUniformContext.d.ts +10 -0
- package/dist/components/getUniformContext.js +17 -0
- package/dist/components/nodes/HeadingRichTextNode.d.ts +2 -0
- package/dist/components/nodes/HeadingRichTextNode.js +6 -0
- package/dist/components/nodes/LinebreakRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinebreakRichTextNode.js +4 -0
- package/dist/components/nodes/LinkRichTextNode.d.ts +2 -0
- package/dist/components/nodes/LinkRichTextNode.js +6 -0
- package/dist/components/nodes/ListItemRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListItemRichTextNode.js +5 -0
- package/dist/components/nodes/ListRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ListRichTextNode.js +6 -0
- package/dist/components/nodes/ParagraphRichTextNode.d.ts +2 -0
- package/dist/components/nodes/ParagraphRichTextNode.js +6 -0
- package/dist/components/nodes/TabRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TabRichTextNode.js +4 -0
- package/dist/components/nodes/TextRichTextNode.d.ts +2 -0
- package/dist/components/nodes/TextRichTextNode.js +9 -0
- package/dist/components/renderComponent.d.ts +26 -0
- package/dist/components/renderComponent.js +52 -0
- package/dist/components/resolvePath.d.ts +5 -0
- package/dist/components/resolvePath.js +34 -0
- package/dist/components/retrieveRoute.d.ts +198 -0
- package/dist/components/retrieveRoute.js +146 -0
- package/dist/components/types.d.ts +15 -0
- package/dist/components/types.js +1 -0
- package/dist/config/helpers.d.ts +23 -0
- package/dist/config/helpers.js +34 -0
- package/dist/config/models.d.ts +51 -0
- package/dist/config/models.js +1 -0
- package/dist/config/uniform.server.config.d.ts +3 -0
- package/dist/config/uniform.server.config.js +4 -0
- package/dist/cookie/index.d.ts +12 -0
- package/dist/cookie/index.js +21 -0
- package/dist/handler/createPreviewGETRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewGETRouteHandler.js +43 -0
- package/dist/handler/createPreviewPOSTRouteHandler.d.ts +1 -0
- package/dist/handler/createPreviewPOSTRouteHandler.js +88 -0
- package/dist/handler/createUniformRouteHandler.d.ts +4 -0
- package/dist/handler/createUniformRouteHandler.js +10 -0
- package/dist/handler/helpers.d.ts +17 -0
- package/dist/handler/helpers.js +148 -0
- package/dist/handler/messages/handleCompositionChanged.d.ts +2 -0
- package/dist/handler/messages/handleCompositionChanged.js +9 -0
- package/dist/handler/messages/handleCompositionDeleted.d.ts +2 -0
- package/dist/handler/messages/handleCompositionDeleted.js +9 -0
- package/dist/handler/messages/handleCompositionPublished.d.ts +2 -0
- package/dist/handler/messages/handleCompositionPublished.js +9 -0
- package/dist/handler/messages/handleManifestPublished.d.ts +2 -0
- package/dist/handler/messages/handleManifestPublished.js +10 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeDelete.js +21 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeInsert.js +21 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.d.ts +2 -0
- package/dist/handler/messages/handleProjectMapNodeUpdate.js +22 -0
- package/dist/handler/messages/handleRedirectDelete.d.ts +2 -0
- package/dist/handler/messages/handleRedirectDelete.js +15 -0
- package/dist/handler/messages/handleRedirectInsert.d.ts +2 -0
- package/dist/handler/messages/handleRedirectInsert.js +15 -0
- package/dist/handler/messages/handleRedirectUpdate.d.ts +2 -0
- package/dist/handler/messages/handleRedirectUpdate.js +15 -0
- package/dist/hooks/useForgetMe.d.ts +4 -0
- package/dist/hooks/useForgetMe.js +10 -0
- package/dist/hooks/useToggleConsent.d.ts +7 -0
- package/dist/hooks/useToggleConsent.js +22 -0
- package/dist/hooks/useUniformContext.d.ts +1 -0
- package/dist/hooks/useUniformContext.js +3 -0
- package/dist/index.esm.js +17 -26
- package/dist/index.js +17 -26
- package/dist/index.mjs +17 -26
- package/dist/models/index.d.ts +30 -0
- package/dist/models/index.js +1 -0
- package/dist/register/componentStore.d.ts +1 -0
- package/dist/register/componentStore.js +2 -0
- package/dist/register/componentStoreResolver.d.ts +4 -0
- package/dist/register/componentStoreResolver.js +5 -0
- package/dist/register/createComponentStore.d.ts +12 -0
- package/dist/register/createComponentStore.js +13 -0
- package/dist/register/createComponentStoreResolver.d.ts +12 -0
- package/dist/register/createComponentStoreResolver.js +9 -0
- package/dist/register/getTypeWithVariant.d.ts +1 -0
- package/dist/register/getTypeWithVariant.js +1 -0
- package/dist/register/registerUniformComponent.d.ts +10 -0
- package/dist/register/registerUniformComponent.js +8 -0
- package/dist/resolve/resolveChildren.d.ts +17 -0
- package/dist/resolve/resolveChildren.js +20 -0
- package/dist/score/index.d.ts +3 -0
- package/dist/score/index.js +114 -0
- package/dist/utils/__tests__/apply.spec.d.ts +1 -0
- package/dist/utils/__tests__/apply.spec.js +358 -0
- package/dist/utils/__tests__/diff.spec.d.ts +1 -0
- package/dist/utils/__tests__/diff.spec.js +394 -0
- package/dist/utils/apply.d.ts +10 -0
- package/dist/utils/apply.js +124 -0
- package/dist/utils/comp.d.ts +25 -0
- package/dist/utils/comp.js +65 -0
- package/dist/utils/diff.d.ts +58 -0
- package/dist/utils/diff.js +144 -0
- package/dist/utils/draft.d.ts +20 -0
- package/dist/utils/draft.js +22 -0
- package/dist/utils/tag.d.ts +2 -0
- package/dist/utils/tag.js +7 -0
- package/dist/utils/url.d.ts +1 -0
- package/dist/utils/url.js +10 -0
- package/package.json +14 -14
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { ResolvedRouteGetResponse, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
2
|
+
|
|
3
|
+
import { UniformCompositionProps } from './UniformComposition';
|
|
4
|
+
export type ResolveRouteOptions = {
|
|
5
|
+
path: string;
|
|
6
|
+
state?: number;
|
|
7
|
+
searchParams:
|
|
8
|
+
| {
|
|
9
|
+
[key: string]: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
| undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare const resolveComposition: ({
|
|
14
|
+
searchParams,
|
|
15
|
+
params,
|
|
16
|
+
update,
|
|
17
|
+
}: Pick<UniformCompositionProps, 'searchParams' | 'params' | 'update'>) => Promise<{
|
|
18
|
+
type: 'composition';
|
|
19
|
+
matchedRoute: string;
|
|
20
|
+
dynamicInputs?:
|
|
21
|
+
| {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
}
|
|
24
|
+
| undefined;
|
|
25
|
+
composition: {
|
|
26
|
+
type: string;
|
|
27
|
+
parameters?:
|
|
28
|
+
| {
|
|
29
|
+
[key: string]: {
|
|
30
|
+
value: unknown;
|
|
31
|
+
type: string;
|
|
32
|
+
connectedData?:
|
|
33
|
+
| {
|
|
34
|
+
pointer: string;
|
|
35
|
+
syntax: 'jptr';
|
|
36
|
+
}
|
|
37
|
+
| undefined;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
| undefined;
|
|
41
|
+
variant?: string | undefined;
|
|
42
|
+
projectMapNodes?:
|
|
43
|
+
| {
|
|
44
|
+
id: string;
|
|
45
|
+
path: string;
|
|
46
|
+
projectMapId: string;
|
|
47
|
+
}[]
|
|
48
|
+
| undefined;
|
|
49
|
+
slots?:
|
|
50
|
+
| {
|
|
51
|
+
[key: string]: {
|
|
52
|
+
type: string;
|
|
53
|
+
parameters?:
|
|
54
|
+
| {
|
|
55
|
+
[key: string]: {
|
|
56
|
+
value: unknown;
|
|
57
|
+
type: string;
|
|
58
|
+
connectedData?:
|
|
59
|
+
| {
|
|
60
|
+
pointer: string;
|
|
61
|
+
syntax: 'jptr';
|
|
62
|
+
}
|
|
63
|
+
| undefined;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
| undefined;
|
|
67
|
+
variant?: string | undefined;
|
|
68
|
+
slots?:
|
|
69
|
+
| {
|
|
70
|
+
[key: string]: any[];
|
|
71
|
+
}
|
|
72
|
+
| undefined;
|
|
73
|
+
_id?: string | undefined;
|
|
74
|
+
_pattern?: string | undefined;
|
|
75
|
+
_dataResources?:
|
|
76
|
+
| {
|
|
77
|
+
[key: string]: {
|
|
78
|
+
type: string;
|
|
79
|
+
isPatternParameter?: boolean | undefined;
|
|
80
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
81
|
+
variables?:
|
|
82
|
+
| {
|
|
83
|
+
[key: string]: string;
|
|
84
|
+
}
|
|
85
|
+
| undefined;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
| undefined;
|
|
89
|
+
_patternDataResources?:
|
|
90
|
+
| {
|
|
91
|
+
[key: string]: {
|
|
92
|
+
type: string;
|
|
93
|
+
isPatternParameter?: boolean | undefined;
|
|
94
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
95
|
+
variables?:
|
|
96
|
+
| {
|
|
97
|
+
[key: string]: string;
|
|
98
|
+
}
|
|
99
|
+
| undefined;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
| undefined;
|
|
103
|
+
_patternError?: 'NOTFOUND' | 'CYCLIC' | undefined;
|
|
104
|
+
_overrides?:
|
|
105
|
+
| {
|
|
106
|
+
[key: string]: {
|
|
107
|
+
parameters?:
|
|
108
|
+
| {
|
|
109
|
+
[key: string]: {
|
|
110
|
+
value: unknown;
|
|
111
|
+
type: string;
|
|
112
|
+
connectedData?:
|
|
113
|
+
| {
|
|
114
|
+
pointer: string;
|
|
115
|
+
syntax: 'jptr';
|
|
116
|
+
}
|
|
117
|
+
| undefined;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
| undefined;
|
|
121
|
+
variant?: string | undefined;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
| undefined;
|
|
125
|
+
_overridability?:
|
|
126
|
+
| {
|
|
127
|
+
parameters?:
|
|
128
|
+
| {
|
|
129
|
+
[key: string]: 'yes' | 'no';
|
|
130
|
+
}
|
|
131
|
+
| undefined;
|
|
132
|
+
variants?: boolean | undefined;
|
|
133
|
+
}
|
|
134
|
+
| undefined;
|
|
135
|
+
}[];
|
|
136
|
+
}
|
|
137
|
+
| undefined;
|
|
138
|
+
_id: string;
|
|
139
|
+
_slug?: string | null | undefined;
|
|
140
|
+
_name: string;
|
|
141
|
+
_dataResources?:
|
|
142
|
+
| {
|
|
143
|
+
[key: string]: {
|
|
144
|
+
type: string;
|
|
145
|
+
isPatternParameter?: boolean | undefined;
|
|
146
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
147
|
+
variables?:
|
|
148
|
+
| {
|
|
149
|
+
[key: string]: string;
|
|
150
|
+
}
|
|
151
|
+
| undefined;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
| undefined;
|
|
155
|
+
_overrides?:
|
|
156
|
+
| {
|
|
157
|
+
[key: string]: {
|
|
158
|
+
parameters?:
|
|
159
|
+
| {
|
|
160
|
+
[key: string]: {
|
|
161
|
+
value: unknown;
|
|
162
|
+
type: string;
|
|
163
|
+
connectedData?:
|
|
164
|
+
| {
|
|
165
|
+
pointer: string;
|
|
166
|
+
syntax: 'jptr';
|
|
167
|
+
}
|
|
168
|
+
| undefined;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
| undefined;
|
|
172
|
+
variant?: string | undefined;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
| undefined;
|
|
176
|
+
_overridability?:
|
|
177
|
+
| {
|
|
178
|
+
parameters?:
|
|
179
|
+
| {
|
|
180
|
+
[key: string]: 'yes' | 'no';
|
|
181
|
+
}
|
|
182
|
+
| undefined;
|
|
183
|
+
variants?: boolean | undefined;
|
|
184
|
+
}
|
|
185
|
+
| undefined;
|
|
186
|
+
};
|
|
187
|
+
cookieValue: string | undefined;
|
|
188
|
+
path: string;
|
|
189
|
+
searchParams:
|
|
190
|
+
| {
|
|
191
|
+
[key: string]: string | undefined;
|
|
192
|
+
}
|
|
193
|
+
| undefined;
|
|
194
|
+
isCanvasEditing: boolean;
|
|
195
|
+
seenComponents: import('../models').SeenUniformComponent[];
|
|
196
|
+
}>;
|
|
197
|
+
export declare const retrieveRoute: (data: ResolveRouteOptions) => Promise<ResolvedRouteGetResponse>;
|
|
198
|
+
export declare const resolveRedirectHref: (resolveResult: RouteGetResponseRedirect, path: string) => string;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, CANVAS_PUBLISHED_STATE, } from '@uniformdev/canvas';
|
|
2
|
+
import { RedirectClient } from '@uniformdev/redirect';
|
|
3
|
+
import { get } from '@vercel/edge-config';
|
|
4
|
+
import { cookies, headers } from 'next/headers';
|
|
5
|
+
import { notFound, redirect } from 'next/navigation';
|
|
6
|
+
import { getManifestFromApi } from '../client/manifestClient';
|
|
7
|
+
import { getRouteClient } from '../client/routeClient';
|
|
8
|
+
import { getRouteRevalidateInterval, getServerConfig } from '../config/helpers';
|
|
9
|
+
import { isDevelopmentEnvironment, isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment, } from '../utils/draft';
|
|
10
|
+
import { buildPathTag } from '../utils/tag';
|
|
11
|
+
import { getBaseUrl } from '../utils/url';
|
|
12
|
+
import { evaluateComposition } from './evaluateComposition';
|
|
13
|
+
import { resolvePath } from './resolvePath';
|
|
14
|
+
export const resolveComposition = async ({ searchParams, params, update, }) => {
|
|
15
|
+
// prefetch manifest immediately
|
|
16
|
+
void getManifestFromApi({
|
|
17
|
+
searchParams,
|
|
18
|
+
});
|
|
19
|
+
const draftMode = isDraftModeEnabled({ searchParams });
|
|
20
|
+
const previewEnvironment = isOnVercelPreviewEnvironment();
|
|
21
|
+
const isDevelopment = isDevelopmentEnvironment();
|
|
22
|
+
const isCanvasEditing = isIncontextEditingEnabled({
|
|
23
|
+
searchParams,
|
|
24
|
+
});
|
|
25
|
+
// resolve the path from provided params
|
|
26
|
+
const path = resolvePath({
|
|
27
|
+
params,
|
|
28
|
+
});
|
|
29
|
+
let state;
|
|
30
|
+
if (isCanvasEditing) {
|
|
31
|
+
state = CANVAS_EDITOR_STATE;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
state = draftMode || previewEnvironment || isDevelopment ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
35
|
+
}
|
|
36
|
+
// resolve the route from the path
|
|
37
|
+
const resolveResult = await retrieveRoute({
|
|
38
|
+
path,
|
|
39
|
+
state,
|
|
40
|
+
searchParams,
|
|
41
|
+
});
|
|
42
|
+
// if the route is a redirect, redirect
|
|
43
|
+
if (resolveResult.type === 'redirect') {
|
|
44
|
+
const href = resolveRedirectHref(resolveResult, path);
|
|
45
|
+
redirect(href);
|
|
46
|
+
}
|
|
47
|
+
// if the route is not found, return 404
|
|
48
|
+
if (resolveResult.type === 'notFound') {
|
|
49
|
+
notFound();
|
|
50
|
+
}
|
|
51
|
+
const { compositionApiResponse, ...rest } = resolveResult;
|
|
52
|
+
// evaluate the composition
|
|
53
|
+
const { cookieValue, composition: evaluatedComposition, seenComponents, } = await evaluateComposition({
|
|
54
|
+
root: compositionApiResponse.composition,
|
|
55
|
+
params,
|
|
56
|
+
searchParams: searchParams !== null && searchParams !== void 0 ? searchParams : {},
|
|
57
|
+
dynamicInputs: rest.dynamicInputs,
|
|
58
|
+
headers: headers(),
|
|
59
|
+
cookies: cookies()
|
|
60
|
+
.getAll()
|
|
61
|
+
.reduce((acc, cookie) => {
|
|
62
|
+
acc[cookie.name] = cookie.value;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {}),
|
|
65
|
+
update,
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
composition: evaluatedComposition,
|
|
69
|
+
cookieValue,
|
|
70
|
+
path,
|
|
71
|
+
searchParams,
|
|
72
|
+
isCanvasEditing,
|
|
73
|
+
seenComponents,
|
|
74
|
+
...rest,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export const retrieveRoute = async (data) => {
|
|
78
|
+
void resolveRouteByEdgeConfig(data);
|
|
79
|
+
void resolveRouteByRouteApi(data);
|
|
80
|
+
const edgeConfigValue = await resolveRouteByEdgeConfig(data);
|
|
81
|
+
let result;
|
|
82
|
+
if (edgeConfigValue) {
|
|
83
|
+
result = edgeConfigValue;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const routeApiValue = await resolveRouteByRouteApi(data);
|
|
87
|
+
result = routeApiValue;
|
|
88
|
+
}
|
|
89
|
+
// fall back to draft if requesting editor state
|
|
90
|
+
if (result.type === 'notFound' && data.state === CANVAS_EDITOR_STATE) {
|
|
91
|
+
return retrieveRoute({
|
|
92
|
+
...data,
|
|
93
|
+
state: CANVAS_DRAFT_STATE,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
export const resolveRedirectHref = (resolveResult, path) => {
|
|
99
|
+
let href;
|
|
100
|
+
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
101
|
+
const requestUrl = `${getBaseUrl()}${path}`;
|
|
102
|
+
const expandedUrl = RedirectClient.getTargetVariableExpandedUrl(requestUrl, resolveResult.redirect);
|
|
103
|
+
const url = new URL(expandedUrl);
|
|
104
|
+
href = url.pathname;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
href = resolveResult.redirect.targetUrl;
|
|
108
|
+
}
|
|
109
|
+
return href;
|
|
110
|
+
};
|
|
111
|
+
const resolveRouteByEdgeConfig = async (data) => {
|
|
112
|
+
var _a;
|
|
113
|
+
const config = getServerConfig();
|
|
114
|
+
if (!((_a = config.experimental) === null || _a === void 0 ? void 0 : _a.edgeRedirects) || !process.env.EDGE_CONFIG) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const sourcePathKey = buildPathTag(data.path);
|
|
118
|
+
const key = sourcePathKey.replace(/\W+/g, '');
|
|
119
|
+
let edgeConfig;
|
|
120
|
+
try {
|
|
121
|
+
edgeConfig = await get(key);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.warn('Failed to retrieve edge config', e);
|
|
126
|
+
}
|
|
127
|
+
if (!edgeConfig) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return edgeConfig;
|
|
131
|
+
};
|
|
132
|
+
const resolveRouteByRouteApi = async (data) => {
|
|
133
|
+
var _a;
|
|
134
|
+
const routeClient = getRouteClient({
|
|
135
|
+
revalidate: getRouteRevalidateInterval({
|
|
136
|
+
searchParams: data.searchParams,
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
const routeResult = await routeClient.getRoute({
|
|
140
|
+
path: data.path,
|
|
141
|
+
state: data.state,
|
|
142
|
+
withComponentIDs: data.state === CANVAS_DRAFT_STATE || data.state === CANVAS_EDITOR_STATE,
|
|
143
|
+
withContentSourceMap: isOnVercelPreviewEnvironment() && ((_a = getServerConfig().experimental) === null || _a === void 0 ? void 0 : _a.vercelVisualEditing),
|
|
144
|
+
});
|
|
145
|
+
return routeResult;
|
|
146
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RichTextNode } from '@uniformdev/richtext';
|
|
2
|
+
import React, { PropsWithChildren } from 'react';
|
|
3
|
+
export type RichTextComponentProps<TNode extends RichTextNode = RichTextNode> = {
|
|
4
|
+
node: TNode;
|
|
5
|
+
};
|
|
6
|
+
export type RichTextRendererComponent<TNode extends RichTextNode = RichTextNode> = React.ComponentType<
|
|
7
|
+
PropsWithChildren<RichTextComponentProps<TNode>>
|
|
8
|
+
>;
|
|
9
|
+
/**
|
|
10
|
+
* Function that maps a Rich Text node instance to its React component to render it.
|
|
11
|
+
* The resolver would commonly inspect the `type` of the component to decide.
|
|
12
|
+
*/
|
|
13
|
+
export type RenderRichTextComponentResolver = (
|
|
14
|
+
node: RichTextNode
|
|
15
|
+
) => RichTextRendererComponent | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { UniformServerConfig } from './models';
|
|
2
|
+
export declare const getCanvasRevalidateInterval: (options: {
|
|
3
|
+
searchParams:
|
|
4
|
+
| {
|
|
5
|
+
[key: string]: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
| undefined;
|
|
8
|
+
}) => number | undefined;
|
|
9
|
+
export declare const getManifestRevalidateInterval: (options: {
|
|
10
|
+
searchParams:
|
|
11
|
+
| {
|
|
12
|
+
[key: string]: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
| undefined;
|
|
15
|
+
}) => number | undefined;
|
|
16
|
+
export declare const getRouteRevalidateInterval: (options: {
|
|
17
|
+
searchParams:
|
|
18
|
+
| {
|
|
19
|
+
[key: string]: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
| undefined;
|
|
22
|
+
}) => number | undefined;
|
|
23
|
+
export declare const getServerConfig: () => UniformServerConfig;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isDraftModeEnabled, isOnVercelPreviewEnvironment } from '../utils/draft';
|
|
2
|
+
export const getCanvasRevalidateInterval = (options) => {
|
|
3
|
+
if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
|
|
4
|
+
return -1;
|
|
5
|
+
}
|
|
6
|
+
const config = getServerConfig();
|
|
7
|
+
return 'canvasRevalidateInterval' in config ? config.canvasRevalidateInterval : undefined;
|
|
8
|
+
};
|
|
9
|
+
export const getManifestRevalidateInterval = (options) => {
|
|
10
|
+
if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
|
|
11
|
+
return -1;
|
|
12
|
+
}
|
|
13
|
+
const config = getServerConfig();
|
|
14
|
+
return 'manifestRevalidateInterval' in config ? config.manifestRevalidateInterval : undefined;
|
|
15
|
+
};
|
|
16
|
+
export const getRouteRevalidateInterval = (options) => {
|
|
17
|
+
if (isDraftModeEnabled({ searchParams: options.searchParams }) || isOnVercelPreviewEnvironment()) {
|
|
18
|
+
return -1;
|
|
19
|
+
}
|
|
20
|
+
const config = getServerConfig();
|
|
21
|
+
return 'routeRevalidateInterval' in config ? config.routeRevalidateInterval : undefined;
|
|
22
|
+
};
|
|
23
|
+
export const getServerConfig = () => {
|
|
24
|
+
let serverConfig;
|
|
25
|
+
try {
|
|
26
|
+
serverConfig = require('uniform.server.config.js');
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
serverConfig = {
|
|
30
|
+
defaultConsent: false,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return serverConfig;
|
|
34
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type UniformServerConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* Sets the default value of storage consent for new unknown visitors.
|
|
4
|
+
*
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
defaultConsent?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Interval to revalidate the manifest at.
|
|
10
|
+
*
|
|
11
|
+
* @default 60
|
|
12
|
+
*/
|
|
13
|
+
manifestRevalidateInterval?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Interval to revalidate route data at.
|
|
16
|
+
*
|
|
17
|
+
* @default 10
|
|
18
|
+
*/
|
|
19
|
+
routeRevalidateInterval?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Interval to revalidate canvas data at.
|
|
22
|
+
*
|
|
23
|
+
* @default 10
|
|
24
|
+
*/
|
|
25
|
+
canvasRevalidateInterval?: number;
|
|
26
|
+
/**
|
|
27
|
+
* 😅
|
|
28
|
+
*/
|
|
29
|
+
experimental?: {
|
|
30
|
+
/**
|
|
31
|
+
* Enables edge cache of redirects.
|
|
32
|
+
*
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
edgeRedirects?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Enables edge cache of compositions.
|
|
38
|
+
*
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
edgeCompositions?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Dynamic tokens names that should be used for localization.
|
|
44
|
+
*/
|
|
45
|
+
localeDynamicInputs?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Enables visual editing mode.
|
|
48
|
+
*/
|
|
49
|
+
vercelVisualEditing?: boolean;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the Uniform cookie with the provided value.
|
|
3
|
+
*/
|
|
4
|
+
export declare const setUniformCookie: (value: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Determine if the Uniform cookie is present.
|
|
7
|
+
*/
|
|
8
|
+
export declare const hasUniformCookie: () => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the Uniform cookie value.
|
|
11
|
+
*/
|
|
12
|
+
export declare const removeUniformCookie: () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
|
|
2
|
+
import Cookies from 'js-cookie';
|
|
3
|
+
/**
|
|
4
|
+
* Sets the Uniform cookie with the provided value.
|
|
5
|
+
*/
|
|
6
|
+
export const setUniformCookie = (value) => {
|
|
7
|
+
Cookies.set(UNIFORM_DEFAULT_COOKIE_NAME, value);
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Determine if the Uniform cookie is present.
|
|
11
|
+
*/
|
|
12
|
+
export const hasUniformCookie = () => {
|
|
13
|
+
const cookie = Cookies.get(UNIFORM_DEFAULT_COOKIE_NAME);
|
|
14
|
+
return Boolean(cookie);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Gets the Uniform cookie value.
|
|
18
|
+
*/
|
|
19
|
+
export const removeUniformCookie = () => {
|
|
20
|
+
Cookies.remove(UNIFORM_DEFAULT_COOKIE_NAME);
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createPreviewGETRouteHandler: () => (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CANVAS_DRAFT_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from '@uniformdev/canvas';
|
|
2
|
+
import { draftMode } from 'next/headers';
|
|
3
|
+
import { redirect } from 'next/navigation';
|
|
4
|
+
import { resolveRedirectHref, retrieveRoute } from '../components/retrieveRoute';
|
|
5
|
+
export const createPreviewGETRouteHandler = () => {
|
|
6
|
+
return async (request) => {
|
|
7
|
+
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
8
|
+
return new Response('No preview secret is configured', { status: 401 });
|
|
9
|
+
}
|
|
10
|
+
const { searchParams } = new URL(request.url);
|
|
11
|
+
const secret = searchParams.get('secret');
|
|
12
|
+
const path = searchParams.get('path');
|
|
13
|
+
if (secret !== process.env.UNIFORM_PREVIEW_SECRET) {
|
|
14
|
+
return new Response('Invalid preview secret', { status: 401 });
|
|
15
|
+
}
|
|
16
|
+
if (!path) {
|
|
17
|
+
return new Response('Path not provided', { status: 401 });
|
|
18
|
+
}
|
|
19
|
+
const resolveResult = await retrieveRoute({
|
|
20
|
+
path,
|
|
21
|
+
state: CANVAS_DRAFT_STATE,
|
|
22
|
+
searchParams: {
|
|
23
|
+
// about to be in draft mode so pretend for now.
|
|
24
|
+
[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]: 'true',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
draftMode().enable();
|
|
28
|
+
if (resolveResult.type === 'redirect') {
|
|
29
|
+
const href = resolveRedirectHref(resolveResult, path);
|
|
30
|
+
if (resolveResult.redirect.targetProjectMapNodeId) {
|
|
31
|
+
// do we need this query string param still with draft mode cookie?
|
|
32
|
+
redirect(`${href}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
redirect(href);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (resolveResult.type === 'notFound') {
|
|
39
|
+
return new Response('Invalid path', { status: 401 });
|
|
40
|
+
}
|
|
41
|
+
redirect(`${path}?${IN_CONTEXT_EDITOR_QUERY_STRING_PARAM}=true`);
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createPreviewPOSTRouteHandler: () => (request: Request) => Promise<Response>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CANVAS_DRAFT_STATE, generateHash } from '@uniformdev/canvas';
|
|
2
|
+
import { revalidateTag } from 'next/cache';
|
|
3
|
+
import { NextResponse } from 'next/server';
|
|
4
|
+
import { getCanvasClient } from '../client/canvasClient';
|
|
5
|
+
import { diff } from '../utils/diff';
|
|
6
|
+
import { isSvixMessage } from './helpers';
|
|
7
|
+
import { handleCompositionChanged } from './messages/handleCompositionChanged';
|
|
8
|
+
import { handleCompositionDeleted } from './messages/handleCompositionDeleted';
|
|
9
|
+
import { handleCompositionPublished } from './messages/handleCompositionPublished';
|
|
10
|
+
import { handleManifestPublished } from './messages/handleManifestPublished';
|
|
11
|
+
import { handleProjectMapNodeDelete } from './messages/handleProjectMapNodeDelete';
|
|
12
|
+
import { handleProjectMapNodeInsert } from './messages/handleProjectMapNodeInsert';
|
|
13
|
+
import { handleProjectMapNodeUpdate } from './messages/handleProjectMapNodeUpdate';
|
|
14
|
+
import { handleRedirectDelete } from './messages/handleRedirectDelete';
|
|
15
|
+
import { handleRedirectInsert } from './messages/handleRedirectInsert';
|
|
16
|
+
import { handleRedirectUpdate } from './messages/handleRedirectUpdate';
|
|
17
|
+
export const createPreviewPOSTRouteHandler = () => {
|
|
18
|
+
return async (request) => {
|
|
19
|
+
const { looksLikeMessage, validation } = await isSvixMessage(request);
|
|
20
|
+
if (looksLikeMessage) {
|
|
21
|
+
if (!validation) {
|
|
22
|
+
return new Response('This looks like a webhook request but the validation failed.', { status: 401 });
|
|
23
|
+
}
|
|
24
|
+
return handleSvixMessage(request);
|
|
25
|
+
}
|
|
26
|
+
if (!process.env.UNIFORM_PREVIEW_SECRET) {
|
|
27
|
+
return new Response('No preview secret is configured', { status: 401 });
|
|
28
|
+
}
|
|
29
|
+
const message = (await request.json());
|
|
30
|
+
if (!(message === null || message === void 0 ? void 0 : message.composition) || !(message === null || message === void 0 ? void 0 : message.hash)) {
|
|
31
|
+
return new Response('Invalid message', { status: 401 });
|
|
32
|
+
}
|
|
33
|
+
const { composition, hash } = message;
|
|
34
|
+
const calculatedHash = generateHash({
|
|
35
|
+
composition,
|
|
36
|
+
secret: process.env.UNIFORM_PREVIEW_SECRET,
|
|
37
|
+
});
|
|
38
|
+
if (hash !== calculatedHash) {
|
|
39
|
+
return new Response('Invalid hash', { status: 401 });
|
|
40
|
+
}
|
|
41
|
+
const canvasClient = await getCanvasClient();
|
|
42
|
+
const { composition: existingComposition } = await canvasClient.getCompositionById({
|
|
43
|
+
compositionId: composition._id,
|
|
44
|
+
state: CANVAS_DRAFT_STATE,
|
|
45
|
+
withComponentIDs: true,
|
|
46
|
+
});
|
|
47
|
+
const compositionDiff = diff(existingComposition, composition);
|
|
48
|
+
return NextResponse.json({
|
|
49
|
+
composition,
|
|
50
|
+
existingComposition,
|
|
51
|
+
diff: compositionDiff,
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
const handleSvixMessage = async (request) => {
|
|
56
|
+
const handlers = [
|
|
57
|
+
handleProjectMapNodeUpdate,
|
|
58
|
+
handleProjectMapNodeInsert,
|
|
59
|
+
handleProjectMapNodeDelete,
|
|
60
|
+
handleCompositionDeleted,
|
|
61
|
+
handleCompositionChanged,
|
|
62
|
+
handleCompositionPublished,
|
|
63
|
+
handleRedirectInsert,
|
|
64
|
+
handleRedirectUpdate,
|
|
65
|
+
handleRedirectDelete,
|
|
66
|
+
handleManifestPublished,
|
|
67
|
+
];
|
|
68
|
+
let tags = undefined;
|
|
69
|
+
const jsonBody = await request.json();
|
|
70
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
71
|
+
const handler = handlers[i];
|
|
72
|
+
const result = await handler(jsonBody);
|
|
73
|
+
if (result) {
|
|
74
|
+
tags = result.tags;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (tags === null || tags === void 0 ? void 0 : tags.length) {
|
|
79
|
+
for (let i = 0; i < tags.length; i++) {
|
|
80
|
+
const tag = tags[i];
|
|
81
|
+
revalidateTag(tag);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return new Response(JSON.stringify({
|
|
85
|
+
handled: typeof tags !== 'undefined',
|
|
86
|
+
tags,
|
|
87
|
+
}));
|
|
88
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createPreviewGETRouteHandler } from './createPreviewGETRouteHandler';
|
|
2
|
+
import { createPreviewPOSTRouteHandler } from './createPreviewPOSTRouteHandler';
|
|
3
|
+
export const createUniformRouteHandler = () => {
|
|
4
|
+
const GET = createPreviewGETRouteHandler();
|
|
5
|
+
const POST = createPreviewPOSTRouteHandler();
|
|
6
|
+
return {
|
|
7
|
+
GET,
|
|
8
|
+
POST,
|
|
9
|
+
};
|
|
10
|
+
};
|