@sitecore-cloudsdk/events 0.2.4 → 0.3.1-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -30
- package/dist/cjs/package.json +5 -6
- package/dist/cjs/src/browser.d.ts +1 -1
- package/dist/cjs/src/lib/consts.d.ts +5 -1
- package/dist/cjs/src/lib/consts.js +9 -3
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +5 -9
- package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +2 -2
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +3 -6
- package/dist/cjs/src/lib/events/base-event.d.ts +3 -2
- package/dist/cjs/src/lib/events/base-event.js +3 -2
- package/dist/cjs/src/lib/events/common-interfaces.d.ts +4 -21
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +15 -14
- package/dist/cjs/src/lib/events/custom-event/custom-event.js +17 -10
- package/dist/cjs/src/lib/events/custom-event/event.d.ts +4 -7
- package/dist/cjs/src/lib/events/custom-event/event.js +4 -8
- package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +6 -8
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +6 -9
- package/dist/cjs/src/lib/events/custom-event/form.d.ts +2 -1
- package/dist/cjs/src/lib/events/custom-event/form.js +10 -8
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +10 -9
- package/dist/cjs/src/lib/events/identity/identity-event.js +37 -37
- package/dist/cjs/src/lib/events/identity/identity.d.ts +4 -6
- package/dist/cjs/src/lib/events/identity/identity.js +6 -7
- package/dist/cjs/src/lib/events/identity/identityServer.d.ts +6 -8
- package/dist/cjs/src/lib/events/identity/identityServer.js +7 -9
- package/dist/cjs/src/lib/events/index.d.ts +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +15 -7
- package/dist/cjs/src/lib/events/page-view/page-view-event.js +31 -24
- package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +6 -7
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +7 -9
- package/dist/cjs/src/lib/events/page-view/page-view.d.ts +5 -6
- package/dist/cjs/src/lib/events/page-view/page-view.js +6 -7
- package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +2 -2
- package/dist/cjs/src/lib/events/send-event/sendEvent.js +12 -7
- package/dist/cjs/src/lib/getGuestId/getGuestId.js +1 -1
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +15 -3
- package/dist/cjs/src/lib/initializer/browser/initializer.js +6 -6
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +5 -3
- package/dist/cjs/src/lib/initializer/server/initializer.js +4 -3
- package/dist/cjs/src/server.d.ts +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +5 -6
- package/dist/esm/src/browser.d.ts +1 -1
- package/dist/esm/src/lib/consts.d.ts +5 -1
- package/dist/esm/src/lib/consts.js +8 -2
- package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +3 -5
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +5 -9
- package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +2 -2
- package/dist/esm/src/lib/eventStorage/eventStorage.js +4 -7
- package/dist/esm/src/lib/events/base-event.d.ts +3 -2
- package/dist/esm/src/lib/events/base-event.js +3 -2
- package/dist/esm/src/lib/events/common-interfaces.d.ts +4 -21
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +15 -14
- package/dist/esm/src/lib/events/custom-event/custom-event.js +15 -8
- package/dist/esm/src/lib/events/custom-event/event.d.ts +4 -7
- package/dist/esm/src/lib/events/custom-event/event.js +4 -8
- package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +6 -8
- package/dist/esm/src/lib/events/custom-event/eventServer.js +7 -10
- package/dist/esm/src/lib/events/custom-event/form.d.ts +2 -1
- package/dist/esm/src/lib/events/custom-event/form.js +10 -8
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +10 -9
- package/dist/esm/src/lib/events/identity/identity-event.js +30 -30
- package/dist/esm/src/lib/events/identity/identity.d.ts +4 -6
- package/dist/esm/src/lib/events/identity/identity.js +6 -7
- package/dist/esm/src/lib/events/identity/identityServer.d.ts +6 -8
- package/dist/esm/src/lib/events/identity/identityServer.js +8 -10
- package/dist/esm/src/lib/events/index.d.ts +3 -3
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +15 -7
- package/dist/esm/src/lib/events/page-view/page-view-event.js +31 -24
- package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +6 -7
- package/dist/esm/src/lib/events/page-view/page-view-server.js +8 -10
- package/dist/esm/src/lib/events/page-view/page-view.d.ts +5 -6
- package/dist/esm/src/lib/events/page-view/page-view.js +6 -7
- package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +2 -2
- package/dist/esm/src/lib/events/send-event/sendEvent.js +13 -8
- package/dist/esm/src/lib/getGuestId/getGuestId.js +1 -1
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +15 -3
- package/dist/esm/src/lib/initializer/browser/initializer.js +7 -7
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +5 -3
- package/dist/esm/src/lib/initializer/server/initializer.js +5 -4
- package/dist/esm/src/server.d.ts +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- 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
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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/
|
|
100
|
+
[Official Sitecore Cloud SDK documentation](https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html)
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-cloudsdk/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1-rc.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"homepage": "https://doc.sitecore.com/xmc/en/developers/
|
|
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.
|
|
20
|
-
"@sitecore-cloudsdk/utils": "^0.
|
|
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 {
|
|
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';
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Returns the version of the library.
|
|
3
3
|
*/
|
|
4
4
|
export declare const LIBRARY_VERSION: string;
|
|
5
|
+
/**
|
|
6
|
+
* Returns the name & version of the library in a String.
|
|
7
|
+
*/
|
|
8
|
+
export declare const X_CLIENT_SOFTWARE_ID: string;
|
|
5
9
|
export declare enum ErrorMessages {
|
|
6
10
|
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
11
|
IE_0004 = "[IE-0004] You must first initialize the \"events/browser\" module. Run the \"init\" function.",
|
|
@@ -9,7 +13,7 @@ export declare enum ErrorMessages {
|
|
|
9
13
|
IV_0002 = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.",
|
|
10
14
|
IV_0003 = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.",
|
|
11
15
|
IV_0004 = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.",
|
|
12
|
-
IV_0005 = "[IV-0005]
|
|
16
|
+
IV_0005 = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.",
|
|
13
17
|
MV_0003 = "[MV-0003] \"identifiers\" is required."
|
|
14
18
|
}
|
|
15
19
|
export declare const EVENTS_NAMESPACE = "sitecore-cloudsdk:events";
|
|
@@ -3,15 +3,20 @@ 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.EVENTS_NAMESPACE = exports.ErrorMessages = exports.LIBRARY_VERSION = void 0;
|
|
6
|
+
exports.EVENTS_NAMESPACE = exports.ErrorMessages = exports.X_CLIENT_SOFTWARE_ID = 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
|
-
const package_json_1 = __importDefault(require("../../package.json"));
|
|
10
9
|
const consts_1 = require("./events/consts");
|
|
10
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
11
11
|
/**
|
|
12
12
|
* Returns the version of the library.
|
|
13
13
|
*/
|
|
14
14
|
exports.LIBRARY_VERSION = package_json_1.default.version;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the name & version of the library in a String.
|
|
17
|
+
*/
|
|
18
|
+
exports.X_CLIENT_SOFTWARE_ID = `${package_json_1.default.name} ${exports.LIBRARY_VERSION}`;
|
|
19
|
+
/* eslint-disable max-len */
|
|
15
20
|
var ErrorMessages;
|
|
16
21
|
(function (ErrorMessages) {
|
|
17
22
|
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.";
|
|
@@ -20,7 +25,8 @@ var ErrorMessages;
|
|
|
20
25
|
ErrorMessages["IV_0002"] = "[IV-0002] Incorrect value for \"dob\". Format the value according to ISO 8601.";
|
|
21
26
|
ErrorMessages["IV_0003"] = "[IV-0003] Incorrect value for \"email\". Set the value to a valid email address.";
|
|
22
27
|
ErrorMessages["IV_0004"] = "[IV-0004] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
|
|
23
|
-
ErrorMessages["IV_0005"] = "[IV-0005]
|
|
28
|
+
ErrorMessages["IV_0005"] = "[IV-0005] \"extensionData\" supports maximum 50 attributes. Reduce the number of attributes.";
|
|
24
29
|
ErrorMessages["MV_0003"] = "[MV-0003] \"identifiers\" is required.";
|
|
25
30
|
})(ErrorMessages || (exports.ErrorMessages = ErrorMessages = {}));
|
|
31
|
+
/* eslint-enable max-len */
|
|
26
32
|
exports.EVENTS_NAMESPACE = 'sitecore-cloudsdk:events';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { EventData } from '../events';
|
|
2
2
|
/**
|
|
3
3
|
* A function that adds event to the queue
|
|
4
|
-
*
|
|
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(
|
|
7
|
+
export declare function addToEventQueue(eventData: EventData): Promise<void>;
|
|
@@ -2,27 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addToEventQueue = void 0;
|
|
4
4
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
|
-
const initializer_1 = require("../initializer/browser/initializer");
|
|
6
|
-
const eventStorage_1 = require("./eventStorage");
|
|
7
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
8
6
|
const consts_1 = require("../consts");
|
|
7
|
+
const initializer_1 = require("../initializer/browser/initializer");
|
|
8
|
+
const eventStorage_1 = require("./eventStorage");
|
|
9
9
|
/**
|
|
10
10
|
* A function that adds event to the queue
|
|
11
|
-
*
|
|
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(
|
|
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
|
-
settings
|
|
25
|
-
type,
|
|
21
|
+
settings
|
|
26
22
|
};
|
|
27
23
|
eventStorage_1.eventQueue.enqueueEvent(queueEventPayload);
|
|
28
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CustomEventArguments } from '../events';
|
|
1
|
+
import type { CustomEventArguments } from '../events';
|
|
2
2
|
declare class EventQueue {
|
|
3
3
|
/**
|
|
4
4
|
* Initialize the Event Storage
|
|
@@ -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' | '
|
|
33
|
+
export type QueueEventPayload = Pick<CustomEventArguments, 'eventData' | 'settings' | 'id'>;
|
|
34
34
|
export declare const eventQueue: EventQueue;
|
|
35
35
|
export {};
|
|
@@ -35,7 +35,7 @@ class EventQueue {
|
|
|
35
35
|
queueEventPayload.eventData.language = queueEventPayload.eventData.language ?? (0, core_1.language)();
|
|
36
36
|
new events_1.CustomEvent({
|
|
37
37
|
sendEvent: sendEvent_1.sendEvent,
|
|
38
|
-
...queueEventPayload
|
|
38
|
+
...queueEventPayload
|
|
39
39
|
});
|
|
40
40
|
const eventQueue = this.getEventQueue();
|
|
41
41
|
eventQueue.push(queueEventPayload);
|
|
@@ -46,16 +46,13 @@ class EventQueue {
|
|
|
46
46
|
*/
|
|
47
47
|
async sendAllEvents() {
|
|
48
48
|
const eventQueue = this.getEventQueue();
|
|
49
|
-
for (const queueEventPayload of eventQueue)
|
|
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
|
-
settings: queueEventPayload.settings
|
|
56
|
-
type: queueEventPayload.type,
|
|
54
|
+
settings: queueEventPayload.settings
|
|
57
55
|
}).send();
|
|
58
|
-
}
|
|
59
56
|
this.clearQueue();
|
|
60
57
|
}
|
|
61
58
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventAttributesInput } from './common-interfaces';
|
|
1
|
+
import type { EventAttributesInput } from './common-interfaces';
|
|
2
2
|
export declare class BaseEvent {
|
|
3
3
|
private baseEventData;
|
|
4
4
|
private readonly browserId;
|
|
@@ -29,6 +29,7 @@ export interface BasePayload {
|
|
|
29
29
|
language?: string;
|
|
30
30
|
page?: string;
|
|
31
31
|
pos: string;
|
|
32
|
+
requested_at: string;
|
|
32
33
|
}
|
|
33
|
-
type BaseEventData =
|
|
34
|
+
type BaseEventData = EventAttributesInput;
|
|
34
35
|
export {};
|
|
@@ -23,15 +23,16 @@ class BaseEvent {
|
|
|
23
23
|
*/
|
|
24
24
|
mapBaseEventPayload() {
|
|
25
25
|
return {
|
|
26
|
-
|
|
26
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
27
27
|
browser_id: this.browserId,
|
|
28
28
|
channel: this.baseEventData.channel,
|
|
29
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
30
29
|
client_key: '',
|
|
31
30
|
currency: this.baseEventData.currency,
|
|
32
31
|
language: this.language,
|
|
33
32
|
page: this.page,
|
|
34
33
|
pos: '',
|
|
34
|
+
requested_at: new Date().toISOString()
|
|
35
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
}
|
|
@@ -1,31 +1,14 @@
|
|
|
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;
|
|
1
|
+
import type { NestedObject } from '@sitecore-cloudsdk/utils';
|
|
10
2
|
/**
|
|
11
3
|
* Event data that is sent to Sitecore EP
|
|
12
4
|
*/
|
|
13
|
-
interface
|
|
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
|
-
|
|
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,8 +1,8 @@
|
|
|
1
|
+
import type { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
1
4
|
import { BaseEvent } from '../base-event';
|
|
2
|
-
import {
|
|
3
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
4
|
-
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
-
import { BasicTypes, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import type { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class CustomEvent extends BaseEvent {
|
|
7
7
|
customEventPayload: CustomEventPayload;
|
|
8
8
|
private sendEvent;
|
|
@@ -24,16 +24,20 @@ export declare class CustomEvent extends BaseEvent {
|
|
|
24
24
|
*/
|
|
25
25
|
export interface CustomEventArguments {
|
|
26
26
|
sendEvent: SendEvent;
|
|
27
|
-
eventData:
|
|
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
|
|
35
33
|
*/
|
|
36
34
|
export interface CustomEventPayload extends NestedObject {
|
|
35
|
+
sc_search?: {
|
|
36
|
+
data: NestedObject;
|
|
37
|
+
metadata: {
|
|
38
|
+
ut_api_version: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
37
41
|
ext?: {
|
|
38
42
|
[key: string]: BasicTypes;
|
|
39
43
|
};
|
|
@@ -41,11 +45,8 @@ export interface CustomEventPayload extends NestedObject {
|
|
|
41
45
|
/**
|
|
42
46
|
* Interface with the required/optional attributes in order to send a custom event to SitecoreCloud API
|
|
43
47
|
*/
|
|
44
|
-
export interface
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
49
|
-
interface CustomEventData extends Partial<EventAttributesInput>, NestedObject {
|
|
48
|
+
export interface EventData extends EventAttributesInput, NestedObject {
|
|
49
|
+
type: string;
|
|
50
|
+
searchData?: NestedObject;
|
|
51
|
+
extensionData?: ExtensionData;
|
|
50
52
|
}
|
|
51
|
-
export {};
|
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomEvent = void 0;
|
|
4
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
5
4
|
const base_event_1 = require("../base-event");
|
|
5
|
+
const consts_1 = require("../../consts");
|
|
6
|
+
const consts_2 = require("../consts");
|
|
6
7
|
const utils_1 = require("@sitecore-cloudsdk/utils");
|
|
7
|
-
const consts_1 = require("../consts");
|
|
8
|
-
const consts_2 = require("../../consts");
|
|
9
8
|
class CustomEvent extends base_event_1.BaseEvent {
|
|
10
9
|
/**
|
|
11
10
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
12
11
|
* @param args - Unified object containing the required properties
|
|
13
12
|
*/
|
|
14
13
|
constructor(args) {
|
|
15
|
-
const { channel, currency, language, page, ...rest } = args.eventData;
|
|
14
|
+
const { channel, currency, language, page, type, extensionData, searchData, ...rest } = args.eventData;
|
|
16
15
|
super({ channel, currency, language, page }, args.id);
|
|
17
16
|
this.extensionData = {};
|
|
18
17
|
this.sendEvent = args.sendEvent;
|
|
19
18
|
this.settings = args.settings;
|
|
20
19
|
this.customEventPayload = {
|
|
21
|
-
type
|
|
22
|
-
...rest
|
|
20
|
+
type,
|
|
21
|
+
...rest
|
|
23
22
|
};
|
|
24
|
-
if (
|
|
25
|
-
this.extensionData = (0, utils_1.flattenObject)({ object:
|
|
23
|
+
if (extensionData)
|
|
24
|
+
this.extensionData = (0, utils_1.flattenObject)({ object: extensionData });
|
|
26
25
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
27
|
-
if (numberOfExtensionDataProperties >
|
|
28
|
-
throw new Error(
|
|
26
|
+
if (numberOfExtensionDataProperties > consts_2.MAX_EXT_ATTRIBUTES)
|
|
27
|
+
throw new Error(consts_1.ErrorMessages.IV_0005);
|
|
29
28
|
if (numberOfExtensionDataProperties > 0)
|
|
30
29
|
this.customEventPayload.ext = this.extensionData;
|
|
30
|
+
if (searchData)
|
|
31
|
+
this.customEventPayload.sc_search = {
|
|
32
|
+
data: searchData,
|
|
33
|
+
metadata: {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
35
|
+
ut_api_version: '1.0'
|
|
36
|
+
}
|
|
37
|
+
};
|
|
31
38
|
}
|
|
32
39
|
/**
|
|
33
40
|
* Sends the event to Sitecore EP
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
3
|
-
import { CustomEventInput } from './custom-event';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventData } from './custom-event';
|
|
4
3
|
/**
|
|
5
4
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
6
|
-
*
|
|
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(
|
|
9
|
+
export declare function event(eventData: EventData): Promise<EPResponse | null>;
|
|
@@ -4,28 +4,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.event = void 0;
|
|
5
5
|
const core_1 = require("@sitecore-cloudsdk/core");
|
|
6
6
|
const custom_event_1 = require("./custom-event");
|
|
7
|
+
const consts_1 = require("../../consts");
|
|
7
8
|
const initializer_1 = require("../../initializer/browser/initializer");
|
|
8
9
|
const sendEvent_1 = require("../send-event/sendEvent");
|
|
9
|
-
const consts_1 = require("../../consts");
|
|
10
10
|
/**
|
|
11
11
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
12
|
-
*
|
|
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(
|
|
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
|
-
settings
|
|
28
|
-
type,
|
|
24
|
+
settings
|
|
29
25
|
}).send();
|
|
30
26
|
}
|
|
31
27
|
exports.event = event;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Request } from '@sitecore-cloudsdk/utils';
|
|
1
|
+
import type { EPResponse } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventData } from './custom-event';
|
|
3
|
+
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
5
4
|
/**
|
|
6
5
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
7
|
-
*
|
|
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
|
|
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>(
|
|
11
|
+
export declare function eventServer<T extends Request>(request: T, eventData: EventData): Promise<EPResponse | null>;
|
|
@@ -4,26 +4,23 @@ 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 sendEvent_1 = require("../send-event/sendEvent");
|
|
8
7
|
const consts_1 = require("../../consts");
|
|
8
|
+
const sendEvent_1 = require("../send-event/sendEvent");
|
|
9
9
|
/**
|
|
10
10
|
* A function that sends an event to SitecoreCloud API with the specified type
|
|
11
|
-
*
|
|
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
|
|
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(
|
|
16
|
+
function eventServer(request, eventData) {
|
|
18
17
|
const settings = (0, core_1.handleGetSettingsError)(core_1.getSettingsServer, consts_1.ErrorMessages.IE_0005);
|
|
19
|
-
const id = (0, core_1.
|
|
18
|
+
const id = (0, core_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId);
|
|
20
19
|
return new custom_event_1.CustomEvent({
|
|
21
20
|
eventData,
|
|
22
|
-
extensionData,
|
|
23
21
|
id,
|
|
24
22
|
sendEvent: sendEvent_1.sendEvent,
|
|
25
|
-
settings
|
|
26
|
-
type,
|
|
23
|
+
settings
|
|
27
24
|
}).send();
|
|
28
25
|
}
|
|
29
26
|
exports.eventServer = eventServer;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { EPResponse } from '@sitecore-cloudsdk/core';
|
|
1
|
+
import type { 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
|
|
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.form = void 0;
|
|
5
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");
|
|
9
7
|
const consts_1 = require("../../consts");
|
|
8
|
+
const initializer_1 = require("../../initializer/browser/initializer");
|
|
9
|
+
const sendEvent_1 = require("../send-event/sendEvent");
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
settings
|
|
30
|
-
type: 'FORM',
|
|
32
|
+
settings
|
|
31
33
|
});
|
|
32
34
|
formEvent.page = undefined;
|
|
33
35
|
return formEvent.send();
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
1
3
|
import { BaseEvent } from '../base-event';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
-
import { SendEvent } from '../send-event/sendEvent';
|
|
4
|
+
import type { FlattenedObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import type { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class IdentityEvent extends BaseEvent {
|
|
7
|
-
private
|
|
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
|
|
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
|
|
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
|
-
|
|
95
|
-
extensionData?: ExtensionData;
|
|
96
|
+
identityData: IdentityData;
|
|
96
97
|
id: string;
|
|
97
98
|
settings: Settings;
|
|
98
99
|
infer?: Infer;
|