-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Nextjs] CloudSDK Integration (#1652)
* Initial commit * Handle async Events init call * Update * Update * Updated test * rename nextjs-personalize -> nextjs-xmcloud. move feaas and BYOC here. * Move Sitecore Edge Platform / conext related items to nextjs-xmcloud * Updated context initialization * Updated dependency * Updated Yarn.lock * Fix lint errors * Updated CHANGELOG * Repurpose nextjs-personalize -> nextjs-xmcloud initializer "system" template (driven by prompt / --xmcloud CLI option) * Moved skipping of site information fetch on XM Cloud to base package (GraphQLSiteInfoService) * CHANGELOG update * Updated Context implementation, added unit tests * Updated CHANGELOG * Updated comment * Updated cloudsdk to use latest production version * Updated yarn.lock * Introduced Bootstrap and pulled nextjs-xmcloud * Update .env * Updated jsdoc * Avoid unused vars rule for Bootstrap * Normalize sitecoreEdgeUrl * Updated CHANGELOG * Updated BYOC initialization * Updated Props doc * Updates * Updated unit test * Updated comment * Provided sitecoreEdgeUrl to the middleware * Refactoring * Passing props to SDK's * Updated type * Renamed SDKs -> sdks * Updated yarn.lock --------- Co-authored-by: Adam Brauer <[email protected]>
- Loading branch information
1 parent
3468861
commit 6325950
Showing
32 changed files
with
645 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 12 additions & 6 deletions
18
packages/create-sitecore-jss/src/templates/nextjs-sxa/src/pages/_app.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/create-sitecore-jss/src/templates/nextjs-xmcloud/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"@sitecore/components": "~1.0.19", | ||
"@sitecore/engage": "^1.4.1", | ||
"@sitecore/components": "^1.1.0", | ||
"@sitecore-cloudsdk/events": "^0.1.1", | ||
"@sitecore-feaas/clientside": "^0.4.12" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/Bootstrap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { SitecorePageProps } from 'lib/page-props'; | ||
import { context } from 'src/lib/context'; | ||
import { siteResolver } from 'lib/site-resolver'; | ||
import config from 'temp/config'; | ||
|
||
/** | ||
* The Bootstrap component is the entry point for performing any initialization logic | ||
* that needs to happen early in the application's lifecycle. | ||
*/ | ||
const Bootstrap = (props: SitecorePageProps): JSX.Element | null => { | ||
const site = props.layoutData?.sitecore.context.site; | ||
const siteInfo = siteResolver.getByName(site?.name || config.siteName); | ||
|
||
/** | ||
* Initializes the application Context and associated Software Development Kits (SDKs). | ||
* This function is the entry point for setting up the application's context and any SDKs that are required for its proper functioning. | ||
* It prepares the resources needed to interact with various services and features within the application. | ||
*/ | ||
context.init({ siteName: siteInfo.name }); | ||
|
||
return null; | ||
}; | ||
|
||
export default Bootstrap; |
7 changes: 2 additions & 5 deletions
7
packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/byoc/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/context/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Context } from '@sitecore-jss/sitecore-jss-nextjs/context'; | ||
import config from 'temp/config'; | ||
|
||
import Events from './sdk/events'; | ||
|
||
/** | ||
* List of SDKs to be initialized. | ||
* Each SDK is defined as a module with the @type {SDK} type. | ||
*/ | ||
const sdks = { | ||
Events, | ||
}; | ||
|
||
/** | ||
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs). | ||
*/ | ||
export const context = new Context<typeof sdks>({ | ||
sitecoreEdgeUrl: config.sitecoreEdgeUrl, | ||
sitecoreEdgeContextId: config.sitecoreEdgeContextId, | ||
siteName: config.siteName, | ||
sdks, | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/context/sdk/events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as Events from '@sitecore-cloudsdk/events/browser'; | ||
import { SDK } from '@sitecore-jss/sitecore-jss-nextjs/context'; | ||
|
||
const sdkModule: SDK<typeof Events> = { | ||
sdk: Events, | ||
init: async (props) => { | ||
// Events module can't be initialized on the server side | ||
// We also don't want to initialize it in development mode | ||
if (typeof window === 'undefined' || process.env.NODE_ENV === 'development') return; | ||
|
||
await Events.init({ | ||
siteName: props.siteName, | ||
sitecoreEdgeContextId: props.sitecoreEdgeContextId, | ||
// Replace with the top level cookie domain of the website that is being integrated e.g ".example.com" and not "www.example.com" | ||
cookieDomain: window.location.hostname.replace(/^www\./, ''), | ||
// Cookie may be created in personalize middleware (server), but if not we should create it here | ||
enableBrowserCookie: true, | ||
}); | ||
}, | ||
}; | ||
|
||
export default sdkModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
...create-sitecore-jss/src/templates/nextjs-xmcloud/src/lib/site-resolver/plugins/default.ts
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
packages/create-sitecore-jss/src/templates/nextjs/src/Bootstrap.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { SitecorePageProps } from 'lib/page-props'; | ||
|
||
/** | ||
* The Bootstrap component is the entry point for performing any initialization logic | ||
* that needs to happen early in the application's lifecycle. | ||
*/ | ||
const Bootstrap = (_props: SitecorePageProps): JSX.Element | null => { | ||
return null; | ||
}; | ||
|
||
export default Bootstrap; |
18 changes: 12 additions & 6 deletions
18
packages/create-sitecore-jss/src/templates/nextjs/src/pages/_app.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './types/context/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/cjs/context/index'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.