@sitecore-content-sdk/nextjs 0.1.0-beta.9 → 0.1.0-canary.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 +5 -4
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/component-props-loader.d.ts +1 -0
- package/component-props-loader.js +3 -0
- package/dist/cjs/client/index.js +10 -0
- package/dist/cjs/client/sitecore-nextjs-client.js +117 -0
- package/dist/cjs/components/RichText.js +16 -4
- package/dist/cjs/config/define-cli-config.js +30 -0
- package/dist/cjs/config/index.js +3 -1
- package/dist/cjs/editing/editing-config-middleware.js +1 -3
- package/dist/cjs/editing/editing-render-middleware.js +13 -9
- package/dist/cjs/editing/index.js +2 -2
- package/dist/cjs/index.js +16 -18
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/middleware.js +23 -12
- package/dist/cjs/middleware/multisite-middleware.js +19 -8
- package/dist/cjs/middleware/personalize-middleware.js +3 -3
- package/dist/cjs/middleware/redirects-middleware.js +28 -13
- package/dist/cjs/middleware/sitemap-middleware.js +47 -0
- package/dist/cjs/services/component-props-service.js +41 -50
- package/dist/cjs/tools/component-props.loader.js +101 -0
- package/dist/cjs/tools/index.js +9 -0
- package/dist/cjs/tools/templating/byoc-component.js +75 -0
- package/dist/cjs/tools/templating/constants.js +7 -0
- package/dist/cjs/tools/templating/default-component.js +54 -0
- package/dist/cjs/tools/templating/utils.js +18 -0
- package/dist/cjs/utils/index.js +2 -1
- package/dist/cjs/utils/utils.js +10 -1
- package/dist/esm/client/index.js +2 -0
- package/dist/esm/client/sitecore-nextjs-client.js +113 -0
- package/dist/esm/components/RichText.js +14 -2
- package/dist/esm/config/define-cli-config.js +26 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/editing/editing-config-middleware.js +1 -3
- package/dist/esm/editing/editing-render-middleware.js +11 -7
- package/dist/esm/editing/index.js +1 -1
- package/dist/esm/index.js +3 -5
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/middleware.js +23 -12
- package/dist/esm/middleware/multisite-middleware.js +20 -9
- package/dist/esm/middleware/personalize-middleware.js +4 -4
- package/dist/esm/middleware/redirects-middleware.js +29 -14
- package/dist/esm/middleware/sitemap-middleware.js +43 -0
- package/dist/esm/services/component-props-service.js +41 -50
- package/dist/esm/tools/component-props.loader.js +65 -0
- package/dist/esm/tools/index.js +1 -0
- package/dist/esm/tools/templating/byoc-component.js +69 -0
- package/dist/esm/tools/templating/constants.js +4 -0
- package/dist/esm/tools/templating/default-component.js +48 -0
- package/dist/esm/tools/templating/utils.js +12 -0
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/utils.js +8 -0
- package/package.json +16 -13
- package/tools.d.ts +1 -0
- package/tools.js +1 -0
- package/types/client/index.d.ts +2 -0
- package/types/client/sitecore-nextjs-client.d.ts +44 -0
- package/types/components/RichText.d.ts +7 -1
- package/types/config/define-cli-config.d.ts +8 -0
- package/types/config/index.d.ts +1 -0
- package/types/editing/editing-config-middleware.d.ts +4 -2
- package/types/editing/editing-render-middleware.d.ts +3 -31
- package/types/editing/index.d.ts +1 -1
- package/types/index.d.ts +6 -8
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/middleware.d.ts +13 -7
- package/types/middleware/sitemap-middleware.d.ts +12 -0
- package/types/services/component-props-service.d.ts +10 -26
- package/types/sharedTypes/component-props.d.ts +18 -0
- package/types/sharedTypes/sitecore-page-props.d.ts +5 -0
- package/types/tools/component-props.loader.d.ts +7 -0
- package/types/tools/index.d.ts +1 -0
- package/types/tools/templating/byoc-component.d.ts +2 -0
- package/types/tools/templating/constants.d.ts +4 -0
- package/types/tools/templating/default-component.d.ts +2 -0
- package/types/tools/templating/utils.d.ts +6 -0
- package/types/utils/index.d.ts +1 -1
- package/types/utils/utils.d.ts +2 -0
- package/dist/cjs/ComponentBuilder.js +0 -63
- package/dist/cjs/graphql/index.js +0 -7
- package/dist/cjs/services/base-graphql-sitemap-service.js +0 -206
- package/dist/cjs/services/graphql-sitemap-service.js +0 -64
- package/dist/cjs/services/mutisite-graphql-sitemap-service.js +0 -81
- package/dist/esm/ComponentBuilder.js +0 -59
- package/dist/esm/graphql/index.js +0 -1
- package/dist/esm/services/base-graphql-sitemap-service.js +0 -201
- package/dist/esm/services/graphql-sitemap-service.js +0 -59
- package/dist/esm/services/mutisite-graphql-sitemap-service.js +0 -77
- package/graphql.d.ts +0 -1
- package/graphql.js +0 -1
- package/types/ComponentBuilder.d.ts +0 -59
- package/types/graphql/index.d.ts +0 -1
- package/types/services/base-graphql-sitemap-service.d.ts +0 -148
- package/types/services/graphql-sitemap-service.d.ts +0 -51
- package/types/services/mutisite-graphql-sitemap-service.d.ts +0 -42
- package/types/sharedTypes/module-factory.d.ts +0 -32
- /package/dist/cjs/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
- /package/dist/esm/sharedTypes/{module-factory.js → sitecore-page-props.js} +0 -0
|
@@ -9,57 +9,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
export class ComponentPropsService {
|
|
12
|
-
|
|
13
|
-
* SSR mode
|
|
14
|
-
* Fetch component props using getServerSideProps function
|
|
15
|
-
* @param {FetchComponentPropsArguments<GetServerSidePropsContext>} params fetch params
|
|
16
|
-
* @returns {Promise<ComponentPropsCollection>} props
|
|
17
|
-
*/
|
|
18
|
-
fetchServerSideComponentProps(params) {
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const { moduleFactory, layoutData, context } = params;
|
|
21
|
-
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const module = yield moduleFactory(componentName);
|
|
23
|
-
return module === null || module === void 0 ? void 0 : module.getServerSideProps;
|
|
24
|
-
});
|
|
25
|
-
return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* SSG mode
|
|
30
|
-
* Fetch component props using getStaticProps function
|
|
31
|
-
* @param {FetchComponentPropsArguments<GetStaticPropsContext>} params fetch arguments
|
|
32
|
-
* @returns {Promise<ComponentPropsCollection>} props
|
|
33
|
-
*/
|
|
34
|
-
fetchStaticComponentProps(params) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const { moduleFactory, layoutData, context } = params;
|
|
37
|
-
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const module = yield moduleFactory(componentName);
|
|
39
|
-
return module === null || module === void 0 ? void 0 : module.getStaticProps;
|
|
40
|
-
});
|
|
41
|
-
return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Traverse Layout Service data tree and call side effects on component level.
|
|
46
|
-
* Side effect function can be: getStaticProps (SSG) or getServerSideProps (SSR)
|
|
47
|
-
* @param {FetchFunctionFactory<NextContext>} fetchFunctionFactory fetch function factory
|
|
48
|
-
* @param {LayoutServiceData} layoutData layout data
|
|
49
|
-
* @param {NextContext} context next context
|
|
50
|
-
* @returns {Promise<ComponentPropsCollection>} component props
|
|
51
|
-
*/
|
|
52
|
-
fetchComponentProps(fetchFunctionFactory, layoutData, context) {
|
|
12
|
+
fetchComponentProps(params) {
|
|
53
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
var _a;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const { layoutData, context, components } = params;
|
|
16
|
+
if (this.isServerSidePropsContext(context)) {
|
|
17
|
+
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = (yield this.getModule(components, componentName))) === null || _a === void 0 ? void 0 : _a.getServerSideProps; });
|
|
18
|
+
const requests = yield this.collectRequests({
|
|
19
|
+
placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
|
|
20
|
+
fetchFunctionFactory,
|
|
21
|
+
layoutData,
|
|
22
|
+
context,
|
|
23
|
+
});
|
|
24
|
+
return yield this.execRequests(requests);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () { var _a; return (_a = (yield this.getModule(components, componentName))) === null || _a === void 0 ? void 0 : _a.getStaticProps; });
|
|
28
|
+
const requests = yield this.collectRequests({
|
|
29
|
+
placeholders: (_b = layoutData.sitecore.route) === null || _b === void 0 ? void 0 : _b.placeholders,
|
|
30
|
+
fetchFunctionFactory,
|
|
31
|
+
layoutData,
|
|
32
|
+
context,
|
|
33
|
+
});
|
|
34
|
+
return yield this.execRequests(requests);
|
|
35
|
+
}
|
|
63
36
|
});
|
|
64
37
|
}
|
|
65
38
|
/**
|
|
@@ -157,4 +130,22 @@ export class ComponentPropsService {
|
|
|
157
130
|
});
|
|
158
131
|
return allComponentRenderings;
|
|
159
132
|
}
|
|
133
|
+
// TODO: remove when unifying server/static component props
|
|
134
|
+
/**
|
|
135
|
+
* Determines whether context is GetServerSidePropsContext (SSR) or GetStaticPropsContext (SSG)
|
|
136
|
+
* @param {GetServerSidePropsContext | GetStaticPropsContext} context
|
|
137
|
+
*/
|
|
138
|
+
isServerSidePropsContext(context) {
|
|
139
|
+
return context.req !== undefined;
|
|
140
|
+
}
|
|
141
|
+
getModule(components, componentName) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
var _a;
|
|
144
|
+
const component = components.get(componentName);
|
|
145
|
+
if (!component)
|
|
146
|
+
return null;
|
|
147
|
+
const module = component.dynamicModule ? yield ((_a = component === null || component === void 0 ? void 0 : component.dynamicModule) === null || _a === void 0 ? void 0 : _a.call(component)) : component;
|
|
148
|
+
return module;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
160
151
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as recast from 'recast';
|
|
2
|
+
/**
|
|
3
|
+
* Webpack loader to strip functions from the source code
|
|
4
|
+
* Strips the `getServerSideProps` and `getStaticProps` functions from the source code
|
|
5
|
+
* @param {string} source file source code
|
|
6
|
+
* @returns {string} output file source code with stripped functions
|
|
7
|
+
*/
|
|
8
|
+
export default function componentPropsLoader(source) {
|
|
9
|
+
// Parse the source code into an AST (Abstract Syntax Tree)
|
|
10
|
+
const ast = recast.parse(source, {
|
|
11
|
+
parser: require('recast/parsers/babel-ts'),
|
|
12
|
+
});
|
|
13
|
+
// List of functions to strip from the AST
|
|
14
|
+
const functionsToStrip = ['getServerSideProps', 'getStaticProps'];
|
|
15
|
+
// Remove the function from the list of functions to strip
|
|
16
|
+
const updateList = (functionName) => {
|
|
17
|
+
// Remove the function from the list of functions to strip
|
|
18
|
+
functionsToStrip.splice(functionsToStrip.indexOf(functionName), 1);
|
|
19
|
+
};
|
|
20
|
+
// Traverse the AST and strip the functions
|
|
21
|
+
recast.visit(ast, {
|
|
22
|
+
// Visit the named export function expression
|
|
23
|
+
visitExportNamedDeclaration: function (path) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
// Get the variable declaration from the AST
|
|
26
|
+
(_b = (_a = path.node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b.forEach((declaration) => {
|
|
27
|
+
// Check if the function is in the list of functions to strip
|
|
28
|
+
if ('id' in declaration &&
|
|
29
|
+
'name' in declaration.id &&
|
|
30
|
+
typeof declaration.id.name === 'string' &&
|
|
31
|
+
functionsToStrip.includes(declaration.id.name)) {
|
|
32
|
+
updateList(declaration.id.name);
|
|
33
|
+
// Strip the function from the AST
|
|
34
|
+
path.prune();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (functionsToStrip.length === 0) {
|
|
38
|
+
// We have pruned all the functions we need to, so we can stop traversing the AST
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
// Continue traversing the AST
|
|
42
|
+
this.traverse(path);
|
|
43
|
+
},
|
|
44
|
+
// Visit the named export function declaration
|
|
45
|
+
visitFunctionDeclaration: function (path) {
|
|
46
|
+
// Check if the function is in the list of functions to strip
|
|
47
|
+
if (path.node.id &&
|
|
48
|
+
'name' in path.node.id &&
|
|
49
|
+
typeof path.node.id.name === 'string' &&
|
|
50
|
+
functionsToStrip.includes(path.node.id.name)) {
|
|
51
|
+
updateList(path.node.id.name);
|
|
52
|
+
// Strip the function from the AST
|
|
53
|
+
path.prune();
|
|
54
|
+
}
|
|
55
|
+
if (functionsToStrip.length === 0) {
|
|
56
|
+
// We have pruned all the functions we need to, so we can stop traversing the AST
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// Continue traversing the AST
|
|
60
|
+
this.traverse(path);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
// Generate the output code
|
|
64
|
+
return recast.print(ast).code;
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateSites, generateMetadata, getComponentList, generatePlugins, ModuleType, } from '@sitecore-content-sdk/core/tools';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
|
|
3
|
+
import { COMPONENT_FILE_EXTENSION } from './constants';
|
|
4
|
+
/**
|
|
5
|
+
* Next.js BYOC component boilerplate
|
|
6
|
+
* @param {string} componentName - the component name
|
|
7
|
+
* @returns component generated template
|
|
8
|
+
*/
|
|
9
|
+
const generateTemplate = (componentName) => {
|
|
10
|
+
return `import React from 'react';
|
|
11
|
+
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
12
|
+
|
|
13
|
+
interface ${componentName}Props {
|
|
14
|
+
title: string;
|
|
15
|
+
columnsCount: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const ${componentName} = (props: ${componentName}Props): JSX.Element => {
|
|
19
|
+
const columns: string[] = [];
|
|
20
|
+
for (let i = 0; i < props.columnsCount; i++) {
|
|
21
|
+
columns.push(\`Component Column \${i + 1}\`);
|
|
22
|
+
}
|
|
23
|
+
return (
|
|
24
|
+
<div className="container">
|
|
25
|
+
<h2>{props.title || 'BYOC Demo'}</h2>
|
|
26
|
+
<p>${componentName} Component</p>
|
|
27
|
+
<div className="row">
|
|
28
|
+
{columns.map((text, index) => (
|
|
29
|
+
<div key={index} className={\`col-sm-\${props.columnsCount}\`}>
|
|
30
|
+
{text}
|
|
31
|
+
</div>
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
FEAAS.External.registerComponent(${componentName}, {
|
|
39
|
+
name: '${componentName}',
|
|
40
|
+
properties: {
|
|
41
|
+
title: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
},
|
|
44
|
+
columnsCount: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
`;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Generates a list of next steps when scaffolding a component.
|
|
53
|
+
* @param {string} componentOutputPath - The file path where the component file is generated.
|
|
54
|
+
* @returns {string[]} An array of strings, each representing a next step.
|
|
55
|
+
*/
|
|
56
|
+
const getNextSteps = (componentOutputPath) => {
|
|
57
|
+
const nextSteps = [];
|
|
58
|
+
nextSteps.push('* Modify component registration through FEAAS.External.registerComponent if needed');
|
|
59
|
+
if (componentOutputPath) {
|
|
60
|
+
nextSteps.push(`* Implement the component in ${chalk.green(componentOutputPath)}`);
|
|
61
|
+
}
|
|
62
|
+
return nextSteps;
|
|
63
|
+
};
|
|
64
|
+
export const byocTemplate = {
|
|
65
|
+
name: ComponentTemplateType.BYOC,
|
|
66
|
+
fileExtension: COMPONENT_FILE_EXTENSION,
|
|
67
|
+
generateTemplate,
|
|
68
|
+
getNextSteps,
|
|
69
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { ComponentTemplateType } from '@sitecore-content-sdk/core/config';
|
|
3
|
+
import { COMPONENT_FILE_EXTENSION } from './constants';
|
|
4
|
+
/**
|
|
5
|
+
* Next.js component boilerplate
|
|
6
|
+
* @param {string} componentName - the component name
|
|
7
|
+
* @returns component generated template
|
|
8
|
+
*/
|
|
9
|
+
const generateTemplate = (componentName) => {
|
|
10
|
+
return `import React from 'react';
|
|
11
|
+
import { ComponentParams, ComponentRendering } from '@sitecore-content-sdk/nextjs';
|
|
12
|
+
|
|
13
|
+
interface ${componentName}Props {
|
|
14
|
+
rendering: ComponentRendering & { params: ComponentParams };
|
|
15
|
+
params: ComponentParams;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const Default = (props: ${componentName}Props): JSX.Element => {
|
|
19
|
+
const id = props.params.RenderingIdentifier;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className={\`component \${props.params.styles}\`} id={id ? id : undefined}>
|
|
23
|
+
<div className="component-content">
|
|
24
|
+
<p>${componentName} Component</p>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
`;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generates a list of next steps when scaffolding a component.
|
|
33
|
+
* @param {string} componentOutputPath - The file path where the component file is generated.
|
|
34
|
+
* @returns {string[]} An array of strings, each representing a next step.
|
|
35
|
+
*/
|
|
36
|
+
const getNextSteps = (componentOutputPath) => {
|
|
37
|
+
const nextSteps = [];
|
|
38
|
+
if (componentOutputPath) {
|
|
39
|
+
nextSteps.push(`* Implement the React component in ${chalk.green(componentOutputPath)}`);
|
|
40
|
+
}
|
|
41
|
+
return nextSteps;
|
|
42
|
+
};
|
|
43
|
+
export const defaultTemplate = {
|
|
44
|
+
name: ComponentTemplateType.DEFAULT,
|
|
45
|
+
fileExtension: COMPONENT_FILE_EXTENSION,
|
|
46
|
+
generateTemplate,
|
|
47
|
+
getNextSteps,
|
|
48
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
/**
|
|
3
|
+
* Run watch mode, watching on @var paths
|
|
4
|
+
* @param {string[]} paths paths to watch by chokidar
|
|
5
|
+
* @param {Function<void>} cb callback to run on file change
|
|
6
|
+
*/
|
|
7
|
+
export function watchItems(paths, cb) {
|
|
8
|
+
chokidar
|
|
9
|
+
.watch(paths, { ignoreInitial: true, awaitWriteFinish: true })
|
|
10
|
+
.on('add', cb)
|
|
11
|
+
.on('unlink', cb);
|
|
12
|
+
}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { handleEditorFastRefresh } from './utils';
|
|
1
|
+
export { handleEditorFastRefresh, extractPath } from './utils';
|
|
2
2
|
export { tryParseEnvValue, resolveUrl } from '@sitecore-content-sdk/core/utils';
|
|
3
3
|
export { isEditorActive, resetEditorChromes } from '@sitecore-content-sdk/core/editing';
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -35,3 +35,11 @@ export const getJssEditingSecret = () => {
|
|
|
35
35
|
}
|
|
36
36
|
return secret;
|
|
37
37
|
};
|
|
38
|
+
export const extractPath = (context) => {
|
|
39
|
+
var _a;
|
|
40
|
+
return context.params === undefined
|
|
41
|
+
? '/'
|
|
42
|
+
: Array.isArray(context.params.path)
|
|
43
|
+
? context.params.path.join('/')
|
|
44
|
+
: (_a = context.params.path) !== null && _a !== void 0 ? _a : '/';
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-canary.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,23 +15,23 @@
|
|
|
15
15
|
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
16
16
|
"prepublishOnly": "npm run build",
|
|
17
17
|
"coverage": "nyc npm test",
|
|
18
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/
|
|
18
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/client/index.ts --entryPoints src/tools/index.ts --githubPages false"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
23
23
|
"author": {
|
|
24
24
|
"name": "Sitecore Corporation",
|
|
25
|
-
"url": "https://
|
|
25
|
+
"url": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
|
-
"homepage": "https://
|
|
28
|
+
"homepage": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html",
|
|
29
29
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/sitecore/
|
|
30
|
+
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@sitecore-cloudsdk/core": "^0.
|
|
34
|
-
"@sitecore-cloudsdk/personalize": "^0.
|
|
33
|
+
"@sitecore-cloudsdk/core": "^0.5.0",
|
|
34
|
+
"@sitecore-cloudsdk/personalize": "^0.5.0",
|
|
35
35
|
"@testing-library/dom": "^10.4.0",
|
|
36
36
|
"@testing-library/react": "^16.2.0",
|
|
37
37
|
"@types/chai": "^4.3.4",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"next": "^14.2.18",
|
|
58
58
|
"nock": "14.0.0-beta.7",
|
|
59
59
|
"nyc": "^17.1.0",
|
|
60
|
+
"proxyquire": "^2.1.3",
|
|
60
61
|
"react": "^18.2.0",
|
|
61
62
|
"react-dom": "^18.2.0",
|
|
62
63
|
"sinon": "^19.0.2",
|
|
@@ -65,24 +66,26 @@
|
|
|
65
66
|
"typescript": "~5.7.3"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"@sitecore-cloudsdk/core": "^0.
|
|
69
|
-
"@sitecore-cloudsdk/
|
|
69
|
+
"@sitecore-cloudsdk/core": "^0.5.0",
|
|
70
|
+
"@sitecore-cloudsdk/events": "^0.5.0",
|
|
71
|
+
"@sitecore-cloudsdk/personalize": "^0.5.0",
|
|
70
72
|
"next": "^14.2.18",
|
|
71
73
|
"react": "^18.2.0",
|
|
72
74
|
"react-dom": "^18.2.0"
|
|
73
75
|
},
|
|
74
76
|
"dependencies": {
|
|
75
|
-
"@
|
|
76
|
-
"@sitecore-content-sdk/
|
|
77
|
-
"@sitecore-content-sdk/react": "0.1.0-
|
|
77
|
+
"@babel/parser": "^7.26.10",
|
|
78
|
+
"@sitecore-content-sdk/core": "0.1.0-canary.0",
|
|
79
|
+
"@sitecore-content-sdk/react": "0.1.0-canary.0",
|
|
78
80
|
"@vercel/kv": "^3.0.0",
|
|
79
81
|
"prop-types": "^15.8.1",
|
|
82
|
+
"recast": "^0.23.11",
|
|
80
83
|
"regex-parser": "^2.3.0",
|
|
81
84
|
"sync-disk-cache": "^2.1.0"
|
|
82
85
|
},
|
|
83
86
|
"description": "",
|
|
84
87
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "2352eb9d087aa563507d1a2092af21ddf1e31c35",
|
|
86
89
|
"files": [
|
|
87
90
|
"dist",
|
|
88
91
|
"types",
|
package/tools.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/tools/index';
|
package/tools.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/tools/index');
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClient, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, getEdgeProxyContentUrl, createGraphQLClientFactory, SitecoreClientInit, } from '@sitecore-content-sdk/core/client';
|
|
2
|
+
export { SitecoreNextjsClient as SitecoreClient, NextjsPage } from './sitecore-nextjs-client';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FetchOptions, Page, PageOptions, SitecoreClient, SitecoreClientInit } from '@sitecore-content-sdk/core/client';
|
|
2
|
+
import { ComponentPropsCollection, NextjsJssComponent } from '../sharedTypes/component-props';
|
|
3
|
+
import { GetServerSidePropsContext, GetStaticPropsContext, PreviewData } from 'next';
|
|
4
|
+
import { LayoutServiceData } from '@sitecore-content-sdk/core/layout';
|
|
5
|
+
import { ComponentPropsService } from '../services/component-props-service';
|
|
6
|
+
import { ComponentMap } from '@sitecore-content-sdk/react';
|
|
7
|
+
export type NextjsPage = Page & {
|
|
8
|
+
componentProps?: ComponentPropsCollection;
|
|
9
|
+
notFound?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare class SitecoreNextjsClient extends SitecoreClient {
|
|
12
|
+
protected initOptions: SitecoreClientInit;
|
|
13
|
+
protected componentPropsService: ComponentPropsService;
|
|
14
|
+
constructor(initOptions: SitecoreClientInit);
|
|
15
|
+
/**
|
|
16
|
+
* Resolves site based on the provided path
|
|
17
|
+
* @param {string | string[]} path path to resolve site from
|
|
18
|
+
* @returns resolved site, or default site info if not found
|
|
19
|
+
*/
|
|
20
|
+
resolveSiteFromPath(path: string | string[]): import("@sitecore-content-sdk/core/site").SiteInfo;
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes a nextjs path that could have been rewritten
|
|
23
|
+
* @param {string | string[]} path nextjs path
|
|
24
|
+
* @returns path string without nextjs prefixes
|
|
25
|
+
*/
|
|
26
|
+
parsePath(path: string | string[]): string;
|
|
27
|
+
getPage(path: string | string[], pageOptions: PageOptions, options?: FetchOptions): Promise<NextjsPage | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves preview page and layout details
|
|
30
|
+
* @param {PreviewData} previewData - The editing preview data for metadata mode.
|
|
31
|
+
* @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
|
|
32
|
+
*/
|
|
33
|
+
getPreview(previewData: PreviewData, fetchOptions?: FetchOptions): Promise<NextjsPage | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Parses components from nextjs component map and layoutData, executes getServerProps/getStaticProps methods
|
|
36
|
+
* and returns resulting props from components
|
|
37
|
+
* @param {LayoutServiceData} layoutData layout data to parse compnents from
|
|
38
|
+
* @param {PreviewData} context Nextjs preview data
|
|
39
|
+
* @param {ComponentMap<NextjsJssComponent>} components component map to get props for
|
|
40
|
+
* @returns {ComponentPropsCollection} component props
|
|
41
|
+
*/
|
|
42
|
+
getComponentData(layoutData: LayoutServiceData, context: GetServerSidePropsContext | GetStaticPropsContext, components: ComponentMap<NextjsJssComponent>): Promise<ComponentPropsCollection>;
|
|
43
|
+
protected getComponentPropsService(): ComponentPropsService;
|
|
44
|
+
}
|
|
@@ -10,9 +10,15 @@ export type RichTextProps = ReactRichTextProps & {
|
|
|
10
10
|
/**
|
|
11
11
|
* Controls the prefetch of internal links. This can be beneficial if you have RichText fields
|
|
12
12
|
* with large numbers of internal links in them.
|
|
13
|
+
* - `true` (default): The full route & its data will be prefetched.
|
|
14
|
+
* - `hover`: Prefetching will happen on hover.
|
|
15
|
+
* - `false`: Prefetching will not happen.
|
|
13
16
|
* @default true
|
|
14
17
|
*/
|
|
15
|
-
prefetchLinks?: boolean;
|
|
18
|
+
prefetchLinks?: boolean | 'hover';
|
|
19
|
+
};
|
|
20
|
+
export declare const prefetched: {
|
|
21
|
+
[cacheKey: string]: boolean;
|
|
16
22
|
};
|
|
17
23
|
export declare const RichText: {
|
|
18
24
|
(props: RichTextProps): JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SitecoreCliConfigInput, SitecoreCliConfig } from '@sitecore-content-sdk/core/config';
|
|
2
|
+
/**
|
|
3
|
+
* Accepts a `SitecoreCliConfigInput` object and returns the Sitecore Content SDK CLI configuration from the specified file,
|
|
4
|
+
* updated with the required default values.
|
|
5
|
+
* @param {SitecoreCliConfigInput} cliConfig the cli configuration provided by the application
|
|
6
|
+
* @returns {SitecoreCliConfig} full sitecore cli configuration to use with cli
|
|
7
|
+
*/
|
|
8
|
+
export declare const defineCliConfig: (cliConfig: SitecoreCliConfigInput) => SitecoreCliConfig;
|
package/types/config/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import { Metadata } from '@sitecore-content-sdk/
|
|
2
|
+
import { Metadata } from '@sitecore-content-sdk/core/editing';
|
|
3
|
+
import { ComponentMap } from '@sitecore-content-sdk/react';
|
|
4
|
+
import { NextjsJssComponent } from '../sharedTypes/component-props';
|
|
3
5
|
export type EditingConfigMiddlewareConfig = {
|
|
4
6
|
/**
|
|
5
7
|
* Components available in the application
|
|
6
8
|
*/
|
|
7
|
-
components:
|
|
9
|
+
components: ComponentMap<NextjsJssComponent>;
|
|
8
10
|
/**
|
|
9
11
|
* Application metadata
|
|
10
12
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import {
|
|
3
|
-
import { EditingRenderQueryParams, LayoutKind } from '@sitecore-content-sdk/core/editing';
|
|
2
|
+
import { EditingRenderQueryParams, DesignLibraryRenderPreviewData } from '@sitecore-content-sdk/core/editing';
|
|
4
3
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
5
4
|
/**
|
|
6
5
|
* Configuration for the Editing Render Middleware.
|
|
@@ -22,39 +21,12 @@ export type EditingNextApiRequest = NextApiRequest & {
|
|
|
22
21
|
query: EditingRenderQueryParams;
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
export type EditingPreviewData = {
|
|
28
|
-
site: string;
|
|
29
|
-
itemId: string;
|
|
30
|
-
language: string;
|
|
31
|
-
pageState: Exclude<LayoutServicePageState, 'Normal'>;
|
|
32
|
-
variantIds: string[];
|
|
33
|
-
version?: string;
|
|
34
|
-
layoutKind?: LayoutKind;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Data for Component Library rendering mode
|
|
38
|
-
*/
|
|
39
|
-
export interface ComponentLibraryRenderPreviewData {
|
|
40
|
-
site: string;
|
|
41
|
-
itemId: string;
|
|
42
|
-
renderingId: string;
|
|
43
|
-
componentUid: string;
|
|
44
|
-
language: string;
|
|
45
|
-
pageState: LayoutServicePageState;
|
|
46
|
-
mode?: 'library';
|
|
47
|
-
variant?: string;
|
|
48
|
-
version?: string;
|
|
49
|
-
dataSourceId?: string;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Type guard for Component Library mode
|
|
24
|
+
* Type guard for Design Library mode
|
|
53
25
|
* @param {object} data preview data to check
|
|
54
26
|
* @returns true if the data is EditingPreviewData
|
|
55
27
|
* @see EditingPreviewData
|
|
56
28
|
*/
|
|
57
|
-
export declare const
|
|
29
|
+
export declare const isDesignLibraryPreviewData: (data: unknown) => data is DesignLibraryRenderPreviewData;
|
|
58
30
|
/**
|
|
59
31
|
* Middleware / handler for use in the editing render Next.js API route (e.g. '/api/editing/render')
|
|
60
32
|
* which is required for Sitecore editing support.
|
package/types/editing/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { GraphQLEditingService } from '@sitecore-content-sdk/core/editing';
|
|
2
|
-
export { EditingRenderMiddleware, EditingRenderMiddlewareConfig,
|
|
2
|
+
export { EditingRenderMiddleware, EditingRenderMiddlewareConfig, isDesignLibraryPreviewData, } from './editing-render-middleware';
|
|
3
3
|
export { FEAASRenderMiddleware, FEAASRenderMiddlewareConfig } from './feaas-render-middleware';
|
|
4
4
|
export { EditingConfigMiddleware, EditingConfigMiddlewareConfig, } from './editing-config-middleware';
|
|
5
5
|
export { RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-content-sdk/core/layout';
|
package/types/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
export { constants, NativeDataFetcher, NativeDataFetcherConfig, NativeDataFetcherResponse, NativeDataFetcherError, HTMLLink, enableDebug, debug, CacheClient, CacheOptions, MemoryCacheClient, } from '@sitecore-content-sdk/core';
|
|
2
|
-
export {
|
|
2
|
+
export { LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, getContentStylesheetLink, EditMode, RenderingType, } from '@sitecore-content-sdk/core/layout';
|
|
3
3
|
export { RestComponentLayoutService } from '@sitecore-content-sdk/core/editing';
|
|
4
4
|
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
5
5
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, } from '@sitecore-content-sdk/core/i18n';
|
|
6
6
|
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-content-sdk/core/personalize';
|
|
7
|
-
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
|
|
8
|
-
export {
|
|
7
|
+
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, NextjsJssComponent, } from './sharedTypes/component-props';
|
|
8
|
+
export { SitecorePageProps } from './sharedTypes/sitecore-page-props';
|
|
9
9
|
export { ComponentPropsService } from './services/component-props-service';
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { GraphQLSitePathService, GraphQLSitePathServiceConfig, } from '@sitecore-content-sdk/core/site';
|
|
11
|
+
export { StaticPath } from '@sitecore-content-sdk/core';
|
|
12
12
|
export { GraphQLSitemapXmlService, GraphQLSitemapXmlServiceConfig, GraphQLErrorPagesService, GraphQLErrorPagesServiceConfig, RobotsQueryResult, GraphQLRobotsService, GraphQLRobotsServiceConfig, ErrorPages, SiteInfo, SiteResolver, GraphQLSiteInfoService, GraphQLSiteInfoServiceConfig, getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, } from '@sitecore-content-sdk/core/site';
|
|
13
|
-
export { StaticPath } from './services/graphql-sitemap-service';
|
|
14
13
|
export { ComponentPropsReactContext, ComponentPropsContextProps, ComponentPropsContext, useComponentProps, } from './components/ComponentPropsContext';
|
|
15
14
|
export { Link, LinkProps } from './components/Link';
|
|
16
15
|
export { RichText, RichTextProps } from './components/RichText';
|
|
@@ -20,5 +19,4 @@ import * as FEaaSWrapper from './components/FEaaSWrapper';
|
|
|
20
19
|
import * as BYOCWrapper from './components/BYOCWrapper';
|
|
21
20
|
export { FEaaSWrapper };
|
|
22
21
|
export { BYOCWrapper };
|
|
23
|
-
export {
|
|
24
|
-
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, ComponentLibraryLayout, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-content-sdk/react';
|
|
22
|
+
export { ComponentMap, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getDesignLibraryStylesheetLinks, File, FileField, RichTextField, DesignLibrary, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, Form, } from '@sitecore-content-sdk/react';
|
|
@@ -3,3 +3,4 @@ export { MiddlewareBase, MiddlewareBaseConfig, Middleware, defineMiddleware } fr
|
|
|
3
3
|
export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-middleware';
|
|
4
4
|
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
5
5
|
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
6
|
+
export { SitemapMiddleware } from './sitemap-middleware';
|