@remkoj/optimizely-cms-nextjs 4.1.0 → 4.3.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/README.md +79 -2
- package/dist/cms-page/index.d.ts +1 -0
- package/dist/cms-page/index.js +1 -0
- package/dist/cms-page/index.js.map +1 -1
- package/dist/cms-page/middleware.d.ts +12 -0
- package/dist/cms-page/middleware.js +44 -0
- package/dist/cms-page/middleware.js.map +1 -0
- package/dist/cms-page/page.d.ts +9 -0
- package/dist/cms-page/page.js +49 -27
- package/dist/cms-page/page.js.map +1 -1
- package/dist/components/on-page-edit.d.ts +3 -1
- package/dist/components/on-page-edit.js +21 -10
- package/dist/components/on-page-edit.js.map +1 -1
- package/dist/ope/page.js +24 -18
- package/dist/ope/page.js.map +1 -1
- package/dist/ope/types.d.ts +6 -0
- package/dist/publish/index.d.ts +26 -3
- package/dist/publish/index.js +35 -17
- package/dist/publish/index.js.map +1 -1
- package/package.json +19 -11
package/README.md
CHANGED
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
# Optimizely SaaS CMS Next.
|
|
2
|
-
|
|
1
|
+
# Optimizely SaaS CMS - Next.js Integration
|
|
2
|
+
[](./LICENSE)
|
|
3
|
+
|
|
4
|
+
> [!TIP]
|
|
5
|
+
> Looking to implement a new Next.js based site with Optimizely SaaS CMS? The easiest way to get started is our [project template]([http](https://github.com/remkoj/optimizely-saas-starter)).
|
|
6
|
+
|
|
7
|
+
This package provides the needed components to implement a Next.js based frontedn for Optimizely SaaS CMS, with full support for the preview capabilities of Optimizely CMS.
|
|
8
|
+
|
|
9
|
+
[Release notes](https://github.com/remkoj/optimizely-dxp-clients/releases)
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
### Catch-all route rendering
|
|
13
|
+
Default implementation of the Catch-All route in Next.js to allow rendering any page created and managed by editors.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// In `src/app/[[...path]]/page.tsx`
|
|
17
|
+
|
|
18
|
+
import { CmsPage as OptimizelyCmsPage } from "@remkoj/optimizely-cms-nextjs"
|
|
19
|
+
import getFactory from '@/components/factory' // Or any other file where you have your component factory defined.
|
|
20
|
+
import { getContentByPath } from "@/gql/functions" // Or any other file that has the `getContentByPath` function
|
|
21
|
+
|
|
22
|
+
const { CmsPage, generateMetadata, generateStaticParams } = OptimizelyCmsPage.createPage(getFactory(), {
|
|
23
|
+
getContentByPath: getContentByPath
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Configure the Next.JS route handling for the pages
|
|
27
|
+
export const dynamic = "error"; // Make sure we're leveraging SSG for CMS managed pages.
|
|
28
|
+
export const dynamicParams = true; // Allow new pages to be resolved without rebuilding the site.
|
|
29
|
+
export const revalidate = false; // Keep the cache untill manually revalidated using the Webhook.
|
|
30
|
+
export const fetchCache = "default-cache"; // Cache fetch results by default, while allowing an opt-out.
|
|
31
|
+
|
|
32
|
+
// Export CMS Page
|
|
33
|
+
export {
|
|
34
|
+
generateMetadata,
|
|
35
|
+
generateStaticParams
|
|
36
|
+
}
|
|
37
|
+
export default CmsPage
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The `createPage` method has many more options allowing you to take control over what is happening while the page renders. The options object has built-in documentation that your IDE can show if you've got JavaScript / TypeScript language support enabled.
|
|
41
|
+
|
|
42
|
+
### Cache invalidation
|
|
43
|
+
Default implementation to handle webhooks from Optimizely Graph to purge the Next.js cache based upon taht incoming request.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// In `src/app/api/content/publish/route.ts`
|
|
47
|
+
|
|
48
|
+
import createPublishApi from '@remkoj/optimizely-cms-nextjs/publish'
|
|
49
|
+
|
|
50
|
+
const publishApi = createPublishApi(
|
|
51
|
+
{
|
|
52
|
+
paths: [ '/', '/[[...path]]', '/sitemap.xml' ] // The list of fall-back paths to flush,
|
|
53
|
+
optimizePublish: true // Use the data received from Graph to selectively flush the cache
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
// Configure the Next.JS route handling for the pages
|
|
58
|
+
export const dynamic = 'force-dynamic' // Make sure all API-Requests are executed
|
|
59
|
+
export const dynamicParams = true // Make sure all matching routes are always executed
|
|
60
|
+
export const revalidate = 0 // Don't cache
|
|
61
|
+
export const fetchCache = 'force-no-store' // Don't cache
|
|
62
|
+
export const runtime = 'edge' // Run at the edge
|
|
63
|
+
|
|
64
|
+
// Export API Handler
|
|
65
|
+
export const GET = publishApi
|
|
66
|
+
export const POST = publishApi
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The `createPublishApi` method has many more options allowing you to take control over what is happening while the page renders. The options object has built-in documentation that your IDE can show if you've got JavaScript / TypeScript language support enabled.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
### Middleware
|
|
73
|
+
The package provides the following enhancements for Next.js middleware:
|
|
74
|
+
| Wrapper | import | Purpose |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| withEditFallback | `@remkoj/optimizely-cms-nextjs/preview` | Rewrite incoming Optimizely CMS 12 preview / on-page-edit URLs to Optimizely SaaS CMS preview URLs |
|
|
77
|
+
| withLanguagePrefix | `@remkoj/optimizely-cms-nextjs/page` | Handle the redirect of the homepage `/` to the locale that best matches the incoming request, such as `/en`. The locales and their URLs are taken from the second parameter - the ChannelDefinition.
|
|
78
|
+
|
|
79
|
+
If you use both wrappers, the `withEditFallback` wrapper must wrap the `withLanguagePrefix` wrapper, to ensure that the edit mode URL is rewritten before the language prefix is applied.
|
package/dist/cms-page/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { GetContentByPathMethod, GetMetaDataByPathMethod } from './data.js';
|
|
2
2
|
export type { CreatePageOptions, DefaultCmsPageProps as CmsPageProps, DefaultCmsPageParams as CmsPageParams } from './page.js';
|
|
3
3
|
export type { CreateLayoutOptions } from './layout.js';
|
|
4
|
+
export { withLanguagePrefix } from './middleware.js';
|
|
4
5
|
export { createPage } from './page.js';
|
|
5
6
|
export { createLayout } from './layout.js';
|
package/dist/cms-page/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cms-page/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cms-page/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { type NextMiddleware } from "next/server.js";
|
|
3
|
+
import { type ChannelDefinition } from "@remkoj/optimizely-graph-client";
|
|
4
|
+
/**
|
|
5
|
+
* Wrap the provided middleware with enforcement of the language code as the first
|
|
6
|
+
* slug in the URL.
|
|
7
|
+
*
|
|
8
|
+
* @param next The Next.JS Middleware to wrap, will be invoked if there's no redirect needed
|
|
9
|
+
* @param channel The Optimizely CMS Application definition
|
|
10
|
+
* @returns The newly constructed Next.JS Middleware
|
|
11
|
+
*/
|
|
12
|
+
export declare function withLanguagePrefix<T extends NextMiddleware>(next: T, channel: ChannelDefinition): T;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
import { NextResponse } from "next/server.js";
|
|
3
|
+
import { match } from '@formatjs/intl-localematcher';
|
|
4
|
+
import Negotiator from 'negotiator';
|
|
5
|
+
/**
|
|
6
|
+
* Wrap the provided middleware with enforcement of the language code as the first
|
|
7
|
+
* slug in the URL.
|
|
8
|
+
*
|
|
9
|
+
* @param next The Next.JS Middleware to wrap, will be invoked if there's no redirect needed
|
|
10
|
+
* @param channel The Optimizely CMS Application definition
|
|
11
|
+
* @returns The newly constructed Next.JS Middleware
|
|
12
|
+
*/
|
|
13
|
+
export function withLanguagePrefix(next, channel) {
|
|
14
|
+
if (!channel)
|
|
15
|
+
throw new Error("The language prefix handling requires a CMS Channel Definition");
|
|
16
|
+
const defaultLocale = channel.defaultLocale;
|
|
17
|
+
const locales = channel.locales.map(x => x.code);
|
|
18
|
+
const slugs = channel.getSlugs();
|
|
19
|
+
function getLocale(request) {
|
|
20
|
+
const headers = {};
|
|
21
|
+
request.headers.forEach((v, k) => { headers[k] = v; });
|
|
22
|
+
const languages = new Negotiator({ headers }).languages();
|
|
23
|
+
return match(languages, locales, defaultLocale);
|
|
24
|
+
}
|
|
25
|
+
const newMiddleware = (request, ...params) => {
|
|
26
|
+
const pathname = request.nextUrl.pathname;
|
|
27
|
+
const DEBUG = process.env.NODE_ENV == 'development';
|
|
28
|
+
const pathnameIsMissingLocale = !slugs.some(slug => pathname.toLowerCase().startsWith(`/${slug.toLowerCase()}/`) || pathname.toLowerCase() === `/${slug.toLowerCase()}`);
|
|
29
|
+
if (pathnameIsMissingLocale) {
|
|
30
|
+
const locale = getLocale(request);
|
|
31
|
+
const slug = channel.resolveSlug(locale);
|
|
32
|
+
if (DEBUG)
|
|
33
|
+
console.log(`💬 [Middleware] Detected locale missing in ${pathname}, redirecting to /${slug}${pathname}`);
|
|
34
|
+
const newUrl = request.nextUrl.clone();
|
|
35
|
+
newUrl.pathname = `/${slug}${pathname}`;
|
|
36
|
+
return NextResponse.redirect(newUrl, {
|
|
37
|
+
status: DEBUG ? 302 : 301
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return next(request, ...params);
|
|
41
|
+
};
|
|
42
|
+
return newMiddleware;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/cms-page/middleware.ts"],"names":[],"mappings":"AAAA,OAA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CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;QACxK,IAAI,uBAAuB,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;YACjC,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YACxC,IAAI,KAAK;gBACL,OAAO,CAAC,GAAG,CAAC,8CAA+C,QAAS,qBAAsB,IAAK,GAAI,QAAS,EAAE,CAAC,CAAA;YACnH,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YACtC,MAAM,CAAC,QAAQ,GAAG,IAAK,IAAK,GAAI,QAAS,EAAE,CAAA;YAC3C,OAAO,YAAY,CAAC,QAAQ,CAAC,MAAM,EAAE;gBACjC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;aAC5B,CAAC,CAAA;QACN,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAA;IACnC,CAAC,CAAA;IACD,OAAO,aAAkB,CAAA;AAC7B,CAAC"}
|
package/dist/cms-page/page.d.ts
CHANGED
|
@@ -86,6 +86,15 @@ export type CreatePageOptions<LocaleEnum = SystemLocales, TParams extends Record
|
|
|
86
86
|
* @returns The processed route
|
|
87
87
|
*/
|
|
88
88
|
routeToParams: (route: Route) => TParams;
|
|
89
|
+
/**
|
|
90
|
+
* Takes the Next.JS route segments and try to transform it into an initial
|
|
91
|
+
* locale code, the default implementation will try to resolve the `lang`
|
|
92
|
+
* route segment using the channel definition.
|
|
93
|
+
*
|
|
94
|
+
* @param slugs The slugs to resolve
|
|
95
|
+
* @returns The resolved locale
|
|
96
|
+
*/
|
|
97
|
+
paramsToLocale: (params?: TParams, channel?: ChannelDefinition) => string | undefined;
|
|
89
98
|
};
|
|
90
99
|
/**
|
|
91
100
|
* Generate the React Server Side component and Next.JS functions needed to render an
|
package/dist/cms-page/page.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RouteResolver } from '@remkoj/optimizely-graph-client/router';
|
|
|
6
6
|
import { OptiCmsSchema } from '@remkoj/optimizely-graph-client/client';
|
|
7
7
|
import { normalizeContentLinkWithLocale } from '@remkoj/optimizely-graph-client/utils';
|
|
8
8
|
// React Support
|
|
9
|
-
import { CmsContent, Utils,
|
|
9
|
+
import { CmsContent, Utils, getServerContext } from '@remkoj/optimizely-cms-react/rsc';
|
|
10
10
|
// Within package
|
|
11
11
|
import { MetaDataResolver } from '../metadata.js';
|
|
12
12
|
import { urlToPath, localeToGraphLocale } from './utils.js';
|
|
@@ -22,7 +22,16 @@ const CreatePageOptionDefaults = {
|
|
|
22
22
|
client: getServerClient,
|
|
23
23
|
routerFactory: (client) => new RouteResolver(client),
|
|
24
24
|
propsToCmsPath: ({ params }) => buildRequestPath(params),
|
|
25
|
-
routeToParams: (route) => { return { path: urlToPath(route.url), lang: route.locale }; }
|
|
25
|
+
routeToParams: (route) => { return { path: urlToPath(route.url), lang: route.locale }; },
|
|
26
|
+
paramsToLocale: (params, channel) => {
|
|
27
|
+
if (!channel)
|
|
28
|
+
return undefined;
|
|
29
|
+
const lang = params?.lang;
|
|
30
|
+
const toTest = Array.isArray(lang) ? lang.at(0) : lang;
|
|
31
|
+
if (!toTest)
|
|
32
|
+
return channel.defaultLocale;
|
|
33
|
+
return channel.slugToLocale(toTest.toString());
|
|
34
|
+
}
|
|
26
35
|
};
|
|
27
36
|
/**
|
|
28
37
|
* Generate the React Server Side component and Next.JS functions needed to render an
|
|
@@ -35,7 +44,7 @@ const CreatePageOptionDefaults = {
|
|
|
35
44
|
*/
|
|
36
45
|
export function createPage(factory, options) {
|
|
37
46
|
// Build the global/shared configuration for the Optimizely CMS Page
|
|
38
|
-
const { getContentByPath, client: clientFactory, channel, propsToCmsPath, routeToParams, routerFactory } = {
|
|
47
|
+
const { getContentByPath, client: clientFactory, channel, propsToCmsPath, routeToParams, routerFactory, paramsToLocale } = {
|
|
39
48
|
...CreatePageOptionDefaults,
|
|
40
49
|
...options
|
|
41
50
|
};
|
|
@@ -52,30 +61,39 @@ export function createPage(factory, options) {
|
|
|
52
61
|
const graphLocale = localeToGraphLocale(route.locale, channel);
|
|
53
62
|
return [route, contentLink, contentType, graphLocale];
|
|
54
63
|
};
|
|
64
|
+
// Create channelId
|
|
65
|
+
/**
|
|
66
|
+
* The Channel Identifier to be used for this page
|
|
67
|
+
*/
|
|
68
|
+
const channelId = channel ? globalClient.currentOptiCmsSchema == OptiCmsSchema.CMS12 ? channel.id : getPrimaryURL(channel).origin : undefined;
|
|
55
69
|
const pageDefintion = {
|
|
56
|
-
generateStaticParams: async () => (await router.getRoutes()).map(r => routeToParams(r)),
|
|
57
|
-
generateMetadata: async (
|
|
58
|
-
//
|
|
59
|
-
const
|
|
60
|
-
|
|
70
|
+
generateStaticParams: async () => (await router.getRoutes(channelId)).map(r => routeToParams(r)),
|
|
71
|
+
generateMetadata: async ({ params, searchParams }, parent) => {
|
|
72
|
+
// Get context
|
|
73
|
+
const context = getServerContext();
|
|
74
|
+
context.setOptimizelyGraphClient(globalClient);
|
|
75
|
+
context.setComponentFactory(factory);
|
|
76
|
+
// Read variables from request
|
|
77
|
+
const requestPath = propsToCmsPath({ params, searchParams });
|
|
61
78
|
if (!requestPath)
|
|
62
79
|
return Promise.resolve({});
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
const initialLocale = paramsToLocale(params, channel);
|
|
81
|
+
if (initialLocale)
|
|
82
|
+
context.setLocale(initialLocale);
|
|
83
|
+
// Debug output
|
|
84
|
+
if (context.isDebug)
|
|
85
|
+
console.log(`⚪ [CmsPage.generateMetadata] Processed Next.JS route: ${JSON.stringify(params)} => Optimizely CMS route: ${JSON.stringify({ path: requestPath, siteId: channelId })}`);
|
|
65
86
|
// Resolve the route to a content link
|
|
66
|
-
const routeInfo = await getInfoByPath(requestPath,
|
|
87
|
+
const routeInfo = await getInfoByPath(requestPath, channelId);
|
|
67
88
|
if (!routeInfo) {
|
|
68
|
-
if (isDebug
|
|
89
|
+
if (context.isDebug)
|
|
69
90
|
console.log('⚪ [CmsPage.generateMetadata] No data received');
|
|
70
91
|
return Promise.resolve({});
|
|
71
92
|
}
|
|
72
93
|
const [route, contentLink, contentType, graphLocale] = routeInfo;
|
|
73
|
-
if (isDebug
|
|
94
|
+
if (context.isDebug)
|
|
74
95
|
console.log(`⚪ [CmsPage.generateMetadata] Retrieved content info:`, route);
|
|
75
|
-
// Update context
|
|
76
|
-
const context = getServerContext();
|
|
77
|
-
context.setOptimizelyGraphClient(globalClient);
|
|
78
|
-
context.setComponentFactory(factory);
|
|
96
|
+
// Update context from route
|
|
79
97
|
context.setLocale(route.locale);
|
|
80
98
|
// Fetch the metadata based upon the actual content type and resolve parent
|
|
81
99
|
const metaResolver = new MetaDataResolver(globalClient);
|
|
@@ -83,7 +101,7 @@ export function createPage(factory, options) {
|
|
|
83
101
|
metaResolver.resolve(factory, contentLink, contentType, graphLocale),
|
|
84
102
|
parent
|
|
85
103
|
]);
|
|
86
|
-
if (isDebug
|
|
104
|
+
if (context.isDebug)
|
|
87
105
|
console.log(`⚪ [CmsPage.generateMetadata] Component yielded metadata:`, pageMetadata);
|
|
88
106
|
// Make sure merging of objects goes correctly
|
|
89
107
|
for (const metaKey of Object.getOwnPropertyNames(pageMetadata)) {
|
|
@@ -98,35 +116,39 @@ export function createPage(factory, options) {
|
|
|
98
116
|
}
|
|
99
117
|
return pageMetadata;
|
|
100
118
|
},
|
|
101
|
-
CmsPage: async (
|
|
119
|
+
CmsPage: async ({ params, searchParams }) => {
|
|
102
120
|
// Prepare the context
|
|
103
121
|
const context = getServerContext();
|
|
104
122
|
context.setOptimizelyGraphClient(globalClient);
|
|
105
123
|
context.setComponentFactory(factory);
|
|
106
124
|
// Analyze the Next.JS Request props
|
|
107
|
-
const requestPath = propsToCmsPath(
|
|
108
|
-
if (isDebug
|
|
109
|
-
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(
|
|
125
|
+
const requestPath = propsToCmsPath({ params, searchParams });
|
|
126
|
+
if (context.isDebug)
|
|
127
|
+
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(params)} => Optimizely CMS route: ${JSON.stringify({ path: requestPath })}`);
|
|
110
128
|
// If we don't have the path, or the path is an internal Next.js route reject it.
|
|
111
129
|
if (!requestPath || requestPath.startsWith('/_next/'))
|
|
112
130
|
return notFound();
|
|
131
|
+
// Determine the initial locale
|
|
132
|
+
const initialLocale = paramsToLocale(params, channel);
|
|
133
|
+
if (initialLocale)
|
|
134
|
+
context.setLocale(initialLocale);
|
|
113
135
|
// Resolve the content based upon the path
|
|
114
136
|
const pathForRequest = (requestPath.endsWith("/") ? [requestPath.substring(0, requestPath.length - 1), requestPath] : [requestPath, requestPath + '/']).filter(x => x.length >= 1);
|
|
115
137
|
const requestVars = {
|
|
116
138
|
path: pathForRequest,
|
|
117
|
-
siteId:
|
|
139
|
+
siteId: channelId
|
|
118
140
|
};
|
|
119
|
-
if (isDebug
|
|
120
|
-
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(
|
|
141
|
+
if (context.isDebug)
|
|
142
|
+
console.log(`⚪ [CmsPage] Processed Next.JS route: ${JSON.stringify(params)} => getContentByPath Variables: ${JSON.stringify(requestVars)}`);
|
|
121
143
|
const response = await getContentByPath(globalClient, requestVars);
|
|
122
144
|
const info = (response?.content?.items ?? [])[0];
|
|
123
145
|
if (!info) {
|
|
124
|
-
if (
|
|
146
|
+
if (context.isDebugOrDevelopment) {
|
|
125
147
|
console.error(`🔴 [CmsPage] Unable to load content for ${requestPath}, data received: `, response);
|
|
126
148
|
}
|
|
127
149
|
return notFound();
|
|
128
150
|
}
|
|
129
|
-
else if (
|
|
151
|
+
else if (context.isDebugOrDevelopment && (response?.content?.items ?? []).length > 1) {
|
|
130
152
|
console.warn(`🟠 [CmsPage] Resolving content for ${requestPath}, yielded ${(response?.content?.items ?? []).length} items, picked:`, info);
|
|
131
153
|
}
|
|
132
154
|
// Extract the type & link
|
|
@@ -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;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,KAAK,EAAE,
|
|
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;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,KAAK,EAAE,gBAAgB,EAAyB,MAAM,kCAAkC,CAAA;AAE7G,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;AA8C9C,MAAM,CAAN,I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,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"}
|
|
@@ -5,7 +5,9 @@ type OptimizelyCmsContentSavedEvent = {
|
|
|
5
5
|
previewUrl: string;
|
|
6
6
|
previewToken: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const OnPageEdit: FunctionComponent<PropsWithChildren
|
|
8
|
+
export declare const OnPageEdit: FunctionComponent<PropsWithChildren<{
|
|
9
|
+
refreshTimeout?: number | false;
|
|
10
|
+
}>>;
|
|
9
11
|
export default OnPageEdit;
|
|
10
12
|
declare global {
|
|
11
13
|
interface Window {
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useState, useEffect, useRef, } from 'react';
|
|
3
3
|
import { useRouter } from 'next/navigation.js';
|
|
4
|
-
export const OnPageEdit = ({ children }) => {
|
|
4
|
+
export const OnPageEdit = ({ children, refreshTimeout = false }) => {
|
|
5
5
|
const router = useRouter();
|
|
6
6
|
const [showMask, setShowMask] = useState(false);
|
|
7
|
+
const reloadDelay = useRef();
|
|
7
8
|
function onContentSaved(eventData) {
|
|
8
9
|
const previewUrl = window.location.href;
|
|
9
10
|
setShowMask(true);
|
|
10
|
-
|
|
11
|
+
if (reloadDelay.current)
|
|
12
|
+
clearTimeout(reloadDelay.current);
|
|
11
13
|
if (eventData?.previewUrl && previewUrl != eventData.previewUrl) {
|
|
14
|
+
// First: Use the updated preview URL if we have it
|
|
12
15
|
const newUrl = new URL(eventData.previewUrl);
|
|
13
16
|
console.log(`Navigating to provided preview path: ${newUrl.pathname}${newUrl.search}`);
|
|
14
|
-
|
|
17
|
+
if (refreshTimeout)
|
|
18
|
+
reloadDelay.current = setTimeout(() => router.push(newUrl.pathname + newUrl.search), refreshTimeout);
|
|
19
|
+
else
|
|
20
|
+
router.push(newUrl.pathname + newUrl.search, { scroll: false });
|
|
15
21
|
// or refresh the page
|
|
16
22
|
}
|
|
17
23
|
else {
|
|
18
24
|
console.log(`Refreshing preview: ${eventData.contentLink}`);
|
|
19
|
-
|
|
25
|
+
if (refreshTimeout)
|
|
26
|
+
reloadDelay.current = setTimeout(() => router.refresh(), refreshTimeout);
|
|
27
|
+
else
|
|
28
|
+
router.refresh();
|
|
20
29
|
}
|
|
21
30
|
setShowMask(false);
|
|
22
31
|
}
|
|
@@ -24,23 +33,25 @@ export const OnPageEdit = ({ children }) => {
|
|
|
24
33
|
// Bind to the Saved event
|
|
25
34
|
useEffect(() => {
|
|
26
35
|
console.log(`🟢 Enabling ContentSaved event handler`);
|
|
27
|
-
window.addEventListener(
|
|
36
|
+
window.addEventListener('optimizely:cms:contentSaved', listener);
|
|
28
37
|
let unsub = undefined;
|
|
29
38
|
let cancelled = false;
|
|
30
|
-
waitFor(() => window.epi)
|
|
39
|
+
waitFor(() => window.epi)
|
|
40
|
+
.then((epi) => {
|
|
31
41
|
if (!cancelled) {
|
|
32
42
|
console.log(`⚪ Enabling ContentSaved event handler`);
|
|
33
43
|
let r = epi.subscribe('contentSaved', onContentSaved);
|
|
34
44
|
unsub = r.remove;
|
|
35
45
|
}
|
|
36
|
-
})
|
|
37
|
-
|
|
46
|
+
})
|
|
47
|
+
.catch(() => {
|
|
48
|
+
console.warn('Unable to bind to the contentSaved event');
|
|
38
49
|
});
|
|
39
50
|
// Unsubscribe when needed
|
|
40
51
|
return () => {
|
|
41
52
|
cancelled = true;
|
|
42
53
|
console.log(`Navigating away, disabling ContentSaved event handler`);
|
|
43
|
-
window.removeEventListener(
|
|
54
|
+
window.removeEventListener('optimizely:cms:contentSaved', listener);
|
|
44
55
|
if (unsub)
|
|
45
56
|
unsub();
|
|
46
57
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-page-edit.js","sourceRoot":"","sources":["../../src/components/on-page-edit.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,
|
|
1
|
+
{"version":3,"file":"on-page-edit.js","sourceRoot":"","sources":["../../src/components/on-page-edit.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,GAGP,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAS9C,MAAM,CAAC,MAAM,UAAU,GAEnB,CAAC,EAAE,QAAQ,EAAE,cAAc,GAAG,KAAK,EAAE,EAAE,EAAE;IAC3C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAA;IACxD,MAAM,WAAW,GAAG,MAAM,EAA2B,CAAA;IAErD,SAAS,cAAc,CAAC,SAAyC;QAC/D,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QAEvC,WAAW,CAAC,IAAI,CAAC,CAAA;QAEjB,IAAI,WAAW,CAAC,OAAO;YAAE,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAE1D,IAAI,SAAS,EAAE,UAAU,IAAI,UAAU,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;YAChE,mDAAmD;YACnD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;YAC5C,OAAO,CAAC,GAAG,CACT,wCAAwC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAC1E,CAAA;YACD,IAAI,cAAc;gBAChB,WAAW,CAAC,OAAO,GAAG,UAAU,CAC9B,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAClD,cA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jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import 'server-only';
|
|
3
|
-
import { contentLinkToString, localeToGraphLocale } from '@remkoj/optimizely-graph-client/utils';
|
|
4
|
-
import { getServerContext, Utils, CmsContent } from '@remkoj/optimizely-cms-react/rsc';
|
|
3
|
+
import { contentLinkToString, localeToGraphLocale, } from '@remkoj/optimizely-graph-client/utils';
|
|
4
|
+
import { getServerContext, Utils, CmsContent, } from '@remkoj/optimizely-cms-react/rsc';
|
|
5
5
|
import { notFound } from 'next/navigation.js';
|
|
6
6
|
import OnPageEdit from '../components/on-page-edit.js';
|
|
7
7
|
import { getAuthorizedServerClient } from '../client.js';
|
|
@@ -11,12 +11,13 @@ import { getContentById } from './data.js';
|
|
|
11
11
|
import { getContentRequest, isValidRequest } from './tools.js';
|
|
12
12
|
const defaultOptions = {
|
|
13
13
|
refreshNotice: () => _jsx(_Fragment, {}),
|
|
14
|
-
layout: props => _jsx(_Fragment, { children: props.children }),
|
|
14
|
+
layout: (props) => _jsx(_Fragment, { children: props.children }),
|
|
15
15
|
loader: getContentById,
|
|
16
16
|
clientFactory: (token) => getAuthorizedServerClient(token),
|
|
17
17
|
communicationInjectorPath: '/util/javascript/communicationinjector.js',
|
|
18
18
|
contentResolver: getContentRequest,
|
|
19
|
-
requestValidator: isValidRequest
|
|
19
|
+
requestValidator: isValidRequest,
|
|
20
|
+
refreshTimeout: false,
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Create the EditPage component needed by Next.JS to render the "On Page
|
|
@@ -27,40 +28,43 @@ const defaultOptions = {
|
|
|
27
28
|
* @returns The React Component that can be used by Next.JS to render the page
|
|
28
29
|
*/
|
|
29
30
|
export function createEditPageComponent(factory, options) {
|
|
30
|
-
const { layout: PageLayout, refreshNotice: RefreshNotice, loader: getContentById, clientFactory, communicationInjectorPath, contentResolver: resolveContent, requestValidator: validateRequest } = { ...defaultOptions, ...options };
|
|
31
|
+
const { layout: PageLayout, refreshNotice: RefreshNotice, loader: getContentById, clientFactory, communicationInjectorPath, contentResolver: resolveContent, requestValidator: validateRequest, refreshTimeout, } = { ...defaultOptions, ...options };
|
|
31
32
|
async function EditPage(props) {
|
|
32
33
|
// Create context
|
|
33
34
|
const context = getServerContext();
|
|
34
35
|
// Validate the search parameters
|
|
35
36
|
if (!validateRequest(props, false, context.isDevelopment)) {
|
|
36
|
-
console.error(
|
|
37
|
+
console.error('🔴 [OnPageEdit] Invalid edit mode request');
|
|
37
38
|
return notFound();
|
|
38
39
|
}
|
|
39
40
|
// Get the requested content item
|
|
40
41
|
const contentRequestInfo = resolveContent(props);
|
|
41
42
|
if (!contentRequestInfo) {
|
|
42
|
-
console.error(
|
|
43
|
+
console.error('🔴 [OnPageEdit] Unable to resolve requested content');
|
|
43
44
|
return notFound();
|
|
44
45
|
}
|
|
45
46
|
const { token, ctx, ...contentRequest } = contentRequestInfo;
|
|
46
47
|
// Build context
|
|
47
48
|
const client = clientFactory(token);
|
|
49
|
+
//client.updateFlags({ cache: false, queryCache: false })
|
|
48
50
|
context.setOptimizelyGraphClient(client);
|
|
49
51
|
context.setComponentFactory(factory);
|
|
50
52
|
context.setMode(ctx);
|
|
51
53
|
// Get information from the Request URI
|
|
52
54
|
if (context.isDebug) {
|
|
53
|
-
console.log(
|
|
54
|
-
console.log(
|
|
55
|
-
console.log(
|
|
55
|
+
console.log('⚪ [OnPageEdit] Request context:', ctx);
|
|
56
|
+
console.log('⚪ [OnPageEdit] Request token:', token);
|
|
57
|
+
console.log('⚪ [OnPageEdit] Requested content:', JSON.stringify(contentRequest));
|
|
56
58
|
}
|
|
57
59
|
try {
|
|
58
60
|
const contentInfo = await getContentById(client, {
|
|
59
61
|
...contentRequest,
|
|
60
|
-
locale: localeToGraphLocale(contentRequest.locale)
|
|
62
|
+
locale: localeToGraphLocale(contentRequest.locale),
|
|
61
63
|
});
|
|
62
64
|
if ((contentInfo?.content?.total ?? 0) > 1) {
|
|
63
|
-
console.warn(
|
|
65
|
+
console.warn('🟠 [OnPageEdit] Content request ' +
|
|
66
|
+
JSON.stringify(contentRequest) +
|
|
67
|
+
' yielded more then one item, picking first matching');
|
|
64
68
|
}
|
|
65
69
|
const contentItem = (contentInfo?.content?.items ?? [])[0];
|
|
66
70
|
const contentType = Utils.normalizeContentType(contentItem?._metadata.types);
|
|
@@ -76,12 +80,12 @@ export function createEditPageComponent(factory, options) {
|
|
|
76
80
|
const contentLink = {
|
|
77
81
|
key: contentItem._metadata.key,
|
|
78
82
|
locale: contentItem._metadata.locale,
|
|
79
|
-
version: contentItem._metadata.version
|
|
83
|
+
version: contentItem._metadata.version,
|
|
80
84
|
};
|
|
81
85
|
if (context.isDebug) {
|
|
82
|
-
console.log(
|
|
86
|
+
console.log('⚪ [OnPageEdit] Resolved content:', JSON.stringify({
|
|
83
87
|
...contentLink,
|
|
84
|
-
type: (contentItem.contentType ?? []).join('/')
|
|
88
|
+
type: (contentItem.contentType ?? []).join('/'),
|
|
85
89
|
}));
|
|
86
90
|
}
|
|
87
91
|
// Store the editable content so it can be tested
|
|
@@ -89,13 +93,15 @@ export function createEditPageComponent(factory, options) {
|
|
|
89
93
|
if (contentLink.locale)
|
|
90
94
|
context.setLocale(contentLink.locale);
|
|
91
95
|
// Render the content, with edit mode context
|
|
92
|
-
const isPage = contentType.some(x => x?.toLowerCase() ==
|
|
96
|
+
const isPage = contentType.some((x) => x?.toLowerCase() == 'page') ?? false;
|
|
93
97
|
const Layout = isPage ? PageLayout : React.Fragment;
|
|
94
|
-
const output = _jsxs(_Fragment, { children: [_jsx(Script, { src: new URL(communicationInjectorPath, client.siteInfo.cmsURL).href, strategy:
|
|
98
|
+
const output = (_jsxs(_Fragment, { children: [_jsx(Script, { src: new URL(communicationInjectorPath, client.siteInfo.cmsURL).href, strategy: "afterInteractive" }), _jsxs(Layout, { locale: contentItem.locale?.name ?? '', children: [_jsx(OnPageEdit, { refreshTimeout: refreshTimeout, children: _jsx(RefreshNotice, {}) }), _jsx(CmsContent, { contentType: contentType, contentLink: contentLink, fragmentData: contentItem })] }), context.isDebug && (_jsxs("div", { className: "optly-contentLink", children: ["ContentItem:", ' ', contentLink
|
|
99
|
+
? contentLinkToString(contentLink)
|
|
100
|
+
: 'Invalid content link returned from Optimizely Graph'] }))] }));
|
|
95
101
|
return output;
|
|
96
102
|
}
|
|
97
103
|
catch (e) {
|
|
98
|
-
console.error(
|
|
104
|
+
console.error('🔴 [OnPageEdit] Caught error', e);
|
|
99
105
|
return notFound();
|
|
100
106
|
}
|
|
101
107
|
}
|
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;
|
|
1
|
+
{"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/ope/page.tsx"],"names":[],"mappings":";AAAA,OAAO,aAAa,CAAA;AAOpB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,uCAAuC,CAAA;AAE9C,OAAO,EACL,gBAAgB,EAChB,KAAK,EACL,UAAU,GAEX,MAAM,kCAAkC,CAAA;AACzC,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,GAA4B;IAC9C,aAAa,EAAE,GAAG,EAAE,CAAC,mBAAK;IAC1B,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,4BAAG,KAAK,CAAC,QAAQ,GAAI;IACxC,MAAM,EAAE,cAAc;IACtB,aAA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G,GACN,EACb,KAAC,UAAU,IACT,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,WAAW,GACzB,IACK,EACR,OAAO,CAAC,OAAO,IAAI,CAClB,eAAK,SAAS,EAAC,mBAAmB,6BACnB,GAAG,EACf,WAAW;gCACV,CAAC,CAAC,mBAAmB,CAAC,WAAW,CAAC;gCAClC,CAAC,CAAC,qDAAqD,IACrD,CACP,IACA,CACJ,CAAA;YACD,OAAO,MAAM,CAAA;QACf,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,CAAC,CAAC,CAAA;YAChD,OAAO,QAAQ,EAAE,CAAA;QACnB,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,eAAe,uBAAuB,CAAA"}
|
package/dist/ope/types.d.ts
CHANGED
|
@@ -102,6 +102,12 @@ export type EditViewOptions<LocaleType = string> = {
|
|
|
102
102
|
* @returns If the request is valid
|
|
103
103
|
*/
|
|
104
104
|
requestValidator: (props: EditPageProps, throwOnInvalid?: boolean, isDevelopment?: boolean) => props is ValidatedEditPageProps;
|
|
105
|
+
/**
|
|
106
|
+
* Enforce a refresh delay in the on page editing / preview, between a signal
|
|
107
|
+
* has been received from the CMS and the instruction to Next.JS to actually
|
|
108
|
+
* refresh the page.
|
|
109
|
+
*/
|
|
110
|
+
refreshTimeout?: number | false;
|
|
105
111
|
};
|
|
106
112
|
type MayBe<T> = T extends Array<infer R> ? Array<R | null> | null : T | null;
|
|
107
113
|
export type GetContentByIdData = {
|
package/dist/publish/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type NextRequest, NextResponse } from 'next/server.js';
|
|
2
2
|
import { revalidatePath, revalidateTag } from "next/cache.js";
|
|
3
|
-
import { type ClientFactory, OptiCmsSchema, RouteResolver } from '@remkoj/optimizely-graph-client';
|
|
3
|
+
import { type ClientFactory, OptiCmsSchema, RouteResolver, type Route } from '@remkoj/optimizely-graph-client';
|
|
4
4
|
export { type NextRequest, NextResponse } from 'next/server.js';
|
|
5
5
|
export type PublishApiHandler = (req: NextRequest) => Promise<NextResponse<PublishApiResponse>> | NextResponse<PublishApiResponse>;
|
|
6
6
|
export type PublishScopes = NonNullable<Parameters<typeof revalidatePath>[1]>;
|
|
@@ -30,6 +30,9 @@ export type PublishHookData = {
|
|
|
30
30
|
items: never;
|
|
31
31
|
};
|
|
32
32
|
});
|
|
33
|
+
type PartialRouteResolver = {
|
|
34
|
+
getContentInfoById: (...args: Parameters<InstanceType<(typeof RouteResolver)>['getContentInfoById']>) => Promise<undefined | Pick<Route, 'path'>>;
|
|
35
|
+
};
|
|
33
36
|
export type PublishApiOptions = {
|
|
34
37
|
/**
|
|
35
38
|
* The list of paths that your implementation uses with Optimizely CMS
|
|
@@ -49,7 +52,7 @@ export type PublishApiOptions = {
|
|
|
49
52
|
/**
|
|
50
53
|
* The tags to revalidate the cache for
|
|
51
54
|
*/
|
|
52
|
-
tags: Array<Parameters<typeof revalidateTag>[0]
|
|
55
|
+
tags: Parameters<typeof revalidateTag>[0] | Array<Parameters<typeof revalidateTag>[0]> | ((data: PublishHookData | null | undefined) => Promise<Array<Parameters<typeof revalidateTag>[0]>>);
|
|
53
56
|
/**
|
|
54
57
|
* If set to true, the handler will only publish the paths of the items
|
|
55
58
|
* that are changed. However this comes at the expense of needing a GraphQL
|
|
@@ -64,7 +67,7 @@ export type PublishApiOptions = {
|
|
|
64
67
|
/**
|
|
65
68
|
* The router to use when the publishing optimization is enabled
|
|
66
69
|
*/
|
|
67
|
-
router: (() =>
|
|
70
|
+
router: (() => PartialRouteResolver) | {
|
|
68
71
|
urlBase?: URL | string;
|
|
69
72
|
resolverMode?: OptiCmsSchema;
|
|
70
73
|
};
|
|
@@ -76,6 +79,26 @@ export type PublishApiOptions = {
|
|
|
76
79
|
* @returns
|
|
77
80
|
*/
|
|
78
81
|
hookDataFilter: (hookType: PublishHookData['type']) => boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Take the item identifier as reported by Optimizely Graph and turn that into a
|
|
84
|
+
* key and locale. The default implementation assumes [key]_[locale]_[status]
|
|
85
|
+
*
|
|
86
|
+
* @param itemId The Item ID to parse
|
|
87
|
+
* @param subject The Hook Subject, to make the processing different for single or bulk. Typical values are "bulk" or "doc"
|
|
88
|
+
* @returns An array, with the first item being the key, second locale
|
|
89
|
+
*/
|
|
90
|
+
itemIdToKeyAndLocale: (itemId: string, subject?: PublishHookData['type']['subject']) => {
|
|
91
|
+
key: string;
|
|
92
|
+
locale: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Basic filter for bulk operations, to only select those items in a bulk operation
|
|
96
|
+
* that are actually needed for processing.
|
|
97
|
+
*
|
|
98
|
+
* @param bulkItemStatus
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
bulkItemStatusFilter: (bulkItemStatus: string) => boolean;
|
|
79
102
|
};
|
|
80
103
|
export type PublishApiResponse = {
|
|
81
104
|
revalidated: {
|
package/dist/publish/index.js
CHANGED
|
@@ -11,10 +11,21 @@ const publishApiDefaults = {
|
|
|
11
11
|
optimizePublish: false,
|
|
12
12
|
client: createClient,
|
|
13
13
|
router: {},
|
|
14
|
-
hookDataFilter: (hookType) => hookType.subject == 'bulk' && hookType.action == 'completed'
|
|
14
|
+
hookDataFilter: (hookType) => hookType.subject == 'bulk' && hookType.action == 'completed',
|
|
15
|
+
bulkItemStatusFilter: (bulkItemStatus) => bulkItemStatus == "indexed" || bulkItemStatus == "deleted",
|
|
16
|
+
itemIdToKeyAndLocale: (id, subject) => {
|
|
17
|
+
let [key, locale, versionId] = [].fill('', 0, 2);
|
|
18
|
+
if (subject == 'doc')
|
|
19
|
+
[key, versionId, locale] = id.split('_');
|
|
20
|
+
else
|
|
21
|
+
[key, locale] = id.split('_');
|
|
22
|
+
if (key && locale)
|
|
23
|
+
return { key: key.replaceAll('-', ''), locale, versionId };
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
15
26
|
};
|
|
16
27
|
export function createPublishApi(options) {
|
|
17
|
-
const { paths, additionalPaths, optimizePublish, client: clientFactory, router: routerFactory, hookDataFilter, tags, scopes } = {
|
|
28
|
+
const { paths, additionalPaths, optimizePublish, client: clientFactory, router: routerFactory, hookDataFilter, tags, scopes, itemIdToKeyAndLocale, bulkItemStatusFilter } = {
|
|
18
29
|
...publishApiDefaults,
|
|
19
30
|
...options
|
|
20
31
|
};
|
|
@@ -22,30 +33,34 @@ export function createPublishApi(options) {
|
|
|
22
33
|
function getRouteResolver() {
|
|
23
34
|
return typeof routerFactory == 'function' ? routerFactory() : new RouteResolver(client, routerFactory?.urlBase, routerFactory?.resolverMode ?? client.currentOptiCmsSchema);
|
|
24
35
|
}
|
|
25
|
-
function
|
|
36
|
+
function resolveTags(data) {
|
|
37
|
+
if (typeof tags == 'function')
|
|
38
|
+
return tags(data);
|
|
39
|
+
if (Array.isArray(tags))
|
|
40
|
+
return Promise.resolve(tags);
|
|
41
|
+
return Promise.resolve([tags]);
|
|
42
|
+
}
|
|
43
|
+
function publishAll(targetPaths, targetTags, optimized = false) {
|
|
26
44
|
scopes.forEach(scope => {
|
|
27
45
|
targetPaths.forEach(path => revalidatePath(path, scope));
|
|
28
46
|
additionalPaths.forEach(path => revalidatePath(path, scope));
|
|
29
47
|
});
|
|
30
|
-
|
|
31
|
-
return { revalidated: { scopes, paths: [...targetPaths, ...additionalPaths], tags }, optimized };
|
|
48
|
+
targetTags.forEach(tag => revalidateTag(tag));
|
|
49
|
+
return { revalidated: { scopes, paths: [...targetPaths, ...additionalPaths], tags: targetTags }, optimized };
|
|
32
50
|
}
|
|
33
51
|
function getItemIds(hookData) {
|
|
34
52
|
let items = [];
|
|
35
53
|
switch (hookData.type.subject) {
|
|
36
54
|
case "doc":
|
|
37
|
-
items = [hookData.data.docId]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}).filter(x => x);
|
|
55
|
+
items = [hookData.data.docId]
|
|
56
|
+
.map(item => itemIdToKeyAndLocale(item))
|
|
57
|
+
.filter(x => x);
|
|
41
58
|
break;
|
|
42
59
|
case "bulk":
|
|
43
60
|
items = Object.getOwnPropertyNames(hookData.data.items ?? {}).map(pn => {
|
|
44
61
|
const status = hookData.data.items[pn];
|
|
45
|
-
if (status
|
|
46
|
-
|
|
47
|
-
return key && locale ? { key: key.replaceAll('-', ''), locale } : undefined;
|
|
48
|
-
}
|
|
62
|
+
if (bulkItemStatusFilter(status))
|
|
63
|
+
return itemIdToKeyAndLocale(pn);
|
|
49
64
|
return undefined;
|
|
50
65
|
}).filter(x => x);
|
|
51
66
|
break;
|
|
@@ -69,12 +84,15 @@ export function createPublishApi(options) {
|
|
|
69
84
|
}
|
|
70
85
|
try {
|
|
71
86
|
// Get the webhook data
|
|
72
|
-
const webhookData = await req.json();
|
|
87
|
+
const webhookData = await req.json().catch(() => undefined);
|
|
73
88
|
console.debug('[Publish-API] Webhook data', webhookData);
|
|
89
|
+
// Resolve the tags related to this request
|
|
90
|
+
const publishTags = await resolveTags(webhookData);
|
|
91
|
+
console.debug('[Publish-API] Publishing tags', publishTags);
|
|
74
92
|
// Purge everything if not known (e.g. for a GET request)
|
|
75
93
|
if (!webhookData) {
|
|
76
94
|
console.error("[Publish-API] No hook data received, optimization disabled");
|
|
77
|
-
return NextResponse.json(publishAll(paths));
|
|
95
|
+
return NextResponse.json(publishAll(paths, publishTags));
|
|
78
96
|
}
|
|
79
97
|
// Make sure we're allowed to process the hook
|
|
80
98
|
if (!hookDataFilter(webhookData.type)) {
|
|
@@ -83,7 +101,7 @@ export function createPublishApi(options) {
|
|
|
83
101
|
}
|
|
84
102
|
// If we're not optimizing, just publish everything
|
|
85
103
|
if (!optimizePublish)
|
|
86
|
-
return NextResponse.json(publishAll(paths));
|
|
104
|
+
return NextResponse.json(publishAll(paths, publishTags));
|
|
87
105
|
// Get the actual content ids from the hook data
|
|
88
106
|
const contentIds = getItemIds(webhookData);
|
|
89
107
|
console.debug("[Publish-API] Content items to publish:", JSON.stringify(contentIds));
|
|
@@ -99,7 +117,7 @@ export function createPublishApi(options) {
|
|
|
99
117
|
}).filter(x => x);
|
|
100
118
|
console.debug("[Publish-API] Content paths to publish:", JSON.stringify(pathsToFlush));
|
|
101
119
|
// Flush these paths
|
|
102
|
-
return NextResponse.json(publishAll(pathsToFlush, true));
|
|
120
|
+
return NextResponse.json(publishAll(pathsToFlush, publishTags, true));
|
|
103
121
|
}
|
|
104
122
|
catch (e) {
|
|
105
123
|
console.error("[Publish-API] Error handling publishing request", e?.message ?? e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/publish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAqC,aAAa,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/publish/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAqC,aAAa,EAAc,MAAM,iCAAiC,CAAA;AAC9G,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAE5D,OAAO,EAAoB,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAmH/D,MAAM,kBAAkB,GAAsB;IAC1C,KAAK,EAAE,CAAC,GAAG,EAAE,cAAc,EAAE,SAAS,EAAE,qBAAqB,CAAC;IAC9D,eAAe,EAAE,EAAE;IACnB,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,IAAI,EAAE,EAAE;IACR,eAAe,EAAE,KAAK;IACtB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,E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AAK,CAAC,iDAAiD,EAAG,CAAW,EAAE,OAAO,IAAI,CAAC,CAAC,CAAA;YAC5F,OAAO,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAG,CAAW,EAAE,OAAO,IAAI,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QACnG,CAAC;IACL,CAAC,CAAA;IAED,OAAO,cAAc,CAAA;AACzB,CAAC;AAED,SAAS,eAAe,CAAC,GAAgB;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QACrC,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC;QACrC,SAAS,CAAA;AACjB,CAAC;AAED,eAAe,gBAAgB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remkoj/optimizely-cms-nextjs",
|
|
3
|
+
"description": "Next.JS integration for Optimizely SaaS CMS",
|
|
3
4
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "4.
|
|
5
|
+
"version": "4.3.0",
|
|
5
6
|
"repository": "https://github.com/remkoj/optimizely-dxp-clients.git",
|
|
6
7
|
"author": "Remko Jantzen <693172+remkoj@users.noreply.github.com>",
|
|
7
8
|
"homepage": "https://github.com/remkoj/optimizely-dxp-clients",
|
|
@@ -17,7 +18,8 @@
|
|
|
17
18
|
"./publish": "./dist/publish/index.js",
|
|
18
19
|
"./types": "./dist/types.js",
|
|
19
20
|
"./components": "./dist/components/shared/index.js",
|
|
20
|
-
"./preview": "./dist/ope/index.js"
|
|
21
|
+
"./preview": "./dist/ope/index.js",
|
|
22
|
+
"./page": "./dist/cms-page/index.js"
|
|
21
23
|
},
|
|
22
24
|
"typesVersions": {
|
|
23
25
|
"*": {
|
|
@@ -35,30 +37,36 @@
|
|
|
35
37
|
],
|
|
36
38
|
"preview": [
|
|
37
39
|
"dist/ope/index.d.ts"
|
|
40
|
+
],
|
|
41
|
+
"page": [
|
|
42
|
+
"dist/cms-page/index.d.ts"
|
|
38
43
|
]
|
|
39
44
|
}
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {
|
|
42
|
-
"@remkoj/optimizely-cms-react": "4.
|
|
43
|
-
"@remkoj/optimizely-graph-client": "4.
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/
|
|
47
|
+
"@remkoj/optimizely-cms-react": "4.3.0",
|
|
48
|
+
"@remkoj/optimizely-graph-client": "4.3.0",
|
|
49
|
+
"@types/negotiator": "^0.6.3",
|
|
50
|
+
"@types/node": "^22.13.5",
|
|
51
|
+
"@types/react": "^18.3.18",
|
|
46
52
|
"@types/react-dom": "18.3.5",
|
|
47
53
|
"graphql": "^16.10.0",
|
|
48
54
|
"graphql-request": "^6.1.0",
|
|
49
|
-
"next": "^14.2.
|
|
55
|
+
"next": "^14.2.24",
|
|
50
56
|
"prop-types": "^15.8.1",
|
|
51
57
|
"react": "^18.3.1",
|
|
52
58
|
"react-dom": "^18.3.1",
|
|
53
59
|
"scheduler": "^0.25.0",
|
|
54
|
-
"typescript": "^5.7.
|
|
60
|
+
"typescript": "^5.7.3"
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
57
|
-
"
|
|
63
|
+
"@formatjs/intl-localematcher": "^0.6.0",
|
|
64
|
+
"deepmerge": "^4.3.1",
|
|
65
|
+
"negotiator": "^1.0.0"
|
|
58
66
|
},
|
|
59
67
|
"peerDependencies": {
|
|
60
|
-
"@remkoj/optimizely-cms-react": "
|
|
61
|
-
"@remkoj/optimizely-graph-client": "
|
|
68
|
+
"@remkoj/optimizely-cms-react": "^4",
|
|
69
|
+
"@remkoj/optimizely-graph-client": "^4",
|
|
62
70
|
"graphql": "^16",
|
|
63
71
|
"graphql-request": "^6",
|
|
64
72
|
"next": "^14",
|