@remkoj/optimizely-cms-nextjs 2.0.4 → 2.1.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/cms-page/page.d.ts +62 -5
- package/dist/cms-page/page.js +69 -41
- package/dist/cms-page/page.js.map +1 -1
- package/dist/cms-page/utils.d.ts +3 -2
- package/dist/cms-page/utils.js +22 -4
- package/dist/cms-page/utils.js.map +1 -1
- package/dist/ope/page.d.ts +0 -2
- package/dist/ope/page.js +6 -6
- package/dist/ope/page.js.map +1 -1
- package/dist/ope/types.d.ts +29 -2
- package/package.json +9 -9
package/dist/cms-page/page.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import 'server-only';
|
|
2
2
|
import type { Metadata, ResolvingMetadata } from 'next';
|
|
3
|
-
import { type
|
|
3
|
+
import { type IRouteResolver, type Route } from '@remkoj/optimizely-graph-client/router';
|
|
4
|
+
import { type ChannelDefinition } from '@remkoj/optimizely-graph-client/channels';
|
|
5
|
+
import { type ClientFactory, type IOptiGraphClient } from '@remkoj/optimizely-graph-client/client';
|
|
4
6
|
import { type ComponentFactory } from '@remkoj/optimizely-cms-react/rsc';
|
|
5
7
|
import { type GetContentByPathMethod } from './data.js';
|
|
6
8
|
export type DefaultCmsPageParams = {
|
|
7
9
|
path?: string[];
|
|
8
|
-
lang?: string;
|
|
9
10
|
};
|
|
10
11
|
export type DefaultCmsPageSearchParams = {};
|
|
11
12
|
export type DefaultCmsPageProps<TParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageParams, TSearchParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageSearchParams> = {
|
|
@@ -13,8 +14,28 @@ export type DefaultCmsPageProps<TParams extends Record<string, string | Array<st
|
|
|
13
14
|
searchParams: TSearchParams;
|
|
14
15
|
};
|
|
15
16
|
export type OptiCmsNextJsPage<TParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageParams, TSearchParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageSearchParams> = {
|
|
17
|
+
/**
|
|
18
|
+
* Default implementation for the `generateStaticParams` export of a
|
|
19
|
+
* Next.JS Page.
|
|
20
|
+
*
|
|
21
|
+
* @returns The list of routes that should be pre-rendered by Next.JS
|
|
22
|
+
*/
|
|
16
23
|
generateStaticParams: () => Promise<TParams[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Default implementation for the `generateMetadata` export, which builds
|
|
26
|
+
* the metadata for the given route within the Next.JS app.
|
|
27
|
+
*
|
|
28
|
+
* @param props The properties of the page
|
|
29
|
+
* @param resolving The metadata that is currently resolving
|
|
30
|
+
* @returns Updated metadat
|
|
31
|
+
*/
|
|
17
32
|
generateMetadata: (props: DefaultCmsPageProps<TParams, TSearchParams>, resolving: ResolvingMetadata) => Promise<Metadata>;
|
|
33
|
+
/**
|
|
34
|
+
* The actual component that performs the page rendering
|
|
35
|
+
*
|
|
36
|
+
* @param props The properties of the page
|
|
37
|
+
* @returns The component to render the page
|
|
38
|
+
*/
|
|
18
39
|
CmsPage: (props: DefaultCmsPageProps<TParams, TSearchParams>) => Promise<JSX.Element>;
|
|
19
40
|
};
|
|
20
41
|
export declare enum SystemLocales {
|
|
@@ -22,12 +43,48 @@ export declare enum SystemLocales {
|
|
|
22
43
|
Neutral = "NEUTRAL"
|
|
23
44
|
}
|
|
24
45
|
export type CreatePageOptions<LocaleEnum = SystemLocales, TParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageParams, TSearchParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageSearchParams> = {
|
|
25
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Main function used to retrieve the content by path
|
|
48
|
+
*/
|
|
26
49
|
getContentByPath: GetContentByPathMethod<LocaleEnum>;
|
|
50
|
+
/**
|
|
51
|
+
* The factory that should yield the GraphQL Client to be used within this
|
|
52
|
+
* page.
|
|
53
|
+
*/
|
|
27
54
|
client: ClientFactory;
|
|
55
|
+
/**
|
|
56
|
+
* The channel information used to resolve locales, domains and more
|
|
57
|
+
*/
|
|
28
58
|
channel?: ChannelDefinition;
|
|
59
|
+
/**
|
|
60
|
+
* Override the default RouteResolver that is used to discover the routes
|
|
61
|
+
* provided by the Optimizely CMS and to retrieve the content reference for
|
|
62
|
+
* each route.
|
|
63
|
+
*
|
|
64
|
+
* @param client The Optimizely GraphQL Client to use
|
|
65
|
+
* @returns The RouteResolver to use
|
|
66
|
+
*/
|
|
67
|
+
routerFactory: (client?: IOptiGraphClient) => IRouteResolver;
|
|
68
|
+
/**
|
|
69
|
+
* Take the props received by the CmsPage from Next.JS and tranform those
|
|
70
|
+
* into a path that will be understood by Optimizely CMS. The default
|
|
71
|
+
* implementation works with both `/[lang]/[[...path]]` as well as
|
|
72
|
+
* `/[[...path]]`
|
|
73
|
+
*
|
|
74
|
+
* @param props The Properties (slugs & search params) received
|
|
75
|
+
* by Next.JS
|
|
76
|
+
* @return The path to be retrieved from Router or getContentByPath
|
|
77
|
+
* function
|
|
78
|
+
*/
|
|
29
79
|
propsToCmsPath: (props: DefaultCmsPageProps<TParams, TSearchParams>) => string | null;
|
|
30
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Take the route from the Routing Service and transform that to the route
|
|
82
|
+
* params used by Next.JS. The default implementation assumes that the CMS
|
|
83
|
+
* routes will be handled by `/[[...path]]`
|
|
84
|
+
*
|
|
85
|
+
* @param route The Route retrieved from Optimizely Graph
|
|
86
|
+
* @returns The processed route
|
|
87
|
+
*/
|
|
31
88
|
routeToParams: (route: Route) => TParams;
|
|
32
89
|
};
|
|
33
90
|
/**
|
|
@@ -39,4 +96,4 @@ export type CreatePageOptions<LocaleEnum = SystemLocales, TParams extends Record
|
|
|
39
96
|
* @param options The page component generation options
|
|
40
97
|
* @returns The Optimizely CMS Page
|
|
41
98
|
*/
|
|
42
|
-
export declare function createPage<LocaleEnum = SystemLocales, TParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageParams, TSearchParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageSearchParams>(factory: ComponentFactory, options?: Partial<CreatePageOptions<LocaleEnum, TParams, TSearchParams>>): OptiCmsNextJsPage
|
|
99
|
+
export declare function createPage<LocaleEnum = SystemLocales, TParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageParams, TSearchParams extends Record<string, string | Array<string> | undefined> = DefaultCmsPageSearchParams>(factory: ComponentFactory, options?: Partial<CreatePageOptions<LocaleEnum, TParams, TSearchParams>>): OptiCmsNextJsPage<TParams, TSearchParams>;
|
package/dist/cms-page/page.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import 'server-only';
|
|
3
|
+
import { cache } from 'react';
|
|
3
4
|
import deepmerge from 'deepmerge';
|
|
4
5
|
import { notFound } from 'next/navigation.js';
|
|
5
|
-
import { RouteResolver } from '@remkoj/optimizely-graph-client';
|
|
6
|
+
import { RouteResolver } from '@remkoj/optimizely-graph-client/router';
|
|
7
|
+
import { OptiCmsSchema } from '@remkoj/optimizely-graph-client/client';
|
|
6
8
|
import { normalizeContentLinkWithLocale } from '@remkoj/optimizely-graph-client/utils';
|
|
9
|
+
// React Support
|
|
7
10
|
import { CmsContent, isDebug, getServerContext } from '@remkoj/optimizely-cms-react/rsc';
|
|
8
11
|
import { Utils } from '@remkoj/optimizely-cms-react';
|
|
12
|
+
// Within package
|
|
9
13
|
import { MetaDataResolver } from '../metadata.js';
|
|
10
14
|
import { urlToPath, localeToGraphLocale } from './utils.js';
|
|
11
15
|
import getContentByPathBase from './data.js';
|
|
@@ -16,12 +20,11 @@ export var SystemLocales;
|
|
|
16
20
|
SystemLocales["Neutral"] = "NEUTRAL";
|
|
17
21
|
})(SystemLocales || (SystemLocales = {}));
|
|
18
22
|
const CreatePageOptionDefaults = {
|
|
19
|
-
defaultLocale: null,
|
|
20
23
|
getContentByPath: getContentByPathBase,
|
|
21
24
|
client: getServerClient,
|
|
25
|
+
routerFactory: (client) => new RouteResolver(client),
|
|
22
26
|
propsToCmsPath: ({ params }) => buildRequestPath(params),
|
|
23
|
-
|
|
24
|
-
routeToParams: (route) => { return { path: urlToPath(route.url, route.locale), lang: route.locale }; }
|
|
27
|
+
routeToParams: (route) => { return { path: urlToPath(route.url), lang: route.locale }; }
|
|
25
28
|
};
|
|
26
29
|
/**
|
|
27
30
|
* Generate the React Server Side component and Next.JS functions needed to render an
|
|
@@ -33,42 +36,57 @@ const CreatePageOptionDefaults = {
|
|
|
33
36
|
* @returns The Optimizely CMS Page
|
|
34
37
|
*/
|
|
35
38
|
export function createPage(factory, options) {
|
|
36
|
-
|
|
39
|
+
// Build the global/shared configuration for the Optimizely CMS Page
|
|
40
|
+
const { getContentByPath, client: clientFactory, channel, propsToCmsPath, routeToParams, routerFactory } = {
|
|
37
41
|
...CreatePageOptionDefaults,
|
|
38
42
|
...options
|
|
39
43
|
};
|
|
44
|
+
// Create the global Graph Client
|
|
40
45
|
const globalClient = clientFactory();
|
|
46
|
+
// Create the global Router instance
|
|
47
|
+
const router = routerFactory(globalClient);
|
|
48
|
+
const getInfoByPath = cache(async (requestPath, siteId) => {
|
|
49
|
+
const route = await router.getContentInfoByPath(requestPath, siteId);
|
|
50
|
+
if (!route)
|
|
51
|
+
return undefined;
|
|
52
|
+
const contentLink = router.routeToContentLink(route);
|
|
53
|
+
const contentType = route.contentType;
|
|
54
|
+
const graphLocale = localeToGraphLocale(route.locale, channel);
|
|
55
|
+
return [route, contentLink, contentType, graphLocale];
|
|
56
|
+
});
|
|
41
57
|
const pageDefintion = {
|
|
42
|
-
generateStaticParams: async () =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
generateMetadata: async (props, resolving) => {
|
|
48
|
-
// Read variables from request
|
|
49
|
-
//const client = clientFactory()
|
|
58
|
+
generateStaticParams: async () => (await router.getRoutes()).map(r => routeToParams(r)),
|
|
59
|
+
generateMetadata: async (props, parent) => {
|
|
60
|
+
// Read variables from request
|
|
61
|
+
const siteId = channel ? (globalClient.currentOptiCmsSchema == OptiCmsSchema.CMS12 ? channel.id : channel.defaultDomain) : undefined;
|
|
50
62
|
const requestPath = propsToCmsPath(props);
|
|
51
63
|
if (!requestPath)
|
|
52
64
|
return Promise.resolve({});
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
if (isDebug())
|
|
66
|
+
console.log(`⚪ [CmsPage.generateMetadata] Processed Next.JS route: ${JSON.stringify(props)} => Optimizely CMS route: ${JSON.stringify({ path: requestPath, siteId })}`);
|
|
55
67
|
// Resolve the route to a content link
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
68
|
+
const routeInfo = await getInfoByPath(requestPath, siteId);
|
|
69
|
+
if (!routeInfo) {
|
|
70
|
+
if (isDebug())
|
|
71
|
+
console.log('⚪ [CmsPage.generateMetadata] No data received');
|
|
58
72
|
return Promise.resolve({});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
}
|
|
74
|
+
const [route, contentLink, contentType, graphLocale] = routeInfo;
|
|
75
|
+
if (isDebug())
|
|
76
|
+
console.log(`⚪ [CmsPage.generateMetadata] Retrieved content info:`, route);
|
|
77
|
+
// Update context
|
|
78
|
+
const context = getServerContext();
|
|
79
|
+
context.setOptimizelyGraphClient(globalClient);
|
|
80
|
+
context.setComponentFactory(factory);
|
|
81
|
+
context.setLocale(route.locale);
|
|
67
82
|
// Fetch the metadata based upon the actual content type and resolve parent
|
|
83
|
+
const metaResolver = new MetaDataResolver(globalClient);
|
|
68
84
|
const [pageMetadata, baseMetadata] = await Promise.all([
|
|
69
85
|
metaResolver.resolve(factory, contentLink, contentType, graphLocale),
|
|
70
|
-
|
|
86
|
+
parent
|
|
71
87
|
]);
|
|
88
|
+
if (isDebug())
|
|
89
|
+
console.log(`⚪ [CmsPage.generateMetadata] Component yielded metadata:`, pageMetadata);
|
|
72
90
|
// Make sure merging of objects goes correctly
|
|
73
91
|
for (const metaKey of Object.getOwnPropertyNames(pageMetadata)) {
|
|
74
92
|
if (typeof (pageMetadata[metaKey]) == "object" && pageMetadata[metaKey] != null && baseMetadata[metaKey] != undefined && baseMetadata[metaKey] != null) {
|
|
@@ -85,23 +103,23 @@ export function createPage(factory, options) {
|
|
|
85
103
|
CmsPage: async (props) => {
|
|
86
104
|
// Prepare the context
|
|
87
105
|
const context = getServerContext();
|
|
88
|
-
|
|
89
|
-
if (!context.client)
|
|
90
|
-
context.setOptimizelyGraphClient(client);
|
|
106
|
+
context.setOptimizelyGraphClient(globalClient);
|
|
91
107
|
context.setComponentFactory(factory);
|
|
92
108
|
// Analyze the Next.JS Request props
|
|
93
|
-
const requestLocale = propsToCmsLocale(props, defaultLocale);
|
|
94
109
|
const requestPath = propsToCmsPath(props);
|
|
95
110
|
if (isDebug())
|
|
96
|
-
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(props)} => Optimizely CMS route: ${JSON.stringify({ path: requestPath
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
if (requestLocale)
|
|
100
|
-
context.setLocale(requestLocale);
|
|
101
|
-
// Resolve the content based upon the path
|
|
102
|
-
if (!requestPath)
|
|
111
|
+
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(props)} => Optimizely CMS route: ${JSON.stringify({ path: requestPath })}`);
|
|
112
|
+
// If we don't have the path, or the path is an internal Next.JS route reject it.
|
|
113
|
+
if (!requestPath || requestPath.startsWith('/_next/'))
|
|
103
114
|
return notFound();
|
|
104
|
-
|
|
115
|
+
// Resolve the content based upon the path
|
|
116
|
+
const requestVars = {
|
|
117
|
+
path: requestPath,
|
|
118
|
+
siteId: channel ? (globalClient.currentOptiCmsSchema == OptiCmsSchema.CMS12 ? channel.id : getPrimaryURL(channel).href) : null
|
|
119
|
+
};
|
|
120
|
+
if (isDebug())
|
|
121
|
+
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(props)} => getContentByPath Variables: ${JSON.stringify(requestVars)}`);
|
|
122
|
+
const response = await getContentByPath(globalClient, requestVars);
|
|
105
123
|
const info = (response?.content?.items ?? [])[0];
|
|
106
124
|
if (!info) {
|
|
107
125
|
if (isDebug()) {
|
|
@@ -109,15 +127,18 @@ export function createPage(factory, options) {
|
|
|
109
127
|
}
|
|
110
128
|
return notFound();
|
|
111
129
|
}
|
|
130
|
+
else if (isDebug() && (response?.content?.items ?? []).length > 1) {
|
|
131
|
+
console.warn(`🟠 [CmsPage] Resolving content for ${requestPath}, yielded ${(response?.content?.items ?? []).length} items, picked:`, info);
|
|
132
|
+
}
|
|
112
133
|
// Extract the type & link
|
|
113
134
|
const contentType = Utils.normalizeContentType(info._metadata?.types);
|
|
114
135
|
const contentLink = normalizeContentLinkWithLocale(info._metadata);
|
|
115
|
-
if (contentLink?.locale)
|
|
116
|
-
context.setLocale(contentLink?.locale);
|
|
117
136
|
if (!contentLink) {
|
|
118
137
|
console.error("🔴 [CmsPage] Unable to infer the contentLink from the retrieved content, this should not have happened!");
|
|
119
138
|
return notFound();
|
|
120
139
|
}
|
|
140
|
+
if (contentLink?.locale)
|
|
141
|
+
context.setLocale(contentLink?.locale);
|
|
121
142
|
// Render the content link
|
|
122
143
|
return _jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: info });
|
|
123
144
|
}
|
|
@@ -138,9 +159,16 @@ function buildRequestPath({ lang, path }) {
|
|
|
138
159
|
slugs.unshift(lang);
|
|
139
160
|
if (slugs.length == 0)
|
|
140
161
|
return '/';
|
|
141
|
-
const fullPath = '/' + slugs.filter(x => x && x.length > 0).join('/');
|
|
162
|
+
const fullPath = '/' + slugs.filter(x => x && x.length > 0).map(x => decodeURIComponent(x)).join('/');
|
|
142
163
|
if (!slugs[slugs.length - 1].includes('.'))
|
|
143
164
|
return fullPath + '/';
|
|
144
165
|
return fullPath;
|
|
145
166
|
}
|
|
167
|
+
function getPrimaryURL(chnl) {
|
|
168
|
+
const dd = chnl.domains.filter(x => x.isPrimary).at(0) ?? chnl.domains.at(0);
|
|
169
|
+
if (!dd)
|
|
170
|
+
return chnl.getPrimaryDomain();
|
|
171
|
+
const s = dd.name.startsWith('localhost') || dd.name.indexOf('.local') > 0 ? 'http:' : 'https:';
|
|
172
|
+
return new URL(`${s}//${dd.name}`);
|
|
173
|
+
}
|
|
146
174
|
//# sourceMappingURL=page.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/cms-page/page.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/cms-page/page.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAEpB,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,SAAS,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAI7C,OAAO,EAAE,aAAa,EAAmC,MAAM,wCAAwC,CAAA;AAEvG,OAAO,EAA6C,aAAa,EAAE,MAAM,wCAAwC,CAAA;AACjH,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,gBAAgB;AAChB,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAyB,MAAM,kCAAkC,CAAA;AAC/G,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAEpD,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,oBAAqD,MAAM,WAAW,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AA8C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,IAAI,CAAC,EAAE;QACH,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAA;IAClC,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAA;IAC/F,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;AACtC,CAAC"}
|
package/dist/cms-page/utils.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ export declare function urlToPath(baseUrl: URL, language?: string): string[];
|
|
|
10
10
|
* @returns
|
|
11
11
|
*/
|
|
12
12
|
export declare function localeToGraphLocale(locale: string, channel?: ChannelDefinition): string;
|
|
13
|
-
export declare function slugToLocale<T extends string | undefined | null>(channel: ChannelDefinition, slug: string, defaultValue: T): string | T;
|
|
14
|
-
export declare function slugToGraphLocale<T extends string | undefined | null>(channel: ChannelDefinition, slug: string, defaultValue: T): string | T;
|
|
13
|
+
export declare function slugToLocale<T extends string | undefined | null>(channel: ChannelDefinition | undefined, slug: string | null, defaultValue: T): string | T;
|
|
14
|
+
export declare function slugToGraphLocale<T extends string | undefined | null>(channel: ChannelDefinition | undefined, slug: string | null, defaultValue: T): string | T;
|
|
15
|
+
export declare function localeToSlug<T>(channel: ChannelDefinition | undefined, locale: T): string;
|
package/dist/cms-page/utils.js
CHANGED
|
@@ -19,11 +19,29 @@ export function localeToGraphLocale(locale, channel) {
|
|
|
19
19
|
return channel?.localeToGraphLocale(locale) ?? coreLocaleToGraphLocale(locale);
|
|
20
20
|
}
|
|
21
21
|
export function slugToLocale(channel, slug, defaultValue) {
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
if (!slug)
|
|
23
|
+
return defaultValue;
|
|
24
|
+
if (!channel) {
|
|
25
|
+
let parsedSlug = slug.replaceAll('_', '-').split('-').map((x, i) => i == 1 ? x.toUpperCase() : x.toLowerCase()).join('-');
|
|
26
|
+
return parsedSlug;
|
|
27
|
+
}
|
|
28
|
+
const locale = channel.slugToLocale(slug);
|
|
29
|
+
return locale || defaultValue?.replaceAll("_", "-");
|
|
24
30
|
}
|
|
25
31
|
export function slugToGraphLocale(channel, slug, defaultValue) {
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
if (!slug)
|
|
33
|
+
return defaultValue;
|
|
34
|
+
if (!channel) {
|
|
35
|
+
let parsedSlug = slug.replaceAll('_', '-').split('-').map((x, i) => i == 1 ? x.toUpperCase() : x.toLowerCase()).join('_');
|
|
36
|
+
return parsedSlug;
|
|
37
|
+
}
|
|
38
|
+
const graphLocale = channel.slugToGraphLocale(slug);
|
|
39
|
+
return graphLocale || defaultValue?.replaceAll("-", "_");
|
|
40
|
+
}
|
|
41
|
+
export function localeToSlug(channel, locale) {
|
|
42
|
+
const baseSlug = locale.toLowerCase().replaceAll('_', '-');
|
|
43
|
+
if (!channel)
|
|
44
|
+
return baseSlug;
|
|
45
|
+
return channel.localeToSlug(locale) ?? baseSlug;
|
|
28
46
|
}
|
|
29
47
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/cms-page/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,IAAI,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAEtG,oDAAoD;AACpD,MAAM,UAAU,SAAS,CAAC,OAAY,EAAE,QAAiB;IACrD,IAAI,KAAK,GAAc,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACjE,IAAI,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,QAAQ;QAChC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACzB,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AAC7D,CAAC"}
|
package/dist/ope/page.d.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { type ComponentFactory } from '@remkoj/optimizely-cms-react/rsc';
|
|
|
5
5
|
* Create the EditPage component needed by Next.JS to render the "On Page
|
|
6
6
|
* Editing" variant of the content item selected by the editor.
|
|
7
7
|
*
|
|
8
|
-
* @param dxpUrl The domain of the CMS instance
|
|
9
|
-
* @param client The Apollo GraphQL client to use
|
|
10
8
|
* @param factory The component factory to be used
|
|
11
9
|
* @param options The optional options to use to control the edit page
|
|
12
10
|
* @returns The React Component that can be used by Next.JS to render the page
|
package/dist/ope/page.js
CHANGED
|
@@ -15,30 +15,30 @@ const defaultOptions = {
|
|
|
15
15
|
layout: props => _jsx(_Fragment, { children: props.children }),
|
|
16
16
|
loader: getContentById,
|
|
17
17
|
clientFactory: (token) => getAuthorizedServerClient(token),
|
|
18
|
-
communicationInjectorPath: '/util/javascript/communicationinjector.js'
|
|
18
|
+
communicationInjectorPath: '/util/javascript/communicationinjector.js',
|
|
19
|
+
contentResolver: getContentRequest,
|
|
20
|
+
requestValidator: isValidRequest
|
|
19
21
|
};
|
|
20
22
|
/**
|
|
21
23
|
* Create the EditPage component needed by Next.JS to render the "On Page
|
|
22
24
|
* Editing" variant of the content item selected by the editor.
|
|
23
25
|
*
|
|
24
|
-
* @param dxpUrl The domain of the CMS instance
|
|
25
|
-
* @param client The Apollo GraphQL client to use
|
|
26
26
|
* @param factory The component factory to be used
|
|
27
27
|
* @param options The optional options to use to control the edit page
|
|
28
28
|
* @returns The React Component that can be used by Next.JS to render the page
|
|
29
29
|
*/
|
|
30
30
|
export function createEditPageComponent(factory, options) {
|
|
31
|
-
const { layout: PageLayout, refreshNotice: RefreshNotice, loader: getContentById, clientFactory, communicationInjectorPath } = { ...defaultOptions, ...options };
|
|
31
|
+
const { layout: PageLayout, refreshNotice: RefreshNotice, loader: getContentById, clientFactory, communicationInjectorPath, contentResolver: resolveContent, requestValidator: validateRequest } = { ...defaultOptions, ...options };
|
|
32
32
|
async function EditPage(props) {
|
|
33
33
|
// Create context
|
|
34
34
|
const context = getServerContext();
|
|
35
35
|
// Validate the search parameters
|
|
36
|
-
if (!
|
|
36
|
+
if (!validateRequest(props, false, context.isDevelopment)) {
|
|
37
37
|
console.error("🔴 [OnPageEdit] Invalid edit mode request");
|
|
38
38
|
return notFound();
|
|
39
39
|
}
|
|
40
40
|
// Get the requested content item
|
|
41
|
-
const contentRequestInfo =
|
|
41
|
+
const contentRequestInfo = resolveContent(props);
|
|
42
42
|
if (!contentRequestInfo) {
|
|
43
43
|
console.error("🔴 [OnPageEdit] Unable to resolve requested content");
|
|
44
44
|
return notFound();
|
package/dist/ope/page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/ope/page.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAGpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAA;AAC3E,OAAO,EAAE,KAAK,EAA8B,MAAM,8BAA8B,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAyB,MAAM,kCAAkC,CAAA;AACtG,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,UAAU,MAAM,+BAA+B,CAAA;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,MAAM,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE9D,MAAM,cAAc,GAAqB;IACrC,aAAa,EAAE,GAAG,EAAE,CAAC,mBAAK;IAC1B,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,4BAAI,KAAK,CAAC,QAAQ,GAAK;IACxC,MAAM,EAAE,cAAc;IACt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d.ts
CHANGED
|
@@ -60,11 +60,18 @@ export type EditViewOptions = {
|
|
|
60
60
|
locale: string;
|
|
61
61
|
}>>;
|
|
62
62
|
/**
|
|
63
|
-
* The
|
|
63
|
+
* The fourth step of the handling of a Preview/On-Page-Edit view,
|
|
64
|
+
* which actually loads the data of content to be shown to the
|
|
65
|
+
* editor.
|
|
64
66
|
*/
|
|
65
67
|
loader: GetContentByIdMethod;
|
|
66
68
|
/**
|
|
67
|
-
* The
|
|
69
|
+
* The third step of the handling of a Preview/On-Page-Edit view,
|
|
70
|
+
* which gets the Optimizely Graph client for the token/auth method
|
|
71
|
+
* inferred by the contentResolver.
|
|
72
|
+
*
|
|
73
|
+
* @param token The token to be used
|
|
74
|
+
* @returns The Optimizely Graph Client
|
|
68
75
|
*/
|
|
69
76
|
clientFactory: ClientFactory;
|
|
70
77
|
/**
|
|
@@ -72,6 +79,26 @@ export type EditViewOptions = {
|
|
|
72
79
|
* path.
|
|
73
80
|
*/
|
|
74
81
|
communicationInjectorPath: string;
|
|
82
|
+
/**
|
|
83
|
+
* The second step of the handling of a Preview/On-Page-Edit view,
|
|
84
|
+
* this actually extracts the requested content identification info
|
|
85
|
+
* from the path and search params
|
|
86
|
+
*
|
|
87
|
+
* @param props The page path props and search params
|
|
88
|
+
* @returns The requested content information
|
|
89
|
+
*/
|
|
90
|
+
contentResolver: (props: ValidatedEditPageProps) => ContentRequest | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* This is the first step of the handling of a Preview/On-Page-Edit view,
|
|
93
|
+
* where the parameters should be validated to ensure this is a correct
|
|
94
|
+
* preview/on-page-edit request.
|
|
95
|
+
*
|
|
96
|
+
* @param props The page path props and search params
|
|
97
|
+
* @param throwOnInvalid Whether an error must thrown on invalid data
|
|
98
|
+
* @param isDevelopment Whether this request runs in development mode
|
|
99
|
+
* @returns If the request is valid
|
|
100
|
+
*/
|
|
101
|
+
requestValidator: (props: EditPageProps, throwOnInvalid?: boolean, isDevelopment?: boolean) => props is ValidatedEditPageProps;
|
|
75
102
|
};
|
|
76
103
|
export type GetContentByIdData<LocaleType = string> = {
|
|
77
104
|
content: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-cms-nextjs",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"packageManager": "yarn@4.1.1",
|
|
6
6
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
7
7
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
@@ -36,26 +36,26 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@remkoj/optimizely-cms-react": "2.0
|
|
40
|
-
"@remkoj/optimizely-graph-client": "2.0
|
|
41
|
-
"@types/node": "^22.
|
|
42
|
-
"@types/react": "^18.3.
|
|
39
|
+
"@remkoj/optimizely-cms-react": "2.1.0",
|
|
40
|
+
"@remkoj/optimizely-graph-client": "2.1.0",
|
|
41
|
+
"@types/node": "^22.7.4",
|
|
42
|
+
"@types/react": "^18.3.11",
|
|
43
43
|
"@types/react-dom": "18.3.0",
|
|
44
44
|
"graphql": "^16.9.0",
|
|
45
45
|
"graphql-request": "^6.1.0",
|
|
46
|
-
"next": "^14.2.
|
|
46
|
+
"next": "^14.2.14",
|
|
47
47
|
"prop-types": "^15.8.1",
|
|
48
48
|
"react": "^18.3.1",
|
|
49
49
|
"react-dom": "^18.3.1",
|
|
50
50
|
"scheduler": "^0.23.2",
|
|
51
|
-
"typescript": "^5.
|
|
51
|
+
"typescript": "^5.6.2"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"deepmerge": "^4.3.1"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@remkoj/optimizely-cms-react": "2.0
|
|
58
|
-
"@remkoj/optimizely-graph-client": "2.0
|
|
57
|
+
"@remkoj/optimizely-cms-react": "2.1.0",
|
|
58
|
+
"@remkoj/optimizely-graph-client": "2.1.0",
|
|
59
59
|
"graphql": "^16",
|
|
60
60
|
"graphql-request": "^6",
|
|
61
61
|
"next": "^14",
|