@sitecore-cloudsdk/events 0.3.1 → 0.4.0-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 +31 -59
- package/dist/cjs/package.json +3 -3
- package/dist/cjs/src/browser.d.ts +4 -3
- package/dist/cjs/src/browser.js +8 -5
- package/dist/cjs/src/lib/consts.d.ts +7 -6
- package/dist/cjs/src/lib/consts.js +9 -8
- package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +23 -10
- package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +1 -1
- package/dist/cjs/src/lib/eventStorage/eventStorage.js +3 -3
- package/dist/cjs/src/lib/eventStorage/processEventQueue.js +1 -1
- package/dist/cjs/src/lib/events/base-event.js +3 -3
- package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +1 -1
- package/dist/cjs/src/lib/events/custom-event/event.d.ts +1 -1
- package/dist/cjs/src/lib/events/custom-event/event.js +24 -12
- package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +2 -2
- package/dist/cjs/src/lib/events/custom-event/eventServer.js +16 -7
- package/dist/cjs/src/lib/events/custom-event/form.d.ts +3 -3
- package/dist/cjs/src/lib/events/custom-event/form.js +43 -21
- package/dist/cjs/src/lib/events/identity/identity-event.d.ts +1 -1
- package/dist/cjs/src/lib/events/identity/identity.d.ts +1 -1
- package/dist/cjs/src/lib/events/identity/identity.js +24 -12
- package/dist/cjs/src/lib/events/identity/identityServer.d.ts +2 -2
- package/dist/cjs/src/lib/events/identity/identityServer.js +17 -6
- package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +1 -1
- package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +2 -2
- package/dist/cjs/src/lib/events/page-view/page-view-server.js +17 -6
- package/dist/cjs/src/lib/events/page-view/page-view.d.ts +1 -1
- package/dist/cjs/src/lib/events/page-view/page-view.js +26 -13
- package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +1 -1
- package/dist/cjs/src/lib/events/send-event/sendEvent.js +7 -7
- package/dist/cjs/src/lib/getBrowserId/getBrowserId.d.ts +8 -0
- package/dist/cjs/src/lib/getBrowserId/getBrowserId.js +16 -0
- package/dist/cjs/src/lib/getGuestId/getGuestId.d.ts +6 -3
- package/dist/cjs/src/lib/getGuestId/getGuestId.js +19 -8
- package/dist/cjs/src/lib/init/browser/initializer.d.ts +13 -0
- package/dist/cjs/src/lib/init/browser/initializer.js +48 -0
- package/dist/cjs/src/lib/init/server/initializer.d.ts +11 -0
- package/dist/cjs/src/lib/init/server/initializer.js +26 -0
- package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +11 -22
- package/dist/cjs/src/lib/initializer/browser/initializer.js +20 -31
- package/dist/cjs/src/lib/initializer/server/initializer.d.ts +11 -8
- package/dist/cjs/src/lib/initializer/server/initializer.js +17 -17
- package/dist/cjs/src/server.d.ts +3 -2
- package/dist/cjs/src/server.js +6 -3
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/package.json +3 -3
- package/dist/esm/src/browser.d.ts +4 -3
- package/dist/esm/src/browser.js +4 -3
- package/dist/esm/src/lib/consts.d.ts +7 -6
- package/dist/esm/src/lib/consts.js +8 -7
- package/dist/esm/src/lib/eventStorage/addToEventQueue.js +24 -11
- package/dist/esm/src/lib/eventStorage/clearEventQueue.js +1 -1
- package/dist/esm/src/lib/eventStorage/eventStorage.js +1 -1
- package/dist/esm/src/lib/eventStorage/processEventQueue.js +1 -1
- package/dist/esm/src/lib/events/base-event.js +1 -1
- package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +1 -1
- package/dist/esm/src/lib/events/custom-event/event.d.ts +1 -1
- package/dist/esm/src/lib/events/custom-event/event.js +25 -13
- package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +2 -2
- package/dist/esm/src/lib/events/custom-event/eventServer.js +17 -8
- package/dist/esm/src/lib/events/custom-event/form.d.ts +3 -3
- package/dist/esm/src/lib/events/custom-event/form.js +44 -22
- package/dist/esm/src/lib/events/identity/identity-event.d.ts +1 -1
- package/dist/esm/src/lib/events/identity/identity.d.ts +1 -1
- package/dist/esm/src/lib/events/identity/identity.js +25 -13
- package/dist/esm/src/lib/events/identity/identityServer.d.ts +2 -2
- package/dist/esm/src/lib/events/identity/identityServer.js +17 -6
- package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +1 -1
- package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +2 -2
- package/dist/esm/src/lib/events/page-view/page-view-server.js +18 -7
- package/dist/esm/src/lib/events/page-view/page-view.d.ts +1 -1
- package/dist/esm/src/lib/events/page-view/page-view.js +27 -14
- package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +1 -1
- package/dist/esm/src/lib/events/send-event/sendEvent.js +3 -3
- package/dist/esm/src/lib/getBrowserId/getBrowserId.d.ts +8 -0
- package/dist/esm/src/lib/getBrowserId/getBrowserId.js +12 -0
- package/dist/esm/src/lib/getGuestId/getGuestId.d.ts +6 -3
- package/dist/esm/src/lib/getGuestId/getGuestId.js +20 -9
- package/dist/esm/src/lib/init/browser/initializer.d.ts +13 -0
- package/dist/esm/src/lib/init/browser/initializer.js +43 -0
- package/dist/esm/src/lib/init/server/initializer.d.ts +11 -0
- package/dist/esm/src/lib/init/server/initializer.js +22 -0
- package/dist/esm/src/lib/initializer/browser/initializer.d.ts +11 -22
- package/dist/esm/src/lib/initializer/browser/initializer.js +18 -29
- package/dist/esm/src/lib/initializer/server/initializer.d.ts +11 -8
- package/dist/esm/src/lib/initializer/server/initializer.js +15 -16
- package/dist/esm/src/server.d.ts +3 -2
- package/dist/esm/src/server.js +3 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,33 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
1
|
+
import { getBrowserId, getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
2
|
+
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import { ErrorMessages, PACKAGE_NAME } from '../../consts';
|
|
4
|
+
import { awaitInit } from '../../init/browser/initializer';
|
|
6
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
+
import { CustomEvent } from './custom-event';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends a form event to SitecoreCloud API
|
|
9
9
|
*
|
|
10
10
|
* @param formId - The required form ID string
|
|
11
11
|
* @param interactionType - The required interaction type string. Possible values: "VIEWED", "SUBMITTED"
|
|
12
|
-
*
|
|
12
|
+
* @param componentInstanceId - The required component instance ID string
|
|
13
13
|
* @returns The response object that Sitecore EP returns or null
|
|
14
14
|
*/
|
|
15
|
-
export async function form(formId, interactionType) {
|
|
15
|
+
export async function form(formId, interactionType, componentInstanceId) {
|
|
16
16
|
await awaitInit();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (getEnabledPackage(PACKAGE_NAME)?.initState) {
|
|
18
|
+
const settings = getCloudSDKSettings();
|
|
19
|
+
const id = getCookieValueClientSide(settings.cookieSettings.name.browserId);
|
|
20
|
+
const formEvent = new CustomEvent({
|
|
21
|
+
eventData: {
|
|
22
|
+
extensionData: {
|
|
23
|
+
componentInstanceId,
|
|
24
|
+
formId,
|
|
25
|
+
interactionType: interactionType.toUpperCase()
|
|
26
|
+
},
|
|
27
|
+
type: 'FORM'
|
|
28
|
+
},
|
|
29
|
+
id,
|
|
30
|
+
sendEvent,
|
|
31
|
+
settings: settings
|
|
32
|
+
});
|
|
33
|
+
formEvent.page = undefined;
|
|
34
|
+
return formEvent.send();
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0014);
|
|
38
|
+
const id = getBrowserId();
|
|
39
|
+
const formEvent = new CustomEvent({
|
|
40
|
+
eventData: {
|
|
41
|
+
extensionData: {
|
|
42
|
+
componentInstanceId,
|
|
43
|
+
formId,
|
|
44
|
+
interactionType: interactionType.toUpperCase()
|
|
45
|
+
},
|
|
46
|
+
type: 'FORM'
|
|
24
47
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return formEvent.send();
|
|
48
|
+
id,
|
|
49
|
+
sendEvent,
|
|
50
|
+
settings
|
|
51
|
+
});
|
|
52
|
+
formEvent.page = undefined;
|
|
53
|
+
return formEvent.send();
|
|
54
|
+
}
|
|
33
55
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
1
|
+
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core/internal';
|
|
2
2
|
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
3
3
|
import { BaseEvent } from '../base-event';
|
|
4
4
|
import type { FlattenedObject } from '@sitecore-cloudsdk/utils';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { ErrorMessages } from '../../consts';
|
|
4
|
-
import {
|
|
5
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
1
|
+
import { getBrowserId, getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
2
|
+
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import { ErrorMessages, PACKAGE_NAME } from '../../consts';
|
|
4
|
+
import { awaitInit } from '../../init/browser/initializer';
|
|
6
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
+
import { IdentityEvent } from './identity-event';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
9
9
|
*
|
|
@@ -12,12 +12,24 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
12
12
|
*/
|
|
13
13
|
export async function identity(identityData) {
|
|
14
14
|
await awaitInit();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
if (getEnabledPackage(PACKAGE_NAME)?.initState) {
|
|
16
|
+
const settings = getCloudSDKSettings();
|
|
17
|
+
const id = getCookieValueClientSide(settings.cookieSettings.name.browserId);
|
|
18
|
+
return new IdentityEvent({
|
|
19
|
+
id,
|
|
20
|
+
identityData,
|
|
21
|
+
sendEvent,
|
|
22
|
+
settings: settings
|
|
23
|
+
}).send();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0014);
|
|
27
|
+
const id = getBrowserId();
|
|
28
|
+
return new IdentityEvent({
|
|
29
|
+
id,
|
|
30
|
+
identityData,
|
|
31
|
+
sendEvent,
|
|
32
|
+
settings
|
|
33
|
+
}).send();
|
|
34
|
+
}
|
|
23
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { IdentityData } from './identity-event';
|
|
1
|
+
import { type EPResponse } from '@sitecore-cloudsdk/core/internal';
|
|
3
2
|
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import type { IdentityData } from './identity-event';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
6
6
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { builderInstanceServer, getCookieValueFromRequest, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
import { getCloudSDKSettingsServer as getCloudSDKSettings, getEnabledPackageServer as getEnabledPackage, getSettingsServer } from '@sitecore-cloudsdk/core/internal';
|
|
4
|
+
import { ErrorMessages, PACKAGE_NAME } from '../../consts';
|
|
5
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
+
import { IdentityEvent } from './identity-event';
|
|
6
7
|
/**
|
|
7
8
|
* A function that sends an IDENTITY event to SitecoreCloud API
|
|
8
9
|
*
|
|
@@ -11,10 +12,20 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
11
12
|
* @returns The response object that Sitecore EP returns
|
|
12
13
|
*/
|
|
13
14
|
export function identityServer(request, identityData) {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
let settings;
|
|
16
|
+
let browserId;
|
|
17
|
+
if (builderInstanceServer) {
|
|
18
|
+
if (!getEnabledPackage(PACKAGE_NAME))
|
|
19
|
+
throw new Error(ErrorMessages.IE_0015);
|
|
20
|
+
settings = getCloudSDKSettings();
|
|
21
|
+
browserId = getCookieValueFromRequest(request, settings.cookieSettings.name.browserId);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0015);
|
|
25
|
+
browserId = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
|
|
26
|
+
}
|
|
16
27
|
return new IdentityEvent({
|
|
17
|
-
id,
|
|
28
|
+
id: browserId,
|
|
18
29
|
identityData,
|
|
19
30
|
sendEvent,
|
|
20
31
|
settings: settings
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core';
|
|
1
|
+
import type { EPResponse, Infer, Settings } from '@sitecore-cloudsdk/core/internal';
|
|
2
2
|
import type { EventAttributesInput, ExtensionData } from '../common-interfaces';
|
|
3
3
|
import type { FlattenedObject, NestedObject } from '@sitecore-cloudsdk/utils';
|
|
4
4
|
import { BaseEvent } from '../base-event';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { PageViewData } from './page-view-event';
|
|
1
|
+
import { type EPResponse } from '@sitecore-cloudsdk/core/internal';
|
|
3
2
|
import type { Request } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import type { PageViewData } from './page-view-event';
|
|
4
4
|
/**
|
|
5
5
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
6
6
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
import { builderInstanceServer, getCloudSDKSettingsServer, getCookieValueFromRequest, getEnabledPackageServer as getEnabledPackage, getSettingsServer } from '@sitecore-cloudsdk/core/internal';
|
|
4
|
+
import { ErrorMessages, PACKAGE_NAME } from '../../consts';
|
|
5
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
+
import { PageViewEvent } from './page-view-event';
|
|
6
7
|
/**
|
|
7
8
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
8
9
|
*
|
|
@@ -11,15 +12,25 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
11
12
|
* @returns The response object that Sitecore EP returns
|
|
12
13
|
*/
|
|
13
14
|
export function pageViewServer(request, pageViewData) {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
let settings;
|
|
16
|
+
let browserId;
|
|
16
17
|
// Host is irrelevant but necessary to support relative URL
|
|
17
18
|
const requestUrl = new URL(request.url, `https://localhost`);
|
|
19
|
+
if (builderInstanceServer) {
|
|
20
|
+
if (!getEnabledPackage(PACKAGE_NAME))
|
|
21
|
+
throw new Error(ErrorMessages.IE_0015);
|
|
22
|
+
settings = getCloudSDKSettingsServer();
|
|
23
|
+
browserId = getCookieValueFromRequest(request, settings.cookieSettings.name.browserId);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0015);
|
|
27
|
+
browserId = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
|
|
28
|
+
}
|
|
18
29
|
return new PageViewEvent({
|
|
19
|
-
id,
|
|
30
|
+
id: browserId,
|
|
20
31
|
pageViewData,
|
|
21
32
|
searchParams: requestUrl.search,
|
|
22
33
|
sendEvent,
|
|
23
|
-
settings
|
|
34
|
+
settings: settings
|
|
24
35
|
}).send();
|
|
25
36
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { ErrorMessages } from '../../consts';
|
|
4
|
-
import {
|
|
5
|
-
import { awaitInit } from '../../initializer/browser/initializer';
|
|
1
|
+
import { getBrowserId, getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
2
|
+
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils';
|
|
3
|
+
import { ErrorMessages, PACKAGE_NAME } from '../../consts';
|
|
4
|
+
import { awaitInit } from '../../init/browser/initializer';
|
|
6
5
|
import { sendEvent } from '../send-event/sendEvent';
|
|
6
|
+
import { PageViewEvent } from './page-view-event';
|
|
7
7
|
/**
|
|
8
8
|
* A function that sends a VIEW event to SitecoreCloud API
|
|
9
9
|
*
|
|
@@ -13,13 +13,26 @@ import { sendEvent } from '../send-event/sendEvent';
|
|
|
13
13
|
*/
|
|
14
14
|
export async function pageView(pageViewData) {
|
|
15
15
|
await awaitInit();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
if (getEnabledPackage(PACKAGE_NAME)?.initState) {
|
|
17
|
+
const settings = getCloudSDKSettings();
|
|
18
|
+
const id = getCookieValueClientSide(settings.cookieSettings.name.browserId);
|
|
19
|
+
return new PageViewEvent({
|
|
20
|
+
id,
|
|
21
|
+
pageViewData,
|
|
22
|
+
searchParams: window.location.search,
|
|
23
|
+
sendEvent,
|
|
24
|
+
settings: settings
|
|
25
|
+
}).send();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0014);
|
|
29
|
+
const id = getBrowserId();
|
|
30
|
+
return new PageViewEvent({
|
|
31
|
+
id,
|
|
32
|
+
pageViewData,
|
|
33
|
+
searchParams: window.location.search,
|
|
34
|
+
sendEvent,
|
|
35
|
+
settings
|
|
36
|
+
}).send();
|
|
37
|
+
}
|
|
25
38
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BasePayload, CustomEventPayload, IdentityEventPayload, PageViewEventPayload } from '..';
|
|
2
|
-
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core';
|
|
2
|
+
import type { EPResponse, Settings } from '@sitecore-cloudsdk/core/internal';
|
|
3
3
|
/**
|
|
4
4
|
* This factory function sends an event to Edge Proxy
|
|
5
5
|
* @param body - The event data to send
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { API_VERSION, debug, processDebugResponse } from '@sitecore-cloudsdk/core';
|
|
3
|
-
import { EVENTS_NAMESPACE,
|
|
2
|
+
import { API_VERSION, debug, processDebugResponse } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
import { EVENTS_NAMESPACE, PACKAGE_VERSION, X_CLIENT_SOFTWARE_ID } from '../../consts';
|
|
4
4
|
/**
|
|
5
5
|
* This factory function sends an event to Edge Proxy
|
|
6
6
|
* @param body - The event data to send
|
|
@@ -17,7 +17,7 @@ export async function sendEvent(body, settings) {
|
|
|
17
17
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
18
18
|
'Content-Type': 'application/json',
|
|
19
19
|
'X-Client-Software-ID': X_CLIENT_SOFTWARE_ID,
|
|
20
|
-
'X-Library-Version':
|
|
20
|
+
'X-Library-Version': PACKAGE_VERSION
|
|
21
21
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
22
22
|
},
|
|
23
23
|
method: 'POST'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the browser ID from the cookie
|
|
3
|
+
* @returns The browser ID if the cookie exists
|
|
4
|
+
* @deprecated Cloud SDK v0.4 introduces a new getBrowserId function. If you are upgrading from v0.3, we recommend that
|
|
5
|
+
* you use the getBrowserId function that is exposed from \@sitecore-cloudsdk/core/browser. The v0.3 function will be
|
|
6
|
+
* deprecated and removed in a future Cloud SDK release.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getBrowserId(): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { getBrowserId as getBrowserIdCore } from '@sitecore-cloudsdk/core/browser';
|
|
3
|
+
/**
|
|
4
|
+
* Get the browser ID from the cookie
|
|
5
|
+
* @returns The browser ID if the cookie exists
|
|
6
|
+
* @deprecated Cloud SDK v0.4 introduces a new getBrowserId function. If you are upgrading from v0.3, we recommend that
|
|
7
|
+
* you use the getBrowserId function that is exposed from \@sitecore-cloudsdk/core/browser. The v0.3 function will be
|
|
8
|
+
* deprecated and removed in a future Cloud SDK release.
|
|
9
|
+
*/
|
|
10
|
+
export function getBrowserId() {
|
|
11
|
+
return getBrowserIdCore();
|
|
12
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* A function that returns the guest
|
|
3
|
-
* @returns - A promise that resolves with the guest
|
|
4
|
-
* @throws - Will throw an error if the
|
|
2
|
+
* A function that returns the guest ID.
|
|
3
|
+
* @returns - A promise that resolves with the guest ID
|
|
4
|
+
* @throws - Will throw an error if the sitecoreEdgeContextId is incorrect
|
|
5
|
+
* @deprecated Cloud SDK v0.4 introduces a new getGuestId function. If you are upgrading from v0.3, we recommend that
|
|
6
|
+
* you use the getGuestId function that is exposed from \@sitecore-cloudsdk/core/browser. The v0.3 function will be
|
|
7
|
+
* deprecated and removed in a future Cloud SDK release.
|
|
5
8
|
*/
|
|
6
9
|
export declare function getGuestId(): Promise<string>;
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import { getBrowserId, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { getBrowserId, getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage, getGuestId as getGuestIdFromCore, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils';
|
|
4
|
+
import { ErrorMessages, PACKAGE_NAME } from '../consts';
|
|
5
|
+
import { awaitInit } from '../init/browser/initializer';
|
|
5
6
|
/**
|
|
6
|
-
* A function that returns the guest
|
|
7
|
-
* @returns - A promise that resolves with the guest
|
|
8
|
-
* @throws - Will throw an error if the
|
|
7
|
+
* A function that returns the guest ID.
|
|
8
|
+
* @returns - A promise that resolves with the guest ID
|
|
9
|
+
* @throws - Will throw an error if the sitecoreEdgeContextId is incorrect
|
|
10
|
+
* @deprecated Cloud SDK v0.4 introduces a new getGuestId function. If you are upgrading from v0.3, we recommend that
|
|
11
|
+
* you use the getGuestId function that is exposed from \@sitecore-cloudsdk/core/browser. The v0.3 function will be
|
|
12
|
+
* deprecated and removed in a future Cloud SDK release.
|
|
9
13
|
*/
|
|
10
14
|
export async function getGuestId() {
|
|
11
15
|
await awaitInit();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
if (getEnabledPackage(PACKAGE_NAME)?.initState) {
|
|
17
|
+
const settings = getCloudSDKSettings();
|
|
18
|
+
const id = getCookieValueClientSide(settings.cookieSettings.name.browserId);
|
|
19
|
+
return getGuestIdFromCore(id, settings.sitecoreEdgeContextId, settings.sitecoreEdgeUrl);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0014);
|
|
23
|
+
const id = getBrowserId();
|
|
24
|
+
return getGuestIdFromCore(id, settings.sitecoreEdgeContextId, settings.sitecoreEdgeUrl);
|
|
25
|
+
}
|
|
15
26
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BrowserSettings } from '@sitecore-cloudsdk/core/internal';
|
|
2
|
+
export declare let initPromise: Promise<void> | null;
|
|
3
|
+
/**
|
|
4
|
+
* Initiates the Events library using the global settings added by the developer
|
|
5
|
+
* @param settings - Global settings added by the developer
|
|
6
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
7
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
8
|
+
*/
|
|
9
|
+
export declare function init(settings: BrowserSettings): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function awaitInit(): Promise<void>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
+
import { EVENTS_NAMESPACE, ErrorMessages, PACKAGE_NAME, PACKAGE_VERSION } from '../../consts';
|
|
3
|
+
import { debug, getBrowserId, getEnabledPackageBrowser as getEnabledPackage, initCore } from '@sitecore-cloudsdk/core/internal';
|
|
4
|
+
export let initPromise = null;
|
|
5
|
+
/* eslint-disable max-len */
|
|
6
|
+
/**
|
|
7
|
+
* Initiates the Events library using the global settings added by the developer
|
|
8
|
+
* @param settings - Global settings added by the developer
|
|
9
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
10
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
11
|
+
*/
|
|
12
|
+
/* eslint-enable max-len */
|
|
13
|
+
export async function init(settings) {
|
|
14
|
+
if (typeof window === 'undefined')
|
|
15
|
+
throw new Error(ErrorMessages.IE_0001);
|
|
16
|
+
try {
|
|
17
|
+
initPromise = initCore(settings);
|
|
18
|
+
await initPromise;
|
|
19
|
+
debug(EVENTS_NAMESPACE)('eventsClient library initialized');
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
debug(EVENTS_NAMESPACE)('Error on initializing eventsClient library: %o', error);
|
|
23
|
+
initPromise = null;
|
|
24
|
+
throw new Error(error);
|
|
25
|
+
}
|
|
26
|
+
window.Engage = {
|
|
27
|
+
...window.Engage,
|
|
28
|
+
getBrowserId: () => getBrowserId(),
|
|
29
|
+
versions: {
|
|
30
|
+
...window.Engage?.versions,
|
|
31
|
+
events: PACKAGE_VERSION
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A function that handles the async browser init logic. Throws an error or awaits the promise.
|
|
37
|
+
*/
|
|
38
|
+
export async function awaitInit() {
|
|
39
|
+
const initState = getEnabledPackage(PACKAGE_NAME)?.initState;
|
|
40
|
+
if (initPromise === null && !initState)
|
|
41
|
+
throw new Error(ErrorMessages.IE_0014);
|
|
42
|
+
initPromise ? await initPromise : await initState;
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Request, Response } from '@sitecore-cloudsdk/utils';
|
|
2
|
+
import type { ServerSettings } from '@sitecore-cloudsdk/core/internal';
|
|
3
|
+
/**
|
|
4
|
+
* Initiates the server Events library using the global settings added by the developer
|
|
5
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request
|
|
6
|
+
* @param response - The response object, either a Middleware Next Response or an HTTP Response
|
|
7
|
+
* @param settings - Global settings added by the developer
|
|
8
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
9
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
10
|
+
*/
|
|
11
|
+
export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { debug, initCoreServer } from '@sitecore-cloudsdk/core/internal';
|
|
2
|
+
import { EVENTS_NAMESPACE } from '../../consts';
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
/**
|
|
5
|
+
* Initiates the server Events library using the global settings added by the developer
|
|
6
|
+
* @param request - The request object, either a Middleware Request or an HTTP Request
|
|
7
|
+
* @param response - The response object, either a Middleware Next Response or an HTTP Response
|
|
8
|
+
* @param settings - Global settings added by the developer
|
|
9
|
+
* @returns A promise that resolves with an object that handles the library functionality
|
|
10
|
+
* @deprecated Cloud SDK v0.4 introduces new initialization logic. If you are upgrading from v0.3, we recommend that you upgrade your initialization code. The v0.3 initialization logic will be deprecated and removed in a future Cloud SDK release.
|
|
11
|
+
*/
|
|
12
|
+
/* eslint-enable max-len */
|
|
13
|
+
export async function initServer(request, response, settings) {
|
|
14
|
+
try {
|
|
15
|
+
await initCoreServer(settings, request, response);
|
|
16
|
+
debug(EVENTS_NAMESPACE)('eventsServer library initialized');
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
debug(EVENTS_NAMESPACE)('Error on initializing eventsServer library with error: %o', error);
|
|
20
|
+
throw new Error(error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,24 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare
|
|
3
|
-
declare global {
|
|
4
|
-
interface Window {
|
|
5
|
-
Engage: {
|
|
6
|
-
[x: string]: any;
|
|
7
|
-
getBrowserId?: () => string;
|
|
8
|
-
versions?: {
|
|
9
|
-
personalize?: string;
|
|
10
|
-
events?: string;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Initiates the Events library using the global settings added by the developer
|
|
17
|
-
* @param settings - Global settings added by the developer
|
|
18
|
-
* @returns A promise that resolves with an object that handles the library functionality
|
|
19
|
-
*/
|
|
20
|
-
export declare function init(settings: BrowserSettings): Promise<void>;
|
|
1
|
+
import { CloudSDKBrowserInitializer } from '@sitecore-cloudsdk/core/browser';
|
|
2
|
+
export declare function sideEffects(): Promise<void>;
|
|
21
3
|
/**
|
|
22
|
-
*
|
|
4
|
+
* Makes the functionality of the events package available.
|
|
5
|
+
*
|
|
6
|
+
* @returns An instance of {@link CloudSDKBrowserInitializer}
|
|
23
7
|
*/
|
|
24
|
-
export declare function
|
|
8
|
+
export declare function addEvents(this: CloudSDKBrowserInitializer): CloudSDKBrowserInitializer;
|
|
9
|
+
declare module '@sitecore-cloudsdk/core/browser' {
|
|
10
|
+
interface CloudSDKBrowserInitializer {
|
|
11
|
+
addEvents: typeof addEvents;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,39 +1,28 @@
|
|
|
1
1
|
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
|
|
2
|
-
import {
|
|
3
|
-
import { debug,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @returns A promise that resolves with an object that handles the library functionality
|
|
9
|
-
*/
|
|
10
|
-
export async function init(settings) {
|
|
11
|
-
if (typeof window === 'undefined')
|
|
12
|
-
throw new Error(ErrorMessages.IE_0001);
|
|
13
|
-
try {
|
|
14
|
-
initPromise = initCore(settings);
|
|
15
|
-
await initPromise;
|
|
16
|
-
debug(EVENTS_NAMESPACE)('eventsClient library initialized');
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
debug(EVENTS_NAMESPACE)('Error on initializing eventsClient library: %o', error);
|
|
20
|
-
initPromise = null;
|
|
21
|
-
throw new Error(error);
|
|
22
|
-
}
|
|
2
|
+
import { CloudSDKBrowserInitializer } from '@sitecore-cloudsdk/core/browser';
|
|
3
|
+
import { debug, enabledPackagesBrowser as enabledPackages, getCloudSDKSettingsBrowser as getCloudSDKSettings, PackageInitializer } from '@sitecore-cloudsdk/core/internal';
|
|
4
|
+
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils';
|
|
5
|
+
import { EVENTS_NAMESPACE, PACKAGE_NAME, PACKAGE_VERSION } from '../../consts';
|
|
6
|
+
export async function sideEffects() {
|
|
7
|
+
window.Engage ?? (window.Engage = {});
|
|
23
8
|
window.Engage = {
|
|
24
9
|
...window.Engage,
|
|
25
|
-
getBrowserId: () =>
|
|
10
|
+
getBrowserId: () => getCookieValueClientSide(getCloudSDKSettings().cookieSettings.name.browserId),
|
|
26
11
|
versions: {
|
|
27
|
-
...window.Engage
|
|
28
|
-
events:
|
|
12
|
+
...window.Engage.versions,
|
|
13
|
+
events: PACKAGE_VERSION
|
|
29
14
|
}
|
|
30
15
|
};
|
|
16
|
+
debug(EVENTS_NAMESPACE)('eventsClient library initialized');
|
|
31
17
|
}
|
|
32
18
|
/**
|
|
33
|
-
*
|
|
19
|
+
* Makes the functionality of the events package available.
|
|
20
|
+
*
|
|
21
|
+
* @returns An instance of {@link CloudSDKBrowserInitializer}
|
|
34
22
|
*/
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
export function addEvents() {
|
|
24
|
+
const eventsInitializer = new PackageInitializer({ sideEffects });
|
|
25
|
+
enabledPackages.set(PACKAGE_NAME, eventsInitializer);
|
|
26
|
+
return this;
|
|
39
27
|
}
|
|
28
|
+
CloudSDKBrowserInitializer.prototype.addEvents = addEvents;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { CloudSDKServerInitializer } from '@sitecore-cloudsdk/core/server';
|
|
2
|
+
export declare function sideEffects(): Promise<void>;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @
|
|
7
|
-
* @param settings - Global settings added by the developer
|
|
8
|
-
* @returns A promise that resolves with an object that handles the library functionality
|
|
4
|
+
* Makes the functionality of the events package available.
|
|
5
|
+
*
|
|
6
|
+
* @returns An instance of {@link CloudSDKServerInitializer}
|
|
9
7
|
*/
|
|
10
|
-
export declare function
|
|
8
|
+
export declare function addEvents(this: CloudSDKServerInitializer): CloudSDKServerInitializer;
|
|
9
|
+
declare module '@sitecore-cloudsdk/core/server' {
|
|
10
|
+
interface CloudSDKServerInitializer {
|
|
11
|
+
addEvents: typeof addEvents;
|
|
12
|
+
}
|
|
13
|
+
}
|