@sitecore-cloudsdk/events 0.3.1 → 0.4.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +31 -59
  2. package/dist/cjs/package.json +3 -3
  3. package/dist/cjs/src/browser.d.ts +4 -3
  4. package/dist/cjs/src/browser.js +8 -5
  5. package/dist/cjs/src/lib/consts.d.ts +7 -6
  6. package/dist/cjs/src/lib/consts.js +9 -8
  7. package/dist/cjs/src/lib/eventStorage/addToEventQueue.js +23 -10
  8. package/dist/cjs/src/lib/eventStorage/clearEventQueue.js +1 -1
  9. package/dist/cjs/src/lib/eventStorage/eventStorage.js +3 -3
  10. package/dist/cjs/src/lib/eventStorage/processEventQueue.js +1 -1
  11. package/dist/cjs/src/lib/events/base-event.js +3 -3
  12. package/dist/cjs/src/lib/events/custom-event/custom-event.d.ts +1 -1
  13. package/dist/cjs/src/lib/events/custom-event/event.d.ts +1 -1
  14. package/dist/cjs/src/lib/events/custom-event/event.js +24 -12
  15. package/dist/cjs/src/lib/events/custom-event/eventServer.d.ts +2 -2
  16. package/dist/cjs/src/lib/events/custom-event/eventServer.js +16 -7
  17. package/dist/cjs/src/lib/events/custom-event/form.d.ts +3 -3
  18. package/dist/cjs/src/lib/events/custom-event/form.js +43 -21
  19. package/dist/cjs/src/lib/events/identity/identity-event.d.ts +1 -1
  20. package/dist/cjs/src/lib/events/identity/identity.d.ts +1 -1
  21. package/dist/cjs/src/lib/events/identity/identity.js +24 -12
  22. package/dist/cjs/src/lib/events/identity/identityServer.d.ts +2 -2
  23. package/dist/cjs/src/lib/events/identity/identityServer.js +17 -6
  24. package/dist/cjs/src/lib/events/page-view/page-view-event.d.ts +1 -1
  25. package/dist/cjs/src/lib/events/page-view/page-view-server.d.ts +2 -2
  26. package/dist/cjs/src/lib/events/page-view/page-view-server.js +17 -6
  27. package/dist/cjs/src/lib/events/page-view/page-view.d.ts +1 -1
  28. package/dist/cjs/src/lib/events/page-view/page-view.js +26 -13
  29. package/dist/cjs/src/lib/events/send-event/sendEvent.d.ts +1 -1
  30. package/dist/cjs/src/lib/events/send-event/sendEvent.js +7 -7
  31. package/dist/cjs/src/lib/getBrowserId/getBrowserId.d.ts +8 -0
  32. package/dist/cjs/src/lib/getBrowserId/getBrowserId.js +16 -0
  33. package/dist/cjs/src/lib/getGuestId/getGuestId.d.ts +6 -3
  34. package/dist/cjs/src/lib/getGuestId/getGuestId.js +19 -8
  35. package/dist/cjs/src/lib/init/browser/initializer.d.ts +13 -0
  36. package/dist/cjs/src/lib/init/browser/initializer.js +48 -0
  37. package/dist/cjs/src/lib/init/server/initializer.d.ts +11 -0
  38. package/dist/cjs/src/lib/init/server/initializer.js +26 -0
  39. package/dist/cjs/src/lib/initializer/browser/initializer.d.ts +11 -22
  40. package/dist/cjs/src/lib/initializer/browser/initializer.js +20 -31
  41. package/dist/cjs/src/lib/initializer/server/initializer.d.ts +11 -8
  42. package/dist/cjs/src/lib/initializer/server/initializer.js +17 -17
  43. package/dist/cjs/src/server.d.ts +3 -2
  44. package/dist/cjs/src/server.js +6 -3
  45. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  46. package/dist/esm/package.json +3 -3
  47. package/dist/esm/src/browser.d.ts +4 -3
  48. package/dist/esm/src/browser.js +4 -3
  49. package/dist/esm/src/lib/consts.d.ts +7 -6
  50. package/dist/esm/src/lib/consts.js +8 -7
  51. package/dist/esm/src/lib/eventStorage/addToEventQueue.js +24 -11
  52. package/dist/esm/src/lib/eventStorage/clearEventQueue.js +1 -1
  53. package/dist/esm/src/lib/eventStorage/eventStorage.js +1 -1
  54. package/dist/esm/src/lib/eventStorage/processEventQueue.js +1 -1
  55. package/dist/esm/src/lib/events/base-event.js +1 -1
  56. package/dist/esm/src/lib/events/custom-event/custom-event.d.ts +1 -1
  57. package/dist/esm/src/lib/events/custom-event/event.d.ts +1 -1
  58. package/dist/esm/src/lib/events/custom-event/event.js +25 -13
  59. package/dist/esm/src/lib/events/custom-event/eventServer.d.ts +2 -2
  60. package/dist/esm/src/lib/events/custom-event/eventServer.js +17 -8
  61. package/dist/esm/src/lib/events/custom-event/form.d.ts +3 -3
  62. package/dist/esm/src/lib/events/custom-event/form.js +44 -22
  63. package/dist/esm/src/lib/events/identity/identity-event.d.ts +1 -1
  64. package/dist/esm/src/lib/events/identity/identity.d.ts +1 -1
  65. package/dist/esm/src/lib/events/identity/identity.js +25 -13
  66. package/dist/esm/src/lib/events/identity/identityServer.d.ts +2 -2
  67. package/dist/esm/src/lib/events/identity/identityServer.js +17 -6
  68. package/dist/esm/src/lib/events/page-view/page-view-event.d.ts +1 -1
  69. package/dist/esm/src/lib/events/page-view/page-view-server.d.ts +2 -2
  70. package/dist/esm/src/lib/events/page-view/page-view-server.js +18 -7
  71. package/dist/esm/src/lib/events/page-view/page-view.d.ts +1 -1
  72. package/dist/esm/src/lib/events/page-view/page-view.js +27 -14
  73. package/dist/esm/src/lib/events/send-event/sendEvent.d.ts +1 -1
  74. package/dist/esm/src/lib/events/send-event/sendEvent.js +3 -3
  75. package/dist/esm/src/lib/getBrowserId/getBrowserId.d.ts +8 -0
  76. package/dist/esm/src/lib/getBrowserId/getBrowserId.js +12 -0
  77. package/dist/esm/src/lib/getGuestId/getGuestId.d.ts +6 -3
  78. package/dist/esm/src/lib/getGuestId/getGuestId.js +20 -9
  79. package/dist/esm/src/lib/init/browser/initializer.d.ts +13 -0
  80. package/dist/esm/src/lib/init/browser/initializer.js +43 -0
  81. package/dist/esm/src/lib/init/server/initializer.d.ts +11 -0
  82. package/dist/esm/src/lib/init/server/initializer.js +22 -0
  83. package/dist/esm/src/lib/initializer/browser/initializer.d.ts +11 -22
  84. package/dist/esm/src/lib/initializer/browser/initializer.js +18 -29
  85. package/dist/esm/src/lib/initializer/server/initializer.d.ts +11 -8
  86. package/dist/esm/src/lib/initializer/server/initializer.js +15 -16
  87. package/dist/esm/src/server.d.ts +3 -2
  88. package/dist/esm/src/server.js +3 -2
  89. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  90. package/package.json +3 -3
@@ -1,33 +1,55 @@
1
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
2
- import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
3
- import { CustomEvent } from './custom-event';
4
- import { ErrorMessages } from '../../consts';
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
- * settings object, you must specify it here
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
- const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
18
- const id = getBrowserId();
19
- const formEvent = new CustomEvent({
20
- eventData: {
21
- extensionData: {
22
- formId,
23
- interactionType: interactionType.toUpperCase()
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
- type: 'FORM'
26
- },
27
- id,
28
- sendEvent,
29
- settings
30
- });
31
- formEvent.page = undefined;
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,4 +1,4 @@
1
- import type { EPResponse } from '@sitecore-cloudsdk/core';
1
+ import type { EPResponse } from '@sitecore-cloudsdk/core/internal';
2
2
  import type { IdentityData } from './identity-event';
3
3
  /**
4
4
  * A function that sends an IDENTITY event to SitecoreCloud API
@@ -1,9 +1,9 @@
1
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
2
- import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
3
- import { ErrorMessages } from '../../consts';
4
- import { IdentityEvent } from './identity-event';
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
- const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
16
- const id = getBrowserId();
17
- return new IdentityEvent({
18
- id,
19
- identityData,
20
- sendEvent,
21
- settings
22
- }).send();
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 { EPResponse } from '@sitecore-cloudsdk/core';
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 { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
3
- import { ErrorMessages } from '../../consts';
4
- import { IdentityEvent } from './identity-event';
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
- const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
15
- const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
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 { EPResponse } from '@sitecore-cloudsdk/core';
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 { getCookieValueFromRequest, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core';
3
- import { ErrorMessages } from '../../consts';
4
- import { PageViewEvent } from './page-view-event';
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
- const settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0005);
15
- const id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId);
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,4 +1,4 @@
1
- import type { EPResponse } from '@sitecore-cloudsdk/core';
1
+ import type { EPResponse } from '@sitecore-cloudsdk/core/internal';
2
2
  import type { PageViewData } from './page-view-event';
3
3
  /**
4
4
  * A function that sends a VIEW event to SitecoreCloud API
@@ -1,9 +1,9 @@
1
- // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S.
2
- import { getBrowserId, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core';
3
- import { ErrorMessages } from '../../consts';
4
- import { PageViewEvent } from './page-view-event';
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
- const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
17
- const id = getBrowserId();
18
- return new PageViewEvent({
19
- id,
20
- pageViewData,
21
- searchParams: window.location.search,
22
- sendEvent,
23
- settings
24
- }).send();
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, LIBRARY_VERSION, X_CLIENT_SOFTWARE_ID } from '../../consts';
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': 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 id.
3
- * @returns - A promise that resolves with the guest id
4
- * @throws - Will throw an error if the clientKey/browser id is invalid
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 { ErrorMessages } from '../consts';
4
- import { awaitInit } from '../initializer/browser/initializer';
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 id.
7
- * @returns - A promise that resolves with the guest id
8
- * @throws - Will throw an error if the clientKey/browser id is invalid
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
- const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0004);
13
- const id = getBrowserId();
14
- return getGuestIdFromCore(id, settings.sitecoreEdgeContextId, settings.sitecoreEdgeUrl);
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 type { BrowserSettings } from '@sitecore-cloudsdk/core';
2
- export declare let initPromise: Promise<void> | null;
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
- * A function that handles the async browser init logic. Throws an error or awaits the promise.
4
+ * Makes the functionality of the events package available.
5
+ *
6
+ * @returns An instance of {@link CloudSDKBrowserInitializer}
23
7
  */
24
- export declare function awaitInit(): Promise<void>;
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 { EVENTS_NAMESPACE, ErrorMessages, LIBRARY_VERSION } from '../../consts';
3
- import { debug, getBrowserId, initCore } from '@sitecore-cloudsdk/core';
4
- export let initPromise = null;
5
- /**
6
- * Initiates the Events library using the global settings added by the developer
7
- * @param settings - Global settings added by the developer
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: () => getBrowserId(),
10
+ getBrowserId: () => getCookieValueClientSide(getCloudSDKSettings().cookieSettings.name.browserId),
26
11
  versions: {
27
- ...window.Engage?.versions,
28
- events: LIBRARY_VERSION
12
+ ...window.Engage.versions,
13
+ events: PACKAGE_VERSION
29
14
  }
30
15
  };
16
+ debug(EVENTS_NAMESPACE)('eventsClient library initialized');
31
17
  }
32
18
  /**
33
- * A function that handles the async browser init logic. Throws an error or awaits the promise.
19
+ * Makes the functionality of the events package available.
20
+ *
21
+ * @returns An instance of {@link CloudSDKBrowserInitializer}
34
22
  */
35
- export async function awaitInit() {
36
- if (initPromise === null)
37
- throw new Error(ErrorMessages.IE_0004);
38
- await initPromise;
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 type { Request, Response } from '@sitecore-cloudsdk/utils';
2
- import type { ServerSettings } from '@sitecore-cloudsdk/core';
1
+ import { CloudSDKServerInitializer } from '@sitecore-cloudsdk/core/server';
2
+ export declare function sideEffects(): Promise<void>;
3
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
4
+ * Makes the functionality of the events package available.
5
+ *
6
+ * @returns An instance of {@link CloudSDKServerInitializer}
9
7
  */
10
- export declare function initServer(request: Request, response: Response, settings: ServerSettings): Promise<void>;
8
+ export declare function addEvents(this: CloudSDKServerInitializer): CloudSDKServerInitializer;
9
+ declare module '@sitecore-cloudsdk/core/server' {
10
+ interface CloudSDKServerInitializer {
11
+ addEvents: typeof addEvents;
12
+ }
13
+ }