@sitecore-jss/sitecore-jss-nextjs 22.0.0-canary.38 → 22.0.0-canary.42
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 -3
- package/context.d.ts +1 -0
- package/context.js +1 -0
- package/dist/cjs/ComponentBuilder.js +63 -0
- package/dist/cjs/components/BYOCWrapper.js +47 -0
- package/dist/cjs/components/FEaaSWrapper.js +49 -0
- package/dist/cjs/components/NextImage.js +2 -10
- package/dist/cjs/components/RichText.js +10 -10
- package/dist/cjs/context/context.js +83 -0
- package/dist/cjs/context/index.js +5 -0
- package/dist/cjs/editing/constants.js +6 -0
- package/dist/cjs/editing/editing-config-middleware.js +49 -0
- package/dist/cjs/editing/editing-data-middleware.js +2 -2
- package/dist/cjs/editing/editing-data-service.js +15 -7
- package/dist/cjs/editing/editing-render-middleware.js +24 -10
- package/dist/cjs/editing/feaas-render-middleware.js +87 -0
- package/dist/cjs/editing/index.js +7 -1
- package/dist/cjs/editing/render-middleware.js +27 -0
- package/dist/cjs/editing/vercel-editing-data-cache.js +48 -0
- package/dist/cjs/graphql/index.js +7 -0
- package/dist/cjs/index.js +37 -25
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/middleware.js +18 -2
- package/dist/cjs/middleware/multisite-middleware.js +14 -8
- package/dist/cjs/middleware/personalize-middleware.js +62 -56
- package/dist/cjs/middleware/redirects-middleware.js +48 -25
- package/dist/cjs/services/base-graphql-sitemap-service.js +7 -6
- package/dist/cjs/services/component-props-service.js +6 -6
- package/dist/cjs/utils/utils.js +7 -16
- package/dist/esm/ComponentBuilder.js +59 -0
- package/dist/esm/components/BYOCWrapper.js +42 -0
- package/dist/esm/components/FEaaSWrapper.js +44 -0
- package/dist/esm/components/NextImage.js +1 -8
- package/dist/esm/components/RichText.js +10 -10
- package/dist/esm/context/context.js +79 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/editing/constants.js +3 -0
- package/dist/esm/editing/editing-config-middleware.js +45 -0
- package/dist/esm/editing/editing-data-middleware.js +1 -1
- package/dist/esm/editing/editing-data-service.js +13 -5
- package/dist/esm/editing/editing-render-middleware.js +24 -10
- package/dist/esm/editing/feaas-render-middleware.js +83 -0
- package/dist/esm/editing/index.js +3 -0
- package/dist/esm/editing/render-middleware.js +23 -0
- package/dist/esm/editing/vercel-editing-data-cache.js +44 -0
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +10 -20
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/middleware.js +18 -2
- package/dist/esm/middleware/multisite-middleware.js +14 -8
- package/dist/esm/middleware/personalize-middleware.js +65 -59
- package/dist/esm/middleware/redirects-middleware.js +48 -25
- package/dist/esm/services/base-graphql-sitemap-service.js +7 -6
- package/dist/esm/services/component-props-service.js +6 -6
- package/dist/esm/utils/utils.js +7 -13
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/package.json +15 -12
- package/types/ComponentBuilder.d.ts +61 -0
- package/types/components/BYOCWrapper.d.ts +19 -0
- package/types/components/ComponentPropsContext.d.ts +1 -0
- package/types/components/FEaaSWrapper.d.ts +21 -0
- package/types/components/Link.d.ts +2 -1
- package/types/components/NextImage.d.ts +3 -3
- package/types/components/Placeholder.d.ts +3 -1
- package/types/components/RichText.d.ts +6 -0
- package/types/context/context.d.ts +116 -0
- package/types/context/index.d.ts +1 -0
- package/types/editing/constants.d.ts +3 -0
- package/types/editing/editing-config-middleware.d.ts +29 -0
- package/types/editing/editing-data-service.d.ts +12 -4
- package/types/editing/editing-render-middleware.d.ts +2 -1
- package/types/editing/feaas-render-middleware.d.ts +32 -0
- package/types/editing/index.d.ts +3 -0
- package/types/editing/render-middleware.d.ts +15 -0
- package/types/editing/vercel-editing-data-cache.d.ts +19 -0
- package/types/graphql/index.d.ts +1 -0
- package/types/index.d.ts +12 -12
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/middleware.d.ts +8 -0
- package/types/middleware/multisite-middleware.d.ts +15 -0
- package/types/middleware/personalize-middleware.d.ts +53 -14
- package/types/services/base-graphql-sitemap-service.d.ts +7 -10
- package/types/services/component-props-service.d.ts +2 -2
- package/types/sharedTypes/component-props.d.ts +5 -1
- package/types/sharedTypes/module-factory.d.ts +33 -0
- package/types/utils/utils.d.ts +2 -0
- package/types/sharedTypes/component-module.d.ts +0 -13
- /package/dist/cjs/sharedTypes/{component-module.js → module-factory.js} +0 -0
- /package/dist/esm/sharedTypes/{component-module.js → module-factory.js} +0 -0
|
@@ -12,7 +12,8 @@ import { NextResponse } from 'next/server';
|
|
|
12
12
|
import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-jss/sitecore-jss/site';
|
|
13
13
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
14
14
|
import { MiddlewareBase } from './middleware';
|
|
15
|
-
const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, '
|
|
15
|
+
const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, 'i');
|
|
16
|
+
const REGEXP_ABSOLUTE_URL = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
16
17
|
/**
|
|
17
18
|
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
18
19
|
* compares with current url and redirects to target url
|
|
@@ -29,13 +30,14 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
29
30
|
const language = this.getLanguage(req);
|
|
30
31
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
31
32
|
let site;
|
|
33
|
+
const startTimestamp = Date.now();
|
|
32
34
|
debug.redirects('redirects middleware start: %o', {
|
|
33
35
|
pathname,
|
|
34
36
|
language,
|
|
35
37
|
hostname,
|
|
36
38
|
});
|
|
37
39
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
if (this.config.disabled && this.config.disabled(req, NextResponse.next())) {
|
|
40
|
+
if (this.config.disabled && this.config.disabled(req, res || NextResponse.next())) {
|
|
39
41
|
debug.redirects('skipped (redirects middleware is disabled)');
|
|
40
42
|
return res || NextResponse.next();
|
|
41
43
|
}
|
|
@@ -51,44 +53,58 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
51
53
|
return res || NextResponse.next();
|
|
52
54
|
}
|
|
53
55
|
// Find context site language and replace token
|
|
54
|
-
if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target)
|
|
56
|
+
if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
|
|
57
|
+
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
58
|
+
existsRedirect.target.includes(hostname))) {
|
|
55
59
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
56
60
|
}
|
|
57
61
|
const url = req.nextUrl.clone();
|
|
58
|
-
|
|
59
|
-
if (absoluteUrlRegex.test(existsRedirect.target)) {
|
|
62
|
+
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
60
63
|
url.href = existsRedirect.target;
|
|
61
|
-
url.locale = req.nextUrl.locale;
|
|
62
64
|
}
|
|
63
65
|
else {
|
|
66
|
+
const source = `${url.pathname}${url.search}`;
|
|
64
67
|
url.search = existsRedirect.isQueryStringPreserved ? url.search : '';
|
|
65
68
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
66
69
|
if (this.locales.includes(urlFirstPart)) {
|
|
67
70
|
url.locale = urlFirstPart;
|
|
68
|
-
|
|
71
|
+
existsRedirect.target = existsRedirect.target.replace(`/${urlFirstPart}`, '');
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const target = source
|
|
74
|
+
.replace(regexParser(existsRedirect.pattern), existsRedirect.target)
|
|
75
|
+
.replace(/^\/\//, '/')
|
|
76
|
+
.split('?');
|
|
77
|
+
url.pathname = target[0];
|
|
78
|
+
if (target[1]) {
|
|
79
|
+
const newParams = new URLSearchParams(target[1]);
|
|
80
|
+
for (const [key, val] of newParams.entries()) {
|
|
81
|
+
url.searchParams.append(key, val);
|
|
82
|
+
}
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
const redirectUrl = decodeURIComponent(url.href);
|
|
75
86
|
/** return Response redirect with http code of redirect type **/
|
|
76
87
|
switch (existsRedirect.redirectType) {
|
|
77
88
|
case REDIRECT_TYPE_301:
|
|
78
|
-
return NextResponse.redirect(redirectUrl,
|
|
89
|
+
return NextResponse.redirect(redirectUrl, {
|
|
90
|
+
status: 301,
|
|
91
|
+
statusText: 'Moved Permanently',
|
|
92
|
+
headers: res === null || res === void 0 ? void 0 : res.headers,
|
|
93
|
+
});
|
|
79
94
|
case REDIRECT_TYPE_302:
|
|
80
|
-
return NextResponse.redirect(redirectUrl,
|
|
95
|
+
return NextResponse.redirect(redirectUrl, {
|
|
96
|
+
status: 302,
|
|
97
|
+
statusText: 'Found',
|
|
98
|
+
headers: res === null || res === void 0 ? void 0 : res.headers,
|
|
99
|
+
});
|
|
81
100
|
case REDIRECT_TYPE_SERVER_TRANSFER:
|
|
82
|
-
return NextResponse.rewrite(redirectUrl);
|
|
101
|
+
return NextResponse.rewrite(redirectUrl, res);
|
|
83
102
|
default:
|
|
84
|
-
return NextResponse.next();
|
|
103
|
+
return res || NextResponse.next();
|
|
85
104
|
}
|
|
86
105
|
});
|
|
87
106
|
const response = yield createResponse();
|
|
88
|
-
|
|
89
|
-
// Don't need to set when middleware is disabled
|
|
90
|
-
site && response.cookies.set(this.SITE_SYMBOL, site.name);
|
|
91
|
-
debug.redirects('redirects middleware end: %o', {
|
|
107
|
+
debug.redirects('redirects middleware end in %dms: %o', Date.now() - startTimestamp, {
|
|
92
108
|
redirected: response.redirected,
|
|
93
109
|
status: response.status,
|
|
94
110
|
url: response.url,
|
|
@@ -128,15 +144,22 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
128
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
145
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
130
146
|
const tragetURL = req.nextUrl.pathname;
|
|
131
|
-
const targetQS =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
const targetQS = req.nextUrl.search || '';
|
|
148
|
+
const language = this.getLanguage(req);
|
|
149
|
+
const modifyRedirects = structuredClone(redirects);
|
|
150
|
+
return modifyRedirects.length
|
|
151
|
+
? modifyRedirects.find((redirect) => {
|
|
152
|
+
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
153
|
+
redirect.pattern = `/^\/${redirect.pattern
|
|
135
154
|
.replace(/^\/|\/$/g, '')
|
|
136
|
-
.replace(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
155
|
+
.replace(/^\^\/|\/\$$/g, '')
|
|
156
|
+
.replace(/^\^|\$$/g, '')
|
|
157
|
+
.replace(/(?<!\\)\?/g, '\\?')
|
|
158
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/gi`;
|
|
159
|
+
return ((regexParser(redirect.pattern).test(tragetURL) ||
|
|
160
|
+
regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
161
|
+
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
162
|
+
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}${targetQS}`)) &&
|
|
140
163
|
(redirect.locale
|
|
141
164
|
? redirect.locale.toLowerCase() === req.nextUrl.locale.toLowerCase()
|
|
142
165
|
: true));
|
|
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss/graphql';
|
|
11
10
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
12
11
|
import { getPersonalizedRewrite } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
12
|
/** @private */
|
|
@@ -32,7 +31,7 @@ query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
|
32
31
|
$language: String!
|
|
33
32
|
$includedPaths: [String]
|
|
34
33
|
$excludedPaths: [String]
|
|
35
|
-
$pageSize: Int =
|
|
34
|
+
$pageSize: Int = 100
|
|
36
35
|
$after: String
|
|
37
36
|
) {
|
|
38
37
|
site {
|
|
@@ -128,7 +127,7 @@ export class BaseGraphQLSitemapService {
|
|
|
128
127
|
getTranformedPaths(siteName, languages, formatStaticPath) {
|
|
129
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
129
|
const paths = new Array();
|
|
131
|
-
|
|
130
|
+
for (const language of languages) {
|
|
132
131
|
if (language === '') {
|
|
133
132
|
throw new RangeError(languageEmptyError);
|
|
134
133
|
}
|
|
@@ -136,7 +135,7 @@ export class BaseGraphQLSitemapService {
|
|
|
136
135
|
const results = yield this.fetchLanguageSitePaths(language, siteName);
|
|
137
136
|
const transformedPaths = yield this.transformLanguageSitePaths(results, formatStaticPath, language);
|
|
138
137
|
paths.push(...transformedPaths);
|
|
139
|
-
}
|
|
138
|
+
}
|
|
140
139
|
return paths;
|
|
141
140
|
});
|
|
142
141
|
}
|
|
@@ -191,8 +190,10 @@ export class BaseGraphQLSitemapService {
|
|
|
191
190
|
* @returns {GraphQLClient} implementation
|
|
192
191
|
*/
|
|
193
192
|
getGraphQLClient() {
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
if (!this.options.clientFactory) {
|
|
194
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
195
|
+
}
|
|
196
|
+
return this.options.clientFactory({
|
|
196
197
|
debugger: debug.sitemap,
|
|
197
198
|
});
|
|
198
199
|
}
|
|
@@ -17,9 +17,9 @@ export class ComponentPropsService {
|
|
|
17
17
|
*/
|
|
18
18
|
fetchServerSideComponentProps(params) {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const {
|
|
20
|
+
const { moduleFactory, layoutData, context } = params;
|
|
21
21
|
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const module = yield
|
|
22
|
+
const module = yield moduleFactory(componentName);
|
|
23
23
|
return module === null || module === void 0 ? void 0 : module.getServerSideProps;
|
|
24
24
|
});
|
|
25
25
|
return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
|
|
@@ -33,9 +33,9 @@ export class ComponentPropsService {
|
|
|
33
33
|
*/
|
|
34
34
|
fetchStaticComponentProps(params) {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const {
|
|
36
|
+
const { moduleFactory, layoutData, context } = params;
|
|
37
37
|
const fetchFunctionFactory = (componentName) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const module = yield
|
|
38
|
+
const module = yield moduleFactory(componentName);
|
|
39
39
|
return module === null || module === void 0 ? void 0 : module.getStaticProps;
|
|
40
40
|
});
|
|
41
41
|
return this.fetchComponentProps(fetchFunctionFactory, layoutData, context);
|
|
@@ -122,11 +122,11 @@ export class ComponentPropsService {
|
|
|
122
122
|
componentProps[uid] = result;
|
|
123
123
|
})
|
|
124
124
|
.catch((error) => {
|
|
125
|
-
const errLog = `Error during preload data for component ${uid}: ${error.message ||
|
|
126
|
-
error}`;
|
|
125
|
+
const errLog = `Error during preload data for component ${req.rendering.componentName} (${uid}): ${error.message || error}`;
|
|
127
126
|
console.error(chalk.red(errLog));
|
|
128
127
|
componentProps[uid] = {
|
|
129
128
|
error: error.message || errLog,
|
|
129
|
+
componentName: req.rendering.componentName,
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
});
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
2
|
/**
|
|
4
3
|
* Get the publicUrl.
|
|
@@ -6,25 +5,20 @@ import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/u
|
|
|
6
5
|
* This is set to http://localhost:3000 by default.
|
|
7
6
|
* VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
|
|
8
7
|
* preview deployment has unique url, we don't know exact url.
|
|
8
|
+
* Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
|
|
9
|
+
* In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
|
|
9
10
|
*/
|
|
10
11
|
export const getPublicUrl = () => {
|
|
11
|
-
if (process.env.VERCEL_URL)
|
|
12
|
-
return `https://${process.env.VERCEL_URL}`;
|
|
13
12
|
let url = process.env.PUBLIC_URL;
|
|
14
13
|
if (url === undefined) {
|
|
15
|
-
|
|
14
|
+
if (process.env.NETLIFY && process.env.DEPLOY_URL)
|
|
15
|
+
return process.env.DEPLOY_URL;
|
|
16
|
+
if (process.env.VERCEL_URL)
|
|
17
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
16
18
|
url = 'http://localhost:3000';
|
|
17
19
|
}
|
|
18
|
-
else {
|
|
19
|
-
try {
|
|
20
|
-
new URL(url);
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
throw new Error(`The PUBLIC_URL environment variable '${url}' is not a valid URL.`);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
20
|
// Ensure no trailing slash
|
|
27
|
-
return url.
|
|
21
|
+
return url.replace(/\/$/, '');
|
|
28
22
|
};
|
|
29
23
|
/**
|
|
30
24
|
* Since Sitecore editors do not support Fast Refresh:
|
package/graphql.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/graphql/index';
|
package/graphql.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/graphql/index');
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.0.0-canary.
|
|
3
|
+
"version": "22.0.0-canary.42",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
9
9
|
"clean": "del-cli dist types",
|
|
10
|
-
"lint": "eslint ./src/**/*.tsx ./src/**/*.ts",
|
|
10
|
+
"lint": "eslint \"./src/**/*.tsx\" \"./src/**/*.ts\"",
|
|
11
11
|
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"coverage": "nyc npm test",
|
|
14
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --githubPages false"
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-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"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
-
"npm": ">=6"
|
|
17
|
+
"node": ">=18"
|
|
19
18
|
},
|
|
20
19
|
"author": {
|
|
21
20
|
"name": "Sitecore Corporation",
|
|
@@ -30,6 +29,7 @@
|
|
|
30
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
32
|
+
"@sitecore-cloudsdk/personalize": "^0.3.0",
|
|
33
33
|
"@types/chai": "^4.3.4",
|
|
34
34
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
35
|
"@types/chai-string": "^1.4.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@types/mocha": "^10.0.1",
|
|
38
38
|
"@types/node": "~18.11.18",
|
|
39
39
|
"@types/prop-types": "^15.7.5",
|
|
40
|
-
"@types/react": "^18.
|
|
40
|
+
"@types/react": "^18.2.22",
|
|
41
41
|
"@types/react-dom": "^18.0.10",
|
|
42
42
|
"@types/sinon": "^10.0.13",
|
|
43
43
|
"@types/sinon-chai": "^3.2.9",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"eslint-plugin-react": "^7.32.1",
|
|
55
55
|
"jsdom": "^21.1.0",
|
|
56
56
|
"mocha": "^10.2.0",
|
|
57
|
-
"next": "^
|
|
57
|
+
"next": "^14.1.0",
|
|
58
58
|
"nock": "^13.3.0",
|
|
59
59
|
"nyc": "^15.1.0",
|
|
60
60
|
"react": "^18.2.0",
|
|
@@ -65,14 +65,17 @@
|
|
|
65
65
|
"typescript": "~4.9.4"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"
|
|
68
|
+
"@sitecore-cloudsdk/events": "^0.3.0",
|
|
69
|
+
"@sitecore-cloudsdk/personalize": "^0.3.0",
|
|
70
|
+
"next": "^14.1.0",
|
|
69
71
|
"react": "^18.2.0",
|
|
70
72
|
"react-dom": "^18.2.0"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"@sitecore-jss/sitecore-jss": "^22.0.0-canary.
|
|
74
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^22.0.0-canary.
|
|
75
|
-
"@sitecore-jss/sitecore-jss-react": "^22.0.0-canary.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^22.0.0-canary.42",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.0.0-canary.42",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^22.0.0-canary.42",
|
|
78
|
+
"@vercel/kv": "^0.2.1",
|
|
76
79
|
"node-html-parser": "^6.1.4",
|
|
77
80
|
"prop-types": "^15.8.1",
|
|
78
81
|
"regex-parser": "^2.2.11",
|
|
@@ -80,7 +83,7 @@
|
|
|
80
83
|
},
|
|
81
84
|
"description": "",
|
|
82
85
|
"types": "types/index.d.ts",
|
|
83
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "5832a186100a80805113d68cde0f8e578ef9193c",
|
|
84
87
|
"files": [
|
|
85
88
|
"dist",
|
|
86
89
|
"types",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import { ComponentFactory } from '@sitecore-jss/sitecore-jss-react';
|
|
3
|
+
import { Module, ModuleFactory } from './sharedTypes/module-factory';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a component that can be imported dynamically
|
|
7
|
+
*/
|
|
8
|
+
export type LazyModule = {
|
|
9
|
+
module: () => Promise<Module>;
|
|
10
|
+
element: (isEditing?: boolean) => ComponentType;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Component is a module or a lazy module
|
|
14
|
+
*/
|
|
15
|
+
type Component = Module | LazyModule | ComponentType;
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for ComponentBuilder
|
|
18
|
+
*/
|
|
19
|
+
export type ComponentBuilderConfig<Component> = {
|
|
20
|
+
/**
|
|
21
|
+
* List of components to be stored
|
|
22
|
+
*/
|
|
23
|
+
components: Map<string, Component>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for ComponentFactory
|
|
27
|
+
*/
|
|
28
|
+
type ComponentFactoryConfig = {
|
|
29
|
+
isEditing?: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Nextjs implementation of component builder class for building components based on the configuration.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ComponentBuilder {
|
|
35
|
+
protected config: ComponentBuilderConfig<Component>;
|
|
36
|
+
/**
|
|
37
|
+
* List of components to be stored
|
|
38
|
+
*/
|
|
39
|
+
protected components: Map<string, Component>;
|
|
40
|
+
/**
|
|
41
|
+
* SXA uses custom default export name
|
|
42
|
+
*/
|
|
43
|
+
protected DEFAULT_EXPORT_NAME: string;
|
|
44
|
+
constructor(config: ComponentBuilderConfig<Component>);
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new instance of module factory
|
|
47
|
+
* Module factory provides a module (file) including all exports.
|
|
48
|
+
* Module can be imported dynamically or statically.
|
|
49
|
+
* @returns {ModuleFactory} Module factory implementation
|
|
50
|
+
*/
|
|
51
|
+
getModuleFactory(): ModuleFactory;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new instance of component factory
|
|
54
|
+
* Component can be imported dynamically or statically.
|
|
55
|
+
* @param {Object} [config] Component factory configuration
|
|
56
|
+
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
57
|
+
* @returns {ComponentFactory} Component factory implementation
|
|
58
|
+
*/
|
|
59
|
+
getComponentFactory({ isEditing }?: ComponentFactoryConfig): ComponentFactory;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BYOCWrapper } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
+
import { GetStaticComponentProps, GetServerSideComponentProps } from '../sharedTypes/component-props';
|
|
3
|
+
/**
|
|
4
|
+
* This is a repackaged version of the React BYOCWrapper component with support for
|
|
5
|
+
* server rendering in Next.js (using component-level data-fetching feature of JSS).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Will be called during SSG
|
|
9
|
+
* @param {ComponentRendering} rendering
|
|
10
|
+
* @returns {GetStaticPropsContext} context
|
|
11
|
+
*/
|
|
12
|
+
export declare const getStaticProps: GetStaticComponentProps;
|
|
13
|
+
/**
|
|
14
|
+
* Will be called during SSR
|
|
15
|
+
* @param {ComponentRendering} rendering
|
|
16
|
+
* @returns {GetStaticPropsContext} context
|
|
17
|
+
*/
|
|
18
|
+
export declare const getServerSideProps: GetServerSideComponentProps;
|
|
19
|
+
export default BYOCWrapper;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FEaaSWrapper } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
+
import { GetStaticComponentProps, GetServerSideComponentProps } from '../sharedTypes/component-props';
|
|
3
|
+
/**
|
|
4
|
+
* This is a repackaged version of the React FEaaSWrapper component with support for
|
|
5
|
+
* server rendering in Next.js (using component-level data-fetching feature of JSS).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Will be called during SSG
|
|
9
|
+
* @param {ComponentRendering} rendering
|
|
10
|
+
* @param {LayoutServiceData} layoutData
|
|
11
|
+
* @returns {GetStaticPropsContext} context
|
|
12
|
+
*/
|
|
13
|
+
export declare const getStaticProps: GetStaticComponentProps;
|
|
14
|
+
/**
|
|
15
|
+
* Will be called during SSR
|
|
16
|
+
* @param {ComponentRendering} rendering
|
|
17
|
+
* @param {LayoutServiceData} layoutData
|
|
18
|
+
* @returns {GetStaticPropsContext} context
|
|
19
|
+
*/
|
|
20
|
+
export declare const getServerSideProps: GetServerSideComponentProps;
|
|
21
|
+
export default FEaaSWrapper;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { LinkProps as ReactLinkProps } from '@sitecore-jss/sitecore-jss-react';
|
|
3
4
|
export type LinkProps = ReactLinkProps & {
|
|
@@ -7,4 +8,4 @@ export type LinkProps = ReactLinkProps & {
|
|
|
7
8
|
*/
|
|
8
9
|
internalLinkMatcher?: RegExp;
|
|
9
10
|
};
|
|
10
|
-
export declare const Link: React.ForwardRefExoticComponent<
|
|
11
|
+
export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ImageProps } from '@sitecore-jss/sitecore-jss-react';
|
|
3
|
-
import {
|
|
4
|
-
type NextImageProps =
|
|
5
|
-
export declare const sitecoreLoader: ImageLoader;
|
|
4
|
+
import { ImageProps as NextImageProperties } from 'next/image';
|
|
5
|
+
type NextImageProps = ImageProps & Partial<NextImageProperties>;
|
|
6
6
|
export declare const NextImage: React.FC<NextImageProps>;
|
|
7
7
|
export {};
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
/// <reference types="@types/react" />
|
|
2
|
+
import React from 'react';
|
|
1
3
|
import { PlaceholderComponentProps } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
-
export declare const Placeholder: (props: PlaceholderComponentProps) => JSX.Element;
|
|
4
|
+
export declare const Placeholder: (props: PlaceholderComponentProps) => React.JSX.Element;
|
|
@@ -6,6 +6,12 @@ export type RichTextProps = ReactRichTextProps & {
|
|
|
6
6
|
* @default 'a[href^="/"]'
|
|
7
7
|
*/
|
|
8
8
|
internalLinksSelector?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Controls the prefetch of internal links. This can be beneficial if you have RichText fields
|
|
11
|
+
* with large numbers of internal links in them.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
prefetchLinks?: boolean;
|
|
9
15
|
};
|
|
10
16
|
export declare const RichText: {
|
|
11
17
|
(props: RichTextProps): JSX.Element;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
+
/**
|
|
3
|
+
* Software Development Kit (SDK) instance
|
|
4
|
+
*/
|
|
5
|
+
export type SDK<SDKType = unknown> = {
|
|
6
|
+
/**
|
|
7
|
+
* The Software Development Kit (SDK) library instance
|
|
8
|
+
*/
|
|
9
|
+
sdk: SDKType;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the Software Development Kit (SDK)
|
|
12
|
+
*/
|
|
13
|
+
init: (props: InitSDKProps) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Software Development Kits (SDKs) to be initialized
|
|
17
|
+
*/
|
|
18
|
+
type SDKModulesType = Record<string, SDK>;
|
|
19
|
+
/**
|
|
20
|
+
* Properties that are passed to the Context.
|
|
21
|
+
*/
|
|
22
|
+
export interface ContextInitProps {
|
|
23
|
+
/**
|
|
24
|
+
* Your Sitecore site name
|
|
25
|
+
*/
|
|
26
|
+
siteName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Sitecore page state (normal, preview, edit)
|
|
29
|
+
*/
|
|
30
|
+
pageState?: LayoutServicePageState;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration that is passed to the Context.
|
|
34
|
+
*/
|
|
35
|
+
export interface ContextConfig<SDKModules extends SDKModulesType> {
|
|
36
|
+
/**
|
|
37
|
+
* Your Sitecore Edge URL
|
|
38
|
+
*/
|
|
39
|
+
sitecoreEdgeUrl: string;
|
|
40
|
+
/**
|
|
41
|
+
* Your Sitecore Edge Context ID
|
|
42
|
+
*/
|
|
43
|
+
sitecoreEdgeContextId: string;
|
|
44
|
+
/**
|
|
45
|
+
* Your Sitecore site name
|
|
46
|
+
*/
|
|
47
|
+
siteName: string;
|
|
48
|
+
/**
|
|
49
|
+
* Software Development Kits (SDKs) to be initialized
|
|
50
|
+
*/
|
|
51
|
+
sdks: {
|
|
52
|
+
[module in keyof SDKModules]: SDKModules[module];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Properties that are passed to the Software Development Kit (SDK) initialization function.
|
|
57
|
+
*/
|
|
58
|
+
type InitSDKProps = Omit<ContextConfig<SDKModulesType>, 'sdks'>;
|
|
59
|
+
/**
|
|
60
|
+
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
61
|
+
*/
|
|
62
|
+
export declare class Context<SDKModules extends SDKModulesType> {
|
|
63
|
+
protected props: ContextConfig<SDKModules>;
|
|
64
|
+
/**
|
|
65
|
+
* Indicates whether the Context and SDK(s) have been initialized
|
|
66
|
+
*/
|
|
67
|
+
isInitialized: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The Sitecore Edge URL
|
|
70
|
+
*/
|
|
71
|
+
readonly sitecoreEdgeUrl: string;
|
|
72
|
+
/**
|
|
73
|
+
* The Sitecore Edge Context ID
|
|
74
|
+
*/
|
|
75
|
+
readonly sitecoreEdgeContextId: string;
|
|
76
|
+
/**
|
|
77
|
+
* The Sitecore site name
|
|
78
|
+
*/
|
|
79
|
+
siteName: string;
|
|
80
|
+
/**
|
|
81
|
+
* Sitecore page state (normal, preview, edit)
|
|
82
|
+
*/
|
|
83
|
+
pageState: LayoutServicePageState;
|
|
84
|
+
/**
|
|
85
|
+
* Software Development Kits (SDKs) to be initialized
|
|
86
|
+
*/
|
|
87
|
+
readonly sdks: {
|
|
88
|
+
[module in keyof SDKModules]?: SDKModules[module]['sdk'];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Promises for the SDKs
|
|
92
|
+
*/
|
|
93
|
+
protected sdkPromises: {
|
|
94
|
+
[module in keyof SDKModules]?: Promise<SDKModules[module]['sdk']>;
|
|
95
|
+
};
|
|
96
|
+
protected sdkErrors: {
|
|
97
|
+
[module in keyof SDKModules]?: string;
|
|
98
|
+
};
|
|
99
|
+
constructor(props: ContextConfig<SDKModules>);
|
|
100
|
+
init(props?: ContextInitProps): void;
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
103
|
+
*
|
|
104
|
+
* @param {string} name SDK name
|
|
105
|
+
* @returns initialized SDK
|
|
106
|
+
*/
|
|
107
|
+
getSDK: <T extends keyof SDKModules>(name: T) => Promise<SDKModules[T]["sdk"]>;
|
|
108
|
+
/**
|
|
109
|
+
* Initializes the Software Development Kit (SDK)
|
|
110
|
+
*
|
|
111
|
+
* @param {T} name SDK name
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
protected initSDK<T extends keyof SDKModules>(name: T): void;
|
|
115
|
+
}
|
|
116
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { Metadata } from '@sitecore-jss/sitecore-jss-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
|
+
}
|