@sitecore-cloudsdk/personalize 0.3.1-rc.1 → 0.4.0-rc.0
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/README.md +49 -65
- package/dist/cjs/package.json +4 -3
- package/dist/cjs/src/browser.d.ts +3 -2
- package/dist/cjs/src/browser.js +4 -3
- package/dist/cjs/src/lib/consts.d.ts +7 -10
- package/dist/cjs/src/lib/consts.js +10 -11
- package/dist/cjs/src/lib/{initializer → init}/client/initializer.d.ts +4 -2
- package/dist/cjs/src/lib/{initializer → init}/client/initializer.js +16 -9
- package/dist/cjs/src/lib/init/server/initializer.d.ts +11 -0
- package/dist/cjs/src/lib/init/server/initializer.js +28 -0
- package/dist/cjs/src/lib/initializer/browser/createPersonalizeCookie.d.ts +3 -0
- package/dist/cjs/src/lib/initializer/browser/createPersonalizeCookie.js +20 -0
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +32 -0
- package/dist/cjs/src/lib/initializer/browser/initializer.js +73 -0
- package/dist/cjs/src/lib/initializer/browser/interfaces.d.ts +17 -0
- package/dist/cjs/src/lib/initializer/browser/interfaces.js +2 -0
- package/dist/cjs/src/lib/initializer/server/createPersonalizeCookie.d.ts +4 -0
- package/dist/cjs/src/lib/initializer/server/createPersonalizeCookie.js +13 -0
- package/dist/cjs/src/lib/initializer/server/handleHttpCookie.d.ts +4 -0
- package/dist/cjs/src/lib/initializer/server/handleHttpCookie.js +31 -0
- package/dist/cjs/src/lib/initializer/server/handleNextJsMiddlewareCookie.d.ts +4 -0
- package/dist/cjs/src/lib/initializer/server/handleNextJsMiddlewareCookie.js +27 -0
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +13 -8
- package/dist/cjs/src/lib/initializer/server/initializer.js +32 -18
- package/dist/cjs/src/lib/initializer/server/interfaces.d.ts +11 -0
- package/dist/cjs/src/lib/initializer/server/interfaces.js +2 -0
- package/dist/cjs/src/lib/personalization/personalize.d.ts +1 -1
- package/dist/cjs/src/lib/personalization/personalize.js +20 -9
- package/dist/cjs/src/lib/personalization/personalizeServer.d.ts +1 -1
- package/dist/cjs/src/lib/personalization/personalizeServer.js +17 -5
- package/dist/cjs/src/lib/personalization/personalizer.d.ts +4 -4
- package/dist/cjs/src/lib/personalization/personalizer.js +2 -2
- package/dist/cjs/src/lib/personalization/send-call-flows-request.d.ts +2 -2
- package/dist/cjs/src/lib/personalization/send-call-flows-request.js +11 -11
- package/dist/cjs/src/lib/web-personalization/get-cdn-url.d.ts +1 -0
- package/dist/cjs/src/lib/web-personalization/get-cdn-url.js +18 -0
- package/dist/cjs/src/server.d.ts +3 -2
- package/dist/cjs/src/server.js +4 -3
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +4 -3
- package/dist/esm/src/browser.d.ts +3 -2
- package/dist/esm/src/browser.js +3 -2
- package/dist/esm/src/lib/consts.d.ts +7 -10
- package/dist/esm/src/lib/consts.js +9 -10
- package/dist/esm/src/lib/{initializer → init}/client/initializer.d.ts +4 -2
- package/dist/esm/src/lib/{initializer → init}/client/initializer.js +13 -6
- package/dist/esm/src/lib/init/server/initializer.d.ts +11 -0
- package/dist/esm/src/lib/init/server/initializer.js +24 -0
- package/dist/esm/src/lib/initializer/browser/createPersonalizeCookie.d.ts +3 -0
- package/dist/esm/src/lib/initializer/browser/createPersonalizeCookie.js +16 -0
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +32 -0
- package/dist/esm/src/lib/initializer/browser/initializer.js +68 -0
- package/dist/esm/src/lib/initializer/browser/interfaces.d.ts +17 -0
- package/dist/esm/src/lib/initializer/browser/interfaces.js +1 -0
- package/dist/esm/src/lib/initializer/server/createPersonalizeCookie.d.ts +4 -0
- package/dist/esm/src/lib/initializer/server/createPersonalizeCookie.js +9 -0
- package/dist/esm/src/lib/initializer/server/handleHttpCookie.d.ts +4 -0
- package/dist/esm/src/lib/initializer/server/handleHttpCookie.js +27 -0
- package/dist/esm/src/lib/initializer/server/handleNextJsMiddlewareCookie.d.ts +4 -0
- package/dist/esm/src/lib/initializer/server/handleNextJsMiddlewareCookie.js +23 -0
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +13 -8
- package/dist/esm/src/lib/initializer/server/initializer.js +29 -16
- package/dist/esm/src/lib/initializer/server/interfaces.d.ts +11 -0
- package/dist/esm/src/lib/initializer/server/interfaces.js +1 -0
- package/dist/esm/src/lib/personalization/personalize.d.ts +1 -1
- package/dist/esm/src/lib/personalization/personalize.js +21 -10
- package/dist/esm/src/lib/personalization/personalizeServer.d.ts +1 -1
- package/dist/esm/src/lib/personalization/personalizeServer.js +18 -6
- package/dist/esm/src/lib/personalization/personalizer.d.ts +4 -4
- package/dist/esm/src/lib/personalization/personalizer.js +1 -1
- package/dist/esm/src/lib/personalization/send-call-flows-request.d.ts +2 -2
- package/dist/esm/src/lib/personalization/send-call-flows-request.js +3 -3
- package/dist/esm/src/lib/web-personalization/get-cdn-url.d.ts +1 -0
- package/dist/esm/src/lib/web-personalization/get-cdn-url.js +14 -0
- package/dist/esm/src/server.d.ts +3 -2
- package/dist/esm/src/server.js +3 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
# personalize
|
|
2
2
|
|
|
3
|
-
This package provides browser- and server-side functions to run
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
To use the Sitecore Cloud SDK, you need an XM Cloud project. This project has to be created from the [XM Cloud foundation template](https://github.com/sitecorelabs/xmcloud-foundation-head) and deployed on XM Cloud.
|
|
8
|
-
|
|
9
|
-
The foundation template contains an XM Cloud JSS Next.js app. You use the Sitecore Cloud SDK in this app. To be able to use the Sitecore Cloud SDK, you need JSS version 21.6.0 or newer.
|
|
3
|
+
This package provides browser- and server-side functions to run personalizations in your app. Personalization is for showing the most relevant content to your users.
|
|
10
4
|
|
|
11
5
|
## Installation
|
|
12
6
|
|
|
@@ -16,86 +10,76 @@ npm install @sitecore-cloudsdk/personalize
|
|
|
16
10
|
|
|
17
11
|
## Usage
|
|
18
12
|
|
|
19
|
-
1. Initialize the package using the `
|
|
20
|
-
2.
|
|
13
|
+
1. Initialize the package using the `CloudSDK` function, available in the `core` package.
|
|
14
|
+
2. To run web personalization (browser-side only):
|
|
15
|
+
1. Initialize the `events` package.
|
|
16
|
+
2. Enable web personalization during initialization.
|
|
17
|
+
3. To run interactive personalization, use the `personalize` function.
|
|
21
18
|
|
|
22
19
|
## Code examples
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
**NOTE**
|
|
27
|
-
|
|
28
|
-
These code examples illustrate how the Sitecore Cloud SDK works in a standalone Next.js app. In production, you implement Sitecore Cloud SDK functionality differently, in a JSS Next.js app. See code examples for that environment in the official documentation.
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
Run personalization from the browser side:
|
|
21
|
+
Run personalizations from the browser side:
|
|
33
22
|
|
|
34
23
|
```ts
|
|
35
24
|
'use client';
|
|
25
|
+
|
|
36
26
|
import { useEffect } from 'react';
|
|
37
|
-
import {
|
|
27
|
+
import { CloudSDK } from '@sitecore-cloudsdk/core/browser';
|
|
28
|
+
import { personalize } from '@sitecore-cloudsdk/personalize/browser';
|
|
38
29
|
|
|
39
30
|
export default function Home() {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
|
|
47
|
-
siteName: process.env.NEXT_PUBLIC_SITENAME || '',
|
|
48
|
-
enableBrowserCookie: true,
|
|
31
|
+
const getPersonalizeData = async () => {
|
|
32
|
+
// Run interactive personalization:
|
|
33
|
+
const data = await personalize({
|
|
34
|
+
channel: 'WEB',
|
|
35
|
+
currency: 'EUR',
|
|
36
|
+
friendlyId: '<YOUR_EXPERIENCE_FRIENDLY_ID>'
|
|
49
37
|
});
|
|
50
38
|
|
|
51
|
-
console.log(
|
|
39
|
+
console.log(data);
|
|
52
40
|
};
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
CloudSDK({
|
|
44
|
+
/* Initialization settings. See `core` package code examples. */
|
|
45
|
+
})
|
|
46
|
+
.addEvents() // Initialize the `events` package to enable web personalization
|
|
47
|
+
.addPersonalize({ enablePersonalizeCookie: true, webPersonalization: true }) // Enable web personalization
|
|
48
|
+
.initialize();
|
|
49
|
+
|
|
50
|
+
getPersonalizeData();
|
|
51
|
+
}, []);
|
|
63
52
|
|
|
64
|
-
return
|
|
65
|
-
<div>
|
|
66
|
-
<button onClick={runPersonalization}>run personalization</button>
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
53
|
+
return <></>;
|
|
69
54
|
}
|
|
70
55
|
```
|
|
71
56
|
|
|
72
|
-
Run
|
|
57
|
+
Run personalizations from the server side:
|
|
73
58
|
|
|
74
59
|
```ts
|
|
75
|
-
import { NextResponse } from 'next/server';
|
|
76
|
-
import
|
|
77
|
-
import {
|
|
78
|
-
|
|
79
|
-
export async function middleware(
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
await
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
import type { NextRequest, NextResponse } from 'next/server';
|
|
61
|
+
import { CloudSDK } from '@sitecore-cloudsdk/core/server';
|
|
62
|
+
import { personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
63
|
+
|
|
64
|
+
export async function middleware(request: NextRequest) {
|
|
65
|
+
const response = NextResponse.next();
|
|
66
|
+
|
|
67
|
+
await CloudSDK(request, response, {
|
|
68
|
+
/* Initialization settings. See `core` package code examples. */
|
|
69
|
+
})
|
|
70
|
+
.addPersonalize({ enablePersonalizeCookie: true })
|
|
71
|
+
.initialize();
|
|
72
|
+
|
|
73
|
+
// Run interactive personalization:
|
|
74
|
+
const data = await personalize(request, {
|
|
75
|
+
channel: 'WEB',
|
|
76
|
+
currency: 'EUR',
|
|
77
|
+
friendlyId: '<YOUR_EXPERIENCE_FRIENDLY_ID>'
|
|
86
78
|
});
|
|
87
79
|
|
|
88
|
-
console.log(
|
|
89
|
-
|
|
90
|
-
const personalizationData = {
|
|
91
|
-
friendlyId: 'personalize_test',
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
await personalize(req, personalizationData);
|
|
95
|
-
|
|
96
|
-
console.log('Ran personalization.');
|
|
80
|
+
console.log(data);
|
|
97
81
|
|
|
98
|
-
return
|
|
82
|
+
return response;
|
|
99
83
|
}
|
|
100
84
|
```
|
|
101
85
|
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-cloudsdk/personalize",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-rc.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
|
|
6
6
|
"exports": {
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@sitecore-cloudsdk/core": "^0.
|
|
20
|
-
"@sitecore-cloudsdk/
|
|
19
|
+
"@sitecore-cloudsdk/core": "^0.4.0-rc.0",
|
|
20
|
+
"@sitecore-cloudsdk/events": "^0.4.0-rc.0",
|
|
21
|
+
"@sitecore-cloudsdk/utils": "^0.4.0-rc.0"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"build": "npm run build:cjs && npm run build:es",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { init } from './lib/
|
|
1
|
+
export { init } from './lib/init/client/initializer';
|
|
2
2
|
export { personalize } from './lib/personalization/personalize';
|
|
3
|
-
export {
|
|
3
|
+
export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts';
|
|
4
4
|
export type { PersonalizeData } from './lib/personalization/personalizer';
|
|
5
|
+
import './lib/initializer/browser/initializer';
|
package/dist/cjs/src/browser.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PERSONALIZE_NAMESPACE = exports.
|
|
5
|
-
var initializer_1 = require("./lib/
|
|
4
|
+
exports.PERSONALIZE_NAMESPACE = exports.PACKAGE_VERSION = exports.personalize = exports.init = void 0;
|
|
5
|
+
var initializer_1 = require("./lib/init/client/initializer");
|
|
6
6
|
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return initializer_1.init; } });
|
|
7
7
|
var personalize_1 = require("./lib/personalization/personalize");
|
|
8
8
|
Object.defineProperty(exports, "personalize", { enumerable: true, get: function () { return personalize_1.personalize; } });
|
|
9
9
|
var consts_1 = require("./lib/consts");
|
|
10
|
-
Object.defineProperty(exports, "
|
|
10
|
+
Object.defineProperty(exports, "PACKAGE_VERSION", { enumerable: true, get: function () { return consts_1.PACKAGE_VERSION; } });
|
|
11
11
|
Object.defineProperty(exports, "PERSONALIZE_NAMESPACE", { enumerable: true, get: function () { return consts_1.PERSONALIZE_NAMESPACE; } });
|
|
12
|
+
require("./lib/initializer/browser/initializer");
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
1
|
+
export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize";
|
|
2
|
+
export declare const PACKAGE_VERSION: string;
|
|
3
|
+
export declare const PACKAGE_NAME: string;
|
|
4
|
+
export declare const UTM_PREFIX = "utm_";
|
|
5
5
|
export declare enum ErrorMessages {
|
|
6
|
-
IE_0001 = "[IE-0001]
|
|
6
|
+
IE_0001 = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules.",
|
|
7
7
|
IE_0006 = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function.",
|
|
8
8
|
IE_0007 = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function.",
|
|
9
|
+
IE_0016 = "[IE-0016] - You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\".",
|
|
10
|
+
IE_0017 = "[IE-0017] - You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/server\", and import \"@sitecore-cloudsdk/personalize/server\". Then, run \"await CloudSDK().addPersonalize().initialize()\".",
|
|
9
11
|
MV_0004 = "[MV-0004] \"friendlyId\" is required."
|
|
10
12
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the namespace of the library.
|
|
13
|
-
*/
|
|
14
|
-
export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize";
|
|
15
|
-
export declare const UTM_PREFIX = "utm_";
|
|
@@ -4,23 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.UTM_PREFIX = exports.
|
|
7
|
+
exports.ErrorMessages = exports.UTM_PREFIX = exports.PACKAGE_NAME = exports.PACKAGE_VERSION = exports.PERSONALIZE_NAMESPACE = void 0;
|
|
8
8
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
9
9
|
const package_json_1 = __importDefault(require("../../package.json"));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.
|
|
10
|
+
exports.PERSONALIZE_NAMESPACE = 'sitecore-cloudsdk:personalize';
|
|
11
|
+
exports.PACKAGE_VERSION = package_json_1.default.version;
|
|
12
|
+
exports.PACKAGE_NAME = package_json_1.default.name;
|
|
13
|
+
exports.UTM_PREFIX = 'utm_';
|
|
14
14
|
var ErrorMessages;
|
|
15
15
|
(function (ErrorMessages) {
|
|
16
16
|
// eslint-disable-next-line max-len
|
|
17
|
-
ErrorMessages["IE_0001"] = "[IE-0001]
|
|
17
|
+
ErrorMessages["IE_0001"] = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules.";
|
|
18
18
|
ErrorMessages["IE_0006"] = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function.";
|
|
19
19
|
ErrorMessages["IE_0007"] = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function.";
|
|
20
|
+
// eslint-disable-next-line max-len
|
|
21
|
+
ErrorMessages["IE_0016"] = "[IE-0016] - You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\".";
|
|
22
|
+
// eslint-disable-next-line max-len
|
|
23
|
+
ErrorMessages["IE_0017"] = "[IE-0017] - You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/server\", and import \"@sitecore-cloudsdk/personalize/server\". Then, run \"await CloudSDK().addPersonalize().initialize()\".";
|
|
20
24
|
ErrorMessages["MV_0004"] = "[MV-0004] \"friendlyId\" is required.";
|
|
21
25
|
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
|
|
22
|
-
/**
|
|
23
|
-
* Returns the namespace of the library.
|
|
24
|
-
*/
|
|
25
|
-
exports.PERSONALIZE_NAMESPACE = 'sitecore-cloudsdk:personalize';
|
|
26
|
-
exports.UTM_PREFIX = 'utm_';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BrowserSettings } from '@sitecore-cloudsdk/core/internal';
|
|
2
2
|
export declare let initPromise: Promise<void> | null;
|
|
3
3
|
/**
|
|
4
4
|
* Initiates the Engage library using the global settings added by the developer
|
|
5
5
|
* @param settings - Global settings added by the developer
|
|
6
|
-
* @returns A promise that resolves with an object that handles the library
|
|
6
|
+
* @returns A promise that resolves with an object that handles the library
|
|
7
|
+
* The base class for controls that can be rendered.
|
|
8
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
7
9
|
*/
|
|
8
10
|
export declare function init(settings: BrowserSettings): Promise<void>;
|
|
9
11
|
/**
|
|
@@ -2,34 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.awaitInit = exports.init = exports.initPromise = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
5
6
|
const consts_1 = require("../../consts");
|
|
6
|
-
const
|
|
7
|
+
const internal_2 = require("@sitecore-cloudsdk/core/internal");
|
|
7
8
|
exports.initPromise = null;
|
|
9
|
+
/* eslint-disable max-len */
|
|
8
10
|
/**
|
|
9
11
|
* Initiates the Engage library using the global settings added by the developer
|
|
10
12
|
* @param settings - Global settings added by the developer
|
|
11
|
-
* @returns A promise that resolves with an object that handles the library
|
|
13
|
+
* @returns A promise that resolves with an object that handles the library
|
|
14
|
+
* The base class for controls that can be rendered.
|
|
15
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
12
16
|
*/
|
|
17
|
+
/* eslint-enable max-len */
|
|
13
18
|
async function init(settings) {
|
|
14
19
|
if (typeof window === 'undefined')
|
|
15
20
|
throw new Error(consts_1.ErrorMessages.IE_0001);
|
|
16
21
|
try {
|
|
17
|
-
exports.initPromise = (0,
|
|
22
|
+
exports.initPromise = (0, internal_2.initCore)(settings);
|
|
18
23
|
await exports.initPromise;
|
|
19
|
-
(0,
|
|
24
|
+
(0, internal_2.debug)(consts_1.PERSONALIZE_NAMESPACE)('personalizeClient library initialized');
|
|
20
25
|
}
|
|
21
26
|
catch (error) {
|
|
22
|
-
(0,
|
|
27
|
+
(0, internal_2.debug)(consts_1.PERSONALIZE_NAMESPACE)('Error on initializing personalizeClient library with error: %o', error);
|
|
23
28
|
exports.initPromise = null;
|
|
24
29
|
throw new Error(error);
|
|
25
30
|
}
|
|
26
31
|
window.Engage ?? (window.Engage = {});
|
|
27
32
|
window.Engage = {
|
|
28
33
|
...window.Engage,
|
|
29
|
-
getBrowserId: () => (0,
|
|
34
|
+
getBrowserId: () => (0, internal_1.getBrowserId)(),
|
|
30
35
|
versions: {
|
|
31
36
|
...window.Engage.versions,
|
|
32
|
-
personalize: consts_1.
|
|
37
|
+
personalize: consts_1.PACKAGE_VERSION
|
|
33
38
|
}
|
|
34
39
|
};
|
|
35
40
|
}
|
|
@@ -38,8 +43,10 @@ exports.init = init;
|
|
|
38
43
|
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
39
44
|
*/
|
|
40
45
|
async function awaitInit() {
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
const initState = (0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.initState;
|
|
47
|
+
if (exports.initPromise === null && !initState)
|
|
48
|
+
throw new Error(consts_1.ErrorMessages.IE_0016);
|
|
43
49
|
await exports.initPromise;
|
|
50
|
+
await initState;
|
|
44
51
|
}
|
|
45
52
|
exports.awaitInit = awaitInit;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Request, Response } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import { type ServerSettings } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
/**
|
|
4
|
+
* Initiates the server Engage library using the global settings added by the developer
|
|
5
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request
|
|
6
|
+
* @param response - The response object, either a Middleware Next Response or an HTTP Response
|
|
7
|
+
* @param settings - Global settings added by the developer
|
|
8
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
9
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
10
|
+
*/
|
|
11
|
+
export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.initServer = void 0;
|
|
5
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
6
|
+
const consts_1 = require("../../consts");
|
|
7
|
+
const internal_2 = require("@sitecore-cloudsdk/core/internal");
|
|
8
|
+
/* eslint-disable max-len */
|
|
9
|
+
/**
|
|
10
|
+
* Initiates the server Engage library using the global settings added by the developer
|
|
11
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request
|
|
12
|
+
* @param response - The response object, either a Middleware Next Response or an HTTP Response
|
|
13
|
+
* @param settings - Global settings added by the developer
|
|
14
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
15
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
16
|
+
*/
|
|
17
|
+
/* eslint-enable max-len */
|
|
18
|
+
async function initServer(request, response, settings) {
|
|
19
|
+
try {
|
|
20
|
+
await (0, internal_1.initCoreServer)(settings, request, response);
|
|
21
|
+
(0, internal_2.debug)(consts_1.PERSONALIZE_NAMESPACE)('personalizeServer library initialized');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
(0, internal_2.debug)(consts_1.PERSONALIZE_NAMESPACE)('Error on initializing personalizeServer library with error: %o', error);
|
|
25
|
+
throw new Error(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.initServer = initServer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPersonalizeCookie = void 0;
|
|
4
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
5
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
6
|
+
async function createPersonalizeCookie(personalizeSettings, cloudSDKSettings) {
|
|
7
|
+
const cookiesValuesFromEdgeBrowser = (0, internal_1.getCookiesValuesFromEdgeBrowser)();
|
|
8
|
+
const attributes = (0, internal_1.getDefaultCookieAttributes)(cloudSDKSettings.cookieSettings.expiryDays, cloudSDKSettings.cookieSettings.domain);
|
|
9
|
+
const guestIdCookieValue = (0, utils_1.getCookieValueClientSide)(personalizeSettings.cookieSettings.name.guestId);
|
|
10
|
+
const browserIdCookieValue = (0, utils_1.getCookieValueClientSide)(cloudSDKSettings.cookieSettings.name.browserId);
|
|
11
|
+
if (guestIdCookieValue)
|
|
12
|
+
return;
|
|
13
|
+
else if (cookiesValuesFromEdgeBrowser?.guestId)
|
|
14
|
+
document.cookie = (0, utils_1.createCookieString)(personalizeSettings.cookieSettings.name.guestId, cookiesValuesFromEdgeBrowser.guestId, attributes);
|
|
15
|
+
else if (browserIdCookieValue) {
|
|
16
|
+
const guestIdCookieValue = await (0, internal_1.getGuestId)(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl);
|
|
17
|
+
document.cookie = (0, utils_1.createCookieString)(personalizeSettings.cookieSettings.name.guestId, guestIdCookieValue, attributes);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.createPersonalizeCookie = createPersonalizeCookie;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CloudSDKBrowserInitializer } from '@sitecore-cloudsdk/core/browser';
|
|
2
|
+
import { type EPResponse } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
import type { EventData, IdentityData } from '@sitecore-cloudsdk/events/browser';
|
|
4
|
+
import type { BrowserSettings } from './interfaces';
|
|
5
|
+
export declare function sideEffects(): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Makes the functionality of the personalize package available.
|
|
8
|
+
*
|
|
9
|
+
* @returns An instance of {@link CloudSDKBrowserInitializer}
|
|
10
|
+
*/
|
|
11
|
+
export declare function addPersonalize(this: CloudSDKBrowserInitializer, settings?: BrowserSettings): CloudSDKBrowserInitializer;
|
|
12
|
+
declare module '@sitecore-cloudsdk/core/browser' {
|
|
13
|
+
interface CloudSDKBrowserInitializer {
|
|
14
|
+
addPersonalize: typeof addPersonalize;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
declare global {
|
|
18
|
+
interface Personalize {
|
|
19
|
+
settings?: {
|
|
20
|
+
async?: boolean;
|
|
21
|
+
defer?: boolean;
|
|
22
|
+
};
|
|
23
|
+
version: string;
|
|
24
|
+
pageView?: () => Promise<EPResponse | null>;
|
|
25
|
+
identity?: (identityData: IdentityData) => Promise<EPResponse | null>;
|
|
26
|
+
form?: (formId: string, interactionType: 'VIEWED' | 'SUBMITTED', componentInstanceId: string) => Promise<EPResponse | null>;
|
|
27
|
+
event?: (eventData: EventData) => Promise<EPResponse | null>;
|
|
28
|
+
addToEventQueue?: (eventData: EventData) => Promise<void>;
|
|
29
|
+
processEventQueue?: () => Promise<void>;
|
|
30
|
+
clearEventQueue?: () => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addPersonalize = exports.sideEffects = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const browser_1 = require("@sitecore-cloudsdk/core/browser");
|
|
6
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
7
|
+
const browser_2 = require("@sitecore-cloudsdk/events/browser");
|
|
8
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
9
|
+
const consts_1 = require("../../consts");
|
|
10
|
+
const get_cdn_url_1 = require("../../web-personalization/get-cdn-url");
|
|
11
|
+
const createPersonalizeCookie_1 = require("./createPersonalizeCookie");
|
|
12
|
+
async function sideEffects() {
|
|
13
|
+
const personalizeSettings = (0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.settings;
|
|
14
|
+
const cloudSDKSettings = (0, internal_1.getCloudSDKSettingsBrowser)();
|
|
15
|
+
window.scCloudSDK = {
|
|
16
|
+
...window.scCloudSDK,
|
|
17
|
+
personalize: {
|
|
18
|
+
version: consts_1.PACKAGE_VERSION
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
if (personalizeSettings.webPersonalization) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
|
+
window.scCloudSDK.personalize.settings = personalizeSettings.webPersonalization;
|
|
24
|
+
window.scCloudSDK.personalize = {
|
|
25
|
+
...window.scCloudSDK.personalize,
|
|
26
|
+
addToEventQueue: browser_2.addToEventQueue,
|
|
27
|
+
clearEventQueue: browser_2.clearEventQueue,
|
|
28
|
+
event: browser_2.event,
|
|
29
|
+
form: browser_2.form,
|
|
30
|
+
identity: browser_2.identity,
|
|
31
|
+
pageView: browser_2.pageView,
|
|
32
|
+
processEventQueue: browser_2.processEventQueue
|
|
33
|
+
};
|
|
34
|
+
const cdnUrl = await (0, get_cdn_url_1.getCdnUrl)(cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl);
|
|
35
|
+
if (cdnUrl)
|
|
36
|
+
(0, utils_1.appendScriptWithAttributes)({ async: personalizeSettings.webPersonalization.async, src: cdnUrl });
|
|
37
|
+
}
|
|
38
|
+
(0, internal_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('personalizeClient library initialized');
|
|
39
|
+
if (!cloudSDKSettings.cookieSettings.enableBrowserCookie || !personalizeSettings.enablePersonalizeCookie)
|
|
40
|
+
return;
|
|
41
|
+
await (0, createPersonalizeCookie_1.createPersonalizeCookie)(personalizeSettings, cloudSDKSettings);
|
|
42
|
+
}
|
|
43
|
+
exports.sideEffects = sideEffects;
|
|
44
|
+
/**
|
|
45
|
+
* Makes the functionality of the personalize package available.
|
|
46
|
+
*
|
|
47
|
+
* @returns An instance of {@link CloudSDKBrowserInitializer}
|
|
48
|
+
*/
|
|
49
|
+
function addPersonalize(settings = { enablePersonalizeCookie: false }) {
|
|
50
|
+
const dependencies = [];
|
|
51
|
+
const cookieSettings = {
|
|
52
|
+
name: {
|
|
53
|
+
guestId: `${internal_1.COOKIE_NAME_PREFIX}${(0, internal_1.getCloudSDKSettingsBrowser)().sitecoreEdgeContextId}_personalize`
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
let webPersonalization = false;
|
|
57
|
+
if (settings.webPersonalization) {
|
|
58
|
+
dependencies.push({ method: browser_2.PACKAGE_INITIALIZER_METHOD_NAME, name: browser_2.PACKAGE_NAME });
|
|
59
|
+
webPersonalization = {
|
|
60
|
+
async: settings.webPersonalization.async ?? true,
|
|
61
|
+
defer: settings.webPersonalization.defer ?? false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const personalizeInitializer = new internal_1.PackageInitializer({
|
|
65
|
+
dependencies,
|
|
66
|
+
settings: { ...settings, cookieSettings, webPersonalization },
|
|
67
|
+
sideEffects
|
|
68
|
+
});
|
|
69
|
+
internal_1.enabledPackagesBrowser.set(consts_1.PACKAGE_NAME, personalizeInitializer);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
exports.addPersonalize = addPersonalize;
|
|
73
|
+
browser_1.CloudSDKBrowserInitializer.prototype.addPersonalize = addPersonalize;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type WebPersonalizationSettings = {
|
|
2
|
+
async: boolean;
|
|
3
|
+
defer: boolean;
|
|
4
|
+
};
|
|
5
|
+
export interface BrowserSettings {
|
|
6
|
+
webPersonalization?: boolean | Partial<WebPersonalizationSettings>;
|
|
7
|
+
enablePersonalizeCookie?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PersonalizeSettings {
|
|
10
|
+
webPersonalization: false | WebPersonalizationSettings;
|
|
11
|
+
enablePersonalizeCookie?: boolean;
|
|
12
|
+
cookieSettings: {
|
|
13
|
+
name: {
|
|
14
|
+
guestId: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Settings } from '@sitecore-cloudsdk/core/server';
|
|
2
|
+
import { type Request, type Response } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import type { PersonalizeSettings } from './interfaces';
|
|
4
|
+
export declare function createPersonalizeCookie(request: Request, response: Response, settings: PersonalizeSettings, cloudSDKSettings: Settings): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPersonalizeCookie = void 0;
|
|
4
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
5
|
+
const handleHttpCookie_1 = require("./handleHttpCookie");
|
|
6
|
+
const handleNextJsMiddlewareCookie_1 = require("./handleNextJsMiddlewareCookie");
|
|
7
|
+
async function createPersonalizeCookie(request, response, settings, cloudSDKSettings) {
|
|
8
|
+
if ((0, utils_1.isNextJsMiddlewareRequest)(request) && (0, utils_1.isNextJsMiddlewareResponse)(response))
|
|
9
|
+
await (0, handleNextJsMiddlewareCookie_1.handleNextJsMiddlewareCookie)(request, response, settings, cloudSDKSettings);
|
|
10
|
+
else if ((0, utils_1.isHttpRequest)(request) && (0, utils_1.isHttpResponse)(response))
|
|
11
|
+
await (0, handleHttpCookie_1.handleHttpCookie)(request, response, settings, cloudSDKSettings);
|
|
12
|
+
}
|
|
13
|
+
exports.createPersonalizeCookie = createPersonalizeCookie;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Settings } from '@sitecore-cloudsdk/core/server';
|
|
2
|
+
import { type Request, type Response } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import type { PersonalizeSettings } from './interfaces';
|
|
4
|
+
export declare function handleHttpCookie(request: Request, response: Response, settings: PersonalizeSettings, cloudSDKSettings: Settings): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleHttpCookie = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
6
|
+
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
7
|
+
async function handleHttpCookie(request, response, settings, cloudSDKSettings) {
|
|
8
|
+
const httpRequest = request;
|
|
9
|
+
const httpResponse = response;
|
|
10
|
+
const cookiesValuesFromEdgeServer = (0, internal_1.getCookiesValuesFromEdgeServer)();
|
|
11
|
+
const guestIdCookie = (0, utils_1.getCookieServerSide)(httpRequest.headers.cookie, settings.cookieSettings.name.guestId);
|
|
12
|
+
const browserIdCookie = (0, utils_1.getCookieServerSide)(httpRequest.headers.cookie, cloudSDKSettings.cookieSettings.name.browserId);
|
|
13
|
+
const defaultCookieAttributes = (0, internal_1.getDefaultCookieAttributes)(cloudSDKSettings.cookieSettings.expiryDays, cloudSDKSettings.cookieSettings.domain);
|
|
14
|
+
let guestIdCookieString;
|
|
15
|
+
if (guestIdCookie)
|
|
16
|
+
guestIdCookieString = (0, utils_1.createCookieString)(settings.cookieSettings.name.guestId, guestIdCookie.value, defaultCookieAttributes);
|
|
17
|
+
else if (cookiesValuesFromEdgeServer.guestId)
|
|
18
|
+
guestIdCookieString = (0, utils_1.createCookieString)(settings.cookieSettings.name.guestId, cookiesValuesFromEdgeServer.guestId, defaultCookieAttributes);
|
|
19
|
+
else if (browserIdCookie) {
|
|
20
|
+
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestId)(browserIdCookie.value, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl);
|
|
21
|
+
guestIdCookieString = (0, utils_1.createCookieString)(settings.cookieSettings.name.guestId, guestIdCookieValueFromEdgeProxy, defaultCookieAttributes);
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
return;
|
|
25
|
+
if (!guestIdCookie)
|
|
26
|
+
httpRequest.headers.cookie = httpRequest.headers.cookie
|
|
27
|
+
? httpRequest.headers.cookie + '; ' + guestIdCookieString
|
|
28
|
+
: guestIdCookieString;
|
|
29
|
+
httpResponse.setHeader('Set-Cookie', guestIdCookieString);
|
|
30
|
+
}
|
|
31
|
+
exports.handleHttpCookie = handleHttpCookie;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Settings } from '@sitecore-cloudsdk/core/server';
|
|
2
|
+
import type { Request, Response } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import type { PersonalizeSettings } from './interfaces';
|
|
4
|
+
export declare function handleNextJsMiddlewareCookie(request: Request, response: Response, settings: PersonalizeSettings, cloudSDKSettings: Settings): Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleNextJsMiddlewareCookie = void 0;
|
|
4
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
+
const internal_1 = require("@sitecore-cloudsdk/core/internal");
|
|
6
|
+
async function handleNextJsMiddlewareCookie(request, response, settings, cloudSDKSettings) {
|
|
7
|
+
const middlewareRequest = request;
|
|
8
|
+
const middlewareResponse = response;
|
|
9
|
+
const cookiesValuesFromEdgeServer = (0, internal_1.getCookiesValuesFromEdgeServer)();
|
|
10
|
+
const guestIdCookieValue = (0, internal_1.getCookieValueFromMiddlewareRequest)(middlewareRequest, settings.cookieSettings.name.guestId);
|
|
11
|
+
const browserIdCookieValue = (0, internal_1.getCookieValueFromMiddlewareRequest)(middlewareRequest, cloudSDKSettings.cookieSettings.name.browserId);
|
|
12
|
+
const defaultCookieAttributes = (0, internal_1.getDefaultCookieAttributes)(cloudSDKSettings.cookieSettings.expiryDays, cloudSDKSettings.cookieSettings.domain);
|
|
13
|
+
let guestIdValue;
|
|
14
|
+
if (guestIdCookieValue)
|
|
15
|
+
guestIdValue = guestIdCookieValue;
|
|
16
|
+
else if (cookiesValuesFromEdgeServer.guestId)
|
|
17
|
+
guestIdValue = cookiesValuesFromEdgeServer.guestId;
|
|
18
|
+
else if (browserIdCookieValue) {
|
|
19
|
+
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestId)(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl);
|
|
20
|
+
guestIdValue = guestIdCookieValueFromEdgeProxy;
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
return;
|
|
24
|
+
middlewareRequest.cookies.set(settings.cookieSettings.name.guestId, guestIdValue, defaultCookieAttributes);
|
|
25
|
+
middlewareResponse.cookies.set(settings.cookieSettings.name.guestId, guestIdValue, defaultCookieAttributes);
|
|
26
|
+
}
|
|
27
|
+
exports.handleNextJsMiddlewareCookie = handleNextJsMiddlewareCookie;
|