@sitecore-cloudsdk/events 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -24
- package/dist/cjs/package.json +8 -4
- package/dist/cjs/src/lib/consts.d.ts +10 -0
- package/dist/cjs/src/lib/consts.js +13 -1
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +8 -3
- package/dist/cjs/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +4 -3
- package/dist/cjs/src/lib/eventStorage/eventStorage.d.ts +4 -8
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +15 -15
- package/dist/cjs/src/lib/eventStorage/processEventQueue.d.ts +1 -1
- package/dist/cjs/src/lib/eventStorage/processEventQueue.js +4 -3
- package/dist/cjs/src/lib/events/base-event.d.ts +1 -3
- package/dist/cjs/src/lib/events/base-event.js +1 -2
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +4 -3
- package/dist/cjs/src/lib/events/custom-event/custom-event.js +6 -4
- package/dist/cjs/src/lib/events/custom-event/event.js +7 -3
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +4 -4
- package/dist/cjs/src/lib/events/custom-event/form.js +8 -4
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +4 -3
- package/dist/cjs/src/lib/events/identity/identity-event.js +10 -8
- package/dist/cjs/src/lib/events/identity/identity.js +8 -5
- package/dist/cjs/src/lib/events/identity/identityServer.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +4 -3
- package/dist/cjs/src/lib/events/page-view/page-view-event.js +6 -5
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +3 -3
- package/dist/cjs/src/lib/events/page-view/page-view.js +9 -4
- package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +17 -0
- package/dist/cjs/src/lib/events/send-event/sendEvent.js +29 -0
- package/dist/cjs/src/lib/getGuestId/getGuestId.js +6 -4
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +6 -19
- package/dist/cjs/src/lib/initializer/browser/initializer.js +21 -39
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +1 -16
- package/dist/cjs/src/lib/initializer/server/initializer.js +1 -28
- package/dist/cjs/src/server.d.ts +0 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +8 -4
- package/dist/esm/src/lib/consts.d.ts +10 -0
- package/dist/esm/src/lib/consts.js +12 -0
- package/dist/esm/src/lib/eventStorage/addToEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +8 -3
- package/dist/esm/src/lib/eventStorage/clearEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/clearEventQueue.js +4 -3
- package/dist/esm/src/lib/eventStorage/eventStorage.d.ts +4 -8
- package/dist/esm/src/lib/eventStorage/eventStorage.js +15 -14
- package/dist/esm/src/lib/eventStorage/processEventQueue.d.ts +1 -1
- package/dist/esm/src/lib/eventStorage/processEventQueue.js +4 -3
- package/dist/esm/src/lib/events/base-event.d.ts +1 -3
- package/dist/esm/src/lib/events/base-event.js +1 -2
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +4 -3
- package/dist/esm/src/lib/events/custom-event/custom-event.js +6 -4
- package/dist/esm/src/lib/events/custom-event/event.js +8 -4
- package/dist/esm/src/lib/events/custom-event/eventServer.js +5 -5
- package/dist/esm/src/lib/events/custom-event/form.js +8 -4
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +4 -3
- package/dist/esm/src/lib/events/identity/identity-event.js +10 -8
- package/dist/esm/src/lib/events/identity/identity.js +8 -5
- package/dist/esm/src/lib/events/identity/identityServer.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +4 -3
- package/dist/esm/src/lib/events/page-view/page-view-event.js +6 -5
- package/dist/esm/src/lib/events/page-view/page-view-server.js +4 -4
- package/dist/esm/src/lib/events/page-view/page-view.js +9 -4
- package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +17 -0
- package/dist/esm/src/lib/events/send-event/sendEvent.js +25 -0
- package/dist/esm/src/lib/getGuestId/getGuestId.js +6 -4
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +6 -19
- package/dist/esm/src/lib/initializer/browser/initializer.js +20 -37
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +1 -16
- package/dist/esm/src/lib/initializer/server/initializer.js +1 -26
- package/dist/esm/src/server.d.ts +0 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -4
- package/dist/cjs/src/lib/ep/EventApiClient.d.ts +0 -18
- package/dist/cjs/src/lib/ep/EventApiClient.js +0 -34
- package/dist/esm/src/lib/ep/EventApiClient.d.ts +0 -18
- package/dist/esm/src/lib/ep/EventApiClient.js +0 -30
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
2
|
+
import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
3
3
|
import { CustomEvent } from './custom-event';
|
|
4
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
5
|
+
import { awaitInit } from '../../initializer/browser/initializer';
|
|
4
6
|
/**
|
|
5
7
|
* A function that sends a form event to SitecoreCloud API
|
|
6
8
|
* @param formId - The required form ID string
|
|
@@ -8,16 +10,18 @@ import { CustomEvent } from './custom-event';
|
|
|
8
10
|
* settings object, you must specify it here
|
|
9
11
|
* @returns The response object that Sitecore EP returns or null
|
|
10
12
|
*/
|
|
11
|
-
export function form(formId, interactionType) {
|
|
12
|
-
|
|
13
|
+
export async function form(formId, interactionType) {
|
|
14
|
+
await awaitInit();
|
|
15
|
+
const settings = getSettings();
|
|
16
|
+
const id = getBrowserId();
|
|
13
17
|
const formEvent = new CustomEvent({
|
|
14
|
-
eventApiClient,
|
|
15
18
|
eventData: {},
|
|
16
19
|
extensionData: {
|
|
17
20
|
formId,
|
|
18
21
|
interactionType: interactionType.toUpperCase(),
|
|
19
22
|
},
|
|
20
23
|
id,
|
|
24
|
+
sendEvent,
|
|
21
25
|
settings,
|
|
22
26
|
type: 'FORM',
|
|
23
27
|
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { BaseEvent } from '../base-event';
|
|
2
2
|
import { ExtensionData, EventAttributesInput } from '../common-interfaces';
|
|
3
|
-
import { EventApiClient } from '../../ep/EventApiClient';
|
|
4
3
|
import { FlattenedObject } from '@sitecore-cloudsdk/utils';
|
|
5
4
|
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
5
|
+
import { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class IdentityEvent extends BaseEvent {
|
|
7
7
|
private eventData;
|
|
8
|
-
private
|
|
8
|
+
private sendEvent;
|
|
9
9
|
private extensionData;
|
|
10
10
|
private numberOfExtensionDataProperties;
|
|
11
|
+
private settings;
|
|
11
12
|
/**
|
|
12
13
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
13
14
|
* @param args - Unified object containing the required properties
|
|
@@ -89,7 +90,7 @@ export interface IdentityEventPayload {
|
|
|
89
90
|
* Interface of the unified arguments object for identity event
|
|
90
91
|
*/
|
|
91
92
|
export interface IdentityEventArguments {
|
|
92
|
-
|
|
93
|
+
sendEvent: SendEvent;
|
|
93
94
|
eventData: IdentityEventAttributesInput;
|
|
94
95
|
extensionData?: ExtensionData;
|
|
95
96
|
id: string;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { BaseEvent } from '../base-event';
|
|
3
3
|
import { MAX_EXT_ATTRIBUTES } from '../consts';
|
|
4
4
|
import { isShortISODateString, isValidEmail, flattenObject } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import { ErrorMessages } from '../../consts';
|
|
5
6
|
export class IdentityEvent extends BaseEvent {
|
|
6
7
|
/**
|
|
7
8
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
@@ -9,17 +10,18 @@ export class IdentityEvent extends BaseEvent {
|
|
|
9
10
|
*/
|
|
10
11
|
constructor(args) {
|
|
11
12
|
const { channel, currency, language, page } = args.eventData;
|
|
12
|
-
super({ channel, currency, language, page }, args.
|
|
13
|
+
super({ channel, currency, language, page }, args.id);
|
|
13
14
|
this.extensionData = {};
|
|
14
15
|
this.numberOfExtensionDataProperties = 0;
|
|
15
16
|
this.validateAttributes(args.eventData);
|
|
16
17
|
this.eventData = args.eventData;
|
|
17
|
-
this.
|
|
18
|
+
this.sendEvent = args.sendEvent;
|
|
19
|
+
this.settings = args.settings;
|
|
18
20
|
if (args.extensionData)
|
|
19
21
|
this.extensionData = flattenObject({ object: args.extensionData });
|
|
20
22
|
this.numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
21
23
|
if (this.numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
22
|
-
throw new Error(
|
|
24
|
+
throw new Error(ErrorMessages.IV_0005);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Function that validates the identifiers object, email and date attributes for CDN users
|
|
@@ -27,15 +29,15 @@ export class IdentityEvent extends BaseEvent {
|
|
|
27
29
|
*/
|
|
28
30
|
validateAttributes(eventData) {
|
|
29
31
|
if (eventData.identifiers.length === 0)
|
|
30
|
-
throw new Error(
|
|
32
|
+
throw new Error(ErrorMessages.MV_0003);
|
|
31
33
|
if (eventData.dob !== undefined && !isShortISODateString(eventData.dob))
|
|
32
|
-
throw new Error(
|
|
34
|
+
throw new Error(ErrorMessages.IV_0002);
|
|
33
35
|
eventData.identifiers.forEach((identifier) => {
|
|
34
36
|
if (identifier.expiryDate && !isShortISODateString(identifier.expiryDate))
|
|
35
|
-
throw new Error(
|
|
37
|
+
throw new Error(ErrorMessages.IV_0004);
|
|
36
38
|
});
|
|
37
39
|
if (eventData.email && !isValidEmail(eventData.email))
|
|
38
|
-
throw new Error(
|
|
40
|
+
throw new Error(ErrorMessages.IV_0003);
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
41
43
|
* A function that maps the identity event input data with the payload sent to the API
|
|
@@ -79,6 +81,6 @@ export class IdentityEvent extends BaseEvent {
|
|
|
79
81
|
const baseAttr = this.mapBaseEventPayload();
|
|
80
82
|
const eventAttrs = this.mapAttributes();
|
|
81
83
|
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
82
|
-
return await this.
|
|
84
|
+
return await this.sendEvent(fetchBody, this.settings);
|
|
83
85
|
}
|
|
84
86
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { getDependencies } from '../../initializer/browser/initializer';
|
|
1
|
+
import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
3
2
|
import { IdentityEvent } from './identity-event';
|
|
3
|
+
import { awaitInit } from '../../initializer/browser/initializer';
|
|
4
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
4
5
|
/**
|
|
5
6
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
6
7
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -8,13 +9,15 @@ import { IdentityEvent } from './identity-event';
|
|
|
8
9
|
* This object will be flattened and sent in the ext object of the payload
|
|
9
10
|
* @returns The response object that Sitecore EP returns
|
|
10
11
|
*/
|
|
11
|
-
export function identity(eventData, extensionData) {
|
|
12
|
-
|
|
12
|
+
export async function identity(eventData, extensionData) {
|
|
13
|
+
await awaitInit();
|
|
14
|
+
const settings = getSettings();
|
|
15
|
+
const id = getBrowserId();
|
|
13
16
|
return new IdentityEvent({
|
|
14
|
-
eventApiClient,
|
|
15
17
|
eventData,
|
|
16
18
|
extensionData,
|
|
17
19
|
id,
|
|
20
|
+
sendEvent,
|
|
18
21
|
settings,
|
|
19
22
|
}).send();
|
|
20
23
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { getBrowserIdFromRequest } from '@sitecore-cloudsdk/core';
|
|
3
|
-
import { getServerDependencies } from '../../initializer/server/initializer';
|
|
2
|
+
import { getBrowserIdFromRequest, getSettingsServer } from '@sitecore-cloudsdk/core';
|
|
4
3
|
import { IdentityEvent } from './identity-event';
|
|
4
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
5
5
|
/**
|
|
6
6
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
7
7
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -11,13 +11,13 @@ import { IdentityEvent } from './identity-event';
|
|
|
11
11
|
* @returns The response object that Sitecore EP returns
|
|
12
12
|
*/
|
|
13
13
|
export function identityServer(eventData, request, extensionData) {
|
|
14
|
-
const
|
|
14
|
+
const settings = getSettingsServer();
|
|
15
15
|
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
|
|
16
16
|
return new IdentityEvent({
|
|
17
|
-
eventApiClient,
|
|
18
17
|
eventData,
|
|
19
18
|
extensionData,
|
|
20
19
|
id,
|
|
20
|
+
sendEvent,
|
|
21
21
|
settings: settings,
|
|
22
22
|
}).send();
|
|
23
23
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
2
2
|
import { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
3
3
|
import { BaseEvent } from '../base-event';
|
|
4
|
-
import { EventApiClient } from '../../ep/EventApiClient';
|
|
5
4
|
import { EventAttributesInput } from '../common-interfaces';
|
|
5
|
+
import { SendEvent } from '../send-event/sendEvent';
|
|
6
6
|
export declare class PageViewEvent extends BaseEvent {
|
|
7
7
|
static isFirstPageView: boolean;
|
|
8
|
-
private
|
|
8
|
+
private sendEvent;
|
|
9
9
|
private eventData;
|
|
10
10
|
private extensionData;
|
|
11
11
|
private urlSearchParams;
|
|
12
12
|
private includeUTMParameters;
|
|
13
|
+
settings: Settings;
|
|
13
14
|
/**
|
|
14
15
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
15
16
|
* @param args - Unified object containing the required properties
|
|
@@ -47,7 +48,7 @@ export declare class PageViewEvent extends BaseEvent {
|
|
|
47
48
|
* Interface of the unified arguments object for page view event
|
|
48
49
|
*/
|
|
49
50
|
export interface PageViewEventArguments {
|
|
50
|
-
|
|
51
|
+
sendEvent: SendEvent;
|
|
51
52
|
eventData: PageViewEventInput;
|
|
52
53
|
id: string;
|
|
53
54
|
settings: Settings;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
1
|
import { flattenObject } from '@sitecore-cloudsdk/utils';
|
|
3
2
|
import { BaseEvent } from '../base-event';
|
|
4
3
|
import { MAX_EXT_ATTRIBUTES, UTM_PREFIX } from '../consts';
|
|
4
|
+
import { ErrorMessages } from '../../consts';
|
|
5
5
|
export class PageViewEvent extends BaseEvent {
|
|
6
6
|
/**
|
|
7
7
|
* A class that extends from {@link BaseEvent} and has all the required functionality to send a VIEW event
|
|
@@ -14,16 +14,17 @@ export class PageViewEvent extends BaseEvent {
|
|
|
14
14
|
currency,
|
|
15
15
|
language,
|
|
16
16
|
page,
|
|
17
|
-
}, args.
|
|
17
|
+
}, args.id);
|
|
18
18
|
this.extensionData = {};
|
|
19
19
|
this.eventData = args.eventData;
|
|
20
|
+
this.sendEvent = args.sendEvent;
|
|
21
|
+
this.settings = args.settings;
|
|
20
22
|
this.urlSearchParams = new URLSearchParams(decodeURI(args.searchParams));
|
|
21
23
|
if (args.extensionData)
|
|
22
24
|
this.extensionData = flattenObject({ object: args.extensionData });
|
|
23
25
|
const numberOfExtensionDataProperties = Object.entries(this.extensionData).length;
|
|
24
26
|
if (numberOfExtensionDataProperties > MAX_EXT_ATTRIBUTES)
|
|
25
|
-
throw new Error(
|
|
26
|
-
this.eventApiClient = args.eventApiClient;
|
|
27
|
+
throw new Error(ErrorMessages.IV_0005);
|
|
27
28
|
this.includeUTMParameters =
|
|
28
29
|
args.eventData.includeUTMParameters === undefined ? true : args.eventData.includeUTMParameters;
|
|
29
30
|
}
|
|
@@ -90,7 +91,7 @@ export class PageViewEvent extends BaseEvent {
|
|
|
90
91
|
const eventAttrs = this.mapAttributes();
|
|
91
92
|
const fetchBody = Object.assign({}, eventAttrs, baseAttr);
|
|
92
93
|
PageViewEvent.isFirstPageView = false;
|
|
93
|
-
return await this.
|
|
94
|
+
return await this.sendEvent(fetchBody, this.settings);
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* Retrieves UTM parameters from the url query string
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { getBrowserIdFromRequest } from '@sitecore-cloudsdk/core';
|
|
3
|
-
import { getServerDependencies } from '../../initializer/server/initializer';
|
|
2
|
+
import { getBrowserIdFromRequest, getSettingsServer } from '@sitecore-cloudsdk/core';
|
|
4
3
|
import { PageViewEvent } from './page-view-event';
|
|
4
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
5
5
|
/**
|
|
6
6
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
7
7
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -11,16 +11,16 @@ import { PageViewEvent } from './page-view-event';
|
|
|
11
11
|
* @returns The response object that Sitecore EP returns
|
|
12
12
|
*/
|
|
13
13
|
export function pageViewServer(eventData, request, extensionData) {
|
|
14
|
-
const
|
|
14
|
+
const settings = getSettingsServer();
|
|
15
15
|
const id = getBrowserIdFromRequest(request, settings.cookieSettings.cookieName);
|
|
16
16
|
// Host is irrelevant but necessary to support relative URL
|
|
17
17
|
const requestUrl = new URL(request.url, `https://localhost`);
|
|
18
18
|
return new PageViewEvent({
|
|
19
|
-
eventApiClient,
|
|
20
19
|
eventData,
|
|
21
20
|
extensionData,
|
|
22
21
|
id,
|
|
23
22
|
searchParams: requestUrl.search,
|
|
23
|
+
sendEvent,
|
|
24
24
|
settings,
|
|
25
25
|
}).send();
|
|
26
26
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { getBrowserId, getSettings } from '@sitecore-cloudsdk/core';
|
|
2
3
|
import { PageViewEvent } from './page-view-event';
|
|
4
|
+
import { awaitInit } from '../../initializer/browser/initializer';
|
|
5
|
+
import { sendEvent } from '../send-event/sendEvent';
|
|
3
6
|
/**
|
|
4
7
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
5
8
|
* @param eventData - The required/optional attributes in order to be send to SitecoreCloud API
|
|
@@ -7,14 +10,16 @@ import { PageViewEvent } from './page-view-event';
|
|
|
7
10
|
* This object will be flattened and sent in the ext object of the payload
|
|
8
11
|
* @returns The response object that Sitecore EP returns
|
|
9
12
|
*/
|
|
10
|
-
export function pageView(eventData, extensionData) {
|
|
11
|
-
|
|
13
|
+
export async function pageView(eventData, extensionData) {
|
|
14
|
+
await awaitInit();
|
|
15
|
+
const settings = getSettings();
|
|
16
|
+
const id = getBrowserId();
|
|
12
17
|
return new PageViewEvent({
|
|
13
|
-
eventApiClient,
|
|
14
18
|
eventData,
|
|
15
19
|
extensionData,
|
|
16
20
|
id,
|
|
17
21
|
searchParams: window.location.search,
|
|
22
|
+
sendEvent,
|
|
18
23
|
settings,
|
|
19
24
|
}).send();
|
|
20
25
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { BasePayload, PageViewEventPayload, IdentityEventPayload, CustomEventPayload } from '..';
|
|
3
|
+
/**
|
|
4
|
+
* This factory function sends an event to Edge Proxy
|
|
5
|
+
* @param body - The event data to send
|
|
6
|
+
* @param settings - The global settings
|
|
7
|
+
*/
|
|
8
|
+
export declare function sendEvent(body: EPFetchBody & BasePayload, settings: Settings): Promise<EPResponse | null>;
|
|
9
|
+
/**
|
|
10
|
+
* The type of sendEvent function
|
|
11
|
+
*/
|
|
12
|
+
export type SendEvent = (body: EPFetchBody & BasePayload, settings: Settings) => Promise<EPResponse | null>;
|
|
13
|
+
/**
|
|
14
|
+
* The type describing all possible event payloads
|
|
15
|
+
*/
|
|
16
|
+
type EPFetchBody = PageViewEventPayload | IdentityEventPayload | CustomEventPayload;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { API_VERSION } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { LIBRARY_VERSION } from '../../consts';
|
|
4
|
+
/**
|
|
5
|
+
* This factory function sends an event to Edge Proxy
|
|
6
|
+
* @param body - The event data to send
|
|
7
|
+
* @param settings - The global settings
|
|
8
|
+
*/
|
|
9
|
+
export async function sendEvent(body, settings) {
|
|
10
|
+
const eventUrl = `${settings.sitecoreEdgeUrl}/events/${API_VERSION}/events?sitecoreContextId=${settings.sitecoreEdgeContextId}&siteId=${settings.siteName}`;
|
|
11
|
+
const fetchOptions = {
|
|
12
|
+
body: JSON.stringify(body),
|
|
13
|
+
headers: {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
17
|
+
'X-Library-Version': LIBRARY_VERSION,
|
|
18
|
+
},
|
|
19
|
+
method: 'POST',
|
|
20
|
+
};
|
|
21
|
+
return await fetch(eventUrl, fetchOptions)
|
|
22
|
+
.then((response) => response.json())
|
|
23
|
+
.then((data) => data)
|
|
24
|
+
.catch(() => null);
|
|
25
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { awaitInit } from '../initializer/browser/initializer';
|
|
3
|
+
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings } from '@sitecore-cloudsdk/core';
|
|
4
4
|
/**
|
|
5
5
|
* A function that returns the guest id.
|
|
6
6
|
* @returns - A promise that resolves with the guest id
|
|
7
7
|
* @throws - Will throw an error if the clientKey/browser id is invalid
|
|
8
8
|
*/
|
|
9
|
-
export function getGuestId() {
|
|
10
|
-
|
|
9
|
+
export async function getGuestId() {
|
|
10
|
+
await awaitInit();
|
|
11
|
+
const settings = getSettings();
|
|
12
|
+
const id = getBrowserId();
|
|
11
13
|
return getGuestIdFromCore(id, settings.sitecoreEdgeContextId, settings.sitecoreEdgeUrl);
|
|
12
14
|
}
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { EventQueue } from '../../eventStorage/eventStorage';
|
|
4
|
-
export declare function setDependencies(settings: BrowserEventsSettings | null): void;
|
|
5
|
-
/**
|
|
6
|
-
* Retrieves the browser event settings object.
|
|
7
|
-
*
|
|
8
|
-
* This function ensures that the browser event settings have been initialized and contain essential properties like `settings`, `eventQueue`, and `eventApiClient`.
|
|
9
|
-
*
|
|
10
|
-
* @returns The browser event settings object.
|
|
11
|
-
* @throws Error if the event settings haven't been initialized with the required properties.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getDependencies(): BrowserEventsSettings;
|
|
14
|
-
export interface BrowserEventsSettings {
|
|
15
|
-
id: string;
|
|
16
|
-
settings: Settings;
|
|
17
|
-
eventQueue: EventQueue;
|
|
18
|
-
eventApiClient: EventApiClient;
|
|
19
|
-
}
|
|
1
|
+
import { SettingsParamsBrowser } from '@sitecore-cloudsdk/core';
|
|
2
|
+
export declare let initPromise: Promise<void> | null;
|
|
20
3
|
/**
|
|
21
4
|
* Initiates the Events library using the global settings added by the developer
|
|
22
5
|
* @param settingsInput - Global settings added by the developer
|
|
23
6
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
24
7
|
*/
|
|
25
8
|
export declare function init(settingsInput: SettingsParamsBrowser): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
11
|
+
*/
|
|
12
|
+
export declare function awaitInit(): Promise<void>;
|
|
@@ -1,48 +1,23 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { EventQueue } from '../../eventStorage/eventStorage';
|
|
6
|
-
let dependencies = null;
|
|
7
|
-
export function setDependencies(settings) {
|
|
8
|
-
dependencies = settings;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Retrieves the browser event settings object.
|
|
12
|
-
*
|
|
13
|
-
* This function ensures that the browser event settings have been initialized and contain essential properties like `settings`, `eventQueue`, and `eventApiClient`.
|
|
14
|
-
*
|
|
15
|
-
* @returns The browser event settings object.
|
|
16
|
-
* @throws Error if the event settings haven't been initialized with the required properties.
|
|
17
|
-
*/
|
|
18
|
-
export function getDependencies() {
|
|
19
|
-
if (!dependencies) {
|
|
20
|
-
throw Error(`[IE-0004] You must first initialize the "events/browser" module. Run the "init" function.`);
|
|
21
|
-
}
|
|
22
|
-
return dependencies;
|
|
23
|
-
}
|
|
2
|
+
import { getBrowserId, initCore } from '@sitecore-cloudsdk/core';
|
|
3
|
+
import { ErrorMessages, LIBRARY_VERSION } from '../../consts';
|
|
4
|
+
export let initPromise = null;
|
|
24
5
|
/**
|
|
25
6
|
* Initiates the Events library using the global settings added by the developer
|
|
26
7
|
* @param settingsInput - Global settings added by the developer
|
|
27
8
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
28
9
|
*/
|
|
29
10
|
export async function init(settingsInput) {
|
|
30
|
-
if (typeof window === 'undefined')
|
|
31
|
-
throw new Error(
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
if (typeof window === 'undefined')
|
|
12
|
+
throw new Error(ErrorMessages.IE_0001);
|
|
13
|
+
try {
|
|
14
|
+
initPromise = initCore(settingsInput);
|
|
15
|
+
await initPromise;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
initPromise = null;
|
|
19
|
+
throw new Error(error);
|
|
34
20
|
}
|
|
35
|
-
await initCore(settingsInput);
|
|
36
|
-
const settings = getSettings();
|
|
37
|
-
const id = getBrowserId();
|
|
38
|
-
const eventApiClient = new EventApiClient(settings.sitecoreEdgeUrl, settingsInput.sitecoreEdgeContextId, settingsInput.siteName);
|
|
39
|
-
const eventQueue = new EventQueue(sessionStorage, eventApiClient);
|
|
40
|
-
setDependencies({
|
|
41
|
-
eventApiClient,
|
|
42
|
-
eventQueue,
|
|
43
|
-
id,
|
|
44
|
-
settings,
|
|
45
|
-
});
|
|
46
21
|
window.Engage = {
|
|
47
22
|
...window.Engage,
|
|
48
23
|
getBrowserId: () => getBrowserId(),
|
|
@@ -52,3 +27,11 @@ export async function init(settingsInput) {
|
|
|
52
27
|
},
|
|
53
28
|
};
|
|
54
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
32
|
+
*/
|
|
33
|
+
export async function awaitInit() {
|
|
34
|
+
if (initPromise === null)
|
|
35
|
+
throw new Error(ErrorMessages.IE_0004);
|
|
36
|
+
await initPromise;
|
|
37
|
+
}
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EventApiClient } from '../../ep/EventApiClient';
|
|
1
|
+
import { SettingsParamsServer } from '@sitecore-cloudsdk/core';
|
|
3
2
|
import { HttpResponse, MiddlewareNextResponse, Request } from '@sitecore-cloudsdk/utils';
|
|
4
|
-
export declare function setServerDependencies(settings: ServerEventsSettings | null): void;
|
|
5
|
-
/**
|
|
6
|
-
* Retrieves the server event settings object.
|
|
7
|
-
*
|
|
8
|
-
* This function ensures that the server event settings have been initialized and contain essential properties like `settings` and `eventApiClient`.
|
|
9
|
-
*
|
|
10
|
-
* @returns The server event settings object.
|
|
11
|
-
* @throws Error if the server event settings haven't been initialized with the required properties.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getServerDependencies(): ServerEventsSettings;
|
|
14
3
|
/**
|
|
15
4
|
* Initiates the server Events library using the global settings added by the developer
|
|
16
5
|
* @param settings - Global settings added by the developer
|
|
17
6
|
* @returns A promise that resolves with an object that handles the library functionality
|
|
18
7
|
*/
|
|
19
8
|
export declare function initServer<Response extends MiddlewareNextResponse | HttpResponse>(settingsInput: SettingsParamsServer, request: Request, response: Response): Promise<void>;
|
|
20
|
-
export interface ServerEventsSettings {
|
|
21
|
-
settings: Settings;
|
|
22
|
-
eventApiClient: EventApiClient;
|
|
23
|
-
}
|
|
@@ -1,24 +1,5 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import { EventApiClient } from '../../ep/EventApiClient';
|
|
4
|
-
let serverDependencies = null;
|
|
5
|
-
export function setServerDependencies(settings) {
|
|
6
|
-
serverDependencies = settings;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves the server event settings object.
|
|
10
|
-
*
|
|
11
|
-
* This function ensures that the server event settings have been initialized and contain essential properties like `settings` and `eventApiClient`.
|
|
12
|
-
*
|
|
13
|
-
* @returns The server event settings object.
|
|
14
|
-
* @throws Error if the server event settings haven't been initialized with the required properties.
|
|
15
|
-
*/
|
|
16
|
-
export function getServerDependencies() {
|
|
17
|
-
if (!serverDependencies) {
|
|
18
|
-
throw Error(`[IE-0005] You must first initialize the "events/server" module. Run the "init" function.`);
|
|
19
|
-
}
|
|
20
|
-
return serverDependencies;
|
|
21
|
-
}
|
|
2
|
+
import { initCoreServer } from '@sitecore-cloudsdk/core';
|
|
22
3
|
/**
|
|
23
4
|
* Initiates the server Events library using the global settings added by the developer
|
|
24
5
|
* @param settings - Global settings added by the developer
|
|
@@ -26,10 +7,4 @@ export function getServerDependencies() {
|
|
|
26
7
|
*/
|
|
27
8
|
export async function initServer(settingsInput, request, response) {
|
|
28
9
|
await initCoreServer(settingsInput, request, response);
|
|
29
|
-
const settings = getSettingsServer();
|
|
30
|
-
const eventApiClient = new EventApiClient(settings.sitecoreEdgeUrl, settings.sitecoreEdgeContextId, settings.siteName);
|
|
31
|
-
setServerDependencies({
|
|
32
|
-
eventApiClient,
|
|
33
|
-
settings,
|
|
34
|
-
});
|
|
35
10
|
}
|
package/dist/esm/src/server.d.ts
CHANGED
|
@@ -4,4 +4,3 @@ export { identityServer as identity } from './lib/events/identity/identityServer
|
|
|
4
4
|
export { pageViewServer as pageView } from './lib/events/page-view/page-view-server';
|
|
5
5
|
export { LIBRARY_VERSION } from './lib/consts';
|
|
6
6
|
export type { PageViewEventInput, CustomEventInput, IdentityEventAttributesInput } from './lib/events';
|
|
7
|
-
export type { ServerEventsSettings as EventsSettings } from './lib/initializer/server/initializer';
|