create-sitecore-jss 22.4.0-canary.9 → 22.5.0-canary.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/dist/templates/angular-sxp/src/app/jss-data-fetcher.service.ts +6 -8
- package/dist/templates/nextjs/src/pages/[[...path]].tsx +1 -1
- package/dist/templates/nextjs-styleguide-tracking/src/lib/data-fetcher.ts +6 -6
- package/dist/templates/nextjs-sxa/src/pages/404.tsx +1 -1
- package/dist/templates/nextjs-sxa/src/pages/500.tsx +1 -1
- package/dist/templates/nextjs-sxa/src/pages/api/sitemap.ts +23 -12
- package/dist/templates/nextjs-xmcloud/src/Bootstrap.tsx +1 -2
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/preview-mode.ts +0 -45
- package/dist/templates/react/package.json +0 -1
- package/dist/templates/react/server/server.js +0 -4
- package/dist/templates/react/src/dataFetcher.js +12 -9
- package/dist/templates/vue/package.json +0 -1
- package/dist/templates/vue/server/server.js +0 -4
- package/dist/templates/vue/src/dataFetcher.js +13 -11
- package/package.json +2 -2
- package/dist/templates/nextjs-xmcloud/src/pages/component-library/render.tsx +0 -51
|
@@ -4,12 +4,10 @@ import { HttpResponse } from '@sitecore-jss/sitecore-jss-angular';
|
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
|
|
6
6
|
@Injectable({
|
|
7
|
-
providedIn: 'root'
|
|
7
|
+
providedIn: 'root',
|
|
8
8
|
})
|
|
9
9
|
export class JssDataFetcherService {
|
|
10
|
-
constructor(
|
|
11
|
-
private readonly httpClient: HttpClient,
|
|
12
|
-
) {
|
|
10
|
+
constructor(private readonly httpClient: HttpClient) {
|
|
13
11
|
this.fetch = this.fetch.bind(this);
|
|
14
12
|
}
|
|
15
13
|
|
|
@@ -28,9 +26,9 @@ export class JssDataFetcherService {
|
|
|
28
26
|
|
|
29
27
|
return lastValueFrom(result)
|
|
30
28
|
.then((responseData) => ({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
data: responseData as T,
|
|
30
|
+
status: 200,
|
|
31
|
+
statusText: 'OK',
|
|
34
32
|
}))
|
|
35
33
|
.catch((error: HttpErrorResponse) => {
|
|
36
34
|
if (error instanceof Error) {
|
|
@@ -40,7 +38,7 @@ export class JssDataFetcherService {
|
|
|
40
38
|
return {
|
|
41
39
|
data: error.error as T,
|
|
42
40
|
status: error.status,
|
|
43
|
-
statusText: error.statusText
|
|
41
|
+
statusText: error.statusText,
|
|
44
42
|
};
|
|
45
43
|
});
|
|
46
44
|
}
|
|
@@ -62,7 +62,7 @@ export const getStaticPaths: GetStaticPaths = async (context) => {
|
|
|
62
62
|
let paths: StaticPath[] = [];
|
|
63
63
|
let fallback: boolean | 'blocking' = 'blocking';
|
|
64
64
|
|
|
65
|
-
if (process.env.NODE_ENV !== 'development' &&
|
|
65
|
+
if (process.env.NODE_ENV !== 'development' && process.env.DISABLE_SSG_FETCH?.toLowerCase() !== 'true') {
|
|
66
66
|
try {
|
|
67
67
|
// Note: Next.js runs export in production mode
|
|
68
68
|
paths = await sitemapFetcher.fetch(context);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NativeDataFetcher, NativeDataFetcherResponse } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Implements a data fetcher using
|
|
4
|
+
* Implements a data fetcher using NativeDataFetcher - replace with your favorite
|
|
5
5
|
* SSR-capable HTTP or fetch library if you like. See HttpDataFetcher<T> type
|
|
6
6
|
* in sitecore-jss library for implementation details/notes.
|
|
7
7
|
* @param {string} url The URL to request; may include query string
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {RequestInit} data Optional data to POST with the request.
|
|
9
9
|
*/
|
|
10
10
|
export function dataFetcher<ResponseType>(
|
|
11
11
|
url: string,
|
|
12
|
-
data?:
|
|
13
|
-
): Promise<
|
|
14
|
-
return new
|
|
12
|
+
data?: RequestInit
|
|
13
|
+
): Promise<NativeDataFetcherResponse<ResponseType>> {
|
|
14
|
+
return new NativeDataFetcher().fetch<ResponseType>(url, data);
|
|
15
15
|
}
|
|
@@ -40,7 +40,7 @@ export const getStaticProps: GetStaticProps = async (context) => {
|
|
|
40
40
|
});
|
|
41
41
|
let resultErrorPages: ErrorPages | null = null;
|
|
42
42
|
|
|
43
|
-
if (
|
|
43
|
+
if (process.env.DISABLE_SSG_FETCH?.toLowerCase() !== 'true') {
|
|
44
44
|
try {
|
|
45
45
|
resultErrorPages = await errorPagesService.fetchErrorPages();
|
|
46
46
|
} catch (error) {
|
|
@@ -56,7 +56,7 @@ export const getStaticProps: GetStaticProps = async (context) => {
|
|
|
56
56
|
});
|
|
57
57
|
let resultErrorPages: ErrorPages | null = null;
|
|
58
58
|
|
|
59
|
-
if (
|
|
59
|
+
if (process.env.DISABLE_SSG_FETCH?.toLowerCase() !== 'true') {
|
|
60
60
|
try {
|
|
61
61
|
resultErrorPages = await errorPagesService.fetchErrorPages();
|
|
62
62
|
} catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
-
import {
|
|
2
|
+
import { NativeDataFetcher, GraphQLSitemapXmlService } from '@sitecore-jss/sitecore-jss-nextjs'
|
|
3
3
|
import { siteResolver } from 'lib/site-resolver';
|
|
4
4
|
import config from 'temp/config';
|
|
5
5
|
import clientFactory from 'lib/graphql-client-factory';
|
|
@@ -33,28 +33,39 @@ const sitemapApi = async (
|
|
|
33
33
|
const sitemapUrl = isAbsoluteUrl ? sitemapPath : `${config.sitecoreApiHost}${sitemapPath}`;
|
|
34
34
|
res.setHeader('Content-Type', 'text/xml;charset=utf-8');
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
try {
|
|
37
|
+
const fetcher = new NativeDataFetcher();
|
|
38
|
+
const response = await fetcher.fetch(sitemapUrl);
|
|
39
|
+
|
|
40
|
+
const reader = (response?.data as ReadableStream<Uint8Array>).getReader();
|
|
41
|
+
if (reader) {
|
|
42
|
+
while (true) {
|
|
43
|
+
const { done, value } = await reader.read();
|
|
44
|
+
if (done) break;
|
|
45
|
+
if (value) res.write(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
res.end();
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return res.redirect('/404');
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
45
53
|
}
|
|
46
54
|
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
47
58
|
// this approache if user go to /sitemap.xml - under it generate xml page with list of sitemaps
|
|
48
59
|
const sitemaps = await sitemapXmlService.fetchSitemaps();
|
|
49
60
|
|
|
50
61
|
if (!sitemaps.length) {
|
|
51
62
|
return res.redirect('/404');
|
|
52
63
|
}
|
|
53
|
-
|
|
64
|
+
|
|
54
65
|
const reqtHost = req.headers.host;
|
|
55
66
|
const reqProtocol = req.headers['x-forwarded-proto'] || 'https';
|
|
56
67
|
const SitemapLinks = sitemaps
|
|
57
|
-
.map((item) => {
|
|
68
|
+
.map((item: string) => {
|
|
58
69
|
const parseUrl = item.split('/');
|
|
59
70
|
const lastSegment = parseUrl[parseUrl.length - 1];
|
|
60
71
|
|
|
@@ -13,10 +13,9 @@ const Bootstrap = (props: SitecorePageProps): JSX.Element | null => {
|
|
|
13
13
|
// Browser ClientSDK init allows for page view events to be tracked
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
const pageState = props.layoutData?.sitecore?.context.pageState;
|
|
16
|
-
const renderingType = props.layoutData?.sitecore?.context.renderingType;
|
|
17
16
|
if (process.env.NODE_ENV === 'development')
|
|
18
17
|
console.debug('Browser Events SDK is not initialized in development environment');
|
|
19
|
-
else if (pageState !== LayoutServicePageState.Normal
|
|
18
|
+
else if (pageState !== LayoutServicePageState.Normal)
|
|
20
19
|
console.debug('Browser Events SDK is not initialized in edit and preview modes');
|
|
21
20
|
else {
|
|
22
21
|
CloudSDK({
|
|
@@ -6,14 +6,11 @@ import {
|
|
|
6
6
|
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
7
7
|
import {
|
|
8
8
|
editingDataService,
|
|
9
|
-
isComponentLibraryPreviewData,
|
|
10
9
|
isEditingMetadataPreviewData,
|
|
11
10
|
} from '@sitecore-jss/sitecore-jss-nextjs/editing';
|
|
12
11
|
import { SitecorePageProps } from 'lib/page-props';
|
|
13
12
|
import { graphQLEditingService } from 'lib/graphql-editing-service';
|
|
14
13
|
import { Plugin } from '..';
|
|
15
|
-
import { RestComponentLayoutService } from '@sitecore-jss/sitecore-jss-nextjs';
|
|
16
|
-
import config from 'temp/config';
|
|
17
14
|
|
|
18
15
|
class PreviewModePlugin implements Plugin {
|
|
19
16
|
order = 1;
|
|
@@ -21,48 +18,6 @@ class PreviewModePlugin implements Plugin {
|
|
|
21
18
|
async exec(props: SitecorePageProps, context: GetServerSidePropsContext | GetStaticPropsContext) {
|
|
22
19
|
if (!context.preview) return props;
|
|
23
20
|
|
|
24
|
-
if (isComponentLibraryPreviewData(context.previewData)) {
|
|
25
|
-
const { itemId, componentUid, site, language, renderingId, dataSourceId, version, variant } =
|
|
26
|
-
context.previewData;
|
|
27
|
-
|
|
28
|
-
const componentService = new RestComponentLayoutService({
|
|
29
|
-
apiHost: config.sitecoreApiHost,
|
|
30
|
-
apiKey: config.sitecoreApiKey,
|
|
31
|
-
siteName: site,
|
|
32
|
-
configurationName: config.layoutServiceConfigurationName,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const componentData = await componentService.fetchComponentData({
|
|
36
|
-
siteName: site,
|
|
37
|
-
itemId,
|
|
38
|
-
language,
|
|
39
|
-
componentUid,
|
|
40
|
-
renderingId,
|
|
41
|
-
dataSourceId,
|
|
42
|
-
variant,
|
|
43
|
-
version,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// we can reuse editing service, fortunately
|
|
47
|
-
const dictionaryData = await graphQLEditingService.fetchDictionaryData({
|
|
48
|
-
siteName: site,
|
|
49
|
-
language,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (!componentData) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Unable to fetch editing data for preview ${JSON.stringify(context.previewData)}`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
props.locale = context.previewData.language;
|
|
59
|
-
props.layoutData = componentData;
|
|
60
|
-
props.headLinks = [];
|
|
61
|
-
props.dictionary = dictionaryData;
|
|
62
|
-
|
|
63
|
-
return props;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
21
|
// If we're in Pages preview (editing) Metadata Edit Mode, prefetch the editing data
|
|
67
22
|
if (isEditingMetadataPreviewData(context.previewData)) {
|
|
68
23
|
const { site, itemId, language, version, variantIds, layoutKind } = context.previewData;
|
|
@@ -3,7 +3,6 @@ import React from 'react';
|
|
|
3
3
|
import { StaticRouter } from 'react-router-dom/server';
|
|
4
4
|
import { renderToStringWithData } from '@apollo/client/react/ssr';
|
|
5
5
|
import Helmet from 'react-helmet';
|
|
6
|
-
import axios from 'axios';
|
|
7
6
|
import http from 'http';
|
|
8
7
|
import https from 'https';
|
|
9
8
|
import GraphQLClientFactory from '../src/lib/GraphQLClientFactory';
|
|
@@ -31,9 +30,6 @@ function assertReplace(string, value, replacement) {
|
|
|
31
30
|
|
|
32
31
|
// Setup Http/Https agents for keep-alive. Used in headless-proxy
|
|
33
32
|
export const setUpDefaultAgents = (httpAgent, httpsAgent) => {
|
|
34
|
-
axios.defaults.httpAgent = httpAgent;
|
|
35
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
36
|
-
|
|
37
33
|
http.globalAgent = httpAgent;
|
|
38
34
|
https.globalAgent = httpsAgent;
|
|
39
35
|
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NativeDataFetcher } from '@sitecore-jss/sitecore-jss-react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Implements a data fetcher using
|
|
4
|
+
* Implements a data fetcher using NativeDataFetcher - replace with your favorite
|
|
5
5
|
* SSR-capable HTTP or fetch library if you like. See HttpDataFetcher<T> type
|
|
6
6
|
* in sitecore-jss library for implementation details/notes.
|
|
7
7
|
* @param {string} url The URL to request; may include query string
|
|
8
8
|
* @param {any} data Optional data to POST with the request.
|
|
9
9
|
*/
|
|
10
|
-
export function dataFetcher(url, data) {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export async function dataFetcher(url, data) {
|
|
11
|
+
const fetcher = new NativeDataFetcher({ credentials: 'include' });
|
|
12
|
+
|
|
13
|
+
const response = await fetcher.fetch(url, {
|
|
13
14
|
method: data ? 'POST' : 'GET',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
headers: {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
},
|
|
18
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
18
19
|
});
|
|
20
|
+
|
|
21
|
+
return response.data;
|
|
19
22
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { renderToString } from '@vue/server-renderer';
|
|
2
2
|
import serializeJavascript from 'serialize-javascript';
|
|
3
3
|
import { renderMetaToString } from 'vue-meta/ssr';
|
|
4
|
-
import axios from 'axios';
|
|
5
4
|
import http from 'http';
|
|
6
5
|
import https from 'https';
|
|
7
6
|
import i18ninit from '../src/i18n';
|
|
@@ -29,9 +28,6 @@ function assertReplace(string, value, replacement) {
|
|
|
29
28
|
|
|
30
29
|
// Setup Http/Https agents for keep-alive. Used in headless-proxy
|
|
31
30
|
export const setUpDefaultAgents = (httpAgent, httpsAgent) => {
|
|
32
|
-
axios.defaults.httpAgent = httpAgent;
|
|
33
|
-
axios.defaults.httpsAgent = httpsAgent;
|
|
34
|
-
|
|
35
31
|
http.globalAgent = httpAgent;
|
|
36
32
|
https.globalAgent = httpsAgent;
|
|
37
33
|
};
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { NativeDataFetcher } from '@sitecore-jss/sitecore-jss-vue';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Implements a data fetcher using
|
|
5
|
-
* SSR-capable HTTP or fetch library if you like.
|
|
6
|
-
* in sitecore-jss library for implementation details/notes.
|
|
4
|
+
* Implements a data fetcher using NativeDataFetcher - replace with your favorite
|
|
5
|
+
* SSR-capable HTTP or fetch library if you like.
|
|
7
6
|
* @param {string} url The URL to request; may include query string
|
|
8
7
|
* @param {any} data Optional data to POST with the request.
|
|
9
8
|
*/
|
|
10
|
-
export function dataFetcher(url, data) {
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export async function dataFetcher(url, data) {
|
|
10
|
+
const fetcher = new NativeDataFetcher({ credentials: 'include' });
|
|
11
|
+
|
|
12
|
+
const response = await fetcher.fetch(url, {
|
|
13
13
|
method: data ? 'POST' : 'GET',
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
body: data ? JSON.stringify(data) : undefined,
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
return response.data;
|
|
19
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-sitecore-jss",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.5.0-canary.1",
|
|
4
4
|
"description": "Sitecore JSS initializer",
|
|
5
5
|
"bin": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
66
|
"typescript": "~5.6.3"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "90e6a507ac1be88357673c85ab5d4caa3089b147"
|
|
69
69
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { GetServerSideProps } from 'next';
|
|
2
|
-
import Head from 'next/head';
|
|
3
|
-
import {
|
|
4
|
-
ComponentLibraryLayout,
|
|
5
|
-
ComponentPropsContext,
|
|
6
|
-
SitecoreContext,
|
|
7
|
-
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
8
|
-
import { SitecorePageProps } from 'lib/page-props';
|
|
9
|
-
import { sitecorePagePropsFactory } from 'lib/page-props-factory';
|
|
10
|
-
import NotFound from 'src/NotFound';
|
|
11
|
-
import { componentBuilder } from 'temp/componentBuilder';
|
|
12
|
-
import config from 'temp/config';
|
|
13
|
-
|
|
14
|
-
const FEAASRender = ({
|
|
15
|
-
notFound,
|
|
16
|
-
componentProps,
|
|
17
|
-
layoutData,
|
|
18
|
-
headLinks,
|
|
19
|
-
}: SitecorePageProps): JSX.Element => {
|
|
20
|
-
if (notFound) {
|
|
21
|
-
return <NotFound />;
|
|
22
|
-
}
|
|
23
|
-
return (
|
|
24
|
-
<ComponentPropsContext value={componentProps}>
|
|
25
|
-
<SitecoreContext
|
|
26
|
-
componentFactory={componentBuilder.getComponentFactory()}
|
|
27
|
-
layoutData={layoutData}
|
|
28
|
-
>
|
|
29
|
-
<Head>
|
|
30
|
-
<title>Sitecore Component Library</title>
|
|
31
|
-
<link rel="icon" href={`${config.publicUrl}/favicon.ico`} />
|
|
32
|
-
{headLinks.map((headLink) => (
|
|
33
|
-
<link rel={headLink.rel} key={headLink.href} href={headLink.href} />
|
|
34
|
-
))}
|
|
35
|
-
</Head>
|
|
36
|
-
<ComponentLibraryLayout {...layoutData} />
|
|
37
|
-
</SitecoreContext>
|
|
38
|
-
</ComponentPropsContext>
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const getServerSideProps: GetServerSideProps = async (context) => {
|
|
43
|
-
const props = await sitecorePagePropsFactory.create(context);
|
|
44
|
-
return {
|
|
45
|
-
props,
|
|
46
|
-
// not found when page not requested through editing render api or notFound set in page-props
|
|
47
|
-
notFound: props.notFound || !context.preview,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default FEAASRender;
|