@sitecore-cloudsdk/events 0.1.5 → 0.2.1

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 (75) hide show
  1. package/dist/cjs/package.json +8 -4
  2. package/dist/cjs/src/lib/consts.d.ts +10 -0
  3. package/dist/cjs/src/lib/consts.js +13 -2
  4. package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
  5. package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +8 -3
  6. package/dist/cjs/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
  7. package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +4 -3
  8. package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +4 -8
  9. package/dist/cjs/src/lib/eventStorage/eventStorage.js +15 -15
  10. package/dist/cjs/src/lib/eventStorage/processEventQueue.d.ts +1 -1
  11. package/dist/cjs/src/lib/eventStorage/processEventQueue.js +4 -3
  12. package/dist/cjs/src/lib/events/base-event.d.ts +1 -3
  13. package/dist/cjs/src/lib/events/base-event.js +1 -2
  14. package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +4 -3
  15. package/dist/cjs/src/lib/events/custom-event/custom-event.js +6 -4
  16. package/dist/cjs/src/lib/events/custom-event/event.js +7 -3
  17. package/dist/cjs/src/lib/events/custom-event/eventServer.js +4 -4
  18. package/dist/cjs/src/lib/events/custom-event/form.js +8 -4
  19. package/dist/cjs/src/lib/events/identity/identity-event.d.ts +4 -3
  20. package/dist/cjs/src/lib/events/identity/identity-event.js +10 -8
  21. package/dist/cjs/src/lib/events/identity/identity.js +8 -5
  22. package/dist/cjs/src/lib/events/identity/identityServer.js +3 -3
  23. package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +4 -3
  24. package/dist/cjs/src/lib/events/page-view/page-view-event.js +6 -5
  25. package/dist/cjs/src/lib/events/page-view/page-view-server.js +3 -3
  26. package/dist/cjs/src/lib/events/page-view/page-view.js +9 -4
  27. package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +17 -0
  28. package/dist/cjs/src/lib/events/send-event/sendEvent.js +29 -0
  29. package/dist/cjs/src/lib/getGuestId/getGuestId.js +6 -4
  30. package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +6 -19
  31. package/dist/cjs/src/lib/initializer/browser/initializer.js +21 -39
  32. package/dist/cjs/src/lib/initializer/server/initializer.d.ts +1 -16
  33. package/dist/cjs/src/lib/initializer/server/initializer.js +1 -28
  34. package/dist/cjs/src/server.d.ts +0 -1
  35. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  36. package/dist/esm/package.json +8 -4
  37. package/dist/esm/src/lib/consts.d.ts +10 -0
  38. package/dist/esm/src/lib/consts.js +12 -1
  39. package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
  40. package/dist/esm/src/lib/eventStorage/addToEventQueue.js +8 -3
  41. package/dist/esm/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
  42. package/dist/esm/src/lib/eventStorage/clearEventQueue.js +4 -3
  43. package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +4 -8
  44. package/dist/esm/src/lib/eventStorage/eventStorage.js +15 -14
  45. package/dist/esm/src/lib/eventStorage/processEventQueue.d.ts +1 -1
  46. package/dist/esm/src/lib/eventStorage/processEventQueue.js +4 -3
  47. package/dist/esm/src/lib/events/base-event.d.ts +1 -3
  48. package/dist/esm/src/lib/events/base-event.js +1 -2
  49. package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +4 -3
  50. package/dist/esm/src/lib/events/custom-event/custom-event.js +6 -4
  51. package/dist/esm/src/lib/events/custom-event/event.js +8 -4
  52. package/dist/esm/src/lib/events/custom-event/eventServer.js +5 -5
  53. package/dist/esm/src/lib/events/custom-event/form.js +8 -4
  54. package/dist/esm/src/lib/events/identity/identity-event.d.ts +4 -3
  55. package/dist/esm/src/lib/events/identity/identity-event.js +10 -8
  56. package/dist/esm/src/lib/events/identity/identity.js +8 -5
  57. package/dist/esm/src/lib/events/identity/identityServer.js +4 -4
  58. package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +4 -3
  59. package/dist/esm/src/lib/events/page-view/page-view-event.js +6 -5
  60. package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -4
  61. package/dist/esm/src/lib/events/page-view/page-view.js +9 -4
  62. package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +17 -0
  63. package/dist/esm/src/lib/events/send-event/sendEvent.js +25 -0
  64. package/dist/esm/src/lib/getGuestId/getGuestId.js +6 -4
  65. package/dist/esm/src/lib/initializer/browser/initializer.d.ts +6 -19
  66. package/dist/esm/src/lib/initializer/browser/initializer.js +20 -37
  67. package/dist/esm/src/lib/initializer/server/initializer.d.ts +1 -16
  68. package/dist/esm/src/lib/initializer/server/initializer.js +1 -26
  69. package/dist/esm/src/server.d.ts +0 -1
  70. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  71. package/package.json +8 -4
  72. package/dist/cjs/src/lib/ep/EventApiClient.d.ts +0 -18
  73. package/dist/cjs/src/lib/ep/EventApiClient.js +0 -34
  74. package/dist/esm/src/lib/ep/EventApiClient.d.ts +0 -18
  75. package/dist/esm/src/lib/ep/EventApiClient.js +0 -30
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-cloudsdk/events",
3
- "version": "0.1.5",
3
+ "version": "0.2.1",
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.3",
19
- "@sitecore-cloudsdk/utils": "^0.1.3"
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,12 +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;
14
- // just a commit change
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;
@@ -5,6 +5,7 @@ exports.IdentityEvent = void 0;
5
5
  const base_event_1 = require("../base-event");
6
6
  const consts_1 = require("../consts");
7
7
  const utils_1 = require("@sitecore-cloudsdk/utils");
8
+ const consts_2 = require("../../consts");
8
9
  class IdentityEvent 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,17 +13,18 @@ class IdentityEvent extends base_event_1.BaseEvent {
12
13
  */
13
14
  constructor(args) {
14
15
  const { channel, currency, language, page } = 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
18
  this.numberOfExtensionDataProperties = 0;
18
19
  this.validateAttributes(args.eventData);
19
20
  this.eventData = args.eventData;
20
- this.eventApiClient = args.eventApiClient;
21
+ this.sendEvent = args.sendEvent;
22
+ this.settings = args.settings;
21
23
  if (args.extensionData)
22
24
  this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
23
25
  this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
24
26
  if (this.numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
25
- throw new Error(`[IV-0005] This event supports maximum ${consts_1.MAX_EXT_ATTRIBUTES} attributes. Reduce the number of attributes.`);
27
+ throw new Error(consts_2.ErrorMessages.IV_0005);
26
28
  }
27
29
  /**
28
30
  * Function that validates the identifiers object, email and date attributes for CDN users
@@ -30,15 +32,15 @@ class IdentityEvent extends base_event_1.BaseEvent {
30
32
  */
31
33
  validateAttributes(eventData) {
32
34
  if (eventData.identifiers.length === 0)
33
- throw new Error(`[MV-0003] "identifiers" is required.`);
35
+ throw new Error(consts_2.ErrorMessages.MV_0003);
34
36
  if (eventData.dob !== undefined && !(0, utils_1.isShortISODateString)(eventData.dob))
35
- throw new Error(`[IV-0002] Incorrect value for "dob". Format the value according to ISO 8601.`);
37
+ throw new Error(consts_2.ErrorMessages.IV_0002);
36
38
  eventData.identifiers.forEach((identifier) => {
37
39
  if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
38
- throw new Error(`[IV-0004] Incorrect value for "expiryDate". Format the value according to ISO 8601.`);
40
+ throw new Error(consts_2.ErrorMessages.IV_0004);
39
41
  });
40
42
  if (eventData.email && !(0, utils_1.isValidEmail)(eventData.email))
41
- throw new Error(`[IV-0003] Incorrect value for "email". Set the value to a valid email address.`);
43
+ throw new Error(consts_2.ErrorMessages.IV_0003);
42
44
  }
43
45
  /**
44
46
  * A function that maps the identity event input data with the payload sent to the API
@@ -82,7 +84,7 @@ class IdentityEvent extends base_event_1.BaseEvent {
82
84
  const baseAttr = this.mapBaseEventPayload();
83
85
  const eventAttrs = this.mapAttributes();
84
86
  const fetchBody = Object.assign({}, eventAttrs, baseAttr);
85
- return await this.eventApiClient.send(fetchBody);
87
+ return await this.sendEvent(fetchBody, this.settings);
86
88
  }
87
89
  }
88
90
  exports.IdentityEvent = IdentityEvent;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.identity = void 0;
5
- const initializer_1 = require("../../initializer/browser/initializer");
4
+ const core_1 = require("@sitecore-cloudsdk/core");
6
5
  const identity_event_1 = require("./identity-event");
6
+ const initializer_1 = require("../../initializer/browser/initializer");
7
+ const sendEvent_1 = require("../send-event/sendEvent");
7
8
  /**
8
9
  * A function that sends an IDENTITY event to SitecoreCloud API
9
10
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
@@ -11,13 +12,15 @@ const identity_event_1 = require("./identity-event");
11
12
  * This object will be flattened and sent in the ext object of the payload
12
13
  * @returns The response object that Sitecore EP returns
13
14
  */
14
- function identity(eventData, extensionData) {
15
- const { eventApiClient, id, settings } = (0, initializer_1.getDependencies)();
15
+ async function identity(eventData, extensionData) {
16
+ await (0, initializer_1.awaitInit)();
17
+ const settings = (0, core_1.getSettings)();
18
+ const id = (0, core_1.getBrowserId)();
16
19
  return new identity_event_1.IdentityEvent({
17
- eventApiClient,
18
20
  eventData,
19
21
  extensionData,
20
22
  id,
23
+ sendEvent: sendEvent_1.sendEvent,
21
24
  settings,
22
25
  }).send();
23
26
  }
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.identityServer = void 0;
5
5
  const core_1 = require("@sitecore-cloudsdk/core");
6
- const initializer_1 = require("../../initializer/server/initializer");
7
6
  const identity_event_1 = require("./identity-event");
7
+ const sendEvent_1 = require("../send-event/sendEvent");
8
8
  /**
9
9
  * A function that sends an IDENTITY event to SitecoreCloud API
10
10
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
@@ -14,13 +14,13 @@ const identity_event_1 = require("./identity-event");
14
14
  * @returns The response object that Sitecore EP returns
15
15
  */
16
16
  function identityServer(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 identity_event_1.IdentityEvent({
20
- eventApiClient,
21
20
  eventData,
22
21
  extensionData,
23
22
  id,
23
+ sendEvent: sendEvent_1.sendEvent,
24
24
  settings: settings,
25
25
  }).send();
26
26
  }
@@ -1,15 +1,16 @@
1
1
  import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
2
2
  import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
3
3
  import { BaseEvent } from '../base-event';
4
- import { EventApiClient } from '../../ep/EventApiClient';
5
4
  import { EventAttributesInput } from '../common-interfaces';
5
+ import { SendEvent } from '../send-event/sendEvent';
6
6
  export declare class PageViewEvent extends BaseEvent {
7
7
  static isFirstPageView: boolean;
8
- private eventApiClient;
8
+ private sendEvent;
9
9
  private eventData;
10
10
  private extensionData;
11
11
  private urlSearchParams;
12
12
  private includeUTMParameters;
13
+ settings: Settings;
13
14
  /**
14
15
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
15
16
  * @param args - Unified object containing the required properties
@@ -47,7 +48,7 @@ export declare class PageViewEvent extends BaseEvent {
47
48
  * Interface of the unified arguments object for page view event
48
49
  */
49
50
  export interface PageViewEventArguments {
50
- eventApiClient: EventApiClient;
51
+ sendEvent: SendEvent;
51
52
  eventData: PageViewEventInput;
52
53
  id: string;
53
54
  settings: Settings;