Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nextjs] Update Cloudsdk to v0.4 #1933

Merged
merged 22 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"dependencies": {
"@sitecore/components": "^1.1.10",
"@sitecore-cloudsdk/events": "^0.3.1",
"@sitecore-cloudsdk/core": "^0.4.0-rc.0",
"@sitecore-cloudsdk/events": "^0.4.0-rc.0",
"@sitecore-feaas/clientside": "^0.5.17"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CloudSDK } from "@sitecore-cloudsdk/core/browser";
import * as Events from '@sitecore-cloudsdk/events/browser';
import { SDK } from '@sitecore-jss/sitecore-jss-nextjs/context';

Expand All @@ -11,15 +12,17 @@ const sdkModule: SDK<typeof Events> = {
if (process.env.NODE_ENV === 'development')
throw 'Browser Events SDK is not initialized in development environment';

await Events.init({
await CloudSDK({
siteName: props.siteName,
sitecoreEdgeUrl: props.sitecoreEdgeUrl,
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,
});
})
.addEvents()
.initialize();
},
};

Expand Down
7 changes: 4 additions & 3 deletions packages/sitecore-jss-nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"url": "https://github.com/sitecore/jss/issues"
},
"devDependencies": {
"@sitecore-cloudsdk/personalize": "^0.3.1",
"@sitecore-cloudsdk/core": "^0.4.0-rc.0",
"@sitecore-cloudsdk/personalize": "^0.4.0-rc.0",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
"@types/chai-string": "^1.4.2",
Expand Down Expand Up @@ -65,8 +66,8 @@
"typescript": "~4.9.4"
},
"peerDependencies": {
"@sitecore-cloudsdk/events": "^0.3.1",
"@sitecore-cloudsdk/personalize": "^0.3.1",
"@sitecore-cloudsdk/events": "^0.4.0-rc.0",
"@sitecore-cloudsdk/personalize": "^0.4.0-rc.0",
"next": "^14.2.7",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
} from '@sitecore-jss/sitecore-jss/personalize';
import { debug } from '@sitecore-jss/sitecore-jss';
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
import { init, personalize } from '@sitecore-cloudsdk/personalize/server';
import { CloudSDK } from '@sitecore-cloudsdk/core/server';
import { personalize } from '@sitecore-cloudsdk/personalize/server';

export type CdpServiceConfig = {
/**
Expand Down Expand Up @@ -119,13 +120,15 @@ export class PersonalizeMiddleware extends MiddlewareBase {
request: NextRequest;
response: NextResponse;
}): Promise<void> {
await init(request, response, {
await CloudSDK(request, response, {
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
siteName,
cookieDomain: hostname,
enableServerCookie: true,
});
})
.addPersonalize()
.initialize();
}

protected async personalize(
Expand Down
Loading