@sitecore-content-sdk/nextjs 0.1.0-beta.1
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/LICENSE.txt +202 -0
- package/README.md +10 -0
- package/dist/cjs/ComponentBuilder.js +63 -0
- package/dist/cjs/components/BYOCWrapper.js +41 -0
- package/dist/cjs/components/ComponentPropsContext.js +57 -0
- package/dist/cjs/components/FEaaSWrapper.js +43 -0
- package/dist/cjs/components/Link.js +87 -0
- package/dist/cjs/components/NextImage.js +82 -0
- package/dist/cjs/components/Placeholder.js +49 -0
- package/dist/cjs/components/RichText.js +95 -0
- package/dist/cjs/editing/constants.js +10 -0
- package/dist/cjs/editing/editing-config-middleware.js +62 -0
- package/dist/cjs/editing/editing-render-middleware.js +182 -0
- package/dist/cjs/editing/feaas-render-middleware.js +101 -0
- package/dist/cjs/editing/index.js +16 -0
- package/dist/cjs/editing/render-middleware.js +43 -0
- package/dist/cjs/graphql/index.js +7 -0
- package/dist/cjs/index.js +119 -0
- package/dist/cjs/middleware/index.js +13 -0
- package/dist/cjs/middleware/middleware.js +97 -0
- package/dist/cjs/middleware/multisite-middleware.js +93 -0
- package/dist/cjs/middleware/personalize-middleware.js +231 -0
- package/dist/cjs/middleware/redirects-middleware.js +264 -0
- package/dist/cjs/monitoring/healthcheck-middleware.js +30 -0
- package/dist/cjs/monitoring/index.js +5 -0
- package/dist/cjs/services/base-graphql-sitemap-service.js +206 -0
- package/dist/cjs/services/component-props-service.js +167 -0
- package/dist/cjs/services/graphql-sitemap-service.js +64 -0
- package/dist/cjs/services/mutisite-graphql-sitemap-service.js +81 -0
- package/dist/cjs/sharedTypes/component-props.js +2 -0
- package/dist/cjs/sharedTypes/module-factory.js +2 -0
- package/dist/cjs/site/index.js +5 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/cjs/utils/utils.js +42 -0
- package/dist/esm/ComponentBuilder.js +59 -0
- package/dist/esm/components/BYOCWrapper.js +36 -0
- package/dist/esm/components/ComponentPropsContext.js +19 -0
- package/dist/esm/components/FEaaSWrapper.js +38 -0
- package/dist/esm/components/Link.js +48 -0
- package/dist/esm/components/NextImage.js +76 -0
- package/dist/esm/components/Placeholder.js +12 -0
- package/dist/esm/components/RichText.js +55 -0
- package/dist/esm/editing/constants.js +7 -0
- package/dist/esm/editing/editing-config-middleware.js +58 -0
- package/dist/esm/editing/editing-render-middleware.js +177 -0
- package/dist/esm/editing/feaas-render-middleware.js +97 -0
- package/dist/esm/editing/index.js +5 -0
- package/dist/esm/editing/render-middleware.js +39 -0
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/middleware/index.js +5 -0
- package/dist/esm/middleware/middleware.js +93 -0
- package/dist/esm/middleware/multisite-middleware.js +89 -0
- package/dist/esm/middleware/personalize-middleware.js +227 -0
- package/dist/esm/middleware/redirects-middleware.js +257 -0
- package/dist/esm/monitoring/healthcheck-middleware.js +26 -0
- package/dist/esm/monitoring/index.js +1 -0
- package/dist/esm/services/base-graphql-sitemap-service.js +201 -0
- package/dist/esm/services/component-props-service.js +160 -0
- package/dist/esm/services/graphql-sitemap-service.js +59 -0
- package/dist/esm/services/mutisite-graphql-sitemap-service.js +77 -0
- package/dist/esm/sharedTypes/component-props.js +1 -0
- package/dist/esm/sharedTypes/module-factory.js +1 -0
- package/dist/esm/site/index.js +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/utils.js +37 -0
- package/editing.d.ts +1 -0
- package/editing.js +1 -0
- package/global.d.ts +21 -0
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/middleware.d.ts +1 -0
- package/middleware.js +1 -0
- package/monitoring.d.ts +1 -0
- package/monitoring.js +1 -0
- package/package.json +92 -0
- package/site.d.ts +1 -0
- package/site.js +1 -0
- package/types/ComponentBuilder.d.ts +59 -0
- package/types/components/BYOCWrapper.d.ts +20 -0
- package/types/components/ComponentPropsContext.d.ts +18 -0
- package/types/components/FEaaSWrapper.d.ts +22 -0
- package/types/components/Link.d.ts +10 -0
- package/types/components/NextImage.d.ts +6 -0
- package/types/components/Placeholder.d.ts +8 -0
- package/types/components/RichText.d.ts +32 -0
- package/types/editing/constants.d.ts +7 -0
- package/types/editing/editing-config-middleware.d.ts +29 -0
- package/types/editing/editing-render-middleware.d.ts +79 -0
- package/types/editing/feaas-render-middleware.d.ts +32 -0
- package/types/editing/index.d.ts +5 -0
- package/types/editing/render-middleware.d.ts +24 -0
- package/types/graphql/index.d.ts +1 -0
- package/types/index.d.ts +24 -0
- package/types/middleware/index.d.ts +5 -0
- package/types/middleware/middleware.d.ts +82 -0
- package/types/middleware/multisite-middleware.d.ts +39 -0
- package/types/middleware/personalize-middleware.d.ts +102 -0
- package/types/middleware/redirects-middleware.d.ts +57 -0
- package/types/monitoring/healthcheck-middleware.d.ts +12 -0
- package/types/monitoring/index.d.ts +1 -0
- package/types/services/base-graphql-sitemap-service.d.ts +148 -0
- package/types/services/component-props-service.d.ts +81 -0
- package/types/services/graphql-sitemap-service.d.ts +51 -0
- package/types/services/mutisite-graphql-sitemap-service.d.ts +42 -0
- package/types/sharedTypes/component-props.d.ts +26 -0
- package/types/sharedTypes/module-factory.d.ts +32 -0
- package/types/site/index.d.ts +1 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/utils.d.ts +8 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
13
|
+
"clean": "del-cli dist types",
|
|
14
|
+
"lint": "eslint \"./src/**/*.tsx\" \"./src/**/*.ts\"",
|
|
15
|
+
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
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/graphql/index.ts --githubPages false"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Sitecore Corporation",
|
|
25
|
+
"url": "https://jss.sitecore.com"
|
|
26
|
+
},
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"homepage": "https://jss.sitecore.com",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/sitecore/jss/issues"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@sitecore-cloudsdk/core": "^0.4.2",
|
|
34
|
+
"@sitecore-cloudsdk/personalize": "^0.4.2",
|
|
35
|
+
"@testing-library/dom": "^10.4.0",
|
|
36
|
+
"@testing-library/react": "^16.2.0",
|
|
37
|
+
"@types/chai": "^4.3.4",
|
|
38
|
+
"@types/chai-as-promised": "^7.1.5",
|
|
39
|
+
"@types/chai-string": "^1.4.2",
|
|
40
|
+
"@types/mocha": "^10.0.1",
|
|
41
|
+
"@types/node": "~22.9.0",
|
|
42
|
+
"@types/prop-types": "^15.7.5",
|
|
43
|
+
"@types/react": "^18.2.45",
|
|
44
|
+
"@types/react-dom": "^18.0.10",
|
|
45
|
+
"@types/sinon": "^10.0.13",
|
|
46
|
+
"@types/sinon-chai": "^3.2.9",
|
|
47
|
+
"chai": "^4.3.7",
|
|
48
|
+
"chai-as-promised": "^7.1.1",
|
|
49
|
+
"chai-string": "^1.5.0",
|
|
50
|
+
"chalk": "^4.1.2",
|
|
51
|
+
"cross-fetch": "^4.1.0",
|
|
52
|
+
"del-cli": "^6.0.0",
|
|
53
|
+
"eslint": "^8.56.0",
|
|
54
|
+
"eslint-plugin-react": "^7.32.1",
|
|
55
|
+
"jsdom": "^26.0.0",
|
|
56
|
+
"mocha": "^11.1.0",
|
|
57
|
+
"next": "^14.2.18",
|
|
58
|
+
"nock": "14.0.0-beta.7",
|
|
59
|
+
"nyc": "^17.1.0",
|
|
60
|
+
"react": "^18.2.0",
|
|
61
|
+
"react-dom": "^18.2.0",
|
|
62
|
+
"sinon": "^19.0.2",
|
|
63
|
+
"sinon-chai": "^3.7.0",
|
|
64
|
+
"ts-node": "^10.9.1",
|
|
65
|
+
"typescript": "~5.7.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@sitecore-cloudsdk/core": "^0.4.2",
|
|
69
|
+
"@sitecore-cloudsdk/personalize": "^0.4.2",
|
|
70
|
+
"next": "^14.2.18",
|
|
71
|
+
"react": "^18.2.0",
|
|
72
|
+
"react-dom": "^18.2.0"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@sitecore-content-sdk/core": "^0.1.0-beta.1",
|
|
76
|
+
"@sitecore-content-sdk/dev-tools": "^0.1.0-beta.1",
|
|
77
|
+
"@sitecore-content-sdk/react": "^0.1.0-beta.1",
|
|
78
|
+
"@vercel/kv": "^3.0.0",
|
|
79
|
+
"prop-types": "^15.8.1",
|
|
80
|
+
"regex-parser": "^2.3.0",
|
|
81
|
+
"sync-disk-cache": "^2.1.0"
|
|
82
|
+
},
|
|
83
|
+
"description": "",
|
|
84
|
+
"types": "types/index.d.ts",
|
|
85
|
+
"gitHead": "11e6c0ce4b6bcaf8a5ddffa39a921c8dd145e603",
|
|
86
|
+
"files": [
|
|
87
|
+
"dist",
|
|
88
|
+
"types",
|
|
89
|
+
"/*.js",
|
|
90
|
+
"/*.d.ts"
|
|
91
|
+
]
|
|
92
|
+
}
|
package/site.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/site/index';
|
package/site.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/site/index');
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ComponentFactory, JssComponentType } from '@sitecore-content-sdk/react';
|
|
2
|
+
import { Module, ModuleFactory } from './sharedTypes/module-factory';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a component that can be imported dynamically
|
|
5
|
+
*/
|
|
6
|
+
export type LazyModule = {
|
|
7
|
+
module: () => Promise<Module>;
|
|
8
|
+
element: (isEditing?: boolean) => JssComponentType;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Component is a module or a lazy module
|
|
12
|
+
*/
|
|
13
|
+
type Component = Module | LazyModule | JssComponentType;
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for ComponentBuilder
|
|
16
|
+
*/
|
|
17
|
+
export type ComponentBuilderConfig<Component> = {
|
|
18
|
+
/**
|
|
19
|
+
* List of components to be stored
|
|
20
|
+
*/
|
|
21
|
+
components: Map<string, Component>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for ComponentFactory
|
|
25
|
+
*/
|
|
26
|
+
type ComponentFactoryConfig = {
|
|
27
|
+
isEditing?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Nextjs implementation of component builder class for building components based on the configuration.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ComponentBuilder {
|
|
33
|
+
protected config: ComponentBuilderConfig<Component>;
|
|
34
|
+
/**
|
|
35
|
+
* List of components to be stored
|
|
36
|
+
*/
|
|
37
|
+
protected components: Map<string, Component>;
|
|
38
|
+
/**
|
|
39
|
+
* SXA uses custom default export name
|
|
40
|
+
*/
|
|
41
|
+
protected DEFAULT_EXPORT_NAME: string;
|
|
42
|
+
constructor(config: ComponentBuilderConfig<Component>);
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new instance of module factory
|
|
45
|
+
* Module factory provides a module (file) including all exports.
|
|
46
|
+
* Module can be imported dynamically or statically.
|
|
47
|
+
* @returns {ModuleFactory} Module factory implementation
|
|
48
|
+
*/
|
|
49
|
+
getModuleFactory(): ModuleFactory;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new instance of component factory
|
|
52
|
+
* Component can be imported dynamically or statically.
|
|
53
|
+
* @param {object} [config] Component factory configuration
|
|
54
|
+
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
55
|
+
* @returns {ComponentFactory} Component factory implementation
|
|
56
|
+
*/
|
|
57
|
+
getComponentFactory({ isEditing }?: ComponentFactoryConfig): ComponentFactory;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BYOCWrapper } from '@sitecore-content-sdk/react';
|
|
2
|
+
import { GetStaticComponentProps, GetServerSideComponentProps } from '../sharedTypes/component-props';
|
|
3
|
+
/**
|
|
4
|
+
* TODO: remove when framework agnostic forms implemented
|
|
5
|
+
* This is a repackaged version of the React BYOCWrapper component with support for
|
|
6
|
+
* server rendering in Next.js (using component-level data-fetching feature of JSS).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Will be called during SSG
|
|
10
|
+
* @param {ComponentRendering} rendering
|
|
11
|
+
* @returns {GetStaticPropsContext} context
|
|
12
|
+
*/
|
|
13
|
+
export declare const getStaticProps: GetStaticComponentProps;
|
|
14
|
+
/**
|
|
15
|
+
* Will be called during SSR
|
|
16
|
+
* @param {ComponentRendering} rendering
|
|
17
|
+
* @returns {GetStaticPropsContext} context
|
|
18
|
+
*/
|
|
19
|
+
export declare const getServerSideProps: GetServerSideComponentProps;
|
|
20
|
+
export default BYOCWrapper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ComponentPropsCollection } from '../sharedTypes/component-props';
|
|
3
|
+
/**
|
|
4
|
+
* Component props context which we are using in order to store data fetched on components level (getStaticProps/getServerSideProps)
|
|
5
|
+
*/
|
|
6
|
+
export declare const ComponentPropsReactContext: React.Context<ComponentPropsCollection>;
|
|
7
|
+
/**
|
|
8
|
+
* Hook in order to get access to props related to specific component. Data comes from ComponentPropsContext.
|
|
9
|
+
* @see ComponentPropsContext
|
|
10
|
+
* @param {string | undefined} componentUid component uId
|
|
11
|
+
* @returns {ComponentData | undefined} component props
|
|
12
|
+
*/
|
|
13
|
+
export declare function useComponentProps<ComponentData>(componentUid: string | undefined): ComponentData | undefined;
|
|
14
|
+
export type ComponentPropsContextProps = {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
value: ComponentPropsCollection;
|
|
17
|
+
};
|
|
18
|
+
export declare const ComponentPropsContext: ({ children, value, }: ComponentPropsContextProps) => JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { FEaaSWrapper } from '@sitecore-content-sdk/react';
|
|
2
|
+
import { GetStaticComponentProps, GetServerSideComponentProps } from '../sharedTypes/component-props';
|
|
3
|
+
/**
|
|
4
|
+
* TODO: remove when framework agnostic forms implemented
|
|
5
|
+
* This is a repackaged version of the React FEaaSWrapper component with support for
|
|
6
|
+
* server rendering in Next.js (using component-level data-fetching feature of JSS).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Will be called during SSG
|
|
10
|
+
* @param {ComponentRendering} rendering
|
|
11
|
+
* @param {LayoutServiceData} layoutData
|
|
12
|
+
* @returns {GetStaticPropsContext} context
|
|
13
|
+
*/
|
|
14
|
+
export declare const getStaticProps: GetStaticComponentProps;
|
|
15
|
+
/**
|
|
16
|
+
* Will be called during SSR
|
|
17
|
+
* @param {ComponentRendering} rendering
|
|
18
|
+
* @param {LayoutServiceData} layoutData
|
|
19
|
+
* @returns {GetStaticPropsContext} context
|
|
20
|
+
*/
|
|
21
|
+
export declare const getServerSideProps: GetServerSideComponentProps;
|
|
22
|
+
export default FEaaSWrapper;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LinkProps as ReactLinkProps } from '@sitecore-content-sdk/react';
|
|
3
|
+
export type LinkProps = ReactLinkProps & {
|
|
4
|
+
/**
|
|
5
|
+
* If `href` match with `internalLinkMatcher` regexp, then it's internal link and NextLink will be rendered
|
|
6
|
+
* @default /^\//g
|
|
7
|
+
*/
|
|
8
|
+
internalLinkMatcher?: RegExp;
|
|
9
|
+
};
|
|
10
|
+
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageProps } from '@sitecore-content-sdk/react';
|
|
3
|
+
import { ImageProps as NextImageProperties } from 'next/image';
|
|
4
|
+
type NextImageProps = ImageProps & Partial<NextImageProperties>;
|
|
5
|
+
export declare const NextImage: React.FC<NextImageProps>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { PlaceholderComponentProps, WithSitecoreContextProps, EnhancedOmit } from '@sitecore-content-sdk/react';
|
|
3
|
+
/**
|
|
4
|
+
* React Placeholder component wrapped by withSitecoreContext, so these properties shouldn't be passed to the Next.js Placeholder.
|
|
5
|
+
*/
|
|
6
|
+
type PlaceholderProps = EnhancedOmit<PlaceholderComponentProps, keyof WithSitecoreContextProps>;
|
|
7
|
+
export declare const Placeholder: (props: PlaceholderProps) => React.JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { RichTextProps as ReactRichTextProps } from '@sitecore-content-sdk/react';
|
|
4
|
+
export type RichTextProps = ReactRichTextProps & {
|
|
5
|
+
/**
|
|
6
|
+
* Selector which should be used in order to prefetch it and attach event listeners
|
|
7
|
+
* @default 'a[href^="/"]'
|
|
8
|
+
*/
|
|
9
|
+
internalLinksSelector?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Controls the prefetch of internal links. This can be beneficial if you have RichText fields
|
|
12
|
+
* with large numbers of internal links in them.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
prefetchLinks?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare const RichText: {
|
|
18
|
+
(props: RichTextProps): JSX.Element;
|
|
19
|
+
propTypes: {
|
|
20
|
+
field: PropTypes.Requireable<PropTypes.InferProps<{
|
|
21
|
+
value: PropTypes.Requireable<string>;
|
|
22
|
+
metadata: PropTypes.Requireable<{
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}>;
|
|
25
|
+
}>>;
|
|
26
|
+
tag: PropTypes.Requireable<string>;
|
|
27
|
+
editable: PropTypes.Requireable<boolean>;
|
|
28
|
+
emptyFieldEditingComponent: PropTypes.Requireable<NonNullable<React.ComponentClass<unknown, any> | React.FC<unknown>>>;
|
|
29
|
+
internalLinksSelector: PropTypes.Requireable<string>;
|
|
30
|
+
};
|
|
31
|
+
displayName: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = "x-vercel-protection-bypass";
|
|
2
|
+
export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass-cookie";
|
|
3
|
+
/**
|
|
4
|
+
* Headers that should be passed along to (Editing Chromes handler) SSR request.
|
|
5
|
+
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const EDITING_PASS_THROUGH_HEADERS: string[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { Metadata } from '@sitecore-content-sdk/dev-tools';
|
|
3
|
+
export type EditingConfigMiddlewareConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* Components available in the application
|
|
6
|
+
*/
|
|
7
|
+
components: string[] | Map<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Application metadata
|
|
10
|
+
*/
|
|
11
|
+
metadata: Metadata;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Middleware / handler used in the editing config API route in xmcloud add on (e.g. '/api/editing/config')
|
|
15
|
+
* provides configuration information to determine feature compatibility on Pages side.
|
|
16
|
+
*/
|
|
17
|
+
export declare class EditingConfigMiddleware {
|
|
18
|
+
protected config: EditingConfigMiddlewareConfig;
|
|
19
|
+
/**
|
|
20
|
+
* @param {EditingConfigMiddlewareConfig} [config] Editing configuration middleware config
|
|
21
|
+
*/
|
|
22
|
+
constructor(config: EditingConfigMiddlewareConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Gets the Next.js API route handler
|
|
25
|
+
* @returns middleware handler
|
|
26
|
+
*/
|
|
27
|
+
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
28
|
+
private handler;
|
|
29
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { LayoutServicePageState } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
import { EditingRenderQueryParams, LayoutKind } from '@sitecore-content-sdk/core/editing';
|
|
4
|
+
import { RenderMiddlewareBase } from './render-middleware';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the Editing Render Middleware.
|
|
7
|
+
*/
|
|
8
|
+
export type EditingRenderMiddlewareConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Function used to determine route/page URL to render.
|
|
11
|
+
* This may be necessary for certain custom Next.js routing configurations.
|
|
12
|
+
* @param {string} itemPath The Sitecore relative item path e.g. '/styleguide'
|
|
13
|
+
* @returns {string} The URL to render
|
|
14
|
+
* @default `${itemPath}`
|
|
15
|
+
*/
|
|
16
|
+
resolvePageUrl?: (itemPath: string) => string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Next.js API request with editing request query parameters.
|
|
20
|
+
*/
|
|
21
|
+
export type EditingNextApiRequest = NextApiRequest & {
|
|
22
|
+
query: EditingRenderQueryParams;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Data for Next.js Preview (Editing) Mode.
|
|
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
|
|
53
|
+
* @param {object} data preview data to check
|
|
54
|
+
* @returns true if the data is EditingPreviewData
|
|
55
|
+
* @see EditingPreviewData
|
|
56
|
+
*/
|
|
57
|
+
export declare const isComponentLibraryPreviewData: (data: unknown) => data is ComponentLibraryRenderPreviewData;
|
|
58
|
+
/**
|
|
59
|
+
* Middleware / handler for use in the editing render Next.js API route (e.g. '/api/editing/render')
|
|
60
|
+
* which is required for Sitecore editing support.
|
|
61
|
+
*/
|
|
62
|
+
export declare class EditingRenderMiddleware extends RenderMiddlewareBase {
|
|
63
|
+
config?: EditingRenderMiddlewareConfig | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* @param {EditingRenderMiddlewareConfig} [config] Editing render middleware config
|
|
66
|
+
*/
|
|
67
|
+
constructor(config?: EditingRenderMiddlewareConfig | undefined);
|
|
68
|
+
/**
|
|
69
|
+
* Gets the Next.js API route handler
|
|
70
|
+
* @returns route handler
|
|
71
|
+
*/
|
|
72
|
+
getHandler(): (req: EditingNextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the Content-Security-Policy header value
|
|
75
|
+
* @returns Content-Security-Policy header value
|
|
76
|
+
*/
|
|
77
|
+
private getSCPHeader;
|
|
78
|
+
private handler;
|
|
79
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { RenderMiddlewareBase } from './render-middleware';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for `FEAASRenderMiddleware`.
|
|
5
|
+
*/
|
|
6
|
+
export interface FEAASRenderMiddlewareConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Defines FEAAS page route to render.
|
|
9
|
+
* This may be necessary for certain custom Next.js routing configurations.
|
|
10
|
+
* @default /feaas/render
|
|
11
|
+
*/
|
|
12
|
+
pageUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Middleware / handler for use in the feaas render Next.js API route (e.g. '/api/editing/feaas/render')
|
|
16
|
+
* which is required for Sitecore editing support.
|
|
17
|
+
*/
|
|
18
|
+
export declare class FEAASRenderMiddleware extends RenderMiddlewareBase {
|
|
19
|
+
protected config?: FEAASRenderMiddlewareConfig | undefined;
|
|
20
|
+
private pageUrl;
|
|
21
|
+
private defaultPageUrl;
|
|
22
|
+
/**
|
|
23
|
+
* @param {EditingRenderMiddlewareConfig} [config] Editing render middleware config
|
|
24
|
+
*/
|
|
25
|
+
constructor(config?: FEAASRenderMiddlewareConfig | undefined);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the Next.js API route handler
|
|
28
|
+
* @returns route handler
|
|
29
|
+
*/
|
|
30
|
+
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
31
|
+
private handler;
|
|
32
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GraphQLEditingService } from '@sitecore-content-sdk/core/editing';
|
|
2
|
+
export { EditingRenderMiddleware, EditingRenderMiddlewareConfig, isComponentLibraryPreviewData, EditingPreviewData, } from './editing-render-middleware';
|
|
3
|
+
export { FEAASRenderMiddleware, FEAASRenderMiddlewareConfig } from './feaas-render-middleware';
|
|
4
|
+
export { EditingConfigMiddleware, EditingConfigMiddlewareConfig, } from './editing-config-middleware';
|
|
5
|
+
export { RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-content-sdk/core/layout';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IncomingHttpHeaders } from 'http';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for middleware that handles pages and components rendering in Sitecore Editors.
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class RenderMiddlewareBase {
|
|
6
|
+
/**
|
|
7
|
+
* Gets query parameters that should be passed along to subsequent requests (e.g. for deployment protection bypass)
|
|
8
|
+
* @param {object} query Object of query parameters from incoming URL
|
|
9
|
+
* @returns Object of approved query parameters
|
|
10
|
+
*/
|
|
11
|
+
protected getQueryParamsForPropagation: (query: Partial<{
|
|
12
|
+
[key: string]: string | string[];
|
|
13
|
+
}>) => {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get headers that should be passed along to subsequent requests
|
|
18
|
+
* @param {IncomingHttpHeaders} headers Incoming HTTP Headers
|
|
19
|
+
* @returns Object of approved headers
|
|
20
|
+
*/
|
|
21
|
+
protected getHeadersForPropagation: (headers: IncomingHttpHeaders) => {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLClientError, RetryStrategy, DefaultRetryStrategy, GraphQLRequestClient, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, getEdgeProxyContentUrl, } from '@sitecore-content-sdk/core/graphql';
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export { constants, NativeDataFetcher, NativeDataFetcherConfig, NativeDataFetcherResponse, NativeDataFetcherError, HTMLLink, enableDebug, debug, CacheClient, CacheOptions, MemoryCacheClient, } from '@sitecore-content-sdk/core';
|
|
2
|
+
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, getContentStylesheetLink, EditMode, } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
export { RestComponentLayoutService } from '@sitecore-content-sdk/core/editing';
|
|
4
|
+
export { mediaApi } from '@sitecore-content-sdk/core/media';
|
|
5
|
+
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, } from '@sitecore-content-sdk/core/i18n';
|
|
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 { ModuleFactory, Module } from './sharedTypes/module-factory';
|
|
9
|
+
export { ComponentPropsService } from './services/component-props-service';
|
|
10
|
+
export { GraphQLSitemapService, GraphQLSitemapServiceConfig, } from './services/graphql-sitemap-service';
|
|
11
|
+
export { MultisiteGraphQLSitemapService, MultisiteGraphQLSitemapServiceConfig, } from './services/mutisite-graphql-sitemap-service';
|
|
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
|
+
export { ComponentPropsReactContext, ComponentPropsContextProps, ComponentPropsContext, useComponentProps, } from './components/ComponentPropsContext';
|
|
15
|
+
export { Link, LinkProps } from './components/Link';
|
|
16
|
+
export { RichText, RichTextProps } from './components/RichText';
|
|
17
|
+
export { Placeholder } from './components/Placeholder';
|
|
18
|
+
export { NextImage } from './components/NextImage';
|
|
19
|
+
import * as FEaaSWrapper from './components/FEaaSWrapper';
|
|
20
|
+
import * as BYOCWrapper from './components/BYOCWrapper';
|
|
21
|
+
export { FEaaSWrapper };
|
|
22
|
+
export { BYOCWrapper };
|
|
23
|
+
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
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';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { debug } from '@sitecore-content-sdk/core';
|
|
2
|
+
export { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
|
+
export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-middleware';
|
|
4
|
+
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
5
|
+
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SiteInfo, SiteResolver } from '@sitecore-content-sdk/core/site';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
export type MiddlewareBaseConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* function, determines if middleware should be turned off, based on cookie, header, or other considerations
|
|
6
|
+
* @param {NextRequest} [req] request object from middleware handler
|
|
7
|
+
* @param {NextResponse} [res] response object from middleware handler
|
|
8
|
+
*/
|
|
9
|
+
disabled?: (req?: NextRequest, res?: NextResponse) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Function used to determine if route should be excluded.
|
|
12
|
+
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
13
|
+
* This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
14
|
+
* @param {string} pathname The pathname
|
|
15
|
+
* @returns {boolean} Whether to exclude the route
|
|
16
|
+
*/
|
|
17
|
+
excludeRoute?: (pathname: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Fallback hostname in case `host` header is not present
|
|
20
|
+
* @default localhost
|
|
21
|
+
*/
|
|
22
|
+
defaultHostname?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Site resolution implementation by name/hostname
|
|
25
|
+
*/
|
|
26
|
+
siteResolver: SiteResolver;
|
|
27
|
+
};
|
|
28
|
+
export declare abstract class MiddlewareBase {
|
|
29
|
+
protected config: MiddlewareBaseConfig;
|
|
30
|
+
protected SITE_SYMBOL: string;
|
|
31
|
+
protected REWRITE_HEADER_NAME: string;
|
|
32
|
+
protected defaultHostname: string;
|
|
33
|
+
constructor(config: MiddlewareBaseConfig);
|
|
34
|
+
/**
|
|
35
|
+
* Determines if mode is preview
|
|
36
|
+
* @param {NextRequest} req request
|
|
37
|
+
* @returns {boolean} is preview
|
|
38
|
+
*/
|
|
39
|
+
protected isPreview(req: NextRequest): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Determines if the request is a Next.js (next/link) prefetch request
|
|
42
|
+
* @param {NextRequest} req request
|
|
43
|
+
* @returns {boolean} is prefetch
|
|
44
|
+
*/
|
|
45
|
+
protected isPrefetch(req: NextRequest): boolean;
|
|
46
|
+
protected excludeRoute(pathname: string): boolean | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Safely extract all headers for debug logging
|
|
49
|
+
* Necessary to avoid middleware issue https://github.com/vercel/next.js/issues/39765
|
|
50
|
+
* @param {Headers} incomingHeaders Incoming headers
|
|
51
|
+
* @returns Object with headers as key/value pairs
|
|
52
|
+
*/
|
|
53
|
+
protected extractDebugHeaders(incomingHeaders: Headers): {
|
|
54
|
+
[key: string]: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Provides used language
|
|
58
|
+
* @param {NextRequest} req request
|
|
59
|
+
* @returns {string} language
|
|
60
|
+
*/
|
|
61
|
+
protected getLanguage(req: NextRequest): string;
|
|
62
|
+
/**
|
|
63
|
+
* Extract 'host' header
|
|
64
|
+
* @param {NextRequest} req request
|
|
65
|
+
*/
|
|
66
|
+
protected getHostHeader(req: NextRequest): string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Get site information.
|
|
69
|
+
* Can not be used in **Preview** mode, since site will not be resolved
|
|
70
|
+
* @param {NextRequest} req request
|
|
71
|
+
* @param {NextResponse} [res] response
|
|
72
|
+
* @returns {SiteInfo} site information
|
|
73
|
+
*/
|
|
74
|
+
protected getSite(req: NextRequest, res?: NextResponse): SiteInfo;
|
|
75
|
+
/**
|
|
76
|
+
* Create a rewrite response
|
|
77
|
+
* @param {string} rewritePath the destionation path
|
|
78
|
+
* @param {NextRequest} req the current request
|
|
79
|
+
* @param {NextResponse} res the current response
|
|
80
|
+
*/
|
|
81
|
+
protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse): NextResponse;
|
|
82
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
|
+
export type CookieAttributes = {
|
|
4
|
+
/**
|
|
5
|
+
* the Secure attribute of the site cookie
|
|
6
|
+
*/
|
|
7
|
+
secure: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* the HttpOnly attribute of the site cookie
|
|
10
|
+
*/
|
|
11
|
+
httpOnly: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* the SameSite attribute of the site cookie
|
|
14
|
+
*/
|
|
15
|
+
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined;
|
|
16
|
+
};
|
|
17
|
+
export type MultisiteMiddlewareConfig = Omit<MiddlewareBaseConfig, 'disabled'> & {
|
|
18
|
+
/**
|
|
19
|
+
* Function used to determine if site should be resolved from sc_site cookie when present
|
|
20
|
+
*/
|
|
21
|
+
useCookieResolution?: (req: NextRequest) => boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Middleware / handler for multisite support
|
|
25
|
+
*/
|
|
26
|
+
export declare class MultisiteMiddleware extends MiddlewareBase {
|
|
27
|
+
protected config: MultisiteMiddlewareConfig;
|
|
28
|
+
/**
|
|
29
|
+
* @param {MultisiteMiddlewareConfig} [config] Multisite middleware config
|
|
30
|
+
*/
|
|
31
|
+
constructor(config: MultisiteMiddlewareConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Gets the Next.js middleware handler with error handling
|
|
34
|
+
* @returns middleware handler
|
|
35
|
+
*/
|
|
36
|
+
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
37
|
+
protected excludeRoute(pathname: string): boolean | undefined;
|
|
38
|
+
private handler;
|
|
39
|
+
}
|