create-sitecore-jss 22.2.0-canary.80 → 22.2.0-canary.81

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.
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "dependencies": {
3
- "@sitecore/components": "^1.1.10",
4
- "@sitecore-cloudsdk/events": "^0.3.1",
3
+ "@sitecore/components": "~2.0.0",
4
+ "@sitecore-cloudsdk/core": "^0.4.0",
5
+ "@sitecore-cloudsdk/events": "^0.4.0",
5
6
  "@sitecore-feaas/clientside": "^0.5.17"
6
7
  }
7
8
  }
@@ -1,21 +1,36 @@
1
+ import { useEffect } from 'react';
1
2
  import { SitecorePageProps } from 'lib/page-props';
2
- import { context } from 'src/lib/context';
3
+ import { CloudSDK } from '@sitecore-cloudsdk/core/browser';
4
+ import '@sitecore-cloudsdk/events/browser';
3
5
  import config from 'temp/config';
6
+ import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-nextjs';
4
7
 
5
8
  /**
6
9
  * The Bootstrap component is the entry point for performing any initialization logic
7
10
  * that needs to happen early in the application's lifecycle.
8
11
  */
9
12
  const Bootstrap = (props: SitecorePageProps): JSX.Element | null => {
10
- /**
11
- * Initializes the application Context and associated Software Development Kits (SDKs).
12
- * This function is the entry point for setting up the application's context and any SDKs that are required for its proper functioning.
13
- * It prepares the resources needed to interact with various services and features within the application.
14
- */
15
- context.init({
16
- siteName: props.site?.name || config.sitecoreSiteName,
17
- pageState: props.layoutData?.sitecore?.context?.pageState,
18
- });
13
+ // Browser ClientSDK init allows for page view events to be tracked
14
+ useEffect(() => {
15
+ const pageState = props.layoutData?.sitecore?.context.pageState;
16
+ if (process.env.NODE_ENV === 'development')
17
+ console.debug('Browser Events SDK is not initialized in development environment');
18
+ else if (pageState !== LayoutServicePageState.Normal)
19
+ console.debug('Browser Events SDK is not initialized in edit and preview modes');
20
+ else {
21
+ CloudSDK({
22
+ sitecoreEdgeUrl: config.sitecoreEdgeUrl,
23
+ sitecoreEdgeContextId: config.sitecoreEdgeContextId,
24
+ siteName: props.site?.name || config.sitecoreSiteName,
25
+ enableBrowserCookie: true,
26
+ // Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com"
27
+ cookieDomain: window.location.hostname.replace(/^www\./, ''),
28
+ })
29
+ .addEvents()
30
+ .initialize();
31
+ }
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, [props.site?.name]);
19
34
 
20
35
  return null;
21
36
  };
@@ -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 { context } from 'lib/context';
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
- export default FEAAS.ExternalComponentBundle;
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 are cases where Events SDK will be absent which are expected to reject
50
- context
51
- .getSDK('Events')
52
- .then((Events) =>
53
- Events.pageView({
54
- channel: 'WEB',
55
- currency: 'USD',
56
- page: route.name,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sitecore-jss",
3
- "version": "22.2.0-canary.80",
3
+ "version": "22.2.0-canary.81",
4
4
  "description": "Sitecore JSS initializer",
5
5
  "bin": "./dist/index.js",
6
6
  "scripts": {
@@ -63,5 +63,5 @@
63
63
  "ts-node": "^10.9.1",
64
64
  "typescript": "~4.9.5"
65
65
  },
66
- "gitHead": "0ecca7f10712e929cfe4375ccfbd479020cd30fc"
66
+ "gitHead": "8b710877973ac2dedbf09cb4dffc62bb85bbc6dd"
67
67
  }
@@ -1,22 +0,0 @@
1
- import { Context } from '@sitecore-jss/sitecore-jss-nextjs/context';
2
- import config from 'temp/config';
3
-
4
- import Events from './sdk/events';
5
-
6
- /**
7
- * List of SDKs to be initialized.
8
- * Each SDK is defined as a module with the @type {SDK} type.
9
- */
10
- const sdks = {
11
- Events,
12
- };
13
-
14
- /**
15
- * Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
16
- */
17
- export const context = new Context<typeof sdks>({
18
- sitecoreEdgeUrl: config.sitecoreEdgeUrl,
19
- sitecoreEdgeContextId: config.sitecoreEdgeContextId,
20
- siteName: config.sitecoreSiteName,
21
- sdks,
22
- });
@@ -1,26 +0,0 @@
1
- import * as Events from '@sitecore-cloudsdk/events/browser';
2
- import { SDK } from '@sitecore-jss/sitecore-jss-nextjs/context';
3
-
4
- const sdkModule: SDK<typeof Events> = {
5
- sdk: Events,
6
- init: async (props) => {
7
- // Events module can't be initialized on the server side
8
- // We also don't want to initialize it in development mode
9
- if (typeof window === 'undefined')
10
- throw 'Browser Events SDK is not initialized in server context';
11
- if (process.env.NODE_ENV === 'development')
12
- throw 'Browser Events SDK is not initialized in development environment';
13
-
14
- await Events.init({
15
- siteName: props.siteName,
16
- sitecoreEdgeUrl: props.sitecoreEdgeUrl,
17
- sitecoreEdgeContextId: props.sitecoreEdgeContextId,
18
- // Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com"
19
- cookieDomain: window.location.hostname.replace(/^www\./, ''),
20
- // Cookie may be created in personalize middleware (server), but if not we should create it here
21
- enableBrowserCookie: true,
22
- });
23
- },
24
- };
25
-
26
- export default sdkModule;