@sitecore-cloudsdk/events 0.2.3 → 0.3.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 (76) hide show
  1. package/README.md +8 -30
  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.d.ts +1 -1
  5. package/dist/cjs/src/lib/consts.js +1 -1
  6. package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
  7. package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +2 -6
  8. package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +1 -1
  9. package/dist/cjs/src/lib/eventStorage/eventStorage.js +0 -2
  10. package/dist/cjs/src/lib/events/base-event.d.ts +1 -1
  11. package/dist/cjs/src/lib/events/common-interfaces.d.ts +3 -20
  12. package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +5 -11
  13. package/dist/cjs/src/lib/events/custom-event/custom-event.js +4 -4
  14. package/dist/cjs/src/lib/events/custom-event/event.d.ts +3 -6
  15. package/dist/cjs/src/lib/events/custom-event/event.js +2 -6
  16. package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +4 -6
  17. package/dist/cjs/src/lib/events/custom-event/eventServer.js +3 -6
  18. package/dist/cjs/src/lib/events/custom-event/form.d.ts +1 -0
  19. package/dist/cjs/src/lib/events/custom-event/form.js +7 -5
  20. package/dist/cjs/src/lib/events/identity/identity-event.d.ts +6 -5
  21. package/dist/cjs/src/lib/events/identity/identity-event.js +26 -25
  22. package/dist/cjs/src/lib/events/identity/identity.d.ts +3 -5
  23. package/dist/cjs/src/lib/events/identity/identity.js +4 -5
  24. package/dist/cjs/src/lib/events/identity/identityServer.d.ts +4 -6
  25. package/dist/cjs/src/lib/events/identity/identityServer.js +4 -6
  26. package/dist/cjs/src/lib/events/index.d.ts +3 -3
  27. package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +5 -4
  28. package/dist/cjs/src/lib/events/page-view/page-view-event.js +11 -11
  29. package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +5 -6
  30. package/dist/cjs/src/lib/events/page-view/page-view-server.js +4 -6
  31. package/dist/cjs/src/lib/events/page-view/page-view.d.ts +4 -5
  32. package/dist/cjs/src/lib/events/page-view/page-view.js +4 -5
  33. package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +3 -3
  34. package/dist/cjs/src/lib/initializer/browser/initializer.js +3 -3
  35. package/dist/cjs/src/lib/initializer/server/initializer.d.ts +4 -2
  36. package/dist/cjs/src/lib/initializer/server/initializer.js +4 -2
  37. package/dist/cjs/src/server.d.ts +1 -1
  38. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  39. package/dist/esm/package.json +5 -6
  40. package/dist/esm/src/browser.d.ts +1 -1
  41. package/dist/esm/src/lib/consts.d.ts +1 -1
  42. package/dist/esm/src/lib/consts.js +1 -1
  43. package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
  44. package/dist/esm/src/lib/eventStorage/addToEventQueue.js +2 -6
  45. package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +1 -1
  46. package/dist/esm/src/lib/eventStorage/eventStorage.js +0 -2
  47. package/dist/esm/src/lib/events/base-event.d.ts +1 -1
  48. package/dist/esm/src/lib/events/common-interfaces.d.ts +3 -20
  49. package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +5 -11
  50. package/dist/esm/src/lib/events/custom-event/custom-event.js +4 -4
  51. package/dist/esm/src/lib/events/custom-event/event.d.ts +3 -6
  52. package/dist/esm/src/lib/events/custom-event/event.js +2 -6
  53. package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +4 -6
  54. package/dist/esm/src/lib/events/custom-event/eventServer.js +3 -6
  55. package/dist/esm/src/lib/events/custom-event/form.d.ts +1 -0
  56. package/dist/esm/src/lib/events/custom-event/form.js +7 -5
  57. package/dist/esm/src/lib/events/identity/identity-event.d.ts +6 -5
  58. package/dist/esm/src/lib/events/identity/identity-event.js +26 -25
  59. package/dist/esm/src/lib/events/identity/identity.d.ts +3 -5
  60. package/dist/esm/src/lib/events/identity/identity.js +4 -5
  61. package/dist/esm/src/lib/events/identity/identityServer.d.ts +4 -6
  62. package/dist/esm/src/lib/events/identity/identityServer.js +4 -6
  63. package/dist/esm/src/lib/events/index.d.ts +3 -3
  64. package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +5 -4
  65. package/dist/esm/src/lib/events/page-view/page-view-event.js +11 -11
  66. package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +5 -6
  67. package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -6
  68. package/dist/esm/src/lib/events/page-view/page-view.d.ts +4 -5
  69. package/dist/esm/src/lib/events/page-view/page-view.js +4 -5
  70. package/dist/esm/src/lib/initializer/browser/initializer.d.ts +3 -3
  71. package/dist/esm/src/lib/initializer/browser/initializer.js +3 -3
  72. package/dist/esm/src/lib/initializer/server/initializer.d.ts +4 -2
  73. package/dist/esm/src/lib/initializer/server/initializer.js +4 -2
  74. package/dist/esm/src/server.d.ts +1 -1
  75. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +5 -6
@@ -30,6 +30,6 @@ export interface Storage {
30
30
  setItem(key: string, value: string): void;
31
31
  removeItem(key: string): void;
32
32
  }
33
- export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'extensionData' | 'type' | 'settings' | 'id'>;
33
+ export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'settings' | 'id'>;
34
34
  export declare const eventQueue: EventQueue;
35
35
  export {};
@@ -46,11 +46,9 @@ class EventQueue {
46
46
  for (const queueEventPayload of eventQueue) {
47
47
  await new CustomEvent({
48
48
  eventData: queueEventPayload.eventData,
49
- extensionData: queueEventPayload.extensionData,
50
49
  id: queueEventPayload.id,
51
50
  sendEvent,
52
51
  settings: queueEventPayload.settings,
53
- type: queueEventPayload.type,
54
52
  }).send();
55
53
  }
56
54
  this.clearQueue();
@@ -30,5 +30,5 @@ export interface BasePayload {
30
30
  page?: string;
31
31
  pos: string;
32
32
  }
33
- type BaseEventData = Partial<EventAttributesInput>;
33
+ type BaseEventData = EventAttributesInput;
34
34
  export {};
@@ -1,31 +1,14 @@
1
1
  import { NestedObject } from '@sitecore-cloudsdk/utils';
2
- /**
3
- * Event data received as input to be sent to Sitecore EP
4
- */
5
- interface MandatoryInput {
6
- channel: string;
7
- currency: string;
8
- }
9
- type MandatoryEventInput = MandatoryInput;
10
2
  /**
11
3
  * Event data that is sent to Sitecore EP
12
4
  */
13
- interface InferrableInput {
14
- /**
15
- * To be restored back to MandatoryEventInput Interface
16
- * as mandatory input parameter in version 1.0.0
17
- */
5
+ export interface EventAttributesInput {
18
6
  language?: string;
19
7
  page?: string;
20
- }
21
- type InferrableEventInput = InferrableInput;
22
- /**
23
- * Interface to hold the base event attributes
24
- */
25
- export interface EventAttributesInput extends MandatoryEventInput, InferrableEventInput {
8
+ channel?: string;
9
+ currency?: string;
26
10
  }
27
11
  /**
28
12
  * Type of the extension data that the developer can pass to events
29
13
  */
30
14
  export type ExtensionData = NestedObject;
31
- export {};
@@ -1,5 +1,5 @@
1
1
  import { BaseEvent } from '../base-event';
2
- import { EventAttributesInput } from '../common-interfaces';
2
+ import { EventAttributesInput, ExtensionData } from '../common-interfaces';
3
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';
@@ -24,11 +24,9 @@ export declare class CustomEvent extends BaseEvent {
24
24
  */
25
25
  export interface CustomEventArguments {
26
26
  sendEvent: SendEvent;
27
- eventData: CustomEventData;
27
+ eventData: EventData;
28
28
  id: string;
29
- extensionData?: NestedObject;
30
29
  settings: Settings;
31
- type: string;
32
30
  }
33
31
  /**
34
32
  * Interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
@@ -41,11 +39,7 @@ export interface CustomEventPayload extends NestedObject {
41
39
  /**
42
40
  * Interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
43
41
  */
44
- export interface CustomEventInput extends EventAttributesInput, NestedObject {
45
- }
46
- /**
47
- * Internal interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
48
- */
49
- interface CustomEventData extends Partial<EventAttributesInput>, NestedObject {
42
+ export interface EventData extends EventAttributesInput, NestedObject {
43
+ type: string;
44
+ extensionData?: ExtensionData;
50
45
  }
51
- export {};
@@ -9,17 +9,17 @@ export class CustomEvent extends BaseEvent {
9
9
  * @param args - Unified object containing the required properties
10
10
  */
11
11
  constructor(args) {
12
- const { channel, currency, language, page, ...rest } = args.eventData;
12
+ const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
13
13
  super({ channel, currency, language, page }, args.id);
14
14
  this.extensionData = {};
15
15
  this.sendEvent = args.sendEvent;
16
16
  this.settings = args.settings;
17
17
  this.customEventPayload = {
18
- type: args.type,
18
+ type,
19
19
  ...rest,
20
20
  };
21
- if (args.extensionData)
22
- this.extensionData = flattenObject({ object: args.extensionData });
21
+ if (extensionData)
22
+ this.extensionData = flattenObject({ object: extensionData });
23
23
  const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
24
24
  if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
25
25
  throw new Error(ErrorMessages.IV_0005);
@@ -1,12 +1,9 @@
1
1
  import { EPResponse } from '@sitecore-cloudsdk/core';
2
- import { ExtensionData } from '../common-interfaces';
3
- import { CustomEventInput } from './custom-event';
2
+ import { EventData } from './custom-event';
4
3
  /**
5
4
  * A function that sends an event to SitecoreCloud API with the specified type
6
- * @param type - The required type of the event
5
+ *
7
6
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
8
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
9
- * This object will be flattened and sent in the ext object of the payload
10
7
  * @returns The response object that Sitecore EP returns
11
8
  */
12
- export declare function event(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
9
+ export declare function event(eventData: EventData): Promise<EPResponse | null>;
@@ -6,22 +6,18 @@ import { sendEvent } from '../send-event/sendEvent';
6
6
  import { ErrorMessages } from '../../consts';
7
7
  /**
8
8
  * A function that sends an event to SitecoreCloud API with the specified type
9
- * @param type - The required type of the event
9
+ *
10
10
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
11
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
12
- * This object will be flattened and sent in the ext object of the payload
13
11
  * @returns The response object that Sitecore EP returns
14
12
  */
15
- export async function event(type, eventData, extensionData) {
13
+ export async function event(eventData) {
16
14
  await awaitInit();
17
15
  const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
18
16
  const id = getBrowserId();
19
17
  return new CustomEvent({
20
18
  eventData,
21
- extensionData,
22
19
  id,
23
20
  sendEvent,
24
21
  settings,
25
- type,
26
22
  }).send();
27
23
  }
@@ -1,13 +1,11 @@
1
1
  import { EPResponse } from '@sitecore-cloudsdk/core';
2
- import { ExtensionData } from '../common-interfaces';
3
- import { CustomEventInput } from './custom-event';
2
+ import { EventData } from './custom-event';
4
3
  import { Request } from '@sitecore-cloudsdk/utils';
5
4
  /**
6
5
  * A function that sends an event to SitecoreCloud API with the specified type
7
- * @param type - The required type of the event
8
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
6
+ *
9
7
  * @param request - Interface with constraint for extending request
10
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
8
+ * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
11
9
  * @returns The response object that Sitecore EP returns
12
10
  */
13
- export declare function eventServer<T extends Request>(type: string, eventData: CustomEventInput, request: T, extensionData?: ExtensionData): Promise<EPResponse | null>;
11
+ export declare function eventServer<T extends Request>(request: T, eventData: EventData): Promise<EPResponse | null>;
@@ -5,21 +5,18 @@ import { sendEvent } from '../send-event/sendEvent';
5
5
  import { ErrorMessages } from '../../consts';
6
6
  /**
7
7
  * A function that sends an event to SitecoreCloud API with the specified type
8
- * @param type - The required type of the event
9
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
8
+ *
10
9
  * @param request - Interface with constraint for extending request
11
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
10
+ * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
12
11
  * @returns The response object that Sitecore EP returns
13
12
  */
14
- export function eventServer(type, eventData, request, extensionData) {
13
+ export function eventServer(request, eventData) {
15
14
  const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
16
15
  const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
17
16
  return new CustomEvent({
18
17
  eventData,
19
- extensionData,
20
18
  id,
21
19
  sendEvent,
22
20
  settings,
23
- type,
24
21
  }).send();
25
22
  }
@@ -1,6 +1,7 @@
1
1
  import { EPResponse } from '@sitecore-cloudsdk/core';
2
2
  /**
3
3
  * A function that sends a form event to SitecoreCloud API
4
+ *
4
5
  * @param formId - The required form ID string
5
6
  * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"
6
7
  * settings object, you must specify it here
@@ -6,6 +6,7 @@ import { awaitInit } from '../../initializer/browser/initializer';
6
6
  import { ErrorMessages } from '../../consts';
7
7
  /**
8
8
  * A function that sends a form event to SitecoreCloud API
9
+ *
9
10
  * @param formId - The required form ID string
10
11
  * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"
11
12
  * settings object, you must specify it here
@@ -16,15 +17,16 @@ export async function form(formId, interactionType) {
16
17
  const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
17
18
  const id = getBrowserId();
18
19
  const formEvent = new CustomEvent({
19
- eventData: {},
20
- extensionData: {
21
- formId,
22
- interactionType: interactionType.toUpperCase(),
20
+ eventData: {
21
+ extensionData: {
22
+ formId,
23
+ interactionType: interactionType.toUpperCase(),
24
+ },
25
+ type: 'FORM',
23
26
  },
24
27
  id,
25
28
  sendEvent,
26
29
  settings,
27
- type: 'FORM',
28
30
  });
29
31
  formEvent.page = undefined;
30
32
  return formEvent.send();
@@ -4,19 +4,20 @@ import { FlattenedObject } from '@sitecore-cloudsdk/utils';
4
4
  import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
5
5
  import { SendEvent } from '../send-event/sendEvent';
6
6
  export declare class IdentityEvent extends BaseEvent {
7
- private eventData;
7
+ private identityData;
8
8
  private sendEvent;
9
9
  private extensionData;
10
10
  private numberOfExtensionDataProperties;
11
11
  private settings;
12
12
  /**
13
13
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
14
+ *
14
15
  * @param args - Unified object containing the required properties
15
16
  */
16
17
  constructor(args: IdentityEventArguments);
17
18
  /**
18
19
  * Function that validates the identifiers object, email and date attributes for CDN users
19
- * * @param eventData - The data to be validated
20
+ * * @param identityData - The data to be validated
20
21
  */
21
22
  private validateAttributes;
22
23
  /**
@@ -41,7 +42,7 @@ interface EPIdentifier {
41
42
  /**
42
43
  * Interface with the necessary attributes for the input for sending Identity events
43
44
  */
44
- export interface IdentityEventAttributesInput extends EventAttributesInput {
45
+ export interface IdentityData extends EventAttributesInput {
45
46
  city?: string;
46
47
  country?: string;
47
48
  dob?: string;
@@ -56,6 +57,7 @@ export interface IdentityEventAttributesInput extends EventAttributesInput {
56
57
  state?: string;
57
58
  street?: string[];
58
59
  title?: string;
60
+ extensionData?: ExtensionData;
59
61
  }
60
62
  /**
61
63
  * The JSON array of objects that contain the identity identifiers
@@ -91,8 +93,7 @@ export interface IdentityEventPayload {
91
93
  */
92
94
  export interface IdentityEventArguments {
93
95
  sendEvent: SendEvent;
94
- eventData: IdentityEventAttributesInput;
95
- extensionData?: ExtensionData;
96
+ identityData: IdentityData;
96
97
  id: string;
97
98
  settings: Settings;
98
99
  infer?: Infer;
@@ -6,37 +6,38 @@ import { ErrorMessages } from '../../consts';
6
6
  export class IdentityEvent extends BaseEvent {
7
7
  /**
8
8
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
9
+ *
9
10
  * @param args - Unified object containing the required properties
10
11
  */
11
12
  constructor(args) {
12
- const { channel, currency, language, page } = args.eventData;
13
+ const { channel, currency, language, page, extensionData } = args.identityData;
13
14
  super({ channel, currency, language, page }, args.id);
14
15
  this.extensionData = {};
15
16
  this.numberOfExtensionDataProperties = 0;
16
- this.validateAttributes(args.eventData);
17
- this.eventData = args.eventData;
17
+ this.validateAttributes(args.identityData);
18
+ this.identityData = args.identityData;
18
19
  this.sendEvent = args.sendEvent;
19
20
  this.settings = args.settings;
20
- if (args.extensionData)
21
- this.extensionData = flattenObject({ object: args.extensionData });
21
+ if (extensionData)
22
+ this.extensionData = flattenObject({ object: extensionData });
22
23
  this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
23
24
  if (this.numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
24
25
  throw new Error(ErrorMessages.IV_0005);
25
26
  }
26
27
  /**
27
28
  * Function that validates the identifiers object, email and date attributes for CDN users
28
- * * @param eventData - The data to be validated
29
+ * * @param identityData - The data to be validated
29
30
  */
30
- validateAttributes(eventData) {
31
- if (eventData.identifiers.length === 0)
31
+ validateAttributes(identityData) {
32
+ if (identityData.identifiers.length === 0)
32
33
  throw new Error(ErrorMessages.MV_0003);
33
- if (eventData.dob !== undefined && !isShortISODateString(eventData.dob))
34
+ if (identityData.dob !== undefined && !isShortISODateString(identityData.dob))
34
35
  throw new Error(ErrorMessages.IV_0002);
35
- eventData.identifiers.forEach((identifier) => {
36
+ identityData.identifiers.forEach((identifier) => {
36
37
  if (identifier.expiryDate && !isShortISODateString(identifier.expiryDate))
37
38
  throw new Error(ErrorMessages.IV_0004);
38
39
  });
39
- if (eventData.email && !isValidEmail(eventData.email))
40
+ if (identityData.email && !isValidEmail(identityData.email))
40
41
  throw new Error(ErrorMessages.IV_0003);
41
42
  }
42
43
  /**
@@ -45,13 +46,13 @@ export class IdentityEvent extends BaseEvent {
45
46
  */
46
47
  mapAttributes() {
47
48
  const identityPayload = {
48
- city: this.eventData.city,
49
- country: this.eventData.country,
50
- dob: this.eventData.dob,
51
- email: this.eventData.email,
52
- firstname: this.eventData.firstName,
53
- gender: this.eventData.gender,
54
- identifiers: this.eventData.identifiers.map((value) => {
49
+ city: this.identityData.city,
50
+ country: this.identityData.country,
51
+ dob: this.identityData.dob,
52
+ email: this.identityData.email,
53
+ firstname: this.identityData.firstName,
54
+ gender: this.identityData.gender,
55
+ identifiers: this.identityData.identifiers.map((value) => {
55
56
  return {
56
57
  // eslint-disable-next-line @typescript-eslint/naming-convention
57
58
  expiry_date: value.expiryDate,
@@ -59,14 +60,14 @@ export class IdentityEvent extends BaseEvent {
59
60
  provider: value.provider,
60
61
  };
61
62
  }),
62
- lastname: this.eventData.lastName,
63
- mobile: this.eventData.mobile,
64
- phone: this.eventData.phone,
63
+ lastname: this.identityData.lastName,
64
+ mobile: this.identityData.mobile,
65
+ phone: this.identityData.phone,
65
66
  // eslint-disable-next-line @typescript-eslint/naming-convention
66
- postal_code: this.eventData.postalCode,
67
- state: this.eventData.state,
68
- street: this.eventData.street,
69
- title: this.eventData.title,
67
+ postal_code: this.identityData.postalCode,
68
+ state: this.identityData.state,
69
+ street: this.identityData.street,
70
+ title: this.identityData.title,
70
71
  type: 'IDENTITY',
71
72
  };
72
73
  if (this.numberOfExtensionDataProperties > 0)
@@ -1,11 +1,9 @@
1
- import { ExtensionData } from '../common-interfaces';
2
1
  import { EPResponse } from '@sitecore-cloudsdk/core';
3
- import { IdentityEventAttributesInput } from './identity-event';
2
+ import { IdentityData } from './identity-event';
4
3
  /**
5
4
  * A function that sends an IDENTITY event to SitecoreCloud API
5
+ *
6
6
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
7
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
8
- * This object will be flattened and sent in the ext object of the payload
9
7
  * @returns The response object that Sitecore EP returns
10
8
  */
11
- export declare function identity(eventData: IdentityEventAttributesInput, extensionData?: ExtensionData): Promise<EPResponse | null>;
9
+ export declare function identity(identityData: IdentityData): Promise<EPResponse | null>;
@@ -1,3 +1,4 @@
1
+ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
1
2
  import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
2
3
  import { IdentityEvent } from './identity-event';
3
4
  import { awaitInit } from '../../initializer/browser/initializer';
@@ -5,19 +6,17 @@ import { sendEvent } from '../send-event/sendEvent';
5
6
  import { ErrorMessages } from '../../consts';
6
7
  /**
7
8
  * A function that sends an IDENTITY event to SitecoreCloud API
9
+ *
8
10
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
9
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
10
- * This object will be flattened and sent in the ext object of the payload
11
11
  * @returns The response object that Sitecore EP returns
12
12
  */
13
- export async function identity(eventData, extensionData) {
13
+ export async function identity(identityData) {
14
14
  await awaitInit();
15
15
  const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
16
16
  const id = getBrowserId();
17
17
  return new IdentityEvent({
18
- eventData,
19
- extensionData,
20
18
  id,
19
+ identityData,
21
20
  sendEvent,
22
21
  settings,
23
22
  }).send();
@@ -1,13 +1,11 @@
1
- import { ExtensionData } from '../common-interfaces';
2
1
  import { Request } from '@sitecore-cloudsdk/utils';
3
2
  import { EPResponse } from '@sitecore-cloudsdk/core';
4
- import { IdentityEventAttributesInput } from './identity-event';
3
+ import { IdentityData } from './identity-event';
5
4
  /**
6
5
  * A function that sends an IDENTITY event to SitecoreCloud API
7
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
6
+ *
8
7
  * @param request - Interface with constraint for extending request
9
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
10
- * This object will be flattened and sent in the ext object of the payload
8
+ * @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
11
9
  * @returns The response object that Sitecore EP returns
12
10
  */
13
- export declare function identityServer(eventData: IdentityEventAttributesInput, request: Request, extensionData?: ExtensionData): Promise<EPResponse | null>;
11
+ export declare function identityServer(request: Request, identityData: IdentityData): Promise<EPResponse | null>;
@@ -5,19 +5,17 @@ import { sendEvent } from '../send-event/sendEvent';
5
5
  import { ErrorMessages } from '../../consts';
6
6
  /**
7
7
  * A function that sends an IDENTITY event to SitecoreCloud API
8
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
8
+ *
9
9
  * @param request - Interface with constraint for extending request
10
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
11
- * This object will be flattened and sent in the ext object of the payload
10
+ * @param identityData - The required/optional attributes in order to be send to SitecoreCloud API
12
11
  * @returns The response object that Sitecore EP returns
13
12
  */
14
- export function identityServer(eventData, request, extensionData) {
13
+ export function identityServer(request, identityData) {
15
14
  const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
16
15
  const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
17
16
  return new IdentityEvent({
18
- eventData,
19
- extensionData,
20
17
  id,
18
+ identityData,
21
19
  sendEvent,
22
20
  settings: settings,
23
21
  }).send();
@@ -1,9 +1,9 @@
1
1
  export { BaseEvent } from './base-event';
2
2
  export type { BasePayload } from './base-event';
3
3
  export { PageViewEvent } from './page-view/page-view-event';
4
- export type { PageViewEventInput, PageViewEventPayload } from './page-view/page-view-event';
4
+ export type { PageViewData, PageViewEventPayload } from './page-view/page-view-event';
5
5
  export { CustomEvent } from './custom-event/custom-event';
6
- export type { CustomEventInput, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
6
+ export type { EventData, CustomEventPayload, CustomEventArguments } from './custom-event/custom-event';
7
7
  export { IdentityEvent } from './identity/identity-event';
8
- export type { IdentityEventAttributesInput, IdentityEventPayload } from './identity/identity-event';
8
+ export type { IdentityData, IdentityEventPayload } from './identity/identity-event';
9
9
  export type { ExtensionData } from './common-interfaces';
@@ -1,12 +1,12 @@
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 { EventAttributesInput } from '../common-interfaces';
4
+ import { EventAttributesInput, ExtensionData } from '../common-interfaces';
5
5
  import { SendEvent } from '../send-event/sendEvent';
6
6
  export declare class PageViewEvent extends BaseEvent {
7
7
  static isFirstPageView: boolean;
8
8
  private sendEvent;
9
- private eventData;
9
+ private pageViewData;
10
10
  private extensionData;
11
11
  private urlSearchParams;
12
12
  private includeUTMParameters;
@@ -49,7 +49,7 @@ export declare class PageViewEvent extends BaseEvent {
49
49
  */
50
50
  export interface PageViewEventArguments {
51
51
  sendEvent: SendEvent;
52
- eventData: PageViewEventInput;
52
+ pageViewData: PageViewData;
53
53
  id: string;
54
54
  settings: Settings;
55
55
  infer?: Infer;
@@ -59,10 +59,11 @@ export interface PageViewEventArguments {
59
59
  /**
60
60
  * Type with the required/optional attributes in order to send a view event to SitecoreCloud API
61
61
  */
62
- export interface PageViewEventInput extends EventAttributesInput {
62
+ export interface PageViewData extends EventAttributesInput {
63
63
  pageVariantId?: string;
64
64
  referrer?: string;
65
65
  includeUTMParameters?: boolean;
66
+ extensionData?: ExtensionData;
66
67
  }
67
68
  /**
68
69
  * Interface with the utm_ parameters
@@ -8,7 +8,7 @@ export class PageViewEvent extends BaseEvent {
8
8
  * @param args - Unified object containing the required properties
9
9
  */
10
10
  constructor(args) {
11
- const { channel, currency, language, page } = args.eventData;
11
+ const { channel, currency, language, page, extensionData } = args.pageViewData;
12
12
  super({
13
13
  channel,
14
14
  currency,
@@ -16,26 +16,26 @@ export class PageViewEvent extends BaseEvent {
16
16
  page,
17
17
  }, args.id);
18
18
  this.extensionData = {};
19
- this.eventData = args.eventData;
19
+ this.pageViewData = args.pageViewData;
20
20
  this.sendEvent = args.sendEvent;
21
21
  this.settings = args.settings;
22
22
  this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
23
- if (args.extensionData)
24
- this.extensionData = flattenObject({ object: args.extensionData });
23
+ if (extensionData)
24
+ this.extensionData = flattenObject({ object: extensionData });
25
25
  const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
26
26
  if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
27
27
  throw new Error(ErrorMessages.IV_0005);
28
28
  this.includeUTMParameters =
29
- args.eventData.includeUTMParameters === undefined ? true : args.eventData.includeUTMParameters;
29
+ args.pageViewData.includeUTMParameters === undefined ? true : args.pageViewData.includeUTMParameters;
30
30
  }
31
31
  /**
32
32
  * Gets the variant ID from the url if not passed by the developer
33
33
  * Gets the variant ID from the extension data if not found from the url
34
34
  * @returns - variant ID or null
35
35
  */
36
- getPageVariantId(pageVariantIdFromEventData, pageVariantIdFromExt) {
37
- if (pageVariantIdFromEventData)
38
- return pageVariantIdFromEventData;
36
+ getPageVariantId(pageVariantIdFromPageViewData, pageVariantIdFromExt) {
37
+ if (pageVariantIdFromPageViewData)
38
+ return pageVariantIdFromPageViewData;
39
39
  const pageVariantIdFromURL = this.urlSearchParams.get('variantid');
40
40
  if (pageVariantIdFromURL)
41
41
  return pageVariantIdFromURL;
@@ -49,8 +49,8 @@ export class PageViewEvent extends BaseEvent {
49
49
  * @returns - the referrer
50
50
  */
51
51
  getReferrer() {
52
- if (this.eventData.referrer)
53
- return this.eventData.referrer;
52
+ if (this.pageViewData.referrer)
53
+ return this.pageViewData.referrer;
54
54
  if (typeof window === 'undefined')
55
55
  return null;
56
56
  if (!PageViewEvent.isFirstPageView || !document.referrer)
@@ -66,7 +66,7 @@ export class PageViewEvent extends BaseEvent {
66
66
  let viewPayload = {
67
67
  type: 'VIEW',
68
68
  };
69
- const pageVariantId = this.getPageVariantId(this.eventData.pageVariantId, this.extensionData['pageVariantId']);
69
+ const pageVariantId = this.getPageVariantId(this.pageViewData.pageVariantId, this.extensionData['pageVariantId']);
70
70
  if (pageVariantId !== null)
71
71
  viewPayload.ext = { ...viewPayload.ext, pageVariantId };
72
72
  if (Object.keys(this.extensionData).length > 0) {
@@ -1,12 +1,11 @@
1
1
  import { EPResponse } from '@sitecore-cloudsdk/core';
2
- import { NestedObject, Request } from '@sitecore-cloudsdk/utils';
3
- import { PageViewEventInput } from './page-view-event';
2
+ import { Request } from '@sitecore-cloudsdk/utils';
3
+ import { PageViewData } from './page-view-event';
4
4
  /**
5
5
  * A function that sends a VIEW event to SitecoreCloud API
6
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
6
+ *
7
7
  * @param request - Interface with constraint for extending request
8
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
9
- * This object will be flattened and sent in the ext object of the payload
8
+ * @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
10
9
  * @returns The response object that Sitecore EP returns
11
10
  */
12
- export declare function pageViewServer<T extends Request>(eventData: PageViewEventInput, request: T, extensionData?: NestedObject): Promise<EPResponse | null>;
11
+ export declare function pageViewServer<T extends Request>(request: T, pageViewData: PageViewData): Promise<EPResponse | null>;
@@ -5,21 +5,19 @@ import { sendEvent } from '../send-event/sendEvent';
5
5
  import { ErrorMessages } from '../../consts';
6
6
  /**
7
7
  * A function that sends a VIEW event to SitecoreCloud API
8
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
8
+ *
9
9
  * @param request - Interface with constraint for extending request
10
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
11
- * This object will be flattened and sent in the ext object of the payload
10
+ * @param pageViewData - The required/optional attributes in order to be send to SitecoreCloud API
12
11
  * @returns The response object that Sitecore EP returns
13
12
  */
14
- export function pageViewServer(eventData, request, extensionData) {
13
+ export function pageViewServer(request, pageViewData) {
15
14
  const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
16
15
  const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
17
16
  // Host is irrelevant but necessary to support relative URL
18
17
  const requestUrl = new URL(request.url, `https://localhost`);
19
18
  return new PageViewEvent({
20
- eventData,
21
- extensionData,
22
19
  id,
20
+ pageViewData,
23
21
  searchParams: requestUrl.search,
24
22
  sendEvent,
25
23
  settings,