@uniformdev/canvas-next-rsc 19.51.0 → 19.53.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/actions/updateContext.d.ts +2 -0
- package/dist/actions/updateContext.js +17 -0
- package/dist/components/DefaultNotImplementedComponent.d.ts +1 -1
- package/dist/components/GoogleTagManagerAnalytics.d.ts +1 -1
- package/dist/components/UniformComponent.d.ts +1 -0
- package/dist/components/UniformComposition.d.ts +7 -2
- package/dist/components/UniformComposition.js +5 -62
- package/dist/components/UniformContext.d.ts +1 -4
- package/dist/components/UniformRichTextNode.d.ts +1 -1
- package/dist/components/UniformScript.d.ts +1 -1
- package/dist/components/UniformText.d.ts +1 -1
- package/dist/components/__tests__/evaluateComposition.spec.js +11 -3
- package/dist/components/evaluateComposition.d.ts +3 -3
- package/dist/components/evaluateComposition.js +13 -11
- package/dist/components/getUniformContext.d.ts +6 -0
- package/dist/components/getUniformContext.js +16 -0
- package/dist/components/retrieveRoute.d.ts +131 -0
- package/dist/components/retrieveRoute.js +70 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +6 -1
- package/package.json +18 -16
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
|
|
3
|
+
import { cookies } from 'next/headers';
|
|
4
|
+
import { getUniformContext } from '../components/getUniformContext';
|
|
5
|
+
import { serializeCookie } from '../score';
|
|
6
|
+
export const updateContextAction = async (options) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const context = await getUniformContext({
|
|
9
|
+
cookieValue: (_a = cookies().get(UNIFORM_DEFAULT_COOKIE_NAME)) === null || _a === void 0 ? void 0 : _a.value,
|
|
10
|
+
});
|
|
11
|
+
if (!context.storage.data.consent) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
await context.update(options);
|
|
15
|
+
const scoreCookie = serializeCookie(context.storage.data);
|
|
16
|
+
cookies().set(UNIFORM_DEFAULT_COOKIE_NAME, scoreCookie);
|
|
17
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ComponentProps } from './UniformComponent';
|
|
2
|
-
export declare function DefaultNotImplementedComponent(props: ComponentProps): JSX.Element | null;
|
|
2
|
+
export declare function DefaultNotImplementedComponent(props: ComponentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -7,6 +7,7 @@ export type CompositionContext = Omit<RouteGetResponseComposition, 'compositionA
|
|
|
7
7
|
searchParams: {
|
|
8
8
|
[key: string]: string | undefined;
|
|
9
9
|
} | undefined;
|
|
10
|
+
cookieValue: string | undefined;
|
|
10
11
|
};
|
|
11
12
|
export type ComponentProps<TProps = unknown> = TProps & {
|
|
12
13
|
component: ComponentInstance;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ContextState } from '@uniformdev/context';
|
|
1
2
|
import { ReactNode } from 'react';
|
|
2
3
|
export type SuspenseOptions = {
|
|
3
4
|
mode: 'off';
|
|
@@ -25,11 +26,15 @@ export type UniformCompositionProps = {
|
|
|
25
26
|
mode: 'off';
|
|
26
27
|
} | {
|
|
27
28
|
mode: 'fallback';
|
|
28
|
-
fallback:
|
|
29
|
+
fallback: ReactNode;
|
|
29
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Update state that should be added to the call to update before composition evaluation
|
|
33
|
+
*/
|
|
34
|
+
update?: Partial<ContextState>;
|
|
30
35
|
/**
|
|
31
36
|
* The children of the UniformComposition component.
|
|
32
37
|
*/
|
|
33
38
|
children?: ReactNode;
|
|
34
39
|
};
|
|
35
|
-
export declare const UniformComposition: ({ suspense, ...props }: UniformCompositionProps) => JSX.Element;
|
|
40
|
+
export declare const UniformComposition: ({ suspense, ...props }: UniformCompositionProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, CANVAS_PUBLISHED_STATE } from '@uniformdev/canvas';
|
|
3
|
-
import { cookies, headers } from 'next/headers';
|
|
4
|
-
import { notFound, redirect } from 'next/navigation';
|
|
5
2
|
import { Suspense } from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import { isDevelopmentEnvironment, isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment, } from '../utils/draft';
|
|
8
|
-
import { evaluateComposition } from './evaluateComposition';
|
|
9
|
-
import { resolvePath } from './resolvePath';
|
|
10
|
-
import { resolveRedirectHref, retrieveRoute } from './retrieveRoute';
|
|
3
|
+
import { resolveComposition } from './retrieveRoute';
|
|
11
4
|
import { UniformComponent } from './UniformComponent';
|
|
12
5
|
import { UniformProvider } from './UniformContext';
|
|
13
6
|
import { UniformScript } from './UniformScript';
|
|
@@ -20,67 +13,17 @@ const ConditionalWrapper = ({ children, options }) => {
|
|
|
20
13
|
}
|
|
21
14
|
return _jsx(Suspense, { fallback: options.fallback, children: children });
|
|
22
15
|
};
|
|
23
|
-
const UniformCompositionInner = async ({ params, searchParams, children }) => {
|
|
24
|
-
|
|
25
|
-
void getManifestFromApi({
|
|
26
|
-
searchParams,
|
|
27
|
-
});
|
|
28
|
-
const draftMode = isDraftModeEnabled({ searchParams });
|
|
29
|
-
const previewEnvironment = isOnVercelPreviewEnvironment();
|
|
30
|
-
const isDevelopment = isDevelopmentEnvironment();
|
|
31
|
-
const isCanvasEditing = isIncontextEditingEnabled({
|
|
32
|
-
searchParams,
|
|
33
|
-
});
|
|
34
|
-
// resolve the path from provided params
|
|
35
|
-
const path = resolvePath({
|
|
16
|
+
const UniformCompositionInner = async ({ params, searchParams, update, children, }) => {
|
|
17
|
+
const { composition: evaluatedComposition, cookieValue, path, searchParams: evaluatedSearchParams, seenComponents, isCanvasEditing, ...rest } = await resolveComposition({
|
|
36
18
|
params,
|
|
37
|
-
});
|
|
38
|
-
let state;
|
|
39
|
-
if (isCanvasEditing) {
|
|
40
|
-
state = CANVAS_EDITOR_STATE;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
state = draftMode || previewEnvironment || isDevelopment ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
44
|
-
}
|
|
45
|
-
// resolve the route from the path
|
|
46
|
-
const resolveResult = await retrieveRoute({
|
|
47
|
-
path,
|
|
48
|
-
state,
|
|
49
19
|
searchParams,
|
|
50
|
-
|
|
51
|
-
// if the route is a redirect, redirect
|
|
52
|
-
if (resolveResult.type === 'redirect') {
|
|
53
|
-
const href = resolveRedirectHref(resolveResult, path);
|
|
54
|
-
redirect(href);
|
|
55
|
-
}
|
|
56
|
-
// if the route is not found, return 404
|
|
57
|
-
if (resolveResult.type === 'notFound') {
|
|
58
|
-
notFound();
|
|
59
|
-
}
|
|
60
|
-
const { compositionApiResponse, ...rest } = resolveResult;
|
|
61
|
-
// retrieve the manifest
|
|
62
|
-
const manifest = await getManifestFromApi({
|
|
63
|
-
searchParams,
|
|
64
|
-
});
|
|
65
|
-
// evaluate the composition
|
|
66
|
-
const { cookieValue, composition: evaluatedComposition, seenComponents, } = await evaluateComposition({
|
|
67
|
-
root: compositionApiResponse.composition,
|
|
68
|
-
params,
|
|
69
|
-
searchParams: searchParams !== null && searchParams !== void 0 ? searchParams : {},
|
|
70
|
-
dynamicInputs: rest.dynamicInputs,
|
|
71
|
-
manifest,
|
|
72
|
-
headers: headers(),
|
|
73
|
-
cookies: cookies()
|
|
74
|
-
.getAll()
|
|
75
|
-
.reduce((acc, cookie) => {
|
|
76
|
-
acc[cookie.name] = cookie.value;
|
|
77
|
-
return acc;
|
|
78
|
-
}, {}),
|
|
20
|
+
update,
|
|
79
21
|
});
|
|
80
22
|
const context = {
|
|
81
23
|
composition: evaluatedComposition,
|
|
82
24
|
path,
|
|
83
25
|
searchParams,
|
|
26
|
+
cookieValue,
|
|
84
27
|
...rest,
|
|
85
28
|
};
|
|
86
29
|
return (_jsxs(UniformProvider, { cookieValue: cookieValue, seenComponents: seenComponents, children: [_jsx(UniformScript, { enabled: isCanvasEditing }), _jsx(UniformComponent, { data: evaluatedComposition, context: context }), Boolean(children) && children] }));
|
|
@@ -5,7 +5,4 @@ export type UniformContextProps = {
|
|
|
5
5
|
seenComponents: SeenUniformComponent[] | undefined;
|
|
6
6
|
};
|
|
7
7
|
export declare const UniformContext: import("react").Context<UniformContextProps>;
|
|
8
|
-
export declare const UniformProvider: ({ children, cookieValue, seenComponents, }: PropsWithChildren<
|
|
9
|
-
cookieValue: string | undefined;
|
|
10
|
-
seenComponents: SeenUniformComponent[] | undefined;
|
|
11
|
-
}>) => JSX.Element;
|
|
8
|
+
export declare const UniformProvider: ({ children, cookieValue, seenComponents, }: PropsWithChildren<UniformContextProps>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,4 +7,4 @@ export type UniformRichTextNodeProps = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Render a single RichText node
|
|
9
9
|
*/
|
|
10
|
-
export declare function UniformRichTextNode({ node, ...props }: UniformRichTextNodeProps): JSX.Element | null;
|
|
10
|
+
export declare function UniformRichTextNode({ node, ...props }: UniformRichTextNodeProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -3,4 +3,4 @@ import { CompositionContext } from './UniformComponent';
|
|
|
3
3
|
export type UniformTextProps = {
|
|
4
4
|
context: CompositionContext;
|
|
5
5
|
} & Omit<PureUniformTextProps, 'skipCustomRendering' | 'isContextualEditing'>;
|
|
6
|
-
export declare const UniformText: ({ context, ...rest }: UniformTextProps) => JSX.Element;
|
|
6
|
+
export declare const UniformText: ({ context, ...rest }: UniformTextProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { CANVAS_LOCALE_TAG_PARAM, CANVAS_LOCALIZATION_SLOT, CANVAS_LOCALIZATION_TYPE, } from '@uniformdev/canvas';
|
|
2
|
+
import { Context } from '@uniformdev/context';
|
|
2
3
|
import { evaluateComposition } from '../evaluateComposition';
|
|
4
|
+
jest.mock('../getUniformContext', () => ({
|
|
5
|
+
getUniformContext: () => {
|
|
6
|
+
return new Context({
|
|
7
|
+
manifest: {
|
|
8
|
+
project: {},
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
3
13
|
describe('evaluateComposition', () => {
|
|
4
14
|
it('should localize a compoisition when dynmaic inputs include locale token', async () => {
|
|
5
15
|
var _a, _b;
|
|
@@ -61,9 +71,7 @@ describe('evaluateComposition', () => {
|
|
|
61
71
|
localeDynamicInputs: ['lang'],
|
|
62
72
|
},
|
|
63
73
|
},
|
|
64
|
-
|
|
65
|
-
project: {},
|
|
66
|
-
},
|
|
74
|
+
update: undefined,
|
|
67
75
|
});
|
|
68
76
|
const localizedHero = (_a = root.slots) === null || _a === void 0 ? void 0 : _a['content'][0];
|
|
69
77
|
expect(localizedHero).toBeDefined();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RootComponentInstance, RouteGetResponseComposition } from '@uniformdev/canvas';
|
|
2
|
-
import {
|
|
2
|
+
import { ContextState } from '@uniformdev/context';
|
|
3
3
|
import { UniformServerConfig } from '../config';
|
|
4
4
|
import { SeenUniformComponent } from '../models';
|
|
5
|
-
export declare const evaluateComposition: ({ root, params, searchParams, dynamicInputs,
|
|
5
|
+
export declare const evaluateComposition: ({ root, params, searchParams, dynamicInputs, headers, cookies, update, config, }: {
|
|
6
6
|
root: RootComponentInstance;
|
|
7
7
|
params: {
|
|
8
8
|
slug: string | string[];
|
|
@@ -11,9 +11,9 @@ export declare const evaluateComposition: ({ root, params, searchParams, dynamic
|
|
|
11
11
|
[key: string]: string | undefined;
|
|
12
12
|
};
|
|
13
13
|
dynamicInputs: RouteGetResponseComposition['dynamicInputs'];
|
|
14
|
-
manifest: ManifestV2;
|
|
15
14
|
headers: Headers;
|
|
16
15
|
cookies: Record<string, string>;
|
|
16
|
+
update: Partial<ContextState> | undefined;
|
|
17
17
|
config?: UniformServerConfig | undefined;
|
|
18
18
|
}) => Promise<{
|
|
19
19
|
composition: RootComponentInstance;
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_TYPE, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, walkComponentTree, } from '@uniformdev/canvas';
|
|
2
|
-
import {
|
|
2
|
+
import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
|
|
3
3
|
import serverConfig from '../config/uniform.server.config';
|
|
4
4
|
import { serializeCookie } from '../score';
|
|
5
5
|
import { isIncontextEditingEnabled } from '../utils/draft';
|
|
6
6
|
import { getBaseUrl } from '../utils/url';
|
|
7
7
|
import { getEnrichmentTags } from './getEnrichmentTags';
|
|
8
|
+
import { getUniformContext } from './getUniformContext';
|
|
8
9
|
import { resolvePath } from './resolvePath';
|
|
9
|
-
export const evaluateComposition = async ({ root, params, searchParams, dynamicInputs,
|
|
10
|
-
// retrieve the score from the cookie, if any
|
|
11
|
-
const score = cookies[UNIFORM_DEFAULT_COOKIE_NAME];
|
|
10
|
+
export const evaluateComposition = async ({ root, params, searchParams, dynamicInputs, headers, cookies, update, config = serverConfig, }) => {
|
|
12
11
|
// resolve the path from route params
|
|
13
12
|
const path = resolvePath({
|
|
14
13
|
params,
|
|
15
14
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
transitionStore: new CookieTransitionDataStore({
|
|
20
|
-
serverCookieValue: score,
|
|
21
|
-
}),
|
|
15
|
+
const context = await getUniformContext({
|
|
16
|
+
searchParams,
|
|
17
|
+
cookieValue: cookies[UNIFORM_DEFAULT_COOKIE_NAME] || undefined,
|
|
22
18
|
});
|
|
23
19
|
// generate the current URL for the request
|
|
24
20
|
const url = new URL(`${getBaseUrl()}${path}`);
|
|
@@ -28,15 +24,21 @@ export const evaluateComposition = async ({ root, params, searchParams, dynamicI
|
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
26
|
const missingQuirkValue = 'unknown';
|
|
27
|
+
const { cookies: updateCookies, quirks: updateQuirks, ...restOfUpdate } = update || {};
|
|
31
28
|
// update context to update scores
|
|
32
29
|
await context.update({
|
|
33
|
-
cookies
|
|
30
|
+
cookies: {
|
|
31
|
+
...cookies,
|
|
32
|
+
...(updateCookies || {}),
|
|
33
|
+
},
|
|
34
34
|
url,
|
|
35
35
|
quirks: {
|
|
36
36
|
'vc-country': headers.get('x-vercel-ip-country') || missingQuirkValue,
|
|
37
37
|
'vc-region': headers.get('x-vercel-ip-country-region') || missingQuirkValue,
|
|
38
38
|
'vc-city': headers.get('x-vercel-ip-city') || missingQuirkValue,
|
|
39
|
+
...(updateQuirks || {}),
|
|
39
40
|
},
|
|
41
|
+
...restOfUpdate,
|
|
40
42
|
});
|
|
41
43
|
const composition = root;
|
|
42
44
|
const resolvedLocaleKey = Object.keys(dynamicInputs || {}).find((key) => {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Context } from '@uniformdev/context';
|
|
2
|
+
import { UniformCompositionProps } from './UniformComposition';
|
|
3
|
+
export declare const getUniformContext: ({ searchParams, cookieValue, }: {
|
|
4
|
+
searchParams?: UniformCompositionProps['searchParams'];
|
|
5
|
+
cookieValue: string | undefined;
|
|
6
|
+
}) => Promise<Context>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Context, CookieTransitionDataStore } from '@uniformdev/context';
|
|
2
|
+
import { getManifestFromApi } from '../client/manifestClient';
|
|
3
|
+
import serverConfig from '../config/uniform.server.config';
|
|
4
|
+
export const getUniformContext = async ({ searchParams, cookieValue, }) => {
|
|
5
|
+
const manifest = await getManifestFromApi({
|
|
6
|
+
searchParams,
|
|
7
|
+
});
|
|
8
|
+
const context = new Context({
|
|
9
|
+
manifest,
|
|
10
|
+
defaultConsent: serverConfig.defaultConsent,
|
|
11
|
+
transitionStore: new CookieTransitionDataStore({
|
|
12
|
+
serverCookieValue: cookieValue,
|
|
13
|
+
}),
|
|
14
|
+
});
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ResolvedRouteGetResponse, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
2
|
+
import { UniformCompositionProps } from './UniformComposition';
|
|
2
3
|
export type ResolveRouteOptions = {
|
|
3
4
|
path: string;
|
|
4
5
|
state?: number;
|
|
@@ -6,5 +7,135 @@ export type ResolveRouteOptions = {
|
|
|
6
7
|
[key: string]: string | undefined;
|
|
7
8
|
} | undefined;
|
|
8
9
|
};
|
|
10
|
+
export declare const resolveComposition: ({ searchParams, params, update, }: Pick<UniformCompositionProps, 'searchParams' | 'params' | 'update'>) => Promise<{
|
|
11
|
+
type: "composition";
|
|
12
|
+
matchedRoute: string;
|
|
13
|
+
dynamicInputs?: {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
} | undefined;
|
|
16
|
+
composition: {
|
|
17
|
+
type: string;
|
|
18
|
+
parameters?: {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
value: unknown;
|
|
21
|
+
type: string;
|
|
22
|
+
connectedData?: {
|
|
23
|
+
pointer: string;
|
|
24
|
+
syntax: "jptr";
|
|
25
|
+
} | undefined;
|
|
26
|
+
};
|
|
27
|
+
} | undefined;
|
|
28
|
+
variant?: string | undefined;
|
|
29
|
+
projectMapNodes?: {
|
|
30
|
+
id: string;
|
|
31
|
+
path: string;
|
|
32
|
+
projectMapId: string;
|
|
33
|
+
}[] | undefined;
|
|
34
|
+
slots?: {
|
|
35
|
+
[key: string]: {
|
|
36
|
+
type: string;
|
|
37
|
+
parameters?: {
|
|
38
|
+
[key: string]: {
|
|
39
|
+
value: unknown;
|
|
40
|
+
type: string;
|
|
41
|
+
connectedData?: {
|
|
42
|
+
pointer: string;
|
|
43
|
+
syntax: "jptr";
|
|
44
|
+
} | undefined;
|
|
45
|
+
};
|
|
46
|
+
} | undefined;
|
|
47
|
+
variant?: string | undefined;
|
|
48
|
+
slots?: {
|
|
49
|
+
[key: string]: any[];
|
|
50
|
+
} | undefined;
|
|
51
|
+
_id?: string | undefined;
|
|
52
|
+
_pattern?: string | undefined;
|
|
53
|
+
_dataResources?: {
|
|
54
|
+
[key: string]: {
|
|
55
|
+
type: string;
|
|
56
|
+
isPatternParameter?: boolean | undefined;
|
|
57
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
58
|
+
variables?: {
|
|
59
|
+
[key: string]: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
};
|
|
62
|
+
} | undefined;
|
|
63
|
+
_patternDataResources?: {
|
|
64
|
+
[key: string]: {
|
|
65
|
+
type: string;
|
|
66
|
+
isPatternParameter?: boolean | undefined;
|
|
67
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
68
|
+
variables?: {
|
|
69
|
+
[key: string]: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
};
|
|
72
|
+
} | undefined;
|
|
73
|
+
_patternError?: "NOTFOUND" | "CYCLIC" | undefined;
|
|
74
|
+
_overrides?: {
|
|
75
|
+
[key: string]: {
|
|
76
|
+
parameters?: {
|
|
77
|
+
[key: string]: {
|
|
78
|
+
value: unknown;
|
|
79
|
+
type: string;
|
|
80
|
+
connectedData?: {
|
|
81
|
+
pointer: string;
|
|
82
|
+
syntax: "jptr";
|
|
83
|
+
} | undefined;
|
|
84
|
+
};
|
|
85
|
+
} | undefined;
|
|
86
|
+
variant?: string | undefined;
|
|
87
|
+
};
|
|
88
|
+
} | undefined;
|
|
89
|
+
_overridability?: {
|
|
90
|
+
parameters?: {
|
|
91
|
+
[key: string]: "yes" | "no";
|
|
92
|
+
} | undefined;
|
|
93
|
+
variants?: boolean | undefined;
|
|
94
|
+
} | undefined;
|
|
95
|
+
}[];
|
|
96
|
+
} | undefined;
|
|
97
|
+
_id: string;
|
|
98
|
+
_slug?: string | null | undefined;
|
|
99
|
+
_name: string;
|
|
100
|
+
_dataResources?: {
|
|
101
|
+
[key: string]: {
|
|
102
|
+
type: string;
|
|
103
|
+
isPatternParameter?: boolean | undefined;
|
|
104
|
+
ignorePatternParameterDefault?: boolean | undefined;
|
|
105
|
+
variables?: {
|
|
106
|
+
[key: string]: string;
|
|
107
|
+
} | undefined;
|
|
108
|
+
};
|
|
109
|
+
} | undefined;
|
|
110
|
+
_overrides?: {
|
|
111
|
+
[key: string]: {
|
|
112
|
+
parameters?: {
|
|
113
|
+
[key: string]: {
|
|
114
|
+
value: unknown;
|
|
115
|
+
type: string;
|
|
116
|
+
connectedData?: {
|
|
117
|
+
pointer: string;
|
|
118
|
+
syntax: "jptr";
|
|
119
|
+
} | undefined;
|
|
120
|
+
};
|
|
121
|
+
} | undefined;
|
|
122
|
+
variant?: string | undefined;
|
|
123
|
+
};
|
|
124
|
+
} | undefined;
|
|
125
|
+
_overridability?: {
|
|
126
|
+
parameters?: {
|
|
127
|
+
[key: string]: "yes" | "no";
|
|
128
|
+
} | undefined;
|
|
129
|
+
variants?: boolean | undefined;
|
|
130
|
+
} | undefined;
|
|
131
|
+
};
|
|
132
|
+
cookieValue: string | undefined;
|
|
133
|
+
path: string;
|
|
134
|
+
searchParams: {
|
|
135
|
+
[key: string]: string | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
isCanvasEditing: boolean;
|
|
138
|
+
seenComponents: import("../models").SeenUniformComponent[];
|
|
139
|
+
}>;
|
|
9
140
|
export declare const retrieveRoute: (data: ResolveRouteOptions) => Promise<ResolvedRouteGetResponse>;
|
|
10
141
|
export declare const resolveRedirectHref: (resolveResult: RouteGetResponseRedirect, path: string) => string;
|
|
@@ -1,12 +1,80 @@
|
|
|
1
|
-
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, } from '@uniformdev/canvas';
|
|
1
|
+
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, CANVAS_PUBLISHED_STATE, } from '@uniformdev/canvas';
|
|
2
2
|
import { RedirectClient } from '@uniformdev/redirect';
|
|
3
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';
|
|
4
7
|
import { getRouteClient } from '../client/routeClient';
|
|
5
8
|
import { getRouteRevalidateInterval } from '../config/helpers';
|
|
6
9
|
import config from '../config/uniform.server.config';
|
|
7
|
-
import { isOnVercelPreviewEnvironment } from '../utils/draft';
|
|
10
|
+
import { isDevelopmentEnvironment, isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment, } from '../utils/draft';
|
|
8
11
|
import { buildPathTag } from '../utils/tag';
|
|
9
12
|
import { getBaseUrl } from '../utils/url';
|
|
13
|
+
import { evaluateComposition } from './evaluateComposition';
|
|
14
|
+
import { resolvePath } from './resolvePath';
|
|
15
|
+
export const resolveComposition = async ({ searchParams, params, update, }) => {
|
|
16
|
+
// prefetch manifest immediately
|
|
17
|
+
void getManifestFromApi({
|
|
18
|
+
searchParams,
|
|
19
|
+
});
|
|
20
|
+
const draftMode = isDraftModeEnabled({ searchParams });
|
|
21
|
+
const previewEnvironment = isOnVercelPreviewEnvironment();
|
|
22
|
+
const isDevelopment = isDevelopmentEnvironment();
|
|
23
|
+
const isCanvasEditing = isIncontextEditingEnabled({
|
|
24
|
+
searchParams,
|
|
25
|
+
});
|
|
26
|
+
// resolve the path from provided params
|
|
27
|
+
const path = resolvePath({
|
|
28
|
+
params,
|
|
29
|
+
});
|
|
30
|
+
let state;
|
|
31
|
+
if (isCanvasEditing) {
|
|
32
|
+
state = CANVAS_EDITOR_STATE;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
state = draftMode || previewEnvironment || isDevelopment ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
36
|
+
}
|
|
37
|
+
// resolve the route from the path
|
|
38
|
+
const resolveResult = await retrieveRoute({
|
|
39
|
+
path,
|
|
40
|
+
state,
|
|
41
|
+
searchParams,
|
|
42
|
+
});
|
|
43
|
+
// if the route is a redirect, redirect
|
|
44
|
+
if (resolveResult.type === 'redirect') {
|
|
45
|
+
const href = resolveRedirectHref(resolveResult, path);
|
|
46
|
+
redirect(href);
|
|
47
|
+
}
|
|
48
|
+
// if the route is not found, return 404
|
|
49
|
+
if (resolveResult.type === 'notFound') {
|
|
50
|
+
notFound();
|
|
51
|
+
}
|
|
52
|
+
const { compositionApiResponse, ...rest } = resolveResult;
|
|
53
|
+
// evaluate the composition
|
|
54
|
+
const { cookieValue, composition: evaluatedComposition, seenComponents, } = await evaluateComposition({
|
|
55
|
+
root: compositionApiResponse.composition,
|
|
56
|
+
params,
|
|
57
|
+
searchParams: searchParams !== null && searchParams !== void 0 ? searchParams : {},
|
|
58
|
+
dynamicInputs: rest.dynamicInputs,
|
|
59
|
+
headers: headers(),
|
|
60
|
+
cookies: cookies()
|
|
61
|
+
.getAll()
|
|
62
|
+
.reduce((acc, cookie) => {
|
|
63
|
+
acc[cookie.name] = cookie.value;
|
|
64
|
+
return acc;
|
|
65
|
+
}, {}),
|
|
66
|
+
update,
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
composition: evaluatedComposition,
|
|
70
|
+
cookieValue,
|
|
71
|
+
path,
|
|
72
|
+
searchParams,
|
|
73
|
+
isCanvasEditing,
|
|
74
|
+
seenComponents,
|
|
75
|
+
...rest,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
10
78
|
export const retrieveRoute = async (data) => {
|
|
11
79
|
void resolveRouteByEdgeConfig(data);
|
|
12
80
|
void resolveRouteByRouteApi(data);
|
package/dist/index.d.ts
CHANGED
|
@@ -9,12 +9,15 @@ export { useToggleConsent } from './hooks/useToggleConsent';
|
|
|
9
9
|
export { useUniformContext } from './hooks/useUniformContext';
|
|
10
10
|
export { componentStore } from './register/componentStore';
|
|
11
11
|
export { registerUniformComponent } from './register/registerUniformComponent';
|
|
12
|
+
export { getUniformContext } from './components/getUniformContext';
|
|
12
13
|
export { getCanvasClient } from './client/canvasClient';
|
|
13
14
|
export { getManifestClient } from './client/manifestClient';
|
|
14
15
|
export { getProjectMapClient } from './client/projectMapClient';
|
|
15
16
|
export { getRouteClient } from './client/routeClient';
|
|
16
|
-
export
|
|
17
|
-
export
|
|
17
|
+
export { resolveComposition } from './components/retrieveRoute';
|
|
18
|
+
export { updateContextAction } from './actions/updateContext';
|
|
19
|
+
export declare const UniformComposition: (props: Omit<BaseUniformCompositionProps, 'suspense' | 'children' | 'update'>) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare const UniformCompositionCustom: (props: BaseUniformCompositionProps) => import("react/jsx-runtime").JSX.Element;
|
|
18
21
|
export { UniformRichText } from './components/UniformRichText';
|
|
19
22
|
export { isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment } from './utils/draft';
|
|
20
23
|
export { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, IN_CONTEXT_EDITOR_QUERY_STRING_PARAM, } from '@uniformdev/canvas';
|
package/dist/index.js
CHANGED
|
@@ -12,12 +12,17 @@ export { useUniformContext } from './hooks/useUniformContext';
|
|
|
12
12
|
// Component Registry
|
|
13
13
|
export { componentStore } from './register/componentStore';
|
|
14
14
|
export { registerUniformComponent } from './register/registerUniformComponent';
|
|
15
|
+
// Context
|
|
16
|
+
export { getUniformContext } from './components/getUniformContext';
|
|
15
17
|
// Clients
|
|
16
18
|
export { getCanvasClient } from './client/canvasClient';
|
|
17
19
|
export { getManifestClient } from './client/manifestClient';
|
|
18
20
|
export { getProjectMapClient } from './client/projectMapClient';
|
|
19
21
|
export { getRouteClient } from './client/routeClient';
|
|
20
|
-
export
|
|
22
|
+
export { resolveComposition } from './components/retrieveRoute';
|
|
23
|
+
// actions
|
|
24
|
+
export { updateContextAction } from './actions/updateContext';
|
|
25
|
+
export const UniformComposition = (props) => _jsx(BaseUniformComposition, { ...props });
|
|
21
26
|
export const UniformCompositionCustom = (props) => (_jsx(BaseUniformComposition, { ...props }));
|
|
22
27
|
export { UniformRichText } from './components/UniformRichText';
|
|
23
28
|
export { isDraftModeEnabled, isIncontextEditingEnabled, isOnVercelPreviewEnvironment } from './utils/draft';
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.53.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"dev": "
|
|
6
|
+
"dev": "tsc --watch",
|
|
7
7
|
"build": "tsc && node scripts/remove-export.js",
|
|
8
8
|
"lint": "eslint \"**/*.{ts,tsx}\" --fix",
|
|
9
9
|
"test": "jest --maxWorkers=1 --passWithNoTests"
|
|
@@ -48,33 +48,35 @@
|
|
|
48
48
|
"@types/gtag.js": "^0.0.13",
|
|
49
49
|
"@types/js-cookie": "^3.0.3",
|
|
50
50
|
"@types/node": "^18.0.0",
|
|
51
|
-
"@types/react": "^18.2.
|
|
51
|
+
"@types/react": "^18.2.20",
|
|
52
52
|
"eslint": "^8.11.0",
|
|
53
|
-
"next": "13.4.12",
|
|
53
|
+
"next": "^13.4.12",
|
|
54
54
|
"react": "18.2.0",
|
|
55
|
-
"react-dom": "18.2.0"
|
|
56
|
-
"typescript": "^5.0.4"
|
|
55
|
+
"react-dom": "18.2.0"
|
|
57
56
|
},
|
|
58
57
|
"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/richtext": "19.
|
|
65
|
-
"@uniformdev/webhooks": "19.
|
|
58
|
+
"@uniformdev/canvas": "19.53.0",
|
|
59
|
+
"@uniformdev/canvas-react": "19.53.0",
|
|
60
|
+
"@uniformdev/context": "19.53.0",
|
|
61
|
+
"@uniformdev/project-map": "19.53.0",
|
|
62
|
+
"@uniformdev/redirect": "19.53.0",
|
|
63
|
+
"@uniformdev/richtext": "19.53.0",
|
|
64
|
+
"@uniformdev/webhooks": "19.53.0",
|
|
66
65
|
"@vercel/edge-config": "^0.2.0",
|
|
67
66
|
"dequal": "^2.0.3",
|
|
68
67
|
"js-cookie": "^3.0.5",
|
|
69
68
|
"svix": "^1.5.0"
|
|
70
69
|
},
|
|
70
|
+
"engines": {
|
|
71
|
+
"node": ">=16.14.0"
|
|
72
|
+
},
|
|
71
73
|
"peerDependencies": {
|
|
72
74
|
"next": ">=13.4.7",
|
|
73
|
-
"react": ">=
|
|
74
|
-
"react-dom": ">=
|
|
75
|
+
"react": ">=18.2",
|
|
76
|
+
"react-dom": ">=18.2"
|
|
75
77
|
},
|
|
76
78
|
"publishConfig": {
|
|
77
79
|
"access": "public"
|
|
78
80
|
},
|
|
79
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "2f5a368ac31888a37da39c0e449b29b94c35c591"
|
|
80
82
|
}
|