@sitecore-cloudsdk/events 0.1.2 → 0.1.4

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 (76) hide show
  1. package/README.md +31 -24
  2. package/dist/cjs/package.json +8 -4
  3. package/dist/cjs/src/lib/consts.d.ts +10 -0
  4. package/dist/cjs/src/lib/consts.js +13 -1
  5. package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
  6. package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +8 -3
  7. package/dist/cjs/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
  8. package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +4 -3
  9. package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +4 -8
  10. package/dist/cjs/src/lib/eventStorage/eventStorage.js +15 -15
  11. package/dist/cjs/src/lib/eventStorage/processEventQueue.d.ts +1 -1
  12. package/dist/cjs/src/lib/eventStorage/processEventQueue.js +4 -3
  13. package/dist/cjs/src/lib/events/base-event.d.ts +1 -3
  14. package/dist/cjs/src/lib/events/base-event.js +1 -2
  15. package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +4 -3
  16. package/dist/cjs/src/lib/events/custom-event/custom-event.js +6 -4
  17. package/dist/cjs/src/lib/events/custom-event/event.js +7 -3
  18. package/dist/cjs/src/lib/events/custom-event/eventServer.js +4 -4
  19. package/dist/cjs/src/lib/events/custom-event/form.js +8 -4
  20. package/dist/cjs/src/lib/events/identity/identity-event.d.ts +4 -3
  21. package/dist/cjs/src/lib/events/identity/identity-event.js +10 -8
  22. package/dist/cjs/src/lib/events/identity/identity.js +8 -5
  23. package/dist/cjs/src/lib/events/identity/identityServer.js +3 -3
  24. package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +4 -3
  25. package/dist/cjs/src/lib/events/page-view/page-view-event.js +6 -5
  26. package/dist/cjs/src/lib/events/page-view/page-view-server.js +3 -3
  27. package/dist/cjs/src/lib/events/page-view/page-view.js +9 -4
  28. package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +17 -0
  29. package/dist/cjs/src/lib/events/send-event/sendEvent.js +29 -0
  30. package/dist/cjs/src/lib/getGuestId/getGuestId.js +6 -4
  31. package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +6 -19
  32. package/dist/cjs/src/lib/initializer/browser/initializer.js +21 -39
  33. package/dist/cjs/src/lib/initializer/server/initializer.d.ts +1 -16
  34. package/dist/cjs/src/lib/initializer/server/initializer.js +1 -28
  35. package/dist/cjs/src/server.d.ts +0 -1
  36. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  37. package/dist/esm/package.json +8 -4
  38. package/dist/esm/src/lib/consts.d.ts +10 -0
  39. package/dist/esm/src/lib/consts.js +12 -0
  40. package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
  41. package/dist/esm/src/lib/eventStorage/addToEventQueue.js +8 -3
  42. package/dist/esm/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
  43. package/dist/esm/src/lib/eventStorage/clearEventQueue.js +4 -3
  44. package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +4 -8
  45. package/dist/esm/src/lib/eventStorage/eventStorage.js +15 -14
  46. package/dist/esm/src/lib/eventStorage/processEventQueue.d.ts +1 -1
  47. package/dist/esm/src/lib/eventStorage/processEventQueue.js +4 -3
  48. package/dist/esm/src/lib/events/base-event.d.ts +1 -3
  49. package/dist/esm/src/lib/events/base-event.js +1 -2
  50. package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +4 -3
  51. package/dist/esm/src/lib/events/custom-event/custom-event.js +6 -4
  52. package/dist/esm/src/lib/events/custom-event/event.js +8 -4
  53. package/dist/esm/src/lib/events/custom-event/eventServer.js +5 -5
  54. package/dist/esm/src/lib/events/custom-event/form.js +8 -4
  55. package/dist/esm/src/lib/events/identity/identity-event.d.ts +4 -3
  56. package/dist/esm/src/lib/events/identity/identity-event.js +10 -8
  57. package/dist/esm/src/lib/events/identity/identity.js +8 -5
  58. package/dist/esm/src/lib/events/identity/identityServer.js +4 -4
  59. package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +4 -3
  60. package/dist/esm/src/lib/events/page-view/page-view-event.js +6 -5
  61. package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -4
  62. package/dist/esm/src/lib/events/page-view/page-view.js +9 -4
  63. package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +17 -0
  64. package/dist/esm/src/lib/events/send-event/sendEvent.js +25 -0
  65. package/dist/esm/src/lib/getGuestId/getGuestId.js +6 -4
  66. package/dist/esm/src/lib/initializer/browser/initializer.d.ts +6 -19
  67. package/dist/esm/src/lib/initializer/browser/initializer.js +20 -37
  68. package/dist/esm/src/lib/initializer/server/initializer.d.ts +1 -16
  69. package/dist/esm/src/lib/initializer/server/initializer.js +1 -26
  70. package/dist/esm/src/server.d.ts +0 -1
  71. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +8 -4
  73. package/dist/cjs/src/lib/ep/EventApiClient.d.ts +0 -18
  74. package/dist/cjs/src/lib/ep/EventApiClient.js +0 -34
  75. package/dist/esm/src/lib/ep/EventApiClient.d.ts +0 -18
  76. package/dist/esm/src/lib/ep/EventApiClient.js +0 -30
package/README.md CHANGED
@@ -2,14 +2,13 @@
2
2
 
3
3
  © Sitecore Corporation A/S. All rights reserved. Sitecore© is a registered trademark of Sitecore Corporation A/S.
4
4
 
5
- This package provides browser- and server-side functions to ​capture events in your app and send them to Sitecore. Events are for collecting behavioral and transactional data about your users as they interact with your app.
5
+ This package provides browser- and server-side functions to ​capture events in your app and send them to Sitecore. Events are for collecting behavioral data about your users as they interact with your app.
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
- - A Next.js 13 app deployed on Sitecore XM Cloud.
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
 
@@ -28,12 +27,20 @@ npm install @sitecore-cloudsdk/events
28
27
 
29
28
  ## Code examples
30
29
 
30
+ ---
31
+
32
+ **NOTE**
33
+
34
+ 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.
35
+
36
+ ---
37
+
31
38
  Capture and send a VIEW event from the browser side:
32
39
 
33
40
  ```ts
34
- "use client";
35
- import { useEffect } from "react";
36
- import { init, pageView } from "@sitecore-cloudsdk/events/browser";
41
+ 'use client';
42
+ import { useEffect } from 'react';
43
+ import { init, pageView } from '@sitecore-cloudsdk/events/browser';
37
44
 
38
45
  export default function Home() {
39
46
  useEffect(() => {
@@ -42,8 +49,8 @@ export default function Home() {
42
49
 
43
50
  const initEvents = async () => {
44
51
  await init({
45
- sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || "",
46
- siteName: process.env.NEXT_PUBLIC_SITENAME || "",
52
+ sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
53
+ siteName: process.env.NEXT_PUBLIC_SITENAME || '',
47
54
  enableBrowserCookie: true,
48
55
  });
49
56
 
@@ -52,17 +59,17 @@ export default function Home() {
52
59
 
53
60
  const sendPageViewEvent = async () => {
54
61
  let eventData: any = {
55
- channel: "WEB",
56
- currency: "EUR",
62
+ channel: 'WEB',
63
+ currency: 'EUR',
57
64
  };
58
65
 
59
66
  let extensionData: any = {
60
- customKey: "customValue",
67
+ customKey: 'customValue',
61
68
  };
62
69
 
63
70
  await pageView(eventData, extensionData);
64
71
 
65
- console.log("Sent VIEW event.");
72
+ console.log('Sent VIEW event.');
66
73
  };
67
74
 
68
75
  return (
@@ -76,17 +83,17 @@ export default function Home() {
76
83
  Capture and send a VIEW event from the server side:
77
84
 
78
85
  ```ts
79
- import { NextResponse } from "next/server";
80
- import type { NextRequest } from "next/server";
81
- import { init, pageView } from "@sitecore-cloudsdk/events/server";
86
+ import { NextResponse } from 'next/server';
87
+ import type { NextRequest } from 'next/server';
88
+ import { init, pageView } from '@sitecore-cloudsdk/events/server';
82
89
 
83
90
  export async function middleware(req: NextRequest) {
84
91
  const res = NextResponse.next();
85
92
 
86
93
  await init(
87
94
  {
88
- sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || "",
89
- siteName: process.env.NEXT_PUBLIC_SITENAME || "",
95
+ sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
96
+ siteName: process.env.NEXT_PUBLIC_SITENAME || '',
90
97
  enableServerCookie: true,
91
98
  },
92
99
  req,
@@ -96,17 +103,17 @@ export async function middleware(req: NextRequest) {
96
103
  console.log(`Initialized "@sitecore-cloudsdk/events/server".`);
97
104
 
98
105
  let eventData: any = {
99
- channel: "WEB",
100
- currency: "EUR",
106
+ channel: 'WEB',
107
+ currency: 'EUR',
101
108
  };
102
109
 
103
110
  let extensionData: any = {
104
- customKey: "customValue",
111
+ customKey: 'customValue',
105
112
  };
106
113
 
107
114
  const pageViewRes = await pageView(eventData, req, extensionData);
108
115
 
109
- console.log("Sent VIEW event.");
116
+ console.log('Sent VIEW event.');
110
117
 
111
118
  return res;
112
119
  }
@@ -114,8 +121,8 @@ export async function middleware(req: NextRequest) {
114
121
 
115
122
  ## Documentation
116
123
 
117
- Coming soon.
124
+ [Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html)
118
125
 
119
126
  ### License
120
127
 
121
- The Sitecore Cloud SDK uses the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
128
+ The Sitecore Cloud SDK uses the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0).
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-cloudsdk/events",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "license": "Apache-2.0",
5
5
  "exports": {
6
6
  "./server": {
@@ -15,8 +15,8 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@sitecore-cloudsdk/core": "^0.1.0-rc.2",
19
- "@sitecore-cloudsdk/utils": "^0.1.0-rc.2"
18
+ "@sitecore-cloudsdk/core": "^0.2.0",
19
+ "@sitecore-cloudsdk/utils": "^0.2.0"
20
20
  },
21
21
  "scripts": {
22
22
  "build": "npm run build:cjs && npm run build:es",
@@ -32,5 +32,9 @@
32
32
  "server.cjs",
33
33
  "server.js",
34
34
  "server.d.ts"
35
- ]
35
+ ],
36
+ "engines": {
37
+ "node": ">=18",
38
+ "npm": ">=9"
39
+ }
36
40
  }
@@ -2,3 +2,13 @@
2
2
  * Returns the version of the library.
3
3
  */
4
4
  export declare const LIBRARY_VERSION: string;
5
+ export declare enum ErrorMessages {
6
+ 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.",
7
+ IE_0004 = "[IE-0004] You must first initialize the \"events/browser\" module. Run the \"init\" function.",
8
+ IE_0005 = "[IE-0005] You must first initialize the \"events/server\" module. Run the \"init\" function.",
9
+ IV_0002 = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.",
10
+ IV_0003 = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.",
11
+ IV_0004 = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.",
12
+ IV_0005 = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.",
13
+ MV_0003 = "[MV-0003] \"identifiers\" is required."
14
+ }
@@ -3,11 +3,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LIBRARY_VERSION = void 0;
6
+ exports.ErrorMessages = exports.LIBRARY_VERSION = void 0;
7
7
  // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
8
8
  /* eslint-disable @typescript-eslint/naming-convention */
9
9
  const package_json_1 = __importDefault(require("../../package.json"));
10
+ const consts_1 = require("./events/consts");
10
11
  /**
11
12
  * Returns the version of the library.
12
13
  */
13
14
  exports.LIBRARY_VERSION = package_json_1.default.version;
15
+ var ErrorMessages;
16
+ (function (ErrorMessages) {
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.";
18
+ ErrorMessages["IE_0004"] = "[IE-0004] You must first initialize the \"events/browser\" module. Run the \"init\" function.";
19
+ ErrorMessages["IE_0005"] = "[IE-0005] You must first initialize the \"events/server\" module. Run the \"init\" function.";
20
+ ErrorMessages["IV_0002"] = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.";
21
+ ErrorMessages["IV_0003"] = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.";
22
+ ErrorMessages["IV_0004"] = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
23
+ ErrorMessages["IV_0005"] = "[IV-0005] This event supports maximum 50 attributes. Reduce the number of attributes.";
24
+ ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
25
+ })(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
@@ -6,4 +6,4 @@ import { CustomEventInput, ExtensionData } from '../events';
6
6
  * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
7
7
  * This object will be flattened and sent in the ext object of the payload
8
8
  */
9
- export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): void;
9
+ export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<void>;
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addToEventQueue = void 0;
4
+ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
4
5
  const initializer_1 = require("../initializer/browser/initializer");
6
+ const eventStorage_1 = require("./eventStorage");
7
+ const core_1 = require("@sitecore-cloudsdk/core");
5
8
  /**
6
9
  * A function that adds event to the queue
7
10
  * @param type - The required type of the event
@@ -9,8 +12,10 @@ const initializer_1 = require("../initializer/browser/initializer");
9
12
  * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
10
13
  * This object will be flattened and sent in the ext object of the payload
11
14
  */
12
- function addToEventQueue(type, eventData, extensionData) {
13
- const { id, settings, eventQueue } = (0, initializer_1.getDependencies)();
15
+ async function addToEventQueue(type, eventData, extensionData) {
16
+ await (0, initializer_1.awaitInit)();
17
+ const settings = (0, core_1.getSettings)();
18
+ const id = (0, core_1.getBrowserId)();
14
19
  const queueEventPayload = {
15
20
  eventData,
16
21
  extensionData,
@@ -18,6 +23,6 @@ function addToEventQueue(type, eventData, extensionData) {
18
23
  settings,
19
24
  type,
20
25
  };
21
- eventQueue.enqueueEvent(queueEventPayload);
26
+ eventStorage_1.eventQueue.enqueueEvent(queueEventPayload);
22
27
  }
23
28
  exports.addToEventQueue = addToEventQueue;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Deletes the queue from session.
3
3
  */
4
- export declare function clearEventQueue(): void;
4
+ export declare function clearEventQueue(): Promise<void>;
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.clearEventQueue = void 0;
4
4
  // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
5
5
  const initializer_1 = require("../initializer/browser/initializer");
6
+ const eventStorage_1 = require("./eventStorage");
6
7
  /**
7
8
  * Deletes the queue from session.
8
9
  */
9
- function clearEventQueue() {
10
- const { eventQueue } = (0, initializer_1.getDependencies)();
11
- eventQueue.clearQueue();
10
+ async function clearEventQueue() {
11
+ await (0, initializer_1.awaitInit)();
12
+ eventStorage_1.eventQueue.clearQueue();
12
13
  }
13
14
  exports.clearEventQueue = clearEventQueue;
@@ -1,16 +1,9 @@
1
- import { EventApiClient } from '../ep/EventApiClient';
2
1
  import { CustomEventArguments } from '../events';
3
- export declare class EventQueue {
4
- private storage;
5
- private eventApiClient;
2
+ declare class EventQueue {
6
3
  /**
7
4
  * Initialize the Event Storage
8
- * @param storage - Interface that describes the storage functionality
9
- * @param eventApiClient - The API client which sends events to EP
10
- * @param infer - The instance of the infer class
11
5
  */
12
6
  private key;
13
- constructor(storage: Storage, eventApiClient: EventApiClient);
14
7
  /** Returns the stored array of data with type QueueEventPayload, or empty array if the given key does not exist. */
15
8
  private getEventQueue;
16
9
  /**
@@ -27,6 +20,7 @@ export declare class EventQueue {
27
20
  * Clears the queue from storage.
28
21
  */
29
22
  clearQueue(): void;
23
+ private getSessionStorage;
30
24
  }
31
25
  /**
32
26
  * This Storage interface represents the required storage functionality.
@@ -37,3 +31,5 @@ export interface Storage {
37
31
  removeItem(key: string): void;
38
32
  }
39
33
  export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'extensionData' | 'type' | 'settings' | 'id'>;
34
+ export declare const eventQueue: EventQueue;
35
+ export {};
@@ -1,26 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventQueue = void 0;
3
+ exports.eventQueue = void 0;
4
4
  // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
5
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const events_1 = require("../events");
7
+ const sendEvent_1 = require("../events/send-event/sendEvent");
7
8
  class EventQueue {
8
- constructor(storage, eventApiClient) {
9
- this.storage = storage;
10
- this.eventApiClient = eventApiClient;
9
+ constructor() {
11
10
  /**
12
11
  * Initialize the Event Storage
13
- * @param storage - Interface that describes the storage functionality
14
- * @param eventApiClient - The API client which sends events to EP
15
- * @param infer - The instance of the infer class
16
12
  */
17
13
  this.key = 'EventQueue';
18
14
  }
19
15
  /** Returns the stored array of data with type QueueEventPayload, or empty array if the given key does not exist. */
20
16
  getEventQueue() {
21
- const storedQueue = this.storage.getItem(this.key);
22
- if (!storedQueue)
23
- return [];
17
+ const sessionStorage = this.getSessionStorage();
18
+ const storedQueue = sessionStorage.getItem(this.key) ?? '""';
24
19
  try {
25
20
  const parsedQueueEvent = JSON.parse(storedQueue);
26
21
  return Array.isArray(parsedQueueEvent) ? parsedQueueEvent : [];
@@ -35,15 +30,16 @@ class EventQueue {
35
30
  * Performs validation by creating a new CustomEvent.
36
31
  */
37
32
  enqueueEvent(queueEventPayload) {
33
+ const sessionStorage = this.getSessionStorage();
38
34
  queueEventPayload.eventData.page = queueEventPayload.eventData.page ?? (0, core_1.pageName)();
39
35
  queueEventPayload.eventData.language = queueEventPayload.eventData.language ?? (0, core_1.language)();
40
36
  new events_1.CustomEvent({
41
- eventApiClient: this.eventApiClient,
37
+ sendEvent: sendEvent_1.sendEvent,
42
38
  ...queueEventPayload,
43
39
  });
44
40
  const eventQueue = this.getEventQueue();
45
41
  eventQueue.push(queueEventPayload);
46
- this.storage.setItem(this.key, JSON.stringify(eventQueue));
42
+ sessionStorage.setItem(this.key, JSON.stringify(eventQueue));
47
43
  }
48
44
  /**
49
45
  * Iterates the queue, and sends sequently the custom events to Sitecore EP.
@@ -52,10 +48,10 @@ class EventQueue {
52
48
  const eventQueue = this.getEventQueue();
53
49
  for (const queueEventPayload of eventQueue) {
54
50
  await new events_1.CustomEvent({
55
- eventApiClient: this.eventApiClient,
56
51
  eventData: queueEventPayload.eventData,
57
52
  extensionData: queueEventPayload.extensionData,
58
53
  id: queueEventPayload.id,
54
+ sendEvent: sendEvent_1.sendEvent,
59
55
  settings: queueEventPayload.settings,
60
56
  type: queueEventPayload.type,
61
57
  }).send();
@@ -66,7 +62,11 @@ class EventQueue {
66
62
  * Clears the queue from storage.
67
63
  */
68
64
  clearQueue() {
69
- this.storage.removeItem(this.key);
65
+ const sessionStorage = this.getSessionStorage();
66
+ sessionStorage.removeItem(this.key);
67
+ }
68
+ getSessionStorage() {
69
+ return sessionStorage;
70
70
  }
71
71
  }
72
- exports.EventQueue = EventQueue;
72
+ exports.eventQueue = new EventQueue();
@@ -2,4 +2,4 @@
2
2
  * A function that sends all queue events to SitecoreCloud API.
3
3
  * Clears the queue upon completion.
4
4
  */
5
- export declare function processEventQueue(): void;
5
+ export declare function processEventQueue(): Promise<void>;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processEventQueue = void 0;
4
4
  // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
5
5
  const initializer_1 = require("../initializer/browser/initializer");
6
+ const eventStorage_1 = require("./eventStorage");
6
7
  /**
7
8
  * A function that sends all queue events to SitecoreCloud API.
8
9
  * Clears the queue upon completion.
9
10
  */
10
- function processEventQueue() {
11
- const { eventQueue } = (0, initializer_1.getDependencies)();
12
- eventQueue.sendAllEvents();
11
+ async function processEventQueue() {
12
+ await (0, initializer_1.awaitInit)();
13
+ eventStorage_1.eventQueue.sendAllEvents();
13
14
  }
14
15
  exports.processEventQueue = processEventQueue;
@@ -1,8 +1,6 @@
1
- import type { Settings } from '@sitecore-cloudsdk/core';
2
1
  import { EventAttributesInput } from './common-interfaces';
3
2
  export declare class BaseEvent {
4
3
  private baseEventData;
5
- protected settings: Settings;
6
4
  private readonly browserId;
7
5
  private readonly language;
8
6
  page: string;
@@ -13,7 +11,7 @@ export declare class BaseEvent {
13
11
  * @param id - The browser id
14
12
  * @param infer - The source of methods to estimate language and page parameters
15
13
  */
16
- constructor(baseEventData: BaseEventData, settings: Settings, id: string);
14
+ constructor(baseEventData: BaseEventData, id: string);
17
15
  /**
18
16
  * A function that returns the properties for sending events to Sitecore EP
19
17
  * @returns an object that is required
@@ -11,9 +11,8 @@ class BaseEvent {
11
11
  * @param id - The browser id
12
12
  * @param infer - The source of methods to estimate language and page parameters
13
13
  */
14
- constructor(baseEventData, settings, id) {
14
+ constructor(baseEventData, id) {
15
15
  this.baseEventData = baseEventData;
16
- this.settings = settings;
17
16
  this.browserId = id;
18
17
  this.language = this.baseEventData.language ?? (0, core_1.language)();
19
18
  this.page = this.baseEventData.page ?? (0, core_1.pageName)();
@@ -1,12 +1,13 @@
1
1
  import { BaseEvent } from '../base-event';
2
2
  import { EventAttributesInput } from '../common-interfaces';
3
- import { EventApiClient } from '../../ep/EventApiClient';
3
+ import { SendEvent } from '../send-event/sendEvent';
4
4
  import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
5
5
  import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
6
6
  export declare class CustomEvent extends BaseEvent {
7
7
  customEventPayload: CustomEventPayload;
8
- private eventApiClient;
8
+ private sendEvent;
9
9
  private extensionData;
10
+ private settings;
10
11
  /**
11
12
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
12
13
  * @param args - Unified object containing the required properties
@@ -22,7 +23,7 @@ export declare class CustomEvent extends BaseEvent {
22
23
  * Interface of the unified arguments object for custom event
23
24
  */
24
25
  export interface CustomEventArguments {
25
- eventApiClient: EventApiClient;
26
+ sendEvent: SendEvent;
26
27
  eventData: CustomEventData;
27
28
  id: string;
28
29
  extensionData?: NestedObject;
@@ -5,6 +5,7 @@ exports.CustomEvent = void 0;
5
5
  const base_event_1 = require("../base-event");
6
6
  const utils_1 = require("@sitecore-cloudsdk/utils");
7
7
  const consts_1 = require("../consts");
8
+ const consts_2 = require("../../consts");
8
9
  class CustomEvent extends base_event_1.BaseEvent {
9
10
  /**
10
11
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
@@ -12,9 +13,10 @@ class CustomEvent extends base_event_1.BaseEvent {
12
13
  */
13
14
  constructor(args) {
14
15
  const { channel, currency, language, page, ...rest } = args.eventData;
15
- super({ channel, currency, language, page }, args.settings, args.id);
16
+ super({ channel, currency, language, page }, args.id);
16
17
  this.extensionData = {};
17
- this.eventApiClient = args.eventApiClient;
18
+ this.sendEvent = args.sendEvent;
19
+ this.settings = args.settings;
18
20
  this.customEventPayload = {
19
21
  type: args.type,
20
22
  ...rest,
@@ -23,7 +25,7 @@ class CustomEvent extends base_event_1.BaseEvent {
23
25
  this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
24
26
  const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
25
27
  if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
26
- throw new Error(`[IV-0005] This event supports maximum ${consts_1.MAX_EXT_ATTRIBUTES} attributes. Reduce the number of attributes.`);
28
+ throw new Error(consts_2.ErrorMessages.IV_0005);
27
29
  if (numberOfExtensionDataProperties > 0)
28
30
  this.customEventPayload.ext = this.extensionData;
29
31
  }
@@ -34,7 +36,7 @@ class CustomEvent extends base_event_1.BaseEvent {
34
36
  async send() {
35
37
  const baseAttr = this.mapBaseEventPayload();
36
38
  const fetchBody = Object.assign({}, this.customEventPayload, baseAttr);
37
- return await this.eventApiClient.send(fetchBody);
39
+ return await this.sendEvent(fetchBody, this.settings);
38
40
  }
39
41
  }
40
42
  exports.CustomEvent = CustomEvent;
@@ -2,8 +2,10 @@
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
4
  exports.event = void 0;
5
+ const core_1 = require("@sitecore-cloudsdk/core");
5
6
  const custom_event_1 = require("./custom-event");
6
7
  const initializer_1 = require("../../initializer/browser/initializer");
8
+ const sendEvent_1 = require("../send-event/sendEvent");
7
9
  /**
8
10
  * A function that sends an event to SitecoreCloud API with the specified type
9
11
  * @param type - The required type of the event
@@ -12,13 +14,15 @@ const initializer_1 = require("../../initializer/browser/initializer");
12
14
  * This object will be flattened and sent in the ext object of the payload
13
15
  * @returns The response object that Sitecore EP returns
14
16
  */
15
- function event(type, eventData, extensionData) {
16
- const { eventApiClient, id, settings } = (0, initializer_1.getDependencies)();
17
+ async function event(type, eventData, extensionData) {
18
+ await (0, initializer_1.awaitInit)();
19
+ const settings = (0, core_1.getSettings)();
20
+ const id = (0, core_1.getBrowserId)();
17
21
  return new custom_event_1.CustomEvent({
18
- eventApiClient,
19
22
  eventData,
20
23
  extensionData,
21
24
  id,
25
+ sendEvent: sendEvent_1.sendEvent,
22
26
  settings,
23
27
  type,
24
28
  }).send();
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.eventServer = void 0;
5
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const custom_event_1 = require("./custom-event");
7
- const initializer_1 = require("../../initializer/server/initializer");
7
+ const sendEvent_1 = require("../send-event/sendEvent");
8
8
  /**
9
9
  * A function that sends an event to SitecoreCloud API with the specified type
10
10
  * @param type - The required type of the event
@@ -14,14 +14,14 @@ const initializer_1 = require("../../initializer/server/initializer");
14
14
  * @returns The response object that Sitecore EP returns
15
15
  */
16
16
  function eventServer(type, eventData, request, extensionData) {
17
- const { eventApiClient, settings } = (0, initializer_1.getServerDependencies)();
17
+ const settings = (0, core_1.getSettingsServer)();
18
18
  const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
19
19
  return new custom_event_1.CustomEvent({
20
- eventApiClient,
21
20
  eventData,
22
21
  extensionData,
23
22
  id,
24
- settings: settings,
23
+ sendEvent: sendEvent_1.sendEvent,
24
+ settings,
25
25
  type,
26
26
  }).send();
27
27
  }
@@ -2,8 +2,10 @@
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
4
  exports.form = void 0;
5
- const initializer_1 = require("../../initializer/browser/initializer");
5
+ const core_1 = require("@sitecore-cloudsdk/core");
6
6
  const custom_event_1 = require("./custom-event");
7
+ const sendEvent_1 = require("../send-event/sendEvent");
8
+ const initializer_1 = require("../../initializer/browser/initializer");
7
9
  /**
8
10
  * A function that sends a form event to SitecoreCloud API
9
11
  * @param formId - The required form ID string
@@ -11,16 +13,18 @@ const custom_event_1 = require("./custom-event");
11
13
  * settings object, you must specify it here
12
14
  * @returns The response object that Sitecore EP returns or null
13
15
  */
14
- function form(formId, interactionType) {
15
- const { eventApiClient, id, settings } = (0, initializer_1.getDependencies)();
16
+ async function form(formId, interactionType) {
17
+ await (0, initializer_1.awaitInit)();
18
+ const settings = (0, core_1.getSettings)();
19
+ const id = (0, core_1.getBrowserId)();
16
20
  const formEvent = new custom_event_1.CustomEvent({
17
- eventApiClient,
18
21
  eventData: {},
19
22
  extensionData: {
20
23
  formId,
21
24
  interactionType: interactionType.toUpperCase(),
22
25
  },
23
26
  id,
27
+ sendEvent: sendEvent_1.sendEvent,
24
28
  settings,
25
29
  type: 'FORM',
26
30
  });
@@ -1,13 +1,14 @@
1
1
  import { BaseEvent } from '../base-event';
2
2
  import { ExtensionData, EventAttributesInput } from '../common-interfaces';
3
- import { EventApiClient } from '../../ep/EventApiClient';
4
3
  import { FlattenedObject } from '@sitecore-cloudsdk/utils';
5
4
  import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
5
+ import { SendEvent } from '../send-event/sendEvent';
6
6
  export declare class IdentityEvent extends BaseEvent {
7
7
  private eventData;
8
- private eventApiClient;
8
+ private sendEvent;
9
9
  private extensionData;
10
10
  private numberOfExtensionDataProperties;
11
+ private settings;
11
12
  /**
12
13
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
13
14
  * @param args - Unified object containing the required properties
@@ -89,7 +90,7 @@ export interface IdentityEventPayload {
89
90
  * Interface of the unified arguments object for identity event
90
91
  */
91
92
  export interface IdentityEventArguments {
92
- eventApiClient: EventApiClient;
93
+ sendEvent: SendEvent;
93
94
  eventData: IdentityEventAttributesInput;
94
95
  extensionData?: ExtensionData;
95
96
  id: string;