@sitecore-cloudsdk/personalize 0.2.4 → 0.3.1-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.
Files changed (36) hide show
  1. package/README.md +8 -18
  2. package/dist/cjs/package.json +5 -6
  3. package/dist/cjs/src/browser.d.ts +1 -1
  4. package/dist/cjs/src/lib/consts.js +1 -0
  5. package/dist/cjs/src/lib/initializer/client/initializer.d.ts +3 -3
  6. package/dist/cjs/src/lib/initializer/client/initializer.js +6 -6
  7. package/dist/cjs/src/lib/initializer/server/initializer.d.ts +5 -3
  8. package/dist/cjs/src/lib/initializer/server/initializer.js +4 -2
  9. package/dist/cjs/src/lib/personalization/personalize.d.ts +6 -5
  10. package/dist/cjs/src/lib/personalization/personalize.js +8 -6
  11. package/dist/cjs/src/lib/personalization/personalizeServer.d.ts +8 -6
  12. package/dist/cjs/src/lib/personalization/personalizeServer.js +10 -10
  13. package/dist/cjs/src/lib/personalization/personalizer.d.ts +12 -9
  14. package/dist/cjs/src/lib/personalization/personalizer.js +31 -35
  15. package/dist/cjs/src/lib/personalization/send-call-flows-request.d.ts +4 -2
  16. package/dist/cjs/src/lib/personalization/send-call-flows-request.js +22 -8
  17. package/dist/cjs/src/server.d.ts +1 -1
  18. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  19. package/dist/esm/package.json +5 -6
  20. package/dist/esm/src/browser.d.ts +1 -1
  21. package/dist/esm/src/lib/consts.js +1 -0
  22. package/dist/esm/src/lib/initializer/client/initializer.d.ts +3 -3
  23. package/dist/esm/src/lib/initializer/client/initializer.js +6 -6
  24. package/dist/esm/src/lib/initializer/server/initializer.d.ts +5 -3
  25. package/dist/esm/src/lib/initializer/server/initializer.js +5 -3
  26. package/dist/esm/src/lib/personalization/personalize.d.ts +6 -5
  27. package/dist/esm/src/lib/personalization/personalize.js +8 -6
  28. package/dist/esm/src/lib/personalization/personalizeServer.d.ts +8 -6
  29. package/dist/esm/src/lib/personalization/personalizeServer.js +11 -11
  30. package/dist/esm/src/lib/personalization/personalizer.d.ts +12 -9
  31. package/dist/esm/src/lib/personalization/personalizer.js +32 -36
  32. package/dist/esm/src/lib/personalization/send-call-flows-request.d.ts +4 -2
  33. package/dist/esm/src/lib/personalization/send-call-flows-request.js +23 -9
  34. package/dist/esm/src/server.d.ts +1 -1
  35. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +5 -6
package/README.md CHANGED
@@ -53,10 +53,7 @@ export default function Home() {
53
53
 
54
54
  const runPersonalization = async () => {
55
55
  const personalizationData = {
56
- channel: 'WEB',
57
- currency: 'USD',
58
56
  friendlyId: 'personalize_test',
59
- language: 'EN',
60
57
  };
61
58
 
62
59
  await personalize(personalizationData);
@@ -82,28 +79,21 @@ import { init, personalize } from '@sitecore-cloudsdk/personalize/server';
82
79
  export async function middleware(req: NextRequest) {
83
80
  const res = NextResponse.next();
84
81
 
85
- await init(
86
- {
87
- sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
88
- siteName: process.env.NEXT_PUBLIC_SITENAME || '',
89
- enableServerCookie: true,
90
- },
91
- req,
92
- res
93
- );
82
+ await init(req, res, {
83
+ sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
84
+ siteName: process.env.NEXT_PUBLIC_SITENAME || '',
85
+ enableServerCookie: true,
86
+ });
94
87
 
95
88
  console.log(`Initialized "@sitecore-cloudsdk/personalize/server".`);
96
89
 
97
90
  const personalizationData = {
98
- channel: 'WEB',
99
- currency: 'EUR',
100
91
  friendlyId: 'personalize_test',
101
- language: 'EN',
102
92
  };
103
93
 
104
- const personalizeRes = await personalize(personalizationData, req);
94
+ await personalize(req, personalizationData);
105
95
 
106
- console.log('personalizeResponse:', personalizeRes);
96
+ console.log('Ran personalization.');
107
97
 
108
98
  return res;
109
99
  }
@@ -111,4 +101,4 @@ export async function middleware(req: NextRequest) {
111
101
 
112
102
  ## Documentation
113
103
 
114
- [Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html)
104
+ [Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html)
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@sitecore-cloudsdk/personalize",
3
- "version": "0.2.4",
3
+ "version": "0.3.1-rc.0",
4
4
  "license": "Apache-2.0",
5
- "homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html",
5
+ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
6
6
  "exports": {
7
7
  "./server": {
8
8
  "import": "./server.js",
@@ -16,8 +16,8 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@sitecore-cloudsdk/core": "^0.2.4",
20
- "@sitecore-cloudsdk/utils": "^0.2.4"
19
+ "@sitecore-cloudsdk/core": "^0.3.1-rc.0",
20
+ "@sitecore-cloudsdk/utils": "^0.3.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "npm run build:cjs && npm run build:es",
@@ -35,7 +35,6 @@
35
35
  "server.d.ts"
36
36
  ],
37
37
  "engines": {
38
- "node": ">=18",
39
- "npm": ">=9"
38
+ "node": ">=18"
40
39
  }
41
40
  }
@@ -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, PERSONALIZE_NAMESPACE } from './lib/consts';
4
- export type { PersonalizerInput } from './lib/personalization/personalizer';
4
+ export type { PersonalizeData } from './lib/personalization/personalizer';
@@ -13,6 +13,7 @@ const package_json_1 = __importDefault(require("../../package.json"));
13
13
  exports.LIBRARY_VERSION = package_json_1.default.version;
14
14
  var ErrorMessages;
15
15
  (function (ErrorMessages) {
16
+ // eslint-disable-next-line max-len
16
17
  ErrorMessages["IE_0001"] = "[IE-0001] The \"window\" object is not available on the server side. Use the \"window\" object only on the client side, and in the correct execution context.";
17
18
  ErrorMessages["IE_0006"] = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function.";
18
19
  ErrorMessages["IE_0007"] = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function.";
@@ -1,11 +1,11 @@
1
- import { SettingsParamsBrowser } from '@sitecore-cloudsdk/core';
1
+ import type { BrowserSettings } from '@sitecore-cloudsdk/core';
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
- * @param settingsInput - Global settings added by the developer
5
+ * @param settings - Global settings added by the developer
6
6
  * @returns A promise that resolves with an object that handles the library functionality
7
7
  */
8
- export declare function init(settingsInput: SettingsParamsBrowser): Promise<void>;
8
+ export declare function init(settings: BrowserSettings): Promise<void>;
9
9
  /**
10
10
  * A function that handles the async browser init logic. Throws an error or awaits the promise.
11
11
  */
@@ -2,19 +2,19 @@
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 core_1 = require("@sitecore-cloudsdk/core");
6
5
  const consts_1 = require("../../consts");
6
+ const core_1 = require("@sitecore-cloudsdk/core");
7
7
  exports.initPromise = null;
8
8
  /**
9
9
  * Initiates the Engage library using the global settings added by the developer
10
- * @param settingsInput - Global settings added by the developer
10
+ * @param settings - Global settings added by the developer
11
11
  * @returns A promise that resolves with an object that handles the library functionality
12
12
  */
13
- async function init(settingsInput) {
13
+ async function init(settings) {
14
14
  if (typeof window === 'undefined')
15
15
  throw new Error(consts_1.ErrorMessages.IE_0001);
16
16
  try {
17
- exports.initPromise = (0, core_1.initCore)(settingsInput);
17
+ exports.initPromise = (0, core_1.initCore)(settings);
18
18
  await exports.initPromise;
19
19
  (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('personalizeClient library initialized');
20
20
  }
@@ -29,8 +29,8 @@ async function init(settingsInput) {
29
29
  getBrowserId: () => (0, core_1.getBrowserId)(),
30
30
  versions: {
31
31
  ...window.Engage.versions,
32
- personalize: consts_1.LIBRARY_VERSION,
33
- },
32
+ personalize: consts_1.LIBRARY_VERSION
33
+ }
34
34
  };
35
35
  }
36
36
  exports.init = init;
@@ -1,8 +1,10 @@
1
- import { SettingsParamsServer } from '@sitecore-cloudsdk/core';
2
- import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
1
+ import type { Request, Response } from '@sitecore-cloudsdk/utils';
2
+ import type { ServerSettings } from '@sitecore-cloudsdk/core';
3
3
  /**
4
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
5
7
  * @param settings - Global settings added by the developer
6
8
  * @returns A promise that resolves with an object that handles the library functionality
7
9
  */
8
- export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
10
+ export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
@@ -6,12 +6,14 @@ const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const consts_1 = require("../../consts");
7
7
  /**
8
8
  * Initiates the server Engage library using the global settings added by the developer
9
+ * @param request - The request object, either a Middleware Request or an HTTP Request
10
+ * @param response - The response object, either a Middleware Next Response or an HTTP Response
9
11
  * @param settings - Global settings added by the developer
10
12
  * @returns A promise that resolves with an object that handles the library functionality
11
13
  */
12
- async function initServer(settingsInput, request, response) {
14
+ async function initServer(request, response, settings) {
13
15
  try {
14
- await (0, core_1.initCoreServer)(settingsInput, request, response);
16
+ await (0, core_1.initCoreServer)(settings, request, response);
15
17
  (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('personalizeServer library initialized');
16
18
  }
17
19
  catch (error) {
@@ -1,10 +1,11 @@
1
- import { FailedCalledFlowsResponse } from './send-call-flows-request';
2
- import { PersonalizerInput } from './personalizer';
1
+ import type { FailedCalledFlowsResponse } from './send-call-flows-request';
2
+ import type { PersonalizeData } 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
6
- * @param timeout - Optional timeout in milliseconds.
7
- * Used to abort the request to execute an interactive experiment or web experiment.
6
+ * @param opts - An object containing additional options.
8
7
  * @returns A flow execution response
9
8
  */
10
- export declare function personalize(personalizeData: PersonalizerInput, timeout?: number): Promise<unknown | null | FailedCalledFlowsResponse>;
9
+ export declare function personalize(personalizeData: PersonalizeData, opts?: {
10
+ timeout?: number;
11
+ }): Promise<unknown | null | FailedCalledFlowsResponse>;
@@ -1,23 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.personalize = void 0;
4
+ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
4
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
+ const consts_1 = require("../consts");
5
7
  const personalizer_1 = require("./personalizer");
6
8
  const initializer_1 = require("../initializer/client/initializer");
7
- const consts_1 = require("../consts");
9
+ const utils_1 = require("@sitecore-cloudsdk/utils");
8
10
  /**
9
11
  * A function that executes an interactive experiment or web experiment over any web-based or mobile application.
10
12
  * @param personalizeData - The required/optional attributes in order to create a flow execution
11
- * @param timeout - Optional timeout in milliseconds.
12
- * Used to abort the request to execute an interactive experiment or web experiment.
13
+ * @param opts - An object containing additional options.
13
14
  * @returns A flow execution response
14
15
  */
15
- async function personalize(personalizeData, timeout) {
16
+ async function personalize(personalizeData, opts) {
16
17
  await (0, initializer_1.awaitInit)();
17
18
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0006);
18
19
  const id = (0, core_1.getBrowserId)();
19
- return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, window.location.search, {
20
- timeout,
20
+ const guestId = (0, utils_1.getCookieValueClientSide)(settings.cookieSettings.cookieNames.guestId);
21
+ return new personalizer_1.Personalizer(id, guestId).getInteractiveExperienceData(personalizeData, settings, window.location.search, {
22
+ timeout: opts?.timeout
21
23
  });
22
24
  }
23
25
  exports.personalize = personalize;
@@ -1,12 +1,14 @@
1
- import { FailedCalledFlowsResponse } from './send-call-flows-request';
2
- import { Request } from '@sitecore-cloudsdk/utils';
3
- import { PersonalizerInput } from './personalizer';
1
+ import type { PersonalizeData } from './personalizer';
2
+ import type { FailedCalledFlowsResponse } from './send-call-flows-request';
3
+ import type { Request } from '@sitecore-cloudsdk/utils';
4
4
  /**
5
5
  * A function that executes an interactive experiment or web experiment over any web-based or mobile application.
6
+ * @param request - The request object, either a Middleware Request or an HTTP Request
6
7
  * @param personalizeData - The required/optional attributes in order to create a flow execution
7
- * @param request - Interface with constraint for extending request
8
- * @param timeout - Optional timeout in milliseconds.
8
+ * @param opts - An optional object containing additional options such as timeout.
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 Request>(personalizeData: PersonalizerInput, request: T, timeout?: number): Promise<unknown | null | FailedCalledFlowsResponse>;
12
+ export declare function personalizeServer<T extends Request>(request: T, personalizeData: PersonalizeData, opts?: {
13
+ timeout?: number;
14
+ }): Promise<unknown | null | FailedCalledFlowsResponse>;
@@ -1,31 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.personalizeServer = void 0;
4
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
5
4
  const core_1 = require("@sitecore-cloudsdk/core");
6
- const utils_1 = require("@sitecore-cloudsdk/utils");
7
- const personalizer_1 = require("./personalizer");
8
5
  const consts_1 = require("../consts");
6
+ const personalizer_1 = require("./personalizer");
7
+ const utils_1 = require("@sitecore-cloudsdk/utils");
9
8
  /**
10
9
  * A function that executes an interactive experiment or web experiment over any web-based or mobile application.
10
+ * @param request - The request object, either a Middleware Request or an HTTP Request
11
11
  * @param personalizeData - The required/optional attributes in order to create a flow execution
12
- * @param request - Interface with constraint for extending request
13
- * @param timeout - Optional timeout in milliseconds.
12
+ * @param opts - An optional object containing additional options such as timeout.
14
13
  * Used to abort the request to execute an interactive experiment or web experiment.
15
14
  * @returns A flow execution response
16
15
  */
17
- function personalizeServer(personalizeData, request, timeout) {
16
+ function personalizeServer(request, personalizeData, opts) {
18
17
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0007);
19
- const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
18
+ const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
19
+ const guestId = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.guestId);
20
20
  const requestUrl = new URL(request.url, `https://localhost`);
21
21
  const userAgent = (0, utils_1.isNextJsMiddlewareRequest)(request)
22
22
  ? request.headers.get('user-agent')
23
23
  : request.headers['user-agent'];
24
24
  if (!personalizeData.geo && (0, utils_1.isNextJsMiddlewareRequest)(request) && request.geo && Object.keys(request.geo).length)
25
25
  personalizeData.geo = request.geo;
26
- return new personalizer_1.Personalizer(id).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, {
27
- timeout,
28
- userAgent,
26
+ return new personalizer_1.Personalizer(id, guestId).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, {
27
+ timeout: opts?.timeout,
28
+ userAgent
29
29
  });
30
30
  }
31
31
  exports.personalizeServer = personalizeServer;
@@ -1,21 +1,23 @@
1
- import { Settings } from '@sitecore-cloudsdk/core';
2
- import { FailedCalledFlowsResponse } from './send-call-flows-request';
3
- import { NestedObject } from '@sitecore-cloudsdk/utils';
1
+ import type { FailedCalledFlowsResponse } from './send-call-flows-request';
2
+ import type { NestedObject } from '@sitecore-cloudsdk/utils';
3
+ import type { Settings } from '@sitecore-cloudsdk/core';
4
4
  export declare class Personalizer {
5
- private id;
5
+ private browserId;
6
+ private guestId;
6
7
  /**
7
8
  * The Personalizer Class runs a flow of interactive experiments.
8
- * @param id - The browser id of the user
9
+ * @param browserId - The browser id of the user
10
+ * @param guestId - The guestRef of the user
9
11
  */
10
- constructor(id: string);
12
+ constructor(browserId: string, guestId: string);
11
13
  /**
12
14
  * A function to make a request to the Sitecore EP /callFlows API endpoint
13
- * @param personalizeInput - The personalize input from the developer
15
+ * @param personalizeData - The personalize input from the developer
14
16
  * @param settings - The setting that was set during initialization
15
17
  * @param opts - Optional object that contains options for timeout and UA
16
18
  * @returns - A promise that resolves with either the Sitecore EP response object or null
17
19
  */
18
- getInteractiveExperienceData(personalizeInput: PersonalizerInput, settings: Settings, searchParams: string, opts?: {
20
+ getInteractiveExperienceData(personalizeData: PersonalizeData, settings: Settings, searchParams: string, opts?: {
19
21
  timeout?: number;
20
22
  userAgent?: string | null;
21
23
  }): Promise<unknown | null | FailedCalledFlowsResponse>;
@@ -52,7 +54,7 @@ export interface PersonalizeGeolocation {
52
54
  /**
53
55
  * An interface that describes the flow execution model attributes input for the library
54
56
  */
55
- export interface PersonalizerInput {
57
+ export interface PersonalizeData {
56
58
  channel: string;
57
59
  currency: string;
58
60
  email?: string;
@@ -61,6 +63,7 @@ export interface PersonalizerInput {
61
63
  identifier?: PersonalizeIdentifierInput;
62
64
  language?: string;
63
65
  params?: PersonalizeInputParams;
66
+ pageVariantIds?: string[];
64
67
  }
65
68
  /**
66
69
  * An interface that describes the identifier model attributes for the library
@@ -1,66 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Personalizer = void 0;
4
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
4
+ const consts_1 = require("../consts");
5
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const send_call_flows_request_1 = require("./send-call-flows-request");
7
- const consts_1 = require("../consts");
8
7
  class Personalizer {
9
8
  /**
10
9
  * The Personalizer Class runs a flow of interactive experiments.
11
- * @param id - The browser id of the user
10
+ * @param browserId - The browser id of the user
11
+ * @param guestId - The guestRef of the user
12
12
  */
13
- constructor(id) {
14
- this.id = id;
13
+ constructor(browserId, guestId) {
14
+ this.browserId = browserId;
15
+ this.guestId = guestId;
15
16
  }
16
17
  /**
17
18
  * A function to make a request to the Sitecore EP /callFlows API endpoint
18
- * @param personalizeInput - The personalize input from the developer
19
+ * @param personalizeData - The personalize input from the developer
19
20
  * @param settings - The setting that was set during initialization
20
21
  * @param opts - Optional object that contains options for timeout and UA
21
22
  * @returns - A promise that resolves with either the Sitecore EP response object or null
22
23
  */
23
- async getInteractiveExperienceData(personalizeInput, settings, searchParams, opts) {
24
- this.validate(personalizeInput);
25
- const sanitizedInput = this.sanitizeInput(personalizeInput);
24
+ async getInteractiveExperienceData(personalizeData, settings, searchParams, opts) {
25
+ this.validate(personalizeData);
26
+ const sanitizedInput = this.sanitizeInput(personalizeData);
26
27
  if (searchParams.includes(consts_1.UTM_PREFIX) && !sanitizedInput.params?.utm) {
27
28
  sanitizedInput.params = sanitizedInput.params || {};
28
29
  sanitizedInput.params.utm = this.extractUrlParamsWithPrefix(searchParams, consts_1.UTM_PREFIX);
29
30
  }
30
31
  const mappedData = this.mapPersonalizeInputToEPData(sanitizedInput);
31
32
  if (!mappedData.email && !mappedData.identifiers)
32
- mappedData.browserId = this.id;
33
- return (0, send_call_flows_request_1.sendCallFlowsRequest)(mappedData, settings, opts)
34
- .then((payload) => {
35
- (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Personalize payload: %O', payload);
36
- return payload;
37
- })
38
- .catch((err) => {
39
- throw err;
40
- });
33
+ mappedData.browserId = this.browserId;
34
+ return await (0, send_call_flows_request_1.sendCallFlowsRequest)(mappedData, settings, opts);
41
35
  }
42
36
  /**
43
37
  * A function that sanitizes the personalize input data
44
38
  * @returns - The sanitized object
45
39
  */
46
- sanitizeInput(personalizerInput) {
47
- const sanitizedInput = {
48
- channel: personalizerInput.channel,
49
- currency: personalizerInput.currency,
50
- friendlyId: personalizerInput.friendlyId,
51
- language: personalizerInput.language,
40
+ sanitizeInput(personalizeData) {
41
+ const sanitizedData = {
42
+ channel: personalizeData.channel,
43
+ currency: personalizeData.currency,
44
+ friendlyId: personalizeData.friendlyId,
45
+ language: personalizeData.language
52
46
  };
53
- if (personalizerInput.identifier &&
54
- personalizerInput.identifier.id &&
55
- personalizerInput.identifier.id.trim().length > 0)
56
- sanitizedInput.identifier = personalizerInput.identifier;
57
- if (personalizerInput.email && personalizerInput.email.trim().length > 0)
58
- sanitizedInput.email = personalizerInput.email;
59
- if (personalizerInput.params && Object.keys(personalizerInput.params).length > 0)
60
- sanitizedInput.params = personalizerInput.params;
61
- if (personalizerInput.geo && Object.keys(personalizerInput.geo).length > 0)
62
- sanitizedInput.params = { ...sanitizedInput.params, geo: { ...personalizerInput.geo } };
63
- return sanitizedInput;
47
+ if (personalizeData.identifier && personalizeData.identifier.id && personalizeData.identifier.id.trim().length > 0)
48
+ sanitizedData.identifier = personalizeData.identifier;
49
+ if (personalizeData.email && personalizeData.email.trim().length > 0)
50
+ sanitizedData.email = personalizeData.email;
51
+ if (personalizeData.params && Object.keys(personalizeData.params).length > 0)
52
+ sanitizedData.params = personalizeData.params;
53
+ if (personalizeData.geo && Object.keys(personalizeData.geo).length > 0)
54
+ sanitizedData.params = { ...personalizeData.params, geo: { ...personalizeData.geo } };
55
+ if (personalizeData.pageVariantIds?.length)
56
+ sanitizedData.pageVariantIds = personalizeData.pageVariantIds;
57
+ return sanitizedData;
64
58
  }
65
59
  /**
66
60
  * A function that maps the personalize input data with the EP
@@ -73,10 +67,12 @@ class Personalizer {
73
67
  currencyCode: input.currency,
74
68
  email: input.email,
75
69
  friendlyId: input.friendlyId,
70
+ guestRef: this.guestId,
76
71
  identifiers: input.identifier,
77
72
  language: input.language ?? (0, core_1.language)(),
78
73
  params: input.params,
79
74
  pointOfSale: '',
75
+ variants: input.pageVariantIds
80
76
  };
81
77
  return mappedData;
82
78
  }
@@ -1,5 +1,5 @@
1
- import { Settings } from '@sitecore-cloudsdk/core';
2
- import { NestedObject } from '@sitecore-cloudsdk/utils';
1
+ import type { Settings } from '@sitecore-cloudsdk/core';
2
+ import type { NestedObject } from '@sitecore-cloudsdk/utils';
3
3
  /**
4
4
  * A function that sends a CallFlow request to Sitecore EP
5
5
  * @param personalizeData - Properties to be send to Sitecore EP
@@ -49,6 +49,8 @@ export interface EPCallFlowsBody {
49
49
  language: string | undefined;
50
50
  params?: EPCallFlowsParams;
51
51
  pointOfSale: string;
52
+ guestRef: string;
53
+ variants?: string[];
52
54
  }
53
55
  /**
54
56
  * A type that describes the params property of the EPCallFlowsBody
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendCallFlowsRequest = void 0;
4
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
4
+ const consts_1 = require("../consts");
5
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const utils_1 = require("@sitecore-cloudsdk/utils");
7
- const consts_1 = require("../consts");
8
7
  /**
9
8
  * A function that sends a CallFlow request to Sitecore EP
10
9
  * @param personalizeData - Properties to be send to Sitecore EP
@@ -13,6 +12,9 @@ const consts_1 = require("../consts");
13
12
  * @returns - A promise that resolves with either the Sitecore EP response object or unknown
14
13
  */
15
14
  async function sendCallFlowsRequest(epCallFlowsBody, settings, opts) {
15
+ const startTimestamp = Date.now();
16
+ let debugResponse = {};
17
+ // eslint-disable-next-line max-len
16
18
  const requestUrl = `${settings.sitecoreEdgeUrl}/v1/personalize?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
17
19
  const fetchOptions = {
18
20
  body: JSON.stringify(epCallFlowsBody),
@@ -20,9 +22,10 @@ async function sendCallFlowsRequest(epCallFlowsBody, settings, opts) {
20
22
  /* eslint-disable @typescript-eslint/naming-convention */
21
23
  'Content-Type': 'application/json',
22
24
  'X-Library-Version': consts_1.LIBRARY_VERSION,
25
+ 'x-sc-correlation-id': (0, core_1.generateCorrelationId)()
23
26
  /* eslint-enable @typescript-eslint/naming-convention */
24
27
  },
25
- method: 'POST',
28
+ method: 'POST'
26
29
  };
27
30
  if (opts?.userAgent)
28
31
  fetchOptions.headers['User-Agent'] = opts.userAgent;
@@ -30,8 +33,13 @@ async function sendCallFlowsRequest(epCallFlowsBody, settings, opts) {
30
33
  if (opts?.timeout === undefined)
31
34
  return fetch(requestUrl, fetchOptions)
32
35
  .then((response) => {
33
- (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Personalize response: %O', response);
36
+ debugResponse = (0, core_1.processDebugResponse)(consts_1.PERSONALIZE_NAMESPACE, response);
34
37
  return response.json();
38
+ })
39
+ .then((data) => {
40
+ debugResponse.body = data;
41
+ (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Personalize response in %dms : %O', Date.now() - startTimestamp, debugResponse);
42
+ return data;
35
43
  })
36
44
  .catch((error) => {
37
45
  (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Error personalize response: %O', error);
@@ -39,14 +47,20 @@ async function sendCallFlowsRequest(epCallFlowsBody, settings, opts) {
39
47
  });
40
48
  return (0, utils_1.fetchWithTimeout)(requestUrl, opts.timeout, fetchOptions)
41
49
  .then((response) => {
42
- (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Personalize response: %O', response);
43
- return (response && response.json()) || null;
50
+ if (!response)
51
+ return null;
52
+ debugResponse = (0, core_1.processDebugResponse)(consts_1.PERSONALIZE_NAMESPACE, response);
53
+ return response.json();
54
+ })
55
+ .then((data) => {
56
+ debugResponse.body = data;
57
+ (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Personalize response in %dms : %O', Date.now() - startTimestamp, debugResponse);
58
+ return data;
44
59
  })
45
60
  .catch((error) => {
46
61
  (0, core_1.debug)(consts_1.PERSONALIZE_NAMESPACE)('Error personalize response: %O', error);
47
- if (error.message.includes('IV-0006') || error.message.includes('IE-0002')) {
62
+ if (error.message.includes('IV-0006') || error.message.includes('IE-0002'))
48
63
  throw new Error(error.message);
49
- }
50
64
  return null;
51
65
  });
52
66
  }
@@ -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, PERSONALIZE_NAMESPACE } from './lib/consts';
4
- export type { PersonalizerInput } from './lib/personalization/personalizer';
4
+ export type { PersonalizeData } from './lib/personalization/personalizer';