@sitecore-cloudsdk/personalize 0.1.1 → 0.1.3
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 +32 -25
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/browser.d.ts +1 -1
- package/dist/cjs/src/lib/initializer/client/initializer.d.ts +7 -10
- package/dist/cjs/src/lib/initializer/client/initializer.js +2 -2
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +7 -7
- package/dist/cjs/src/lib/initializer/server/initializer.js +1 -1
- package/dist/cjs/src/lib/personalization/callflow-edge-proxy-client.d.ts +22 -22
- package/dist/cjs/src/lib/personalization/callflow-edge-proxy-client.js +6 -6
- package/dist/cjs/src/lib/personalization/personalize.d.ts +3 -3
- package/dist/cjs/src/lib/personalization/personalizeServer.d.ts +4 -4
- package/dist/cjs/src/lib/personalization/personalizer.d.ts +15 -15
- package/dist/cjs/src/lib/personalization/personalizer.js +8 -8
- package/dist/cjs/src/server.d.ts +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/browser.d.ts +1 -1
- package/dist/esm/src/lib/initializer/client/initializer.d.ts +7 -10
- package/dist/esm/src/lib/initializer/client/initializer.js +3 -3
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +7 -7
- package/dist/esm/src/lib/initializer/server/initializer.js +1 -1
- package/dist/esm/src/lib/personalization/callflow-edge-proxy-client.d.ts +22 -22
- package/dist/esm/src/lib/personalization/callflow-edge-proxy-client.js +6 -6
- package/dist/esm/src/lib/personalization/personalize.d.ts +3 -3
- package/dist/esm/src/lib/personalization/personalizeServer.d.ts +4 -4
- package/dist/esm/src/lib/personalization/personalizer.d.ts +15 -15
- package/dist/esm/src/lib/personalization/personalizer.js +8 -8
- package/dist/esm/src/server.d.ts +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/src/lib/utils/appendScriptWithAttributes.d.ts +0 -6
- package/dist/cjs/src/lib/utils/appendScriptWithAttributes.js +0 -12
- package/dist/esm/src/lib/utils/appendScriptWithAttributes.d.ts +0 -6
- package/dist/esm/src/lib/utils/appendScriptWithAttributes.js +0 -8
package/README.md
CHANGED
|
@@ -6,10 +6,9 @@ This package provides browser- and server-side functions to run personalization
|
|
|
6
6
|
|
|
7
7
|
## Prerequisites
|
|
8
8
|
|
|
9
|
-
To use the Sitecore Cloud SDK, you need
|
|
9
|
+
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.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
- An XM Cloud Plus subscription.
|
|
11
|
+
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.
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
15
14
|
|
|
@@ -24,12 +23,20 @@ npm install @sitecore-cloudsdk/personalize
|
|
|
24
23
|
|
|
25
24
|
## Code examples
|
|
26
25
|
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
**NOTE**
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
27
34
|
Run personalization from the browser side:
|
|
28
35
|
|
|
29
36
|
```ts
|
|
30
|
-
|
|
31
|
-
import { useEffect } from
|
|
32
|
-
import { init, personalize } from
|
|
37
|
+
'use client';
|
|
38
|
+
import { useEffect } from 'react';
|
|
39
|
+
import { init, personalize } from '@sitecore-cloudsdk/personalize/browser';
|
|
33
40
|
|
|
34
41
|
export default function Home() {
|
|
35
42
|
useEffect(() => {
|
|
@@ -38,8 +45,8 @@ export default function Home() {
|
|
|
38
45
|
|
|
39
46
|
const initPersonalize = async () => {
|
|
40
47
|
await init({
|
|
41
|
-
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID ||
|
|
42
|
-
siteName: process.env.NEXT_PUBLIC_SITENAME ||
|
|
48
|
+
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
|
|
49
|
+
siteName: process.env.NEXT_PUBLIC_SITENAME || '',
|
|
43
50
|
enableBrowserCookie: true,
|
|
44
51
|
});
|
|
45
52
|
|
|
@@ -48,15 +55,15 @@ export default function Home() {
|
|
|
48
55
|
|
|
49
56
|
const runPersonalization = async () => {
|
|
50
57
|
const personalizationData = {
|
|
51
|
-
channel:
|
|
52
|
-
currency:
|
|
53
|
-
friendlyId:
|
|
54
|
-
language:
|
|
58
|
+
channel: 'WEB',
|
|
59
|
+
currency: 'USD',
|
|
60
|
+
friendlyId: 'personalize_test',
|
|
61
|
+
language: 'EN',
|
|
55
62
|
};
|
|
56
63
|
|
|
57
64
|
await personalize(personalizationData);
|
|
58
65
|
|
|
59
|
-
console.log(
|
|
66
|
+
console.log('Ran personalization.');
|
|
60
67
|
};
|
|
61
68
|
|
|
62
69
|
return (
|
|
@@ -70,17 +77,17 @@ export default function Home() {
|
|
|
70
77
|
Run personalization from the server side:
|
|
71
78
|
|
|
72
79
|
```ts
|
|
73
|
-
import { NextResponse } from
|
|
74
|
-
import type { NextRequest } from
|
|
75
|
-
import { init, personalize } from
|
|
80
|
+
import { NextResponse } from 'next/server';
|
|
81
|
+
import type { NextRequest } from 'next/server';
|
|
82
|
+
import { init, personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
76
83
|
|
|
77
84
|
export async function middleware(req: NextRequest) {
|
|
78
85
|
const res = NextResponse.next();
|
|
79
86
|
|
|
80
87
|
await init(
|
|
81
88
|
{
|
|
82
|
-
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID ||
|
|
83
|
-
siteName: process.env.NEXT_PUBLIC_SITENAME ||
|
|
89
|
+
sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
|
|
90
|
+
siteName: process.env.NEXT_PUBLIC_SITENAME || '',
|
|
84
91
|
enableServerCookie: true,
|
|
85
92
|
},
|
|
86
93
|
req,
|
|
@@ -90,15 +97,15 @@ export async function middleware(req: NextRequest) {
|
|
|
90
97
|
console.log(`Initialized "@sitecore-cloudsdk/personalize/server".`);
|
|
91
98
|
|
|
92
99
|
const personalizationData = {
|
|
93
|
-
channel:
|
|
94
|
-
currency:
|
|
95
|
-
friendlyId:
|
|
96
|
-
language:
|
|
100
|
+
channel: 'WEB',
|
|
101
|
+
currency: 'EUR',
|
|
102
|
+
friendlyId: 'personalize_test',
|
|
103
|
+
language: 'EN',
|
|
97
104
|
};
|
|
98
105
|
|
|
99
106
|
const personalizeRes = await personalize(personalizationData, req);
|
|
100
107
|
|
|
101
|
-
console.log(
|
|
108
|
+
console.log('personalizeResponse:', personalizeRes);
|
|
102
109
|
|
|
103
110
|
return res;
|
|
104
111
|
}
|
|
@@ -106,8 +113,8 @@ export async function middleware(req: NextRequest) {
|
|
|
106
113
|
|
|
107
114
|
## Documentation
|
|
108
115
|
|
|
109
|
-
|
|
116
|
+
[Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html)
|
|
110
117
|
|
|
111
118
|
### License
|
|
112
119
|
|
|
113
|
-
The Sitecore Cloud SDK uses the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
|
|
120
|
+
The Sitecore Cloud SDK uses the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { init } from './lib/initializer/client/initializer';
|
|
2
2
|
export { personalize } from './lib/personalization/personalize';
|
|
3
3
|
export { LIBRARY_VERSION } from './lib/consts';
|
|
4
|
-
export type {
|
|
4
|
+
export type { PersonalizerInput } from './lib/personalization/personalizer';
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Settings, SettingsParamsBrowser } from '@sitecore-cloudsdk/core';
|
|
2
2
|
import { CallFlowEdgeProxyClient } from '../../personalization/callflow-edge-proxy-client';
|
|
3
3
|
/**
|
|
4
4
|
* Sets the personalize settings to be used by the application.
|
|
5
5
|
*
|
|
6
6
|
* @param settings - The personalize settings to be set, or `null` to clear the settings.
|
|
7
7
|
*/
|
|
8
|
-
export declare function setDependencies(settings:
|
|
8
|
+
export declare function setDependencies(settings: BrowserPersonalizeSettings | null): void;
|
|
9
9
|
/**
|
|
10
10
|
* Retrieves the browser personalize settings object.
|
|
11
11
|
*
|
|
12
|
-
* This function ensures that the browser personalize settings have been initialized and contain essential properties like `settings` and `
|
|
12
|
+
* This function ensures that the browser personalize settings have been initialized and contain essential properties like `settings` and `callFlowEPClient`.
|
|
13
13
|
*
|
|
14
14
|
* @returns The browser personalize settings object.
|
|
15
15
|
* @throws Error if the personalize settings haven't been initialized with the required properties.
|
|
16
16
|
*/
|
|
17
|
-
export declare function getDependencies():
|
|
17
|
+
export declare function getDependencies(): BrowserPersonalizeSettings;
|
|
18
18
|
/**
|
|
19
19
|
* Initiates the Engage library using the global settings added by the developer
|
|
20
20
|
* @param settingsInput - Global settings added by the developer
|
|
21
21
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
22
22
|
*/
|
|
23
|
-
export declare function init(settingsInput:
|
|
24
|
-
export
|
|
25
|
-
webPersonalization?: boolean | IWebPersonalizationConfig;
|
|
26
|
-
} & ISettingsParamsBrowser;
|
|
27
|
-
export interface IBrowserPersonalizeSettings {
|
|
23
|
+
export declare function init(settingsInput: SettingsParamsBrowser): Promise<void>;
|
|
24
|
+
export interface BrowserPersonalizeSettings {
|
|
28
25
|
id: string;
|
|
29
|
-
settings:
|
|
26
|
+
settings: Settings;
|
|
30
27
|
callFlowEdgeProxyClient: CallFlowEdgeProxyClient;
|
|
31
28
|
}
|
|
@@ -18,14 +18,14 @@ exports.setDependencies = setDependencies;
|
|
|
18
18
|
/**
|
|
19
19
|
* Retrieves the browser personalize settings object.
|
|
20
20
|
*
|
|
21
|
-
* This function ensures that the browser personalize settings have been initialized and contain essential properties like `settings` and `
|
|
21
|
+
* This function ensures that the browser personalize settings have been initialized and contain essential properties like `settings` and `callFlowEPClient`.
|
|
22
22
|
*
|
|
23
23
|
* @returns The browser personalize settings object.
|
|
24
24
|
* @throws Error if the personalize settings haven't been initialized with the required properties.
|
|
25
25
|
*/
|
|
26
26
|
function getDependencies() {
|
|
27
27
|
if (!dependencies) {
|
|
28
|
-
throw Error(`[IE-
|
|
28
|
+
throw Error(`[IE-0006] You must first initialize the "personalize/browser" module. Run the "init" function.`);
|
|
29
29
|
}
|
|
30
30
|
return dependencies;
|
|
31
31
|
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { SettingsParamsServer } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import { BrowserPersonalizeSettings } from '../client/initializer';
|
|
3
|
+
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
/**
|
|
5
5
|
* Sets the personalize settings to be used by the application.
|
|
6
6
|
*
|
|
7
7
|
* @param settings - The personalize settings to be set, or `null` to clear the settings.
|
|
8
8
|
*/
|
|
9
|
-
export declare function setDependencies(settings:
|
|
9
|
+
export declare function setDependencies(settings: ServerPersonalize | null): void;
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves the personalize server settings used by the application.
|
|
12
12
|
*
|
|
13
13
|
* @returns The personalize server settings.
|
|
14
14
|
* @throws Error if the personalize server settings haven't been initialized.
|
|
15
15
|
*/
|
|
16
|
-
export declare function getServerDependencies():
|
|
16
|
+
export declare function getServerDependencies(): ServerPersonalize;
|
|
17
17
|
/**
|
|
18
18
|
* Initiates the server Engage library using the global settings added by the developer
|
|
19
19
|
* @param settings - Global settings added by the developer
|
|
20
20
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
21
21
|
*/
|
|
22
|
-
export declare function initServer<
|
|
23
|
-
export type
|
|
22
|
+
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
|
|
23
|
+
export type ServerPersonalize = Omit<BrowserPersonalizeSettings, 'id'>;
|
|
@@ -22,7 +22,7 @@ exports.setDependencies = setDependencies;
|
|
|
22
22
|
*/
|
|
23
23
|
function getServerDependencies() {
|
|
24
24
|
if (!serverDependencies) {
|
|
25
|
-
throw Error(`[IE-
|
|
25
|
+
throw Error(`[IE-0007] You must first initialize the "personalize/server" module. Run the "init" function.`);
|
|
26
26
|
}
|
|
27
27
|
return serverDependencies;
|
|
28
28
|
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare class CallFlowEdgeProxyClient implements
|
|
4
|
-
settings:
|
|
1
|
+
import { Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import { NestedObject } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
export declare class CallFlowEdgeProxyClient implements PersonalizeClient {
|
|
4
|
+
settings: Settings;
|
|
5
5
|
/**
|
|
6
6
|
* A helper class which handles the functionality for sending CALLFLOW requests
|
|
7
|
-
* @param personalizeData - The mandatory payload to be send to Sitecore
|
|
7
|
+
* @param personalizeData - The mandatory payload to be send to Sitecore EP
|
|
8
8
|
* @param settings - The global settings
|
|
9
9
|
*/
|
|
10
|
-
constructor(settings:
|
|
10
|
+
constructor(settings: Settings);
|
|
11
11
|
/**
|
|
12
|
-
* A function that sends a CallFlow request to Sitecore
|
|
13
|
-
* @param personalizeData - Properties to be send to Sitecore
|
|
12
|
+
* A function that sends a CallFlow request to Sitecore EP
|
|
13
|
+
* @param personalizeData - Properties to be send to Sitecore EP
|
|
14
14
|
* @param timeout - Optional timeout in milliseconds to cancel the request
|
|
15
|
-
* @returns - A promise that resolves with either the Sitecore
|
|
15
|
+
* @returns - A promise that resolves with either the Sitecore EP response object or unknown
|
|
16
16
|
*/
|
|
17
|
-
sendCallFlowsRequest(
|
|
17
|
+
sendCallFlowsRequest(epCallFlowsBody: EPCallFlowsBody, timeout?: number): Promise<any>;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* An interface with the basic functionality that the derived classes needs to implement
|
|
21
21
|
*/
|
|
22
|
-
export interface
|
|
23
|
-
settings:
|
|
24
|
-
sendCallFlowsRequest: (
|
|
22
|
+
export interface PersonalizeClient {
|
|
23
|
+
settings: Settings;
|
|
24
|
+
sendCallFlowsRequest: (epCallFlowAttributes: EPCallFlowsBody, timeout?: number) => Promise<unknown | null | FailedCalledFlowsResponse>;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* An interface that describes the failed response model from Sitecore
|
|
27
|
+
* An interface that describes the failed response model from Sitecore EP
|
|
28
28
|
*/
|
|
29
|
-
export interface
|
|
29
|
+
export interface FailedCalledFlowsResponse {
|
|
30
30
|
status: string;
|
|
31
31
|
code: string;
|
|
32
32
|
message: string;
|
|
@@ -36,26 +36,26 @@ export interface IFailedCalledFlowsResponse {
|
|
|
36
36
|
/**
|
|
37
37
|
* An interface that describes the identifier model attributes for the library
|
|
38
38
|
*/
|
|
39
|
-
export interface
|
|
39
|
+
export interface EPIdentifier {
|
|
40
40
|
id: string;
|
|
41
41
|
provider: string;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* An interface that describes the payload sent to Sitecore
|
|
44
|
+
* An interface that describes the payload sent to Sitecore EP library
|
|
45
45
|
*/
|
|
46
|
-
export interface
|
|
46
|
+
export interface EPCallFlowsBody {
|
|
47
47
|
browserId?: string;
|
|
48
48
|
email?: string;
|
|
49
49
|
friendlyId: string;
|
|
50
|
-
identifiers?:
|
|
50
|
+
identifiers?: EPIdentifier;
|
|
51
51
|
channel: string;
|
|
52
52
|
clientKey: string;
|
|
53
53
|
currencyCode: string;
|
|
54
54
|
language: string | undefined;
|
|
55
|
-
params?:
|
|
55
|
+
params?: EPCallFlowsParams;
|
|
56
56
|
pointOfSale: string;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* A type that describes the params property of the
|
|
59
|
+
* A type that describes the params property of the EPCallFlowsBody
|
|
60
60
|
*/
|
|
61
|
-
export type
|
|
61
|
+
export type EPCallFlowsParams = NestedObject;
|
|
@@ -7,22 +7,22 @@ const consts_1 = require("../consts");
|
|
|
7
7
|
class CallFlowEdgeProxyClient {
|
|
8
8
|
/**
|
|
9
9
|
* A helper class which handles the functionality for sending CALLFLOW requests
|
|
10
|
-
* @param personalizeData - The mandatory payload to be send to Sitecore
|
|
10
|
+
* @param personalizeData - The mandatory payload to be send to Sitecore EP
|
|
11
11
|
* @param settings - The global settings
|
|
12
12
|
*/
|
|
13
13
|
constructor(settings) {
|
|
14
14
|
this.settings = settings;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* A function that sends a CallFlow request to Sitecore
|
|
18
|
-
* @param personalizeData - Properties to be send to Sitecore
|
|
17
|
+
* A function that sends a CallFlow request to Sitecore EP
|
|
18
|
+
* @param personalizeData - Properties to be send to Sitecore EP
|
|
19
19
|
* @param timeout - Optional timeout in milliseconds to cancel the request
|
|
20
|
-
* @returns - A promise that resolves with either the Sitecore
|
|
20
|
+
* @returns - A promise that resolves with either the Sitecore EP response object or unknown
|
|
21
21
|
*/
|
|
22
|
-
async sendCallFlowsRequest(
|
|
22
|
+
async sendCallFlowsRequest(epCallFlowsBody, timeout) {
|
|
23
23
|
const requestUrl = `${this.settings.sitecoreEdgeUrl}/personalize/v2/callFlows?sitecoreContextId=${this.settings.sitecoreEdgeContextId}&siteId=${this.settings.siteName}`;
|
|
24
24
|
const fetchOptions = {
|
|
25
|
-
body: JSON.stringify(
|
|
25
|
+
body: JSON.stringify(epCallFlowsBody),
|
|
26
26
|
headers: {
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
28
|
'Content-Type': 'application/json',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FailedCalledFlowsResponse } from './callflow-edge-proxy-client';
|
|
2
|
+
import { PersonalizerInput } from './personalizer';
|
|
3
3
|
/**
|
|
4
4
|
* A function that executes an interactive experiment or web experiment over any web-based or mobile application.
|
|
5
5
|
* @param personalizeData - The required/optional attributes in order to create a flow execution
|
|
@@ -7,4 +7,4 @@ import { IPersonalizerInput } from './personalizer';
|
|
|
7
7
|
* Used to abort the request to execute an interactive experiment or web experiment.
|
|
8
8
|
* @returns A flow execution response
|
|
9
9
|
*/
|
|
10
|
-
export declare function personalize(personalizeData:
|
|
10
|
+
export declare function personalize(personalizeData: PersonalizerInput, timeout?: number): Promise<unknown | null | FailedCalledFlowsResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { FailedCalledFlowsResponse } from './callflow-edge-proxy-client';
|
|
2
|
+
import { Request } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import { PersonalizerInput } from './personalizer';
|
|
4
4
|
/**
|
|
5
5
|
* A function that executes an interactive experiment or web experiment over any web-based or mobile application.
|
|
6
6
|
* @param personalizeData - The required/optional attributes in order to create a flow execution
|
|
@@ -9,4 +9,4 @@ import { IPersonalizerInput } from './personalizer';
|
|
|
9
9
|
* Used to abort the request to execute an interactive experiment or web experiment.
|
|
10
10
|
* @returns A flow execution response
|
|
11
11
|
*/
|
|
12
|
-
export declare function personalizeServer<T extends
|
|
12
|
+
export declare function personalizeServer<T extends Request>(personalizeData: PersonalizerInput, request: T, timeout?: number): Promise<unknown | null | FailedCalledFlowsResponse>;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FailedCalledFlowsResponse, PersonalizeClient } from './callflow-edge-proxy-client';
|
|
2
|
+
import { NestedObject } from '@sitecore-cloudsdk/utils';
|
|
3
3
|
export declare class Personalizer {
|
|
4
4
|
private personalizeClient;
|
|
5
5
|
private id;
|
|
6
6
|
/**
|
|
7
7
|
* The Personalizer Class runs a flow of interactive experiments.
|
|
8
|
-
* @param personalizeClient - The data to be send to Sitecore
|
|
8
|
+
* @param personalizeClient - The data to be send to Sitecore EP
|
|
9
9
|
* @param infer - The source of methods to estimate language and page parameters
|
|
10
10
|
*/
|
|
11
|
-
constructor(personalizeClient:
|
|
11
|
+
constructor(personalizeClient: PersonalizeClient, id: string);
|
|
12
12
|
/**
|
|
13
|
-
* A function to make a request to the Sitecore
|
|
13
|
+
* A function to make a request to the Sitecore EP /callFlows API endpoint
|
|
14
14
|
* @param timeout - Optional timeout in milliseconds to cancel the request
|
|
15
|
-
* @returns - A promise that resolves with either the Sitecore
|
|
15
|
+
* @returns - A promise that resolves with either the Sitecore EP response object or null
|
|
16
16
|
*/
|
|
17
|
-
getInteractiveExperienceData(personalizeInput:
|
|
17
|
+
getInteractiveExperienceData(personalizeInput: PersonalizerInput, timeout?: number): Promise<unknown | null | FailedCalledFlowsResponse>;
|
|
18
18
|
/**
|
|
19
19
|
* A function that sanitizes the personalize input data
|
|
20
20
|
* @returns - The sanitized object
|
|
21
21
|
*/
|
|
22
22
|
private sanitizeInput;
|
|
23
23
|
/**
|
|
24
|
-
* A function that maps the personalize input data with the
|
|
25
|
-
* @returns - The
|
|
24
|
+
* A function that maps the personalize input data with the EP
|
|
25
|
+
* @returns - The EP object
|
|
26
26
|
*/
|
|
27
|
-
private
|
|
27
|
+
private mapPersonalizeInputToEPData;
|
|
28
28
|
/**
|
|
29
29
|
* A validation method to throw error for the mandatory property for runtime users
|
|
30
30
|
*/
|
|
@@ -33,23 +33,23 @@ export declare class Personalizer {
|
|
|
33
33
|
/**
|
|
34
34
|
* An interface that describes the flow execution model attributes input for the library
|
|
35
35
|
*/
|
|
36
|
-
export interface
|
|
36
|
+
export interface PersonalizerInput {
|
|
37
37
|
channel: string;
|
|
38
38
|
currency: string;
|
|
39
39
|
email?: string;
|
|
40
40
|
friendlyId: string;
|
|
41
|
-
identifier?:
|
|
41
|
+
identifier?: PersonalizeIdentifierInput;
|
|
42
42
|
language?: string;
|
|
43
|
-
params?:
|
|
43
|
+
params?: PersonalizeInputParams;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* An interface that describes the identifier model attributes for the library
|
|
47
47
|
*/
|
|
48
|
-
export interface
|
|
48
|
+
export interface PersonalizeIdentifierInput {
|
|
49
49
|
id: string;
|
|
50
50
|
provider: string;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* A type that describes the params field
|
|
54
54
|
*/
|
|
55
|
-
export type
|
|
55
|
+
export type PersonalizeInputParams = NestedObject;
|
|
@@ -7,7 +7,7 @@ const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
|
7
7
|
class Personalizer {
|
|
8
8
|
/**
|
|
9
9
|
* The Personalizer Class runs a flow of interactive experiments.
|
|
10
|
-
* @param personalizeClient - The data to be send to Sitecore
|
|
10
|
+
* @param personalizeClient - The data to be send to Sitecore EP
|
|
11
11
|
* @param infer - The source of methods to estimate language and page parameters
|
|
12
12
|
*/
|
|
13
13
|
constructor(personalizeClient, id) {
|
|
@@ -15,14 +15,14 @@ class Personalizer {
|
|
|
15
15
|
this.id = id;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* A function to make a request to the Sitecore
|
|
18
|
+
* A function to make a request to the Sitecore EP /callFlows API endpoint
|
|
19
19
|
* @param timeout - Optional timeout in milliseconds to cancel the request
|
|
20
|
-
* @returns - A promise that resolves with either the Sitecore
|
|
20
|
+
* @returns - A promise that resolves with either the Sitecore EP response object or null
|
|
21
21
|
*/
|
|
22
22
|
async getInteractiveExperienceData(personalizeInput, timeout) {
|
|
23
23
|
this.validate(personalizeInput);
|
|
24
24
|
const sanitizedInput = this.sanitizeInput(personalizeInput);
|
|
25
|
-
const mappedData = this.
|
|
25
|
+
const mappedData = this.mapPersonalizeInputToEPData(sanitizedInput);
|
|
26
26
|
if (!mappedData.email && !mappedData.identifiers)
|
|
27
27
|
mappedData.browserId = this.id;
|
|
28
28
|
const response = await this.personalizeClient.sendCallFlowsRequest(mappedData, timeout);
|
|
@@ -50,10 +50,10 @@ class Personalizer {
|
|
|
50
50
|
return sanitizedInput;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* A function that maps the personalize input data with the
|
|
54
|
-
* @returns - The
|
|
53
|
+
* A function that maps the personalize input data with the EP
|
|
54
|
+
* @returns - The EP object
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
mapPersonalizeInputToEPData(input) {
|
|
57
57
|
const mappedData = {
|
|
58
58
|
channel: input.channel,
|
|
59
59
|
clientKey: '',
|
|
@@ -72,7 +72,7 @@ class Personalizer {
|
|
|
72
72
|
*/
|
|
73
73
|
validate({ friendlyId }) {
|
|
74
74
|
if (!friendlyId || friendlyId.trim().length === 0)
|
|
75
|
-
throw new Error(`[MV-
|
|
75
|
+
throw new Error(`[MV-0004] "friendlyId" is required.`);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
exports.Personalizer = Personalizer;
|
package/dist/cjs/src/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { initServer as init } from './lib/initializer/server/initializer';
|
|
2
2
|
export { personalizeServer as personalize } from './lib/personalization/personalizeServer';
|
|
3
3
|
export { LIBRARY_VERSION } from './lib/consts';
|
|
4
|
-
export type {
|
|
4
|
+
export type { PersonalizerInput } from './lib/personalization/personalizer';
|