create-sitecore-jss 22.2.0-canary.9 → 22.3.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/bin.js +17 -43
- package/dist/common/processes/next.js +4 -1
- package/dist/common/processes/transform.js +2 -12
- package/dist/common/prompts/base.js +0 -13
- package/dist/common/prompts/proxy.js +35 -0
- package/dist/common/prompts/sxp.js +16 -2
- package/dist/common/utils/helpers.js +27 -2
- package/dist/init-runner.js +1 -1
- package/dist/initializers/angular/prompts.js +4 -4
- package/dist/initializers/angular-xmcloud/index.js +21 -7
- package/dist/initializers/node-xmcloud-proxy/index.js +2 -1
- package/dist/templates/angular/.env +4 -5
- package/dist/templates/angular/.eslintrc +1 -0
- package/dist/templates/angular/gitignore +5 -0
- package/dist/templates/angular/package.json +6 -8
- package/dist/templates/angular/scripts/config/plugins/fallback.ts +0 -1
- package/dist/templates/angular/scripts/generate-component-factory/index.ts +45 -0
- package/dist/templates/angular/scripts/generate-component-factory/plugins/component-factory.ts +147 -0
- package/dist/templates/angular/scripts/generate-component-factory/plugins/components.ts +19 -0
- package/dist/templates/angular/scripts/generate-component-factory/plugins/packages.ts +29 -0
- package/dist/templates/angular/scripts/generate-component-factory/template.ts +46 -0
- package/dist/templates/angular/scripts/generate-config.ts +25 -6
- package/dist/templates/angular/scripts/generate-plugins.ts +5 -0
- package/dist/templates/angular/scripts/update-graphql-fragment-data.ts +21 -30
- package/dist/templates/angular/server.bundle.ts +3 -23
- package/dist/templates/angular/server.exports.ts +13 -0
- package/dist/templates/angular/src/app/JssState.ts +2 -9
- package/dist/templates/angular/src/app/app.module.ts +5 -4
- package/dist/templates/angular/src/app/app.server.module.ts +9 -6
- package/dist/templates/angular/src/app/components/gitignore +1 -1
- package/dist/templates/angular/src/app/i18n/jss-translation-client-loader.service.ts +15 -7
- package/dist/templates/angular/src/app/i18n/jss-translation-server-loader.service.ts +14 -2
- package/dist/templates/angular/src/app/jss-context.server-side.service.ts +4 -2
- package/dist/templates/angular/src/app/jss-context.service.ts +14 -11
- package/dist/templates/angular/src/app/jss-graphql.service.ts +7 -7
- package/dist/templates/angular/src/app/layout/jss-layout.service.ts +2 -2
- package/dist/templates/angular/src/app/lib/dictionary-service-factory.ts +4 -1
- package/dist/templates/angular/src/app/lib/graphql-client-factory/config.ts +21 -0
- package/dist/templates/angular/src/app/lib/graphql-client-factory/index.ts +16 -0
- package/dist/templates/angular/src/app/lib/layout-service-factory.ts +1 -1
- package/dist/templates/angular/src/app/routing/layout/layout.component.ts +10 -9
- package/dist/templates/angular/src/environments/gitignore +2 -1
- package/dist/templates/angular-sxp/.env +2 -0
- package/dist/templates/angular-sxp/scripts/config/plugins/disconnected.ts +4 -2
- package/dist/templates/angular-sxp/src/app/components/graph-ql-layout/graph-ql-layout.component.ts +1 -1
- package/dist/templates/angular-xmcloud/.env +15 -2
- package/dist/templates/angular-xmcloud/angular.json +0 -1
- package/dist/templates/angular-xmcloud/package.json +2 -0
- package/dist/templates/angular-xmcloud/scripts/bootstrap.ts +28 -0
- package/dist/templates/angular-xmcloud/scripts/config/plugins/xmcloud.ts +16 -0
- package/dist/templates/angular-xmcloud/scripts/generate-component-factory/plugins/packages.ts +34 -0
- package/dist/templates/angular-xmcloud/scripts/generate-component-factory/template.ts +57 -0
- package/dist/templates/angular-xmcloud/scripts/generate-metadata.ts +25 -0
- package/dist/templates/angular-xmcloud/server.exports.ts +24 -0
- package/dist/templates/angular-xmcloud/src/app/components/app-components.shared.module.ts +21 -0
- package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.html +5 -0
- package/dist/templates/angular-xmcloud/src/app/components/column-splitter/column-splitter.component.ts +40 -0
- package/dist/templates/angular-xmcloud/src/app/components/container/container.component.html +2 -3
- package/dist/templates/angular-xmcloud/src/app/components/image/image.component.html +36 -0
- package/dist/templates/angular-xmcloud/src/app/components/image/image.component.ts +67 -0
- package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.html +15 -0
- package/dist/templates/angular-xmcloud/src/app/components/link-list/link-list.component.ts +41 -0
- package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.html +23 -0
- package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation-item.component.ts +65 -0
- package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.html +21 -0
- package/dist/templates/angular-xmcloud/src/app/components/navigation/navigation.component.ts +49 -0
- package/dist/templates/angular-xmcloud/src/app/components/page-content/page-content.component.html +5 -0
- package/dist/templates/angular-xmcloud/src/app/components/page-content/page-content.component.ts +39 -0
- package/dist/templates/angular-xmcloud/src/app/components/partial-design-dynamic-placeholder/partial-design-dynamic-placeholder.component.html +1 -0
- package/dist/templates/angular-xmcloud/src/app/components/partial-design-dynamic-placeholder/partial-design-dynamic-placeholder.component.ts +15 -0
- package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.html +21 -0
- package/dist/templates/angular-xmcloud/src/app/components/promo/promo.component.ts +13 -0
- package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.html +7 -12
- package/dist/templates/angular-xmcloud/src/app/components/richtext/richtext.component.ts +6 -1
- package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.html +11 -0
- package/dist/templates/angular-xmcloud/src/app/components/row-splitter/row-splitter.component.ts +35 -0
- package/dist/templates/angular-xmcloud/src/app/components/sxa.component.ts +3 -3
- package/dist/templates/angular-xmcloud/src/app/components/title/title.component.html +10 -0
- package/dist/templates/angular-xmcloud/src/app/components/title/title.component.ts +56 -0
- package/dist/templates/angular-xmcloud/src/app/jss-link.service.ts +55 -0
- package/dist/templates/angular-xmcloud/src/app/lib/config.ts +2 -0
- package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory/config.ts +58 -0
- package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.html +38 -0
- package/dist/templates/angular-xmcloud/src/app/routing/layout/layout.component.ts +104 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/cdp-page-view.component.ts +77 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/cloud-sdk-init.component.ts +48 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.component.html +5 -0
- package/dist/templates/angular-xmcloud/src/app/routing/scripts/scripts.module.ts +12 -0
- package/dist/templates/angular-xmcloud/src/assets/styles/basic/_header.scss +3 -1
- package/dist/templates/angular-xmcloud/src/assets/styles/main.scss +10 -0
- package/dist/templates/nextjs/package.json +5 -5
- package/dist/templates/nextjs/scripts/config/plugins/fallback.ts +0 -1
- package/dist/templates/nextjs/scripts/generate-config.ts +8 -1
- package/dist/templates/nextjs/src/lib/page-props-factory/plugins/component-props.ts +2 -1
- package/dist/templates/nextjs-styleguide/package.json +1 -1
- package/dist/templates/nextjs-styleguide/scripts/config/plugins/disconnected.ts +1 -0
- package/dist/templates/nextjs-sxa/src/assets/sass/components/common/_alignment.scss +34 -7
- package/dist/templates/nextjs-sxa/src/components/Container.tsx +6 -14
- package/dist/templates/nextjs-xmcloud/package.json +3 -2
- package/dist/templates/nextjs-xmcloud/src/Bootstrap.tsx +25 -10
- package/dist/templates/nextjs-xmcloud/src/byoc/{index.ts → index.tsx} +25 -8
- package/dist/templates/nextjs-xmcloud/src/components/CdpPageView.tsx +9 -14
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/component-themes.ts +2 -1
- package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/preview-mode.ts +2 -1
- package/dist/templates/node-headless-ssr-experience-edge/gitignore +19 -0
- package/dist/templates/node-headless-ssr-experience-edge/package.json +2 -2
- package/dist/templates/node-headless-ssr-proxy/gitignore +19 -0
- package/dist/templates/node-headless-ssr-proxy/package.json +3 -3
- package/dist/templates/node-headless-ssr-proxy/src/config.ts +3 -3
- package/dist/templates/node-headless-ssr-proxy/src/httpAgents.ts +2 -2
- package/dist/templates/node-headless-ssr-proxy/src/index.ts +9 -2
- package/dist/templates/node-xmcloud-proxy/.env +7 -1
- package/dist/templates/node-xmcloud-proxy/README.md +1 -1
- package/dist/templates/node-xmcloud-proxy/gitignore +33 -0
- package/dist/templates/node-xmcloud-proxy/package.json +3 -2
- package/dist/templates/node-xmcloud-proxy/src/config.ts +9 -3
- package/dist/templates/node-xmcloud-proxy/src/index.ts +54 -5
- package/dist/templates/node-xmcloud-proxy/src/types.ts +10 -42
- package/dist/templates/react/package.json +5 -5
- package/dist/templates/react/scripts/generate-config.js +10 -3
- package/dist/templates/react-native/package.json +4 -4
- package/dist/templates/vue/package.json +4 -4
- package/dist/templates/vue/scripts/generate-config.js +5 -0
- package/package.json +2 -2
- package/dist/templates/angular/scripts/generate-component-factory.ts +0 -166
- package/dist/templates/angular/src/app/lib/graphql-client-factory.ts +0 -28
- package/dist/templates/angular-xmcloud/src/app/lib/graphql-client-factory.ts +0 -44
- package/dist/templates/nextjs-xmcloud/src/lib/context/index.ts +0 -22
- package/dist/templates/nextjs-xmcloud/src/lib/context/sdk/events.ts +0 -26
|
@@ -1,26 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import * as FEAAS from '@sitecore-feaas/clientside/react';
|
|
3
|
+
import * as Events from '@sitecore-cloudsdk/events/browser';
|
|
2
4
|
import '@sitecore/components/context';
|
|
3
5
|
import dynamic from 'next/dynamic';
|
|
4
|
-
import
|
|
6
|
+
import config from 'temp/config';
|
|
7
|
+
import {
|
|
8
|
+
LayoutServicePageState,
|
|
9
|
+
SitecoreContextReactContext,
|
|
10
|
+
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
5
11
|
/**
|
|
6
12
|
* This is an out-of-box bundler for External components (BYOC) (see Sitecore documentation for more details)
|
|
7
13
|
* It enables registering components in client-only or SSR/hybrid contexts
|
|
8
14
|
* It's recommended to not modify this file - please add BYOC imports in corresponding index.*.ts files instead
|
|
9
15
|
*/
|
|
10
16
|
|
|
11
|
-
// Set context properties to be available within BYOC components
|
|
12
|
-
FEAAS.setContextProperties(context);
|
|
13
|
-
|
|
14
17
|
// Import your client-only components via client-bundle. Nextjs's dynamic() call will ensure they are only rendered client-side
|
|
15
18
|
const ClientBundle = dynamic(() => import('./index.client'), {
|
|
16
19
|
ssr: false,
|
|
17
20
|
});
|
|
18
21
|
|
|
19
|
-
// Import your hybrid (server rendering with client hydration) components via index.hybrid.ts
|
|
20
|
-
import './index.hybrid';
|
|
21
|
-
|
|
22
22
|
// As long as component bundle is exported and rendered on page (as an empty element), client-only BYOC components are registered and become available
|
|
23
23
|
// The rest of components will be regsitered in both server and client-side contexts when this module is imported into Layout
|
|
24
24
|
FEAAS.enableNextClientsideComponents(dynamic, ClientBundle);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
// Import your hybrid (server rendering with client hydration) components via index.hybrid.ts
|
|
27
|
+
import './index.hybrid';
|
|
28
|
+
|
|
29
|
+
const BYOCInit = (): JSX.Element | null => {
|
|
30
|
+
const sitecoreContext = React.useContext(SitecoreContextReactContext).context;
|
|
31
|
+
// Set context properties to be available within BYOC components
|
|
32
|
+
FEAAS.setContextProperties({
|
|
33
|
+
sitecoreEdgeUrl: config.sitecoreEdgeUrl,
|
|
34
|
+
sitecoreEdgeContextId: config.sitecoreEdgeContextId,
|
|
35
|
+
pageState: sitecoreContext?.pageState || LayoutServicePageState.Normal,
|
|
36
|
+
siteName: sitecoreContext?.site?.name || config.sitecoreSiteName,
|
|
37
|
+
eventsSDK: Events,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return <FEAAS.ExternalComponentBundle />;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default BYOCInit;
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
useSitecoreContext,
|
|
5
5
|
} from '@sitecore-jss/sitecore-jss-nextjs';
|
|
6
6
|
import { useEffect } from 'react';
|
|
7
|
+
import { pageView } from '@sitecore-cloudsdk/events/browser';
|
|
7
8
|
import config from 'temp/config';
|
|
8
|
-
import { context } from 'lib/context';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* This is the CDP page view component.
|
|
@@ -46,19 +46,14 @@ const CdpPageView = (): JSX.Element => {
|
|
|
46
46
|
variantId as string,
|
|
47
47
|
scope
|
|
48
48
|
);
|
|
49
|
-
// there
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
pageVariantId,
|
|
58
|
-
language,
|
|
59
|
-
})
|
|
60
|
-
)
|
|
61
|
-
.catch((e) => console.debug(e));
|
|
49
|
+
// there can be cases where Events are not initialized which are expected to reject
|
|
50
|
+
pageView({
|
|
51
|
+
channel: 'WEB',
|
|
52
|
+
currency: 'USD',
|
|
53
|
+
page: route.name,
|
|
54
|
+
pageVariantId,
|
|
55
|
+
language,
|
|
56
|
+
}).catch((e) => console.debug(e));
|
|
62
57
|
}, [pageState, route, variantId, site]);
|
|
63
58
|
|
|
64
59
|
return <></>;
|
package/dist/templates/nextjs-xmcloud/src/lib/page-props-factory/plugins/component-themes.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { Plugin } from '..';
|
|
|
4
4
|
import config from 'temp/config';
|
|
5
5
|
|
|
6
6
|
class ComponentThemesPlugin implements Plugin {
|
|
7
|
-
|
|
7
|
+
// Make sure to run this plugin after the personalization plugin, since it relies on the layout data
|
|
8
|
+
order = 10;
|
|
8
9
|
|
|
9
10
|
async exec(props: SitecorePageProps) {
|
|
10
11
|
// Collect FEAAS, BYOC, SXA component themes
|
|
@@ -20,13 +20,14 @@ class PreviewModePlugin implements Plugin {
|
|
|
20
20
|
|
|
21
21
|
// If we're in Pages preview (editing) Metadata Edit Mode, prefetch the editing data
|
|
22
22
|
if (isEditingMetadataPreviewData(context.previewData)) {
|
|
23
|
-
const { site, itemId, language, version, variantIds } = context.previewData;
|
|
23
|
+
const { site, itemId, language, version, variantIds, layoutKind } = context.previewData;
|
|
24
24
|
|
|
25
25
|
const data = await graphQLEditingService.fetchEditingData({
|
|
26
26
|
siteName: site,
|
|
27
27
|
itemId,
|
|
28
28
|
language,
|
|
29
29
|
version,
|
|
30
|
+
layoutKind,
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
if (!data) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# local env files
|
|
7
|
+
.env.local
|
|
8
|
+
.env.*.local
|
|
9
|
+
|
|
10
|
+
# IDE - VSCode
|
|
11
|
+
.vscode/*
|
|
12
|
+
!.vscode/settings.json
|
|
13
|
+
!.vscode/tasks.json
|
|
14
|
+
!.vscode/launch.json
|
|
15
|
+
!.vscode/extensions.json
|
|
16
|
+
|
|
17
|
+
# System Files
|
|
18
|
+
.DS_Store
|
|
19
|
+
Thumbs.db
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-headless-ssr-experience-edge-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary",
|
|
4
4
|
"description": "Node server-side-rendering sample for running JSS apps under Node hosting using Experience Edge",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "ts-node ./src/index.ts"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"homepage": "https://jss.sitecore.com",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
22
|
+
"@sitecore-jss/sitecore-jss": "~22.3.0-canary",
|
|
23
23
|
"compression": "^1.7.4",
|
|
24
24
|
"express": "^4.18.2",
|
|
25
25
|
"dotenv": "^16.0.3"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# dependencies
|
|
4
|
+
/node_modules
|
|
5
|
+
|
|
6
|
+
# local env files
|
|
7
|
+
.env.local
|
|
8
|
+
.env.*.local
|
|
9
|
+
|
|
10
|
+
# IDE - VSCode
|
|
11
|
+
.vscode/*
|
|
12
|
+
!.vscode/settings.json
|
|
13
|
+
!.vscode/tasks.json
|
|
14
|
+
!.vscode/launch.json
|
|
15
|
+
!.vscode/extensions.json
|
|
16
|
+
|
|
17
|
+
# System Files
|
|
18
|
+
.DS_Store
|
|
19
|
+
Thumbs.db
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-headless-ssr-proxy-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary",
|
|
4
4
|
"description": "Node server-side-rendering proxy sample for running JSS apps under Node hosting",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "ts-node ./src/index.ts"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"homepage": "https://jss.sitecore.com",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
23
|
-
"@sitecore-jss/sitecore-jss-proxy": "~22.
|
|
22
|
+
"@sitecore-jss/sitecore-jss": "~22.3.0-canary",
|
|
23
|
+
"@sitecore-jss/sitecore-jss-proxy": "~22.3.0-canary",
|
|
24
24
|
"agentkeepalive": "^4.2.1",
|
|
25
25
|
"compression": "~1.7.4",
|
|
26
26
|
"express": "~4.19.2",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { headlessProxy } from '@sitecore-jss/sitecore-jss-proxy';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { RestDictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
|
|
4
4
|
import { httpAgentsConfig } from './httpAgents';
|
|
@@ -13,7 +13,7 @@ let siteName = process.env.SITECORE_SITE_NAME || appName;
|
|
|
13
13
|
|
|
14
14
|
const bundlePath = process.env.SITECORE_JSS_SERVER_BUNDLE || `../dist/${appName}/server.bundle`;
|
|
15
15
|
|
|
16
|
-
const serverBundle = require(bundlePath) as ServerBundle;
|
|
16
|
+
const serverBundle = require(bundlePath) as headlessProxy.ServerBundle;
|
|
17
17
|
|
|
18
18
|
httpAgentsConfig.setUpDefaultAgents(serverBundle);
|
|
19
19
|
|
|
@@ -33,7 +33,7 @@ const dictionaryService = new RestDictionaryService({
|
|
|
33
33
|
/**
|
|
34
34
|
* @type {ProxyConfig}
|
|
35
35
|
*/
|
|
36
|
-
export const config: ProxyConfig = {
|
|
36
|
+
export const config: headlessProxy.ProxyConfig = {
|
|
37
37
|
/**
|
|
38
38
|
* The require'd server.bundle.js file from your pre-built JSS app
|
|
39
39
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { headlessProxy } from '@sitecore-jss/sitecore-jss-proxy';
|
|
2
2
|
import keepAlive from 'agentkeepalive';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
import https from 'https';
|
|
@@ -14,7 +14,7 @@ const httpAgent = new keepAlive(keepAliveConfig);
|
|
|
14
14
|
const httpsAgent = (new keepAlive.HttpsAgent(keepAliveConfig) as unknown) as https.Agent;
|
|
15
15
|
|
|
16
16
|
interface HttpAgentsConfig {
|
|
17
|
-
setUpDefaultAgents: (serverBundle: ServerBundle) => void;
|
|
17
|
+
setUpDefaultAgents: (serverBundle: headlessProxy.ServerBundle) => void;
|
|
18
18
|
getAgent: (url: string) => http.Agent | https.Agent;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import compression from 'compression';
|
|
3
3
|
import 'dotenv/config';
|
|
4
|
-
import
|
|
4
|
+
import { headlessProxy } from '@sitecore-jss/sitecore-jss-proxy';
|
|
5
5
|
import { config } from './config';
|
|
6
6
|
//import { cacheMiddleware } from './cacheMiddleware';
|
|
7
7
|
|
|
@@ -42,7 +42,14 @@ server.use((req, _res, next) => {
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// For any other requests, we render app routes server-side and return them
|
|
45
|
-
server.use(
|
|
45
|
+
server.use(
|
|
46
|
+
'*',
|
|
47
|
+
headlessProxy.middleware(
|
|
48
|
+
config.serverBundle.renderView,
|
|
49
|
+
config,
|
|
50
|
+
config.serverBundle.parseRouteUrl
|
|
51
|
+
)
|
|
52
|
+
);
|
|
46
53
|
|
|
47
54
|
server.listen(port, () => {
|
|
48
55
|
console.log(`server listening on port ${port}!`);
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# To secure the Sitecore editor endpoint exposed by your proxy app
|
|
2
|
+
# (`/api/editing/render` by default), a secret token is used.
|
|
3
|
+
# The environment variable is used by `editingRouter`
|
|
4
|
+
# We recommend an alphanumeric value of at least 16 characters.
|
|
5
|
+
JSS_EDITING_SECRET=
|
|
6
|
+
|
|
7
|
+
# Your proxy port (default: 3000)
|
|
2
8
|
PROXY_PORT=
|
|
3
9
|
|
|
4
10
|
# Your proxy server bundle path
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
|
2
|
+
|
|
3
|
+
# compiled output
|
|
4
|
+
/dist
|
|
5
|
+
|
|
6
|
+
# dependencies
|
|
7
|
+
/node_modules
|
|
8
|
+
|
|
9
|
+
# local env files
|
|
10
|
+
.env.local
|
|
11
|
+
.env.*.local
|
|
12
|
+
|
|
13
|
+
# IDE - VSCode
|
|
14
|
+
.vscode/*
|
|
15
|
+
!.vscode/settings.json
|
|
16
|
+
!.vscode/tasks.json
|
|
17
|
+
!.vscode/launch.json
|
|
18
|
+
!.vscode/extensions.json
|
|
19
|
+
|
|
20
|
+
# misc
|
|
21
|
+
/connect.lock
|
|
22
|
+
/libpeerconnection.log
|
|
23
|
+
npm-debug.log
|
|
24
|
+
testem.log
|
|
25
|
+
/typings
|
|
26
|
+
|
|
27
|
+
# System Files
|
|
28
|
+
.DS_Store
|
|
29
|
+
Thumbs.db
|
|
30
|
+
|
|
31
|
+
# deploy platforms
|
|
32
|
+
.vercel
|
|
33
|
+
.netlify
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-xmcloud-sample",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary",
|
|
4
4
|
"description": "Node XM Cloud Proxy sample for running XM Cloud JSS SPA apps",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Sitecore Corporation",
|
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
"start": "ts-node ./src/index.ts"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"@sitecore-jss/sitecore-jss-proxy": "~22.3.0-canary",
|
|
13
14
|
"compression": "^1.7.4",
|
|
14
15
|
"express": "^4.18.2",
|
|
15
16
|
"dotenv": "^16.0.3",
|
|
16
17
|
"http-proxy-middleware": "^3.0.0"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"@sitecore-jss/sitecore-jss": "~22.
|
|
20
|
+
"@sitecore-jss/sitecore-jss": "~22.3.0-canary",
|
|
20
21
|
"@types/compression": "^1.7.2",
|
|
21
22
|
"@types/express": "^4.17.17",
|
|
22
23
|
"ts-node": "^10.9.1",
|
|
@@ -3,9 +3,15 @@ import { Config, ServerBundle } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
* The server.bundle.js file from your pre-built SPA app.
|
|
5
5
|
*/
|
|
6
|
-
const bundlePath = process.env.PROXY_BUNDLE_PATH ||
|
|
6
|
+
const bundlePath = process.env.PROXY_BUNDLE_PATH || '../dist/server.bundle';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let serverBundle: ServerBundle;
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
serverBundle = require(bundlePath);
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(`ERROR: The server.bundle.js error. ${error}`);
|
|
14
|
+
}
|
|
9
15
|
|
|
10
16
|
export const config: Config = {
|
|
11
17
|
/**
|
|
@@ -15,5 +21,5 @@ export const config: Config = {
|
|
|
15
21
|
/**
|
|
16
22
|
* Port which will be used when start the proxy
|
|
17
23
|
*/
|
|
18
|
-
port: process.env.PROXY_PORT ||
|
|
24
|
+
port: process.env.PROXY_PORT || 3000,
|
|
19
25
|
};
|
|
@@ -3,6 +3,8 @@ import express, { Response } from 'express';
|
|
|
3
3
|
import compression from 'compression';
|
|
4
4
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
5
5
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
6
|
+
import { editingRouter } from '@sitecore-jss/sitecore-jss-proxy';
|
|
7
|
+
import { healthCheck } from '@sitecore-jss/sitecore-jss-proxy';
|
|
6
8
|
import { config } from './config';
|
|
7
9
|
|
|
8
10
|
const server = express();
|
|
@@ -21,12 +23,12 @@ const requiredProperties = [
|
|
|
21
23
|
'renderView',
|
|
22
24
|
'parseRouteUrl',
|
|
23
25
|
'clientFactory',
|
|
24
|
-
'
|
|
26
|
+
'getClientFactoryConfig',
|
|
25
27
|
'defaultLanguage',
|
|
26
28
|
'layoutServiceFactory',
|
|
27
29
|
'dictionaryServiceFactory',
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
+
'components',
|
|
31
|
+
'metadata',
|
|
30
32
|
];
|
|
31
33
|
|
|
32
34
|
const missingProperties = requiredProperties.filter((property) => !config.serverBundle[property]);
|
|
@@ -43,6 +45,31 @@ const layoutService = layoutServiceFactory.create();
|
|
|
43
45
|
|
|
44
46
|
const dictionaryService = dictionaryServiceFactory.create();
|
|
45
47
|
|
|
48
|
+
const clientFactoryConfig = config.serverBundle.getClientFactoryConfig();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* GraphQL endpoint resolution to meet the requirements of the http-proxy-middleware
|
|
52
|
+
*/
|
|
53
|
+
const graphQLEndpoint = (() => {
|
|
54
|
+
try {
|
|
55
|
+
const graphQLEndpoint = new URL(clientFactoryConfig.endpoint);
|
|
56
|
+
// Browser request path to the proxy. Includes only the pathname.
|
|
57
|
+
const pathname = graphQLEndpoint.pathname;
|
|
58
|
+
// Target URL for the proxy. Can't include the query string.
|
|
59
|
+
const target = `${graphQLEndpoint.protocol}//${graphQLEndpoint.hostname}${pathname}`;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
target,
|
|
63
|
+
path: pathname,
|
|
64
|
+
};
|
|
65
|
+
} catch (error) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`ERROR: The serverBundle should export a getClientFactoryConfig function with valid GraphQL endpoint URL returned, current value is ${clientFactoryConfig.endpoint}. ` +
|
|
68
|
+
'Please check your server bundle.'
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
|
|
46
73
|
/**
|
|
47
74
|
* Parse requested url in order to detect current route and language
|
|
48
75
|
* @param {string} reqRoute requested route
|
|
@@ -94,13 +121,35 @@ server.use(
|
|
|
94
121
|
* Proxy browser GraphQL requests to the Sitecore GraphQL endpoint
|
|
95
122
|
*/
|
|
96
123
|
server.use(
|
|
97
|
-
|
|
124
|
+
graphQLEndpoint.path,
|
|
98
125
|
createProxyMiddleware({
|
|
99
|
-
target:
|
|
126
|
+
target: graphQLEndpoint.target,
|
|
100
127
|
changeOrigin: true,
|
|
101
128
|
})
|
|
102
129
|
);
|
|
103
130
|
|
|
131
|
+
/**
|
|
132
|
+
* The health check endpoint
|
|
133
|
+
*/
|
|
134
|
+
server.use(healthCheck());
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Proxy editing requests through the editing router
|
|
138
|
+
*/
|
|
139
|
+
server.use(
|
|
140
|
+
'/api/editing',
|
|
141
|
+
editingRouter({
|
|
142
|
+
config: {
|
|
143
|
+
components: config.serverBundle.components,
|
|
144
|
+
metadata: config.serverBundle.metadata,
|
|
145
|
+
},
|
|
146
|
+
render: {
|
|
147
|
+
clientFactory: config.serverBundle.clientFactory,
|
|
148
|
+
renderView,
|
|
149
|
+
},
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
|
|
104
153
|
server.use(async (req, res) => {
|
|
105
154
|
debug.proxy(`performing SSR for ${req.originalUrl}`);
|
|
106
155
|
|
|
@@ -1,55 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
GraphQLRequestClientFactory,
|
|
3
|
+
GraphQLRequestClientFactoryConfig,
|
|
4
|
+
} from '@sitecore-jss/sitecore-jss';
|
|
2
5
|
import { DictionaryService } from '@sitecore-jss/sitecore-jss/i18n';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The rendered HTML to return to the client
|
|
8
|
-
*/
|
|
9
|
-
html: string;
|
|
10
|
-
/**
|
|
11
|
-
* Set the HTTP status code. If not set, the status code returned from Layout Service is returned.
|
|
12
|
-
*/
|
|
13
|
-
status?: number;
|
|
14
|
-
/**
|
|
15
|
-
* Sets a redirect URL, causing the reply to send a HTTP redirect instead of the HTML content.
|
|
16
|
-
* Note: when using this you must set the status code to 301 or 302.
|
|
17
|
-
*/
|
|
18
|
-
redirect?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare type AppRenderer = (
|
|
22
|
-
callback: (error: Error | null, result: ServerResponse | null) => void,
|
|
23
|
-
path: string,
|
|
24
|
-
/**
|
|
25
|
-
* Data returned by Layout Service. If the route does not exist, null.
|
|
26
|
-
*/
|
|
27
|
-
layoutData: LayoutServiceData,
|
|
28
|
-
viewBag: {
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
dictionary: { [key: string]: string };
|
|
31
|
-
}
|
|
32
|
-
) => void;
|
|
33
|
-
|
|
34
|
-
declare type RouteUrlParser = (
|
|
35
|
-
url: string
|
|
36
|
-
) => {
|
|
37
|
-
sitecoreRoute?: string;
|
|
38
|
-
lang?: string;
|
|
39
|
-
qsParams?: string;
|
|
40
|
-
};
|
|
6
|
+
import { Metadata } from '@sitecore-jss/sitecore-jss/utils';
|
|
7
|
+
import { LayoutService } from '@sitecore-jss/sitecore-jss/layout';
|
|
8
|
+
import { AppRenderer, RouteUrlParser } from '@sitecore-jss/sitecore-jss-proxy';
|
|
41
9
|
|
|
42
10
|
export interface ServerBundle {
|
|
43
11
|
[key: string]: unknown;
|
|
44
12
|
renderView: AppRenderer;
|
|
45
13
|
parseRouteUrl: RouteUrlParser;
|
|
46
14
|
clientFactory: GraphQLRequestClientFactory;
|
|
47
|
-
|
|
15
|
+
getClientFactoryConfig: () => GraphQLRequestClientFactoryConfig;
|
|
48
16
|
defaultLanguage: string;
|
|
49
17
|
layoutServiceFactory: { create: () => LayoutService };
|
|
50
18
|
dictionaryServiceFactory: { create: () => DictionaryService };
|
|
51
|
-
|
|
52
|
-
|
|
19
|
+
components: string[] | Map<string, unknown>;
|
|
20
|
+
metadata: Metadata;
|
|
53
21
|
}
|
|
54
22
|
|
|
55
23
|
export interface Config {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%- appName %>",
|
|
3
3
|
"description": "Application utilizing Sitecore JavaScript Services and React (create-react-app).",
|
|
4
|
-
"version": "22.
|
|
4
|
+
"version": "22.3.0-canary",
|
|
5
5
|
"private": true,
|
|
6
6
|
"config": {
|
|
7
7
|
"appName": "<%- appName %>",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@apollo/client": "^3.7.1",
|
|
31
|
-
"@sitecore-jss/sitecore-jss-react": "~22.
|
|
31
|
+
"@sitecore-jss/sitecore-jss-react": "~22.3.0-canary",
|
|
32
32
|
"axios": "^1.2.0",
|
|
33
33
|
"bootstrap": "^5.2.3",
|
|
34
34
|
"cross-fetch": "^3.1.5",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"@babel/preset-env": "^7.20.2",
|
|
54
54
|
"@babel/preset-react": "^7.18.6",
|
|
55
55
|
"@babel/register": "~7.18.9",
|
|
56
|
-
"@sitecore-jss/sitecore-jss-cli": "~22.
|
|
57
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "~22.
|
|
58
|
-
"@sitecore-jss/sitecore-jss-rendering-host": "~22.
|
|
56
|
+
"@sitecore-jss/sitecore-jss-cli": "~22.3.0-canary",
|
|
57
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "~22.3.0-canary",
|
|
58
|
+
"@sitecore-jss/sitecore-jss-rendering-host": "~22.3.0-canary",
|
|
59
59
|
"babel-loader": "~9.1.0",
|
|
60
60
|
"babel-preset-react-app": "~10.0.1",
|
|
61
61
|
"chalk": "~4.1.2",
|
|
@@ -31,6 +31,11 @@ generateConfig();
|
|
|
31
31
|
* NOTE! Any configs returned here will be written into the client-side JS bundle. DO NOT PUT SECRETS HERE.
|
|
32
32
|
*/
|
|
33
33
|
function generateConfig() {
|
|
34
|
+
// Handle undefined values
|
|
35
|
+
Object.keys(defaultConfig).forEach((prop) => {
|
|
36
|
+
defaultConfig[prop] = defaultConfig[prop] || '';
|
|
37
|
+
});
|
|
38
|
+
|
|
34
39
|
try {
|
|
35
40
|
config = jssConfigFactory.create(defaultConfig);
|
|
36
41
|
} catch (error) {
|
|
@@ -50,9 +55,11 @@ const config = {};\n`;
|
|
|
50
55
|
|
|
51
56
|
// Set base configuration values, allowing override with environment variables
|
|
52
57
|
Object.keys(config).forEach(prop => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
58
|
+
// Handle undefined values
|
|
59
|
+
const value = config[prop] || '';
|
|
60
|
+
configText += `config.${prop} = process.env.REACT_APP_${constantCase(
|
|
61
|
+
prop
|
|
62
|
+
)} || "${value.trim()}";\n`;
|
|
56
63
|
});
|
|
57
64
|
configText += 'module.exports = config;';
|
|
58
65
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%- appName %>",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary",
|
|
4
4
|
"description": "A basic React Native app utilizing Sitecore JavaScript Services",
|
|
5
5
|
"config": {
|
|
6
6
|
"appName": "<%- appName %>",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@react-native-community/masked-view": "^0.1.10",
|
|
26
|
-
"@sitecore-jss/sitecore-jss-react-native": "~22.
|
|
26
|
+
"@sitecore-jss/sitecore-jss-react-native": "~22.3.0-canary",
|
|
27
27
|
"prop-types": "^15.6.0",
|
|
28
28
|
"react": "16.13.1",
|
|
29
29
|
"react-native": "^0.63.4",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"private": true,
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@sitecore-jss/sitecore-jss-cli": "~22.
|
|
41
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "~22.
|
|
40
|
+
"@sitecore-jss/sitecore-jss-cli": "~22.3.0-canary",
|
|
41
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "~22.3.0-canary",
|
|
42
42
|
"babel-core": "^6.26.0",
|
|
43
43
|
"babel-eslint": "^8.2.1",
|
|
44
44
|
"babel-plugin-inline-replace-variables": "^1.3.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<%- appName %>",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary",
|
|
4
4
|
"description": "Application utilizing Sitecore JavaScript Services and Vue (vue-cli).",
|
|
5
5
|
"private": true,
|
|
6
6
|
"config": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@apollo/client": "^3.7.4",
|
|
47
47
|
"@panter/vue-i18next": "~0.15.2",
|
|
48
|
-
"@sitecore-jss/sitecore-jss-vue": "~22.
|
|
48
|
+
"@sitecore-jss/sitecore-jss-vue": "~22.3.0-canary",
|
|
49
49
|
"@vue/apollo-composable": "4.0.0-beta.2",
|
|
50
50
|
"@vue/apollo-option": "^4.0.0-alpha.20",
|
|
51
51
|
"@vue/apollo-ssr": "^4.0.0-alpha.18",
|
|
@@ -64,8 +64,8 @@
|
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@babel/eslint-parser": "^7.19.1",
|
|
66
66
|
"@babel/register": "7.18.9",
|
|
67
|
-
"@sitecore-jss/sitecore-jss-cli": "~22.
|
|
68
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "~22.
|
|
67
|
+
"@sitecore-jss/sitecore-jss-cli": "~22.3.0-canary",
|
|
68
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "~22.3.0-canary",
|
|
69
69
|
"@vue/cli-plugin-babel": "~5.0.8",
|
|
70
70
|
"@vue/cli-plugin-eslint": "~5.0.8",
|
|
71
71
|
"@vue/cli-service": "~5.0.8",
|
|
@@ -33,6 +33,11 @@ module.exports = function generateConfig(configOverrides) {
|
|
|
33
33
|
// and finally config passed in the configOverrides param wins.
|
|
34
34
|
const config = Object.assign(defaultConfig, scjssConfig, packageJson, configOverrides);
|
|
35
35
|
|
|
36
|
+
// Handle undefined values
|
|
37
|
+
Object.keys(config).forEach((prop) => {
|
|
38
|
+
config[prop] = config[prop] || '';
|
|
39
|
+
});
|
|
40
|
+
|
|
36
41
|
// The GraphQL endpoint is an example of making a _computed_ config setting
|
|
37
42
|
// based on other config settings.
|
|
38
43
|
const computedConfig = {};
|