@sitecore-cloudsdk/events 0.2.4 → 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
package/README.md CHANGED
@@ -56,16 +56,7 @@ export default function Home() {
56
56
  };
57
57
 
58
58
  const sendPageViewEvent = async () => {
59
- let eventData: any = {
60
- channel: 'WEB',
61
- currency: 'EUR',
62
- };
63
-
64
- let extensionData: any = {
65
- customKey: 'customValue',
66
- };
67
-
68
- await pageView(eventData, extensionData);
59
+ await pageView();
69
60
 
70
61
  console.log('Sent VIEW event.');
71
62
  };
@@ -88,28 +79,15 @@ import { init, pageView } from '@sitecore-cloudsdk/events/server';
88
79
  export async function middleware(req: NextRequest) {
89
80
  const res = NextResponse.next();
90
81
 
91
- await init(
92
- {
93
- sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
94
- siteName: process.env.NEXT_PUBLIC_SITENAME || '',
95
- enableServerCookie: true,
96
- },
97
- req,
98
- res
99
- );
82
+ await init(req, res, {
83
+ sitecoreEdgeContextId: process.env.NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID || '',
84
+ siteName: process.env.NEXT_PUBLIC_SITENAME || '',
85
+ enableServerCookie: true,
86
+ });
100
87
 
101
88
  console.log(`Initialized "@sitecore-cloudsdk/events/server".`);
102
89
 
103
- let eventData: any = {
104
- channel: 'WEB',
105
- currency: 'EUR',
106
- };
107
-
108
- let extensionData: any = {
109
- customKey: 'customValue',
110
- };
111
-
112
- const pageViewRes = await pageView(eventData, req, extensionData);
90
+ const pageViewRes = await pageView(req);
113
91
 
114
92
  console.log('Sent VIEW event.');
115
93
 
@@ -119,4 +97,4 @@ export async function middleware(req: NextRequest) {
119
97
 
120
98
  ## Documentation
121
99
 
122
- [Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html)
100
+ [Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html)
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@sitecore-cloudsdk/events",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
- "homepage": "https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-cloud-sdk.html",
5
+ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html",
6
6
  "exports": {
7
7
  "./server": {
8
8
  "import": "./server.js",
@@ -16,8 +16,8 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@sitecore-cloudsdk/core": "^0.2.4",
20
- "@sitecore-cloudsdk/utils": "^0.2.4"
19
+ "@sitecore-cloudsdk/core": "^0.3.0",
20
+ "@sitecore-cloudsdk/utils": "^0.3.0"
21
21
  },
22
22
  "scripts": {
23
23
  "build": "npm run build:cjs && npm run build:es",
@@ -35,7 +35,6 @@
35
35
  "server.d.ts"
36
36
  ],
37
37
  "engines": {
38
- "node": ">=18",
39
- "npm": ">=9"
38
+ "node": ">=18"
40
39
  }
41
40
  }
@@ -1,6 +1,6 @@
1
1
  export { getBrowserId } from '@sitecore-cloudsdk/core';
2
2
  export { init } from './lib/initializer/browser/initializer';
3
- export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
3
+ export type { PageViewData, EventData, IdentityData } from './lib/events';
4
4
  export { addToEventQueue } from './lib/eventStorage/addToEventQueue';
5
5
  export { processEventQueue } from './lib/eventStorage/processEventQueue';
6
6
  export { clearEventQueue } from './lib/eventStorage/clearEventQueue';
@@ -9,7 +9,7 @@ export declare enum ErrorMessages {
9
9
  IV_0002 = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.",
10
10
  IV_0003 = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.",
11
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.",
12
+ IV_0005 = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.",
13
13
  MV_0003 = "[MV-0003] \"identifiers\" is required."
14
14
  }
15
15
  export declare const EVENTS_NAMESPACE = "sitecore-cloudsdk:events";
@@ -20,7 +20,7 @@ var ErrorMessages;
20
20
  ErrorMessages["IV_0002"] = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.";
21
21
  ErrorMessages["IV_0003"] = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.";
22
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.";
23
+ ErrorMessages["IV_0005"] = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.";
24
24
  ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
25
25
  })(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
26
26
  exports.EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';
@@ -1,9 +1,7 @@
1
- import { CustomEventInput, ExtensionData } from '../events';
1
+ import { EventData } from '../events';
2
2
  /**
3
3
  * A function that adds event to the queue
4
- * @param type - The required type of the event
4
+ *
5
5
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
6
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
7
- * This object will be flattened and sent in the ext object of the payload
8
6
  */
9
- export declare function addToEventQueue(type: string, eventData: CustomEventInput, extensionData?: ExtensionData): Promise<void>;
7
+ export declare function addToEventQueue(eventData: EventData): Promise<void>;
@@ -8,21 +8,17 @@ const core_1 = require("@sitecore-cloudsdk/core");
8
8
  const consts_1 = require("../consts");
9
9
  /**
10
10
  * A function that adds event to the queue
11
- * @param type - The required type of the event
11
+ *
12
12
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
13
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
14
- * This object will be flattened and sent in the ext object of the payload
15
13
  */
16
- async function addToEventQueue(type, eventData, extensionData) {
14
+ async function addToEventQueue(eventData) {
17
15
  await (0, initializer_1.awaitInit)();
18
16
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
19
17
  const id = (0, core_1.getBrowserId)();
20
18
  const queueEventPayload = {
21
19
  eventData,
22
- extensionData,
23
20
  id,
24
21
  settings,
25
- type,
26
22
  };
27
23
  eventStorage_1.eventQueue.enqueueEvent(queueEventPayload);
28
24
  }
@@ -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 {};
@@ -49,11 +49,9 @@ class EventQueue {
49
49
  for (const queueEventPayload of eventQueue) {
50
50
  await new events_1.CustomEvent({
51
51
  eventData: queueEventPayload.eventData,
52
- extensionData: queueEventPayload.extensionData,
53
52
  id: queueEventPayload.id,
54
53
  sendEvent: sendEvent_1.sendEvent,
55
54
  settings: queueEventPayload.settings,
56
- type: queueEventPayload.type,
57
55
  }).send();
58
56
  }
59
57
  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 {};
@@ -12,17 +12,17 @@ class CustomEvent extends base_event_1.BaseEvent {
12
12
  * @param args - Unified object containing the required properties
13
13
  */
14
14
  constructor(args) {
15
- const { channel, currency, language, page, ...rest } = args.eventData;
15
+ const { channel, currency, language, page, type, extensionData, ...rest } = args.eventData;
16
16
  super({ channel, currency, language, page }, args.id);
17
17
  this.extensionData = {};
18
18
  this.sendEvent = args.sendEvent;
19
19
  this.settings = args.settings;
20
20
  this.customEventPayload = {
21
- type: args.type,
21
+ type,
22
22
  ...rest,
23
23
  };
24
- if (args.extensionData)
25
- this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
24
+ if (extensionData)
25
+ this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
26
26
  const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
27
27
  if (numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
28
28
  throw new Error(consts_2.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>;
@@ -9,23 +9,19 @@ const sendEvent_1 = require("../send-event/sendEvent");
9
9
  const consts_1 = require("../../consts");
10
10
  /**
11
11
  * A function that sends an event to SitecoreCloud API with the specified type
12
- * @param type - The required type of the event
12
+ *
13
13
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
14
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
15
- * This object will be flattened and sent in the ext object of the payload
16
14
  * @returns The response object that Sitecore EP returns
17
15
  */
18
- async function event(type, eventData, extensionData) {
16
+ async function event(eventData) {
19
17
  await (0, initializer_1.awaitInit)();
20
18
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
21
19
  const id = (0, core_1.getBrowserId)();
22
20
  return new custom_event_1.CustomEvent({
23
21
  eventData,
24
- extensionData,
25
22
  id,
26
23
  sendEvent: sendEvent_1.sendEvent,
27
24
  settings,
28
- type,
29
25
  }).send();
30
26
  }
31
27
  exports.event = event;
@@ -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>;
@@ -8,22 +8,19 @@ const sendEvent_1 = require("../send-event/sendEvent");
8
8
  const consts_1 = require("../../consts");
9
9
  /**
10
10
  * A function that sends an event to SitecoreCloud API with the specified type
11
- * @param type - The required type of the event
12
- * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
11
+ *
13
12
  * @param request - Interface with constraint for extending request
14
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
13
+ * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
15
14
  * @returns The response object that Sitecore EP returns
16
15
  */
17
- function eventServer(type, eventData, request, extensionData) {
16
+ function eventServer(request, eventData) {
18
17
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
19
18
  const id = (0, core_1.getBrowserIdFromRequest)(request, settings.cookieSettings.cookieName);
20
19
  return new custom_event_1.CustomEvent({
21
20
  eventData,
22
- extensionData,
23
21
  id,
24
22
  sendEvent: sendEvent_1.sendEvent,
25
23
  settings,
26
- type,
27
24
  }).send();
28
25
  }
29
26
  exports.eventServer = eventServer;
@@ -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
@@ -9,6 +9,7 @@ const initializer_1 = require("../../initializer/browser/initializer");
9
9
  const consts_1 = require("../../consts");
10
10
  /**
11
11
  * A function that sends a form event to SitecoreCloud API
12
+ *
12
13
  * @param formId - The required form ID string
13
14
  * @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"
14
15
  * settings object, you must specify it here
@@ -19,15 +20,16 @@ async function form(formId, interactionType) {
19
20
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
20
21
  const id = (0, core_1.getBrowserId)();
21
22
  const formEvent = new custom_event_1.CustomEvent({
22
- eventData: {},
23
- extensionData: {
24
- formId,
25
- interactionType: interactionType.toUpperCase(),
23
+ eventData: {
24
+ extensionData: {
25
+ formId,
26
+ interactionType: interactionType.toUpperCase(),
27
+ },
28
+ type: 'FORM',
26
29
  },
27
30
  id,
28
31
  sendEvent: sendEvent_1.sendEvent,
29
32
  settings,
30
- type: 'FORM',
31
33
  });
32
34
  formEvent.page = undefined;
33
35
  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;
@@ -9,37 +9,38 @@ const consts_2 = require("../../consts");
9
9
  class IdentityEvent extends base_event_1.BaseEvent {
10
10
  /**
11
11
  * A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
12
+ *
12
13
  * @param args - Unified object containing the required properties
13
14
  */
14
15
  constructor(args) {
15
- const { channel, currency, language, page } = args.eventData;
16
+ const { channel, currency, language, page, extensionData } = args.identityData;
16
17
  super({ channel, currency, language, page }, args.id);
17
18
  this.extensionData = {};
18
19
  this.numberOfExtensionDataProperties = 0;
19
- this.validateAttributes(args.eventData);
20
- this.eventData = args.eventData;
20
+ this.validateAttributes(args.identityData);
21
+ this.identityData = args.identityData;
21
22
  this.sendEvent = args.sendEvent;
22
23
  this.settings = args.settings;
23
- if (args.extensionData)
24
- this.extensionData = (0, utils_1.flattenObject)({ object: args.extensionData });
24
+ if (extensionData)
25
+ this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
25
26
  this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
26
27
  if (this.numberOfExtensionDataProperties > consts_1.MAX_EXT_ATTRIBUTES)
27
28
  throw new Error(consts_2.ErrorMessages.IV_0005);
28
29
  }
29
30
  /**
30
31
  * Function that validates the identifiers object, email and date attributes for CDN users
31
- * * @param eventData - The data to be validated
32
+ * * @param identityData - The data to be validated
32
33
  */
33
- validateAttributes(eventData) {
34
- if (eventData.identifiers.length === 0)
34
+ validateAttributes(identityData) {
35
+ if (identityData.identifiers.length === 0)
35
36
  throw new Error(consts_2.ErrorMessages.MV_0003);
36
- if (eventData.dob !== undefined && !(0, utils_1.isShortISODateString)(eventData.dob))
37
+ if (identityData.dob !== undefined && !(0, utils_1.isShortISODateString)(identityData.dob))
37
38
  throw new Error(consts_2.ErrorMessages.IV_0002);
38
- eventData.identifiers.forEach((identifier) => {
39
+ identityData.identifiers.forEach((identifier) => {
39
40
  if (identifier.expiryDate && !(0, utils_1.isShortISODateString)(identifier.expiryDate))
40
41
  throw new Error(consts_2.ErrorMessages.IV_0004);
41
42
  });
42
- if (eventData.email && !(0, utils_1.isValidEmail)(eventData.email))
43
+ if (identityData.email && !(0, utils_1.isValidEmail)(identityData.email))
43
44
  throw new Error(consts_2.ErrorMessages.IV_0003);
44
45
  }
45
46
  /**
@@ -48,13 +49,13 @@ class IdentityEvent extends base_event_1.BaseEvent {
48
49
  */
49
50
  mapAttributes() {
50
51
  const identityPayload = {
51
- city: this.eventData.city,
52
- country: this.eventData.country,
53
- dob: this.eventData.dob,
54
- email: this.eventData.email,
55
- firstname: this.eventData.firstName,
56
- gender: this.eventData.gender,
57
- identifiers: this.eventData.identifiers.map((value) => {
52
+ city: this.identityData.city,
53
+ country: this.identityData.country,
54
+ dob: this.identityData.dob,
55
+ email: this.identityData.email,
56
+ firstname: this.identityData.firstName,
57
+ gender: this.identityData.gender,
58
+ identifiers: this.identityData.identifiers.map((value) => {
58
59
  return {
59
60
  // eslint-disable-next-line @typescript-eslint/naming-convention
60
61
  expiry_date: value.expiryDate,
@@ -62,14 +63,14 @@ class IdentityEvent extends base_event_1.BaseEvent {
62
63
  provider: value.provider,
63
64
  };
64
65
  }),
65
- lastname: this.eventData.lastName,
66
- mobile: this.eventData.mobile,
67
- phone: this.eventData.phone,
66
+ lastname: this.identityData.lastName,
67
+ mobile: this.identityData.mobile,
68
+ phone: this.identityData.phone,
68
69
  // eslint-disable-next-line @typescript-eslint/naming-convention
69
- postal_code: this.eventData.postalCode,
70
- state: this.eventData.state,
71
- street: this.eventData.street,
72
- title: this.eventData.title,
70
+ postal_code: this.identityData.postalCode,
71
+ state: this.identityData.state,
72
+ street: this.identityData.street,
73
+ title: this.identityData.title,
73
74
  type: 'IDENTITY',
74
75
  };
75
76
  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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.identity = void 0;
4
+ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
4
5
  const core_1 = require("@sitecore-cloudsdk/core");
5
6
  const identity_event_1 = require("./identity-event");
6
7
  const initializer_1 = require("../../initializer/browser/initializer");
@@ -8,19 +9,17 @@ const sendEvent_1 = require("../send-event/sendEvent");
8
9
  const consts_1 = require("../../consts");
9
10
  /**
10
11
  * A function that sends an IDENTITY event to SitecoreCloud API
12
+ *
11
13
  * @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
12
- * @param extensionData - The optional extensionData attributes that will be sent to SitecoreCloud API.
13
- * This object will be flattened and sent in the ext object of the payload
14
14
  * @returns The response object that Sitecore EP returns
15
15
  */
16
- async function identity(eventData, extensionData) {
16
+ async function identity(identityData) {
17
17
  await (0, initializer_1.awaitInit)();
18
18
  const settings = (0, core_1.handleGetSettingsError)(core_1.getSettings, consts_1.ErrorMessages.IE_0004);
19
19
  const id = (0, core_1.getBrowserId)();
20
20
  return new identity_event_1.IdentityEvent({
21
- eventData,
22
- extensionData,
23
21
  id,
22
+ identityData,
24
23
  sendEvent: sendEvent_1.sendEvent,
25
24
  settings,
26
25
  }).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>;